fwdloop 0.32.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 +20 -2
- package/package.json +2 -2
- package/src/auditchecks.js +55 -0
- package/src/authoring.js +53 -12
- package/src/blockasks.js +45 -0
- package/src/blockassemble.js +159 -0
- package/src/blockdraft.js +86 -0
- package/src/blocklines.js +30 -0
- package/src/blockpick.js +175 -0
- package/src/cardlist.js +19 -0
- package/src/checkblock.js +843 -0
- package/src/checked.js +48 -9
- package/src/checklist.js +99 -0
- package/src/checklistsign.js +93 -0
- package/src/checkpick.js +7 -73
- package/src/checkwords.js +20 -1
- package/src/cited-record.js +21 -1
- package/src/citedcheck.js +162 -7
- package/src/closers.js +41 -3
- package/src/declaration.js +34 -9
- package/src/declaredclose.js +4 -0
- package/src/draft-steps.js +3 -1
- package/src/drafter.js +311 -206
- package/src/factwords.js +112 -0
- package/src/inputlook.js +53 -0
- package/src/labelscan.js +162 -0
- package/src/noteask.js +62 -0
- package/src/pageask.js +9 -69
- package/src/pagedropwords.js +11 -1
- package/src/pagedry.js +27 -4
- package/src/pagerules.js +19 -3
- package/src/panel/author.js +76 -7
- package/src/panel/authorcard.js +43 -17
- package/src/panel/data.js +41 -9
- package/src/panel/index.html +208 -13
- package/src/panel/result.js +4 -3
- package/src/panel/server.js +3 -1
- package/src/pickrecord.js +70 -54
- package/src/placerule.js +398 -0
- package/src/planrebuild.js +216 -0
- package/src/rowedit.js +148 -0
- package/src/rubricstep.js +272 -0
- package/src/runfile.js +4 -2
- package/src/runner.js +67 -10
- package/src/setup.js +11 -5
- package/src/sheetblock.js +22 -8
- package/src/sheetbuild.js +151 -0
- package/src/sheetchecks.js +52 -66
- package/src/sheetclaims.js +12 -32
- package/src/sheetfind.js +4 -4
- package/src/sheetlook.js +14 -3
- package/src/sheetoffer.js +74 -57
- package/src/sheetrows.js +123 -0
- package/src/sheetrun.js +13 -10
- package/src/summary-words.js +3 -3
- package/src/ticket-draft.js +4 -21
- package/src/ticketrows.js +100 -0
- package/src/try-checks.js +31 -12
- package/src/types.js +1 -0
- package/types/auditchecks.d.ts +25 -0
- package/types/authoring.d.ts +21 -2
- package/types/blockasks.d.ts +36 -0
- package/types/blockassemble.d.ts +50 -0
- package/types/blockdraft.d.ts +75 -0
- package/types/blocklines.d.ts +31 -0
- package/types/blockpick.d.ts +46 -0
- package/types/cardlist.d.ts +21 -0
- package/types/checkblock.d.ts +378 -0
- package/types/checked.d.ts +16 -2
- package/types/checklist.d.ts +115 -0
- package/types/checklistsign.d.ts +27 -0
- package/types/checkpick.d.ts +4 -34
- package/types/checkwords.d.ts +5 -0
- package/types/cited-record.d.ts +9 -0
- package/types/citedcheck.d.ts +33 -2
- package/types/closers.d.ts +24 -2
- package/types/declaration.d.ts +7 -0
- package/types/declaredclose.d.ts +2 -0
- package/types/drafter.d.ts +29 -715
- package/types/factwords.d.ts +38 -0
- package/types/inputlook.d.ts +49 -0
- package/types/labelscan.d.ts +35 -0
- package/types/noteask.d.ts +52 -0
- package/types/pageask.d.ts +2 -35
- package/types/pagedry.d.ts +13 -0
- package/types/pagerules.d.ts +7 -0
- package/types/panel/author.d.ts +41 -0
- package/types/panel/authorcard.d.ts +14 -9
- package/types/panel/authorflows.d.ts +4 -4
- package/types/panel/data.d.ts +5 -3
- package/types/panel/jobgrid.d.ts +1 -1
- package/types/pickrecord.d.ts +69 -13
- package/types/placerule.d.ts +208 -0
- package/types/planrebuild.d.ts +52 -0
- package/types/provider.d.ts +1 -1
- package/types/rowedit.d.ts +48 -0
- package/types/rubricstep.d.ts +63 -0
- package/types/runfile.d.ts +5 -2
- package/types/runner.d.ts +45 -1
- package/types/sheetblock.d.ts +12 -4
- package/types/sheetbuild.d.ts +84 -0
- package/types/sheetchecks.d.ts +12 -18
- package/types/sheetclaims.d.ts +2 -1
- package/types/sheetfind.d.ts +2 -2
- package/types/sheetoffer.d.ts +31 -6
- package/types/sheetrows.d.ts +81 -0
- package/types/sheetrun.d.ts +4 -4
- package/types/summary-words.d.ts +2 -1
- package/types/ticket-draft.d.ts +3 -49
- package/types/ticketrows.d.ts +61 -0
- package/types/try-checks.d.ts +4 -2
- package/types/types.d.ts +8 -0
- package/src/repairs.js +0 -38
- package/types/repairs.d.ts +0 -13
package/src/panel/author.js
CHANGED
|
@@ -36,8 +36,11 @@ import { dirname, join } from 'node:path';
|
|
|
36
36
|
import { fileURLToPath } from 'node:url';
|
|
37
37
|
|
|
38
38
|
import {
|
|
39
|
-
ANSWER_FILE, NOT_CHECKED_FILE, OPEN_QUESTION_SAY, PANEL_DRAFTS_DIR, readQuestions, readoutHeadIndexes, scrub, signDraft,
|
|
39
|
+
ANSWER_FILE, NOT_CHECKED_FILE, OPEN_QUESTION_SAY, PANEL_DRAFTS_DIR, claimPlanDir, readQuestions, readoutHeadIndexes, scrub, signDraft, writePlanFiles,
|
|
40
40
|
} from '../authoring.js';
|
|
41
|
+
import { rowEditPlan } from '../planrebuild.js';
|
|
42
|
+
import { cardLinesOf } from '../checklistsign.js';
|
|
43
|
+
import { appendSpendRow } from '../provider.js';
|
|
41
44
|
import { ruleOfAnswer, panelQuestionText, DROP_IT } from '../pageask.js';
|
|
42
45
|
import { checkFlowName, nextRunId, readFileInside, readdirInside } from '../flow.js';
|
|
43
46
|
import { readModelRecord } from '../flowmodel.js';
|
|
@@ -49,6 +52,7 @@ import {
|
|
|
49
52
|
applyAnswers, capFloorFor, capFloorOf, capFloorUsd, cardFields, checkCard, checkInputRows, parseInputLines, parseJobBox,
|
|
50
53
|
} from './authorcard.js';
|
|
51
54
|
import { checkedLines, notCheckedView } from '../checked.js';
|
|
55
|
+
import { EVERY_STEP_TEXTS } from '../try-checks.js';
|
|
52
56
|
import { recordPath, RECORD_FILE, KEPT_WORDS } from '../pickrecord.js';
|
|
53
57
|
import { csvRolesOf } from '../sheetblock.js';
|
|
54
58
|
import {
|
|
@@ -132,6 +136,9 @@ export function createAuthor(opts) {
|
|
|
132
136
|
};
|
|
133
137
|
|
|
134
138
|
const readJson = readJsonFile;
|
|
139
|
+
/** every file text scrubbed of the keys, as the draft child writes them @param {Record<string, string>} files @param {string[]} keys */
|
|
140
|
+
const scrubbed = (files, keys) => Object.fromEntries(Object.entries(files).map(([f, t]) => [f, scrub(t, keys)]));
|
|
141
|
+
const isObj = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
135
142
|
|
|
136
143
|
/**
|
|
137
144
|
* The monthly room for a cap, from the ONE read-only check the CLI's door also decides on (`checkMonthlyRoom`, src/monthly.js).
|
|
@@ -255,7 +262,8 @@ export function createAuthor(opts) {
|
|
|
255
262
|
const kind = redrafts.has(n) ? 'answers' : 'revise';
|
|
256
263
|
if (kind === 'revise') reviseNo += 1;
|
|
257
264
|
// M4d am15 (every line of the list): this plan's own line, from its own log, built by `reviseStepList`; the try history is in the Audit Draft group
|
|
258
|
-
const
|
|
265
|
+
const rowEdit = kind === 'answers' ? readJson(dir, `redraft-${n}.json`)?.rowEdit : undefined;
|
|
266
|
+
const name = rowEdit ? (rowEdit.op === 'drop' ? 'a check dropped' : 'a check added') : kind === 'answers' ? 'drafted again with your answers' : `revise ${reviseNo}`;
|
|
259
267
|
const running = n === newest && childRunning(dir); // C9: running first, then the result
|
|
260
268
|
// the result BEFORE the log: the child writes log.json first and the result (spec.hash, or the red log itself) after, so a result we see has its log already on disk
|
|
261
269
|
const res = resultOf(dir, `draft-${n}`, keys);
|
|
@@ -278,6 +286,9 @@ export function createAuthor(opts) {
|
|
|
278
286
|
// the plan's questions: any open one makes the phase `questions-open`, whatever colour the plan is (the answers are what it was waiting for)
|
|
279
287
|
const q = rel === 'draft' ? firstQs : readQuestions(join(dir, rel));
|
|
280
288
|
if (q.open.length > 0) {
|
|
289
|
+
// the child writes its questions, THEN exits; `answer` refuses `draft-live` while it is alive, so a question is offered only once it has ended (one decider: what the phase offers, the answer door takes).
|
|
290
|
+
// A child never comes back to life, so a stale "alive" only delays the offer; asked AFTER the files were read, the questions are already on disk (C9's order is for a missing result)
|
|
291
|
+
if (childRunning(dir)) return { ...shared, phase: newest > 0 ? (cur.kind === 'answers' ? 'redrafting' : 'revising') : 'drafting' };
|
|
281
292
|
const lineText = (line) => parseJobBox(typeof card?.job === 'string' ? card.job : '').steps[line - 1]?.text ?? null;
|
|
282
293
|
const questions = q.questions.map((x) => ({ k: x.k, line: x.line, lineText: lineText(x.line), question: scrub(x.question, keys), answered: x.answer !== null, ...(x.source === 'look' ? { source: 'look', ask: x.ask, proposes: typeof x.proposal === 'string' && (x.ask === 'reading' || x.ask === 'check'), drops: Number.isInteger(x.ruleNo), shown: scrub(panelQuestionText(x), keys) } : {}) }));
|
|
283
294
|
return { ...shared, stepList: stepListOf(dir, rel, keys, true), phase: 'questions-open', plan: rel, questions, openK: q.open[0].k, total: q.questions.length };
|
|
@@ -315,7 +326,16 @@ export function createAuthor(opts) {
|
|
|
315
326
|
...(parsed?.ok === true ? { askLines: parsed.arbiter.asks.map((x) => x.line), lines: parsed.lines, csvRoles: csvRolesOf(parsed.arbiter) } : { hasAsk: true }),
|
|
316
327
|
...(Array.isArray(kept) ? { keptChecks: kept.filter((k) => k && k.check).map((k) => ({ line: k.line, check: k.check })), keptWords: KEPT_WORDS } : {}),
|
|
317
328
|
};
|
|
318
|
-
|
|
329
|
+
const ncFile = readJson(dir, `${rel}/${NOT_CHECKED_FILE}`);
|
|
330
|
+
const view = notCheckedView(ncFile?.notChecked, decl);
|
|
331
|
+
// M16 item 5: the plan card's list - the rows with their tags and Drop, the suggestions with Add - read from the card the draft saved (src/cardlist.js); a plan without a list has none
|
|
332
|
+
const card = cardLinesOf(decl).size > 0 ? readJson(dir, `${rel}/log.json`)?.checkCard : undefined;
|
|
333
|
+
const list = card && Array.isArray(card.rows) && Array.isArray(card.suggested) ? { lines: [...cardLinesOf(decl)].sort((a, b) => a - b), rows: card.rows, suggested: card.suggested } : null;
|
|
334
|
+
// M16 P4c (bareloop's plan view): the job's lines with their `~` rules (the signed text's own, split at its "; " joins) and the two checks every step has; a plan with a list draws them
|
|
335
|
+
const planLines = parsed?.ok === true ? parsed.lines.map((/** @type {any} */ l) => ({ n: l.n, text: l.text, rules: l.guardrail ? l.guardrail.split('; ') : [] })) : [];
|
|
336
|
+
return {
|
|
337
|
+
checked: checkedLines(decl, opts), notChecked: { ...view, ...(isObj(ncFile?.by) ? { by: ncFile.by } : {}) }, ...(list ? { list, planLines, always: [...EVERY_STEP_TEXTS] } : {}),
|
|
338
|
+
};
|
|
319
339
|
}
|
|
320
340
|
|
|
321
341
|
/** The answers an answer-redraft was drafted with, as the marker recorded them: `[{ line, lineText, question, answer }]` (scrubbed). @param {string} dir @param {number} n @param {string[]} keys */
|
|
@@ -778,12 +798,12 @@ export function createAuthor(opts) {
|
|
|
778
798
|
const all = full.map((x) => {
|
|
779
799
|
const typed = x.k === v.openK ? answer : x.answer;
|
|
780
800
|
const ch = x.k === v.openK ? choice : x.choice;
|
|
781
|
-
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 };
|
|
782
802
|
});
|
|
783
803
|
const adds = all.filter((x) => x.rule !== null);
|
|
784
804
|
const grown = applyAnswers(typeof v.card.job === 'string' ? v.card.job : '', all);
|
|
785
805
|
if (grown.added !== adds.length) return { status: 409, body: { ok: false, refused: 'no-such-line', say: 'An answer is about a job line the card no longer has. Draft again from the card. Nothing was signed.' } };
|
|
786
|
-
const vet = vetCard({ ...v.card, job: grown.job }, loaded, draftedSoFar(dir, v.card));
|
|
806
|
+
const vet = vetCard({ ...v.card, job: grown.job }, loaded, draftedSoFar(dir, v.card), readJson(dir, RUN_OF_FILE)?.flow);
|
|
787
807
|
if (!vet.ok) return vet.reply;
|
|
788
808
|
for (const other of listIds()) {
|
|
789
809
|
if (other === id) continue;
|
|
@@ -791,7 +811,7 @@ export function createAuthor(opts) {
|
|
|
791
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.' } };
|
|
792
812
|
}
|
|
793
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`.
|
|
794
|
-
redraft = { vet, all, picks: grown.picks, left: grown.left };
|
|
814
|
+
redraft = { vet, all, picks: grown.picks, left: grown.left, columns: grown.columns };
|
|
795
815
|
}
|
|
796
816
|
try {
|
|
797
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
|
|
@@ -813,7 +833,7 @@ export function createAuthor(opts) {
|
|
|
813
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' });
|
|
814
834
|
child = spawnDetached({
|
|
815
835
|
bin,
|
|
816
|
-
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)],
|
|
817
837
|
env: loaded.env,
|
|
818
838
|
logPath: join(dir, `redraft-${n}.log`),
|
|
819
839
|
});
|
|
@@ -826,6 +846,55 @@ export function createAuthor(opts) {
|
|
|
826
846
|
return { status: 202, body: { ok: true, draftId: id, n, redrafting: true } };
|
|
827
847
|
},
|
|
828
848
|
|
|
849
|
+
/**
|
|
850
|
+
* `POST /api/author/:id/row-edit` body `{ op: 'drop'|'add', key }` (M16 item 5, am3 (4); hamr 2026-11-13 N-2): the plan card's Drop and Add. $0 and instant: the panel REBUILDS the list from the
|
|
851
|
+
* newest green plan's saved files (src/planrebuild.js), applies the choice through the block's own `rowChoice`, and writes a NEW plan folder `draft-<n>` (records are write-once, the old plan is
|
|
852
|
+
* never touched) booked as a plan of its own with a $0 spend row. It spawns no `fwdloop draft`, builds no provider, makes no call. Signing then reads the new plan (its hash). A refusal is plain
|
|
853
|
+
* words and writes nothing.
|
|
854
|
+
* @param {string} id @param {any} body
|
|
855
|
+
*/
|
|
856
|
+
rowEdit(id, body) {
|
|
857
|
+
const { keys } = keysNow();
|
|
858
|
+
if (!ID_RE.test(id)) return { status: 404, body: { ok: false, refused: 'no-such-draft' } };
|
|
859
|
+
const dd = draftsDir();
|
|
860
|
+
const dir = dd === null ? null : join(dd, id);
|
|
861
|
+
const v = dir === null ? null : /** @type {any} */ (readDraft(dir, id, keys));
|
|
862
|
+
if (dir === null || v === null || v.card === null) return { status: 404, body: { ok: false, refused: 'no-such-draft' } };
|
|
863
|
+
if (v.phase !== 'green' || typeof v.plan !== 'string' || !Array.isArray(v.revises)) return { status: 409, body: { ok: false, refused: 'not-green', say: `This draft is ${v.phase}, not a finished plan, so its checks cannot be changed.` } };
|
|
864
|
+
const b = body && typeof body === 'object' ? body : {};
|
|
865
|
+
if (b.op !== 'drop' && b.op !== 'add') return { status: 400, body: { ok: false, refused: 'bad-choice', say: 'That is not one of the choices. Nothing was changed.' } };
|
|
866
|
+
if (typeof b.key !== 'string' || b.key === '' || b.key.length > 200) return { status: 400, body: { ok: false, refused: 'bad-row', say: 'That check is not on the list. Nothing was changed.' } };
|
|
867
|
+
if (childRunning(dir)) return { status: 409, body: { ok: false, refused: 'draft-live', say: 'The draft process is still finishing. Try again in a moment.' } };
|
|
868
|
+
// the plan was drafted with questions on, unless it is the redraft after answers (it never asks); a plan made by a Drop or an Add keeps the one it came from
|
|
869
|
+
const cur = PLAN_DIR_RE.exec(v.plan)?.[1];
|
|
870
|
+
const marker = cur === undefined ? null : readJson(dir, `redraft-${cur}.json`);
|
|
871
|
+
const asks = marker === null ? true : (marker.rowEdit ? marker.rowEdit.asks !== false : false);
|
|
872
|
+
const planDir = join(dir, v.plan);
|
|
873
|
+
const made = rowEditPlan({ planDir, op: b.op, key: b.key, asks });
|
|
874
|
+
if (!made.ok) return { status: 409, body: { ok: false, refused: made.refused ?? 'row-edit', say: made.say } };
|
|
875
|
+
const n = Math.max(0, ...v.revises.map((x) => x.n)) + 1;
|
|
876
|
+
const at = new Date().toISOString();
|
|
877
|
+
const newDir = join(dir, `draft-${n}`);
|
|
878
|
+
const prose = readFileInside(planDir, 'prose.txt');
|
|
879
|
+
try {
|
|
880
|
+
claimPlanDir(newDir);
|
|
881
|
+
if (Object.keys(made.pages).length > 0) claimPlanDir(join(newDir, 'pages'));
|
|
882
|
+
writePlanFiles(newDir, scrubbed(made.files, keys));
|
|
883
|
+
writePlanFiles(newDir, scrubbed(made.pages, keys));
|
|
884
|
+
// the $0 book of this plan: no call was made, so no round and no cost (a known $0, not an unknown one)
|
|
885
|
+
appendSpendRow(join(newDir, 'spend.jsonl'), {
|
|
886
|
+
kind: 'draft', provider: null, price: null, model: readModelRecord(planDir)?.model ?? null, modelReturned: null, tokens: null, costUsd: 0, rounds: 0, calls: 0, spendComplete: true, stop: null, budgetUsd: null, startedAt: at, wallMs: 0,
|
|
887
|
+
});
|
|
888
|
+
writePlanFiles(dir, {
|
|
889
|
+
[`card-${n}.json`]: `${JSON.stringify(v.card, null, 2)}\n`, [`prose-${n}.txt`]: prose.ok ? prose.text : '',
|
|
890
|
+
[`redraft-${n}.json`]: `${JSON.stringify({ fromPlan: v.plan, answers: [], rowEdit: { op: b.op, key: b.key, at, asks } })}\n`,
|
|
891
|
+
}, { flag: 'wx', mode: 0o600 });
|
|
892
|
+
} catch (e) {
|
|
893
|
+
return { status: 500, body: { ok: false, refused: 'write', say: `The changed plan could not be saved (${/** @type {any} */ (e)?.code ?? 'error'}). Nothing was changed.` } };
|
|
894
|
+
}
|
|
895
|
+
return { status: 200, body: { ok: true, draftId: id, n, plan: `draft-${n}`, hash: made.hash } };
|
|
896
|
+
},
|
|
897
|
+
|
|
829
898
|
/**
|
|
830
899
|
* `GET /api/author/live`: the newest draft that is not abandoned or signed, and the newest panel start the human has not cleared
|
|
831
900
|
* (`starting` or `refused`; a `started` one is in Runs) — read from files, never memory.
|
package/src/panel/authorcard.js
CHANGED
|
@@ -15,6 +15,8 @@ import {
|
|
|
15
15
|
import { isAbsolute, join } from 'node:path';
|
|
16
16
|
|
|
17
17
|
import { checkFlowName } from '../flow.js';
|
|
18
|
+
import { sameRuleWords } from '../blockpick.js';
|
|
19
|
+
import { isColumnChoiceRule, columnChoiceParts, swapColumnWord } from '../sheetoffer.js';
|
|
18
20
|
import { isWebUrl } from '../pagefetch.js';
|
|
19
21
|
import { checkSendDestination } from '../runner.js';
|
|
20
22
|
import { parseSignedText } from '../signed-text.js';
|
|
@@ -95,7 +97,7 @@ export function parseJobBox(text) {
|
|
|
95
97
|
* that line's own `~` lines (several answers for one line keep their order). The job box's own lines are untouched; the card -> prose path
|
|
96
98
|
* (`cardToProse`) then writes the answer as that line's guardrail, so it reaches the signed text and the hash. Pure. An answer for a line
|
|
97
99
|
* the box does not have is NOT added (the caller sees the count). An answer equal (exact string, after trim) to a `~` rule already on that line is not added
|
|
98
|
-
* again, and still counts: it is taken, the line already says it.
|
|
100
|
+
* again (case, spacing and trailing punctuation aside; also not when it is one `; ` part of a `~` line), and still counts: it is taken, the line already says it.
|
|
99
101
|
* @param {string} job @param {{ line: number, answer: string }[]} answers
|
|
100
102
|
* @returns {{ job: string, added: number }}
|
|
101
103
|
*/
|
|
@@ -103,7 +105,7 @@ export function appendAnswersToJob(job, answers) {
|
|
|
103
105
|
const raw = String(job).split('\n');
|
|
104
106
|
/** @type {Map<number, number>} the index of the last non-empty box line that belongs to each step (its own line or a `~` under it) */
|
|
105
107
|
const lastOf = new Map();
|
|
106
|
-
/** @type {Map<number,
|
|
108
|
+
/** @type {Map<number, string[]>} the `~` rules each step already has: a `~` line's whole words, and each `; ` part of it (a rule of its own) */
|
|
107
109
|
const have = new Map();
|
|
108
110
|
let step = 0;
|
|
109
111
|
raw.forEach((l, i) => {
|
|
@@ -111,7 +113,7 @@ export function appendAnswersToJob(job, answers) {
|
|
|
111
113
|
if (t === '') return;
|
|
112
114
|
if (!t.startsWith('~')) step += 1;
|
|
113
115
|
if (step > 0) lastOf.set(step, i);
|
|
114
|
-
if (step > 0 && t.startsWith('~')) have.set(step, (have.get(step) ??
|
|
116
|
+
if (step > 0 && t.startsWith('~')) { const w = t.slice(1).trim(); have.set(step, [...(have.get(step) ?? []), w, ...w.split('; ').filter(Boolean)]); }
|
|
115
117
|
});
|
|
116
118
|
/** @type {Map<number, string[]>} */
|
|
117
119
|
const after = new Map();
|
|
@@ -120,9 +122,11 @@ export function appendAnswersToJob(job, answers) {
|
|
|
120
122
|
if (!lastOf.has(a.line)) continue;
|
|
121
123
|
const at = /** @type {number} */ (lastOf.get(a.line));
|
|
122
124
|
added += 1;
|
|
123
|
-
const rules = have.get(a.line) ??
|
|
124
|
-
|
|
125
|
-
|
|
125
|
+
const rules = have.get(a.line) ?? [];
|
|
126
|
+
// borrowed-from: bareloop src/panel/authorsession.js@v0.56.0 (3383cce) F318 0291e910
|
|
127
|
+
// words the line already holds as a rule (a whole `~` line or one `; ` part of it) add no second line; different words still add one
|
|
128
|
+
if (rules.some((t) => sameRuleWords(t, a.answer))) continue;
|
|
129
|
+
have.set(a.line, [...rules, a.answer.trim()]);
|
|
126
130
|
after.set(at, [...(after.get(at) ?? []), `~ ${a.answer}`]);
|
|
127
131
|
}
|
|
128
132
|
const out = [];
|
|
@@ -131,7 +135,7 @@ export function appendAnswersToJob(job, answers) {
|
|
|
131
135
|
}
|
|
132
136
|
|
|
133
137
|
/**
|
|
134
|
-
* 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.
|
|
135
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
|
|
136
140
|
* @returns {{ job: string, replaced: boolean }}
|
|
137
141
|
*/
|
|
@@ -145,33 +149,55 @@ export function replaceRuleOnJob(job, line, oldText, newText) {
|
|
|
145
149
|
if (!t.startsWith('~')) { step += 1; continue; }
|
|
146
150
|
if (step === line && norm(t.slice(1)) === norm(oldText)) { raw[i] = `~ ${newText}`; return { job: raw.join('\n'), replaced: true }; }
|
|
147
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
|
+
}
|
|
148
163
|
return { job: String(job), replaced: false };
|
|
149
164
|
}
|
|
150
165
|
|
|
151
166
|
/**
|
|
152
|
-
* THE one writer of what a set of answers does to the job box and to the picks (M4e am24, M10 am16 (4),
|
|
153
|
-
* (
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
* @
|
|
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}[]}}
|
|
157
173
|
*/
|
|
158
174
|
export function applyAnswers(job, all) {
|
|
159
175
|
let out = job;
|
|
160
176
|
let done = 0;
|
|
161
177
|
/** @type {{ line: number, answer: string }[]} */
|
|
162
178
|
const appends = [];
|
|
179
|
+
/** @type {{line: number, word: string, column: string}[]} */
|
|
180
|
+
const columns = [];
|
|
163
181
|
for (const x of all) {
|
|
164
182
|
if (x.rule === null) continue;
|
|
165
|
-
|
|
166
|
-
|
|
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);
|
|
167
193
|
if (r.replaced) { out = r.job; done += 1; }
|
|
168
194
|
} else appends.push({ line: x.line, answer: x.rule });
|
|
169
195
|
}
|
|
170
196
|
const grown = appendAnswersToJob(out, appends);
|
|
171
197
|
const picks = all.filter((x) => (x.ask === 'check' || x.ask === 'no-check') && !x.left)
|
|
172
|
-
.map((x) => ({ line: x.line, rule: x.
|
|
173
|
-
const left = all.filter((x) => x.left).
|
|
174
|
-
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 };
|
|
175
201
|
}
|
|
176
202
|
|
|
177
203
|
/**
|
package/src/panel/data.js
CHANGED
|
@@ -40,8 +40,11 @@ import { readSpendRows } from '../provider.js';
|
|
|
40
40
|
import { applyRunValues, parseWaitMs, pickRunValues, VALUES_FILE_RE } from '../runvalues.js';
|
|
41
41
|
import { readSetup } from '../setup.js';
|
|
42
42
|
import { parseHintBlock } from '../learn.js';
|
|
43
|
-
import { checkedLines, notCheckedView,
|
|
44
|
-
import {
|
|
43
|
+
import { checkedLines, notCheckedView, notCheckedLabelOf, listPartRows } from '../checked.js';
|
|
44
|
+
import { EVERY_STEP_TEXTS } from '../try-checks.js';
|
|
45
|
+
import { LABEL_PICKED, tagOf } from '../checkwords.js';
|
|
46
|
+
import { listLinesOf } from '../checklistsign.js';
|
|
47
|
+
import { auditChecksOf } from '../auditchecks.js';
|
|
45
48
|
import { panelQuestionText } from '../pageask.js';
|
|
46
49
|
import { csvRolesOf, askSheetCard } from '../sheetblock.js';
|
|
47
50
|
import { readSheetChecks } from '../sheet-record.js';
|
|
@@ -1543,7 +1546,7 @@ function runSummary(ctx, glyph, { root, catalogue, triggerRead, now, home }) {
|
|
|
1543
1546
|
}
|
|
1544
1547
|
const send = ctx.arbiter && Array.isArray(ctx.arbiter.sends) ? ctx.arbiter.sends.find((x) => x.target && typeof x.target.path === 'string') : undefined;
|
|
1545
1548
|
const endedPlain = endedWords({
|
|
1546
|
-
outcome, died, line, destination: send ? send.target.path : null, canResume: ctx.resumable === true && ctx.sameJob === true, home, skipReason: ctx.historyRow?.skipReason,
|
|
1549
|
+
outcome, died, line, destination: send ? send.target.path : null, canResume: ctx.resumable === true && ctx.sameJob === true, home, skipReason: ctx.historyRow?.skipReason, anywayOffered: newTicketScheduleOf(ctx.flowDir) !== null,
|
|
1547
1550
|
});
|
|
1548
1551
|
// M9 am7 item 1: ENDED opens with the run's local end date and time, then its outcome word, then today's reason (NEXT stays as it was)
|
|
1549
1552
|
const ended = endedPlain === null ? null : {
|
|
@@ -1565,6 +1568,15 @@ function runSummary(ctx, glyph, { root, catalogue, triggerRead, now, home }) {
|
|
|
1565
1568
|
return { ended, scheduled, schedule, canSchedule: !!(t && t.hasGreenRun), catchUp: catchUpWords(rec) };
|
|
1566
1569
|
}
|
|
1567
1570
|
|
|
1571
|
+
/**
|
|
1572
|
+
* M13 am10: the job's schedule when it is a new-ticket one, else null. The one test for "the panel has Run it anyway here": the grid's `anyway` and the skipped run's next line both ask it.
|
|
1573
|
+
* @param {string} flowDir
|
|
1574
|
+
*/
|
|
1575
|
+
function newTicketScheduleOf(flowDir) {
|
|
1576
|
+
const sched = readSchedule(flowDir);
|
|
1577
|
+
return sched && sched.trigger?.kind === 'new-ticket' ? sched : null;
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1568
1580
|
/**
|
|
1569
1581
|
* `GET /api/runs/:flow/:runId` — the Run tab (M4a scope item 2): the step
|
|
1570
1582
|
* map from `declaration.steps`, step cards -> attempts from `audit.jsonl`
|
|
@@ -1899,6 +1911,8 @@ export function draftTotals(modelRows, ctx = {}) {
|
|
|
1899
1911
|
*/
|
|
1900
1912
|
export function getDraftBlock(flowDir, runDir) {
|
|
1901
1913
|
const setup = readSetup(flowDir);
|
|
1914
|
+
// M16 item 5: a plan with a list tags the rule a person's answer added `[you]` (a row's `by`), an older plan keeps `[you picked]`
|
|
1915
|
+
const youTag = (() => { try { const d = readFileInside(flowDir, 'declaration.json'); return d.ok && listLinesOf(JSON.parse(d.text)).size > 0 ? tagOf('you') : LABEL_PICKED; } catch { return LABEL_PICKED; } })();
|
|
1902
1916
|
const rows = [];
|
|
1903
1917
|
const human = (r, attempt, extra) => ({
|
|
1904
1918
|
attempt, step: 'drafting', class: 'hitl', verdict: 'hitl', at: r.at ?? null, setup: true, blocked: false, action: 'human', tokensDisplay: { kind: 'no-model' }, ...extra,
|
|
@@ -1934,6 +1948,7 @@ export function getDraftBlock(flowDir, runDir) {
|
|
|
1934
1948
|
else if (r.kind === 'revise') happened.push(r.verdict === 'red' ? 'revise red' : `revising${retry(r)}`);
|
|
1935
1949
|
else if (r.kind === 'redraft') happened.push(r.verdict === 'red' ? 'redraft red' : `redrafting with your answers${retry(r)}`);
|
|
1936
1950
|
else if (r.kind === 'human') happened.push('your answer');
|
|
1951
|
+
else if (r.kind === 'rowedit') happened.push(r.op === 'drop' ? 'you dropped a check' : 'you added a check');
|
|
1937
1952
|
else if (r.kind === 'sign') happened.push(`signed (${r.signedBy ?? 'you'})`);
|
|
1938
1953
|
if (r.kind === 'card') {
|
|
1939
1954
|
const c = r.card && typeof r.card === 'object' ? r.card : {};
|
|
@@ -1942,7 +1957,9 @@ export function getDraftBlock(flowDir, runDir) {
|
|
|
1942
1957
|
rows.push(human(r, n, { action: 'card (you)', gap }));
|
|
1943
1958
|
} else if (r.kind === 'note') rows.push(human(r, n, { action: 'note (you)', gap: String(r.text ?? '') }));
|
|
1944
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:`)
|
|
1945
|
-
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 !== '' ? ` ${
|
|
1960
|
+
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
|
+
// M16 item 5: a Drop or an Add on the card: a human row, $0, no model
|
|
1962
|
+
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 ?? '') }));
|
|
1946
1963
|
else if (r.kind === 'draft') { rows.push(model(r, n, 'draft')); rows.push(...tryRows(r, n)); }
|
|
1947
1964
|
else if (r.kind === 'change') { rows.push(model(r, n, `change ${r.n}`)); rows.push(...tryRows(r, n)); }
|
|
1948
1965
|
else if (r.kind === 'startover') { rows.push(model(r, n, 'start over')); rows.push(...tryRows(r, n)); }
|
|
@@ -2018,7 +2035,7 @@ function attachFolds(groups, runDir, flowDir, { root, flow, catalogue }) {
|
|
|
2018
2035
|
* shared-sidecar contamination risk here the way bareloop's gate-audit
|
|
2019
2036
|
* sidecar had). `null` when the flow/runId doesn't resolve (404).
|
|
2020
2037
|
* @param {{root: string, flow: string, runId: string, scheduleRead?: (flow: string) => any, home?: string, catalogue?: any, resumeAttempt?: (flow: string, runId: string) => any, startingRun?: (flow: string, runId: string) => boolean, now?: () => number}} opts
|
|
2021
|
-
* @returns {{flow:string, runId:string, rows:any[], groups:any[], draft:ReturnType<typeof getDraftBlock>, learnings: any[], needsLeft: string|null, schedule: ReturnType<typeof scheduleAuditWords>, empty:boolean, why:string|null}|null}
|
|
2038
|
+
* @returns {{flow:string, runId:string, rows:any[], groups:any[], draft:ReturnType<typeof getDraftBlock>, auditChecks: ReturnType<typeof auditChecksOf>, learnings: any[], needsLeft: string|null, schedule: ReturnType<typeof scheduleAuditWords>, empty:boolean, why:string|null}|null}
|
|
2022
2039
|
*/
|
|
2023
2040
|
export function getRunAudit({
|
|
2024
2041
|
root, flow, runId, scheduleRead, home, catalogue, resumeAttempt, startingRun, now = Date.now,
|
|
@@ -2046,6 +2063,15 @@ export function getRunAudit({
|
|
|
2046
2063
|
// never a second, client-side re-grouping.
|
|
2047
2064
|
groups,
|
|
2048
2065
|
draft: getDraftBlock(run.flowDir, run.runDir),
|
|
2066
|
+
// M16 item 5 (hamr ruling A, 2026-11-13): the card's own sections - Checks, Not checked, Always checked - each row with its tag and, after the run, its recorded result; null for a plan with no list
|
|
2067
|
+
auditChecks: (() => {
|
|
2068
|
+
if (!catalogue) return null;
|
|
2069
|
+
const job = readRunJob({ root, name: flow, catalogue, runDir: run.runDir }).read;
|
|
2070
|
+
if (!job.ok) return null;
|
|
2071
|
+
const setup = readSetup(run.flowDir);
|
|
2072
|
+
const sign = setup.present ? setup.rows.findLast((/** @type {any} */ r) => r.kind === 'sign') : undefined;
|
|
2073
|
+
return auditChecksOf(job.declaration, readChecks(run.runDir), sign?.notChecked ?? null, { lines: job.lines, csvRoles: csvRolesOf(job.arbiter) });
|
|
2074
|
+
})(),
|
|
2049
2075
|
// M8 item 6: what the planner was told from earlier runs, READ-ONLY (borrowed-from: bareloop src/panel/server.js@v0.46.0:1854): the exact block as the run's record kept it, `hints` = the same text split
|
|
2050
2076
|
// into fields by learn.js's parseHintBlock (the one reader). Empty (no box) when the run was handed nothing: no record, or a run that reused its plan.
|
|
2051
2077
|
learnings: (() => { const rec = readLearningsRecord(run.runDir); return rec === null ? [] : [{ phase: rec.phase, text: rec.text, chars: rec.text.length, ids: rec.ids, hints: parseHintBlock(rec.text) }]; })(),
|
|
@@ -2082,16 +2108,19 @@ export function getRunAudit({
|
|
|
2082
2108
|
*/
|
|
2083
2109
|
function buildJobPlan(declaration, asks, flowDir, flowHash = null, jobLines = /** @type {any[]|undefined} */ (undefined), csvRoles = /** @type {string[]} */ ([])) {
|
|
2084
2110
|
const lines = checkedLines(declaration, { askLines: asks.map((x) => x.line), lines: jobLines, csvRoles });
|
|
2111
|
+
const onList = listLinesOf(declaration); // M16 P4c: a step on a list line carries its check rows apart (the page draws them under the job line, as bareloop's Job tab does)
|
|
2085
2112
|
const declSteps = Array.isArray(declaration?.steps) ? declaration.steps : [];
|
|
2086
2113
|
const steps = declSteps.map((st, i) => {
|
|
2087
2114
|
const ak = asks.find((x) => x.line === st.fromLine);
|
|
2115
|
+
const listRows = onList.has(st.fromLine) ? listPartRows(declaration, st).map((r) => ({ text: r.text, by: r.by })) : null;
|
|
2088
2116
|
return {
|
|
2089
2117
|
step: i + 1,
|
|
2090
2118
|
line: Number.isInteger(st.fromLine) ? st.fromLine : null,
|
|
2091
2119
|
reads: Array.isArray(st.reads) ? st.reads : [],
|
|
2092
2120
|
makes: typeof st.emits === 'string' ? st.emits : null,
|
|
2093
2121
|
mayDo: Array.isArray(st.primitives) ? st.primitives : [],
|
|
2094
|
-
check: lines[i].sentences,
|
|
2122
|
+
check: listRows ? lines[i].sentences.slice(0, lines[i].sentences.length - listRows.length) : lines[i].sentences,
|
|
2123
|
+
...(listRows ? { listRows } : {}),
|
|
2095
2124
|
checkClass: lines[i].class,
|
|
2096
2125
|
sheet: lines[i].sheet ?? null,
|
|
2097
2126
|
ask: !!ak,
|
|
@@ -2107,7 +2136,10 @@ function buildJobPlan(declaration, asks, flowDir, flowHash = null, jobLines = /*
|
|
|
2107
2136
|
const nc = ofThisJob ? signRow?.notChecked : undefined;
|
|
2108
2137
|
const recorded = !!nc && Array.isArray(nc.items);
|
|
2109
2138
|
const view = recorded ? notCheckedView(nc.items, declaration) : { items: [], readNotes: [] };
|
|
2110
|
-
return {
|
|
2139
|
+
return {
|
|
2140
|
+
steps, notChecked: { label: notCheckedLabelOf(declaration), items: view.items, readNotes: view.readNotes, recorded, ...(onList.size > 0 && nc?.by && typeof nc.by === 'object' ? { by: nc.by } : {}) },
|
|
2141
|
+
...(onList.size > 0 ? { always: [...EVERY_STEP_TEXTS] } : {}),
|
|
2142
|
+
};
|
|
2111
2143
|
}
|
|
2112
2144
|
|
|
2113
2145
|
/**
|
|
@@ -2343,8 +2375,8 @@ export function getJobGrid({
|
|
|
2343
2375
|
reason: g.glyph === '[–]' ? g.label.replace(/^skipped — ?/, '') || null : null,
|
|
2344
2376
|
});
|
|
2345
2377
|
}
|
|
2346
|
-
const sched =
|
|
2347
|
-
const from = sched &&
|
|
2378
|
+
const sched = newTicketScheduleOf(flowDir);
|
|
2379
|
+
const from = sched && typeof sched.from === 'string' ? sched.from : null;
|
|
2348
2380
|
const list = from !== null && ticketScheduleOf(flowDir, from) !== null ? getTicketList({
|
|
2349
2381
|
root, flow, runId: from, catalogue,
|
|
2350
2382
|
}) : null;
|