fwdloop 0.28.0 → 0.30.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 +1 -1
- package/bin/fwdloop +27 -5
- package/package.json +3 -3
- package/src/added-end.js +60 -0
- package/src/ask.js +1 -1
- package/src/audit-fold.js +9 -1
- package/src/authoring.js +18 -7
- package/src/checked.js +14 -9
- package/src/checkpick.js +318 -0
- package/src/checkwords.js +29 -0
- package/src/citedcheck.js +14 -0
- package/src/closers.js +40 -3
- package/src/declaration.js +102 -5
- package/src/draft-steps.js +3 -3
- package/src/drafter.js +151 -38
- package/src/jobkey.js +3 -1
- package/src/learn.js +1 -1
- package/src/learnstore.js +6 -6
- package/src/memo.js +120 -0
- package/src/model-step.js +103 -25
- package/src/pageask.js +12 -6
- package/src/pagedropwords.js +9 -0
- package/src/panel/author.js +33 -10
- package/src/panel/authorcard.js +59 -6
- package/src/panel/data.js +16 -10
- package/src/panel/index.html +151 -59
- package/src/panel/result.js +28 -7
- package/src/panel/server.js +2 -1
- package/src/pickrecord.js +146 -0
- package/src/plain-checks.js +16 -3
- package/src/provider.js +4 -1
- package/src/repairs.js +38 -0
- package/src/runfile.js +4 -2
- package/src/runner.js +129 -40
- package/src/send.js +71 -4
- package/src/setup.js +13 -1
- package/src/sheetblock.js +2 -1
- package/src/ticket-draft.js +2 -2
- package/src/ticket-labels.js +2 -2
- package/src/try-checks.js +13 -3
- package/src/whole-job.js +71 -0
- package/types/added-end.d.ts +62 -0
- package/types/ask.d.ts +2 -1
- package/types/audit-fold.d.ts +13 -2
- package/types/authoring.d.ts +6 -2
- package/types/checked.d.ts +7 -2
- package/types/checkpick.d.ts +183 -0
- package/types/checkwords.d.ts +18 -0
- package/types/citedcheck.d.ts +6 -0
- package/types/closers.d.ts +6 -3
- package/types/declaration.d.ts +12 -0
- package/types/drafter.d.ts +28 -25
- package/types/learn.d.ts +1 -0
- package/types/learnstore.d.ts +2 -3
- package/types/memo.d.ts +15 -0
- package/types/model-step.d.ts +23 -3
- package/types/pageask.d.ts +9 -2
- package/types/pagedropwords.d.ts +1 -0
- package/types/panel/author.d.ts +1 -1
- package/types/panel/authorcard.d.ts +41 -0
- package/types/panel/data.d.ts +1 -1
- package/types/panel/jobgrid.d.ts +1 -1
- package/types/panel/result.d.ts +9 -3
- package/types/pickrecord.d.ts +88 -0
- package/types/plain-checks.d.ts +9 -1
- package/types/repairs.d.ts +13 -0
- package/types/runfile.d.ts +7 -2
- package/types/runner.d.ts +16 -5
- package/types/send.d.ts +10 -2
- package/types/setup.d.ts +1 -56
- package/types/try-checks.d.ts +1 -7
- package/types/whole-job.d.ts +70 -0
- package/src/attemptdiff.js +0 -118
- package/types/attemptdiff.d.ts +0 -38
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ general agent. Not a chat bot. A workflow that a person can read, approve, rerun
|
|
|
33
33
|
A real past run: a job that reads a public flights page, lists 3 Madrid→Rome flights, asks a
|
|
34
34
|
human to check them, then writes the result out. Shown across the panel's Job, Run, Ask, Audit and Result tabs.
|
|
35
35
|
|
|
36
|
-
<img src="https://raw.githubusercontent.com/hamr0/fwdloop/main/docs/media/walkthrough.gif" alt="fwdloop panel walkthrough: Job, Run, Ask, Audit, Result" width="100%">
|
|
36
|
+
<img src="https://raw.githubusercontent.com/hamr0/fwdloop/main/docs/media/walkthrough.gif" alt="fwdloop panel walkthrough: Job, Run waiting at the Ask, Ask, passed Run, Audit, Result" width="100%">
|
|
37
37
|
|
|
38
38
|
## Where it comes from
|
|
39
39
|
|
package/bin/fwdloop
CHANGED
|
@@ -52,6 +52,7 @@ import { panelMain } from '../src/panel/server.js';
|
|
|
52
52
|
import { launcherMain } from '../src/launcher.js';
|
|
53
53
|
import { isInteractive, confirmTypedName, NEEDS_TTY } from '../src/sign-confirm.js';
|
|
54
54
|
import { draftToDir, draftKeyRefusal, signDraft, SIGN_LINE, costText, questionsRefusal } from '../src/authoring.js';
|
|
55
|
+
import { readRecordFile } from '../src/pickrecord.js';
|
|
55
56
|
import { userInfo } from 'node:os';
|
|
56
57
|
import { pageAddressesOf, pageAddressRefusal } from '../src/pagefetch.js';
|
|
57
58
|
import { ticketListsOf, isTicketNumber, TICKET_NUMBER_WORDS } from '../src/ticket-shape.js';
|
|
@@ -338,7 +339,7 @@ async function cmdRun(rest) {
|
|
|
338
339
|
const env = keyedEnv();
|
|
339
340
|
|
|
340
341
|
const flowName = positionals[0];
|
|
341
|
-
if (!flowName) fail('run: a flow name is required — fwdloop run <flow> --root <dir> --source <role>=<path> ...');
|
|
342
|
+
if (!flowName) fail('run: a flow name is required — fwdloop run <flow> [--root <dir>] --source <role>=<path> ...');
|
|
342
343
|
|
|
343
344
|
const root = resolveRoot('run', values.root);
|
|
344
345
|
const nameCheck = checkFlowName(flowName);
|
|
@@ -583,7 +584,7 @@ function cmdShow(rest) {
|
|
|
583
584
|
allowPositionals: true,
|
|
584
585
|
});
|
|
585
586
|
const [askId] = positionals;
|
|
586
|
-
if (!askId) fail('show: an askId is required — fwdloop show <askId> --root <dir>');
|
|
587
|
+
if (!askId) fail('show: an askId is required — fwdloop show <askId> [--root <dir>]');
|
|
587
588
|
|
|
588
589
|
const root = resolveRoot('show', values.root);
|
|
589
590
|
const runDir = findRunDirByAskId(root, askId);
|
|
@@ -670,7 +671,7 @@ async function cmdResume(rest) {
|
|
|
670
671
|
});
|
|
671
672
|
const env = keyedEnv();
|
|
672
673
|
const runId = positionals[0];
|
|
673
|
-
if (!runId) fail('resume: a runId is required — fwdloop resume <runId> --flow <name> --root <dir>');
|
|
674
|
+
if (!runId) fail('resume: a runId is required — fwdloop resume <runId> --flow <name> [--root <dir>]');
|
|
674
675
|
if (!values.flow) fail('resume: --flow <name> is required');
|
|
675
676
|
|
|
676
677
|
const root = resolveRoot('resume', values.root);
|
|
@@ -769,7 +770,7 @@ async function cmdContinue(rest) {
|
|
|
769
770
|
});
|
|
770
771
|
const env = keyedEnv();
|
|
771
772
|
const runId = positionals[0];
|
|
772
|
-
if (!runId) fail('continue: a runId is required — fwdloop continue <runId> --flow <name> --root <dir>');
|
|
773
|
+
if (!runId) fail('continue: a runId is required — fwdloop continue <runId> --flow <name> [--root <dir>]');
|
|
773
774
|
if (!values.flow) fail('continue: --flow <name> is required');
|
|
774
775
|
|
|
775
776
|
const root = resolveRoot('continue', values.root);
|
|
@@ -884,6 +885,10 @@ async function cmdDraft(rest) {
|
|
|
884
885
|
'no-questions': { type: 'boolean' },
|
|
885
886
|
// M10 piece 3: the rules the person left Not checked ("drop it"), as `<line>.<rule>` pairs, e.g. `1.2,3.1` (the panel passes this to the redraft after the answers)
|
|
886
887
|
left: { type: 'string' },
|
|
888
|
+
// M10 am16: the checks the person picked and the answers that were not a pick, as JSON (the panel passes this to the redraft after the answers)
|
|
889
|
+
picks: { type: 'string' },
|
|
890
|
+
// M10 am17: the record file of the plan this draft follows (a Revise, or the redraft after the answers); its kept picks skip the suggestion and the asks
|
|
891
|
+
carry: { type: 'string' },
|
|
887
892
|
// M4d amendment 6: the model that drafts (and then runs) the job - a line ticked in Settings > Providers; --provider only if two keys tick the same id.
|
|
888
893
|
// --thinking is the Chat "Thinking on" tick (drafting only; off unless given).
|
|
889
894
|
model: { type: 'string' }, provider: { type: 'string' }, thinking: { type: 'boolean' },
|
|
@@ -909,6 +914,21 @@ async function cmdDraft(rest) {
|
|
|
909
914
|
leftRules.push({ line: Number(m[1]), rule: Number(m[2]) });
|
|
910
915
|
}
|
|
911
916
|
|
|
917
|
+
/** @type {any[]|undefined} */
|
|
918
|
+
let checkPicks;
|
|
919
|
+
if (values.picks !== undefined) {
|
|
920
|
+
try { checkPicks = JSON.parse(values.picks); } catch { checkPicks = undefined; }
|
|
921
|
+
if (!Array.isArray(checkPicks) || checkPicks.some((x) => !x || !Number.isInteger(x.line) || !Number.isInteger(x.rule))) fail('draft: --picks takes a JSON list of {line, rule, check|null, added?, own?}');
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
/** @type {any[]|undefined} */
|
|
925
|
+
let carriedPicks;
|
|
926
|
+
if (values.carry !== undefined) {
|
|
927
|
+
const abs = resolve(values.carry);
|
|
928
|
+
const g = readFileInside(dirname(abs), basename(abs));
|
|
929
|
+
if (g.ok) carriedPicks = readRecordFile(abs) ?? undefined; // a missing or unreadable record is no record: every guardrail is asked, as before
|
|
930
|
+
}
|
|
931
|
+
|
|
912
932
|
let injected = {};
|
|
913
933
|
if (process.env.NODE_ENV === 'test' && process.env.FWDLOOP_TEST_DRAFT_PROVIDER) {
|
|
914
934
|
const mod = await import(pathToFileURL(resolve(process.env.FWDLOOP_TEST_DRAFT_PROVIDER)).href);
|
|
@@ -967,6 +987,8 @@ async function cmdDraft(rest) {
|
|
|
967
987
|
name: values.name,
|
|
968
988
|
noQuestions: values['no-questions'] === true,
|
|
969
989
|
...(leftRules.length ? { leftRules } : {}),
|
|
990
|
+
...(checkPicks === undefined ? {} : { checkPicks }),
|
|
991
|
+
...(carriedPicks === undefined ? {} : { carriedPicks }),
|
|
970
992
|
draftThinking: values.thinking === true ? 'on' : 'off',
|
|
971
993
|
flowType,
|
|
972
994
|
...(values.mcp ? { mcpServer: values.mcp } : {}),
|
|
@@ -1024,7 +1046,7 @@ async function cmdSign(rest) {
|
|
|
1024
1046
|
});
|
|
1025
1047
|
if (!result.ok) fail(`sign refused — ${result.reds.join('; ')}`);
|
|
1026
1048
|
if (result.runId) {
|
|
1027
|
-
process.stdout.write(`signed: ${result.runDir} as ${result.runId} of ${values['run-of']} (by ${result.signature.signedBy})\nrun it: fwdloop run ${values['run-of']} --root <dir> --run-id ${result.runId} --source <role>=<path> ...\n`);
|
|
1049
|
+
process.stdout.write(`signed: ${result.runDir} as ${result.runId} of ${values['run-of']} (by ${result.signature.signedBy})\nrun it: fwdloop run ${values['run-of']} [--root <dir>] --run-id ${result.runId} --source <role>=<path> ...\n`);
|
|
1028
1050
|
return;
|
|
1029
1051
|
}
|
|
1030
1052
|
process.stdout.write(`signed: ${result.flowDir} (by ${result.signature.signedBy})\n`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fwdloop",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.0",
|
|
4
4
|
"description": "Describe a job as steps and guardrails; an agent builds the workflow, pauses for humans where you said, checks every step happened, and reruns it under budgets it cannot touch.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -49,9 +49,9 @@
|
|
|
49
49
|
"NOTICE"
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"bare-agent": "^0.
|
|
52
|
+
"bare-agent": "^0.59.0",
|
|
53
53
|
"barebrowse": "^0.26.0",
|
|
54
|
-
"bareguard": "^0.
|
|
54
|
+
"bareguard": "^0.34.1",
|
|
55
55
|
"litectx": "^0.32.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
package/src/added-end.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// M13 am8: the end of a job is added by code, never typed. ONE writer of the added lines (`addEnd`), ONE reader that finds them again in a plan (`addedLinesOf`).
|
|
2
|
+
// Given the card's parsed job steps and its Destination: no Destination -> nothing added; the last line not an Ask -> `ask <wait>: check the result with me`
|
|
3
|
+
// then `write it out`; the last line an Ask -> only `write it out`. The send is always the added `write it out`. The wait is the card's Ask wait (the
|
|
4
|
+
// caller's `jobFileLines` writes it out, as it does for any ask line with no wait of its own).
|
|
5
|
+
// Throws away: nothing. Third outcomes: an empty job adds nothing (the card refuses an empty job before this runs).
|
|
6
|
+
|
|
7
|
+
export const ADDED_ASK_QUESTION = 'check the result with me';
|
|
8
|
+
export const ADDED_WRITE = 'write it out';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {{ n: number, text: string, ask: null | { wait: string|null, question: string }, guardrails: string[] }[]} steps `parseJobBox` steps
|
|
12
|
+
* @param {string} destination the card's Destination ('' = none)
|
|
13
|
+
* @returns {{ steps: { n: number, text: string, ask: null | { wait: string|null, question: string }, guardrails: string[] }[], added: number[] }} the steps with the end added, and the numbers of the added lines
|
|
14
|
+
*/
|
|
15
|
+
export function addEnd(steps, destination) {
|
|
16
|
+
if (destination === '' || steps.length === 0) return { steps, added: [] };
|
|
17
|
+
const out = [...steps];
|
|
18
|
+
/** @type {number[]} */
|
|
19
|
+
const added = [];
|
|
20
|
+
if (out[out.length - 1].ask === null) {
|
|
21
|
+
const n = out.length + 1;
|
|
22
|
+
out.push({ n, text: `ask: ${ADDED_ASK_QUESTION}`, ask: { wait: null, question: ADDED_ASK_QUESTION }, guardrails: [] });
|
|
23
|
+
added.push(n);
|
|
24
|
+
}
|
|
25
|
+
const n = out.length + 1;
|
|
26
|
+
out.push({ n, text: ADDED_WRITE, ask: null, guardrails: [] });
|
|
27
|
+
added.push(n);
|
|
28
|
+
return { steps: out, added };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The added lines of a plan, found again from its signed lines and arbiter: the send line when it reads `write it out`, and the Ask just before it
|
|
33
|
+
* when that reads `check the result with me`. A job signed before M13 am8 (its send line is the person's own words) finds none.
|
|
34
|
+
* @param {{ n: number, text: string }[]} lines @param {{ sends?: { line: number }[], asks?: { line: number }[] }} arbiter
|
|
35
|
+
* @returns {Set<number>}
|
|
36
|
+
*/
|
|
37
|
+
export function addedLinesOf(lines, arbiter) {
|
|
38
|
+
const found = new Set();
|
|
39
|
+
const send = (arbiter?.sends ?? [])[0];
|
|
40
|
+
if (!send) return found;
|
|
41
|
+
const textOf = (/** @type {number} */ n) => lines.find((l) => l.n === n)?.text;
|
|
42
|
+
if (textOf(send.line) !== ADDED_WRITE) return found;
|
|
43
|
+
found.add(send.line);
|
|
44
|
+
if (textOf(send.line - 1) === ADDED_ASK_QUESTION && (arbiter.asks ?? []).some((a) => a.line === send.line - 1)) found.add(send.line - 1);
|
|
45
|
+
return found;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The lines a person typed, found again from a signed job: the signed lines without the send line (the last line when it is the send; today's `write it out`, or
|
|
50
|
+
* the person's own words in a job signed before am8) and without an added Ask before it. ONE reader for the Edit card (`cardFromSigned`) and the job identity (`jobKeyOfSigned`).
|
|
51
|
+
* @template {{ n: number, text: string }} L
|
|
52
|
+
* @param {L[]} lines @param {{ sends?: { line: number }[], asks?: { line: number }[] }} arbiter
|
|
53
|
+
* @returns {L[]}
|
|
54
|
+
*/
|
|
55
|
+
export function typedLinesOf(lines, arbiter) {
|
|
56
|
+
const sends = arbiter?.sends ?? [];
|
|
57
|
+
const lastSend = sends.length === 1 && sends[0].line === lines.length ? sends[0].line : null;
|
|
58
|
+
const added = addedLinesOf(lines, arbiter);
|
|
59
|
+
return lines.filter((l) => l.n !== lastSend && !added.has(l.n));
|
|
60
|
+
}
|
package/src/ask.js
CHANGED
|
@@ -699,7 +699,7 @@ export function readAcceptedHashesByEmits(runDir) {
|
|
|
699
699
|
/**
|
|
700
700
|
* @param {string} runDir
|
|
701
701
|
* @returns {{ archived: true, asks: Array<{ askId: string, question?: string, askedAt?: string, expiresAt?: string,
|
|
702
|
-
* evidence: ReturnType<typeof readAskEvidence>,
|
|
702
|
+
* evidence: ReturnType<typeof readAskEvidence>, emits?: string,
|
|
703
703
|
* answer: { status: string, reason?: string, answeredAt?: string, why?: string } }> } | { archived: false, why: string }}
|
|
704
704
|
*/
|
|
705
705
|
export function listArchivedAsks(runDir) {
|
package/src/audit-fold.js
CHANGED
|
@@ -51,6 +51,9 @@ export function humanWords(r) {
|
|
|
51
51
|
return null;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
/** M14 am1 item 1: the words for the reason a rerun started with, shaped like the redo words above. @param {string} words */
|
|
55
|
+
export const rerunWords = (words) => `you said rerun: "${words}"`;
|
|
56
|
+
|
|
54
57
|
/** The short answer for a card: `accepted`, `redo: "<text>"`, `cancelled`. @param {any} r */
|
|
55
58
|
function answerShort(r) {
|
|
56
59
|
const w = humanWords(r);
|
|
@@ -61,7 +64,7 @@ function answerShort(r) {
|
|
|
61
64
|
* The fold of one step, or `null` for a step with nothing new to show (an old run, or a step that is neither a model step with records nor an ask).
|
|
62
65
|
* @param {{rows:any[], tryMarks:string[], closeClass:string|null}} group `deriveAuditGroups`' group for the step
|
|
63
66
|
* @param {ReturnType<typeof loadDiaries>} d
|
|
64
|
-
* @param {{about?: string|null}} [info] `about`: the file an ask is about
|
|
67
|
+
* @param {{about?: string|null, rerun?: {words: string}|null}} [info] `about`: the file an ask is about; `rerun`: this run's reason for starting (run.json), given for its first step only
|
|
65
68
|
*/
|
|
66
69
|
export function deriveFold(group, d, info = {}) {
|
|
67
70
|
const step = group.rows[0]?.step ?? null;
|
|
@@ -116,6 +119,8 @@ export function deriveFold(group, d, info = {}) {
|
|
|
116
119
|
n: r.attempt, mark: group.tryMarks[i] ?? '·', thinking: r.thinkingPhrase ?? null, gap: r.gap || null, answer: null, about: null, checks: rec?.checks ?? [], output: rec?.output ?? null,
|
|
117
120
|
// M8 am7 item 4: the exact text this try was handed, from its own audit row (`hints` count + `hintsText`); null (no line) when nothing was handed
|
|
118
121
|
hints: typeof r.hintsText === 'string' && r.hintsText !== '' && Number.isInteger(r.hints) ? { n: r.hints, text: r.hintsText } : null,
|
|
122
|
+
// M14 item 7: the exact memo text (what happened so far in this run) this try was handed, from its own audit row (`memoText`); null (no button) when none was
|
|
123
|
+
memo: typeof r.memoText === 'string' && r.memoText !== '' ? { text: r.memoText } : null,
|
|
119
124
|
});
|
|
120
125
|
});
|
|
121
126
|
// rounds count on through all of a step's tries, so they order the calls and tool calls; a try's check row goes after the last round it saw
|
|
@@ -123,6 +128,9 @@ export function deriveFold(group, d, info = {}) {
|
|
|
123
128
|
calls.forEach((c, i) => items.push({ k: c.round * 2, i, row: { round: c.round, try: c.try, action: 'model call', path: null, decision: callDecision(c), at: c.at } }));
|
|
124
129
|
tools.forEach((t, i) => items.push({ k: t.round * 2 + 1, i: 1e6 + i, row: { round: t.round, try: t.try, action: `model · ${t.tool}`, path: t.path ?? null, decision: toolDecision(t), at: t.at } }));
|
|
125
130
|
checkRows.forEach((c, i) => items.push({ k: (c.lastRound ?? 0) * 2 + 1.5, i: 2e6 + i, row: { round: null, try: c.try, action: 'check', path: c.output?.file ?? null, decision: checkDecision(c.checks), at: c.at } }));
|
|
131
|
+
// M14 am1 item 1 / item 11: a rerun's reason was handed to its first step (as its gap and in its memo) and is kept in the run's own run.json; it shows, in the shape of
|
|
132
|
+
// the redo words (`humanWords`), as the first row of that step's first try
|
|
133
|
+
if (info.rerun && tryRows.length > 0) items.push({ k: -1, i: -1, row: { round: null, try: tryRows[0].attempt, action: 'human', path: null, decision: rerunWords(info.rerun.words), at: null } });
|
|
126
134
|
items.sort((a, b) => a.k - b.k || a.i - b.i);
|
|
127
135
|
for (const it of items) rows.push(it.row);
|
|
128
136
|
}
|
package/src/authoring.js
CHANGED
|
@@ -22,7 +22,9 @@ import path from 'node:path';
|
|
|
22
22
|
import { draft } from './drafter.js';
|
|
23
23
|
import { parseSignedText, unsignedAskTtls } from './signed-text.js';
|
|
24
24
|
import { validateDeclaration, flowTypeOf } from './declaration.js';
|
|
25
|
+
import { addedLinesOf } from './added-end.js';
|
|
25
26
|
import { factRows } from './citedcheck.js';
|
|
27
|
+
import { plainWords, labelled } from './checkwords.js';
|
|
26
28
|
import { sheetLineBlocks } from './sheetblock.js';
|
|
27
29
|
import { loadCatalogue } from './catalogue.js';
|
|
28
30
|
import { WIRED_VERBS } from './primitives.js';
|
|
@@ -38,6 +40,7 @@ import { hintsForRun, placeSpecOf } from './learnstore.js';
|
|
|
38
40
|
import { redactSecrets } from './redact.js';
|
|
39
41
|
import { sessionPriorSpend, writeDraftSpend } from './draftspend.js';
|
|
40
42
|
import { writeSetup } from './setup.js';
|
|
43
|
+
import { RECORD_FILE } from './pickrecord.js';
|
|
41
44
|
import { mcpPickHere } from './mcp-pick.js';
|
|
42
45
|
|
|
43
46
|
export const SPEC_HASH_FILE = 'spec.hash';
|
|
@@ -88,7 +91,7 @@ export function specHash({
|
|
|
88
91
|
* answer file counts as no answer. No questions file = `{ questions: [], open: [] }`.
|
|
89
92
|
* @param {string} planDir
|
|
90
93
|
* 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`.
|
|
91
|
-
* @returns {{ questions: {k:number, line:number, question:string, answer:string|null, at?:string, rule?:string|null, source?:string, ask?:string, ruleNo?:number, ruleText?:string, proposal?:string|null}[], open: {k:number, line:number, question:string, answer:null}[] }}
|
|
94
|
+
* @returns {{ questions: {k:number, line:number, question:string, answer:string|null, at?:string, rule?:string|null, source?:string, ask?:string, ruleNo?:number, ruleText?:string, proposal?:string|null, check?:Record<string, any>, pairRule?:number}[], open: {k:number, line:number, question:string, answer:null}[] }}
|
|
92
95
|
*/
|
|
93
96
|
export function readQuestions(planDir) {
|
|
94
97
|
const none = { questions: [], open: [] };
|
|
@@ -113,7 +116,7 @@ export function readQuestions(planDir) {
|
|
|
113
116
|
}
|
|
114
117
|
return {
|
|
115
118
|
k, line: q.line, question: String(q.question), answer, ...(at === undefined ? {} : { at }), ...(rule === undefined ? {} : { rule }),
|
|
116
|
-
...(q.source === 'look' ? { source: 'look', ask: q.ask, ruleNo: q.ruleNo, ruleText: q.ruleText, proposal: typeof q.proposal === 'string' ? q.proposal : null } : {}),
|
|
119
|
+
...(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 } : {}) } : {}),
|
|
117
120
|
};
|
|
118
121
|
});
|
|
119
122
|
return { questions, open: /** @type {any} */ (questions.filter((q) => q.answer === null)) };
|
|
@@ -212,23 +215,28 @@ export function buildReadout({
|
|
|
212
215
|
if (Array.isArray(declaration.ticketWatch) && declaration.ticketWatch.length) out.push(` ticket watch: ${declaration.ticketWatch.join(', ')}`);
|
|
213
216
|
out.push('', READOUT_HEADS.steps);
|
|
214
217
|
const sheetBlocks = sheetLineBlocks({ declaration, lines });
|
|
218
|
+
const addedLines = addedLinesOf(lines, arbiter); // M13 am8: the lines code added at the end are marked `added`
|
|
215
219
|
declaration.steps.forEach((st, i) => {
|
|
216
|
-
out.push(` ${i + 1}. (line ${st.fromLine}) ${st.goal}`);
|
|
220
|
+
out.push(` ${i + 1}. (line ${st.fromLine}) ${st.goal}${addedLines.has(st.fromLine) ? ' [added]' : ''}`);
|
|
217
221
|
out.push(` grants: ${st.primitives?.length ? st.primitives.join(', ') : 'none (pure stop)'}`
|
|
218
222
|
+ ` | reads: ${st.reads?.length ? st.reads.join(', ') : '-'} | emits: ${st.emits} | check: ${st.close?.class}`);
|
|
219
223
|
if (Array.isArray(st.mcpTools) && st.mcpTools.length) out.push(` tools: ${st.mcpTools.join(', ')}`);
|
|
220
224
|
// M10 am7 item 1: the facts a cited step checks its quotes against, signed with the readout (typed fields, never model prose)
|
|
221
|
-
if (st.close?.cited && typeof st.close.cited === 'object') for (const row of factRows(st.close.cited)) out.push(` ${row}`);
|
|
225
|
+
if (st.close?.cited && typeof st.close.cited === 'object') for (const row of factRows(st.close.cited)) out.push(` ${labelled(row, 'agent')}`);
|
|
222
226
|
// M10b piece 1: the signed sheet checks, one row each, written by code from the typed fields
|
|
223
227
|
if (Array.isArray(st.close?.sheet)) for (const row of sheetBlocks.find((b) => b.line === st.fromLine)?.checked ?? []) out.push(` sheet check: ${row.text}`);
|
|
224
228
|
// M10 am8 item 2: the column lock, signed with the readout (typed fields)
|
|
225
229
|
if (Array.isArray(st.close?.columns)) for (const c of st.close.columns) if (typeof c?.column === 'string' && typeof c?.source === 'string') out.push(` cells only from column '${c.column}' of ${c.source}`);
|
|
230
|
+
// M10 am16: the checks the person picked, signed with the readout, each in the one set of plain words (typed fields, never model prose)
|
|
231
|
+
if (Array.isArray(st.close?.shape?.picked)) for (const c of st.close.shape.picked) out.push(` ${labelled(`you picked: ${plainWords(c)}`, 'picked')}`);
|
|
232
|
+
// M10 am22 (1): the checks the person picked for a fact line are signed with the readout too, in the same words
|
|
233
|
+
if (st.close?.class === 'green' && Array.isArray(st.close.picked)) for (const c of st.close.picked) out.push(` ${labelled(`you picked: ${plainWords(c)}`, 'picked')}`);
|
|
226
234
|
// M4e amendment 14 item 5: the check's sections in its order (+ word limit); fixed text from typed fields, never model prose.
|
|
227
235
|
const shape = st.close?.shape;
|
|
228
236
|
if (Array.isArray(shape?.sections) && shape.sections.length > 0) {
|
|
229
237
|
const per = Number.isInteger(shape.wordsPerSection) ? ` · about ${shape.wordsPerSection} words each` : '';
|
|
230
238
|
const lim = Number.isInteger(shape.maxWords) ? ` · under ${shape.maxWords} words` : '';
|
|
231
|
-
out.push(` sections: ${shape.sections.join(' · ')}${per}${lim}`);
|
|
239
|
+
out.push(` ${labelled(`sections: ${shape.sections.join(' · ')}${per}${lim}`, 'agent')}`);
|
|
232
240
|
}
|
|
233
241
|
});
|
|
234
242
|
out.push('', READOUT_HEADS.asks);
|
|
@@ -294,7 +302,7 @@ export function draftKeyRefusal(slot, env) {
|
|
|
294
302
|
* `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).
|
|
295
303
|
*/
|
|
296
304
|
export async function draftToDir({
|
|
297
|
-
proseFile, dir, root, name, slot, model, draftThinking = /** @type {'on'|'off'} */ ('off'), keyNames, env = process.env, provider, rates, modelId, noQuestions = false, onResult, fetchPage, leftRules, proseRead,
|
|
305
|
+
proseFile, dir, root, name, slot, model, draftThinking = /** @type {'on'|'off'} */ ('off'), keyNames, env = process.env, provider, rates, modelId, noQuestions = false, onResult, fetchPage, leftRules, checkPicks, carriedPicks, proseRead,
|
|
298
306
|
flowType = /** @type {'plain'|'mcp'|'tickets'} */ ('plain'), mcpServer = /** @type {string|undefined} */ (undefined), mcpPick = /** @type {any} */ (undefined), mcpServers = /** @type {string[]|undefined} */ (undefined),
|
|
299
307
|
}) {
|
|
300
308
|
const refuse = (reds) => ({ ok: false, wrote: false, reds, costUsd: 0 });
|
|
@@ -371,8 +379,10 @@ export async function draftToDir({
|
|
|
371
379
|
}
|
|
372
380
|
// M13 piece 4 (R1): the job's MCP is every tool of that server's newest OK check, read here by code (the server is never started); never checked = a $0 refusal in the drafter's pre-flight
|
|
373
381
|
const mcp = flowType === 'plain' ? null : (mcpPick ?? (typeof mcpServer === 'string' ? mcpPickHere(mcpServer) : { ok: false, say: 'pick an MCP for this flow type' }));
|
|
382
|
+
/** @type {{picks: object[], kept: object[]}|null} */
|
|
383
|
+
let pickRecord = null; // M10 am17: handed by draft() as it learns it; the last one handed is this draft's (written below, the one writer)
|
|
374
384
|
const result = await draft({
|
|
375
|
-
proseText: prose.text, slot, model, provider, rates, modelId, env, onBook, priorSpend, offerQuestions: !noQuestions, draftThinking, draftDir: path.join(dir, PAGES_DIR), fetchPage, learnHints, ...(leftRules === undefined ? {} : { leftRules }),
|
|
385
|
+
proseText: prose.text, slot, model, provider, rates, modelId, env, onBook, priorSpend, offerQuestions: !noQuestions, draftThinking, draftDir: path.join(dir, PAGES_DIR), fetchPage, learnHints, ...(leftRules === undefined ? {} : { leftRules }), ...(checkPicks === undefined ? {} : { checkPicks }), ...(carriedPicks === undefined ? {} : { carriedPicks }), onPickRecord: (r) => { pickRecord = r; },
|
|
376
386
|
flowType, mcp, ...(mcpServers === undefined ? {} : { mcpServers }),
|
|
377
387
|
});
|
|
378
388
|
if (result.stop === 'pre-flight') {
|
|
@@ -404,6 +414,7 @@ export async function draftToDir({
|
|
|
404
414
|
// Amendments 24/25: the questions and the drafter's own "not checked" reading are written BEFORE log.json/spec.hash (the panel reads those
|
|
405
415
|
// two as "the draft finished"), as their own files: never in the readout, so never in the hash.
|
|
406
416
|
if (result.questions?.length) files[QUESTIONS_FILE] = scrub(dj({ questions: result.questions }), secrets);
|
|
417
|
+
if (pickRecord !== null) files[RECORD_FILE] = scrub(dj(pickRecord), secrets); // M10 am17: the picks carried to the next plan (this drafting folder only, never a run folder)
|
|
407
418
|
files[NOT_CHECKED_FILE] = scrub(dj({ notChecked: result.notChecked ?? [] }), secrets);
|
|
408
419
|
if (result.pageLooks || result.sheetLooks) files[PAGE_LOOK_FILE] = scrub(dj({ pages: result.pageLooks ?? [], ...(result.sheetLooks ? { sheets: result.sheetLooks } : {}), look: result.look ?? { facts: [], dropped: [] } }), secrets);
|
|
409
420
|
files['log.json'] = scrub(dj({
|
package/src/checked.js
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
export const NOT_CHECKED_LABEL = "not checked (the AI's own reading)";
|
|
13
13
|
|
|
14
14
|
import { factRows } from './citedcheck.js';
|
|
15
|
+
import { plainWords, labelled } from './checkwords.js';
|
|
15
16
|
import { sheetCheckRows } from './sheetchecks.js';
|
|
16
17
|
import { sheetLineBlocks } from './sheetblock.js';
|
|
17
18
|
import { splitReadNotes, signedFactNames } from './pagedropwords.js';
|
|
@@ -22,11 +23,11 @@ const list = (xs) => xs.join(', ');
|
|
|
22
23
|
* One entry per step, in plan order: the plain sentences for what its typed close checks.
|
|
23
24
|
* M10b piece 4: with `lines` (the signed job lines) a step that reads a sheet also carries `sheet`, its line's block (src/sheetblock.js `sheetLineBlocks`: guardrails,
|
|
24
25
|
* Checked with `covers`, Not checked), and its sentences are only the lead sentence; the surfaces draw the block. Without `lines` the older one-row-per-check sentences.
|
|
25
|
-
* @param {{ steps?: any[] }} declaration @param {{ hasAsk?: boolean, askLines?: number[], lines?: any[], csvRoles?: string[] }} [opts] hasAsk = the job has a signed ask line (so "you check it at the ask" is true);
|
|
26
|
+
* @param {{ steps?: any[] }} declaration @param {{ hasAsk?: boolean, askLines?: number[], lines?: any[], csvRoles?: string[], keptChecks?: {line: number, check: any}[], keptWords?: string }} [opts] hasAsk = the job has a signed ask line (so "you check it at the ask" is true);
|
|
26
27
|
* askLines = the job lines of the signed asks, which also lets a step after the LAST ask read "you check it after you accept" (am41 item 2, am42: the ONE place for these words)
|
|
27
28
|
* @returns {{ step: number, line: number|null, goal: string, class: string, sentences: string[], sheet?: ReturnType<typeof sheetLineBlocks>[number] }[]}
|
|
28
29
|
*/
|
|
29
|
-
export function checkedLines(declaration, { hasAsk = true, askLines, lines, csvRoles = [] } = {}) {
|
|
30
|
+
export function checkedLines(declaration, { hasAsk = true, askLines, lines, csvRoles = [], keptChecks = [], keptWords = '' } = {}) {
|
|
30
31
|
const blocks = Array.isArray(lines) ? sheetLineBlocks({ declaration, lines, csvRoles }) : [];
|
|
31
32
|
const steps = Array.isArray(declaration?.steps) ? declaration.steps : [];
|
|
32
33
|
if (Array.isArray(askLines)) hasAsk = askLines.length > 0;
|
|
@@ -40,23 +41,27 @@ export function checkedLines(declaration, { hasAsk = true, askLines, lines, csvR
|
|
|
40
41
|
const out = [];
|
|
41
42
|
if (cls === 'green' && st.close.cited && typeof st.close.cited === 'object') {
|
|
42
43
|
// M10 am7 item 1: the facts the drafter wrote, as plain rows written by code from the typed fields
|
|
43
|
-
out.push(`Each result must be quoted word for word from the saved page "${st.close.cited.source}", and the machine checks every quote, every value and the count against that copy.`, ...factRows(st.close.cited));
|
|
44
|
+
out.push(`Each result must be quoted word for word from the saved page "${st.close.cited.source}", and the machine checks every quote, every value and the count against that copy.`, ...factRows(st.close.cited).map((r) => labelled(r, 'agent')));
|
|
44
45
|
} else if (cls === 'green' && Array.isArray(st.close.sheet)) {
|
|
45
46
|
// M10b piece 1: the signed sheet checks, one row each, written by code from the typed fields
|
|
46
|
-
out.push('The machine recomputes each of these from the saved sheet and compares it with what the step gave:', ...(sheet ? [] : sheetCheckRows(st.close.sheet)));
|
|
47
|
+
out.push('The machine recomputes each of these from the saved sheet and compares it with what the step gave:', ...(sheet ? [] : sheetCheckRows(st.close.sheet).map((r) => labelled(r, 'agent'))));
|
|
47
48
|
} else if (cls === 'green') {
|
|
48
49
|
out.push('Every figure must cite its source cell, or a formula over cells, and the machine recomputes it and compares it with its source.');
|
|
49
50
|
} else if (cls === 'softgreen') {
|
|
50
51
|
out.push('The reply is checked as plain text only.');
|
|
51
|
-
if (Number.isInteger(shape.maxWords)) out.push(`The whole output is under ${shape.maxWords} words
|
|
52
|
-
if (Array.isArray(shape.sections) && shape.sections.length > 0) out.push(`These section headings are there, in this order: ${list(shape.sections)}
|
|
53
|
-
if (Number.isInteger(shape.wordsPerSection) && Array.isArray(shape.sections) && shape.sections.length > 0) out.push(`Each of those sections is about ${shape.wordsPerSection} words
|
|
54
|
-
if (Number.isInteger(shape.linesPerInvoice)) out.push(`The output comes in blocks of ${shape.linesPerInvoice} lines
|
|
55
|
-
if (Array.isArray(shape.mustCarry) && shape.mustCarry.length > 0) out.push(`Every block carries: ${list(shape.mustCarry)}
|
|
52
|
+
if (Number.isInteger(shape.maxWords)) out.push(labelled(`The whole output is under ${shape.maxWords} words.`, 'agent'));
|
|
53
|
+
if (Array.isArray(shape.sections) && shape.sections.length > 0) out.push(labelled(`These section headings are there, in this order: ${list(shape.sections)}.`, 'agent'));
|
|
54
|
+
if (Number.isInteger(shape.wordsPerSection) && Array.isArray(shape.sections) && shape.sections.length > 0) out.push(labelled(`Each of those sections is about ${shape.wordsPerSection} words.`, 'agent'));
|
|
55
|
+
if (Number.isInteger(shape.linesPerInvoice)) out.push(labelled(`The output comes in blocks of ${shape.linesPerInvoice} lines.`, 'agent'));
|
|
56
|
+
if (Array.isArray(shape.mustCarry) && shape.mustCarry.length > 0) out.push(labelled(`Every block carries: ${list(shape.mustCarry)}.`, 'agent'));
|
|
57
|
+
// M10 am16: each check the person picked, in the words it was picked in (src/checkwords.js, the one place)
|
|
58
|
+
if (Array.isArray(shape.picked)) for (const c of shape.picked) out.push(labelled(`You picked: ${plainWords(c)}.${keptChecks.some((k) => k.line === st.fromLine && plainWords(k.check) === plainWords(c)) ? ` (${keptWords})` : ''}`, 'picked'));
|
|
56
59
|
} else {
|
|
57
60
|
if (lastAsk !== -1 && i > lastAsk) out.push('No machine check of the content; you check it after you accept.');
|
|
58
61
|
else out.push(hasAsk ? 'No machine check of the content: you check it at the ask.' : 'No machine check of the content; the machine checks only that the step happened.');
|
|
59
62
|
}
|
|
63
|
+
// M10 am22 (1)(4): the checks the person picked for a fact line, beside its fact rows
|
|
64
|
+
if (cls === 'green' && Array.isArray(st.close.picked)) for (const c of st.close.picked) out.push(labelled(`You picked: ${plainWords(c)}.${keptChecks.some((k) => k.line === st.fromLine && plainWords(k.check) === plainWords(c)) ? ` (${keptWords})` : ''}`, 'picked'));
|
|
60
65
|
return {
|
|
61
66
|
step: i + 1, line: Number.isInteger(st?.fromLine) ? st.fromLine : null, goal: typeof st?.goal === 'string' ? st.goal : '', class: String(cls), sentences: out,
|
|
62
67
|
...(sheet && cls === 'green' ? { sheet } : {}),
|