pi-dev-flow 0.96.1 → 0.98.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 +32 -0
- package/docs/concurrency.md +5 -3
- package/docs/gates.md +33 -18
- package/docs/guardrails.md +12 -4
- package/docs/playbook.md +8 -3
- package/docs/reflections.md +6 -2
- package/extensions/dev-flow.ts +50 -30
- package/package.json +1 -1
- package/skills/dev-flow/SKILL.md +3 -3
- package/skills/dev-flow/references/finish.md +21 -15
- package/skills/dev-flow/references/pre-release.md +8 -7
- package/skills/dev-flow/references/release.md +2 -2
- package/skills/dev-flow/references/start.md +2 -0
- package/src/core.ts +82 -6
- package/src/projectmd.ts +24 -2
- package/src/runtime/base.ts +1 -1
- package/src/runtime/checks.ts +12 -2
- package/src/runtime/gates.ts +47 -5
- package/src/runtime/grants.ts +31 -3
- package/src/runtime/reflect.ts +49 -1
- package/src/runtime/ship.ts +72 -44
package/src/core.ts
CHANGED
|
@@ -56,6 +56,9 @@ export interface FlowState {
|
|
|
56
56
|
/** when flow verify at pre-release asked Verified? over review fixes; cleared by the answer — flow release refuses while it is set */
|
|
57
57
|
reverifyAsked?: string;
|
|
58
58
|
releaseOnly?: boolean; // verify found nothing on the branch but unreleased work on main: this flow only cuts the version (#161)
|
|
59
|
+
/** gh#299: the release call came from the agent's --version on a confirmed Approve? whose operator answer named
|
|
60
|
+
* no kind — a proposal, not the operator's word. Shown with Verified?, cleared by their answer or flow bump. */
|
|
61
|
+
versionProposed?: boolean;
|
|
59
62
|
versionChoice?: string; // the operator's release call, recorded with Approve?: patch | minor | major (a decision, never a number: counted from the newest tag at release, so a parallel flow taking the number moves it), "next" (playbook version = versioned: any bump past the last tag) or "unreleased"; any gate call before the tag can change it
|
|
60
63
|
versionFrom?: string; // the manifest version when the call was recorded — only for the hint's "as things stand" number; the gate counts from the newest tag
|
|
61
64
|
/** the session and its operator-message count when Verified? moved this flow to pre-release (gh#254): under
|
|
@@ -71,6 +74,7 @@ export interface FlowState {
|
|
|
71
74
|
reflectedAt?: string; // a reflect worker reported for this flow — finish runs one first while this is unset (only --no-reflect --confirmed skips it)
|
|
72
75
|
devPort?: number; // the port the operator chose for this flow's dev deploy when the default was held by another flow — finish stops it (devDown)
|
|
73
76
|
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)
|
|
77
|
+
reflectApplied?: boolean; // finish filed the closing reflection's own fold/drop recommendations (no question) — like reflectQuiet, nothing is left open for Finish?
|
|
74
78
|
reflectQuiet?: boolean; // finish skipped the closing reflection because the flow had no friction — with nothing else open, Finish? answers itself (release.finish = on-change)
|
|
75
79
|
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
|
|
76
80
|
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)
|
|
@@ -758,6 +762,13 @@ export function prepFiles(cfg: Config): Set<string> {
|
|
|
758
762
|
return new Set([cfg.versioning.file, cfg.release.changelog, cfg.versioning.file === "package.json" ? "package-lock.json" : ""].filter(Boolean) as string[]);
|
|
759
763
|
}
|
|
760
764
|
|
|
765
|
+
/** A path that ships no behaviour an operator's look at the running app could have judged: docs and tests. A
|
|
766
|
+
* commit touching only these after Verified? rides under that word (named in the release output) instead of
|
|
767
|
+
* asking Release? again. Markdown outside docs/ is not here: a skill or prompt file is product in some repos. */
|
|
768
|
+
export function nonBehaviourPath(f: string): boolean {
|
|
769
|
+
return /^docs\//.test(f) || /^(README|CONTRIBUTING|CHANGELOG)(\.[a-z]+)?$/i.test(f) || /(^|\/)(test|tests|__tests__|spec)\//.test(f) || /\.(test|spec)\.[a-z0-9]+$/i.test(f);
|
|
770
|
+
}
|
|
771
|
+
|
|
761
772
|
/** True when every changed path is a release-prep file (and something changed): the bump and the changelog
|
|
762
773
|
* entry land after the checks by design, and re-running the whole suite over them proves nothing new. */
|
|
763
774
|
export function prepOnlyChange(cfg: Config, changed: string[]): boolean {
|
|
@@ -1353,6 +1364,51 @@ export function localDefaultAhead(o: { defaultBranch: string; checkoutBranch: st
|
|
|
1353
1364
|
* DEV_FLOW_ALLOW_MAIN: the guard prints it, the operator grants it, the agent types it. (#83) */
|
|
1354
1365
|
export const ALLOW_REWRITE = "DEV_FLOW_ALLOW_REWRITE=1";
|
|
1355
1366
|
|
|
1367
|
+
/** The operator's yes to a playbook `confirm` rule, spelled on the retried command (gh#289). A guard confirm
|
|
1368
|
+
* never opens a dialog inside the agent's tool call — that held calls silently for hours, past their own
|
|
1369
|
+
* timeout — and a dialog's yes never reached the agent, so it repeated the same command. The guard refuses at
|
|
1370
|
+
* once with the reason; the agent asks in chat; the prefix counts only once an operator message followed. */
|
|
1371
|
+
export const OPERATOR_CONFIRMED = "DEV_FLOW_CONFIRMED=1";
|
|
1372
|
+
|
|
1373
|
+
/** A command carrying the prefix as its leading assignment, and the command it judges (prefix removed). */
|
|
1374
|
+
export function confirmedPrefix(command: string): { prefixed: boolean; target: string } {
|
|
1375
|
+
const t = command.trim();
|
|
1376
|
+
const m = t.match(/^DEV_FLOW_CONFIRMED=1\s+/);
|
|
1377
|
+
return m ? { prefixed: true, target: t.slice(m[0].length).trim() } : { prefixed: false, target: t };
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
/** The last confirm a session was refused: what it was for, and the operator-message count then. */
|
|
1381
|
+
export interface GuardAsk {
|
|
1382
|
+
target: string;
|
|
1383
|
+
users: number | null;
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
/** The verdict on a call that trips confirm rule(s): run (the operator answered this exact call), or a refusal
|
|
1387
|
+
* telling the agent to ask in chat, with the ask to record. `edit`: an edit has no command to prefix — a repeat
|
|
1388
|
+
* of the same edit after an operator message is the answer. A worker has no operator: never granted. */
|
|
1389
|
+
export function guardConfirmVerdict(o: { target: string; what: string; whys: string[]; prefixed: boolean; edit: boolean; users: number | null; prev: GuardAsk | undefined; worker: boolean }): { allow: true } | { allow: false; reason: string; record: GuardAsk | null } {
|
|
1390
|
+
const why = o.whys.join("; ");
|
|
1391
|
+
if (o.worker) return { allow: false, reason: `project rule: ${why} — it needs the operator's yes, and a worker has no operator: do not run it or work around it; name it under \`checks not run:\` in the REPORT`, record: null };
|
|
1392
|
+
const claims = o.edit || o.prefixed;
|
|
1393
|
+
const same = !!o.prev && o.prev.target === o.target;
|
|
1394
|
+
// no transcript to count (users null): a typed prefix is the agent's explicit claim and is taken, as --confirmed is
|
|
1395
|
+
// (grantCheck); a repeated edit claims nothing out loud, so it needs a counted operator reply
|
|
1396
|
+
const counted = o.users !== null && o.prev?.users !== null && o.prev !== undefined && o.users > o.prev.users;
|
|
1397
|
+
const answered = same && (counted || (!o.edit && (o.users === null || o.prev!.users === null)));
|
|
1398
|
+
if (claims && answered) return { allow: true };
|
|
1399
|
+
const retry = o.edit ? "repeat the same edit" : `re-run the same command prefixed with ${OPERATOR_CONFIRMED}`;
|
|
1400
|
+
const early = claims && same ? ` The operator has said nothing since the guard asked — ${o.edit ? "the repeat" : "the prefix"} counts only after their reply.` : o.prefixed ? ` ${OPERATOR_CONFIRMED} answers a refusal of this exact command; there was none, so this is the ask.` : "";
|
|
1401
|
+
return {
|
|
1402
|
+
allow: false,
|
|
1403
|
+
record: { target: o.target, users: o.users },
|
|
1404
|
+
reason: needsOperator(
|
|
1405
|
+
`${o.what} trips a project rule: ${why}.${early}`,
|
|
1406
|
+
o.edit ? "Edit it?" : "Run it?",
|
|
1407
|
+
`ask the operator in chat: name the ${o.edit ? "file" : "command"} and the rule's reason, and offer a form that avoids the rule if there is one. On their yes, ${retry}. A form that avoids the rule runs without asking.`,
|
|
1408
|
+
),
|
|
1409
|
+
};
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1356
1412
|
/** True when a segment force-pushes: `git push` carrying a force flag (`--force`, `--force-with-lease…`,
|
|
1357
1413
|
* `-f`, `-uf`). Decided on the verb per segment, not on a flag anywhere after `git` — `filter-branch
|
|
1358
1414
|
* --force` rewrites a local copy and `git show -f` lists files, and a blunt flag-only deny blocks both,
|
|
@@ -2689,12 +2745,14 @@ function stageHint(state: FlowState, cfg: Config): string {
|
|
|
2689
2745
|
if (vc === "unreleased")
|
|
2690
2746
|
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${gateAsks}`;
|
|
2691
2747
|
const prep = [cfg.release.changelog ? `prepare ${cfg.release.changelog} (fold Unreleased lines verbatim)` : "", cfg.versioning.file ? `bump version in ${cfg.versioning.file}${isBumpKind(vc) ? ` one ${vc} step past the newest tag (${bumpVersion(state.versionFrom, vc) ?? `the next ${vc}`} as of approval — a flow that released since moves it; flow release names the number)` : ""}` : ""].filter(Boolean).join(" and ");
|
|
2748
|
+
// gh#299: a proposal the operator never saw (a yolo skipped Verified?) is confirmed before the prep is cut
|
|
2749
|
+
if (vc && prep && state.versionProposed) return `${review}fix must/should, update docs; the release call ${vc} is the agent's proposal, not the operator's word — ask them the kind (patch, minor or major; flow bump <kind> --confirmed on a change) before you ${prep}; show the PR summary, version and changelog, then run flow release${gateAsks}`;
|
|
2692
2750
|
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${gateAsks}`;
|
|
2693
2751
|
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 run flow release${gateAsks}`;
|
|
2694
2752
|
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, then run flow release${gateAsks}`;
|
|
2695
2753
|
}
|
|
2696
2754
|
case "release":
|
|
2697
|
-
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
|
|
2755
|
+
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 run flow finish right away — do not ask Finish? first: it runs the closing reflection, files its suggestions and closes out, and asks only when something is left open`;
|
|
2698
2756
|
if (state.publish) return `flow release publishes (push, PR, CI wait, merge${state.noVersion ? "" : ", tag"}) and records the release — re-run it after a "publish stopped" or "publish waiting" result; then flow finish`;
|
|
2699
2757
|
return `publish: push the branch, open the PR, merge once CI is green (gh pr checks <n> --watch)${mergeHintFor(cfg)}${state.noVersion ? " — unversioned: no bump, no tag" : ", push the annotated tag"}; then flow finish records the release and closes out`;
|
|
2700
2758
|
}
|
|
@@ -2856,6 +2914,7 @@ export function defaultBudgetMin(op: WorkerOp, size: WorkerSize = {}): number {
|
|
|
2856
2914
|
|
|
2857
2915
|
/** Why an op is not legal for a feature at this stage, or null. */
|
|
2858
2916
|
export function workerOpError(op: string, stage: Stage): string | null {
|
|
2917
|
+
if (!op) return `op is missing — pass it as its own field beside note: flow_stage({ op: "implement" | "review" | "reflect", note: "…" }). implement: a worker edits and commits a slice; review: a fresh read-only reviewer; reflect: a fresh reviewer of this session's transcripts`;
|
|
2859
2918
|
if (op !== "implement" && op !== "review" && op !== "reflect") return `unknown op "${op}" — flow_stage ops: implement (a worker edits and commits a slice), review (a fresh read-only reviewer), reflect (a fresh reviewer of this session's transcripts)`;
|
|
2860
2919
|
const ok = WORKER_OP_STAGES[op];
|
|
2861
2920
|
return ok.includes(stage) ? null : `op "${op}" runs at ${ok.join(" or ")} — the feature is at ${stage}`;
|
|
@@ -2870,7 +2929,11 @@ export interface WorkerBriefInput {
|
|
|
2870
2929
|
defaultBranch: string;
|
|
2871
2930
|
commits: string; // `git log --oneline <base>..HEAD`
|
|
2872
2931
|
status: string; // `git status --short`
|
|
2873
|
-
|
|
2932
|
+
/** `green`: the driver's own flow check passed against this exact tree (fingerprint match) — a reviewer reads
|
|
2933
|
+
* that record instead of re-running the suite (gh#285) */
|
|
2934
|
+
checks: { name: string; command: string; green?: boolean }[];
|
|
2935
|
+
/** the feature's tmp dir as a literal path: a worker shell has no TMPDIR of its own (gh#281) */
|
|
2936
|
+
scratchDir?: string;
|
|
2874
2937
|
/** the playbook's `flow-worker` lines (gh#201): setup a worker needs before any project check can run */
|
|
2875
2938
|
preamble?: string[];
|
|
2876
2939
|
/** a --docs flow: the gates skip every project command, and no setup ran in the worktree — the brief hands out none (gh#211) */
|
|
@@ -2902,7 +2965,18 @@ function workerGuardLines(guard: GuardRules | undefined): string[] {
|
|
|
2902
2965
|
/** The facts every worker needs, so the driver's note can be just the slice. The plan path is absolute:
|
|
2903
2966
|
* it lives in the MAIN checkout's gitignored .dev-flow/, never inside the worktree. */
|
|
2904
2967
|
export function buildWorkerBrief(o: WorkerBriefInput): string {
|
|
2905
|
-
|
|
2968
|
+
// a read-only reviewer does not own the stack: the health probe answers a question it was told not to touch (gh#285)
|
|
2969
|
+
const listed = o.op === "review" ? o.checks.filter((c) => c.name !== "health") : o.checks;
|
|
2970
|
+
const checks = listed.length
|
|
2971
|
+
? listed.map((c) => `- ${c.name}: \`${c.command}\`${o.op === "review" && c.green ? " — green at this tree per the driver's flow check: do not re-run it" : ""}`).join("\n")
|
|
2972
|
+
: "- (the playbook defines no tier-1 commands)";
|
|
2973
|
+
const allGreen = o.op === "review" && listed.length > 0 && listed.every((c) => c.green);
|
|
2974
|
+
const checksHead =
|
|
2975
|
+
o.op === "review"
|
|
2976
|
+
? allGreen
|
|
2977
|
+
? "- Project checks (all green at this tree per the driver's flow check — do not re-run the suite; reproduce a specific claim with a targeted test instead):"
|
|
2978
|
+
: `- Project checks (run only the ones not marked green${o.preamble?.length ? ", in a shell that ran the setup below first" : ""}; a green one ran against this exact tree):`
|
|
2979
|
+
: `- Project checks (run them before you report${o.preamble?.length ? ", in a shell that ran the setup below first" : ""}):`;
|
|
2906
2980
|
const head = [
|
|
2907
2981
|
`You are a ${o.op === "implement" ? "stage worker implementing a slice" : "fresh, independent reviewer"} for dev-flow feature \`${o.slug}\`.`,
|
|
2908
2982
|
"",
|
|
@@ -2916,9 +2990,11 @@ export function buildWorkerBrief(o: WorkerBriefInput): string {
|
|
|
2916
2990
|
`- Uncommitted now: ${o.status.trim() ? `\n${o.status.trim().split("\n").map((l) => ` ${l}`).join("\n")}` : "clean"}`,
|
|
2917
2991
|
o.docs
|
|
2918
2992
|
? "- 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."
|
|
2919
|
-
:
|
|
2993
|
+
: `${checksHead}\n${checks}`,
|
|
2920
2994
|
"- You hold no flow tool: gates, checkpoints and the operator stay with the driving session.",
|
|
2921
|
-
|
|
2995
|
+
// gh#281: TMPDIR is not set in a worker's shell, so "$TMPDIR/x" became "/x"; and a playbook may require
|
|
2996
|
+
// scratch elsewhere (inside the worktree, so the toolchain resolves from it) — its rule wins
|
|
2997
|
+
`- Scratch: ${o.scratchDir ? `\`${o.scratchDir}\` (the feature's tmp dir — use this path; $TMPDIR is not set in your shell)` : "a `mktemp -d` dir"}; remove what you create. When the project's playbook names another scratch location, the playbook wins.`,
|
|
2922
2998
|
"",
|
|
2923
2999
|
...workerGuardLines(o.guard),
|
|
2924
3000
|
...(o.preamble?.length && !o.docs
|
|
@@ -2943,7 +3019,7 @@ export function buildWorkerBrief(o: WorkerBriefInput): string {
|
|
|
2943
3019
|
]
|
|
2944
3020
|
: [
|
|
2945
3021
|
"## Contract",
|
|
2946
|
-
`- Check, don't fix: read ${o.planFile ? "the plan" : "the task"}, the diff (\`git diff ${o.defaultBranch}...HEAD\`) and the code; run the checks and any probe that proves a claim. Change no files, make no commits.`,
|
|
3022
|
+
`- Check, don't fix: read ${o.planFile ? "the plan" : "the task"}, the diff (\`git diff ${o.defaultBranch}...HEAD\`) and the code; run the checks not already green and any probe that proves a claim. Change no files, make no commits.`,
|
|
2947
3023
|
"- Look for correctness bugs, claims in docs/changelog the code does not back, missing tests for risky paths, and plan items not delivered.",
|
|
2948
3024
|
"- A project check you could not run (a missing variable, file or service) is not a pass: name it and why under `checks not run:` in the REPORT, and say in the verdict line that the review is read-only for it.",
|
|
2949
3025
|
"- Finish with a final message whose last section starts with a line `REPORT` followed by: `verdict: PASS` or `verdict: FAIL`, then findings (most severe first, each with file:line and how you proved it).",
|
package/src/projectmd.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* tier 3: every other line — prose injected to the agent when its stage begins
|
|
6
6
|
* Parsing is pure and never fatal: unknown stages/keys and odd syntax become warnings.
|
|
7
7
|
*/
|
|
8
|
-
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
8
|
+
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
9
9
|
import path from "node:path";
|
|
10
10
|
import { applyAnswer, type ChecklistItem, type Config, DEFAULTS, healthProbe, parseMergeStyle, parseVersion, parseSize, toSeconds, type GuardRules, type StageCheck } from "./core.ts";
|
|
11
11
|
|
|
@@ -520,7 +520,28 @@ export function ghostFeatureDirs(root: string): string[] {
|
|
|
520
520
|
const df = path.join(root, ".dev-flow");
|
|
521
521
|
if (!existsSync(df)) return [];
|
|
522
522
|
return readdirSync(df, { withFileTypes: true })
|
|
523
|
-
|
|
523
|
+
// a plan/ holding no file has nothing to recover: that dir is an empty one (emptyFeatureDirs), swept without a question
|
|
524
|
+
.filter((d) => d.isDirectory() && existsSync(path.join(df, d.name, "plan")) && !existsSync(path.join(df, d.name, "state.json")) && !holdsNoFile(path.join(df, d.name)))
|
|
525
|
+
.map((d) => `.dev-flow/${d.name}`);
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
/** True when a directory holds no file anywhere beneath it — only (nested) empty directories. */
|
|
529
|
+
function holdsNoFile(dir: string): boolean {
|
|
530
|
+
for (const e of readdirSync(dir, { withFileTypes: true })) {
|
|
531
|
+
if (!e.isDirectory()) return false;
|
|
532
|
+
if (!holdsNoFile(path.join(dir, e.name))) return false;
|
|
533
|
+
}
|
|
534
|
+
return true;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/** Feature dirs emptied by a hand cleanup that stopped at the directory (gh#282): no file anywhere inside, so
|
|
538
|
+
* neither a feature (no state.json) nor a plan ghost (no plan/*.md). They hold nothing, so removing them loses
|
|
539
|
+
* nothing. `minAgeMs` keeps a dir a `flow start` is creating this very moment out of the sweep. */
|
|
540
|
+
export function emptyFeatureDirs(root: string, minAgeMs = 0, nowMs = Date.now()): string[] {
|
|
541
|
+
const df = path.join(root, ".dev-flow");
|
|
542
|
+
if (!existsSync(df)) return [];
|
|
543
|
+
return readdirSync(df, { withFileTypes: true })
|
|
544
|
+
.filter((d) => d.isDirectory() && holdsNoFile(path.join(df, d.name)) && nowMs - statSync(path.join(df, d.name)).mtimeMs >= minAgeMs)
|
|
524
545
|
.map((d) => `.dev-flow/${d.name}`);
|
|
525
546
|
}
|
|
526
547
|
|
|
@@ -592,6 +613,7 @@ export function doctorFindings(root: string, cfg: Config, md: ParsedMd | null):
|
|
|
592
613
|
if (cfg.commands.run && !cfg.checkList.some((c) => c.name === "health")) f.push('run command configured but no tier-1 health check — add commands.health or a flow-check so "running and healthy" is enforced');
|
|
593
614
|
if (cfg.commands.dev && !healthProbe(cfg)) f.push("dev deploy configured but no health check — flow verify cannot prove the deploy came back serving this build: add commands.health or a flow-check health block");
|
|
594
615
|
if (!cfg.checkList.length) f.push("implement tier-1 gates nothing — no test, no health, no flow-check block: 'flow check' would pass vacuously");
|
|
616
|
+
for (const g of emptyFeatureDirs(root)) f.push(`${g} is an empty feature dir — no state.json, no plan/, no file at all (a hand cleanup that stopped at the directory); flow init removes it`);
|
|
595
617
|
for (const g of ghostFeatureDirs(root)) f.push(`${g} has a plan/ but no state.json — ghost of a closed, aborted or hand-made feature (flow start <slug> --confirmed adopts it as a new feature; flow init offers to remove it)`);
|
|
596
618
|
return f;
|
|
597
619
|
}
|
package/src/runtime/base.ts
CHANGED
|
@@ -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> [--evidence=<file:line>]|list|plan|tidy|move <id> --playbook|--code|done <id>[,<id>…] [<what>]|reopen <id> [<why>]|defer <id> <why>|--same <id> [<evidence>]] | 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] [--reflections=r<id>,…] [--no-ui --confirmed] [--force] [--merge=squash|merge|rebase|any] [--check-upstream] | use <slug> | test | check | health | review [done <verdict>|--skip] | approve [--yolo] [--version=patch|minor|major|--no-version] | bump <patch|minor|major|none> [slug] | verify [--yolo] [--port=<n>|--replace] [--version=<kind>|--no-version] | release [--yolo|--version=<kind>|--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 — approve --confirmed carries the operator's release call on a versioned project: --version=patch|minor|major (the kind of step — the number is counted from the newest tag when the release runs) or --no-version (merge unreleased), asked with Approve?; it is never asked again, and the operator changes it on any later gate call (verify/release take the same flags) or with bump <kind> --confirmed, until the tag is cut — 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 prints open items by id (r<n>: never renumbered), plan groups them into flows with the start command, move <id> re-files one, done <id> checks a fixed one off, reopen <id> brings back one closed by mistake (from the archive too), --same <id> counts a recurrence on its row, defer <id> <why> leaves a row linked to the bound flow open, tidy moves closed ones to reflections-archive.md — start --reflections=<ids> links rows to the flow and finish closes them as fixed by it — 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)";
|
|
239
|
+
"help [--json] | init [--force|--draft|--write <text>|--write-file <path>|--answers key=value…|--answers-file <path>] [--confirmed] [--track] | reflect [<note> [--evidence=<file:line>]|list|plan|tidy|move <id> --playbook|--code|done <id>[,<id>…] [<what>]|reopen <id> [<why>]|defer <id> <why>|--same <id> [<evidence>]] | roadmap [add <text> [--slug=<slug>] [--brief=<notes>|--brief-file=<path>]|pick <n> <slug>|done <n>[,<n>…]|drop <n>[,<n>…]|tidy] | doctor [<issue note>] | guard <command>|--path <file> | status [slug] [--json] | start <slug> [--ui|--patch|--docs] [--reflections=r<id>,…] [--no-ui --confirmed] [--force] [--merge=squash|merge|rebase|any] [--check-upstream] | use <slug> | test | check | health | review [done <verdict>|--skip] | approve [--yolo] [--version=patch|minor|major|--no-version] | bump <patch|minor|major|none> [slug] | verify [--yolo] [--port=<n>|--replace] [--version=<kind>|--no-version] | release [--yolo|--version=<kind>|--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 — approve --confirmed carries the operator's release call on a versioned project: --version=patch|minor|major (the kind of step — the number is counted from the newest tag when the release runs) or --no-version (merge unreleased), asked with Approve?; it is never asked again, and the operator changes it on any later gate call (verify/release take the same flags) or with bump <kind> --confirmed, until the tag is cut — 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 prints open items by id (r<n>: never renumbered), plan groups them into flows with the start command, move <id> re-files one, done <id> checks a fixed one off, reopen <id> brings back one closed by mistake (from the archive too), --same <id> counts a recurrence on its row, defer <id> <why> leaves a row linked to the bound flow open, tidy moves closed ones to reflections-archive.md — start --reflections=<ids> links rows to the flow and finish closes them as fixed by it — 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");
|
package/src/runtime/checks.ts
CHANGED
|
@@ -131,8 +131,10 @@ export async function devSlotCheck(o: GateCtx, state: FlowState): Promise<RunRes
|
|
|
131
131
|
// the holder's review is over — it is past Verified? (pre-release or release) and not re-asking it, or it is
|
|
132
132
|
// gone: nobody is looking at that deploy, so taking the port asks nobody (lettuce rail-avatar-size-28 asked
|
|
133
133
|
// replace-or-wait over a flow that had already merged)
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
// The same holds for a holder that is not waiting on its Verified?: only that question puts a person in front
|
|
135
|
+
// of the deploy — the holder's own verify redeploys before it asks again.
|
|
136
|
+
if (!other || other.pendingAsk !== "Verified?")
|
|
137
|
+
return { note: `dev: replaced ${slot.slug}'s deploy on ${portLabel(port)} — ${other ? `it is at ${other.stage}, not waiting on its Verified?` : "that flow is gone"}, so nobody was reviewing it` };
|
|
136
138
|
const taken = new Set(Object.keys(reg).map(Number).filter(Number.isFinite));
|
|
137
139
|
const nextPort = port !== undefined ? await nextFreePort(port, taken) : null;
|
|
138
140
|
const mem = memAvailable();
|
|
@@ -142,6 +144,12 @@ export async function devSlotCheck(o: GateCtx, state: FlowState): Promise<RunRes
|
|
|
142
144
|
`RAM available ${mem !== null ? formatSize(mem) : "unknown"}${cfg.instanceMem !== undefined ? ` (one instance needs ${formatSize(cfg.instanceMem)})` : ""}`,
|
|
143
145
|
`disk free ${disk !== null ? formatSize(disk) : "unknown"}${cfg.instanceDisk !== undefined ? ` (one instance needs ${formatSize(cfg.instanceDisk)})` : ""}`,
|
|
144
146
|
].join(", ");
|
|
147
|
+
// under review, and a second instance is known to fit: run alongside — nothing of the other flow is touched
|
|
148
|
+
if (side.ok && cfg.parallelDev === true && nextPort !== null) {
|
|
149
|
+
state.devPort = nextPort;
|
|
150
|
+
writeState(root, state);
|
|
151
|
+
return { note: `dev: ${portLabel(port)} is serving ${slot.slug} under review — deployed alongside on port ${nextPort} (parallelDev = yes)` };
|
|
152
|
+
}
|
|
145
153
|
const caveat = side.ok
|
|
146
154
|
? cfg.parallelDev === undefined
|
|
147
155
|
? " The playbook does not say whether two instances can share this machine (parallelDev = yes|no) — tell the operator that when you ask."
|
|
@@ -474,4 +482,6 @@ export interface Session {
|
|
|
474
482
|
/** Operator messages in this session's branch so far, or null/undefined when it cannot be read — a gate
|
|
475
483
|
* compares it with the count it recorded earlier to know whether the operator spoke since (gh#254). */
|
|
476
484
|
operatorMessages?: number | null;
|
|
485
|
+
/** The operator's newest message text, or null/undefined when it cannot be read (gh#299). */
|
|
486
|
+
operatorText?: string | null;
|
|
477
487
|
}
|
package/src/runtime/gates.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
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 { foldCallError, skipsChecks, approveGate, versionArg, playbookVersionChoice, releaseCallQuestion, describeVersionChoice, 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, parseRowIds, DF_GITIGNORE } from "../core.ts";
|
|
5
|
-
import { applyAnswers, buildDraft, doctorFindings, ghostFeatureDirs, ghostInfo, lineDiff, loadProject, mdDigest, parseAnswers, parseProjectMd } from "../projectmd.ts";
|
|
4
|
+
import { type ReflectFinding, type ReflectOpenCheck, ALLOW_REWRITE, forcePushInvocation, guardBash, guardPath, foldCallError, skipsChecks, approveGate, versionArg, playbookVersionChoice, releaseCallQuestion, describeVersionChoice, 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, parseRowIds, DF_GITIGNORE } from "../core.ts";
|
|
5
|
+
import { applyAnswers, buildDraft, doctorFindings, emptyFeatureDirs, ghostFeatureDirs, ghostInfo, lineDiff, loadProject, mdDigest, parseAnswers, parseProjectMd } from "../projectmd.ts";
|
|
6
6
|
import { linkedTag } from "../fold.ts";
|
|
7
|
+
import { namesReleaseCall } from "./grants.ts";
|
|
7
8
|
import { detectProject } from "../detect.ts";
|
|
8
9
|
import { AGENT_MARK } from "../present.ts";
|
|
9
10
|
import { GATE_HELP, SELF_BUILD, refreshDocsCode, type Ui, manifestAt, recordReleaseCall, buildSkew, copyWarning, currentBranch, dfDir, featDir, featureEnv, flagValue, gateCwd, gitConsistency, initiated, loadedVersion, mergeHistoryEvidence, needState, now, originUrl, publishedVersion, readClaim, readReflections, readReflectionsText, readRoadmap, readState, roadmapFile, sh, stateFile, tail, unfinishedStates, writePlaybookMergePolicy, writeState } from "./base.ts";
|
|
@@ -14,7 +15,7 @@ import { gateFinish, gateRelease, gateReleaseDone, gateVerify } from "./ship.ts"
|
|
|
14
15
|
|
|
15
16
|
/** What a gate may need from the extension closure: finish runs the closing reflection worker itself. */
|
|
16
17
|
export interface FlowHooks {
|
|
17
|
-
reflect?: (state: FlowState, note: string) => Promise<{ text: string; recorded: boolean; findings: number; failed: boolean }>;
|
|
18
|
+
reflect?: (state: FlowState, note: string) => Promise<{ text: string; recorded: boolean; findings: number; failed: boolean; report?: { findings: ReflectFinding[]; open: ReflectOpenCheck[] } }>;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
/** Write `.dev-flow/.gitignore` when it is missing; true when it did. Best effort — never fails a gate. */
|
|
@@ -75,6 +76,9 @@ export async function runFlow(args: string[], root: string, ui: Ui, sess: Sessio
|
|
|
75
76
|
case "doctor":
|
|
76
77
|
return gateDoctor(o);
|
|
77
78
|
|
|
79
|
+
case "guard":
|
|
80
|
+
return gateGuard(o, rest);
|
|
81
|
+
|
|
78
82
|
case "version":
|
|
79
83
|
return gateVersion(o);
|
|
80
84
|
|
|
@@ -169,6 +173,13 @@ export async function gateInit(o: GateCtx): Promise<RunResult> {
|
|
|
169
173
|
const draftFresh = buildDraft(det);
|
|
170
174
|
const questions = setupQuestions(det, { merge: mergeEv, tag: tagEv });
|
|
171
175
|
if (flag("draft")) return { text: existsSync(mdFile) ? readFileSync(mdFile, "utf8") : draftFresh }; // read path: prints content, writes nothing (and offers no deletions)
|
|
176
|
+
// empty feature dirs hold nothing to lose: removed with a note, no question (gh#282). Ten minutes old at
|
|
177
|
+
// least, so a dir a parallel flow start has only just created is not swept before its state.json lands.
|
|
178
|
+
const empties = emptyFeatureDirs(root, 10 * 60_000);
|
|
179
|
+
if (empties.length) {
|
|
180
|
+
for (const g of empties) rmSync(path.join(root, g), { recursive: true, force: true });
|
|
181
|
+
notes.push(`removed ${empties.length} empty feature dir(s) — no state.json, no plan/, no file: ${empties.map((g) => g.slice(".dev-flow/".length)).join(", ")}`);
|
|
182
|
+
}
|
|
172
183
|
// ghosts: feature dirs whose state.json is gone — inert, invisible to status and guards, and only findable by eye
|
|
173
184
|
const ghosts = ghostFeatureDirs(root);
|
|
174
185
|
if (ghosts.length) {
|
|
@@ -517,9 +528,14 @@ export async function gateApprove(o: GateCtx): Promise<RunResult> {
|
|
|
517
528
|
state!.stage = "implement";
|
|
518
529
|
state!.approvals.plan = now();
|
|
519
530
|
if (call) recordReleaseCall(root, state!, cfg, call);
|
|
531
|
+
// gh#299: an operator answer that names no kind accepts the plan, not the agent's proposed call — kept, marked
|
|
532
|
+
const proposed = flag("confirmed") && !!relArg.choice && !namesReleaseCall(sess.operatorText ?? null, relArg.choice);
|
|
533
|
+
if (proposed) state!.versionProposed = true;
|
|
534
|
+
else if (relArg.choice) delete state!.versionProposed;
|
|
520
535
|
delete state!.pendingAsk;
|
|
521
536
|
writeState(root, state!);
|
|
522
|
-
|
|
537
|
+
const proposedNote = proposed ? ` — recorded as YOUR PROPOSAL: the operator's answer named no kind, so the call is not theirs yet. Verified? shows it to them; their answer, or flow bump <kind> --confirmed, settles it` : "";
|
|
538
|
+
return { text: `plan approved${audit}${state!.yolo ? " — yolo: later gate questions pre-confirmed" : ""}; worktree ${wtRel} on branch ${branch}.${call ? `\nrelease call: ${describeVersionChoice(call, state!.versionFrom)}${proposedNote} — the number is counted from the newest tag at release; the operator can change the call on any gate call (or flow bump <kind>) until the tag` : ""}${setupNote}\n${AGENT_MARK}next: ${nextHint(state!, cfg)}` };
|
|
523
539
|
}
|
|
524
540
|
|
|
525
541
|
/** `flow bump <patch|minor|major|none> [slug]`: the operator changes the release call at any stage before the tag.
|
|
@@ -540,9 +556,10 @@ export async function gateBump(o: GateCtx): Promise<RunResult> {
|
|
|
540
556
|
if (!cfg.versioning.file && choice !== "unreleased") return { text: "bump FAILED:\n- the playbook sets no version file (versionFile under ## release), so there is nothing to bump — set one first", isError: true };
|
|
541
557
|
if (state!.publish?.tag || state!.approvals.release) return { text: `bump FAILED:\n- ${state!.publish?.tag ?? "the release"} is already ${state!.publish?.tag ? "tagged" : "recorded"} — the call cannot change after the tag`, isError: true };
|
|
542
558
|
const was = state!.versionChoice;
|
|
543
|
-
if (was === choice) return { text: `release call unchanged: ${describeVersionChoice(choice, state!.versionFrom)}` };
|
|
559
|
+
if (was === choice && !(state!.versionProposed && flag("confirmed"))) return { text: `release call unchanged: ${describeVersionChoice(choice, state!.versionFrom)}${state!.versionProposed ? " — still the agent's proposal; flow bump <kind> --confirmed on the operator's word settles it" : ""}` };
|
|
544
560
|
if (!flag("confirmed")) return { text: needsOperator(`change the release call from ${was ? describeVersionChoice(was) : "none"} to ${describeVersionChoice(choice)}`, "Release call?", `this is the operator's word — on it, re-run flow bump ${kind}${slug ? ` ${slug}` : ""} --confirmed`), isError: true };
|
|
545
561
|
recordReleaseCall(root, state!, cfg, choice);
|
|
562
|
+
delete state!.versionProposed; // the operator's own word now (gh#299)
|
|
546
563
|
writeState(root, state!);
|
|
547
564
|
const prep = state!.stage === "pre-release" || state!.stage === "release" ? ` — redo the release prep to match (${choice === "unreleased" ? "revert any bump; the entry goes under Unreleased" : "the version file and its changelog heading"}); flow release names the number` : "";
|
|
548
565
|
return { text: `release call changed (confirmed by operator instruction): ${was ? describeVersionChoice(was) : "none"} → ${describeVersionChoice(choice, state!.versionFrom)}${prep}` };
|
|
@@ -718,6 +735,31 @@ export async function gateRoadmap(o: GateCtx): Promise<RunResult> {
|
|
|
718
735
|
}
|
|
719
736
|
}
|
|
720
737
|
|
|
738
|
+
/** `flow guard "<command>"` / `flow guard --path <file>`: which of the playbook's own flow-guard rules a command
|
|
739
|
+
* or a path trips, through the same matcher the hooks use (gh#287). Reads only; runs nothing. */
|
|
740
|
+
export async function gateGuard(o: GateCtx, rest: string[]): Promise<RunResult> {
|
|
741
|
+
const { root, cfg } = o;
|
|
742
|
+
const g = cfg.guard;
|
|
743
|
+
const nRules = g.deny.length + g.confirm.length + g.protect.length + g.forbid.length;
|
|
744
|
+
const usage = 'usage: flow guard "<command>" (which playbook rule a shell command trips) or flow guard --path <file> (which rule an edit of that path trips)';
|
|
745
|
+
if (rest[0] === "--path") {
|
|
746
|
+
const file = rest.slice(1).join(" ").trim();
|
|
747
|
+
if (!file) return { text: usage, isError: true };
|
|
748
|
+
const v = guardPath(path.resolve(root, file), root, g);
|
|
749
|
+
const verdict = v.block ? `blocked — ${v.block}` : v.confirm ? `asks the operator — ${v.confirm}` : "no playbook rule matches this path";
|
|
750
|
+
return { text: `flow guard --path ${file}: ${verdict}\n(${nRules} playbook rule(s); stage guards — worktree, main-checkout and flow-state rules — are judged separately at the call)` };
|
|
751
|
+
}
|
|
752
|
+
const command = rest.join(" ").trim();
|
|
753
|
+
if (!command) return { text: usage, isError: true };
|
|
754
|
+
const v = guardBash(command, g);
|
|
755
|
+
const lines: string[] = [];
|
|
756
|
+
if (v.block) lines.push(`blocked — ${v.block} (the command never runs)`);
|
|
757
|
+
for (const r of v.confirms) lines.push(`asks the operator — \`${r.pattern}\`${r.why ? ` :: ${r.why}` : ""}`);
|
|
758
|
+
if (forcePushInvocation(command)) lines.push(`asks the operator — dev-flow's own force-push rule (the operator's word is the ${ALLOW_REWRITE} prefix)`);
|
|
759
|
+
if (!lines.length) lines.push("no playbook rule matches — runs as far as the playbook is concerned");
|
|
760
|
+
return { text: `flow guard: \`${command.length > 200 ? `${command.slice(0, 200)}…` : command}\`\n${lines.map((l) => `- ${l}`).join("\n")}\n(${nRules} playbook rule(s); read-only segments such as cat or grep are skipped, as at the call; stage guards are judged separately)` };
|
|
761
|
+
}
|
|
762
|
+
|
|
721
763
|
export async function gateDoctor(o: GateCtx): Promise<RunResult> {
|
|
722
764
|
const { root, rest } = o;
|
|
723
765
|
// read-only findings on demand — never writes, never asks, safe for agents and CI at any stage
|
package/src/runtime/grants.ts
CHANGED
|
@@ -29,6 +29,30 @@ export function operatorMessageCount(entries: readonly unknown[] | null | undefi
|
|
|
29
29
|
return n;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
/** The text of the operator's newest message in the branch, or null when it cannot be read. */
|
|
33
|
+
export function lastOperatorText(entries: readonly unknown[] | null | undefined): string | null {
|
|
34
|
+
if (!Array.isArray(entries)) return null;
|
|
35
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
36
|
+
// SAFETY: narrow structural view of the SessionEntry union; only a user message's text is read
|
|
37
|
+
const m = entries[i] as { type?: string; message?: { role?: string; content?: unknown } };
|
|
38
|
+
if (m.type !== "message" || m.message?.role !== "user") continue;
|
|
39
|
+
const c = m.message.content;
|
|
40
|
+
if (typeof c === "string") return c;
|
|
41
|
+
if (Array.isArray(c)) return c.map((p) => (p && typeof p === "object" && (p as { type?: string }).type === "text" ? String((p as { text?: unknown }).text ?? "") : "")).join(" ");
|
|
42
|
+
return "";
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Whether the operator's words name this release call (gh#299): `minor` for minor, `unreleased` / `no version`
|
|
48
|
+
* / `don't release` for unreleased. Null words (unreadable) are taken as naming it — nothing to check against. */
|
|
49
|
+
export function namesReleaseCall(words: string | null, choice: string): boolean {
|
|
50
|
+
if (words === null) return true;
|
|
51
|
+
const w = words.toLowerCase();
|
|
52
|
+
if (choice === "unreleased") return /\bunreleased\b|\bno[- ]?version\b|\bdon'?t (?:release|version|bump)\b|\bwithout (?:a )?(?:release|version|bump)\b|\bno (?:release|bump)\b/.test(w);
|
|
53
|
+
return new RegExp(`\\b${choice}\\b`).test(w);
|
|
54
|
+
}
|
|
55
|
+
|
|
32
56
|
export interface GrantLedger {
|
|
33
57
|
/** per session: the gate that last asked for the operator's word, and the operator-message count then */
|
|
34
58
|
asked: Map<string, { sub: string; users: number }>;
|
|
@@ -69,7 +93,10 @@ export function grantCheck(args: readonly string[], key: string, users: number |
|
|
|
69
93
|
export function grantRecord(args: readonly string[], key: string, users: number | null, res: { text: string; isError?: boolean }, ledger: GrantLedger): void {
|
|
70
94
|
if (users === null) return;
|
|
71
95
|
const sub = args[0] ?? "";
|
|
72
|
-
|
|
96
|
+
// gh#283: a stopped or waiting publish resumes on a re-run and asks nobody — its prose may still mention the
|
|
97
|
+
// operator's word (a real failure's way forward), which must not turn the resume into a question
|
|
98
|
+
const resumable = /(?:^|\n)publish (?:stopped|waiting) —/.test(res.text);
|
|
99
|
+
if (res.isError && !resumable && (res.text.startsWith(NEEDS_OPERATOR) || ASKS_FOR_WORD.test(res.text))) {
|
|
73
100
|
ledger.asked.set(key, { sub, users });
|
|
74
101
|
return;
|
|
75
102
|
}
|
|
@@ -79,8 +106,9 @@ export function grantRecord(args: readonly string[], key: string, users: number
|
|
|
79
106
|
|
|
80
107
|
/** A refusal that is the work failing, not the process: a red test, a broken build, a deploy that did not come up. */
|
|
81
108
|
const WORK_FAILURE = /check run at the gate failed|\bbuild FAILED\b|dev deploy FAILED|probe FAILED|served-build check FAILED|after-merge check "[^"]*" failed|has not passed|publish stopped — PR #\d+ checks failed/;
|
|
82
|
-
/** The release gate still waiting on CI
|
|
83
|
-
|
|
109
|
+
/** The release gate still waiting on CI, or finish handing over the release-stage items: re-running it is the
|
|
110
|
+
* instruction, never a sign the agent is stuck. */
|
|
111
|
+
const WAITING = /(?:^|\n)(?:publish waiting|release-stage work) —/;
|
|
84
112
|
/** `flow check|test|health` reporting a red run — the answer those tools exist to give. A refusal from them that
|
|
85
113
|
* is not a run (nothing configured, no feature bound) stays friction. */
|
|
86
114
|
const RED_RUN = /^(?:tier-1 checks:|test: FAIL|health: FAIL)/;
|
package/src/runtime/reflect.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** dev-flow runtime — Reflections and the upstream issue fold. Moved out of extensions/dev-flow.ts as is (exports added). */
|
|
2
2
|
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import { ensureReflectIds as ensureReflectIdsFor, appendReflection, doneItemCount, githubSlug, pluginVersion, guessReflectSections, reflectItems, reflectMove, reflectDone, reflectRow, reflectLegacyPluginCount, reflectionNudges, pluginIssueRecipe, reflectionLine, reflectionsTidy, openChecklistItems, parseRowIds, reflectSame, reflectReopen, closedRowsBySection, archiveAppend, archiveTake, reflectFixPlan, rowId, type ReflectTarget, type ReflectItem, type ReflectSection, type FlowState } from "../core.ts";
|
|
4
|
+
import { ensureReflectIds as ensureReflectIdsFor, appendReflection, doneItemCount, githubSlug, pluginVersion, guessReflectSections, reflectItems, reflectMove, reflectDone, reflectRow, reflectLegacyPluginCount, reflectionNudges, pluginIssueRecipe, reflectionLine, reflectionsTidy, openChecklistItems, parseRowIds, reflectSame, reflectReopen, closedRowsBySection, archiveAppend, archiveTake, reflectFixPlan, rowId, shortFindingNote, type ReflectFinding, type ReflectOpenCheck, type ReflectTarget, type ReflectItem, type ReflectSection, type FlowState } from "../core.ts";
|
|
5
5
|
import { dedupeReflections, linkedTag, parseGhIssues, similarNote, type FoldResult, type GhIssue } from "../fold.ts";
|
|
6
6
|
import { dfDir, now, originUrl, readState, writeState, readReflectArchive, readReflections, readReflectionsText, reflectArchiveFile, sh } from "./base.ts";
|
|
7
7
|
import { type RunResult, type Session } from "./checks.ts";
|
|
@@ -107,6 +107,54 @@ export function reflectDeferNote(root: string, sess: Session, args: string[]): R
|
|
|
107
107
|
return { text: `reflect: r${id} deferred by ${sess.slug} — it stays open (${why}); finish closes the rest of the linked rows as fixed` };
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
+
/** finish's closing reflection, settled without a question: the reviewer's own fold/drop recommendation is
|
|
111
|
+
* applied — a fold is recorded (a recurrence on the row its dup names), a drop records nothing — and the lines
|
|
112
|
+
* say what happened and how to undo it. A plugin fold outside the dev-flow repo is an upstream issue, which is
|
|
113
|
+
* public: it is named for the operator, never filed from here. */
|
|
114
|
+
export async function applyReflectFindings(root: string, sess: Session, report: { findings: ReflectFinding[]; open: ReflectOpenCheck[] }): Promise<string[]> {
|
|
115
|
+
const self = isSelfRepo(root);
|
|
116
|
+
const out: string[] = [];
|
|
117
|
+
const upstream: string[] = [];
|
|
118
|
+
for (const f of report.findings) {
|
|
119
|
+
const short = shortFindingNote(f.note);
|
|
120
|
+
if (f.rec === "drop") {
|
|
121
|
+
out.push(` ${f.n}. dropped: ${short}`);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const dupRow = /^r(\d+)$/i.exec(f.dup.trim());
|
|
125
|
+
if (dupRow) {
|
|
126
|
+
const same = reflectSameNote(root, sess, [`r${dupRow[1]}`, f.evidence]);
|
|
127
|
+
if (!same.isError) {
|
|
128
|
+
out.push(` ${f.n}. folded as a recurrence of r${dupRow[1]}: ${short}`);
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (/^gh#\d+$/i.test(f.dup.trim())) {
|
|
133
|
+
out.push(` ${f.n}. already filed as ${f.dup.trim()}: ${short}`);
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (f.kind === "plugin" && !self) {
|
|
137
|
+
upstream.push(` ${f.n}. ${short}`);
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
const r = await reflectNote(root, sess, [f.note], f.kind === "docs" ? "playbook" : "code", f.evidence);
|
|
141
|
+
const id = /reflected as (r\d+)/.exec(r.text)?.[1] ?? /as (r\d+)/.exec(r.text)?.[1];
|
|
142
|
+
out.push(` ${f.n}. folded${id ? ` as ${id}` : ""} (${f.kind === "docs" ? "playbook" : "code"}): ${short}`);
|
|
143
|
+
}
|
|
144
|
+
for (const o of report.open) {
|
|
145
|
+
if (o.status === "recurred") {
|
|
146
|
+
const same = reflectSameNote(root, sess, [`r${o.n}`, o.reason]);
|
|
147
|
+
if (!same.isError) out.push(` r${o.n} seen again: ${shortFindingNote(o.reason)}`);
|
|
148
|
+
} else if (o.status === "fixed") out.push(` r${o.n} looks fixed${o.reason ? ` (${shortFindingNote(o.reason)})` : ""} — close it on the operator's word: flow reflect done r${o.n} "<where>"`);
|
|
149
|
+
}
|
|
150
|
+
if (!out.length && !upstream.length) return ["closing reflection: nothing new to fold."];
|
|
151
|
+
return [
|
|
152
|
+
`closing reflection — the reviewer's recommendations were applied (no question; to undo a fold: flow reflect done <id> "dropped"; to keep a drop: flow reflect --playbook|--code "<note>"):`,
|
|
153
|
+
...out,
|
|
154
|
+
...(upstream.length ? [" dev-flow feedback to file upstream on the operator's word (flow reflect --plugin \"<note>\" prints the recipe):", ...upstream] : []),
|
|
155
|
+
];
|
|
156
|
+
}
|
|
157
|
+
|
|
110
158
|
/** Close the rows a flow was linked to and did not defer — finish's half of the link. Returns the ids closed. */
|
|
111
159
|
export function closeLinkedReflections(root: string, state: FlowState, prNote: string): number[] {
|
|
112
160
|
const linked = (state.reflections ?? []).filter((r) => !r.deferred);
|