From 210608b20f6c54fc095e2c8c424e0f67c99bc90e Mon Sep 17 00:00:00 2001 From: dj-oyu <68707227+dj-oyu@users.noreply.github.com> Date: Sun, 15 Mar 2026 18:40:18 +0900 Subject: [PATCH] refactor: extract context.go fork insertions to context_ext.go Move orchestration identity overrides to extIdentityOverrides() and orchestration guidance + peer note injection to extPromptSections(). getIdentity and BuildSystemPrompt now call these ext methods instead of inlining the fork-specific logic. Co-Authored-By: Claude Opus 4.6 (1M context) --- pkg/agent/context.go | 43 +++++++----------------------------- pkg/agent/context_ext.go | 47 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 35 deletions(-) diff --git a/pkg/agent/context.go b/pkg/agent/context.go index cfa40e69a..e8924036f 100644 --- a/pkg/agent/context.go +++ b/pkg/agent/context.go @@ -89,32 +89,14 @@ func (cb *ContextBuilder) getIdentity() string { // Build tools section dynamically toolsSection := cb.buildToolsSection() - // Build prompt with optional orchestration banner - var prompt string - if cb.orchestrationEnabled { - prompt = ` /_/_/_/_/_/_/_/_/_/_/_/_/_/_/ - - O R C H E S T R A M O D E - -/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ - - - -` + // Orchestration overrides (banner, identity, executing rule) + prompt, identity, executingRule := cb.extIdentityOverrides() + if identity == "" { + identity = "a helpful AI assistant" } - - // Conditional identity and plan executing rule for orchestration mode - identity := "a helpful AI assistant" - executingRule := `Work through the current Phase's steps. + if executingRule == "" { + executingRule = `Work through the current Phase's steps. Mark each "- [x]" via edit_file. The system will auto-advance phases.` - if cb.orchestrationEnabled { - identity = "a conductor AI agent that orchestrates subagents" - executingRule = `Delegate the current Phase's steps to subagents using spawn. - For each step: spawn a subagent with the appropriate preset (scout for investigation, - coder for implementation, analyst for review). Spawn multiple independent steps in parallel. - When a subagent completes, mark "- [x]" via edit_file and record findings in - ## Orchestration > Findings in MEMORY.md. - Only do a step inline if it's a single quick tool call (e.g., reading one file).` } return fmt.Sprintf(prompt+`# picoclaw 🦞 (%s) @@ -223,12 +205,8 @@ func (cb *ContextBuilder) BuildSystemPrompt() string { // Core identity section parts = append(parts, cb.getIdentity()) - // Orchestration guidance — injected only when spawn tool is registered - if cb.tools != nil { - if _, hasSpawn := cb.tools.Get("spawn"); hasSpawn { - parts = append(parts, orchestrationGuidance) - } - } + // Fork-specific prompt sections (orchestration guidance, peer note) + parts = append(parts, cb.extPromptSections()...) // Bootstrap files bootstrapContent := cb.LoadBootstrapFiles() @@ -253,11 +231,6 @@ The following skills extend your capabilities. To use a skill, read its SKILL.md } } - // Peer session coordination - if cb.peerNote != "" { - parts = append(parts, "## Active Sessions\n\n"+cb.peerNote) - } - // Memory context memoryContext := cb.memory.GetMemoryContext() if memoryContext != "" { diff --git a/pkg/agent/context_ext.go b/pkg/agent/context_ext.go index 61b245488..6919380d2 100644 --- a/pkg/agent/context_ext.go +++ b/pkg/agent/context_ext.go @@ -33,6 +33,53 @@ func (cb *ContextBuilder) SetOrchestrationEnabled(enabled bool) { cb.orchestrationEnabled = enabled } +// extIdentityOverrides returns the orchestration-specific overrides for +// getIdentity: banner prefix, identity string, and plan executing rule. +// When orchestration is disabled, all return values are empty strings. +func (cb *ContextBuilder) extIdentityOverrides() (banner, identity, executingRule string) { + if !cb.orchestrationEnabled { + return "", "", "" + } + + banner = ` /_/_/_/_/_/_/_/_/_/_/_/_/_/_/ + + O R C H E S T R A M O D E + +/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ + + + +` + identity = "a conductor AI agent that orchestrates subagents" + executingRule = `Delegate the current Phase's steps to subagents using spawn. + For each step: spawn a subagent with the appropriate preset (scout for investigation, + coder for implementation, analyst for review). Spawn multiple independent steps in parallel. + When a subagent completes, mark "- [x]" via edit_file and record findings in + ## Orchestration > Findings in MEMORY.md. + Only do a step inline if it's a single quick tool call (e.g., reading one file).` + return banner, identity, executingRule +} + +// extPromptSections returns fork-specific prompt sections to append to +// BuildSystemPrompt: orchestration guidance and peer session note. +func (cb *ContextBuilder) extPromptSections() []string { + var sections []string + + // Orchestration guidance — injected only when spawn tool is registered + if cb.tools != nil { + if _, hasSpawn := cb.tools.Get("spawn"); hasSpawn { + sections = append(sections, orchestrationGuidance) + } + } + + // Peer session coordination + if cb.peerNote != "" { + sections = append(sections, "## Active Sessions\n\n"+cb.peerNote) + } + + return sections +} + // Memory returns the underlying MemoryStore for direct plan queries. func (cb *ContextBuilder) Memory() *MemoryStore { return cb.memory