@jive-sh/workflow-platform 0.6.3 → 1.0.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 +66 -295
- package/component/_generated/api.ts +72 -0
- package/component/_generated/component.ts +621 -0
- package/component/_generated/dataModel.ts +60 -0
- package/component/_generated/server.ts +169 -0
- package/component/convex.config.ts +3 -0
- package/component/engine.ts +755 -0
- package/component/errors.ts +66 -0
- package/component/events.ts +17 -0
- package/component/notes.ts +13 -0
- package/component/places.ts +136 -0
- package/component/retention.ts +205 -0
- package/component/runEngine.ts +25 -0
- package/component/schema.ts +132 -0
- package/component/steps.ts +188 -0
- package/component/store.ts +512 -0
- package/component/tasks.ts +289 -0
- package/component/worker.ts +109 -0
- package/component/workflows.ts +83 -0
- package/dist/definition/agent-runner.js +9 -0
- package/dist/definition/agent-runner.js.map +1 -0
- package/dist/definition/file-store.js +9 -0
- package/dist/definition/file-store.js.map +1 -0
- package/dist/definition/program-build.js +10 -0
- package/dist/definition/program-build.js.map +1 -0
- package/dist/definition/step.js +1 -0
- package/dist/definition/step.js.map +1 -0
- package/dist/definition/task-schema.js +5 -0
- package/dist/definition/task-schema.js.map +1 -0
- package/dist/definition/tasks.js +9 -0
- package/dist/definition/tasks.js.map +1 -0
- package/dist/definition/workflow.js +111 -0
- package/dist/definition/workflow.js.map +1 -0
- package/dist/graph.js +301 -9
- package/dist/graph.js.map +1 -1
- package/dist/index.js +7 -133
- package/dist/index.js.map +1 -1
- package/package.json +9 -4
- package/src/definition/agent-runner.ts +59 -0
- package/src/definition/file-store.ts +20 -0
- package/src/definition/program-build.ts +30 -0
- package/src/definition/step.ts +106 -0
- package/src/definition/task-schema.ts +15 -0
- package/src/definition/tasks.ts +43 -0
- package/src/definition/workflow.ts +255 -0
- package/src/graph.ts +341 -19
- package/src/index.ts +8 -168
- package/worker/directory-file-store.ts +42 -0
- package/worker/index.ts +12 -0
- package/worker/platform-client.ts +138 -0
- package/worker/step-meter.ts +80 -0
- package/worker/worker-tasks.ts +27 -0
- package/worker/worker.test.ts +200 -0
- package/worker/worker.ts +240 -0
- package/dist/budget-states.js +0 -30
- package/dist/budget-states.js.map +0 -1
- package/dist/cpu-limit/limiter.js +0 -839
- package/dist/cpu-limit/limiter.js.map +0 -1
- package/dist/cpu-limit/use.js +0 -139
- package/dist/cpu-limit/use.js.map +0 -1
- package/dist/dashboard/agent-usage.js +0 -25
- package/dist/dashboard/agent-usage.js.map +0 -1
- package/dist/dashboard/dashboard.css +0 -134
- package/dist/dashboard/drilldown.js +0 -16
- package/dist/dashboard/drilldown.js.map +0 -1
- package/dist/dashboard/queue-lines.js +0 -44
- package/dist/dashboard/queue-lines.js.map +0 -1
- package/dist/dashboard/queue-table.js +0 -16
- package/dist/dashboard/queue-table.js.map +0 -1
- package/dist/dashboard/spending-words.js +0 -32
- package/dist/dashboard/spending-words.js.map +0 -1
- package/dist/failure.js +0 -35
- package/dist/failure.js.map +0 -1
- package/dist/keep-running.js +0 -77
- package/dist/keep-running.js.map +0 -1
- package/dist/outside-failure.js +0 -31
- package/dist/outside-failure.js.map +0 -1
- package/dist/pick-wakes.js +0 -125
- package/dist/pick-wakes.js.map +0 -1
- package/dist/project.js +0 -1
- package/dist/project.js.map +0 -1
- package/dist/queue-counts.js +0 -51
- package/dist/queue-counts.js.map +0 -1
- package/dist/reasons.js +0 -33
- package/dist/reasons.js.map +0 -1
- package/dist/spending-limit.js +0 -88
- package/dist/spending-limit.js.map +0 -1
- package/dist/step-files.js +0 -200
- package/dist/step-files.js.map +0 -1
- package/dist/step-meter.js +0 -97
- package/dist/step-meter.js.map +0 -1
- package/dist/step-usage.js +0 -19
- package/dist/step-usage.js.map +0 -1
- package/dist/steps.js +0 -920
- package/dist/steps.js.map +0 -1
- package/dist/storage/budgets.js +0 -85
- package/dist/storage/budgets.js.map +0 -1
- package/dist/storage/engine-records.js +0 -75
- package/dist/storage/engine-records.js.map +0 -1
- package/dist/storage/engine-storage.js +0 -67
- package/dist/storage/engine-storage.js.map +0 -1
- package/dist/storage/input-records.js +0 -12
- package/dist/storage/input-records.js.map +0 -1
- package/dist/storage/move-store.js +0 -251
- package/dist/storage/move-store.js.map +0 -1
- package/dist/storage/sqlite-store.js +0 -723
- package/dist/storage/sqlite-store.js.map +0 -1
- package/dist/storage/step-records.js +0 -11
- package/dist/storage/step-records.js.map +0 -1
- package/dist/storage/storage-error.js +0 -19
- package/dist/storage/storage-error.js.map +0 -1
- package/dist/storage/task-store.js +0 -24
- package/dist/storage/task-store.js.map +0 -1
- package/dist/tasks.js +0 -475
- package/dist/tasks.js.map +0 -1
- package/dist/views/format.js +0 -37
- package/dist/views/format.js.map +0 -1
- package/dist/views/runs-now.js +0 -75
- package/dist/views/runs-now.js.map +0 -1
- package/dist/views/step-funnel.js +0 -98
- package/dist/views/step-funnel.js.map +0 -1
- package/dist/views/step-graph.js +0 -34
- package/dist/views/step-graph.js.map +0 -1
- package/dist/views/workflow-flows.js +0 -53
- package/dist/views/workflow-flows.js.map +0 -1
- package/dist/views/workflows-view.js +0 -230
- package/dist/views/workflows-view.js.map +0 -1
- package/src/budget-states.ts +0 -55
- package/src/cpu-limit/limiter.ts +0 -935
- package/src/cpu-limit/use.ts +0 -166
- package/src/dashboard/agent-usage-line.tsx +0 -28
- package/src/dashboard/agent-usage.ts +0 -48
- package/src/dashboard/dashboard.css +0 -134
- package/src/dashboard/drilldown.ts +0 -43
- package/src/dashboard/index.tsx +0 -4
- package/src/dashboard/machine-controls.tsx +0 -53
- package/src/dashboard/queue-bar.tsx +0 -43
- package/src/dashboard/queue-chart.tsx +0 -150
- package/src/dashboard/queue-lines.ts +0 -87
- package/src/dashboard/queue-table.ts +0 -37
- package/src/dashboard/spending-limit-control.tsx +0 -50
- package/src/dashboard/spending-words.ts +0 -50
- package/src/dashboard/step-graph.tsx +0 -106
- package/src/dashboard/workflow-dag.tsx +0 -204
- package/src/dashboard/workflow-drilldown.tsx +0 -89
- package/src/dashboard/workflows-dashboard.tsx +0 -414
- package/src/failure.ts +0 -36
- package/src/keep-running.ts +0 -83
- package/src/outside-failure.ts +0 -39
- package/src/pick-wakes.ts +0 -182
- package/src/project.ts +0 -115
- package/src/queue-counts.ts +0 -64
- package/src/reasons.ts +0 -30
- package/src/spending-limit.ts +0 -156
- package/src/step-files.ts +0 -208
- package/src/step-meter.ts +0 -120
- package/src/step-usage.ts +0 -23
- package/src/steps.ts +0 -1239
- package/src/storage/budgets.ts +0 -113
- package/src/storage/engine-records.ts +0 -102
- package/src/storage/engine-storage.ts +0 -82
- package/src/storage/input-records.ts +0 -43
- package/src/storage/move-store.ts +0 -265
- package/src/storage/sqlite-store.ts +0 -829
- package/src/storage/step-records.ts +0 -306
- package/src/storage/storage-error.ts +0 -35
- package/src/storage/task-store.ts +0 -235
- package/src/tasks.ts +0 -561
- package/src/views/format.ts +0 -40
- package/src/views/runs-now.ts +0 -120
- package/src/views/step-funnel.ts +0 -163
- package/src/views/step-graph.ts +0 -68
- package/src/views/workflow-flows.ts +0 -97
- package/src/views/workflows-view.ts +0 -443
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* TASKS OVER TIME, small: one status of one workflow as a thin line, always as a percent of that workflow's tasks
|
|
5
|
-
* (`queue-lines.ts`). Each line carries a number at its end and in the key under the chart, where its label reads its
|
|
6
|
-
* tasks over its workflow's total with the percent, so no line is told apart by colour alone. Which lines show is the
|
|
7
|
-
* reader's choice, made in a table (a row per workflow, a column per status) and kept in this browser for each level of
|
|
8
|
-
* the drill-down.
|
|
9
|
-
*/
|
|
10
|
-
import { useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
11
|
-
import type { WorkflowsView, WorkflowView } from '../views/workflows-view';
|
|
12
|
-
import { localTime } from '../views/format';
|
|
13
|
-
import { lineLabel, percentOf, queueRows } from './queue-lines';
|
|
14
|
-
|
|
15
|
-
const STORED_CHOICE = 'workflow-platform.queue-chart.lines';
|
|
16
|
-
/** Lines shown before the reader chooses: the rows that finished most. */
|
|
17
|
-
const SHOWN_AT_FIRST = 3;
|
|
18
|
-
const DASHES = ['', '5 3', '1.5 2.5', '7 2 1.5 2', '3 3'];
|
|
19
|
-
/** The host page's colours, so a line keeps its contrast in a light theme and a dark one alike. */
|
|
20
|
-
const SHADES = ['var(--wp-fg)', 'var(--wp-ok)', 'var(--accent, #5aa9e6)', 'var(--near, #dfa33c)', 'var(--wp-dim)'];
|
|
21
|
-
/** The status a workflow's finished tasks stand in. */
|
|
22
|
-
const DONE = 'done';
|
|
23
|
-
|
|
24
|
-
const readChoice = (level: string): ReadonlyArray<string> | null => {
|
|
25
|
-
try {
|
|
26
|
-
const stored = window.localStorage.getItem(`${STORED_CHOICE}:${level}`);
|
|
27
|
-
return stored === null ? null : (JSON.parse(stored) as ReadonlyArray<string>);
|
|
28
|
-
} catch {
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export interface QueueChartProps {
|
|
34
|
-
readonly view: Pick<WorkflowsView, 'at' | 'queueHistory'>;
|
|
35
|
-
/** The table's rows: the workflows of the level being looked at, in its order. */
|
|
36
|
-
readonly workflows: ReadonlyArray<WorkflowView>;
|
|
37
|
-
/** The level, for the reader's choice of lines there. */
|
|
38
|
-
readonly level: string;
|
|
39
|
-
/** What the first column holds: a step of the level, or the workflow itself. */
|
|
40
|
-
readonly rowWord: string;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function QueueChart({ view, workflows, level, rowWord }: QueueChartProps) {
|
|
44
|
-
const rows = queueRows({ workflows, history: view.queueHistory, at: view.at });
|
|
45
|
-
const all = rows.flatMap((r) => r.lines);
|
|
46
|
-
const [chosen, setChosen] = useState<ReadonlyArray<string> | null>(null);
|
|
47
|
-
useEffect(() => setChosen(readChoice(level)), [level]);
|
|
48
|
-
const shownAtFirst = all.filter((l) => l.status === DONE && l.now.tasks > 0).sort((a, b) => b.now.tasks - a.now.tasks).slice(0, SHOWN_AT_FIRST).map((l) => l.key);
|
|
49
|
-
const shownKeys = chosen ?? shownAtFirst;
|
|
50
|
-
const shown = all.filter((l) => shownKeys.includes(l.key));
|
|
51
|
-
const choose = (key: string, on: boolean) => {
|
|
52
|
-
const next = on ? [...shownKeys, key] : shownKeys.filter((k) => k !== key);
|
|
53
|
-
setChosen(next);
|
|
54
|
-
try { window.localStorage.setItem(`${STORED_CHOICE}:${level}`, JSON.stringify(next)); } catch { /* A browser that keeps nothing shows the first lines again. */ }
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
// Drawn at the width it is given, so its type stays small and sharp on a phone and a desktop alike.
|
|
58
|
-
const box = useRef<HTMLDivElement>(null);
|
|
59
|
-
const [width, setWidth] = useState(600);
|
|
60
|
-
useLayoutEffect(() => {
|
|
61
|
-
const el = box.current;
|
|
62
|
-
if (el === null) return;
|
|
63
|
-
const measure = () => setWidth(Math.max(280, el.clientWidth));
|
|
64
|
-
measure();
|
|
65
|
-
const watch = new ResizeObserver(measure);
|
|
66
|
-
watch.observe(el);
|
|
67
|
-
return () => watch.disconnect();
|
|
68
|
-
}, []);
|
|
69
|
-
|
|
70
|
-
if (rows.length === 0) return null;
|
|
71
|
-
const statuses = rows[0]!.lines.map((l) => l.status);
|
|
72
|
-
const H = 130;
|
|
73
|
-
const P = { t: 8, r: 18, b: 18, l: 40 };
|
|
74
|
-
const from = Math.min(view.at - 3600, ...shown.flatMap((l) => l.points.map((p) => p.at)));
|
|
75
|
-
const X = (t: number) => P.l + ((t - from) / Math.max(1, view.at - from)) * (width - P.l - P.r);
|
|
76
|
-
const Y = (percent: number) => H - P.b - (percent / 100) * (H - P.t - P.b);
|
|
77
|
-
// Each line's number at its end, moved apart so no two overlap.
|
|
78
|
-
const ends = shown.map((l, i) => ({ l, i, y: Y(percentOf(l.now)) })).sort((a, b) => a.y - b.y);
|
|
79
|
-
for (let k = 1; k < ends.length; k += 1) ends[k]!.y = Math.max(ends[k]!.y, ends[k - 1]!.y + 10);
|
|
80
|
-
const recordedSince = view.queueHistory.length === 0 ? null : view.queueHistory[0]!.at;
|
|
81
|
-
|
|
82
|
-
return (
|
|
83
|
-
<section className="wp-chart" aria-label="Tasks over time, as a percent of each workflow's tasks">
|
|
84
|
-
<div className="wp-chart-head">
|
|
85
|
-
<span>Tasks over time</span>
|
|
86
|
-
<span className="wp-mut">{recordedSince === null ? 'recorded from now on, each time a count moves' : `recorded since ${localTime(recordedSince)}`}</span>
|
|
87
|
-
</div>
|
|
88
|
-
<div ref={box} className="wp-chart-box">
|
|
89
|
-
{shown.length === 0 ? <p className="wp-line wp-mut">No line chosen: tick a count in the table below.</p> : (
|
|
90
|
-
<svg width={width} height={H} role="img" aria-label={`Tasks over time, each line a percent of its workflow's tasks: ${shown.map((l) => lineLabel(l, l.now)).join(', ')}`}>
|
|
91
|
-
{[0, 50, 100].map((percent) => (
|
|
92
|
-
<g key={percent}>
|
|
93
|
-
<line x1={P.l} x2={width - P.r} y1={Y(percent)} y2={Y(percent)} stroke="var(--wp-line)" strokeWidth="1" />
|
|
94
|
-
<text x={P.l - 4} y={Y(percent) + 3} textAnchor="end" fontSize="9" fill="var(--wp-dim)">{percent}%</text>
|
|
95
|
-
</g>
|
|
96
|
-
))}
|
|
97
|
-
<text x={P.l} y={H - 4} fontSize="9" fill="var(--wp-dim)">{localTime(from)}</text>
|
|
98
|
-
<text x={width - P.r} y={H - 4} fontSize="9" fill="var(--wp-dim)" textAnchor="end">now</text>
|
|
99
|
-
{shown.map((l, i) => (
|
|
100
|
-
<path
|
|
101
|
-
key={l.key}
|
|
102
|
-
d={l.points.map((p, k) => (k === 0 ? `M${X(p.at)},${Y(percentOf(p))}` : `H${X(p.at)}V${Y(percentOf(p))}`)).join('')}
|
|
103
|
-
fill="none" stroke={SHADES[i % SHADES.length]} strokeWidth="1.25" strokeDasharray={DASHES[i % DASHES.length]}
|
|
104
|
-
/>
|
|
105
|
-
))}
|
|
106
|
-
{shown.map((l, i) => <circle key={`now:${l.key}`} cx={X(view.at)} cy={Y(percentOf(l.now))} r="2.2" fill={SHADES[i % SHADES.length]} />)}
|
|
107
|
-
{ends.map(({ l, i, y }) => <text key={l.key} x={width - P.r + 5} y={y + 3} fontSize="9.5" fill="var(--wp-fg)">{i + 1}</text>)}
|
|
108
|
-
</svg>
|
|
109
|
-
)}
|
|
110
|
-
</div>
|
|
111
|
-
<p className="wp-chart-axis wp-mut">Each line: one status, as a percent of all the tasks of its workflow.</p>
|
|
112
|
-
{shown.length === 0 ? null : (
|
|
113
|
-
<ol className="wp-chart-key">
|
|
114
|
-
{shown.map((l, i) => (
|
|
115
|
-
<li key={l.key}>
|
|
116
|
-
<svg width="26" height="8" aria-hidden="true"><line x1="0" x2="26" y1="4" y2="4" stroke={SHADES[i % SHADES.length]} strokeWidth="1.5" strokeDasharray={DASHES[i % DASHES.length]} /></svg>
|
|
117
|
-
{lineLabel(l, l.now)}
|
|
118
|
-
</li>
|
|
119
|
-
))}
|
|
120
|
-
</ol>
|
|
121
|
-
)}
|
|
122
|
-
<details className="wp-chart-choose">
|
|
123
|
-
<summary>choose lines ({shown.length} of {all.length})</summary>
|
|
124
|
-
<div className="wp-tablewrap">
|
|
125
|
-
<table className="wp-choose">
|
|
126
|
-
<thead>
|
|
127
|
-
<tr><th scope="col">{rowWord}</th>{statuses.map((s) => <th key={s} scope="col" className="wp-r">{s}</th>)}<th scope="col" className="wp-r">total</th></tr>
|
|
128
|
-
</thead>
|
|
129
|
-
<tbody>
|
|
130
|
-
{rows.map((r) => (
|
|
131
|
-
<tr key={r.workflow}>
|
|
132
|
-
<th scope="row">{r.workflow}</th>
|
|
133
|
-
{r.lines.map((l) => (
|
|
134
|
-
<td key={l.key} className="wp-r">
|
|
135
|
-
<label>
|
|
136
|
-
<input type="checkbox" aria-label={`Show ${l.workflow} ${l.status}`} checked={shownKeys.includes(l.key)} onChange={(e) => choose(l.key, e.target.checked)} />
|
|
137
|
-
{l.now.tasks.toLocaleString('en-US')}
|
|
138
|
-
</label>
|
|
139
|
-
</td>
|
|
140
|
-
))}
|
|
141
|
-
<td className="wp-r">{r.total.toLocaleString('en-US')}</td>
|
|
142
|
-
</tr>
|
|
143
|
-
))}
|
|
144
|
-
</tbody>
|
|
145
|
-
</table>
|
|
146
|
-
</div>
|
|
147
|
-
</details>
|
|
148
|
-
</section>
|
|
149
|
-
);
|
|
150
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A WORKFLOW'S TASKS OVER TIME, AS SHARES OF ITS TOTAL: one row per workflow, one line per status, each point that status's
|
|
3
|
-
* tasks over every task the workflow had at that moment. Alex, 2026-11-19: "this should really be a table where row is
|
|
4
|
-
* workflow step and column is status. the y axis should always be a percent of the total tasks assigned to the workflow",
|
|
5
|
-
* and of a line's label: "the line label gets the numerator and denominator with percent in parens".
|
|
6
|
-
*
|
|
7
|
-
* Read from the view's history of counts (a row where a count moved, `queue-counts.ts`) and each queue's count now. Pure,
|
|
8
|
-
* with no React and no JSX, so a test reads it without a page.
|
|
9
|
-
*/
|
|
10
|
-
import type { QueueCount } from '../storage/task-store';
|
|
11
|
-
|
|
12
|
-
/** One status of one workflow at one moment: its tasks, and every task the workflow had then. */
|
|
13
|
-
export interface QueuePoint {
|
|
14
|
-
/** Unix seconds. */
|
|
15
|
-
readonly at: number;
|
|
16
|
-
readonly tasks: number;
|
|
17
|
-
readonly total: number;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** A line: one status of one workflow over time, its last point the count now. */
|
|
21
|
-
export interface QueueLine {
|
|
22
|
-
readonly key: string;
|
|
23
|
-
readonly workflow: string;
|
|
24
|
-
readonly status: string;
|
|
25
|
-
readonly points: ReadonlyArray<QueuePoint>;
|
|
26
|
-
readonly now: QueuePoint;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/** A row of the table: a workflow, its total now, and its line for each status, in the platform's order of statuses. */
|
|
30
|
-
export interface QueueRow {
|
|
31
|
-
readonly workflow: string;
|
|
32
|
-
readonly total: number;
|
|
33
|
-
readonly lines: ReadonlyArray<QueueLine>;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** A point's share of its workflow's tasks, 0 to 100; 0 for a workflow with no task. */
|
|
37
|
-
export const percentOf = (p: Pick<QueuePoint, 'tasks' | 'total'>): number => (p.total === 0 ? 0 : (100 * p.tasks) / p.total);
|
|
38
|
-
|
|
39
|
-
/** A share as a label writes it: a whole percent, and "under 1%" for a share that is not zero and rounds to it. */
|
|
40
|
-
export const percentText = (p: Pick<QueuePoint, 'tasks' | 'total'>): string => {
|
|
41
|
-
const percent = percentOf(p);
|
|
42
|
-
return percent > 0 && percent < 0.5 ? 'under 1%' : `${Math.round(percent)}%`;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const written = (n: number): string => n.toLocaleString('en-US');
|
|
46
|
-
|
|
47
|
-
/** A line's label: its status's tasks over its workflow's total, then the percent: `Decompile done 2,510 / 7,273 (35%)`. */
|
|
48
|
-
export const lineLabel = (line: Pick<QueueLine, 'workflow' | 'status'>, at: Pick<QueuePoint, 'tasks' | 'total'>): string =>
|
|
49
|
-
`${line.workflow} ${line.status} ${written(at.tasks)} / ${written(at.total)} (${percentText(at)})`;
|
|
50
|
-
|
|
51
|
-
const keyOf = (workflow: string, status: string) => `${workflow} · ${status}`;
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Each workflow's row. A point is made at each moment a count of the workflow was recorded, from the first at which every
|
|
55
|
-
* status the history holds has a count: before it the total would leave tasks out.
|
|
56
|
-
*/
|
|
57
|
-
export const queueRows = (input: {
|
|
58
|
-
/** Each with its tasks by status now, in the platform's order of statuses; none for a workflow with no tasks. */
|
|
59
|
-
readonly workflows: ReadonlyArray<{ readonly name: string; readonly queue: Readonly<Record<string, number>> | null }>;
|
|
60
|
-
/** Oldest first. */
|
|
61
|
-
readonly history: ReadonlyArray<QueueCount>;
|
|
62
|
-
/** When the counts now were read, unix seconds. */
|
|
63
|
-
readonly at: number;
|
|
64
|
-
}): ReadonlyArray<QueueRow> => input.workflows.flatMap((w) => {
|
|
65
|
-
if (w.queue === null) return [];
|
|
66
|
-
const queue = w.queue;
|
|
67
|
-
const statuses = Object.keys(queue);
|
|
68
|
-
const recorded = input.history.filter((r) => r.workflow === w.name && statuses.includes(r.bucket));
|
|
69
|
-
const firstSeen = new Map<string, number>();
|
|
70
|
-
for (const r of recorded) if (!firstSeen.has(r.bucket)) firstSeen.set(r.bucket, r.at);
|
|
71
|
-
const complete = Math.max(-Infinity, ...firstSeen.values());
|
|
72
|
-
const counts = new Map<string, number>(statuses.map((s) => [s, 0]));
|
|
73
|
-
const moments: Array<{ readonly at: number; readonly counts: ReadonlyMap<string, number>; readonly total: number }> = [];
|
|
74
|
-
recorded.forEach((r, i) => {
|
|
75
|
-
counts.set(r.bucket, r.tasks);
|
|
76
|
-
const last = i === recorded.length - 1 || recorded[i + 1]!.at !== r.at;
|
|
77
|
-
if (last && r.at >= complete) moments.push({ at: r.at, counts: new Map(counts), total: [...counts.values()].reduce((a, b) => a + b, 0) });
|
|
78
|
-
});
|
|
79
|
-
const total = statuses.reduce((sum, s) => sum + queue[s]!, 0);
|
|
80
|
-
return [{
|
|
81
|
-
workflow: w.name, total,
|
|
82
|
-
lines: statuses.map((status) => {
|
|
83
|
-
const now = { at: input.at, tasks: queue[status]!, total };
|
|
84
|
-
return { key: keyOf(w.name, status), workflow: w.name, status, now, points: [...moments.map((m) => ({ at: m.at, tasks: m.counts.get(status)!, total: m.total })), now] };
|
|
85
|
-
}),
|
|
86
|
-
}];
|
|
87
|
-
});
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A QUEUE'S TASKS AS A COLUMN ADDITION: one addend per task category, in the order the platform defines them, a zero as
|
|
3
|
-
* much as any other count, and their total. Alex, 2026-11-18: "the different task categories shown as a math equation so
|
|
4
|
-
* it's easier to read like a stacked addition table with the total at the bottom".
|
|
5
|
-
*
|
|
6
|
-
* The total is the addends added up here, never a count read apart from them, so the two cannot disagree. The categories
|
|
7
|
-
* and their order are the queue's own keys: the view gives every queue all of the platform's categories, in its order
|
|
8
|
-
* (`views/workflows-view.ts` `queuesNow`). Pure, with no React and no JSX, so a test reads it without a page.
|
|
9
|
-
*
|
|
10
|
-
* THE QUEUED ROW SAYS HOW MANY OF ITS TASKS NEED AN AGENT, in parentheses: "804 queued (12 need agent)". Alex,
|
|
11
|
-
* 2026-11-20: "there can be in parens the number in the queue marked for needing an agent". Like every figure of the
|
|
12
|
-
* table it is shown at 0 too, for a workflow with an agent step; one with none can mark no task, and shows none.
|
|
13
|
-
*/
|
|
14
|
-
export interface QueueSum {
|
|
15
|
-
readonly addends: ReadonlyArray<{ readonly category: string; readonly tasks: number; readonly text: string; readonly note: string | null }>;
|
|
16
|
-
readonly total: number;
|
|
17
|
-
readonly totalText: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** A count as the table writes it: thousands separated, as every figure on the page is. */
|
|
21
|
-
const written = (tasks: number): string => tasks.toLocaleString('en-US');
|
|
22
|
-
|
|
23
|
-
/** "12 need agent", "1 needs agent": Alex, 2026-11-20: "(12 need agent) is fine. no 'an'". */
|
|
24
|
-
const needWords = (tasks: number): string => `${written(tasks)} ${tasks === 1 ? 'needs' : 'need'} agent`;
|
|
25
|
-
|
|
26
|
-
/** `queuedNeedingAnAgent`: how many queued tasks are marked as needing an agent; none where none can be (`WorkflowView`). */
|
|
27
|
-
export const queueSum = (queue: Readonly<Record<string, number>>, queuedNeedingAnAgent: number | null = null): QueueSum => {
|
|
28
|
-
const addends = Object.entries(queue).map(([category, tasks]) => ({
|
|
29
|
-
category, tasks, text: written(tasks),
|
|
30
|
-
note: category === 'queued' && queuedNeedingAnAgent !== null ? needWords(queuedNeedingAnAgent) : null,
|
|
31
|
-
}));
|
|
32
|
-
const total = addends.reduce((sum, a) => sum + a.tasks, 0);
|
|
33
|
-
return { addends, total, totalText: written(total) };
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
/** An addend's label as the table and its one-line form write it: "queued (12 need agent)". */
|
|
37
|
-
export const addendLabel = (a: QueueSum['addends'][number]): string => (a.note === null ? a.category : `${a.category} (${a.note})`);
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* THE SPENDING LIMIT ON THE PAGE (`spending-limit.ts`): what it is set to with − and +, the week's reading against it, whether
|
|
5
|
-
* it holds every agent step, whether the reading is stale, and which agent steps wait on it, each in words
|
|
6
|
-
* (`spending-words.ts`). A click shows at once, as asked, until the page's next reading says the same; a failed one says why.
|
|
7
|
-
*/
|
|
8
|
-
import { useEffect, useState } from 'react';
|
|
9
|
-
import type { SpendingLimitState } from '../spending-limit';
|
|
10
|
-
import { heldStepsWords, spendingSettingWords, spendingStaleWords, spendingVerdictWords, type HeldStep } from './spending-words';
|
|
11
|
-
|
|
12
|
-
export interface SpendingLimitControlProps {
|
|
13
|
-
readonly spending: SpendingLimitState;
|
|
14
|
-
readonly held: ReadonlyArray<HeldStep>;
|
|
15
|
-
readonly now: number;
|
|
16
|
-
/** Stores a new limit, a whole percent from 0 to 100; with none the limit shows without buttons. */
|
|
17
|
-
readonly setSpendingLimit?: (weekPercent: number) => Promise<void>;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const WHY = 'While the newest good reading of the week is at or past this percent, every agent step of every workflow waits before its agent call. A failed or late reading never lifts it.';
|
|
21
|
-
|
|
22
|
-
export function SpendingLimitControl({ spending, held, now, setSpendingLimit }: SpendingLimitControlProps) {
|
|
23
|
-
const [asked, setAsked] = useState<number | null>(null);
|
|
24
|
-
const [failed, setFailed] = useState<string | null>(null);
|
|
25
|
-
useEffect(() => {
|
|
26
|
-
if (asked !== null && asked === spending.limitPercent && spending.setAt !== null) setAsked(null);
|
|
27
|
-
}, [asked, spending.limitPercent, spending.setAt]);
|
|
28
|
-
const shown = asked === null ? spending.limitPercent : asked;
|
|
29
|
-
const set = (to: number) => {
|
|
30
|
-
if (setSpendingLimit === undefined) return;
|
|
31
|
-
setAsked(to);
|
|
32
|
-
setFailed(null);
|
|
33
|
-
setSpendingLimit(to).catch((e: unknown) => { setAsked(null); setFailed(e instanceof Error ? e.message : String(e)); });
|
|
34
|
-
};
|
|
35
|
-
const stale = spendingStaleWords(spending, now);
|
|
36
|
-
const waiting = heldStepsWords(spending, held);
|
|
37
|
-
return (
|
|
38
|
-
<div className="wp-spending">
|
|
39
|
-
<span className="wp-limit" title={WHY}>
|
|
40
|
-
{setSpendingLimit === undefined ? null : <button type="button" aria-label="Lower the spending limit" disabled={shown <= 0} onClick={() => set(shown - 1)}>−</button>}
|
|
41
|
-
<span>{spendingSettingWords({ limitPercent: shown, setAt: asked === null ? spending.setAt : now })}</span>
|
|
42
|
-
{setSpendingLimit === undefined ? null : <button type="button" aria-label="Raise the spending limit" disabled={shown >= 100} onClick={() => set(shown + 1)}>+</button>}
|
|
43
|
-
{failed === null ? null : <span className="wp-bad">not saved: {failed}</span>}
|
|
44
|
-
</span>
|
|
45
|
-
<p className={spending.holds ? 'wp-line wp-bad' : 'wp-line'}>{spendingVerdictWords(spending, now)}</p>
|
|
46
|
-
{stale === null ? null : <p className="wp-line wp-bad">{stale}</p>}
|
|
47
|
-
{waiting === null ? null : <p className={held.length > 0 ? 'wp-line wp-bad' : 'wp-line wp-mut'}>{waiting}</p>}
|
|
48
|
-
</div>
|
|
49
|
-
);
|
|
50
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* THE SPENDING LIMIT IN WORDS (`spending-limit.ts`): what it is set to, the week's reading against it, whether it holds, and
|
|
3
|
-
* which agent steps wait on it. Each state is said in words, first in its line; a colour on the page only repeats it. Pure,
|
|
4
|
-
* with no React and no JSX, so a test reads it without a page.
|
|
5
|
-
*/
|
|
6
|
-
import type { SpendingLimitState } from '../spending-limit';
|
|
7
|
-
import type { PhaseRunsNow } from '../views/runs-now';
|
|
8
|
-
import { percentCut, whenAgo } from '../views/format';
|
|
9
|
-
|
|
10
|
-
/** One agent step the limit holds runs at, and how many. */
|
|
11
|
-
export interface HeldStep {
|
|
12
|
-
readonly workflow: string;
|
|
13
|
-
readonly step: string;
|
|
14
|
-
readonly runs: number;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** Every agent step the limit holds a run at now, from where runs are now. */
|
|
18
|
-
export const heldSteps = (runsNow: ReadonlyArray<PhaseRunsNow>): ReadonlyArray<HeldStep> =>
|
|
19
|
-
runsNow.flatMap((p) => p.workflows.flatMap((w) => w.steps.filter((s) => s.heldBySpendingLimit > 0).map((s) => ({ workflow: w.workflow, step: s.step, runs: s.heldBySpendingLimit }))));
|
|
20
|
-
|
|
21
|
-
/** What the limit is set to: "agents stop at 95% of the week (the default)". */
|
|
22
|
-
export const spendingSettingWords = (s: Pick<SpendingLimitState, 'limitPercent' | 'setAt'>): string =>
|
|
23
|
-
`Spending limit: agents stop at ${s.limitPercent}% of the week${s.setAt === null ? ' (the default)' : ''}`;
|
|
24
|
-
|
|
25
|
-
/** The week's reading against the limit, and whether it holds every agent step. */
|
|
26
|
-
export const spendingVerdictWords = (s: SpendingLimitState, now: number): string => {
|
|
27
|
-
if (s.reading === null) {
|
|
28
|
-
return s.failedSince === null
|
|
29
|
-
? "Holds nothing: there is no reading of the week's use yet."
|
|
30
|
-
: `Holds nothing: there is no good reading of the week's use yet; the newest read failed at ${whenAgo(s.failedSince.at, now)}: ${s.failedSince.error}`;
|
|
31
|
-
}
|
|
32
|
-
const reading = `the week's use is ${percentCut(s.reading.usedPercent)}, read ${whenAgo(s.reading.readAt, now)}`;
|
|
33
|
-
return s.holds
|
|
34
|
-
? `Holding every agent step: ${reading}, at or past the limit. Each waits before its agent call until a reading is below ${s.limitPercent}%.`
|
|
35
|
-
: `Holds nothing: ${reading}, below the limit.`;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
/** Why the reading is stale and what the limit does meanwhile; none while it is current. */
|
|
39
|
-
export const spendingStaleWords = (s: SpendingLimitState, now: number): string | null => {
|
|
40
|
-
if (!s.stale) return null;
|
|
41
|
-
return s.failedSince === null
|
|
42
|
-
? "The reading is stale: none came since. The limit keeps that reading's verdict until a new one."
|
|
43
|
-
: `The reading is stale: the newest read failed at ${whenAgo(s.failedSince.at, now)} (${s.failedSince.error}). The limit keeps the last good reading's verdict until a read succeeds.`;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
/** Which agent steps wait on it; none to say while it holds nothing and nothing waits. */
|
|
47
|
-
export const heldStepsWords = (s: Pick<SpendingLimitState, 'holds'>, held: ReadonlyArray<HeldStep>): string | null => {
|
|
48
|
-
if (held.length === 0) return s.holds ? 'No agent step has reached it yet.' : null;
|
|
49
|
-
return `Waiting on it: ${held.map((h) => `${h.workflow}, step ${h.step} (${h.runs} run${h.runs === 1 ? '' : 's'})`).join('; ')}.`;
|
|
50
|
-
};
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* ONE WORKFLOW'S DECLARED STEP GRAPH, DRAWN SMALL: its steps one under another in the order a run takes them, a step that
|
|
5
|
-
* does not run deterministically marked with how it runs, in words, a sub-workflow step a link to its workflow's own level, and every edge an arrow with a number. The numbers' list below says each edge's condition and
|
|
6
|
-
* how many runs took it in the window. An edge to the next row goes straight down; any other runs in a lane of its own on
|
|
7
|
-
* the right, so it crosses no step.
|
|
8
|
-
*/
|
|
9
|
-
import { useLayoutEffect, useRef, useState } from 'react';
|
|
10
|
-
import { A_STEP_FAILS, RUN_ENDS, RUN_STARTS } from '../graph';
|
|
11
|
-
import type { WorkflowGraph } from '../views/step-graph';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Each step's row, in the order the workflow declares its steps, which is the order a run takes them: the run's start (and
|
|
15
|
-
* "a step fails", where an edge leaves it) first, then each step on a row of its own, then the run's end. Pure.
|
|
16
|
-
*/
|
|
17
|
-
export const stepRows = (graph: WorkflowGraph): ReadonlyArray<ReadonlyArray<string>> => [
|
|
18
|
-
[RUN_STARTS, ...(graph.edges.some((e) => e.from === A_STEP_FAILS) ? [A_STEP_FAILS] : [])],
|
|
19
|
-
...graph.steps.map((s) => [s.name]),
|
|
20
|
-
[RUN_ENDS],
|
|
21
|
-
];
|
|
22
|
-
|
|
23
|
-
export function StepGraph({ graph, hrefOfWorkflow }: { readonly graph: WorkflowGraph; readonly hrefOfWorkflow?: (workflow: string) => string }) {
|
|
24
|
-
const box = useRef<HTMLDivElement>(null);
|
|
25
|
-
const [paths, setPaths] = useState<ReadonlyArray<{ readonly key: string; readonly n: number; readonly d: string; readonly at: { readonly x: number; readonly y: number } }>>([]);
|
|
26
|
-
const [size, setSize] = useState({ w: 0, h: 0 });
|
|
27
|
-
const rows = stepRows(graph);
|
|
28
|
-
const declared = new Map(graph.steps.map((s) => [s.name, s]));
|
|
29
|
-
useLayoutEffect(() => {
|
|
30
|
-
const el = box.current;
|
|
31
|
-
if (el === null) return;
|
|
32
|
-
const draw = () => {
|
|
33
|
-
const at = el.getBoundingClientRect();
|
|
34
|
-
const rect = (name: string) => el.querySelector(`[data-step="${CSS.escape(name)}"]`)?.getBoundingClientRect() ?? null;
|
|
35
|
-
const right = Math.max(0, ...[...el.querySelectorAll('[data-step]')].map((s) => s.getBoundingClientRect().right - at.left));
|
|
36
|
-
let lanes = 0;
|
|
37
|
-
setSize({ w: el.scrollWidth, h: el.scrollHeight });
|
|
38
|
-
setPaths(graph.edges.flatMap((e, i) => {
|
|
39
|
-
const a = rect(e.from), b = rect(e.to);
|
|
40
|
-
if (a === null || b === null) return [];
|
|
41
|
-
const ax = a.left + a.width / 2 - at.left, bx = b.left + b.width / 2 - at.left;
|
|
42
|
-
const nextRow = b.top >= a.bottom - 1 && b.top - a.bottom < 40;
|
|
43
|
-
if (nextRow) {
|
|
44
|
-
const y1 = a.bottom - at.top, y2 = b.top - at.top;
|
|
45
|
-
return [{ key: `${e.from}>${e.to}`, n: i + 1, d: `M${ax},${y1} C${ax},${(y1 + y2) / 2} ${bx},${(y1 + y2) / 2} ${bx},${y2 - 5}`, at: { x: (ax + bx) / 2, y: (y1 + y2) / 2 } }];
|
|
46
|
-
}
|
|
47
|
-
// Back up, along its own row, or past a row: in a lane on the right.
|
|
48
|
-
const lane = right + 12 + 10 * lanes++;
|
|
49
|
-
const ay = a.top + a.height / 2 - at.top, by = b.top + b.height / 2 - at.top;
|
|
50
|
-
return [{ key: `${e.from}>${e.to}`, n: i + 1, d: `M${a.right - at.left},${ay} H${lane} V${by} H${b.right - at.left + 5}`, at: { x: lane, y: (ay + by) / 2 } }];
|
|
51
|
-
}));
|
|
52
|
-
};
|
|
53
|
-
draw();
|
|
54
|
-
const watch = new ResizeObserver(draw);
|
|
55
|
-
watch.observe(el);
|
|
56
|
-
return () => watch.disconnect();
|
|
57
|
-
}, [graph]);
|
|
58
|
-
|
|
59
|
-
if (!graph.declared) return <p className="wp-line wp-bad">No step graph declared yet.</p>;
|
|
60
|
-
return (
|
|
61
|
-
<div className="wp-steps">
|
|
62
|
-
<div ref={box} className="wp-steps-box">
|
|
63
|
-
<svg className="wp-steps-edges" width={size.w} height={size.h} aria-hidden="true">
|
|
64
|
-
<defs>
|
|
65
|
-
<marker id="wp-step-arrow" viewBox="0 0 8 8" refX="7" refY="4" markerWidth="6" markerHeight="6" orient="auto-start-reverse">
|
|
66
|
-
<path d="M0,0 L8,4 L0,8 z" fill="var(--wp-edge)" />
|
|
67
|
-
</marker>
|
|
68
|
-
</defs>
|
|
69
|
-
{paths.map((p) => <path key={p.key} d={p.d} fill="none" stroke="var(--wp-edge)" strokeWidth="1.1" markerEnd="url(#wp-step-arrow)" />)}
|
|
70
|
-
{paths.map((p) => (
|
|
71
|
-
<g key={`n:${p.key}`}>
|
|
72
|
-
<circle cx={p.at.x} cy={p.at.y} r="7" fill="var(--wp-bg)" stroke="var(--wp-edge)" strokeWidth="0.8" />
|
|
73
|
-
<text x={p.at.x} y={p.at.y + 3} fontSize="8.5" textAnchor="middle" fill="var(--wp-fg)">{p.n}</text>
|
|
74
|
-
</g>
|
|
75
|
-
))}
|
|
76
|
-
</svg>
|
|
77
|
-
{rows.map((row) => (
|
|
78
|
-
<div key={row.join('|')} className="wp-steps-row">
|
|
79
|
-
{row.map((name) => {
|
|
80
|
-
const step = declared.get(name);
|
|
81
|
-
const className = name === RUN_STARTS || name === RUN_ENDS || name === A_STEP_FAILS ? 'wp-step wp-step-end' : 'wp-step';
|
|
82
|
-
const title = step?.description ?? name;
|
|
83
|
-
// A sub-workflow step opens its workflow's own level, as its row in the list of steps does.
|
|
84
|
-
if (step !== undefined && step.workflow !== null && hrefOfWorkflow !== undefined) {
|
|
85
|
-
return <a key={name} data-step={name} className={`${className} wp-step-link`} href={hrefOfWorkflow(step.workflow)} title={title}>{name}<em> · sub-workflow, open ›</em></a>;
|
|
86
|
-
}
|
|
87
|
-
return (
|
|
88
|
-
<span key={name} data-step={name} className={className} title={title}>
|
|
89
|
-
{name}{step === undefined || step.runs === null || step.runs === 'deterministic' ? null : <em> · {step.runs}</em>}
|
|
90
|
-
</span>
|
|
91
|
-
);
|
|
92
|
-
})}
|
|
93
|
-
</div>
|
|
94
|
-
))}
|
|
95
|
-
</div>
|
|
96
|
-
<ol className="wp-steps-when">
|
|
97
|
-
{graph.edges.map((e) => (
|
|
98
|
-
<li key={`${e.from}>${e.to}`}>{e.from} → {e.to}: {e.when}{e.runs === 0 ? '' : ` (${e.runs.toLocaleString('en-US')} run${e.runs === 1 ? '' : 's'})`}</li>
|
|
99
|
-
))}
|
|
100
|
-
</ol>
|
|
101
|
-
{graph.undeclared.length === 0 ? null : (
|
|
102
|
-
<p className="wp-line wp-bad">Taken but not declared: {graph.undeclared.map((e) => `${e.from} → ${e.to} (${e.runs})`).join('; ')}</p>
|
|
103
|
-
)}
|
|
104
|
-
</div>
|
|
105
|
-
);
|
|
106
|
-
}
|