pi-dev-flow 0.92.1 → 0.94.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 +33 -0
- package/docs/gates.md +30 -8
- package/docs/guardrails.md +5 -1
- package/docs/playbook.md +2 -2
- package/extensions/dev-flow.ts +27 -4
- package/package.json +1 -1
- package/skills/dev-flow/SKILL.md +6 -6
- package/skills/dev-flow/references/implement.md +10 -1
- package/skills/dev-flow/references/pre-release.md +12 -6
- package/skills/dev-flow/references/reflect.md +5 -3
- package/skills/flow-review/SKILL.md +1 -1
- package/src/core.ts +174 -34
- package/src/present.ts +6 -3
- package/src/projectmd.ts +41 -7
- package/src/runtime/base.ts +18 -3
- package/src/runtime/checks.ts +30 -9
- package/src/runtime/gates.ts +69 -14
- package/src/runtime/publish.ts +30 -5
- package/src/runtime/ship.ts +68 -20
package/src/runtime/gates.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** dev-flow runtime — The gate runner and the gates that do not ship anything. Moved out of extensions/dev-flow.ts as is (exports added). */
|
|
2
2
|
import { copyFileSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import { approveGate, applicableItems, appendRoadmapItem, checklistHash, claimBlocks, doneItemCount, detectForge, gateHelpJson, healthProbe, parseMergeStyle, investigationBrief, pluginVersion, reflectProtocol, reflectUnfiledCount, reflectionNudges, reflectionRoutes, listFiles, needsOperator, newState, nextHint, openChecklistItems, releaseGate, roadmapDone, roadmapDrop, roadmapOpenCount, roadmapBriefFor, roadmapPick, roadmapTidy, statusJson, subst, sq, featureTmpDir, foreignWorktreeLinks, validSlug, verifyGate, STAGE_EMOJI, type ReflectTarget, type Config, type FlowState } from "../core.ts";
|
|
4
|
+
import { approveGate, applicableItems, appendRoadmapItem, checklistHash, claimBlocks, doneItemCount, detectForge, gateHelpJson, healthProbe, parseMergeStyle, investigationBrief, pluginVersion, reflectProtocol, reflectUnfiledCount, reflectionNudges, reflectionRoutes, listFiles, needsOperator, newState, nextHint, openChecklistItems, releaseGate, roadmapDone, roadmapDrop, roadmapOpenCount, roadmapOpenRows, roadmapBriefFor, roadmapPick, roadmapTidy, statusJson, subst, sq, featureTmpDir, foreignWorktreeLinks, validSlug, verifyGate, STAGE_EMOJI, type ReflectTarget, type Config, type FlowState } from "../core.ts";
|
|
5
5
|
import { applyAnswers, buildDraft, doctorFindings, ghostFeatureDirs, ghostInfo, lineDiff, loadProject, mdDigest, parseAnswers, parseProjectMd } from "../projectmd.ts";
|
|
6
6
|
import { linkedTag } from "../fold.ts";
|
|
7
7
|
import { detectProject } from "../detect.ts";
|
|
@@ -73,6 +73,9 @@ export async function runFlow(args: string[], root: string, ui: Ui, sess: Sessio
|
|
|
73
73
|
case "health":
|
|
74
74
|
return gateHealth(o);
|
|
75
75
|
|
|
76
|
+
case "review":
|
|
77
|
+
return gateReview(o);
|
|
78
|
+
|
|
76
79
|
case "release":
|
|
77
80
|
return gateRelease(o);
|
|
78
81
|
|
|
@@ -89,7 +92,8 @@ export async function runFlow(args: string[], root: string, ui: Ui, sess: Sessio
|
|
|
89
92
|
return gateAbort(o);
|
|
90
93
|
|
|
91
94
|
default:
|
|
92
|
-
|
|
95
|
+
// gh#238: the unknown word first and alone — the full usage buried it
|
|
96
|
+
return { text: `unknown subcommand "${sub.length > 120 ? `${sub.slice(0, 120)}…` : sub}" — known: ${GATE_HELP.split(" — ")[0].split(" | ").map((g) => g.split(" ")[0]).join(", ")}; flow help prints the usage`, isError: true };
|
|
93
97
|
}
|
|
94
98
|
}
|
|
95
99
|
/** Records the checkpoint word a gate asked for and has not been given: the footer shows 💬 (“operator,
|
|
@@ -554,12 +558,20 @@ export async function gateRoadmap(o: GateCtx): Promise<RunResult> {
|
|
|
554
558
|
const open = roadmapOpenCount(text);
|
|
555
559
|
const done = doneItemCount(text);
|
|
556
560
|
const save = (next: string) => writeFileSync(roadmapFile(root), next); // .dev-flow/ existence is runFlow's precondition
|
|
561
|
+
// gh#245: numbers are row numbers (open and done items) — a done keeps every other number where list printed it
|
|
562
|
+
const rows = roadmapOpenRows(text);
|
|
563
|
+
const openRows = new Set(rows.map((r) => r.row));
|
|
557
564
|
const idx = Number(args[0]);
|
|
558
|
-
const validIdx = Number.isInteger(idx) && idx
|
|
565
|
+
const validIdx = Number.isInteger(idx) && openRows.has(idx);
|
|
566
|
+
const rowRange = rows.length ? `an open row (${rows.map((r) => r.row).join(", ")})` : "an open item (none open)";
|
|
567
|
+
// done/drop take a batch (`done 6,7` or `done 6 7`), resolved against the list as it stands before any edit
|
|
568
|
+
const batch = [...new Set(args.flatMap((a) => a.split(",")).map((a) => a.trim()).filter(Boolean))];
|
|
569
|
+
const batchNums = batch.map(Number);
|
|
570
|
+
const badBatch = batch.filter((_, i) => !Number.isInteger(batchNums[i]) || !openRows.has(batchNums[i]));
|
|
559
571
|
switch (verb) {
|
|
560
572
|
case "list": {
|
|
561
573
|
if (!open) return { text: done ? `roadmap: nothing open (${done} done — flow roadmap tidy drops them)` : "roadmap: empty — flow roadmap add \"<future feature>\"" };
|
|
562
|
-
return { text: [`roadmap — ${open} open (${done} done):`, ...
|
|
574
|
+
return { text: [`roadmap — ${open} open (${done} done; numbers are row numbers: done leaves the others as they are, drop and tidy renumber):`, ...rows.map((r) => ` ${r.row}. ${r.item}`)].join("\n") };
|
|
563
575
|
}
|
|
564
576
|
case "add": {
|
|
565
577
|
if (!args.length) return { text: 'usage: flow roadmap add "<future feature>" [--slug=<slug>] [--brief=<notes>|--brief-file=<path>]', isError: true };
|
|
@@ -576,33 +588,44 @@ export async function gateRoadmap(o: GateCtx): Promise<RunResult> {
|
|
|
576
588
|
}
|
|
577
589
|
case "pick": {
|
|
578
590
|
const slug = args[1] ?? "";
|
|
579
|
-
if (!validIdx) return { text: `pick:
|
|
591
|
+
if (!validIdx) return { text: `pick: ${rowRange} required — flow roadmap lists them`, isError: true };
|
|
580
592
|
if (!slug || !validSlug(slug)) return { text: `usage: flow roadmap pick <n> <slug> — the slug flow start will use (lowercase, dashes)`, isError: true };
|
|
581
593
|
save(roadmapPick(text, idx, slug)!);
|
|
582
594
|
return { text: `roadmap: item ${idx} picked for ${slug} — now: flow start ${slug} (flow finish checks the item off when it ships)` };
|
|
583
595
|
}
|
|
584
596
|
case "done": {
|
|
585
|
-
if (!
|
|
597
|
+
if (!batch.length || badBatch.length) return { text: `done: ${badBatch.length ? `${badBatch.join(", ")} ${badBatch.length > 1 ? "are" : "is"} not ` : ""}${rowRange}${badBatch.length ? "" : " required"} — nothing was changed; flow roadmap lists them`, isError: true };
|
|
586
598
|
// stamped with date + bound slug, so history says what shipped it
|
|
587
|
-
|
|
588
|
-
|
|
599
|
+
const stamp = [new Date().toISOString().slice(0, 10), sess.slug].filter(Boolean).join(" ");
|
|
600
|
+
let next = text;
|
|
601
|
+
for (const n of batchNums) next = roadmapDone(next, n, stamp)!; // rows stay put under done
|
|
602
|
+
save(next);
|
|
603
|
+
const names = batchNums.map((n) => `${n}. ${rows.find((r) => r.row === n)!.item}`);
|
|
604
|
+
return { text: `roadmap: ${batchNums.length > 1 ? `${batchNums.length} items` : `item ${batchNums[0]}`} marked done (${open - batchNums.length} open) — ${names.join(" | ")}` };
|
|
589
605
|
}
|
|
590
606
|
case "drop":
|
|
591
607
|
case "remove":
|
|
592
608
|
case "delete": {
|
|
593
609
|
// not shipped, not wanted: gone from the backlog, so the done list never claims it was built
|
|
594
|
-
if (!
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
610
|
+
if (!batch.length || badBatch.length) return { text: `drop: ${badBatch.length ? `${badBatch.join(", ")} ${badBatch.length > 1 ? "are" : "is"} not ` : ""}${rowRange}${badBatch.length ? "" : " required"} — nothing was changed; flow roadmap lists them`, isError: true };
|
|
611
|
+
let next = text;
|
|
612
|
+
const gone: string[] = [];
|
|
613
|
+
// highest row first: removing a row shifts only the rows below it
|
|
614
|
+
for (const n of [...batchNums].sort((a, b) => b - a)) {
|
|
615
|
+
const r = roadmapDrop(next, n)!;
|
|
616
|
+
next = r.text;
|
|
617
|
+
gone.unshift(`"${r.item}"`);
|
|
618
|
+
}
|
|
619
|
+
save(next);
|
|
620
|
+
return { text: `roadmap: ${gone.length > 1 ? `${gone.length} items` : `item ${batchNums[0]}`} dropped — ${gone.join(", ")} (${open - gone.length} open); the row numbers below changed — run flow roadmap before the next pick, done or drop` };
|
|
598
621
|
}
|
|
599
622
|
case "tidy": {
|
|
600
623
|
if (!done) return { text: `roadmap: nothing to tidy (${open} open, 0 done)` };
|
|
601
624
|
save(roadmapTidy(text));
|
|
602
|
-
return { text: `roadmap: dropped ${done} done item(s) — ${open} open` };
|
|
625
|
+
return { text: `roadmap: dropped ${done} done item(s) — ${open} open; the row numbers changed — run flow roadmap before the next pick, done or drop` };
|
|
603
626
|
}
|
|
604
627
|
default:
|
|
605
|
-
return { text: "usage: flow roadmap [list|add <text> [--slug=<slug>] [--brief=<notes>|--brief-file=<path>]|pick <n> <slug>|done <n
|
|
628
|
+
return { text: "usage: flow roadmap [list|add <text> [--slug=<slug>] [--brief=<notes>|--brief-file=<path>]|pick <n> <slug>|done <n>[,<n>…]|drop <n>[,<n>…]|tidy] — <n> is the row number flow roadmap prints", isError: true };
|
|
606
629
|
}
|
|
607
630
|
}
|
|
608
631
|
|
|
@@ -706,6 +729,38 @@ export async function gateHealth(o: GateCtx): Promise<RunResult> {
|
|
|
706
729
|
return { text: `health: ${res.ok ? "PASS" : "FAIL"} (${probe}${triedNote(res.attempts)})\n${tail(res.out)}` };
|
|
707
730
|
}
|
|
708
731
|
|
|
732
|
+
/** gh#233: records the review flow verify (before Verified?) and flow release require. `done "<verdict>"` — the agent ran the playbook's
|
|
733
|
+
* review step inline; `--skip` — the operator's word to ship without one (asked first: Skip review?). A
|
|
734
|
+
* flow_stage review worker records itself. Bare: what is on record. Bound flow only — `done`'s verdict is free text. */
|
|
735
|
+
export async function gateReview(o: GateCtx): Promise<RunResult> {
|
|
736
|
+
const { root, ui, sess, cfg, rest, flag } = o;
|
|
737
|
+
const { state, err } = needState(root, sess);
|
|
738
|
+
if (err) return err;
|
|
739
|
+
const st = state!;
|
|
740
|
+
const words = rest.filter((a) => !a.startsWith("--"));
|
|
741
|
+
const onRecord = st.review
|
|
742
|
+
? `review on record: ${st.review.by === "skipped" ? "skipped on the operator's word" : `${st.review.by}${st.review.head ? ` over ${st.review.head.slice(0, 7)}` : ""}${st.review.verdict ? ` — ${st.review.verdict}` : ""}`} (${ago(st.review.at)})`
|
|
743
|
+
: "no review on record";
|
|
744
|
+
if (!words.length && !flag("skip")) return { text: `${onRecord}${cfg.release.review ? ` — flow verify requires one before Verified? (${cfg.release.review})` : " — the playbook sets no review step"}` };
|
|
745
|
+
if (st.stage !== "implement" && st.stage !== "pre-release") return { text: `review is recorded at implement or pre-release — ${st.slug} is at ${st.stage}`, isError: true };
|
|
746
|
+
const head = st.worktree ? (await sh("git rev-parse HEAD", gateCwd(root, st))).out.trim() : "";
|
|
747
|
+
if (flag("skip")) {
|
|
748
|
+
if (!flag("confirmed")) {
|
|
749
|
+
const ok = ui.hasUI && (await ui.confirm("Skip review?", `Release ${st.slug} without the review step (${cfg.release.review || "none set"})?`));
|
|
750
|
+
if (!ok) return { text: needsOperator(`shipping without a review is the operator's word — the playbook's review step is ${cfg.release.review || "unset"}`, "Skip review?", "ask the operator in chat, then re-run flow review --skip --confirmed once they answer"), isError: true };
|
|
751
|
+
}
|
|
752
|
+
st.review = { by: "skipped", at: now(), ...(head ? { head } : {}) };
|
|
753
|
+
writeState(root, st);
|
|
754
|
+
return { text: `review skipped on the operator's word — flow release will not ask for one` };
|
|
755
|
+
}
|
|
756
|
+
if (words[0] !== "done") return { text: `usage: flow review [done "<verdict>"] | --skip [--confirmed]`, isError: true };
|
|
757
|
+
const verdict = words.slice(1).join(" ").trim();
|
|
758
|
+
if (!verdict) return { text: `flow review done needs the verdict in a line — e.g. flow review done "PASS — 2 should-fix items fixed in abc1234"`, isError: true };
|
|
759
|
+
st.review = { by: "inline", at: now(), ...(head ? { head } : {}), verdict: verdict.slice(0, 300) };
|
|
760
|
+
writeState(root, st);
|
|
761
|
+
return { text: `review recorded${head ? ` over ${head.slice(0, 7)}` : ""} — ${st.review.verdict}` };
|
|
762
|
+
}
|
|
763
|
+
|
|
709
764
|
export async function gateUse(o: GateCtx): Promise<RunResult> {
|
|
710
765
|
const { root, sess, slugArg } = o;
|
|
711
766
|
if (!slugArg) return { text: "usage: flow use <slug>", isError: true };
|
package/src/runtime/publish.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { existsSync, readFileSync } from "node:fs";
|
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import { pickReleaseNotes, prepOnlyChange, sq } from "../core.ts";
|
|
8
8
|
import type { Config, FlowState } from "../core.ts";
|
|
9
|
-
import { gateCwd, mergeBase, releaseTags, sh, tail, writeState } from "./base.ts";
|
|
9
|
+
import { featDir, gateCwd, mergeBase, releaseTags, sh, tail, writeState } from "./base.ts";
|
|
10
10
|
|
|
11
11
|
/** How long the gate waits on a PR's CI; a seam so tests run in milliseconds (same shape as artifactWait). */
|
|
12
12
|
export const publishWait = {
|
|
@@ -96,6 +96,25 @@ export async function gatePublishes(cfg: Config, forgeName: string, root: string
|
|
|
96
96
|
return (await sh("gh --version", root, 15_000)).ok;
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
+
/** gh#240: the repo's own pull-request template, when it has one (GitHub's single-file locations). */
|
|
100
|
+
export function prTemplate(cwd: string): string | null {
|
|
101
|
+
for (const rel of [".github/pull_request_template.md", ".github/PULL_REQUEST_TEMPLATE.md", "pull_request_template.md", "PULL_REQUEST_TEMPLATE.md", "docs/pull_request_template.md", "docs/PULL_REQUEST_TEMPLATE.md"])
|
|
102
|
+
if (existsSync(path.join(cwd, rel))) return rel;
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** The PR body the agent authored for the gate to open the PR with (gh#240). */
|
|
107
|
+
export const prBodyFile = (root: string, slug: string) => path.join(featDir(root, slug), "pr-body.md");
|
|
108
|
+
|
|
109
|
+
/** gh#240: a repo with a PR template keeps its gate list there — what changed, who verified it, over which
|
|
110
|
+
* commit. Synthesizing the body from the changelog dropped all of it, and the merged PR had to be patched
|
|
111
|
+
* afterwards. With a template and no authored body the gate refuses before the PR exists; null when fine. */
|
|
112
|
+
export function prBodyOwed(root: string, state: FlowState): string | null {
|
|
113
|
+
const tpl = prTemplate(gateCwd(root, state));
|
|
114
|
+
if (!tpl || existsSync(prBodyFile(root, state.slug))) return null;
|
|
115
|
+
return `this repo has a pull-request template (${tpl}) and no PR body is written — flow release opens the PR itself, and a body synthesized from the changelog drops the template's sections. Write .dev-flow/${state.slug}/pr-body.md from ${tpl} (every section filled; the changelog entry, and the commit the operator's Verified? was given over), then re-run`;
|
|
116
|
+
}
|
|
117
|
+
|
|
99
118
|
async function prsFor(branch: string, cwd: string): Promise<Pr[] | null> {
|
|
100
119
|
const r = await sh(`gh pr list --head ${sq(branch)} --state all --limit 20 --json number,state,url,headRefOid,mergeCommit`, cwd, 60_000);
|
|
101
120
|
return r.ok ? jsonArray<Pr>(r.out) ?? (r.out.trim() ? null : []) : null;
|
|
@@ -113,8 +132,11 @@ async function prTitle(cwd: string, cfg: Config, slug: string): Promise<string>
|
|
|
113
132
|
return rows[0]?.[1] ?? slug;
|
|
114
133
|
}
|
|
115
134
|
|
|
116
|
-
/** Body for the PR: the
|
|
117
|
-
|
|
135
|
+
/** Body for the PR: the authored .dev-flow/<slug>/pr-body.md (gh#240), else the changelog entry of the version
|
|
136
|
+
* being released, else the branch's commit subjects. */
|
|
137
|
+
async function prBody(root: string, cwd: string, cfg: Config, state: FlowState): Promise<string> {
|
|
138
|
+
const authored = prBodyFile(root, state.slug);
|
|
139
|
+
if (existsSync(authored)) return readFileSync(authored, "utf8").trim();
|
|
118
140
|
const file = cfg.release.changelog ? path.join(cwd, cfg.release.changelog) : "";
|
|
119
141
|
const entry = pickReleaseNotes({ changelog: file && existsSync(file) ? readFileSync(file, "utf8") : null, version: state.releaseVersion ?? null, annotation: "" }).notes;
|
|
120
142
|
if (entry) return entry;
|
|
@@ -157,13 +179,16 @@ export async function publishRelease(root: string, state: FlowState, cfg: Config
|
|
|
157
179
|
let pr = found.open;
|
|
158
180
|
if (pr) steps.push(`PR #${pr.number} already open`);
|
|
159
181
|
else {
|
|
160
|
-
const
|
|
182
|
+
const owed = prBodyOwed(root, state);
|
|
183
|
+
if (owed) return stop(owed, `write .dev-flow/${state.slug}/pr-body.md`);
|
|
184
|
+
const authored = existsSync(prBodyFile(root, state.slug));
|
|
185
|
+
const body = await prBody(root, wt, cfg, state);
|
|
161
186
|
const create = await sh(`gh pr create --head ${sq(br)} --base ${sq(cfg.defaultBranch)} --title ${sq(await prTitle(wt, cfg, state.slug))} --body ${sq(body || state.slug)}`, wt);
|
|
162
187
|
if (!create.ok) return stop(`opening the PR failed:\n${tail(create.out, 8)}`, "open the PR yourself");
|
|
163
188
|
found = await find();
|
|
164
189
|
pr = found?.open;
|
|
165
190
|
if (!pr) return stop("the PR was created but gh pr list does not show it yet", "wait a moment");
|
|
166
|
-
steps.push(`PR #${pr.number} opened`);
|
|
191
|
+
steps.push(`PR #${pr.number} opened (body: ${authored ? "your pr-body.md" : "the changelog entry"})`);
|
|
167
192
|
}
|
|
168
193
|
state.publish = { ...state.publish, pr: pr.number };
|
|
169
194
|
writeState(root, state);
|
package/src/runtime/ship.ts
CHANGED
|
@@ -1,13 +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, prepFiles, 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, reviewOwed, localDefaultAhead, failTail } 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
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
|
+
import { gatePublishes, prBodyOwed, publishRelease } from "./publish.ts";
|
|
11
11
|
|
|
12
12
|
/** gh#198: the version question asked with Verified? — null when it is not the operator's to answer here
|
|
13
13
|
* (no manifest to version, the playbook decides, or an earlier Verified? already recorded the call). */
|
|
@@ -48,6 +48,14 @@ export async function gateVerify(o: GateCtx): Promise<RunResult> {
|
|
|
48
48
|
// tier-1 gate first (tier-2 confirmation is recorded by this very command, so it is excluded here)
|
|
49
49
|
const preGate = verifyGate({ ...state!, confirmations: { ...state!.confirmations, implement: { hash: checklistHash(items), at: now() } } }, cfg, branch);
|
|
50
50
|
if (preGate.length) return { text: `verify gate FAILED:\n- ${preGate.join("\n- ")}\n${branchLine}`, isError: true };
|
|
51
|
+
// The review runs before the operator is asked Verified?, not after it: reviewed in pre-release, every
|
|
52
|
+
// finding the review turned up changed the tree the operator had already said yes to, and Verified? was
|
|
53
|
+
// asked again — three times in one flow. Reviewed first, the operator's one look covers the tree that ships.
|
|
54
|
+
// A re-verify at pre-release and a release-only cut (nothing on the branch to read) owe none here.
|
|
55
|
+
if (state!.stage === "implement" && !isReleaseOnly(cfg, branch)) {
|
|
56
|
+
const owed = reviewOwed(state!, cfg);
|
|
57
|
+
if (owed) return { text: `verify gate FAILED:\n- the review comes before Verified?, so the operator's word covers the reviewed tree and review fixes never re-ask it — ${owed}\n${branchLine}`, isError: true };
|
|
58
|
+
}
|
|
51
59
|
// a stack another flow is reviewing or releasing on is not this gate's to take — ask before deploying
|
|
52
60
|
const slotted = cfg.commands.dev && !state!.docs ? await devSlotCheck(o, state!) : { note: "" };
|
|
53
61
|
if ("text" in slotted) return slotted;
|
|
@@ -88,7 +96,7 @@ export async function gateVerify(o: GateCtx): Promise<RunResult> {
|
|
|
88
96
|
const res = await sh(cfg.commands.build, gateCwd(root, state!), undefined, devEnv(root, state!, cfg));
|
|
89
97
|
state!.checks.build = { ok: res.ok, at: now() };
|
|
90
98
|
writeState(root, state!);
|
|
91
|
-
if (!res.ok) return { text: `build FAILED (${cfg.commands.build}):\n${
|
|
99
|
+
if (!res.ok) return { text: `build FAILED (${cfg.commands.build}):\n${failTail(res.out)}`, isError: true };
|
|
92
100
|
did.push(`build ran (${cfg.commands.build})`);
|
|
93
101
|
}
|
|
94
102
|
// deploy to dev before asking — the operator reviews the running dev app, not a promise
|
|
@@ -151,18 +159,24 @@ export async function gateVerify(o: GateCtx): Promise<RunResult> {
|
|
|
151
159
|
const fpDeployed = state!.docs ? null : await worktreeFingerprint(gateCwd(root, state!));
|
|
152
160
|
if (fpDeployed) state!.reviewDeploy = { wt: fpDeployed, slot: slotKey(devPortOf(state!, cfg)), at: now() };
|
|
153
161
|
else delete state!.reviewDeploy;
|
|
162
|
+
// a re-verify the gate asked for holds the release until it is answered: the operator's "verified" in chat
|
|
163
|
+
// reached the agent once, which went on to release prep and never recorded it, and the release shipped
|
|
164
|
+
// under the older word with a warning nobody acted on
|
|
165
|
+
if (reverify) state!.reverifyAsked = now();
|
|
154
166
|
markPendingAsk(root, state!, "Verified?"); // pending however it is asked — a chat question or a dialog
|
|
155
167
|
// the agent's call never opens a dialog (#181): this is the review deploy — the app is up for the
|
|
156
168
|
// operator, and the answer comes back in chat as flow verify --confirmed
|
|
157
169
|
if (!ui.hasUI) {
|
|
158
170
|
const port = devPortOf(state!, cfg);
|
|
159
|
-
|
|
171
|
+
// gh#229: say what actually ran — with no dev deploy and no health probe nothing was deployed or probed
|
|
172
|
+
const what = state!.docs ? "ready for review" : cfg.commands.dev ? `deployed for review${port !== undefined ? ` on port ${port}` : ""}` : healthProbe(cfg) ? "live app re-probed for review" : "ready for review — no dev deploy or health probe is configured, so nothing was deployed or probed: the operator checks the change as it runs for them";
|
|
160
173
|
const vq = versionQuestion(root, state!, cfg);
|
|
161
174
|
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}` };
|
|
162
175
|
}
|
|
163
176
|
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?`);
|
|
164
177
|
if (!ok) {
|
|
165
178
|
delete state!.pendingAsk;
|
|
179
|
+
delete state!.reverifyAsked;
|
|
166
180
|
writeState(root, state!);
|
|
167
181
|
return { text: `verification declined — stay in ${reverify ? "pre-release" : "implement"} and fix what failed` };
|
|
168
182
|
}
|
|
@@ -194,6 +208,7 @@ export async function gateVerify(o: GateCtx): Promise<RunResult> {
|
|
|
194
208
|
const before = state!.stage;
|
|
195
209
|
state!.stage = "pre-release";
|
|
196
210
|
delete state!.pendingAsk;
|
|
211
|
+
delete state!.reverifyAsked;
|
|
197
212
|
writeState(root, state!);
|
|
198
213
|
if (before === "pre-release")
|
|
199
214
|
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)}` };
|
|
@@ -244,6 +259,15 @@ export async function gateRelease(o: GateCtx): Promise<RunResult> {
|
|
|
244
259
|
const n = dirtyWt.out.split("\n").filter((l) => l.trim()).length;
|
|
245
260
|
return { text: `release gate FAILED:\n- ${n} uncommitted path(s) in ${state!.worktree} — a merge ships the branch, not your working tree: commit or discard them, then re-run\n${tail(dirtyWt.out)}`, isError: true };
|
|
246
261
|
}
|
|
262
|
+
// a re-verify flow verify asked for and nobody recorded: the release would ship under the older Verified?
|
|
263
|
+
if (state!.reverifyAsked)
|
|
264
|
+
return { text: `release gate FAILED:\n- flow verify asked the operator Verified? over the review fixes (${ago(state!.reverifyAsked)}) and no answer is recorded — once they answer in chat, run flow verify --confirmed (an unchanged tree is not deployed again); if they said no, fix it and run flow verify again`, isError: true };
|
|
265
|
+
// gh#233: the review step ran (or the operator waived it) before anything slow or anything ships
|
|
266
|
+
const noReview = reviewOwed(state!, cfg);
|
|
267
|
+
if (noReview) return { text: `release gate FAILED:\n- ${noReview}`, isError: true };
|
|
268
|
+
// gh#240: the PR body the template asks for exists before Release? is asked — the gate opens and merges the PR
|
|
269
|
+
const noBody = prBodyOwed(root, state!);
|
|
270
|
+
if (noBody && (await gatePublishes(cfg, forgeOf(cfg, await originUrl(root)), root))) return { text: `release gate FAILED:\n- ${noBody}`, isError: true };
|
|
247
271
|
const branchProof = await branchState(wtCwd, cfg.defaultBranch);
|
|
248
272
|
const manifestVer = cfg.versioning.file && existsSync(path.join(wtCwd, cfg.versioning.file))
|
|
249
273
|
? parseVersion(cfg.versioning.file, readFileSync(path.join(wtCwd, cfg.versioning.file), "utf8"))
|
|
@@ -292,7 +316,11 @@ export async function gateRelease(o: GateCtx): Promise<RunResult> {
|
|
|
292
316
|
// — except across a commit that is nothing but release prep: those greens are carried onto the current tree
|
|
293
317
|
const fpRelease = await worktreeFingerprint(wtCwd);
|
|
294
318
|
const keptThroughPrep = await keepThroughPrep(root, state!, cfg, fpRelease);
|
|
295
|
-
|
|
319
|
+
// gh#231: remember why each owed check is owed — the result names it instead of reading like skipped work
|
|
320
|
+
const failedBefore = new Set(Object.entries(state!.checks).filter(([, r]) => !r.ok).map(([n]) => n));
|
|
321
|
+
const staleNow = new Set(freshenChecks(state!, fpRelease));
|
|
322
|
+
if (staleNow.size || keptThroughPrep.length) writeState(root, state!);
|
|
323
|
+
const owedWhy = (n: string) => (staleNow.has(n) ? "the tree changed since it passed" : failedBefore.has(n) ? "its last run failed" : "no run on record");
|
|
296
324
|
// gh#198: the branch must carry the call the operator made — a bump they did not choose, or a bump on a flow
|
|
297
325
|
// they said merges unreleased, is prep that contradicts the word Release? would stand on. It runs before the
|
|
298
326
|
// generic proofs: when a parallel flow released first, "already tagged" alone would send the agent round a loop.
|
|
@@ -333,8 +361,9 @@ export async function gateRelease(o: GateCtx): Promise<RunResult> {
|
|
|
333
361
|
let checksNote = carried.length ? ` Checks kept (${carried.join(", ")}): only release prep was committed since they passed.` : "";
|
|
334
362
|
if (owed.length) {
|
|
335
363
|
const ran = await runChecks(root, state!, cfg, owed);
|
|
336
|
-
|
|
337
|
-
|
|
364
|
+
const why = owed.map((c) => `${c.name}: ${owedWhy(c.name)}`).join("; ");
|
|
365
|
+
if (ran.failed) return { text: `release gate FAILED — a check run at the gate failed (run because ${why}):\n${ran.lines.join("\n")}`, isError: true };
|
|
366
|
+
checksNote += ` Checks ran at the gate (${why}).`;
|
|
338
367
|
}
|
|
339
368
|
const preGate = preReleaseGate(gateState(state!.checks), cfg, prep);
|
|
340
369
|
if (preGate.length) return { text: `release gate FAILED:\n- ${preGate.join("\n- ")}`, isError: true };
|
|
@@ -411,7 +440,13 @@ export async function gateRelease(o: GateCtx): Promise<RunResult> {
|
|
|
411
440
|
: stale
|
|
412
441
|
? "a yolo given earlier does not choose to release under an older dev-flow build — ask Release? with the update-or-proceed question"
|
|
413
442
|
: "";
|
|
414
|
-
|
|
443
|
+
// gh#206: a yolo held back only by the playbook's until-release knob carries nothing new for the operator
|
|
444
|
+
// to weigh — it just means "Release? is asked like on any flow". Their chat answer (a plain --confirmed)
|
|
445
|
+
// stands on the first call, as it does on a flow without yolo; asking first made them repeat a word already
|
|
446
|
+
// given. gh#219's shape — `--yolo --confirmed` replayed from the plan-stage word — still gets the question.
|
|
447
|
+
// Commits after Verified? and a stale build carry news, so those holds always ask first.
|
|
448
|
+
const untilReleaseOnly = cfg.release.yolo === "until-release" && !postVerify && !stale;
|
|
449
|
+
const mustAskFirst = (!!holdWhy && !(untilReleaseOnly && !flag("yolo"))) || stale;
|
|
415
450
|
const confirmed = flag("confirmed") && !(mustAskFirst && !ui.hasUI && state!.pendingAsk !== "Release?");
|
|
416
451
|
const yoloHeld = confirmed ? "" : holdWhy;
|
|
417
452
|
// gh#198: release.ask = on-change — Release? answers itself when it would only re-confirm Verified?: the call
|
|
@@ -597,7 +632,7 @@ export async function gateReleaseDone(o: GateCtx): Promise<RunResult> {
|
|
|
597
632
|
// ancestry proves "not squashed, not rebased"; a squash and a rebase look identical here, so when it
|
|
598
633
|
// fails the forge itself is asked which one it was (gh/glab; self-hosted stays an advisory)
|
|
599
634
|
const ancestor = refsOk ? (await sh(`git merge-base --is-ancestor origin/${sq(br)} origin/${sq(cfg.defaultBranch)}`, root)).ok : null;
|
|
600
|
-
const proof = mergeShapeProof(cfg.release.merge, { ancestor, forgeStyle: ancestor === false ? await forgeMergeStyle(gateCwd(root, state!), forgeName, br) : null, branch: br, defaultBranch: cfg.defaultBranch });
|
|
635
|
+
const proof = mergeShapeProof(cfg.release.merge, { ancestor, forgeStyle: ancestor === false ? await forgeMergeStyle(gateCwd(root, state!), forgeName, br) : null, forgeAsked: forgeName === "github" || forgeName === "gitlab", branch: br, defaultBranch: cfg.defaultBranch });
|
|
601
636
|
if (proof.errors.length) errs.push(...proof.errors);
|
|
602
637
|
else mergeNote = proof.note;
|
|
603
638
|
}
|
|
@@ -731,24 +766,37 @@ export async function gateFinishCore(o: GateCtx): Promise<RunResult> {
|
|
|
731
766
|
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 };
|
|
732
767
|
const origin = await originUrl(root);
|
|
733
768
|
const hasOriginF = origin !== null;
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
769
|
+
// gh#234/gh#228: judge the local default branch, not whatever HEAD the main checkout happens to be on, and
|
|
770
|
+
// name what is local-only — playbook tracking is a note, anything else must reach origin first
|
|
771
|
+
const checkoutBranch = await currentBranch(root);
|
|
772
|
+
const localDef = `refs/heads/${cfg.defaultBranch}`;
|
|
773
|
+
let aheadNote = "";
|
|
774
|
+
if (hasOriginF && (await sh(`git rev-parse --verify -q ${sq(localDef)}`, root)).ok) {
|
|
775
|
+
const log = await sh(`git log --no-decorate --name-only --format=%x1e%h%x20%s ${sq(`origin/${cfg.defaultBranch}`)}..${sq(localDef)}`, root);
|
|
776
|
+
if (log.ok) {
|
|
777
|
+
const commits = log.out.split("\x1e").map((r) => r.split("\n").map((l) => l.trim()).filter(Boolean)).filter((r) => r.length).map(([line, ...files]) => ({ line, files }));
|
|
778
|
+
const ahead = localDefaultAhead({ defaultBranch: cfg.defaultBranch, checkoutBranch, commits });
|
|
779
|
+
if (ahead?.block) return { text: ahead.block, isError: true };
|
|
780
|
+
aheadNote = ahead?.note ?? "";
|
|
781
|
+
}
|
|
737
782
|
}
|
|
738
783
|
// close-out also syncs the main checkout: a released flow must never leave local
|
|
739
784
|
// <default> trailing origin — the push check above proved nothing local-only remains, so a
|
|
740
785
|
// differing sha means local trails and the fast-forward is safe. never a merge: a diverged
|
|
741
786
|
// or not-checked-out main prints the operator's exact command instead of touching anything
|
|
742
|
-
let syncNote =
|
|
743
|
-
if (hasOriginF) {
|
|
744
|
-
const
|
|
787
|
+
let syncNote = aheadNote;
|
|
788
|
+
if (hasOriginF && !aheadNote) {
|
|
789
|
+
const localSha = await sh(`git rev-parse --verify -q ${sq(localDef)}`, root);
|
|
745
790
|
const originSha = await sh(`git rev-parse ${sq(`origin/${cfg.defaultBranch}`)}`, root);
|
|
746
|
-
if (
|
|
747
|
-
const onDefault =
|
|
748
|
-
|
|
791
|
+
if (localSha.ok && originSha.ok && localSha.out.trim() !== originSha.out.trim()) {
|
|
792
|
+
const onDefault = checkoutBranch === cfg.defaultBranch;
|
|
793
|
+
// off the default branch, the local ref moves without touching the checkout: fetch into it fast-forward-only
|
|
794
|
+
const ff = onDefault
|
|
795
|
+
? await sh(`git merge --ff-only ${sq(`origin/${cfg.defaultBranch}`)}`, root)
|
|
796
|
+
: await sh(`git fetch -q . ${sq(`refs/remotes/origin/${cfg.defaultBranch}:${localDef}`)}`, root);
|
|
749
797
|
syncNote = ff.ok
|
|
750
|
-
? ` local ${cfg.defaultBranch} fast-forwarded to origin/${cfg.defaultBranch}.`
|
|
751
|
-
: ` local ${cfg.defaultBranch} trails origin/${cfg.defaultBranch} and did not fast-forward cleanly — sync by hand: git -C ${sq(root)} pull --ff-only`;
|
|
798
|
+
? ` local ${cfg.defaultBranch} fast-forwarded to origin/${cfg.defaultBranch}${onDefault ? "" : ` (the main checkout stays on ${checkoutBranch})`}.`
|
|
799
|
+
: ` local ${cfg.defaultBranch} trails origin/${cfg.defaultBranch} and did not fast-forward cleanly — sync by hand: git -C ${sq(root)} ${onDefault ? "pull --ff-only" : `fetch . origin/${cfg.defaultBranch}:${cfg.defaultBranch}`}`;
|
|
752
800
|
}
|
|
753
801
|
}
|
|
754
802
|
// After-merge checks (flow-check blocks under ## release): run from the main checkout, which now holds the
|