fwdloop 0.31.0 → 0.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/bin/fwdloop +8 -2
  2. package/package.json +2 -2
  3. package/src/auditchecks.js +53 -0
  4. package/src/authoring.js +52 -12
  5. package/src/blockasks.js +44 -0
  6. package/src/blockassemble.js +140 -0
  7. package/src/blockdraft.js +91 -0
  8. package/src/blocklines.js +30 -0
  9. package/src/blockpick.js +165 -0
  10. package/src/cardlist.js +19 -0
  11. package/src/checkblock.js +804 -0
  12. package/src/checked.js +48 -9
  13. package/src/checklist.js +99 -0
  14. package/src/checklistsign.js +93 -0
  15. package/src/checkwords.js +20 -1
  16. package/src/cited-record.js +21 -1
  17. package/src/citedcheck.js +162 -7
  18. package/src/closers.js +41 -3
  19. package/src/declaration.js +25 -2
  20. package/src/declaredclose.js +4 -0
  21. package/src/draft-steps.js +3 -1
  22. package/src/drafter.js +244 -134
  23. package/src/factwords.js +112 -0
  24. package/src/inputlook.js +53 -0
  25. package/src/jsonbrace.js +21 -0
  26. package/src/labelscan.js +162 -0
  27. package/src/pageask.js +4 -1
  28. package/src/pagedropwords.js +11 -1
  29. package/src/panel/author.js +76 -5
  30. package/src/panel/authorcard.js +9 -6
  31. package/src/panel/data.js +41 -9
  32. package/src/panel/index.html +202 -13
  33. package/src/panel/result.js +4 -3
  34. package/src/panel/server.js +3 -1
  35. package/src/pickrecord.js +28 -0
  36. package/src/placerule.js +398 -0
  37. package/src/planrebuild.js +206 -0
  38. package/src/rowedit.js +118 -0
  39. package/src/rubricstep.js +264 -0
  40. package/src/runfile.js +4 -2
  41. package/src/runner.js +67 -10
  42. package/src/setup.js +10 -4
  43. package/src/sheetblock.js +6 -2
  44. package/src/sheetchecks.js +49 -64
  45. package/src/sheetclaims.js +12 -32
  46. package/src/sheetlook.js +2 -2
  47. package/src/sheetoffer.js +25 -53
  48. package/src/sheetrows.js +107 -0
  49. package/src/sheetrun.js +31 -1
  50. package/src/summary-words.js +3 -3
  51. package/src/try-checks.js +31 -12
  52. package/src/types.js +1 -0
  53. package/types/auditchecks.d.ts +24 -0
  54. package/types/authoring.d.ts +18 -1
  55. package/types/blockasks.d.ts +37 -0
  56. package/types/blockassemble.d.ts +33 -0
  57. package/types/blockdraft.d.ts +83 -0
  58. package/types/blocklines.d.ts +31 -0
  59. package/types/blockpick.d.ts +41 -0
  60. package/types/cardlist.d.ts +21 -0
  61. package/types/checkblock.d.ts +363 -0
  62. package/types/checked.d.ts +16 -2
  63. package/types/checklist.d.ts +115 -0
  64. package/types/checklistsign.d.ts +27 -0
  65. package/types/checkwords.d.ts +5 -0
  66. package/types/cited-record.d.ts +9 -0
  67. package/types/citedcheck.d.ts +33 -2
  68. package/types/closers.d.ts +24 -2
  69. package/types/declaredclose.d.ts +2 -0
  70. package/types/drafter.d.ts +15 -361
  71. package/types/factwords.d.ts +38 -0
  72. package/types/inputlook.d.ts +49 -0
  73. package/types/jsonbrace.d.ts +8 -0
  74. package/types/labelscan.d.ts +35 -0
  75. package/types/pageask.d.ts +2 -0
  76. package/types/panel/author.d.ts +41 -0
  77. package/types/panel/authorcard.d.ts +1 -1
  78. package/types/panel/data.d.ts +4 -2
  79. package/types/panel/jobgrid.d.ts +1 -1
  80. package/types/pickrecord.d.ts +22 -0
  81. package/types/placerule.d.ts +208 -0
  82. package/types/planrebuild.d.ts +52 -0
  83. package/types/provider.d.ts +1 -1
  84. package/types/rowedit.d.ts +33 -0
  85. package/types/rubricstep.d.ts +60 -0
  86. package/types/runfile.d.ts +5 -2
  87. package/types/runner.d.ts +45 -1
  88. package/types/sheetblock.d.ts +1 -0
  89. package/types/sheetchecks.d.ts +10 -17
  90. package/types/sheetclaims.d.ts +2 -1
  91. package/types/sheetoffer.d.ts +5 -5
  92. package/types/sheetrows.d.ts +73 -0
  93. package/types/sheetrun.d.ts +12 -0
  94. package/types/summary-words.d.ts +2 -1
  95. package/types/try-checks.d.ts +4 -2
  96. package/types/types.d.ts +8 -0
@@ -0,0 +1,165 @@
1
+ // borrowed-from: bareloop src/checkpick.js@v0.56.0 (3383cce) (isCountable, keepOrDrop, countCheck, partOfPick, sameRuleWords and what they call; HOW_TO_ANSWER and CANT_CHECK_WORDS are fwd's own, src/checkpick.js, the same words)
2
+ // This file is bareloop's checkpick.js. fwd already has a src/checkpick.js (the M10 am16 pick path, whose keepOrDrop and countCheck differ from these); the check block calls THESE,
3
+ // so they live here under another name and the am16 module is left as it is.
4
+ // The pick vocabulary and its keep-or-drop: a suggested check is kept only if its rule is on bareguard's list and offered here, it carries only that rule's own fields, and every
5
+ // number is one the person's rule names.
6
+ import { rubricVocabulary } from 'bareguard';
7
+ import { plainWords, OFFERED } from './checkwords.js';
8
+
9
+ export { plainWords };
10
+
11
+ const VOCAB = /** @type {Record<string, {description: string, fields: Record<string, {type: string, required?: boolean}>}>} */ (rubricVocabulary.rules);
12
+
13
+ /** fields code sets, or that never decide: never offered, never kept */
14
+ const IGNORED = new Set(['id', 'field', 'text', 'strict']);
15
+
16
+ const NUM_FIELDS = ['value', 'size', 'wordsPerSection'];
17
+
18
+ const WORD_FIELDS = ['names', 'phrases'];
19
+
20
+ // ---- the guardrail readers (fwd src/declaration.js@v0.29.0) ------------------------------------------------------------------------------
21
+ const readNumber = (/** @type {string} */ t) => Number(t.replace(/,/g, ''));
22
+
23
+ /** every whole-output word number in a guardrail ("under 600 words" -> [600]); a "<n> words each" / "per section" size is never listed here @param {unknown} g @returns {number[]} */
24
+ export function guardrailWordNumbers(g) {
25
+ if (typeof g !== 'string') return [];
26
+ return [...g.matchAll(/(?<![\d,])(\d{1,3}(?:,\d{3})+|\d+)\s*words?\b(?!\s*(?:each|per\s+section)\b)/gi)].map((m) => readNumber(m[1]));
27
+ }
28
+
29
+ /** every standalone number in a guardrail's own text (digits not joined to letters) @param {unknown} g @returns {number[]} */
30
+ export function guardrailStandaloneNumbers(g) {
31
+ if (typeof g !== 'string') return [];
32
+ return [...g.matchAll(/(?<![A-Za-z0-9_.,])(\d{1,3}(?:,\d{3})+|\d+(?:\.\d+)?)(?![A-Za-z0-9_])/g)].map((m) => Number(m[1].replace(/,/g, '')));
33
+ }
34
+
35
+ /** the "<n> words each" / "<n> words per section" size, or null @param {unknown} g @returns {number|null} */
36
+ export function guardrailWordsPerSection(g) {
37
+ const m = typeof g === 'string' ? /(?<![\d,])(\d{1,3}(?:,\d{3})+|\d+)(?:\s*words?|ish(?:\s+words?)?)\s+(?:each|per\s+section)\b/i.exec(g) : null;
38
+ return m ? readNumber(m[1]) : null;
39
+ }
40
+
41
+ const NUMBER_WORDS = /** @type {Record<string, number>} */ ({ one: 1, two: 2, three: 3, four: 4, five: 5, six: 6, seven: 7, eight: 8, nine: 9, ten: 10 });
42
+
43
+ /** the first "<N> sections" in a guardrail (digits, or one..ten), or null @param {unknown} g @returns {number|null} */
44
+ export function guardrailSectionCount(g) {
45
+ const m = typeof g === 'string' ? /\b(\d+|one|two|three|four|five|six|seven|eight|nine|ten)\s+(?:\w+\s+)?sections?\b/i.exec(g) : null;
46
+ if (!m) return null;
47
+ return /^\d+$/.test(m[1]) ? Number(m[1]) : NUMBER_WORDS[m[1].toLowerCase()];
48
+ }
49
+
50
+ /** the first "<N> bullets / list items / items / lines / points" in a guardrail (digits, or one..ten), or null @param {unknown} g @returns {number|null} */
51
+ export function guardrailItemCount(g) {
52
+ const m = typeof g === 'string' ? /\b(\d+|one|two|three|four|five|six|seven|eight|nine|ten)\s+(?:\w+\s+)?(?:bullets?|bullet\s+points?|list\s+items?|items?|lines?|points?)\b/i.exec(g) : null;
53
+ if (!m) return null;
54
+ return /^\d+$/.test(m[1]) ? Number(m[1]) : NUMBER_WORDS[m[1].toLowerCase()];
55
+ }
56
+
57
+ /** a list-bound word the guardrail uses: the count it names, or the one it stands for ("more than 3" = at least 4, "fewer than 3" = at most 2) */
58
+ const MORE_THAN = /(?<!\b(?:no|not)\s)\bmore\s+than\s+(\d+)\b/i;
59
+
60
+ const FEWER_THAN = /(?<!\b(?:no|not)\s)\b(?:(?:fewer|less)\s+than|under|below)\s+(\d+)\b/i;
61
+
62
+ /** the direction of a list-items rule's wording: 'max', 'min' or null (exact / not said) @param {string} t @returns {'max'|'min'|null} */
63
+ function listDirection(t) {
64
+ if (/\b(at\s+most|up\s+to|no\s+more\s+than|not\s+more\s+than|max(?:imum)?(?:\s+of)?)\b/i.test(t) || FEWER_THAN.test(t)) return 'max';
65
+ if (/\b(at\s+least|min(?:imum)?(?:\s+of)?|no\s+fewer\s+than|not\s+fewer\s+than)\b/i.test(t) || MORE_THAN.test(t)) return 'min';
66
+ return null;
67
+ }
68
+
69
+ /** the numbers a rule may carry: the standalone numbers of the guardrail, plus N+1 for "more than N" (min) and N-1 for "fewer than N" (max) @param {string} rule @param {string} g @returns {number[]} */
70
+ function listBoundNumbers(rule, g) {
71
+ const named = guardrailStandaloneNumbers(g);
72
+ if (rule === 'minListItems') { const m = MORE_THAN.exec(g); if (m) named.push(Number(m[1]) + 1); }
73
+ if (rule === 'maxListItems') { const m = FEWER_THAN.exec(g); if (m) named.push(Number(m[1]) - 1); }
74
+ return named;
75
+ }
76
+
77
+ /** @param {unknown} g @returns {boolean} the rule is a COUNT bareguard checks (words, list items or lines, sections): code reads it, whatever the page look said about it */
78
+ export const isCountable = (g) => guardrailWordNumbers(g).length > 0 || guardrailItemCount(g) !== null || guardrailSectionCount(g) !== null;
79
+
80
+ // ---- code's keep-or-drop (am16 (2)) ------------------------------------------------------------------------------------------------------
81
+ const norm = (/** @type {unknown} */ t) => String(t).toLowerCase().replace(/\s+/g, ' ').trim();
82
+
83
+ /** a ~ rule's words compared case, spacing and trailing punctuation blind: the one spelling "is this the same rule?" is asked by */
84
+ export const sameRuleWords = (/** @type {unknown} */ a, /** @type {unknown} */ b) => norm(a).replace(/[.,;:!?\s]+$/, '') === norm(b).replace(/[.,;:!?\s]+$/, '');
85
+
86
+ const tokens = (/** @type {unknown} */ t) => new Set(norm(t).match(/[\p{L}\p{N}]+/gu) ?? []);
87
+
88
+ /**
89
+ * Keep a suggestion only if its rule is on bareguard's list, it carries only that rule's own fields, every number in it is a number the guardrail names and every word in it
90
+ * is a word of the guardrail. Anything else is dropped, with the reason. `none` is a drop with the reason `none`.
91
+ * @param {string} guardrail @param {any} sug the model's entry for this guardrail
92
+ * @returns {{kept: true, check: Record<string, any>}|{kept: false, why: string}}
93
+ */
94
+ export function keepOrDrop(guardrail, sug) {
95
+ if (sug == null || typeof sug !== 'object') return { kept: false, why: 'unreadable suggestion' };
96
+ const { rule } = sug;
97
+ if (rule === 'none' || rule === undefined || rule === null) return { kept: false, why: 'none' };
98
+ if (typeof rule !== 'string' || !Object.hasOwn(VOCAB, rule)) return { kept: false, why: `rule "${rule}" is not on bareguard's list` };
99
+ if (!OFFERED.includes(rule)) return { kept: false, why: `rule "${rule}" is on bareguard's list but is not offered here` };
100
+ const own = Object.keys(VOCAB[rule].fields).filter((k) => !IGNORED.has(k));
101
+ for (const k of own) if (VOCAB[rule].fields[k].required && sug[k] == null) return { kept: false, why: `${rule} needs ${k}` };
102
+ const allowed = new Set([...own, 'rule', 'line', 'guardrail']);
103
+ for (const k of Object.keys(sug)) if (sug[k] != null && !allowed.has(k)) return { kept: false, why: `${rule} does not take ${k}` };
104
+ /** @type {Record<string, any>} */
105
+ const check = { rule };
106
+ for (const k of own) {
107
+ const v = sug[k];
108
+ if (v == null) continue;
109
+ if (NUM_FIELDS.includes(k)) {
110
+ const floor = rule === 'maxListItems' ? 0 : 1; // maxListItems 0 = no bullets (bareguard 0.35); every other count starts at 1
111
+ if (!Number.isInteger(v) || v < floor) return { kept: false, why: `${k} ${JSON.stringify(v)} is not a whole number >= ${floor}` };
112
+ const named = rule === 'maxWords' || rule === 'minWords' ? guardrailWordNumbers(guardrail)
113
+ : k === 'wordsPerSection' ? [guardrailWordsPerSection(guardrail)].filter((x) => x !== null)
114
+ : listBoundNumbers(rule, guardrail);
115
+ if (!named.includes(v)) return { kept: false, why: `${k} ${v} is not a number the guardrail names (${named.join(', ') || 'it names none'})` };
116
+ check[k] = v;
117
+ } else if (WORD_FIELDS.includes(k)) {
118
+ if (!Array.isArray(v) || v.length === 0 || v.some((s) => typeof s !== 'string' || s.trim() === '')) return { kept: false, why: `${k} is not a list of words` };
119
+ const gTok = tokens(guardrail);
120
+ const gNorm = norm(guardrail);
121
+ for (const s of v) {
122
+ if (!gNorm.includes(norm(s))) return { kept: false, why: `${k} "${s}" is not in the guardrail's words` };
123
+ for (const t of tokens(s)) if (!gTok.has(t)) return { kept: false, why: `${k} word "${t}" is not a word of the guardrail` };
124
+ }
125
+ check[k] = v;
126
+ }
127
+ }
128
+ if (rule === 'sections' || rule === 'sectionOrder' || rule === 'sectionWords') {
129
+ const want = guardrailSectionCount(guardrail);
130
+ if (want !== null && check.names.length !== want) return { kept: false, why: `the guardrail says ${want} sections; the check has ${check.names.length}` };
131
+ }
132
+ return { kept: true, check };
133
+ }
134
+
135
+ /**
136
+ * The check CODE proposes for a count rule when the call yields none (R10, ours; fwd has no such fallback): a bullets / list-items / points count -> listItems N (exact; "at most / up to / no more than / fewer than / under / below" -> maxListItems, "at least / minimum / no fewer than / more than" -> minListItems, F315), a lines count ->
137
+ * maxLines N, ONE word number -> minWords N when the rule says "at least / minimum / more than", else maxWords N. A section count names no sections, so none is built; a rule naming two different counts ("3 bullets under 80 words") is not built either; a rule with
138
+ * several word numbers or a range ("between 100 and 200 words") is not guessed. The result passes `keepOrDrop`, so every number is one the rule names.
139
+ * @param {string} text @returns {Record<string, any>|null}
140
+ */
141
+ export function countCheck(text) {
142
+ const items = guardrailItemCount(text);
143
+ const words = guardrailWordNumbers(text);
144
+ /** @type {Record<string, any>|null} */
145
+ let built = null;
146
+ if (items !== null && (words.length > 0 || guardrailSectionCount(text) !== null)) return null; // two different counts in one rule: first-match readers would guess, so nothing is built
147
+ if (items !== null && /\blines?\b/i.test(text) && !/\b(bullets?|items?|points?)\b/i.test(text)) built = { rule: 'maxLines', value: items };
148
+ else if (items !== null) {
149
+ const dir = listDirection(text);
150
+ if (dir === 'min') built = { rule: 'minListItems', value: MORE_THAN.test(text) ? items + 1 : items };
151
+ else if (dir === 'max') built = { rule: 'maxListItems', value: FEWER_THAN.test(text) ? items - 1 : items };
152
+ else built = { rule: 'listItems', value: items };
153
+ }
154
+ else if (words.length === 1 && !/\bbetween\b|\d\s*(?:-|–|to)\s*\d/i.test(text)) built = { rule: /\b(at least|min(?:imum)?|more than|over|no fewer than)\b/i.test(text) ? 'minWords' : 'maxWords', value: words[0] };
155
+ if (built === null) return null;
156
+ const res = keepOrDrop(text, built);
157
+ return res.kept ? res.check : null;
158
+ }
159
+
160
+ /** a part of a rubric-step stage, from a pick: the check's own fields, the rule's words, and the `~` rule numbers it carries out @param {Record<string, any>} check @param {string} text @param {number[]} rules */
161
+ export function partOfPick(check, text, rules) {
162
+ const { rule, ...fields } = check;
163
+ return { text, class: 'countable', check: rule, ...fields, rules };
164
+ }
165
+
@@ -0,0 +1,19 @@
1
+ // borrowed-from: bareloop src/panel/jobplan.js@v0.56.0 (3383cce) (planFromConfirm: the card's suggested list and the checks under each line, from the block's own readers)
2
+ // M16 P4 item 4 (docs/wiki/the-module-ladder.md, "M16" item 5): what the plan card shows of the list, written ONCE at draft time from the block's own rows (`renderCard`, `suggestedView`)
3
+ // and kept in the draft's log.json as `checkCard`. The page only draws it (bareloop src/panel/jobplan.js@v0.56.0 reads the same two readers); it never decides a check.
4
+ // What this throws away: the rows' proofs (`can`, `pick`, parts). Only the words, the tag, the reason and whether a Drop is offered survive.
5
+ import { renderCard } from './checkblock.js';
6
+
7
+ /**
8
+ * @param {import('./checkblock.js').CheckBlock} block
9
+ * @returns {{rows: {key: string, line: number, by: string, state: string, text: string, reason: string|null, drop: boolean}[], suggested: {key: string, line: number, text: string, dropped?: boolean}[]}}
10
+ */
11
+ export function cardOfBlock(block) {
12
+ const dropOffered = new Set(block.rows.filter((r) => r.state === 'built' && block.isBang(r)).map((r) => r.key));
13
+ return {
14
+ rows: renderCard(block.rows).map((r) => ({
15
+ key: r.key, line: r.line, by: r.by, state: r.state, text: r.text.replace(/^[~!$] /, ''), reason: r.reason ?? null, drop: dropOffered.has(r.key),
16
+ })),
17
+ suggested: block.suggestedView(),
18
+ };
19
+ }