fwdloop 0.21.0 → 0.23.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/bin/fwdloop +85 -34
- package/package.json +4 -3
- package/src/ask.js +20 -4
- package/src/audit-fold.js +5 -1
- package/src/authoring.js +36 -6
- package/src/canrun.js +5 -0
- package/src/checked.js +32 -4
- package/src/cited-record.js +138 -0
- package/src/cited-source.js +49 -0
- package/src/citedcheck.js +321 -0
- package/src/citedwords.js +197 -0
- package/src/closers.js +37 -198
- package/src/csv.js +69 -12
- package/src/ctx-tools.js +2 -14
- package/src/declaration.js +143 -5
- package/src/diary.js +2 -2
- package/src/docx.js +16 -2
- package/src/draft-steps.js +1 -1
- package/src/drafter.js +322 -33
- package/src/flow.js +33 -7
- package/src/flowmodel.js +21 -0
- package/src/input-facts.js +20 -3
- package/src/model-step.js +38 -21
- package/src/pageask.js +136 -0
- package/src/pagebits.js +107 -0
- package/src/pagedropwords.js +171 -0
- package/src/pagedry.js +120 -0
- package/src/pagefetch.js +164 -0
- package/src/pagelook.js +155 -0
- package/src/pagemap.js +55 -0
- package/src/pageplace.js +103 -0
- package/src/pagerules.js +318 -0
- package/src/panel/author.js +43 -21
- package/src/panel/authorcard.js +20 -3
- package/src/panel/authorflows.js +21 -15
- package/src/panel/authorstart.js +2 -4
- package/src/panel/authortrigger.js +14 -4
- package/src/panel/data.js +102 -6
- package/src/panel/index.html +321 -12
- package/src/panel/result.js +301 -0
- package/src/panel/server.js +27 -3
- package/src/primitives.js +2 -3
- package/src/provider.js +5 -2
- package/src/redact.js +17 -0
- package/src/runner.js +102 -14
- package/src/schedule.js +3 -3
- package/src/setup.js +16 -1
- package/src/sheet-record.js +57 -0
- package/src/sheetblock.js +170 -0
- package/src/sheetchecks.js +206 -0
- package/src/sheetclaims.js +78 -0
- package/src/sheetfind.js +50 -0
- package/src/sheetlook.js +157 -0
- package/src/sheetoffer.js +125 -0
- package/src/sheetrun.js +105 -0
- package/src/signed-text.js +11 -1
- package/src/thinking.js +1 -1
- package/src/try-checks.js +12 -0
- package/src/types.js +4 -11
- package/types/ask.d.ts +2 -1
- package/types/authoring.d.ts +19 -2
- package/types/checked.d.ts +19 -3
- package/types/cited-record.d.ts +21 -0
- package/types/cited-source.d.ts +18 -0
- package/types/citedcheck.d.ts +95 -0
- package/types/citedwords.d.ts +97 -0
- package/types/closers.d.ts +37 -10
- package/types/csv.d.ts +25 -4
- package/types/ctx-tools.d.ts +0 -1
- package/types/declaration.d.ts +20 -1
- package/types/docx.d.ts +14 -0
- package/types/drafter.d.ts +264 -8
- package/types/flow.d.ts +21 -0
- package/types/flowmodel.d.ts +15 -0
- package/types/input-facts.d.ts +12 -2
- package/types/model-step.d.ts +40 -19
- package/types/pageask.d.ts +75 -0
- package/types/pagebits.d.ts +32 -0
- package/types/pagedropwords.d.ts +40 -0
- package/types/pagedry.d.ts +38 -0
- package/types/pagefetch.d.ts +86 -0
- package/types/pagelook.d.ts +75 -0
- package/types/pagemap.d.ts +31 -0
- package/types/pageplace.d.ts +22 -0
- package/types/pagerules.d.ts +86 -0
- package/types/panel/authorcard.d.ts +4 -1
- package/types/panel/authorflows.d.ts +2 -0
- package/types/panel/data.d.ts +26 -0
- package/types/panel/result.d.ts +156 -0
- package/types/provider.d.ts +3 -1
- package/types/redact.d.ts +1 -0
- package/types/runner.d.ts +162 -9
- package/types/schedule.d.ts +0 -11
- package/types/setup.d.ts +13 -0
- package/types/sheet-record.d.ts +24 -0
- package/types/sheetblock.d.ts +116 -0
- package/types/sheetchecks.d.ts +70 -0
- package/types/sheetclaims.d.ts +26 -0
- package/types/sheetfind.d.ts +46 -0
- package/types/sheetlook.d.ts +120 -0
- package/types/sheetoffer.d.ts +25 -0
- package/types/sheetrun.d.ts +35 -0
- package/types/thinking.d.ts +1 -1
- package/types/types.d.ts +27 -14
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
// borrowed-from: bareloop src/factwords.js@2f93962 (keptSetOf, checkFactWords: the page-word path, where the label must be one the page-word map KEPT; bareloop's
|
|
2
|
+
// code-made label list (src/labelscan.js) is the other path and is not copied - a source with no look is refused as unread instead)
|
|
3
|
+
// M10 amendment 7 item 1 (docs/wiki/the-module-ladder.md): the facts a cited step checks are WRITTEN by the drafter and CHECKED by code at $0, before
|
|
4
|
+
// anything is signed. Code refuses, naming the job line, when: a label is not one the page-read kept (label-off-list); a word is not on the page
|
|
5
|
+
// (word-missing); a label shows up fewer times than the result count (label-rare, phrase-rare); a page rule dropped that word (word-dropped). Tighter than
|
|
6
|
+
// bareloop (signed): a number rule that is not in the person's own words on that line (their `~` rule, or a reading they agreed to, which is a `~` line
|
|
7
|
+
// too) is refused (number-unsigned). And, from item 2 (R2c), a place the page-read grew to phrases must have every phrase in the part (place-missing).
|
|
8
|
+
//
|
|
9
|
+
// Pure: no I/O, no model. Compared white-space blind. Third outcome, named: a source with no page-read (md text, a page the look never read) is a red
|
|
10
|
+
// `unread` - a check whose words were never proved against the source is never signed. What this throws away: nothing; every red is a sentence.
|
|
11
|
+
|
|
12
|
+
import { asList, countExact, countPhrase, normLabel, wordsSaidOn } from './pagebits.js';
|
|
13
|
+
import { dropSentence } from './pagedropwords.js';
|
|
14
|
+
import { factsOfLook } from './citedcheck.js';
|
|
15
|
+
|
|
16
|
+
/** @typedef {{code: string, detail: string}} WordRed */
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* What the page-word map KEPT and DROPPED for one input: the sets the proof reads.
|
|
20
|
+
* @param {{facts?: any[], dropped?: any[]}|null|undefined} look @param {string} source
|
|
21
|
+
* @returns {{labels: Set<string>|null, words: Set<string>, dropped: Map<string, any>}|null} null = the page was not read by the map; `labels: null` = a document (no map, any label in the text)
|
|
22
|
+
*/
|
|
23
|
+
export function keptSetOf(look, source) {
|
|
24
|
+
if (!look || !Array.isArray(look.dropped)) return null;
|
|
25
|
+
const facts = (Array.isArray(look.facts) ? look.facts : []).filter((f) => f && f.source === source && Array.isArray(f.words));
|
|
26
|
+
const set = (/** @type {string[]} */ a) => new Set(a.map((w) => normLabel(String(w))));
|
|
27
|
+
/** @type {Map<string, any>} */
|
|
28
|
+
const dropped = new Map();
|
|
29
|
+
for (const d of look.dropped) if (d.source === source && typeof d.word === 'string' && !dropped.has(normLabel(d.word))) dropped.set(normLabel(d.word), d);
|
|
30
|
+
return {
|
|
31
|
+
labels: set(facts.filter((f) => f.shape !== 'phrase').flatMap((f) => f.words)),
|
|
32
|
+
words: set(facts.flatMap((f) => [...f.words, ...(f.phrases ?? []), ...(f.unit ?? []), ...(f.currency ?? [])])),
|
|
33
|
+
dropped,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The reds for ONE fact part against its frozen source text and what the page-word map kept.
|
|
39
|
+
* @param {{part: any, text: string, line: number, kept: NonNullable<ReturnType<typeof keptSetOf>>}} o
|
|
40
|
+
* @returns {WordRed[]}
|
|
41
|
+
*/
|
|
42
|
+
export function factWordReds({
|
|
43
|
+
part, text, line, kept,
|
|
44
|
+
}) {
|
|
45
|
+
/** @type {WordRed[]} */
|
|
46
|
+
const reds = [];
|
|
47
|
+
const src = part.source;
|
|
48
|
+
const red = (/** @type {string} */ code, /** @type {string} */ msg) => reds.push({ code, detail: `line ${line}: ${msg}` });
|
|
49
|
+
for (const f of Array.isArray(part.facts) ? part.facts : []) {
|
|
50
|
+
const who = `fact "${f.name}"`;
|
|
51
|
+
// a word the page rules DROPPED (and no other fact kept) can never come back through the drafter
|
|
52
|
+
const dropRed = (/** @type {string} */ what, /** @type {unknown} */ w) => {
|
|
53
|
+
const n = normLabel(String(w));
|
|
54
|
+
const d = kept.dropped.get(n);
|
|
55
|
+
if (!d || kept.words.has(n)) return false;
|
|
56
|
+
red('word-dropped', `${who}: the ${what} ${JSON.stringify(n)} cannot be used. ${dropSentence(d)}`);
|
|
57
|
+
return true;
|
|
58
|
+
};
|
|
59
|
+
if (f.anchor !== undefined && f.shape !== 'phrase') {
|
|
60
|
+
const label = normLabel(String(f.anchor));
|
|
61
|
+
if (dropRed('label', f.anchor)) { /* said above */ } else if (kept.labels !== null && !kept.labels.has(label)) {
|
|
62
|
+
const some = [...kept.labels].slice(0, 12).map((l) => JSON.stringify(l)).join(', ');
|
|
63
|
+
red('label-off-list', `${who}: the label ${JSON.stringify(label)} is not one of the labels the page words for "${src}" kept. A label is picked from those, never typed${some ? `: ${some}` : ' (there are none - leave the label out)'}.`);
|
|
64
|
+
} else if (countExact(text, label) < 1) {
|
|
65
|
+
red('word-missing', `${who}: the label ${JSON.stringify(label)} is not in the input "${src}".`);
|
|
66
|
+
} else if (Number.isInteger(part.count?.min) && countExact(text, label) < part.count.min) {
|
|
67
|
+
const n = part.count.min;
|
|
68
|
+
const seen = countExact(text, label);
|
|
69
|
+
red('label-rare', `${who}: the label ${JSON.stringify(label)} is in the input "${src}" only ${seen} time${seen === 1 ? '' : 's'}, but this line asks for ${n} results, so a label that sits in each result must be there at least ${n} times. Pick a label that is counted ${n} or more times.`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (f.until !== undefined) dropRed('closing label', f.until);
|
|
73
|
+
if (f.until !== undefined && countExact(text, f.until) < 1) red('word-missing', `${who}: ${JSON.stringify(f.until)} is not in the input "${src}". Copy the closing words from the input, or leave them out.`);
|
|
74
|
+
if (f.shape === 'phrase' && typeof f.phrase === 'string') {
|
|
75
|
+
const seen = countPhrase(text, f.phrase);
|
|
76
|
+
if (seen < 1) red('word-missing', `${who}: ${JSON.stringify(f.phrase)} is not in the input "${src}". Copy the words the input really uses, or remove the check.`);
|
|
77
|
+
else if (Number.isInteger(part.count?.min) && seen < part.count.min) {
|
|
78
|
+
const n = part.count.min;
|
|
79
|
+
red('phrase-rare', `${who}: the words ${JSON.stringify(f.phrase)} are in the input "${src}" only ${seen} time${seen === 1 ? '' : 's'}, but this line asks for ${n} results - each result's own quote must say them. Pick words every result says, or drop this check.`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
for (const u of asList(f.unit)) dropRed('unit', u);
|
|
83
|
+
for (const c of asList(f.currency)) dropRed('currency', c);
|
|
84
|
+
for (const u of asList(f.unit)) if (countPhrase(text, u) < 1) red('word-missing', `${who}: the unit ${JSON.stringify(u)} is not in the input "${src}". Copy the words the input really uses.`);
|
|
85
|
+
for (const c of asList(f.currency)) if (countExact(text, c) < 1) red('word-missing', `${who}: the currency ${JSON.stringify(c)} is not in the input "${src}". Copy the sign the input really uses.`);
|
|
86
|
+
}
|
|
87
|
+
return reds;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The numbers a person said in their words, by KIND. A number inside a time (05:00), a date (2026-11-18) or an amount ($150) is part of that token, not
|
|
92
|
+
* a bare number: "5" is not said by "05:00", "15" and "50" are not said by "$150". (bareloop's `boundInWords` is a substring test and accepts all of those; this
|
|
93
|
+
* reader is ours - FINDINGS-worthy, see the commit.) Times compare without a leading zero on the hour ("05:00" = "5:00"), spaces dropped, case folded.
|
|
94
|
+
* @param {string} text
|
|
95
|
+
* @returns {{bare: Set<number>, amount: Set<number>, time: Set<string>, date: Set<string>}}
|
|
96
|
+
*/
|
|
97
|
+
export function numbersSaid(text) {
|
|
98
|
+
const out = { bare: new Set(), amount: new Set(), time: new Set(), date: new Set() };
|
|
99
|
+
for (const m of String(text).matchAll(/(\d{1,2}:\d{2}(?:\s?[AaPp][Mm])?)|(\d{1,4}[-/.]\d{1,2}[-/.]\d{1,4})|([$\u20ac\u00a3]\s?\d[\d,]*(?:\.\d+)?)|(\d[\d,]*(?:\.\d+)?)/g)) {
|
|
100
|
+
if (m[1]) out.time.add(timeKey(m[1]));
|
|
101
|
+
else if (m[2]) out.date.add(m[2]);
|
|
102
|
+
else if (m[3]) out.amount.add(Number(m[3].replace(/[^\d.]/g, '')));
|
|
103
|
+
else out.bare.add(Number(m[4].replace(/,/g, '')));
|
|
104
|
+
}
|
|
105
|
+
return out;
|
|
106
|
+
}
|
|
107
|
+
/** @param {string} t @returns {string} a time token as compared: no spaces, lower case, no leading zero on the hour */
|
|
108
|
+
const timeKey = (t) => t.replace(/\s+/g, '').toLowerCase().replace(/^0(?=\d:)/, '');
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Tighter than bareloop (signed, am7 item 1): every number in a fact's rule must be in the person's own words on this job line (the line and its `~` rules;
|
|
112
|
+
* an agreed reading is a `~` line too), as the right KIND of token: a money or number bound is a bare number or an amount, a time bound is a time, a date bound
|
|
113
|
+
* is a date. A bound the AI made up, or one that only sits inside another token, is refused.
|
|
114
|
+
* @param {{part: any, jobLine: {n: number, text?: string, rule?: string, rules?: string[]}}} o @returns {WordRed[]}
|
|
115
|
+
*/
|
|
116
|
+
export function numberRuleReds({ part, jobLine }) {
|
|
117
|
+
/** @type {WordRed[]} */
|
|
118
|
+
const reds = [];
|
|
119
|
+
const said = numbersSaid(wordsSaidOn(jobLine));
|
|
120
|
+
const isSaid = (/** @type {string} */ shape, /** @type {unknown} */ b) => {
|
|
121
|
+
if (shape === 'money' || shape === 'number') return typeof b === 'number' && (said.bare.has(b) || said.amount.has(b));
|
|
122
|
+
if (shape === 'time') return typeof b === 'string' && said.time.has(timeKey(b));
|
|
123
|
+
if (shape === 'date') return typeof b === 'string' && said.date.has(b);
|
|
124
|
+
return false;
|
|
125
|
+
};
|
|
126
|
+
for (const f of Array.isArray(part.facts) ? part.facts : []) {
|
|
127
|
+
if (!f.rule || typeof f.rule !== 'object') continue;
|
|
128
|
+
const bounds = f.rule.op === 'between' ? [f.rule.lo, f.rule.hi] : [f.rule.value];
|
|
129
|
+
for (const b of bounds) {
|
|
130
|
+
if (!isSaid(f.shape, b)) {
|
|
131
|
+
reds.push({
|
|
132
|
+
code: 'number-unsigned',
|
|
133
|
+
detail: `line ${jobLine.n}: fact "${f.name}" has the number ${b} in its rule, but ${b} is not in your words on line ${jobLine.n}. A number rule must come from a ~ rule you wrote or a reading you agreed to. Change the ~ rule on line ${jobLine.n} to say it, or leave this rule out.`,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return reds;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const NUMBER_WORDS = Object.freeze({ one: 1, two: 2, three: 3, four: 4, five: 5, six: 6, seven: 7, eight: 8, nine: 9, ten: 10 });
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Signed (am7 item 1): "List 3 ..." is the count, 3 results. A count the person never said as a bare number or a word number (not inside a time, a date or an
|
|
145
|
+
* amount) is refused. Same reader as the number rules.
|
|
146
|
+
* @param {{part: any, jobLine: {n: number, text?: string, rule?: string, rules?: string[]}}} o @returns {WordRed[]}
|
|
147
|
+
*/
|
|
148
|
+
export function countReds({ part, jobLine }) {
|
|
149
|
+
/** @type {WordRed[]} */
|
|
150
|
+
const reds = [];
|
|
151
|
+
const text = wordsSaidOn(jobLine);
|
|
152
|
+
const said = numbersSaid(text).bare;
|
|
153
|
+
for (const w of text.toLowerCase().split(/[^\p{L}\p{N}]+/u)) { const n = NUMBER_WORDS[/** @type {'one'} */ (w)]; if (n !== undefined) said.add(n); }
|
|
154
|
+
const c = part.count && typeof part.count === 'object' ? part.count : {};
|
|
155
|
+
for (const k of ['min', 'max']) {
|
|
156
|
+
if (c[k] === undefined || said.has(c[k])) continue;
|
|
157
|
+
reds.push({ code: 'count-unsigned', detail: `line ${jobLine.n}: the result count has the number ${c[k]}, but ${c[k]} is not in your words on line ${jobLine.n}. The count is the number you asked for ("List 3" is 3 results); say it on the line, or leave the count out.` });
|
|
158
|
+
}
|
|
159
|
+
return reds;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* R2c (am7 item 2): a place the page-read grew to phrases must have EVERY phrase as a phrase fact of the part, or a flipped route passes.
|
|
164
|
+
* @param {{part: any, line: number, look: {facts?: any[]}|null|undefined}} o @returns {WordRed[]}
|
|
165
|
+
*/
|
|
166
|
+
export function placeReds({ part, line, look }) {
|
|
167
|
+
/** @type {WordRed[]} */
|
|
168
|
+
const reds = [];
|
|
169
|
+
const have = new Set((Array.isArray(part.facts) ? part.facts : []).filter((/** @type {any} */ f) => f.shape === 'phrase').map((/** @type {any} */ f) => String(f.phrase)));
|
|
170
|
+
for (const k of Array.isArray(look?.facts) ? look.facts : []) {
|
|
171
|
+
if (k.line !== line || k.source !== part.source || !Array.isArray(k.phrases)) continue;
|
|
172
|
+
for (const f of factsOfLook(k)) {
|
|
173
|
+
if (!have.has(f.phrase)) {
|
|
174
|
+
reds.push({
|
|
175
|
+
code: 'place-missing',
|
|
176
|
+
detail: `line ${line}: the place ${JSON.stringify(k.name)} must be checked with the words ${JSON.stringify(f.phrase)} (the page writes the place with its role: a result that leaves the other way does not say them). Add a phrase fact with exactly those words${k.phrases.length > 1 ? `, and one for each of: ${k.phrases.map((/** @type {string} */ p) => JSON.stringify(p)).join(', ')}` : ''}.`,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return reds;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Every word red for one cited part, in the order a person fixes them.
|
|
186
|
+
* @param {{part: any, text: string|undefined, line: number, jobLine: any, look: {facts?: any[], dropped?: any[]}|null|undefined, doc?: boolean}} o @returns {WordRed[]}
|
|
187
|
+
*/
|
|
188
|
+
export function citedWordReds({
|
|
189
|
+
part, text, line, jobLine, look, doc = false,
|
|
190
|
+
}) {
|
|
191
|
+
// M10 piece 5 (item 2): a DOCUMENT has no page-word map; its words are proved on its text alone (a label need not be one a map kept)
|
|
192
|
+
const kept = doc ? { labels: null, words: new Set(), dropped: new Map() } : keptSetOf(look, part.source);
|
|
193
|
+
if (typeof text !== 'string' || kept === null) {
|
|
194
|
+
return [{ code: 'unread', detail: `line ${line}: the input "${part.source}" was not read here to prove the words against it, so a check on it cannot be drafted. A check on quotes works on a saved web page.` }];
|
|
195
|
+
}
|
|
196
|
+
return [...factWordReds({ part, text, line, kept }), ...numberRuleReds({ part, jobLine }), ...countReds({ part, jobLine }), ...placeReds({ part, line, look })];
|
|
197
|
+
}
|
package/src/closers.js
CHANGED
|
@@ -2,40 +2,21 @@
|
|
|
2
2
|
// SIGNED", scope item 4): `closeByClass(step, artifact, ctx)` — the
|
|
3
3
|
// deterministic, $0 close, dispatched on the step's declared `close.class`.
|
|
4
4
|
//
|
|
5
|
-
// borrowed-from: fwdloop poc/m0/
|
|
6
|
-
// grammar sum/count/min/max/sub/daysBetween; `parseNumeric`/`roundTo` —
|
|
7
|
-
// compare a stated figure to its source at the SOURCE's own decimal
|
|
8
|
-
// precision, never the stated figure's) and fwdloop poc/m0/shape.mjs@29caa83
|
|
5
|
+
// borrowed-from: fwdloop poc/m0/shape.mjs@29caa83
|
|
9
6
|
// (`closeWordsAndSections`, F38 version — every failing check reported, not
|
|
10
7
|
// just the first). Rewritten against M2's own typed artifact contract below
|
|
11
8
|
// — src/ never imports from poc/ (CLAUDE.md: "borrow, never import").
|
|
9
|
+
// (The M0 cell-cite grammar - sum/count/min/max/sub/daysBetween over `<input>!C3` cites - retired in M10b piece 5, item 8.)
|
|
12
10
|
//
|
|
13
11
|
// ---------------------------------------------------------------------------
|
|
14
12
|
// Artifact contracts (M2 scope item 4's own docblock requirement).
|
|
15
13
|
// ---------------------------------------------------------------------------
|
|
16
14
|
//
|
|
17
|
-
// GREEN step artifact:
|
|
18
|
-
// -
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
// artifact already in `ctx.reads`
|
|
23
|
-
// (e.g. "aging_cells!E2").
|
|
24
|
-
// "<formula>(<arg>[,<arg>...])" formula ∈ {sum,count,min,max,sub,
|
|
25
|
-
// daysBetween}; each <arg> is a cell
|
|
26
|
-
// cite OR "#<fieldName>" naming an
|
|
27
|
-
// EARLIER field of this SAME
|
|
28
|
-
// artifact (fields resolve in
|
|
29
|
-
// declared order, never forward —
|
|
30
|
-
// same flat shape M0's citation-id
|
|
31
|
-
// inputs used; formulas never
|
|
32
|
-
// nest inside one string).
|
|
33
|
-
// `daysBetween(cite)` (one arg) computes days between that date and
|
|
34
|
-
// `ctx.businessDate`; `daysBetween(cite,cite)` (two args) computes days
|
|
35
|
-
// between the two — never a third form.
|
|
36
|
-
// A malformed field or an artifact shaped wrong is `unparseable` (a
|
|
37
|
-
// casualty, never a red — bareloop F17); an internal error while
|
|
38
|
-
// resolving is `crash`.
|
|
15
|
+
// GREEN step artifact: one of two forms, each with its own closer.
|
|
16
|
+
// - a page or document quote: `{ results: [...] }` (`closeCited`, bareguard's `cited` check);
|
|
17
|
+
// - a sheet: one typed claim box per `cells` check (`closeSheet`, src/sheetrun.js, bareguard's `cells` / `table` checks).
|
|
18
|
+
// A green step with neither `close.cited` nor `close.sheet` is the retired cell cite: `closeByClass` answers `crash`, and a job signed that way is refused
|
|
19
|
+
// at start (src/canrun.js `findUnbuildableCheckStep`) before it can get here.
|
|
39
20
|
//
|
|
40
21
|
// SOFTGREEN (compose) step artifact: `{ text: string }`
|
|
41
22
|
// - `text` is the whole composed text; `maxWords`/`sections`/`wordsPerSection` run over it directly. Since M4e amendment 18 these
|
|
@@ -63,191 +44,45 @@
|
|
|
63
44
|
// signed text).
|
|
64
45
|
|
|
65
46
|
import { createRubric, checkStep } from 'bareguard';
|
|
47
|
+
import { checkCited } from './citedcheck.js';
|
|
48
|
+
import { closeSheet } from './sheetrun.js';
|
|
66
49
|
|
|
67
50
|
/** @typedef {import('./types.js').CloseVerdict} CloseVerdict */
|
|
68
51
|
|
|
69
|
-
const FORMULAS = Object.freeze({
|
|
70
|
-
sum: (vals) => vals.reduce((a, b) => a + b, 0),
|
|
71
|
-
count: (vals) => vals.length,
|
|
72
|
-
min: (vals) => Math.min(...vals),
|
|
73
|
-
max: (vals) => Math.max(...vals),
|
|
74
|
-
sub: (vals) => vals[0] - vals[1],
|
|
75
|
-
});
|
|
76
|
-
|
|
77
52
|
/** An input with cells (M4d amendment 8): a file whose name ends `.csv`. The one decider for "this input can be cited". */
|
|
78
53
|
export function isCellsPath(p) {
|
|
79
54
|
return typeof p === 'string' && p.toLowerCase().endsWith('.csv');
|
|
80
55
|
}
|
|
81
56
|
|
|
82
|
-
const CELL_RE = /^([a-zA-Z0-9_-]+)!([A-Za-z]+)(\d+)$/;
|
|
83
|
-
const FORMULA_RE = /^(sum|count|min|max|sub|daysBetween)\((.*)\)$/;
|
|
84
|
-
const FIELD_REF_RE = /^#([A-Za-z0-9_]+)$/;
|
|
85
|
-
const ISO_DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
86
|
-
|
|
87
|
-
function colIndexOf(col) {
|
|
88
|
-
let n = 0;
|
|
89
|
-
for (const ch of col.toUpperCase()) n = n * 26 + (ch.charCodeAt(0) - 64);
|
|
90
|
-
return n - 1;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/** Strip thousands separators / currency symbols; report the value and the source's own decimal precision. */
|
|
94
|
-
function parseNumeric(raw) {
|
|
95
|
-
const cleaned = String(raw).replace(/[$,]/g, '').trim();
|
|
96
|
-
const value = Number(cleaned);
|
|
97
|
-
const dot = cleaned.indexOf('.');
|
|
98
|
-
const decimals = dot === -1 ? 0 : cleaned.length - dot - 1;
|
|
99
|
-
return { value, decimals };
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function roundTo(n, decimals) {
|
|
103
|
-
const f = 10 ** decimals;
|
|
104
|
-
return Math.round(n * f) / f;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function getCellRaw(artifact, col, row) {
|
|
108
|
-
const found = (artifact.rows ?? []).find((r) => r.rowNumber === row);
|
|
109
|
-
if (!found) return null;
|
|
110
|
-
return found.cells?.[col.toUpperCase()] ?? null;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
57
|
/**
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*/
|
|
121
|
-
function resolveCite(cite, ctx) {
|
|
122
|
-
if (typeof cite !== 'string' || cite.length === 0) {
|
|
123
|
-
return { ok: false, red: `cite must be a non-empty string, got ${JSON.stringify(cite)}` };
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const cellMatch = CELL_RE.exec(cite);
|
|
127
|
-
if (cellMatch) {
|
|
128
|
-
const [, artifactId, col, rowStr] = cellMatch;
|
|
129
|
-
const artifact = ctx.reads?.[artifactId];
|
|
130
|
-
if (!artifact) return { ok: false, red: `cite "${cite}": unknown artifact "${artifactId}"` };
|
|
131
|
-
if (artifact.kind !== 'cells' && artifact.kind !== 'csv') {
|
|
132
|
-
return { ok: false, red: `cite "${cite}": artifact "${artifactId}" is not a cells/csv-kind read` };
|
|
133
|
-
}
|
|
134
|
-
if (colIndexOf(col) < 0) return { ok: false, red: `cite "${cite}": "${col}" is not a valid column` };
|
|
135
|
-
const row = Number(rowStr);
|
|
136
|
-
const raw = getCellRaw(artifact, col, row);
|
|
137
|
-
if (raw === null) return { ok: false, red: `cite "${cite}": cell ${col}${row} does not exist in "${artifactId}"` };
|
|
138
|
-
return { ok: true, raw };
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const fieldMatch = FIELD_REF_RE.exec(cite);
|
|
142
|
-
if (fieldMatch) {
|
|
143
|
-
const name = fieldMatch[1];
|
|
144
|
-
if (!Object.prototype.hasOwnProperty.call(ctx.fieldsSoFar ?? {}, name)) {
|
|
145
|
-
return { ok: false, red: `cite "${cite}": field "${name}" is not resolved yet (fields resolve top to bottom, never forward)` };
|
|
146
|
-
}
|
|
147
|
-
return { ok: true, raw: ctx.fieldsSoFar[name].value };
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const formulaMatch = FORMULA_RE.exec(cite);
|
|
151
|
-
if (formulaMatch) {
|
|
152
|
-
const [, op, argsRaw] = formulaMatch;
|
|
153
|
-
const argCites = argsRaw.split(',').map((s) => s.trim()).filter((s) => s.length > 0);
|
|
154
|
-
|
|
155
|
-
if (op === 'daysBetween') {
|
|
156
|
-
if (argCites.length < 1 || argCites.length > 2) {
|
|
157
|
-
return { ok: false, red: `cite "${cite}": daysBetween takes 1 or 2 args, got ${argCites.length}` };
|
|
158
|
-
}
|
|
159
|
-
const resolved = [];
|
|
160
|
-
for (const arg of argCites) {
|
|
161
|
-
const r = resolveCite(arg, ctx);
|
|
162
|
-
if (!r.ok) return r;
|
|
163
|
-
resolved.push(r.raw);
|
|
164
|
-
}
|
|
165
|
-
const fromDate = resolved[0];
|
|
166
|
-
const toDate = argCites.length === 2 ? resolved[1] : ctx.businessDate;
|
|
167
|
-
if (!ISO_DATE_RE.test(String(fromDate)) || !ISO_DATE_RE.test(String(toDate))) {
|
|
168
|
-
return { ok: false, red: `cite "${cite}": daysBetween needs ISO (YYYY-MM-DD) dates, got "${fromDate}"/"${toDate}"` };
|
|
169
|
-
}
|
|
170
|
-
const days = Math.round((Date.parse(`${toDate}T00:00:00Z`) - Date.parse(`${fromDate}T00:00:00Z`)) / 86400000);
|
|
171
|
-
return { ok: true, computed: days };
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
const fn = FORMULAS[op];
|
|
175
|
-
if (!fn) return { ok: false, red: `cite "${cite}": unknown formula "${op}" (closed grammar: sum,count,min,max,sub,daysBetween)` };
|
|
176
|
-
const vals = [];
|
|
177
|
-
for (const arg of argCites) {
|
|
178
|
-
const r = resolveCite(arg, ctx);
|
|
179
|
-
if (!r.ok) return r;
|
|
180
|
-
const num = r.computed !== undefined ? r.computed : parseNumeric(r.raw).value;
|
|
181
|
-
if (Number.isNaN(num)) return { ok: false, red: `cite "${cite}": arg "${arg}" does not resolve to a number` };
|
|
182
|
-
vals.push(num);
|
|
183
|
-
}
|
|
184
|
-
return { ok: true, computed: fn(vals) };
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
return { ok: false, red: `cite "${cite}" does not match the cell or formula grammar` };
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
function checkField(name, field, ctx) {
|
|
191
|
-
if (!field || typeof field !== 'object' || field.value === undefined || typeof field.cite !== 'string') {
|
|
192
|
-
return { verdict: 'red', red: `field "${name}" must be an object {value, cite:string}, got ${JSON.stringify(field)}` };
|
|
193
|
-
}
|
|
194
|
-
const resolved = resolveCite(field.cite, ctx);
|
|
195
|
-
if (!resolved.ok) return { verdict: 'red', red: `field "${name}": ${resolved.red}` };
|
|
196
|
-
|
|
197
|
-
if (resolved.computed !== undefined) {
|
|
198
|
-
if (Number(field.value) !== resolved.computed) {
|
|
199
|
-
return { verdict: 'red', red: `field "${name}" ${field.value} ≠ ${field.cite} = ${resolved.computed}` };
|
|
200
|
-
}
|
|
201
|
-
return { verdict: 'green' };
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
const raw = resolved.raw;
|
|
205
|
-
if (ISO_DATE_RE.test(String(field.value))) {
|
|
206
|
-
if (String(field.value) !== String(raw)) {
|
|
207
|
-
return { verdict: 'red', red: `field "${name}" ${field.value} ≠ cite ${field.cite} = ${raw}` };
|
|
208
|
-
}
|
|
209
|
-
return { verdict: 'green' };
|
|
210
|
-
}
|
|
211
|
-
const { value: numVal, decimals } = parseNumeric(raw);
|
|
212
|
-
if (Number.isNaN(numVal)) {
|
|
213
|
-
if (String(field.value).trim() !== String(raw).trim()) {
|
|
214
|
-
return { verdict: 'red', red: `field "${name}" ${field.value} ≠ cite ${field.cite} = ${raw}` };
|
|
215
|
-
}
|
|
216
|
-
return { verdict: 'green' };
|
|
217
|
-
}
|
|
218
|
-
if (roundTo(Number(field.value), decimals) !== roundTo(numVal, decimals)) {
|
|
219
|
-
return { verdict: 'red', red: `field "${name}" ${field.value} ≠ cite ${field.cite} = ${numVal}` };
|
|
220
|
-
}
|
|
221
|
-
return { verdict: 'green' };
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* `green` close: every field in `artifact.fields`, in declared order,
|
|
226
|
-
* resolves and matches its cite. First red wins.
|
|
58
|
+
* M10 piece 4 (item 2, "green grows"): the green close of a step that cites quotes instead of cells. `part` is the step's fact part (`close.cited`, set by
|
|
59
|
+
* code from the page look's kept facts, never by the model); `source` is the run's OWN frozen copy of the page or doc (`readRunSource`); the artifact is
|
|
60
|
+
* `{ results: [{ quote, values: { <fact name>: "<value as the quote writes it>" } }] }`. bareguard's `cited` check proves each quote is word for word in
|
|
61
|
+
* the frozen text, each value is in its quote and passes its rule, and the number of results is as signed. No model grades.
|
|
62
|
+
* Third outcomes, each named, never green: no readable source or an artifact that is not an object (`unparseable`, a casualty), a part bareguard cannot sign
|
|
63
|
+
* (`crash`). `cited` carries what the runner writes to the run's cited-check record: the part and the check's own answer.
|
|
227
64
|
*
|
|
65
|
+
* @param {any} part
|
|
228
66
|
* @param {any} artifact
|
|
229
|
-
* @param {{
|
|
230
|
-
* @returns {CloseVerdict}
|
|
67
|
+
* @param {{ok: true, text: string, sha256: string}|{ok: false, red: string}|null|undefined} source
|
|
68
|
+
* @returns {Promise<CloseVerdict>}
|
|
231
69
|
*/
|
|
232
|
-
export function
|
|
70
|
+
export async function closeCited(part, artifact, source) {
|
|
233
71
|
try {
|
|
234
|
-
if (!
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
const names = Object.keys(artifact.fields);
|
|
238
|
-
if (names.length === 0) {
|
|
239
|
-
return /** @type {CloseVerdict} */ ({ verdict: 'unparseable', red: 'green artifact has no fields' });
|
|
72
|
+
if (!source || source.ok !== true) {
|
|
73
|
+
const red = source && source.ok === false ? source.red : `input "${part?.source}": the run gave the check no saved copy to read`;
|
|
74
|
+
return /** @type {CloseVerdict} */ ({ verdict: 'unparseable', red: `cited close: ${red}`, cited: { part, check: { verdict: 'stopped', gapLines: [], fault: red, sha256: '', claims: [], evidence: [] } } });
|
|
240
75
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
for (const name of names) {
|
|
244
|
-
const result = checkField(name, artifact.fields[name], { reads: ctx.reads, fieldsSoFar, businessDate: ctx.businessDate });
|
|
245
|
-
if (result.verdict === 'red') return /** @type {CloseVerdict} */ (result);
|
|
246
|
-
fieldsSoFar[name] = artifact.fields[name];
|
|
76
|
+
if (!artifact || typeof artifact !== 'object' || Array.isArray(artifact)) {
|
|
77
|
+
return /** @type {CloseVerdict} */ ({ verdict: 'unparseable', red: 'cited artifact must be an object shaped {results: [{quote, values}]}' });
|
|
247
78
|
}
|
|
248
|
-
|
|
79
|
+
const check = await checkCited({ part, text: source.text, results: artifact.results });
|
|
80
|
+
const cited = { part, check, results: artifact.results };
|
|
81
|
+
if (check.verdict === 'green') return /** @type {CloseVerdict} */ ({ verdict: 'green', red: null, cited });
|
|
82
|
+
if (check.verdict === 'red') return /** @type {CloseVerdict} */ ({ verdict: 'red', red: check.gapLines.join('\n'), cited });
|
|
83
|
+
return /** @type {CloseVerdict} */ ({ verdict: 'crash', red: `cited close stopped: ${check.fault}`, cited });
|
|
249
84
|
} catch (err) {
|
|
250
|
-
return { verdict: 'crash', red: `
|
|
85
|
+
return /** @type {CloseVerdict} */ ({ verdict: 'crash', red: `cited close crashed: ${err.message}` });
|
|
251
86
|
}
|
|
252
87
|
}
|
|
253
88
|
|
|
@@ -429,14 +264,18 @@ export async function closeSoftgreen(artifact, shape) {
|
|
|
429
264
|
/**
|
|
430
265
|
* The one dispatcher — `close by declared class` (M2 scope item 4).
|
|
431
266
|
*
|
|
432
|
-
* @param {{ close?: { class?: string, shape?: Record<string, any
|
|
267
|
+
* @param {{ close?: { class?: string, shape?: Record<string, any>, cited?: any, columns?: {source: string, column: string}[], sheet?: any[] } }} step
|
|
433
268
|
* @param {unknown} artifact
|
|
434
|
-
* @param {{ reads: Record<string, any>, businessDate: string }} ctx
|
|
269
|
+
* @param {{ reads: Record<string, any>, businessDate: string, source?: {ok: true, text: string, sha256: string}|{ok: false, red: string}|null, sheet?: any }} ctx
|
|
270
|
+
* `source` (M10 piece 4) = the run's own frozen copy a cited step reads, from `readRunSource`; only a step whose close carries `cited` reads it
|
|
271
|
+
* `sheet` (M10b piece 2) = the run's own tables and recorded `tableSha`s a step with `close.sheet` is checked on, from `readRunSheets`
|
|
435
272
|
* @returns {Promise<CloseVerdict>}
|
|
436
273
|
*/
|
|
437
274
|
export async function closeByClass(step, artifact, ctx) {
|
|
438
275
|
const cls = step?.close?.class;
|
|
439
|
-
if (cls === 'green') return
|
|
276
|
+
if (cls === 'green' && step?.close?.cited) return await closeCited(step.close.cited, artifact, ctx.source);
|
|
277
|
+
if (cls === 'green' && Array.isArray(step?.close?.sheet)) return await closeSheet(step.close.sheet, artifact, ctx.sheet);
|
|
278
|
+
if (cls === 'green') return { verdict: 'crash', red: 'closeByClass: a green step with no close.sheet or close.cited is the retired cell cite' };
|
|
440
279
|
if (cls === 'softgreen') return await closeSoftgreen(artifact, step?.close?.shape ?? {});
|
|
441
280
|
if (cls === 'hitl') return { verdict: 'hitl', red: null };
|
|
442
281
|
return { verdict: 'crash', red: `closeByClass: unknown close class ${JSON.stringify(cls)}` };
|
package/src/csv.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
// borrowed-from: fwdloop poc/m0/csv.mjs@76a3607 (
|
|
2
|
-
// parser
|
|
3
|
-
// doesn't need (dependency hierarchy: stdlib/vanilla first). The addressable
|
|
1
|
+
// borrowed-from: fwdloop poc/m0/csv.mjs@76a3607 (the first reader; M10b item 2 rewrote it to RFC 4180 quoting). Tiny CSV
|
|
2
|
+
// parser (dependency hierarchy: stdlib/vanilla first). The addressable
|
|
4
3
|
// -cells contract (`parseCellRef`/`colLetter`) is fwdloop's own citation
|
|
5
4
|
// grammar (F13, ruled 2026-09-09 — not a baresuite primitive), so it lives
|
|
6
5
|
// with the reader that produces those addresses.
|
|
@@ -32,17 +31,61 @@ export function parseCellRef(cell) {
|
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
34
|
+
* Split CSV text into records (RFC 4180): a cell may be quoted ("1,200.50" is one cell, "" inside quotes is one quote, a comma or a line break inside quotes
|
|
35
|
+
* stays in the cell); LF and CRLF both end a record. Each record carries `line`, the 1-based line of the text it starts on, so a line break inside a quoted
|
|
36
|
+
* cell still counts. A blank line (nothing, not even quotes) is no record, but its line is counted. A quote inside an unquoted cell is just a character.
|
|
37
|
+
* @param {string} text @returns {{line: number, fields: string[]}[]}
|
|
38
|
+
*/
|
|
39
|
+
function records(text) {
|
|
40
|
+
/** @type {{line: number, fields: string[]}[]} */
|
|
41
|
+
const out = [];
|
|
42
|
+
let line = 1;
|
|
43
|
+
let startLine = 1;
|
|
44
|
+
/** @type {string[]} */ let fields = [];
|
|
45
|
+
let cell = '';
|
|
46
|
+
let inQuotes = false;
|
|
47
|
+
let quoted = false; // the current record used a quote: an empty cell then is a real cell, not a blank line
|
|
48
|
+
const endCell = () => { fields.push(cell); cell = ''; };
|
|
49
|
+
const endRecord = () => {
|
|
50
|
+
endCell();
|
|
51
|
+
if (!(fields.length === 1 && fields[0] === '' && !quoted)) out.push({ line: startLine, fields });
|
|
52
|
+
fields = [];
|
|
53
|
+
quoted = false;
|
|
54
|
+
};
|
|
55
|
+
for (let i = 0; i < text.length; i += 1) {
|
|
56
|
+
const ch = text[i];
|
|
57
|
+
if (inQuotes) {
|
|
58
|
+
if (ch === '"') {
|
|
59
|
+
if (text[i + 1] === '"') { cell += '"'; i += 1; } else inQuotes = false;
|
|
60
|
+
} else {
|
|
61
|
+
if (ch === '\n') line += 1;
|
|
62
|
+
cell += ch;
|
|
63
|
+
}
|
|
64
|
+
} else if (ch === '"' && cell === '') { inQuotes = true; quoted = true; }
|
|
65
|
+
else if (ch === ',') endCell();
|
|
66
|
+
else if (ch === '\n' || (ch === '\r' && text[i + 1] === '\n')) {
|
|
67
|
+
if (ch === '\r') i += 1;
|
|
68
|
+
endRecord();
|
|
69
|
+
line += 1;
|
|
70
|
+
startLine = line;
|
|
71
|
+
} else cell += ch;
|
|
72
|
+
}
|
|
73
|
+
if (cell !== '' || fields.length > 0 || quoted) endRecord();
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Parse CSV text into { header, rows } (RFC 4180 quoting, see `records`).
|
|
79
|
+
* `rows[i]` is `{ rowNumber, cells: { A: '...', B: '...' }, byName: { Customer: '...' }, raw: ['...', '...'] }` (`raw` is the row's cells exactly as the file has them: no padding, nothing cut)
|
|
80
|
+
* where `rowNumber` is the real sheet line the row starts on (header is row 1; a blank line is skipped but still counted, so it never shifts the rows below).
|
|
38
81
|
*/
|
|
39
82
|
export function parseCsv(text) {
|
|
40
|
-
const
|
|
41
|
-
if (
|
|
42
|
-
const header =
|
|
83
|
+
const recs = records(text);
|
|
84
|
+
if (recs.length === 0) return { header: [], rows: [] };
|
|
85
|
+
const header = recs[0].fields;
|
|
43
86
|
const rows = [];
|
|
44
|
-
for (let i = 1; i <
|
|
45
|
-
const fields =
|
|
87
|
+
for (let i = 1; i < recs.length; i += 1) {
|
|
88
|
+
const fields = recs[i].fields;
|
|
46
89
|
const cells = {};
|
|
47
90
|
const byName = {};
|
|
48
91
|
header.forEach((name, col) => {
|
|
@@ -51,7 +94,21 @@ export function parseCsv(text) {
|
|
|
51
94
|
cells[letter] = val;
|
|
52
95
|
byName[name] = val;
|
|
53
96
|
});
|
|
54
|
-
rows.push({ rowNumber: i
|
|
97
|
+
rows.push({ rowNumber: recs[i].line, cells, byName, raw: [...fields] });
|
|
55
98
|
}
|
|
56
99
|
return { header, rows };
|
|
57
100
|
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* A parsed sheet as bareguard's table shape: `{ header: string[], rows: [{ rowNumber, cells: string[] }] }`. Each row's cells are the row exactly as the file
|
|
104
|
+
* has it (`raw`): a short or a long row is NOT padded or cut here, so bareguard itself stops it (`tableSha` gives null for a ragged row, and the table is
|
|
105
|
+
* refused). The header strings are exactly as the file has them. The one writer of this shape (M10b item 2).
|
|
106
|
+
* @param {{header: string[], rows: {rowNumber: number, raw: string[]}[]}} sheet from `parseCsv`
|
|
107
|
+
* @returns {{header: string[], rows: {rowNumber: number, cells: string[]}[]}}
|
|
108
|
+
*/
|
|
109
|
+
export function sheetTable(sheet) {
|
|
110
|
+
return {
|
|
111
|
+
header: [...sheet.header],
|
|
112
|
+
rows: sheet.rows.map((r) => ({ rowNumber: r.rowNumber, cells: [...r.raw] })),
|
|
113
|
+
};
|
|
114
|
+
}
|
package/src/ctx-tools.js
CHANGED
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
// - no spine `emit`: model-step already tallies each tool a step called;
|
|
15
15
|
// - `remember`/`forget` are NOT here: memory lasts one run (PRD: no learning
|
|
16
16
|
// between flows), so they stay refused.
|
|
17
|
-
// - redactSecrets
|
|
17
|
+
// - redactSecrets lives in src/redact.js (bareloop's src/validate.js@07215d6 inventory).
|
|
18
18
|
|
|
19
19
|
import path from 'node:path';
|
|
20
20
|
import { createRequire } from 'node:module';
|
|
21
|
-
import {
|
|
21
|
+
import { redactSecrets } from './redact.js';
|
|
22
22
|
import { withRunStore } from './run-store.js';
|
|
23
23
|
|
|
24
24
|
const require = createRequire(import.meta.url);
|
|
@@ -28,18 +28,6 @@ const { compress: compressNode, StalePointerError } = require('litectx');
|
|
|
28
28
|
* because that is what enters the store). Bareloop's number, signed in M7 item 3. */
|
|
29
29
|
export const ISOLATE_MAX_BYTES = 65536;
|
|
30
30
|
|
|
31
|
-
const SECRET_PATTERNS = [
|
|
32
|
-
/(?<![A-Za-z0-9_-])sk-[A-Za-z0-9_-]{16,}/,
|
|
33
|
-
/(?<![A-Za-z0-9_-])ghp_[A-Za-z0-9]{20,}/,
|
|
34
|
-
/(?<![A-Za-z0-9_-])github_pat_[A-Za-z0-9_]{20,}/,
|
|
35
|
-
/(?<![A-Za-z0-9_-])AKIA[0-9A-Z]{16}/,
|
|
36
|
-
/(?<![A-Za-z0-9_-])xox[bap]-[A-Za-z0-9-]{10,}/,
|
|
37
|
-
/(?<![A-Za-z0-9_-])AIza[0-9A-Za-z_-]{35}/,
|
|
38
|
-
];
|
|
39
|
-
|
|
40
|
-
/** Mask known secret shapes. @param {unknown} raw */
|
|
41
|
-
export const redactSecrets = (raw) => redact(String(raw ?? ''), { patterns: SECRET_PATTERNS });
|
|
42
|
-
|
|
43
31
|
const LINE_SPACE = 'Line numbers are 0-based; copy them between recall and get as printed.';
|
|
44
32
|
|
|
45
33
|
/**
|