fwdloop 0.33.0 → 0.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -0
- package/bin/fwdloop +18 -2
- package/package.json +1 -1
- package/src/action-line.js +100 -0
- package/src/action-stop.js +44 -0
- package/src/ask.js +9 -2
- package/src/auditchecks.js +6 -4
- package/src/authoring.js +28 -14
- 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 +102 -58
- package/src/checked.js +7 -2
- package/src/checklist.js +1 -3
- package/src/checklistsign.js +1 -1
- package/src/checkpick.js +7 -73
- package/src/declaration.js +20 -35
- package/src/drafter.js +281 -208
- package/src/jobkey.js +2 -3
- package/src/noteask.js +62 -0
- package/src/pageask.js +24 -69
- package/src/pagedry.js +27 -4
- package/src/pagemap.js +8 -2
- package/src/pagerules.js +19 -3
- package/src/panel/author.js +63 -36
- package/src/panel/authorcard.js +36 -20
- package/src/panel/data.js +5 -1
- package/src/panel/index.html +66 -37
- 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/runner.js +87 -41
- package/src/runvalues.js +9 -1
- package/src/setup.js +3 -1
- package/src/sheetblock.js +17 -7
- package/src/sheetbuild.js +148 -0
- package/src/sheetchecks.js +3 -2
- package/src/sheetfind.js +4 -4
- package/src/sheetlook.js +15 -4
- package/src/sheetoffer.js +50 -5
- package/src/sheetrows.js +18 -2
- package/src/signed-text.js +1 -5
- package/src/ticket-draft.js +4 -21
- package/src/ticketrows.js +100 -0
- package/src/whole-job.js +27 -11
- package/types/action-line.d.ts +71 -0
- package/types/action-stop.d.ts +36 -0
- package/types/ask.d.ts +3 -2
- package/types/auditchecks.d.ts +2 -1
- package/types/authoring.d.ts +8 -3
- 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 +33 -17
- package/types/checked.d.ts +2 -0
- package/types/checklist.d.ts +3 -5
- package/types/checkpick.d.ts +4 -34
- package/types/declaration.d.ts +7 -0
- package/types/drafter.d.ts +23 -356
- package/types/noteask.d.ts +52 -0
- package/types/pageask.d.ts +12 -36
- package/types/pagedry.d.ts +13 -0
- package/types/pagerules.d.ts +7 -0
- package/types/panel/author.d.ts +1 -1
- package/types/panel/authorcard.d.ts +13 -8
- package/types/panel/authorflows.d.ts +4 -4
- package/types/panel/data.d.ts +2 -2
- package/types/panel/jobgrid.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 +82 -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/types/whole-job.d.ts +3 -3
- package/src/added-end.js +0 -60
- package/src/repairs.js +0 -38
- package/types/added-end.d.ts +0 -62
- package/types/repairs.d.ts +0 -13
package/src/panel/authorcard.js
CHANGED
|
@@ -16,10 +16,10 @@ 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';
|
|
22
|
-
import { addEnd, typedLinesOf } from '../added-end.js';
|
|
23
23
|
import { capTooSmallText } from '../draftspend.js';
|
|
24
24
|
import { startableMcpServers, mcpConfigFor } from '../mcp-sources.js';
|
|
25
25
|
import { mcpPickFor } from '../mcp-pick.js';
|
|
@@ -134,7 +134,7 @@ export function appendAnswersToJob(job, answers) {
|
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
/**
|
|
137
|
-
* M10 am21: the submitted job box with ONE `~`
|
|
137
|
+
* 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
138
|
* @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
139
|
* @returns {{ job: string, replaced: boolean }}
|
|
140
140
|
*/
|
|
@@ -148,33 +148,55 @@ export function replaceRuleOnJob(job, line, oldText, newText) {
|
|
|
148
148
|
if (!t.startsWith('~')) { step += 1; continue; }
|
|
149
149
|
if (step === line && norm(t.slice(1)) === norm(oldText)) { raw[i] = `~ ${newText}`; return { job: raw.join('\n'), replaced: true }; }
|
|
150
150
|
}
|
|
151
|
+
// the rule may be one `; ` part of a `~` line (a rule of its own): replace that part, keep the others in place
|
|
152
|
+
step = 0;
|
|
153
|
+
for (let i = 0; i < raw.length; i += 1) {
|
|
154
|
+
const t = raw[i].trim();
|
|
155
|
+
if (t === '') continue;
|
|
156
|
+
if (!t.startsWith('~')) { step += 1; continue; }
|
|
157
|
+
if (step !== line) continue;
|
|
158
|
+
const parts = t.slice(1).trim().split('; ');
|
|
159
|
+
const at = parts.findIndex((p) => norm(p) === norm(oldText));
|
|
160
|
+
if (parts.length > 1 && at >= 0) { parts[at] = newText; raw[i] = `~ ${parts.join('; ')}`; return { job: raw.join('\n'), replaced: true }; }
|
|
161
|
+
}
|
|
151
162
|
return { job: String(job), replaced: false };
|
|
152
163
|
}
|
|
153
164
|
|
|
154
165
|
/**
|
|
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
|
-
* @
|
|
166
|
+
* 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
|
|
167
|
+
* (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
|
|
168
|
+
* 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
|
|
169
|
+
* 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).
|
|
170
|
+
* @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
|
|
171
|
+
* @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
172
|
*/
|
|
161
173
|
export function applyAnswers(job, all) {
|
|
162
174
|
let out = job;
|
|
163
175
|
let done = 0;
|
|
164
176
|
/** @type {{ line: number, answer: string }[]} */
|
|
165
177
|
const appends = [];
|
|
178
|
+
/** @type {{line: number, word: string, column: string}[]} */
|
|
179
|
+
const columns = [];
|
|
166
180
|
for (const x of all) {
|
|
167
181
|
if (x.rule === null) continue;
|
|
168
|
-
|
|
169
|
-
|
|
182
|
+
// 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
|
|
183
|
+
// 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
|
|
184
|
+
const parts = isColumnChoiceRule(x.proposal) && Number.isInteger(x.ruleNo) ? columnChoiceParts(x.rule) : null;
|
|
185
|
+
const swapped = parts ? swapColumnWord(String(x.ruleText ?? ''), parts.word, parts.column) : null;
|
|
186
|
+
// 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
|
|
187
|
+
// 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
|
|
188
|
+
const proseCol = isColumnChoiceRule(x.proposal) && isColumnChoiceRule(x.rule) && (!Number.isInteger(x.ruleNo) || swapped === null) ? columnChoiceParts(x.rule) : null;
|
|
189
|
+
if (proseCol) { columns.push({ line: x.line, word: proseCol.word, column: proseCol.column }); continue; }
|
|
190
|
+
if (x.ask !== undefined && Number.isInteger(x.ruleNo) && (!isColumnChoiceRule(x.proposal) || !isColumnChoiceRule(x.rule) || swapped !== null)) {
|
|
191
|
+
const r = replaceRuleOnJob(out, x.line, String(x.ruleText ?? ''), swapped ?? x.rule);
|
|
170
192
|
if (r.replaced) { out = r.job; done += 1; }
|
|
171
193
|
} else appends.push({ line: x.line, answer: x.rule });
|
|
172
194
|
}
|
|
173
195
|
const grown = appendAnswersToJob(out, appends);
|
|
174
196
|
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 };
|
|
197
|
+
.map((x) => ({ line: x.line, rule: x.ruleNo, check: x.check ?? null, ...(x.own ? { own: true } : {}) }));
|
|
198
|
+
const left = all.filter((x) => x.left).map((x) => ({ line: x.line, rule: x.ruleNo }));
|
|
199
|
+
return { job: grown.job, added: grown.added + done + columns.length, picks, left, columns };
|
|
178
200
|
}
|
|
179
201
|
|
|
180
202
|
/**
|
|
@@ -260,7 +282,7 @@ export function runInputRows(v) {
|
|
|
260
282
|
* @returns {string}
|
|
261
283
|
*/
|
|
262
284
|
export function cardToProse(card) {
|
|
263
|
-
const { steps } =
|
|
285
|
+
const { steps } = parseJobBox(card.job); // M13 am11: code adds no line; the send is tentative on the last typed line (the draft decides, src/drafter.js)
|
|
264
286
|
const out = [...jobFileLines(steps, card.askWait), '', ARBITER_HEADING];
|
|
265
287
|
out.push(`guardrail: cap $${capText(Number(card.capUsd))} per run`);
|
|
266
288
|
if (card.destination !== '') out.push(`guardrail: send at line ${steps.length} to file:${card.destination}`);
|
|
@@ -287,9 +309,6 @@ export function cardFromSigned({ lines, arbiter }) {
|
|
|
287
309
|
const asks = new Map((arbiter.asks ?? []).map((a) => [a.line, a]));
|
|
288
310
|
const jobLines = [];
|
|
289
311
|
let firstWait = null;
|
|
290
|
-
// M13 am8: the end is added by code (`cardToProse`), so the card's job leaves out the send line (the last line when it is the send) and an added Ask before it
|
|
291
|
-
const lastSend = (arbiter.sends ?? []).length === 1 && arbiter.sends[0].line === lines.length ? arbiter.sends[0].line : null;
|
|
292
|
-
const typed = new Set(typedLinesOf(lines, arbiter).map((l) => l.n));
|
|
293
312
|
for (const l of lines) {
|
|
294
313
|
const ak = asks.get(l.n);
|
|
295
314
|
if (ak) {
|
|
@@ -297,7 +316,6 @@ export function cardFromSigned({ lines, arbiter }) {
|
|
|
297
316
|
if (w === null) return no();
|
|
298
317
|
firstWait ??= w;
|
|
299
318
|
}
|
|
300
|
-
if (!typed.has(l.n)) continue;
|
|
301
319
|
if (ak) jobLines.push(`Ask ${waitText(ak.ttlMs)}: ${l.text}`);
|
|
302
320
|
else jobLines.push(l.text);
|
|
303
321
|
if (typeof l.guardrail === 'string' && l.guardrail !== '') jobLines.push(`~ ${l.guardrail}`);
|
|
@@ -314,9 +332,7 @@ export function cardFromSigned({ lines, arbiter }) {
|
|
|
314
332
|
const again = parseSignedText(cardToProse(cardFields({ ...card, flowName: 'x' })));
|
|
315
333
|
// M9 am1: the trigger is not a box on the card, and signing an Edit clears it (By hand again), so it is not part of the fidelity check
|
|
316
334
|
const norm = (a) => JSON.stringify({ ...a, trigger: null, asks: (a.asks ?? []).map(({ ttlSigned, ...rest }) => rest) });
|
|
317
|
-
|
|
318
|
-
const sendText = (/** @type {{n: number, text: string}[]} */ ls) => ls.map((l) => (l.n === lastSend ? { ...l, text: '' } : l));
|
|
319
|
-
const sameLines = again.ok && JSON.stringify(sendText(again.lines)) === JSON.stringify(sendText(lines));
|
|
335
|
+
const sameLines = again.ok && JSON.stringify(again.lines) === JSON.stringify(lines);
|
|
320
336
|
if (!sameLines || norm(again.arbiter) !== norm(arbiter)) return no();
|
|
321
337
|
return { ok: true, card };
|
|
322
338
|
}
|
package/src/panel/data.js
CHANGED
|
@@ -45,7 +45,7 @@ import { EVERY_STEP_TEXTS } from '../try-checks.js';
|
|
|
45
45
|
import { LABEL_PICKED, tagOf } from '../checkwords.js';
|
|
46
46
|
import { listLinesOf } from '../checklistsign.js';
|
|
47
47
|
import { auditChecksOf } from '../auditchecks.js';
|
|
48
|
-
import { panelQuestionText } from '../pageask.js';
|
|
48
|
+
import { panelQuestionText, decidedWords } from '../pageask.js';
|
|
49
49
|
import { csvRolesOf, askSheetCard } from '../sheetblock.js';
|
|
50
50
|
import { readSheetChecks } from '../sheet-record.js';
|
|
51
51
|
import {
|
|
@@ -1957,6 +1957,8 @@ export function getDraftBlock(flowDir, runDir) {
|
|
|
1957
1957
|
rows.push(human(r, n, { action: 'card (you)', gap }));
|
|
1958
1958
|
} else if (r.kind === 'note') rows.push(human(r, n, { action: 'note (you)', gap: String(r.text ?? '') }));
|
|
1959
1959
|
// M10 am2 item 4: a question the page look raised and your answer, under the drafting step, in bareloop's words (`you were asked:` / `you said:`)
|
|
1960
|
+
// M17 am8: a button-picked answer reads what was decided (`agreed — ...`), never the question that quotes a replaced rule's old words
|
|
1961
|
+
else if (r.kind === 'human' && decidedWords(r) !== null) rows.push(human(r, n, { action: decidedWords(r), gap: '' }));
|
|
1960
1962
|
else if (r.kind === 'human') rows.push(human(r, n, { action: `you were asked: ${panelQuestionText(r)}`, gap: `you said: ${r.answer}${r.source === 'look' && typeof r.rule === 'string' && r.rule !== '' ? ` ${youTag}` : ''}` }));
|
|
1961
1963
|
// M16 item 5: a Drop or an Add on the card: a human row, $0, no model
|
|
1962
1964
|
else if (r.kind === 'rowedit') rows.push(human(r, n, { action: r.op === 'drop' ? 'you dropped a check' : 'you added a check', gap: String(r.key ?? '') }));
|
|
@@ -2298,6 +2300,7 @@ function resultDoorOf(asks) {
|
|
|
2298
2300
|
const block = asks.blocks.at(-1);
|
|
2299
2301
|
const ask = block?.current;
|
|
2300
2302
|
if (!ask || ask.open !== true) return null;
|
|
2303
|
+
if (ask.kind === 'action-stop') return null; // M13 am11: the stop before the action is answered on the Ask tab (Accept / Not now); the Result tab's Your call has Rerun, which the stop does not take
|
|
2301
2304
|
if (asks.resume && asks.resume.askId === ask.askId && asks.resume.state !== 'broken') return null;
|
|
2302
2305
|
return { askId: ask.askId, draftNo: block.draftNo };
|
|
2303
2306
|
}
|
|
@@ -2536,6 +2539,7 @@ function normalizeArchivedRow(a) {
|
|
|
2536
2539
|
answeredAt: a.answer.answeredAt ?? null,
|
|
2537
2540
|
archived: true,
|
|
2538
2541
|
emits: typeof a.emits === 'string' ? a.emits : null,
|
|
2542
|
+
kind: typeof a.kind === 'string' ? a.kind : null, // M13 am11: 'action-stop' = the stop before the action (Accept / Not now)
|
|
2539
2543
|
evidence: flattenEvidence(a.evidence),
|
|
2540
2544
|
};
|
|
2541
2545
|
}
|
package/src/panel/index.html
CHANGED
|
@@ -226,7 +226,6 @@
|
|
|
226
226
|
.badge.cyan{color:var(--cyan);}
|
|
227
227
|
|
|
228
228
|
.hint{font-size:11px;color:var(--text-faint);margin-top:4px;}
|
|
229
|
-
.hint.jf-added{margin-top:2px;overflow-wrap:anywhere;}
|
|
230
229
|
.hint.money-red{color:var(--red);}
|
|
231
230
|
.btn{padding:8px 14px;min-height:44px;border:1px solid var(--border-strong);background:var(--panel2);color:var(--text);white-space:nowrap;flex:none;position:relative;}
|
|
232
231
|
.btn::before{content:"[ ";color:var(--text-faint);}
|
|
@@ -478,9 +477,6 @@
|
|
|
478
477
|
.audit-group.audit-fold h4.audit-status-header::after{content:none;}
|
|
479
478
|
/* M8 item 6: bareloop's learnings box, copied (borrowed-from: bareloop src/panel/index.html@v0.47.1 417e80c, the learnings arrow only): a framed row, the header a full-width button with the arrow, chip and words inline; the arrow is the same ▶ / ▼ the other Audit folds draw (h4.audit-status-header::before), faint, a smaller gap on a phone */
|
|
480
479
|
.audit-part{border:1px solid var(--border);margin-bottom:6px;background:var(--panel2);}
|
|
481
|
-
/* borrowed-from: bareloop src/panel/index.html@v0.56.0 (3383cce) :181-182 */
|
|
482
|
-
.audit-caret{flex:none;color:var(--text-faint);margin-right:.6em;}
|
|
483
|
-
@media (max-width: 640px){ .audit-caret{margin-right:.2em;} }
|
|
484
480
|
.audit-part-toggle{width:100%;text-align:left;display:block;white-space:normal;min-height:44px;padding:8px 10px;}
|
|
485
481
|
.audit-part-toggle::before,.audit-part-toggle::after{content:"";}
|
|
486
482
|
.audit-part-toggle.audit-learn-fold::before{content:"\25B6 ";color:var(--text-faint);}
|
|
@@ -600,6 +596,11 @@
|
|
|
600
596
|
/* M10 am4: the Result tab. borrowed-from: bareloop src/panel/index.html@2959217 :188 :192 :397-408 (the Your-call card's rules are below, am5 item 2) */
|
|
601
597
|
.st-word{font-weight:700;color:var(--text);}
|
|
602
598
|
.step-state{display:inline-flex;align-items:center;gap:2px;font-size:12px;}
|
|
599
|
+
.audit-checks-word{font-size:12px;font-weight:700;color:var(--text);}
|
|
600
|
+
/* hamr ask: a passed group's / the run summary's "passed" word = the checks word; the sign glyph stays green. Placed after the phone rule so it also wins at 390/320 */
|
|
601
|
+
.audit-group h4.audit-status-header > .badge.audit-passed-word{font-size:12px;font-weight:700;color:var(--text);}
|
|
602
|
+
.audit-group h4.audit-status-header > .badge.audit-passed-word .audit-sign-glyph{color:var(--green);}
|
|
603
|
+
.audit-group.audit-fold h4.audit-status-header > .badge.audit-passed-word{font-size:12px;}
|
|
603
604
|
/* PRD v1.107 Part 6: the Result tab. Boxes are the Job tab's own (.job-card, .field, .ro-value, .field-row); text wraps, nothing scrolls the page. */
|
|
604
605
|
#result-body{min-width:0;overflow-wrap:anywhere;}
|
|
605
606
|
.rs-ok{color:var(--green);font-weight:700;}
|
|
@@ -1219,9 +1220,7 @@
|
|
|
1219
1220
|
<div class="jf-gut" id="jf-job-gut" data-testid="jf-job-gut" aria-hidden="true"><div class="jf-gut-in"></div></div>
|
|
1220
1221
|
<textarea class="jf-wrap" id="jf-job" rows="6" data-testid="jf-job" autocomplete="off" spellcheck="false" placeholder="Read my resume ~keep it under 600 words Ask: check it with me Write it out"></textarea>
|
|
1221
1222
|
</div>
|
|
1222
|
-
<div class="hint
|
|
1223
|
-
<div class="hint jf-added" id="jf-added-write" data-testid="jf-added-write" hidden></div>
|
|
1224
|
-
<div class="hint">One step per line. A line starting with <code>~</code> is a guardrail of the step above it. <code>Ask:</code> stops for you; <code>Ask 2h:</code> sets that ask's own wait. fwdloop adds the last check and the write to your Destination.</div>
|
|
1223
|
+
<div class="hint">One step per line. A line starting with <code>~</code> is a guardrail of the step above it. <code>Ask:</code> stops for you; <code>Ask 2h:</code> sets that ask's own wait. Your last line writes the result to the Destination. Leave it out and fwdloop suggests one.</div>
|
|
1225
1224
|
<div class="jf-err" id="jf-err-job" data-testid="jf-err-job"></div>
|
|
1226
1225
|
</div>
|
|
1227
1226
|
<div class="field">
|
|
@@ -2721,6 +2720,8 @@
|
|
|
2721
2720
|
// M16 am4: with `onList` the checks are drawn as rows of the list (tags, Drop) by the caller, so this draws the rest
|
|
2722
2721
|
function sheetBlockLines(sheet, onList){
|
|
2723
2722
|
if(!sheet) return [];
|
|
2723
|
+
// 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
|
|
2724
|
+
if(onList && sheet.codeBuilt === true) return [];
|
|
2724
2725
|
var out = [];
|
|
2725
2726
|
if((sheet.guardrails || []).length){
|
|
2726
2727
|
out.push("Guardrails:");
|
|
@@ -3590,7 +3591,16 @@
|
|
|
3590
3591
|
var stateSpan = document.createElement("span");
|
|
3591
3592
|
stateSpan.className = "badge " + auditStateClass(p.state) + " sign-badge";
|
|
3592
3593
|
stateSpan.setAttribute("data-testid", "audit-group-state");
|
|
3593
|
-
|
|
3594
|
+
var signEnd = p.status.indexOf(" ");
|
|
3595
|
+
if(p.state === "done" && p.status.charAt(0) === "[" && signEnd > 0){
|
|
3596
|
+
// hamr ask: the "passed" word is the same as the checks header's word (12px, text color); the [\u2713] sign keeps its green
|
|
3597
|
+
stateSpan.className += " audit-passed-word";
|
|
3598
|
+
var glyph = document.createElement("span");
|
|
3599
|
+
glyph.className = "audit-sign-glyph";
|
|
3600
|
+
glyph.textContent = p.status.slice(0, signEnd);
|
|
3601
|
+
stateSpan.appendChild(glyph);
|
|
3602
|
+
stateSpan.appendChild(document.createTextNode(p.status.slice(signEnd)));
|
|
3603
|
+
} else stateSpan.textContent = p.status;
|
|
3594
3604
|
h4.appendChild(stateSpan);
|
|
3595
3605
|
var dotSpan = document.createElement("span");
|
|
3596
3606
|
dotSpan.className = "audit-fold-dot";
|
|
@@ -4158,35 +4168,46 @@
|
|
|
4158
4168
|
if(rows.some(function(r){ return r.result === "none"; })) return glyphClass("[\u00B7]");
|
|
4159
4169
|
return glyphClass("[\u2713]");
|
|
4160
4170
|
}
|
|
4161
|
-
// borrowed-from: bareloop src/panel/index.html@v0.56.0 (3383cce) :1358 (auditCaret)
|
|
4162
|
-
function auditCaret(open){ return '<span class="audit-caret">' + (open ? "\u25BC" : "\u25B6") + '</span>'; }
|
|
4163
4171
|
function auditChecksEl(ac){
|
|
4164
4172
|
var all = (ac.checks || []).concat(ac.always || []);
|
|
4165
4173
|
var nPass = all.filter(function(r){ return r.result === "passed"; }).length;
|
|
4166
4174
|
var nFail = all.filter(function(r){ return r.result === "failed"; }).length;
|
|
4167
|
-
var head = "
|
|
4175
|
+
var head = " \u00B7 " + nPass + " passed" + (nFail ? " \u00B7 " + nFail + " failed" : "") + ((ac.notChecked || []).length ? " \u00B7 " + ac.notChecked.length + " not checked" : "");
|
|
4176
|
+
// hamr ask: the same component as a step fold (div.audit-group.audit-fold + h4.audit-status-header, as the schedule fold is), so it lines up with the step rows by construction
|
|
4168
4177
|
var wrap = document.createElement("div");
|
|
4169
|
-
wrap.className = "audit-
|
|
4178
|
+
wrap.className = "audit-group audit-fold closed";
|
|
4170
4179
|
wrap.setAttribute("data-testid", "audit-checks-group");
|
|
4171
|
-
var btn = document.createElement("
|
|
4172
|
-
btn.
|
|
4173
|
-
btn.
|
|
4174
|
-
btn.setAttribute("aria-expanded", "false");
|
|
4180
|
+
var btn = document.createElement("h4");
|
|
4181
|
+
btn.className = "audit-status-header";
|
|
4182
|
+
btn.setAttribute("role", "button"); btn.setAttribute("tabindex", "0"); btn.setAttribute("aria-expanded", "false");
|
|
4175
4183
|
btn.setAttribute("data-testid", "audit-checks-toggle");
|
|
4176
|
-
|
|
4177
|
-
var
|
|
4178
|
-
|
|
4184
|
+
btn.style.cursor = "pointer";
|
|
4185
|
+
var signCls = auditChecksSignClass(all);
|
|
4186
|
+
var sign = document.createElement("span"), signGlyph = document.createElement("span");
|
|
4187
|
+
sign.setAttribute("data-testid", "audit-checks-state");
|
|
4188
|
+
signGlyph.className = "audit-sign-glyph"; signGlyph.textContent = signCls === "green" ? "[\u2713]" : signCls === "red" ? "[\u2717]" : "[\u00B7]";
|
|
4189
|
+
sign.className = "badge " + signCls + " sign-badge" + (signCls === "green" ? " audit-passed-word" : "");
|
|
4190
|
+
sign.appendChild(signGlyph); btn.appendChild(sign);
|
|
4191
|
+
var nm = document.createElement("span"); nm.className = "audit-fold-name keep"; nm.innerHTML = "<b class=\"audit-checks-word\">checks</b>"; btn.appendChild(nm);
|
|
4192
|
+
var lead = document.createElement("span"); lead.textContent = "\u00b7"; btn.appendChild(lead);
|
|
4193
|
+
var tl = document.createElement("span"); tl.className = "audit-fold-tail wrap"; tl.textContent = head.replace(/^ \u00B7 /, ""); btn.appendChild(tl);
|
|
4179
4194
|
var body = document.createElement("div");
|
|
4180
|
-
body.className = "audit-
|
|
4195
|
+
body.className = "audit-fold-body";
|
|
4181
4196
|
body.hidden = true;
|
|
4182
4197
|
body.setAttribute("data-testid", "audit-checks-body");
|
|
4183
4198
|
var sec = function(title, rows, tid){
|
|
4184
4199
|
if(!rows || !rows.length) return "";
|
|
4185
4200
|
return '<div data-testid="' + tid + '" style="margin:6px 0"><div><b>' + escapeXml(title) + "</b></div>" + rows.map(auditCheckRowHtml).join("") + "</div>";
|
|
4186
4201
|
};
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
|
|
4202
|
+
var readSec = function(notes){
|
|
4203
|
+
if(!notes || !notes.length) return "";
|
|
4204
|
+
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>";
|
|
4205
|
+
};
|
|
4206
|
+
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>";
|
|
4207
|
+
function paint(open){ body.hidden = !open; wrap.classList.toggle("closed", !open); btn.setAttribute("aria-expanded", open ? "true" : "false"); }
|
|
4208
|
+
function toggle(){ var open = body.hidden; auditExpanded["\u0000checks"] = open; paint(open); }
|
|
4209
|
+
btn.addEventListener("click", toggle);
|
|
4210
|
+
btn.addEventListener("keydown", function(e){ if(e.key === "Enter" || e.key === " "){ e.preventDefault(); toggle(); } });
|
|
4190
4211
|
if(auditExpanded["\u0000checks"] === true) paint(true);
|
|
4191
4212
|
wrap.appendChild(btn); wrap.appendChild(body);
|
|
4192
4213
|
return wrap;
|
|
@@ -5292,7 +5313,17 @@
|
|
|
5292
5313
|
var root = document.createElement("div");
|
|
5293
5314
|
root.className = "answer-doors";
|
|
5294
5315
|
root.setAttribute("data-testid", "answer-doors");
|
|
5295
|
-
if(model.kind === "doors"){
|
|
5316
|
+
if(model.kind === "doors" && ask.kind === "action-stop"){
|
|
5317
|
+
// M13 am11 rule 3: the stop before the action: its question is the ask's own line; two buttons, Accept and Not now (the Stop: the run ends stopped, nothing is written). No reason box, no other words.
|
|
5318
|
+
var stopBar = document.createElement("div");
|
|
5319
|
+
stopBar.className = "actions-row";
|
|
5320
|
+
stopBar.setAttribute("data-testid", "action-bar");
|
|
5321
|
+
stopBar.appendChild(makeButton("Accept", "btn-accept", function(){ sendAnswer(root, ask, ctx, "accept"); }));
|
|
5322
|
+
stopBar.appendChild(makeButton("Not now", "btn-not-now", function(){
|
|
5323
|
+
postJSON("/api/stop", { flow: ctx.flow, runId: ctx.runId }).then(function(){ return reloadRun(ctx.flow, ctx.runId); }).catch(function(){ return reloadRun(ctx.flow, ctx.runId); });
|
|
5324
|
+
}));
|
|
5325
|
+
root.appendChild(stopBar);
|
|
5326
|
+
} else if(model.kind === "doors"){
|
|
5296
5327
|
if(model.note){
|
|
5297
5328
|
var note = textDiv("answer-msg refused", model.note);
|
|
5298
5329
|
note.setAttribute("data-testid", "answer-note");
|
|
@@ -5963,6 +5994,8 @@
|
|
|
5963
5994
|
return "line " + a.line + (a.lineText ? ": " + a.lineText : "") + "\n > " + a.answer;
|
|
5964
5995
|
})});
|
|
5965
5996
|
}
|
|
5997
|
+
// M13 am11 rule 1: the job's action, the AI's pick, with Drop (a redraft that makes the line an ordinary one)
|
|
5998
|
+
if(state.action && Number.isInteger(state.action.line)) blocks.push({id: "chat-action", action: state.action});
|
|
5966
5999
|
// M16 P4c: a plan with a list draws bareloop's plan view (lines, checks with their tags, Suggested, the folds) in one bubble, from the card the draft saved (server: state.list, planLines, always)
|
|
5967
6000
|
var list = state.list && Array.isArray(state.list.rows) ? state.list : null;
|
|
5968
6001
|
if(list){
|
|
@@ -6336,18 +6369,7 @@
|
|
|
6336
6369
|
clearBtn.textContent = b.text;
|
|
6337
6370
|
clearBtn.disabled = b.disabled;
|
|
6338
6371
|
}
|
|
6339
|
-
// M13 am8: the end code adds, in grey under the Job box (the server's `addEnd` is the one writer; this only shows it): an Ask unless the last step is already one, then the write.
|
|
6340
|
-
function paintAddedEnd(){
|
|
6341
|
-
var steps = jobEl.value.split("\n").map(function(l){ return l.trim(); }).filter(function(l){ return l !== "" && l.charAt(0) !== "~"; });
|
|
6342
|
-
var on = destEl.value.trim() !== "" && steps.length > 0;
|
|
6343
|
-
var needAsk = on && !/^ask[: ]/i.test(steps[steps.length - 1]);
|
|
6344
|
-
var askEl = byId("jf-added-ask"), writeEl = byId("jf-added-write");
|
|
6345
|
-
askEl.hidden = !needAsk; writeEl.hidden = !on;
|
|
6346
|
-
askEl.textContent = "+ Ask " + (askWaitEl.value.trim() || "1h") + ": check the result";
|
|
6347
|
-
writeEl.textContent = "+ Write to Destination";
|
|
6348
|
-
}
|
|
6349
6372
|
function refreshStartEnabled(){
|
|
6350
|
-
paintAddedEnd();
|
|
6351
6373
|
paintRequired();
|
|
6352
6374
|
startOk = startReady();
|
|
6353
6375
|
syncCardLock();
|
|
@@ -6832,14 +6854,21 @@
|
|
|
6832
6854
|
function planControlHTML(op, key){
|
|
6833
6855
|
return ' <button type="button" class="btn jp-btn" data-testid="plan-' + op + '" data-rowop="' + op + '" data-rowkey="' + escapeXml(key) + '">' + (op === "add" ? "Add" : "Drop") + "</button>";
|
|
6834
6856
|
}
|
|
6857
|
+
// M13 am11c: the action row, two cases, never a Drop (to change it, Revise). You picked it (Agree or typed): [you]. The AI's pick, or an old log with no `by`: [agent].
|
|
6858
|
+
function actionRowHtml(a){
|
|
6859
|
+
var n = escapeXml(String(a.line));
|
|
6860
|
+
if(a.by === "you") return '<div class="fold" data-testid="plan-action-row"><span class="mk">\u203A</span> line ' + n + ' writes everything before it' + byTagOf("you") + "</div>";
|
|
6861
|
+
return '<div class="fold" data-testid="plan-action-row"><span class="mk">\u203A</span> line ' + n + ' writes everything before it' + byTagOf("agent") + "</div>";
|
|
6862
|
+
}
|
|
6835
6863
|
// Your answers / Checked / Not checked; a plan being drafted again leaves them on show (like the plan), anything else without a green plan clears them
|
|
6836
6864
|
function renderExtras(state){
|
|
6837
6865
|
if(state && (state.phase === "revising" || state.phase === "redrafting")) return;
|
|
6838
6866
|
var v = extrasFor(state);
|
|
6839
6867
|
var html = v ? v.blocks.map(function(b){
|
|
6840
|
-
var inner = b.
|
|
6868
|
+
var inner = b.action ? '<div class="who">fwdloop</div>' + actionRowHtml(b.action)
|
|
6869
|
+
: b.plan ? '<div class="who">fwdloop</div>' + planViewHtml(b.plan, planControlHTML)
|
|
6841
6870
|
: '<b class="readout-head">' + escapeXml(b.head) + '</b>' + (b.sub ? ' <span class="hint">(' + escapeXml(b.sub) + ')</span>' : '') + (b.lines.length ? '\n' + b.lines.map(extraLineHTML).join("\n") : '');
|
|
6842
|
-
return '<div class="msg' + (b.plan ? ' bot' : '') + '" id="' + b.id + '" data-testid="' + b.id + '">' + inner + '</div>';
|
|
6871
|
+
return '<div class="msg' + (b.plan || b.action ? ' bot' : '') + '" id="' + b.id + '" data-testid="' + b.id + '">' + inner + '</div>';
|
|
6843
6872
|
}).join("") : "";
|
|
6844
6873
|
if(html !== extrasKey){ extrasKey = html; extrasEl.innerHTML = html; }
|
|
6845
6874
|
}
|
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);
|
package/src/planrebuild.js
CHANGED
|
@@ -14,10 +14,12 @@ import { setUpBlock, ticketLeaveOut, pickEdits, ledgerEdits } from './blockdraft
|
|
|
14
14
|
import { assembleFromBlock } from './blockassemble.js';
|
|
15
15
|
import { cardOfBlock } from './cardlist.js';
|
|
16
16
|
import { editsOf } from './rowedit.js';
|
|
17
|
+
import { NOTE_KIND } from './noteask.js';
|
|
17
18
|
import { offerRules, rowsFromAnswer, codeScope } from './checkpick.js';
|
|
18
19
|
import { matchRecord, readRowChoices, RECORD_FILE } from './pickrecord.js';
|
|
19
20
|
import { listLinesOf, cardLinesOf } from './checklistsign.js';
|
|
20
21
|
import { csvRolesOf } from './sheetblock.js';
|
|
22
|
+
import { withTicketRows } from './ticketrows.js';
|
|
21
23
|
import { isSheetKey, sheetChoice, withSheetRows, withSheetCard, droppedSheetOf } from './sheetrows.js';
|
|
22
24
|
import { validateDeclaration } from './declaration.js';
|
|
23
25
|
import { loadCatalogue } from './catalogue.js';
|
|
@@ -84,11 +86,13 @@ export function rebuildBlock({ planDir, asks }) {
|
|
|
84
86
|
texts, jobLines: plan.jobLines, look,
|
|
85
87
|
kept: { picks: matched.picks.filter(inBlock).filter(isKept), left: matched.left.filter(inBlock).filter(isKept), askRules: matched.askRules.filter(inBlock) },
|
|
86
88
|
fresh: { picks: matched.picks.filter(inBlock).filter((x) => !isKept(x)), left: leftFresh },
|
|
87
|
-
asks, countScope: (t) => codeScope(parsed.arbiter.sources, t) === 'in',
|
|
89
|
+
asks, countScope: (t) => codeScope(parsed.arbiter.sources, t) === 'in', leaveOut: ticketLeaveOut(declaration.flowType, plan.jobLines),
|
|
88
90
|
});
|
|
89
91
|
// the AI's replies, in the order the draft took them (log.json keeps each reply as sent)
|
|
90
92
|
const askRules = allShape.filter((r) => !isKept(r));
|
|
91
93
|
for (const e of Array.isArray(log?.log) ? log.log : []) {
|
|
94
|
+
// the note question's answers ride its entry, a failed turn's too (a `failed` answer is a Not checked row, so it must replay)
|
|
95
|
+
if (isRec(e) && e.kind === NOTE_KIND) { block.setNotes(notesOfEntry(e)); continue; }
|
|
92
96
|
if (!isRec(e) || e.outcome !== 'answered' || !isRec(e.args)) continue;
|
|
93
97
|
if (e.kind === 'check-suggest') block.applyDelta({ label: 'pre:check-suggest', pre: true, edits: pickEdits(rowsFromAnswer(askRules, e.args), blockLineNums) });
|
|
94
98
|
else if (e.kind === 'ledger-suggest') block.applyDelta({ label: 'pre:ledger-suggest', pre: true, edits: ledgerEdits(e.args.extra) });
|
|
@@ -106,7 +110,7 @@ export function rebuildBlock({ planDir, asks }) {
|
|
|
106
110
|
/**
|
|
107
111
|
* The checks of a rebuilt block put back into the saved plan's declaration (the same assembly the draft used), re-proved by the validator.
|
|
108
112
|
* @param {any} b @param {any} [from] the declaration to assemble over (a sheet Drop or Add changes its `close.sheet`); the saved one by default
|
|
109
|
-
* @returns {{ok: true, declaration: any, notChecked: string[], notCheckedBy: Record<string, string>, sheet: ReturnType<typeof withSheetRows>['sheet']}|{ok: false, say: string}}
|
|
113
|
+
* @returns {{ok: true, declaration: any, notChecked: string[], notCheckedBy: Record<string, string>, sheet: ReturnType<typeof withSheetRows>['sheet'], tickets: ReturnType<typeof withTicketRows>['tickets']}|{ok: false, say: string}}
|
|
110
114
|
*/
|
|
111
115
|
function assembleAgain(b, from = b.declaration) {
|
|
112
116
|
const { checkList: _c, pickedLines: _p, ...saved } = from;
|
|
@@ -116,10 +120,13 @@ function assembleAgain(b, from = b.declaration) {
|
|
|
116
120
|
const src = b.lineSet.has(st?.fromLine) && isRec(st.close) && isRec(st.close.cited) ? st.close.cited.source : undefined;
|
|
117
121
|
return typeof src === 'string' && docs.has(src) && Array.isArray(st.reads) ? { ...st, reads: st.reads.filter((/** @type {string} */ r) => r !== src) } : st;
|
|
118
122
|
}) };
|
|
119
|
-
const built = assembleFromBlock({ declaration: rest, block: b.block, lines: b.lines, lineSet: b.lineSet });
|
|
123
|
+
const built = assembleFromBlock({ declaration: rest, block: b.block, lines: b.lines, lineSet: b.lineSet, askLines: new Set(b.parsed.arbiter.asks.map((/** @type {any} */ a) => a.line)) });
|
|
120
124
|
// M16 am4: the sheet checks are rows on the list too, read from the steps the same way the draft read them
|
|
121
125
|
const withSheet = withSheetRows({ declaration: built.declaration, lines: b.lines, csvRoles: csvRolesOf(b.parsed.arbiter) });
|
|
122
|
-
|
|
126
|
+
// M17 am6: the Tickets filter and watch are rows on the list too, read from the declaration's fields the same way the draft read them
|
|
127
|
+
const withTickets = withTicketRows({ declaration: withSheet.declaration, lines: b.lines });
|
|
128
|
+
const ticketLines = withTickets.tickets.notChecked.map((t) => `not checked · "${t.rule}" — ${t.reason}`);
|
|
129
|
+
const a = { ...built, declaration: withTickets.declaration, notChecked: [...built.notChecked, ...ticketLines], notCheckedBy: { ...built.notCheckedBy, ...Object.fromEntries(ticketLines.map((t) => [t, 'you'])) } };
|
|
123
130
|
const cat = loadCatalogue();
|
|
124
131
|
if (!cat.ok) return { ok: false, say: 'The catalogue could not be read. Nothing was changed.' };
|
|
125
132
|
const inPlan = new Set(b.block.rows.filter((r) => r.state === 'built').flatMap((r) => (r.factNames ?? []).map((/** @type {string} */ nm) => `${r.line}:${nm}`)));
|
|
@@ -130,9 +137,12 @@ function assembleAgain(b, from = b.declaration) {
|
|
|
130
137
|
pageWords: { texts: b.texts, look: pageSources ? { facts: planFacts, dropped: b.look.dropped } : null, docs: docRolesOf(b.parsed.arbiter.sources) },
|
|
131
138
|
});
|
|
132
139
|
if (!verdict.ok) return { ok: false, say: `The changed list did not pass the plan's checks (${String(verdict.reds[0])}). Nothing was changed.` };
|
|
133
|
-
return { ok: true, declaration: a.declaration, notChecked: a.notChecked, notCheckedBy: a.notCheckedBy, sheet: withSheet.sheet };
|
|
140
|
+
return { ok: true, declaration: a.declaration, notChecked: a.notChecked, notCheckedBy: a.notCheckedBy, sheet: withSheet.sheet, tickets: withTickets.tickets };
|
|
134
141
|
}
|
|
135
142
|
|
|
143
|
+
/** the answers a note-question entry of the draft's log recorded; only well-formed ones (a line, yes|no|failed) @param {any} e @returns {{line: number, answer: 'yes'|'no'|'failed'}[]} */
|
|
144
|
+
const notesOfEntry = (e) => (Array.isArray(e.notes) ? e.notes.filter((/** @type {any} */ a) => isRec(a) && Number.isInteger(a.line) && (a.answer === 'yes' || a.answer === 'no' || a.answer === 'failed')) : []);
|
|
145
|
+
|
|
136
146
|
/** the plan's list and the closes it checks, as one comparable string (the proof that the rebuild is the saved plan) @param {any} d */
|
|
137
147
|
const fingerprint = (d) => JSON.stringify([d.checkList ?? null, (d.steps ?? []).map((/** @type {any} */ s) => [s?.fromLine, s?.close])]);
|
|
138
148
|
|
|
@@ -199,7 +209,7 @@ export function rowEditPlan({ planDir, op, key, asks = true }) {
|
|
|
199
209
|
'readout.txt': readoutText,
|
|
200
210
|
[NOT_CHECKED_FILE]: dj({ notChecked, ...(Object.keys(by).length ? { by } : {}) }),
|
|
201
211
|
[RECORD_FILE]: dj({ ...record, rowChoices: b.block.choicesRecord(), ...(droppedNow.length ? { sheetDropped: droppedNow } : {}) }),
|
|
202
|
-
'log.json': dj({ ...(isRec(b.log) ? b.log : {}), log: [...(Array.isArray(b.log?.log) ? b.log.log : []), logRow], checkCard: withSheetCard(cardOfBlock(b.block), after.sheet, droppedNow) }),
|
|
212
|
+
'log.json': dj({ ...(isRec(b.log) ? b.log : {}), log: [...(Array.isArray(b.log?.log) ? b.log.log : []), logRow], checkCard: (() => { const c = withSheetCard(cardOfBlock(b.block), after.sheet, droppedNow); return after.tickets.card.length ? withSheetCard(c, { card: after.tickets.card }) : c; })() }),
|
|
203
213
|
'spec.hash': `${h.hash}\n`,
|
|
204
214
|
},
|
|
205
215
|
};
|