@jive-sh/workflow-platform 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -6
- package/dist/dashboard/drilldown.js +2 -2
- package/dist/dashboard/drilldown.js.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/steps.js +34 -21
- package/dist/steps.js.map +1 -1
- package/dist/storage/sqlite-store.js +4 -0
- package/dist/storage/sqlite-store.js.map +1 -1
- package/dist/views/runs-now.js +1 -1
- package/dist/views/runs-now.js.map +1 -1
- package/dist/views/step-funnel.js +1 -1
- package/dist/views/step-funnel.js.map +1 -1
- package/dist/views/step-graph.js +1 -1
- package/dist/views/step-graph.js.map +1 -1
- package/dist/views/workflow-flows.js +53 -0
- package/dist/views/workflow-flows.js.map +1 -0
- package/dist/views/workflows-view.js +11 -4
- package/dist/views/workflows-view.js.map +1 -1
- package/package.json +1 -1
- package/src/dashboard/dashboard.css +13 -1
- package/src/dashboard/drilldown.ts +2 -3
- package/src/dashboard/step-graph.tsx +18 -10
- package/src/dashboard/workflow-dag.tsx +204 -0
- package/src/dashboard/workflows-dashboard.tsx +17 -8
- package/src/index.ts +1 -0
- package/src/steps.ts +52 -28
- package/src/storage/sqlite-store.ts +11 -1
- package/src/storage/task-store.ts +23 -0
- package/src/views/runs-now.ts +2 -2
- package/src/views/step-funnel.ts +2 -2
- package/src/views/step-graph.ts +4 -4
- package/src/views/workflow-flows.ts +97 -0
- package/src/views/workflows-view.ts +22 -10
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* THE PROJECT'S WORKFLOWS AS A DAG, laid out by ELK's layered algorithm (`elkjs`, which the host page brings, as it brings
|
|
5
|
+
* React): each workflow one node, in layers in topological order of the forward edges, so every forward arrow points down;
|
|
6
|
+
* each stage's layers kept together (ELK's partitions, one per stage in the project's order) and shown as a band named in
|
|
7
|
+
* a gutter on the left that no edge enters. Edges are routed orthogonally around the nodes, each with its label beside its
|
|
8
|
+
* own line and its arrowhead at its target. A send-back, the only edge against the flow, is routed apart by ELK as a feedback
|
|
9
|
+
* edge, dashed and labelled "sends back". A box's name opens that workflow's own level. Workflows no work flows to or from are not drawn: the list of steps under the map has them.
|
|
10
|
+
*
|
|
11
|
+
* Chosen over dagre (`@dagrejs/dagre`): ELK routes edges around nodes and places labels beside their own edges, lays out
|
|
12
|
+
* partitions in order and routes feedback edges apart; dagre does none of those, and its edges and labels cross nodes.
|
|
13
|
+
*/
|
|
14
|
+
import ELK, { type ElkNode } from 'elkjs/lib/elk.bundled.js';
|
|
15
|
+
import { useEffect, useLayoutEffect, useRef, useState, type CSSProperties, type ReactNode } from 'react';
|
|
16
|
+
import type { WorkflowFlow } from '../views/workflow-flows';
|
|
17
|
+
import type { WorkflowView, WorkflowsView } from '../views/workflows-view';
|
|
18
|
+
import { QueueBar } from './queue-bar';
|
|
19
|
+
|
|
20
|
+
/** An edge's label: what it is, and along a wait how many wait. */
|
|
21
|
+
const flowLabel = (f: WorkflowFlow): string => (f.kind === 'waits on' ? `${f.waiting.toLocaleString('en-US')} wait on it` : f.kind);
|
|
22
|
+
/** An edge's line: solid feeds, dashed sends back, dotted gives input, dash-dot waits on. */
|
|
23
|
+
const DASH: Readonly<Record<WorkflowFlow['kind'], string | undefined>> = { feeds: undefined, 'sends back': '7 4', 'gives input': '1.5 3.5', 'waits on': '7 3 1.5 3' };
|
|
24
|
+
|
|
25
|
+
/** The node's width; its height is measured from what it shows. */
|
|
26
|
+
const NODE_WIDTH = 250;
|
|
27
|
+
/** The left gutter the stages are named in. */
|
|
28
|
+
const GUTTER = 104;
|
|
29
|
+
const LABEL_HEIGHT = 15;
|
|
30
|
+
const labelWidth = (text: string) => Math.ceil(text.length * 6.3) + 10;
|
|
31
|
+
|
|
32
|
+
interface Laid {
|
|
33
|
+
readonly nodes: ReadonlyMap<string, { readonly x: number; readonly y: number; readonly h: number }>;
|
|
34
|
+
readonly edges: ReadonlyArray<{ readonly flow: WorkflowFlow; readonly points: ReadonlyArray<{ readonly x: number; readonly y: number }>; readonly label: { readonly x: number; readonly y: number; readonly w: number } | null }>;
|
|
35
|
+
readonly width: number;
|
|
36
|
+
readonly height: number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const elk = new ELK();
|
|
40
|
+
|
|
41
|
+
/** The layout of the linked workflows, given each node's height. */
|
|
42
|
+
const layOut = async (input: {
|
|
43
|
+
/** In pipeline order: by stage, then by depth through forward edges within it. */
|
|
44
|
+
readonly workflows: ReadonlyArray<{ readonly name: string; readonly stage: number; readonly height: number }>;
|
|
45
|
+
readonly flows: ReadonlyArray<WorkflowFlow>;
|
|
46
|
+
}): Promise<Laid> => {
|
|
47
|
+
const asked: ElkNode = {
|
|
48
|
+
id: 'workflows',
|
|
49
|
+
layoutOptions: {
|
|
50
|
+
'elk.algorithm': 'layered',
|
|
51
|
+
'elk.direction': 'DOWN',
|
|
52
|
+
'elk.edgeRouting': 'ORTHOGONAL',
|
|
53
|
+
'elk.partitioning.activate': 'true',
|
|
54
|
+
// One layering for all, so every stage's layers come before the next stage's; laid out apart, unconnected groups sat side by side.
|
|
55
|
+
'elk.separateConnectedComponents': 'false',
|
|
56
|
+
'elk.layered.feedbackEdges': 'true',
|
|
57
|
+
// The platform's pipeline order decides which edges go against the flow: only one to a workflow earlier in it, a
|
|
58
|
+
// send-back. Left to itself, ELK kept Retry near-misses' send-back as forward and drew Decompile's feed going up.
|
|
59
|
+
'elk.layered.cycleBreaking.strategy': 'MODEL_ORDER',
|
|
60
|
+
'elk.layered.considerModelOrder.strategy': 'NODES_AND_EDGES',
|
|
61
|
+
'elk.layered.spacing.nodeNodeBetweenLayers': '64',
|
|
62
|
+
'elk.spacing.nodeNode': '36',
|
|
63
|
+
'elk.spacing.edgeNode': '18',
|
|
64
|
+
'elk.spacing.edgeEdge': '12',
|
|
65
|
+
'elk.spacing.edgeLabel': '4',
|
|
66
|
+
'elk.layered.edgeLabels.sideSelection': 'SMART_DOWN',
|
|
67
|
+
'elk.padding': `[top=34,left=${GUTTER},bottom=16,right=16]`,
|
|
68
|
+
},
|
|
69
|
+
children: input.workflows.map((w) => ({ id: w.name, width: NODE_WIDTH, height: w.height, layoutOptions: { 'elk.partitioning.partition': String(w.stage) } })),
|
|
70
|
+
edges: input.flows.map((f, i) => ({ id: `edge-${i}`, sources: [f.from], targets: [f.to], labels: [{ id: `label-${i}`, text: flowLabel(f), width: labelWidth(flowLabel(f)), height: LABEL_HEIGHT }] })),
|
|
71
|
+
};
|
|
72
|
+
const graph = await elk.layout(asked);
|
|
73
|
+
const nodes = new Map((graph.children ?? []).map((c) => [c.id, { x: c.x ?? 0, y: c.y ?? 0, h: c.height ?? 0 }]));
|
|
74
|
+
const edges = (graph.edges ?? []).map((e, i) => {
|
|
75
|
+
const s = e.sections?.[0];
|
|
76
|
+
const label = e.labels?.[0];
|
|
77
|
+
return {
|
|
78
|
+
flow: input.flows[i]!,
|
|
79
|
+
points: s === undefined ? [] : [s.startPoint, ...(s.bendPoints ?? []), s.endPoint],
|
|
80
|
+
label: label === undefined || label.x === undefined || label.y === undefined ? null : { x: label.x, y: label.y, w: label.width ?? 0 },
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
return { nodes, edges, width: graph.width ?? 0, height: graph.height ?? 0 };
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export interface WorkflowDagProps {
|
|
87
|
+
readonly view: WorkflowsView;
|
|
88
|
+
readonly phaseLabel: (phase: string) => string;
|
|
89
|
+
/** A box's runs and agents now, with its limit controls. */
|
|
90
|
+
readonly nodeStatus: (w: WorkflowView) => ReactNode;
|
|
91
|
+
/** The address of a workflow's own level, which its box's name opens. */
|
|
92
|
+
readonly hrefOfWorkflow: (workflow: string) => string;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function Node({ w, nodeStatus, href, style }: { readonly w: WorkflowView; readonly nodeStatus: (w: WorkflowView) => ReactNode; readonly href: string; readonly style?: CSSProperties }) {
|
|
96
|
+
return (
|
|
97
|
+
<div data-workflow={w.name} className="wp-node" style={style}>
|
|
98
|
+
<a className="wp-node-name" href={href} title={`Open ${w.name}: ${w.description}`}>{w.name} ›</a>
|
|
99
|
+
{w.queue === null ? null : <QueueBar queue={w.queue} />}
|
|
100
|
+
<div className="wp-node-status">{nodeStatus(w)}</div>
|
|
101
|
+
</div>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function WorkflowDag({ view, phaseLabel, nodeStatus, hrefOfWorkflow }: WorkflowDagProps) {
|
|
106
|
+
const all = view.groups.flatMap((g) => g.workflows);
|
|
107
|
+
const linkedNames = new Set(view.flows.flatMap((f) => [f.from, f.to]));
|
|
108
|
+
const linked = all.filter((w) => linkedNames.has(w.name));
|
|
109
|
+
const stageOf = new Map(view.groups.map((g, i) => [g.phase, i]));
|
|
110
|
+
|
|
111
|
+
// Each box's height, measured as drawn, then the layout from them; laid out again whenever a height or the flows change.
|
|
112
|
+
const map = useRef<HTMLDivElement>(null);
|
|
113
|
+
const [heights, setHeights] = useState<string>('');
|
|
114
|
+
const [laid, setLaid] = useState<Laid | null>(null);
|
|
115
|
+
const [failed, setFailed] = useState<string | null>(null);
|
|
116
|
+
// Opened at its first box: on a phone the box shows one box across, and a map opened at its left edge showed none.
|
|
117
|
+
const scrollBox = useRef<HTMLDivElement>(null);
|
|
118
|
+
const opened = useRef(false);
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
if (laid === null || opened.current || scrollBox.current === null) return;
|
|
121
|
+
const first = [...laid.nodes.values()].sort((a, b) => a.y - b.y || a.x - b.x)[0];
|
|
122
|
+
if (first === undefined) return;
|
|
123
|
+
opened.current = true;
|
|
124
|
+
if (scrollBox.current.clientWidth < laid.width) scrollBox.current.scrollLeft = Math.max(0, first.x - 12);
|
|
125
|
+
}, [laid]);
|
|
126
|
+
useLayoutEffect(() => {
|
|
127
|
+
const el = map.current;
|
|
128
|
+
if (el === null) return;
|
|
129
|
+
const measure = () => setHeights(JSON.stringify([...el.querySelectorAll('[data-workflow]')].map((n) => [n.getAttribute('data-workflow'), Math.ceil(n.getBoundingClientRect().height)])));
|
|
130
|
+
measure();
|
|
131
|
+
const watch = new ResizeObserver(measure);
|
|
132
|
+
for (const n of el.querySelectorAll('[data-workflow]')) watch.observe(n);
|
|
133
|
+
return () => watch.disconnect();
|
|
134
|
+
}, [view.at, linked.length]);
|
|
135
|
+
const flowsKey = JSON.stringify(view.flows.map((f) => [f.from, f.to, f.kind, flowLabel(f)]));
|
|
136
|
+
useEffect(() => {
|
|
137
|
+
if (heights === '') return;
|
|
138
|
+
const h = new Map(JSON.parse(heights) as Array<[string, number]>);
|
|
139
|
+
let current = true;
|
|
140
|
+
const inOrder = [...linked].sort((a, b) => a.place.stage - b.place.stage || a.place.depth - b.place.depth || a.name.localeCompare(b.name));
|
|
141
|
+
layOut({ workflows: inOrder.map((w) => ({ name: w.name, stage: stageOf.get(w.phase) ?? 0, height: h.get(w.name) ?? 120 })), flows: view.flows })
|
|
142
|
+
.then((l) => { if (current) { setLaid(l); setFailed(null); } })
|
|
143
|
+
.catch((e: unknown) => { if (current) setFailed(e instanceof Error ? e.message : String(e)); });
|
|
144
|
+
return () => { current = false; };
|
|
145
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- `linked` and `stageOf` follow `heights` and `flowsKey`.
|
|
146
|
+
}, [heights, flowsKey]);
|
|
147
|
+
|
|
148
|
+
// Each stage's band: from the top of its first box to the bottom of its last.
|
|
149
|
+
const bands = laid === null ? [] : view.groups.flatMap((g) => {
|
|
150
|
+
const ys = linked.filter((w) => w.phase === g.phase).flatMap((w) => { const n = laid.nodes.get(w.name); return n === undefined ? [] : [{ top: n.y, bottom: n.y + n.h }]; });
|
|
151
|
+
return ys.length === 0 ? [] : [{ phase: g.phase, top: Math.min(...ys.map((y) => y.top)) - 24, bottom: Math.max(...ys.map((y) => y.bottom)) + 14 }];
|
|
152
|
+
});
|
|
153
|
+
if (linked.length === 0) return null;
|
|
154
|
+
const others = all.length - linked.length;
|
|
155
|
+
|
|
156
|
+
return (
|
|
157
|
+
<div className="wp-dag-wrap">
|
|
158
|
+
<p className="wp-line wp-mut">
|
|
159
|
+
Each box is one workflow; its name opens it. Arrows point the way work goes, down the page: a solid arrow feeds the next
|
|
160
|
+
workflow's tasks; dashed, “sends back”, returns work to an earlier one. Each stage is a band, named on the left.
|
|
161
|
+
{others === 0 ? null : ` The ${others.toLocaleString('en-US')} workflow${others === 1 ? '' : 's'} no work flows to or from ${others === 1 ? 'is' : 'are'} in the list of steps below.`}
|
|
162
|
+
</p>
|
|
163
|
+
{failed === null ? null : <p className="wp-line wp-bad">The map could not be laid out: {failed}</p>}
|
|
164
|
+
<div ref={scrollBox} className="wp-dag-scroll">
|
|
165
|
+
<div ref={map} className="wp-dag" style={{ width: laid === null ? undefined : laid.width, height: laid === null ? undefined : laid.height }}>
|
|
166
|
+
{laid === null ? null : (
|
|
167
|
+
<svg className="wp-dag-edges" width={laid.width} height={laid.height} aria-hidden="true">
|
|
168
|
+
<defs>
|
|
169
|
+
<marker id="wp-arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="11" markerHeight="11" markerUnits="userSpaceOnUse" orient="auto">
|
|
170
|
+
<path d="M0,0 L10,5 L0,10 z" fill="var(--wp-edge)" />
|
|
171
|
+
</marker>
|
|
172
|
+
</defs>
|
|
173
|
+
{bands.map((b, i) => (
|
|
174
|
+
<g key={b.phase}>
|
|
175
|
+
<rect x={0} y={b.top} width={laid.width} height={b.bottom - b.top} fill={i % 2 === 0 ? 'var(--wp-band)' : 'transparent'} />
|
|
176
|
+
<foreignObject x={6} y={b.top + 6} width={GUTTER - 16} height={Math.max(40, b.bottom - b.top - 12)}>
|
|
177
|
+
<div className="wp-band-name">{phaseLabel(b.phase)}</div>
|
|
178
|
+
</foreignObject>
|
|
179
|
+
</g>
|
|
180
|
+
))}
|
|
181
|
+
{laid.edges.map(({ flow, points }) => (
|
|
182
|
+
<polyline key={`${flow.from}>${flow.to}>${flow.kind}`} points={points.map((p) => `${p.x},${p.y}`).join(' ')} fill="none" stroke="var(--wp-edge)"
|
|
183
|
+
strokeWidth={flow.kind === 'feeds' ? 1.8 : 1.5} strokeDasharray={DASH[flow.kind]} markerEnd="url(#wp-arrow)" />
|
|
184
|
+
))}
|
|
185
|
+
{laid.edges.map(({ flow, label }) => (label === null ? null : (
|
|
186
|
+
<g key={`label:${flow.from}>${flow.to}>${flow.kind}`}>
|
|
187
|
+
<rect x={label.x} y={label.y} width={label.w} height={LABEL_HEIGHT} rx={3} fill="var(--wp-bg)" stroke="var(--wp-edge)" strokeWidth="0.7" />
|
|
188
|
+
<text x={label.x + 5} y={label.y + 11} fontSize="10.5" fill="var(--wp-fg)">{flowLabel(flow)}{flow.why === null ? null : <title>{flow.why}</title>}</text>
|
|
189
|
+
</g>
|
|
190
|
+
)))}
|
|
191
|
+
</svg>
|
|
192
|
+
)}
|
|
193
|
+
{linked.map((w) => {
|
|
194
|
+
const at = laid?.nodes.get(w.name);
|
|
195
|
+
return (
|
|
196
|
+
<Node key={w.name} w={w} nodeStatus={nodeStatus} href={hrefOfWorkflow(w.name)}
|
|
197
|
+
style={at === undefined ? { position: 'absolute', left: 0, top: 0, visibility: 'hidden' } : { position: 'absolute', left: at.x, top: at.y }} />
|
|
198
|
+
);
|
|
199
|
+
})}
|
|
200
|
+
</div>
|
|
201
|
+
</div>
|
|
202
|
+
</div>
|
|
203
|
+
);
|
|
204
|
+
}
|
|
@@ -20,6 +20,7 @@ import { QueueBar } from './queue-bar';
|
|
|
20
20
|
import { QueueChart } from './queue-chart';
|
|
21
21
|
import { Breadcrumb, StepList } from './workflow-drilldown';
|
|
22
22
|
import { StepGraph } from './step-graph';
|
|
23
|
+
import { WorkflowDag } from './workflow-dag';
|
|
23
24
|
import { AgentUsageLine } from './agent-usage-line';
|
|
24
25
|
import type { AgentUsage } from './agent-usage';
|
|
25
26
|
import { MachineControls } from './machine-controls';
|
|
@@ -109,12 +110,12 @@ export const usePolledJson = <A,>(url: string, everyMs: number): { readonly data
|
|
|
109
110
|
return { data, error };
|
|
110
111
|
};
|
|
111
112
|
|
|
112
|
-
const costCells = (c: StepCost | null,
|
|
113
|
+
const costCells = (c: StepCost | null, agentic: boolean): ReactNode => (
|
|
113
114
|
<>
|
|
114
115
|
<td className="wp-r">{c === null ? '' : c.calls.toLocaleString('en-US')}</td>
|
|
115
116
|
<td className={c !== null && c.failed > 0 ? 'wp-r wp-bad' : 'wp-r'}>{c === null || c.failed === 0 ? '' : c.failed.toLocaleString('en-US')}</td>
|
|
116
117
|
<td className="wp-r">{c === null ? '' : duration(c.seconds)}</td>
|
|
117
|
-
<td className="wp-r">{c === null || !
|
|
118
|
+
<td className="wp-r">{c === null || !agentic ? '' : `${compact(c.inputTokens)} / ${compact(c.outputTokens)}`}</td>
|
|
118
119
|
<td className="wp-r">{c === null ? '' : duration(c.cpuSeconds)}</td>
|
|
119
120
|
<td className="wp-r">{c === null || c.items === 0 ? '' : c.items.toLocaleString('en-US')}</td>
|
|
120
121
|
</>
|
|
@@ -136,7 +137,7 @@ function StepsTable({ workflow, usesAgents, runs, now }: { readonly workflow: Wo
|
|
|
136
137
|
<div className="wp-tablewrap"><table className="wp-table">
|
|
137
138
|
<thead>
|
|
138
139
|
<tr>
|
|
139
|
-
<th>step</th><th title="
|
|
140
|
+
<th>step</th><th title="Deterministic: code only. Agentic: an agent does it. Classification: a separate classifier model decides.">how it runs</th><th>runs now</th>
|
|
140
141
|
<th className="wp-r">calls</th><th className="wp-r">failed</th><th className="wp-r">time</th>
|
|
141
142
|
<th className="wp-r" title="Input tokens, fresh and cached / output tokens">tokens in / out</th>
|
|
142
143
|
<th className="wp-r" title="Its own and its processes' CPU">CPU</th><th className="wp-r">items</th>
|
|
@@ -150,9 +151,9 @@ function StepsTable({ workflow, usesAgents, runs, now }: { readonly workflow: Wo
|
|
|
150
151
|
<Fragment key={s.name}>
|
|
151
152
|
<tr>
|
|
152
153
|
<td title={s.description} className={s.declared ? '' : 'wp-bad'}>{s.name}{s.declared ? '' : ' (not declared)'}</td>
|
|
153
|
-
<td>{s.
|
|
154
|
+
<td>{s.runs ?? ''}</td>
|
|
154
155
|
<td className="wp-mut">{nowCell(at, now)}</td>
|
|
155
|
-
{costCells(s.cost, s.
|
|
156
|
+
{costCells(s.cost, s.runs === 'agentic')}
|
|
156
157
|
<td className="wp-mut" title={s.endings.map((e) => `${e.records} ${e.outcome}: ${e.reason}`).join('\n')}>{s.endings.length === 0 ? '' : `${s.endings[0]!.reason} (${s.endings[0]!.records})`}</td>
|
|
157
158
|
</tr>
|
|
158
159
|
{at?.waitingOn === null || at?.waitingOn === undefined ? null : (
|
|
@@ -284,7 +285,7 @@ const FIGURES_EVERY_MS = 15_000;
|
|
|
284
285
|
* An open workflow: what it gave and cost, its steps, its step graph and where its runs stopped, read from its own records
|
|
285
286
|
* while it is open. The figures of the workflow opened before it are never shown under this one's name.
|
|
286
287
|
*/
|
|
287
|
-
function WorkflowDetail({ workflow, runs, now, figuresUrl }: { readonly workflow: WorkflowView; readonly runs: WorkflowRunsNow | undefined; readonly now: number; readonly figuresUrl: (workflow: string) => string }) {
|
|
288
|
+
function WorkflowDetail({ workflow, runs, now, figuresUrl, hrefOfWorkflow }: { readonly workflow: WorkflowView; readonly runs: WorkflowRunsNow | undefined; readonly now: number; readonly figuresUrl: (workflow: string) => string; readonly hrefOfWorkflow: (workflow: string) => string }) {
|
|
288
289
|
const read = usePolledJson<WorkflowFigures>(figuresUrl(workflow.name), FIGURES_EVERY_MS);
|
|
289
290
|
const figures = read.data !== null && read.data.workflow === workflow.name ? read.data : null;
|
|
290
291
|
return (
|
|
@@ -307,7 +308,7 @@ function WorkflowDetail({ workflow, runs, now, figuresUrl }: { readonly workflow
|
|
|
307
308
|
<p className="wp-line">{runCostLine(figures)}</p>
|
|
308
309
|
<StepsTable workflow={figures} usesAgents={workflow.usesAgents} runs={runs} now={now} />
|
|
309
310
|
<h4 className="wp-h4">Step graph</h4>
|
|
310
|
-
<div className="wp-tablewrap"><StepGraph graph={figures.graph} /></div>
|
|
311
|
+
<div className="wp-tablewrap"><StepGraph graph={figures.graph} hrefOfWorkflow={hrefOfWorkflow} /></div>
|
|
311
312
|
<h4 className="wp-h4">Where runs stopped</h4>
|
|
312
313
|
<FunnelTable funnel={figures.funnel} />
|
|
313
314
|
</>
|
|
@@ -344,12 +345,20 @@ function DrillLevelView({ data, path, hrefOf, now, figuresUrl, sourceHref, phase
|
|
|
344
345
|
{/* Its tasks over time: at the top a row for each step that has tasks; below it, the workflow opened and each such step of its own. */}
|
|
345
346
|
<QueueChart view={data.view} level={path.join("/")} rowWord={w === null ? "step" : "workflow"}
|
|
346
347
|
workflows={[...(w === null ? [] : [w]), ...level.steps.flatMap((s) => { const sub = s.workflow === null ? undefined : workflowOf(s.workflow); return sub === undefined || sub.name === w?.name ? [] : [sub]; })]} />
|
|
348
|
+
{/* At the top, the map of its steps: each workflow a box whose name opens it, with the arrows work takes between them. */}
|
|
349
|
+
{w !== null ? null : (
|
|
350
|
+
<>
|
|
351
|
+
<h3 className="wp-h3">Map</h3>
|
|
352
|
+
<WorkflowDag view={data.view} phaseLabel={phaseLabel} hrefOfWorkflow={(name) => hrefOf([name])}
|
|
353
|
+
nodeStatus={(node) => <WorkflowStatus workflow={node} runs={runsOf(node.name)} limits={node.limits} setLimit={setLimit} />} />
|
|
354
|
+
</>
|
|
355
|
+
)}
|
|
347
356
|
<h3 className="wp-h3">Steps</h3>
|
|
348
357
|
<StepList
|
|
349
358
|
steps={level.steps} path={level.crumbs[level.crumbs.length - 1]!.path} hrefOf={hrefOf} workflowOf={workflowOf} runsOf={runsOf} runs={runs}
|
|
350
359
|
{...(w === null ? { groupKey: (s: StepSummary) => stageOf(s.workflow), groupOf: (s: StepSummary) => { const stage = stageOf(s.workflow); return stage === null ? null : phaseLabel(stage); } } : {})}
|
|
351
360
|
/>
|
|
352
|
-
{w === null ? null : <WorkflowDetail workflow={w} runs={runs} now={now} figuresUrl={figuresUrl} />}
|
|
361
|
+
{w === null ? null : <WorkflowDetail workflow={w} runs={runs} now={now} figuresUrl={figuresUrl} hrefOfWorkflow={(name) => hrefOf([...level.crumbs[level.crumbs.length - 1]!.path, name])} />}
|
|
353
362
|
</section>
|
|
354
363
|
);
|
|
355
364
|
}
|
package/src/index.ts
CHANGED
|
@@ -50,6 +50,7 @@ export * from './views/runs-now';
|
|
|
50
50
|
export * from './views/step-funnel';
|
|
51
51
|
export * from './views/step-graph';
|
|
52
52
|
export * from './views/workflows-view';
|
|
53
|
+
export * from './views/workflow-flows';
|
|
53
54
|
export type { NewNote, TaskStore, TextChange } from './storage/task-store';
|
|
54
55
|
export type { AgentUsage, UsageLimit } from './dashboard/agent-usage';
|
|
55
56
|
|
package/src/steps.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* writes its one record (`storage/step-records.ts`): start, end, outcome, tokens, compiles, and a heartbeat while an agent
|
|
7
7
|
* works. A dashboard derives all it says from those records and these declarations.
|
|
8
8
|
*
|
|
9
|
-
* const PICK = defineStep({ name: 'Pick',
|
|
9
|
+
* const PICK = defineStep({ name: 'Pick', runs: 'deterministic', description: '...', at: import.meta.path, success: Schema.Number });
|
|
10
10
|
* export const MyWorkflow = defineWorkflow({ phase: 'main', description: '...', at: import.meta.path, steps: () => [PICK],
|
|
11
11
|
* graph: () => [{ from: RUN_STARTS, to: PICK.name, when: 'each run' }, { from: PICK.name, to: RUN_ENDS, when: 'always' }] })('My workflow', { payload, success, error, idempotencyKey });
|
|
12
12
|
* ... yield* PICK.run(Effect.gen(...)); a repeating step gives its number: PICK.run(body, { call: 2 })
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
* first agent step: an item that passes now is finished, with no agent and no tokens; one that fails gives the agent the
|
|
24
24
|
* exact failure as its input; one that cannot be tested says why.
|
|
25
25
|
*
|
|
26
|
-
* An agent call needs `AgentStep`, which only
|
|
26
|
+
* An agent call needs `AgentStep`, which only a step that runs agentically (`runs: 'agentic'`) provides, so it cannot compile anywhere else.
|
|
27
27
|
*
|
|
28
28
|
* A BUDGET LIMITS THE AGENTS WORKING, NOT ONLY THE RUNS STARTED. Before each agent step, a run its workflow's budget has no
|
|
29
29
|
* room for ends: oldest runs keep their places, so with 10 going and a budget of 5 exactly the newest 5 end, and no two runs
|
|
@@ -72,7 +72,7 @@ export interface ApiUsage {
|
|
|
72
72
|
readonly output_tokens?: number | null;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
/** Provided only inside
|
|
75
|
+
/** Provided only inside a step that runs agentically; an agent call reports what it spent through it. */
|
|
76
76
|
export class AgentStep extends Context.Service<AgentStep, {
|
|
77
77
|
/** A request's usage so far, by the message it belongs to, as it arrives: the step's record shows it at once. */
|
|
78
78
|
readonly usage: (message: string, model: string | null, usage: ApiUsage) => void;
|
|
@@ -98,28 +98,40 @@ export const isStoodDown = (failure: unknown): boolean => failure === STOOD_DOWN
|
|
|
98
98
|
|
|
99
99
|
/** Whether a run is surplus: it is past the budget in the workflow's runs, oldest first. A run not listed is not counted. Pure. */
|
|
100
100
|
export const surplusRun = (oldestFirst: ReadonlyArray<string>, run: string, budget: number): boolean => oldestFirst.indexOf(run) >= budget;
|
|
101
|
-
|
|
101
|
+
/**
|
|
102
102
|
/**
|
|
103
103
|
* WHAT A STEP IS, as a page says it in words. Alex, 2026-11-19: "there are different kinds of workflow steps. like a check,
|
|
104
104
|
* like a sub workflow."
|
|
105
105
|
*
|
|
106
|
-
* step
|
|
107
|
-
* agent calls an agent;
|
|
106
|
+
* step does part of the work;
|
|
108
107
|
* check decides whether the work passes;
|
|
109
108
|
* sub-workflow a workflow used as a step of another workflow (`StepDeclaration.workflow` names it).
|
|
110
109
|
*/
|
|
111
|
-
export const STEP_KINDS = ['step', '
|
|
110
|
+
export const STEP_KINDS = ['step', 'check', 'sub-workflow'] as const;
|
|
112
111
|
export type StepKind = (typeof STEP_KINDS)[number];
|
|
113
112
|
|
|
114
|
-
/**
|
|
115
|
-
|
|
116
|
-
|
|
113
|
+
/**
|
|
114
|
+
* HOW A STEP RUNS, a separate question from what it is. Alex, 2026-11-19: "rather than 'no ai' or 'agent' I think a step
|
|
115
|
+
* should be labeled as one of the following 'deterministic', 'agentic' or 'classification' where that third option allows
|
|
116
|
+
* for steps which use a separate classifier model".
|
|
117
|
+
*
|
|
118
|
+
* deterministic code only;
|
|
119
|
+
* agentic an agent does it: it waits for one of its workflow's agents (`untilAgentSlot`);
|
|
120
|
+
* classification a separate classifier model decides.
|
|
121
|
+
*
|
|
122
|
+
* A step or a check is any of the three. A sub-workflow step states none: its workflow's own steps state theirs.
|
|
123
|
+
*/
|
|
124
|
+
export const STEP_RUNS = ['deterministic', 'agentic', 'classification'] as const;
|
|
125
|
+
export type StepRuns = (typeof STEP_RUNS)[number];
|
|
126
|
+
|
|
127
|
+
/** A step's kind, from its declaration: the kind it states, a check where it is its workflow's test, a step otherwise. Pure. */
|
|
128
|
+
export const stepKindOf = (s: Pick<StepDeclaration, 'test' | 'kind'>): StepKind => s.kind ?? (s.test === true ? 'check' : 'step');
|
|
117
129
|
|
|
118
130
|
export interface StepDeclaration {
|
|
119
131
|
readonly name: string;
|
|
120
|
-
/**
|
|
121
|
-
readonly
|
|
122
|
-
/** What it is where it is
|
|
132
|
+
/** How it runs; none for a sub-workflow step. */
|
|
133
|
+
readonly runs: StepRuns | null;
|
|
134
|
+
/** What it is where it is not a plain step (`stepKindOf`). */
|
|
123
135
|
readonly kind?: 'check' | 'sub-workflow';
|
|
124
136
|
/** For a sub-workflow step: the workflow it runs, by name. */
|
|
125
137
|
readonly workflow?: string;
|
|
@@ -218,6 +230,11 @@ export interface WorkflowDeclaration<Phase extends string = string, R = never> {
|
|
|
218
230
|
readonly items?: () => Effect.Effect<ReadonlyArray<string>, unknown, R>;
|
|
219
231
|
/** Its Pick takes the first task of its queue it can claim (`tasks.ts` `queueOrder`), so a dashboard lists that queue. */
|
|
220
232
|
readonly picksQueueHead?: true;
|
|
233
|
+
/**
|
|
234
|
+
* The workflows whose results become its tasks: the arrows of the project's map (`views/workflow-flows.ts`). A workflow
|
|
235
|
+
* used as a step of another needs none: it is drawn inside that one.
|
|
236
|
+
*/
|
|
237
|
+
readonly fedBy?: ReadonlyArray<string>;
|
|
221
238
|
/** Its step graph (`StepEdge`); none until it declares one. */
|
|
222
239
|
readonly graph?: () => ReadonlyArray<StepEdge>;
|
|
223
240
|
/** What it runs on (`WorkflowInputs`); none until it declares them, and it runs whenever its trigger says. */
|
|
@@ -250,7 +267,7 @@ export const runLimitOf = (d: Pick<WorkflowDeclaration<string, unknown>, 'pendin
|
|
|
250
267
|
export const hasAList = (d: Pick<WorkflowDeclaration<string, unknown>, 'pending' | 'items'>): boolean => d.pending !== undefined || d.items !== undefined;
|
|
251
268
|
|
|
252
269
|
/** Whether a step uses an agent: it is an agent step, or a sub-workflow step whose workflow has one at any depth. Pure. */
|
|
253
|
-
export const stepUsesAnAgent = (s: Pick<StepDeclaration, '
|
|
270
|
+
export const stepUsesAnAgent = (s: Pick<StepDeclaration, 'runs' | 'agentUnder'>): boolean => s.runs === 'agentic' || s.agentUnder?.() === true;
|
|
254
271
|
|
|
255
272
|
/** Whether a workflow's budget rules it: a declared list, and an agent step of its own or under a sub-workflow step. Pure. */
|
|
256
273
|
export const keptRunningByItsBudget = (d: Pick<WorkflowDeclaration<string, unknown>, 'pending' | 'items' | 'steps'>): boolean =>
|
|
@@ -520,16 +537,16 @@ export const makeSteps = <Phase extends string, R>(deps: {
|
|
|
520
537
|
const toolInputs: string[] = [];
|
|
521
538
|
let before: TreeHashes | null = null;
|
|
522
539
|
let recordId: number | null = null;
|
|
523
|
-
let meter = new StepMeter(null, step.
|
|
540
|
+
let meter = new StepMeter(null, (step.runs === 'agentic'), [], null);
|
|
524
541
|
return Effect.acquireUseRelease(
|
|
525
542
|
Effect.flatMap(Effect.gen(function* () {
|
|
526
543
|
yield* checkEdge(instance.workflow._tag, instance.executionId, step.name);
|
|
527
544
|
// A sub-workflow step is run again when its workflow has ended: it takes its open record up again, and names the run it started.
|
|
528
|
-
const id = yield* recorded('open its record', records.openStepRun({ workflow: instance.workflow._tag, run: instance.executionId, step: step.name, call, agent: step.
|
|
545
|
+
const id = yield* recorded('open its record', records.openStepRun({ workflow: instance.workflow._tag, run: instance.executionId, step: step.name, call, agent: (step.runs === 'agentic'), subject, ...(childRun === null ? {} : { resume: true as const }) }));
|
|
529
546
|
if (id !== null && childRun !== null) yield* recorded('name the run it started', records.setStepChild({ id, childRun }));
|
|
530
|
-
const beat = step.
|
|
547
|
+
const beat = (step.runs === 'agentic') && id !== null ? setInterval(() => recordNow('its heartbeat', records.beatStepRun(id)), AGENT_BEAT_MS) : null;
|
|
531
548
|
recordId = id;
|
|
532
|
-
meter = new StepMeter(id, step.
|
|
549
|
+
meter = new StepMeter(id, (step.runs === 'agentic'), step.writes ?? [], null);
|
|
533
550
|
meterOpened(meter);
|
|
534
551
|
return { id, beat };
|
|
535
552
|
}), (opened) => (mayWrite === undefined
|
|
@@ -543,7 +560,7 @@ export const makeSteps = <Phase extends string, R>(deps: {
|
|
|
543
560
|
return opened;
|
|
544
561
|
}))),
|
|
545
562
|
() => pipe(
|
|
546
|
-
step.
|
|
563
|
+
(step.runs === 'agentic') ? Effect.andThen(untilAgentSlot(instance, () => recordId), execute) : execute,
|
|
547
564
|
// What it changed, on its record, and a change it named outside where it may write refuses the step.
|
|
548
565
|
Effect.tap(() => Effect.suspend(() => {
|
|
549
566
|
const earlier = before;
|
|
@@ -560,12 +577,12 @@ export const makeSteps = <Phase extends string, R>(deps: {
|
|
|
560
577
|
})),
|
|
561
578
|
Effect.provideService(CurrentMeter, meter),
|
|
562
579
|
Effect.provideService(deps.CurrentStepUsage, meter),
|
|
563
|
-
step.
|
|
580
|
+
(step.runs === 'agentic') ? Effect.provideService(AgentStep, { usage, report, touched: (inputs) => { toolInputs.push(...inputs); }, waiting: (why) => { if (recordId !== null) recordNow('say what it waits on', records.setStepWaiting({ id: recordId, waiting: why })); } }) : (e) => e,
|
|
564
581
|
) as Effect.Effect<A, E, Exclude<R2, AgentStep>>,
|
|
565
582
|
({ id, beat }, exit) => Effect.gen(function* () {
|
|
566
583
|
if (beat !== null) clearInterval(beat);
|
|
567
584
|
// Its agent slot is free for its workflow's next run waiting on one.
|
|
568
|
-
if (step.
|
|
585
|
+
if ((step.runs === 'agentic')) deps.wakes.wakePicksOf(TOPS.get(instance.executionId)?.workflow ?? instance.workflow._tag, 'an agent step ended');
|
|
569
586
|
// An interrupted step is no move: the run does it again.
|
|
570
587
|
if (Exit.isSuccess(exit) || !Cause.hasInterrupts(exit.cause)) lastStepRan.set(instance.executionId, { step: step.name, failed: !Exit.isSuccess(exit) });
|
|
571
588
|
meterClosed(meter);
|
|
@@ -669,7 +686,8 @@ export const makeSteps = <Phase extends string, R>(deps: {
|
|
|
669
686
|
/** A step: its declaration, and `run`, the only way to run it. */
|
|
670
687
|
const defineStep = <A>(d: {
|
|
671
688
|
readonly name: string;
|
|
672
|
-
|
|
689
|
+
/** How it runs (`StepRuns`). */
|
|
690
|
+
readonly runs: StepRuns;
|
|
673
691
|
readonly description: string;
|
|
674
692
|
/** `import.meta.path`, for its link. */
|
|
675
693
|
readonly at: string;
|
|
@@ -680,7 +698,7 @@ export const makeSteps = <Phase extends string, R>(deps: {
|
|
|
680
698
|
readonly subject?: (a: A) => string | null;
|
|
681
699
|
/** For an agent step with tools: the paths, from the project's root, it may change (`step-files.ts`). */
|
|
682
700
|
readonly mayWrite?: ReadonlyArray<string>;
|
|
683
|
-
/**
|
|
701
|
+
/** A check decides whether the work passes (`StepKind`); absent, a plain step. */
|
|
684
702
|
readonly kind?: 'check';
|
|
685
703
|
/** Marks the no-agent test an item goes through first. Use `defineItemTest` where the step only tests. */
|
|
686
704
|
readonly test?: true;
|
|
@@ -701,7 +719,7 @@ export const makeSteps = <Phase extends string, R>(deps: {
|
|
|
701
719
|
}) => {
|
|
702
720
|
const writes = [...(d.mayWrite ?? []), ...(d.writes ?? [])];
|
|
703
721
|
const declaration: StepDeclaration = {
|
|
704
|
-
name: d.name,
|
|
722
|
+
name: d.name, runs: d.runs, description: d.description, ...(d.kind === undefined ? {} : { kind: d.kind }), ...(d.test === undefined ? {} : { test: true }), ...(d.shared === undefined ? {} : { shared: true }), ...(d.perItem === undefined ? {} : { perItem: true }), ...(d.picked === undefined ? {} : { picks: true }),
|
|
705
723
|
...(writes.length === 0 ? {} : { writes }),
|
|
706
724
|
source: d.prompt ?? { path: sourcePath(d.at), anchor: `'${d.name}'` },
|
|
707
725
|
};
|
|
@@ -713,7 +731,7 @@ export const makeSteps = <Phase extends string, R>(deps: {
|
|
|
713
731
|
success: d.success,
|
|
714
732
|
error: Schema.String,
|
|
715
733
|
execute: pipe(
|
|
716
|
-
standDownIfSurplus({ agent: d.
|
|
734
|
+
standDownIfSurplus({ agent: d.runs === 'agentic', picks: d.picked !== undefined }),
|
|
717
735
|
Effect.andThen(measured(declaration, options?.call ?? null, options?.subject ?? null, d.subject, d.reason, d.mayWrite, d.picked === undefined ? execute : untilPicked(d.picked, execute))),
|
|
718
736
|
Effect.retry({ while: deps.isTransientFailure, times: 10, schedule: Schedule.spaced('3 seconds') }),
|
|
719
737
|
Effect.mapError(describeFailure),
|
|
@@ -743,7 +761,7 @@ export const makeSteps = <Phase extends string, R>(deps: {
|
|
|
743
761
|
|
|
744
762
|
/** The no-agent test step of a workflow, before its first agent step. */
|
|
745
763
|
const defineItemTest = (d: { readonly description: string; readonly at: string }) => {
|
|
746
|
-
const step = defineStep({ name: 'Test',
|
|
764
|
+
const step = defineStep({ name: 'Test', runs: 'deterministic', test: true, description: d.description, at: d.at, prompt: { path: sourcePath(d.at), anchor: 'defineItemTest(' }, success: ItemTest });
|
|
747
765
|
return { ...step, run: <E, R2>(test: Effect.Effect<ItemTest, E, R2>, options?: { readonly call?: number; readonly subject?: string }) => step.run(heldToItsList(test, options?.subject ?? null), options) };
|
|
748
766
|
};
|
|
749
767
|
|
|
@@ -779,7 +797,7 @@ export const makeSteps = <Phase extends string, R>(deps: {
|
|
|
779
797
|
const given = (result: unknown): Effect.Effect<A, string> => (isDeclared(result) ? Effect.succeed(result) : Effect.fail(`${child} gave a result that is not what this step declares`));
|
|
780
798
|
const name = d.as ?? child;
|
|
781
799
|
const declaration: StepDeclaration = {
|
|
782
|
-
name,
|
|
800
|
+
name, runs: null, kind: 'sub-workflow', workflow: child,
|
|
783
801
|
description: DECLARED.get(child)?.description ?? `Runs ${child}.`,
|
|
784
802
|
source: DECLARED.get(child)?.source ?? { path: sourcePath(d.at), anchor: `'${child}'` },
|
|
785
803
|
agentUnder: () => {
|
|
@@ -858,6 +876,11 @@ export const makeSteps = <Phase extends string, R>(deps: {
|
|
|
858
876
|
/** Every item it has a task for, done or not (`WorkflowDeclaration.items`), in place of `pending`. */
|
|
859
877
|
readonly items?: () => Effect.Effect<ReadonlyArray<string>, unknown, R>;
|
|
860
878
|
readonly picksQueueHead?: true;
|
|
879
|
+
/**
|
|
880
|
+
* The workflows whose results become its tasks: the arrows of the project's map (`views/workflow-flows.ts`). A workflow
|
|
881
|
+
* used as a step of another needs none: it is drawn inside that one.
|
|
882
|
+
*/
|
|
883
|
+
readonly fedBy?: ReadonlyArray<string>;
|
|
861
884
|
/** Its step graph: which step can follow which, and when. */
|
|
862
885
|
readonly graph?: () => ReadonlyArray<StepEdge>;
|
|
863
886
|
/** What it runs on: its trigger starts a run only when they changed (`runIfInputsChanged`). */
|
|
@@ -897,6 +920,7 @@ export const makeSteps = <Phase extends string, R>(deps: {
|
|
|
897
920
|
...(d.pending === undefined ? {} : { pending: d.pending }),
|
|
898
921
|
...(d.items === undefined ? {} : { items: d.items }),
|
|
899
922
|
...(d.picksQueueHead === undefined ? {} : { picksQueueHead: d.picksQueueHead }),
|
|
923
|
+
...(d.fedBy === undefined ? {} : { fedBy: d.fedBy }),
|
|
900
924
|
...(d.inputs === undefined ? {} : { inputs: d.inputs }),
|
|
901
925
|
...(d.taskInputs === undefined ? {} : { taskInputs: d.taskInputs }),
|
|
902
926
|
item: d.item,
|
|
@@ -995,7 +1019,7 @@ export const makeSteps = <Phase extends string, R>(deps: {
|
|
|
995
1019
|
states: { readonly phase: Phase; readonly description: string; readonly stepDescription: string; readonly at: string; readonly writes?: ReadonlyArray<string>; readonly inputs?: WorkflowInputs<R> },
|
|
996
1020
|
name: string, step: string, success: Schema.Codec<A, unknown>, execute: Effect.Effect<A, E, R2>,
|
|
997
1021
|
) => {
|
|
998
|
-
const theStep = defineStep({ name: step,
|
|
1022
|
+
const theStep = defineStep({ name: step, runs: 'deterministic', shared: true, description: states.stepDescription, at: states.at, success, ...(states.writes === undefined ? {} : { writes: states.writes }) });
|
|
999
1023
|
const workflow = defineWorkflow({ phase: states.phase, description: states.description, at: states.at, steps: () => [theStep], item: null, ...(states.inputs === undefined ? {} : { inputs: states.inputs }),
|
|
1000
1024
|
graph: () => [{ from: RUN_STARTS, to: step, when: 'each turn' }, { from: step, to: RUN_ENDS, when: 'always' }] })(name, {
|
|
1001
1025
|
payload: { turn: Schema.Number },
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
stepErrorKept, type FunnelStepRecord, type ItemCost, type ItemHistoryRow, type LastStepNow, type NewestStepRecord, type RunCost, type RunOutcomeRow, type StepEdgeTaken,
|
|
12
12
|
type StepFileCount, type StepRecords, type StepRunRow, type UndeclaredWrites, type WorkStep, AGENT_LIVE_SECONDS,
|
|
13
13
|
} from './step-records';
|
|
14
|
-
import { LISTED_AGAIN, MOVED_TO_FRONT, STATUS_KINDS, STOOD_DOWN_OUTCOME, TRIES_START_AGAIN_KINDS, type Listed, type NewNote, type QueueCount, type TaskNote, type TaskRef, type TaskState, type TaskStore } from './task-store';
|
|
14
|
+
import { LISTED_AGAIN, MOVED_TO_FRONT, STATUS_KINDS, STOOD_DOWN_OUTCOME, TRIES_START_AGAIN_KINDS, type Listed, type ListedWait, type NewNote, type QueueCount, type ReturnedBetween, type TaskNote, type TaskRef, type TaskState, type TaskStore } from './task-store';
|
|
15
15
|
import type { InputRecords, InputRun } from './input-records';
|
|
16
16
|
import { storeCall, storeCalls } from './storage-error';
|
|
17
17
|
|
|
@@ -779,6 +779,16 @@ export const sqliteStore = (options: {
|
|
|
779
779
|
WHERE at >= ?1 OR at = (SELECT MAX(p.at) FROM queue_counts p WHERE p.workflow = q.workflow AND p.bucket = q.bucket AND p.at < ?1)
|
|
780
780
|
ORDER BY at`,
|
|
781
781
|
).all(since) as ReadonlyArray<QueueCount>, [])),
|
|
782
|
+
returnedBetween: () => storeCall('tasks: returnedBetween', () =>
|
|
783
|
+
read((db) => db.query(
|
|
784
|
+
`SELECT n.by_workflow AS "from", t.workflow AS "to", COUNT(*) AS notes, MAX(n.at) AS last FROM task_notes n JOIN tasks t ON t.id = n.task
|
|
785
|
+
WHERE n.kind IN (${TRIES_START_AGAIN_KINDS.map((k) => `'${k}'`).join(', ')}) AND n.by_workflow IS NOT NULL AND n.by_workflow <> t.workflow GROUP BY 1, 2 ORDER BY 1, 2`,
|
|
786
|
+
).all() as ReadonlyArray<ReturnedBetween>, [])),
|
|
787
|
+
listedWaits: () => storeCall('tasks: listedWaits', () =>
|
|
788
|
+
read((db) => db.query(
|
|
789
|
+
`SELECT workflow, json_extract(listed, '$.on') AS "on", json_extract(listed, '$.label') AS label, COUNT(*) AS tasks FROM tasks
|
|
790
|
+
WHERE listed IS NOT NULL AND json_extract(listed, '$.kind') = 'wait' GROUP BY 1, 2, 3 ORDER BY 1, 2, 3`,
|
|
791
|
+
).all() as ReadonlyArray<ListedWait>, [])),
|
|
782
792
|
writable: () => options.file() !== null,
|
|
783
793
|
};
|
|
784
794
|
|
|
@@ -127,6 +127,25 @@ export interface QueueCount {
|
|
|
127
127
|
readonly tasks: number;
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
+
/**
|
|
131
|
+
* Tasks of one workflow that a step of another returned to their queue (`tasks.ts` `requeue`, `reopen`): how many notes,
|
|
132
|
+
* the last when.
|
|
133
|
+
*/
|
|
134
|
+
export interface ReturnedBetween {
|
|
135
|
+
readonly from: string;
|
|
136
|
+
readonly to: string;
|
|
137
|
+
readonly notes: number;
|
|
138
|
+
readonly last: number;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** A workflow's tasks its list last put on one wait, by what they wait on and the list's words for it. */
|
|
142
|
+
export interface ListedWait {
|
|
143
|
+
readonly workflow: string;
|
|
144
|
+
readonly on: string;
|
|
145
|
+
readonly label: string;
|
|
146
|
+
readonly tasks: number;
|
|
147
|
+
}
|
|
148
|
+
|
|
130
149
|
/** What a reading of a workflow's list changed. */
|
|
131
150
|
export interface ListingRecorded {
|
|
132
151
|
/** Whether it put any task in the queue: one new to the list, or one it lists again. */
|
|
@@ -184,6 +203,10 @@ export interface TaskStore {
|
|
|
184
203
|
readonly recordQueueCounts: (r: { readonly at: number; readonly counts: ReadonlyArray<Omit<QueueCount, 'at'>> }) => Effect.Effect<void, StorageError>;
|
|
185
204
|
/** Each count recorded since `since`, and for each queue and status the last recorded before it, oldest first. */
|
|
186
205
|
readonly queueCountsSince: (since: number) => Effect.Effect<ReadonlyArray<QueueCount>, StorageError>;
|
|
206
|
+
/** Every workflow a step of which returned another's tasks to their queue, by the two. */
|
|
207
|
+
readonly returnedBetween: () => Effect.Effect<ReadonlyArray<ReturnedBetween>, StorageError>;
|
|
208
|
+
/** Every wait a workflow's list puts its tasks on now, with how many. */
|
|
209
|
+
readonly listedWaits: () => Effect.Effect<ReadonlyArray<ListedWait>, StorageError>;
|
|
187
210
|
/** Whether the store can be written: false in a test that named no store. */
|
|
188
211
|
readonly writable: () => boolean;
|
|
189
212
|
}
|
package/src/views/runs-now.ts
CHANGED
|
@@ -44,7 +44,7 @@ export interface PhaseRunsNow<Phase extends string = string> {
|
|
|
44
44
|
readonly workflows: ReadonlyArray<WorkflowRunsNow>;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
type Declared<Phase extends string> = { readonly name: string; readonly phase: Phase; readonly steps: () => ReadonlyArray<Pick<StepDeclaration, 'name' | '
|
|
47
|
+
type Declared<Phase extends string> = { readonly name: string; readonly phase: Phase; readonly steps: () => ReadonlyArray<Pick<StepDeclaration, 'name' | 'runs'>> };
|
|
48
48
|
|
|
49
49
|
const sum = <T>(xs: ReadonlyArray<T>, f: (x: T) => number) => xs.reduce((a, x) => a + f(x), 0);
|
|
50
50
|
|
|
@@ -53,7 +53,7 @@ const workflowRunsNow = <Phase extends string>(d: Declared<Phase>, runs: Readonl
|
|
|
53
53
|
const r = newest.get(run);
|
|
54
54
|
return r === undefined ? [] : [r];
|
|
55
55
|
});
|
|
56
|
-
const declared = d.steps().map((s) => ({ name: s.name, agent: s.
|
|
56
|
+
const declared = d.steps().map((s) => ({ name: s.name, agent: s.runs === 'agentic' }));
|
|
57
57
|
const undeclared = [...new Set(records.map((r) => r.step))].filter((name) => !declared.some((s) => s.name === name))
|
|
58
58
|
.map((name) => ({ name, agent: records.some((r) => r.step === name && r.agent === 1) }));
|
|
59
59
|
const steps = [...declared, ...undeclared].map((s): StepRunsNow => {
|
package/src/views/step-funnel.ts
CHANGED
|
@@ -62,7 +62,7 @@ export const FUNNEL_WINDOW_HOURS = [1, 24] as const;
|
|
|
62
62
|
/** Reasons listed under the step most runs stopped at; the rest are counted together. */
|
|
63
63
|
export const TOP_STOP_REASONS = 3;
|
|
64
64
|
|
|
65
|
-
type Declared = { readonly item: string | null } & { readonly steps: () => ReadonlyArray<Pick<StepDeclaration, 'name' | '
|
|
65
|
+
type Declared = { readonly item: string | null } & { readonly steps: () => ReadonlyArray<Pick<StepDeclaration, 'name' | 'runs'>> };
|
|
66
66
|
|
|
67
67
|
/** The commonest of a run's item outcomes, so a batch run gives one reason. */
|
|
68
68
|
const commonest = (xs: ReadonlyArray<string>): string => {
|
|
@@ -123,7 +123,7 @@ export const stepFunnel = (input: {
|
|
|
123
123
|
return { step: last.step, finished, reason: finished ? null : stopReason(last, theirs) };
|
|
124
124
|
});
|
|
125
125
|
|
|
126
|
-
const declared = input.declaration.steps().map((s) => ({ name: s.name, agent: s.
|
|
126
|
+
const declared = input.declaration.steps().map((s) => ({ name: s.name, agent: s.runs === 'agentic' }));
|
|
127
127
|
const undeclared = [...new Set(runs.flatMap(([, rs]) => rs.map((r) => r.step)))].filter((name) => !declared.some((s) => s.name === name))
|
|
128
128
|
.map((name) => ({ name, agent: runs.some(([, rs]) => rs.some((r) => r.step === name && r.agent === 1)) }));
|
|
129
129
|
const counted = [...declared, ...undeclared].map((s) => {
|