bareloop 0.54.1 → 0.56.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +122 -0
- package/bareloop.context.md +67 -6
- package/package.json +3 -3
- package/src/authorflow.js +217 -238
- package/src/authoring.js +22 -6
- package/src/authorjob.js +138 -30
- package/src/authorreadout.js +15 -4
- package/src/authorrun.js +13 -4
- package/src/authorscout.js +9 -6
- package/src/behaviour.js +14 -0
- package/src/blockasks.js +43 -0
- package/src/cardschedule.js +42 -0
- package/src/checkblock.js +772 -0
- package/src/checklist.js +128 -0
- package/src/checkpick.js +294 -0
- package/src/checksuggest.js +28 -0
- package/src/checkwords.js +27 -0
- package/src/cli.js +1 -1
- package/src/config.js +24 -1
- package/src/declaredclose.js +30 -1
- package/src/destpoint.js +151 -0
- package/src/draftspend.js +85 -0
- package/src/facts.js +8 -1
- package/src/factwords.js +14 -1
- package/src/fitcheck.js +5 -3
- package/src/job.js +81 -1
- package/src/jobblock.js +9 -0
- package/src/labelscan.js +11 -0
- package/src/launcher.js +3 -2
- package/src/mcpchecks.js +52 -0
- package/src/mcppick.js +36 -0
- package/src/mcpsources.js +77 -0
- package/src/mcpuse.js +97 -0
- package/src/natural.js +23 -0
- package/src/pagemap.js +20 -5
- package/src/panel/authorroutes.js +105 -18
- package/src/panel/authorsession.js +293 -44
- package/src/panel/index.html +873 -41
- package/src/panel/jobgrid.js +117 -0
- package/src/panel/jobplan.js +103 -35
- package/src/panel/scheduler.js +80 -13
- package/src/panel/schedules.js +189 -28
- package/src/panel/schedulestart.js +44 -13
- package/src/panel/server.js +471 -39
- package/src/panel/settingsroutes.js +133 -3
- package/src/panel/status.js +19 -1
- package/src/panel/tickets.js +44 -0
- package/src/pickrecord.js +163 -0
- package/src/placerule.js +355 -0
- package/src/plan.js +31 -2
- package/src/planrun.js +71 -15
- package/src/prcheckout.js +259 -0
- package/src/promptregisters.js +11 -0
- package/src/questionbox.js +112 -0
- package/src/readshim.js +3 -2
- package/src/revises.js +56 -0
- package/src/rowedit.js +115 -0
- package/src/rubricstep.js +265 -132
- package/src/run.js +19 -2
- package/src/runexport.js +2 -0
- package/src/runlist.js +3 -2
- package/src/schedulewords.js +46 -4
- package/src/source.js +81 -7
- package/src/stepmcp.js +86 -0
- package/src/ticket.js +113 -0
- package/src/ticketfilter.js +76 -0
- package/src/ticketlabels.js +79 -0
- package/src/ticketmcp.js +111 -0
- package/src/ticketnext.js +35 -0
- package/src/ticketrepo.js +98 -0
- package/src/ticketschedule.js +32 -0
- package/src/ticketshape.js +45 -0
- package/src/tools.js +9 -0
- package/src/trigger.js +14 -2
- package/src/triggerclock.js +7 -3
- package/src/triggerfiles.js +19 -11
- package/src/triggertickets.js +244 -0
- package/src/userrun.js +191 -10
- package/src/validate.js +3 -1
- package/src/worktree.js +43 -1
- package/types/authorflow.d.ts +86 -93
- package/types/authorjob.d.ts +35 -4
- package/types/authorreadout.d.ts +4 -3
- package/types/authorscout.d.ts +4 -2
- package/types/behaviour.d.ts +12 -0
- package/types/blockasks.d.ts +37 -0
- package/types/cardschedule.d.ts +24 -0
- package/types/checkblock.d.ts +361 -0
- package/types/checklist.d.ts +134 -0
- package/types/checkpick.d.ts +160 -0
- package/types/checksuggest.d.ts +30 -0
- package/types/checkwords.d.ts +14 -0
- package/types/config.d.ts +7 -0
- package/types/declaredclose.d.ts +4 -0
- package/types/destpoint.d.ts +89 -0
- package/types/draftspend.d.ts +37 -0
- package/types/factwords.d.ts +7 -0
- package/types/fitcheck.d.ts +7 -1
- package/types/job.d.ts +13 -0
- package/types/jobblock.d.ts +9 -0
- package/types/labelscan.d.ts +7 -0
- package/types/launcher.d.ts +2 -2
- package/types/mcpchecks.d.ts +8 -0
- package/types/mcppick.d.ts +33 -0
- package/types/mcpsources.d.ts +51 -0
- package/types/mcpuse.d.ts +15 -0
- package/types/natural.d.ts +2 -0
- package/types/pagemap.d.ts +6 -1
- package/types/panel/authorroutes.d.ts +11 -2
- package/types/panel/authorsession.d.ts +69 -3
- package/types/panel/jobgrid.d.ts +405 -0
- package/types/panel/jobplan.d.ts +55 -11
- package/types/panel/scheduler.d.ts +7 -2
- package/types/panel/schedules.d.ts +124 -4
- package/types/panel/schedulestart.d.ts +21 -3
- package/types/panel/server.d.ts +432 -10
- package/types/panel/settingsroutes.d.ts +4 -2
- package/types/panel/status.d.ts +16 -2
- package/types/panel/tickets.d.ts +61 -0
- package/types/pickrecord.d.ts +100 -0
- package/types/placerule.d.ts +194 -0
- package/types/plan.d.ts +1 -0
- package/types/prcheckout.d.ts +151 -0
- package/types/questionbox.d.ts +87 -0
- package/types/readshim.d.ts +4 -3
- package/types/revises.d.ts +23 -0
- package/types/rowedit.d.ts +32 -0
- package/types/rubricstep.d.ts +100 -48
- package/types/run.d.ts +27 -1
- package/types/runlist.d.ts +6 -3
- package/types/schedulewords.d.ts +29 -2
- package/types/source.d.ts +40 -4
- package/types/stepmcp.d.ts +40 -0
- package/types/ticket.d.ts +114 -0
- package/types/ticketfilter.d.ts +34 -0
- package/types/ticketlabels.d.ts +44 -0
- package/types/ticketmcp.d.ts +84 -0
- package/types/ticketnext.d.ts +33 -0
- package/types/ticketrepo.d.ts +118 -0
- package/types/ticketschedule.d.ts +21 -0
- package/types/ticketshape.d.ts +37 -0
- package/types/tools.d.ts +1 -0
- package/types/trigger.d.ts +9 -1
- package/types/triggerclock.d.ts +6 -2
- package/types/triggerfiles.d.ts +13 -5
- package/types/triggertickets.d.ts +110 -0
- package/types/userrun.d.ts +50 -0
- package/types/validate.d.ts +1 -0
- package/types/worktree.d.ts +19 -0
package/src/rubricstep.js
CHANGED
|
@@ -3,6 +3,7 @@ import { readFile, lstat } from 'node:fs/promises';
|
|
|
3
3
|
import { join, dirname } from 'node:path';
|
|
4
4
|
import { createRubric, checkStep, renderGaps, numbersInQuote } from 'bareguard';
|
|
5
5
|
import { dropRows, dropLine } from './pagedropwords.js';
|
|
6
|
+
import { OFFERED, plainWords } from './checkwords.js';
|
|
6
7
|
import { factPartOf, factShapeReds, factDecides, factClaims, factRows, plainFactItem, factBrief, writtenSpans } from './facts.js';
|
|
7
8
|
|
|
8
9
|
// PART 1a (docs/product/ITEM33-BUILD.md, "Addendum 2026-10-12"): the rubric job on LOCAL FILES — what one job line leaves
|
|
@@ -37,15 +38,36 @@ export function stepFileContract() {
|
|
|
37
38
|
' ** or __ marks do not matter). Every number in a claim must also appear in its quote.',
|
|
38
39
|
' In each claim, copy every number, time and price exactly as the input writes it (for example "9:27 AM", not "09:27"),',
|
|
39
40
|
' because the check matches the numbers in your claim against your quote.',
|
|
40
|
-
'A job line the brief below marks as a FACTS line is different: its file holds
|
|
41
|
+
'A job line the brief below marks as a FACTS line is different: its file holds {"results": [{"quote": "...", "values":',
|
|
41
42
|
'{"<fact>": "<value>"}}]} — one result per thing found, one quote copied exactly from the text of that one result, the values written as the quote',
|
|
42
|
-
'writes them; no "
|
|
43
|
+
'writes them; no "cites". It holds a "text" too only when the brief says it is also a TEXT line (the person asked for limits on the words, so',
|
|
44
|
+
'the same file carries both "results" and "text"). A line the brief marks as a TEXT line keeps "text" (free words), and every number in it',
|
|
43
45
|
'must be copied from a quote of an earlier facts line.',
|
|
44
46
|
'Write nothing outside output/, and never edit the files under input/. The file must be complete, valid JSON: a file cut',
|
|
45
47
|
'off before its closing brace counts as not written.',
|
|
46
48
|
].join('\n');
|
|
47
49
|
}
|
|
48
50
|
|
|
51
|
+
/**
|
|
52
|
+
* R10 (fwd am28, rewritten here): what a facts+text line's worker is told about the person's picks, one plain line per pick, the values and what counts, never a verdict and never any other
|
|
53
|
+
* check. Written by code from the signed pick parts; a list item is what bareguard's listItems counts (its own line starting with "1." or "- " and a space).
|
|
54
|
+
* @param {any[]} picked countable parts (`{check, value, names, ...}`) @returns {string[]}
|
|
55
|
+
*/
|
|
56
|
+
export function toldPicks(picked) {
|
|
57
|
+
const list = (/** @type {unknown} */ v) => (Array.isArray(v) ? v.map((x) => String(x)).join(', ') : '');
|
|
58
|
+
return picked.map((p) => {
|
|
59
|
+
switch (p.check) {
|
|
60
|
+
case 'listItems': return `Your "text" must have exactly ${p.value} list items; a list item is its own line starting with "1." or "- " followed by a space and its text.`;
|
|
61
|
+
case 'maxListItems': return `Your "text" must have at most ${p.value} list items; a list item is its own line starting with "1." or "- " followed by a space and its text.`;
|
|
62
|
+
case 'minListItems': return `Your "text" must have at least ${p.value} list items; a list item is its own line starting with "1." or "- " followed by a space and its text.`;
|
|
63
|
+
case 'nonEmpty': return 'Your "text" must not be empty.';
|
|
64
|
+
case 'mustCarry': return `Your "text" must carry ${list(p.phrases)}.`;
|
|
65
|
+
case 'blockLines': return `Your "text" must be in blocks of ${p.size} lines, each carrying ${list(p.phrases)}.`;
|
|
66
|
+
default: return `Your "text" must have ${plainWords({ ...p, rule: p.check })}.`;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
49
71
|
/**
|
|
50
72
|
* What the worker is told about each line, from the close that will grade it (PART 1b item 7): a FACTS line gets its
|
|
51
73
|
* facts and its count; a TEXT line that follows a facts line is told its numbers come from that line's quotes. Written by code from
|
|
@@ -65,10 +87,18 @@ export function lineBriefs(closeDecl) {
|
|
|
65
87
|
const count = !c ? 'one result for every one you find' : c.min !== undefined && c.max !== undefined
|
|
66
88
|
? (c.min === c.max ? `exactly ${c.min} result${c.min === 1 ? '' : 's'}` : `${c.min} to ${c.max} results`)
|
|
67
89
|
: c.min !== undefined ? `at least ${c.min} results` : `at most ${c.max} results`;
|
|
90
|
+
// keep-both: the person's picks (countable parts) sit beside the fact on this line, so the same file also carries the "text" they limit
|
|
91
|
+
const alsoText = st.params.parts.some((/** @type {any} */ q) => isRec(q) && q.class === 'countable');
|
|
92
|
+
// R10 (fwd am28): the picks among them, as the signed close's own record names them, are told to the worker in plain words
|
|
93
|
+
const record = Array.isArray(closeDecl.picks) ? closeDecl.picks : [];
|
|
94
|
+
const picked = st.params.parts.filter((/** @type {any} */ q) => isRec(q) && q.class === 'countable' && OFFERED.includes(q.check) && record.some((/** @type {any} */ x) => isRec(x) && x.line === n && sameJson(x.part, q)));
|
|
68
95
|
out.push({
|
|
69
96
|
line: n,
|
|
70
97
|
text: [
|
|
71
|
-
|
|
98
|
+
alsoText
|
|
99
|
+
? `Job line ${n} is a FACTS line AND a TEXT line. Write ${stepFileRel(n)} as {"results": [{"quote": "...", "values": {...}}], "text": "..."} — the results are the facts below, the "text" is your answer to the line in your own words (its limits are in the line's ~ rules); no "cites".`
|
|
100
|
+
: `Job line ${n} is a FACTS line. Write ${stepFileRel(n)} as {"results": [{"quote": "...", "values": {...}}]} and nothing else — no "text", no "cites".`,
|
|
101
|
+
...(alsoText && picked.length ? toldPicks(picked).map((t) => ` ${t}`) : []),
|
|
72
102
|
` One result per thing you find in the input "${fp.source}": ${count}.`,
|
|
73
103
|
' "quote": ONE quote per result, copied exactly from that result\'s own text in the input (at most 4000 characters) — never joined from two results.',
|
|
74
104
|
' "values": one entry per fact below, written exactly as the quote writes it (for example "9:27 AM", not "09:27"; "389", not "389.00").',
|
|
@@ -156,6 +186,14 @@ export const COUNT_CHECKS = Object.freeze({
|
|
|
156
186
|
maxLines: Object.freeze(['value']),
|
|
157
187
|
sections: Object.freeze(['names']),
|
|
158
188
|
sectionWords: Object.freeze(['names', 'wordsPerSection']),
|
|
189
|
+
// R10 (bareguard 0.31, fwdloop v0.29.0 OFFERED): the five text checks a person's pick may carry; the drafter never writes them
|
|
190
|
+
nonEmpty: Object.freeze([]),
|
|
191
|
+
listItems: Object.freeze(['value']),
|
|
192
|
+
maxListItems: Object.freeze(['value']), // bareguard 0.35 (F315): an at-most / at-least bound on the list items, beside the exact listItems
|
|
193
|
+
minListItems: Object.freeze(['value']),
|
|
194
|
+
sectionOrder: Object.freeze(['names']),
|
|
195
|
+
mustCarry: Object.freeze(['phrases']),
|
|
196
|
+
blockLines: Object.freeze(['size', 'phrases']),
|
|
159
197
|
cited: Object.freeze(['source']),
|
|
160
198
|
// a COUNT of the claims listed under an input: the code counts the list (flattenStep), bareguard's own min/max compares it
|
|
161
199
|
minClaims: Object.freeze(['value', 'source']),
|
|
@@ -165,12 +203,16 @@ export const COUNT_CHECKS = Object.freeze({
|
|
|
165
203
|
numbersFromFacts: Object.freeze(['from']),
|
|
166
204
|
});
|
|
167
205
|
/** every field a part may carry, whatever its class */
|
|
168
|
-
const PART_FIELDS = Object.freeze(['text', 'class', 'check', 'value', 'names', 'wordsPerSection', 'source', 'domains', 'covers', 'rules', 'from', 'record', 'facts', 'count', 'tested', 'sample']);
|
|
206
|
+
const PART_FIELDS = Object.freeze(['text', 'class', 'check', 'value', 'names', 'wordsPerSection', 'source', 'domains', 'phrases', 'size', 'covers', 'rules', 'from', 'record', 'facts', 'count', 'tested', 'sample']);
|
|
169
207
|
|
|
170
208
|
/** @typedef {{code: string, path: string, detail: string}} ShapeRed */
|
|
171
209
|
|
|
172
210
|
/** @param {unknown} v @returns {v is Record<string, any>} */
|
|
173
211
|
const isRec = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
212
|
+
/** @param {unknown} v @returns {string} JSON with every object's keys sorted, so two equal parts compare equal whatever order their keys were written in */
|
|
213
|
+
const sortedJson = (v) => JSON.stringify(v, (_k, x) => (isRec(x) ? Object.fromEntries(Object.entries(x).sort(([a], [b]) => (a < b ? -1 : 1))) : x));
|
|
214
|
+
/** @param {unknown} a @param {unknown} b */
|
|
215
|
+
const sameJson = (a, b) => sortedJson(a) === sortedJson(b);
|
|
174
216
|
/** @param {unknown} v @returns {v is string} */
|
|
175
217
|
const nonEmpty = (v) => typeof v === 'string' && v.trim() !== '';
|
|
176
218
|
/** @param {unknown} v @returns {v is string[]} */
|
|
@@ -214,12 +256,13 @@ export function rubricStepShapeReds(p, at) {
|
|
|
214
256
|
if (part.class !== 'countable') return;
|
|
215
257
|
if (!Object.hasOwn(COUNT_CHECKS, part.check)) { red('invalid-value', `${w}.check`, `one of ${Object.keys(COUNT_CHECKS).join(' | ')}`); return; }
|
|
216
258
|
for (const f of COUNT_CHECKS[part.check]) {
|
|
217
|
-
const ok = f === 'value' || f === 'wordsPerSection' ? Number.isInteger(part[f]) && part[f] >= 1
|
|
218
|
-
: f === 'names' ? nameList(part
|
|
259
|
+
const ok = f === 'value' || f === 'wordsPerSection' || f === 'size' ? Number.isInteger(part[f]) && part[f] >= 1
|
|
260
|
+
: f === 'names' || f === 'phrases' ? nameList(part[f])
|
|
219
261
|
: f === 'from' ? Array.isArray(part.from) && part.from.length > 0 && new Set(part.from).size === part.from.length && part.from.every((/** @type {unknown} */ x) => Number.isInteger(x) && /** @type {number} */ (x) >= 1)
|
|
220
262
|
: nonEmpty(part.source) && part.source.length <= 128;
|
|
221
263
|
if (!ok) {
|
|
222
264
|
red('invalid-value', `${w}.${f}`, f === 'names' ? 'a non-empty array of section names'
|
|
265
|
+
: f === 'phrases' ? 'a non-empty array of words or phrases'
|
|
223
266
|
: f === 'source' ? 'the label of the input a quote must come from'
|
|
224
267
|
: f === 'from' ? 'the numbers of the earlier fact lines whose checked quotes the text\'s numbers come from (distinct integers, 1 or more)'
|
|
225
268
|
: 'an integer, 1 or more');
|
|
@@ -246,7 +289,8 @@ export function citedLabels(params) {
|
|
|
246
289
|
*/
|
|
247
290
|
export function buildStepSpec(params, inputShas) {
|
|
248
291
|
/** @type {Record<string, any>[]} */
|
|
249
|
-
|
|
292
|
+
// a fact step has no text to floor, unless the person's picks put text checks on its line (keep-both): then "text" must be there, or an upper bound alone (maxWords) would pass an empty file
|
|
293
|
+
const checks = factPartOf(params) && !params.parts.some((x) => x.class === 'countable') ? [] : [{ id: 'text-present', rule: 'nonEmpty', field: 'text' }];
|
|
250
294
|
params.parts.forEach((part, i) => {
|
|
251
295
|
if (part.class === 'fact') {
|
|
252
296
|
// ONE bareguard `cited` check per fact part: the quote is in the frozen input, every value is in the quote and meets its rule
|
|
@@ -261,6 +305,11 @@ export function buildStepSpec(params, inputShas) {
|
|
|
261
305
|
case 'maxWords': case 'minWords': case 'maxLines': checks.push({ id, rule: part.check, field: 'text', value: part.value }); break;
|
|
262
306
|
case 'sections': checks.push({ id, rule: 'sections', field: 'text', names: [...part.names] }); break;
|
|
263
307
|
case 'sectionWords': checks.push({ id, rule: 'sectionWords', field: 'text', names: [...part.names], wordsPerSection: part.wordsPerSection }); break;
|
|
308
|
+
case 'nonEmpty': checks.push({ id, rule: 'nonEmpty', field: 'text' }); break;
|
|
309
|
+
case 'listItems': case 'maxListItems': case 'minListItems': checks.push({ id, rule: part.check, field: 'text', value: part.value }); break;
|
|
310
|
+
case 'sectionOrder': checks.push({ id, rule: 'sectionOrder', field: 'text', names: [...part.names] }); break;
|
|
311
|
+
case 'mustCarry': checks.push({ id, rule: 'mustCarry', field: 'text', phrases: [...part.phrases] }); break;
|
|
312
|
+
case 'blockLines': checks.push({ id, rule: 'blockLines', field: 'text', size: part.size, phrases: [...part.phrases] }); break;
|
|
264
313
|
case 'cited': checks.push({ id, rule: 'cited', claims: `cites:${part.source}`, source: part.source }); break;
|
|
265
314
|
case 'minClaims': checks.push({ id, rule: 'min', field: `claims:${part.source}`, value: part.value }); break;
|
|
266
315
|
case 'maxClaims': checks.push({ id, rule: 'max', field: `claims:${part.source}`, value: part.value }); break;
|
|
@@ -394,6 +443,12 @@ export function plainStepGap(step, why, g, params = null) {
|
|
|
394
443
|
if (g.check === 'minWords') return `${at}: "text" has ${g.measured} words, at least ${g.limit} are required`;
|
|
395
444
|
if (g.check === 'maxLines') return `${at}: "text" has ${g.measured} lines, at most ${g.limit} are allowed`;
|
|
396
445
|
if (g.check === 'sections') return `${at}: "text" is missing section(s): ${(g.items ?? []).join(', ')}`;
|
|
446
|
+
if (g.check === 'maxListItems') return `${at}: "text" has ${g.measured} list items, at most ${g.limit} are allowed`;
|
|
447
|
+
if (g.check === 'minListItems') return `${at}: "text" has ${g.measured} list items, at least ${g.limit} are required`;
|
|
448
|
+
if (g.check === 'listItems') return `${at}: "text" has ${g.measured} list items, exactly ${g.limit} are required`;
|
|
449
|
+
if (g.check === 'sectionOrder') return `${at}: "text" does not hold its sections in the asked order (${(g.items ?? []).map((/** @type {string} */ x) => x.replace(/^[^:]*:/, '')).join(', ')} out of place)`;
|
|
450
|
+
if (g.check === 'mustCarry') return `${at}: "text" does not carry: ${(g.items ?? []).join(', ')}`;
|
|
451
|
+
if (g.check === 'blockLines') return `${at}: "text" is not in blocks of ${g.limit} lines each carrying the asked words (${(g.items ?? []).join(', ')})`;
|
|
397
452
|
if ((g.check === 'min' || g.check === 'max') && String(g.field ?? '').startsWith('claims:')) {
|
|
398
453
|
const label = String(g.field).slice('claims:'.length);
|
|
399
454
|
return g.check === 'min'
|
|
@@ -532,6 +587,12 @@ function dupUnitWords(p, path) {
|
|
|
532
587
|
return null;
|
|
533
588
|
}
|
|
534
589
|
|
|
590
|
+
/** The legal example the `rubric-fact-twice` red carries as its drafter-only `hint` (the person's text is the plain sentence): one fact part holding two facts, the rule it carries listed in "rules", no "count" (a picked count is a pick). */
|
|
591
|
+
const factTwiceExample = (/** @type {unknown} */ source) => ({
|
|
592
|
+
class: 'fact', source: typeof source === 'string' ? source : 'Changelog', text: 'the release heading and a section word', rules: [1],
|
|
593
|
+
facts: [{ name: 'release heading', shape: 'phrase', phrase: '## [0.54.1] - 2026-11-04' }, { name: 'section word', shape: 'phrase', phrase: '### Fixed' }],
|
|
594
|
+
});
|
|
595
|
+
|
|
535
596
|
/**
|
|
536
597
|
* R11 — the drafting-time rules for the `rubric-step` stages of a declaration, each a red in the person's plain words that
|
|
537
598
|
* names the job line and ends "Nothing spent." where nothing was. Pure; never throws. Judged parts are RED in this build
|
|
@@ -544,10 +605,11 @@ function dupUnitWords(p, path) {
|
|
|
544
605
|
* naming both parts and both numbers;
|
|
545
606
|
* - a `cited` part names a label the person's inputs do not have.
|
|
546
607
|
* @param {any[]} stages the declaration's stages
|
|
547
|
-
* @param {{inputLabels?: string[]|null, red: (code: string, path: string, detail: string, extra?: object) => void}} o
|
|
548
|
-
* `inputLabels` absent = the label rule is not run (a caller with no inputs in hand)
|
|
608
|
+
* @param {{inputLabels?: string[]|null, picks?: {line: number, part: any}[]|null, red: (code: string, path: string, detail: string, extra?: object) => void}} o
|
|
609
|
+
* `inputLabels` absent = the label rule is not run (a caller with no inputs in hand);
|
|
610
|
+
* `picks` = the record of the person's picks (`declaration.picks`, `{line, part}` each): the only countable parts a fact line may carry
|
|
549
611
|
*/
|
|
550
|
-
export function checkRubricParts(stages, { inputLabels = null, red }) {
|
|
612
|
+
export function checkRubricParts(stages, { inputLabels = null, red, picks = null }) {
|
|
551
613
|
/** @type {Map<number, string>} */
|
|
552
614
|
const owner = new Map();
|
|
553
615
|
/** the stage index of each fact line (PART 1b: a prose step ties its numbers to fact lines that are checked BEFORE it) @type {Map<number, number>} */
|
|
@@ -596,7 +658,7 @@ export function checkRubricParts(stages, { inputLabels = null, red }) {
|
|
|
596
658
|
red('rubric-part-source', `${w}.source`, `line ${line}: '${said}' asks for quotes from "${sayText(part.source ?? '')}", but the job's inputs are ${inputLabels.map((l) => `"${l}"`).join(', ')}.`, { line: step, stage: label });
|
|
597
659
|
}
|
|
598
660
|
if (p.parts.filter((/** @type {any} */ x) => isRec(x) && x.class === 'fact').length > 1) {
|
|
599
|
-
red('rubric-fact-twice', w, `line ${line}: '${said}' is a second fact list on the same line. One line has one list of facts; put them all in one. Nothing spent.`, { line: step, stage: label });
|
|
661
|
+
red('rubric-fact-twice', w, `line ${line}: '${said}' is a second fact list on the same line. One line has one list of facts; put them all in one. Nothing spent.`, { line: step, stage: label, hint: `Example of ONE part holding two facts: ${JSON.stringify(factTwiceExample(part.source))}` });
|
|
600
662
|
}
|
|
601
663
|
} else if (part.class === 'countable') {
|
|
602
664
|
if (part.check === 'numbersFromFacts') {
|
|
@@ -606,7 +668,9 @@ export function checkRubricParts(stages, { inputLabels = null, red }) {
|
|
|
606
668
|
}
|
|
607
669
|
return;
|
|
608
670
|
}
|
|
609
|
-
|
|
671
|
+
// keep-both: a fact line may carry a countable part only when it IS one of the person's recorded picks (an offered check, its `rules`, the same line, the same words)
|
|
672
|
+
const isPick = factLine && Array.isArray(picks) && picks.some((x) => isRec(x) && x.line === step && sameJson(x.part, part)) && OFFERED.includes(part.check) && Array.isArray(part.rules);
|
|
673
|
+
if (factLine && !isPick) {
|
|
610
674
|
red('rubric-fact-text', w, `line ${line}: '${said}' counts or quotes free text, but this line lists facts and has no text. Say it as a fact (a shape and a rule) or remove it. Nothing spent.`, { line: step, stage: label });
|
|
611
675
|
return;
|
|
612
676
|
}
|
|
@@ -726,117 +790,134 @@ export function checkRubricRules(stages, { jobLines = null, refused = null, red
|
|
|
726
790
|
/** a clock time as a person writes it: 7:00, 07:00, 7:00 AM, 11 PM is not matched (no minutes) */
|
|
727
791
|
const CLOCK = '\\d{1,2}:\\d{2}(?:\\s?[AaPp][Mm])?';
|
|
728
792
|
const TIME_RANGE_RE = new RegExp(`\\b(?:between|from)\\s+(${CLOCK})\\s+(?:and|to|-)\\s+(${CLOCK})`, 'i');
|
|
729
|
-
const NEGATING_RE = /\b(?:not|no|never|outside|except|before|after|without)\b/i;
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
*/
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
const facts = fp.facts.map((/** @type {any} */ f) => {
|
|
754
|
-
if (!isRec(f) || !isRec(f.rule) || f.aiProposal !== true) return f;
|
|
755
|
-
const own = (/** @type {unknown[]} */ bounds) => bounds.every((b) => boundInWords(b, said));
|
|
756
|
-
const bounds = f.rule.op === 'between' ? [f.rule.lo, f.rule.hi] : [f.rule.value];
|
|
757
|
-
const { aiProposal: _drop, ...rest } = f;
|
|
758
|
-
if (own(bounds)) return rest;
|
|
759
|
-
if (ranges.length === 1 && proposed.length === 1 && proposed[0] === f) {
|
|
760
|
-
const m = /** @type {RegExpExecArray} */ (ranges[0]);
|
|
761
|
-
return { ...rest, rule: { op: 'between', lo: m[1], hi: m[2] } };
|
|
762
|
-
}
|
|
763
|
-
return f;
|
|
764
|
-
});
|
|
765
|
-
const parts = st.params.parts.map((/** @type {any} */ x) => (x === fp ? { ...x, facts } : x));
|
|
766
|
-
return { ...st, params: { ...st.params, parts } };
|
|
767
|
-
});
|
|
768
|
-
const carried = (/** @type {number} */ line, /** @type {number} */ n) => stages.some((/** @type {any} */ st) => isRec(st) && st.kind === 'rubric-step' && isRec(st.params) && st.params.step === line
|
|
769
|
-
&& Array.isArray(st.params.parts) && st.params.parts.some((/** @type {any} */ x) => isRec(x) && Array.isArray(x.rules) && x.rules.includes(n)));
|
|
770
|
-
/** @type {any} */
|
|
771
|
-
const out = { ...declaration, stages };
|
|
772
|
-
if (Array.isArray(declaration.refused)) out.refused = declaration.refused.filter((/** @type {any} */ r) => !(isRec(r) && Number.isInteger(r.line) && Number.isInteger(r.rule) && carried(r.line, r.rule)));
|
|
773
|
-
return out;
|
|
793
|
+
export const NEGATING_RE = /\b(?:not|no|never|outside|except|before|after|without)\b/i;
|
|
794
|
+
|
|
795
|
+
// The limit reader (hamr ruling A, 2026-11-12): when the look tied a money or time fact to a `~` rule but gave no limit, CODE reads the limit
|
|
796
|
+
// from the person's own rule words. ONE amount or ONE range only; every other text is a plain reason (Not checked), never a wrong check.
|
|
797
|
+
// The direction words are the FACT_OPS words of src/facts.js (lt under, lte at most, gt over, gte at least) plus their plain synonyms.
|
|
798
|
+
const AMOUNT = '(?:[$\\u20ac\\u00a3]\\s?(\\d[\\d,]*(?:\\.\\d+)?)|(\\d[\\d,]*(?:\\.\\d+)?)\\s?(?:US\\s)?(?:dollars?|euros?|pounds?|USD|EUR|GBP)\\b)';
|
|
799
|
+
const AMOUNT_ALL_RE = new RegExp(AMOUNT, 'gi');
|
|
800
|
+
const MONEY_BETWEEN_RE = new RegExp(`\\bbetween\\s+${AMOUNT}\\s+(?:and|to|-)\\s+${AMOUNT}`, 'i');
|
|
801
|
+
const MONEY_DIRECTION_RE = new RegExp(`\\b(under|below|less than|fewer than|at most|up to|no more than|over|above|more than|at least|no less than|no fewer than)\\s+${AMOUNT}`, 'i');
|
|
802
|
+
const MONEY_OR_LESS_RE = new RegExp(`${AMOUNT}\\s+or\\s+(less|fewer|under|below|lower|more|over|above|higher)\\b`, 'i');
|
|
803
|
+
const DIRECTION_OP = /** @type {Record<string, 'lt'|'lte'|'gt'|'gte'>} */ ({ under: 'lt', below: 'lt', 'less than': 'lt', 'fewer than': 'lt', 'at most': 'lte', 'up to': 'lte', 'no more than': 'lte', over: 'gt', above: 'gt', 'more than': 'gt', 'at least': 'gte', 'no less than': 'gte', 'no fewer than': 'gte' });
|
|
804
|
+
const CURRENCY_STEM = /** @type {Record<string, string>} */ ({ $: 'dollar', '€': 'euro', '£': 'pound', usd: 'dollar', eur: 'euro', gbp: 'pound' });
|
|
805
|
+
const num = (/** @type {string|undefined} */ a, /** @type {string|undefined} */ b) => Number(String(a ?? b).replace(/,/g, ''));
|
|
806
|
+
const hhmm = (/** @type {string} */ t) => (/[AaPp][Mm]/.test(t) ? null : t.replace(/\s+/g, '').replace(/^(\d):/, '0$1:'));
|
|
807
|
+
|
|
808
|
+
/** does the amount token's currency (sign or word) fit the look fact's currency and unit lists? A fact with neither list fits anything. */
|
|
809
|
+
function currencyFits(/** @type {string} */ tok, /** @type {any} */ fact) {
|
|
810
|
+
const cur = (Array.isArray(fact?.currency) ? fact.currency : fact?.currency ? [fact.currency] : []).map(String);
|
|
811
|
+
const unit = (Array.isArray(fact?.unit) ? fact.unit : fact?.unit ? [fact.unit] : []).map((/** @type {unknown} */ u) => String(u).toLowerCase());
|
|
812
|
+
if (!cur.length && !unit.length) return true;
|
|
813
|
+
const sym = /^[$€£]/.test(tok) ? tok.charAt(0) : null;
|
|
814
|
+
const last = String(tok.trim().split(/\s+/).at(-1)).toLowerCase();
|
|
815
|
+
const stem = sym ? CURRENCY_STEM[sym] : (CURRENCY_STEM[last] ?? last.replace(/s$/, ''));
|
|
816
|
+
return (sym !== null && cur.includes(sym)) || unit.some((/** @type {string} */ u) => u.includes(String(stem)));
|
|
774
817
|
}
|
|
775
818
|
|
|
776
819
|
/**
|
|
777
|
-
*
|
|
778
|
-
*
|
|
779
|
-
*
|
|
780
|
-
* @param {any} declaration @returns {any}
|
|
820
|
+
* Does this rule text hold more than one amount (money) or more than one time range (time)? The ONE guard code's own limit read and an AI
|
|
821
|
+
* reading edit both use: "under $450 or over $900" is two limits, and one reading of it would be a wrong check.
|
|
822
|
+
* @param {string} shape @param {string} text @returns {boolean}
|
|
781
823
|
*/
|
|
782
|
-
export function
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
const
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
const
|
|
816
|
-
if (
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
}
|
|
821
|
-
const text = dropLine(row, jobLines, lineRules);
|
|
822
|
-
if (!notes.includes(text)) notes.push(text);
|
|
824
|
+
export function holdsManyBounds(shape, text) {
|
|
825
|
+
const t = String(text ?? '');
|
|
826
|
+
if (shape === 'time') return [...t.matchAll(new RegExp(TIME_RANGE_RE.source, 'gi'))].length > 1 || (t.match(/\d{1,2}:\d{2}/g) ?? []).length > 2;
|
|
827
|
+
if (shape === 'money') { const amts = [...t.matchAll(AMOUNT_ALL_RE)]; return amts.length > 1 && !(MONEY_BETWEEN_RE.test(t) && amts.length === 2); }
|
|
828
|
+
return false;
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
/**
|
|
832
|
+
* The limit the person's own words give a fact of this shape: `{reading}` or `{why}` (a plain reason; the rule then stays Not checked).
|
|
833
|
+
* @param {string} shape money or time @param {string} text the `~` rule's words @param {any} [fact] the look fact (its currency and unit lists must fit)
|
|
834
|
+
* @returns {{reading: {op: 'lt'|'lte'|'gt'|'gte', value: number} | {op: 'between', lo: number|string, hi: number|string}} | {why: string}}
|
|
835
|
+
*/
|
|
836
|
+
export function readLimit(shape, text, fact = {}) {
|
|
837
|
+
const t = String(text ?? '');
|
|
838
|
+
if (shape === 'time') {
|
|
839
|
+
if (NEGATING_RE.test(t)) return { why: 'a one-sided or negated time (before, after, not) is not a range code can read' };
|
|
840
|
+
if (/\b\d{1,2}(?::\d{2})?\s?[ap]\.?m\b/i.test(t)) return { why: 'a 12-hour time (am or pm) is not read, write it like 06:00' };
|
|
841
|
+
if (holdsManyBounds('time', t)) return { why: 'more than one time range in the rule' };
|
|
842
|
+
const m = TIME_RANGE_RE.exec(t);
|
|
843
|
+
if (!m) return { why: 'no range between two times in the rule' };
|
|
844
|
+
const lo = hhmm(String(m[1])), hi = hhmm(String(m[2]));
|
|
845
|
+
if (!lo || !hi) return { why: 'a 12-hour time (am or pm) is not read, write it like 06:00' };
|
|
846
|
+
if (lo >= hi) return { why: 'a range whose end is not after its start is not read' };
|
|
847
|
+
return { reading: { op: 'between', lo, hi } };
|
|
848
|
+
}
|
|
849
|
+
if (shape === 'money') {
|
|
850
|
+
if (/\b(?:not|never|outside|except|without)\b/i.test(t)) return { why: 'a negated limit (not, except, without) is not read' };
|
|
851
|
+
const amts = [...t.matchAll(AMOUNT_ALL_RE)];
|
|
852
|
+
if (!amts.length) return { why: 'no amount with a currency sign or word in the rule' };
|
|
853
|
+
for (const a of amts) if (!currencyFits(a[0], fact)) return { why: 'the amount is in another currency than the page fact' };
|
|
854
|
+
if (holdsManyBounds('money', t)) return { why: 'more than one amount in the rule' };
|
|
855
|
+
const b = MONEY_BETWEEN_RE.exec(t);
|
|
856
|
+
if (b) { const lo = num(b[1], b[2]), hi = num(b[3], b[4]); return lo < hi ? { reading: { op: 'between', lo, hi } } : { why: 'a range whose end is not above its start is not read' }; }
|
|
857
|
+
const d = MONEY_DIRECTION_RE.exec(t);
|
|
858
|
+
if (d) return { reading: { op: /** @type {'lt'|'lte'|'gt'|'gte'} */ (DIRECTION_OP[String(d[1]).toLowerCase()]), value: num(d[2], d[3]) } };
|
|
859
|
+
const o = MONEY_OR_LESS_RE.exec(t);
|
|
860
|
+
if (o) return { reading: { op: /^(less|fewer|under|below|lower)$/i.test(String(o[3])) ? 'lte' : 'gte', value: num(o[1], o[2]) } };
|
|
861
|
+
return { why: 'the rule gives an amount but no direction (under, over, at most, at least, between)' };
|
|
823
862
|
}
|
|
824
|
-
return {
|
|
863
|
+
return { why: 'code reads a limit only for money or time' };
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
/** the words a list row of kind `$cited` / `$numbers` carries no text for */
|
|
867
|
+
const DEFAULT_ROW_WORDS = Object.freeze({ cited: 'every claim quotes its input', numbers: 'every number matches a quote' });
|
|
868
|
+
|
|
869
|
+
/**
|
|
870
|
+
* A check-list row named in the person's plain words: `phrase "### Fixed"`. The words are the draft log's; with none, the text after the key's kind prefix (`L1.phrase.### fixed`).
|
|
871
|
+
* Never empty. Pure.
|
|
872
|
+
* @param {unknown} kind @param {string} key @param {string[]|null|undefined} words
|
|
873
|
+
* @returns {string}
|
|
874
|
+
*/
|
|
875
|
+
export function listRowName(kind, key, words) {
|
|
876
|
+
const k = typeof kind === 'string' && kind ? kind : 'check';
|
|
877
|
+
if (k === 'cited' || k === 'numbers') return DEFAULT_ROW_WORDS[k];
|
|
878
|
+
const tail = key.replace(/^L\d+\.(?:[^.]*\.)?/, '').trim();
|
|
879
|
+
const w = Array.isArray(words) && words.length ? words : [tail || key];
|
|
880
|
+
return `${k} ${w.map((x) => `"${x}"`).join(', ')}`;
|
|
825
881
|
}
|
|
826
882
|
|
|
827
883
|
/**
|
|
828
884
|
* The ~ rules the drafter listed under Not checked (`refused` entries that name a `rule`), each as one line in the person's own
|
|
829
885
|
* words: `line N: "<the rule as written>" — <the drafter's reason>` (PART 1b, RF6 / RF16).
|
|
830
|
-
* @param {any} closeDecl @param {any[]|null|undefined} jobLines @returns {string[]}
|
|
886
|
+
* @param {any} closeDecl @param {any[]|null|undefined} jobLines @param {{key: string, words: string[]}[]|null} [ledger] the draft log's final list rows (`readDraftLedger`) @returns {string[]}
|
|
831
887
|
*/
|
|
832
|
-
export function ruleNotChecked(closeDecl, jobLines) {
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
888
|
+
export function ruleNotChecked(closeDecl, jobLines, ledger = null) {
|
|
889
|
+
return ruleNotCheckedItems(closeDecl, jobLines, ledger).map((i) => i.text);
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
/** the same lines as {@link ruleNotChecked}, each with who it belongs to (`by`: the row's kind, F-c) @param {any} closeDecl @param {any[]|null|undefined} jobLines @param {{key: string, words: string[]}[]|null} [ledger] @returns {{text: string, by?: 'you'|'agent'|'default'}[]} */
|
|
893
|
+
export function ruleNotCheckedItems(closeDecl, jobLines, ledger = null) {
|
|
894
|
+
return refusedOf(closeDecl).filter((r) => Number.isInteger(r.rule) || r.fromList).map((r) => {
|
|
895
|
+
const text = Number.isInteger(r.rule) ? lineRules((jobLines ?? []).find((/** @type {any} */ l) => isRec(l) && l.n === r.line))[/** @type {number} */ (r.rule) - 1] : (r.label ?? null);
|
|
896
|
+
const by = r.by ? { by: r.by } : {};
|
|
897
|
+
// a list row that is not a fact or a rule is named by its words, as the Job tab names it (one owner: listRowName)
|
|
898
|
+
if (!text && r.fromList && r.key) return { text: `line ${r.line}: ${listRowName(r.kind, r.key, ledger?.find((x) => x.key === r.key)?.words)} — ${r.reason}`, ...by };
|
|
899
|
+
return { text: `line ${r.line}: ${text ? `"${text}"` : `rule ${r.rule ?? r.kind}`} — ${r.reason}`, ...by };
|
|
837
900
|
});
|
|
838
901
|
}
|
|
839
902
|
|
|
903
|
+
/**
|
|
904
|
+
* The refusals of a signed close, as ONE reader: when the close carries the one check list (`closeDecl.list`) its not-checked rows are the refusals (a `~` rule's row names the rule, a fact row its
|
|
905
|
+
* fact name); the old `closeDecl.refused` entries a list has no row for (a line-level refusal, a rule the list never saw) are kept, so nothing the older close said is lost. A close with no list
|
|
906
|
+
* reads `refused` alone. Pure.
|
|
907
|
+
* @param {any} closeDecl
|
|
908
|
+
* @returns {{line: number, rule?: number, kind?: string, key?: string, by?: 'you'|'agent'|'default', label?: string, reason: string, fromList: boolean}[]}
|
|
909
|
+
*/
|
|
910
|
+
export function refusedOf(closeDecl) {
|
|
911
|
+
const old = (isRec(closeDecl) && Array.isArray(closeDecl.refused) ? closeDecl.refused : []).filter((/** @type {any} */ r) => isRec(r) && Number.isInteger(r.line) && typeof r.reason === 'string');
|
|
912
|
+
const list = isRec(closeDecl) && Array.isArray(closeDecl.list) ? closeDecl.list : null;
|
|
913
|
+
if (list === null) return old.map((/** @type {any} */ r) => ({ line: r.line, ...(Number.isInteger(r.rule) ? { rule: r.rule } : {}), reason: r.reason, fromList: false }));
|
|
914
|
+
const rows = list.filter((/** @type {any} */ r) => isRec(r) && r.state === 'not-checked' && Number.isInteger(r.line) && typeof r.reason === 'string' && r.kind !== 'floor').map((/** @type {any} */ r) => ({
|
|
915
|
+
line: r.line, ...(Number.isInteger(r.rule) ? { rule: r.rule } : {}), kind: String(r.kind), key: String(r.key), ...(['you', 'agent', 'default'].includes(r.by) ? { by: r.by } : {}), ...(r.kind === 'fact' ? { label: String(r.key).split('.').slice(2).join('.') } : {}), reason: r.reason, fromList: true,
|
|
916
|
+
}));
|
|
917
|
+
const seen = (/** @type {any} */ r) => rows.some((x) => x.line === r.line && x.rule === (Number.isInteger(r.rule) ? r.rule : undefined) && Number.isInteger(r.rule));
|
|
918
|
+
return [...rows, ...old.filter((/** @type {any} */ r) => !seen(r)).map((/** @type {any} */ r) => ({ line: r.line, ...(Number.isInteger(r.rule) ? { rule: r.rule } : {}), reason: r.reason, fromList: false }))];
|
|
919
|
+
}
|
|
920
|
+
|
|
840
921
|
/**
|
|
841
922
|
* The Not-checked lines code owns for the rubric-step stages of a close: a prose step's CONTENT is judged by the person at
|
|
842
923
|
* Accept, and the card says so (PART 1b, RF5). One line per prose step (a stage with no fact part).
|
|
@@ -869,6 +950,13 @@ export function partSentence(part) {
|
|
|
869
950
|
case 'maxLines': return `the text is at most ${n(part.value, 'line')}`;
|
|
870
951
|
case 'sections': return `the text has the section(s): ${list(part.names)}`;
|
|
871
952
|
case 'sectionWords': return `each section (${list(part.names)}) is about ${part.wordsPerSection} words`;
|
|
953
|
+
case 'nonEmpty': return 'the text is not empty';
|
|
954
|
+
case 'listItems': return `the text has exactly ${n(part.value, 'list item')}`;
|
|
955
|
+
case 'maxListItems': return `the text has at most ${n(part.value, 'list item')}`;
|
|
956
|
+
case 'minListItems': return `the text has at least ${n(part.value, 'list item')}`;
|
|
957
|
+
case 'sectionOrder': return `the text has the section(s) ${list(part.names)}, in that order`;
|
|
958
|
+
case 'mustCarry': return `the text carries ${list(part.phrases)}`;
|
|
959
|
+
case 'blockLines': return `the text is in blocks of ${n(part.size, 'line')}, each carrying ${list(part.phrases)}`;
|
|
872
960
|
case 'cited': return `every claim is backed by a quote copied from "${part.source}"`;
|
|
873
961
|
case 'minClaims': return `at least ${part.value} claim(s) are listed under "${part.source}"`;
|
|
874
962
|
case 'maxClaims': return `at most ${part.value} claim(s) are listed under "${part.source}"`;
|
|
@@ -877,19 +965,43 @@ export function partSentence(part) {
|
|
|
877
965
|
}
|
|
878
966
|
}
|
|
879
967
|
|
|
968
|
+
/** the words of the default cited check code adds to a text line of a one-input job (the one list's `$` row); the card reads a part with exactly these words as `[default]` @param {string} label @returns {string} */
|
|
969
|
+
export const defaultCitedText = (label) => `every claim is backed by a quote copied from "${label}"`;
|
|
970
|
+
|
|
880
971
|
/**
|
|
881
972
|
* The checks a signed close actually runs, per job line, in plain code-written sentences: one per countable part of every
|
|
882
973
|
* rubric-step stage. This is the ONE reader both the plan card and the sign-time invariant use.
|
|
974
|
+
* Each row says who added the check (`by`): `you` = one of the person's picks, as the signed close's own record (`closeDecl.picks`) names it; `agent` = the drafter's;
|
|
975
|
+
* `default` = code's own (the one list's `$` rows: the cited part written by `defaultCitedText`, and the numbers tie of a text step).
|
|
883
976
|
* @param {any} closeDecl
|
|
884
|
-
* @returns {{line: number, text: string,
|
|
977
|
+
* @returns {{line: number, text: string, by: 'agent'|'you'|'default', key?: string}[]}
|
|
885
978
|
*/
|
|
886
979
|
export function checksOfClose(closeDecl) {
|
|
887
980
|
const stages = isRec(closeDecl) && Array.isArray(closeDecl.stages) ? closeDecl.stages : [];
|
|
981
|
+
const record = isRec(closeDecl) && Array.isArray(closeDecl.picks) ? closeDecl.picks : [];
|
|
982
|
+
const list = isRec(closeDecl) && Array.isArray(closeDecl.list) ? closeDecl.list.filter((/** @type {any} */ r) => isRec(r) && r.state === 'built') : [];
|
|
983
|
+
/** the tag of a fact by its row's kind (hamr 2026-11-13, F-c): a fact a `~` rule built is [you], a `!` row's [agent]; `facts` on the signed row names what it built. No such row (an older close): the old reading */
|
|
984
|
+
const factBy = (/** @type {number} */ line, /** @type {string} */ name) => {
|
|
985
|
+
const rows = list.filter((/** @type {any} */ r) => r.line === line && Array.isArray(r.facts) && r.facts.includes(name));
|
|
986
|
+
const r = rows.find((/** @type {any} */ x) => x.by === 'you') ?? rows[0];
|
|
987
|
+
return r ? { by: /** @type {'agent'|'you'|'default'} */ (r.by), key: String(r.key) } : null;
|
|
988
|
+
};
|
|
989
|
+
const countBy = (/** @type {number} */ line, /** @type {number} */ pi) => {
|
|
990
|
+
const r = list.find((/** @type {any} */ x) => x.line === line && x.kind === 'count' && isRec(x.part) && x.part.part === pi);
|
|
991
|
+
return r ? { by: /** @type {'agent'|'you'|'default'} */ (r.by), key: String(r.key) } : null;
|
|
992
|
+
};
|
|
888
993
|
return stages.flatMap((/** @type {any} */ st) => (isRec(st) && st.kind === 'rubric-step' && isRec(st.params) && Array.isArray(st.params.parts)
|
|
889
|
-
? st.params.parts.
|
|
890
|
-
|
|
994
|
+
? st.params.parts.flatMap((/** @type {any} */ p, /** @type {number} */ pi) => {
|
|
995
|
+
if (!isRec(p) || (p.class !== 'countable' && p.class !== 'fact')) return [];
|
|
996
|
+
/** @type {'agent'|'you'|'default'} */
|
|
997
|
+
const by = p.check === 'numbersFromFacts' || (p.check === 'cited' && p.text === defaultCitedText(p.source)) ? 'default' : record.some((/** @type {any} */ x) => isRec(x) && x.line === st.params.step && sameJson(x.part, p)) ? 'you' : 'agent';
|
|
891
998
|
// a fact part is one plan row per fact (and one for its count): the person signs the rows, the close runs the same list
|
|
892
|
-
|
|
999
|
+
if (p.class !== 'fact') return [{ line: st.params.step, text: partSentence(p), by }];
|
|
1000
|
+
const facts = Array.isArray(p.facts) ? p.facts : [];
|
|
1001
|
+
return factRows(p).map((/** @type {string} */ text, /** @type {number} */ i) => {
|
|
1002
|
+
const own = i < facts.length ? factBy(st.params.step, facts[i]?.name) : countBy(st.params.step, pi);
|
|
1003
|
+
return { line: st.params.step, text, by: own?.by ?? by, ...(own ? { key: own.key } : {}) };
|
|
1004
|
+
});
|
|
893
1005
|
})
|
|
894
1006
|
: []));
|
|
895
1007
|
}
|
|
@@ -906,30 +1018,51 @@ export function signedFactNames(closeDecl) {
|
|
|
906
1018
|
}
|
|
907
1019
|
|
|
908
1020
|
/**
|
|
909
|
-
*
|
|
910
|
-
*
|
|
911
|
-
*
|
|
912
|
-
*
|
|
913
|
-
* @
|
|
914
|
-
* `jobLines` — the person's numbered lines, so a ~ rule the drafter listed as Not checked reads in the person's own words
|
|
915
|
-
* @returns {{checkItems: {text: string, fromLine: number[]}[], notChecked: string[], moved: {text: string, fromLine: number[]|null}[]}}
|
|
1021
|
+
* The plan card after drafting, read from the signed close ALONE (one source, the same the Job tab reads): its checks are `checksOfClose`; its Not checked is the close's own notes, the prose
|
|
1022
|
+
* steps' "you judge it at Accept" lines and the refusals (`ruleNotChecked`, which reads the list's not-checked rows when the close carries the list). Nothing the confirm turn said is merged
|
|
1023
|
+
* in: a rubric confirm turn plans the goal only, so a check can never be shown and then silently dropped (run mv5bk400).
|
|
1024
|
+
* @param {{closeDecl: any, jobLines?: any[]|null, ledger?: {key: string, words: string[]}[]|null}} o `jobLines` the person's numbered lines, so a ~ rule reads in the person's own words; `ledger` the draft log's final list rows, so a phrase row is named by its words
|
|
1025
|
+
* @returns {{checkItems: {text: string, fromLine: number[], by: 'agent'|'you'|'default', key?: string}[], notChecked: string[], notCheckedBy: Record<string, 'you'|'agent'|'default'>}}
|
|
916
1026
|
*/
|
|
917
|
-
export function
|
|
918
|
-
const
|
|
919
|
-
const
|
|
920
|
-
|
|
1027
|
+
export function cardOfClose({ closeDecl, jobLines = null, ledger = null }) {
|
|
1028
|
+
const notes = isRec(closeDecl) && Array.isArray(closeDecl.notes) ? closeDecl.notes.filter((/** @type {any} */ n) => typeof n === 'string' && n) : [];
|
|
1029
|
+
const items = ruleNotCheckedItems(closeDecl, jobLines, ledger);
|
|
1030
|
+
/** @type {Record<string, 'you'|'agent'|'default'>} */
|
|
1031
|
+
const notCheckedBy = {};
|
|
1032
|
+
for (const i of items) if (i.by) notCheckedBy[i.text] = i.by;
|
|
921
1033
|
return {
|
|
922
|
-
checkItems:
|
|
923
|
-
notChecked: [
|
|
924
|
-
|
|
925
|
-
...proseNotChecked(closeDecl),
|
|
926
|
-
...ruleNotChecked(closeDecl, jobLines),
|
|
927
|
-
...moved.map((m) => `${m.fromLine && m.fromLine.length ? `line ${m.fromLine.join(', ')}: ` : ''}${m.text} — nothing in this close counts it or checks it against a quote`),
|
|
928
|
-
],
|
|
929
|
-
moved,
|
|
1034
|
+
checkItems: checksOfClose(closeDecl).map((c) => ({ text: c.text, fromLine: [c.line], by: c.by, ...(c.key ? { key: c.key } : {}) })),
|
|
1035
|
+
notChecked: [...new Set([...notes, ...proseNotChecked(closeDecl), ...items.map((i) => i.text)])],
|
|
1036
|
+
notCheckedBy,
|
|
930
1037
|
};
|
|
931
1038
|
}
|
|
932
1039
|
|
|
1040
|
+
/**
|
|
1041
|
+
* The sign-time check of a close that carries the one check list: every BUILT row (the mechanical floor aside) points at a part that is really in the close, and every real check part
|
|
1042
|
+
* (countable or fact) has at least one built row pointing at it, so a check cannot be in the close with no row and a row cannot claim a check the close does not run. A close with no list is
|
|
1043
|
+
* not examined here. Pure.
|
|
1044
|
+
* @param {any} closeDecl @returns {{ok: true}|{ok: false, error: string}}
|
|
1045
|
+
*/
|
|
1046
|
+
export function listMatchesClose(closeDecl) {
|
|
1047
|
+
const list = isRec(closeDecl) && Array.isArray(closeDecl.list) ? closeDecl.list : null;
|
|
1048
|
+
if (list === null) return { ok: true };
|
|
1049
|
+
const stages = Array.isArray(closeDecl.stages) ? closeDecl.stages : [];
|
|
1050
|
+
const partsOn = (/** @type {number} */ n) => stages.filter((/** @type {any} */ st) => isRec(st) && st.kind === 'rubric-step' && isRec(st.params) && st.params.step === n && Array.isArray(st.params.parts)).flatMap((/** @type {any} */ st) => st.params.parts);
|
|
1051
|
+
const built = list.filter((/** @type {any} */ r) => isRec(r) && r.state === 'built' && r.kind !== 'floor');
|
|
1052
|
+
const bad = built.filter((/** @type {any} */ r) => !(isRec(r.part) && r.part.line === r.line && Number.isInteger(r.part.part) && isRec(partsOn(r.line)[r.part.part])));
|
|
1053
|
+
const lines = [...new Set(stages.filter((/** @type {any} */ st) => isRec(st) && st.kind === 'rubric-step' && isRec(st.params)).map((/** @type {any} */ st) => st.params.step))];
|
|
1054
|
+
const bare = lines.flatMap((/** @type {number} */ n) => partsOn(n).map((/** @type {any} */ p, /** @type {number} */ i) => ({ n, i, p })))
|
|
1055
|
+
.filter(({ p }) => isRec(p) && (p.class === 'countable' || p.class === 'fact'))
|
|
1056
|
+
// a part has its row when a built row points at it, or when the part lists (in its `rules`) the number of a built `~` row of its line (a row points at ONE part, a rule may be carried by several)
|
|
1057
|
+
.filter(({ n, i, p }) => !built.some((/** @type {any} */ r) => (isRec(r.part) && r.part.line === n && r.part.part === i)
|
|
1058
|
+
|| (r.kind === 'rule' && r.line === n && Array.isArray(p.rules) && p.rules.includes(r.rule))));
|
|
1059
|
+
if (bad.length === 0 && bare.length === 0) return { ok: true };
|
|
1060
|
+
const parts = [];
|
|
1061
|
+
if (bad.length) parts.push(`a row points at a check the close does not run: ${bad.map((/** @type {any} */ r) => r.key).join('; ')}`);
|
|
1062
|
+
if (bare.length) parts.push(`a check in the close has no row: line ${bare.map(({ n, i }) => `${n} part ${i + 1}`).join('; ')}`);
|
|
1063
|
+
return { ok: false, error: `The list of checks does not match the signed close (${parts.join(' | ')}). Nothing was signed — draft again.` };
|
|
1064
|
+
}
|
|
1065
|
+
|
|
933
1066
|
/**
|
|
934
1067
|
* The sign-time invariant: the checks the person was shown (`shown`, from the plan card) are exactly the checks the signed
|
|
935
1068
|
* close runs (`checksOfClose`), per line. Pure.
|