phase-gate-sequence
Skill2 starsChanged 8 months agoApache-2.0View on GitHub
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/).
In this repository27 other files it gives its agents.
- adopt-test-2/AGENTS.mdAGENTS.md
- adopt-test-3/AGENTS.mdAGENTS.md
- adopt-test/AGENTS.mdAGENTS.md
- AGENTS.mdAGENTS.md
- {{cookiecutter.project_slug}}/AGENTS.mdAGENTS.md
- docs/AGENTS.mdAGENTS.md
- .github/agents/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- agent-file-authoringSkill
- conventional-commitSkill
- corpus-sweepSkill
- deep-research-sprintSkill
- delegation-routingSkill
- prompt-archaeologySkill
- pr-review-replySkill
- pr-review-triageSkill
- rate-limit-resilienceSkill
- research-epic-planningSkill
- secondary-research-sprintSkill
- session-managementSkill
- session-retrospectiveSkill
- skill-authoringSkill
- source-cachingSkill
- sprint-planningSkill
- transcript-extractionSkill
- validate-before-commitSkill
- workplan-scaffoldSkill
The file
We split this skill into the rules it gives an agent
11 rules. About 0 are common, 6 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈6
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 39
Run this sequence after every ## Phase N Output write, before delegating the next domain phase.
- Distinctive: line 43
Before any complex phase execution, run the orchestration loop detector:
- Very specific: line 51
If loop_detected: false → proceed to Step 1
- Very specific: line 52
If loop_detected: true → do not execute.
- Distinctive: line 58
If the scratchpad exceeds 2000 lines:
- Distinctive: line 95
All orchestrators must check before high-cost delegations (e.g., research scout with 3+ parallel scouts).
- Very specific: line 134
If the completed phase was a long research, synthesis, or multi-file editing delegation, recommend /compact before the next delegation.
- Distinctive: line 140
Pause all delegation immediately: when any of the following is true:
- Very specific: line 147
Write ## Context Window Checkpoint to the scratchpad: active phase + status, committed vs.
- Distinctive: line 148
Commit and push all in-progress changes.
- Distinctive: line 150
Do not proceed until the user resumes via the handoff prompt.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Phase Gate Sequence
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.
Beliefs & Context
- Governing axiom: Axiom 2 — Algorithms Before Tokens — deterministic procedure over repeated instruction
- GitHub issue: #79 — Skills as Decision Codifiers
- Formal FSM spec:
data/phase-gate-fsm.yml— machine-readable state specification for this gate loop (states: INIT, PHASE_RUNNING, GATE_CHECK, COMPACT_CHECK, COMMIT, CLOSED) - Agents that use this skill: Executive Orchestrator, Executive Researcher, Executive Fleet, Executive Docs
- Foundation docs:
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)
Workflow
Run this sequence after every ## Phase N Output write, before delegating the next domain phase.
Step 0: Loop Audit (Pre-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"- If
loop_detected: false→ proceed to Step 1 - If
loop_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.
Step 1 — Prune
If the scratchpad exceeds 2000 lines:
uv run python scripts/prune_scratchpad.pyStep 1.5 — Pre-Delegation Rate-Limit Gate (Sprint 18+)
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)
fiIntegration: This check prevents cascading rate-limit failures mid-phase. If blocked:
- Log the gate decision to scratchpad under
## Rate-Limit Gate Output - Defer the delegation to the next session, OR
- Sleep for recommended duration and monitor for consecutive failures (circuit-breaker)
Note: 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).
Step 2 — Write Pre-Compact Checkpoint
Append ## Pre-Compact Checkpoint to the scratchpad with:
- What is complete (include commit SHAs)
- What is next
- Any open questions or blockers
Step 3 — Commit In-Progress Changes (Orchestrator)
Orchestrator commits in-progress changes via terminal:
git add -A && git commit -m "chore: pre-compact checkpoint — Phase N complete"Step 4 — Pre-Review Grep Sweep
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"
fiFix any matches before invoking Review.
Step 5 — Review Gate
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.
Step 6 — Compact Recommendation
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.
Context Window Alert — Trigger Conditions
Pause all delegation immediately when any of the following is true:
- Compaction has occurred in this session, OR
- The user signals compaction is becoming frequent, OR
- You detect you are reconstructing already-explored context (re-reading the same file, re-running the same search)
When triggered:
- Write
## Context Window Checkpointto 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. - Commit and push all in-progress changes.
- Present the session handoff prompt template from
executive-orchestrator.agent.mdlines 215–236 — fill in bracketed fields from the scratchpad. - Do not proceed until the user resumes via the handoff prompt.
Completion Criteria
The phase gate is correctly applied for a given phase when:
## Pre-Compact Checkpointexists in the scratchpad for every completed domain phase.## Review Outputwith APPROVED verdict exists before the next domain phase was delegated.- All phase deliverables are committed at gate time — no in-progress changes left dangling.
- Grep sweep ran clean (or violations were fixed before review was requested).
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.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

