fwdloop 0.36.0 → 0.38.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/README.md +6 -20
- package/bin/fwdloop +35 -12
- package/package.json +3 -3
- package/src/action-stop.js +1 -1
- package/src/auditchecks.js +41 -9
- package/src/authoring.js +78 -20
- package/src/blockasks.js +10 -12
- package/src/blockassemble.js +49 -46
- package/src/blockdraft.js +4 -2
- package/src/blockpick.js +10 -0
- package/src/canrun.js +2 -1
- package/src/cardlist.js +28 -5
- package/src/checkblock.js +598 -61
- package/src/checked.js +27 -33
- package/src/checklistsign.js +3 -3
- package/src/checklook.js +45 -0
- package/src/checkrows.js +202 -0
- package/src/cited-record.js +2 -2
- package/src/citedcheck.js +53 -12
- package/src/citedwords.js +7 -4
- package/src/closers.js +49 -2
- package/src/declaration.js +34 -10
- package/src/drafter.js +99 -74
- package/src/factwords.js +7 -4
- package/src/globprefix.js +26 -0
- package/src/isrec.js +2 -0
- package/src/line-checks.js +1 -2
- package/src/minrule.js +16 -0
- package/src/model-step.js +22 -4
- package/src/pageask.js +0 -3
- package/src/pagedropwords.js +3 -11
- package/src/pagedry.js +75 -1
- package/src/pagefetch.js +11 -6
- package/src/pagelook.js +2 -1
- package/src/pagerules.js +8 -2
- package/src/panel/author.js +33 -8
- package/src/panel/data.js +3 -2
- package/src/panel/index.html +177 -37
- package/src/panel/result.js +34 -1
- package/src/pickrecord.js +14 -0
- package/src/planrebuild.js +55 -19
- package/src/ratelimit.js +117 -0
- package/src/report.js +14 -2
- package/src/rowresults.js +111 -0
- package/src/rubricstep.js +65 -2
- package/src/runner.js +38 -5
- package/src/shapebuild.js +281 -0
- package/src/shapelook.js +91 -0
- package/src/shapemenu.js +64 -0
- package/src/shaperesult.js +104 -0
- package/src/shaperows.js +263 -0
- package/src/shapewords.js +140 -0
- package/src/sheet-record.js +1 -2
- package/src/sheetblock.js +1 -2
- package/src/sheetbuild.js +41 -29
- package/src/sheetchecks.js +1 -2
- package/src/sheetclaims.js +1 -2
- package/src/sheetoffer.js +1 -1
- package/src/sheetrows.js +10 -64
- package/src/sheetrun.js +1 -2
- package/src/ticketrows.js +2 -3
- package/src/try-checks.js +39 -6
- package/src/types.js +1 -0
- package/src/whole-job.js +24 -8
- package/types/action-stop.d.ts +1 -1
- package/types/auditchecks.d.ts +13 -2
- package/types/authoring.d.ts +21 -2
- package/types/blockasks.d.ts +6 -10
- package/types/blockassemble.d.ts +12 -13
- package/types/blockdraft.d.ts +3 -2
- package/types/blockpick.d.ts +4 -0
- package/types/cardlist.d.ts +18 -2
- package/types/checkblock.d.ts +276 -27
- package/types/checked.d.ts +15 -6
- package/types/checklook.d.ts +36 -0
- package/types/checkrows.d.ts +119 -0
- package/types/citedcheck.d.ts +4 -2
- package/types/closers.d.ts +10 -1
- package/types/drafter.d.ts +9 -4
- package/types/globprefix.d.ts +5 -0
- package/types/isrec.d.ts +1 -0
- package/types/minrule.d.ts +6 -0
- package/types/model-step.d.ts +43 -2
- package/types/pageask.d.ts +0 -1
- package/types/pagedropwords.d.ts +0 -1
- package/types/pagedry.d.ts +27 -0
- package/types/pagefetch.d.ts +3 -2
- package/types/pagerules.d.ts +4 -0
- package/types/panel/result.d.ts +16 -1
- package/types/pickrecord.d.ts +10 -0
- package/types/ratelimit.d.ts +59 -0
- package/types/report.d.ts +2 -1
- package/types/rowresults.d.ts +28 -0
- package/types/rubricstep.d.ts +21 -0
- package/types/runner.d.ts +3 -1
- package/types/shapebuild.d.ts +97 -0
- package/types/shapelook.d.ts +76 -0
- package/types/shapemenu.d.ts +40 -0
- package/types/shaperesult.d.ts +40 -0
- package/types/shaperows.d.ts +102 -0
- package/types/shapewords.d.ts +43 -0
- package/types/sheetbuild.d.ts +31 -13
- package/types/sheetrows.d.ts +5 -36
- package/types/ticketrows.d.ts +1 -1
- package/types/try-checks.d.ts +2 -1
- package/types/types.d.ts +4 -0
- package/types/whole-job.d.ts +20 -4
package/src/checkblock.js
CHANGED
|
@@ -1,25 +1,38 @@
|
|
|
1
1
|
// borrowed-from: bareloop src/checkblock.js@v0.57.0 (c18df406)
|
|
2
|
+
// borrowed-from: bareloop src/checkblock.js@v0.60.0 (M19 S3: caught up from the earlier port; sheet rows, repo rows, droppable, choiceEntries and lineWordKeys as the tag has them)
|
|
3
|
+
// borrowed-from: bareloop src/checkblock.js@v0.61.0 (fc56e1f3) (M19 S3: the shape rows, setShape and the shape Drops; where a hunk is not taken the line says `fwd keeps`)
|
|
4
|
+
// Where a signed fwd rule stays instead of the tag's line, the line says `fwd keeps` (hamr 2026-11-19: "checks move inside with the same flow we have, don't make unneccessary drift"): the own-words answer to any question (M10 am16), no `$prose` row and no floor row on the card (the card draws neither today), no `corrected` flag, and fwd's own sheet Not-checked words.
|
|
5
|
+
// fwd never sets `repo` (it has no repo job), so the repo rows below are inert here and stay as the tag has them.
|
|
2
6
|
// first ported from: bareloop src/checkblock.js@v0.56.0 (3383cce) + f148028e (M16 am2: an agreed answer's follower row takes its parent's check after the parts are numbered, 4 lines in build())
|
|
3
7
|
// Ported, not copied whole (M16 am3 (1)): the imports point at fwd's files (src/blockpick.js is bareloop's checkpick.js under another name), and the three patterns built from text
|
|
4
8
|
// (the whole-word test in `inText`, the number test in `inJob` and `matchCount`) are written by hand, because src/ builds no pattern from text (test/signed-text.test.js).
|
|
5
|
-
// THE CHECK BLOCK of a
|
|
9
|
+
// 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").
|
|
6
10
|
// 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).
|
|
7
11
|
// 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
|
|
8
12
|
// 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.
|
|
9
13
|
// fromJob -> addLook -> reconcile( match -> build -> ask ), then, while a question is open or a reply waits: apply it and reconcile the WHOLE list again.
|
|
10
|
-
// Pure: no I/O, no clock, no model.
|
|
14
|
+
// 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
|
|
15
|
+
// 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.
|
|
16
|
+
// The same rows store, the same asks, the same Drop/carry, the same signedRows and closeView serve both.
|
|
17
|
+
import { globToPrefix } from './globprefix.js';
|
|
11
18
|
import { countExact, countPhrase } from './pagebits.js';
|
|
12
19
|
import { checkFactWords, keptSetOf } from './factwords.js';
|
|
13
|
-
import { isCountable, keepOrDrop, countCheck, obviousCheck, partOfPick, plainWords
|
|
20
|
+
import { isCountable, keepOrDrop, countCheck, obviousCheck, partOfPick, plainWords } from './blockpick.js';
|
|
14
21
|
import { dropRows, dropSentence } from './pagedropwords.js';
|
|
15
|
-
import { phraseInNoResult } from './pagedry.js';
|
|
16
|
-
import { boundInWords, rubricStepShapeReds, defaultCitedText, defaultNoteText, readLimit, holdsManyBounds, NEGATING_RE, WHY_OTHER_CURRENCY } from './rubricstep.js';
|
|
22
|
+
import { phraseInNoResult, asSeenOf } from './pagedry.js';
|
|
23
|
+
import { boundInWords, rubricStepShapeReds, stageKeyOf, guardKeyOf, FENCE_KEY, defaultCitedText, defaultNoteText, readLimit, holdsManyBounds, NEGATING_RE, WHY_OTHER_CURRENCY } from './rubricstep.js';
|
|
17
24
|
import { validReading } from './pagerules.js';
|
|
18
25
|
import { weekOnly, weekTokens, WEEK_ONLY_WORDS, MAX_BANG } from './checklist.js';
|
|
19
26
|
import { fitPlacePhrase } from './placerule.js';
|
|
20
27
|
import { ruleWords } from './pageask.js';
|
|
21
28
|
import { SIGNED_ROW_FIELDS } from './declaredclose.js';
|
|
22
29
|
import { factSentence, countSentence, factsOfLook } from './citedcheck.js';
|
|
30
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
31
|
+
import { sheetCheckSentence } from './sheetchecks.js';
|
|
32
|
+
import { sheetCheckName, sheetPlainText, coversWords } from './sheetblock.js';
|
|
33
|
+
import { sheetCheckBody, sheetRowKey } from './sheetrows.js';
|
|
34
|
+
import { shapeRowKey, shapeDefaultKey, shapeFieldText, buildShapePart, itemCountOf } from './shaperows.js';
|
|
35
|
+
import { fieldSpec } from './shapebuild.js';
|
|
23
36
|
|
|
24
37
|
/**
|
|
25
38
|
* A row. `kind`: rule, fact, phrase, count, cited, numbers, floor. `by`: you (`~`), agent (`!`), default (`$`). A `~` row may carry `links` (the look's facts tied to it),
|
|
@@ -27,11 +40,10 @@ import { factSentence, countSentence, factsOfLook } from './citedcheck.js';
|
|
|
27
40
|
* @typedef {Record<string, any>} Row
|
|
28
41
|
*/
|
|
29
42
|
|
|
30
|
-
/**
|
|
31
|
-
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' });
|
|
43
|
+
/** what `setSheet` is given: code's build of a job's sheet checks, per sheet line @typedef {Awaited<ReturnType<typeof import('./sheetbuild.js').buildSheetChecks>>} SheetBuilt */
|
|
32
44
|
|
|
33
45
|
/** the four row edits an AI reply may hold */
|
|
34
|
-
export const EDIT_OPS = Object.freeze(['add', 'reading', 'pick', 'not-checkable']);
|
|
46
|
+
export const EDIT_OPS = Object.freeze(['add', 'reading', 'pick', 'not-checkable', 'fence']);
|
|
35
47
|
|
|
36
48
|
const norm = (/** @type {unknown} */ t) => String(t ?? '').toLowerCase().replace(/\s+/g, ' ').trim();
|
|
37
49
|
const isRec = (/** @type {unknown} */ v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
@@ -68,7 +80,6 @@ const wordSet = (/** @type {unknown} */ t) => new Set(norm(t).match(/[\p{L}\p{N}
|
|
|
68
80
|
export const REASON = Object.freeze({
|
|
69
81
|
left: 'You chose to leave it Not checked, so you judge it at Accept.',
|
|
70
82
|
nothingOnPage: 'Your own words are on the line; the machine has no check for them, so you judge it at Accept.',
|
|
71
|
-
cantCheck: "I can't check this on the page; waiting for your answer",
|
|
72
83
|
noRule: 'No rule can check this, so you judge it at Accept.',
|
|
73
84
|
waitingPick: 'waiting for your answer on the proposed check',
|
|
74
85
|
waitingReading: 'waiting for your answer on the reading',
|
|
@@ -76,30 +87,35 @@ export const REASON = Object.freeze({
|
|
|
76
87
|
manyInputs: 'the job has more than one input and code cannot pick which one the claims quote',
|
|
77
88
|
oneSidedTime: 'a time limit the AI proposes must be a range, so you judge it at Accept.',
|
|
78
89
|
countNeedsFact: 'a result count needs a fact to count; this line has none',
|
|
79
|
-
// borrowed-from: bareloop src/checkblock.js@v0.58.0
|
|
80
90
|
countNeedsSuggested: 'a result count needs a fact to count; add the suggested fact on this line to count its results',
|
|
81
91
|
lookNoWords: "the page does not hold the words of the look's fact for this rule",
|
|
82
92
|
afterLast: 'no more tries: Start over (rows are never changed by the AI after the last try)',
|
|
83
93
|
noPick: 'No check was picked for it, so you judge it at Accept.',
|
|
94
|
+
itemCountByRule: 'your rule on this line sets the item count',
|
|
84
95
|
negated: 'it says what is not needed, so there is nothing to check',
|
|
85
96
|
dropped: 'You dropped it.',
|
|
86
97
|
suggested: 'Suggested: not in your job, so it is not checked unless you add it.',
|
|
98
|
+
sheetLine: 'this line reads a sheet and its rules are checked by the sheet checks, so a row edit about it is not used',
|
|
99
|
+
sheetFacts: 'this line reads a sheet, so it is checked by its sheet checks and not by page facts',
|
|
100
|
+
columnRule: "this rule only names a column; the agent's checks on this line use it",
|
|
87
101
|
});
|
|
88
102
|
|
|
89
|
-
/** the card
|
|
103
|
+
/** the card's rows: which rows show, and their key, line, tag, state and reason. NO words: the words of a row are the plan reader's (src/checkrows.js `planCard`), one writer (M19 am6 item 4). @param {Row[]} rows */
|
|
90
104
|
export function renderCard(rows) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (r.kind === 'rule') body = `"${r.text}"${r.pick && !sameRuleWords(r.text, plainWords(r.pick)) ? ` -> ${plainWords(r.pick)}` : ''}`;
|
|
94
|
-
else if (r.kind === 'count') body = `${CARD_T.count} ${r.min ?? ''}-${r.max ?? ''}`;
|
|
95
|
-
else if (r.kind === 'cited') body = `${CARD_T.cited} "${r.source ?? CARD_T.theInput}"`;
|
|
96
|
-
else if (r.kind === 'note') body = defaultNoteText(r.line);
|
|
97
|
-
else if (r.kind === 'numbers') body = `${CARD_T.numbers} ${(r.after ?? []).join(', ')}`;
|
|
98
|
-
else body = `${r.kind} "${r.name ?? r.words?.[0] ?? ''}"${(r.grown ?? r.words)?.length ? ` ${CARD_T.withWords} ${(r.grown ?? r.words).map((/** @type {string} */ w) => `"${w}"`).join(', ')}` : ''}`;
|
|
99
|
-
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}` };
|
|
100
|
-
});
|
|
105
|
+
// fwd keeps: the card draws no floor row (and there is no prose row) today
|
|
106
|
+
return rows.filter((r) => r.kind !== 'floor' && r.state !== 'suggested' && r.state !== 'dropped' && !r.hidden).map((r) => ({ key: r.key, line: r.line, by: r.by, state: r.state, reason: r.reason ?? null }));
|
|
101
107
|
}
|
|
102
108
|
|
|
109
|
+
/**
|
|
110
|
+
* M19 am5: the fields a phrase fact is signed with: several different proved words sign as ONE any-of fact (`anyOf`, a quote holds any one, on word edges); one word signs `phrase`, exactly as before.
|
|
111
|
+
* @param {string[]} words the proved words @param {string} first the word used when there is one or none
|
|
112
|
+
* @returns {{shape: 'phrase', phrase: string} | {shape: 'phrase', anyOf: string[]}}
|
|
113
|
+
*/
|
|
114
|
+
const phraseSigned = (words, first) => {
|
|
115
|
+
const alts = [...new Set(words)];
|
|
116
|
+
return alts.length > 1 ? { shape: 'phrase', anyOf: alts } : { shape: 'phrase', phrase: alts[0] ?? first };
|
|
117
|
+
};
|
|
118
|
+
|
|
103
119
|
/**
|
|
104
120
|
* The facts a place fit builds (hamr 2026-11-11, plain split names): one value keeps the fact's own name; a version AND a date become TWO facts, "<name> version" and "<name> date", each with its
|
|
105
121
|
* own place rule. The words version, date and "and" leave the base name first, so "release version" is not named "release version version".
|
|
@@ -112,11 +128,27 @@ function placeFacts(name, strips, mk) {
|
|
|
112
128
|
return strips.map((s) => mk(nm(s.kind), { shape: 'phrase', phrase: s.value, place: s.rule }));
|
|
113
129
|
}
|
|
114
130
|
|
|
131
|
+
/**
|
|
132
|
+
* 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.
|
|
133
|
+
* @param {{n: number, text: string}[]} lines @param {{line: number, key: string, choice: string}[]} picks @returns {{lineWords: string, occurrence: number, tail: string, choice: string}[]}
|
|
134
|
+
*/
|
|
135
|
+
export function choiceEntries(lines, picks) {
|
|
136
|
+
const seen = new Map();
|
|
137
|
+
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 }]; }));
|
|
138
|
+
return picks.map((p) => ({ ...(key.get(p.line) ?? { lineWords: '', occurrence: 0 }), tail: p.key.replace(/^L\d+\./, ''), choice: String(p.choice) }));
|
|
139
|
+
}
|
|
140
|
+
|
|
115
141
|
export class CheckBlock {
|
|
116
|
-
/** @param {{texts: Record<string, string>, labels: string[], maxTries?: number, countScope?: (ruleText: string) => boolean, asks?: boolean, split?: boolean, cited?: 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) */
|
|
117
|
-
constructor({ texts, labels, maxTries = 3, countScope = () => true, asks = true, split = false, cited = true }) {
|
|
142
|
+
/** @param {{texts: Record<string, string>, labels: string[], maxTries?: number, countScope?: (ruleText: string) => boolean, asks?: boolean, split?: boolean, cited?: 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) */
|
|
143
|
+
constructor({ texts, labels, maxTries = 3, countScope = () => true, asks = true, split = false, cited = true, repo = null }) {
|
|
118
144
|
// M16 am1: `cited: false` = no `$` cited default row on this job's lines (fwd's own quote checks stay as they are); the `$` floor stays
|
|
119
145
|
this.cited = cited;
|
|
146
|
+
/** 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} */
|
|
147
|
+
this.repo = repo;
|
|
148
|
+
/** @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 */
|
|
149
|
+
this.declared = [];
|
|
150
|
+
/** 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>} */
|
|
151
|
+
this.guardCover = new Set();
|
|
120
152
|
/** 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) */
|
|
121
153
|
this.split = split;
|
|
122
154
|
this.countScope = countScope;
|
|
@@ -145,6 +177,166 @@ export class CheckBlock {
|
|
|
145
177
|
this.closeCache = null;
|
|
146
178
|
/** @type {Map<number, 'yes'|'no'|'failed'>} the note question's answer per facts-only line (src/noteask.js; code decides what it means) */
|
|
147
179
|
this.notes = new Map();
|
|
180
|
+
/** @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) */
|
|
181
|
+
this.guards = [];
|
|
182
|
+
/** @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` */
|
|
183
|
+
this.fence = null;
|
|
184
|
+
/** S4: the job lines that read a sheet (a CSV input and a `~` rule): every rule of such a line is decided by the sheet checks alone, never by the page path (`src/sheetrows.js` `sheetLineNumbers`) @type {Set<number>} */
|
|
185
|
+
this.sheetLines = new Set();
|
|
186
|
+
/** S4: what code built from the AI's `sheetChecks` (src/sheetbuild.js `buildSheetChecks`), null until the row-edit turn has answered @type {SheetBuilt|null} */
|
|
187
|
+
this.sheetBuilt = null;
|
|
188
|
+
/** shape jobs (clause 4): what code built from the AI's `itemShape` (src/shapebuild.js `buildShapes`), null until the row-edit turn has answered. A line in `built` is a SHAPE line: a line is exactly one class, facts, sheet or shape @type {ReturnType<typeof import('./shapebuild.js').buildShapes>|null} */
|
|
189
|
+
this.shapeBuilt = null;
|
|
190
|
+
/** shape jobs: the Drops the person made, kept beside the rows (`agent` = `<line>:<field name>`, `rules` = `<line>:<rule number>`) @type {{agent: Set<string>, rules: Set<string>}} */
|
|
191
|
+
this.shapeDrops = { agent: new Set(), rules: new Set() };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** 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 */
|
|
195
|
+
setGuards(names, fence = null) { this.guards = [...new Set(names)]; this.fence = Array.isArray(fence) && fence.length ? [...fence] : null; }
|
|
196
|
+
|
|
197
|
+
/** S4: the job lines that read a sheet. Their rules are decided by the sheet checks alone (no page path, no pick question, no row edit), from here on @param {number[]} nums */
|
|
198
|
+
setSheetLines(nums) { this.sheetLines = new Set(nums); }
|
|
199
|
+
/** @param {number} n */
|
|
200
|
+
isSheetLine(n) { return this.sheetLines.has(n); }
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* S4: the checks code built from the AI's `sheetChecks` become rows of the one list: an `[agent]` row for each check that is no rule row's. A `[you]` row is the `~` rule's own row (its state comes from the sheet,
|
|
204
|
+
* `matchSheetRule`). A Drop the person made on a check is kept for the same check (same typed fields) when the checks are built again; every row is reconciled.
|
|
205
|
+
* fwd keeps: no `[default]` sheet row (the tag adds one per sheet line, bareloop S4); fwd's list has none (M16 am4 (2): "a `[default]` sheet check does not exist").
|
|
206
|
+
* @param {SheetBuilt} built
|
|
207
|
+
*/
|
|
208
|
+
setSheet(built) {
|
|
209
|
+
const dropped = this.rows.filter((r) => r.kind === 'sheet' && r.by === 'agent' && r.choice === 'drop').map((r) => ({ line: r.line, body: sheetCheckBody(r.check) }));
|
|
210
|
+
this.sheetBuilt = built;
|
|
211
|
+
this.rows = this.rows.filter((r) => r.kind !== 'sheet');
|
|
212
|
+
for (const n of this.sheetLines) {
|
|
213
|
+
const b = built.built[n];
|
|
214
|
+
if (!b) continue;
|
|
215
|
+
for (const p of b.agentRows) {
|
|
216
|
+
const row = this.addRow({ key: sheetRowKey(n, p.check.id), line: n, kind: 'sheet', by: 'agent', from: 'agent', check: p.check });
|
|
217
|
+
if (dropped.some((d) => d.line === n && isDeepStrictEqual(d.body, sheetCheckBody(p.check)))) row.choice = 'drop';
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
this.reconcile();
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** shape jobs, rules first: does job line `n` hold a rule that took its shape field (no truth check could take it)? Only such a line carries shape rows and a shape part @param {number} n */
|
|
224
|
+
isShapeLine(n) { return !this.isSheetLine(n) && this.rows.some((r) => r.kind === 'rule' && r.line === n && r.can?.how === 'shape'); }
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Shape jobs, rules first (hamr 2026-11-19): remember the shape code built from the shape look (src/shapebuild.js `buildShapes`). It decides nothing by itself: `matchRule` tries every rule's truth check (fact, cite, count, phrase, pick) FIRST,
|
|
228
|
+
* and a rule that ends with none and no open ask may take its shape field (`takesShape`). A line where no rule did has no shape rows at all (`syncShapeRows`), so a page job's rows stay as they were. A Drop the person made
|
|
229
|
+
* (an `[agent]` field, or a rule's own shape field) is kept for the same field when the shape is built again. Every row is reconciled.
|
|
230
|
+
* @param {ReturnType<typeof import('./shapebuild.js').buildShapes>} built
|
|
231
|
+
*/
|
|
232
|
+
setShape(built) {
|
|
233
|
+
this.keepShapeDrops();
|
|
234
|
+
this.shapeBuilt = built;
|
|
235
|
+
this.reconcile();
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** the Drops the shape rows carry now, remembered beside the rows (a row can leave the list and come back) */
|
|
239
|
+
keepShapeDrops() {
|
|
240
|
+
for (const r of this.rows) {
|
|
241
|
+
if (r.kind === 'shape' && r.by === 'agent' && r.choice === 'drop' && r.field?.name !== undefined) this.shapeDrops.agent.add(`${r.line}:${r.field.name}`);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Rules first: may this rule, which no truth check could take, take the shape field the shape look proposed for it? Its own `[you]` row then carries the field. Null when it may not (no shape, a sheet or repo job, no field for the rule).
|
|
247
|
+
* @param {Row} r @returns {{name: string}|null}
|
|
248
|
+
*/
|
|
249
|
+
takesShape(r) {
|
|
250
|
+
// a rule code marks as negating says what is NOT needed: it stays with the person (NEGATING_RE, the old ruling), never a shape field ("no nonstop" must not become nonstop = false)
|
|
251
|
+
if (this.repo !== null || r.kind !== 'rule' || this.isSheetLine(r.line) || NEGATING_RE.test(String(r.text))) return null;
|
|
252
|
+
const rs = this.shapeBuilt?.built[r.line]?.rows.find((x) => x.rule === r.rule && x.text === r.text);
|
|
253
|
+
return rs && rs.state === 'built' && typeof rs.name === 'string' ? { name: rs.name } : null;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* The rules that are still Not checked once every truth check, the person's answers and the pending asks are settled, and that may still take a shape field (not a sheet or repo job, not left or negating by the person's words):
|
|
258
|
+
* the ONLY rules the shape look is asked about, and only when there is one. Call after `reconcile`.
|
|
259
|
+
* @returns {{line: number, rule: number}[]}
|
|
260
|
+
*/
|
|
261
|
+
shapeCandidates() {
|
|
262
|
+
if (this.repo !== null) return [];
|
|
263
|
+
return this.rows.filter((r) => r.kind === 'rule' && !r.left && (!r.can?.ok || r.truthRefused) && !r.can?.ask && !this.isSheetLine(r.line) && !NEGATING_RE.test(String(r.text))).map((r) => ({ line: r.line, rule: Number(r.rule) }));
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Shape rows live only on a line where a rule took its shape field: its `[agent]` extra fields (job-derived on, no-word Suggested) and its `$` count row are added there, and removed from any line where none did.
|
|
268
|
+
* Called after the rules are matched.
|
|
269
|
+
*/
|
|
270
|
+
syncShapeRows() {
|
|
271
|
+
const built = this.shapeBuilt?.built ?? {};
|
|
272
|
+
for (const [k, b] of Object.entries(built)) {
|
|
273
|
+
const n = Number(k);
|
|
274
|
+
const live = this.isShapeLine(n);
|
|
275
|
+
const have = this.rows.filter((r) => r.kind === 'shape' && r.line === n);
|
|
276
|
+
if (!live) { if (have.length) { this.keepShapeDrops(); this.rows = this.rows.filter((r) => !(r.kind === 'shape' && r.line === n)); } continue; }
|
|
277
|
+
for (const f of b.fields.filter((x) => x.by === 'agent')) {
|
|
278
|
+
if (have.some((r) => r.key === shapeRowKey(n, f.name))) continue;
|
|
279
|
+
const row = this.addRow({ key: shapeRowKey(n, f.name), line: n, kind: 'shape', by: 'agent', from: 'agent', field: f, state: 'not-checked', reason: 'not yet matched' });
|
|
280
|
+
if (this.shapeDrops.agent.has(`${n}:${f.name}`)) row.choice = 'drop';
|
|
281
|
+
}
|
|
282
|
+
if (b.itemCount && !have.some((r) => r.key === shapeDefaultKey(n))) this.addRow({ key: shapeDefaultKey(n), line: n, kind: 'shape', by: 'default', from: 'default', state: 'not-checked', reason: 'not yet matched' });
|
|
283
|
+
}
|
|
284
|
+
// a line the shape look built nothing for keeps no shape rows
|
|
285
|
+
this.rows = this.rows.filter((r) => !(r.kind === 'shape' && built[r.line] === undefined));
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/** the dropped shape fields the record keeps, tied to the line's words (not its number): an `[agent]` field by its name, a rule's own shape field by its rule number @returns {{lineWords: string, occurrence: number, name?: string, rule?: number}[]} */
|
|
289
|
+
shapeDroppedRecord() {
|
|
290
|
+
this.keepShapeDrops();
|
|
291
|
+
const keys = this.lineWordKeys();
|
|
292
|
+
const at = (/** @type {number} */ n) => keys.get(n) ?? { lineWords: '', occurrence: 0 };
|
|
293
|
+
return [
|
|
294
|
+
...[...this.shapeDrops.agent].map((x) => { const i = x.indexOf(':'); return { n: Number(x.slice(0, i)), name: x.slice(i + 1) }; }).filter((d) => this.lines.some((l) => l.n === d.n)).map((d) => ({ ...at(d.n), name: d.name })),
|
|
295
|
+
...[...this.shapeDrops.rules].map((x) => { const [n, rule] = x.split(':').map(Number); return { ...at(n), rule }; }).filter((d) => d.lineWords !== ''),
|
|
296
|
+
];
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/** a Revise keeps a Drop of the very same field (same line words, same name or rule number); a field this draft did not build is not dropped @param {{lineWords: string, occurrence: number, name?: string, rule?: number}[]} rec */
|
|
300
|
+
carryShapeDropped(rec) {
|
|
301
|
+
const keys = this.lineWordKeys();
|
|
302
|
+
for (const d of Array.isArray(rec) ? rec : []) {
|
|
303
|
+
if (!d || typeof d.lineWords !== 'string' || !Number.isInteger(d.occurrence)) continue;
|
|
304
|
+
const n = [...keys].find(([, k]) => k.lineWords === d.lineWords && k.occurrence === d.occurrence)?.[0];
|
|
305
|
+
if (n === undefined) continue;
|
|
306
|
+
if (typeof d.name === 'string') {
|
|
307
|
+
this.shapeDrops.agent.add(`${n}:${d.name}`);
|
|
308
|
+
const row = this.rows.find((r) => r.kind === 'shape' && r.by === 'agent' && r.line === n && r.field?.name === d.name);
|
|
309
|
+
if (row) { row.choice = 'drop'; row.keptFromLast = true; }
|
|
310
|
+
} else if (Number.isInteger(d.rule)) this.shapeDrops.rules.add(`${n}:${d.rule}`);
|
|
311
|
+
}
|
|
312
|
+
this.reconcile();
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* The dropped sheet checks the record keeps, as fwd's picks record has always written them (`{key, line, index, check, text}`, M17 am3): `index` is the check's place among its line's checks, `check` the check as built.
|
|
317
|
+
* fwd keeps this record shape (the tag ties each entry to the line's words instead, `{lineWords, occurrence, check, text}`): the record is a file of the plan folder, and a draft saved before this carries the old shape.
|
|
318
|
+
* @returns {{key: string, line: number, index: number, check: Record<string, any>, text: string}[]}
|
|
319
|
+
*/
|
|
320
|
+
sheetDroppedRecord() {
|
|
321
|
+
return this.rows.filter((r) => r.kind === 'sheet' && r.by === 'agent' && r.choice === 'drop').map((r) => ({
|
|
322
|
+
key: r.key, line: r.line, index: Math.max(0, (this.sheetBuilt?.built[r.line]?.checks ?? []).findIndex((/** @type {any} */ c) => c.id === r.check.id)), check: r.check, text: String(r.offer?.text ?? ''),
|
|
323
|
+
}));
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** a Revise keeps a Drop of the very same check: the record's entries, matched on the line and the check's own fields (never its id: code names every check); a check this draft did not build is not dropped @param {{line: number, check: Record<string, any>}[]} rec */
|
|
327
|
+
carrySheetDropped(rec) {
|
|
328
|
+
for (const d of Array.isArray(rec) ? rec : []) {
|
|
329
|
+
if (!d || !Number.isInteger(d.line) || !isRec(d.check)) continue;
|
|
330
|
+
const row = this.rows.find((r) => r.kind === 'sheet' && r.by === 'agent' && r.line === d.line && isDeepStrictEqual(sheetCheckBody(r.check), sheetCheckBody(d.check)));
|
|
331
|
+
if (row) row.choice = 'drop';
|
|
332
|
+
}
|
|
333
|
+
this.reconcile();
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/** each job line's words and its order among equal lines (the key a record ties a choice to) @returns {Map<number, {lineWords: string, occurrence: number}>} */
|
|
337
|
+
lineWordKeys() {
|
|
338
|
+
const seen = new Map();
|
|
339
|
+
return 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 }]; }));
|
|
148
340
|
}
|
|
149
341
|
|
|
150
342
|
textOf(/** @type {string|undefined} */ source) { return this.texts[source ?? this.labels[0] ?? ''] ?? Object.values(this.texts)[0] ?? ''; }
|
|
@@ -169,7 +361,7 @@ export class CheckBlock {
|
|
|
169
361
|
for (const l of jobLines) {
|
|
170
362
|
this.lines.push({ n: l.n, text: l.text });
|
|
171
363
|
(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 }));
|
|
172
|
-
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)" });
|
|
364
|
+
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)" });
|
|
173
365
|
}
|
|
174
366
|
}
|
|
175
367
|
|
|
@@ -198,6 +390,19 @@ export class CheckBlock {
|
|
|
198
390
|
}
|
|
199
391
|
}
|
|
200
392
|
|
|
393
|
+
/**
|
|
394
|
+
* S1 (the sheet look, src/sheetlook.js): a `~` rule whose word is no column of its CSV carries ONE column question. Agree writes `reading` (the rule's own words with the column in place of the word) as the rule's words,
|
|
395
|
+
* through the same one-rule-in, one-rule-out answer as any reading (`applyAnswer`); no line is added. Code builds the question; nothing here reads a model field.
|
|
396
|
+
* A tie (`columns`, `readings`: the rule's words for each tied column) has no single reading: the person picks a column (`applyAnswer` `column`) and the rule is that column's reading.
|
|
397
|
+
* @param {{line: number, rule: number|null, question: string, reading?: string, columns?: string[], readings?: Record<string, string>}[]} asks
|
|
398
|
+
*/
|
|
399
|
+
addSheetAsks(asks) {
|
|
400
|
+
for (const a of asks) {
|
|
401
|
+
const r = a.rule === null ? undefined : this.ruleRows(a.line).find((x) => x.rule === a.rule);
|
|
402
|
+
if (r) r.sheetAsk = { ruleText: r.text, question: a.question, proposal: a.reading ?? null, ...(Array.isArray(a.columns) ? { columns: [...a.columns], readings: { ...a.readings } } : {}) };
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
201
406
|
// 3. can code check it on the saved page? Never the AI. `row.can` = {ok, how, ...} or {ok:false, why} or {ok:false, ask, ...}
|
|
202
407
|
match() {
|
|
203
408
|
// live draft 3 (hamr 2026-11-13: "anything not in your original job that code can check goes to Suggested"): a `!` fact whose page words are longer than what the job says ("Boston Logan International
|
|
@@ -208,10 +413,13 @@ export class CheckBlock {
|
|
|
208
413
|
if (r.kind === 'floor') continue;
|
|
209
414
|
if (r.left) r.can = { ok: false, why: REASON.left };
|
|
210
415
|
else if (r.lookWhy && r.kind === 'fact' && !r.words.length) r.can = { ok: false, why: r.lookWhy };
|
|
416
|
+
else if (r.kind === 'stage') r.can = r.refusal ? { ok: false, why: r.said } : { ok: true, how: 'stage' };
|
|
211
417
|
else if (r.kind === 'rule') this.matchRule(r);
|
|
212
418
|
else if (r.kind === 'fact' || r.kind === 'phrase') this.matchBang(r);
|
|
213
419
|
else if (r.kind === 'count') this.matchCount(r);
|
|
420
|
+
else if (r.kind === 'sheet') r.can = { ok: true, how: 'sheet' };
|
|
214
421
|
}
|
|
422
|
+
this.takeItemCounts();
|
|
215
423
|
// N-1 (hamr 2026-11-13): code splits the `!` rows. Words (or the count number) in the job line or its ~ rules = JOB-DERIVED (built, Drop). Not in the job = SUGGESTED: held out of the close, offered
|
|
216
424
|
// only when code has already proved it can build it (build() trials it), and switched on by the person's Add. The person's Drop removes a row for good. Never the AI.
|
|
217
425
|
for (const r of this.split ? this.rows : []) {
|
|
@@ -221,6 +429,18 @@ export class CheckBlock {
|
|
|
221
429
|
// a Drop is undone through Suggested (live draft 3): the row was proved buildable, so it is offered again with Add; only a row code can still build is offered
|
|
222
430
|
if (r.can?.ok && r.choice !== 'add' && (!r.derived || r.choice === 'drop')) r.held = true;
|
|
223
431
|
}
|
|
432
|
+
// shape rows live only on a line where a rule took its shape field (rules first): added or removed now that the rules are matched; their own state is set below
|
|
433
|
+
this.syncShapeRows();
|
|
434
|
+
for (const r of this.rows) if (r.kind === 'shape') r.can = { ok: true, how: 'shape' };
|
|
435
|
+
// S4: an `[agent]` sheet row the person dropped is held out of the close and offered again under Suggested (Add); it is code's own check, already built, so no trial is needed
|
|
436
|
+
// shape jobs: an `[agent]` field the person dropped, or one with no word of the job (R2), is held out of the close and offered under Suggested (Add); it is code's own field, already built, so no trial is needed
|
|
437
|
+
for (const r of this.rows) if (r.kind === 'shape' && r.by === 'agent') { r.held = r.choice === 'drop' || (r.field?.held === true && r.choice !== 'add'); r.offer = { text: shapeFieldText({ name: r.field.name, spec: fieldSpec(r.field), rule: null }, []) }; }
|
|
438
|
+
for (const r of this.rows) if (r.kind === 'sheet' && r.by === 'agent') { r.held = r.choice === 'drop'; r.offer = { text: sheetPlainText(sheetCheckName(r.check), sheetCheckSentence(r.check), coversWords(this.coverTexts(r))) }; }
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/** the person's own words of the rules an `[agent]` sheet row shows (its `covers`) @param {Row} r @returns {string[]} */
|
|
442
|
+
coverTexts(r) {
|
|
443
|
+
return (Array.isArray(r.check?.covers) ? r.check.covers : []).map((/** @type {number} */ n) => this.ruleRows(r.line).find((x) => x.rule === n)?.text).filter((/** @type {unknown} */ t) => typeof t === 'string');
|
|
224
444
|
}
|
|
225
445
|
|
|
226
446
|
/** 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) */
|
|
@@ -244,12 +464,26 @@ export class CheckBlock {
|
|
|
244
464
|
inJob(/** @type {Row} */ r) {
|
|
245
465
|
const said = this.said(r.line);
|
|
246
466
|
if (r.kind === 'count') return [r.min, r.max].filter((x) => Number.isInteger(x)).some((n) => numberIn(said, n));
|
|
247
|
-
// 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
|
|
248
|
-
//
|
|
249
|
-
// A phrase or place is job-derived 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")
|
|
467
|
+
// 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
|
|
468
|
+
// 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")
|
|
250
469
|
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));
|
|
251
470
|
}
|
|
252
471
|
|
|
472
|
+
/**
|
|
473
|
+
* M19 am11 item 1: on a line with item fields (a shape line), a `~` rule that counts list items is the shape part's own item count, not a count pick over `text`. Run after every rule is matched, so the order of the rules does not matter.
|
|
474
|
+
* The ONE writer of such a row's `can` and of its `from` (it is the person's rule again, not a pick). A text line, a sheet line and a repo line are unchanged. A Drop of the rule is kept (`shapeDrops.rules`).
|
|
475
|
+
*/
|
|
476
|
+
takeItemCounts() {
|
|
477
|
+
if (this.repo !== null) return;
|
|
478
|
+
for (const r of this.rows) {
|
|
479
|
+
if (r.kind !== 'rule' || r.left || r.can?.how === 'shape' || this.isSheetLine(r.line) || NEGATING_RE.test(String(r.text)) || !this.isShapeLine(r.line)) continue;
|
|
480
|
+
const count = itemCountOf(String(r.text));
|
|
481
|
+
if (count === null) continue;
|
|
482
|
+
r.can = this.shapeDrops.rules.has(`${r.line}:${r.rule}`) ? { ok: false, why: REASON.dropped } : { ok: true, how: 'shape', count };
|
|
483
|
+
if (r.can.ok) r.from = 'rule';
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
253
487
|
/** a `!` count row is built unless a `~` rule on its line already names the number */
|
|
254
488
|
matchCount(/** @type {Row} */ r) {
|
|
255
489
|
const nums = [r.min, r.max].filter((x) => Number.isInteger(x)).map(String);
|
|
@@ -257,7 +491,21 @@ export class CheckBlock {
|
|
|
257
491
|
r.can = said ? { ok: false, why: `a ~ rule already says it: line ${r.line} rule ${said.rule} names the number` } : { ok: true, how: 'count' };
|
|
258
492
|
}
|
|
259
493
|
|
|
260
|
-
|
|
494
|
+
/** RULES FIRST (hamr 2026-11-19): today's truth check for the rule; only a rule that ends with none and no open ask takes the shape field proposed for it (the strongest check wins, no ask) @param {Row} r */
|
|
495
|
+
matchRule(r) {
|
|
496
|
+
this.matchTruthRule(r);
|
|
497
|
+
// a truth check code picked but REFUSED when it built the line (live mwnbs3np: 4 results, a title said once) is no check: the rule is still Not checked, so it may take its shape field (hamr: shape for what code could not check)
|
|
498
|
+
if (r.can?.ask || (r.can?.ok && !r.truthRefused)) return;
|
|
499
|
+
const sh = this.takesShape(r);
|
|
500
|
+
if (sh === null) return;
|
|
501
|
+
r.can = this.shapeDrops.rules.has(`${r.line}:${r.rule}`) ? { ok: false, why: REASON.dropped } : { ok: true, how: 'shape', name: sh.name };
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
matchTruthRule(/** @type {Row} */ r) {
|
|
505
|
+
if (this.repo !== null) { this.matchRepoRule(r); return; }
|
|
506
|
+
// S1: the sheet look's column question, while the rule still says the words it was asked about (an answered, dropped or retyped rule is not asked again)
|
|
507
|
+
if (r.sheetAsk && this.asks && !r.agreed && !r.left && r.text === r.sheetAsk.ruleText) { r.can = { ok: false, ask: 'reading', proposal: r.sheetAsk.proposal, question: r.sheetAsk.question, ...(r.sheetAsk.columns ? { columns: r.sheetAsk.columns, readings: r.sheetAsk.readings } : {}), why: REASON.waitingReading }; return; }
|
|
508
|
+
if (this.isSheetLine(r.line)) { this.matchSheetRule(r); return; }
|
|
261
509
|
if (isCountable(r.text)) { this.matchCountRule(r); return; }
|
|
262
510
|
// 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.
|
|
263
511
|
const negated = NEGATING_RE.test(r.text);
|
|
@@ -305,14 +553,30 @@ export class CheckBlock {
|
|
|
305
553
|
}
|
|
306
554
|
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; }
|
|
307
555
|
if (r.links?.length && !links.length) { r.can = { ok: false, why: REASON.lookNoWords }; return; }
|
|
308
|
-
if (r.origin === 'typed' || r.cantAsked) { r.can = { ok: false, why: r.aiReason ?? r.lookWhy ?? REASON.
|
|
556
|
+
if (r.origin === 'typed' || r.cantAsked) { r.can = { ok: false, why: r.aiReason ?? r.lookWhy ?? REASON.noPick }; return; }
|
|
309
557
|
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; }
|
|
310
|
-
|
|
558
|
+
// borrowed-from: bareloop src/checkblock.js@v0.61.0 (fc56e1f3) (M19 am3: a rule no check can prove is Not checked at once, never asked; the shape look can take it)
|
|
559
|
+
r.can = { ok: false, why: r.lookWhy ?? REASON.noPick };
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* S4: a `~` rule of a sheet line. The sheet checks code built decide it, and nothing else does (ONE owner: a rule has never two rows): built = this rule's own `[you]` row carries the check; an `[agent]` row that shows it carries it
|
|
564
|
+
* (and a Drop of that row leaves the rule Not checked); a table check only named it, a refusal, or nothing picked = Not checked with that plain reason. Before the AI's turn has answered, nothing is picked yet.
|
|
565
|
+
* @param {Row} r
|
|
566
|
+
*/
|
|
567
|
+
matchSheetRule(r) {
|
|
568
|
+
const b = this.sheetBuilt?.built[r.line];
|
|
569
|
+
const rs = b?.rows.find((x) => x.rule === r.rule && x.text === r.text);
|
|
570
|
+
if (!rs) { r.can = { ok: false, why: r.lookWhy ?? REASON.noPick }; return; }
|
|
571
|
+
if (rs.state === 'built') r.can = { ok: true, how: 'sheet', id: rs.id };
|
|
572
|
+
else if (rs.state === 'agent-row') r.can = this.rows.some((x) => x.kind === 'sheet' && x.line === r.line && x.check?.id === rs.id && x.choice === 'drop') ? { ok: false, why: REASON.dropped } : { ok: true, how: 'sheet', id: rs.id };
|
|
573
|
+
else if (rs.state === 'column') r.can = { ok: false, why: REASON.columnRule };
|
|
574
|
+
else r.can = { ok: false, why: rs.reason === REASON.noPick ? (r.lookWhy ?? REASON.noPick) : String(rs.reason) };
|
|
311
575
|
}
|
|
312
576
|
|
|
313
577
|
/** a `~` rule that counts words, bullets, lines or sections: a settled pick builds it; else code proposes the check and asks */
|
|
314
578
|
matchCountRule(/** @type {Row} */ r) {
|
|
315
|
-
if (!r.pick && (r.cantAsked || !this.countScope(r.text))) { r.can = { ok: false, why: r.aiReason ?? REASON.
|
|
579
|
+
if (!r.pick && (r.cantAsked || !this.countScope(r.text))) { r.can = { ok: false, why: r.aiReason ?? REASON.noPick }; return; }
|
|
316
580
|
if (r.pick) { r.can = { ok: true, how: 'pick' }; return; }
|
|
317
581
|
// 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
|
|
318
582
|
const obvious = obviousCheck(r.text);
|
|
@@ -321,9 +585,10 @@ export class CheckBlock {
|
|
|
321
585
|
if (res.kept) { r.pick = res.check; r.from = 'pick'; r.can = { ok: true, how: 'pick' }; return; }
|
|
322
586
|
}
|
|
323
587
|
const proposal = r.pickProposal ?? countCheck(r.text);
|
|
324
|
-
if (!this.asks) r.can = { ok: false, why: REASON.
|
|
588
|
+
if (!this.asks) r.can = { ok: false, why: REASON.noPick };
|
|
325
589
|
else if (proposal) r.can = { ok: false, ask: 'check', proposal, why: REASON.waitingPick };
|
|
326
|
-
|
|
590
|
+
// borrowed-from: bareloop src/checkblock.js@v0.61.0 (fc56e1f3) (M19 am3: no count proposal is Not checked at once, never asked)
|
|
591
|
+
else r.can = { ok: false, why: REASON.noPick };
|
|
327
592
|
}
|
|
328
593
|
|
|
329
594
|
/** 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 */
|
|
@@ -354,6 +619,7 @@ export class CheckBlock {
|
|
|
354
619
|
|
|
355
620
|
// 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.
|
|
356
621
|
build() {
|
|
622
|
+
if (this.repo !== null) return this.buildRepo();
|
|
357
623
|
/** @type {any[]} */ const stages = [];
|
|
358
624
|
/** @type {any[]} */ const parts = [];
|
|
359
625
|
/** @type {{part: number, line: number, rows: string[], origin: string}[]} */ const map = [];
|
|
@@ -363,6 +629,11 @@ export class CheckBlock {
|
|
|
363
629
|
/** @type {string[][]} */ const lineRows = [];
|
|
364
630
|
this.buildLine(l, lineParts, lineRows, factLines);
|
|
365
631
|
if (lineParts.length) stages.push({ name: `line-${l.n}`, kind: 'rubric-step', fromLine: [l.n], params: { step: l.n, parts: lineParts } });
|
|
632
|
+
// fwd keeps: no `carriesText` on the floor row and no `$prose` row (the tag sets the first for the card's floor words and adds the second for each text line; fwd's card draws neither today, and the v0.56.0 parity
|
|
633
|
+
// test (test/m16-block-parity.test.js) holds the rows as they are; M19 S6 draws the floor row and brings both)
|
|
634
|
+
// only a shape line's floor row carries the flag: every other row stays byte-identical to what it was
|
|
635
|
+
const hasShape = lineParts.some((p) => p.class === 'shape');
|
|
636
|
+
for (const f of this.rowsOn(l.n, 'floor')) { if (hasShape && !lineParts.some((p) => p.class === 'fact') && !lineParts.some((p) => p.class === 'countable')) f.listLine = true; else delete f.listLine; }
|
|
366
637
|
lineParts.forEach((p, i) => {
|
|
367
638
|
for (const k of lineRows[i] ?? []) { const row = this.rows.find((x) => x.key === k); if (row) row.part = { line: l.n, part: i }; }
|
|
368
639
|
map.push({ part: parts.length, line: l.n, rows: lineRows[i] ?? [], origin: 'code' });
|
|
@@ -370,7 +641,7 @@ export class CheckBlock {
|
|
|
370
641
|
});
|
|
371
642
|
}
|
|
372
643
|
// a suggestion code has not built stays off the card (Audit only, F-b); a held one is trialled: shown under Suggested only when code has proved it builds (hamr 2026-11-13)
|
|
373
|
-
for (const r of this.rows.filter((x) => x.held)) this.trialOffer(r);
|
|
644
|
+
for (const r of this.rows.filter((x) => x.held && x.kind !== 'sheet' && x.kind !== 'shape')) this.trialOffer(r);
|
|
374
645
|
if (this.split) for (const r of this.rows) r.hidden = this.isBang(r) && r.state === 'not-checked' && !r.lookWhy;
|
|
375
646
|
this.closeCache = { stages, parts, map };
|
|
376
647
|
return this.closeCache;
|
|
@@ -400,18 +671,26 @@ export class CheckBlock {
|
|
|
400
671
|
|
|
401
672
|
/** one line's parts: a pick part per count rule, ONE fact part carrying every fact row of the line (and its result count), then the `$` defaults */
|
|
402
673
|
buildLine(/** @type {{n: number, text: string}} */ l, /** @type {any[]} */ lineParts, /** @type {string[][]} */ lineRows, /** @type {Set<number>} */ factLines) {
|
|
674
|
+
let foundFact = false;
|
|
403
675
|
/** @type {any[]} */ const facts = [];
|
|
404
676
|
/** @type {{r: Row, src: string}[]} */ const factRows = [];
|
|
405
677
|
/** @type {Row|null} */ let countRow = null;
|
|
406
678
|
/** @type {number[]} */ const rulesCarried = [];
|
|
407
679
|
/** 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}[]} */
|
|
408
680
|
const pickParts = [];
|
|
681
|
+
/** S4: the rows a sheet part carries (a `~` rule row the sheet built, an `[agent]` row, the `[default]` row) @type {Row[]} */
|
|
682
|
+
const sheetRows = [];
|
|
683
|
+
/** shape jobs: the rows a shape part carries (a `~` rule row with a field, an `[agent]` field row, the `[default]` row) @type {Row[]} */
|
|
684
|
+
const shapeRows = [];
|
|
409
685
|
for (const r of this.rowsOn(l.n)) {
|
|
410
686
|
if (r.kind === 'floor') continue;
|
|
411
687
|
r.part = null;
|
|
412
|
-
r.grown = undefined;
|
|
413
688
|
if (!r.can?.ok) { r.state = 'not-checked'; r.reason = r.can?.why ?? 'not checked'; continue; }
|
|
414
689
|
if (r.held) { r.state = 'suggested'; r.reason = r.choice === 'drop' ? REASON.dropped : REASON.suggested; continue; }
|
|
690
|
+
if (r.can.how === 'sheet') { sheetRows.push(r); continue; }
|
|
691
|
+
if (r.can.how === 'shape') { shapeRows.push(r); continue; }
|
|
692
|
+
// a line is a sheet line or a facts line, never both (a stage-shape red): a page fact on a sheet line is Not checked in plain words
|
|
693
|
+
if (this.isSheetLine(l.n) && (r.kind === 'fact' || r.kind === 'phrase' || r.kind === 'count')) { r.state = 'not-checked'; r.reason = REASON.sheetFacts; continue; }
|
|
415
694
|
if (r.can.how === 'pick') {
|
|
416
695
|
const p = partOfPick(r.pick, r.text, [r.rule]);
|
|
417
696
|
const reds = rubricStepShapeReds({ step: l.n, parts: [p] }, 'trial');
|
|
@@ -421,40 +700,90 @@ export class CheckBlock {
|
|
|
421
700
|
}
|
|
422
701
|
if (r.can.how === 'count') { countRow = r; continue; }
|
|
423
702
|
const built = this.factsOf(r, facts);
|
|
424
|
-
if ('why' in built) { r.state = 'not-checked'; r.reason = `code could not build a legal check from it: ${built.why}`; continue; }
|
|
703
|
+
if ('why' in built) { r.state = 'not-checked'; r.reason = `code could not build a legal check from it: ${built.why}`; if (r.kind === 'rule') r.truthRefused = true; continue; }
|
|
425
704
|
facts.push(...built.fresh);
|
|
426
705
|
r.factNames = built.names;
|
|
427
706
|
factRows.push({ r, src: built.src });
|
|
428
707
|
if (r.kind === 'rule') rulesCarried.push(r.rule);
|
|
429
708
|
r.state = 'built'; r.reason = null;
|
|
430
709
|
}
|
|
710
|
+
if (sheetRows.length > 0) this.buildSheetPartOf(l, sheetRows, lineParts, lineRows);
|
|
431
711
|
if (facts.length) {
|
|
712
|
+
// borrowed-from: bareloop src/checkblock.js@v0.60.0 (F337: the planner's example when a label sits off the result's first line; from the drafting copy, only here at signing)
|
|
713
|
+
const asSeen = asSeenOf(this.textOf(factRows[0]?.src), facts, factRows[0]?.src ?? '');
|
|
432
714
|
const part = {
|
|
433
715
|
text: facts.map((f) => f.name).join('; '), class: 'fact', source: factRows[0]?.src, facts,
|
|
716
|
+
...(asSeen ? { asSeen } : {}),
|
|
434
717
|
...(rulesCarried.length ? { rules: rulesCarried } : {}),
|
|
435
718
|
...(countRow ? { count: { ...(Number.isInteger(countRow.min) ? { min: countRow.min } : {}), ...(Number.isInteger(countRow.max) ? { max: countRow.max } : {}) } } : {}),
|
|
436
719
|
};
|
|
437
720
|
const reds = rubricStepShapeReds({ step: l.n, parts: [part] }, 'trial');
|
|
438
721
|
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; }
|
|
439
722
|
else {
|
|
440
|
-
// M17 am4 (B3): the ONE writer of a place's grown phrases (fwd's signed R2c, M10 am7 item 2): the part holds EVERY phrase as a fact of its own
|
|
441
|
-
//
|
|
723
|
+
// M17 am4 (B3): the ONE writer of a place's grown phrases (fwd's signed R2c, M10 am7 item 2): the part holds EVERY phrase as a fact of its own; the plan and the Job tab say what the plan checks
|
|
724
|
+
// (M19 am6 item 4: the row copies of the words, `grown` and `oneOf`, are gone). A place the look did not grow keeps the one word.
|
|
442
725
|
const src = factRows[0]?.src;
|
|
443
726
|
const grownOf = (/** @type {any} */ f) => {
|
|
444
727
|
const k = f && f.shape === 'phrase' ? /** @type {any[]} */ (this.lookFacts).find((x) => x.line === l.n && Array.isArray(x.phrases) && String(x.name) === f.name && (x.source === undefined || x.source === src)) : undefined;
|
|
445
728
|
return k ? factsOfLook(k) : null;
|
|
446
729
|
};
|
|
447
|
-
|
|
448
|
-
const words = (r.factNames ?? []).flatMap((/** @type {string} */ n) => (grownOf(facts.find((f) => f.name === n)) ?? []).map((x) => String(x.phrase)));
|
|
449
|
-
r.grown = words.length ? words : undefined;
|
|
450
|
-
}
|
|
451
|
-
lineParts.push({ ...part, facts: facts.flatMap((f) => grownOf(f) ?? [f]) }); lineRows.push([...factRows.map((f) => f.r.key), ...(countRow ? [countRow.key] : [])]); factLines.add(l.n); if (countRow) { countRow.state = 'built'; countRow.reason = null; } }
|
|
452
|
-
// borrowed-from: bareloop src/checkblock.js@v0.58.0
|
|
730
|
+
lineParts.push({ ...part, facts: facts.flatMap((f) => grownOf(f) ?? [f]) }); lineRows.push([...factRows.map((f) => f.r.key), ...(countRow ? [countRow.key] : [])]); foundFact = true; if (countRow) { countRow.state = 'built'; countRow.reason = null; } }
|
|
453
731
|
} 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; }
|
|
732
|
+
// facts+shape: the shape part follows the fact part (the same `results` list); its fields are the rules no truth check could take
|
|
733
|
+
if (shapeRows.length > 0) this.buildShapePartOf(l, shapeRows, lineParts, lineRows);
|
|
454
734
|
for (const { p, key } of pickParts) { lineParts.push(p); lineRows.push([key]); }
|
|
735
|
+
// M19 am15 (F257): a line with no ~ of the person's own keeps the parts of the `!` rows the person Added (nothing else builds one there: match() holds every `!` row of such a line), so it may be a fact line
|
|
736
|
+
if (foundFact) factLines.add(l.n);
|
|
455
737
|
this.buildDefaults(l, lineParts, lineRows, factLines);
|
|
456
738
|
}
|
|
457
739
|
|
|
740
|
+
/**
|
|
741
|
+
* S4: ONE sheet part per sheet line, from the checks code built (the `[you]` rule rows' checks, then the `[agent]` checks the person has not dropped). Every row it carries points at it. A part code cannot legally build leaves its rows Not checked
|
|
742
|
+
* in the stage-shape red's own words; a line whose checks were all dropped has no part and no `[default]` row.
|
|
743
|
+
* @param {{n: number}} l @param {Row[]} sheetRows @param {any[]} lineParts @param {string[][]} lineRows
|
|
744
|
+
*/
|
|
745
|
+
buildSheetPartOf(l, sheetRows, lineParts, lineRows) {
|
|
746
|
+
const b = this.sheetBuilt?.built[l.n];
|
|
747
|
+
const held = new Set(this.rows.filter((r) => r.kind === 'sheet' && r.line === l.n && r.held).map((r) => r.check.id));
|
|
748
|
+
const checks = b ? [...b.ruleRows.map((p) => p.check), ...b.agentRows.map((p) => p.check).filter((c) => !held.has(c.id))] : [];
|
|
749
|
+
if (checks.length === 0) { for (const r of sheetRows) { r.state = 'dropped'; r.reason = null; } return; }
|
|
750
|
+
const rules = [...new Set(sheetRows.filter((r) => r.kind === 'rule').map((r) => Number(r.rule)))].sort((x, y) => x - y);
|
|
751
|
+
// fwd keeps: the checks stay exactly as built (the tag's `buildSheetPart` shares one claim between a sum and a count of one condition for bareloop's worker; fwd's close.sheet keeps them apart, M15 am3a), and the part is
|
|
752
|
+
// not tried by `rubricStepShapeReds`: fwd's one gate for a sheet check is the declaration validator (src/sheetchecks.js `sheetCheckReds`), which runs on the assembled close
|
|
753
|
+
const part = { text: `the checks of line ${l.n} on the sheet`, class: 'sheet', checks: checks.map((c) => ({ ...c })), ...(rules.length ? { rules } : {}) };
|
|
754
|
+
lineParts.push(part);
|
|
755
|
+
lineRows.push(sheetRows.map((r) => r.key));
|
|
756
|
+
for (const r of sheetRows) { r.state = 'built'; r.reason = null; }
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
/**
|
|
760
|
+
* Shape jobs: ONE shape part per shape line, from the fields that stand (a `[you]` rule row's field, then the `[agent]` fields the person has not dropped and that are not Suggested) and the item count the person's words gave. Every
|
|
761
|
+
* row it carries points at it. A line left with no field has no part and no `[default]` row.
|
|
762
|
+
* The part is validated by `rubricStepShapeReds` (names, kinds, count, and bareguard's own `createRubric` over the `itemShape` check): a part code cannot legally build leaves its rows Not checked in that red's own words, as `buildSheetPartOf` does.
|
|
763
|
+
* @param {{n: number, text: string}} l @param {Row[]} shapeRows @param {any[]} lineParts @param {string[][]} lineRows
|
|
764
|
+
*/
|
|
765
|
+
buildShapePartOf(l, shapeRows, lineParts, lineRows) {
|
|
766
|
+
const b = this.shapeBuilt?.built[l.n];
|
|
767
|
+
const fields = (b?.fields ?? []).filter((f) => shapeRows.some((r) => (f.by === 'you' && r.kind === 'rule' && r.rule === f.rule) || (f.by === 'agent' && r.key === shapeRowKey(l.n, f.name))));
|
|
768
|
+
if (!b || !fields.some((f) => f.by === 'you')) { for (const r of shapeRows) { r.state = 'dropped'; r.reason = null; } return; }
|
|
769
|
+
// M19 am11 items 1, 2: the `~` rules that count items set the line's count (all of them: the largest at-least and the smallest at-most hold); then code's own per-input count is Not checked, with its reason
|
|
770
|
+
const countRows = shapeRows.filter((r) => r.kind === 'rule' && r.can?.count);
|
|
771
|
+
const ruleCount = countRows.length === 0 ? null : {
|
|
772
|
+
...(countRows.some((r) => Number.isInteger(r.can.count.min)) ? { min: Math.max(...countRows.map((r) => r.can.count.min).filter(Number.isInteger)) } : {}),
|
|
773
|
+
...(countRows.some((r) => Number.isInteger(r.can.count.max)) ? { max: Math.min(...countRows.map((r) => r.can.count.max).filter(Number.isInteger)) } : {}),
|
|
774
|
+
};
|
|
775
|
+
if (ruleCount !== null) {
|
|
776
|
+
for (const r of shapeRows.filter((x) => x.kind === 'shape' && x.by === 'default')) { r.state = 'not-checked'; r.reason = REASON.itemCountByRule; }
|
|
777
|
+
shapeRows = shapeRows.filter((r) => !(r.kind === 'shape' && r.by === 'default'));
|
|
778
|
+
}
|
|
779
|
+
const part = buildShapePart({ text: `the items of line ${l.n}`, fields: fields.map((f) => ({ name: f.name, spec: fieldSpec(f), rule: f.rule, by: f.by })), itemCount: ruleCount ?? b.itemCount, countRules: countRows.map((r) => Number(r.rule)) });
|
|
780
|
+
const reds = rubricStepShapeReds({ step: l.n, parts: [...lineParts.filter((p) => p.class === 'fact'), part] }, 'trial');
|
|
781
|
+
if (reds.length) { for (const r of shapeRows) { r.state = 'not-checked'; r.reason = `code could not build the line's shape part: ${reds[0]?.detail}`; } return; }
|
|
782
|
+
lineParts.push(part);
|
|
783
|
+
lineRows.push(shapeRows.map((r) => r.key));
|
|
784
|
+
for (const r of shapeRows) { r.state = 'built'; r.reason = null; }
|
|
785
|
+
}
|
|
786
|
+
|
|
458
787
|
/**
|
|
459
788
|
* The fact(s) a fact-like row builds, checked alone through the bareguard shapes and against the facts already on the line.
|
|
460
789
|
* @param {Row} r @param {any[]} onLine the facts already built on this line @returns {{fresh: any[], src: string, names: string[]} | {why: string}}
|
|
@@ -471,10 +800,10 @@ export class CheckBlock {
|
|
|
471
800
|
if (r.kind === 'rule') {
|
|
472
801
|
const w = base.words.find((/** @type {string} */ x) => proved(this.textOf(src), x)) ?? base.words[0];
|
|
473
802
|
fs = r.can.strips ? placeFacts(base.name, r.can.strips, mk)
|
|
474
|
-
: base.shape === 'phrase' ? [mk(base.name, {
|
|
803
|
+
: base.shape === 'phrase' ? [mk(base.name, phraseSigned(base.words.filter((/** @type {string} */ x) => proved(this.textOf(src), x)), w))]
|
|
475
804
|
: [kindFields(base, w, { ...(r.can.reading ? { rule: r.can.reading } : {}), ...(r.can.aiProposal ? { aiProposal: true } : {}) })];
|
|
476
805
|
} else if (r.can.how === 'place') fs = placeFacts(r.name ?? 'phrase', r.can.strips, mk);
|
|
477
|
-
else if (r.shape === 'phrase' || r.kind === 'phrase') fs = [mk(r.name ?? `phrase ${r.words[0]}`, {
|
|
806
|
+
else if (r.shape === 'phrase' || r.kind === 'phrase') fs = [mk(r.name ?? `phrase ${r.words[0]}`, phraseSigned((r.words ?? []).filter((/** @type {string} */ x) => proved(this.textOf(src), x)), r.can.word))];
|
|
478
807
|
else fs = [kindFields(r, r.can.word, {})];
|
|
479
808
|
const fresh = [];
|
|
480
809
|
const names = fs.map((f) => f.name);
|
|
@@ -497,6 +826,8 @@ export class CheckBlock {
|
|
|
497
826
|
/** the `$` defaults of a line, decided from what the line ended with: a text line quotes its input (one input only) and ties its numbers to the fact lines before it */
|
|
498
827
|
buildDefaults(/** @type {{n: number}} */ l, /** @type {any[]} */ lineParts, /** @type {string[][]} */ lineRows, /** @type {Set<number>} */ factLines) {
|
|
499
828
|
// M16 am1: with `cited: false` the cited row is never added and the numbers default below still runs
|
|
829
|
+
// S4: a sheet line quotes nothing and ties no number to a quote: its `$cited` default is never added (a cited part beside a sheet part is a stage-shape red)
|
|
830
|
+
if (this.isSheetLine(l.n)) return;
|
|
500
831
|
const cited = !this.cited ? null : 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] });
|
|
501
832
|
const numbers = this.rowsOn(l.n, 'numbers')[0] ?? null;
|
|
502
833
|
if (cited) cited.part = null;
|
|
@@ -506,7 +837,7 @@ export class CheckBlock {
|
|
|
506
837
|
else if (cited) { cited.state = 'not-checked'; cited.reason = REASON.manyInputs; }
|
|
507
838
|
const earlier = [...factLines].filter((n) => n < l.n);
|
|
508
839
|
if (!earlier.length) return;
|
|
509
|
-
const nr = numbers ?? this.addRow({ key: `L${l.n}.$numbers`, line: l.n, kind: 'numbers', by: 'default', from: 'default'
|
|
840
|
+
const nr = numbers ?? this.addRow({ key: `L${l.n}.$numbers`, line: l.n, kind: 'numbers', by: 'default', from: 'default' });
|
|
510
841
|
lineParts.push({ text: 'every number in the text is in a checked quote', class: 'countable', check: 'numbersFromFacts', from: earlier });
|
|
511
842
|
lineRows.push([nr.key]); nr.state = 'built'; nr.reason = null; nr.part = null;
|
|
512
843
|
}
|
|
@@ -534,21 +865,179 @@ export class CheckBlock {
|
|
|
534
865
|
/** the note question's answers, `{line, answer: 'yes'|'no'|'failed'}`; the whole list is reconciled again @param {{line: number, answer: 'yes'|'no'|'failed'}[]} answers */
|
|
535
866
|
setNotes(answers) { for (const a of answers) this.notes.set(a.line, a.answer); this.reconcile(); }
|
|
536
867
|
|
|
868
|
+
// ── a repo job's check TYPE (hamr 2026-11-15: "same flow as rubric, no exceptions; only the TYPE of checks varies") ──────────────────────────────────────────────────────────────────────────
|
|
869
|
+
// 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
|
|
870
|
+
// 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.
|
|
871
|
+
|
|
872
|
+
/**
|
|
873
|
+
* 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.
|
|
874
|
+
* @param {{n: number, text: string, rules?: string[]}[]} jobLines
|
|
875
|
+
*/
|
|
876
|
+
syncJob(jobLines) {
|
|
877
|
+
this.lines = jobLines.map((l) => ({ n: l.n, text: l.text }));
|
|
878
|
+
const keep = new Set();
|
|
879
|
+
for (const l of jobLines) {
|
|
880
|
+
(l.rules ?? []).forEach((t, i) => {
|
|
881
|
+
const key = `L${l.n}.~${i + 1}`;
|
|
882
|
+
keep.add(key);
|
|
883
|
+
const row = this.rows.find((r) => r.key === key);
|
|
884
|
+
if (!row) { this.addRow({ key, line: l.n, kind: 'rule', by: 'you', from: 'rule', origin: 'typed', cantAsked: true, text: t, rule: i + 1 }); return; }
|
|
885
|
+
if (row.text !== t) { row.text = t; row.origin = 'typed'; row.left = false; row.cantAsked = true; }
|
|
886
|
+
});
|
|
887
|
+
}
|
|
888
|
+
this.rows = this.rows.filter((r) => r.kind !== 'rule' || keep.has(r.key));
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
/** the repo listing at the seed, once it is read (the rule rows are judged against it) @param {string[]|null} files */
|
|
892
|
+
setListing(files) { if (this.repo !== null) this.repo.files = Array.isArray(files) ? [...files] : null; }
|
|
893
|
+
|
|
894
|
+
/**
|
|
895
|
+
* 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`.
|
|
896
|
+
* @param {any[]} stages the declaration's stages, guards included @param {{guardNames?: string[], refused?: any[], guardLines?: any[]}} [o]
|
|
897
|
+
*/
|
|
898
|
+
addStages(stages, { guardNames = [], refused = [], guardLines = [] } = {}) {
|
|
899
|
+
this.rows = this.rows.filter((r) => r.kind !== 'stage');
|
|
900
|
+
this.declared = Array.isArray(stages) ? stages : [];
|
|
901
|
+
this.guardCover = new Set((Array.isArray(guardLines) ? guardLines : []).flatMap((/** @type {any} */ g) => (Array.isArray(g?.lines) ? g.lines : [])));
|
|
902
|
+
const guards = new Set(guardNames);
|
|
903
|
+
// 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)
|
|
904
|
+
const covered = new Set([...this.guardCover, ...this.declared.filter((st) => st && !guards.has(st.name) && Array.isArray(st.fromLine)).flatMap((st) => st.fromLine)]);
|
|
905
|
+
for (const l of this.lines) {
|
|
906
|
+
for (const st of this.declared) {
|
|
907
|
+
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;
|
|
908
|
+
this.addRow({ key: stageKeyOf(st.name), line: l.n, kind: 'stage', by: 'agent', from: 'agent', stageName: st.name, cover: [...st.fromLine] });
|
|
909
|
+
}
|
|
910
|
+
(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))
|
|
911
|
+
.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 }));
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
/** the repo paths outside the write scope (the pointing call is shown these); empty when there is no listing or no fence @returns {string[]} */
|
|
916
|
+
outsideScope() {
|
|
917
|
+
const files = this.repo?.files;
|
|
918
|
+
const scope = this.repo?.writeScope;
|
|
919
|
+
return Array.isArray(files) && Array.isArray(scope) && scope.length ? files.filter((f) => !this.inScope(f)) : [];
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
/** 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[]} */
|
|
923
|
+
outsideFolders() {
|
|
924
|
+
const files = this.repo?.files;
|
|
925
|
+
if (!Array.isArray(files) || this.outsideScope().length === 0) return [];
|
|
926
|
+
const all = new Set();
|
|
927
|
+
/** the folders above at least one file the run may change (one pass over the listing) */
|
|
928
|
+
const open = new Set();
|
|
929
|
+
for (const f of files) {
|
|
930
|
+
const inside = this.inScope(f);
|
|
931
|
+
for (let i = f.indexOf('/'); i > 0; i = f.indexOf('/', i + 1)) { all.add(f.slice(0, i)); if (inside) open.add(f.slice(0, i)); }
|
|
932
|
+
}
|
|
933
|
+
return [...all].filter((d) => !open.has(d));
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
/** is this repo file a place the run may change? @param {string} f */
|
|
937
|
+
inScope(f) {
|
|
938
|
+
return (this.repo?.writeScope ?? []).some((s) => { const pre = String(globToPrefix(String(s))).trim().replace(/^\.\//, '').replace(/\/+$/, ''); return pre === '' || pre === '.' || pre === '/' || f === pre || f.startsWith(`${pre}/`); });
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
/** the listing paths (a file, or a folder written `folder/`) a text names as whole tokens @param {string} text @returns {string[]} */
|
|
942
|
+
namedPaths(text) {
|
|
943
|
+
const files = this.repo?.files;
|
|
944
|
+
if (!Array.isArray(files)) return [];
|
|
945
|
+
const said = ` ${String(text).replace(/(^|[\s"'(])\.\//g, '$1')} `;
|
|
946
|
+
const all = new Set(files);
|
|
947
|
+
for (const f of files) for (let i = f.indexOf('/'); i > 0; i = f.indexOf('/', i + 1)) all.add(f.slice(0, i));
|
|
948
|
+
// borrowed-from: bareloop src/checkblock.js@v0.60.0 (`namedPaths`): the tag builds a pattern from each path; src/ builds none (test/signed-text.test.js), so the same two tests are written by hand:
|
|
949
|
+
// before the path no word character, `.`, `/` or `-`; after a file no word character or `-`, and no `.` that starts an extension; after a folder written `folder/` no word character, `.` or `-`
|
|
950
|
+
const wordy = (/** @type {string} */ c) => /\w/.test(c);
|
|
951
|
+
const holds = (/** @type {string} */ p) => {
|
|
952
|
+
const tail = files.includes(p) ? '' : '/';
|
|
953
|
+
for (let i = said.indexOf(p + tail); i !== -1; i = said.indexOf(p + tail, i + 1)) {
|
|
954
|
+
const before = said[i - 1] ?? '';
|
|
955
|
+
const after = said[i + p.length + tail.length] ?? '';
|
|
956
|
+
const afterNext = said[i + p.length + tail.length + 1] ?? '';
|
|
957
|
+
if (before !== '' && (wordy(before) || before === '.' || before === '/' || before === '-')) continue;
|
|
958
|
+
if (files.includes(p) ? (after !== '' && (wordy(after) || after === '-' || (after === '.' && wordy(afterNext)))) : (after !== '' && (wordy(after) || after === '.' || after === '-'))) continue;
|
|
959
|
+
return true;
|
|
960
|
+
}
|
|
961
|
+
return false;
|
|
962
|
+
};
|
|
963
|
+
return [...all].filter((p) => said.includes(p) && holds(p));
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
/**
|
|
967
|
+
* 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.
|
|
968
|
+
* @param {string} text the rule's own words @param {string} path @returns {boolean}
|
|
969
|
+
*/
|
|
970
|
+
provesFence(text, path) {
|
|
971
|
+
const files = this.repo?.files;
|
|
972
|
+
if (!Array.isArray(files) || this.outsideScope().length === 0) return false;
|
|
973
|
+
const p = String(path).trim().replace(/^\.\//, '').replace(/\/+$/, '');
|
|
974
|
+
const named = this.namedPaths(text);
|
|
975
|
+
if (!named.includes(p)) return false;
|
|
976
|
+
return !named.some((n) => files.some((f) => (f === n || f.startsWith(`${n}/`)) && this.inScope(f)));
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
/** 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 */
|
|
980
|
+
editFence(e) {
|
|
981
|
+
if (this.repo === null) return { refusedBecause: 'a fence pointer is for a repo job' };
|
|
982
|
+
const r = this.ruleRows(e.line).find((x) => x.rule === e.rule);
|
|
983
|
+
if (!r) return { refusedBecause: 'names no ~ rule of this line' };
|
|
984
|
+
const path = typeof e.path === 'string' ? e.path.trim().replace(/^\.\//, '').replace(/\/+$/, '') : '';
|
|
985
|
+
if (!path) return { refusedBecause: 'no path given' };
|
|
986
|
+
if (!(this.repo.files ?? []).some((f) => f === path || f.startsWith(`${path}/`))) return { refusedBecause: `${path} is not on the repo listing` };
|
|
987
|
+
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` };
|
|
988
|
+
r.pointed = path;
|
|
989
|
+
return { accepted: true, landedKey: r.key };
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
/** 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 */
|
|
993
|
+
matchRepoRule(r) {
|
|
994
|
+
// the AI points, code proves (never kept without a pointer; own words that replaced the rule are proved again against the same pointer)
|
|
995
|
+
if (typeof r.pointed === 'string' && this.provesFence(r.text, r.pointed)) { r.can = { ok: true, how: 'fence', path: r.pointed }; return; }
|
|
996
|
+
if (r.origin === 'typed' || r.cantAsked) { r.can = { ok: false, why: REASON.noPick }; return; }
|
|
997
|
+
r.can = { ok: false, why: REASON.noPick };
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
/** 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 */
|
|
1001
|
+
buildRepo() {
|
|
1002
|
+
for (const r of this.rows) {
|
|
1003
|
+
if (r.kind !== 'rule' && r.kind !== 'stage') continue;
|
|
1004
|
+
r.part = null;
|
|
1005
|
+
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; }
|
|
1006
|
+
}
|
|
1007
|
+
for (const r of this.rows) {
|
|
1008
|
+
if (r.kind !== 'stage' || r.state !== 'built' || r.choice !== 'drop') continue;
|
|
1009
|
+
if (this.dropOk(r)) { r.state = 'dropped'; r.reason = REASON.dropped; } else r.choice = undefined;
|
|
1010
|
+
}
|
|
1011
|
+
const gone = new Set(this.rows.filter((r) => r.kind === 'stage' && r.state === 'dropped').map((r) => r.stageName));
|
|
1012
|
+
this.closeCache = { stages: this.declared.filter((st) => !gone.has(st?.name)), parts: [], map: [] };
|
|
1013
|
+
return this.closeCache;
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
/** 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 */
|
|
1017
|
+
dropOk(r) {
|
|
1018
|
+
const others = this.rows.filter((x) => x !== r && x.kind === 'stage');
|
|
1019
|
+
const live = others.filter((x) => !x.refusal && x.state === 'built');
|
|
1020
|
+
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));
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
/** 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 */
|
|
1024
|
+
droppable(r) { return this.isBang(r) || (this.repo !== null && r.kind === 'stage' && r.refusal !== true) || (r.kind === 'sheet' && r.by === 'agent') || (r.kind === 'shape' && r.by === 'agent') || (r.kind === 'rule' && r.can?.how === 'shape'); }
|
|
1025
|
+
|
|
537
1026
|
// 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).
|
|
538
1027
|
ask() {
|
|
539
1028
|
this.open = [];
|
|
540
1029
|
for (const r of this.rows) {
|
|
541
1030
|
if (!r.can?.ask) continue;
|
|
542
|
-
this.open.push({ key: `${r.key}:${r.can.ask}`, rowKey: r.key, line: r.line, ruleText: r.text, ask: r.can.ask, proposal: r.can.proposal ?? null, offers: { agree: r.can.proposal != null, drop: true } });
|
|
1031
|
+
this.open.push({ key: `${r.key}:${r.can.ask}`, rowKey: r.key, line: r.line, ruleText: r.text, ask: r.can.ask, proposal: r.can.proposal ?? null, ...(typeof r.can.question === 'string' ? { question: r.can.question } : {}), ...(Array.isArray(r.can.columns) ? { columns: r.can.columns, readings: r.can.readings } : {}), offers: { agree: r.can.proposal != null, drop: true } });
|
|
543
1032
|
}
|
|
544
1033
|
return this.open;
|
|
545
1034
|
}
|
|
546
1035
|
hasOpenQuestions() { return this.open.length > 0; }
|
|
547
1036
|
hasPendingDelta() { return this.queue.length > 0; }
|
|
548
1037
|
|
|
549
|
-
// 6. the person's answer: a row edit from the typed CHOICE (agree | drop
|
|
550
|
-
//
|
|
551
|
-
/** @param {string} qKey @param {string} choice @param {string} [text] @returns {{ok: true} | {ok: false, why: string}} */
|
|
1038
|
+
// 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):
|
|
1039
|
+
// 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`).
|
|
1040
|
+
/** @param {string} qKey @param {string} choice @param {string} [text] the person's correction (a reading question only) @returns {{ok: true} | {ok: false, why: string}} */
|
|
552
1041
|
applyAnswer(qKey, choice, text) {
|
|
553
1042
|
const q = this.open.find((x) => x.key === qKey);
|
|
554
1043
|
const r = q ? this.rows.find((x) => x.key === q.rowKey) : undefined;
|
|
@@ -565,7 +1054,16 @@ export class CheckBlock {
|
|
|
565
1054
|
r.text = said;
|
|
566
1055
|
return { ok: true };
|
|
567
1056
|
}
|
|
1057
|
+
// S1 tie: the person picked one of the tied columns (`text` = its name); the rule is the rule's own words with that column in place, one rule in, one rule out
|
|
1058
|
+
if (choice === 'column') {
|
|
1059
|
+
if (!Array.isArray(q.columns)) return { ok: false, why: 'that choice is not offered for this question' };
|
|
1060
|
+
const col = String(text ?? '');
|
|
1061
|
+
if (!q.columns.includes(col)) return { ok: false, why: 'that is not one of the columns offered' };
|
|
1062
|
+
r.text = String(q.readings?.[col]); r.agreed = true;
|
|
1063
|
+
return { ok: true };
|
|
1064
|
+
}
|
|
568
1065
|
if (choice === 'drop') { r.left = true; return { ok: true }; }
|
|
1066
|
+
// fwd keeps: the tag takes the person's own words only for a READING question (and marks them `corrected`); fwd takes them for any question (M10 am16)
|
|
569
1067
|
if (choice === 'rule') {
|
|
570
1068
|
const said = String(text ?? '').replace(/\s+/g, ' ').trim();
|
|
571
1069
|
if (!said) return { ok: false, why: 'an answer is needed' };
|
|
@@ -622,12 +1120,15 @@ export class CheckBlock {
|
|
|
622
1120
|
applyEdit(/** @type {any} */ e, /** @type {{adds: number}} */ kept) {
|
|
623
1121
|
if (!isRec(e) || !EDIT_OPS.includes(e.op)) return { refusedBecause: `"${e?.op}" is not a row edit (the AI never sends a check or a part)` };
|
|
624
1122
|
if (!Number.isInteger(e.line) || !this.lines.some((l) => l.n === e.line)) return { refusedBecause: 'names a job line that does not exist' };
|
|
1123
|
+
// S4: a rule has never two rows: the rules of a sheet line belong to the sheet checks, so a row edit about the line cannot add a second check or a second reason
|
|
1124
|
+
if (this.isSheetLine(e.line)) return { refusedBecause: REASON.sheetLine };
|
|
625
1125
|
if (e.op === 'add') {
|
|
626
1126
|
if (kept.adds >= MAX_BANG) return { refusedBecause: `more than ${MAX_BANG} checks proposed` };
|
|
627
1127
|
const res = this.editAdd(e);
|
|
628
1128
|
if (res.accepted) kept.adds += 1;
|
|
629
1129
|
return res;
|
|
630
1130
|
}
|
|
1131
|
+
if (e.op === 'fence') return this.editFence(e);
|
|
631
1132
|
if (e.op === 'reading') return this.editReading(e);
|
|
632
1133
|
if (e.op === 'pick') return this.editPick(e);
|
|
633
1134
|
return this.editNot(e);
|
|
@@ -731,7 +1232,7 @@ export class CheckBlock {
|
|
|
731
1232
|
// 8. whole-list reconcile, every time
|
|
732
1233
|
reconcile() { this.match(); const c = this.build(); this.ask(); return c; }
|
|
733
1234
|
|
|
734
|
-
/** 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) */
|
|
1235
|
+
/** 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) */
|
|
735
1236
|
drive({ answer }) {
|
|
736
1237
|
this.unanswered = [];
|
|
737
1238
|
this.reconcile();
|
|
@@ -752,15 +1253,13 @@ export class CheckBlock {
|
|
|
752
1253
|
return this;
|
|
753
1254
|
}
|
|
754
1255
|
|
|
755
|
-
card() { return renderCard(this.rows); }
|
|
756
|
-
|
|
757
1256
|
/**
|
|
758
1257
|
* The rows as the close shape the card readers (`checksOfClose`, `refusedOf`, `cardOfClose`) already read: the block's stages, the picks code records and the signed list. The confirm card
|
|
759
1258
|
* and the signed card read the rows through the SAME readers, so a row shown at confirm is the row signed. Reconciles first (the whole list, every time).
|
|
760
1259
|
*/
|
|
761
1260
|
closeView() {
|
|
762
1261
|
const c = this.reconcile();
|
|
763
|
-
return { stages: c.stages, picks: this.picksOf(c), list: this.signedRows() };
|
|
1262
|
+
return { stages: c.stages, picks: this.picksOf(c), list: this.signedRows(), ...(this.fence ? { fence: [...this.fence] } : {}) };
|
|
764
1263
|
}
|
|
765
1264
|
|
|
766
1265
|
/** 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}[]} */
|
|
@@ -768,6 +1267,17 @@ export class CheckBlock {
|
|
|
768
1267
|
return c.map.flatMap((m) => { const part = c.parts[m.part]; return part && part.class === 'countable' && Array.isArray(part.rules) ? [{ line: m.line, part }] : []; });
|
|
769
1268
|
}
|
|
770
1269
|
|
|
1270
|
+
/**
|
|
1271
|
+
* The rules and lines the close has no check for, as the signed close's `refused` (one owner: the draft's assembled declaration and a final-card Drop both read it): each `~` rule row that is not built, then each job line no stage serves.
|
|
1272
|
+
* @param {{n: number}[]|null|undefined} jobLines @param {any[]} stages the block's stages @returns {{line: number, rule?: number, reason: string}[]}
|
|
1273
|
+
*/
|
|
1274
|
+
refusedView(jobLines, stages) {
|
|
1275
|
+
/** @type {{line: number, rule?: number, reason: string}[]} */
|
|
1276
|
+
const refused = this.rows.filter((r) => r.kind === 'rule' && r.state !== 'built').map((r) => ({ line: r.line, rule: r.rule, reason: String(r.reason ?? 'not checked') }));
|
|
1277
|
+
for (const l of jobLines ?? []) if (!stages.some((st) => Array.isArray(st.fromLine) && st.fromLine.includes(l.n))) refused.push({ line: l.n, reason: REASON.noRule });
|
|
1278
|
+
return refused;
|
|
1279
|
+
}
|
|
1280
|
+
|
|
771
1281
|
/** the standing ruling "a run needs one check": one row that is not the floor is built */
|
|
772
1282
|
hasBuiltCheck() { return this.rows.some((r) => r.state === 'built' && r.kind !== 'floor'); }
|
|
773
1283
|
|
|
@@ -776,11 +1286,17 @@ export class CheckBlock {
|
|
|
776
1286
|
* `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.
|
|
777
1287
|
*/
|
|
778
1288
|
signedRows() {
|
|
779
|
-
|
|
1289
|
+
const rows = (this.repo !== null ? [...this.rows].sort((a, b) => a.line - b.line) : this.rows).map((r) => {
|
|
780
1290
|
const gone = r.state === 'suggested' || r.hidden === true;
|
|
781
1291
|
const row = { ...r, ...(gone ? { state: 'dropped' } : {}), ...(r.state === 'built' && r.factNames?.length ? { facts: r.factNames } : {}) };
|
|
782
1292
|
return Object.fromEntries(SIGNED_ROW_FIELDS.filter((f) => row[f] !== undefined && row[f] !== null).map((f) => [f, row[f]]));
|
|
783
1293
|
});
|
|
1294
|
+
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' }] : [])];
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
/** the `[you]` rule rows the person dropped (Not checked, "You dropped it."): the card gives each an Add back button @returns {{key: string, line: number, text: string}[]} */
|
|
1298
|
+
droppedRulesView() {
|
|
1299
|
+
return this.rows.filter((r) => r.kind === 'rule' && this.shapeDrops.rules.has(`${r.line}:${r.rule}`)).map((r) => ({ key: r.key, line: r.line, text: String(r.text ?? '') }));
|
|
784
1300
|
}
|
|
785
1301
|
|
|
786
1302
|
/** the suggestions code has proved it can build, as the card offers them (Add): `{key, line, text}` */
|
|
@@ -802,9 +1318,32 @@ export class CheckBlock {
|
|
|
802
1318
|
rowChoice(key, choice) {
|
|
803
1319
|
const r = this.rows.find((x) => x.key === key);
|
|
804
1320
|
if (!r) return { ok: false, why: 'there is no such check on the list' };
|
|
1321
|
+
// a rule's own shape field (rules first: the rule had no truth check) can be dropped: that rule goes Not checked; to get it back, Revise
|
|
1322
|
+
if (r.kind === 'rule' && r.can?.how === 'shape') {
|
|
1323
|
+
if (choice !== 'drop') return { ok: false, why: 'that check is already on the card' };
|
|
1324
|
+
this.shapeDrops.rules.add(`${r.line}:${r.rule}`);
|
|
1325
|
+
this.reconcile();
|
|
1326
|
+
return { ok: true };
|
|
1327
|
+
}
|
|
1328
|
+
if (r.kind === 'rule' && this.shapeDrops.rules.has(`${r.line}:${r.rule}`)) {
|
|
1329
|
+
// Add back: the inverse of the Drop above; the rule is judged again by code, so it returns to its own row (Checked) exactly as before the drop
|
|
1330
|
+
if (choice !== 'add') return { ok: false, why: 'that check is already dropped' };
|
|
1331
|
+
this.shapeDrops.rules.delete(`${r.line}:${r.rule}`);
|
|
1332
|
+
this.reconcile();
|
|
1333
|
+
return { ok: true };
|
|
1334
|
+
}
|
|
805
1335
|
if (r.by === 'you') return { ok: false, why: 'that check comes from a rule you wrote; edit the job to change it' };
|
|
806
|
-
if (r.by !== 'agent' || !this.
|
|
1336
|
+
if (r.by !== 'agent' || !this.droppable(r)) return { ok: false, why: 'that check is code\'s own and stays' };
|
|
807
1337
|
if (choice !== 'drop' && choice !== 'add') return { ok: false, why: 'not one of the choices' };
|
|
1338
|
+
if (r.kind === 'stage') {
|
|
1339
|
+
// a repo work stage: Drop takes it out of the close (never the last check on its line), Add puts it back
|
|
1340
|
+
if (choice === 'drop' && r.state !== 'built') return { ok: false, why: 'only a check that is on the card can be dropped' };
|
|
1341
|
+
if (choice === 'add' && r.state !== 'dropped') return { ok: false, why: 'only a dropped check can be added back' };
|
|
1342
|
+
if (choice === 'drop' && !this.dropOk(r)) return { ok: false, why: `Dropping that check would leave line ${r.line} with no check, so it stays.` };
|
|
1343
|
+
r.choice = choice === 'drop' ? 'drop' : undefined;
|
|
1344
|
+
this.reconcile();
|
|
1345
|
+
return { ok: true };
|
|
1346
|
+
}
|
|
808
1347
|
if (choice === 'drop' && r.state !== 'built') return { ok: false, why: 'only a check that is on the card can be dropped' };
|
|
809
1348
|
if (choice === 'add' && r.state !== 'suggested') return { ok: false, why: 'only a suggested check can be added' };
|
|
810
1349
|
const before = r.choice;
|
|
@@ -816,9 +1355,7 @@ export class CheckBlock {
|
|
|
816
1355
|
|
|
817
1356
|
/** 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}[]} */
|
|
818
1357
|
choicesRecord() {
|
|
819
|
-
|
|
820
|
-
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 }]; }));
|
|
821
|
-
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) }));
|
|
1358
|
+
return choiceEntries(this.lines, this.rows.filter((r) => r.kind !== 'sheet' && r.kind !== 'shape' && (r.choice === 'drop' || r.choice === 'add')).map((r) => ({ line: r.line, key: r.key, choice: String(r.choice) })));
|
|
822
1359
|
}
|
|
823
1360
|
|
|
824
1361
|
/** 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 */
|
|
@@ -828,7 +1365,7 @@ export class CheckBlock {
|
|
|
828
1365
|
for (const c of Array.isArray(rec) ? rec : []) {
|
|
829
1366
|
if (!c || (c.choice !== 'drop' && c.choice !== 'add')) continue;
|
|
830
1367
|
const line = lines.find((l) => l.w === c.lineWords && l.o === c.occurrence);
|
|
831
|
-
const r = line ? this.rows.find((x) => x.line === line.n && this.
|
|
1368
|
+
const r = line ? this.rows.find((x) => x.line === line.n && this.droppable(x) && x.key.replace(/^L\d+\./, '') === c.tail) : undefined;
|
|
832
1369
|
if (r) { r.choice = c.choice; r.keptFromLast = true; }
|
|
833
1370
|
}
|
|
834
1371
|
}
|