fwdloop 0.12.0 → 0.14.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.
Files changed (62) hide show
  1. package/bin/fwdloop +155 -27
  2. package/package.json +2 -2
  3. package/src/ask.js +3 -0
  4. package/src/authoring.js +135 -16
  5. package/src/books.js +23 -2
  6. package/src/canrun.js +106 -0
  7. package/src/catalogue.json +2 -2
  8. package/src/checked.js +50 -0
  9. package/src/closers.js +112 -91
  10. package/src/config.js +2 -1
  11. package/src/declaration.js +175 -3
  12. package/src/drafter.js +148 -10
  13. package/src/draftspend.js +70 -0
  14. package/src/flow.js +43 -0
  15. package/src/keysfile.js +4 -2
  16. package/src/liveness.js +1 -1
  17. package/src/model-step.js +31 -5
  18. package/src/monthly.js +195 -28
  19. package/src/panel/author.js +638 -0
  20. package/src/panel/authorcard.js +340 -0
  21. package/src/panel/authorflows.js +317 -0
  22. package/src/panel/authorresume.js +149 -0
  23. package/src/panel/authorstart.js +257 -0
  24. package/src/panel/authorvalues.js +110 -0
  25. package/src/panel/data.js +318 -99
  26. package/src/panel/index.html +2000 -330
  27. package/src/panel/resume.js +6 -8
  28. package/src/panel/server.js +122 -119
  29. package/src/panel/settings.js +8 -6
  30. package/src/panel/spawn.js +77 -0
  31. package/src/provider.js +12 -17
  32. package/src/runner.js +707 -104
  33. package/src/runvalues.js +178 -0
  34. package/src/send.js +10 -3
  35. package/src/setup.js +127 -0
  36. package/types/authoring.d.ts +56 -2
  37. package/types/books.d.ts +14 -2
  38. package/types/canrun.d.ts +64 -0
  39. package/types/checked.d.ts +23 -0
  40. package/types/closers.d.ts +47 -28
  41. package/types/config.d.ts +1 -0
  42. package/types/declaration.d.ts +23 -1
  43. package/types/drafter.d.ts +151 -2
  44. package/types/draftspend.d.ts +21 -0
  45. package/types/flow.d.ts +23 -0
  46. package/types/liveness.d.ts +2 -2
  47. package/types/model-step.d.ts +4 -7
  48. package/types/monthly.d.ts +46 -1
  49. package/types/panel/author.d.ts +316 -0
  50. package/types/panel/authorcard.d.ts +142 -0
  51. package/types/panel/authorflows.d.ts +175 -0
  52. package/types/panel/authorresume.d.ts +32 -0
  53. package/types/panel/authorstart.d.ts +115 -0
  54. package/types/panel/authorvalues.d.ts +62 -0
  55. package/types/panel/data.d.ts +105 -63
  56. package/types/panel/server.d.ts +11 -33
  57. package/types/panel/spawn.d.ts +30 -0
  58. package/types/provider.d.ts +6 -9
  59. package/types/runner.d.ts +129 -6
  60. package/types/runvalues.d.ts +97 -0
  61. package/types/send.d.ts +5 -1
  62. package/types/setup.d.ts +77 -0
@@ -0,0 +1,316 @@
1
+ /**
2
+ * @param {{ root: string, home?: string, skipMonthly?: boolean, loadEnv: () => { ok: boolean, env: Record<string, string|undefined>, refusal: string|null }, bin?: string, childRunning?: (dir: string) => boolean }} 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
+ childRunning?: (dir: string) => boolean;
17
+ }): {
18
+ flows: () => {
19
+ status: number;
20
+ body: {
21
+ ok: boolean;
22
+ flows: never[];
23
+ leftThisMonth?: undefined;
24
+ };
25
+ } | {
26
+ status: number;
27
+ body: {
28
+ ok: boolean;
29
+ flows: {
30
+ values: {
31
+ capUsd: number;
32
+ destination: string | null;
33
+ askWaits: Record<string, string>;
34
+ };
35
+ jobLines: any;
36
+ hasSend: boolean;
37
+ capFloorUsd: any;
38
+ floorText: string;
39
+ flow: string;
40
+ capUsd: any;
41
+ roles: any;
42
+ nextRunId: string;
43
+ lastRunId: string | null;
44
+ lastSources: Record<string, string>;
45
+ leftThisMonth: any;
46
+ runs: {
47
+ sources: Record<string, string>;
48
+ values: {
49
+ capUsd: number;
50
+ destination: string | null;
51
+ askWaits: Record<string, string>;
52
+ };
53
+ runId: string;
54
+ }[];
55
+ stats: {
56
+ steps: any;
57
+ asks: number;
58
+ green: number;
59
+ notGreen: number;
60
+ avgSpendUsd: number | null;
61
+ avgWallMs: number | null;
62
+ };
63
+ }[];
64
+ leftThisMonth: {
65
+ limitUsd: null;
66
+ leftUsd: null;
67
+ atLeast: boolean;
68
+ say: string;
69
+ } | {
70
+ limitUsd: any;
71
+ leftUsd: number;
72
+ atLeast: any;
73
+ say: string;
74
+ };
75
+ };
76
+ };
77
+ runAgain: (flow: string | null, runId: string | null) => {
78
+ status: any;
79
+ body: {
80
+ ok: boolean;
81
+ refused: string;
82
+ say: any;
83
+ };
84
+ } | {
85
+ status: number;
86
+ body: {
87
+ ok: boolean;
88
+ flow: {
89
+ values: {
90
+ capUsd: number;
91
+ destination: string | null;
92
+ askWaits: Record<string, string>;
93
+ };
94
+ jobLines: any;
95
+ hasSend: boolean;
96
+ capFloorUsd: any;
97
+ floorText: string;
98
+ flow: string;
99
+ capUsd: any;
100
+ roles: any;
101
+ nextRunId: string;
102
+ lastRunId: string | null;
103
+ lastSources: Record<string, string>;
104
+ leftThisMonth: any;
105
+ runs: {
106
+ sources: Record<string, string>;
107
+ values: {
108
+ capUsd: number;
109
+ destination: string | null;
110
+ askWaits: Record<string, string>;
111
+ };
112
+ runId: string;
113
+ }[];
114
+ stats: {
115
+ steps: any;
116
+ asks: number;
117
+ green: number;
118
+ notGreen: number;
119
+ avgSpendUsd: number | null;
120
+ avgWallMs: number | null;
121
+ };
122
+ };
123
+ pick: {
124
+ sources: Record<string, string>;
125
+ values: {
126
+ capUsd: number;
127
+ destination: string | null;
128
+ askWaits: Record<string, string>;
129
+ };
130
+ runId: string;
131
+ };
132
+ };
133
+ };
134
+ run: (body: any) => {
135
+ status: any;
136
+ body: any;
137
+ };
138
+ runPrepare: (body: any) => {
139
+ status: any;
140
+ body: any;
141
+ };
142
+ resumePrepare: (body: any) => any;
143
+ resumeForm: (flow: string | null, runId: string | null) => {
144
+ status: any;
145
+ body: any;
146
+ };
147
+ resume: (body: any) => any;
148
+ /**
149
+ * `GET /api/author/monthly-check?cap=<usd>`: the note under Cap, one read-only check. `{ text, red }` is what to show (red =
150
+ * the cap does not fit this month); `floorUsd` is the smallest cap that funds one round of a model step, for the page's
151
+ * `needs at least $X per run` line. A cap that is not a number above 0 gets no note. Never spends, never writes.
152
+ * @param {unknown} cap @param {string|null} [spent] what a resumed run has already spent (amendment 4 item 4)
153
+ */
154
+ monthlyCheck(cap: unknown, spent?: string | null): {
155
+ status: number;
156
+ body: {
157
+ ok: boolean;
158
+ text: string;
159
+ red: boolean;
160
+ floorUsd: any;
161
+ floorText: string;
162
+ };
163
+ };
164
+ /** `GET /api/author/start/:startId`: the start's phase, read from its files. @param {string} id */
165
+ startGet(id: string): {
166
+ status: number;
167
+ body: {
168
+ ok: boolean;
169
+ refused: string;
170
+ };
171
+ } | {
172
+ status: number;
173
+ body: {
174
+ phase: string;
175
+ startId: string;
176
+ kind: any;
177
+ flow: any;
178
+ runId: any;
179
+ ok: boolean;
180
+ refused?: undefined;
181
+ };
182
+ };
183
+ /** `POST /api/author/start/:startId/clear`: dismiss a refused start. @param {string} id */
184
+ startClear(id: string): {
185
+ status: number;
186
+ body: {
187
+ ok: boolean;
188
+ refused: string;
189
+ say?: undefined;
190
+ startId?: undefined;
191
+ };
192
+ } | {
193
+ status: number;
194
+ body: {
195
+ ok: boolean;
196
+ refused: string;
197
+ say: string;
198
+ startId?: undefined;
199
+ };
200
+ } | {
201
+ status: number;
202
+ body: {
203
+ ok: boolean;
204
+ startId: string;
205
+ refused?: undefined;
206
+ say?: undefined;
207
+ };
208
+ };
209
+ /**
210
+ * `POST /api/author/draft`: card -> $0 checks -> one detached `fwdloop draft` -> 202 { draftId }. Nothing is created
211
+ * on a refusal. Synchronous on purpose (see the file header).
212
+ * @param {any} body
213
+ * @returns {{ status: number, body: any }}
214
+ */
215
+ start(body: any): {
216
+ status: number;
217
+ body: any;
218
+ };
219
+ /**
220
+ * `POST /api/author/:id/sign-prepare` (the first click of "Sign & run"): what the human is about to sign — the readout, the
221
+ * hash, the flow name, the cap. GREEN drafts only. Writes nothing: the page holds the hash it was shown, and `sign`
222
+ * re-reads everything from disk.
223
+ * @param {string} id
224
+ */
225
+ signPrepare(id: string): any;
226
+ /**
227
+ * `POST /api/author/:id/sign` body `{ hash, runId? }`: sign and start the run — only when the draft is green and
228
+ * 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
229
+ * refuses by name, signs nothing, writes nothing, spends nothing. Fully synchronous (no await between the checks and the
230
+ * writes), so two sign POSTs together sign once: the second reads the first's `signed.json` and is refused.
231
+ * @param {string} id @param {any} body
232
+ */
233
+ sign(id: string, body: any): any;
234
+ /**
235
+ * `POST /api/author/:id/revise` body = the card fields, as `POST /api/author/draft` takes them (M4e amendment 14): the human's edited
236
+ * card on a draft whose first plan was green -> the same $0 checks as a first draft -> `card-<n>.json` + `prose-<n>.txt` (write-once)
237
+ * -> one detached plain `fwdloop draft prose-<n>.txt --out draft-<n>` -> 202. The model gets the card only. Up to MAX_REVISES per
238
+ * draft; a refusal makes no model call and writes nothing. A body carrying a note (`text`/`note`) is refused: nothing the human types
239
+ * goes to the model as a note. Synchronous, like `start`.
240
+ * @param {string} id @param {any} body
241
+ */
242
+ revise(id: string, body: any): {
243
+ status: number;
244
+ body: any;
245
+ };
246
+ /**
247
+ * `POST /api/author/:id/answer` body `{ k, answer }` (M4e amendments 24, 25): the human's answer to the plan's question `k` of `n`, one at a time.
248
+ * A blank answer is refused and the question stays open; there is no skip. The answer is written ONCE ('wx') as `<plan>/answer-<k>.json`. After
249
+ * the LAST answer the plan is drafted again as a fresh plain `fwdloop draft --no-questions` child (it never asks), from the submitted card with
250
+ * each answer added word for word as a `~` guardrail under its line (the one `appendAnswersToJob`, then the one `cardToProse`). It is booked as
251
+ * an answer redraft (`redraft-<n>.json`), not a revise: it uses none of the 2. Synchronous, like `revise`; a refusal at $0 writes nothing.
252
+ * @param {string} id @param {any} body
253
+ */
254
+ answer(id: string, body: any): {
255
+ status: number;
256
+ body: any;
257
+ };
258
+ /**
259
+ * `GET /api/author/live`: the newest draft that is not abandoned or signed, and the newest panel start the human has not cleared
260
+ * (`starting` or `refused`; a `started` one is in Runs) — read from files, never memory.
261
+ */
262
+ live(): {
263
+ status: number;
264
+ body: {
265
+ ok: boolean;
266
+ draft: any;
267
+ start: {
268
+ phase: string;
269
+ startId: string;
270
+ kind: any;
271
+ flow: any;
272
+ runId: any;
273
+ } | null;
274
+ };
275
+ };
276
+ /** `GET /api/author/:id`. @param {string} id */
277
+ get(id: string): {
278
+ status: number;
279
+ body: any;
280
+ };
281
+ /**
282
+ * `POST /api/author/:id/abandon`: stop the child (by its recorded pid, only after `isFwdloopAlive` says it is ours),
283
+ * confirm it is gone, then write `abandoned.json`. No further model call; the spend already booked stays booked.
284
+ * @param {string} id
285
+ */
286
+ abandon(id: string): Promise<{
287
+ status: number;
288
+ body: {
289
+ ok: boolean;
290
+ refused: string;
291
+ say?: undefined;
292
+ phase?: undefined;
293
+ stopped?: undefined;
294
+ };
295
+ } | {
296
+ status: number;
297
+ body: {
298
+ ok: boolean;
299
+ refused: string;
300
+ say: string;
301
+ phase?: undefined;
302
+ stopped?: undefined;
303
+ };
304
+ } | {
305
+ status: number;
306
+ body: {
307
+ ok: boolean;
308
+ phase: string;
309
+ stopped: boolean;
310
+ refused?: undefined;
311
+ say?: undefined;
312
+ };
313
+ }>;
314
+ };
315
+ /** Up to 2 revises per draft (amendment 14 item 3); a revise is used once its `draft-<n>/` exists (a refusal at $0 makes none). */
316
+ export const MAX_REVISES: 2;
@@ -0,0 +1,142 @@
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
+ /**
24
+ * M4e amendment 24 item 3: the submitted job box with each answer added WORD FOR WORD as a `~` line under the job line it is about, after
25
+ * that line's own `~` lines (several answers for one line keep their order). The job box's own lines are untouched; the card -> prose path
26
+ * (`cardToProse`) then writes the answer as that line's guardrail, so it reaches the signed text and the hash. Pure. An answer for a line
27
+ * the box does not have is NOT added (the caller sees the count).
28
+ * @param {string} job @param {{ line: number, answer: string }[]} answers
29
+ * @returns {{ job: string, added: number }}
30
+ */
31
+ export function appendAnswersToJob(job: string, answers: {
32
+ line: number;
33
+ answer: string;
34
+ }[]): {
35
+ job: string;
36
+ added: number;
37
+ };
38
+ /**
39
+ * THE one place a step's `~` lines become its guardrail: several `~` lines under one step are ONE continuous guardrail (hamr ruling 2026-10-09),
40
+ * each part verbatim (trimmed), in typed order, joined by "; ". An answer (am24) is one more `~` line, so it joins here too. The signed-text parser
41
+ * stays strict 1-for-1 because the job file never carries more than one `guardrail:` per line.
42
+ * @param {string[]} parts
43
+ */
44
+ export function joinGuardrails(parts: string[]): string;
45
+ /** 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 */
46
+ export function jobFileLines(steps: ReturnType<typeof parseJobBox>["steps"], askWait: string): string[];
47
+ /**
48
+ * 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
49
+ * as the box shows it (empty lines are skipped and not numbered). A line with no colon is flagged `noColon`.
50
+ * @param {string} text
51
+ * @returns {{ line: number, role: string, path: string, noColon?: true }[]}
52
+ */
53
+ export function parseInputLines(text: string): {
54
+ line: number;
55
+ role: string;
56
+ path: string;
57
+ noColon?: true;
58
+ }[];
59
+ /**
60
+ * Normalise what the page sent into the typed card (one reader of the request body's shape). Unknown fields are
61
+ * dropped; nothing here judges a value. `inputs` is the inputs box's TEXT (`name: path` per line); `destination` is the folder.
62
+ * @param {any} body
63
+ */
64
+ export function cardFields(body: any): {
65
+ flowName: string;
66
+ job: string;
67
+ destination: string;
68
+ inputs: string;
69
+ capUsd: any;
70
+ askWait: string;
71
+ };
72
+ /** 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 */
73
+ export function runInputRows(v: any): {
74
+ role: string;
75
+ path: string;
76
+ }[];
77
+ /**
78
+ * 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
79
+ * job file); the arbiter block is built only from the card's own fields. The ONE card -> prose function.
80
+ * @param {ReturnType<typeof cardFields>} card
81
+ * @returns {string}
82
+ */
83
+ export function cardToProse(card: ReturnType<typeof cardFields>): string;
84
+ /**
85
+ * 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,
86
+ * a role shape the signed-text parser accepts and used once, each path a full path to a readable regular file (realpath at the
87
+ * 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
88
+ * sentence starts "Line N:". A Run-door row has no line: its refusal is field `inputs.<n>`.
89
+ * @param {{role: string, path: string, line?: number, noColon?: true}[]} rows
90
+ * @returns {{field: string, say: string}[]} one refusal per bad row
91
+ */
92
+ export function checkInputRows(rows: {
93
+ role: string;
94
+ path: string;
95
+ line?: number;
96
+ noColon?: true;
97
+ }[]): {
98
+ field: string;
99
+ say: string;
100
+ }[];
101
+ /**
102
+ * 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
103
+ * `spent + ceiling > cap` (`runStepRalph`), and every ordinary (non-ask) step is a model step, so the floor is the runner's own
104
+ * per-round ceiling (`resolveCeilingUsd`) as soon as the job has one such line; a job of only asks spends nothing before its stop.
105
+ * ONE function: the card's Draft check, Sign, and the page's note all read it. Returns 0 when no step needs a round.
106
+ * @param {string} jobText
107
+ */
108
+ export function capFloorUsd(jobText: string): any;
109
+ /** 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 */
110
+ export function capFloorFor(hasRoundStep: boolean): any;
111
+ /** The one sentence for a cap under the floor (red under Cap, and the Draft / sign refusal). @param {number} floorUsd */
112
+ export function capFloorText(floorUsd: number): string;
113
+ /**
114
+ * 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,
115
+ * else the sentence (a folder that is the run folder, a flow folder, the root, `.drafts`, `.starts`, the config folder, a file, a missing
116
+ * folder, a path with a control character). Never overwrite is the send's own rule at write time.
117
+ * @param {string} dest the folder as typed @param {string} root the flows root
118
+ * @returns {string|null}
119
+ */
120
+ export function destinationRefusal(dest: string, root: string): string | null;
121
+ /**
122
+ * Every $0 check on the card, before any spawn (scope 6). Collects all refusals so the page can name every box.
123
+ * @param {ReturnType<typeof cardFields>} card
124
+ * @param {{ root: string, env?: Record<string, string|undefined> }} ctx `env` = the merged keys env: a key value typed into any box is refused
125
+ * @returns {{ ok: true, prose: string }|{ ok: false, refusals: {field: string, say: string}[] }}
126
+ */
127
+ export function checkCard(card: ReturnType<typeof cardFields>, { root, env }: {
128
+ root: string;
129
+ env?: Record<string, string | undefined>;
130
+ }): {
131
+ ok: true;
132
+ prose: string;
133
+ } | {
134
+ ok: false;
135
+ refusals: {
136
+ field: string;
137
+ say: string;
138
+ }[];
139
+ };
140
+ /** The heading line the prose files use (flows/job2-m6a-3/prose.txt); the parser matches `/^arbiter guardrails\b/i`. */
141
+ export const ARBITER_HEADING: "Arbiter guardrails (belong to no line; human-signed, tighten-only \u2014 never authored or claimed by the drafter):";
142
+ 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
+ };