@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,358 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* THE STEP RECORDS: one record per step run, written only by the step definer (`steps.ts`): which workflow, run and step,
|
|
3
|
-
* when it started and ended, how it ended, what it spent and used, and, while an agent step runs, its heartbeat. Every
|
|
4
|
-
* figure about a workflow's cost and progress is a query of these.
|
|
5
|
-
*
|
|
6
|
-
* An interface, so where the records live is the store's business: `sqlite-store.ts` keeps them in a SQLite file. Every
|
|
7
|
-
* method is an effect, so a store on a remote database answers the same calls.
|
|
8
|
-
*/
|
|
9
|
-
import type { Effect } from 'effect';
|
|
10
|
-
import { startAndEnd } from '../failure';
|
|
11
|
-
import type { ProcessIdentity } from '../project';
|
|
12
|
-
import type { StorageError } from './storage-error';
|
|
13
|
-
|
|
14
|
-
/** What a step spent: input tokens by the kind the weekly limit weights differently, output tokens, compiles. */
|
|
15
|
-
export interface StepSpend {
|
|
16
|
-
fresh: number;
|
|
17
|
-
cacheWrite: number;
|
|
18
|
-
cacheRead: number;
|
|
19
|
-
output: number;
|
|
20
|
-
compiles: number;
|
|
21
|
-
/** The API requests an agent step made: each reads the whole context back. */
|
|
22
|
-
requests: number;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const noSpend = (): StepSpend => ({ fresh: 0, cacheWrite: 0, cacheRead: 0, output: 0, compiles: 0, requests: 0 });
|
|
26
|
-
|
|
27
|
-
/** An agent step with no usage this long has a fault: every agent's first request reports it within seconds. */
|
|
28
|
-
export const NO_USAGE_FAULT_SECONDS = 120;
|
|
29
|
-
/** An agent step's heartbeat older than this means its process is gone, whatever the record says. */
|
|
30
|
-
export const AGENT_LIVE_SECONDS = 180;
|
|
31
|
-
/** How often the definer beats an agent step's record. */
|
|
32
|
-
export const AGENT_BEAT_MS = 30_000;
|
|
33
|
-
|
|
34
|
-
/** What a step used, as its meter measured it (`step-meter.ts`). */
|
|
35
|
-
export interface StepUsed {
|
|
36
|
-
/** CPU of its own processes, exact. */
|
|
37
|
-
readonly childCpuSeconds: number;
|
|
38
|
-
/** Its share of its process's own CPU while it ran. */
|
|
39
|
-
readonly ownCpuSeconds: number;
|
|
40
|
-
readonly peakMemoryMb: number;
|
|
41
|
-
readonly filesWritten: number;
|
|
42
|
-
readonly compiles: number;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* What a step worked on: 'shared' (declared: work no one item owns), 'nothing' (its Pick found none, and every step after
|
|
47
|
-
* it), 'none due' (a batch with no item to do), 'functions' (one part record per item: the stored word, from the first
|
|
48
|
-
* project's items) or 'undeclared'.
|
|
49
|
-
*/
|
|
50
|
-
export type StepScope = 'shared' | 'nothing' | 'none due' | 'functions' | 'undeclared';
|
|
51
|
-
|
|
52
|
-
/** A failed step's error as its record keeps it: 8,000 characters, the start and the end of a longer one. */
|
|
53
|
-
export const stepErrorKept = (error: string): string => startAndEnd(error, { cap: 8000, end: 3000, what: 'the error' });
|
|
54
|
-
|
|
55
|
-
export type StepOutcome = 'success' | 'failure' | 'interrupted';
|
|
56
|
-
|
|
57
|
-
/** One step of one run over a window, its calls added up. */
|
|
58
|
-
export interface StepRunRow {
|
|
59
|
-
readonly workflow: string;
|
|
60
|
-
readonly run: string;
|
|
61
|
-
readonly step: string;
|
|
62
|
-
readonly agent: number;
|
|
63
|
-
readonly calls: number;
|
|
64
|
-
/** Calls not ended. */
|
|
65
|
-
readonly open: number;
|
|
66
|
-
readonly failed: number;
|
|
67
|
-
readonly ms: number;
|
|
68
|
-
readonly fresh: number;
|
|
69
|
-
readonly cache_write: number;
|
|
70
|
-
readonly cache_read: number;
|
|
71
|
-
readonly output: number;
|
|
72
|
-
readonly compiles: number;
|
|
73
|
-
/** What it worked on; none on a step before its run named one. */
|
|
74
|
-
readonly subject: string | null;
|
|
75
|
-
readonly requests: number;
|
|
76
|
-
/** When its oldest live call with no usage started; none when every live call has some. */
|
|
77
|
-
readonly no_usage_since: number | null;
|
|
78
|
-
readonly cpu_seconds: number;
|
|
79
|
-
readonly files_written: number;
|
|
80
|
-
readonly peak_memory_mb: number;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* WHAT ONE RUN COST: every step of it added up. `cpuSeconds` is its steps' own share of their process's CPU and all of their
|
|
85
|
-
* child processes' (`childCpuSeconds`), each process measured when it exited (`step-meter.ts`).
|
|
86
|
-
*/
|
|
87
|
-
export interface RunCost {
|
|
88
|
-
readonly workflow: string;
|
|
89
|
-
readonly run: string;
|
|
90
|
-
/** When its first step started, unix seconds. */
|
|
91
|
-
readonly started: number;
|
|
92
|
-
/** From its first step's start to its last step's end, or its newest heartbeat while one is open. */
|
|
93
|
-
readonly seconds: number;
|
|
94
|
-
/** Input tokens, fresh and cached, and output tokens. */
|
|
95
|
-
readonly tokens: number;
|
|
96
|
-
readonly cpuSeconds: number;
|
|
97
|
-
readonly childCpuSeconds: number;
|
|
98
|
-
readonly compiles: number;
|
|
99
|
-
readonly peakMemoryMb: number;
|
|
100
|
-
/** Whether a step of it is still open. */
|
|
101
|
-
readonly going: boolean;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/** One item of one run, as it ended. */
|
|
105
|
-
export interface RunOutcomeRow {
|
|
106
|
-
readonly workflow: string;
|
|
107
|
-
readonly run: string;
|
|
108
|
-
readonly subject: string;
|
|
109
|
-
readonly outcome: string;
|
|
110
|
-
readonly finished: number;
|
|
111
|
-
readonly at: number;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/** A folder's files written in one hour that no step declared. */
|
|
115
|
-
export interface UndeclaredWrites {
|
|
116
|
-
readonly hour: number;
|
|
117
|
-
readonly folder: string;
|
|
118
|
-
readonly files: number;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/** What to rank items by. */
|
|
122
|
-
export type ItemRank = 'tokens' | 'cpu' | 'seconds';
|
|
123
|
-
|
|
124
|
-
/** What one workflow's items cost since a time, optionally in one step, costliest first. */
|
|
125
|
-
export interface ItemCost {
|
|
126
|
-
readonly subject: string;
|
|
127
|
-
readonly tokens: number;
|
|
128
|
-
readonly output: number;
|
|
129
|
-
readonly seconds: number;
|
|
130
|
-
readonly compiles: number;
|
|
131
|
-
readonly cpuSeconds: number;
|
|
132
|
-
readonly peakMemoryMb: number;
|
|
133
|
-
/** Runs that worked on it. */
|
|
134
|
-
readonly tries: number;
|
|
135
|
-
readonly outcome: string | null;
|
|
136
|
-
readonly finished: boolean;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/** A step's files written, each finished record. */
|
|
140
|
-
export interface StepFileCount {
|
|
141
|
-
readonly workflow: string;
|
|
142
|
-
readonly step: string;
|
|
143
|
-
readonly started: number;
|
|
144
|
-
readonly files_written: number;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/** One item's history, across workflows: each step of each run that worked on it. */
|
|
148
|
-
export interface ItemHistoryRow {
|
|
149
|
-
readonly workflow: string;
|
|
150
|
-
readonly run: string;
|
|
151
|
-
readonly step: string;
|
|
152
|
-
readonly started: number;
|
|
153
|
-
readonly calls: number;
|
|
154
|
-
readonly tokens: number;
|
|
155
|
-
readonly output: number;
|
|
156
|
-
readonly seconds: number;
|
|
157
|
-
readonly compiles: number;
|
|
158
|
-
readonly cpuSeconds: number;
|
|
159
|
-
readonly peakMemoryMb: number;
|
|
160
|
-
readonly outcome: string | null;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* The workflow step a piece of work on an item was done in. `recorded`: the step record stored when it was done. `matched
|
|
165
|
-
* afterwards`: exactly one step of one run worked on the item while the work's time fell inside it.
|
|
166
|
-
*/
|
|
167
|
-
export interface WorkStep {
|
|
168
|
-
readonly workflow: string;
|
|
169
|
-
readonly run: string;
|
|
170
|
-
readonly step: string;
|
|
171
|
-
readonly how: 'recorded' | 'matched afterwards';
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/** A run's newest step record: the step it is in now while that record is open, or the one it last ended. */
|
|
175
|
-
export interface NewestStepRecord {
|
|
176
|
-
readonly run: string;
|
|
177
|
-
readonly step: string;
|
|
178
|
-
readonly agent: number;
|
|
179
|
-
readonly started: number;
|
|
180
|
-
/** None while the step is still going. */
|
|
181
|
-
readonly ended: number | null;
|
|
182
|
-
/** What an open step waits on, in its own words (a Pick with nothing it can claim); none while it works. */
|
|
183
|
-
readonly waiting: string | null;
|
|
184
|
-
/** For a sub-workflow step: the run it started, whose own newest record says where the work is now; absent on any other. */
|
|
185
|
-
readonly childRun?: string | null;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/** One step record of a run in a funnel's window, in the order written. */
|
|
189
|
-
export interface FunnelStepRecord {
|
|
190
|
-
readonly workflow: string;
|
|
191
|
-
readonly run: string;
|
|
192
|
-
readonly step: string;
|
|
193
|
-
readonly agent: number;
|
|
194
|
-
readonly started: number;
|
|
195
|
-
readonly ended: number | null;
|
|
196
|
-
readonly outcome: string | null;
|
|
197
|
-
readonly error: string | null;
|
|
198
|
-
readonly scope: string | null;
|
|
199
|
-
/** Why it ended as it did, in a line; none on a record from before reasons were kept. */
|
|
200
|
-
readonly reason: string | null;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/** Runs that went from one step to the next, the later started in the window; `from` null where it was the run's first. */
|
|
204
|
-
export interface StepEdgeTaken {
|
|
205
|
-
readonly workflow: string;
|
|
206
|
-
readonly from: string | null;
|
|
207
|
-
readonly fromFailed: boolean;
|
|
208
|
-
readonly to: string;
|
|
209
|
-
readonly runs: number;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* WHICH RECORDS RETENTION DELETES IN ONE CALL (`retention.ts`): one step's of a workflow, a workflow's other steps' (those no
|
|
214
|
-
* longer declared included), or those of every workflow not named (none declared now).
|
|
215
|
-
*/
|
|
216
|
-
export type RecordsSelection =
|
|
217
|
-
| { readonly workflow: string; readonly step: string }
|
|
218
|
-
| { readonly workflow: string; readonly stepsOtherThan: ReadonlyArray<string> }
|
|
219
|
-
| { readonly workflowsOtherThan: ReadonlyArray<string> };
|
|
220
|
-
|
|
221
|
-
/** A run's last step so far, for its runs that worked in the window. */
|
|
222
|
-
export interface LastStepNow {
|
|
223
|
-
readonly workflow: string;
|
|
224
|
-
readonly run: string;
|
|
225
|
-
readonly step: string;
|
|
226
|
-
readonly failed: boolean;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
export interface StepRecords {
|
|
230
|
-
// ------------------------------------------------------------------ written by the step definer
|
|
231
|
-
/**
|
|
232
|
-
* Opens a step's record. It works on what `subject` names, else on what the run last worked on, else on what the run
|
|
233
|
-
* that started it as a sub-workflow works on. `resume`: the run's open record of this step and call is taken up again
|
|
234
|
-
* where there is one (a sub-workflow step, run again when its workflow has ended). `version` is its workflow's version now
|
|
235
|
-
* (`steps.ts` `versionOf`); the record takes its run's, the version on the run's first record, so a run resumed under newer
|
|
236
|
-
* code keeps the version it started on. Null where nothing is written.
|
|
237
|
-
*/
|
|
238
|
-
readonly openStepRun: (r: { readonly workflow: string; readonly run: string; readonly step: string; readonly call: number | null; readonly agent: boolean; readonly subject: string | null; readonly version: string; readonly resume?: true }) => Effect.Effect<number | null, StorageError>;
|
|
239
|
-
/** The run a sub-workflow step started, on that step's open record: what ties a run to the run above it. */
|
|
240
|
-
readonly setStepChild: (r: { readonly id: number; readonly childRun: string }) => Effect.Effect<void, StorageError>;
|
|
241
|
-
/** The run at the top of the runs that started this one as a sub-workflow, with its workflow; none for a run nothing started so. */
|
|
242
|
-
readonly rootOfRun: (run: string) => Effect.Effect<{ readonly run: string; readonly workflow: string } | null, StorageError>;
|
|
243
|
-
/** The run whose sub-workflow step started this one, with its workflow and that step's name; none for a run nothing started so. */
|
|
244
|
-
readonly parentOfRun: (run: string) => Effect.Effect<{ readonly run: string; readonly workflow: string; readonly step: string } | null, StorageError>;
|
|
245
|
-
readonly beatStepRun: (id: number) => Effect.Effect<void, StorageError>;
|
|
246
|
-
/** What an agent step has spent so far, on its open record, as each usage arrives. */
|
|
247
|
-
readonly updateStepSpend: (r: { readonly id: number; readonly spend: StepSpend; readonly model: string | null }) => Effect.Effect<void, StorageError>;
|
|
248
|
-
readonly closeStepRun: (r: { readonly id: number; readonly outcome: StepOutcome; readonly reason: string | null; readonly error: string | null; readonly spend: StepSpend; readonly subject: string | null; readonly used: StepUsed; readonly scope: StepScope }) => Effect.Effect<void, StorageError>;
|
|
249
|
-
/** What an open step waits on now, or null once it no longer waits. */
|
|
250
|
-
readonly setStepWaiting: (r: { readonly id: number; readonly waiting: string | null }) => Effect.Effect<void, StorageError>;
|
|
251
|
-
/** A pick that waited for work starts its record when it found some: the wait was not work on that item. */
|
|
252
|
-
readonly restartStepRun: (id: number) => Effect.Effect<void, StorageError>;
|
|
253
|
-
/** A compile a process of the step's own ran: that process cannot reach the step's meter. */
|
|
254
|
-
readonly addStepCompile: (id: number) => Effect.Effect<void, StorageError>;
|
|
255
|
-
/** Opens one item's part of a batch step. */
|
|
256
|
-
readonly openStepItem: (r: { readonly stepRun: number; readonly subject: string }) => Effect.Effect<number | null, StorageError>;
|
|
257
|
-
readonly closeStepItem: (r: { readonly id: number; readonly outcome: StepOutcome; readonly used: Pick<StepUsed, 'childCpuSeconds' | 'ownCpuSeconds' | 'peakMemoryMb' | 'compiles'> }) => Effect.Effect<void, StorageError>;
|
|
258
|
-
/** The files an agent step changed (`step-files.ts`), on its one record. */
|
|
259
|
-
readonly recordStepFiles: (r: { readonly id: number; readonly files: string }) => Effect.Effect<void, StorageError>;
|
|
260
|
-
/** A test said an item passes while the workflow's list still holds it: a fault in that test or that list. */
|
|
261
|
-
readonly recordClearedButListed: (r: { readonly workflow: string; readonly run: string; readonly item: string; readonly said: string }) => Effect.Effect<void, StorageError>;
|
|
262
|
-
/** Adds files written in each folder to the hour starting at `hour`. */
|
|
263
|
-
readonly recordUndeclaredWrites: (r: { readonly hour: number; readonly counts: ReadonlyMap<string, number> }) => Effect.Effect<void, StorageError>;
|
|
264
|
-
/**
|
|
265
|
-
* Closes every record left open by a process that has ended, `interrupted`, at its last heartbeat. A record from before
|
|
266
|
-
* owners were kept is closed only if it was opened before `serviceStartedAt`. Returns how many it closed.
|
|
267
|
-
*/
|
|
268
|
-
readonly closeStepRunsLeftOpen: (serviceStartedAt: number) => Effect.Effect<number, StorageError>;
|
|
269
|
-
/**
|
|
270
|
-
* DELETES THE RECORDS `select` NAMES OF RUNS THAT ENDED BEFORE `before`, each batch record's parts with it: a record goes
|
|
271
|
-
* once every record of its run has ended before then, its run is none of `keepRuns` (the engine's runs not finished),
|
|
272
|
-
* and it is not of one of the `keepNewest` newest runs of its step (by when each started there), however old: a project that
|
|
273
|
-
* finished or stalled keeps each step's last runs. Retention's one delete (`retention.ts`). How many records and parts went.
|
|
274
|
-
*/
|
|
275
|
-
readonly deleteRecordsOfRunsEndedBefore: (r: { readonly select: RecordsSelection; readonly before: number; readonly keepRuns: ReadonlyArray<string>; readonly keepNewest: number }) => Effect.Effect<{ readonly records: number; readonly parts: number }, StorageError>;
|
|
276
|
-
|
|
277
|
-
// ------------------------------------------------------------------ read
|
|
278
|
-
/** The file record of a run's newest try at a step. */
|
|
279
|
-
readonly stepFilesOf: (r: { readonly run: string; readonly step: string }) => Effect.Effect<string | null, StorageError>;
|
|
280
|
-
/** The step a run did last, and whether it failed; none before its first. A step a restart interrupted is not one. */
|
|
281
|
-
readonly lastStepOf: (run: string) => Effect.Effect<{ readonly step: string; readonly failed: boolean; readonly owner: ProcessIdentity | null } | null, StorageError>;
|
|
282
|
-
/** The step a run is on now, and what it works on. */
|
|
283
|
-
readonly stepOfRun: (run: string) => Effect.Effect<{ readonly step: string; readonly subject: string | null; readonly started: number } | null, StorageError>;
|
|
284
|
-
/** The run's newest named item. */
|
|
285
|
-
readonly subjectOfRun: (run: string) => Effect.Effect<string | null, StorageError>;
|
|
286
|
-
readonly clearedButListedSince: (since: number) => Effect.Effect<ReadonlyArray<{ readonly workflow: string; readonly item: string; readonly said: string; readonly times: number }>, StorageError>;
|
|
287
|
-
/** Each workflow's newest finished step. */
|
|
288
|
-
readonly newestStepOutcomes: () => Effect.Effect<ReadonlyMap<string, { readonly step: string; readonly outcome: string; readonly error: string | null }>, StorageError>;
|
|
289
|
-
/** The newest run of a workflow: when its last step ended, and whether it spent anything. */
|
|
290
|
-
readonly newestRun: (workflow: string) => Effect.Effect<{ readonly endedAt: number; readonly spent: boolean } | null, StorageError>;
|
|
291
|
-
/** A workflow's newest step activity (a start, heartbeat or end) and newest step end. */
|
|
292
|
-
readonly newestStepActivity: (workflow: string) => Effect.Effect<{ readonly activeAt: number | null; readonly endedAt: number | null }, StorageError>;
|
|
293
|
-
/** Each run's records since `since`, added up by step and subject. With `workflow`, here and below, only that workflow's. */
|
|
294
|
-
readonly stepRunsSince: (since: number, workflow?: string) => Effect.Effect<ReadonlyArray<StepRunRow>, StorageError>;
|
|
295
|
-
/** What each run that began since `since` cost, all its steps added up, its processes' CPU included. */
|
|
296
|
-
readonly runCostsSince: (since: number, workflow?: string) => Effect.Effect<ReadonlyArray<RunCost>, StorageError>;
|
|
297
|
-
readonly agentModelsSince: (since: number) => Effect.Effect<ReadonlyArray<{ readonly model: string; readonly steps: number }>, StorageError>;
|
|
298
|
-
/** When records begin; none before the first. */
|
|
299
|
-
readonly stepRunsBegin: () => Effect.Effect<number | null, StorageError>;
|
|
300
|
-
/** Every run with an agent step, all time: when it started and what its agent steps spent. */
|
|
301
|
-
readonly agentRunsEver: (workflow?: string) => Effect.Effect<ReadonlyArray<{ readonly workflow: string; readonly run: string; readonly started: number; readonly fresh: number; readonly cacheWrite: number; readonly cacheRead: number; readonly output: number; readonly requests: number }>, StorageError>;
|
|
302
|
-
readonly runOutcomesSince: (since: number, workflow?: string) => Effect.Effect<ReadonlyArray<RunOutcomeRow>, StorageError>;
|
|
303
|
-
readonly undeclaredWritesSince: (since: number) => Effect.Effect<ReadonlyArray<UndeclaredWrites>, StorageError>;
|
|
304
|
-
readonly itemCosts: (r: { readonly workflow: string; readonly step: string | null; readonly since: number; readonly rank?: ItemRank }) => Effect.Effect<ReadonlyArray<ItemCost>, StorageError>;
|
|
305
|
-
/** What a workflow's steps declared as shared cost since `since`: charged to no item. */
|
|
306
|
-
readonly sharedCosts: (r: { readonly workflow: string; readonly since: number }) => Effect.Effect<{ readonly cpuSeconds: number; readonly seconds: number; readonly compiles: number }, StorageError>;
|
|
307
|
-
readonly stepFileCountsSince: (since: number) => Effect.Effect<ReadonlyArray<StepFileCount>, StorageError>;
|
|
308
|
-
readonly itemHistory: (subject: string) => Effect.Effect<ReadonlyArray<ItemHistoryRow>, StorageError>;
|
|
309
|
-
/** Each piece of work's step, in order; null where it is not recorded. */
|
|
310
|
-
readonly stepsOfWork: (work: ReadonlyArray<{ readonly subject: string; readonly at: number; readonly stepRun: number | null }>) => Effect.Effect<ReadonlyArray<WorkStep | null>, StorageError>;
|
|
311
|
-
/** When subjects begin. */
|
|
312
|
-
readonly subjectsBegin: () => Effect.Effect<number | null, StorageError>;
|
|
313
|
-
/** The newest record of each run named. */
|
|
314
|
-
readonly newestStepRecords: (runs: ReadonlyArray<string>) => Effect.Effect<ReadonlyArray<NewestStepRecord>, StorageError>;
|
|
315
|
-
/** Every record of every run whose first step started at or after `since`, and those runs' item outcomes. */
|
|
316
|
-
readonly funnelRecordsSince: (since: number, workflow?: string) => Effect.Effect<{ readonly records: ReadonlyArray<FunnelStepRecord>; readonly outcomes: ReadonlyArray<RunOutcomeRow> }, StorageError>;
|
|
317
|
-
/** Each item's newest successful call of these steps of a workflow, newest first. */
|
|
318
|
-
readonly newestCallsByItem: (r: { readonly workflow: string; readonly steps: ReadonlyArray<string> }) => Effect.Effect<ReadonlyArray<{ readonly subject: string; readonly run: string; readonly activity: string; readonly ended: number }>, StorageError>;
|
|
319
|
-
/** Every step-to-step move in the window, by workflow, and each run's last step. Interrupted records are not moves. */
|
|
320
|
-
readonly stepEdgesSince: (since: number, workflow?: string) => Effect.Effect<{ readonly edges: ReadonlyArray<StepEdgeTaken>; readonly lasts: ReadonlyArray<LastStepNow> }, StorageError>;
|
|
321
|
-
// ------------------------------------------------------------------ read for each step's time distribution (`step-times.ts`)
|
|
322
|
-
/**
|
|
323
|
-
* Every record of one version of a workflow up to `newestId`, the newest record of any when it was read, through their
|
|
324
|
-
* index (`step_runs_by_version`), with each batch record's parts: `recordsSince` reads on from `newestId`, so none is missed.
|
|
325
|
-
*/
|
|
326
|
-
readonly versionRecords: (r: { readonly workflow: string; readonly version: string }) => Effect.Effect<TimedRecords & { readonly newestId: number }, StorageError>;
|
|
327
|
-
/** Every record written after record `after` (by id, so only new ones are read), and these records again by id, with parts. */
|
|
328
|
-
readonly recordsSince: (r: { readonly after: number; readonly again: ReadonlyArray<number> }) => Effect.Effect<TimedRecords, StorageError>;
|
|
329
|
-
/** The version of a workflow other than `version` whose newest record is newest, and when that was; none where it has none. */
|
|
330
|
-
readonly previousVersion: (r: { readonly workflow: string; readonly version: string }) => Effect.Effect<{ readonly version: string; readonly at: number } | null, StorageError>;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
/** A step record as its time distribution reads it. */
|
|
334
|
-
export interface TimedRecord {
|
|
335
|
-
readonly id: number;
|
|
336
|
-
readonly workflow: string;
|
|
337
|
-
readonly version: string | null;
|
|
338
|
-
readonly run: string;
|
|
339
|
-
readonly step: string;
|
|
340
|
-
readonly subject: string | null;
|
|
341
|
-
readonly started: number;
|
|
342
|
-
readonly ended: number | null;
|
|
343
|
-
/** 'functions' for a batch record, whose items' parts are its `TimedPart`s. */
|
|
344
|
-
readonly scope: string | null;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
/** One item's part of a batch record (`step_functions`). */
|
|
348
|
-
export interface TimedPart {
|
|
349
|
-
readonly stepRun: number;
|
|
350
|
-
readonly subject: string;
|
|
351
|
-
readonly started: number;
|
|
352
|
-
readonly ended: number | null;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
export interface TimedRecords {
|
|
356
|
-
readonly records: ReadonlyArray<TimedRecord>;
|
|
357
|
-
readonly parts: ReadonlyArray<TimedPart>;
|
|
358
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WHAT EVERY STORE FAILS WITH: a read or write it could not make. Every store method is an effect failing with this, so a
|
|
3
|
-
* store on a remote database (Convex) answers the same calls the SQLite stores do, and a caller says what it does about a
|
|
4
|
-
* store it cannot reach instead of the store throwing.
|
|
5
|
-
*/
|
|
6
|
-
import { Data, Effect, Schedule } from 'effect';
|
|
7
|
-
|
|
8
|
-
export class StorageError extends Data.TaggedError('StorageError')<{
|
|
9
|
-
/** Which store and call: `step records: openStepRun`. */
|
|
10
|
-
readonly operation: string;
|
|
11
|
-
readonly reason: string;
|
|
12
|
-
}> {}
|
|
13
|
-
|
|
14
|
-
/** A held lock: what a connection that never waits inside SQLite throws when another holds it. */
|
|
15
|
-
const LOCKED = /database is locked|SQLITE_BUSY/i;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* A synchronous store's call as an effect: what it throws becomes a `StorageError` naming the call. A held lock is tried
|
|
19
|
-
* again every 20 ms for up to 10 s, yielding between tries, never waiting inside SQLite: a wait there holds the thread,
|
|
20
|
-
* and a transaction that thread holds on another connection of the same file could not finish (2026-11-01, `STORAGE.md`).
|
|
21
|
-
*/
|
|
22
|
-
export const storeCall = <A>(operation: string, call: () => A): Effect.Effect<A, StorageError> =>
|
|
23
|
-
Effect.retry(
|
|
24
|
-
Effect.try({ try: call, catch: (e) => new StorageError({ operation, reason: e instanceof Error ? e.message : String(e) }) }),
|
|
25
|
-
{ while: (e) => LOCKED.test(e.reason), times: 500, schedule: Schedule.spaced('20 millis') },
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
/** A store's calls as a synchronous store makes them: each returns what its effect gives. */
|
|
29
|
-
export type SynchronousCalls<S> = {
|
|
30
|
-
readonly [K in keyof S]: S[K] extends (...args: infer P) => Effect.Effect<infer A, StorageError> ? (...args: P) => A : never;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
/** A synchronous store's calls as the interface's effects, each named in its failure (`storeCall`). */
|
|
34
|
-
export const storeCalls = <S>(store: string, calls: SynchronousCalls<S>): S =>
|
|
35
|
-
Object.fromEntries(Object.entries(calls).map(([name, call]) => [name, (...args: ReadonlyArray<unknown>) => storeCall(`${store}: ${name}`, () => (call as (...a: ReadonlyArray<unknown>) => unknown)(...args))])) as S;
|
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* THE TASK STORE: one row per task (a workflow and its item), its append-only notes, and where its workflow's list last
|
|
3
|
-
* put it. The queue's rules (`tasks.ts`) read and write only through this, so where tasks live is the store's business:
|
|
4
|
-
* `sqlite-store.ts` keeps them beside the step records. Every call is an effect, so a remote store can answer it.
|
|
5
|
-
*/
|
|
6
|
-
import type { Effect } from 'effect';
|
|
7
|
-
import type { StorageError } from './storage-error';
|
|
8
|
-
|
|
9
|
-
/** A task, by its workflow and its item; the item matches in any case. */
|
|
10
|
-
export interface TaskRef {
|
|
11
|
-
readonly workflow: string;
|
|
12
|
-
readonly item: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/** Who wrote a note: a step of a run of a workflow; all null for a person, through the project's API. */
|
|
16
|
-
export interface NoteBy {
|
|
17
|
-
readonly workflow: string | null;
|
|
18
|
-
readonly run: string | null;
|
|
19
|
-
readonly step: string | null;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** A change to a task's text: both texts stored by hash (`TextStore`), and the diff between them. */
|
|
23
|
-
export interface TextChange {
|
|
24
|
-
readonly beforeSha: string;
|
|
25
|
-
readonly afterSha: string;
|
|
26
|
-
readonly flags: string;
|
|
27
|
-
readonly diff: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface TaskNote {
|
|
31
|
-
readonly id: number;
|
|
32
|
-
readonly task: TaskRef;
|
|
33
|
-
/** Unix seconds. */
|
|
34
|
-
readonly at: number;
|
|
35
|
-
readonly kind: string;
|
|
36
|
-
readonly by: NoteBy;
|
|
37
|
-
readonly why: string;
|
|
38
|
-
/** Another task the note is about: a verdict's target, the task reopened or waited on. */
|
|
39
|
-
readonly about: TaskRef | null;
|
|
40
|
-
/** The hash of the `about` task's text the note was written against. */
|
|
41
|
-
readonly aboutSha: string | null;
|
|
42
|
-
/** On an outcome: whether it finished the task. */
|
|
43
|
-
readonly finished: boolean | null;
|
|
44
|
-
/** New input another workflow or step gave the task, stored by hash; none on any other note. */
|
|
45
|
-
readonly inputSha: string | null;
|
|
46
|
-
/** On an outcome: the fingerprint of the task's inputs as its run left them (`tasks.ts` `TaskInputs`); none where unknown. */
|
|
47
|
-
readonly inputs: string | null;
|
|
48
|
-
readonly change: TextChange | null;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/** A note to append. */
|
|
52
|
-
export interface NewNote {
|
|
53
|
-
readonly task: TaskRef;
|
|
54
|
-
readonly by: NoteBy;
|
|
55
|
-
readonly kind: string;
|
|
56
|
-
readonly why: string;
|
|
57
|
-
readonly about?: TaskRef;
|
|
58
|
-
readonly aboutSha?: string;
|
|
59
|
-
readonly finished?: boolean;
|
|
60
|
-
readonly inputSha?: string;
|
|
61
|
-
readonly inputs?: string;
|
|
62
|
-
readonly change?: TextChange;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Where a workflow's list last put a task: on one of its lines, or among the items it says no run should start on, with
|
|
67
|
-
* the reason (`label`) and what it waits for (`on`).
|
|
68
|
-
*/
|
|
69
|
-
export type Listed =
|
|
70
|
-
| { readonly kind: 'line'; readonly label: string }
|
|
71
|
-
| { readonly kind: 'wait'; readonly label: string; readonly on: string };
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* WHERE A TASK'S NOTES LEAVE IT (`tasks.ts`, where the rule is written down): the newest of its outcomes, its blocks and
|
|
75
|
-
* its returns to the queue decides. `removed`: its workflow no longer has the item.
|
|
76
|
-
*/
|
|
77
|
-
export type NotedStatus = 'queued' | 'blocked' | 'done' | 'removed';
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* THE KIND THE ENGINE WRITES WHEN A RUN ON A TASK FINDS NO AGENT IT CAN CLAIM (`steps.ts` `claimAgentsOrEnd`), or holds one
|
|
81
|
-
* while the agents can no longer be had (`beforeAgentCall`): its task goes to the back of its queue, marked as needing an
|
|
82
|
-
* agent, with why in words, and the run ends. Alex, 2026-11-20: "if a workflow run is paused because it needs an agent it
|
|
83
|
-
* should probably go to the back of the queue and the task gets marked for needing an agent such that the workflow
|
|
84
|
-
* dequeuing logic can skip over functions which need an agent when the agentic budget is zero." And 2026-11-21, of runs
|
|
85
|
-
* waiting for agents in use: "we mark the task as needing an agent and put it back so the next one can start."
|
|
86
|
-
*/
|
|
87
|
-
export const NEEDS_AN_AGENT = 'needs an agent';
|
|
88
|
-
/** The kind the engine writes on a marked task once a run on it took an agent: its mark has done its work, so it clears. */
|
|
89
|
-
export const AGENT_TAKEN = 'a run took an agent for it';
|
|
90
|
-
/** What cleared a mark until 2026-11-22, when an agent took an agent step rather than a run claiming one: read on old notes. */
|
|
91
|
-
export const AGENT_STEP_RAN = 'an agent step ran';
|
|
92
|
-
|
|
93
|
-
/** The note kinds a status is read from, and what each leaves a task as. A run that stood down wrote no such note. */
|
|
94
|
-
export const STATUS_KINDS: Readonly<Record<string, NotedStatus>> = {
|
|
95
|
-
queued: 'queued', unblocked: 'queued', 'listed again': 'queued', blocked: 'blocked', removed: 'removed', [NEEDS_AN_AGENT]: 'queued',
|
|
96
|
-
// Kinds written before 2026-11-19, read as what they did: each put its task back in its queue, or held it out.
|
|
97
|
-
reopened: 'queued', 'new input': 'queued', resumed: 'queued', released: 'queued', held: 'blocked', 'waits on': 'blocked',
|
|
98
|
-
};
|
|
99
|
-
/** The kinds after which a task's count of failed tries starts again: every return to the queue but a lapsed block's. */
|
|
100
|
-
export const TRIES_START_AGAIN_KINDS: ReadonlyArray<string> = ['queued', 'reopened', 'new input', 'resumed', 'released'];
|
|
101
|
-
/** The outcome of a run that stood down for its workflow's limits: no agent was called, so it is no try and no status. */
|
|
102
|
-
export const STOOD_DOWN_OUTCOME = 'stood down';
|
|
103
|
-
/** The kind a reading of its workflow's list writes on a task it holds again: back in its queue, its failed tries still counted. */
|
|
104
|
-
export const LISTED_AGAIN = 'listed again';
|
|
105
|
-
/** The kind the reorder call writes: its task goes ahead of the queue until a run takes it. */
|
|
106
|
-
export const MOVED_TO_FRONT = 'moved to front';
|
|
107
|
-
/** Why a task blocked for nothing new went back to its queue: the lapse of that block (`tasks.ts` `blockLapsed`). */
|
|
108
|
-
export const UNBLOCKED_INPUTS_CHANGED = 'something new since its last failed try';
|
|
109
|
-
|
|
110
|
-
/** A task as its queue reads it, from one query: no note is read in code. */
|
|
111
|
-
export interface TaskState {
|
|
112
|
-
readonly id: number;
|
|
113
|
-
readonly ref: TaskRef;
|
|
114
|
-
readonly listed: Listed | null;
|
|
115
|
-
readonly status: NotedStatus;
|
|
116
|
-
/** Why, in the words of the note that left it there; none for a task no note has moved. */
|
|
117
|
-
readonly why: string | null;
|
|
118
|
-
/** The kind of that note; none for a task no note has moved. */
|
|
119
|
-
readonly kind: string | null;
|
|
120
|
-
/** When it came to that status, unix seconds: its note's time, or when it was made. */
|
|
121
|
-
readonly since: number;
|
|
122
|
-
/** That note's id: what orders two tasks of one moment. 0 with none. */
|
|
123
|
-
readonly note: number;
|
|
124
|
-
/**
|
|
125
|
-
* ITS PLACE IN ITS QUEUE: when it entered it, unix seconds, and that note's id (0 with none), what `tasks.ts` `queueOrder`
|
|
126
|
-
* sorts by. The note that put it there, or when it was made; a block for nothing new and that block's lapse are no
|
|
127
|
-
* entry, so a task whose block lapsed is back at the place it held before it, and a blocked task holds that place for
|
|
128
|
-
* when it lapses.
|
|
129
|
-
*
|
|
130
|
-
* Why (2026-11-21): a lapse counted as entering the queue, so the 112 Decompile tasks a new answer revision reached went
|
|
131
|
-
* from the places their last failed tries gave them, some days old, to the back of 803 queued, about 85 hours away.
|
|
132
|
-
*/
|
|
133
|
-
readonly entered: { readonly at: number; readonly note: number };
|
|
134
|
-
/** The id of its `moved to front` note written since it came to that status; none otherwise. */
|
|
135
|
-
readonly front: number | null;
|
|
136
|
-
/** Failed tries since its count last started again. */
|
|
137
|
-
readonly tries: number;
|
|
138
|
-
/** The fingerprint of its inputs that note recorded (an outcome's, a block's); none where it recorded none. */
|
|
139
|
-
readonly inputs: string | null;
|
|
140
|
-
/** The other task that note is about: the one a blocked task waits on. */
|
|
141
|
-
readonly about: TaskRef | null;
|
|
142
|
-
/** Whether a step or a person put it back in its queue (`TRIES_START_AGAIN_KINDS`), and its final check has not passed since. */
|
|
143
|
-
readonly returned: boolean;
|
|
144
|
-
/** Notes on it that changed its text: what the flipping rule reads only where there are enough to flip. */
|
|
145
|
-
readonly changes: number;
|
|
146
|
-
/**
|
|
147
|
-
* WHY IT NEEDS AN AGENT, from its newest `needs an agent` note, while that mark stands; none otherwise. Something new from
|
|
148
|
-
* outside its workflow clears it (a return to its queue, a move to the front, any note by a person or another workflow),
|
|
149
|
-
* and so do a run on it that took an agent and its final check passing (`AGENT_TAKEN`, a finished outcome).
|
|
150
|
-
*/
|
|
151
|
-
readonly needsAgent: string | null;
|
|
152
|
-
/**
|
|
153
|
-
* THE FINGERPRINT ITS NEWEST RUN LEFT IT WITH, from that run's outcome, one that stood down included; none where no run
|
|
154
|
-
* has ended on it, its outcome recorded none, or a note has brought it new input since (`NewNote.inputSha`). What a Pick
|
|
155
|
-
* reads to pass over a task nothing new has reached since its last run while no agent can be had (`tasks.ts`
|
|
156
|
-
* `passedOverWithoutAnAgent`).
|
|
157
|
-
*/
|
|
158
|
-
readonly lastRunInputs: string | null;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/** How many of a workflow's tasks stood in one status from `at` on, unix seconds. */
|
|
162
|
-
export interface QueueCount {
|
|
163
|
-
readonly at: number;
|
|
164
|
-
readonly workflow: string;
|
|
165
|
-
readonly bucket: string;
|
|
166
|
-
readonly tasks: number;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/** What a reading of a workflow's list changed. */
|
|
170
|
-
export interface ListingRecorded {
|
|
171
|
-
/** Whether it put any task in the queue: one new to the list, or one it lists again. */
|
|
172
|
-
readonly fresh: boolean;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
export interface TaskStore {
|
|
176
|
-
/**
|
|
177
|
-
* Appends notes in one transaction, in order; each one's id, or null for an outcome a run already has (a resumed run ends
|
|
178
|
-
* again, and keeps its first). Fails when the store cannot write.
|
|
179
|
-
*/
|
|
180
|
-
readonly append: (notes: ReadonlyArray<NewNote>) => Effect.Effect<ReadonlyArray<number | null>, StorageError>;
|
|
181
|
-
/**
|
|
182
|
-
* In one transaction: appends a run's outcome on its task; where the run's step blocked it, a `blocked` note after it;
|
|
183
|
-
* and, when the outcome is new and finished, a `queued` note on every task blocked waiting on it. Returns whether the
|
|
184
|
-
* outcome was new and the tasks returned to their queues.
|
|
185
|
-
*/
|
|
186
|
-
readonly appendOutcome: (r: {
|
|
187
|
-
readonly task: TaskRef; readonly by: NoteBy; readonly why: string; readonly finished: boolean; readonly inputs: string | null;
|
|
188
|
-
/** Why the run's step blocked the task, where it did. */
|
|
189
|
-
readonly blocked: string | null;
|
|
190
|
-
readonly resumedWhy: (waiter: TaskRef) => string;
|
|
191
|
-
}) => Effect.Effect<{ readonly appended: boolean; readonly resumed: ReadonlyArray<TaskRef> }, StorageError>;
|
|
192
|
-
/**
|
|
193
|
-
* WHERE A WORKFLOW'S LIST PUTS EACH OF ITS ITEMS NOW, replacing the last listing in one transaction. `everyItem` says
|
|
194
|
-
* which kind of list it is (`steps.ts` `WorkflowDeclaration`):
|
|
195
|
-
*
|
|
196
|
-
* every item (`items`) a task is made for each; one whose item left the list gets a `removed` note, and one listed
|
|
197
|
-
* again a `listed again` note, which puts it in the queue. No status moves otherwise.
|
|
198
|
-
* work left (`pending`) an item off the list is its workflow's task only while it is done, or once a step or a
|
|
199
|
-
* person has put it back in the queue, until it finishes. One listed again after
|
|
200
|
-
* it left, or listed as work while done (by a list read after it finished), gets a
|
|
201
|
-
* `listed again` note, which puts it in the queue.
|
|
202
|
-
*/
|
|
203
|
-
readonly recordListing: (r: {
|
|
204
|
-
readonly workflow: string; readonly listed: ReadonlyArray<{ readonly item: string; readonly listed: Listed }>;
|
|
205
|
-
readonly everyItem: boolean;
|
|
206
|
-
/** When the list was read, unix seconds. */
|
|
207
|
-
readonly readAt: number;
|
|
208
|
-
readonly by: NoteBy;
|
|
209
|
-
}) => Effect.Effect<ListingRecorded, StorageError>;
|
|
210
|
-
/**
|
|
211
|
-
* A workflow's tasks as their notes leave them. Only those that are its own now: on its list; or done; or put back in its
|
|
212
|
-
* queue by a step or a person and not finished since, whatever its list says; never one
|
|
213
|
-
* `removed`.
|
|
214
|
-
*/
|
|
215
|
-
readonly statesOf: (workflow: string) => Effect.Effect<ReadonlyArray<TaskState>, StorageError>;
|
|
216
|
-
/** One task as its notes leave it, its workflow's own now or not; none for a task no workflow has named. */
|
|
217
|
-
readonly state: (task: TaskRef) => Effect.Effect<TaskState | null, StorageError>;
|
|
218
|
-
/** A task's notes, oldest first. */
|
|
219
|
-
readonly notes: (task: TaskRef) => Effect.Effect<ReadonlyArray<TaskNote>, StorageError>;
|
|
220
|
-
/** A task's stable id; null for one no workflow has named yet. */
|
|
221
|
-
readonly taskId: (task: TaskRef) => Effect.Effect<number | null, StorageError>;
|
|
222
|
-
/** Records each queue's counts as they are `at`, a count only where it differs from the last recorded for it. */
|
|
223
|
-
readonly recordQueueCounts: (r: { readonly at: number; readonly counts: ReadonlyArray<Omit<QueueCount, 'at'>> }) => Effect.Effect<void, StorageError>;
|
|
224
|
-
/** Each count recorded since `since`, and for each queue and status the last recorded before it, oldest first. */
|
|
225
|
-
readonly queueCountsSince: (since: number) => Effect.Effect<ReadonlyArray<QueueCount>, StorageError>;
|
|
226
|
-
/** Whether the store can be written: false in a test that named no store. */
|
|
227
|
-
readonly writable: () => boolean;
|
|
228
|
-
/**
|
|
229
|
-
* DELETES A WORKFLOW'S TASKS THAT ARE ITS RUNS (`steps.ts` `tasksAreRuns`), with their notes, where the task's newest note is
|
|
230
|
-
* before `before`, its item (its run) is none of `keepItems`, it is none of the workflow's `keepNewest` newest such tasks,
|
|
231
|
-
* and no other task's note names it. Only for such a workflow:
|
|
232
|
-
* an item's task is the work's state, never deleted by retention (`retention.ts`). How many tasks and notes went.
|
|
233
|
-
*/
|
|
234
|
-
readonly deleteRunTasksEndedBefore: (r: { readonly workflow: string; readonly before: number; readonly keepItems: ReadonlyArray<string>; readonly keepNewest: number }) => Effect.Effect<{ readonly tasks: number; readonly notes: number }, StorageError>;
|
|
235
|
-
}
|