fwdloop 0.38.0 → 0.39.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 (127) hide show
  1. package/bin/fwdloop +21 -19
  2. package/package.json +1 -1
  3. package/src/ask.js +70 -148
  4. package/src/audit-fold.js +5 -4
  5. package/src/auditchecks.js +6 -4
  6. package/src/authoring.js +32 -60
  7. package/src/blockasks.js +2 -1
  8. package/src/blockassemble.js +3 -2
  9. package/src/blockdraft.js +2 -2
  10. package/src/blockpick.js +5 -5
  11. package/src/books.js +217 -12
  12. package/src/checkblock.js +20 -41
  13. package/src/checklistsign.js +25 -3
  14. package/src/checklook.js +3 -1
  15. package/src/checkpick.js +5 -76
  16. package/src/cited-source.js +4 -4
  17. package/src/citedcheck.js +6 -11
  18. package/src/citedwords.js +9 -8
  19. package/src/closers.js +9 -6
  20. package/src/declaration.js +14 -49
  21. package/src/diary.js +23 -1
  22. package/src/draft-steps.js +11 -1
  23. package/src/drafter.js +13 -9
  24. package/src/draftfiles.js +127 -0
  25. package/src/draftspend.js +165 -17
  26. package/src/flow.js +42 -87
  27. package/src/flowmodel.js +1 -1
  28. package/src/index.js +3 -2
  29. package/src/inside.js +86 -0
  30. package/src/jsonl-append.js +33 -1
  31. package/src/learn.js +1 -1
  32. package/src/learnstore.js +20 -22
  33. package/src/line-checks.js +1 -1
  34. package/src/liveness.js +3 -0
  35. package/src/mcp-use.js +8 -9
  36. package/src/memo.js +13 -16
  37. package/src/model-step.js +2 -2
  38. package/src/page-words.js +8 -0
  39. package/src/pageask.js +8 -3
  40. package/src/pagebits.js +8 -1
  41. package/src/pagedropwords.js +1 -1
  42. package/src/pagerules.js +6 -3
  43. package/src/panel/author.js +99 -75
  44. package/src/panel/authorcard.js +21 -8
  45. package/src/panel/authorflows.js +3 -3
  46. package/src/panel/authorresume.js +3 -3
  47. package/src/panel/authorstart.js +15 -16
  48. package/src/panel/authortrigger.js +43 -70
  49. package/src/panel/data.js +125 -168
  50. package/src/panel/index.html +122 -61
  51. package/src/panel/jobgrid.js +3 -7
  52. package/src/panel/result.js +7 -10
  53. package/src/panel/resume.js +4 -3
  54. package/src/panel/scheduler.js +9 -9
  55. package/src/panel/server.js +8 -4
  56. package/src/panel/spawn.js +22 -11
  57. package/src/panel/tickets.js +2 -2
  58. package/src/pickrecord.js +51 -31
  59. package/src/placerule.js +3 -4
  60. package/src/planrebuild.js +19 -19
  61. package/src/primitives.js +1 -1
  62. package/src/provider.js +1 -1
  63. package/src/reasons.js +25 -0
  64. package/src/runfile.js +26 -2
  65. package/src/runner.js +57 -105
  66. package/src/runvalues.js +47 -24
  67. package/src/schedule-choices.js +41 -0
  68. package/src/schedule-shape.js +39 -0
  69. package/src/schedule.js +9 -8
  70. package/src/setup.js +20 -36
  71. package/src/shaperows.js +2 -2
  72. package/src/sheetblock.js +2 -2
  73. package/src/sheetbuild.js +5 -5
  74. package/src/sheetrun.js +4 -5
  75. package/src/summary-words.js +2 -1
  76. package/src/thinking.js +5 -2
  77. package/src/ticketrows.js +7 -28
  78. package/src/trigger-clock.js +9 -23
  79. package/src/trigger-files.js +30 -22
  80. package/src/trigger-tickets.js +15 -14
  81. package/src/try-checks.js +2 -1
  82. package/src/types.js +2 -0
  83. package/types/ask.d.ts +25 -20
  84. package/types/authoring.d.ts +7 -42
  85. package/types/blockpick.d.ts +1 -1
  86. package/types/books.d.ts +256 -4
  87. package/types/checkblock.d.ts +1 -23
  88. package/types/checklist.d.ts +3 -3
  89. package/types/checklistsign.d.ts +7 -0
  90. package/types/checkpick.d.ts +0 -21
  91. package/types/citedwords.d.ts +7 -4
  92. package/types/closers.d.ts +1 -0
  93. package/types/declaration.d.ts +4 -14
  94. package/types/diary.d.ts +14 -1
  95. package/types/draft-steps.d.ts +7 -0
  96. package/types/drafter.d.ts +1 -1
  97. package/types/draftfiles.d.ts +89 -0
  98. package/types/draftspend.d.ts +74 -0
  99. package/types/flow.d.ts +32 -54
  100. package/types/index.d.ts +3 -3
  101. package/types/inside.d.ts +58 -0
  102. package/types/jsonl-append.d.ts +20 -0
  103. package/types/learnstore.d.ts +0 -2
  104. package/types/liveness.d.ts +1 -0
  105. package/types/page-words.d.ts +6 -0
  106. package/types/pageask.d.ts +2 -0
  107. package/types/pagebits.d.ts +3 -0
  108. package/types/pagerules.d.ts +1 -0
  109. package/types/panel/author.d.ts +7 -3
  110. package/types/panel/authorcard.d.ts +0 -6
  111. package/types/panel/authorflows.d.ts +4 -4
  112. package/types/panel/authortrigger.d.ts +16 -2
  113. package/types/panel/data.d.ts +36 -11
  114. package/types/panel/spawn.d.ts +18 -2
  115. package/types/pickrecord.d.ts +29 -0
  116. package/types/reasons.d.ts +23 -0
  117. package/types/runfile.d.ts +14 -0
  118. package/types/runner.d.ts +6 -38
  119. package/types/runvalues.d.ts +17 -2
  120. package/types/schedule-choices.d.ts +9 -0
  121. package/types/schedule-shape.d.ts +15 -0
  122. package/types/sheetbuild.d.ts +1 -1
  123. package/types/thinking.d.ts +1 -0
  124. package/types/ticketrows.d.ts +0 -9
  125. package/types/trigger-clock.d.ts +3 -2
  126. package/types/trigger-files.d.ts +15 -4
  127. package/types/types.d.ts +8 -0
@@ -4,7 +4,7 @@
4
4
  // its lines are. The write is a temporary file, then a rename, so a reader sees the old file or the new one; the other section is carried over untouched.
5
5
  import { writeFileSync, renameSync } from 'node:fs';
6
6
  import { join } from 'node:path';
7
- import { readFileInside } from './flow.js';
7
+ import { readFileInside } from './inside.js';
8
8
  import { isRec } from './isrec.js';
9
9
 
10
10
  /** the record's name in the run's own folder */
package/src/liveness.js CHANGED
@@ -160,6 +160,9 @@ export function readResumeLock(runDir) {
160
160
  return { state: alive === true ? 'live' : alive === false ? 'dead' : 'unknown', pid: h.pid, procStart, path };
161
161
  }
162
162
 
163
+ /** M20 am8: the one question "may someone still hold this run's resume lock": a live holder, or one whose liveness cannot be told (never treated as dead) @param {unknown} state a `readResumeLock` state @returns {boolean} */
164
+ export const lockMayBeHeld = (state) => state === 'live' || state === 'unknown';
165
+
163
166
  /** The run's books, for the 10-minute fallback: state, audit, model log, spend ledger, and the pid file itself. */
164
167
  const BOOK_FILES = ['state.json', 'audit.jsonl', 'log.json', 'spend.jsonl', 'pids.jsonl'];
165
168
  const FRESH_MS = 10 * 60 * 1000;
package/src/mcp-use.js CHANGED
@@ -3,8 +3,10 @@
3
3
  // - a ticket read: `run.json` `inputs[].mcp.calls` (server + tool; the file holds no time, so `last` is the file's mtime);
4
4
  // - a step's tool call: a `kind:"tool"` row of `diary.jsonl` whose tool is `<server>_<tool>` (M13 piece 2); `decision:"deny"` is a denied call, counted apart and not as a use.
5
5
  // A torn or unreadable file is skipped, row by row (its rows go missing from the count; it never breaks the page).
6
- import { readdirSync, readFileSync, statSync } from 'node:fs';
6
+ import { readdirSync, statSync } from 'node:fs';
7
7
  import { join } from 'node:path';
8
+ import { readRunRecord } from './runfile.js';
9
+ import { readTools } from './diary.js';
8
10
 
9
11
  const safeDir = (/** @type {string} */ p) => { try { return readdirSync(p); } catch { return []; } };
10
12
 
@@ -30,7 +32,9 @@ export function countMcpUse(root, servers) {
30
32
  const dir = join(root, flow, 'runs', name);
31
33
  const key = `${flow}/${name}`;
32
34
  try {
33
- const j = JSON.parse(readFileSync(join(dir, 'run.json'), 'utf8'));
35
+ const rr = readRunRecord(dir);
36
+ if (!rr.ok) throw new Error(rr.red);
37
+ const j = rr.rec;
34
38
  const mtime = statSync(join(dir, 'run.json')).mtime.toISOString();
35
39
  for (const i of Array.isArray(j?.inputs) ? j.inputs : []) {
36
40
  const m = i?.mcp;
@@ -38,13 +42,8 @@ export function countMcpUse(root, servers) {
38
42
  for (const c of Array.isArray(m.calls) ? m.calls : []) if (typeof c?.tool === 'string') use(m.server, c.tool, key, mtime, false);
39
43
  }
40
44
  } catch { /* no run.json, or torn: nothing counted from it */ }
41
- let text;
42
- try { text = readFileSync(join(dir, 'diary.jsonl'), 'utf8'); } catch { continue; }
43
- for (const line of text.split('\n')) {
44
- if (!line.includes('"kind":"tool"')) continue;
45
- let r;
46
- try { r = JSON.parse(line); } catch { continue; }
47
- if (r?.kind !== 'tool' || typeof r.tool !== 'string') continue;
45
+ for (const r of readTools(dir)) {
46
+ if (typeof r?.tool !== 'string') continue;
48
47
  const server = byLength.find((s) => r.tool.startsWith(`${s}_`) && r.tool.length > s.length + 1);
49
48
  if (server) use(server, r.tool.slice(server.length + 1), key, typeof r.at === 'string' ? r.at : '', r.decision === 'deny');
50
49
  }
package/src/memo.js CHANGED
@@ -3,10 +3,12 @@
3
3
  // `asks/<id>.json` (the human's words, by `listArchivedAsks`), `job/declaration.json` (step order) and `run.json`'s `rerun` section. It writes nothing: the exact
4
4
  // text a try was handed is kept by that try's audit row (`memoText`, runner.js `makeAuditRow`), so no new run-folder file. Pure over those files, so it survives a
5
5
  // pause, a resume and a restart. It never carries money or time (no cost, no duration); gap texts are the closer's own words, kept as they are (cut at GAP_CHARS).
6
- import { readAudit } from './books.js';
7
- import { readFileInside } from './flow.js';
6
+ import { readAudit, isGoodEnding } from './books.js';
7
+ import { readRunJobCopy } from './flow.js';
8
+ import { readFileInside } from './inside.js';
9
+ import { loadCatalogue } from './catalogue.js';
8
10
  import { listArchivedAsks, DECISION_STATUS } from './ask.js';
9
- import { readRunRecord } from './runfile.js';
11
+ import { readRerunWords } from './runfile.js';
10
12
  import {
11
13
  foldCards, nameOf, errorKinds, flaggedTokens, quoteLines,
12
14
  } from './learn.js';
@@ -19,8 +21,6 @@ export const MEMO_CAP = 4000;
19
21
  /** one gap text is cut here (with an ellipsis), so a single long red cannot eat the whole cap */
20
22
  const GAP_CHARS = 300;
21
23
 
22
- /** a try that closed well; every other verdict of a model try is a failure the memo names */
23
- const WELL = new Set(['green', 'hitl']);
24
24
  const DECISION_OF = Object.fromEntries(Object.entries(DECISION_STATUS).map(([k, v]) => [v, k]));
25
25
 
26
26
  const oneLine = (/** @type {unknown} */ t) => (typeof t === 'string' ? t.replace(/\s+/g, ' ').trim() : '');
@@ -29,21 +29,18 @@ const says = (/** @type {string} */ words) => (words === '' ? '' : ` — user sa
29
29
 
30
30
  /** step names in the job's own order, from the run's copy of the job (`[]` when it cannot be read) @param {string} runDir @returns {string[]} */
31
31
  function stepOrder(runDir) {
32
- const r = readFileInside(runDir, 'job/declaration.json');
33
- if (!r.ok) return [];
34
- try {
35
- const steps = JSON.parse(r.text)?.steps;
36
- return Array.isArray(steps) ? steps.map((s) => s?.emits).filter((e) => typeof e === 'string') : [];
37
- } catch { return []; }
32
+ const cat = loadCatalogue();
33
+ const job = cat.ok ? readRunJobCopy(runDir, cat.primitives) : { present: /** @type {false} */ (false) }; // M20 am3 item 2: a copy that fails its signature is no job
34
+ const steps = job.present && job.ok ? job.declaration?.steps : null;
35
+ return Array.isArray(steps) ? steps.map((s) => s?.emits).filter((e) => typeof e === 'string') : [];
38
36
  }
39
37
 
40
38
  /** the human lines: the rerun line first (this run began as a rerun), then one per answered ask in the order they were asked (N counts every ask of this run) @param {string} runDir @param {string[]} order @returns {string[]} */
41
39
  function humanLines(runDir, order) {
42
40
  /** @type {string[]} */
43
41
  const lines = [];
44
- const rec = readRunRecord(runDir);
45
- const rr = rec.ok ? rec.rec.rerun : null;
46
- if (rr && typeof rr === 'object' && rr.decision === 'rerun' && typeof rr.words === 'string') lines.push(`rerun${says(oneLine(rr.words))}`);
42
+ const rerunWords = readRerunWords(runDir);
43
+ if (rerunWords !== null) lines.push(`rerun${says(oneLine(rerunWords))}`);
47
44
  const listed = listArchivedAsks(runDir);
48
45
  if (!listed.archived) return lines;
49
46
  const asks = [...listed.asks].sort((a, b) => String(a.askedAt ?? '').localeCompare(String(b.askedAt ?? '')));
@@ -95,10 +92,10 @@ export function buildMemo(runDir, { step, cap = MEMO_CAP }) {
95
92
 
96
93
  const last = tries.at(-1) ?? null;
97
94
  // item 6: the newest failure's words are left out when the retry (the same step, straight after a failure) already gets them as its gap
98
- const retryGetsGap = last !== null && last.step === step && !WELL.has(last.verdict);
95
+ const retryGetsGap = last !== null && last.step === step && !isGoodEnding(last.verdict);
99
96
  const earlier = tries.slice(0, -1);
100
97
  const sameStep = earlier.filter((t) => t.step === step);
101
- const failures = earlier.filter((t) => t.step !== step && !WELL.has(t.verdict));
98
+ const failures = earlier.filter((t) => t.step !== step && !isGoodEnding(t.verdict));
102
99
  const label = (/** @type {{step: string, n: number, verdict: string, gap: string}} */ t) => `step ${t.step} try ${t.n} — result: ${t.verdict}`;
103
100
  const gapOf = (/** @type {{gap: string}} */ t) => (t.gap === '' ? '' : ` — ${cutGap(t.gap)}`);
104
101
  const foldLine = (/** @type {string} */ kind, /** @type {any[]} */ g) => ({ kind, text: `${kind}: ${label(g[0])}${gapOf(g[0])}${g.length > 1 ? ` (x${g.length})` : ''}` });
package/src/model-step.js CHANGED
@@ -29,7 +29,7 @@ import { Loop, HaltError } from 'bare-agent';
29
29
  import { GateRefusal } from './primitives.js';
30
30
  import { appendCall, appendTool, nextRound } from './diary.js';
31
31
  import { ConfigError } from './config.js';
32
- import { worstThinkingStatus } from './thinking.js';
32
+ import { worstThinkingStatus, isThinkingMode } from './thinking.js';
33
33
  import { citedBrief, toldPicks } from './citedcheck.js';
34
34
  import { shapeBriefOf, shapeLineBrief } from './rubricstep.js';
35
35
 
@@ -392,7 +392,7 @@ export function makeLiveModelStep({
392
392
  const diaryStep = stepMeta.step ?? null;
393
393
  const diaryTry = typeof stepMeta.attempt === 'number' ? stepMeta.attempt : null;
394
394
  const toolSchema = buildEmitArtifactSchema(stepMeta.class, stepMeta.class === 'green' && Boolean(stepMeta.cited), stepMeta.class === 'green' && Array.isArray(stepMeta.sheet) ? stepMeta.sheet : null, stepMeta.class === 'green' && stepMeta.withText === true, isRec(stepMeta.itemShape));
395
- const thinkingMode = stepMeta.thinkingMode === 'on' || stepMeta.thinkingMode === 'off' ? stepMeta.thinkingMode : null;
395
+ const thinkingMode = isThinkingMode(stepMeta.thinkingMode) ? /** @type {'on'|'off'} */ (stepMeta.thinkingMode) : null;
396
396
  const systemPrompt = 'You are executing one step of a signed, human-authored automation. '
397
397
  + 'Call emit_artifact exactly once with this step\'s result. Ground every value in the '
398
398
  + 'reads you were handed or the tools you were granted — never invent a figure.';
@@ -0,0 +1,8 @@
1
+ // M20 am8a item 1: the words the page asks instead of spelling them itself, built from the modules that own the facts (the panel injects the constant like the schedule choices: src/schedule-choices.js).
2
+ // The page is a classic script and cannot import; its client-made states (phase "revising" set by the page itself) have no server data to carry a flag, so it asks this list.
3
+ import { TAG } from './checkwords.js';
4
+ import { REASON_DECISIONS } from './ask.js';
5
+ import { REVISE_PHASES, NOT_GREEN_PHASES } from './panel/author.js';
6
+
7
+ /** @returns {{tags: Record<string,string>, reasonDecisions: string[], reviseRunning: string[], notGreen: string[]}} tags: origin -> tag word; reasonDecisions: the decisions that need a reason; reviseRunning: phases where a revise or redraft runs; notGreen: phases where the draft ended red or stopped */
8
+ export const pageWords = () => ({ tags: { ...TAG }, reasonDecisions: [...REASON_DECISIONS], reviseRunning: [...REVISE_PHASES], notGreen: [...NOT_GREEN_PHASES] });
package/src/pageask.js CHANGED
@@ -3,7 +3,6 @@
3
3
  // borrowed-from: bareloop src/pagemap.js@v0.49.0 (d51a367) (stripAgreeLead, F240; adapted: literal regex, src/ bans new RegExp)
4
4
  // The words of the asks and of the answers to them. M17 am4 (A1): the asks themselves come from the list (src/blockasks.js); the page-look ask path that sat here is gone.
5
5
  import { redactSecrets } from './redact.js';
6
- import { HOW_TO_ANSWER } from './checkpick.js';
7
6
  import { columnTail } from './sheetfind.js';
8
7
 
9
8
  /** the most asks before drafting; more than this is a job to rewrite, not a questionnaire (am1) */
@@ -133,14 +132,20 @@ export function ruleOfAnswer(q, typed, choice) {
133
132
  // M17 am9 item 4: a column picked from a tie is the reading the tie carried for that column (the rule's words are rewritten in place by applyAnswers); anything not on the list never reaches here (the door refuses it)
134
133
  if (choice === 'column') return { rule: q.readings?.[typedText] ?? null, left: q.readings?.[typedText] === undefined };
135
134
  if (choice !== undefined) { // M10 am29: a typed choice decides, never the words; the box (`rule`) keeps its words whole
136
- const shapeC = q.ask === 'check' || q.ask === 'no-check';
135
+ const shapeC = isShapeAsk(q.ask);
137
136
  if (choice === 'agree' && typeof q.proposal === 'string' && (q.ask === 'reading' || q.ask === 'check')) return { rule: q.proposal, left: false, ...(q.ask === 'check' && q.check ? { check: q.check } : {}) };
138
137
  if (choice === 'drop') return { rule: null, left: true };
139
138
  return { rule: typedText, left: false, ...(shapeC ? { own: true } : {}) };
140
139
  }
141
140
  const text = stripAgreeLead(typedText); // F240: "yes, check it as ..." is the person's own words minus the leading "yes,"
142
- const shape = q.ask === 'check' || q.ask === 'no-check';
141
+ const shape = isShapeAsk(q.ask);
143
142
  if ((q.ask === 'reading' || q.ask === 'check') && typeof q.proposal === 'string' && isAgree(text)) return { rule: q.proposal, left: false, ...(q.ask === 'check' && q.check ? { check: q.check } : {}) };
144
143
  if ((q.ask === 'cant-check' || shape) && isDropIt(text)) return { rule: null, left: true };
145
144
  return { rule: text, left: false, ...(shape ? { own: true } : {}) };
146
145
  }
146
+
147
+ /** M20 am8: the one question "is this a shape guardrail's ask" (`check` proposes a check, `no-check` found none) @param {unknown} ask @returns {boolean} */
148
+ export const isShapeAsk = (ask) => ask === 'check' || ask === 'no-check';
149
+
150
+ /** how every answer is told, once (am2 item 2's words) */
151
+ export const HOW_TO_ANSWER = (/** @type {number} */ line, /** @type {boolean} */ agree) => `${agree ? 'Answer "agree" to use it, or type your own words' : 'Type your own words'} (your answer replaces that ~ rule on line ${line}), or answer "drop it" to leave it Not checked.`;
package/src/pagebits.js CHANGED
@@ -7,7 +7,14 @@ export const MAX_CURRENCIES = 3;
7
7
  export const MAX_UNITS = 10;
8
8
  export const MAX_UNIT_CHARS = 100;
9
9
  export const asList = (/** @type {unknown} */ v) => (Array.isArray(v) ? v.map(String) : (typeof v === 'string' ? [v] : []));
10
- export const boundOk = (/** @type {string} */ shape, /** @type {unknown} */ v) => (shape === 'number' || shape === 'money' ? typeof v === 'number' && Number.isFinite(v) : typeof v === 'string' && v !== '');
10
+ /** M20 am8: the one question "is this fact shape phrase-like" (the words of a phrase or a place are looked for on the page) @param {unknown} shape @returns {boolean} */
11
+ export const isPhraseShape = (shape) => shape === 'phrase' || shape === 'place';
12
+ /** M20 am8: the one question "is this a legal result count": `{min, max}` only, at least one of them, whole numbers 1 or more, min no more than max (each caller keeps its own words for a refusal) @param {any} c @returns {boolean} */
13
+ export const isLegalCount = (c) => isRec(c) && Object.keys(c).every((k) => k === 'min' || k === 'max') && (c.min !== undefined || c.max !== undefined)
14
+ && ['min', 'max'].every((k) => c[k] === undefined || (Number.isInteger(c[k]) && c[k] >= 1)) && (c.min === undefined || c.max === undefined || c.min <= c.max);
15
+ /** M20 am8: the one question "is this fact shape an amount" (money or number: read as a plain number, carries the decimal mark, its bounds are numbers) @param {unknown} shape @returns {boolean} */
16
+ export const isAmountShape = (shape) => shape === 'money' || shape === 'number';
17
+ export const boundOk = (/** @type {string} */ shape, /** @type {unknown} */ v) => (isAmountShape(shape) ? typeof v === 'number' && Number.isFinite(v) : typeof v === 'string' && v !== '');
11
18
 
12
19
  // borrowed-from: bareloop src/factwords.js@18ab77c (squash, loose, countExact, countPhrase - rewritten without a built pattern, same count, see test/m10-pagebits.test.js)
13
20
  const WS = /[\s   ]+/g;
@@ -8,7 +8,7 @@
8
8
 
9
9
  // borrowed-from: bareloop src/pagedropwords.js@v0.56.0 (3383cce) (the four reasons the block's drops carry, and the sign-twice sentence by `d.other`; FACT_LANGS lives with the facts in src/citedcheck.js)
10
10
  import { FACT_LANGS } from './citedcheck.js';
11
- import { REASON } from './checkblock.js';
11
+ import { REASON } from './reasons.js';
12
12
 
13
13
  /** the two ways a sign listed twice can be used once (v0.56.0 spells the sentence from `d.other`; no other -> "currency", the sentence fwd has always written) */
14
14
  const SIGN_TWICE_AS = ['currency', 'unit'];
package/src/pagerules.js CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  import { lineRules } from './pagebits.js';
9
9
  import { MAX_CURRENCIES, MAX_UNITS, MAX_UNIT_CHARS, FACT_OPS, boundOk } from './pagebits.js';
10
- import { countExact, countPhrase, squash, normLabel } from './pagebits.js';
10
+ import { countExact, countPhrase, squash, normLabel, isAmountShape } from './pagebits.js';
11
11
 
12
12
  /**
13
13
  * @typedef {{op: string, value?: string|number, lo?: string|number, hi?: string|number}} Reading what a `~` rule means as a limit (PRD v1.107 Part 5b): the same shape as a signed fact rule
@@ -40,13 +40,16 @@ export function tieOf(from, jobLines) {
40
40
  return out;
41
41
  }
42
42
 
43
+ /** M20 am8: the one question "can CODE read a limit from the person's words for this fact shape" (money or time: readLimit reads those two) @param {unknown} shape @returns {shape is 'money'|'time'} */
44
+ export const canReadLimit = (shape) => shape === 'money' || shape === 'time';
45
+
43
46
  /**
44
47
  * Is this a legal `reading` for a fact of this shape? Only a time or money fact carries one, with the op set and the bound types of a signed
45
48
  * fact rule (src/facts.js): no other key, no missing bound. A malformed one makes the whole map answer malformed (no repair).
46
49
  * @param {unknown} shape @param {unknown} r @returns {boolean}
47
50
  */
48
51
  export function validReading(shape, r) {
49
- if (shape !== 'time' && shape !== 'money') return false;
52
+ if (!canReadLimit(shape)) return false;
50
53
  if (!isRec(r) || !FACT_OPS.includes(r.op)) return false;
51
54
  const keys = Object.keys(r).sort().join();
52
55
  return r.op === 'between' ? keys === 'hi,lo,op' && boundOk(shape, r.lo) && boundOk(shape, r.hi) : keys === 'op,value' && boundOk(shape, r.value);
@@ -220,7 +223,7 @@ export function applyPageRules(text, mapping, jobLines) {
220
223
  }
221
224
  pending.push({ f, kept, cur: [], uni: [] });
222
225
  } else if (VALUE_SHAPES.includes(String(f.shape))) {
223
- const amount = f.shape === 'money' || f.shape === 'number';
226
+ const amount = isAmountShape(f.shape);
224
227
  /** labels the page holds (and, for an amount, that have a number right after them) */
225
228
  const labels = [];
226
229
  /** the AI's labels as U1 leaves them, a word the page does not hold included: the first of these is R1's reference */