From 7a43c3e06572354c5800941d805893a871986754 Mon Sep 17 00:00:00 2001 From: mingmxren Date: Wed, 4 Mar 2026 02:34:58 +0800 Subject: [PATCH] refactor(agent): address self-review comments on loop.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- pkg/agent/loop.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pkg/agent/loop.go b/pkg/agent/loop.go index 0b4be28e0..cdca8bb56 100644 --- a/pkg/agent/loop.go +++ b/pkg/agent/loop.go @@ -101,10 +101,9 @@ func NewAgentLoop( state: stateManager, summarizing: sync.Map{}, fallback: fallbackChain, + cmdRegistry: commands.NewRegistry(commands.BuiltinDefinitions()), } - al.cmdRegistry = commands.NewRegistry(commands.BuiltinDefinitions()) - return al } @@ -1471,7 +1470,7 @@ func (al *AgentLoop) handleCommand( return "", false } - rt := al.buildRuntime() + rt := al.buildCommandsRuntime() executor := commands.NewExecutor(al.cmdRegistry, rt) var commandReply string @@ -1495,12 +1494,12 @@ func (al *AgentLoop) handleCommand( return commandReply, true } return "", true - default: + default: // OutcomePassthrough — let the message fall through to LLM return "", false } } -func (al *AgentLoop) buildRuntime() *commands.Runtime { +func (al *AgentLoop) buildCommandsRuntime() *commands.Runtime { return &commands.Runtime{ Config: al.cfg, GetModelInfo: func() (string, string) {