pi-dev-flow 0.97.0 → 0.99.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.
@@ -55,6 +55,39 @@ knobs · merge-policy state.
55
55
  - Start warns when this session runs an older dev-flow build than the
56
56
  checkout (`/reload` before trusting gate output) and lists playbook gaps.
57
57
 
58
+ ### Jira (opt-in: a `flow-jira` block in project.md)
59
+
60
+ - **Turning it on: `flow jira init`.** It asks one thing at a time, and each
61
+ answer is a flag on the next call:
62
+ 1. `Jira login?` — the operator runs `/flow jira login` themselves. Never
63
+ ask for the token in chat.
64
+ 2. `Jira project?` → `--project=KEY`.
65
+ 3. `Issue types?` → `--types=A,B`.
66
+ 4. `Mapping OK?` — show the proposed status mapping. The operator can
67
+ change it with `--map=<Type>.<stage>=<Status>`. On their word,
68
+ re-run with `--confirmed`.
69
+ - **Starting from an issue.** When the operator names an issue key, run
70
+ `flow start --jira=KEY`. The slug comes from the issue unless you give
71
+ one. The issue's description seeds `plan/plan.md`. To link a flow that
72
+ is already running: `flow jira link KEY`.
73
+ - **No issue named at start?** The start output asks you to offer three
74
+ choices: create a new issue, link an existing one, or go without. To
75
+ create one: `flow jira create --summary="…" [--description="…"]
76
+ [--type=…]`. It previews and asks `Create Jira issue?`. On a yes, re-run
77
+ it with `--confirmed`, and the new issue is linked. Never create an issue
78
+ unasked; `--no-jira` on start skips the offer.
79
+ - **Roadmap items:** `flow jira create --roadmap=<n>[,<n>…]` makes one issue
80
+ per item and stamps the item with `[KEY]`. Picking that item and starting
81
+ it links its issue automatically.
82
+ - **Your closing message is posted to the issue** when it asks something,
83
+ with the plan and mockups attached at Approve?. Images you name by path
84
+ are attached too, so name screenshot files explicitly.
85
+ - **Answers that come back from Jira:**
86
+ - `[Jira KEY · your comment] …` and `[Jira KEY moved to … ] Approved` are
87
+ the operator's own answers. Treat them exactly like a chat reply.
88
+ - `… information only` lines are not answers.
89
+ - `flow jira check` reads the issue now. `flow jira status` shows the links.
90
+
58
91
  ### Modes
59
92
 
60
93
  - `normal` — a written plan (`plan/plan.md`) is required before Approve?.
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
@@ -67,6 +70,8 @@ export interface FlowState {
67
70
  /** reflection rows this flow set out to fix (`flow start --reflections=r3,r7`): finish closes each as fixed by
68
71
  * this flow, unless `flow reflect defer <id> "<why>"` left it open with a reason */
69
72
  reflections?: { id: number; body: string; deferred?: string }[];
73
+ /** the Jira issue this flow syncs with (`flow start --jira=KEY`, project.md flow-jira) */
74
+ jira?: JiraLink;
70
75
  verifiedHead?: string; // HEAD the operator's Verified? was given over — release names commits after it, so the word is not recorded as the verdict for a tree nobody looked at (#162)
71
76
  reflectedAt?: string; // a reflect worker reported for this flow — finish runs one first while this is unset (only --no-reflect --confirmed skips it)
72
77
  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)
@@ -131,6 +136,48 @@ export interface Versioning {
131
136
  pattern: string;
132
137
  }
133
138
 
139
+ /** A dev-flow stage, plus `done` (the flow finished), as a Jira status mapping target. */
140
+ export type JiraStage = Stage | "done";
141
+
142
+ /** project.md ` ```flow-jira ` block (src/jira/config.ts) — the opt-in Jira sync; absent = off. */
143
+ export interface JiraConfig {
144
+ site: string; // acme.atlassian.net
145
+ cloudId?: string;
146
+ project: string; // project key
147
+ issueTypes: string[];
148
+ /** issue type → stage → status names (the first is where dev-flow moves the issue) */
149
+ status: Record<string, Partial<Record<JiraStage, string[]>>>;
150
+ /** which of the agent's closing messages become comments: asks (a question is pending) | all */
151
+ mirror: "asks" | "all";
152
+ /** seconds between reply checks after a question; the last repeats */
153
+ watch: number[];
154
+ /** seconds after the question when the watch gives up */
155
+ watchCap: number;
156
+ }
157
+
158
+ /** A flow's link to its Jira issue, in state.json. */
159
+ export interface JiraLink {
160
+ key: string;
161
+ type: string; // issue type name
162
+ site: string;
163
+ /** the token owner's account id — only their comments are answers */
164
+ accountId?: string;
165
+ /** ids of comments dev-flow posted (never read back as answers) */
166
+ posted: string[];
167
+ /** ISO time up to which comments have been read */
168
+ seenUntil?: string;
169
+ /** the newest comment id read (Jira ids grow; its comment times are minute-precision) */
170
+ seenCommentId?: string;
171
+ /** the issue's status as last seen (or last set by dev-flow) */
172
+ lastStatus?: string;
173
+ /** sha1 of files already attached, so a re-ask does not attach them again */
174
+ attached?: string[];
175
+ /** sha1 of the last closing message mirrored — the same message is never posted twice */
176
+ mirrored?: string;
177
+ /** the open question a watch is waiting on: armed when it was posted, `checks` made since */
178
+ watch?: { ask: string; since: string; checks: number };
179
+ }
180
+
134
181
  export interface Config {
135
182
  defaultBranch: string;
136
183
  branchPattern: string; // {slug} substituted
@@ -166,6 +213,8 @@ export interface Config {
166
213
  /** Lines from the ## global `flow-worker` block: every flow_stage brief carries them, so a worker can run the
167
214
  * project's checks (e.g. an export of a test password read from a gitignored file) — gh#201. */
168
215
  workerPreamble?: string[];
216
+ /** project.md flow-jira block — the opt-in Jira sync; unset = off */
217
+ jira?: JiraConfig;
169
218
  }
170
219
 
171
220
  export const DEFAULTS: Config = {
@@ -1361,6 +1410,51 @@ export function localDefaultAhead(o: { defaultBranch: string; checkoutBranch: st
1361
1410
  * DEV_FLOW_ALLOW_MAIN: the guard prints it, the operator grants it, the agent types it. (#83) */
1362
1411
  export const ALLOW_REWRITE = "DEV_FLOW_ALLOW_REWRITE=1";
1363
1412
 
1413
+ /** The operator's yes to a playbook `confirm` rule, spelled on the retried command (gh#289). A guard confirm
1414
+ * never opens a dialog inside the agent's tool call — that held calls silently for hours, past their own
1415
+ * timeout — and a dialog's yes never reached the agent, so it repeated the same command. The guard refuses at
1416
+ * once with the reason; the agent asks in chat; the prefix counts only once an operator message followed. */
1417
+ export const OPERATOR_CONFIRMED = "DEV_FLOW_CONFIRMED=1";
1418
+
1419
+ /** A command carrying the prefix as its leading assignment, and the command it judges (prefix removed). */
1420
+ export function confirmedPrefix(command: string): { prefixed: boolean; target: string } {
1421
+ const t = command.trim();
1422
+ const m = t.match(/^DEV_FLOW_CONFIRMED=1\s+/);
1423
+ return m ? { prefixed: true, target: t.slice(m[0].length).trim() } : { prefixed: false, target: t };
1424
+ }
1425
+
1426
+ /** The last confirm a session was refused: what it was for, and the operator-message count then. */
1427
+ export interface GuardAsk {
1428
+ target: string;
1429
+ users: number | null;
1430
+ }
1431
+
1432
+ /** The verdict on a call that trips confirm rule(s): run (the operator answered this exact call), or a refusal
1433
+ * telling the agent to ask in chat, with the ask to record. `edit`: an edit has no command to prefix — a repeat
1434
+ * of the same edit after an operator message is the answer. A worker has no operator: never granted. */
1435
+ 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 } {
1436
+ const why = o.whys.join("; ");
1437
+ 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 };
1438
+ const claims = o.edit || o.prefixed;
1439
+ const same = !!o.prev && o.prev.target === o.target;
1440
+ // no transcript to count (users null): a typed prefix is the agent's explicit claim and is taken, as --confirmed is
1441
+ // (grantCheck); a repeated edit claims nothing out loud, so it needs a counted operator reply
1442
+ const counted = o.users !== null && o.prev?.users !== null && o.prev !== undefined && o.users > o.prev.users;
1443
+ const answered = same && (counted || (!o.edit && (o.users === null || o.prev!.users === null)));
1444
+ if (claims && answered) return { allow: true };
1445
+ const retry = o.edit ? "repeat the same edit" : `re-run the same command prefixed with ${OPERATOR_CONFIRMED}`;
1446
+ 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.` : "";
1447
+ return {
1448
+ allow: false,
1449
+ record: { target: o.target, users: o.users },
1450
+ reason: needsOperator(
1451
+ `${o.what} trips a project rule: ${why}.${early}`,
1452
+ o.edit ? "Edit it?" : "Run it?",
1453
+ `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.`,
1454
+ ),
1455
+ };
1456
+ }
1457
+
1364
1458
  /** True when a segment force-pushes: `git push` carrying a force flag (`--force`, `--force-with-lease…`,
1365
1459
  * `-f`, `-uf`). Decided on the verb per segment, not on a flag anywhere after `git` — `filter-branch
1366
1460
  * --force` rewrites a local copy and `git show -f` lists files, and a blunt flag-only deny blocks both,
@@ -2557,6 +2651,35 @@ export function roadmapPick(text: string, n: number, slug: string): string | nul
2557
2651
  return editOpenRow(text, n, (l) => (l.trim().includes(`(${slug})`) ? l.trim() : `${l.trim()} (${slug})`));
2558
2652
  }
2559
2653
 
2654
+ /** The open item at row n with its brief, or null. */
2655
+ export function roadmapItemAt(text: string, n: number): { item: string; brief: string } | null {
2656
+ const lines = text.split("\n");
2657
+ let row = 0;
2658
+ for (let i = 0; i < lines.length; i++) {
2659
+ if (!isRoadmapRow(lines[i]) || ++row !== n) continue;
2660
+ if (!isOpenItem(lines[i])) return null;
2661
+ const brief: string[] = [];
2662
+ for (let j = i + 1; j < lines.length && isBriefLine(lines[j]); j++) brief.push(lines[j].replace(/^\s+> ?/, ""));
2663
+ return { item: lines[i].trim().slice(6), brief: brief.join("\n").trim() };
2664
+ }
2665
+ return null;
2666
+ }
2667
+
2668
+ /** The Jira key an item was stamped with (`[DEV-12]`), or null. */
2669
+ export const roadmapJiraKey = (item: string): string | null => item.match(/\[([A-Z][A-Z0-9_]*-\d+)\]/)?.[1] ?? null;
2670
+
2671
+ /** An item's text without its stamps — `(slug)` and `[KEY]` — e.g. for an issue summary. */
2672
+ export const roadmapItemTitle = (item: string): string =>
2673
+ item
2674
+ .replace(/\s*\[[A-Z][A-Z0-9_]*-\d+\]/g, "")
2675
+ .replace(/\s*\([a-z0-9-]+\)\s*$/, "")
2676
+ .trim();
2677
+
2678
+ /** Stamp the open item at row n with a Jira key `[KEY]`. Null when row n is no open item. */
2679
+ export function roadmapStampJira(text: string, n: number, key: string): string | null {
2680
+ return editOpenRow(text, n, (l) => (roadmapJiraKey(l) ? l.trim() : l.trim().replace(/^(- \[ \] )(.*?)(\s*\([a-z0-9-]+\))?$/, (_m, h, body, slug) => `${h}${body} [${key}]${slug ?? ""}`)));
2681
+ }
2682
+
2560
2683
  /** Check the open item at row n with a done stamp. Null when row n is no open item. */
2561
2684
  export function roadmapDone(text: string, n: number, stamp: string): string | null {
2562
2685
  return editOpenRow(text, n, (l) => stampItem(l, stamp));
@@ -2697,6 +2820,8 @@ function stageHint(state: FlowState, cfg: Config): string {
2697
2820
  if (vc === "unreleased")
2698
2821
  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}`;
2699
2822
  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 ");
2823
+ // gh#299: a proposal the operator never saw (a yolo skipped Verified?) is confirmed before the prep is cut
2824
+ 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}`;
2700
2825
  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}`;
2701
2826
  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}`;
2702
2827
  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}`;
@@ -2864,6 +2989,7 @@ export function defaultBudgetMin(op: WorkerOp, size: WorkerSize = {}): number {
2864
2989
 
2865
2990
  /** Why an op is not legal for a feature at this stage, or null. */
2866
2991
  export function workerOpError(op: string, stage: Stage): string | null {
2992
+ 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`;
2867
2993
  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)`;
2868
2994
  const ok = WORKER_OP_STAGES[op];
2869
2995
  return ok.includes(stage) ? null : `op "${op}" runs at ${ok.join(" or ")} — the feature is at ${stage}`;
@@ -2878,7 +3004,11 @@ export interface WorkerBriefInput {
2878
3004
  defaultBranch: string;
2879
3005
  commits: string; // `git log --oneline <base>..HEAD`
2880
3006
  status: string; // `git status --short`
2881
- checks: { name: string; command: string }[];
3007
+ /** `green`: the driver's own flow check passed against this exact tree (fingerprint match) — a reviewer reads
3008
+ * that record instead of re-running the suite (gh#285) */
3009
+ checks: { name: string; command: string; green?: boolean }[];
3010
+ /** the feature's tmp dir as a literal path: a worker shell has no TMPDIR of its own (gh#281) */
3011
+ scratchDir?: string;
2882
3012
  /** the playbook's `flow-worker` lines (gh#201): setup a worker needs before any project check can run */
2883
3013
  preamble?: string[];
2884
3014
  /** a --docs flow: the gates skip every project command, and no setup ran in the worktree — the brief hands out none (gh#211) */
@@ -2910,7 +3040,18 @@ function workerGuardLines(guard: GuardRules | undefined): string[] {
2910
3040
  /** The facts every worker needs, so the driver's note can be just the slice. The plan path is absolute:
2911
3041
  * it lives in the MAIN checkout's gitignored .dev-flow/, never inside the worktree. */
2912
3042
  export function buildWorkerBrief(o: WorkerBriefInput): string {
2913
- const checks = o.checks.length ? o.checks.map((c) => `- ${c.name}: \`${c.command}\``).join("\n") : "- (the playbook defines no tier-1 commands)";
3043
+ // a read-only reviewer does not own the stack: the health probe answers a question it was told not to touch (gh#285)
3044
+ const listed = o.op === "review" ? o.checks.filter((c) => c.name !== "health") : o.checks;
3045
+ const checks = listed.length
3046
+ ? 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")
3047
+ : "- (the playbook defines no tier-1 commands)";
3048
+ const allGreen = o.op === "review" && listed.length > 0 && listed.every((c) => c.green);
3049
+ const checksHead =
3050
+ o.op === "review"
3051
+ ? allGreen
3052
+ ? "- 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):"
3053
+ : `- 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):`
3054
+ : `- Project checks (run them before you report${o.preamble?.length ? ", in a shell that ran the setup below first" : ""}):`;
2914
3055
  const head = [
2915
3056
  `You are a ${o.op === "implement" ? "stage worker implementing a slice" : "fresh, independent reviewer"} for dev-flow feature \`${o.slug}\`.`,
2916
3057
  "",
@@ -2924,9 +3065,11 @@ export function buildWorkerBrief(o: WorkerBriefInput): string {
2924
3065
  `- Uncommitted now: ${o.status.trim() ? `\n${o.status.trim().split("\n").map((l) => ` ${l}`).join("\n")}` : "clean"}`,
2925
3066
  o.docs
2926
3067
  ? "- 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."
2927
- : `- Project checks (run them before you report${o.preamble?.length ? ", in a shell that ran the setup below first" : ""}):\n${checks}`,
3068
+ : `${checksHead}\n${checks}`,
2928
3069
  "- You hold no flow tool: gates, checkpoints and the operator stay with the driving session.",
2929
- "- Scratch goes in $TMPDIR (the feature's tmp dir); remove what you create there — `d=$(mktemp -d) && …; rm -rf \"$d\"`.",
3070
+ // gh#281: TMPDIR is not set in a worker's shell, so "$TMPDIR/x" became "/x"; and a playbook may require
3071
+ // scratch elsewhere (inside the worktree, so the toolchain resolves from it) — its rule wins
3072
+ `- 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.`,
2930
3073
  "",
2931
3074
  ...workerGuardLines(o.guard),
2932
3075
  ...(o.preamble?.length && !o.docs
@@ -2951,7 +3094,7 @@ export function buildWorkerBrief(o: WorkerBriefInput): string {
2951
3094
  ]
2952
3095
  : [
2953
3096
  "## Contract",
2954
- `- 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.`,
3097
+ `- 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.`,
2955
3098
  "- Look for correctness bugs, claims in docs/changelog the code does not back, missing tests for risky paths, and plan items not delivered.",
2956
3099
  "- 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.",
2957
3100
  "- 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).",