bareloop 0.57.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.
- package/CHANGELOG.md +45 -0
- package/bareloop.context.md +11 -8
- package/package.json +1 -1
- package/src/authorflow.js +50 -62
- package/src/authorjob.js +100 -30
- package/src/authorreadout.js +88 -0
- package/src/authorrun.js +63 -24
- package/src/authorscout.js +9 -1
- package/src/blockasks.js +11 -16
- package/src/checkblock.js +227 -31
- package/src/checkpick.js +0 -5
- package/src/declaredclose.js +38 -6
- package/src/draftspend.js +20 -4
- package/src/fencepointcall.js +76 -0
- package/src/guarddescriptions.js +14 -0
- package/src/kinds.js +5 -1
- package/src/pagemap.js +7 -29
- package/src/panel/authorroutes.js +6 -1
- package/src/panel/authorsession.js +108 -32
- package/src/panel/index.html +38 -13
- package/src/panel/jobplan.js +49 -16
- package/src/panel/server.js +66 -6
- package/src/planrun.js +2 -0
- package/src/promptregisters.js +5 -0
- package/src/questionbox.js +32 -20
- package/src/reviewdoor.js +1 -1
- package/src/rowresults.js +69 -0
- package/src/rubricstep.js +110 -22
- package/src/stagewords.js +24 -0
- package/types/authorflow.d.ts +42 -79
- package/types/authorjob.d.ts +3 -2
- package/types/authorreadout.d.ts +44 -0
- package/types/authorrun.d.ts +20 -0
- package/types/blockasks.d.ts +5 -10
- package/types/checkblock.d.ts +115 -11
- package/types/checkpick.d.ts +0 -3
- package/types/declaredclose.d.ts +3 -1
- package/types/draftspend.d.ts +16 -2
- package/types/fencepointcall.d.ts +68 -0
- package/types/guarddescriptions.d.ts +7 -0
- package/types/kinds.d.ts +1 -0
- package/types/pagemap.d.ts +2 -5
- package/types/panel/authorsession.d.ts +3 -2
- package/types/panel/jobplan.d.ts +13 -1
- package/types/panel/server.d.ts +41 -16
- package/types/questionbox.d.ts +20 -6
- package/types/rowresults.d.ts +23 -0
- package/types/rubricstep.d.ts +34 -7
- package/types/stagewords.d.ts +11 -0
package/src/checkblock.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
// THE CHECK BLOCK of a
|
|
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.
|
|
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
11
|
import { isCountable, keepOrDrop, countCheck, obviousCheck, partOfPick, plainWords, sameRuleWords } from './checkpick.js';
|
|
9
12
|
import { dropRows, dropSentence } from './pagedropwords.js';
|
|
10
13
|
import { phraseInNoResult } from './pagedry.js';
|
|
11
|
-
import { boundInWords, rubricStepShapeReds, defaultCitedText, defaultNoteText, readLimit, holdsManyBounds, NEGATING_RE, WHY_OTHER_CURRENCY } from './rubricstep.js';
|
|
14
|
+
import { boundInWords, rubricStepShapeReds, floorWords, stageKeyOf, guardKeyOf, FENCE_KEY, PROSE_WORDS, defaultCitedText, defaultNoteText, readLimit, holdsManyBounds, NEGATING_RE, WHY_OTHER_CURRENCY } from './rubricstep.js';
|
|
12
15
|
import { validReading } from './pagerules.js';
|
|
13
16
|
import { weekOnly, weekTokens, WEEK_ONLY_WORDS, MAX_BANG } from './checklist.js';
|
|
14
17
|
import { fitPlacePhrase } from './placerule.js';
|
|
@@ -26,7 +29,7 @@ import { factSentence, countSentence } from './facts.js';
|
|
|
26
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' });
|
|
27
30
|
|
|
28
31
|
/** the four row edits an AI reply may hold */
|
|
29
|
-
export const EDIT_OPS = Object.freeze(['add', 'reading', 'pick', 'not-checkable']);
|
|
32
|
+
export const EDIT_OPS = Object.freeze(['add', 'reading', 'pick', 'not-checkable', 'fence']);
|
|
30
33
|
|
|
31
34
|
const norm = (/** @type {unknown} */ t) => String(t ?? '').toLowerCase().replace(/\s+/g, ' ').trim();
|
|
32
35
|
const isRec = (/** @type {unknown} */ v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
@@ -40,7 +43,6 @@ const wordSet = (/** @type {unknown} */ t) => new Set(norm(t).match(/[\p{L}\p{N}
|
|
|
40
43
|
export const REASON = Object.freeze({
|
|
41
44
|
left: 'You chose to leave it Not checked, so you judge it at Accept.',
|
|
42
45
|
nothingOnPage: 'Your own words are on the line; the machine has no check for them, so you judge it at Accept.',
|
|
43
|
-
cantCheck: "I can't check this on the page; waiting for your answer",
|
|
44
46
|
noRule: 'No rule can check this, so you judge it at Accept.',
|
|
45
47
|
waitingPick: 'waiting for your answer on the proposed check',
|
|
46
48
|
waitingReading: 'waiting for your answer on the reading',
|
|
@@ -48,6 +50,7 @@ export const REASON = Object.freeze({
|
|
|
48
50
|
manyInputs: 'the job has more than one input and code cannot pick which one the claims quote',
|
|
49
51
|
oneSidedTime: 'a time limit the AI proposes must be a range, so you judge it at Accept.',
|
|
50
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',
|
|
51
54
|
lookNoWords: "the page does not hold the words of the look's fact for this rule",
|
|
52
55
|
afterLast: 'no more tries: Start over (rows are never changed by the AI after the last try)',
|
|
53
56
|
noPick: 'No check was picked for it, so you judge it at Accept.',
|
|
@@ -58,9 +61,11 @@ export const REASON = Object.freeze({
|
|
|
58
61
|
|
|
59
62
|
/** the card lines: rows in, lines out. ONE pure function of the rows; nothing else may feed it. @param {Row[]} rows */
|
|
60
63
|
export function renderCard(rows) {
|
|
61
|
-
return rows.filter((r) => r.
|
|
64
|
+
return rows.filter((r) => r.state !== 'suggested' && r.state !== 'dropped' && !r.hidden).map((r) => {
|
|
62
65
|
let body;
|
|
63
|
-
if (r.kind === '
|
|
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)}` : ''}`;
|
|
64
69
|
else if (r.kind === 'count') body = `${CARD_T.count} ${r.min ?? ''}-${r.max ?? ''}`;
|
|
65
70
|
else if (r.kind === 'cited') body = `${CARD_T.cited} "${r.source ?? CARD_T.theInput}"`;
|
|
66
71
|
else if (r.kind === 'note') body = defaultNoteText(r.line);
|
|
@@ -82,9 +87,25 @@ function placeFacts(name, strips, mk) {
|
|
|
82
87
|
return strips.map((s) => mk(nm(s.kind), { shape: 'phrase', phrase: s.value, place: s.rule }));
|
|
83
88
|
}
|
|
84
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
|
+
|
|
85
100
|
export class CheckBlock {
|
|
86
|
-
/** @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) */
|
|
87
|
-
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();
|
|
88
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) */
|
|
89
110
|
this.split = split;
|
|
90
111
|
this.countScope = countScope;
|
|
@@ -113,8 +134,15 @@ export class CheckBlock {
|
|
|
113
134
|
this.closeCache = null;
|
|
114
135
|
/** @type {Map<number, 'yes'|'no'|'failed'>} the note question's answer per facts-only line (src/noteask.js; code decides what it means) */
|
|
115
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;
|
|
116
141
|
}
|
|
117
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
|
+
|
|
118
146
|
textOf(/** @type {string|undefined} */ source) { return this.texts[source ?? this.labels[0] ?? ''] ?? Object.values(this.texts)[0] ?? ''; }
|
|
119
147
|
/** @param {number} line @param {string} [kind] */
|
|
120
148
|
rowsOn(line, kind) { return this.rows.filter((r) => r.line === line && (kind === undefined || r.kind === kind)); }
|
|
@@ -137,7 +165,7 @@ export class CheckBlock {
|
|
|
137
165
|
for (const l of jobLines) {
|
|
138
166
|
this.lines.push({ n: l.n, text: l.text });
|
|
139
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 }));
|
|
140
|
-
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)" });
|
|
141
169
|
}
|
|
142
170
|
}
|
|
143
171
|
|
|
@@ -159,7 +187,10 @@ export class CheckBlock {
|
|
|
159
187
|
this.lookFacts.push(f);
|
|
160
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
|
|
161
189
|
const tied = Number.isInteger(f.forRule) ? this.ruleRows(f.line).find((r) => r.rule === f.forRule) : undefined;
|
|
162
|
-
|
|
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;
|
|
163
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 };
|
|
164
195
|
if (row) { (row.links ??= []).push({ ...carried, reading: f.reading }); continue; }
|
|
165
196
|
this.addRow({ key: `L${f.line}.fact.${norm(f.name)}`, line: f.line, kind: 'fact', by: 'agent', from: 'look', ...carried });
|
|
@@ -176,6 +207,7 @@ export class CheckBlock {
|
|
|
176
207
|
if (r.kind === 'floor') continue;
|
|
177
208
|
if (r.left) r.can = { ok: false, why: REASON.left };
|
|
178
209
|
else if (r.lookWhy && r.kind === 'fact' && !r.words.length) r.can = { ok: false, why: r.lookWhy };
|
|
210
|
+
else if (r.kind === 'stage') r.can = r.refusal ? { ok: false, why: r.said } : { ok: true, how: 'stage' };
|
|
179
211
|
else if (r.kind === 'rule') this.matchRule(r);
|
|
180
212
|
else if (r.kind === 'fact' || r.kind === 'phrase') this.matchBang(r);
|
|
181
213
|
else if (r.kind === 'count') this.matchCount(r);
|
|
@@ -212,8 +244,9 @@ export class CheckBlock {
|
|
|
212
244
|
inJob(/** @type {Row} */ r) {
|
|
213
245
|
const said = this.said(r.line);
|
|
214
246
|
if (r.kind === 'count') return [r.min, r.max].filter((x) => Number.isInteger(x)).some((n) => new RegExp(`(?<![\\d.])${n}(?![\\d.])`).test(said));
|
|
215
|
-
// 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
|
|
216
|
-
|
|
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));
|
|
217
250
|
}
|
|
218
251
|
|
|
219
252
|
/** a `!` count row is built unless a `~` rule on its line already names the number */
|
|
@@ -224,6 +257,7 @@ export class CheckBlock {
|
|
|
224
257
|
}
|
|
225
258
|
|
|
226
259
|
matchRule(/** @type {Row} */ r) {
|
|
260
|
+
if (this.repo !== null) { this.matchRepoRule(r); return; }
|
|
227
261
|
if (isCountable(r.text)) { this.matchCountRule(r); return; }
|
|
228
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.
|
|
229
263
|
const negated = NEGATING_RE.test(r.text);
|
|
@@ -253,6 +287,7 @@ export class CheckBlock {
|
|
|
253
287
|
if (reading === undefined || !validReading(l.shape, reading)) continue; // code does not guess a limit; the AI may still propose one
|
|
254
288
|
const bounds = reading.op === 'between' ? [reading.lo, reading.hi] : [reading.value];
|
|
255
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
|
|
256
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; }
|
|
257
292
|
if (unsaid && l.shape === 'time' && reading.op !== 'between') { r.can = { ok: false, why: REASON.oneSidedTime }; return; }
|
|
258
293
|
r.can = { ok: true, how: 'fact', link: l, reading, aiProposal: unsaid && !ownWords && !r.agreed, ...(ownWords ? { readBy: 'your words' } : {}) };
|
|
@@ -271,9 +306,12 @@ export class CheckBlock {
|
|
|
271
306
|
}
|
|
272
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; }
|
|
273
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; }
|
|
274
311
|
if (r.origin === 'typed' || r.cantAsked) { r.can = { ok: false, why: r.aiReason ?? r.lookWhy ?? REASON.nothingOnPage }; return; }
|
|
275
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; }
|
|
276
|
-
|
|
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 };
|
|
277
315
|
}
|
|
278
316
|
|
|
279
317
|
/** a `~` rule that counts words, bullets, lines or sections: a settled pick builds it; else code proposes the check and asks */
|
|
@@ -289,7 +327,7 @@ export class CheckBlock {
|
|
|
289
327
|
const proposal = r.pickProposal ?? countCheck(r.text);
|
|
290
328
|
if (!this.asks) r.can = { ok: false, why: REASON.noRule };
|
|
291
329
|
else if (proposal) r.can = { ok: false, ask: 'check', proposal, why: REASON.waitingPick };
|
|
292
|
-
else r.can =
|
|
330
|
+
else r.can = { ok: false, why: REASON.noRule };
|
|
293
331
|
}
|
|
294
332
|
|
|
295
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 */
|
|
@@ -320,6 +358,7 @@ export class CheckBlock {
|
|
|
320
358
|
|
|
321
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.
|
|
322
360
|
build() {
|
|
361
|
+
if (this.repo !== null) return this.buildRepo();
|
|
323
362
|
/** @type {any[]} */ const stages = [];
|
|
324
363
|
/** @type {any[]} */ const parts = [];
|
|
325
364
|
/** @type {{part: number, line: number, rows: string[], origin: string}[]} */ const map = [];
|
|
@@ -329,6 +368,15 @@ export class CheckBlock {
|
|
|
329
368
|
/** @type {string[][]} */ const lineRows = [];
|
|
330
369
|
this.buildLine(l, lineParts, lineRows, factLines);
|
|
331
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'));
|
|
332
380
|
lineParts.forEach((p, i) => {
|
|
333
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 }; }
|
|
334
382
|
map.push({ part: parts.length, line: l.n, rows: lineRows[i] ?? [], origin: 'code' });
|
|
@@ -373,7 +421,7 @@ export class CheckBlock {
|
|
|
373
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}[]} */
|
|
374
422
|
const pickParts = [];
|
|
375
423
|
for (const r of this.rowsOn(l.n)) {
|
|
376
|
-
if (r.kind === 'floor') continue;
|
|
424
|
+
if (r.kind === 'floor' || r.kind === 'prose') continue;
|
|
377
425
|
r.part = null;
|
|
378
426
|
if (!r.can?.ok) { r.state = 'not-checked'; r.reason = r.can?.why ?? 'not checked'; continue; }
|
|
379
427
|
if (r.held) { r.state = 'suggested'; r.reason = r.choice === 'drop' ? REASON.dropped : REASON.suggested; continue; }
|
|
@@ -402,7 +450,7 @@ export class CheckBlock {
|
|
|
402
450
|
const reds = rubricStepShapeReds({ step: l.n, parts: [part] }, 'trial');
|
|
403
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; }
|
|
404
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; } }
|
|
405
|
-
} 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; }
|
|
406
454
|
for (const { p, key } of pickParts) { lineParts.push(p); lineRows.push([key]); }
|
|
407
455
|
this.buildDefaults(l, lineParts, lineRows, factLines);
|
|
408
456
|
}
|
|
@@ -484,6 +532,145 @@ export class CheckBlock {
|
|
|
484
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 */
|
|
485
533
|
setNotes(answers) { for (const a of answers) this.notes.set(a.line, a.answer); this.reconcile(); }
|
|
486
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
|
+
|
|
487
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).
|
|
488
675
|
ask() {
|
|
489
676
|
this.open = [];
|
|
@@ -496,9 +683,9 @@ export class CheckBlock {
|
|
|
496
683
|
hasOpenQuestions() { return this.open.length > 0; }
|
|
497
684
|
hasPendingDelta() { return this.queue.length > 0; }
|
|
498
685
|
|
|
499
|
-
// 6. the person's answer: a row edit from the typed CHOICE (agree | drop
|
|
500
|
-
//
|
|
501
|
-
/** @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}} */
|
|
502
689
|
applyAnswer(qKey, choice, text) {
|
|
503
690
|
const q = this.open.find((x) => x.key === qKey);
|
|
504
691
|
const r = q ? this.rows.find((x) => x.key === q.rowKey) : undefined;
|
|
@@ -516,11 +703,11 @@ export class CheckBlock {
|
|
|
516
703
|
return { ok: true };
|
|
517
704
|
}
|
|
518
705
|
if (choice === 'drop') { r.left = true; return { ok: true }; }
|
|
519
|
-
|
|
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') {
|
|
520
708
|
const said = String(text ?? '').replace(/\s+/g, ' ').trim();
|
|
521
709
|
if (!said) return { ok: false, why: 'an answer is needed' };
|
|
522
|
-
|
|
523
|
-
r.text = said; r.origin = 'typed'; r.cantAsked = !isCountable(said);
|
|
710
|
+
r.text = said; r.origin = 'typed'; r.cantAsked = !isCountable(said); r.corrected = true;
|
|
524
711
|
return { ok: true };
|
|
525
712
|
}
|
|
526
713
|
return { ok: false, why: 'not one of the choices' };
|
|
@@ -578,6 +765,7 @@ export class CheckBlock {
|
|
|
578
765
|
if (res.accepted) kept.adds += 1;
|
|
579
766
|
return res;
|
|
580
767
|
}
|
|
768
|
+
if (e.op === 'fence') return this.editFence(e);
|
|
581
769
|
if (e.op === 'reading') return this.editReading(e);
|
|
582
770
|
if (e.op === 'pick') return this.editPick(e);
|
|
583
771
|
return this.editNot(e);
|
|
@@ -681,7 +869,7 @@ export class CheckBlock {
|
|
|
681
869
|
// 8. whole-list reconcile, every time
|
|
682
870
|
reconcile() { this.match(); const c = this.build(); this.ask(); return c; }
|
|
683
871
|
|
|
684
|
-
/** 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) */
|
|
685
873
|
drive({ answer }) {
|
|
686
874
|
this.unanswered = [];
|
|
687
875
|
this.reconcile();
|
|
@@ -710,7 +898,7 @@ export class CheckBlock {
|
|
|
710
898
|
*/
|
|
711
899
|
closeView() {
|
|
712
900
|
const c = this.reconcile();
|
|
713
|
-
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] } : {}) };
|
|
714
902
|
}
|
|
715
903
|
|
|
716
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}[]} */
|
|
@@ -726,11 +914,12 @@ export class CheckBlock {
|
|
|
726
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.
|
|
727
915
|
*/
|
|
728
916
|
signedRows() {
|
|
729
|
-
|
|
917
|
+
const rows = (this.repo !== null ? [...this.rows].sort((a, b) => a.line - b.line) : this.rows).map((r) => {
|
|
730
918
|
const gone = r.state === 'suggested' || r.hidden === true;
|
|
731
919
|
const row = { ...r, ...(gone ? { state: 'dropped' } : {}), ...(r.state === 'built' && r.factNames?.length ? { facts: r.factNames } : {}) };
|
|
732
920
|
return Object.fromEntries(SIGNED_ROW_FIELDS.filter((f) => row[f] !== undefined && row[f] !== null).map((f) => [f, row[f]]));
|
|
733
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' }] : [])];
|
|
734
923
|
}
|
|
735
924
|
|
|
736
925
|
/** the suggestions code has proved it can build, as the card offers them (Add): `{key, line, text}` */
|
|
@@ -753,8 +942,17 @@ export class CheckBlock {
|
|
|
753
942
|
const r = this.rows.find((x) => x.key === key);
|
|
754
943
|
if (!r) return { ok: false, why: 'there is no such check on the list' };
|
|
755
944
|
if (r.by === 'you') return { ok: false, why: 'that check comes from a rule you wrote; edit the job to change it' };
|
|
756
|
-
if (r.by !== 'agent' || !this.
|
|
945
|
+
if (r.by !== 'agent' || !this.droppable(r)) return { ok: false, why: 'that check is code\'s own and stays' };
|
|
757
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
|
+
}
|
|
758
956
|
if (choice === 'drop' && r.state !== 'built') return { ok: false, why: 'only a check that is on the card can be dropped' };
|
|
759
957
|
if (choice === 'add' && r.state !== 'suggested') return { ok: false, why: 'only a suggested check can be added' };
|
|
760
958
|
const before = r.choice;
|
|
@@ -766,9 +964,7 @@ export class CheckBlock {
|
|
|
766
964
|
|
|
767
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}[]} */
|
|
768
966
|
choicesRecord() {
|
|
769
|
-
|
|
770
|
-
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 }]; }));
|
|
771
|
-
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) })));
|
|
772
968
|
}
|
|
773
969
|
|
|
774
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 */
|
|
@@ -778,7 +974,7 @@ export class CheckBlock {
|
|
|
778
974
|
for (const c of Array.isArray(rec) ? rec : []) {
|
|
779
975
|
if (!c || (c.choice !== 'drop' && c.choice !== 'add')) continue;
|
|
780
976
|
const line = lines.find((l) => l.w === c.lineWords && l.o === c.occurrence);
|
|
781
|
-
const r = line ? this.rows.find((x) => x.line === line.n && this.
|
|
977
|
+
const r = line ? this.rows.find((x) => x.line === line.n && this.droppable(x) && x.key.replace(/^L\d+\./, '') === c.tail) : undefined;
|
|
782
978
|
if (r) { r.choice = c.choice; r.keptFromLast = true; }
|
|
783
979
|
}
|
|
784
980
|
}
|
package/src/checkpick.js
CHANGED
|
@@ -291,11 +291,6 @@ export function rowsFromAnswer(scoped, args) {
|
|
|
291
291
|
}
|
|
292
292
|
|
|
293
293
|
// ---- the asks (words are item 4's) -------------------------------------------------------------------------------------------------------
|
|
294
|
-
/** the can't-check ask, as the signed words say it */
|
|
295
|
-
export const CANT_CHECK_WORDS = "I can't check this. Your own words, or Not checked?";
|
|
296
|
-
/** how every answer is told, once (fwd am2 item 2's words) */
|
|
297
|
-
export const HOW_TO_ANSWER = (/** @type {number} */ line, /** @type {boolean} */ agree) => `${agree ? 'Answer "agree" to use it, or type your own words' : 'Type your own words'} (your answer replaces that ~ rule on line ${line}), or answer "drop it" to leave it Not checked.`;
|
|
298
|
-
|
|
299
294
|
/** a part of a rubric-step stage, from a pick: the check's own fields, the rule's words, and the `~` rule numbers it carries out @param {Record<string, any>} check @param {string} text @param {number[]} rules */
|
|
300
295
|
export function partOfPick(check, text, rules) {
|
|
301
296
|
const { rule, ...fields } = check;
|
package/src/declaredclose.js
CHANGED
|
@@ -69,6 +69,7 @@
|
|
|
69
69
|
// a leaked worktree outlives the process that made it.
|
|
70
70
|
|
|
71
71
|
import { runStage, makeSeedTrees, STOP_FAULTS, EXIT_RED } from './kinds.js';
|
|
72
|
+
import { guardKeyOf } from './rubricstep.js';
|
|
72
73
|
import {
|
|
73
74
|
validateDeclaration, classGuards, genreOwnedEnvNames, ungroundedGenreEnv, DECLARABLE_LANGUAGES, TYPES_GENRE, catalogueForLang, KIND_CATALOGUE, TEXT_GENRE, genreForLang,
|
|
74
75
|
VERDICT_CLASSES, LIVE_CLASSES, NEVER_OFFERED_KINDS,
|
|
@@ -99,15 +100,15 @@ export const DECLARED_GENRES = Object.freeze([TYPES_GENRE.name, TEXT_GENRE]);
|
|
|
99
100
|
* constrained to the names the genre OWNS, so it can never become an environment
|
|
100
101
|
* channel of its own.
|
|
101
102
|
*/
|
|
102
|
-
export const CLOSE_DECL_FIELDS = Object.freeze(['genre', 'lang', 'stages', 'notes', 'refused', 'guardLines', 'picks', 'list', 'genreEnv']);
|
|
103
|
+
export const CLOSE_DECL_FIELDS = Object.freeze(['genre', 'lang', 'stages', 'notes', 'refused', 'guardLines', 'fenceKept', 'picks', 'list', 'genreEnv']);
|
|
103
104
|
|
|
104
105
|
/** the fields of a row of the one check list that the signed close carries (`closeDecl.list`); the row's own words are never signed */
|
|
105
|
-
export const SIGNED_ROW_FIELDS = Object.freeze(['line', 'key', 'from', 'by', 'kind', 'state', 'rule', 'part', 'reason', 'facts']);
|
|
106
|
+
export const SIGNED_ROW_FIELDS = Object.freeze(['line', 'key', 'from', 'by', 'kind', 'state', 'rule', 'part', 'reason', 'facts', 'fence']);
|
|
106
107
|
/** the states a signed row may end in */
|
|
107
108
|
export const SIGNED_STATES = Object.freeze(['built', 'not-checked', 'dropped']);
|
|
108
109
|
const SIGNED_FROM = Object.freeze(['rule', 'pick', 'look', 'agent', 'default']);
|
|
109
110
|
const SIGNED_BY = Object.freeze(['you', 'agent', 'default']);
|
|
110
|
-
const SIGNED_KINDS = Object.freeze(['rule', 'fact', 'cited', 'count', 'phrase', 'numbers', 'note', 'floor']);
|
|
111
|
+
const SIGNED_KINDS = Object.freeze(['rule', 'fact', 'cited', 'count', 'phrase', 'numbers', 'note', 'floor', 'guard', 'prose', 'fence', 'stage']);
|
|
111
112
|
|
|
112
113
|
/**
|
|
113
114
|
* The prefix M1 puts on EVERY gap line of a declared stage (its `ctx.gapKeep`).
|
|
@@ -313,7 +314,9 @@ export function validateCloseDecl(closeDecl, opts = {}) {
|
|
|
313
314
|
const w = `${at}.list[${i}]`;
|
|
314
315
|
if (!isObj(row)) { red('invalid-value', w, 'a row: { line, key, from, by, kind, state, rule?, part?, reason? }'); return; }
|
|
315
316
|
for (const k of Object.keys(row)) if (!SIGNED_ROW_FIELDS.includes(k)) red('unknown-field', `${w}.${k}`, `not a signed row field (the row's own words are never signed); fields: ${SIGNED_ROW_FIELDS.join(', ')}`);
|
|
316
|
-
|
|
317
|
+
// a `guard` or `fence` row is the job's (line 0, once for the whole job); every other row names its job line
|
|
318
|
+
const jobWide = row.kind === 'guard' || row.kind === 'fence';
|
|
319
|
+
if (!Number.isInteger(row.line) || row.line < (jobWide ? 0 : 1) || (jobWide && row.line !== 0)) red('invalid-value', `${w}.line`, jobWide ? 'a guard or fence row belongs to the whole job: line 0' : 'the job line number');
|
|
317
320
|
if (!isNonEmptyString(row.key)) red('invalid-value', `${w}.key`, 'the row key, a non-empty string');
|
|
318
321
|
if (!SIGNED_FROM.includes(row.from)) red('invalid-value', `${w}.from`, `menu: ${SIGNED_FROM.join('|')}`);
|
|
319
322
|
if (!SIGNED_BY.includes(row.by)) red('invalid-value', `${w}.by`, `menu: ${SIGNED_BY.join('|')}`);
|
|
@@ -322,10 +325,17 @@ export function validateCloseDecl(closeDecl, opts = {}) {
|
|
|
322
325
|
if (row.rule !== undefined && !Number.isInteger(row.rule)) red('invalid-value', `${w}.rule`, 'the ~ rule number');
|
|
323
326
|
if (row.part !== undefined && !(isObj(row.part) && Number.isInteger(row.part.line) && Number.isInteger(row.part.part))) red('invalid-value', `${w}.part`, '{ line, part }: the job line and the index of the part that carries the row');
|
|
324
327
|
if (row.reason !== undefined && typeof row.reason !== 'string') red('invalid-value', `${w}.reason`, 'plain words');
|
|
328
|
+
if (row.fence !== undefined && !isNonEmptyString(row.fence)) red('invalid-value', `${w}.fence`, 'the path the write fence keeps, a non-empty string (a repo job\'s ~ rule row the fence keeps)');
|
|
325
329
|
if (row.facts !== undefined && !(Array.isArray(row.facts) && row.facts.every((/** @type {unknown} */ x) => typeof x === 'string'))) red('invalid-value', `${w}.facts`, 'the names of the facts the row built, an array of strings');
|
|
326
330
|
});
|
|
327
331
|
}
|
|
328
332
|
}
|
|
333
|
+
// an OLD signed repo spec may carry the drafter's fence claim (`fenceKept`, unreleased dev sessions): it still loads and Reuses; only its SHAPE is read, nothing reads its words, and a new draft never writes it
|
|
334
|
+
if (closeDecl.fenceKept !== undefined) {
|
|
335
|
+
if (!Array.isArray(closeDecl.fenceKept) || !closeDecl.fenceKept.every((/** @type {any} */ c) => isObj(c) && Number.isInteger(c.line) && c.line >= 1 && Number.isInteger(c.rule) && c.rule >= 1 && isNonEmptyString(c.path))) {
|
|
336
|
+
red('invalid-value', `${at}.fenceKept`, '{line, rule, path} entries (an older signed spec\'s fence claim)');
|
|
337
|
+
}
|
|
338
|
+
}
|
|
329
339
|
// PART 1a: a genre is bound to its language — code languages are TYPES, the rubric-files language is TEXT, and neither may
|
|
330
340
|
// wear the other's label (`lang` is checked just below; an unknown lang reds there)
|
|
331
341
|
if (!DECLARED_GENRES.includes(closeDecl.genre) || closeDecl.genre !== genreForLang(closeDecl.lang)) {
|
|
@@ -528,13 +538,14 @@ function translate(r, redact) {
|
|
|
528
538
|
* @param {{timeoutMs?: number, cwd?: string, seedRef?: string,
|
|
529
539
|
* seedTrees?: any, gapCap?: number, maxBuffer?: number, baselineMode?: 'auto'|'worktree',
|
|
530
540
|
* humanRuling?: {decision: string, text?: string|null}|null,
|
|
531
|
-
* onRubricEvidence?: ((e: any) => void)|null}} [opts]
|
|
541
|
+
* onRubricEvidence?: ((e: any) => void)|null, list?: any[]|null}} [opts]
|
|
542
|
+
* `list` = the signed one check list (`closeDecl.list`): given, each stage entry records a RESULT PER ROW (`rows`, plus `unclaimed` words for a gap no row owns), report-only (Addendum 2026-11-14 (c) piece 4)
|
|
532
543
|
* @returns {Promise<any>}
|
|
533
544
|
*/
|
|
534
545
|
export async function runDeclaredStages(stages, redact = (s) => s, opts = {}) {
|
|
535
546
|
const {
|
|
536
547
|
timeoutMs, cwd, seedRef, seedTrees: shared, gapCap, maxBuffer, baselineMode, humanRuling = null,
|
|
537
|
-
onRubricEvidence = null,
|
|
548
|
+
onRubricEvidence = null, list = null,
|
|
538
549
|
} = opts;
|
|
539
550
|
if (!isNonEmptyString(cwd) || !isNonEmptyString(seedRef)) {
|
|
540
551
|
// Refuse rather than guess. A declared close measures against a SEED; a
|
|
@@ -567,6 +578,7 @@ export async function runDeclaredStages(stages, redact = (s) => s, opts = {}) {
|
|
|
567
578
|
humanRuling,
|
|
568
579
|
// REPORT-ONLY seam: what a rubric-step stage's cited checks read (bareguard `full.evidence`); the runner records it, nothing here reads it
|
|
569
580
|
onRubricEvidence,
|
|
581
|
+
...(Array.isArray(list) ? { list } : {}),
|
|
570
582
|
seedTrees,
|
|
571
583
|
};
|
|
572
584
|
try {
|
|
@@ -591,6 +603,8 @@ export async function runDeclaredStages(stages, redact = (s) => s, opts = {}) {
|
|
|
591
603
|
// an earlier green's announcement would otherwise be lost behind the
|
|
592
604
|
// stage that decided.
|
|
593
605
|
...(t.notes !== undefined ? { notes: t.notes } : {}),
|
|
606
|
+
// a RESULT PER ROW of the signed list (report-only): a rubric step's rows come from its own graded gaps; a guard stage is its own job-level row. Masked at this boundary like every recorded string
|
|
607
|
+
...rowsRecordOf(list, st, r, t, redact),
|
|
594
608
|
});
|
|
595
609
|
last = t;
|
|
596
610
|
if (t.verdict !== 'satisfied') {
|
|
@@ -614,6 +628,24 @@ export async function runDeclaredStages(stages, redact = (s) => s, opts = {}) {
|
|
|
614
628
|
}
|
|
615
629
|
}
|
|
616
630
|
|
|
631
|
+
/**
|
|
632
|
+
* The per-row results one stage entry records (Addendum 2026-11-14 (c) piece 4): `{rows, unclaimed?}` or nothing. A rubric step's come from its detail (the runner graded them against the signed list);
|
|
633
|
+
* a guard stage with a signed `guard` row is that row, passed when the stage was satisfied. The stage's own verdict is never changed by any of this.
|
|
634
|
+
* @param {any[]|null} list @param {any} st the declared stage @param {any} r the stage result @param {any} t its translation @param {(s: string) => string} redact
|
|
635
|
+
* @returns {{rows?: any[], unclaimed?: string[]}}
|
|
636
|
+
*/
|
|
637
|
+
function rowsRecordOf(list, st, r, t, redact) {
|
|
638
|
+
if (!Array.isArray(list)) return {};
|
|
639
|
+
if (st?.kind === 'rubric-step' && Array.isArray(r?.detail?.rows)) {
|
|
640
|
+
return {
|
|
641
|
+
rows: r.detail.rows.map((/** @type {any} */ x) => ({ key: x.key, result: x.result, ...(typeof x.why === 'string' ? { why: redact(x.why) } : {}) })),
|
|
642
|
+
...(Array.isArray(r.detail.unclaimed) && r.detail.unclaimed.length ? { unclaimed: r.detail.unclaimed.map((/** @type {string} */ u) => redact(String(u))) } : {}),
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
const guard = list.find((/** @type {any} */ x) => x && x.kind === 'guard' && x.key === guardKeyOf(String(st?.name)));
|
|
646
|
+
return guard ? { rows: [{ key: guard.key, result: t.verdict === 'satisfied' ? 'passed' : 'failed' }] } : {};
|
|
647
|
+
}
|
|
648
|
+
|
|
617
649
|
/**
|
|
618
650
|
* The ONE number the trend reader may compare, and the omissions are the point.
|
|
619
651
|
* `trend.js` reads improvement as `value < best`, so:
|