bareloop 0.56.0 → 0.58.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 (93) hide show
  1. package/CHANGELOG.md +80 -0
  2. package/README.md +3 -3
  3. package/bareloop.context.md +75 -214
  4. package/package.json +2 -2
  5. package/src/authorflow.js +71 -136
  6. package/src/authoring.js +5 -124
  7. package/src/authorjob.js +125 -417
  8. package/src/authorreadout.js +105 -355
  9. package/src/authorrun.js +70 -234
  10. package/src/authorscout.js +9 -1
  11. package/src/blockasks.js +12 -17
  12. package/src/bundlerun.js +4 -1
  13. package/src/checkblock.js +297 -75
  14. package/src/checklist.js +1 -1
  15. package/src/checkpick.js +9 -5
  16. package/src/cli.js +3 -3
  17. package/src/declaredclose.js +45 -112
  18. package/src/destpoint.js +1 -1
  19. package/src/draftspend.js +20 -4
  20. package/src/fencepointcall.js +76 -0
  21. package/src/guarddescriptions.js +14 -0
  22. package/src/index.js +3 -43
  23. package/src/interviewrun.js +13 -8
  24. package/src/job.js +20 -1
  25. package/src/jobblock.js +11 -46
  26. package/src/judged.js +13 -1229
  27. package/src/kinds.js +10 -348
  28. package/src/noteask.js +124 -0
  29. package/src/pagedry.js +27 -5
  30. package/src/pagemap.js +7 -29
  31. package/src/pagerules.js +18 -3
  32. package/src/panel/authorroutes.js +15 -4
  33. package/src/panel/authorsession.js +201 -167
  34. package/src/panel/importrun.js +0 -1
  35. package/src/panel/index.html +43 -18
  36. package/src/panel/jobplan.js +54 -19
  37. package/src/panel/server.js +90 -69
  38. package/src/panel/status.js +3 -0
  39. package/src/pickrecord.js +15 -54
  40. package/src/planrun.js +4 -48
  41. package/src/promptregisters.js +7 -17
  42. package/src/providerrows.js +0 -36
  43. package/src/providers.js +4 -25
  44. package/src/questionbox.js +34 -30
  45. package/src/reviewdoor.js +1 -1
  46. package/src/rowresults.js +69 -0
  47. package/src/rubricstep.js +136 -28
  48. package/src/run.js +2 -15
  49. package/src/stagewords.js +24 -0
  50. package/src/userrun.js +14 -111
  51. package/types/authorflow.d.ts +51 -137
  52. package/types/authoring.d.ts +1 -14
  53. package/types/authorjob.d.ts +14 -55
  54. package/types/authorreadout.d.ts +52 -80
  55. package/types/authorrun.d.ts +20 -0
  56. package/types/blockasks.d.ts +5 -11
  57. package/types/checkblock.d.ts +147 -28
  58. package/types/checklist.d.ts +2 -2
  59. package/types/checkpick.d.ts +5 -3
  60. package/types/cli.d.ts +1 -3
  61. package/types/declaredclose.d.ts +5 -33
  62. package/types/draftspend.d.ts +16 -2
  63. package/types/fencepointcall.d.ts +68 -0
  64. package/types/guarddescriptions.d.ts +7 -0
  65. package/types/index.d.ts +2 -4
  66. package/types/job.d.ts +8 -0
  67. package/types/jobblock.d.ts +8 -38
  68. package/types/judged.d.ts +7 -357
  69. package/types/kinds.d.ts +4 -104
  70. package/types/noteask.d.ts +76 -0
  71. package/types/pagedry.d.ts +13 -0
  72. package/types/pagemap.d.ts +2 -5
  73. package/types/pagerules.d.ts +7 -0
  74. package/types/panel/authorsession.d.ts +37 -5
  75. package/types/panel/jobplan.d.ts +15 -3
  76. package/types/panel/server.d.ts +46 -13
  77. package/types/panel/status.d.ts +5 -0
  78. package/types/pickrecord.d.ts +8 -13
  79. package/types/planrun.d.ts +1 -22
  80. package/types/providerrows.d.ts +0 -31
  81. package/types/providers.d.ts +3 -19
  82. package/types/questionbox.d.ts +20 -6
  83. package/types/rowresults.d.ts +23 -0
  84. package/types/rubricstep.d.ts +43 -7
  85. package/types/run.d.ts +1 -20
  86. package/types/stagewords.d.ts +11 -0
  87. package/types/userrun.d.ts +0 -1
  88. package/src/calibrate.js +0 -702
  89. package/src/cardauthor.js +0 -502
  90. package/src/fitcheck.js +0 -168
  91. package/types/calibrate.d.ts +0 -201
  92. package/types/cardauthor.d.ts +0 -358
  93. package/types/fitcheck.d.ts +0 -119
package/src/checkblock.js CHANGED
@@ -1,13 +1,17 @@
1
- // THE CHECK BLOCK of a rubric job (hamr 2026-11-12: "goal again is simplfication and one flow one place ai suggestes ! code adds $ and code decides what worked/doable").
1
+ // THE CHECK BLOCK of a job (hamr 2026-11-12: "goal again is simplfication and one flow one place ai suggestes ! code adds $ and code decides what worked/doable").
2
2
  // ONE store: `rows`. Nothing else holds a check. Rows are `~` (the person's own rule), `!` (the agent's suggestion: a look fact, or an AI edit) and `$` (code's defaults).
3
3
  // The AI's whole part is a list of proposed ROW EDITS; code judges each edit alone, matches every row against the saved page, builds every check through the bareguard-backed
4
4
  // shapes, and says why a row it cannot build is Not checked. The block never removes a row: only the person (`applyAnswer`) or code (`match`) changes one.
5
5
  // fromJob -> addLook -> reconcile( match -> build -> ask ), then, while a question is open or a reply waits: apply it and reconcile the WHOLE list again.
6
- // Pure: no I/O, no clock, no model. Rubric jobs only (repo jobs never run through it).
6
+ // Pure: no I/O, no clock, no model. ONE block for every job (hamr 2026-11-15: "same flow as rubric, no exceptions; same CheckBlock, only the TYPE of checks varies"). A rubric job's rows are facts, phrases and
7
+ // counts built into rubric-step parts; a repo job (`repo` option) holds `~` rule rows the write fence keeps (or that the person answers about), `!` rows for the drafter's catalogue work stages, and the same `$` rows.
8
+ // The same rows store, the same asks, the same Drop/carry, the same signedRows and closeView serve both.
9
+ import { globToPrefix } from './validate.js';
7
10
  import { countExact, countPhrase, checkFactWords, keptSetOf } from './factwords.js';
8
- import { isCountable, keepOrDrop, countCheck, partOfPick, plainWords, sameRuleWords } from './checkpick.js';
9
- import { dropRows } from './pagedropwords.js';
10
- import { boundInWords, rubricStepShapeReds, defaultCitedText, readLimit, holdsManyBounds, NEGATING_RE } from './rubricstep.js';
11
+ import { isCountable, keepOrDrop, countCheck, obviousCheck, partOfPick, plainWords, sameRuleWords } from './checkpick.js';
12
+ import { dropRows, dropSentence } from './pagedropwords.js';
13
+ import { phraseInNoResult } from './pagedry.js';
14
+ import { boundInWords, rubricStepShapeReds, floorWords, stageKeyOf, guardKeyOf, FENCE_KEY, PROSE_WORDS, defaultCitedText, defaultNoteText, readLimit, holdsManyBounds, NEGATING_RE, WHY_OTHER_CURRENCY } from './rubricstep.js';
11
15
  import { validReading } from './pagerules.js';
12
16
  import { weekOnly, weekTokens, WEEK_ONLY_WORDS, MAX_BANG } from './checklist.js';
13
17
  import { fitPlacePhrase } from './placerule.js';
@@ -22,10 +26,10 @@ import { factSentence, countSentence } from './facts.js';
22
26
  */
23
27
 
24
28
  /** the card's fixed words, one spelling (the renderer reads them; a test reads them too) */
25
- export const CARD_T = Object.freeze({ agreed: 'you agreed:', count: 'result count', cited: 'every claim is backed by a quote copied from', theInput: 'the input', numbers: 'every number in the text is in a checked quote of line', withWords: 'with the words' });
29
+ export const CARD_T = Object.freeze({ count: 'result count', cited: 'every claim is backed by a quote copied from', theInput: 'the input', numbers: 'every number in the text is in a checked quote of line', withWords: 'with the words' });
26
30
 
27
31
  /** the four row edits an AI reply may hold */
28
- export const EDIT_OPS = Object.freeze(['add', 'reading', 'pick', 'not-checkable']);
32
+ export const EDIT_OPS = Object.freeze(['add', 'reading', 'pick', 'not-checkable', 'fence']);
29
33
 
30
34
  const norm = (/** @type {unknown} */ t) => String(t ?? '').toLowerCase().replace(/\s+/g, ' ').trim();
31
35
  const isRec = (/** @type {unknown} */ v) => v !== null && typeof v === 'object' && !Array.isArray(v);
@@ -39,7 +43,6 @@ const wordSet = (/** @type {unknown} */ t) => new Set(norm(t).match(/[\p{L}\p{N}
39
43
  export const REASON = Object.freeze({
40
44
  left: 'You chose to leave it Not checked, so you judge it at Accept.',
41
45
  nothingOnPage: 'Your own words are on the line; the machine has no check for them, so you judge it at Accept.',
42
- cantCheck: "I can't check this on the page; waiting for your answer",
43
46
  noRule: 'No rule can check this, so you judge it at Accept.',
44
47
  waitingPick: 'waiting for your answer on the proposed check',
45
48
  waitingReading: 'waiting for your answer on the reading',
@@ -47,6 +50,7 @@ export const REASON = Object.freeze({
47
50
  manyInputs: 'the job has more than one input and code cannot pick which one the claims quote',
48
51
  oneSidedTime: 'a time limit the AI proposes must be a range, so you judge it at Accept.',
49
52
  countNeedsFact: 'a result count needs a fact to count; this line has none',
53
+ countNeedsSuggested: 'a result count needs a fact to count; add the suggested fact on this line to count its results',
50
54
  lookNoWords: "the page does not hold the words of the look's fact for this rule",
51
55
  afterLast: 'no more tries: Start over (rows are never changed by the AI after the last try)',
52
56
  noPick: 'No check was picked for it, so you judge it at Accept.',
@@ -57,11 +61,14 @@ export const REASON = Object.freeze({
57
61
 
58
62
  /** the card lines: rows in, lines out. ONE pure function of the rows; nothing else may feed it. @param {Row[]} rows */
59
63
  export function renderCard(rows) {
60
- return rows.filter((r) => r.kind !== 'floor' && r.state !== 'suggested' && r.state !== 'dropped' && !r.hidden).map((r) => {
64
+ return rows.filter((r) => r.state !== 'suggested' && r.state !== 'dropped' && !r.hidden).map((r) => {
61
65
  let body;
62
- if (r.kind === 'rule') body = `"${r.text}"${r.pick ? ` -> ${plainWords(r.pick)}` : ''}${r.agreedText ? ` (${CARD_T.agreed} ${r.agreedText})` : ''}`;
66
+ if (r.kind === 'floor') body = floorWords(r.line, r.carriesText !== false);
67
+ else if (r.kind === 'prose') body = PROSE_WORDS;
68
+ else if (r.kind === 'rule') body = `"${r.text}"${r.pick && !sameRuleWords(r.text, plainWords(r.pick)) ? ` -> ${plainWords(r.pick)}` : ''}`;
63
69
  else if (r.kind === 'count') body = `${CARD_T.count} ${r.min ?? ''}-${r.max ?? ''}`;
64
70
  else if (r.kind === 'cited') body = `${CARD_T.cited} "${r.source ?? CARD_T.theInput}"`;
71
+ else if (r.kind === 'note') body = defaultNoteText(r.line);
65
72
  else if (r.kind === 'numbers') body = `${CARD_T.numbers} ${(r.after ?? []).join(', ')}`;
66
73
  else body = `${r.kind} "${r.name ?? r.words?.[0] ?? ''}"${r.words?.length ? ` ${CARD_T.withWords} ${r.words.map((/** @type {string} */ w) => `"${w}"`).join(', ')}` : ''}`;
67
74
  return { key: r.key, line: r.line, by: r.by, state: r.state, reason: r.reason ?? null, text: `${r.by === 'you' ? '~' : r.by === 'agent' ? '!' : '$'} ${body}` };
@@ -80,9 +87,25 @@ function placeFacts(name, strips, mk) {
80
87
  return strips.map((s) => mk(nm(s.kind), { shape: 'phrase', phrase: s.value, place: s.rule }));
81
88
  }
82
89
 
90
+ /**
91
+ * The Drop/Add choices of rows, tied to the line's words (not its number) and the row's own name, so a Revise keeps them. ONE owner for the block's own record and for a Drop made on a signed card.
92
+ * @param {{n: number, text: string}[]} lines @param {{line: number, key: string, choice: string}[]} picks @returns {{lineWords: string, occurrence: number, tail: string, choice: string}[]}
93
+ */
94
+ export function choiceEntries(lines, picks) {
95
+ const seen = new Map();
96
+ const key = new Map(lines.map((l) => { const w = norm(l.text); const o = seen.get(w) ?? 0; seen.set(w, o + 1); return [l.n, { lineWords: w, occurrence: o }]; }));
97
+ return picks.map((p) => ({ ...(key.get(p.line) ?? { lineWords: '', occurrence: 0 }), tail: p.key.replace(/^L\d+\./, ''), choice: String(p.choice) }));
98
+ }
99
+
83
100
  export class CheckBlock {
84
- /** @param {{texts: Record<string, string>, labels: string[], maxTries?: number, countScope?: (ruleText: string) => boolean, asks?: boolean, split?: boolean}} o the frozen input texts, their labels, how many AI replies (tries) may still change a row, whether code scopes a counting `~` rule in (a pick is asked), and whether a person can be asked at all (`asks`: false = a rule code cannot settle is Not checked, a reading code proposes is built as the AI's proposal) */
85
- constructor({ texts, labels, maxTries = 3, countScope = () => true, asks = true, split = false }) {
101
+ /** @param {{texts: Record<string, string>, labels: string[], maxTries?: number, countScope?: (ruleText: string) => boolean, asks?: boolean, split?: boolean, repo?: {files: string[]|null, writeScope: string[]|null}|null}} o the frozen input texts, their labels, how many AI replies (tries) may still change a row, whether code scopes a counting `~` rule in (a pick is asked), and whether a person can be asked at all (`asks`: false = a rule code cannot settle is Not checked, a reading code proposes is built as the AI's proposal) */
102
+ constructor({ texts, labels, maxTries = 3, countScope = () => true, asks = true, split = false, repo = null }) {
103
+ /** a repo job's check TYPE (the only thing that varies): `files` = the repo listing at the seed (null until it is read), `writeScope` = the signed write fence. Null = a rubric job @type {{files: string[]|null, writeScope: string[]|null}|null} */
104
+ this.repo = repo;
105
+ /** @type {any[]} a repo job's drafted stages as the drafter wrote them (guards included); the rows of the work stages are in `rows`, the close's stages are these minus the dropped ones */
106
+ this.declared = [];
107
+ /** the job lines a mandatory guard already covers (`guardLines`): a repo stage is never dropped when it is the last thing covering a line @type {Set<number>} */
108
+ this.guardCover = new Set();
86
109
  /** the product path sets it: `!` rows split into job-derived and suggested, a suggestion code cannot build is hidden (hamr 2026-11-13). Off, every `!` row is built as before (the older callers and their tests) */
87
110
  this.split = split;
88
111
  this.countScope = countScope;
@@ -109,12 +132,23 @@ export class CheckBlock {
109
132
  this.deltaLog = [];
110
133
  /** @type {any} */
111
134
  this.closeCache = null;
135
+ /** @type {Map<number, 'yes'|'no'|'failed'>} the note question's answer per facts-only line (src/noteask.js; code decides what it means) */
136
+ this.notes = new Map();
137
+ /** @type {string[]} the NAMES of the mandatory guards the close carries (Addendum 2026-11-14 (c) piece 2): each is a job-level `$` row of the signed list, never a row of `rows` (no line, so no check of a line) */
138
+ this.guards = [];
139
+ /** @type {string[]|null} the write fence of the job: a job-level `$` row of the signed list (hamr 2026-11-15), never a row of `rows` */
140
+ this.fence = null;
112
141
  }
113
142
 
143
+ /** the mandatory guards of this job's class, by name: signedRows() adds one `$` guard row for each, once for the whole job @param {string[]} names @param {string[]|null} [fence] the signed write fence, when the job has one */
144
+ setGuards(names, fence = null) { this.guards = [...new Set(names)]; this.fence = Array.isArray(fence) && fence.length ? [...fence] : null; }
145
+
114
146
  textOf(/** @type {string|undefined} */ source) { return this.texts[source ?? this.labels[0] ?? ''] ?? Object.values(this.texts)[0] ?? ''; }
115
147
  /** @param {number} line @param {string} [kind] */
116
148
  rowsOn(line, kind) { return this.rows.filter((r) => r.line === line && (kind === undefined || r.kind === kind)); }
117
149
  ruleRows(/** @type {number} */ line) { return this.rows.filter((r) => r.kind === 'rule' && r.line === line); }
150
+ /** does a `~` rule's own row say it is Not checked? Then its row is the ONE place the rule is said (its reason: the look's sentence, or the person's Drop) @param {number} line @param {number} rule */
151
+ saysRule(line, rule) { return this.rows.some((r) => r.kind === 'rule' && r.line === line && r.rule === rule && r.state === 'not-checked' && typeof r.reason === 'string' && r.reason !== ''); }
118
152
  /** every word the person wrote on a line: the line and its `~` rules */
119
153
  said(/** @type {number} */ line) { return [this.lines.find((l) => l.n === line)?.text ?? '', ...this.ruleRows(line).map((r) => r.text)].join(' '); }
120
154
  /** @param {Row} r @returns {Row} the row as stored (a repeated key gets `#2`) */
@@ -131,7 +165,7 @@ export class CheckBlock {
131
165
  for (const l of jobLines) {
132
166
  this.lines.push({ n: l.n, text: l.text });
133
167
  (l.rules ?? []).forEach((t, i) => this.addRow({ key: `L${l.n}.~${i + 1}`, line: l.n, kind: 'rule', by: 'you', from: 'rule', origin: 'job', text: t, rule: i + 1 }));
134
- this.addRow({ key: `L${l.n}.$floor`, line: l.n, kind: 'floor', by: 'default', from: 'default', state: 'built', reason: null, text: "the file exists and its text is not empty (code's own floor)" });
168
+ if (this.repo === null) this.addRow({ key: `L${l.n}.$floor`, line: l.n, kind: 'floor', by: 'default', from: 'default', state: 'built', reason: null, text: "the file exists and its text is not empty (code's own floor)" });
135
169
  }
136
170
  }
137
171
 
@@ -153,7 +187,10 @@ export class CheckBlock {
153
187
  this.lookFacts.push(f);
154
188
  // a fact the look tied to a COUNTING `~` rule stays a fact of its own: the pick path owns that rule (R10, hamr 2026-11-09), so the rule uses no link
155
189
  const tied = Number.isInteger(f.forRule) ? this.ruleRows(f.line).find((r) => r.rule === f.forRule) : undefined;
156
- const row = tied && !isCountable(tied.text) ? tied : undefined;
190
+ // hamr 2026-11-15 (live run mwi76vh8, "be friendly" + "Select flight"): a phrase or place the person's own `~` rule words do not contain is no check of that rule; it is an ordinary `!` row (the split/inJob path
191
+ // decides Drop or Suggested) and the rule goes Not checked. A version or a date keeps the place-rule path; money, time, number and date links are unchanged.
192
+ const named = !tied || !['phrase', 'place'].includes(f.shape) || (f.words ?? []).some((/** @type {string} */ w) => weekOnly(w) || norm(tied.text).includes(norm(w)));
193
+ const row = tied && named && !isCountable(tied.text) ? tied : undefined;
157
194
  const carried = { name: f.name, shape: f.shape, words: [...(f.words ?? [])], unit: f.unit, currency: f.currency, decimal: f.decimal, lang: f.lang, source: f.source };
158
195
  if (row) { (row.links ??= []).push({ ...carried, reading: f.reading }); continue; }
159
196
  this.addRow({ key: `L${f.line}.fact.${norm(f.name)}`, line: f.line, kind: 'fact', by: 'agent', from: 'look', ...carried });
@@ -170,8 +207,7 @@ export class CheckBlock {
170
207
  if (r.kind === 'floor') continue;
171
208
  if (r.left) r.can = { ok: false, why: REASON.left };
172
209
  else if (r.lookWhy && r.kind === 'fact' && !r.words.length) r.can = { ok: false, why: r.lookWhy };
173
- else if (r.folded) r.can = { ok: false, why: REASON.noPick };
174
- else if (r.parent) this.matchFollow(r);
210
+ else if (r.kind === 'stage') r.can = r.refusal ? { ok: false, why: r.said } : { ok: true, how: 'stage' };
175
211
  else if (r.kind === 'rule') this.matchRule(r);
176
212
  else if (r.kind === 'fact' || r.kind === 'phrase') this.matchBang(r);
177
213
  else if (r.kind === 'count') this.matchCount(r);
@@ -188,7 +224,7 @@ export class CheckBlock {
188
224
  }
189
225
 
190
226
  /** a `!` row: the agent's fact, phrase or count (a look fact tied to a rule is a link on that rule's row, never a row of its own) */
191
- isBang(/** @type {Row} */ r) { return r.by === 'agent' && (r.kind === 'fact' || r.kind === 'phrase' || r.kind === 'count') && !r.parent; }
227
+ isBang(/** @type {Row} */ r) { return r.by === 'agent' && (r.kind === 'fact' || r.kind === 'phrase' || r.kind === 'count'); }
192
228
 
193
229
  /**
194
230
  * The job's own word for a `!` row: when none of its page words is in the job line or its `~` rules but a proper name the job holds (capital or digit first, 3+ characters) is a whole-word part of one
@@ -208,14 +244,9 @@ export class CheckBlock {
208
244
  inJob(/** @type {Row} */ r) {
209
245
  const said = this.said(r.line);
210
246
  if (r.kind === 'count') return [r.min, r.max].filter((x) => Number.isInteger(x)).some((n) => new RegExp(`(?<![\\d.])${n}(?![\\d.])`).test(said));
211
- // a fact the person asked for BY NAME ("the release heading") is in the job too: the look's page words rarely echo the job's own words
212
- return (r.words ?? []).some((/** @type {string} */ w) => inText(said, w)) || (r.kind === 'fact' && typeof r.name === 'string' && inText(said, r.name));
213
- }
214
-
215
- /** a `~` line an agreed answer wrote (or a carried pair partner) is checked by the rule it was agreed from: one check, both numbers */
216
- matchFollow(/** @type {Row} */ r) {
217
- const parent = this.rows.find((x) => x.key === r.parent);
218
- r.can = parent?.can?.ok ? { ok: true, how: 'follow' } : { ok: false, why: parent?.can?.why ?? 'the rule it was agreed from is not checked' };
247
+ // a money, time, number or date fact the person asked for BY NAME ("the release heading") is in the job too: the look's page words rarely echo the job's own words. A phrase or place is job-derived
248
+ // only when its own words are in the person's text: a name the AI gave it is no proof (hamr 2026-11-15, live run mwi76vh8: "friendly" for "Select flight")
249
+ return (r.words ?? []).some((/** @type {string} */ w) => inText(said, w)) || (r.kind === 'fact' && r.shape !== 'phrase' && r.shape !== 'place' && typeof r.name === 'string' && inText(said, r.name));
219
250
  }
220
251
 
221
252
  /** a `!` count row is built unless a `~` rule on its line already names the number */
@@ -226,6 +257,7 @@ export class CheckBlock {
226
257
  }
227
258
 
228
259
  matchRule(/** @type {Row} */ r) {
260
+ if (this.repo !== null) { this.matchRepoRule(r); return; }
229
261
  if (isCountable(r.text)) { this.matchCountRule(r); return; }
230
262
  // F-a (hamr 2026-11-13): a rule that carries a negation ("nonstop is not mandatory") says what is NOT needed; its words can never give a phrase bound ("must say"). The one negation reader is NEGATING_RE.
231
263
  const negated = NEGATING_RE.test(r.text);
@@ -234,12 +266,16 @@ export class CheckBlock {
234
266
  const links = (r.links ?? []).filter((/** @type {any} */ l) => !(negated && isPhrase(l)) && l.words.some((/** @type {string} */ w) => proved(this.textOf(l.source), w)));
235
267
  const said = this.said(r.line);
236
268
  let ownWhy = null;
269
+ let otherCurrency = false;
237
270
  for (const l of links) {
238
271
  let reading = l.reading;
239
272
  let ownWords = false;
240
273
  if (l.shape === 'money' || l.shape === 'time') {
241
274
  // the person's words win (hamr 2026-11-13): code's reading of the `~` words beats the look's and the AI's; theirs is used only when code cannot read the words
242
275
  const rd = this.wordsReading(l, r.text);
276
+ // fwdloop run walk-m16-flights run-1: "under $150" on a euro fact fell back to the look's reading and checked 150 euros; a bound in another currency than the page fact is never replaced by the look's or the AI's reading
277
+ const lim = !rd && l.shape === 'money' ? readLimit('money', r.text, l) : null;
278
+ if (lim && 'why' in lim && lim.why === WHY_OTHER_CURRENCY) { otherCurrency = true; continue; }
243
279
  if (rd) { reading = rd; ownWords = true; }
244
280
  else if (reading === undefined) {
245
281
  const own = readLimit(l.shape, r.text, l);
@@ -251,6 +287,7 @@ export class CheckBlock {
251
287
  if (reading === undefined || !validReading(l.shape, reading)) continue; // code does not guess a limit; the AI may still propose one
252
288
  const bounds = reading.op === 'between' ? [reading.lo, reading.hi] : [reading.value];
253
289
  const unsaid = bounds.some((b) => !boundInWords(b, said));
290
+ if (unsaid && r.corrected) { r.can = { ok: false, why: REASON.noRule }; return; } // the person's corrected words do not carry the look's bound: never built from the AI's reading, never asked again
254
291
  if (unsaid && !r.agreed && this.asks) { r.can = { ok: false, ask: 'reading', link: l, reading, proposal: `${l.name} ${ruleWords({ shape: l.shape, unit: l.unit, currency: l.currency, rule: reading })}`, why: REASON.waitingReading }; return; }
255
292
  if (unsaid && l.shape === 'time' && reading.op !== 'between') { r.can = { ok: false, why: REASON.oneSidedTime }; return; }
256
293
  r.can = { ok: true, how: 'fact', link: l, reading, aiProposal: unsaid && !ownWords && !r.agreed, ...(ownWords ? { readBy: 'your words' } : {}) };
@@ -267,20 +304,30 @@ export class CheckBlock {
267
304
  r.can = { ok: true, how: 'fact', link: l, reading: undefined };
268
305
  return;
269
306
  }
307
+ if (otherCurrency) { r.can = { ok: false, why: `the amount in your rule is in another currency than the page's prices, so it is not checked.` }; return; }
270
308
  if (r.links?.length && !links.length) { r.can = { ok: false, why: REASON.lookNoWords }; return; }
309
+ // a READING the person corrected in words (applyAnswer `rule`): code tried the new words above; what it cannot prove is Not checked with REASON.noRule, never a second question
310
+ if (r.corrected) { r.can = { ok: false, why: REASON.noRule }; return; }
271
311
  if (r.origin === 'typed' || r.cantAsked) { r.can = { ok: false, why: r.aiReason ?? r.lookWhy ?? REASON.nothingOnPage }; return; }
272
312
  if (r.links?.length) { r.can = { ok: false, why: r.aiReason ?? `the look tied a fact to this rule but gave no limit, and ${ownWhy ? `in your words ${ownWhy}` : 'your own words give none code can read'}, so you judge it at Accept.` }; return; }
273
- r.can = this.asks ? { ok: false, ask: 'cant-check', why: r.lookWhy ?? REASON.cantCheck } : { ok: false, why: r.lookWhy ?? REASON.noRule };
313
+ // hamr 2026-11-15 (option A): a rule no check can prove has only one answer (Drop it), so it is NOT asked: it is Not checked with code's reason at once
314
+ r.can = { ok: false, why: r.lookWhy ?? REASON.noRule };
274
315
  }
275
316
 
276
317
  /** a `~` rule that counts words, bullets, lines or sections: a settled pick builds it; else code proposes the check and asks */
277
318
  matchCountRule(/** @type {Row} */ r) {
278
319
  if (!r.pick && (r.cantAsked || !this.countScope(r.text))) { r.can = { ok: false, why: r.aiReason ?? REASON.noRule }; return; }
279
320
  if (r.pick) { r.can = { ok: true, how: 'pick' }; return; }
321
+ // no obvious asks (hamr 2026-11-14): a rule whose words ARE the check ("exactly 3 list items") is settled as it stands, so a replaced rule never re-asks on a re-draft or a Reuse
322
+ const obvious = obviousCheck(r.text);
323
+ if (obvious) {
324
+ const res = keepOrDrop(r.text, /** @type {any} */ ({ ...obvious }));
325
+ if (res.kept) { r.pick = res.check; r.from = 'pick'; r.can = { ok: true, how: 'pick' }; return; }
326
+ }
280
327
  const proposal = r.pickProposal ?? countCheck(r.text);
281
328
  if (!this.asks) r.can = { ok: false, why: REASON.noRule };
282
329
  else if (proposal) r.can = { ok: false, ask: 'check', proposal, why: REASON.waitingPick };
283
- else r.can = r.origin === 'typed' ? { ok: false, why: REASON.noRule } : { ok: false, ask: 'cant-check', why: REASON.cantCheck };
330
+ else r.can = { ok: false, why: REASON.noRule };
284
331
  }
285
332
 
286
333
  /** a `!` fact or phrase row: its words must be on the page; a version or a date is true only today, so only a place rule's fit may carry it */
@@ -300,11 +347,18 @@ export class CheckBlock {
300
347
  r.can = { ok: true, how: 'place', strips: fits[0] ?? [] };
301
348
  return;
302
349
  }
350
+ // fwdloop run walk-m16-flights run-1: "Rome" was on the page (search box, toggles) but in no result row, so no run could pass it. When the line's look reads result rows (a money fact), a phrase in none of them is refused with the look's own sentence (one owner: pagedry.js + pagedropwords.js)
351
+ // (a look fact already went through the same dry read in pagemap.js, so only the AI's own adds are read here)
352
+ if (r.from === 'agent' && (r.shape ?? 'phrase') === 'phrase') {
353
+ const money = this.lookFacts.filter((/** @type {any} */ f) => f.line === r.line && f.shape === 'money' && (!r.source || !f.source || f.source === r.source));
354
+ if (phraseInNoResult(text, money, provedWords[0])) { r.can = { ok: false, why: dropSentence({ line: r.line, fact: r.name ?? provedWords[0], other: provedWords[0], reason: 'phrase-no-result' }) }; return; }
355
+ }
303
356
  r.can = { ok: true, how: 'bang', word: provedWords[0] };
304
357
  }
305
358
 
306
359
  // 4. code makes every check from the rows; a row it cannot build keeps its place with its plain reason. Returns the close's stages, parts and the row map.
307
360
  build() {
361
+ if (this.repo !== null) return this.buildRepo();
308
362
  /** @type {any[]} */ const stages = [];
309
363
  /** @type {any[]} */ const parts = [];
310
364
  /** @type {{part: number, line: number, rows: string[], origin: string}[]} */ const map = [];
@@ -314,6 +368,15 @@ export class CheckBlock {
314
368
  /** @type {string[][]} */ const lineRows = [];
315
369
  this.buildLine(l, lineParts, lineRows, factLines);
316
370
  if (lineParts.length) stages.push({ name: `line-${l.n}`, kind: 'rubric-step', fromLine: [l.n], params: { step: l.n, parts: lineParts } });
371
+ // the line's `$` floor row says whether its file carries text (a facts-only line has no text check): code's own reading of the parts just built
372
+ // a line that writes text (a stage with no fact part) gets its `$` prose row: Not checked, the person judges what the text says at Accept (one owner; never a check, so hasBuiltCheck skips it)
373
+ const writesText = lineParts.length > 0 && !lineParts.some((p) => p.class === 'fact');
374
+ const prose = this.rowsOn(l.n, 'prose')[0];
375
+ if (writesText) {
376
+ const row = prose ?? this.addRow({ key: `L${l.n}.$prose`, line: l.n, kind: 'prose', by: 'default', from: 'default' });
377
+ row.state = 'not-checked'; row.reason = PROSE_WORDS;
378
+ } else if (prose) { prose.state = 'dropped'; prose.reason = null; }
379
+ for (const f of this.rowsOn(l.n, 'floor')) f.carriesText = lineParts.length > 0 && !(lineParts.some((p) => p.class === 'fact') && !lineParts.some((p) => p.class === 'countable'));
317
380
  lineParts.forEach((p, i) => {
318
381
  for (const k of lineRows[i] ?? []) { const row = this.rows.find((x) => x.key === k); if (row) row.part = { line: l.n, part: i }; }
319
382
  map.push({ part: parts.length, line: l.n, rows: lineRows[i] ?? [], origin: 'code' });
@@ -358,13 +421,12 @@ export class CheckBlock {
358
421
  /** the person's picks of this line: they follow the line's fact part on the card, as they always did (the facts, then the picks, then the defaults) @type {{p: any, key: string}[]} */
359
422
  const pickParts = [];
360
423
  for (const r of this.rowsOn(l.n)) {
361
- if (r.kind === 'floor') continue;
424
+ if (r.kind === 'floor' || r.kind === 'prose') continue;
362
425
  r.part = null;
363
- if (r.parent) continue; // a follow row copies its parent's end state after the line is built
364
426
  if (!r.can?.ok) { r.state = 'not-checked'; r.reason = r.can?.why ?? 'not checked'; continue; }
365
427
  if (r.held) { r.state = 'suggested'; r.reason = r.choice === 'drop' ? REASON.dropped : REASON.suggested; continue; }
366
428
  if (r.can.how === 'pick') {
367
- const p = partOfPick(r.pick, r.text, [r.rule, ...this.followsOf(r).map((/** @type {Row} */ f) => f.rule)]);
429
+ const p = partOfPick(r.pick, r.text, [r.rule]);
368
430
  const reds = rubricStepShapeReds({ step: l.n, parts: [p] }, 'trial');
369
431
  if (reds.length) { r.state = 'not-checked'; r.reason = `the pick is not a legal check: ${reds[0].detail}`; continue; }
370
432
  pickParts.push({ p, key: r.key }); r.state = 'built'; r.reason = null;
@@ -376,7 +438,7 @@ export class CheckBlock {
376
438
  facts.push(...built.fresh);
377
439
  r.factNames = built.names;
378
440
  factRows.push({ r, src: built.src });
379
- if (r.kind === 'rule') rulesCarried.push(r.rule, ...this.followsOf(r).map((/** @type {Row} */ f) => f.rule));
441
+ if (r.kind === 'rule') rulesCarried.push(r.rule);
380
442
  r.state = 'built'; r.reason = null;
381
443
  }
382
444
  if (facts.length) {
@@ -388,18 +450,11 @@ export class CheckBlock {
388
450
  const reds = rubricStepShapeReds({ step: l.n, parts: [part] }, 'trial');
389
451
  if (reds.length) for (const x of [...factRows.map((f) => f.r), ...(countRow ? [countRow] : [])]) { x.state = 'not-checked'; x.reason = `code could not build the line's fact part: ${reds[0]?.detail}`; x.part = null; }
390
452
  else { lineParts.push(part); lineRows.push([...factRows.map((f) => f.r.key), ...(countRow ? [countRow.key] : [])]); factLines.add(l.n); if (countRow) { countRow.state = 'built'; countRow.reason = null; } }
391
- } else if (countRow) { countRow.state = 'not-checked'; countRow.reason = REASON.countNeedsFact; }
453
+ } else if (countRow) { countRow.state = 'not-checked'; countRow.reason = this.rowsOn(l.n).some((x) => x.held && (x.kind === 'fact' || x.kind === 'phrase')) ? REASON.countNeedsSuggested : REASON.countNeedsFact; }
392
454
  for (const { p, key } of pickParts) { lineParts.push(p); lineRows.push([key]); }
393
455
  this.buildDefaults(l, lineParts, lineRows, factLines);
394
- for (const f of this.rowsOn(l.n).filter((x) => x.parent)) {
395
- const par = this.rows.find((x) => x.key === f.parent);
396
- f.state = par?.state ?? 'not-checked'; f.reason = par?.state === 'built' ? null : (par?.reason ?? 'not checked'); f.part = par?.part ?? null;
397
- }
398
456
  }
399
457
 
400
- /** the follow rows of a row (its agreed or carried `~` lines) */
401
- followsOf(/** @type {Row} */ r) { return this.rows.filter((x) => x.parent === r.key); }
402
-
403
458
  /**
404
459
  * The fact(s) a fact-like row builds, checked alone through the bareguard shapes and against the facts already on the line.
405
460
  * @param {Row} r @param {any[]} onLine the facts already built on this line @returns {{fresh: any[], src: string, names: string[]} | {why: string}}
@@ -444,7 +499,7 @@ export class CheckBlock {
444
499
  const cited = this.rowsOn(l.n, 'cited')[0] ?? this.addRow({ key: `L${l.n}.$cited`, line: l.n, kind: 'cited', by: 'default', from: 'default', source: this.labels[0] });
445
500
  const numbers = this.rowsOn(l.n, 'numbers')[0] ?? null;
446
501
  cited.part = null;
447
- if (factLines.has(l.n)) { cited.state = 'not-checked'; cited.reason = REASON.onePerLine; return; }
502
+ if (factLines.has(l.n)) { cited.state = 'not-checked'; cited.reason = REASON.onePerLine; this.buildNote(l, lineParts, lineRows); return; }
448
503
  const only = this.labels.length === 1 ? this.labels[0] : null;
449
504
  if (only) { lineParts.push({ text: defaultCitedText(only), class: 'countable', check: 'cited', source: only }); lineRows.push([cited.key]); cited.state = 'built'; cited.reason = null; }
450
505
  else { cited.state = 'not-checked'; cited.reason = REASON.manyInputs; }
@@ -455,6 +510,167 @@ export class CheckBlock {
455
510
  lineRows.push([nr.key]); nr.state = 'built'; nr.reason = null; nr.part = null;
456
511
  }
457
512
 
513
+ /**
514
+ * The `$` note row of a facts-only line (build 2026-11-14 (b)): the one note question said yes -> a countable nonEmpty text part sits beside the facts (the existing keep-both shape), so the brief
515
+ * is FACTS AND TEXT and text-present is floored; no -> nothing; the call failed -> a Not checked row in plain words. One owner of the row and its part.
516
+ */
517
+ buildNote(/** @type {{n: number}} */ l, /** @type {any[]} */ lineParts, /** @type {string[][]} */ lineRows) {
518
+ const ans = this.notes.get(l.n);
519
+ if (ans !== 'yes' && ans !== 'failed') return;
520
+ const row = this.rowsOn(l.n, 'note')[0] ?? this.addRow({ key: `L${l.n}.$note`, line: l.n, kind: 'note', by: 'default', from: 'default' });
521
+ if (ans === 'failed') { row.state = 'not-checked'; row.reason = `could not ask whether line ${l.n} also wants a note`; row.part = null; return; }
522
+ lineParts.push({ text: defaultNoteText(l.n), class: 'countable', check: 'nonEmpty' });
523
+ lineRows.push([row.key]); row.state = 'built'; row.reason = null;
524
+ }
525
+
526
+ /** the job lines that ended up facts-only (a fact part and no text beside it): the lines the note question is about. Reconciles first. @returns {number[]} */
527
+ factOnlyLines() {
528
+ const c = this.reconcile();
529
+ return c.stages.filter((/** @type {any} */ st) => st.params.parts.some((/** @type {any} */ p) => p.class === 'fact') && !st.params.parts.some((/** @type {any} */ p) => p.class === 'countable')).map((/** @type {any} */ st) => st.params.step);
530
+ }
531
+
532
+ /** the note question's answers, `{line, answer: 'yes'|'no'|'failed'}`; the whole list is reconciled again @param {{line: number, answer: 'yes'|'no'|'failed'}[]} answers */
533
+ setNotes(answers) { for (const a of answers) this.notes.set(a.line, a.answer); this.reconcile(); }
534
+
535
+ // ── a repo job's check TYPE (hamr 2026-11-15: "same flow as rubric, no exceptions; only the TYPE of checks varies") ──────────────────────────────────────────────────────────────────────────
536
+ // The rows are the same rows. A `~` rule is kept (built) only when CODE finds a repo path in the person's own words that the write fence keeps; every other rule is asked about (Agree / Drop it / own
537
+ // words, the same ask the rubric flow uses) or Not checked with a REASON. A `!` row is a work stage the drafter wrote from the catalogue (the check type), droppable like any `!` row, never the last one on a line.
538
+
539
+ /**
540
+ * The person's job lines as they stand now (a try-3 answer replaced or added a `~` rule): a rule whose words changed is the person's own typed words (its old answer is void), a new rule is a new row, a rule that is gone leaves.
541
+ * @param {{n: number, text: string, rules?: string[]}[]} jobLines
542
+ */
543
+ syncJob(jobLines) {
544
+ this.lines = jobLines.map((l) => ({ n: l.n, text: l.text }));
545
+ const keep = new Set();
546
+ for (const l of jobLines) {
547
+ (l.rules ?? []).forEach((t, i) => {
548
+ const key = `L${l.n}.~${i + 1}`;
549
+ keep.add(key);
550
+ const row = this.rows.find((r) => r.key === key);
551
+ if (!row) { this.addRow({ key, line: l.n, kind: 'rule', by: 'you', from: 'rule', origin: 'typed', cantAsked: true, text: t, rule: i + 1 }); return; }
552
+ if (row.text !== t) { row.text = t; row.origin = 'typed'; row.left = false; row.cantAsked = true; }
553
+ });
554
+ }
555
+ this.rows = this.rows.filter((r) => r.kind !== 'rule' || keep.has(r.key));
556
+ }
557
+
558
+ /** the repo listing at the seed, once it is read (the rule rows are judged against it) @param {string[]|null} files */
559
+ setListing(files) { if (this.repo !== null) this.repo.files = Array.isArray(files) ? [...files] : null; }
560
+
561
+ /**
562
+ * The drafter's work stages as `!` rows (a mandatory guard is not one), and a Not checked `!` row for each line the drafter refused: the refusal is only the SIGNAL, the reason is code's (`REASON.noRule`, the one table). Idempotent: the stage rows are made again from `stages`.
563
+ * @param {any[]} stages the declaration's stages, guards included @param {{guardNames?: string[], refused?: any[], guardLines?: any[]}} [o]
564
+ */
565
+ addStages(stages, { guardNames = [], refused = [], guardLines = [] } = {}) {
566
+ this.rows = this.rows.filter((r) => r.kind !== 'stage');
567
+ this.declared = Array.isArray(stages) ? stages : [];
568
+ this.guardCover = new Set((Array.isArray(guardLines) ? guardLines : []).flatMap((/** @type {any} */ g) => (Array.isArray(g?.lines) ? g.lines : [])));
569
+ const guards = new Set(guardNames);
570
+ // a line a live stage or a guard's `guardLines` covers is never refused (the rubric's rule: only a line no check could be built for is refused)
571
+ const covered = new Set([...this.guardCover, ...this.declared.filter((st) => st && !guards.has(st.name) && Array.isArray(st.fromLine)).flatMap((st) => st.fromLine)]);
572
+ for (const l of this.lines) {
573
+ for (const st of this.declared) {
574
+ if (!st || typeof st.name !== 'string' || guards.has(st.name) || !Array.isArray(st.fromLine) || st.fromLine.length === 0 || Math.min(...st.fromLine) !== l.n) continue;
575
+ this.addRow({ key: stageKeyOf(st.name), line: l.n, kind: 'stage', by: 'agent', from: 'agent', stageName: st.name, cover: [...st.fromLine] });
576
+ }
577
+ (Array.isArray(refused) ? refused : []).filter((/** @type {any} */ x) => x && x.line === l.n && !Number.isInteger(x.rule) && typeof x.reason === 'string' && !covered.has(l.n))
578
+ .forEach((/** @type {any} */ x, /** @type {number} */ i) => this.addRow({ key: `L${l.n}.refused.${i + 1}`, line: l.n, kind: 'stage', by: 'agent', from: 'agent', refusal: true, said: REASON.noRule }));
579
+ }
580
+ }
581
+
582
+ /** the repo paths outside the write scope (the pointing call is shown these); empty when there is no listing or no fence @returns {string[]} */
583
+ outsideScope() {
584
+ const files = this.repo?.files;
585
+ const scope = this.repo?.writeScope;
586
+ return Array.isArray(files) && Array.isArray(scope) && scope.length ? files.filter((f) => !this.inScope(f)) : [];
587
+ }
588
+
589
+ /** the folders every file of which lies outside the write scope (a rule may ask such a folder to stay as it is, written `folder/`); the pointing call is shown them beside the files @returns {string[]} */
590
+ outsideFolders() {
591
+ const files = this.repo?.files;
592
+ if (!Array.isArray(files) || this.outsideScope().length === 0) return [];
593
+ const all = new Set();
594
+ for (const f of files) for (let i = f.indexOf('/'); i > 0; i = f.indexOf('/', i + 1)) all.add(f.slice(0, i));
595
+ return [...all].filter((d) => !files.some((f) => f.startsWith(`${d}/`) && this.inScope(f)));
596
+ }
597
+
598
+ /** is this repo file a place the run may change? @param {string} f */
599
+ inScope(f) {
600
+ return (this.repo?.writeScope ?? []).some((s) => { const pre = String(globToPrefix(String(s))).trim().replace(/^\.\//, '').replace(/\/+$/, ''); return pre === '' || pre === '.' || pre === '/' || f === pre || f.startsWith(`${pre}/`); });
601
+ }
602
+
603
+ /** the listing paths (a file, or a folder written `folder/`) a text names as whole tokens @param {string} text @returns {string[]} */
604
+ namedPaths(text) {
605
+ const files = this.repo?.files;
606
+ if (!Array.isArray(files)) return [];
607
+ const said = ` ${String(text).replace(/(^|[\s"'(])\.\//g, '$1')} `;
608
+ const all = new Set(files);
609
+ for (const f of files) for (let i = f.indexOf('/'); i > 0; i = f.indexOf('/', i + 1)) all.add(f.slice(0, i));
610
+ const esc = (/** @type {string} */ t) => t.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
611
+ return [...all].filter((p) => new RegExp(`(?<![\\w./-])${esc(p)}${files.includes(p) ? '(?![\\w-]|\\.\\w)' : '/(?![\\w.-])'}`).test(said));
612
+ }
613
+
614
+ /**
615
+ * Code's proof of a fence pointer: `path` is on the listing, the rule's own words name it (whole token; a folder as `folder/`), and neither it nor any other path those words name holds a place the run may change.
616
+ * @param {string} text the rule's own words @param {string} path @returns {boolean}
617
+ */
618
+ provesFence(text, path) {
619
+ const files = this.repo?.files;
620
+ if (!Array.isArray(files) || this.outsideScope().length === 0) return false;
621
+ const p = String(path).trim().replace(/^\.\//, '').replace(/\/+$/, '');
622
+ const named = this.namedPaths(text);
623
+ if (!named.includes(p)) return false;
624
+ return !named.some((n) => files.some((f) => (f === n || f.startsWith(`${n}/`)) && this.inScope(f)));
625
+ }
626
+
627
+ /** the AI's pointer at a repo `~` rule ({op:'fence', line, rule, path}): judged ALONE; code's proof decides, the AI only points @param {any} e */
628
+ editFence(e) {
629
+ if (this.repo === null) return { refusedBecause: 'a fence pointer is for a repo job' };
630
+ const r = this.ruleRows(e.line).find((x) => x.rule === e.rule);
631
+ if (!r) return { refusedBecause: 'names no ~ rule of this line' };
632
+ const path = typeof e.path === 'string' ? e.path.trim().replace(/^\.\//, '').replace(/\/+$/, '') : '';
633
+ if (!path) return { refusedBecause: 'no path given' };
634
+ if (!(this.repo.files ?? []).some((f) => f === path || f.startsWith(`${path}/`))) return { refusedBecause: `${path} is not on the repo listing` };
635
+ if (!this.provesFence(r.text, path)) return { refusedBecause: `the rule's own words do not name ${path}, or it names a place the run may change` };
636
+ r.pointed = path;
637
+ return { accepted: true, landedKey: r.key };
638
+ }
639
+
640
+ /** a repo `~` rule: kept by the write fence when the AI pointed at a path and code proves it from the person's words; else the same ask the rubric flow uses (the person's Agree / Drop it / own words), Not checked when nobody can be asked @param {Row} r */
641
+ matchRepoRule(r) {
642
+ // the AI points, code proves (never kept without a pointer; own words that replaced the rule are proved again against the same pointer)
643
+ if (typeof r.pointed === 'string' && this.provesFence(r.text, r.pointed)) { r.can = { ok: true, how: 'fence', path: r.pointed }; return; }
644
+ if (r.origin === 'typed' || r.cantAsked) { r.can = { ok: false, why: REASON.nothingOnPage }; return; }
645
+ r.can = { ok: false, why: REASON.noRule };
646
+ }
647
+
648
+ /** a repo job's rows: a rule is built with the path the fence keeps for it or Not checked with its reason; a work stage is built, or dropped when the person dropped it and it is not the last thing on its line */
649
+ buildRepo() {
650
+ for (const r of this.rows) {
651
+ if (r.kind !== 'rule' && r.kind !== 'stage') continue;
652
+ r.part = null;
653
+ if (r.can?.ok) { r.state = 'built'; r.reason = null; if (r.kind === 'rule') r.fence = r.can.path; } else { r.state = 'not-checked'; r.reason = r.can?.why ?? 'not checked'; delete r.fence; }
654
+ }
655
+ for (const r of this.rows) {
656
+ if (r.kind !== 'stage' || r.state !== 'built' || r.choice !== 'drop') continue;
657
+ if (this.dropOk(r)) { r.state = 'dropped'; r.reason = REASON.dropped; } else r.choice = undefined;
658
+ }
659
+ const gone = new Set(this.rows.filter((r) => r.kind === 'stage' && r.state === 'dropped').map((r) => r.stageName));
660
+ this.closeCache = { stages: this.declared.filter((st) => !gone.has(st?.name)), parts: [], map: [] };
661
+ return this.closeCache;
662
+ }
663
+
664
+ /** may this repo work-stage row be dropped? Never the last check on a line it serves (another live stage, a guard's `guardLines` or a line refusal still covers it), and never the last work stage of the job @param {Row} r */
665
+ dropOk(r) {
666
+ const others = this.rows.filter((x) => x !== r && x.kind === 'stage');
667
+ const live = others.filter((x) => !x.refusal && x.state === 'built');
668
+ return live.length > 0 && (r.cover ?? [r.line]).every((/** @type {number} */ n) => this.guardCover.has(n) || live.some((x) => (x.cover ?? []).includes(n)) || others.some((x) => x.refusal && x.line === n));
669
+ }
670
+
671
+ /** a row the person can Drop (and Add back): a `!` fact, phrase or count; in a repo job also a work stage the drafter wrote @param {Row} r */
672
+ droppable(r) { return this.isBang(r) || (this.repo !== null && r.kind === 'stage' && r.refusal !== true); }
673
+
458
674
  // 5. the code-forced questions for rows code cannot settle (a person answers; the CHOICE decides, never the words). Cap 3 is the caller's (MAX_QUESTIONS).
459
675
  ask() {
460
676
  this.open = [];
@@ -467,8 +683,9 @@ export class CheckBlock {
467
683
  hasOpenQuestions() { return this.open.length > 0; }
468
684
  hasPendingDelta() { return this.queue.length > 0; }
469
685
 
470
- // 6. the person's answer: a row edit from the typed CHOICE (agree | drop | rule)
471
- /** @param {string} qKey @param {string} choice @param {string} [text] @returns {{ok: true} | {ok: false, why: string}} */
686
+ // 6. the person's answer: a row edit from the typed CHOICE (agree | drop), buttons only (hamr 2026-11-15: a typed own-words answer is retired; a rule is changed by Revise). ONE rule in, ONE rule out (hamr 2026-11-14):
687
+ // an agreed answer REPLACES the asked rule, same line and same rule number; this list is the one owner (the job text is rebuilt from it, `jobLinesView`).
688
+ /** @param {string} qKey @param {string} choice @param {string} [text] the person's correction (a reading question only) @returns {{ok: true} | {ok: false, why: string}} */
472
689
  applyAnswer(qKey, choice, text) {
473
690
  const q = this.open.find((x) => x.key === qKey);
474
691
  const r = q ? this.rows.find((x) => x.key === q.rowKey) : undefined;
@@ -479,50 +696,46 @@ export class CheckBlock {
479
696
  if (q.ask === 'check') {
480
697
  const res = keepOrDrop(r.text, /** @type {any} */ ({ ...q.proposal }));
481
698
  if (!res.kept) return { ok: false, why: String(res.why) };
482
- r.pick = res.check; r.from = 'pick'; r.agreedText = plainWords(/** @type {any} */ (res.check));
483
- said = r.agreedText;
484
- } else { r.agreed = true; r.agreedText = said; }
485
- // hamr 2026-11-12 (ruling 1): an agreed answer is a `~` rule in plain words, a new line with the SAME rule number a typed rule gets; an edited added line (pairWith) IS that line, so its words are replaced
486
- if (r.pairWith !== undefined) r.text = said;
487
- else {
488
- // F318: agreeing to words the line already holds as a `~` rule adds no second line (the pick cites the rule that is there); a reading always adds its line
489
- const held = q.ask === 'check' ? this.ruleRows(r.line).filter((x) => sameRuleWords(x.text, said)).at(-1) : undefined;
490
- if (held === undefined) this.addRow({ key: `L${r.line}.~${this.ruleRows(r.line).length + 1}`, line: r.line, kind: 'rule', by: 'you', from: 'rule', origin: 'agreed', parent: r.key, text: said, rule: this.ruleRows(r.line).length + 1 });
491
- else if (held !== r) this.follow(r, held);
492
- }
699
+ r.pick = res.check; r.from = 'pick';
700
+ said = plainWords(/** @type {any} */ (res.check));
701
+ } else r.agreed = true;
702
+ r.text = said;
493
703
  return { ok: true };
494
704
  }
495
705
  if (choice === 'drop') { r.left = true; return { ok: true }; }
496
- if (choice === 'rule') {
706
+ // only a READING question takes the person's words (hamr 2026-11-15 ruling): they REPLACE the asked rule (one in, one out) and code proves them as it proves any rule; no second question
707
+ if (choice === 'rule' && q.ask === 'reading') {
497
708
  const said = String(text ?? '').replace(/\s+/g, ' ').trim();
498
709
  if (!said) return { ok: false, why: 'an answer is needed' };
499
- r.cantAsked = true;
500
- const n = this.ruleRows(r.line).length + 1;
501
- this.addRow({ key: `L${r.line}.~${n}`, line: r.line, kind: 'rule', by: 'you', from: 'rule', origin: 'typed', text: said, rule: n });
710
+ r.text = said; r.origin = 'typed'; r.cantAsked = !isCountable(said); r.corrected = true;
502
711
  return { ok: true };
503
712
  }
504
713
  return { ok: false, why: 'not one of the choices' };
505
714
  }
506
715
 
507
- /** the `~` row `partner` is checked by `source` (one check, both rule numbers) */
508
- follow(/** @type {Row} */ source, /** @type {Row} */ partner) { partner.parent = source.key; partner.origin = 'agreed'; }
716
+ /**
717
+ * The job lines as the list now holds them: every line's `~` rules are the rule rows' own words, in rule order (a replaced rule keeps its place and number). ONE owner of the job text after an answer.
718
+ * @template {{n: number, text: string}} L @param {L[]} jobLines @returns {(L & {rule: string, rules: string[]})[]}
719
+ */
720
+ jobLinesView(jobLines) {
721
+ return jobLines.map((l) => {
722
+ const rules = this.ruleRows(l.n).sort((a, b) => a.rule - b.rule).map((r) => String(r.text));
723
+ return { ...l, rule: rules.join('; '), rules };
724
+ });
725
+ }
509
726
 
510
727
  /**
511
- * Revise keeps the picks of the last draft (am17/am18/am21, `src/pickrecord.js` `matchRecord`): a kept pick settles its rule and its added `~` line follows it; a kept left rule is
512
- * left; an edited added line (`pairRule`) is the row asked and its source follows it.
513
- * @param {{picks?: {line: number, rule: number, check: any, added?: string, own?: boolean}[], left?: {line: number, rule: number}[]}} kept
514
- * @param {{line: number, rule: number, pairRule?: number}[]} [asked] the rules still asked (a `pairRule` marks an edited added line)
728
+ * Revise keeps the picks of the last draft (am17/am18, `src/pickrecord.js` `matchRecord`): a kept pick settles its rule (its words are the final rule's words) and a kept left rule is left.
729
+ * @param {{picks?: {line: number, rule: number, check: any, own?: boolean}[], left?: {line: number, rule: number}[]}} kept
515
730
  */
516
- carry({ picks = [], left = [] }, asked = []) {
731
+ carry({ picks = [], left = [] }) {
517
732
  const rowOf = (/** @type {number} */ line, /** @type {number} */ rule) => this.ruleRows(line).find((x) => x.rule === rule);
518
733
  for (const p of picks) {
519
734
  const r = rowOf(p.line, p.rule);
520
735
  if (!r) continue;
521
- if (p.check) { r.pick = p.check; r.from = 'pick'; r.keptFromLast = true; r.agreedText = plainWords(p.check); } else { r.cantAsked = true; r.keptFromLast = true; }
522
- if (typeof p.added === 'string') { const add = this.ruleRows(p.line).filter((x) => x !== r && !x.parent && sameRuleWords(x.text, String(p.added))).at(-1); if (add) this.follow(r, add); }
736
+ if (p.check) { r.pick = p.check; r.from = 'pick'; r.keptFromLast = true; } else { r.cantAsked = !isCountable(r.text); r.keptFromLast = true; }
523
737
  }
524
738
  for (const l of left) { const r = rowOf(l.line, l.rule); if (r) { r.left = true; r.keptFromLast = true; } }
525
- for (const a of asked) if (a.pairRule !== undefined) { const r = rowOf(a.line, a.rule); if (r) { r.pairWith = a.pairRule; const src = rowOf(a.line, a.pairRule); if (src && src !== r) this.follow(r, src); } }
526
739
  }
527
740
 
528
741
  // 7. the AI's reply: a list of proposed ROW edits, each judged ALONE; a bad edit is refused on its own and costs the rest nothing
@@ -552,6 +765,7 @@ export class CheckBlock {
552
765
  if (res.accepted) kept.adds += 1;
553
766
  return res;
554
767
  }
768
+ if (e.op === 'fence') return this.editFence(e);
555
769
  if (e.op === 'reading') return this.editReading(e);
556
770
  if (e.op === 'pick') return this.editPick(e);
557
771
  return this.editNot(e);
@@ -655,7 +869,7 @@ export class CheckBlock {
655
869
  // 8. whole-list reconcile, every time
656
870
  reconcile() { this.match(); const c = this.build(); this.ask(); return c; }
657
871
 
658
- /** the loop: while a question is open or a reply waits, apply it and reconcile the WHOLE list again. `answer(q)` gives {choice, text} or null (a person who did not answer) */
872
+ /** the loop: while a question is open or a reply waits, apply it and reconcile the WHOLE list again. `answer(q)` gives {choice, text?} or null (a person who did not answer) */
659
873
  drive({ answer }) {
660
874
  this.unanswered = [];
661
875
  this.reconcile();
@@ -684,7 +898,7 @@ export class CheckBlock {
684
898
  */
685
899
  closeView() {
686
900
  const c = this.reconcile();
687
- return { stages: c.stages, picks: this.picksOf(c), list: this.signedRows() };
901
+ return { stages: c.stages, picks: this.picksOf(c), list: this.signedRows(), ...(this.fence ? { fence: [...this.fence] } : {}) };
688
902
  }
689
903
 
690
904
  /** the picks code records: a countable part carrying the `~` rule numbers it settles @param {{parts: any[], map: {part: number, line: number}[]}} c the build @returns {{line: number, part: any}[]} */
@@ -700,11 +914,12 @@ export class CheckBlock {
700
914
  * `dropped` with code's reason (it is on the Audit, never on the card), and a built row carries the names of the facts it made (`facts`), so every reader can tag each fact by its row's kind.
701
915
  */
702
916
  signedRows() {
703
- return this.rows.map((r) => {
917
+ const rows = (this.repo !== null ? [...this.rows].sort((a, b) => a.line - b.line) : this.rows).map((r) => {
704
918
  const gone = r.state === 'suggested' || r.hidden === true;
705
919
  const row = { ...r, ...(gone ? { state: 'dropped' } : {}), ...(r.state === 'built' && r.factNames?.length ? { facts: r.factNames } : {}) };
706
920
  return Object.fromEntries(SIGNED_ROW_FIELDS.filter((f) => row[f] !== undefined && row[f] !== null).map((f) => [f, row[f]]));
707
921
  });
922
+ return [...rows, ...this.guards.map((name) => ({ line: 0, key: guardKeyOf(name), from: 'default', by: 'default', kind: 'guard', state: 'built' })), ...(this.fence ? [{ line: 0, key: FENCE_KEY, from: 'default', by: 'default', kind: 'fence', state: 'built' }] : [])];
708
923
  }
709
924
 
710
925
  /** the suggestions code has proved it can build, as the card offers them (Add): `{key, line, text}` */
@@ -727,8 +942,17 @@ export class CheckBlock {
727
942
  const r = this.rows.find((x) => x.key === key);
728
943
  if (!r) return { ok: false, why: 'there is no such check on the list' };
729
944
  if (r.by === 'you') return { ok: false, why: 'that check comes from a rule you wrote; edit the job to change it' };
730
- if (r.by !== 'agent' || !this.isBang(r)) return { ok: false, why: 'that check is code\'s own and stays' };
945
+ if (r.by !== 'agent' || !this.droppable(r)) return { ok: false, why: 'that check is code\'s own and stays' };
731
946
  if (choice !== 'drop' && choice !== 'add') return { ok: false, why: 'not one of the choices' };
947
+ if (r.kind === 'stage') {
948
+ // a repo work stage: Drop takes it out of the close (never the last check on its line), Add puts it back
949
+ if (choice === 'drop' && r.state !== 'built') return { ok: false, why: 'only a check that is on the card can be dropped' };
950
+ if (choice === 'add' && r.state !== 'dropped') return { ok: false, why: 'only a dropped check can be added back' };
951
+ if (choice === 'drop' && !this.dropOk(r)) return { ok: false, why: `Dropping that check would leave line ${r.line} with no check, so it stays.` };
952
+ r.choice = choice === 'drop' ? 'drop' : undefined;
953
+ this.reconcile();
954
+ return { ok: true };
955
+ }
732
956
  if (choice === 'drop' && r.state !== 'built') return { ok: false, why: 'only a check that is on the card can be dropped' };
733
957
  if (choice === 'add' && r.state !== 'suggested') return { ok: false, why: 'only a suggested check can be added' };
734
958
  const before = r.choice;
@@ -740,9 +964,7 @@ export class CheckBlock {
740
964
 
741
965
  /** the person's Drop/Add choices, tied to the line's words (not its number) and the row's own name, so a Revise keeps them @returns {{lineWords: string, occurrence: number, tail: string, choice: string}[]} */
742
966
  choicesRecord() {
743
- const seen = new Map();
744
- const key = new Map(this.lines.map((l) => { const w = norm(l.text); const o = seen.get(w) ?? 0; seen.set(w, o + 1); return [l.n, { lineWords: w, occurrence: o }]; }));
745
- return this.rows.filter((r) => r.choice === 'drop' || r.choice === 'add').map((r) => ({ ...(key.get(r.line) ?? { lineWords: '', occurrence: 0 }), tail: r.key.replace(/^L\d+\./, ''), choice: String(r.choice) }));
967
+ return choiceEntries(this.lines, this.rows.filter((r) => r.choice === 'drop' || r.choice === 'add').map((r) => ({ line: r.line, key: r.key, choice: String(r.choice) })));
746
968
  }
747
969
 
748
970
  /** a Revise keeps the last draft's Drop/Add choices on the rows that are still there (same line words, same row); code still judges every one @param {{lineWords: string, occurrence: number, tail: string, choice: string}[]} rec */
@@ -752,7 +974,7 @@ export class CheckBlock {
752
974
  for (const c of Array.isArray(rec) ? rec : []) {
753
975
  if (!c || (c.choice !== 'drop' && c.choice !== 'add')) continue;
754
976
  const line = lines.find((l) => l.w === c.lineWords && l.o === c.occurrence);
755
- const r = line ? this.rows.find((x) => x.line === line.n && this.isBang(x) && x.key.replace(/^L\d+\./, '') === c.tail) : undefined;
977
+ const r = line ? this.rows.find((x) => x.line === line.n && this.droppable(x) && x.key.replace(/^L\d+\./, '') === c.tail) : undefined;
756
978
  if (r) { r.choice = c.choice; r.keptFromLast = true; }
757
979
  }
758
980
  }