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
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// borrowed-from: bareloop src/shaperesult.js@v0.61.0 (fc56e1f3)
|
|
2
|
+
// SHAPE JOBS (itemShape), the signed mock design/shape-views-mock.html (hamr 2026-11-18): the ONE view-model of a shape line's answer, read by the Result tab's grid (src/panel/server.js -> src/panel/index.html) and the
|
|
3
|
+
// .md report (src/resultmd.js), so the grid and the report say the same thing. Items are rows, the signed fields are columns; a cell is a mark and a short value; the errors are the plain item reds. Pure.
|
|
4
|
+
// cell value: the item's own value (clipped, yes/no for a boolean, a list's entries joined), then the bound's words in brackets when the person bounded the field (`Ada (2 words)`, `a, b (2 entries)`). A red `#<i>:<path>:<reason>` (bareguard's, names and counts only) marks the cell of its field; a red with no field (`item-not-object`) marks the whole row.
|
|
5
|
+
// The words of a red here name the worker's own value where the reason is a wrong value (`status is "done", not one of: ...`): the value comes from the delivered file, never from bareguard's gap.
|
|
6
|
+
import { upper, SHAPE_HEAD_PARTS, SHAPE_TRUTH_PARTS } from './shaperows.js';
|
|
7
|
+
import { parseShapeItem, itemFieldOf, plainShapeItem } from './shapewords.js';
|
|
8
|
+
|
|
9
|
+
const isRec = (/** @type {unknown} */ v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
10
|
+
const clip = (/** @type {string} */ t, n = 40) => (t.length > n ? `${t.slice(0, n - 1)}…` : t);
|
|
11
|
+
|
|
12
|
+
/** one scalar as written, whitespace folded @param {unknown} v @returns {string} */
|
|
13
|
+
const scalar = (v) => (typeof v === 'boolean' ? (v ? 'yes' : 'no') : typeof v === 'string' || typeof v === 'number' ? String(v).replace(/\s+/g, ' ').trim() : '');
|
|
14
|
+
|
|
15
|
+
/** the short value of one cell: the item's own value (clipped), then the bound's words in brackets where the field has one (`Ada (2 words)`, `a, b (2 entries)`) @param {Record<string, any>} spec @param {unknown} v @returns {string} */
|
|
16
|
+
function cellText(spec, v) {
|
|
17
|
+
if (v === undefined || v === null) return '';
|
|
18
|
+
const join = (/** @type {string} */ val, /** @type {string} */ extra) => (val && extra ? `${val} (${extra})` : val || extra);
|
|
19
|
+
switch (spec.kind) {
|
|
20
|
+
case 'text': {
|
|
21
|
+
if (typeof v !== 'string') return '';
|
|
22
|
+
const bounded = ['maxChars', 'minChars', 'maxWords', 'minWords'].some((k) => spec[k] !== undefined && !(k === 'minChars' && spec[k] === 1));
|
|
23
|
+
const extra = !bounded ? '' : spec.maxWords !== undefined || spec.minWords !== undefined ? ((n) => `${n} word${n === 1 ? '' : 's'}`)(v.trim() === '' ? 0 : v.trim().split(/\s+/).length) : `${[...v].length} chars`;
|
|
24
|
+
return join(clip(scalar(v)), extra);
|
|
25
|
+
}
|
|
26
|
+
case 'list': return Array.isArray(v) ? join(clip(v.map(scalar).filter((x) => x !== '').join(', ')), `${v.length} ${v.length === 1 ? 'entry' : 'entries'}`) : '';
|
|
27
|
+
default: return typeof v === 'object' ? '' : clip(scalar(v), 40);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* One item red in the Result tab's words: `item 3: status is "done", not one of: in progress, closed, finished`.
|
|
33
|
+
* @param {string} red `#<i>:<path>:<reason>` @param {Record<string, any>|null} field the signed field `{name, spec, rule?}` or null @param {unknown} value the worker's value @param {string} said the person's rule for the field
|
|
34
|
+
* @returns {string}
|
|
35
|
+
*/
|
|
36
|
+
export function shapeViewRed(red, field, value, said) {
|
|
37
|
+
const p = parseShapeItem(red);
|
|
38
|
+
if (p === null || p.path === null || field === null) return plainShapeItem(red);
|
|
39
|
+
const at = `item ${p.i + 1}: ${field.name}`;
|
|
40
|
+
const r = p.reason;
|
|
41
|
+
const w = /^(too-short|too-long):(chars|words):(\d+)([<>])(\d+)$/.exec(r);
|
|
42
|
+
if (w) {
|
|
43
|
+
const unit = w[2] === 'chars' ? 'characters' : 'words';
|
|
44
|
+
if (w[1] === 'too-short' && w[2] === 'chars' && w[5] === '1') return `${at} is empty`;
|
|
45
|
+
return w[1] === 'too-long' ? `${at} is too long (${w[3]} ${unit}, ${upper(Number(w[5]), '', said)})` : `${at} is too short (${w[3]} ${unit}, at least ${w[5]})`;
|
|
46
|
+
}
|
|
47
|
+
if (r === 'not-one-of') return `${at} is ${typeof value === 'string' ? `"${clip(value)}"` : 'not a word'}, not one of: ${(Array.isArray(field.spec.values) ? field.spec.values : []).join(', ')}`;
|
|
48
|
+
if (r === 'missing') return `${at} is missing`;
|
|
49
|
+
if (r === 'wrong-value') return `${at} is ${typeof value === 'boolean' ? (value ? 'yes' : 'no') : 'not what the job asks for'}, not ${field.spec.equals === true ? 'yes' : 'no'}`;
|
|
50
|
+
return plainShapeItem(red).replace(/^item (\d+): "([^"]*)"/, (_m, n, f) => `item ${n}: ${f}`);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The model of a shape line's answer.
|
|
55
|
+
* @param {{part: any, results: unknown, reds?: string[], rules?: string[]}} o `part` the signed shape part; `results` the answer's `results` list; `reds` the item reds the close recorded (`#<i>:<path>:<reason>`, none for a green run); `rules` the line's `~` rules
|
|
56
|
+
* @returns {{columns: {name: string}[], rows: {name: string, cells: {mark: 'g'|'r', text: string, why?: string}[]}[], total: number, passed: number, failed: number, errors: string[], notChecked: string, head: string}}
|
|
57
|
+
*/
|
|
58
|
+
export function shapeResultModel({ part, results, reds = [], rules = [] }) {
|
|
59
|
+
const fields = (Array.isArray(part?.fields) ? part.fields : []).filter(isRec);
|
|
60
|
+
const items = Array.isArray(results) ? results : [];
|
|
61
|
+
const said = (/** @type {any} */ f) => (Number.isInteger(f.rule) ? rules[f.rule - 1] ?? '' : '');
|
|
62
|
+
const first = fields.find((f) => f.spec?.kind === 'text');
|
|
63
|
+
const redsBy = (/** @type {number} */ i) => reds.filter((x) => parseShapeItem(x)?.i === i);
|
|
64
|
+
/** @type {string[]} */
|
|
65
|
+
const errors = [];
|
|
66
|
+
const rows = items.map((it, i) => {
|
|
67
|
+
const mine = redsBy(i);
|
|
68
|
+
const whole = mine.some((x) => itemFieldOf(x) === null && !String(x).includes(':unknown-field:'));
|
|
69
|
+
const val = (/** @type {string} */ n) => (isRec(it) ? it[n] : undefined);
|
|
70
|
+
const title = first !== undefined && typeof val(first.name) === 'string' && String(val(first.name)).trim() !== '' ? ` · ${clip(String(val(first.name)).trim())}` : '';
|
|
71
|
+
/** @type {Record<string, string>} */
|
|
72
|
+
const why = {};
|
|
73
|
+
for (const x of mine) { const nm = itemFieldOf(x); const f = fields.find((y) => y.name === nm) ?? null; const e = shapeViewRed(x, f, f ? val(f.name) : undefined, f ? said(f) : ''); errors.push(e); if (f) why[f.name] = e.replace(`item ${i + 1}: ${f.name} `, ''); }
|
|
74
|
+
const cells = fields.map((f) => {
|
|
75
|
+
const bad = whole || mine.some((x) => itemFieldOf(x) === f.name);
|
|
76
|
+
return { mark: /** @type {'g'|'r'} */ (bad ? 'r' : 'g'), text: cellText(f.spec, val(f.name)), ...(why[f.name] !== undefined ? { why: why[f.name] } : {}) };
|
|
77
|
+
});
|
|
78
|
+
return { name: `${i + 1}${title}`, cells };
|
|
79
|
+
});
|
|
80
|
+
const failed = rows.filter((r) => r.cells.some((c) => c.mark === 'r')).length;
|
|
81
|
+
return {
|
|
82
|
+
columns: fields.map((f) => ({ name: String(f.name) })), rows, total: rows.length, passed: rows.length - failed, failed, errors,
|
|
83
|
+
notChecked: SHAPE_TRUTH_PARTS.join(' — '), head: SHAPE_HEAD_PARTS.join(' · '),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** a markdown table cell: pipes and line breaks made safe @param {string} t */
|
|
88
|
+
const md = (t) => t.replace(/\|/g, '\\|').replace(/\s*\n\s*/g, ' ');
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The shape section of the .md report (the signed mock D): the shape-checks line, a table (items as rows, fields as columns, a mark and the short value in each cell), the Not checked line and, when any item failed, a Failed list.
|
|
92
|
+
* @param {ReturnType<typeof shapeResultModel>} m @returns {string}
|
|
93
|
+
*/
|
|
94
|
+
export function shapeMarkdown(m) {
|
|
95
|
+
const cols = m.columns.map((c) => c.name);
|
|
96
|
+
const lines = [
|
|
97
|
+
`${SHAPE_HEAD_PARTS[0]} (${SHAPE_HEAD_PARTS[1]})`, '',
|
|
98
|
+
`| item | ${cols.join(' | ')} |`, `| --- |${cols.map(() => ' --- |').join('')}`,
|
|
99
|
+
...m.rows.map((r) => `| ${md(r.name)} | ${r.cells.map((c) => md(`${c.mark === 'g' ? '✓' : '✗'}${c.text ? ` ${c.text}` : ''}`)).join(' | ')} |`),
|
|
100
|
+
'', `Not checked: ${SHAPE_TRUTH_PARTS[0]} (${SHAPE_TRUTH_PARTS[1]})`,
|
|
101
|
+
...(m.errors.length ? ['', '### Failed', '', ...m.errors.map((e) => `- ${e}`)] : []),
|
|
102
|
+
];
|
|
103
|
+
return lines.join('\n');
|
|
104
|
+
}
|
package/src/shaperows.js
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
// borrowed-from: bareloop src/shaperows.js@v0.61.0 (fc56e1f3)
|
|
2
|
+
// SHAPE JOBS (itemShape), docs/product/ITEM33-BUILD.md "Addendum 2026-11-18: shape jobs", clause 8 "Views" (and the rows' words of clause 4): the WORDS of the shape rows of the one list and the pure readers of a signed close's shape part.
|
|
3
|
+
// Modelled on src/sheetrows.js. The ROWS themselves live in the one owner, src/checkblock.js (`setShape`, `rowChoice`); this file only names them and reads them back, so the confirm card, the signed card, the Job tab, the
|
|
4
|
+
// Result tab and the report say the same thing.
|
|
5
|
+
// THE PART (what the views read and what `rubricStepShapeReds`, `buildStepSpec` and `lineBriefs` sign, check and brief):
|
|
6
|
+
// { class: 'shape', text, fields: [{ name, spec: {kind, required?, ...bounds}, rule?: <the ~ rule number it comes from>, row?: 'agent' }], minItems?, maxItems?, rules?: [<rule numbers>] }
|
|
7
|
+
// Rows of one shape line: a `[you]` row per `~` rule that has a field (the rule's own row, kind `rule`), an `[agent]` row per extra field (kind `shape`, key `L<n>.shape.<name>`), and the line's `[default]` row (key
|
|
8
|
+
// `L<n>.$shape`): the answer is a list of items, with the item count when the person's words gave one.
|
|
9
|
+
import { createRubric, rubricVocabulary } from 'bareguard';
|
|
10
|
+
import { lineRules } from './pagebits.js';
|
|
11
|
+
import { nameWhy, shapeNameRules, SHAPE_KINDS } from './shapemenu.js';
|
|
12
|
+
import { countCheck } from './blockpick.js';
|
|
13
|
+
|
|
14
|
+
const isRec = (/** @type {unknown} */ v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
15
|
+
|
|
16
|
+
/** the key of an `[agent]` shape row and of a line's `[default]` shape row @param {number} line @param {string} name */
|
|
17
|
+
export const shapeRowKey = (line, name) => `L${line}.shape.${name}`;
|
|
18
|
+
/** @param {number} line */
|
|
19
|
+
export const shapeDefaultKey = (line) => `L${line}.$shape`;
|
|
20
|
+
|
|
21
|
+
/** the words of the `[default]` row of a shape line, drawn only when the person's words gave an item count (hamr 2026-11-18: the card's `$` row is the Not checked line): `exactly 2 items` @param {{min?: number, max?: number}|null} [count] @returns {string|null} */
|
|
22
|
+
export function shapeDefaultWords(count = null) {
|
|
23
|
+
if (count && Number.isInteger(count.min) && count.min === count.max) return `the answer lists exactly ${count.min} item${count.min === 1 ? '' : 's'}`;
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* M19 am11 item 1: the item count a `~` rule's own words ARE ("exactly 4 list items" -> 4 to 4, "at least 3" -> at least 3, "at most 5" -> at most 5), or null. "at most 0" is no item count (bareguard's `maxItems` is at least 1): it stays a pick over the text.
|
|
29
|
+
* @param {string} text @returns {{min?: number, max?: number}|null}
|
|
30
|
+
*/
|
|
31
|
+
export function itemCountOf(text) {
|
|
32
|
+
const c = /** @type {any} */ (countCheck(text));
|
|
33
|
+
if (!c) return null;
|
|
34
|
+
if (c.rule === 'listItems') return { min: c.value, max: c.value };
|
|
35
|
+
if (c.rule === 'minListItems') return { min: c.value };
|
|
36
|
+
if (c.rule === 'maxListItems' && c.value >= 1) return { max: c.value };
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* M19 am11: the words of the rule row that holds a signed item count (the `[default]` row's words, `the answer lists exactly N items`, for an exact count; `at least N items` / `at most N items` beside it). Pure.
|
|
42
|
+
* @param {{minItems?: number, maxItems?: number}} part @returns {string|null}
|
|
43
|
+
*/
|
|
44
|
+
export function shapeCountWords(part) {
|
|
45
|
+
const lo = Number.isInteger(part.minItems) ? /** @type {number} */ (part.minItems) : null;
|
|
46
|
+
const hi = Number.isInteger(part.maxItems) ? /** @type {number} */ (part.maxItems) : null;
|
|
47
|
+
const s = (/** @type {number} */ n) => `${n} item${n === 1 ? '' : 's'}`;
|
|
48
|
+
if (lo !== null && lo === hi) return shapeDefaultWords({ min: lo, max: lo });
|
|
49
|
+
const w = [...(lo !== null ? [`at least ${s(lo)}`] : []), ...(hi !== null ? [`at most ${s(hi)}`] : [])];
|
|
50
|
+
return w.length ? `the answer lists ${w.join(' and ')}` : null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** why the truth of a shape line's items is not checked: the person judges it at Accept (the Not checked row of every shape line) */
|
|
54
|
+
export const SHAPE_TRUTH_PARTS = Object.freeze(['whether each one is true', 'you judge it at Accept']);
|
|
55
|
+
export const SHAPE_TRUTH_WORDS = SHAPE_TRUTH_PARTS.join(' \u2014 ');
|
|
56
|
+
|
|
57
|
+
/** @param {unknown} v @returns {string} */
|
|
58
|
+
const q = (v) => (typeof v === 'string' ? `"${v}"` : String(v));
|
|
59
|
+
|
|
60
|
+
/** the words of a shape card's heading, once above a shape line's rows (code's, never the model's) */
|
|
61
|
+
export const SHAPE_HEAD_PARTS = Object.freeze(['Shape checks', "code checks each item's form, not whether it is true"]);
|
|
62
|
+
export const SHAPE_HEAD = SHAPE_HEAD_PARTS.join(' \u00B7 ');
|
|
63
|
+
|
|
64
|
+
/** an upper bound `n` as the person's own form: "under N unit" when their words say under/fewer than/less than/below N+1 (so the signed N is "under N+1"), else "at most N unit" @param {number} n @param {string} unit @param {string} said */
|
|
65
|
+
export function upper(n, unit, said) {
|
|
66
|
+
const u = unit ? ` ${unit}` : '';
|
|
67
|
+
return [...String(said).matchAll(/(?:under|fewer than|less than|below)\s+(\d+)\b/gi)].some((m) => m[1] === String(n + 1)) ? `under ${n + 1}${u}` : `at most ${n}${u}`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** one bound range as words: `at least 3`, `at most 10`, `over 3`, `under 10` @param {Record<string, any>} s @param {string} said @returns {string[]} */
|
|
71
|
+
function range(s, said) {
|
|
72
|
+
return [
|
|
73
|
+
...(s.min !== undefined ? [`at least ${q(s.min)}`] : []), ...(s.gt !== undefined ? [`over ${q(s.gt)}`] : []),
|
|
74
|
+
...(s.max !== undefined ? [typeof s.max === 'number' ? upper(s.max, '', said) : `at most ${q(s.max)}`] : []), ...(s.lt !== undefined ? [`under ${q(s.lt)}`] : []),
|
|
75
|
+
];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* A field spec as one plain sentence, written by code from the signed fields, in the person's own form where their words show it ("under 200 characters", not "at most 199"). Pure.
|
|
80
|
+
* @param {Record<string, any>} spec `{kind, required?, ...bounds}` @param {string} [said] the person's own rule for the field @returns {string}
|
|
81
|
+
*/
|
|
82
|
+
export function shapeFieldSentence(spec, said = '') {
|
|
83
|
+
const s = isRec(spec) ? spec : {};
|
|
84
|
+
/** @type {string} */
|
|
85
|
+
let out;
|
|
86
|
+
switch (s.kind) {
|
|
87
|
+
case 'text': {
|
|
88
|
+
const c = [
|
|
89
|
+
...(s.minChars === 1 ? ['not empty'] : s.minChars !== undefined ? [`at least ${s.minChars} characters`] : []), ...(s.maxChars !== undefined ? [upper(s.maxChars, 'characters', said)] : []),
|
|
90
|
+
...(s.minWords !== undefined ? [`at least ${s.minWords} words`] : []), ...(s.maxWords !== undefined ? [upper(s.maxWords, 'words', said)] : []),
|
|
91
|
+
];
|
|
92
|
+
out = c.length ? c.join(', ') : 'text';
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
case 'number': out = ['a number', ...range(s, said)].join(', '); break;
|
|
96
|
+
case 'money': out = ['an amount of money', ...range(s, said)].join(', '); break;
|
|
97
|
+
case 'date': out = ['a date', ...range(s, said)].join(', '); break;
|
|
98
|
+
case 'time': out = ['a time', ...range(s, said)].join(', '); break;
|
|
99
|
+
case 'url': out = 'a web address'; break;
|
|
100
|
+
case 'oneOf': out = `one of: ${(Array.isArray(s.values) ? s.values : []).join(', ')}`; break;
|
|
101
|
+
case 'boolean': out = s.equals === true ? 'yes' : s.equals === false ? 'no' : 'yes or no'; break;
|
|
102
|
+
case 'list': {
|
|
103
|
+
const c = [...(s.minEntries !== undefined ? [`at least ${s.minEntries} entries`] : []), ...(s.maxEntries !== undefined ? [upper(s.maxEntries, 'entries', said)] : []), ...(s.unique === true ? ['no repeats'] : [])];
|
|
104
|
+
out = [`a list of ${isRec(s.of) ? shapeFieldSentence(s.of, said) : 'values'}`, ...c].join(', ');
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
default: out = String(s.kind ?? 'a value');
|
|
108
|
+
}
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* The signed part of ONE shape line, from the fields that stand (the `[you]` rule fields and the `[agent]` fields the person has not dropped or left Suggested).
|
|
114
|
+
* @param {{text: string, fields: {name: string, spec: Record<string, any>, rule?: number|null, by?: 'you'|'agent'}[], itemCount?: {n?: number, min?: number, max?: number}|null, countRules?: number[]}} o `countRules` = the `~` rules whose words are the item count
|
|
115
|
+
* @returns {Record<string, any>}
|
|
116
|
+
*/
|
|
117
|
+
export function buildShapePart({ text, fields, itemCount = null, countRules = [] }) {
|
|
118
|
+
const rules = [...new Set([...fields.filter((f) => Number.isInteger(f.rule)).map((f) => /** @type {number} */ (f.rule)), ...countRules])].sort((a, b) => a - b);
|
|
119
|
+
// M19 am11: the count is `{n}` (code's per-input count: exactly n) or `{min?, max?}` (a `~` rule's own count: at least / at most)
|
|
120
|
+
const lo = itemCount === null ? null : Number.isInteger(itemCount.n) ? itemCount.n : Number.isInteger(itemCount.min) ? itemCount.min : null;
|
|
121
|
+
const hi = itemCount === null ? null : Number.isInteger(itemCount.n) ? itemCount.n : Number.isInteger(itemCount.max) ? itemCount.max : null;
|
|
122
|
+
return {
|
|
123
|
+
class: 'shape', text,
|
|
124
|
+
fields: fields.map((f) => ({ name: f.name, spec: f.spec, ...(Number.isInteger(f.rule) ? { rule: f.rule } : {}), ...(f.by === 'agent' ? { row: 'agent' } : {}) })),
|
|
125
|
+
...(lo !== null ? { minItems: lo } : {}), ...(hi !== null ? { maxItems: hi } : {}),
|
|
126
|
+
...(rules.length ? { rules } : {}),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** the shape part of a rubric-step stage's params, or null: picked by the line's signed CLASS, never by a key of the answer file @param {any} params @returns {any} */
|
|
131
|
+
export const shapePartOf = (params) => (isRec(params) && Array.isArray(params.parts) ? params.parts.find((/** @type {any} */ p) => isRec(p) && p.class === 'shape' && Array.isArray(p.fields)) ?? null : null);
|
|
132
|
+
|
|
133
|
+
/** the signed shape part of job line `n` in a close, or null @param {any} closeDecl @param {number} n */
|
|
134
|
+
export function shapePartOfLine(closeDecl, n) {
|
|
135
|
+
for (const st of Array.isArray(closeDecl?.stages) ? closeDecl.stages : []) {
|
|
136
|
+
if (!isRec(st) || st.kind !== 'rubric-step' || !isRec(st.params) || st.params.step !== n) continue;
|
|
137
|
+
const p = shapePartOf(st.params);
|
|
138
|
+
if (p) return p;
|
|
139
|
+
}
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** the words of one signed field row: `name \u00B7 sentence` (the rule it comes from is the `~ [you]` tag's, the card's heading says what is checked) @param {any} f @param {string[]} rules the line's `~` rules @returns {string} */
|
|
144
|
+
export function shapeFieldText(f, rules) {
|
|
145
|
+
const said = Number.isInteger(f.rule) ? rules[f.rule - 1] : undefined;
|
|
146
|
+
return `${f.name} \u00B7 ${shapeFieldSentence(f.spec, said ?? '')}`;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* The shape rows of a signed close, read from its shape parts: one per field (a `[you]` rule row's, an `[agent]` row's), then the line's `[default]` row. A close with no shape part has none.
|
|
151
|
+
* `rule` is the rule a `[you]` row is. Text is code's (never a model's).
|
|
152
|
+
* @param {any} closeDecl @param {any[]|null} [jobLines] the person's numbered lines
|
|
153
|
+
* @returns {{line: number, key: string, by: 'you'|'agent'|'default', text: string, name?: string, rule?: number}[]}
|
|
154
|
+
*/
|
|
155
|
+
export function shapeRowsOf(closeDecl, jobLines = null) {
|
|
156
|
+
const stages = isRec(closeDecl) && Array.isArray(closeDecl.stages) ? closeDecl.stages : [];
|
|
157
|
+
/** @type {{line: number, key: string, by: 'you'|'agent'|'default', text: string, name?: string, rule?: number, shape: true}[]} */
|
|
158
|
+
const out = [];
|
|
159
|
+
for (const st of stages) {
|
|
160
|
+
if (!isRec(st) || st.kind !== 'rubric-step' || !isRec(st.params)) continue;
|
|
161
|
+
const part = shapePartOf(st.params);
|
|
162
|
+
if (!part) continue;
|
|
163
|
+
const n = st.params.step;
|
|
164
|
+
const rules = lineRules((jobLines ?? []).find((/** @type {any} */ l) => isRec(l) && l.n === n));
|
|
165
|
+
for (const f of part.fields.filter(isRec)) {
|
|
166
|
+
out.push(Number.isInteger(f.rule) && f.row !== 'agent'
|
|
167
|
+
? { line: n, key: `L${n}.~${f.rule}`, by: 'you', text: shapeFieldText(f, rules), name: String(f.name), rule: f.rule, shape: true }
|
|
168
|
+
: { line: n, key: shapeRowKey(n, String(f.name)), by: 'agent', text: shapeFieldText(f, rules), name: String(f.name), shape: true });
|
|
169
|
+
}
|
|
170
|
+
const dw = shapeDefaultWords(Number.isInteger(part.minItems) ? { min: part.minItems, max: part.maxItems } : null);
|
|
171
|
+
if (dw !== null) out.push({ line: n, key: shapeDefaultKey(n), by: 'default', text: dw, shape: true });
|
|
172
|
+
}
|
|
173
|
+
return out;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** the fields that say what a shape field IS: all but the names code gives it (the row's own key) — two drafts spell the same field alike @param {{name: string, kind: string, required?: boolean, bounds?: Record<string, any>}} f @returns {Record<string, any>} */
|
|
177
|
+
export const shapeFieldBody = (f) => ({ name: f.name, kind: f.kind, required: f.required === true, bounds: f.bounds ?? {} });
|
|
178
|
+
|
|
179
|
+
/** bareguard's own worked example item of `itemShape` (its address and values are bareguard's, not ours) @type {Record<string, any>} */
|
|
180
|
+
const WORKED = /** @type {any} */ (rubricVocabulary).rules.itemShape.example.output.items[0];
|
|
181
|
+
|
|
182
|
+
/** the answer field the `itemShape` check reads: the shape answer's one list (the step file is `{"results": [...]}`) */
|
|
183
|
+
export const SHAPE_FIELD = 'results';
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* The bareguard `itemShape` check of a signed shape part (clause 6, `buildStepSpec`): the answer field `results`, the item count the person's words gave, and one field spec per signed field.
|
|
187
|
+
* @param {any} part a `shape` part @param {string} id @param {any} [factPart] the step's fact part, when the line is facts+shape @returns {Record<string, any>}
|
|
188
|
+
*/
|
|
189
|
+
export function shapeItemCheck(part, id, factPart = null) {
|
|
190
|
+
const own = Object.fromEntries((Array.isArray(part.fields) ? part.fields : []).filter(isRec).map((f) => [String(f.name), f.spec]));
|
|
191
|
+
// FACTS + SHAPE (the rules-first spec, verified on real data in the shape-combined round 2 scratch run): the one list is also read by `cited`, and the itemShape is CLOSED, so it lists the keys the fact result carries:
|
|
192
|
+
// `quote` (text, required) and `values` (an object, one OPTIONAL field per signed fact: a number read from text for a money or number fact, text for every other shape). No `claim` key: `cited` reads claims
|
|
193
|
+
// that `flattenStep` builds from the signed fact names. The item COUNT stays with the fact part's own count checks (one fault, one report); the shape part's count is used only when the fact part has none.
|
|
194
|
+
const facts = isRec(factPart) && Array.isArray(factPart.facts) ? factPart.facts.filter(isRec) : null;
|
|
195
|
+
const factCounted = isRec(factPart) && isRec(factPart.count) && (Number.isInteger(factPart.count.min) || Number.isInteger(factPart.count.max));
|
|
196
|
+
const count = facts !== null && factCounted ? {} : { ...(Number.isInteger(part.minItems) ? { minItems: part.minItems } : {}), ...(Number.isInteger(part.maxItems) ? { maxItems: part.maxItems } : {}) };
|
|
197
|
+
const fields = facts === null ? own : {
|
|
198
|
+
quote: { kind: 'text', required: true },
|
|
199
|
+
values: { kind: 'object', fields: Object.fromEntries(facts.map((f) => [String(f.name), f.shape === 'money' || f.shape === 'number' ? { kind: 'number', fromText: true } : { kind: 'text' }])) },
|
|
200
|
+
...own,
|
|
201
|
+
};
|
|
202
|
+
return { id, rule: 'itemShape', field: SHAPE_FIELD, ...count, fields };
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* The SHAPE of a `shape` part (clause 5, called by `rubricStepShapeReds`): its fields are named legally and once, each spec has a kind on the menu, the count is whole numbers, a rule number is a whole number, and bareguard itself
|
|
207
|
+
* accepts the check (`createRubric`, which refuses an impossible bound or a field spec it does not know, naming the path). Pure, never throws.
|
|
208
|
+
* @param {any} part @param {string} w the path of the part @param {(code: string, path: string, detail: string) => void} red
|
|
209
|
+
*/
|
|
210
|
+
export function shapeShapeReds(part, w, red, factPart = null) {
|
|
211
|
+
const fs = part.fields;
|
|
212
|
+
if (!Array.isArray(fs) || fs.length === 0) { red('invalid-value', `${w}.fields`, 'a non-empty list of fields: {name, spec, rule?, row?}'); return; }
|
|
213
|
+
const rules = shapeNameRules();
|
|
214
|
+
const seen = new Set();
|
|
215
|
+
fs.forEach((/** @type {any} */ f, /** @type {number} */ i) => {
|
|
216
|
+
const fw = `${w}.fields[${i}]`;
|
|
217
|
+
if (!isRec(f)) { red('invalid-value', fw, '{name, spec, rule?, row?}'); return; }
|
|
218
|
+
const bad = nameWhy(f.name, rules);
|
|
219
|
+
if (bad !== null) red('invalid-value', `${fw}.name`, bad);
|
|
220
|
+
else if (seen.has(f.name)) red('invalid-value', `${fw}.name`, `the field name "${f.name}" is used twice`);
|
|
221
|
+
else seen.add(f.name);
|
|
222
|
+
if (factPart && (f.name === 'quote' || f.name === 'values')) red('invalid-value', `${fw}.name`, `"${f.name}" is a key of the fact results on this line, so it cannot name a shape field`);
|
|
223
|
+
if (!isRec(f.spec) || !Object.hasOwn(SHAPE_KINDS, String(f.spec.kind))) red('invalid-value', `${fw}.spec.kind`, `one of ${Object.keys(SHAPE_KINDS).join(' | ')}`);
|
|
224
|
+
if (Object.hasOwn(f, 'rule') && !(Number.isInteger(f.rule) && f.rule >= 1)) red('invalid-value', `${fw}.rule`, 'the number of the ~ rule the field comes from (an integer, 1 or more)');
|
|
225
|
+
if (Object.hasOwn(f, 'row') && f.row !== 'agent') red('invalid-value', `${fw}.row`, '"agent" (the tag of a field code made its own row) or absent');
|
|
226
|
+
});
|
|
227
|
+
for (const k of ['minItems', 'maxItems']) if (Object.hasOwn(part, k) && !(Number.isInteger(part[k]) && part[k] >= (k === 'maxItems' ? 1 : 0))) red('invalid-value', `${w}.${k}`, 'a whole number of items');
|
|
228
|
+
if (Number.isInteger(part.minItems) && Number.isInteger(part.maxItems) && part.minItems > part.maxItems) red('invalid-value', `${w}.maxItems`, 'maxItems is below minItems');
|
|
229
|
+
if (!isRec(part) || fs.some((/** @type {any} */ f) => !isRec(f) || !isRec(f.spec))) return;
|
|
230
|
+
// bareguard is the judge of whether the shape is SIGNABLE: ask it here, at $0
|
|
231
|
+
try {
|
|
232
|
+
createRubric({ schema: 1, goal: 'shape', inputs: [], checkpoints: { shape: { gating: false, checks: [shapeItemCheck(part, 'shape', factPart)] } } });
|
|
233
|
+
} catch (e) {
|
|
234
|
+
red('invalid-value', `${w}.fields`, `bareguard refuses this shape: ${String(/** @type {any} */ (e)?.message ?? e)}`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* One worked example item of a shape, written by code from the signed fields (never by a model): a value of each field's kind that the field's own bounds accept.
|
|
240
|
+
* @param {{name: string, spec: Record<string, any>}[]} fields @returns {Record<string, any>}
|
|
241
|
+
*/
|
|
242
|
+
export function shapeExampleItem(fields) {
|
|
243
|
+
const one = (/** @type {Record<string, any>} */ s) => {
|
|
244
|
+
switch (s.kind) {
|
|
245
|
+
case 'text': {
|
|
246
|
+
if (Number.isInteger(s.minWords) && s.minWords > 0) return Array.from({ length: s.minWords }, () => 'word').join(' ');
|
|
247
|
+
const lo = Math.max(Number.isInteger(s.minChars) ? s.minChars : 1, 1);
|
|
248
|
+
const len = Math.min(Math.max(12, lo), Number.isInteger(s.maxChars) ? s.maxChars : Infinity);
|
|
249
|
+
return 'Example text'.padEnd(len, '.').slice(0, len);
|
|
250
|
+
}
|
|
251
|
+
case 'number': return s.min ?? (s.gt !== undefined ? s.gt + 1 : s.max ?? (s.lt !== undefined ? s.lt - 1 : 1));
|
|
252
|
+
case 'oneOf': return Array.isArray(s.values) ? s.values[0] : 'value';
|
|
253
|
+
case 'money': { const c = Array.isArray(s.currency) ? s.currency[0] : s.currency; const u = Array.isArray(s.unit) ? s.unit[0] : s.unit; const a = s.min ?? (s.gt !== undefined ? s.gt + 1 : s.max ?? (s.lt !== undefined ? s.lt - 1 : 10)); return typeof c === 'string' && c.length === 1 ? `${c}${a}` : `${a} ${u ?? c ?? ''}`.trim(); }
|
|
254
|
+
case 'date': return s.min ?? '2026-01-15';
|
|
255
|
+
case 'time': return s.min ?? '09:30';
|
|
256
|
+
case 'url': return WORKED.link;
|
|
257
|
+
case 'boolean': return s.equals ?? true;
|
|
258
|
+
case 'list': return isRec(s.of) ? [one(s.of)] : [];
|
|
259
|
+
default: return 'value';
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
return Object.fromEntries(fields.map((f) => [f.name, one(f.spec)]));
|
|
263
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// borrowed-from: bareloop src/shapewords.js@v0.61.0 (fc56e1f3)
|
|
2
|
+
// One wording differs from v0.61.0, by hamr's ask on 2026-11-20: the `(it is ...)` words of a `not-a-list` gap say `plain text`, `a number` and so on (MEASURED_WORDS), where v0.61.0 prints bareguard's raw `type:string`.
|
|
3
|
+
// SHAPE JOBS (itemShape), docs/product/ITEM33-BUILD.md "Addendum 2026-11-18: shape jobs", clause 7 "Words": the plain sentence of a bareguard `itemShape` gap, so a red says what to fix and never a raw code.
|
|
4
|
+
// bareguard's item reds read `#<i>:<path>:<reason>` (0-based item, dotted path, `name[j]` for a list entry; reasons `missing`, `wrong-type`, `not-one-of`, `bad-number|money|date|time|url`, `wrong-value`, `under`, `over`,
|
|
5
|
+
// `too-short|too-long:chars|words:<n><|><bound>`, `unknown-field:<key>`, and a list's `not-a-list`, `unreadable`, `count-under|count-over:<n><|><bound>`, `too-many:<n>><cap>`, `duplicate`); an item with no field part is
|
|
6
|
+
// `#<i>:item-not-object` or `#<i>:unreadable`. The whole-field gaps are `missing`, `unreadable`, `not-a-list`, `too-many`, `count-under`, `count-over`. A gap carries names, counts and bounds, never the worker's values, so
|
|
7
|
+
// neither does a sentence here. The item is shown 1-based ("item 2" for `#1`). A reason this table does not know falls back to its raw text: nothing is dropped.
|
|
8
|
+
// Pure. `plainShapeGap` is called by src/rubricstep.js `plainStepGap`; `plainShapeItem` and `itemFieldOf` by src/rowresults.js.
|
|
9
|
+
|
|
10
|
+
/** the kinds of value a reader names in a red, in a person's words */
|
|
11
|
+
const READS = Object.freeze({ 'bad-number': 'a number', 'bad-money': 'a money amount', 'bad-date': 'a date', 'bad-time': 'a time', 'bad-url': 'a web address' });
|
|
12
|
+
|
|
13
|
+
/** the words of a `not-a-list` gap's measured value (bareguard's `type:<kind>`); any other measured value is printed as it came */
|
|
14
|
+
export const MEASURED_WORDS = Object.freeze({ 'type:string': 'plain text', 'type:number': 'a number', 'type:boolean': 'true or false', 'type:object': 'an object', 'type:null': 'empty' });
|
|
15
|
+
|
|
16
|
+
/** the measured value of a `not-a-list` gap in a person's words, or `something else` when none came @param {unknown} measured @returns {string} */
|
|
17
|
+
export function measuredWords(measured) {
|
|
18
|
+
if (measured === undefined || measured === null) return 'something else';
|
|
19
|
+
return Object.hasOwn(MEASURED_WORDS, String(measured)) ? MEASURED_WORDS[/** @type {keyof typeof MEASURED_WORDS} */ (String(measured))] : String(measured);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** one path as words: `tags[2]` is `tags, entry 3` (entries count from 1 for a person) @param {string} path @returns {string} */
|
|
23
|
+
const pathWords = (path) => path.replace(/\[(\d+)\]/g, (_m, j) => `, entry ${Number(j) + 1}`);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Split one item red into its item (0-based), its field path (null when the red is about the item as a whole) and its reason. Null when the text is not an item red.
|
|
27
|
+
* @param {unknown} item @returns {{i: number, path: string|null, reason: string}|null}
|
|
28
|
+
*/
|
|
29
|
+
export function parseShapeItem(item) {
|
|
30
|
+
const m = /^#(\d+):(.*)$/s.exec(String(item));
|
|
31
|
+
if (!m) return null;
|
|
32
|
+
const rest = m[2];
|
|
33
|
+
const i = Number(m[1]);
|
|
34
|
+
if (rest === 'item-not-object' || rest === 'unreadable' || rest.startsWith('unknown-field:')) return { i, path: null, reason: rest };
|
|
35
|
+
const at = rest.indexOf(':');
|
|
36
|
+
return at < 0 ? { i, path: null, reason: rest } : { i, path: rest.slice(0, at), reason: rest.slice(at + 1) };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** the field a red names, as the signed spec names it: the first name of the path, a list entry's `[j]` and a nested `.name` left off @param {unknown} item @returns {string|null} */
|
|
40
|
+
export function itemFieldOf(item) {
|
|
41
|
+
const p = parseShapeItem(item);
|
|
42
|
+
return p && p.path !== null ? p.path.split(/[.[]/)[0] : null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* One item red as a plain sentence: `item 2: "summary" is too long (201 characters, at most 200)`.
|
|
47
|
+
* @param {unknown} item `#<i>:<path>:<reason>` @returns {string}
|
|
48
|
+
*/
|
|
49
|
+
export function plainShapeItem(item) {
|
|
50
|
+
const p = parseShapeItem(item);
|
|
51
|
+
if (p === null) return String(item);
|
|
52
|
+
const at = `item ${p.i + 1}`;
|
|
53
|
+
const r = p.reason;
|
|
54
|
+
if (p.path === null) {
|
|
55
|
+
if (r === 'item-not-object') return `${at} is not an object with named fields`;
|
|
56
|
+
if (r === 'unreadable') return `${at} could not be read`;
|
|
57
|
+
if (r.startsWith('unknown-field:')) return `${at} has a field "${r.slice('unknown-field:'.length)}" that the job does not ask for`;
|
|
58
|
+
return `${at}: ${r}`;
|
|
59
|
+
}
|
|
60
|
+
const f = `"${pathWords(p.path)}"`;
|
|
61
|
+
const w = /^(too-short|too-long):(chars|words):(\d+)([<>])(\d+)$/.exec(r);
|
|
62
|
+
if (w) {
|
|
63
|
+
const unit = w[2] === 'chars' ? 'characters' : 'words';
|
|
64
|
+
return w[1] === 'too-long' ? `${at}: ${f} is too long (${w[3]} ${unit}, at most ${w[5]})` : `${at}: ${f} is too short (${w[3]} ${unit}, at least ${w[5]})`;
|
|
65
|
+
}
|
|
66
|
+
const c = /^(count-under|count-over):(\d+)([<>])(\d+)$/.exec(r);
|
|
67
|
+
if (c) return c[1] === 'count-over' ? `${at}: ${f} has ${c[2]} entries, at most ${c[4]} are allowed` : `${at}: ${f} has ${c[2]} entries, at least ${c[4]} are required`;
|
|
68
|
+
const t = /^too-many:(\d+)>(\d+)$/.exec(r);
|
|
69
|
+
if (t) return `${at}: ${f} has too many entries to check (${t[1]} against a limit of ${t[2]})`;
|
|
70
|
+
if (r.startsWith('unknown-field:')) return `${at}: ${f} has a field "${r.slice('unknown-field:'.length)}" that the job does not ask for`;
|
|
71
|
+
if (Object.hasOwn(READS, r)) return `${at}: ${f} is not ${/** @type {Record<string, string>} */ (READS)[r]} as written`;
|
|
72
|
+
switch (r) {
|
|
73
|
+
case 'missing': return `${at}: ${f} is missing`;
|
|
74
|
+
case 'wrong-type': return `${at}: ${f} is not the kind of value the job asks for`;
|
|
75
|
+
case 'not-one-of': return `${at}: ${f} is not one of the allowed values`;
|
|
76
|
+
case 'wrong-value': return `${at}: ${f} does not have the value the job asks for`;
|
|
77
|
+
case 'under': return `${at}: ${f} is below the lowest value allowed`;
|
|
78
|
+
case 'over': return `${at}: ${f} is above the highest value allowed`;
|
|
79
|
+
case 'not-a-list': return `${at}: ${f} is not a list`;
|
|
80
|
+
case 'unreadable': return `${at}: ${f} could not be read`;
|
|
81
|
+
case 'duplicate': return `${at}: ${f} repeats an earlier entry`;
|
|
82
|
+
default: return `${at}: ${f} ${r}`;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* One bareguard `itemShape` gap as plain lines (one per item red, or one for a whole-field gap).
|
|
88
|
+
* @param {{at: string, file: string, field?: string}} where `at` = `line N`, `file` = the step file's path, `field` = the answer field holding the items (default `results`)
|
|
89
|
+
* @param {any} g the gap @returns {string}
|
|
90
|
+
*/
|
|
91
|
+
export function plainShapeGap({ at, file, field = 'results' }, g) {
|
|
92
|
+
const f = `"${field}"`;
|
|
93
|
+
switch (g.kind) {
|
|
94
|
+
case 'missing': return `${at}: ${file} has no ${f} list — give a list of items, one object per item`;
|
|
95
|
+
case 'unreadable': return `${at}: ${f} in ${file} could not be read`;
|
|
96
|
+
case 'not-a-list': return `${at}: ${f} in ${file} is not a list (it is ${measuredWords(g.measured)}) — give a list of items`;
|
|
97
|
+
case 'too-many': return `${at}: ${f} lists too many items to check (${g.measured} against a limit of ${g.limit})`;
|
|
98
|
+
case 'count-under': return `${at}: ${f} lists ${g.measured} item(s), at least ${g.limit} are required`;
|
|
99
|
+
case 'count-over': return `${at}: ${f} lists ${g.measured} item(s), at most ${g.limit} are allowed`;
|
|
100
|
+
case 'item-shape': {
|
|
101
|
+
const items = Array.isArray(g.items) ? g.items : [];
|
|
102
|
+
const lines = items.map((/** @type {unknown} */ it) => `${at}: ${plainShapeItem(it)}`);
|
|
103
|
+
const more = typeof g.itemsTotal === 'number' ? g.itemsTotal - items.length : 0;
|
|
104
|
+
return [...lines, ...(more > 0 ? [`${at}: and ${more} more problem(s) in the items`] : [])].join('\n');
|
|
105
|
+
}
|
|
106
|
+
default: return `${at}: the items cannot be checked (${String(g.kind)})`;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** the number of reds a gap counts for the stage's trend number: each item red is one, a whole-field gap is one @param {any} g @returns {number} */
|
|
111
|
+
export const shapeGapCount = (g) => (g.kind === 'item-shape' ? (typeof g.itemsTotal === 'number' ? g.itemsTotal : Array.isArray(g.items) ? g.items.length : 1) : 1);
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* The inverse of {@link plainShapeItem}: the item red (`#<i>:<path>:<reason>`) a plain sentence of ours says, or null when the text is none of ours. A red run records only the close's plain gap lines (the per-row record
|
|
115
|
+
* is the final close's), so the Result tab's grid reads them back through this; a test walks every reason through both directions.
|
|
116
|
+
* @param {string} text `item 3: "status" is not one of the allowed values` @returns {string|null}
|
|
117
|
+
*/
|
|
118
|
+
export function shapeItemOfPlain(text) {
|
|
119
|
+
const t = String(text).trim();
|
|
120
|
+
let m = /^item (\d+) (?:is not an object with named fields|could not be read|has a field "(.*)" that the job does not ask for)$/s.exec(t);
|
|
121
|
+
if (m) { const i = Number(m[1]) - 1; return t.endsWith('named fields') ? `#${i}:item-not-object` : t.endsWith('be read') ? `#${i}:unreadable` : `#${i}:unknown-field:${m[2]}`; }
|
|
122
|
+
m = /^item (\d+): "(.*?)" (.*)$/s.exec(t);
|
|
123
|
+
if (!m) return null;
|
|
124
|
+
const i = Number(m[1]) - 1;
|
|
125
|
+
const path = m[2].replace(/, entry (\d+)/g, (_x, j) => `[${Number(j) - 1}]`);
|
|
126
|
+
const r = m[3];
|
|
127
|
+
const at = (/** @type {string} */ reason) => `#${i}:${path}:${reason}`;
|
|
128
|
+
let w = /^is too (long|short) \((\d+) (characters|words), (?:at most|at least) (\d+)\)$/.exec(r);
|
|
129
|
+
if (w) return at(`too-${w[1]}:${w[3] === 'characters' ? 'chars' : 'words'}:${w[2]}${w[1] === 'long' ? '>' : '<'}${w[4]}`);
|
|
130
|
+
w = /^has (\d+) entries, (at most|at least) (\d+) (?:are allowed|are required)$/.exec(r);
|
|
131
|
+
if (w) return at(`count-${w[2] === 'at most' ? 'over' : 'under'}:${w[1]}${w[2] === 'at most' ? '>' : '<'}${w[3]}`);
|
|
132
|
+
w = /^has too many entries to check \((\d+) against a limit of (\d+)\)$/.exec(r);
|
|
133
|
+
if (w) return at(`too-many:${w[1]}>${w[2]}`);
|
|
134
|
+
const table = /** @type {Record<string, string>} */ ({
|
|
135
|
+
'is missing': 'missing', 'is not the kind of value the job asks for': 'wrong-type', 'is not one of the allowed values': 'not-one-of', 'does not have the value the job asks for': 'wrong-value',
|
|
136
|
+
'is below the lowest value allowed': 'under', 'is above the highest value allowed': 'over', 'is not a list': 'not-a-list', 'could not be read': 'unreadable', 'repeats an earlier entry': 'duplicate',
|
|
137
|
+
'is not a number as written': 'bad-number', 'is not a money amount as written': 'bad-money', 'is not a date as written': 'bad-date', 'is not a time as written': 'bad-time', 'is not a web address as written': 'bad-url',
|
|
138
|
+
});
|
|
139
|
+
return Object.hasOwn(table, r) ? at(table[r]) : null;
|
|
140
|
+
}
|
package/src/sheet-record.js
CHANGED
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
// Shape: { lines: [ { n, try, passed, tables: [{name, tableSha}], checks: [the signed check objects], claims: <the step's answer>, results: [{id, text, ok, result}], red } ] }.
|
|
4
4
|
// `tables[].tableSha` is the one recorded at the run's start (run.json), the one the check used. Throws away: nothing the check saw; no cell text is kept here.
|
|
5
5
|
import { readLineSection, writeLineSection } from './line-checks.js';
|
|
6
|
-
|
|
7
|
-
const isRec = (/** @type {unknown} */ v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
6
|
+
import { isRec } from './isrec.js';
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* @param {string} runDir @param {{n: number, try: number, checks: any[], closed: {verdict: string, red?: string|null, sheetRecord?: any}}} o
|
package/src/sheetblock.js
CHANGED
|
@@ -14,8 +14,7 @@ import { lineRules } from './pagebits.js';
|
|
|
14
14
|
import { sheetCheckSentence } from './sheetchecks.js';
|
|
15
15
|
import { isColumnChoiceRule } from './sheetoffer.js';
|
|
16
16
|
import { NO_VALUE_WHY } from './ticketrows.js';
|
|
17
|
-
|
|
18
|
-
const isRec = (/** @type {unknown} */ v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
17
|
+
import { isRec } from './isrec.js';
|
|
19
18
|
|
|
20
19
|
/** the short plain name of each bareguard op (the ONE table; a test fails when bareguard gains an op this table does not name). `noDuplicates` and `noEmpty` add the column. */
|
|
21
20
|
export const SHEET_OP_NAMES = Object.freeze({
|