Encodes the mandatory 6-step inter-phase checkpoint sequence that executive-tier agents run after every domain phase and before delegating the next. Includes the context window alert trigger conditions and session handoff prompt template. USE FOR: running the post-phase prune → checkpoint → commit → grep sweep → review → compact sequence; triggering the context-window alert and generating a handoff prompt; ensuring no domain phase is skipped or batched without a gate record. DO NOT USE FOR: deciding which agent to delegate to (use delegation-routing); session start/close lifecycle (use session-management); individual script command syntax (see docs/toolchain/).
This skill enacts the Algorithms-Before-Tokens axiom from MANIFESTO.md: the 6-step gate is a deterministic algorithm encoded once and shared across all executive agents, eliminating parallel re-derivation and enforcing consistent phase discipline fleet-wide.
data/phase-gate-fsm.yml — machine-readable state specification for this gate loop (states: INIT, PHASE_RUNNING, GATE_CHECK, COMPACT_CHECK, COMMIT, CLOSED)AGENTS.md — compaction-aware writing, commit discipline, Programmatic-Firstexecutive-orchestrator.agent.md — canonical per-phase sequence (lines 169–196) and context window alert protocol (lines 198–242)Run this sequence after every ## Phase N Output write, before delegating the next domain phase.
Before any complex phase execution, run the orchestration loop detector:
uv run python scripts/detect_orchestration_loop.py \
--task "<current-phase-name>" \
--scratchpad ".tmp/$(git branch --show-current | tr '/' '-')/$(date +%Y-%m-%d).md"
loop_detected: false → proceed to Step 1loop_detected: true → do not execute. Write to scratchpad: ## Loop Detected — [task] — iteration [N]; awaiting user direction. Surface to user: "I detected that I attempted this task [N] iterations ago. What should I do differently?"Encoding point: Governed by AGENTS.md § Guardrails. Script: scripts/detect_orchestration_loop.py. Research basis: docs/research/orchestrator-autopilot-failure.md § Recommendation 4.
If the scratchpad exceeds 2000 lines:
uv run python scripts/prune_scratchpad.py
Before delegating the next phase, check the rate-limit budget gate (see rate-limit-resilience SKILL, issue #325):
# Get current token budget (from tracking or API)
CURRENT_BUDGET=75000 # example
OPERATION='delegation' # or 'phase_boundary', 'fetch_source', etc.
PROVIDER='claude'
GATE_RESULT=$(uv run python scripts/rate_limit_gate.py "$CURRENT_BUDGET" "$OPERATION" --provider "$PROVIDER" --audit-log)
if echo "$GATE_RESULT" | grep -q '"safe": true'; then
# Safe: proceed with delegation
echo "Gate APPROVED: safe to proceed"
else
# Blocked: defer or sleep
SLEEP_SEC=$(echo "$GATE_RESULT" | grep -o '"recommended_sleep_sec": [0-9]*' | cut -d: -f2)
echo "Gate BLOCKED: Rate-limited. Recommended sleep: ${SLEEP_SEC}s"
echo "Defer this delegation to next session or sleep and retry"
# Option 1: Write to scratchpad and stop
# Option 2: Sleep and retry (caution: uses token budget)
fi
Integration: This check prevents cascading rate-limit failures mid-phase. If blocked:
## Rate-Limit Gate OutputNote: This is new infrastructure from Phase 0 (Sprint 18, issue #325). Phase 1 research (docs/research/ai-cognitive-load.md, issue #315) validates this gate: token-heavy workflows with >4 handoffs exceed working memory capacity; rate-limit gates reduce decision surface and human error. Integration point: AGENTS.md § Rate-Limit Resilience Throughout MANIFESTO Axioms shows how this gate operationalizes Algorithms-Before-Tokens (#319 trendslop research), Local-Compute-First (#317 vendor lock-in), and Endogenous-First (#315 cognitive load) axioms.
All orchestrators must check before high-cost delegations (e.g., research scout with 3+ parallel scouts).
Append ## Pre-Compact Checkpoint to the scratchpad with:
Orchestrator commits in-progress changes via terminal:
git add -A && git commit -m "chore: pre-compact checkpoint — Phase N complete"
Scans the entire .github/ directory (all agent and skill files) for known heading-contract violations and erroneous patterns — not scoped to changed files only, since stale patterns can exist anywhere.
if grep -r "Phase N Review Output\|Fetch-before-check" .github/; then
echo "ERROR: known pattern violations found — fix before requesting review"
elif [ $? -eq 1 ]; then
echo "grep sweep clean"
else
echo "ERROR: grep failed during sweep — investigate before requesting review"
fi
Fix any matches before invoking Review.
Invoke the Review agent with the changed file list and scratchpad location. Append verdict to the scratchpad under ## Review Output. Do not advance to the next phase until APPROVED.
If the completed phase was a long research, synthesis, or multi-file editing delegation, recommend /compact before the next delegation. After any compaction event: re-read the scratchpad and workplan from disk before continuing.
Pause all delegation immediately when any of the following is true:
When triggered:
## Context Window Checkpoint to the scratchpad: active phase + status, committed vs. in-progress deliverables (with SHAs), last agent delegated + ≤100-token return summary, single next concrete step, open blockers.executive-orchestrator.agent.md lines 215–236 — fill in bracketed fields from the scratchpad.The phase gate is correctly applied for a given phase when:
## Pre-Compact Checkpoint exists in the scratchpad for every completed domain phase.## Review Output with APPROVED verdict exists before the next domain phase was delegated.Exit condition: The loop terminates when ## Session Summary has been written and uv run python scripts/prune_scratchpad.py --force has run — see the session-management skill for the full session close sequence.