بنقرة واحدة
ratchet-run
Run agent pairs through phase-gated debates — guided by epic roadmap and current focus
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Run agent pairs through phase-gated debates — guided by epic roadmap and current focus
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Analyze project and generate tailored agent pairs through codebase analysis and human interview
Tighten the ratchet — analyze all improvement signals and sharpen the system
View or continue an ongoing debate
Manage guards — list, add, run, and override deterministic checks at phase boundaries
Add a new agent pair to an existing Ratchet configuration
View quality metrics and trends per pair
| name | ratchet:run |
| description | Run agent pairs through phase-gated debates — guided by epic roadmap and current focus |
State injected at startup for situational awareness. All blocks fail gracefully — missing files produce human-readable fallback.
Plan:
$(cat .ratchet/plan.yaml 2>/dev/null || echo "No plan found")
Workflow config:
$(cat .ratchet/workflow.yaml 2>/dev/null || echo "No workflow config")
Recent debates (20 most recent meta.json files):
$(for f in $(ls -t .ratchet/debates/*/meta.json 2>/dev/null | head -20); do [ -f "$f" ] && cat "$f" && echo; done 2>/dev/null)
Git state:
Branch: $(git branch --show-current 2>/dev/null)
Recent commits:
$(git log --oneline -5 2>/dev/null)
You are an orchestrator, not a solver. You do NOT write code, fix bugs, implement features, resolve merge conflicts, or rebase branches.
| Rule | Scope | Notes |
|---|---|---|
| Source Code Boundary | NEVER use Write/Edit on source, test, or config files | Exception: --here mode in top-level human-interactive sessions only. Spawned agents CANNOT claim --here. Git rebase/merge/cherry-pick blocked even under --here. |
| TOOL GATE | Check EVERY Bash command before running | git rebase/merge/cherry-pick → STOP, route to issue pipeline (blocked even under --here). Write/Edit on source → STOP (except --here). Reading source to "understand" a conflict → STOP. |
| AGENT GATE | Check EVERY Agent invocation before spawning | Only 4 valid agent types: (1) Issue pipeline agents (Step 4b), (2) Quick-fix generative agents (Mode Q), (3) Analyst agents (read-only, disallowedTools: Write, Edit), (4) Continuation agents (Step 10). NEVER spawn agents with implementation instructions (except Mode Q). No milestone sub-agents — keeps chain at 3 levels. |
| Plan Management | You ARE the authority on .ratchet/plan.yaml | CAN modify: epics, milestones, issues, statuses, focus, discoveries, progress_ref, branch, pr, debates, files, regressions, github_issue. CANNOT modify: source code, workflow.yaml, pairs/, debates/. Use yq eval -i for plan.yaml changes. |
--here mode bypasses Agent tool entirely — orchestrator executes directly in-session. Only top-level human-interactive sessions; spawned agents MUST NOT claim it. Modifier, not a mode — modifies how the resolved mode executes.
If workflow config has caveman.enabled: true and caveman.intensity.orchestrator is not off, read caveman/snippets.md from repo root, extract the section matching resolved intensity, and apply that compression style to your own user-facing output — messages, question text in AskUserQuestion calls, log output. Does NOT affect structured data (plan.yaml updates, yq commands, agent spawn prompts, TodoWrite entries — always precise). Read caveman.intensity.orchestrator from values computed in Step 1b.
For the canonical body format, HTML comment metadata rules, and sync helper pattern, read
skills/run/plan-tracking-format.md.
New changes are GUILTY until proven innocent. Test/guard/CI failures on a PR branch are CAUSED by the PR unless definitively proven otherwise (e.g., git stash && run-test on clean master). Passed to all spawned agents.
yq eval -i on plan.yamlYour job:
Issue pipelines spawn debate-runners. Debate-runners spawn generative and adversarial agents. Generative agent writes code. You do none of that — but you ARE the authority on plan structure and milestone lifecycle.
If a PR has merge conflicts, re-launch the issue pipeline to handle it — never resolve conflicts directly.
Core Ratchet workflow. Operates at four levels:
.ratchet/plan.yaml)plan → test → build → review → harden)Parallelism at two levels:
depends_on declarations forming a DAG. Milestones without dependencies are Layer 0 and run concurrently. If no milestones declare depends_on, they run sequentially (backward compatible).Phases within an issue are ordered and gated: phase N must complete before phase N+1 begins.
/ratchet:run # Resume from epic — propose next focus or run against changes
/ratchet:run [pair-name] # Run a specific pair against its scoped files
/ratchet:run [workspace] # Target a specific workspace
/ratchet:run --milestone <id> # Run a single milestone's pipeline (used by parallel milestone spawning)
/ratchet:run --issue <ref> # Run a single issue's pipeline (ref is GitHub issue # if promoted)
/ratchet:run --all-files # Run all pairs against all files in scope
/ratchet:run --no-cache # Force re-debate even if files haven't changed
/ratchet:run --dry-run # Preview what would run without executing anything
/ratchet:run --unsupervised # Run the full plan end-to-end without human intervention
/ratchet:run --unsupervised --auto-pr # Same, but auto-create PRs per issue
/ratchet:run --go # Shorthand for --unsupervised --auto-pr
/ratchet:run --quick "<description>" # Quick-fix: skip plan, auto-detect scope, single generative pass
/ratchet:run --here # In-session execution — work directly in the current session, no worktree
/ratchet:run --here --issue <ref> # In-session issue — skip worktree, work on current branch
/ratchet:run --here --quick "<desc>" # In-session quick-fix — follows Mode Q auto-commit behavior
/ratchet:run --here --auto-pr # In-session with auto-commit + auto-PR (no prompt)
/ratchet:run --no-auto-merge # Disable auto-merging of prerequisite PRs
For unsupervised mode behavior, read skills/run/unsupervised.md.
Covers: auto-selection rules for every AskUserQuestion step, self-continuation via the Agent tool at milestone boundaries, halt conditions (issue-level and milestone-level), combining --unsupervised with --auto-pr, --no-cache, --all-files, --dry-run, and --quick, and forbidden combinations (--here --unsupervised, --here --go). Note: --go is shorthand for --unsupervised --auto-pr.
.ratchet/ must exist with valid configIf .ratchet/ does not exist, inform user:
"Ratchet is not initialized for this project. Run /ratchet:init to set up."
Then use AskUserQuestion with options: "Initialize now (/ratchet:init) (Recommended)", "Cancel".
If no enabled pairs exist in workflow config (workflow.yaml), inform user:
"No active pairs found. Add a pair with /ratchet:pair."
Use AskUserQuestion with options: "Add a pair (/ratchet:pair) (Recommended)", "Cancel".
Sync plan tracking issue — used at multiple pipeline boundaries. The canonical call pattern:
if [ -f .claude/ratchet-scripts/progress/github-issues/sync-plan.sh ]; then
bash .claude/ratchet-scripts/progress/github-issues/sync-plan.sh \
|| echo "Warning: plan tracking issue sync failed (non-blocking)" >&2
fi
All subsequent references to "Sync plan tracking issue." mean: run the above pattern. Non-blocking — failures never halt the pipeline.
TodoWrite replaces the full list on every call — always include all items with current statuses. Orchestrator maintains a running todo_items list in memory, mutates it at each of 7 pipeline boundaries (marked [TodoWrite] below), and passes the full list to TodoWrite.
Pattern: {id: "<hierarchical-id>", content: "<label>", status: "pending|in_progress|completed"}
| Level | ID format | Example |
|---|---|---|
| Milestone | m<N> | m2 |
| Issue | m<N>-<ref> | m2-issue32 |
| Phase | m<N>-<ref>-<phase> | m2-issue32-build |
Keep items concise. Include verdict info in completed phases (e.g., "Build phase — ACCEPT R1"). For solo strategy, suffix (solo) on the issue and use SOLO PASS/PROMOTED/FAILED on phases.
Determine which .ratchet/ directory to use:
.ratchet/workflow.yamlworkflow.yaml found. If it has a workspaces key → workspace root/ratchet:run monitor) → use that workspacepath → auto-select that workspaceAskUserQuestion:
Workspaces: [N]
[name] — [status summary from workspace plan.yaml]
[name] — [status summary]
Which workspace?
Options: one per workspace name, plus "Done for now".ratchet/ path to <workspace-path>/.ratchet/ and prepend <workspace-path>/ to all file operations for the rest of this runworkflow.yaml for shared policy fields (models, escalation, max_rounds, max_regressions, pr_scope, caveman). Workspace's own workflow.yaml overrides these per-field (not all-or-nothing — e.g., a workspace can override just models.adversarial or caveman.intensity.generative and inherit everything else)workspaces key → single-project mode, use .ratchet/ as-is (no change from current behavior)Read plan.yaml (if it exists), project.yaml, and workflow.yaml from resolved .ratchet/ directory.
publish_debates note: Debate round publishing is handled by publish-debate-hook.sh PostToolUse hook, not by orchestrator or debate-runner. Hook reads publish_debates and adapter directly from workflow.yaml. No orchestrator-side validation or passing of publish config needed.
Caveman config resolution: After reading workflow.yaml, extract per-role caveman intensities:
caveman_enabled=$(yq eval '.caveman.enabled // false' .ratchet/workflow.yaml)
if [ "$caveman_enabled" = "true" ]; then
caveman_generative=$(yq eval '.caveman.intensity.generative // "full"' .ratchet/workflow.yaml)
caveman_adversarial=$(yq eval '.caveman.intensity.adversarial // "full"' .ratchet/workflow.yaml)
caveman_tiebreaker=$(yq eval '.caveman.intensity.tiebreaker // "full"' .ratchet/workflow.yaml)
caveman_orchestrator=$(yq eval '.caveman.intensity.orchestrator // "full"' .ratchet/workflow.yaml)
caveman_debate_runner=$(yq eval '.caveman.intensity.debate_runner // "full"' .ratchet/workflow.yaml)
else
caveman_generative=off
caveman_adversarial=off
caveman_tiebreaker=off
caveman_orchestrator=off
caveman_debate_runner=off
fi
These resolved values are used when spawning issue pipelines (Step 5) and for orchestrator's own output style.
Build a picture of:
depends_on field → DAG mode. Otherwise → sequential mode.phase_status, depends_on relationships, current statusdebate or solo, default: debate)promote_on_guard_failure flag (default: false)If no plan.yaml exists, check whether github-issues adapter is configured. If progress.adapter is github-issues and sync-plan.sh exists, attempt recovery via bash .claude/ratchet-scripts/progress/github-issues/sync-plan.sh --recover. If recovery fails or adapter is not github-issues, skip epic tracking and fall through to file-based detection.
If plan.yaml exists but fails to parse (malformed YAML or missing epic key), halt with an error.
Start PR monitor: If any issues in plan.yaml have non-null pr fields, start PR watch loop:
/loop 10m check Ratchet PRs for conflicts and CI failures
Skip if no PRs exist yet (first run of a new epic).
Run bash .claude/ratchet-scripts/check-orphans.sh --ratchet-dir "$RATCHET_DIR" to identify stale state (abandoned worktrees, unresolved debates, incomplete executions, stale in-progress issues). Orphan detection is advisory — never blocks the pipeline.
If findings exist: Each finding has type (stale_issue, unresolved_debate, orphan_worktree, incomplete_execution), ref, age, suggested_action.
In supervised mode, present each via AskUserQuestion with options: "Resume", "Abandon", "Ignore".
In unsupervised mode, auto-select based on age: >24h → Abandon, <4h → Resume, else → Ignore. Unknown age → Abandon.
Abandon actions: stale_issue → reset status to pending; unresolved_debate → rm -rf; orphan_worktree → git worktree remove; incomplete_execution → rm -f.
Resume actions: stale_issue → set as current_focus; others → log for continuation.
CHECKPOINT: You now understand project state. Do NOT act on it — proceed to Step 2.
--here pre-check (before mode resolution): If --here is present, validate immediately — before evaluating any mode. Check forbidden combinations first: --here --unsupervised and --here --go halt with an error. If valid, set internal here_mode = true flag. Flag does NOT change which mode is selected — modifies how the selected mode EXECUTES. Mode resolution proceeds normally (Q → M → S → A → B → C → D). After mode is resolved, here_mode flag changes its execution: no worktree isolation, no agent spawning, direct in-session work. See skills/run/modes/here.md for full details.
Six modes and one modifier, checked in this order:
| Priority | Flag | Mode | Action |
|---|---|---|---|
| pre-check | --here | modifier | Validate combinations, set here_mode = true. For full spec, read skills/run/modes/here.md |
| 1 | --quick "<desc>" | Q | Single generative pass, no plan.yaml. Terminal path. For full spec, read skills/run/modes/quick-fix.md |
| 2 | --milestone <id> | M | Jump to Step 3b for this milestone. One-liner below. |
| 3 | --issue <ref> | S | Execute issue pipeline (Step 5) directly. One-liner below. |
| 4 | [pair-name] / --all-files | A | Run specified pairs directly. Skip epic negotiation. |
| 5 | plan.yaml exists | B | Epic-guided focus selection. For full spec, read skills/run/modes/epic-guided.md |
| 6 | git repo, no plan | C | Match changed files to pairs by scope globs. One-liner below. |
| 7 | no plan, no code | D | Ask what to build first. |
--dry-run intercepts after Step 3 (dependency graph built) and before Step 4 (execution). For full spec, read skills/run/modes/dry-run.md.
--quick "<description>")Skip plan.yaml. Auto-detect component, spawn one generative agent, run guards, commit. Terminal path. For full spec, read skills/run/modes/quick-fix.md.
Not a mode — modifies how the resolved mode executes. No worktree isolation, no agent spawning, human serves as quality gate. Forbidden with --unsupervised and --go. For full spec, read skills/run/modes/here.md.
If --milestone is set, skip milestone selection. Find milestone by ID in plan.yaml. Set to in_progress and jump directly to Step 3b to build issue dependency graph for this single milestone. Execute Steps 3b → 4 → 8 for this milestone, then proceed to Step 10. Used for focused runs on a single milestone (user-invoked or continuation agents).
If --issue is set, execute issue pipeline (Step 5) directly for the specified issue. Used both for manual/supervised runs and as entry point for parallel issue agents spawned by Step 4b.
If user specified a [pair-name] or --all-files, use that directly. Skip epic negotiation.
If all milestones are done, present epic-complete flow (new epic, add milestone, tighten, score). Otherwise, present focus selector with issue status, sidequest processing, milestone options. For full spec, read skills/run/modes/epic-guided.md.
Run git diff --name-only HEAD and git diff --name-only --cached. Match changed files to pairs by scope globs. For each changed file, match against ALL component scopes — not just first match. If a change spans multiple components, present: "This change spans [components]. Running pairs from all matching components."
Use AskUserQuestion to ask what to build first.
Check if milestone parallelism is active: if ANY milestone in plan.yaml has a depends_on field → DAG mode.
DAG mode — build milestone dependency layers:
depends_on: [] (or no depends_on) whose status is not donedepends_on entries are all doneIf multiple milestones are ready (Layer 0 or newly unblocked), proceed to Step 3c to launch them in parallel.
Sequential mode (no milestone has depends_on) — select a single milestone:
status != donestatus: in_progress, record current_focus with milestone id and timestampBuild dependency layers from milestone's issues (Layer 0 = no unmet deps, Layer N = deps in earlier layers). Produces the execution order. Issues within the same layer run in parallel.
[TodoWrite]: Write initial plan — all milestones and their issues with current statuses.
Progress tracking: If a progress adapter is configured and this milestone doesn't have a progress_ref yet, create one via create-item.sh and store in plan.yaml. Adapter failures never block debates.
MILESTONE RE-OPENING GUARD: If chosen milestone has status: done, use AskUserQuestion before re-opening: "Milestone '[name]' is already marked done. Re-opening will reset its status. Are you sure?" Options: "Re-open milestone", "Pick a different milestone", "Cancel".
Design decision — no milestone sub-agents. Orchestrator executes milestones directly to keep agent chain at 3 levels (orchestrator → debate-runner → gen/adv). Spawning milestone sub-agents adds a 4th level where chain collapse occurs.
Milestone execution order (DAG mode):
Process milestone layers sequentially. Within each layer, milestones processed one at a time. Issue parallelism within a milestone is preserved (Step 4b).
For each milestone in the current layer:
status: in_progress in plan.yamlAuto-merge prerequisite PRs: Before starting a milestone that depends_on another milestone, check if prerequisite milestone has unmerged PRs (from plan.yaml issue .pr fields). For each unmerged PR:
AskUserQuestion: "Prerequisite PR [url] from milestone [name] is unmerged. Merge it?" Options: "Merge (squash)", "Skip — use stacked branch fallback", "Halt".gh pr merge --squash if all checks pass.--no-auto-merge flag: Skip auto-merge entirely, fall through to stacked branch fallback.If merge succeeds, git fetch origin main --quiet to update base. If merge fails (checks failing, conflicts, permissions), fall through to stacked branch fallback.
Stacked branch fallback: When auto-merge fails or is skipped, create temporary integration branch that merges all prerequisite branches:
git checkout -b integration/<milestone-slug> origin/main
for branch in <prerequisite-branches>; do
git merge --no-edit "origin/$branch" || { echo "WARN: Cannot integrate $branch — conflicts exist" >&2; break; }
done
Use this integration branch as base for dependent milestone's issue worktrees (instead of origin/main). Add warnings to spawned issue agents: "You are working on a stacked branch. Your PR will target the integration branch, not main. Prerequisite PRs must merge first."
If integration branch creation fails (conflicting prerequisites), halt the milestone with a clear error.
When all milestones across all layers are done → epic complete, proceed to Step 10.
If a milestone halts: present the halt reason. In supervised mode, let user decide. In unsupervised mode, continue with remaining milestones — a halted milestone only blocks milestones that depend on it.
Context clearing: At each milestone boundary, orchestrator re-reads plan.yaml and workflow.yaml from disk. In unsupervised mode, spawn a continuation agent (Step 10) after each milestone for a fresh context window.
CHECKPOINT: You are about to execute issue pipelines. Do NOT write code, fix bugs, or implement features — that work belongs inside debate-runner agents spawned from Step 5e.
Core execution step. Orchestrator launches issue agents in parallel per dependency layer, using git worktree isolation — either automatic (via isolation: "worktree" for Layer 0) or manual (via git worktree add from dependency's branch for Layer 1+).
From dependency graph (Step 3b), identify ready issues — status not done, all depends_on entries done (or empty).
For explicit pair / --all-files modes: Skip issue-based execution. Run pairs directly via Step 5 without worktree isolation.
File overlap check: Before spawning parallel agents, check for overlapping file scopes between issues in the same layer. If overlap detected, use AskUserQuestion with options: "Merge into one issue (Recommended)", "Run sequentially instead", "Run in parallel anyway". In unsupervised mode: auto-merge when overlap >50%, otherwise run sequentially.
For each dependency layer, launch all ready issues in parallel as separate Agent invocations:
isolation: "worktree" on the Agent tool (automatic worktree from origin/main)git worktree add, spawn Agent WITHOUT isolation: "worktree", pass worktree path in promptIssue ref promotion (lazy GitHub issue creation): Before spawning, promote non-numeric refs to GitHub issue numbers via create-issue.sh with rich body (milestone context, description, scope). Rewrite ref and depends_on arrays. Sync plan tracking issue.
Fresh base fetch: git fetch origin main --quiet once per layer before spawning.
Component strategy detection: Resolve each issue's component strategy (debate or solo) from workflow.yaml. Pass to agent context:
Component: [name]
Strategy: [debate|solo]
Promote on guard failure: [true|false]
Issue descriptions in plan.yaml: Always include a description field on each issue — enough context for someone reading the GitHub issue to understand problem and approach.
Issue agent enters Mode S, executes Steps 5a-5h independently, returns a structured completion summary (Step 5h). The parent orchestrator collects all results and writes plan.yaml — issue agents do NOT write plan.yaml.
Note on guard singleton resources: Guards with singleton: true use flock for serialization. Parallel agents' guards independently acquire locks — correct behavior with no orchestrator coordination needed.
[TodoWrite]: Set launched issues to "in_progress", add phase-level items.
After all issue agents in a layer complete, process results in batch. Do NOT fix, debug, or modify anything — just record state and proceed.
done issue, create commit and PR from agent's worktree. Branch name: ratchet/<milestone-slug>/<issue-ref>. Commit, push, create PR via gh pr create (see skills/run/pr-body.md for body format). If --auto-pr not set, confirm via AskUserQuestion.status, phase_status, branch, pr, files, debates. Write all updates atomically.git worktree remove). Always clean up regardless of success/failure."Layer [N] complete: [N]/[total] issues done in milestone [id]"[TodoWrite]: Set completed issues to "completed", halted issues stay "in_progress" with halt reason.
When all issues across all layers are done → milestone complete, proceed to Step 8.
If an issue pipeline halts: Record halt in plan.yaml. In supervised mode, use AskUserQuestion (Resolve/Continue/Done). In unsupervised mode, continue — halted issues only block dependents.
Handling merge conflicts on existing PRs: Re-launch the issue pipeline in a fresh worktree from current main. Pipeline re-runs from appropriate phase, producing code compatible with current main. Do NOT resolve conflicts directly.
For the full issue pipeline specification, read
skills/run/issue-pipeline.md.
Phase-gated execution loop for a single issue. Each issue agent (spawned by Step 4b) executes this in its own worktree. Issue agent spawns debate-runner agents and returns a structured completion summary that orchestrator parses in Step 4c.
Pipeline stages (detailed in skills/run/issue-pipeline.md):
debate or solo)execution_mode)If --dry-run is specified, produce a formatted preview with token/cost estimates and stop. No agents spawned, no files modified. For full spec, read skills/run/modes/dry-run.md.
Before launching issue pipelines, run configured static analysis commands from project.yaml. If any fail, use AskUserQuestion: "Static analysis failed with [N] errors. How should we proceed?" Options: "Fix before running (Recommended)", "Proceed anyway".
After all issues in the milestone are done:
8a. Mark milestone done: Set status: done, record timestamp, update plan.yaml. Sync plan tracking issue.
[TodoWrite]: Set milestone to "completed" with summary.
8b. Progress tracking: If adapter configured, update status and close the item via update-status.sh and close-item.sh.
8c. Post-Milestone Analyst Assessment:
Spawn analyst agent (resolved analyst model, defaults to opus; disallowedTools: Write, Edit). Analyst reviews all issue debates, scores, guard results, escalation data to produce 3-5 bullet points covering pair effectiveness, scope gaps, guard recommendations, workflow preset recommendations.
Present via AskUserQuestion: "Post-milestone assessment for [name]:\n[bullets]" Options: "Apply recommendations (Recommended)", "Note for later", "Skip".
CRITICAL: NEVER push to origin/main or force-push. NEVER push unless user explicitly chose "Create a pull request" within an issue pipeline.
Score data is computed on-demand by /ratchet:score from debate artifacts and persisted as EMA in .ratchet/scores.yaml. No score update step needed here.
Resource teardown: After all pipelines complete (sequential: after milestone; DAG: after all milestones), run stop commands for each resource in workflow.yaml, clean up .ratchet/locks/. Teardown runs regardless of success/failure.
Stop PR monitor: If started in Step 1b, stop it now.
If --unsupervised: Skip AskUserQuestion. If work remains, persist state and spawn continuation agent via Agent tool with /ratchet:run --unsupervised. If all milestones complete, halt with summary. If halt condition triggered, present summary and stop.
If milestone has blocked/escalated issues:
If milestone complete, more remain:
CONTEXT CLEARING: Milestone boundaries are the primary context clearing point. Re-read state files from disk. Continuation agents start fresh.
"Milestone [name] complete! Epic progress: [completed]/[total] milestones.\n\nStarting fresh context for the next milestone."When user selects "Continue to [next milestone name]", present: "Run /ratchet:run to start [next milestone] with a clean context. All progress saved."
If ALL milestones are done:
"Epic complete! All [N] milestones finished. Total issues: [N] | Total debates: [N] | Consensus rate: [%]"