buildSystemPrompt applies system-level prompt injections in the canonical order. It is used by both the initial prompt assembly and the ReloadMessages callback to keep them in sync.
( prompt []fantasy.Message, subagentInstruction string, instruction string, resolvedSkills []skillspkg.ResolvedSkill, userPrompt string, behaviorContext systemPromptBehaviorContext, )
| 6723 | // canonical order. It is used by both the initial prompt assembly |
| 6724 | // and the ReloadMessages callback to keep them in sync. |
| 6725 | func buildSystemPrompt( |
| 6726 | prompt []fantasy.Message, |
| 6727 | subagentInstruction string, |
| 6728 | instruction string, |
| 6729 | resolvedSkills []skillspkg.ResolvedSkill, |
| 6730 | userPrompt string, |
| 6731 | behaviorContext systemPromptBehaviorContext, |
| 6732 | ) []fantasy.Message { |
| 6733 | if subagentInstruction != "" { |
| 6734 | prompt = chatprompt.InsertSystem(prompt, subagentInstruction) |
| 6735 | } |
| 6736 | if instruction != "" { |
| 6737 | prompt = chatprompt.InsertSystem(prompt, instruction) |
| 6738 | } |
| 6739 | if skillIndex := chattool.FormatResolvedSkillIndex(resolvedSkills); skillIndex != "" { |
| 6740 | prompt = chatprompt.InsertSystem(prompt, skillIndex) |
| 6741 | } |
| 6742 | if userPrompt != "" { |
| 6743 | prompt = chatprompt.InsertSystem(prompt, userPrompt) |
| 6744 | } |
| 6745 | if isExploreSubagentMode(behaviorContext.chatMode) { |
| 6746 | prompt = chatprompt.InsertSystem(prompt, ExploreSubagentOverlayPrompt) |
| 6747 | return prompt |
| 6748 | } |
| 6749 | isPlanModeTurn := behaviorContext.planMode.Valid && behaviorContext.planMode.ChatPlanMode == database.ChatPlanModePlan |
| 6750 | if isPlanModeTurn { |
| 6751 | if behaviorContext.isRootChat { |
| 6752 | prompt = chatprompt.InsertSystem(prompt, PlanningOverlayPrompt()) |
| 6753 | if behaviorContext.planModeInstructions != "" { |
| 6754 | prompt = chatprompt.InsertSystem(prompt, behaviorContext.planModeInstructions) |
| 6755 | } |
| 6756 | } else { |
| 6757 | prompt = chatprompt.InsertSystem(prompt, PlanningSubagentOverlayPrompt) |
| 6758 | } |
| 6759 | } |
| 6760 | return prompt |
| 6761 | } |
| 6762 | |
| 6763 | func removeSkillIndexMessages(prompt []fantasy.Message) []fantasy.Message { |
| 6764 | out := make([]fantasy.Message, 0, len(prompt)) |