fwdloop 0.33.0 → 0.34.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 +14 -2
- package/package.json +1 -1
- package/src/auditchecks.js +6 -4
- package/src/authoring.js +4 -3
- package/src/blockasks.js +3 -2
- package/src/blockassemble.js +40 -21
- package/src/blockdraft.js +8 -13
- package/src/blockpick.js +11 -1
- package/src/checkblock.js +95 -56
- package/src/checklist.js +1 -1
- package/src/checklistsign.js +1 -1
- package/src/checkpick.js +7 -73
- package/src/declaration.js +9 -7
- package/src/drafter.js +152 -130
- package/src/noteask.js +62 -0
- package/src/pageask.js +5 -68
- package/src/pagedry.js +27 -4
- package/src/pagerules.js +19 -3
- package/src/panel/author.js +3 -3
- package/src/panel/authorcard.js +34 -11
- package/src/panel/index.html +7 -1
- package/src/pickrecord.js +42 -54
- package/src/planrebuild.js +16 -6
- package/src/rowedit.js +35 -5
- package/src/rubricstep.js +9 -1
- package/src/setup.js +1 -1
- package/src/sheetblock.js +17 -7
- package/src/sheetbuild.js +151 -0
- package/src/sheetchecks.js +3 -2
- package/src/sheetfind.js +4 -4
- package/src/sheetlook.js +14 -3
- package/src/sheetoffer.js +50 -5
- package/src/sheetrows.js +18 -2
- package/src/ticket-draft.js +4 -21
- package/src/ticketrows.js +100 -0
- package/types/auditchecks.d.ts +2 -1
- package/types/authoring.d.ts +4 -2
- package/types/blockasks.d.ts +1 -2
- package/types/blockassemble.d.ts +20 -3
- package/types/blockdraft.d.ts +4 -12
- package/types/blockpick.d.ts +5 -0
- package/types/checkblock.d.ts +32 -17
- package/types/checklist.d.ts +3 -3
- package/types/checkpick.d.ts +4 -34
- package/types/declaration.d.ts +7 -0
- package/types/drafter.d.ts +15 -355
- package/types/noteask.d.ts +52 -0
- package/types/pageask.d.ts +0 -35
- package/types/pagedry.d.ts +13 -0
- package/types/pagerules.d.ts +7 -0
- package/types/panel/authorcard.d.ts +13 -8
- package/types/panel/authorflows.d.ts +4 -4
- package/types/panel/data.d.ts +1 -1
- package/types/pickrecord.d.ts +47 -13
- package/types/rowedit.d.ts +16 -1
- package/types/rubricstep.d.ts +3 -0
- package/types/sheetblock.d.ts +11 -4
- package/types/sheetbuild.d.ts +84 -0
- package/types/sheetchecks.d.ts +2 -1
- package/types/sheetfind.d.ts +2 -2
- package/types/sheetoffer.d.ts +26 -1
- package/types/sheetrows.d.ts +8 -0
- package/types/ticket-draft.d.ts +3 -49
- package/types/ticketrows.d.ts +61 -0
- package/src/repairs.js +0 -38
- package/types/repairs.d.ts +0 -13
package/src/noteask.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// borrowed-from: bareloop src/noteask.js@v0.57.0 (c18df406) (NOTE_SYSTEM, the question's wording, decideNote's reading of the typed answer; the call itself is fwd's forced tool turn, src/drafter.js forcedTurn, not bareloop's text reply)
|
|
2
|
+
// The note question (M17 am1 1(e)). A facts-only line ("find these on the page") may also ask for written words ("and write a one-sentence note"). Code cannot read that from the line, so the AI is
|
|
3
|
+
// asked ONCE per draft, only when a line is facts-only: yes or no per line, typed. CODE decides what it means (src/checkblock.js buildNote: a `$` note row and a countable nonEmpty part, so the step
|
|
4
|
+
// is told to write `text`). The AI sees the numbered line text only, never a `~` rule. A call with no usable answer leaves each asked line facts-only with a Not checked row, never a guess.
|
|
5
|
+
// What this throws away: everything but yes/no per asked line (a line it was not asked about, any other field).
|
|
6
|
+
|
|
7
|
+
/** the label of the forced turn, as the draft's log and the replay in src/planrebuild.js see it */
|
|
8
|
+
export const NOTE_KIND = 'note-ask';
|
|
9
|
+
export const NOTE_TOOL = 'answer_note_question';
|
|
10
|
+
|
|
11
|
+
export const NOTE_SYSTEM = 'You read the numbered lines of a job. You answer only about what each line says; you never invent words.';
|
|
12
|
+
|
|
13
|
+
export const NOTE_SCHEMA = Object.freeze({
|
|
14
|
+
type: 'object',
|
|
15
|
+
properties: {
|
|
16
|
+
lines: {
|
|
17
|
+
type: 'array',
|
|
18
|
+
items: {
|
|
19
|
+
type: 'object',
|
|
20
|
+
properties: { line: { type: 'integer', minimum: 1, description: 'the job line number' }, writtenWords: { enum: ['yes', 'no'] } },
|
|
21
|
+
required: ['line', 'writtenWords'],
|
|
22
|
+
additionalProperties: false,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
required: ['lines'],
|
|
27
|
+
additionalProperties: false,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
/** What the AI is told: the numbered job lines (text only) and the one question. @param {{n: number, text: string}[]} lines @returns {string} */
|
|
31
|
+
export function notePrompt(lines) {
|
|
32
|
+
return `THE JOB:\n${lines.map((l) => `LINE ${l.n}: ${l.text}`).join('\n')}\n\n`
|
|
33
|
+
+ 'For EACH line answer ONE question: does the line also ask for written words (a note, a sentence, a paragraph, a summary) beyond the facts found on the page (items, numbers, dates, quoted words)? '
|
|
34
|
+
+ 'A line that only asks to list, find or give items with their fields is "no". '
|
|
35
|
+
+ `Call ${NOTE_TOOL} once with one entry per line: {"line": <line number>, "writtenWords": "yes" or "no"}. `
|
|
36
|
+
+ 'Example: for "LINE 1: List the 3 newest posts with title and date" and "LINE 2: Write a two-sentence recap of the newest post" the entries are line 1 "no" and line 2 "yes".';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Code reads the typed answer: every asked line answered exactly yes or no, else null (no repair). An answer for a line not asked is unreadable too.
|
|
41
|
+
* @param {any} args the tool's arguments @param {{n: number}[]} lines @returns {Map<number, 'yes'|'no'>|null}
|
|
42
|
+
*/
|
|
43
|
+
export function decideNote(args, lines) {
|
|
44
|
+
if (args === null || typeof args !== 'object' || !Array.isArray(args.lines)) return null;
|
|
45
|
+
/** @type {Map<number, 'yes'|'no'>} */
|
|
46
|
+
const out = new Map();
|
|
47
|
+
for (const e of args.lines) {
|
|
48
|
+
if (e === null || typeof e !== 'object' || !Number.isInteger(e.line) || (e.writtenWords !== 'yes' && e.writtenWords !== 'no') || !lines.some((l) => l.n === e.line)) return null;
|
|
49
|
+
out.set(e.line, e.writtenWords);
|
|
50
|
+
}
|
|
51
|
+
return lines.every((l) => out.has(l.n)) ? out : null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The answers per asked line as the block reads them: the typed answer, or `failed` for every asked line when there is none. ONE function, shared by the draft and the replay.
|
|
56
|
+
* @param {number[]} asked the facts-only lines asked @param {any} args the tool's arguments, or null @param {{n: number}[]} lines
|
|
57
|
+
* @returns {{line: number, answer: 'yes'|'no'|'failed'}[]}
|
|
58
|
+
*/
|
|
59
|
+
export function noteAnswers(asked, args, lines) {
|
|
60
|
+
const d = args === null ? null : decideNote(args, lines.filter((l) => asked.includes(l.n)));
|
|
61
|
+
return asked.map((n) => ({ line: n, answer: d?.get(n) ?? 'failed' }));
|
|
62
|
+
}
|
package/src/pageask.js
CHANGED
|
@@ -1,21 +1,8 @@
|
|
|
1
|
-
// borrowed-from: bareloop src/pagemap.js@0a34846 (DROP_IT, isDropIt, isAgree, readingQuestion, readingOfQuestion,
|
|
1
|
+
// borrowed-from: bareloop src/pagemap.js@0a34846 (DROP_IT, isDropIt, isAgree, readingQuestion, readingOfQuestion, tooManyAsksText)
|
|
2
2
|
// borrowed-from: bareloop src/facts.js@0a34846 (ruleWords, sayBound, moneyAs)
|
|
3
3
|
// borrowed-from: bareloop src/pagemap.js@v0.49.0 (d51a367) (stripAgreeLead, F240; adapted: literal regex, src/ bans new RegExp)
|
|
4
|
-
//
|
|
5
|
-
// result. The model never decides whether to ask: this file reads a kept fact's own keys (line, forRule, name, shape, unit, currency, reading) and the job
|
|
6
|
-
// lines, and nothing else (test/m10-pageask.test.js greps for it). The question words are bareloop's, verbatim (am5 item 1); the answer words are
|
|
7
|
-
// agree / yes (code's reading), your own words, and, for a can't-check ask only, "drop it" (am2 item 2).
|
|
8
|
-
// Every rule is one of three kinds:
|
|
9
|
-
// PAGE: a kept page word carries it: no ask.
|
|
10
|
-
// READING: a kept fact carries it with a `reading` (a limit the page cannot hold in words, e.g. "not a red-eye"). Asked only when a bound of the
|
|
11
|
-
// reading is NOT in the words the person wrote; a bound they wrote themselves is theirs and nothing is asked.
|
|
12
|
-
// CAN'T CHECK: no kept fact carries it.
|
|
13
|
-
// A COUNT guardrail (declaration.js isCountGuardrail) is none of these: it is asked once, as a pick (M10 am24).
|
|
14
|
-
// Throws away: a fact's name, words and source (only its reading and the rule it serves are used).
|
|
4
|
+
// The words of the asks and of the answers to them. M17 am4 (A1): the asks themselves come from the list (src/blockasks.js); the page-look ask path that sat here is gone.
|
|
15
5
|
import { redactSecrets } from './redact.js';
|
|
16
|
-
import { lineRules, boundInWords, wordsSaidOn } from './pagebits.js';
|
|
17
|
-
import { validReading } from './pagerules.js';
|
|
18
|
-
import { isCountGuardrail } from './declaration.js';
|
|
19
6
|
import { HOW_TO_ANSWER } from './checkpick.js';
|
|
20
7
|
import { columnTail } from './sheetfind.js';
|
|
21
8
|
|
|
@@ -44,9 +31,6 @@ export const stripAgreeLead = (text) => {
|
|
|
44
31
|
return m ? m[1].trim() : String(text ?? '');
|
|
45
32
|
};
|
|
46
33
|
|
|
47
|
-
/** @typedef {{line: number, rule: number, source: 'look', question: string, ask: 'reading'|'cant-check', ruleText: string, reading?: string}} LookAsk
|
|
48
|
-
* `reading` = the plain words an `agree` writes as a `~` rule (a reading ask only) */
|
|
49
|
-
|
|
50
34
|
/** @param {unknown} n @param {string} shape @param {any} f @returns {string} one bound, as the person would say it */
|
|
51
35
|
function sayBound(n, shape, f) {
|
|
52
36
|
if (shape === 'money') return moneyAs(f, /** @type {string|number} */ (n), false);
|
|
@@ -77,9 +61,9 @@ const READING_ASKED = '. Agree?';
|
|
|
77
61
|
const READING_ANSWER = ' Answer "agree"';
|
|
78
62
|
const READING_TAIL = `${READING_ASKED}${READING_ANSWER}`;
|
|
79
63
|
/** @param {number} n @returns {string} the rest of a reading ask after its answer words */
|
|
80
|
-
const readingRest = (n) => `, or type your own reading (your answer
|
|
64
|
+
const readingRest = (n) => `, or type your own reading (your answer replaces that ~ rule on line ${n}).`;
|
|
81
65
|
/** @param {number} n @returns {string} the answer words a can't-check ask ends with (said once, here, and cut in the panel) */
|
|
82
|
-
const cantCheckTail = (n) => ` Answer "${DROP_IT}", or type how to check it (your answer
|
|
66
|
+
const cantCheckTail = (n) => ` Answer "${DROP_IT}", or type how to check it (your answer replaces that ~ rule on line ${n}).`;
|
|
83
67
|
/** @param {number} n @param {string} rule @param {string} reading @returns {string} */
|
|
84
68
|
export const readingQuestion = (n, rule, reading) => `Your line ${n} says "${rule}".${READING_HEAD}${reading}${READING_TAIL}${readingRest(n)}`;
|
|
85
69
|
// borrowed-from: bareloop src/pagemap.js@v0.56.0 (3383cce) (cantCheckQuestion; readingQuestion above is exported for the block's asks)
|
|
@@ -101,58 +85,11 @@ export function readingOfQuestion(q) {
|
|
|
101
85
|
export function panelQuestionText(q) {
|
|
102
86
|
const text = String(q.question);
|
|
103
87
|
if (q.source !== 'look') return text;
|
|
104
|
-
const tails = [`${READING_ANSWER}${readingRest(q.line)}`, cantCheckTail(q.line), columnTail(q.line), ` ${HOW_TO_ANSWER(q.line, true)}`, ` ${HOW_TO_ANSWER(q.line, false)}`];
|
|
88
|
+
const tails = [`${READING_ANSWER}${readingRest(q.line)}`, cantCheckTail(q.line), columnTail(q.line), columnTail(q.line, true), ` ${HOW_TO_ANSWER(q.line, true)}`, ` ${HOW_TO_ANSWER(q.line, false)}`];
|
|
105
89
|
const hit = tails.find((t) => text.endsWith(t));
|
|
106
90
|
return hit === undefined ? text : text.slice(0, text.length - hit.length);
|
|
107
91
|
}
|
|
108
92
|
|
|
109
|
-
/**
|
|
110
|
-
* The early asks CODE forces before any paid drafting, from the look's own result. One ask per rule text on a line; readings first, then can't-check
|
|
111
|
-
* asks, each in line order. The caller applies the cap and the answer gate.
|
|
112
|
-
* @param {{facts?: {line: number, forRule?: number, name?: string, shape?: string, unit?: string[], currency?: string[], reading?: import('./pagerules.js').Reading}[]}|null|undefined} look
|
|
113
|
-
* @param {{n: number, text?: string, rule?: string, rules?: string[]}[]|null|undefined} jobLines
|
|
114
|
-
* @returns {LookAsk[]}
|
|
115
|
-
*/
|
|
116
|
-
export function askableFromLook(look, jobLines) {
|
|
117
|
-
const facts = Array.isArray(look?.facts) ? look.facts : [];
|
|
118
|
-
/** @type {LookAsk[]} */
|
|
119
|
-
const readings = [];
|
|
120
|
-
/** @type {LookAsk[]} */
|
|
121
|
-
const cants = [];
|
|
122
|
-
/** @type {Set<string>} */
|
|
123
|
-
const seen = new Set();
|
|
124
|
-
for (const l of Array.isArray(jobLines) ? jobLines : []) {
|
|
125
|
-
lineRules(l).forEach((rule, k) => {
|
|
126
|
-
const n = k + 1;
|
|
127
|
-
if (isCountGuardrail(rule)) return; // M10 am24: a count guardrail is asked only as a pick (src/checkpick.js), never as a page question; its look facts stay
|
|
128
|
-
const key = `${l.n}\u0000${rule.trim().toLowerCase()}`;
|
|
129
|
-
const tied = facts.filter((f) => f.line === l.n && f.forRule === n);
|
|
130
|
-
if (tied.length > 0) {
|
|
131
|
-
const said = wordsSaidOn(l);
|
|
132
|
-
const f = tied.find((x) => x.reading && validReading(x.shape, x.reading) && ruleBounds(x.reading).some((b) => !boundInWords(b, said)));
|
|
133
|
-
if (f === undefined || seen.has(key)) return;
|
|
134
|
-
seen.add(key);
|
|
135
|
-
const reading = `${f.name} ${ruleWords({ shape: f.shape, unit: f.unit, currency: f.currency, rule: f.reading })}`;
|
|
136
|
-
readings.push({
|
|
137
|
-
line: l.n, rule: n, source: 'look', ask: 'reading', ruleText: rule, reading,
|
|
138
|
-
question: readingQuestion(l.n, rule, reading),
|
|
139
|
-
});
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
if (seen.has(key)) return;
|
|
143
|
-
seen.add(key);
|
|
144
|
-
cants.push({
|
|
145
|
-
line: l.n, rule: n, source: 'look', ask: 'cant-check', ruleText: rule,
|
|
146
|
-
question: `Your line ${l.n} says "${rule}". I can't check this on the page. Drop it?${cantCheckTail(l.n)}`,
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
return [...readings, ...cants];
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/** @param {import('./pagerules.js').Reading} r @returns {unknown[]} the bounds a reading holds */
|
|
154
|
-
const ruleBounds = (r) => (r.op === 'between' ? [r.lo, r.hi] : [r.value]);
|
|
155
|
-
|
|
156
93
|
/**
|
|
157
94
|
* More asks than the cap means the job needs a rewrite, not a questionnaire. The code-owned stop words list EVERY ask and its reading as the
|
|
158
95
|
* suggestion (no extra paid call). A secret in a rule is masked.
|
package/src/pagedry.js
CHANGED
|
@@ -83,6 +83,31 @@ export async function dryReadMoney(text, facts) {
|
|
|
83
83
|
return { facts: kept, dropped, reads, results };
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
// borrowed-from: bareloop src/pagedry.js@v0.57.0 (c18df406) (resultQuotes, phraseInNoResult: 637e76ad)
|
|
87
|
+
/**
|
|
88
|
+
* The page's RESULT LINES: the lines the given money facts read (`moneyResultLines`), each quote once. Empty when no money fact reads a line (the result lines are then unknown).
|
|
89
|
+
* The one owner of "what is a result row" for phrase facts, shared by the dry read below and by the check list's `!` rows (`phraseInNoResult`).
|
|
90
|
+
* @param {string} text @param {KeptFact[]} facts @returns {string[]}
|
|
91
|
+
*/
|
|
92
|
+
export function resultQuotes(text, facts) {
|
|
93
|
+
/** @type {Set<string>} */
|
|
94
|
+
const quotes = new Set();
|
|
95
|
+
for (const k of facts) if (k.shape === 'money') for (const r of moneyResultLines(text, k)) quotes.add(r.quote);
|
|
96
|
+
return [...quotes];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Is this phrase in the page but in NONE of its result lines (the `phrase-no-result` case)? Sync, for a `!` row the check list is about to build.
|
|
101
|
+
* True only when result lines exist and no line holds the words (case and spacing aside, a plain substring: it never refuses a phrase the run's presence check could pass).
|
|
102
|
+
* With no result line known nothing is guessed (false).
|
|
103
|
+
* @param {string} text @param {KeptFact[]} moneyFacts the line's money facts @param {string} words @returns {boolean}
|
|
104
|
+
*/
|
|
105
|
+
export function phraseInNoResult(text, moneyFacts, words) {
|
|
106
|
+
const rows = resultQuotes(text, moneyFacts);
|
|
107
|
+
const w = words.replace(/\s+/g, ' ').trim().toLowerCase();
|
|
108
|
+
return rows.length > 0 && w !== '' && !rows.some((q) => q.replace(/\s+/g, ' ').toLowerCase().includes(w));
|
|
109
|
+
}
|
|
110
|
+
|
|
86
111
|
/**
|
|
87
112
|
* The same "can it read" for PHRASE facts (bareloop c550dc8; our failure: m10-walk-flights-3, "Rome" was on the page only in "Track prices from Madrid to
|
|
88
113
|
* Rome" switches, in none of the 18 result lines, so no result could ever say it). A kept phrase fact is read against the page's RESULT LINES = the lines
|
|
@@ -94,9 +119,7 @@ export async function dryReadMoney(text, facts) {
|
|
|
94
119
|
* @returns {Promise<{facts: KeptFact[], dropped: Dropped[], reads: Record<string, number>}>} `reads` = result lines that said the phrase, per fact name
|
|
95
120
|
*/
|
|
96
121
|
export async function dryReadPhrases(text, facts) {
|
|
97
|
-
|
|
98
|
-
const quotes = new Set();
|
|
99
|
-
for (const k of facts) if (k.shape === 'money') for (const r of moneyResultLines(text, k)) quotes.add(r.quote);
|
|
122
|
+
const quotes = resultQuotes(text, facts);
|
|
100
123
|
/** @type {KeptFact[]} */
|
|
101
124
|
const kept = [];
|
|
102
125
|
/** @type {Dropped[]} */
|
|
@@ -104,7 +127,7 @@ export async function dryReadPhrases(text, facts) {
|
|
|
104
127
|
/** @type {Record<string, number>} */
|
|
105
128
|
const reads = {};
|
|
106
129
|
for (const k of facts) {
|
|
107
|
-
if (k.shape !== 'phrase' || quotes.
|
|
130
|
+
if (k.shape !== 'phrase' || quotes.length === 0 || !k.words.length) { kept.push(k); continue; }
|
|
108
131
|
const part = { source: SOURCE, facts: factsOfLook({ name: CLAIM, shape: 'phrase', words: [k.words[0]] }) };
|
|
109
132
|
let n = 0;
|
|
110
133
|
for (const quote of quotes) {
|
package/src/pagerules.js
CHANGED
|
@@ -162,6 +162,19 @@ const CURRENCY_SYMBOLS = ['$', '€', '£'];
|
|
|
162
162
|
/** the shapes that read a value after a label */
|
|
163
163
|
const VALUE_SHAPES = ['money', 'time', 'number'];
|
|
164
164
|
|
|
165
|
+
// borrowed-from: bareloop src/pagerules.js@v0.57.0 (c18df406) (withColon, 1583d563)
|
|
166
|
+
/**
|
|
167
|
+
* The ONE owner of a label's separator: the label as the page writes it. The run's checker reads a value right after the signed label, so a page that
|
|
168
|
+
* writes "Departure time: 10:24 AM." can only be read by the label "Departure time:". When EVERY place the page holds the label has a colon right after
|
|
169
|
+
* it, the label is signed with that colon; one bare place leaves it as the look gave it. A plain count of the page's own text, no pattern.
|
|
170
|
+
* @param {string} text the frozen page text @param {string} label a label as normLabel leaves it @returns {string}
|
|
171
|
+
*/
|
|
172
|
+
export function withColon(text, label) {
|
|
173
|
+
if (label.endsWith(':')) return label;
|
|
174
|
+
const n = countExact(text, label);
|
|
175
|
+
return n >= 1 && countExact(text, `${label}:`) === n ? `${label}:` : label;
|
|
176
|
+
}
|
|
177
|
+
|
|
165
178
|
/**
|
|
166
179
|
* Apply the rules to the AI's map over one saved page. Returns the kept facts and, for everything a rule removed, one `dropped` entry.
|
|
167
180
|
* The order of the rules is the POC's (apply-v3.mjs): found-on-page, then the rules that read the page. A place is read as a phrase.
|
|
@@ -208,9 +221,12 @@ export function applyPageRules(text, mapping, jobLines) {
|
|
|
208
221
|
const asListed = [];
|
|
209
222
|
/** U1: labels the page writes after the number */
|
|
210
223
|
const moved = [];
|
|
211
|
-
for (const
|
|
212
|
-
const
|
|
213
|
-
if (!
|
|
224
|
+
for (const w00 of words) {
|
|
225
|
+
const base = normLabel(w00);
|
|
226
|
+
if (!base) continue;
|
|
227
|
+
// a label the page always writes with a colon right after it ("Departure time: 10:24 AM.") is signed as the page writes it (run mwgsl7zx)
|
|
228
|
+
const w = withColon(text, base);
|
|
229
|
+
const w0 = w === base ? w00 : w;
|
|
214
230
|
if (countExact(text, w) < 1) { asListed.push(w0); drop(f, w0, 'not-on-page'); continue; }
|
|
215
231
|
if (amount) {
|
|
216
232
|
const { B, A } = beforeAfter(lines, w);
|
package/src/panel/author.js
CHANGED
|
@@ -798,7 +798,7 @@ export function createAuthor(opts) {
|
|
|
798
798
|
const all = full.map((x) => {
|
|
799
799
|
const typed = x.k === v.openK ? answer : x.answer;
|
|
800
800
|
const ch = x.k === v.openK ? choice : x.choice;
|
|
801
|
-
return { line: x.line, question: x.question, answer: typed, ...ruleOfAnswer(x, typed, ch), ruleNo: x.ruleNo, ruleText: x.ruleText, ask: x.ask,
|
|
801
|
+
return { line: x.line, question: x.question, answer: typed, ...ruleOfAnswer(x, typed, ch), ruleNo: x.ruleNo, ruleText: x.ruleText, ask: x.ask, proposal: x.proposal };
|
|
802
802
|
});
|
|
803
803
|
const adds = all.filter((x) => x.rule !== null);
|
|
804
804
|
const grown = applyAnswers(typeof v.card.job === 'string' ? v.card.job : '', all);
|
|
@@ -811,7 +811,7 @@ export function createAuthor(opts) {
|
|
|
811
811
|
if (ov && LIVE_PHASES.has(ov.phase)) return { status: 409, body: { ok: false, refused: 'draft-live', draftId: other, say: 'A draft is already running. Wait for it, or abandon it, before answering.' } };
|
|
812
812
|
}
|
|
813
813
|
// M10 am16 (4): what a shape guardrail's answers picked, for the redraft: the check an agree took, or the person's own words (a `~` rule, no check). A rule left Not checked rides `left`.
|
|
814
|
-
redraft = { vet, all, picks: grown.picks, left: grown.left };
|
|
814
|
+
redraft = { vet, all, picks: grown.picks, left: grown.left, columns: grown.columns };
|
|
815
815
|
}
|
|
816
816
|
try {
|
|
817
817
|
// the human row of the draft log (am2 item 4): the question, the answer, the line, the time; a look ask also carries what code proposed and the rule the answer added, as their own fields
|
|
@@ -833,7 +833,7 @@ export function createAuthor(opts) {
|
|
|
833
833
|
writeFileSync(files[2], `${JSON.stringify({ fromPlan: v.plan, answers: redraft.all.map((x) => ({ line: x.line, question: x.question, answer: x.answer })), ...(redraft.left.length ? { left: redraft.left } : {}) })}\n`, { mode: 0o600, flag: 'wx' });
|
|
834
834
|
child = spawnDetached({
|
|
835
835
|
bin,
|
|
836
|
-
argv: ['draft', files[1], '--out', join(dir, `draft-${n}`), '--root', realpathSync(root), '--name', redraft.vet.card.flowName, '--no-questions', ...carryArgv(dir, [], v.plan), ...(redraft.picks.length ? ['--picks', JSON.stringify(redraft.picks)] : []), ...(redraft.left.length ? ['--left', redraft.left.map((x) => `${x.line}.${x.rule}`).join(',')] : []), ...modelArgv(redraft.vet.card)],
|
|
836
|
+
argv: ['draft', files[1], '--out', join(dir, `draft-${n}`), '--root', realpathSync(root), '--name', redraft.vet.card.flowName, '--no-questions', ...carryArgv(dir, [], v.plan), ...(redraft.picks.length ? ['--picks', JSON.stringify(redraft.picks)] : []), ...(redraft.left.length ? ['--left', redraft.left.map((x) => `${x.line}.${x.rule}`).join(',')] : []), ...(redraft.columns.length ? ['--columns', JSON.stringify(redraft.columns)] : []), ...modelArgv(redraft.vet.card)],
|
|
837
837
|
env: loaded.env,
|
|
838
838
|
logPath: join(dir, `redraft-${n}.log`),
|
|
839
839
|
});
|
package/src/panel/authorcard.js
CHANGED
|
@@ -16,6 +16,7 @@ import { isAbsolute, join } from 'node:path';
|
|
|
16
16
|
|
|
17
17
|
import { checkFlowName } from '../flow.js';
|
|
18
18
|
import { sameRuleWords } from '../blockpick.js';
|
|
19
|
+
import { isColumnChoiceRule, columnChoiceParts, swapColumnWord } from '../sheetoffer.js';
|
|
19
20
|
import { isWebUrl } from '../pagefetch.js';
|
|
20
21
|
import { checkSendDestination } from '../runner.js';
|
|
21
22
|
import { parseSignedText } from '../signed-text.js';
|
|
@@ -134,7 +135,7 @@ export function appendAnswersToJob(job, answers) {
|
|
|
134
135
|
}
|
|
135
136
|
|
|
136
137
|
/**
|
|
137
|
-
* M10 am21: the submitted job box with ONE `~`
|
|
138
|
+
* M10 am21, M17 am1: the submitted job box with ONE `~` rule of a job line (a whole `~` line, or one `; ` part of it) replaced by the words of an answer. Pure.
|
|
138
139
|
* @param {string} job @param {number} line the job line (step) number @param {string} oldText the `~` words to replace (case and spacing aside) @param {string} newText
|
|
139
140
|
* @returns {{ job: string, replaced: boolean }}
|
|
140
141
|
*/
|
|
@@ -148,33 +149,55 @@ export function replaceRuleOnJob(job, line, oldText, newText) {
|
|
|
148
149
|
if (!t.startsWith('~')) { step += 1; continue; }
|
|
149
150
|
if (step === line && norm(t.slice(1)) === norm(oldText)) { raw[i] = `~ ${newText}`; return { job: raw.join('\n'), replaced: true }; }
|
|
150
151
|
}
|
|
152
|
+
// the rule may be one `; ` part of a `~` line (a rule of its own): replace that part, keep the others in place
|
|
153
|
+
step = 0;
|
|
154
|
+
for (let i = 0; i < raw.length; i += 1) {
|
|
155
|
+
const t = raw[i].trim();
|
|
156
|
+
if (t === '') continue;
|
|
157
|
+
if (!t.startsWith('~')) { step += 1; continue; }
|
|
158
|
+
if (step !== line) continue;
|
|
159
|
+
const parts = t.slice(1).trim().split('; ');
|
|
160
|
+
const at = parts.findIndex((p) => norm(p) === norm(oldText));
|
|
161
|
+
if (parts.length > 1 && at >= 0) { parts[at] = newText; raw[i] = `~ ${parts.join('; ')}`; return { job: raw.join('\n'), replaced: true }; }
|
|
162
|
+
}
|
|
151
163
|
return { job: String(job), replaced: false };
|
|
152
164
|
}
|
|
153
165
|
|
|
154
166
|
/**
|
|
155
|
-
* THE one writer of what a set of answers does to the job box and to the picks (M4e am24, M10 am16 (4),
|
|
156
|
-
* (
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
* @
|
|
167
|
+
* THE one writer of what a set of answers does to the job box and to the picks (M4e am24, M10 am16 (4); M17 am1 (a), one rule in, one rule out): an answer about one of the person's `~` rules
|
|
168
|
+
* (a look ask with a rule number) REPLACES that rule in place, the same line and the same rule number (`replaceRuleOnJob`), and never adds a line beside it. Only an answer that is about no
|
|
169
|
+
* rule (a drafter question, a sheet column ask) is still added word for word as a new `~` line (`appendAnswersToJob`). Picks and left rules are numbered as the asks carried them; a pick carries
|
|
170
|
+
* no `added` words, because its rule's words ARE the answer. A rule-about answer whose rule is no longer on the job line is not applied (the caller sees the count and refuses).
|
|
171
|
+
* @param {string} job @param {{line: number, rule: string|null, left: boolean, check?: Record<string, any>|null, own?: boolean, ruleNo?: number, ruleText?: string, ask?: string, proposal?: string|null}[]} all
|
|
172
|
+
* @returns {{job: string, added: number, picks: {line: number, rule: number|undefined, check: Record<string, any>|null, own?: boolean}[], left: {line: number, rule: number|undefined}[], columns: {line: number, word: string, column: string}[]}}
|
|
160
173
|
*/
|
|
161
174
|
export function applyAnswers(job, all) {
|
|
162
175
|
let out = job;
|
|
163
176
|
let done = 0;
|
|
164
177
|
/** @type {{ line: number, answer: string }[]} */
|
|
165
178
|
const appends = [];
|
|
179
|
+
/** @type {{line: number, word: string, column: string}[]} */
|
|
180
|
+
const columns = [];
|
|
166
181
|
for (const x of all) {
|
|
167
182
|
if (x.rule === null) continue;
|
|
168
|
-
|
|
169
|
-
|
|
183
|
+
// M17 ruling 1: a column ask tied to one of the person's `~` rules rewrites THAT rule in place - agreed, the job's word is swapped for the column ("Price over 500" -> "Amount over 500"); the
|
|
184
|
+
// person's own words replace it like any other rule. A column word tied to no rule (the job's prose) is still one more `~` line
|
|
185
|
+
const parts = isColumnChoiceRule(x.proposal) && Number.isInteger(x.ruleNo) ? columnChoiceParts(x.rule) : null;
|
|
186
|
+
const swapped = parts ? swapColumnWord(String(x.ruleText ?? ''), parts.word, parts.column) : null;
|
|
187
|
+
// M17 ruling 2: an agreed column for a word that is no `~` rule (the job's prose) adds NO `~` line; it is told to the AI, whose check (if it suggests one) is a `!` `[agent]` row built by code
|
|
188
|
+
// and so is an agreed column for a word that is not in the tied rule's text (nothing to rewrite): never a new line
|
|
189
|
+
const proseCol = isColumnChoiceRule(x.proposal) && isColumnChoiceRule(x.rule) && (!Number.isInteger(x.ruleNo) || swapped === null) ? columnChoiceParts(x.rule) : null;
|
|
190
|
+
if (proseCol) { columns.push({ line: x.line, word: proseCol.word, column: proseCol.column }); continue; }
|
|
191
|
+
if (x.ask !== undefined && Number.isInteger(x.ruleNo) && (!isColumnChoiceRule(x.proposal) || !isColumnChoiceRule(x.rule) || swapped !== null)) {
|
|
192
|
+
const r = replaceRuleOnJob(out, x.line, String(x.ruleText ?? ''), swapped ?? x.rule);
|
|
170
193
|
if (r.replaced) { out = r.job; done += 1; }
|
|
171
194
|
} else appends.push({ line: x.line, answer: x.rule });
|
|
172
195
|
}
|
|
173
196
|
const grown = appendAnswersToJob(out, appends);
|
|
174
197
|
const picks = all.filter((x) => (x.ask === 'check' || x.ask === 'no-check') && !x.left)
|
|
175
|
-
.map((x) => ({ line: x.line, rule: x.
|
|
176
|
-
const left = all.filter((x) => x.left).
|
|
177
|
-
return { job: grown.job, added: grown.added + done, picks, left };
|
|
198
|
+
.map((x) => ({ line: x.line, rule: x.ruleNo, check: x.check ?? null, ...(x.own ? { own: true } : {}) }));
|
|
199
|
+
const left = all.filter((x) => x.left).map((x) => ({ line: x.line, rule: x.ruleNo }));
|
|
200
|
+
return { job: grown.job, added: grown.added + done + columns.length, picks, left, columns };
|
|
178
201
|
}
|
|
179
202
|
|
|
180
203
|
/**
|
package/src/panel/index.html
CHANGED
|
@@ -2721,6 +2721,8 @@
|
|
|
2721
2721
|
// M16 am4: with `onList` the checks are drawn as rows of the list (tags, Drop) by the caller, so this draws the rest
|
|
2722
2722
|
function sheetBlockLines(sheet, onList){
|
|
2723
2723
|
if(!sheet) return [];
|
|
2724
|
+
// M17 am4 (C7): a plan whose sheet checks code built shows the list only: its rows and its one Not checked list, never this block beside them
|
|
2725
|
+
if(onList && sheet.codeBuilt === true) return [];
|
|
2724
2726
|
var out = [];
|
|
2725
2727
|
if((sheet.guardrails || []).length){
|
|
2726
2728
|
out.push("Guardrails:");
|
|
@@ -4184,7 +4186,11 @@
|
|
|
4184
4186
|
if(!rows || !rows.length) return "";
|
|
4185
4187
|
return '<div data-testid="' + tid + '" style="margin:6px 0"><div><b>' + escapeXml(title) + "</b></div>" + rows.map(auditCheckRowHtml).join("") + "</div>";
|
|
4186
4188
|
};
|
|
4187
|
-
|
|
4189
|
+
var readSec = function(notes){
|
|
4190
|
+
if(!notes || !notes.length) return "";
|
|
4191
|
+
return '<div data-testid="audit-checks-readnotes" style="margin:6px 0"><div><b>How the page was read</b></div>' + notes.map(function(t){ return '<div class="audit-check-row" data-testid="audit-read-note" style="overflow-wrap:anywhere;margin:2px 0">' + escapeXml(t) + "</div>"; }).join("") + "</div>";
|
|
4192
|
+
};
|
|
4193
|
+
body.innerHTML = '<div class="jp">' + sec("Checks", ac.checks, "audit-checks-checks") + sec("Not checked", ac.notChecked, "audit-checks-notchecked") + readSec(ac.readNotes) + sec("Always checked", ac.always, "audit-checks-always") + "</div>";
|
|
4188
4194
|
function paint(open){ body.hidden = !open; btn.setAttribute("aria-expanded", open ? "true" : "false"); btn.innerHTML = headHtml(open); }
|
|
4189
4195
|
btn.addEventListener("click", function(){ var open = body.hidden; auditExpanded["\u0000checks"] = open; paint(open); });
|
|
4190
4196
|
if(auditExpanded["\u0000checks"] === true) paint(true);
|
package/src/pickrecord.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// borrowed-from: bareloop src/pickrecord.js@v0.57.0 (c18df406)
|
|
1
2
|
// M10 am17 + am18: the ONE record of check picks, carried from plan to plan. A pick is tied to its job line's WORDS (plus its order among lines with the same words)
|
|
2
3
|
// and to its guardrail's exact words, never to a line or rule number: both are recomputed on the new card. This file is the only writer of a record's entries
|
|
3
4
|
// (`entriesFromAnswers`) and the only reader that decides keep-or-ask (`matchRecord`); the logic is the one F146 / F146b proved (poc/m10-am17/keep-picks-am18.mjs).
|
|
@@ -10,7 +11,7 @@ export const RECORD_FILE = 'picks-record.json';
|
|
|
10
11
|
/** the exact words a kept pick is marked with in the draft log, the Audit and the plan card (M10 am17 (6)) */
|
|
11
12
|
export const KEPT_WORDS = 'kept from last draft';
|
|
12
13
|
|
|
13
|
-
/** @typedef {{lineWords: string, occurrence: number, ruleText: string, added
|
|
14
|
+
/** @typedef {{lineWords: string, occurrence: number, ruleText: string, added?: string|null, check: Record<string, any>|null, own: boolean, left: boolean}} Entry */
|
|
14
15
|
/** @typedef {{line: number, rule: number, text: string}} Rule */
|
|
15
16
|
|
|
16
17
|
const norm = (/** @type {unknown} */ t) => String(t).toLowerCase().replace(/\s+/g, ' ').trim();
|
|
@@ -34,9 +35,9 @@ export function lineKeys(lines) {
|
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
/**
|
|
37
|
-
* The entries for answers just given, numbered on THIS card (the answer redraft's card: its line and rule numbers are the ones the asks carried).
|
|
38
|
+
* The entries for answers just given, numbered on THIS card (the answer redraft's card: its line and rule numbers are the ones the asks carried; the rule's text is the FINAL rule's words).
|
|
38
39
|
* @param {{n: number, text: string}[]} lines @param {Rule[]} rules
|
|
39
|
-
* @param {{line: number, rule: number, check?: Record<string, any>|null,
|
|
40
|
+
* @param {{line: number, rule: number, check?: Record<string, any>|null, own?: boolean}[]} picks @param {{line: number, rule: number}[]} left
|
|
40
41
|
* @returns {Entry[]}
|
|
41
42
|
*/
|
|
42
43
|
export function entriesFromAnswers(lines, rules, picks, left) {
|
|
@@ -51,82 +52,43 @@ export function entriesFromAnswers(lines, rules, picks, left) {
|
|
|
51
52
|
const out = [];
|
|
52
53
|
for (const p of picks) {
|
|
53
54
|
const b = base(p.line, p.rule);
|
|
54
|
-
if (b) out.push({ ...b,
|
|
55
|
+
if (b) out.push({ ...b, check: p.check ?? null, own: p.own === true, left: false });
|
|
55
56
|
}
|
|
56
57
|
for (const l of left) {
|
|
57
58
|
const b = base(l.line, l.rule);
|
|
58
|
-
if (b) out.push({ ...b,
|
|
59
|
+
if (b) out.push({ ...b, check: null, own: false, left: true });
|
|
59
60
|
}
|
|
60
61
|
return out;
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
/**
|
|
64
65
|
* Decide, for the card in hand, which stored picks are kept and which guardrails must be asked.
|
|
65
|
-
* A pick is KEPT when the job line with its words (same order among equal lines) still has
|
|
66
|
-
*
|
|
67
|
-
* partner left on the card is folded (neither asked nor given the old check) - except an EDITED added line (M10 am21): that one is asked (`pairRule` = its source's number) and the source is folded. Pure.
|
|
66
|
+
* A pick is KEPT when the job line with its words (same order among equal lines) still has a guardrail with the pick's exact words. One rule in, one rule out (hamr 2026-11-14): an answer REPLACED the
|
|
67
|
+
* rule it was asked about, so the stored words are the final rule's words and there is no second line to pair; a rule whose words changed is simply new and asked. Pure.
|
|
68
68
|
* @param {Entry[]} entries @param {{n: number, text: string}[]} lines @param {Rule[]} rules every guardrail the call settles
|
|
69
|
-
* @returns {{picks: {line: number, rule: number, check: Record<string, any>|null,
|
|
70
|
-
* kept: {line: number, rule: number, entry: Entry}[], askRules:
|
|
69
|
+
* @returns {{picks: {line: number, rule: number, check: Record<string, any>|null, own?: boolean}[], left: {line: number, rule: number}[],
|
|
70
|
+
* kept: {line: number, rule: number, entry: Entry}[], askRules: Rule[]}}
|
|
71
71
|
*/
|
|
72
72
|
export function matchRecord(entries, lines, rules) {
|
|
73
73
|
const byKey = new Map([...lineKeys(lines)].map(([n, k]) => [`${k.lineWords}#${k.occurrence}`, n]));
|
|
74
74
|
/** @type {Set<string>} */
|
|
75
75
|
const claimed = new Set();
|
|
76
|
-
/** @type {Set<string>} */
|
|
77
|
-
const folded = new Set();
|
|
78
|
-
/** @type {Map<string, number>} an edited added line (by id) -> the rule number of the source it was paired with (M10 am21) */
|
|
79
|
-
const edited = new Map();
|
|
80
|
-
const free = (/** @type {number} */ n, /** @type {string} */ text) => rules.find((r) => r.line === n && !claimed.has(id(r)) && !folded.has(id(r)) && norm(r.text) === norm(text));
|
|
81
76
|
const kept = [];
|
|
82
|
-
/** @type {{e: Entry, n: number|undefined}[]} */
|
|
83
|
-
const broken = [];
|
|
84
77
|
for (const e of Array.isArray(entries) ? entries : []) {
|
|
85
78
|
const n = byKey.get(`${e.lineWords}#${e.occurrence}`);
|
|
86
|
-
const src = n === undefined ? undefined :
|
|
87
|
-
if (src)
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (add) claimed.add(id(add));
|
|
91
|
-
kept.push({ line: n, rule: src.rule, entry: e });
|
|
92
|
-
} else {
|
|
93
|
-
if (src) claimed.delete(id(src));
|
|
94
|
-
broken.push({ e, n });
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
// a pair broken on one side is ONE pick, so ONE ask: the partner that is left folds into it (it keeps no old check and is not asked on its own)
|
|
98
|
-
for (const { e, n } of broken) {
|
|
99
|
-
if (e.added === null) continue;
|
|
100
|
-
if (n === undefined) {
|
|
101
|
-
// the line's own words changed: it is a new line, all its guardrails are asked; its old `~` line with its source still there rides the source's ask
|
|
102
|
-
for (const l of lines) {
|
|
103
|
-
const s = free(l.n, e.ruleText);
|
|
104
|
-
const a = s ? rules.find((r) => r.line === l.n && r !== s && !claimed.has(id(r)) && !folded.has(id(r)) && norm(r.text) === norm(e.added ?? '')) : undefined;
|
|
105
|
-
if (a) { folded.add(id(a)); break; }
|
|
106
|
-
}
|
|
107
|
-
continue;
|
|
108
|
-
}
|
|
109
|
-
const src = free(n, e.ruleText);
|
|
110
|
-
const add = free(n, e.added);
|
|
111
|
-
if (src && !add) {
|
|
112
|
-
// the added line was edited (or deleted): the unclaimed rule right after the source on that line is it. M10 am21: the ONE ask is about THAT line's words
|
|
113
|
-
// (it carries the source's number as `pairRule`, the rule its pick is kept under); the source rides it and is not asked on its own
|
|
114
|
-
const p = rules.find((r) => r.line === n && r.rule > src.rule && !claimed.has(id(r)) && !folded.has(id(r)));
|
|
115
|
-
if (p) { folded.add(id(src)); edited.set(id(p), src.rule); }
|
|
116
|
-
} else if (add && !src) {
|
|
117
|
-
// the source was edited: the unclaimed rule right before the added line is it; the old added line rides that ask
|
|
118
|
-
const p = [...rules].reverse().find((r) => r.line === n && r.rule < add.rule && !claimed.has(id(r)) && !folded.has(id(r)));
|
|
119
|
-
if (p) folded.add(id(add));
|
|
120
|
-
}
|
|
79
|
+
const src = n === undefined ? undefined : rules.find((r) => r.line === n && !claimed.has(id(r)) && norm(r.text) === norm(e.ruleText));
|
|
80
|
+
if (!src) continue;
|
|
81
|
+
claimed.add(id(src));
|
|
82
|
+
kept.push({ line: /** @type {number} */ (n), rule: src.rule, entry: e });
|
|
121
83
|
}
|
|
122
84
|
const picks = [];
|
|
123
85
|
const left = [];
|
|
124
86
|
for (const k of kept) {
|
|
125
87
|
const e = k.entry;
|
|
126
88
|
if (e.left) left.push({ line: k.line, rule: k.rule });
|
|
127
|
-
else picks.push({ line: k.line, rule: k.rule, check: e.check, ...(e.
|
|
89
|
+
else picks.push({ line: k.line, rule: k.rule, check: e.check, ...(e.own ? { own: true } : {}) });
|
|
128
90
|
}
|
|
129
|
-
return { picks, left, kept, askRules: rules.filter((r) => !claimed.has(id(r))
|
|
91
|
+
return { picks, left, kept, askRules: rules.filter((r) => !claimed.has(id(r))) };
|
|
130
92
|
}
|
|
131
93
|
|
|
132
94
|
/**
|
|
@@ -170,5 +132,31 @@ export function readSheetDropped(file) {
|
|
|
170
132
|
} catch { return null; }
|
|
171
133
|
}
|
|
172
134
|
|
|
135
|
+
/**
|
|
136
|
+
* M17 ruling 2: the columns a person agreed for a word of the job's prose (or a word that is not in the rule it was asked about), kept in the same record as the picks and carried like them:
|
|
137
|
+
* tied to the job line's WORDS (and its order among equal lines), never to a number. `columns` entries are `{lineWords, occurrence, word, column}`.
|
|
138
|
+
* @param {string} file @returns {{lineWords: string, occurrence: number, word: string, column: string}[]|null}
|
|
139
|
+
*/
|
|
140
|
+
export function readColumns(file) {
|
|
141
|
+
try {
|
|
142
|
+
const g = readFileInside(path.dirname(file), path.basename(file));
|
|
143
|
+
if (!g.ok) return null;
|
|
144
|
+
const j = JSON.parse(g.text);
|
|
145
|
+
return Array.isArray(j?.columns) ? j.columns.filter((/** @type {any} */ e) => e && typeof e.lineWords === 'string' && Number.isInteger(e.occurrence) && typeof e.word === 'string' && typeof e.column === 'string') : null;
|
|
146
|
+
} catch { return null; }
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** @param {{n: number, text: string}[]} lines @param {{line: number, word: string, column: string}[]} cols @returns {{lineWords: string, occurrence: number, word: string, column: string}[]} the answers as the record keeps them */
|
|
150
|
+
export function columnEntries(lines, cols) {
|
|
151
|
+
const keys = lineKeys(lines);
|
|
152
|
+
return cols.flatMap((c) => { const k = keys.get(c.line); return k === undefined ? [] : [{ ...k, word: c.word, column: c.column }]; });
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** @param {{lineWords: string, occurrence: number, word: string, column: string}[]} entries @param {{n: number, text: string}[]} lines @returns {{line: number, word: string, column: string}[]} the record's answers whose job line is still on the card (same words, same order) */
|
|
156
|
+
export function columnsOnLines(entries, lines) {
|
|
157
|
+
const byKey = new Map([...lineKeys(lines)].map(([n, k]) => [`${k.lineWords}#${k.occurrence}`, n]));
|
|
158
|
+
return entries.flatMap((e) => { const n = byKey.get(`${e.lineWords}#${e.occurrence}`); return n === undefined ? [] : [{ line: n, word: e.word, column: e.column }]; });
|
|
159
|
+
}
|
|
160
|
+
|
|
173
161
|
/** where a plan folder keeps its record @param {string} planDir */
|
|
174
162
|
export const recordPath = (planDir) => path.join(planDir, RECORD_FILE);
|