refactor(agent): address self-review comments on loop.go

- Move cmdRegistry init into struct literal (review comment #11)
- Rename buildRuntime → buildCommandsRuntime for clarity (review comment #12)
- Add comment to default switch case explaining passthrough (review comment #13)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
mingmxren 2026-03-04 02:34:58 +08:00
parent 3c2b6e8121
commit 7a43c3e065

View file

@ -101,10 +101,9 @@ func NewAgentLoop(
state: stateManager, state: stateManager,
summarizing: sync.Map{}, summarizing: sync.Map{},
fallback: fallbackChain, fallback: fallbackChain,
cmdRegistry: commands.NewRegistry(commands.BuiltinDefinitions()),
} }
al.cmdRegistry = commands.NewRegistry(commands.BuiltinDefinitions())
return al return al
} }
@ -1471,7 +1470,7 @@ func (al *AgentLoop) handleCommand(
return "", false return "", false
} }
rt := al.buildRuntime() rt := al.buildCommandsRuntime()
executor := commands.NewExecutor(al.cmdRegistry, rt) executor := commands.NewExecutor(al.cmdRegistry, rt)
var commandReply string var commandReply string
@ -1495,12 +1494,12 @@ func (al *AgentLoop) handleCommand(
return commandReply, true return commandReply, true
} }
return "", true return "", true
default: default: // OutcomePassthrough — let the message fall through to LLM
return "", false return "", false
} }
} }
func (al *AgentLoop) buildRuntime() *commands.Runtime { func (al *AgentLoop) buildCommandsRuntime() *commands.Runtime {
return &commands.Runtime{ return &commands.Runtime{
Config: al.cfg, Config: al.cfg,
GetModelInfo: func() (string, string) { GetModelInfo: func() (string, string) {