pi-dev-flow 0.91.1 → 0.92.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/README.md +5 -5
- package/docs/development.md +2 -1
- package/docs/gates.md +56 -16
- package/docs/guardrails.md +4 -2
- package/docs/headless.md +9 -5
- package/docs/playbook.md +13 -3
- package/docs/reflections.md +4 -2
- package/extensions/dev-flow.ts +18 -6
- package/package.json +1 -1
- package/skills/dev-flow/references/finish.md +12 -5
- package/skills/dev-flow/references/implement.md +6 -2
- package/skills/dev-flow/references/plan.md +9 -5
- package/skills/dev-flow/references/pre-release.md +8 -5
- package/skills/dev-flow/references/reflect.md +2 -2
- package/skills/dev-flow/references/release.md +53 -40
- package/skills/dev-flow/references/start.md +11 -8
- package/src/core.ts +43 -14
- package/src/projectmd.ts +21 -2
- package/src/runtime/base.ts +1 -1
- package/src/runtime/checks.ts +95 -5
- package/src/runtime/gates.ts +53 -14
- package/src/runtime/grants.ts +38 -4
- package/src/runtime/publish.ts +223 -0
- package/src/runtime/ship.ts +136 -38
package/src/runtime/ship.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
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, versionArg, playbookVersionChoice, describeVersionChoice, majorBump, bumpVersion, isBumpKind, resolvedDevEnv } 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, prepFiles, versionArg, playbookVersionChoice, describeVersionChoice, majorBump, bumpVersion, isBumpKind, resolvedDevEnv } from "../core.ts";
|
|
5
5
|
import type { Config, FlowState } from "../core.ts";
|
|
6
6
|
import { AGENT_MARK } from "../present.ts";
|
|
7
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";
|
|
8
|
-
import { type RunResult, branchState, catchUp, describeBranchState, devEnv, devPortOf, devSlotCheck, healthRerunsAfterDeploy, pendingChecks, probeHealth, readDevPorts, runChecks, slotKey, triedNote, unreleasedOnMain, worktreeFingerprint, writeDevPorts } from "./checks.ts";
|
|
8
|
+
import { type RunResult, ago, releaseDevSlot, keepThroughPrep, branchState, catchUp, describeBranchState, devEnv, devPortOf, devSlotCheck, healthRerunsAfterDeploy, pendingChecks, probeHealth, readDevPorts, runChecks, slotKey, triedNote, unreleasedOnMain, worktreeFingerprint, writeDevPorts } from "./checks.ts";
|
|
9
9
|
import { type GateCtx, markPendingAsk } from "./gates.ts";
|
|
10
|
+
import { gatePublishes, publishRelease } from "./publish.ts";
|
|
10
11
|
|
|
11
12
|
/** gh#198: the version question asked with Verified? — null when it is not the operator's to answer here
|
|
12
13
|
* (no manifest to version, the playbook decides, or an earlier Verified? already recorded the call). */
|
|
@@ -38,7 +39,8 @@ export async function gateVerify(o: GateCtx): Promise<RunResult> {
|
|
|
38
39
|
// A green record belongs to the tree it ran against. A worktree change made through bash (sed,
|
|
39
40
|
// a formatter, codegen) fires no edit-tool invalidation — the fingerprint is what notices the
|
|
40
41
|
// tree moved, and the dropped records become pending so the gate itself reruns them (#84 path).
|
|
41
|
-
const
|
|
42
|
+
const fpAtGate = await worktreeFingerprint(gateCwd(root, state!));
|
|
43
|
+
const staleAtGate = freshenChecks(state!, fpAtGate, (n) => n === "health" && healthRerunsAfterDeploy(cfg));
|
|
42
44
|
if (staleAtGate.length) writeState(root, state!);
|
|
43
45
|
const pending = pendingChecks(state!, cfg);
|
|
44
46
|
const gateRun = pending.length ? await runChecks(root, state!, cfg, pending) : null;
|
|
@@ -56,10 +58,32 @@ export async function gateVerify(o: GateCtx): Promise<RunResult> {
|
|
|
56
58
|
if (slotted.note) did.push(slotted.note);
|
|
57
59
|
if (gateRun) did.push(`checks ran at the gate (${pending.map((c) => c.name).join(", ")})`);
|
|
58
60
|
if (staleAtGate.length) did.push(`stale record(s) rerun after a worktree change: ${staleAtGate.join(", ")}`);
|
|
61
|
+
// The operator's answer arrives over the deploy `flow verify` just put up for them. When the tree is the
|
|
62
|
+
// one that was deployed and this flow still holds the slot, building and deploying it again proves nothing
|
|
63
|
+
// the review deploy did not — it only costs the minutes twice and can fail after the operator said yes.
|
|
64
|
+
// The app must still answer: a probe that fails falls back to the full deploy.
|
|
65
|
+
const rd = state!.reviewDeploy;
|
|
66
|
+
let standing = false;
|
|
67
|
+
// a check that just ran at this gate may have rewritten the tree (a formatter, codegen): compare what is there now
|
|
68
|
+
const fpNow = rd && flag("confirmed") && gateRun ? await worktreeFingerprint(gateCwd(root, state!)) : fpAtGate;
|
|
69
|
+
if (!state!.docs && flag("confirmed") && rd && fpNow && rd.wt === fpNow && rd.slot === slotKey(devPortOf(state!, cfg))) {
|
|
70
|
+
standing = !cfg.commands.dev || readDevPorts(root)[rd.slot]?.slug === state!.slug;
|
|
71
|
+
const liveProbe = standing ? healthProbe(cfg) : undefined;
|
|
72
|
+
if (liveProbe) {
|
|
73
|
+
const probed = await probeHealth(root, state!, cfg, liveProbe);
|
|
74
|
+
if ("seedFail" in probed) return probed.seedFail;
|
|
75
|
+
if (probed.ok) did.push(`health: live re-probe PASS (${liveProbe}${triedNote(probed.attempts)})`);
|
|
76
|
+
else {
|
|
77
|
+
standing = false;
|
|
78
|
+
did.push("the review deploy stopped answering — deployed again");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (standing) did.push(`review deploy stands (deployed ${ago(rd.at)}, tree unchanged) — not built or deployed again`);
|
|
82
|
+
}
|
|
59
83
|
if (state!.docs) {
|
|
60
84
|
// docs mode's contract: no tier-1 work happens, so a docs flow neither builds, deploys nor probes (#43 #49)
|
|
61
85
|
did.push("docs mode: project commands skipped (build/dev/health)");
|
|
62
|
-
} else {
|
|
86
|
+
} else if (!standing) {
|
|
63
87
|
if (cfg.commands.build) {
|
|
64
88
|
const res = await sh(cfg.commands.build, gateCwd(root, state!), undefined, devEnv(root, state!, cfg));
|
|
65
89
|
state!.checks.build = { ok: res.ok, at: now() };
|
|
@@ -109,7 +133,7 @@ export async function gateVerify(o: GateCtx): Promise<RunResult> {
|
|
|
109
133
|
return { text: `served-build check FAILED (${cfg.commands.servedBuild}) — the app is up but does not serve this branch's HEAD ${head.slice(0, 12)}:\n${tail(sb.out)}`, isError: true };
|
|
110
134
|
did.push(`serves ${head.slice(0, 7)} (HEAD)`);
|
|
111
135
|
}
|
|
112
|
-
if (!state!.docs && cfg.commands.dev) {
|
|
136
|
+
if (!state!.docs && cfg.commands.dev && !standing) {
|
|
113
137
|
const head = (await sh("git rev-parse HEAD", gateCwd(root, state!))).out.trim();
|
|
114
138
|
writeDevPorts(root, { ...readDevPorts(root), [slotKey(devPortOf(state!, cfg))]: { slug: state!.slug, head, at: now() } });
|
|
115
139
|
}
|
|
@@ -123,6 +147,10 @@ export async function gateVerify(o: GateCtx): Promise<RunResult> {
|
|
|
123
147
|
let audit = flag("confirmed") ? " (confirmed by operator instruction)" : state!.yolo && !reverify ? " (yolo: pre-confirmed)" : "";
|
|
124
148
|
const askPending = !flag("confirmed") && (!state!.yolo || reverify);
|
|
125
149
|
if (askPending) {
|
|
150
|
+
// what the operator is about to look at: the tree as the deploy left it (build output included)
|
|
151
|
+
const fpDeployed = state!.docs ? null : await worktreeFingerprint(gateCwd(root, state!));
|
|
152
|
+
if (fpDeployed) state!.reviewDeploy = { wt: fpDeployed, slot: slotKey(devPortOf(state!, cfg)), at: now() };
|
|
153
|
+
else delete state!.reviewDeploy;
|
|
126
154
|
markPendingAsk(root, state!, "Verified?"); // pending however it is asked — a chat question or a dialog
|
|
127
155
|
// the agent's call never opens a dialog (#181): this is the review deploy — the app is up for the
|
|
128
156
|
// operator, and the answer comes back in chat as flow verify --confirmed
|
|
@@ -172,10 +200,29 @@ export async function gateVerify(o: GateCtx): Promise<RunResult> {
|
|
|
172
200
|
return { text: `verified${audit} — entering pre-release stage.${choiceNote}\n${ran}\n${AGENT_MARK}next: ${nextHint(state!, cfg)}` };
|
|
173
201
|
}
|
|
174
202
|
|
|
203
|
+
/** The release stage, run by the gate: publish (push, PR, CI, merge, tag), then the release record's proofs.
|
|
204
|
+
* `head` is what the gate already has to say (the approval); a refusal keeps it so nothing reads as undone. */
|
|
205
|
+
async function publishAndRecord(o: GateCtx, state: FlowState, head: string): Promise<RunResult> {
|
|
206
|
+
const lead = head ? `${head}\n` : "";
|
|
207
|
+
const pub = await publishRelease(o.root, state, o.cfg);
|
|
208
|
+
if (!pub.ok) return { text: `${lead}${pub.text}`, isError: true };
|
|
209
|
+
const rec = await gateReleaseDone({ ...o, rest: o.rest.filter((a) => a !== "--confirmed" && a !== "--yolo") });
|
|
210
|
+
return { ...rec, text: `${lead}${pub.log}\n${rec.text}` };
|
|
211
|
+
}
|
|
212
|
+
|
|
175
213
|
export async function gateRelease(o: GateCtx): Promise<RunResult> {
|
|
176
214
|
const { root, ui, sess, cfg, flag, slugArg, takeYoloWord } = o;
|
|
177
215
|
const { state, err } = needState(root, sess, slugArg);
|
|
178
216
|
if (err) return err;
|
|
217
|
+
// Release? was answered on an earlier call: this one resumes publishing where it stopped (CI still running,
|
|
218
|
+
// a red check fixed, a PR merged by hand) — nothing is asked again
|
|
219
|
+
if (state!.stage === "release" && state!.approvals["pre-release"]) {
|
|
220
|
+
if (state!.approvals.release) return { text: `release already recorded.\n${AGENT_MARK}next: ${nextHint(state!, cfg)}` };
|
|
221
|
+
if (await gatePublishes(cfg, forgeOf(cfg, await originUrl(root)), root)) {
|
|
222
|
+
if (!state!.publish) state!.publish = {};
|
|
223
|
+
return publishAndRecord(o, state!, "");
|
|
224
|
+
}
|
|
225
|
+
}
|
|
179
226
|
// operator's word at Release?: this flow ships without a version bump or tag — recorded only once Release? is answered.
|
|
180
227
|
// gh#198: --version=<v> / --no-version here re-make the call recorded with Verified? (the operator changed their mind)
|
|
181
228
|
const relArg = versionArg(flagValue(o.rest, "version"), flag("no-version"));
|
|
@@ -242,7 +289,10 @@ export async function gateRelease(o: GateCtx): Promise<RunResult> {
|
|
|
242
289
|
const conflictMarkers = markerDiff?.ok ? conflictMarkerLines(markerDiff.out) : undefined;
|
|
243
290
|
const prep = { manifestVersion: manifestVer, remoteTags, changelog, changelogChanged, changelogBase, noFoldCheck: flag("no-fold-check"), conflictMarkers, noMarkerCheck: flag("no-marker-check") };
|
|
244
291
|
// same freshness rule as verify: a green predating a worktree write may not stand for the tree this gate blesses
|
|
245
|
-
|
|
292
|
+
// — except across a commit that is nothing but release prep: those greens are carried onto the current tree
|
|
293
|
+
const fpRelease = await worktreeFingerprint(wtCwd);
|
|
294
|
+
const keptThroughPrep = await keepThroughPrep(root, state!, cfg, fpRelease);
|
|
295
|
+
if (freshenChecks(state!, fpRelease).length || keptThroughPrep.length) writeState(root, state!);
|
|
246
296
|
// gh#198: the branch must carry the call the operator made — a bump they did not choose, or a bump on a flow
|
|
247
297
|
// they said merges unreleased, is prep that contradicts the word Release? would stand on. It runs before the
|
|
248
298
|
// generic proofs: when a parallel flow released first, "already tagged" alone would send the agent round a loop.
|
|
@@ -271,7 +321,22 @@ export async function gateRelease(o: GateCtx): Promise<RunResult> {
|
|
|
271
321
|
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
322
|
}
|
|
273
323
|
// tier-2 pre-release confirmation is recorded by this very command, so it is excluded here
|
|
274
|
-
|
|
324
|
+
// The checks this gate needs green are run by the gate, as verify does (#84) — after the cheap proofs, so a
|
|
325
|
+
// wrong version or a missing changelog entry is refused before minutes are spent on a suite.
|
|
326
|
+
const owed = state!.docs ? [] : cfg.checkList.filter((c) => !state!.checks[c.name]?.ok);
|
|
327
|
+
const assumed = { ...state!.checks, ...Object.fromEntries(owed.map((c) => [c.name, { ok: true, at: now() }])) };
|
|
328
|
+
const gateState = (checks: FlowState["checks"]) => ({ ...state!, checks, noVersion, confirmations: { ...state!.confirmations, "pre-release": { hash: checklistHash(items), at: now() } } });
|
|
329
|
+
const cheap = preReleaseGate(gateState(assumed), cfg, prep);
|
|
330
|
+
if (cheap.length) return { text: `release gate FAILED:\n- ${cheap.join("\n- ")}`, isError: true };
|
|
331
|
+
// read off the records, not this call: an earlier run of this gate (the one that asked Release?) may have carried them
|
|
332
|
+
const carried = Object.entries(state!.checks).filter(([, r]) => r.ok && r.prep).map(([n]) => n);
|
|
333
|
+
let checksNote = carried.length ? ` Checks kept (${carried.join(", ")}): only release prep was committed since they passed.` : "";
|
|
334
|
+
if (owed.length) {
|
|
335
|
+
const ran = await runChecks(root, state!, cfg, owed);
|
|
336
|
+
if (ran.failed) return { text: `release gate FAILED — a check run at the gate failed:\n${ran.lines.join("\n")}`, isError: true };
|
|
337
|
+
checksNote += ` Checks ran at the gate (${owed.map((c) => c.name).join(", ")}).`;
|
|
338
|
+
}
|
|
339
|
+
const preGate = preReleaseGate(gateState(state!.checks), cfg, prep);
|
|
275
340
|
if (preGate.length) return { text: `release gate FAILED:\n- ${preGate.join("\n- ")}`, isError: true };
|
|
276
341
|
// the build the tag will trigger, proven before anything ships: a broken artifact build found after the
|
|
277
342
|
// tag costs follow-up PRs and a re-cut tag
|
|
@@ -298,7 +363,7 @@ export async function gateRelease(o: GateCtx): Promise<RunResult> {
|
|
|
298
363
|
? `Shipped since ${behind}: ${missing.slice(0, 8).join(", ")}${missing.length > 8 ? ` …(${missing.length} total)` : ""} — see ${clPath}. `
|
|
299
364
|
: `What shipped between them is not readable from the checkout's CHANGELOG.md — read it before deciding. `) +
|
|
300
365
|
`Update (/reload, then re-run flow release on the current build) or proceed with the old release?`;
|
|
301
|
-
staleNote = `released under dev-flow ${behind} (${selfBuild.label} ${selfBuild.version ?? "?"})
|
|
366
|
+
staleNote = `released under dev-flow ${behind} (${selfBuild.label} ${selfBuild.version ?? "?"}) — the operator was asked update-or-proceed and chose to proceed; proofs newer than ${behind} did not run`;
|
|
302
367
|
}
|
|
303
368
|
// #162: Verified? was answered over one tree; commits after it ship under that word unless someone says
|
|
304
369
|
// so. A warning, never a refusal — doc-only moves after verify are normal; the operator decides.
|
|
@@ -320,8 +385,8 @@ export async function gateRelease(o: GateCtx): Promise<RunResult> {
|
|
|
320
385
|
// gh#187: the release-prep commit (the bump, the changelog entry, whatever else the bump rewrites — an
|
|
321
386
|
// image tag in a compose file) lands after Verified? by design and no container verdict could cover
|
|
322
387
|
// it. It is the commit that touches the version file, or one that touches nothing but prep files.
|
|
323
|
-
const
|
|
324
|
-
const isPrep = (c: { files: string[] }) => (!!cfg.versioning.file && c.files.includes(cfg.versioning.file)) || (c.files.length > 0 && c.files.every((f) =>
|
|
388
|
+
const prepSet = prepFiles(cfg);
|
|
389
|
+
const isPrep = (c: { files: string[] }) => (!!cfg.versioning.file && c.files.includes(cfg.versioning.file)) || (c.files.length > 0 && c.files.every((f) => prepSet.has(f)));
|
|
325
390
|
const prep = commits.filter(isPrep);
|
|
326
391
|
const changed = commits.filter((c) => !isPrep(c));
|
|
327
392
|
// changed code shipping under an earlier word is friction the closing reflection should look at
|
|
@@ -332,16 +397,26 @@ export async function gateRelease(o: GateCtx): Promise<RunResult> {
|
|
|
332
397
|
// a standing yolo (given at an earlier checkpoint) stops short of Release? when the playbook says so, or
|
|
333
398
|
// when commits landed after Verified? — the word was given before those commits existed (gh#176).
|
|
334
399
|
// --confirmed is the operator's own answer at this checkpoint, yolo-at-Release? included: it always stands.
|
|
335
|
-
|
|
400
|
+
// gh#219, gh#217: --confirmed is the operator's answer to a question this gate put to them. Where a question
|
|
401
|
+
// must be put — a standing yolo the playbook or new commits hold back, or a stale build only they can choose
|
|
402
|
+
// to release under — a --confirmed that arrives before the gate asked answers nothing: it is a replayed
|
|
403
|
+
// flag, and the "by operator choice" record would name a choice nobody was offered. The gate asks first; the
|
|
404
|
+
// answer to that ask (an operator message after it — the grant ledger's rule) is what stands.
|
|
405
|
+
const holdWhy = !state!.yolo
|
|
336
406
|
? ""
|
|
337
407
|
: cfg.release.yolo === "until-release"
|
|
338
408
|
? "the playbook sets yolo = until-release: a yolo given earlier never answers Release? — ask it"
|
|
339
409
|
: postVerify
|
|
340
410
|
? "a yolo given earlier does not cover commits that landed after Verified? — ask Release? with them named"
|
|
341
|
-
:
|
|
411
|
+
: stale
|
|
412
|
+
? "a yolo given earlier does not choose to release under an older dev-flow build — ask Release? with the update-or-proceed question"
|
|
413
|
+
: "";
|
|
414
|
+
const mustAskFirst = !!holdWhy || stale;
|
|
415
|
+
const confirmed = flag("confirmed") && !(mustAskFirst && !ui.hasUI && state!.pendingAsk !== "Release?");
|
|
416
|
+
const yoloHeld = confirmed ? "" : holdWhy;
|
|
342
417
|
// gh#198: release.ask = on-change — Release? answers itself when it would only re-confirm Verified?: the call
|
|
343
418
|
// 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" && !
|
|
419
|
+
const onChange = cfg.release.ask !== "always" && !confirmed && !state!.yolo;
|
|
345
420
|
const askWhy = !onChange
|
|
346
421
|
? ""
|
|
347
422
|
: !state!.verifiedHead
|
|
@@ -360,8 +435,8 @@ export async function gateRelease(o: GateCtx): Promise<RunResult> {
|
|
|
360
435
|
? `${newest} → ${manifestVer} is a major bump — the playbook's versioned call does not choose that`
|
|
361
436
|
: "";
|
|
362
437
|
const auto = onChange && !askWhy;
|
|
363
|
-
let audit =
|
|
364
|
-
const askPending = !auto && !
|
|
438
|
+
let audit = 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)" : "";
|
|
439
|
+
const askPending = !auto && !confirmed && (!state!.yolo || !!yoloHeld);
|
|
365
440
|
if (askPending) {
|
|
366
441
|
markPendingAsk(root, state!, "Release?");
|
|
367
442
|
if (!ui.hasUI) {
|
|
@@ -396,8 +471,15 @@ export async function gateRelease(o: GateCtx): Promise<RunResult> {
|
|
|
396
471
|
if (!state!.noVersion && manifestVer) state!.releaseVersion = manifestVer;
|
|
397
472
|
if (stale) state!.staleBuild = `${behind} (${selfBuild.label} ${selfBuild.version ?? "?"})`;
|
|
398
473
|
delete state!.pendingAsk;
|
|
474
|
+
// on GitHub the gate runs the release stage itself: the Release? answer (or its self-answer) is what authorizes
|
|
475
|
+
// the merge and the tag, exactly as it authorized the agent to run them by hand
|
|
476
|
+
const selfPublish = await gatePublishes(cfg, forgeOf(cfg, await originUrl(root)), root);
|
|
477
|
+
if (selfPublish) state!.publish = {};
|
|
478
|
+
else delete state!.publish;
|
|
399
479
|
writeState(root, state!);
|
|
400
|
-
|
|
480
|
+
const approved = `release approved${audit}${state!.noVersion ? " — unversioned: no bump or tag; your changelog entry rides under Unreleased until the next versioned release folds it" : ""} — entering release stage.${manifestVer ? ` Version ${manifestVer}.` : ""}${checksNote}${foldNote}${staleNote ? ` ${staleNote}.` : ""}${postVerify ? ` Warning: ${postVerify}.` : ""}\n${describeBranchState(branchProof, cfg.defaultBranch)}`;
|
|
481
|
+
if (selfPublish) return publishAndRecord(o, state!, approved);
|
|
482
|
+
return { text: `${approved}\n${AGENT_MARK}next: ${nextHint(state!, cfg)}` };
|
|
401
483
|
}
|
|
402
484
|
|
|
403
485
|
/** How long release-done waits on the publish CI a tag push started; a seam so tests run in milliseconds. */
|
|
@@ -450,12 +532,12 @@ export async function awaitArtifact(cmd: string, tag: string, root: string): Pro
|
|
|
450
532
|
return {
|
|
451
533
|
...art,
|
|
452
534
|
waited: failed.length
|
|
453
|
-
? `the CI ${tag} started did not pass — ${failed.map((r) => `${r.workflowName}: ${r.conclusion || "?"} (${r.url})`).join(", ")}; fix and re-publish, then re-run
|
|
535
|
+
? `the CI ${tag} started did not pass — ${failed.map((r) => `${r.workflowName}: ${r.conclusion || "?"} (${r.url})`).join(", ")}; fix and re-publish, then re-run flow finish`
|
|
454
536
|
: `every CI run ${tag} started finished green, yet the artifact is missing — check where the publish workflow pushes`,
|
|
455
537
|
};
|
|
456
538
|
}
|
|
457
539
|
if (elapsed >= artifactWait.budgetMs)
|
|
458
|
-
return { ...art, waited: `the publish CI is still running after ${mins()} (${pending.map((r) => `${r.workflowName}: ${r.url}`).join(", ")}) — re-run
|
|
540
|
+
return { ...art, waited: `the publish CI is still running after ${mins()} (${pending.map((r) => `${r.workflowName}: ${r.url}`).join(", ")}) — re-run flow finish once it finishes` };
|
|
459
541
|
await artifactWait.sleep(artifactWait.pollMs);
|
|
460
542
|
}
|
|
461
543
|
}
|
|
@@ -643,7 +725,7 @@ export async function gateFinishCore(o: GateCtx): Promise<RunResult> {
|
|
|
643
725
|
const { state, err } = needState(root, sess, slugArg);
|
|
644
726
|
if (err) return err;
|
|
645
727
|
if (!state!.approvals.release)
|
|
646
|
-
return { text: `finish closes a released feature — stage is "${state!.stage}" and no release is recorded;
|
|
728
|
+
return { text: `finish closes a released feature — stage is "${state!.stage}" and no release is recorded; publish it first — flow release (to abandon an unfinished feature, run flow abort)`, isError: true };
|
|
647
729
|
// after this the flow state is gone: nothing may sit uncommitted or unpushed
|
|
648
730
|
const dirty = await sh("git status --porcelain", root);
|
|
649
731
|
if (dirty.ok && dirty.out.trim()) return { text: `main checkout has uncommitted changes — commit them first (finish deletes .dev-flow/${state!.slug}/):\n${tail(dirty.out)}`, isError: true };
|
|
@@ -669,6 +751,20 @@ export async function gateFinishCore(o: GateCtx): Promise<RunResult> {
|
|
|
669
751
|
: ` local ${cfg.defaultBranch} trails origin/${cfg.defaultBranch} and did not fast-forward cleanly — sync by hand: git -C ${sq(root)} pull --ff-only`;
|
|
670
752
|
}
|
|
671
753
|
}
|
|
754
|
+
// After-merge checks (flow-check blocks under ## release): run from the main checkout, which now holds the
|
|
755
|
+
// merged release, before anything is removed. They are the scripted form of a release-stage checklist item —
|
|
756
|
+
// the gate sees them pass instead of the operator waving through a command the agent says it ran (gh#210).
|
|
757
|
+
let releaseChecksNote = "";
|
|
758
|
+
if (!state!.docs && cfg.releaseChecks.length) {
|
|
759
|
+
const owed = cfg.releaseChecks.filter((c) => !state!.checks[`release:${c.name}`]?.ok);
|
|
760
|
+
for (const c of owed) {
|
|
761
|
+
const res = await sh(c.cmd, root, undefined, devEnv(root, state!, cfg));
|
|
762
|
+
state!.checks[`release:${c.name}`] = { ok: res.ok, at: now() };
|
|
763
|
+
writeState(root, state!);
|
|
764
|
+
if (!res.ok) return { text: `finish blocked — after-merge check "${c.name}" failed in the main checkout (${c.cmd}); nothing was removed:\n${tail(res.out)}`, isError: true };
|
|
765
|
+
}
|
|
766
|
+
releaseChecksNote = ` after-merge checks green (${cfg.releaseChecks.map((c) => c.name).join(", ")}).`;
|
|
767
|
+
}
|
|
672
768
|
// the cleanup part of closing out: drop the worktree and branch the release consumed
|
|
673
769
|
const wt = worktreeAbs(root, state!);
|
|
674
770
|
let closeNote: string;
|
|
@@ -699,7 +795,7 @@ export async function gateFinishCore(o: GateCtx): Promise<RunResult> {
|
|
|
699
795
|
}
|
|
700
796
|
}
|
|
701
797
|
// a forge release that failed at release-done is still the operator's call — but they must see it before the state vanishes (#63)
|
|
702
|
-
const forgeSkipNote = state!.forgeReleaseSkipped ? ` WARNING: the forge release was not created (${state!.forgeReleaseSkipped}) — recreate it manually or
|
|
798
|
+
const forgeSkipNote = state!.forgeReleaseSkipped ? ` WARNING: the forge release was not created (${state!.forgeReleaseSkipped}) — recreate it manually or have the operator run /flow release-done before finishing.` : "";
|
|
703
799
|
// the one finish question — asked after the safety checks so it can never be a wasted question
|
|
704
800
|
// yolo works uniformly at every gate: at Finish? nothing later remains to pre-confirm, the flag just answers this one
|
|
705
801
|
const yoloWord = takeYoloWord(state!);
|
|
@@ -717,13 +813,22 @@ export async function gateFinishCore(o: GateCtx): Promise<RunResult> {
|
|
|
717
813
|
const quiet = !state!.reflectedAt && !skipReflect && cfg.release.reflect !== "always" && !(state!.friction ?? 0) && !note.trim();
|
|
718
814
|
if (quiet) {
|
|
719
815
|
state!.reflectedAt = now();
|
|
816
|
+
state!.reflectQuiet = true;
|
|
720
817
|
writeState(root, state!);
|
|
721
818
|
}
|
|
722
819
|
const quietNote = quiet ? " closing reflection skipped: no refusals, guard blocks or unverified changes this flow (playbook reflect = always runs it anyway)." : "";
|
|
723
820
|
if (!state!.reflectedAt && !skipReflect) {
|
|
724
821
|
const skipHint = "or — only on the operator's explicit word — flow finish --no-reflect --confirmed";
|
|
725
822
|
if (!o.hooks.reflect) return { text: `finish: no reflection recorded for ${state!.slug} and no reflect worker available here — run flow_stage(op: "reflect") first, ${skipHint}`, isError: true };
|
|
726
|
-
|
|
823
|
+
// gh#216: a worker that dies must come back as a refusal the driver can read — never as nothing at all,
|
|
824
|
+
// which spends the operator's word and leaves a shipped feature open with no sign anything failed
|
|
825
|
+
let r: Awaited<ReturnType<NonNullable<typeof o.hooks.reflect>>>;
|
|
826
|
+
try {
|
|
827
|
+
r = await o.hooks.reflect(state!, flagValue(o.rest, "note") ?? "");
|
|
828
|
+
} catch (e) {
|
|
829
|
+
r = { text: `the reflection worker failed: ${e instanceof Error ? e.message : String(e)}`, recorded: false, findings: 0, failed: true };
|
|
830
|
+
}
|
|
831
|
+
if (!r.recorded && !r.text.trim()) r = { ...r, text: "the reflection worker returned nothing — no report, no error" };
|
|
727
832
|
const cur = readState(root, state!.slug) ?? state!; // the worker stamped reflectedAt on disk
|
|
728
833
|
if (!r.recorded)
|
|
729
834
|
return { text: `finish: the closing reflection did not report — nothing was removed.\n\n${r.text}\n\nNext: re-run flow finish to retry, or review inline (bare flow reflect prints the protocol) and then flow_stage(op: "reflect"), ${skipHint}.`, isError: true };
|
|
@@ -735,7 +840,14 @@ export async function gateFinishCore(o: GateCtx): Promise<RunResult> {
|
|
|
735
840
|
return { text: needsOperator(`the closing reflection has findings — nothing was removed yet; your fold/drop answer also finishes the feature.\n\n${r.text}`, "Fold or drop?", `the fold/drop answer is the Finish? answer: apply it, then run flow finish --confirmed without asking again — the worktree, branch and .dev-flow/${state!.slug}/ go on that run`), isError: true };
|
|
736
841
|
}
|
|
737
842
|
const reflectSkipNote = skipReflect && !state!.reflectedAt ? ` Reflection skipped on the operator's word — nothing re-checked this session or the open reflections.` : "";
|
|
738
|
-
|
|
843
|
+
// Finish? answers itself on a clean flow (release.finish = on-change, the default): the release is recorded,
|
|
844
|
+
// main is clean and pushed, the worktree holds nothing uncommitted, nothing was skipped and nothing is open —
|
|
845
|
+
// the question had no decision left in it. Anything open (a reflection that ran, release-stage items, a
|
|
846
|
+
// forge release that failed, a skipped reflection) still asks.
|
|
847
|
+
const openReleaseItems = checklistPending(cfg, state!, "release");
|
|
848
|
+
const autoFinish = cfg.release.finish !== "always" && !flag("confirmed") && !state!.yolo && !!state!.reflectQuiet && !openReleaseItems && !forgeSkipNote && !skipReflect;
|
|
849
|
+
const autoNote = autoFinish ? " Finish? answered itself (finish = on-change): the release is recorded, nothing was skipped and nothing is open." : "";
|
|
850
|
+
const askPending = !flag("confirmed") && !state!.yolo && !autoFinish;
|
|
739
851
|
if (askPending) {
|
|
740
852
|
markPendingAsk(root, state!, "Finish?");
|
|
741
853
|
if (!ui.hasUI) {
|
|
@@ -750,21 +862,7 @@ export async function gateFinishCore(o: GateCtx): Promise<RunResult> {
|
|
|
750
862
|
return { text: "finish declined" };
|
|
751
863
|
}
|
|
752
864
|
}
|
|
753
|
-
|
|
754
|
-
// port's stack stays up — it is the machine's shared app, and the next flow redeploys over it
|
|
755
|
-
let devDownNote = "";
|
|
756
|
-
if (state!.devPort !== undefined && state!.devPort !== cfg.devPort) {
|
|
757
|
-
if (cfg.commands.devDown) {
|
|
758
|
-
const down = await sh(cfg.commands.devDown, gateCwd(root, state!), 5 * 60_000, devEnv(root, state!, cfg));
|
|
759
|
-
devDownNote = down.ok ? ` dev instance on port ${state!.devPort} stopped (${cfg.commands.devDown}).` : ` dev instance on port ${state!.devPort} did NOT stop (${cfg.commands.devDown}) — stop it by hand:\n${tail(down.out)}\n`;
|
|
760
|
-
} else devDownNote = ` dev instance on port ${state!.devPort} is still running — the playbook has no devDown to stop it; stop it by hand.`;
|
|
761
|
-
}
|
|
762
|
-
const reg = readDevPorts(root);
|
|
763
|
-
const mine = Object.keys(reg).filter((k) => reg[k].slug === state!.slug);
|
|
764
|
-
if (mine.length) {
|
|
765
|
-
for (const k of mine) delete reg[k];
|
|
766
|
-
writeDevPorts(root, reg);
|
|
767
|
-
}
|
|
865
|
+
const devDownNote = await releaseDevSlot(root, state!, cfg);
|
|
768
866
|
if (wt && existsSync(wt)) {
|
|
769
867
|
const rm = await sh(`git worktree remove ${sq(wt)} && git branch -D ${sq(state!.branch)}`, root);
|
|
770
868
|
if (!rm.ok) return { text: `worktree removal failed:\n${rm.out}\nif files are owned by another user (e.g. root-owned docker build output), remove ${state!.worktree} manually and rerun flow finish`, isError: true };
|
|
@@ -808,5 +906,5 @@ export async function gateFinishCore(o: GateCtx): Promise<RunResult> {
|
|
|
808
906
|
// finish is the moment between flows: name the fix / tidy suggestion when a rule fires, nothing otherwise
|
|
809
907
|
const nudge = reflectionNudges(readReflectionsText(root), now().slice(0, 10), { between: true });
|
|
810
908
|
const nudgeNote = [nudge.fix, nudge.tidy].filter(Boolean).map((n) => ` ${n} — offer it to the operator.`).join("");
|
|
811
|
-
return { text: `feature ${state!.slug} done — ${closeNote}${remoteNote}; .dev-flow/${state!.slug}/ removed.${devDownNote}${roadmapNote}${forgeSkipNote}${reflectSkipNote}${quietNote}${syncNote}${nudgeNote} Re-read flow status before reporting open flows — a sibling feature may have finished while this session ran.` };
|
|
909
|
+
return { text: `feature ${state!.slug} done — ${closeNote}${remoteNote}; .dev-flow/${state!.slug}/ removed.${devDownNote}${roadmapNote}${forgeSkipNote}${reflectSkipNote}${quietNote}${releaseChecksNote}${autoNote}${syncNote}${nudgeNote} Re-read flow status before reporting open flows — a sibling feature may have finished while this session ran.` };
|
|
812
910
|
}
|