fwdloop 0.24.0 → 0.25.1

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 (50) hide show
  1. package/bin/fwdloop +33 -26
  2. package/package.json +1 -1
  3. package/src/cited-record.js +3 -22
  4. package/src/cited-source.js +5 -6
  5. package/src/csv.js +2 -1
  6. package/src/diary.js +21 -17
  7. package/src/flowmodel.js +6 -37
  8. package/src/keysfile.js +1 -1
  9. package/src/launcher.js +552 -0
  10. package/src/learnstore.js +6 -4
  11. package/src/line-checks.js +55 -0
  12. package/src/opener.js +33 -0
  13. package/src/panel/author.js +2 -0
  14. package/src/panel/authorflows.js +9 -9
  15. package/src/panel/authorresume.js +4 -3
  16. package/src/panel/data.js +3 -2
  17. package/src/panel/index.html +22 -8
  18. package/src/panel/result.js +7 -12
  19. package/src/panel/server.js +53 -5
  20. package/src/panel/settings.js +4 -18
  21. package/src/panel/spawn.js +0 -9
  22. package/src/prompts.js +33 -0
  23. package/src/runfile.js +59 -0
  24. package/src/runner.js +18 -17
  25. package/src/sheet-record.js +15 -35
  26. package/src/sheetblock.js +3 -3
  27. package/src/sheetrun.js +6 -6
  28. package/src/summary-words.js +13 -5
  29. package/src/tty-colour.js +29 -0
  30. package/types/cited-record.d.ts +0 -2
  31. package/types/diary.d.ts +2 -5
  32. package/types/flowmodel.d.ts +2 -21
  33. package/types/keysfile.d.ts +7 -0
  34. package/types/launcher.d.ts +307 -0
  35. package/types/learnstore.d.ts +1 -1
  36. package/types/line-checks.d.ts +26 -0
  37. package/types/opener.d.ts +12 -0
  38. package/types/panel/author.d.ts +2 -0
  39. package/types/panel/result.d.ts +1 -3
  40. package/types/panel/server.d.ts +24 -3
  41. package/types/panel/settings.d.ts +2 -2
  42. package/types/panel/spawn.d.ts +0 -6
  43. package/types/prompts.d.ts +14 -0
  44. package/types/runfile.d.ts +47 -0
  45. package/types/runner.d.ts +3 -3
  46. package/types/sheet-record.d.ts +0 -2
  47. package/types/sheetblock.d.ts +2 -2
  48. package/types/sheetrun.d.ts +1 -1
  49. package/types/summary-words.d.ts +2 -1
  50. package/types/tty-colour.d.ts +33 -0
@@ -0,0 +1,307 @@
1
+ /**
2
+ * @typedef {object} Panel one answered probe
3
+ * @property {number} port @property {number} pid @property {string} version @property {number} drafts @property {number} schedules @property {string} [startedAt] ISO, absent on an older panel
4
+ * @property {string} url
5
+ */
6
+ /**
7
+ * @typedef {object} LauncherDeps every OS touch, injectable (a test passes all of them)
8
+ * @property {string} [home] the fwdloop config home (`~/.config/fwdloop`, src/config.js `configHome`); undefined = the real one
9
+ * @property {string} [root] the flows folder the runs line reads and `start` hands the panel (`--root`); default '.' like `fwdloop panel`
10
+ * @property {number} [portStart] @property {number} [portCount]
11
+ * @property {number[]} [ports] an explicit port list (tests); wins over portStart/portCount
12
+ * @property {number} [timeoutMs] probe timeout per port
13
+ * @property {number} [deadlineMs] start/stop wait deadline
14
+ * @property {number} [silentWaitMs] how long start keeps asking a taken, silent port (default 10 s)
15
+ * @property {string} [nodeVersion] default process.versions.node
16
+ * @property {typeof fetch} [fetchImpl]
17
+ * @property {(a: {bin: string, argv: string[], env: Record<string, string|undefined>, logPath: string}) => any} [spawnFn] default src/panel/spawn.js `spawnDetached`
18
+ * @property {(pid: number, sig: string|number) => void} [kill] default process.kill
19
+ * @property {((target: string) => Promise<boolean>)} [open] default the shared OS opener
20
+ * @property {(port: number) => Promise<boolean>} [portFree] default: try to bind 127.0.0.1:port
21
+ * @property {(ms: number) => Promise<void>} [sleep]
22
+ * @property {(question: string) => Promise<string>} [ask] the y/N and menu reader
23
+ * @property {string} [fwdloopBin] default bin/fwdloop of this package
24
+ * @property {import('./tty-colour.js').Paint} [paint] colour for stdout lines (default none); {@link makePaint} decides TTY / NO_COLOR / TERM
25
+ * @property {import('./tty-colour.js').Paint} [paintErr] colour for stderr lines (default: `paint`)
26
+ * @property {number} [now] ms clock for the run list's 7-day rule (default: real time); tests pass their own
27
+ * @property {Record<string, string|undefined>} [env] raw env handed to the panel child (default process.env)
28
+ */
29
+ /**
30
+ * The run counts, from the panel's own `listRuns` rows - the SAME two reads the page makes (src/panel/index.html: Running now = `live === true`,
31
+ * Needs you = a non-empty `needs`, the tag `needsYouOf` decides, M11 included). A flow with no runs yet (`runId` null) is not a run. A part that is 0 still shows.
32
+ * @param {any[]} rows
33
+ * @returns {{running: number, needYou: number, total: number}}
34
+ */
35
+ export function countRuns(rows: any[]): {
36
+ running: number;
37
+ needYou: number;
38
+ total: number;
39
+ };
40
+ /**
41
+ * "installed ✓" = the folder exists, config.json is there and reads with no problem, `.env` exists with mode 600, node >= 22.
42
+ * Otherwise the FIRST missing thing in plain words.
43
+ * @param {{home?: string, nodeVersion?: string}} o
44
+ * @returns {{ok: boolean, problem: string|null}}
45
+ */
46
+ export function installState(o: {
47
+ home?: string;
48
+ nodeVersion?: string;
49
+ }): {
50
+ ok: boolean;
51
+ problem: string | null;
52
+ };
53
+ /**
54
+ * Ask one port for `/api/whoami`. Never throws. `silent` = no reply inside the timeout (a loaded or stuck process may still be a
55
+ * panel); `other` = something replied (or refused) and it is not a fwdloop whoami.
56
+ * @param {{port: number, timeoutMs?: number, fetchImpl?: typeof fetch}} o
57
+ * @returns {Promise<{state: 'panel', panel: Panel}|{state: 'other'}|{state: 'silent'}>}
58
+ */
59
+ export function probePort(o: {
60
+ port: number;
61
+ timeoutMs?: number;
62
+ fetchImpl?: typeof fetch;
63
+ }): Promise<{
64
+ state: "panel";
65
+ panel: Panel;
66
+ } | {
67
+ state: "other";
68
+ } | {
69
+ state: "silent";
70
+ }>;
71
+ /**
72
+ * Ask 127.0.0.1 across the ports in parallel; a reply with `app === "fwdloop"` is a panel. Never throws.
73
+ * @param {{ports: number[], timeoutMs?: number, fetchImpl?: typeof fetch}} o
74
+ * @returns {Promise<Panel[]>} in port order
75
+ */
76
+ export function probePanels(o: {
77
+ ports: number[];
78
+ timeoutMs?: number;
79
+ fetchImpl?: typeof fetch;
80
+ }): Promise<Panel[]>;
81
+ /**
82
+ * The panel's own date style (src/panel/index.html rlShortDate): local `MM/DD HH:MM`; an unparseable stamp is shown raw, never blank.
83
+ * @param {string} iso
84
+ */
85
+ export function shortDate(iso: string): string;
86
+ /**
87
+ * The header, ONCE per call: the two lines every `fwdloop` command prints first, plus the panels the probe found (the commands
88
+ * reuse them, so nothing is probed twice).
89
+ * @param {LauncherDeps & {version?: string}} d
90
+ * @returns {Promise<{lines: string[], panels: Panel[]}>}
91
+ */
92
+ export function buildHeader(d: LauncherDeps & {
93
+ version?: string;
94
+ }): Promise<{
95
+ lines: string[];
96
+ panels: Panel[];
97
+ }>;
98
+ /**
99
+ * @param {LauncherDeps & {version?: string}} d
100
+ * @returns {Promise<string[]>} the two header lines
101
+ */
102
+ export function headerLines(d: LauncherDeps & {
103
+ version?: string;
104
+ }): Promise<string[]>;
105
+ /**
106
+ * `fwdloop install` — creates only what is missing, never reads a key value.
107
+ * @param {{out: (s: string) => void, err: (s: string) => void}} io @param {LauncherDeps & {version?: string}} d @param {{lines: string[], panels: Panel[]}} [shown]
108
+ * @returns {Promise<number>}
109
+ */
110
+ export function installCmd(io: {
111
+ out: (s: string) => void;
112
+ err: (s: string) => void;
113
+ }, d: LauncherDeps & {
114
+ version?: string;
115
+ }, shown?: {
116
+ lines: string[];
117
+ panels: Panel[];
118
+ }): Promise<number>;
119
+ /**
120
+ * `fwdloop status` — the header, then one line per panel (or `Panel not running.`). Exit 0 running, 3 not running; 0 when the menu ran it.
121
+ * @param {{out: (s: string) => void}} io @param {LauncherDeps & {version?: string}} d @param {{lines: string[], panels: Panel[]}} [shown] header the menu already printed
122
+ * @returns {Promise<number>}
123
+ */
124
+ export function statusCmd(io: {
125
+ out: (s: string) => void;
126
+ }, d: LauncherDeps & {
127
+ version?: string;
128
+ }, shown?: {
129
+ lines: string[];
130
+ panels: Panel[];
131
+ }): Promise<number>;
132
+ /**
133
+ * `fwdloop start` — find a running panel first; else start one detached on the first free port 4800..4809, wait until it answers,
134
+ * open the page.
135
+ * @param {{out: (s: string) => void, err: (s: string) => void}} io @param {LauncherDeps & {version?: string}} d @param {{lines: string[], panels: Panel[]}} [shown]
136
+ * @returns {Promise<number>}
137
+ */
138
+ export function startCmd(io: {
139
+ out: (s: string) => void;
140
+ err: (s: string) => void;
141
+ }, d: LauncherDeps & {
142
+ version?: string;
143
+ }, shown?: {
144
+ lines: string[];
145
+ panels: Panel[];
146
+ }): Promise<number>;
147
+ /**
148
+ * `fwdloop stop [--yes]` — SIGTERM the pid of EVERY panel the probe finds (one panel at a time is the rule; no "which one"), wait until each
149
+ * port stops answering. Drafts are in memory: warn (summed over all found panels) and ask y/N unless `--yes`.
150
+ * @param {string[]} args
151
+ * @param {{out: (s: string) => void, err: (s: string) => void}} io @param {LauncherDeps & {version?: string}} d @param {{lines: string[], panels: Panel[]}} [shown]
152
+ * @returns {Promise<number>}
153
+ */
154
+ export function stopCmd(args: string[], io: {
155
+ out: (s: string) => void;
156
+ err: (s: string) => void;
157
+ }, d: LauncherDeps & {
158
+ version?: string;
159
+ }, shown?: {
160
+ lines: string[];
161
+ panels: Panel[];
162
+ }): Promise<number>;
163
+ /**
164
+ * `fwdloop restart [--yes]` (M4b am6 item 2) — the existing stop (same open-drafts warning and question; `--yes` skips it), then the existing start, on the port
165
+ * the panel had when it is free. No panel running: it just starts. A declined or failed stop starts nothing.
166
+ * @param {string[]} args
167
+ * @param {{out: (s: string) => void, err: (s: string) => void}} io @param {LauncherDeps & {version?: string}} d @param {{lines: string[], panels: Panel[]}} [shown]
168
+ * @returns {Promise<number>}
169
+ */
170
+ export function restartCmd(args: string[], io: {
171
+ out: (s: string) => void;
172
+ err: (s: string) => void;
173
+ }, d: LauncherDeps & {
174
+ version?: string;
175
+ }, shown?: {
176
+ lines: string[];
177
+ panels: Panel[];
178
+ }): Promise<number>;
179
+ /**
180
+ * The bare `fwdloop` menu: header, the five choices, one question. Runs the chosen command and returns its exit code.
181
+ * @param {{out: (s: string) => void, err: (s: string) => void}} io @param {LauncherDeps & {version?: string}} d
182
+ * @returns {Promise<number>}
183
+ */
184
+ export function menuCmd(io: {
185
+ out: (s: string) => void;
186
+ err: (s: string) => void;
187
+ }, d: LauncherDeps & {
188
+ version?: string;
189
+ }): Promise<number>;
190
+ /**
191
+ * The launcher doors: the bare `fwdloop` menu and `start | stop | restart | status | install` (bin/fwdloop calls this; bareloop's runLauncher in src/cli.js). All logic is above;
192
+ * this only supplies the line reader and the colour. `deps.launcher` is the test seam for every OS touch (ports, spawn, kill, opener, clock).
193
+ * @param {'menu'|'start'|'stop'|'restart'|'status'|'install'} cmd @param {string[]} rest
194
+ * @param {{ stdin?: any, stdout?: any, stderr?: any, home?: string, root?: string, processEnv?: Record<string, string|undefined>, launcher?: LauncherDeps & {version?: string} }} deps
195
+ * @returns {Promise<number>}
196
+ */
197
+ export function launcherMain(cmd: "menu" | "start" | "stop" | "restart" | "status" | "install", rest: string[], deps: {
198
+ stdin?: any;
199
+ stdout?: any;
200
+ stderr?: any;
201
+ home?: string;
202
+ root?: string;
203
+ processEnv?: Record<string, string | undefined>;
204
+ launcher?: LauncherDeps & {
205
+ version?: string;
206
+ };
207
+ }): Promise<number>;
208
+ /** the first port tried, and how many in a row (4800..4809) */
209
+ export const PORT_START: 4800;
210
+ export const PORT_COUNT: 10;
211
+ /**
212
+ * one answered probe
213
+ */
214
+ export type Panel = {
215
+ port: number;
216
+ pid: number;
217
+ version: string;
218
+ drafts: number;
219
+ schedules: number;
220
+ /**
221
+ * ISO, absent on an older panel
222
+ */
223
+ startedAt?: string | undefined;
224
+ url: string;
225
+ };
226
+ /**
227
+ * every OS touch, injectable (a test passes all of them)
228
+ */
229
+ export type LauncherDeps = {
230
+ /**
231
+ * the fwdloop config home (`~/.config/fwdloop`, src/config.js `configHome`); undefined = the real one
232
+ */
233
+ home?: string | undefined;
234
+ /**
235
+ * the flows folder the runs line reads and `start` hands the panel (`--root`); default '.' like `fwdloop panel`
236
+ */
237
+ root?: string | undefined;
238
+ portStart?: number | undefined;
239
+ portCount?: number | undefined;
240
+ /**
241
+ * an explicit port list (tests); wins over portStart/portCount
242
+ */
243
+ ports?: number[] | undefined;
244
+ /**
245
+ * probe timeout per port
246
+ */
247
+ timeoutMs?: number | undefined;
248
+ /**
249
+ * start/stop wait deadline
250
+ */
251
+ deadlineMs?: number | undefined;
252
+ /**
253
+ * how long start keeps asking a taken, silent port (default 10 s)
254
+ */
255
+ silentWaitMs?: number | undefined;
256
+ /**
257
+ * default process.versions.node
258
+ */
259
+ nodeVersion?: string | undefined;
260
+ fetchImpl?: typeof fetch | undefined;
261
+ /**
262
+ * default src/panel/spawn.js `spawnDetached`
263
+ */
264
+ spawnFn?: ((a: {
265
+ bin: string;
266
+ argv: string[];
267
+ env: Record<string, string | undefined>;
268
+ logPath: string;
269
+ }) => any) | undefined;
270
+ /**
271
+ * default process.kill
272
+ */
273
+ kill?: ((pid: number, sig: string | number) => void) | undefined;
274
+ /**
275
+ * default the shared OS opener
276
+ */
277
+ open?: ((target: string) => Promise<boolean>) | undefined;
278
+ /**
279
+ * default: try to bind 127.0.0.1:port
280
+ */
281
+ portFree?: ((port: number) => Promise<boolean>) | undefined;
282
+ sleep?: ((ms: number) => Promise<void>) | undefined;
283
+ /**
284
+ * the y/N and menu reader
285
+ */
286
+ ask?: ((question: string) => Promise<string>) | undefined;
287
+ /**
288
+ * default bin/fwdloop of this package
289
+ */
290
+ fwdloopBin?: string | undefined;
291
+ /**
292
+ * colour for stdout lines (default none); {@link makePaint} decides TTY / NO_COLOR / TERM
293
+ */
294
+ paint?: import("./tty-colour.js").Paint | undefined;
295
+ /**
296
+ * colour for stderr lines (default: `paint`)
297
+ */
298
+ paintErr?: import("./tty-colour.js").Paint | undefined;
299
+ /**
300
+ * ms clock for the run list's 7-day rule (default: real time); tests pass their own
301
+ */
302
+ now?: number | undefined;
303
+ /**
304
+ * raw env handed to the panel child (default process.env)
305
+ */
306
+ env?: Record<string, string | undefined> | undefined;
307
+ };
@@ -108,7 +108,7 @@ export function eventsOfRun(runDir: string, workflow: string): {
108
108
  * THE RUN-END TALLY ($0, code only, no model; M8 item 2): turn a finished run's folder into cards and fold them into the ledger.
109
109
  * The place is the first input's source made absolute lexically (`path.resolve`, no fs: the F48 guard keeps realpathSync out of this file, so a symlinked source is not followed). The ledger run id is `<workflow>/<runId>` (fwdloop's run ids repeat across workflows, bareloop's do not). M8 am4: every run's notes COUNT at once (trust 'deterministic'), a run
110
110
  * with a signed ask included; there is no hold. It runs whether `learningHints` is on or off. `questions` (bareloop's stageQuestionsByName) is, here, the failing check's own text from
111
- * the run's checks.jsonl, so a check with no checks.jsonl row (a run from before am29) has no `meaning`.
111
+ * the run's diary.jsonl, so a check with no checks row there (a run from before am29) has no `meaning`.
112
112
  * Borrowed-from: bareloop src/learnstore.js@v0.47.0:124 (learnAtRunEnd).
113
113
  * @param {{home?: string, workflow: string, runId: string, runDir: string, specHash: string|null, now?: Date}} o
114
114
  * @returns {{wrote: boolean, counted: number, held: number, problem: string|null, noise: string|null, cards: number}}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * One section of the record: `{ok: true, lines}`, or `{ok: false, missing: true}` when the file or the section is not there, or `{ok: false, missing: false, red}` when
3
+ * the file (or the section) is not what it should be. Read through the safe gateway.
4
+ * @param {string} runDir @param {LineSection} section
5
+ * @returns {{ok: true, lines: any[]}|{ok: false, missing: true}|{ok: false, missing: false, red: string}}
6
+ */
7
+ export function readLineSection(runDir: string, section: LineSection): {
8
+ ok: true;
9
+ lines: any[];
10
+ } | {
11
+ ok: false;
12
+ missing: true;
13
+ } | {
14
+ ok: false;
15
+ missing: false;
16
+ red: string;
17
+ };
18
+ /**
19
+ * Change one section's lines and write the file: `change` gets the section's lines now (none when the section or the file is missing or unreadable: the record is started
20
+ * again, this function is its only writer) and returns the lines to keep, or null to write nothing. The other section is carried over as it is. Atomic.
21
+ * @param {string} runDir @param {LineSection} section @param {(lines: any[]) => any[]|null} change @returns {void}
22
+ */
23
+ export function writeLineSection(runDir: string, section: LineSection, change: (lines: any[]) => any[] | null): void;
24
+ /** the record's name in the run's own folder */
25
+ export const LINE_CHECKS_FILE: "line-checks.json";
26
+ export type LineSection = "cited" | "sheet";
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @param {string} target a folder path or a URL
3
+ * @param {{ platform?: string, spawnFn?: ((cmd: string, args: string[], o: object) => any)|null, underTest?: boolean }} [opts]
4
+ * `spawnFn: null` = no opener at all (resolves false); undefined = the real spawn, unless `underTest`, which spawns nothing
5
+ * unless a test injected one
6
+ * @returns {Promise<boolean>} true once the opener process has started
7
+ */
8
+ export function openInOs(target: string, opts?: {
9
+ platform?: string;
10
+ spawnFn?: ((cmd: string, args: string[], o: object) => any) | null;
11
+ underTest?: boolean;
12
+ }): Promise<boolean>;
@@ -43,6 +43,8 @@ export function createAuthor(opts: {
43
43
  };
44
44
  /** `GET /api/author/run-again`, its flow entry carrying the trigger card like the list's entries do. @param {string|null} flow @param {string|null} runId */
45
45
  runAgain(flow: string | null, runId: string | null): any;
46
+ /** M4b am4 item 7: how many drafts are open for `whoami` and the launcher's stop warning: the card `live()` returns (the newest draft not abandoned or signed), 0 or 1. */
47
+ openDrafts(): 0 | 1;
46
48
  run: (body: any) => {
47
49
  status: any;
48
50
  body: any;
@@ -7,7 +7,7 @@ export function isResultRun(arbiter: any): boolean;
7
7
  * @param {any} declaration @returns {string} */
8
8
  export function checkTypeOf(declaration: any): string;
9
9
  /**
10
- * The ONE reader of the M10 cited-check record (`<run>/cited-checks.json`). Expected shape (typed, nothing parsed out of prose):
10
+ * The ONE reader of the M10 cited-check record (the `cited` section of `<run>/line-checks.json`, src/line-checks.js; `writeCitedLine`, src/cited-record.js, writes it). Expected shape (typed, nothing parsed out of prose):
11
11
  * { lines: [ { n: int, source: string (the role of a signed source), passed: boolean,
12
12
  * facts: [ { name: string, kind: 'phrase'|'value', sentence: string, confirmed?: true } ],
13
13
  * rows: [ { n: int, quote: string, cells: string[] (one per fact), proof?: { text: string, marks: [[start, end], ...] } } ] | null,
@@ -152,5 +152,3 @@ export const RESULT_YOU_CONFIRMED: "(you confirmed)";
152
152
  /** the Your-call card's words (bareloop server.js@2959217 DOOR_WORDS.waiting.head and RESULT_DOOR_ASK); the page types none of them */
153
153
  export const RESULT_DOOR_HEAD: "waiting for you";
154
154
  export const RESULT_DOOR_ASK: "the checks passed; is this what you wanted?";
155
- export { CITED_CHECKS_FILE };
156
- import { CITED_CHECKS_FILE } from '../cited-record.js';
@@ -4,24 +4,45 @@
4
4
  * real listening socket where that is simpler.
5
5
  * @param {import('node:http').IncomingMessage} req
6
6
  * @param {import('node:http').ServerResponse} res
7
- * @param {{ root: string, port: number, packagePath?: string, resumer: ReturnType<typeof createResumer>, settings: ReturnType<typeof createSettings>, author: ReturnType<typeof createAuthor>, now?: () => number }} opts
7
+ * @param {{ root: string, port: number, version?: string|null, startedAt?: string, packagePath?: string, resumer: ReturnType<typeof createResumer>, settings: ReturnType<typeof createSettings>, author: ReturnType<typeof createAuthor>, now?: () => number }} opts
8
8
  */
9
9
  export function handleRequest(req: import("node:http").IncomingMessage, res: import("node:http").ServerResponse, opts: {
10
10
  root: string;
11
11
  port: number;
12
+ version?: string | null;
13
+ startedAt?: string;
12
14
  packagePath?: string;
13
15
  resumer: ReturnType<typeof createResumer>;
14
16
  settings: ReturnType<typeof createSettings>;
15
17
  author: ReturnType<typeof createAuthor>;
16
18
  now?: () => number;
17
19
  }): void;
20
+ /**
21
+ * The runs list as the panel builds it, for a caller with no panel running (the launcher header): the SAME `listRuns` over the same catalogue,
22
+ * so Needs you (M11's `needsYouOf` tag on each row) has ONE owner. Read-only, $0; the resume-attempt and starting-run lookups are the panel's
23
+ * in-memory ones and a stopped panel has none.
24
+ * borrowed-from: bareloop src/panel/server.js@c772d4e (runsListForCount); adapted: fwdloop's listRuns rows, no schedules-gave-up part (fwdloop has no such concept).
25
+ * @param {{ root: string, now?: () => number }} opts
26
+ * @returns {any[]} the rows of /api/runs
27
+ */
28
+ export function runsListForCount(opts: {
29
+ root: string;
30
+ now?: () => number;
31
+ }): any[];
32
+ /**
33
+ * The ONE spelling of the panel's own address (the launcher prints and opens it too).
34
+ * borrowed-from: bareloop src/panel/server.js@9104b2b (panelUrl); adaptation: none.
35
+ * @param {number} boundPort
36
+ * @returns {string}
37
+ */
38
+ export function panelUrl(boundPort: number): string;
18
39
  /**
19
40
  * Start the panel server. Binds `127.0.0.1` ONLY. A taken port is a LOUD,
20
41
  * non-zero-exit failure — this never falls back to another port (see file
21
42
  * header). Resolves once actually listening; rejects on a bind error
22
43
  * (including `EADDRINUSE`) with a `.port` field on the error for the
23
44
  * caller's message.
24
- * @param {{ port?: number, root: string, packagePath?: string, settings?: { home?: string, env?: Record<string,string|undefined>, fetch?: typeof fetch, now?: () => number, openFolderSpawn?: Function, platform?: string }, resume?: { env?: Record<string,string|undefined>, bin?: string, logDir?: string, maxTries?: number, windowMs?: number, slotMs?: number }, author?: { env?: Record<string,string|undefined>, loadEnv?: () => any, bin?: string, now?: () => number }, scheduler?: { intervalMs?: number } }} opts
45
+ * @param {{ port?: number, root: string, packagePath?: string, settings?: { home?: string, env?: Record<string,string|undefined>, fetch?: typeof fetch, now?: () => number, openFolderSpawn?: (cmd: string, args: string[], o: object) => any, platform?: string }, resume?: { env?: Record<string,string|undefined>, bin?: string, logDir?: string, maxTries?: number, windowMs?: number, slotMs?: number }, author?: { env?: Record<string,string|undefined>, loadEnv?: () => any, bin?: string, now?: () => number }, scheduler?: { intervalMs?: number } }} opts
25
46
  * `resume` and `author` are for tests only (a fake env/bin, a short retry window); the CLI passes none.
26
47
  * @returns {Promise<{ server: import('node:http').Server, port: number, tick: () => void, close: () => Promise<void> }>}
27
48
  */
@@ -34,7 +55,7 @@ export function createPanelServer(opts: {
34
55
  env?: Record<string, string | undefined>;
35
56
  fetch?: typeof fetch;
36
57
  now?: () => number;
37
- openFolderSpawn?: Function;
58
+ openFolderSpawn?: (cmd: string, args: string[], o: object) => any;
38
59
  platform?: string;
39
60
  };
40
61
  resume?: {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @param {{ home?: string, skip?: boolean, env?: Record<string,string|undefined>, fetch?: typeof fetch, now?: () => number, openFolderSpawn?: Function, platform?: string }} cfg
2
+ * @param {{ home?: string, skip?: boolean, env?: Record<string,string|undefined>, fetch?: typeof fetch, now?: () => number, openFolderSpawn?: (cmd: string, args: string[], o: object) => any, platform?: string }} cfg
3
3
  * `home` the config home (undefined = the real `~/.config/fwdloop`); `skip` true under a test process
4
4
  * with no `FWDLOOP_CONFIG_HOME` (Settings then touches nothing); `env` the shell side (tests only);
5
5
  * `fetch` and `now` are test seams.
@@ -10,7 +10,7 @@ export function createSettings(cfg: {
10
10
  env?: Record<string, string | undefined>;
11
11
  fetch?: typeof fetch;
12
12
  now?: () => number;
13
- openFolderSpawn?: Function;
13
+ openFolderSpawn?: (cmd: string, args: string[], o: object) => any;
14
14
  platform?: string;
15
15
  }): {
16
16
  handle: ({ method, pathname, query, body }: {
@@ -1,9 +1,3 @@
1
- /**
2
- * The ONE spawn for the Settings "Open keys folder" button (borrowed-from: bareloop src/panel/settingsroutes.js@07c298f): the OS file manager
3
- * (`xdg-open` / `open`) on a folder the server chose, argv array, no shell, detached. Settings calls it only through its injected seam.
4
- * @param {string} cmd @param {string[]} args @param {import('node:child_process').SpawnOptions} o
5
- */
6
- export function spawnOpener(cmd: string, args: string[], o: import("node:child_process").SpawnOptions): import("child_process").ChildProcess;
7
1
  /**
8
2
  * @param {{ bin: string, argv: string[], env: Record<string, string|undefined>, logPath: string }} a
9
3
  * @returns {import('node:child_process').ChildProcess} the child (already `unref()`ed; the log fd is closed here)
@@ -0,0 +1,14 @@
1
+ /**
2
+ * One readline over `stdin`, with a LINE QUEUE: lines that arrive before the next question (piped input, a paste, or input that
3
+ * ends while the header is still waiting on the port probe) wait for it instead of being dropped, and a closed stdin answers ''
4
+ * (the safe default) and never hangs.
5
+ * @param {{ stdin?: any, stdout?: any }} [io]
6
+ * @returns {{ ask: (q: string) => Promise<string>, close: () => void }}
7
+ */
8
+ export function openAsker(io?: {
9
+ stdin?: any;
10
+ stdout?: any;
11
+ }): {
12
+ ask: (q: string) => Promise<string>;
13
+ close: () => void;
14
+ };
@@ -0,0 +1,47 @@
1
+ /**
2
+ * The record as parsed, or why not. `missing` = no file; `unreadable` = the gateway refused it (a symlink, outside the folder); `invalid` = not a JSON object.
3
+ * @param {string|null} runDir @returns {{ok: true, rec: Record<string, any>}|{ok: false, code: 'missing'|'unreadable'|'invalid', red: string}}
4
+ */
5
+ export function readRunRecord(runDir: string | null): {
6
+ ok: true;
7
+ rec: Record<string, any>;
8
+ } | {
9
+ ok: false;
10
+ code: "missing" | "unreadable" | "invalid";
11
+ red: string;
12
+ };
13
+ /**
14
+ * M4d am26: the run's OWN record of the box (`thinking` in `<run>/run.json`) and nothing else: `true`/`false`, or `null` when the run has none (a run from before am25).
15
+ * An unreadable record is box off, as `readJobThinking` has always read it. @param {string|null} runDir @returns {boolean|null}
16
+ */
17
+ export function readRunThinking(runDir: string | null): boolean | null;
18
+ /**
19
+ * M8b: the ONE reader of what a run froze at its start (`inputs` in `<run>/run.json`: the manifest `freezeInputs` made). `missing` = the run froze none (no record, or no
20
+ * `inputs` section: a refusal at freeze leaves none); `unreadable` = the gateway refused the file; `invalid` = the section is not a list.
21
+ * @param {string|null} runDir
22
+ * @returns {{ok: true, entries: any[]}|{ok: false, code: 'missing'|'unreadable'|'invalid', red: string}}
23
+ */
24
+ export function readRunInputs(runDir: string | null): {
25
+ ok: true;
26
+ entries: any[];
27
+ } | {
28
+ ok: false;
29
+ code: "missing" | "unreadable" | "invalid";
30
+ red: string;
31
+ };
32
+ /**
33
+ * M8b item 1: the ONE writer of `run.json`, called once when a fresh run has frozen its inputs (`runFlow`); never over an existing record. `model` is the pick
34
+ * the run started on (M4d am33; null = the section is left out), `thinking` the job's "Thinking on" box as it was at the start (M4d am25: written for every fresh
35
+ * run, ticked or not), `inputs` the manifest `freezeInputs` returned. A fresh run always has `thinking` and `inputs`.
36
+ * @param {string} runDir @param {{ model: { slot: string, model: string }|null, thinking: boolean, inputs: any[] }} start
37
+ */
38
+ export function writeRunStart(runDir: string, { model, thinking, inputs }: {
39
+ model: {
40
+ slot: string;
41
+ model: string;
42
+ } | null;
43
+ thinking: boolean;
44
+ inputs: any[];
45
+ }): void;
46
+ /** the file's name in the run's folder */
47
+ export const RUN_FILE: "run.json";
package/types/runner.d.ts CHANGED
@@ -96,7 +96,7 @@ export function freezePage(dir: string, id: string, url: string, { fetchPage }?:
96
96
  red: string;
97
97
  }>;
98
98
  /** Copy each named source into `<runDir>/inputs/`, hash the FROZEN copy
99
- * (never the original again after this), write `inputs.json`. An
99
+ * (never the original again after this) and return the manifest, which `runFlow` records as the `inputs` of `run.json` (M8b). An
100
100
  * unreadable source refuses by name. A source that is a web address
101
101
  * (M10 item 1) is fetched and frozen by `freezePage`, in the same manifest.
102
102
  * @param {string} runDir @param {Array<{id: string, path: string}>} sources
@@ -304,7 +304,7 @@ export function runStepRalph({ step, primitivesMap, readsMap, businessDate, mode
304
304
  * @param {() => string} [opts.clock] - returns the current ISO timestamp; defaults to the wall clock.
305
305
  * @param {string} opts.businessDate - the run's explicit "as of today", never the wall clock.
306
306
  * @param {number} [opts.ceilingUsd] - per-attempt ceiling override; the model's hold from Settings prices (`ceilingCostUsd`); absent = no hold.
307
- * @param {{slot: string, model: string}} [opts.runModel] - M4d am33: the model this run started on; recorded once in the run folder (run-model.json) and kept by every resume/continue.
307
+ * @param {{slot: string, model: string}} [opts.runModel] - M4d am33: the model this run started on; recorded once in the run folder (run.json) and kept by every resume/continue.
308
308
  * @param {string|null} [opts.initialGap] - M3 scope item 7 (rerun as a fresh
309
309
  * run): a human's rerun reason, carried as the FIRST ordinary step's
310
310
  * starting gap. Never used by a plain `runFlow` call outside `resumeRun`'s
@@ -398,7 +398,7 @@ export function makeParkingAskStep(): (opts?: any) => Promise<{
398
398
  * @param {() => string} [opts.clock]
399
399
  * @param {string} opts.businessDate
400
400
  * @param {number} [opts.ceilingUsd]
401
- * @param {{slot: string, model: string}} [opts.runModel] - M4d am33: the model this run started on; recorded once in the run folder (run-model.json) and kept by every resume/continue.
401
+ * @param {{slot: string, model: string}} [opts.runModel] - M4d am33: the model this run started on; recorded once in the run folder (run.json) and kept by every resume/continue.
402
402
  * @param {() => number} [opts.nowMs] - F45 finding 3; see `runFlow`'s own.
403
403
  * @param {(newRunDir:string) => void} [opts.onRerunStart] - amendment 16 C2: called with the new run's folder just before a `rerun` starts it.
404
404
  */
@@ -20,5 +20,3 @@ export function writeSheetLine(runDir: string, { n, try: attempt, checks, closed
20
20
  export function readSheetChecks(runDir: string): {
21
21
  lines: any[];
22
22
  } | null;
23
- /** the record's name in the run's own folder */
24
- export const SHEET_CHECKS_FILE: "sheet-checks.json";
@@ -11,7 +11,7 @@ export function sheetFoundWords(check: any, claims: unknown): string | null;
11
11
  * The block of every job line whose step reads a sheet. A line qualifies when its green step carries `close.sheet`, or (with `csvRoles`) reads a CSV input and carries no
12
12
  * older `close.columns` / `close.cited` check (then every guardrail is Not checked).
13
13
  * @param {{declaration: any, lines: Array<{n: number, rules?: string[], guardrail?: string, rule?: string}>, csvRoles?: string[], record?: any}} o
14
- * `record` = the parsed `sheet-checks.json` (`{lines: [...]}`), only after a run
14
+ * `record` = the `sheet` section of `line-checks.json` (`{lines: [...]}`), only after a run
15
15
  * @returns {Array<{line: number, guardrails: string[], checked: Array<{id: string, name: string, words: string, covers: string[], coversWords: string, text: string, ok?: boolean, found?: string}>, notChecked: string[]|'none'}>}
16
16
  */
17
17
  export function sheetLineBlocks({ declaration, lines, csvRoles, record }: {
@@ -60,7 +60,7 @@ export function csvRolesOf(arbiter: any): string[];
60
60
  */
61
61
  export function claimLines(claims: unknown): string[];
62
62
  /**
63
- * M10b am4: what an ask card shows for the claim boxes it was given. The step is the sheet step whose saved try (`sheet-checks.json`) holds exactly these claims; its block is
63
+ * M10b am4: what an ask card shows for the claim boxes it was given. The step is the sheet step whose saved try (the `sheet` section of `line-checks.json`) holds exactly these claims; its block is
64
64
  * the Result tab's own (`sheetLineBlocks`, that try's verdicts), and `answer` is the claims value by value. Null when no saved try matches: the caller then keeps the old line.
65
65
  * @param {{claims: unknown, declaration: any, lines: Array<{n: number, rules?: string[], guardrail?: string, rule?: string}>, csvRoles?: string[], record?: any}} o
66
66
  * @returns {{block: ReturnType<typeof sheetLineBlocks>[number], answer: string[]}|null}
@@ -7,7 +7,7 @@ export function sheetRolesOf(steps: any[]): string[];
7
7
  */
8
8
  export function tableShaOfFrozen(runDir: string, name: string): string | null;
9
9
  /**
10
- * What a sheet check reads in a run: the run's OWN frozen copy of each sheet its checks name, as bareguard's table, and the `tableSha` recorded in `inputs.json` at
10
+ * What a sheet check reads in a run: the run's OWN frozen copy of each sheet its checks name, as bareguard's table, and the `tableSha` recorded in `run.json` (inputs) at
11
11
  * the run's start. The table is NOT compared here: bareguard compares it to the recorded sha when it checks (and stops if it differs).
12
12
  * @param {string} runDir @param {any[]} checks the step's `close.sheet`
13
13
  * @returns {{ok: true, tables: Record<string, {header: string[], rows: any[]}>, inputs: Array<{name: string, sha256: string}>}|{ok: false, red: string}}
@@ -40,7 +40,7 @@ export function catchUpWords(rec: any): "This run was a catch-up: it started mor
40
40
  * ENDED / NEXT of a finished run. Every outcome the history row can hold has a fixed sentence; an unknown one gets an honest fixed fallback
41
41
  * that names the code and guesses nothing. `null` when there is no ending (still running, waiting, or no history row and not died).
42
42
  * @param {{outcome: string|null, died?: boolean, line: number|null, destination: string|null, canResume: boolean, home?: string}} f
43
- * @returns {{reason: string, next: string}|null}
43
+ * @returns {{reason: string, next: string, rows?: Array<[string, string]>}|null}
44
44
  */
45
45
  export function endedWords(f: {
46
46
  outcome: string | null;
@@ -52,6 +52,7 @@ export function endedWords(f: {
52
52
  }): {
53
53
  reason: string;
54
54
  next: string;
55
+ rows?: Array<[string, string]>;
55
56
  } | null;
56
57
  /** "MM/DD HH:MM", local time: the same form as the run cards' `rlShortDate`. @param {number|string} when epoch ms or an ISO string */
57
58
  export function shortStamp(when: number | string): string;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @typedef {object} Paint
3
+ * @property {boolean} on
4
+ * @property {(s: string) => string} grey @property {(s: string) => string} green @property {(s: string) => string} yellow
5
+ * @property {(s: string) => string} red @property {(s: string) => string} cyan @property {(s: string) => string} boldCyan
6
+ */
7
+ /**
8
+ * Colour is on only for a terminal: the stream says it is a TTY, `NO_COLOR` is empty/unset, and `TERM` is not `dumb`.
9
+ * @param {{isTTY?: boolean}|undefined} stream the output stream (process.stdout)
10
+ * @param {Record<string, string|undefined>} [env]
11
+ * @returns {Paint}
12
+ */
13
+ export function makePaint(stream: {
14
+ isTTY?: boolean;
15
+ } | undefined, env?: Record<string, string | undefined>): Paint;
16
+ export namespace PLAIN {
17
+ let on: boolean;
18
+ let grey: (s: string) => string;
19
+ let green: (s: string) => string;
20
+ let yellow: (s: string) => string;
21
+ let red: (s: string) => string;
22
+ let cyan: (s: string) => string;
23
+ let boldCyan: (s: string) => string;
24
+ }
25
+ export type Paint = {
26
+ on: boolean;
27
+ grey: (s: string) => string;
28
+ green: (s: string) => string;
29
+ yellow: (s: string) => string;
30
+ red: (s: string) => string;
31
+ cyan: (s: string) => string;
32
+ boldCyan: (s: string) => string;
33
+ };