@pmelab/gtd 2.6.0 β†’ 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,81 +1,40 @@
1
1
  # gi[t]hings.**done**
2
2
 
3
- > [!WARNING] This project is an experiment in unapologetic vibe coding. Code
4
- > might be terrible, I don't even know πŸ€·β€β™‚οΈ But otherwise I wouldn't have built it
5
- > in the first place. Now I have something that actually helps me.
6
-
7
- A git-aware CLI that drives a turn-taking loop between a human and an autonomous
8
- coding agent: capture an idea, grill it into a product-level plan, grill that
9
- into a technical architecture, decompose it into work packages, execute with
10
- parallel subagents, test, agentically review each package, walk a human through
11
- a review, distill durable lessons from the cycle into the project's own docs,
12
- and finally squash the whole cycle into one conventional-commits commit at the
13
- end.
14
-
15
- Internally, gtd is a **pure fold** over git history. The decision core
16
- (`src/Machine.ts`) is a single IO-free function, `resolve(events)` β€” **no
17
- xstate, no actor, no Effect**. The Effect "edge" (`src/Events.ts`) does all the
18
- git/filesystem IO: it reads the **first-parent** commit subjects since the
19
- merge-base with the default branch (whole-history fallback when there is no
20
- default branch, when HEAD equals the merge-base, or when there is no merge-base)
21
- plus the working tree, turns them into a `COMMIT[]` + single terminal `RESOLVE`
22
- event stream, and folds them through the machine. The fold lands on exactly
23
- **one** of 21 states, plus which actor (human or agent) is awaited there. A
24
- single call resolves to a single state.
25
-
26
- Steering is entirely **machine-authored commit subjects** β€” there are no marker
27
- files, sentinels, or auto-advance tails to parse. A turn commit looks like
28
- `gtd(human): grilling` or `gtd(agent): building`; a routing commit (bookkeeping
29
- the machine performs itself between turns) looks like `gtd: tests green`.
30
- `src/Subjects.ts` is the closed grammar both the machine and the edge read.
31
-
32
- All workflow state lives under **`.gtd/`**: the product plan (`.gtd/TODO.md`),
33
- the technical architecture it converges into (`.gtd/ARCHITECTURE.md`), work
34
- packages (`.gtd/01-…/`), review records (`.gtd/REVIEW.md`, `.gtd/FEEDBACK.md`),
35
- and loop bookkeeping (`.gtd/ERRORS.md`, `.gtd/HEALTH.md`, `.gtd/LEARNINGS.md`,
36
- `.gtd/SQUASH_MSG.md`). One rule follows for every agent in the loop: **never
37
- touch `.gtd/`** except the single file a prompt explicitly grants. A `TODO.md`
38
- or `REVIEW.md` at the repository root is the project's own file β€” gtd never
39
- reads, consumes, or deletes it. (Corollary: don't gitignore `.gtd/` β€” the
40
- workflow commits its state through it.)
41
-
42
- ## Quick start: the two-beat loop
43
-
44
- gtd splits what used to be one mutating command into three:
45
-
46
- - **`gtd step`** β€” advance the workflow as the **human** actor, to fixpoint.
47
- - **`gtd step-agent`** β€” advance the workflow as the **agent** actor, to
48
- fixpoint.
49
- - **`gtd next`** β€” print the prompt for whichever actor is currently awaited,
50
- without mutating anything.
51
-
52
- An agent loop is a two-beat protocol repeated forever:
53
-
54
- 1. Run `gtd step-agent` to advance any agent-owned bookkeeping to a fixpoint.
55
- 2. Run `gtd next --json` and read the `actor` field. If it is `"human"`,
56
- **halt** β€” the human owns the next move, and the agent's job is done for this
57
- turn. If it is `"agent"`, feed `prompt` (when non-null) to the agent, let it
58
- act, then go back to step 1; at a pending checkpoint (`prompt` is null) go
59
- straight back to step 1.
60
-
61
- A human acts by editing files (answering questions in `.gtd/TODO.md` or
62
- `.gtd/ARCHITECTURE.md`, annotating `.gtd/REVIEW.md`, fixing code) and then
63
- running `gtd step` to capture the edit as their turn and hand control back to
64
- the agent side of the loop.
65
-
66
- ```bash
67
- gtd step-agent # advance the machine's own bookkeeping
68
- gtd next --json # ask who's up and what they should do
69
- ```
70
-
71
- See [The reference loop driver](#the-reference-loop-driver) for a full script
72
- implementing this protocol, and [`skills/loop/SKILL.md`](skills/loop/SKILL.md)
73
- for the agent-facing instructions that follow the same pinned contract.
74
- `gtd-loop`, installed alongside `gtd` (see below), is the packaged, ready-to-run
75
- implementation of that same script for anyone who doesn't want to drive the loop
76
- by hand.
77
-
78
- ## Installation
3
+ > β€žFix all the tests." β€žβœ… All tests pass!" β€žThe E2E suite is red." β€žAh, you
4
+ > mean _those_ tests."
5
+
6
+ **Chat is a terrible source of truth. Git isn't.**
7
+
8
+ **gtd** is a git-aware CLI that derives the entire agentic workflow β€” capture,
9
+ plan, build, test, review β€” from your repository state, and prints the next
10
+ prompt for whatever agent you point at it. Every step is a commit. Tests are run
11
+ by the tool and branched on by exit code, so the agent never grades its own
12
+ homework.
13
+
14
+ No chat scrollback. No lost sessions. No infinite fix loops. Just git.
15
+
16
+ ## Why
17
+
18
+ - **Durable & replayable.** The workflow state _is_ your git history β€” a pure
19
+ fold over commit subjects and the working tree. Kill the session, reboot, come
20
+ back next week: run `gtd` and it resumes exactly where it stopped.
21
+ - **Shareable.** Push the branch, and the workflow travels with it β€” the state
22
+ lives in the commits, so another machine (or another person) picks up exactly
23
+ where you left off.
24
+ - **Files, not chat.** Plans live in `.gtd/TODO.md`, reviews in
25
+ `.gtd/REVIEW.md`. Answer the agent's questions inline, approve by ticking
26
+ checkboxes β€” all in your own editor. There is no chat UI to lose.
27
+ - **Harness agnostic.** gtd emits prompts to stdout (or JSON). Claude Code, a
28
+ bash loop, a CI job, or you reading it out loud β€” the workflow doesn't care
29
+ who executes it.
30
+ - **Bounded, not runaway.** Fix attempts are budgeted. When the cap is hit, gtd
31
+ stops and escalates to a human instead of burning tokens rewriting the same
32
+ test for the 47th time.
33
+ - **Clean history.** When the feature ships, all the intermediate `gtd:` commits
34
+ squash into one conventional commit β€” as if a very disciplined engineer did it
35
+ in one sitting.
36
+
37
+ ## Install
79
38
 
80
39
  ```bash
81
40
  npm install -g @pmelab/gtd
@@ -88,1030 +47,56 @@ npx @pmelab/gtd
88
47
  ```
89
48
 
90
49
  No config file, no setup subcommand β€” `gtd` auto-initializes a `.gtdrc.json`
91
- schema stub on first run (see [Auto-init](#auto-init)).
92
-
93
- ## Command reference
94
-
95
- ```
96
- Usage: gtd [command] [options]
97
-
98
- Commands:
99
- step Advance the workflow as the human actor (to fixpoint)
100
- step-agent Advance the workflow as the agent actor (to fixpoint)
101
- next Print the prompt for whichever actor is awaited (no mutation)
102
- status Predict the next commit and state from the working tree (no mutation)
103
- review <target> Anchor an ad-hoc human review against a git ref or branch
104
- questions List open questions from the active grilling/architecting doc
105
- changesets List changesets/files from the active review doc
106
- format <file> Format a markdown file in place
107
-
108
- Options:
109
- --json Output structured JSON instead of plain text
110
- --version, -v Print version and exit
111
- --help, -h Print this help and exit
112
- ```
113
-
114
- `--version` (`-v`) and `--help` (`-h`) short-circuit before any git or
115
- repository-state work β€” they run outside a repo and in any repo state. Bare
116
- `gtd` (no subcommand) is a usage error: it prints the help text and exits 1
117
- without touching the repository. Every other command must be run from the
118
- **repository root** β€” gtd derives steering files, diffs, and pathspecs relative
119
- to cwd, so it refuses with a clear error if invoked from a subdirectory.
120
-
121
- `--json` is the only long option. Any other `--` option (including a typo like
122
- `--jsn`) is rejected with a usage error rather than silently ignored, so a
123
- mistyped flag can never degrade a JSON caller to plain-text mode.
124
-
125
- One nuance to "(no mutation)": `next` and `status` never author commits or
126
- change workflow state, but while a human review is pending they do maintain the
127
- review checkout window (closing it to read state, re-arming it on the way out β€”
128
- see [Human review gate](#human-review-gate)), which transiently moves HEAD and
129
- the index. The working tree is never touched.
130
-
131
- ### `gtd step` / `gtd step-agent`
132
-
133
- Both drive the **same fixpoint loop** β€” gather β†’ resolve β†’ perform the returned
134
- edge action β†’ repeat β€” differing only in which actor's turn they are allowed to
135
- capture:
136
-
137
- - **`gtd step`** captures the **human** turn at whichever gate is awaiting one.
138
- - **`gtd step-agent`** captures the **agent** turn.
139
-
140
- **Fixpoint advance.** A single invocation may author several commits: it authors
141
- the awaited actor's turn commit, then keeps performing any further mid-chain
142
- routing (a test run, a routing commit, a package close, …) until it reaches a
143
- rest where a prompt would be shown, or a fixpoint where nothing changed.
144
- `gtd step`/`gtd step-agent` never print a prompt themselves β€” that's
145
- `gtd next`'s job.
146
-
147
- **Idempotence.** Re-running the same command again once the tree is settled at a
148
- rest authors **zero** new commits. It exits 0 while the rest still awaits that
149
- command's actor (an inert empty agent turn, the idle health check); once the
150
- rest awaits the _other_ actor, the re-run is an out-of-turn refusal β€” still zero
151
- commits, but non-zero exit.
152
-
153
- **Out-of-turn refusal.** Human and agent turns are strictly separated: the wrong
154
- mutator always errors, at every state, on clean and dirty trees alike.
155
- `gtd step-agent` while a human turn is awaited refuses with
156
- `"<state> awaits a human turn β€” run \`gtd step\`"`; `gtd
157
- step`while an agent turn is awaited refuses with`"<state> awaits an agent turn β€”
158
- run \`gtd
159
- step-agent\`"`β€” exit non-zero, zero commits either way. Human edits made while the agent is awaited (e.g. amendment notes in`.gtd/`package files after the`gtd:
160
- planning` commit lands) stay pending in the working tree and ride along as input
161
- to the agent's next captured turn; left unamended, the build proceeds.
162
-
163
- **Red-test fixpoints exit 0.** A red test run below the fix-attempt cap (or the
164
- health-fix cap) still writes its findings and commits β€” it is a normal,
165
- successful step of the loop, not a failure of the `step`/`step-agent`
166
- invocation. `step`/`step-agent` only exit non-zero for a genuine refusal or an
167
- operational error (bad config, missing test binary, corrupted state).
168
-
169
- **Output.** Plain mode prints one `committed: <subject>` line per commit this
170
- invocation authored (oldest→newest), then a final `state: <state>` line:
171
-
172
- ```
173
- committed: gtd(human): grilling
174
- committed: gtd: architecting
175
- state: architecting
176
- ```
177
-
178
- `--json` emits `{state, actions, commits}` instead (see
179
- [JSON schemas](#json-schemas)).
180
-
181
- ### `gtd next`
182
-
183
- Pure prompt emitter β€” it **never mutates** the repository. It reports whichever
184
- actor is currently awaited and, if the tree is at a genuine rest, the full
185
- prompt for that actor.
186
-
187
- **Purity.** No commits, no file writes, no test runs β€” `gtd next` only gathers
188
- and resolves.
189
-
190
- **Dirty-tree refusal.** If the working tree has pending changes outside the
191
- steering-file set, `gtd next` refuses rather than guess at a prompt for a state
192
- that hasn't been captured yet:
193
-
194
- ```
195
- gtd next: working tree is dirty β€” run `gtd status` to inspect it, then advance with `gtd step` or `gtd step-agent` (whichever actor is awaited)
196
- ```
197
-
198
- **Pending.** If HEAD is mid-chain β€” bookkeeping the next `step`/`step-agent`
199
- invocation would perform before reaching a rest β€” `gtd next` reports
200
- `pending: true` with no prompt. Mid-chain bookkeeping is invoker-agnostic, so
201
- either mutator resumes it; the report names the actor whose chain it is. In
202
- plain mode an agent-driven checkpoint prints `"mid-chain checkpoint β€” run \`gtd
203
- step-agent\` to continue, then run \`gtd next\`
204
- again"`, a human-driven one prints `"mid-chain checkpoint β€” run \`gtd step\` to
205
- continue"`.
206
-
207
- **Agent tail lines.** In plain-mode output, a prompt for the **agent** actor
208
- ends with the pinned tail:
209
-
210
- ```
211
- Finish your turn by running `gtd step-agent`. Then run `gtd next` and follow
212
- its output β€” repeat this cycle as long as the output is addressed to you (the
213
- agent); when it awaits the human, stop and hand off.
214
- ```
215
-
216
- The first sentence closes the current turn; the second closes the outer loop β€”
217
- it is what lets a plain-text agent chain multiple iterations (e.g. successive
218
- test/fix cycles) without an external driver, until a human gate is reached.
219
- Human-actor prompts carry no tail. `--json` output never embeds the tail into
220
- `prompt` either β€” the structured `actor` field (see JSON schemas below) carries
221
- the same information: `"agent"` means another agent round, `"human"` means stop
222
- and hand off.
223
-
224
- ### `gtd status`
225
-
226
- Pure, read-only **dry-run prediction** β€” the same gather+resolve `gtd next`
227
- runs, but reporting a prediction of the next turn rather than the actual prompt.
228
- Performs no git mutation, no test run, no file write β€” guaranteed side-effect
229
- free, including on a dirty tree.
230
-
231
- Prints four fields:
232
-
233
- ```
234
- State: grilling
235
- Awaits: human
236
- Predicted commit: gtd(human): grilling
237
- Predicted state: grilling
238
- ```
239
-
240
- - **State** β€” the currently resolved state.
241
- - **Awaits** β€” the actor (`human` or `agent`) whose turn it is.
242
- - **Predicted commit** β€” the subject `step`/`step-agent` would author next, or
243
- `(none)` at a fixpoint (e.g. idle with nothing to do).
244
- - **Predicted state** β€” the state that commit would land in.
245
-
246
- `gtd status` takes no arguments β€” extra positional args are rejected.
247
-
248
- ### `gtd review <target>`
249
-
250
- A pure mutator that **anchors, then exits** β€” it never prints a prompt itself.
251
- Use it to start an ad-hoc human review against an explicit git ref or branch,
252
- independent of the automatic review base the workflow otherwise computes.
253
-
254
- 1. Refuses on a dirty tree.
255
- 2. Resolves `<target>` via merge-base semantics and computes the diff HEAD adds
256
- over `merge-base(<target>, HEAD)`.
257
- 3. Refuses if that diff is empty after filtering ("nothing to review").
258
- 4. Authors exactly one commit: `gtd: reviewing <full-hash-of-the-base>`.
259
- 5. Prints a short confirmation pointing at `gtd next` β€” it does **not** print
260
- the review prompt itself.
261
-
262
- ```bash
263
- gtd review main
264
- # anchored review at <hash> β€” run `gtd next` to get the review prompt
265
- gtd next --json
266
- # {"actor":"agent", ...} β€” the review-record prompt scoped to that anchor
267
- ```
268
-
269
- Errors (all exit 1, message on stderr):
270
-
271
- - Missing target: `gtd review: missing target argument`
272
- - Extra arguments:
273
- `gtd review: too many arguments β€” expected one target, got: …`
274
- - Unresolvable ref: `gtd review: cannot resolve ref '<target>': <error message>`
275
- - Empty diff:
276
- `gtd review: nothing to review (<target> diff is empty after filtering)`
277
-
278
- ### `gtd questions` / `gtd changesets`
279
-
280
- Pure, read-only reporters β€” no dirty-tree check, no mutation β€” that parse the
281
- structured content out of the active grilling/architecting and review documents,
282
- for a future UI:
283
-
284
- - **`gtd questions`** reads whichever of `.gtd/TODO.md` / `.gtd/ARCHITECTURE.md`
285
- is present and reports its `## Open Questions` list (see
286
- [Structured grilling/architecting and review files](#structured-grillingarchitecting-and-review-files)
287
- below). Reports an empty list when neither file exists.
288
- - **`gtd changesets`** reads `.gtd/REVIEW.md`, if present, and reports its
289
- chunks/file-pointer list. Reports an empty list when the file doesn't exist.
290
-
291
- Both take no arguments and always exit 0 β€” a malformed file is reported via the
292
- `errors` field/lines rather than failing the command (the same diagnosis
293
- `gtd step-agent` would refuse the agent's next turn capture with).
294
-
295
- ```bash
296
- gtd questions --json
297
- # {"file":".gtd/TODO.md","questions":[{"question":"Which operations?","status":"suggested","text":"add and subtract."}],"errors":[]}
298
- gtd changesets --json
299
- # {"file":".gtd/REVIEW.md","shortHash":"abc1234","fullHash":"abc1234...","changesets":[...],"errors":[]}
300
- ```
301
-
302
- ### `gtd format <file>`
303
-
304
- Unchanged from v1: formats a markdown file in place with a bundled prettier
305
- (`parser: "markdown"`, `printWidth: 80`, `proseWrap: "always"`), ignoring the
306
- host repo's own `.prettierrc` so `.gtd/TODO.md`/`.gtd/REVIEW.md` stay
307
- consistently formatted regardless of the host project's toolchain. Rejects
308
- `--json` (exit 1, `gtd format does not accept --json`) β€” it is a plain file
309
- operation, not a v2 state command.
310
-
311
- Errors (all exit 1, message on stderr):
312
-
313
- - Missing path: `gtd format: missing file path argument`
314
- - Extra arguments: `gtd format: too many arguments β€” expected one path, got: …`
315
- - Non-markdown file:
316
- `gtd format: <file> is not a markdown file (expected .md or .markdown)`
317
- - File not found: `gtd: skipped formatting <file>: not found`
318
-
319
- ## JSON schemas
320
-
321
- Pass `--json` to `step`, `step-agent`, `next`, `status`, `review`, `questions`,
322
- or `changesets` for machine-readable single-line JSON output instead of plain
323
- text.
324
-
325
- **`step` / `step-agent`** β€” `{state, actions, commits}`:
326
-
327
- ```json
328
- {
329
- "state": "architecting",
330
- "actions": ["capture the human turn as \"gtd(human): grilling\""],
331
- "commits": ["gtd(human): grilling", "gtd: architecting"]
332
- }
333
- ```
334
-
335
- - `state` β€” the final resolved state after the fixpoint loop settled.
336
- - `actions` β€” human-readable descriptions of every edge action this invocation
337
- performed, oldest→newest.
338
- - `commits` — every commit subject this invocation authored, oldest→newest.
339
-
340
- **`next`** β€” `{state, actor, pending, prompt}`:
341
-
342
- ```json
343
- {
344
- "state": "building",
345
- "actor": "agent",
346
- "pending": false,
347
- "prompt": "..."
348
- }
349
- ```
350
-
351
- - `state` β€” the resolved state.
352
- - `actor` β€” `"human"` or `"agent"`: who owns the next move. This is the single
353
- loop-driver signal: `"agent"` means proceed with another round β€” act on
354
- `prompt` when present, then run `gtd step-agent`; at an agent-driven pending
355
- checkpoint (`prompt` is `null`, nothing to act on) just run `gtd step-agent`.
356
- `"human"` means halt and hand off (a human rest, whose prompt body already
357
- tells the human what to do, or a human-driven pending checkpoint resumed by
358
- `gtd step`).
359
- - `pending` β€” `true` at a mid-chain HEAD (no prompt yet β€” resume with a mutator
360
- first); `false` at a genuine rest.
361
- - `prompt` β€” the full prompt markdown when `pending` is `false`, else `null`.
362
-
363
- **`status`** β€” `{state, actor, predictedCommit, predictedState}`:
364
-
365
- ```json
366
- {
367
- "state": "grilling",
368
- "actor": "human",
369
- "predictedCommit": "gtd(human): grilling",
370
- "predictedState": "grilling"
371
- }
372
- ```
373
-
374
- `predictedCommit` is `null` when the next invocation would author nothing (e.g.
375
- idle with a green health check).
376
-
377
- **`questions`** β€” `{file, questions, errors}`:
378
-
379
- ```json
380
- {
381
- "file": ".gtd/TODO.md",
382
- "questions": [
383
- {
384
- "question": "Which operations?",
385
- "status": "suggested",
386
- "text": "add and subtract."
387
- }
388
- ],
389
- "errors": []
390
- }
391
- ```
392
-
393
- `file` is `null` when neither `.gtd/TODO.md` nor `.gtd/ARCHITECTURE.md` is
394
- present. `errors` lists any structural problems in the file β€” the same diagnosis
395
- that would make `gtd step-agent` refuse the agent's next turn capture.
396
-
397
- **`changesets`** β€” `{file, shortHash, fullHash, changesets, errors}`:
398
-
399
- ```json
400
- {
401
- "file": ".gtd/REVIEW.md",
402
- "shortHash": "abc1234",
403
- "fullHash": "abc1234def5678901234567890123456789abcd",
404
- "changesets": [
405
- {
406
- "title": "Add calculator",
407
- "description": "New add function for the calculator.",
408
- "files": [{ "path": "./src/calc.ts", "line": 1, "checked": false }]
409
- }
410
- ],
411
- "errors": []
412
- }
413
- ```
414
-
415
- `file` is `null` when `.gtd/REVIEW.md` doesn't exist. `errors` mirrors
416
- `questions`' field above.
417
-
418
- **Error envelope** β€” every command, in `--json` mode, reports failures inside
419
- the JSON object rather than as unstructured text, and still exits 1:
420
-
421
- ```json
422
- { "state": "error", "prompt": "<message>" }
423
- ```
424
-
425
- There is no auto-advance flag anywhere in the wire format β€” `actor` replaces it.
426
- The caller decides whether to keep looping based on `actor` (halt on `"human"`)
427
- and `pending` (re-run `step`/`step-agent` first when `true`), not on a boolean
428
- auto-advance flag.
429
-
430
- ## The reference loop driver
431
-
432
- A minimal bash implementation of the pinned two-beat protocol, driving an agent
433
- CLI (e.g. `claude -p`) against `gtd --json` output. This is the authoritative
434
- reference for what a loop driver must do; keep any other implementation
435
- (including `skills/loop/SKILL.md`) consistent with it rather than editing both
436
- independently.
437
-
438
- ```bash
439
- #!/usr/bin/env bash
440
- set -euo pipefail
441
-
442
- while true; do
443
- # 1. Advance the machine's own agent-owned bookkeeping to a fixpoint.
444
- gtd step-agent --json >/dev/null || true
445
-
446
- # 2. Ask who's up next. `actor` is the single "proceed" signal.
447
- next="$(gtd next --json)"
448
- actor="$(jq -r .actor <<<"$next")"
449
- prompt="$(jq -r .prompt <<<"$next")"
450
-
451
- if [[ "$actor" != "agent" ]]; then
452
- echo "Halting β€” the human owns the next move."
453
- break
454
- fi
455
-
456
- if [[ "$prompt" == "null" ]]; then
457
- # Agent-driven pending checkpoint: nothing to act on β€” loop back to
458
- # step 1, whose `gtd step-agent` resumes the mid-chain bookkeeping.
459
- continue
460
- fi
461
-
462
- # Agent's turn: feed the prompt to the agent, then let it finish with
463
- # `gtd step-agent` itself (the prompt's tail instructs it to).
464
- claude -p "$prompt" --dangerously-skip-permissions
465
- done
466
- ```
467
-
468
- The agent is expected to run `gtd step-agent` itself once it finishes acting on
469
- the prompt (the plain-mode tail says exactly this) β€” the driver's own
470
- `step-agent` calls exist to advance any bookkeeping the agent doesn't own
471
- (routing commits, test runs) between agent turns.
50
+ schema stub on first run (see [Configuration](docs/configuration.md#auto-init)).
472
51
 
473
- The loop halts on `actor: "human"` alone: a human rest (`pending: false`, the
474
- prompt body addresses the human) or a human-driven pending checkpoint
475
- (`pending: true`, resumed by the human's own `gtd step`). Everything the agent
476
- side can drive β€” agent rests and agent-driven checkpoints β€” reports
477
- `actor: "agent"`, so multiple agent turns and commits (e.g. successive test/fix
478
- cycles, a force-approved package close) chain without human involvement until an
479
- actual human gate is hit.
52
+ ## How it works
480
53
 
481
- `bin/gtd-loop`, installed as the `gtd-loop` binary, is the packaged
482
- implementation of this exact script β€” kept in sync with it the same way
483
- `skills/loop/SKILL.md` is. It additionally attempts `gtd step` (not just
484
- `gtd step-agent`) every iteration, so a plain rerun after you've edited a file
485
- at a human gate (no commit needed) picks up your edit and keeps going, and it
486
- halts with a diagnostic if the same state and prompt repeat with no progress
487
- (see `skills/loop/SKILL.md`'s "Stall detection").
54
+ Three commands drive everything:
488
55
 
489
- ### Using a different agent
490
-
491
- `gtd-loop` defaults to
492
- `claude -p "$GTD_LOOP_PROMPT" --dangerously-skip-permissions`, but the agent
493
- invocation is swappable: set `GTD_LOOP_AGENT_CMD` to any shell command, and it
494
- runs with the prompt available as `$GTD_LOOP_PROMPT` in its environment. For
495
- example, to drive a different agent CLI:
496
-
497
- ```bash
498
- GTD_LOOP_AGENT_CMD='my-agent-cli --prompt "$GTD_LOOP_PROMPT"' gtd-loop
499
- ```
500
-
501
- ## States & subjects overview
502
-
503
- `resolve()` lands on exactly one of **21 states**: `grilling`, `architecting`,
504
- `grilled`, `planning`, `building`, `testing`, `fixing`, `escalate`,
505
- `agentic-review`, `close-package`, `review`, `await-review`, `done`, `learning`,
506
- `await-learning-review`, `learning-apply`, `learning-applied`, `squashing`,
507
- `idle`, `health-check`, `health-fixing`. Each state has a fixed awaited actor
508
- (see `awaitedActor` in `src/Machine.ts`): `idle`, `escalate`, `await-review`,
509
- and `await-learning-review` await the **human**; every other state awaits the
510
- **agent**.
511
-
512
- For the full precedence ladder, illegal combinations, and the counter folds that
513
- drive the fix loops, see [STATES.md](STATES.md) β€” this section is a summary.
514
-
515
- ### Turn commits β€” `gtd(<actor>): <gate>`
516
-
517
- Authored by `gtd step`/`gtd step-agent` as the first commit of a fresh chain.
518
- The closed set of gates:
519
-
520
- | Gate | Authored by |
521
- | ---------------- | ------------------------------------------------------------------ |
522
- | `grilling` | human (answers) / agent (product-plan iteration) |
523
- | `architecting` | human (answers) / agent (architecture iteration) |
524
- | `grilled` | agent (converged, ready to decompose) |
525
- | `building` | agent (package work, or human feedback while agent is out of turn) |
526
- | `fixing` | agent (test-fix or review-fix round) |
527
- | `agentic-review` | agent (writes .gtd/FEEDBACK.md verdict) |
528
- | `review` | agent (writes .gtd/REVIEW.md) / human (approves or gives feedback) |
529
- | `squashing` | agent (overwrites .gtd/SQUASH_MSG.md) |
530
- | `learning` | agent (overwrites .gtd/LEARNINGS.md) / human (accepts or edits) |
531
- | `learning-apply` | agent (integrates .gtd/LEARNINGS.md into CLAUDE.md/AGENTS.md/docs) |
532
- | `health-fixing` | agent (idle health-check repair) |
533
- | `escalate` | human (deletes .gtd/ERRORS.md to resume) |
534
-
535
- ### Routing commits β€” `gtd: <phase>`
536
-
537
- Bookkeeping the machine authors itself between turns, never a turn a human or
538
- agent "wins": `gtd: architecting`, `gtd: grilled`, `gtd: planning`,
539
- `gtd: tests green`, `gtd: errors`, `gtd: package done`, `gtd: awaiting review`,
540
- `gtd: review feedback`, `gtd: done`, `gtd: squash template`,
541
- `gtd: reviewing <hash>` (parameterized, from `gtd review`), `gtd: health-check`,
542
- `gtd: health-fix`, `gtd: learning template`, `gtd: learning drafted`,
543
- `gtd: learning approved`, `gtd: learning applied`.
544
-
545
- Everything else β€” any non-`gtd` subject, and any `gtd: *` subject outside this
546
- closed set β€” is a **boundary commit**: inert as far as the machine's grammar is
547
- concerned. See [Upgrading from v1](#upgrading-from-v1-breaking-change) for why
548
- this matters on upgrade.
549
-
550
- ## Workflow walkthroughs
551
-
552
- ### Grilling: two phases, product then architecture
553
-
554
- A dirty tree at a boundary HEAD (a fresh idea, sketched in a file or just left
555
- as pending code) is captured in **one** human turn: `gtd step` commits
556
- everything pending as `gtd(human): grilling` β€” nothing is reverted or seeded,
557
- the captured files stay in history. `gtd next` hands the agent that turn's diff;
558
- the agent develops `.gtd/TODO.md` into a concrete **product-level** plan **in
559
- one turn** β€” user-facing decisions only, no architecture β€” proposing a
560
- **suggested default** for every open question under an enforced
561
- `## Open Questions` structure (see
562
- [Structured grilling/architecting and review files](#structured-grillingarchitecting-and-review-files)),
563
- and leaves `.gtd/TODO.md` uncommitted for `gtd(agent): grilling`.
564
-
565
- There are no markers to answer β€” the human either:
566
-
567
- - **Accepts the suggested defaults**: runs a clean `gtd step` at the answer
568
- gate. An empty `gtd(human): grilling` turn plus routing `gtd: architecting`
569
- lands automatically β€” `.gtd/ARCHITECTURE.md` is seeded from the converged
570
- `.gtd/TODO.md` content and `.gtd/TODO.md` is deleted, in that one commit.
571
- - **Edits `.gtd/TODO.md`** with real answers, then runs `gtd step`, which
572
- captures the edit as a fresh `gtd(human): grilling` turn and hands it back to
573
- the agent for another round.
574
-
575
- Technical architecting works exactly the same way, one file later: the agent
576
- develops `.gtd/ARCHITECTURE.md` into a concrete **technical** plan β€” file/module
577
- structure, data model, tech-stack choices β€” and the human answers or accepts
578
- defaults at the `architecting` gate. Accepting converges to `gtd: grilled` and
579
- `gtd next` emits the decompose prompt (which now reads `.gtd/ARCHITECTURE.md`).
580
-
581
- **Escape hatch for already-technical input:** if the human's initial dirty tree
582
- already contains `.gtd/ARCHITECTURE.md` (their own technical sketch), `gtd step`
583
- captures the entry turn as `gtd(human): architecting` directly, skipping product
584
- grilling for that cycle entirely β€” no CLI flag needed, it's driven purely by
585
- which steering file is present.
586
-
587
- ### Structured grilling/architecting and review files
588
-
589
- `.gtd/TODO.md`, `.gtd/ARCHITECTURE.md`, and `.gtd/REVIEW.md` stay plain,
590
- human-readable markdown, but each follows an enforced structure so the data can
591
- be parsed out programmatically (`gtd questions` / `gtd changesets`, both
592
- `--json`-able, for a future UI) instead of staying opaque prose.
593
-
594
- **Grilling/architecting** (identical contract, one file and phase apart): an
595
- OPTIONAL `## Open Questions` section β€” omitted entirely means zero open
596
- questions, not an error. Every `###` sub-heading directly under it is one open
597
- question; its first body line must be `Suggested default: <text>` (the agent's
598
- proposal) or `Answer: <text>` (a human's answer):
599
-
600
- ```markdown
601
- # Plan
602
-
603
- Build a calculator that can add and subtract.
604
-
605
- ## Open Questions
606
-
607
- ### Which operations?
608
-
609
- Suggested default: add and subtract.
610
- ```
611
-
612
- **Review**: a `# Review: <short-hash>` header as the first line, an
613
- `<!-- base: <full-hash> -->` comment, and at least one `##` chunk with a
614
- non-empty title and at least one `- [ ]` / `- [x]` file-pointer line β€” the same
615
- format `@review` already instructs the agent to write (see
616
- [Human review gate](#human-review-gate) below).
617
-
618
- Validation applies ONLY to the **agent's own authored draft** at the gate that
619
- writes the file β€” never to a human's free-form edits (their answer at the
620
- grilling/architecting gate, their feedback/approval at the review gate). When
621
- the active file is malformed, `gtd step-agent` refuses (zero commits, a stderr
622
- message listing every structural problem) instead of capturing the turn; the
623
- agent fixes the file and reruns `gtd step-agent`. `gtd questions --json` /
624
- `gtd changesets --json` surface the same `errors` without blocking anything, so
625
- an agent (or a UI) can self-check before committing to a turn.
626
-
627
- ### Build lifecycle: budgets
628
-
629
- Once decomposed, `.gtd/` holds ordered work packages. `gtd next` at
630
- `gtd: planning`/`gtd: package done` selects the lowest-numbered remaining
631
- package and inlines only its task files. The agent builds it and leaves the work
632
- **uncommitted**; the next invocation's edge action commits it (the
633
- `gtd(agent): building` turn commit) and runs `testCommand`.
634
-
635
- - **Green** β†’ Agentic Review.
636
- - **Red, below `fixAttemptCap`** (default 3) β†’ write findings, commit
637
- `gtd: errors`, rest at **Fixing** for the agent.
638
- - **Red, at/over the cap** β†’ write `.gtd/ERRORS.md` instead, commit
639
- `gtd: errors`, rest at **Escalate** β€” a human gate. Deleting `.gtd/ERRORS.md`
640
- and landing that deletion as `gtd(human): escalate` resets the budget and
641
- re-tests from zero in the same invocation.
642
-
643
- ### Agentic review
644
-
645
- A green test run always rests at **Agentic Review**: the agent reviews the
646
- package's accumulated diff against its task specs and writes `.gtd/FEEDBACK.md`.
647
- An **empty** `.gtd/FEEDBACK.md` is the approval signal β€” the same
648
- `gtd(agent): agentic-review` turn closes the package (`gtd: package done`,
649
- removing `.gtd/FEEDBACK.md` and the finished package directory) in one
650
- invocation. Non-empty findings rest for the fixing prompt; fixing loops back
651
- through the test gate and re-reviews. Once `reviewFixCount >= reviewThreshold`
652
- (default 3) within a package, Agentic Review **force-approves** without ever
653
- writing `.gtd/FEEDBACK.md` β€” so a package can never review-loop forever. The
654
- findings round that crosses the threshold still gets its fixing round; the
655
- force-approve close then fires at the next green re-test instead of another
656
- review. (Any agentic-review turn that touches `.gtd/FEEDBACK.md` counts toward
657
- the threshold β€” including the approval write itself; an approval that crosses
658
- the threshold simply closes the package as usual.) Setting
659
- `agenticReview: false` force-approves every package immediately.
660
-
661
- A **do-nothing agent invocation** β€” `gtd step-agent` on a clean tree at ANY
662
- agent-awaited rest whose move is a file artifact (`grilling`, `architecting`,
663
- `grilled`, `building`, `fixing`, `agentic-review`, `review`, `squashing` while
664
- `.gtd/SQUASH_MSG.md` still holds the unmodified template, `learning` while
665
- `.gtd/LEARNINGS.md` still holds the unmodified template, and `learning-apply`
666
- unconditionally) β€” is inert: zero commits, no state consumed; `gtd next`
667
- re-emits the same prompt. This is load-bearing for the loop protocol, whose
668
- every iteration opens with `gtd step-agent` before the agent has acted: without
669
- the guard that opening beat would author junk empty turns β€” and worse, consume
670
- workflow state (an empty decompose turn would delete `.gtd/ARCHITECTURE.md` with
671
- no packages written; an empty squashing turn would squash the cycle under the
672
- placeholder template). The same guards hold at the classification layer for
673
- histories that already carry such turns: a `gtd(agent): grilled` HEAD only
674
- routes to `gtd: planning` when packages exist, a `gtd(agent): review` HEAD only
675
- routes to `gtd: awaiting review` when `.gtd/REVIEW.md` exists, and a squashing
676
- (or learning) turn only proceeds once its template has been overwritten. The one
677
- deliberate exception is `health-fixing`, whose empty turn is meaningful (the
678
- failure may have been environmental β€” the machine removes `.gtd/HEALTH.md` and
679
- re-tests). Human gates are unaffected: an empty **human** turn stays a signal
680
- (accept-defaults at grilling/architecting, clean approval at review,
681
- accept-the-draft-as-is at the learning review gate).
682
-
683
- ### Human review gate
684
-
685
- Once `.gtd/` is fully closed, the machine writes `.gtd/REVIEW.md` and rests at
686
- **await-review**, awaiting the human. Approval is any of:
687
-
688
- - A **clean** `gtd step` (nothing edited) β€” an empty `gtd(human): review` turn
689
- plus routing `gtd: done`.
690
- - Flipping only `- [ ]` β†’ `- [x]` checkboxes in `.gtd/REVIEW.md` β€” checkbox-only
691
- edits are also treated as clean approval.
692
- - Deleting `.gtd/REVIEW.md` outright.
693
-
694
- Any **substantive** edit β€” to `.gtd/REVIEW.md` prose, or to the reviewed code
695
- itself β€” is feedback: `gtd(human): review` plus routing `gtd: review feedback`,
696
- `.gtd/REVIEW.md` removed, and `gtd next` re-emits a grilling prompt to the agent
697
- that inlines the human's finding.
698
-
699
- **The review diff lives in your editor.** While the gate is pending, gtd holds
700
- open a _review checkout window_: it saves the real head to
701
- `refs/gtd/review-head`, then rewinds HEAD and the index to the review base with
702
- `git reset --mixed`, leaving the working tree untouched. Every editor's standard
703
- git integration now shows the entire reviewable diff as ordinary uncommitted
704
- changes β€” SCM panel, gutter marks, per-file diffs. Review it there:
705
-
706
- - **Edit** anything (code or `.gtd/REVIEW.md` prose) β†’ feedback.
707
- - **Discard a hunk** in the editor β†’ that reversion IS the feedback: the agent
708
- is re-grilled with it.
709
- - **Delete a surfaced file** β†’ reject-this-file feedback.
710
- - Touch nothing (or tick checkboxes / delete `.gtd/REVIEW.md`) β†’ approval.
711
-
712
- Any gtd invocation closes the window first (restoring HEAD/index exactly, so
713
- only your own edits remain dirty β€” they land as their own separate
714
- `gtd(human): review` commit, never mixed into the reviewed work), and
715
- `gtd next`/`gtd status` re-arm it on their way out. The mechanics are
716
- crash-safe; details and invariants in STATES.md ("The review checkout window").
717
-
718
- Caveats while a review is pending: don't push (the branch tip rests at the
719
- review base β€” the real head is safe under `refs/gtd/review-head`); commits you
720
- make manually survive as working-tree content and become review feedback, but
721
- their commit message is discarded; linked `git worktree` checkouts are
722
- unsupported. If you switch branches mid-review, gtd refuses to touch the foreign
723
- branch and prints the manual recovery command.
724
-
725
- ### Learning
726
-
727
- With `learning: true` (the default), `gtd: done` (or the health-fix path's green
728
- re-test) is **not** a rest β€” the chain continues straight to
729
- `gtd: learning template`, writing and committing a `.gtd/LEARNINGS.md` template,
730
- running _before_ the squash decision so it still sees the pre-squash history.
731
- `gtd next` then emits the learning prompt: the agent walks the cycle's test
732
- failures, review feedback, and health-check rounds, keeps only
733
- durable/generalizable lessons, and overwrites `.gtd/LEARNINGS.md` with them.
734
- Once `gtd step-agent` captures that draft (`gtd(agent): learning`), it rests at
735
- **await-learning-review** for a human β€” who either accepts the draft as-is (an
736
- empty turn) or edits it; there is no reject path, so the very next `gtd step`
737
- always proceeds (`gtd(human): learning` β†’ `gtd: learning approved`), resting at
738
- **learning-apply** for the agent. The agent integrates the approved learnings
739
- into the project's own docs (`CLAUDE.md`/`AGENTS.md`/wherever fits, its
740
- judgment); its turn (`gtd(agent): learning-apply`) removes `.gtd/LEARNINGS.md`
741
- and lands at `gtd: learning applied`, which then runs the same squash decision
742
- `gtd: done` runs today. With `learning: false`, `gtd: done` behaves exactly as
743
- it does without this section: no `.gtd/LEARNINGS.md` is ever written. Learning
744
- and squash are independent flags β€” either can be on without the other.
745
-
746
- ### Squash
747
-
748
- With `squash: true` (the default), `gtd: done` (or, once learning has run,
749
- `gtd: learning applied`) is **not** a rest β€” the same chain continues straight
750
- to `gtd: squash template`, writing and committing a `.gtd/SQUASH_MSG.md`
751
- template. `gtd next` then emits the squashing prompt: the agent overwrites
752
- `.gtd/SQUASH_MSG.md` with a real conventional-commits message (drawing on
753
- grilling- and architecting-round decisions from history) and finishes its turn.
754
- `gtd step-agent` then performs the squash itself: `git reset --soft <base>` +
755
- `git commit`, collapsing every intermediate `gtd: *` commit of the cycle into
756
- one β€” including any review-feedback detours, and the learning phase's own
757
- commits if learning ran: the squash base is the cycle's ORIGINAL start (the
758
- first grilling or, via the escape hatch, architecting turn since the previous
759
- `gtd: done` boundary, or the `gtd: reviewing <hash>` anchor for an ad-hoc review
760
- cycle), not the most recent re-grilling round β€” the collapse folds the whole
761
- cycle into one, using the overwritten message's content verbatim (turn position,
762
- not message content, triggers the squash). Doc edits made during
763
- `learning-apply` survive in the squashed tree, not as their own commit. With
764
- `squash: false`, `gtd: done` (or `gtd: learning applied`) is the resting
765
- boundary and no template is ever written.
766
-
767
- ### Health check
768
-
769
- Outside any process (idle, nothing to review, no steering files), `gtd step`
770
- runs `testCommand` as a health check rather than settling immediately. Green
771
- settles idle with zero commits. Red below `fixAttemptCap` writes
772
- `.gtd/HEALTH.md` and rests at **Health Fixing** for the agent; the fixer's own
773
- turn (`gtd(agent): health-fixing`) removes `.gtd/HEALTH.md` and re-tests in the
774
- same chain β€” a green re-test continues to learning (if enabled), then squash (if
775
- enabled), or idle; red repeats the health-fix loop; red at the cap writes
776
- `.gtd/ERRORS.md` and escalates.
777
-
778
- ### Escalate / budget reset
779
-
780
- `.gtd/ERRORS.md` present is always a human gate, regardless of which loop wrote
781
- it (test-fix or health-fix). Deleting `.gtd/ERRORS.md` and running `gtd step`
782
- records the deletion as the human's `gtd(human): escalate` turn, which
783
- **immediately re-tests in the same invocation** β€” this resets the relevant
784
- fix-attempt budget to zero.
785
-
786
- ## States & subjects: overview table
787
-
788
- | State | Awaits | Turn/routing subject at rest |
789
- | ----------------------- | -------------- | ---------------------------------------------------------------- |
790
- | `grilling` | human or agent | `gtd(human): grilling` / `gtd(agent): grilling` |
791
- | `architecting` | human or agent | `gtd: architecting` / `gtd(agent): architecting` |
792
- | `grilled` | agent | `gtd: grilled` |
793
- | `planning` | agent | `.gtd/` modified |
794
- | `building` | agent | `gtd: planning` / `gtd: package done` |
795
- | `testing` | β€” (edge-only) | mid-chain only |
796
- | `fixing` | agent | `gtd: errors` |
797
- | `escalate` | human | `.gtd/ERRORS.md` present |
798
- | `agentic-review` | agent | `gtd: tests green` |
799
- | `close-package` | β€” (edge-only) | mid-chain only |
800
- | `review` | agent | `gtd: package done` (no more packages) / `gtd: reviewing <hash>` |
801
- | `await-review` | human | `gtd: awaiting review` |
802
- | `done` | β€” (edge-only) | `gtd: done` |
803
- | `learning` | agent | `gtd: learning template` |
804
- | `await-learning-review` | human | `gtd: learning drafted` |
805
- | `learning-apply` | agent | `gtd: learning approved` |
806
- | `learning-applied` | β€” (edge-only) | `gtd: learning applied` |
807
- | `squashing` | agent | `gtd: squash template` |
808
- | `idle` | human | no steering files, green health check |
809
- | `health-check` | β€” (edge-only) | mid-chain only |
810
- | `health-fixing` | agent | `.gtd/HEALTH.md` present |
811
-
812
- See [STATES.md](STATES.md) for the full precedence ladder, the counter folds,
813
- and every illegal steering-file combination.
814
-
815
- ## Configuration
816
-
817
- gtd reads an optional `.gtdrc` config file via
818
- [cosmiconfig](https://github.com/cosmiconfig/cosmiconfig). With no config, the
819
- built-in defaults apply. Supported filenames (searched in this order):
820
-
821
- - `.gtdrc`
822
- - `.gtdrc.json`
823
- - `.gtdrc.yaml`
824
- - `.gtdrc.yml`
825
- - `gtd.config.json`
826
- - `gtd.config.yaml`
827
-
828
- ### Schema
829
-
830
- - **`testCommand`** (string, default `npm run test`) β€” the command the edge runs
831
- after a build turn, and on the idle health-check path.
832
- - **`fixAttemptCap`** (non-negative integer, default `3`) β€” the test-fix budget:
833
- how many `gtd: errors` attempts are allowed per sub-loop before the failure is
834
- escalated to `.gtd/ERRORS.md` (Escalate). `0` disables the cap (escalates
835
- immediately on the first red run). Also reused as the health-fix budget β€” no
836
- separate config key.
837
- - **`reviewThreshold`** (integer β‰₯ 1, default `3`) β€” the review-fix budget: how
838
- many agentic-review findings rounds are allowed per package before Agentic
839
- Review force-approves.
840
- - **`agenticReview`** (boolean, default `true`) β€” kill-switch for the
841
- per-package Agentic Review gate. Set `false` to force-approve every package
842
- and proceed directly to human review.
843
- - **`squash`** (boolean, default `true`) β€” after `gtd: done` (or, once learning
844
- has run, `gtd: learning applied`), collapse the cycle's `gtd: *` commits into
845
- a single conventional-commits commit. Set `false` to keep the granular
846
- history.
847
- - **`learning`** (boolean, default `true`) β€” after `gtd: done` (or the
848
- health-fix path's green re-test), distill durable lessons from the cycle into
849
- `.gtd/LEARNINGS.md`, have a human review them, then integrate them into the
850
- project's own docs before the squash decision runs. Set `false` to skip the
851
- phase entirely β€” independent of `squash`.
852
- - **`models`** β€” model selection for the subagent-spawning states:
853
- - `planning` β€” high-reasoning tier (default `claude-opus-4-8`), used by
854
- `decompose` (the `grilled`/`planning` states), `grilling`, `architecting`,
855
- `agentic-review`, and `clean` (the `review`/`squashing`/`learning`/
856
- `learning-apply` states).
857
- - `execution` β€” everyday tier (default `claude-sonnet-4-8`), used by
858
- `building` and `fixing`.
859
- - `states.*` β€” per-state overrides keyed by `decompose`, `grilling`,
860
- `architecting`, `building`, `fixing`, `agentic-review`, `clean`. Unknown
861
- `states` keys are **rejected**.
862
- - **`$schema`** (string, optional) β€” stripped before validation, so it never
863
- counts as an unknown key. Point it at the published schema for editor-backed
864
- autocompletion. A `schema.json` is generated from the config schema at build
865
- time and ships with the package.
866
-
867
- ### Validation and errors
868
-
869
- If a config file fails to load or is invalid, gtd **exits with code 1** and
870
- writes a human-readable error to **stderr** (never stdout):
871
-
872
- - **Parse errors** (malformed YAML/JSON) β€” message includes the offending
873
- filename.
874
- - **Non-object top-level** β€” a YAML list or `null` at the root is rejected with
875
- the filename in the message.
876
- - **Schema violations** β€” unknown keys or out-of-range values emit
877
- `Invalid gtd config: <field>: <reason>`.
878
- - **Missing test binary** β€” if `testCommand` names an executable that cannot be
879
- found (`ENOENT`), gtd exits 1 with `gtd: test command not found: <command>` on
880
- stderr. A non-zero test _exit code_ is not an error β€” it drives the normal red
881
- path.
882
-
883
- ### Lookup and precedence
884
-
885
- gtd walks from the current working directory **up to your home directory** (or
886
- to the filesystem root when cwd is outside home), collecting every `.gtdrc` it
887
- finds along the way. All found levels are **deep-merged**, with the **innermost
888
- (cwd) config winning** on conflicts β€” so a shared `.gtdrc` in a worktree-parent
889
- directory cascades to every checkout beneath it, while any individual checkout
890
- can still override settings with its own `.gtdrc`.
891
-
892
- ### Auto-init
893
-
894
- On every **state command** (`step`, `step-agent`, `next`, `status`, `review`)
895
- that has passed the repo-root guard, if the cwd→root walk finds **no** config
896
- anywhere, gtd creates and commits a starter `.gtdrc.json` at the repository root
897
- containing only a `$schema` link. Auto-init never runs for `--version`/`--help`,
898
- `format`, bare/unknown commands, or an invocation refused by the repo-root guard
899
- β€” those perform no repository mutation of any kind. On a repo with no commits
900
- yet, or whose HEAD is a plain (non-`gtd:`) commit, the stub is committed as its
901
- own `chore: add .gtdrc.json`. If HEAD is already a `gtd:`-owned commit
902
- (mid-workflow), the stub is instead **amended into HEAD** β€” stacking a fresh
903
- boundary commit there would produce an unrecognized HEAD most workflow states
904
- can't resolve past.
905
-
906
- ### Example
907
-
908
- ```yaml
909
- # .gtdrc.yaml
910
- testCommand: pnpm test
911
- fixAttemptCap: 3
912
- reviewThreshold: 3
913
- agenticReview: true
914
- squash: true
915
- learning: true
916
- models:
917
- planning: claude-opus-4-8
918
- execution: claude-sonnet-4-8
919
- states:
920
- decompose: claude-opus-4-8
921
- building: claude-sonnet-4-8
922
- ```
923
-
924
- ## Repository requirements
925
-
926
- - **Single writer, linear branch.** State is folded from **first-parent**
927
- history only. A merge commit at HEAD is unsupported (documented, not handled)
928
- β€” it degrades gracefully on the default branch rather than crashing, but do
929
- not rely on merge commits mid-cycle.
930
- - **Test/build artifacts must be gitignored.** This is **load-bearing**, not a
931
- style preference: every fixpoint hop in `gtd step`/`gtd step-agent` detects
932
- "clean" via `git status --porcelain`, which silently omits anything matched by
933
- `.gitignore`. If your `testCommand` (or the build it triggers) writes
934
- tracked-but-untracked output β€” a `dist/`, a coverage report, a log file β€” into
935
- the working tree, the tree never goes clean after a green test run, and the
936
- fixpoint loop cannot converge: it will either loop forever re-detecting a
937
- "dirty" boundary or misclassify build output as the human's next feature
938
- capture. Gitignore every path your test/build toolchain writes before wiring
939
- gtd into a repo.
940
- - **Repository root invocation.** Every subcommand except `--help`/`--version`
941
- must run from the git repository root β€” steering files and diffs are resolved
942
- against the process cwd.
943
-
944
- ## Build orchestration
945
-
946
- ### Decompose
947
-
948
- The Grilled/Planning states spawn a planning-model subagent that breaks
949
- `.gtd/ARCHITECTURE.md` into executable work packages under `.gtd/`:
950
-
951
- ```
952
- .gtd/
953
- 01-auth-module/
954
- 01-define-types.md
955
- 02-implement-login.md
956
- 02-api-endpoints/
957
- 01-create-routes.md
958
- 02-add-middleware.md
959
- ```
960
-
961
- Rules:
962
-
963
- - **Packages are sequential, in ordinal dependency order** β€” `01-`, `02-`, …;
964
- the set is frozen once written. Package 02 cannot start until 01 is complete.
965
- - **Each package is green on its own** β€” the test suite runs after every
966
- package, so none may leave the tree red for a later package to fix.
967
- - **Tasks within a package are parallel and file-disjoint** β€” one subagent per
968
- task, no isolation; tasks that would touch the same file are merged into one.
969
- - **Vertical slices, not horizontal** β€” each package is a thin, end-to-end
970
- slice; prefer many thin packages over a "set up infrastructure" package.
971
- - **Task files are self-contained** β€” description, acceptance-criteria
972
- checkboxes, relevant file paths, constraints, and edge cases.
973
-
974
- ### Execute
975
-
976
- Execution is **one package per cycle**. `gtd next` selects the single next
977
- package itself, names it in the prompt, and inlines its task files' full
978
- contents β€” the agent never browses `.gtd/` or picks a package itself. A single
979
- cycle:
980
-
981
- 1. Spawn parallel execution-model workers for all tasks in the selected package.
982
- 2. Leave all changes **uncommitted**. Do not commit, do not delete the package
983
- directory, do not run tests.
984
- 3. Finish the turn with `gtd step-agent` β€” the next hop's edge action commits
985
- the work (`gtd(agent): building`) and runs `testCommand` to verify it.
986
-
987
- ## Upgrading from v1 (BREAKING CHANGE)
988
-
989
- v2 ships as a **major** semantic-release bump (`2.0.0`) so the binary and the
990
- loop-driving text (this README, `skills/loop/SKILL.md`) can never skew against
991
- each other. There is **no backward compatibility with the v1 command surface**:
992
- the single mutating `gtd` command, marker/sentinel files, the `autoAdvance` JSON
993
- field, and the `gtd: transport` handoff commit are all gone. `gtd` bare now
994
- errors rather than driving a loop; use `gtd step-agent` / `gtd next` /
995
- `gtd step` instead.
996
-
997
- **Commit-history compatibility is one-way.** Any repo with v1-taxonomy history
998
- in it (`gtd: new task`, `gtd: grilling`, `gtd: transport`, a bare
999
- `gtd: reviewing` with no hash, …) upgrades cleanly: those subjects fall outside
1000
- v2's closed turn/routing grammar and parse as inert **boundary commits** β€” they
1001
- are never mistaken for v2 workflow state and never error.
1002
-
1003
- **Finish or clean up any in-flight v1 cycle first.** If a repo has an
1004
- **in-progress** v1 cycle β€” steering files present (root-level `TODO.md`,
1005
- `REVIEW.md`, `FEEDBACK.md`, `ERRORS.md`, or `.gtd/`) whose HEAD carries v1-only
1006
- commit subjects β€” the v2 binary does not know how to resume it: v1 steering
1007
- files have no v2 turn commit backing them, so a cold v2 invocation on that tree
1008
- can land in an unrecognized state. Either finish the v1 cycle to a clean
1009
- boundary with your existing v1 binary before upgrading, or manually clean up
1010
- (remove the steering files / `.gtd/`, commit the result) so the upgrade starts
1011
- from a plain boundary HEAD.
1012
-
1013
- **Steering files moved into `.gtd/`.** Earlier v2 builds kept `TODO.md`,
1014
- `REVIEW.md`, `FEEDBACK.md`, `ERRORS.md`, `HEALTH.md`, and `SQUASH_MSG.md` at the
1015
- repository root; they now live under `.gtd/`. Upgrade at a clean boundary (idle,
1016
- post-squash): a repo at rest needs nothing. Mid-cycle repos should either finish
1017
- the cycle on the old build first or move the root-level steering files into
1018
- `.gtd/` by hand and commit. History classification is backward-compatible β€” the
1019
- counter folds recognize both the old root paths and the new `.gtd/` paths in
1020
- existing commits.
1021
-
1022
- **Re-copy the loop skill.** If you vendor `skills/loop/` into a consuming repo
1023
- or agent harness, upgrading the `gtd` binary also means re-copying that skill
1024
- from this release β€” the v1 skill text still describes the old single-command
1025
- loop and will drive the new binary incorrectly.
1026
-
1027
- For maintainers: this repo releases via `semantic-release` reading Conventional
1028
- Commits, and needs **no config change** for a major bump β€” but the release
1029
- commit/PR **must carry a `BREAKING CHANGE:` footer** (or a `!` after the type)
1030
- for `@semantic-release/commit-analyzer` to compute `2.0.0` rather than a
1031
- minor/patch bump.
1032
-
1033
- ## Development
1034
-
1035
- ```bash
1036
- npm install
1037
- npm run dev # run from source, no build (node dev/run.mjs)
1038
- npm run build # tsdown β†’ dist/gtd.bundle.mjs
1039
- npm test # format:check, typecheck, lint, unit + e2e tests, fallow
1040
- npm run test:unit # vitest unit tests (the pure resolver) β€” --project unit
1041
- npm run test:e2e # gherkin e2e via vitest + quickpickle β€” --project e2e
1042
- npm run test:mutation # StrykerJS mutation testing (manual only, ~2 min)
1043
- npm run typecheck
1044
- npm run lint
1045
- ```
1046
-
1047
- ### Pre-commit hook
1048
-
1049
- A pre-commit hook is installed automatically via the `prepare` script when you
1050
- run `npm install` on a fresh clone β€” no manual setup needed. The hook runs
1051
- [lint-staged](https://github.com/lint-staged/lint-staged) with
1052
- [oxfmt](https://oxc.rs/docs/guide/usage/formatter.html), formatting every staged
1053
- file before each commit (`oxfmt --no-error-on-unmatched-pattern --write`),
1054
- mirroring the `format:check` step enforced in CI (`oxfmt --check .`).
1055
-
1056
- ### Prompt templates
1057
-
1058
- Each prompt-bearing state has a self-contained Eta template in
1059
- `src/prompts/*.md` that owns its full prompt β€” header, context, and body. Shared
1060
- fragments live as partials in `src/prompts/partials/`: `header`, the context
1061
- renderers (`diff`, `feedback`, `package`), and the single `agent-turn` tail
1062
- partial (the pinned "Finish your turn by running `gtd step-agent`. Then run
1063
- `gtd next` …" loop-closing instructions).
1064
-
1065
- At module load, `src/Prompt.ts` registers every template on a single `new Eta()`
1066
- instance via `loadTemplate`. `readFile` and `resolvePath` are nulled afterward
1067
- so rendering resolves exclusively from the in-memory cache β€” the compiled ESM
1068
- bundle carries no runtime `fs` dependency.
1069
-
1070
- `buildPrompt(result, resolveModel?, output?)` selects the state's template,
1071
- builds a view-model (model string, tail partial name, context), renders it,
1072
- collapses runs of three or more blank lines to two, and ensures exactly one
1073
- trailing newline. It throws for the five states that render no prompt at all
1074
- (`testing`, `planning`, `close-package`, `done`, `health-check`) β€” those are
1075
- performed entirely by the edge.
1076
-
1077
- `npm run dev` runs `src/main.ts` directly via Node's native TypeScript
1078
- type-stripping (requires Node 22.6+). It registers `dev/hooks.mjs`, which fills
1079
- the two gaps the tsdown build otherwise covers: resolving `./Foo.js` specifiers
1080
- to the on-disk `./Foo.ts`, and importing `*.md` prompt files as text. Pass CLI
1081
- args after `--`, e.g. `npm run dev -- format <file>`.
1082
-
1083
- The decision core (`src/Machine.ts`) is pure and IO-free, so the whole 16-state
1084
- ladder and both counter folds are trivially unit-testable in isolation; all
1085
- git/filesystem IO is confined to the edge (`src/Events.ts`).
1086
-
1087
- `npm run build` produces `dist/gtd.bundle.mjs`, which npm exposes as the `gtd`
1088
- binary via the `bin` field in `package.json`.
1089
-
1090
- ### Mutation testing
1091
-
1092
- Run mutation testing on-demand with `npm run test:mutation` (StrykerJS, ~2 min)
1093
- β€” never run it as part of routine development; it is a deliberate,
1094
- manually-triggered check. The single `stryker.config.json` mutates six core
1095
- files:
1096
-
1097
- ```
1098
- src/Machine.ts src/Prompt.ts src/Config.ts
1099
- src/Format.ts src/State.ts src/Events.ts
1100
- ```
1101
-
1102
- `src/Git.ts` is excluded: the Cucumber harness stubs git at the Effect boundary,
1103
- so `Git.ts` mutants have zero in-memory coverage.
1104
-
1105
- The HTML report lands in `reports/mutation/mutation.html` (git-ignored).
1106
-
1107
- ## Releasing
56
+ - **`gtd step`** β€” advance the workflow as the **human** actor.
57
+ - **`gtd step-agent`** β€” advance the workflow as the **agent** actor.
58
+ - **`gtd next`** β€” print the prompt for whichever actor is currently awaited,
59
+ without mutating anything.
1108
60
 
1109
- Releases are automatic. Push releasable Conventional Commits (`fix:`, `feat:`,
1110
- or breaking changes) to `main` and the Release workflow runs the tests, then
1111
- `npx semantic-release`. Semantic-release computes the next version, writes it
1112
- into `package.json`, builds the bundle, commits the bump back as
1113
- `chore(release): X.Y.Z [skip ci]`, tags `vX.Y.Z`, and creates the GitHub release
1114
- with `gtd.bundle.mjs` attached.
61
+ The loop is two beats, repeated: run `gtd step-agent`, then `gtd next --json`.
62
+ If the `actor` field says `"agent"`, feed the prompt to your agent and repeat;
63
+ if it says `"human"`, stop β€” it's your move. You act by editing files (answering
64
+ questions, reviewing the diff in your editor, fixing code) and running
65
+ `gtd step`.
66
+
67
+ Along the way, gtd grills your idea into a product plan, then a technical
68
+ architecture, decomposes it into work packages, builds them one at a time, runs
69
+ your tests after every package, has the agent review its own diff, walks you
70
+ through a final review, and squashes the whole cycle into one clean commit.
71
+
72
+ You don't have to start at the beginning: the steering file you hand the entry
73
+ turn picks the phase β€” plain notes start product grilling,
74
+ `.gtd/ARCHITECTURE.md` starts technical grilling, a final `.gtd/PLAN.md` goes
75
+ straight to decomposition, and a hand-written `.gtd/HEALTH.md` goes straight
76
+ into the error-fixing loop. See
77
+ [Entry points](docs/workflow.md#entry-points-which-file-starts-the-cycle-where).
78
+
79
+ `gtd-loop`, installed alongside `gtd`, is a ready-to-run driver for the whole
80
+ protocol β€” point it at a repo and it runs the loop until it's your turn. See
81
+ [Driving the loop](docs/loop.md).
82
+
83
+ Before wiring gtd into a repo, note the
84
+ [repository requirements](docs/cli.md#repository-requirements) β€” most
85
+ importantly: gitignore everything your test command writes.
86
+
87
+ ## Documentation
88
+
89
+ - [CLI reference](docs/cli.md) β€” every command, exit codes, JSON schemas,
90
+ repository requirements
91
+ - [The workflow](docs/workflow.md) β€” states, grilling, budgets, the review gate,
92
+ learning, squash
93
+ - [Driving the loop](docs/loop.md) β€” the reference loop driver, `gtd-loop`,
94
+ custom agents
95
+ - [Configuration](docs/configuration.md) β€” `.gtdrc` schema, lookup, auto-init
96
+ - [Upgrading from v1](docs/upgrading-from-v1.md) β€” breaking changes and
97
+ migration
98
+ - [Development](docs/development.md) β€” building, testing, releasing
99
+ - [STATES.md](STATES.md) β€” the full state-machine specification
1115
100
 
1116
101
  ## License
1117
102