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
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// M13 piece 3 (docs/wiki/the-module-ladder.md, M13 scope items 1 and 2): the ONE place that decides where fwdloop's MCP servers come from.
|
|
2
|
+
// Sources, in order: the 4 places bare-agent reads, then the paths the person added on Settings > MCP (config.json `mcpPaths`, in the order added).
|
|
3
|
+
// A project folder's `.mcp.json` is never read: every path here is explicit, bare-agent's default discovery is never called (F108 c).
|
|
4
|
+
// bare-agent's `discoverServers` is called once PER PATH (it merges silently and keeps no file of origin, F108 a); the merge, "first wins" and the shadow mark are done here.
|
|
5
|
+
// A server with no `command` (a remote one) is listed and marked `remote`: it is never started. This file only READS the config files and
|
|
6
|
+
// returns names, flags and file paths; a command, its args and its env are never copied out of `discoverServers`' result.
|
|
7
|
+
import { discoverServers } from 'bare-agent/mcp';
|
|
8
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
9
|
+
import { homedir } from 'node:os';
|
|
10
|
+
import { join } from 'node:path';
|
|
11
|
+
import { readConfig, configDoorHome, ConfigError } from './config.js';
|
|
12
|
+
|
|
13
|
+
export { mcpPathProblem } from './config.js';
|
|
14
|
+
|
|
15
|
+
/** the 4 places bare-agent reads, in its order (absolute) */
|
|
16
|
+
export const DEFAULT_MCP_PLACES = () => {
|
|
17
|
+
const h = homedir();
|
|
18
|
+
return [join(h, '.mcp.json'), join(h, '.claude', 'mcp_servers.json'), join(h, '.config', 'Claude', 'claude_desktop_config.json'), join(h, '.cursor', 'mcp.json')];
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** a typed path as a real one: `~/` is the home folder @param {string} p */
|
|
22
|
+
export const expandMcpPath = (p) => (p === '~' ? homedir() : p.startsWith('~/') ? join(homedir(), p.slice(2)) : p);
|
|
23
|
+
|
|
24
|
+
/** a path as the page shows it: the home folder written `~` @param {string} p */
|
|
25
|
+
export const showMcpPath = (p) => { const h = homedir(); return p === h ? '~' : p.startsWith(`${h}/`) ? `~${p.slice(h.length)}` : p; };
|
|
26
|
+
|
|
27
|
+
/** the added paths in config.json (typed form); none under a test process with no config home, or when config.json is broken (the page says so) @param {string} [home] */
|
|
28
|
+
export function addedMcpPaths(home) {
|
|
29
|
+
let h = home;
|
|
30
|
+
if (h === undefined) { const door = configDoorHome(); if (door.skip) return { paths: [], problem: null }; h = door.home; }
|
|
31
|
+
try {
|
|
32
|
+
const c = readConfig({ home: h });
|
|
33
|
+
return { paths: Array.isArray(c.mcpPaths) ? /** @type {string[]} */ (c.mcpPaths) : [], problem: null };
|
|
34
|
+
} catch (e) {
|
|
35
|
+
if (!(e instanceof ConfigError)) throw e;
|
|
36
|
+
return { paths: [], problem: 'Your settings file (config.json) cannot be read, so added paths are not shown.' };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Every place, in order, with the servers found in it.
|
|
42
|
+
* `status`: 'found' (a readable file), 'missing' (no file) or 'not-json' (a file that is not JSON; bare-agent skips it silently).
|
|
43
|
+
* A server: `{name, remote, shadowedBy}`; `shadowedBy` is the shown path of the earlier place that has the same name (the earlier one wins), or null.
|
|
44
|
+
* @param {{ home?: string }} [o] `home` the config home (tests); undefined = the door's
|
|
45
|
+
* @returns {{ places: Array<{ path: string, file: string, added: boolean, status: 'found'|'missing'|'not-json', servers: Array<{name: string, remote: boolean, shadowedBy: string|null}> }>, problem: string|null }}
|
|
46
|
+
*/
|
|
47
|
+
export function mcpSources(o = {}) {
|
|
48
|
+
const added = addedMcpPaths(o.home);
|
|
49
|
+
const typed = [...DEFAULT_MCP_PLACES().map((p) => ({ path: showMcpPath(p), added: false })), ...added.paths.map((p) => ({ path: p, added: true }))];
|
|
50
|
+
/** @type {Map<string, string>} */
|
|
51
|
+
const first = new Map();
|
|
52
|
+
const places = typed.map(({ path, added: isAdded }) => {
|
|
53
|
+
const file = expandMcpPath(path);
|
|
54
|
+
if (!existsSync(file)) return { path, file, added: isAdded, status: /** @type {const} */ ('missing'), servers: [] };
|
|
55
|
+
try { JSON.parse(readFileSync(file, 'utf8')); } catch { return { path, file, added: isAdded, status: /** @type {const} */ ('not-json'), servers: [] }; }
|
|
56
|
+
const found = discoverServers([file]);
|
|
57
|
+
const servers = [...found].map(([name, def]) => {
|
|
58
|
+
const shadowedBy = first.get(name) ?? null;
|
|
59
|
+
if (shadowedBy === null) first.set(name, path);
|
|
60
|
+
return { name, remote: typeof def?.command !== 'string' || def.command === '', shadowedBy };
|
|
61
|
+
});
|
|
62
|
+
return { path, file, added: isAdded, status: /** @type {const} */ ('found'), servers };
|
|
63
|
+
});
|
|
64
|
+
return { places, problem: added.problem };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The file that holds the WINNING `server` (the first place in the list that has the name), whether it is remote, or null when no place has it.
|
|
69
|
+
* Every place fwdloop starts an MCP from takes its config file from here.
|
|
70
|
+
* @param {string} server @param {{ home?: string }} [o]
|
|
71
|
+
* @returns {{ file: string, remote: boolean } | null}
|
|
72
|
+
*/
|
|
73
|
+
export function mcpConfigFor(server, o = {}) {
|
|
74
|
+
for (const p of mcpSources(o).places) {
|
|
75
|
+
const s = p.servers.find((x) => x.name === server);
|
|
76
|
+
if (s) return { file: p.file, remote: s.remote };
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** the names of the servers that can be started (winners only, remote left out) @param {{ home?: string }} [o] @returns {string[]} */
|
|
82
|
+
export function startableMcpServers(o = {}) {
|
|
83
|
+
return mcpSources(o).places.flatMap((p) => p.servers.filter((s) => !s.remote && s.shadowedBy === null).map((s) => s.name));
|
|
84
|
+
}
|
package/src/mcp-use.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// M13 piece 3 (docs/wiki/the-module-ladder.md, M13 scope item 2 "Use counts come from what runs already record"; FINDINGS F113): how often each MCP server's tools were used,
|
|
2
|
+
// read from what runs already keep. No new run-folder file, nothing is written.
|
|
3
|
+
// - a ticket read: `run.json` `inputs[].mcp.calls` (server + tool; the file holds no time, so `last` is the file's mtime);
|
|
4
|
+
// - a step's tool call: a `kind:"tool"` row of `diary.jsonl` whose tool is `<server>_<tool>` (M13 piece 2); `decision:"deny"` is a denied call, counted apart and not as a use.
|
|
5
|
+
// A torn or unreadable file is skipped, row by row (its rows go missing from the count; it never breaks the page).
|
|
6
|
+
import { readdirSync, readFileSync, statSync } from 'node:fs';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
|
|
9
|
+
const safeDir = (/** @type {string} */ p) => { try { return readdirSync(p); } catch { return []; } };
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {string} root the jobs folder (`<root>/<flow>/runs/run-<n>/`)
|
|
13
|
+
* @param {string[]} servers the server names to count for; a step tool row belongs to the LONGEST name that prefixes it with `_`
|
|
14
|
+
* @returns {Map<string, { calls: number, runs: number, last: string|null, denied: number, tools: Map<string, number> }>}
|
|
15
|
+
*/
|
|
16
|
+
export function countMcpUse(root, servers) {
|
|
17
|
+
const byLength = [...servers].sort((a, b) => b.length - a.length);
|
|
18
|
+
/** @type {Map<string, { calls: number, runSet: Set<string>, last: string, denied: number, tools: Map<string, number> }>} */
|
|
19
|
+
const acc = new Map(servers.map((s) => [s, { calls: 0, runSet: new Set(), last: '', denied: 0, tools: new Map() }]));
|
|
20
|
+
const use = (/** @type {string} */ server, /** @type {string} */ tool, /** @type {string} */ run, /** @type {string} */ at, /** @type {boolean} */ denied) => {
|
|
21
|
+
const a = acc.get(server);
|
|
22
|
+
if (!a) return;
|
|
23
|
+
if (denied) { a.denied++; return; }
|
|
24
|
+
a.calls++; a.runSet.add(run); a.tools.set(tool, (a.tools.get(tool) ?? 0) + 1);
|
|
25
|
+
if (at && at > a.last) a.last = at;
|
|
26
|
+
};
|
|
27
|
+
for (const flow of safeDir(root)) {
|
|
28
|
+
for (const name of safeDir(join(root, flow, 'runs'))) {
|
|
29
|
+
if (!name.startsWith('run-')) continue;
|
|
30
|
+
const dir = join(root, flow, 'runs', name);
|
|
31
|
+
const key = `${flow}/${name}`;
|
|
32
|
+
try {
|
|
33
|
+
const j = JSON.parse(readFileSync(join(dir, 'run.json'), 'utf8'));
|
|
34
|
+
const mtime = statSync(join(dir, 'run.json')).mtime.toISOString();
|
|
35
|
+
for (const i of Array.isArray(j?.inputs) ? j.inputs : []) {
|
|
36
|
+
const m = i?.mcp;
|
|
37
|
+
if (!m || typeof m.server !== 'string') continue;
|
|
38
|
+
for (const c of Array.isArray(m.calls) ? m.calls : []) if (typeof c?.tool === 'string') use(m.server, c.tool, key, mtime, false);
|
|
39
|
+
}
|
|
40
|
+
} catch { /* no run.json, or torn: nothing counted from it */ }
|
|
41
|
+
let text;
|
|
42
|
+
try { text = readFileSync(join(dir, 'diary.jsonl'), 'utf8'); } catch { continue; }
|
|
43
|
+
for (const line of text.split('\n')) {
|
|
44
|
+
if (!line.includes('"kind":"tool"')) continue;
|
|
45
|
+
let r;
|
|
46
|
+
try { r = JSON.parse(line); } catch { continue; }
|
|
47
|
+
if (r?.kind !== 'tool' || typeof r.tool !== 'string') continue;
|
|
48
|
+
const server = byLength.find((s) => r.tool.startsWith(`${s}_`) && r.tool.length > s.length + 1);
|
|
49
|
+
if (server) use(server, r.tool.slice(server.length + 1), key, typeof r.at === 'string' ? r.at : '', r.decision === 'deny');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return new Map([...acc].map(([s, a]) => [s, { calls: a.calls, runs: a.runSet.size, last: a.last || null, denied: a.denied, tools: a.tools }]));
|
|
54
|
+
}
|
package/src/natural.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// M13 item 9.6: the ONE place that orders names with numbers in them (`run-9` before `run-10`, `#8` before `#10`, `run-3-rerun-1` before `run-25`).
|
|
2
|
+
// Digit runs compare as numbers (by length after leading zeros, then by text, so a long number never loses digits); everything else compares as text.
|
|
3
|
+
|
|
4
|
+
/** @param {string} a @param {string} b digit strings */
|
|
5
|
+
const digits = (a, b) => {
|
|
6
|
+
const x = a.replace(/^0+/, '');
|
|
7
|
+
const y = b.replace(/^0+/, '');
|
|
8
|
+
return x.length - y.length || (x < y ? -1 : x > y ? 1 : 0);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/** @param {unknown} x @param {unknown} y @returns {number} negative, 0 or positive, like a sort callback */
|
|
12
|
+
export function compareNatural(x, y) {
|
|
13
|
+
const tx = String(x).match(/\d+|\D+/g) ?? [];
|
|
14
|
+
const ty = String(y).match(/\d+|\D+/g) ?? [];
|
|
15
|
+
for (let i = 0; i < Math.min(tx.length, ty.length); i++) {
|
|
16
|
+
const a = tx[i];
|
|
17
|
+
const b = ty[i];
|
|
18
|
+
if (a === b) continue; // eslint-disable-line no-continue
|
|
19
|
+
const c = /^\d/.test(a) && /^\d/.test(b) ? digits(a, b) : (a < b ? -1 : 1);
|
|
20
|
+
if (c !== 0) return c;
|
|
21
|
+
}
|
|
22
|
+
return tx.length - ty.length;
|
|
23
|
+
}
|
package/src/panel/author.js
CHANGED
|
@@ -55,7 +55,6 @@ import {
|
|
|
55
55
|
} from '../provider.js';
|
|
56
56
|
import { thinkingSupport as bareagentThinkingSupport, THINKING_FIXED_SAY, THINKING_UNVERIFIED_SAY } from '../thinking.js';
|
|
57
57
|
import { parseSignedText } from '../signed-text.js';
|
|
58
|
-
import { ticketNumberOf, ticketRefusals, ticketSourcesOf } from '../ticket-draft.js';
|
|
59
58
|
import { draftStepList, reviseStepList } from '../draft-steps.js';
|
|
60
59
|
import {
|
|
61
60
|
capTooSmallText, draftingSpent, EARLIER_MISSING_SAY, potSplit, STARTED_OVER_FILE, usdText,
|
|
@@ -195,16 +194,6 @@ export function createAuthor(opts) {
|
|
|
195
194
|
return draftingSpent(dir, { ceilingUsd: capFloorFor(true, home, card) }).usd;
|
|
196
195
|
}
|
|
197
196
|
|
|
198
|
-
/**
|
|
199
|
-
* M12 piece 3: the ticket-list input of a plan's signed text (the role a by-hand start picks ONE ticket of), or null. The ONE reader; the green view shows the box from it and the sign door checks it.
|
|
200
|
-
* @param {string} dir the draft folder @param {string} rel the plan folder @returns {string|null}
|
|
201
|
-
*/
|
|
202
|
-
function ticketRoleOfPlan(dir, rel) {
|
|
203
|
-
const prose = readFileInside(dir, `${rel}/prose.txt`);
|
|
204
|
-
const parsed = prose.ok ? parseSignedText(prose.text) : null;
|
|
205
|
-
return parsed?.ok === true ? (ticketSourcesOf(parsed.arbiter.sources)[0]?.role ?? null) : null;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
197
|
/**
|
|
209
198
|
* M4d am16: the split of the card's Cap $ at Sign & run, from ALL of this job's drafting (the one writer of that total, `draftingSpent`). Unpriced rounds count at their
|
|
210
199
|
* worst case (the picked model's Settings ceiling). `refusal` = what is left cannot pay one run round at its worst case: refused at $0.
|
|
@@ -295,7 +284,7 @@ export function createAuthor(opts) {
|
|
|
295
284
|
if (q.questions.length > 0) return { ...shared, phase: 'stopped', say: ANSWERS_NOT_DRAFTED_SAY };
|
|
296
285
|
if (res.phase === 'green') {
|
|
297
286
|
const answers = newest > 0 && redrafts.has(newest) ? answersOf(dir, newest, keys) : [];
|
|
298
|
-
return { ...shared, phase: 'green', hash: res.hash, readout: res.readout, readoutHeads: res.readoutHeads, plan: rel,
|
|
287
|
+
return { ...shared, phase: 'green', hash: res.hash, readout: res.readout, readoutHeads: res.readoutHeads, plan: rel, answers, ...planChecks(dir, rel) };
|
|
299
288
|
}
|
|
300
289
|
return { ...shared, phase: 'red', reds: res.reds, say: newest === 0 ? RED_SAY : cur.say };
|
|
301
290
|
}
|
|
@@ -380,7 +369,9 @@ export function createAuthor(opts) {
|
|
|
380
369
|
}
|
|
381
370
|
|
|
382
371
|
/** The flags that make a draft child use the card's model and thinking choice. @param {any} card */
|
|
383
|
-
const modelArgv = (card) => ['--model', card.model, '--provider', card.provider, ...(card.thinking === true ? ['--thinking'] : [])
|
|
372
|
+
const modelArgv = (card) => ['--model', card.model, '--provider', card.provider, ...(card.thinking === true ? ['--thinking'] : []),
|
|
373
|
+
// M13 piece 4: the card's Flow type and MCP ride every draft of the job (first, revised, redrafted)
|
|
374
|
+
...(card.flowType ? ['--flow-type', card.flowType, '--mcp', card.mcp] : [])];
|
|
384
375
|
|
|
385
376
|
/**
|
|
386
377
|
* The $0 checks both a first draft and a revise run on the card as submitted: the card's own checks (a key value, the flow name,
|
|
@@ -608,16 +599,23 @@ export function createAuthor(opts) {
|
|
|
608
599
|
const run = starter.checkRun(name, runId);
|
|
609
600
|
if (!run.ok) return { status: 400, body: { ok: false, refused: 'run-id', say: run.say } };
|
|
610
601
|
}
|
|
611
|
-
// M12 piece 3 (hamr 2026-10-29): a ticket job reads ONE ticket per run, so Sign & run takes its number too; refused at $0 BEFORE signing (nothing signed, no run folder)
|
|
612
|
-
const ticketRole = ticketRoleOfPlan(dir, v.plan);
|
|
613
|
-
const ticketBad = ticketRefusals(ticketRole, b);
|
|
614
|
-
if (ticketBad.length > 0) return { status: 400, body: { ok: false, refused: 'ticket', refusals: ticketBad } };
|
|
615
|
-
const ticket = ticketNumberOf(b.ticket);
|
|
616
602
|
const signedBy = userInfo().username;
|
|
617
603
|
// M6 am9: a red run's redraft of an unchanged job is signed as the plan of a NEW run of the same workflow (the workflow's files are not written)
|
|
618
604
|
const runOfRec = readJson(dir, RUN_OF_FILE);
|
|
619
605
|
const asRunOf = typeof runOfRec?.flow === 'string' ? { flow: runOfRec.flow } : undefined;
|
|
620
606
|
if (asRunOf !== undefined && runId !== '') return { status: 400, body: { ok: false, refused: 'run-id', say: 'This plan becomes the next run of its workflow by itself; a run name cannot be typed. Nothing was signed.' } };
|
|
607
|
+
// M13 piece 5 (signed item 7): the card's Schedule row is checked now, on the plan about to be signed, so a refusal never leaves a signed job without its schedule. A plan that becomes the next
|
|
608
|
+
// run of its workflow signs no job, so it signs no schedule: the workflow keeps the one it has.
|
|
609
|
+
let cardSchedule = null;
|
|
610
|
+
if (asRunOf === undefined && v.card.schedule) {
|
|
611
|
+
const planProse = readFileInside(join(dir, v.plan), 'prose.txt');
|
|
612
|
+
const planDecl = readJson(join(dir, v.plan), 'declaration.json');
|
|
613
|
+
const parsedPlan = planProse.ok ? parseSignedText(planProse.text) : null;
|
|
614
|
+
if (!parsedPlan || !parsedPlan.ok || !planDecl) return { status: 409, body: { ok: false, refused: 'schedule', say: 'The plan could not be read to check its schedule. Nothing was signed.' } };
|
|
615
|
+
const planned = triggerDoor.cardSchedule(v.card.schedule, { arbiter: parsedPlan.arbiter, declaration: planDecl });
|
|
616
|
+
if (!planned.ok) return { status: 400, body: { ok: false, refused: 'schedule', say: planned.say } };
|
|
617
|
+
cardSchedule = planned.trigger;
|
|
618
|
+
}
|
|
621
619
|
const result = signDraft({
|
|
622
620
|
dir: join(dir, v.plan), approve: v.hash, signedBy, env: loaded.env, keyNames: loaded.keyNames, sessionDir: dir, ...(asRunOf ? { asRunOf } : {}),
|
|
623
621
|
});
|
|
@@ -641,8 +639,10 @@ export function createAuthor(opts) {
|
|
|
641
639
|
}
|
|
642
640
|
}
|
|
643
641
|
const started = starter.start({
|
|
644
|
-
kind: 'sign', flow: name, runId, sources: inputs.map((r) => ({ role: r.role, path: r.path
|
|
642
|
+
kind: 'sign', flow: name, runId, sources: inputs.map((r) => ({ role: r.role, path: r.path })), values, ...(asRunOf ? { planRun: true, pick: result.modelPick ?? null } : {}),
|
|
645
643
|
}, loaded);
|
|
644
|
+
// M13 piece 5 (signed item 7): the same sign writes the job's schedule.json, OFF; the panel turns it on after the job's first green run. `from` = the run this sign started.
|
|
645
|
+
if (cardSchedule !== null) triggerDoor.signSchedule({ flow: name, flowSignatureHash: result.signature.flow, trigger: cardSchedule, from: started.status === 202 && typeof started.body.runId === 'string' ? started.body.runId : null, signedBy });
|
|
646
646
|
if (started.status !== 202) return { status: started.status, body: { ...started.body, signed: true, flow: name, say: `${started.body.say ?? 'The run did not start.'} The flow is signed; start it from "Run a signed flow".` } };
|
|
647
647
|
return { status: 202, body: { ...started.body, signed: true } };
|
|
648
648
|
},
|
package/src/panel/authorcard.js
CHANGED
|
@@ -19,6 +19,11 @@ import { isWebUrl } from '../pagefetch.js';
|
|
|
19
19
|
import { checkSendDestination } from '../runner.js';
|
|
20
20
|
import { parseSignedText } from '../signed-text.js';
|
|
21
21
|
import { capTooSmallText } from '../draftspend.js';
|
|
22
|
+
import { startableMcpServers, mcpConfigFor } from '../mcp-sources.js';
|
|
23
|
+
import { mcpPickFor } from '../mcp-pick.js';
|
|
24
|
+
import { isTicketListUrl } from '../ticket-draft.js';
|
|
25
|
+
import { validateSchedule } from '../trigger-clock.js';
|
|
26
|
+
import { remoteRefusal } from '../ticket-mcp.js';
|
|
22
27
|
import { readPriceConfig, resolveUsableModel, ceilingCostUsd } from '../provider.js';
|
|
23
28
|
|
|
24
29
|
/** The heading line the prose files use (flows/job2-m6a-3/prose.txt); the parser matches `/^arbiter guardrails\b/i`. */
|
|
@@ -182,6 +187,11 @@ export function cardFields(body) {
|
|
|
182
187
|
// M4d amendment 6: the picked model (a key name and a model id from Chat's menu) and the per-job "Thinking on" tick; present only when sent
|
|
183
188
|
...(str(b.provider).trim() !== '' || str(b.model).trim() !== '' ? { provider: str(b.provider).trim(), model: str(b.model).trim() } : {}),
|
|
184
189
|
...(b.thinking === true ? { thinking: true } : {}),
|
|
190
|
+
// M13 piece 4: the Flow type (plain | mcp | tickets) and the MCP pick; sent only when the card names one, signed with the job
|
|
191
|
+
...(str(b.flowType).trim() !== '' && str(b.flowType).trim() !== 'plain' ? { flowType: str(b.flowType).trim(), mcp: str(b.mcp).trim() } : {}),
|
|
192
|
+
// M13 piece 5 (item 7): the Schedule row, signed with the job. Absent = By hand (no schedule.json). Only the typed fields are kept.
|
|
193
|
+
...(b.schedule && typeof b.schedule === 'object' && !Array.isArray(b.schedule)
|
|
194
|
+
? { schedule: b.schedule.kind === 'new-ticket' ? { kind: 'new-ticket' } : { kind: b.schedule.kind, hour: b.schedule.hour, minute: b.schedule.minute } } : {}),
|
|
185
195
|
};
|
|
186
196
|
}
|
|
187
197
|
|
|
@@ -390,6 +400,31 @@ export function checkCard(card, { root, keys = [], home, runOf }) {
|
|
|
390
400
|
if (why !== null) no('destination', why);
|
|
391
401
|
}
|
|
392
402
|
|
|
403
|
+
// M13 piece 4: the Flow type and its MCP. MCP and Tickets name an MCP fwdloop can start whose tools have been checked (R1: the job gets every tool of the newest OK check;
|
|
404
|
+
// never a started server here). Tickets needs the ticket list address as an Inputs line; MCP may have none.
|
|
405
|
+
const flow = /** @type {{flowType?: string, mcp?: string}} */ (card).flowType ?? 'plain';
|
|
406
|
+
if (!['plain', 'mcp', 'tickets'].includes(flow)) no('flowType', 'Flow type must be plain, MCP or Tickets MCP.');
|
|
407
|
+
else if (flow !== 'plain') {
|
|
408
|
+
const server = String(/** @type {any} */ (card).mcp ?? '');
|
|
409
|
+
if (server === '') no('mcp', 'Pick an MCP.');
|
|
410
|
+
else if (!startableMcpServers({ home }).includes(server)) no('mcp', mcpConfigFor(server, { home })?.remote ? remoteRefusal(server) : `${server} is not an MCP fwdloop can start (Settings > MCP lists the ones found).`);
|
|
411
|
+
else {
|
|
412
|
+
const pick = mcpPickFor(server, home);
|
|
413
|
+
if (!pick.ok) no('mcp', pick.say);
|
|
414
|
+
}
|
|
415
|
+
if (flow === 'tickets' && !parseInputLines(card.inputs).some((i) => isTicketListUrl(i.path))) no('inputs', 'Tickets needs the ticket list address as an Inputs line (for example issues: https://github.com/owner/repo/issues).');
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// M13 piece 5 (item 7): the Schedule row. Every day at HH:MM for any flow type; When a new ticket arrives only for Tickets. The trigger itself (list, server, tool) is filled from the signed job at sign.
|
|
419
|
+
const sched = /** @type {any} */ (card).schedule;
|
|
420
|
+
if (sched !== undefined) {
|
|
421
|
+
if (sched.kind === 'new-ticket') {
|
|
422
|
+
if (flow !== 'tickets') no('schedule', 'Only a Tickets MCP job can start on a new ticket.');
|
|
423
|
+
} else if (sched.kind === 'daily') {
|
|
424
|
+
try { validateSchedule(sched); } catch { no('schedule', 'The time must be an hour 0-23 and a minute 0-59, like 09:00.'); }
|
|
425
|
+
} else no('schedule', 'Pick when it runs from the choices.');
|
|
426
|
+
}
|
|
427
|
+
|
|
393
428
|
// inputs: one `name: path` per line; a role and a path on every line, no repeated role; each path a readable regular file (realpath)
|
|
394
429
|
refusals.push(...checkInputRows(parseInputLines(card.inputs)));
|
|
395
430
|
|
package/src/panel/authorflows.js
CHANGED
|
@@ -14,7 +14,8 @@ import { lstatSync, realpathSync } from 'node:fs';
|
|
|
14
14
|
import { join } from 'node:path';
|
|
15
15
|
|
|
16
16
|
import { scrub } from '../authoring.js';
|
|
17
|
-
import {
|
|
17
|
+
import { ticketSourcesOf } from '../ticket-draft.js';
|
|
18
|
+
import { flowTypeOf } from '../declaration.js';
|
|
18
19
|
import { endRow, readHistory } from '../books.js';
|
|
19
20
|
import { canFlowRun, willNotRunSay } from '../canrun.js';
|
|
20
21
|
import { loadCatalogue } from '../catalogue.js';
|
|
@@ -45,7 +46,7 @@ export const editBlockedSay = (runId) => `finish or stop ${runId} first`;
|
|
|
45
46
|
export const EDIT_STARTING_SAY = 'a run is starting';
|
|
46
47
|
const NO_LIMIT = 'no monthly limit set';
|
|
47
48
|
/** The body keys a run start takes (amendment 5 item 2): the open boxes plus the hash of the second click. Any other key is refused by name. */
|
|
48
|
-
const RUN_KEYS = ['flow', 'inputs', 'runId', 'destination', 'capUsd', 'askWaits', 'hash', 'provider', 'model', 'planOf'
|
|
49
|
+
const RUN_KEYS = ['flow', 'inputs', 'runId', 'destination', 'capUsd', 'askWaits', 'hash', 'provider', 'model', 'planOf'];
|
|
49
50
|
|
|
50
51
|
/**
|
|
51
52
|
* What the Run / Resume forms show of a signed flow (read from its own files, never from a model): the job lines as the signed text has them
|
|
@@ -230,10 +231,6 @@ export function createFlowsDoor(opts) {
|
|
|
230
231
|
if (Object.hasOwn(pages, r.role) && r.path !== pages[r.role]) refusals.push({ field: `inputs.${n}`, say: pageAddressRefusal(r.role, pages[r.role]) });
|
|
231
232
|
});
|
|
232
233
|
const declared = (read.arbiter.sources ?? []).map((s) => s.role);
|
|
233
|
-
// M12 piece 3 (hamr 2026-10-29): a by-hand Run on a job with a ticket list picks ONE ticket by number; any other job takes none
|
|
234
|
-
const ticketRole = ticketSourcesOf(read.arbiter.sources)[0]?.role ?? null;
|
|
235
|
-
const ticket = ticketNumberOf(body?.ticket);
|
|
236
|
-
refusals.push(...ticketRefusals(ticketRole, body));
|
|
237
234
|
for (const role of declared) {
|
|
238
235
|
if (!Object.hasOwn(pages, role) && !rows.some((r) => r.role === role)) refusals.push({ field: 'inputs', say: `This flow needs an input named "${role}". Add it.` });
|
|
239
236
|
}
|
|
@@ -251,7 +248,7 @@ export function createFlowsDoor(opts) {
|
|
|
251
248
|
flow, flowSignatureHash: read.signature.flow, runId: null, version: 0, values,
|
|
252
249
|
});
|
|
253
250
|
return {
|
|
254
|
-
ok: /** @type {true} */ (true), flow, read, declared, rows: declared.map((role) => rows.find((r) => r.role === role) ?? { role, path: pages[role] }),
|
|
251
|
+
ok: /** @type {true} */ (true), flow, read, declared, rows: declared.map((role) => rows.find((r) => r.role === role) ?? { role, path: pages[role] }), runId, values, differs: checked.differs || runModel !== null, hash, newPick, flowDir: join(realRoot, flow), planFrom,
|
|
255
252
|
};
|
|
256
253
|
}
|
|
257
254
|
|
|
@@ -303,11 +300,11 @@ export function createFlowsDoor(opts) {
|
|
|
303
300
|
const last = lastSources(flowDir, roles, pageAddressesOf(read.arbiter));
|
|
304
301
|
const { passed, stats } = runsOf(flowDir, name, read, roles);
|
|
305
302
|
return {
|
|
306
|
-
flow: name, capUsd: read.arbiter.capUsd, roles, pages: pageAddressesOf(read.arbiter), tickets: ticketSourcesOf(read.arbiter.sources).map((x) => x.role), nextRunId: nextRunId(flowDir), lastRunId: last.runId, lastSources: last.sources, leftThisMonth: left,
|
|
303
|
+
flow: name, capUsd: read.arbiter.capUsd, roles, pages: pageAddressesOf(read.arbiter), tickets: flowTypeOf(read.declaration) === 'tickets' ? ticketSourcesOf(read.arbiter.sources).map((x) => x.role) : [], flowType: flowTypeOf(read.declaration), mcp: read.declaration?.mcp?.server ?? null, nextRunId: nextRunId(flowDir), lastRunId: last.runId, lastSources: last.sources, leftThisMonth: left,
|
|
307
304
|
runs: passed, stats,
|
|
308
305
|
...formFacts(read, home, flowDir),
|
|
309
306
|
// M6 am5/am6: the job as the card Reuse workflow opens (`ok:true, card`), or why the card cannot hold it (`ok:false, say`). Nothing blocks it: a reuse never changes the job it is opened from.
|
|
310
|
-
edit: (() => { const c = cardFromSigned(read); return c.ok ? { ok: true, card: c.card } : c; })(),
|
|
307
|
+
edit: (() => { const c = cardFromSigned(read); return c.ok ? { ok: true, card: { ...c.card, ...(flowTypeOf(read.declaration) === 'plain' ? {} : { flowType: flowTypeOf(read.declaration), mcp: read.declaration?.mcp?.server ?? '' }) } } : c; })(),
|
|
311
308
|
};
|
|
312
309
|
}
|
|
313
310
|
|
|
@@ -325,7 +322,7 @@ export function createFlowsDoor(opts) {
|
|
|
325
322
|
},
|
|
326
323
|
|
|
327
324
|
/**
|
|
328
|
-
* M6 am9: is this run red, as the panel's glyph rule reads it (`[✗]` and nothing else; stopped `[■]` and waiting are not)? The server decides this itself,
|
|
325
|
+
* M6 am9: is this run red, as the panel's glyph rule reads it (`[✗]` and nothing else; stopped `[■]` and waiting are not; M13 9b.2: not a run that failed preflight)? The server decides this itself,
|
|
329
326
|
* never from the page's word. False for a run that does not resolve.
|
|
330
327
|
* @param {string} flow @param {unknown} runId
|
|
331
328
|
*/
|
|
@@ -334,7 +331,10 @@ export function createFlowsDoor(opts) {
|
|
|
334
331
|
if (realRoot === null || !checkFlowName(flow).ok || typeof runId !== 'string' || runId === '') return false;
|
|
335
332
|
const cat = loadCatalogue();
|
|
336
333
|
if (!cat.ok) return false;
|
|
337
|
-
|
|
334
|
+
if (getRunGlyph({ root: realRoot, flow, runId, catalogue: cat.primitives })?.glyph !== '[✗]') return false;
|
|
335
|
+
// M13 item 9b.2: a run that failed preflight never ran its plan (no step, $0), so its plan did not fail: reusing it unchanged is Run now, not a paid redraft
|
|
336
|
+
const end = endRow(readHistory(join(realRoot, flow)), join(realRoot, flow, 'runs', runId), runId);
|
|
337
|
+
return end?.outcome !== 'preflight-red';
|
|
338
338
|
},
|
|
339
339
|
|
|
340
340
|
/**
|
|
@@ -356,11 +356,15 @@ export function createFlowsDoor(opts) {
|
|
|
356
356
|
* @param {any} body
|
|
357
357
|
*/
|
|
358
358
|
reuseCheck(body) {
|
|
359
|
-
|
|
359
|
+
// M13 am4 item 1: `flowType` and `mcp` are job fields like the lines; read here, never reach the run door. An absent field = unchanged; plain has no server.
|
|
360
|
+
const { job, fromRun, flowType, mcp, ...rest } = body && typeof body === 'object' ? body : /** @type {any} */ ({});
|
|
360
361
|
const realRoot = realRootOrNull();
|
|
361
362
|
if (realRoot !== null && typeof job === 'string' && typeof rest.flow === 'string' && checkFlowName(rest.flow).ok) {
|
|
362
363
|
const read = readSigned(realRoot, rest.flow);
|
|
363
|
-
|
|
364
|
+
const signedType = read.ok ? flowTypeOf(read.declaration) : 'plain';
|
|
365
|
+
const typeChanged = typeof flowType === 'string' && flowType !== signedType;
|
|
366
|
+
const mcpChanged = typeof mcp === 'string' && (flowType ?? signedType) !== 'plain' && mcp !== (read.ok ? read.declaration?.mcp?.server ?? '' : '');
|
|
367
|
+
if (read.ok && (jobKeyOfCard(job) !== jobKeyOfSigned(read) || typeChanged || mcpChanged)) {
|
|
364
368
|
return { status: 200, body: { ok: true, kind: 'draft', suggestedName: suggestFlowName(realRoot, rest.flow) } };
|
|
365
369
|
}
|
|
366
370
|
// M6 am9: a RED run always drafts. The job is unchanged here, so the new plan is the next run of the SAME workflow (no new name). Only `[✗]` is red.
|
|
@@ -467,7 +471,7 @@ export function createFlowsDoor(opts) {
|
|
|
467
471
|
};
|
|
468
472
|
}
|
|
469
473
|
const started = starter.start({
|
|
470
|
-
kind: 'run', flow: s.flow, runId: s.runId, sources: s.declared.map((role) => ({ role, path: /** @type {{path: string}} */ (s.rows.find((r) => r.role === role)).path
|
|
474
|
+
kind: 'run', flow: s.flow, runId: s.runId, sources: s.declared.map((role) => ({ role, path: /** @type {{path: string}} */ (s.rows.find((r) => r.role === role)).path })), values, pick: s.newPick, planOf: s.planFrom,
|
|
471
475
|
}, loaded);
|
|
472
476
|
// M4d amendment 7b: the pick of a flow that had no record is written only once the start succeeded (a refused start leaves none), beside the signed files, never in them
|
|
473
477
|
if (started.status === 202 && s.newPick !== null) {
|