Implements a mainspec end-to-end by auto-detecting mode. Sequential mode (≤3 slices) commits slices in order on the current `feature/<feature>` branch. Parallel mode (>3 slices) uses dependency-aware tiered execution with per-slice worktrees, branches, PRs, and auto-merge into the feature branch. Agent-first — invoked headless by the harness dispatcher with the feature slug as its single argument. No human-in-the-loop, no approval gates.
60
70%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Critical
Do not install without reviewing
Fix and improve this skill with Tessl
tessl review fix ./skills/sdd/implement-mainspec/SKILL.mdThe canonical home for this skill is implement-mainspec in tdg-ninja/context-specs-factory-ai
Implements all slices from a mainspec in dependency order. Auto-detects sequential (≤3 slices) or parallel (>3 slices) mode based on tier computation. Agent-first: invoked headless by the harness dispatcher, runs end-to-end with no approval gates, exits.
Invoked by the dispatcher as: claude -p "/implement-mainspec <feature>", run from inside the feature worktree (the dispatcher cds into it — there is no print-mode --cwd flag).
Single argument: <feature> — kebab-case feature slug. The mainspec path is specs/<feature>/mainspec.md relative to cwd.
Inputs read from disk (paths relative to cwd):
specs/<feature>/mainspec.mdspecs/<feature>/slices/*.mdfeature/<feature> branch state (worktree HEAD).Outputs to disk / remote:
slice/<number>-<kebab-name> pushed to origin (not deleted after merge — they remain as archaeological evidence so the eventual feature/<feature> → main PR review can trace which commits belong to which slice).feature/<feature> with gh pr merge --merge (preserves slice commits + a merge commit).feature/<feature>.No sentinel. The dispatcher's success signal for this step is ./prds/<feature>/run-prd-test.sh exits 0, verified externally. The PRD test is encoded into a slice's Signal by spec-planning, so completing all slices implies the PRD test passes. We do not write a sentinel file — the dispatcher records the green result in specs/<feature>/.prd-passed once the runner first exits 0 (so a possibly-LLM-judge runner isn't re-run every tick); this skill neither writes nor reads that file.
Idempotency:
feature/<feature> git history. Determine which slices are already merged (look for merge commits like Merge slice/<n>-<name> or branches whose commits match slice scope).compute_tiers.py) minus the already-merged set.No approval gates anywhere. No AskUserQuestion for plan approval, default-branch warning, tier review, retry decisions, or branch-state ambiguity. Every decision is deterministic or deferred to the next dispatcher tick.
Phase 0: Detection — Run compute_tiers.py, check total_slices to select mode
Phase 1: Parse & Resume — Read mainspec, parse DAG, inspect feature/<feature> for already-merged slices
--- SEQUENTIAL MODE (≤3 slices) ---
Phase 2: Implement — Delegate each remaining slice to slice-implementer subagent (sequential, foreground). Orchestrator handles git directly on feature/<feature>.
Phase 3: Log — Log final status of this invocation to stdout for observability
--- PARALLEL MODE (>3 slices) ---
Phase 2: Tier 0 — Delegate foundation slices to slice-implementer subagents (sequential, foreground). Orchestrator handles git directly on feature/<feature>.
Phase 3: Parallel Tiers — For each subsequent tier: create worktrees, spawn slice-implementer subagents (background), orchestrator handles git after completion.
Phase 4: Auto-Merge — Create PRs and auto-merge into feature/<feature> with `gh pr merge --merge`. Branches are NOT deleted on merge.
Phase 5: Log — Log final status of this invocation to stdout for observabilityThe dispatcher guarantees a clean worktree on feature/<feature> before invoking. Verify deterministically and exit on violation — the dispatcher will re-derive state on the next tick.
git rev-parse --git-dir succeeds. If not, exit non-zero.feature/<feature> — must match the argument exactly. If not, exit. (Never create the feature branch; the dispatcher's atomic rename from prd/<author>/<feature> did that.)git status --porcelain empty. If not, exit (the dispatcher's wipe should guarantee this; if it trips, something upstream is wrong).git remote get-url origin succeeds. If not, exit. Parallel mode requires remote..claude/worktrees/ is in .gitignore. Auto-append if missing (idempotent; no prompt).Run the tier computation script and select the execution mode deterministically:
1. Run: python3 .claude/skills/implement-mainspec/scripts/compute_tiers.py specs/<feature>/mainspec.md
2. Parse the JSON output which includes:
- mainspec_name, feature_branch
- tiers: array of { tier: N, slices: [{ number, name, file }] }
- file: absolute path to the slice file (can be used directly by subagents)
- total_slices, max_parallel
3. Mode detection (no override, no prompt):
- total_slices ≤ 3 → SEQUENTIAL MODE
- total_slices > 3 → PARALLEL MODE
4. Log to stdout: "Detected <N> slices → <sequential|parallel> mode" for observability.compute_tiers.py parses the mainspec's "Slice Dependency Map" table:
| Field | Source | Example |
|---|---|---|
| Slice number | First column, before — | 3.1 |
| Slice name | First column, after — | SVG Path Animation Utilities |
| Dependencies | "Depends On" column | 3.1 or — (none) |
| Blocks | "Blocks" column | 3.2, 3.3, 3.4, 3.5 or — (none) |
| Slice file path | From compute_tiers.py output | absolute path to slice file |
The script handles topological sort and tier assignment via the algorithm:
1. Start with all slices. remaining = all slices.
2. Tier 0 = slices with no dependencies (Depends On = "—" or "Nothing")
3. Remove Tier 0 from remaining
4. Tier N = slices in remaining whose ALL dependencies are in Tiers 0..N-1
5. Remove Tier N from remaining
6. Repeat until remaining is empty
7. If remaining is not empty and no progress was made → circular dependency errorBefore implementing anything, inspect what's already merged on feature/<feature>:
1. git fetch origin
2. For each slice in the mainspec DAG:
- Check whether a merge commit referencing `slice/<number>-<kebab-name>` exists in
`git log feature/<feature>` (e.g., `git log --merges --grep "slice/<number>-"`).
- If yes, mark slice as ALREADY-MERGED. Skip it.
- Otherwise, mark slice as REMAINING.
3. If all slices are ALREADY-MERGED, log "all slices merged, nothing to do" and exit cleanly.
4. Otherwise, proceed with REMAINING slices in their original tier assignments.Log the computed plan to stdout for observability — what mode, which tiers, which slices are remaining vs. already-merged. No approval gate, no AskUserQuestion. Proceed directly to Phase 2.
Sequential mode log format:
## Execution Plan: <mainspec-name>
Mode: Sequential
Total slices: N (already-merged: M, remaining: K)
Remaining order:
1. Slice X.Y: <name>
2. Slice X.Y: <name>Parallel mode log format:
## Execution Plan: <mainspec-name>
Mode: Parallel
Feature branch: feature/<feature>
Total slices: N (already-merged: M, remaining: K)
Total tiers: T (remaining tiers to process: T')
Tier 0 (Foundation): X.Y <name>, X.Y <name>
Tier 1 (Parallel — N subagents): X.Y <name>, X.Y <name>
Tier 2 (Parallel — N subagents): X.Y <name>Applies only to SEQUENTIAL MODE (≤3 slices). The preconditions section already guaranteed we are on feature/<feature>, so we commit directly to it. No default-branch warning, no approval prompt.
For each REMAINING slice in dependency order (skipping already-merged ones from Phase 1):
slice-implementer subagent (foreground, NOT background):
subagent_type: "slice-implementer" and mode: "bypassPermissions".references/subagent-prompt-template.md (Sequential Mode section). The template passes max_signal_iterations: 3 to bound the inner signal-fix loop.git status to detect changes.git add <changed-files> (only files the subagent created/modified).git commit -m "Implement slice <number>: <name>".git push origin feature/<feature>.git status shows changes, they should not be committed).After all remaining slices: proceed to Phase 3 (Log).
Applies only to PARALLEL MODE (>3 slices). See below for detailed instructions:
Applies only to PARALLEL MODE. The dispatcher's atomic rename already created feature/<feature> before this skill ran. We verify and proceed; we never create the feature branch.
1. Verify HEAD branch == feature/<feature>:
actual="$(git rev-parse --abbrev-ref HEAD)"
[[ "${actual}" == "feature/<feature>" ]] || exit 1
2. Verify the branch tracks origin:
git rev-parse --abbrev-ref --symbolic-full-name @{u} >/dev/null 2>&1 || git push -u origin feature/<feature>Naming conventions:
feature/<feature> (e.g., feature/svg-and-charts).slice/<number>-<kebab-name> (e.g., slice/3.3-barchart)..claude/worktrees/<feature>/slice-<number>-<kebab-name>.Spec file access: Spec files are referenced by absolute path (resolved from compute_tiers.py output). Subagents read specs from the original location, not from their worktree.
Git state recovery (deterministic, no prompts):
git pull --ff-only origin feature/<feature> before any tier work./implement-mainspec tick was interrupted. Check whether the corresponding PR is merged via gh pr view slice/<number>-<kebab-name> --json state -q .state:
MERGED → slice is done; skip it.OPEN → PR was created but not merged; auto-merge it as part of Phase 4.feature/<feature> HEAD → unusable, but harmless; recreate the worktree on top.Applies only to PARALLEL MODE. Execute on feature/<feature> directly.
Tier 0 slices are delegated to slice-implementer subagents sequentially (one at a time, foreground). The orchestrator handles all git operations.
For each REMAINING Tier 0 slice (in dependency order):
slice-implementer subagent (foreground, NOT background):
subagent_type: "slice-implementer" and mode: "bypassPermissions".references/subagent-prompt-template.md (Tier 0 section).git status to detect changed files.git add <changed-files> (only files the subagent created/modified).git commit -m "Implement slice <number>: <name>".git push origin feature/<feature>.Tier 0 slices are committed directly to feature/<feature> — no PRs. This is the foundation that all subsequent tiers depend on.
Applies only to PARALLEL MODE. Create worktrees before spawning subagents for each tier.
Critical: Do NOT use isolation: "worktree" from the Agent tool — it branches from the remote default branch and won't have Tier 0 code.
Preflight — bootstrap availability. Before creating any worktrees, check for scripts/bootstrap-worktree.sh. If it is not an executable file, emit a loud warning to stdout — e.g. WARN: no executable scripts/bootstrap-worktree.sh found; slice worktrees will lack deps/.env/codegen, so signals and unit tests may fail. Continuing anyway. — then proceed. Do not halt: a missing bootstrap script is a warning, not a precondition. When the script IS present, each worktree is bootstrapped right after creation (see below).
For each REMAINING slice in the current tier (skip slices whose PR is already merged):
# Derive names from compute_tiers.py output
worktree_name="slice-<number>-<kebab-name>"
branch_name="slice/<number>-<kebab-name>"
worktree_path=".claude/worktrees/<feature>/${worktree_name}"
# Create worktree branching FROM the feature branch.
# If branch already exists locally or on origin, attach without -b.
if git show-ref --verify --quiet "refs/heads/${branch_name}" \
|| git show-ref --verify --quiet "refs/remotes/origin/${branch_name}"; then
git worktree add "${worktree_path}" "${branch_name}"
else
git worktree add "${worktree_path}" -b "${branch_name}" feature/<feature>
fi
# Record the absolute worktree path for the subagent prompt
abs_worktree_path="$(realpath ${worktree_path})"
# Make the fresh worktree runnable: a bare worktree has no gitignored files
# (node_modules, .env, generated code), so slice signals and unit tests would fail
# for reasons unrelated to the feature. Mirrors the dispatcher's bootstrap hook.
# Idempotent + non-interactive; a failure here is logged but does not stop the slice.
if [[ -x scripts/bootstrap-worktree.sh ]]; then
./scripts/bootstrap-worktree.sh "${abs_worktree_path}" || \
echo "WARN: bootstrap-worktree.sh failed for ${abs_worktree_path} — signals/tests may fail" >&2
fiAfter PRs for a tier have been merged (or on a controlled exit):
1. For each worktree: git worktree remove <path>
2. If removal fails (uncommitted changes): log the failure and exit.
The dispatcher's next tick will wipe state and re-derive what to do.
3. After all tiers complete: git worktree pruneApplies only to PARALLEL MODE. Execute for each REMAINING tier after Tier 0.
Create worktrees for all REMAINING slices in this tier per the Worktree Management section above.
Read references/subagent-prompt-template.md for the full prompt template.
Spawn one background subagent per slice:
run_in_background: true.subagent_type: "slice-implementer" and mode: "bypassPermissions".isolation: "worktree" (worktree already created in 3a).max_signal_iterations: 3 to bound the inner signal-fix loop.Batching: If a tier has more than 7 slices, split into batches of up to 7. Spawn batch 1, wait for all to complete, then spawn batch 2.
TaskOutput(task_id=<id>, block=true) per subagent.After all subagents for the tier complete, the orchestrator handles git for each worktree of a successful slice:
For each successful slice in the tier:
1. cd <worktree-absolute-path>
2. git status (detect changed files)
3. git add <changed-files> (only files the subagent created/modified, NOT git add -A)
4. git commit -m "Implement slice <number>: <name>"
5. git push -u origin <branch-name>references/error-handling.md for detailed recovery procedures.Applies only to PARALLEL MODE. Execute after each tier's subagents complete and orchestrator git operations finish. There is no review gate, no AskUserQuestion, no "Review & merge / Stop here" prompt. Slice PRs are created and merged automatically.
For each successfully completed slice in the current tier whose PR does not already exist:
gh pr create \
--head slice/<number>-<kebab-name> \
--base feature/<feature> \
--title "Slice <number>: <name>" \
--body "Implements slice <number> of <feature>. Part of Tier <N>.
Signal: <Signal Skill: name or None> — <passed / skipped>"Create all PRs for the tier in parallel.
For each PR (in slice-number order):
gh pr merge <pr-number> --mergeKey constraints:
--merge (NOT --squash) — preserves the slice's individual commits plus a merge commit. The merge commit clearly delineates which commits belong to which slice when reviewing the eventual feature/<feature> → main PR.--delete-branch — slice branches stay on origin as archaeological evidence. Reviewers of the feature→main PR can navigate to slice/<n>-<name> to see the focused, in-context diff for any slice.After each successful merge:
git pull origin feature/<feature> in the orchestrator's checkout to bring the merged commits in.If gh pr merge fails for conflict reasons:
/implement-mainspec on the next tick; that invocation's idempotency check will see the failed PR is still open and either retry the merge (if origin now has the prerequisite commits) or skip if the work has moved on.After all PRs for the tier are merged:
git worktree remove <path> for each slice worktree in this tier.feature/<feature>).If any slice in the tier failed in Phase 3 (slice-implementer reported FAILURE):
There is no human to report to. Write a concise stdout log of what this invocation did so the dispatcher's log is readable. The dispatcher does not parse this output; it only checks ./prds/<feature>/run-prd-test.sh exit code externally.
Sequential mode log:
## /implement-mainspec invocation summary: <feature>
Mode: Sequential
Skipped (already-merged): <list of slice numbers> (or none)
Implemented this invocation: <list of slice numbers>
Failed this invocation: <list of slice numbers> (or none)
Branch: feature/<feature> (pushed)Parallel mode log:
## /implement-mainspec invocation summary: <feature>
Mode: Parallel
Feature branch: feature/<feature>
Skipped (already-merged): <list of slice numbers> (or none)
Tier 0 implemented: <list>
Tier 1 implemented (auto-merged): <list of PRs merged>
Tier 2 implemented (auto-merged): <list of PRs merged>
...
Failed this invocation: <list of slice numbers + reasons> (or none)
If failures: dispatcher will re-fire on next tick; idempotency will skip merged work.
If no failures: dispatcher will verify `./prds/<feature>/run-prd-test.sh` exits 0 on next tick.Signal skills provide runtime feedback during implementation. They validate that code works correctly in real environments.
Each slice includes a Signal section after the Objective:
## Signal
**Signal Skill:** {signal-skill-name | None}
**Expected Behavior:**
- what should succeed when correctly implementedskill: "{signal-name}"Sequential mode:
[ ] X.Y-<slice-name> - Implement
[ ] X.Y-<slice-name> - Signal Validation
[ ] X.Y-<slice-name> - Unit Tests
...Parallel mode:
[ ] Phase 0 - Mode Detection
[ ] Phase 1 - Parse DAG & resume detection
[ ] Phase 2 - Tier 0 foundation slices (sequential)
[ ] Tier 0: X.Y-<slice-name> - Delegate to slice-implementer
[ ] Tier 0: X.Y-<slice-name> - Git commit & push
[ ] Tier 1: Create worktrees
[ ] Tier 1: Spawn slice-implementer subagents (N slices)
[ ] Tier 1: Wait for completion
[ ] Tier 1: Git commit & push for each worktree
[ ] Tier 1: Create PRs
[ ] Tier 1: Auto-merge PRs (`gh pr merge --merge`)
[ ] Tier 1: Worktree cleanup
...
[ ] Phase 5 - Stdout logDetailed reference material for parallel mode execution:
references/subagent-prompt-template.md when spawning subagents in Phase 4references/error-handling.md when any phase encounters errorsreferences/release-strategy.md when presenting the summary report or when the user asks about releasingDO:
slice-implementer subagents — orchestrator stays lean.subagent_type: "slice-implementer" and mode: "bypassPermissions" for all subagent spawns.max_signal_iterations: 3 to each subagent (via the prompt template) so the inner signal-fix loop is bounded.git status to detect changed files after subagent completion.feature/<feature>); never create it.feature/<feature> git history at the start of every invocation to determine which slices are already merged; idempotency depends on this.DON'T:
AskUserQuestion anywhere. The dispatcher provides no input, and the human is not in the loop.slice-implementer subagent../prds/<feature>/run-prd-test.sh exit code, not a sentinel.DON'T:
DO:
scripts/bootstrap-worktree.sh right after git worktree add; if the script is absent, warn and continue (do not fail the run).gh pr merge --merge (preserving slice commits + a merge commit). Never --squash. Never --delete-branch — slice branches stay on origin as evidence.feature/<feature>.DON'T:
isolation: "worktree" — it branches from default branch, missing Tier 0 code.main — always target feature/<feature>.main into feature/<feature> — only when needed for conflicts during the eventual feature→main PR.3a7a725
Canonical home
since Aug 20, 2026
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.