fwdloop 0.27.0 → 0.29.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 +54 -13
- package/package.json +3 -3
- package/src/ask.js +1 -1
- package/src/audit-fold.js +9 -1
- package/src/authoring.js +22 -5
- package/src/canrun.js +19 -16
- package/src/checked.js +5 -2
- package/src/checkpick.js +257 -0
- package/src/checkwords.js +24 -0
- package/src/closers.js +8 -1
- package/src/config.js +18 -0
- package/src/declaration.js +85 -5
- package/src/drafter.js +143 -47
- package/src/flow.js +2 -1
- package/src/launcher.js +4 -2
- package/src/learn.js +1 -1
- package/src/learnstore.js +8 -7
- package/src/mcp-checks.js +50 -0
- package/src/mcp-pick.js +33 -0
- package/src/mcp-sources.js +84 -0
- package/src/mcp-use.js +54 -0
- package/src/memo.js +120 -0
- package/src/model-step.js +89 -17
- package/src/natural.js +23 -0
- package/src/pageask.js +9 -6
- package/src/pagedropwords.js +9 -0
- package/src/panel/author.js +50 -28
- package/src/panel/authorcard.js +86 -2
- package/src/panel/authorflows.js +18 -14
- package/src/panel/authortrigger.js +241 -84
- package/src/panel/data.js +99 -11
- package/src/panel/index.html +683 -210
- package/src/panel/jobgrid.js +127 -0
- package/src/panel/result.js +28 -7
- package/src/panel/scheduler.js +8 -2
- package/src/panel/server.js +17 -7
- package/src/panel/settings.js +119 -4
- package/src/panel/tickets.js +12 -7
- package/src/pickrecord.js +146 -0
- package/src/plain-checks.js +1 -0
- package/src/primitives.js +34 -5
- package/src/provider.js +4 -1
- package/src/runfile.js +4 -2
- package/src/runner.js +170 -45
- package/src/send.js +71 -4
- package/src/setup.js +13 -1
- package/src/summary-words.js +15 -3
- package/src/ticket-draft.js +40 -42
- package/src/ticket-labels.js +10 -0
- package/src/ticket-mcp.js +33 -10
- package/src/ticket-next.js +33 -0
- package/src/ticket-shape.js +9 -0
- package/src/trigger-clock.js +4 -4
- package/src/trigger-files.js +3 -3
- package/src/trigger-tickets.js +41 -12
- package/types/ask.d.ts +2 -1
- package/types/audit-fold.d.ts +13 -2
- package/types/authoring.d.ts +10 -2
- package/types/canrun.d.ts +5 -12
- package/types/checked.d.ts +7 -2
- package/types/checkpick.d.ts +149 -0
- package/types/checkwords.d.ts +14 -0
- package/types/closers.d.ts +2 -1
- package/types/config.d.ts +6 -0
- package/types/declaration.d.ts +17 -0
- package/types/drafter.d.ts +446 -50
- package/types/learn.d.ts +1 -0
- package/types/learnstore.d.ts +2 -3
- package/types/mcp-checks.d.ts +8 -0
- package/types/mcp-pick.d.ts +23 -0
- package/types/mcp-sources.d.ts +51 -0
- package/types/mcp-use.d.ts +12 -0
- package/types/memo.d.ts +15 -0
- package/types/model-step.d.ts +5 -0
- package/types/natural.d.ts +2 -0
- package/types/pageask.d.ts +9 -2
- package/types/pagedropwords.d.ts +1 -0
- package/types/panel/author.d.ts +37 -1
- package/types/panel/authorcard.d.ts +52 -0
- package/types/panel/authorflows.d.ts +9 -1
- package/types/panel/authortrigger.d.ts +73 -7
- package/types/panel/data.d.ts +56 -2
- package/types/panel/jobgrid.d.ts +109 -0
- package/types/panel/result.d.ts +9 -3
- package/types/panel/server.d.ts +5 -1
- package/types/panel/settings.d.ts +3 -2
- package/types/panel/tickets.d.ts +26 -4
- package/types/pickrecord.d.ts +88 -0
- package/types/primitives.d.ts +15 -2
- package/types/runfile.d.ts +7 -2
- package/types/runner.d.ts +128 -77
- package/types/send.d.ts +10 -2
- package/types/setup.d.ts +1 -56
- package/types/summary-words.d.ts +22 -3
- package/types/ticket-draft.d.ts +40 -32
- package/types/ticket-labels.d.ts +6 -0
- package/types/ticket-mcp.d.ts +18 -1
- package/types/ticket-next.d.ts +23 -0
- package/types/ticket-shape.d.ts +5 -0
- package/types/trigger-clock.d.ts +4 -3
- package/types/trigger-files.d.ts +1 -1
- package/types/trigger-tickets.d.ts +18 -4
- 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
|
@@ -34,7 +34,7 @@ import { TRIGGER_RECORD_FILE } from '../src/trigger-line.js';
|
|
|
34
34
|
import { makeLiveModelStep } from '../src/model-step.js';
|
|
35
35
|
import { seedLedger } from '../src/learnstore.js';
|
|
36
36
|
import { sendViaPrimitive } from '../src/send.js';
|
|
37
|
-
import { resolvePrimitives } from '../src/primitives.js';
|
|
37
|
+
import { resolvePrimitives, stepMcp } from '../src/primitives.js';
|
|
38
38
|
import {
|
|
39
39
|
checkKeyPreflight, resolveUsableModel, pickTicked, readPriceConfig, ceilingCostUsd,
|
|
40
40
|
} from '../src/provider.js';
|
|
@@ -52,9 +52,13 @@ 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
|
-
import { ticketListsOf } from '../src/ticket-shape.js';
|
|
58
|
+
import { ticketListsOf, isTicketNumber, TICKET_NUMBER_WORDS } from '../src/ticket-shape.js';
|
|
59
|
+
import { flowTypeOf } from '../src/declaration.js';
|
|
60
|
+
import { LOOK_TOOL } from '../src/ticket-draft.js';
|
|
61
|
+
import { newestUnrunTicket } from '../src/ticket-next.js';
|
|
58
62
|
|
|
59
63
|
// This CLI drives no fixed provider (M4d amendment 6). A job runs with the model recorded beside it as its DEFAULT (M4d am33: `run --model` picks any other ticked model for that run) (`model.json`, written when it was drafted:
|
|
60
64
|
// the provider is the name of a key, its key is read from the env under that name and never printed); `draft` takes `--model` (+ `--provider`).
|
|
@@ -335,7 +339,7 @@ async function cmdRun(rest) {
|
|
|
335
339
|
const env = keyedEnv();
|
|
336
340
|
|
|
337
341
|
const flowName = positionals[0];
|
|
338
|
-
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> ...');
|
|
339
343
|
|
|
340
344
|
const root = resolveRoot('run', values.root);
|
|
341
345
|
const nameCheck = checkFlowName(flowName);
|
|
@@ -382,13 +386,21 @@ async function cmdRun(rest) {
|
|
|
382
386
|
}
|
|
383
387
|
}
|
|
384
388
|
// M12 piece 2 (PRD ruling 2026-10-29): a job with a ticket-list input reads ONE ticket per run, picked by number. Refused at $0, by name, before anything is claimed.
|
|
385
|
-
|
|
389
|
+
// M13 piece 4: only a Tickets job (flow type) has a ticket list; the address is its Inputs line
|
|
390
|
+
const ticketLists = flowTypeOf(read.declaration) === 'tickets' ? ticketListsOf(read.arbiter) : {};
|
|
386
391
|
const ticketRoles = Object.keys(ticketLists);
|
|
387
392
|
if (ticketRoles.length > 1) fail(`run: flow "${flowName}" has more than one ticket list (${ticketRoles.join(', ')}); a run reads one. Nothing started.`);
|
|
388
393
|
if (values.anyway && values.ticket === undefined) fail(`run: --anyway belongs with --ticket <number>. Nothing started.`);
|
|
389
394
|
if (values.ticket !== undefined && ticketRoles.length === 0) fail(`run: --ticket ${values.ticket}, but flow "${flowName}" has no ticket-list input. Nothing started.`);
|
|
390
|
-
if (ticketRoles.length === 1 && values.ticket === undefined)
|
|
391
|
-
|
|
395
|
+
if (ticketRoles.length === 1 && values.ticket === undefined) {
|
|
396
|
+
// M13 piece 4 (R2): a by-hand run has no ticket # box; it reads the newest ticket that has not run yet. `--ticket` stays for the machine's own starts (the schedule, Run it anyway, a rerun).
|
|
397
|
+
const lookTool = (read.declaration.mcp?.tools ?? []).find((t) => t === LOOK_TOOL);
|
|
398
|
+
if (lookTool === undefined) fail(`run: flow "${flowName}" does not list ${LOOK_TOOL} among its signed tools, so the newest ticket cannot be found. Nothing started.`);
|
|
399
|
+
const next = await newestUnrunTicket({ flowDir: join(root, flowName), listUrl: ticketLists[ticketRoles[0]], mcp: { server: read.declaration.mcp.server, tool: lookTool } });
|
|
400
|
+
if (!next.ok) fail(`run: ${next.say.replace(/\.?$/, '.')} Nothing started.`);
|
|
401
|
+
values.ticket = String(next.number);
|
|
402
|
+
}
|
|
403
|
+
if (values.ticket !== undefined && !(/^[1-9][0-9]*$/.test(values.ticket) && isTicketNumber(Number(values.ticket)))) fail(`run: --ticket "${values.ticket}" is not a ticket number (${TICKET_NUMBER_WORDS}). Nothing started.`);
|
|
392
404
|
const sources = declaredRoles.map((role) => ({ id: role, path: parsedSources[role], ...(ticketRoles[0] === role ? { ticket: { number: Number(values.ticket), ...(values.anyway ? { anyway: true } : {}) } } : {}) }));
|
|
393
405
|
for (const src of sources) {
|
|
394
406
|
if (!Object.hasOwn(pages, src.id) && !existsSync(src.path)) fail(`run: source "${src.id}" is unreadable at ${src.path}`);
|
|
@@ -447,7 +459,7 @@ async function cmdRun(rest) {
|
|
|
447
459
|
// `freezeInputs` for this run dir, so a refusal leaves nothing behind.
|
|
448
460
|
const predictedInputs = sources.map((s) => ({ id: s.id, frozen: join(runDir, 'inputs', `${s.id}${extname(s.path)}`) }));
|
|
449
461
|
const allVerbs = [...new Set(declaration.steps.flatMap((s) => s.primitives ?? []))];
|
|
450
|
-
const { tools: primitives, reds: primitiveReds } = resolvePrimitives(catalogue, allVerbs, { runDir, inputs: predictedInputs });
|
|
462
|
+
const { tools: primitives, reds: primitiveReds } = resolvePrimitives(catalogue, allVerbs, { runDir, inputs: predictedInputs, mcp: stepMcp(declaration) });
|
|
451
463
|
|
|
452
464
|
const result = await runFlow({
|
|
453
465
|
root,
|
|
@@ -572,7 +584,7 @@ function cmdShow(rest) {
|
|
|
572
584
|
allowPositionals: true,
|
|
573
585
|
});
|
|
574
586
|
const [askId] = positionals;
|
|
575
|
-
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>]');
|
|
576
588
|
|
|
577
589
|
const root = resolveRoot('show', values.root);
|
|
578
590
|
const runDir = findRunDirByAskId(root, askId);
|
|
@@ -659,7 +671,7 @@ async function cmdResume(rest) {
|
|
|
659
671
|
});
|
|
660
672
|
const env = keyedEnv();
|
|
661
673
|
const runId = positionals[0];
|
|
662
|
-
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>]');
|
|
663
675
|
if (!values.flow) fail('resume: --flow <name> is required');
|
|
664
676
|
|
|
665
677
|
const root = resolveRoot('resume', values.root);
|
|
@@ -718,7 +730,7 @@ async function cmdResume(rest) {
|
|
|
718
730
|
// F46's unwired-verb preflight refusal now lives in `resumeRun` itself
|
|
719
731
|
// (`src/runner.js`) — this CLI no longer keeps a second copy of the check.
|
|
720
732
|
const { tools: primitives, reds: primitiveReds } = resolvePrimitives(catalogue, allVerbs, {
|
|
721
|
-
runDir, inputs: inputsManifest.map((m) => ({ id: m.id, frozen: m.frozen })),
|
|
733
|
+
runDir, inputs: inputsManifest.map((m) => ({ id: m.id, frozen: m.frozen })), mcp: stepMcp(declaration),
|
|
722
734
|
});
|
|
723
735
|
|
|
724
736
|
const result = await resumeRun({
|
|
@@ -758,7 +770,7 @@ async function cmdContinue(rest) {
|
|
|
758
770
|
});
|
|
759
771
|
const env = keyedEnv();
|
|
760
772
|
const runId = positionals[0];
|
|
761
|
-
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>]');
|
|
762
774
|
if (!values.flow) fail('continue: --flow <name> is required');
|
|
763
775
|
|
|
764
776
|
const root = resolveRoot('continue', values.root);
|
|
@@ -805,7 +817,7 @@ async function cmdContinue(rest) {
|
|
|
805
817
|
const inputsManifest = inputsRead.ok ? inputsRead.entries : [];
|
|
806
818
|
const allVerbs = [...new Set(declaration.steps.flatMap((s) => s.primitives ?? []))];
|
|
807
819
|
const { tools: primitives, reds: primitiveReds } = resolvePrimitives(catalogue, allVerbs, {
|
|
808
|
-
runDir, inputs: inputsManifest.map((m) => ({ id: m.id, frozen: m.frozen })),
|
|
820
|
+
runDir, inputs: inputsManifest.map((m) => ({ id: m.id, frozen: m.frozen })), mcp: stepMcp(declaration),
|
|
809
821
|
});
|
|
810
822
|
|
|
811
823
|
const result = await continueRun({
|
|
@@ -873,12 +885,22 @@ async function cmdDraft(rest) {
|
|
|
873
885
|
'no-questions': { type: 'boolean' },
|
|
874
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)
|
|
875
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' },
|
|
876
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.
|
|
877
893
|
// --thinking is the Chat "Thinking on" tick (drafting only; off unless given).
|
|
878
894
|
model: { type: 'string' }, provider: { type: 'string' }, thinking: { type: 'boolean' },
|
|
895
|
+
// M13 piece 4: the job's flow type (plain | mcp | tickets) and its MCP server, from the card; the tools come from that server's newest OK `check tools` (never a started server)
|
|
896
|
+
'flow-type': { type: 'string' }, mcp: { type: 'string' },
|
|
879
897
|
},
|
|
880
898
|
allowPositionals: true,
|
|
881
899
|
});
|
|
900
|
+
const flowType = values['flow-type'] ?? 'plain';
|
|
901
|
+
if (!['plain', 'mcp', 'tickets'].includes(flowType)) fail(`draft: --flow-type takes plain, mcp or tickets, got "${flowType}"`);
|
|
902
|
+
if (flowType === 'plain' && values.mcp !== undefined) fail('draft: --mcp goes with --flow-type mcp or tickets');
|
|
903
|
+
if (flowType !== 'plain' && !values.mcp) fail(`draft: --flow-type ${flowType} needs --mcp <server>`);
|
|
882
904
|
const keysLoad = keyedLoad();
|
|
883
905
|
const { env } = keysLoad;
|
|
884
906
|
const proseFile = positionals[0];
|
|
@@ -892,6 +914,21 @@ async function cmdDraft(rest) {
|
|
|
892
914
|
leftRules.push({ line: Number(m[1]), rule: Number(m[2]) });
|
|
893
915
|
}
|
|
894
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
|
+
|
|
895
932
|
let injected = {};
|
|
896
933
|
if (process.env.NODE_ENV === 'test' && process.env.FWDLOOP_TEST_DRAFT_PROVIDER) {
|
|
897
934
|
const mod = await import(pathToFileURL(resolve(process.env.FWDLOOP_TEST_DRAFT_PROVIDER)).href);
|
|
@@ -950,7 +987,11 @@ async function cmdDraft(rest) {
|
|
|
950
987
|
name: values.name,
|
|
951
988
|
noQuestions: values['no-questions'] === true,
|
|
952
989
|
...(leftRules.length ? { leftRules } : {}),
|
|
990
|
+
...(checkPicks === undefined ? {} : { checkPicks }),
|
|
991
|
+
...(carriedPicks === undefined ? {} : { carriedPicks }),
|
|
953
992
|
draftThinking: values.thinking === true ? 'on' : 'off',
|
|
993
|
+
flowType,
|
|
994
|
+
...(values.mcp ? { mcpServer: values.mcp } : {}),
|
|
954
995
|
env,
|
|
955
996
|
keyNames: keysLoad.keyNames,
|
|
956
997
|
...pick,
|
|
@@ -1005,7 +1046,7 @@ async function cmdSign(rest) {
|
|
|
1005
1046
|
});
|
|
1006
1047
|
if (!result.ok) fail(`sign refused — ${result.reds.join('; ')}`);
|
|
1007
1048
|
if (result.runId) {
|
|
1008
|
-
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`);
|
|
1009
1050
|
return;
|
|
1010
1051
|
}
|
|
1011
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.29.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.31.0",
|
|
55
55
|
"litectx": "^0.32.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
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
|
@@ -21,8 +21,9 @@ import path from 'node:path';
|
|
|
21
21
|
|
|
22
22
|
import { draft } from './drafter.js';
|
|
23
23
|
import { parseSignedText, unsignedAskTtls } from './signed-text.js';
|
|
24
|
-
import { validateDeclaration } from './declaration.js';
|
|
24
|
+
import { validateDeclaration, flowTypeOf } from './declaration.js';
|
|
25
25
|
import { factRows } from './citedcheck.js';
|
|
26
|
+
import { plainWords } from './checkwords.js';
|
|
26
27
|
import { sheetLineBlocks } from './sheetblock.js';
|
|
27
28
|
import { loadCatalogue } from './catalogue.js';
|
|
28
29
|
import { WIRED_VERBS } from './primitives.js';
|
|
@@ -38,6 +39,8 @@ import { hintsForRun, placeSpecOf } from './learnstore.js';
|
|
|
38
39
|
import { redactSecrets } from './redact.js';
|
|
39
40
|
import { sessionPriorSpend, writeDraftSpend } from './draftspend.js';
|
|
40
41
|
import { writeSetup } from './setup.js';
|
|
42
|
+
import { RECORD_FILE } from './pickrecord.js';
|
|
43
|
+
import { mcpPickHere } from './mcp-pick.js';
|
|
41
44
|
|
|
42
45
|
export const SPEC_HASH_FILE = 'spec.hash';
|
|
43
46
|
/** 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. */
|
|
@@ -87,7 +90,7 @@ export function specHash({
|
|
|
87
90
|
* answer file counts as no answer. No questions file = `{ questions: [], open: [] }`.
|
|
88
91
|
* @param {string} planDir
|
|
89
92
|
* 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`.
|
|
90
|
-
* @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}[] }}
|
|
93
|
+
* @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}[] }}
|
|
91
94
|
*/
|
|
92
95
|
export function readQuestions(planDir) {
|
|
93
96
|
const none = { questions: [], open: [] };
|
|
@@ -112,7 +115,7 @@ export function readQuestions(planDir) {
|
|
|
112
115
|
}
|
|
113
116
|
return {
|
|
114
117
|
k, line: q.line, question: String(q.question), answer, ...(at === undefined ? {} : { at }), ...(rule === undefined ? {} : { rule }),
|
|
115
|
-
...(q.source === 'look' ? { source: 'look', ask: q.ask, ruleNo: q.ruleNo, ruleText: q.ruleText, proposal: typeof q.proposal === 'string' ? q.proposal : null } : {}),
|
|
118
|
+
...(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 } : {}) } : {}),
|
|
116
119
|
};
|
|
117
120
|
});
|
|
118
121
|
return { questions, open: /** @type {any} */ (questions.filter((q) => q.answer === null)) };
|
|
@@ -196,6 +199,11 @@ export function buildReadout({
|
|
|
196
199
|
out.push(` ${s.role} = ${s.path}${h ? ` [headings: ${h.join(' | ') || 'none'}]` : ''}`);
|
|
197
200
|
}
|
|
198
201
|
// M12 piece 3: what is signed for MCP, from the declaration's typed fields (a job without them prints none of these rows)
|
|
202
|
+
// M13 piece 4: the flow type (the card's Flow type, signed with the job), in the card's own words; a declaration with no `flowType` (signed before M13) prints no such row
|
|
203
|
+
if (Object.hasOwn(declaration, 'flowType')) {
|
|
204
|
+
const flowType = flowTypeOf(declaration);
|
|
205
|
+
out.push(` flow type: ${flowType === 'mcp' ? 'MCP' : flowType === 'tickets' ? 'Tickets MCP' : 'plain'}`);
|
|
206
|
+
}
|
|
199
207
|
const mcp = declaration.mcp;
|
|
200
208
|
if (mcp && typeof mcp === 'object') out.push(` mcp: ${mcp.server} · tools: ${(mcp.tools ?? []).join(', ')}`);
|
|
201
209
|
const filter = declaration.ticketFilter;
|
|
@@ -217,6 +225,8 @@ export function buildReadout({
|
|
|
217
225
|
if (Array.isArray(st.close?.sheet)) for (const row of sheetBlocks.find((b) => b.line === st.fromLine)?.checked ?? []) out.push(` sheet check: ${row.text}`);
|
|
218
226
|
// M10 am8 item 2: the column lock, signed with the readout (typed fields)
|
|
219
227
|
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}`);
|
|
228
|
+
// M10 am16: the checks the person picked, signed with the readout, each in the one set of plain words (typed fields, never model prose)
|
|
229
|
+
if (Array.isArray(st.close?.shape?.picked)) for (const c of st.close.shape.picked) out.push(` you picked: ${plainWords(c)}`);
|
|
220
230
|
// M4e amendment 14 item 5: the check's sections in its order (+ word limit); fixed text from typed fields, never model prose.
|
|
221
231
|
const shape = st.close?.shape;
|
|
222
232
|
if (Array.isArray(shape?.sections) && shape.sections.length > 0) {
|
|
@@ -288,7 +298,8 @@ export function draftKeyRefusal(slot, env) {
|
|
|
288
298
|
* `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).
|
|
289
299
|
*/
|
|
290
300
|
export async function draftToDir({
|
|
291
|
-
proseFile, dir, root, name, slot, model, draftThinking = /** @type {'on'|'off'} */ ('off'), keyNames, env = process.env, provider, rates, modelId, noQuestions = false, onResult, fetchPage, leftRules, proseRead,
|
|
301
|
+
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,
|
|
302
|
+
flowType = /** @type {'plain'|'mcp'|'tickets'} */ ('plain'), mcpServer = /** @type {string|undefined} */ (undefined), mcpPick = /** @type {any} */ (undefined), mcpServers = /** @type {string[]|undefined} */ (undefined),
|
|
292
303
|
}) {
|
|
293
304
|
const refuse = (reds) => ({ ok: false, wrote: false, reds, costUsd: 0 });
|
|
294
305
|
const nameCheck = checkFlowName(name);
|
|
@@ -362,8 +373,13 @@ export async function draftToDir({
|
|
|
362
373
|
hintError = redactSecrets(String(e?.message ?? e)).split('\n')[0];
|
|
363
374
|
}
|
|
364
375
|
}
|
|
376
|
+
// 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
|
|
377
|
+
const mcp = flowType === 'plain' ? null : (mcpPick ?? (typeof mcpServer === 'string' ? mcpPickHere(mcpServer) : { ok: false, say: 'pick an MCP for this flow type' }));
|
|
378
|
+
/** @type {{picks: object[], kept: object[]}|null} */
|
|
379
|
+
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)
|
|
365
380
|
const result = await draft({
|
|
366
|
-
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 }),
|
|
381
|
+
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; },
|
|
382
|
+
flowType, mcp, ...(mcpServers === undefined ? {} : { mcpServers }),
|
|
367
383
|
});
|
|
368
384
|
if (result.stop === 'pre-flight') {
|
|
369
385
|
try { rmdirSync(dir); } catch { /* the claimed dir is still empty; leave it rather than mask the refusal */ }
|
|
@@ -394,6 +410,7 @@ export async function draftToDir({
|
|
|
394
410
|
// Amendments 24/25: the questions and the drafter's own "not checked" reading are written BEFORE log.json/spec.hash (the panel reads those
|
|
395
411
|
// two as "the draft finished"), as their own files: never in the readout, so never in the hash.
|
|
396
412
|
if (result.questions?.length) files[QUESTIONS_FILE] = scrub(dj({ questions: result.questions }), secrets);
|
|
413
|
+
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)
|
|
397
414
|
files[NOT_CHECKED_FILE] = scrub(dj({ notChecked: result.notChecked ?? [] }), secrets);
|
|
398
415
|
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);
|
|
399
416
|
files['log.json'] = scrub(dj({
|
package/src/canrun.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// verb with no wired implementation) is not offered. Reads only; writes nothing. `WIRED_VERBS` stays the one list (src/primitives.js).
|
|
4
4
|
import { WIRED_VERBS } from './primitives.js';
|
|
5
5
|
import { buildSoftgreenRubric } from './closers.js';
|
|
6
|
+
import { flowTypeOf } from './declaration.js';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* The first step granting a verb that has no wired implementation, or null. (A verb absent from the catalogue entirely is caught earlier,
|
|
@@ -25,21 +26,23 @@ export function unwiredRed(found) {
|
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
29
|
+
* M13 piece 4 (F105 rewritten): the first plan problem with the job's MCP tools, as the preflight sentence, or null. Two rules, both $0 and by name:
|
|
30
|
+
* a step may grant only a tool the job lists (`mcp.tools`); a generic MCP job (flowType `mcp`) needs at least one step granting at least one of them. A Tickets job's
|
|
31
|
+
* own tools (`issue_read`, `list_issues`) belong to the job (the frozen read and the look), so no step has to grant them. A job with no `mcp` block has nothing to check.
|
|
32
|
+
* @param {Record<string, any>} declaration `readFlow`'s declaration @returns {string|null}
|
|
31
33
|
*/
|
|
32
|
-
export function
|
|
33
|
-
const
|
|
34
|
-
if (!
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
34
|
+
export function findMcpPlanRed(declaration) {
|
|
35
|
+
const server = declaration.mcp?.server;
|
|
36
|
+
if (!server) return null;
|
|
37
|
+
const listed = new Set(Array.isArray(declaration.mcp.tools) ? declaration.mcp.tools : []);
|
|
38
|
+
for (const step of declaration.steps) {
|
|
39
|
+
const stray = (step.mcpTools ?? []).find((/** @type {string} */ t) => !listed.has(t));
|
|
40
|
+
if (stray !== undefined) return `preflight: step "${step.emits}" (line ${step.fromLine}) grants tool "${stray}", which the job does not list for server "${server}"`;
|
|
41
|
+
}
|
|
42
|
+
if (flowTypeOf(declaration) === 'mcp' && !declaration.steps.some((/** @type {any} */ s) => (s.mcpTools ?? []).length > 0)) {
|
|
43
|
+
return `preflight: MCP job (server "${server}") has no step that calls one of its tools`;
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
/** bareguard refuses a signed name or phrase past this many characters (rubric MAX_SIGNED_LEN). */
|
|
@@ -117,8 +120,8 @@ export function canFlowRun(read) {
|
|
|
117
120
|
if (!read || read.ok !== true) return { ok: false, red: String(read?.reds?.[0] ?? 'the flow does not read') };
|
|
118
121
|
const unwired = findUnwiredVerbStep(read.declaration);
|
|
119
122
|
if (unwired) return { ok: false, red: unwiredRed(unwired) };
|
|
120
|
-
const
|
|
121
|
-
if (
|
|
123
|
+
const mcpRed = findMcpPlanRed(read.declaration);
|
|
124
|
+
if (mcpRed) return { ok: false, red: mcpRed };
|
|
122
125
|
const unbuildable = findUnbuildableCheckStep(read.declaration);
|
|
123
126
|
if (unbuildable) return { ok: false, red: unbuildableRed(unbuildable), detail: unbuildable.why };
|
|
124
127
|
return { ok: true };
|
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 } 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;
|
|
@@ -53,6 +54,8 @@ export function checkedLines(declaration, { hasAsk = true, askLines, lines, csvR
|
|
|
53
54
|
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
55
|
if (Number.isInteger(shape.linesPerInvoice)) out.push(`The output comes in blocks of ${shape.linesPerInvoice} lines.`);
|
|
55
56
|
if (Array.isArray(shape.mustCarry) && shape.mustCarry.length > 0) out.push(`Every block carries: ${list(shape.mustCarry)}.`);
|
|
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(`You picked: ${plainWords(c)}.${keptChecks.some((k) => k.line === st.fromLine && plainWords(k.check) === plainWords(c)) ? ` (${keptWords})` : ''}`);
|
|
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.');
|