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/core.ts
CHANGED
|
@@ -53,6 +53,8 @@ export interface FlowState {
|
|
|
53
53
|
forgeReleaseSkipped?: string; // a gh/glab release create that failed: release-done says so, finish names it so the missing forge release cannot slip past (#63)
|
|
54
54
|
staleBuild?: string; // release ran under an older dev-flow than the checkout by operator choice ("<loaded> (checkout <disk>)"); release-done repeats the acknowledgement
|
|
55
55
|
pendingAsk?: string; // the checkpoint word a gate asked for and has not been given ("Approve?", "Verified?", …) — presentation only (💬 in the footer), it never gates
|
|
56
|
+
/** when flow verify at pre-release asked Verified? over review fixes; cleared by the answer — flow release refuses while it is set */
|
|
57
|
+
reverifyAsked?: string;
|
|
56
58
|
releaseOnly?: boolean; // verify found nothing on the branch but unreleased work on main: this flow only cuts the version (#161)
|
|
57
59
|
versionChoice?: string; // the operator's release call, recorded with Verified? (gh#198): patch | minor | major (counted from the newest tag at release, so a parallel flow taking the number moves it), an exact version, "next" (playbook version = versioned: any bump past the last tag) or "unreleased"
|
|
58
60
|
versionFrom?: string; // the manifest version when the call was recorded — what a patch/minor/major call was counted from at Verified?
|
|
@@ -62,9 +64,19 @@ export interface FlowState {
|
|
|
62
64
|
friction?: number; // process refusals, a gate refusing twice in a row, guard blocks and post-Verified? code changes this feature hit (isFriction; a red check alone is not one) — finish skips the closing reflection at 0 (playbook reflect = on-friction)
|
|
63
65
|
reflectQuiet?: boolean; // finish skipped the closing reflection because the flow had no friction — with nothing else open, Finish? answers itself (release.finish = on-change)
|
|
64
66
|
reviewDeploy?: { wt: string; slot: string; at: string }; // the tree (checkFingerprint) and dev slot `flow verify` deployed for the operator's review — a --confirmed over the same tree does not build and deploy it a second time
|
|
67
|
+
review?: FlowReview; // the review step ran (worker or inline) or the operator skipped it — flow verify (before Verified?) and flow release refuse without one (gh#233)
|
|
65
68
|
aborted?: string; // flow abort on a feature whose worktree exists: the state is a deliberate abandoned-feature record (gh#138) — the doctor's git-consistency sweep must never flag its hand-removed worktree as drift
|
|
66
69
|
}
|
|
67
70
|
|
|
71
|
+
/** A recorded review (run in implement, before Verified?): `worker` (a flow_stage review worker reported), `inline` (the agent ran the
|
|
72
|
+
* playbook's review step and recorded it with `flow review done`), or `skipped` (the operator's word). */
|
|
73
|
+
export interface FlowReview {
|
|
74
|
+
by: "worker" | "inline" | "skipped";
|
|
75
|
+
at: string;
|
|
76
|
+
head?: string; // the worktree HEAD the review read — release names commits after it
|
|
77
|
+
verdict?: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
68
80
|
/** Tier-2 item: operator prose; uiOnly items ("(ui)" in project.md) apply only to --ui features;
|
|
69
81
|
* versionedOnly items ("(versioned)") presuppose a bump/tag and stand down on a --no-version flow (#166);
|
|
70
82
|
* docs items ("(docs)") keep an implement item on a --docs flow, where implement items otherwise stand down (gh#207). */
|
|
@@ -568,6 +580,14 @@ export function versionArg(value: string | null, noVersion: boolean): { choice:
|
|
|
568
580
|
* under Unreleased. The git-dependent proofs (touched, folded) skip with an advisory when no base
|
|
569
581
|
* resolves; the content proofs always run (#97). Review/docs quality stays tier-2.
|
|
570
582
|
*/
|
|
583
|
+
/** gh#233: the playbook's review step is a release prerequisite, not a hint — a 566-line change shipped with
|
|
584
|
+
* no review because nothing recorded whether one ran. A docs flow and a release-only cut (nothing on the
|
|
585
|
+
* branch to read) owe none; `release.review = ""` opts the project out. Null when nothing is owed. */
|
|
586
|
+
export function reviewOwed(state: FlowState, cfg: Config): string | null {
|
|
587
|
+
if (!cfg.release.review || state.docs || state.releaseOnly || state.review) return null;
|
|
588
|
+
return `no review is recorded for this flow — run the playbook's review step (${cfg.release.review}, or flow_stage op "review"), fix what it finds, then record it: flow review done "<verdict in a line>" (a review worker records itself). To ship without a review, ask the operator; on their word: flow review --skip --confirmed`;
|
|
589
|
+
}
|
|
590
|
+
|
|
571
591
|
export function preReleaseGate(state: FlowState, cfg: Config, prep: ReleasePrep): string[] {
|
|
572
592
|
const errs: string[] = [];
|
|
573
593
|
if (state.stage !== "pre-release") errs.push(`stage is "${state.stage}", the release gate only applies to "pre-release"`);
|
|
@@ -582,7 +602,7 @@ export function preReleaseGate(state: FlowState, cfg: Config, prep: ReleasePrep)
|
|
|
582
602
|
// A --docs flow does not (#163): it changes the playbook/docs, which many projects keep out of a
|
|
583
603
|
// user-facing changelog — an entry it writes is still welcome, just not proven.
|
|
584
604
|
if (cfg.release.changelog && !state.docs) {
|
|
585
|
-
if (!prep.changelog) errs.push(`release.changelog "${cfg.release.changelog}" does not exist — an unversioned release must record its entry there (under Unreleased)`);
|
|
605
|
+
if (!prep.changelog) errs.push(`release.changelog "${cfg.release.changelog}" does not exist — an unversioned release must record its entry there (under Unreleased), or set changelog = "" under ## release if this project keeps none`);
|
|
586
606
|
else {
|
|
587
607
|
if (prep.changelogChanged === false) errs.push(`${prep.changelog.file} is unchanged on this branch — an unversioned release must add its entry (under Unreleased)`);
|
|
588
608
|
// an unversioned release must leave a trail someone can find later: the section is where it lives,
|
|
@@ -607,7 +627,7 @@ export function preReleaseGate(state: FlowState, cfg: Config, prep: ReleasePrep)
|
|
|
607
627
|
errs.push(`version ${prep.manifestVersion} is already tagged — bump the manifest to the next version`);
|
|
608
628
|
}
|
|
609
629
|
if (cfg.release.changelog) {
|
|
610
|
-
if (!prep.changelog) errs.push(`release.changelog "${cfg.release.changelog}" does not exist — prepare the changelog`);
|
|
630
|
+
if (!prep.changelog) errs.push(`release.changelog "${cfg.release.changelog}" does not exist — prepare the changelog (a project that keeps none: set changelog = "" under ## release)`);
|
|
611
631
|
else {
|
|
612
632
|
const entry = prep.manifestVersion ? changelogEntry(prep.changelog.content, prep.manifestVersion) : "";
|
|
613
633
|
if (prep.manifestVersion && !entry)
|
|
@@ -922,6 +942,8 @@ export interface MergeShapeFacts {
|
|
|
922
942
|
ancestor: boolean | null;
|
|
923
943
|
/** What the forge says landed the PR, when `gh`/`glab` could answer — the only way to tell a squash from a rebase. */
|
|
924
944
|
forgeStyle?: MergeStyle | null;
|
|
945
|
+
/** Was a forge CLI (gh/glab) there to ask? false on a self-hosted forge: a null forgeStyle then means "unknown", not "no merged PR". */
|
|
946
|
+
forgeAsked?: boolean;
|
|
925
947
|
/** Wording only. */
|
|
926
948
|
branch?: string;
|
|
927
949
|
defaultBranch?: string;
|
|
@@ -941,7 +963,13 @@ export function mergeShapeProof(policy: MergeStyle | "any" | undefined, facts: M
|
|
|
941
963
|
if (facts.ancestor === null) return { errors, note: `merge = ${policy} could not be checked from here (no origin or ${br} is not fetched) — confirm the merge style by hand` };
|
|
942
964
|
const landed = facts.forgeStyle ?? null;
|
|
943
965
|
if (policy === "merge") {
|
|
944
|
-
|
|
966
|
+
// gh#237: "not an ancestor" is also what an unmerged PR and a stale origin/<default> look like — blame a
|
|
967
|
+
// squash only when the forge says one landed
|
|
968
|
+
if (!facts.ancestor && landed === "merge")
|
|
969
|
+
errors.push(`the forge reports ${br} merged as a merge commit, but it is not an ancestor of ${def} here — this clone's ${def} is behind the forge: git fetch origin, then re-run`);
|
|
970
|
+
else if (!facts.ancestor && !landed)
|
|
971
|
+
errors.push(`${br} is not an ancestor of ${def}, and the forge reports no merged PR for it — not merged yet, or merged moments ago and not fetched: let the merge finish, git fetch origin, then re-run${facts.forgeAsked === false ? " (no forge CLI answered here — a squash or rebase merge looks the same, and the playbook says merge = merge)" : ""}`);
|
|
972
|
+
else if (!facts.ancestor) errors.push(`the playbook says merge = merge, but ${br} is not an ancestor of ${def} — the PR was ${MERGE_PAST[landed!]}, which rewrites the branch's commits out of the release's ancestry`);
|
|
945
973
|
else if (landed && landed !== "merge") errors.push(`the forge reports a ${landed} merge, but the playbook says merge = merge`);
|
|
946
974
|
else return { errors, note: `merge shape matches the playbook: ${br} is an ancestor of ${def} (merge = merge)` };
|
|
947
975
|
} else {
|
|
@@ -1195,6 +1223,22 @@ export function playbookOnlyChange(porcelain: string): boolean {
|
|
|
1195
1223
|
return paths.length === 1 && PLAYBOOK_PATH.test(paths[0]);
|
|
1196
1224
|
}
|
|
1197
1225
|
|
|
1226
|
+
/** gh#234, gh#228: what `flow finish` says about commits on the local default branch that origin does not have.
|
|
1227
|
+
* `flow init --track` commits the playbook to local main and nothing ever pushes it, so "push the release"
|
|
1228
|
+
* sent the agent to merge origin into local main and push the default branch directly. Playbook-only commits
|
|
1229
|
+
* are setup, not an unpushed release: a note, never a block. Anything else is named, with the branch the
|
|
1230
|
+
* main checkout is actually on — "git push origin main" from a checkout on another branch pushes nothing
|
|
1231
|
+
* you meant. Null when nothing is local-only. */
|
|
1232
|
+
export function localDefaultAhead(o: { defaultBranch: string; checkoutBranch: string; commits: { line: string; files: string[] }[] }): { block: string | null; note: string } | null {
|
|
1233
|
+
const { defaultBranch: d, checkoutBranch: cur, commits } = o;
|
|
1234
|
+
if (!commits.length) return null;
|
|
1235
|
+
const list = `${commits.slice(0, 5).map((c) => c.line).join(" | ")}${commits.length > 5 ? ` …(${commits.length - 5} more)` : ""}`;
|
|
1236
|
+
const where = cur && cur !== d ? ` (the main checkout is on ${cur}, not ${d} — this is the local ${d} branch)` : "";
|
|
1237
|
+
if (commits.every((c) => c.files.length > 0 && c.files.every((f) => PLAYBOOK_PATH.test(f))))
|
|
1238
|
+
return { block: null, note: ` local ${d} carries ${commits.length} playbook commit(s) origin/${d} does not have (${list})${where} — playbook tracking from flow init --track; they reach origin through a docs flow, never a direct push to ${d}. To line local ${d} up with origin meanwhile: git -C <main checkout> rebase origin/${d} ${d}.` };
|
|
1239
|
+
return { block: `local ${d} has ${commits.length} commit(s) origin/${d} does not have${where}: ${list} — finish removes the flow state, so nothing may stay local-only. If these are release chores, push them (git push origin ${d}); if they are work that belongs in a flow, move them onto a branch and ship them through one; then re-run flow finish`, note: "" };
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1198
1242
|
/** The operator's authorisation for rewriting a branch that is already pushed — same contract as
|
|
1199
1243
|
* DEV_FLOW_ALLOW_MAIN: the guard prints it, the operator grants it, the agent types it. (#83) */
|
|
1200
1244
|
export const ALLOW_REWRITE = "DEV_FLOW_ALLOW_REWRITE=1";
|
|
@@ -1307,6 +1351,36 @@ export function checkoutInvocation(command: string): { target: string; creates:
|
|
|
1307
1351
|
return target ? { target: unquote(target), creates: false } : null;
|
|
1308
1352
|
}
|
|
1309
1353
|
|
|
1354
|
+
/** The branch a `git branch <name>` creates, or null (listing, deleting, renaming, copying and the query flags only read
|
|
1355
|
+
* or move what exists — a rename is still not new work). */
|
|
1356
|
+
export function branchCreateInvocation(command: string): string | null {
|
|
1357
|
+
const m = command.match(/\bgit\s+(?:-C\s+\S+\s+)?branch\b([^;|&\n]*)/);
|
|
1358
|
+
if (!m) return null;
|
|
1359
|
+
const tok = m[1].trim().split(/\s+/).filter(Boolean);
|
|
1360
|
+
if (tok.some((t) => /^(-d|-D|--delete|-m|-M|--move|-c|-C|--copy|-l|--list|-a|--all|-r|--remotes|-v|-vv|--verbose|--contains|--no-contains|--merged|--no-merged|--points-at|--show-current|--edit-description|-u|--set-upstream-to(=.*)?|--unset-upstream|--format(=.*)?|--sort(=.*)?)$/.test(t))) return null;
|
|
1361
|
+
const name = tok.find((t) => !t.startsWith("-"));
|
|
1362
|
+
return name ? unquote(name) : null;
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
/** gh#232: a feature worktree holds its feature and nothing else. After `flow release` recorded the release, an
|
|
1366
|
+
* agent cut a side branch in the same worktree, committed a redesign on it and merged it to production with no
|
|
1367
|
+
* plan, check, review or Verified? — every gate is keyed to the feature branch, so none of them saw it. Judged
|
|
1368
|
+
* per git segment that runs inside a feature worktree: new branches, commits or merges on any branch but the
|
|
1369
|
+
* feature's own, and commits once its release is recorded, are refused. Null when the segment may run. */
|
|
1370
|
+
export function worktreeWorkGuard(o: { subs: string[]; command: string; branch: string; home: { slug: string; branch: string; released: boolean; wt: string } }): string | null {
|
|
1371
|
+
const { subs, home } = o;
|
|
1372
|
+
const newFlow = `follow-up work is its own flow: flow start <new-slug> (--patch for a small fix) — it gets a worktree, plan, checks, review and Verified? of its own`;
|
|
1373
|
+
const created = subs.includes("branch") ? branchCreateInvocation(o.command) : null;
|
|
1374
|
+
if (created) return `a feature worktree stays on its own branch — not creating ${created} in ${home.wt}; ${newFlow}`;
|
|
1375
|
+
const writes = subs.includes("commit") || subs.includes("merge") || subs.includes("cherry-pick") || subs.includes("revert");
|
|
1376
|
+
if (!writes) return null;
|
|
1377
|
+
if (o.branch && home.branch && o.branch !== home.branch)
|
|
1378
|
+
return `${home.wt} is ${home.slug}'s worktree (branch ${home.branch}), but it is on ${o.branch} — work committed here skips every gate of ${home.slug}; switch back (git switch ${home.branch}) — ${newFlow}`;
|
|
1379
|
+
if (home.released)
|
|
1380
|
+
return `${home.slug}'s release is recorded — its worktree takes no new commits (they would never ship through a gate); ${newFlow}. Release chores belong in the main checkout; flow finish closes ${home.slug}`;
|
|
1381
|
+
return null;
|
|
1382
|
+
}
|
|
1383
|
+
|
|
1310
1384
|
// ------------------------------------------------------- project safety rules
|
|
1311
1385
|
|
|
1312
1386
|
/** One flow-guard rule: `pattern` is a JS regex source (deny/confirm) or a repo-relative path (protect/forbid). */
|
|
@@ -1568,6 +1642,17 @@ export function featureTmpDir(dfDir: string, slug: string): string {
|
|
|
1568
1642
|
return path.join(dfDir, slug, "tmp");
|
|
1569
1643
|
}
|
|
1570
1644
|
|
|
1645
|
+
/** gh#243: the per-flow scratch dir is a TMPDIR every tool writes into, and tooling that never removes its
|
|
1646
|
+
* `mktemp` dirs left ~1,000 of them after one flow. Which entries a gate may sweep: names shaped like mktemp
|
|
1647
|
+
* output (`tmp.XXXXXX`, `<prefix>.XXXXXX`, `<prefix>-XXXXXX` — a 6+ char random tail with a digit or mixed
|
|
1648
|
+
* case) untouched for `maxAgeMs`. A name the project chose (a dev server's cache dir) never matches, and
|
|
1649
|
+
* anything recent may still be in use. */
|
|
1650
|
+
export function staleScratch(entries: { name: string; mtimeMs: number }[], now: number, maxAgeMs = 3_600_000): string[] {
|
|
1651
|
+
const tail = /^(?:tmp|[\w-]+?)[.-]([A-Za-z0-9]{6,})$/;
|
|
1652
|
+
const randomish = (t: string) => /\d/.test(t) || (/[a-z]/.test(t) && /[A-Z]/.test(t));
|
|
1653
|
+
return entries.filter((e) => { const m = tail.exec(e.name); return !!m && randomish(m[1]) && now - e.mtimeMs > maxAgeMs; }).map((e) => e.name);
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1571
1656
|
/** The env every process of a bound feature gets: TMPDIR in the feature's scratch dir, and that dir as a
|
|
1572
1657
|
* git ceiling. The scratch dir sits inside the repo, so without the ceiling git walks up out of a
|
|
1573
1658
|
* test's mkdtemp fixture and answers with the enclosing checkout — a suite asserting "no repo here"
|
|
@@ -2168,45 +2253,57 @@ export function roadmapBriefFor(text: string, slug: string): { item: string; bri
|
|
|
2168
2253
|
/** Number of open roadmap items. */
|
|
2169
2254
|
export const roadmapOpenCount = (text: string) => openChecklistItems(text).length;
|
|
2170
2255
|
|
|
2171
|
-
/**
|
|
2172
|
-
*
|
|
2173
|
-
|
|
2174
|
-
|
|
2256
|
+
/** gh#245: roadmap numbers are row numbers over every item, open and done, the way reflections number
|
|
2257
|
+
* theirs (gh#197). Numbered over open items only, `done 6` shifted the old 7 into 6, so "close 6 and 7"
|
|
2258
|
+
* closed one item twice over and the wrong one went with it. A done item keeps its row, so closing one
|
|
2259
|
+
* leaves every other number where `list` printed it; drop and tidy remove rows and renumber. */
|
|
2260
|
+
const isRoadmapRow = (l: string) => isOpenItem(l) || isDoneItem(l);
|
|
2261
|
+
|
|
2262
|
+
/** The open items with their row numbers — what `flow roadmap` lists and pick/done/drop take. */
|
|
2263
|
+
export function roadmapOpenRows(text: string): { row: number; item: string }[] {
|
|
2264
|
+
let row = 0;
|
|
2265
|
+
const out: { row: number; item: string }[] = [];
|
|
2266
|
+
for (const l of text.split("\n")) {
|
|
2267
|
+
if (!isRoadmapRow(l)) continue;
|
|
2268
|
+
row++;
|
|
2269
|
+
if (isOpenItem(l)) out.push({ row, item: l.trim().slice(6) });
|
|
2270
|
+
}
|
|
2271
|
+
return out;
|
|
2272
|
+
}
|
|
2273
|
+
|
|
2274
|
+
/** Rewrite the open item at row n (rows count open and done items, 1-based); null when row n is no open item. */
|
|
2275
|
+
function editOpenRow(text: string, n: number, edit: (line: string) => string): string | null {
|
|
2276
|
+
let row = 0;
|
|
2175
2277
|
let hit = false;
|
|
2176
2278
|
const out = text.split("\n").map((l) => {
|
|
2177
|
-
if (!isOpenItem(l)) return l;
|
|
2178
|
-
++seen;
|
|
2179
|
-
if (seen !== n) return l;
|
|
2279
|
+
if (!isRoadmapRow(l) || ++row !== n || !isOpenItem(l)) return l;
|
|
2180
2280
|
hit = true;
|
|
2181
|
-
return
|
|
2281
|
+
return edit(l);
|
|
2182
2282
|
});
|
|
2183
2283
|
return hit ? out.join("\n") : null;
|
|
2184
2284
|
}
|
|
2185
2285
|
|
|
2186
|
-
/**
|
|
2286
|
+
/** Stamp the open item at row n with `(slug)` — the pick→finish handshake. Null when row n is no open item.
|
|
2287
|
+
* Re-picking the same slug is a no-op stamp. */
|
|
2288
|
+
export function roadmapPick(text: string, n: number, slug: string): string | null {
|
|
2289
|
+
return editOpenRow(text, n, (l) => (l.trim().includes(`(${slug})`) ? l.trim() : `${l.trim()} (${slug})`));
|
|
2290
|
+
}
|
|
2291
|
+
|
|
2292
|
+
/** Check the open item at row n with a done stamp. Null when row n is no open item. */
|
|
2187
2293
|
export function roadmapDone(text: string, n: number, stamp: string): string | null {
|
|
2188
|
-
|
|
2189
|
-
let hit = false;
|
|
2190
|
-
const out = text.split("\n").map((l) => {
|
|
2191
|
-
if (!isOpenItem(l)) return l;
|
|
2192
|
-
++seen;
|
|
2193
|
-
if (seen !== n) return l;
|
|
2194
|
-
hit = true;
|
|
2195
|
-
return stampItem(l, stamp);
|
|
2196
|
-
});
|
|
2197
|
-
return hit ? out.join("\n") : null;
|
|
2294
|
+
return editOpenRow(text, n, (l) => stampItem(l, stamp));
|
|
2198
2295
|
}
|
|
2199
2296
|
|
|
2200
|
-
/** Remove the
|
|
2201
|
-
*
|
|
2297
|
+
/** Remove the open item at row n and its brief — an idea the operator no longer wants, which `done` would
|
|
2298
|
+
* record as shipped. Null when row n is no open item. */
|
|
2202
2299
|
export function roadmapDrop(text: string, n: number): { text: string; item: string } | null {
|
|
2203
|
-
let
|
|
2300
|
+
let row = 0;
|
|
2204
2301
|
let item: string | null = null;
|
|
2205
2302
|
let dropping = false;
|
|
2206
2303
|
const out = text.split("\n").filter((l) => {
|
|
2207
2304
|
if (isBriefLine(l)) return !dropping;
|
|
2208
2305
|
dropping = false;
|
|
2209
|
-
if (!
|
|
2306
|
+
if (!isRoadmapRow(l) || ++row !== n || !isOpenItem(l)) return true;
|
|
2210
2307
|
item = l.trim().slice(6);
|
|
2211
2308
|
dropping = true;
|
|
2212
2309
|
return false;
|
|
@@ -2304,17 +2401,22 @@ export function nextHint(state: FlowState, cfg: Config): string {
|
|
|
2304
2401
|
const open = openItemsNote(cfg, state, "implement");
|
|
2305
2402
|
return `edit in ${state.worktree} (docs mode: no project commands)${open ? `, go through the checklist with the operator (${open})` : ""}, ask Verified?, then flow verify --confirmed`;
|
|
2306
2403
|
}
|
|
2307
|
-
|
|
2404
|
+
// the review comes before Verified? (flow verify refuses until it is on record), so the operator's one look covers the reviewed tree
|
|
2405
|
+
const rv = reviewOwed(state, cfg) ? `; then the review — ${cfg.release.review}, fix what it finds and record it (flow review done "<verdict>"; a flow_stage review worker records itself)` : "";
|
|
2406
|
+
return `build and test in ${state.worktree}, commit as you go, flow check${rv}; then flow verify (deploys for review), look yourself, keep the app running, ask Verified? and run flow verify --confirmed on the answer`;
|
|
2308
2407
|
case "pre-release": {
|
|
2309
2408
|
// gh#198: the release call made with Verified? decides which prep this is
|
|
2310
2409
|
const vc = state.versionChoice;
|
|
2410
|
+
// gh#233: flow release refuses until the review is on record — the hint says how it gets there
|
|
2411
|
+
const rv = reviewOwed(state, cfg) ? `${cfg.release.review} (then record it: flow review done "<verdict>")` : cfg.release.review && state.review ? "review on record" : "";
|
|
2412
|
+
const review = rv ? `${rv}, ` : "";
|
|
2311
2413
|
const auto = cfg.release.ask !== "always" ? " (release.ask = on-change: it asks Release? only when something beyond the prep changed)" : "";
|
|
2312
2414
|
if (vc === "unreleased")
|
|
2313
|
-
return `${
|
|
2415
|
+
return `${review}fix must/should${state.docs ? "" : " (a fix that changes behaviour: flow verify redeploys and re-asks Verified? over it)"}, update docs${cfg.release.changelog && !state.docs ? `, add this flow's line under Unreleased in ${cfg.release.changelog} (the call is merge unreleased: no bump)` : ""}; show the PR summary, then run flow release${auto || " and ask Release?"}`;
|
|
2314
2416
|
const prep = [cfg.release.changelog ? `prepare ${cfg.release.changelog} (fold Unreleased lines verbatim)` : "", cfg.versioning.file ? `bump version in ${cfg.versioning.file}${isBumpKind(vc) ? ` to ${bumpVersion(state.versionFrom, vc) ?? `the next ${vc}`} (a ${vc} release, the operator's call — the gate counts it from the newest tag, so a flow that released first moves the number)` : vc && vc !== "next" ? ` to ${vc} (the operator's call)` : ""}` : ""].filter(Boolean).join(" and ");
|
|
2315
|
-
if (vc && prep) return `${
|
|
2316
|
-
if (state.docs && prep) return `${
|
|
2317
|
-
return `${
|
|
2417
|
+
if (vc && prep) return `${review}fix must/should${state.docs ? "" : " (a fix that changes behaviour: flow verify redeploys and re-asks Verified? over it)"}, update docs, ${prep}; show the PR summary, version and changelog, then run flow release${auto || " and ask Release?"}`;
|
|
2418
|
+
if (state.docs && prep) return `${review}fix must/should; a docs flow usually ships unversioned — ask the operator (flow release --no-version on their word); versioned instead: ${prep}; then ask Release? and run flow release`;
|
|
2419
|
+
return `${review}fix must/should${state.docs ? "" : " (a fix that changes behaviour: flow verify redeploys and re-asks Verified? over it)"}, update docs${prep ? `, ${prep}` : ""}; show the PR summary, version and changelog, ask Release? and run flow release`;
|
|
2318
2420
|
}
|
|
2319
2421
|
case "release":
|
|
2320
2422
|
if (state.approvals.release) return `release recorded — commit and push any release chores in the main checkout (DEV_FLOW_ALLOW_MAIN=1 for the pre-commit hook), then flow finish (closing reflection first; its fold/drop answer is Finish?)`;
|
|
@@ -2323,6 +2425,41 @@ export function nextHint(state: FlowState, cfg: Config): string {
|
|
|
2323
2425
|
}
|
|
2324
2426
|
}
|
|
2325
2427
|
|
|
2428
|
+
/** gh#242: a failing check's output, trimmed for the gate result. The last lines alone pointed away from the
|
|
2429
|
+
* failure — a lint step's tail was its pre-existing warnings and "script exited with code 1", and the two files
|
|
2430
|
+
* it refused were 200 lines up. When the output is longer than the tail, the error-level lines that the tail
|
|
2431
|
+
* cuts off are lifted above it, each with the line before it (formatters name the file there), capped. */
|
|
2432
|
+
export function failTail(out: string, n = 15, maxErr = 12): string {
|
|
2433
|
+
const lines = out.split("\n").filter((l) => l.trim());
|
|
2434
|
+
if (lines.length <= n) return out;
|
|
2435
|
+
const cut = lines.length - n;
|
|
2436
|
+
const isErr = (l: string) => !/\bwarn(?:ing)?s?\b/i.test(l) && /(^|[\s[(:])(?:error|errors|ERR!|FAIL(?:ED|URE)?|fail(?:ed|ure)?|panic(?:ked)?|exception|Traceback)\b|[×✖✗]|^\s*E\s{2,}|AssertionError/i.test(l);
|
|
2437
|
+
const pick = new Set<number>();
|
|
2438
|
+
for (let i = 0; i < cut && pick.size < maxErr * 2; i++)
|
|
2439
|
+
if (isErr(lines[i])) {
|
|
2440
|
+
if (i > 0 && !isErr(lines[i - 1])) pick.add(i - 1);
|
|
2441
|
+
pick.add(i);
|
|
2442
|
+
}
|
|
2443
|
+
const clip = (l: string) => (l.length > 240 ? `${l.slice(0, 240)}…` : l);
|
|
2444
|
+
const head = [...pick].sort((a, b) => a - b).slice(0, maxErr * 2).map((i) => clip(lines[i]));
|
|
2445
|
+
return `${head.length ? `error lines from the ${cut} cut off:\n${head.join("\n")}\n…\n` : `…(${cut} lines)…\n`}${lines.slice(-n).join("\n")}`;
|
|
2446
|
+
}
|
|
2447
|
+
|
|
2448
|
+
/** gh#238: the flow tool's `args` must be an array of strings. A call whose array arrived marshalled as one JSON
|
|
2449
|
+
* string was dispatched with the whole blob as the subcommand, and the refusal ("unknown subcommand …" plus the
|
|
2450
|
+
* full usage) never said the shape was wrong. Null when the shape is fine. */
|
|
2451
|
+
export function flowArgsShapeError(args: unknown): string | null {
|
|
2452
|
+
if (!Array.isArray(args)) return `args must be an array of strings, e.g. ["status"] or ["start", "my-slug"] — this arrived as ${args === null ? "null" : typeof args}`;
|
|
2453
|
+
if (args.some((a) => typeof a !== "string")) return `args must be an array of strings — element(s) ${args.map((a, i) => (typeof a === "string" ? -1 : i)).filter((i) => i >= 0).join(", ")} are not strings`;
|
|
2454
|
+
if (args.length === 1 && /^\s*\[/.test(args[0] as string)) {
|
|
2455
|
+
let inner: unknown = null;
|
|
2456
|
+
try { inner = JSON.parse(args[0] as string); } catch { /* not JSON: still looks like a marshalled array */ }
|
|
2457
|
+
const shown = Array.isArray(inner) ? JSON.stringify(inner) : (args[0] as string).slice(0, 120);
|
|
2458
|
+
return `args must be an array of strings; this arrived as one string holding an array (${shown}) — pass the elements themselves: args: ${shown}`;
|
|
2459
|
+
}
|
|
2460
|
+
return null;
|
|
2461
|
+
}
|
|
2462
|
+
|
|
2326
2463
|
/** Stable token prefixing every no-UI operator refusal, so a headless orchestrator can route refusals without grepping prose. */
|
|
2327
2464
|
export const NEEDS_OPERATOR = "NEEDS-OPERATOR";
|
|
2328
2465
|
|
|
@@ -2491,6 +2628,7 @@ export function buildWorkerBrief(o: WorkerBriefInput): string {
|
|
|
2491
2628
|
? "- Project checks: none — this is a docs flow. The gates skip the project's commands and no setup ran in this worktree (no installed dependencies): do not install, build or run the test suite; check the docs against the code by reading."
|
|
2492
2629
|
: `- Project checks (run them before you report${o.preamble?.length ? ", in a shell that ran the setup below first" : ""}):\n${checks}`,
|
|
2493
2630
|
"- You hold no flow tool: gates, checkpoints and the operator stay with the driving session.",
|
|
2631
|
+
"- Scratch goes in $TMPDIR (the feature's tmp dir); remove what you create there — `d=$(mktemp -d) && …; rm -rf \"$d\"`.",
|
|
2494
2632
|
"",
|
|
2495
2633
|
...workerGuardLines(o.guard),
|
|
2496
2634
|
...(o.preamble?.length && !o.docs
|
|
@@ -2651,11 +2789,13 @@ export function digestTranscript(jsonl: string, opts: { maxChars?: number } = {}
|
|
|
2651
2789
|
const res = textOf(m.content);
|
|
2652
2790
|
if (m.isError) {
|
|
2653
2791
|
errors++;
|
|
2654
|
-
|
|
2792
|
+
// gh#239: a guard block reaches the transcript as an error result whose text is the guard's reason;
|
|
2793
|
+
// the operator-ask ones lead with the marker. A successful result is never a guard event, whatever
|
|
2794
|
+
// words its output quotes — matching NEEDS-OPERATOR anywhere in a success tagged a grep as a block.
|
|
2795
|
+
const guardAsk = name !== "flow" && name !== "flow_stage" && res.trimStart().startsWith(NEEDS_OPERATOR);
|
|
2796
|
+
out.push(`${L} ${guardAsk ? "GUARD" : "ERROR"} ${name}${call ? ` (call L${call.line}: ${clip(call.args, 160)})` : ""} → ${clip(res, 400)}`);
|
|
2655
2797
|
} else if (name === "flow" || name === "flow_stage") {
|
|
2656
2798
|
out.push(`${L} ↳ ${clip(res, name === "flow_stage" ? 600 : 400)}`);
|
|
2657
|
-
} else if (/NEEDS-OPERATOR/.test(res.slice(0, 600))) {
|
|
2658
|
-
out.push(`${L} GUARD ${name}${call ? ` (call L${call.line}: ${clip(call.args, 160)})` : ""} → ${clip(res, 300)}`);
|
|
2659
2799
|
}
|
|
2660
2800
|
}
|
|
2661
2801
|
}
|
package/src/present.ts
CHANGED
|
@@ -111,10 +111,13 @@ export function stageLine(state: FlowState, cfg: Config, f: StageFacts = {}): st
|
|
|
111
111
|
if (stage === "implement" || stage === "pre-release") {
|
|
112
112
|
if (f.ahead !== undefined) fields.push(`commits \`${f.ahead} ahead, ${f.uncommitted ?? 0} uncommitted\``);
|
|
113
113
|
if (!state.docs) fields.push(`checks ${checksSummary(state)}`);
|
|
114
|
-
const
|
|
114
|
+
const list = applicableItems(cfg, state, stage);
|
|
115
115
|
const pend = checklistPending(cfg, state, stage);
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
// gh#241: name them — a bare count made the agent re-read project.md, and implement's and pre-release's
|
|
117
|
+
// lists are different checklists, so the count "moved" with no explanation
|
|
118
|
+
const clip = (t: string) => (t.length > 40 ? `${t.slice(0, 39)}…` : t);
|
|
119
|
+
if (pend) fields.push(`tier-2 \`${pend} open\` ? (## ${stage}: ${list.slice(0, 4).map((i) => `"${clip(i.text)}"`).join(" · ")}${list.length > 4 ? ` +${list.length - 4}` : ""})`);
|
|
120
|
+
else if (list.length) fields.push("tier-2 `confirmed` ✓");
|
|
118
121
|
}
|
|
119
122
|
if (stage === "pre-release" || stage === "release") {
|
|
120
123
|
const version = state.noVersion ? "version `no-version` ✓" : state.releaseVersion ? `version \`${state.releaseVersion}\` ✓` : state.versionChoice && state.versionChoice !== "next" && state.versionChoice !== "unreleased" ? `version \`${state.versionChoice}\` ✓` : f.manifest ? `version \`${f.manifest}\` ~` : "version `pending` ?";
|
package/src/projectmd.ts
CHANGED
|
@@ -160,7 +160,10 @@ export function parseProjectMd(text: string): ParsedMd {
|
|
|
160
160
|
return;
|
|
161
161
|
}
|
|
162
162
|
if (inFence === "flow") {
|
|
163
|
-
|
|
163
|
+
// gh#226: an empty value is the opt-out (`changelog =`, `changelog = ""`) — `(.+?)` read `key = ` as " " and
|
|
164
|
+
// `""` as a literal, so a project could not say "no changelog" at all
|
|
165
|
+
const m0 = line.match(/^\s*([A-Za-z][\w.]*)\s*=\s*(.*?)\s*$/);
|
|
166
|
+
const m = m0 ? ([m0[0], m0[1], m0[2].replace(/^(["'])\1$/, "")] as const) : null;
|
|
164
167
|
if (!m || !stage) {
|
|
165
168
|
if (line.trim() && !line.trim().startsWith("#")) p.hard.push(`${where}: expected \`key = value\` inside flow block`);
|
|
166
169
|
} else if (!MD_STAGES.includes(stage as MdStage)) {
|
|
@@ -280,6 +283,17 @@ export function mdToConfig(p: ParsedMd): Config {
|
|
|
280
283
|
const rel = (nested as { release?: { releases?: unknown } }).release;
|
|
281
284
|
if (rel && typeof rel.releases === "string") rel.releases = !/^(no|false)$/i.test(rel.releases);
|
|
282
285
|
mergeInto(c, nested);
|
|
286
|
+
// gh#226: an empty value in the playbook is an explicit opt-out (`changelog =`), not "keep the default" —
|
|
287
|
+
// applyAnswer drops "" (that is the answers' meaning of unset), so the empties are set here, string keys only
|
|
288
|
+
for (const stage of MD_STAGES)
|
|
289
|
+
for (const [key, val] of Object.entries(p.flow[stage])) {
|
|
290
|
+
if (val !== "" || !key.includes(".")) continue; // a top-level key (defaultBranch, worktreeDir…) has no "none"
|
|
291
|
+
const segs = key.split(".");
|
|
292
|
+
const leaf = segs.pop()!;
|
|
293
|
+
let at: Record<string, unknown> | undefined = c as unknown as Record<string, unknown>;
|
|
294
|
+
for (const sg of segs) at = at && typeof at[sg] === "object" && at[sg] !== null ? (at[sg] as Record<string, unknown>) : undefined;
|
|
295
|
+
if (at && (at[leaf] === undefined || typeof at[leaf] === "string")) at[leaf] = "";
|
|
296
|
+
}
|
|
283
297
|
// a flow-guard block is the whole rule set; with none in project.md the DEFAULTS (empty) stand
|
|
284
298
|
if (GUARD_VERBS.some((v) => p.guard[v].length)) c.guard = structuredClone(p.guard);
|
|
285
299
|
// one check per name: an explicit flow-check block wins over the `test =` / `health =` shorthand
|
|
@@ -533,14 +547,34 @@ export function doctorFindings(root: string, cfg: Config, md: ParsedMd | null):
|
|
|
533
547
|
if (!existsSync(mf)) f.push(`versioning.file "${cfg.versioning.file}" does not exist`);
|
|
534
548
|
else if (!parseVersion(cfg.versioning.file, readFileSync(mf, "utf8"))) f.push(`versioning.file "${cfg.versioning.file}": no parsable version found`);
|
|
535
549
|
}
|
|
536
|
-
// drift: `npm|pnpm|yarn|bun run <script>` where the script no longer exists
|
|
537
|
-
|
|
538
|
-
const
|
|
539
|
-
|
|
550
|
+
// drift: `npm|pnpm|yarn|bun run <script>` where the script no longer exists — judged against the package.json
|
|
551
|
+
// the command actually runs in (gh#227): a leading `cd <dir> &&`, or npm --prefix / pnpm -C / yarn --cwd
|
|
552
|
+
const scriptsAt = new Map<string, Record<string, string> | null>();
|
|
553
|
+
const scriptsOf = (dir: string): Record<string, string> | null => {
|
|
554
|
+
if (!scriptsAt.has(dir)) {
|
|
555
|
+
const pj = path.join(root, dir, "package.json");
|
|
556
|
+
const raw = existsSync(pj) ? safeJson(readFileSync(pj, "utf8")) : null;
|
|
557
|
+
scriptsAt.set(dir, raw && typeof raw === "object" && typeof (raw as { scripts?: unknown }).scripts === "object" ? (raw as { scripts: Record<string, string> }).scripts : null);
|
|
558
|
+
}
|
|
559
|
+
return scriptsAt.get(dir)!;
|
|
560
|
+
};
|
|
540
561
|
const cmdList = [...Object.entries(cfg.commands).map(([k, v]) => [`commands.${k}`, v!] as [string, string]), ...cfg.checkList.map((c) => [`check ${c.name}`, c.cmd] as [string, string])];
|
|
541
562
|
for (const [label, cmd] of cmdList) {
|
|
542
|
-
|
|
543
|
-
|
|
563
|
+
let dir = ".";
|
|
564
|
+
for (const seg of cmd.split(/&&|;|\|\||\n/)) {
|
|
565
|
+
const cd = seg.match(/^\s*cd\s+(['"]?)([^'"\s]+)\1\s*$/);
|
|
566
|
+
if (cd) {
|
|
567
|
+
// only a relative cd is followable; an absolute or $VAR one leaves the package.json unknown
|
|
568
|
+
dir = /^[\w.][\w./-]*$/.test(cd[2]) ? path.join(dir, cd[2]) : "";
|
|
569
|
+
continue;
|
|
570
|
+
}
|
|
571
|
+
const run = seg.match(/\b(npm|pnpm|yarn|bun)\b(.*?)\s+run\s+([\w:.-]+)/);
|
|
572
|
+
if (!run || !dir) continue;
|
|
573
|
+
const pre = run[2].match(/(?:--prefix|-C|--cwd|--dir)[=\s]+(['"]?)([^'"\s]+)\1/);
|
|
574
|
+
const at = pre ? (/^[\w.][\w./-]*$/.test(pre[2]) ? path.join(dir, pre[2]) : "") : dir;
|
|
575
|
+
const scripts = at ? scriptsOf(at) : null;
|
|
576
|
+
if (scripts && !(run[3] in scripts)) f.push(`${label} runs "run ${run[3]}" but ${at === "." ? "" : `${at}/`}package.json has no such script`);
|
|
577
|
+
}
|
|
544
578
|
for (const tok of cmd.split(/\s+/)) {
|
|
545
579
|
// only root-relative paths are probeable — checks run in the worktree, where `../../docker/.env` is correct
|
|
546
580
|
if (/^[\w][\w-]*\/[\w./-]+$/.test(tok) && /\.\w+$/.test(tok) && !existsSync(path.join(root, tok))) {
|
package/src/runtime/base.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/** dev-flow runtime — Shared runtime: shell, paths, flow state, sessions and claims, skill core, compaction pacing. Moved out of extensions/dev-flow.ts as is (exports added). */
|
|
2
2
|
import { exec } from "node:child_process";
|
|
3
|
-
import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { promisify } from "node:util";
|
|
6
6
|
import { compact, SettingsManager, type ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
7
|
-
import { checklistPending, claimBlocks, classifyMergeHistory, cmpVersions, detectForge, extractSkillCore, featureBranchPrefix, healthRetry, parseMergeStyle, parseLsRemoteTags, pluginVersion, reflectItems, sessionRunsOlderBuild, listFiles, shouldSelfCompact, sq, featureTmpDir, featureTmpEnv, mainCheckoutRoot, type ReflectItem, type Config, type FeatureRef, type FlowState, type SessionClaim } from "../core.ts";
|
|
7
|
+
import { checklistPending, claimBlocks, classifyMergeHistory, cmpVersions, detectForge, extractSkillCore, featureBranchPrefix, healthRetry, parseMergeStyle, parseLsRemoteTags, pluginVersion, reflectItems, sessionRunsOlderBuild, listFiles, shouldSelfCompact, sq, featureTmpDir, featureTmpEnv, staleScratch, mainCheckoutRoot, type ReflectItem, type Config, type FeatureRef, type FlowState, type SessionClaim } from "../core.ts";
|
|
8
8
|
import { loadProject, parseProjectMd, setPlaybookKey } from "../projectmd.ts";
|
|
9
9
|
import { bashTimeout } from "../timeouts.ts";
|
|
10
10
|
import { type RunResult, type Session } from "./checks.ts";
|
|
@@ -236,7 +236,7 @@ export async function releaseTags(root: string): Promise<string[] | null> {
|
|
|
236
236
|
}
|
|
237
237
|
|
|
238
238
|
export const GATE_HELP =
|
|
239
|
-
"help [--json] | init [--force|--draft|--write <text>|--write-file <path>|--answers key=value…|--answers-file <path>] [--confirmed] [--track] | reflect [<note>|list|tidy|move <n> --playbook|--code|done <n>[,<n>…] [<what>]] | roadmap [add <text> [--slug=<slug>] [--brief=<notes>|--brief-file=<path>]|pick <n> <slug>|done <n
|
|
239
|
+
"help [--json] | init [--force|--draft|--write <text>|--write-file <path>|--answers key=value…|--answers-file <path>] [--confirmed] [--track] | reflect [<note>|list|tidy|move <n> --playbook|--code|done <n>[,<n>…] [<what>]] | roadmap [add <text> [--slug=<slug>] [--brief=<notes>|--brief-file=<path>]|pick <n> <slug>|done <n>[,<n>…]|drop <n>[,<n>…]|tidy] | doctor [<issue note>] | status [slug] [--json] | start <slug> [--ui|--patch|--docs] [--no-ui --confirmed] [--force] [--merge=squash|merge|rebase|any] [--check-upstream] | use <slug> | test | check | health | review [done <verdict>|--skip] | approve [--yolo] | verify [--yolo] [--port=<n>|--replace] [--version=<v>|--no-version] | release [--yolo|--version=<v>|--no-version|--no-fold-check|--no-marker-check] | finish [--yolo] [--no-reflect] [--note=<text>] [--no-artifact-check|--no-release-create] [slug] | abort [slug] [--purge] | version [--check-upstream] — state gates take [slug] and --confirmed (the operator already answered in chat); without it the agent's call returns NEEDS-OPERATOR with the question to ask in chat (it never opens a dialog), and the /flow slash command asks in a dialog — verify without --confirmed rebases a branch that is behind the default branch and deploys for review; --port=<n> / --replace answer its Dev port? question when another flow holds the stack — --ui on start is the agent's call whenever screens change (it only adds the mockup gate); --patch/--docs are proposed at start and granted by the Approve? answer; --no-ui (clearing ui on a plan-stage feature) and --merge=<style> are operator-granted (--confirmed); start refuses until the playbook has a merge policy and writes the answer into project.md — --yolo (with --confirmed) answers that checkpoint and pre-confirms every later one; checks and guardrails stay — verify --confirmed carries the operator's release call: --version=<v> (ship that version) or --no-version (merge unreleased), asked with Verified?; release takes the same flags when the call changed — on GitHub release then publishes itself (push, PR, CI wait, merge in the playbook style, annotated tag) and records the release; a 'publish stopped' or 'publish waiting' result is resumed by re-running flow release; publish = manual in the playbook (or another forge) leaves those steps to the agent, and finish records the release (--no-artifact-check / --no-release-create skip a proof on the operator's word) — release --no-version ships merge + changelog only (no bump, tag or forge release); --no-fold-check skips the changelog fold line proofs on the operator's word; --no-marker-check lets a branch add conflict-marker-shaped lines on purpose — finish runs the closing reflection worker first (before removing anything) and stops for the operator's fold/drop; the re-run with --confirmed cleans up; --no-reflect --confirmed skips it on the operator's explicit word (yolo never does), --note= hands the worker the operator's friction notes — release names a session running an older dev-flow build than the disk ships and asks update (/reload) or proceed — recorded, never a block — reflect <note> queues a project suggestion in reflections.md (--playbook = docs-flow fix, --code = patch-flow fix); --plugin never writes — dev-flow feedback goes upstream and it prints the GitHub issue recipe; bare reflect prints the session-reflection protocol (bound: run flow_stage op reflect); list numbers open items, move <n> re-files one, done <n> checks a fixed one off, tidy drops closed ones — roadmap manages .dev-flow/roadmap.md: pick <n> <slug> (or add --slug=) stamps an item for flow start, which seeds the new plan from its brief; finish checks it off; drop <n> removes an item nobody wants any more (done would record it as shipped); <n> is the row number list prints — done leaves the others in place, drop and tidy renumber — a new feature asked for mid-flow is parked there, never as a hand-made .dev-flow/<slug>/; start <slug> --confirmed adopts such a ghost dir — review records the review flow verify requires before it asks Verified? (and flow release before it ships): done <verdict> after the playbook's review step ran inline (a flow_stage review worker records itself); --skip (--confirmed, the operator's Skip review? answer) ships without one; bare review shows what is on record — doctor reviews structure, git consistency and open reflections (never writes); doctor <note> prints an investigation brief — abort unbinds and keeps the worktree; abort --purge (--confirmed, the operator's Purge? answer) removes the worktree, branch and feature folder of a dropped feature, never anything on origin — version prints the build the disk ships and any other dev-flow copies in this process (--check-upstream asks the registry)";
|
|
240
240
|
export const featDir = (root: string, slug: string) => path.join(dfDir(root), slug);
|
|
241
241
|
export const stateFile = (root: string, slug: string) => path.join(featDir(root, slug), "state.json");
|
|
242
242
|
export const claimFile = (root: string, slug: string) => path.join(featDir(root, slug), "claim.json");
|
|
@@ -507,6 +507,21 @@ export function featureEnv(root: string, state: FlowState): Record<string, strin
|
|
|
507
507
|
return featureTmpEnv(dir);
|
|
508
508
|
}
|
|
509
509
|
|
|
510
|
+
/** gh#243: drop stale mktemp leftovers from the feature's scratch dir (staleScratch decides which). Run where a
|
|
511
|
+
* gate runs the project's commands; best effort — a sweep that cannot read or remove something skips it. */
|
|
512
|
+
export function sweepScratch(root: string, state: FlowState, now = Date.now()): number {
|
|
513
|
+
const dir = featureTmpDir(dfDir(root), state.slug);
|
|
514
|
+
let entries: { name: string; mtimeMs: number }[] = [];
|
|
515
|
+
try {
|
|
516
|
+
entries = readdirSync(dir).map((name) => { try { return { name, mtimeMs: statSync(path.join(dir, name)).mtimeMs }; } catch { return { name, mtimeMs: now }; } });
|
|
517
|
+
} catch { return 0; }
|
|
518
|
+
let n = 0;
|
|
519
|
+
for (const name of staleScratch(entries, now)) {
|
|
520
|
+
try { rmSync(path.join(dir, name), { recursive: true, force: true }); n++; } catch { /* in use or not ours: leave it */ }
|
|
521
|
+
}
|
|
522
|
+
return n;
|
|
523
|
+
}
|
|
524
|
+
|
|
510
525
|
/** Per-cwd cache of the main checkout a linked worktree belongs to (null = not a linked worktree) —
|
|
511
526
|
* every hook resolves its root through flowRoot, so git is asked once per directory. */
|
|
512
527
|
export const mainCheckoutCache = new Map<string, string | null>();
|
package/src/runtime/checks.ts
CHANGED
|
@@ -3,10 +3,10 @@ import { existsSync, readFileSync, statfsSync } from "node:fs";
|
|
|
3
3
|
import { createServer } from "node:net";
|
|
4
4
|
import { freemem } from "node:os";
|
|
5
5
|
import path from "node:path";
|
|
6
|
-
import { AGENT_MARK, checkFingerprint, DEFAULTS, freshenChecks, healthProbe, prepOnlyChange, listFiles, needsOperator, newestTaggedVersion, parseVersion, sq, validSlug, formatSize, sideBySide, type BranchState, type Config, type DevSlot, type FlowState, type StageCheck } from "../core.ts";
|
|
6
|
+
import { AGENT_MARK, checkFingerprint, DEFAULTS, failTail, freshenChecks, healthProbe, prepOnlyChange, listFiles, needsOperator, newestTaggedVersion, parseVersion, sq, validSlug, formatSize, sideBySide, type BranchState, type Config, type DevSlot, type FlowState, type StageCheck } from "../core.ts";
|
|
7
7
|
import { loadProject } from "../projectmd.ts";
|
|
8
8
|
import { agentText, presentGate, type GateView, type StageFacts } from "../present.ts";
|
|
9
|
-
import { atomicWrite, boundFeature, buildSkew, dfDir, featDir, featureEnv, flagValue, gateCwd, initiated, mergeBase, now, originUrl, readState, runHealthProbe, sh, tail, worktreeAbs, writeState } from "./base.ts";
|
|
9
|
+
import { atomicWrite, boundFeature, buildSkew, dfDir, featDir, featureEnv, sweepScratch, flagValue, gateCwd, initiated, mergeBase, now, originUrl, readState, runHealthProbe, sh, tail, worktreeAbs, writeState } from "./base.ts";
|
|
10
10
|
import { type GateCtx } from "./gates.ts";
|
|
11
11
|
|
|
12
12
|
/** The port this flow's dev deploy uses: the operator's pick for it, else the playbook default. */
|
|
@@ -200,6 +200,7 @@ export async function runChecks(root: string, state: FlowState, cfg: Config, che
|
|
|
200
200
|
const lines: string[] = [];
|
|
201
201
|
let failed = false;
|
|
202
202
|
const ran: string[] = [];
|
|
203
|
+
sweepScratch(root, state);
|
|
203
204
|
for (const c of checks) {
|
|
204
205
|
// health is the same probe `flow health` runs: seeded first, retried within healthWait
|
|
205
206
|
const res = c.name === "health" ? await seededProbe(root, state, cfg, c.cmd) : await sh(c.cmd, gateCwd(root, state), undefined, featureEnv(root, state));
|
|
@@ -211,7 +212,7 @@ export async function runChecks(root: string, state: FlowState, cfg: Config, che
|
|
|
211
212
|
state.checks[c.name] = { ok: res.ok, at: now() };
|
|
212
213
|
ran.push(c.name);
|
|
213
214
|
const tried = triedNote((res as { attempts?: number }).attempts ?? 1);
|
|
214
|
-
lines.push(`${c.name}: ${res.ok ? "PASS" : "FAIL"} (${c.cmd}${tried})${res.ok ? "" : `\n${
|
|
215
|
+
lines.push(`${c.name}: ${res.ok ? "PASS" : "FAIL"} (${c.cmd}${tried})${res.ok ? "" : `\n${failTail(res.out)}`}`);
|
|
215
216
|
if (!res.ok) failed = true;
|
|
216
217
|
}
|
|
217
218
|
await stampChecks(root, state, ran);
|
|
@@ -258,12 +259,32 @@ export const triedNote = (attempts: number) => (attempts > 1 ? `, ${attempts} at
|
|
|
258
259
|
* tracked content (a hash of the uncommitted diff) and HEAD. Null when git cannot answer — a
|
|
259
260
|
* measurement failure must never mark a green record stale (see freshenChecks). */
|
|
260
261
|
export async function worktreeFingerprint(cwd: string): Promise<string | null> {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
262
|
+
// gh#231: the fingerprint is the tree's CONTENT — path → blob for every tracked and untracked file as it is on
|
|
263
|
+
// disk. It used to hash HEAD + status + diff, so a check run over an uncommitted fix went stale the moment
|
|
264
|
+
// that same fix was committed, and the next gate re-ran a minute-long suite over an identical tree.
|
|
265
|
+
// Nothing is written: index blob ids for clean paths, `git hash-object` (no -w) for changed and untracked ones.
|
|
266
|
+
const ls = await sh("git ls-files -s -z", cwd);
|
|
267
|
+
const changed = await sh("git ls-files -m -o --exclude-standard -z", cwd);
|
|
268
|
+
const deleted = await sh("git ls-files -d -z", cwd);
|
|
269
|
+
if (!ls.ok || !changed.ok || !deleted.ok) return null;
|
|
270
|
+
const map = new Map<string, string>();
|
|
271
|
+
for (const rec of ls.out.split("\0")) {
|
|
272
|
+
const tab = rec.indexOf("\t");
|
|
273
|
+
if (tab > 0) map.set(rec.slice(tab + 1), rec.slice(0, tab).split(" ")[1] ?? "");
|
|
274
|
+
}
|
|
275
|
+
const gone = new Set(deleted.out.split("\0").filter(Boolean));
|
|
276
|
+
for (const p of gone) map.delete(p);
|
|
277
|
+
const live = [...new Set(changed.out.split("\0").filter((p) => p && !gone.has(p)))].filter((p) => !p.includes("\n"));
|
|
278
|
+
for (let i = 0; i < live.length; i += 200) {
|
|
279
|
+
const batch = live.slice(i, i + 200);
|
|
280
|
+
const h = await sh(`printf '%s\\n' ${batch.map(sq).join(" ")} | git hash-object --stdin-paths`, cwd);
|
|
281
|
+
if (!h.ok) return null;
|
|
282
|
+
const ids = h.out.trim().split("\n");
|
|
283
|
+
if (ids.length !== batch.length) return null;
|
|
284
|
+
batch.forEach((p, j) => map.set(p, ids[j]));
|
|
285
|
+
}
|
|
286
|
+
const listing = [...map.entries()].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)).map(([p, id]) => `${id} ${p}`).join("\n");
|
|
287
|
+
return checkFingerprint(listing, "content");
|
|
267
288
|
}
|
|
268
289
|
|
|
269
290
|
/** Stamp freshly recorded checks with the tree they ran against — taken AFTER the run, so a check
|