Graph Exec
Execute multi-file engineering tasks as a token-optimized, deterministic directed acyclic graph (DAG) of isolated workers in separate git worktrees, with typed JSON contracts, zero-token verification gates, and strict retry caps.
Editor's Note
Ensure the project is a git repository with a clean working tree (`git status --porcelain` empty) before starting. Choose a worker mechanism in this order: 1) Subagents from the harness, 2) Headless agent CLI, 3) Degraded mode if necessary.
When to Use It
- Implementing multi-step features or refactorings as a graph/DAG workflow
- Running tasks that require parallel execution across multiple files
- Executing tasks with strict retry caps and verification gates
SKILL.md
SkillsHunter provides this listing for informational purposes only. Review the skill’s source, license, and required permissions before use. You are responsible for deciding whether to install or run it. Terms of Use
Graph Execution Workflow (graph-exec)
You are the Graph Orchestrator. Your job is to minimize LLM token spend by decomposing work into a Directed Acyclic Graph (DAG), isolating each node in its own git worktree, offloading all mechanical checks to zero-token scripts, and enforcing hard retry caps.
Core rule: Never write product code yourself. Only plan the DAG, dispatch nodes, run deterministic gates, and merge verified results.
<skill_dir> below is the directory containing this SKILL.md. Both scripts
run from anywhere inside the target repository:
bash <skill_dir>/scripts/node.sh start|path|commit|drop <id>: one branch (graph/<id>) and one worktree per node, outside the repository.bash <skill_dir>/scripts/gate.sh ...: scope lock plus proof commands, run in a throwaway checkout of the node's branch.
Preflight
- The project must be a git repository with a clean working tree
(
git status --porcelainempty), so every later change is attributable to a node. - Note the current branch; all merges land there. Never push unless asked.
- Pick a worker mechanism, in this order:
- Subagents from the harness (for example Claude Code's Agent/Task tool or
omp's
tasktool). Do not use a harness's own worktree isolation; the scripts own the worktrees. - Headless agent CLI started inside the node's worktree (for example
claude -p "<prompt>"orcodex exec "<prompt>"), when no subagent tool exists but such a CLI is installed. - Degraded mode: run nodes yourself, one at a time, editing only inside the node's worktree and reading only its contract and owned files. Tell the user the run is degraded; gates and merges stay identical.
- Subagents from the harness (for example Claude Code's Agent/Task tool or
omp's
Node 0 · Triage (Avoid Over-Engineering)
Before building a graph, check the scope. Every node costs a worker run plus re-reading its files, so a graph only pays off on larger work. Abort the graph and do the task directly in one turn unless at least one holds:
- Parallelism: at least 3 nodes can run in the same wave (independent, disjoint files).
- Size: the task spans roughly 10+ files or several subsystems, too much for one context to hold comfortably.
- Independent verification: a
risk: highpart needs a separate audit.
A task of ≤ 2 tightly coupled files, or one that takes < 5 minutes of direct edits, never qualifies.
On abort (the normal path for most tasks): say in one line why the graph was skipped, then do the task directly in the current checkout like any other request. No worktrees, no workers, no gate, no plan document, and nothing else in this skill applies.
Node 1 · Plan & Contract (LLM — High Effort)
Inspect the relevant codebase first. Never ask the user what the code can answer.
Grill only on material ambiguity. If requirements are still unclear after reading the code (behavior, edge cases, interfaces, scope), a wrong plan would be built in parallel by every worker, so settle it now:
- Ask one question per turn, each with your recommended answer and a one-line reason, so the user can reply in a word.
- Give every fuzzy term one canonical name and use it from then on.
- Cap at 5 questions. Record anything still open as an Assumption in the plan instead of asking more. Park questions only a running prototype can answer as Parked, out of scope.
- If you asked anything, show the plan and wait for the user's go-ahead before dispatching. If you asked nothing, proceed.
Produce a compact DAG Plan (keep it under 60 lines) containing:
- Goal & Non-Goals (2–4 bullets), plus the agreed glossary, Assumptions, and Parked items if any. Every worker receives these.
- Nodes in execution waves (
Wave 1,Wave 2, ...). Every node MUST define:id: short slug ([a-z0-9_-]+)depends_on: list of upstream node IDs (or[])owned_files: exact, disjoint list of repo-relative, forward-slash paths this node may create/modify/deleteoutcome: single concrete deliverableverify_cmd: exact shell command, run from the repo root, that deterministically proves the node worksstatic_cmd: optional fast typecheck/lint command (or"")setup_cmd: command that makes a fresh checkout runnable (e.g.npm ci --prefer-offline), or""; usually the same for every nodeeffort:low|medium|high(route cheap/fast for routine edits)read_files: optional read-only files the worker needs for context but may not edit (keeps it from exploring);[]if nonerisk:high(core business logic, auth, data integrity, public API) orlow
Disjoint Ownership Rule: No two nodes in the same wave may share any file
in owned_files. If two tasks must touch the same file, either extract a shared
interface node into an earlier wave or sequence them via depends_on.
Right-size nodes. Every node adds a worker run. Merge tiny nodes that touch related files into one; split only where nodes can really run in parallel or a single worker would carry too much context.
Re-check triage on the finished plan. The plan shows the real shape of the
work. If no wave has 3+ nodes, the plan has no risk: high node, and the task
is not large (the Size rule), abort here: say so in one line and carry out the
plan directly as a checklist in the current checkout, with no worktrees or
workers. Planning cost is already spent; do not add worker cost on top.
Node 2 · Parallel Execution (Isolated Workers)
Execute the DAG wave by wave. For each node in the wave:
WT=$(bash <skill_dir>/scripts/node.sh start <id>): branchgraph/<id>at the currentHEAD, which already contains every merged upstream node.- Dispatch one worker per node, all nodes of the wave in parallel (one batch
call when the harness supports it). Apply
effortwhen the harness lets you choose a model or reasoning level per worker; otherwise ignore it.
For every worker:
- Context: Pass ONLY the Goal (with glossary, Assumptions, Parked), the
node's
outcome,owned_files,read_files,setup_cmd,verify_cmd, the absolute worktree pathWT, and any upstream contracts it depends on. Tell it to read only those files plus whatverify_cmdneeds. Never pass this full conversation. - Output contract: Require exactly this JSON object as the final answer. Use
the harness's structured-output or schema option when it has one; otherwise
instruct the worker to end with the JSON object and nothing else:
{ "type": "object", "properties": { "node_id": { "type": "string" }, "status": { "type": "string", "enum": ["ready", "blocked"] }, "summary": { "type": "string" }, "blocker": { "type": "string" } }, "required": ["node_id", "status", "summary"] }
Worker Rules (include in each worker prompt):
- Work ONLY inside
WT, using absolute paths under it. Never edit the main checkout. - Edit ONLY files listed in
owned_files. - Run
setup_cmdif needed, implementoutcome, and runverify_cmdinsideWTbefore finishing. - Do NOT commit, switch branches, or push; the orchestrator commits.
- Return the required JSON object. If blocked, set
status: "blocked"and explain why inblocker.
After the wave returns:
git status --porcelainin the main checkout must still be empty. If not, a worker escaped its worktree: recordgit status --porcelainoutput as the error for every node of the wave, restore the main checkout (git checkout -- . && git clean -fd; the tree was clean at preflight), and treat each of those nodes as a gate failure.- For each
readynode:bash <skill_dir>/scripts/node.sh commit <id>, then run Node 3. - A
blockednode counts as a gate failure (Node 3 routing) withblockeras the error.
Node 3 · Deterministic Gate (0 LLM Tokens)
Do NOT review the diff with an LLM. Run the gate first:
bash <skill_dir>/scripts/gate.sh \
--branch "graph/<id>" \
--owned "<comma_separated_owned_files>" \
--setup "<setup_cmd>" \
--static "<static_cmd>" \
--verify "<verify_cmd>"
--base defaults to HEAD; the scope check diffs HEAD...graph/<id>, which
measures changes from the node's fork point. The gate checks out the branch in
a throwaway worktree, rejects any changed file outside owned_files (renames
count as both paths), then runs setup, static, and verify there. On pass it
prints one line; on failure it prints the reason plus the last 60 lines of the
failing command's output.
Routing Edges (Circuit Breaker)
- Exit 0 (GATE PASS):
risk: high→ Node 4 (Semantic Audit).risk: lowwhereverify_cmdgives full coverage → skip Node 4, merge.
- Exit 1 (GATE FAIL): increment the node's retry counter.
retries < 2: dispatch a fresh worker into the same worktree (the previous attempt is already there) with only the node contract,WT, and the gate output verbatim plus "fix this". Then commit and gate again.retries == 2: trip the circuit breaker. Mark the node BLOCKED, keep its branch and worktree for the user, do not run downstream dependent nodes, and continue any independent branches.
- Exit 2: gate misuse (bad arguments or unknown ref). Fix the call; this is not a retry.
Node 4 · Semantic Audit (Read-Only LLM — Only After Gate Pass)
Triggered only for risk: high nodes that passed Node 3.
Dispatch a single read-only reviewer (a separate subagent; in degraded mode, a
fresh pass by yourself) with high effort when available. It inspects
git diff HEAD...graph/<id> against the node's outcome and checks ONLY what
scripts cannot:
- Does the logic actually satisfy edge cases and the stated outcome?
- Is the proving test genuine (no tautologies, bypassed assertions, or mocks hiding real behavior)?
Require this JSON object as its final answer:
{
"type": "object",
"properties": {
"verdict": { "type": "string", "enum": ["PASS", "REJECT"] },
"defects": { "type": "array", "items": { "type": "string" } }
},
"required": ["verdict", "defects"]
}
- REJECT: same
retries < 2circuit breaker, withdefectsas the error; re-run Node 3 on the fixed branch before auditing again. - PASS: merge.
Merge
Merge passed nodes into the current branch in wave order, one at a time:
git merge --no-ff --no-edit graph/<id>
bash <skill_dir>/scripts/node.sh drop <id>
Disjoint ownership makes conflicts a planning defect: on conflict run
git merge --abort and mark the node BLOCKED. Start the next wave only after
every node it depends on has merged, so new worktrees include upstream work.
Node 5 · Final Report
Once all waves finish (or halt on blockers), run the repo's top-level test suite once if more than one wave landed, then output a concise table:
| Node | Wave | Retries | Gate | Audit | Status |
|---|
List any BLOCKED nodes with their exact last error and their retained branch
graph/<id> and worktree (node.sh path <id>), so the user can intervene
directly. node.sh drop <id> discards one.
View original Markdown
---
name: graph-exec
description: >-
Execute multi-file engineering tasks as a token-optimized, deterministic
directed acyclic graph (DAG) of isolated workers in separate git worktrees,
with typed JSON contracts, zero-token verification gates, and strict retry
caps. Use when the user invokes graph-exec or asks to implement a multi-step
feature, refactor, or bugfix as a graph/DAG workflow with minimal token usage.
Self-gating: small or tightly coupled tasks are detected and run directly in
the normal shared checkout, with no worktrees or workers.
---
# Graph Execution Workflow (`graph-exec`)
You are the **Graph Orchestrator**. Your job is to minimize LLM token spend by
decomposing work into a Directed Acyclic Graph (DAG), isolating each node in its
own git worktree, offloading all mechanical checks to zero-token scripts, and
enforcing hard retry caps.
**Core rule:** Never write product code yourself. Only plan the DAG, dispatch
nodes, run deterministic gates, and merge verified results.
`<skill_dir>` below is the directory containing this `SKILL.md`. Both scripts
run from anywhere inside the target repository:
- `bash <skill_dir>/scripts/node.sh start|path|commit|drop <id>`: one branch
(`graph/<id>`) and one worktree per node, outside the repository.
- `bash <skill_dir>/scripts/gate.sh ...`: scope lock plus proof commands, run in
a throwaway checkout of the node's branch.
---
## Preflight
- The project must be a git repository with a **clean working tree**
(`git status --porcelain` empty), so every later change is attributable to a
node.
- Note the current branch; all merges land there. Never push unless asked.
- Pick a worker mechanism, in this order:
1. **Subagents** from the harness (for example Claude Code's Agent/Task tool or
omp's `task` tool). Do not use a harness's own worktree isolation; the
scripts own the worktrees.
2. **Headless agent CLI** started inside the node's worktree (for example
`claude -p "<prompt>"` or `codex exec "<prompt>"`), when no subagent tool
exists but such a CLI is installed.
3. **Degraded mode:** run nodes yourself, one at a time, editing only inside
the node's worktree and reading only its contract and owned files. Tell
the user the run is degraded; gates and merges stay identical.
---
## Node 0 · Triage (Avoid Over-Engineering)
Before building a graph, check the scope. Every node costs a worker run plus
re-reading its files, so a graph only pays off on larger work. **Abort the
graph and do the task directly in one turn** unless at least one holds:
- **Parallelism:** at least 3 nodes can run in the same wave (independent,
disjoint files).
- **Size:** the task spans roughly 10+ files or several subsystems, too much for
one context to hold comfortably.
- **Independent verification:** a `risk: high` part needs a separate audit.
A task of ≤ 2 tightly coupled files, or one that takes < 5 minutes of direct
edits, never qualifies.
**On abort (the normal path for most tasks):** say in one line why the graph
was skipped, then do the task directly in the current checkout like any other
request. No worktrees, no workers, no gate, no plan document, and nothing
else in this skill applies.
---
## Node 1 · Plan & Contract (LLM — High Effort)
Inspect the relevant codebase first. Never ask the user what the code can
answer.
**Grill only on material ambiguity.** If requirements are still unclear after
reading the code (behavior, edge cases, interfaces, scope), a wrong plan would
be built in parallel by every worker, so settle it now:
- Ask **one question per turn**, each with your recommended answer and a
one-line reason, so the user can reply in a word.
- Give every fuzzy term one canonical name and use it from then on.
- Cap at **5 questions**. Record anything still open as an **Assumption** in the
plan instead of asking more. Park questions only a running prototype can
answer as **Parked**, out of scope.
- If you asked anything, show the plan and wait for the user's go-ahead before
dispatching. If you asked nothing, proceed.
Produce a compact **DAG Plan** (keep it under 60 lines) containing:
1. **Goal & Non-Goals** (2–4 bullets), plus the agreed glossary, Assumptions,
and Parked items if any. Every worker receives these.
2. **Nodes** in execution waves (`Wave 1`, `Wave 2`, ...). Every node MUST define:
- `id`: short slug (`[a-z0-9_-]+`)
- `depends_on`: list of upstream node IDs (or `[]`)
- `owned_files`: exact, **disjoint** list of repo-relative, forward-slash
paths this node may create/modify/delete
- `outcome`: single concrete deliverable
- `verify_cmd`: exact shell command, run from the repo root, that
deterministically proves the node works
- `static_cmd`: optional fast typecheck/lint command (or `""`)
- `setup_cmd`: command that makes a fresh checkout runnable (e.g.
`npm ci --prefer-offline`), or `""`; usually the same for every node
- `effort`: `low` | `medium` | `high` (route cheap/fast for routine edits)
- `read_files`: optional read-only files the worker needs for context but
may not edit (keeps it from exploring); `[]` if none
- `risk`: `high` (core business logic, auth, data integrity, public API) or
`low`
**Disjoint Ownership Rule:** No two nodes in the same wave may share any file
in `owned_files`. If two tasks must touch the same file, either extract a shared
interface node into an earlier wave or sequence them via `depends_on`.
**Right-size nodes.** Every node adds a worker run. Merge tiny nodes that touch
related files into one; split only where nodes can really run in parallel or a
single worker would carry too much context.
**Re-check triage on the finished plan.** The plan shows the real shape of the
work. If no wave has 3+ nodes, the plan has no `risk: high` node, and the task
is not large (the Size rule), abort here: say so in one line and carry out the
plan directly as a checklist in the current checkout, with no worktrees or
workers. Planning cost is already spent; do not add worker cost on top.
---
## Node 2 · Parallel Execution (Isolated Workers)
Execute the DAG wave by wave. For each node in the wave:
1. `WT=$(bash <skill_dir>/scripts/node.sh start <id>)`: branch `graph/<id>` at
the current `HEAD`, which already contains every merged upstream node.
2. Dispatch one worker per node, all nodes of the wave in parallel (one batch
call when the harness supports it). Apply `effort` when the harness lets you
choose a model or reasoning level per worker; otherwise ignore it.
For every worker:
- **Context:** Pass ONLY the Goal (with glossary, Assumptions, Parked), the
node's `outcome`, `owned_files`, `read_files`, `setup_cmd`, `verify_cmd`, the
absolute worktree path `WT`, and any upstream contracts it depends on. Tell it
to read only those files plus what `verify_cmd` needs. Never pass this full
conversation.
- **Output contract:** Require exactly this JSON object as the final answer. Use
the harness's structured-output or schema option when it has one; otherwise
instruct the worker to end with the JSON object and nothing else:
```json
{
"type": "object",
"properties": {
"node_id": { "type": "string" },
"status": { "type": "string", "enum": ["ready", "blocked"] },
"summary": { "type": "string" },
"blocker": { "type": "string" }
},
"required": ["node_id", "status", "summary"]
}
```
Worker Rules (include in each worker prompt):
- Work ONLY inside `WT`, using absolute paths under it. Never edit the main
checkout.
- Edit ONLY files listed in `owned_files`.
- Run `setup_cmd` if needed, implement `outcome`, and run `verify_cmd` inside
`WT` before finishing.
- Do NOT commit, switch branches, or push; the orchestrator commits.
- Return the required JSON object. If blocked, set `status: "blocked"` and
explain why in `blocker`.
After the wave returns:
- `git status --porcelain` in the main checkout must still be empty. If not, a
worker escaped its worktree: record `git status --porcelain` output as the
error for every node of the wave, restore the main checkout
(`git checkout -- . && git clean -fd`; the tree was clean at preflight), and
treat each of those nodes as a gate failure.
- For each `ready` node: `bash <skill_dir>/scripts/node.sh commit <id>`, then
run Node 3.
- A `blocked` node counts as a gate failure (Node 3 routing) with `blocker` as
the error.
---
## Node 3 · Deterministic Gate (0 LLM Tokens)
Do NOT review the diff with an LLM. Run the gate first:
```bash
bash <skill_dir>/scripts/gate.sh \
--branch "graph/<id>" \
--owned "<comma_separated_owned_files>" \
--setup "<setup_cmd>" \
--static "<static_cmd>" \
--verify "<verify_cmd>"
```
`--base` defaults to `HEAD`; the scope check diffs `HEAD...graph/<id>`, which
measures changes from the node's fork point. The gate checks out the branch in
a throwaway worktree, rejects any changed file outside `owned_files` (renames
count as both paths), then runs setup, static, and verify there. On pass it
prints one line; on failure it prints the reason plus the last 60 lines of the
failing command's output.
### Routing Edges (Circuit Breaker)
- **Exit 0 (GATE PASS):**
- `risk: high` → Node 4 (Semantic Audit).
- `risk: low` where `verify_cmd` gives full coverage → skip Node 4, merge.
- **Exit 1 (GATE FAIL):** increment the node's retry counter.
- `retries < 2`: dispatch a fresh worker into the **same** worktree (the
previous attempt is already there) with only the node contract, `WT`, and
the gate output verbatim plus "fix this". Then commit and gate again.
- `retries == 2`: trip the circuit breaker. Mark the node BLOCKED, keep its
branch and worktree for the user, do not run downstream dependent nodes,
and continue any independent branches.
- **Exit 2:** gate misuse (bad arguments or unknown ref). Fix the call; this is
not a retry.
---
## Node 4 · Semantic Audit (Read-Only LLM — Only After Gate Pass)
Triggered only for `risk: high` nodes that passed Node 3.
Dispatch a single read-only reviewer (a separate subagent; in degraded mode, a
fresh pass by yourself) with high effort when available. It inspects
`git diff HEAD...graph/<id>` against the node's `outcome` and checks ONLY what
scripts cannot:
- Does the logic actually satisfy edge cases and the stated outcome?
- Is the proving test genuine (no tautologies, bypassed assertions, or mocks
hiding real behavior)?
Require this JSON object as its final answer:
```json
{
"type": "object",
"properties": {
"verdict": { "type": "string", "enum": ["PASS", "REJECT"] },
"defects": { "type": "array", "items": { "type": "string" } }
},
"required": ["verdict", "defects"]
}
```
- **REJECT:** same `retries < 2` circuit breaker, with `defects` as the error;
re-run Node 3 on the fixed branch before auditing again.
- **PASS:** merge.
### Merge
Merge passed nodes into the current branch in wave order, one at a time:
```bash
git merge --no-ff --no-edit graph/<id>
bash <skill_dir>/scripts/node.sh drop <id>
```
Disjoint ownership makes conflicts a planning defect: on conflict run
`git merge --abort` and mark the node BLOCKED. Start the next wave only after
every node it depends on has merged, so new worktrees include upstream work.
---
## Node 5 · Final Report
Once all waves finish (or halt on blockers), run the repo's top-level test
suite once if more than one wave landed, then output a concise table:
| Node | Wave | Retries | Gate | Audit | Status |
| ---- | ---- | ------- | ---- | ----- | ------ |
List any BLOCKED nodes with their exact last error and their retained branch
`graph/<id>` and worktree (`node.sh path <id>`), so the user can intervene
directly. `node.sh drop <id>` discards one.
Community Reviews & Field Notes
Tried this skill on your own project? Share the model you used and the results you got.