{"data":{"slug":"discovered-e6d1b0906e945aa7cd2b1ef535e824ae003df5dd0d668730","title":"Graph Exec","summary":"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.","url":"https:\/\/skillshunter.net\/skills\/discovered-e6d1b0906e945aa7cd2b1ef535e824ae003df5dd0d668730","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/discovered-e6d1b0906e945aa7cd2b1ef535e824ae003df5dd0d668730","markdown_url":"https:\/\/skillshunter.net\/skills\/discovered-e6d1b0906e945aa7cd2b1ef535e824ae003df5dd0d668730.md","download_url":"https:\/\/skillshunter.net\/skills\/discovered-e6d1b0906e945aa7cd2b1ef535e824ae003df5dd0d668730\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_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.","instructions":"---\nname: graph-exec\ndescription: >-\n  Execute multi-file engineering tasks as a token-optimized, deterministic\n  directed acyclic graph (DAG) of isolated workers in separate git worktrees,\n  with typed JSON contracts, zero-token verification gates, and strict retry\n  caps. Use when the user invokes graph-exec or asks to implement a multi-step\n  feature, refactor, or bugfix as a graph\/DAG workflow with minimal token usage.\n  Self-gating: small or tightly coupled tasks are detected and run directly in\n  the normal shared checkout, with no worktrees or workers.\n---\n\n# Graph Execution Workflow (`graph-exec`)\n\nYou are the **Graph Orchestrator**. Your job is to minimize LLM token spend by\ndecomposing work into a Directed Acyclic Graph (DAG), isolating each node in its\nown git worktree, offloading all mechanical checks to zero-token scripts, and\nenforcing hard retry caps.\n\n**Core rule:** Never write product code yourself. Only plan the DAG, dispatch\nnodes, run deterministic gates, and merge verified results.\n\n`<skill_dir>` below is the directory containing this `SKILL.md`. Both scripts\nrun from anywhere inside the target repository:\n\n- `bash <skill_dir>\/scripts\/node.sh start|path|commit|drop <id>`: one branch\n  (`graph\/<id>`) and one worktree per node, outside the repository.\n- `bash <skill_dir>\/scripts\/gate.sh ...`: scope lock plus proof commands, run in\n  a throwaway checkout of the node's branch.\n\n---\n\n## Preflight\n\n- The project must be a git repository with a **clean working tree**\n  (`git status --porcelain` empty), so every later change is attributable to a\n  node.\n- Note the current branch; all merges land there. Never push unless asked.\n- Pick a worker mechanism, in this order:\n  1. **Subagents** from the harness (for example Claude Code's Agent\/Task tool or\n     omp's `task` tool). Do not use a harness's own worktree isolation; the\n     scripts own the worktrees.\n  2. **Headless agent CLI** started inside the node's worktree (for example\n     `claude -p \"<prompt>\"` or `codex exec \"<prompt>\"`), when no subagent tool\n     exists but such a CLI is installed.\n  3. **Degraded mode:** run nodes yourself, one at a time, editing only inside\n     the node's worktree and reading only its contract and owned files. Tell\n     the user the run is degraded; gates and merges stay identical.\n\n---\n\n## Node 0 \u00b7 Triage (Avoid Over-Engineering)\n\nBefore building a graph, check the scope. Every node costs a worker run plus\nre-reading its files, so a graph only pays off on larger work. **Abort the\ngraph and do the task directly in one turn** unless at least one holds:\n- **Parallelism:** at least 3 nodes can run in the same wave (independent,\n  disjoint files).\n- **Size:** the task spans roughly 10+ files or several subsystems, too much for\n  one context to hold comfortably.\n- **Independent verification:** a `risk: high` part needs a separate audit.\n\nA task of \u2264 2 tightly coupled files, or one that takes < 5 minutes of direct\nedits, never qualifies.\n\n**On abort (the normal path for most tasks):** say in one line why the graph\nwas skipped, then do the task directly in the current checkout like any other\nrequest. No worktrees, no workers, no gate, no plan document, and nothing\nelse in this skill applies.\n\n---\n\n## Node 1 \u00b7 Plan & Contract (LLM \u2014 High Effort)\n\nInspect the relevant codebase first. Never ask the user what the code can\nanswer.\n\n**Grill only on material ambiguity.** If requirements are still unclear after\nreading the code (behavior, edge cases, interfaces, scope), a wrong plan would\nbe built in parallel by every worker, so settle it now:\n- Ask **one question per turn**, each with your recommended answer and a\n  one-line reason, so the user can reply in a word.\n- Give every fuzzy term one canonical name and use it from then on.\n- Cap at **5 questions**. Record anything still open as an **Assumption** in the\n  plan instead of asking more. Park questions only a running prototype can\n  answer as **Parked**, out of scope.\n- If you asked anything, show the plan and wait for the user's go-ahead before\n  dispatching. If you asked nothing, proceed.\n\nProduce a compact **DAG Plan** (keep it under 60 lines) containing:\n1. **Goal & Non-Goals** (2\u20134 bullets), plus the agreed glossary, Assumptions,\n   and Parked items if any. Every worker receives these.\n2. **Nodes** in execution waves (`Wave 1`, `Wave 2`, ...). Every node MUST define:\n   - `id`: short slug (`[a-z0-9_-]+`)\n   - `depends_on`: list of upstream node IDs (or `[]`)\n   - `owned_files`: exact, **disjoint** list of repo-relative, forward-slash\n     paths this node may create\/modify\/delete\n   - `outcome`: single concrete deliverable\n   - `verify_cmd`: exact shell command, run from the repo root, that\n     deterministically proves the node works\n   - `static_cmd`: optional fast typecheck\/lint command (or `\"\"`)\n   - `setup_cmd`: command that makes a fresh checkout runnable (e.g.\n     `npm ci --prefer-offline`), or `\"\"`; usually the same for every node\n   - `effort`: `low` | `medium` | `high` (route cheap\/fast for routine edits)\n   - `read_files`: optional read-only files the worker needs for context but\n     may not edit (keeps it from exploring); `[]` if none\n   - `risk`: `high` (core business logic, auth, data integrity, public API) or\n     `low`\n\n**Disjoint Ownership Rule:** No two nodes in the same wave may share any file\nin `owned_files`. If two tasks must touch the same file, either extract a shared\ninterface node into an earlier wave or sequence them via `depends_on`.\n\n**Right-size nodes.** Every node adds a worker run. Merge tiny nodes that touch\nrelated files into one; split only where nodes can really run in parallel or a\nsingle worker would carry too much context.\n\n**Re-check triage on the finished plan.** The plan shows the real shape of the\nwork. If no wave has 3+ nodes, the plan has no `risk: high` node, and the task\nis not large (the Size rule), abort here: say so in one line and carry out the\nplan directly as a checklist in the current checkout, with no worktrees or\nworkers. Planning cost is already spent; do not add worker cost on top.\n\n---\n\n## Node 2 \u00b7 Parallel Execution (Isolated Workers)\n\nExecute the DAG wave by wave. For each node in the wave:\n\n1. `WT=$(bash <skill_dir>\/scripts\/node.sh start <id>)`: branch `graph\/<id>` at\n   the current `HEAD`, which already contains every merged upstream node.\n2. Dispatch one worker per node, all nodes of the wave in parallel (one batch\n   call when the harness supports it). Apply `effort` when the harness lets you\n   choose a model or reasoning level per worker; otherwise ignore it.\n\nFor every worker:\n- **Context:** Pass ONLY the Goal (with glossary, Assumptions, Parked), the\n  node's `outcome`, `owned_files`, `read_files`, `setup_cmd`, `verify_cmd`, the\n  absolute worktree path `WT`, and any upstream contracts it depends on. Tell it\n  to read only those files plus what `verify_cmd` needs. Never pass this full\n  conversation.\n- **Output contract:** Require exactly this JSON object as the final answer. Use\n  the harness's structured-output or schema option when it has one; otherwise\n  instruct the worker to end with the JSON object and nothing else:\n  ```json\n  {\n    \"type\": \"object\",\n    \"properties\": {\n      \"node_id\": { \"type\": \"string\" },\n      \"status\": { \"type\": \"string\", \"enum\": [\"ready\", \"blocked\"] },\n      \"summary\": { \"type\": \"string\" },\n      \"blocker\": { \"type\": \"string\" }\n    },\n    \"required\": [\"node_id\", \"status\", \"summary\"]\n  }\n  ```\n\nWorker Rules (include in each worker prompt):\n- Work ONLY inside `WT`, using absolute paths under it. Never edit the main\n  checkout.\n- Edit ONLY files listed in `owned_files`.\n- Run `setup_cmd` if needed, implement `outcome`, and run `verify_cmd` inside\n  `WT` before finishing.\n- Do NOT commit, switch branches, or push; the orchestrator commits.\n- Return the required JSON object. If blocked, set `status: \"blocked\"` and\n  explain why in `blocker`.\n\nAfter the wave returns:\n- `git status --porcelain` in the main checkout must still be empty. If not, a\n  worker escaped its worktree: record `git status --porcelain` output as the\n  error for every node of the wave, restore the main checkout\n  (`git checkout -- . && git clean -fd`; the tree was clean at preflight), and\n  treat each of those nodes as a gate failure.\n- For each `ready` node: `bash <skill_dir>\/scripts\/node.sh commit <id>`, then\n  run Node 3.\n- A `blocked` node counts as a gate failure (Node 3 routing) with `blocker` as\n  the error.\n\n---\n\n## Node 3 \u00b7 Deterministic Gate (0 LLM Tokens)\n\nDo NOT review the diff with an LLM. Run the gate first:\n\n```bash\nbash <skill_dir>\/scripts\/gate.sh \\\n  --branch \"graph\/<id>\" \\\n  --owned \"<comma_separated_owned_files>\" \\\n  --setup \"<setup_cmd>\" \\\n  --static \"<static_cmd>\" \\\n  --verify \"<verify_cmd>\"\n```\n\n`--base` defaults to `HEAD`; the scope check diffs `HEAD...graph\/<id>`, which\nmeasures changes from the node's fork point. The gate checks out the branch in\na throwaway worktree, rejects any changed file outside `owned_files` (renames\ncount as both paths), then runs setup, static, and verify there. On pass it\nprints one line; on failure it prints the reason plus the last 60 lines of the\nfailing command's output.\n\n### Routing Edges (Circuit Breaker)\n\n- **Exit 0 (GATE PASS):**\n  - `risk: high` \u2192 Node 4 (Semantic Audit).\n  - `risk: low` where `verify_cmd` gives full coverage \u2192 skip Node 4, merge.\n- **Exit 1 (GATE FAIL):** increment the node's retry counter.\n  - `retries < 2`: dispatch a fresh worker into the **same** worktree (the\n    previous attempt is already there) with only the node contract, `WT`, and\n    the gate output verbatim plus \"fix this\". Then commit and gate again.\n  - `retries == 2`: trip the circuit breaker. Mark the node BLOCKED, keep its\n    branch and worktree for the user, do not run downstream dependent nodes,\n    and continue any independent branches.\n- **Exit 2:** gate misuse (bad arguments or unknown ref). Fix the call; this is\n  not a retry.\n\n---\n\n## Node 4 \u00b7 Semantic Audit (Read-Only LLM \u2014 Only After Gate Pass)\n\nTriggered only for `risk: high` nodes that passed Node 3.\n\nDispatch a single read-only reviewer (a separate subagent; in degraded mode, a\nfresh pass by yourself) with high effort when available. It inspects\n`git diff HEAD...graph\/<id>` against the node's `outcome` and checks ONLY what\nscripts cannot:\n- Does the logic actually satisfy edge cases and the stated outcome?\n- Is the proving test genuine (no tautologies, bypassed assertions, or mocks\n  hiding real behavior)?\n\nRequire this JSON object as its final answer:\n\n```json\n{\n  \"type\": \"object\",\n  \"properties\": {\n    \"verdict\": { \"type\": \"string\", \"enum\": [\"PASS\", \"REJECT\"] },\n    \"defects\": { \"type\": \"array\", \"items\": { \"type\": \"string\" } }\n  },\n  \"required\": [\"verdict\", \"defects\"]\n}\n```\n\n- **REJECT:** same `retries < 2` circuit breaker, with `defects` as the error;\n  re-run Node 3 on the fixed branch before auditing again.\n- **PASS:** merge.\n\n### Merge\n\nMerge passed nodes into the current branch in wave order, one at a time:\n\n```bash\ngit merge --no-ff --no-edit graph\/<id>\nbash <skill_dir>\/scripts\/node.sh drop <id>\n```\n\nDisjoint ownership makes conflicts a planning defect: on conflict run\n`git merge --abort` and mark the node BLOCKED. Start the next wave only after\nevery node it depends on has merged, so new worktrees include upstream work.\n\n---\n\n## Node 5 \u00b7 Final Report\n\nOnce all waves finish (or halt on blockers), run the repo's top-level test\nsuite once if more than one wave landed, then output a concise table:\n\n| Node | Wave | Retries | Gate | Audit | Status |\n| ---- | ---- | ------- | ---- | ----- | ------ |\n\nList any BLOCKED nodes with their exact last error and their retained branch\n`graph\/<id>` and worktree (`node.sh path <id>`), so the user can intervene\ndirectly. `node.sh drop <id>` discards one.\n","use_cases":["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"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/n8bour\/graph-exec\/blob\/c314fac6728af667aea2ea9f2be001311bf33894\/skills\/graph-exec\/SKILL.md","source_commit":"c314fac6728af667aea2ea9f2be001311bf33894","license":null,"version":null,"listing_approved_at":"2026-11-29","created_at":"2026-11-28T18:56:22.000000Z","updated_at":"2026-11-29T10:53:52.000000Z","seo_title":"Graph Exec - Execute Multi-File Engineering Tasks as a DAG","seo_description":"Execute complex engineering tasks as a directed acyclic graph (DAG) of isolated workers in separate git worktrees with typed JSON contracts and zero-token verification.","seo_keywords":["graph execution","directed acyclic graph","git worktree","isolated workers","zero-token verification","engineering tasks"]}}