@juicesharp/rpiv-pi 2.4.0 → 2.5.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/README.md +6 -6
- package/docs/architecture.md +3 -3
- package/docs/skills.md +3 -1
- package/docs/workflows.md +8 -2
- package/extensions/rpiv-core/built-in-workflows.ts +277 -243
- package/extensions/rpiv-core/built-ins/index.ts +27 -0
- package/extensions/rpiv-core/built-ins/markdown-fence.ts +108 -0
- package/extensions/rpiv-core/built-ins/shared.ts +153 -0
- package/extensions/rpiv-core/lane-console.ts +9 -1
- package/extensions/rpiv-core/lane-list.ts +43 -6
- package/extensions/rpiv-core/lane-progress.ts +49 -4
- package/extensions/rpiv-core/pipeline-pointer.ts +1 -1
- package/extensions/rpiv-core/run-lane-registry.ts +46 -21
- package/package.json +3 -3
- package/skills/quick-plan/SKILL.md +165 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A fence-opening line: optional leading whitespace then 3+ backticks or 3+
|
|
3
|
+
* tildes (the CommonMark info-string delimiter). Single source of truth every
|
|
4
|
+
* fence-aware scan shares.
|
|
5
|
+
*/
|
|
6
|
+
const FENCE_LINE_RE = /^\s*(`{3,}|~{3,})/;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Whether `line` CLOSES the fence whose opener recorded `fenceChar` and
|
|
10
|
+
* `fenceLen`. CommonMark: a closing fence uses the SAME char (``` ``` ``` does not
|
|
11
|
+
* close `~~~`) and is at least as long (a 4-backtick opener needs 4+ to close),
|
|
12
|
+
* with only that char plus optional trailing whitespace on the line. `fence` is
|
|
13
|
+
* the current line's `RegExpExecArray` match (narrowed from the guarded
|
|
14
|
+
* `.exec()` result).
|
|
15
|
+
*/
|
|
16
|
+
const closesFence = (line: string, fence: RegExpExecArray, fenceChar: string, fenceLen: number): boolean => {
|
|
17
|
+
const len = fence[1].length;
|
|
18
|
+
return fence[1][0] === fenceChar && len >= fenceLen && line.trim().length === len;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Visit every line of `content` that sits OUTSIDE fenced code blocks, calling
|
|
23
|
+
* `visit(line, index)` with the line text and its 0-based index in
|
|
24
|
+
* `content.split("\n")`. A `## Phase N:` / `## Slice N:` / `### Phase N —` / a
|
|
25
|
+
* `#### N. path` inside a ``` or ~~~ fence is example/fixture text — a meta-plan
|
|
26
|
+
* (one whose subject is the pipeline) legitimately embeds the pipeline's own
|
|
27
|
+
* plan/slice fixtures — not a structural heading or declared write, so a naive
|
|
28
|
+
* line scan would false-count it. Mirrors the fence-aware boundary scan in
|
|
29
|
+
* skills/_shared/stitch-elaborations.mjs. Fence-opener and fence-closer lines
|
|
30
|
+
* are skipped (never visited); `index` advances once per line (including skipped
|
|
31
|
+
* fence lines) so it stays aligned with any caller's own `content.split("\n")`
|
|
32
|
+
* array.
|
|
33
|
+
*/
|
|
34
|
+
const forEachLineOutsideFences = (content: string, visit: (line: string, index: number) => void): void => {
|
|
35
|
+
let inFence = false;
|
|
36
|
+
let fenceLen = 0;
|
|
37
|
+
let fenceChar = "";
|
|
38
|
+
let index = 0;
|
|
39
|
+
for (const line of content.split("\n")) {
|
|
40
|
+
const fence = FENCE_LINE_RE.exec(line);
|
|
41
|
+
if (fence) {
|
|
42
|
+
if (!inFence) {
|
|
43
|
+
inFence = true;
|
|
44
|
+
fenceLen = fence[1].length;
|
|
45
|
+
fenceChar = fence[1][0];
|
|
46
|
+
} else if (closesFence(line, fence, fenceChar, fenceLen)) {
|
|
47
|
+
inFence = false;
|
|
48
|
+
fenceLen = 0;
|
|
49
|
+
fenceChar = "";
|
|
50
|
+
}
|
|
51
|
+
} else if (!inFence) {
|
|
52
|
+
visit(line, index);
|
|
53
|
+
}
|
|
54
|
+
index++;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Count lines matching `re` (a `^…` heading pattern) that sit OUTSIDE fenced code
|
|
60
|
+
* blocks. Fence-awareness lives on `forEachLineOutsideFences` (a naive `matchAll`
|
|
61
|
+
* counts fenced examples and false-throws the derived-array staleness guard);
|
|
62
|
+
* the per-line `lineRe` drops the source's `g`/`m` flags so `lastIndex` can't drift.
|
|
63
|
+
*/
|
|
64
|
+
const countHeadingsOutsideFences = (content: string, re: RegExp): number => {
|
|
65
|
+
const lineRe = new RegExp(re.source); // per-line test; drop g/m so lastIndex can't drift
|
|
66
|
+
let count = 0;
|
|
67
|
+
forEachLineOutsideFences(content, (line) => {
|
|
68
|
+
if (lineRe.test(line)) count++;
|
|
69
|
+
});
|
|
70
|
+
return count;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Character-offset spans of fenced code blocks (delimiter lines included), an
|
|
75
|
+
* unterminated fence running to end-of-text. Mirrors the `inFence`/`fenceLen`
|
|
76
|
+
* toggle `countHeadingsOutsideFences` carries so every fence-aware scan agrees
|
|
77
|
+
* on the same boundaries.
|
|
78
|
+
*/
|
|
79
|
+
const fencedSpans = (content: string): [number, number][] => {
|
|
80
|
+
const spans: [number, number][] = [];
|
|
81
|
+
let inFence = false;
|
|
82
|
+
let fenceLen = 0;
|
|
83
|
+
let fenceChar = "";
|
|
84
|
+
let spanStart = 0;
|
|
85
|
+
let offset = 0;
|
|
86
|
+
for (const line of content.split("\n")) {
|
|
87
|
+
const lineEnd = offset + line.length + 1; // +1 for the split-consumed \n
|
|
88
|
+
const fence = FENCE_LINE_RE.exec(line);
|
|
89
|
+
if (fence) {
|
|
90
|
+
if (!inFence) {
|
|
91
|
+
inFence = true;
|
|
92
|
+
fenceLen = fence[1].length;
|
|
93
|
+
fenceChar = fence[1][0];
|
|
94
|
+
spanStart = offset;
|
|
95
|
+
} else if (closesFence(line, fence, fenceChar, fenceLen)) {
|
|
96
|
+
inFence = false;
|
|
97
|
+
fenceLen = 0;
|
|
98
|
+
fenceChar = "";
|
|
99
|
+
spans.push([spanStart, lineEnd]);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
offset = lineEnd;
|
|
103
|
+
}
|
|
104
|
+
if (inFence) spans.push([spanStart, offset]);
|
|
105
|
+
return spans;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export { closesFence, countHeadingsOutsideFences, FENCE_LINE_RE, fencedSpans, forEachLineOutsideFences };
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { basename, isAbsolute, join } from "node:path";
|
|
3
|
+
import { type Artifact, handleToString, type Output, type RunView } from "@juicesharp/rpiv-workflow/registration";
|
|
4
|
+
import { StagePreflightError } from "@juicesharp/rpiv-workflow/runner";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A plan's structured `phases:` frontmatter array — the machine-readable phase
|
|
8
|
+
* enumeration a plan-producing skill (`blueprint`, `plan`) derives from its
|
|
9
|
+
* `## Phase N:` body headings — is what drives `implement` fanout. The
|
|
10
|
+
* convention lives here; rpiv-workflow knows nothing about phases.
|
|
11
|
+
*
|
|
12
|
+
* Cap: a plan declaring more than 32 phases throws. The rpiv-pi planning skills
|
|
13
|
+
* cap around 8 phases in practice; 32 leaves headroom for stretch plans without
|
|
14
|
+
* letting a pathological (or hostile) plan drive an unbounded fanout loop.
|
|
15
|
+
*/
|
|
16
|
+
const MAX_PHASES = 32;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* One parsed entry of a plan's `phases:` array. `entry` carries the whole raw
|
|
20
|
+
* frontmatter object, so a consumer can read fields beyond `{ n, title }`
|
|
21
|
+
* without this parser knowing about them.
|
|
22
|
+
*/
|
|
23
|
+
interface PhaseRecord {
|
|
24
|
+
entry: Record<string, unknown>;
|
|
25
|
+
/** From `entry.n`, falling back to the 1-based array position. */
|
|
26
|
+
n: number;
|
|
27
|
+
/** From `entry.title`, or "" when absent. */
|
|
28
|
+
title: string;
|
|
29
|
+
/** 0-based position in the array. */
|
|
30
|
+
index: number;
|
|
31
|
+
/** Total phases in this plan. */
|
|
32
|
+
total: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Read an artifact file, resolving a workflow-relative path against `cwd`. */
|
|
36
|
+
const readArtifactFile = (path: string, cwd: string): string =>
|
|
37
|
+
readFileSync(isAbsolute(path) ? path : join(cwd, path), "utf-8");
|
|
38
|
+
|
|
39
|
+
/** Build the halting `StagePreflightError` shape every phase fanout/iterate guard `throw`s. */
|
|
40
|
+
const haltPreflight = (who: string, summary: string, detail: string): StagePreflightError =>
|
|
41
|
+
new StagePreflightError("halt", who, summary, detail, true);
|
|
42
|
+
|
|
43
|
+
/** Latest `fs`-handle artifact most recently published under `name` (undefined if none). */
|
|
44
|
+
const latestFsArtifact = (state: RunView, name: string): Artifact | undefined =>
|
|
45
|
+
state.named[name]?.at(-1)?.artifacts.find((a) => a.handle.kind === "fs");
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* An `Artifact` narrowed to its `fs`-handle variant — the plan-path-carrying
|
|
49
|
+
* shape the scope checks key the verdict path + `artifact` field off. Annotates
|
|
50
|
+
* a captured artifact ACROSS loop iterations so the `if (a.handle.kind !== "fs")
|
|
51
|
+
* continue` guard's narrowing carries to the post-loop `latest.handle.path` read
|
|
52
|
+
* (the file's idiom — `designPathsBySlice` reads `.path` inside its own
|
|
53
|
+
* same-scope guard; this loop captures the artifact across iterations, so the
|
|
54
|
+
* narrowed type annotates the capture).
|
|
55
|
+
*/
|
|
56
|
+
type FsArtifact = Artifact & { handle: { kind: "fs"; path: string } };
|
|
57
|
+
|
|
58
|
+
/** The verdict directory the deterministic checks and the LLM grade panel share. */
|
|
59
|
+
const VERDICT_DIR = ".rpiv/artifacts/verdicts";
|
|
60
|
+
/** Binary verdict score: a clean pass. The gate keys off `severity`, never this number. */
|
|
61
|
+
const VERDICT_PASS_SCORE = 100;
|
|
62
|
+
/** Binary verdict score: at least one finding. The gate keys off `severity`, never this number. */
|
|
63
|
+
const VERDICT_FAIL_SCORE = 0;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* A `path:line` (or `path:line-line`) citation in an artifact's prose. Requires a
|
|
67
|
+
* dotted extension so timestamps (`17:13:27`), ratios, and bare `Slice 2:` labels
|
|
68
|
+
* never match — only file references with a real extension are verified.
|
|
69
|
+
*
|
|
70
|
+
* A citation may START with a single dot (`.github/workflows/ci.yml:12`,
|
|
71
|
+
* `.eslintrc.js:3`) — without it, dot-dirs and dotfiles were captured with the
|
|
72
|
+
* dot stripped and guaranteed to fail the floor as a mangled path. The leading
|
|
73
|
+
* dot is taken only when the preceding char is not a word char or another dot
|
|
74
|
+
* (`(?<![\w.])`), and a dotless start only at a word boundary (`(?<!\w)`), so a
|
|
75
|
+
* prose ellipsis (`...packages/x.ts:5`) still yields `packages/x.ts`, never
|
|
76
|
+
* `...packages/x.ts`.
|
|
77
|
+
*/
|
|
78
|
+
const FILE_LINE_CITATION_RE = /((?:(?<![\w.])\.)?(?<!\w)[\w][\w./-]*\.[a-zA-Z][a-zA-Z0-9]{0,4}):(\d+)(?:-(\d+))?/g;
|
|
79
|
+
|
|
80
|
+
/** A structure-dimension finding — the shared shape the deterministic verdict
|
|
81
|
+
* checks emit (`detail` is the actionable message, `where` locates the defect). */
|
|
82
|
+
type StructureFinding = { detail: string; where: string };
|
|
83
|
+
|
|
84
|
+
/** An `fs` artifact handle (the only handle kind the verdict checks operate on). */
|
|
85
|
+
type FsHandle = { kind: "fs"; path: string };
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Write the shared `{ dimension: "structure" }` verdict and publish it on an fs
|
|
89
|
+
* artifact. The three deterministic structure checks (`sliceStructureCheck`,
|
|
90
|
+
* `subplanCoverageCheck`, `planCitationCheck`) all emit the SAME verdict shape
|
|
91
|
+
* and basename-keyed JSON write, so it lives here once. `who` is the channel
|
|
92
|
+
* prefix folded into the basename (so a re-run OVERWRITES its own slot —
|
|
93
|
+
* idempotent across fix/reslice/re-dispatch rounds); `handle` is the artifact
|
|
94
|
+
* the check inspected (serialized into `data.artifact` and basename-keyed).
|
|
95
|
+
*
|
|
96
|
+
* The `severity: pass ? "none" : "high"` floor is load-bearing: the gate routes
|
|
97
|
+
* via `allDimensionsPass`/`subplanGatePasses`, whose severity floor silently
|
|
98
|
+
* passes a `pass:false` verdict rated `low`/`none`; a structural defect MUST
|
|
99
|
+
* rate `high` or it ships. The `score` is the binary verdict scale (100 = clean,
|
|
100
|
+
* 0 = finding; the gate keys off `severity`, never this number).
|
|
101
|
+
*
|
|
102
|
+
* `extra` lets a caller stamp additional gate-readable fields onto the verdict
|
|
103
|
+
* data (and the persisted JSON, so the trail records them) — currently only
|
|
104
|
+
* `sliceStructureCheck`'s `citeDischarged` stamp.
|
|
105
|
+
*/
|
|
106
|
+
const writeStructureVerdict = (
|
|
107
|
+
who: string,
|
|
108
|
+
handle: FsHandle,
|
|
109
|
+
findings: StructureFinding[],
|
|
110
|
+
cwd: string,
|
|
111
|
+
extra?: Record<string, unknown>,
|
|
112
|
+
): Omit<Output, "meta"> => {
|
|
113
|
+
const pass = findings.length === 0;
|
|
114
|
+
const data = {
|
|
115
|
+
dimension: "structure",
|
|
116
|
+
pass,
|
|
117
|
+
score: pass ? VERDICT_PASS_SCORE : VERDICT_FAIL_SCORE,
|
|
118
|
+
severity: pass ? "none" : "high",
|
|
119
|
+
artifact: handleToString(handle),
|
|
120
|
+
findings,
|
|
121
|
+
feedback: pass ? "" : findings.map((f) => f.detail).join(" "),
|
|
122
|
+
...extra,
|
|
123
|
+
};
|
|
124
|
+
const rel = join(VERDICT_DIR, `${who}__${basename(handle.path, ".md")}.json`);
|
|
125
|
+
mkdirSync(join(cwd, VERDICT_DIR), { recursive: true });
|
|
126
|
+
writeFileSync(join(cwd, rel), JSON.stringify(data, null, 2), "utf-8");
|
|
127
|
+
return { kind: "json", artifacts: [{ handle: { kind: "fs", path: rel } }], data };
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* The reconcile write-restriction's static allowlist — a conservative test-path
|
|
132
|
+
* classifier. A directive may apply its `find → replace` ONLY to a co-located test
|
|
133
|
+
* file (`*.test.{ts,tsx,js,jsx}`); any other target is flagged and left untouched
|
|
134
|
+
* (fail-closed: golden masters, fixtures, `*.t.ts`, and production sources are NOT
|
|
135
|
+
* auto-applied). Narrow by design — do not widen it to compensate for a weak
|
|
136
|
+
* directive (correctness rests on this neither false-failing a legit test edit
|
|
137
|
+
* nor false-allowing a non-test target).
|
|
138
|
+
*/
|
|
139
|
+
const TEST_PATH_RE = /\.test\.[tj]sx?$/;
|
|
140
|
+
|
|
141
|
+
export type { FsArtifact, PhaseRecord, StructureFinding };
|
|
142
|
+
export {
|
|
143
|
+
FILE_LINE_CITATION_RE,
|
|
144
|
+
haltPreflight,
|
|
145
|
+
latestFsArtifact,
|
|
146
|
+
MAX_PHASES,
|
|
147
|
+
readArtifactFile,
|
|
148
|
+
TEST_PATH_RE,
|
|
149
|
+
VERDICT_DIR,
|
|
150
|
+
VERDICT_FAIL_SCORE,
|
|
151
|
+
VERDICT_PASS_SCORE,
|
|
152
|
+
writeStructureVerdict,
|
|
153
|
+
};
|
|
@@ -49,6 +49,7 @@ import {
|
|
|
49
49
|
computeLaneLayout,
|
|
50
50
|
renderLaneList,
|
|
51
51
|
renderLiveOutputBorder,
|
|
52
|
+
renderRecap,
|
|
52
53
|
renderStageBreakdown,
|
|
53
54
|
SPIN_INTERVAL_MS,
|
|
54
55
|
SPINNER_FRAMES,
|
|
@@ -141,7 +142,7 @@ export class LaneConsole implements Component {
|
|
|
141
142
|
* PageDown walks it; retarget clears it). Decoupled from body.length → no drift. */
|
|
142
143
|
private anchorLine = 0;
|
|
143
144
|
/** max(0, body.length - rows) cached every windowTranscript() frame; scroll() reads it
|
|
144
|
-
* because it has no body/rows in scope (
|
|
145
|
+
* because it has no body/rows in scope (may lag the latest token by one frame —
|
|
145
146
|
* self-corrects on the next render, never produces a negative start or a height change). */
|
|
146
147
|
private lastMaxStart = 0;
|
|
147
148
|
/** `t` toggles tool/summary expansion in the transcript. */
|
|
@@ -336,11 +337,18 @@ export class LaneConsole implements Component {
|
|
|
336
337
|
// — this is what keeps the lane view static across the step-in.
|
|
337
338
|
const { laneCap } = computeLaneLayout(realRows);
|
|
338
339
|
const laneList = renderLaneList(this.theme, width, { active: true, selection, frame: this.frame, laneCap });
|
|
340
|
+
// Recap summary (auto-shows — no toggle): ONE trail-derived end-of-run line for the
|
|
341
|
+
// selected lane (newest artifact · +N more · ⚠ reason). Empty when the lane is missing,
|
|
342
|
+
// carries no recap (a running / reactivated lane renders byte-identical), or the recap
|
|
343
|
+
// adds nothing beyond the lane chip. Spliced AFTER the lane list and BEFORE the optional
|
|
344
|
+
// stage block; ≤1 line, absorbed by the transcript flex region.
|
|
345
|
+
const recapBlock = target ? renderRecap(this.theme, width, target.runId) : [];
|
|
339
346
|
const stageBlock =
|
|
340
347
|
target && this.stageBreakdownExpanded ? renderStageBreakdown(this.theme, width, target.runId) : [];
|
|
341
348
|
const rule = this.theme.fg("accent", "─".repeat(Math.max(0, width)));
|
|
342
349
|
const laneBlock = [
|
|
343
350
|
...laneList,
|
|
351
|
+
...(recapBlock.length ? ["", ...recapBlock] : []),
|
|
344
352
|
...(stageBlock.length ? ["", ...stageBlock] : []),
|
|
345
353
|
"",
|
|
346
354
|
this.footer(width, target),
|
|
@@ -98,6 +98,17 @@ function padCol(theme: Theme, color: ThemeColor, text: string, width: number, bo
|
|
|
98
98
|
return theme.fg(color, content) + " ".repeat(gap);
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
/** Canonical `.rpiv/artifacts/` root every collector path shares — stripped for display to
|
|
102
|
+
* reclaim ~16 dead columns; stored values keep the full path. */
|
|
103
|
+
const ARTIFACTS_DISPLAY_PREFIX = ".rpiv/artifacts/";
|
|
104
|
+
|
|
105
|
+
/** Display form of an artifact path — see `ARTIFACTS_DISPLAY_PREFIX` for the display-only/
|
|
106
|
+
* stored-values split. Non-canonical paths (url/opaque/inline handles, out-of-tree fs paths)
|
|
107
|
+
* pass through untouched. */
|
|
108
|
+
function displayArtifact(path: string): string {
|
|
109
|
+
return path.startsWith(ARTIFACTS_DISPLAY_PREFIX) ? path.slice(ARTIFACTS_DISPLAY_PREFIX.length) : path;
|
|
110
|
+
}
|
|
111
|
+
|
|
101
112
|
/** The dock descriptor for a lane — the run's `--name` alias when it differs from the workflow,
|
|
102
113
|
* else the `runId` (always defined, so every row carries the `workflow:` tag + a descriptor). */
|
|
103
114
|
function laneDescriptor(lane: LaneEntry): string {
|
|
@@ -280,12 +291,11 @@ function renderProgressRow(
|
|
|
280
291
|
if (progress.units) nameRaw += ` · units ${progress.units.done}/${progress.units.total}`;
|
|
281
292
|
const usageTally = formatUsageTally(usage);
|
|
282
293
|
if (usageTally) nameRaw += ` · ${usageTally}`;
|
|
283
|
-
// The run's primary artifact path (a `produces` stage emitted one) — rendered as a
|
|
284
|
-
//
|
|
285
|
-
//
|
|
286
|
-
//
|
|
287
|
-
|
|
288
|
-
if (lastArtifact) nameRaw += ` → ${lastArtifact}`;
|
|
294
|
+
// The run's primary artifact path (a `produces` stage emitted one) — rendered as a trailing
|
|
295
|
+
// `→ <bucket>/<file>` AFTER the usage tally so a completed row points at what it built.
|
|
296
|
+
// Omitted when `lastArtifact` is undefined, so a side-effect-only run renders byte-identical
|
|
297
|
+
// to before this field existed.
|
|
298
|
+
if (lastArtifact) nameRaw += ` → ${displayArtifact(lastArtifact)}`;
|
|
289
299
|
|
|
290
300
|
const coloredName = theme.fg("muted", nameRaw);
|
|
291
301
|
const coreW = visibleWidth(prefix) + visibleWidth(nameRaw);
|
|
@@ -431,6 +441,33 @@ export function renderLiveOutputBorder(theme: Theme, width: number): string {
|
|
|
431
441
|
return theme.fg("dim", truncateToWidth(label, Math.max(0, width)));
|
|
432
442
|
}
|
|
433
443
|
|
|
444
|
+
/**
|
|
445
|
+
* Render the end-of-run summary (the post-mortem recap) for ONE lane (console-only —
|
|
446
|
+
* the ambient dock never calls this, mirroring `renderStageBreakdown`). Reads the lane
|
|
447
|
+
* LIVE; a missing/evicted lane or a lane with no `recap` yields []. Auto-shows in the
|
|
448
|
+
* console's laneBlock (no toggle — distinct from the `s`-gated `renderStageBreakdown`),
|
|
449
|
+
* and ≤1 line by construction so the console's constant-height invariant holds. Its
|
|
450
|
+
* outcome can legitimately diverge from the lane chip (the accepted
|
|
451
|
+
* `droppedFailureRows` divergence: recap reads "completed" off the trail while the
|
|
452
|
+
* chip shows ✗ failed).
|
|
453
|
+
*/
|
|
454
|
+
export function renderRecap(theme: Theme, width: number, runId: string): string[] {
|
|
455
|
+
const recap = getLane(runId)?.recap;
|
|
456
|
+
if (!recap) return [];
|
|
457
|
+
const parts: string[] = [];
|
|
458
|
+
const n = recap.artifacts.length;
|
|
459
|
+
if (n > 0) {
|
|
460
|
+
parts.push(theme.fg("muted", `→ ${displayArtifact(recap.artifacts[n - 1])}`));
|
|
461
|
+
if (n > 1) parts.push(theme.fg("dim", `+${n - 1} more`));
|
|
462
|
+
}
|
|
463
|
+
// Failure reason only for a non-completed outcome that carries one.
|
|
464
|
+
if (recap.outcome !== "completed" && recap.failureReason) {
|
|
465
|
+
parts.push(theme.fg("warning", `⚠ ${recap.failureReason}`));
|
|
466
|
+
}
|
|
467
|
+
if (parts.length === 0) return [];
|
|
468
|
+
return [truncateToWidth(parts.join(" · "), width, "…")];
|
|
469
|
+
}
|
|
470
|
+
|
|
434
471
|
/**
|
|
435
472
|
* Render the per-stage token breakdown for ONE lane (console-only — the ambient dock
|
|
436
473
|
* never calls this, so its capped region is unchanged). Reads the lane LIVE; a missing
|
|
@@ -45,6 +45,7 @@ import {
|
|
|
45
45
|
retireRun,
|
|
46
46
|
seedPendingUnits,
|
|
47
47
|
setLaneProgress,
|
|
48
|
+
setRecap,
|
|
48
49
|
setUnitStarted,
|
|
49
50
|
sweepRunningUnits,
|
|
50
51
|
} from "./run-lane-registry.js";
|
|
@@ -84,6 +85,20 @@ function guard(): ProgressGuard {
|
|
|
84
85
|
*/
|
|
85
86
|
const fanoutRuns = new Set<string>();
|
|
86
87
|
|
|
88
|
+
/**
|
|
89
|
+
* runId → the current run instance's `ctx.state`. A resume reuses the runId but
|
|
90
|
+
* starts a fresh `ctx.state`, so object identity distinguishes the predecessor
|
|
91
|
+
* from its resumed successor — the basis of the `onWorkflowEnd` instance guard
|
|
92
|
+
* below. Seeded on `onWorkflowStart`, deleted on the terminal-proceed path,
|
|
93
|
+
* cleared wholesale by `__resetLaneProgress`. Module-local (the bridge runs only
|
|
94
|
+
* at the root launcher).
|
|
95
|
+
*
|
|
96
|
+
* Residual (microtask-scale, accepted): a predecessor end landing between the
|
|
97
|
+
* successor's `recordRun` and its `onWorkflowStart` seed-overwrite still slips
|
|
98
|
+
* through.
|
|
99
|
+
*/
|
|
100
|
+
const activeInstances = new Map<string, object>();
|
|
101
|
+
|
|
87
102
|
/**
|
|
88
103
|
* Wire the lifecycle→registry bridge to the ROOT launcher's session_start.
|
|
89
104
|
* Skipped for a detached foreground child (branded relay ui) and any non-UI
|
|
@@ -116,8 +131,15 @@ export async function registerLaneProgress(): Promise<void> {
|
|
|
116
131
|
try {
|
|
117
132
|
// Thin `/startup` entry (re-exports registerLifecycle) — keeps the
|
|
118
133
|
// loader/DSL/runner graph off startup and avoids the barrel-import race.
|
|
119
|
-
const { registerLifecycle } = await import("@juicesharp/rpiv-workflow/startup");
|
|
134
|
+
const { registerLifecycle, summarizeRun } = await import("@juicesharp/rpiv-workflow/startup");
|
|
120
135
|
g.dispose = registerLifecycle({
|
|
136
|
+
// Seed run-INSTANCE identity keyed by runId. A resume REUSES the runId, so a
|
|
137
|
+
// runId-only gate is racy — but `reconstructState` hands the resumed successor a
|
|
138
|
+
// FRESH ctx.state object, so the onWorkflowEnd instance guard compares identities to
|
|
139
|
+
// drop a stale predecessor's late end (it must not re-retire/re-cap the resumed lane).
|
|
140
|
+
onWorkflowStart: (ctx) => {
|
|
141
|
+
activeInstances.set(ctx.runId, ctx.state);
|
|
142
|
+
},
|
|
121
143
|
// onStageStart fires for EVERY stage kind — a plain sequential stage (the single-stage
|
|
122
144
|
// entry announcement, run-stage.ts:221) AND every loop stage, where it fires BEFORE
|
|
123
145
|
// onLoopStart (announceLoopStart, loop.ts:75→78). So retiring the prior stage's fan-out
|
|
@@ -217,6 +239,13 @@ export async function registerLaneProgress(): Promise<void> {
|
|
|
217
239
|
onWorkflowEnd: (result, ctx) => {
|
|
218
240
|
const status = result.termination?.status;
|
|
219
241
|
if (!status || status === "running") return; // still in-flight — nothing to retire
|
|
242
|
+
// Run-instance guard: drop a superseded predecessor's late terminal event so it can't
|
|
243
|
+
// re-stamp the resumed lane with the predecessor's outcome + recap (a resume reactivates
|
|
244
|
+
// the lane to "running", re-arming retireRun's first-retire-wins gate). Fail-open when no
|
|
245
|
+
// instance was recorded — see `activeInstances` for the identity basis + residual window.
|
|
246
|
+
const recorded = activeInstances.get(ctx.runId);
|
|
247
|
+
if (recorded !== undefined && recorded !== ctx.state) return; // stale predecessor end
|
|
248
|
+
activeInstances.delete(ctx.runId); // keep the map bounded to in-flight runs
|
|
220
249
|
const lane = getLane(ctx.runId);
|
|
221
250
|
const name = lane?.name ?? ctx.workflow;
|
|
222
251
|
// `termination.error` is the readable cause (the same text as the trail's
|
|
@@ -224,18 +253,33 @@ export async function registerLaneProgress(): Promise<void> {
|
|
|
224
253
|
const error = result.termination?.error;
|
|
225
254
|
// `lastArtifact` is the primary artifact's canonical path (a `produces`
|
|
226
255
|
// stage emitted one) — retained on the lane so a completed row can render
|
|
227
|
-
// `→
|
|
256
|
+
// `→ <bucket>/<file>.md`. Undefined for side-effect-only runs.
|
|
228
257
|
const lastArtifact = result.lastArtifact;
|
|
229
258
|
// Sweep any unit that never fired onUnitEnd (abort/throw) to the run's terminal
|
|
230
259
|
// kind BEFORE retiring, so a failed run's stuck sub-rows read ✗ (retireRun's
|
|
231
260
|
// running→done fallback then no-ops on them). Drop the gate — the run is over.
|
|
232
261
|
sweepRunningUnits(ctx.runId, status === "completed" ? "done" : "failed");
|
|
233
262
|
fanoutRuns.delete(ctx.runId);
|
|
263
|
+
// End-of-run summary off the on-disk JSONL trail (the post-mortem recap). Computed
|
|
264
|
+
// for EVERY terminal outcome (completed/failed/cancelled/aborted), not only failures,
|
|
265
|
+
// and BEFORE retirement so the lane is still live while the trail is read. The recap
|
|
266
|
+
// does NOT gate retirement: a run whose recap resolved to undefined still retires.
|
|
267
|
+
const recap = summarizeRun(ctx.cwd, ctx.runId);
|
|
234
268
|
retireRun(ctx.runId, status, error, lastArtifact);
|
|
269
|
+
// Land the recap on the (possibly already-terminal) lane. See `setRecap` for why it's
|
|
270
|
+
// ungated by status. Fail-soft: an undefined recap stores nothing.
|
|
271
|
+
if (recap !== undefined) setRecap(ctx.runId, recap);
|
|
235
272
|
const ui = getCapturedUiContext();
|
|
236
273
|
if (!ui) return;
|
|
237
|
-
if (status === "completed")
|
|
238
|
-
|
|
274
|
+
if (status === "completed") {
|
|
275
|
+
// A "completed" termination whose recap reads "stopped" is a
|
|
276
|
+
// gate-routed stop (a stop-on-fail preset's red gate): the run
|
|
277
|
+
// halted before its chain's natural end, so a ✓ success toast
|
|
278
|
+
// would misreport it. Surface the recap's reason instead.
|
|
279
|
+
if (recap?.outcome === "stopped")
|
|
280
|
+
ui.notify(`⚠ ${name} ${recap.failureReason ?? "stopped at a gate"} — /lanes to view`, "warning");
|
|
281
|
+
else ui.notify(`✓ ${name} finished — /lanes to view`, "info");
|
|
282
|
+
} else if (status === "failed") {
|
|
239
283
|
// Inject the short reason into the toast so the user learns WHY without
|
|
240
284
|
// opening the lane; falls back to the bare line when no cause is known.
|
|
241
285
|
const short = shortFailureReason(error);
|
|
@@ -263,4 +307,5 @@ export function __resetLaneProgress(): void {
|
|
|
263
307
|
g.dispose?.();
|
|
264
308
|
g.dispose = undefined;
|
|
265
309
|
fanoutRuns.clear();
|
|
310
|
+
activeInstances.clear();
|
|
266
311
|
}
|
|
@@ -35,7 +35,7 @@ export const PIPELINE_POINTER = [
|
|
|
35
35
|
"Other explicit-only commands: /skill:slice, /skill:revise, /skill:elaborate,",
|
|
36
36
|
"/skill:architecture-review, /skill:frontend-design",
|
|
37
37
|
"Workflow-internal (dispatched by lanes — never suggest): amend, design-slice,",
|
|
38
|
-
"design-review, synthesize, grade, remediate",
|
|
38
|
+
"design-review, synthesize, grade, remediate, quick-plan",
|
|
39
39
|
].join("\n");
|
|
40
40
|
|
|
41
41
|
export function injectPipelinePointer(pi: ExtensionAPI): void {
|
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
|
|
17
17
|
import type { ExtensionUIContext } from "@earendil-works/pi-coding-agent";
|
|
18
18
|
|
|
19
|
+
import type { RunRecap } from "@juicesharp/rpiv-workflow";
|
|
20
|
+
|
|
19
21
|
import { addLaneUsage, type LaneUsage, toLaneUsage } from "./lane-usage.js";
|
|
20
22
|
import { emitQuestionAsked, emitQuestionResolved } from "./question-lifecycle.js";
|
|
21
23
|
|
|
@@ -201,7 +203,7 @@ export interface LaneEntry {
|
|
|
201
203
|
/**
|
|
202
204
|
* Primary artifact path at run termination — `RunWorkflowResult.lastArtifact`
|
|
203
205
|
* captured at `retireRun` (the runner's terminal `onWorkflowEnd`), so a completed
|
|
204
|
-
* lane row can surface `→
|
|
206
|
+
* lane row can surface `→ <bucket>/<file>.md` as a trailing
|
|
205
207
|
* segment. Undefined for a side-effect-only run (no `produces` stage emitted a
|
|
206
208
|
* primary artifact) and for aborted/failed runs (the terminal writers pass ≤3
|
|
207
209
|
* args). Cleared on resume (`recordRun` reactivation) so a resumed run never
|
|
@@ -209,6 +211,16 @@ export interface LaneEntry {
|
|
|
209
211
|
* clears.
|
|
210
212
|
*/
|
|
211
213
|
lastArtifact?: string;
|
|
214
|
+
/**
|
|
215
|
+
* End-of-run summary projected from the on-disk JSONL trail by `summarizeRun`
|
|
216
|
+
* (rpiv-workflow) — the lane-console renders it via `renderRecap` for a terminal
|
|
217
|
+
* lane that carries one. Written by `setRecap` at `onWorkflowEnd` — see it for
|
|
218
|
+
* the single-writer invariant. Undefined for a run that never reached
|
|
219
|
+
* `onWorkflowEnd` (in-progress / hard-teardown) and cleared on resume
|
|
220
|
+
* (`recordRun` reactivation) so a resumed run never leaks the prior recap —
|
|
221
|
+
* mirroring `lastArtifact`.
|
|
222
|
+
*/
|
|
223
|
+
recap?: RunRecap;
|
|
212
224
|
/**
|
|
213
225
|
* When this lane first started waiting on a deferred foreground question
|
|
214
226
|
* — `Date.now()` stamped on the FIRST enqueue that finds the clock
|
|
@@ -317,6 +329,7 @@ export function recordRun(runId: string, name: string, meta?: { workflow?: strin
|
|
|
317
329
|
existing.units.clear(); // drop the prior run's per-unit sessions + terminal snapshots
|
|
318
330
|
existing.error = undefined; // clear the prior run's terminal failure reason
|
|
319
331
|
existing.lastArtifact = undefined; // clear the prior run's primary artifact path
|
|
332
|
+
existing.recap = undefined; // clear the prior run's end-of-run summary
|
|
320
333
|
existing.progress = undefined; // clear stale stage progress
|
|
321
334
|
existing.needsInputSince = undefined; // clear any stale needs-input clock
|
|
322
335
|
} else {
|
|
@@ -456,6 +469,23 @@ export function retireRun(
|
|
|
456
469
|
for (const idx of cleared) emitQuestionResolved(runId, idx, "cleared");
|
|
457
470
|
}
|
|
458
471
|
|
|
472
|
+
/**
|
|
473
|
+
* Store a run's end-of-run summary — the SOLE recap writer, deliberately ungated
|
|
474
|
+
* by the lane's terminal status: the x-key `stopSelected` path (lane-console.ts)
|
|
475
|
+
* retires the lane to "aborted" while the run is still in-flight, and the recap
|
|
476
|
+
* computed at `onWorkflowEnd` must still land on that already-terminal lane
|
|
477
|
+
* (`retireRun` is a first-retire-wins no-op there and never touches `recap`).
|
|
478
|
+
* The host's hard-teardown dispose fallback (workflow-execution-host.ts), where
|
|
479
|
+
* `onWorkflowEnd` may never fire, stores no recap — such a lane reads bare
|
|
480
|
+
* "aborted". Best-effort: a missing lane is a no-op.
|
|
481
|
+
*/
|
|
482
|
+
export function setRecap(runId: string, recap: RunRecap): void {
|
|
483
|
+
const entry = state().lanes.get(runId);
|
|
484
|
+
if (!entry) return;
|
|
485
|
+
entry.recap = recap;
|
|
486
|
+
notify();
|
|
487
|
+
}
|
|
488
|
+
|
|
459
489
|
/**
|
|
460
490
|
* Capture a run's transcript snapshot WHILE its child session is still alive
|
|
461
491
|
* (fast-path). The detached host calls this from its per-stage `finally`,
|
|
@@ -464,32 +494,27 @@ export function retireRun(
|
|
|
464
494
|
* (with `currentSession` already gone), the snapshot is already in place. Best-effort:
|
|
465
495
|
* a missing/evicted lane is a no-op. Does NOT notify — the paired `setCurrentSession`
|
|
466
496
|
* that immediately follows in the host does.
|
|
467
|
-
*
|
|
468
|
-
* Capture-side fold-at-overwrite: a sequential multi-child stage parks EVERY child
|
|
469
|
-
* on the SAME `SINGLE_UNIT_KEY` slot, so `captureSnapshotInto`'s `finalUsage =`
|
|
470
|
-
* overwrite would evict each OUTGOING child's tokens before the stage-end
|
|
471
|
-
* `foldStageUsage` can count them (losing all but the last). Fold the unit's
|
|
472
|
-
* already-parked `finalUsage` (the outgoing child) into the CURRENT stage bucket
|
|
473
|
-
* BEFORE the overwrite; the overwrite then EVICTS it from the slot, so
|
|
474
|
-
* `foldStageUsage` cannot re-count it. Capture-time (children 1..N-1) and stage-end
|
|
475
|
-
* (surviving last child N) touch disjoint sets → fold-exactly-once, no double-count.
|
|
476
|
-
* Fail-soft by composition: no parked `finalUsage` (first capture / a failed
|
|
477
|
-
* getUsage) skips the fold, and `addStageUsage`'s own guard drops an unset
|
|
478
|
-
* stageName (pre-first-stage capture). Usage-only — `finalBranch`/`finalCwd`/
|
|
479
|
-
* `finalToolDefs` stay last-writer-wins across the overwrite.
|
|
480
|
-
*
|
|
481
|
-
* The fold is gated on a LIVE lane (`status === "running"`): the dock's optimistic
|
|
482
|
-
* `x` cancel calls `retireRun` BEFORE this teardown capture, and retire's own
|
|
483
|
-
* snapshot parks the SAME still-live child's usage onto the slot — so the parked
|
|
484
|
-
* value here is a same-child re-capture, not an outgoing sibling. Folding it would
|
|
485
|
-
* count the child twice (once in the bucket, once via the retained unit at render).
|
|
486
|
-
* Post-retirement the overwrite-only path is exactly right.
|
|
487
497
|
*/
|
|
488
498
|
export function captureFinalSnapshot(runId: string, index: number, session: LaneSession): void {
|
|
489
499
|
const entry = state().lanes.get(runId);
|
|
490
500
|
if (!entry) return;
|
|
491
501
|
const unit = upsertUnit(entry, index);
|
|
502
|
+
// The fold is gated on a LIVE lane (`status === "running"`): the dock's optimistic
|
|
503
|
+
// `x` cancel calls `retireRun` BEFORE this teardown capture, and retire's own snapshot
|
|
504
|
+
// parks the SAME still-live child's usage onto the slot — so the parked value here is a
|
|
505
|
+
// same-child re-capture, not an outgoing sibling. Folding here would double-count (once
|
|
506
|
+
// in the bucket, once via the retained unit at render). Post-retirement the overwrite-only
|
|
507
|
+
// path is exactly right.
|
|
492
508
|
if (unit.finalUsage && entry.status === "running") {
|
|
509
|
+
// Fold-at-overwrite: a sequential multi-child stage parks EVERY child on the SAME
|
|
510
|
+
// `SINGLE_UNIT_KEY` slot, so `captureSnapshotInto`'s `finalUsage =` overwrite would
|
|
511
|
+
// evict each OUTGOING child's tokens before the stage-end `foldStageUsage` can count
|
|
512
|
+
// them (losing all but the last). Fold the unit's already-parked `finalUsage` (the
|
|
513
|
+
// outgoing child) into the CURRENT stage bucket via `addStageUsage` BEFORE the
|
|
514
|
+
// overwrite; the overwrite then EVICTS it from the slot, so `foldStageUsage` cannot
|
|
515
|
+
// re-count it. Capture-time (children 1..N-1) and stage-end (surviving last child N)
|
|
516
|
+
// touch disjoint sets → fold-exactly-once, no double-count. Usage-only —
|
|
517
|
+
// `finalBranch`/`finalCwd`/`finalToolDefs` stay last-writer-wins across the overwrite.
|
|
493
518
|
addStageUsage(runId, entry.progress?.stageName, unit.finalUsage);
|
|
494
519
|
}
|
|
495
520
|
captureSnapshotInto(unit, session);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juicesharp/rpiv-pi",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "A skill-based development workflow for Pi Agent.
|
|
3
|
+
"version": "2.5.0",
|
|
4
|
+
"description": "A skill-based development workflow for Pi Agent. 29 contract-carrying skills (discover → research → design → plan → implement → validate → code-review → commit, and more), the 15 named subagents they dispatch, and four built-in /wf workflows that chain them end to end in detached parallel runs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
7
7
|
"pi-extension",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
]
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@juicesharp/rpiv-config": "^2.
|
|
52
|
+
"@juicesharp/rpiv-config": "^2.5.0",
|
|
53
53
|
"typebox": "^1.1.24"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|