feat: inject active mission context into agent system prompt

The session-start hook approach didn't work — Claude Code's TUI
overwrites stdout before the agent sees it, and the hook only fires
when the agent calls it as a tool.

Instead, inject mission context directly into the composed system
prompt via build_runtime_prompt(). When mission.json is active in
CWD, the agent gets mission name, ID, milestone progress, and
mandatory first-action instructions in its initial context.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-22 17:44:36 -06:00
parent 612796d8e0
commit 221afe94d9

View File

@@ -169,6 +169,40 @@ EOF
printf '\n\n# Runtime-Specific Contract\n\n'
cat "$runtime_file"
# Inject active mission context if present in CWD
local mission_file=".mosaic/orchestrator/mission.json"
if [[ -f "$mission_file" ]] && command -v jq &>/dev/null; then
local status
status="$(jq -r '.status // "inactive"' "$mission_file" 2>/dev/null)"
if [[ "$status" == "active" || "$status" == "paused" ]]; then
local m_name m_id m_count m_completed
m_name="$(jq -r '.name // "unnamed"' "$mission_file")"
m_id="$(jq -r '.mission_id // ""' "$mission_file")"
m_count="$(jq '.milestones | length' "$mission_file")"
m_completed="$(jq '[.milestones[] | select(.status == "completed")] | length' "$mission_file")"
printf '\n\n# Active Mission Context\n\n'
cat <<MISSION_EOF
An active orchestration mission has been detected in this project.
**Mission:** $m_name
**ID:** $m_id
**Status:** $status
**Milestones:** $m_completed / $m_count completed
## MANDATORY First Actions
1. Load \`~/.config/mosaic/guides/ORCHESTRATOR-PROTOCOL.md\` (mission lifecycle protocol)
2. Read \`docs/MISSION-MANIFEST.md\` for full mission scope, milestones, and success criteria
3. Read \`docs/scratchpads/${m_id}.md\` for session history, decisions, and corrections
4. Read \`docs/TASKS.md\` for current task state (what is done, what is next)
5. Do NOT begin any coding or planning until you have read all four documents above
You are resuming an existing mission. The state files are the source of truth.
MISSION_EOF
fi
fi
}
# Ensure runtime contract is present at the runtime's native config path.