fwdloop 0.27.0 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/bin/fwdloop +54 -13
- package/package.json +3 -3
- package/src/ask.js +1 -1
- package/src/audit-fold.js +9 -1
- package/src/authoring.js +22 -5
- package/src/canrun.js +19 -16
- package/src/checked.js +5 -2
- package/src/checkpick.js +257 -0
- package/src/checkwords.js +24 -0
- package/src/closers.js +8 -1
- package/src/config.js +18 -0
- package/src/declaration.js +85 -5
- package/src/drafter.js +143 -47
- package/src/flow.js +2 -1
- package/src/launcher.js +4 -2
- package/src/learn.js +1 -1
- package/src/learnstore.js +8 -7
- package/src/mcp-checks.js +50 -0
- package/src/mcp-pick.js +33 -0
- package/src/mcp-sources.js +84 -0
- package/src/mcp-use.js +54 -0
- package/src/memo.js +120 -0
- package/src/model-step.js +89 -17
- package/src/natural.js +23 -0
- package/src/pageask.js +9 -6
- package/src/pagedropwords.js +9 -0
- package/src/panel/author.js +50 -28
- package/src/panel/authorcard.js +86 -2
- package/src/panel/authorflows.js +18 -14
- package/src/panel/authortrigger.js +241 -84
- package/src/panel/data.js +99 -11
- package/src/panel/index.html +683 -210
- package/src/panel/jobgrid.js +127 -0
- package/src/panel/result.js +28 -7
- package/src/panel/scheduler.js +8 -2
- package/src/panel/server.js +17 -7
- package/src/panel/settings.js +119 -4
- package/src/panel/tickets.js +12 -7
- package/src/pickrecord.js +146 -0
- package/src/plain-checks.js +1 -0
- package/src/primitives.js +34 -5
- package/src/provider.js +4 -1
- package/src/runfile.js +4 -2
- package/src/runner.js +170 -45
- package/src/send.js +71 -4
- package/src/setup.js +13 -1
- package/src/summary-words.js +15 -3
- package/src/ticket-draft.js +40 -42
- package/src/ticket-labels.js +10 -0
- package/src/ticket-mcp.js +33 -10
- package/src/ticket-next.js +33 -0
- package/src/ticket-shape.js +9 -0
- package/src/trigger-clock.js +4 -4
- package/src/trigger-files.js +3 -3
- package/src/trigger-tickets.js +41 -12
- package/types/ask.d.ts +2 -1
- package/types/audit-fold.d.ts +13 -2
- package/types/authoring.d.ts +10 -2
- package/types/canrun.d.ts +5 -12
- package/types/checked.d.ts +7 -2
- package/types/checkpick.d.ts +149 -0
- package/types/checkwords.d.ts +14 -0
- package/types/closers.d.ts +2 -1
- package/types/config.d.ts +6 -0
- package/types/declaration.d.ts +17 -0
- package/types/drafter.d.ts +446 -50
- package/types/learn.d.ts +1 -0
- package/types/learnstore.d.ts +2 -3
- package/types/mcp-checks.d.ts +8 -0
- package/types/mcp-pick.d.ts +23 -0
- package/types/mcp-sources.d.ts +51 -0
- package/types/mcp-use.d.ts +12 -0
- package/types/memo.d.ts +15 -0
- package/types/model-step.d.ts +5 -0
- package/types/natural.d.ts +2 -0
- package/types/pageask.d.ts +9 -2
- package/types/pagedropwords.d.ts +1 -0
- package/types/panel/author.d.ts +37 -1
- package/types/panel/authorcard.d.ts +52 -0
- package/types/panel/authorflows.d.ts +9 -1
- package/types/panel/authortrigger.d.ts +73 -7
- package/types/panel/data.d.ts +56 -2
- package/types/panel/jobgrid.d.ts +109 -0
- package/types/panel/result.d.ts +9 -3
- package/types/panel/server.d.ts +5 -1
- package/types/panel/settings.d.ts +3 -2
- package/types/panel/tickets.d.ts +26 -4
- package/types/pickrecord.d.ts +88 -0
- package/types/primitives.d.ts +15 -2
- package/types/runfile.d.ts +7 -2
- package/types/runner.d.ts +128 -77
- package/types/send.d.ts +10 -2
- package/types/setup.d.ts +1 -56
- package/types/summary-words.d.ts +22 -3
- package/types/ticket-draft.d.ts +40 -32
- package/types/ticket-labels.d.ts +6 -0
- package/types/ticket-mcp.d.ts +18 -1
- package/types/ticket-next.d.ts +23 -0
- package/types/ticket-shape.d.ts +5 -0
- package/types/trigger-clock.d.ts +4 -3
- package/types/trigger-files.d.ts +1 -1
- package/types/trigger-tickets.d.ts +18 -4
- package/src/attemptdiff.js +0 -118
- package/types/attemptdiff.d.ts +0 -38
package/src/setup.js
CHANGED
|
@@ -16,6 +16,8 @@ import { notCheckedBlock } from './checked.js';
|
|
|
16
16
|
import { readDraftSpend } from './draftspend.js';
|
|
17
17
|
import { readFileInside, readdirInside } from './flow.js';
|
|
18
18
|
import { readSpendRows } from './provider.js';
|
|
19
|
+
import { checkAsks } from './checkpick.js';
|
|
20
|
+
import { RECORD_FILE, KEPT_WORDS } from './pickrecord.js';
|
|
19
21
|
|
|
20
22
|
export const SETUP_FILE = 'setup.jsonl';
|
|
21
23
|
const CARD_RE = /^card-(\d+)\.json$/;
|
|
@@ -65,10 +67,20 @@ function planRow(sessionDir, rel, kind, n) {
|
|
|
65
67
|
* @param {string} sessionDir @param {string} rel
|
|
66
68
|
*/
|
|
67
69
|
function humanRows(sessionDir, rel) {
|
|
68
|
-
|
|
70
|
+
const answered = readQuestions(join(sessionDir, rel)).questions.filter((q) => q.source === 'look' && q.answer !== null).map((q) => ({
|
|
69
71
|
kind: 'human', n: q.k, at: q.at ?? null, source: 'look', ask: q.ask, question: q.question, answer: q.answer, line: q.line,
|
|
70
72
|
ruleNo: q.ruleNo, ruleText: q.ruleText, proposal: q.proposal ?? null, rule: q.rule ?? null,
|
|
71
73
|
}));
|
|
74
|
+
// M10 am17 (6): a pick kept from the last draft is the same row, from this plan's picks record (not an answer file), its answer being the words `kept from last draft`
|
|
75
|
+
const kept = Array.isArray(readJson(join(sessionDir, rel), RECORD_FILE)?.kept) ? readJson(join(sessionDir, rel), RECORD_FILE).kept : [];
|
|
76
|
+
const keptRows = kept.map((k, i) => {
|
|
77
|
+
const [ask] = checkAsks([{ line: k.line, rule: k.rule, text: k.ruleText, check: k.check ?? null, why: null }]);
|
|
78
|
+
return {
|
|
79
|
+
kind: 'human', n: answered.length + i + 1, at: null, source: 'look', ask: ask.ask, question: ask.question, answer: KEPT_WORDS, line: k.line,
|
|
80
|
+
ruleNo: k.rule, ruleText: k.ruleText, proposal: ask.reading ?? null, rule: k.added ?? null,
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
return [...answered, ...keptRows];
|
|
72
84
|
}
|
|
73
85
|
|
|
74
86
|
/**
|
package/src/summary-words.js
CHANGED
|
@@ -70,6 +70,12 @@ export function nextInWords(ms, now) {
|
|
|
70
70
|
return hours < 48 ? `next in ${hours}h` : `next in ${Math.floor(hours / 24)}d`;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
/** M13 piece 5 (signed item 7): a schedule that was signed with the job and is off until the first green run. The Run card's grey line; one owner. */
|
|
74
|
+
export const SCHEDULE_WAITING_SAY = 'Schedule waiting for a green run';
|
|
75
|
+
|
|
76
|
+
/** M13 item 9b.3: the one line for a look that could not read, with its cause (never "0 new"). @param {{at: number, why: string}} p */
|
|
77
|
+
export const lookProblemWords = (p) => `could not read the tickets: ${String(p.why).trim().replace(/\.$/, '')}. It looks again in 15 minutes.`;
|
|
78
|
+
|
|
73
79
|
/**
|
|
74
80
|
* NEXT of a job with a trigger. One sentence, first match wins:
|
|
75
81
|
* 1. a run of this job is waiting at its ask (the next run waits too);
|
|
@@ -77,7 +83,8 @@ export function nextInWords(ms, now) {
|
|
|
77
83
|
* 3. a clock kind with a next slot; 4. a file kind that is armed; 5. not armed yet.
|
|
78
84
|
* A last outcome of `refused` goes in front of 3-5, so a trigger that cannot start is never silent.
|
|
79
85
|
* `red` is the typed flag for "the human must act": monthly-exhausted and the refused lead. The page paints it; it never guesses from the text.
|
|
80
|
-
*
|
|
86
|
+
* M13 piece 5: `waiting` (signed with the job, off until the first green run) says SCHEDULE_WAITING_SAY, before every other row but the ask.
|
|
87
|
+
* @param {{trigger: Trigger, armed: boolean, waiting?: boolean, lookProblem?: {at: number, why: string}|null, nextSlotMs: number|null, lastOutcome: any, waitingLine: number|null, now: number}} f
|
|
81
88
|
* @returns {{text: string, red: boolean}}
|
|
82
89
|
*/
|
|
83
90
|
export function scheduledNextFor(f) {
|
|
@@ -92,6 +99,8 @@ export function scheduledNextFor(f) {
|
|
|
92
99
|
const left = last.atLeast === true ? `at most ${money(last.leftUsd)} left` : `${money(last.leftUsd)} left`;
|
|
93
100
|
return say(`Paused: not enough money left this month (${left}, a run needs up to ${money(last.needUsd)}). Raise the monthly limit in Settings, or it starts again on the 1st.`, true);
|
|
94
101
|
}
|
|
102
|
+
if (f.waiting === true) return say(SCHEDULE_WAITING_SAY);
|
|
103
|
+
if (f.lookProblem) return say(`The last look ${lookProblemWords(f.lookProblem)}`, true); // M13 item 9b.3
|
|
95
104
|
const lead = last !== null && last.outcome === 'refused' && typeof last.why === 'string' && last.why !== '' ? `The last try did not start: ${last.why} ` : '';
|
|
96
105
|
const red = lead !== '';
|
|
97
106
|
if (!armed) return say(`${lead}Not armed yet: the panel arms it on its next check.`, red);
|
|
@@ -258,14 +267,17 @@ function monthUsedUpWords(row) {
|
|
|
258
267
|
* - month used up: `month used up: $0.01 left, needs $0.50 · next: raise the limit in Settings, or it starts on the 1st`, red only while `nowMs` is still that month;
|
|
259
268
|
* - refused: `refused: <why> · next: fix it in Cancel / modify schedule`, red until a later good start.
|
|
260
269
|
* `next` otherwise: `next <day stamp>`, `next: waiting for a new file` (file schedule) or `next: not armed yet`.
|
|
261
|
-
*
|
|
270
|
+
* M13 piece 5: a schedule signed with the job and still off (`waiting`) has line 2 `Schedule waiting for a green run`, `grey: true` (a red run is normal shaping, never red).
|
|
271
|
+
* @param {{trigger: Trigger|null, home?: string, last: {at: string, runId: string, outcome: string, catchUp: boolean}|null, nextSlotMs: number|null, armed: boolean, waiting?: boolean, lookProblem?: {at: number, why: string}|null, problem: any, nowMs?: number}} f
|
|
262
272
|
* `problem`: the newest fire when it started nothing (busy, monthly-exhausted, refused), else null.
|
|
263
|
-
* @returns {{line1: string, line2: string|null, red: boolean}}
|
|
273
|
+
* @returns {{line1: string, line2: string|null, red: boolean, grey?: boolean}}
|
|
264
274
|
*/
|
|
265
275
|
export function scheduleBlockWords(f) {
|
|
266
276
|
const head = scheduleHead(f.trigger, f.home);
|
|
267
277
|
const tr = f.trigger;
|
|
268
278
|
if (head === null || tr === null) return { line1: 'By hand', line2: null, red: false };
|
|
279
|
+
if (f.waiting === true) return { line1: head, line2: SCHEDULE_WAITING_SAY, red: false, grey: true };
|
|
280
|
+
if (f.lookProblem) return { line1: head, line2: `last look ${shortStamp(f.lookProblem.at)} · ${lookProblemWords(f.lookProblem)}`, red: true }; // M13 item 9b.3
|
|
269
281
|
const file = tr.kind === 'new-file' || tr.kind === 'file-updated';
|
|
270
282
|
const next = tr.kind === 'new-ticket' ? 'next: waiting for a new ticket' : file ? 'next: waiting for a new file' : (f.nextSlotMs !== null && f.armed ? `next ${dayStamp(f.nextSlotMs)}` : 'next: not armed yet');
|
|
271
283
|
const p = f.problem;
|
package/src/ticket-draft.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// per run through the job's MCP tools). The drafter may SUGGEST the job's `mcp`/`mcpTools` (issue_read) and a `ticketFilter` (priority / label names); a human
|
|
4
4
|
// signs it and code decides at run. The first facts line is F90c's, the line that made the drafter read a ticket role at all (FINDINGS F90c, F92).
|
|
5
5
|
import { discoverServers } from 'bare-agent/mcp';
|
|
6
|
-
import {
|
|
6
|
+
import { startableMcpServers } from './mcp-sources.js';
|
|
7
7
|
import { LIST_URL } from './ticket-shape.js';
|
|
8
8
|
|
|
9
9
|
/** the one tool the first slice reads a ticket with */
|
|
@@ -15,48 +15,47 @@ export const isTicketListUrl = (url) => LIST_URL.test(String(url).trim());
|
|
|
15
15
|
/** the signed page sources that are ticket roles @param {Array<{kind?: string, role: string, path: string}>} sources */
|
|
16
16
|
export const ticketSourcesOf = (sources) => (sources ?? []).filter((s) => s.kind === 'page' && isTicketListUrl(s.path));
|
|
17
17
|
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
*/
|
|
22
|
-
export const ticketNumberOf = (v) => (typeof v === 'string' && /^[1-9][0-9]{0,8}$/.test(v.trim()) ? Number(v.trim()) : (Number.isInteger(v) && /** @type {number} */ (v) >= 1 ? /** @type {number} */ (v) : null));
|
|
23
|
-
|
|
24
|
-
/** the refusals of a by-hand start's ticket box: a ticket job needs a number; any other job takes none. @param {string|null} ticketRole @param {any} body @returns {{field: string, say: string}[]} */
|
|
25
|
-
export function ticketRefusals(ticketRole, body) {
|
|
26
|
-
if (ticketRole !== null && ticketNumberOf(body?.ticket) === null) return [{ field: 'ticket', say: `This job reads one ticket of "${ticketRole}" per run. Give its ticket number (a whole number from 1). Nothing started.` }];
|
|
27
|
-
if (ticketRole === null && Object.hasOwn(body ?? {}, 'ticket') && body.ticket !== undefined) return [{ field: 'ticket', say: 'This job has no ticket list, so there is no ticket number to give. Nothing started.' }];
|
|
28
|
-
return [];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** the server names in the user's own `~/.mcp.json` (what the drafter may name); none when the file is missing or unreadable @param {string} [configPath] @returns {string[]} */
|
|
32
|
-
export function userMcpServers(configPath = USER_MCP_CONFIG()) {
|
|
33
|
-
try { return [...discoverServers([configPath]).keys()]; } catch { return []; }
|
|
18
|
+
/** the startable server names across the MCP sources (src/mcp-sources.js), or in one explicit file (what the drafter may name); none when the file is missing or unreadable @param {string} [configPath] @returns {string[]} */
|
|
19
|
+
export function userMcpServers(configPath) {
|
|
20
|
+
try { return configPath ? [...discoverServers([configPath]).keys()] : startableMcpServers(); } catch { return []; }
|
|
34
21
|
}
|
|
35
22
|
|
|
36
23
|
/**
|
|
37
|
-
* The lines under "Inputs" for one ticket role. The first is F90c's, word for word
|
|
38
|
-
*
|
|
24
|
+
* The lines under "Inputs" for one ticket role (M13 piece 4: flow type Tickets). The first is F90c's, word for word. The ticket is already frozen under its role and the job's own
|
|
25
|
+
* tools (`issue_read` to read it, `list_issues` to look for new ones) belong to the job, so no step needs them; a step lists a tool only if it calls it live.
|
|
26
|
+
* @param {string} role @returns {string[]}
|
|
39
27
|
*/
|
|
40
|
-
export function ticketFactsLines(role
|
|
28
|
+
export function ticketFactsLines(role) {
|
|
41
29
|
return [
|
|
42
30
|
`- ${role}: one ticket's text (a signed input, already frozen at run start; read it by listing "${role}" in a step's reads, do not fetch it)`,
|
|
43
|
-
`
|
|
44
|
-
|
|
31
|
+
` A step that reads "${role}" still lists "read" in its primitives: the ticket is frozen, but reading it is a grant.`,
|
|
32
|
+
` Flow type: Tickets. The ticket is already frozen under "${role}" by the job's own tools ("${TICKET_TOOL}" reads it, "${LOOK_TOOL}" looks for new ones); no step needs them. A step lists a tool in "mcpTools" ONLY if that step calls the tool live; leave "mcpTools" out of every other step. The job's server and tool list are set by the program, not by you.`,
|
|
33
|
+
' When a guardrail names a priority or a label (for example "priority P1 only", "only tickets with priority P1 count", "only issues labelled bug"), you MUST add a top-level "ticketFilter": {"priority": [P0 to P3 values], "labels": [label names]} for it; leave it out only when no guardrail names a priority or a label, and such a guardrail stays hitl. A human signs it and code decides at run; never invent a label.',
|
|
45
34
|
' You may SUGGEST a top-level "ticketWatch": ["state", "labels"] (one or both) ONLY for a guardrail that says to run a ticket again when its state or its labels change. Any other thing to watch cannot be put there: leave it out and it stays hitl.',
|
|
46
35
|
];
|
|
47
36
|
}
|
|
48
37
|
|
|
49
|
-
/** the
|
|
50
|
-
export function
|
|
38
|
+
/** the lines for a generic MCP job: the server, its tool names (so the drafter can grant them to steps), and the rule that a step lists a tool only if it calls it live @param {string} server @param {string[]} tools @returns {string[]} */
|
|
39
|
+
export function mcpFactsLines(server, tools) {
|
|
40
|
+
return [
|
|
41
|
+
`- Flow type: MCP (generic). The job's MCP server is "${server}" and its tools are: ${tools.join(', ')}. The job's server and tool list are set by the program, not by you.`,
|
|
42
|
+
' A step lists a tool in "mcpTools" ONLY if that step calls the tool live, using the exact tool name above; at least one step must list at least one tool. Leave "mcpTools" out of every other step.',
|
|
43
|
+
];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** the one tool a Tickets job looks for new tickets with (src/panel/authortrigger.js) */
|
|
47
|
+
export const LOOK_TOOL = 'list_issues';
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The schema parts a job with an MCP adds (M13 piece 4): per-step `mcpTools` (an enum of the job's tool names) for MCP (generic) and Tickets, and for Tickets the top-level
|
|
51
|
+
* `ticketFilter` and `ticketWatch`. The job's own `mcp` block and `flowType` are NOT offered: code sets them.
|
|
52
|
+
* @param {{flowType: 'mcp'|'tickets', tools: string[]}} o
|
|
53
|
+
*/
|
|
54
|
+
export function ticketSchemaParts({ flowType, tools }) {
|
|
55
|
+
const step = { mcpTools: { type: 'array', items: { type: 'string', enum: tools }, description: 'the MCP tools this step calls LIVE (exact names); omit on every step that calls none' } };
|
|
56
|
+
if (flowType !== 'tickets') return { top: {}, step };
|
|
51
57
|
return {
|
|
52
58
|
top: {
|
|
53
|
-
mcp: {
|
|
54
|
-
type: 'object',
|
|
55
|
-
properties: { server: { type: 'string', enum: servers }, tools: { type: 'array', items: { type: 'string', enum: [TICKET_TOOL] } } },
|
|
56
|
-
required: ['server', 'tools'],
|
|
57
|
-
additionalProperties: false,
|
|
58
|
-
description: `the MCP server (from the person's ~/.mcp.json) and the tools the job uses: ["${TICKET_TOOL}"]`,
|
|
59
|
-
},
|
|
60
59
|
ticketFilter: {
|
|
61
60
|
type: 'object',
|
|
62
61
|
properties: {
|
|
@@ -68,20 +67,19 @@ export function ticketSchemaParts(servers) {
|
|
|
68
67
|
},
|
|
69
68
|
ticketWatch: { type: 'array', items: { type: 'string', enum: ['state', 'labels'] }, description: 'optional: suggest only for a guardrail that says to run a ticket again when its state or its labels change' },
|
|
70
69
|
},
|
|
71
|
-
step
|
|
70
|
+
step,
|
|
72
71
|
};
|
|
73
72
|
}
|
|
74
73
|
|
|
75
74
|
/**
|
|
76
|
-
*
|
|
77
|
-
*
|
|
75
|
+
* M13 piece 4: the $0 refusals before any provider call. Tickets needs a ticket-list Inputs line; MCP (generic) and Tickets need a server that is startable and a tool list from a
|
|
76
|
+
* check (`pick`, src/mcp-pick.js: `{ok, server, tools}` or `{ok:false, say}`).
|
|
77
|
+
* @param {{flowType: string, ticketSources: Array<{role: string}>, pick: any, servers: string[]}} o @returns {string[]}
|
|
78
78
|
*/
|
|
79
|
-
export function ticketReds(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
if (!
|
|
83
|
-
if (!servers.includes(
|
|
84
|
-
|
|
85
|
-
if (!reader) reds.push(`declaration: no step reads "${roles[0]}" and lists "${TICKET_TOOL}" in mcpTools`);
|
|
86
|
-
return reds;
|
|
79
|
+
export function ticketReds({ flowType, ticketSources, pick, servers }) {
|
|
80
|
+
if (flowType === 'plain') return [];
|
|
81
|
+
if (flowType === 'tickets' && ticketSources.length === 0) return ['Tickets needs the ticket list address as an Inputs line (for example issues: https://github.com/owner/repo/issues)'];
|
|
82
|
+
if (!pick || pick.ok !== true) return [String(pick?.say ?? 'press check tools in Settings > MCP first')];
|
|
83
|
+
if (!servers.includes(pick.server)) return [`the MCP "${pick.server}" is not a server fwdloop can start (${servers.join(', ') || 'none found'})`];
|
|
84
|
+
return [];
|
|
87
85
|
}
|
package/src/ticket-labels.js
CHANGED
|
@@ -39,6 +39,16 @@ export function readTicketFields(text) {
|
|
|
39
39
|
return { ok: true, labels, state: typeof o.state === 'string' ? o.state.toLowerCase() : null, title: typeof o.title === 'string' ? o.title : null };
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* M13 piece 7 (9.4): the ONE reader of "the filter was unsure about this ticket", from a run.json input entry: true when its stored verdict ran with an `unsure`
|
|
44
|
+
* reason (also when the ticket was sent with Run it anyway and the filter's own verdict was unsure). Anything else, a torn entry too, is false.
|
|
45
|
+
* @param {any} entry @returns {boolean}
|
|
46
|
+
*/
|
|
47
|
+
export function filterUnsure(entry) {
|
|
48
|
+
const f = entry?.filter;
|
|
49
|
+
return typeof f?.unsure === 'string' || (f?.outcome === 'anyway' && typeof f?.was?.unsure === 'string');
|
|
50
|
+
}
|
|
51
|
+
|
|
42
52
|
/**
|
|
43
53
|
* @param {{text: string, filter?: {priority?: string[], labels?: string[]}}} a `filter` = the job's signed `ticketFilter` (or absent)
|
|
44
54
|
* @returns {{outcome: 'run', unsure?: string}|{outcome: 'skip', reason: string}}
|
package/src/ticket-mcp.js
CHANGED
|
@@ -1,17 +1,40 @@
|
|
|
1
1
|
// M12 piece 1b/1c (docs/wiki/the-module-ladder.md, "M12 scope (restart)" items 1-3, 11): read ONE ticket through the user's own MCP server, nothing else.
|
|
2
2
|
// The tool source is the user's `~/.mcp.json` (an explicit path; a repo's .mcp.json is never read). The bridge starts ONLY the server the job names, with
|
|
3
|
-
// `allow` = exactly the job's tools, so any other tool does not exist for the run.
|
|
3
|
+
// `allow` = exactly the job's tools, so any other tool does not exist for the run. M13 item 3: a hint (`readOnlyHint`) is info only; no tool is refused for lacking one.
|
|
4
4
|
// Every refusal names its real cause (F101), at $0; none ever reads as empty content (F103). Proven by F100 (a ticket as a frozen input), F101, F103.
|
|
5
5
|
// Borrowed shape: fwdloop poc/mcp/f100/scratch.diff (`src/ticket-mcp.js`), re-shaped: job-typed tools, explicit config, the three causes kept apart.
|
|
6
6
|
import { createMCPBridge, discoverServers } from 'bare-agent/mcp';
|
|
7
7
|
import { homedir } from 'node:os';
|
|
8
8
|
import { join } from 'node:path';
|
|
9
9
|
import { redactSecrets } from './redact.js';
|
|
10
|
-
import { parseTicketList } from './ticket-shape.js';
|
|
10
|
+
import { parseTicketList, isTicketNumber, TICKET_NUMBER_WORDS } from './ticket-shape.js';
|
|
11
|
+
import { mcpConfigFor } from './mcp-sources.js';
|
|
11
12
|
|
|
12
|
-
/** the
|
|
13
|
+
/** M13 item 9.5: the only parent env names an MCP gets (plus its own settings); the one list for every place fwdloop starts an MCP, so no provider key reaches it */
|
|
14
|
+
export const MCP_PASS_ENV = ['PATH', 'HOME'];
|
|
15
|
+
|
|
16
|
+
/** M13 design point 11 (F118): the one start option set for every place fwdloop starts an MCP: no provider key (passEnv) and the home folder as the start folder (bare-agent bridge `cwd`; no `~` expansion, so the real path) */
|
|
17
|
+
export const mcpStartOpts = () => ({ passEnv: MCP_PASS_ENV, cwd: homedir() });
|
|
18
|
+
|
|
19
|
+
/** the refusal for a failed bridge start: a bad home folder (bare-agent throws ValidationError before any spawn) says so plainly, any other cause keeps its own first line */
|
|
20
|
+
export const startRefusal = (/** @type {string} */ server, /** @type {any} */ e) => `${server} did not start: ${e?.name === 'ValidationError' ? `the home folder could not be used (${firstLine(e)})` : firstLine(e)}`;
|
|
21
|
+
|
|
22
|
+
/** the user's own `~/.mcp.json`: the config a caller that names no place falls back to (a server found nowhere then reads "not in ~/.mcp.json") */
|
|
13
23
|
export const USER_MCP_CONFIG = () => join(homedir(), '.mcp.json');
|
|
14
24
|
|
|
25
|
+
/**
|
|
26
|
+
* M13 piece 3: the config file a server starts from. An explicit path (a test seam) wins; otherwise the file of the WINNING place for `server` (src/mcp-sources.js,
|
|
27
|
+
* the one decider), or `~/.mcp.json` when no place has it. `remote` true = the winner has no start command (listed, not usable).
|
|
28
|
+
* @param {string} server @param {string} [explicit] @returns {{ file: string, remote: boolean }}
|
|
29
|
+
*/
|
|
30
|
+
export function configForServer(server, explicit) {
|
|
31
|
+
if (explicit) return { file: explicit, remote: false };
|
|
32
|
+
return mcpConfigFor(server) ?? { file: USER_MCP_CONFIG(), remote: false };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** the refusal for a remote server (no start command), at $0 @param {string} server */
|
|
36
|
+
export const remoteRefusal = (server) => `${server} is a remote server, not supported yet`;
|
|
37
|
+
|
|
15
38
|
/** the first line of a message, secrets redacted, clipped: all a refusal ever shows of a server's own error */
|
|
16
39
|
export const firstLine = (e) => redactSecrets(String(e?.message ?? e ?? '')).split('\n').find((l) => l.trim() !== '')?.trim().slice(0, 200) ?? 'no message';
|
|
17
40
|
|
|
@@ -24,25 +47,25 @@ export const isDeviceLogin = (text) => text.includes('github.com/login/device');
|
|
|
24
47
|
* @returns {Promise<{ok: true, text: string, url: string, record: {server: string, exposed: string[], missing: Array<{server: string, tool: string}>, calls: Array<{tool: string, owner: string, repo: string, issue_number: number}>}} | {ok: false, error: string}>}
|
|
25
48
|
* `record` is what the run keeps (in its `run.json` input entry): what the server exposed and lacked, and each call made.
|
|
26
49
|
*/
|
|
27
|
-
export async function readTicketMcp({ listUrl, number, mcp, configPath
|
|
50
|
+
export async function readTicketMcp({ listUrl, number, mcp, configPath: explicitConfig, timeoutMs = 90000 }) {
|
|
28
51
|
const list = parseTicketList(listUrl);
|
|
29
52
|
if (!list.ok) return list;
|
|
30
|
-
if (!
|
|
53
|
+
if (!isTicketNumber(number)) return { ok: false, error: `ticket number ${JSON.stringify(number)} is not ${TICKET_NUMBER_WORDS}` };
|
|
31
54
|
const { owner, repo } = list;
|
|
32
55
|
const { server, tools } = mcp;
|
|
56
|
+
// M13 piece 4: the frozen read starts the server with issue_read alone, whatever else the job lists (the job lists every tool of its server)
|
|
33
57
|
if (!tools.includes('issue_read')) return { ok: false, error: `the job does not list issue_read, the tool that reads a ticket` };
|
|
58
|
+
const { file: configPath, remote } = configForServer(server, explicitConfig);
|
|
34
59
|
if (!discoverServers([configPath]).has(server)) return { ok: false, error: `${server} is not in ~/.mcp.json` };
|
|
60
|
+
if (remote) return { ok: false, error: remoteRefusal(server) };
|
|
35
61
|
let bridge;
|
|
36
62
|
try {
|
|
37
|
-
bridge = await createMCPBridge({ configPaths: [configPath], timeout: timeoutMs, callTimeout: timeoutMs, confirmServer: () => true, allow: { [server]:
|
|
63
|
+
bridge = await createMCPBridge({ configPaths: [configPath], ...mcpStartOpts(), timeout: timeoutMs, callTimeout: timeoutMs, confirmServer: () => true, allow: { [server]: ['issue_read'] } });
|
|
38
64
|
const failed = bridge.errors.find((e) => e.server === server);
|
|
39
65
|
if (failed) return { ok: false, error: `${server} did not start: ${firstLine(failed.error)}` };
|
|
40
66
|
const lacking = bridge.missing?.[0];
|
|
41
67
|
if (lacking) return { ok: false, error: `${server} does not offer ${lacking.tool}` };
|
|
42
68
|
const prefix = `${server}_`;
|
|
43
|
-
for (const t of bridge.tools) {
|
|
44
|
-
if (t.annotations?.readOnlyHint !== true) return { ok: false, error: `${server} does not mark ${t.name.slice(prefix.length)} read-only (readOnlyHint is not true)` };
|
|
45
|
-
}
|
|
46
69
|
const tool = bridge.tools.find((t) => t.name === `${prefix}issue_read`);
|
|
47
70
|
if (!tool) return { ok: false, error: `${server} does not offer issue_read` };
|
|
48
71
|
const call = { tool: 'issue_read', owner, repo, issue_number: number };
|
|
@@ -59,7 +82,7 @@ export async function readTicketMcp({ listUrl, number, mcp, configPath = USER_MC
|
|
|
59
82
|
if (text.trim() === '') return { ok: false, error: `${server}: issue_read returned nothing for ${url}` };
|
|
60
83
|
return { ok: true, text, url, record };
|
|
61
84
|
} catch (e) {
|
|
62
|
-
return { ok: false, error:
|
|
85
|
+
return { ok: false, error: startRefusal(server, e) };
|
|
63
86
|
} finally {
|
|
64
87
|
try { await bridge?.close(); } catch { /* already closed */ }
|
|
65
88
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// M13 piece 4 (hamr ruling R2, 2026-10-31): a by-hand Run on a Tickets job has no ticket # box. It reads the NEWEST ticket that has not run yet; the run then reads it through the
|
|
2
|
+
// job's filter as always (a non-match ends skipped, grey, $0). Nothing new = one plain line at $0 and no run. "Has run" = this job's own runs hold the number (`run.json`
|
|
3
|
+
// `inputs[].ticket.number`, a skipped run included); "newest" is the schedule's own look (`lookTickets`, the job's signed `list_issues`, newest first, open tickets).
|
|
4
|
+
// A job with no ticket run yet takes the newest open ticket of the first page (item 6: the first run reads the newest ticket at the time it starts; older ones never run).
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
|
|
7
|
+
import { listRunIds } from './flow.js';
|
|
8
|
+
import { readRunInputs } from './runfile.js';
|
|
9
|
+
import { lookTickets } from './trigger-tickets.js';
|
|
10
|
+
|
|
11
|
+
/** the ticket numbers this job's runs have read @param {string} flowDir @returns {Set<number>} */
|
|
12
|
+
export function ranTicketNumbers(flowDir) {
|
|
13
|
+
const out = new Set();
|
|
14
|
+
for (const id of listRunIds(flowDir)) {
|
|
15
|
+
const got = readRunInputs(join(flowDir, 'runs', id));
|
|
16
|
+
if (!got.ok) continue;
|
|
17
|
+
for (const e of got.entries) if (Number.isInteger(e?.ticket?.number)) out.add(e.ticket.number);
|
|
18
|
+
}
|
|
19
|
+
return out;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param {{flowDir: string, listUrl: string, mcp: {server: string, tool: string}, configPath?: string, look?: typeof lookTickets}} o `look` is a test seam
|
|
24
|
+
* @returns {Promise<{ok: true, number: number} | {ok: false, say: string}>}
|
|
25
|
+
*/
|
|
26
|
+
export async function newestUnrunTicket({ flowDir, listUrl, mcp, configPath, look = lookTickets }) {
|
|
27
|
+
const ran = ranTicketNumbers(flowDir);
|
|
28
|
+
const r = await look({ listUrl, mcp, ...(configPath ? { configPath } : {}), seen: ran.size === 0 ? null : ran, last: new Map(), watch: [] });
|
|
29
|
+
if (!r.ok) return { ok: false, say: String(r.error) };
|
|
30
|
+
const numbers = r.found.map((f) => f.number);
|
|
31
|
+
if (numbers.length === 0) return { ok: false, say: ran.size === 0 ? `No open ticket at ${listUrl}.` : `Nothing new: no ticket newer than #${Math.max(...ran)} has come in.` };
|
|
32
|
+
return { ok: true, number: Math.max(...numbers) };
|
|
33
|
+
}
|
package/src/ticket-shape.js
CHANGED
|
@@ -22,3 +22,12 @@ export function parseTicketList(listUrl) {
|
|
|
22
22
|
export function ticketListsOf(arbiter) {
|
|
23
23
|
return Object.fromEntries((arbiter?.sources ?? []).filter((s) => s.kind === 'page' && LIST_URL.test(String(s.path).trim())).map((s) => [s.role, String(s.path).trim()]));
|
|
24
24
|
}
|
|
25
|
+
|
|
26
|
+
/** M13 piece 7 (9.7): the one cap on a ticket number, 10 digits. Every door that takes or reads a ticket number uses `isTicketNumber`. Under 2^53, so a safe JS number. */
|
|
27
|
+
export const TICKET_MAX = 9_999_999_999;
|
|
28
|
+
|
|
29
|
+
/** The one check of a ticket number: a whole number from 1 to `TICKET_MAX`. @param {unknown} n @returns {n is number} */
|
|
30
|
+
export const isTicketNumber = (n) => Number.isSafeInteger(n) && /** @type {number} */ (n) >= 1 && /** @type {number} */ (n) <= TICKET_MAX;
|
|
31
|
+
|
|
32
|
+
/** The words every refusal of a ticket number uses. */
|
|
33
|
+
export const TICKET_NUMBER_WORDS = `a whole number from 1 to ${TICKET_MAX.toLocaleString('en-US')}`;
|
package/src/trigger-clock.js
CHANGED
|
@@ -19,7 +19,7 @@ import { dirname } from 'node:path';
|
|
|
19
19
|
import { appendRow, ledgerText } from './jsonl-append.js';
|
|
20
20
|
|
|
21
21
|
/** @typedef {{kind:'daily'|'weekdays', hour:number, minute:number} | {kind:'weekly', day:string, hour:number, minute:number}} Schedule */
|
|
22
|
-
/** @typedef {{id:string, kind:'armed'|'fire', at:number, slot?:number, catchUp?:boolean, missed?:number, sig?:string}} ClockRow */
|
|
22
|
+
/** @typedef {{id:string, kind:'armed'|'fire', at:number, slot?:number, catchUp?:boolean, missed?:number, sig?:string, ticketN?:number}} ClockRow */
|
|
23
23
|
/** @typedef {{fire:boolean, catchUp:boolean, missed:number, slot?:number}} Due */
|
|
24
24
|
|
|
25
25
|
/** A slot seen MORE than this after its set time is a catch-up (M9 am2 item 1). Exactly this late is on time. */
|
|
@@ -129,9 +129,9 @@ function appendOnce(file, row, sig) {
|
|
|
129
129
|
appendRow(file, sig === undefined ? row : { ...row, sig });
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
/** The trigger was set at `now`: no slot before this ever fires. @param {string} file @param {number} now @param {string} [sig] */
|
|
133
|
-
export function armTrigger(file, now, sig) {
|
|
134
|
-
appendOnce(file, { id: `armed:${now}`, kind: 'armed', at: now }, sig);
|
|
132
|
+
/** The trigger was set at `now`: no slot before this ever fires. M13 piece 5: `ticketN` = the highest ticket number the first green run read; a ticket schedule's first look baselines only tickets up to it. @param {string} file @param {number} now @param {string} [sig] @param {number} [ticketN] */
|
|
133
|
+
export function armTrigger(file, now, sig, ticketN) {
|
|
134
|
+
appendOnce(file, { id: `armed:${now}`, kind: 'armed', at: now, ...(Number.isInteger(ticketN) ? { ticketN } : {}) }, sig);
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
/**
|
package/src/trigger-files.js
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
} from 'node:fs';
|
|
19
19
|
import { basename, dirname, join } from 'node:path';
|
|
20
20
|
import { createHash } from 'node:crypto';
|
|
21
|
+
import { compareNatural } from './natural.js';
|
|
21
22
|
|
|
22
23
|
import { appendRow, ledgerText } from './jsonl-append.js';
|
|
23
24
|
|
|
@@ -78,13 +79,12 @@ export function recordDropped(ledger, item, why, at, sig) {
|
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
/**
|
|
81
|
-
* The queue: arrived and neither ran nor dropped, oldest arrival first. Identical arrival times: by name, then by sha (deterministic).
|
|
82
|
+
* The queue: arrived and neither ran nor dropped, oldest arrival first. Identical arrival times: by name, then by sha (deterministic); numbers inside a name compare as numbers (`#8` before `#10`).
|
|
82
83
|
* @param {SeenRow[]} rows @returns {(SeenRow & {path:string})[]}
|
|
83
84
|
*/
|
|
84
85
|
export function queueOf(rows) {
|
|
85
|
-
const cmp = (/** @type {string} */ x, /** @type {string} */ y) => (x < y ? -1 : x > y ? 1 : 0);
|
|
86
86
|
return /** @type {any} */ (rows.filter((r) => waiting(rows, r)))
|
|
87
|
-
.sort((x, y) => x.at - y.at ||
|
|
87
|
+
.sort((x, y) => x.at - y.at || compareNatural(x.name, y.name) || compareNatural(x.sha, y.sha));
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
/**
|
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/ask.d.ts
CHANGED
|
@@ -227,7 +227,7 @@ export function readAcceptedHashesByEmits(runDir: string): {
|
|
|
227
227
|
/**
|
|
228
228
|
* @param {string} runDir
|
|
229
229
|
* @returns {{ archived: true, asks: Array<{ askId: string, question?: string, askedAt?: string, expiresAt?: string,
|
|
230
|
-
* evidence: ReturnType<typeof readAskEvidence>,
|
|
230
|
+
* evidence: ReturnType<typeof readAskEvidence>, emits?: string,
|
|
231
231
|
* answer: { status: string, reason?: string, answeredAt?: string, why?: string } }> } | { archived: false, why: string }}
|
|
232
232
|
*/
|
|
233
233
|
export function listArchivedAsks(runDir: string): {
|
|
@@ -238,6 +238,7 @@ export function listArchivedAsks(runDir: string): {
|
|
|
238
238
|
askedAt?: string;
|
|
239
239
|
expiresAt?: string;
|
|
240
240
|
evidence: ReturnType<typeof readAskEvidence>;
|
|
241
|
+
emits?: string;
|
|
241
242
|
answer: {
|
|
242
243
|
status: string;
|
|
243
244
|
reason?: string;
|
package/types/audit-fold.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export function humanWords(r: any): string | null;
|
|
|
13
13
|
* The fold of one step, or `null` for a step with nothing new to show (an old run, or a step that is neither a model step with records nor an ask).
|
|
14
14
|
* @param {{rows:any[], tryMarks:string[], closeClass:string|null}} group `deriveAuditGroups`' group for the step
|
|
15
15
|
* @param {ReturnType<typeof loadDiaries>} d
|
|
16
|
-
* @param {{about?: string|null}} [info] `about`: the file an ask is about
|
|
16
|
+
* @param {{about?: string|null, rerun?: {words: string}|null}} [info] `about`: the file an ask is about; `rerun`: this run's reason for starting (run.json), given for its first step only
|
|
17
17
|
*/
|
|
18
18
|
export function deriveFold(group: {
|
|
19
19
|
rows: any[];
|
|
@@ -21,11 +21,21 @@ export function deriveFold(group: {
|
|
|
21
21
|
closeClass: string | null;
|
|
22
22
|
}, d: ReturnType<typeof loadDiaries>, info?: {
|
|
23
23
|
about?: string | null;
|
|
24
|
+
rerun?: {
|
|
25
|
+
words: string;
|
|
26
|
+
} | null;
|
|
24
27
|
}): {
|
|
25
28
|
who: string;
|
|
26
29
|
tally: string | null;
|
|
27
30
|
tries: any[];
|
|
28
|
-
rows:
|
|
31
|
+
rows: {
|
|
32
|
+
round: null;
|
|
33
|
+
try: any;
|
|
34
|
+
action: string;
|
|
35
|
+
path: string | null;
|
|
36
|
+
decision: string;
|
|
37
|
+
at: any;
|
|
38
|
+
}[];
|
|
29
39
|
counts: {
|
|
30
40
|
rounds: number;
|
|
31
41
|
tools: number;
|
|
@@ -52,3 +62,4 @@ export function summaryLines(d: ReturnType<typeof loadDiaries>): {
|
|
|
52
62
|
calls: string;
|
|
53
63
|
checks: string;
|
|
54
64
|
};
|
|
65
|
+
export function rerunWords(words: string): string;
|