fwdloop 0.27.0 → 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 +27 -8
- package/package.json +2 -2
- package/src/authoring.js +11 -1
- package/src/canrun.js +19 -16
- package/src/config.js +18 -0
- package/src/declaration.js +32 -2
- package/src/drafter.js +29 -14
- package/src/flow.js +2 -1
- package/src/launcher.js +4 -2
- package/src/learnstore.js +2 -1
- 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 +19 -19
- package/src/panel/authorcard.js +35 -0
- package/src/panel/authorflows.js +18 -14
- package/src/panel/authortrigger.js +241 -84
- package/src/panel/data.js +89 -6
- package/src/panel/index.html +552 -157
- package/src/panel/jobgrid.js +127 -0
- package/src/panel/scheduler.js +8 -2
- package/src/panel/server.js +15 -6
- package/src/panel/settings.js +119 -4
- package/src/panel/tickets.js +12 -7
- package/src/primitives.js +34 -5
- package/src/runner.js +88 -15
- 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/authoring.d.ts +5 -1
- package/types/canrun.d.ts +5 -12
- package/types/config.d.ts +6 -0
- package/types/declaration.d.ts +8 -0
- package/types/drafter.d.ts +447 -38
- 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 +36 -0
- package/types/panel/authorcard.d.ts +11 -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/server.d.ts +5 -1
- package/types/panel/settings.d.ts +3 -2
- package/types/panel/tickets.d.ts +26 -4
- package/types/primitives.d.ts +15 -2
- package/types/runner.d.ts +112 -72
- 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/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,7 +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 } from '../src/ticket-shape.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';
|
|
58
61
|
|
|
59
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:
|
|
60
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`).
|
|
@@ -382,13 +385,21 @@ async function cmdRun(rest) {
|
|
|
382
385
|
}
|
|
383
386
|
}
|
|
384
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.
|
|
385
|
-
|
|
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) : {};
|
|
386
390
|
const ticketRoles = Object.keys(ticketLists);
|
|
387
391
|
if (ticketRoles.length > 1) fail(`run: flow "${flowName}" has more than one ticket list (${ticketRoles.join(', ')}); a run reads one. Nothing started.`);
|
|
388
392
|
if (values.anyway && values.ticket === undefined) fail(`run: --anyway belongs with --ticket <number>. Nothing started.`);
|
|
389
393
|
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
|
-
|
|
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.`);
|
|
392
403
|
const sources = declaredRoles.map((role) => ({ id: role, path: parsedSources[role], ...(ticketRoles[0] === role ? { ticket: { number: Number(values.ticket), ...(values.anyway ? { anyway: true } : {}) } } : {}) }));
|
|
393
404
|
for (const src of sources) {
|
|
394
405
|
if (!Object.hasOwn(pages, src.id) && !existsSync(src.path)) fail(`run: source "${src.id}" is unreadable at ${src.path}`);
|
|
@@ -447,7 +458,7 @@ async function cmdRun(rest) {
|
|
|
447
458
|
// `freezeInputs` for this run dir, so a refusal leaves nothing behind.
|
|
448
459
|
const predictedInputs = sources.map((s) => ({ id: s.id, frozen: join(runDir, 'inputs', `${s.id}${extname(s.path)}`) }));
|
|
449
460
|
const allVerbs = [...new Set(declaration.steps.flatMap((s) => s.primitives ?? []))];
|
|
450
|
-
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) });
|
|
451
462
|
|
|
452
463
|
const result = await runFlow({
|
|
453
464
|
root,
|
|
@@ -718,7 +729,7 @@ async function cmdResume(rest) {
|
|
|
718
729
|
// F46's unwired-verb preflight refusal now lives in `resumeRun` itself
|
|
719
730
|
// (`src/runner.js`) — this CLI no longer keeps a second copy of the check.
|
|
720
731
|
const { tools: primitives, reds: primitiveReds } = resolvePrimitives(catalogue, allVerbs, {
|
|
721
|
-
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),
|
|
722
733
|
});
|
|
723
734
|
|
|
724
735
|
const result = await resumeRun({
|
|
@@ -805,7 +816,7 @@ async function cmdContinue(rest) {
|
|
|
805
816
|
const inputsManifest = inputsRead.ok ? inputsRead.entries : [];
|
|
806
817
|
const allVerbs = [...new Set(declaration.steps.flatMap((s) => s.primitives ?? []))];
|
|
807
818
|
const { tools: primitives, reds: primitiveReds } = resolvePrimitives(catalogue, allVerbs, {
|
|
808
|
-
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),
|
|
809
820
|
});
|
|
810
821
|
|
|
811
822
|
const result = await continueRun({
|
|
@@ -876,9 +887,15 @@ async function cmdDraft(rest) {
|
|
|
876
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.
|
|
877
888
|
// --thinking is the Chat "Thinking on" tick (drafting only; off unless given).
|
|
878
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' },
|
|
879
892
|
},
|
|
880
893
|
allowPositionals: true,
|
|
881
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>`);
|
|
882
899
|
const keysLoad = keyedLoad();
|
|
883
900
|
const { env } = keysLoad;
|
|
884
901
|
const proseFile = positionals[0];
|
|
@@ -951,6 +968,8 @@ async function cmdDraft(rest) {
|
|
|
951
968
|
noQuestions: values['no-questions'] === true,
|
|
952
969
|
...(leftRules.length ? { leftRules } : {}),
|
|
953
970
|
draftThinking: values.thinking === true ? 'on' : 'off',
|
|
971
|
+
flowType,
|
|
972
|
+
...(values.mcp ? { mcpServer: values.mcp } : {}),
|
|
954
973
|
env,
|
|
955
974
|
keyNames: keysLoad.keyNames,
|
|
956
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. */
|
|
@@ -196,6 +197,11 @@ export function buildReadout({
|
|
|
196
197
|
out.push(` ${s.role} = ${s.path}${h ? ` [headings: ${h.join(' | ') || 'none'}]` : ''}`);
|
|
197
198
|
}
|
|
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
|
+
}
|
|
199
205
|
const mcp = declaration.mcp;
|
|
200
206
|
if (mcp && typeof mcp === 'object') out.push(` mcp: ${mcp.server} · tools: ${(mcp.tools ?? []).join(', ')}`);
|
|
201
207
|
const filter = declaration.ticketFilter;
|
|
@@ -289,6 +295,7 @@ export function draftKeyRefusal(slot, env) {
|
|
|
289
295
|
*/
|
|
290
296
|
export async function draftToDir({
|
|
291
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),
|
|
292
299
|
}) {
|
|
293
300
|
const refuse = (reds) => ({ ok: false, wrote: false, reds, costUsd: 0 });
|
|
294
301
|
const nameCheck = checkFlowName(name);
|
|
@@ -362,8 +369,11 @@ export async function draftToDir({
|
|
|
362
369
|
hintError = redactSecrets(String(e?.message ?? e)).split('\n')[0];
|
|
363
370
|
}
|
|
364
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' }));
|
|
365
374
|
const result = await draft({
|
|
366
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 }),
|
|
367
377
|
});
|
|
368
378
|
if (result.stop === 'pre-flight') {
|
|
369
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,
|
|
@@ -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/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
|
@@ -60,6 +60,7 @@ export const DECLARATION_FIELDS = Object.freeze([
|
|
|
60
60
|
'refused',
|
|
61
61
|
'inputFacts',
|
|
62
62
|
'mcp',
|
|
63
|
+
'flowType',
|
|
63
64
|
'ticketFilter',
|
|
64
65
|
'ticketWatch',
|
|
65
66
|
// step level
|
|
@@ -87,10 +88,38 @@ const VALID_CLASSES = Object.freeze(['green', 'softgreen', 'hitl']);
|
|
|
87
88
|
// an ask's position, an ask's TTL, the egress allow-list...").
|
|
88
89
|
const ARBITER_KEYS = Object.freeze(['cap', 'ask', 'ttl', 'send', 'source', 'trigger', 'skills']);
|
|
89
90
|
|
|
90
|
-
const TOP_LEVEL_ALLOWED = Object.freeze(['steps', 'guardrailClasses', 'unjudgeable', 'refused', 'inputFacts', 'mcp', 'ticketFilter', 'ticketWatch']);
|
|
91
|
+
const TOP_LEVEL_ALLOWED = Object.freeze(['steps', 'guardrailClasses', 'unjudgeable', 'refused', 'inputFacts', 'mcp', 'flowType', 'ticketFilter', 'ticketWatch']);
|
|
91
92
|
const STEP_ALLOWED = Object.freeze(['goal', 'primitives', 'reads', 'emits', 'fromLine', 'close', 'picks', 'mcpTools']);
|
|
92
93
|
const CLOSE_ALLOWED = Object.freeze(['class', 'shape', 'cited', 'columns', 'sheet']);
|
|
93
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
|
+
|
|
94
123
|
/** M12 piece 1a: the ONE shape of an MCP server or tool name in a job (the bridge names a tool `<server>_<tool>`). */
|
|
95
124
|
const MCP_NAME = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
|
96
125
|
|
|
@@ -769,6 +798,7 @@ export function validateDeclaration(declaration, context = {}) {
|
|
|
769
798
|
}
|
|
770
799
|
|
|
771
800
|
// --- M12 piece 1a: the job's MCP tools (optional) -------------------------------
|
|
801
|
+
checkFlowType(declaration, reds);
|
|
772
802
|
const mcpTools = checkMcp(declaration, reds);
|
|
773
803
|
checkTicketFilter(declaration, reds);
|
|
774
804
|
checkTicketWatch(declaration, reds);
|
|
@@ -1017,7 +1047,7 @@ export function validateDeclaration(declaration, context = {}) {
|
|
|
1017
1047
|
stepInfo.forEach((st, i) => {
|
|
1018
1048
|
const isSignedAskLine = st.fromLine !== null && signedAskLines.has(st.fromLine);
|
|
1019
1049
|
if (st.primitives.length === 0 && st.effectiveClass === 'hitl' && !isSignedAskLine) {
|
|
1020
|
-
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`);
|
|
1021
1051
|
}
|
|
1022
1052
|
});
|
|
1023
1053
|
|
package/src/drafter.js
CHANGED
|
@@ -20,8 +20,9 @@ import { capTooSmallText, usdText } from './draftspend.js';
|
|
|
20
20
|
import { parseSignedText, unsignedAskTtls } from './signed-text.js';
|
|
21
21
|
import { validateDeclaration, SHAPE_KEYS, checkGuardrailSums, guardrailWordsPerSection } from './declaration.js';
|
|
22
22
|
import { loadCatalogue } from './catalogue.js';
|
|
23
|
+
import { findMcpPlanRed } from './canrun.js';
|
|
23
24
|
import { WIRED_VERBS, wiredMenu } from './primitives.js';
|
|
24
|
-
import { ticketSourcesOf, ticketFactsLines, ticketSchemaParts, ticketReds, userMcpServers } from './ticket-draft.js';
|
|
25
|
+
import { ticketSourcesOf, ticketFactsLines, mcpFactsLines, ticketSchemaParts, ticketReds, userMcpServers } from './ticket-draft.js';
|
|
25
26
|
import { readInputFacts } from './input-facts.js';
|
|
26
27
|
import { freezePage } from './runner.js';
|
|
27
28
|
import { removeFrozenPages } from './flow.js';
|
|
@@ -130,12 +131,12 @@ const SHAPE_PROPS = Object.freeze({
|
|
|
130
131
|
/**
|
|
131
132
|
* The forced tool's parameter schema. `menu` = wiredMenu(). `sheets` (M10b piece 3, optional) = the drafting copy's table of each CSV input role: with it a step may carry
|
|
132
133
|
* `close.sheet`, and every column a check names is an enum of that sheet's exact header (src/sheetoffer.js); without it (no CSV input) no sheet property exists.
|
|
133
|
-
*
|
|
134
|
-
* @param {any[]} menu @param {{sheets?: Record<string, {header: string[]}>, ticket?: {
|
|
134
|
+
* M13 piece 4: `ticket` = `{flowType, tools}` for MCP (generic) and Tickets; then a step may carry `mcpTools` (an enum of the job's tools) and, for Tickets, the tool carries `ticketFilter` and `ticketWatch` (src/ticket-draft.js). The job's `mcp` block and `flowType` are set by code, never offered.
|
|
135
|
+
* @param {any[]} menu @param {{sheets?: Record<string, {header: string[]}>, ticket?: {flowType: 'mcp'|'tickets', tools: string[]}}} [o]
|
|
135
136
|
*/
|
|
136
137
|
export function buildDeclarationSchema(menu, { sheets, ticket } = {}) {
|
|
137
138
|
const sheetProp = sheets ? sheetChecksProp(sheets) : null;
|
|
138
|
-
const ticketParts = ticket ? ticketSchemaParts(ticket
|
|
139
|
+
const ticketParts = ticket ? ticketSchemaParts(ticket) : null;
|
|
139
140
|
const shapeProps = {};
|
|
140
141
|
for (const key of SHAPE_KEYS) {
|
|
141
142
|
if (!SHAPE_PROPS[key]) throw new Error(`schema: SHAPE_KEYS gained "${key}" — add its type to SHAPE_PROPS`);
|
|
@@ -244,7 +245,7 @@ export const QUESTIONS_PROMPT = [
|
|
|
244
245
|
].join('\n');
|
|
245
246
|
|
|
246
247
|
/** The declaration schema plus the optional `notChecked` (every try) and, on try 3 only, `questions`. Neither is in `required`. */
|
|
247
|
-
/** @param {any[]} menu @param {{questions?: boolean, sheets?: Record<string, {header: string[]}>|undefined, ticket?: {
|
|
248
|
+
/** @param {any[]} menu @param {{questions?: boolean, sheets?: Record<string, {header: string[]}>|undefined, ticket?: {flowType: 'mcp'|'tickets', tools: string[]}}} [o] */
|
|
248
249
|
export function buildRoundSchema(menu, { questions = false, sheets = undefined, ticket = undefined } = {}) {
|
|
249
250
|
const s = buildDeclarationSchema(menu, { sheets, ticket });
|
|
250
251
|
const extra = { notChecked: { type: 'array', items: { type: 'string' }, description: 'what the job asks for that no typed check verifies' } };
|
|
@@ -435,6 +436,8 @@ export async function draft({
|
|
|
435
436
|
draftDir = /** @type {string|null} */ (null), fetchPage = undefined, leftRules = /** @type {{line: number, rule: number}[]} */ ([]),
|
|
436
437
|
learnHints = /** @type {{text: string, ids: string[]}|null} */ (null),
|
|
437
438
|
mcpServers = /** @type {string[]|undefined} */ (undefined),
|
|
439
|
+
// M13 piece 4: the job's flow type and its MCP pick (`mcpPickFor`: `{ok, server, tools}`), both set by code from the card; the drafter is told them, never asked for them
|
|
440
|
+
flowType = /** @type {'plain'|'mcp'|'tickets'} */ ('plain'), mcp = /** @type {any} */ (null),
|
|
438
441
|
}) {
|
|
439
442
|
// What was asked of thinking and the WORST status bareagent reported across the rounds (the page says it loudly unless 'applied'). Read from the round log, the one record.
|
|
440
443
|
const thinkingOf = () => {
|
|
@@ -460,10 +463,12 @@ export async function draft({
|
|
|
460
463
|
// The file inputs are read first, at $0, before a provider is built (a page input is fetched only after the price and cap gates, below).
|
|
461
464
|
const fileFacts = readInputFacts((arbiter.sources ?? []).filter((s) => s.kind !== 'page'));
|
|
462
465
|
if (!fileFacts.ok) return fail(fileFacts.reds);
|
|
463
|
-
//
|
|
464
|
-
|
|
465
|
-
const
|
|
466
|
-
|
|
466
|
+
// M13 piece 4: with flow type Tickets, a GitHub issues list is a ticket role, not a page: never fetched at draft; the drafter is told it exists and may suggest a label filter.
|
|
467
|
+
// The job's flow type and MCP (server + every tool of its newest OK check) come from the card; the refusals are at $0, before any provider is built.
|
|
468
|
+
const ticketSources = flowType === 'tickets' ? ticketSourcesOf(arbiter.sources) : [];
|
|
469
|
+
const servers = flowType === 'plain' ? [] : (mcpServers ?? userMcpServers());
|
|
470
|
+
const flowReds = ticketReds({ flowType, ticketSources, pick: mcp, servers });
|
|
471
|
+
if (flowReds.length) return fail(flowReds);
|
|
467
472
|
|
|
468
473
|
let { provider, rates, modelId } = { provider: injected, rates: injectedRates, modelId: injectedModelId };
|
|
469
474
|
let prices = null; // the one price lookup's result (live provider only); the cap check below uses the SAME price
|
|
@@ -667,7 +672,7 @@ export async function draft({
|
|
|
667
672
|
}
|
|
668
673
|
// The page lines go on the drafter's list of inputs: the first line of a page's block replaces the plain line readInputFacts wrote for it.
|
|
669
674
|
const factsBase = pageInfo.length ? [...facts.info.filter((l) => !pageSources.some((s) => l.startsWith(`- ${s.role}: a web page`))), ...pageInfo] : facts.info;
|
|
670
|
-
const factsInfo = [...factsBase, ...ticketSources.flatMap((s) => ticketFactsLines(s.role,
|
|
675
|
+
const factsInfo = [...factsBase, ...ticketSources.flatMap((s) => ticketFactsLines(s.role)), ...(flowType === 'mcp' ? mcpFactsLines(mcp.server, mcp.tools) : [])];
|
|
671
676
|
|
|
672
677
|
// `notChecked` is offered on every try (information, not asking); `questions` only on try 3 (below).
|
|
673
678
|
// M10b piece 3: the drafting copy's table of each CSV input - the header the drafter may pick from, the table bareguard's sign-time test runs over
|
|
@@ -700,7 +705,7 @@ export async function draft({
|
|
|
700
705
|
// Amendment 25: a lock is a mechanism. Only try 3 of 3, and only when tries 1 and 2 BOTH failed validation (`revisions` counts the
|
|
701
706
|
// validator's refusals fed back), gets the `questions` property; the redraft after an answer passes offerQuestions:false and never does.
|
|
702
707
|
const askOpen = offerQuestions && revisions === MAX_REVISIONS;
|
|
703
|
-
const schema = buildRoundSchema(menu, { questions: askOpen, sheets: sheetTables, ticket:
|
|
708
|
+
const schema = buildRoundSchema(menu, { questions: askOpen, sheets: sheetTables, ticket: flowType === 'plain' ? undefined : { flowType, tools: mcp.tools } });
|
|
704
709
|
const tool = {
|
|
705
710
|
name: TOOL,
|
|
706
711
|
description: 'Emit the flow declaration over the granted primitives, or refuse lines you cannot serve.',
|
|
@@ -747,6 +752,9 @@ export async function draft({
|
|
|
747
752
|
: malformed ? `the tool call's arguments were not valid JSON (${malformed.error})`
|
|
748
753
|
: 'no usable tool call (text instead of the tool)';
|
|
749
754
|
entry.outcome = `structure: ${why}`;
|
|
755
|
+
// the raw answer is kept (log.json): the unparseable arguments as sent, else the model's text
|
|
756
|
+
if (typeof malformed?.rawArguments === 'string') entry.rawArguments = malformed.rawArguments;
|
|
757
|
+
else if (typeof result?.text === 'string' && result.text !== '') entry.rawText = result.text;
|
|
750
758
|
log.push(entry);
|
|
751
759
|
lastReds = [why];
|
|
752
760
|
// M4d am3 A3: a round cut off at the output cap before tries 1 and 2 are spent is a FAILED TRY, advancing the same counter a
|
|
@@ -776,6 +784,10 @@ export async function draft({
|
|
|
776
784
|
const { questions: rawQuestions, notChecked: rawNotChecked, ...captureRest } = /** @type {Record<string, any>} */ (captured);
|
|
777
785
|
/** @type {Record<string, any>} */
|
|
778
786
|
const declaration = { ...(askOpen ? captureRest : { ...captureRest, ...(rawQuestions === undefined ? {} : { questions: rawQuestions }) }), inputFacts: facts.inputFacts };
|
|
787
|
+
// M13 piece 4: the flow type and the job's MCP (server + every tool of the newest OK check, R1) are set by code; whatever the model sent for them is overwritten.
|
|
788
|
+
declaration.flowType = flowType;
|
|
789
|
+
if (flowType === 'plain') delete declaration.mcp;
|
|
790
|
+
else declaration.mcp = { server: mcp.server, tools: [...mcp.tools] };
|
|
779
791
|
// M6a amendment 1 (F50): the goal is the signed line, set by the machine; whatever the model sent is overwritten.
|
|
780
792
|
if (Array.isArray(declaration.steps)) {
|
|
781
793
|
declaration.steps = declaration.steps.map((st) => (isPlainObject(st) ? { ...st, goal: goalForLine(st.fromLine, lines) } : st));
|
|
@@ -791,18 +803,21 @@ export async function draft({
|
|
|
791
803
|
});
|
|
792
804
|
}
|
|
793
805
|
// M10b piece 4: `covers` (which ~ rules a check verifies) stays on the check and is signed; the validator checks it, the plan card shows it
|
|
794
|
-
const
|
|
806
|
+
const verdict1 = validateDeclaration(declaration, {
|
|
795
807
|
arbiter, lines, catalogue: validationCatalogue, wired: WIRED_VERBS, verbatimGoals: true, fitJobLine: true,
|
|
796
808
|
// M10 am7 item 1: the words of every cited fact are proved on the drafting copy of the page, against what the page-word map kept
|
|
797
809
|
sheetWords: sheetTables ? { headers: Object.fromEntries(Object.entries(sheetTables).map(([role, t]) => [role, t.header])), facts: sheetFacts.filter((f) => f.shape === 'column'), tables: sheetTables } : undefined,
|
|
798
810
|
pageWords: { texts: { ...(facts.docs ?? {}), ...Object.fromEntries(Object.entries(pages).map(([role, pg]) => [role, pg.text])) }, look: pageSources.length ? { facts: look.facts, dropped: look.dropped } : null, docs: docRolesOf(arbiter.sources) },
|
|
799
811
|
});
|
|
800
|
-
|
|
801
|
-
const
|
|
812
|
+
// M13 piece 4 (F105 rewritten): a generic MCP job whose steps call none of its tools is fed back like any validator red (the run would refuse it at $0, by the same sentence)
|
|
813
|
+
const planRed = verdict1.ok ? findMcpPlanRed(declaration) : null;
|
|
814
|
+
const verdict = planRed ? { ok: false, reds: [planRed] } : verdict1;
|
|
802
815
|
lastDecl = declaration;
|
|
803
816
|
const asked = askOpen ? normalizeQuestions(rawQuestions, failedLines) : { kept: [], dropped: [] };
|
|
804
817
|
extras = { questions: asked.kept, droppedQuestions: asked.dropped, notChecked: [...new Set([...pageNotChecked, ...cleanNotChecked(rawNotChecked), ...uncoveredRules(declaration, jobLines, Object.keys(facts.sheets ?? {}))])] };
|
|
805
818
|
if (asked.dropped.length) entry.droppedQuestions = asked.dropped;
|
|
819
|
+
// the declaration the model sent, as parsed, before any code overwrite (log.json keeps it per try)
|
|
820
|
+
entry.args = captured;
|
|
806
821
|
if (verdict.ok) {
|
|
807
822
|
entry.outcome = 'valid';
|
|
808
823
|
log.push(entry);
|
package/src/flow.js
CHANGED
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
} from 'node:fs';
|
|
26
26
|
import path from 'node:path';
|
|
27
27
|
|
|
28
|
+
import { compareNatural } from './natural.js';
|
|
28
29
|
import { parseSignedText } from './signed-text.js';
|
|
29
30
|
import { signFlow, verifyFlow } from './signature.js';
|
|
30
31
|
import { validateDeclaration } from './declaration.js';
|
|
@@ -251,7 +252,7 @@ export function listRunIds(flowDir) {
|
|
|
251
252
|
return entries
|
|
252
253
|
.filter((e) => e.isDirectory() && checkRunId(e.name).ok)
|
|
253
254
|
.map((e) => e.name)
|
|
254
|
-
.sort();
|
|
255
|
+
.sort(compareNatural);
|
|
255
256
|
}
|
|
256
257
|
|
|
257
258
|
/**
|
package/src/launcher.js
CHANGED
|
@@ -25,7 +25,7 @@ import { openAsker } from './prompts.js';
|
|
|
25
25
|
import { dirname, join } from 'node:path';
|
|
26
26
|
import { fileURLToPath } from 'node:url';
|
|
27
27
|
import { readConfig, updateConfig, configPath, defaultFlowsRoot, ConfigError } from './config.js';
|
|
28
|
-
import { keysHome, keysFilePath, createKeysFile } from './keysfile.js';
|
|
28
|
+
import { keysHome, keysFilePath, createKeysFile, isKeyName } from './keysfile.js';
|
|
29
29
|
import { openInOs } from './opener.js';
|
|
30
30
|
import { PLAIN, makePaint } from './tty-colour.js';
|
|
31
31
|
import { readOwnVersion } from './version.js';
|
|
@@ -307,7 +307,9 @@ export function runNpm(args, o = {}) {
|
|
|
307
307
|
const spawnImpl = o.spawnImpl ?? realSpawn;
|
|
308
308
|
return new Promise((resolve) => {
|
|
309
309
|
let child;
|
|
310
|
-
|
|
310
|
+
// M13 am1: npm and its install scripts get the shell's env without any `*_KEY` setting (`isKeyName`); only the panel spawn (startCmd) carries keys
|
|
311
|
+
const env = Object.fromEntries(Object.entries(process.env).filter(([n]) => !isKeyName(n)));
|
|
312
|
+
try { child = spawnImpl('npm', args, { shell: false, stdio: 'inherit', env }); } catch { resolve(1); return; }
|
|
311
313
|
let done = false;
|
|
312
314
|
const end = (/** @type {number} */ code) => { if (done) return; done = true; clearTimeout(timer); resolve(code); };
|
|
313
315
|
const timer = setTimeout(() => { try { child.kill('SIGTERM'); } catch { /* already gone */ } end(1); }, o.deadlineMs ?? NPM_DEADLINE_MS);
|
package/src/learnstore.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync, chmodSync } from 'node:fs';
|
|
11
11
|
import { join, dirname, resolve } from 'node:path';
|
|
12
12
|
import { homedir } from 'node:os';
|
|
13
|
+
import { compareNatural } from './natural.js';
|
|
13
14
|
import { configHome, configDoorHome, readConfig } from './config.js';
|
|
14
15
|
import { emptyLedger, redactDeep, countLedger, releasePending, recordHealth, buildCards, placeOf, renderHints } from './learn.js';
|
|
15
16
|
import { readAudit, readHistory } from './books.js';
|
|
@@ -316,7 +317,7 @@ export function seedLedger({ root, home }) {
|
|
|
316
317
|
} catch { out.skipped.unreadable += 1; }
|
|
317
318
|
}
|
|
318
319
|
}
|
|
319
|
-
todo.sort((a, b) => a.end.getTime() - b.end.getTime() || `${a.workflow}/${a.runId}
|
|
320
|
+
todo.sort((a, b) => a.end.getTime() - b.end.getTime() || compareNatural(`${a.workflow}/${a.runId}`, `${b.workflow}/${b.runId}`));
|
|
320
321
|
for (const t of todo) {
|
|
321
322
|
const cur = readLedger(home);
|
|
322
323
|
if (cur.problem) { out.problem = cur.problem; return out; }
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// M13 piece 3 (hamr 2026-10-31): the log of `check tools` presses, `mcp-checks.jsonl` beside config.json. APPEND-ONLY: each press appends one line, nothing is ever rewritten
|
|
2
|
+
// or removed. A line is `{server, path, at, ok, tools:[{name, hint}]}` or `{server, path, at, ok:false, error}`. The page shows the newest line per path and server.
|
|
3
|
+
// A torn or foreign line is skipped when reading, so a half-written last line never hides the earlier ones.
|
|
4
|
+
import { appendFileSync, mkdirSync, readFileSync } from 'node:fs';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { configHome } from './config.js';
|
|
7
|
+
|
|
8
|
+
export const MCP_CHECKS_FILE = 'mcp-checks.jsonl';
|
|
9
|
+
|
|
10
|
+
/** @param {string|undefined} home the config home */
|
|
11
|
+
export const mcpChecksFile = (home) => join(configHome(home), MCP_CHECKS_FILE);
|
|
12
|
+
|
|
13
|
+
/** append ONE line; throws when it cannot be written @param {string|undefined} home @param {Record<string, any>} entry */
|
|
14
|
+
export function appendMcpCheck(home, entry) {
|
|
15
|
+
mkdirSync(configHome(home), { recursive: true, mode: 0o700 });
|
|
16
|
+
appendFileSync(mcpChecksFile(home), `${JSON.stringify(entry)}\n`, { mode: 0o600 });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** every well-formed line, oldest first; none when the file is missing @param {string|undefined} home @returns {any[]} */
|
|
20
|
+
function checkLines(home) {
|
|
21
|
+
let text = '';
|
|
22
|
+
try { text = readFileSync(mcpChecksFile(home), 'utf8'); } catch { return []; }
|
|
23
|
+
const out = [];
|
|
24
|
+
for (const line of text.split('\n')) {
|
|
25
|
+
let r;
|
|
26
|
+
try { r = JSON.parse(line); } catch { continue; }
|
|
27
|
+
if (typeof r?.server !== 'string' || typeof r?.path !== 'string' || typeof r?.at !== 'string') continue;
|
|
28
|
+
out.push(r);
|
|
29
|
+
}
|
|
30
|
+
return out;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** the newest line per `path\tserver` @param {string|undefined} home @returns {Map<string, any>} */
|
|
34
|
+
export function newestMcpChecks(home) {
|
|
35
|
+
const out = new Map();
|
|
36
|
+
for (const r of checkLines(home)) out.set(`${r.path}\t${r.server}`, r);
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** M13 piece 4 (R1): the tool names of the newest OK line (with at least one tool) for this server at this path, or null @param {string|undefined} home @param {string} server @param {string} path @returns {string[]|null} */
|
|
41
|
+
export function newestOkMcpTools(home, server, path) {
|
|
42
|
+
/** @type {string[]|null} */
|
|
43
|
+
let tools = null;
|
|
44
|
+
for (const r of checkLines(home)) {
|
|
45
|
+
if (r.server !== server || r.path !== path || r.ok !== true || !Array.isArray(r.tools)) continue;
|
|
46
|
+
const names = r.tools.map((/** @type {any} */ x) => x?.name).filter((/** @type {unknown} */ n) => typeof n === 'string' && n !== '');
|
|
47
|
+
if (names.length > 0) tools = [...new Set(names)];
|
|
48
|
+
}
|
|
49
|
+
return tools;
|
|
50
|
+
}
|
package/src/mcp-pick.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// M13 piece 4 (hamr ruling R1, 2026-10-31): the ONE place that decides the tools a job gets from its MCP. A job with an MCP gets ALL the tools of that MCP's newest OK line in
|
|
2
|
+
// `mcp-checks.jsonl` (src/mcp-checks.js), set by code: never chosen by the drafter, never reviewed by the person, and no server is ever started here (a server starts only on
|
|
3
|
+
// a press of `check tools`). A tool the server gains later is not in the job (signed item 3). Read-only; writes nothing.
|
|
4
|
+
import { newestOkMcpTools } from './mcp-checks.js';
|
|
5
|
+
import { mcpSources, mcpConfigFor } from './mcp-sources.js';
|
|
6
|
+
import { configDoorHome, configHome } from './config.js';
|
|
7
|
+
import { remoteRefusal } from './ticket-mcp.js';
|
|
8
|
+
|
|
9
|
+
/** the one refusal for an MCP nobody has checked (or whose check never succeeded) */
|
|
10
|
+
export const NEVER_CHECKED_SAY = 'press check tools in Settings > MCP first';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {string} server @param {string|undefined|null} home the config home; undefined = the door's decision (`configDoorHome`: a test process with no `FWDLOOP_CONFIG_HOME` has none, so "never checked"; otherwise the default config home); null = none
|
|
14
|
+
* @returns {{ ok: true, server: string, tools: string[] } | { ok: false, say: string }}
|
|
15
|
+
*/
|
|
16
|
+
export function mcpPickFor(server, home) {
|
|
17
|
+
if (home === undefined) {
|
|
18
|
+
const door = configDoorHome();
|
|
19
|
+
if (door.skip) return { ok: false, say: NEVER_CHECKED_SAY };
|
|
20
|
+
home = configHome(door.home);
|
|
21
|
+
}
|
|
22
|
+
if (typeof home !== 'string') return { ok: false, say: NEVER_CHECKED_SAY };
|
|
23
|
+
const place = mcpSources({ home }).places.find((p) => p.servers.some((s) => s.name === server));
|
|
24
|
+
if (!place) return { ok: false, say: `${server} is not in any MCP config (Settings > MCP lists the ones found)` };
|
|
25
|
+
if (mcpConfigFor(server, { home })?.remote) return { ok: false, say: remoteRefusal(server) };
|
|
26
|
+
const tools = newestOkMcpTools(home, server, place.path);
|
|
27
|
+
return tools === null ? { ok: false, say: NEVER_CHECKED_SAY } : { ok: true, server, tools };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** `mcpPickFor` at the config home this process uses (a test process with no `FWDLOOP_CONFIG_HOME` has none) @param {string} server */
|
|
31
|
+
export function mcpPickHere(server) {
|
|
32
|
+
return mcpPickFor(server, undefined);
|
|
33
|
+
}
|