@pmelab/gtd 6.6.0 → 6.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.
@@ -1,481 +0,0 @@
1
- # The `advanced` template: the full grilling → architecting → decompose → picking → review machine
2
-
3
- This walks through the **`advanced`** bundled workflow template — the fuller
4
- machine `gtd init advanced` scaffolds (`src/workflows/advanced.yaml`). The other
5
- bundled template, **`simple`** (`gtd init simple`), is the smaller 10-state
6
- machine walked through in
7
- [STATES.md §10](../../STATES.md#10-the-bundled-workflow-templates) — including
8
- the two steering-file validation loops it carries over `.gtd/TODO.md` and
9
- `.gtd/REVIEW.md`, which this machine's own `grilling`/`reviewing` phases predate
10
- and don't validate. `gtd init advanced` writes the block below directly, so you
11
- normally don't paste it by hand; it's reproduced here as the annotated
12
- reference.
13
-
14
- Compared to the `simple` template, this machine adds:
15
-
16
- - **Two-phase human-in-the-loop planning with Q&A loops** — `grilling` ⇄
17
- `grilling-answer` develops a product-level plan from `.gtd/TODO.md` one open
18
- question at a time; `architecting` ⇄ `architecting-answer` repeats the same
19
- shape for `.gtd/ARCHITECTURE.md`, the technical plan built on top of the
20
- converged product plan.
21
- - **Task decomposition** — `decompose` turns the converged architecture into an
22
- ordered set of self-contained task files under `.gtd/tasks/`.
23
- - **The deterministic `picking` queue arbiter** — a `script` state that feeds
24
- tasks into `.gtd/NEXT.md` one at a time, with a per-task `building` →
25
- `checking`/`fixing` loop, until the queue empties.
26
- - **Agent-prepared review** — `reviewing` has the agent write `.gtd/REVIEW.md`
27
- summarizing the full cycle diff for a human to check before `await-review`
28
- resolves an approval or feedback. `reviewing` also declares
29
- `reviewEntry: true`, so `gtd review <commitish>` can start a review process
30
- here directly over `<commitish>..HEAD` (e.g. a colleague's PR branch) — see
31
- [STATES.md §11](../../STATES.md#11-the-review-checkout-window).
32
- - **A squash finale** — approval at `await-review` moves to `squashing` (the
33
- agent authors `.gtd/COMMIT_MSG.md`) and then `done`, a `commit:` state that
34
- squashes the whole cycle into one commit. The `simple` template drops this: it
35
- rests at `idle` on approval instead and leaves every turn commit in history
36
- for the human to squash (or not) however they choose.
37
-
38
- This example also carries `file:`/`mode:` annotations on every state that rests
39
- on a steering file (see the state table below and
40
- [docs/design/state-file-association.md](../design/state-file-association.md)) —
41
- it is the LSP-heavy flow, with `gtd lsp` dispatching document symbols/code
42
- actions/diagnostics off those declarations rather than a hardcoded basename:
43
- `grilling`/`grilling-answer` and `architecting`/`architecting-answer` are
44
- `qa`-format (`vars.todoFile`/`vars.architectureFile` respectively — a new
45
- `architectureFile` var joins `testCommand`), `reviewing`/`await-review` are
46
- `review`-format (`vars.reviewFile`), and `fixing`/`escalate` declare `file:`
47
- alone (`vars.feedbackFile` is plain text, no LSP format).
48
-
49
- Running `gtd init advanced` writes this whole definition into `.gtdrc.json`
50
- under a `workflow:` key for you. The block below is the same definition in YAML
51
- form (the source is `src/workflows/advanced.yaml`), nested under `workflow:` —
52
- paste it into your own `.gtdrc`/`.gtdrc.yaml` if you'd rather hand-author or
53
- tweak it. See [Configuration](../configuration.md) for the `.gtdrc` schema this
54
- slots into.
55
-
56
- ## State table
57
-
58
- | State | Actor | Content | `on` | Retry | Model | File | Mode |
59
- | --------------------- | ----- | ------- | --------------------------------------------------------------------------------- | ------------------ | ------- | ----------------------- | -------- |
60
- | `idle` (initial) | human | message | `* **` → `grilling` | — | — | — | — |
61
- | `grilling` | agent | prompt | `* **` → `grilling-answer` | — | `smart` | `vars.todoFile` | `qa` |
62
- | `grilling-answer` | human | message | `C` → `architecting`; `* **` → `grilling` | — | — | `vars.todoFile` | `qa` |
63
- | `architecting` | agent | prompt | `* **` → `architecting-answer` | — | `smart` | `vars.architectureFile` | `qa` |
64
- | `architecting-answer` | human | message | `C` → `decompose`; `* **` → `architecting` | — | — | `vars.architectureFile` | `qa` |
65
- | `decompose` | agent | prompt | `* .gtd/tasks/**` → `picking` | — | `base` | — | — |
66
- | `picking` | check | script | `D .gtd/NEXT.md` → `reviewing`; `* .gtd/NEXT.md` → `building`; `C` → `reviewing` | — | — | — | — |
67
- | `building` | agent | prompt | `* **` → `checking` | — | `base` | — | — |
68
- | `checking` | check | script | `A .gtd/FEEDBACK.md` → `fixing`; `M .gtd/FEEDBACK.md` → `fixing`; `C` → `picking` | — | — | — | — |
69
- | `fixing` | agent | prompt | `* **` → `checking` | max 3 → `escalate` | `base` | `vars.feedbackFile` | — |
70
- | `escalate` | human | message | `* **` → `checking` | — | — | `vars.feedbackFile` | — |
71
- | `reviewing` | agent | prompt | `* .gtd/REVIEW.md` → `await-review` | — | `smart` | `vars.reviewFile` | `review` |
72
- | `await-review` | human | message | `D .gtd/REVIEW.md` → `squashing`; `* **` → `grilling` | — | — | `vars.reviewFile` | `review` |
73
- | `squashing` | agent | prompt | `A .gtd/COMMIT_MSG.md` → `done`; `M .gtd/COMMIT_MSG.md` → `done` | — | `base` | — | — |
74
- | `done` | — | commit | (final — squashes the whole cycle, message read from `.gtd/COMMIT_MSG.md`) | — | — |
75
-
76
- ## The `.gtdrc` recipe
77
-
78
- ````yaml
79
- workflow:
80
- vars:
81
- testCommand: npm test
82
- todoFile: .gtd/TODO.md
83
- architectureFile: .gtd/ARCHITECTURE.md
84
- reviewFile: .gtd/REVIEW.md
85
- feedbackFile: .gtd/FEEDBACK.md
86
- # The two model tiers every agent state draws from — opaque harness hints,
87
- # repointed here (or via a top-level .gtdrc `vars:` / `GTD_VAR_` override)
88
- # to change every state on that tier at once.
89
- plannerModel: smart
90
- coderModel: base
91
-
92
- states:
93
- idle:
94
- actor: human
95
- initial: true
96
- message: |
97
- No active gtd cycle.
98
-
99
- To start one: write `.gtd/TODO.md` with a short sketch of what you want
100
- built — a few sentences is enough — then run `gtd step human`.
101
- on:
102
- "* **": grilling
103
-
104
- grilling:
105
- actor: agent
106
- file: <%= it.vars.todoFile %>
107
- mode: qa
108
- # `model` is an opaque harness hint — gtd never interprets this string, it
109
- # only passes it through to `gtd next --json`/`gtd status --json` so the
110
- # driving loop can map it onto whatever models its agent harness provides.
111
- # Every agent state draws its tier from a `vars` model entry (see `vars:`
112
- # above): `plannerModel` (default "smart") for the one-shot planning/
113
- # architecting/reviewing turns, `coderModel` (default "base") for the
114
- # decompose/build/fix/squash turns.
115
- model: <%= it.vars.plannerModel %>
116
- prompt: |
117
- You are an autonomous coding agent. `.gtd/` holds this workflow's own
118
- state (plans, task specs, review records) — never create, edit, or
119
- delete anything under `.gtd/` except `<%= it.vars.todoFile %>`, which
120
- this prompt tells you to write.
121
-
122
- `<%= it.vars.todoFile %>` holds the plan under development. Read it,
123
- then develop it into a concrete, product-level plan in this one turn —
124
- explore the codebase before asking anything, so every open question is
125
- one the codebase genuinely cannot answer.
126
-
127
- Scope: product and user-facing decisions only. Leave implementation
128
- details (file/module structure, data models, tech-stack choices) for
129
- the next phase (`.gtd/ARCHITECTURE.md`).
130
-
131
- For every remaining open question, add it under a `## Open Questions`
132
- heading near the top, one `### <question>` sub-heading each, its body
133
- your suggested answer in plain prose (always suggest one — the human
134
- accepts it by leaving it untouched, or overrides it by editing it). Omit
135
- the section entirely once there are none.
136
-
137
- If `.gtd/TODO.md` already carries a `## Open Questions` section from a
138
- previous lap, the human has now responded to that whole batch: fold every
139
- one of those questions into the plan — the human's edit where they gave
140
- one, your own suggestion where they left it untouched (an untouched
141
- suggestion IS acceptance) — and MOVE each resolved `### <question>` block
142
- down into a `## Answered Questions` section at the bottom. Raise any
143
- genuinely new questions under `## Open Questions` at the top.
144
-
145
- Leave `.gtd/TODO.md` uncommitted and finish your turn — do not commit,
146
- and do not run `gtd step agent` yourself; the harness does that.
147
- on:
148
- "* **": grilling-answer
149
-
150
- grilling-answer:
151
- actor: human
152
- file: <%= it.vars.todoFile %>
153
- mode: qa
154
- message: |
155
- `<%= it.vars.todoFile %>` holds the plan under development, with any
156
- open questions under `## Open Questions` — each carrying a suggested
157
- answer.
158
-
159
- To answer a question, edit its body in place, then run
160
- `gtd step human`; leave a suggestion untouched to accept it as-is. On the
161
- next lap the agent folds every answered question into the plan and moves
162
- it down to `## Answered Questions`.
163
-
164
- To accept all suggested answers as-is and move on to technical
165
- architecting, run `gtd step human` with no edits.
166
- on:
167
- "C": architecting
168
- "* **": grilling
169
-
170
- architecting:
171
- actor: agent
172
- file: <%= it.vars.architectureFile %>
173
- mode: qa
174
- model: <%= it.vars.plannerModel %>
175
- prompt: |
176
- You are an autonomous coding agent. `.gtd/` holds this workflow's own
177
- state — never create, edit, or delete anything under `.gtd/` except
178
- `<%= it.vars.architectureFile %>` and `<%= it.vars.todoFile %>`, which
179
- this prompt tells you to write and delete respectively.
180
-
181
- Read `<%= it.vars.todoFile %>` (the converged product plan) and
182
- develop `<%= it.vars.architectureFile %>` from it in this one turn:
183
- file/module structure, data models, library/tech-stack choices,
184
- error-handling strategy — the *how*, building on the *what* already
185
- settled. Do not re-open product-level decisions from
186
- `<%= it.vars.todoFile %>`; treat them as settled.
187
-
188
- For every remaining open question, add it under a `## Open Questions`
189
- heading the same way as the grilling phase (one `### <question>`
190
- sub-heading, its body your suggested answer in plain prose). Omit the
191
- section once there are none. On a return lap, fold the whole answered
192
- batch into the plan and move each resolved `### <question>` block down
193
- into a `## Answered Questions` section at the bottom, exactly as grilling
194
- does.
195
-
196
- Once `<%= it.vars.architectureFile %>` is written, delete
197
- `<%= it.vars.todoFile %>` — its content has been folded in and it must
198
- not linger.
199
-
200
- Leave everything uncommitted and finish your turn.
201
- on:
202
- "* **": architecting-answer
203
-
204
- architecting-answer:
205
- actor: human
206
- file: <%= it.vars.architectureFile %>
207
- mode: qa
208
- message: |
209
- `<%= it.vars.architectureFile %>` holds the technical plan under
210
- development, with any open questions under `## Open Questions`.
211
-
212
- To answer a question, edit its body in place, then run `gtd step human`;
213
- leave a suggestion untouched to accept it as-is.
214
-
215
- To accept all suggested answers as-is and move on to decomposing the
216
- work, run `gtd step human` with no edits.
217
- on:
218
- "C": decompose
219
- "* **": architecting
220
-
221
- decompose:
222
- actor: agent
223
- model: <%= it.vars.coderModel %>
224
- prompt: |
225
- You are an autonomous coding agent. `.gtd/` holds this workflow's own
226
- state — never create, edit, or delete anything under `.gtd/` except the
227
- task-spec files this prompt tells you to write (under `.gtd/tasks/`),
228
- and `.gtd/ARCHITECTURE.md`, which it tells you to delete.
229
-
230
- Read `.gtd/ARCHITECTURE.md` (the converged technical plan) and
231
- decompose it into an ordered set of self-contained task files under
232
- `.gtd/tasks/` (e.g. `.gtd/tasks/01-short-name.md`,
233
- `.gtd/tasks/02-short-name.md`, ...). Order them so the test suite can
234
- pass again after each one lands; each file is self-contained
235
- (description, acceptance criteria as `- [ ]` checkboxes, relevant
236
- paths) since a building turn receives only that one file as context.
237
-
238
- No task file may reference any other `.gtd/` file, or a requirement to
239
- preserve/update workflow state — `.gtd/` is machine-managed and gets
240
- cleaned up as the cycle proceeds.
241
-
242
- Once the task files are written, delete `.gtd/ARCHITECTURE.md`. Leave
243
- everything uncommitted and finish your turn.
244
- on:
245
- "* .gtd/tasks/**": picking
246
-
247
- picking:
248
- actor: check
249
- script: |
250
- #!/usr/bin/env bash
251
- # gtd check turn (the queue arbiter) — the loop driver executes
252
- # this verbatim, then steps the check actor. Mechanics only: take the
253
- # first task file (by name) under .gtd/tasks/ into .gtd/NEXT.md, or
254
- # remove .gtd/NEXT.md when the queue is empty. What NEXT.md's
255
- # presence/absence MEANS (another task to build vs. the queue closing
256
- # out to review) is decided by this state's own `on` rules at capture
257
- # time — never here.
258
- set +e
259
- next=$(ls .gtd/tasks/*.md 2>/dev/null | head -n 1)
260
- if [ -n "$next" ]; then
261
- printf '%s' "$next" > .gtd/NEXT.md
262
- else
263
- rm -f .gtd/NEXT.md
264
- fi
265
- on:
266
- "D .gtd/NEXT.md": reviewing
267
- "* .gtd/NEXT.md": building
268
- "C": reviewing
269
-
270
- building:
271
- actor: agent
272
- model: <%= it.vars.coderModel %>
273
- prompt: |
274
- You are an autonomous coding agent. `.gtd/` holds this workflow's own
275
- state — never create or edit anything under `.gtd/` except deleting the
276
- one task file this prompt tells you to delete; never touch
277
- `.gtd/NEXT.md` yourself — the `picking` state owns it.
278
-
279
- The task file to implement is: <%~ it.read(".gtd/NEXT.md") %>
280
-
281
- Read that file and implement EXACTLY the one task it describes — no
282
- more, no less; leave every other task file under `.gtd/tasks/`
283
- untouched. Use TDD discipline: one test, then the implementation that
284
- passes it, then the next — never write all the tests first.
285
-
286
- Delete the task file once its work is complete and verified. Leave
287
- everything else uncommitted and finish your turn.
288
- on:
289
- "* **": checking
290
-
291
- checking:
292
- actor: check
293
- script: |
294
- #!/usr/bin/env bash
295
- # gtd check turn — the loop driver executes this verbatim, then
296
- # steps the check actor. Mechanics only: run the test suite and record a
297
- # red run's output as .gtd/FEEDBACK.md. What that output MEANS (another
298
- # fix round vs escalation) is decided by the workflow's own `on`/`retry`
299
- # rules at capture time — never here.
300
- #
301
- # `it.vars.testCommand` defaults to "npm test" (this workflow's own
302
- # `vars:` above) — override it with a top-level `.gtdrc`
303
- # `vars: { testCommand: ... }` key, or a `GTD_VAR_testCommand`
304
- # environment variable (highest precedence).
305
- set +e
306
- mkdir -p .gtd
307
- <%~ it.vars.testCommand %> > .gtd/.check-output 2>&1
308
- code=$?
309
- if [ "$code" -ne 0 ]; then
310
- if [ -s .gtd/.check-output ]; then
311
- mv .gtd/.check-output .gtd/FEEDBACK.md
312
- else
313
- rm -f .gtd/.check-output
314
- printf 'npm test failed with exit code %s and produced no output.' "$code" > .gtd/FEEDBACK.md
315
- fi
316
- else
317
- rm -f .gtd/.check-output
318
- fi
319
- on:
320
- "A .gtd/FEEDBACK.md": fixing
321
- "M .gtd/FEEDBACK.md": fixing
322
- "C": picking
323
-
324
- fixing:
325
- actor: agent
326
- file: <%= it.vars.feedbackFile %>
327
- model: <%= it.vars.coderModel %>
328
- retry:
329
- max: 3
330
- otherwise: escalate
331
- prompt: |
332
- You are an autonomous coding agent. `.gtd/` holds this workflow's own
333
- state — never create, edit, or delete anything under `.gtd/` except
334
- `<%= it.vars.feedbackFile %>`, which this prompt tells you to address.
335
-
336
- Read `<%= it.vars.feedbackFile %>` (the failing test output) and fix
337
- the code so the suite passes. Keep the change focused — do not
338
- refactor unrelated code. If the feedback is wrong, empty or delete
339
- `<%= it.vars.feedbackFile %>` instead of "fixing" a non-issue; the
340
- machine picks the dispute up either way.
341
-
342
- Leave everything uncommitted and finish your turn — do not commit.
343
- on:
344
- "* **": checking
345
-
346
- escalate:
347
- actor: human
348
- file: <%= it.vars.feedbackFile %>
349
- message: |
350
- The agent could not get the check to pass after repeated attempts.
351
- `<%= it.vars.feedbackFile %>` holds the last failing output.
352
-
353
- Investigate and fix it yourself (editing code and/or
354
- `<%= it.vars.feedbackFile %>`), then run `gtd step human` to try the
355
- check again.
356
- on:
357
- "* **": checking
358
-
359
- reviewing:
360
- actor: agent
361
- file: <%= it.vars.reviewFile %>
362
- mode: review
363
- model: <%= it.vars.plannerModel %>
364
- # A second way in: `gtd review <commitish>` (clean tree, resting at the
365
- # initial state) enters here directly over <commitish>..HEAD — see
366
- # STATES.md §11.
367
- reviewEntry: true
368
- prompt: |
369
- You are an autonomous coding agent. `.gtd/` holds this workflow's own
370
- state — never create, edit, or delete anything under `.gtd/` except
371
- `<%= it.vars.reviewFile %>`, which this prompt tells you to write.
372
-
373
- Write `<%= it.vars.reviewFile %>` to help a human review the cycle's
374
- full diff (inlined below): group hunks semantically (same
375
- feature/refactor/fix, even across files), and for each group write a
376
- short heading, an explanation of what changed and why, and
377
- `- [ ] ./path/to/file.ts#42` style file pointers (checkboxes are for
378
- the human to tick, not you).
379
-
380
- Leave `<%= it.vars.reviewFile %>` uncommitted and finish your turn.
381
- <% if (it.processDiff.trim()) { %>
382
-
383
- ## Full cycle diff
384
-
385
- ```diff
386
- <%~ it.processDiff %>
387
- ```
388
- <% } %>
389
- on:
390
- "* .gtd/REVIEW.md": await-review
391
-
392
- await-review:
393
- actor: human
394
- file: <%= it.vars.reviewFile %>
395
- mode: review
396
- # Opens the review checkout window: HEAD/index are rewound to the cycle
397
- # start so the whole diff shows as uncommitted changes in the editor
398
- # (see STATES.md §11). Closes automatically once the cycle rests elsewhere.
399
- reviewWindow: true
400
- message: |
401
- `<%= it.vars.reviewFile %>` holds the review record for the completed
402
- cycle.
403
-
404
- To approve: delete `<%= it.vars.reviewFile %>` and run
405
- `gtd step human`.
406
-
407
- To request changes: edit `<%= it.vars.reviewFile %>` (or the code)
408
- with what's wrong — including just ticking its checkboxes — then run
409
- `gtd step human`; this sends the cycle back through grilling with your
410
- feedback as the new input.
411
- on:
412
- "D .gtd/REVIEW.md": squashing
413
- "* **": grilling
414
-
415
- squashing:
416
- actor: agent
417
- model: <%= it.vars.coderModel %>
418
- prompt: |
419
- You are an autonomous coding agent. The cycle is approved and done.
420
- `.gtd/` holds this workflow's own state — never create, edit, or delete
421
- anything under `.gtd/` except `.gtd/COMMIT_MSG.md`, which this prompt
422
- tells you to write.
423
-
424
- Write `.gtd/COMMIT_MSG.md` with ONE conventional-commits message for
425
- the entire cycle (subject line `type(scope): subject`, imperative mood,
426
- <= 72 characters; a body explaining the why, trade-offs, and key
427
- decisions). Plain text, no markdown wrapper.
428
-
429
- Leave `.gtd/COMMIT_MSG.md` uncommitted and finish your turn — entering
430
- this file squashes the whole cycle into one commit using its content as
431
- the message.
432
- <% if (it.processDiff.trim()) { %>
433
-
434
- ## Full cycle diff
435
-
436
- ```diff
437
- <%~ it.processDiff %>
438
- ```
439
- <% } %>
440
- on:
441
- "A .gtd/COMMIT_MSG.md": done
442
- "M .gtd/COMMIT_MSG.md": done
443
-
444
- done:
445
- commit: |
446
- <%~ it.read(".gtd/COMMIT_MSG.md") %>
447
-
448
- Token cost: <%= it.processCost %>
449
- <% it.processCostByModel.forEach(function(m){ %>
450
- - <%= m.model %>: <%= m.cost %>
451
- <% }) %>
452
- ````
453
-
454
- The `done` commit appends a token-cost summary to the squashed message: if the
455
- loop driving this workflow passes `gtd step <actor> --cost=<n> --model=<name>`
456
- after each agent turn, `it.processCost` is the summed cost of the whole cycle
457
- (including the `squashing` step itself) and `it.processCostByModel` itemizes it
458
- per model — so the single squash commit records the feature's complete cost,
459
- broken down by which model spent what, even though the per-turn trailers are
460
- discarded with the turns they collapsed. Drop these lines if your driver doesn't
461
- track cost — `it.processCost` is `0` and `it.processCostByModel` empty then. See
462
- [Configuration: Token cost](../configuration.md#token-cost).
463
-
464
- A clean `gtd step human` at `grilling-answer`/`architecting-answer` (the `C`
465
- event) accepts the current phase's draft and moves on; any other pending change
466
- loops back for another round. `picking` is a `script` state whose only job is to
467
- inspect `.gtd/tasks/` (a tree property patterns can't see directly) and turn it
468
- into a diff patterns CAN see — see the walkthrough in
469
- [STATES.md §10](../../STATES.md#10-the-bundled-workflow-templates) (the version
470
- of that section frozen alongside this example) for the full state-by-state
471
- narrative, including the `on`-declaration-order subtlety at `picking` and the
472
- `fixing` retry-cap pooling caveat.
473
-
474
- ## See also
475
-
476
- - [docs/design/work-packages.md](../design/work-packages.md) — the arbiter's
477
- decision record: why the scripted `picking` state (Option A) was chosen over
478
- the agent-encoded-verdict, tree-predicate-guard, and template-enumeration
479
- alternatives, plus the process-per-task topology variant.
480
- - [STATES.md](../../STATES.md) — the pattern-machine model this recipe compiles
481
- against (pattern grammar, resolution, retry, the squash lifecycle).