@jive-sh/workflow-platform 0.7.0 → 1.1.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 +70 -435
- package/component/_generated/api.ts +72 -0
- package/component/_generated/component.ts +629 -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 +756 -0
- package/component/errors.ts +66 -0
- package/component/events.ts +17 -0
- package/component/notes.ts +19 -0
- package/component/places.ts +136 -0
- package/component/retention.ts +205 -0
- package/component/runEngine.ts +25 -0
- package/component/schema.ts +135 -0
- package/component/steps.ts +188 -0
- package/component/store.ts +513 -0
- package/component/tasks.ts +290 -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 +117 -0
- package/dist/definition/workflow.js.map +1 -0
- package/dist/graph.js +310 -9
- package/dist/graph.js.map +1 -1
- package/dist/index.js +7 -196
- 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 +262 -0
- package/src/graph.ts +352 -19
- package/src/index.ts +8 -238
- package/worker/directory-file-store.ts +42 -0
- package/worker/index.ts +12 -0
- package/worker/platform-client.ts +144 -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 -148
- package/dist/dashboard/drilldown.js +0 -47
- 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/run-doing-words.js +0 -29
- package/dist/dashboard/run-doing-words.js.map +0 -1
- package/dist/dashboard/setting-words.js +0 -18
- package/dist/dashboard/setting-words.js.map +0 -1
- package/dist/dashboard/spending-words.js +0 -24
- 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 -79
- 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/retention.js +0 -59
- package/dist/retention.js.map +0 -1
- package/dist/settings.js +0 -88
- package/dist/settings.js.map +0 -1
- package/dist/spending-limit.js +0 -82
- 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-times.js +0 -114
- package/dist/step-times.js.map +0 -1
- package/dist/step-usage.js +0 -19
- package/dist/step-usage.js.map +0 -1
- package/dist/steps.js +0 -1205
- package/dist/steps.js.map +0 -1
- package/dist/storage/agent-claims.js +0 -3
- package/dist/storage/agent-claims.js.map +0 -1
- package/dist/storage/budgets.js +0 -121
- package/dist/storage/budgets.js.map +0 -1
- package/dist/storage/engine-records.js +0 -91
- 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 -901
- 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 -30
- package/dist/storage/task-store.js.map +0 -1
- package/dist/system-workflows.js +0 -54
- package/dist/system-workflows.js.map +0 -1
- package/dist/tasks.js +0 -500
- 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 -117
- 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 -39
- package/dist/views/step-graph.js.map +0 -1
- package/dist/views/workflows-view.js +0 -236
- package/dist/views/workflows-view.js.map +0 -1
- package/src/budget-states.ts +0 -54
- 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 -148
- package/src/dashboard/drilldown.ts +0 -70
- package/src/dashboard/index.tsx +0 -4
- package/src/dashboard/limits-and-runs.tsx +0 -191
- package/src/dashboard/machine-controls.tsx +0 -53
- package/src/dashboard/queue-bar.tsx +0 -62
- package/src/dashboard/queue-chart.tsx +0 -149
- package/src/dashboard/queue-lines.ts +0 -87
- package/src/dashboard/queue-table.ts +0 -37
- package/src/dashboard/run-doing-words.ts +0 -41
- package/src/dashboard/setting-words.ts +0 -30
- package/src/dashboard/spending-limit-control.tsx +0 -47
- package/src/dashboard/spending-words.ts +0 -32
- package/src/dashboard/time-distribution.tsx +0 -61
- package/src/dashboard/workflow-dag.tsx +0 -322
- package/src/dashboard/workflow-drilldown.tsx +0 -31
- package/src/dashboard/workflows-dashboard.tsx +0 -532
- package/src/failure.ts +0 -36
- package/src/keep-running.ts +0 -85
- package/src/outside-failure.ts +0 -39
- package/src/pick-wakes.ts +0 -182
- package/src/project.ts +0 -127
- package/src/queue-counts.ts +0 -64
- package/src/reasons.ts +0 -30
- package/src/retention.ts +0 -90
- package/src/settings.ts +0 -171
- package/src/spending-limit.ts +0 -139
- package/src/step-files.ts +0 -208
- package/src/step-meter.ts +0 -120
- package/src/step-times.ts +0 -151
- package/src/step-usage.ts +0 -23
- package/src/steps.ts +0 -1616
- package/src/storage/agent-claims.ts +0 -63
- package/src/storage/budgets.ts +0 -152
- package/src/storage/engine-records.ts +0 -119
- 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 -1022
- package/src/storage/step-records.ts +0 -358
- package/src/storage/storage-error.ts +0 -35
- package/src/storage/task-store.ts +0 -235
- package/src/system-workflows.ts +0 -70
- package/src/tasks.ts +0 -586
- package/src/views/format.ts +0 -40
- package/src/views/runs-now.ts +0 -188
- package/src/views/step-funnel.ts +0 -163
- package/src/views/step-graph.ts +0 -77
- package/src/views/workflows-view.ts +0 -484
- package/src/workflow-dag.test.tsx +0 -89
- package/src/workflow-page.test.tsx +0 -170
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* A WORKFLOW'S RUNS AND ITS LIMITS, each on lines of its own. Alex, 2026-11-22: "i really want to see all this on separate
|
|
5
|
-
* lines. the set limits controls and the current runs status".
|
|
6
|
-
*
|
|
7
|
-
* Runs each state its runs are in, a count and its words, added up to the runs going, laid out as a workflow's tasks are.
|
|
8
|
-
* Limits each limit on a line with its control and where its value is set: its run limit, its agents' limit, how long its
|
|
9
|
-
* records are kept and the fewest of its runs kept however old (`settings.ts`), the last two set while the app runs.
|
|
10
|
-
*
|
|
11
|
-
* The same control sets every number (`NumberControl`): a click shows at once, as asked, until the page's next reading says
|
|
12
|
-
* the same; a failed one says why; a value set can go back to its default.
|
|
13
|
-
*/
|
|
14
|
-
import { useEffect, useState, type ReactNode } from 'react';
|
|
15
|
-
import type { RuntimeSettingName, SettingLevel } from '../settings';
|
|
16
|
-
import type { WorkflowRunsNow } from '../views/runs-now';
|
|
17
|
-
import type { RetentionSettings, WorkflowView } from '../views/workflows-view';
|
|
18
|
-
import { runsDoingLines } from './run-doing-words';
|
|
19
|
-
import { setOnWords } from './setting-words';
|
|
20
|
-
|
|
21
|
-
/** Which of a workflow's two limits a control sets. */
|
|
22
|
-
export type LimitName = 'runs' | 'agents';
|
|
23
|
-
|
|
24
|
-
/** Stores one of a workflow's limits: a whole number, or none for the run limit's default (its agents' limit). The project's own route. */
|
|
25
|
-
export type SetLimit = (r: { readonly workflow: string; readonly limit: LimitName; readonly value: number | null }) => Promise<void>;
|
|
26
|
-
|
|
27
|
-
/** Stores a retention setting at one level: a value, or none to put that level back to its code's value. The project's own route. */
|
|
28
|
-
export type SetSetting = (r: { readonly level: SettingLevel; readonly name: RuntimeSettingName; readonly value: number | null }) => Promise<void>;
|
|
29
|
-
|
|
30
|
-
const plural = (n: number, one: string, many: string) => `${n.toLocaleString('en-US')} ${n === 1 ? one : many}`;
|
|
31
|
-
|
|
32
|
-
/** ONE NUMBER AND ITS BUTTONS: − and + by `step`, never below `min`, and back to its default where it is set. */
|
|
33
|
-
export function NumberControl({ name, value, words, step, min, isSet, resettable, says, set }: {
|
|
34
|
-
/** What it sets, for its buttons' labels: "the run limit of Decompile". */
|
|
35
|
-
readonly name: string;
|
|
36
|
-
/** Its value now; none for no limit. */
|
|
37
|
-
readonly value: number | null;
|
|
38
|
-
readonly words: (value: number | null) => string;
|
|
39
|
-
readonly step: number;
|
|
40
|
-
readonly min: number;
|
|
41
|
-
/** Whether a value is set at its level, not its default. */
|
|
42
|
-
readonly isSet: boolean;
|
|
43
|
-
/** Whether it has a default a set value can go back to. */
|
|
44
|
-
readonly resettable: boolean;
|
|
45
|
-
readonly says: string;
|
|
46
|
-
/** Stores a value, or none for the default; with none, the number shows without buttons. */
|
|
47
|
-
readonly set: ((value: number | null) => Promise<void>) | undefined;
|
|
48
|
-
}) {
|
|
49
|
-
const [asked, setAsked] = useState<{ readonly value: number | null } | null>(null);
|
|
50
|
-
const [failed, setFailed] = useState<string | null>(null);
|
|
51
|
-
useEffect(() => {
|
|
52
|
-
if (asked !== null && (asked.value === null ? !isSet : asked.value === value && isSet)) setAsked(null);
|
|
53
|
-
}, [asked, value, isSet]);
|
|
54
|
-
const shown = asked === null || asked.value === null ? value : asked.value;
|
|
55
|
-
const ask = (next: number | null) => {
|
|
56
|
-
if (set === undefined) return;
|
|
57
|
-
setAsked({ value: next });
|
|
58
|
-
setFailed(null);
|
|
59
|
-
set(next).catch((e: unknown) => { setAsked(null); setFailed(e instanceof Error ? e.message : String(e)); });
|
|
60
|
-
};
|
|
61
|
-
return (
|
|
62
|
-
<span className="wp-limit" title={says} onClick={(e) => e.preventDefault()}>
|
|
63
|
-
{set === undefined ? null : <button type="button" aria-label={`Lower ${name}`} disabled={shown !== null && shown - step < min} onClick={() => ask(shown === null ? min : shown - step)}>−</button>}
|
|
64
|
-
<span className={shown === 0 ? 'wp-bad' : undefined}>{words(shown)}</span>
|
|
65
|
-
{set === undefined ? null : <button type="button" aria-label={`Raise ${name}`} onClick={() => ask(shown === null ? Math.max(min, step) : shown + step)}>+</button>}
|
|
66
|
-
{set === undefined || !resettable || !isSet ? null : <button type="button" aria-label={`Put ${name} back to its default`} onClick={() => ask(null)}>default</button>}
|
|
67
|
-
{failed === null ? null : <span className="wp-bad">not saved: {failed}</span>}
|
|
68
|
-
</span>
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/** What each limit sets, said on its control. */
|
|
73
|
-
const LIMIT_WORDS: Readonly<Record<LimitName, { readonly unit: (n: number) => string; readonly says: string }>> = {
|
|
74
|
-
runs: { unit: (n) => plural(n, 'run', 'runs'), says: 'Run limit: how many runs of it may go at once, however they start; at 0 none starts. With none set: its agents\' limit where it has one, else no limit.' },
|
|
75
|
-
agents: { unit: (n) => plural(n, 'agent', 'agents'), says: 'Agents\' limit: how many agents the runs under it may hold at once. A run claims one at its first agent step and holds it to its end; with none free it gives its task back, marked as needing an agent, and ends. At 0 no run gets one.' },
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
/** One of a workflow's two limits and its buttons. */
|
|
79
|
-
export function LimitControl({ workflow, limit, value, isSet, setLimit }: { readonly workflow: string; readonly limit: LimitName; readonly value: number | null; readonly isSet: boolean; readonly setLimit: SetLimit | undefined }) {
|
|
80
|
-
const words = LIMIT_WORDS[limit];
|
|
81
|
-
return (
|
|
82
|
-
<NumberControl name={`the ${limit === 'runs' ? 'run limit' : 'agents\' limit'} of ${workflow}`} value={value} words={(n) => (n === null ? 'no limit' : words.unit(n))}
|
|
83
|
-
step={1} min={0} isSet={isSet} resettable={limit === 'runs'} says={words.says}
|
|
84
|
-
set={setLimit === undefined ? undefined : (next) => setLimit({ workflow, limit, value: next })} />
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/** What each retention setting is, as its control says it: its words, how far a click moves it, and its least value. */
|
|
89
|
-
const SETTING_WORDS: Readonly<Record<RuntimeSettingName, { readonly label: string; readonly words: (n: number) => string; readonly step: number; readonly min: number; readonly says: string }>> = {
|
|
90
|
-
retentionDays: { label: 'keeps', words: (n) => plural(n, 'day', 'days'), step: 1, min: 1, says: 'How many days the records of its runs are kept once each run has ended; older ones are deleted by the platform\'s own workflow Retention, but for its newest runs.' },
|
|
91
|
-
keepAtLeastRuns: { label: 'keeps at least', words: (n) => plural(n, 'run', 'runs'), step: 1_000, min: 0, says: 'How many of each step\'s newest runs keep their records however long ago they ended, so a finished or stalled project keeps its last runs.' },
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
/** A level as its control's name says it. Pure. */
|
|
95
|
-
const levelWords = (level: SettingLevel): string => (level.kind === 'app' ? 'the app' : level.kind === 'workflow' ? level.workflow : `step ${level.step} of ${level.workflow}`);
|
|
96
|
-
|
|
97
|
-
/** One retention setting at one level, its buttons, and where its value is set. */
|
|
98
|
-
export function SettingControl({ level, name, settings, setSetting }: { readonly level: SettingLevel; readonly name: RuntimeSettingName; readonly settings: RetentionSettings; readonly setSetting: SetSetting | undefined }) {
|
|
99
|
-
const words = SETTING_WORDS[name];
|
|
100
|
-
const kept = name === 'retentionDays' ? settings.days : settings.atLeastRuns;
|
|
101
|
-
const isSet = name === 'retentionDays' ? settings.storedHere.days : settings.storedHere.atLeastRuns;
|
|
102
|
-
const here = level.kind === 'app' ? { workflow: '', step: null } : level.kind === 'workflow' ? { workflow: level.workflow, step: null } : { workflow: level.workflow, step: level.step };
|
|
103
|
-
return (
|
|
104
|
-
<>
|
|
105
|
-
<NumberControl name={`how many ${name === 'retentionDays' ? 'days' : 'runs at least'} ${levelWords(level)} keeps`} value={kept.value} words={(n) => words.words(n ?? 0)}
|
|
106
|
-
step={words.step} min={words.min} isSet={isSet} resettable says={words.says} set={setSetting === undefined ? undefined : (next) => setSetting({ level, name, value: next })} />
|
|
107
|
-
<span className="wp-mut">({setOnWords(kept.setOn, here)})</span>
|
|
108
|
-
</>
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/** One line of a limits table: what it limits, its control, and anything after. */
|
|
113
|
-
function LimitLine({ label, children }: { readonly label: string; readonly children: ReactNode }) {
|
|
114
|
-
return <tr><td className="wp-limits-label">{label}</td><td>{children}</td></tr>;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/** Where a workflow's own limit is set, in words. Pure. */
|
|
118
|
-
const limitSetOn = (set: boolean, otherwise: string): string => (set ? 'set on this workflow' : otherwise);
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* A WORKFLOW'S LIMITS, A LINE EACH: its run limit and agents' limit where it has them, and its own retention settings,
|
|
122
|
-
* which every step under it that sets none inherits. Each line says where its value is set.
|
|
123
|
-
*/
|
|
124
|
-
export function LimitLines({ workflow, setLimit, setSetting }: { readonly workflow: WorkflowView; readonly setLimit: SetLimit | undefined; readonly setSetting: SetSetting | undefined }) {
|
|
125
|
-
const limits = workflow.limits;
|
|
126
|
-
const level: SettingLevel = { kind: 'workflow', workflow: workflow.name };
|
|
127
|
-
return (
|
|
128
|
-
<table className="wp-limits">
|
|
129
|
-
<tbody>
|
|
130
|
-
{limits === null ? (
|
|
131
|
-
<LimitLine label="runs">
|
|
132
|
-
<span className="wp-mut">{workflow.startsOn.kind === 'a step' ? `none of its own: its runs are steps of ${workflow.startsOn.of.join(', ')}` : 'none of its own: each of its steps is a workflow with its own'}</span>
|
|
133
|
-
</LimitLine>
|
|
134
|
-
) : (
|
|
135
|
-
<>
|
|
136
|
-
<LimitLine label="runs">
|
|
137
|
-
<LimitControl workflow={workflow.name} limit="runs" value={limits.runs} isSet={limits.runsSet} setLimit={setLimit} />
|
|
138
|
-
<span className="wp-mut">({limitSetOn(limits.runsSet, limits.agents === null ? 'the default: no limit' : 'the default: its agents\' limit')})</span>
|
|
139
|
-
</LimitLine>
|
|
140
|
-
{limits.agents === null ? null : (
|
|
141
|
-
<LimitLine label="agents">
|
|
142
|
-
<LimitControl workflow={workflow.name} limit="agents" value={limits.agents} isSet setLimit={setLimit} />
|
|
143
|
-
<span className="wp-mut">({limitSetOn(limits.agentsSet, 'the default')})</span>
|
|
144
|
-
</LimitLine>
|
|
145
|
-
)}
|
|
146
|
-
</>
|
|
147
|
-
)}
|
|
148
|
-
<LimitLine label={SETTING_WORDS.retentionDays.label}><SettingControl level={level} name="retentionDays" settings={workflow.retention} setSetting={setSetting} /></LimitLine>
|
|
149
|
-
<LimitLine label={SETTING_WORDS.keepAtLeastRuns.label}><SettingControl level={level} name="keepAtLeastRuns" settings={workflow.retention} setSetting={setSetting} /></LimitLine>
|
|
150
|
-
</tbody>
|
|
151
|
-
</table>
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/** Retention settings at one level other than a workflow's own (the app, or a step in its box), a line each. */
|
|
156
|
-
export function RetentionLines({ level, settings, setSetting }: { readonly level: SettingLevel; readonly settings: RetentionSettings; readonly setSetting: SetSetting | undefined }) {
|
|
157
|
-
return (
|
|
158
|
-
<table className="wp-limits">
|
|
159
|
-
<tbody>
|
|
160
|
-
<LimitLine label={SETTING_WORDS.retentionDays.label}><SettingControl level={level} name="retentionDays" settings={settings} setSetting={setSetting} /></LimitLine>
|
|
161
|
-
<LimitLine label={SETTING_WORDS.keepAtLeastRuns.label}><SettingControl level={level} name="keepAtLeastRuns" settings={settings} setSetting={setSetting} /></LimitLine>
|
|
162
|
-
</tbody>
|
|
163
|
-
</table>
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/** A WORKFLOW'S GOING RUNS, A LINE A STATE, added up to the runs going, as its tasks are (`runsDoingLines`). */
|
|
168
|
-
export function RunsLines({ workflow, runs }: { readonly workflow: WorkflowView; readonly runs: WorkflowRunsNow | undefined }) {
|
|
169
|
-
const lines = runsDoingLines({ doing: runs?.doing ?? [], usesAgents: workflow.usesAgents });
|
|
170
|
-
const going = runs?.runs ?? 0;
|
|
171
|
-
return (
|
|
172
|
-
<table className="wp-sum" data-counts="runs" title="Each run going counted once, by its newest step record, read through a sub-workflow step to the run it started">
|
|
173
|
-
<tbody>
|
|
174
|
-
{lines.map((l, i) => (
|
|
175
|
-
<tr key={l.words}>
|
|
176
|
-
<td className="wp-sum-plus">{i === lines.length - 1 && lines.length > 1 ? '+' : ''}</td>
|
|
177
|
-
<td className="wp-sum-n">{l.runs.toLocaleString('en-US')}</td>
|
|
178
|
-
<td className="wp-sum-label">{l.words}</td>
|
|
179
|
-
</tr>
|
|
180
|
-
))}
|
|
181
|
-
</tbody>
|
|
182
|
-
<tfoot>
|
|
183
|
-
<tr className="wp-sum-total">
|
|
184
|
-
<td className="wp-sum-plus" />
|
|
185
|
-
<td className="wp-sum-n">{going.toLocaleString('en-US')}</td>
|
|
186
|
-
<td className="wp-sum-label">going</td>
|
|
187
|
-
</tr>
|
|
188
|
-
</tfoot>
|
|
189
|
-
</table>
|
|
190
|
-
);
|
|
191
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* THE PROJECT'S TWO MACHINE CONTROLS, where it gives them: its one CPU limit with − and +, and the stop of everything it
|
|
5
|
-
* runs, with the resume that undoes it. Generic to any project on the platform: the platform holds the CPU limit
|
|
6
|
-
* (`cpu-limit/limiter.ts`), and a run limit of 0 on every workflow is how everything stops. Each control says what it does
|
|
7
|
-
* in words, and a click that failed says why.
|
|
8
|
-
*/
|
|
9
|
-
import { useState } from 'react';
|
|
10
|
-
import { localTime } from '../views/format';
|
|
11
|
-
|
|
12
|
-
export interface MachineControlsProps {
|
|
13
|
-
/** The CPU limit now, and how many threads the machine has: the most it can be set to. */
|
|
14
|
-
readonly cpu: { readonly limit: number; readonly threads?: number };
|
|
15
|
-
/** When everything was stopped, unix seconds; none while the project runs. */
|
|
16
|
-
readonly stopped: { readonly at: number } | null;
|
|
17
|
-
readonly now: number;
|
|
18
|
-
/** Stores a new CPU limit; with none the limit shows without buttons. */
|
|
19
|
-
readonly setCpuLimit?: (limit: number) => Promise<void>;
|
|
20
|
-
/** Stops everything the project runs, and resumes it; with neither, no button shows. */
|
|
21
|
-
readonly stopEverything?: () => Promise<void>;
|
|
22
|
-
readonly resume?: () => Promise<void>;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function MachineControls({ cpu, stopped, now, setCpuLimit, stopEverything, resume }: MachineControlsProps) {
|
|
26
|
-
const [asked, setAsked] = useState<number | null>(null);
|
|
27
|
-
const [failed, setFailed] = useState<string | null>(null);
|
|
28
|
-
const doing = (what: Promise<void>) => { setFailed(null); what.catch((e: unknown) => { setAsked(null); setFailed(e instanceof Error ? e.message : String(e)); }); };
|
|
29
|
-
const limit = asked !== null && asked !== cpu.limit ? asked : cpu.limit;
|
|
30
|
-
const change = (to: number) => {
|
|
31
|
-
if (setCpuLimit === undefined) return;
|
|
32
|
-
setAsked(to);
|
|
33
|
-
doing(setCpuLimit(to));
|
|
34
|
-
};
|
|
35
|
-
const why = 'How many CPU-heavy processes run at once. Takes effect on new work at once; running work finishes.';
|
|
36
|
-
if (setCpuLimit === undefined && stopEverything === undefined && resume === undefined) return null;
|
|
37
|
-
return (
|
|
38
|
-
<div className="wp-machine">
|
|
39
|
-
{setCpuLimit === undefined ? null : (
|
|
40
|
-
<span className="wp-limit" title={why}>
|
|
41
|
-
<button type="button" aria-label="Lower the CPU limit" disabled={limit <= 1} onClick={() => change(limit - 1)}>−</button>
|
|
42
|
-
<span>CPU limit: {limit}{cpu.threads === undefined ? '' : ` of ${cpu.threads}`}</span>
|
|
43
|
-
<button type="button" aria-label="Raise the CPU limit" disabled={cpu.threads !== undefined && limit >= cpu.threads} onClick={() => change(limit + 1)}>+</button>
|
|
44
|
-
</span>
|
|
45
|
-
)}
|
|
46
|
-
{stopped === null
|
|
47
|
-
? (stopEverything === undefined ? null : <button type="button" className="wp-stop" title="Stops every process of the project and sets every limit aside until you resume." onClick={() => doing(stopEverything())}>Stop everything</button>)
|
|
48
|
-
: (resume === undefined ? null : <button type="button" className="wp-stop" title="Puts the limits back and starts the work again." onClick={() => doing(resume())}>Resume</button>)}
|
|
49
|
-
{stopped === null ? null : <span className="wp-bad">Everything stopped at {localTime(stopped.at, now)}; the limits are set aside.</span>}
|
|
50
|
-
{failed === null ? null : <span className="wp-bad">not done: {failed}</span>}
|
|
51
|
-
</div>
|
|
52
|
-
);
|
|
53
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* COUNTS AS A BAR, with the addition under it (`queue-table.ts`): a workflow's tasks (queued + in progress + blocked + done)
|
|
5
|
-
* or a step's calls (in progress + failed + done), a rule, the total. The bar's segments differ in lightness, and every
|
|
6
|
-
* count is also in words.
|
|
7
|
-
*/
|
|
8
|
-
import { addendLabel, queueSum } from './queue-table';
|
|
9
|
-
|
|
10
|
-
/** Each count's segment, in the order the bar draws them; a count named nowhere here is drawn last, as the dimmest. */
|
|
11
|
-
const SEGMENTS: ReadonlyArray<{ readonly key: string; readonly cls: string }> = [
|
|
12
|
-
{ key: 'done', cls: 'wp-seg-done' },
|
|
13
|
-
{ key: 'in progress', cls: 'wp-seg-running' },
|
|
14
|
-
{ key: 'queued', cls: 'wp-seg-queued' },
|
|
15
|
-
{ key: 'blocked', cls: 'wp-seg-rest' },
|
|
16
|
-
{ key: 'failed', cls: 'wp-seg-rest' },
|
|
17
|
-
];
|
|
18
|
-
|
|
19
|
-
export function QueueBar({ queue, queuedNeedingAnAgent, counts = 'tasks', totalLabel = 'total' }: {
|
|
20
|
-
/** Counts by category, in the order the addition lists them. */
|
|
21
|
-
readonly queue: Readonly<Record<string, number>>;
|
|
22
|
-
/** How many queued tasks need an agent; none where no task can be marked (`WorkflowView`). */
|
|
23
|
-
readonly queuedNeedingAnAgent: number | null;
|
|
24
|
-
/** What it counts, written on its table (`data-counts`) for whatever reads the page: a workflow's tasks, or a step's calls. */
|
|
25
|
-
readonly counts?: 'tasks' | 'calls';
|
|
26
|
-
/** What the total counts: "total" for tasks, "calls, 24 h" for a step's calls. */
|
|
27
|
-
readonly totalLabel?: string;
|
|
28
|
-
}) {
|
|
29
|
-
const sum = queueSum(queue, queuedNeedingAnAgent);
|
|
30
|
-
const segments = [
|
|
31
|
-
...SEGMENTS.filter((s) => s.key in queue),
|
|
32
|
-
...Object.keys(queue).filter((k) => !SEGMENTS.some((s) => s.key === k)).map((key) => ({ key, cls: 'wp-seg-rest' })),
|
|
33
|
-
];
|
|
34
|
-
return (
|
|
35
|
-
<div className="wp-queue">
|
|
36
|
-
<div className="wp-bar" role="img" aria-label={sum.addends.map((a) => `${a.text} ${addendLabel(a)}`).join(', ')}>
|
|
37
|
-
{segments.map((s) => {
|
|
38
|
-
const n = queue[s.key] ?? 0;
|
|
39
|
-
return n === 0 ? null : <span key={s.key} className={s.cls} style={{ width: `${(100 * n) / Math.max(1, sum.total)}%` }} />;
|
|
40
|
-
})}
|
|
41
|
-
</div>
|
|
42
|
-
<table className="wp-sum" data-counts={counts}>
|
|
43
|
-
<tbody>
|
|
44
|
-
{sum.addends.map((a, i) => (
|
|
45
|
-
<tr key={a.category}>
|
|
46
|
-
<td className="wp-sum-plus">{i === sum.addends.length - 1 ? '+' : ''}</td>
|
|
47
|
-
<td className="wp-sum-n">{a.text}</td>
|
|
48
|
-
<td className="wp-sum-label">{addendLabel(a)}</td>
|
|
49
|
-
</tr>
|
|
50
|
-
))}
|
|
51
|
-
</tbody>
|
|
52
|
-
<tfoot>
|
|
53
|
-
<tr className="wp-sum-total">
|
|
54
|
-
<td className="wp-sum-plus" />
|
|
55
|
-
<td className="wp-sum-n">{sum.totalText}</td>
|
|
56
|
-
<td className="wp-sum-label">{totalLabel}</td>
|
|
57
|
-
</tr>
|
|
58
|
-
</tfoot>
|
|
59
|
-
</table>
|
|
60
|
-
</div>
|
|
61
|
-
);
|
|
62
|
-
}
|
|
@@ -1,149 +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 <p className="wp-line wp-mut">Neither it nor any workflow under it, at any depth, records tasks.</p>;
|
|
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 className="wp-mut">{recordedSince === null ? 'recorded from now on, each time a count moves' : `recorded since ${localTime(recordedSince)}`}</span>
|
|
86
|
-
</div>
|
|
87
|
-
<div ref={box} className="wp-chart-box">
|
|
88
|
-
{shown.length === 0 ? <p className="wp-line wp-mut">No line chosen: tick a count in the table below.</p> : (
|
|
89
|
-
<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(', ')}`}>
|
|
90
|
-
{[0, 50, 100].map((percent) => (
|
|
91
|
-
<g key={percent}>
|
|
92
|
-
<line x1={P.l} x2={width - P.r} y1={Y(percent)} y2={Y(percent)} stroke="var(--wp-line)" strokeWidth="1" />
|
|
93
|
-
<text x={P.l - 4} y={Y(percent) + 3} textAnchor="end" fontSize="9" fill="var(--wp-dim)">{percent}%</text>
|
|
94
|
-
</g>
|
|
95
|
-
))}
|
|
96
|
-
<text x={P.l} y={H - 4} fontSize="9" fill="var(--wp-dim)">{localTime(from)}</text>
|
|
97
|
-
<text x={width - P.r} y={H - 4} fontSize="9" fill="var(--wp-dim)" textAnchor="end">now</text>
|
|
98
|
-
{shown.map((l, i) => (
|
|
99
|
-
<path
|
|
100
|
-
key={l.key}
|
|
101
|
-
d={l.points.map((p, k) => (k === 0 ? `M${X(p.at)},${Y(percentOf(p))}` : `H${X(p.at)}V${Y(percentOf(p))}`)).join('')}
|
|
102
|
-
fill="none" stroke={SHADES[i % SHADES.length]} strokeWidth="1.25" strokeDasharray={DASHES[i % DASHES.length]}
|
|
103
|
-
/>
|
|
104
|
-
))}
|
|
105
|
-
{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]} />)}
|
|
106
|
-
{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>)}
|
|
107
|
-
</svg>
|
|
108
|
-
)}
|
|
109
|
-
</div>
|
|
110
|
-
<p className="wp-chart-axis wp-mut">Each line: one status, as a percent of all the tasks of its workflow.</p>
|
|
111
|
-
{shown.length === 0 ? null : (
|
|
112
|
-
<ol className="wp-chart-key">
|
|
113
|
-
{shown.map((l, i) => (
|
|
114
|
-
<li key={l.key}>
|
|
115
|
-
<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>
|
|
116
|
-
{lineLabel(l, l.now)}
|
|
117
|
-
</li>
|
|
118
|
-
))}
|
|
119
|
-
</ol>
|
|
120
|
-
)}
|
|
121
|
-
<details className="wp-chart-choose">
|
|
122
|
-
<summary>choose lines ({shown.length} of {all.length})</summary>
|
|
123
|
-
<div className="wp-tablewrap">
|
|
124
|
-
<table className="wp-choose">
|
|
125
|
-
<thead>
|
|
126
|
-
<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>
|
|
127
|
-
</thead>
|
|
128
|
-
<tbody>
|
|
129
|
-
{rows.map((r) => (
|
|
130
|
-
<tr key={r.workflow}>
|
|
131
|
-
<th scope="row">{r.workflow}</th>
|
|
132
|
-
{r.lines.map((l) => (
|
|
133
|
-
<td key={l.key} className="wp-r">
|
|
134
|
-
<label>
|
|
135
|
-
<input type="checkbox" aria-label={`Show ${l.workflow} ${l.status}`} checked={shownKeys.includes(l.key)} onChange={(e) => choose(l.key, e.target.checked)} />
|
|
136
|
-
{l.now.tasks.toLocaleString('en-US')}
|
|
137
|
-
</label>
|
|
138
|
-
</td>
|
|
139
|
-
))}
|
|
140
|
-
<td className="wp-r">{r.total.toLocaleString('en-US')}</td>
|
|
141
|
-
</tr>
|
|
142
|
-
))}
|
|
143
|
-
</tbody>
|
|
144
|
-
</table>
|
|
145
|
-
</div>
|
|
146
|
-
</details>
|
|
147
|
-
</section>
|
|
148
|
-
);
|
|
149
|
-
}
|
|
@@ -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,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A WORKFLOW'S GOING RUNS IN WORDS, EACH BY WHAT IT IS DOING (`views/runs-now.ts` `RunDoing`): "3 runs going: 1 holding
|
|
3
|
-
* an agent, 2 in Repair names". The counts add up to the runs going. Pure, with no React and no
|
|
4
|
-
* JSX, so a test reads it without a page.
|
|
5
|
-
*/
|
|
6
|
-
import type { RunDoing, RunsDoing } from '../views/runs-now';
|
|
7
|
-
|
|
8
|
-
const runsWord = (n: number) => `${n} run${n === 1 ? '' : 's'}`;
|
|
9
|
-
|
|
10
|
-
/** One count's words; runs holding an agent name the agents' limit they hold them under, where the workflow has one. */
|
|
11
|
-
const countWords = (c: RunsDoing, agentsLimit: number | null): string => `${c.runs} ${doingWords(c.doing, agentsLimit)}`;
|
|
12
|
-
|
|
13
|
-
const doingWords = (d: RunDoing, agentsLimit: number | null): string =>
|
|
14
|
-
d.kind === 'holding an agent' ? `holding an agent${agentsLimit === null ? '' : ` (limit ${agentsLimit})`}`
|
|
15
|
-
: d.kind === 'in a step' ? `in ${d.step}`
|
|
16
|
-
: d.kind === 'waiting at a step' ? `waiting at ${d.step}`
|
|
17
|
-
: d.kind;
|
|
18
|
-
|
|
19
|
-
/** Its counts, with one of runs holding an agent, none included, where it uses agents: its agent count is never missing. Pure. */
|
|
20
|
-
const withAgentCount = (r: { readonly doing: ReadonlyArray<RunsDoing>; readonly usesAgents: boolean }): ReadonlyArray<RunsDoing> =>
|
|
21
|
-
r.usesAgents && !r.doing.some((c) => c.doing.kind === 'holding an agent') ? [{ doing: { kind: 'holding an agent' }, runs: 0 }, ...r.doing] : r.doing;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* A workflow's going runs and what each is doing. One that uses agents always says how many hold one, none included, so its
|
|
25
|
-
* agent count is never missing; its agents' limit is the one its runs' claims count against.
|
|
26
|
-
*/
|
|
27
|
-
export const runsGoingWords = (r: { readonly runs: number; readonly doing: ReadonlyArray<RunsDoing>; readonly usesAgents: boolean; readonly agentsLimit: number | null }): string => {
|
|
28
|
-
if (r.runs === 0) return 'no run going';
|
|
29
|
-
const counts = withAgentCount(r);
|
|
30
|
-
return `${runsWord(r.runs)} going: ${counts.map((c) => countWords(c, r.agentsLimit)).join(', ')}`;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* A WORKFLOW'S GOING RUNS AS LINES, one a state, each its count and its words, as the page's Runs section adds them up to
|
|
35
|
-
* the runs going; its agents' limit is on the Limits section. One that uses agents always has its line of runs holding an
|
|
36
|
-
* agent, none included. Pure.
|
|
37
|
-
*/
|
|
38
|
-
export const runsDoingLines = (r: { readonly doing: ReadonlyArray<RunsDoing>; readonly usesAgents: boolean }): ReadonlyArray<{ readonly runs: number; readonly words: string }> => {
|
|
39
|
-
const counts = withAgentCount(r);
|
|
40
|
-
return counts.map((c) => ({ runs: c.runs, words: doingWords(c.doing, null) }));
|
|
41
|
-
};
|