fwdloop 0.37.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 (140) hide show
  1. package/README.md +5 -19
  2. package/bin/fwdloop +51 -29
  3. package/package.json +1 -1
  4. package/src/ask.js +70 -148
  5. package/src/audit-fold.js +5 -4
  6. package/src/auditchecks.js +6 -4
  7. package/src/authoring.js +36 -64
  8. package/src/blockasks.js +2 -1
  9. package/src/blockassemble.js +7 -9
  10. package/src/blockdraft.js +2 -2
  11. package/src/blockpick.js +5 -5
  12. package/src/books.js +217 -12
  13. package/src/checkblock.js +25 -55
  14. package/src/checked.js +2 -3
  15. package/src/checklistsign.js +26 -5
  16. package/src/checklook.js +3 -1
  17. package/src/checkpick.js +5 -76
  18. package/src/cited-source.js +4 -4
  19. package/src/citedcheck.js +6 -11
  20. package/src/citedwords.js +9 -8
  21. package/src/closers.js +9 -6
  22. package/src/declaration.js +22 -55
  23. package/src/diary.js +23 -1
  24. package/src/draft-steps.js +11 -1
  25. package/src/drafter.js +28 -23
  26. package/src/draftfiles.js +127 -0
  27. package/src/draftspend.js +165 -17
  28. package/src/flow.js +42 -87
  29. package/src/flowmodel.js +1 -1
  30. package/src/index.js +3 -2
  31. package/src/inside.js +86 -0
  32. package/src/isrec.js +2 -0
  33. package/src/jsonl-append.js +33 -1
  34. package/src/learn.js +1 -1
  35. package/src/learnstore.js +20 -22
  36. package/src/line-checks.js +2 -3
  37. package/src/liveness.js +3 -0
  38. package/src/mcp-use.js +8 -9
  39. package/src/memo.js +13 -16
  40. package/src/minrule.js +16 -0
  41. package/src/model-step.js +3 -3
  42. package/src/page-words.js +8 -0
  43. package/src/pageask.js +8 -3
  44. package/src/pagebits.js +8 -1
  45. package/src/pagedropwords.js +1 -1
  46. package/src/pagerules.js +6 -3
  47. package/src/panel/author.js +121 -78
  48. package/src/panel/authorcard.js +21 -8
  49. package/src/panel/authorflows.js +3 -3
  50. package/src/panel/authorresume.js +3 -3
  51. package/src/panel/authorstart.js +15 -16
  52. package/src/panel/authortrigger.js +43 -70
  53. package/src/panel/data.js +125 -168
  54. package/src/panel/index.html +154 -63
  55. package/src/panel/jobgrid.js +3 -7
  56. package/src/panel/result.js +7 -10
  57. package/src/panel/resume.js +4 -3
  58. package/src/panel/scheduler.js +9 -9
  59. package/src/panel/server.js +8 -4
  60. package/src/panel/spawn.js +22 -11
  61. package/src/panel/tickets.js +2 -2
  62. package/src/pickrecord.js +51 -31
  63. package/src/placerule.js +3 -4
  64. package/src/planrebuild.js +19 -19
  65. package/src/primitives.js +1 -1
  66. package/src/provider.js +1 -1
  67. package/src/reasons.js +25 -0
  68. package/src/report.js +2 -1
  69. package/src/runfile.js +26 -2
  70. package/src/runner.js +57 -105
  71. package/src/runvalues.js +47 -24
  72. package/src/schedule-choices.js +41 -0
  73. package/src/schedule-shape.js +39 -0
  74. package/src/schedule.js +9 -8
  75. package/src/setup.js +20 -36
  76. package/src/shaperows.js +2 -2
  77. package/src/sheet-record.js +1 -2
  78. package/src/sheetblock.js +3 -4
  79. package/src/sheetbuild.js +5 -5
  80. package/src/sheetchecks.js +1 -2
  81. package/src/sheetclaims.js +1 -2
  82. package/src/sheetoffer.js +1 -1
  83. package/src/sheetrun.js +5 -7
  84. package/src/summary-words.js +2 -1
  85. package/src/thinking.js +5 -2
  86. package/src/ticketrows.js +8 -30
  87. package/src/trigger-clock.js +9 -23
  88. package/src/trigger-files.js +30 -22
  89. package/src/trigger-tickets.js +15 -14
  90. package/src/try-checks.js +2 -1
  91. package/src/types.js +2 -0
  92. package/types/ask.d.ts +25 -20
  93. package/types/authoring.d.ts +8 -42
  94. package/types/blockassemble.d.ts +0 -1
  95. package/types/blockpick.d.ts +1 -1
  96. package/types/books.d.ts +256 -4
  97. package/types/checkblock.d.ts +2 -25
  98. package/types/checklist.d.ts +3 -3
  99. package/types/checklistsign.d.ts +7 -0
  100. package/types/checkpick.d.ts +0 -21
  101. package/types/citedwords.d.ts +7 -4
  102. package/types/closers.d.ts +1 -0
  103. package/types/declaration.d.ts +4 -14
  104. package/types/diary.d.ts +14 -1
  105. package/types/draft-steps.d.ts +7 -0
  106. package/types/drafter.d.ts +3 -2
  107. package/types/draftfiles.d.ts +89 -0
  108. package/types/draftspend.d.ts +74 -0
  109. package/types/flow.d.ts +32 -54
  110. package/types/index.d.ts +3 -3
  111. package/types/inside.d.ts +58 -0
  112. package/types/isrec.d.ts +1 -0
  113. package/types/jsonl-append.d.ts +20 -0
  114. package/types/learnstore.d.ts +0 -2
  115. package/types/liveness.d.ts +1 -0
  116. package/types/minrule.d.ts +6 -0
  117. package/types/page-words.d.ts +6 -0
  118. package/types/pageask.d.ts +2 -0
  119. package/types/pagebits.d.ts +3 -0
  120. package/types/pagerules.d.ts +1 -0
  121. package/types/panel/author.d.ts +7 -3
  122. package/types/panel/authorcard.d.ts +0 -6
  123. package/types/panel/authorflows.d.ts +4 -4
  124. package/types/panel/authortrigger.d.ts +16 -2
  125. package/types/panel/data.d.ts +36 -11
  126. package/types/panel/spawn.d.ts +18 -2
  127. package/types/pickrecord.d.ts +29 -0
  128. package/types/reasons.d.ts +23 -0
  129. package/types/runfile.d.ts +14 -0
  130. package/types/runner.d.ts +6 -38
  131. package/types/runvalues.d.ts +17 -2
  132. package/types/schedule-choices.d.ts +9 -0
  133. package/types/schedule-shape.d.ts +15 -0
  134. package/types/sheetbuild.d.ts +1 -1
  135. package/types/sheetclaims.d.ts +0 -1
  136. package/types/thinking.d.ts +1 -0
  137. package/types/ticketrows.d.ts +0 -9
  138. package/types/trigger-clock.d.ts +3 -2
  139. package/types/trigger-files.d.ts +15 -4
  140. package/types/types.d.ts +8 -0
@@ -4,6 +4,8 @@
4
4
  // What a run recorded for a check is read off its diary (`checks` rows: each check numbered with its `ok`, and for a list line its `part`); nothing is re-derived. What this throws away: the checks of a line off the list
5
5
  // (the sheet and the older plans keep their own Audit rows), and the per-try history (the LAST try of a step is the one that closed it).
6
6
  import { listLinesOf } from './checklistsign.js';
7
+ import { tagOf } from './checkwords.js';
8
+ import { newestChecksOf } from './diary.js';
7
9
  import { listPartRows, notCheckedView } from './checked.js';
8
10
  import { EVERY_STEP, EVERY_STEP_TEXTS } from './try-checks.js';
9
11
  import { sheetRowsOf } from './sheetrows.js';
@@ -25,7 +27,7 @@ export function auditChecksOf(declaration, diary, notChecked, { lines: jobLines
25
27
  const sheetRows = sheetOn ? sheetRowsOf({ declaration, lines: jobLines, csvRoles }) : null;
26
28
  if (lines.size === 0 && !(sheetRows && sheetRows.card.length > 0)) return null;
27
29
  const steps = (Array.isArray(declaration?.steps) ? declaration.steps : []).filter((/** @type {any} */ st) => lines.has(st?.fromLine));
28
- const lastTry = (/** @type {any} */ st) => (Array.isArray(diary) ? diary : []).filter((d) => d.step === (st.emits ?? st.goal ?? null)).at(-1);
30
+ const lastTry = (/** @type {any} */ st) => newestChecksOf(Array.isArray(diary) ? diary : [], st.emits ?? st.goal ?? null) ?? undefined;
29
31
  /** @type {AuditCheckRow[]} */
30
32
  const checks = [];
31
33
  // the same rows by the job line that owns them, their words without the `line N · ` prefix (S7: one block per line)
@@ -62,13 +64,13 @@ export function auditChecksOf(declaration, diary, notChecked, { lines: jobLines
62
64
  // M17 am4 (C3): the Audit splits a reading note from Not checked as the card and the Job tab do (src/checked.js notCheckedView)
63
65
  const view = notCheckedView(notChecked?.items ?? [], declaration);
64
66
  /** @type {AuditCheckRow[]} */
65
- const notRows = view.items.map((t) => ({ ...splitNotChecked(t), by: by[t] === 'you' || by[t] === 'agent' || by[t] === 'default' ? /** @type {'you'|'agent'|'default'} */ (by[t]) : null, result: 'not-checked' }));
67
+ const notRows = view.items.map((t) => ({ ...splitNotChecked(t), by: tagOf(by[t]) !== '' ? /** @type {'you'|'agent'|'default'} */ (by[t]) : null, result: 'not-checked' }));
66
68
  // the two checks every step has (src/try-checks.js #1 and #2): passed when every step that ran them passed, failed when one did not
67
69
  const every = (/** @type {string} */ text) => {
68
- const seen = (Array.isArray(diary) ? diary : []).flatMap((d) => (d.checks ?? []).filter((/** @type {any} */ c) => c.source === EVERY_STEP && c.text === text));
70
+ const seen = (Array.isArray(diary) ? diary : []).flatMap((d) => (Array.isArray(d.checks) ? d.checks : []).filter((/** @type {any} */ c) => c.source === EVERY_STEP && c.text === text));
69
71
  return seen.length === 0 ? 'none' : seen.every((/** @type {any} */ c) => c.ok) ? 'passed' : 'failed';
70
72
  };
71
- const everyWhy = (/** @type {string} */ text) => whyOf((Array.isArray(diary) ? diary : []).flatMap((d) => (d.checks ?? []).filter((/** @type {any} */ c) => c.source === EVERY_STEP && c.text === text)).find((/** @type {any} */ c) => !c.ok));
73
+ const everyWhy = (/** @type {string} */ text) => whyOf((Array.isArray(diary) ? diary : []).flatMap((d) => (Array.isArray(d.checks) ? d.checks : []).filter((/** @type {any} */ c) => c.source === EVERY_STEP && c.text === text)).find((/** @type {any} */ c) => !c.ok));
72
74
  /** @type {AuditCheckRow[]} */
73
75
  const always = EVERY_STEP_TEXTS.map((text) => ({ text, kind: 'file', by: /** @type {'default'} */ ('default'), result: every(text), ...everyWhy(text) }));
74
76
  // M19 S7: one block per job line (its checks, its Not checked rows) and the Not checked rows no line owns; the two every-step rows are the page's "Every line" block (a one-line job's Line 1 block)
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,14 +347,14 @@ 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),
392
354
  }) {
393
- const refuse = (reds) => ({ ok: false, wrote: false, reds, costUsd: 0 });
355
+ const refuse = (reds, box = /** @type {string|null} */ (null)) => ({ ok: false, wrote: false, reds, costUsd: 0, box });
394
356
  const nameCheck = checkFlowName(name);
395
- if (!nameCheck.ok) return refuse([nameCheck.red]);
357
+ if (!nameCheck.ok) return refuse([nameCheck.red], 'flowName');
396
358
  if (typeof root !== 'string' || root === '') return refuse(['draft: --root <flows dir> is required']);
397
359
  // An unsigned draft folder inside the flows root would list as a flow in the panel and Inbox (checked by realpath, at use time).
398
360
  const realRoot = realpathOfNew(root);
@@ -410,7 +372,7 @@ export async function draftToDir({
410
372
  const injected = provider != null;
411
373
  if (!injected) {
412
374
  const refusal = draftKeyRefusal(slot, env);
413
- if (refusal !== null) return refuse([refusal]);
375
+ if (refusal !== null) return refuse([refusal], 'model');
414
376
  }
415
377
  const secrets = keyValues(env, [...new Set([...(keyNames ?? []), ...(typeof slot === 'string' ? [slot] : [])])]);
416
378
  if (secrets.some((s) => s.length >= 8 && prose.text.includes(s))) return refuse(['prose: contains an API key value — refused']);
@@ -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 {
@@ -478,7 +445,7 @@ export async function draftToDir({
478
445
  });
479
446
  if (result.stop === 'pre-flight') {
480
447
  try { rmdirSync(dir); } catch { /* the claimed dir is still empty; leave it rather than mask the refusal */ }
481
- return refuse(cleanReds(result.reds));
448
+ return refuse(cleanReds(result.reds), result.box ?? null);
482
449
  }
483
450
  // M8 item 5a: what was handed is kept once beside the draft (only when a round was actually sent with it); a failure is recorded, never raised.
484
451
  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,15 +18,12 @@ export const ASK_LINE_REASON = 'you judge it at the Ask';
18
18
  */
19
19
  export const SHAPE_ONLY_CLASS = 'green';
20
20
 
21
- // fwd (F251): the no-guardrail words are the check block's (src/checkblock.js), the one writer; re-exported for the readers that import them from here
22
- export { NO_GUARDRAIL_WORDS } from './checkblock.js';
23
-
24
- import { REASON } from './checkblock.js';
21
+ import { REASON } from './reasons.js';
25
22
  import { KEPT_WORDS } from './pickrecord.js';
23
+ import { tagOf } from './checkwords.js';
26
24
  import { lineRules } from './pagebits.js';
27
25
  import { isListedNotChecked, notCheckedItem, ruleTextOf } from './checkrows.js';
28
-
29
- const isRec = (/** @type {unknown} */ v) => v !== null && typeof v === 'object' && !Array.isArray(v);
26
+ import { isRec } from './isrec.js';
30
27
 
31
28
  /** a countable part as the picked check the softgreen close runs: its own fields, the rule named `rule` (the inverse of the block's partOfPick) @param {Record<string, any>} part */
32
29
  export function pickedOf(part) {
@@ -67,7 +64,7 @@ export function assembleFromBlock({ declaration, block, lines, lineSet, askLines
67
64
  }
68
65
  if (!isRec(st) || !Number.isInteger(n) || !lineSet.has(n)) return st;
69
66
  const parts = partsOf(n);
70
- // fwd (F251): the check block is the one decider that a line with no ~ guardrail holds no check (src/checkblock.js buildLine), so every part it holds is kept here
67
+ // the check block is the one decider of which parts a line holds (src/checkblock.js buildLine), so every part it holds is kept here
71
68
  const fact = parts.find((p) => p.class === 'fact');
72
69
  // M19 S5: the shape part rides the fact part (facts+shape, class green); a line with no fact part takes it only when a class is ruled for it (`shapeOnlyClass`)
73
70
  const picks = parts.filter((p) => p.class === 'countable' && p.check !== 'cited' && p.check !== 'numbersFromFacts');
@@ -102,7 +99,8 @@ export function assembleFromBlock({ declaration, block, lines, lineSet, askLines
102
99
  for (const n of lineSet) {
103
100
  const mine = steps.find((/** @type {any} */ st) => isRec(st) && st.fromLine === n);
104
101
  // the classes of a list line are code's: a line with no guardrail of the person's has no class entry, whatever the AI sent
105
- if (!guarded(n)) { delete guardrailClasses[String(n)]; continue; }
102
+ // M19 am15 (F257): a line with no guardrail of the person's has a class only when a check the person Added holds it; else no entry (hitl)
103
+ if (!guarded(n) && (!mine || mine.close.class === 'hitl')) { delete guardrailClasses[String(n)]; continue; }
106
104
  if (!mine) continue;
107
105
  guardrailClasses[String(n)] = mine.close.class;
108
106
  }
@@ -126,7 +124,7 @@ export function assembleFromBlock({ declaration, block, lines, lineSet, askLines
126
124
  if (own?.hidden) return null;
127
125
  // the reason is the signed row's own `reason` (src/checkblock.js REASON, the one table); M10 am17 (6): `kept` words
128
126
  const line = notCheckedItem(r, ruleTextOf(lines, r) ?? own?.text, own ? (own.name ? [own.name] : own.words) : undefined, own?.keptFromLast === true);
129
- if (r.by === 'you' || r.by === 'agent' || r.by === 'default') notCheckedBy[line] = r.by;
127
+ if (tagOf(r.by) !== '') notCheckedBy[line] = r.by;
130
128
  return line;
131
129
  }).filter((x) => x !== null);
132
130
  for (const l of lines) {
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,9 +48,9 @@ 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
  }