@juicesharp/rpiv-pi 2.2.0 → 2.3.1
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 +9 -8
- package/docs/lanes.md +3 -2
- package/docs/models-config.md +6 -6
- package/docs/workflows.md +4 -18
- package/extensions/rpiv-core/artifact-collector.ts +2 -2
- package/extensions/rpiv-core/built-in-workflows.ts +251 -365
- package/extensions/rpiv-core/index.ts +2 -2
- package/extensions/rpiv-core/lane-console.ts +62 -5
- package/extensions/rpiv-core/lane-list.ts +79 -3
- package/extensions/rpiv-core/lane-progress.ts +8 -1
- package/extensions/rpiv-core/lane-switcher.ts +114 -33
- package/extensions/rpiv-core/lane-usage.ts +25 -0
- package/extensions/rpiv-core/models-config-validate.ts +1 -1
- package/extensions/rpiv-core/models-config.ts +3 -3
- package/extensions/rpiv-core/register-built-in-workflows.ts +2 -2
- package/extensions/rpiv-core/run-lane-registry.ts +80 -4
- package/extensions/rpiv-core/sdk-workflow-host.ts +39 -3
- package/extensions/rpiv-core/subagent-usage.ts +147 -0
- package/package.json +3 -3
- package/skills/blueprint/SKILL.md +1 -1
- package/skills/discover/SKILL.md +1 -1
- package/skills/elaborate/SKILL.md +14 -14
- package/skills/grade/SKILL.md +6 -5
- package/skills/implement/SKILL.md +1 -1
- package/skills/plan/SKILL.md +1 -1
- package/skills/slice/SKILL.md +1 -1
- package/skills/synthesize/SKILL.md +2 -2
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* Tool-owning plugins are siblings (see siblings.ts); install via /rpiv-setup.
|
|
8
8
|
*
|
|
9
9
|
* Workflow runtime + `/wf` command live in `@juicesharp/rpiv-workflow`. We
|
|
10
|
-
* contribute
|
|
10
|
+
* contribute three built-in workflows (build / polish / vet) via the
|
|
11
11
|
* sibling's `registerBuiltIns` programmatic API so they're available to
|
|
12
12
|
* users running `/wf` without authoring their own.
|
|
13
13
|
*/
|
|
@@ -42,7 +42,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
42
42
|
registerSetupCommand(pi);
|
|
43
43
|
registerRpivModelsCommand(pi); // /rpiv-models cascade picker
|
|
44
44
|
// Warn-on-miss: surface models.json record-key typos (skills.committ,
|
|
45
|
-
// presets.
|
|
45
|
+
// presets.buildd) that pass schema validation but silently never apply.
|
|
46
46
|
registerModelsConfigValidation(pi);
|
|
47
47
|
// Stage model/effort override: the session_start hook captures modelRegistry +
|
|
48
48
|
// current model + the foreground uiContext UNCONDITIONALLY (independent of
|
|
@@ -49,6 +49,7 @@ import {
|
|
|
49
49
|
computeLaneLayout,
|
|
50
50
|
renderLaneList,
|
|
51
51
|
renderLiveOutputBorder,
|
|
52
|
+
renderStageBreakdown,
|
|
52
53
|
SPIN_INTERVAL_MS,
|
|
53
54
|
SPINNER_FRAMES,
|
|
54
55
|
} from "./lane-list.js";
|
|
@@ -57,6 +58,8 @@ import {
|
|
|
57
58
|
type DisplayRow,
|
|
58
59
|
dequeueInput,
|
|
59
60
|
evictRun,
|
|
61
|
+
getLane,
|
|
62
|
+
type LaneStatus,
|
|
60
63
|
laneNeedsInput,
|
|
61
64
|
listLanes,
|
|
62
65
|
listLanesForDisplay,
|
|
@@ -93,6 +96,14 @@ function sameTarget(a: Target | undefined, b: Target | undefined): boolean {
|
|
|
93
96
|
return a.runId === b.runId && a.unitIndex === b.unitIndex;
|
|
94
97
|
}
|
|
95
98
|
|
|
99
|
+
/** A terminal-failure status the `r` rerun keybinding can resume from (`failed`/`aborted`/
|
|
100
|
+
* `cancelled`). `running`/`completed` are NOT resumable — `r` is inert on them (use `x` to
|
|
101
|
+
* stop a running run; a completed run has nothing to resume). Backed by LaneStatus
|
|
102
|
+
* (run-lane-registry.ts), which mirrors rpiv-workflow's RunTermination.status. */
|
|
103
|
+
function isTerminalFailure(status: LaneStatus | undefined): boolean {
|
|
104
|
+
return status === "failed" || status === "aborted" || status === "cancelled";
|
|
105
|
+
}
|
|
106
|
+
|
|
96
107
|
/**
|
|
97
108
|
* A TUI proxy that reports a capped `terminal.rows` (the embedded questionnaire's
|
|
98
109
|
* allocated band) while forwarding everything else — requestRender, columns, cursor.
|
|
@@ -135,6 +146,8 @@ export class LaneConsole implements Component {
|
|
|
135
146
|
private lastMaxStart = 0;
|
|
136
147
|
/** `t` toggles tool/summary expansion in the transcript. */
|
|
137
148
|
private toolsExpanded = false;
|
|
149
|
+
/** `s` toggles the per-stage token breakdown below the lane block (hidden by default). */
|
|
150
|
+
private stageBreakdownExpanded = false;
|
|
138
151
|
/** The transcript view for the currently-selected unit; swapped on re-target. */
|
|
139
152
|
private transcript: LaneTranscriptView | undefined;
|
|
140
153
|
private transcriptTarget: Target | undefined;
|
|
@@ -166,6 +179,7 @@ export class LaneConsole implements Component {
|
|
|
166
179
|
private readonly theme: Theme,
|
|
167
180
|
private readonly kb: KeybindingsManager,
|
|
168
181
|
private readonly done: () => void,
|
|
182
|
+
private readonly onRerun: (runId: string) => void,
|
|
169
183
|
) {
|
|
170
184
|
// Land on the row the user stepped in from (the dock's top / needs-input row), else 0.
|
|
171
185
|
const rows = listLanesForDisplay();
|
|
@@ -322,8 +336,16 @@ export class LaneConsole implements Component {
|
|
|
322
336
|
// — this is what keeps the lane view static across the step-in.
|
|
323
337
|
const { laneCap } = computeLaneLayout(realRows);
|
|
324
338
|
const laneList = renderLaneList(this.theme, width, { active: true, selection, frame: this.frame, laneCap });
|
|
339
|
+
const stageBlock =
|
|
340
|
+
target && this.stageBreakdownExpanded ? renderStageBreakdown(this.theme, width, target.runId) : [];
|
|
325
341
|
const rule = this.theme.fg("accent", "─".repeat(Math.max(0, width)));
|
|
326
|
-
const laneBlock = [
|
|
342
|
+
const laneBlock = [
|
|
343
|
+
...laneList,
|
|
344
|
+
...(stageBlock.length ? ["", ...stageBlock] : []),
|
|
345
|
+
"",
|
|
346
|
+
this.footer(width, target),
|
|
347
|
+
rule,
|
|
348
|
+
];
|
|
327
349
|
|
|
328
350
|
// LIVE OUTPUT region on top: a `── live output ──` labelled border, then the transcript
|
|
329
351
|
// (the padded flex band that unfurls upward), then the inline question when the selected
|
|
@@ -387,11 +409,16 @@ export class LaneConsole implements Component {
|
|
|
387
409
|
(target.unitIndex === SINGLE_UNIT_KEY
|
|
388
410
|
? laneNeedsInput(target.runId)
|
|
389
411
|
: unitNeedsInput(target.runId, target.unitIndex));
|
|
390
|
-
const
|
|
412
|
+
const canRerun = target ? isTerminalFailure(getLane(target.runId)?.status) : false;
|
|
391
413
|
const toggle = this.toolsExpanded ? "t collapse" : "t expand";
|
|
414
|
+
const stages = this.stageBreakdownExpanded ? "s hide stages" : "s stages";
|
|
392
415
|
const answer = canAnswer ? "⏎ answer · " : "";
|
|
416
|
+
const rerun = canRerun ? "r rerun · " : "";
|
|
393
417
|
return truncateToWidth(
|
|
394
|
-
this.theme.fg(
|
|
418
|
+
this.theme.fg(
|
|
419
|
+
"dim",
|
|
420
|
+
`↑/↓ lanes · ${answer}PgUp/PgDn scroll · ${toggle} · ${stages} · ${rerun}x stop · ↑/←/esc back`,
|
|
421
|
+
),
|
|
395
422
|
width,
|
|
396
423
|
"…",
|
|
397
424
|
);
|
|
@@ -478,10 +505,18 @@ export class LaneConsole implements Component {
|
|
|
478
505
|
this.stopSelected();
|
|
479
506
|
return;
|
|
480
507
|
}
|
|
508
|
+
if (data === "r") {
|
|
509
|
+
this.rerunSelected();
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
481
512
|
if (data === "t") {
|
|
482
513
|
this.toolsExpanded = !this.toolsExpanded;
|
|
483
514
|
this.tui.requestRender();
|
|
484
515
|
}
|
|
516
|
+
if (data === "s") {
|
|
517
|
+
this.stageBreakdownExpanded = !this.stageBreakdownExpanded;
|
|
518
|
+
this.tui.requestRender();
|
|
519
|
+
}
|
|
485
520
|
}
|
|
486
521
|
|
|
487
522
|
/** Move the spine selection (clamped) and reconcile via sync() — the single seam that
|
|
@@ -537,6 +572,21 @@ export class LaneConsole implements Component {
|
|
|
537
572
|
this.tui.requestRender(true);
|
|
538
573
|
}
|
|
539
574
|
|
|
575
|
+
/** `r` resumes a TERMINAL-FAILURE lane (failed/aborted/cancelled) by its run-id — the resume
|
|
576
|
+
* reuses the run-id and appends to the same JSONL trail, so the row flips back to running
|
|
577
|
+
* reactively (the provider's recordRun reactivation fires via the lane lifecycle). Inert on
|
|
578
|
+
* a running/completed row (nothing to resume). The callback is threaded in from the launcher
|
|
579
|
+
* (lane-switcher), which builds the observer-only WorkflowHostContext and dispatches
|
|
580
|
+
* resumeWorkflowByRunId through a guarded dynamic import. requestRender is belt-and-braces
|
|
581
|
+
* during the dynamic-import settle window; the flip itself is subscription-driven. */
|
|
582
|
+
private rerunSelected(): void {
|
|
583
|
+
const row = listLanesForDisplay()[this.selection];
|
|
584
|
+
if (!row) return;
|
|
585
|
+
if (!isTerminalFailure(row.lane.status)) return; // running/completed — nothing to resume
|
|
586
|
+
this.onRerun(row.lane.runId);
|
|
587
|
+
this.tui.requestRender(true);
|
|
588
|
+
}
|
|
589
|
+
|
|
540
590
|
invalidate(): void {
|
|
541
591
|
this.inner?.invalidate?.();
|
|
542
592
|
}
|
|
@@ -561,6 +611,13 @@ export class LaneConsole implements Component {
|
|
|
561
611
|
* step-in jump); the caller (lane-switcher) suppresses the ambient dock for the duration
|
|
562
612
|
* instead, since the browser renders the lane block itself.
|
|
563
613
|
*/
|
|
564
|
-
export function showLaneConsole(
|
|
565
|
-
|
|
614
|
+
export function showLaneConsole(
|
|
615
|
+
ui: ExtensionUIContext,
|
|
616
|
+
runId: string,
|
|
617
|
+
unitIndex: number,
|
|
618
|
+
onRerun: (runId: string) => void,
|
|
619
|
+
): Promise<void> {
|
|
620
|
+
return ui.custom<void>(
|
|
621
|
+
(tui, theme, kb, done) => new LaneConsole(runId, unitIndex, tui, theme, kb, () => done(), onRerun),
|
|
622
|
+
);
|
|
566
623
|
}
|
|
@@ -14,9 +14,10 @@
|
|
|
14
14
|
import type { Theme, ThemeColor } from "@earendil-works/pi-coding-agent";
|
|
15
15
|
import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
16
16
|
import { shortFailureReason } from "./lane-failure.js";
|
|
17
|
-
import { formatTokens, type LaneUsage } from "./lane-usage.js";
|
|
17
|
+
import { addLaneUsage, formatTokens, type LaneUsage } from "./lane-usage.js";
|
|
18
18
|
import {
|
|
19
19
|
type DisplayRow,
|
|
20
|
+
getLane,
|
|
20
21
|
type LaneEntry,
|
|
21
22
|
type LaneProgress,
|
|
22
23
|
type LaneStatus,
|
|
@@ -27,6 +28,7 @@ import {
|
|
|
27
28
|
unitNeedsInput,
|
|
28
29
|
unitUsage,
|
|
29
30
|
} from "./run-lane-registry.js";
|
|
31
|
+
import { getSubagentUsageForRun, getSubagentUsageForStage } from "./subagent-usage.js";
|
|
30
32
|
|
|
31
33
|
/** Per-row CAP on the lane region (the scroll-follow window + its +N above/below summaries).
|
|
32
34
|
* computeLaneLayout bounds laneCap at MAX_WIDGET_LINES - 1, so the list never grows unbounded. */
|
|
@@ -145,6 +147,35 @@ function sumLaneUsage(units: Iterable<UnitLane>): LaneUsage | undefined {
|
|
|
145
147
|
return result;
|
|
146
148
|
}
|
|
147
149
|
|
|
150
|
+
/** The single definition of "a lane's tokens" — the run-so-far total, unified at read
|
|
151
|
+
* time from the three disjoint token sources:
|
|
152
|
+
* 1. folded prior-stage orchestrator tokens (`lane.stageUsage` — `foldStageUsage`
|
|
153
|
+
* moves a stage's tokens here BEFORE `clearUnitLanes` empties `units`, so the two
|
|
154
|
+
* never overlap);
|
|
155
|
+
* 2. the CURRENT stage's live/retained orchestrator units (`sumLaneUsage(units)`);
|
|
156
|
+
* 3. the run's recorded subagent contribution (`getSubagentUsageForRun`).
|
|
157
|
+
* Shared by the per-row tally (`renderLaneRow`) and the run grand total (`sumRunUsage`
|
|
158
|
+
* → `renderHeading`) so the heading and the rows can never disagree — and both agree
|
|
159
|
+
* with the sum of `renderStageBreakdown`'s per-stage lines, which read the same three
|
|
160
|
+
* sources stage-by-stage. Returns undefined when no source carries usage. */
|
|
161
|
+
function laneUsageTotal(lane: LaneEntry): LaneUsage | undefined {
|
|
162
|
+
let folded: LaneUsage | undefined;
|
|
163
|
+
for (const usage of lane.stageUsage.values()) folded = addLaneUsage(folded, usage);
|
|
164
|
+
return addLaneUsage(addLaneUsage(folded, sumLaneUsage(lane.units.values())), getSubagentUsageForRun(lane.runId));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Run-level token aggregate across every lane — folds each lane's `laneUsageTotal`
|
|
168
|
+
* (orchestrator units + subagent contribution) through `addLaneUsage`: 4-way sum,
|
|
169
|
+
* recomputed `total`, `cost` accumulated when any side carries it, `percent` dropped.
|
|
170
|
+
* Returns undefined when no lane carries usage. */
|
|
171
|
+
function sumRunUsage(lanes: Iterable<LaneEntry>): LaneUsage | undefined {
|
|
172
|
+
let acc: LaneUsage | undefined;
|
|
173
|
+
for (const lane of lanes) {
|
|
174
|
+
acc = addLaneUsage(acc, laneUsageTotal(lane));
|
|
175
|
+
}
|
|
176
|
+
return acc;
|
|
177
|
+
}
|
|
178
|
+
|
|
148
179
|
/** The compact CAP + lane-region budget, computed from the terminal size. `totalRows` is
|
|
149
180
|
* min(MAX_DOCK_ROWS, terminal.rows); `laneCap` is the lane region, bounded by MAX_WIDGET_LINES
|
|
150
181
|
* - 1 so the list never grows unbounded. Both surfaces size the lane block with the SAME
|
|
@@ -242,12 +273,19 @@ function renderProgressRow(
|
|
|
242
273
|
width: number,
|
|
243
274
|
reason?: string,
|
|
244
275
|
usage?: LaneUsage,
|
|
276
|
+
lastArtifact?: string,
|
|
245
277
|
): string {
|
|
246
278
|
let nameRaw = progress.stageName;
|
|
247
279
|
if (progress.phase === "retry" && progress.attempt !== undefined) nameRaw += ` · retry ${progress.attempt}`;
|
|
248
280
|
if (progress.units) nameRaw += ` · units ${progress.units.done}/${progress.units.total}`;
|
|
249
281
|
const usageTally = formatUsageTally(usage);
|
|
250
282
|
if (usageTally) nameRaw += ` · ${usageTally}`;
|
|
283
|
+
// The run's primary artifact path (a `produces` stage emitted one) — rendered as a
|
|
284
|
+
// trailing `→ path` segment AFTER the usage tally so a completed row points at what
|
|
285
|
+
// it built. Inherits `muted` via the single theme.fg("muted", nameRaw) wrap below,
|
|
286
|
+
// same as the tally. Omitted entirely when `lastArtifact` is undefined, so a
|
|
287
|
+
// side-effect-only run renders byte-identical to before this field existed.
|
|
288
|
+
if (lastArtifact) nameRaw += ` → ${lastArtifact}`;
|
|
251
289
|
|
|
252
290
|
const coloredName = theme.fg("muted", nameRaw);
|
|
253
291
|
const coreW = visibleWidth(prefix) + visibleWidth(nameRaw);
|
|
@@ -304,7 +342,8 @@ function renderLaneRow(
|
|
|
304
342
|
|
|
305
343
|
if (needs) return `${prefix}${theme.fg("warning", "needs input")}`;
|
|
306
344
|
const reason = shortFailureReason(lane.error ?? (progress?.phase === "error" ? progress.reason : undefined));
|
|
307
|
-
if (progress)
|
|
345
|
+
if (progress)
|
|
346
|
+
return renderProgressRow(theme, prefix, progress, width, reason, laneUsageTotal(lane), lane.lastArtifact);
|
|
308
347
|
const label = running ? "streaming…" : lane.status;
|
|
309
348
|
const tail = reason ? `${theme.fg("muted", label)}${theme.fg("warning", ` — ${reason}`)}` : theme.fg("muted", label);
|
|
310
349
|
return `${prefix}${tail}`;
|
|
@@ -327,7 +366,10 @@ function renderHeading(theme: Theme, width: number): string {
|
|
|
327
366
|
headText = activeCount > 0 ? `Runs (${activeCount} active)` : `Runs (${allLanes.length})`;
|
|
328
367
|
}
|
|
329
368
|
const titleIcon = anyNeedsInput ? `${theme.fg("warning", "●")} ` : "";
|
|
330
|
-
|
|
369
|
+
const chip = theme.bg("selectedBg", ` ${headText} `);
|
|
370
|
+
const tally = formatUsageTally(sumRunUsage(allLanes));
|
|
371
|
+
const tallyStr = tally ? theme.fg("muted", ` ${tally}`) : "";
|
|
372
|
+
return truncateToWidth(` ${titleIcon}${chip}${tallyStr}`, width, "…");
|
|
331
373
|
}
|
|
332
374
|
|
|
333
375
|
/**
|
|
@@ -388,3 +430,37 @@ export function renderLiveOutputBorder(theme: Theme, width: number): string {
|
|
|
388
430
|
if (remaining >= 0) return theme.fg("dim", label + "─".repeat(remaining));
|
|
389
431
|
return theme.fg("dim", truncateToWidth(label, Math.max(0, width)));
|
|
390
432
|
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Render the per-stage token breakdown for ONE lane (console-only — the ambient dock
|
|
436
|
+
* never calls this, so its capped region is unchanged). Reads the lane LIVE; a missing
|
|
437
|
+
* or evicted lane yields []. Stages appear in execution order: stageUsage insertion
|
|
438
|
+
* order (folded prior stages), then the current stage name if not already present.
|
|
439
|
+
*
|
|
440
|
+
* Each stage's unified usage folds three sources through addLaneUsage (the token-source
|
|
441
|
+
* partitioning invariant — orchestrator + subagent are unified ONLY here, never in storage):
|
|
442
|
+
* 1. the folded stageUsage bucket (prior stages' tokens, retained across clearUnitLanes);
|
|
443
|
+
* 2. the CURRENT stage's live units (added at read time, since no fold fires for a running
|
|
444
|
+
* stage — sumLaneUsage(lane.units.values()) when this stage is the active one, else
|
|
445
|
+
* undefined for a completed stage whose units were already folded + cleared);
|
|
446
|
+
* 3. the stage's subagent contribution (getSubagentUsageForStage).
|
|
447
|
+
* A stage with zero net usage (empty tally) is omitted; returns [] when no stage carries
|
|
448
|
+
* usage. Each rendered line reuses the SAME formatUsageTally idiom the lane row uses.
|
|
449
|
+
*/
|
|
450
|
+
export function renderStageBreakdown(theme: Theme, width: number, runId: string): string[] {
|
|
451
|
+
const lane = getLane(runId);
|
|
452
|
+
if (!lane) return [];
|
|
453
|
+
const currentName = lane.progress?.stageName;
|
|
454
|
+
// Execution order: folded stages in insertion order, then the current stage if new.
|
|
455
|
+
const stageNames: string[] = [...lane.stageUsage.keys()];
|
|
456
|
+
if (currentName && !stageNames.includes(currentName)) stageNames.push(currentName);
|
|
457
|
+
const lines: string[] = [];
|
|
458
|
+
for (const name of stageNames) {
|
|
459
|
+
const folded = lane.stageUsage.get(name);
|
|
460
|
+
const live = name === currentName ? sumLaneUsage(lane.units.values()) : undefined;
|
|
461
|
+
const total = addLaneUsage(addLaneUsage(folded, live), getSubagentUsageForStage(runId, name));
|
|
462
|
+
const tally = formatUsageTally(total);
|
|
463
|
+
if (tally) lines.push(truncateToWidth(` ${theme.fg("muted", `${name} ${tally}`)}`, width, "…"));
|
|
464
|
+
}
|
|
465
|
+
return lines;
|
|
466
|
+
}
|
|
@@ -39,6 +39,7 @@ import { shortFailureReason } from "./lane-failure.js";
|
|
|
39
39
|
import { isLaneRelayUiContext } from "./lane-relay-ui.js";
|
|
40
40
|
import {
|
|
41
41
|
clearUnitLanes,
|
|
42
|
+
foldStageUsage,
|
|
42
43
|
getLane,
|
|
43
44
|
markUnitDone,
|
|
44
45
|
retireRun,
|
|
@@ -125,6 +126,7 @@ export async function registerLaneProgress(): Promise<void> {
|
|
|
125
126
|
// loop's onLoopStart only drops the gate, it never cleared the prior generation).
|
|
126
127
|
// clearUnitLanes is a no-op on an empty map, so the first stage of a run pays nothing.
|
|
127
128
|
onStageStart: (stage, ctx) => {
|
|
129
|
+
foldStageUsage(ctx.runId);
|
|
128
130
|
clearUnitLanes(ctx.runId);
|
|
129
131
|
setLaneProgress(ctx.runId, { stageName: stage.name, phase: "running" });
|
|
130
132
|
},
|
|
@@ -146,6 +148,7 @@ export async function registerLaneProgress(): Promise<void> {
|
|
|
146
148
|
// generation. A non-fan-out loop (iterate/assess/verify) drops the gate so its
|
|
147
149
|
// sequential units never materialize sub-rows.
|
|
148
150
|
if (info.kind === "fanout") {
|
|
151
|
+
foldStageUsage(ctx.runId);
|
|
149
152
|
clearUnitLanes(ctx.runId);
|
|
150
153
|
fanoutRuns.add(ctx.runId);
|
|
151
154
|
// Fan out the generation's unit sub-rows as PENDING the instant onLoopStart
|
|
@@ -219,12 +222,16 @@ export async function registerLaneProgress(): Promise<void> {
|
|
|
219
222
|
// `termination.error` is the readable cause (the same text as the trail's
|
|
220
223
|
// errMsg) — retain it on the lane for the dock chip + viewer header.
|
|
221
224
|
const error = result.termination?.error;
|
|
225
|
+
// `lastArtifact` is the primary artifact's canonical path (a `produces`
|
|
226
|
+
// stage emitted one) — retained on the lane so a completed row can render
|
|
227
|
+
// `→ .rpiv/artifacts/<bucket>/<file>.md`. Undefined for side-effect-only runs.
|
|
228
|
+
const lastArtifact = result.lastArtifact;
|
|
222
229
|
// Sweep any unit that never fired onUnitEnd (abort/throw) to the run's terminal
|
|
223
230
|
// kind BEFORE retiring, so a failed run's stuck sub-rows read ✗ (retireRun's
|
|
224
231
|
// running→done fallback then no-ops on them). Drop the gate — the run is over.
|
|
225
232
|
sweepRunningUnits(ctx.runId, status === "completed" ? "done" : "failed");
|
|
226
233
|
fanoutRuns.delete(ctx.runId);
|
|
227
|
-
retireRun(ctx.runId, status, error);
|
|
234
|
+
retireRun(ctx.runId, status, error, lastArtifact);
|
|
228
235
|
const ui = getCapturedUiContext();
|
|
229
236
|
if (!ui) return;
|
|
230
237
|
if (status === "completed") ui.notify(`✓ ${name} finished — /lanes to view`, "info");
|
|
@@ -12,8 +12,14 @@
|
|
|
12
12
|
* inline question answering — so the belowEditor dock is never itself "activated".
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import type {
|
|
15
|
+
import type {
|
|
16
|
+
ExtensionAPI,
|
|
17
|
+
ExtensionContext,
|
|
18
|
+
ExtensionUIContext,
|
|
19
|
+
KeybindingsManager,
|
|
20
|
+
} from "@earendil-works/pi-coding-agent";
|
|
16
21
|
import type { EditorTheme, KeyId, TUI } from "@earendil-works/pi-tui";
|
|
22
|
+
import type { WorkflowHostContext } from "@juicesharp/rpiv-workflow";
|
|
17
23
|
import { showLaneConsole } from "./lane-console.js";
|
|
18
24
|
import { LaneDock } from "./lane-dock.js";
|
|
19
25
|
import { LaneDockEditor } from "./lane-dock-editor.js";
|
|
@@ -26,6 +32,7 @@ import {
|
|
|
26
32
|
setFocusedRun,
|
|
27
33
|
subscribeLanes,
|
|
28
34
|
} from "./run-lane-registry.js";
|
|
35
|
+
import { isModuleNotFound } from "./utils.js";
|
|
29
36
|
|
|
30
37
|
/**
|
|
31
38
|
* Root hotkey that opens the lane switcher, registered via Pi's `registerShortcut`
|
|
@@ -54,6 +61,16 @@ let unsubscribe: (() => void) | undefined;
|
|
|
54
61
|
/** The launcher UI that owns the dock editor — kept so __resetLaneSwitcher can
|
|
55
62
|
* restore Pi's default editor. Set once per ctx identity at session_start. */
|
|
56
63
|
let editorCtx: ExtensionUIContext | undefined;
|
|
64
|
+
/** The rerun callback the lane console calls on `r` — built in session_start (where pi/ui
|
|
65
|
+
* are in scope) from the captured launcher cwd + sessionManager. Undefined before the first
|
|
66
|
+
* root session_start (the console passes a no-op then). */
|
|
67
|
+
let rerunCallback: ((runId: string) => void) | undefined;
|
|
68
|
+
/** Launcher cwd captured at session_start — the WorkflowHostContext.cwd the rerun's
|
|
69
|
+
* resumeWorkflowByRunId resolves the run-id against (resolveRun/loadWorkflows read it). */
|
|
70
|
+
let launcherCwd: string | undefined;
|
|
71
|
+
/** Launcher sessionManager captured at session_start — the WorkflowHostContext.sessionManager
|
|
72
|
+
* the detached executor host borrows as its live observer. */
|
|
73
|
+
let launcherSessionManager: ExtensionContext["sessionManager"] | undefined;
|
|
57
74
|
/** Guard so a second ⏎ never stacks a second console (re-entrancy belt-and-braces;
|
|
58
75
|
* while a console is open the editor isn't focused, so this rarely trips). */
|
|
59
76
|
let switchingLane = false;
|
|
@@ -70,7 +87,7 @@ function stepIn(ui: ExtensionUIContext): void {
|
|
|
70
87
|
const top = listLanesForDisplay()[0];
|
|
71
88
|
if (!top) return;
|
|
72
89
|
const unitIndex = top.kind === "unit" ? top.unit.index : SINGLE_UNIT_KEY;
|
|
73
|
-
void switchIntoLane(ui, top.lane.runId, unitIndex);
|
|
90
|
+
void switchIntoLane(ui, top.lane.runId, unitIndex, rerunCallback ?? (() => {}));
|
|
74
91
|
}
|
|
75
92
|
|
|
76
93
|
/**
|
|
@@ -83,7 +100,12 @@ function stepIn(ui: ExtensionUIContext): void {
|
|
|
83
100
|
* can't strand focus (which would leave Ctrl-C hijacked at root). Called by the dock editor's
|
|
84
101
|
* `onOpen` and by `stepIn`.
|
|
85
102
|
*/
|
|
86
|
-
export async function switchIntoLane(
|
|
103
|
+
export async function switchIntoLane(
|
|
104
|
+
ui: ExtensionUIContext,
|
|
105
|
+
runId: string,
|
|
106
|
+
unitIndex: number,
|
|
107
|
+
onRerun: (runId: string) => void = () => {},
|
|
108
|
+
): Promise<void> {
|
|
87
109
|
if (switchingLane) return; // never stack two consoles
|
|
88
110
|
switchingLane = true;
|
|
89
111
|
setFocusedRun(runId);
|
|
@@ -91,7 +113,7 @@ export async function switchIntoLane(ui: ExtensionUIContext, runId: string, unit
|
|
|
91
113
|
// dock below would duplicate it — hide it for the duration.
|
|
92
114
|
dock?.setSuppressed(true);
|
|
93
115
|
try {
|
|
94
|
-
await showLaneConsole(ui, runId, unitIndex); // the lane browser: spine + transcript + inline question
|
|
116
|
+
await showLaneConsole(ui, runId, unitIndex, onRerun); // the lane browser: spine + transcript + inline question
|
|
95
117
|
} finally {
|
|
96
118
|
dock?.setSuppressed(false);
|
|
97
119
|
setFocusedRun(undefined);
|
|
@@ -102,35 +124,91 @@ export async function switchIntoLane(ui: ExtensionUIContext, runId: string, unit
|
|
|
102
124
|
export function registerLaneSwitcher(pi: ExtensionAPI): void {
|
|
103
125
|
const hotkey = resolveHotkey();
|
|
104
126
|
|
|
105
|
-
pi.on(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
127
|
+
pi.on(
|
|
128
|
+
"session_start",
|
|
129
|
+
async (
|
|
130
|
+
_event: unknown,
|
|
131
|
+
ctx: {
|
|
132
|
+
hasUI?: boolean;
|
|
133
|
+
ui?: ExtensionUIContext;
|
|
134
|
+
cwd?: string;
|
|
135
|
+
sessionManager?: ExtensionContext["sessionManager"];
|
|
136
|
+
},
|
|
137
|
+
) => {
|
|
138
|
+
// A detached child re-loads rpiv-core and re-fires this hook with its
|
|
139
|
+
// bound relay ui. Skip it — only the ROOT launcher owns the ambient dock +
|
|
140
|
+
// registry subscription. A child mounting its own dock would re-point the
|
|
141
|
+
// shared singleton at its relay and clobber the launcher's `rpiv-lanes` widget.
|
|
142
|
+
if (!ctx.hasUI || !ctx.ui || isLaneRelayUiContext(ctx.ui)) return;
|
|
143
|
+
const ui = ctx.ui;
|
|
144
|
+
// Capture the launcher cwd + sessionManager so the `r` rerun callback can build the
|
|
145
|
+
// observer-only WorkflowHostContext resumeWorkflowByRunId needs (resolveRun +
|
|
146
|
+
// loadWorkflows read cwd; the detached executor host borrows sessionManager as its
|
|
147
|
+
// live observer). Re-captured on every root session_start (/reload) like editorCtx.
|
|
148
|
+
launcherCwd = ctx.cwd;
|
|
149
|
+
launcherSessionManager = ctx.sessionManager;
|
|
150
|
+
// Build the rerun callback here (ui in scope): resume a failed/aborted/cancelled run
|
|
151
|
+
// by its run-id via a guarded dynamic import of the workflow runner. Degrades silently
|
|
152
|
+
// when rpiv-workflow is absent (isModuleNotFound) — /rpiv-setup guides the user. The
|
|
153
|
+
// async resume is fire-and-forget; the failed→running lane flip is subscription-driven
|
|
154
|
+
// (recordRun reactivation via the lane lifecycle), so the console does NOT await it.
|
|
155
|
+
rerunCallback = (runId: string): void => {
|
|
156
|
+
void (async () => {
|
|
157
|
+
try {
|
|
158
|
+
// Guarded dynamic import — degrades silently when rpiv-workflow is absent
|
|
159
|
+
// (isModuleNotFound); /rpiv-setup guides the user. The /runner entry keeps the
|
|
160
|
+
// loader/DSL graph off the import (sibling-import-graph permits the dynamic form).
|
|
161
|
+
const runner = await import("@juicesharp/rpiv-workflow/runner");
|
|
162
|
+
// Observer-only ctx: the detached executor provider supplies spawnChild/
|
|
163
|
+
// maxConcurrency (registered on the root session_start by workflow-execution-host).
|
|
164
|
+
// The double cast is required — the object omits spawnChild/maxConcurrency, so a
|
|
165
|
+
// single `as WorkflowHostContext` fails TS2352 (mirrors the as-unknown-as cast in
|
|
166
|
+
// workflow-execution-host.ts). cwd/sessionManager are the real captured launcher values.
|
|
167
|
+
const hostCtx = {
|
|
168
|
+
cwd: launcherCwd,
|
|
169
|
+
hasUI: true,
|
|
170
|
+
ui: { notify: (m: string, l?: "info" | "warning" | "error") => ui.notify(m, l) },
|
|
171
|
+
sessionManager: launcherSessionManager,
|
|
172
|
+
waitForIdle: () => Promise.resolve(),
|
|
173
|
+
} as unknown as WorkflowHostContext;
|
|
174
|
+
void runner
|
|
175
|
+
.resumeWorkflowByRunId(hostCtx, runId)
|
|
176
|
+
.then((r) => {
|
|
177
|
+
// Surface ONLY a pre-run refusal (no JSONL created) — an in-run failure is
|
|
178
|
+
// notified by the stage machinery; a success reactivates the lane reactively.
|
|
179
|
+
// r.runId === undefined distinguishes a refusal (resolveRun/load miss).
|
|
180
|
+
if (!r.success && r.runId === undefined && r.error) ui.notify(r.error, "error");
|
|
181
|
+
})
|
|
182
|
+
.catch((e) => ui.notify(`rpiv: resume failed — ${String(e)}`, "error"));
|
|
183
|
+
} catch (err) {
|
|
184
|
+
if (!isModuleNotFound(err)) console.error("[rpiv-core] failed to load workflow runner:", err);
|
|
185
|
+
return; // sibling absent — /rpiv-setup guides the user
|
|
186
|
+
}
|
|
187
|
+
})();
|
|
188
|
+
};
|
|
189
|
+
dock ??= new LaneDock();
|
|
190
|
+
dock.setUICtx(ui);
|
|
191
|
+
dock.update();
|
|
192
|
+
// Subscribe once: re-render the dock on any registry change (run recorded/
|
|
193
|
+
// evicted, status, current session, needs-input, dock selection).
|
|
194
|
+
unsubscribe ??= subscribeLanes(() => dock?.update());
|
|
195
|
+
// Install the dock editor once per ctx identity (re-install on /reload). It
|
|
196
|
+
// proxies dock navigation; ⏎ on a selected lane switches into it. The host
|
|
197
|
+
// preserves editor text + app keybindings across the swap.
|
|
198
|
+
if (ui !== editorCtx) {
|
|
199
|
+
editorCtx = ui;
|
|
200
|
+
ui.setEditorComponent(
|
|
201
|
+
(tui: TUI, theme: EditorTheme, keybindings: KeybindingsManager) =>
|
|
202
|
+
new LaneDockEditor(
|
|
203
|
+
tui,
|
|
204
|
+
theme,
|
|
205
|
+
keybindings,
|
|
206
|
+
(runId, unitIndex) => void switchIntoLane(ui, runId, unitIndex, rerunCallback ?? (() => {})),
|
|
207
|
+
),
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
);
|
|
134
212
|
|
|
135
213
|
pi.registerCommand("lanes", {
|
|
136
214
|
description: "Open the workflow run lane browser",
|
|
@@ -173,4 +251,7 @@ export function __resetLaneSwitcher(): void {
|
|
|
173
251
|
editorCtx = undefined;
|
|
174
252
|
dock?.dispose();
|
|
175
253
|
dock = undefined;
|
|
254
|
+
rerunCallback = undefined;
|
|
255
|
+
launcherCwd = undefined;
|
|
256
|
+
launcherSessionManager = undefined;
|
|
176
257
|
}
|
|
@@ -81,6 +81,31 @@ export function toLaneUsage(stats: unknown): LaneUsage | undefined {
|
|
|
81
81
|
return usage;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
/**
|
|
85
|
+
* Pairwise sum of two `LaneUsage` (or the defined side when one is `undefined`):
|
|
86
|
+
* sums the 4 token dimensions + recomputes `total` (= sum of all four), threads the
|
|
87
|
+
* scalar `cost` when EITHER side carries it, and drops `percent` (a context-window
|
|
88
|
+
* fill ratio is not meaningfully summable). Returns `undefined` only when BOTH are
|
|
89
|
+
* absent — the identity element of the sum — so folding through it is a no-op.
|
|
90
|
+
*
|
|
91
|
+
* Created once here and consumed by every token-accounting consumer —
|
|
92
|
+
* the single canonical pairwise sum, so the per-row tally, the run grand total, and
|
|
93
|
+
* the stage breakdown can never diverge. `addLaneUsage(undefined, x) === x`, so it
|
|
94
|
+
* composes a run/stage/lane roll-up uniformly whether a side carries usage or not.
|
|
95
|
+
*/
|
|
96
|
+
export function addLaneUsage(a?: LaneUsage, b?: LaneUsage): LaneUsage | undefined {
|
|
97
|
+
if (!a && !b) return undefined;
|
|
98
|
+
if (!a) return b;
|
|
99
|
+
if (!b) return a;
|
|
100
|
+
const input = a.input + b.input;
|
|
101
|
+
const output = a.output + b.output;
|
|
102
|
+
const cacheRead = a.cacheRead + b.cacheRead;
|
|
103
|
+
const cacheWrite = a.cacheWrite + b.cacheWrite;
|
|
104
|
+
const result: LaneUsage = { input, output, cacheRead, cacheWrite, total: input + output + cacheRead + cacheWrite };
|
|
105
|
+
if (a.cost !== undefined || b.cost !== undefined) result.cost = (a.cost ?? 0) + (b.cost ?? 0);
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
|
|
84
109
|
/**
|
|
85
110
|
* Format a token count in pi's footer idiom — ported verbatim from the SDK's
|
|
86
111
|
* `footer.js:17-29` (`formatTokens`): `<1e3` bare · `<1e4` `N.Nk` · `<1e6`
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* models-config-validate — session_start warn-on-miss for models.json keys.
|
|
3
3
|
*
|
|
4
4
|
* Record-key typos (`skills.committ`, `agents.codebase-analzyer`,
|
|
5
|
-
* `presets.
|
|
5
|
+
* `presets.buildd`) pass TypeBox validation (records are structurally dynamic)
|
|
6
6
|
* and silently fall through to the defaults cascade — the override the user
|
|
7
7
|
* meant to set just never applies, with no feedback. This hook surfaces them
|
|
8
8
|
* once per process via `console.warn`.
|
|
@@ -118,7 +118,7 @@ const PresetSchema = Type.Object(
|
|
|
118
118
|
* names within that workflow.
|
|
119
119
|
*
|
|
120
120
|
* `Type.Record(Type.String(), …)` wrappers are structurally dynamic and cannot
|
|
121
|
-
* stamp `additionalProperties: false` — record-key typos (`presets.
|
|
121
|
+
* stamp `additionalProperties: false` — record-key typos (`presets.buildd`,
|
|
122
122
|
* `skills.committ`) pass schema validation by design and fall through to the
|
|
123
123
|
* defaults cascade at lookup. `findUnknownModelKeys` (wired into session_start
|
|
124
124
|
* by models-config-validate.ts) is the runtime warn-on-miss safety net.
|
|
@@ -374,8 +374,8 @@ export interface KnownModelKeys {
|
|
|
374
374
|
|
|
375
375
|
/**
|
|
376
376
|
* Return dotted paths of configured models.json keys that match no known key —
|
|
377
|
-
* e.g. `skills.committ`, `agents.codebase-analzyer`, `presets.
|
|
378
|
-
* `presets.
|
|
377
|
+
* e.g. `skills.committ`, `agents.codebase-analzyer`, `presets.buildd`,
|
|
378
|
+
* `presets.build.stages.plann`. Record-key typos pass TypeBox validation
|
|
379
379
|
* (records are structurally dynamic) and silently fall through to the defaults
|
|
380
380
|
* cascade; this surfaces them. Axes with an `undefined` known-list are skipped;
|
|
381
381
|
* an unknown preset workflow short-circuits (its inner stages aren't validated
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
import { isModuleNotFound } from "./utils.js";
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
|
-
* Register the
|
|
24
|
+
* Register the three built-in workflows (build / polish / vet)
|
|
25
25
|
* with the rpiv-workflow runtime, if that sibling is installed. A missing
|
|
26
26
|
* sibling resolves to a no-op; any other failure is re-thrown so genuine bugs
|
|
27
27
|
* surface rather than hiding behind the absent-sibling path.
|
|
@@ -29,7 +29,7 @@ import { isModuleNotFound } from "./utils.js";
|
|
|
29
29
|
export async function registerBuiltInWorkflows(): Promise<void> {
|
|
30
30
|
try {
|
|
31
31
|
// Thin `/startup` entry (~9ms, no DSL/runner). Register a LAZY provider so
|
|
32
|
-
// `built-in-workflows.js` (the ~180ms authoring-DSL graph) builds the
|
|
32
|
+
// `built-in-workflows.js` (the ~180ms authoring-DSL graph) builds the three
|
|
33
33
|
// definitions on first `/wf`, not at startup. Missing sibling →
|
|
34
34
|
// ERR_MODULE_NOT_FOUND → no-op (no `/wf` without it).
|
|
35
35
|
const { registerBuiltInsProvider, registerBuiltIns } = await import("@juicesharp/rpiv-workflow/startup");
|