@juicesharp/rpiv-pi 2.1.0 → 2.3.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 +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/bash-timeout.ts +16 -0
- package/extensions/rpiv-core/built-in-workflows.ts +2289 -318
- package/extensions/rpiv-core/guidance.ts +35 -19
- package/extensions/rpiv-core/index.ts +2 -2
- package/extensions/rpiv-core/lane-console.ts +62 -5
- package/extensions/rpiv-core/lane-list.ts +84 -32
- package/extensions/rpiv-core/lane-progress.ts +13 -77
- 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 +38 -3
- package/extensions/rpiv-core/register-built-in-workflows.ts +2 -2
- package/extensions/rpiv-core/run-lane-registry.ts +80 -69
- package/extensions/rpiv-core/sdk-workflow-host.ts +43 -3
- package/extensions/rpiv-core/subagent-usage.ts +147 -0
- package/extensions/rpiv-core/workflow-execution-host.ts +24 -7
- package/package.json +3 -3
- package/skills/amend/SKILL.md +7 -3
- package/skills/annotate-guidance/SKILL.md +1 -0
- package/skills/architecture-review/SKILL.md +1 -0
- package/skills/blueprint/SKILL.md +10 -4
- package/skills/changelog/SKILL.md +1 -0
- package/skills/commit/SKILL.md +1 -0
- package/skills/design/SKILL.md +4 -3
- package/skills/design-review/SKILL.md +1 -0
- package/skills/design-slice/SKILL.md +2 -1
- package/skills/discover/SKILL.md +1 -1
- package/skills/elaborate/SKILL.md +21 -9
- package/skills/elaborate/_helpers/validate-workflow-invariant.mjs +88 -0
- package/skills/explore/SKILL.md +1 -0
- package/skills/frontend-design/SKILL.md +1 -0
- package/skills/grade/SKILL.md +24 -6
- package/skills/implement/SKILL.md +10 -2
- package/skills/plan/SKILL.md +10 -6
- package/skills/research/SKILL.md +9 -8
- package/skills/resume-handoff/SKILL.md +1 -0
- package/skills/revise/SKILL.md +1 -0
- package/skills/slice/SKILL.md +4 -3
- package/skills/synthesize/SKILL.md +16 -7
- package/skills/validate/SKILL.md +1 -0
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
* `resolveGuidance` is pure logic with no ExtensionAPI references
|
|
16
16
|
* (utility-module rule from extensions/rpiv-core/CLAUDE.md). Side
|
|
17
17
|
* effects (sendMessage, in-memory dedup Set) live in
|
|
18
|
-
* `handleToolCallGuidance
|
|
19
|
-
* `clearInjectionState`.
|
|
18
|
+
* `handleToolCallGuidance` (sendMessage only), `resolveAndFormatNewGuidance`
|
|
19
|
+
* and `injectRootGuidance` (dedup-Set owners), and `clearInjectionState`.
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
import { existsSync, readFileSync } from "node:fs";
|
|
@@ -160,8 +160,37 @@ export function injectRootGuidance(cwd: string, pi: ExtensionAPI): void {
|
|
|
160
160
|
// ---------------------------------------------------------------------------
|
|
161
161
|
|
|
162
162
|
/**
|
|
163
|
-
*
|
|
164
|
-
*
|
|
163
|
+
* Resolve, dedup, mark, and format guidance for a touched file — the "build"
|
|
164
|
+
* half of tool-call injection (no `ExtensionAPI`, no `sendMessage`). Owns the
|
|
165
|
+
* `injectedGuidance` Set read+mark so the dedup filter and the mark step stay
|
|
166
|
+
* in one function: marking before returning content lets the caller send with
|
|
167
|
+
* idempotence > reliability.
|
|
168
|
+
*
|
|
169
|
+
* Returns the `"\n\n---\n\n"`-joined formatted blocks, or `null` when nothing
|
|
170
|
+
* resolves along the ladder OR every resolved file is already injected (marks
|
|
171
|
+
* nothing in the null cases).
|
|
172
|
+
*/
|
|
173
|
+
export function resolveAndFormatNewGuidance(filePath: string, cwd: string, toolName: string): string | null {
|
|
174
|
+
const resolved = resolveGuidance(filePath, cwd);
|
|
175
|
+
const newFiles = resolved.filter((g) => !injectedGuidance.has(g.relativePath));
|
|
176
|
+
if (newFiles.length === 0) return null;
|
|
177
|
+
|
|
178
|
+
// Mark before send — idempotence > reliability.
|
|
179
|
+
for (const g of newFiles) {
|
|
180
|
+
injectedGuidance.add(g.relativePath);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const trigger = `auto-loaded because ${toolName} touched ${shortenPath(filePath, cwd)}`;
|
|
184
|
+
const contextParts = newFiles.map((g) => wrapGuidance(formatLabel(g), g.content, trigger));
|
|
185
|
+
|
|
186
|
+
return contextParts.join("\n\n---\n\n");
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Handle guidance injection on tool_call events for read/edit/write — a thin
|
|
191
|
+
* wiring pipeline: filter → extract → delegate → send. Resolve/dedup/mark/format
|
|
192
|
+
* live in `resolveAndFormatNewGuidance`; this handler adds no direct
|
|
193
|
+
* `injectedGuidance` reference.
|
|
165
194
|
*/
|
|
166
195
|
export function handleToolCallGuidance(
|
|
167
196
|
event: { toolName: string; input: Record<string, unknown> },
|
|
@@ -173,21 +202,8 @@ export function handleToolCallGuidance(
|
|
|
173
202
|
const filePath = (event.input as any).file_path ?? (event.input as any).path;
|
|
174
203
|
if (!filePath) return;
|
|
175
204
|
|
|
176
|
-
const
|
|
177
|
-
if (
|
|
178
|
-
|
|
179
|
-
const newFiles = resolved.filter((g) => !injectedGuidance.has(g.relativePath));
|
|
180
|
-
if (newFiles.length === 0) return;
|
|
181
|
-
|
|
182
|
-
// Mark before sendMessage — idempotence > reliability.
|
|
183
|
-
for (const g of newFiles) {
|
|
184
|
-
injectedGuidance.add(g.relativePath);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
const trigger = `auto-loaded because ${event.toolName} touched ${shortenPath(filePath, ctx.cwd)}`;
|
|
188
|
-
const contextParts = newFiles.map((g) => wrapGuidance(formatLabel(g), g.content, trigger));
|
|
189
|
-
|
|
190
|
-
sendGuidanceMessage(pi, contextParts.join("\n\n---\n\n"));
|
|
205
|
+
const content = resolveAndFormatNewGuidance(filePath, ctx.cwd, event.toolName);
|
|
206
|
+
if (content !== null) sendGuidanceMessage(pi, content);
|
|
191
207
|
}
|
|
192
208
|
|
|
193
209
|
/**
|
|
@@ -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. */
|
|
@@ -51,25 +53,17 @@ export const SPIN_INTERVAL_MS = 160;
|
|
|
51
53
|
const CURSOR_SELECTED = "❯ ";
|
|
52
54
|
const CURSOR_UNSELECTED = " ";
|
|
53
55
|
|
|
54
|
-
/** Mini stage-progress bar: filled/empty cells, capped + scaled for big workflows. */
|
|
55
|
-
const BAR_FILLED = "▰";
|
|
56
|
-
const BAR_EMPTY = "▱";
|
|
57
|
-
const BAR_MAX_CELLS = 7;
|
|
58
56
|
/** Minimum leftover display columns to bother showing a failure-reason chip. */
|
|
59
57
|
const MIN_REASON_WIDTH = 6;
|
|
60
|
-
/** Lap marker (`↻7`) for the path ordinal — shown ONLY once the walk has re-entered a stage
|
|
61
|
-
* (`stageNumber > visited`) so an acyclic run stays a clean `3/4` with no marker. */
|
|
62
|
-
const LAP_MARK = "↻";
|
|
63
58
|
/** Retry glyph (onStageRetry); running uses the spinner, error the failed glyph. */
|
|
64
59
|
const RETRY_GLYPH = "⟲";
|
|
65
60
|
|
|
66
61
|
// Fixed-width columns (column stability): each leading field is truncated or right-padded to a
|
|
67
|
-
// constant DISPLAY width so the
|
|
62
|
+
// constant DISPLAY width so the status region starts at the same column on every row.
|
|
68
63
|
const TAG_COL = 12;
|
|
69
64
|
const MAX_LABEL_WIDTH = 40;
|
|
70
65
|
const LABEL_LEADING = 4 + TAG_COL + 2;
|
|
71
66
|
const PROGRESS_MIN_WIDTH = 12;
|
|
72
|
-
const NUM_COL = 5;
|
|
73
67
|
|
|
74
68
|
/** Per-status glyph; needs-input overrides it (see renderLaneRow). */
|
|
75
69
|
const STATUS_GLYPH: Record<LaneStatus, string> = {
|
|
@@ -153,6 +147,35 @@ function sumLaneUsage(units: Iterable<UnitLane>): LaneUsage | undefined {
|
|
|
153
147
|
return result;
|
|
154
148
|
}
|
|
155
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
|
+
|
|
156
179
|
/** The compact CAP + lane-region budget, computed from the terminal size. `totalRows` is
|
|
157
180
|
* min(MAX_DOCK_ROWS, terminal.rows); `laneCap` is the lane region, bounded by MAX_WIDGET_LINES
|
|
158
181
|
* - 1 so the list never grows unbounded. Both surfaces size the lane block with the SAME
|
|
@@ -241,8 +264,7 @@ function renderUnitRow(
|
|
|
241
264
|
|
|
242
265
|
/**
|
|
243
266
|
* Render a lane row carrying live stage progress. Width priority under pressure: the
|
|
244
|
-
* `
|
|
245
|
-
* mini-bar (decoration) is dropped FIRST — so a failed row shows its cause before its bar.
|
|
267
|
+
* `stageName` label is always kept; the failure `reason` chip fills what's left.
|
|
246
268
|
*/
|
|
247
269
|
function renderProgressRow(
|
|
248
270
|
theme: Theme,
|
|
@@ -251,41 +273,33 @@ function renderProgressRow(
|
|
|
251
273
|
width: number,
|
|
252
274
|
reason?: string,
|
|
253
275
|
usage?: LaneUsage,
|
|
276
|
+
lastArtifact?: string,
|
|
254
277
|
): string {
|
|
255
|
-
const cells = BAR_MAX_CELLS;
|
|
256
|
-
const visited = progress.visited ?? Math.min(progress.stageNumber, progress.totalStages);
|
|
257
|
-
const ratio = progress.totalStages > 0 ? visited / progress.totalStages : 0;
|
|
258
|
-
const filled = Math.max(0, Math.min(cells, Math.round(ratio * cells)));
|
|
259
|
-
const filledStr = BAR_FILLED.repeat(filled);
|
|
260
|
-
const emptyStr = BAR_EMPTY.repeat(cells - filled);
|
|
261
|
-
|
|
262
|
-
const numRaw = `${visited}/${progress.totalStages}`;
|
|
263
278
|
let nameRaw = progress.stageName;
|
|
264
279
|
if (progress.phase === "retry" && progress.attempt !== undefined) nameRaw += ` · retry ${progress.attempt}`;
|
|
265
|
-
if (progress.stageNumber > visited) nameRaw += ` · ${LAP_MARK}${progress.stageNumber}`;
|
|
266
280
|
if (progress.units) nameRaw += ` · units ${progress.units.done}/${progress.units.total}`;
|
|
267
281
|
const usageTally = formatUsageTally(usage);
|
|
268
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}`;
|
|
269
289
|
|
|
270
|
-
const numCol = padCol(theme, "muted", numRaw, NUM_COL);
|
|
271
290
|
const coloredName = theme.fg("muted", nameRaw);
|
|
272
|
-
const coreW = visibleWidth(prefix) +
|
|
291
|
+
const coreW = visibleWidth(prefix) + visibleWidth(nameRaw);
|
|
273
292
|
|
|
274
293
|
let reasonStr = "";
|
|
275
294
|
if (reason) {
|
|
276
295
|
const leftover = width - coreW;
|
|
277
296
|
if (leftover >= MIN_REASON_WIDTH) reasonStr = theme.fg("warning", truncateToWidth(` — ${reason}`, leftover, "…"));
|
|
278
297
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
const includeBar = cells > 0 && coreW + reasonW + cells + 2 <= width;
|
|
282
|
-
if (!includeBar) return `${prefix}${numCol} ${coloredName}${reasonStr}`;
|
|
283
|
-
const coloredBar = `${theme.fg("accent", filledStr)}${theme.fg("dim", emptyStr)}`;
|
|
284
|
-
return `${prefix}${coloredBar} ${numCol} ${coloredName}${reasonStr}`;
|
|
298
|
+
return `${prefix}${coloredName}${reasonStr}`;
|
|
285
299
|
}
|
|
286
300
|
|
|
287
301
|
/** Render a lane (parent) row: cursor-gutter · status-glyph · workflow-tag · descriptor ·
|
|
288
|
-
* [progress
|
|
302
|
+
* [stage progress / status word]. needs-input wins the glyph + trailing label. */
|
|
289
303
|
function renderLaneRow(
|
|
290
304
|
theme: Theme,
|
|
291
305
|
lane: LaneEntry,
|
|
@@ -328,7 +342,8 @@ function renderLaneRow(
|
|
|
328
342
|
|
|
329
343
|
if (needs) return `${prefix}${theme.fg("warning", "needs input")}`;
|
|
330
344
|
const reason = shortFailureReason(lane.error ?? (progress?.phase === "error" ? progress.reason : undefined));
|
|
331
|
-
if (progress)
|
|
345
|
+
if (progress)
|
|
346
|
+
return renderProgressRow(theme, prefix, progress, width, reason, laneUsageTotal(lane), lane.lastArtifact);
|
|
332
347
|
const label = running ? "streaming…" : lane.status;
|
|
333
348
|
const tail = reason ? `${theme.fg("muted", label)}${theme.fg("warning", ` — ${reason}`)}` : theme.fg("muted", label);
|
|
334
349
|
return `${prefix}${tail}`;
|
|
@@ -351,7 +366,10 @@ function renderHeading(theme: Theme, width: number): string {
|
|
|
351
366
|
headText = activeCount > 0 ? `Runs (${activeCount} active)` : `Runs (${allLanes.length})`;
|
|
352
367
|
}
|
|
353
368
|
const titleIcon = anyNeedsInput ? `${theme.fg("warning", "●")} ` : "";
|
|
354
|
-
|
|
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, "…");
|
|
355
373
|
}
|
|
356
374
|
|
|
357
375
|
/**
|
|
@@ -412,3 +430,37 @@ export function renderLiveOutputBorder(theme: Theme, width: number): string {
|
|
|
412
430
|
if (remaining >= 0) return theme.fg("dim", label + "─".repeat(remaining));
|
|
413
431
|
return theme.fg("dim", truncateToWidth(label, Math.max(0, width)));
|
|
414
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
|
+
}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*
|
|
11
11
|
* Each lifecycle event maps to `setLaneProgress(ctx.runId, …)`:
|
|
12
12
|
* - onStageStart → clear the prior stage's fan-out unit sub-rows (every stage kind; it fires
|
|
13
|
-
* before onLoopStart on a loop stage) + {
|
|
13
|
+
* before onLoopStart on a loop stage) + { stageName, phase: "running" }
|
|
14
14
|
* - onStageRetry → phase "retry" + attempt ("⟲ … retry 2/3")
|
|
15
15
|
* - onStageError → phase "error" (brief — the run then evicts)
|
|
16
16
|
* - onLoopStart → seed units.total (fanout precomputes its unit list); on a
|
|
@@ -39,12 +39,11 @@ 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
|
-
noteVisitedStage,
|
|
45
45
|
retireRun,
|
|
46
46
|
seedPendingUnits,
|
|
47
|
-
seedVisitedStages,
|
|
48
47
|
setLaneProgress,
|
|
49
48
|
setUnitStarted,
|
|
50
49
|
sweepRunningUnits,
|
|
@@ -119,19 +118,6 @@ export async function registerLaneProgress(): Promise<void> {
|
|
|
119
118
|
// loader/DSL/runner graph off startup and avoids the barrel-import race.
|
|
120
119
|
const { registerLifecycle } = await import("@juicesharp/rpiv-workflow/startup");
|
|
121
120
|
g.dispose = registerLifecycle({
|
|
122
|
-
// Fires ONCE per run (new or resumed) BEFORE the chain kicks. On a RESUME the
|
|
123
|
-
// engine reconstructs its distinct-visited set from the trail and re-enters the
|
|
124
|
-
// walk at a deep `stageNumber`, but only re-fires per-stage events from that point
|
|
125
|
-
// forward — so seed the registry's accumulator from `ctx.visited` HERE, otherwise
|
|
126
|
-
// the bridge recounts from zero and a near-done resume renders a misleading "1/17".
|
|
127
|
-
// A fresh run carries an empty `visited`, so this no-ops. The numerator surfaces on
|
|
128
|
-
// the first post-seed `setLaneProgress` (the resumed stage's onStageStart).
|
|
129
|
-
onWorkflowStart: (ctx) => {
|
|
130
|
-
if (ctx.visited?.length) seedVisitedStages(ctx.runId, ctx.visited);
|
|
131
|
-
},
|
|
132
|
-
// `noteVisitedStage` is idempotent per stage name, so calling it from every
|
|
133
|
-
// per-stage event keeps `visited` (the distinct-nodes-visited fraction
|
|
134
|
-
// numerator) correct without inflating on a loop-back — see LaneProgress.
|
|
135
121
|
// onStageStart fires for EVERY stage kind — a plain sequential stage (the single-stage
|
|
136
122
|
// entry announcement, run-stage.ts:221) AND every loop stage, where it fires BEFORE
|
|
137
123
|
// onLoopStart (announceLoopStart, loop.ts:75→78). So retiring the prior stage's fan-out
|
|
@@ -140,24 +126,12 @@ export async function registerLaneProgress(): Promise<void> {
|
|
|
140
126
|
// loop's onLoopStart only drops the gate, it never cleared the prior generation).
|
|
141
127
|
// clearUnitLanes is a no-op on an empty map, so the first stage of a run pays nothing.
|
|
142
128
|
onStageStart: (stage, ctx) => {
|
|
129
|
+
foldStageUsage(ctx.runId);
|
|
143
130
|
clearUnitLanes(ctx.runId);
|
|
144
|
-
setLaneProgress(ctx.runId, {
|
|
145
|
-
stageNumber: stage.stageNumber,
|
|
146
|
-
totalStages: ctx.totalStages,
|
|
147
|
-
visited: noteVisitedStage(ctx.runId, stage.name),
|
|
148
|
-
stageName: stage.name,
|
|
149
|
-
phase: "running",
|
|
150
|
-
});
|
|
131
|
+
setLaneProgress(ctx.runId, { stageName: stage.name, phase: "running" });
|
|
151
132
|
},
|
|
152
133
|
onStageRetry: (stage, attempt, ctx) =>
|
|
153
|
-
setLaneProgress(ctx.runId, {
|
|
154
|
-
stageNumber: stage.stageNumber,
|
|
155
|
-
totalStages: ctx.totalStages,
|
|
156
|
-
visited: noteVisitedStage(ctx.runId, stage.name),
|
|
157
|
-
stageName: stage.name,
|
|
158
|
-
phase: "retry",
|
|
159
|
-
attempt,
|
|
160
|
-
}),
|
|
134
|
+
setLaneProgress(ctx.runId, { stageName: stage.name, phase: "retry", attempt }),
|
|
161
135
|
// Carry the stage's failure cause so the dock row can surface WHY
|
|
162
136
|
// it failed before the run retires — no longer discarded.
|
|
163
137
|
onStageError: (stage, error, ctx) => {
|
|
@@ -166,28 +140,7 @@ export async function registerLaneProgress(): Promise<void> {
|
|
|
166
140
|
// onUnitEnd — flip every still-running sub-row to ✗ so none spins forever.
|
|
167
141
|
sweepRunningUnits(ctx.runId, "failed");
|
|
168
142
|
fanoutRuns.delete(ctx.runId);
|
|
169
|
-
setLaneProgress(ctx.runId, {
|
|
170
|
-
stageNumber: stage.stageNumber,
|
|
171
|
-
totalStages: ctx.totalStages,
|
|
172
|
-
visited: noteVisitedStage(ctx.runId, stage.name),
|
|
173
|
-
stageName: stage.name,
|
|
174
|
-
phase: "error",
|
|
175
|
-
reason: error,
|
|
176
|
-
});
|
|
177
|
-
},
|
|
178
|
-
// A decision edge took its arm: credit each not-taken RECOVERY arm (a
|
|
179
|
-
// failure loop the chosen arm skipped for good — build's slice-fix/plan-fix/code-fix)
|
|
180
|
-
// as visited. This advances the distinct-nodes-visited numerator at the
|
|
181
|
-
// gate, so the bar reaches `totalStages` WHILE the terminal stage runs
|
|
182
|
-
// (commit shows 16/16) instead of capping below until the onWorkflowEnd
|
|
183
|
-
// snap. `noteVisitedStage` is idempotent + the runner already excludes
|
|
184
|
-
// already-visited / forward arms, so this never inflates past the total.
|
|
185
|
-
onRoute: (_from, _to, ctx, bypassed) => {
|
|
186
|
-
if (!bypassed?.length) return;
|
|
187
|
-
let visited = 0;
|
|
188
|
-
for (const name of bypassed) visited = noteVisitedStage(ctx.runId, name);
|
|
189
|
-
const prog = getLane(ctx.runId)?.progress;
|
|
190
|
-
if (prog) setLaneProgress(ctx.runId, { ...prog, visited });
|
|
143
|
+
setLaneProgress(ctx.runId, { stageName: stage.name, phase: "error", reason: error });
|
|
191
144
|
},
|
|
192
145
|
onLoopStart: (stage, info, ctx) => {
|
|
193
146
|
// A new fan-out generation REPLACES the prior one's sub-rows — the engine
|
|
@@ -195,6 +148,7 @@ export async function registerLaneProgress(): Promise<void> {
|
|
|
195
148
|
// generation. A non-fan-out loop (iterate/assess/verify) drops the gate so its
|
|
196
149
|
// sequential units never materialize sub-rows.
|
|
197
150
|
if (info.kind === "fanout") {
|
|
151
|
+
foldStageUsage(ctx.runId);
|
|
198
152
|
clearUnitLanes(ctx.runId);
|
|
199
153
|
fanoutRuns.add(ctx.runId);
|
|
200
154
|
// Fan out the generation's unit sub-rows as PENDING the instant onLoopStart
|
|
@@ -211,9 +165,6 @@ export async function registerLaneProgress(): Promise<void> {
|
|
|
211
165
|
fanoutRuns.delete(ctx.runId);
|
|
212
166
|
}
|
|
213
167
|
setLaneProgress(ctx.runId, {
|
|
214
|
-
stageNumber: stage.stageNumber,
|
|
215
|
-
totalStages: ctx.totalStages,
|
|
216
|
-
visited: noteVisitedStage(ctx.runId, stage.name),
|
|
217
168
|
stageName: stage.name,
|
|
218
169
|
phase: "running",
|
|
219
170
|
// Fanout precomputes its unit list; pull loops (iterate/assess) discover
|
|
@@ -257,14 +208,7 @@ export async function registerLaneProgress(): Promise<void> {
|
|
|
257
208
|
const prev = getLane(ctx.runId)?.progress?.units;
|
|
258
209
|
units = { done: (prev?.done ?? 0) + 1, total: prev?.total ?? unit.index + 1 };
|
|
259
210
|
}
|
|
260
|
-
setLaneProgress(ctx.runId, {
|
|
261
|
-
stageNumber: stage.stageNumber,
|
|
262
|
-
totalStages: ctx.totalStages,
|
|
263
|
-
visited: noteVisitedStage(ctx.runId, stage.name),
|
|
264
|
-
stageName: stage.name,
|
|
265
|
-
phase: "running",
|
|
266
|
-
units,
|
|
267
|
-
});
|
|
211
|
+
setLaneProgress(ctx.runId, { stageName: stage.name, phase: "running", units });
|
|
268
212
|
},
|
|
269
213
|
// The run terminated: RETAIN the lane with its terminal status (so
|
|
270
214
|
// it stays visible + its transcript stays viewable) and PUSH a completion
|
|
@@ -278,24 +222,16 @@ export async function registerLaneProgress(): Promise<void> {
|
|
|
278
222
|
// `termination.error` is the readable cause (the same text as the trail's
|
|
279
223
|
// errMsg) — retain it on the lane for the dock chip + viewer header.
|
|
280
224
|
const error = result.termination?.error;
|
|
281
|
-
//
|
|
282
|
-
//
|
|
283
|
-
//
|
|
284
|
-
|
|
285
|
-
// safety net for any uncredited skip (e.g. a gate passed before a resume point,
|
|
286
|
-
// whose onRoute never re-fired). Paint the bar full on clean completion only;
|
|
287
|
-
// `failed`/`aborted` keep their last real snapshot so the row stays frozen at
|
|
288
|
-
// the stage that died.
|
|
289
|
-
const prog = lane?.progress;
|
|
290
|
-
if (status === "completed" && prog && prog.visited !== prog.totalStages) {
|
|
291
|
-
setLaneProgress(ctx.runId, { ...prog, visited: prog.totalStages });
|
|
292
|
-
}
|
|
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;
|
|
293
229
|
// Sweep any unit that never fired onUnitEnd (abort/throw) to the run's terminal
|
|
294
230
|
// kind BEFORE retiring, so a failed run's stuck sub-rows read ✗ (retireRun's
|
|
295
231
|
// running→done fallback then no-ops on them). Drop the gate — the run is over.
|
|
296
232
|
sweepRunningUnits(ctx.runId, status === "completed" ? "done" : "failed");
|
|
297
233
|
fanoutRuns.delete(ctx.runId);
|
|
298
|
-
retireRun(ctx.runId, status, error);
|
|
234
|
+
retireRun(ctx.runId, status, error, lastArtifact);
|
|
299
235
|
const ui = getCapturedUiContext();
|
|
300
236
|
if (!ui) return;
|
|
301
237
|
if (status === "completed") ui.notify(`✓ ${name} finished — /lanes to view`, "info");
|