fwdloop 0.26.2 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/fwdloop +46 -7
- package/package.json +2 -2
- package/src/authoring.js +21 -1
- package/src/canrun.js +23 -0
- package/src/config.js +18 -0
- package/src/declaration.js +129 -3
- package/src/drafter.js +38 -10
- package/src/flow.js +2 -1
- package/src/launcher.js +4 -2
- package/src/learnstore.js +3 -2
- 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/natural.js +23 -0
- package/src/panel/author.js +17 -1
- package/src/panel/authorcard.js +35 -0
- package/src/panel/authorflows.js +15 -6
- package/src/panel/authorstart.js +10 -6
- package/src/panel/authortrigger.js +263 -82
- package/src/panel/data.js +127 -9
- package/src/panel/index.html +945 -94
- package/src/panel/jobgrid.js +127 -0
- package/src/panel/scheduler.js +48 -6
- package/src/panel/server.js +33 -8
- package/src/panel/settings.js +119 -4
- package/src/panel/tickets.js +118 -0
- package/src/primitives.js +34 -5
- package/src/runner.js +129 -15
- package/src/schedule.js +5 -0
- package/src/summary-words.js +27 -7
- package/src/ticket-draft.js +85 -0
- package/src/ticket-labels.js +75 -0
- package/src/ticket-mcp.js +89 -0
- package/src/ticket-next.js +33 -0
- package/src/ticket-shape.js +33 -0
- package/src/trigger-clock.js +4 -4
- package/src/trigger-files.js +4 -4
- package/src/trigger-line.js +2 -1
- package/src/trigger-tickets.js +238 -0
- package/types/authoring.d.ts +5 -1
- package/types/canrun.d.ts +7 -0
- package/types/config.d.ts +6 -0
- package/types/declaration.d.ts +8 -0
- package/types/drafter.d.ts +552 -21
- 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/natural.d.ts +2 -0
- package/types/panel/author.d.ts +44 -0
- package/types/panel/authorcard.d.ts +11 -0
- package/types/panel/authorflows.d.ts +11 -1
- package/types/panel/authorstart.d.ts +3 -1
- package/types/panel/authortrigger.d.ts +83 -7
- package/types/panel/data.d.ts +78 -5
- package/types/panel/jobgrid.d.ts +109 -0
- package/types/panel/scheduler.d.ts +7 -2
- package/types/panel/server.d.ts +13 -2
- package/types/panel/settings.d.ts +3 -2
- package/types/panel/tickets.d.ts +103 -0
- package/types/primitives.d.ts +15 -2
- package/types/runner.d.ts +133 -75
- package/types/summary-words.d.ts +24 -4
- package/types/ticket-draft.d.ts +104 -0
- package/types/ticket-labels.d.ts +42 -0
- package/types/ticket-mcp.d.ts +57 -0
- package/types/ticket-next.d.ts +23 -0
- package/types/ticket-shape.d.ts +30 -0
- package/types/trigger-clock.d.ts +4 -3
- package/types/trigger-files.d.ts +3 -1
- package/types/trigger-line.d.ts +7 -0
- package/types/trigger-tickets.d.ts +105 -0
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';
|
|
@@ -54,6 +54,10 @@ import { isInteractive, confirmTypedName, NEEDS_TTY } from '../src/sign-confirm.
|
|
|
54
54
|
import { draftToDir, draftKeyRefusal, signDraft, SIGN_LINE, costText, questionsRefusal } from '../src/authoring.js';
|
|
55
55
|
import { userInfo } from 'node:os';
|
|
56
56
|
import { pageAddressesOf, pageAddressRefusal } from '../src/pagefetch.js';
|
|
57
|
+
import { ticketListsOf, isTicketNumber, TICKET_NUMBER_WORDS } from '../src/ticket-shape.js';
|
|
58
|
+
import { flowTypeOf } from '../src/declaration.js';
|
|
59
|
+
import { LOOK_TOOL } from '../src/ticket-draft.js';
|
|
60
|
+
import { newestUnrunTicket } from '../src/ticket-next.js';
|
|
57
61
|
|
|
58
62
|
// 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:
|
|
59
63
|
// 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`).
|
|
@@ -305,6 +309,10 @@ function reportRunResult(result, { rootArg }) {
|
|
|
305
309
|
process.exitCode = 1;
|
|
306
310
|
return;
|
|
307
311
|
}
|
|
312
|
+
if (result.outcome === 'skipped') { // hamr 2026-10-30: a skip is a normal grey ending, not a failure
|
|
313
|
+
process.stdout.write(`skipped: spentUsd=${result.spentUsd}\n`);
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
308
316
|
process.stderr.write(`fwdloop: ${result.outcome}${result.red ? ` — ${result.red}` : ''}\n`);
|
|
309
317
|
process.exitCode = 1;
|
|
310
318
|
}
|
|
@@ -319,6 +327,8 @@ async function cmdRun(rest) {
|
|
|
319
327
|
options: {
|
|
320
328
|
root: { type: 'string' },
|
|
321
329
|
source: { type: 'string', multiple: true, default: [] },
|
|
330
|
+
ticket: { type: 'string' }, // M12: the one ticket of the job's ticket list this run reads, by number
|
|
331
|
+
anyway: { type: 'boolean' }, // M12 p3 (hamr 2026-10-30): this ticket came by "Run it anyway"; the run does not skip it for its labels or closed
|
|
322
332
|
'run-id': { type: 'string' },
|
|
323
333
|
// a job drafted before its model was recorded: the model it runs with (a ticked line); --provider only if two keys tick the same id
|
|
324
334
|
model: { type: 'string' }, provider: { type: 'string' },
|
|
@@ -334,6 +344,12 @@ async function cmdRun(rest) {
|
|
|
334
344
|
const nameCheck = checkFlowName(flowName);
|
|
335
345
|
if (!nameCheck.ok) fail(nameCheck.red);
|
|
336
346
|
|
|
347
|
+
// A refusal before the run starts must leave no run folder behind. The panel claims `run-<n>` (and may put the signed values in it) BEFORE it spawns this
|
|
348
|
+
// child, so EVERY exit before the run begins undoes it: registered here, at the first line that can fail, not after the checks (rmdir only ever removes an EMPTY folder).
|
|
349
|
+
const dropUnstartedRun = (dir) => process.on('exit', () => { dropUnstartedValues(dir); try { rmdirSync(dir); } catch { /* not empty, or gone: nothing to undo */ } });
|
|
350
|
+
const typedRun = typeof values['run-id'] === 'string' ? resolveRunDir(join(root, flowName), values['run-id']) : null;
|
|
351
|
+
if (typedRun?.ok) dropUnstartedRun(typedRun.runDir);
|
|
352
|
+
|
|
337
353
|
const loaded = loadCatalogue();
|
|
338
354
|
if (!loaded.ok) fail(`catalogue: ${loaded.reds.join('; ')}`);
|
|
339
355
|
const catalogue = loaded.primitives;
|
|
@@ -368,7 +384,23 @@ async function cmdRun(rest) {
|
|
|
368
384
|
fail(`run: --source role "${role}" is not declared by flow "${flowName}" (known roles: ${declaredRoles.join(', ') || '(none)'})`);
|
|
369
385
|
}
|
|
370
386
|
}
|
|
371
|
-
|
|
387
|
+
// 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.
|
|
388
|
+
// M13 piece 4: only a Tickets job (flow type) has a ticket list; the address is its Inputs line
|
|
389
|
+
const ticketLists = flowTypeOf(read.declaration) === 'tickets' ? ticketListsOf(read.arbiter) : {};
|
|
390
|
+
const ticketRoles = Object.keys(ticketLists);
|
|
391
|
+
if (ticketRoles.length > 1) fail(`run: flow "${flowName}" has more than one ticket list (${ticketRoles.join(', ')}); a run reads one. Nothing started.`);
|
|
392
|
+
if (values.anyway && values.ticket === undefined) fail(`run: --anyway belongs with --ticket <number>. Nothing started.`);
|
|
393
|
+
if (values.ticket !== undefined && ticketRoles.length === 0) fail(`run: --ticket ${values.ticket}, but flow "${flowName}" has no ticket-list input. Nothing started.`);
|
|
394
|
+
if (ticketRoles.length === 1 && values.ticket === undefined) {
|
|
395
|
+
// 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).
|
|
396
|
+
const lookTool = (read.declaration.mcp?.tools ?? []).find((t) => t === LOOK_TOOL);
|
|
397
|
+
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.`);
|
|
398
|
+
const next = await newestUnrunTicket({ flowDir: join(root, flowName), listUrl: ticketLists[ticketRoles[0]], mcp: { server: read.declaration.mcp.server, tool: lookTool } });
|
|
399
|
+
if (!next.ok) fail(`run: ${next.say.replace(/\.?$/, '.')} Nothing started.`);
|
|
400
|
+
values.ticket = String(next.number);
|
|
401
|
+
}
|
|
402
|
+
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.`);
|
|
403
|
+
const sources = declaredRoles.map((role) => ({ id: role, path: parsedSources[role], ...(ticketRoles[0] === role ? { ticket: { number: Number(values.ticket), ...(values.anyway ? { anyway: true } : {}) } } : {}) }));
|
|
372
404
|
for (const src of sources) {
|
|
373
405
|
if (!Object.hasOwn(pages, src.id) && !existsSync(src.path)) fail(`run: source "${src.id}" is unreadable at ${src.path}`);
|
|
374
406
|
}
|
|
@@ -383,6 +415,7 @@ async function cmdRun(rest) {
|
|
|
383
415
|
if (!claimed.ok) fail(claimed.red);
|
|
384
416
|
runId = claimed.runId;
|
|
385
417
|
runDir = claimed.runDir;
|
|
418
|
+
dropUnstartedRun(runDir);
|
|
386
419
|
} else {
|
|
387
420
|
const runIdCheck = resolveRunDir(join(root, flowName), runId);
|
|
388
421
|
if (!runIdCheck.ok) fail(runIdCheck.red);
|
|
@@ -394,8 +427,6 @@ async function cmdRun(rest) {
|
|
|
394
427
|
const applied = applyRunValues(read.arbiter, flowName, read.signature.flow, pickRunValues(runDir));
|
|
395
428
|
if (!applied.ok) fail(`run: ${applied.red}`);
|
|
396
429
|
const { arbiter } = applied;
|
|
397
|
-
// a refusal before the run starts must not leave the claimed empty folder behind (rmdir only ever removes an EMPTY folder)
|
|
398
|
-
process.on('exit', () => { dropUnstartedValues(runDir); try { rmdirSync(runDir); } catch { /* not empty, or gone: nothing to undo */ } });
|
|
399
430
|
|
|
400
431
|
// The key preflight (item A: "refuses at $0 BEFORE any book write") runs
|
|
401
432
|
// here — before ANY directory for this run is created.
|
|
@@ -427,7 +458,7 @@ async function cmdRun(rest) {
|
|
|
427
458
|
// `freezeInputs` for this run dir, so a refusal leaves nothing behind.
|
|
428
459
|
const predictedInputs = sources.map((s) => ({ id: s.id, frozen: join(runDir, 'inputs', `${s.id}${extname(s.path)}`) }));
|
|
429
460
|
const allVerbs = [...new Set(declaration.steps.flatMap((s) => s.primitives ?? []))];
|
|
430
|
-
const { tools: primitives, reds: primitiveReds } = resolvePrimitives(catalogue, allVerbs, { runDir, inputs: predictedInputs });
|
|
461
|
+
const { tools: primitives, reds: primitiveReds } = resolvePrimitives(catalogue, allVerbs, { runDir, inputs: predictedInputs, mcp: stepMcp(declaration) });
|
|
431
462
|
|
|
432
463
|
const result = await runFlow({
|
|
433
464
|
root,
|
|
@@ -698,7 +729,7 @@ async function cmdResume(rest) {
|
|
|
698
729
|
// F46's unwired-verb preflight refusal now lives in `resumeRun` itself
|
|
699
730
|
// (`src/runner.js`) — this CLI no longer keeps a second copy of the check.
|
|
700
731
|
const { tools: primitives, reds: primitiveReds } = resolvePrimitives(catalogue, allVerbs, {
|
|
701
|
-
runDir, inputs: inputsManifest.map((m) => ({ id: m.id, frozen: m.frozen })),
|
|
732
|
+
runDir, inputs: inputsManifest.map((m) => ({ id: m.id, frozen: m.frozen })), mcp: stepMcp(declaration),
|
|
702
733
|
});
|
|
703
734
|
|
|
704
735
|
const result = await resumeRun({
|
|
@@ -785,7 +816,7 @@ async function cmdContinue(rest) {
|
|
|
785
816
|
const inputsManifest = inputsRead.ok ? inputsRead.entries : [];
|
|
786
817
|
const allVerbs = [...new Set(declaration.steps.flatMap((s) => s.primitives ?? []))];
|
|
787
818
|
const { tools: primitives, reds: primitiveReds } = resolvePrimitives(catalogue, allVerbs, {
|
|
788
|
-
runDir, inputs: inputsManifest.map((m) => ({ id: m.id, frozen: m.frozen })),
|
|
819
|
+
runDir, inputs: inputsManifest.map((m) => ({ id: m.id, frozen: m.frozen })), mcp: stepMcp(declaration),
|
|
789
820
|
});
|
|
790
821
|
|
|
791
822
|
const result = await continueRun({
|
|
@@ -856,9 +887,15 @@ async function cmdDraft(rest) {
|
|
|
856
887
|
// 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.
|
|
857
888
|
// --thinking is the Chat "Thinking on" tick (drafting only; off unless given).
|
|
858
889
|
model: { type: 'string' }, provider: { type: 'string' }, thinking: { type: 'boolean' },
|
|
890
|
+
// 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)
|
|
891
|
+
'flow-type': { type: 'string' }, mcp: { type: 'string' },
|
|
859
892
|
},
|
|
860
893
|
allowPositionals: true,
|
|
861
894
|
});
|
|
895
|
+
const flowType = values['flow-type'] ?? 'plain';
|
|
896
|
+
if (!['plain', 'mcp', 'tickets'].includes(flowType)) fail(`draft: --flow-type takes plain, mcp or tickets, got "${flowType}"`);
|
|
897
|
+
if (flowType === 'plain' && values.mcp !== undefined) fail('draft: --mcp goes with --flow-type mcp or tickets');
|
|
898
|
+
if (flowType !== 'plain' && !values.mcp) fail(`draft: --flow-type ${flowType} needs --mcp <server>`);
|
|
862
899
|
const keysLoad = keyedLoad();
|
|
863
900
|
const { env } = keysLoad;
|
|
864
901
|
const proseFile = positionals[0];
|
|
@@ -931,6 +968,8 @@ async function cmdDraft(rest) {
|
|
|
931
968
|
noQuestions: values['no-questions'] === true,
|
|
932
969
|
...(leftRules.length ? { leftRules } : {}),
|
|
933
970
|
draftThinking: values.thinking === true ? 'on' : 'off',
|
|
971
|
+
flowType,
|
|
972
|
+
...(values.mcp ? { mcpServer: values.mcp } : {}),
|
|
934
973
|
env,
|
|
935
974
|
keyNames: keysLoad.keyNames,
|
|
936
975
|
...pick,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fwdloop",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.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,7 +49,7 @@
|
|
|
49
49
|
"NOTICE"
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"bare-agent": "^0.
|
|
52
|
+
"bare-agent": "^0.57.0",
|
|
53
53
|
"barebrowse": "^0.26.0",
|
|
54
54
|
"bareguard": "^0.26.0",
|
|
55
55
|
"litectx": "^0.32.0"
|
package/src/authoring.js
CHANGED
|
@@ -21,7 +21,7 @@ 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
26
|
import { sheetLineBlocks } from './sheetblock.js';
|
|
27
27
|
import { loadCatalogue } from './catalogue.js';
|
|
@@ -38,6 +38,7 @@ import { hintsForRun, placeSpecOf } from './learnstore.js';
|
|
|
38
38
|
import { redactSecrets } from './redact.js';
|
|
39
39
|
import { sessionPriorSpend, writeDraftSpend } from './draftspend.js';
|
|
40
40
|
import { writeSetup } from './setup.js';
|
|
41
|
+
import { mcpPickHere } from './mcp-pick.js';
|
|
41
42
|
|
|
42
43
|
export const SPEC_HASH_FILE = 'spec.hash';
|
|
43
44
|
/** 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. */
|
|
@@ -195,12 +196,27 @@ export function buildReadout({
|
|
|
195
196
|
const h = declaration.inputFacts?.[s.role];
|
|
196
197
|
out.push(` ${s.role} = ${s.path}${h ? ` [headings: ${h.join(' | ') || 'none'}]` : ''}`);
|
|
197
198
|
}
|
|
199
|
+
// M12 piece 3: what is signed for MCP, from the declaration's typed fields (a job without them prints none of these rows)
|
|
200
|
+
// 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
|
|
201
|
+
if (Object.hasOwn(declaration, 'flowType')) {
|
|
202
|
+
const flowType = flowTypeOf(declaration);
|
|
203
|
+
out.push(` flow type: ${flowType === 'mcp' ? 'MCP' : flowType === 'tickets' ? 'Tickets MCP' : 'plain'}`);
|
|
204
|
+
}
|
|
205
|
+
const mcp = declaration.mcp;
|
|
206
|
+
if (mcp && typeof mcp === 'object') out.push(` mcp: ${mcp.server} · tools: ${(mcp.tools ?? []).join(', ')}`);
|
|
207
|
+
const filter = declaration.ticketFilter;
|
|
208
|
+
if (filter && typeof filter === 'object') {
|
|
209
|
+
const parts = [...(filter.priority?.length ? [`priority ${filter.priority.join(', ')}`] : []), ...(filter.labels?.length ? [`labels ${filter.labels.join(', ')}`] : [])];
|
|
210
|
+
if (parts.length) out.push(` ticket filter: ${parts.join(' · ')}`);
|
|
211
|
+
}
|
|
212
|
+
if (Array.isArray(declaration.ticketWatch) && declaration.ticketWatch.length) out.push(` ticket watch: ${declaration.ticketWatch.join(', ')}`);
|
|
198
213
|
out.push('', READOUT_HEADS.steps);
|
|
199
214
|
const sheetBlocks = sheetLineBlocks({ declaration, lines });
|
|
200
215
|
declaration.steps.forEach((st, i) => {
|
|
201
216
|
out.push(` ${i + 1}. (line ${st.fromLine}) ${st.goal}`);
|
|
202
217
|
out.push(` grants: ${st.primitives?.length ? st.primitives.join(', ') : 'none (pure stop)'}`
|
|
203
218
|
+ ` | reads: ${st.reads?.length ? st.reads.join(', ') : '-'} | emits: ${st.emits} | check: ${st.close?.class}`);
|
|
219
|
+
if (Array.isArray(st.mcpTools) && st.mcpTools.length) out.push(` tools: ${st.mcpTools.join(', ')}`);
|
|
204
220
|
// M10 am7 item 1: the facts a cited step checks its quotes against, signed with the readout (typed fields, never model prose)
|
|
205
221
|
if (st.close?.cited && typeof st.close.cited === 'object') for (const row of factRows(st.close.cited)) out.push(` ${row}`);
|
|
206
222
|
// M10b piece 1: the signed sheet checks, one row each, written by code from the typed fields
|
|
@@ -279,6 +295,7 @@ export function draftKeyRefusal(slot, env) {
|
|
|
279
295
|
*/
|
|
280
296
|
export async function draftToDir({
|
|
281
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,
|
|
298
|
+
flowType = /** @type {'plain'|'mcp'|'tickets'} */ ('plain'), mcpServer = /** @type {string|undefined} */ (undefined), mcpPick = /** @type {any} */ (undefined), mcpServers = /** @type {string[]|undefined} */ (undefined),
|
|
282
299
|
}) {
|
|
283
300
|
const refuse = (reds) => ({ ok: false, wrote: false, reds, costUsd: 0 });
|
|
284
301
|
const nameCheck = checkFlowName(name);
|
|
@@ -352,8 +369,11 @@ export async function draftToDir({
|
|
|
352
369
|
hintError = redactSecrets(String(e?.message ?? e)).split('\n')[0];
|
|
353
370
|
}
|
|
354
371
|
}
|
|
372
|
+
// 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
|
+
const mcp = flowType === 'plain' ? null : (mcpPick ?? (typeof mcpServer === 'string' ? mcpPickHere(mcpServer) : { ok: false, say: 'pick an MCP for this flow type' }));
|
|
355
374
|
const result = await draft({
|
|
356
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 }),
|
|
376
|
+
flowType, mcp, ...(mcpServers === undefined ? {} : { mcpServers }),
|
|
357
377
|
});
|
|
358
378
|
if (result.stop === 'pre-flight') {
|
|
359
379
|
try { rmdirSync(dir); } catch { /* the claimed dir is still empty; leave it rather than mask the refusal */ }
|
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,
|
|
@@ -24,6 +25,26 @@ export function unwiredRed(found) {
|
|
|
24
25
|
return `preflight: step "${found.step.emits}" (line ${found.step.fromLine}) grants verb "${found.verb}", which has no wired implementation`;
|
|
25
26
|
}
|
|
26
27
|
|
|
28
|
+
/**
|
|
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}
|
|
33
|
+
*/
|
|
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;
|
|
46
|
+
}
|
|
47
|
+
|
|
27
48
|
/** bareguard refuses a signed name or phrase past this many characters (rubric MAX_SIGNED_LEN). */
|
|
28
49
|
const MAX_ENTRY_CHARS = 1000;
|
|
29
50
|
const SIGN_AGAIN = 'and sign the job again';
|
|
@@ -99,6 +120,8 @@ export function canFlowRun(read) {
|
|
|
99
120
|
if (!read || read.ok !== true) return { ok: false, red: String(read?.reds?.[0] ?? 'the flow does not read') };
|
|
100
121
|
const unwired = findUnwiredVerbStep(read.declaration);
|
|
101
122
|
if (unwired) return { ok: false, red: unwiredRed(unwired) };
|
|
123
|
+
const mcpRed = findMcpPlanRed(read.declaration);
|
|
124
|
+
if (mcpRed) return { ok: false, red: mcpRed };
|
|
102
125
|
const unbuildable = findUnbuildableCheckStep(read.declaration);
|
|
103
126
|
if (unbuildable) return { ok: false, red: unbuildableRed(unbuildable), detail: unbuildable.why };
|
|
104
127
|
return { ok: true };
|
package/src/config.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
// "prices": { "<slot>": { "inPerM": n, "cachedInPerM": n, "outPerM": n } }, // USD per 1M tokens, each optional; a saved "cachedInPerM" is tolerated, never read (M4d amendment 2)
|
|
7
7
|
// "providers": { "<KEY_NAME>": { "shape": "<shape id>", "baseUrl": "http(s)://…", "legacyMaxTokens": true|false } }, // each optional; a row is a key name from the keys file (M4d amendment 6). An older file's "model" is tolerated and read by nothing.
|
|
8
8
|
// "models": { "<KEY_NAME>": [ { "model": "<id>", "use": true|false, "inPerM": n, "outPerM": n } ] }, // M4d amendment 3 C: a price per model
|
|
9
|
+
// "mcpPaths": ["<path to an MCP config file>", …], // M13 piece 3: the paths added on Settings > MCP, in order (absolute or ~/…); the page's only writer is POST /api/settings/mcp-path
|
|
9
10
|
// "learningHints": true|false } // M8 am1: absent = false; the drafter is handed earlier runs' notes only when true (src/learnstore.js learningHintsOn). No control on the Settings page.
|
|
10
11
|
// A models line's price is a PAIR or nothing (`modelsProblem` is the one rule): 0 / 0 typed is a chosen price, a
|
|
11
12
|
// ticked line needs both, a half pair is refused. A slot with no list is migrated on READ (`effectiveModels` in
|
|
@@ -129,6 +130,18 @@ export function providerFieldProblem(field, v) {
|
|
|
129
130
|
* // borrowed-from: bareloop src/config.js@v0.48.0 (ed3a110) */
|
|
130
131
|
export const cleanBaseUrl = (v) => v.replace(/(?<!\/)\/+$/, '');
|
|
131
132
|
|
|
133
|
+
/**
|
|
134
|
+
* M13 piece 3: why a typed MCP config path cannot be kept in `mcpPaths`, or null: one rule for the Settings route and for the config reader.
|
|
135
|
+
* Absolute or `~/…`, one line of at most 500 characters.
|
|
136
|
+
* @param {unknown} p
|
|
137
|
+
*/
|
|
138
|
+
export function mcpPathProblem(p) {
|
|
139
|
+
if (typeof p !== 'string' || p.trim() === '') return 'must be a path to an MCP config file';
|
|
140
|
+
if (p.length > 500 || /[\0\r\n]/.test(p)) return 'must be one line of at most 500 characters';
|
|
141
|
+
if (!(p.startsWith('/') || p.startsWith('~/'))) return 'must start with / or ~/';
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
|
|
132
145
|
const isPrice = (v) => typeof v === 'number' && Number.isFinite(v) && v > 0;
|
|
133
146
|
|
|
134
147
|
/**
|
|
@@ -198,6 +211,11 @@ function validateDoc(doc) {
|
|
|
198
211
|
if (doc.learningHints !== undefined && typeof doc.learningHints !== 'boolean') {
|
|
199
212
|
throw new ConfigError('learningHints must be true or false');
|
|
200
213
|
}
|
|
214
|
+
if (doc.mcpPaths !== undefined) {
|
|
215
|
+
if (!Array.isArray(doc.mcpPaths)) throw new ConfigError('mcpPaths must be a list of paths');
|
|
216
|
+
doc.mcpPaths.forEach((p, i) => { const why = mcpPathProblem(p); if (why) throw new ConfigError(`mcpPaths.${i} ${why}`); });
|
|
217
|
+
if (new Set(doc.mcpPaths).size !== doc.mcpPaths.length) throw new ConfigError('mcpPaths holds a path twice');
|
|
218
|
+
}
|
|
201
219
|
validateProviders(doc.providers);
|
|
202
220
|
validateModels(doc.models);
|
|
203
221
|
if (doc.prices === undefined) return;
|
package/src/declaration.js
CHANGED
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
// No `new RegExp` anywhere in this file — a test in test/signed-text.test.js
|
|
37
37
|
// greps all of src/ for that, and it must keep passing with this file added.
|
|
38
38
|
|
|
39
|
+
import { WATCHABLE } from './ticket-shape.js';
|
|
39
40
|
import { buildSoftgreenRubric, isCellsPath } from './closers.js';
|
|
40
41
|
import { factPartReds } from './citedcheck.js';
|
|
41
42
|
import { numberRuleReds, countReds, citedWordReds } from './citedwords.js';
|
|
@@ -58,6 +59,10 @@ export const DECLARATION_FIELDS = Object.freeze([
|
|
|
58
59
|
'unjudgeable',
|
|
59
60
|
'refused',
|
|
60
61
|
'inputFacts',
|
|
62
|
+
'mcp',
|
|
63
|
+
'flowType',
|
|
64
|
+
'ticketFilter',
|
|
65
|
+
'ticketWatch',
|
|
61
66
|
// step level
|
|
62
67
|
'goal',
|
|
63
68
|
'primitives',
|
|
@@ -66,6 +71,7 @@ export const DECLARATION_FIELDS = Object.freeze([
|
|
|
66
71
|
'fromLine',
|
|
67
72
|
'close',
|
|
68
73
|
'picks',
|
|
74
|
+
'mcpTools',
|
|
69
75
|
// close level
|
|
70
76
|
'class',
|
|
71
77
|
'shape',
|
|
@@ -82,10 +88,111 @@ const VALID_CLASSES = Object.freeze(['green', 'softgreen', 'hitl']);
|
|
|
82
88
|
// an ask's position, an ask's TTL, the egress allow-list...").
|
|
83
89
|
const ARBITER_KEYS = Object.freeze(['cap', 'ask', 'ttl', 'send', 'source', 'trigger', 'skills']);
|
|
84
90
|
|
|
85
|
-
const TOP_LEVEL_ALLOWED = Object.freeze(['steps', 'guardrailClasses', 'unjudgeable', 'refused', 'inputFacts']);
|
|
86
|
-
const STEP_ALLOWED = Object.freeze(['goal', 'primitives', 'reads', 'emits', 'fromLine', 'close', 'picks']);
|
|
91
|
+
const TOP_LEVEL_ALLOWED = Object.freeze(['steps', 'guardrailClasses', 'unjudgeable', 'refused', 'inputFacts', 'mcp', 'flowType', 'ticketFilter', 'ticketWatch']);
|
|
92
|
+
const STEP_ALLOWED = Object.freeze(['goal', 'primitives', 'reads', 'emits', 'fromLine', 'close', 'picks', 'mcpTools']);
|
|
87
93
|
const CLOSE_ALLOWED = Object.freeze(['class', 'shape', 'cited', 'columns', 'sheet']);
|
|
88
94
|
|
|
95
|
+
/** M13 piece 4 (signed item 4): the job's flow type, set by code from the job card, signed with the job. */
|
|
96
|
+
export const FLOW_TYPES = Object.freeze(['plain', 'mcp', 'tickets']);
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* M13 piece 4: the ONE reader of a job's flow type. The field when present; a job signed before it existed (M12 shape: an `mcp` block, no `flowType`) is a Tickets
|
|
100
|
+
* job, since M12 only had ticket jobs; no `mcp` block is plain.
|
|
101
|
+
* @param {Record<string, any>} declaration @returns {'plain'|'mcp'|'tickets'}
|
|
102
|
+
*/
|
|
103
|
+
export function flowTypeOf(declaration) {
|
|
104
|
+
if (typeof declaration?.flowType === 'string' && FLOW_TYPES.includes(declaration.flowType)) return /** @type {any} */ (declaration.flowType);
|
|
105
|
+
return declaration?.mcp ? 'tickets' : 'plain';
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** M13 piece 4: `flowType` (optional on a job signed before M13) must be one of the three, and agree with the `mcp` block.
|
|
109
|
+
* @param {Record<string, any>} declaration @param {string[]} reds */
|
|
110
|
+
function checkFlowType(declaration, reds) {
|
|
111
|
+
if (!Object.hasOwn(declaration, 'flowType')) return;
|
|
112
|
+
const t = declaration.flowType;
|
|
113
|
+
if (typeof t !== 'string' || !FLOW_TYPES.includes(t)) { reds.push('declaration: flowType must be plain, mcp or tickets'); return; }
|
|
114
|
+
const hasMcp = Object.hasOwn(declaration, 'mcp');
|
|
115
|
+
if (t === 'plain' && hasMcp) reds.push('declaration: flowType "plain" takes no "mcp" server');
|
|
116
|
+
if (t !== 'plain' && !hasMcp) reds.push(`declaration: flowType "${t}" needs an "mcp" server`);
|
|
117
|
+
if (t !== 'tickets') {
|
|
118
|
+
if (Object.hasOwn(declaration, 'ticketFilter')) reds.push('declaration: "ticketFilter" belongs to a Tickets MCP job');
|
|
119
|
+
if (Object.hasOwn(declaration, 'ticketWatch')) reds.push('declaration: "ticketWatch" belongs to a Tickets MCP job');
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** M12 piece 1a: the ONE shape of an MCP server or tool name in a job (the bridge names a tool `<server>_<tool>`). */
|
|
124
|
+
const MCP_NAME = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
|
125
|
+
|
|
126
|
+
/** M12 piece 1a: the job's typed MCP tools, `mcp: {server, tools}`, optional (a job without it is unchanged). Returns the tool list when valid, else null.
|
|
127
|
+
* @param {Record<string, any>} declaration @param {string[]} reds @returns {string[]|null} */
|
|
128
|
+
function checkMcp(declaration, reds) {
|
|
129
|
+
if (!Object.hasOwn(declaration, 'mcp')) return null;
|
|
130
|
+
const m = declaration.mcp;
|
|
131
|
+
if (!isPlainObject(m)) {
|
|
132
|
+
reds.push('declaration: "mcp" must be an object {server, tools}');
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
const before = reds.length;
|
|
136
|
+
for (const key of Object.keys(m)) {
|
|
137
|
+
if (key !== 'server' && key !== 'tools') reds.push(`declaration: unknown key "${key}" at declaration.mcp.${key}`);
|
|
138
|
+
}
|
|
139
|
+
if (typeof m.server !== 'string' || !MCP_NAME.test(m.server)) reds.push('declaration: mcp.server must be a plain server name (letters, digits, _ or -)');
|
|
140
|
+
if (!Array.isArray(m.tools) || m.tools.length === 0) {
|
|
141
|
+
reds.push('declaration: mcp.tools must be a non-empty list of tool names');
|
|
142
|
+
} else {
|
|
143
|
+
const seen = new Set();
|
|
144
|
+
for (const t of m.tools) {
|
|
145
|
+
if (typeof t !== 'string' || !MCP_NAME.test(t)) reds.push(`declaration: mcp.tools names ${JSON.stringify(t)}, which is not a plain tool name`);
|
|
146
|
+
else if (seen.has(t)) reds.push(`declaration: mcp.tools names "${t}" twice`);
|
|
147
|
+
else seen.add(t);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return reds.length === before ? m.tools : null;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** M12 piece 3 (item 4): the signed label filter, `ticketFilter: {priority?: ['P0'..'P3'], labels?: [names]}`; optional, and only on a job that lists MCP tools.
|
|
154
|
+
* Pure data: code decides at run (src/ticket-labels.js); the drafter may only suggest it and a human signs it.
|
|
155
|
+
* @param {Record<string, any>} declaration @param {string[]} reds */
|
|
156
|
+
function checkTicketFilter(declaration, reds) {
|
|
157
|
+
if (!Object.hasOwn(declaration, 'ticketFilter')) return;
|
|
158
|
+
const f = declaration.ticketFilter;
|
|
159
|
+
if (!isPlainObject(f) || Object.keys(f).length === 0) {
|
|
160
|
+
reds.push('declaration: "ticketFilter" must be an object with "priority" and/or "labels"');
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (!Object.hasOwn(declaration, 'mcp')) reds.push('declaration: "ticketFilter" filters tickets read through the job\'s "mcp" tools, but the job lists no "mcp" server');
|
|
164
|
+
for (const key of Object.keys(f)) {
|
|
165
|
+
if (key !== 'priority' && key !== 'labels') reds.push(`declaration: unknown key "${key}" at declaration.ticketFilter.${key}`);
|
|
166
|
+
}
|
|
167
|
+
/** @type {Array<['priority'|'labels', (v: string) => boolean]>} */
|
|
168
|
+
const lists = [['priority', (v) => /^P[0-3]$/.test(v)], ['labels', (v) => v.trim() !== '' && v.length <= 100]];
|
|
169
|
+
for (const [key, ok] of lists) {
|
|
170
|
+
if (!Object.hasOwn(f, key)) continue;
|
|
171
|
+
if (!Array.isArray(f[key]) || f[key].length === 0) { reds.push(`declaration: ticketFilter.${key} must be a non-empty list`); continue; }
|
|
172
|
+
const seen = new Set();
|
|
173
|
+
for (const v of f[key]) {
|
|
174
|
+
if (typeof v !== 'string' || !ok(v)) reds.push(`declaration: ticketFilter.${key} names ${JSON.stringify(v)}, which is not ${key === 'priority' ? 'a priority from P0 to P3' : 'a label name (1 to 100 characters)'}`);
|
|
175
|
+
else if (seen.has(v.toLowerCase())) reds.push(`declaration: ticketFilter.${key} names "${v}" twice`);
|
|
176
|
+
else seen.add(v.toLowerCase());
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** M12 piece 3 (signed item 7): the ticket fields a schedule may watch, `ticketWatch: ['state'|'labels']`; optional, only on a job that lists MCP tools, typed values only.
|
|
182
|
+
* The scheduler compares (src/trigger-tickets.js); the drafter may suggest, a human signs. @param {Record<string, any>} declaration @param {string[]} reds */
|
|
183
|
+
function checkTicketWatch(declaration, reds) {
|
|
184
|
+
if (!Object.hasOwn(declaration, 'ticketWatch')) return;
|
|
185
|
+
const w = declaration.ticketWatch;
|
|
186
|
+
if (!Array.isArray(w) || w.length === 0) { reds.push(`declaration: "ticketWatch" must be a non-empty list of fields (${WATCHABLE.join(' and ')})`); return; }
|
|
187
|
+
if (!Object.hasOwn(declaration, 'mcp')) reds.push('declaration: "ticketWatch" watches tickets read through the job\'s "mcp" tools, but the job lists no "mcp" server');
|
|
188
|
+
const seen = new Set();
|
|
189
|
+
for (const f of w) {
|
|
190
|
+
if (typeof f !== 'string' || !WATCHABLE.includes(f)) reds.push(`declaration: ticketWatch names ${JSON.stringify(f)}, which is not a field that can be watched (${WATCHABLE.join(' and ')})`);
|
|
191
|
+
else if (seen.has(f)) reds.push(`declaration: ticketWatch names "${f}" twice`);
|
|
192
|
+
else seen.add(f);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
89
196
|
/** @returns {value is Record<string, any>} */
|
|
90
197
|
function isPlainObject(value) {
|
|
91
198
|
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
@@ -690,6 +797,12 @@ export function validateDeclaration(declaration, context = {}) {
|
|
|
690
797
|
reds.push('declaration: "inputFacts" must be an object keyed by source role');
|
|
691
798
|
}
|
|
692
799
|
|
|
800
|
+
// --- M12 piece 1a: the job's MCP tools (optional) -------------------------------
|
|
801
|
+
checkFlowType(declaration, reds);
|
|
802
|
+
const mcpTools = checkMcp(declaration, reds);
|
|
803
|
+
checkTicketFilter(declaration, reds);
|
|
804
|
+
checkTicketWatch(declaration, reds);
|
|
805
|
+
|
|
693
806
|
// --- steps ------------------------------------------------------------------
|
|
694
807
|
const emitSeen = new Set();
|
|
695
808
|
const declaredEmits = new Set();
|
|
@@ -719,6 +832,19 @@ export function validateDeclaration(declaration, context = {}) {
|
|
|
719
832
|
}
|
|
720
833
|
}
|
|
721
834
|
|
|
835
|
+
// M12 piece 1a: the MCP tools this step uses (optional); each must be one the job lists
|
|
836
|
+
if (Object.hasOwn(step, 'mcpTools')) {
|
|
837
|
+
if (!Array.isArray(step.mcpTools)) {
|
|
838
|
+
reds.push(`declaration: ${label}.mcpTools must be a list of the job's MCP tool names`);
|
|
839
|
+
} else if (!Object.hasOwn(declaration, 'mcp')) {
|
|
840
|
+
reds.push(`declaration: ${label}.mcpTools names tools, but the job lists no "mcp" server`);
|
|
841
|
+
} else if (mcpTools) {
|
|
842
|
+
for (const t of step.mcpTools) {
|
|
843
|
+
if (!mcpTools.includes(t)) reds.push(`declaration: ${label}.mcpTools names "${t}", which the job's mcp.tools does not list`);
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
|
|
722
848
|
// primitives
|
|
723
849
|
const primitives = Array.isArray(step.primitives) ? step.primitives : null;
|
|
724
850
|
if (primitives === null) {
|
|
@@ -921,7 +1047,7 @@ export function validateDeclaration(declaration, context = {}) {
|
|
|
921
1047
|
stepInfo.forEach((st, i) => {
|
|
922
1048
|
const isSignedAskLine = st.fromLine !== null && signedAskLines.has(st.fromLine);
|
|
923
1049
|
if (st.primitives.length === 0 && st.effectiveClass === 'hitl' && !isSignedAskLine) {
|
|
924
|
-
reds.push(`declaration: steps[${i}] (line ${st.fromLine}) is a pause (no primitives, hitl) at an unsigned line`);
|
|
1050
|
+
reds.push(`declaration: steps[${i}] (line ${st.fromLine}) is a pause (no primitives, hitl) at an unsigned line: grant it "read" (or the verb it needs), or make the line an Ask`);
|
|
925
1051
|
}
|
|
926
1052
|
});
|
|
927
1053
|
|