pi-dev-flow 0.88.0 → 0.90.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  /** dev-flow runtime — Reflections and the upstream issue fold. Moved out of extensions/dev-flow.ts as is (exports added). */
2
2
  import { existsSync, readFileSync, writeFileSync } from "node:fs";
3
3
  import path from "node:path";
4
- import { appendReflection, doneItemCount, githubSlug, pluginVersion, guessReflectSections, reflectItems, reflectMove, reflectDone, reflectLegacyPluginCount, reflectionNudges, pluginIssueRecipe, reflectionLine, reflectionsTidy, openChecklistItems, type ReflectTarget, type ReflectItem, type ReflectSection } from "../core.ts";
4
+ import { appendReflection, doneItemCount, githubSlug, pluginVersion, guessReflectSections, reflectItems, reflectMove, reflectDone, reflectRow, reflectLegacyPluginCount, reflectionNudges, pluginIssueRecipe, reflectionLine, reflectionsTidy, openChecklistItems, type ReflectTarget, type ReflectItem, type ReflectSection } from "../core.ts";
5
5
  import { dedupeReflections, linkedTag, parseGhIssues, similarNote, type FoldResult, type GhIssue } from "../fold.ts";
6
6
  import { dfDir, now, originUrl, readReflections, readReflectionsText, sh } from "./base.ts";
7
7
  import { type RunResult, type Session } from "./checks.ts";
@@ -70,13 +70,13 @@ export async function foldView(root: string, items: ReflectItem[]): Promise<Fold
70
70
  /** The fold block shared by flow doctor and flow reflect list: header, one row per unmatched
71
71
  * issue with its route, then the unmerged near-miss hints. Local rows carry their ⟷ gh#N tag
72
72
  * at the call site — the fold lists upstream items, it never re-numbers the local queue. */
73
- export function foldRows(fold: FoldView, selfRepo: boolean): string[] {
73
+ export function foldRows(fold: FoldView, selfRepo: boolean, items: readonly ReflectItem[] = []): string[] {
74
74
  if (fold.state === "absent") return [];
75
75
  if (fold.state === "skipped") return [`upstream issues: skipped (${fold.why})`];
76
76
  if (!fold.open) return [];
77
77
  const rows = [`upstream on ${fold.slug} — ${fold.open} open issue(s) on GitHub (canonical there — close on GitHub, never here; this is a fold, not a copy):`];
78
78
  for (const i of fold.result.upstreamOnly) rows.push(` gh#${i.number} ${i.title} → ${selfRepo ? "fix in a flow here (patch flow if small)" : "fix in a flow here, or close won't-fix on GitHub"}`);
79
- for (const s of fold.result.similar) rows.push(` ${similarNote(s, s.item + 1)}`);
79
+ for (const s of fold.result.similar) rows.push(` ${similarNote(s, items[s.item]?.n ?? s.item + 1)}`);
80
80
  return rows;
81
81
  }
82
82
 
@@ -88,16 +88,16 @@ export async function reflectList(root: string): Promise<RunResult> {
88
88
  const fold = await foldView(root, items);
89
89
  const local = items.length
90
90
  ? [
91
- `reflections — ${items.length} open:`,
91
+ `reflections — ${items.length} open (numbers are row numbers: checking one off leaves the others as they are; tidy and move renumber):`,
92
92
  ...items.map((it, i) => {
93
93
  const link = fold.state === "ok" ? fold.result.linked.find((l) => l.item === i) : undefined;
94
- return ` ${i + 1}. [${it.section}] ${it.line.replace(/^- \[ \] /, "")}${link ? linkedTag(link.issue) : ""}`;
94
+ return ` ${it.n}. [${it.section}] ${it.line.replace(/^- \[ \] /, "")}${link ? linkedTag(link.issue) : ""}`;
95
95
  }),
96
96
  ]
97
97
  : fold.state === "absent" || fold.state === "skipped"
98
98
  ? ["reflections: nothing open"]
99
99
  : ["reflections: nothing open locally"];
100
- return { text: [...local, ...legacyPluginRows(readReflectionsText(root), isSelfRepo(root)), ...foldRows(fold, isSelfRepo(root))].join("\n") };
100
+ return { text: [...local, ...legacyPluginRows(readReflectionsText(root), isSelfRepo(root)), ...foldRows(fold, isSelfRepo(root), items)].join("\n") };
101
101
  }
102
102
 
103
103
  /** Open rows still under the legacy `## plugin` heading: they belong on GitHub, not in a project's queue. */
@@ -121,30 +121,42 @@ export function reflectMoveNote(root: string, args: string[], forced: ReflectTar
121
121
  const n = Number(args[0]);
122
122
  const text = readReflectionsText(root);
123
123
  const items = reflectItems(text);
124
- if (!Number.isInteger(n) || n < 1 || n > items.length) return { text: `move: open item 1–${items.length} required — flow reflect list numbers them`, isError: true };
125
- if (items[n - 1].section === section) return { text: `reflect: item ${n} is already under ## ${section}` };
124
+ const it = items.find((x) => x.n === n);
125
+ if (!it) return { text: `move: ${noOpenRow(text, n, items)}`, isError: true };
126
+ if (it.section === section) return { text: `reflect: item ${n} is already under ## ${section}` };
126
127
  // the same note open under both headings (an old --both filing): the move merges it, it does not copy it
127
- const twin = items.some((it, i) => i !== n - 1 && it.section === section && it.body === items[n - 1].body);
128
+ const twin = items.some((x) => x !== it && x.section === section && x.body === it.body);
128
129
  const next = reflectMove(text, n, section);
129
- if (next === null) return { text: `move: open item 1–${items.length} required — flow reflect list numbers them`, isError: true };
130
+ if (next === null) return { text: `move: ${noOpenRow(text, n, items)}`, isError: true };
130
131
  writeFileSync(path.join(dfDir(root), "reflections.md"), next);
131
- const note = items[n - 1].line.replace(/^- \[ \] /, "");
132
- return { text: twin ? `reflect: item ${n} was already recorded under ## ${section} — the duplicate is gone (${note})` : `reflect: item ${n} re-filed under ## ${section} — ${note}` };
132
+ const note = it.line.replace(/^- \[ \] /, "");
133
+ return { text: `${twin ? `reflect: item ${n} was already recorded under ## ${section} — the duplicate is gone (${note})` : `reflect: item ${n} re-filed under ## ${section} — ${note}`}\n${RENUMBERED}` };
133
134
  }
134
135
 
135
- /** `flow reflect done <n> [what fixed it]` — check a folded/fixed item off, so doctor stops re-reporting it (#165). */
136
+ const RENUMBERED = "the row numbers changed — run flow reflect list before the next done or move";
137
+
138
+ /** Why `<n>` names no open row (gh#197): a row already checked off says which note it holds, so a batch that
139
+ * drifted shows the mismatch instead of closing the wrong line. */
140
+ function noOpenRow(text: string, n: number, items: readonly ReflectItem[]): string {
141
+ const row = Number.isInteger(n) && n > 0 ? reflectRow(text, n) : null;
142
+ if (row && !row.open) return `item ${n} is already checked off (${row.line.replace(/^-\s*\[[xX]\]\s*/, "")}) — flow reflect list shows the open ones`;
143
+ return items.length ? `no open item ${n} — open: ${items.map((i) => i.n).join(", ")} (flow reflect list numbers them)` : "nothing open in reflections.md";
144
+ }
145
+
146
+ /** `flow reflect done <n> [what fixed it]` — check a folded/fixed item off, so doctor stops re-reporting it (#165).
147
+ * `<n>` is the stable row number (gh#197): closing one leaves every other number where `list` printed it. */
136
148
  export function reflectDoneNote(root: string, sess: Session, args: string[]): RunResult {
137
149
  const text = readReflectionsText(root);
138
150
  const items = reflectItems(text);
139
151
  const n = Number(args[0]);
140
- if (!Number.isInteger(n) || n < 1 || n > items.length)
141
- return { text: items.length ? `done: open item 1–${items.length} required — flow reflect list numbers them` : "done: nothing open in reflections.md", isError: true };
152
+ const it = items.find((x) => x.n === n);
153
+ if (!it) return { text: `done: ${noOpenRow(text, n, items)}`, isError: true };
142
154
  const stamp = [now().slice(0, 10), sess.slug].filter(Boolean).join(" ");
143
155
  const what = args.slice(1).join(" ").trim();
144
156
  const next = reflectDone(text, n, what ? `${stamp} — ${what}` : stamp)!;
145
157
  writeFileSync(path.join(dfDir(root), "reflections.md"), next);
146
158
  const { tidy } = reflectionNudges(next, now().slice(0, 10));
147
- return { text: `reflect: item ${n} checked off — ${items[n - 1].body}` + (tidy ? `\n${tidy}` : "") };
159
+ return { text: `reflect: item ${n} checked off — ${it.body}${what ? ` — fixed: ${what}` : ""}` + (tidy ? `\n${tidy}` : "") };
148
160
  }
149
161
 
150
162
  /** `flow reflect tidy` — drop the closed (`- [x]`) items; the `— fixed:` note already recorded the outcome. */
@@ -156,5 +168,5 @@ export function reflectTidy(root: string): RunResult {
156
168
  const open = openChecklistItems(text).length;
157
169
  if (!closed) return { text: `reflections: nothing to tidy (${open} open, 0 closed)` };
158
170
  writeFileSync(file, reflectionsTidy(text));
159
- return { text: `reflections: dropped ${closed} closed item(s) — ${open} open` };
171
+ return { text: `reflections: dropped ${closed} closed item(s) — ${open} open; ${RENUMBERED}` };
160
172
  }
@@ -1,17 +1,34 @@
1
1
  /** dev-flow runtime — The gates that ship: verify, release, release-done, finish. Moved out of extensions/dev-flow.ts as is (exports added). */
2
2
  import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs";
3
3
  import path from "node:path";
4
- import { applicableItems, changelogVersionsBetween, normalizeReleaseBody, pendingEntryLines, pickReleaseNotes, checklistHash, checklistPending, cmpVersions, freshenChecks, healthProbe, mergeShapeProof, preReleaseGate, reflectionNudges, conflictMarkerLines, isReleaseOnly, looksLikeShellError, needsOperator, newestTaggedVersion, nextHint, releaseGate, parseVersion, roadmapDoneForSlug, sq, tagNotesCommand, verifyGate, versionTagGate, servedBuildMatches } from "../core.ts";
4
+ import { applicableItems, changelogVersionsBetween, normalizeReleaseBody, pendingEntryLines, pickReleaseNotes, checklistHash, checklistPending, cmpVersions, freshenChecks, healthProbe, mergeShapeProof, preReleaseGate, reflectionNudges, conflictMarkerLines, isReleaseOnly, looksLikeShellError, needsOperator, newestTaggedVersion, nextHint, releaseGate, parseVersion, roadmapDoneForSlug, sq, tagNotesCommand, verifyGate, versionTagGate, servedBuildMatches, versionArg, playbookVersionChoice, describeVersionChoice, majorBump, bumpVersion, isBumpKind, resolvedDevEnv } from "../core.ts";
5
+ import type { Config, FlowState } from "../core.ts";
5
6
  import { AGENT_MARK } from "../present.ts";
6
7
  import { buildSkew, copyWarning, currentBranch, featDir, flagValue, forgeMergeStyle, forgeOf, gateCwd, mergeBase, needState, now, originUrl, readReflectionsText, readRoadmap, readState, releaseTags, roadmapFile, sh, tail, worktreeAbs, writeState } from "./base.ts";
7
8
  import { type RunResult, branchState, catchUp, describeBranchState, devEnv, devPortOf, devSlotCheck, healthRerunsAfterDeploy, pendingChecks, probeHealth, readDevPorts, runChecks, slotKey, triedNote, unreleasedOnMain, worktreeFingerprint, writeDevPorts } from "./checks.ts";
8
9
  import { type GateCtx, markPendingAsk } from "./gates.ts";
9
10
 
11
+ /** gh#198: the version question asked with Verified? — null when it is not the operator's to answer here
12
+ * (no manifest to version, the playbook decides, or an earlier Verified? already recorded the call). */
13
+ function versionQuestion(root: string, state: FlowState, cfg: Config): { ask: string; flags: string } | null {
14
+ if (!cfg.versioning.file || playbookVersionChoice(cfg) || state.versionChoice) return null;
15
+ const file = path.join(gateCwd(root, state), cfg.versioning.file);
16
+ const now = existsSync(file) ? parseVersion(cfg.versioning.file, readFileSync(file, "utf8")) : null;
17
+ const kinds = (["patch", "minor", "major"] as const).map((k) => `${k}${bumpVersion(now, k) ? ` (→ ${bumpVersion(now, k)})` : ""}`).join(", ");
18
+ return {
19
+ ask: `also ask the release call: a ${kinds} release — propose one by the playbook's versioning rule${now ? ` (${cfg.versioning.file} is at ${now})` : ""} — or merge unreleased (no bump, no tag)${state.docs ? "; a docs flow usually merges unreleased" : ""}`,
20
+ flags: "--version=patch|minor|major (or the exact version they named) or --no-version (merge unreleased)",
21
+ };
22
+ }
23
+
10
24
  export async function gateVerify(o: GateCtx): Promise<RunResult> {
11
25
  const { root, ui, sess, cfg, flag, slugArg, takeYoloWord } = o;
12
26
  const { state, err } = needState(root, sess, slugArg);
13
27
  if (err) return err;
14
28
  const items = applicableItems(cfg, state!, "implement");
29
+ // gh#198: the release call (versioned vs unreleased) rides on the Verified? answer — the prep that follows depends on it
30
+ const verArg = versionArg(flagValue(o.rest, "version"), flag("no-version"));
31
+ if ("error" in verArg) return { text: `verify gate FAILED:\n- ${verArg.error}`, isError: true };
15
32
  // the operator reviews the tree that ships: catch up with the default branch before anything runs
16
33
  const caught = state!.stage === "implement" ? await catchUp(root, state!, cfg, flag("confirmed")) : { note: "" };
17
34
  if ("text" in caught) return caught;
@@ -53,11 +70,14 @@ export async function gateVerify(o: GateCtx): Promise<RunResult> {
53
70
  // deploy to dev before asking — the operator reviews the running dev app, not a promise
54
71
  const probe = healthProbe(cfg);
55
72
  if (cfg.commands.dev) {
56
- const res = await sh(cfg.commands.dev, gateCwd(root, state!), undefined, devEnv(root, state!, cfg));
73
+ const env = devEnv(root, state!, cfg);
74
+ const res = await sh(cfg.commands.dev, gateCwd(root, state!), undefined, env);
57
75
  state!.checks.dev = { ok: res.ok, at: now() };
58
76
  writeState(root, state!);
59
- if (!res.ok) return { text: `dev deploy FAILED (${cfg.commands.dev}):\n${tail(res.out)}`, isError: true };
60
- did.push(`dev ran (${cfg.commands.dev})${devPortOf(state!, cfg) !== undefined ? ` on port ${devPortOf(state!, cfg)}` : ""}`);
77
+ // gh#204: the command prints as the playbook wrote it — say what its $DEV_FLOW_* and compose project resolved to
78
+ const resolved = resolvedDevEnv(cfg.commands.dev, env);
79
+ if (!res.ok) return { text: `dev deploy FAILED (${cfg.commands.dev})${resolved ? ` — ${resolved}` : ""}:\n${tail(res.out)}`, isError: true };
80
+ did.push(`dev ran (${cfg.commands.dev})${devPortOf(state!, cfg) !== undefined ? ` on port ${devPortOf(state!, cfg)}` : ""}${resolved ? ` — ${resolved}` : ""}`);
61
81
  // the deploy is what must be proven, not just run: a container that came back unhealthy, or
62
82
  // still serves the previous build, must not pass on a health PASS recorded before it was
63
83
  // recreated. What "the expected version" means is the project's business — the probe runs in
@@ -109,7 +129,8 @@ export async function gateVerify(o: GateCtx): Promise<RunResult> {
109
129
  if (!ui.hasUI) {
110
130
  const port = devPortOf(state!, cfg);
111
131
  const what = state!.docs ? "ready for review" : cfg.commands.dev ? `deployed for review${port !== undefined ? ` on port ${port}` : ""}` : "live app re-probed for review";
112
- return { text: `${needsOperator(`${what}${reverify ? ` — a re-verify over the review fixes since ${state!.verifiedHead?.slice(0, 7) ?? "the last Verified?"}` : ""} — the app stays up until you answer`, "Verified?", "look at the change in the running app yourself first (the playbook's self-check), then ask the operator Verified? in chat and run flow verify --confirmed once they answer. Keep it running until they answer.")}\n${ran}` };
132
+ const vq = versionQuestion(root, state!, cfg);
133
+ return { text: `${needsOperator(`${what}${reverify ? ` — a re-verify over the review fixes since ${state!.verifiedHead?.slice(0, 7) ?? "the last Verified?"}` : ""} — the app stays up until you answer${vq ? ` — ${vq.ask}` : ""}`, "Verified?", `look at the change in the running app yourself first (the playbook's self-check), then ask the operator Verified? in chat and run flow verify --confirmed${vq ? ` ${vq.flags}` : ""} once they answer. Keep it running until they answer.`)}\n${ran}` };
113
134
  }
114
135
  const ok = await ui.confirm("Operator verification", `Verified? All checks green${cfg.commands.dev && !state!.docs ? `; dev deploy is up for review (${cfg.commands.dev})` : ""} \u2014 does it work?`);
115
136
  if (!ok) {
@@ -129,21 +150,38 @@ export async function gateVerify(o: GateCtx): Promise<RunResult> {
129
150
  const vHead = await sh("git rev-parse HEAD", gateCwd(root, state!));
130
151
  if (vHead.ok && vHead.out.trim()) state!.verifiedHead = vHead.out.trim();
131
152
  else delete state!.verifiedHead;
153
+ // gh#198: the operator's call, else the playbook's, else whatever an earlier Verified? recorded
154
+ const choice = verArg.choice ?? state!.versionChoice ?? playbookVersionChoice(cfg);
155
+ if (choice) {
156
+ if (choice !== state!.versionChoice || !state!.versionFrom) {
157
+ const mf = cfg.versioning.file ? path.join(gateCwd(root, state!), cfg.versioning.file) : "";
158
+ const from = mf && existsSync(mf) ? parseVersion(cfg.versioning.file!, readFileSync(mf, "utf8")) : null;
159
+ if (from) state!.versionFrom = from;
160
+ }
161
+ state!.versionChoice = choice;
162
+ if (choice === "unreleased") state!.noVersion = true;
163
+ else delete state!.noVersion;
164
+ }
165
+ const choiceNote = choice ? `\nrelease call: ${describeVersionChoice(choice, state!.versionFrom)}` : "";
132
166
  const before = state!.stage;
133
167
  state!.stage = "pre-release";
134
168
  delete state!.pendingAsk;
135
169
  writeState(root, state!);
136
170
  if (before === "pre-release")
137
- return { text: `re-verified${audit} over ${state!.verifiedHead?.slice(0, 7) ?? "the current tree"} — the Verified? word now covers the review fixes; still in pre-release.\n${ran}\n${AGENT_MARK}next: ${nextHint(state!, cfg)}` };
138
- return { text: `verified${audit} — entering pre-release stage.\n${ran}\n${AGENT_MARK}next: ${nextHint(state!, cfg)}` };
171
+ return { text: `re-verified${audit} over ${state!.verifiedHead?.slice(0, 7) ?? "the current tree"} — the Verified? word now covers the review fixes; still in pre-release.${choiceNote}\n${ran}\n${AGENT_MARK}next: ${nextHint(state!, cfg)}` };
172
+ return { text: `verified${audit} — entering pre-release stage.${choiceNote}\n${ran}\n${AGENT_MARK}next: ${nextHint(state!, cfg)}` };
139
173
  }
140
174
 
141
175
  export async function gateRelease(o: GateCtx): Promise<RunResult> {
142
176
  const { root, ui, sess, cfg, flag, slugArg, takeYoloWord } = o;
143
177
  const { state, err } = needState(root, sess, slugArg);
144
178
  if (err) return err;
145
- // operator's word at Release?: this flow ships without a version bump or tag — recorded only once Release? is answered
146
- const noVersion = flag("no-version") || !!state!.noVersion;
179
+ // operator's word at Release?: this flow ships without a version bump or tag — recorded only once Release? is answered.
180
+ // gh#198: --version=<v> / --no-version here re-make the call recorded with Verified? (the operator changed their mind)
181
+ const relArg = versionArg(flagValue(o.rest, "version"), flag("no-version"));
182
+ if ("error" in relArg) return { text: `release gate FAILED:\n- ${relArg.error}`, isError: true };
183
+ const choice = relArg.choice ?? state!.versionChoice ?? playbookVersionChoice(cfg);
184
+ const noVersion = choice === "unreleased" || (!relArg.choice && !!state!.noVersion);
147
185
  // (versioned) items stand down on an unversioned flow — the set confirmed here is the one that applies to it
148
186
  const items = applicableItems(cfg, { ...state!, noVersion }, "pre-release");
149
187
  // yolo is the operator's word at Release? — pre-confirms Finish?; publishing guardrails stay enforced
@@ -205,6 +243,33 @@ export async function gateRelease(o: GateCtx): Promise<RunResult> {
205
243
  const prep = { manifestVersion: manifestVer, remoteTags, changelog, changelogChanged, changelogBase, noFoldCheck: flag("no-fold-check"), conflictMarkers, noMarkerCheck: flag("no-marker-check") };
206
244
  // same freshness rule as verify: a green predating a worktree write may not stand for the tree this gate blesses
207
245
  if (freshenChecks(state!, await worktreeFingerprint(wtCwd)).length) writeState(root, state!);
246
+ // gh#198: the branch must carry the call the operator made — a bump they did not choose, or a bump on a flow
247
+ // they said merges unreleased, is prep that contradicts the word Release? would stand on. It runs before the
248
+ // generic proofs: when a parallel flow released first, "already tagged" alone would send the agent round a loop.
249
+ const tagOf = (v: string) => cfg.versioning.pattern.replace("{version}", v);
250
+ const newest = cfg.versioning.file && !noVersion ? newestTaggedVersion(cfg.versioning.pattern, remoteTags) : null;
251
+ if (cfg.versioning.file && choice && choice !== "next") {
252
+ const re = "ask the operator, then re-run with --version=<their call> or --no-version and --confirmed on their answer";
253
+ let baseVer: string | null = null;
254
+ if (markerBase) {
255
+ const was = await sh(`git show ${sq(`${markerBase}:${cfg.versioning.file}`)} 2>/dev/null`, wtCwd);
256
+ baseVer = was.ok && was.out.trim() ? parseVersion(cfg.versioning.file, was.out) : null;
257
+ }
258
+ if (isBumpKind(choice)) {
259
+ // counted from what actually shipped last, so a flow that took the number first moves this one along
260
+ const from = newest ?? baseVer ?? state!.versionFrom ?? null;
261
+ const want = bumpVersion(from, choice);
262
+ const moved = from && state!.versionFrom && from !== state!.versionFrom ? ` — ${tagOf(from)} was released since Verified? (the call was counted from ${state!.versionFrom} then)` : "";
263
+ if (want && manifestVer !== want)
264
+ return { text: `release gate FAILED:\n- the operator's call is a ${choice} release: bump ${cfg.versioning.file} to ${want} (${choice} past ${from})${moved}, and head its changelog entry ${want} — it says ${manifestVer ?? "no version"}`, isError: true };
265
+ } else if (choice !== "unreleased") {
266
+ if (remoteTags.includes(tagOf(choice)))
267
+ return { text: `release gate FAILED:\n- ${choice}, the operator's call at Verified?, is taken: ${tagOf(choice)} was released since (another flow got there first) — ${re}; propose the same kind of step past ${newest ?? choice}, never pick the number yourself`, isError: true };
268
+ if (manifestVer && manifestVer !== choice)
269
+ return { text: `release gate FAILED:\n- the operator's release call is ${choice}, but ${cfg.versioning.file} says ${manifestVer} — bump it to ${choice}, or, if the call changed, ${re}`, isError: true };
270
+ } else if (manifestVer && baseVer && baseVer !== manifestVer)
271
+ return { text: `release gate FAILED:\n- the operator's call is to merge unreleased, but the branch bumps ${cfg.versioning.file} ${baseVer} → ${manifestVer} — revert the bump (the entry goes under Unreleased), or, if the call changed, ${re}`, isError: true };
272
+ }
208
273
  // tier-2 pre-release confirmation is recorded by this very command, so it is excluded here
209
274
  const preGate = preReleaseGate({ ...state!, noVersion, confirmations: { ...state!.confirmations, "pre-release": { hash: checklistHash(items), at: now() } } }, cfg, prep);
210
275
  if (preGate.length) return { text: `release gate FAILED:\n- ${preGate.join("\n- ")}`, isError: true };
@@ -274,12 +339,34 @@ export async function gateRelease(o: GateCtx): Promise<RunResult> {
274
339
  : postVerify
275
340
  ? "a yolo given earlier does not cover commits that landed after Verified? — ask Release? with them named"
276
341
  : "";
277
- let audit = flag("confirmed") ? " (confirmed by operator instruction)" : state!.yolo ? " (yolo: pre-confirmed)" : "";
278
- const askPending = !flag("confirmed") && (!state!.yolo || !!yoloHeld);
342
+ // gh#198: release.ask = on-change — Release? answers itself when it would only re-confirm Verified?: the call
343
+ // is on record, nothing but release prep landed since, and no other question (stale build, a major bump) is open
344
+ const onChange = cfg.release.ask !== "always" && !flag("confirmed") && !state!.yolo;
345
+ const askWhy = !onChange
346
+ ? ""
347
+ : !state!.verifiedHead
348
+ ? "no Verified? tree on record to compare against"
349
+ : cfg.versioning.file && !choice
350
+ ? "no release call on record — ask it with Release?: patch, minor, major, or merge unreleased"
351
+ : relArg.choice && relArg.choice !== state!.versionChoice
352
+ ? `the release call changed since Verified? (${state!.versionChoice ?? "none"} → ${relArg.choice}) — the operator makes that call`
353
+ : postVerify
354
+ ? "commits beyond release prep landed after Verified?"
355
+ : stale
356
+ ? "the session build is behind the checkout"
357
+ : cfg.release.yolo === "until-release"
358
+ ? "the playbook sets yolo = until-release"
359
+ : choice === "next" && newest && manifestVer && majorBump(newest, manifestVer)
360
+ ? `${newest} → ${manifestVer} is a major bump — the playbook's versioned call does not choose that`
361
+ : "";
362
+ const auto = onChange && !askWhy;
363
+ let audit = flag("confirmed") ? " (confirmed by operator instruction)" : auto ? ` (auto-answered: release.ask = on-change — ${describeVersionChoice(choice ?? "next", state!.versionFrom)} was the call at Verified?, and only release prep landed since)` : state!.yolo ? " (yolo: pre-confirmed)" : "";
364
+ const askPending = !auto && !flag("confirmed") && (!state!.yolo || !!yoloHeld);
279
365
  if (askPending) {
280
366
  markPendingAsk(root, state!, "Release?");
281
367
  if (!ui.hasUI) {
282
- return { text: needsOperator(`ready to publish${yoloHeld ? ` (${yoloHeld})` : ""}${stale ? ` — also: ${staleAsk}` : ""}${postVerify ? ` — ${postVerify}` : ""}`, "Release?", `re-run with --confirmed once the operator answered 'Release?' in chat${stale ? " (and the stale-build question)" : ""}`), isError: true };
368
+ const callAsk = cfg.versioning.file && !choice ? " — also ask the release call: a patch, minor or major release, or merge unreleased (no bump, no tag)?" : "";
369
+ return { text: needsOperator(`ready to publish${yoloHeld ? ` (${yoloHeld})` : ""}${askWhy ? ` (asked: ${askWhy})` : ""}${stale ? ` — also: ${staleAsk}` : ""}${postVerify ? ` — ${postVerify}` : ""}${callAsk}`, "Release?", `re-run with --confirmed once the operator answered 'Release?' in chat${stale ? " (and the stale-build question)" : ""}${callAsk ? " (add --version=patch|minor|major, an exact version, or --no-version for their release call)" : ""}`), isError: true };
283
370
  }
284
371
  const ok = await ui.confirm("Enter release", `Release ${state!.slug}${manifestVer ? ` v${manifestVer}` : ""}${noVersion ? " (unversioned — merge + changelog entry only: no bump, no tag for this flow)" : ""}? Publishing starts: PR, merge${noVersion ? "" : ", tag"} — release-done afterwards needs no further answer.${staleAsk ? `\n\n${staleAsk}` : ""}${postVerify ? `\n\n${postVerify}` : ""}${yoloHeld ? `\n\n(${yoloHeld})` : ""}`);
285
372
  if (!ok) {
@@ -290,6 +377,8 @@ export async function gateRelease(o: GateCtx): Promise<RunResult> {
290
377
  audit = " (confirmed in dialog)";
291
378
  }
292
379
  if (noVersion) state!.noVersion = true;
380
+ else delete state!.noVersion;
381
+ if (choice) state!.versionChoice = choice;
293
382
  if (unverifiedChange) state!.friction = (state!.friction ?? 0) + 1;
294
383
  state!.confirmations = { ...state!.confirmations, "pre-release": { hash: checklistHash(items), at: now() } };
295
384
  state!.approvals["pre-release"] = now();
@@ -532,8 +621,20 @@ export async function gateFinish(o: GateCtx): Promise<RunResult> {
532
621
  if (err || !state || state.approvals.release || state.stage !== "release" || !state.approvals["pre-release"]) return gateFinishCore(o);
533
622
  const rec = await gateReleaseDone({ ...o, rest: o.rest.filter((a) => a !== "--confirmed" && a !== "--yolo") });
534
623
  if (rec.isError) return rec;
535
- const fin = await gateFinishCore(o);
536
624
  const recorded = rec.text.split("\n").filter((l) => !l.startsWith(AGENT_MARK)).join("\n");
625
+ // gh#205: release-stage items (a post-merge build, a deploy check from the default branch) are work done after
626
+ // the merge. A separate release-done names them while the worktree still stands; folded into finish, one
627
+ // call recorded the release and removed everything, so an unversioned flow never saw them. Stop once here.
628
+ const cur = readState(o.root, state.slug) ?? state;
629
+ if (checklistPending(o.cfg, cur, "release")) {
630
+ markPendingAsk(o.root, cur, "Finish?");
631
+ const items = applicableItems(o.cfg, cur, "release").map((i) => `"${i.text}"`).join(" | ");
632
+ return {
633
+ text: `${recorded}\n\n${needsOperator(`release recorded — nothing was removed yet: the release-stage checklist (## release in .dev-flow/project.md) is still open: ${items}`, "Finish?", `do each release-stage item now (they run after the merge, from ${o.cfg.defaultBranch} — not the worktree), tell the operator what each showed, then ask Finish? and run flow finish --confirmed when they answer`)}`,
634
+ isError: true,
635
+ };
636
+ }
637
+ const fin = await gateFinishCore(o);
537
638
  return { ...fin, text: `${recorded}\n\n${fin.text}` };
538
639
  }
539
640
 
@@ -638,7 +739,9 @@ export async function gateFinishCore(o: GateCtx): Promise<RunResult> {
638
739
  if (askPending) {
639
740
  markPendingAsk(root, state!, "Finish?");
640
741
  if (!ui.hasUI) {
641
- return { text: needsOperator(`cleanup removes the worktree, branch and feature folder.${quietNote}${forgeSkipNote}`, "Finish?", "ask the operator Finish? in chat, then re-run with --confirmed"), isError: true };
742
+ // the Finish? answer is what closes the release-stage items: name them in the question it asks
743
+ const openRelease = checklistPending(cfg, state!, "release") ? ` Release-stage checklist to close with this answer: ${applicableItems(cfg, state!, "release").map((i) => `"${i.text}"`).join(" | ")}.` : "";
744
+ return { text: needsOperator(`cleanup removes the worktree, branch and feature folder.${openRelease}${quietNote}${forgeSkipNote}`, "Finish?", "ask the operator Finish? in chat, then re-run with --confirmed"), isError: true };
642
745
  }
643
746
  const ok = await ui.confirm("Finish feature", `Finish ${state!.slug}?${unmergedNote}${forgeSkipNote} Removes worktree, branch ${state!.branch || "-"} and .dev-flow/${state!.slug}/.`);
644
747
  if (!ok) {