@@ -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.
0 commit comments