fwdloop 0.37.0 → 0.39.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 +5 -19
- package/bin/fwdloop +51 -29
- package/package.json +1 -1
- package/src/ask.js +70 -148
- package/src/audit-fold.js +5 -4
- package/src/auditchecks.js +6 -4
- package/src/authoring.js +36 -64
- package/src/blockasks.js +2 -1
- package/src/blockassemble.js +7 -9
- package/src/blockdraft.js +2 -2
- package/src/blockpick.js +5 -5
- package/src/books.js +217 -12
- package/src/checkblock.js +25 -55
- package/src/checked.js +2 -3
- package/src/checklistsign.js +26 -5
- package/src/checklook.js +3 -1
- package/src/checkpick.js +5 -76
- package/src/cited-source.js +4 -4
- package/src/citedcheck.js +6 -11
- package/src/citedwords.js +9 -8
- package/src/closers.js +9 -6
- package/src/declaration.js +22 -55
- package/src/diary.js +23 -1
- package/src/draft-steps.js +11 -1
- package/src/drafter.js +28 -23
- package/src/draftfiles.js +127 -0
- package/src/draftspend.js +165 -17
- package/src/flow.js +42 -87
- package/src/flowmodel.js +1 -1
- package/src/index.js +3 -2
- package/src/inside.js +86 -0
- package/src/isrec.js +2 -0
- package/src/jsonl-append.js +33 -1
- package/src/learn.js +1 -1
- package/src/learnstore.js +20 -22
- package/src/line-checks.js +2 -3
- package/src/liveness.js +3 -0
- package/src/mcp-use.js +8 -9
- package/src/memo.js +13 -16
- package/src/minrule.js +16 -0
- package/src/model-step.js +3 -3
- package/src/page-words.js +8 -0
- package/src/pageask.js +8 -3
- package/src/pagebits.js +8 -1
- package/src/pagedropwords.js +1 -1
- package/src/pagerules.js +6 -3
- package/src/panel/author.js +121 -78
- package/src/panel/authorcard.js +21 -8
- package/src/panel/authorflows.js +3 -3
- package/src/panel/authorresume.js +3 -3
- package/src/panel/authorstart.js +15 -16
- package/src/panel/authortrigger.js +43 -70
- package/src/panel/data.js +125 -168
- package/src/panel/index.html +154 -63
- package/src/panel/jobgrid.js +3 -7
- package/src/panel/result.js +7 -10
- package/src/panel/resume.js +4 -3
- package/src/panel/scheduler.js +9 -9
- package/src/panel/server.js +8 -4
- package/src/panel/spawn.js +22 -11
- package/src/panel/tickets.js +2 -2
- package/src/pickrecord.js +51 -31
- package/src/placerule.js +3 -4
- package/src/planrebuild.js +19 -19
- package/src/primitives.js +1 -1
- package/src/provider.js +1 -1
- package/src/reasons.js +25 -0
- package/src/report.js +2 -1
- package/src/runfile.js +26 -2
- package/src/runner.js +57 -105
- package/src/runvalues.js +47 -24
- package/src/schedule-choices.js +41 -0
- package/src/schedule-shape.js +39 -0
- package/src/schedule.js +9 -8
- package/src/setup.js +20 -36
- package/src/shaperows.js +2 -2
- package/src/sheet-record.js +1 -2
- package/src/sheetblock.js +3 -4
- package/src/sheetbuild.js +5 -5
- package/src/sheetchecks.js +1 -2
- package/src/sheetclaims.js +1 -2
- package/src/sheetoffer.js +1 -1
- package/src/sheetrun.js +5 -7
- package/src/summary-words.js +2 -1
- package/src/thinking.js +5 -2
- package/src/ticketrows.js +8 -30
- package/src/trigger-clock.js +9 -23
- package/src/trigger-files.js +30 -22
- package/src/trigger-tickets.js +15 -14
- package/src/try-checks.js +2 -1
- package/src/types.js +2 -0
- package/types/ask.d.ts +25 -20
- package/types/authoring.d.ts +8 -42
- package/types/blockassemble.d.ts +0 -1
- package/types/blockpick.d.ts +1 -1
- package/types/books.d.ts +256 -4
- package/types/checkblock.d.ts +2 -25
- package/types/checklist.d.ts +3 -3
- package/types/checklistsign.d.ts +7 -0
- package/types/checkpick.d.ts +0 -21
- package/types/citedwords.d.ts +7 -4
- package/types/closers.d.ts +1 -0
- package/types/declaration.d.ts +4 -14
- package/types/diary.d.ts +14 -1
- package/types/draft-steps.d.ts +7 -0
- package/types/drafter.d.ts +3 -2
- package/types/draftfiles.d.ts +89 -0
- package/types/draftspend.d.ts +74 -0
- package/types/flow.d.ts +32 -54
- package/types/index.d.ts +3 -3
- package/types/inside.d.ts +58 -0
- package/types/isrec.d.ts +1 -0
- package/types/jsonl-append.d.ts +20 -0
- package/types/learnstore.d.ts +0 -2
- package/types/liveness.d.ts +1 -0
- package/types/minrule.d.ts +6 -0
- package/types/page-words.d.ts +6 -0
- package/types/pageask.d.ts +2 -0
- package/types/pagebits.d.ts +3 -0
- package/types/pagerules.d.ts +1 -0
- package/types/panel/author.d.ts +7 -3
- package/types/panel/authorcard.d.ts +0 -6
- package/types/panel/authorflows.d.ts +4 -4
- package/types/panel/authortrigger.d.ts +16 -2
- package/types/panel/data.d.ts +36 -11
- package/types/panel/spawn.d.ts +18 -2
- package/types/pickrecord.d.ts +29 -0
- package/types/reasons.d.ts +23 -0
- package/types/runfile.d.ts +14 -0
- package/types/runner.d.ts +6 -38
- package/types/runvalues.d.ts +17 -2
- package/types/schedule-choices.d.ts +9 -0
- package/types/schedule-shape.d.ts +15 -0
- package/types/sheetbuild.d.ts +1 -1
- package/types/sheetclaims.d.ts +0 -1
- package/types/thinking.d.ts +1 -0
- package/types/ticketrows.d.ts +0 -9
- package/types/trigger-clock.d.ts +3 -2
- package/types/trigger-files.d.ts +15 -4
- package/types/types.d.ts +8 -0
package/src/auditchecks.js
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
// What a run recorded for a check is read off its diary (`checks` rows: each check numbered with its `ok`, and for a list line its `part`); nothing is re-derived. What this throws away: the checks of a line off the list
|
|
5
5
|
// (the sheet and the older plans keep their own Audit rows), and the per-try history (the LAST try of a step is the one that closed it).
|
|
6
6
|
import { listLinesOf } from './checklistsign.js';
|
|
7
|
+
import { tagOf } from './checkwords.js';
|
|
8
|
+
import { newestChecksOf } from './diary.js';
|
|
7
9
|
import { listPartRows, notCheckedView } from './checked.js';
|
|
8
10
|
import { EVERY_STEP, EVERY_STEP_TEXTS } from './try-checks.js';
|
|
9
11
|
import { sheetRowsOf } from './sheetrows.js';
|
|
@@ -25,7 +27,7 @@ export function auditChecksOf(declaration, diary, notChecked, { lines: jobLines
|
|
|
25
27
|
const sheetRows = sheetOn ? sheetRowsOf({ declaration, lines: jobLines, csvRoles }) : null;
|
|
26
28
|
if (lines.size === 0 && !(sheetRows && sheetRows.card.length > 0)) return null;
|
|
27
29
|
const steps = (Array.isArray(declaration?.steps) ? declaration.steps : []).filter((/** @type {any} */ st) => lines.has(st?.fromLine));
|
|
28
|
-
const lastTry = (/** @type {any} */ st) => (Array.isArray(diary) ? diary : []
|
|
30
|
+
const lastTry = (/** @type {any} */ st) => newestChecksOf(Array.isArray(diary) ? diary : [], st.emits ?? st.goal ?? null) ?? undefined;
|
|
29
31
|
/** @type {AuditCheckRow[]} */
|
|
30
32
|
const checks = [];
|
|
31
33
|
// the same rows by the job line that owns them, their words without the `line N · ` prefix (S7: one block per line)
|
|
@@ -62,13 +64,13 @@ export function auditChecksOf(declaration, diary, notChecked, { lines: jobLines
|
|
|
62
64
|
// M17 am4 (C3): the Audit splits a reading note from Not checked as the card and the Job tab do (src/checked.js notCheckedView)
|
|
63
65
|
const view = notCheckedView(notChecked?.items ?? [], declaration);
|
|
64
66
|
/** @type {AuditCheckRow[]} */
|
|
65
|
-
const notRows = view.items.map((t) => ({ ...splitNotChecked(t), by: by[t]
|
|
67
|
+
const notRows = view.items.map((t) => ({ ...splitNotChecked(t), by: tagOf(by[t]) !== '' ? /** @type {'you'|'agent'|'default'} */ (by[t]) : null, result: 'not-checked' }));
|
|
66
68
|
// the two checks every step has (src/try-checks.js #1 and #2): passed when every step that ran them passed, failed when one did not
|
|
67
69
|
const every = (/** @type {string} */ text) => {
|
|
68
|
-
const seen = (Array.isArray(diary) ? diary : []).flatMap((d) => (d.checks
|
|
70
|
+
const seen = (Array.isArray(diary) ? diary : []).flatMap((d) => (Array.isArray(d.checks) ? d.checks : []).filter((/** @type {any} */ c) => c.source === EVERY_STEP && c.text === text));
|
|
69
71
|
return seen.length === 0 ? 'none' : seen.every((/** @type {any} */ c) => c.ok) ? 'passed' : 'failed';
|
|
70
72
|
};
|
|
71
|
-
const everyWhy = (/** @type {string} */ text) => whyOf((Array.isArray(diary) ? diary : []).flatMap((d) => (d.checks
|
|
73
|
+
const everyWhy = (/** @type {string} */ text) => whyOf((Array.isArray(diary) ? diary : []).flatMap((d) => (Array.isArray(d.checks) ? d.checks : []).filter((/** @type {any} */ c) => c.source === EVERY_STEP && c.text === text)).find((/** @type {any} */ c) => !c.ok));
|
|
72
74
|
/** @type {AuditCheckRow[]} */
|
|
73
75
|
const always = EVERY_STEP_TEXTS.map((text) => ({ text, kind: 'file', by: /** @type {'default'} */ ('default'), result: every(text), ...everyWhy(text) }));
|
|
74
76
|
// M19 S7: one block per job line (its checks, its Not checked rows) and the Not checked rows no line owns; the two every-step rows are the page's "Every line" block (a one-line job's Line 1 block)
|
package/src/authoring.js
CHANGED
|
@@ -31,7 +31,8 @@ import { sheetLineBlocks } from './sheetblock.js';
|
|
|
31
31
|
import { loadCatalogue } from './catalogue.js';
|
|
32
32
|
import { WIRED_VERBS } from './primitives.js';
|
|
33
33
|
import { canonicalBytes } from './signature.js';
|
|
34
|
-
import { writeFlow, writeRunPlan, readFlow,
|
|
34
|
+
import { writeFlow, writeRunPlan, readFlow, readJsonFile, checkFlowName, readDraftLog } from './flow.js';
|
|
35
|
+
import { readFileInside, readdirInside } from './inside.js';
|
|
35
36
|
import { jobKeyOfSigned } from './jobkey.js';
|
|
36
37
|
import { checkSendDestination } from './runner.js';
|
|
37
38
|
import { checkKeyPreflight, appendSpendRow } from './provider.js';
|
|
@@ -40,28 +41,25 @@ import { readModelRecord, writeModelRecord, writeLearningsRecord, writeLearnings
|
|
|
40
41
|
import { configDoorHome } from './config.js';
|
|
41
42
|
import { hintsForRun, placeSpecOf } from './learnstore.js';
|
|
42
43
|
import { redactSecrets } from './redact.js';
|
|
43
|
-
import { sessionPriorSpend, writeDraftSpend } from './draftspend.js';
|
|
44
|
+
import { makeStepWriter, sessionPriorSpend, writeDraftSpend } from './draftspend.js';
|
|
44
45
|
import { writeSetup } from './setup.js';
|
|
45
|
-
import { RECORD_FILE } from './pickrecord.js';
|
|
46
|
+
import { RECORD_FILE, readKept, readRowChoices, recordPath, addedCountsOf } from './pickrecord.js';
|
|
46
47
|
import { planMatchesCard, numbersWords } from './checkrows.js';
|
|
47
48
|
import { csvRolesOf } from './sheetblock.js';
|
|
48
49
|
import { mcpPickHere } from './mcp-pick.js';
|
|
49
50
|
import { hitlWords, notCheckedView } from './checked.js';
|
|
51
|
+
import {
|
|
52
|
+
SPEC_HASH_FILE, LEAK_MARKER_FILE, draftVerdict, QUESTIONS_FILE, ANSWER_FILE, NOT_CHECKED_FILE, readNotCheckedFile, readQuestions, scrub, readCard, cardFileName, readRedraftMarker, redraftFileName, readPlanTexts,
|
|
53
|
+
} from './draftfiles.js';
|
|
50
54
|
|
|
51
|
-
export const SPEC_HASH_FILE = 'spec.hash';
|
|
52
55
|
/** The one folder under the flows root where the panel keeps its draft folders (M4e). Starts with a dot, so it is never a flow name. */
|
|
53
56
|
export const PANEL_DRAFTS_DIR = '.drafts';
|
|
54
|
-
/** Written when the end sweep finds a key in the draft dir; sign refuses a dir that has it. */
|
|
55
|
-
export const LEAK_MARKER_FILE = 'scrub-leak.red';
|
|
56
57
|
/** M4e amendments 24/25: the drafter's questions (written once by `fwdloop draft`), each human answer (`answer-<k>.json`, written once by the panel),
|
|
57
58
|
* and the drafter's own "not checked" reading (information only; never in the readout, so never in the hash). */
|
|
58
|
-
export const QUESTIONS_FILE = 'questions.json';
|
|
59
|
-
export const NOT_CHECKED_FILE = 'not-checked.json';
|
|
60
59
|
/** M10: the drafting copy of each web page input is kept in this folder of the draft folder (a run freezes its own, never this one). */
|
|
61
60
|
export const PAGES_DIR = 'pages';
|
|
62
61
|
/** M10 item 3: what the page-word look kept and dropped, per page input (the map the AI named, the kept facts with their readings, every drop). Not signed. */
|
|
63
62
|
export const PAGE_LOOK_FILE = 'page-look.json';
|
|
64
|
-
export const ANSWER_FILE = (k) => `answer-${k}.json`;
|
|
65
63
|
export const SIGN_LINE = (dir, hash) => `DRAFTED — NOT SIGNED. To sign: fwdloop sign ${dir} --approve ${hash}`;
|
|
66
64
|
|
|
67
65
|
const sha = (bytes) => createHash('sha256').update(bytes).digest('hex');
|
|
@@ -91,42 +89,13 @@ export function specHash({
|
|
|
91
89
|
}
|
|
92
90
|
|
|
93
91
|
/**
|
|
94
|
-
* The
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
* @param {string} planDir
|
|
98
|
-
* A question the page look raised (M10 piece 3) also carries `source: 'look'`, `ask` ('reading' | 'cant-check'), `ruleNo`, `ruleText` and `proposal`; an answer file carries `at`.
|
|
99
|
-
* @returns {{ questions: {k:number, line:number, question:string, answer:string|null, at?:string, rule?:string|null, choice?:'agree'|'drop'|'rule'|'column', source?:string, ask?:string, ruleNo?:number, ruleText?:string, proposal?:string|null, check?:Record<string, any>, pairRule?:number, columns?:string[], readings?:Record<string,string>}[], open: {k:number, line:number, question:string, answer:null}[] }}
|
|
92
|
+
* The flow name a draft will sign as: the `name` in `target.json` of a plan folder (`planDir`, read through the safe gateway). A string that is not empty,
|
|
93
|
+
* else null (no file, not JSON, not an object, no name, a name that is empty or not a string).
|
|
94
|
+
* @param {string} planDir @returns {string|null}
|
|
100
95
|
*/
|
|
101
|
-
export function
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
if (!f.ok) return none;
|
|
105
|
-
let list;
|
|
106
|
-
try { list = JSON.parse(f.text)?.questions; } catch { return none; }
|
|
107
|
-
if (!Array.isArray(list)) return none;
|
|
108
|
-
const questions = list.map((q, i) => {
|
|
109
|
-
const k = i + 1;
|
|
110
|
-
const a = readFileInside(planDir, ANSWER_FILE(k));
|
|
111
|
-
let answer = null;
|
|
112
|
-
let at;
|
|
113
|
-
/** @type {string|null|undefined} the `~` rule the answer added (null = it left the rule Not checked), as the answer file recorded it */
|
|
114
|
-
let rule;
|
|
115
|
-
/** @type {'agree'|'drop'|'rule'|'column'|undefined} M10 am29: which one the answer used (`agree`, `drop` or `rule`), when the file records it */
|
|
116
|
-
let choice;
|
|
117
|
-
if (a.ok) {
|
|
118
|
-
try {
|
|
119
|
-
const j = JSON.parse(a.text);
|
|
120
|
-
const t = j?.answer;
|
|
121
|
-
if (typeof t === 'string' && t.trim() !== '') { answer = t; if (typeof j.at === 'string') at = j.at; if (j.rule === null || typeof j.rule === 'string') rule = j.rule; if (j.choice === 'agree' || j.choice === 'drop' || j.choice === 'rule' || j.choice === 'column') choice = j.choice; }
|
|
122
|
-
} catch { /* unreadable = unanswered */ }
|
|
123
|
-
}
|
|
124
|
-
return {
|
|
125
|
-
k, line: q.line, question: String(q.question), answer, ...(at === undefined ? {} : { at }), ...(rule === undefined ? {} : { rule }), ...(choice === undefined ? {} : { choice }),
|
|
126
|
-
...(q.source === 'look' ? { source: 'look', ask: q.ask, ruleNo: q.ruleNo, ruleText: q.ruleText, proposal: typeof q.proposal === 'string' ? q.proposal : null, ...(q.check && typeof q.check === 'object' ? { check: q.check } : {}), ...(Number.isInteger(q.pairRule) ? { pairRule: q.pairRule } : {}), ...(Array.isArray(q.columns) && q.columns.length > 0 && q.readings && typeof q.readings === 'object' ? { columns: q.columns.map(String), readings: q.readings } : {}) } : {}),
|
|
127
|
-
};
|
|
128
|
-
});
|
|
129
|
-
return { questions, open: /** @type {any} */ (questions.filter((q) => q.answer === null)) };
|
|
96
|
+
export function readTargetName(planDir) {
|
|
97
|
+
const name = readJsonFile(planDir, 'target.json')?.name;
|
|
98
|
+
return typeof name === 'string' && name !== '' ? name : null;
|
|
130
99
|
}
|
|
131
100
|
|
|
132
101
|
export const OPEN_QUESTION_SAY = 'A question the plan raised is still open. Answer it in the panel (fwdloop panel), then sign the plan it drafts after your answers. Nothing was signed.';
|
|
@@ -139,13 +108,6 @@ export function questionsRefusal(planDir) {
|
|
|
139
108
|
return q.open.length > 0 ? OPEN_QUESTION_SAY : ANSWERED_QUESTION_SAY;
|
|
140
109
|
}
|
|
141
110
|
|
|
142
|
-
/** Literal (never RegExp) key scrub; a secret under 8 chars is skipped so it can't blank ordinary text. */
|
|
143
|
-
export function scrub(text, secrets) {
|
|
144
|
-
let out = text;
|
|
145
|
-
for (const s of secrets) if (typeof s === 'string' && s.length >= 8) out = out.split(s).join('[redacted-key]');
|
|
146
|
-
return out;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
111
|
/** Count files directly inside `dir` that contain a secret literally. */
|
|
150
112
|
export function sweepForSecrets(dir, secrets) {
|
|
151
113
|
const live = secrets.filter((s) => typeof s === 'string' && s.length >= 8);
|
|
@@ -385,14 +347,14 @@ export function writePlanFiles(dir, files, opts = {}) {
|
|
|
385
347
|
* `onResult({ ok })` (M4d am32): called once, after the spend is booked and just before the result files are written (the CLI gives its monthly hold back there).
|
|
386
348
|
*/
|
|
387
349
|
export async function draftToDir({
|
|
388
|
-
proseFile, dir, root, name, slot, model, draftThinking = /** @type {'on'|'off'} */ ('off'), keyNames, env = process.env, provider, rates, modelId, noQuestions = false, onResult, fetchPage, leftRules, columnAnswers, carriedColumns, checkPicks, carriedPicks, carriedChoices, carriedSheetDropped, carriedShapeDropped, proseRead,
|
|
350
|
+
proseFile, dir, root, name, slot, model, draftThinking = /** @type {'on'|'off'} */ ('off'), keyNames, env = process.env, provider, rates, modelId, noQuestions = false, onResult, onStepLine, fetchPage, leftRules, columnAnswers, carriedColumns, checkPicks, carriedPicks, carriedChoices, carriedSheetDropped, carriedShapeDropped, proseRead,
|
|
389
351
|
flowType = /** @type {'plain'|'mcp'|'tickets'} */ ('plain'), mcpServer = /** @type {string|undefined} */ (undefined), mcpPick = /** @type {any} */ (undefined), mcpServers = /** @type {string[]|undefined} */ (undefined),
|
|
390
352
|
// M13 am11: what the card's tentative send line is (see draft()); null = the prose file is the truth
|
|
391
353
|
actionMode = /** @type {null|'check'|'known'} */ (null),
|
|
392
354
|
}) {
|
|
393
|
-
const refuse = (reds) => ({ ok: false, wrote: false, reds, costUsd: 0 });
|
|
355
|
+
const refuse = (reds, box = /** @type {string|null} */ (null)) => ({ ok: false, wrote: false, reds, costUsd: 0, box });
|
|
394
356
|
const nameCheck = checkFlowName(name);
|
|
395
|
-
if (!nameCheck.ok) return refuse([nameCheck.red]);
|
|
357
|
+
if (!nameCheck.ok) return refuse([nameCheck.red], 'flowName');
|
|
396
358
|
if (typeof root !== 'string' || root === '') return refuse(['draft: --root <flows dir> is required']);
|
|
397
359
|
// An unsigned draft folder inside the flows root would list as a flow in the panel and Inbox (checked by realpath, at use time).
|
|
398
360
|
const realRoot = realpathOfNew(root);
|
|
@@ -410,7 +372,7 @@ export async function draftToDir({
|
|
|
410
372
|
const injected = provider != null;
|
|
411
373
|
if (!injected) {
|
|
412
374
|
const refusal = draftKeyRefusal(slot, env);
|
|
413
|
-
if (refusal !== null) return refuse([refusal]);
|
|
375
|
+
if (refusal !== null) return refuse([refusal], 'model');
|
|
414
376
|
}
|
|
415
377
|
const secrets = keyValues(env, [...new Set([...(keyNames ?? []), ...(typeof slot === 'string' ? [slot] : [])])]);
|
|
416
378
|
if (secrets.some((s) => s.length >= 8 && prose.text.includes(s))) return refuse(['prose: contains an API key value — refused']);
|
|
@@ -428,9 +390,14 @@ export async function draftToDir({
|
|
|
428
390
|
// Spend is booked per call into `<dir>/draft-spend.json` (src/draftspend.js), so a draft stopped between rounds
|
|
429
391
|
// keeps what it paid. The first write is the mark that a call is in flight: if that cannot be written, the call is not made.
|
|
430
392
|
let startedAt = null;
|
|
393
|
+
// M20 am1 item 5 (+ am2): the step lines, written by the CLI's `onStepLine` into the draft's existing child.log; none when nothing listens
|
|
394
|
+
const stepWriter = typeof onStepLine === 'function' ? makeStepWriter(onStepLine) : null;
|
|
431
395
|
const onBook = ({
|
|
432
|
-
inFlight, calls, unmetered, metered, modelId: usedModel, price,
|
|
396
|
+
inFlight, calls, unmetered, metered, modelId: usedModel, price, partial,
|
|
433
397
|
}) => {
|
|
398
|
+
if (stepWriter !== null && typeof partial === 'function') {
|
|
399
|
+
try { stepWriter(partial(), null, false); } catch { /* progress only: a failed line never fails the draft */ }
|
|
400
|
+
}
|
|
434
401
|
const now = new Date().toISOString();
|
|
435
402
|
startedAt ??= now;
|
|
436
403
|
try {
|
|
@@ -478,7 +445,7 @@ export async function draftToDir({
|
|
|
478
445
|
});
|
|
479
446
|
if (result.stop === 'pre-flight') {
|
|
480
447
|
try { rmdirSync(dir); } catch { /* the claimed dir is still empty; leave it rather than mask the refusal */ }
|
|
481
|
-
return refuse(cleanReds(result.reds));
|
|
448
|
+
return refuse(cleanReds(result.reds), result.box ?? null);
|
|
482
449
|
}
|
|
483
450
|
// M8 item 5a: what was handed is kept once beside the draft (only when a round was actually sent with it); a failure is recorded, never raised.
|
|
484
451
|
try {
|
|
@@ -522,6 +489,10 @@ export async function draftToDir({
|
|
|
522
489
|
// M13 am11: the job's action (the last line the AI named, or the person agreed or typed), or null: the plan card's row `› line <n> writes everything before it`
|
|
523
490
|
action: result.action ?? null,
|
|
524
491
|
}), secrets);
|
|
492
|
+
// M20 am1 item 5: the last step lines (every step ended, final labels) are written before the result files, so a draft the panel sees finished already has them
|
|
493
|
+
if (stepWriter !== null) {
|
|
494
|
+
try { stepWriter(JSON.parse(files['log.json']), result.declaration ?? null, true); } catch { /* progress only */ }
|
|
495
|
+
}
|
|
525
496
|
let hash = null;
|
|
526
497
|
if (result.ok) {
|
|
527
498
|
const declarationText = scrub(dj(result.declaration), secrets);
|
|
@@ -595,7 +566,8 @@ export function signDraft({
|
|
|
595
566
|
dir, approve, signedBy, signedAt = new Date().toISOString(), env = process.env, keyNames, sessionDir, replaces, asRunOf,
|
|
596
567
|
}) {
|
|
597
568
|
const refuse = (...reds) => ({ ok: false, reds });
|
|
598
|
-
|
|
569
|
+
const dv = draftVerdict(dir);
|
|
570
|
+
if (dv.leak.ok) return refuse(`sign: "${dir}" carries a key-leak marker (${LEAK_MARKER_FILE}) — never signed`);
|
|
599
571
|
const openQuestion = questionsRefusal(dir);
|
|
600
572
|
if (openQuestion !== null) return refuse(`sign: ${openQuestion}`);
|
|
601
573
|
// Sign is $0 and takes no key, so it can only sweep for the keys it is told of (`keyNames`, the rows set up in Settings).
|
|
@@ -606,7 +578,7 @@ export function signDraft({
|
|
|
606
578
|
const read = (f) => readFileInside(dir, f);
|
|
607
579
|
const parts = {};
|
|
608
580
|
for (const f of ['prose.txt', 'declaration.json', 'input-facts.json', 'readout.txt', SPEC_HASH_FILE, 'target.json']) {
|
|
609
|
-
const r = read(f);
|
|
581
|
+
const r = f === SPEC_HASH_FILE ? dv.hashFile : read(f);
|
|
610
582
|
if (!r.ok) return refuse(`sign: "${dir}" is not a green draft — ${f} ${r.missing ? 'is missing' : `is refused (${r.red})`}`);
|
|
611
583
|
parts[f] = r.text;
|
|
612
584
|
}
|
|
@@ -633,18 +605,18 @@ export function signDraft({
|
|
|
633
605
|
if (!cat.ok) return refuse(`sign: catalogue: ${cat.reds.join('; ')}`);
|
|
634
606
|
const verdict = validateDeclaration(declaration, {
|
|
635
607
|
arbiter: signed.arbiter, lines: signed.lines, catalogue: cat.primitives, wired: WIRED_VERBS, verbatimGoals: true, fitJobLine: true,
|
|
608
|
+
addedCounts: addedCountsOf(readRowChoices(recordPath(dir)), signed.lines),
|
|
636
609
|
});
|
|
637
610
|
if (!verdict.ok) return { ok: false, reds: verdict.reds };
|
|
638
611
|
// M19 am6 item 3 (bareloop `planMatchesClose`): the card a draft saved must equal the checks the signed plan runs, line by line; a difference refuses the sign at $0, naming the line.
|
|
639
612
|
// Only a card saved with its own Not checked list (this build) is compared; an older saved card is drawn from the plan and not held to it.
|
|
640
613
|
const cardReds = (() => {
|
|
641
614
|
if (!Array.isArray(declaration.checkList)) return [];
|
|
642
|
-
const
|
|
643
|
-
const
|
|
644
|
-
|
|
645
|
-
try { log = lg.ok ? JSON.parse(lg.text) : null; record = rec.ok ? JSON.parse(rec.text) : null; } catch { return []; }
|
|
615
|
+
const keptRead = readKept(dir);
|
|
616
|
+
const log = readDraftLog(dir);
|
|
617
|
+
if (keptRead.torn) return []; // an unreadable record: the check skips
|
|
646
618
|
if (!log?.checkCard || !Array.isArray(log.checkCard.notChecked)) return [];
|
|
647
|
-
const kept =
|
|
619
|
+
const kept = (keptRead.kept ?? []).filter((/** @type {any} */ k) => k && Number.isInteger(k.line));
|
|
648
620
|
return planMatchesCard({ declaration, lines: signed.lines, csvRoles: csvRolesOf(signed.arbiter), kept, log: log.log }, log.checkCard);
|
|
649
621
|
})();
|
|
650
622
|
if (cardReds.length) return { ok: false, reds: cardReds };
|
package/src/blockasks.js
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
// The questions of the check block, as the answer gate reads them (`answerQuestions`, src/questionbox.js): ONE spelling of the question words, written by code from a row that
|
|
4
4
|
// code could not settle (reading | check). The block's `open` list is the source; the person's CHOICE (agree | drop | rule) goes back through `block.applyAnswer`.
|
|
5
5
|
import { readingQuestion } from './pageask.js';
|
|
6
|
-
import { plainWords
|
|
6
|
+
import { plainWords } from './checkpick.js';
|
|
7
|
+
import { HOW_TO_ANSWER } from './pageask.js';
|
|
7
8
|
|
|
8
9
|
/** @typedef {{key: string, rowKey: string, line: number, rule: number, source: 'look', ask: 'reading'|'check', ruleText: string, question: string, counted: boolean, reading?: string, check?: Record<string, any>}} BlockAsk */
|
|
9
10
|
|
package/src/blockassemble.js
CHANGED
|
@@ -18,15 +18,12 @@ export const ASK_LINE_REASON = 'you judge it at the Ask';
|
|
|
18
18
|
*/
|
|
19
19
|
export const SHAPE_ONLY_CLASS = 'green';
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
export { NO_GUARDRAIL_WORDS } from './checkblock.js';
|
|
23
|
-
|
|
24
|
-
import { REASON } from './checkblock.js';
|
|
21
|
+
import { REASON } from './reasons.js';
|
|
25
22
|
import { KEPT_WORDS } from './pickrecord.js';
|
|
23
|
+
import { tagOf } from './checkwords.js';
|
|
26
24
|
import { lineRules } from './pagebits.js';
|
|
27
25
|
import { isListedNotChecked, notCheckedItem, ruleTextOf } from './checkrows.js';
|
|
28
|
-
|
|
29
|
-
const isRec = (/** @type {unknown} */ v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
26
|
+
import { isRec } from './isrec.js';
|
|
30
27
|
|
|
31
28
|
/** a countable part as the picked check the softgreen close runs: its own fields, the rule named `rule` (the inverse of the block's partOfPick) @param {Record<string, any>} part */
|
|
32
29
|
export function pickedOf(part) {
|
|
@@ -67,7 +64,7 @@ export function assembleFromBlock({ declaration, block, lines, lineSet, askLines
|
|
|
67
64
|
}
|
|
68
65
|
if (!isRec(st) || !Number.isInteger(n) || !lineSet.has(n)) return st;
|
|
69
66
|
const parts = partsOf(n);
|
|
70
|
-
//
|
|
67
|
+
// the check block is the one decider of which parts a line holds (src/checkblock.js buildLine), so every part it holds is kept here
|
|
71
68
|
const fact = parts.find((p) => p.class === 'fact');
|
|
72
69
|
// M19 S5: the shape part rides the fact part (facts+shape, class green); a line with no fact part takes it only when a class is ruled for it (`shapeOnlyClass`)
|
|
73
70
|
const picks = parts.filter((p) => p.class === 'countable' && p.check !== 'cited' && p.check !== 'numbersFromFacts');
|
|
@@ -102,7 +99,8 @@ export function assembleFromBlock({ declaration, block, lines, lineSet, askLines
|
|
|
102
99
|
for (const n of lineSet) {
|
|
103
100
|
const mine = steps.find((/** @type {any} */ st) => isRec(st) && st.fromLine === n);
|
|
104
101
|
// the classes of a list line are code's: a line with no guardrail of the person's has no class entry, whatever the AI sent
|
|
105
|
-
|
|
102
|
+
// M19 am15 (F257): a line with no guardrail of the person's has a class only when a check the person Added holds it; else no entry (hitl)
|
|
103
|
+
if (!guarded(n) && (!mine || mine.close.class === 'hitl')) { delete guardrailClasses[String(n)]; continue; }
|
|
106
104
|
if (!mine) continue;
|
|
107
105
|
guardrailClasses[String(n)] = mine.close.class;
|
|
108
106
|
}
|
|
@@ -126,7 +124,7 @@ export function assembleFromBlock({ declaration, block, lines, lineSet, askLines
|
|
|
126
124
|
if (own?.hidden) return null;
|
|
127
125
|
// the reason is the signed row's own `reason` (src/checkblock.js REASON, the one table); M10 am17 (6): `kept` words
|
|
128
126
|
const line = notCheckedItem(r, ruleTextOf(lines, r) ?? own?.text, own ? (own.name ? [own.name] : own.words) : undefined, own?.keptFromLast === true);
|
|
129
|
-
if (r.by
|
|
127
|
+
if (tagOf(r.by) !== '') notCheckedBy[line] = r.by;
|
|
130
128
|
return line;
|
|
131
129
|
}).filter((x) => x !== null);
|
|
132
130
|
for (const l of lines) {
|
package/src/blockdraft.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { redactSecrets } from './redact.js';
|
|
5
5
|
import { newJobBlock } from './blocklines.js';
|
|
6
6
|
import { EDIT_OPS } from './checkblock.js';
|
|
7
|
-
import {
|
|
7
|
+
import { isCountable } from './blockpick.js';
|
|
8
8
|
import { ticketRuleField } from './ticketrows.js';
|
|
9
9
|
|
|
10
10
|
/** the cap of refusals one revise turn carries (bareloop REVISE_RED_CAP) */
|
|
@@ -84,5 +84,5 @@ export const editRecord = (rec) => rec.edits.map((e) => ({ op: e?.op, accepted:
|
|
|
84
84
|
*/
|
|
85
85
|
export function ticketLeaveOut(flowType, jobLines) {
|
|
86
86
|
if (flowType !== 'tickets') return [];
|
|
87
|
-
return jobLines.flatMap((l) => (l.rules ?? []).map((t, i) => ({ line: l.n, rule: i + 1, t })).filter((x) => ticketRuleField(x.t) !== null && !
|
|
87
|
+
return jobLines.flatMap((l) => (l.rules ?? []).map((t, i) => ({ line: l.n, rule: i + 1, t })).filter((x) => ticketRuleField(x.t) !== null && !isCountable(x.t)).map((x) => ({ line: x.line, rule: x.rule })));
|
|
88
88
|
}
|
package/src/blockpick.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// borrowed-from: bareloop src/checkpick.js@v0.57.0 (c18df406)
|
|
2
|
+
// fwd changed (M20 am8 item 2): guardrailItemCount keeps fwd's lookbehind (a number right after $ € £ . , is not an item count), and these readers are the one copy fwd's src/declaration.js re-exports.
|
|
2
3
|
// first ported from: bareloop src/checkpick.js@v0.56.0 (3383cce) (isCountable, keepOrDrop, countCheck, partOfPick, sameRuleWords and what they call; HOW_TO_ANSWER and CANT_CHECK_WORDS are fwd's own, src/checkpick.js, the same words)
|
|
3
|
-
// This file is bareloop's checkpick.js. fwd
|
|
4
|
-
// so they live here under another name and the am16 module is left as it is.
|
|
4
|
+
// This file is bareloop's checkpick.js. fwd's src/checkpick.js (the M10 am16 pick path) calls THESE keepOrDrop and countCheck (M20 am8 item 3: its own two are gone), as does the check block.
|
|
5
5
|
// The pick vocabulary and its keep-or-drop: a suggested check is kept only if its rule is on bareguard's list and offered here, it carries only that rule's own fields, and every
|
|
6
6
|
// number is one the person's rule names.
|
|
7
7
|
import { rubricVocabulary } from 'bareguard';
|
|
@@ -18,7 +18,7 @@ const NUM_FIELDS = ['value', 'size', 'wordsPerSection'];
|
|
|
18
18
|
|
|
19
19
|
const WORD_FIELDS = ['names', 'phrases'];
|
|
20
20
|
|
|
21
|
-
// ---- the guardrail readers (
|
|
21
|
+
// ---- the guardrail readers: THE one copy (M20 am8 item 2; src/declaration.js re-exports them) ------------------------------------------------------------------------------
|
|
22
22
|
const readNumber = (/** @type {string} */ t) => Number(t.replace(/,/g, ''));
|
|
23
23
|
|
|
24
24
|
/** every whole-output word number in a guardrail ("under 600 words" -> [600]); a "<n> words each" / "per section" size is never listed here @param {unknown} g @returns {number[]} */
|
|
@@ -48,9 +48,9 @@ export function guardrailSectionCount(g) {
|
|
|
48
48
|
return /^\d+$/.test(m[1]) ? Number(m[1]) : NUMBER_WORDS[m[1].toLowerCase()];
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
/** the first "<N> bullets / list items / items / lines / points" in a guardrail (digits, or one..ten), or null @param {unknown} g @returns {number|null} */
|
|
51
|
+
/** the first "<N> bullets / list items / items / lines / points" in a guardrail (digits, or one..ten; not a price like "$5 per item" or a decimal), or null @param {unknown} g @returns {number|null} */
|
|
52
52
|
export function guardrailItemCount(g) {
|
|
53
|
-
const m = typeof g === 'string' ?
|
|
53
|
+
const m = typeof g === 'string' ? /(?<![$€£\d.,])\b(\d+|one|two|three|four|five|six|seven|eight|nine|ten)\s+(?:\w+\s+)?(?:bullets?|bullet\s+points?|list\s+items?|items?|lines?|points?)\b/i.exec(g) : null;
|
|
54
54
|
if (!m) return null;
|
|
55
55
|
return /^\d+$/.test(m[1]) ? Number(m[1]) : NUMBER_WORDS[m[1].toLowerCase()];
|
|
56
56
|
}
|