@pmelab/gtd 9.6.0 → 9.7.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 +410 -231
- package/dist/gtd.bundle.mjs +2137 -1633
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -85,16 +85,17 @@ gtd is a small **pattern machine**: named states, each awaiting one actor and
|
|
|
85
85
|
carrying one piece of content (a script, a prompt, a message, or a squash commit
|
|
86
86
|
template), with an ordered set of change-patterns routing to the next state.
|
|
87
87
|
|
|
88
|
-
The loop is one beat, repeated: run `gtd
|
|
88
|
+
The loop is one beat, repeated: run `gtd status --json` and dispatch on `kind` —
|
|
89
89
|
`"message"` means it's a human's move (stop and hand off, unless it's the run's
|
|
90
90
|
opening beat, which the human triggered by re-running the driver: land that one,
|
|
91
91
|
since changing nothing is itself a declared outcome at some gates); `"capture"`
|
|
92
92
|
means a human gate the human already acted on (land it immediately); `"script"`
|
|
93
|
-
means the driver runs `
|
|
94
|
-
`
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
93
|
+
means the driver runs `gtd next`'s own plain-text output itself, then lands it;
|
|
94
|
+
`"prompt"` means feed `gtd next`'s output to your agent — using the accompanying
|
|
95
|
+
`session.id`/`session.resume` fields off `gtd status --json` to continue or
|
|
96
|
+
start that agent conversation (see "Driving the loop" below) — then run
|
|
97
|
+
`gtd land` once it's done. gtd itself never executes anything — the driver owns
|
|
98
|
+
running scripts. Every `gtd next`/ `gtd status` call is strictly mutation-free,
|
|
98
99
|
safe to poll or peek at any time: `session.id`/`session.resume` are DERIVED,
|
|
99
100
|
never stored, so looking is free — nothing distinguishes a peek from a dispatch,
|
|
100
101
|
and there is no separate claiming form at all. A `prompt` beat whose turn
|
|
@@ -102,7 +103,7 @@ changes nothing still lands: `gtd land` commits an EMPTY `gtd(<actor>): <state>`
|
|
|
102
103
|
attempt instead of silently doing nothing, so the fruitless dispatch is visible
|
|
103
104
|
in history rather than invisible. `"kind": "stalled"` is derived from that
|
|
104
105
|
history — HEAD is an empty attempt at the resting state and the tree is clean —
|
|
105
|
-
so every `gtd
|
|
106
|
+
so every `gtd status --json` call reports it, and it stays reported on a repeat
|
|
106
107
|
(there's no marker to consume) until something actually changes. The fix for a
|
|
107
108
|
repeated stall is either a better prompt, a `retry:` cap on the state that
|
|
108
109
|
redirects to an escalation state after N fruitless attempts, or — if the state
|
|
@@ -301,18 +302,19 @@ Commands:
|
|
|
301
302
|
Takes no argument. Run once per repo; refuses if a gtd
|
|
302
303
|
config already exists. Leaves the file uncommitted for you
|
|
303
304
|
to review and commit
|
|
304
|
-
land Land whatever the tree now shows at the currently
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
305
|
+
land Land whatever the tree now shows at the currently resolved
|
|
306
|
+
rest — a human capture, an agent/check turn, an empty
|
|
307
|
+
attempt (a fruitless prompt turn), or a squash. Pass
|
|
308
|
+
--cost=<n> (optionally --model=<name>) to record the
|
|
309
|
+
just-finished invocation's token cost and model on the
|
|
310
|
+
turn commit (summed into it.processCost/
|
|
311
|
+
processCostByModel). Plain (the default) prints ONLY the
|
|
312
|
+
script that records the landing; a driver runs it, e.g.
|
|
313
|
+
`gtd land | sh`. --json/--sh instead emit script (that
|
|
314
|
+
same script, byte-identical) alongside settled, idle,
|
|
315
|
+
state (the post-land target), subject, cost and model —
|
|
316
|
+
--json/--sh are mutually exclusive. Exits 0 on success, 1
|
|
317
|
+
on any refusal — see the Exit codes section below
|
|
316
318
|
(no command) --entry <state>
|
|
317
319
|
Starts a new process authenticated as human, e.g.
|
|
318
320
|
'gtd --entry <state>'
|
|
@@ -327,29 +329,35 @@ Commands:
|
|
|
327
329
|
Refuses on a dirty working tree, when there is no retained
|
|
328
330
|
history, or when HEAD has advanced past the squash with
|
|
329
331
|
commits that would be lost
|
|
330
|
-
next Print the resolved rest's
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
332
|
+
next Print the resolved rest's beat (no mutation, safe to
|
|
333
|
+
poll), in one of three encodings. Plain (the default): a
|
|
334
|
+
status summary, a blank line, then the step verbatim —
|
|
335
|
+
except at a prompt rest, which is the bare step (plus the
|
|
336
|
+
self-validation instruction when applicable) with no
|
|
337
|
+
header, since those bytes are the agent's own input. --json
|
|
338
|
+
emits the one structured surface gtd has: kind
|
|
339
|
+
(capture|message|script|prompt|stalled) selects what a
|
|
340
|
+
driver does, content is what it runs or shows, idle marks
|
|
341
|
+
the workflow's initial state with a clean tree, plus the
|
|
342
|
+
prompt session, model, validate script, log path, changes,
|
|
343
|
+
next and the resting state's own fields. --sh emits the
|
|
344
|
+
same fields as gtd_-prefixed POSIX shell assignments.
|
|
345
|
+
--json/--sh are mutually exclusive. Exits 0 — see the
|
|
346
|
+
Exit codes section below
|
|
338
347
|
validate Print the script that formats (when declared) then
|
|
339
348
|
validates the resolved rest's steering file, using its
|
|
340
349
|
mode's commands (its file:/mode:), instead of running it —
|
|
341
350
|
a driver runs the script and reads the findings from its
|
|
342
|
-
own exit code/output. Always exits 0;
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
(instruction + findings) and exits with the
|
|
348
|
-
validator's own code
|
|
351
|
+
own exit code/output. Always exits 0; prints "nothing to
|
|
352
|
+
validate" when the resolved rest declares nothing to run.
|
|
353
|
+
On a non-zero validate exit the emitted script prints a
|
|
354
|
+
ready-to-send fix prompt (instruction + findings) and
|
|
355
|
+
exits with the validator's own code
|
|
349
356
|
lsp Start the LSP server for .gtd/ steering files (stdio)
|
|
350
357
|
visualize Serve an interactive diagram of the active workflow on a
|
|
351
|
-
local web server (--port <n>, --no-open
|
|
352
|
-
|
|
358
|
+
local web server (--port <n>, --no-open). Prints the
|
|
359
|
+
chosen port on its own line — with --port 0, this is the
|
|
360
|
+
only way to learn which port was picked
|
|
353
361
|
check <mode> <file>
|
|
354
362
|
Read <file> and run the built-in steering format named
|
|
355
363
|
<mode> (see `gtd validate`'s modes: qa, review) over its
|
|
@@ -370,7 +378,11 @@ Commands:
|
|
|
370
378
|
help Print this help and exit
|
|
371
379
|
|
|
372
380
|
Options:
|
|
373
|
-
--json
|
|
381
|
+
--json (gtd next/gtd land only) output structured JSON
|
|
382
|
+
instead of plain text. Mutually exclusive with --sh
|
|
383
|
+
--sh (gtd next/gtd land only) output gtd_-prefixed POSIX
|
|
384
|
+
shell assignments instead of plain text. Mutually
|
|
385
|
+
exclusive with --json
|
|
374
386
|
--port=<n> (gtd visualize only) port to serve on (default: a free port)
|
|
375
387
|
--no-open (gtd visualize only) do not open the browser
|
|
376
388
|
--cost=<n> (gtd land only) record the invocation's token cost
|
|
@@ -386,23 +398,73 @@ Options:
|
|
|
386
398
|
instead run the qa open-questions predicate over <file>,
|
|
387
399
|
printing each unanswered question one per line and exiting
|
|
388
400
|
non-zero when any remain
|
|
389
|
-
--
|
|
401
|
+
--verbose enable stderr narration for this invocation: which rest
|
|
402
|
+
resolved, which declared pattern each pending change
|
|
403
|
+
matched, which review-window action was emitted, and how
|
|
404
|
+
config resolved across layers. Aliased to -v
|
|
405
|
+
--version, -V Print version and exit
|
|
390
406
|
--help, -h Print this help and exit
|
|
391
407
|
```
|
|
392
408
|
|
|
393
|
-
|
|
409
|
+
### Plain output is not a parsing surface
|
|
410
|
+
|
|
411
|
+
`gtd next`'s plain encoding (and `gtd status`'s own) is for a human, or a driver
|
|
412
|
+
that merely displays it — never for scraping. Parsing lives in `--json`/`--sh`,
|
|
413
|
+
both of which read from the exact same field set (`gtd install`'s briefing has
|
|
414
|
+
the full reference); anything that greps, cuts, or `awk`s plain text is
|
|
415
|
+
unsupported, and its shape may change across releases with no warning.
|
|
416
|
+
|
|
417
|
+
### Exit codes
|
|
418
|
+
|
|
419
|
+
Closed at five numbers, five meanings — a new command never grows this table;
|
|
420
|
+
whose turn is next lives in `gtd next --json`'s own `kind` field instead.
|
|
421
|
+
|
|
422
|
+
| Code | Meaning |
|
|
423
|
+
| --------- | ---------------- |
|
|
424
|
+
| 0 | success |
|
|
425
|
+
| 1 | runtime error |
|
|
426
|
+
| 2 | usage error |
|
|
427
|
+
| 130 / 143 | SIGINT / SIGTERM |
|
|
428
|
+
|
|
429
|
+
Every command follows this table uniformly, `next`/`land` included: `0` on
|
|
430
|
+
success, `1` on refusal, `2` on usage error, `130`/`143` when gtd itself dies by
|
|
431
|
+
that signal — a parent's `wait` sees a real signal death (`WIFSIGNALED`), not a
|
|
432
|
+
chosen exit code that merely reuses the same number. No command's exit code
|
|
433
|
+
carries a second meaning.
|
|
434
|
+
|
|
435
|
+
**Migration — read this even if you already migrated for a prior release.** This
|
|
436
|
+
is the second inversion in as many releases, folded into one note rather than
|
|
437
|
+
two to compose in your head: `10`/`20` (whose turn was next) are gone — every
|
|
438
|
+
command exits `0`/`1`/`2` uniformly now; `gtd status` is gone (folded into
|
|
439
|
+
`gtd next`); and plain `gtd next` now prints a status header at every kind
|
|
440
|
+
EXCEPT `prompt` — agent input is untouched, since plain `gtd next` at a `prompt`
|
|
441
|
+
rest is byte-identical to before. A driver must read whose turn is next off
|
|
442
|
+
`gtd next --json`'s own `kind` field
|
|
443
|
+
(`capture`/`message`/`script`/`prompt`/`stalled`) — never off gtd's exit code,
|
|
444
|
+
which no longer carries that signal at all.
|
|
445
|
+
|
|
446
|
+
Every usage mistake — an unknown option or command, missing/extra arguments, a
|
|
447
|
+
scope violation (e.g. `--cost` on a command other than `gtd land`), a bad flag
|
|
448
|
+
value — is a USAGE error (`2`), never a runtime error (`1`): nothing was even
|
|
449
|
+
attempted. `--help`/`--version` still exit `0`.
|
|
450
|
+
|
|
451
|
+
`--version` (`-V`) / `gtd version` and `--help` (`-h`) / `gtd help`
|
|
394
452
|
short-circuit before any git or repository-state work — they run outside a repo
|
|
395
|
-
and in any repo state
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
`
|
|
405
|
-
|
|
453
|
+
and in any repo state, and print to **stdout** at exit 0. `--verbose` (`-v`) is
|
|
454
|
+
not a short-circuit — it gates narration for whatever command follows (see
|
|
455
|
+
[Narration and remediation](#narration-and-remediation) below). Bare `gtd` (no
|
|
456
|
+
subcommand) is a usage error that exits 2 — gtd decides and prints, full stop;
|
|
457
|
+
driving a loop is a driver's job, not a bundled command (see
|
|
458
|
+
[Driving the loop](#driving-the-loop) below) — printing its help text to
|
|
459
|
+
**stderr**, not stdout: stdout stays byte-empty on every failure, a usage error
|
|
460
|
+
included (see [Error envelope](#error-envelope) below). Any other, truly unknown
|
|
461
|
+
subcommand is likewise a usage error exiting 2 without touching the repository.
|
|
462
|
+
The state commands (`land`, `--entry`, `abandon`, `restore`, `next`, `status`,
|
|
463
|
+
`validate`) must run from the **repository root** — gtd derives the workflow,
|
|
464
|
+
pending changes, and process history relative to cwd, so they refuse with a
|
|
465
|
+
clear error from a subdirectory; `lsp`, `init`, `visualize`, `check`, and
|
|
466
|
+
`install` are standalone and run from anywhere (see each command's own help
|
|
467
|
+
entry).
|
|
406
468
|
|
|
407
469
|
`--json`, `--cost=<n>`, `--model=<name>` (the latter two only for `gtd land`),
|
|
408
470
|
`--entry <state>` (no other command at all), and `--var <name>=<value>` (with
|
|
@@ -435,23 +497,68 @@ real `gtd land` lands.
|
|
|
435
497
|
|
|
436
498
|
### Error envelope
|
|
437
499
|
|
|
438
|
-
|
|
439
|
-
|
|
500
|
+
**stdout is either the complete artifact or byte-empty — never a partial write
|
|
501
|
+
followed by an error.** Every command buffers everything it would print and
|
|
502
|
+
flushes that buffer to stdout exactly once, only after it succeeds; on any
|
|
503
|
+
failure the buffer is simply discarded, so stdout never carries a half-written
|
|
504
|
+
prompt/script alongside a message about why it stopped. `gtd visualize` is the
|
|
505
|
+
one exception worth knowing: it flushes its served-URL line immediately, before
|
|
506
|
+
blocking on `Ctrl-C`, since a flush-on-success would never otherwise fire.
|
|
507
|
+
|
|
508
|
+
Any invocation that carries `--json` (valid only for `gtd status` — every other
|
|
509
|
+
command usage-errors on it) reports a failure as a machine-readable envelope on
|
|
510
|
+
**stderr** — including the scope violation itself, so a driver that always adds
|
|
511
|
+
`--json` still gets a parseable envelope on every failure, not only
|
|
512
|
+
`gtd status`'s own:
|
|
440
513
|
|
|
441
514
|
```json
|
|
442
515
|
{ "state": "error", "prompt": "<message>" }
|
|
443
516
|
```
|
|
444
517
|
|
|
445
|
-
This covers every failure mode, not just a command's own refusal: a
|
|
446
|
-
error** (an unknown flag, a missing argument, `gtd --entry version`'s
|
|
447
|
-
enterable state") and a **defect** (a layer throwing outside
|
|
448
|
-
channel) both get the same envelope — there is
|
|
449
|
-
`--json` without one
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
518
|
+
This covers every failure mode, not just a command's own refusal (exit 1): a
|
|
519
|
+
**usage error** (an unknown flag, a missing argument, `gtd --entry version`'s
|
|
520
|
+
"not an enterable state" — exit 2) and a **defect** (a layer throwing outside
|
|
521
|
+
the ordinary error channel — exit 1) both get the same envelope shape — there is
|
|
522
|
+
no failure path that reaches `--json` without one — but a usage error's exit
|
|
523
|
+
code is 2, never 1, so a driver can tell "you invoked gtd wrong" apart from "gtd
|
|
524
|
+
refused/broke" (see [Exit codes](#exit-codes)).
|
|
525
|
+
|
|
526
|
+
A human-readable `gtd: <message>` line is also always written to **stderr**,
|
|
527
|
+
right after the envelope — stdout carries neither one on a failing run. Stderr
|
|
528
|
+
always carries exactly one `gtd: ` prefix: a message already authored with its
|
|
529
|
+
own `gtd:`/`gtd <cmd>:` prefix is never doubled.
|
|
530
|
+
|
|
531
|
+
**Accepted cost:** a driver that pipes stdout into `jq` on a failed run now
|
|
532
|
+
reads nothing instead of a parseable error object — it must read stderr or the
|
|
533
|
+
exit code to learn why a run failed.
|
|
534
|
+
|
|
535
|
+
### Narration and remediation
|
|
536
|
+
|
|
537
|
+
Stderr carries two things beyond the `gtd: ` message line above: NARRATION,
|
|
538
|
+
gated by `--verbose`/`-v`, and REMEDIATION, unconditional.
|
|
539
|
+
|
|
540
|
+
`--verbose` (alias `-v`) turns on one line of commentary per in-process fact a
|
|
541
|
+
command's dispatch already computes — which rest resolved, which declared
|
|
542
|
+
pattern each pending change matched, which review-window action was emitted, and
|
|
543
|
+
how config resolved across `.gtdrc` layers. Without it, none of this is printed;
|
|
544
|
+
stdout is never touched either way — narration is a stderr-only concern, exactly
|
|
545
|
+
like the error envelope above.
|
|
546
|
+
|
|
547
|
+
A failure's remediation detail is unconditional — it prints at every verbosity,
|
|
548
|
+
on the line(s) right after the `gtd: `-prefixed message, each indented two
|
|
549
|
+
spaces: a bad config key names the offending key and which `.gtdrc` layer it
|
|
550
|
+
came from, a corrupted ref names the ref, and a missing binary in a steering
|
|
551
|
+
mode's `format:`/`validate:` command names the resolved `$PATH` it was looked up
|
|
552
|
+
in.
|
|
553
|
+
|
|
554
|
+
### Non-interactive today
|
|
555
|
+
|
|
556
|
+
gtd is non-interactive: no readline, no `/dev/tty`, no prompt call anywhere in
|
|
557
|
+
`src/`. If interaction is ever added, it goes to `/dev/tty`, never stderr, and
|
|
558
|
+
never blocks — a question fails with a code when the tty cannot be opened rather
|
|
559
|
+
than hanging. The reason is the section above: stderr already has two occupants,
|
|
560
|
+
narration and remediation, and a question mixed into that stream would deadlock
|
|
561
|
+
a driver that never reads stderr.
|
|
455
562
|
|
|
456
563
|
## Driving the loop
|
|
457
564
|
|
|
@@ -485,24 +592,24 @@ not of the loop itself; see
|
|
|
485
592
|
below for a worked example.
|
|
486
593
|
|
|
487
594
|
A workflow state can declare an optional `label:` — a human-readable display
|
|
488
|
-
name surfaced in `gtd
|
|
489
|
-
per-beat progress lines; an outer wrapper (a terminal multiplexer, a
|
|
490
|
-
can use it the same way.
|
|
595
|
+
name surfaced in `gtd status --json`/plain `gtd status`. The driver uses it for
|
|
596
|
+
its per-beat progress lines; an outer wrapper (a terminal multiplexer, a
|
|
597
|
+
notifier) can use it the same way.
|
|
491
598
|
|
|
492
599
|
Memory is **entry-scoped to a machine**, not a state-authored label: each
|
|
493
600
|
machine instance (a node in the `machines:` tree, e.g. `build`, `build.health`,
|
|
494
601
|
`packages.item`, `packages.item.health`) owns its own conversational scope, and
|
|
495
|
-
a `prompt`-content state's `memory` key — surfaced in `gtd
|
|
496
|
-
`
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
602
|
+
a `prompt`-content state's `memory` key — surfaced in `gtd status --json`'s
|
|
603
|
+
`memory` field, and as a `Memory: <key>` line in plain `gtd status` — is
|
|
604
|
+
computed, never authored, as `<scope>#<hash7>`: `<scope>` is that machine
|
|
605
|
+
instance's dotted path (the root instance is shown as `root`), and `<hash7>`
|
|
606
|
+
anchors to the commit the CURRENT unbroken entry into that scope started FROM.
|
|
607
|
+
Entering a **descendant** scope (e.g. dipping from `build` into `build.health`)
|
|
608
|
+
does not break the parent's unbroken run — a full agent turn in a nested child
|
|
609
|
+
machine, then back to the parent, still resumes the SAME parent conversation;
|
|
610
|
+
entering a **sibling or unrelated** scope does start a fresh one. The bundled
|
|
611
|
+
template's `build.review` (the human review tail) is a worked example: it is
|
|
612
|
+
nested INSIDE `build` (the builder's own machine) so that a
|
|
506
613
|
`gtd --entry fix-precheck` run — `build.fix` -> `build.health.check` ->
|
|
507
614
|
`build.review.*` -> `build.squashing` — stays inside one subtree, letting
|
|
508
615
|
`build.squashing` resume the SAME session that made the fixes instead of a
|
|
@@ -523,8 +630,8 @@ scopes.
|
|
|
523
630
|
computed `<scope>#<hash7>` key above — so the same scope-run always re-derives
|
|
524
631
|
the exact same id, and there is no table, no file, no write to keep in sync.
|
|
525
632
|
`session.resume` is `true` iff a prior `prompt` turn already landed within that
|
|
526
|
-
same scope-run. Because nothing is written, calling `gtd
|
|
527
|
-
row — a driver's own opening peek, a status poll, a curious human — derives
|
|
633
|
+
same scope-run. Because nothing is written, calling `gtd status --json` twice in
|
|
634
|
+
a row — a driver's own opening peek, a status poll, a curious human — derives
|
|
528
635
|
IDENTICAL `session.id`/`session.resume` values both times, since there is
|
|
529
636
|
nothing to poison: looking is free, and there is no separate claiming form to
|
|
530
637
|
protect. The per-scope survival story (a child machine's own excursion doesn't
|
|
@@ -550,7 +657,7 @@ reports `gtd`'s own lifecycle to that status without any herdr-specific
|
|
|
550
657
|
knowledge in `gtd` itself: `working` while the loop drives, `blocked` when it
|
|
551
658
|
comes to rest on a human (a gate, a stall, a non-zero exit), and `idle`
|
|
552
659
|
(rendered as "done" once the pane's tab is unfocused) when a run ends without
|
|
553
|
-
anything owed. It needs nothing from `gtd` beyond `gtd
|
|
660
|
+
anything owed. It needs nothing from `gtd` beyond `gtd next --sh`'s `gtd_actor`
|
|
554
661
|
field — a strictly read-only orientation peek.
|
|
555
662
|
|
|
556
663
|
Save this as `~/.local/bin/gtdh`, `chmod +x` it, and run `gtdh` in place of
|
|
@@ -560,8 +667,8 @@ Save this as `~/.local/bin/gtdh`, `chmod +x` it, and run `gtdh` in place of
|
|
|
560
667
|
#!/usr/bin/env bash
|
|
561
668
|
# Report gtd's own lifecycle to the herdr pane it runs in: working while the
|
|
562
669
|
# loop drives, blocked when it rests on you, idle (shown as "done") otherwise.
|
|
563
|
-
# Needs nothing from gtd but `gtd
|
|
564
|
-
# passthrough.
|
|
670
|
+
# Needs nothing from gtd but `gtd next --sh`. Outside herdr it is a plain
|
|
671
|
+
# passthrough.
|
|
565
672
|
set -uo pipefail
|
|
566
673
|
|
|
567
674
|
pane="${HERDR_PANE_ID:-}"
|
|
@@ -586,14 +693,16 @@ trap 'report blocked; exit 130' INT TERM
|
|
|
586
693
|
env -u HERDR_PANE_ID gtd-loop
|
|
587
694
|
rc=$?
|
|
588
695
|
|
|
589
|
-
# Whose turn is it now? `gtd
|
|
590
|
-
#
|
|
591
|
-
#
|
|
592
|
-
#
|
|
593
|
-
#
|
|
594
|
-
|
|
696
|
+
# Whose turn is it now? `gtd next --sh` is a strictly read-only peek — every
|
|
697
|
+
# gtd command is, including `gtd next` (its prompt session id is derived,
|
|
698
|
+
# never minted/stored) — only the emitted scripts a driver runs actually
|
|
699
|
+
# touch git. A human actor means gtd is waiting on you; anything else means
|
|
700
|
+
# the run ended with nothing owed. Assign first, THEN eval — same reason as
|
|
701
|
+
# the driver above.
|
|
702
|
+
out="$(gtd next --sh 2>/dev/null)" || out=""
|
|
703
|
+
eval "${out:-}" 2>/dev/null || true
|
|
595
704
|
|
|
596
|
-
if [ "$rc" -ne 0 ] || [ -z "$
|
|
705
|
+
if [ "$rc" -ne 0 ] || [ -z "${gtd_actor:-}" ] || [ "$gtd_actor" = human ]; then
|
|
597
706
|
report blocked
|
|
598
707
|
else
|
|
599
708
|
report idle
|
|
@@ -632,7 +741,7 @@ to build a driver without leaving your terminal. The briefing ends by directing
|
|
|
632
741
|
the agent to INTERVIEW you first — which agent CLI runs the turns, under what
|
|
633
742
|
permission model, how you want to invoke the loop, what should happen at a human
|
|
634
743
|
gate — and to build the driver your answers describe rather than copying the
|
|
635
|
-
reference
|
|
744
|
+
reference sh. It writes nothing: "install" means installing knowledge into the
|
|
636
745
|
calling agent's context, and the briefing it prints is always exactly as current
|
|
637
746
|
as the `gtd` that printed it.
|
|
638
747
|
|
|
@@ -641,88 +750,109 @@ privileged one — the engine itself is a supported public surface, and anything
|
|
|
641
750
|
below holds for any driver you write against it. gtd decides and prints; it
|
|
642
751
|
never touches git itself. The four commands that change anything — `gtd land`,
|
|
643
752
|
`gtd --entry <state>`, `gtd abandon`, and `gtd restore` — perform no git write
|
|
644
|
-
when run
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
753
|
+
when run: each one prints ONE POSIX sh script for YOU to execute
|
|
754
|
+
(`src/Emit.ts`'s `combinedScript`) — a leading comment ("gtd emitted this and
|
|
755
|
+
did NOT run it — pipe it into `sh` to land the turn"), then the REQUIRED half
|
|
756
|
+
verbatim, then, only when there's a presentation-only follow-up, a second
|
|
757
|
+
comment ("presentation only — safe to skip") and the OPTIONAL half wrapped in a
|
|
758
|
+
subshell whose own non-zero exit is swallowed (reported to stderr as a warning,
|
|
759
|
+
never turning a landed turn into a failing one). Printing gtd's output and never
|
|
760
|
+
running it is not driving anything; a driver must pipe or execute what gtd
|
|
761
|
+
prints — e.g. the capture-then-pipe form the reference driver below uses — never
|
|
762
|
+
a bare `gtd land | sh`, which would hand an empty script to a shell on a refusal
|
|
763
|
+
instead of stopping first (see the reference driver's own use of `gtd land --sh`
|
|
764
|
+
below).
|
|
765
|
+
|
|
766
|
+
Every script gtd emits — `gtd land`, `gtd --entry <state>`, `gtd abandon`,
|
|
767
|
+
`gtd restore`, and the format/validate script `gtd validate` prints — is POSIX
|
|
768
|
+
`sh`, portable to `dash`: a driver may run any of them with any POSIX-compliant
|
|
769
|
+
shell, not specifically bash. The same convention extends to the workflow's own
|
|
770
|
+
`vars.testCommand` (what a `script`-content check state actually executes): it
|
|
771
|
+
is expected to be POSIX sh-compatible too, but this is a DOCUMENTED CONVENTION
|
|
772
|
+
only — gtd never inspects or validates `testCommand`'s shell dialect itself, it
|
|
773
|
+
only renders the value into a script and hands it to whatever shell the driver
|
|
774
|
+
invokes that script with.
|
|
775
|
+
|
|
776
|
+
- **The required half** is everything that decides what lands in git — closing
|
|
777
|
+
an open review checkout window, the resting state's own steering-mode
|
|
657
778
|
`format:`/`validate:` commands, the commit or squash itself (`gtd land` and
|
|
658
779
|
`gtd --entry <state>`), or the ref update and reset that undo a process
|
|
659
780
|
(`gtd abandon`, `gtd restore`) — and, last, a printed line naming what just
|
|
660
781
|
landed (`src/OutcomeScript.ts`'s `gtd_report_*` calls): a transition or
|
|
661
782
|
capture's changed-file rows, or the abandon/restore prose, resolved from the
|
|
662
|
-
repository AFTER the write above it.
|
|
663
|
-
never lands, and you never see what it
|
|
664
|
-
|
|
665
|
-
|
|
783
|
+
repository AFTER the write above it. Its own exit code IS the printed script's
|
|
784
|
+
exit code — skipping it means the turn never lands, and you never see what it
|
|
785
|
+
did.
|
|
786
|
+
- **The optional half** is presentation only: re-opening the review checkout
|
|
787
|
+
window (the `<<<<<<< HEAD` diff view) after `gtd land` lands at a
|
|
666
788
|
`reviewWindow: true` state, so an editor's diff view has something to show.
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
789
|
+
Its own failure is swallowed by the wrapping subshell (a warning on stderr,
|
|
790
|
+
nothing more) — skip it (or let it fail) and you lose nothing but that view,
|
|
791
|
+
the workflow is still driven correctly. `gtd abandon`/`gtd restore` never
|
|
792
|
+
carry one — there is no window to reopen after either, so their printed
|
|
793
|
+
artifact is the required half alone, with no trailing comment/subshell at all.
|
|
670
794
|
|
|
671
|
-
`gtd
|
|
795
|
+
`gtd status --json` carries one more field worth a custom driver's attention:
|
|
672
796
|
|
|
673
797
|
- **`log`** — the per-worktree loop log path, always present. It's derived from
|
|
674
798
|
the worktree's own git dir, so two worktrees looping concurrently never share
|
|
675
|
-
one file; set `$GTD_LOOP_LOG` to override it verbatim
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
799
|
+
one file; set `$GTD_LOOP_LOG` to override it verbatim, or `$GIT_DIR` to name
|
|
800
|
+
the git dir directly (both honored the same way every git subprocess already
|
|
801
|
+
honors them — an inherited `$GIT_DIR` moves the log path along with it). gtd
|
|
802
|
+
itself neither creates nor truncates this file — a driver appends subprocess
|
|
803
|
+
output to it and truncates once at the start of a run, exactly like the driver
|
|
804
|
+
above does.
|
|
805
|
+
|
|
806
|
+
Even a genuine no-op `gtd land` (a clean tree matching no `on` pattern) prints a
|
|
807
|
+
PRINT-ONLY script: no git write, just the same `nothing to do at "<state>"` line
|
|
808
|
+
the script prints when a driver runs it. Every encoding (plain, `--json`,
|
|
809
|
+
`--sh`) carries that same script verbatim in its `script` field — running it is
|
|
810
|
+
never optional, whichever encoding a driver reads it from. The script is
|
|
811
|
+
self-contained (it carries its own precondition assert and retry helper) and
|
|
812
|
+
safe to run standalone, in sequence, or not at all — paste it into a terminal
|
|
813
|
+
and it does exactly what it says, printed output included: it detects its own
|
|
814
|
+
tty/`NO_COLOR` at RUN time (not at the moment gtd generated it), so the
|
|
815
|
+
fancy/plain rendering always matches wherever you actually run it.
|
|
690
816
|
|
|
691
817
|
A driver has no opening move. It does not need to know whose turn it is before
|
|
692
|
-
it starts — `gtd next --json` tells it, and a human's pending edit
|
|
693
|
-
ordinary `kind: "capture"` beat that the driver lands like any
|
|
694
|
-
this replaces: never `gtd land` outside a beat you dispatched. A
|
|
695
|
-
clean `prompt` rest authors an empty attempt on purpose (that IS
|
|
696
|
-
bookkeeping), so an unconditional opening land would manufacture a
|
|
697
|
-
a fresh start.
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
`
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
`
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
818
|
+
it starts — `gtd next --json`/`--sh` tells it, and a human's pending edit
|
|
819
|
+
arrives as an ordinary `kind: "capture"` beat that the driver lands like any
|
|
820
|
+
other. The rule this replaces: never `gtd land` outside a beat you dispatched. A
|
|
821
|
+
stray land at a clean `prompt` rest authors an empty attempt on purpose (that IS
|
|
822
|
+
the stall bookkeeping), so an unconditional opening land would manufacture a
|
|
823
|
+
stall out of a fresh start. The one EXCEPTION is the run's very first beat: land
|
|
824
|
+
it before trusting `idle` there too, so a workflow whose initial state declares
|
|
825
|
+
its own clean-tree `"C"` pattern still gets a chance to advance on a human's
|
|
826
|
+
bare re-invocation, rather than the driver concluding "nothing owed" without
|
|
827
|
+
ever giving that edge a turn (see the reference driver's own comment on this).
|
|
828
|
+
|
|
829
|
+
Exit code carries none of this any more — every command, `next`/`land` included,
|
|
830
|
+
exits `0` on success (see [Exit codes](#exit-codes) above). Whose turn is next,
|
|
831
|
+
and whether a landing settles, are both PLAIN FIELDS on `gtd next --json`/`--sh`
|
|
832
|
+
and `gtd land --json`/`--sh`: `next`'s own `kind`
|
|
833
|
+
(`capture`/`message`/`script`/`prompt`/`stalled`) and `idle`; `land`'s own
|
|
834
|
+
`settled` and `idle`. `gtd land --sh` carries `settled`/`idle` alongside the
|
|
835
|
+
script itself, so ONE invocation both runs the landing and tells the driver
|
|
836
|
+
whether to stop — no second read needed to decide. A no-op at a `script` rest
|
|
837
|
+
settles right where it rests (stop immediately, nothing more to read); an
|
|
838
|
+
ordinary or squash landing that finishes the whole process instead resolves
|
|
839
|
+
`idle` on the FOLLOWING `gtd next` — the reference driver below reads once more
|
|
840
|
+
only to DISPLAY that gate's message, never to decide whether to stop. Declaring
|
|
841
|
+
a `C` edge on a `script` state is the workflow-side way to make the state
|
|
842
|
+
advance instead of settling.
|
|
843
|
+
|
|
844
|
+
### Drivers other than sh
|
|
845
|
+
|
|
846
|
+
The protocol above is JSON in (from `gtd status --json` alone), subprocesses out
|
|
847
|
+
— sh is one convenient shape, not the only one. A **program** parses
|
|
848
|
+
`gtd status --json`, switches on `kind`, and runs `gtd next`'s (plain-text)
|
|
849
|
+
output and `gtd land`'s (POSIX sh) output as subprocesses — no sh anywhere in
|
|
850
|
+
it. A **human** runs plain `gtd next` (there is no JSON form of it at all), does
|
|
851
|
+
what it says, and pastes `gtd land | sh`: plain-text output exists for exactly
|
|
852
|
+
this, printing the combined script ready to paste. An **agent** gets
|
|
853
|
+
`gtd install` as its instructions — the same protocol, in a form built to be
|
|
854
|
+
pasted into a context window rather than read. A **CI job** is the program case
|
|
855
|
+
with the `prompt` arm pointed at a headless agent CLI, and
|
|
726
856
|
`kind: "message"`/`kind: "stalled"` mapped onto "stop and report".
|
|
727
857
|
|
|
728
858
|
### A complete minimal driver
|
|
@@ -737,102 +867,149 @@ This exact fenced block is extracted and executed by
|
|
|
737
867
|
`tests/integration/features/readme-driver.feature` — renaming the heading above
|
|
738
868
|
or splitting the block into more than one fence breaks the build.
|
|
739
869
|
|
|
870
|
+
**Pipe the prompt to the agent CLI on stdin — never pass it as a command-line
|
|
871
|
+
argument.** A `prompt` beat's content embeds a full diff, and argv is capped:
|
|
872
|
+
roughly 1 MB on macOS, and POSIX guarantees only 4 KB (`ARG_MAX`). Both are
|
|
873
|
+
reachable by an ordinary diff, so a driver that passes the prompt as an argument
|
|
874
|
+
works in testing and then fails on the first large change, in a way that looks
|
|
875
|
+
like an agent error rather than a driver bug. The driver below pipes `$c`/`$out`
|
|
876
|
+
into `claude -p` over stdin for exactly this reason.
|
|
877
|
+
|
|
740
878
|
```bash
|
|
741
|
-
#!/usr/bin/env
|
|
742
|
-
set -
|
|
743
|
-
|
|
744
|
-
# The bundle plans; this executes. Emitted scripts print their own outcomes.
|
|
745
|
-
# Exit 3 means SETTLED — nothing owed — so this exits the whole driver at 0.
|
|
746
|
-
gtd_land() {
|
|
747
|
-
local json code=0
|
|
748
|
-
json="$(gtd land --json)" || code=$?
|
|
749
|
-
[ "$code" = 0 ] || [ "$code" = 3 ] || return "$code"
|
|
750
|
-
bash -c "$(jq -r '.required // empty' <<<"$json")" || return $?
|
|
751
|
-
bash -c "$(jq -r '.optional // empty' <<<"$json")" ||
|
|
752
|
-
echo "warn: presentation follow-up failed — continuing" >&2
|
|
753
|
-
[ "$code" = 3 ] && exit 0
|
|
754
|
-
return 0
|
|
755
|
-
}
|
|
879
|
+
#!/usr/bin/env sh
|
|
880
|
+
set -eu
|
|
756
881
|
|
|
757
882
|
beat=1
|
|
758
883
|
while :; do
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
884
|
+
# One invocation per beat: assign first, THEN eval — command substitution
|
|
885
|
+
# inside eval's own argument would swallow a failed `gtd next` under
|
|
886
|
+
# `set -e` (eval would see only the empty string and abort on some later
|
|
887
|
+
# unset variable with a confusing message). Assigning to `out` first makes
|
|
888
|
+
# this a simple command whose own exit status IS the substitution's, so
|
|
889
|
+
# `set -e` aborts correctly on a genuine failure.
|
|
890
|
+
out="$(gtd next --sh)"
|
|
891
|
+
eval "$out"
|
|
892
|
+
|
|
893
|
+
# `gtd_idle` (true iff the initial state, clean tree) is the one shape
|
|
894
|
+
# that means the process is genuinely done — EXCEPT on the run's opening
|
|
895
|
+
# beat: land it anyway, so a workflow whose initial state declares its own
|
|
896
|
+
# clean-tree "C" pattern still gets a chance to fire.
|
|
897
|
+
if [ "$beat" -gt 1 ] && [ "${gtd_idle:-}" = true ]; then
|
|
898
|
+
gtd next
|
|
899
|
+
exit 0
|
|
900
|
+
fi
|
|
901
|
+
|
|
902
|
+
case "$gtd_kind" in
|
|
903
|
+
stalled) printf '%s\n' "$gtd_content" >&2; exit 1 ;;
|
|
764
904
|
# you re-ran us resting here: you either edited something or accepted by
|
|
765
905
|
# editing nothing, so land the opening beat either way. Later beats are
|
|
766
906
|
# gates we just produced and you have not read yet — hand off.
|
|
767
|
-
message) [ "$beat" = 1 ] || {
|
|
907
|
+
message) [ "$beat" = 1 ] || { gtd next; exit 0; } ;;
|
|
768
908
|
capture) ;; # the human already acted — just land it
|
|
769
|
-
script)
|
|
909
|
+
script)
|
|
910
|
+
sh -c "$gtd_content" >>"$gtd_log" 2>&1 || true ;;
|
|
770
911
|
prompt)
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
912
|
+
# $gtd_content embeds a full diff, so it goes to the agent over
|
|
913
|
+
# stdin, never as an argv positional — argv is capped (~1 MB on
|
|
914
|
+
# macOS, and POSIX guarantees only 4 KB, ARG_MAX), and a diff crosses
|
|
915
|
+
# that far sooner than you'd expect.
|
|
916
|
+
agent_turn() { printf '%s' "$gtd_content" | claude -p "$1" "$gtd_session_id" \
|
|
917
|
+
${gtd_model:+--model "$gtd_model"} --dangerously-skip-permissions \
|
|
918
|
+
>>"$gtd_log" 2>&1; }
|
|
919
|
+
if [ "${gtd_session_resume:-}" = true ]
|
|
776
920
|
then agent_turn --resume || agent_turn --session-id
|
|
777
921
|
else agent_turn --session-id || agent_turn --resume
|
|
778
922
|
fi
|
|
779
|
-
|
|
780
|
-
while [ -n "$
|
|
781
|
-
n=$((n + 1)) && [ "$n" -gt 3 ] && { printf '%s\n' "$
|
|
782
|
-
|
|
783
|
-
|
|
923
|
+
n=0
|
|
924
|
+
while [ -n "${gtd_validate:-}" ] && ! fix="$(sh -c "$gtd_validate" 2>&1)"; do
|
|
925
|
+
n=$((n + 1)) && [ "$n" -gt 3 ] && { printf '%s\n' "$fix" >&2; exit 1; }
|
|
926
|
+
# $fix IS the fix prompt, verbatim — piped for the same reason as
|
|
927
|
+
# $gtd_content above
|
|
928
|
+
printf '%s' "$fix" | claude -p --resume "$gtd_session_id" \
|
|
929
|
+
--dangerously-skip-permissions >>"$gtd_log" 2>&1
|
|
784
930
|
done ;;
|
|
785
931
|
esac
|
|
786
|
-
|
|
932
|
+
|
|
933
|
+
# `gtd land --sh` carries `settled`/`idle` alongside the script itself —
|
|
934
|
+
# one invocation tells us both what to run and whether to stop, with no
|
|
935
|
+
# second read needed to decide either.
|
|
936
|
+
out="$(gtd land --sh)"
|
|
937
|
+
eval "$out"
|
|
938
|
+
printf '%s\n' "$gtd_script" | sh
|
|
939
|
+
if [ "${gtd_settled:-}" = true ]; then
|
|
940
|
+
[ "${gtd_idle:-}" = true ] && gtd next
|
|
941
|
+
exit 0
|
|
942
|
+
fi
|
|
787
943
|
beat=$((beat + 1))
|
|
788
944
|
done
|
|
789
945
|
```
|
|
790
946
|
|
|
791
|
-
Line by line it is the protocol described above:
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
947
|
+
Line by line it is the protocol described above: `out="$(gtd next --sh)"` then
|
|
948
|
+
`eval "$out"` is one invocation per beat — assigning first is what lets `set -e`
|
|
949
|
+
abort correctly on a genuine failure, where `eval "$(gtd next --sh)"` would
|
|
950
|
+
instead eval the empty string and die later on some unrelated unset variable;
|
|
951
|
+
the driver carries no `unset` of its own, since the `--sh` document's own
|
|
952
|
+
preamble makes `eval` self-contained. The very first beat lands even when
|
|
953
|
+
`gtd_idle` is already true, so a workflow whose initial state declares its own
|
|
954
|
+
clean-tree `"C"` pattern still gets a chance to fire before the driver calls it
|
|
955
|
+
done. `kind: "stalled"` prints `$gtd_content` (the diagnosis itself) to stderr
|
|
956
|
+
and stops — no re-invocation needed, since the beat already fetched it;
|
|
957
|
+
`message` halts unless it is the opening beat, which the human's own
|
|
958
|
+
re-invocation authored and which therefore lands like any other decision (see
|
|
959
|
+
[Driving the loop](#driving-the-loop) above — this is the one place the driver,
|
|
960
|
+
not gtd, decides, because "has the human read this gate" is run-scoped knowledge
|
|
961
|
+
gtd deliberately does not keep); `capture` lands a human's already-made edit
|
|
962
|
+
outright, no display needed; `script` runs `$gtd_content` in the driver;
|
|
963
|
+
`prompt` sends it to the agent over stdin with `$gtd_session_id`/`$gtd_model`
|
|
964
|
+
mapped onto the agent's session flags — trying `resume`'s hinted flag first and
|
|
965
|
+
falling back to the other on failure, since the session id is derived, not
|
|
966
|
+
remembered (see [Driving the loop](#driving-the-loop) above) — and its own
|
|
967
|
+
`$gtd_validate` script's output re-prompted verbatim on failure (the driver owns
|
|
968
|
+
only the retry cap). Every optional variable (`$gtd_model`, `$gtd_validate`,
|
|
969
|
+
`$gtd_session_resume`, `$gtd_idle`, `$gtd_settled`) is read as `${var:-}` or
|
|
970
|
+
`${var:+...}` — under `set -u`, the `--sh` document's own `unset` preamble makes
|
|
971
|
+
an absent field genuinely unset, not empty, so a bare `$gtd_model` would abort
|
|
972
|
+
the driver. Every landed turn is executed — and reported — by the emitted
|
|
973
|
+
scripts themselves, via `gtd land --sh`'s own `$gtd_script` field, captured then
|
|
974
|
+
piped to `sh`. `$gtd_settled` ends a run that has nothing left to do: a no-op at
|
|
975
|
+
a `script` rest settles right where it rests (stop immediately, nothing more to
|
|
976
|
+
read), while an ordinary or squash landing that finishes the whole process
|
|
977
|
+
instead resolves `$gtd_idle` on the FOLLOWING beat's own `gtd next --sh` read —
|
|
978
|
+
the reference driver reads once more (a plain `gtd next`) only to DISPLAY that
|
|
979
|
+
gate's own message, the decision to stop already made from `$gtd_settled`/
|
|
980
|
+
`$gtd_idle` alone.
|
|
809
981
|
|
|
810
982
|
### The self-validation gate
|
|
811
983
|
|
|
812
984
|
After an agent turn at a state that declares `file:`+`mode:`, run the script:
|
|
813
|
-
either `gtd
|
|
985
|
+
either `gtd status --json`'s own embedded `.validate` field (present at every
|
|
814
986
|
`prompt` beat that hands over a validatable file), or, standalone,
|
|
815
|
-
`gtd validate
|
|
816
|
-
shared resolver. Exit 0 means the file is well-formed — proceed to
|
|
817
|
-
non-zero exit means the script's own captured output IS a
|
|
818
|
-
ready-to-send fix prompt (an instruction plus the findings, see
|
|
819
|
-
`failurePromptWrapper`): send it back to the same agent session
|
|
820
|
-
cap how many fix attempts you allow yourself — the driver owns
|
|
821
|
-
not gtd. Landing never TRUSTS that you validated, either: the
|
|
822
|
-
script carries the same format/validate commands ahead of its own
|
|
823
|
-
fails without committing when they fail, so a malformed file is never
|
|
824
|
-
whether or not you ran the validate script first.
|
|
987
|
+
`gtd validate`'s own plain-text output — both resolve the exact same script from
|
|
988
|
+
one shared resolver. Exit 0 means the file is well-formed — proceed to
|
|
989
|
+
`gtd land`. A non-zero exit means the script's own captured output IS a
|
|
990
|
+
complete, ready-to-send fix prompt (an instruction plus the findings, see
|
|
991
|
+
`src/Emit.ts`'s `failurePromptWrapper`): send it back to the same agent session
|
|
992
|
+
verbatim, and cap how many fix attempts you allow yourself — the driver owns
|
|
993
|
+
that retry count, not gtd. Landing never TRUSTS that you validated, either: the
|
|
994
|
+
emitted `land` script carries the same format/validate commands ahead of its own
|
|
995
|
+
commit and fails without committing when they fail, so a malformed file is never
|
|
996
|
+
captured whether or not you ran the validate script first.
|
|
825
997
|
|
|
826
998
|
### Failure taxonomy and recovery
|
|
827
999
|
|
|
828
|
-
|
|
829
|
-
non-zero-looking
|
|
1000
|
+
Several different things can go wrong, and they mean different things — and most
|
|
1001
|
+
non-zero-looking exits are not a failure at all:
|
|
830
1002
|
|
|
831
1003
|
- **`gtd` itself exits 1.** Nothing was attempted — this is a refusal (a guard
|
|
832
|
-
rejected the turn)
|
|
833
|
-
- **`gtd
|
|
834
|
-
|
|
835
|
-
|
|
1004
|
+
rejected the turn). No script was ever produced.
|
|
1005
|
+
- **`gtd` itself exits 2.** A usage error — nothing was even attempted, the
|
|
1006
|
+
invocation itself was wrong (unknown option/command, bad arity, a scope
|
|
1007
|
+
violation).
|
|
1008
|
+
- **`gtd land` succeeds (exit 0) but doesn't settle.** This is NOT a failure:
|
|
1009
|
+
whose turn is next lives in the FOLLOWING `gtd next`'s own `kind` field, not
|
|
1010
|
+
in `gtd land`'s exit code (see [Exit codes](#exit-codes)) — and `gtd land`'s
|
|
1011
|
+
own stdout still carries a script (a print-only note, or a genuine
|
|
1012
|
+
retain+rewind, or an ordinary commit) that a driver must still run.
|
|
836
1013
|
- **An emitted script exits non-zero when YOU run it.** Something may have
|
|
837
1014
|
partially happened — e.g. a `gtd_retry`-wrapped git write landed but a later
|
|
838
1015
|
step in the same script failed.
|
|
@@ -856,8 +1033,10 @@ its own retry/resume logic beyond "if the script failed, ask gtd again."
|
|
|
856
1033
|
|
|
857
1034
|
### Prerequisites
|
|
858
1035
|
|
|
859
|
-
-
|
|
860
|
-
|
|
1036
|
+
- **A POSIX `sh`** (dash, ash, bash's own POSIX mode, etc.) — gtd's own emitted
|
|
1037
|
+
scripts (`gtd land`, `gtd --entry <state>`, `gtd abandon`, `gtd restore`) are
|
|
1038
|
+
POSIX sh; captured, then piped into it (see
|
|
1039
|
+
[Writing your own driver](#writing-your-own-driver) above).
|
|
861
1040
|
- **`gtd` on `PATH`** — a mode's seeded `validate:` command (the one the
|
|
862
1041
|
compiler fills in for the built-in `qa`/`review` formats) is literally the
|
|
863
1042
|
string `gtd check <mode> '<file>'`, invoked by NAME from inside an emitted
|
|
@@ -896,7 +1075,7 @@ One case never runs your `format:` (or `validate:`) at all: a step whose diff
|
|
|
896
1075
|
DELETES the state's own `file:`. Deleting it is a legitimate outcome — a review
|
|
897
1076
|
sign-off's whole diff is the review doc's deletion — and there is nothing left
|
|
898
1077
|
to format. Emitting the command anyway would make such a step unlandable, since
|
|
899
|
-
`format:` is the first line of a `set -
|
|
1078
|
+
`format:` is the first line of a `set -eu` script and a formatter like
|
|
900
1079
|
`prettier --write` exits non-zero on a path that is not there.
|
|
901
1080
|
|
|
902
1081
|
### Built-in steering formats are ordinary modes
|
|
@@ -1002,7 +1181,7 @@ workflow:
|
|
|
1002
1181
|
retry:
|
|
1003
1182
|
max: <number>
|
|
1004
1183
|
otherwise: <targetState>
|
|
1005
|
-
label: <string> # optional, opaque display name passed through `gtd
|
|
1184
|
+
label: <string> # optional, opaque display name passed through `gtd status --json`
|
|
1006
1185
|
file: <string> # optional, an Eta template naming the state's steering file
|
|
1007
1186
|
mode: <modeName> # optional, requires "file" — must be declared in `modes:` (qa/review are seeded for you; everything else, including prose, you declare)
|
|
1008
1187
|
reviewWindow: true # optional — open the review checkout window at rest here
|