---
name: plan-and-tdd
description: >-
  The per-task discipline to apply INSIDE /speckit-implement (Spec Kit), once the spec is approved and /speckit-plan, /speckit-tasks and /speckit-analyze have run: check that tasks.md carries test tasks, then for each task write the failing test first, the minimum code to green, refactor, run ./gates/run-chain.sh, get review, and commit one concern with its Spec: trailer and the task ticked. Not an entry point and never before approval. Adapted from obra/superpowers writing-plans + test-driven-development (MIT).
title: plan-and-tdd
canonical_url: https://skilld.dev/gh/doxuta/ai-factory-kit/plan-and-tdd
last_updated: 2026-11-12T06:31:13.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> If the user asked to install this Skill, run `npx skilld install doxuta/ai-factory-kit/plan-and-tdd`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/plan-and-tdd`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/doxuta/ai-factory-kit/plan-and-tdd) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/plan-and-tdd`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/plan-and-tdd --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/plan-and-tdd --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

<!-- WHO READS ME: an agent implementing a feature whose spec is approved.
     I POINT TO (kit paths; factory/... once adopted): harness/skills/spec-first/SKILL.md (the
     discipline before approval) · gates/GATES.md (the chain every commit runs; §10 commit
     trailers) · model/SPEC-FLOW.md (the implement step, which I conduct) ·
     harness/agents/task-orchestra.md (when the tasks split into parallel parcels). -->

# Plan → TDD — from approved tasks to landed commits

Entry condition: `specs/<id>/spec.md` says `status: approved` with `approved_by` and
`approved_on`, and `plan.md`, `quickstart.md` and `tasks.md` exist
([`spec-first`](../spec-first/SKILL.md) gets you there). Anything missing → stop and run the
Spec Kit command that makes it (`/speckit-specify`, `/speckit-plan`, `/speckit-tasks`). This
is the constitution's HARD-GATE, not a preference. This skill writes no plan and no tasks of
its own — one plan, one task list, both Spec Kit's — and when the tasks split into
file-disjoint parcels, [`task-orchestra`](../../agents/task-orchestra.md) runs them in parallel,
each worker following this loop. Work that is not a feature — a bug in accepted behaviour, a
hotfix, a refactor, a chore — runs the same per-task loop under its own lane's entry condition
instead (an accepted spec for a bug, no spec for a refactor):
[NON-FEATURE-WORK](../../../model/NON-FEATURE-WORK.md).

## Check tasks.md before the first line of code

`/speckit-tasks` wrote it; you check it (the step of [SPEC-FLOW](../../../model/SPEC-FLOW.md)
that `/speckit-analyze` also reads):

- **Test tasks are there**, each ahead of the code it proves. Spec Kit's `/speckit-tasks`
  generates tests only when asked; constitution Article VI asks. Missing? Re-run
  `/speckit-tasks` with "tests first for every behaviour change" as its argument.
- **Every task is independently verifiable** and carries a measurable "done = …". One task ≈
  one commit ≈ one concern; a task you cannot name in one clause is two tasks.
- **Risky tasks are flagged** — anything on the surfaces the constitution's Development
  Workflow names (for a web product: data isolation, schema, authorization, money). Those get
  adversarial review before commit, not just the normal pass.
- Tasks use Spec Kit's checklist format, `- [ ] T001 …`; a task deliberately moved out of this
  feature reads `(deferred → <where>)`, so it does not hold the spec back.
- **Feature 001, the walking skeleton**, ends by installing the kit's gate hook and CI job:
  `python3 factory/bin/adopt.py --install-git-hook --ci github`, then the toolchain steps in
  `.github/workflows/factory-gates.yml` ([PHASE-0 §7](../../../model/PHASE-0.md)). A task that
  writes its own pre-commit hook, hook installer or gate workflow is wrong: re-plan it onto
  those two commands.

## The loop, per task

1. **Red** — write the failing test first, and *watch it fail*. A test that passes before the
   code exists proves nothing. **Vacuous-green check**: confirm the test filter matches ≥1
   real test name — a filter matching zero tests exits green
   ([GATES §1](../../../gates/GATES.md)).
2. **Green** — the minimum code that passes. No gold-plating; the
   [`ponytail`](../ponytail/SKILL.md) ladder applies inside the layer.
3. **Refactor** — clean up with the tests staying green.
4. **Gates** — `./gates/run-chain.sh`. Red = fix, never proceed; a `TODO` slot is red too. The
   one exception is feature 001 wiring the chain: its commits may be red only at a `TODO` slot,
   with the spec gates run directly ([GATES §1](../../../gates/GATES.md)). A
   new route, command or exported surface needs its caller in the same task or a named task —
   the `orphan-endpoints` slot (`gates/check-orphan-endpoints.sh`, configured by
   `gates/orphan-endpoints.conf`; unconfigured it is red, "not wired") checks routes.
5. **Review** — an independent reviewer; adversarial lenses
   ([tech-lead-review](../../agents/tech-lead-review.md)) for the flagged tasks. Findings are
   fixed or refuted with evidence, never shelved (GATES §2).
6. **Commit** — `type(scope): description`, one concern, with a `Spec: <id>` trailer
   ([GATES §10](../../../gates/GATES.md)). The task's checkbox (`- [x] T00n`) and any spec or
   plan correction land **in the same commit** — deferred sync is how maps start lying.

When every task is ticked, the chain is green and review has passed, the feature is built, not
accepted: someone other than the builder runs `quickstart.md` and records
`specs/<id>/acceptance.md` before the status moves to `accepted` (GATES §3).

## Stop rules

- The design turns out wrong mid-task → stop, return to the spec
  ([`spec-first`](../spec-first/SKILL.md)); a changed requirement goes back to the owner for
  approval. Pushing through a broken design is how one correction commit becomes five.
- A task still resists after two honest attempts → the task is mis-cut; re-plan it.
- Never race a milestone by dropping tests or review — a green lie costs more than a red
  truth, because the lie compounds.
