agentleFS
EndogenAIEndogenAI/dogma/.github/skills/phase-gate-sequence/SKILL.md

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/).

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
  1. Very specific:

    Run this sequence after every ## Phase N Output write, before delegating the next domain phase.

    line 39
  2. Distinctive:

    Before any complex phase execution, run the orchestration loop detector:

    line 43
  3. Very specific:

    If loop_detected: false → proceed to Step 1

    line 51
  4. Very specific:

    If loop_detected: true → do not execute.

    line 52
  5. Distinctive:

    If the scratchpad exceeds 2000 lines:

    line 58
  6. Distinctive:

    All orchestrators must check before high-cost delegations (e.g., research scout with 3+ parallel scouts).

    line 95
  7. Very specific:

    If the completed phase was a long research, synthesis, or multi-file editing delegation, recommend /compact before the next delegation.

    line 134
  8. Distinctive:

    Pause all delegation immediately: when any of the following is true:

    line 140
  9. Very specific:

    Write ## Context Window Checkpoint to the scratchpad: active phase + status, committed vs.

    line 147
  10. Distinctive:

    Commit and push all in-progress changes.

    line 148
  11. Distinctive:

    Do not proceed until the user resumes via the handoff prompt.

    line 150

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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-First
    • executive-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.py

Step 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)
fi

Integration: 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"
fi

Fix 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:

  1. Write ## 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.
  2. Commit and push all in-progress changes.
  3. Present the session handoff prompt template from executive-orchestrator.agent.md lines 215–236 — fill in bracketed fields from the scratchpad.
  4. 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 Checkpoint exists in the scratchpad for every completed domain phase.
  • ## Review Output with 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.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.