fwdloop 0.26.2 → 0.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/bin/fwdloop +46 -7
  2. package/package.json +2 -2
  3. package/src/authoring.js +21 -1
  4. package/src/canrun.js +23 -0
  5. package/src/config.js +18 -0
  6. package/src/declaration.js +129 -3
  7. package/src/drafter.js +38 -10
  8. package/src/flow.js +2 -1
  9. package/src/launcher.js +4 -2
  10. package/src/learnstore.js +3 -2
  11. package/src/mcp-checks.js +50 -0
  12. package/src/mcp-pick.js +33 -0
  13. package/src/mcp-sources.js +84 -0
  14. package/src/mcp-use.js +54 -0
  15. package/src/natural.js +23 -0
  16. package/src/panel/author.js +17 -1
  17. package/src/panel/authorcard.js +35 -0
  18. package/src/panel/authorflows.js +15 -6
  19. package/src/panel/authorstart.js +10 -6
  20. package/src/panel/authortrigger.js +263 -82
  21. package/src/panel/data.js +127 -9
  22. package/src/panel/index.html +945 -94
  23. package/src/panel/jobgrid.js +127 -0
  24. package/src/panel/scheduler.js +48 -6
  25. package/src/panel/server.js +33 -8
  26. package/src/panel/settings.js +119 -4
  27. package/src/panel/tickets.js +118 -0
  28. package/src/primitives.js +34 -5
  29. package/src/runner.js +129 -15
  30. package/src/schedule.js +5 -0
  31. package/src/summary-words.js +27 -7
  32. package/src/ticket-draft.js +85 -0
  33. package/src/ticket-labels.js +75 -0
  34. package/src/ticket-mcp.js +89 -0
  35. package/src/ticket-next.js +33 -0
  36. package/src/ticket-shape.js +33 -0
  37. package/src/trigger-clock.js +4 -4
  38. package/src/trigger-files.js +4 -4
  39. package/src/trigger-line.js +2 -1
  40. package/src/trigger-tickets.js +238 -0
  41. package/types/authoring.d.ts +5 -1
  42. package/types/canrun.d.ts +7 -0
  43. package/types/config.d.ts +6 -0
  44. package/types/declaration.d.ts +8 -0
  45. package/types/drafter.d.ts +552 -21
  46. package/types/mcp-checks.d.ts +8 -0
  47. package/types/mcp-pick.d.ts +23 -0
  48. package/types/mcp-sources.d.ts +51 -0
  49. package/types/mcp-use.d.ts +12 -0
  50. package/types/natural.d.ts +2 -0
  51. package/types/panel/author.d.ts +44 -0
  52. package/types/panel/authorcard.d.ts +11 -0
  53. package/types/panel/authorflows.d.ts +11 -1
  54. package/types/panel/authorstart.d.ts +3 -1
  55. package/types/panel/authortrigger.d.ts +83 -7
  56. package/types/panel/data.d.ts +78 -5
  57. package/types/panel/jobgrid.d.ts +109 -0
  58. package/types/panel/scheduler.d.ts +7 -2
  59. package/types/panel/server.d.ts +13 -2
  60. package/types/panel/settings.d.ts +3 -2
  61. package/types/panel/tickets.d.ts +103 -0
  62. package/types/primitives.d.ts +15 -2
  63. package/types/runner.d.ts +133 -75
  64. package/types/summary-words.d.ts +24 -4
  65. package/types/ticket-draft.d.ts +104 -0
  66. package/types/ticket-labels.d.ts +42 -0
  67. package/types/ticket-mcp.d.ts +57 -0
  68. package/types/ticket-next.d.ts +23 -0
  69. package/types/ticket-shape.d.ts +30 -0
  70. package/types/trigger-clock.d.ts +4 -3
  71. package/types/trigger-files.d.ts +3 -1
  72. package/types/trigger-line.d.ts +7 -0
  73. package/types/trigger-tickets.d.ts +105 -0
@@ -4,11 +4,15 @@
4
4
  * real listening socket where that is simpler.
5
5
  * @param {import('node:http').IncomingMessage} req
6
6
  * @param {import('node:http').ServerResponse} res
7
- * @param {{ root: string, port: number, version?: string|null, startedAt?: string, packagePath?: string, resumer: ReturnType<typeof createResumer>, settings: ReturnType<typeof createSettings>, author: ReturnType<typeof createAuthor>, now?: () => number }} opts
7
+ * @param {{ root: string, port: number, checksHome: { skip: boolean, home: string|undefined }, version?: string|null, startedAt?: string, packagePath?: string, resumer: ReturnType<typeof createResumer>, settings: ReturnType<typeof createSettings>, author: ReturnType<typeof createAuthor>, now?: () => number, ticketQueue: {arriveAnyway: Function} }} opts
8
8
  */
9
9
  export function handleRequest(req: import("node:http").IncomingMessage, res: import("node:http").ServerResponse, opts: {
10
10
  root: string;
11
11
  port: number;
12
+ checksHome: {
13
+ skip: boolean;
14
+ home: string | undefined;
15
+ };
12
16
  version?: string | null;
13
17
  startedAt?: string;
14
18
  packagePath?: string;
@@ -16,6 +20,9 @@ export function handleRequest(req: import("node:http").IncomingMessage, res: imp
16
20
  settings: ReturnType<typeof createSettings>;
17
21
  author: ReturnType<typeof createAuthor>;
18
22
  now?: () => number;
23
+ ticketQueue: {
24
+ arriveAnyway: Function;
25
+ };
19
26
  }): void;
20
27
  /**
21
28
  * The runs list as the panel builds it, for a caller with no panel running (the launcher header): the SAME `listRuns` over the same catalogue,
@@ -42,7 +49,7 @@ export function panelUrl(boundPort: number): string;
42
49
  * header). Resolves once actually listening; rejects on a bind error
43
50
  * (including `EADDRINUSE`) with a `.port` field on the error for the
44
51
  * caller's message.
45
- * @param {{ port?: number, root: string, packagePath?: string, settings?: { home?: string, env?: Record<string,string|undefined>, fetch?: typeof fetch, now?: () => number, openFolderSpawn?: (cmd: string, args: string[], o: object) => any, platform?: string }, resume?: { env?: Record<string,string|undefined>, bin?: string, logDir?: string, maxTries?: number, windowMs?: number, slotMs?: number }, author?: { env?: Record<string,string|undefined>, loadEnv?: () => any, bin?: string, now?: () => number }, scheduler?: { intervalMs?: number } }} opts
52
+ * @param {{ port?: number, root: string, packagePath?: string, settings?: { home?: string, env?: Record<string,string|undefined>, fetch?: typeof fetch, now?: () => number, openFolderSpawn?: (cmd: string, args: string[], o: object) => any, platform?: string }, resume?: { env?: Record<string,string|undefined>, bin?: string, logDir?: string, maxTries?: number, windowMs?: number, slotMs?: number }, author?: { env?: Record<string,string|undefined>, loadEnv?: () => any, bin?: string, now?: () => number }, scheduler?: { intervalMs?: number, mcpConfig?: string }, ticketQueue?: {arriveAnyway?: Function} }} opts
46
53
  * `resume` and `author` are for tests only (a fake env/bin, a short retry window); the CLI passes none.
47
54
  * @returns {Promise<{ server: import('node:http').Server, port: number, tick: () => void, close: () => Promise<void> }>}
48
55
  */
@@ -74,6 +81,10 @@ export function createPanelServer(opts: {
74
81
  };
75
82
  scheduler?: {
76
83
  intervalMs?: number;
84
+ mcpConfig?: string;
85
+ };
86
+ ticketQueue?: {
87
+ arriveAnyway?: Function;
77
88
  };
78
89
  }): Promise<{
79
90
  server: import("node:http").Server;
@@ -1,10 +1,11 @@
1
1
  /**
2
- * @param {{ home?: string, skip?: boolean, env?: Record<string,string|undefined>, fetch?: typeof fetch, now?: () => number, openFolderSpawn?: (cmd: string, args: string[], o: object) => any, platform?: string }} cfg
3
- * `home` the config home (undefined = the real `~/.config/fwdloop`); `skip` true under a test process
2
+ * @param {{ root?: string, home?: string, skip?: boolean, env?: Record<string,string|undefined>, fetch?: typeof fetch, now?: () => number, openFolderSpawn?: (cmd: string, args: string[], o: object) => any, platform?: string }} cfg
3
+ * `root` the jobs folder (the MCP use counts read its runs); `home` the config home (undefined = the real `~/.config/fwdloop`); `skip` true under a test process
4
4
  * with no `FWDLOOP_CONFIG_HOME` (Settings then touches nothing); `env` the shell side (tests only);
5
5
  * `fetch` and `now` are test seams.
6
6
  */
7
7
  export function createSettings(cfg: {
8
+ root?: string;
8
9
  home?: string;
9
10
  skip?: boolean;
10
11
  env?: Record<string, string | undefined>;
@@ -0,0 +1,103 @@
1
+ /**
2
+ * The ticket schedule this run was set from, or null (no schedule, not a ticket schedule, or set from another run).
3
+ * @param {string} flowDir @param {string} runId @param {(dir: string) => any} [readSched]
4
+ */
5
+ export function ticketScheduleOf(flowDir: string, runId: string, readSched?: (dir: string) => any): any;
6
+ /**
7
+ * @param {{flowDir: string, runId: string, runIdsOf: (flowDir: string) => string[], glyphOf: (runId: string) => {glyph: string, label: string}|null, atOf?: (runId: string) => number|null, readSched?: (dir: string) => any}} a
8
+ * @returns {null | {line: string, list: string, groups: Array<{key: string, label: string, open: boolean, rows: any[]}>}}
9
+ */
10
+ export function ticketListOf({ flowDir, runId, runIdsOf, glyphOf, atOf, readSched }: {
11
+ flowDir: string;
12
+ runId: string;
13
+ runIdsOf: (flowDir: string) => string[];
14
+ glyphOf: (runId: string) => {
15
+ glyph: string;
16
+ label: string;
17
+ } | null;
18
+ atOf?: (runId: string) => number | null;
19
+ readSched?: (dir: string) => any;
20
+ }): null | {
21
+ line: string;
22
+ list: string;
23
+ groups: Array<{
24
+ key: string;
25
+ label: string;
26
+ open: boolean;
27
+ rows: any[];
28
+ }>;
29
+ };
30
+ /**
31
+ * `POST /api/author/ticket-anyway`: queue a SKIPPED ticket as a new arrival, after a short reason. Without a reason nothing starts. The queue is the schedule builder's:
32
+ * `queue.arriveAnyway({flow, number, reason})` is the ONE seam (production: `arriveAnywayOf`).
33
+ * @param {{body: any, listOf: (flow: string, runId: string) => ReturnType<typeof ticketListOf>, queue: {arriveAnyway: (a: {flow: string, runId: string, number: number, reason: string}) => {ok: boolean, say?: string, started?: boolean}}}} a
34
+ * @returns {{status: number, body: Record<string, any>}}
35
+ */
36
+ export function ticketAnyway({ body, listOf, queue }: {
37
+ body: any;
38
+ listOf: (flow: string, runId: string) => ReturnType<typeof ticketListOf>;
39
+ queue: {
40
+ arriveAnyway: (a: {
41
+ flow: string;
42
+ runId: string;
43
+ number: number;
44
+ reason: string;
45
+ }) => {
46
+ ok: boolean;
47
+ say?: string;
48
+ started?: boolean;
49
+ };
50
+ };
51
+ }): {
52
+ status: number;
53
+ body: Record<string, any>;
54
+ };
55
+ /**
56
+ * The production queue seam: ONE `arrived` row (`recordAnyway`, the ledger's writer) in the job's schedule ledger, so the scheduler's queue starts the ticket as a new
57
+ * arrival under the job's normal cap. A job with no live ticket schedule is refused by name, at $0, with nothing written.
58
+ * M13 am3: a ticket schedule that is signed but OFF (`startAnyway`, the trigger door's one by-hand start) starts the ticket at once instead; it writes no row.
59
+ * @param {{scan: () => any[], now: () => number, startAnyway?: (a: {flow: string, number: number}) => {ok: boolean, say: string} | null}} a
60
+ * @returns {{arriveAnyway: (a: {flow: string, runId: string, number: number, reason: string}) => {ok: boolean, say?: string, started?: boolean}}}
61
+ */
62
+ export function arriveAnywayOf({ scan, now, startAnyway }: {
63
+ scan: () => any[];
64
+ now: () => number;
65
+ startAnyway?: (a: {
66
+ flow: string;
67
+ number: number;
68
+ }) => {
69
+ ok: boolean;
70
+ say: string;
71
+ } | null;
72
+ }): {
73
+ arriveAnyway: (a: {
74
+ flow: string;
75
+ runId: string;
76
+ number: number;
77
+ reason: string;
78
+ }) => {
79
+ ok: boolean;
80
+ say?: string;
81
+ started?: boolean;
82
+ };
83
+ };
84
+ /** the four groups, in the mockup's order: key, label, open at first. The page draws them; it types none of these words. */
85
+ export const TICKET_GROUPS: readonly {
86
+ key: string;
87
+ label: string;
88
+ open: boolean;
89
+ }[];
90
+ /** a run's sign -> its group. Running / stuck / expired / waiting all need a person or are still going: Needs you. */
91
+ export const GROUP_OF: Readonly<{
92
+ '[\u00B7]': "wait";
93
+ '[\u25B6]': "wait";
94
+ '[II]': "wait";
95
+ '[!]': "wait";
96
+ '[\u2713]': "done";
97
+ '[\u2013]': "skip";
98
+ '[\u2717]': "stop";
99
+ '[\u25A0]': "stop";
100
+ '[?]': "stop";
101
+ }>;
102
+ /** a "Run it anyway" reason: short, never blank. The same bar as a rerun's. */
103
+ export const ANYWAY_REASON_MAX: 500;
@@ -7,6 +7,11 @@ export function rolePrimitiveFor(frozenPath: any): "read" | "readDocx" | "addres
7
7
  * WIRED_VERBS (and, when `skills` is given, in a signed skill). Absence,
8
8
  * not refusal. Throws only if catalogue.json itself is unreadable. */
9
9
  export function wiredMenu(skills: any): import("./types.js").CatalogueEntry[];
10
+ /** M13 item 5: the job's MCP, as `resolvePrimitives` wants it: the signed server and every tool any step grants; `undefined` when no step has `mcpTools` */
11
+ export function stepMcp(declaration: any): {
12
+ server: any;
13
+ tools: any[];
14
+ } | undefined;
10
15
  /**
11
16
  * Resolve the granted tools for one step's model call. Never throws —
12
17
  * a verb absent from the catalogue, or present but unimplemented here, is
@@ -15,7 +20,7 @@ export function wiredMenu(skills: any): import("./types.js").CatalogueEntry[];
15
20
  *
16
21
  * @param {import('./types.js').CatalogueEntry[]} catalogue - `loadCatalogue().primitives` (or an injected test catalogue).
17
22
  * @param {string[]} grantedVerbs - `step.primitives`.
18
- * @param {{ runDir: string, inputs?: Array<{id:string, frozen:string}> }} ctx
23
+ * @param {{ runDir: string, inputs?: Array<{id:string, frozen:string}>, mcp?: {server: string, tools: string[]} }} ctx - `mcp` (`stepMcp`): the signed `<server>_<tool>` names the gate also allows (M13 item 5)
19
24
  * @returns {{ tools: Record<string, any>, reds: string[] }}
20
25
  */
21
26
  export function resolvePrimitives(catalogue: import("./types.js").CatalogueEntry[], grantedVerbs: string[], ctx: {
@@ -24,6 +29,10 @@ export function resolvePrimitives(catalogue: import("./types.js").CatalogueEntry
24
29
  id: string;
25
30
  frozen: string;
26
31
  }>;
32
+ mcp?: {
33
+ server: string;
34
+ tools: string[];
35
+ };
27
36
  }): {
28
37
  tools: Record<string, any>;
29
38
  reds: string[];
@@ -45,7 +54,10 @@ export function resolvePrimitives(catalogue: import("./types.js").CatalogueEntry
45
54
  * `instanceof` and records `{verb, path, rule}` on the attempt's audit row —
46
55
  * never parsed back out of the message string. */
47
56
  export class GateRefusal extends Error {
48
- constructor(verb: any, resolved: any, rule: any);
57
+ /** `tool: true` (M13 item 5): a refused MCP tool, `verb` is its name; it names no path, so it gets no filesystem wording */
58
+ constructor(verb: any, resolved: any, rule: any, { tool }?: {
59
+ tool?: boolean | undefined;
60
+ });
49
61
  verb: any;
50
62
  path: any;
51
63
  rule: any;
@@ -56,3 +68,4 @@ export class GateRefusal extends Error {
56
68
  * catalogue-present-but-unwired verb must refuse before any model call or
57
69
  * spend) imports this SAME set rather than keeping a second copy of the list. */
58
70
  export const WIRED_VERBS: Set<string>;
71
+ export function mcpToolName(server: any, tool: any): string;
package/types/runner.d.ts CHANGED
@@ -99,15 +99,21 @@ export function freezePage(dir: string, id: string, url: string, { fetchPage }?:
99
99
  * (never the original again after this) and return the manifest, which `runFlow` records as the `inputs` of `run.json` (M8b). An
100
100
  * unreadable source refuses by name. A source that is a web address
101
101
  * (M10 item 1) is fetched and frozen by `freezePage`, in the same manifest.
102
- * @param {string} runDir @param {Array<{id: string, path: string}>} sources
102
+ * @param {string} runDir @param {Array<{id: string, path: string, ticket?: {number: number, anyway?: true}}>} sources
103
103
  * M10b amendment 1: a CSV input named in `tableRoles` (the sheets a step's `close.sheet` reads) also gets its `tableSha` (bareguard's fingerprint of the table made
104
104
  * from the FROZEN copy) in its manifest entry - the ONE place it is written, once, with the run's inputs; every sheet check of the run uses this recorded value.
105
105
  * A sheet bareguard cannot read as a table refuses the run here, naming the input.
106
- * @param {{fetchPage?: (url: string) => Promise<{ok: true, text: string, url: string}|{ok: false, error: string}>, tableRoles?: string[]}} [o] */
106
+ * M12 piece 1b: a source with `ticket: {number}` is one ticket of the list at its `path`, read through the job's MCP tools (`mcp`, the declaration's `{server, tools}`) by
107
+ * `ticketRead` and frozen like a page; its manifest entry also carries `mcp`, the record of what the server exposed and each call made (kept in `run.json`, no new file).
108
+ * @param {{fetchPage?: (url: string) => Promise<{ok: true, text: string, url: string}|{ok: false, error: string}>, tableRoles?: string[], mcp?: {server: string, tools: string[]}, ticketRead?: typeof readTicketMcp, ticketFilter?: {priority?: string[], labels?: string[]}}} [o] */
107
109
  export function freezeInputs(runDir: string, sources: Array<{
108
110
  id: string;
109
111
  path: string;
110
- }>, { fetchPage, tableRoles }?: {
112
+ ticket?: {
113
+ number: number;
114
+ anyway?: true;
115
+ };
116
+ }>, { fetchPage, tableRoles, mcp, ticketRead, ticketFilter }?: {
111
117
  fetchPage?: (url: string) => Promise<{
112
118
  ok: true;
113
119
  text: string;
@@ -117,10 +123,20 @@ export function freezeInputs(runDir: string, sources: Array<{
117
123
  error: string;
118
124
  }>;
119
125
  tableRoles?: string[];
126
+ mcp?: {
127
+ server: string;
128
+ tools: string[];
129
+ };
130
+ ticketRead?: typeof readTicketMcp;
131
+ ticketFilter?: {
132
+ priority?: string[];
133
+ labels?: string[];
134
+ };
120
135
  }): Promise<{
121
136
  ok: boolean;
122
137
  red: string;
123
138
  manifest?: undefined;
139
+ skip?: undefined;
124
140
  } | {
125
141
  ok: boolean;
126
142
  manifest: (Record<string, any> | {
@@ -130,8 +146,35 @@ export function freezeInputs(runDir: string, sources: Array<{
130
146
  sha256: string;
131
147
  bytes: number;
132
148
  })[];
149
+ skip: string | null;
133
150
  red?: undefined;
134
151
  }>;
152
+ /**
153
+ * The sources a rerun re-freezes: each input's original source. M13 item 9.1: a ticket input's source is the ticket's own address; it goes back as its LIST address with the
154
+ * ticket mark, so the rerun reads the ticket through the job's MCP tools and the signed filter, not as a web page.
155
+ * @param {Array<{id: string, source: string, ticket?: {number: number}, filter?: {outcome?: string}}>} manifest
156
+ */
157
+ export function rerunSourcesOf(manifest: Array<{
158
+ id: string;
159
+ source: string;
160
+ ticket?: {
161
+ number: number;
162
+ };
163
+ filter?: {
164
+ outcome?: string;
165
+ };
166
+ }>): ({
167
+ id: string;
168
+ path: string;
169
+ ticket?: undefined;
170
+ } | {
171
+ id: string;
172
+ path: string;
173
+ ticket: {
174
+ anyway?: true | undefined;
175
+ number: number | undefined;
176
+ };
177
+ })[];
135
178
  /** The send target's folder (M4e amendment 1, "Destination is any folder").
136
179
  * An absolute `file:/abs/path` is that folder, anywhere on the machine. A
137
180
  * relative path keeps its M0/M2 meaning: joined onto the install folder and
@@ -216,79 +259,16 @@ export function readArtifactsMapChecked(runDir: any, ids: any, { docxRoles }?: {
216
259
  red: string;
217
260
  };
218
261
  /**
219
- * Run one step to green (or hitl pass-through), looping under strikes and
220
- * the attempt fallback. Returns `{ ok:true, artifact, attempts }` on success
221
- * or `{ ok:false, outcome, red }` on any halt. Appends one audit row per
222
- * attempt via `deps.recordAudit`. Never throws for a model/close failure —
223
- * only a programmer error (a malformed step, an unreachable branch) escapes.
224
- *
225
- * @param {object} opts
226
- * @param {any} opts.step
227
- * @param {Record<string, any>} [opts.primitivesMap]
228
- * @param {Record<string, any>} opts.readsMap
229
- * @param {string} opts.businessDate
230
- * @param {(executorContext:object, grantedTools:Record<string,any>, stepMeta?:{class:string|null}, seam?:{stopRequested?:() => boolean}) => Promise<any>} opts.modelStep
231
- * @param {{ value: number }} opts.spent
232
- * @param {number} opts.capUsd
233
- * @param {number} opts.ceilingUsd
234
- * @param {(row: any, modelOutput?: any) => void} opts.recordAudit
235
- * @param {string|null} [opts.initialGap]
236
- * @param {number} [opts.attemptOffset]
237
- * @param {(() => {text: string, ids: string[]}|null)|null} [opts.learnHints] - M8 am7: `stepHintsReader`'s closure (the drafter's one block function); asked only on a retry, redo or rerun try
238
- * @param {boolean} [opts.thinkingBox] - M4d am25: the job's "Thinking on" box as this run's copy keeps it (default off)
239
- * @param {() => string} [opts.now] - M4a-2: stamps each audit row's `at`;
240
- * defaults to the real wall clock.
241
- * @param {(() => boolean)|null} [opts.readStop] - amendment 7 item 8: the run's stop reader, asked before every try and (via modelStep's seam) every model call
242
- * @param {number} [opts.stepNo] - this step's 1-based number, for the words of a stop row
243
- * @param {string|null} [opts.prevStepId] - the id of step stepNo-1 (null for step 1): the step a "stopped after step N-1" row is filed under
244
- * @param {number} [opts.triesDone] - tries a Stop already closed on this step (they count against its limit)
245
- * @param {string|null} [opts.runDir] - M4d am29 item 2: the run's folder, where each try saves its checks
246
- * @returns {Promise<{ok:true, artifact:any, attempts:number, hitl?:boolean} | {ok:false, outcome:string, red:string, stop?:{where:string, book:Record<string, any>, step?:string|null}}>}
262
+ * One step's tries (`runStepTries`), with the step's signed MCP tools (M13 items 3 and 5): the bridge starts ONCE here, before the first try, with `allow` = exactly
263
+ * the step's `mcpTools` (any other tool does not exist for the run), and closes in a `finally` after the last. A server that is not configured, will not start or lacks a signed
264
+ * tool refuses by name at $0 before any provider call, in `readTicketMcp`'s own words (src/ticket-mcp.js). Each tool the model sees is the bridge's, bound to the run's gated entry
265
+ * (`resolvePrimitives`), so every call is the Gate's decision and the model step's diary row. A step with no `mcpTools` takes the plain path, untouched.
266
+ * @param {Parameters<typeof runStepTries>[0] & {mcpServer?: string|null}} opts - `mcpServer`: the job's signed `mcp.server`
267
+ * @returns {ReturnType<typeof runStepTries>}
247
268
  */
248
- export function runStepRalph({ step, primitivesMap, readsMap, businessDate, modelStep, spent, capUsd, ceilingUsd, recordAudit, initialGap, attemptOffset, thinkingBox, learnHints, now, readStop, stepNo, triesDone, runDir, prevStepId, }: {
249
- step: any;
250
- primitivesMap?: Record<string, any> | undefined;
251
- readsMap: Record<string, any>;
252
- businessDate: string;
253
- modelStep: (executorContext: object, grantedTools: Record<string, any>, stepMeta?: {
254
- class: string | null;
255
- }, seam?: {
256
- stopRequested?: () => boolean;
257
- }) => Promise<any>;
258
- spent: {
259
- value: number;
260
- };
261
- capUsd: number;
262
- ceilingUsd: number;
263
- recordAudit: (row: any, modelOutput?: any) => void;
264
- initialGap?: string | null | undefined;
265
- attemptOffset?: number | undefined;
266
- learnHints?: (() => {
267
- text: string;
268
- ids: string[];
269
- } | null) | null | undefined;
270
- thinkingBox?: boolean | undefined;
271
- now?: (() => string) | undefined;
272
- readStop?: (() => boolean) | null | undefined;
273
- stepNo?: number | undefined;
274
- prevStepId?: string | null | undefined;
275
- triesDone?: number | undefined;
276
- runDir?: string | null | undefined;
277
- }): Promise<{
278
- ok: true;
279
- artifact: any;
280
- attempts: number;
281
- hitl?: boolean;
282
- } | {
283
- ok: false;
284
- outcome: string;
285
- red: string;
286
- stop?: {
287
- where: string;
288
- book: Record<string, any>;
289
- step?: string | null;
290
- };
291
- }>;
269
+ export function runStepRalph({ mcpServer, ...opts }: Parameters<typeof runStepTries>[0] & {
270
+ mcpServer?: string | null;
271
+ }): ReturnType<typeof runStepTries>;
292
272
  /**
293
273
  * @param {object} opts
294
274
  * @param {string} opts.root - the flows root directory (M1's `readFlow` root).
@@ -553,3 +533,81 @@ export const STOP_FILE: "stop.request";
553
533
  export const HALT_FILE: "halt.json";
554
534
  /** where a failure of learnings work that must not stop the run is recorded (one appended row, in the run's own folder): the run-end tally (`recordRunNotes`) and the take of the draft's learnings record (`takeLearningsRecord`, in runFlow). The run itself is unaffected */
555
535
  export const LEARN_ERROR_FILE: "learn-error.jsonl";
536
+ import { readTicketMcp } from './ticket-mcp.js';
537
+ /**
538
+ * Run one step to green (or hitl pass-through), looping under strikes and
539
+ * the attempt fallback. Returns `{ ok:true, artifact, attempts }` on success
540
+ * or `{ ok:false, outcome, red }` on any halt. Appends one audit row per
541
+ * attempt via `deps.recordAudit`. Never throws for a model/close failure —
542
+ * only a programmer error (a malformed step, an unreachable branch) escapes.
543
+ *
544
+ * @param {object} opts
545
+ * @param {any} opts.step
546
+ * @param {Record<string, any>} [opts.primitivesMap]
547
+ * @param {Record<string, any>} opts.readsMap
548
+ * @param {string} opts.businessDate
549
+ * @param {(executorContext:object, grantedTools:Record<string,any>, stepMeta?:{class:string|null}, seam?:{stopRequested?:() => boolean}) => Promise<any>} opts.modelStep
550
+ * @param {{ value: number }} opts.spent
551
+ * @param {number} opts.capUsd
552
+ * @param {number} opts.ceilingUsd
553
+ * @param {(row: any, modelOutput?: any) => void} opts.recordAudit
554
+ * @param {string|null} [opts.initialGap]
555
+ * @param {number} [opts.attemptOffset]
556
+ * @param {(() => {text: string, ids: string[]}|null)|null} [opts.learnHints] - M8 am7: `stepHintsReader`'s closure (the drafter's one block function); asked only on a retry, redo or rerun try
557
+ * @param {boolean} [opts.thinkingBox] - M4d am25: the job's "Thinking on" box as this run's copy keeps it (default off)
558
+ * @param {() => string} [opts.now] - M4a-2: stamps each audit row's `at`;
559
+ * defaults to the real wall clock.
560
+ * @param {(() => boolean)|null} [opts.readStop] - amendment 7 item 8: the run's stop reader, asked before every try and (via modelStep's seam) every model call
561
+ * @param {number} [opts.stepNo] - this step's 1-based number, for the words of a stop row
562
+ * @param {string|null} [opts.prevStepId] - the id of step stepNo-1 (null for step 1): the step a "stopped after step N-1" row is filed under
563
+ * @param {number} [opts.triesDone] - tries a Stop already closed on this step (they count against its limit)
564
+ * @param {string|null} [opts.runDir] - M4d am29 item 2: the run's folder, where each try saves its checks
565
+ * @param {Record<string, any>} [opts.mcpGranted] - M13 item 5: this step's signed MCP tools, already bound to its bridge (`runStepRalph` builds them); handed to the model with the verbs
566
+ * @returns {Promise<{ok:true, artifact:any, attempts:number, hitl?:boolean} | {ok:false, outcome:string, red:string, stop?:{where:string, book:Record<string, any>, step?:string|null}}>}
567
+ */
568
+ declare function runStepTries({ step, primitivesMap, readsMap, businessDate, modelStep, spent, capUsd, ceilingUsd, recordAudit, initialGap, attemptOffset, thinkingBox, learnHints, now, readStop, stepNo, triesDone, runDir, prevStepId, mcpGranted, }: {
569
+ step: any;
570
+ primitivesMap?: Record<string, any> | undefined;
571
+ readsMap: Record<string, any>;
572
+ businessDate: string;
573
+ modelStep: (executorContext: object, grantedTools: Record<string, any>, stepMeta?: {
574
+ class: string | null;
575
+ }, seam?: {
576
+ stopRequested?: () => boolean;
577
+ }) => Promise<any>;
578
+ spent: {
579
+ value: number;
580
+ };
581
+ capUsd: number;
582
+ ceilingUsd: number;
583
+ recordAudit: (row: any, modelOutput?: any) => void;
584
+ initialGap?: string | null | undefined;
585
+ attemptOffset?: number | undefined;
586
+ learnHints?: (() => {
587
+ text: string;
588
+ ids: string[];
589
+ } | null) | null | undefined;
590
+ thinkingBox?: boolean | undefined;
591
+ now?: (() => string) | undefined;
592
+ readStop?: (() => boolean) | null | undefined;
593
+ stepNo?: number | undefined;
594
+ prevStepId?: string | null | undefined;
595
+ triesDone?: number | undefined;
596
+ runDir?: string | null | undefined;
597
+ mcpGranted?: Record<string, any> | undefined;
598
+ }): Promise<{
599
+ ok: true;
600
+ artifact: any;
601
+ attempts: number;
602
+ hitl?: boolean;
603
+ } | {
604
+ ok: false;
605
+ outcome: string;
606
+ red: string;
607
+ stop?: {
608
+ where: string;
609
+ book: Record<string, any>;
610
+ step?: string | null;
611
+ };
612
+ }>;
613
+ export {};
@@ -20,12 +20,18 @@ export function nextInWords(ms: number, now: number): string;
20
20
  * 3. a clock kind with a next slot; 4. a file kind that is armed; 5. not armed yet.
21
21
  * A last outcome of `refused` goes in front of 3-5, so a trigger that cannot start is never silent.
22
22
  * `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.
23
- * @param {{trigger: Trigger, armed: boolean, nextSlotMs: number|null, lastOutcome: any, waitingLine: number|null, now: number}} f
23
+ * 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.
24
+ * @param {{trigger: Trigger, armed: boolean, waiting?: boolean, lookProblem?: {at: number, why: string}|null, nextSlotMs: number|null, lastOutcome: any, waitingLine: number|null, now: number}} f
24
25
  * @returns {{text: string, red: boolean}}
25
26
  */
26
27
  export function scheduledNextFor(f: {
27
28
  trigger: Trigger;
28
29
  armed: boolean;
30
+ waiting?: boolean;
31
+ lookProblem?: {
32
+ at: number;
33
+ why: string;
34
+ } | null;
29
35
  nextSlotMs: number | null;
30
36
  lastOutcome: any;
31
37
  waitingLine: number | null;
@@ -39,7 +45,7 @@ export function catchUpWords(rec: any): "This run was a catch-up: it started mor
39
45
  /**
40
46
  * ENDED / NEXT of a finished run. Every outcome the history row can hold has a fixed sentence; an unknown one gets an honest fixed fallback
41
47
  * that names the code and guesses nothing. `null` when there is no ending (still running, waiting, or no history row and not died).
42
- * @param {{outcome: string|null, died?: boolean, line: number|null, destination: string|null, canResume: boolean, home?: string}} f
48
+ * @param {{outcome: string|null, died?: boolean, line: number|null, destination: string|null, canResume: boolean, home?: string, skipReason?: string}} f
43
49
  * @returns {{reason: string, next: string, rows?: Array<[string, string]>}|null}
44
50
  */
45
51
  export function endedWords(f: {
@@ -49,6 +55,7 @@ export function endedWords(f: {
49
55
  destination: string | null;
50
56
  canResume: boolean;
51
57
  home?: string;
58
+ skipReason?: string;
52
59
  }): {
53
60
  reason: string;
54
61
  next: string;
@@ -89,9 +96,10 @@ export function startedWords(rec: any, startMs: number | null, home?: string): s
89
96
  * - 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;
90
97
  * - refused: `refused: <why> · next: fix it in Cancel / modify schedule`, red until a later good start.
91
98
  * `next` otherwise: `next <day stamp>`, `next: waiting for a new file` (file schedule) or `next: not armed yet`.
92
- * @param {{trigger: Trigger|null, home?: string, last: {at: string, runId: string, outcome: string, catchUp: boolean}|null, nextSlotMs: number|null, armed: boolean, problem: any, nowMs?: number}} f
99
+ * 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).
100
+ * @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
93
101
  * `problem`: the newest fire when it started nothing (busy, monthly-exhausted, refused), else null.
94
- * @returns {{line1: string, line2: string|null, red: boolean}}
102
+ * @returns {{line1: string, line2: string|null, red: boolean, grey?: boolean}}
95
103
  */
96
104
  export function scheduleBlockWords(f: {
97
105
  trigger: Trigger | null;
@@ -104,12 +112,18 @@ export function scheduleBlockWords(f: {
104
112
  } | null;
105
113
  nextSlotMs: number | null;
106
114
  armed: boolean;
115
+ waiting?: boolean;
116
+ lookProblem?: {
117
+ at: number;
118
+ why: string;
119
+ } | null;
107
120
  problem: any;
108
121
  nowMs?: number;
109
122
  }): {
110
123
  line1: string;
111
124
  line2: string | null;
112
125
  red: boolean;
126
+ grey?: boolean;
113
127
  };
114
128
  /**
115
129
  * M9 am9 / am11: a run's Audit `schedule` section (one for every run of a job that has a schedule NOW; `null` when it has none). Folded head
@@ -152,6 +166,12 @@ export function needsLeftWords(left: {
152
166
  } | null): string | null;
153
167
  /** ENDED (am7 item 1): `10/14 08:16 · passed · Goal met.`. The stamp is the run's local end time; the word is the run's outcome word (none for a run ended on purpose). @param {string|null} at ISO @param {string|null} word @param {string} reason */
154
168
  export function endedLineWords(at: string | null, word: string | null, reason: string): string;
169
+ /** 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. */
170
+ export const SCHEDULE_WAITING_SAY: "Schedule waiting for a green run";
171
+ export function lookProblemWords(p: {
172
+ at: number;
173
+ why: string;
174
+ }): string;
155
175
  /** M9 am8 item 3: the busy sentence, in the busy row of `triggers.jsonl` and in the SCHEDULE block. One owner; the scheduler writes it, the words read it. */
156
176
  export const SCHEDULE_BUSY_SAY: "a run of this job was still working";
157
177
  export function startedNothing(row: any): any;
@@ -0,0 +1,104 @@
1
+ /** 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[]} */
2
+ export function userMcpServers(configPath?: string): string[];
3
+ /**
4
+ * 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
5
+ * 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.
6
+ * @param {string} role @returns {string[]}
7
+ */
8
+ export function ticketFactsLines(role: string): string[];
9
+ /** 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[]} */
10
+ export function mcpFactsLines(server: string, tools: string[]): string[];
11
+ /**
12
+ * 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
13
+ * `ticketFilter` and `ticketWatch`. The job's own `mcp` block and `flowType` are NOT offered: code sets them.
14
+ * @param {{flowType: 'mcp'|'tickets', tools: string[]}} o
15
+ */
16
+ export function ticketSchemaParts({ flowType, tools }: {
17
+ flowType: "mcp" | "tickets";
18
+ tools: string[];
19
+ }): {
20
+ top: {
21
+ ticketFilter?: undefined;
22
+ ticketWatch?: undefined;
23
+ };
24
+ step: {
25
+ mcpTools: {
26
+ type: string;
27
+ items: {
28
+ type: string;
29
+ enum: string[];
30
+ };
31
+ description: string;
32
+ };
33
+ };
34
+ } | {
35
+ top: {
36
+ ticketFilter: {
37
+ type: string;
38
+ properties: {
39
+ priority: {
40
+ type: string;
41
+ items: {
42
+ type: string;
43
+ enum: string[];
44
+ };
45
+ description: string;
46
+ };
47
+ labels: {
48
+ type: string;
49
+ items: {
50
+ type: string;
51
+ };
52
+ description: string;
53
+ };
54
+ };
55
+ additionalProperties: boolean;
56
+ description: string;
57
+ };
58
+ ticketWatch: {
59
+ type: string;
60
+ items: {
61
+ type: string;
62
+ enum: string[];
63
+ };
64
+ description: string;
65
+ };
66
+ };
67
+ step: {
68
+ mcpTools: {
69
+ type: string;
70
+ items: {
71
+ type: string;
72
+ enum: string[];
73
+ };
74
+ description: string;
75
+ };
76
+ };
77
+ };
78
+ /**
79
+ * 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
80
+ * check (`pick`, src/mcp-pick.js: `{ok, server, tools}` or `{ok:false, say}`).
81
+ * @param {{flowType: string, ticketSources: Array<{role: string}>, pick: any, servers: string[]}} o @returns {string[]}
82
+ */
83
+ export function ticketReds({ flowType, ticketSources, pick, servers }: {
84
+ flowType: string;
85
+ ticketSources: Array<{
86
+ role: string;
87
+ }>;
88
+ pick: any;
89
+ servers: string[];
90
+ }): string[];
91
+ /** the one tool the first slice reads a ticket with */
92
+ export const TICKET_TOOL: "issue_read";
93
+ export function isTicketListUrl(url: unknown): boolean;
94
+ export function ticketSourcesOf(sources: Array<{
95
+ kind?: string;
96
+ role: string;
97
+ path: string;
98
+ }>): {
99
+ kind?: string;
100
+ role: string;
101
+ path: string;
102
+ }[];
103
+ /** the one tool a Tickets job looks for new tickets with (src/panel/authortrigger.js) */
104
+ export const LOOK_TOOL: "list_issues";