pi-dev-flow 0.74.0 → 0.75.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 CHANGED
@@ -4,6 +4,13 @@ Format: newest first. `Unreleased` collects what's merged but not yet tagged.
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [0.75.0] - 2026-11-03
8
+
9
+ **`flow_stage` workers are now visible in pi-web.** A delegated worker used to be a session pi-web never mentioned — the operator watched the driving session go quiet.
10
+
11
+ ### Added
12
+ - `flow_stage` workers register themselves as pi-web subagents: the worker's session file carries the `pi-web:subagent` meta where pi-web's scanner looks for it (first data entry) and a terminal result when the run ends, so the worker appears in the session's Agents menu under profile `flow-implement` / `flow-review` — ✓ with its REPORT, ✗ failed, or interrupted. The row settles when the run ends; while it runs pi-web displays it as interrupted, because only pi-web's own sessions can prove liveness. Plain pi is unchanged, and a stamp that cannot write never breaks a worker.
13
+
7
14
  ## [0.74.0] - 2026-11-03
8
15
 
9
16
  **Audit: gaps closed, dead code out.** A full read of the extension, core and playbook parser after 0.73.0's reset.
package/README.md CHANGED
@@ -185,7 +185,9 @@ tests as contract, and a structural-vs-cheap self-audit so the diff shrank becau
185
185
  got smaller, not because comments got deleted. For a big implement slice the session can hand
186
186
  the work to **`flow_stage`**: a fresh pi session in the worktree that edits, commits and reports,
187
187
  or a fresh read-only reviewer (`op: "review"`) whose PASS/FAIL is advice, not a gate. Both are
188
- optional, and the plan path, commits and checks are briefed automatically. And while a flow writes code, the
188
+ optional, and the plan path, commits and checks are briefed automatically. In pi-web a worker also
189
+ shows up in the session's Agents menu as a subagent, its final status on the row and its report in
190
+ the opened transcript. And while a flow writes code, the
189
191
  implement stage injects a compact senior-discipline guidance — smallest complete change, no
190
192
  speculative abstraction, finish what your change breaks, a failing-first test for risky logic —
191
193
  your playbook's `prose.implement` replaces it wholesale whenever you write your own. (The review
@@ -206,7 +206,7 @@ function copyWarning(): string | null {
206
206
  }
207
207
  /** Test seam: the smoke suite cannot load a second copy of this module, so it plants registry
208
208
  * entries and asserts the warnings the real duplicate would print. */
209
- export const testSeams = { copies: COPIES, skillCore: { value: undefined as string | null | undefined } };
209
+ export const testSeams = { copies: COPIES, skillCore: { value: undefined as string | null | undefined }, piweb: { meta: piwebWorkerMeta, stamp: piwebStamp } };
210
210
 
211
211
  interface Ui {
212
212
  hasUI: boolean;
@@ -1914,14 +1914,58 @@ const workerSessions = new Set<string>();
1914
1914
  /** Toolset per worker op: an implementer codes, a reviewer reads and runs commands only. */
1915
1915
  const WORKER_TOOLS: Record<WorkerOp, string[]> = { implement: ["read", "bash", "edit", "write"], review: ["read", "bash"] };
1916
1916
 
1917
+ /** What makes a worker show up in pi-web's Agents menu: pi-web classifies a subagent from the
1918
+ * custom entries its own runtime writes into the child's session file (pi-web lib/subagents.ts
1919
+ * readSubagentRun, fed by lib/session-reader.ts). Two placement rules the reader enforces:
1920
+ * the meta entry must be the file's FIRST data entry (the scanner reads header + one line and
1921
+ * calls anything else a fork), and a persisted `running` the host cannot prove live displays as
1922
+ * `interrupted` — so the final result entry is what the menu really rests on.
1923
+ * Unknown entry types are inert in plain pi, so stamping is unconditional. */
1924
+ const PIWEB_SUBAGENT = { meta: "pi-web:subagent", status: "pi-web:subagent-status", result: "pi-web:subagent-result" } as const;
1925
+
1926
+ interface WorkerSubagentMeta {
1927
+ parentId: string;
1928
+ parentFile: string;
1929
+ toolCallId: string;
1930
+ profile: string;
1931
+ description: string;
1932
+ task: string;
1933
+ }
1934
+
1935
+ /** Only version 1 + the two lineage strings are hard-validated by pi-web's reader; the rest is
1936
+ * display. resourceSnapshot is deliberately absent: its presence pins the tool set strictly when
1937
+ * pi-web reopens the child, and these workers are never resumed by pi-web. */
1938
+ function piwebWorkerMeta(m: WorkerSubagentMeta): Record<string, unknown> {
1939
+ return {
1940
+ version: 1,
1941
+ parentSessionId: m.parentId,
1942
+ parentSessionPath: m.parentFile,
1943
+ parentToolCallId: m.toolCallId,
1944
+ profile: m.profile,
1945
+ description: m.description,
1946
+ task: m.task,
1947
+ runInBackground: false,
1948
+ createdAt: now(),
1949
+ };
1950
+ }
1951
+
1952
+ /** Best-effort by contract: a stamp that will not write must never break the worker run —
1953
+ * visibility, not function (same rule as the worker's setSessionName renames). */
1954
+ function piwebStamp(target: { appendCustomEntry?(customType: string, data?: unknown): unknown } | undefined, customType: string, data: unknown): void {
1955
+ try { target?.appendCustomEntry?.(customType, data); } catch { /* visibility only */ }
1956
+ }
1957
+
1917
1958
  /** Seam that spawns a worker as a real pi session — tests replace `.run`. With the driver's session
1918
1959
  * file and directory known, the worker's header links back to the driver (`parentSession`), so pi's
1919
- * picker nests it under the driver. */
1920
- export const stageWorkerSpawn: { run: (o: { work: string; model: unknown; name: string; tools: string[]; parent?: string; dir?: string }) => Promise<AgentSession> } = {
1921
- run: async ({ work, model, name, tools, parent, dir }) => {
1960
+ * picker nests it under the driver, and the pi-web meta lands as the file's first data entry. */
1961
+ export const stageWorkerSpawn: { run: (o: { work: string; model: unknown; name: string; tools: string[]; parent?: string; dir?: string; subagent?: WorkerSubagentMeta }) => Promise<AgentSession> } = {
1962
+ run: async ({ work, model, name, tools, parent, dir, subagent }) => {
1922
1963
  const loader = new DefaultResourceLoader({ cwd: work, agentDir: getAgentDir() });
1923
1964
  await loader.reload();
1924
1965
  const sessionManager = parent && dir ? SessionManager.create(work, dir, { parentSession: parent }) : undefined;
1966
+ // The meta must be stamped here — before createAgentSession appends model_change/session_info,
1967
+ // because pi-web's scanner classifies the child only from the first data entry after the header.
1968
+ if (sessionManager && subagent) piwebStamp(sessionManager, PIWEB_SUBAGENT.meta, piwebWorkerMeta(subagent));
1925
1969
  const { session } = await createAgentSession({ cwd: work, model: model as never, tools, excludeTools: ["flow", "flow_stage"], resourceLoader: loader, sessionManager });
1926
1970
  try { workerSessions.add(session.sessionManager.getSessionId()); } catch { /* an id-less session just gets the default context */ }
1927
1971
  try { session.setSessionName(name); } catch { /* naming is visibility, not function */ }
@@ -2120,15 +2164,15 @@ export default function devFlow(pi: ExtensionAPI) {
2120
2164
  name: "flow_stage",
2121
2165
  label: "Stage worker",
2122
2166
  description:
2123
- 'Optional: hand a slice of work to a fresh pi session so this conversation stays lean. op "implement" (stage implement) — the worker edits and commits a slice on the feature branch; op "review" (implement or pre-release) — a fresh read-only reviewer that returns findings and a PASS/FAIL verdict (advisory: no gate depends on it). The plan path, branch, commits so far and the project checks are added to the brief automatically — `note` is just the slice: what to do, operator answers and decisions the worker cannot see. The worker holds no flow tool; gates and checkpoints stay with you. Small work and small fixes are fine to do inline.',
2124
- promptSnippet: 'flow_stage(op: "implement"|"review", note, label?) — optional fresh-session worker for a big implement slice, or an independent review; gates stay with you',
2167
+ 'Optional: hand a slice of work to a fresh pi session so this conversation stays lean. op "implement" (stage implement) — the worker edits and commits a slice on the feature branch; op "review" (implement or pre-release) — a fresh read-only reviewer that returns findings and a PASS/FAIL verdict (advisory: no gate depends on it). The plan path, branch, commits so far and the project checks are added to the brief automatically — `note` is just the slice: what to do, operator answers and decisions the worker cannot see. The worker holds no flow tool; gates and checkpoints stay with you. Small work and small fixes are fine to do inline. In pi-web the worker appears in the session\'s Agents menu as a subagent; the row carries its final status, the opened transcript its report.',
2168
+ promptSnippet: 'flow_stage(op: "implement"|"review", note, label?) — optional fresh-session worker for a big implement slice, or an independent review; gates stay with you; in pi-web workers show up as subagents in the Agents menu',
2125
2169
  parameters: Type.Object({
2126
2170
  op: Type.String({ description: '"implement" (a worker edits + commits a slice) or "review" (read-only reviewer, findings + verdict)' }),
2127
2171
  note: Type.String({ description: "The slice: what to do and anything from this conversation the worker must know (operator answers, decisions). Facts (plan path, commits, checks) are added for you." }),
2128
2172
  label: Type.Optional(Type.String({ description: "A few words naming this delegation, shown in the worker's session name." })),
2129
2173
  budgetMin: Type.Optional(Type.Number({ description: "Wall-clock budget in minutes (5-180; default 60 implement, 30 review). Past it the worker is interrupted." })),
2130
2174
  }),
2131
- execute: async (_id, params, signal, onUpdate, ctx) => {
2175
+ execute: async (id, params, signal, onUpdate, ctx) => {
2132
2176
  const err = (text: string) => ({ content: [{ type: "text" as const, text }], details: undefined, isError: true });
2133
2177
  const op = String(params.op ?? "").trim().toLowerCase();
2134
2178
  const root = await flowRoot(ctx.cwd);
@@ -2160,8 +2204,11 @@ export default function devFlow(pi: ExtensionAPI) {
2160
2204
  checks: cfg.checkList.map((c) => ({ name: c.name, command: c.cmd })),
2161
2205
  note: String(params.note ?? ""),
2162
2206
  });
2163
- let lineage: { file?: string; dir?: string } = {};
2164
- try { lineage = { file: ctx.sessionManager.getSessionFile() ?? undefined, dir: ctx.sessionManager.getSessionDir() ?? undefined }; } catch { /* unbacked driver: the worker is unlinked */ }
2207
+ let lineage: { id?: string; file?: string; dir?: string } = {};
2208
+ try { lineage = { id: ctx.sessionManager.getSessionId(), file: ctx.sessionManager.getSessionFile() ?? undefined, dir: ctx.sessionManager.getSessionDir() ?? undefined }; } catch { /* unbacked driver: the worker is unlinked */ }
2209
+ // pi-web visibility needs both halves of the lineage: the id the Agents menu links the child
2210
+ // to, the file the parentSession header points at — without either the worker stays unlinked.
2211
+ const subagent = !lineage.id || !lineage.file ? undefined : { parentId: lineage.id, parentFile: lineage.file, toolCallId: id, profile: `flow-${wop}`, description: name, task: brief };
2165
2212
  let child: AgentSession | undefined;
2166
2213
  let timedOut = false;
2167
2214
  let crash: string | null = null;
@@ -2172,7 +2219,8 @@ export default function devFlow(pi: ExtensionAPI) {
2172
2219
  signal?.addEventListener("abort", abortChild);
2173
2220
  let unsub: (() => void) | undefined;
2174
2221
  try {
2175
- child = await stageWorkerSpawn.run({ work, model: ctx.model, name: `⏳ ${name}`, tools: WORKER_TOOLS[wop], parent: lineage.file, dir: lineage.dir });
2222
+ child = await stageWorkerSpawn.run({ work, model: ctx.model, name: `⏳ ${name}`, tools: WORKER_TOOLS[wop], parent: lineage.file, dir: lineage.dir, subagent });
2223
+ if (subagent) piwebStamp(child.sessionManager, PIWEB_SUBAGENT.status, { version: 1, status: "running" });
2176
2224
  unsub = child.subscribe((ev: unknown) => {
2177
2225
  const e = ev as { type?: string; toolName?: string };
2178
2226
  if (e.type === "tool_execution_start") {
@@ -2201,8 +2249,20 @@ export default function devFlow(pi: ExtensionAPI) {
2201
2249
  const newCommits = headBefore && headAfter && headBefore !== headAfter ? await git(`git log --oneline ${sq(headBefore)}..HEAD`) : "";
2202
2250
  const dirty = (await git("git status --short")).trim();
2203
2251
  const outcome = crash ? `crashed: ${crash}` : timedOut ? `interrupted at the ${budgetMin}-min budget` : report.found ? "reported" : `ended without REPORT after ${nudges} nudge(s)`;
2252
+ // the terminal entry is what settles the Agents menu row (a persisted `running` the host
2253
+ // cannot prove live displays as `interrupted`); a no-REPORT run is a failure, not a ✓.
2254
+ if (subagent) {
2255
+ const doneAt = now();
2256
+ piwebStamp(child?.sessionManager, PIWEB_SUBAGENT.result, crash
2257
+ ? { version: 1, status: "failed", completedAt: doneAt, error: crash }
2258
+ : timedOut || signal?.aborted
2259
+ ? { version: 1, status: "aborted", completedAt: doneAt }
2260
+ : report.found
2261
+ ? { version: 1, status: "completed", completedAt: doneAt, result: report.body }
2262
+ : { version: 1, status: "failed", completedAt: doneAt, error: `ended without REPORT after ${nudges} nudge(s)`, result: report.body });
2263
+ }
2204
2264
  try { if (child) workerSessions.delete(child.sessionManager.getSessionId()); } catch { /* id-less session: nothing was registered */ }
2205
- try { child?.setSessionName(`${report.found && !crash && !timedOut ? "✓" : "✗"} ${name}${report.verdict ? ` · ${report.verdict}` : ""}`); } catch { /* visibility only */ }
2265
+ try { child?.setSessionName(`${report.found && !crash && !timedOut && !signal?.aborted ? "✓" : "✗"} ${name}${report.verdict ? ` · ${report.verdict}` : ""}`); } catch { /* visibility only */ }
2206
2266
  const parts = [
2207
2267
  `${glyph} ${wop} worker ${outcome} (${Math.round((Date.now() - started) / 60_000)} min)`,
2208
2268
  report.found ? `REPORT:\n${report.body.slice(0, 6000)}` : `no REPORT — last words:\n${report.body}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-dev-flow",
3
- "version": "0.74.0",
3
+ "version": "0.75.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": [