fwdloop 0.23.0 → 0.25.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 (71) hide show
  1. package/bin/fwdloop +62 -32
  2. package/package.json +1 -1
  3. package/src/ask.js +15 -1
  4. package/src/attemptdiff.js +118 -0
  5. package/src/audit-fold.js +2 -0
  6. package/src/authoring.js +32 -2
  7. package/src/cited-record.js +3 -22
  8. package/src/cited-source.js +5 -6
  9. package/src/citedwords.js +36 -2
  10. package/src/config.js +5 -1
  11. package/src/diary.js +21 -17
  12. package/src/drafter.js +6 -2
  13. package/src/flowmodel.js +52 -28
  14. package/src/keysfile.js +1 -1
  15. package/src/launcher.js +552 -0
  16. package/src/learn.js +952 -0
  17. package/src/learnstore.js +348 -0
  18. package/src/line-checks.js +55 -0
  19. package/src/model-step.js +2 -0
  20. package/src/opener.js +33 -0
  21. package/src/pagedry.js +3 -4
  22. package/src/pagefetch.js +9 -2
  23. package/src/pagerules.js +28 -5
  24. package/src/panel/author.js +2 -0
  25. package/src/panel/authorflows.js +9 -9
  26. package/src/panel/authorresume.js +4 -3
  27. package/src/panel/data.js +63 -14
  28. package/src/panel/index.html +162 -16
  29. package/src/panel/result.js +7 -12
  30. package/src/panel/server.js +53 -5
  31. package/src/panel/settings.js +4 -18
  32. package/src/panel/spawn.js +0 -9
  33. package/src/prompts.js +33 -0
  34. package/src/redact.js +6 -6
  35. package/src/runfile.js +60 -0
  36. package/src/runner.js +144 -33
  37. package/src/sheet-record.js +15 -35
  38. package/src/sheetblock.js +3 -3
  39. package/src/sheetrun.js +6 -6
  40. package/src/summary-words.js +13 -5
  41. package/src/thinking.js +11 -0
  42. package/src/tty-colour.js +29 -0
  43. package/types/ask.d.ts +7 -2
  44. package/types/attemptdiff.d.ts +38 -0
  45. package/types/cited-record.d.ts +0 -2
  46. package/types/citedwords.d.ts +14 -0
  47. package/types/diary.d.ts +2 -5
  48. package/types/drafter.d.ts +6 -1
  49. package/types/flowmodel.d.ts +37 -20
  50. package/types/keysfile.d.ts +7 -0
  51. package/types/launcher.d.ts +307 -0
  52. package/types/learn.d.ts +576 -0
  53. package/types/learnstore.d.ts +168 -0
  54. package/types/line-checks.d.ts +26 -0
  55. package/types/opener.d.ts +12 -0
  56. package/types/pagerules.d.ts +7 -0
  57. package/types/panel/author.d.ts +2 -0
  58. package/types/panel/data.d.ts +2 -1
  59. package/types/panel/result.d.ts +2 -4
  60. package/types/panel/server.d.ts +24 -3
  61. package/types/panel/settings.d.ts +2 -2
  62. package/types/panel/spawn.d.ts +0 -6
  63. package/types/prompts.d.ts +14 -0
  64. package/types/runfile.d.ts +48 -0
  65. package/types/runner.d.ts +14 -5
  66. package/types/sheet-record.d.ts +0 -2
  67. package/types/sheetblock.d.ts +2 -2
  68. package/types/sheetrun.d.ts +1 -1
  69. package/types/summary-words.d.ts +2 -1
  70. package/types/thinking.d.ts +11 -0
  71. package/types/tty-colour.d.ts +33 -0
@@ -376,7 +376,7 @@ function authorPost(res, url, body, author) {
376
376
  * real listening socket where that is simpler.
377
377
  * @param {import('node:http').IncomingMessage} req
378
378
  * @param {import('node:http').ServerResponse} res
379
- * @param {{ root: string, port: number, packagePath?: string, resumer: ReturnType<typeof createResumer>, settings: ReturnType<typeof createSettings>, author: ReturnType<typeof createAuthor>, now?: () => number }} opts
379
+ * @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
380
380
  */
381
381
  export function handleRequest(req, res, opts) {
382
382
  const method = req.method ?? 'GET';
@@ -510,7 +510,7 @@ export function handleRequest(req, res, opts) {
510
510
  return;
511
511
  }
512
512
  html = html.replace(/__FWDLOOP_PANEL_PORT__/g, String(opts.port));
513
- const version = readOwnVersion(opts.packagePath); // M4d am17: the header's number, read from fwdloop's own package.json at serve time
513
+ const version = opts.version !== undefined ? opts.version : readOwnVersion(opts.packagePath); // M4d am17: the header's number from fwdloop's own package.json; M4b am5 item 5: the one read at panel start (opts.version), not at serve time
514
514
  html = version === null ? html.replace(/v__FWDLOOP_VERSION__/g, 'version unknown').replace(/__FWDLOOP_VERSION__/g, '') : html.replace(/__FWDLOOP_VERSION__/g, version);
515
515
  html = html.replace(/__FWDLOOP_PLAN_CHECK_RULES__/g, () => JSON.stringify(pageRules())); // M4d am15: the one copy of the plain words
516
516
  if (method === 'HEAD') {
@@ -523,6 +523,13 @@ export function handleRequest(req, res, opts) {
523
523
  return;
524
524
  }
525
525
 
526
+ // M4b am4 item 7 (borrowed-from: bareloop src/panel/server.js@cb2e8a7): who is answering here, the launcher's probe (`fwdloop start|stop|status`). Read-only, no token;
527
+ // the Host guard above already holds. `drafts` = the open drafting card (opts.author.openDrafts), `schedules` = jobs with a live schedule.
528
+ if (pathname === '/api/whoami') {
529
+ send(200, whoamiPayload(opts));
530
+ return;
531
+ }
532
+
526
533
  const loaded = loadCatalogue();
527
534
  if (!loaded.ok) {
528
535
  sendText(res, 500, `catalogue failed to load: ${cleanPaths(loaded.reds.join('; '), opts.root)}`);
@@ -629,13 +636,50 @@ export function handleRequest(req, res, opts) {
629
636
  sendText(res, 404, 'not found');
630
637
  }
631
638
 
639
+ /**
640
+ * `GET /api/whoami` body (borrowed-from: bareloop src/panel/server.js@cb2e8a7 whoamiPayload, commit 98cbb1c version read at start).
641
+ * Adapted: app 'fwdloop'; `drafts` = `author.openDrafts()` (the open drafting card), `schedules` = the live schedules `author.trigger.scan()` finds.
642
+ * @param {{ port: number, version?: string|null, startedAt?: string, packagePath?: string, author?: ReturnType<typeof createAuthor> }} opts
643
+ */
644
+ function whoamiPayload(opts) {
645
+ const drafts = opts.author ? opts.author.openDrafts() : 0;
646
+ let schedules = 0;
647
+ try { schedules = opts.author ? opts.author.trigger.scan().length : 0; } catch { schedules = 0; }
648
+ const version = opts.version !== undefined ? opts.version : readOwnVersion(opts.packagePath);
649
+ return { app: 'fwdloop', version: version ?? 'unknown', pid: process.pid, port: opts.port, drafts, schedules, startedAt: opts.startedAt };
650
+ }
651
+
652
+ /**
653
+ * 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,
654
+ * 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
655
+ * in-memory ones and a stopped panel has none.
656
+ * borrowed-from: bareloop src/panel/server.js@c772d4e (runsListForCount); adapted: fwdloop's listRuns rows, no schedules-gave-up part (fwdloop has no such concept).
657
+ * @param {{ root: string, now?: () => number }} opts
658
+ * @returns {any[]} the rows of /api/runs
659
+ */
660
+ export function runsListForCount(opts) {
661
+ const loaded = loadCatalogue();
662
+ if (!loaded.ok) throw new Error(`catalogue failed to load: ${loaded.reds.join('; ')}`);
663
+ return listRuns({ root: opts.root, catalogue: loaded.primitives, ...(opts.now ? { now: opts.now } : {}) });
664
+ }
665
+
666
+ /**
667
+ * The ONE spelling of the panel's own address (the launcher prints and opens it too).
668
+ * borrowed-from: bareloop src/panel/server.js@9104b2b (panelUrl); adaptation: none.
669
+ * @param {number} boundPort
670
+ * @returns {string}
671
+ */
672
+ export function panelUrl(boundPort) {
673
+ return `http://127.0.0.1:${boundPort}`;
674
+ }
675
+
632
676
  /**
633
677
  * Start the panel server. Binds `127.0.0.1` ONLY. A taken port is a LOUD,
634
678
  * non-zero-exit failure — this never falls back to another port (see file
635
679
  * header). Resolves once actually listening; rejects on a bind error
636
680
  * (including `EADDRINUSE`) with a `.port` field on the error for the
637
681
  * caller's message.
638
- * @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
682
+ * @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
639
683
  * `resume` and `author` are for tests only (a fake env/bin, a short retry window); the CLI passes none.
640
684
  * @returns {Promise<{ server: import('node:http').Server, port: number, tick: () => void, close: () => Promise<void> }>}
641
685
  */
@@ -645,6 +689,10 @@ export function createPanelServer(opts) {
645
689
  }
646
690
  const requestedPort = opts.port ?? DEFAULT_PORT;
647
691
  const { root } = opts;
692
+ // M4b am5 item 5: the version THIS process runs, read once at start. package.json on disk can move on while the panel keeps running old code.
693
+ const version = readOwnVersion(opts.packagePath);
694
+ // M4b am6 item 1: when this panel started, set once here; whoami hands it out so the launcher can say how long ago.
695
+ const startedAt = new Date().toISOString();
648
696
  // One resumer per server: the one owner of every run's resume-attempt record.
649
697
  // M4d: the keys file is re-read before EVERY resume spawn (editing it needs no restart); an env injected by a test is the shell side.
650
698
  const resumer = createResumer({ root, loadEnv: () => keysForDoor({ env: opts.resume?.env }), ...opts.resume });
@@ -672,7 +720,7 @@ export function createPanelServer(opts) {
672
720
  const server = createServer((req, res) => {
673
721
  try {
674
722
  handleRequest(req, res, {
675
- root, port: boundPort, resumer, settings, author, packagePath: opts.packagePath, now: opts.author?.now,
723
+ root, port: boundPort, resumer, settings, author, version, startedAt, packagePath: opts.packagePath, now: opts.author?.now,
676
724
  });
677
725
  } catch (e) {
678
726
  sendText(res, 500, 'internal error');
@@ -726,7 +774,7 @@ export async function panelMain(argv, ctx) {
726
774
  const keys = keysForDoor();
727
775
  if (!keys.ok) ctx.err(String(keys.refusal));
728
776
  ctx.out(`fwdloop panel — (root: ${root}) (Ctrl-C to stop)`);
729
- ctx.out(`http://127.0.0.1:${boundPort}/`);
777
+ ctx.out(`${panelUrl(boundPort)}/`);
730
778
  // never resolves on its own — the process stays up until killed, same
731
779
  // shape any other long-running dev server takes.
732
780
  await new Promise(() => {});
@@ -21,7 +21,7 @@ import {
21
21
  import { SHAPES } from '../providershapes.js';
22
22
  import { keysForDoor, isKeyName } from '../keysfile.js';
23
23
  import { spendSummary } from '../monthly.js';
24
- import { spawnOpener as realSpawn } from './spawn.js';
24
+ import { openInOs } from '../opener.js';
25
25
  import { dirname } from 'node:path';
26
26
  import { homedir } from 'node:os';
27
27
 
@@ -32,7 +32,7 @@ const BROKEN_CONFIG = 'Your settings file (config.json) cannot be read. Fix or r
32
32
  const isNumberAbove0 = (v) => typeof v === 'number' && Number.isFinite(v) && v > 0;
33
33
 
34
34
  /**
35
- * @param {{ home?: string, skip?: boolean, env?: Record<string,string|undefined>, fetch?: typeof fetch, now?: () => number, openFolderSpawn?: Function, platform?: string }} cfg
35
+ * @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
36
36
  * `home` the config home (undefined = the real `~/.config/fwdloop`); `skip` true under a test process
37
37
  * with no `FWDLOOP_CONFIG_HOME` (Settings then touches nothing); `env` the shell side (tests only);
38
38
  * `fetch` and `now` are test seams.
@@ -181,22 +181,8 @@ export function createSettings(cfg) {
181
181
  const shown = keys().path;
182
182
  const dir = dirname(shown.startsWith('~') ? homedir() + shown.slice(1) : shown);
183
183
  const cannot = () => reply(200, { ok: true, opened: false, path: dir });
184
- const platform = cfg.platform ?? process.platform;
185
- const cmd = platform === 'linux' ? 'xdg-open' : (platform === 'darwin' ? 'open' : null);
186
- const opener = cfg.openFolderSpawn ?? (process.env.NODE_ENV === 'test' ? null : realSpawn);
187
- if (!cmd || !opener) return Promise.resolve(cannot());
188
- return new Promise((resolve) => {
189
- let child;
190
- try { child = opener(cmd, [dir], { detached: true, stdio: 'ignore' }); } catch { resolve(cannot()); return; }
191
- let settled = false;
192
- child.once('error', () => { if (!settled) { settled = true; resolve(cannot()); } });
193
- child.once('spawn', () => {
194
- if (settled) return;
195
- settled = true;
196
- if (typeof child.unref === 'function') child.unref();
197
- resolve(reply(200, { ok: true, opened: true, path: dir }));
198
- });
199
- });
184
+ return openInOs(dir, { platform: cfg.platform, spawnFn: cfg.openFolderSpawn, underTest: process.env.NODE_ENV === 'test' })
185
+ .then((opened) => (opened ? reply(200, { ok: true, opened: true, path: dir }) : cannot()));
200
186
  }
201
187
 
202
188
  async function test(body) {
@@ -17,15 +17,6 @@ import { keyValues } from '../keysfile.js';
17
17
  /** A pid whose liveness cannot be told (no /proc) counts as running only while its pid.json is this fresh (M4c's 10-minute rule). */
18
18
  const UNKNOWN_FRESH_MS = 10 * 60 * 1000;
19
19
 
20
- /**
21
- * The ONE spawn for the Settings "Open keys folder" button (borrowed-from: bareloop src/panel/settingsroutes.js@07c298f): the OS file manager
22
- * (`xdg-open` / `open`) on a folder the server chose, argv array, no shell, detached. Settings calls it only through its injected seam.
23
- * @param {string} cmd @param {string[]} args @param {import('node:child_process').SpawnOptions} o
24
- */
25
- export function spawnOpener(cmd, args, o) {
26
- return spawn(cmd, args, o);
27
- }
28
-
29
20
  /**
30
21
  * @param {{ bin: string, argv: string[], env: Record<string, string|undefined>, logPath: string }} a
31
22
  * @returns {import('node:child_process').ChildProcess} the child (already `unref()`ed; the log fd is closed here)
package/src/prompts.js ADDED
@@ -0,0 +1,33 @@
1
+ // borrowed-from: bareloop src/prompts.js@1bad2c8 (openAsker only; askRequired and the menu changes are not copied)
2
+ // The CLI's one line-asker. Every prompt in the launcher reads through this, so a closed stdin behaves the same everywhere.
3
+
4
+ import { createInterface } from 'node:readline';
5
+
6
+ /**
7
+ * One readline over `stdin`, with a LINE QUEUE: lines that arrive before the next question (piped input, a paste, or input that
8
+ * ends while the header is still waiting on the port probe) wait for it instead of being dropped, and a closed stdin answers ''
9
+ * (the safe default) and never hangs.
10
+ * @param {{ stdin?: any, stdout?: any }} [io]
11
+ * @returns {{ ask: (q: string) => Promise<string>, close: () => void }}
12
+ */
13
+ export function openAsker(io = {}) {
14
+ const stdout = io.stdout ?? process.stdout;
15
+ const stdin = io.stdin ?? process.stdin;
16
+ const tty = Boolean(stdin.isTTY);
17
+ // a real terminal needs readline's output to echo the typed line; piped input echoes nothing
18
+ const rl = createInterface({ input: stdin, ...(tty ? { output: stdout, terminal: true } : { terminal: false }) });
19
+ /** @type {string[]} */
20
+ const queue = [];
21
+ /** @type {((s: string) => void)[]} */
22
+ const waiting = [];
23
+ let closed = false;
24
+ rl.on('line', (line) => { const w = waiting.shift(); if (w) w(line); else queue.push(line); });
25
+ rl.once('close', () => { closed = true; while (waiting.length) /** @type {(s: string) => void} */ (waiting.shift())(''); });
26
+ const ask = (/** @type {string} */ q) => {
27
+ stdout.write(q);
28
+ if (queue.length) return Promise.resolve(/** @type {string} */ (queue.shift()));
29
+ if (closed) return Promise.resolve('');
30
+ return new Promise((resolve) => { waiting.push(resolve); });
31
+ };
32
+ return { ask, close: () => rl.close() };
33
+ }
package/src/redact.js CHANGED
@@ -1,16 +1,16 @@
1
1
  // The one secret inventory: known token shapes only, masked before a value is stored or written.
2
- // borrowed-from: bareloop src/validate.js@07215d6 (SECRET_PATTERNS). Its own module so a caller that only
2
+ // borrowed-from: bareloop src/validate.js@76168c8 (SECRET_PATTERNS; a key right after a hyphen is masked for the distinctive prefixes). Its own module so a caller that only
3
3
  // needs to mask (src/diary.js) does not pull litectx in through src/ctx-tools.js.
4
4
 
5
5
  import { redact } from 'bareguard';
6
6
 
7
7
  const SECRET_PATTERNS = [
8
8
  /(?<![A-Za-z0-9_-])sk-[A-Za-z0-9_-]{16,}/,
9
- /(?<![A-Za-z0-9_-])ghp_[A-Za-z0-9]{20,}/,
10
- /(?<![A-Za-z0-9_-])github_pat_[A-Za-z0-9_]{20,}/,
11
- /(?<![A-Za-z0-9_-])AKIA[0-9A-Z]{16}/,
12
- /(?<![A-Za-z0-9_-])xox[bap]-[A-Za-z0-9-]{10,}/,
13
- /(?<![A-Za-z0-9_-])AIza[0-9A-Za-z_-]{35}/,
9
+ /(?<![A-Za-z0-9_])ghp_[A-Za-z0-9]{20,}/,
10
+ /(?<![A-Za-z0-9_])github_pat_[A-Za-z0-9_]{20,}/,
11
+ /(?<![A-Za-z0-9_])AKIA[0-9A-Z]{16}/,
12
+ /(?<![A-Za-z0-9_])xox[bap]-[A-Za-z0-9-]{10,}/,
13
+ /(?<![A-Za-z0-9_])AIza[0-9A-Za-z_-]{35}/,
14
14
  ];
15
15
 
16
16
  /** Mask known secret shapes. @param {unknown} raw */
package/src/runfile.js ADDED
@@ -0,0 +1,60 @@
1
+ // M8b item 1: `run.json`, the run's start record - one file in the run's folder with three sections: `model` (the model the run started on, M4d am33),
2
+ // `thinking` (the job's "Thinking on" box as it was at the start, M4d am25) and `inputs` (the manifest `freezeInputs` made, M3/M10). Written once, by
3
+ // `writeRunStart` and nothing else; every reader of those three goes through this file's readers (`readRunModel` is in src/flowmodel.js, which owns the provider's
4
+ // key-name check). Kept free of the provider on purpose: the learnings note code reads `inputs` and must reach no provider module.
5
+ import { writeFileSync } from 'node:fs';
6
+ import { join } from 'node:path';
7
+ import { readFileInside } from './flow.js';
8
+
9
+ /** the file's name in the run's folder */
10
+ export const RUN_FILE = 'run.json';
11
+
12
+ /**
13
+ * 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.
14
+ * @param {string|null} runDir @returns {{ok: true, rec: Record<string, any>}|{ok: false, code: 'missing'|'unreadable'|'invalid', red: string}}
15
+ */
16
+ export function readRunRecord(runDir) {
17
+ if (typeof runDir !== 'string') return { ok: false, code: 'missing', red: `no ${RUN_FILE}` };
18
+ const r = readFileInside(runDir, RUN_FILE);
19
+ if (!r.ok) return r.missing ? { ok: false, code: 'missing', red: `no ${RUN_FILE}` } : { ok: false, code: 'unreadable', red: `${RUN_FILE}: ${r.red}` };
20
+ try {
21
+ const j = JSON.parse(r.text);
22
+ return j !== null && typeof j === 'object' && !Array.isArray(j) ? { ok: true, rec: j } : { ok: false, code: 'invalid', red: `${RUN_FILE} is not a JSON object` };
23
+ } catch (err) { return { ok: false, code: 'invalid', red: `${RUN_FILE} is not valid JSON — ${/** @type {any} */ (err).message}` }; }
24
+ }
25
+
26
+ /**
27
+ * 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).
28
+ * An unreadable record is box off, as `readJobThinking` has always read it. @param {string|null} runDir @returns {boolean|null}
29
+ */
30
+ export function readRunThinking(runDir) {
31
+ const got = readRunRecord(runDir);
32
+ if (!got.ok) return got.code === 'invalid' ? false : null;
33
+ return Object.hasOwn(got.rec, 'thinking') ? got.rec.thinking === true : null;
34
+ }
35
+
36
+ /**
37
+ * 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
38
+ * `inputs` section: a refusal at freeze leaves none); `unreadable` = the gateway refused the file; `invalid` = the section is not a list.
39
+ * @param {string|null} runDir
40
+ * @returns {{ok: true, entries: any[]}|{ok: false, code: 'missing'|'unreadable'|'invalid', red: string}}
41
+ */
42
+ export function readRunInputs(runDir) {
43
+ const got = readRunRecord(runDir);
44
+ if (!got.ok) return got;
45
+ if (!Object.hasOwn(got.rec, 'inputs')) return { ok: false, code: 'missing', red: `${RUN_FILE} has no inputs` };
46
+ return Array.isArray(got.rec.inputs) ? { ok: true, entries: got.rec.inputs } : { ok: false, code: 'invalid', red: `${RUN_FILE}: inputs is not a list` };
47
+ }
48
+
49
+ /**
50
+ * 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
51
+ * 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
52
+ * run, ticked or not), `inputs` the manifest `freezeInputs` returned. A section given as null is left out;
53
+ * a fresh run always has `thinking` and `inputs`.
54
+ * @param {string} runDir @param {{ model: { slot: string, model: string }|null, thinking: boolean|null, inputs: any[]|null }} start
55
+ */
56
+ export function writeRunStart(runDir, { model, thinking, inputs }) {
57
+ writeFileSync(join(runDir, RUN_FILE), `${JSON.stringify({
58
+ ...(model ? { model: { slot: model.slot, model: model.model } } : {}), ...(thinking === null ? {} : { thinking }), ...(inputs === null ? {} : { inputs }),
59
+ }, null, 2)}\n`, { mode: 0o600, flag: 'wx' });
60
+ }