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/src/trigger-tickets.js
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
// and `name: #<number>`, so `queueOf`, `recordRan` and `recordDropped` work on it unchanged.
|
|
8
8
|
import { createMCPBridge, discoverServers } from 'bare-agent/mcp';
|
|
9
9
|
|
|
10
|
-
import {
|
|
11
|
-
import { parseTicketList } from './ticket-shape.js';
|
|
10
|
+
import { configForServer, remoteRefusal, mcpStartOpts, startRefusal, firstLine, isDeviceLogin } from './ticket-mcp.js';
|
|
11
|
+
import { parseTicketList, isTicketNumber, TICKET_MAX } from './ticket-shape.js';
|
|
12
12
|
import { appendSeen, readSeen, queueOf } from './trigger-files.js';
|
|
13
13
|
|
|
14
14
|
/** A look every 15 minutes, fixed (item 8). */
|
|
@@ -40,25 +40,28 @@ export function reasonFor(prev, cur, watch) {
|
|
|
40
40
|
* One look. `seen` null = the first look after signing (the first page is the starting point, nothing runs). Otherwise newest first with the cursor, stopping at a seen
|
|
41
41
|
* number; with watched fields the walk goes on past it only as far as the oldest tracked ticket, comparing each tracked ticket's watched values with `last`.
|
|
42
42
|
* Every failure is `{ok:false, error}` naming its cause, at $0; none reads as "0 new".
|
|
43
|
-
*
|
|
44
|
-
*
|
|
43
|
+
* M13 piece 5 (F114f): `cut` (first look only) = the highest ticket number the job's first green run read. The first look goes on past a page whose tickets are all above it, so
|
|
44
|
+
* every ticket that came in after that run started is seen; `recordLook` then baselines the ones up to `cut` and lets the rest arrive.
|
|
45
|
+
* @param {{listUrl: string, mcp: {server: string, tool: string}, configPath?: string, seen: Set<number>|null, last: Map<number, {state: string, labels: string[]}>, watch: string[], cut?: number, perPage?: number, timeoutMs?: number}} o
|
|
46
|
+
* @returns {Promise<{ok: true, first: boolean, cut?: number, ignored?: number[], found: Array<{number: number, state: string, labels: string[], createdAt: string|null}>, changed: Array<{number: number, reason: string, state: string, labels: string[]}>, pages: number} | {ok: false, error: string}>}
|
|
45
47
|
*/
|
|
46
48
|
export async function lookTickets({
|
|
47
|
-
listUrl, mcp, configPath
|
|
49
|
+
listUrl, mcp, configPath: explicitConfig, seen, last, watch, cut, perPage = 10, timeoutMs = 90000,
|
|
48
50
|
}) {
|
|
49
51
|
const parsed = parseTicketList(listUrl);
|
|
50
52
|
if (!parsed.ok) return parsed;
|
|
51
53
|
const { owner, repo } = parsed;
|
|
52
54
|
const { server, tool } = mcp;
|
|
55
|
+
const { file: configPath, remote } = configForServer(server, explicitConfig);
|
|
53
56
|
if (!discoverServers([configPath]).has(server)) return { ok: false, error: `${server} is not in ~/.mcp.json` };
|
|
57
|
+
if (remote) return { ok: false, error: remoteRefusal(server) };
|
|
54
58
|
const first = seen === null;
|
|
55
59
|
let bridge;
|
|
56
60
|
try {
|
|
57
|
-
bridge = await createMCPBridge({ configPaths: [configPath], timeout: timeoutMs, callTimeout: timeoutMs, confirmServer: () => true, allow: { [server]: [tool] } });
|
|
61
|
+
bridge = await createMCPBridge({ configPaths: [configPath], ...mcpStartOpts(), timeout: timeoutMs, callTimeout: timeoutMs, confirmServer: () => true, allow: { [server]: [tool] } });
|
|
58
62
|
const failed = bridge.errors.find((/** @type {any} */ e) => e.server === server);
|
|
59
63
|
if (failed) return { ok: false, error: `${server} did not start: ${firstLine(failed.error)}` };
|
|
60
64
|
if (bridge.missing?.[0]) return { ok: false, error: `${server} does not offer ${bridge.missing[0].tool}` };
|
|
61
|
-
for (const t of bridge.tools) if (t.annotations?.readOnlyHint !== true) return { ok: false, error: `${server} does not mark ${t.name.slice(`${server}_`.length)} read-only (readOnlyHint is not true)` };
|
|
62
65
|
const list = bridge.tools.find((/** @type {any} */ t) => t.name === `${server}_${tool}`);
|
|
63
66
|
if (!list) return { ok: false, error: `${server} does not offer ${tool}` };
|
|
64
67
|
|
|
@@ -79,6 +82,8 @@ export async function lookTickets({
|
|
|
79
82
|
};
|
|
80
83
|
|
|
81
84
|
const found = [];
|
|
85
|
+
/** @type {number[]} */
|
|
86
|
+
const ignored = [];
|
|
82
87
|
/** @type {Array<{number: number, reason: string, state: string, labels: string[]}>} */
|
|
83
88
|
const changed = [];
|
|
84
89
|
const tracked = new Set(first ? [] : last.keys());
|
|
@@ -87,6 +92,8 @@ export async function lookTickets({
|
|
|
87
92
|
let after;
|
|
88
93
|
let pages = 0;
|
|
89
94
|
let hitSeen = false;
|
|
95
|
+
// M13 item 6: a ticket is new only if its number is higher than the highest seen (closed seen tickets leave an OPEN-only list; older open ones are not new)
|
|
96
|
+
const maxSeen = first ? 0 : Math.max(0, ...seen);
|
|
90
97
|
for (;;) {
|
|
91
98
|
const args = {
|
|
92
99
|
owner, repo, orderBy: 'CREATED_AT', direction: 'DESC', perPage, ...(watch.length === 0 ? { state: 'OPEN' } : {}), fields: ['number', 'created_at', 'state', 'labels'], ...(after ? { after } : {}),
|
|
@@ -100,6 +107,8 @@ export async function lookTickets({
|
|
|
100
107
|
for (const i of r.issues) {
|
|
101
108
|
const n = i.number;
|
|
102
109
|
if (!Number.isInteger(n)) continue;
|
|
110
|
+
// M13 piece 7 (9.7): a number over the one cap is ignored, never a crash; the look records one reason
|
|
111
|
+
if (!isTicketNumber(n)) { ignored.push(n); continue; }
|
|
103
112
|
lowest = Math.min(lowest, n);
|
|
104
113
|
const rec = { number: n, ...watchedOf(i), createdAt: typeof i.created_at === 'string' ? i.created_at : null };
|
|
105
114
|
if (first) { found.push(rec); continue; }
|
|
@@ -111,19 +120,19 @@ export async function lookTickets({
|
|
|
111
120
|
const reason = reasonFor(prev, rec, watch);
|
|
112
121
|
if (reason) changed.push({ number: n, reason, state: rec.state, labels: rec.labels });
|
|
113
122
|
}
|
|
114
|
-
} else if (!hitSeen) found.push(rec);
|
|
123
|
+
} else if (!hitSeen && n > maxSeen) found.push(rec);
|
|
115
124
|
}
|
|
116
|
-
if (first) break;
|
|
117
|
-
const done = hitSeen && (watch.length === 0 || stillNeeded.size === 0 || lowest < oldestTracked);
|
|
125
|
+
if (first && (cut === undefined || lowest <= cut)) break;
|
|
126
|
+
const done = (hitSeen || lowest <= maxSeen) && (watch.length === 0 || stillNeeded.size === 0 || lowest < oldestTracked);
|
|
118
127
|
if (done || !r.pageInfo?.hasNextPage || !r.pageInfo?.endCursor) break;
|
|
119
128
|
if (pages >= MAX_PAGES) return { ok: false, error: `more than ${MAX_PAGES} pages of new tickets in one look` };
|
|
120
129
|
after = r.pageInfo.endCursor;
|
|
121
130
|
}
|
|
122
131
|
return {
|
|
123
|
-
ok: true, first, found, changed: changed.sort((a, b) => a.number - b.number), pages,
|
|
132
|
+
ok: true, first, ...(first && cut !== undefined ? { cut } : {}), ...(ignored.length ? { ignored } : {}), found, changed: changed.sort((a, b) => a.number - b.number), pages,
|
|
124
133
|
};
|
|
125
134
|
} catch (e) {
|
|
126
|
-
return { ok: false, error:
|
|
135
|
+
return { ok: false, error: startRefusal(server, e) };
|
|
127
136
|
} finally {
|
|
128
137
|
try { await bridge?.close(); } catch { /* already closed */ }
|
|
129
138
|
}
|
|
@@ -142,6 +151,14 @@ export function lastSeen(ledger, sig) {
|
|
|
142
151
|
return m;
|
|
143
152
|
}
|
|
144
153
|
/** Has this signing had its first look (its baseline written)? @param {string} ledger @param {string} sig */
|
|
154
|
+
/**
|
|
155
|
+
* M13 item 9b.3: the cause of the newest look when it could not read, else null. The newest look row decides: an `unreadable` row is the problem until a later look reads
|
|
156
|
+
* (its `looked`, `baseline` or `arrived` row). @param {import('./trigger-files.js').SeenRow[]} rows @returns {{at: number, why: string}|null}
|
|
157
|
+
*/
|
|
158
|
+
export function lookProblemOf(rows) {
|
|
159
|
+
const last = /** @type {any[]} */ (rows).findLast((r) => r.kind === 'unreadable' || r.kind === 'looked' || r.kind === 'baseline' || r.kind === 'arrived');
|
|
160
|
+
return last?.kind === 'unreadable' ? { at: last.at, why: String(last.why ?? 'it could not read the list') } : null;
|
|
161
|
+
}
|
|
145
162
|
export const hasBaseline = (ledger, sig) => readSeen(ledger, sig).some((r) => r.kind === 'baseline');
|
|
146
163
|
|
|
147
164
|
/**
|
|
@@ -155,10 +172,22 @@ export function recordLook(ledger, sig, look, at) {
|
|
|
155
172
|
appendSeen(ledger, /** @type {any} */ ({ id: `unreadable:${at}`, kind: 'unreadable', sha: `unreadable:${at}`, name: '', size: 0, at, why: look.error }), sig);
|
|
156
173
|
return { arrived: [], unreadable: look.error };
|
|
157
174
|
}
|
|
175
|
+
// a look that read, after one that could not: one `looked` row ends the problem even when nothing is new (the only look row that is not found tickets)
|
|
176
|
+
// M13 piece 7 (9.7): ticket numbers over the cap were ignored by the look; ONE reason is recorded on the same row
|
|
177
|
+
const note = look.ignored?.length ? `ignored ${look.ignored.length} ticket number${look.ignored.length === 1 ? '' : 's'} over ${TICKET_MAX.toLocaleString('en-US')}: ${look.ignored.slice(0, 5).join(', ')}` : null;
|
|
178
|
+
if (note !== null || lookProblemOf(readSeen(ledger, sig))) appendSeen(ledger, /** @type {any} */ ({ id: `looked:${at}`, kind: 'looked', sha: `looked:${at}`, name: '', size: 0, at, ...(note !== null ? { why: note } : {}) }), sig);
|
|
158
179
|
const arrived = [];
|
|
159
180
|
const watch = (/** @type {{state: string, labels: string[]}} */ w) => ({ state: w.state, labels: w.labels });
|
|
160
181
|
if (look.first) {
|
|
161
182
|
for (const i of [...look.found].reverse()) {
|
|
183
|
+
if (look.cut !== undefined && i.number > look.cut) {
|
|
184
|
+
// M13 piece 5 (F114f): above the number the first green run read = it came in after that run began, so it runs once the schedule is on
|
|
185
|
+
appendSeen(ledger, /** @type {any} */ ({
|
|
186
|
+
id: `arrived:ticket:${i.number}`, kind: 'arrived', sha: `ticket:${i.number}`, name: `#${i.number}`, path: `#${i.number}`, size: 0, at, number: i.number, watch: watch(i),
|
|
187
|
+
}), sig);
|
|
188
|
+
arrived.push(i.number);
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
162
191
|
appendSeen(ledger, /** @type {any} */ ({
|
|
163
192
|
id: `baseline:ticket:${i.number}`, kind: 'baseline', sha: `ticket:${i.number}`, name: `#${i.number}`, path: `#${i.number}`, size: 0, at, number: i.number, watch: watch(i),
|
|
164
193
|
}), sig);
|
package/types/authoring.d.ts
CHANGED
|
@@ -95,7 +95,7 @@ export function draftKeyRefusal(slot: string, env: Record<string, string | undef
|
|
|
95
95
|
* Test seam: `provider`/`rates`/`modelId` are injected; without them a live provider is built.
|
|
96
96
|
* `onResult({ ok })` (M4d am32): called once, after the spend is booked and just before the result files are written (the CLI gives its monthly hold back there).
|
|
97
97
|
*/
|
|
98
|
-
export function draftToDir({ proseFile, dir, root, name, slot, model, draftThinking, keyNames, env, provider, rates, modelId, noQuestions, onResult, fetchPage, leftRules, proseRead, }: {
|
|
98
|
+
export function draftToDir({ proseFile, dir, root, name, slot, model, draftThinking, keyNames, env, provider, rates, modelId, noQuestions, onResult, fetchPage, leftRules, proseRead, flowType, mcpServer, mcpPick, mcpServers, }: {
|
|
99
99
|
proseFile: any;
|
|
100
100
|
dir: any;
|
|
101
101
|
root: any;
|
|
@@ -113,6 +113,10 @@ export function draftToDir({ proseFile, dir, root, name, slot, model, draftThink
|
|
|
113
113
|
fetchPage: any;
|
|
114
114
|
leftRules: any;
|
|
115
115
|
proseRead: any;
|
|
116
|
+
flowType?: "mcp" | "plain" | "tickets" | undefined;
|
|
117
|
+
mcpServer?: string | undefined;
|
|
118
|
+
mcpPick?: any;
|
|
119
|
+
mcpServers?: string[] | undefined;
|
|
116
120
|
}): Promise<{
|
|
117
121
|
ok: boolean;
|
|
118
122
|
wrote: boolean;
|
package/types/canrun.d.ts
CHANGED
|
@@ -20,19 +20,12 @@ export function unwiredRed(found: {
|
|
|
20
20
|
verb: string;
|
|
21
21
|
}): string;
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
23
|
+
* 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:
|
|
24
|
+
* 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
|
|
25
|
+
* 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.
|
|
26
|
+
* @param {Record<string, any>} declaration `readFlow`'s declaration @returns {string|null}
|
|
26
27
|
*/
|
|
27
|
-
export function
|
|
28
|
-
tool: string;
|
|
29
|
-
server: string;
|
|
30
|
-
} | null;
|
|
31
|
-
/** The preflight refusal sentence for a job tool no step grants. @param {{tool: string, server: string}} found */
|
|
32
|
-
export function unusedMcpToolRed(found: {
|
|
33
|
-
tool: string;
|
|
34
|
-
server: string;
|
|
35
|
-
}): string;
|
|
28
|
+
export function findMcpPlanRed(declaration: Record<string, any>): string | null;
|
|
36
29
|
/**
|
|
37
30
|
* M4e amendment 23: the ONE function that turns "this step's check cannot be built" into a plain sentence. It reads the shape, never
|
|
38
31
|
* bareguard's wording, so no `spec.` path or `checks[` index can reach a human. The steps are numbered by the job line they came from
|
package/types/config.d.ts
CHANGED
|
@@ -31,6 +31,12 @@ export function configDoorHome(): {
|
|
|
31
31
|
};
|
|
32
32
|
/** One provider field's value problem in plain words, or null when fine. Shared by validateDoc and the route. */
|
|
33
33
|
export function providerFieldProblem(field: any, v: any): string | null;
|
|
34
|
+
/**
|
|
35
|
+
* 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.
|
|
36
|
+
* Absolute or `~/…`, one line of at most 500 characters.
|
|
37
|
+
* @param {unknown} p
|
|
38
|
+
*/
|
|
39
|
+
export function mcpPathProblem(p: unknown): "must be a path to an MCP config file" | "must be one line of at most 500 characters" | "must start with / or ~/" | null;
|
|
34
40
|
/**
|
|
35
41
|
* THE one rule for a slot's model lines (M4d amendment 3 items 7-8), used by config validation and the Settings
|
|
36
42
|
* route. A price is a PAIR (`inPerM` and `outPerM`, each a finite number >= 0 — 0 / 0 typed is a chosen price,
|
package/types/declaration.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 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
|
|
3
|
+
* job, since M12 only had ticket jobs; no `mcp` block is plain.
|
|
4
|
+
* @param {Record<string, any>} declaration @returns {'plain'|'mcp'|'tickets'}
|
|
5
|
+
*/
|
|
6
|
+
export function flowTypeOf(declaration: Record<string, any>): "plain" | "mcp" | "tickets";
|
|
1
7
|
/**
|
|
2
8
|
* A small, pure walker over `declaration.steps` for callers that only want
|
|
3
9
|
* the shape-key verdict (e.g. poc/m1/slot-batch.mjs's `shape` column) —
|
|
@@ -88,6 +94,8 @@ export function validateDeclaration(declaration: unknown, context?: {
|
|
|
88
94
|
* kept in sync with the checks below so a mutation suite can assert it
|
|
89
95
|
* tested every one of them (same trick as ARBITER_FIELDS/SIGNATURE_FIELDS). */
|
|
90
96
|
export const DECLARATION_FIELDS: readonly string[];
|
|
97
|
+
/** M13 piece 4 (signed item 4): the job's flow type, set by code from the job card, signed with the job. */
|
|
98
|
+
export const FLOW_TYPES: readonly string[];
|
|
91
99
|
/** The typed `close.shape` vocabulary, signed by hamr 2026-09-23 (v1):
|
|
92
100
|
* exactly these four top-level keys. Anything else inside `shape` reds by
|
|
93
101
|
* name. */
|