From e824ce8945814927ef75452354d16a76f705f2b0 Mon Sep 17 00:00:00 2001 From: dj-oyu <68707227+dj-oyu@users.noreply.github.com> Date: Tue, 24 Feb 2026 18:20:19 +0900 Subject: [PATCH] fix: refresh cached system prompt after LLM iteration Tool execution during runLLMIteration updates touch_dir, but the cached system prompt was captured before that. Now rebuilds and re-captures after iteration so Mini App shows the prompt with current workDir (correct AGENTS.md). Co-Authored-By: Claude Opus 4.6 --- pkg/agent/loop.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/agent/loop.go b/pkg/agent/loop.go index a49a74eb0..6d44bc262 100644 --- a/pkg/agent/loop.go +++ b/pkg/agent/loop.go @@ -926,8 +926,12 @@ func (al *AgentLoop) runAgentLoop(ctx context.Context, agent *AgentInstance, opt return "", err } - // If last tool had ForUser content and we already sent it, we might not need to send final response - // This is controlled by the tool's Silent flag and ForUser content + // 5-post. Refresh cached system prompt: tool execution may have updated touch_dir, + // so rebuild with current workDir so Mini App shows the up-to-date version. + if active := al.sessions.ListActive(); len(active) > 0 && active[0].SessionKey == opts.SessionKey && active[0].TouchDir != "" { + agent.ContextBuilder.SetWorkDir(filepath.Join(agent.Workspace, active[0].TouchDir)) + } + al.lastSystemPrompt.Store(agent.ContextBuilder.BuildSystemPrompt()) // 5a. Auto-advance plan phases after LLM iteration postStatus := agent.ContextBuilder.GetPlanStatus()