Skip to content

Commit c98debc

Browse files
committed
Fix hooks sync template agent resolution
1 parent d03019c commit c98debc

4 files changed

Lines changed: 73 additions & 4 deletions

File tree

internal/cmd/hooks_sync.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func runHooksSync(cmd *cobra.Command, args []string) error {
127127
if loc.Rig != "" {
128128
rigPath = filepath.Join(townRoot, loc.Rig)
129129
}
130-
rc := config.ResolveRoleAgentConfig(loc.Role, townRoot, rigPath)
130+
rc := config.ResolveRoleConfiguredAgentConfig(loc.Role, townRoot, rigPath)
131131
if rc == nil || rc.Hooks == nil || rc.Hooks.Provider == "" {
132132
continue
133133
}

internal/cmd/patrol_helpers_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ func TestBuildRefineryPatrolVars_FullConfig(t *testing.T) {
134134
"run_tests": "true",
135135
"target_branch": "main",
136136
"delete_merged_branches": "true",
137+
"judgment_enabled": "false",
138+
"review_depth": "standard",
137139
}
138140

139141
varMap := make(map[string]string)
@@ -299,8 +301,8 @@ func TestBuildRefineryPatrolVars_BoolFormat(t *testing.T) {
299301
trueVal := true
300302
falseVal2 := false
301303
mq := &config.MergeQueueConfig{
302-
Enabled: true,
303-
IntegrationBranchAutoLand: &trueVal,
304+
Enabled: true,
305+
IntegrationBranchAutoLand: &trueVal,
304306
IntegrationBranchRefineryEnabled: &trueVal,
305307
RunTests: &trueVal,
306308
SetupCommand: "npm ci",

internal/config/loader.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,6 +1698,73 @@ func ResolveRoleAgentName(role, townRoot, rigPath string) (agentName string, isR
16981698
return "claude", false
16991699
}
17001700

1701+
// ResolveRoleConfiguredAgentConfig returns the configured agent for a role
1702+
// without requiring its binary to exist in PATH. This is for config-driven
1703+
// flows like hooks sync and doctor checks that need the intended provider and
1704+
// template even before the runtime is installed locally.
1705+
func ResolveRoleConfiguredAgentConfig(role, townRoot, rigPath string) *RuntimeConfig {
1706+
var rigSettings *RigSettings
1707+
if rigPath != "" {
1708+
var err error
1709+
rigSettings, err = LoadRigSettings(RigSettingsPath(rigPath))
1710+
if err != nil {
1711+
rigSettings = nil
1712+
}
1713+
}
1714+
1715+
townSettings, err := LoadOrCreateTownSettings(TownSettingsPath(townRoot))
1716+
if err != nil {
1717+
townSettings = NewTownSettings()
1718+
}
1719+
1720+
_ = LoadAgentRegistry(DefaultAgentRegistryPath(townRoot))
1721+
if rigPath != "" {
1722+
_ = LoadRigAgentRegistry(RigAgentRegistryPath(rigPath))
1723+
}
1724+
1725+
resolveNamed := func(agentName string) *RuntimeConfig {
1726+
if agentName == "" {
1727+
return nil
1728+
}
1729+
rc := lookupAgentConfigIfExists(agentName, townSettings, rigSettings)
1730+
if rc == nil {
1731+
return nil
1732+
}
1733+
rc.ResolvedAgent = agentName
1734+
return rc
1735+
}
1736+
1737+
if rigSettings != nil && rigSettings.RoleAgents != nil {
1738+
if agentName, ok := rigSettings.RoleAgents[role]; ok && agentName != "" {
1739+
if rc := resolveNamed(agentName); rc != nil {
1740+
return rc
1741+
}
1742+
}
1743+
}
1744+
1745+
if townSettings.RoleAgents != nil {
1746+
if agentName, ok := townSettings.RoleAgents[role]; ok && agentName != "" {
1747+
if rc := resolveNamed(agentName); rc != nil {
1748+
return rc
1749+
}
1750+
}
1751+
}
1752+
1753+
if rigSettings != nil && rigSettings.Agent != "" {
1754+
if rc := resolveNamed(rigSettings.Agent); rc != nil {
1755+
return rc
1756+
}
1757+
}
1758+
1759+
if townSettings.DefaultAgent != "" {
1760+
if rc := resolveNamed(townSettings.DefaultAgent); rc != nil {
1761+
return rc
1762+
}
1763+
}
1764+
1765+
return DefaultRuntimeConfig()
1766+
}
1767+
17011768
// lookupAgentConfig looks up an agent by name.
17021769
// Checks rig-level custom agents first, then town's custom agents, then built-in presets from agents.go.
17031770
// Falls back to DefaultRuntimeConfig() if no match is found.

internal/doctor/hooks_sync_check.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (c *HooksSyncCheck) Run(ctx *CheckContext) *CheckResult {
9999
if loc.Rig != "" {
100100
rigPath = filepath.Join(ctx.TownRoot, loc.Rig)
101101
}
102-
rc := config.ResolveRoleAgentConfig(loc.Role, ctx.TownRoot, rigPath)
102+
rc := config.ResolveRoleConfiguredAgentConfig(loc.Role, ctx.TownRoot, rigPath)
103103
if rc == nil || rc.Hooks == nil || rc.Hooks.Provider == "" {
104104
continue
105105
}

0 commit comments

Comments
 (0)