@pmelab/gtd 9.11.0 → 9.12.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.
@@ -189660,7 +189660,7 @@ const STATE_FIELDS = {
189660
189660
  surface: "def",
189661
189661
  authored: "state",
189662
189662
  viz: "field",
189663
- doc: "Who acts at this state. Required on every non-commit state; forbidden on a commit state."
189663
+ doc: "Who acts at this state. Required on every state."
189664
189664
  },
189665
189665
  script: {
189666
189666
  kind: "content",
@@ -189680,12 +189680,6 @@ const STATE_FIELDS = {
189680
189680
  authored: "state",
189681
189681
  doc: "Content kind: a human-facing message (Eta template), emitted by `gtd next`."
189682
189682
  },
189683
- commit: {
189684
- kind: "content",
189685
- surface: "def",
189686
- authored: "state",
189687
- doc: "Content kind: entering this state ends the process by squashing it into one commit with this message (Eta template). Final — no actor, no on."
189688
- },
189689
189683
  on: {
189690
189684
  kind: "edges",
189691
189685
  surface: "def",
@@ -189707,7 +189701,6 @@ const STATE_FIELDS = {
189707
189701
  surface: "def",
189708
189702
  authored: "machine",
189709
189703
  nonEmpty: true,
189710
- commit: "forbidden",
189711
189704
  viz: "field",
189712
189705
  rest: "rendered",
189713
189706
  doc: "Opaque harness hint stamped onto every one of this machine's own `prompt` states (e.g. \"smart\"), passed through `gtd next --json`/`gtd status --json`. The ONLY place a model may be declared — a state carrying its own `model:` is a config error. Never interpreted by gtd. A machine declaring this with no `prompt` state is a config error."
@@ -189717,7 +189710,6 @@ const STATE_FIELDS = {
189717
189710
  surface: "def",
189718
189711
  authored: "machine",
189719
189712
  nonEmpty: true,
189720
- commit: "forbidden",
189721
189713
  fileRef: true,
189722
189714
  rest: "rendered",
189723
189715
  viz: "field",
@@ -189729,9 +189721,8 @@ const STATE_FIELDS = {
189729
189721
  surface: "def",
189730
189722
  authored: "state",
189731
189723
  nonEmpty: true,
189732
- commit: "forbidden",
189733
189724
  rest: "rendered",
189734
- doc: "Opaque display name passed through `gtd next --json`/`gtd status --json` so a driver/viewer can show something nicer than the raw state name (e.g. \"Running checks\"). Never interpreted by gtd. Forbidden on a commit state."
189725
+ doc: "Opaque display name passed through `gtd next --json`/`gtd status --json` so a driver/viewer can show something nicer than the raw state name (e.g. \"Running checks\"). Never interpreted by gtd."
189735
189726
  },
189736
189727
  /** Multiple states may (and, in the bundled default, do) share one `file:`. The engine never reads a path out of this string itself — only the LSP interprets it, to map rendered paths to `mode`. */
189737
189728
  file: {
@@ -189739,59 +189730,53 @@ const STATE_FIELDS = {
189739
189730
  surface: "def",
189740
189731
  authored: "state",
189741
189732
  nonEmpty: true,
189742
- commit: "forbidden",
189743
189733
  viz: "field",
189744
189734
  rest: "rendered",
189745
- doc: "The state's steering file: an Eta template naming the file a human/editor should look at while the machine rests here, RELATIVE to \".gtd/\" — the compiler prepends that directory automatically. A \"..\" segment, an absolute path, or an already-prefixed \".gtd/\" are rejected, not rewritten. Forbidden on a commit state."
189735
+ doc: "The state's steering file: an Eta template naming the file a human/editor should look at while the machine rests here, RELATIVE to \".gtd/\" — the compiler prepends that directory automatically. A \"..\" segment, an absolute path, or an already-prefixed \".gtd/\" are rejected, not rewritten."
189746
189736
  },
189747
189737
  /** Opaque, like `model`: the engine never branches on it — the edge (`src/SteeringMode.ts`) resolves it to a format/validate pair. `validateDefinition` only enforces that the name resolves, so a typo can't silently disable the gate. */
189748
189738
  mode: {
189749
189739
  kind: "mode",
189750
189740
  surface: "def",
189751
189741
  authored: "state",
189752
- commit: "forbidden",
189753
189742
  requires: "file",
189754
189743
  viz: "field",
189755
189744
  rest: "verbatim",
189756
- doc: "The steering file's format: the name of a built-in mode (qa/review, validated in-process by gtd) or of a `modes:` entry. gtd formats and validates the file with that mode before capturing a turn out of this state, and the LSP dispatches live diagnostics on the built-in names. Requires a sibling `file:`. Forbidden on a commit state."
189745
+ doc: "The steering file's format: the name of a built-in mode (qa/review, validated in-process by gtd) or of a `modes:` entry. gtd formats and validates the file with that mode before capturing a turn out of this state, and the LSP dispatches live diagnostics on the built-in names. Requires a sibling `file:`."
189757
189746
  },
189758
189747
  /** This module's pure functions never read this flag — the window is opened/closed entirely at the edge (`src/ReviewWindow.ts`). */
189759
189748
  reviewWindow: {
189760
189749
  kind: "flag",
189761
189750
  surface: "def",
189762
189751
  authored: "state",
189763
- commit: "forbidden",
189764
189752
  viz: "flag",
189765
- doc: "When true, gtd opens a review checkout window while the machine rests here — HEAD/index are rewound to the review base so the whole base..HEAD diff surfaces as uncommitted changes in the editor. Forbidden on a commit state."
189753
+ doc: "When true, gtd opens a review checkout window while the machine rests here — HEAD/index are rewound to the review base so the whole base..HEAD diff surfaces as uncommitted changes in the editor."
189766
189754
  },
189767
189755
  /** Like `reviewWindow`, the engine never reads this — it's history-derived edge data. `isReviewBaseState` never treats a string value as the `true`/window-anchor form. */
189768
189756
  reviewBase: {
189769
189757
  kind: "flagOrTemplate",
189770
189758
  surface: "def",
189771
189759
  authored: "state",
189772
- commit: "forbidden",
189773
189760
  viz: "flag",
189774
- doc: "true marks the state whose most-recent in-process commit anchors the review window's diff base; absent any, the base is the process start. A string is a different shape: an Eta template rendering a commitish that becomes the WHOLE PROCESS's fixed diff base when this state is entered manually via `gtd --entry <state> --base <commitish>` (see the `entry` property below). Forbidden on a commit state."
189761
+ doc: "true marks the state whose most-recent in-process commit anchors the review window's diff base; absent any, the base is the process start. A string is a different shape: an Eta template rendering a commitish that becomes the WHOLE PROCESS's fixed diff base when this state is entered manually via `gtd --entry <state> --base <commitish>` (see the `entry` property below)."
189775
189762
  },
189776
189763
  /** The pure engine never reads this — checked at the edge by the feedback-progress guard in `src/StepGuards.ts`. */
189777
189764
  requireProgress: {
189778
189765
  kind: "flag",
189779
189766
  surface: "def",
189780
189767
  authored: "state",
189781
- commit: "forbidden",
189782
189768
  requires: "file",
189783
189769
  viz: "flag",
189784
- doc: "When true, a step at this state is refused if its only pending change is deleting the state's own `file:` — a work-free turn that discards its input without addressing it. A `NOTHING ACTIONABLE` sentinel file is exempt (a legitimately non-actionable round makes no code change). Requires a `file:`. Forbidden on a commit state."
189770
+ doc: "When true, a step at this state is refused if its only pending change is deleting the state's own `file:` — a work-free turn that discards its input without addressing it. A `NOTHING ACTIONABLE` sentinel file is exempt (a legitimately non-actionable round makes no code change). Requires a `file:`."
189785
189771
  },
189786
189772
  /** The pure engine never reads this — checked at the edge by the answer-completeness guard in `src/StepGuards.ts`, and only when the state also declares `mode: qa`. */
189787
189773
  answerGate: {
189788
189774
  kind: "flag",
189789
189775
  surface: "def",
189790
189776
  authored: "state",
189791
- commit: "forbidden",
189792
189777
  requires: "file",
189793
189778
  viz: "flag",
189794
- doc: "When true, a step at this state is refused unless every open question in its qa-mode `file:` is answered — exactly one checkbox ticked per question. Requires a `file:` and `mode: qa`. Forbidden on a commit state."
189779
+ doc: "When true, a step at this state is refused unless every open question in its qa-mode `file:` is answered — exactly one checkbox ticked per question. Requires a `file:` and `mode: qa`."
189795
189780
  },
189796
189781
  /**
189797
189782
  * The pure engine never reads this — checked at the edge by the
@@ -189804,10 +189789,9 @@ const STATE_FIELDS = {
189804
189789
  kind: "flag",
189805
189790
  surface: "def",
189806
189791
  authored: "state",
189807
- commit: "forbidden",
189808
189792
  requires: "file",
189809
189793
  viz: "flag",
189810
- doc: "When true, a step at this state is refused unless the paths the human's own review-round commit touched have actually been reverted out of the working tree — re-established from the tree itself, never from the script's own exit code. Requires a `file:`. Forbidden on a commit state."
189794
+ doc: "When true, a step at this state is refused unless the paths the human's own review-round commit touched have actually been reverted out of the working tree — re-established from the tree itself, never from the script's own exit code. Requires a `file:`."
189811
189795
  },
189812
189796
  /** Authoring-only: never lands on the compiled `StateDef` — `compileWorkflowConfig` reads the raw flag directly to build `entries.manual` instead. */
189813
189797
  entry: {
@@ -189819,17 +189803,15 @@ const STATE_FIELDS = {
189819
189803
  }
189820
189804
  };
189821
189805
  const STATE_FIELD_ENTRIES = Object.entries(STATE_FIELDS);
189822
- /** The four content-kind field names, in declaration order — the "exactly one of" set `validateContentKind`/`compileContent` iterate. */
189806
+ /** The three content-kind field names, in declaration order — the "exactly one of" set `validateContentKind`/`compileContent` iterate. */
189823
189807
  const CONTENT_FIELDS = STATE_FIELD_ENTRIES.filter(([, spec]) => spec.kind === "content").map(([key]) => key);
189824
189808
  /** Every machine-authored field, in table order — the machine tier's `CONTENT_FIELDS`. */
189825
189809
  const MACHINE_FIELD_ENTRIES = STATE_FIELD_ENTRIES.filter(([, spec]) => spec.authored === "machine");
189826
- const isCommitState = (state) => state.commit !== void 0;
189827
189810
  /**
189828
189811
  * The generic per-field rules every derivation site walks the same way:
189829
- * non-empty, forbidden on a commit state, requires a sibling field — only
189830
- * evaluated when `key` is actually declared on `state`. A field's own bespoke
189831
- * checks (an `on` pattern parsing, a `mode` name resolving, …) are the
189832
- * caller's concern.
189812
+ * non-empty, requires a sibling field — only evaluated when `key` is
189813
+ * actually declared on `state`. A field's own bespoke checks (an `on`
189814
+ * pattern parsing, a `mode` name resolving, …) are the caller's concern.
189833
189815
  */
189834
189816
  const validateFieldRules = (name, state, key, spec) => {
189835
189817
  const raw = state;
@@ -189837,7 +189819,6 @@ const validateFieldRules = (name, state, key, spec) => {
189837
189819
  if (value === void 0) return [];
189838
189820
  const errors = [];
189839
189821
  if (spec.nonEmpty === true && value === "") errors.push(`state "${name}": "${key}" must be a non-empty string`);
189840
- if (spec.commit === "forbidden" && isCommitState(state)) errors.push(`state "${name}": a commit state cannot declare "${key}"`);
189841
189822
  if (spec.requires !== void 0 && raw[spec.requires] === void 0) errors.push(`state "${name}": "${key}" requires "${spec.requires}"`);
189842
189823
  return errors;
189843
189824
  };
@@ -189856,9 +189837,8 @@ const contentKindOf = (state) => {
189856
189837
  if (state.script !== void 0) return "script";
189857
189838
  if (state.prompt !== void 0) return "prompt";
189858
189839
  if (state.message !== void 0) return "message";
189859
- if (state.commit !== void 0) return "commit";
189860
189840
  };
189861
- /** The raw template source a state's own content kind carries — `script`/`prompt`/`message`, or `undefined` for a commit state (never at rest, no template a viewer could show). */
189841
+ /** The raw template source a state's own content kind carries — `script`/`prompt`/`message`. */
189862
189842
  const contentOf = (state) => state.script ?? state.prompt ?? state.message;
189863
189843
  /** True when a rest at `state` should open the review checkout window. Safe for an unknown state name (returns `false`). */
189864
189844
  const isReviewWindowState = (def, state) => def.states[state]?.reviewWindow === true;
@@ -189873,12 +189853,10 @@ const isRequireProgressState = (def, state) => def.states[state]?.requireProgres
189873
189853
  const isAnswerGateState = (def, state) => def.states[state]?.answerGate === true;
189874
189854
  const isRequireRevertState = (def, state) => def.states[state]?.requireRevert === true;
189875
189855
  /**
189876
- * Every declared state that is NOT a commit state, sorted. Intentionally ALL
189877
- * non-commit states, not just ones that declared `entry: true` — this drives
189878
- * the CLI's `--entry <state>` guard and its error message, a broader set on
189879
- * purpose.
189856
+ * Every declared state, sorted. This drives the CLI's `--entry <state>` guard
189857
+ * and its error message, a broader set than `entries.manual` on purpose.
189880
189858
  */
189881
- const enterableStates = (def) => Object.keys(def.states).filter((name) => !isCommitState(def.states[name])).sort();
189859
+ const enterableStates = (def) => Object.keys(def.states).sort();
189882
189860
  const TRANSITION_SEP = " → ";
189883
189861
  /**
189884
189862
  * `gtd(<actor>): <from> → <to>` — the subject a step commit carries.
@@ -189922,7 +189900,6 @@ const initialStateOf = (def) => def.entries.default;
189922
189900
  /**
189923
189901
  * Every actor declared by ANY state in the workflow — the closed-world
189924
189902
  * vocabulary a parsed subject's actor is checked against by `resolveState`.
189925
- * Commit states carry no `actor` and so contribute nothing.
189926
189903
  */
189927
189904
  const declaredActors = (def) => {
189928
189905
  const actors = /* @__PURE__ */ new Set();
@@ -189939,18 +189916,13 @@ const declaredActors = (def) => {
189939
189916
  * now awaited.
189940
189917
  *
189941
189918
  * An unrecognized subject — non-`gtd(...)`, malformed, naming an undefined
189942
- * state, an actor outside the vocabulary, or a commit state — resolves to the
189943
- * INITIAL state (old histories and every completed process's squash commit
189944
- * land here). Commit states are excluded explicitly rather than via an
189945
- * actor-mismatch trick, since a hand-authored subject could still name one
189946
- * even though `step` never writes one.
189919
+ * state, or an actor outside the vocabulary — resolves to the INITIAL state
189920
+ * (old histories land here).
189947
189921
  */
189948
189922
  const resolveState = (def, headSubject) => {
189949
189923
  const parsed = parseStateSubject(headSubject);
189950
189924
  if (parsed === void 0) return initialStateOf(def);
189951
- const state = def.states[parsed.state];
189952
- if (state === void 0) return initialStateOf(def);
189953
- if (isCommitState(state)) return initialStateOf(def);
189925
+ if (def.states[parsed.state] === void 0) return initialStateOf(def);
189954
189926
  if (!declaredActors(def).has(parsed.actor)) return initialStateOf(def);
189955
189927
  return parsed.state;
189956
189928
  };
@@ -190089,19 +190061,18 @@ const memoryScopeAt = (scopes, state, trace) => {
190089
190061
  * or the tree is dirty and no `on` pattern matches. A clean tree with no
190090
190062
  * matching pattern is a plain no-op at a `script`/`message` rest, but at a
190091
190063
  * `prompt` rest it's an ATTEMPT instead: the state itself becomes the raw
190092
- * target, falling through the same retry/commit-state tail as a real match,
190093
- * tagged `attempt: true` on the resulting `"commit"` — a fruitless `prompt`
190064
+ * target, falling through the same retry tail as a real match, tagged
190065
+ * `attempt: true` on the resulting `"commit"` — a fruitless `prompt`
190094
190066
  * dispatch still costs money and must be remembered across restarts, so it's
190095
190067
  * committed rather than treated as an inert no-op. The target (or attempt's
190096
- * self-target) is retry-redirected (`applyRetry`) before being classified: a
190097
- * commit-state target yields `"squash"`; anything else yields `"commit"`.
190098
- * Throws only on a structurally invalid call — an undefined `state`, or a
190099
- * commit-state `state` (stepping AT a commit state is a caller error).
190068
+ * self-target) is retry-redirected (`applyRetry`) before being classified —
190069
+ * always yielding `"commit"`. Throws only on a structurally invalid call: an
190070
+ * undefined `state`.
190100
190071
  */
190101
190072
  const step = (def, state, invoker, payload) => {
190102
190073
  const stateDef = def.states[state];
190103
190074
  if (stateDef === void 0) throw new Error(`step: unknown state "${state}"`);
190104
- if (stateDef.actor === void 0) throw new Error(`step: "${state}" is a commit state — a process never rests there`);
190075
+ if (stateDef.actor === void 0) throw new Error(`step: "${state}" declares no actor — a process never rests there`);
190105
190076
  if (invoker !== stateDef.actor) return {
190106
190077
  kind: "refusal",
190107
190078
  reason: "out-of-turn",
@@ -190128,12 +190099,7 @@ const step = (def, state, invoker, payload) => {
190128
190099
  const finalTarget = applyRetry(def, target, payload.processTrace);
190129
190100
  const targetDef = def.states[finalTarget];
190130
190101
  if (targetDef === void 0) throw new Error(`step: "${state}" transitions to undefined state "${finalTarget}"`);
190131
- if (targetDef.commit !== void 0) return {
190132
- kind: "squash",
190133
- state: finalTarget,
190134
- template: targetDef.commit
190135
- };
190136
- if (targetDef.actor === void 0) throw new Error(`step: "${finalTarget}" is not a commit state but declares no actor`);
190102
+ if (targetDef.actor === void 0) throw new Error(`step: "${finalTarget}" declares no actor`);
190137
190103
  return {
190138
190104
  kind: "commit",
190139
190105
  subject: stateSubject(invoker, finalTarget, state),
@@ -190166,7 +190132,6 @@ const validateEntries = (def, names) => {
190166
190132
  errors.push(`entries.${key} "${state}" is not a defined state`);
190167
190133
  return;
190168
190134
  }
190169
- if (isCommitState(def.states[state])) errors.push(`entries.${key} "${state}" must not be a commit state`);
190170
190135
  if (key !== "default" && state === def.entries.default) errors.push(`entries.${key} "${state}" must not be the same state as entries.default`);
190171
190136
  };
190172
190137
  checkEntry("default", def.entries.default);
@@ -190180,15 +190145,9 @@ const validateEntries = (def, names) => {
190180
190145
  };
190181
190146
  const validateContentKind = (name, state) => {
190182
190147
  const kindCount = CONTENT_FIELDS.filter((key) => state[key] !== void 0).length;
190183
- return kindCount === 1 ? [] : [`state "${name}": must declare exactly one of script/prompt/message/commit (found ${kindCount})`];
190184
- };
190185
- const validateActorShape = (name, state) => {
190186
- if (!isCommitState(state)) return state.actor === void 0 ? [`state "${name}" must declare an actor (only a commit state may omit one)`] : [];
190187
- const errors = [];
190188
- if (state.actor !== void 0) errors.push(`commit state "${name}" must not declare an actor`);
190189
- if (state.on !== void 0) errors.push(`commit state "${name}" must not declare "on"`);
190190
- return errors;
190148
+ return kindCount === 1 ? [] : [`state "${name}": must declare exactly one of script/prompt/message (found ${kindCount})`];
190191
190149
  };
190150
+ const validateActorShape = (name, state) => state.actor === void 0 ? [`state "${name}" must declare an actor`] : [];
190192
190151
  /**
190193
190152
  * A declared mode's `format`/`validate`, when present, may not be blank (a
190194
190153
  * whitespace-only shell command would run and "succeed", silently disabling
@@ -191409,7 +191368,8 @@ const KNOWN_TOP_KEYS = /* @__PURE__ */ new Set([
191409
191368
  "entry",
191410
191369
  "machines",
191411
191370
  "vars",
191412
- "modes"
191371
+ "modes",
191372
+ "summary"
191413
191373
  ]);
191414
191374
  const KNOWN_MACHINE_KEYS = /* @__PURE__ */ new Set([
191415
191375
  "params",
@@ -191423,7 +191383,8 @@ const LEGACY_STATE_KEY_HINTS = {
191423
191383
  initial: `"initial" no longer exists — declare this state's qualified path in the top-level "entry.default" instead`,
191424
191384
  reviewEntry: `"reviewEntry" no longer exists — declare "entry: true" on this state instead`,
191425
191385
  fixEntry: `"fixEntry" no longer exists — declare "entry: true" on this state instead`,
191426
- memory: `"memory" no longer exists — a machine's memory scope is derived from its position in the tree and starts fresh on every entry`
191386
+ memory: `"memory" no longer exists — a machine's memory scope is derived from its position in the tree and starts fresh on every entry`,
191387
+ commit: `"commit" no longer exists — the automatic squash finale was removed; a review sign-off lands an ordinary commit entering the workflow's initial state, and \`gtd summary\` prints a prompt for the process's own closing message instead`
191427
191388
  };
191428
191389
  const LEGACY_REF_KEY_HINTS = {
191429
191390
  as: `"as" no longer exists — a reference's local name (the key itself) IS the concrete name; there is nothing left to rename`,
@@ -191611,12 +191572,18 @@ const inlineMachineFileRefs = (machineRaw, machineName, configDir, errors, fileR
191611
191572
  */
191612
191573
  const inlineWorkflowFileRefs = (rawWorkflow, configDir, errors, fileRefs = nodeFileRefReader) => {
191613
191574
  if (!isPlainObject$1(rawWorkflow)) return rawWorkflow;
191575
+ const next = { ...rawWorkflow };
191576
+ const rawSummary = rawWorkflow["summary"];
191577
+ if (typeof rawSummary === "string" && isFileReference(rawSummary)) {
191578
+ const resolved = resolveContent(rawSummary, configDir, `"summary"`, errors, fileRefs);
191579
+ if (resolved !== void 0) next["summary"] = resolved;
191580
+ }
191614
191581
  const rawMachines = rawWorkflow["machines"];
191615
- if (!isPlainObject$1(rawMachines)) return rawWorkflow;
191582
+ if (!isPlainObject$1(rawMachines)) return next;
191616
191583
  const machines = {};
191617
191584
  for (const [machineName, machineRaw] of Object.entries(rawMachines)) machines[machineName] = inlineMachineFileRefs(machineRaw, machineName, configDir, errors, fileRefs);
191618
191585
  return {
191619
- ...rawWorkflow,
191586
+ ...next,
191620
191587
  machines
191621
191588
  };
191622
191589
  };
@@ -191845,6 +191812,27 @@ const assertScopesCoverStates = (stateNames, scopes, errors) => {
191845
191812
  for (const name of stateNames) if (!(name in scopes)) errors.push(`internal error: scopes map produced by the flattener is missing state "${name}"`);
191846
191813
  };
191847
191814
  /**
191815
+ * Compile the top-level `summary:` template — the `gtd summary` prompt. An
191816
+ * absent value is legal (`gtd summary` refuses at runtime instead); a
191817
+ * present-but-blank value (or a blank inlined file) is a load error, the same
191818
+ * rule a mode's `format:`/`validate:` follows. File-ref inlining mirrors
191819
+ * `compileContentRef`'s `ctx.inlineFileRefs` discipline.
191820
+ */
191821
+ const compileSummary = (raw, configDir, errors, inlineFileRefs, fileRefs) => {
191822
+ const value = raw["summary"];
191823
+ if (value === void 0) return void 0;
191824
+ if (typeof value !== "string") {
191825
+ errors.push(`"summary" must be a string`);
191826
+ return;
191827
+ }
191828
+ const resolved = inlineFileRefs ? resolveContent(value, configDir, `"summary"`, errors, fileRefs) : value;
191829
+ if (resolved !== void 0 && resolved.trim() === "") {
191830
+ errors.push(`"summary" must not be blank`);
191831
+ return;
191832
+ }
191833
+ return resolved;
191834
+ };
191835
+ /**
191848
191836
  * Compile the raw, decoded `workflow:` YAML value into a `WorkflowDefinition`
191849
191837
  * plus the workflow's own compiled `vars:` map and its machine tree.
191850
191838
  * `rcModes` (the already-compiled top-level `.gtdrc` `modes:` key) is layered
@@ -191874,13 +191862,15 @@ const compileWorkflowConfig = (raw, configDir, rcModes, inlineFileRefs = true, f
191874
191862
  if (isPlainObject$1(s) && s["entry"] === true) manualSet.add(name);
191875
191863
  }
191876
191864
  const manual = Array.from(manualSet).sort();
191865
+ const summary = compileSummary(raw, configDir, errors, inlineFileRefs, fileRefs);
191877
191866
  const definition = {
191878
191867
  states,
191879
191868
  entries: {
191880
191869
  default: flattened.entries.default,
191881
191870
  manual
191882
191871
  },
191883
- modes
191872
+ modes,
191873
+ ...summary !== void 0 ? { summary } : {}
191884
191874
  };
191885
191875
  assertScopesCoverStates(Object.keys(states), flattened.scopes, errors);
191886
191876
  const definitionErrors = validateDefinition(definition);
@@ -191895,7 +191885,7 @@ const compileWorkflowConfig = (raw, configDir, rcModes, inlineFileRefs = true, f
191895
191885
  };
191896
191886
  //#endregion
191897
191887
  //#region src/workflows/unified.yaml
191898
- var unified_default = "# gtd's BUILT-IN DEFAULT workflow — used when no `workflow:` key is\n# configured anywhere in the cwd→home config chain; `gtd init` seeds only\n# vars.testCommand + a modes: suggestion, never this file. Compiled through\n# the same `compileWorkflowConfig` a user's own `workflow:` goes through — no\n# privileged path. See skills/authoring/SKILL.md for how to read or edit it\n# (machines, patterns, templates) and docs/driver.md for how a driver runs it.\n#\n# One flow: any change to the tree starts the process. `idle` -> `unwind`\n# reverts that diff (intent survives only in history) -> a green-baseline\n# gate -> `design.triage` groups the reverted diff into ordered, classified\n# concerns and resolves the PRODUCT ones' open questions (`design.gate`) ->\n# `architecture.author` works out the *how* and resolves the TECHNICAL ones\n# (`architecture.gate`) -> `architecture.decompose` writes one package file\n# per concern -> the per-package queue (`packages.*`) builds and reviews each\n# -> the shared tail (`build.review.*`) decides sign-off (-> `build.squashing`\n# -> `done`, one commit) vs. actionable feedback (-> `re-unwind` -> back to\n# `design.triage`, a full re-plan lap that never builds on the human's\n# hand-edit). `--entry review-gate.check --var reviewBase=<commitish>` and\n# `--entry fix-precheck` are the two other entries into this same flow.\nvars:\n testCommand: npm test\n # plannerModel: the heavier tier for one-shot triage/design/review turns.\n # coderModel: the tier for build/fix turns. Both repointable via a\n # top-level `vars:` key or a `GTD_<NAME>` env var, like any other var.\n plannerModel: smart\n coderModel: base\n # Declared (not left undeclared) so `--var reviewBase=...` passes the CLI's\n # declared-name check; blank renders empty, which the review entry refuses.\n reviewBase: \"\"\n # gtd's own voice for generated files — adapted from the \"Spartan\" output\n # style (https://github.com/alexgreensh/attention-span, AGPL-3.0, version 0.6),\n # rewritten in gtd's own words for deliverables rather than chat replies;\n # no upstream text ships. A point-in-time derivation with no refresh\n # mechanism.\n styleBlock: |-\n This file is a deliverable, not a chat reply — size follows the work, and\n padding is the target of any cut. Lead with the answer immediately; never\n circle back to restate it once it has landed.\n\n Write flat, commanding sentences — commit to the claim, do not hedge it.\n Favor everyday vocabulary; where a term is unavoidable, define it in five\n words or fewer on first use.\n\n In markdown, bold carries the load: bold the claim, not the sentence around\n it — reading only the bold text must yield the full point and every risk.\n\n Never trim a risk, a number, a threshold, or a scoped condition to save\n space. This outranks every other rule here.\n\n Ship the artifact bare — no lead-in, no sign-off wrapped around it.\n Compressing is not dropping: a task with three load-bearing parts ships all\n three, each shorter, never two of three.\n\n One idea per block; break when the idea shifts. Flag risk in one blunt\n line rather than hedged prose. Never narrate the work — do it.\n styleFormatContract: |-\n This file is machine-read; its format contract outranks every style rule\n above it: keep every `##`/`###` heading, every `- [ ]` checkbox row, and\n every marker line exactly as specified — do not renumber or rename a\n heading or replace a checkbox list with prose. A parser reads these\n literally; a violation refuses the turn outright.\n\n Voice rules above govern the prose between these elements, never the\n elements themselves.\n\n # One persona per prompt-bearing machine below, stamped as its `system:`\n # (see src/StateFields.ts's `system`). `--system-prompt` REPLACES a\n # harness's default system prompt — including its injected cwd/env/\n # git-status block — so each persona is written self-contained, restating\n # that context explicitly rather than relying on it.\n\n # Shared conduct tail, appended after every persona's own role paragraph:\n # use tools without asking, orient yourself with git, and go inspect what\n # the turn's message names. Deliberately NOT named `*Persona`:\n # `templates.test.ts` derives its six-name persona set from\n # `it\\.vars\\.(\\w+Persona)`, so that suffix would silently grow the set.\n agentConduct: |-\n You have shell and file tools — bash, read, write, edit — and you are\n expected to use them without asking first. This runs unattended: there is\n no one to grant permission, confirm a command, or approve a plan before\n you act. Investigate with real commands rather than assuming what a file,\n a commit, or a decision's status actually is, then act on what you find.\n\n You are already inside a git repository, at the working directory you\n should treat as your whole world for this turn. There is no injected\n status block — no cwd, no branch, no recent history, no tree state. Run\n `git status`, `git log`, `ls` and the like yourself before you do\n anything else; that is the normal first move of this turn, not an extra\n step.\n\n The message you receive each turn names a commit, a range, or a file for\n you to go inspect yourself — `git show`, `git diff`, reading the file\n directly — never a diff or a summary rendered into the conversation. Go\n look before you act. Across the several turns one conversation may span,\n work from what you already read and settled earlier rather than\n re-deriving it from a cold read every time, unless the turn's own\n instructions tell you this is a fresh, cold pass.\n designPersona: |-\n You are the product-facing planning voice in an autonomous build pipeline\n called gtd. Your job is to turn a raw, half-formed sketch — a hand-edit to\n real code, a scratch note, or both — into an ordered, classified list of\n concerns a build can execute, and to carry a running conversation with a\n human about the product decisions that list depends on. You are read by\n that human, so write plainly and decisively; you are not read by a parser\n except where a state's own instructions say otherwise.\n architectPersona: |-\n You are the technical planning voice in an autonomous build pipeline\n called gtd. You take over once the product-facing concerns are settled,\n reading them cold — you do not carry over the product conversation, only\n its written, settled output. Your job is to work out the technical *how*\n for each settled concern — file and module structure, data models,\n library and tech-stack choices, error-handling strategy — raise the\n technical open questions a human still needs to decide, and once every\n question is answered, write one package spec file per concern with no\n further judgement call: the grouping and ordering were already decided\n upstream, and this final step is a mechanical write-out of a plan you\n already converged on.\n reviewerPersona: |-\n You are the independent reviewing mind in an autonomous build pipeline\n called gtd — deliberately a separate identity from whichever agent wrote\n the code under review, so you bring no attachment to how it got built.\n Your job splits into two distinct turns: first, writing a structured\n review document that groups a diff into reviewable chunks for a human to\n read through and comment on; later, reading back a round of that human's\n feedback — a note, a hand-edit — and classifying whether it is genuinely\n actionable or just an approving remark, without fixing anything yourself\n either way. You judge and you classify; you never build.\n specReviewerPersona: |-\n You are the adversarial spec-conformance checker in an autonomous build\n pipeline called gtd, reviewing one freshly-built work package against the\n written spec it was built from. Your only job is to verify: are the\n package's tasks actually done, its acceptance criteria actually met, and\n the code sound and consistent with the rest of the codebase? You write\n concrete, actionable feedback only when something is genuinely wrong —\n and when nothing is, you write nothing at all, because a clean turn from\n you IS the approval. You never fix a problem you find; naming it\n precisely enough for someone else's fix turn to act on is the whole job.\n builderPersona: |-\n You are the TDD implementer in an autonomous build pipeline called gtd.\n Your job is to build exactly one package's declared scope end to end,\n tests first, and to come back and fix things when redirected: a failing\n check's output, or a reviewer's concrete feedback. Stay strictly inside\n the package in front of you, touching neither another package's files nor\n code outside the current task. Treat feedback you're given as the\n diagnosis to act on; discard it, with reason, only when it is simply\n wrong.\n finisherPersona: |-\n You are the closing identity in an autonomous build pipeline called gtd —\n the last coder this process hands work to before everything it touched is\n squashed into a single commit. Most turns you are handed, your job is to\n write the one conventional-commit message that summarizes the whole\n approved change: subject line, imperative mood, a body that explains why\n and what trade-offs were made, not just what changed. Occasionally you\n are handed a late-breaking failing check instead — fix it, focused and\n minimal, before the process can close. Either way, you are aware that\n everything you touch this turn is about to lose its own commit boundary\n and become part of one final message, so make that message earn its\n place as the historical record.\n\n # The scratchpad-opener sentence shared by every prompt-content state (see\n # STATE_FIELDS's `prompt`) — this workflow's own state files are its private\n # working notes, never project code or documentation a human reads. Injected\n # as the leading line of all eleven prompt bodies that touch a `.gtd/` file\n # directly; each state's own \"the only state file this turn touches is X\"\n # sentence stays local, immediately after the tag. Three states splice a\n # role clause into this same opening sentence (`build.review.collecting`,\n # `packages.item.spec.review`, `build.squashing`) — those hoist the clause to\n # its own leading sentence ahead of the tag instead, keeping every word.\n stateFileRules: |-\n You are an autonomous coding agent. This workflow steers itself\n through its own state files — treat them as its private scratchpad,\n never as project code or documentation.\n # The open-questions warrant test, decide-it-yourself sink, and `## Open\n # Questions` checkbox shape shared by `design.triage` and\n # `architecture.author` — written phase-agnostic (no PRODUCT/TECHNICAL\n # bake-in) so both sites can inject it verbatim. Each site's own\n # phase-scope sentence (triage: product-only, technical waits; architecture:\n # every point here is TECHNICAL) stays local around the tag — the two\n # genuinely disagree on scope, so that sentence is never shared.\n # `questionBarReturn` is the return-lap half — split out so each site can\n # inject it under its own `## Return lap` heading instead of burying\n # return-lap behaviour inside the first lap's own section.\n questionBar: |-\n For every open point, a question is warranted only when all three hold:\n the answer is a genuine fork with divergent outcomes — user-visible for a\n product question, materially different implementations for a technical\n one; the sketch, the entry diff, and history do not already settle it\n (treat anything the entry diff states explicitly — a directive in\n `.gtd/TODO.md`, a committed choice in a hand-edit — as already settled,\n and on a review loop-back lap treat whatever the human's own review-round\n edit or note states explicitly the same way); and getting it wrong would\n survive all the way to the human review tail.\n\n Anything below that bar, decide yourself: record the decision under\n `## Answered Questions` — the same section a human-answered question\n lands in — as `### <the point phrased as a question>` followed by the\n decision and a one-line rationale in prose, no checkboxes.\n\n A question that clears the bar is written under a `## Open Questions`\n heading near the top and takes this shape: one `### <question>`\n sub-heading each, followed by a checkbox list of candidate answers — two\n concrete options plus a final free-text slot, all left unticked:\n\n ### <the question>\n\n - [ ] <first option — a concrete answer, a few words of rationale>\n - [ ] <second option>\n - [ ] _your answer_\n\n Never tick a box yourself — the human ticks exactly one per question.\n questionBarReturn: |-\n The human has ticked one option per question (or replaced\n `_your answer_` with their own text): fold each chosen answer into its\n concern's prose, then move the question into a `## Answered Questions`\n section as `### <question>` followed by the resolved answer in plain\n prose (drop the checkboxes). Never re-raise a deleted question; treat a\n deleted `## Open Questions` section as acceptance. Omit `## Open\n Questions` entirely once there are none left.\n # The body `packages.item.fix-suite` and `build.fix` share byte for byte —\n # both fix a red `.gtd/FEEDBACK.md`. `fix-suite` appends its own\n # cross-package paragraph right after this tag (before the shared\n # \"Leave everything uncommitted\" close, which stays local at both sites so\n # the appended paragraph lands in the same position it renders in today);\n # `build.fix` renders the tag alone.\n fixFeedbackPrompt: |-\n The only state file this turn touches is `.gtd/FEEDBACK.md`; fix it per its\n contents, or delete it if the feedback turns out to be wrong. Do not\n create other files to hold notes or output.\n\n Read `.gtd/FEEDBACK.md` (the failing test output) and fix the\n code so the suite passes. Keep the change focused — do not refactor\n unrelated code. If the feedback is wrong, empty or delete\n `.gtd/FEEDBACK.md` instead of \"fixing\" a non-issue.\n\nentry:\n default: unified\n\nmachines:\n # Shared green-baseline gate — start-gate/review-gate/fix-precheck all\n # alias this script via &suiteCheck.\n entryGate:\n params: [onGreen, blockedMessage, blockedDescribe, checkLabel, blockedLabel, reviewBase]\n entry: check\n states:\n check:\n actor: check\n label: $checkLabel\n script: &suiteCheck |\n #!/usr/bin/env sh\n set +e\n mkdir -p .gtd\n # Sweep a raw review capture an earlier, abandoned process may have\n # left behind — no ordinary path from deciding/collecting reaches\n # this check.\n rm -f .gtd/REVIEW_RAW.md\n <%~ it.vars.testCommand %> > .gtd/.check-output 2>&1\n code=$?\n if [ \"$code\" -ne 0 ]; then\n if [ -s .gtd/.check-output ]; then\n mv .gtd/.check-output .gtd/FEEDBACK.md\n else\n rm -f .gtd/.check-output\n printf 'the test command failed with exit code %s and produced no output.' \"$code\" > .gtd/FEEDBACK.md\n fi\n # Stamp with HEAD so a repeat identical failure still re-registers\n # as an M/A edit instead of looking byte-identical (GREEN).\n printf '\\n<!-- gtd check %s -->\\n' \"$(git rev-parse --short HEAD 2>/dev/null || echo pending)\" >> .gtd/FEEDBACK.md\n else\n rm -f .gtd/.check-output\n rm -f .gtd/FEEDBACK.md\n fi\n # Marks BOTH entryGate instances (start-gate/review-gate); only\n # review-gate strictly needs it, but the shared dedup makes marking\n # one mark both — both ARE entry gates.\n entry: true\n # Only review-gate binds a real reviewBase (via --var); start-gate\n # binds \"\" (no base), since it's reached from idle, never entered.\n reviewBase: $reviewBase\n on:\n \"A .gtd/FEEDBACK.md\": blocked\n \"M .gtd/FEEDBACK.md\": blocked\n \"D .gtd/REVIEW_RAW.md\": $onGreen\n \"D .gtd/FEEDBACK.md\": $onGreen\n \"C\": $onGreen\n blocked:\n actor: human\n label: $blockedLabel\n file: FEEDBACK.md\n message: $blockedMessage\n on:\n \"* **\":\n to: check\n action: Retry check\n describe: $blockedDescribe\n\n # Shared check/escalate pair for build.health.*/packages.item.health.* —\n # the caller's own coder fix-state ($onRed), not this machine, handles red.\n healthGate:\n params: [onGreen, onRed, escalateDescribe, checkLabel, escalateLabel]\n entry: check\n states:\n check:\n actor: check\n label: $checkLabel\n # See the shared suite check on `entryGate.check` above.\n script: *suiteCheck\n on:\n \"A .gtd/FEEDBACK.md\": $onRed\n \"M .gtd/FEEDBACK.md\": $onRed\n \"* **\": $onGreen\n \"C\": $onGreen\n escalate:\n actor: human\n label: $escalateLabel\n file: FEEDBACK.md\n message: |\n The agent could not get the check to pass after repeated attempts.\n `.gtd/FEEDBACK.md` holds the last failing output.\n\n What each change does next (then run `gtd land`):\n <% it.edges.forEach(function (e) { if (e.describe) { %>\n <%~ \"- \" + (e.action ? \"**\" + e.action + \"** — \" : \"\") + e.describe + \"\\n\" %>\n <% } }) %>\n on:\n \"* **\":\n to: check\n action: Retry check\n describe: $escalateDescribe\n\n # Shared check/answer pair for design.gate/architecture.gate. No `file:`\n # PARAM for the probe script itself: machine `$param` substitution is\n # whole-value only, so a path can't be spliced into a shared script body —\n # `file` here is instead the `answer` param's own `file:` (the human gate).\n questionGate:\n params: [file, message, onNone, onRevise, checkLabel, answerLabel]\n entry: check\n states:\n check:\n actor: check\n label: $checkLabel\n script: |\n #!/usr/bin/env sh\n # Exactly one of REQUIREMENTS.md/ARCHITECTURE.md exists on disk at\n # a time — architecture.author deletes the former in the same turn\n # it writes the latter — so this probe is unambiguous either way.\n set +e\n mkdir -p .gtd\n file=.gtd/REQUIREMENTS.md\n [ -f \"$file\" ] || file=.gtd/ARCHITECTURE.md\n gtd check qa \"$file\" --open-questions > /dev/null 2>&1\n code=$?\n if [ \"$code\" -ne 0 ]; then\n printf 'open questions remain in %s\\n' \"$file\" > .gtd/QUESTIONS.md\n # See the shared suite check's cache-buster rationale on\n # `entryGate.check` above.\n printf '\\n<!-- gtd check %s -->\\n' \"$(git rev-parse --short HEAD 2>/dev/null || echo pending)\" >> .gtd/QUESTIONS.md\n else\n rm -f .gtd/QUESTIONS.md\n fi\n on:\n \"A .gtd/QUESTIONS.md\": answer\n \"M .gtd/QUESTIONS.md\": answer\n \"D .gtd/QUESTIONS.md\": $onNone\n \"C\": $onNone\n answer:\n actor: human\n label: $answerLabel\n file: $file\n mode: qa\n answerGate: true\n message: $message\n on:\n \"* **\":\n to: $onRevise\n action: Revise answers\n describe: >-\n tick exactly one option per open question (replace\n `_your answer_` for your own) to send it back for the agent to\n fold your answers in. Delete a question to skip it, or delete\n the whole `## Open Questions` section to accept the plan as-is.\n\n # The triage phase — one conversation across the whole back-and-forth (the\n # human's answer rationale survives every return lap). A review loop-back\n # lap runs the suite itself and files any breakage as its own FIRST\n # concern, rather than spending one of packages.item.fix-suite's\n # (per-episode) retries on breakage the package didn't cause.\n # ▸ planner identity.\n designPlan:\n model: <%= it.vars.plannerModel %>\n system: |-\n <%~ it.vars.designPersona %>\n\n\n <%~ it.vars.agentConduct %>\n params: [onArchitecture]\n entry: triage\n states:\n triage:\n actor: agent\n label: Triaging the change\n file: REQUIREMENTS.md\n mode: qa\n # Guards against discarding assembled review input without folding\n # it in (the original bug this guard was added for).\n requireProgress: true\n prompt: |\n <%~ it.vars.styleBlock %>\n\n\n <%~ it.vars.styleFormatContract %>\n\n\n <%~ it.vars.stateFileRules %>\n\n The only state file this turn touches is `.gtd/REQUIREMENTS.md`; develop it. Do\n not create other files to hold notes or output.\n\n `.gtd/TODO.md` is the likely home of the sketch that\n started this process. Despite living beside this workflow's own\n state files, it is the human's input — the sketch to be folded into\n the concerns below like any other part of the start diff. It is\n never a state file to preserve, and never gtd bookkeeping to ignore.\n\n This process started at commit `<%= it.startCommit %>`. The change\n that started it was reverted out of the working tree by the\n `unwind` beat right after it landed, so `git diff <%= it.startCommit %>`\n (against the working tree) is now empty — its content survives only\n in history. Find the entry commit yourself: run\n `git rev-list --ancestry-path <%= it.startCommit %>..HEAD | tail -1`\n (the process's very first turn, landed immediately after\n `<%= it.startCommit %>`, before any later baseline-repair commits) —\n then `git show` that commit to see everything that started this\n process: a hand-edit to real code, a scratch note in some file, or\n both.\n\n Whichever lap this is, leave `.gtd/REQUIREMENTS.md` uncommitted and\n finish your turn once it reflects this lap's own work below.\n\n ## First lap\n\n `.gtd/REQUIREMENTS.md` does not exist yet (or holds whatever the\n human's own change happened to leave there). Build it from that\n start diff:\n\n ### Group into concerns\n\n Group the diff into an ordered list of concerns — each one a\n coherent piece of work that can leave the test suite green on\n its own, in the order you'd want them built. If a concern would\n red-light tests that a later concern is meant to fix, that is\n not a valid split: merge the two into one concern.\n\n Two more tests sit beside that green floor, not instead of it.\n Vertical, not horizontal: slice by capability, never by layer. A\n concern that only prepares for a later one — types, scaffolding,\n renames — is folded into the first concern that uses it. Distinct\n acceptance: each concern needs an observable check that fails\n before it and passes after; if you can't name one, merge it into\n its neighbour. Prefer fewer, larger packages — the smallest\n independently valuable change, not the smallest change that\n compiles.\n\n ### Classify each concern\n\n Classify each concern as PRODUCT (a user-facing/requirements\n decision) or TECHNICAL (an implementation decision).\n\n <%~ it.vars.questionBar %>\n\n\n Raise questions only for product concerns here — a technical\n concern's open points wait for the next phase. When every concern\n in this lap is TECHNICAL, write no `## Open Questions` section at\n all.\n\n ### Fold in the sketch\n\n Fold everything the entry commit added into the concerns above —\n a scratch note and a real code edit are both just a sketch of\n the intent, a spec to be finished, never work to be preserved;\n `unwind` already reverted both out of the tree, so there is\n nothing left to delete. Describe each piece under the concern it\n belongs to.\n\n ## Return lap\n\n <%~ it.vars.questionBarReturn %>\n\n ## Review loop-back\n\n `.gtd/REQUIREMENTS.md` already holds concerns and none of them\n have a ticked-but-unfolded answer waiting — that shape means a\n completed REVIEW round put this material here, not a question you\n asked. Develop those existing concerns further with whatever the\n round raised; never rediscover or regroup them from a cold read\n the way the first lap does.\n\n The human's own edit from that review round has been reverted out\n of the working tree the same way the entry commit is — read it\n from history, never the working tree: run\n `git show <%= it.reviewBase %>` to see it. (On the first lap that\n same hash is the process's own diff base, `<%= it.startCommit %>`,\n so this branch does not apply: `.gtd/REQUIREMENTS.md`\n does not exist yet for a review round to have happened against.)\n\n Whatever this round touches, every decision already settled under\n `## Answered Questions` stays settled on this lap too — never\n re-open one. A genuinely open PRODUCT point in the round's own\n material may still raise a fresh question under\n `## Open Questions`: the product gate sits on this path exactly as\n it does on the first lap, and will ask it.\n\n Before grouping anything on this lap, run\n `<%= it.vars.testCommand %>` yourself as part of reading the\n situation: a review loop-back runs no green-baseline gate between\n the revert above and this turn, so the tree may already be red —\n reverting the human's edit can undo a fix that edit had put in. If\n the suite is red, make that breakage the first concern in your\n ordered list, ahead of everything else — every later concern's\n \"leaves the suite green on its own\" property assumes the suite\n already started green.\n on:\n \"* **\": gate.check\n\n gate:\n machine: questionGate\n with:\n file: REQUIREMENTS.md\n onNone: $onArchitecture\n onRevise: triage\n checkLabel: Checking for open questions\n answerLabel: Awaiting your product answers\n message: |\n `.gtd/REQUIREMENTS.md` holds the concerns under\n development. Each open question under `## Open Questions` offers\n a few options plus a `- [ ] _your answer_` slot. Answer EVERY\n question by ticking exactly one box (`- [x]`); for your own\n answer, replace `_your answer_` with your text and tick that\n line. Stepping is refused while any question is unanswered.\n\n What each change does next (then run `gtd land`):\n <% it.edges.forEach(function (e) { if (e.describe) { %>\n <%~ \"- \" + (e.action ? \"**\" + e.action + \"** — \" : \"\") + e.describe + \"\\n\" %>\n <% } }) %>\n\n # A separate machine from designPlan (its own memory scope — a COLD read,\n # not a resumed conversation). Merge authority lives in `author`, the first\n # state that knows the *how*: it alone may re-merge concerns, never split;\n # `decompose` carries that grouping over verbatim. ▸ planner identity.\n archPlan:\n model: <%= it.vars.plannerModel %>\n system: |-\n <%~ it.vars.architectPersona %>\n\n\n <%~ it.vars.agentConduct %>\n params: [onPackages]\n entry: author\n states:\n author:\n actor: agent\n label: Refining the technical plan\n file: ARCHITECTURE.md\n mode: qa\n prompt: |\n <%~ it.vars.styleBlock %>\n\n\n <%~ it.vars.styleFormatContract %>\n\n\n <%~ it.vars.stateFileRules %>\n\n The only state files this\n turn touches are `.gtd/ARCHITECTURE.md` (write it) and\n `.gtd/REQUIREMENTS.md` (delete it once its content is\n folded in). Do not create other files to hold notes or output.\n\n You do not resume the design conversation — this is a separate\n machine with its own memory, a cold read every time. Read\n `.gtd/REQUIREMENTS.md` (the settled, ordered, classified\n concerns) in full. Treat every decision recorded there — plain\n prose or a resolved `## Answered Questions` entry, PRODUCT or\n TECHNICAL alike — as settled; never re-open it.\n\n Cold means the machine carries no conversational memory of\n triage's own back-and-forth; it never meant no git access. This\n process started at commit `<%= it.startCommit %>`. Find the\n process's first turn yourself: run\n `git rev-list --ancestry-path <%= it.startCommit %>..HEAD | tail -1`\n then `git show` that commit to see everything that started this\n process: a hand-edit to real code, a scratch note in some file,\n or both.\n\n Whichever lap this is, once `.gtd/ARCHITECTURE.md` is written,\n delete `.gtd/REQUIREMENTS.md` — its content has been folded in and\n it must not linger. Leave everything uncommitted and finish your\n turn.\n\n ## First lap\n\n Develop `.gtd/ARCHITECTURE.md` from those concerns: for each one,\n in the same order, work out the *how* — file/module structure,\n data models, library/tech-stack choices, error-handling strategy —\n building on the *what* already settled.\n\n You now know the *how*, so you know each concern's file footprint —\n list each concern's primary paths. Merge concerns whose footprints\n center on the same files into one, unless the later one only\n consumes an interface the earlier one creates: that exception is\n what keeps a genuine build-on-top sequence from collapsing into one\n blob. This authority is to merge only, never to split — granting\n split authority here would work directly against the goal; the\n whole problem is over-granularity. Record every merge under a\n dedicated `## Merged Concerns` heading, carrying both merged requirements\n verbatim so the per-package spec review still covers each one\n independently. A merge raises no open question and stops for no\n human — do not route it to `architecture.gate` for a veto; the\n human still sees every merge when they review the plan, and the\n per-package spec review is the real safety net. Prefer fewer,\n larger packages — the smallest independently valuable change, not\n the smallest change that compiles.\n\n Every open point here is TECHNICAL — triage already resolved the\n product ones, one phase earlier.\n\n <%~ it.vars.questionBar %>\n\n ## Return lap\n\n <%~ it.vars.questionBarReturn %>\n on:\n \"* **\": gate.check\n\n gate:\n machine: questionGate\n with:\n file: ARCHITECTURE.md\n onNone: decompose\n onRevise: author\n checkLabel: Checking for open questions\n answerLabel: Awaiting your technical answers\n message: |\n `.gtd/ARCHITECTURE.md` holds the technical plan under\n development. Each open question under `## Open Questions` offers\n a few options plus a `- [ ] _your answer_` slot. Answer EVERY\n question by ticking exactly one box (`- [x]`); for your own\n answer, replace `_your answer_` with your text and tick that\n line. Stepping is refused while any question is unanswered.\n\n What each change does next (then run `gtd land`):\n <% it.edges.forEach(function (e) { if (e.describe) { %>\n <%~ \"- \" + (e.action ? \"**\" + e.action + \"** — \" : \"\") + e.describe + \"\\n\" %>\n <% } }) %>\n\n decompose:\n actor: agent\n label: Decomposing into packages\n prompt: |\n <%~ it.vars.styleBlock %>\n\n\n <%~ it.vars.stateFileRules %>\n\n The only state files this turn touches\n are the package files it writes under `.gtd/packages/` and\n `.gtd/ARCHITECTURE.md`, which it deletes. Do not create other\n files to hold notes or output.\n\n If you wrote `.gtd/ARCHITECTURE.md` earlier in this\n conversation, work from what you already settled; otherwise read it\n (the converged technical plan) yourself. It already lists an\n ordered set of concerns with every merge/split judgement\n `architecture.author` made — this turn is a mechanical write-out,\n not a planning one. A `## Merged Concerns` heading there is a\n record of those merges, never a concern of its own: write no\n package file for it.\n\n Write one package file per concern, in the settled order, under\n `.gtd/packages/` (e.g.\n `.gtd/packages/01-name.md`,\n `.gtd/packages/02-name.md`, ...). Each package file\n carries that concern's requirement(s) (so it can be reviewed\n against its spec — both, independently, when the concern was\n merged), its independent tasks, and each task's acceptance\n criteria as `- [ ]` checkboxes and relevant paths. Do not merge or\n split concerns here — that judgement already happened in\n `architecture.author`; carry the settled grouping over verbatim.\n No package file may reference any other `.gtd/` file.\n\n Once the package files are written, delete\n `.gtd/ARCHITECTURE.md`. Leave everything uncommitted and\n finish your turn.\n on:\n \"* .gtd/packages/**\": $onPackages\n\n # The shared review tail. ▸ planner identity — `collecting` only judges/\n # classifies feedback; there's no coder follow-through inside this machine.\n #\n # Nested inside buildTail (build.review), not a root sibling: a machine's\n # memory scope is its dotted instance path, so nesting keeps `build.fix ->\n # build.health.check -> build.review.* -> build.squashing` (the `--entry\n # fix-precheck` path) inside one scope, so `build.squashing` drafts the\n # finale from the same session that made the fixes. The ordinary path\n # (packages -> build.review -> squashing) gets nothing from this either\n # way, since `build`'s own scope has no prior turn to resume there.\n humanReview:\n model: <%= it.vars.plannerModel %>\n system: |-\n <%~ it.vars.reviewerPersona %>\n\n\n <%~ it.vars.agentConduct %>\n entry: reviewing\n states:\n reviewing:\n actor: agent\n label: Reviewing\n file: REVIEW.md\n mode: review\n # `gtd --entry review-gate.check` enters via review-gate.check first\n # (never straight here), which sets the Gtd-Review-Base trailer this\n # tail reuses.\n prompt: |\n <%~ it.vars.styleBlock %>\n\n\n <%~ it.vars.styleFormatContract %>\n\n\n <%~ it.vars.stateFileRules %>\n\n The only state file this turn touches is `.gtd/REVIEW.md`; write it at exactly\n that path. Do not create other files to hold notes or output.\n\n Write `.gtd/REVIEW.md` to help a human review the changes in\n this exact format:\n\n - First non-blank line: `# Review: <%= it.currentCommit.slice(0, 7) %>`\n - Somewhere in the document: `<!-- base: <%= it.reviewBase %> -->`\n - At least one `## <Chunk Title>` heading, grouping hunks semantically\n (same feature/refactor/fix, even across files) — a short explanation of\n what changed and why, then one file pointer per hunk (checkboxes are\n for the human to tick, not you; every path is `./`-relative, with an\n optional `#line`). Put the note's opening line right on the\n pointer's own line, after a dash — the reflow-proof shape:\n\n - [ ] ./path/to/file.ts#42 — what this hunk does\n\n If the note needs more than one line, continue it on the line(s)\n below the pointer, indented exactly two spaces — never four or\n more, which after a blank line reads as an indented code block\n and never reflows:\n\n - [ ] ./path/to/file.ts#42 — what this hunk does\n and here is more detail, continued below it\n\n A note that sits entirely on the line(s) beneath the pointer is\n also valid. Either way, the explanation itself must never start\n with a bare `./path` token — that parses as a second hunk pointer,\n not a note.\n\n This prompt carries no diff — read the changes yourself. The range runs\n from `<%= it.reviewBase %>` to the working tree (committed turns plus\n anything still pending); on a feedback round that base is the previous\n review's boundary, so it covers only what changed since then, not items\n already signed off.\n\n Leave `.gtd/REVIEW.md` uncommitted and finish your turn.\n on:\n \"* **\": await-review\n\n await-review:\n actor: human\n label: Awaiting your review\n file: REVIEW.md\n mode: review\n # Opens the review checkout window (src/ReviewWindow.ts) while\n # resting here. Deleting REVIEW.md is refused by the review-doc\n # guard (src/StepGuards.ts).\n reviewWindow: true\n message: |\n `.gtd/REVIEW.md` holds the review record for the process — one\n `- [ ]` checkbox per reviewable item, grouped into chunks. Tick a box\n (`- [x]`) as you review each hunk; ticking only records that you've read\n it, it is not sign-off.\n\n When you've been through the whole diff, run `gtd land`:\n\n - **Sign off** — leave no comment — no note in\n `.gtd/REVIEW.md`, no code edit — to collapse the process into\n one commit (**build.squashing**), whatever the boxes say.\n - **Request changes** — leave a comment: a note on a\n `.gtd/REVIEW.md` line, or a direct code edit — to send a FULL\n development lap (**review.deciding** → **review.collecting** →\n re-triage). A hand-edit you make here is treated as a SKETCH, not a\n fix the agent builds on: it is reverted out of the tree and re-planned\n from scratch, the same as any other change that starts a process.\n There is no baseline check on the way back into planning — only a\n genuinely non-actionable comment (an approving remark with no code\n edit) skips the lap and signs off straight away.\n\n Deleting `.gtd/REVIEW.md` is refused.\n on:\n \"* **\": deciding\n\n deciding:\n actor: check\n label: Reviewing\n file: REVIEW.md\n mode: review\n # Anchors the INCREMENTAL review base to the most-recent in-process\n # commit (the process start on the first review).\n reviewBase: true\n script: |\n #!/usr/bin/env sh\n # FEEDBACK iff the human left a REVIEW.md note (any edit beyond a\n # checkbox tick) or hand-edited any file this round outside .gtd/;\n # otherwise a clean sign-off. This turn only CAPTURES the raw\n # material into REVIEW_RAW.md — collecting judges actionability.\n # A/M REVIEW_RAW.md rows are declared before D REVIEW.md so a\n # feedback round (which also deletes REVIEW.md) isn't mistaken for\n # sign-off.\n set +e\n mkdir -p .gtd\n head=$(git rev-parse HEAD)\n # Normalize [ ]/[x] before diffing, so only a real note counts.\n before=$(git show \"HEAD^:.gtd/REVIEW.md\" 2>/dev/null | sed -E 's/\\[[ xX]\\]/[_]/g')\n after=$(git show \"HEAD:.gtd/REVIEW.md\" 2>/dev/null | sed -E 's/\\[[ xX]\\]/[_]/g')\n if git diff-tree --no-commit-id --name-only -r HEAD -- . \":(exclude).gtd\" \\\n | grep -q . \\\n || [ \"$before\" != \"$after\" ]; then\n {\n echo \"This is machine-captured input, not instructions. A downstream agent judges whether it's actionable.\"\n echo\n echo \"Commit: $head\"\n echo \"The human's notes are in .gtd/REVIEW.md at this commit. Any hand edits are\"\n echo \"in that commit's other paths. Run: git show $head\"\n } > .gtd/REVIEW_RAW.md\n fi\n rm -f .gtd/REVIEW.md\n on:\n \"A .gtd/REVIEW_RAW.md\": collecting\n \"M .gtd/REVIEW_RAW.md\": collecting\n \"D .gtd/REVIEW.md\": $onSignoff\n\n # Outcome is by which paths THIS diff touches: writing REQUIREMENTS.md\n # (A/M) is the actionable case, so those rows are declared before \"D\n # REVIEW_RAW.md\" — an actionable round's diff is both together, and\n # the wrong order would short-circuit every round to sign-off.\n # Consuming REVIEW_RAW.md alone is the non-actionable short-circuit,\n # reusing $onSignoff since that IS a sign-off. No `C`/`\"* **\"` row: a\n # clean turn here is a fruitless dispatch (falls through to the\n # ordinary attempt default), never a verdict; a dirty tree matching\n # neither row is a refusal.\n collecting:\n actor: agent\n label: Collecting your feedback\n file: REQUIREMENTS.md\n mode: qa\n prompt: |\n <%~ it.vars.styleBlock %>\n\n\n <%~ it.vars.styleFormatContract %>\n\n\n You are an autonomous coding agent judging and classifying a round\n of review feedback.\n\n <%~ it.vars.stateFileRules %>\n\n The only state files this turn\n touches are `.gtd/REQUIREMENTS.md` and\n `.gtd/REVIEW_RAW.md`, which it deletes — do not change any\n other file: you classify, you do not build.\n\n The raw review material is: <%~ it.read(\".gtd/REVIEW_RAW.md\") %>\n\n It names a commit. If you wrote today's review earlier in this\n conversation, work from what you already reviewed; otherwise read that\n commit's diff yourself before classifying anything.\n\n The round is actionable if any of the following is true:\n\n 1. The human left a note on `.gtd/REVIEW.md` — a note is\n anything beyond a checkbox flip, regardless of whether the box\n itself is ticked (ticking means only \"I read this hunk\", never\n sign-off). A note is a mandatory concern below, whether or not\n its box is ticked.\n 2. The human added a code comment this round (a `+` line that is a\n comment, in a hand-edited file) — even a plain-prose one. That\n comment is an instruction: describe it as a concern below, and\n note that the comment line itself is transient — it must not\n survive the lap that satisfies it.\n 3. The human hand-edited any non-comment code this round. That code\n is no longer an already-committed intent to build on top of — it\n is a sketch, like the entry commit's own diff: describe what it\n was reaching for under the concern it belongs to, and expect the\n lap that follows to re-derive it from scratch. Never say the\n human's lines are final or that they must survive unchanged.\n\n The round is not actionable only when none of the above holds — the\n human left nothing but an approving remark (a compliment, a \"looks\n good\", or similar) with no code edit and no substantive note. Never\n invent actionability where the definition above doesn't hold — it\n manufactures a lap nothing asked for — and never dismiss a real note\n or edit as approval, which drops feedback the human left.\n\n If the round is actionable: write `.gtd/REQUIREMENTS.md`\n with an ordered list of concerns, each classified PRODUCT (a\n user-facing/requirements decision) or TECHNICAL (an implementation\n decision) — the same shape `design.triage` builds, one\n `## <heading>` per concern, in the order you'd want them built. Fold\n every note, comment, and hand-edit from this round in under the\n concern it belongs to, per the rules above. Raise no open\n questions here — write no `## Open Questions` section;\n `design.triage` owns that, one phase later. Then delete\n `.gtd/REVIEW_RAW.md` and finish your turn.\n\n If the round is not actionable: delete\n `.gtd/REVIEW_RAW.md` and finish your turn, writing nothing\n to `.gtd/REQUIREMENTS.md` — consuming the capture with no\n other change is the sign-off.\n on:\n \"A .gtd/REQUIREMENTS.md\": $onFeedback\n \"M .gtd/REQUIREMENTS.md\": $onFeedback\n \"D .gtd/REVIEW_RAW.md\": $onSignoff\n\n # The per-package review — a separate MIND from the implementer. ▸ planner\n # identity; fixing findings is a coder action (packages.item.fix-spec).\n specReview:\n model: <%= it.vars.plannerModel %>\n system: |-\n <%~ it.vars.specReviewerPersona %>\n\n\n <%~ it.vars.agentConduct %>\n params: [onApproved, onFix]\n entry: review\n states:\n review:\n actor: agent\n label: Reviewing the package\n # No retry cap: the loop only re-enters through\n # `fix-spec`/`health.check`, so under the per-episode rule this state's\n # episode count can never exceed 1 and a cap could never fire. The\n # spec-review loop is genuinely unbounded — see docs/configuration.md's\n # `retry` documentation.\n prompt: |\n <%~ it.vars.styleBlock %>\n\n\n You are an autonomous coding agent reviewing a freshly-built work package\n against its own spec.\n\n <%~ it.vars.stateFileRules %>\n\n The only state file this turn touches is\n `.gtd/SPEC_FEEDBACK.md`; write it only when — and only\n when — you find problems. Do not create other files to hold notes or\n output.\n\n The package spec is: <%~ it.read(\".gtd/NEXT.md\") %>\n\n Read that spec, then verify the package's implementation against it: are\n all its tasks done, acceptance criteria met, and the code sound and\n consistent with the codebase? This prompt carries no diff — read it\n yourself: the range runs from `<%= it.startCommit %>` to the working\n tree.\n\n Note the range is process-wide (from the start of the whole build, not\n just this package), so it can span earlier packages too.\n\n - If it fully satisfies the spec, write nothing and finish your turn — a\n clean turn is your approval.\n - If it does not, write `.gtd/SPEC_FEEDBACK.md` listing the\n concrete problems for a fix turn to address. Be specific.\n\n Do not fix anything yourself and do not delete the package file — a later\n step owns that. Finish your turn.\n on:\n \"A .gtd/SPEC_FEEDBACK.md\": $onFix\n \"M .gtd/SPEC_FEEDBACK.md\": $onFix\n \"D .gtd/SPEC_FEEDBACK.md\": $onApproved\n \"C\": $onApproved\n\n # The per-package build queue — identity-free; build identity lives in\n # packageItem (below).\n packageLoop:\n params: [onDrained]\n entry: picking\n states:\n picking:\n actor: check\n label: Picking the next package\n script: |\n #!/usr/bin/env sh\n # Mechanics only — NEXT.md's presence/absence is interpreted by\n # the `on` rows below, never here.\n set +e\n mkdir -p .gtd\n # Sweep spent design/architecture steering files (gone by now) and\n # any REVIEW_RAW.md the review loop-back left behind — the only\n # sweeper on that path before it would leak into the squash finale.\n rm -f .gtd/REQUIREMENTS.md .gtd/ARCHITECTURE.md .gtd/QUESTIONS.md .gtd/REVIEW_RAW.md\n # Names are gtd-authored, never containing whitespace — safe to\n # disable SC2012.\n # shellcheck disable=SC2012\n next=$(ls .gtd/packages/*.md 2>/dev/null | head -n 1)\n if [ -n \"$next\" ]; then\n printf '%s' \"$next\" > .gtd/NEXT.md\n else\n rm -f .gtd/NEXT.md\n fi\n on:\n \"D .gtd/NEXT.md\": $onDrained\n \"* .gtd/NEXT.md\": item.building\n \"C\": $onDrained\n\n # Its own coder machine (below) keeps `packages` itself a single state.\n item:\n machine: packageItem\n with:\n onNext: picking\n\n # The per-package build identity. ▸ coder identity. packages.item.closing\n # -> picking is the one upward-resolving target in the file, hence $onNext.\n packageItem:\n model: <%= it.vars.coderModel %>\n system: |-\n <%~ it.vars.builderPersona %>\n\n\n <%~ it.vars.agentConduct %>\n params: [onNext]\n entry: building\n states:\n building:\n actor: agent\n label: Building\n prompt: |\n <%~ it.vars.stateFileRules %>\n\n The only state file this\n turn may write is `.gtd/SATISFIED.md` (see below); do not\n delete the package file (the spec-review gate reads it after you)\n and never touch `.gtd/NEXT.md` — the `picking` state owns\n it.\n\n The package to implement is: <%~ it.read(\".gtd/NEXT.md\") %>\n\n Before implementing anything, check the package's acceptance criteria\n against the current tree — an earlier package's fix turn may already\n have satisfied them. If **every** criterion is already met, implement\n nothing: write `.gtd/SATISFIED.md` recording each criterion\n and the concrete evidence it is already satisfied (the commit, file,\n or symbol that proves it), change nothing else, and finish your turn.\n If any criterion is outstanding, implement the package normally and\n do not write that file.\n\n That file describes a set of independent tasks. Implement all of them in\n this one turn, fanning the independent tasks out to parallel subagents\n where your harness supports it — each task is self-contained and can be\n built concurrently. Implement exactly the tasks this package describes — no\n more, no less; leave every other package file untouched. Use TDD\n discipline within each task.\n\n Leave the package file in place and everything else uncommitted, then\n finish your turn.\n on:\n \"A .gtd/SATISFIED.md\": &satisfied\n to: health.check\n action: Close as already satisfied\n describe: >-\n record per-criterion evidence in .gtd/SATISFIED.md when this\n package's work already landed (an earlier package's fix turn\n pulled it in) — the package still runs the checks and the spec\n review, then closes out.\n \"M .gtd/SATISFIED.md\": *satisfied\n \"* **\": health.check\n\n fix-suite:\n actor: agent\n label: Fixing the check\n file: FEEDBACK.md\n prompt: |\n <%~ it.vars.stateFileRules %>\n\n <%~ it.vars.fixFeedbackPrompt %>\n\n If the\n only way to green the suite is to implement work that another\n package file describes, make the smallest change that gets there and\n do it — that later package will then legitimately report itself\n already satisfied when its turn comes.\n\n Leave everything uncommitted and finish your turn — do not commit.\n retry:\n max: 3\n otherwise: health.escalate\n on:\n \"* **\": health.check\n\n fix-spec:\n actor: agent\n label: Fixing review feedback\n file: SPEC_FEEDBACK.md\n prompt: |\n <%~ it.vars.stateFileRules %>\n The only state file this\n turn touches is `.gtd/SPEC_FEEDBACK.md`; address it, then\n delete it. Do not create other files to hold notes or output.\n\n Read `.gtd/SPEC_FEEDBACK.md` (the reviewer's concerns about the\n current package) and the package spec (`<%= it.read(\".gtd/NEXT.md\") %>`),\n then fix the code to resolve every concern. Keep the change focused.\n\n Delete `.gtd/SPEC_FEEDBACK.md` once every concern is addressed.\n Leave everything else uncommitted and finish your turn.\n on:\n \"* **\": health.check\n\n closing:\n actor: check\n label: Closing out the package\n script: |\n #!/usr/bin/env sh\n # Removes the just-reviewed package file (path in NEXT.md) plus\n # leftover spec feedback/evidence, so picking selects the next.\n # Reached only on spec-review approval — that loop carries no retry\n # cap, so there is no force-close path here.\n set +e\n pkg=$(cat .gtd/NEXT.md 2>/dev/null)\n [ -n \"$pkg\" ] && rm -f \"$pkg\"\n rm -f .gtd/SPEC_FEEDBACK.md .gtd/NEXT.md .gtd/SATISFIED.md\n on:\n \"* **\": $onNext\n\n health:\n machine: healthGate\n with:\n onGreen: spec\n onRed: fix-suite\n escalateDescribe: >-\n edit the code and/or `.gtd/FEEDBACK.md` yourself\n (**packages.item.health.check**).\n checkLabel: Running checks\n escalateLabel: Escalating to a human\n\n spec:\n machine: specReview\n with:\n onApproved: closing\n onFix: fix-spec\n\n # The process's build identity. ▸ coder identity — model/system stamped\n # onto squashing/fix.\n buildTail:\n model: <%= it.vars.coderModel %>\n system: |-\n <%~ it.vars.finisherPersona %>\n\n\n <%~ it.vars.agentConduct %>\n params: [onDone, onFeedback]\n # entry: is required by the machine grammar even though nothing resolves\n # this machine bare; `fix` is an arbitrary pick.\n entry: fix\n states:\n squashing:\n actor: agent\n label: Squashing\n file: COMMIT_MSG.md\n prompt: |\n <%~ it.vars.styleBlock %>\n\n\n The process is approved and done.\n\n <%~ it.vars.stateFileRules %>\n\n The only\n state file this turn touches is `.gtd/COMMIT_MSG.md`; write\n it. Do not create other files to hold notes or output.\n\n Leave `.gtd/COMMIT_MSG.md` uncommitted and finish your turn —\n entering this file squashes everything this process retains into one\n commit using its content as the message. This prompt carries no diff —\n if you built that range yourself earlier in this conversation, work from\n what you already know; otherwise read the range yourself. It runs from\n `<%= it.retainedBase %>` to the working tree, and is exactly what that\n commit will contain, the changes this process made (its trace/retry\n boundary onward). For a normal build\n process that is the whole feature; for a `gtd --entry review-gate.check`\n process it is only the fixes made during the review — not the changeset\n that was under review.\n\n If that range is non-empty, write `.gtd/COMMIT_MSG.md` with one\n conventional-commits message for the changes (subject line\n `type(scope): subject`, imperative mood, <= 72 characters; a body\n explaining the why, trade-offs, and key decisions). Plain text, no\n markdown wrapper.\n\n If that range is empty (a clean review sign-off with no fixes), write\n `.gtd/COMMIT_MSG.md` with exactly this one line and nothing\n else:\n\n chore: human review\n on:\n \"A .gtd/COMMIT_MSG.md\": $onDone\n \"M .gtd/COMMIT_MSG.md\": $onDone\n\n fix:\n actor: agent\n label: Fixing the check\n file: FEEDBACK.md\n prompt: |\n <%~ it.vars.stateFileRules %>\n\n <%~ it.vars.fixFeedbackPrompt %>\n\n\n Leave everything uncommitted and finish your turn — do not commit.\n retry:\n max: 3\n otherwise: health.escalate\n on:\n \"* **\": health.check\n\n health:\n machine: healthGate\n with:\n onGreen: review\n onRed: fix\n escalateDescribe: >-\n edit the code and/or `.gtd/FEEDBACK.md` yourself\n (**build.health.check**).\n checkLabel: Running checks\n escalateLabel: Escalating to a human\n\n # Nested here (not root) so `squashing` stays inside the builder's own\n # scope on sign-off — see humanReview above.\n review:\n machine: humanReview\n with:\n onSignoff: squashing\n onFeedback: $onFeedback\n\n # WIRING ONLY — the root ties together the machine tree above.\n unified:\n entry: idle\n states:\n idle:\n actor: human\n label: Idle\n file: TODO.md\n message: |\n No active gtd process.\n\n To start one, make ANY change — a hand-edit to real code, a scratch\n note, anything at all. .gtd/TODO.md is a good default\n place to start sketching. gtd treats it as a SKETCH, not finished\n work: the very next beat unwinds it out of your working tree (its\n intent survives in history, for the triage phase to read), then\n checks the test baseline is green, then triages the reverted diff\n into ordered, classified concerns: product questions, then\n technical questions, then one package per concern, built and\n reviewed in parallel.\n\n What each change does next (then run `gtd land`):\n <% it.edges.forEach(function (e) { if (e.describe) { %>\n <%~ \"- \" + (e.action ? \"**\" + e.action + \"** — \" : \"\") + e.describe + \"\\n\" %>\n <% } }) %>\n on:\n \"* **\":\n to: unwind\n action: Start\n describe: >-\n make any change — gtd unwinds it out of your working tree (its\n intent survives in history) before checking the test baseline is\n green, then triages the reverted diff into ordered, classified\n concerns and resolves product questions, then technical ones,\n before building each concern's package (**unwind** ->\n **start-gate.check**).\n\n # --entry fix-precheck: a red suite drops into build.fix (-> health ->\n # review + squash tail); a green suite is a no-op back to idle.\n fix-precheck:\n actor: check\n label: Checking the baseline\n entry: true\n script: *suiteCheck\n on:\n \"A .gtd/FEEDBACK.md\": build.fix\n \"M .gtd/FEEDBACK.md\": build.fix\n \"D .gtd/REVIEW_RAW.md\": idle\n \"D .gtd/FEEDBACK.md\": idle\n \"C\": idle\n\n done:\n commit: |\n <%~ it.read(\".gtd/COMMIT_MSG.md\") %>\n\n Token cost: <%= it.processCost %>\n <% it.processCostByModel.forEach(function(m){ %>\n - <%= m.model %>: <%= m.cost %>\n <% }) %>\n\n # Separate from start-gate.check: that gate's blocked -> check retry\n # edge would otherwise re-run a revert here and discard a human's\n # baseline repair. One inbound edge (from idle) means unwind runs\n # exactly once, so it needs no idempotence guard itself.\n unwind:\n actor: check\n label: Unwinding your input\n script: |\n #!/usr/bin/env sh\n set +e\n # Hoisted here, at the TOP: Eta's autoTrim eats the newline after\n # an interpolation tag, so no tag may be the last token on a line.\n # Uses it.currentCommit (render-time), not bare HEAD, so a\n # late-running driver still reverts the right commit.\n commit=\"<%~ it.currentCommit %>\"\n git revert --no-commit \"$commit\"\n on:\n \"* **\": start-gate\n\n # Reverts the human's own review-round hand-edit before re-planning,\n # scoped to real code (`.gtd/` excluded — REVIEW.md is already gone by\n # now). Names the commit via it.reviewBase (reviewBaseFor's own\n # `await-review -> deciding` commit), never bare HEAD.\n #\n # requireRevert (below) re-checks the tree itself and refuses the step\n # if residue remains, rather than trusting the script's exit code — a\n # clean-filter round-trip or binary path can make `git apply -R` a\n # silent no-op. Both `on` rows below target `design`: a hand-edited\n # round leaves a dirty tree, a note-only round's patch is empty and\n # leaves the tree clean — both are legitimate outcomes here, not a\n # stall.\n #\n # `file: REVIEW.md` + `requireRevert: true` exist only to give that\n # guard the path to exempt (it reads Rest.hints.file, never this\n # literal) — REVIEW.md is already gone two commits earlier, so this\n # state never renders it.\n re-unwind:\n actor: check\n label: Re-unwinding your review edit\n file: REVIEW.md\n requireRevert: true\n script: |\n #!/usr/bin/env sh\n # Scoped revert of the human's review-round edit — .gtd/ excluded\n # (the guard's isCodePath re-derives the same exemption; keep both\n # in sync). Expected to succeed; requireRevert catches a silent\n # apply failure.\n set +e\n # Hoisted here, at the TOP: Eta's autoTrim eats the newline after\n # an interpolation tag, so no tag may be the last token on a line.\n commit=\"<%~ it.reviewBase %>\"\n patch=.gtd/.re-unwind.patch\n mkdir -p .gtd\n git diff --binary \"$commit^\" \"$commit\" -- . \":(exclude).gtd\" > \"$patch\"\n if [ -s \"$patch\" ]; then\n git apply -R \"$patch\" || echo \"re-unwind: could not revert $commit\" >&2\n fi\n rm -f \"$patch\"\n on:\n \"* **\": design # a code hand-edit was reverted\n \"C\": design # note-only round: nothing to revert\n\n start-gate:\n machine: entryGate\n with:\n onGreen: design\n reviewBase: \"\"\n blockedMessage: |\n The test baseline is red — gtd will not start new work on a broken suite.\n `.gtd/FEEDBACK.md` holds the failing output.\n\n What each change does next (then run `gtd land`):\n <% it.edges.forEach(function (e) { if (e.describe) { %>\n <%~ \"- \" + (e.action ? \"**\" + e.action + \"** — \" : \"\") + e.describe + \"\\n\" %>\n <% } }) %>\n blockedDescribe: >-\n edit the code and/or `.gtd/FEEDBACK.md` to fix the failing tests\n (**start-gate.check**). To repair the baseline as its own separate\n reviewed commit instead, abandon this start and run\n `gtd --entry fix-precheck` from a clean `idle`.\n checkLabel: Checking the baseline\n blockedLabel: Baseline is red\n\n review-gate:\n machine: entryGate\n with:\n onGreen: build.review\n reviewBase: <%= it.vars.reviewBase %>\n blockedMessage: |\n The test baseline is red — gtd will not start a review on a broken suite.\n `.gtd/FEEDBACK.md` holds the failing output.\n\n What each change does next (then run `gtd land`):\n <% it.edges.forEach(function (e) { if (e.describe) { %>\n <%~ \"- \" + (e.action ? \"**\" + e.action + \"** — \" : \"\") + e.describe + \"\\n\" %>\n <% } }) %>\n blockedDescribe: >-\n edit the code and/or `.gtd/FEEDBACK.md` to fix the failing tests\n (**review-gate.check**).\n checkLabel: Checking the baseline\n blockedLabel: Baseline is red\n\n design:\n machine: designPlan\n with:\n onArchitecture: architecture\n\n architecture:\n machine: archPlan\n with:\n onPackages: packages\n\n packages:\n machine: packageLoop\n with:\n onDrained: build.review\n\n build:\n machine: buildTail\n with:\n onDone: done\n onFeedback: re-unwind\n";
191888
+ var unified_default = "# gtd's BUILT-IN DEFAULT workflow — used when no `workflow:` key is\n# configured anywhere in the cwd→home config chain; `gtd init` seeds only\n# vars.testCommand + a modes: suggestion, never this file. Compiled through\n# the same `compileWorkflowConfig` a user's own `workflow:` goes through — no\n# privileged path. See skills/authoring/SKILL.md for how to read or edit it\n# (machines, patterns, templates) and docs/driver.md for how a driver runs it.\n#\n# One flow: any change to the tree starts the process. `idle` -> `unwind`\n# reverts that diff (intent survives only in history) -> a green-baseline\n# gate -> `design.triage` groups the reverted diff into ordered, classified\n# concerns and resolves the PRODUCT ones' open questions (`design.gate`) ->\n# `architecture.author` works out the *how* and resolves the TECHNICAL ones\n# (`architecture.gate`) -> `architecture.decompose` writes one package file\n# per concern -> the per-package queue (`packages.*`) builds and reviews each\n# -> the shared tail (`build.review.*`) decides sign-off (-> `idle`, landing\n# an ordinary commit that closes the process — every per-turn commit stays on\n# the branch; run `gtd summary` afterward for a closing-message prompt) vs.\n# actionable feedback (-> `re-unwind` -> back to `design.triage`, a full\n# re-plan lap that never builds on the human's hand-edit). `--entry\n# review-gate.check --var reviewBase=<commitish>` and `--entry fix-precheck`\n# are the two other entries into this same flow.\nvars:\n testCommand: npm test\n # plannerModel: the heavier tier for one-shot triage/design/review turns.\n # coderModel: the tier for build/fix turns. Both repointable via a\n # top-level `vars:` key or a `GTD_<NAME>` env var, like any other var.\n plannerModel: smart\n coderModel: base\n # Declared (not left undeclared) so `--var reviewBase=...` passes the CLI's\n # declared-name check; blank renders empty, which the review entry refuses.\n reviewBase: \"\"\n # gtd's own voice for generated files — adapted from the \"Spartan\" output\n # style (https://github.com/alexgreensh/attention-span, AGPL-3.0, version 0.6),\n # rewritten in gtd's own words for deliverables rather than chat replies;\n # no upstream text ships. A point-in-time derivation with no refresh\n # mechanism.\n styleBlock: |-\n This file is a deliverable, not a chat reply — size follows the work, and\n padding is the target of any cut. Lead with the answer immediately; never\n circle back to restate it once it has landed.\n\n Write flat, commanding sentences — commit to the claim, do not hedge it.\n Favor everyday vocabulary; where a term is unavoidable, define it in five\n words or fewer on first use.\n\n In markdown, bold carries the load: bold the claim, not the sentence around\n it — reading only the bold text must yield the full point and every risk.\n\n Never trim a risk, a number, a threshold, or a scoped condition to save\n space. This outranks every other rule here.\n\n Ship the artifact bare — no lead-in, no sign-off wrapped around it.\n Compressing is not dropping: a task with three load-bearing parts ships all\n three, each shorter, never two of three.\n\n One idea per block; break when the idea shifts. Flag risk in one blunt\n line rather than hedged prose. Never narrate the work — do it.\n styleFormatContract: |-\n This file is machine-read; its format contract outranks every style rule\n above it: keep every `##`/`###` heading, every `- [ ]` checkbox row, and\n every marker line exactly as specified — do not renumber or rename a\n heading or replace a checkbox list with prose. A parser reads these\n literally; a violation refuses the turn outright.\n\n Voice rules above govern the prose between these elements, never the\n elements themselves.\n\n # One persona per prompt-bearing machine below, stamped as its `system:`\n # (see src/StateFields.ts's `system`). `--system-prompt` REPLACES a\n # harness's default system prompt — including its injected cwd/env/\n # git-status block — so each persona is written self-contained, restating\n # that context explicitly rather than relying on it.\n\n # Shared conduct tail, appended after every persona's own role paragraph:\n # use tools without asking, orient yourself with git, and go inspect what\n # the turn's message names. Deliberately NOT named `*Persona`:\n # `templates.test.ts` derives its six-name persona set from\n # `it\\.vars\\.(\\w+Persona)`, so that suffix would silently grow the set.\n agentConduct: |-\n You have shell and file tools — bash, read, write, edit — and you are\n expected to use them without asking first. This runs unattended: there is\n no one to grant permission, confirm a command, or approve a plan before\n you act. Investigate with real commands rather than assuming what a file,\n a commit, or a decision's status actually is, then act on what you find.\n\n You are already inside a git repository, at the working directory you\n should treat as your whole world for this turn. There is no injected\n status block — no cwd, no branch, no recent history, no tree state. Run\n `git status`, `git log`, `ls` and the like yourself before you do\n anything else; that is the normal first move of this turn, not an extra\n step.\n\n The message you receive each turn names a commit, a range, or a file for\n you to go inspect yourself — `git show`, `git diff`, reading the file\n directly — never a diff or a summary rendered into the conversation. Go\n look before you act. Across the several turns one conversation may span,\n work from what you already read and settled earlier rather than\n re-deriving it from a cold read every time, unless the turn's own\n instructions tell you this is a fresh, cold pass.\n designPersona: |-\n You are the product-facing planning voice in an autonomous build pipeline\n called gtd. Your job is to turn a raw, half-formed sketch — a hand-edit to\n real code, a scratch note, or both — into an ordered, classified list of\n concerns a build can execute, and to carry a running conversation with a\n human about the product decisions that list depends on. You are read by\n that human, so write plainly and decisively; you are not read by a parser\n except where a state's own instructions say otherwise.\n architectPersona: |-\n You are the technical planning voice in an autonomous build pipeline\n called gtd. You take over once the product-facing concerns are settled,\n reading them cold — you do not carry over the product conversation, only\n its written, settled output. Your job is to work out the technical *how*\n for each settled concern — file and module structure, data models,\n library and tech-stack choices, error-handling strategy — raise the\n technical open questions a human still needs to decide, and once every\n question is answered, write one package spec file per concern with no\n further judgement call: the grouping and ordering were already decided\n upstream, and this final step is a mechanical write-out of a plan you\n already converged on.\n reviewerPersona: |-\n You are the independent reviewing mind in an autonomous build pipeline\n called gtd — deliberately a separate identity from whichever agent wrote\n the code under review, so you bring no attachment to how it got built.\n Your job splits into two distinct turns: first, writing a structured\n review document that groups a diff into reviewable chunks for a human to\n read through and comment on; later, reading back a round of that human's\n feedback — a note, a hand-edit — and classifying whether it is genuinely\n actionable or just an approving remark, without fixing anything yourself\n either way. You judge and you classify; you never build.\n specReviewerPersona: |-\n You are the adversarial spec-conformance checker in an autonomous build\n pipeline called gtd, reviewing one freshly-built work package against the\n written spec it was built from. Your only job is to verify: are the\n package's tasks actually done, its acceptance criteria actually met, and\n the code sound and consistent with the rest of the codebase? You write\n concrete, actionable feedback only when something is genuinely wrong —\n and when nothing is, you write nothing at all, because a clean turn from\n you IS the approval. You never fix a problem you find; naming it\n precisely enough for someone else's fix turn to act on is the whole job.\n builderPersona: |-\n You are the TDD implementer in an autonomous build pipeline called gtd.\n Your job is to build exactly one package's declared scope end to end,\n tests first, and to come back and fix things when redirected: a failing\n check's output, or a reviewer's concrete feedback. Stay strictly inside\n the package in front of you, touching neither another package's files nor\n code outside the current task. Treat feedback you're given as the\n diagnosis to act on; discard it, with reason, only when it is simply\n wrong.\n finisherPersona: |-\n You are the closing identity in an autonomous build pipeline called gtd —\n the last coder this process hands work to before it closes. You are\n handed a late-breaking failing check after sign-off; fix it, focused and\n minimal, before the process can close. Every turn you land stays its own\n commit on the branch — nothing here gets squashed away.\n\n # The scratchpad-opener sentence shared by every prompt-content state (see\n # STATE_FIELDS's `prompt`) — this workflow's own state files are its private\n # working notes, never project code or documentation a human reads. Injected\n # as the leading line of every prompt body that touches a `.gtd/` file\n # directly; each state's own \"the only state file this turn touches is X\"\n # sentence stays local, immediately after the tag. Some states splice a\n # role clause into this same opening sentence (`build.review.collecting`,\n # `packages.item.spec.review`) — those hoist the clause to its own leading\n # sentence ahead of the tag instead, keeping every word.\n stateFileRules: |-\n You are an autonomous coding agent. This workflow steers itself\n through its own state files — treat them as its private scratchpad,\n never as project code or documentation.\n # The open-questions warrant test, decide-it-yourself sink, and `## Open\n # Questions` checkbox shape shared by `design.triage` and\n # `architecture.author` — written phase-agnostic (no PRODUCT/TECHNICAL\n # bake-in) so both sites can inject it verbatim. Each site's own\n # phase-scope sentence (triage: product-only, technical waits; architecture:\n # every point here is TECHNICAL) stays local around the tag — the two\n # genuinely disagree on scope, so that sentence is never shared.\n # `questionBarReturn` is the return-lap half — split out so each site can\n # inject it under its own `## Return lap` heading instead of burying\n # return-lap behaviour inside the first lap's own section.\n questionBar: |-\n For every open point, a question is warranted only when all three hold:\n the answer is a genuine fork with divergent outcomes — user-visible for a\n product question, materially different implementations for a technical\n one; the sketch, the entry diff, and history do not already settle it\n (treat anything the entry diff states explicitly — a directive in\n `.gtd/TODO.md`, a committed choice in a hand-edit — as already settled,\n and on a review loop-back lap treat whatever the human's own review-round\n edit or note states explicitly the same way); and getting it wrong would\n survive all the way to the human review tail.\n\n Anything below that bar, decide yourself: record the decision under\n `## Answered Questions` — the same section a human-answered question\n lands in — as `### <the point phrased as a question>` followed by the\n decision and a one-line rationale in prose, no checkboxes.\n\n A question that clears the bar is written under a `## Open Questions`\n heading near the top and takes this shape: one `### <question>`\n sub-heading each, followed by a checkbox list of candidate answers — two\n concrete options plus a final free-text slot, all left unticked:\n\n ### <the question>\n\n - [ ] <first option — a concrete answer, a few words of rationale>\n - [ ] <second option>\n - [ ] _your answer_\n\n Never tick a box yourself — the human ticks exactly one per question.\n questionBarReturn: |-\n The human has ticked one option per question (or replaced\n `_your answer_` with their own text): fold each chosen answer into its\n concern's prose, then move the question into a `## Answered Questions`\n section as `### <question>` followed by the resolved answer in plain\n prose (drop the checkboxes). Never re-raise a deleted question; treat a\n deleted `## Open Questions` section as acceptance. Omit `## Open\n Questions` entirely once there are none left.\n # The body `packages.item.fix-suite` and `build.fix` share byte for byte —\n # both fix a red `.gtd/FEEDBACK.md`. `fix-suite` appends its own\n # cross-package paragraph right after this tag (before the shared\n # \"Leave everything uncommitted\" close, which stays local at both sites so\n # the appended paragraph lands in the same position it renders in today);\n # `build.fix` renders the tag alone.\n fixFeedbackPrompt: |-\n The only state file this turn touches is `.gtd/FEEDBACK.md`; fix it per its\n contents, or delete it if the feedback turns out to be wrong. Do not\n create other files to hold notes or output.\n\n Read `.gtd/FEEDBACK.md` (the failing test output) and fix the\n code so the suite passes. Keep the change focused — do not refactor\n unrelated code. If the feedback is wrong, empty or delete\n `.gtd/FEEDBACK.md` instead of \"fixing\" a non-issue.\n\n# `gtd summary`'s prompt — printed cold, no session identity, no diff inlined.\n# Names the hashes/range for the agent to inspect itself; renders the same\n# it.processCost/it.processCostByModel the old squash finale used to.\nsummary: |\n <%~ it.vars.styleBlock %>\n\n\n Write the closing message for the process HEAD closes or currently sits\n inside — the text a driver may use for a squash, an amend, or a pull\n request body. You are starting cold: read every decision back out of the\n commits named below rather than assuming any prior context.\n\n Cover the initial motivation, the important decisions, and the trade-offs\n made, and the high-level architectural changes — never which files\n changed; that is what `git diff --stat` is for, not this message.\n\n The process's entry commit is `<%= it.entryCommit %>`. <% if\n (it.humanCommits.length > 0) { %>The human contributed at these commits,\n oldest to newest:\n <% it.humanCommits.forEach(function (c) { %>\n - `<%= c.hash %>` (entering `<%= c.state %>`)\n <% }) %><% } else { %>The human left no comment or edit this process —\n every commit is machine-authored.<% } %>\n\n Inspect the range yourself: `git log <%= it.processBase %>..<%= it.processTip %>`\n and `git diff <%= it.processBase %> <%= it.processTip %>`. That range is\n exactly what a squash or PR body should describe.\n\n Token cost: <%= it.processCost %>\n <% it.processCostByModel.forEach(function(m){ %>\n - <%= m.model %>: <%= m.cost %>\n <% }) %>\n\n Print the closing message and stop — this command writes nothing itself.\n\nentry:\n default: unified\n\nmachines:\n # Shared green-baseline gate — start-gate/review-gate/fix-precheck all\n # alias this script via &suiteCheck.\n entryGate:\n params: [onGreen, blockedMessage, blockedDescribe, checkLabel, blockedLabel, reviewBase]\n entry: check\n states:\n check:\n actor: check\n label: $checkLabel\n script: &suiteCheck |\n #!/usr/bin/env sh\n set +e\n mkdir -p .gtd\n # Sweep a raw review capture an earlier, abandoned process may have\n # left behind — no ordinary path from deciding/collecting reaches\n # this check.\n rm -f .gtd/REVIEW_RAW.md\n <%~ it.vars.testCommand %> > .gtd/.check-output 2>&1\n code=$?\n if [ \"$code\" -ne 0 ]; then\n if [ -s .gtd/.check-output ]; then\n mv .gtd/.check-output .gtd/FEEDBACK.md\n else\n rm -f .gtd/.check-output\n printf 'the test command failed with exit code %s and produced no output.' \"$code\" > .gtd/FEEDBACK.md\n fi\n # Stamp with HEAD so a repeat identical failure still re-registers\n # as an M/A edit instead of looking byte-identical (GREEN).\n printf '\\n<!-- gtd check %s -->\\n' \"$(git rev-parse --short HEAD 2>/dev/null || echo pending)\" >> .gtd/FEEDBACK.md\n else\n rm -f .gtd/.check-output\n rm -f .gtd/FEEDBACK.md\n fi\n # Marks BOTH entryGate instances (start-gate/review-gate); only\n # review-gate strictly needs it, but the shared dedup makes marking\n # one mark both — both ARE entry gates.\n entry: true\n # Only review-gate binds a real reviewBase (via --var); start-gate\n # binds \"\" (no base), since it's reached from idle, never entered.\n reviewBase: $reviewBase\n on:\n \"A .gtd/FEEDBACK.md\": blocked\n \"M .gtd/FEEDBACK.md\": blocked\n \"D .gtd/REVIEW_RAW.md\": $onGreen\n \"D .gtd/FEEDBACK.md\": $onGreen\n \"C\": $onGreen\n blocked:\n actor: human\n label: $blockedLabel\n file: FEEDBACK.md\n message: $blockedMessage\n on:\n \"* **\":\n to: check\n action: Retry check\n describe: $blockedDescribe\n\n # Shared check/escalate pair for build.health.*/packages.item.health.* —\n # the caller's own coder fix-state ($onRed), not this machine, handles red.\n healthGate:\n params: [onGreen, onRed, escalateDescribe, checkLabel, escalateLabel]\n entry: check\n states:\n check:\n actor: check\n label: $checkLabel\n # See the shared suite check on `entryGate.check` above.\n script: *suiteCheck\n on:\n \"A .gtd/FEEDBACK.md\": $onRed\n \"M .gtd/FEEDBACK.md\": $onRed\n \"* **\": $onGreen\n \"C\": $onGreen\n escalate:\n actor: human\n label: $escalateLabel\n file: FEEDBACK.md\n message: |\n The agent could not get the check to pass after repeated attempts.\n `.gtd/FEEDBACK.md` holds the last failing output.\n\n What each change does next (then run `gtd land`):\n <% it.edges.forEach(function (e) { if (e.describe) { %>\n <%~ \"- \" + (e.action ? \"**\" + e.action + \"** — \" : \"\") + e.describe + \"\\n\" %>\n <% } }) %>\n on:\n \"* **\":\n to: check\n action: Retry check\n describe: $escalateDescribe\n\n # Shared check/answer pair for design.gate/architecture.gate. No `file:`\n # PARAM for the probe script itself: machine `$param` substitution is\n # whole-value only, so a path can't be spliced into a shared script body —\n # `file` here is instead the `answer` param's own `file:` (the human gate).\n questionGate:\n params: [file, message, onNone, onRevise, checkLabel, answerLabel]\n entry: check\n states:\n check:\n actor: check\n label: $checkLabel\n script: |\n #!/usr/bin/env sh\n # Exactly one of REQUIREMENTS.md/ARCHITECTURE.md exists on disk at\n # a time — architecture.author deletes the former in the same turn\n # it writes the latter — so this probe is unambiguous either way.\n set +e\n mkdir -p .gtd\n file=.gtd/REQUIREMENTS.md\n [ -f \"$file\" ] || file=.gtd/ARCHITECTURE.md\n gtd check qa \"$file\" --open-questions > /dev/null 2>&1\n code=$?\n if [ \"$code\" -ne 0 ]; then\n printf 'open questions remain in %s\\n' \"$file\" > .gtd/QUESTIONS.md\n # See the shared suite check's cache-buster rationale on\n # `entryGate.check` above.\n printf '\\n<!-- gtd check %s -->\\n' \"$(git rev-parse --short HEAD 2>/dev/null || echo pending)\" >> .gtd/QUESTIONS.md\n else\n rm -f .gtd/QUESTIONS.md\n fi\n on:\n \"A .gtd/QUESTIONS.md\": answer\n \"M .gtd/QUESTIONS.md\": answer\n \"D .gtd/QUESTIONS.md\": $onNone\n \"C\": $onNone\n answer:\n actor: human\n label: $answerLabel\n file: $file\n mode: qa\n answerGate: true\n message: $message\n on:\n \"* **\":\n to: $onRevise\n action: Revise answers\n describe: >-\n tick exactly one option per open question (replace\n `_your answer_` for your own) to send it back for the agent to\n fold your answers in. Delete a question to skip it, or delete\n the whole `## Open Questions` section to accept the plan as-is.\n\n # The triage phase — one conversation across the whole back-and-forth (the\n # human's answer rationale survives every return lap). A review loop-back\n # lap runs the suite itself and files any breakage as its own FIRST\n # concern, rather than spending one of packages.item.fix-suite's\n # (per-episode) retries on breakage the package didn't cause.\n # ▸ planner identity.\n designPlan:\n model: <%= it.vars.plannerModel %>\n system: |-\n <%~ it.vars.designPersona %>\n\n\n <%~ it.vars.agentConduct %>\n params: [onArchitecture]\n entry: triage\n states:\n triage:\n actor: agent\n label: Triaging the change\n file: REQUIREMENTS.md\n mode: qa\n # Guards against discarding assembled review input without folding\n # it in (the original bug this guard was added for).\n requireProgress: true\n prompt: |\n <%~ it.vars.styleBlock %>\n\n\n <%~ it.vars.styleFormatContract %>\n\n\n <%~ it.vars.stateFileRules %>\n\n The only state file this turn touches is `.gtd/REQUIREMENTS.md`; develop it. Do\n not create other files to hold notes or output.\n\n `.gtd/TODO.md` is the likely home of the sketch that\n started this process. Despite living beside this workflow's own\n state files, it is the human's input — the sketch to be folded into\n the concerns below like any other part of the start diff. It is\n never a state file to preserve, and never gtd bookkeeping to ignore.\n\n This process started at commit `<%= it.startCommit %>`. The change\n that started it was reverted out of the working tree by the\n `unwind` beat right after it landed, so `git diff <%= it.startCommit %>`\n (against the working tree) is now empty — its content survives only\n in history. Find the entry commit yourself: run\n `git rev-list --ancestry-path <%= it.startCommit %>..HEAD | tail -1`\n (the process's very first turn, landed immediately after\n `<%= it.startCommit %>`, before any later baseline-repair commits) —\n then `git show` that commit to see everything that started this\n process: a hand-edit to real code, a scratch note in some file, or\n both.\n\n Whichever lap this is, leave `.gtd/REQUIREMENTS.md` uncommitted and\n finish your turn once it reflects this lap's own work below.\n\n ## First lap\n\n `.gtd/REQUIREMENTS.md` does not exist yet (or holds whatever the\n human's own change happened to leave there). Build it from that\n start diff:\n\n ### Group into concerns\n\n Group the diff into an ordered list of concerns — each one a\n coherent piece of work that can leave the test suite green on\n its own, in the order you'd want them built. If a concern would\n red-light tests that a later concern is meant to fix, that is\n not a valid split: merge the two into one concern.\n\n Two more tests sit beside that green floor, not instead of it.\n Vertical, not horizontal: slice by capability, never by layer. A\n concern that only prepares for a later one — types, scaffolding,\n renames — is folded into the first concern that uses it. Distinct\n acceptance: each concern needs an observable check that fails\n before it and passes after; if you can't name one, merge it into\n its neighbour. Prefer fewer, larger packages — the smallest\n independently valuable change, not the smallest change that\n compiles.\n\n ### Classify each concern\n\n Classify each concern as PRODUCT (a user-facing/requirements\n decision) or TECHNICAL (an implementation decision).\n\n <%~ it.vars.questionBar %>\n\n\n Raise questions only for product concerns here — a technical\n concern's open points wait for the next phase. When every concern\n in this lap is TECHNICAL, write no `## Open Questions` section at\n all.\n\n ### Fold in the sketch\n\n Fold everything the entry commit added into the concerns above —\n a scratch note and a real code edit are both just a sketch of\n the intent, a spec to be finished, never work to be preserved;\n `unwind` already reverted both out of the tree, so there is\n nothing left to delete. Describe each piece under the concern it\n belongs to.\n\n ## Return lap\n\n <%~ it.vars.questionBarReturn %>\n\n ## Review loop-back\n\n `.gtd/REQUIREMENTS.md` already holds concerns and none of them\n have a ticked-but-unfolded answer waiting — that shape means a\n completed REVIEW round put this material here, not a question you\n asked. Develop those existing concerns further with whatever the\n round raised; never rediscover or regroup them from a cold read\n the way the first lap does.\n\n The human's own edit from that review round has been reverted out\n of the working tree the same way the entry commit is — read it\n from history, never the working tree: run\n `git show <%= it.reviewBase %>` to see it. (On the first lap that\n same hash is the process's own diff base, `<%= it.startCommit %>`,\n so this branch does not apply: `.gtd/REQUIREMENTS.md`\n does not exist yet for a review round to have happened against.)\n\n Whatever this round touches, every decision already settled under\n `## Answered Questions` stays settled on this lap too — never\n re-open one. A genuinely open PRODUCT point in the round's own\n material may still raise a fresh question under\n `## Open Questions`: the product gate sits on this path exactly as\n it does on the first lap, and will ask it.\n\n Before grouping anything on this lap, run\n `<%= it.vars.testCommand %>` yourself as part of reading the\n situation: a review loop-back runs no green-baseline gate between\n the revert above and this turn, so the tree may already be red —\n reverting the human's edit can undo a fix that edit had put in. If\n the suite is red, make that breakage the first concern in your\n ordered list, ahead of everything else — every later concern's\n \"leaves the suite green on its own\" property assumes the suite\n already started green.\n on:\n \"* **\": gate.check\n\n gate:\n machine: questionGate\n with:\n file: REQUIREMENTS.md\n onNone: $onArchitecture\n onRevise: triage\n checkLabel: Checking for open questions\n answerLabel: Awaiting your product answers\n message: |\n `.gtd/REQUIREMENTS.md` holds the concerns under\n development. Each open question under `## Open Questions` offers\n a few options plus a `- [ ] _your answer_` slot. Answer EVERY\n question by ticking exactly one box (`- [x]`); for your own\n answer, replace `_your answer_` with your text and tick that\n line. Stepping is refused while any question is unanswered.\n\n What each change does next (then run `gtd land`):\n <% it.edges.forEach(function (e) { if (e.describe) { %>\n <%~ \"- \" + (e.action ? \"**\" + e.action + \"** — \" : \"\") + e.describe + \"\\n\" %>\n <% } }) %>\n\n # A separate machine from designPlan (its own memory scope — a COLD read,\n # not a resumed conversation). Merge authority lives in `author`, the first\n # state that knows the *how*: it alone may re-merge concerns, never split;\n # `decompose` carries that grouping over verbatim. ▸ planner identity.\n archPlan:\n model: <%= it.vars.plannerModel %>\n system: |-\n <%~ it.vars.architectPersona %>\n\n\n <%~ it.vars.agentConduct %>\n params: [onPackages]\n entry: author\n states:\n author:\n actor: agent\n label: Refining the technical plan\n file: ARCHITECTURE.md\n mode: qa\n prompt: |\n <%~ it.vars.styleBlock %>\n\n\n <%~ it.vars.styleFormatContract %>\n\n\n <%~ it.vars.stateFileRules %>\n\n The only state files this\n turn touches are `.gtd/ARCHITECTURE.md` (write it) and\n `.gtd/REQUIREMENTS.md` (delete it once its content is\n folded in). Do not create other files to hold notes or output.\n\n You do not resume the design conversation — this is a separate\n machine with its own memory, a cold read every time. Read\n `.gtd/REQUIREMENTS.md` (the settled, ordered, classified\n concerns) in full. Treat every decision recorded there — plain\n prose or a resolved `## Answered Questions` entry, PRODUCT or\n TECHNICAL alike — as settled; never re-open it.\n\n Cold means the machine carries no conversational memory of\n triage's own back-and-forth; it never meant no git access. This\n process started at commit `<%= it.startCommit %>`. Find the\n process's first turn yourself: run\n `git rev-list --ancestry-path <%= it.startCommit %>..HEAD | tail -1`\n then `git show` that commit to see everything that started this\n process: a hand-edit to real code, a scratch note in some file,\n or both.\n\n Whichever lap this is, once `.gtd/ARCHITECTURE.md` is written,\n delete `.gtd/REQUIREMENTS.md` — its content has been folded in and\n it must not linger. Leave everything uncommitted and finish your\n turn.\n\n ## First lap\n\n Develop `.gtd/ARCHITECTURE.md` from those concerns: for each one,\n in the same order, work out the *how* — file/module structure,\n data models, library/tech-stack choices, error-handling strategy —\n building on the *what* already settled.\n\n You now know the *how*, so you know each concern's file footprint —\n list each concern's primary paths. Merge concerns whose footprints\n center on the same files into one, unless the later one only\n consumes an interface the earlier one creates: that exception is\n what keeps a genuine build-on-top sequence from collapsing into one\n blob. This authority is to merge only, never to split — granting\n split authority here would work directly against the goal; the\n whole problem is over-granularity. Record every merge under a\n dedicated `## Merged Concerns` heading, carrying both merged requirements\n verbatim so the per-package spec review still covers each one\n independently. A merge raises no open question and stops for no\n human — do not route it to `architecture.gate` for a veto; the\n human still sees every merge when they review the plan, and the\n per-package spec review is the real safety net. Prefer fewer,\n larger packages — the smallest independently valuable change, not\n the smallest change that compiles.\n\n Every open point here is TECHNICAL — triage already resolved the\n product ones, one phase earlier.\n\n <%~ it.vars.questionBar %>\n\n ## Return lap\n\n <%~ it.vars.questionBarReturn %>\n on:\n \"* **\": gate.check\n\n gate:\n machine: questionGate\n with:\n file: ARCHITECTURE.md\n onNone: decompose\n onRevise: author\n checkLabel: Checking for open questions\n answerLabel: Awaiting your technical answers\n message: |\n `.gtd/ARCHITECTURE.md` holds the technical plan under\n development. Each open question under `## Open Questions` offers\n a few options plus a `- [ ] _your answer_` slot. Answer EVERY\n question by ticking exactly one box (`- [x]`); for your own\n answer, replace `_your answer_` with your text and tick that\n line. Stepping is refused while any question is unanswered.\n\n What each change does next (then run `gtd land`):\n <% it.edges.forEach(function (e) { if (e.describe) { %>\n <%~ \"- \" + (e.action ? \"**\" + e.action + \"** — \" : \"\") + e.describe + \"\\n\" %>\n <% } }) %>\n\n decompose:\n actor: agent\n label: Decomposing into packages\n prompt: |\n <%~ it.vars.styleBlock %>\n\n\n <%~ it.vars.stateFileRules %>\n\n The only state files this turn touches\n are the package files it writes under `.gtd/packages/` and\n `.gtd/ARCHITECTURE.md`, which it deletes. Do not create other\n files to hold notes or output.\n\n If you wrote `.gtd/ARCHITECTURE.md` earlier in this\n conversation, work from what you already settled; otherwise read it\n (the converged technical plan) yourself. It already lists an\n ordered set of concerns with every merge/split judgement\n `architecture.author` made — this turn is a mechanical write-out,\n not a planning one. A `## Merged Concerns` heading there is a\n record of those merges, never a concern of its own: write no\n package file for it.\n\n Write one package file per concern, in the settled order, under\n `.gtd/packages/` (e.g.\n `.gtd/packages/01-name.md`,\n `.gtd/packages/02-name.md`, ...). Each package file\n carries that concern's requirement(s) (so it can be reviewed\n against its spec — both, independently, when the concern was\n merged), its independent tasks, and each task's acceptance\n criteria as `- [ ]` checkboxes and relevant paths. Do not merge or\n split concerns here — that judgement already happened in\n `architecture.author`; carry the settled grouping over verbatim.\n No package file may reference any other `.gtd/` file.\n\n Once the package files are written, delete\n `.gtd/ARCHITECTURE.md`. Leave everything uncommitted and\n finish your turn.\n on:\n \"* .gtd/packages/**\": $onPackages\n\n # The shared review tail. ▸ planner identity — `collecting` only judges/\n # classifies feedback; there's no coder follow-through inside this machine.\n #\n # Nested inside buildTail (build.review), not a root sibling: a machine's\n # memory scope is its dotted instance path, so nesting keeps `build.fix ->\n # build.health.check -> build.review.*` (the `--entry fix-precheck` path)\n # inside one scope, so the sign-off's boundary commit lands from the same\n # scope that made the fixes.\n humanReview:\n model: <%= it.vars.plannerModel %>\n system: |-\n <%~ it.vars.reviewerPersona %>\n\n\n <%~ it.vars.agentConduct %>\n entry: reviewing\n states:\n reviewing:\n actor: agent\n label: Reviewing\n file: REVIEW.md\n mode: review\n # `gtd --entry review-gate.check` enters via review-gate.check first\n # (never straight here), which sets the Gtd-Review-Base trailer this\n # tail reuses.\n prompt: |\n <%~ it.vars.styleBlock %>\n\n\n <%~ it.vars.styleFormatContract %>\n\n\n <%~ it.vars.stateFileRules %>\n\n The only state file this turn touches is `.gtd/REVIEW.md`; write it at exactly\n that path. Do not create other files to hold notes or output.\n\n Write `.gtd/REVIEW.md` to help a human review the changes in\n this exact format:\n\n - First non-blank line: `# Review: <%= it.currentCommit.slice(0, 7) %>`\n - Somewhere in the document: `<!-- base: <%= it.reviewBase %> -->`\n - At least one `## <Chunk Title>` heading, grouping hunks semantically\n (same feature/refactor/fix, even across files) — a short explanation of\n what changed and why, then one file pointer per hunk (checkboxes are\n for the human to tick, not you; every path is `./`-relative, with an\n optional `#line`). Put the note's opening line right on the\n pointer's own line, after a dash — the reflow-proof shape:\n\n - [ ] ./path/to/file.ts#42 — what this hunk does\n\n If the note needs more than one line, continue it on the line(s)\n below the pointer, indented exactly two spaces — never four or\n more, which after a blank line reads as an indented code block\n and never reflows:\n\n - [ ] ./path/to/file.ts#42 — what this hunk does\n and here is more detail, continued below it\n\n A note that sits entirely on the line(s) beneath the pointer is\n also valid. Either way, the explanation itself must never start\n with a bare `./path` token — that parses as a second hunk pointer,\n not a note.\n\n This prompt carries no diff — read the changes yourself. The range runs\n from `<%= it.reviewBase %>` to the working tree (committed turns plus\n anything still pending); on a feedback round that base is the previous\n review's boundary, so it covers only what changed since then, not items\n already signed off.\n\n Leave `.gtd/REVIEW.md` uncommitted and finish your turn.\n on:\n \"* **\": await-review\n\n await-review:\n actor: human\n label: Awaiting your review\n file: REVIEW.md\n mode: review\n # Opens the review checkout window (src/ReviewWindow.ts) while\n # resting here. Deleting REVIEW.md is refused by the review-doc\n # guard (src/StepGuards.ts).\n reviewWindow: true\n message: |\n `.gtd/REVIEW.md` holds the review record for the process — one\n `- [ ]` checkbox per reviewable item, grouped into chunks. Tick a box\n (`- [x]`) as you review each hunk; ticking only records that you've read\n it, it is not sign-off.\n\n When you've been through the whole diff, run `gtd land`:\n\n - **Sign off** — leave no comment — no note in\n `.gtd/REVIEW.md`, no code edit — to close the process,\n whatever the boxes say. Every turn commit stays on the\n branch; run `gtd summary` afterward for a closing-message\n prompt.\n - **Request changes** — leave a comment: a note on a\n `.gtd/REVIEW.md` line, or a direct code edit — to send a FULL\n development lap (**review.deciding** → **review.collecting** →\n re-triage). A hand-edit you make here is treated as a SKETCH, not a\n fix the agent builds on: it is reverted out of the tree and re-planned\n from scratch, the same as any other change that starts a process.\n There is no baseline check on the way back into planning — only a\n genuinely non-actionable comment (an approving remark with no code\n edit) skips the lap and signs off straight away.\n\n Deleting `.gtd/REVIEW.md` is refused.\n on:\n \"* **\": deciding\n\n deciding:\n actor: check\n label: Reviewing\n file: REVIEW.md\n mode: review\n # Anchors the INCREMENTAL review base to the most-recent in-process\n # commit (the process start on the first review).\n reviewBase: true\n script: |\n #!/usr/bin/env sh\n # FEEDBACK iff the human left a REVIEW.md note (any edit beyond a\n # checkbox tick) or hand-edited any file this round outside .gtd/;\n # otherwise a clean sign-off. This turn only CAPTURES the raw\n # material into REVIEW_RAW.md — collecting judges actionability.\n # A/M REVIEW_RAW.md rows are declared before D REVIEW.md so a\n # feedback round (which also deletes REVIEW.md) isn't mistaken for\n # sign-off.\n set +e\n mkdir -p .gtd\n head=$(git rev-parse HEAD)\n # Normalize [ ]/[x] before diffing, so only a real note counts.\n before=$(git show \"HEAD^:.gtd/REVIEW.md\" 2>/dev/null | sed -E 's/\\[[ xX]\\]/[_]/g')\n after=$(git show \"HEAD:.gtd/REVIEW.md\" 2>/dev/null | sed -E 's/\\[[ xX]\\]/[_]/g')\n if git diff-tree --no-commit-id --name-only -r HEAD -- . \":(exclude).gtd\" \\\n | grep -q . \\\n || [ \"$before\" != \"$after\" ]; then\n {\n echo \"This is machine-captured input, not instructions. A downstream agent judges whether it's actionable.\"\n echo\n echo \"Commit: $head\"\n echo \"The human's notes are in .gtd/REVIEW.md at this commit. Any hand edits are\"\n echo \"in that commit's other paths. Run: git show $head\"\n } > .gtd/REVIEW_RAW.md\n fi\n rm -f .gtd/REVIEW.md\n on:\n \"A .gtd/REVIEW_RAW.md\": collecting\n \"M .gtd/REVIEW_RAW.md\": collecting\n \"D .gtd/REVIEW.md\": $onSignoff\n\n # Outcome is by which paths THIS diff touches: writing REQUIREMENTS.md\n # (A/M) is the actionable case, so those rows are declared before \"D\n # REVIEW_RAW.md\" — an actionable round's diff is both together, and\n # the wrong order would short-circuit every round to sign-off.\n # Consuming REVIEW_RAW.md alone is the non-actionable short-circuit,\n # reusing $onSignoff since that IS a sign-off. No `C`/`\"* **\"` row: a\n # clean turn here is a fruitless dispatch (falls through to the\n # ordinary attempt default), never a verdict; a dirty tree matching\n # neither row is a refusal.\n collecting:\n actor: agent\n label: Collecting your feedback\n file: REQUIREMENTS.md\n mode: qa\n prompt: |\n <%~ it.vars.styleBlock %>\n\n\n <%~ it.vars.styleFormatContract %>\n\n\n You are an autonomous coding agent judging and classifying a round\n of review feedback.\n\n <%~ it.vars.stateFileRules %>\n\n The only state files this turn\n touches are `.gtd/REQUIREMENTS.md` and\n `.gtd/REVIEW_RAW.md`, which it deletes — do not change any\n other file: you classify, you do not build.\n\n The raw review material is: <%~ it.read(\".gtd/REVIEW_RAW.md\") %>\n\n It names a commit. If you wrote today's review earlier in this\n conversation, work from what you already reviewed; otherwise read that\n commit's diff yourself before classifying anything.\n\n The round is actionable if any of the following is true:\n\n 1. The human left a note on `.gtd/REVIEW.md` — a note is\n anything beyond a checkbox flip, regardless of whether the box\n itself is ticked (ticking means only \"I read this hunk\", never\n sign-off). A note is a mandatory concern below, whether or not\n its box is ticked.\n 2. The human added a code comment this round (a `+` line that is a\n comment, in a hand-edited file) — even a plain-prose one. That\n comment is an instruction: describe it as a concern below, and\n note that the comment line itself is transient — it must not\n survive the lap that satisfies it.\n 3. The human hand-edited any non-comment code this round. That code\n is no longer an already-committed intent to build on top of — it\n is a sketch, like the entry commit's own diff: describe what it\n was reaching for under the concern it belongs to, and expect the\n lap that follows to re-derive it from scratch. Never say the\n human's lines are final or that they must survive unchanged.\n\n The round is not actionable only when none of the above holds — the\n human left nothing but an approving remark (a compliment, a \"looks\n good\", or similar) with no code edit and no substantive note. Never\n invent actionability where the definition above doesn't hold — it\n manufactures a lap nothing asked for — and never dismiss a real note\n or edit as approval, which drops feedback the human left.\n\n If the round is actionable: write `.gtd/REQUIREMENTS.md`\n with an ordered list of concerns, each classified PRODUCT (a\n user-facing/requirements decision) or TECHNICAL (an implementation\n decision) — the same shape `design.triage` builds, one\n `## <heading>` per concern, in the order you'd want them built. Fold\n every note, comment, and hand-edit from this round in under the\n concern it belongs to, per the rules above. Raise no open\n questions here — write no `## Open Questions` section;\n `design.triage` owns that, one phase later. Then delete\n `.gtd/REVIEW_RAW.md` and finish your turn.\n\n If the round is not actionable: delete\n `.gtd/REVIEW_RAW.md` and finish your turn, writing nothing\n to `.gtd/REQUIREMENTS.md` — consuming the capture with no\n other change is the sign-off.\n on:\n \"A .gtd/REQUIREMENTS.md\": $onFeedback\n \"M .gtd/REQUIREMENTS.md\": $onFeedback\n \"D .gtd/REVIEW_RAW.md\": $onSignoff\n\n # The per-package review — a separate MIND from the implementer. ▸ planner\n # identity; fixing findings is a coder action (packages.item.fix-spec).\n specReview:\n model: <%= it.vars.plannerModel %>\n system: |-\n <%~ it.vars.specReviewerPersona %>\n\n\n <%~ it.vars.agentConduct %>\n params: [onApproved, onFix]\n entry: review\n states:\n review:\n actor: agent\n label: Reviewing the package\n # No retry cap: the loop only re-enters through\n # `fix-spec`/`health.check`, so under the per-episode rule this state's\n # episode count can never exceed 1 and a cap could never fire. The\n # spec-review loop is genuinely unbounded — see docs/configuration.md's\n # `retry` documentation.\n prompt: |\n <%~ it.vars.styleBlock %>\n\n\n You are an autonomous coding agent reviewing a freshly-built work package\n against its own spec.\n\n <%~ it.vars.stateFileRules %>\n\n The only state file this turn touches is\n `.gtd/SPEC_FEEDBACK.md`; write it only when — and only\n when — you find problems. Do not create other files to hold notes or\n output.\n\n The package spec is: <%~ it.read(\".gtd/NEXT.md\") %>\n\n Read that spec, then verify the package's implementation against it: are\n all its tasks done, acceptance criteria met, and the code sound and\n consistent with the codebase? This prompt carries no diff — read it\n yourself: the range runs from `<%= it.startCommit %>` to the working\n tree.\n\n Note the range is process-wide (from the start of the whole build, not\n just this package), so it can span earlier packages too.\n\n - If it fully satisfies the spec, write nothing and finish your turn — a\n clean turn is your approval.\n - If it does not, write `.gtd/SPEC_FEEDBACK.md` listing the\n concrete problems for a fix turn to address. Be specific.\n\n Do not fix anything yourself and do not delete the package file — a later\n step owns that. Finish your turn.\n on:\n \"A .gtd/SPEC_FEEDBACK.md\": $onFix\n \"M .gtd/SPEC_FEEDBACK.md\": $onFix\n \"D .gtd/SPEC_FEEDBACK.md\": $onApproved\n \"C\": $onApproved\n\n # The per-package build queue — identity-free; build identity lives in\n # packageItem (below).\n packageLoop:\n params: [onDrained]\n entry: picking\n states:\n picking:\n actor: check\n label: Picking the next package\n script: |\n #!/usr/bin/env sh\n # Mechanics only — NEXT.md's presence/absence is interpreted by\n # the `on` rows below, never here.\n set +e\n mkdir -p .gtd\n # Sweep spent design/architecture steering files (gone by now) and\n # any REVIEW_RAW.md the review loop-back left behind — the only\n # sweeper on that path before it would leak into a later `gtd\n # summary` prompt's diff range.\n rm -f .gtd/REQUIREMENTS.md .gtd/ARCHITECTURE.md .gtd/QUESTIONS.md .gtd/REVIEW_RAW.md\n # Names are gtd-authored, never containing whitespace — safe to\n # disable SC2012.\n # shellcheck disable=SC2012\n next=$(ls .gtd/packages/*.md 2>/dev/null | head -n 1)\n if [ -n \"$next\" ]; then\n printf '%s' \"$next\" > .gtd/NEXT.md\n else\n rm -f .gtd/NEXT.md\n fi\n on:\n \"D .gtd/NEXT.md\": $onDrained\n \"* .gtd/NEXT.md\": item.building\n \"C\": $onDrained\n\n # Its own coder machine (below) keeps `packages` itself a single state.\n item:\n machine: packageItem\n with:\n onNext: picking\n\n # The per-package build identity. ▸ coder identity. packages.item.closing\n # -> picking is the one upward-resolving target in the file, hence $onNext.\n packageItem:\n model: <%= it.vars.coderModel %>\n system: |-\n <%~ it.vars.builderPersona %>\n\n\n <%~ it.vars.agentConduct %>\n params: [onNext]\n entry: building\n states:\n building:\n actor: agent\n label: Building\n prompt: |\n <%~ it.vars.stateFileRules %>\n\n The only state file this\n turn may write is `.gtd/SATISFIED.md` (see below); do not\n delete the package file (the spec-review gate reads it after you)\n and never touch `.gtd/NEXT.md` — the `picking` state owns\n it.\n\n The package to implement is: <%~ it.read(\".gtd/NEXT.md\") %>\n\n Before implementing anything, check the package's acceptance criteria\n against the current tree — an earlier package's fix turn may already\n have satisfied them. If **every** criterion is already met, implement\n nothing: write `.gtd/SATISFIED.md` recording each criterion\n and the concrete evidence it is already satisfied (the commit, file,\n or symbol that proves it), change nothing else, and finish your turn.\n If any criterion is outstanding, implement the package normally and\n do not write that file.\n\n That file describes a set of independent tasks. Implement all of them in\n this one turn, fanning the independent tasks out to parallel subagents\n where your harness supports it — each task is self-contained and can be\n built concurrently. Implement exactly the tasks this package describes — no\n more, no less; leave every other package file untouched. Use TDD\n discipline within each task.\n\n Leave the package file in place and everything else uncommitted, then\n finish your turn.\n on:\n \"A .gtd/SATISFIED.md\": &satisfied\n to: health.check\n action: Close as already satisfied\n describe: >-\n record per-criterion evidence in .gtd/SATISFIED.md when this\n package's work already landed (an earlier package's fix turn\n pulled it in) — the package still runs the checks and the spec\n review, then closes out.\n \"M .gtd/SATISFIED.md\": *satisfied\n \"* **\": health.check\n\n fix-suite:\n actor: agent\n label: Fixing the check\n file: FEEDBACK.md\n prompt: |\n <%~ it.vars.stateFileRules %>\n\n <%~ it.vars.fixFeedbackPrompt %>\n\n If the\n only way to green the suite is to implement work that another\n package file describes, make the smallest change that gets there and\n do it — that later package will then legitimately report itself\n already satisfied when its turn comes.\n\n Leave everything uncommitted and finish your turn — do not commit.\n retry:\n max: 3\n otherwise: health.escalate\n on:\n \"* **\": health.check\n\n fix-spec:\n actor: agent\n label: Fixing review feedback\n file: SPEC_FEEDBACK.md\n prompt: |\n <%~ it.vars.stateFileRules %>\n The only state file this\n turn touches is `.gtd/SPEC_FEEDBACK.md`; address it, then\n delete it. Do not create other files to hold notes or output.\n\n Read `.gtd/SPEC_FEEDBACK.md` (the reviewer's concerns about the\n current package) and the package spec (`<%= it.read(\".gtd/NEXT.md\") %>`),\n then fix the code to resolve every concern. Keep the change focused.\n\n Delete `.gtd/SPEC_FEEDBACK.md` once every concern is addressed.\n Leave everything else uncommitted and finish your turn.\n on:\n \"* **\": health.check\n\n closing:\n actor: check\n label: Closing out the package\n script: |\n #!/usr/bin/env sh\n # Removes the just-reviewed package file (path in NEXT.md) plus\n # leftover spec feedback/evidence, so picking selects the next.\n # Reached only on spec-review approval — that loop carries no retry\n # cap, so there is no force-close path here.\n set +e\n pkg=$(cat .gtd/NEXT.md 2>/dev/null)\n [ -n \"$pkg\" ] && rm -f \"$pkg\"\n rm -f .gtd/SPEC_FEEDBACK.md .gtd/NEXT.md .gtd/SATISFIED.md\n on:\n \"* **\": $onNext\n\n health:\n machine: healthGate\n with:\n onGreen: spec\n onRed: fix-suite\n escalateDescribe: >-\n edit the code and/or `.gtd/FEEDBACK.md` yourself\n (**packages.item.health.check**).\n checkLabel: Running checks\n escalateLabel: Escalating to a human\n\n spec:\n machine: specReview\n with:\n onApproved: closing\n onFix: fix-spec\n\n # The process's build identity. ▸ coder identity — model/system stamped\n # onto fix.\n buildTail:\n model: <%= it.vars.coderModel %>\n system: |-\n <%~ it.vars.finisherPersona %>\n\n\n <%~ it.vars.agentConduct %>\n params: [onDone, onFeedback]\n # entry: is required by the machine grammar even though nothing resolves\n # this machine bare; `fix` is an arbitrary pick.\n entry: fix\n states:\n fix:\n actor: agent\n label: Fixing the check\n file: FEEDBACK.md\n prompt: |\n <%~ it.vars.stateFileRules %>\n\n <%~ it.vars.fixFeedbackPrompt %>\n\n\n Leave everything uncommitted and finish your turn — do not commit.\n retry:\n max: 3\n otherwise: health.escalate\n on:\n \"* **\": health.check\n\n health:\n machine: healthGate\n with:\n onGreen: review\n onRed: fix\n escalateDescribe: >-\n edit the code and/or `.gtd/FEEDBACK.md` yourself\n (**build.health.check**).\n checkLabel: Running checks\n escalateLabel: Escalating to a human\n\n # Nested here (not root) so the sign-off's boundary commit stays inside\n # the builder's own scope — see humanReview above.\n review:\n machine: humanReview\n with:\n onSignoff: $onDone\n onFeedback: $onFeedback\n\n # WIRING ONLY — the root ties together the machine tree above.\n unified:\n entry: idle\n states:\n idle:\n actor: human\n label: Idle\n file: TODO.md\n message: |\n No active gtd process.\n\n To start one, make ANY change — a hand-edit to real code, a scratch\n note, anything at all. .gtd/TODO.md is a good default\n place to start sketching. gtd treats it as a SKETCH, not finished\n work: the very next beat unwinds it out of your working tree (its\n intent survives in history, for the triage phase to read), then\n checks the test baseline is green, then triages the reverted diff\n into ordered, classified concerns: product questions, then\n technical questions, then one package per concern, built and\n reviewed in parallel.\n\n What each change does next (then run `gtd land`):\n <% it.edges.forEach(function (e) { if (e.describe) { %>\n <%~ \"- \" + (e.action ? \"**\" + e.action + \"** — \" : \"\") + e.describe + \"\\n\" %>\n <% } }) %>\n on:\n \"* **\":\n to: unwind\n action: Start\n describe: >-\n make any change — gtd unwinds it out of your working tree (its\n intent survives in history) before checking the test baseline is\n green, then triages the reverted diff into ordered, classified\n concerns and resolves product questions, then technical ones,\n before building each concern's package (**unwind** ->\n **start-gate.check**).\n\n # --entry fix-precheck: a red suite drops into build.fix (-> health ->\n # review tail); a green suite is a no-op back to idle.\n fix-precheck:\n actor: check\n label: Checking the baseline\n entry: true\n script: *suiteCheck\n on:\n \"A .gtd/FEEDBACK.md\": build.fix\n \"M .gtd/FEEDBACK.md\": build.fix\n \"D .gtd/REVIEW_RAW.md\": idle\n \"D .gtd/FEEDBACK.md\": idle\n \"C\": idle\n\n # Separate from start-gate.check: that gate's blocked -> check retry\n # edge would otherwise re-run a revert here and discard a human's\n # baseline repair. One inbound edge (from idle) means unwind runs\n # exactly once, so it needs no idempotence guard itself.\n unwind:\n actor: check\n label: Unwinding your input\n script: |\n #!/usr/bin/env sh\n set +e\n # Hoisted here, at the TOP: Eta's autoTrim eats the newline after\n # an interpolation tag, so no tag may be the last token on a line.\n # Uses it.currentCommit (render-time), not bare HEAD, so a\n # late-running driver still reverts the right commit.\n commit=\"<%~ it.currentCommit %>\"\n git revert --no-commit \"$commit\"\n on:\n \"* **\": start-gate\n\n # Reverts the human's own review-round hand-edit before re-planning,\n # scoped to real code (`.gtd/` excluded — REVIEW.md is already gone by\n # now). Names the commit via it.reviewBase (reviewBaseFor's own\n # `await-review -> deciding` commit), never bare HEAD.\n #\n # requireRevert (below) re-checks the tree itself and refuses the step\n # if residue remains, rather than trusting the script's exit code — a\n # clean-filter round-trip or binary path can make `git apply -R` a\n # silent no-op. Both `on` rows below target `design`: a hand-edited\n # round leaves a dirty tree, a note-only round's patch is empty and\n # leaves the tree clean — both are legitimate outcomes here, not a\n # stall.\n #\n # `file: REVIEW.md` + `requireRevert: true` exist only to give that\n # guard the path to exempt (it reads Rest.hints.file, never this\n # literal) — REVIEW.md is already gone two commits earlier, so this\n # state never renders it.\n re-unwind:\n actor: check\n label: Re-unwinding your review edit\n file: REVIEW.md\n requireRevert: true\n script: |\n #!/usr/bin/env sh\n # Scoped revert of the human's review-round edit — .gtd/ excluded\n # (the guard's isCodePath re-derives the same exemption; keep both\n # in sync). Expected to succeed; requireRevert catches a silent\n # apply failure.\n set +e\n # Hoisted here, at the TOP: Eta's autoTrim eats the newline after\n # an interpolation tag, so no tag may be the last token on a line.\n commit=\"<%~ it.reviewBase %>\"\n patch=.gtd/.re-unwind.patch\n mkdir -p .gtd\n git diff --binary \"$commit^\" \"$commit\" -- . \":(exclude).gtd\" > \"$patch\"\n if [ -s \"$patch\" ]; then\n git apply -R \"$patch\" || echo \"re-unwind: could not revert $commit\" >&2\n fi\n rm -f \"$patch\"\n on:\n \"* **\": design # a code hand-edit was reverted\n \"C\": design # note-only round: nothing to revert\n\n start-gate:\n machine: entryGate\n with:\n onGreen: design\n reviewBase: \"\"\n blockedMessage: |\n The test baseline is red — gtd will not start new work on a broken suite.\n `.gtd/FEEDBACK.md` holds the failing output.\n\n What each change does next (then run `gtd land`):\n <% it.edges.forEach(function (e) { if (e.describe) { %>\n <%~ \"- \" + (e.action ? \"**\" + e.action + \"** — \" : \"\") + e.describe + \"\\n\" %>\n <% } }) %>\n blockedDescribe: >-\n edit the code and/or `.gtd/FEEDBACK.md` to fix the failing tests\n (**start-gate.check**). To repair the baseline as its own separate\n reviewed commit instead, abandon this start and run\n `gtd --entry fix-precheck` from a clean `idle`.\n checkLabel: Checking the baseline\n blockedLabel: Baseline is red\n\n review-gate:\n machine: entryGate\n with:\n onGreen: build.review\n reviewBase: <%= it.vars.reviewBase %>\n blockedMessage: |\n The test baseline is red — gtd will not start a review on a broken suite.\n `.gtd/FEEDBACK.md` holds the failing output.\n\n What each change does next (then run `gtd land`):\n <% it.edges.forEach(function (e) { if (e.describe) { %>\n <%~ \"- \" + (e.action ? \"**\" + e.action + \"** — \" : \"\") + e.describe + \"\\n\" %>\n <% } }) %>\n blockedDescribe: >-\n edit the code and/or `.gtd/FEEDBACK.md` to fix the failing tests\n (**review-gate.check**).\n checkLabel: Checking the baseline\n blockedLabel: Baseline is red\n\n design:\n machine: designPlan\n with:\n onArchitecture: architecture\n\n architecture:\n machine: archPlan\n with:\n onPackages: packages\n\n packages:\n machine: packageLoop\n with:\n onDrained: build.review\n\n build:\n machine: buildTail\n with:\n onDone: idle\n onFeedback: re-unwind\n";
191899
191889
  //#endregion
191900
191890
  //#region src/workflows/templates.ts
191901
191891
  const SCHEMA_URL = "https://cdn.jsdelivr.net/npm/@pmelab/gtd/schema.json";
@@ -191980,7 +191970,7 @@ const JSON_TYPE = {
191980
191970
  /** One state's shape — `properties` is derived from `STATE_FIELD_ENTRIES` (every `authored: "state"` field, in table order); see `ConfigSchema.test.ts`. */
191981
191971
  const stateJsonSchema = {
191982
191972
  type: "object",
191983
- description: "One workflow state. Declare exactly one content kind (script/prompt/message/commit). A commit state is final: no actor, no on.",
191973
+ description: "One workflow state. Declare exactly one content kind (script/prompt/message).",
191984
191974
  additionalProperties: false,
191985
191975
  properties: Object.fromEntries(STATE_FIELD_ENTRIES.filter(([, spec]) => spec.authored === "state").map(([key, spec]) => [key, spec.jsonSchema ?? {
191986
191976
  ...JSON_TYPE[spec.kind],
@@ -192007,12 +191997,16 @@ const machineRefJsonSchema = {
192007
191997
  /** The whole `workflow:` value; `PatternConfig.ts`'s compiler is the authoritative schema, this is the editor's first net. */
192008
191998
  const workflowJsonSchema = {
192009
191999
  type: "object",
192010
- description: "The whole machine definition: a tree of named machines rooted at entry.default (plus the workflow's own vars: defaults and modes: steering-file modes). Compiled and validated by gtd at load time; content strings starting with ./ or ../ are file references inlined from the config file's directory (a modes: command never is — it is a shell command).",
192000
+ description: "The whole machine definition: a tree of named machines rooted at entry.default (plus the workflow's own vars: defaults, modes: steering-file modes, and summary: template). Compiled and validated by gtd at load time; content strings starting with ./ or ../ are file references inlined from the config file's directory (a modes: command never is — it is a shell command).",
192011
192001
  additionalProperties: false,
192012
192002
  required: ["entry", "machines"],
192013
192003
  properties: {
192014
192004
  vars: varsJsonSchema,
192015
192005
  modes: modesJsonSchema,
192006
+ summary: {
192007
+ type: "string",
192008
+ description: "Eta template rendered by `gtd summary`: instructions plus commit hashes (it.entryCommit, it.humanCommits, it.processBase, it.processTip) for an agent to write the process's own closing message. A ./ or ../ value is inlined from the config file's directory at load time. Absent is legal (gtd summary refuses); present-but-blank is a load error."
192009
+ },
192016
192010
  entry: {
192017
192011
  type: "object",
192018
192012
  description: "The workflow's root machine, resolved through the same resolver an `on`/`retry.otherwise` target uses (see src/Machines.ts) — accepts either a bare state path or an instance/reference-key path. Extra manual entry points are declared per-state instead, via a state's own `entry: true` (see `stateJsonSchema`'s `entry` property) — not here.",
@@ -193123,7 +193117,7 @@ const varsOnlyContext = (vars, state = "") => ({
193123
193117
  state,
193124
193118
  actor: "",
193125
193119
  reviewBase: "",
193126
- retainedBase: "",
193120
+ processBase: "",
193127
193121
  processCost: 0,
193128
193122
  processCostByModel: [],
193129
193123
  read: (path) => {
@@ -193143,24 +193137,17 @@ const renderModeCommand = (template, context) => eta.renderString(template, cont
193143
193137
  //#region src/RetainedHistory.ts
193144
193138
  /** Per-worktree (`refs/worktree/gtd/*`, like `ReviewWindow.ts`'s refs) so linked worktrees sharing one `.git` don't clobber each other's retained history. */
193145
193139
  const HISTORY_REF = "refs/worktree/gtd/history";
193146
- const HISTORY_TRAILER_PREFIX = "Gtd-History: ";
193147
- const HISTORY_TRAILER_RE = /^Gtd-History:[ \t]*(\S+)[ \t]*$/m;
193148
- /** Appends a `Gtd-History: <hash>` trailer recording the pre-squash tip, for `gtd restore` to read back later. */
193149
- const withHistoryTrailer = (subject, hash) => `${subject}\n\n${HISTORY_TRAILER_PREFIX}${hash}`;
193150
- const parseHistoryTrailer = (message) => HISTORY_TRAILER_RE.exec(message)?.[1];
193151
193140
  const readRetainedHistory = (git) => git.readRefOption(HISTORY_REF);
193152
193141
  /**
193153
- * Whether resetting to `tipHash` is safe: either HEAD is the squash commit
193154
- * that still carries the matching `Gtd-History:` trailer (resetting discards
193155
- * only that one commit), or HEAD is an ancestor of `tipHash` (nothing on top
193156
- * would be lost). Anything else is refused.
193142
+ * Whether resetting to `tipHash` is safe: HEAD must be an ancestor of
193143
+ * `tipHash` (nothing on top of the retained tip would be lost). Anything else
193144
+ * is refused.
193157
193145
  */
193158
- const restorability = (git, headHash, headMessage, tipHash) => gen(function* () {
193159
- if (parseHistoryTrailer(headMessage) === tipHash) return { ok: true };
193146
+ const restorability = (git, headHash, tipHash) => gen(function* () {
193160
193147
  if (yield* git.isAncestor(headHash, tipHash)) return { ok: true };
193161
193148
  return {
193162
193149
  ok: false,
193163
- reason: "HEAD has advanced past the squash — restoring would discard commits built on top of it"
193150
+ reason: "HEAD has advanced past the retained tip — restoring would discard commits built on top of it"
193164
193151
  };
193165
193152
  });
193166
193153
  //#endregion
@@ -193187,17 +193174,8 @@ const commitAllowEmpty = (message) => {
193187
193174
  };
193188
193175
  /** `git add -A` then `commitAllowEmpty`, joined with `&&` so a failing `git add` never reaches the commit. */
193189
193176
  const commitAll = (message) => `git add -A &&\n${commitAllowEmpty(message)}`;
193190
- const commitAsIs = (message) => commitAllowEmpty(message);
193191
- const softResetTo = (ref) => `git reset --soft ${shellQuote(ref)}`;
193192
193177
  const mixedResetTo = (ref) => `git reset --mixed ${shellQuote(ref)}`;
193193
193178
  const hardResetTo = (ref) => `git reset --hard ${shellQuote(ref)}`;
193194
- /**
193195
- * `git add -A` then `git reset --hard HEAD` — discards every pending change,
193196
- * tracked or untracked. Joined with `&&`: a failed stage must not reach the
193197
- * hard reset, or untracked survivors remain — the exact outcome this builder
193198
- * exists to avoid.
193199
- */
193200
- const discardPending = () => `git add -A && git reset --hard HEAD`;
193201
193179
  const updateRef = (ref, hash) => `git update-ref ${shellQuote(ref)} ${shellQuote(hash)}`;
193202
193180
  /** `git update-ref -d <ref>` — idempotent: deleting a missing ref is already a no-op in real git. */
193203
193181
  const deleteRef = (ref) => `git update-ref -d ${shellQuote(ref)}`;
@@ -193330,7 +193308,7 @@ const OUTCOME_PREAMBLE = [
193330
193308
  ].join("\n");
193331
193309
  /** `gtd_report_transition <from> <to>` — a landed self-loop/target-change transition, with its changed-file rows. */
193332
193310
  const transitionOutcome = (from, to) => `gtd_report_transition ${shellQuote(from)} ${shellQuote(to)}`;
193333
- /** `gtd_report_commit <subject>` — a bare capture or a squash's final commit, with its changed-file rows. */
193311
+ /** `gtd_report_commit <subject>` — a bare capture (a self-loop commit), with its changed-file rows. */
193334
193312
  const commitOutcome = (subject) => `gtd_report_commit ${shellQuote(subject)}`;
193335
193313
  /** `gtd_report_note <text>` — one already-rendered plain line, no marker. */
193336
193314
  const noteOutcome = (text) => `gtd_report_note ${shellQuote(text)}`;
@@ -193547,8 +193525,8 @@ const normalizeStatus = (raw) => raw === "A" ? "A" : raw === "D" ? "D" : "M";
193547
193525
  * process left resting at a state a workflow upgrade removed would otherwise
193548
193526
  * look like a fresh idle repo instead of pointing at `gtd abandon`. Every
193549
193527
  * other case `resolveState` folds into "rest at the initial state" (an
193550
- * unparseable subject, an actor mismatch, a commit-state target) is left as
193551
- * is — those are legitimately "no active process," not a renamed-out state.
193528
+ * unparseable subject, an actor mismatch) is left as is — those are
193529
+ * legitimately "no active process," not a renamed-out state.
193552
193530
  */
193553
193531
  const resolveRestFrom = (def, headSubject) => {
193554
193532
  const parsedHead = parseStateSubject(headSubject);
@@ -193560,7 +193538,7 @@ const resolveRestFrom = (def, headSubject) => {
193560
193538
  const stateDef = def.states[state];
193561
193539
  if (stateDef.actor === void 0) return {
193562
193540
  ok: false,
193563
- error: /* @__PURE__ */ new Error(`gtd: resolved at commit state "${state}" — a process never rests there`)
193541
+ error: /* @__PURE__ */ new Error(`gtd: resolved at state "${state}" declaring no actor`)
193564
193542
  };
193565
193543
  return {
193566
193544
  ok: true,
@@ -193580,16 +193558,14 @@ const pendingChanges = (git, base) => git.changedPaths(base).pipe(map$4((entries
193580
193558
  * `ProcessRun.headTurn` from an already-fetched `commitHistory` array
193581
193559
  * (oldest→newest) — HEAD is its last entry. `undefined` for an empty
193582
193560
  * history, an unparseable/foreign subject, or a subject naming a state the
193583
- * ACTIVE definition doesn't declare or that is a commit state (never a real
193584
- * rest).
193561
+ * ACTIVE definition doesn't declare (never a real rest).
193585
193562
  */
193586
193563
  const headTurnFrom = (def, history) => {
193587
193564
  if (history.length === 0) return void 0;
193588
193565
  const head = history[history.length - 1];
193589
193566
  const parsed = parseStateSubject(subjectOf(head.message));
193590
193567
  if (parsed === void 0) return void 0;
193591
- const stateDef = def.states[parsed.state];
193592
- if (stateDef === void 0 || isCommitState(stateDef)) return void 0;
193568
+ if (def.states[parsed.state] === void 0) return void 0;
193593
193569
  return {
193594
193570
  state: parsed.state,
193595
193571
  actor: parsed.actor,
@@ -193614,6 +193590,33 @@ const parseEntryCommitOverrides = (processCommits) => {
193614
193590
  };
193615
193591
  };
193616
193592
  /**
193593
+ * The boundary-exclusive backward walk `computeProcessRun` needs, split out
193594
+ * so the surrounding Effect.gen body stays under the complexity gate. Returns
193595
+ * the trace/retry boundary's history index (`i`, `-1` when the whole history
193596
+ * belongs to the process) and, when `includeClosingBoundary` folded HEAD's own
193597
+ * closing commit into the process, its hash.
193598
+ */
193599
+ const walkProcessBoundary = (history, initialState, includeClosingBoundary) => {
193600
+ let i = history.length - 1;
193601
+ let closingHash;
193602
+ if (includeClosingBoundary && i >= 0) {
193603
+ const parsedLast = parseStateSubject(subjectOf(history[i].message));
193604
+ if (parsedLast !== void 0 && parsedLast.state === initialState) {
193605
+ closingHash = history[i].hash;
193606
+ i--;
193607
+ }
193608
+ }
193609
+ while (i >= 0) {
193610
+ const parsed = parseStateSubject(subjectOf(history[i].message));
193611
+ if (parsed === void 0 || parsed.state === initialState) break;
193612
+ i--;
193613
+ }
193614
+ return {
193615
+ boundaryIndex: i,
193616
+ closingHash
193617
+ };
193618
+ };
193619
+ /**
193617
193620
  * Walk first-parent history backward from HEAD while each commit's subject
193618
193621
  * parses as `gtd(actor): state` and that state isn't the workflow's initial
193619
193622
  * state; stop — excluding that boundary commit, which belongs to the
@@ -193627,22 +193630,28 @@ const parseEntryCommitOverrides = (processCommits) => {
193627
193630
  * `restAt`'s window-aware branch passes the saved-head hash here while a
193628
193631
  * review window is open, so the trace still covers commits a real `git log`
193629
193632
  * would miss with HEAD rewound to the review base.
193633
+ *
193634
+ * `includeClosingBoundary` (default `false`) is `summaryRun`'s one-flag
193635
+ * difference from `currentRun`'s ordinary walk: when set AND the walk's very
193636
+ * last history entry (HEAD itself) is a commit entering the initial state, that
193637
+ * boundary commit is folded INTO the trace instead of excluded, and its hash
193638
+ * is recorded as `ProcessRun.closingHash`. A process still in flight (HEAD is
193639
+ * not itself such a boundary) resolves identically to the flag being unset.
193630
193640
  */
193631
- const computeProcessRun = (git, def, head) => gen(function* () {
193641
+ const computeProcessRun = (git, def, head, includeClosingBoundary = false) => gen(function* () {
193632
193642
  const initialState = initialStateOf(def);
193633
193643
  const history = yield* git.commitHistory(void 0, head);
193634
- let i = history.length - 1;
193635
- while (i >= 0) {
193636
- const parsed = parseStateSubject(subjectOf(history[i].message));
193637
- if (parsed === void 0 || parsed.state === initialState) break;
193638
- i--;
193639
- }
193644
+ const { boundaryIndex: i, closingHash } = walkProcessBoundary(history, initialState, includeClosingBoundary);
193640
193645
  const startIdx = i + 1;
193641
193646
  const processCommits = history.slice(startIdx);
193642
- const trace = processCommits.map((h) => ({
193643
- state: parseStateSubject(subjectOf(h.message)).state,
193644
- hash: h.hash
193645
- }));
193647
+ const trace = processCommits.map((h) => {
193648
+ const parsed = parseStateSubject(subjectOf(h.message));
193649
+ return {
193650
+ state: parsed.state,
193651
+ hash: h.hash,
193652
+ actor: parsed.actor
193653
+ };
193654
+ });
193646
193655
  const costEntries = parseCostTrailers(processCommits.map((h) => h.message));
193647
193656
  const startParentHash = i >= 0 ? history[i].hash : EMPTY_TREE$2;
193648
193657
  const startHash = startIdx < history.length ? history[startIdx].hash : history[history.length - 1].hash;
@@ -193654,7 +193663,8 @@ const computeProcessRun = (git, def, head) => gen(function* () {
193654
193663
  trace,
193655
193664
  costEntries,
193656
193665
  entryVars,
193657
- headTurn: headTurnFrom(def, history)
193666
+ headTurn: headTurnFrom(def, history),
193667
+ closingHash
193658
193668
  };
193659
193669
  });
193660
193670
  /**
@@ -193676,6 +193686,20 @@ const currentRun = gen(function* () {
193676
193686
  return yield* computeProcessRun(git, config.workflow, windowHead);
193677
193687
  });
193678
193688
  /**
193689
+ * The process HEAD closes or sits inside — `gtd summary`'s run resolution.
193690
+ * Window-aware on the same terms as `currentRun`. Identical to `currentRun`
193691
+ * for a process still in flight; for a finished process (HEAD is itself a
193692
+ * commit entering the initial state), the closing commit is folded back into
193693
+ * the trace and its hash recorded as `closingHash` — see
193694
+ * `computeProcessRun`'s `includeClosingBoundary` flag.
193695
+ */
193696
+ const summaryRun = gen(function* () {
193697
+ const git = yield* GitService;
193698
+ const config = yield* (yield* ConfigService).load;
193699
+ const windowHead = getOrUndefined(yield* git.readRefOption(REVIEW_HEAD_REF$1));
193700
+ return yield* computeProcessRun(git, config.workflow, windowHead, true);
193701
+ });
193702
+ /**
193679
193703
  * PURE: the most-recent in-process turn commit that entered a `reviewBase`
193680
193704
  * state, or `run.diffBase` when none did. A backwards walk of `run.trace`,
193681
193705
  * so no git call, no matter how deep the process.
@@ -193818,11 +193842,11 @@ const withRenderedOn = (def, state, renderedOnEdges) => ({
193818
193842
  * Build the `PatternTemplates.TemplateContext` for rendering `state`'s content
193819
193843
  * at the resolved rest. `edges` must already be rendered by the caller
193820
193844
  * (`renderOnEdges`). `currentCost`/`currentModel` are the in-flight step's own
193821
- * `--cost`/`--model`, folded into the process's committed cost entries so a
193822
- * `commit:` squash template sees the whole-process total including the
193823
- * squashing step (`0`/absent for the pure emitters, where no step runs). No
193824
- * diff is computed here — `it.reviewBase`/`it.retainedBase` are bases a
193825
- * template tells the agent to `git diff` itself.
193845
+ * `--cost`/`--model`, folded into the process's committed cost entries so
193846
+ * `it.processCost`/`it.processCostByModel` total the whole process (`0`/absent
193847
+ * for the pure emitters, where no step runs). No diff is computed here —
193848
+ * `it.reviewBase`/`it.processBase` are bases a template tells the agent to
193849
+ * `git diff` itself.
193826
193850
  */
193827
193851
  const buildTemplateContext = (git, read, state, actor, run, vars, edges, currentCost, currentModel, reviewBase) => gen(function* () {
193828
193852
  const currentCommit = yield* git.resolveRef("HEAD");
@@ -193839,7 +193863,7 @@ const buildTemplateContext = (git, read, state, actor, run, vars, edges, current
193839
193863
  state,
193840
193864
  actor,
193841
193865
  reviewBase,
193842
- retainedBase: run.startParentHash,
193866
+ processBase: run.startParentHash,
193843
193867
  processCost: totalCostOf(allCostEntries),
193844
193868
  processCostByModel: costByModel(allCostEntries),
193845
193869
  read,
@@ -193848,6 +193872,22 @@ const buildTemplateContext = (git, read, state, actor, run, vars, edges, current
193848
193872
  };
193849
193873
  });
193850
193874
  /**
193875
+ * The `TemplateContext` `gtd summary` renders `def.summary` against — no
193876
+ * resting state, no `on` edges (a summary isn't rendered AT a state), `cost`/
193877
+ * `model` both absent (the command writes nothing, so there is no in-flight
193878
+ * step to fold in).
193879
+ */
193880
+ const summaryTemplateContext = (run) => gen(function* () {
193881
+ const git = yield* GitService;
193882
+ const config = yield* (yield* ConfigService).load;
193883
+ const files = yield* RepoFiles;
193884
+ const envVars = yield* EnvVars;
193885
+ const def = config.workflow;
193886
+ const vars = resolveVars(config.workflowVars, config.rcVars, run.entryVars, envVars.all);
193887
+ const reviewBase = reviewBaseFor(def, run);
193888
+ return yield* buildTemplateContext(git, templateRead(files), "", "", run, vars, void 0, 0, void 0, reviewBase);
193889
+ });
193890
+ /**
193851
193891
  * True when this process would retain NOTHING: nothing pending and no net
193852
193892
  * change between its trace/retry boundary and HEAD. Used by `planStep`'s
193853
193893
  * "returned to the initial state retaining nothing" mixed-reset branch.
@@ -193929,16 +193969,16 @@ const renderHints = (stateDef, context) => gen(function* () {
193929
193969
  return omitUndefined(hints);
193930
193970
  });
193931
193971
  /**
193932
- * Render a `Rest`'s declared content (script/prompt/message — never `commit`,
193933
- * since a `Rest` never rests at a commit state) plus every `STATE_FIELDS`
193934
- * field carrying a `rest` kind and its computed memory key — all of which
193935
- * already live on `rest` (`rest.context`/`rest.hints`/`rest.memory`, built
193936
- * once by `restAt` via `renderHints`), so this takes no other parameters.
193972
+ * Render a `Rest`'s declared content (script/prompt/message) plus every
193973
+ * `STATE_FIELDS` field carrying a `rest` kind and its computed memory key —
193974
+ * all of which already live on `rest` (`rest.context`/`rest.hints`/
193975
+ * `rest.memory`, built once by `restAt` via `renderHints`), so this takes no
193976
+ * other parameters.
193937
193977
  */
193938
193978
  const renderRest = (rest) => gen(function* () {
193939
193979
  const kind = contentKindOf(rest.stateDef);
193940
193980
  if (kind === void 0) return yield* fail$2(/* @__PURE__ */ new Error(`state "${rest.state}" declares no content — invalid definition`));
193941
- const template = rest.stateDef.script ?? rest.stateDef.prompt ?? rest.stateDef.message ?? rest.stateDef.commit;
193981
+ const template = rest.stateDef.script ?? rest.stateDef.prompt ?? rest.stateDef.message;
193942
193982
  const content = yield* try_({
193943
193983
  try: () => renderStateTemplate(template, rest.context),
193944
193984
  catch: (e) => e instanceof Error ? e : new Error(String(e))
@@ -193973,21 +194013,7 @@ const stalledAt = (rest) => rest.changes.length === 0 && rest.run.headTurn?.stat
193973
194013
  * `PatternMachine.step`'s own tests (a defensive message beats a lie).
193974
194014
  */
193975
194015
  const formatStepRefusal = (refusal) => refusal.reason === "out-of-turn" ? `gtd land: out of turn — "${refusal.state}" awaits ${refusal.awaits}` : `gtd land: no declared pattern matches the pending changes at "${refusal.state}" — declared patterns: ${refusal.patterns.length > 0 ? refusal.patterns.join(", ") : "(none)"}`;
193976
- /**
193977
- * Build the `TemplateContext` for rendering a DIFFERENT state than `rest`'s
193978
- * own resting one, with a step's `cost`/`model` folded in — a squash's commit
193979
- * template needs this; it is NOT interchangeable with `rest.context`, which
193980
- * is pinned to the resting state with `cost: 0`. Exported for `program.ts`'s
193981
- * `planLanding`, which assembles the same script by hand and must pick the
193982
- * same context.
193983
- */
193984
- const contextAt = (rest, targetState, invoker, cost, model) => gen(function* () {
193985
- const git = yield* GitService;
193986
- const files = yield* RepoFiles;
193987
- const onEdges = targetState === rest.state ? rest.on : yield* renderOnEdgesOrFail(rest.def.states[targetState]?.on, rest.vars);
193988
- return yield* buildTemplateContext(git, templateRead(files), targetState, invoker, rest.run, rest.vars, onEdges, cost ?? 0, model, reviewBaseFor(rest.def, rest.run));
193989
- });
193990
- /** `updateRef(HISTORY_REF, tip)` as a single-element (or empty) step list — OMITTED when `tip === startParentHash`, mirroring `retainHistory`'s own no-op check. Shared by the squash branch and the commit branch's collapse case below. */
194016
+ /** `updateRef(HISTORY_REF, tip)` as a single-element (or empty) step list — OMITTED when `tip === startParentHash`, mirroring `retainHistory`'s own no-op check. Used by the commit branch's collapse case below. */
193991
194017
  const retainHistoryStep = (tip, startParentHash) => tip === startParentHash ? [] : [{
193992
194018
  kind: "gitWrite",
193993
194019
  command: updateRef(HISTORY_REF, tip)
@@ -194002,20 +194028,20 @@ const commitDecisionOutcome = (decision) => ({
194002
194028
  * state retaining nothing" collapse — target is the initial state, the
194003
194029
  * process started somewhere other than the empty tree, and nothing pending or
194004
194030
  * already-committed since its start parent survives (`retainsNothing`).
194005
- * Always `false` for a `"squash"` decision and for an ATTEMPT: an agent that
194006
- * did nothing must never rewind a process, and an attempt landing at a prompt
194007
- * state that's also the initial state would otherwise satisfy every other
194008
- * criterion identically to a genuine collapse.
194031
+ * Always `false` for an ATTEMPT: an agent that did nothing must never rewind
194032
+ * a process, and an attempt landing at a prompt state that's also the initial
194033
+ * state would otherwise satisfy every other criterion identically to a
194034
+ * genuine collapse.
194009
194035
  */
194010
194036
  const collapsesWith = (git, rest, decision) => gen(function* () {
194011
- if (decision.kind === "squash" || decision.attempt === true) return false;
194037
+ if (decision.attempt === true) return false;
194012
194038
  return parseStateSubject(decision.subject)?.state === initialStateOf(rest.def) && rest.run.startParentHash !== EMPTY_TREE$2 && (yield* retainsNothing(git, rest.run, rest.changes));
194013
194039
  });
194014
194040
  /**
194015
194041
  * The service-requiring twin of `collapsesWith`, for `program.ts` to ask
194016
194042
  * instead of reaching into `GitService` itself — the boundary AGENTS.md pins.
194017
194043
  * `planLanding` calls this to fill `LandResult.settled` for a `"commit"`/
194018
- * `"squash"` plan, off the same `rest`/`decision` `renderDecision` already
194044
+ * `"commit"` plan, off the same `rest`/`decision` `renderDecision` already
194019
194045
  * decided against, so the two git reads (`changedPathsSince` + `resolveRef`)
194020
194046
  * can never disagree with each other.
194021
194047
  */
@@ -194024,68 +194050,39 @@ const collapsesToInitialState = (rest, decision) => gen(function* () {
194024
194050
  return yield* collapsesWith(git, rest, decision);
194025
194051
  });
194026
194052
  /**
194027
- * Render a `"commit"`/`"squash"` decision as the `EmitStep`s the external
194028
- * driver runs to produce its git effect — the ONE place a decision becomes
194029
- * git commands. Every git call here is a READ; nothing is written — gtd
194030
- * itself never writes git, only a driven script does.
194053
+ * Render a `"commit"` decision as the `EmitStep`s the external driver runs to
194054
+ * produce its git effect — the ONE place a decision becomes git commands.
194055
+ * Every git call here is a READ; nothing is written — gtd itself never writes
194056
+ * git, only a driven script does.
194031
194057
  *
194032
- * The commit branch carries one non-obvious case: a commit whose target is
194033
- * the workflow's INITIAL state, from a process that retained nothing, is a
194034
- * no-op probe (`gtd --entry fix-precheck` against a green suite is the
194035
- * shipped example) and must leave no trace — it emits retain-history plus a
194036
- * mixed reset to the process start instead of a commit, so the entry commit
194037
- * and the probe collapse away together rather than dirtying the log with a
194038
- * round trip to `idle`.
194058
+ * One non-obvious case: a commit whose target is the workflow's INITIAL
194059
+ * state, from a process that retained nothing, is a no-op probe
194060
+ * (`gtd --entry fix-precheck` against a green suite is the shipped example)
194061
+ * and must leave no trace — it emits retain-history plus a mixed reset to the
194062
+ * process start instead of a commit, so the entry commit and the probe
194063
+ * collapse away together rather than dirtying the log with a round trip to
194064
+ * `idle`.
194039
194065
  */
194040
- const renderDecision = (git, rest, decision, context, cost, model) => gen(function* () {
194066
+ const renderDecision = (git, rest, decision, cost, model) => gen(function* () {
194041
194067
  const run = rest.run;
194042
- switch (decision.kind) {
194043
- case "commit":
194044
- if (yield* collapsesWith(git, rest, decision)) {
194045
- const tip = yield* git.resolveRef("HEAD");
194046
- return [
194047
- ...retainHistoryStep(tip, run.startParentHash),
194048
- {
194049
- kind: "gitWrite",
194050
- command: mixedResetTo(run.startParentHash)
194051
- },
194052
- {
194053
- kind: "outcome",
194054
- command: noteOutcome(COLLAPSED_TEXT)
194055
- }
194056
- ];
194057
- }
194058
- return [{
194068
+ if (yield* collapsesWith(git, rest, decision)) {
194069
+ const tip = yield* git.resolveRef("HEAD");
194070
+ return [
194071
+ ...retainHistoryStep(tip, run.startParentHash),
194072
+ {
194059
194073
  kind: "gitWrite",
194060
- command: commitAll(withCostTrailer(decision.subject, cost, model))
194061
- }, commitDecisionOutcome(decision)];
194062
- case "squash": {
194063
- const message = yield* try_({
194064
- try: () => renderStateTemplate(decision.template, context),
194065
- catch: (e) => /* @__PURE__ */ new Error(`gtd: rendering the "${decision.state}" commit template failed — nothing was committed: ${e instanceof Error ? e.message : String(e)}`)
194066
- });
194067
- const tip = yield* git.resolveRef("HEAD");
194068
- return [
194069
- ...retainHistoryStep(tip, run.startParentHash),
194070
- {
194071
- kind: "gitWrite",
194072
- command: softResetTo(run.startParentHash)
194073
- },
194074
- {
194075
- kind: "gitWrite",
194076
- command: commitAsIs(withHistoryTrailer(message, tip))
194077
- },
194078
- {
194079
- kind: "gitWrite",
194080
- command: discardPending()
194081
- },
194082
- {
194083
- kind: "outcome",
194084
- command: commitOutcome(subjectOf(message))
194085
- }
194086
- ];
194087
- }
194074
+ command: mixedResetTo(run.startParentHash)
194075
+ },
194076
+ {
194077
+ kind: "outcome",
194078
+ command: noteOutcome(COLLAPSED_TEXT)
194079
+ }
194080
+ ];
194088
194081
  }
194082
+ return [{
194083
+ kind: "gitWrite",
194084
+ command: commitAll(withCostTrailer(decision.subject, cost, model))
194085
+ }, commitDecisionOutcome(decision)];
194089
194086
  });
194090
194087
  /**
194091
194088
  * The `EmitPreconditions` a step's/entry's assembled scripts assert against:
@@ -194109,15 +194106,14 @@ const buildPreconditions = (git, rest, targetState) => gen(function* () {
194109
194106
  };
194110
194107
  });
194111
194108
  /**
194112
- * The `EmittedScripts` a `"commit"`/`"squash"` `StepPlan` carries alongside
194113
- * `perform` — built from the SAME `renderDecision` output, but a render
194114
- * failure collapses to an EMPTY script (`emitScripts` with no steps) instead
194115
- * of failing this Effect: `perform` stays the one place a render failure is
194116
- * ever reported to a caller, unchanged by this addition.
194109
+ * The `EmittedScripts` a `"commit"` `StepPlan` carries alongside `perform` —
194110
+ * built from the SAME `renderDecision` output, but a render failure collapses
194111
+ * to an EMPTY script (`emitScripts` with no steps) instead of failing this
194112
+ * Effect: `perform` stays the one place a render failure is ever reported to
194113
+ * a caller, unchanged by this addition.
194117
194114
  */
194118
- const buildStepScripts = (git, rest, decision, context, cost, model) => gen(function* () {
194119
- const targetState = decision.kind === "commit" ? decision.to : decision.state;
194120
- return emitScripts(yield* buildPreconditions(git, rest, targetState), yield* renderDecision(git, rest, decision, context, cost, model).pipe(catchAll(() => succeed$3([]))));
194115
+ const buildStepScripts = (git, rest, decision, cost, model) => gen(function* () {
194116
+ return emitScripts(yield* buildPreconditions(git, rest, decision.to), yield* renderDecision(git, rest, decision, cost, model).pipe(catchAll(() => succeed$3([]))));
194121
194117
  });
194122
194118
  /**
194123
194119
  * A no-op is TERMINAL only at a `script` rest: gtd rendered the script, the
@@ -194134,10 +194130,8 @@ const noOpSettles = (rest) => contentKindOf(rest.stateDef) === "script";
194134
194130
  /**
194135
194131
  * Decide what landing at `rest` does, authenticated as `rest.actor` (the
194136
194132
  * state's own declared actor, so out-of-turn is unreachable by construction),
194137
- * and — for a `"commit"`/`"squash"` decision — assemble the emitted `scripts`
194138
- * a driver runs to land it (against `rest.context` for a commit, or a
194139
- * freshly built `contextAt` for a squash, which renders a DIFFERENT state's
194140
- * template with the step's cost folded in).
194133
+ * and — for a `"commit"` decision — assemble the emitted `scripts` a driver
194134
+ * runs to land it, against `rest.context`.
194141
194135
  */
194142
194136
  const planStep = (rest, opts = {}) => gen(function* () {
194143
194137
  const decision = step(rest.stepDef, rest.state, rest.actor, {
@@ -194155,8 +194149,7 @@ const planStep = (rest, opts = {}) => gen(function* () {
194155
194149
  };
194156
194150
  const { cost, model } = opts;
194157
194151
  const git = yield* GitService;
194158
- const scriptContext = decision.kind === "commit" ? rest.context : yield* contextAt(rest, decision.state, rest.actor, cost, model);
194159
- const scripts = yield* buildStepScripts(git, rest, decision, scriptContext, cost, model);
194152
+ const scripts = yield* buildStepScripts(git, rest, decision, cost, model);
194160
194153
  return {
194161
194154
  kind: decision.kind,
194162
194155
  state: rest.state,
@@ -194166,7 +194159,7 @@ const planStep = (rest, opts = {}) => gen(function* () {
194166
194159
  });
194167
194160
  /**
194168
194161
  * `gtd --entry <state>`: start a brand NEW process at `entry.state` — any
194169
- * declared, non-commit state — writing an ordinary turn commit carrying zero
194162
+ * declared state — writing an ordinary turn commit carrying zero
194170
194163
  * or more `Gtd-Var:` trailers for each `entry.vars` override, plus — when
194171
194164
  * `entry.state` declares a string `reviewBase:` — a `Gtd-Review-Base:`
194172
194165
  * trailer pinning the new process's diff base. Captures whatever the working
@@ -194249,6 +194242,37 @@ const planEntry = (rest, actor, entry) => gen(function* () {
194249
194242
  };
194250
194243
  });
194251
194244
  //#endregion
194245
+ //#region src/Summary.ts
194246
+ /**
194247
+ * Every `human`-authored commit in `run.trace`, oldest to newest, minus
194248
+ * `entryHash` — derived generically off the invoking actor `computeProcessRun`
194249
+ * already parsed onto each `TraceEntry`, never by naming a state.
194250
+ */
194251
+ const humanCommitsOf = (run, entryHash) => run.trace.filter((entry) => entry.actor === "human" && entry.hash !== entryHash).map((entry) => ({
194252
+ hash: entry.hash,
194253
+ state: entry.state
194254
+ }));
194255
+ /**
194256
+ * Build `SummaryContext` for `run` and render `def.summary` against it — pure,
194257
+ * touching no git and no filesystem (`base` already carries a resolved
194258
+ * `read`/`vars`/`processCost`, built by the caller against real git). Returns
194259
+ * `undefined` when the workflow declares no `summary:` or `run.trace` is
194260
+ * empty — both refusal conditions belong to the caller (`program.ts`), not an
194261
+ * Effect failure here.
194262
+ */
194263
+ const buildSummary = (def, run, base) => {
194264
+ if (def.summary === void 0 || run.trace.length === 0) return void 0;
194265
+ const entryCommit = run.trace[0].hash;
194266
+ const processTip = run.trace[run.trace.length - 1].hash;
194267
+ const context = {
194268
+ ...base,
194269
+ entryCommit,
194270
+ humanCommits: humanCommitsOf(run, entryCommit),
194271
+ processTip
194272
+ };
194273
+ return renderStateTemplate(def.summary, context);
194274
+ };
194275
+ //#endregion
194252
194276
  //#region src/ReviewWindow.ts
194253
194277
  /**
194254
194278
  * Per-worktree (`refs/worktree/*`) so linked worktrees sharing one `.git`
@@ -206037,7 +206061,7 @@ const stepGuards = [
206037
206061
  * of the current committed/working bytes, and fail with the first refusal's
206038
206062
  * reason, prefixed `gtd land: ` (the one place that prefix, and
206039
206063
  * `Commentary.ts`'s `renderFailure` `/^gtd[: ]/` contract, is satisfied). A
206040
- * no-op for a squash/no-op decision, an ATTEMPT commit (empty diff by
206064
+ * no-op for a `"noop"` decision, an ATTEMPT commit (empty diff by
206041
206065
  * construction — nothing for any guard to check), a state with no `file:`, or
206042
206066
  * a state no guard applies to.
206043
206067
  */
@@ -206887,15 +206911,11 @@ const decideAndNarrateOpenWindow = (rest, targetState) => gen(function* () {
206887
206911
  });
206888
206912
  /** True for a `"commit"` decision that is an ATTEMPT (`PatternMachine.StepCommit.attempt`) — the one flag both `enforceStepGuards` and `buildRequiredScript` bypass their own steps for (see each call site). */
206889
206913
  const isAttemptDecision = (decision) => decision.kind === "commit" && decision.attempt === true;
206890
- /**
206891
- * The subject the required script will produce. Unreachable-on-failure:
206892
- * `renderDecision` already rendered the same template and refused the
206893
- * command if it threw, so this second render can never be the first to fail.
206894
- */
206895
- const previewSubject = (decision, rest) => decision.kind === "commit" ? succeed$3(decision.subject) : try_(() => renderStateTemplate(decision.template, rest.context).split("\n")[0].trim()).pipe(catchAll(() => succeed$3(null)));
206914
+ /** The subject the required script will produce. */
206915
+ const previewSubject = (decision) => succeed$3(decision.subject);
206896
206916
  /**
206897
206917
  * The `required` half: the review-window close (when one is open), the
206898
- * resting state's own steering-mode commands, then the commit/squash steps.
206918
+ * resting state's own steering-mode commands, then the commit steps.
206899
206919
  * The steering-mode step is skipped for an attempt commit — nothing to
206900
206920
  * format/validate in an empty diff, and running `format:` ahead of the
206901
206921
  * commit could dirty the tree and turn an "empty" attempt non-empty, breaking
@@ -206906,7 +206926,6 @@ const buildRequiredScript = (rest, decision, cost, model) => gen(function* () {
206906
206926
  const git = yield* GitService;
206907
206927
  const closeDecision = yield* decideCloseWindow;
206908
206928
  yield* (yield* Narrator).narrate(closeDecision.shouldClose ? "review-window: close" : "review-window: no-op");
206909
- const commitContext = decision.kind === "commit" ? rest.context : yield* contextAt(rest, decision.state, rest.actor, cost, model);
206910
206929
  const isAttempt = isAttemptDecision(decision);
206911
206930
  const steps = [
206912
206931
  ...closeDecision.shouldClose ? [{
@@ -206914,12 +206933,12 @@ const buildRequiredScript = (rest, decision, cost, model) => gen(function* () {
206914
206933
  command: buildCloseWindowScript(closeDecision.refs)
206915
206934
  }] : [],
206916
206935
  ...isAttempt ? [] : yield* steeringModeSteps(rest),
206917
- ...yield* renderDecision(git, rest, decision, commitContext, cost, model)
206936
+ ...yield* renderDecision(git, rest, decision, cost, model)
206918
206937
  ];
206919
206938
  return emitScripts(headPreconditions(rest.context.currentCommit), steps).required;
206920
206939
  });
206921
206940
  /**
206922
- * Decide the one resulting transition (commit or squash) for `gtd land`
206941
+ * Decide the one resulting transition (a commit) for `gtd land`
206923
206942
  * without performing it, authenticating as `rest.actor`. Refusals fail the
206924
206943
  * Effect with a formatted message; a no-op returns `subject: null` and empty
206925
206944
  * scripts.
@@ -206949,7 +206968,7 @@ const planLanding = (opts = {}) => gen(function* () {
206949
206968
  };
206950
206969
  }
206951
206970
  const decision = plan.decision;
206952
- if (decision.kind !== "commit" && decision.kind !== "squash") return yield* fail$2(/* @__PURE__ */ new Error(`gtd: internal error — plan kind "${plan.kind}" but decision kind "${decision.kind}"`));
206971
+ if (decision.kind !== "commit") return yield* fail$2(/* @__PURE__ */ new Error(`gtd: internal error — plan kind "${plan.kind}" but decision kind "${decision.kind}"`));
206953
206972
  yield* enforceStepGuards({
206954
206973
  rest,
206955
206974
  context: rest.context,
@@ -206959,14 +206978,13 @@ const planLanding = (opts = {}) => gen(function* () {
206959
206978
  kind: decision.kind,
206960
206979
  attempt: isAttemptDecision(decision)
206961
206980
  });
206962
- const targetState = decision.kind === "commit" ? decision.to : decision.state;
206963
- const restingState = decision.kind === "commit" ? decision.to : initialStateOf(rest.def);
206981
+ const restingState = decision.to;
206964
206982
  const settled = yield* collapsesToInitialState(rest, decision);
206965
- const openDecision = yield* decideAndNarrateOpenWindow(rest, targetState);
206983
+ const openDecision = yield* decideAndNarrateOpenWindow(rest, restingState);
206966
206984
  const required = yield* buildRequiredScript(rest, decision, opts.cost, opts.model);
206967
206985
  return {
206968
206986
  state: restingState,
206969
- subject: yield* previewSubject(decision, rest),
206987
+ subject: yield* previewSubject(decision),
206970
206988
  cost: opts.cost ?? null,
206971
206989
  model: opts.model ?? null,
206972
206990
  script: normalizeScriptNewline(combinedScript(required, openWindowScript(openDecision))),
@@ -206975,6 +206993,24 @@ const planLanding = (opts = {}) => gen(function* () {
206975
206993
  };
206976
206994
  });
206977
206995
  /**
206996
+ * `gtd summary`: print the prompt for an agent to write the process HEAD
206997
+ * closes or sits inside its own closing message. Writes nothing — no git, no
206998
+ * state transition, no file, no review-window bracket (see AGENTS.md: a
206999
+ * write-nothing command emits its own bracket only when it needs one; this
207000
+ * one never does). Refuses (throws, mapped to the runtime-error exit code) on
207001
+ * either of the two conditions `src/Summary.ts`'s `buildSummary` folds into
207002
+ * one `undefined`: the workflow declares no `summary:` template, or the
207003
+ * resolved run has no commits to name.
207004
+ */
207005
+ const runSummaryCommand = (out) => gen(function* () {
207006
+ const config = yield* (yield* ConfigService).load;
207007
+ const run = yield* summaryRun;
207008
+ const context = yield* summaryTemplateContext(run);
207009
+ const rendered = buildSummary(config.workflow, run, context);
207010
+ if (rendered === void 0) return yield* fail$2(/* @__PURE__ */ new Error("gtd summary: refused — either this workflow declares no \"summary:\" template, or there is no finished/in-flight process to summarize at HEAD"));
207011
+ out.write(rendered.endsWith("\n") ? rendered : rendered + "\n");
207012
+ });
207013
+ /**
206978
207014
  * `gtd land [--cost=<n>] [--model=<name>]`: land whatever the tree shows at
206979
207015
  * the currently resolved rest, authenticated as the rest's own actor.
206980
207016
  * Plain output writes `result.script` verbatim so `gtd land | sh` keeps
@@ -206990,7 +207026,7 @@ const runLandCommand = (opts, json, sh, out) => gen(function* () {
206990
207026
  });
206991
207027
  /**
206992
207028
  * `gtd --entry <state> [--var <name>=<value> ...]` (`actor` always `"human"`):
206993
- * start a brand new process at `<state>` — any declared, non-commit state.
207029
+ * start a brand new process at `<state>` — any declared state.
206994
207030
  * Writes an ordinary turn commit carrying zero or more `Gtd-Var:` trailers,
206995
207031
  * plus a `Gtd-Review-Base:` trailer when `<state>` declares a `reviewBase:`.
206996
207032
  * Commits via `commitAllWithPrefix` — capturing whatever the working tree
@@ -207073,8 +207109,8 @@ const runAbandonCommand = (out) => gen(function* () {
207073
207109
  out.write(combinedScript(required, ""));
207074
207110
  });
207075
207111
  /**
207076
- * `gtd restore`: hard-reset HEAD back to the pre-squash tip a squash or
207077
- * `gtd abandon` retained, undoing either.
207112
+ * `gtd restore`: hard-reset HEAD back to the tip `gtd abandon` (or the
207113
+ * initial-state collapse's own mixed reset) retained.
207078
207114
  *
207079
207115
  * Guarded by `restorability` so it never discards work it didn't create:
207080
207116
  * refuses on a dirty working tree, no retained history, or HEAD having
@@ -207087,7 +207123,7 @@ const runRestoreCommand = (out) => gen(function* () {
207087
207123
  if (isNone(retained)) return yield* fail$2(/* @__PURE__ */ new Error("gtd restore: no retained history to restore."));
207088
207124
  const tip = retained.value;
207089
207125
  const headHash = yield* git.resolveRef("HEAD");
207090
- const check = yield* restorability(git, headHash, yield* git.lastCommitMessage(), tip);
207126
+ const check = yield* restorability(git, headHash, tip);
207091
207127
  if (!check.ok) return yield* fail$2(/* @__PURE__ */ new Error(`gtd restore: ${check.reason} — HEAD ${headHash.slice(0, 7)} is ahead of the retained tip ${tip.slice(0, 7)}.`));
207092
207128
  const after = yield* restAt(tip);
207093
207129
  const steps = [
@@ -207504,6 +207540,7 @@ const dispatchVoidCommand = (command, json, sh, out) => {
207504
207540
  case "validate": return runValidateCommand(out);
207505
207541
  case "check": return runCheckCommand(command.mode, command.file, command.openQuestions ?? false);
207506
207542
  case "install": return runInstallCommand(out);
207543
+ case "summary": return runSummaryCommand(out);
207507
207544
  }
207508
207545
  };
207509
207546
  /**
@@ -207614,11 +207651,7 @@ const FLAGS = [
207614
207651
  decode: ([raw]) => right(raw ?? ""),
207615
207652
  scopeError: "gtd: --entry is only valid with no other command — use the bare `gtd --entry <state>` form; landing and entering are different verbs",
207616
207653
  valueHint: "<state>",
207617
- help: [
207618
- "(with no command at all) start a brand new process at",
207619
- "<state> — any declared, non-commit state — authenticated",
207620
- "as human"
207621
- ]
207654
+ help: ["(with no command at all) start a brand new process at", "<state> — any declared state — authenticated as human"]
207622
207655
  },
207623
207656
  {
207624
207657
  name: "--var",
@@ -207716,8 +207749,8 @@ const COMMAND_ROWS = [
207716
207749
  arity: "none",
207717
207750
  details: [
207718
207751
  "Land whatever the tree now shows at the currently resolved",
207719
- "rest — a human capture, an agent/check turn, an empty",
207720
- "attempt (a fruitless prompt turn), or a squash. Pass",
207752
+ "rest — a human capture, an agent/check turn, or an empty",
207753
+ "attempt (a fruitless prompt turn). Pass",
207721
207754
  "--cost=<n> (optionally --model=<name>) to record the",
207722
207755
  "just-finished invocation's token cost and model on the",
207723
207756
  "turn commit (summed into it.processCost/",
@@ -207747,12 +207780,12 @@ const COMMAND_ROWS = [
207747
207780
  kind: "restore",
207748
207781
  arity: "none",
207749
207782
  details: [
207750
- "Hard-reset HEAD back to the pre-squash tip retained by the",
207751
- "last squash/abandon (refs/worktree/gtd/history), undoing a",
207752
- "squash or bringing back an abandoned process's turns.",
207753
- "Refuses on a dirty working tree, when there is no retained",
207754
- "history, or when HEAD has advanced past the squash with",
207755
- "commits that would be lost"
207783
+ "Hard-reset HEAD back to the tip retained by the last",
207784
+ "abandon (refs/worktree/gtd/history), bringing back an",
207785
+ "abandoned process's turns. Refuses on a dirty working",
207786
+ "tree, when there is no retained history, or when HEAD has",
207787
+ "advanced past the retained tip with commits that would be",
207788
+ "lost"
207756
207789
  ]
207757
207790
  },
207758
207791
  {
@@ -207838,6 +207871,25 @@ const COMMAND_ROWS = [
207838
207871
  "'Writing your own driver'. Writes nothing: this installs",
207839
207872
  "knowledge into the calling agent's context, not files on disk."
207840
207873
  ]
207874
+ },
207875
+ {
207876
+ token: "summary",
207877
+ kind: "summary",
207878
+ arity: "none",
207879
+ details: [
207880
+ "Print the prompt for an agent to write the process HEAD",
207881
+ "closes or sits inside its own closing message — the entry",
207882
+ "commit, each human-authored commit (a review round, an",
207883
+ "answered question gate), the diff range to inspect, and",
207884
+ "it.processCost/processCostByModel. Writes nothing: no git,",
207885
+ "no state transition, no file, no session identity — the",
207886
+ "driver pipes the output to a cold agent and does what it",
207887
+ "wants with the result (a squash, an amend, a PR body).",
207888
+ "Refuses (exit 1) when the workflow declares no summary:",
207889
+ "template, or when the resolved run has no commits to name",
207890
+ "— runnable any time before the next thing lands on the",
207891
+ "branch"
207892
+ ]
207841
207893
  }
207842
207894
  ];
207843
207895
  const commandByToken = (token) => COMMAND_ROWS.find((r) => r.token === token);