fwdloop 0.12.0 → 0.13.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/bin/fwdloop +136 -21
- package/package.json +1 -1
- package/src/ask.js +3 -0
- package/src/authoring.js +101 -13
- package/src/books.js +23 -2
- package/src/canrun.js +36 -0
- package/src/config.js +2 -1
- package/src/declaration.js +72 -2
- package/src/drafter.js +41 -3
- package/src/draftspend.js +70 -0
- package/src/flow.js +43 -0
- package/src/liveness.js +1 -1
- package/src/model-step.js +30 -4
- package/src/monthly.js +58 -13
- package/src/panel/author.js +482 -0
- package/src/panel/authorcard.js +297 -0
- package/src/panel/authorflows.js +312 -0
- package/src/panel/authorresume.js +149 -0
- package/src/panel/authorstart.js +257 -0
- package/src/panel/authorvalues.js +110 -0
- package/src/panel/data.js +228 -34
- package/src/panel/index.html +1745 -127
- package/src/panel/resume.js +6 -8
- package/src/panel/server.js +119 -119
- package/src/panel/settings.js +7 -5
- package/src/panel/spawn.js +77 -0
- package/src/provider.js +12 -17
- package/src/runner.js +639 -85
- package/src/runvalues.js +178 -0
- package/src/send.js +10 -3
- package/src/setup.js +120 -0
- package/types/authoring.d.ts +24 -2
- package/types/books.d.ts +14 -2
- package/types/canrun.d.ts +32 -0
- package/types/config.d.ts +1 -0
- package/types/declaration.d.ts +9 -1
- package/types/drafter.d.ts +15 -1
- package/types/draftspend.d.ts +21 -0
- package/types/flow.d.ts +23 -0
- package/types/liveness.d.ts +2 -2
- package/types/model-step.d.ts +3 -1
- package/types/monthly.d.ts +21 -0
- package/types/panel/author.d.ts +335 -0
- package/types/panel/authorcard.d.ts +120 -0
- package/types/panel/authorflows.d.ts +175 -0
- package/types/panel/authorresume.d.ts +32 -0
- package/types/panel/authorstart.d.ts +115 -0
- package/types/panel/authorvalues.d.ts +62 -0
- package/types/panel/data.d.ts +103 -12
- package/types/panel/server.d.ts +11 -33
- package/types/panel/spawn.d.ts +30 -0
- package/types/provider.d.ts +6 -9
- package/types/runner.d.ts +120 -5
- package/types/runvalues.d.ts +97 -0
- package/types/send.d.ts +5 -1
- package/types/setup.d.ts +83 -0
package/types/monthly.d.ts
CHANGED
|
@@ -46,6 +46,27 @@ export function spendSummary(opts?: {
|
|
|
46
46
|
undatedRows: number;
|
|
47
47
|
preM4dRunsNotCounted: boolean;
|
|
48
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* Read-only: would a run holding `capUsd` fit this month? The same numbers `claimHold` decides on, but no hold row and no settle is
|
|
51
|
+
* written — it is what the panel's note under Cap shows. Throws ConfigError when config.json is broken.
|
|
52
|
+
* @param {{ capUsd: number, home?: string, now?: () => number }} a
|
|
53
|
+
* @returns {Claim}
|
|
54
|
+
*/
|
|
55
|
+
export function checkMonthlyRoom({ capUsd, home, now }: {
|
|
56
|
+
capUsd: number;
|
|
57
|
+
home?: string;
|
|
58
|
+
now?: () => number;
|
|
59
|
+
}): Claim;
|
|
60
|
+
/**
|
|
61
|
+
* The short line under the Cap box (M4e amendment 4 item 1), from the same room: `needs $0.50 ($0.10 left monthly)` (red) when the
|
|
62
|
+
* cap does not fit, `$4.90 left monthly` when it does; '' when no limit is set. Money is never rounded down to look like it fits.
|
|
63
|
+
* @param {Claim} claim
|
|
64
|
+
* @returns {{ text: string, red: boolean }}
|
|
65
|
+
*/
|
|
66
|
+
export function monthlyNote(claim: Claim): {
|
|
67
|
+
text: string;
|
|
68
|
+
red: boolean;
|
|
69
|
+
};
|
|
49
70
|
/**
|
|
50
71
|
* @typedef {object} Claim
|
|
51
72
|
* @property {boolean} ok the hold fits (or no limit is set)
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {{ root: string, home?: string, skipMonthly?: boolean, loadEnv: () => { ok: boolean, env: Record<string, string|undefined>, refusal: string|null }, bin?: string }} opts
|
|
3
|
+
* `loadEnv` is the keys-file door (`keysForDoor`): called before EVERY spawn and every reply that quotes a log, so editing
|
|
4
|
+
* the file needs no restart. Its `env` is BOTH the child's spawn env AND the scrub list (POC (a), M4d wiring rule).
|
|
5
|
+
*/
|
|
6
|
+
export function createAuthor(opts: {
|
|
7
|
+
root: string;
|
|
8
|
+
home?: string;
|
|
9
|
+
skipMonthly?: boolean;
|
|
10
|
+
loadEnv: () => {
|
|
11
|
+
ok: boolean;
|
|
12
|
+
env: Record<string, string | undefined>;
|
|
13
|
+
refusal: string | null;
|
|
14
|
+
};
|
|
15
|
+
bin?: string;
|
|
16
|
+
}): {
|
|
17
|
+
flows: () => {
|
|
18
|
+
status: number;
|
|
19
|
+
body: {
|
|
20
|
+
ok: boolean;
|
|
21
|
+
flows: never[];
|
|
22
|
+
leftThisMonth?: undefined;
|
|
23
|
+
};
|
|
24
|
+
} | {
|
|
25
|
+
status: number;
|
|
26
|
+
body: {
|
|
27
|
+
ok: boolean;
|
|
28
|
+
flows: {
|
|
29
|
+
values: {
|
|
30
|
+
capUsd: number;
|
|
31
|
+
destination: string | null;
|
|
32
|
+
askWaits: Record<string, string>;
|
|
33
|
+
};
|
|
34
|
+
jobLines: any;
|
|
35
|
+
hasSend: boolean;
|
|
36
|
+
capFloorUsd: any;
|
|
37
|
+
floorText: string;
|
|
38
|
+
flow: string;
|
|
39
|
+
capUsd: any;
|
|
40
|
+
roles: any;
|
|
41
|
+
nextRunId: string;
|
|
42
|
+
lastRunId: string | null;
|
|
43
|
+
lastSources: Record<string, string>;
|
|
44
|
+
leftThisMonth: any;
|
|
45
|
+
runs: {
|
|
46
|
+
sources: Record<string, string>;
|
|
47
|
+
values: {
|
|
48
|
+
capUsd: number;
|
|
49
|
+
destination: string | null;
|
|
50
|
+
askWaits: Record<string, string>;
|
|
51
|
+
};
|
|
52
|
+
runId: string;
|
|
53
|
+
}[];
|
|
54
|
+
stats: {
|
|
55
|
+
steps: any;
|
|
56
|
+
asks: number;
|
|
57
|
+
green: number;
|
|
58
|
+
notGreen: number;
|
|
59
|
+
avgSpendUsd: number | null;
|
|
60
|
+
avgWallMs: number | null;
|
|
61
|
+
};
|
|
62
|
+
}[];
|
|
63
|
+
leftThisMonth: {
|
|
64
|
+
limitUsd: null;
|
|
65
|
+
leftUsd: null;
|
|
66
|
+
atLeast: boolean;
|
|
67
|
+
say: string;
|
|
68
|
+
} | {
|
|
69
|
+
limitUsd: any;
|
|
70
|
+
leftUsd: number;
|
|
71
|
+
atLeast: any;
|
|
72
|
+
say: string;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
runAgain: (flow: string | null, runId: string | null) => {
|
|
77
|
+
status: any;
|
|
78
|
+
body: {
|
|
79
|
+
ok: boolean;
|
|
80
|
+
refused: string;
|
|
81
|
+
say: any;
|
|
82
|
+
};
|
|
83
|
+
} | {
|
|
84
|
+
status: number;
|
|
85
|
+
body: {
|
|
86
|
+
ok: boolean;
|
|
87
|
+
flow: {
|
|
88
|
+
values: {
|
|
89
|
+
capUsd: number;
|
|
90
|
+
destination: string | null;
|
|
91
|
+
askWaits: Record<string, string>;
|
|
92
|
+
};
|
|
93
|
+
jobLines: any;
|
|
94
|
+
hasSend: boolean;
|
|
95
|
+
capFloorUsd: any;
|
|
96
|
+
floorText: string;
|
|
97
|
+
flow: string;
|
|
98
|
+
capUsd: any;
|
|
99
|
+
roles: any;
|
|
100
|
+
nextRunId: string;
|
|
101
|
+
lastRunId: string | null;
|
|
102
|
+
lastSources: Record<string, string>;
|
|
103
|
+
leftThisMonth: any;
|
|
104
|
+
runs: {
|
|
105
|
+
sources: Record<string, string>;
|
|
106
|
+
values: {
|
|
107
|
+
capUsd: number;
|
|
108
|
+
destination: string | null;
|
|
109
|
+
askWaits: Record<string, string>;
|
|
110
|
+
};
|
|
111
|
+
runId: string;
|
|
112
|
+
}[];
|
|
113
|
+
stats: {
|
|
114
|
+
steps: any;
|
|
115
|
+
asks: number;
|
|
116
|
+
green: number;
|
|
117
|
+
notGreen: number;
|
|
118
|
+
avgSpendUsd: number | null;
|
|
119
|
+
avgWallMs: number | null;
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
pick: {
|
|
123
|
+
sources: Record<string, string>;
|
|
124
|
+
values: {
|
|
125
|
+
capUsd: number;
|
|
126
|
+
destination: string | null;
|
|
127
|
+
askWaits: Record<string, string>;
|
|
128
|
+
};
|
|
129
|
+
runId: string;
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
run: (body: any) => {
|
|
134
|
+
status: any;
|
|
135
|
+
body: any;
|
|
136
|
+
};
|
|
137
|
+
runPrepare: (body: any) => {
|
|
138
|
+
status: any;
|
|
139
|
+
body: any;
|
|
140
|
+
};
|
|
141
|
+
resumePrepare: (body: any) => any;
|
|
142
|
+
resumeForm: (flow: string | null, runId: string | null) => {
|
|
143
|
+
status: any;
|
|
144
|
+
body: any;
|
|
145
|
+
};
|
|
146
|
+
resume: (body: any) => any;
|
|
147
|
+
/**
|
|
148
|
+
* `GET /api/author/monthly-check?cap=<usd>`: the note under Cap, one read-only check. `{ text, red }` is what to show (red =
|
|
149
|
+
* the cap does not fit this month); `floorUsd` is the smallest cap that funds one round of a model step, for the page's
|
|
150
|
+
* `needs at least $X per run` line. A cap that is not a number above 0 gets no note. Never spends, never writes.
|
|
151
|
+
* @param {unknown} cap @param {string|null} [spent] what a resumed run has already spent (amendment 4 item 4)
|
|
152
|
+
*/
|
|
153
|
+
monthlyCheck(cap: unknown, spent?: string | null): {
|
|
154
|
+
status: number;
|
|
155
|
+
body: {
|
|
156
|
+
ok: boolean;
|
|
157
|
+
text: string;
|
|
158
|
+
red: boolean;
|
|
159
|
+
floorUsd: any;
|
|
160
|
+
floorText: string;
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
/** `GET /api/author/start/:startId`: the start's phase, read from its files. @param {string} id */
|
|
164
|
+
startGet(id: string): {
|
|
165
|
+
status: number;
|
|
166
|
+
body: {
|
|
167
|
+
ok: boolean;
|
|
168
|
+
refused: string;
|
|
169
|
+
};
|
|
170
|
+
} | {
|
|
171
|
+
status: number;
|
|
172
|
+
body: {
|
|
173
|
+
phase: string;
|
|
174
|
+
startId: string;
|
|
175
|
+
kind: any;
|
|
176
|
+
flow: any;
|
|
177
|
+
runId: any;
|
|
178
|
+
ok: boolean;
|
|
179
|
+
refused?: undefined;
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
/** `POST /api/author/start/:startId/clear`: dismiss a refused start. @param {string} id */
|
|
183
|
+
startClear(id: string): {
|
|
184
|
+
status: number;
|
|
185
|
+
body: {
|
|
186
|
+
ok: boolean;
|
|
187
|
+
refused: string;
|
|
188
|
+
say?: undefined;
|
|
189
|
+
startId?: undefined;
|
|
190
|
+
};
|
|
191
|
+
} | {
|
|
192
|
+
status: number;
|
|
193
|
+
body: {
|
|
194
|
+
ok: boolean;
|
|
195
|
+
refused: string;
|
|
196
|
+
say: string;
|
|
197
|
+
startId?: undefined;
|
|
198
|
+
};
|
|
199
|
+
} | {
|
|
200
|
+
status: number;
|
|
201
|
+
body: {
|
|
202
|
+
ok: boolean;
|
|
203
|
+
startId: string;
|
|
204
|
+
refused?: undefined;
|
|
205
|
+
say?: undefined;
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
/**
|
|
209
|
+
* `POST /api/author/draft`: card -> $0 checks -> one detached `fwdloop draft` -> 202 { draftId }. Nothing is created
|
|
210
|
+
* on a refusal. Synchronous on purpose (see the file header).
|
|
211
|
+
* @param {any} body
|
|
212
|
+
* @returns {{ status: number, body: any }}
|
|
213
|
+
*/
|
|
214
|
+
start(body: any): {
|
|
215
|
+
status: number;
|
|
216
|
+
body: any;
|
|
217
|
+
};
|
|
218
|
+
/**
|
|
219
|
+
* `POST /api/author/:id/sign-prepare` (the first click of "Sign & run"): what the human is about to sign — the readout, the
|
|
220
|
+
* hash, the flow name, the cap. GREEN drafts only. Writes nothing: the page holds the hash it was shown, and `sign`
|
|
221
|
+
* re-reads everything from disk.
|
|
222
|
+
* @param {string} id
|
|
223
|
+
*/
|
|
224
|
+
signPrepare(id: string): any;
|
|
225
|
+
/**
|
|
226
|
+
* `POST /api/author/:id/sign` body `{ hash, runId? }`: sign and start the run — only when the draft is green and
|
|
227
|
+
* not abandoned/signed and the hash is the one on disk (M4e amendment 2: the second click, no typed name). Then the SAME `signDraft` as `fwdloop sign`, `signed.json`, and the ONE run start. Any mismatch
|
|
228
|
+
* refuses by name, signs nothing, writes nothing, spends nothing. Fully synchronous (no await between the checks and the
|
|
229
|
+
* writes), so two sign POSTs together sign once: the second reads the first's `signed.json` and is refused.
|
|
230
|
+
* @param {string} id @param {any} body
|
|
231
|
+
*/
|
|
232
|
+
sign(id: string, body: any): any;
|
|
233
|
+
/**
|
|
234
|
+
* `POST /api/author/:id/revise` body `{ text }` (M4e amendment 3 item 3, bareloop's "Ask for a change"): the human's note on a GREEN
|
|
235
|
+
* plan -> $0 checks -> one detached `fwdloop draft --revise-from <current plan> --note note-<n>.txt --out draft-<n>` -> 202. Up to
|
|
236
|
+
* MAX_CHANGES per draft; a refusal makes no model call and writes nothing. The new plan is read back from `draft-<n>/` like any
|
|
237
|
+
* draft; the old plan stays signable until a newer green one exists. Synchronous, like `start`.
|
|
238
|
+
* @param {string} id @param {any} body
|
|
239
|
+
*/
|
|
240
|
+
revise(id: string, body: any): {
|
|
241
|
+
status: number;
|
|
242
|
+
body: {
|
|
243
|
+
ok: boolean;
|
|
244
|
+
refused: string;
|
|
245
|
+
say: string;
|
|
246
|
+
draftId?: undefined;
|
|
247
|
+
n?: undefined;
|
|
248
|
+
};
|
|
249
|
+
} | {
|
|
250
|
+
status: number;
|
|
251
|
+
body: {
|
|
252
|
+
ok: boolean;
|
|
253
|
+
refused: string;
|
|
254
|
+
say?: undefined;
|
|
255
|
+
draftId?: undefined;
|
|
256
|
+
n?: undefined;
|
|
257
|
+
};
|
|
258
|
+
} | {
|
|
259
|
+
status: number;
|
|
260
|
+
body: {
|
|
261
|
+
ok: boolean;
|
|
262
|
+
refused: string;
|
|
263
|
+
draftId: string;
|
|
264
|
+
say: string;
|
|
265
|
+
n?: undefined;
|
|
266
|
+
};
|
|
267
|
+
} | {
|
|
268
|
+
status: number;
|
|
269
|
+
body: {
|
|
270
|
+
ok: boolean;
|
|
271
|
+
draftId: string;
|
|
272
|
+
n: number;
|
|
273
|
+
refused?: undefined;
|
|
274
|
+
say?: undefined;
|
|
275
|
+
};
|
|
276
|
+
};
|
|
277
|
+
/**
|
|
278
|
+
* `GET /api/author/live`: the newest draft that is not abandoned or signed, and the newest panel start the human has not cleared
|
|
279
|
+
* (`starting` or `refused`; a `started` one is in Runs) — read from files, never memory.
|
|
280
|
+
*/
|
|
281
|
+
live(): {
|
|
282
|
+
status: number;
|
|
283
|
+
body: {
|
|
284
|
+
ok: boolean;
|
|
285
|
+
draft: any;
|
|
286
|
+
start: {
|
|
287
|
+
phase: string;
|
|
288
|
+
startId: string;
|
|
289
|
+
kind: any;
|
|
290
|
+
flow: any;
|
|
291
|
+
runId: any;
|
|
292
|
+
} | null;
|
|
293
|
+
};
|
|
294
|
+
};
|
|
295
|
+
/** `GET /api/author/:id`. @param {string} id */
|
|
296
|
+
get(id: string): {
|
|
297
|
+
status: number;
|
|
298
|
+
body: any;
|
|
299
|
+
};
|
|
300
|
+
/**
|
|
301
|
+
* `POST /api/author/:id/abandon`: stop the child (by its recorded pid, only after `isFwdloopAlive` says it is ours),
|
|
302
|
+
* confirm it is gone, then write `abandoned.json`. No further model call; the spend already booked stays booked.
|
|
303
|
+
* @param {string} id
|
|
304
|
+
*/
|
|
305
|
+
abandon(id: string): Promise<{
|
|
306
|
+
status: number;
|
|
307
|
+
body: {
|
|
308
|
+
ok: boolean;
|
|
309
|
+
refused: string;
|
|
310
|
+
say?: undefined;
|
|
311
|
+
phase?: undefined;
|
|
312
|
+
stopped?: undefined;
|
|
313
|
+
};
|
|
314
|
+
} | {
|
|
315
|
+
status: number;
|
|
316
|
+
body: {
|
|
317
|
+
ok: boolean;
|
|
318
|
+
refused: string;
|
|
319
|
+
say: string;
|
|
320
|
+
phase?: undefined;
|
|
321
|
+
stopped?: undefined;
|
|
322
|
+
};
|
|
323
|
+
} | {
|
|
324
|
+
status: number;
|
|
325
|
+
body: {
|
|
326
|
+
ok: boolean;
|
|
327
|
+
phase: string;
|
|
328
|
+
stopped: boolean;
|
|
329
|
+
refused?: undefined;
|
|
330
|
+
say?: undefined;
|
|
331
|
+
};
|
|
332
|
+
}>;
|
|
333
|
+
};
|
|
334
|
+
/** Up to 2 changes per draft (amendment 3 item 3); a change is used once its `draft-<n>/` exists (a refusal at $0 makes none). */
|
|
335
|
+
export const MAX_CHANGES: 2;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The job box (M4e amendment 2 item 1), a pure function of its text. One non-empty line is one step; a line starting with `~` is a
|
|
3
|
+
* guardrail of the step above; `Ask:` / `Ask 2h:` (case-insensitive) is an ask with the card's wait / its own wait; empty lines are
|
|
4
|
+
* dropped. A refusal is `{ line, say }`, `line` = the 1-based line of the box (blank lines count, so the human can find it).
|
|
5
|
+
* @param {string} text
|
|
6
|
+
* @returns {{ steps: { n: number, text: string, ask: null | { wait: string|null, question: string }, guardrails: string[] }[], refusals: { line: number, say: string }[] }}
|
|
7
|
+
*/
|
|
8
|
+
export function parseJobBox(text: string): {
|
|
9
|
+
steps: {
|
|
10
|
+
n: number;
|
|
11
|
+
text: string;
|
|
12
|
+
ask: null | {
|
|
13
|
+
wait: string | null;
|
|
14
|
+
question: string;
|
|
15
|
+
};
|
|
16
|
+
guardrails: string[];
|
|
17
|
+
}[];
|
|
18
|
+
refusals: {
|
|
19
|
+
line: number;
|
|
20
|
+
say: string;
|
|
21
|
+
}[];
|
|
22
|
+
};
|
|
23
|
+
/** The job file lines (`N. text`, ` guardrail: text`, `N. ask <wait>: question`) for parsed steps; the wait is ALWAYS written out. @param {ReturnType<typeof parseJobBox>['steps']} steps @param {string} askWait */
|
|
24
|
+
export function jobFileLines(steps: ReturnType<typeof parseJobBox>["steps"], askWait: string): string[];
|
|
25
|
+
/**
|
|
26
|
+
* The inputs box (amendment 2 item 2): one `name: path` per non-empty line, split at the FIRST colon. `line` is the line's own number
|
|
27
|
+
* as the box shows it (empty lines are skipped and not numbered). A line with no colon is flagged `noColon`.
|
|
28
|
+
* @param {string} text
|
|
29
|
+
* @returns {{ line: number, role: string, path: string, noColon?: true }[]}
|
|
30
|
+
*/
|
|
31
|
+
export function parseInputLines(text: string): {
|
|
32
|
+
line: number;
|
|
33
|
+
role: string;
|
|
34
|
+
path: string;
|
|
35
|
+
noColon?: true;
|
|
36
|
+
}[];
|
|
37
|
+
/**
|
|
38
|
+
* Normalise what the page sent into the typed card (one reader of the request body's shape). Unknown fields are
|
|
39
|
+
* dropped; nothing here judges a value. `inputs` is the inputs box's TEXT (`name: path` per line); `destination` is the folder.
|
|
40
|
+
* @param {any} body
|
|
41
|
+
*/
|
|
42
|
+
export function cardFields(body: any): {
|
|
43
|
+
flowName: string;
|
|
44
|
+
job: string;
|
|
45
|
+
destination: string;
|
|
46
|
+
inputs: string;
|
|
47
|
+
capUsd: any;
|
|
48
|
+
askWait: string;
|
|
49
|
+
};
|
|
50
|
+
/** The Run-a-signed-flow door's rows (a role is fixed by the signed flow): what the page sent, as `{role, path}`. @param {any} v */
|
|
51
|
+
export function runInputRows(v: any): {
|
|
52
|
+
role: string;
|
|
53
|
+
path: string;
|
|
54
|
+
}[];
|
|
55
|
+
/**
|
|
56
|
+
* The prose file text for a card whose fields already passed {@link checkCard}. The job lines come first (the job box's steps as the
|
|
57
|
+
* job file); the arbiter block is built only from the card's own fields. The ONE card -> prose function.
|
|
58
|
+
* @param {ReturnType<typeof cardFields>} card
|
|
59
|
+
* @returns {string}
|
|
60
|
+
*/
|
|
61
|
+
export function cardToProse(card: ReturnType<typeof cardFields>): string;
|
|
62
|
+
/**
|
|
63
|
+
* The $0 check of the input rows, shared by the card (draft door) and the Run-a-signed-flow door: a role and a path on every row,
|
|
64
|
+
* a role shape the signed-text parser accepts and used once, each path a full path to a readable regular file (realpath at the
|
|
65
|
+
* click). Never reads a file's contents. A row from the card's inputs box carries its `line`: its refusal is field `inputs` and its
|
|
66
|
+
* sentence starts "Line N:". A Run-door row has no line: its refusal is field `inputs.<n>`.
|
|
67
|
+
* @param {{role: string, path: string, line?: number, noColon?: true}[]} rows
|
|
68
|
+
* @returns {{field: string, say: string}[]} one refusal per bad row
|
|
69
|
+
*/
|
|
70
|
+
export function checkInputRows(rows: {
|
|
71
|
+
role: string;
|
|
72
|
+
path: string;
|
|
73
|
+
line?: number;
|
|
74
|
+
noColon?: true;
|
|
75
|
+
}[]): {
|
|
76
|
+
field: string;
|
|
77
|
+
say: string;
|
|
78
|
+
}[];
|
|
79
|
+
/**
|
|
80
|
+
* M4e amendment 4 item 2: the smallest per-run cap that funds ONE round of the first model step. The runner halts a step when
|
|
81
|
+
* `spent + ceiling > cap` (`runStepRalph`), and every ordinary (non-ask) step is a model step, so the floor is the runner's own
|
|
82
|
+
* per-round ceiling (`resolveCeilingUsd`) as soon as the job has one such line; a job of only asks spends nothing before its stop.
|
|
83
|
+
* ONE function: the card's Draft check, Sign, and the page's note all read it. Returns 0 when no step needs a round.
|
|
84
|
+
* @param {string} jobText
|
|
85
|
+
*/
|
|
86
|
+
export function capFloorUsd(jobText: string): any;
|
|
87
|
+
/** The floor itself, for a caller that already knows whether the job has a step that is not an ask (a signed flow: any step off an ask line). @param {boolean} hasRoundStep */
|
|
88
|
+
export function capFloorFor(hasRoundStep: boolean): any;
|
|
89
|
+
/** The one sentence for a cap under the floor (red under Cap, and the Draft / sign refusal). @param {number} floorUsd */
|
|
90
|
+
export function capFloorText(floorUsd: number): string;
|
|
91
|
+
/**
|
|
92
|
+
* Amendment 1's destination checks, in ONE place: the New job card and the per-run destination of amendment 5 both ask it. `null` = fine,
|
|
93
|
+
* else the sentence (a folder that is the run folder, a flow folder, the root, `.drafts`, `.starts`, the config folder, a file, a missing
|
|
94
|
+
* folder, a path with a control character). Never overwrite is the send's own rule at write time.
|
|
95
|
+
* @param {string} dest the folder as typed @param {string} root the flows root
|
|
96
|
+
* @returns {string|null}
|
|
97
|
+
*/
|
|
98
|
+
export function destinationRefusal(dest: string, root: string): string | null;
|
|
99
|
+
/**
|
|
100
|
+
* Every $0 check on the card, before any spawn (scope 6). Collects all refusals so the page can name every box.
|
|
101
|
+
* @param {ReturnType<typeof cardFields>} card
|
|
102
|
+
* @param {{ root: string, env?: Record<string, string|undefined> }} ctx `env` = the merged keys env: a key value typed into any box is refused
|
|
103
|
+
* @returns {{ ok: true, prose: string }|{ ok: false, refusals: {field: string, say: string}[] }}
|
|
104
|
+
*/
|
|
105
|
+
export function checkCard(card: ReturnType<typeof cardFields>, { root, env }: {
|
|
106
|
+
root: string;
|
|
107
|
+
env?: Record<string, string | undefined>;
|
|
108
|
+
}): {
|
|
109
|
+
ok: true;
|
|
110
|
+
prose: string;
|
|
111
|
+
} | {
|
|
112
|
+
ok: false;
|
|
113
|
+
refusals: {
|
|
114
|
+
field: string;
|
|
115
|
+
say: string;
|
|
116
|
+
}[];
|
|
117
|
+
};
|
|
118
|
+
/** The heading line the prose files use (flows/job2-m6a-3/prose.txt); the parser matches `/^arbiter guardrails\b/i`. */
|
|
119
|
+
export const ARBITER_HEADING: "Arbiter guardrails (belong to no line; human-signed, tighten-only \u2014 never authored or claimed by the drafter):";
|
|
120
|
+
export function isAskWait(t: string): boolean;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the Run / Resume forms show of a signed flow (read from its own files, never from a model): the job lines as the signed text has them
|
|
3
|
+
* (an ask line carries its question and its wait), the values the open boxes start from, and the cap floor. Amendment 5 item 2: all the rest is dimmed.
|
|
4
|
+
* @param {any} read `readFlow`'s ok result
|
|
5
|
+
*/
|
|
6
|
+
export function formFacts(read: any): {
|
|
7
|
+
values: {
|
|
8
|
+
capUsd: number;
|
|
9
|
+
destination: string | null;
|
|
10
|
+
askWaits: Record<string, string>;
|
|
11
|
+
};
|
|
12
|
+
jobLines: any;
|
|
13
|
+
hasSend: boolean;
|
|
14
|
+
capFloorUsd: any;
|
|
15
|
+
floorText: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* @param {{ root: string, home?: string, skipMonthly?: boolean, loadEnv: () => { ok: boolean, env: Record<string, string|undefined>, refusal: string|null }, starter: ReturnType<typeof import('./authorstart.js').createStarter>, monthlyClaim: (usd: number) => any }} opts
|
|
19
|
+
*/
|
|
20
|
+
export function createFlowsDoor(opts: {
|
|
21
|
+
root: string;
|
|
22
|
+
home?: string;
|
|
23
|
+
skipMonthly?: boolean;
|
|
24
|
+
loadEnv: () => {
|
|
25
|
+
ok: boolean;
|
|
26
|
+
env: Record<string, string | undefined>;
|
|
27
|
+
refusal: string | null;
|
|
28
|
+
};
|
|
29
|
+
starter: ReturnType<typeof import("./authorstart.js").createStarter>;
|
|
30
|
+
monthlyClaim: (usd: number) => any;
|
|
31
|
+
}): {
|
|
32
|
+
/** `GET /api/author/flows`. */
|
|
33
|
+
flows(): {
|
|
34
|
+
status: number;
|
|
35
|
+
body: {
|
|
36
|
+
ok: boolean;
|
|
37
|
+
flows: never[];
|
|
38
|
+
leftThisMonth?: undefined;
|
|
39
|
+
};
|
|
40
|
+
} | {
|
|
41
|
+
status: number;
|
|
42
|
+
body: {
|
|
43
|
+
ok: boolean;
|
|
44
|
+
flows: {
|
|
45
|
+
values: {
|
|
46
|
+
capUsd: number;
|
|
47
|
+
destination: string | null;
|
|
48
|
+
askWaits: Record<string, string>;
|
|
49
|
+
};
|
|
50
|
+
jobLines: any;
|
|
51
|
+
hasSend: boolean;
|
|
52
|
+
capFloorUsd: any;
|
|
53
|
+
floorText: string;
|
|
54
|
+
flow: string;
|
|
55
|
+
capUsd: any;
|
|
56
|
+
roles: any;
|
|
57
|
+
nextRunId: string;
|
|
58
|
+
lastRunId: string | null;
|
|
59
|
+
lastSources: Record<string, string>;
|
|
60
|
+
leftThisMonth: any;
|
|
61
|
+
runs: {
|
|
62
|
+
sources: Record<string, string>;
|
|
63
|
+
values: {
|
|
64
|
+
capUsd: number;
|
|
65
|
+
destination: string | null;
|
|
66
|
+
askWaits: Record<string, string>;
|
|
67
|
+
};
|
|
68
|
+
runId: string;
|
|
69
|
+
}[];
|
|
70
|
+
stats: {
|
|
71
|
+
steps: any;
|
|
72
|
+
asks: number;
|
|
73
|
+
green: number;
|
|
74
|
+
notGreen: number;
|
|
75
|
+
avgSpendUsd: number | null;
|
|
76
|
+
avgWallMs: number | null;
|
|
77
|
+
};
|
|
78
|
+
}[];
|
|
79
|
+
leftThisMonth: {
|
|
80
|
+
limitUsd: null;
|
|
81
|
+
leftUsd: null;
|
|
82
|
+
atLeast: boolean;
|
|
83
|
+
say: string;
|
|
84
|
+
} | {
|
|
85
|
+
limitUsd: any;
|
|
86
|
+
leftUsd: number;
|
|
87
|
+
atLeast: any;
|
|
88
|
+
say: string;
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* `GET /api/author/run-again?flow=&runId=` (amendment 7 item 6): the Signed flow form for ONE run of a signed flow, any outcome, with that
|
|
94
|
+
* run's values and input paths as `pick`. The list's rule (passed run, preflight accepts) does not apply here; a flow the run's own
|
|
95
|
+
* preflight would refuse says why, in the preflight's words. Reads only.
|
|
96
|
+
* @param {string|null} flow @param {string|null} runId
|
|
97
|
+
*/
|
|
98
|
+
runAgain(flow: string | null, runId: string | null): {
|
|
99
|
+
status: any;
|
|
100
|
+
body: {
|
|
101
|
+
ok: boolean;
|
|
102
|
+
refused: string;
|
|
103
|
+
say: any;
|
|
104
|
+
};
|
|
105
|
+
} | {
|
|
106
|
+
status: number;
|
|
107
|
+
body: {
|
|
108
|
+
ok: boolean;
|
|
109
|
+
flow: {
|
|
110
|
+
values: {
|
|
111
|
+
capUsd: number;
|
|
112
|
+
destination: string | null;
|
|
113
|
+
askWaits: Record<string, string>;
|
|
114
|
+
};
|
|
115
|
+
jobLines: any;
|
|
116
|
+
hasSend: boolean;
|
|
117
|
+
capFloorUsd: any;
|
|
118
|
+
floorText: string;
|
|
119
|
+
flow: string;
|
|
120
|
+
capUsd: any;
|
|
121
|
+
roles: any;
|
|
122
|
+
nextRunId: string;
|
|
123
|
+
lastRunId: string | null;
|
|
124
|
+
lastSources: Record<string, string>;
|
|
125
|
+
leftThisMonth: any;
|
|
126
|
+
runs: {
|
|
127
|
+
sources: Record<string, string>;
|
|
128
|
+
values: {
|
|
129
|
+
capUsd: number;
|
|
130
|
+
destination: string | null;
|
|
131
|
+
askWaits: Record<string, string>;
|
|
132
|
+
};
|
|
133
|
+
runId: string;
|
|
134
|
+
}[];
|
|
135
|
+
stats: {
|
|
136
|
+
steps: any;
|
|
137
|
+
asks: number;
|
|
138
|
+
green: number;
|
|
139
|
+
notGreen: number;
|
|
140
|
+
avgSpendUsd: number | null;
|
|
141
|
+
avgWallMs: number | null;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
pick: {
|
|
145
|
+
sources: Record<string, string>;
|
|
146
|
+
values: {
|
|
147
|
+
capUsd: number;
|
|
148
|
+
destination: string | null;
|
|
149
|
+
askWaits: Record<string, string>;
|
|
150
|
+
};
|
|
151
|
+
runId: string;
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* `POST /api/author/run-prepare` (the first click of "Sign & run"): the same $0 checks as `run`, never starts anything and writes nothing.
|
|
157
|
+
* `needsSign` = the Destination, Cap $ or an ask wait differs from the flow's signed value, so the start needs the human's second click
|
|
158
|
+
* carrying `hash` (amendment 5 item 3); false = a plain Run (one click).
|
|
159
|
+
* @param {any} body
|
|
160
|
+
*/
|
|
161
|
+
runPrepare(body: any): {
|
|
162
|
+
status: any;
|
|
163
|
+
body: any;
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* `POST /api/author/run`: $0 checks -> the one start. A refusal names the box, spends $0 and creates nothing. A run whose Destination, Cap $
|
|
167
|
+
* or ask wait differs from the flow's signed values starts only with the `hash` of those values (the human's second click, like page
|
|
168
|
+
* sign): none or a stale one signs nothing and starts nothing. The signed values are written once into the run's own folder first.
|
|
169
|
+
* @param {any} body
|
|
170
|
+
*/
|
|
171
|
+
run(body: any): {
|
|
172
|
+
status: any;
|
|
173
|
+
body: any;
|
|
174
|
+
};
|
|
175
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {{ root: string, loadEnv: () => { ok: boolean, env: Record<string, string|undefined>, refusal: string|null }, monthlyClaim: (usd: number) => any, starter: ReturnType<typeof import('./authorstart.js').createStarter> }} opts
|
|
3
|
+
*/
|
|
4
|
+
export function createResumeDoor(opts: {
|
|
5
|
+
root: string;
|
|
6
|
+
loadEnv: () => {
|
|
7
|
+
ok: boolean;
|
|
8
|
+
env: Record<string, string | undefined>;
|
|
9
|
+
refusal: string | null;
|
|
10
|
+
};
|
|
11
|
+
monthlyClaim: (usd: number) => any;
|
|
12
|
+
starter: ReturnType<typeof import("./authorstart.js").createStarter>;
|
|
13
|
+
}): {
|
|
14
|
+
/**
|
|
15
|
+
* `GET /api/author/resume-form?flow=&runId=`: what the "Resume run-<n>" form shows — the same locating checks as the clicks (a run that is not
|
|
16
|
+
* stopped or cap-halted gets the same refusal), then the values in force (dimmed on the form except the cap), what the run has spent, the
|
|
17
|
+
* job lines as signed and the files it froze. Writes nothing.
|
|
18
|
+
* @param {string|null} flow @param {string|null} runId
|
|
19
|
+
*/
|
|
20
|
+
form(flow: string | null, runId: string | null): {
|
|
21
|
+
status: any;
|
|
22
|
+
body: any;
|
|
23
|
+
};
|
|
24
|
+
/** `POST /api/author/resume-prepare`: the first click. Writes nothing. @param {any} body */
|
|
25
|
+
prepare(body: any): any;
|
|
26
|
+
/**
|
|
27
|
+
* `POST /api/author/resume`: the second click. The hash must be the one the disk gives now (a changed run, a changed cap, a newer version
|
|
28
|
+
* all make it stale); then the new version is written once and the continue is started. Anything else signs nothing, writes nothing.
|
|
29
|
+
* @param {any} body
|
|
30
|
+
*/
|
|
31
|
+
resume(body: any): any;
|
|
32
|
+
};
|