fwdloop 0.11.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.
Files changed (62) hide show
  1. package/bin/fwdloop +248 -27
  2. package/package.json +1 -1
  3. package/src/ask.js +3 -0
  4. package/src/authoring.js +103 -13
  5. package/src/books.js +23 -2
  6. package/src/canrun.js +36 -0
  7. package/src/config.js +256 -0
  8. package/src/declaration.js +72 -2
  9. package/src/drafter.js +53 -11
  10. package/src/draftspend.js +70 -0
  11. package/src/flow.js +43 -0
  12. package/src/keysfile.js +180 -0
  13. package/src/liveness.js +1 -1
  14. package/src/model-step.js +43 -8
  15. package/src/monthly.js +276 -0
  16. package/src/panel/author.js +482 -0
  17. package/src/panel/authorcard.js +297 -0
  18. package/src/panel/authorflows.js +312 -0
  19. package/src/panel/authorresume.js +149 -0
  20. package/src/panel/authorstart.js +257 -0
  21. package/src/panel/authorvalues.js +110 -0
  22. package/src/panel/data.js +228 -34
  23. package/src/panel/index.html +2073 -124
  24. package/src/panel/resume.js +14 -11
  25. package/src/panel/server.js +150 -117
  26. package/src/panel/settings.js +270 -0
  27. package/src/panel/spawn.js +77 -0
  28. package/src/provider.js +189 -43
  29. package/src/providershapes.js +19 -0
  30. package/src/runner.js +639 -85
  31. package/src/runvalues.js +178 -0
  32. package/src/send.js +10 -3
  33. package/src/setup.js +120 -0
  34. package/types/authoring.d.ts +24 -2
  35. package/types/books.d.ts +14 -2
  36. package/types/canrun.d.ts +32 -0
  37. package/types/config.d.ts +52 -0
  38. package/types/declaration.d.ts +9 -1
  39. package/types/drafter.d.ts +18 -2
  40. package/types/draftspend.d.ts +21 -0
  41. package/types/flow.d.ts +23 -0
  42. package/types/keysfile.d.ts +90 -0
  43. package/types/liveness.d.ts +2 -2
  44. package/types/model-step.d.ts +6 -2
  45. package/types/monthly.d.ts +130 -0
  46. package/types/panel/author.d.ts +335 -0
  47. package/types/panel/authorcard.d.ts +120 -0
  48. package/types/panel/authorflows.d.ts +175 -0
  49. package/types/panel/authorresume.d.ts +32 -0
  50. package/types/panel/authorstart.d.ts +115 -0
  51. package/types/panel/authorvalues.d.ts +62 -0
  52. package/types/panel/data.d.ts +103 -12
  53. package/types/panel/resume.d.ts +8 -1
  54. package/types/panel/server.d.ts +19 -33
  55. package/types/panel/settings.d.ts +23 -0
  56. package/types/panel/spawn.d.ts +30 -0
  57. package/types/provider.d.ts +123 -70
  58. package/types/providershapes.d.ts +11 -0
  59. package/types/runner.d.ts +120 -5
  60. package/types/runvalues.d.ts +97 -0
  61. package/types/send.d.ts +5 -1
  62. package/types/setup.d.ts +83 -0
package/types/flow.d.ts CHANGED
@@ -87,6 +87,27 @@ export function listFlowNames(root: string): string[];
87
87
  * @returns {string[]}
88
88
  */
89
89
  export function listRunIds(flowDir: string): string[];
90
+ /**
91
+ * M4e amendment 3 item 2: the ONE place a run gets its default name. `run-<n>`, counting up per flow (the run lives in its flow's
92
+ * folder, so the name only has to be unique there). `nextRunId` only LOOKS (max existing `run-<n>` + 1; the page's prefill);
93
+ * `claimRunId` CLAIMS: it creates the run folder exclusively (mkdir with no `recursive` on the final component, so a second
94
+ * starter gets EEXIST, never the same folder) and bumps n on EEXIST, a bounded number of times. Runs already made keep their ids.
95
+ * @param {string} flowDir
96
+ * @returns {string}
97
+ */
98
+ export function nextRunId(flowDir: string): string;
99
+ /**
100
+ * @param {string} flowDir
101
+ * @returns {{ok:true, runId:string, runDir:string}|{ok:false, red:string}}
102
+ */
103
+ export function claimRunId(flowDir: string): {
104
+ ok: true;
105
+ runId: string;
106
+ runDir: string;
107
+ } | {
108
+ ok: false;
109
+ red: string;
110
+ };
90
111
  /**
91
112
  * F48 round 3 (docs/logs/FINDINGS.md): the ONE mechanism every book reader
92
113
  * in src/ and bin/ routes through to read a file that lives inside a run
@@ -185,6 +206,8 @@ export function readFlow({ root, name, catalogue }: {
185
206
  /** The three files a signed flow directory carries. Every place in this
186
207
  * module that names a flow file uses this — never a literal string. */
187
208
  export const FLOW_FILES: readonly string[];
209
+ /** The one folder under the flows root where the panel keeps each run start's own files (M4e piece 2b). A dot-name, so never a flow. */
210
+ export const PANEL_STARTS_DIR: ".starts";
188
211
  export type WriteFlowResult = import("./types.js").WriteFlowResult;
189
212
  export type ReadFlowResult = import("./types.js").ReadFlowResult;
190
213
  export type CheckFlowNameResult = import("./types.js").CheckFlowNameResult;
@@ -0,0 +1,90 @@
1
+ /**
2
+ * `~/.config/fwdloop`, or an injected override. The CLI/panel door honors the test-only
3
+ * `FWDLOOP_CONFIG_HOME` through `keysForDoor` (two gates, like the other test seams).
4
+ * @param {string} [home] test seam; production never passes it
5
+ * @returns {string}
6
+ */
7
+ export function keysHome(home?: string): string;
8
+ /**
9
+ * @param {string} [home]
10
+ * @returns {string} `<home>/.env`
11
+ */
12
+ export function keysFilePath(home?: string): string;
13
+ /** The one wording of the 1A refusal (ruling 1A, hamr 2026-10-05). @param {string} [home] */
14
+ export function chmodSentence(home?: string): string;
15
+ /**
16
+ * Parse the file's text. Lines that are not `NAME=value` are skipped silently
17
+ * (never echoed — a malformed line may hold a secret).
18
+ * @param {string} text
19
+ * @returns {Record<string,string>}
20
+ */
21
+ export function parseKeysText(text: string): Record<string, string>;
22
+ /**
23
+ * @typedef {object} KeysLoad
24
+ * @property {boolean} ok false = refused: nothing that needs a key may run
25
+ * @property {string} path the keys file's path as shown to people
26
+ * @property {boolean} exists the file is there (true after a create)
27
+ * @property {string[]} names the NAMES the file defines with a value (sorted; never values)
28
+ * @property {string[]} shellOnly the known key names that only the shell sets (file empty/absent)
29
+ * @property {string|null} refusal a plain sentence when `ok` is false, else null
30
+ * @property {Record<string,string|undefined>} env shell env with the file filling the names the
31
+ * shell does not set; on a refusal just a copy of the shell env (no file value). THE ONLY
32
+ * place file values leave this module.
33
+ */
34
+ /**
35
+ * Load the keys file over an env. A missing file is created (0600) and is not a refusal.
36
+ * @param {{ env?: Record<string,string|undefined>, home?: string }} [opts]
37
+ * @returns {KeysLoad}
38
+ */
39
+ export function loadKeysEnv(opts?: {
40
+ env?: Record<string, string | undefined>;
41
+ home?: string;
42
+ }): KeysLoad;
43
+ /**
44
+ * The door helper the CLI and the panel call. Loads the file only when the caller is on the
45
+ * REAL environment, or names a home explicitly (a test), or a test process (`configDoorHome`) with
46
+ * `FWDLOOP_CONFIG_HOME` set — so a test that injects `env` alone, or runs under NODE_ENV=test
47
+ * without a home, never reads (or creates) the real `~/.config/fwdloop/.env`.
48
+ * @param {{ env?: Record<string,string|undefined>, keysHome?: string }} [deps]
49
+ * @returns {KeysLoad & { skipped: boolean }}
50
+ */
51
+ export function keysForDoor(deps?: {
52
+ env?: Record<string, string | undefined>;
53
+ keysHome?: string;
54
+ }): KeysLoad & {
55
+ skipped: boolean;
56
+ };
57
+ /** The key names fwdloop knows (one per provider slot). */
58
+ export const KEY_NAMES: readonly ("SYNTHETIC_API_KEY" | "DEEPSEEK_API_KEY")[];
59
+ export type KeysLoad = {
60
+ /**
61
+ * false = refused: nothing that needs a key may run
62
+ */
63
+ ok: boolean;
64
+ /**
65
+ * the keys file's path as shown to people
66
+ */
67
+ path: string;
68
+ /**
69
+ * the file is there (true after a create)
70
+ */
71
+ exists: boolean;
72
+ /**
73
+ * the NAMES the file defines with a value (sorted; never values)
74
+ */
75
+ names: string[];
76
+ /**
77
+ * the known key names that only the shell sets (file empty/absent)
78
+ */
79
+ shellOnly: string[];
80
+ /**
81
+ * a plain sentence when `ok` is false, else null
82
+ */
83
+ refusal: string | null;
84
+ /**
85
+ * shell env with the file filling the names the
86
+ * shell does not set; on a refusal just a copy of the shell env (no file value). THE ONLY
87
+ * place file values leave this module.
88
+ */
89
+ env: Record<string, string | undefined>;
90
+ };
@@ -21,10 +21,10 @@ export function isFwdloopAlive(pid: number, procStart?: string | null): boolean
21
21
  * The one writer call: this process records itself in the run dir's
22
22
  * `pids.jsonl`, before its first step.
23
23
  * @param {string} runDir
24
- * @param {'run'|'resume'} leg
24
+ * @param {'run'|'resume'|'continue'} leg
25
25
  * @param {string} at ISO timestamp from the run's own clock
26
26
  */
27
- export function recordPid(runDir: string, leg: "run" | "resume", at: string): void;
27
+ export function recordPid(runDir: string, leg: "run" | "resume" | "continue", at: string): void;
28
28
  /**
29
29
  * Is the process that last worked on this run still alive? Reads the newest
30
30
  * `pids.jsonl` row (the one reader, `readPidRows`).
@@ -91,9 +91,10 @@ export function buildEmitArtifactSchema(stepClass: any): Readonly<{
91
91
  * @param {any} [opts.provider] - an injected provider (tests only; production always builds live via `slot`).
92
92
  * @param {{in:number,out:number}} [opts.rates]
93
93
  * @param {string} [opts.modelId]
94
- * @returns {(executorContext:object, grantedTools:Record<string,any>, stepMeta?:{class?:string}) => Promise<any>}
94
+ * @param {Record<string,string|undefined>} [opts.env] - the merged shell+keys-file env the key is read from (default process.env).
95
+ * @returns {(executorContext:object, grantedTools:Record<string,any>, stepMeta?:{class?:string}, seam?:{stopRequested?:() => boolean}) => Promise<any>}
95
96
  */
96
- export function makeLiveModelStep({ slot, model, spendPath, provider: injectedProvider, rates: injectedRates, modelId: injectedModelId, }: {
97
+ export function makeLiveModelStep({ slot, model, spendPath, provider: injectedProvider, rates: injectedRates, modelId: injectedModelId, env, }: {
97
98
  slot?: string | undefined;
98
99
  model?: string | undefined;
99
100
  spendPath: string;
@@ -103,8 +104,11 @@ export function makeLiveModelStep({ slot, model, spendPath, provider: injectedPr
103
104
  out: number;
104
105
  } | undefined;
105
106
  modelId?: string | undefined;
107
+ env?: Record<string, string | undefined> | undefined;
106
108
  }): (executorContext: object, grantedTools: Record<string, any>, stepMeta?: {
107
109
  class?: string;
110
+ }, seam?: {
111
+ stopRequested?: () => boolean;
108
112
  }) => Promise<any>;
109
113
  export const LIVE_PROVIDER_OPTIONS: Readonly<{
110
114
  timeoutMs: 300000;
@@ -0,0 +1,130 @@
1
+ /** realpath of the longest existing prefix of `p`, the rest appended (a run dir does not exist yet at claim time). @param {string} p */
2
+ export function realpathLoose(p: string): string;
3
+ /** @param {string} [home] @returns {any[]} every well-formed row in file order (a torn line is skipped) */
4
+ export function readRuns(home?: string): any[];
5
+ /**
6
+ * The Money tab's figures (piece 4 reads this) and the check's month total.
7
+ * @param {{ home?: string, now?: () => number }} [opts]
8
+ */
9
+ export function spendSummary(opts?: {
10
+ home?: string;
11
+ now?: () => number;
12
+ }): {
13
+ month: {
14
+ modelMinutes: number | null;
15
+ modelMinutesAtLeast: any;
16
+ usd: any;
17
+ atLeast: any;
18
+ tokens: any;
19
+ };
20
+ total: {
21
+ modelMinutes: number | null;
22
+ modelMinutesAtLeast: any;
23
+ usd: any;
24
+ atLeast: any;
25
+ tokens: any;
26
+ };
27
+ byProvider: {
28
+ [k: string]: {
29
+ label: string;
30
+ month: {
31
+ modelMinutes: number | null;
32
+ modelMinutesAtLeast: any;
33
+ usd: any;
34
+ atLeast: any;
35
+ tokens: any;
36
+ };
37
+ total: {
38
+ modelMinutes: number | null;
39
+ modelMinutesAtLeast: any;
40
+ usd: any;
41
+ atLeast: any;
42
+ tokens: any;
43
+ };
44
+ };
45
+ };
46
+ undatedRows: number;
47
+ preM4dRunsNotCounted: boolean;
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
+ };
70
+ /**
71
+ * @typedef {object} Claim
72
+ * @property {boolean} ok the hold fits (or no limit is set)
73
+ * @property {string} holdId the hold row's id (a $0 hold when no limit is set)
74
+ * @property {{limitUsd:number|null, leftUsd:number|null, heldUsd:number, heldRuns:number, needUsd:number, atLeast:boolean}} room
75
+ */
76
+ /**
77
+ * The check at a door. Appends the hold row first (always, even with no limit), then decides. Throws ConfigError when config.json is
78
+ * broken (nothing is appended) or the row cannot be written. A refusal appends a `refused` row.
79
+ * @param {{ what: 'run'|'resume'|'draft', flow: string|null, runId: string|null, runDir: string, holdUsd: number, spentAtHold?: number, home?: string, now?: () => number }} a
80
+ * @returns {Claim}
81
+ */
82
+ export function claimHold({ what, flow, runId, runDir, holdUsd, spentAtHold, home, now, }: {
83
+ what: "run" | "resume" | "draft";
84
+ flow: string | null;
85
+ runId: string | null;
86
+ runDir: string;
87
+ holdUsd: number;
88
+ spentAtHold?: number;
89
+ home?: string;
90
+ now?: () => number;
91
+ }): Claim;
92
+ /**
93
+ * The run's own process ends or parks: give the hold back. Never throws (a failed settle is closed by the
94
+ * next check as "process gone"). `alsoRunDirs` names dirs this process also spent into (a rerun's new run).
95
+ * @param {{ holdId: string|null, why: string, home?: string, now?: () => number, alsoRunDirs?: string[] }} a
96
+ */
97
+ export function settleHold({ holdId, why, home, now, alsoRunDirs, }: {
98
+ holdId: string | null;
99
+ why: string;
100
+ home?: string;
101
+ now?: () => number;
102
+ alsoRunDirs?: string[];
103
+ }): void;
104
+ /**
105
+ * The ONE refusal text (CLI and page): the amount line, then the signed sentence.
106
+ * @param {Claim['room']} room
107
+ */
108
+ export function monthlyRefusalText(room: Claim["room"]): string;
109
+ export { ConfigError };
110
+ export const REFUSAL_SENTENCE: "Nothing spent. Raise the monthly limit in Settings, or wait for next month.";
111
+ export const NOT_RECORDED: "not recorded";
112
+ export type Claim = {
113
+ /**
114
+ * the hold fits (or no limit is set)
115
+ */
116
+ ok: boolean;
117
+ /**
118
+ * the hold row's id (a $0 hold when no limit is set)
119
+ */
120
+ holdId: string;
121
+ room: {
122
+ limitUsd: number | null;
123
+ leftUsd: number | null;
124
+ heldUsd: number;
125
+ heldRuns: number;
126
+ needUsd: number;
127
+ atLeast: boolean;
128
+ };
129
+ };
130
+ import { ConfigError } from './config.js';
@@ -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;