@pmelab/gtd 27.1.0 → 27.2.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.
Files changed (35) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/README.md +16 -9
  3. package/dist/chunks/registry-CP3YuV9j.mjs +101 -0
  4. package/dist/chunks/{reserved-BL9krPao.mjs → reserved-B2QaImnN.mjs} +41 -73
  5. package/dist/chunks/tail-BnhIxCYv.mjs +81 -0
  6. package/dist/gtd.bundle.mjs +5 -2
  7. package/dist/testkit.mjs +5 -2
  8. package/dist/workflows/cleanup.mjs +37 -0
  9. package/dist/workflows/feature.mjs +2 -1
  10. package/dist/workflows/fix.mjs +2 -1
  11. package/dist/workflows/review.mjs +2 -1
  12. package/dist/workflows/rollout.mjs +33 -0
  13. package/dist/workflows.mjs +220 -21
  14. package/package.json +11 -1
  15. package/src/flags/index.test.ts +28 -0
  16. package/src/flags/index.ts +9 -4
  17. package/src/testkit/steps.ts +26 -0
  18. package/src/testkit/testkit.feature +8 -1
  19. package/src/workflows/cleanup/cleanup.feature +323 -0
  20. package/src/workflows/cleanup/cleanup.test.ts +272 -0
  21. package/src/workflows/cleanup/cleanup.ts +52 -0
  22. package/src/workflows/cleanup/index.ts +6 -0
  23. package/src/workflows/index.ts +3 -1
  24. package/src/workflows/rollout/index.ts +6 -0
  25. package/src/workflows/rollout/rollout.feature +214 -0
  26. package/src/workflows/rollout/rollout.test.ts +167 -0
  27. package/src/workflows/rollout/rollout.ts +44 -0
  28. package/src/workflows/shared/health.test.ts +39 -0
  29. package/src/workflows/shared/health.ts +30 -7
  30. package/src/workflows/shared/options.test.ts +22 -0
  31. package/src/workflows/shared/options.ts +19 -0
  32. package/src/workflows/shared/registry.test.ts +305 -0
  33. package/src/workflows/shared/registry.ts +158 -0
  34. package/src/workflows/shared/tail.test.ts +36 -2
  35. package/src/workflows/shared/tail.ts +30 -18
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gtd",
3
- "version": "27.1.0",
3
+ "version": "27.2.0",
4
4
  "description": "Drive the gtd loop inside Claude Code: agent turns run as subagents, gtd decides every beat",
5
5
  "author": {
6
6
  "name": "Philipp Melab"
package/README.md CHANGED
@@ -552,6 +552,13 @@ unknown key. `gtd.config.ts` is the only repository config: gtd 23 removed the
552
552
  home directory — fails every command until you delete it. See
553
553
  [Migrating from `.gtdrc`](https://github.com/pmelab/gtd/blob/main/docs/configuration.md#migrating-from-gtdrc).
554
554
 
555
+ ### Rolling out and cleaning up release flags
556
+
557
+ Two more bundled workflows retire a release flag:
558
+ `gtd --workflow rollout --var flag=<name>` turns it default-on,
559
+ `gtd --workflow cleanup --var flag=<name>` removes it afterwards. See
560
+ [Feature flags](docs/configuration.md#rolling-out-and-cleaning-up-a-release-flag).
561
+
555
562
  ## Checking a range for stray files
556
563
 
557
564
  ```sh
@@ -599,15 +606,15 @@ are not process history: `gtd history` does not list them, and the
599
606
  gtd is one package, `@pmelab/gtd`, and every entrypoint shares its version and
600
607
  [SemVer promise](https://github.com/pmelab/gtd/blob/main/COMPATIBILITY.md).
601
608
 
602
- | Import | What it is |
603
- | -------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
604
- | `@pmelab/gtd/flows` | The flow API a workflow is written in: the steps (`agent`, `human`, `run`, …), workflow factories, `defineConfig` and `FLOWS_PROTOCOL`. |
605
- | `@pmelab/gtd/wire` | The driver protocol: `WIRE_SCHEMA`, the exit codes and the types of every `--json` document. |
606
- | `@pmelab/gtd/steering` | The steering-file formats (`qa`, `review`) and the review-note readers. |
607
- | `@pmelab/gtd/workflow-kit` | Policy-free building blocks to compose a workflow from: health checks, quality laps, scenario freezing, review tails. |
608
- | `@pmelab/gtd/workflows` | Every shipped workflow and all its parts in one module; also resolvable as `@pmelab/gtd/workflow`. |
609
- | `@pmelab/gtd/workflows/feature`, `@pmelab/gtd/workflows/review`, `@pmelab/gtd/workflows/fix` | One shipped workflow each: its factory as the default export, its parts, and the reserved exports (`defaults`, `envDefaults`, `summary`, `steering`, `skills`, `access`). `gtd install` imports these. |
610
- | `@pmelab/gtd/testkit` | Runs any workflow against the real engine, in an in-memory or a real repository. Needs `vitest` and `quickpickle`, optional peer dependencies. |
609
+ | Import | What it is |
610
+ | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
611
+ | `@pmelab/gtd/flows` | The flow API a workflow is written in: the steps (`agent`, `human`, `run`, …), workflow factories, `defineConfig` and `FLOWS_PROTOCOL`. |
612
+ | `@pmelab/gtd/wire` | The driver protocol: `WIRE_SCHEMA`, the exit codes and the types of every `--json` document. |
613
+ | `@pmelab/gtd/steering` | The steering-file formats (`qa`, `review`) and the review-note readers. |
614
+ | `@pmelab/gtd/workflow-kit` | Policy-free building blocks to compose a workflow from: health checks, quality laps, scenario freezing, review tails. |
615
+ | `@pmelab/gtd/workflows` | Every shipped workflow and all its parts in one module; also resolvable as `@pmelab/gtd/workflow`. |
616
+ | `@pmelab/gtd/workflows/feature`, `@pmelab/gtd/workflows/review`, `@pmelab/gtd/workflows/fix`, `@pmelab/gtd/workflows/rollout`, `@pmelab/gtd/workflows/cleanup` | One shipped workflow each: its factory as the default export, its parts, and the reserved exports (`defaults`, `envDefaults`, `summary`, `steering`, `skills`, `access`). `gtd install` imports these. |
617
+ | `@pmelab/gtd/testkit` | Runs any workflow against the real engine, in an in-memory or a real repository. Needs `vitest` and `quickpickle`, optional peer dependencies. |
611
618
 
612
619
  Types come from the TypeScript sources the package ships. Configs never need an
613
620
  install for any of these but `./testkit`: gtd resolves a `gtd.config.ts`'s
@@ -0,0 +1,101 @@
1
+ import { read, refuse } from "../flows.mjs";
2
+ //#region src/workflows/shared/registry.ts
3
+ const FILL = "";
4
+ const commentLength = (rest) => {
5
+ const end = rest.startsWith("//") ? rest.indexOf("\n") : rest.indexOf("*/") + 2;
6
+ return end <= 0 ? rest.length : end;
7
+ };
8
+ const stringEnd = (text, i, quote) => {
9
+ let j = i + 1;
10
+ while (j < text.length && text[j] !== quote) j += text[j] === "\\" ? 2 : 1;
11
+ return Math.min(j, text.length);
12
+ };
13
+ const mask = (text) => {
14
+ let out = "";
15
+ let i = 0;
16
+ while (i < text.length) {
17
+ const c = text[i];
18
+ const rest = text.slice(i);
19
+ if (rest.startsWith("//") || rest.startsWith("/*")) {
20
+ const len = commentLength(rest);
21
+ out += FILL.repeat(len);
22
+ i += len;
23
+ } else if (c === "\"" || c === "'" || c === "`") {
24
+ const j = stringEnd(text, i, c);
25
+ out += c + FILL.repeat(j - i - 1) + (j < text.length ? c : "");
26
+ i = j + 1;
27
+ } else {
28
+ out += c;
29
+ i += 1;
30
+ }
31
+ }
32
+ return out;
33
+ };
34
+ const escapeRegExp = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
35
+ const entrySpan = (text, name) => {
36
+ const quoted = escapeRegExp(name);
37
+ const re = new RegExp(`\\bname\\s*:\\s*(["'\`])${quoted}\\1`, "g");
38
+ const masked = mask(text);
39
+ for (const hit of text.matchAll(re)) {
40
+ if (masked[hit.index] === FILL) continue;
41
+ const start = masked.lastIndexOf("{", hit.index);
42
+ const close = masked.indexOf("}", hit.index);
43
+ return start < 0 || close < 0 ? void 0 : {
44
+ start,
45
+ end: close + 1
46
+ };
47
+ }
48
+ };
49
+ const DEFAULT_ON = /\bdefaultOn\s*:\s*(true|false)\s*,?/;
50
+ const defaultOnHit = (body) => DEFAULT_ON.exec(mask(body));
51
+ const defaultOnValue = (body) => defaultOnHit(body)?.[1];
52
+ const KIND = /\bkind\s*:\s*["'`]/;
53
+ const registryEntry = (text, name) => {
54
+ const span = entrySpan(text, name);
55
+ if (span === void 0) return void 0;
56
+ const body = text.slice(span.start, span.end);
57
+ const hit = KIND.exec(mask(body));
58
+ return {
59
+ kind: (hit === null ? null : /^(\w+)["'`]/.exec(body.slice(hit.index + hit[0].length)))?.[1] ?? "",
60
+ defaultOn: defaultOnValue(body) === "true"
61
+ };
62
+ };
63
+ const canonical = (body) => {
64
+ const hit = defaultOnHit(body);
65
+ const kept = hit === null ? body : body.slice(0, hit.index) + body.slice(hit.index + hit[0].length);
66
+ const masked = mask(kept);
67
+ return kept.split("").filter((c, i) => masked[i] === FILL || !(/\s/.test(c) || c === "," && /^\s*}/.test(masked.slice(i + 1)))).join("");
68
+ };
69
+ /**
70
+ * [] when `after` differs from `before` only by the named entry's `defaultOn`
71
+ * going absent/false → true (whitespace and trailing commas inside that entry
72
+ * ignored, so oxfmt re-wrapping it passes); else one line per fault.
73
+ */
74
+ const flipProblems = (before, after, name) => {
75
+ const was = entrySpan(before, name);
76
+ const now = entrySpan(after, name);
77
+ if (was === void 0) return [`no entry "${name}" before the turn`];
78
+ if (now === void 0) return [`entry "${name}" is gone`];
79
+ const faults = [];
80
+ if (before.slice(0, was.start) !== after.slice(0, now.start)) faults.push("text before the entry changed");
81
+ if (before.slice(was.end) !== after.slice(now.end)) faults.push("text after the entry changed");
82
+ const oldBody = before.slice(was.start, was.end);
83
+ const newBody = after.slice(now.start, now.end);
84
+ if (canonical(oldBody) !== canonical(newBody)) faults.push(`entry "${name}" changed beyond defaultOn`);
85
+ if (defaultOnValue(newBody) !== "true") faults.push(`"${name}" is not set to defaultOn: true`);
86
+ return faults;
87
+ };
88
+ /** `path:line` for every `GTD_FLAG_<NAME>` in shipped sources; re-states scripts/lint-flags.ts' rule by hand. */
89
+ const flagReferences = (files, name) => {
90
+ const pattern = new RegExp(`\\bGTD_FLAG_${escapeRegExp(name.toUpperCase())}\\b`);
91
+ return files.filter(({ path }) => !/\.(test|fixture|stories)\.tsx?$/.test(path)).flatMap(({ path, text }) => text.split("\n").flatMap((line, i) => pattern.test(line) ? [`${path}:${i + 1}`] : []));
92
+ };
93
+ const requireFlag = (workflow, registryPath, name, defaultOn) => {
94
+ if (name === "") return refuse(`gtd: ${workflow} needs --var flag=<name>`);
95
+ const entry = registryEntry(read(registryPath) ?? "", name);
96
+ if (entry === void 0) return refuse(`gtd: ${workflow}: no flag "${name}" in ${registryPath}`);
97
+ if (entry.kind !== "release") return refuse(`gtd: ${workflow}: flag "${name}" is ${entry.kind}, not release`);
98
+ if (entry.defaultOn !== defaultOn) return refuse(defaultOn ? `gtd: ${workflow}: flag "${name}" is not default-on — roll it out first` : `gtd: ${workflow}: flag "${name}" is already default-on`);
99
+ };
100
+ //#endregion
101
+ export { requireFlag as i, flipProblems as n, registryEntry as r, flagReferences as t };
@@ -1,5 +1,5 @@
1
- import { accessFor, agent, answered, changesSince, check, codeThreads, defineWorkflow, env, head, human, judge, numeric, quote, read, refuse, removeScript, run, scope, showScript, skillsFor, start, vars } from "../flows.mjs";
2
- import { escalation as escalation$1, fixFindings, gate as gate$1, healthy as healthy$1, lensScopes, lensesOf, qualityLap as qualityLap$1, removedAssertions, reviewToHandOff } from "../workflow-kit.mjs";
1
+ import { accessFor, agent, answered, changesSince, check, codeThreads, defineWorkflow, env, head, human, judge, numeric, quote, skillsFor, start, vars } from "../flows.mjs";
2
+ import { escalation as escalation$1, gate as gate$1, healthy as healthy$1, lensScopes, lensesOf, removedAssertions } from "../workflow-kit.mjs";
3
3
  import { c as String$, g as standardSchemaV1, h as optionalWith, l as Struct } from "./Schema-CyImoHTj.mjs";
4
4
  //#region src/workflows/shared/prose.ts
5
5
  const skillsPreamble = `- Load whatever's listed here that your harness actually has installed,
@@ -1157,12 +1157,22 @@ const escalationSteps = {
1157
1157
  stop: escalate,
1158
1158
  exhausted: escalationExhausted
1159
1159
  };
1160
+ const guarded = (turn, guard) => async (...a) => {
1161
+ await turn(...a);
1162
+ guard?.();
1163
+ };
1164
+ const guardedSteps = (guard) => ({
1165
+ limit: escalationSteps.limit,
1166
+ describe: guarded(escalationSteps.describe, guard),
1167
+ stop: guarded(escalationSteps.stop, guard),
1168
+ exhausted: guarded(escalationSteps.exhausted, guard)
1169
+ });
1160
1170
  /**
1161
1171
  * Hand a red suite that repeated attempts could not fix to a person: an
1162
1172
  * agent writes `.gtd/ESCALATION.md`, a human narrows it. From the third round
1163
1173
  * on, the human is told the budget is spent instead.
1164
1174
  */
1165
- const escalation = (count) => escalation$1(count, escalationSteps);
1175
+ const escalation = (count, guard) => escalation$1(count, guardedSteps(guard));
1166
1176
  /** "Is this red round the same failure as the last one?" — asked of two reports, or of nothing when one is empty. */
1167
1177
  const retryQuestion = (comparable) => comparable ? {
1168
1178
  id: "verdict",
@@ -1198,21 +1208,25 @@ const runSuite = (options) => check("health.check", env.testCommand ?? "", {
1198
1208
  * first once `FIX_CAP` fixes are spent, or a judge calls the failure
1199
1209
  * identical to the previous round's.
1200
1210
  */
1201
- const healthy = (fix, options = {}) => healthy$1(fix, {
1211
+ const healthy = (fix, options = {}) => healthy$1(guarded(fix, options.guard), {
1202
1212
  check: () => runSuite(options),
1203
1213
  report: FEEDBACK,
1204
1214
  fixCap: 3,
1205
1215
  fixesSoFar: options.fixesSoFar ?? 0,
1206
1216
  sameFailure,
1207
1217
  escalations: options.escalations ?? { rounds: 0 },
1208
- escalation: escalationSteps
1218
+ escalation: guardedSteps(options.guard)
1209
1219
  });
1210
- /** Hold the process at `<name>.blocked` until the suite is green. */
1211
- const gate = (name, message) => gate$1(name, () => baseline("check"), () => human("blocked", {
1220
+ /**
1221
+ * Hold the process at `<name>.blocked` until the suite is green. `guard` runs
1222
+ * after each `blocked` landing only — never after a check, whose refusal would
1223
+ * re-run the same script forever.
1224
+ */
1225
+ const gate = (name, message, guard) => gate$1(name, () => baseline("check"), guarded(() => human("blocked", {
1212
1226
  message,
1213
1227
  label: "Baseline is red",
1214
1228
  file: FEEDBACK
1215
- }));
1229
+ }), guard));
1216
1230
  //#endregion
1217
1231
  //#region src/workflows/shared/vars.ts
1218
1232
  /** Process settings. */
@@ -1259,73 +1273,27 @@ const shipped = (flow, doors, base) => defineWorkflow(standardSchemaV1(ShippedOp
1259
1273
  doors,
1260
1274
  base
1261
1275
  }));
1262
- //#endregion
1263
- //#region src/workflows/shared/tail.ts
1264
- /** The reviewer's own `.gtd/REVIEW.md`, kept beside the human's notes so `fix` can tell them apart. */
1265
- const REVIEW_ORIG = ".gtd/REVIEW.orig.md";
1266
- /**
1267
- * One review turn per lens over the whole change, each appending every
1268
- * finding to `.gtd/QUALITY.md`. Resolves `"findings"` when that file
1269
- * has any.
1270
- */
1271
- const qualityLap = () => qualityLap$1(lensesOf(vars.qualityReviews ?? ""), reviewQuality, QUALITY);
1272
- /** Resolves `true` once `.gtd/QUALITY.md` is resolved, `false` when the fix cap escalated instead. */
1273
- const fixQualityFindings = (escalations) => fixFindings({
1274
- fix: fixQuality,
1275
- findings: QUALITY,
1276
- cap: 3,
1277
- escalate: () => escalation(escalations)
1276
+ const FlagOptions = Struct({
1277
+ ...ShippedOptions.fields,
1278
+ flagRegistry: setting
1278
1279
  });
1279
- /** `.gtd/REVIEW.md` removed at the end of a round at commit `round`. */
1280
- const closeReview = (round) => run("review.closing", removeScript([REVIEW, REVIEW_ORIG]), {
1281
- label: "Closing the review",
1282
- base: round
1283
- });
1284
- /** Refuses while a reviewer's notes still await `gtd door fix`. */
1285
- const refusePendingHandOff = () => {
1286
- if (read(".gtd/REVIEW.orig.md") !== void 0) refuse(`gtd: ${REVIEW_ORIG} is a pending hand-off — run \`gtd door fix\`, or remove ${REVIEW} and ${REVIEW_ORIG}.`);
1287
- };
1288
- /**
1289
- * The build tail: fix (when entered red), keep green, the quality lap, then
1290
- * `finish` — the human review, as the calling workflow runs it. `green`: the
1291
- * caller just left the full suite green (the package loop), so no run opens it.
1292
- */
1293
- const tail = (fixFirst, finish, green = false) => scope("build", async () => {
1294
- const escalations = { rounds: 0 };
1295
- const fix = fixCheck;
1296
- const repair = async () => {
1297
- await fix();
1298
- await healthy(fix, {
1299
- fixesSoFar: 1,
1300
- escalations
1301
- });
1280
+ const flagShipped = (flow) => defineWorkflow(standardSchemaV1(FlagOptions, {
1281
+ onExcessProperty: "error",
1282
+ errors: "all"
1283
+ }), (options) => {
1284
+ const flagDefaults = {
1285
+ ...defaults,
1286
+ flag: "",
1287
+ flagRegistry: "src/flags/index.ts"
1288
+ };
1289
+ return {
1290
+ flow,
1291
+ defaults: over(flagDefaults, options),
1292
+ envDefaults: over(envDefaults, options),
1293
+ doors: {},
1294
+ base: void 0
1302
1295
  };
1303
- if (fixFirst) await repair();
1304
- else if (!green) await healthy(fix, { escalations });
1305
- if (await qualityLap() === "findings") if (await fixQualityFindings(escalations)) await healthy(fix, { escalations });
1306
- else await repair();
1307
- return finish(escalations);
1308
- });
1309
- /**
1310
- * The review and fix workflows' human review since `base`: a sign-off closes
1311
- * `.gtd/REVIEW.md`; a note leaves it, with the reviewer's own version as
1312
- * `REVIEW_ORIG`, for the next `fix` to read — never a re-plan.
1313
- */
1314
- const handOffReview = (base, escalations) => reviewToHandOff(base, {
1315
- file: REVIEW,
1316
- reviewing,
1317
- fixRisks,
1318
- keepGreen: () => healthy(fixCheck, { escalations }),
1319
- awaitReview: (b) => awaitReview(b, handOffAwaitReviewMessage(b)),
1320
- reviewMissing,
1321
- close: closeReview,
1322
- handOff: (reviewed) => run("review.handing-off", showScript(reviewed, REVIEW, REVIEW_ORIG), { label: "Handing your notes to fix" }),
1323
- threadsPending: "gtd land: open-threads: a thread in .gtd/REVIEW.md or an `H:` code comment waits on the agent — nothing answers it here; delete it, or turn it into a note for fix.",
1324
- unparsed: "gtd land: review-doc: your edit to .gtd/REVIEW.md contains no note fix can read — restore the deleted chunk, or write the note as a line under its entry.",
1325
- deleted: "gtd land: review-doc: .gtd/REVIEW.md was deleted — restore it, or leave a note to hand to fix."
1326
1296
  });
1327
- /** The tail the review and fix workflows run: ends at the hand-off review since `base`. */
1328
- const handOffTail = (fixFirst, base) => tail(fixFirst, (escalations) => handOffReview(base, escalations));
1329
1297
  //#endregion
1330
1298
  //#region src/workflows/shared/skills.ts
1331
1299
  const skills = (vars) => ({
@@ -1369,4 +1337,4 @@ const steering = {
1369
1337
  [REVIEW]: "review"
1370
1338
  };
1371
1339
  //#endregion
1372
- export { unwindFailedMessage as $, architectureDecomposePrompt as A, designSystem as B, fixRisks as C, agentWithSkills as D, reviewing as E, buildReviewFixNitsPrompt as F, packagesItemBuildingPrompt as G, finisherSystem as H, buildReviewTriageMessage as I, reviewEditsCapture as J, packagesItemFixSuitePrompt as K, builderSystem as L, buildReviewAnswerQuestionsPrompt as M, buildReviewAwaitAfterDeferMessage as N, architectSystem as O, buildReviewCollectingPrompt as P, startGateBlockedMessage as Q, deferNotesScript as R, fixCheck as S, reviewMissing as T, fixReviewNotesPrompt as U, designTriagePrompt as V, idleMessage as W, reviewNotesCapture as X, reviewGateBlockedMessage as Y, reviewerSystem as Z, FEEDBACK as _, REVIEW_ORIG as a, awaitReview as b, refusePendingHandOff as c, defaults as d, unwindFailure as et, envDefaults as f, ARCHITECTURE as g, healthy as h, skills as i, architectureGateAnswerMessage as j, architectureAuthorPrompt as k, tail as l, gate as m, summary as n, closeReview as o, baseline as p, reviewEditNotesCapture as q, access as r, handOffTail as s, steering as t, shipped as u, REQUIREMENTS as v, planner as w, coder as x, REVIEW as y, designGateAnswerMessage as z };
1340
+ export { reviewerSystem as $, architectureAuthorPrompt as A, designGateAnswerMessage as B, fixRisks as C, reviewing as D, reviewQuality as E, buildReviewCollectingPrompt as F, handOffAwaitReviewMessage as G, designTriagePrompt as H, buildReviewFixNitsPrompt as I, packagesItemFixSuitePrompt as J, idleMessage as K, buildReviewTriageMessage as L, architectureGateAnswerMessage as M, buildReviewAnswerQuestionsPrompt as N, agentWithSkills as O, buildReviewAwaitAfterDeferMessage as P, reviewNotesCapture as Q, builderSystem as R, fixQuality as S, reviewMissing as T, finisherSystem as U, designSystem as V, fixReviewNotesPrompt as W, reviewEditsCapture as X, reviewEditNotesCapture as Y, reviewGateBlockedMessage as Z, REQUIREMENTS as _, flagShipped as a, coder as b, envDefaults as c, gate as d, startGateBlockedMessage as et, guarded as f, QUALITY as g, FEEDBACK as h, skills as i, architectureDecomposePrompt as j, architectSystem as k, baseline as l, ARCHITECTURE as m, summary as n, unwindFailure as nt, shipped as o, healthy as p, packagesItemBuildingPrompt as q, access as r, defaults as s, steering as t, unwindFailedMessage as tt, escalation as u, REVIEW as v, planner as w, fixCheck as x, awaitReview as y, deferNotesScript as z };
@@ -0,0 +1,81 @@
1
+ import { read, refuse, removeScript, run, scope, showScript, vars } from "../flows.mjs";
2
+ import { fixFindings, lensesOf, qualityLap as qualityLap$1, reviewToHandOff } from "../workflow-kit.mjs";
3
+ import { C as fixRisks, D as reviewing, E as reviewQuality, G as handOffAwaitReviewMessage, S as fixQuality, T as reviewMissing, f as guarded, g as QUALITY, p as healthy, u as escalation, v as REVIEW, x as fixCheck, y as awaitReview } from "./reserved-B2QaImnN.mjs";
4
+ //#region src/workflows/shared/tail.ts
5
+ /** The reviewer's own `.gtd/REVIEW.md`, kept beside the human's notes so `fix` can tell them apart. */
6
+ const REVIEW_ORIG = ".gtd/REVIEW.orig.md";
7
+ /**
8
+ * One review turn per lens over the whole change, each appending every
9
+ * finding to `.gtd/QUALITY.md`. Resolves `"findings"` when that file
10
+ * has any.
11
+ */
12
+ const qualityLap = (guard) => qualityLap$1(lensesOf(vars.qualityReviews ?? ""), guarded(reviewQuality, guard), QUALITY);
13
+ /** Resolves `true` once `.gtd/QUALITY.md` is resolved, `false` when the fix cap escalated instead. */
14
+ const fixQualityFindings = (escalations, guard) => fixFindings({
15
+ fix: guarded(fixQuality, guard),
16
+ findings: QUALITY,
17
+ cap: 3,
18
+ escalate: () => escalation(escalations, guard)
19
+ });
20
+ /** `.gtd/REVIEW.md` removed at the end of a round at commit `round`. */
21
+ const closeReview = (round) => run("review.closing", removeScript([REVIEW, REVIEW_ORIG]), {
22
+ label: "Closing the review",
23
+ base: round
24
+ });
25
+ /** Refuses while a reviewer's notes still await `gtd door fix`. */
26
+ const refusePendingHandOff = () => {
27
+ if (read(".gtd/REVIEW.orig.md") !== void 0) refuse(`gtd: ${REVIEW_ORIG} is a pending hand-off — run \`gtd door fix\`, or remove ${REVIEW} and ${REVIEW_ORIG}.`);
28
+ };
29
+ /**
30
+ * The build tail: fix (when entered red), keep green, the quality lap, then
31
+ * `finish` — the human review, as the calling workflow runs it. `green`: the
32
+ * caller just left the full suite green (the package loop), so no run opens it.
33
+ */
34
+ const tail = (fixFirst, finish, green = false, guard) => scope("build", async () => {
35
+ const escalations = { rounds: 0 };
36
+ const fix = fixCheck;
37
+ const repair = async () => {
38
+ await guarded(fix, guard)();
39
+ await healthy(fix, {
40
+ fixesSoFar: 1,
41
+ escalations,
42
+ guard
43
+ });
44
+ };
45
+ if (fixFirst) await repair();
46
+ else if (!green) await healthy(fix, {
47
+ escalations,
48
+ guard
49
+ });
50
+ if (await qualityLap(guard) === "findings") if (await fixQualityFindings(escalations, guard)) await healthy(fix, {
51
+ escalations,
52
+ guard
53
+ });
54
+ else await repair();
55
+ return finish(escalations);
56
+ });
57
+ /**
58
+ * The review and fix workflows' human review since `base`: a sign-off closes
59
+ * `.gtd/REVIEW.md`; a note leaves it, with the reviewer's own version as
60
+ * `REVIEW_ORIG`, for the next `fix` to read — never a re-plan.
61
+ */
62
+ const handOffReview = (base, escalations, guard) => reviewToHandOff(base, {
63
+ file: REVIEW,
64
+ reviewing: guarded(reviewing, guard),
65
+ fixRisks: guarded(fixRisks, guard),
66
+ keepGreen: () => healthy(fixCheck, {
67
+ escalations,
68
+ guard
69
+ }),
70
+ awaitReview: (b) => awaitReview(b, handOffAwaitReviewMessage(b)),
71
+ reviewMissing,
72
+ close: closeReview,
73
+ handOff: (reviewed) => run("review.handing-off", showScript(reviewed, REVIEW, REVIEW_ORIG), { label: "Handing your notes to fix" }),
74
+ threadsPending: "gtd land: open-threads: a thread in .gtd/REVIEW.md or an `H:` code comment waits on the agent — nothing answers it here; delete it, or turn it into a note for fix.",
75
+ unparsed: "gtd land: review-doc: your edit to .gtd/REVIEW.md contains no note fix can read — restore the deleted chunk, or write the note as a line under its entry.",
76
+ deleted: "gtd land: review-doc: .gtd/REVIEW.md was deleted — restore it, or leave a note to hand to fix."
77
+ });
78
+ /** The tail the review and fix workflows run: ends at the hand-off review since `base`. */
79
+ const handOffTail = (fixFirst, base, guard) => tail(fixFirst, (escalations) => handOffReview(base, escalations, guard), false, guard);
80
+ //#endregion
81
+ export { tail as a, refusePendingHandOff as i, closeReview as n, handOffTail as r, REVIEW_ORIG as t };
@@ -20964,7 +20964,6 @@ const restorability = (git, headHash, tipHash) => gen(function* () {
20964
20964
  //#region src/flags/index.ts
20965
20965
  const FLAGS$1 = [];
20966
20966
  const BOOL = {
20967
- "": false,
20968
20967
  "0": false,
20969
20968
  false: false,
20970
20969
  "1": true,
@@ -20972,9 +20971,13 @@ const BOOL = {
20972
20971
  };
20973
20972
  const resolveFlags = (env, registry = FLAGS$1) => {
20974
20973
  const out = {};
20975
- for (const { name } of registry) {
20974
+ for (const { name, defaultOn } of registry) {
20976
20975
  const variable = `GTD_FLAG_${name.toUpperCase()}`;
20977
20976
  const key = (env[variable] ?? "").toLowerCase();
20977
+ if (key === "") {
20978
+ out[name] = defaultOn ?? false;
20979
+ continue;
20980
+ }
20978
20981
  if (!Object.hasOwn(BOOL, key)) throw new Error(`${variable} must be 1, 0, true or false`);
20979
20982
  out[name] = BOOL[key];
20980
20983
  }
package/dist/testkit.mjs CHANGED
@@ -6091,7 +6091,6 @@ const restorability = (git, headHash, tipHash) => gen(function* () {
6091
6091
  //#region src/flags/index.ts
6092
6092
  const FLAGS$1 = [];
6093
6093
  const BOOL = {
6094
- "": false,
6095
6094
  "0": false,
6096
6095
  false: false,
6097
6096
  "1": true,
@@ -6099,9 +6098,13 @@ const BOOL = {
6099
6098
  };
6100
6099
  const resolveFlags = (env, registry = FLAGS$1) => {
6101
6100
  const out = {};
6102
- for (const { name } of registry) {
6101
+ for (const { name, defaultOn } of registry) {
6103
6102
  const variable = `GTD_FLAG_${name.toUpperCase()}`;
6104
6103
  const key = (env[variable] ?? "").toLowerCase();
6104
+ if (key === "") {
6105
+ out[name] = defaultOn ?? false;
6106
+ continue;
6107
+ }
6105
6108
  if (!Object.hasOwn(BOOL, key)) throw new Error(`${variable} must be 1, 0, true or false`);
6106
6109
  out[name] = BOOL[key];
6107
6110
  }
@@ -0,0 +1,37 @@
1
+ import { agent, changes, glob, read, refuse, scope, start, vars } from "../flows.mjs";
2
+ import { a as flagShipped, b as coder, c as envDefaults, i as skills, n as summary, r as access, s as defaults, t as steering } from "../chunks/reserved-B2QaImnN.mjs";
3
+ import { i as refusePendingHandOff, r as handOffTail } from "../chunks/tail-BnhIxCYv.mjs";
4
+ import { i as requireFlag, r as registryEntry, t as flagReferences } from "../chunks/registry-CP3YuV9j.mjs";
5
+ //#region src/workflows/cleanup/cleanup.ts
6
+ const removingPrompt = (name, registry) => `Clean up the release flag "${name}", which is default-on: delete its entry in ${registry}, and remove every \`GTD_FLAG_${name.toUpperCase()}\` check from the shipped sources. Keep the flag-on path; delete code only the off path reached, including tests that pin the off path.`;
7
+ const cleanupFlow = async () => {
8
+ const registry = vars.flagRegistry ?? "";
9
+ const name = vars.flag ?? "";
10
+ refusePendingHandOff();
11
+ requireFlag("cleanup", registry, name, true);
12
+ let scanned = false;
13
+ const guard = () => {
14
+ const turn = scanned ? changes() : void 0;
15
+ if ((turn === void 0 || turn.some((c) => c.path === registry)) && registryEntry(read(registry) ?? "", name) !== void 0) refuse(`gtd land: cleanup: ${registry} still declares flag "${name}"`);
16
+ const hits = flagReferences((turn === void 0 ? [...glob("src/**/*.ts"), ...glob("src/**/*.tsx")] : turn.filter((c) => c.status !== "deleted").map((c) => c.path).filter((path) => path.startsWith("src/") && /\.tsx?$/.test(path))).map((path) => ({
17
+ path,
18
+ text: read(path) ?? ""
19
+ })), name);
20
+ if (hits.length > 0) refuse(`gtd land: cleanup: ${hits.join(", ")} still names GTD_FLAG_${name.toUpperCase()}`);
21
+ };
22
+ await scope("cleanup", async () => {
23
+ await agent("removing", removingPrompt(name, registry), {
24
+ label: `Removing ${name}`,
25
+ model: coder()
26
+ });
27
+ guard();
28
+ scanned = true;
29
+ });
30
+ await handOffTail(false, start(), guard);
31
+ };
32
+ const cleanup = flagShipped(cleanupFlow);
33
+ //#endregion
34
+ //#region src/workflows/cleanup/index.ts
35
+ var cleanup_default = cleanup;
36
+ //#endregion
37
+ export { access, cleanup, cleanupFlow, cleanup_default as default, defaults, envDefaults, skills, steering, summary };
@@ -1,6 +1,7 @@
1
1
  import { answered, changes, changesSince, glob, hasThreadFor, head, human, judge, numeric, read, refuse, removeScript, requireAnswers, requireProgress, requireReplies, requireRevert, requireThreadsClosed, restoreScript, revertScript, run, scope, start, vars } from "../flows.mjs";
2
2
  import { review as review$1 } from "../workflow-kit.mjs";
3
- import { $ as unwindFailedMessage, A as architectureDecomposePrompt, B as designSystem, C as fixRisks, D as agentWithSkills, E as reviewing, F as buildReviewFixNitsPrompt, G as packagesItemBuildingPrompt, I as buildReviewTriageMessage, J as reviewEditsCapture, K as packagesItemFixSuitePrompt, L as builderSystem, M as buildReviewAnswerQuestionsPrompt, N as buildReviewAwaitAfterDeferMessage, O as architectSystem, P as buildReviewCollectingPrompt, Q as startGateBlockedMessage, R as deferNotesScript, S as fixCheck, T as reviewMissing, V as designTriagePrompt, W as idleMessage, X as reviewNotesCapture, Z as reviewerSystem, _ as FEEDBACK, b as awaitReview, c as refusePendingHandOff, d as defaults, et as unwindFailure, f as envDefaults, g as ARCHITECTURE, h as healthy, i as skills, j as architectureGateAnswerMessage, k as architectureAuthorPrompt, l as tail, m as gate, n as summary, o as closeReview, q as reviewEditNotesCapture, r as access, t as steering, u as shipped, v as REQUIREMENTS, w as planner, x as coder, y as REVIEW, z as designGateAnswerMessage } from "../chunks/reserved-BL9krPao.mjs";
3
+ import { $ as reviewerSystem, A as architectureAuthorPrompt, B as designGateAnswerMessage, C as fixRisks, D as reviewing, F as buildReviewCollectingPrompt, H as designTriagePrompt, I as buildReviewFixNitsPrompt, J as packagesItemFixSuitePrompt, K as idleMessage, L as buildReviewTriageMessage, M as architectureGateAnswerMessage, N as buildReviewAnswerQuestionsPrompt, O as agentWithSkills, P as buildReviewAwaitAfterDeferMessage, Q as reviewNotesCapture, R as builderSystem, T as reviewMissing, V as designSystem, X as reviewEditsCapture, Y as reviewEditNotesCapture, _ as REQUIREMENTS, b as coder, c as envDefaults, d as gate, et as startGateBlockedMessage, h as FEEDBACK, i as skills, j as architectureDecomposePrompt, k as architectSystem, m as ARCHITECTURE, n as summary, nt as unwindFailure, o as shipped, p as healthy, q as packagesItemBuildingPrompt, r as access, s as defaults, t as steering, tt as unwindFailedMessage, v as REVIEW, w as planner, x as fixCheck, y as awaitReview, z as deferNotesScript } from "../chunks/reserved-B2QaImnN.mjs";
4
+ import { a as tail, i as refusePendingHandOff, n as closeReview } from "../chunks/tail-BnhIxCYv.mjs";
4
5
  //#region src/workflows/feature/steps.ts
5
6
  /** Turn the sketch since `base` into `.gtd/REQUIREMENTS.md`. */
6
7
  const triage = (base) => agentWithSkills("triage", designTriagePrompt(base), {
@@ -1,6 +1,7 @@
1
1
  import { read, refuse, removeScript, run, scope, start } from "../flows.mjs";
2
2
  import { d as reviewNotes, f as reviewRisks } from "../chunks/steering-DVILanVf.mjs";
3
- import { D as agentWithSkills, H as finisherSystem, U as fixReviewNotesPrompt, a as REVIEW_ORIG, d as defaults, f as envDefaults, i as skills, n as summary, p as baseline, r as access, s as handOffTail, t as steering, u as shipped, x as coder, y as REVIEW } from "../chunks/reserved-BL9krPao.mjs";
3
+ import { O as agentWithSkills, U as finisherSystem, W as fixReviewNotesPrompt, b as coder, c as envDefaults, i as skills, l as baseline, n as summary, o as shipped, r as access, s as defaults, t as steering, v as REVIEW } from "../chunks/reserved-B2QaImnN.mjs";
4
+ import { r as handOffTail, t as REVIEW_ORIG } from "../chunks/tail-BnhIxCYv.mjs";
4
5
  //#region src/workflows/fix/fix.ts
5
6
  /**
6
7
  * Fix every note a human left in a handed-off `.gtd/REVIEW.md` and every
@@ -1,5 +1,6 @@
1
1
  import { start } from "../flows.mjs";
2
- import { Y as reviewGateBlockedMessage, c as refusePendingHandOff, d as defaults, f as envDefaults, i as skills, m as gate, n as summary, r as access, s as handOffTail, t as steering, u as shipped } from "../chunks/reserved-BL9krPao.mjs";
2
+ import { Z as reviewGateBlockedMessage, c as envDefaults, d as gate, i as skills, n as summary, o as shipped, r as access, s as defaults, t as steering } from "../chunks/reserved-B2QaImnN.mjs";
3
+ import { i as refusePendingHandOff, r as handOffTail } from "../chunks/tail-BnhIxCYv.mjs";
3
4
  //#region src/workflows/review/review.ts
4
5
  /**
5
6
  * Pure review of everything since `reviewBase`: a green gate, the quality
@@ -0,0 +1,33 @@
1
+ import { agent, changesSince, head, read, refuse, scope, vars } from "../flows.mjs";
2
+ import { a as flagShipped, b as coder, c as envDefaults, d as gate, i as skills, n as summary, r as access, s as defaults, t as steering } from "../chunks/reserved-B2QaImnN.mjs";
3
+ import { i as requireFlag, n as flipProblems } from "../chunks/registry-CP3YuV9j.mjs";
4
+ //#region src/workflows/rollout/rollout.ts
5
+ const flippingPrompt = (name, registry) => `Roll out the release flag "${name}": in ${registry}, set \`defaultOn: true\` on its entry. Change nothing else — no other entry, no other field, no other file, no comments.`;
6
+ const suiteBlockedMessage = () => "The suite is red after the rollout. Fix it by hand — a rollout may only touch the flag's registry entry — then land.";
7
+ const rolloutFlow = async () => {
8
+ const registry = vars.flagRegistry ?? "";
9
+ const name = vars.flag ?? "";
10
+ requireFlag("rollout", registry, name, false);
11
+ const base = head();
12
+ const before = read(registry) ?? "";
13
+ const guard = () => {
14
+ const strays = changesSince(base).paths.filter((path) => path !== registry && path !== ".gtd/FEEDBACK.md");
15
+ if (strays.length > 0) refuse(`gtd land: rollout-only: ${strays.join(", ")} changed — rollout may only set defaultOn: true on "${name}" in ${registry}`);
16
+ const problems = flipProblems(before, read(registry) ?? "", name);
17
+ if (problems.length > 0) refuse(`gtd land: rollout-only: other edits in ${registry}: ${problems.join("; ")}`);
18
+ };
19
+ await scope("rollout", async () => {
20
+ await agent("flipping", flippingPrompt(name, registry), {
21
+ label: `Rolling out ${name}`,
22
+ model: coder()
23
+ });
24
+ guard();
25
+ await gate("suite", suiteBlockedMessage(), guard);
26
+ });
27
+ };
28
+ const rollout = flagShipped(rolloutFlow);
29
+ //#endregion
30
+ //#region src/workflows/rollout/index.ts
31
+ var rollout_default = rollout;
32
+ //#endregion
33
+ export { access, rollout_default as default, defaults, envDefaults, rollout, rolloutFlow, skills, steering, summary };