pi-dev-flow 0.68.0 → 0.69.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 +12 -0
- package/docs/gates.md +4 -4
- package/docs/playbook.md +7 -0
- package/docs/stage-agent.md +95 -48
- package/extensions/dev-flow.ts +396 -78
- package/package.json +1 -1
- package/skills/dev-flow/SKILL.md +4 -1
- package/skills/dev-flow/references/finish.md +7 -3
- package/skills/dev-flow/references/implement.md +22 -8
- package/skills/dev-flow/references/plan.md +4 -0
- package/skills/dev-flow/references/reflect.md +6 -1
- package/skills/dev-flow/references/release.md +5 -1
- package/skills/dev-flow/references/start.md +12 -0
- package/src/core.ts +431 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-dev-flow",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.69.0",
|
|
4
4
|
"description": "Enforced feature workflow for Pi: plan → implement → pre-release → release, gated checkpoints, self-improvement reflections, one git worktree per feature, changelog + publish as part of the release",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
package/skills/dev-flow/SKILL.md
CHANGED
|
@@ -50,6 +50,9 @@ Ground rules:
|
|
|
50
50
|
`flow release --no-version --confirmed` — the merge still owes a changelog
|
|
51
51
|
entry under `Unreleased`, which the next versioned release folds under its
|
|
52
52
|
version heading (default is versioned: bump + tag).
|
|
53
|
+
- **Pre-plan before binding:** an unbound session writes **nothing** — bring
|
|
54
|
+
findings, questions and a proposed direction + slug/mode, and **ask the
|
|
55
|
+
operator to start** (protocol: `references/start.md`).
|
|
53
56
|
- **One session = exactly one feature** (flow + branch + worktree); parallel
|
|
54
57
|
sessions, one feature each, are the model. A session binds **explicitly and
|
|
55
58
|
only**: `flow start <slug>` binds its own feature (main checkout must be on
|
|
@@ -86,7 +89,7 @@ session's stage injection names the file to read now, and this is the map.
|
|
|
86
89
|
|
|
87
90
|
| Read | For |
|
|
88
91
|
| --- | --- |
|
|
89
|
-
| `references/start.md` | `flow init` (no `.dev-flow/` yet), mode grants (`--patch`, `--docs`), playbook ownership |
|
|
92
|
+
| `references/start.md` | pre-plan (unbound: no writes, ask to start), `flow init` (no `.dev-flow/` yet), mode grants (`--patch`, `--docs`), playbook ownership |
|
|
90
93
|
| `references/plan.md` | plan stage — research, clarify, plan file, mockups, Approve? |
|
|
91
94
|
| `references/implement.md` | implement stage — worktree, commits, checks, tier-2 list, Verified? |
|
|
92
95
|
| `references/pre-release.md` | pre-release — `/flow-review`, docs, changelog + bump, Release? |
|
|
@@ -5,9 +5,13 @@
|
|
|
5
5
|
## Stage: finish
|
|
6
6
|
|
|
7
7
|
**Reflect before you finish** — `flow finish` deletes `.dev-flow/<slug>/` and
|
|
8
|
-
the session context goes with it.
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
the session context goes with it. **Delegate the review**: `flow_stage { op:
|
|
9
|
+
"reflect" }` (legal after `release-done`) hands the whole finished flow — this
|
|
10
|
+
session's transcript plus every worker transcript, the plan, live status — to a
|
|
11
|
+
fresh reviewer that returns `[playbook]`/`[plugin]`-tagged findings as an
|
|
12
|
+
outside view. Park real issues with `flow reflect` (the bare `flow reflect`
|
|
13
|
+
self-protocol under *Reflect* is the fallback only when delegation is
|
|
14
|
+
impossible); then:
|
|
11
15
|
|
|
12
16
|
- issues parked → ask **Fold? Fix? Drop?** and stop: fold = write the items
|
|
13
17
|
into `.dev-flow/reflections.md` (your queue), fix = route them now via
|
|
@@ -9,12 +9,16 @@ or the injection line) — writes elsewhere are blocked; other sessions'
|
|
|
9
9
|
worktrees are theirs (attribution guards judge every path by its owning
|
|
10
10
|
feature).
|
|
11
11
|
|
|
12
|
-
**Delegating the stage's work.**
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
**Delegating the stage's work.** Non-trivial implement is **delegated by default**: run it in
|
|
13
|
+
a disposable worker session with `flow_stage` (`stage: "implement"`) — this session keeps its
|
|
14
|
+
context for the gates and the checkpoint; stay inline only for a tail you can finish in a
|
|
15
|
+
handful of file edits. The
|
|
15
16
|
worker gets a fresh context holding the plan, live git and `flow status
|
|
16
17
|
--json` — it keeps nothing from this conversation, so put every operator
|
|
17
|
-
answer, decision, warning and the exact next action into `note
|
|
18
|
+
answer, decision, warning and the exact next action into `note`, and a short
|
|
19
|
+
`label` — a few words of purpose — so the picker reads `⏳ 🔨 #2 · wire ops` and,
|
|
20
|
+
when it ends, `✓ 🔨 #2 · 3 commits · wire ops` (a verify: `✓ 🔍 · PASS · <label>`)
|
|
21
|
+
instead of a column of identical rows. The worker
|
|
18
22
|
may edit and commit in the worktree but holds no flow tool: gates,
|
|
19
23
|
checkpoints and the claim stay with you. When it returns, digest its stage
|
|
20
24
|
report (done/files/notes/blockers — a handoff, never a verification), rerun
|
|
@@ -25,9 +29,11 @@ snapshot `.diff` the result gives. Delegate a real slice, not the tail: do not
|
|
|
25
29
|
delegate a stage you are about to finish anyway. One worker per session at a
|
|
26
30
|
time — but **sequential re-delegation is legal and often right**: a second
|
|
27
31
|
worker whose `note` says what the first one proved is how a big stage is
|
|
28
|
-
sliced. While one runs, the
|
|
32
|
+
sliced. While one runs, the **tool card streams the worker's live output into
|
|
33
|
+
your transcript** (current tool, last assistant line, ✓/✗ results, clock against budget,
|
|
34
|
+
usage); the footer beats progress, the worker is visible as a
|
|
29
35
|
named session in the picker, and `flow_stage { op: "status" }` answers “how’s it
|
|
30
|
-
going?” without a model call. Size `budgetMin` to the slice (default 45): at 75%
|
|
36
|
+
going?” without a model call on any host (the tail also mirrors to `stage-live.log`). Size `budgetMin` to the slice (default 45; verify/reflect default 30): at 75%
|
|
31
37
|
the worker is steered to commit and report rather than cut off.
|
|
32
38
|
|
|
33
39
|
1. Implement per the approved plan with project conventions and the **stage
|
|
@@ -48,7 +54,15 @@ the worker is steered to commit and report rather than cut off.
|
|
|
48
54
|
the tier-2 confirmation — rerun before verify.
|
|
49
55
|
4. UI flag set? An actual browser visual pass (screenshot or the project's
|
|
50
56
|
automated pass) — not just a typecheck.
|
|
51
|
-
5.
|
|
57
|
+
5. **The independent checker speaks before the operator does:** `flow_stage { op: "verify" }`
|
|
58
|
+
runs a read-only reviewer (toolset read + bash, standing order *check, don't fix*) over the
|
|
59
|
+
plan and the branch diff; it closes with a `VERIFY REPORT` verdict. Its **PASS is a
|
|
60
|
+
precondition of `flow verify`** and belongs to the tree it read: any edit after it — yours or
|
|
61
|
+
a delegated fixer's — drops it like a tier-1 record, so fix → a **fresh** verify worker;
|
|
62
|
+
a verdict from an interrupted or tree-touching worker never stamps (a reviewer that edits
|
|
63
|
+
voids its own report). FAIL means: fix (or delegate), then rerun a fresh one — the report is
|
|
64
|
+
a handoff, the gate's own rerun is the proof.
|
|
65
|
+
6. Done means **running and healthy with pre-existing data**, not "compiles":
|
|
52
66
|
`commands.seedData` (if set) puts real data in place, the app starts with
|
|
53
67
|
the `run` command, and the health check passes — `flow check` covers it
|
|
54
68
|
(seedData runs before health) and `flow verify` probes **the deployed app
|
|
@@ -63,7 +77,7 @@ the worker is steered to commit and report rather than cut off.
|
|
|
63
77
|
`health` itself and refuses while nothing is answering). Checkpoint report: stage line **🔨 implement ·
|
|
64
78
|
`<slug>`** — commits `N ahead, M uncommitted` · tier-1 · tier-2 · deploy/
|
|
65
79
|
health · `branch@sha`, then `Done:`/`Next steps:` per the Stage reports rule. Fixes = iterate and re-verify; that loop is
|
|
66
|
-
free.
|
|
80
|
+
free — but every fix re-owes the verify worker's PASS.
|
|
67
81
|
|
|
68
82
|
`flow verify` re-runs build, runs the `dev` deploy when configured (the
|
|
69
83
|
operator reviews the running app; the gate **prints what it ran** —
|
|
@@ -17,6 +17,10 @@
|
|
|
17
17
|
name is itself the gate's proof: **plan.md** — a preliminary direction
|
|
18
18
|
belongs *inside* plan.md (marked draft), never a separate
|
|
19
19
|
`pre-plan`/`direction.md` file: the approve gate requires plan.md by name.
|
|
20
|
+
The flow folder is the plan's permanent home — the worktree only exists
|
|
21
|
+
after approval, while the plan must exist (and stay amendable during
|
|
22
|
+
implement) from before it; that is why plan.md lives in
|
|
23
|
+
`.dev-flow/<slug>/plan/`, not in the worktree.
|
|
20
24
|
First check
|
|
21
25
|
`git log origin/<default>..<default> --oneline`: local-only default-branch
|
|
22
26
|
commits fall out of the worktree's base (push them or re-plan).
|
|
@@ -26,7 +26,12 @@ and stage context; the operator decides:
|
|
|
26
26
|
count with this verb when the pile grows; offer the tidy to the operator then.
|
|
27
27
|
- **Bare `flow reflect` is the end-of-session reflection** — it runs as part
|
|
28
28
|
of every finish (before the slug folder is deleted — see Stage: finish) and
|
|
29
|
-
whenever the operator asks.
|
|
29
|
+
whenever the operator asks. The default way to run that review at finish is
|
|
30
|
+
delegated: `flow_stage { op: "reflect" }` (release stage, after
|
|
31
|
+
`release-done`) gives the whole flow — driver transcript + every worker
|
|
32
|
+
transcript + plan + status — to an independent session that returns tagged
|
|
33
|
+
findings you put to the operator (Fold? Fix? Drop?); the self-protocol below
|
|
34
|
+
is the fallback when delegation is impossible. It prints the
|
|
30
35
|
protocol: review the full session log (messages, tool calls, results);
|
|
31
36
|
re-check each open item against the current playbook and newer dev-flow
|
|
32
37
|
versions (`npm view pi-dev-flow version` vs the running version, or
|
|
@@ -8,7 +8,11 @@ Cleared for main-repo git (merge/tag/push on the default branch is allowed only
|
|
|
8
8
|
here) — this stage publishes; the preparation happened in pre-release. Run in
|
|
9
9
|
the worktree unless noted:
|
|
10
10
|
|
|
11
|
-
1. Commit everything, push the feature branch, open the PR,
|
|
11
|
+
1. Commit everything, push the feature branch, open the PR, and **merge only once
|
|
12
|
+
CI is green**: `gh pr checks <n> --watch` (or your forge's equivalent) first — a
|
|
13
|
+
locally-green branch can still fail checks that only CI runs (the host may lack the
|
|
14
|
+
tool entirely), and the merge is what turns the default branch red (gh#134). Then
|
|
15
|
+
wait for the merge
|
|
12
16
|
(`gh pr merge <n> --merge` or ask the user) — with the **playbook's merge style spelled out**
|
|
13
17
|
(`gh pr merge <n> --squash` under `merge = squash`), and **the PR number before the flag**: a bare
|
|
14
18
|
`gh pr merge --merge main` makes gh read `main` as the PR selector ("no pull requests found for
|
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
> [../SKILL.md](../SKILL.md); this file is the detail for one stage — read it
|
|
3
3
|
> when the session reaches that stage.
|
|
4
4
|
|
|
5
|
+
## Before a flow exists (pre-plan)
|
|
6
|
+
|
|
7
|
+
A feature request arriving in an **unbound** session gets analysis, not
|
|
8
|
+
scaffolding — this is the only phase with **no writes at all** (guards refuse
|
|
9
|
+
checkout writes unbound anyway): read the code the request touches (reads are
|
|
10
|
+
always free), then bring back to chat: findings, the real unknowns, your
|
|
11
|
+
**open questions** and a proposed **direction**, with a proposed slug and mode
|
|
12
|
+
and its one-line why. **Ask the operator to start the flow** — only on their
|
|
13
|
+
word do you `flow start <slug>` (they grant any `--patch`/`--docs` mode at the
|
|
14
|
+
start gate). The direction lives in chat until the plan stage writes and owns
|
|
15
|
+
`plan.md`.
|
|
16
|
+
|
|
5
17
|
## Start
|
|
6
18
|
|
|
7
19
|
**No `.dev-flow/`?** `flow init` analyzes the repo and prints a **setup
|
package/src/core.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Pure(ish) logic only — no pi imports here so it is unit-testable with
|
|
5
5
|
* `node --test`. The extension in extensions/dev-flow.ts is thin wiring.
|
|
6
6
|
*/
|
|
7
|
-
import { existsSync, readdirSync, readFileSync, realpathSync } from "node:fs";
|
|
7
|
+
import { existsSync, readdirSync, readFileSync, readlinkSync, realpathSync } from "node:fs";
|
|
8
8
|
import { createHash } from "node:crypto";
|
|
9
9
|
import os from "node:os";
|
|
10
10
|
import path from "node:path";
|
|
@@ -47,6 +47,7 @@ export interface FlowState {
|
|
|
47
47
|
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)
|
|
48
48
|
staleBuild?: string; // release ran under an older dev-flow than the checkout by operator choice ("<loaded> (checkout <disk>)"); release-done repeats the acknowledgement
|
|
49
49
|
pendingAsk?: string; // the checkpoint word a gate asked for and has not been given ("Approve?", "Verified?", …) — presentation only (💬 in the footer), it never gates
|
|
50
|
+
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
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
/** Tier-2 item: operator prose; uiOnly items ("(ui)" in project.md) apply only to --ui features. */
|
|
@@ -479,6 +480,9 @@ export function freshenChecks(state: FlowState, fp: string | null, keep: (name:
|
|
|
479
480
|
if (!fp) return [];
|
|
480
481
|
const stale: string[] = [];
|
|
481
482
|
for (const [name, rec] of Object.entries(state.checks)) {
|
|
483
|
+
// the verify stamp answers to a WIDER fingerprint (worktree + plan/), so plain worktree
|
|
484
|
+
// comparison must never speak for it — the verify gate voids it against that fingerprint.
|
|
485
|
+
if (name === VERIFY_STAMP) continue;
|
|
482
486
|
if (rec.wt && rec.wt !== fp && !keep(name)) {
|
|
483
487
|
delete state.checks[name];
|
|
484
488
|
stale.push(name);
|
|
@@ -1810,8 +1814,8 @@ export function nextHint(state: FlowState, cfg: Config): string {
|
|
|
1810
1814
|
return state.approvals.release
|
|
1811
1815
|
? "release recorded — commit and push the release chores in the main checkout (prefix the commit with DEV_FLOW_ALLOW_MAIN=1 — the installed pre-commit hook otherwise blocks main commits), ask the operator Finish? and run flow finish (removes worktree, branch and .dev-flow/" + state.slug + "/)"
|
|
1812
1816
|
: state.noVersion
|
|
1813
|
-
? `publish: commit and push the branch, open
|
|
1814
|
-
: `publish: commit and push the branch, open
|
|
1817
|
+
? `publish: commit and push the branch, open the PR, merge only once CI is green (gh pr checks <n> --watch — a locally-green branch can still fail CI-only jobs)${mergeHintFor(cfg)} — unversioned release: no manifest bump, no tag, your changelog entry rides under Unreleased; then run flow release-done (no further question)`
|
|
1818
|
+
: `publish: commit and push the branch, open the PR, merge only once CI is green (gh pr checks <n> --watch — a locally-green branch can still fail CI-only jobs)${mergeHintFor(cfg)}, create the annotated tag from the manifest version and push it, then run flow release-done (no further question)`;
|
|
1815
1819
|
default:
|
|
1816
1820
|
return "feature finished";
|
|
1817
1821
|
}
|
|
@@ -2063,3 +2067,427 @@ export function stageLiveLine(elapsedMs: number, toolName: string, argsSummary:
|
|
|
2063
2067
|
export function stageInterruptSteer(budgetMin: number): string {
|
|
2064
2068
|
return `Budget spent (${budgetMin} min) — stop planning new work now. Finish only the edit you are mid-way through, commit everything that is done to the feature branch (a "wip(stage): …" commit is fine and expected), then close with the STAGE REPORT block: done lists what is committed, notes says what was never started and what may not compile, blockers says "interrupted at budget". Do not start new units.`;
|
|
2065
2069
|
}
|
|
2070
|
+
|
|
2071
|
+
// ------------------------------------------------------- worker ops beyond the stage work (verify / reflect / live card)
|
|
2072
|
+
|
|
2073
|
+
/** Every `flow_stage` op. `run` is a stage's work; `verify` and `reflect` are check-only reviews —
|
|
2074
|
+
* they read and run commands but hold no edit or write, so the driving session gets independent eyes
|
|
2075
|
+
* without handing over a gate or a fix; `status` reads the live run and needs no worker at all. */
|
|
2076
|
+
export const WORKER_OPS = ["run", "verify", "reflect", "status"] as const;
|
|
2077
|
+
export type WorkerOp = (typeof WORKER_OPS)[number];
|
|
2078
|
+
export function isWorkerOp(s: string): s is WorkerOp {
|
|
2079
|
+
return (WORKER_OPS as readonly string[]).includes(s);
|
|
2080
|
+
}
|
|
2081
|
+
|
|
2082
|
+
/** Default budget per op, minutes (the shared 5–120 clamp still applies). An implement slice is a
|
|
2083
|
+
* whole stage; a review run reads and executes and cannot land a unit, so its default is the
|
|
2084
|
+
* operator-set 30 — smaller default, same steer at 75%. */
|
|
2085
|
+
export const WORKER_OP_BUDGET_MIN: Record<WorkerOp, number> = { run: STAGE_BUDGET_DEFAULT_MIN, verify: 30, reflect: 30, status: STAGE_BUDGET_DEFAULT_MIN };
|
|
2086
|
+
|
|
2087
|
+
/** Toolset per op — the guard still judges every write by the owning feature's stage, but a reviewer
|
|
2088
|
+
* that carries no edit or write tool cannot even try to fix what it is judging (standing order:
|
|
2089
|
+
* check, don't fix). `status` spawns nothing; the empty list is the marker, never a spawn. */
|
|
2090
|
+
export const WORKER_OP_TOOLS: Record<WorkerOp, readonly string[]> = {
|
|
2091
|
+
run: ["read", "bash", "edit", "write"],
|
|
2092
|
+
verify: ["read", "bash"],
|
|
2093
|
+
reflect: ["read", "bash"],
|
|
2094
|
+
status: [],
|
|
2095
|
+
};
|
|
2096
|
+
|
|
2097
|
+
/** Op legality, judged on the bound flow's live state: null = legal, string = the tool's refusal.
|
|
2098
|
+
* `verify` is scoped to implement — it is that stage's own independent proof, while pre-release
|
|
2099
|
+
* already has its review (`/flow-review`) and release/finish carry checkpoint words. `reflect` runs
|
|
2100
|
+
* once the release is recorded and before `flow finish` deletes the flow dir. Gates stay
|
|
2101
|
+
* undelegable: a verify worker's PASS is an INPUT the gate demands, never a gate the worker runs. */
|
|
2102
|
+
export function workerOpError(op: WorkerOp, st: { stage: Stage; approvals: Record<string, string> }): string | null {
|
|
2103
|
+
if (op === "verify" && st.stage !== "implement")
|
|
2104
|
+
return `a verify worker runs only while the feature is at implement (stage is "${st.stage}") — it proves the implement work before Verified?; pre-release review is the playbook's review command, and release/finish carry checkpoint words`;
|
|
2105
|
+
if (op === "reflect" && !(st.stage === "release" && st.approvals.release))
|
|
2106
|
+
return `a reflect worker runs at the release stage after release-done recorded the release (stage is "${st.stage}"${st.approvals.release ? "" : ", no release recorded"}) — it reviews the finished flow before flow finish deletes .dev-flow/<slug>/`;
|
|
2107
|
+
return null;
|
|
2108
|
+
}
|
|
2109
|
+
|
|
2110
|
+
/** Sentinel line that ends a verify worker's final message — the sibling of STAGE_REPORT_HEAD. The
|
|
2111
|
+
* verdict is machine-read: it is what the verify gate demands, so prose approval is never enough. */
|
|
2112
|
+
export const VERIFY_REPORT_HEAD = "VERIFY REPORT";
|
|
2113
|
+
|
|
2114
|
+
/** The verify worker's closing contract. `verdict` is a closed set on purpose: anything the parser
|
|
2115
|
+
* cannot read as pass/fail is treated as NO pass, so a hedged report never stamps the gate. */
|
|
2116
|
+
export const VERIFY_REPORT_CONTRACT = `Close your final message with exactly this block (empty sections say \`none\`):
|
|
2117
|
+
${VERIFY_REPORT_HEAD}
|
|
2118
|
+
verdict: pass | fail
|
|
2119
|
+
findings:
|
|
2120
|
+
- <one line per problem: what the plan requires, what the code does instead, file:line>
|
|
2121
|
+
evidence:
|
|
2122
|
+
- <one line per thing you ran: the command and what it printed>`;
|
|
2123
|
+
|
|
2124
|
+
export interface VerifyReport {
|
|
2125
|
+
/** null = no readable verdict (missing block, or a hedge where pass|fail was demanded). */
|
|
2126
|
+
verdict: "pass" | "fail" | null;
|
|
2127
|
+
findings: string[];
|
|
2128
|
+
evidence: string[];
|
|
2129
|
+
/** true when the worker never emitted the block. */
|
|
2130
|
+
missing: boolean;
|
|
2131
|
+
rawTail: string;
|
|
2132
|
+
}
|
|
2133
|
+
|
|
2134
|
+
/** Digest a verify worker's final message. A missing block or an unreadable verdict is a NON-pass —
|
|
2135
|
+
* the caller must not stamp the gate on anything it did not read. */
|
|
2136
|
+
export function parseVerifyReport(text: string): VerifyReport {
|
|
2137
|
+
const lines = (text ?? "").split("\n");
|
|
2138
|
+
let start = -1;
|
|
2139
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
2140
|
+
if (/^\s*[*_#>\s]*VERIFY\s+REPORT[*_\s]*$/i.test(lines[i])) { start = i; break; }
|
|
2141
|
+
}
|
|
2142
|
+
const rep: VerifyReport = { verdict: null, findings: [], evidence: [], missing: start < 0, rawTail: lines.slice(-15).join("\n").slice(-600) };
|
|
2143
|
+
if (start < 0) return rep;
|
|
2144
|
+
type Section = "findings" | "evidence";
|
|
2145
|
+
let section: Section | null = null;
|
|
2146
|
+
for (const line of lines.slice(start + 1)) {
|
|
2147
|
+
const v = /^\s*verdict\s*[:=]\s*([A-Za-z]+)/i.exec(line.trim());
|
|
2148
|
+
if (v) {
|
|
2149
|
+
const word = v[1].toLowerCase();
|
|
2150
|
+
rep.verdict = word === "pass" || word === "passes" || word === "passed" ? "pass" : word === "fail" || word === "failed" || word === "failing" ? "fail" : null;
|
|
2151
|
+
continue;
|
|
2152
|
+
}
|
|
2153
|
+
const h = /^(findings|evidence)\s*[:=]\s*$/i.exec(line.trim());
|
|
2154
|
+
if (h) { section = h[1].toLowerCase() as Section; continue; }
|
|
2155
|
+
const b = /^\s*[-*]\s+(.+)$/.exec(line);
|
|
2156
|
+
if (b && section) rep[section].push(b[1].trim());
|
|
2157
|
+
}
|
|
2158
|
+
rep.findings = rep.findings.filter((f) => !/^(none|no findings?|n\/a|nothing)[-.\s]*$/i.test(f));
|
|
2159
|
+
return rep;
|
|
2160
|
+
}
|
|
2161
|
+
|
|
2162
|
+
/** Parent-facing digest of a verify run — bounded like the stage digest; the full transcript is on
|
|
2163
|
+
* disk and named by the caller. */
|
|
2164
|
+
export function renderVerifyReport(r: VerifyReport, cap = 4000): string {
|
|
2165
|
+
const parts: string[] = [];
|
|
2166
|
+
if (r.missing) parts.push("verify worker ended WITHOUT the VERIFY REPORT block — there is NO verdict, the tree is not verified:", "```", r.rawTail, "```");
|
|
2167
|
+
else if (!r.verdict) parts.push("VERIFY REPORT carried no readable verdict (pass | fail was required) — treated as NO pass:", "```", r.rawTail, "```");
|
|
2168
|
+
else parts.push(`verdict: ${r.verdict.toUpperCase()}`);
|
|
2169
|
+
if (r.findings.length) parts.push("findings:", ...r.findings.map((x) => `- ${x}`));
|
|
2170
|
+
if (r.evidence.length) parts.push("evidence:", ...r.evidence.map((x) => `- ${x}`));
|
|
2171
|
+
if (!parts.length) parts.push("(report block was empty)");
|
|
2172
|
+
const out = parts.join("\n");
|
|
2173
|
+
return out.length <= cap ? out : `${out.slice(0, cap)}\n…(digest truncated — full worker transcript on disk)`;
|
|
2174
|
+
}
|
|
2175
|
+
|
|
2176
|
+
/** Key the verify-worker PASS rides under inside state.checks. Living there is not a shortcut, it is
|
|
2177
|
+
* the point: the PASS must die exactly when a tier-1 record dies (an edit-tool clear, a fingerprint
|
|
2178
|
+
* that moved), so the friction is precise — one edit, one re-run — and never sticky. */
|
|
2179
|
+
export const VERIFY_STAMP = "verify";
|
|
2180
|
+
|
|
2181
|
+
/** Stamp a PASS over the tree as it is now (fp = worktreeFingerprint; null = git could not answer,
|
|
2182
|
+
* and an unprovable stamp is a stamp that never looks stale — same rule as freshenChecks). */
|
|
2183
|
+
export function recordVerifyPass(state: FlowState, at: string, fp: string | null): void {
|
|
2184
|
+
state.checks[VERIFY_STAMP] = { ok: true, at, ...(fp ? { wt: fp } : {}) };
|
|
2185
|
+
}
|
|
2186
|
+
|
|
2187
|
+
/** How each op's session announces itself in the picker — the stage-line glyph vocabulary reused for
|
|
2188
|
+
* worker names, so a row reads as a role at a glance instead of N identical "stage worker" lines. */
|
|
2189
|
+
export const WORKER_OP_GLYPH: Record<WorkerOp, string> = { run: "🔨", verify: "🔍", reflect: "🏁", status: "👁" };
|
|
2190
|
+
|
|
2191
|
+
/** A driver-supplied purpose, made safe for a session name: control chars gone, whitespace collapsed,
|
|
2192
|
+
* clamped to ~32 chars on a word boundary. "" when nothing meaningful is left. */
|
|
2193
|
+
export function sanitizeWorkerLabel(raw: string): string {
|
|
2194
|
+
const s = raw.replace(/[\x00-\x1f\x7f]/g, " ").replace(/\s+/g, " ").trim();
|
|
2195
|
+
if (s.length <= 32) return s;
|
|
2196
|
+
const cut = s.slice(0, 32);
|
|
2197
|
+
const at = cut.lastIndexOf(" ");
|
|
2198
|
+
return (at >= 16 ? cut.slice(0, at) : cut).trim();
|
|
2199
|
+
}
|
|
2200
|
+
|
|
2201
|
+
/** Session-name grammar: live `⏳ 🔨 #2 · wire ops`, done `✓ 🔨 #2 · 3 commits · wire ops`,
|
|
2202
|
+
* `✓ 🔍 · stamp attack · PASS`, `✗ 🔨 #3 · hard-cut`. The final rename answers "how did it end?"
|
|
2203
|
+
* without opening the row; the ordinal separates re-delegations when no label was given. */
|
|
2204
|
+
export function workerName(mark: string, glyph: string, seq: number | null, label: string, outcome?: string | null): string {
|
|
2205
|
+
const core = `${glyph}${seq ? ` #${seq}` : ""}${outcome ? ` · ${outcome}` : ""}${label ? ` · ${label}` : ""}`;
|
|
2206
|
+
return `${mark} ${core}`;
|
|
2207
|
+
}
|
|
2208
|
+
|
|
2209
|
+
/** Content hash of a feature's plan/ dir (sorted relpath + bytes; "" stable when absent). The verify
|
|
2210
|
+
* verdict was written AGAINST the plan, so a mid-stage plan edit must void the PASS exactly like a
|
|
2211
|
+
* worktree edit — the stamp fingerprint hashes the worktree TOGETHER WITH this. */
|
|
2212
|
+
export function planFingerprint(dir: string): string {
|
|
2213
|
+
const h = createHash("sha256");
|
|
2214
|
+
// absent and empty must not collide — an accidentally deleted plan dir is a different ground than an emptied one
|
|
2215
|
+
h.update(existsSync(dir) ? "present\0" : "absent\0");
|
|
2216
|
+
const walk = (d: string, rel: string) => {
|
|
2217
|
+
// the entry kind rides as a control char after the name — a text marker ("@link") would collide
|
|
2218
|
+
// with a real file literally named that, control chars in a name are the pathological remainder
|
|
2219
|
+
for (const e of readdirSync(d, { withFileTypes: true }).sort((a, b) => (a.name < b.name ? -1 : 1))) {
|
|
2220
|
+
const p = path.join(d, e.name);
|
|
2221
|
+
if (e.isDirectory()) {
|
|
2222
|
+
h.update(`${rel}${e.name}\x01`);
|
|
2223
|
+
walk(p, `${rel}${e.name}/`);
|
|
2224
|
+
} else if (e.isSymbolicLink()) {
|
|
2225
|
+
// a symlinked plan hides its content behind the entry — hash the link AND what it resolves to
|
|
2226
|
+
h.update(`${rel}${e.name}\x02`).update(readlinkSync(p));
|
|
2227
|
+
try {
|
|
2228
|
+
h.update(readFileSync(p));
|
|
2229
|
+
} catch {
|
|
2230
|
+
/* dangling link: the target string is all there is */
|
|
2231
|
+
}
|
|
2232
|
+
} else if (e.isFile()) h.update(`${rel}${e.name}\x00`).update(readFileSync(p));
|
|
2233
|
+
else h.update(`${rel}${e.name}\x03`);
|
|
2234
|
+
}
|
|
2235
|
+
};
|
|
2236
|
+
if (existsSync(dir)) walk(dir, "");
|
|
2237
|
+
return h.digest("hex").slice(0, 16);
|
|
2238
|
+
}
|
|
2239
|
+
|
|
2240
|
+
/** A PASS the verify gate may accept? docs-mode flows are exempt exactly like tier-1 checks: a docs
|
|
2241
|
+
* flow runs no project command, so there is nothing for a checker to check beyond the operator. */
|
|
2242
|
+
export function verifyStampMissing(state: FlowState): boolean {
|
|
2243
|
+
if (state.docs) return false;
|
|
2244
|
+
return !state.checks[VERIFY_STAMP]?.ok;
|
|
2245
|
+
}
|
|
2246
|
+
|
|
2247
|
+
/** The verify gate's refusal line for a missing PASS — printed with the demand spelled out, because
|
|
2248
|
+
* the operator's question must never be asked on a tree nothing independent has looked at. */
|
|
2249
|
+
export const VERIFY_STAMP_REFUSAL = `no verify-worker PASS on this tree — run flow_stage { op: "verify" } and get its verdict: pass before asking Verified? (the PASS belongs to the tree it was read on: any worktree edit drops it like any tier-1 record; a docs flow is exempt)`;
|
|
2250
|
+
|
|
2251
|
+
/** The durable worker index inside .dev-flow/<slug>/stage-sessions/ — one line per finished worker. */
|
|
2252
|
+
export const TRANSCRIPTS_FILE = "transcripts.log";
|
|
2253
|
+
|
|
2254
|
+
/** `worker transcript: …` line appended to .dev-flow/<slug>/stage-sessions/transcripts.log — the
|
|
2255
|
+
* durable index the reflect worker reads (until now a transcript path lived only in the parent's
|
|
2256
|
+
* tool result, i.e. only as long as that session's context). */
|
|
2257
|
+
export function workerTranscriptLine(at: string, op: string, file: string): string {
|
|
2258
|
+
return `[${at}] worker transcript (${op}): ${file}`;
|
|
2259
|
+
}
|
|
2260
|
+
|
|
2261
|
+
/** Parse transcripts.log back into entries; anything unrecognised is skipped, the log is append-only
|
|
2262
|
+
* and hand-editable. Missing files are the caller's problem (a stale path still tells a reader a
|
|
2263
|
+
* worker ran). */
|
|
2264
|
+
export function parseWorkerTranscripts(text: string): { at: string; op: string; path: string }[] {
|
|
2265
|
+
const out: { at: string; op: string; path: string }[] = [];
|
|
2266
|
+
for (const line of (text ?? "").split("\n")) {
|
|
2267
|
+
const m = /^\s*\[(.*?)\]\s*worker transcript(?: \(([^)]*)\))?:\s*(\S+)/.exec(line);
|
|
2268
|
+
if (m) out.push({ at: m[1], op: m[2] ?? "run", path: m[3] });
|
|
2269
|
+
}
|
|
2270
|
+
return out;
|
|
2271
|
+
}
|
|
2272
|
+
|
|
2273
|
+
/** How many live lines the card and `op: "status"` show: enough to see what the worker is doing,
|
|
2274
|
+
* bounded so a long stage never spends the context the delegation just saved (R6). */
|
|
2275
|
+
export const LIVE_TAIL_ITEMS = 8;
|
|
2276
|
+
/** One live line's cap — worker output is signal in a tail, noise in bulk. */
|
|
2277
|
+
const LIVE_LINE_CAP = 110;
|
|
2278
|
+
|
|
2279
|
+
/** One line of a worker's assistant prose, for the live tail: last non-empty line only (a worker
|
|
2280
|
+
* narrating a plan would otherwise drown its own tool activity). */
|
|
2281
|
+
export function stageLiveAssistantLine(elapsedMs: number, text: string): string {
|
|
2282
|
+
const lines = (text ?? "").split("\n").map((l) => l.trim()).filter(Boolean);
|
|
2283
|
+
if (!lines.length) return "";
|
|
2284
|
+
// its own shape, not stageLiveLine's: prose is not `tool — args`, an em dash in front of every
|
|
2285
|
+
// sentence the worker wrote would read as a tool call that happened to talk
|
|
2286
|
+
return `[+${stageElapsedLabel(elapsedMs)}] ✎ ${liveClip(lines[lines.length - 1])}`;
|
|
2287
|
+
}
|
|
2288
|
+
/** A finished tool call: ✓/✗ plus one line of what came back — the difference between "it is running"
|
|
2289
|
+
* and "it is getting somewhere". */
|
|
2290
|
+
export function stageLiveResultLine(elapsedMs: number, toolName: string, ok: boolean, summary: string): string {
|
|
2291
|
+
return stageLiveLine(elapsedMs, `${ok ? "✓" : "✗"} ${toolName}`, liveClip(summary));
|
|
2292
|
+
}
|
|
2293
|
+
|
|
2294
|
+
|
|
2295
|
+
export function liveClip(s: string, cap = LIVE_LINE_CAP): string {
|
|
2296
|
+
const one = (s ?? "").replace(/\s+/g, " ").trim();
|
|
2297
|
+
return one.length > cap ? `${one.slice(0, cap - 1)}…` : one;
|
|
2298
|
+
}
|
|
2299
|
+
|
|
2300
|
+
/** The bounded tail: `… M earlier items` then the last `max` lines (empty lines never counted —
|
|
2301
|
+
* a skipped assistant narration must not push real activity off the card). */
|
|
2302
|
+
export function liveTail(lines: string[], max = LIVE_TAIL_ITEMS): string[] {
|
|
2303
|
+
const kept = lines.filter(Boolean);
|
|
2304
|
+
if (kept.length <= max) return kept;
|
|
2305
|
+
return [`… ${kept.length - max} earlier items`, ...kept.slice(-max)];
|
|
2306
|
+
}
|
|
2307
|
+
|
|
2308
|
+
|
|
2309
|
+
/** Everything the live tool card needs to draw one frame. The card is the guaranteed visibility
|
|
2310
|
+
* surface (it renders in the driver's own transcript on every host), so it is built from plain
|
|
2311
|
+
* strings here and wrapped into components by the extension — the same lines reach a host that only
|
|
2312
|
+
* shows the update's text (pi-web) and the no-UI fallback `op: "status"`. */
|
|
2313
|
+
export interface StageCardView {
|
|
2314
|
+
kind: string;
|
|
2315
|
+
slug: string;
|
|
2316
|
+
elapsedMs: number;
|
|
2317
|
+
budgetMin: number;
|
|
2318
|
+
softFired?: boolean;
|
|
2319
|
+
tail?: string[];
|
|
2320
|
+
usage?: string;
|
|
2321
|
+
state?: "running" | "done" | "failed";
|
|
2322
|
+
verdict?: "pass" | "fail" | null;
|
|
2323
|
+
note?: string;
|
|
2324
|
+
transcript?: string;
|
|
2325
|
+
}
|
|
2326
|
+
|
|
2327
|
+
/** One frame of the worker card: header (what · where · clock against budget), the bounded live tail,
|
|
2328
|
+
* the verdict once there is one, and what it cost. Expanded widens the tail and names the transcript. */
|
|
2329
|
+
export function stageCardLines(v: StageCardView, expanded = false): string[] {
|
|
2330
|
+
const glyph = v.state === "failed" ? "✗" : v.state === "done" ? "✓" : "⏳";
|
|
2331
|
+
const out = [`${glyph} ${v.kind} · ${v.slug} · ${stageElapsedLabel(v.elapsedMs)}/${v.budgetMin}m${v.softFired ? " · closing out" : ""}`];
|
|
2332
|
+
if (v.note) out.push(`note: ${liveClip(v.note, 80)}`);
|
|
2333
|
+
out.push(...liveTail(v.tail ?? [], expanded ? LIVE_TAIL_ITEMS * 4 : LIVE_TAIL_ITEMS));
|
|
2334
|
+
if (v.verdict) out.push(`verdict: ${v.verdict.toUpperCase()}`);
|
|
2335
|
+
if (v.usage) out.push(v.usage);
|
|
2336
|
+
if (expanded && v.transcript) out.push(`transcript: ${v.transcript}`);
|
|
2337
|
+
return out;
|
|
2338
|
+
}
|
|
2339
|
+
|
|
2340
|
+
/** What the tool accumulated from a worker's assistant usage records. */
|
|
2341
|
+
export interface StageUsage {
|
|
2342
|
+
input: number;
|
|
2343
|
+
output: number;
|
|
2344
|
+
cacheRead: number;
|
|
2345
|
+
cacheWrite: number;
|
|
2346
|
+
totalTokens: number;
|
|
2347
|
+
cost: { input: number; output: number; cacheRead: number; cacheWrite: number; total: number };
|
|
2348
|
+
}
|
|
2349
|
+
|
|
2350
|
+
/** One compact usage line for the card and the result: what the run cost, at a glance. */
|
|
2351
|
+
export function stageUsageLine(u: StageUsage, turns?: number): string {
|
|
2352
|
+
const k = (n: number) => (n >= 1000 ? `${(n / 1000).toFixed(n >= 100_000 ? 0 : 1)}k` : String(n));
|
|
2353
|
+
const ctx = u.cacheRead + u.input + u.output;
|
|
2354
|
+
return `${turns ? `${turns} turns · ` : ""}↑${k(u.input)} ↓${k(u.output)} · ctx ${k(ctx)} · $${u.cost.total.toFixed(4)}`;
|
|
2355
|
+
}
|
|
2356
|
+
|
|
2357
|
+
export interface VerifyBriefInput {
|
|
2358
|
+
slug: string;
|
|
2359
|
+
/** absolute path of the feature worktree — the reviewer's whole world. */
|
|
2360
|
+
workDir: string;
|
|
2361
|
+
/** absolute path of plan/plan.md in the main checkout. */
|
|
2362
|
+
planFile: string;
|
|
2363
|
+
statusJson: string;
|
|
2364
|
+
/** `git status --porcelain -b` in the worktree, before the run. */
|
|
2365
|
+
gitSummary: string;
|
|
2366
|
+
/** `git diff --stat <default>…HEAD` — the shape of what is under review; the reviewer reads the
|
|
2367
|
+
* full diff itself (pasting it here would spend the context the delegation saves). */
|
|
2368
|
+
diffStat: string;
|
|
2369
|
+
/** tier-1 commands the playbook says must be green (name + command). */
|
|
2370
|
+
checks: { name: string; cmd: string }[];
|
|
2371
|
+
/** the driver's default branch, for the diff range. */
|
|
2372
|
+
defaultBranch: string;
|
|
2373
|
+
note?: string;
|
|
2374
|
+
}
|
|
2375
|
+
|
|
2376
|
+
/** The verify worker's brief: judge, never fix. The tree-identity clause is what makes the stamp
|
|
2377
|
+
* honest — the tool proves the tree was untouched afterwards, so a PASS can only belong to the tree
|
|
2378
|
+
* the gate is about to approve. */
|
|
2379
|
+
export function buildVerifyBrief(i: VerifyBriefInput): string {
|
|
2380
|
+
const checks = i.checks.length ? i.checks.map((c) => `- ${c.name}: ${c.cmd}`).join("\n") : "- (the playbook names no tier-1 commands — judge against the plan and the diff)";
|
|
2381
|
+
return `You are a dev-flow VERIFY worker: an independent checker for feature "${i.slug}" at its implement stage. You did not write this code and you will not change it. The flow belongs to another session — gates, checkpoints and the operator conversation stay there; you owe one verdict.
|
|
2382
|
+
|
|
2383
|
+
Work only inside ${i.workDir} (the feature worktree, on its branch).
|
|
2384
|
+
|
|
2385
|
+
Standing order — CHECK, DON'T FIX:
|
|
2386
|
+
- You have read and bash only. Do not edit, write, format, commit, stash, or clean anything. The tool compares \`git status --porcelain\`, \`git rev-parse HEAD\` and \`git symbolic-ref HEAD\` before and after your run: if the tree, HEAD or the branch pointer moved at all, your verdict is VOID and the run is reported as a violation.
|
|
2387
|
+
- Running commands is allowed and expected (tests, build, the health probe, starting a throwaway process to read its output) — as long as nothing you run leaves the tree dirty. A command that rewrites tracked files is off-limits; say so in evidence instead.
|
|
2388
|
+
- Never run a flow gate or a flow verb, never ask the operator anything.
|
|
2389
|
+
|
|
2390
|
+
Read first: the plan — ${i.planFile} — then what the branch actually changed:
|
|
2391
|
+
\`git diff ${i.defaultBranch}…HEAD\` (stat now: ${i.diffStat || "(no stat)"})
|
|
2392
|
+
|
|
2393
|
+
Flow truth (\`flow status --json\` from the driving session):
|
|
2394
|
+
${i.statusJson}
|
|
2395
|
+
|
|
2396
|
+
Worktree state at your start (\`git status --porcelain -b\`):
|
|
2397
|
+
${i.gitSummary || "(clean)"}
|
|
2398
|
+
|
|
2399
|
+
|
|
2400
|
+
Tier-1 commands the playbook demands (run them yourself, do not trust the records):
|
|
2401
|
+
${checks}
|
|
2402
|
+
|
|
2403
|
+
Note from the driving session (what it already knows, what it is unsure of, what to look at hardest):
|
|
2404
|
+
${i.note?.trim() || "(none — the plan and the diff are your whole brief)"}
|
|
2405
|
+
Judge the diff against the plan, not against taste. Hunt for: plan items that were skipped or only half-done, behavior that contradicts the plan, missing or hollow tests for what changed, obvious bugs and unsafe paths, anything slow or wasteful under real use, leftover debug output, and docs that now lie. Report what you can prove; skip style preferences.
|
|
2406
|
+
|
|
2407
|
+
Close with the verdict block. verdict: pass ONLY if you found nothing that should stop this from going to the operator — a plan gap, a real bug, or a missing test is a fail. Put the reasoning in findings (with file:line) and what you ran in evidence; the driving session reads ONLY this block, so a finding you did not write down does not exist.
|
|
2408
|
+
${VERIFY_REPORT_CONTRACT}`;
|
|
2409
|
+
}
|
|
2410
|
+
|
|
2411
|
+
/** Findings contract for the reflect worker: tagged, one line each, machine-split so the driver can
|
|
2412
|
+
* print playbook items apart from plugin items without re-reading a whole run. */
|
|
2413
|
+
export const REFLECT_FINDINGS_CONTRACT = `Close your final message with exactly this block (empty sections say \`none\`):
|
|
2414
|
+
REFLECT FINDINGS
|
|
2415
|
+
[playbook] <one line — what this project's playbook (project.md / its references) should say differently> — evidence: <what you saw>
|
|
2416
|
+
[plugin] <one line — what dev-flow itself (a gate, guard, status, doc) should do differently> — evidence: <what you saw>
|
|
2417
|
+
(one line per finding, repeat the tag as many times as you have findings; prefix a line with [neither] when it is real but belongs to neither — the driver routes it by hand)`;
|
|
2418
|
+
|
|
2419
|
+
export interface ReflectFindings {
|
|
2420
|
+
playbook: string[];
|
|
2421
|
+
plugin: string[];
|
|
2422
|
+
other: string[];
|
|
2423
|
+
/** true when no tagged line was found at all — the reviewer produced prose, not findings. */
|
|
2424
|
+
missing: boolean;
|
|
2425
|
+
rawTail: string;
|
|
2426
|
+
}
|
|
2427
|
+
|
|
2428
|
+
/** Split a reflect worker's message into tagged findings. Bullets, bold and inline code around the
|
|
2429
|
+
* tag are tolerated: a model decorates, and re-parsing prose by hand in the driver is worse. */
|
|
2430
|
+
export function parseReflectFindings(text: string): ReflectFindings {
|
|
2431
|
+
const out: ReflectFindings = { playbook: [], plugin: [], other: [], missing: true, rawTail: (text ?? "").split("\n").slice(-15).join("\n").slice(-600) };
|
|
2432
|
+
|
|
2433
|
+
for (const line of (text ?? "").split("\n")) {
|
|
2434
|
+
// bracketed tag (the contract) or a bare `plugin:` lead-in; markdown decoration is noise around it
|
|
2435
|
+
const m = /^\s*(?:[-*>]\s*)?[*_`]*\s*\[\s*(playbook|plugin|neither|other)\s*\]\s*[*_`]*\s*(?:[:—-]\s*)?(.+)$|^\s*(?:[-*>]\s*)?[*_`]*\s*(playbook|plugin)\s*:\s*(.+)$/i.exec(line.trim());
|
|
2436
|
+
if (!m) continue;
|
|
2437
|
+
const body = (m[2] ?? m[4]).replace(/[*`\s]+$/, "").trim();
|
|
2438
|
+
if (!body || /^(none|n\/a|nothing)[-.\s]*$/i.test(body)) continue;
|
|
2439
|
+
const kind = (m[1] ?? m[3]).toLowerCase();
|
|
2440
|
+
if (kind === "playbook") out.playbook.push(body);
|
|
2441
|
+
else if (kind === "plugin") out.plugin.push(body);
|
|
2442
|
+
else out.other.push(body);
|
|
2443
|
+
}
|
|
2444
|
+
out.missing = !out.playbook.length && !out.plugin.length && !out.other.length;
|
|
2445
|
+
return out;
|
|
2446
|
+
}
|
|
2447
|
+
|
|
2448
|
+
export interface ReflectBriefInput {
|
|
2449
|
+
slug: string;
|
|
2450
|
+
planFile: string;
|
|
2451
|
+
statusJson: string;
|
|
2452
|
+
/** The driver's own session file (JSONL) — pre-compaction turns live there even after the driver's
|
|
2453
|
+
* context was summarized away, which is exactly what a finish review needs. */
|
|
2454
|
+
driverSession: string | null;
|
|
2455
|
+
/** Every worker transcript recorded in transcripts.log, oldest first. */
|
|
2456
|
+
transcripts: { at: string; op: string; path: string }[];
|
|
2457
|
+
/** Open reflection lines, so a finding already queued is not queued twice. */
|
|
2458
|
+
openReflections: string[];
|
|
2459
|
+
note?: string;
|
|
2460
|
+
}
|
|
2461
|
+
|
|
2462
|
+
/** The reflect worker's brief: an independent reviewer of the WHOLE flow — driver included. It
|
|
2463
|
+
* cannot ask the operator anything and cannot write, so it returns tagged findings the driver puts to
|
|
2464
|
+
* the operator (fold / fix / drop stays the operator's call, as always). */
|
|
2465
|
+
export function buildReflectBrief(i: ReflectBriefInput): string {
|
|
2466
|
+
const tlist = i.transcripts.length
|
|
2467
|
+
? i.transcripts.map((t) => `- ${t.op} worker (${t.at}): ${t.path}${existsSync(t.path) ? "" : " (file is gone — note it, do not invent it)"}`).join("\n")
|
|
2468
|
+
: "- (this flow delegated nothing — review the driver session alone)";
|
|
2469
|
+
const open = i.openReflections.length ? i.openReflections.map((l) => `- ${l}`).join("\n") : "- none";
|
|
2470
|
+
return `You are a dev-flow REFLECT worker: an independent reviewer of the finished flow "${i.slug}". You review the DRIVER session — the session that drove the flow — plus every worker it delegated, and you report what the process should learn. You are not the driver, so nothing here is defensive: name the wasted turn, the gate that misfired, the playbook line that lied.
|
|
2471
|
+
|
|
2472
|
+
Standing order — read-only: read and bash only. Never edit, write, commit, push, run a flow gate, or ask the operator anything. Reading git logs and files through bash is expected.
|
|
2473
|
+
|
|
2474
|
+
Read the whole flow, in this order:
|
|
2475
|
+
1. the driver's own session transcript: ${i.driverSession ?? "(the driver's session file was not resolvable — review from the transcripts below and say so in your findings)"}
|
|
2476
|
+
(a JSONL of every message, tool call and result. If it is large, read it in chunks and follow the turns, not the file.)
|
|
2477
|
+
2. every worker the flow delegated:
|
|
2478
|
+
${tlist}
|
|
2479
|
+
3. the plan the flow was held to: ${i.planFile}
|
|
2480
|
+
4. how the flow ended (\`flow status --json\` of the driving session):
|
|
2481
|
+
${i.statusJson}
|
|
2482
|
+
|
|
2483
|
+
Then run the reflection itself, over what you read (this is the same protocol \`flow reflect\` prints, applied to the transcripts):
|
|
2484
|
+
1. every turn of the flow: friction, wrong turns, repeated failures, guards or gates that misfired or confused the agent, playbook drift, dead weight the flow added but never used. A finding must cite what happened — "the verify gate refused twice for X, the driver wasted N turns guessing why" is a finding; "the flow was slow" is not.
|
|
2485
|
+
2. classify each one: [playbook] = this project's own playbook/references/checklist wording should change; [plugin] = dev-flow itself (a gate, a guard, status, a doc) should change.
|
|
2486
|
+
3. dedupe against the open queue below — never report the same issue twice; if an open item already covers it, say "already queued: <item>" instead of a new finding.
|
|
2487
|
+
|
|
2488
|
+
Open reflection queue (already filed):
|
|
2489
|
+
${open}
|
|
2490
|
+
|
|
2491
|
+
${i.note?.trim() ? `Note from the driver (context you cannot read elsewhere):\n${i.note.trim()}\n` : ""}
|
|
2492
|
+
${REFLECT_FINDINGS_CONTRACT}`;
|
|
2493
|
+
}
|