@outputai/cli 0.9.1-dev.9f7b159.0 → 0.9.1-next.38ae07c.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/dist/assets/docker/docker-compose-dev.yml +1 -1
- package/dist/commands/workflow/history.d.ts +19 -0
- package/dist/commands/workflow/history.js +99 -0
- package/dist/commands/workflow/history.spec.d.ts +1 -0
- package/dist/commands/workflow/history.spec.js +26 -0
- package/dist/generated/framework_version.json +1 -1
- package/dist/services/workflow_history/correlator.d.ts +26 -0
- package/dist/services/workflow_history/correlator.js +261 -0
- package/dist/services/workflow_history/correlator.spec.d.ts +1 -0
- package/dist/services/workflow_history/correlator.spec.js +116 -0
- package/dist/services/workflow_history.d.ts +23 -0
- package/dist/services/workflow_history.js +79 -0
- package/dist/services/workflow_history.spec.d.ts +1 -0
- package/dist/services/workflow_history.spec.js +87 -0
- package/dist/utils/span_labels.d.ts +11 -0
- package/dist/utils/span_labels.js +22 -0
- package/dist/utils/span_labels.spec.d.ts +1 -0
- package/dist/utils/span_labels.spec.js +36 -0
- package/dist/utils/waterfall.d.ts +31 -0
- package/dist/utils/waterfall.js +192 -0
- package/dist/utils/waterfall.spec.d.ts +1 -0
- package/dist/utils/waterfall.spec.js +100 -0
- package/dist/views/dev/dev_app.js +17 -3
- package/dist/views/dev/hooks/use_step_graph.d.ts +22 -0
- package/dist/views/dev/hooks/use_step_graph.js +76 -0
- package/dist/views/dev/modals/step_graph_modal.d.ts +6 -0
- package/dist/views/dev/modals/step_graph_modal.js +148 -0
- package/dist/views/dev/modals/steps_modal.js +1 -1
- package/dist/views/dev/panels/runs_panel.js +7 -2
- package/dist/views/dev/panels/workflows_panel.js +1 -1
- package/dist/views/dev/state/ui_state.d.ts +8 -0
- package/dist/views/dev/state/ui_state.js +5 -1
- package/oclif.manifest.json +81 -1
- package/package.json +4 -4
- /package/dist/views/dev/utils/{constants.d.ts → ui_constants.d.ts} +0 -0
- /package/dist/views/dev/utils/{constants.js → ui_constants.js} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { getWorkflowIdHistory } from '#api/generated/api.js';
|
|
3
|
+
import { fetchWorkflowHistory } from '#services/workflow_history.js';
|
|
4
|
+
vi.mock('#api/generated/api.js', () => ({ getWorkflowIdHistory: vi.fn() }));
|
|
5
|
+
// The real correlator runs (only the API client is mocked), so spans are derived
|
|
6
|
+
// from the events below — letting us assert duration/offset behaviour end to end.
|
|
7
|
+
const mockGet = getWorkflowIdHistory;
|
|
8
|
+
const T0 = Date.parse('2026-06-22T12:00:00.000Z');
|
|
9
|
+
const at = (seconds) => new Date(T0 + (seconds * 1000)).toISOString();
|
|
10
|
+
const page = (data) => ({ status: 200, data });
|
|
11
|
+
const started = (id, scheduledEventId, sec) => ({
|
|
12
|
+
eventId: id, eventTypeName: 'ACTIVITY_TASK_STARTED', eventTime: at(sec),
|
|
13
|
+
activityTaskStartedEventAttributes: { scheduledEventId, attempt: 1 }
|
|
14
|
+
});
|
|
15
|
+
const completed = (id, scheduledEventId, sec) => ({
|
|
16
|
+
eventId: id, eventTypeName: 'ACTIVITY_TASK_COMPLETED', eventTime: at(sec),
|
|
17
|
+
activityTaskCompletedEventAttributes: { scheduledEventId }
|
|
18
|
+
});
|
|
19
|
+
const scheduled = (id, name, sec) => ({
|
|
20
|
+
eventId: id, eventTypeName: 'ACTIVITY_TASK_SCHEDULED', eventTime: at(sec),
|
|
21
|
+
activityTaskScheduledEventAttributes: { activityType: { name }, activityId: `act-${id}` }
|
|
22
|
+
});
|
|
23
|
+
const workflowStarted = (sec) => ({ eventId: '1', eventTypeName: 'WORKFLOW_EXECUTION_STARTED', eventTime: at(sec) });
|
|
24
|
+
beforeEach(() => mockGet.mockReset());
|
|
25
|
+
describe('fetchWorkflowHistory', () => {
|
|
26
|
+
it('pages through results, pinning the resolved runId after the first page', async () => {
|
|
27
|
+
mockGet
|
|
28
|
+
.mockResolvedValueOnce(page({
|
|
29
|
+
workflow: { workflowId: 'wf-123', runId: 'run-456', status: 'completed', startTime: at(0), closeTime: at(300) },
|
|
30
|
+
runId: 'run-456',
|
|
31
|
+
events: [workflowStarted(0), scheduled('2', 'contentBrief#compressText', 0)],
|
|
32
|
+
nextPageToken: 'token-2'
|
|
33
|
+
}))
|
|
34
|
+
.mockResolvedValueOnce(page({
|
|
35
|
+
workflow: null,
|
|
36
|
+
runId: 'run-456',
|
|
37
|
+
events: [started('3', '2', 0), completed('4', '2', 27)],
|
|
38
|
+
nextPageToken: null
|
|
39
|
+
}));
|
|
40
|
+
const result = await fetchWorkflowHistory({ workflowId: 'wf-123' });
|
|
41
|
+
expect(mockGet).toHaveBeenCalledTimes(2);
|
|
42
|
+
expect(mockGet).toHaveBeenNthCalledWith(1, 'wf-123', { runId: undefined, pageSize: 50, pageToken: undefined, includePayloads: false });
|
|
43
|
+
// Page 2 echoes the runId the first page resolved (the endpoint requires it once a pageToken is used).
|
|
44
|
+
expect(mockGet).toHaveBeenNthCalledWith(2, 'wf-123', { runId: 'run-456', pageSize: 50, pageToken: 'token-2', includePayloads: false });
|
|
45
|
+
expect(result.runId).toBe('run-456');
|
|
46
|
+
expect(result.workflow?.workflowId).toBe('wf-123'); // metadata is taken from the first page only
|
|
47
|
+
expect(result.events).toHaveLength(4);
|
|
48
|
+
expect(result.totalDurationMs).toBe(300_000); // closeTime - startTime
|
|
49
|
+
expect(result.spans).toHaveLength(1);
|
|
50
|
+
expect(result.spans[0].durationMs).toBe(27_000);
|
|
51
|
+
});
|
|
52
|
+
it('forwards an explicit runId and includePayloads, stopping after a single page', async () => {
|
|
53
|
+
mockGet.mockResolvedValueOnce(page({
|
|
54
|
+
workflow: { workflowId: 'wf-9', runId: 'run-1', status: 'running', startTime: at(0) },
|
|
55
|
+
runId: 'run-1', events: [], nextPageToken: null
|
|
56
|
+
}));
|
|
57
|
+
const result = await fetchWorkflowHistory({ workflowId: 'wf-9', runId: 'run-1', includePayloads: true });
|
|
58
|
+
expect(mockGet).toHaveBeenCalledTimes(1);
|
|
59
|
+
expect(mockGet).toHaveBeenCalledWith('wf-9', { runId: 'run-1', pageSize: 50, pageToken: undefined, includePayloads: true });
|
|
60
|
+
expect(result.runId).toBe('run-1');
|
|
61
|
+
});
|
|
62
|
+
it('falls back to the last span end for total duration when there is no closeTime', async () => {
|
|
63
|
+
mockGet.mockResolvedValueOnce(page({
|
|
64
|
+
workflow: { workflowId: 'wf-2', runId: 'run-2', status: 'running', startTime: at(0) },
|
|
65
|
+
runId: 'run-2',
|
|
66
|
+
events: [scheduled('2', 'wf#step', 0), started('3', '2', 0), completed('4', '2', 12)],
|
|
67
|
+
nextPageToken: null
|
|
68
|
+
}));
|
|
69
|
+
const result = await fetchWorkflowHistory({ workflowId: 'wf-2' });
|
|
70
|
+
expect(result.totalDurationMs).toBe(12_000);
|
|
71
|
+
});
|
|
72
|
+
it('derives the timeline origin from WORKFLOW_EXECUTION_STARTED when metadata lacks a startTime', async () => {
|
|
73
|
+
mockGet.mockResolvedValueOnce(page({
|
|
74
|
+
workflow: { workflowId: 'wf-3', runId: 'run-3', status: 'completed' }, // no startTime / closeTime
|
|
75
|
+
runId: 'run-3',
|
|
76
|
+
events: [workflowStarted(0), scheduled('2', 'wf#step', 5), started('3', '2', 5), completed('4', '2', 10)],
|
|
77
|
+
nextPageToken: null
|
|
78
|
+
}));
|
|
79
|
+
const result = await fetchWorkflowHistory({ workflowId: 'wf-3' });
|
|
80
|
+
expect(result.spans[0].startOffsetMs).toBe(5_000);
|
|
81
|
+
expect(result.totalDurationMs).toBe(10_000);
|
|
82
|
+
});
|
|
83
|
+
it('throws when the response has no data', async () => {
|
|
84
|
+
mockGet.mockResolvedValueOnce({ status: 200 });
|
|
85
|
+
await expect(fetchWorkflowHistory({ workflowId: 'wf-x' })).rejects.toThrow(/invalid response/);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A step's name is per step-TYPE, so a fan-out of N identical activities (e.g.
|
|
3
|
+
* 9× "Scrape Serp Page") all share one label and become indistinguishable.
|
|
4
|
+
* Number the repeats in chronological order so each instance is addressable —
|
|
5
|
+
* "Scrape Serp Page #1", "#2", …. Labels that occur once are left untouched.
|
|
6
|
+
*
|
|
7
|
+
* Pass spans in their stored (chronological) order so #1 is the earliest. A
|
|
8
|
+
* TypeScript port of Atlas's `buildSpanLabels`.
|
|
9
|
+
*/
|
|
10
|
+
import type { Span } from '#services/workflow_history/correlator.js';
|
|
11
|
+
export default function buildSpanLabels(spans: Span[]): Map<string, string>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const baseLabel = (span) => span.description ?? span.name;
|
|
2
|
+
export default function buildSpanLabels(spans) {
|
|
3
|
+
const totals = new Map();
|
|
4
|
+
for (const span of spans) {
|
|
5
|
+
const label = baseLabel(span);
|
|
6
|
+
totals.set(label, (totals.get(label) ?? 0) + 1);
|
|
7
|
+
}
|
|
8
|
+
const seen = new Map();
|
|
9
|
+
const labels = new Map();
|
|
10
|
+
for (const span of spans) {
|
|
11
|
+
const label = baseLabel(span);
|
|
12
|
+
if ((totals.get(label) ?? 0) > 1) {
|
|
13
|
+
const n = (seen.get(label) ?? 0) + 1;
|
|
14
|
+
seen.set(label, n);
|
|
15
|
+
labels.set(span.id, `${label} #${n}`);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
labels.set(span.id, label);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return labels;
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import buildSpanLabels from './span_labels.js';
|
|
3
|
+
const span = (id, name) => ({
|
|
4
|
+
id,
|
|
5
|
+
name,
|
|
6
|
+
technicalName: name,
|
|
7
|
+
description: null,
|
|
8
|
+
status: 'completed',
|
|
9
|
+
kind: 'activity',
|
|
10
|
+
attempt: 1,
|
|
11
|
+
startedAt: null,
|
|
12
|
+
scheduledAt: null,
|
|
13
|
+
completedAt: null,
|
|
14
|
+
startOffsetMs: 0,
|
|
15
|
+
endOffsetMs: 0,
|
|
16
|
+
durationMs: 0,
|
|
17
|
+
failureMessage: null
|
|
18
|
+
});
|
|
19
|
+
describe('buildSpanLabels', () => {
|
|
20
|
+
it('numbers repeated labels chronologically and leaves unique labels untouched', () => {
|
|
21
|
+
const spans = [
|
|
22
|
+
span('a', 'Compress Text'),
|
|
23
|
+
span('b', 'Scrape Serp Page'),
|
|
24
|
+
span('c', 'Scrape Serp Page'),
|
|
25
|
+
span('d', 'Scrape Serp Page')
|
|
26
|
+
];
|
|
27
|
+
const labels = buildSpanLabels(spans);
|
|
28
|
+
expect(labels.get('a')).toBe('Compress Text');
|
|
29
|
+
expect(labels.get('b')).toBe('Scrape Serp Page #1');
|
|
30
|
+
expect(labels.get('c')).toBe('Scrape Serp Page #2');
|
|
31
|
+
expect(labels.get('d')).toBe('Scrape Serp Page #3');
|
|
32
|
+
});
|
|
33
|
+
it('returns an empty map for no spans', () => {
|
|
34
|
+
expect(buildSpanLabels([]).size).toBe(0);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Renders a workflow's correlated spans as a terminal waterfall/Gantt chart —
|
|
3
|
+
* a text analog of the Agents HQ "Timeline" view. Each row is a step, drawn as
|
|
4
|
+
* a colored bar positioned by its start offset and sized by its duration, on a
|
|
5
|
+
* shared time axis.
|
|
6
|
+
*
|
|
7
|
+
* The tick math (TICK_STEPS_MS / pickTickStep / formatTickLabel) is a port of
|
|
8
|
+
* Atlas's `StepGantt`; the bar geometry mirrors its leftPct/widthPct as integer
|
|
9
|
+
* terminal columns.
|
|
10
|
+
*/
|
|
11
|
+
import type { Span } from '#services/workflow_history/correlator.js';
|
|
12
|
+
export interface WaterfallOptions {
|
|
13
|
+
width: number;
|
|
14
|
+
color: boolean;
|
|
15
|
+
header?: string;
|
|
16
|
+
labels?: Map<string, string>;
|
|
17
|
+
}
|
|
18
|
+
export interface BarGeometry {
|
|
19
|
+
startCol: number;
|
|
20
|
+
barLen: number;
|
|
21
|
+
instantaneous: boolean;
|
|
22
|
+
}
|
|
23
|
+
export declare const FULL_BLOCK = "\u2588";
|
|
24
|
+
export declare const THIN_BLOCK = "\u258F";
|
|
25
|
+
export declare function pickTickStep(totalMs: number): number;
|
|
26
|
+
export declare function buildTicks(totalMs: number): number[];
|
|
27
|
+
export declare function formatTickLabel(ms: number): string;
|
|
28
|
+
export declare function formatDurationLabel(ms: number): string;
|
|
29
|
+
export declare function computeBar(startOffsetMs: number, endOffsetMs: number, totalMs: number, trackW: number): BarGeometry;
|
|
30
|
+
export declare function buildRulerLine(totalMs: number, trackW: number): string;
|
|
31
|
+
export default function renderWaterfall(spans: Span[], totalDurationMs: number, options: WaterfallOptions): string;
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
const LABEL_MIN = 14;
|
|
2
|
+
const LABEL_MAX = 28;
|
|
3
|
+
const MIN_TRACK = 10;
|
|
4
|
+
export const FULL_BLOCK = '█';
|
|
5
|
+
export const THIN_BLOCK = '▏';
|
|
6
|
+
// Human-friendly step sizes, smallest → largest. Pick the smallest step that
|
|
7
|
+
// yields ~TARGET_TICKS or fewer labels.
|
|
8
|
+
const TICK_STEPS_MS = [
|
|
9
|
+
100, 250, 500,
|
|
10
|
+
1_000, 2_000, 5_000, 10_000, 15_000, 30_000,
|
|
11
|
+
60_000, 2 * 60_000, 5 * 60_000, 10 * 60_000, 15 * 60_000, 30 * 60_000,
|
|
12
|
+
60 * 60_000, 2 * 60 * 60_000, 6 * 60 * 60_000, 12 * 60 * 60_000, 24 * 60 * 60_000
|
|
13
|
+
];
|
|
14
|
+
const TARGET_TICKS = 8;
|
|
15
|
+
const ANSI = {
|
|
16
|
+
completed: '[92m',
|
|
17
|
+
running: '[33m',
|
|
18
|
+
failed: '[31m',
|
|
19
|
+
pending: '[90m',
|
|
20
|
+
dim: '[2m',
|
|
21
|
+
reset: '[0m'
|
|
22
|
+
};
|
|
23
|
+
function clamp(value, lo, hi) {
|
|
24
|
+
return Math.min(Math.max(value, lo), hi);
|
|
25
|
+
}
|
|
26
|
+
export function pickTickStep(totalMs) {
|
|
27
|
+
if (totalMs <= 0) {
|
|
28
|
+
return 1_000;
|
|
29
|
+
}
|
|
30
|
+
const ideal = totalMs / TARGET_TICKS;
|
|
31
|
+
return TICK_STEPS_MS.find(s => s >= ideal) ?? TICK_STEPS_MS[TICK_STEPS_MS.length - 1];
|
|
32
|
+
}
|
|
33
|
+
export function buildTicks(totalMs) {
|
|
34
|
+
const step = pickTickStep(totalMs);
|
|
35
|
+
const count = Math.floor(totalMs / step);
|
|
36
|
+
return Array.from({ length: count + 1 }, (_, i) => i * step);
|
|
37
|
+
}
|
|
38
|
+
// Round to whole units *before* splitting so a remainder that rounds up to a
|
|
39
|
+
// full unit carries instead of rendering "1m60s" / "1h60m".
|
|
40
|
+
function formatClock(ms) {
|
|
41
|
+
const totalSec = Math.round(ms / 1_000);
|
|
42
|
+
if (totalSec < 60) {
|
|
43
|
+
return `${totalSec}s`;
|
|
44
|
+
}
|
|
45
|
+
if (totalSec < 3_600) {
|
|
46
|
+
const m = Math.floor(totalSec / 60);
|
|
47
|
+
const s = totalSec % 60;
|
|
48
|
+
return s === 0 ? `${m}m` : `${m}m${s}s`;
|
|
49
|
+
}
|
|
50
|
+
const totalMin = Math.round(ms / 60_000);
|
|
51
|
+
const h = Math.floor(totalMin / 60);
|
|
52
|
+
const m = totalMin % 60;
|
|
53
|
+
return m === 0 ? `${h}h` : `${h}h${m}m`;
|
|
54
|
+
}
|
|
55
|
+
export function formatTickLabel(ms) {
|
|
56
|
+
if (ms === 0) {
|
|
57
|
+
return '0';
|
|
58
|
+
}
|
|
59
|
+
if (ms < 1_000) {
|
|
60
|
+
return `${ms}ms`;
|
|
61
|
+
}
|
|
62
|
+
return formatClock(ms);
|
|
63
|
+
}
|
|
64
|
+
export function formatDurationLabel(ms) {
|
|
65
|
+
if (ms < 1_000) {
|
|
66
|
+
return `${Math.max(0, Math.round(ms))}ms`;
|
|
67
|
+
}
|
|
68
|
+
return formatClock(ms);
|
|
69
|
+
}
|
|
70
|
+
// Map a span's [startOffset, endOffset] onto integer columns of a `trackW`-wide
|
|
71
|
+
// lane. Both edges are positioned by their own offset and the length is the gap
|
|
72
|
+
// between them — so the bar always spans start→end. (Rounding a separate width
|
|
73
|
+
// off the start, as before, let the right edge drift past the true end time.)
|
|
74
|
+
// A zero-width span still draws a 1-col marker, clamped to stay inside the lane.
|
|
75
|
+
export function computeBar(startOffsetMs, endOffsetMs, totalMs, trackW) {
|
|
76
|
+
const safeTotal = Math.max(totalMs, 1);
|
|
77
|
+
const startCol = clamp(Math.round((startOffsetMs / safeTotal) * trackW), 0, Math.max(0, trackW - 1));
|
|
78
|
+
const endCol = clamp(Math.round((endOffsetMs / safeTotal) * trackW), startCol, trackW);
|
|
79
|
+
const span = endCol - startCol;
|
|
80
|
+
const instantaneous = span <= 0;
|
|
81
|
+
const barLen = Math.min(Math.max(span, 1), trackW - startCol);
|
|
82
|
+
return { startCol, barLen, instantaneous };
|
|
83
|
+
}
|
|
84
|
+
function padOrTruncate(text, width) {
|
|
85
|
+
if (text.length === width) {
|
|
86
|
+
return text;
|
|
87
|
+
}
|
|
88
|
+
if (text.length < width) {
|
|
89
|
+
return text.padEnd(width);
|
|
90
|
+
}
|
|
91
|
+
return `${text.slice(0, width - 1)}…`;
|
|
92
|
+
}
|
|
93
|
+
function truncate(text, width) {
|
|
94
|
+
return text.length <= width ? text : `${text.slice(0, Math.max(0, width - 1))}…`;
|
|
95
|
+
}
|
|
96
|
+
// First tick aligns left, last tick aligns right, middle ticks center on their
|
|
97
|
+
// position — so labels at 0 % and 100 % don't overflow the lane.
|
|
98
|
+
function tickRawStart(idx, count, col, labelLen, trackW) {
|
|
99
|
+
if (idx === 0) {
|
|
100
|
+
return 0;
|
|
101
|
+
}
|
|
102
|
+
if (idx === count - 1) {
|
|
103
|
+
return trackW - labelLen;
|
|
104
|
+
}
|
|
105
|
+
return col - Math.floor(labelLen / 2);
|
|
106
|
+
}
|
|
107
|
+
function tickStart(idx, count, col, labelLen, trackW) {
|
|
108
|
+
return clamp(tickRawStart(idx, count, col, labelLen, trackW), 0, trackW - labelLen);
|
|
109
|
+
}
|
|
110
|
+
// The trackW-wide time-axis ruler (no label gutter, no colour). Exported so the
|
|
111
|
+
// TUI overlay header can render the same ticks the CLI string renderer uses.
|
|
112
|
+
export function buildRulerLine(totalMs, trackW) {
|
|
113
|
+
const safeTotal = Math.max(totalMs, 1);
|
|
114
|
+
const ticks = buildTicks(safeTotal);
|
|
115
|
+
const placements = ticks.reduce((acc, t, idx) => {
|
|
116
|
+
const label = formatTickLabel(t);
|
|
117
|
+
const col = Math.min(Math.round((t / safeTotal) * trackW), trackW - 1);
|
|
118
|
+
const start = tickStart(idx, ticks.length, col, label.length, trackW);
|
|
119
|
+
if (start <= acc.writtenUntil) {
|
|
120
|
+
return acc;
|
|
121
|
+
}
|
|
122
|
+
return { writtenUntil: start + label.length, items: [...acc.items, { start, label }] };
|
|
123
|
+
}, { writtenUntil: -1, items: [] });
|
|
124
|
+
const chars = Array.from({ length: trackW }, () => ' ');
|
|
125
|
+
for (const { start, label } of placements.items) {
|
|
126
|
+
[...label].forEach((ch, i) => {
|
|
127
|
+
chars[start + i] = ch;
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
return chars.join('');
|
|
131
|
+
}
|
|
132
|
+
function renderRuler(totalMs, labelW, trackW, tint) {
|
|
133
|
+
return `${' '.repeat(labelW + 1)}${tint(buildRulerLine(totalMs, trackW), ANSI.dim)}`;
|
|
134
|
+
}
|
|
135
|
+
function renderLegend(tint) {
|
|
136
|
+
const entry = (status, text) => `${tint(FULL_BLOCK, ANSI[status])} ${text}`;
|
|
137
|
+
const entries = [
|
|
138
|
+
entry('completed', 'completed'),
|
|
139
|
+
entry('running', 'running'),
|
|
140
|
+
entry('failed', 'failed'),
|
|
141
|
+
entry('pending', 'pending')
|
|
142
|
+
];
|
|
143
|
+
return tint(entries.join(' '), ANSI.dim);
|
|
144
|
+
}
|
|
145
|
+
// The bars only encode failure as a red lane; surface the reason underneath so a
|
|
146
|
+
// failed run is actionable from the chart alone. `failureMessage` is only
|
|
147
|
+
// populated when the history was fetched with payloads (the server strips it
|
|
148
|
+
// otherwise), so spans without one are simply omitted here.
|
|
149
|
+
function buildFailureLines(spans, labelFor, width, tint) {
|
|
150
|
+
const failed = spans.filter(span => span.status === 'failed' && span.failureMessage);
|
|
151
|
+
if (failed.length === 0) {
|
|
152
|
+
return [];
|
|
153
|
+
}
|
|
154
|
+
const lines = failed.map(span => {
|
|
155
|
+
const message = (span.failureMessage ?? '').replace(/\s+/g, ' ').trim();
|
|
156
|
+
return tint(truncate(`✗ ${labelFor(span)}: ${message}`, width), ANSI.failed);
|
|
157
|
+
});
|
|
158
|
+
return ['', tint('Failures', ANSI.dim), ...lines];
|
|
159
|
+
}
|
|
160
|
+
export default function renderWaterfall(spans, totalDurationMs, options) {
|
|
161
|
+
const { width, color, header, labels } = options;
|
|
162
|
+
if (spans.length === 0) {
|
|
163
|
+
return [header, 'No steps found for this run.'].filter(Boolean).join('\n\n');
|
|
164
|
+
}
|
|
165
|
+
const tint = (text, code) => (color ? `${code}${text}${ANSI.reset}` : text);
|
|
166
|
+
const labelFor = (span) => labels?.get(span.id) ?? span.name;
|
|
167
|
+
const durationFor = (span) => formatDurationLabel(Math.max(0, span.durationMs));
|
|
168
|
+
const longestLabel = Math.max(...spans.map(s => labelFor(s).length));
|
|
169
|
+
const labelW = clamp(longestLabel, LABEL_MIN, LABEL_MAX);
|
|
170
|
+
const durationW = Math.max(...spans.map(s => durationFor(s).length));
|
|
171
|
+
const trackW = Math.max(width - labelW - durationW - 2, MIN_TRACK);
|
|
172
|
+
const rows = spans.map(span => {
|
|
173
|
+
const label = padOrTruncate(labelFor(span), labelW);
|
|
174
|
+
const { startCol, barLen, instantaneous } = computeBar(span.startOffsetMs, span.endOffsetMs, totalDurationMs, trackW);
|
|
175
|
+
const glyph = instantaneous ? THIN_BLOCK : FULL_BLOCK;
|
|
176
|
+
const leading = ' '.repeat(startCol);
|
|
177
|
+
const trailing = ' '.repeat(Math.max(trackW - startCol - barLen, 0));
|
|
178
|
+
const track = `${leading}${tint(glyph.repeat(barLen), ANSI[span.status])}${trailing}`;
|
|
179
|
+
const duration = tint(durationFor(span).padStart(durationW), ANSI.dim);
|
|
180
|
+
return `${label} ${track} ${duration}`;
|
|
181
|
+
});
|
|
182
|
+
const headerLines = header ? [header, ''] : [];
|
|
183
|
+
const failureLines = buildFailureLines(spans, labelFor, width, tint);
|
|
184
|
+
const legendLines = color ? ['', renderLegend(tint)] : [];
|
|
185
|
+
return [
|
|
186
|
+
...headerLines,
|
|
187
|
+
renderRuler(totalDurationMs, labelW, trackW, tint),
|
|
188
|
+
...rows,
|
|
189
|
+
...failureLines,
|
|
190
|
+
...legendLines
|
|
191
|
+
].join('\n');
|
|
192
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import renderWaterfall, { pickTickStep, formatTickLabel, formatDurationLabel, computeBar } from './waterfall.js';
|
|
3
|
+
const span = (id, name, status, startOffsetMs, durationMs) => ({
|
|
4
|
+
id,
|
|
5
|
+
name,
|
|
6
|
+
technicalName: name,
|
|
7
|
+
description: null,
|
|
8
|
+
status,
|
|
9
|
+
kind: 'activity',
|
|
10
|
+
attempt: 1,
|
|
11
|
+
startedAt: null,
|
|
12
|
+
scheduledAt: null,
|
|
13
|
+
completedAt: null,
|
|
14
|
+
startOffsetMs,
|
|
15
|
+
endOffsetMs: startOffsetMs + durationMs,
|
|
16
|
+
durationMs,
|
|
17
|
+
failureMessage: null
|
|
18
|
+
});
|
|
19
|
+
describe('pickTickStep', () => {
|
|
20
|
+
it('targets ~8 ticks by choosing the smallest sufficient step', () => {
|
|
21
|
+
expect(pickTickStep(0)).toBe(1_000);
|
|
22
|
+
expect(pickTickStep(8_000)).toBe(1_000);
|
|
23
|
+
expect(pickTickStep(80_000)).toBe(10_000);
|
|
24
|
+
expect(pickTickStep(160_000)).toBe(30_000);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
describe('formatTickLabel', () => {
|
|
28
|
+
it('formats axis ticks like the UI', () => {
|
|
29
|
+
expect(formatTickLabel(0)).toBe('0');
|
|
30
|
+
expect(formatTickLabel(500)).toBe('500ms');
|
|
31
|
+
expect(formatTickLabel(27_000)).toBe('27s');
|
|
32
|
+
expect(formatTickLabel(60_000)).toBe('1m');
|
|
33
|
+
expect(formatTickLabel(72_000)).toBe('1m12s');
|
|
34
|
+
expect(formatTickLabel(3_600_000)).toBe('1h');
|
|
35
|
+
expect(formatTickLabel(3_660_000)).toBe('1h1m');
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
describe('formatDurationLabel', () => {
|
|
39
|
+
it('always shows a unit, including zero', () => {
|
|
40
|
+
expect(formatDurationLabel(0)).toBe('0ms');
|
|
41
|
+
expect(formatDurationLabel(999)).toBe('999ms');
|
|
42
|
+
expect(formatDurationLabel(1_000)).toBe('1s');
|
|
43
|
+
expect(formatDurationLabel(27_000)).toBe('27s');
|
|
44
|
+
});
|
|
45
|
+
it('carries a rounded-up remainder instead of rendering 60s/60m', () => {
|
|
46
|
+
expect(formatDurationLabel(59_500)).toBe('1m');
|
|
47
|
+
expect(formatDurationLabel(119_500)).toBe('2m');
|
|
48
|
+
expect(formatDurationLabel(3_599_500)).toBe('1h');
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
describe('computeBar', () => {
|
|
52
|
+
it('maps offsets to columns with a min width and lane clamp', () => {
|
|
53
|
+
expect(computeBar(0, 27_000, 100_000, 50)).toEqual({ startCol: 0, barLen: 14, instantaneous: false });
|
|
54
|
+
// Zero-duration step → a single thin marker
|
|
55
|
+
expect(computeBar(50_000, 50_000, 100_000, 50)).toEqual({ startCol: 25, barLen: 1, instantaneous: true });
|
|
56
|
+
// A short step at the very end is clamped so it stays inside the lane
|
|
57
|
+
expect(computeBar(99_000, 100_000, 100_000, 50)).toEqual({ startCol: 49, barLen: 1, instantaneous: false });
|
|
58
|
+
});
|
|
59
|
+
it('sizes the bar to span start→end without right-edge drift', () => {
|
|
60
|
+
// Full-span step fills the lane exactly.
|
|
61
|
+
expect(computeBar(0, 100_000, 100_000, 50)).toEqual({ startCol: 0, barLen: 50, instantaneous: false });
|
|
62
|
+
// End column is rounded from the true end offset (33), not start + a
|
|
63
|
+
// separately-rounded width (which used to overshoot to col 34).
|
|
64
|
+
expect(computeBar(33_000, 66_000, 100_000, 50)).toEqual({ startCol: 17, barLen: 16, instantaneous: false });
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
describe('renderWaterfall', () => {
|
|
68
|
+
const spans = [
|
|
69
|
+
span('a', 'Compress Text', 'completed', 0, 27_000),
|
|
70
|
+
span('b', 'Generate Brief', 'pending', 40_000, 0)
|
|
71
|
+
];
|
|
72
|
+
it('renders labels, bars, durations and a header without color by default', () => {
|
|
73
|
+
const out = renderWaterfall(spans, 40_000, { width: 70, color: false, header: 'wf-1 · run abcd1234 · running · 40s' });
|
|
74
|
+
expect(out).toContain('Compress Text');
|
|
75
|
+
expect(out).toContain('Generate Brief');
|
|
76
|
+
expect(out).toContain('█');
|
|
77
|
+
expect(out).toContain('27s');
|
|
78
|
+
expect(out).toContain('wf-1 · run abcd1234');
|
|
79
|
+
expect(out).not.toContain('\x1b[');
|
|
80
|
+
});
|
|
81
|
+
it('emits ANSI color when enabled', () => {
|
|
82
|
+
const out = renderWaterfall(spans, 40_000, { width: 70, color: true });
|
|
83
|
+
expect(out).toContain('\x1b[');
|
|
84
|
+
expect(out).toContain('\x1b[92m'); // completed → green
|
|
85
|
+
});
|
|
86
|
+
it('shows a friendly message when there are no steps', () => {
|
|
87
|
+
const out = renderWaterfall([], 1, { width: 70, color: false, header: 'wf-1' });
|
|
88
|
+
expect(out).toContain('No steps found for this run.');
|
|
89
|
+
});
|
|
90
|
+
it('lists the reason under the chart for failed steps that carry a message', () => {
|
|
91
|
+
const failed = { ...span('c', 'Scrape Serp Page', 'failed', 10_000, 2_000), failureMessage: 'connection reset' };
|
|
92
|
+
const out = renderWaterfall([...spans, failed], 40_000, { width: 70, color: false });
|
|
93
|
+
expect(out).toContain('Failures');
|
|
94
|
+
expect(out).toContain('✗ Scrape Serp Page: connection reset');
|
|
95
|
+
});
|
|
96
|
+
it('omits the failures section when no failed step has a message', () => {
|
|
97
|
+
const out = renderWaterfall(spans, 40_000, { width: 70, color: false });
|
|
98
|
+
expect(out).not.toContain('Failures');
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -18,7 +18,8 @@ import { HELP_HINTS, HELP_SECTION_COUNT, HelpPanel } from '#views/dev/panels/hel
|
|
|
18
18
|
import { RunModal } from '#views/dev/modals/run_modal.js';
|
|
19
19
|
import { ExpandedJsonModal } from '#views/dev/modals/expanded_json_modal.js';
|
|
20
20
|
import { StepsModal } from '#views/dev/modals/steps_modal.js';
|
|
21
|
-
import {
|
|
21
|
+
import { StepGraphModal } from '#views/dev/modals/step_graph_modal.js';
|
|
22
|
+
import { MIN_TERMINAL_COLUMNS, MIN_TERMINAL_ROWS } from '#views/dev/utils/ui_constants.js';
|
|
22
23
|
const TAB_NUMBER_KEYS = {
|
|
23
24
|
1: 'workflows',
|
|
24
25
|
2: 'runs',
|
|
@@ -65,7 +66,7 @@ const useGlobalInput = (opts) => {
|
|
|
65
66
|
.catch(err => exit(err instanceof Error ? err : new Error(String(err))));
|
|
66
67
|
return;
|
|
67
68
|
}
|
|
68
|
-
if (ui.search.open || ui.runModal.open || ui.expandedJson.open || opts.runDetailOpen) {
|
|
69
|
+
if (ui.search.open || ui.runModal.open || ui.expandedJson.open || ui.stepGraph.open || opts.runDetailOpen) {
|
|
69
70
|
return;
|
|
70
71
|
}
|
|
71
72
|
// Esc on a list view drops an active filter. Skip when we're on
|
|
@@ -133,9 +134,14 @@ const footerFor = (opts) => {
|
|
|
133
134
|
return { hints: HELP_HINTS, itemCount: HELP_SECTION_COUNT, itemLabel: 'sections' };
|
|
134
135
|
};
|
|
135
136
|
const overlayFor = (opts) => {
|
|
137
|
+
// expandedJson sits on top of everything — it's popped from another overlay
|
|
138
|
+
// (e.g. the step graph's `e`), so it must win when both are open.
|
|
136
139
|
if (opts.ui.expandedJson.open) {
|
|
137
140
|
return _jsx(ExpandedJsonModal, {});
|
|
138
141
|
}
|
|
142
|
+
if (opts.ui.stepGraph.open && opts.stepGraphRun) {
|
|
143
|
+
return _jsx(StepGraphModal, { run: opts.stepGraphRun, height: opts.rows });
|
|
144
|
+
}
|
|
139
145
|
if (opts.ui.runModal.open) {
|
|
140
146
|
return _jsx(RunModal, { workflowName: opts.ui.runModal.workflowName, workflowPath: opts.ui.runModal.workflowPath });
|
|
141
147
|
}
|
|
@@ -177,6 +183,14 @@ const Shell = ({ dockerComposePath, onCleanup }) => {
|
|
|
177
183
|
runs.find(r => r.runId === ui.selection.runId && r.workflowId === ui.selection.workflowId) :
|
|
178
184
|
undefined;
|
|
179
185
|
const runDetailOpen = ui.runsView === 'detail' && detailRun !== undefined;
|
|
186
|
+
// Re-resolve the step-graph run from the polled list each render so its
|
|
187
|
+
// status/duration stay live; fall back to the snapshot captured at open.
|
|
188
|
+
const stepGraphRun = useMemo(() => {
|
|
189
|
+
const captured = ui.stepGraph.open ? ui.stepGraph.run : null;
|
|
190
|
+
return captured ?
|
|
191
|
+
(runs.find(r => r.runId === captured.runId && r.workflowId === captured.workflowId) ?? captured) :
|
|
192
|
+
undefined;
|
|
193
|
+
}, [ui.stepGraph.open, ui.stepGraph.run, runs]);
|
|
180
194
|
useGlobalInput({ onCleanup, runDetailOpen });
|
|
181
195
|
const failingServices = useMemo(() => services.filter(isServiceFailed).length, [services]);
|
|
182
196
|
const serviceBadge = useMemo(() => {
|
|
@@ -210,7 +224,7 @@ const Shell = ({ dockerComposePath, onCleanup }) => {
|
|
|
210
224
|
serviceCount: services.length,
|
|
211
225
|
phase
|
|
212
226
|
});
|
|
213
|
-
const overlay = overlayFor({ ui, detailRun, runDetailOpen, rows });
|
|
227
|
+
const overlay = overlayFor({ ui, detailRun, stepGraphRun, runDetailOpen, rows });
|
|
214
228
|
if (terminalTooSmall) {
|
|
215
229
|
return _jsx(TerminalTooSmall, { rows: rows, cols: cols });
|
|
216
230
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type WorkflowMeta } from '#services/workflow_history.js';
|
|
2
|
+
import type { Span } from '#services/workflow_history/correlator.js';
|
|
3
|
+
export interface StepGraph {
|
|
4
|
+
spans: Span[];
|
|
5
|
+
totalDurationMs: number;
|
|
6
|
+
workflow: WorkflowMeta | null;
|
|
7
|
+
labels: Map<string, string>;
|
|
8
|
+
loading: boolean;
|
|
9
|
+
error: string | null;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Fetches a run's correlated step spans for the dev TUI's waterfall overlay,
|
|
13
|
+
* reusing the same `fetchWorkflowHistory` path as the `workflow history` CLI
|
|
14
|
+
* command. Driven by `usePoll`: while the run is still advancing it re-pulls
|
|
15
|
+
* every tick so newly scheduled / finished steps appear, then stops and caches
|
|
16
|
+
* once terminal. The modal ticks the time axis between polls so the right edge
|
|
17
|
+
* tracks elapsed time.
|
|
18
|
+
*
|
|
19
|
+
* A hard fetch failure surfaces as `error` only when nothing has loaded yet — a
|
|
20
|
+
* transient poll blip keeps the last good chart on screen.
|
|
21
|
+
*/
|
|
22
|
+
export declare const useStepGraph: (workflowId: string | undefined, runId: string | undefined, status?: string) => StepGraph;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { useRef, useState } from 'react';
|
|
2
|
+
import { fetchWorkflowHistory } from '#services/workflow_history.js';
|
|
3
|
+
import buildSpanLabels from '#utils/span_labels.js';
|
|
4
|
+
import { isTerminalRunStatus } from '#views/dev/hooks/use_run_detail.js';
|
|
5
|
+
import { usePoll, POLL_INTERVAL_MS } from '#views/dev/hooks/use_poll.js';
|
|
6
|
+
const EMPTY_GRAPH = {
|
|
7
|
+
spans: [],
|
|
8
|
+
totalDurationMs: 0,
|
|
9
|
+
workflow: null,
|
|
10
|
+
labels: new Map(),
|
|
11
|
+
loading: false,
|
|
12
|
+
error: null
|
|
13
|
+
};
|
|
14
|
+
const stepGraphCache = new Map();
|
|
15
|
+
/**
|
|
16
|
+
* Fetches a run's correlated step spans for the dev TUI's waterfall overlay,
|
|
17
|
+
* reusing the same `fetchWorkflowHistory` path as the `workflow history` CLI
|
|
18
|
+
* command. Driven by `usePoll`: while the run is still advancing it re-pulls
|
|
19
|
+
* every tick so newly scheduled / finished steps appear, then stops and caches
|
|
20
|
+
* once terminal. The modal ticks the time axis between polls so the right edge
|
|
21
|
+
* tracks elapsed time.
|
|
22
|
+
*
|
|
23
|
+
* A hard fetch failure surfaces as `error` only when nothing has loaded yet — a
|
|
24
|
+
* transient poll blip keeps the last good chart on screen.
|
|
25
|
+
*/
|
|
26
|
+
export const useStepGraph = (workflowId, runId, status) => {
|
|
27
|
+
const [graph, setGraph] = useState(EMPTY_GRAPH);
|
|
28
|
+
const terminal = isTerminalRunStatus(status);
|
|
29
|
+
const requestKeyRef = useRef('');
|
|
30
|
+
usePoll(Boolean(workflowId), POLL_INTERVAL_MS, async () => {
|
|
31
|
+
if (!workflowId) {
|
|
32
|
+
return 'done';
|
|
33
|
+
}
|
|
34
|
+
const key = `${workflowId}:${runId ?? 'latest'}`;
|
|
35
|
+
requestKeyRef.current = key;
|
|
36
|
+
const cached = stepGraphCache.get(key);
|
|
37
|
+
if (cached) {
|
|
38
|
+
setGraph(cached);
|
|
39
|
+
return 'done';
|
|
40
|
+
}
|
|
41
|
+
setGraph(current => (current.spans.length === 0 ? { ...current, loading: true } : current));
|
|
42
|
+
try {
|
|
43
|
+
// Pull payloads so the detail pane can show each step's input/output and
|
|
44
|
+
// a failed step's reason.
|
|
45
|
+
const result = await fetchWorkflowHistory({ workflowId, runId, includePayloads: true });
|
|
46
|
+
if (requestKeyRef.current !== key) {
|
|
47
|
+
return 'done'; // a different run was selected mid-flight
|
|
48
|
+
}
|
|
49
|
+
const next = {
|
|
50
|
+
spans: result.spans,
|
|
51
|
+
totalDurationMs: result.totalDurationMs,
|
|
52
|
+
workflow: result.workflow,
|
|
53
|
+
labels: buildSpanLabels(result.spans),
|
|
54
|
+
loading: false,
|
|
55
|
+
error: null
|
|
56
|
+
};
|
|
57
|
+
// Cache only terminal runs — a running run's history is still growing.
|
|
58
|
+
if (terminal) {
|
|
59
|
+
stepGraphCache.set(key, next);
|
|
60
|
+
}
|
|
61
|
+
setGraph(next);
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
if (requestKeyRef.current !== key) {
|
|
65
|
+
return 'done';
|
|
66
|
+
}
|
|
67
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
68
|
+
// Keep the last good chart if a poll blips; only surface a cold failure.
|
|
69
|
+
setGraph(current => (current.spans.length > 0 ?
|
|
70
|
+
{ ...current, loading: false } :
|
|
71
|
+
{ ...EMPTY_GRAPH, error: message }));
|
|
72
|
+
}
|
|
73
|
+
return terminal ? 'done' : 'continue';
|
|
74
|
+
});
|
|
75
|
+
return graph;
|
|
76
|
+
};
|