fwdloop 0.24.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 (49) 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/diary.js +21 -17
  6. package/src/flowmodel.js +6 -37
  7. package/src/keysfile.js +1 -1
  8. package/src/launcher.js +552 -0
  9. package/src/learnstore.js +6 -4
  10. package/src/line-checks.js +55 -0
  11. package/src/opener.js +33 -0
  12. package/src/panel/author.js +2 -0
  13. package/src/panel/authorflows.js +9 -9
  14. package/src/panel/authorresume.js +4 -3
  15. package/src/panel/data.js +3 -2
  16. package/src/panel/index.html +22 -8
  17. package/src/panel/result.js +7 -12
  18. package/src/panel/server.js +53 -5
  19. package/src/panel/settings.js +4 -18
  20. package/src/panel/spawn.js +0 -9
  21. package/src/prompts.js +33 -0
  22. package/src/runfile.js +60 -0
  23. package/src/runner.js +18 -17
  24. package/src/sheet-record.js +15 -35
  25. package/src/sheetblock.js +3 -3
  26. package/src/sheetrun.js +6 -6
  27. package/src/summary-words.js +13 -5
  28. package/src/tty-colour.js +29 -0
  29. package/types/cited-record.d.ts +0 -2
  30. package/types/diary.d.ts +2 -5
  31. package/types/flowmodel.d.ts +2 -21
  32. package/types/keysfile.d.ts +7 -0
  33. package/types/launcher.d.ts +307 -0
  34. package/types/learnstore.d.ts +1 -1
  35. package/types/line-checks.d.ts +26 -0
  36. package/types/opener.d.ts +12 -0
  37. package/types/panel/author.d.ts +2 -0
  38. package/types/panel/result.d.ts +1 -3
  39. package/types/panel/server.d.ts +24 -3
  40. package/types/panel/settings.d.ts +2 -2
  41. package/types/panel/spawn.d.ts +0 -6
  42. package/types/prompts.d.ts +14 -0
  43. package/types/runfile.d.ts +48 -0
  44. package/types/runner.d.ts +3 -3
  45. package/types/sheet-record.d.ts +0 -2
  46. package/types/sheetblock.d.ts +2 -2
  47. package/types/sheetrun.d.ts +1 -1
  48. package/types/summary-words.d.ts +2 -1
  49. package/types/tty-colour.d.ts +33 -0
package/src/runner.js CHANGED
@@ -74,7 +74,8 @@ import { appendChecks, nextRound } from './diary.js';
74
74
  import {
75
75
  doneRecord, happenedRecord, outputRecord, closeRecords,
76
76
  } from './try-checks.js';
77
- import { readJobThinking, writeRunThinking, writeRunModel, takeLearningsRecord } from './flowmodel.js';
77
+ import { readJobThinking, readModelRecord, takeLearningsRecord } from './flowmodel.js';
78
+ import { readRunInputs, writeRunStart } from './runfile.js';
78
79
  import { fetchPageText, isWebUrl } from './pagefetch.js';
79
80
  import {
80
81
  readResumeLock, recordPid, writeLockHolder, procStartOf, LOCK_NO_HOLDER,
@@ -415,7 +416,7 @@ export async function freezePage(dir, id, url, { fetchPage = fetchPageText } = {
415
416
  }
416
417
 
417
418
  /** Copy each named source into `<runDir>/inputs/`, hash the FROZEN copy
418
- * (never the original again after this), write `inputs.json`. An
419
+ * (never the original again after this) and return the manifest, which `runFlow` records as the `inputs` of `run.json` (M8b). An
419
420
  * unreadable source refuses by name. A source that is a web address
420
421
  * (M10 item 1) is fetched and frozen by `freezePage`, in the same manifest.
421
422
  * @param {string} runDir @param {Array<{id: string, path: string}>} sources
@@ -452,7 +453,6 @@ export async function freezeInputs(runDir, sources, { fetchPage, tableRoles = []
452
453
  }
453
454
  manifest.push(entry);
454
455
  }
455
- writeFileSync(join(runDir, 'inputs.json'), JSON.stringify(manifest, null, 2));
456
456
  return { ok: true, manifest };
457
457
  }
458
458
 
@@ -642,11 +642,9 @@ const citedRolesOf = (step) => (step?.close?.class === 'green' && typeof step.cl
642
642
  /** A frozen CSV input as `{kind:'cells', header, rows}` (the shape `addressCells` gives), checked against the sha256 recorded at freeze.
643
643
  * Same three outcomes as `readArtifactResult`: not an input of this run (`missing`), refused (`red`), or the cells. */
644
644
  function readInputCells(runDir, id) {
645
- const manifest = readFileInside(runDir, 'inputs.json');
646
- if (!manifest.ok) return manifest.missing ? { ok: false, missing: true } : { ok: false, missing: false, red: manifest.red };
647
- let entries;
648
- try { entries = JSON.parse(manifest.text); } catch (err) { return { ok: false, missing: false, red: `inputs.json is not valid JSON — ${err.message}` }; }
649
- const entry = Array.isArray(entries) ? entries.find((e) => e?.id === id) : undefined;
645
+ const manifest = readRunInputs(runDir);
646
+ if (!manifest.ok) return manifest.code === 'missing' ? { ok: false, missing: true } : { ok: false, missing: false, red: manifest.red };
647
+ const entry = manifest.entries.find((e) => e?.id === id);
650
648
  if (!entry || !isCellsPath(entry.frozen)) return { ok: false, missing: true };
651
649
  const file = readFileInside(runDir, `inputs/${basename(entry.frozen)}`);
652
650
  if (!file.ok) return file.missing ? { ok: false, missing: false, red: 'the frozen copy is missing' } : { ok: false, missing: false, red: file.red };
@@ -857,7 +855,7 @@ export async function runStepRalph({
857
855
  // cut this step short of (their numbering is in `attemptOffset`; a try the Stop cut mid-way is replaced by the new one, never counted
858
856
  // against the limit, so Resume always gets at least one new try).
859
857
  readStop = null, stepNo = 0, triesDone = 0,
860
- // M4d am29 item 2: the run's folder, where each try saves its checks (`checks.jsonl`, src/diary.js)
858
+ // M4d am29 item 2: the run's folder, where each try saves its checks (`diary.jsonl`, kind checks, src/diary.js)
861
859
  runDir = null,
862
860
  // the id of step stepNo-1 (null for step 1): a Stop before this step's first call words itself "after step N-1" and is filed under that step
863
861
  prevStepId = null,
@@ -1146,7 +1144,7 @@ export async function runStepRalph({
1146
1144
  * @param {() => string} [opts.clock] - returns the current ISO timestamp; defaults to the wall clock.
1147
1145
  * @param {string} opts.businessDate - the run's explicit "as of today", never the wall clock.
1148
1146
  * @param {number} [opts.ceilingUsd] - per-attempt ceiling override; the model's hold from Settings prices (`ceilingCostUsd`); absent = no hold.
1149
- * @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.
1147
+ * @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.
1150
1148
  * @param {string|null} [opts.initialGap] - M3 scope item 7 (rerun as a fresh
1151
1149
  * run): a human's rerun reason, carried as the FIRST ordinary step's
1152
1150
  * starting gap. Never used by a plain `runFlow` call outside `resumeRun`'s
@@ -1264,9 +1262,8 @@ export async function runFlow({
1264
1262
  });
1265
1263
  }
1266
1264
 
1267
- // M4d am25: the run keeps the job's "Thinking on" box as it is now (read by `readJobThinking` on every try and every resume)
1268
- writeRunThinking(flowDir, runDir);
1269
- if (runModel) writeRunModel(runDir, runModel); // M4d am33: the one record of the model this run started on
1265
+ // M4d am25: the run keeps the job's "Thinking on" box as it is now (read by `readJobThinking` on every try and every resume); taken here, recorded in `run.json` once the inputs are frozen
1266
+ const thinkingBox = readModelRecord(flowDir)?.thinking === true;
1270
1267
  // M8 item 6: the first run from a freshly signed flow takes the learnings its draft was handed (the Audit box); a run that kept its own plan already has its record; a failure never stops the run
1271
1268
  if (!runOwnsPlan(runDir)) {
1272
1269
  try { takeLearningsRecord(flowDir, runDir); } catch (/** @type {any} */ e) {
@@ -1280,6 +1277,8 @@ export async function runFlow({
1280
1277
  flowDir, runDir, runId, capUsd, startedAt, now, nowMs: getNowMs, signatureHash: signature.flow, outcome: 'preflight-red', red: frozen.red, spent: { value: 0 },
1281
1278
  });
1282
1279
  }
1280
+ // M8b item 1: the run's start record, written once: the model it started on (M4d am33), the "Thinking on" box (M4d am25) and the frozen inputs
1281
+ writeRunStart(runDir, { model: runModel ?? null, thinking: thinkingBox, inputs: /** @type {any[]} */ (frozen.manifest) });
1283
1282
  // M4c: every guard above has passed — this process records itself (pid row) before its first step.
1284
1283
  recordPid(runDir, 'run', now());
1285
1284
 
@@ -2072,7 +2071,7 @@ function sameRoot(recorded, requested) {
2072
2071
  * @param {() => string} [opts.clock]
2073
2072
  * @param {string} opts.businessDate
2074
2073
  * @param {number} [opts.ceilingUsd]
2075
- * @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.
2074
+ * @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.
2076
2075
  * @param {() => number} [opts.nowMs] - F45 finding 3; see `runFlow`'s own.
2077
2076
  * @param {(newRunDir:string) => void} [opts.onRerunStart] - amendment 16 C2: called with the new run's folder just before a `rerun` starts it.
2078
2077
  */
@@ -2382,7 +2381,7 @@ export async function resumeRun({
2382
2381
  }
2383
2382
  try {
2384
2383
  recordLateAnswerIfAny(runDir, now);
2385
- writeLog(runDir, { runId, outcome: 'rerun', attempts: [], artifacts: priorArtifactsForLog });
2384
+ writeLog(runDir, { runId, outcome: 'rerun', attempts: Array.isArray(readLog(runDir)?.attempts) ? readLog(runDir).attempts : [], artifacts: priorArtifactsForLog }); // F83: keep the earlier legs' tries
2386
2385
  } finally {
2387
2386
  // Amendment 16 C6/C7: the history end row is written last, and always.
2388
2387
  appendHistory(flowDir, {
@@ -2464,7 +2463,8 @@ export async function resumeRun({
2464
2463
  }
2465
2464
  }
2466
2465
 
2467
- const attemptsLog = [];
2466
+ // F83: log.json has one writer and it replaces the file, so this leg starts from the tries the earlier legs wrote (the pause's write)
2467
+ const attemptsLog = Array.isArray(readLog(runDir)?.attempts) ? [...readLog(runDir).attempts] : [];
2468
2468
  const auditRows = [];
2469
2469
  const recordAudit = (row, modelOutput, unjudgedCount) => {
2470
2470
  const fullRow = unjudgedCount === undefined ? row : { ...row, unjudgedCount };
@@ -2726,7 +2726,8 @@ export async function continueRun({
2726
2726
  acceptedAskEmitsThisRun.set(emits, recordedHashes.byEmits.get(emits) ?? null);
2727
2727
  }
2728
2728
  }
2729
- const attemptsLog = [];
2729
+ // F83: log.json has one writer and it replaces the file, so this leg starts from the tries the earlier legs wrote (the pause's write)
2730
+ const attemptsLog = Array.isArray(readLog(runDir)?.attempts) ? [...readLog(runDir).attempts] : [];
2730
2731
  const auditRows = [];
2731
2732
  const recordAudit = (row, modelOutput, unjudgedCount) => {
2732
2733
  const fullRow = unjudgedCount === undefined ? row : { ...row, unjudgedCount };
@@ -1,13 +1,8 @@
1
- // M10b piece 2: the ONE writer of `<run>/sheet-checks.json`, the record of what each sheet check said in this run, for the separate checker that re-runs a run's
1
+ // M10b piece 2 / M8b item 3: the writer of the `sheet` section of `<run>/line-checks.json` (the file's one writer is `writeLineSection`, src/line-checks.js), the record of what each sheet check said in this run, for the separate checker that re-runs a run's
2
2
  // signed checks against its saved sheet (M10b "Done when"). Append-only: one entry per (job line, try), written the moment that try's check has run, never replaced.
3
3
  // Shape: { lines: [ { n, try, passed, tables: [{name, tableSha}], checks: [the signed check objects], claims: <the step's answer>, results: [{id, text, ok, result}], red } ] }.
4
- // `tables[].tableSha` is the one recorded at the run's start (inputs.json), the one the check used. Throws away: nothing the check saw; no cell text is kept here.
5
- import { writeFileSync, renameSync } from 'node:fs';
6
- import { join } from 'node:path';
7
- import { readFileInside } from './flow.js';
8
-
9
- /** the record's name in the run's own folder */
10
- export const SHEET_CHECKS_FILE = 'sheet-checks.json';
4
+ // `tables[].tableSha` is the one recorded at the run's start (run.json), the one the check used. Throws away: nothing the check saw; no cell text is kept here.
5
+ import { readLineSection, writeLineSection } from './line-checks.js';
11
6
 
12
7
  const isRec = (/** @type {unknown} */ v) => v !== null && typeof v === 'object' && !Array.isArray(v);
13
8
 
@@ -18,28 +13,17 @@ const isRec = (/** @type {unknown} */ v) => v !== null && typeof v === 'object'
18
13
  export function writeSheetLine(runDir, { n, try: attempt, checks, closed }) {
19
14
  const rec = closed.sheetRecord;
20
15
  if (!rec) return;
21
- /** @type {any[]} */
22
- let lines = [];
23
- const had = readFileInside(runDir, SHEET_CHECKS_FILE);
24
- if (had.ok) {
25
- try {
26
- const parsed = JSON.parse(had.text);
27
- if (isRec(parsed) && Array.isArray(parsed.lines)) lines = parsed.lines;
28
- } catch { lines = []; }
29
- }
30
- if (lines.some((l) => isRec(l) && l.n === n && l.try === attempt)) return;
31
- lines.push({
32
- n, try: attempt, passed: closed.verdict === 'green',
33
- tables: rec.inputs.map((/** @type {any} */ i) => ({ name: i.name, tableSha: i.sha256 })),
34
- checks: JSON.parse(JSON.stringify(checks)),
35
- claims: rec.claims,
36
- results: rec.checks,
37
- red: closed.verdict === 'green' ? null : (closed.red ?? null),
16
+ writeLineSection(runDir, 'sheet', (had) => {
17
+ if (had.some((l) => isRec(l) && l.n === n && l.try === attempt)) return null;
18
+ return [...had, {
19
+ n, try: attempt, passed: closed.verdict === 'green',
20
+ tables: rec.inputs.map((/** @type {any} */ i) => ({ name: i.name, tableSha: i.sha256 })),
21
+ checks: JSON.parse(JSON.stringify(checks)),
22
+ claims: rec.claims,
23
+ results: rec.checks,
24
+ red: closed.verdict === 'green' ? null : (closed.red ?? null),
25
+ }];
38
26
  });
39
- const file = join(runDir, SHEET_CHECKS_FILE);
40
- const tmp = `${file}.tmp`;
41
- writeFileSync(tmp, `${JSON.stringify({ lines }, null, 2)}\n`);
42
- renameSync(tmp, file);
43
27
  }
44
28
 
45
29
  /**
@@ -48,10 +32,6 @@ export function writeSheetLine(runDir, { n, try: attempt, checks, closed }) {
48
32
  * @param {string} runDir @returns {{lines: any[]}|null}
49
33
  */
50
34
  export function readSheetChecks(runDir) {
51
- const got = readFileInside(runDir, SHEET_CHECKS_FILE);
52
- if (!got.ok) return null;
53
- try {
54
- const parsed = JSON.parse(got.text);
55
- return isRec(parsed) && Array.isArray(parsed.lines) ? { lines: parsed.lines } : null;
56
- } catch { return null; }
35
+ const got = readLineSection(runDir, 'sheet');
36
+ return got.ok ? { lines: got.lines } : null;
57
37
  }
package/src/sheetblock.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // M10b piece 4 (docs/wiki/the-module-ladder.md "M10b amendment 2", items 4 and 7): the ONE builder of what a job line that reads a sheet shows -
2
2
  // { guardrails, checked: [{id, name, words, covers, text}], notChecked: [guardrail, ...] | 'none' }
3
3
  // from the signed declaration (the step's `close.sheet`, each check's `covers` tag) and the job line's own `~` rules. After a run, `record` (the
4
- // `sheet-checks.json` lines, src/sheet-record.js) adds to each check its verdict and what was found: `{ok, found}`. Every surface (the Chat plan card, the Job tab, the
4
+ // the `sheet` section of `line-checks.json`, lines, src/sheet-record.js) adds to each check its verdict and what was found: `{ok, found}`. Every surface (the Chat plan card, the Job tab, the
5
5
  // Result tab, the Audit's check rows) shows this block's strings; none of them words a check itself.
6
6
  // Throws away: the check's id, claim, range and the other typed fields that do not change what it says (src/sheetchecks.js `sheetCheckSentence` drops them too).
7
7
  // A green "found" is the step's OWN claimed value in plain words (a number, or a count of rows / days / bands / groups); a string claim (a looked-up cell) is never
@@ -65,7 +65,7 @@ export const coversWords = (rules) => rules.map((r) => `covers "${r}"`).join('
65
65
  * 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
66
66
  * older `close.columns` / `close.cited` check (then every guardrail is Not checked).
67
67
  * @param {{declaration: any, lines: Array<{n: number, rules?: string[], guardrail?: string, rule?: string}>, csvRoles?: string[], record?: any}} o
68
- * `record` = the parsed `sheet-checks.json` (`{lines: [...]}`), only after a run
68
+ * `record` = the `sheet` section of `line-checks.json` (`{lines: [...]}`), only after a run
69
69
  * @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'}>}
70
70
  */
71
71
  export function sheetLineBlocks({ declaration, lines, csvRoles = [], record }) {
@@ -155,7 +155,7 @@ export function claimLines(claims) {
155
155
  }
156
156
 
157
157
  /**
158
- * 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
158
+ * 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
159
159
  * 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.
160
160
  * @param {{claims: unknown, declaration: any, lines: Array<{n: number, rules?: string[], guardrail?: string, rule?: string}>, csvRoles?: string[], record?: any}} o
161
161
  * @returns {{block: ReturnType<typeof sheetLineBlocks>[number], answer: string[]}|null}
package/src/sheetrun.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // M10b piece 2 (docs/wiki/the-module-ladder.md "M10b scope" items 5-6 and amendment 1): a sheet check at RUN time.
2
2
  // - the lock: at run start each CSV input a step's `close.sheet` names gets its `tableSha` (bareguard's fingerprint of the table made from the run's frozen copy)
3
- // written down once with that run's inputs (`freezeInputs` is the one writer of inputs.json and calls `tableShaOfFile`); here is how it is read back;
3
+ // written down once with that run's inputs (`freezeInputs` makes the manifest, `runFlow` records it in run.json, and it calls `tableShaOfFile`); here is how it is read back;
4
4
  // - the judge: `closeSheet` hands the signed checks, the step's typed answer and the run's table to bareguard's `checkStep`. No model grades.
5
5
  // Third outcomes, each named, never green: a sheet the run recorded no fingerprint for, a frozen copy that is missing, a table that no longer gives the recorded
6
6
  // `tableSha` (bareguard stops the check; the red names the input), any other stopped check.
@@ -9,6 +9,7 @@ import { basename } from 'node:path';
9
9
  import { createRubric, checkStep, renderGaps, tableSha } from 'bareguard';
10
10
  import { parseCsv, sheetTable } from './csv.js';
11
11
  import { readFileInside } from './flow.js';
12
+ import { readRunInputs } from './runfile.js';
12
13
  import { sheetCheckSentence, bareguardChecks } from './sheetchecks.js';
13
14
  import { sheetCheckName, sheetFoundWords } from './sheetblock.js';
14
15
 
@@ -37,16 +38,15 @@ export function tableShaOfFrozen(runDir, name) {
37
38
  const SHA_RE = /^[0-9a-f]{64}$/;
38
39
 
39
40
  /**
40
- * 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
41
+ * 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
41
42
  * 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).
42
43
  * @param {string} runDir @param {any[]} checks the step's `close.sheet`
43
44
  * @returns {{ok: true, tables: Record<string, {header: string[], rows: any[]}>, inputs: Array<{name: string, sha256: string}>}|{ok: false, red: string}}
44
45
  */
45
46
  export function readRunSheets(runDir, checks) {
46
- const manifest = readFileInside(runDir, 'inputs.json');
47
- if (!manifest.ok) return { ok: false, red: manifest.missing ? 'this run has no frozen inputs' : `inputs.json: ${manifest.red}` };
48
- let entries;
49
- try { entries = JSON.parse(manifest.text); } catch (err) { return { ok: false, red: `inputs.json is not valid JSON - ${/** @type {any} */ (err).message}` }; }
47
+ const manifest = readRunInputs(runDir);
48
+ if (!manifest.ok) return { ok: false, red: manifest.code === 'missing' ? 'this run has no frozen inputs' : manifest.red };
49
+ const { entries } = manifest;
50
50
  /** @type {Record<string, any>} */
51
51
  const tables = {};
52
52
  const inputs = [];
@@ -110,11 +110,19 @@ const stoppedAt = (line, rest) => (line === null ? `Stopped: ${rest}` : `Stopped
110
110
 
111
111
  const RERUN_NEXT = 'Run it again from the Chat card.';
112
112
 
113
+ /**
114
+ * M9 am24: a NEXT with more than one instruction is `rows` of [label, instruction], one per line (label muted, instruction in a second column).
115
+ * `next` stays the one string every other reader gets: the rows joined "label instruction", one per line. The only writer of both.
116
+ * @param {Array<[string, string]>} rows
117
+ * @returns {{next: string, rows: Array<[string, string]>}}
118
+ */
119
+ const splitNext = (rows) => ({ next: rows.map(([l, t]) => `${l} ${t}`).join('\n'), rows });
120
+
113
121
  /**
114
122
  * 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
115
123
  * that names the code and guesses nothing. `null` when there is no ending (still running, waiting, or no history row and not died).
116
124
  * @param {{outcome: string|null, died?: boolean, line: number|null, destination: string|null, canResume: boolean, home?: string}} f
117
- * @returns {{reason: string, next: string}|null}
125
+ * @returns {{reason: string, next: string, rows?: Array<[string, string]>}|null}
118
126
  */
119
127
  export function endedWords(f) {
120
128
  const {
@@ -129,12 +137,12 @@ export function endedWords(f) {
129
137
  case 'stopped':
130
138
  return { reason: 'Stopped by you.', next: resumeOrAgain };
131
139
  case 'cap-halt':
132
- return { reason: stoppedAt(line, 'the next try could not fit under the money cap.'), next: canResume ? 'Raise the cap and Resume from the Chat card.' : RERUN_NEXT };
140
+ return { reason: stoppedAt(line, 'the next try could not fit under the money cap.'), ...(canResume ? splitNext([['raise the cap:', 'Cap $ on the Chat card'], ['then:', 'Resume from the Chat card']]) : { next: RERUN_NEXT }) };
133
141
  case 'redo-halt':
134
142
  return { reason: stoppedAt(line, 'you rejected it.'), next: RERUN_NEXT };
135
143
  case 'ask-expired':
136
144
  case 'ask-timeout':
137
- return { reason: stoppedAt(line, 'nobody answered in time.'), next: 'Reopen it from the Ask tab, or run it again from the Chat card.' };
145
+ return { reason: stoppedAt(line, 'nobody answered in time.'), ...splitNext([['reopen it:', 'from the Ask tab'], ['or run it again:', 'from the Chat card']]) };
138
146
  case 'not-done':
139
147
  return { reason: stoppedAt(line, 'the step said it did not finish.'), next: RERUN_NEXT };
140
148
  case 'struck-out':
@@ -152,9 +160,9 @@ export function endedWords(f) {
152
160
  case 'rerun':
153
161
  return { reason: 'You ended this run on purpose; a fresh run was started.', next: 'Look at the newest run of this job.' };
154
162
  case 'preflight-red':
155
- return { reason: 'It did not start: the job could not pass its pre-run checks. Nothing was spent.', next: 'Fix what the Audit / logs tab names, then run it again from the Chat card.' };
163
+ return { reason: 'It did not start: the job could not pass its pre-run checks. Nothing was spent.', ...splitNext([['fix it:', 'what the Audit / logs tab names'], ['then:', 'run it again from the Chat card']]) };
156
164
  case 'refused':
157
- return { reason: 'It did not start: the run was refused. Nothing was spent.', next: 'The Audit / logs tab says why. Fix that, then run it again from the Chat card.' };
165
+ return { reason: 'It did not start: the run was refused. Nothing was spent.', ...splitNext([['see why:', 'the Audit / logs tab'], ['then:', 'fix that and run it again from the Chat card']]) };
158
166
  default: {
159
167
  // an unknown code: say so, name the code (from the books, capped), guess nothing
160
168
  const code = String(outcome).replace(/[^\w-]/g, '').slice(0, 40);
@@ -0,0 +1,29 @@
1
+ // borrowed-from: bareloop src/tty-colour.js@v0.47.1 (704d598)
2
+ // Adaptation: none.
3
+ // ONE place for terminal colour (the launcher's header, menu and messages). Colours wrap words and never change them: with colour off
4
+ // every helper returns its text untouched, so plain-text readers (tests, pipes, logs) see the same words.
5
+
6
+ const wrap = (/** @type {string} */ code) => (/** @type {string} */ s) => `\x1b[${code}m${s}\x1b[0m`;
7
+ const id = (/** @type {string} */ s) => s;
8
+
9
+ /**
10
+ * @typedef {object} Paint
11
+ * @property {boolean} on
12
+ * @property {(s: string) => string} grey @property {(s: string) => string} green @property {(s: string) => string} yellow
13
+ * @property {(s: string) => string} red @property {(s: string) => string} cyan @property {(s: string) => string} boldCyan
14
+ */
15
+
16
+ /**
17
+ * Colour is on only for a terminal: the stream says it is a TTY, `NO_COLOR` is empty/unset, and `TERM` is not `dumb`.
18
+ * @param {{isTTY?: boolean}|undefined} stream the output stream (process.stdout)
19
+ * @param {Record<string, string|undefined>} [env]
20
+ * @returns {Paint}
21
+ */
22
+ export function makePaint(stream, env = process.env) {
23
+ const on = Boolean(stream && stream.isTTY) && !(env.NO_COLOR ?? '') && env.TERM !== 'dumb';
24
+ if (!on) return { on, grey: id, green: id, yellow: id, red: id, cyan: id, boldCyan: id };
25
+ return { on, grey: wrap('90'), green: wrap('32'), yellow: wrap('33'), red: wrap('31'), cyan: wrap('36'), boldCyan: wrap('1;36') };
26
+ }
27
+
28
+ /** the no-colour paint, the default when a caller passes none */
29
+ export const PLAIN = makePaint(undefined, {});
@@ -17,5 +17,3 @@ export function citedLineOf({ n, part, results, check, confirmed, }: {
17
17
  * @param {string} runDir @param {Record<string, any>} line @returns {void}
18
18
  */
19
19
  export function writeCitedLine(runDir: string, line: Record<string, any>): void;
20
- /** the record's name in the run's own folder; the Result tab's reader takes it from here */
21
- export const CITED_CHECKS_FILE: "cited-checks.json";
package/types/diary.d.ts CHANGED
@@ -1,8 +1,4 @@
1
- export const DIARY_FILES: Readonly<{
2
- calls: "calls.jsonl";
3
- tools: "tools.jsonl";
4
- checks: "checks.jsonl";
5
- }>;
1
+ export const DIARY_FILE: "diary.jsonl";
6
2
  export function diaryPaths(runDir: string): string[];
7
3
  export function appendCall(runDir: string, row: {
8
4
  step: string | null;
@@ -55,3 +51,4 @@ export function readCalls(runDir: string): any[];
55
51
  export function readTools(runDir: string): any[];
56
52
  export function readChecks(runDir: string): any[];
57
53
  export function nextRound(runDir: string, step: string | null): any;
54
+ export type DiaryKind = "call" | "tool" | "checks";
@@ -17,35 +17,20 @@ export function writeModelRecord(dir: string, { slot, model, thinking }: {
17
17
  thinking?: boolean;
18
18
  }): void;
19
19
  /**
20
- * M4d am25: the ONE reader of the job's "Thinking on" box for a run. A run reads its OWN record (`<run>/thinking.json`, written once when the run
20
+ * M4d am25: the ONE reader of the job's "Thinking on" box for a run. A run reads its OWN record (`thinking` in `<run>/run.json`, written once when the run
21
21
  * started) when it has one; otherwise the flow folder's `model.json`. No record, an unreadable one, or one without `thinking` is box OFF: a job
22
22
  * signed before am25 stored nothing, and it must not start thinking on every try.
23
23
  * @param {string} flowDir @param {string|null} runDir @returns {boolean}
24
24
  */
25
25
  export function readJobThinking(flowDir: string, runDir: string | null): boolean;
26
26
  /**
27
- * M4d am26: the run's OWN record of the box (`<run>/thinking.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: string | null): boolean | null;
31
- /**
32
- * M4d am25: a run keeps the box as the job had it when the run started (write-once, so an Edit of the job never changes a run already going).
33
- * Written for every fresh run, ticked or not. @param {string} flowDir @param {string} runDir
34
- */
35
- export function writeRunThinking(flowDir: string, runDir: string): void;
36
- /**
37
- * M4d am33: the ONE reader of the model a run started on, or null (a run from before the record, or an unusable one: the caller then keeps today's pick).
27
+ * M4d am33: the ONE reader of the model a run started on (`model` in `<run>/run.json`), or null (a run from before the record, or an unusable one: the caller then keeps today's pick).
38
28
  * @param {string|null} runDir @returns {{ slot: string, model: string }|null}
39
29
  */
40
30
  export function readRunModel(runDir: string | null): {
41
31
  slot: string;
42
32
  model: string;
43
33
  } | null;
44
- /** M4d am33: the ONE writer, called once when a fresh run starts (`runFlow`); never over an existing record. @param {string} runDir @param {{ slot: string, model: string }} pick */
45
- export function writeRunModel(runDir: string, { slot, model }: {
46
- slot: string;
47
- model: string;
48
- }): void;
49
34
  /** @param {string} dir @param {{text: string, ids: string[]}} hints */
50
35
  export function writeLearningsRecord(dir: string, { text, ids }: {
51
36
  text: string;
@@ -77,10 +62,6 @@ export function readLearningsRecord(runDir: string): {
77
62
  chars: number;
78
63
  } | null;
79
64
  export const MODEL_FILE: "model.json";
80
- /** M4d am25: the file in a run's folder that keeps the box as the run started with it (outside `job/`, which holds the three signed files only). */
81
- export const RUN_THINKING_FILE: "thinking.json";
82
- /** M4d am33: the file in a run's folder that records the model the run STARTED on (write-once; every continue path keeps it). */
83
- export const RUN_MODEL_FILE: "run-model.json";
84
65
  /**
85
66
  * M8 item 5a: the file that keeps EXACTLY what the drafter was handed from earlier runs (the Audit box of item 6 reads it). Bareloop's
86
67
  * `learnings` spine record shape, `{phase, text, ids, chars}`. Write-once (never over an existing record); written with something handed, or by `writeLearningsError` with an empty `text`
@@ -25,6 +25,13 @@ export function chmodSentence(home?: string): string;
25
25
  * @returns {Record<string,string>}
26
26
  */
27
27
  export function parseKeysText(text: string): Record<string, string>;
28
+ /**
29
+ * Create the file when — and only when — it does not exist: mode 0600 (`wx`), dir 0700,
30
+ * the known key names as commented lines and nothing else.
31
+ * @param {string} [home]
32
+ * @returns {boolean} true if it was created
33
+ */
34
+ export function createKeysFile(home?: string): boolean;
28
35
  /**
29
36
  * @typedef {object} KeysLoad
30
37
  * @property {boolean} ok false = refused: nothing that needs a key may run