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) <noreply@anthropic.com>
This commit is contained in:
dj-oyu 2026-03-15 18:40:18 +09:00
parent 7512b6e8f3
commit 210608b20f
2 changed files with 55 additions and 35 deletions

View file

@ -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 != "" {

View file

@ -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