fwdloop 0.38.0 → 0.40.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 (129) hide show
  1. package/README.md +6 -9
  2. package/bin/fwdloop +21 -19
  3. package/package.json +1 -1
  4. package/src/ask.js +70 -148
  5. package/src/audit-fold.js +6 -5
  6. package/src/auditchecks.js +6 -4
  7. package/src/authoring.js +32 -60
  8. package/src/blockasks.js +2 -1
  9. package/src/blockassemble.js +15 -3
  10. package/src/blockdraft.js +2 -2
  11. package/src/blockpick.js +42 -16
  12. package/src/books.js +237 -12
  13. package/src/checkblock.js +24 -44
  14. package/src/checklistsign.js +25 -3
  15. package/src/checklook.js +3 -1
  16. package/src/checkpick.js +6 -77
  17. package/src/cited-source.js +4 -4
  18. package/src/citedcheck.js +6 -11
  19. package/src/citedwords.js +9 -8
  20. package/src/closers.js +9 -6
  21. package/src/declaration.js +14 -49
  22. package/src/diary.js +23 -1
  23. package/src/draft-steps.js +11 -1
  24. package/src/drafter.js +18 -12
  25. package/src/draftfiles.js +127 -0
  26. package/src/draftspend.js +165 -17
  27. package/src/flow.js +42 -87
  28. package/src/flowmodel.js +1 -1
  29. package/src/index.js +3 -2
  30. package/src/inside.js +106 -0
  31. package/src/jsonl-append.js +33 -1
  32. package/src/learn.js +1 -1
  33. package/src/learnstore.js +20 -22
  34. package/src/line-checks.js +1 -1
  35. package/src/liveness.js +3 -0
  36. package/src/mcp-use.js +8 -9
  37. package/src/memo.js +13 -16
  38. package/src/model-step.js +2 -2
  39. package/src/page-words.js +8 -0
  40. package/src/pageask.js +8 -3
  41. package/src/pagebits.js +8 -1
  42. package/src/pagedropwords.js +1 -1
  43. package/src/pagerules.js +6 -3
  44. package/src/panel/author.js +99 -75
  45. package/src/panel/authorcard.js +21 -8
  46. package/src/panel/authorflows.js +3 -3
  47. package/src/panel/authorresume.js +3 -3
  48. package/src/panel/authorstart.js +15 -16
  49. package/src/panel/authortrigger.js +43 -70
  50. package/src/panel/data.js +186 -188
  51. package/src/panel/index.html +139 -115
  52. package/src/panel/jobgrid.js +3 -7
  53. package/src/panel/result.js +7 -10
  54. package/src/panel/resume.js +4 -3
  55. package/src/panel/scheduler.js +9 -9
  56. package/src/panel/server.js +8 -4
  57. package/src/panel/spawn.js +22 -11
  58. package/src/panel/tickets.js +2 -2
  59. package/src/pickrecord.js +51 -31
  60. package/src/placerule.js +3 -4
  61. package/src/plain-checks.js +1 -1
  62. package/src/planrebuild.js +19 -19
  63. package/src/primitives.js +1 -1
  64. package/src/provider.js +1 -1
  65. package/src/reasons.js +25 -0
  66. package/src/runfile.js +26 -2
  67. package/src/runner.js +57 -105
  68. package/src/runvalues.js +47 -24
  69. package/src/schedule-choices.js +41 -0
  70. package/src/schedule-shape.js +39 -0
  71. package/src/schedule.js +9 -8
  72. package/src/setup.js +20 -36
  73. package/src/shaperows.js +2 -2
  74. package/src/sheetblock.js +2 -2
  75. package/src/sheetbuild.js +5 -5
  76. package/src/sheetrun.js +4 -5
  77. package/src/summary-words.js +2 -1
  78. package/src/thinking.js +5 -2
  79. package/src/ticketrows.js +7 -28
  80. package/src/trigger-clock.js +9 -23
  81. package/src/trigger-files.js +30 -22
  82. package/src/trigger-tickets.js +15 -14
  83. package/src/try-checks.js +2 -1
  84. package/src/types.js +2 -0
  85. package/types/ask.d.ts +25 -20
  86. package/types/authoring.d.ts +7 -42
  87. package/types/blockpick.d.ts +1 -1
  88. package/types/books.d.ts +380 -4
  89. package/types/checkblock.d.ts +1 -23
  90. package/types/checklist.d.ts +3 -3
  91. package/types/checklistsign.d.ts +7 -0
  92. package/types/checkpick.d.ts +0 -21
  93. package/types/citedwords.d.ts +7 -4
  94. package/types/closers.d.ts +1 -0
  95. package/types/declaration.d.ts +4 -14
  96. package/types/diary.d.ts +14 -1
  97. package/types/draft-steps.d.ts +7 -0
  98. package/types/drafter.d.ts +1 -1
  99. package/types/draftfiles.d.ts +89 -0
  100. package/types/draftspend.d.ts +74 -0
  101. package/types/flow.d.ts +32 -54
  102. package/types/index.d.ts +3 -3
  103. package/types/inside.d.ts +71 -0
  104. package/types/jsonl-append.d.ts +20 -0
  105. package/types/learnstore.d.ts +0 -2
  106. package/types/liveness.d.ts +1 -0
  107. package/types/page-words.d.ts +6 -0
  108. package/types/pageask.d.ts +2 -0
  109. package/types/pagebits.d.ts +3 -0
  110. package/types/pagerules.d.ts +1 -0
  111. package/types/panel/author.d.ts +7 -3
  112. package/types/panel/authorcard.d.ts +0 -6
  113. package/types/panel/authorflows.d.ts +4 -4
  114. package/types/panel/authortrigger.d.ts +16 -2
  115. package/types/panel/data.d.ts +50 -16
  116. package/types/panel/spawn.d.ts +18 -2
  117. package/types/pickrecord.d.ts +29 -0
  118. package/types/reasons.d.ts +23 -0
  119. package/types/runfile.d.ts +14 -0
  120. package/types/runner.d.ts +6 -38
  121. package/types/runvalues.d.ts +17 -2
  122. package/types/schedule-choices.d.ts +9 -0
  123. package/types/schedule-shape.d.ts +15 -0
  124. package/types/sheetbuild.d.ts +1 -1
  125. package/types/thinking.d.ts +1 -0
  126. package/types/ticketrows.d.ts +0 -9
  127. package/types/trigger-clock.d.ts +3 -2
  128. package/types/trigger-files.d.ts +15 -4
  129. package/types/types.d.ts +8 -0
@@ -11,7 +11,8 @@
11
11
  import { createHash } from 'node:crypto';
12
12
  import { basename, join } from 'node:path';
13
13
 
14
- import { readFileInside } from '../flow.js';
14
+ import { readFileInside } from '../inside.js';
15
+ import { isFailedEnding, redWhyOf } from '../books.js';
15
16
  import { isCellsPath } from '../closers.js';
16
17
  import { readAcceptedHashesByEmits } from '../ask.js';
17
18
  import { notCheckedLabelOf } from '../checked.js';
@@ -21,7 +22,7 @@ import { flowTypeOf } from '../declaration.js';
21
22
  import { isAgree, readingOfQuestion } from '../pageask.js';
22
23
  import { lineRules } from '../pagebits.js';
23
24
  import { readLineSection, LINE_CHECKS_FILE } from '../line-checks.js';
24
- import { readChecks } from '../diary.js';
25
+ import { readChecks, newestChecksOf } from '../diary.js';
25
26
  import { sheetLineBlocks, csvRolesOf } from '../sheetblock.js';
26
27
  import { readSheetChecks } from '../sheet-record.js';
27
28
  import { tagged } from '../checkwords.js';
@@ -41,8 +42,6 @@ export const RESULT_YOU_CONFIRMED = '(you confirmed)';
41
42
  export const RESULT_DOOR_HEAD = 'waiting for you';
42
43
  export const RESULT_DOOR_ASK = 'the checks passed; is this what you wanted?';
43
44
 
44
- /** end-row outcomes that are not a failure of the job */
45
- const NOT_FAILED = new Set(['complete', 'stopped', 'cap-halt', 'rerun', 'ask-expired']);
46
45
  const FACT_KINDS = new Set(['phrase', 'value']);
47
46
  const isInt = (x) => Number.isInteger(x);
48
47
  const isStr = (x) => typeof x === 'string';
@@ -224,9 +223,8 @@ export function deliveredOf({
224
223
  function checksOfLine(stepsOfLine, diary) {
225
224
  const out = [];
226
225
  for (const st of stepsOfLine) {
227
- const rows = diary.filter((r) => r && r.step === st.emits && isInt(r.try) && Array.isArray(r.checks));
228
- const newest = rows.reduce((m, r) => (m === null || r.try >= m.try ? r : m), null);
229
- for (const c of newest ? newest.checks : []) if (c && isStr(c.text) && typeof c.ok === 'boolean') out.push({ ok: c.ok, text: c.by === 'you' || c.by === 'agent' || c.by === 'default' ? tagged(c.text, c.by) : c.text, result: isStr(c.result) ? c.result : null }); // hamr 2026-11-14: a check the plan's list built carries the tag of its row
226
+ const newest = newestChecksOf(diary, st.emits);
227
+ for (const c of newest ? newest.checks : []) if (c && isStr(c.text) && typeof c.ok === 'boolean') out.push({ ok: c.ok, text: tagged(c.text, c.by), result: isStr(c.result) ? c.result : null }); // hamr 2026-11-14: a check the plan's list built carries the tag of its row
230
228
  }
231
229
  return out;
232
230
  }
@@ -325,9 +323,8 @@ export function buildResult({
325
323
  // a run that failed delivered nothing: say its own first gap, never rows. A stop, a cap halt, a rerun and an expired ask are not a failure (the same
326
324
  // set `computeGlyph` colours `[✗]` by exclusion); a pause has no end row at all.
327
325
  let gap = null;
328
- if (historyRow && !NOT_FAILED.has(historyRow.outcome)) {
329
- const redRow = auditRows.findLast((r) => r.verdict === 'red' || r.verdict === 'not-done');
330
- gap = gapOf(isStr(logJson?.red) && logJson.red !== '' ? logJson.red : (redRow ? `${redRow.step}: ${redRow.gap}` : null));
326
+ if (historyRow && isFailedEnding(historyRow.outcome)) {
327
+ gap = gapOf(redWhyOf(logJson, auditRows));
331
328
  }
332
329
  const pages = [...new Set(urls.values())];
333
330
  return {
@@ -41,9 +41,10 @@ import {
41
41
  import { tmpdir } from 'node:os';
42
42
  import { dirname, join } from 'node:path';
43
43
  import { fileURLToPath } from 'node:url';
44
- import { scrub } from '../authoring.js';
44
+ import { scrub } from '../draftfiles.js';
45
45
  import { keyValues } from '../keysfile.js';
46
46
  import { spawnDetached } from './spawn.js';
47
+ import { consumedAnswerName } from '../books.js';
47
48
 
48
49
  const HERE = dirname(fileURLToPath(import.meta.url));
49
50
  const BIN = join(HERE, '..', '..', 'bin', 'fwdloop');
@@ -101,7 +102,7 @@ export function createResumer(opts) {
101
102
  /** One resume process. Resolves as soon as the books show the answer consumed,
102
103
  * or the child exited, or `deadline` passed — never waits for a long resume. */
103
104
  function tryOnce({ flow, runId, runDir, askId, logPath, deadline }) {
104
- const consumedPath = join(runDir, `answer.${askId}.consumed.json`);
105
+ const consumedPath = join(runDir, consumedAnswerName(askId));
105
106
  const loaded = loadEnv ? loadEnv() : { ok: true, env, refusal: null };
106
107
  if (!loaded.ok) return Promise.resolve({ kind: 'exited', code: null, sig: null, text: String(loaded.refusal) });
107
108
  const runEnv = loaded.env; // ONE object: the spawn env below AND the scrub list further down (POC (a) wiring rule)
@@ -163,7 +164,7 @@ export function createResumer(opts) {
163
164
  // append to, nor have its log deleted by, the first one's clean exit (M4c-fix item 7).
164
165
  const logPath = join(ensureLogDir(opts.logDir), `resume-${rootTag}-${rec.flow}-${rec.runId}-${randomBytes(4).toString('hex')}.log`);
165
166
  rec.logPath = logPath;
166
- const consumed = () => existsSync(join(runDir, `answer.${rec.askId}.consumed.json`));
167
+ const consumed = () => existsSync(join(runDir, consumedAnswerName(rec.askId)));
167
168
  for (let n = 1; n <= maxTries; n += 1) {
168
169
  if (rec.superseded) return;
169
170
  rec.tries = n;
@@ -14,15 +14,14 @@
14
14
  // 2. file kinds: `poll` of this job's file trigger; each file taken is already in the ledger (`ran`) BEFORE the fire.
15
15
  // A schedule change or a Cancel settles the queue in its own click (src/schedule.js `dropQueue` / `carryQueue`): no tick settles anything.
16
16
  // A failure on one job (a folder that went away) is written once to `triggers.jsonl` as `refused` and never stops the other jobs.
17
- import { due, readRows, recordFire } from '../trigger-clock.js';
18
- import {
19
- createFileTrigger, queueOf, readSeen, recheck, recordArrived, recordDropped, recordRan,
20
- } from '../trigger-files.js';
17
+ import { due, recordFire } from '../trigger-clock.js';
18
+ import { createFileTrigger, isFileKind, queueOf, recheck, recordArrived, recordDropped, recordRan } from '../trigger-files.js';
21
19
  import { ledgerOf } from '../schedule.js';
22
20
  import {
23
21
  TICKET_LOOK_MS, hasBaseline, lastSeen, lookTickets, recordLook, seenNumbers,
24
22
  } from '../trigger-tickets.js';
25
23
  import { readOutcomes } from './authortrigger.js';
24
+ import { readTriggerLedger } from '../jsonl-append.js';
26
25
 
27
26
  /**
28
27
  * @param {{ door: ReturnType<typeof import('./authortrigger.js').createTriggerDoor>, now?: () => number, intervalMs?: number, look?: typeof lookTickets, mcpConfig?: string }} opts
@@ -49,7 +48,7 @@ export function createScheduler(opts) {
49
48
  */
50
49
  function runQueue(job, ledger, nowMs) {
51
50
  const { sig } = job;
52
- let queue = queueOf(readSeen(ledger, sig));
51
+ let queue = queueOf(readTriggerLedger(ledger, sig));
53
52
  if (queue.length === 0) return;
54
53
  const key = (/** @type {string} */ sha, /** @type {Record<string, any>} */ r) => `${sha}|${r.outcome}|${r.why ?? ''}`; // a refusal is told once PER REASON; busy / monthly carry no `why`
55
54
  const spoken = new Set(readOutcomes(job.flowDir).filter((r) => typeof r.sha === 'string' && r.sig === sig).map((r) => key(r.sha, r)));
@@ -92,7 +91,7 @@ export function createScheduler(opts) {
92
91
  const first = !hasBaseline(ledger, sig);
93
92
  const watch = Array.isArray(trigger.watch) ? trigger.watch : [];
94
93
  // M13 piece 5 (F114f): the turn-on wrote the ticket number the first green run read; the first look baselines only tickets up to it
95
- const armedRow = first ? readRows(ledger, sig).find((r) => r.kind === 'armed') : undefined;
94
+ const armedRow = first ? readTriggerLedger(ledger, sig).find((r) => r.kind === 'armed') : undefined;
96
95
  const cut = Number.isInteger(armedRow?.ticketN) ? armedRow?.ticketN : undefined;
97
96
  const out = Promise.resolve(look({
98
97
  listUrl: trigger.list, mcp: { server: trigger.server, tool: trigger.tool }, ...(mcpConfig ? { configPath: mcpConfig } : {}),
@@ -119,11 +118,12 @@ export function createScheduler(opts) {
119
118
  if (trigger.kind === 'new-ticket') {
120
119
  startLook(job, key, ledger, nowMs);
121
120
  runQueue(job, ledger, nowMs);
122
- } else if (trigger.kind === 'file-updated' || trigger.kind === 'new-file') {
121
+ } else if (isFileKind(trigger.kind)) {
123
122
  let w = watchers.get(key);
124
123
  if (!w) {
124
+ const ft = /** @type {{kind: 'file-updated', path: string} | {kind: 'new-file', folder: string}} */ (trigger);
125
125
  w = createFileTrigger({
126
- mode: trigger.kind === 'new-file' ? 'new' : 'updated', target: trigger.kind === 'new-file' ? trigger.folder : trigger.path, ledger, sig,
126
+ mode: ft.kind === 'new-file' ? 'new' : 'updated', target: ft.kind === 'new-file' ? ft.folder : ft.path, ledger, sig,
127
127
  });
128
128
  watchers.set(key, w);
129
129
  }
@@ -132,7 +132,7 @@ export function createScheduler(opts) {
132
132
  for (const f of arrived) recordArrived(ledger, f, nowMs, sig); // THE writer of the file ledger: arrival time is this clock, never the file's mtime
133
133
  runQueue(job, ledger, nowMs);
134
134
  } else {
135
- const d = due(trigger, readRows(ledger, sig), nowMs);
135
+ const d = due(/** @type {import('../trigger-clock.js').Schedule} */ (trigger), readTriggerLedger(ledger, sig), nowMs);
136
136
  if (d.fire) {
137
137
  recordFire(ledger, d, nowMs, sig); // BEFORE the fire: a crash loses a run, never doubles one
138
138
  door.fire(job, {
@@ -48,6 +48,8 @@
48
48
 
49
49
  import { createServer } from 'node:http';
50
50
  import { readFileSync, realpathSync } from 'node:fs';
51
+ import { scheduleChoices } from '../schedule-choices.js';
52
+ import { pageWords } from '../page-words.js';
51
53
  import { pageRules } from '../plain-checks.js';
52
54
  import { readOwnVersion } from '../version.js';
53
55
  import path, { dirname, join } from 'node:path';
@@ -60,7 +62,7 @@ import { resolveRunDir } from '../flow.js';
60
62
  import { readAsk, requestStop, stopParkedRun } from '../runner.js';
61
63
  import { removeFromNeedsYou } from './needsyou.js';
62
64
  import {
63
- listRuns, listScheduled, summarizeJobs, RUNS_LIST_LIMITS, getRunDetail, getRunControls, getRunAudit, getRunJob, listStops, inboxOpenCount, getRunAsks, getRunResult, getJobGrid, getTicketList, getRunDownload, readSavedAnswer, hasConsumedAnswer, resolveFlowDir,
65
+ listRuns, listScheduled, summarizeJobs, RUNS_LIST_LIMITS, getRunDetail, getRunControls, getRunAudit, getRunJob, listStops, inboxOpenCount, getRunAsks, getRunResult, getJobGrid, getTicketList, getRunDownload, savedAnswerOf, hasConsumedAnswer, resolveFlowDir,
64
66
  } from './data.js';
65
67
  import { ticketAnyway, arriveAnywayOf } from './tickets.js';
66
68
  import { createResumer } from './resume.js';
@@ -157,7 +159,7 @@ function resolveRun(res, root, flow, runId) {
157
159
  * for it and none was consumed? Then a resume child still alive for the run is only closing.
158
160
  * @param {string} runDir @param {string} askId */
159
161
  function parkedOnYou(runDir, askId) {
160
- return readAsk(runDir)?.askId === askId && readSavedAnswer(runDir) === null && !hasConsumedAnswer(runDir, askId);
162
+ return readAsk(runDir)?.askId === askId && savedAnswerOf(runDir) === null && !hasConsumedAnswer(runDir, askId);
161
163
  }
162
164
 
163
165
  /**
@@ -243,7 +245,7 @@ function removeLockRoute(res, body, root, resumer) {
243
245
  const { flow, runId } = b;
244
246
  const runDir = resolveRun(res, root, flow, runId);
245
247
  if (runDir === null) return;
246
- const saved = readSavedAnswer(runDir);
248
+ const saved = savedAnswerOf(runDir);
247
249
  if (!saved) {
248
250
  refuse(res, 409, 'no-saved-answer', 'this run has no saved, unconsumed answer — a resume would have nothing to apply');
249
251
  return;
@@ -328,7 +330,7 @@ function resumeRoute(res, body, root, resumer) {
328
330
  const { flow, runId } = b;
329
331
  const runDir = resolveRun(res, root, flow, runId);
330
332
  if (runDir === null) return;
331
- const saved = readSavedAnswer(runDir);
333
+ const saved = savedAnswerOf(runDir);
332
334
  if (!saved) {
333
335
  refuse(res, 409, 'no-saved-answer', 'this run has no saved, unconsumed answer — a resume would have nothing to apply');
334
336
  return;
@@ -532,6 +534,8 @@ export function handleRequest(req, res, opts) {
532
534
  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
533
535
  html = version === null ? html.replace(/v__FWDLOOP_VERSION__/g, 'version unknown').replace(/__FWDLOOP_VERSION__/g, '') : html.replace(/__FWDLOOP_VERSION__/g, version);
534
536
  html = html.replace(/__FWDLOOP_PLAN_CHECK_RULES__/g, () => JSON.stringify(pageRules())); // M4d am15: the one copy of the plain words
537
+ html = html.replace(/__FWDLOOP_SCHEDULE_CHOICES__/g, () => JSON.stringify(scheduleChoices())); // M20 am5 item 1: the one list of schedule choices per flow type
538
+ html = html.replace(/__FWDLOOP_PAGE_WORDS__/g, () => JSON.stringify(pageWords())); // M20 am8a item 1: the origin tags, the decisions that need a reason and the draft phases, from their owners
535
539
  if (method === 'HEAD') {
536
540
  res.writeHead(200, { 'content-type': 'text/html; charset=utf-8', 'content-length': Buffer.byteLength(html) });
537
541
  res.end();
@@ -10,7 +10,7 @@ import { spawn } from 'node:child_process';
10
10
  import { closeSync, openSync, writeFileSync } from 'node:fs';
11
11
  import { join } from 'node:path';
12
12
 
13
- import { readFileInside } from '../flow.js';
13
+ import { readJsonFile } from '../flow.js';
14
14
  import { isFwdloopAlive, procStartOf } from '../liveness.js';
15
15
  import { keyValues } from '../keysfile.js';
16
16
 
@@ -44,11 +44,23 @@ export function writePidFile(dir, child) {
44
44
  writeFileSync(join(dir, 'pid.json'), `${JSON.stringify({ pid: child.pid, procStart: procStartOf(/** @type {number} */ (child.pid)), startedAt: Date.now() })}\n`, { mode: 0o600 });
45
45
  }
46
46
 
47
- /** One JSON file of a panel folder through the one safe gateway; null when missing, unreadable or not an object. @param {string} dir @param {string} rel */
48
- export function readJsonFile(dir, rel) {
49
- const r = readFileInside(dir, rel);
50
- if (!r.ok) return null;
51
- try { const j = JSON.parse(r.text); return j && typeof j === 'object' && !Array.isArray(j) ? j : null; } catch { return null; }
47
+ /**
48
+ * M20 am3 item 8: the ONE owner of "is the draft/start child alive": the child recorded in `<dir>/pid.json` (null when none is
49
+ * recorded) and whether it is ours and running now: true / false, or null when it cannot be told (no /proc). `childRunning` and the
50
+ * draft door's abandon both ask it.
51
+ * @param {string} dir
52
+ * @returns {{pid: number, procStart: string|null, startedAt: unknown, alive: boolean|null}|null}
53
+ */
54
+ export function childState(dir) {
55
+ const rec = readJsonFile(dir, 'pid.json');
56
+ if (!rec || !Number.isInteger(rec.pid)) return null;
57
+ const child = { pid: rec.pid, procStart: typeof rec.procStart === 'string' ? rec.procStart : null, startedAt: rec.startedAt };
58
+ return { ...child, alive: childAlive(child) };
59
+ }
60
+
61
+ /** The same question again for a child `childState` returned (the abandon loop asks it after each signal). @param {{pid: number, procStart: string|null}} child @returns {boolean|null} */
62
+ export function childAlive(child) {
63
+ return isFwdloopAlive(child.pid, child.procStart);
52
64
  }
53
65
 
54
66
  /**
@@ -57,11 +69,10 @@ export function readJsonFile(dir, rel) {
57
69
  * @param {string} dir
58
70
  */
59
71
  export function childRunning(dir) {
60
- const pid = readJsonFile(dir, 'pid.json');
61
- if (!pid || !Number.isInteger(pid.pid)) return false;
62
- const alive = isFwdloopAlive(pid.pid, typeof pid.procStart === 'string' ? pid.procStart : null);
63
- if (alive !== null) return alive;
64
- return typeof pid.startedAt === 'number' && Date.now() - pid.startedAt <= UNKNOWN_FRESH_MS;
72
+ const child = childState(dir);
73
+ if (!child) return false;
74
+ if (child.alive !== null) return child.alive;
75
+ return typeof child.startedAt === 'number' && Date.now() - child.startedAt <= UNKNOWN_FRESH_MS;
65
76
  }
66
77
 
67
78
  /**
@@ -5,11 +5,11 @@
5
5
  import { join } from 'node:path';
6
6
 
7
7
  import { readSchedule, ledgerOf } from '../schedule.js';
8
- import { readSeen } from '../trigger-files.js';
9
8
  import { compareNatural } from '../natural.js';
10
9
  import { readRunInputs } from '../runfile.js';
11
10
  import { recordAnyway } from '../trigger-tickets.js';
12
11
  import { isTicketNumber, TICKET_NUMBER_WORDS } from '../ticket-shape.js';
12
+ import { readTriggerLedger } from '../jsonl-append.js';
13
13
 
14
14
  /** the four groups, in the mockup's order: key, label, open at first. The page draws them; it types none of these words. */
15
15
  export const TICKET_GROUPS = Object.freeze([
@@ -41,7 +41,7 @@ export function ticketListOf({ flowDir, runId, runIdsOf, glyphOf, atOf = () => n
41
41
  const sched = ticketScheduleOf(flowDir, runId, readSched);
42
42
  if (!sched) return null;
43
43
  const arrivals = new Map();
44
- for (const r of /** @type {any[]} */ (readSeen(ledgerOf(flowDir), sched.sig))) {
44
+ for (const r of /** @type {any[]} */ (readTriggerLedger(ledgerOf(flowDir), sched.sig))) {
45
45
  if (r.kind !== 'arrived' || !Number.isInteger(r.number)) continue;
46
46
  const a = arrivals.get(r.number) ?? { first: r.at, last: r.at, count: 0, reason: null };
47
47
  arrivals.set(r.number, { first: Math.min(a.first, r.at), last: Math.max(a.last, r.at), count: a.count + 1, reason: typeof r.reason === 'string' ? r.reason : a.reason });
package/src/pickrecord.js CHANGED
@@ -4,7 +4,13 @@
4
4
  // (`entriesFromAnswers`) and the only reader that decides keep-or-ask (`matchRecord`); the logic is the one F146 / F146b proved (poc/m10-am17/keep-picks-am18.mjs).
5
5
  // Throws away: line and rule numbers (recomputed), the model's words (it never sees a pick), a pick whose line or guardrail words no longer match.
6
6
  import path from 'node:path';
7
- import { readFileInside } from './flow.js';
7
+ import { readFileInside } from './inside.js';
8
+ import { readJsonFile } from './flow.js';
9
+
10
+ /** M20 am8: the one list of a person's row choices on the plan card, and the one question "is this a legal Drop or Add choice" (the row-edit door, the record's reader and the check block ask it) */
11
+ export const ROW_CHOICES = Object.freeze(['drop', 'add']);
12
+ /** @param {unknown} choice @returns {boolean} */
13
+ export const isRowChoice = (choice) => ROW_CHOICES.includes(/** @type {string} */ (choice));
8
14
 
9
15
  /** the record's file, inside a drafting folder only (never a run folder) */
10
16
  export const RECORD_FILE = 'picks-record.json';
@@ -96,12 +102,8 @@ export function matchRecord(entries, lines, rules) {
96
102
  * @param {string} file @returns {Entry[]|null}
97
103
  */
98
104
  export function readRecordFile(file) {
99
- try {
100
- const g = readFileInside(path.dirname(file), path.basename(file));
101
- if (!g.ok) return null;
102
- const j = JSON.parse(g.text);
103
- return Array.isArray(j?.picks) ? j.picks.filter((/** @type {any} */ e) => e && typeof e.lineWords === 'string' && Number.isInteger(e.occurrence) && typeof e.ruleText === 'string') : null;
104
- } catch { return null; }
105
+ const j = readJsonFile(path.dirname(file), path.basename(file));
106
+ return Array.isArray(j?.picks) ? j.picks.filter((/** @type {any} */ e) => e && typeof e.lineWords === 'string' && Number.isInteger(e.occurrence) && typeof e.ruleText === 'string') : null;
105
107
  }
106
108
 
107
109
  // borrowed-from: bareloop src/pickrecord.js@v0.56.0 (3383cce) (readRowChoices; read through readFileInside; writeRecordPart not taken, see the M16 p1 report)
@@ -110,12 +112,8 @@ export function readRecordFile(file) {
110
112
  * @param {string} file @returns {{lineWords: string, occurrence: number, tail: string, choice: string}[]|null}
111
113
  */
112
114
  export function readRowChoices(file) {
113
- try {
114
- const g = readFileInside(path.dirname(file), path.basename(file));
115
- if (!g.ok) return null;
116
- const j = JSON.parse(g.text);
117
- return Array.isArray(j?.rowChoices) ? j.rowChoices.filter((/** @type {any} */ e) => e && typeof e.lineWords === 'string' && Number.isInteger(e.occurrence) && typeof e.tail === 'string' && (e.choice === 'drop' || e.choice === 'add')) : null;
118
- } catch { return null; }
115
+ const j = readJsonFile(path.dirname(file), path.basename(file));
116
+ return Array.isArray(j?.rowChoices) ? j.rowChoices.filter((/** @type {any} */ e) => e && typeof e.lineWords === 'string' && Number.isInteger(e.occurrence) && typeof e.tail === 'string' && isRowChoice(e.choice)) : null;
119
117
  }
120
118
 
121
119
  // borrowed-from: bareloop src/pickrecord.js@v0.61.0 (fc56e1f3) (readShapeDropped; read through readFileInside like readSheetDropped; writeRecordPart not taken: fwd's writers are src/authoring.js and src/planrebuild.js)
@@ -124,12 +122,8 @@ export function readRowChoices(file) {
124
122
  * @param {string} file @returns {{lineWords: string, occurrence: number, name?: string, rule?: number}[]|null}
125
123
  */
126
124
  export function readShapeDropped(file) {
127
- try {
128
- const g = readFileInside(path.dirname(file), path.basename(file));
129
- if (!g.ok) return null;
130
- const j = JSON.parse(g.text);
131
- return Array.isArray(j?.shapeDropped) ? j.shapeDropped.filter((/** @type {any} */ d) => d && typeof d.lineWords === 'string' && Number.isInteger(d.occurrence) && (typeof d.name === 'string' || Number.isInteger(d.rule))) : null;
132
- } catch { return null; }
125
+ const j = readJsonFile(path.dirname(file), path.basename(file));
126
+ return Array.isArray(j?.shapeDropped) ? j.shapeDropped.filter((/** @type {any} */ d) => d && typeof d.lineWords === 'string' && Number.isInteger(d.occurrence) && (typeof d.name === 'string' || Number.isInteger(d.rule))) : null;
133
127
  }
134
128
 
135
129
  /**
@@ -138,12 +132,8 @@ export function readShapeDropped(file) {
138
132
  * @param {string} file @returns {{key: string, line: number, index: number, check: Record<string, any>, text: string}[]|null}
139
133
  */
140
134
  export function readSheetDropped(file) {
141
- try {
142
- const g = readFileInside(path.dirname(file), path.basename(file));
143
- if (!g.ok) return null;
144
- const j = JSON.parse(g.text);
145
- return Array.isArray(j?.sheetDropped) ? j.sheetDropped.filter((/** @type {any} */ d) => d && typeof d.key === 'string' && Number.isInteger(d.line) && d.check && typeof d.check === 'object' && !Array.isArray(d.check)) : null;
146
- } catch { return null; }
135
+ const j = readJsonFile(path.dirname(file), path.basename(file));
136
+ return Array.isArray(j?.sheetDropped) ? j.sheetDropped.filter((/** @type {any} */ d) => d && typeof d.key === 'string' && Number.isInteger(d.line) && d.check && typeof d.check === 'object' && !Array.isArray(d.check)) : null;
147
137
  }
148
138
 
149
139
  /**
@@ -152,12 +142,8 @@ export function readSheetDropped(file) {
152
142
  * @param {string} file @returns {{lineWords: string, occurrence: number, word: string, column: string}[]|null}
153
143
  */
154
144
  export function readColumns(file) {
155
- try {
156
- const g = readFileInside(path.dirname(file), path.basename(file));
157
- if (!g.ok) return null;
158
- const j = JSON.parse(g.text);
159
- return Array.isArray(j?.columns) ? j.columns.filter((/** @type {any} */ e) => e && typeof e.lineWords === 'string' && Number.isInteger(e.occurrence) && typeof e.word === 'string' && typeof e.column === 'string') : null;
160
- } catch { return null; }
145
+ const j = readJsonFile(path.dirname(file), path.basename(file));
146
+ return Array.isArray(j?.columns) ? j.columns.filter((/** @type {any} */ e) => e && typeof e.lineWords === 'string' && Number.isInteger(e.occurrence) && typeof e.word === 'string' && typeof e.column === 'string') : null;
161
147
  }
162
148
 
163
149
  /** @param {{n: number, text: string}[]} lines @param {{line: number, word: string, column: string}[]} cols @returns {{lineWords: string, occurrence: number, word: string, column: string}[]} the answers as the record keeps them */
@@ -172,5 +158,39 @@ export function columnsOnLines(entries, lines) {
172
158
  return entries.flatMap((e) => { const n = byKey.get(`${e.lineWords}#${e.occurrence}`); return n === undefined ? [] : [{ line: n, word: e.word, column: e.column }]; });
173
159
  }
174
160
 
161
+ /**
162
+ * M20 am3e item 19: the record's `kept` list, the ONE reader (the plan card, the setup row and the sign-time card check all ask it). `kept` is the list as written, or null
163
+ * when there is none to read (no file, refused by the gateway, not a JSON object, no list). `torn` tells an unreadable record from an empty one: the file was read and
164
+ * is not JSON. The sign-time card check skips on a torn record; the other two read it as no list.
165
+ * @param {string} dir the folder that holds the plan folder @param {string} [rel] `draft`, `draft-<n>` or `.` (the plan folder itself)
166
+ * @returns {{kept: any[]|null, torn: boolean}}
167
+ */
168
+ export function readKept(dir, rel = '.') {
169
+ const g = readFileInside(dir, `${rel}/${RECORD_FILE}`);
170
+ if (!g.ok) return { kept: null, torn: false };
171
+ let j;
172
+ try { j = JSON.parse(g.text); } catch { return { kept: null, torn: true }; }
173
+ return { kept: j !== null && typeof j === 'object' && !Array.isArray(j) && Array.isArray(j.kept) ? j.kept : null, torn: false };
174
+ }
175
+
176
+ /**
177
+ * M20 am4: the counts the person switched on with Add, from the plan's `rowChoices` (the entries `readRowChoices` gives, or the block's own `choicesRecord()`): a set of
178
+ * `<line>:min:<n>` / `<line>:max:<n>` strings, one per number of an Added `count.<min>-<max>` row, the line found by its words as the record ties it. The count check
179
+ * (src/citedwords.js `countReds`) reads a number in this set as said: the Add says it.
180
+ * @param {{lineWords: string, occurrence: number, tail: string, choice: string}[]|null|undefined} entries @param {{n: number, text: string}[]} lines @returns {Set<string>}
181
+ */
182
+ export function addedCountsOf(entries, lines) {
183
+ const out = new Set();
184
+ const keys = lineKeys(lines);
185
+ for (const e of entries ?? []) {
186
+ const m = e.choice === 'add' ? /^count\.(\d*)-(\d*)$/.exec(e.tail) : null;
187
+ const line = m === null ? undefined : [...keys].find(([, k]) => k.lineWords === e.lineWords && k.occurrence === e.occurrence)?.[0];
188
+ if (m === null || line === undefined) continue;
189
+ if (m[1] !== '') out.add(`${line}:min:${m[1]}`);
190
+ if (m[2] !== '') out.add(`${line}:max:${m[2]}`);
191
+ }
192
+ return out;
193
+ }
194
+
175
195
  /** where a plan folder keeps its record @param {string} planDir */
176
196
  export const recordPath = (planDir) => path.join(planDir, RECORD_FILE);
package/src/placerule.js CHANGED
@@ -9,8 +9,8 @@
9
9
  // This module is the graduation (a REWRITE, never a copy) of the round-3 POC (F321). Pure except `lastPlaceRead`, which reads earlier runs' spines.
10
10
 
11
11
  import path from 'node:path';
12
- import { readFileInside, readdirInside } from './flow.js';
13
- import { readRunRecord } from './runfile.js';
12
+ import { readFileInside, readdirInside } from './inside.js';
13
+ import { readPlaceRows } from './runfile.js';
14
14
 
15
15
  /** the two rule kinds on the menu: the version in a heading, and the date on the same heading line */
16
16
  export const PLACE_KINDS = Object.freeze(['headingBetween', 'headingDateAfter']);
@@ -390,8 +390,7 @@ export function lastRunPlaceRead({ flowDir, runId }) {
390
390
  /** @type {Record<string, string>} */
391
391
  const out = {};
392
392
  for (const r of earlier) {
393
- const got = readRunRecord(path.join(flowDir, 'runs', r.id));
394
- const rows = got.ok && Array.isArray(got.rec.placeRules?.rows) ? got.rec.placeRules.rows : [];
393
+ const rows = readPlaceRows(path.join(flowDir, 'runs', r.id)) ?? [];
395
394
  for (const row of rows) if (isRec(row) && row.found === true && typeof row.value === 'string' && !Object.hasOwn(out, String(row.key))) out[String(row.key)] = row.value;
396
395
  }
397
396
  return out;
@@ -25,7 +25,7 @@ export const PLAN_CHECK_RULES = Object.freeze([
25
25
  { re: /send at line \d+ .* is not granted a catalogue primitive of class "write"/, say: 'Your last line sends to your Destination, but your job puts other work on it. Make your last line the one that sends, or move that work above it, then Draft again.', fix: 'Make your last line the one that sends, or move that work above it, then Draft again.', first: true },
26
26
  { re: /send at line \d+|signed send at line|send slot/, say: 'The send step is not set up to follow your accept and write only to your destination.', fix: 'Check the Destination on the card, then Draft again.' },
27
27
  { re: /hitl after the last signed ask/, say: 'A step after your last ask would leave without your seeing it, so it is refused.', fix: 'Move the lines you want to check before your last Ask line, then Draft again.' },
28
- { re: /is a pause .* unsigned line/, say: 'A step pauses at a line you did not sign as an ask.', fix: 'Mark the line you want to stop at with Ask, then Draft again.' },
28
+ { re: /is a pause .* unsigned line/, say: 'A step in the plan has nothing to do at one of your lines.', fix: 'Draft again. If you want the run to stop for you at that line, start the line with Ask.' },
29
29
  { re: /neither served by any step/, say: 'A line of your job is not covered by any step.', fix: 'Make every line of your job say one thing to do, then Draft again.' },
30
30
  { re: /picks|inputFacts|invented name/, say: 'The plan names a field that is not in your input.', fix: 'Check the names in your Inputs and job line, then Draft again.' },
31
31
  { re: /guardrailClasses|unjudgeable|refused/, say: "The AI's notes on which lines it can check are not in a form the checker accepts.", fix: 'Draft again.' },
@@ -7,7 +7,8 @@
7
7
  // What this throws away: nothing of the old plan (it is never rewritten, records are write-once).
8
8
  import path from 'node:path';
9
9
  import { parseSignedText } from './signed-text.js';
10
- import { readFileInside, readdirInside } from './flow.js';
10
+ import { readDraftLog, readJsonFile } from './flow.js';
11
+ import { readFileInside, readdirInside } from './inside.js';
11
12
  import { readInputFacts } from './input-facts.js';
12
13
  import { blockJobLines } from './blocklines.js';
13
14
  import { setUpBlock, ticketLeaveOut, pickEdits, ledgerEdits } from './blockdraft.js';
@@ -17,7 +18,7 @@ import { ledgerRowsOf } from './checkrows.js';
17
18
  import { editsOf } from './rowedit.js';
18
19
  import { NOTE_KIND } from './noteask.js';
19
20
  import { offerRules, rowsFromAnswer, codeScope } from './checkpick.js';
20
- import { matchRecord, readRowChoices, RECORD_FILE } from './pickrecord.js';
21
+ import { matchRecord, readRowChoices, addedCountsOf, RECORD_FILE } from './pickrecord.js';
21
22
  import { listLinesOf, cardLinesOf } from './checklistsign.js';
22
23
  import { csvRolesOf } from './sheetblock.js';
23
24
  import { withTicketRows } from './ticketrows.js';
@@ -30,7 +31,8 @@ import { docRolesOf } from './drafter.js';
30
31
  import { buildShapes } from './shapebuild.js';
31
32
  import { parseShapeAnswer, SHAPE_CALL_LABEL } from './shapelook.js';
32
33
  import { lineRules } from './pagebits.js';
33
- import { buildReadout, specHash, PAGES_DIR, NOT_CHECKED_FILE } from './authoring.js';
34
+ import { buildReadout, specHash, PAGES_DIR } from './authoring.js';
35
+ import { NOT_CHECKED_FILE, SPEC_HASH_FILE, readNotCheckedFile, readPlanTexts } from './draftfiles.js';
34
36
 
35
37
  /** what a person is told when the saved inputs no longer give the saved list: nothing is written */
36
38
  export const REBUILD_CHANGED_SAY = 'The inputs of this plan have changed since it was drafted, so its checks cannot be changed here. Draft again from the card. Nothing was changed.';
@@ -38,7 +40,6 @@ export const REBUILD_CHANGED_SAY = 'The inputs of this plan have changed since i
38
40
  export const NO_LIST_SAY = 'This plan has no list of checks to change. Nothing was changed.';
39
41
 
40
42
  const isRec = (/** @type {unknown} */ v) => v !== null && typeof v === 'object' && !Array.isArray(v);
41
- const readJson = (/** @type {string} */ dir, /** @type {string} */ rel) => { const r = readFileInside(dir, rel); if (!r.ok) return null; try { return JSON.parse(r.text); } catch { return null; } };
42
43
 
43
44
  /**
44
45
  * Rebuild the block of a saved plan at $0. `choices` = the Drop/Add choices the plan was made with (its record's `rowChoices`).
@@ -47,17 +48,15 @@ const readJson = (/** @type {string} */ dir, /** @type {string} */ rel) => { con
47
48
  */
48
49
  export function rebuildBlock({ planDir, asks }) {
49
50
  const no = (/** @type {string} */ say) => ({ ok: /** @type {const} */ (false), say });
50
- const prose = readFileInside(planDir, 'prose.txt');
51
- const parsed = prose.ok ? parseSignedText(prose.text) : null;
52
- const declaration = readJson(planDir, 'declaration.json');
53
- if (!prose.ok || !parsed || !parsed.ok || !isRec(declaration)) return no('This plan could not be read. Nothing was changed.');
51
+ const { proseText, parsed, declaration } = readPlanTexts(planDir);
52
+ if (proseText === null || !parsed || !parsed.ok || !isRec(declaration)) return no('This plan could not be read. Nothing was changed.');
54
53
  // the lines the block was given; a CSV job's sheet lines (M16 am4) have rows on the list too, but the block never had them
55
54
  const lineSet = listLinesOf(declaration);
56
55
  if (cardLinesOf(declaration).size === 0) return no(NO_LIST_SAY);
57
- const log = readJson(planDir, 'log.json');
58
- const pageLook = readJson(planDir, 'page-look.json');
56
+ const log = readDraftLog(planDir);
57
+ const pageLook = readJsonFile(planDir, 'page-look.json');
59
58
  const look = isRec(pageLook?.look) ? { facts: Array.isArray(pageLook.look.facts) ? pageLook.look.facts : [], dropped: Array.isArray(pageLook.look.dropped) ? pageLook.look.dropped : [] } : { facts: [], dropped: [] };
60
- const record = readJson(planDir, RECORD_FILE) ?? {};
59
+ const record = readJsonFile(planDir, RECORD_FILE) ?? {};
61
60
  // the frozen copies of the page inputs, then the document inputs as the draft read them (they are not copied into the folder: an input that changed is caught below)
62
61
  /** @type {Record<string, {text: string}>} */
63
62
  const pages = {};
@@ -70,10 +69,10 @@ export function rebuildBlock({ planDir, asks }) {
70
69
  if (!facts.ok) return no(REBUILD_CHANGED_SAY);
71
70
  const texts = { ...(facts.docs ?? {}), ...Object.fromEntries(Object.entries(pages).map(([role, pg]) => [role, pg.text])) };
72
71
  // the lines the block was given are the lines the saved list has rows on
73
- const all = blockJobLines(prose.text, undefined, []);
72
+ const all = blockJobLines(proseText, undefined, []);
74
73
  if (!all.ok) return no('This plan could not be read. Nothing was changed.');
75
74
  const tied = all.jobLines.filter((l) => !lineSet.has(l.n)).map((l) => l.n);
76
- const plan = blockJobLines(prose.text, undefined, tied);
75
+ const plan = blockJobLines(proseText, undefined, tied);
77
76
  if (!plan.ok) return no('This plan could not be read. Nothing was changed.');
78
77
  const blockLineNums = new Set(plan.jobLines.map((l) => l.n));
79
78
  const inBlock = (/** @type {{line: number}} */ x) => blockLineNums.has(x.line);
@@ -129,7 +128,7 @@ export function rebuildBlock({ planDir, asks }) {
129
128
  if (sheetBuilt !== null) { block.setSheet(sheetBuilt); block.carrySheetDropped(Array.isArray(record.sheetDropped) ? record.sheetDropped : []); }
130
129
  if (Array.isArray(record.shapeDropped) && record.shapeDropped.length) block.carryShapeDropped(record.shapeDropped);
131
130
  block.reconcile();
132
- return { ok: true, block, declaration, lines, lineSet, parsed, texts, look, record, log, proseText: prose.text };
131
+ return { ok: true, block, declaration, lines, lineSet, parsed, texts, look, record, log, proseText };
133
132
  }
134
133
 
135
134
  /**
@@ -158,7 +157,7 @@ function assembleAgain(b, from = b.declaration) {
158
157
  const planFacts = b.look.facts.filter((f) => !b.lineSet.has(f.line) || inPlan.has(`${f.line}:${f.name}`));
159
158
  const pageSources = (b.parsed.arbiter.sources ?? []).some((/** @type {any} */ s) => s.kind === 'page');
160
159
  const verdict = validateDeclaration(a.declaration, {
161
- arbiter: b.parsed.arbiter, lines: b.lines, catalogue: cat.primitives, wired: WIRED_VERBS, verbatimGoals: true, fitJobLine: true,
160
+ arbiter: b.parsed.arbiter, lines: b.lines, catalogue: cat.primitives, wired: WIRED_VERBS, verbatimGoals: true, fitJobLine: true, addedCounts: addedCountsOf(b.block.choicesRecord(), b.lines),
162
161
  pageWords: { texts: b.texts, look: pageSources ? { facts: planFacts, dropped: b.look.dropped } : null, docs: docRolesOf(b.parsed.arbiter.sources) },
163
162
  });
164
163
  if (!verdict.ok) return { ok: false, say: `The changed list did not pass the plan's checks (${String(verdict.reds[0])}). Nothing was changed.` };
@@ -196,18 +195,19 @@ export function rowEditPlan({ planDir, op, key, asks = true }) {
196
195
  const shapeDroppedNow = b.block.shapeDroppedRecord();
197
196
  const after = assembleAgain(b);
198
197
  if (!after.ok) return { ok: false, say: after.say, refused: 'rebuild' };
199
- const target = readJson(planDir, 'target.json');
198
+ const target = readJsonFile(planDir, 'target.json');
200
199
  const inputFactsText = readFileInside(planDir, 'input-facts.json');
201
200
  const targetText = readFileInside(planDir, 'target.json');
202
201
  if (!targetText.ok || !inputFactsText.ok || !isRec(target)) return { ok: false, say: 'This plan could not be read. Nothing was changed.', refused: 'rebuild' };
203
202
  const dj = (/** @type {unknown} */ o) => `${JSON.stringify(o, null, 2)}\n`;
204
203
  const declarationText = dj(after.declaration);
205
204
  // the "Not checked" list: what the old plan listed, less what the old list made, plus what the changed list makes (the AI's own list stays)
206
- const oldNc = readJson(planDir, NOT_CHECKED_FILE)?.notChecked;
205
+ const oldNcFile = readNotCheckedFile(planDir);
206
+ const oldNc = oldNcFile.notChecked;
207
207
  const oldList = Array.isArray(oldNc) ? oldNc.filter((x) => typeof x === 'string') : [];
208
208
  const was = new Set(before.notChecked);
209
209
  const notChecked = [...new Set([...oldList.filter((x) => !was.has(x)), ...after.notChecked])];
210
- const oldBy = isRec(readJson(planDir, NOT_CHECKED_FILE)?.by) ? readJson(planDir, NOT_CHECKED_FILE).by : {};
210
+ const oldBy = oldNcFile.by ?? {};
211
211
  const by = { ...Object.fromEntries(Object.entries(oldBy).filter(([t]) => !was.has(t))), ...after.notCheckedBy };
212
212
  // M19 am4: the plan card the new plan saves is the one its readout reads (one model)
213
213
  // M19 am8 item 1, am9 item 5: the new plan's ledger rows, one per Not checked row, in its own log; the card is read from the new plan (am6)
@@ -246,7 +246,7 @@ export function rowEditPlan({ planDir, op, key, asks = true }) {
246
246
  [NOT_CHECKED_FILE]: dj({ notChecked, ...(Object.keys(by).length ? { by } : {}) }),
247
247
  [RECORD_FILE]: dj({ ...record, rowChoices: b.block.choicesRecord(), ...(droppedNow.length ? { sheetDropped: droppedNow } : {}), ...(shapeDroppedNow.length ? { shapeDropped: shapeDroppedNow } : {}) }),
248
248
  'log.json': dj({ ...(isRec(b.log) ? b.log : {}), log: [...(Array.isArray(b.log?.log) ? b.log.log : []), logRow, ...ledger], checkCard: card }),
249
- 'spec.hash': `${h.hash}\n`,
249
+ [SPEC_HASH_FILE]: `${h.hash}\n`,
250
250
  },
251
251
  };
252
252
  }
package/src/primitives.js CHANGED
@@ -33,7 +33,7 @@ import { readDocxText } from './docx.js';
33
33
  import { parseCsv } from './csv.js';
34
34
  import { makeCtxTools } from './ctx-tools.js';
35
35
  import { diaryPaths } from './diary.js';
36
- import { readdirInside } from './flow.js';
36
+ import { readdirInside } from './inside.js';
37
37
 
38
38
  // bare-agent >=0.47.0: `noFollowSymlinks: true` makes shell_read/write/edit/
39
39
  // grep throw `err.code === 'ELOOP'` when the path's FINAL component is a
package/src/provider.js CHANGED
@@ -19,7 +19,7 @@ import {
19
19
  mkdirSync,
20
20
  } from 'node:fs';
21
21
  import { dirname, basename } from 'node:path';
22
- import { readFileInside } from './flow.js';
22
+ import { readFileInside } from './inside.js';
23
23
  import { appendRow } from './jsonl-append.js';
24
24
  import { readConfig, configDoorHome, cleanBaseUrl } from './config.js';
25
25
  import { isKeyName } from './keysfile.js';
package/src/reasons.js ADDED
@@ -0,0 +1,25 @@
1
+ // M20 am3b item 2 (loop map): the plain reasons code gives, moved verbatim out of src/checkblock.js so the words that quote them (src/pagedropwords.js) need not import the block.
2
+
3
+ /** the plain reasons code gives, in one place (the card, the Job tab and the Audit read them from the row) */
4
+ export const REASON = Object.freeze({
5
+ left: 'You chose to leave it Not checked, so you judge it at Accept.',
6
+ nothingOnPage: 'Your own words are on the line; the machine has no check for them, so you judge it at Accept.',
7
+ noRule: 'No rule can check this, so you judge it at Accept.',
8
+ waitingPick: 'waiting for your answer on the proposed check',
9
+ waitingReading: 'waiting for your answer on the reading',
10
+ onePerLine: 'this line finds facts, so it has no text to quote',
11
+ manyInputs: 'the job has more than one input and code cannot pick which one the claims quote',
12
+ oneSidedTime: 'a time limit the AI proposes must be a range, so you judge it at Accept.',
13
+ countNeedsFact: 'a result count needs a fact to count; this line has none',
14
+ countNeedsSuggested: 'a result count needs a fact to count; add the suggested fact on this line to count its results',
15
+ lookNoWords: "the page does not hold the words of the look's fact for this rule",
16
+ afterLast: 'no more tries: Start over (rows are never changed by the AI after the last try)',
17
+ noPick: 'No check was picked for it, so you judge it at Accept.',
18
+ itemCountByRule: 'your rule on this line sets the item count',
19
+ negated: 'it says what is not needed, so there is nothing to check',
20
+ dropped: 'You dropped it.',
21
+ suggested: 'Suggested: not in your job, so it is not checked unless you add it.',
22
+ sheetLine: 'this line reads a sheet and its rules are checked by the sheet checks, so a row edit about it is not used',
23
+ sheetFacts: 'this line reads a sheet, so it is checked by its sheet checks and not by page facts',
24
+ columnRule: "this rule only names a column; the agent's checks on this line use it",
25
+ });