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
package/src/authoring.js CHANGED
@@ -31,7 +31,8 @@ import { sheetLineBlocks } from './sheetblock.js';
31
31
  import { loadCatalogue } from './catalogue.js';
32
32
  import { WIRED_VERBS } from './primitives.js';
33
33
  import { canonicalBytes } from './signature.js';
34
- import { writeFlow, writeRunPlan, readFlow, readFileInside, readdirInside, checkFlowName } from './flow.js';
34
+ import { writeFlow, writeRunPlan, readFlow, readJsonFile, checkFlowName, readDraftLog } from './flow.js';
35
+ import { readFileInside, readdirInside } from './inside.js';
35
36
  import { jobKeyOfSigned } from './jobkey.js';
36
37
  import { checkSendDestination } from './runner.js';
37
38
  import { checkKeyPreflight, appendSpendRow } from './provider.js';
@@ -40,28 +41,25 @@ import { readModelRecord, writeModelRecord, writeLearningsRecord, writeLearnings
40
41
  import { configDoorHome } from './config.js';
41
42
  import { hintsForRun, placeSpecOf } from './learnstore.js';
42
43
  import { redactSecrets } from './redact.js';
43
- import { sessionPriorSpend, writeDraftSpend } from './draftspend.js';
44
+ import { makeStepWriter, sessionPriorSpend, writeDraftSpend } from './draftspend.js';
44
45
  import { writeSetup } from './setup.js';
45
- import { RECORD_FILE } from './pickrecord.js';
46
+ import { RECORD_FILE, readKept, readRowChoices, recordPath, addedCountsOf } from './pickrecord.js';
46
47
  import { planMatchesCard, numbersWords } from './checkrows.js';
47
48
  import { csvRolesOf } from './sheetblock.js';
48
49
  import { mcpPickHere } from './mcp-pick.js';
49
50
  import { hitlWords, notCheckedView } from './checked.js';
51
+ import {
52
+ SPEC_HASH_FILE, LEAK_MARKER_FILE, draftVerdict, QUESTIONS_FILE, ANSWER_FILE, NOT_CHECKED_FILE, readNotCheckedFile, readQuestions, scrub, readCard, cardFileName, readRedraftMarker, redraftFileName, readPlanTexts,
53
+ } from './draftfiles.js';
50
54
 
51
- export const SPEC_HASH_FILE = 'spec.hash';
52
55
  /** The one folder under the flows root where the panel keeps its draft folders (M4e). Starts with a dot, so it is never a flow name. */
53
56
  export const PANEL_DRAFTS_DIR = '.drafts';
54
- /** Written when the end sweep finds a key in the draft dir; sign refuses a dir that has it. */
55
- export const LEAK_MARKER_FILE = 'scrub-leak.red';
56
57
  /** M4e amendments 24/25: the drafter's questions (written once by `fwdloop draft`), each human answer (`answer-<k>.json`, written once by the panel),
57
58
  * and the drafter's own "not checked" reading (information only; never in the readout, so never in the hash). */
58
- export const QUESTIONS_FILE = 'questions.json';
59
- export const NOT_CHECKED_FILE = 'not-checked.json';
60
59
  /** M10: the drafting copy of each web page input is kept in this folder of the draft folder (a run freezes its own, never this one). */
61
60
  export const PAGES_DIR = 'pages';
62
61
  /** M10 item 3: what the page-word look kept and dropped, per page input (the map the AI named, the kept facts with their readings, every drop). Not signed. */
63
62
  export const PAGE_LOOK_FILE = 'page-look.json';
64
- export const ANSWER_FILE = (k) => `answer-${k}.json`;
65
63
  export const SIGN_LINE = (dir, hash) => `DRAFTED — NOT SIGNED. To sign: fwdloop sign ${dir} --approve ${hash}`;
66
64
 
67
65
  const sha = (bytes) => createHash('sha256').update(bytes).digest('hex');
@@ -91,42 +89,13 @@ export function specHash({
91
89
  }
92
90
 
93
91
  /**
94
- * The questions a plan folder raised and the answers on disk, READ from its files — the ONE reader (the panel's phase reader, the sign
95
- * checks and the page all use it). `questions` = [{ k, line, question, answer|null }], `open` = those with no answer. A blank or unreadable
96
- * answer file counts as no answer. No questions file = `{ questions: [], open: [] }`.
97
- * @param {string} planDir
98
- * A question the page look raised (M10 piece 3) also carries `source: 'look'`, `ask` ('reading' | 'cant-check'), `ruleNo`, `ruleText` and `proposal`; an answer file carries `at`.
99
- * @returns {{ questions: {k:number, line:number, question:string, answer:string|null, at?:string, rule?:string|null, choice?:'agree'|'drop'|'rule'|'column', source?:string, ask?:string, ruleNo?:number, ruleText?:string, proposal?:string|null, check?:Record<string, any>, pairRule?:number, columns?:string[], readings?:Record<string,string>}[], open: {k:number, line:number, question:string, answer:null}[] }}
92
+ * The flow name a draft will sign as: the `name` in `target.json` of a plan folder (`planDir`, read through the safe gateway). A string that is not empty,
93
+ * else null (no file, not JSON, not an object, no name, a name that is empty or not a string).
94
+ * @param {string} planDir @returns {string|null}
100
95
  */
101
- export function readQuestions(planDir) {
102
- const none = { questions: [], open: [] };
103
- const f = readFileInside(planDir, QUESTIONS_FILE);
104
- if (!f.ok) return none;
105
- let list;
106
- try { list = JSON.parse(f.text)?.questions; } catch { return none; }
107
- if (!Array.isArray(list)) return none;
108
- const questions = list.map((q, i) => {
109
- const k = i + 1;
110
- const a = readFileInside(planDir, ANSWER_FILE(k));
111
- let answer = null;
112
- let at;
113
- /** @type {string|null|undefined} the `~` rule the answer added (null = it left the rule Not checked), as the answer file recorded it */
114
- let rule;
115
- /** @type {'agree'|'drop'|'rule'|'column'|undefined} M10 am29: which one the answer used (`agree`, `drop` or `rule`), when the file records it */
116
- let choice;
117
- if (a.ok) {
118
- try {
119
- const j = JSON.parse(a.text);
120
- const t = j?.answer;
121
- if (typeof t === 'string' && t.trim() !== '') { answer = t; if (typeof j.at === 'string') at = j.at; if (j.rule === null || typeof j.rule === 'string') rule = j.rule; if (j.choice === 'agree' || j.choice === 'drop' || j.choice === 'rule' || j.choice === 'column') choice = j.choice; }
122
- } catch { /* unreadable = unanswered */ }
123
- }
124
- return {
125
- k, line: q.line, question: String(q.question), answer, ...(at === undefined ? {} : { at }), ...(rule === undefined ? {} : { rule }), ...(choice === undefined ? {} : { choice }),
126
- ...(q.source === 'look' ? { source: 'look', ask: q.ask, ruleNo: q.ruleNo, ruleText: q.ruleText, proposal: typeof q.proposal === 'string' ? q.proposal : null, ...(q.check && typeof q.check === 'object' ? { check: q.check } : {}), ...(Number.isInteger(q.pairRule) ? { pairRule: q.pairRule } : {}), ...(Array.isArray(q.columns) && q.columns.length > 0 && q.readings && typeof q.readings === 'object' ? { columns: q.columns.map(String), readings: q.readings } : {}) } : {}),
127
- };
128
- });
129
- return { questions, open: /** @type {any} */ (questions.filter((q) => q.answer === null)) };
96
+ export function readTargetName(planDir) {
97
+ const name = readJsonFile(planDir, 'target.json')?.name;
98
+ return typeof name === 'string' && name !== '' ? name : null;
130
99
  }
131
100
 
132
101
  export const OPEN_QUESTION_SAY = 'A question the plan raised is still open. Answer it in the panel (fwdloop panel), then sign the plan it drafts after your answers. Nothing was signed.';
@@ -139,13 +108,6 @@ export function questionsRefusal(planDir) {
139
108
  return q.open.length > 0 ? OPEN_QUESTION_SAY : ANSWERED_QUESTION_SAY;
140
109
  }
141
110
 
142
- /** Literal (never RegExp) key scrub; a secret under 8 chars is skipped so it can't blank ordinary text. */
143
- export function scrub(text, secrets) {
144
- let out = text;
145
- for (const s of secrets) if (typeof s === 'string' && s.length >= 8) out = out.split(s).join('[redacted-key]');
146
- return out;
147
- }
148
-
149
111
  /** Count files directly inside `dir` that contain a secret literally. */
150
112
  export function sweepForSecrets(dir, secrets) {
151
113
  const live = secrets.filter((s) => typeof s === 'string' && s.length >= 8);
@@ -385,7 +347,7 @@ export function writePlanFiles(dir, files, opts = {}) {
385
347
  * `onResult({ ok })` (M4d am32): called once, after the spend is booked and just before the result files are written (the CLI gives its monthly hold back there).
386
348
  */
387
349
  export async function draftToDir({
388
- proseFile, dir, root, name, slot, model, draftThinking = /** @type {'on'|'off'} */ ('off'), keyNames, env = process.env, provider, rates, modelId, noQuestions = false, onResult, fetchPage, leftRules, columnAnswers, carriedColumns, checkPicks, carriedPicks, carriedChoices, carriedSheetDropped, carriedShapeDropped, proseRead,
350
+ proseFile, dir, root, name, slot, model, draftThinking = /** @type {'on'|'off'} */ ('off'), keyNames, env = process.env, provider, rates, modelId, noQuestions = false, onResult, onStepLine, fetchPage, leftRules, columnAnswers, carriedColumns, checkPicks, carriedPicks, carriedChoices, carriedSheetDropped, carriedShapeDropped, proseRead,
389
351
  flowType = /** @type {'plain'|'mcp'|'tickets'} */ ('plain'), mcpServer = /** @type {string|undefined} */ (undefined), mcpPick = /** @type {any} */ (undefined), mcpServers = /** @type {string[]|undefined} */ (undefined),
390
352
  // M13 am11: what the card's tentative send line is (see draft()); null = the prose file is the truth
391
353
  actionMode = /** @type {null|'check'|'known'} */ (null),
@@ -428,9 +390,14 @@ export async function draftToDir({
428
390
  // Spend is booked per call into `<dir>/draft-spend.json` (src/draftspend.js), so a draft stopped between rounds
429
391
  // keeps what it paid. The first write is the mark that a call is in flight: if that cannot be written, the call is not made.
430
392
  let startedAt = null;
393
+ // M20 am1 item 5 (+ am2): the step lines, written by the CLI's `onStepLine` into the draft's existing child.log; none when nothing listens
394
+ const stepWriter = typeof onStepLine === 'function' ? makeStepWriter(onStepLine) : null;
431
395
  const onBook = ({
432
- inFlight, calls, unmetered, metered, modelId: usedModel, price,
396
+ inFlight, calls, unmetered, metered, modelId: usedModel, price, partial,
433
397
  }) => {
398
+ if (stepWriter !== null && typeof partial === 'function') {
399
+ try { stepWriter(partial(), null, false); } catch { /* progress only: a failed line never fails the draft */ }
400
+ }
434
401
  const now = new Date().toISOString();
435
402
  startedAt ??= now;
436
403
  try {
@@ -522,6 +489,10 @@ export async function draftToDir({
522
489
  // M13 am11: the job's action (the last line the AI named, or the person agreed or typed), or null: the plan card's row `› line <n> writes everything before it`
523
490
  action: result.action ?? null,
524
491
  }), secrets);
492
+ // M20 am1 item 5: the last step lines (every step ended, final labels) are written before the result files, so a draft the panel sees finished already has them
493
+ if (stepWriter !== null) {
494
+ try { stepWriter(JSON.parse(files['log.json']), result.declaration ?? null, true); } catch { /* progress only */ }
495
+ }
525
496
  let hash = null;
526
497
  if (result.ok) {
527
498
  const declarationText = scrub(dj(result.declaration), secrets);
@@ -595,7 +566,8 @@ export function signDraft({
595
566
  dir, approve, signedBy, signedAt = new Date().toISOString(), env = process.env, keyNames, sessionDir, replaces, asRunOf,
596
567
  }) {
597
568
  const refuse = (...reds) => ({ ok: false, reds });
598
- if (readFileInside(dir, LEAK_MARKER_FILE).ok) return refuse(`sign: "${dir}" carries a key-leak marker (${LEAK_MARKER_FILE}) — never signed`);
569
+ const dv = draftVerdict(dir);
570
+ if (dv.leak.ok) return refuse(`sign: "${dir}" carries a key-leak marker (${LEAK_MARKER_FILE}) — never signed`);
599
571
  const openQuestion = questionsRefusal(dir);
600
572
  if (openQuestion !== null) return refuse(`sign: ${openQuestion}`);
601
573
  // Sign is $0 and takes no key, so it can only sweep for the keys it is told of (`keyNames`, the rows set up in Settings).
@@ -606,7 +578,7 @@ export function signDraft({
606
578
  const read = (f) => readFileInside(dir, f);
607
579
  const parts = {};
608
580
  for (const f of ['prose.txt', 'declaration.json', 'input-facts.json', 'readout.txt', SPEC_HASH_FILE, 'target.json']) {
609
- const r = read(f);
581
+ const r = f === SPEC_HASH_FILE ? dv.hashFile : read(f);
610
582
  if (!r.ok) return refuse(`sign: "${dir}" is not a green draft — ${f} ${r.missing ? 'is missing' : `is refused (${r.red})`}`);
611
583
  parts[f] = r.text;
612
584
  }
@@ -633,18 +605,18 @@ export function signDraft({
633
605
  if (!cat.ok) return refuse(`sign: catalogue: ${cat.reds.join('; ')}`);
634
606
  const verdict = validateDeclaration(declaration, {
635
607
  arbiter: signed.arbiter, lines: signed.lines, catalogue: cat.primitives, wired: WIRED_VERBS, verbatimGoals: true, fitJobLine: true,
608
+ addedCounts: addedCountsOf(readRowChoices(recordPath(dir)), signed.lines),
636
609
  });
637
610
  if (!verdict.ok) return { ok: false, reds: verdict.reds };
638
611
  // M19 am6 item 3 (bareloop `planMatchesClose`): the card a draft saved must equal the checks the signed plan runs, line by line; a difference refuses the sign at $0, naming the line.
639
612
  // Only a card saved with its own Not checked list (this build) is compared; an older saved card is drawn from the plan and not held to it.
640
613
  const cardReds = (() => {
641
614
  if (!Array.isArray(declaration.checkList)) return [];
642
- const lg = read('log.json');
643
- const rec = read(RECORD_FILE);
644
- /** @type {any} */ let log = null; /** @type {any} */ let record = null;
645
- try { log = lg.ok ? JSON.parse(lg.text) : null; record = rec.ok ? JSON.parse(rec.text) : null; } catch { return []; }
615
+ const keptRead = readKept(dir);
616
+ const log = readDraftLog(dir);
617
+ if (keptRead.torn) return []; // an unreadable record: the check skips
646
618
  if (!log?.checkCard || !Array.isArray(log.checkCard.notChecked)) return [];
647
- const kept = Array.isArray(record?.kept) ? record.kept.filter((/** @type {any} */ k) => k && Number.isInteger(k.line)) : [];
619
+ const kept = (keptRead.kept ?? []).filter((/** @type {any} */ k) => k && Number.isInteger(k.line));
648
620
  return planMatchesCard({ declaration, lines: signed.lines, csvRoles: csvRolesOf(signed.arbiter), kept, log: log.log }, log.checkCard);
649
621
  })();
650
622
  if (cardReds.length) return { ok: false, reds: cardReds };
package/src/blockasks.js CHANGED
@@ -3,7 +3,8 @@
3
3
  // The questions of the check block, as the answer gate reads them (`answerQuestions`, src/questionbox.js): ONE spelling of the question words, written by code from a row that
4
4
  // code could not settle (reading | check). The block's `open` list is the source; the person's CHOICE (agree | drop | rule) goes back through `block.applyAnswer`.
5
5
  import { readingQuestion } from './pageask.js';
6
- import { plainWords, HOW_TO_ANSWER } from './checkpick.js';
6
+ import { plainWords } from './checkpick.js';
7
+ import { HOW_TO_ANSWER } from './pageask.js';
7
8
 
8
9
  /** @typedef {{key: string, rowKey: string, line: number, rule: number, source: 'look', ask: 'reading'|'check', ruleText: string, question: string, counted: boolean, reading?: string, check?: Record<string, any>}} BlockAsk */
9
10
 
@@ -18,9 +18,11 @@ export const ASK_LINE_REASON = 'you judge it at the Ask';
18
18
  */
19
19
  export const SHAPE_ONLY_CLASS = 'green';
20
20
 
21
- import { REASON } from './checkblock.js';
21
+ import { REASON } from './reasons.js';
22
22
  import { KEPT_WORDS } from './pickrecord.js';
23
+ import { tagOf } from './checkwords.js';
23
24
  import { lineRules } from './pagebits.js';
25
+ import { dropRows, dropLine } from './pagedropwords.js';
24
26
  import { isListedNotChecked, notCheckedItem, ruleTextOf } from './checkrows.js';
25
27
  import { isRec } from './isrec.js';
26
28
 
@@ -122,10 +124,20 @@ export function assembleFromBlock({ declaration, block, lines, lineSet, askLines
122
124
  const own = block.rows.find((x) => x.key === r.key);
123
125
  if (own?.hidden) return null;
124
126
  // the reason is the signed row's own `reason` (src/checkblock.js REASON, the one table); M10 am17 (6): `kept` words
125
- const line = notCheckedItem(r, ruleTextOf(lines, r) ?? own?.text, own ? (own.name ? [own.name] : own.words) : undefined, own?.keptFromLast === true);
126
- if (r.by === 'you' || r.by === 'agent' || r.by === 'default') notCheckedBy[line] = r.by;
127
+ // M20 am9h (F238): a fact row the page look dropped tells its own drop, in the words of the look's line (this block is the one writer of it)
128
+ const line = own && own.kind === 'fact' && own.from === 'look' && own.lookWhy
129
+ ? `line ${own.line}: "${own.name}" \u2014 ${own.lookWhy}`
130
+ : notCheckedItem(r, ruleTextOf(lines, r) ?? own?.text, own ? (own.name ? [own.name] : own.words) : undefined, own?.keptFromLast === true);
131
+ if (tagOf(r.by) !== '') notCheckedBy[line] = r.by;
127
132
  return line;
128
133
  }).filter((x) => x !== null);
134
+ // M20 am9h (F238): every drop of the page look is said once, here: a row above already tells it, else it is a line of its own (a note about a word, or a fact whose rule is checked by another)
135
+ for (const row of dropRows(block.look?.dropped ?? [])) {
136
+ const line = dropLine(row, lines, lineRules);
137
+ if (notChecked.includes(line)) continue;
138
+ notChecked.push(line);
139
+ notCheckedBy[line] = 'default';
140
+ }
129
141
  for (const l of lines) {
130
142
  if (!askLines.has(l.n) || typeof l.guardrail !== 'string') continue;
131
143
  for (const rule of lineRules({ rule: l.guardrail })) {
package/src/blockdraft.js CHANGED
@@ -4,7 +4,7 @@
4
4
  import { redactSecrets } from './redact.js';
5
5
  import { newJobBlock } from './blocklines.js';
6
6
  import { EDIT_OPS } from './checkblock.js';
7
- import { isCountGuardrail } from './declaration.js';
7
+ import { isCountable } from './blockpick.js';
8
8
  import { ticketRuleField } from './ticketrows.js';
9
9
 
10
10
  /** the cap of refusals one revise turn carries (bareloop REVISE_RED_CAP) */
@@ -84,5 +84,5 @@ export const editRecord = (rec) => rec.edits.map((e) => ({ op: e?.op, accepted:
84
84
  */
85
85
  export function ticketLeaveOut(flowType, jobLines) {
86
86
  if (flowType !== 'tickets') return [];
87
- return jobLines.flatMap((l) => (l.rules ?? []).map((t, i) => ({ line: l.n, rule: i + 1, t })).filter((x) => ticketRuleField(x.t) !== null && !isCountGuardrail(x.t)).map((x) => ({ line: x.line, rule: x.rule })));
87
+ return jobLines.flatMap((l) => (l.rules ?? []).map((t, i) => ({ line: l.n, rule: i + 1, t })).filter((x) => ticketRuleField(x.t) !== null && !isCountable(x.t)).map((x) => ({ line: x.line, rule: x.rule })));
88
88
  }
package/src/blockpick.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // borrowed-from: bareloop src/checkpick.js@v0.57.0 (c18df406)
2
+ // fwd changed (M20 am8 item 2): guardrailItemCount keeps fwd's lookbehind (a number right after $ € £ . , is not an item count), and these readers are the one copy fwd's src/declaration.js re-exports.
2
3
  // first ported from: bareloop src/checkpick.js@v0.56.0 (3383cce) (isCountable, keepOrDrop, countCheck, partOfPick, sameRuleWords and what they call; HOW_TO_ANSWER and CANT_CHECK_WORDS are fwd's own, src/checkpick.js, the same words)
3
- // This file is bareloop's checkpick.js. fwd already has a src/checkpick.js (the M10 am16 pick path, whose keepOrDrop and countCheck differ from these); the check block calls THESE,
4
- // so they live here under another name and the am16 module is left as it is.
4
+ // This file is bareloop's checkpick.js. fwd's src/checkpick.js (the M10 am16 pick path) calls THESE keepOrDrop and countCheck (M20 am8 item 3: its own two are gone), as does the check block.
5
5
  // The pick vocabulary and its keep-or-drop: a suggested check is kept only if its rule is on bareguard's list and offered here, it carries only that rule's own fields, and every
6
6
  // number is one the person's rule names.
7
7
  import { rubricVocabulary } from 'bareguard';
@@ -18,7 +18,7 @@ const NUM_FIELDS = ['value', 'size', 'wordsPerSection'];
18
18
 
19
19
  const WORD_FIELDS = ['names', 'phrases'];
20
20
 
21
- // ---- the guardrail readers (fwd src/declaration.js@v0.29.0) ------------------------------------------------------------------------------
21
+ // ---- the guardrail readers: THE one copy (M20 am8 item 2; src/declaration.js re-exports them) ------------------------------------------------------------------------------
22
22
  const readNumber = (/** @type {string} */ t) => Number(t.replace(/,/g, ''));
23
23
 
24
24
  /** every whole-output word number in a guardrail ("under 600 words" -> [600]); a "<n> words each" / "per section" size is never listed here @param {unknown} g @returns {number[]} */
@@ -48,33 +48,59 @@ export function guardrailSectionCount(g) {
48
48
  return /^\d+$/.test(m[1]) ? Number(m[1]) : NUMBER_WORDS[m[1].toLowerCase()];
49
49
  }
50
50
 
51
- /** the first "<N> bullets / list items / items / lines / points" in a guardrail (digits, or one..ten), or null @param {unknown} g @returns {number|null} */
51
+ /** the first "<N> bullets / list items / items / lines / points" in a guardrail (digits, or one..ten; not a price like "$5 per item" or a decimal), or null @param {unknown} g @returns {number|null} */
52
52
  export function guardrailItemCount(g) {
53
- const m = typeof g === 'string' ? /\b(\d+|one|two|three|four|five|six|seven|eight|nine|ten)\s+(?:\w+\s+)?(?:bullets?|bullet\s+points?|list\s+items?|items?|lines?|points?)\b/i.exec(g) : null;
53
+ const m = typeof g === 'string' ? /(?<![$€£\d.,])\b(\d+|one|two|three|four|five|six|seven|eight|nine|ten)\s+(?:\w+\s+)?(?:bullets?|bullet\s+points?|list\s+items?|items?|lines?|points?)\b/i.exec(g) : null;
54
54
  if (!m) return null;
55
55
  return /^\d+$/.test(m[1]) ? Number(m[1]) : NUMBER_WORDS[m[1].toLowerCase()];
56
56
  }
57
57
 
58
- /** a list-bound word the guardrail uses: the count it names, or the one it stands for ("more than 3" = at least 4, "fewer than 3" = at most 2) */
59
- const MORE_THAN = /(?<!\b(?:no|not)\s)\bmore\s+than\s+(\d+)\b/i;
58
+ /** a list-bound word the guardrail uses: the count it names, or the one it stands for ("more than 3" = at least 4, "fewer than 3" = at most 2). The bound words are global: read them only through hasBound / firstBound / saysBound, never .test or .exec (a global regex keeps lastIndex between calls) */
59
+ const MORE_THAN = /(?<!\b(?:no|not)\s)\bmore\s+than\s+(\d+)\b/gi;
60
60
 
61
- const FEWER_THAN = /(?<!\b(?:no|not)\s)\b(?:(?:fewer|less)\s+than|under|below)\s+(\d+)\b/i;
61
+ const FEWER_THAN = /(?<!\b(?:no|not)\s)\b(?:(?:fewer|less)\s+than|under|below)\s+(\d+)\b/gi;
62
+
63
+ /** M20 am9d: "over N" reads like "more than N" for a WORDS rule (a list's "over" stays unread here, am8 item 3) */
64
+ const OVER = /(?<!\b(?:no|not)\s)\bover\s+(\d+)\b/gi;
65
+
66
+ /** does `text` say N with the word of `re` (one of the strict bound words above)? @param {RegExp} re @param {string} text @param {number} n */
67
+ const saysBound = (re, text, n) => [...String(text).matchAll(re)].some((m) => Number(m[1]) === n);
68
+ /** does `text` use the bound word `re` at all? search ignores and restores lastIndex @param {RegExp} re @param {string} text */
69
+ const hasBound = (re, text) => String(text).search(re) >= 0;
70
+ /** the first match of the bound word `re` in `text`, or undefined; matchAll works on a copy, so lastIndex stays 0 @param {RegExp} re @param {string} text */
71
+ const firstBound = (re, text) => String(text).matchAll(re).next().value;
72
+ const saysMoreThan = (/** @type {string} */ text, /** @type {number} */ n) => saysBound(MORE_THAN, text, n) || saysBound(OVER, text, n);
73
+
74
+ /** M20 am9d: the whole-output word bound a rule's own words stand for: "under / fewer than / below / less than N words" is at most N-1, "more than / over N words" is at least N+1; "at most / no more than / at least / no fewer than N" stay N. @param {string} text @param {number} n @returns {{rule: 'maxWords'|'minWords', value: number}} */
75
+ function wordsCheck(text, n) {
76
+ if (/\b(at least|min(?:imum)?|no fewer than)\b/i.test(text) || hasBound(MORE_THAN, text) || hasBound(OVER, text)) return { rule: 'minWords', value: saysMoreThan(text, n) ? n + 1 : n };
77
+ return { rule: 'maxWords', value: saysBound(FEWER_THAN, text, n) ? n - 1 : n };
78
+ }
62
79
 
63
80
  /** the direction of a list-items rule's wording: 'max', 'min' or null (exact / not said) @param {string} t @returns {'max'|'min'|null} */
64
81
  function listDirection(t) {
65
- if (/\b(at\s+most|up\s+to|no\s+more\s+than|not\s+more\s+than|max(?:imum)?(?:\s+of)?)\b/i.test(t) || FEWER_THAN.test(t)) return 'max';
66
- if (/\b(at\s+least|min(?:imum)?(?:\s+of)?|no\s+fewer\s+than|not\s+fewer\s+than)\b/i.test(t) || MORE_THAN.test(t)) return 'min';
82
+ if (/\b(at\s+most|up\s+to|no\s+more\s+than|not\s+more\s+than|max(?:imum)?(?:\s+of)?)\b/i.test(t) || hasBound(FEWER_THAN, t)) return 'max';
83
+ if (/\b(at\s+least|min(?:imum)?(?:\s+of)?|no\s+fewer\s+than|not\s+fewer\s+than)\b/i.test(t) || hasBound(MORE_THAN, t)) return 'min';
67
84
  return null;
68
85
  }
69
86
 
70
87
  /** the numbers a rule may carry: the standalone numbers of the guardrail, plus N+1 for "more than N" (min) and N-1 for "fewer than N" (max) @param {string} rule @param {string} g @returns {number[]} */
71
88
  function listBoundNumbers(rule, g) {
72
89
  const named = guardrailStandaloneNumbers(g);
73
- if (rule === 'minListItems') { const m = MORE_THAN.exec(g); if (m) named.push(Number(m[1]) + 1); }
74
- if (rule === 'maxListItems') { const m = FEWER_THAN.exec(g); if (m) named.push(Number(m[1]) - 1); }
90
+ if (rule === 'minListItems') { const m = firstBound(MORE_THAN, g); if (m) named.push(Number(m[1]) + 1); }
91
+ if (rule === 'maxListItems') { const m = firstBound(FEWER_THAN, g); if (m) named.push(Number(m[1]) - 1); }
75
92
  return named;
76
93
  }
77
94
 
95
+ /** the numbers a words rule may carry: the guardrail's word numbers, but a number said with a strict word is its bound: "under N words" carries N-1 (not N: that is the rule's own edge, which fails it), "more than / over N words" carries N+1 @param {string} rule @param {string} g @returns {number[]} */
96
+ function wordBoundNumbers(rule, g) {
97
+ return guardrailWordNumbers(g).map((n) => {
98
+ if (rule === 'maxWords' && saysBound(FEWER_THAN, g, n)) return n - 1;
99
+ if (rule === 'minWords' && saysMoreThan(g, n)) return n + 1;
100
+ return n;
101
+ });
102
+ }
103
+
78
104
  /** @param {unknown} g @returns {boolean} the rule is a COUNT bareguard checks (words, list items or lines, sections): code reads it, whatever the page look said about it */
79
105
  export const isCountable = (g) => guardrailWordNumbers(g).length > 0 || guardrailItemCount(g) !== null || guardrailSectionCount(g) !== null;
80
106
 
@@ -110,7 +136,7 @@ export function keepOrDrop(guardrail, sug) {
110
136
  if (NUM_FIELDS.includes(k)) {
111
137
  const floor = rule === 'maxListItems' ? 0 : 1; // maxListItems 0 = no bullets (bareguard 0.35); every other count starts at 1
112
138
  if (!Number.isInteger(v) || v < floor) return { kept: false, why: `${k} ${JSON.stringify(v)} is not a whole number >= ${floor}` };
113
- const named = rule === 'maxWords' || rule === 'minWords' ? guardrailWordNumbers(guardrail)
139
+ const named = rule === 'maxWords' || rule === 'minWords' ? wordBoundNumbers(rule, guardrail)
114
140
  : k === 'wordsPerSection' ? [guardrailWordsPerSection(guardrail)].filter((x) => x !== null)
115
141
  : listBoundNumbers(rule, guardrail);
116
142
  if (!named.includes(v)) return { kept: false, why: `${k} ${v} is not a number the guardrail names (${named.join(', ') || 'it names none'})` };
@@ -157,11 +183,11 @@ export function countCheck(text) {
157
183
  if (items !== null && /\blines?\b/i.test(text) && !/\b(bullets?|items?|points?)\b/i.test(text)) built = { rule: 'maxLines', value: items };
158
184
  else if (items !== null) {
159
185
  const dir = listDirection(text);
160
- if (dir === 'min') built = { rule: 'minListItems', value: MORE_THAN.test(text) ? items + 1 : items };
161
- else if (dir === 'max') built = { rule: 'maxListItems', value: FEWER_THAN.test(text) ? items - 1 : items };
186
+ if (dir === 'min') built = { rule: 'minListItems', value: hasBound(MORE_THAN, text) ? items + 1 : items };
187
+ else if (dir === 'max') built = { rule: 'maxListItems', value: hasBound(FEWER_THAN, text) ? items - 1 : items };
162
188
  else built = { rule: 'listItems', value: items };
163
189
  }
164
- else if (words.length === 1 && !/\bbetween\b|\d\s*(?:-|–|to)\s*\d/i.test(text)) built = { rule: /\b(at least|min(?:imum)?|more than|over|no fewer than)\b/i.test(text) ? 'minWords' : 'maxWords', value: words[0] };
190
+ else if (words.length === 1 && !/\bbetween\b|\d\s*(?:-|–|to)\s*\d/i.test(text)) built = wordsCheck(text, words[0]);
165
191
  if (built === null) return null;
166
192
  const res = keepOrDrop(text, built);
167
193
  return res.kept ? res.check : null;