@jive-sh/workflow-platform 0.7.0 → 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 -435
- 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 -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 +255 -0
- package/src/graph.ts +341 -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 +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 -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,484 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A PROJECT'S WORKFLOWS AS ITS DASHBOARD SHOWS THEM, READ FROM THE RECORDS AT EACH REQUEST, in two readings:
|
|
3
|
-
*
|
|
4
|
-
* every workflow what it is, its steps with their kinds, its limits, and its tasks by status with their history
|
|
5
|
-
* (`buildWorkflowsView`): what a page shows before a workflow is opened, a few small readings.
|
|
6
|
-
* one workflow its steps and their cost over a window, its step graph with the window's runs on it, and where its
|
|
7
|
-
* runs stopped and why (`buildWorkflowFigures`): read from its own records when a page opens it.
|
|
8
|
-
*
|
|
9
|
-
* Built whole and stored by a job every 5 minutes, the two were one view: 5.7 s of reading on a busy machine, 4.4 s of it
|
|
10
|
-
* three scans of every step record for figures only an opened workflow shows, and a page up to 5 minutes old (2026-11-17).
|
|
11
|
-
* Built from the declarations and the stores alone, so any project's workflows read the same; a project adds its own
|
|
12
|
-
* panels beside it. Where its runs are now (`runs-now.ts`) is read at each request too.
|
|
13
|
-
*/
|
|
14
|
-
import { isMadeOfWorkflows, startedAsSteps, stepKindOf, stepUsesAnAgent, tasksAreRuns, type SourceRef, type StepDeclaration, type StepKind, type StepRuns, type WorkflowDeclaration } from '../steps';
|
|
15
|
-
import { appSetting, stepSetting, storedAt, workflowSetting, type Effective, type InheritedSettings, type SettingLevel, type SettingName, type SettingsTree, type SettingValues, type StoredSetting } from '../settings';
|
|
16
|
-
|
|
17
|
-
/** How long records are kept and the fewest runs kept however old, each with where it is set (`settings.ts`). */
|
|
18
|
-
export interface RetentionSettings {
|
|
19
|
-
readonly days: Effective<number>;
|
|
20
|
-
readonly atLeastRuns: Effective<number>;
|
|
21
|
-
/** Whether a value of each is set at this level while the app runs, so a page can put it back to the code's. */
|
|
22
|
-
readonly storedHere: { readonly days: boolean; readonly atLeastRuns: boolean };
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** A definition's link: its file and text, and the line that text is on now; none when the text is no longer in the file. */
|
|
26
|
-
export interface SourceLink extends SourceRef {
|
|
27
|
-
readonly line: number | null;
|
|
28
|
-
}
|
|
29
|
-
import { Effect } from 'effect';
|
|
30
|
-
import type { StorageError } from '../storage/storage-error';
|
|
31
|
-
import type { SpendingLimitState } from '../spending-limit';
|
|
32
|
-
import { QUEUED_NEEDING_AN_AGENT } from '../queue-counts';
|
|
33
|
-
import type { EngineRecords } from '../storage/engine-records';
|
|
34
|
-
import type { FunnelStepRecord, RunCost, RunOutcomeRow, StepRecords, StepRunRow } from '../storage/step-records';
|
|
35
|
-
import { TASK_STATUSES, type BlockedReason, type TaskStatus } from '../tasks';
|
|
36
|
-
import type { QueueCount, TaskStore } from '../storage/task-store';
|
|
37
|
-
import { stepFunnel, type StepFunnel } from './step-funnel';
|
|
38
|
-
import { workflowGraphs, type WorkflowGraph } from './step-graph';
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* WHAT STARTS ITS RUNS, from its declaration: its queue (a list of work, its runs kept going while it has some), its inputs
|
|
42
|
-
* changing (`inputs`, in its own words), or neither, a timer or a request.
|
|
43
|
-
*/
|
|
44
|
-
export type StartsOn =
|
|
45
|
-
| { readonly kind: 'queue' }
|
|
46
|
-
| { readonly kind: 'inputs'; readonly says: string }
|
|
47
|
-
| { readonly kind: 'timer or request' }
|
|
48
|
-
/** It runs only as a step of the workflows named (`defineSubWorkflow`). */
|
|
49
|
-
| { readonly kind: 'a step'; readonly of: ReadonlyArray<string> }
|
|
50
|
-
/** Its steps are workflows on their own triggers (`steps.ts` `isMadeOfWorkflows`): it has no runs of its own. */
|
|
51
|
-
| {
|
|
52
|
-
readonly kind: 'its steps';
|
|
53
|
-
/** The workflow of the step that does its main work (`WorkflowDeclaration.mainStep`), whose tasks its box shows; none where it names none. */
|
|
54
|
-
readonly mainStep: string | null;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
/** How long the queues' history reaches back. */
|
|
58
|
-
export const QUEUE_HISTORY_DAYS = 7;
|
|
59
|
-
|
|
60
|
-
/** What one step of a workflow cost over the window, from its records: none for a step with no record in it. */
|
|
61
|
-
export interface StepCost {
|
|
62
|
-
/** Its records in the window: one per call. */
|
|
63
|
-
readonly calls: number;
|
|
64
|
-
readonly failed: number;
|
|
65
|
-
/** Calls still going. */
|
|
66
|
-
readonly open: number;
|
|
67
|
-
readonly seconds: number;
|
|
68
|
-
/** Input tokens, fresh and cached. */
|
|
69
|
-
readonly inputTokens: number;
|
|
70
|
-
readonly outputTokens: number;
|
|
71
|
-
readonly cpuSeconds: number;
|
|
72
|
-
readonly compiles: number;
|
|
73
|
-
/** Items it worked on, by the records' subjects. */
|
|
74
|
-
readonly items: number;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export interface StepView {
|
|
78
|
-
readonly name: string;
|
|
79
|
-
/** How it runs (`StepRuns`); none for a sub-workflow step, and for one no longer declared that no agent ran. */
|
|
80
|
-
readonly runs: StepRuns | null;
|
|
81
|
-
readonly description: string;
|
|
82
|
-
readonly source: SourceLink;
|
|
83
|
-
/** Whether its declaration lists it; a step only the records name is no longer declared. */
|
|
84
|
-
readonly declared: boolean;
|
|
85
|
-
readonly cost: StepCost | null;
|
|
86
|
-
/** How its records in the window ended and why (`reasons.ts`), commonest first, the rest added up as one. */
|
|
87
|
-
readonly endings: ReadonlyArray<StepEnding>;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/** How many of a step's records ended one way, for one reason. */
|
|
91
|
-
export interface StepEnding {
|
|
92
|
-
readonly outcome: string;
|
|
93
|
-
readonly reason: string;
|
|
94
|
-
readonly records: number;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/** What a workflow's runs gave over a window: items finished, and per run, per million tokens and per compile. */
|
|
98
|
-
export interface Yield {
|
|
99
|
-
readonly runs: number;
|
|
100
|
-
readonly finished: number;
|
|
101
|
-
readonly tokens: number;
|
|
102
|
-
readonly compiles: number;
|
|
103
|
-
/** None where it had no run, token or compile to divide by. */
|
|
104
|
-
readonly perRun: number | null;
|
|
105
|
-
readonly perMillionTokens: number | null;
|
|
106
|
-
readonly perCompile: number | null;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/** What a run of a workflow costs, from its ended runs in the window. */
|
|
110
|
-
export interface RunCosts {
|
|
111
|
-
/** Its runs that ended in the window. */
|
|
112
|
-
readonly runs: number;
|
|
113
|
-
/** The median run's cost, figure by figure; none with no run. */
|
|
114
|
-
readonly median: { readonly seconds: number; readonly tokens: number; readonly cpuSeconds: number; readonly childCpuSeconds: number; readonly compiles: number } | null;
|
|
115
|
-
/** Its costliest run by CPU, its processes' included. */
|
|
116
|
-
readonly costliest: Pick<RunCost, 'run' | 'started' | 'seconds' | 'tokens' | 'cpuSeconds' | 'compiles'> | null;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const medianOf = (xs: ReadonlyArray<number>): number => {
|
|
120
|
-
const sorted = [...xs].sort((a, b) => a - b);
|
|
121
|
-
const mid = Math.floor(sorted.length / 2);
|
|
122
|
-
return sorted.length % 2 === 1 ? sorted[mid]! : (sorted[mid - 1]! + sorted[mid]!) / 2;
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
/** A workflow's ended runs as their costs: the median run, figure by figure, and the costliest. Pure. */
|
|
126
|
-
export const runCostsOf = (costs: ReadonlyArray<RunCost>): RunCosts => {
|
|
127
|
-
const ended = costs.filter((c) => !c.going);
|
|
128
|
-
if (ended.length === 0) return { runs: 0, median: null, costliest: null };
|
|
129
|
-
const costliest = ended.reduce((a, b) => (b.cpuSeconds > a.cpuSeconds ? b : a));
|
|
130
|
-
return {
|
|
131
|
-
runs: ended.length,
|
|
132
|
-
median: {
|
|
133
|
-
seconds: medianOf(ended.map((c) => c.seconds)), tokens: medianOf(ended.map((c) => c.tokens)), cpuSeconds: medianOf(ended.map((c) => c.cpuSeconds)),
|
|
134
|
-
childCpuSeconds: medianOf(ended.map((c) => c.childCpuSeconds)), compiles: medianOf(ended.map((c) => c.compiles)),
|
|
135
|
-
},
|
|
136
|
-
costliest: { run: costliest.run, started: costliest.started, seconds: costliest.seconds, tokens: costliest.tokens, cpuSeconds: costliest.cpuSeconds, compiles: costliest.compiles },
|
|
137
|
-
};
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
/** Endings listed per step; the rest are added up as one. */
|
|
141
|
-
export const ENDINGS_LISTED = 4;
|
|
142
|
-
|
|
143
|
-
/** A step's records as their endings, commonest first. Pure. */
|
|
144
|
-
export const endingsOf = (records: ReadonlyArray<Pick<FunnelStepRecord, 'outcome' | 'reason'>>): ReadonlyArray<StepEnding> => {
|
|
145
|
-
const counts = new Map<string, StepEnding>();
|
|
146
|
-
for (const r of records) {
|
|
147
|
-
const outcome = r.outcome ?? 'going';
|
|
148
|
-
const reason = r.reason ?? (r.outcome === null ? 'still going' : 'no reason recorded');
|
|
149
|
-
const key = `${outcome}\u0000${reason}`;
|
|
150
|
-
const was = counts.get(key);
|
|
151
|
-
counts.set(key, { outcome, reason, records: (was?.records ?? 0) + 1 });
|
|
152
|
-
}
|
|
153
|
-
const all = [...counts.values()].sort((a, b) => b.records - a.records || a.reason.localeCompare(b.reason));
|
|
154
|
-
const rest = all.slice(ENDINGS_LISTED).reduce((n, e) => n + e.records, 0);
|
|
155
|
-
return [...all.slice(0, ENDINGS_LISTED), ...(rest === 0 ? [] : [{ outcome: 'other', reason: `${all.length - ENDINGS_LISTED} other endings`, records: rest }])];
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
/** A window's yield from its counts. Pure. */
|
|
159
|
-
export const yieldOf = (r: { readonly runs: number; readonly finished: number; readonly tokens: number; readonly compiles: number }): Yield => ({
|
|
160
|
-
...r,
|
|
161
|
-
perRun: r.runs === 0 ? null : r.finished / r.runs,
|
|
162
|
-
perMillionTokens: r.tokens === 0 ? null : (r.finished * 1_000_000) / r.tokens,
|
|
163
|
-
perCompile: r.compiles === 0 ? null : r.finished / r.compiles,
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* A step as a workflow's own view lists it: its kind in words (`steps.ts` `StepKind`), and for a sub-workflow the workflow
|
|
168
|
-
* it opens.
|
|
169
|
-
*/
|
|
170
|
-
export interface StepSummary {
|
|
171
|
-
readonly name: string;
|
|
172
|
-
readonly kind: StepKind;
|
|
173
|
-
/** How it runs; none for a sub-workflow step, whose own steps say theirs. */
|
|
174
|
-
readonly runs: StepRuns | null;
|
|
175
|
-
readonly description: string;
|
|
176
|
-
/** For a sub-workflow: the workflow it runs, by name; none for any other kind. */
|
|
177
|
-
readonly workflow: string | null;
|
|
178
|
-
/** How many days its records are kept, and where that is set (`settings.ts`); for a sub-workflow, its workflow's. */
|
|
179
|
-
readonly retention: RetentionSettings;
|
|
180
|
-
/** The model it runs on, and where that is set; for a sub-workflow, its workflow's; none for a step that uses no agent. */
|
|
181
|
-
readonly model: Effective<string | null> | null;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* THE TOP OF A PROJECT IS ONE WORKFLOW, declared like any other (Alex, 2026-11-19: "decompiling an entire game is in itself
|
|
186
|
-
* a workflow"): what a page enters at. Its steps are workflows, and each opens that workflow's own view.
|
|
187
|
-
*/
|
|
188
|
-
export interface TopWorkflowView {
|
|
189
|
-
readonly name: string;
|
|
190
|
-
readonly description: string;
|
|
191
|
-
readonly steps: ReadonlyArray<StepSummary>;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/** A workflow as a page shows it before it is opened: what it is, its steps, its limits and its queue. */
|
|
195
|
-
export interface WorkflowView {
|
|
196
|
-
readonly name: string;
|
|
197
|
-
/** Its own steps, in order, each with its kind. */
|
|
198
|
-
readonly steps: ReadonlyArray<StepSummary>;
|
|
199
|
-
readonly description: string;
|
|
200
|
-
readonly source: SourceLink;
|
|
201
|
-
/** Its word for one item, none where it works on no single item. */
|
|
202
|
-
readonly item: string | null;
|
|
203
|
-
readonly finishedWord: string | null;
|
|
204
|
-
readonly usesAgents: boolean;
|
|
205
|
-
/**
|
|
206
|
-
* Its limits: how many runs of it may go at once (`runs`, none for no limit; `runsSet` false where that is the default),
|
|
207
|
-
* and, for a workflow its budget keeps going, how many of its runs may be in an agent step at once (`agents`, none for
|
|
208
|
-
* any other). None where no store is read.
|
|
209
|
-
*/
|
|
210
|
-
readonly limits: { readonly agents: number | null; readonly runs: number | null; readonly runsSet: boolean; readonly agentsSet: boolean } | null;
|
|
211
|
-
/** Its tasks by status, as last counted (`queue-counts.ts`); none for a workflow with no item whose tasks are not its runs (`steps.ts` `tasksAreRuns`). */
|
|
212
|
-
readonly queue: Readonly<Record<TaskStatus, number>> | null;
|
|
213
|
-
/**
|
|
214
|
-
* How many of its queued tasks are marked as needing an agent, as last counted (`queue-counts.ts`, `QUEUED_NEEDING_AN_AGENT`);
|
|
215
|
-
* none for a workflow with no item or no agent step, where no task can be marked.
|
|
216
|
-
*/
|
|
217
|
-
readonly queuedNeedingAnAgent: number | null;
|
|
218
|
-
/** What starts its runs. */
|
|
219
|
-
readonly startsOn: StartsOn;
|
|
220
|
-
/** Whether it is one of the platform's own workflows (`system-workflows.ts`): its settings are the app's, its steps the platform's. */
|
|
221
|
-
readonly system: boolean;
|
|
222
|
-
/** Its own retention settings, as every step under it that sets none inherits them. */
|
|
223
|
-
readonly retention: RetentionSettings;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
/** Every workflow, read at the request: nothing here is stored for the page. */
|
|
227
|
-
export interface WorkflowsView {
|
|
228
|
-
/** When it was read, unix seconds. */
|
|
229
|
-
readonly at: number;
|
|
230
|
-
readonly top: TopWorkflowView;
|
|
231
|
-
/** The app's other workflows no workflow has as a step, by name: each is a top of its own, beside the project's. */
|
|
232
|
-
readonly outermost: ReadonlyArray<string>;
|
|
233
|
-
/** The platform's own workflows, by name (`system-workflows.ts`): each a top of its own, shown apart from the app's. */
|
|
234
|
-
readonly system: ReadonlyArray<string>;
|
|
235
|
-
/** Every workflow, in the order defined: the top's steps and theirs, at every depth, each one view. */
|
|
236
|
-
readonly workflows: ReadonlyArray<WorkflowView>;
|
|
237
|
-
/** Each queue's counts by status over the last `QUEUE_HISTORY_DAYS` (`historyByStatus`), a row where one changed, oldest first. */
|
|
238
|
-
readonly queueHistory: ReadonlyArray<QueueCount>;
|
|
239
|
-
/** The spending limit against the newest reading of the week (`spending-limit.ts`); none for a project that reads no week. */
|
|
240
|
-
readonly spending: SpendingLimitState | null;
|
|
241
|
-
/** The app's retention settings, above every workflow (`settings.ts`). */
|
|
242
|
-
readonly appRetention: RetentionSettings;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/** One workflow's figures over a window, read from its own records when it is opened. */
|
|
246
|
-
export interface WorkflowFigures {
|
|
247
|
-
readonly workflow: string;
|
|
248
|
-
/** When it was read, unix seconds, and the window: the `hours` before it. */
|
|
249
|
-
readonly at: number;
|
|
250
|
-
readonly hours: number;
|
|
251
|
-
readonly since: number;
|
|
252
|
-
readonly steps: ReadonlyArray<StepView>;
|
|
253
|
-
/** Its steps' costs added up. */
|
|
254
|
-
readonly total: StepCost;
|
|
255
|
-
readonly graph: WorkflowGraph;
|
|
256
|
-
readonly funnel: StepFunnel;
|
|
257
|
-
/** What a run of it costs, its processes included. */
|
|
258
|
-
readonly runCosts: RunCosts;
|
|
259
|
-
/** What its runs gave in the window, and in the window before it: the trend. */
|
|
260
|
-
readonly yields: { readonly now: Yield; readonly before: Yield };
|
|
261
|
-
/** Why its blocked tasks are blocked now: a count for each reason, most tasks first (`tasks.ts` `blockedReasons`). */
|
|
262
|
-
readonly blocked: ReadonlyArray<BlockedReason>;
|
|
263
|
-
/**
|
|
264
|
-
* Its queued tasks marked as needing an agent, a count for each reason (`tasks.ts` `needsAgentReasons`), and whether its
|
|
265
|
-
* Pick passes over them now because no agent can be had, with why in words; none while one can.
|
|
266
|
-
*/
|
|
267
|
-
readonly needingAnAgent: { readonly reasons: ReadonlyArray<BlockedReason>; readonly passedOverBecause: string | null };
|
|
268
|
-
/**
|
|
269
|
-
* FOR A WORKFLOW A RUN OF ANOTHER STARTS AS A STEP (`defineSubWorkflow`), THE TASKS OF EACH SUCH WORKFLOW PASSING THROUGH
|
|
270
|
-
* IT: that workflow's calls of the step in the window, from its own step records, each on its item (`StepCost`); none where
|
|
271
|
-
* the step was not called. Its tasks are those, counted once, under their own workflow. Empty for any other workflow.
|
|
272
|
-
*/
|
|
273
|
-
readonly passingThrough: ReadonlyArray<{ readonly workflow: string; readonly step: string; readonly cost: StepCost | null }>;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
const NO_COST: StepCost = { calls: 0, failed: 0, open: 0, seconds: 0, inputTokens: 0, outputTokens: 0, cpuSeconds: 0, compiles: 0, items: 0 };
|
|
277
|
-
|
|
278
|
-
const addCosts = (a: StepCost, b: StepCost): StepCost => ({
|
|
279
|
-
calls: a.calls + b.calls, failed: a.failed + b.failed, open: a.open + b.open, seconds: a.seconds + b.seconds,
|
|
280
|
-
inputTokens: a.inputTokens + b.inputTokens, outputTokens: a.outputTokens + b.outputTokens, cpuSeconds: a.cpuSeconds + b.cpuSeconds,
|
|
281
|
-
compiles: a.compiles + b.compiles, items: a.items + b.items,
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
/** One step's rows (one per run, step and subject) as its cost. Pure. */
|
|
285
|
-
export const costOf = (rows: ReadonlyArray<StepRunRow>): StepCost | null =>
|
|
286
|
-
rows.length === 0 ? null : {
|
|
287
|
-
calls: rows.reduce((n, r) => n + r.calls, 0),
|
|
288
|
-
failed: rows.reduce((n, r) => n + r.failed, 0),
|
|
289
|
-
open: rows.reduce((n, r) => n + r.open, 0),
|
|
290
|
-
seconds: rows.reduce((n, r) => n + r.ms, 0) / 1000,
|
|
291
|
-
inputTokens: rows.reduce((n, r) => n + (r.fresh ?? 0) + (r.cache_write ?? 0) + (r.cache_read ?? 0), 0),
|
|
292
|
-
outputTokens: rows.reduce((n, r) => n + (r.output ?? 0), 0),
|
|
293
|
-
cpuSeconds: rows.reduce((n, r) => n + r.cpu_seconds, 0),
|
|
294
|
-
compiles: rows.reduce((n, r) => n + (r.compiles ?? 0), 0),
|
|
295
|
-
items: new Set(rows.flatMap((r) => (r.subject === null ? [] : [r.subject.toLowerCase()]))).size,
|
|
296
|
-
};
|
|
297
|
-
|
|
298
|
-
type Declared = Pick<WorkflowDeclaration<unknown>, 'name' | 'description' | 'source' | 'item' | 'finishedWord' | 'graph' | 'fedBy' | 'mainStep' | 'pending' | 'items' | 'inputs' | 'retentionDays' | 'model' | 'system'> & {
|
|
299
|
-
readonly steps: () => ReadonlyArray<StepDeclaration>;
|
|
300
|
-
};
|
|
301
|
-
|
|
302
|
-
const noTasks = (): Record<TaskStatus, number> => Object.fromEntries(TASK_STATUSES.map((s) => [s, 0])) as Record<TaskStatus, number>;
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* The names a count was recorded under before 2026-11-19, when a task stood in one of six buckets, and the status each is
|
|
306
|
-
* part of now. `queued` and `done` kept their names.
|
|
307
|
-
*/
|
|
308
|
-
const RECORDED_BEFORE: Readonly<Record<string, TaskStatus>> = { running: 'in progress', waiting: 'blocked', stuck: 'blocked', held: 'blocked' };
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* THE RECORDED COUNTS (`queueCountsSince`, oldest first) AS THE FOUR STATUSES: a row for each status of each workflow where
|
|
312
|
-
* its count moved. A count recorded under an older name is part of its status until the workflow has a count under the
|
|
313
|
-
* four, which replaces it; one recorded under an older name after that (by code still running as the newer began) is
|
|
314
|
-
* not read. Pure.
|
|
315
|
-
*/
|
|
316
|
-
export const historyByStatus = (recorded: ReadonlyArray<QueueCount>): ReadonlyArray<QueueCount> => {
|
|
317
|
-
const raw = new Map<string, Map<string, number>>();
|
|
318
|
-
const countedByStatus = new Set<string>();
|
|
319
|
-
const last = new Map<string, number>();
|
|
320
|
-
const out: QueueCount[] = [];
|
|
321
|
-
recorded.forEach((row, i) => {
|
|
322
|
-
const counts = raw.get(row.workflow) ?? new Map<string, number>();
|
|
323
|
-
raw.set(row.workflow, counts);
|
|
324
|
-
const olderName = RECORDED_BEFORE[row.bucket] !== undefined;
|
|
325
|
-
if (!olderName && (row.bucket === 'in progress' || row.bucket === 'blocked') && !countedByStatus.has(row.workflow)) {
|
|
326
|
-
countedByStatus.add(row.workflow);
|
|
327
|
-
for (const older of Object.keys(RECORDED_BEFORE)) counts.delete(older);
|
|
328
|
-
}
|
|
329
|
-
if (!(olderName && countedByStatus.has(row.workflow))) counts.set(row.bucket, row.tasks);
|
|
330
|
-
// Every row of one moment is one count of the workflow: its statuses are read once all of them are in.
|
|
331
|
-
const next = recorded[i + 1];
|
|
332
|
-
if (next !== undefined && next.workflow === row.workflow && next.at === row.at) return;
|
|
333
|
-
for (const status of TASK_STATUSES) {
|
|
334
|
-
const tasks = [...counts].reduce((sum, [name, n]) => sum + (name === status || RECORDED_BEFORE[name] === status ? n : 0), 0);
|
|
335
|
-
const key = `${row.workflow}\u0000${status}`;
|
|
336
|
-
if (last.get(key) !== tasks) out.push({ at: row.at, workflow: row.workflow, bucket: status, tasks });
|
|
337
|
-
last.set(key, tasks);
|
|
338
|
-
}
|
|
339
|
-
});
|
|
340
|
-
return out;
|
|
341
|
-
};
|
|
342
|
-
|
|
343
|
-
/** Each queue's newest count of queued tasks marked as needing an agent, from the recorded counts (oldest first). Pure. */
|
|
344
|
-
export const queuedNeedingAnAgentNow = (recorded: ReadonlyArray<QueueCount>): ReadonlyMap<string, number> =>
|
|
345
|
-
new Map(recorded.filter((row) => row.bucket === QUEUED_NEEDING_AN_AGENT).map((row) => [row.workflow, row.tasks]));
|
|
346
|
-
|
|
347
|
-
/** Each queue's newest count from its history by status (`historyByStatus`), a status never counted at 0. Pure. */
|
|
348
|
-
export const queuesNow = (history: ReadonlyArray<QueueCount>): ReadonlyMap<string, Readonly<Record<TaskStatus, number>>> => {
|
|
349
|
-
const queues = new Map<string, Record<TaskStatus, number>>();
|
|
350
|
-
for (const row of history) {
|
|
351
|
-
const queue = queues.get(row.workflow) ?? noTasks();
|
|
352
|
-
if ((TASK_STATUSES as ReadonlyArray<string>).includes(row.bucket)) queue[row.bucket as TaskStatus] = row.tasks;
|
|
353
|
-
queues.set(row.workflow, queue);
|
|
354
|
-
}
|
|
355
|
-
return queues;
|
|
356
|
-
};
|
|
357
|
-
|
|
358
|
-
/**
|
|
359
|
-
* EVERY WORKFLOW AS A PAGE SHOWS IT BEFORE ONE IS OPENED, READ AT THE REQUEST: the declarations, the limits, each queue's
|
|
360
|
-
* counts as last counted and their history. A few small readings of the store, so a
|
|
361
|
-
* page load needs no stored copy of it. `limitsOf` is none where no store is read.
|
|
362
|
-
*/
|
|
363
|
-
export const buildWorkflowsView = (input: {
|
|
364
|
-
readonly declared: ReadonlyArray<Declared>;
|
|
365
|
-
/** What the app sets above every workflow (`WorkflowProject.settings`). */
|
|
366
|
-
readonly app: InheritedSettings;
|
|
367
|
-
/** The retention settings set while the app runs (`LimitStore.storedSettings`). */
|
|
368
|
-
readonly stored: ReadonlyArray<StoredSetting>;
|
|
369
|
-
readonly now: number;
|
|
370
|
-
/** The queues' history, from the task store. */
|
|
371
|
-
readonly taskStore: Pick<TaskStore, 'queueCountsSince'>;
|
|
372
|
-
/** The line a definition's text is on now. */
|
|
373
|
-
readonly locate: (source: SourceRef) => number | null;
|
|
374
|
-
readonly limitsOf: (workflow: string) => WorkflowView['limits'];
|
|
375
|
-
/** The project's top workflow, by name: the workflow a page enters at. */
|
|
376
|
-
readonly top: string;
|
|
377
|
-
readonly spending: SpendingLimitState | null;
|
|
378
|
-
}): Effect.Effect<WorkflowsView, StorageError> => Effect.gen(function* () {
|
|
379
|
-
// A step's settings as its workflow `of` holds it; a sub-workflow's are what its workflow's own steps inherit.
|
|
380
|
-
const tree: SettingsTree = { declared: input.declared, app: input.app, stored: input.stored };
|
|
381
|
-
const storedHere = (level: SettingLevel): RetentionSettings['storedHere'] => ({ days: storedAt(input.stored, level, 'retentionDays') !== null, atLeastRuns: storedAt(input.stored, level, 'keepAtLeastRuns') !== null });
|
|
382
|
-
const settingOf = <N extends SettingName>(of: string, s: StepDeclaration, name: N): Effective<SettingValues[N]> =>
|
|
383
|
-
(s.workflow === undefined ? stepSetting(tree, { workflow: of, step: s.name, name }) : workflowSetting(tree, { workflow: s.workflow, name }));
|
|
384
|
-
const stepSummary = (of: string) => (s: StepDeclaration): StepSummary => ({
|
|
385
|
-
name: s.name, kind: stepKindOf(s), runs: s.runs, description: s.description, workflow: s.workflow ?? null,
|
|
386
|
-
retention: { days: settingOf(of, s, 'retentionDays'), atLeastRuns: settingOf(of, s, 'keepAtLeastRuns'), storedHere: storedHere({ kind: 'step', workflow: of, step: s.name }) },
|
|
387
|
-
model: stepUsesAnAgent(s) ? settingOf(of, s, 'model') : null,
|
|
388
|
-
});
|
|
389
|
-
// A workflow a run of another starts as a step has no runs or limits of its own; one on its own trigger has both.
|
|
390
|
-
const usedAsAStep = startedAsSteps(input.declared);
|
|
391
|
-
const anyStep = new Set(input.declared.flatMap((d) => d.steps().flatMap((s) => (s.workflow === undefined ? [] : [s.workflow]))));
|
|
392
|
-
const recordedCounts = yield* input.taskStore.queueCountsSince(input.now - QUEUE_HISTORY_DAYS * 86_400);
|
|
393
|
-
const queueHistory = historyByStatus(recordedCounts);
|
|
394
|
-
const queues = queuesNow(queueHistory);
|
|
395
|
-
const needingAnAgent = queuedNeedingAnAgentNow(recordedCounts);
|
|
396
|
-
const workflowView = (d: Declared): WorkflowView => ({
|
|
397
|
-
name: d.name, steps: d.steps().map(stepSummary(d.name)),
|
|
398
|
-
description: d.description, source: { ...d.source, line: input.locate(d.source) }, item: d.item, finishedWord: d.finishedWord,
|
|
399
|
-
usesAgents: d.steps().some(stepUsesAnAgent),
|
|
400
|
-
// A workflow used as a step has no limit of its own to show: its starts are its parent's steps (`defineSubWorkflow`).
|
|
401
|
-
limits: usedAsAStep.has(d.name) || isMadeOfWorkflows(d) ? null : input.limitsOf(d.name),
|
|
402
|
-
// A workflow with no item has tasks where they are its runs (`steps.ts` `tasksAreRuns`): counted from its first run on.
|
|
403
|
-
queue: d.item === null && !tasksAreRuns(d, input.declared) ? null : queues.get(d.name) ?? noTasks(),
|
|
404
|
-
queuedNeedingAnAgent: d.item === null || !d.steps().some(stepUsesAnAgent) ? null : needingAnAgent.get(d.name) ?? 0,
|
|
405
|
-
startsOn: usedAsAStep.has(d.name) ? { kind: 'a step', of: input.declared.filter((p) => p.steps().some((s) => s.workflow === d.name)).map((p) => p.name) }
|
|
406
|
-
: isMadeOfWorkflows(d) ? { kind: 'its steps', mainStep: d.steps().find((s) => s.name === d.mainStep)?.workflow ?? null }
|
|
407
|
-
: d.pending !== undefined || d.items !== undefined ? { kind: 'queue' } : d.inputs !== undefined ? { kind: 'inputs', says: d.inputs.says } : { kind: 'timer or request' },
|
|
408
|
-
system: d.system === true,
|
|
409
|
-
retention: { days: workflowSetting(tree, { workflow: d.name, name: 'retentionDays' }), atLeastRuns: workflowSetting(tree, { workflow: d.name, name: 'keepAtLeastRuns' }), storedHere: storedHere({ kind: 'workflow', workflow: d.name }) },
|
|
410
|
-
});
|
|
411
|
-
return {
|
|
412
|
-
at: input.now,
|
|
413
|
-
top: ((top) => ({ name: input.top, description: top?.description ?? `${input.top} is not declared`, steps: top?.steps().map(stepSummary(input.top)) ?? [] }))(input.declared.find((d) => d.name === input.top)),
|
|
414
|
-
outermost: input.declared.filter((d) => d.name !== input.top && !anyStep.has(d.name) && d.system !== true).map((d) => d.name),
|
|
415
|
-
system: input.declared.filter((d) => d.system === true).map((d) => d.name),
|
|
416
|
-
workflows: input.declared.map(workflowView),
|
|
417
|
-
queueHistory,
|
|
418
|
-
spending: input.spending,
|
|
419
|
-
appRetention: { days: appSetting(tree, 'retentionDays'), atLeastRuns: appSetting(tree, 'keepAtLeastRuns'), storedHere: storedHere({ kind: 'app' }) },
|
|
420
|
-
};
|
|
421
|
-
});
|
|
422
|
-
|
|
423
|
-
/**
|
|
424
|
-
* ONE WORKFLOW'S FIGURES OVER THE `hours` BEFORE `now`, READ FROM ITS OWN RECORDS when a page opens it: each step's cost and
|
|
425
|
-
* endings, its step graph with the runs on each edge, where its runs stopped, what a run costs, and what its runs gave
|
|
426
|
-
* against the window before.
|
|
427
|
-
*/
|
|
428
|
-
export const buildWorkflowFigures = (input: {
|
|
429
|
-
readonly declaration: Declared;
|
|
430
|
-
readonly now: number;
|
|
431
|
-
readonly hours: number;
|
|
432
|
-
readonly records: StepRecords;
|
|
433
|
-
readonly engine: EngineRecords;
|
|
434
|
-
/** Why its blocked tasks are blocked now, and its queued tasks marked as needing an agent, read from its tasks. */
|
|
435
|
-
readonly reasons: Effect.Effect<Pick<WorkflowFigures, 'blocked' | 'needingAnAgent'>, StorageError>;
|
|
436
|
-
/** The line a definition's text is on now. */
|
|
437
|
-
readonly locate: (source: SourceRef) => number | null;
|
|
438
|
-
/** The workflows whose runs start it as a step, and that step's name in each (`WorkflowFigures.passingThrough`). */
|
|
439
|
-
readonly asAStepOf?: ReadonlyArray<{ readonly workflow: string; readonly step: string }>;
|
|
440
|
-
}): Effect.Effect<WorkflowFigures, StorageError> => Effect.gen(function* () {
|
|
441
|
-
const d = input.declaration;
|
|
442
|
-
const since = input.now - input.hours * 3600;
|
|
443
|
-
const before = since - input.hours * 3600;
|
|
444
|
-
const own = yield* input.records.stepRunsSince(since, d.name);
|
|
445
|
-
// The window before, for the trend: its records are those since its start, less the window's own.
|
|
446
|
-
const ownBoth = yield* input.records.stepRunsSince(before, d.name);
|
|
447
|
-
const funnelRecords = yield* input.records.funnelRecordsSince(since, d.name);
|
|
448
|
-
const funnelBoth = yield* input.records.funnelRecordsSince(before, d.name);
|
|
449
|
-
const finishedNow = yield* input.records.runOutcomesSince(since, d.name);
|
|
450
|
-
const finishedBoth = yield* input.records.runOutcomesSince(before, d.name);
|
|
451
|
-
const runCosts = yield* input.records.runCostsSince(since, d.name);
|
|
452
|
-
const moves = yield* input.records.stepEdgesSince(since, d.name);
|
|
453
|
-
const going = new Set((yield* input.engine.unfinishedRuns()).map((u) => u.run));
|
|
454
|
-
const link = (s: SourceRef): SourceLink => ({ ...s, line: input.locate(s) });
|
|
455
|
-
|
|
456
|
-
const declaredSteps = d.steps();
|
|
457
|
-
const onlyInRecords = [...new Set(own.map((r) => r.step))].filter((s) => !declaredSteps.some((x) => x.name === s));
|
|
458
|
-
const steps: ReadonlyArray<StepView> = [
|
|
459
|
-
...declaredSteps.map((s) => ({ name: s.name, runs: s.runs, description: s.description, source: link(s.source), declared: true, cost: costOf(own.filter((r) => r.step === s.name)), endings: endingsOf(funnelRecords.records.filter((r) => r.step === s.name)) })),
|
|
460
|
-
...onlyInRecords.map((name) => ({ name, runs: own.some((r) => r.step === name && r.agent === 1) ? 'agentic' as const : null, description: 'no longer declared', source: link(d.source), declared: false, cost: costOf(own.filter((r) => r.step === name)), endings: endingsOf(funnelRecords.records.filter((r) => r.step === name)) })),
|
|
461
|
-
];
|
|
462
|
-
const funnel = stepFunnel({ declaration: d, records: funnelRecords.records, outcomes: funnelRecords.outcomes, unfinished: going, hours: input.hours, since, now: input.now });
|
|
463
|
-
const funnelBefore = stepFunnel({ declaration: d, records: funnelBoth.records, outcomes: funnelBoth.outcomes, unfinished: going, hours: input.hours, since: before, now: since });
|
|
464
|
-
const costNow = costOf(own) ?? NO_COST;
|
|
465
|
-
const costBoth = costOf(ownBoth) ?? NO_COST;
|
|
466
|
-
const finished = (outcomes: ReadonlyArray<RunOutcomeRow>) => outcomes.filter((o) => o.finished === 1).length;
|
|
467
|
-
return {
|
|
468
|
-
workflow: d.name, at: input.now, hours: input.hours, since,
|
|
469
|
-
steps,
|
|
470
|
-
total: steps.reduce((t, s) => (s.cost === null ? t : addCosts(t, s.cost)), NO_COST),
|
|
471
|
-
graph: workflowGraphs({ declared: [d], taken: moves.edges, lasts: moves.lasts, going })[0]!,
|
|
472
|
-
funnel,
|
|
473
|
-
runCosts: runCostsOf(runCosts),
|
|
474
|
-
...(yield* input.reasons),
|
|
475
|
-
passingThrough: yield* Effect.forEach(input.asAStepOf ?? [], (p) => Effect.map(input.records.stepRunsSince(since, p.workflow), (rows) => ({ ...p, cost: costOf(rows.filter((r) => r.step === p.step)) }))),
|
|
476
|
-
yields: {
|
|
477
|
-
now: yieldOf({ runs: funnel.runs, finished: finished(finishedNow), tokens: costNow.inputTokens + costNow.outputTokens, compiles: costNow.compiles }),
|
|
478
|
-
before: yieldOf({
|
|
479
|
-
runs: funnelBefore.runs, finished: finished(finishedBoth) - finished(finishedNow),
|
|
480
|
-
tokens: costBoth.inputTokens + costBoth.outputTokens - (costNow.inputTokens + costNow.outputTokens), compiles: costBoth.compiles - costNow.compiles,
|
|
481
|
-
}),
|
|
482
|
-
},
|
|
483
|
-
};
|
|
484
|
-
});
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* STEPS THAT FEED NO OTHER STEP ARE DRAWN IN A GRID, their lines said once in words. Upkeep's 28 steps, 26 of them on their
|
|
3
|
-
* own trigger, were one row 6,146 px wide with 54 lines that all said "on its own trigger" or "what it finishes leaves
|
|
4
|
-
* here" (decided as the default in effect, 2026-11-24, while Alex had not yet answered the choice between a grid and one row).
|
|
5
|
-
*
|
|
6
|
-
* 1. Two or more such steps whose lines read the same go in a grid; the steps that feed each other keep their lines.
|
|
7
|
-
* 2. A step on its own, and steps whose lines read differently, keep their lines.
|
|
8
|
-
* 3. The page draws the grid with the sentence and every grid step's box, and lays out only what is left.
|
|
9
|
-
*/
|
|
10
|
-
import { expect, test } from 'bun:test';
|
|
11
|
-
import { renderToStaticMarkup } from 'react-dom/server';
|
|
12
|
-
import { RUN_ENDS, RUN_STARTS } from './graph';
|
|
13
|
-
import { layOut, standAloneSteps, standAloneWords, WorkflowDag } from './dashboard/workflow-dag';
|
|
14
|
-
import type { WorkflowGraph } from './views/step-graph';
|
|
15
|
-
|
|
16
|
-
const step = (name: string) => ({ name, runs: null, description: '', workflow: null });
|
|
17
|
-
const edge = (from: string, to: string, when: string, runs = 0) => ({ from, to, when, runs });
|
|
18
|
-
const onItsOwn = (name: string) => [edge(RUN_STARTS, name, 'on its own trigger'), edge(name, RUN_ENDS, 'what it finishes leaves here')];
|
|
19
|
-
const graphOf = (input: { readonly steps: ReadonlyArray<string>; readonly edges: WorkflowGraph['edges'] }): WorkflowGraph =>
|
|
20
|
-
({ workflow: 'Upkeep', declared: true, steps: input.steps.map(step), edges: input.edges, undeclared: [] });
|
|
21
|
-
|
|
22
|
-
/** Upkeep's shape: Full byte check feeds Compiler host, and every other step is on its own trigger. */
|
|
23
|
-
const upkeep = graphOf({
|
|
24
|
-
steps: ['Closability', 'Full byte check', 'Compiler host', 'Prune logs', 'Reaper'],
|
|
25
|
-
edges: [
|
|
26
|
-
edge(RUN_STARTS, 'Closability', 'on its own trigger'), edge(RUN_STARTS, 'Full byte check', 'on its own trigger'),
|
|
27
|
-
edge(RUN_STARTS, 'Prune logs', 'on its own trigger'), edge(RUN_STARTS, 'Reaper', 'on its own trigger'),
|
|
28
|
-
edge('Full byte check', 'Compiler host', "its results become Compiler host's tasks"),
|
|
29
|
-
edge('Closability', RUN_ENDS, 'what it finishes leaves here'), edge('Compiler host', RUN_ENDS, 'what it finishes leaves here'),
|
|
30
|
-
edge('Prune logs', RUN_ENDS, 'what it finishes leaves here'), edge('Reaper', RUN_ENDS, 'what it finishes leaves here'),
|
|
31
|
-
],
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test('1. steps on their own trigger go in one grid; the two that feed each other keep their three lines', () => {
|
|
35
|
-
const { grids, drawn } = standAloneSteps(upkeep);
|
|
36
|
-
expect({
|
|
37
|
-
grids: grids.map((g) => g.steps),
|
|
38
|
-
drawnSteps: drawn.steps.map((s) => s.name),
|
|
39
|
-
drawnEdges: drawn.edges.map((e) => `${e.from} > ${e.to}`),
|
|
40
|
-
words: grids.map(standAloneWords),
|
|
41
|
-
}).toEqual({
|
|
42
|
-
grids: [['Closability', 'Prune logs', 'Reaper']],
|
|
43
|
-
drawnSteps: ['Full byte check', 'Compiler host'],
|
|
44
|
-
drawnEdges: [`${RUN_STARTS} > Full byte check`, 'Full byte check > Compiler host', `Compiler host > ${RUN_ENDS}`],
|
|
45
|
-
words: ["These 3 steps feed no other step and no step feeds them, so they are drawn without lines. Into each from the run's start: on its own trigger. Out of each to the run's end: what it finishes leaves here."],
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test.each([
|
|
50
|
-
{ name: 'a workflow of one step, in its declared order', graph: graphOf({ steps: ['Pick a page'], edges: [edge(RUN_STARTS, 'Pick a page', ''), edge('Pick a page', RUN_ENDS, '')] }) },
|
|
51
|
-
{
|
|
52
|
-
name: "two steps each with its own condition (Repair names')",
|
|
53
|
-
graph: graphOf({
|
|
54
|
-
steps: ['Rename', 'Book names'],
|
|
55
|
-
edges: [
|
|
56
|
-
edge(RUN_STARTS, 'Rename', 'a failed proof waits for the repair'), edge(RUN_STARTS, 'Book names', 'no failed proof waits', 73),
|
|
57
|
-
edge('Rename', RUN_ENDS, 'always'), edge('Book names', RUN_ENDS, 'always', 73),
|
|
58
|
-
],
|
|
59
|
-
}),
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
name: 'two steps with the same condition but different runs taken',
|
|
63
|
-
graph: graphOf({ steps: ['A', 'B'], edges: [edge(RUN_STARTS, 'A', 'always', 2), edge(RUN_STARTS, 'B', 'always'), edge('A', RUN_ENDS, 'always', 2), edge('B', RUN_ENDS, 'always')] }),
|
|
64
|
-
},
|
|
65
|
-
{ name: 'a chain', graph: graphOf({ steps: ['A', 'B'], edges: [edge(RUN_STARTS, 'A', ''), edge('A', 'B', ''), edge('B', RUN_ENDS, '')] }) },
|
|
66
|
-
])('2. $name keeps every line', ({ graph }) => {
|
|
67
|
-
const { grids, drawn } = standAloneSteps(graph);
|
|
68
|
-
expect({ grids: grids.length, drawn }).toEqual({ grids: 0, drawn: { steps: graph.steps, edges: graph.edges } });
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test('3. the page draws every grid step\'s box under the sentence, and lays out only the rest', async () => {
|
|
72
|
-
const box = (name: string) => ({ href: `/Upkeep/${name}`, title: name, body: <p>{`body of ${name}`}</p> });
|
|
73
|
-
const html = renderToStaticMarkup(<WorkflowDag graph={upkeep} box={box} />);
|
|
74
|
-
const grid = html.slice(html.indexOf('data-stand-alone-steps'));
|
|
75
|
-
expect({
|
|
76
|
-
sentence: grid.includes('These 3 steps feed no other step'),
|
|
77
|
-
inGrid: [...grid.matchAll(/data-step="([^"]*)"/g)].map((m) => m[1]),
|
|
78
|
-
bodies: ['Closability', 'Prune logs', 'Reaper'].every((n) => grid.includes(`body of ${n}`) && grid.includes(`href="/Upkeep/${n}"`)),
|
|
79
|
-
}).toEqual({ sentence: true, inGrid: ['Closability', 'Prune logs', 'Reaper'], bodies: true });
|
|
80
|
-
const laid = await layOut({ graph: standAloneSteps(upkeep).drawn, heightOf: () => 80 });
|
|
81
|
-
expect({ boxes: [...laid.boxes.keys()], lines: laid.edges.length }).toEqual({ boxes: [RUN_STARTS, 'Full byte check', 'Compiler host', RUN_ENDS], lines: 3 });
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
test('3b. a workflow whose every step is on its own trigger has only the grid, no frame and no run start or end box', () => {
|
|
85
|
-
const all = graphOf({ steps: ['Byte coverage', 'Decompile', 'Bank closest trials'], edges: ['Byte coverage', 'Decompile', 'Bank closest trials'].flatMap(onItsOwn) });
|
|
86
|
-
const html = renderToStaticMarkup(<WorkflowDag graph={all} box={(name) => ({ href: null, title: name, body: null })} />);
|
|
87
|
-
expect({ frame: html.includes('wp-dag-scroll'), ends: html.includes(RUN_STARTS) || html.includes(RUN_ENDS), steps: [...html.matchAll(/data-step="([^"]*)"/g)].map((m) => m[1]) })
|
|
88
|
-
.toEqual({ frame: false, ends: false, steps: ['Byte coverage', 'Decompile', 'Bank closest trials'] });
|
|
89
|
-
});
|