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.
Files changed (67) hide show
  1. package/bin/fwdloop +27 -8
  2. package/package.json +2 -2
  3. package/src/authoring.js +11 -1
  4. package/src/canrun.js +19 -16
  5. package/src/config.js +18 -0
  6. package/src/declaration.js +32 -2
  7. package/src/drafter.js +29 -14
  8. package/src/flow.js +2 -1
  9. package/src/launcher.js +4 -2
  10. package/src/learnstore.js +2 -1
  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 +19 -19
  17. package/src/panel/authorcard.js +35 -0
  18. package/src/panel/authorflows.js +18 -14
  19. package/src/panel/authortrigger.js +241 -84
  20. package/src/panel/data.js +89 -6
  21. package/src/panel/index.html +552 -157
  22. package/src/panel/jobgrid.js +127 -0
  23. package/src/panel/scheduler.js +8 -2
  24. package/src/panel/server.js +15 -6
  25. package/src/panel/settings.js +119 -4
  26. package/src/panel/tickets.js +12 -7
  27. package/src/primitives.js +34 -5
  28. package/src/runner.js +88 -15
  29. package/src/summary-words.js +15 -3
  30. package/src/ticket-draft.js +40 -42
  31. package/src/ticket-labels.js +10 -0
  32. package/src/ticket-mcp.js +33 -10
  33. package/src/ticket-next.js +33 -0
  34. package/src/ticket-shape.js +9 -0
  35. package/src/trigger-clock.js +4 -4
  36. package/src/trigger-files.js +3 -3
  37. package/src/trigger-tickets.js +41 -12
  38. package/types/authoring.d.ts +5 -1
  39. package/types/canrun.d.ts +5 -12
  40. package/types/config.d.ts +6 -0
  41. package/types/declaration.d.ts +8 -0
  42. package/types/drafter.d.ts +447 -38
  43. package/types/mcp-checks.d.ts +8 -0
  44. package/types/mcp-pick.d.ts +23 -0
  45. package/types/mcp-sources.d.ts +51 -0
  46. package/types/mcp-use.d.ts +12 -0
  47. package/types/natural.d.ts +2 -0
  48. package/types/panel/author.d.ts +36 -0
  49. package/types/panel/authorcard.d.ts +11 -0
  50. package/types/panel/authorflows.d.ts +9 -1
  51. package/types/panel/authortrigger.d.ts +73 -7
  52. package/types/panel/data.d.ts +56 -2
  53. package/types/panel/jobgrid.d.ts +109 -0
  54. package/types/panel/server.d.ts +5 -1
  55. package/types/panel/settings.d.ts +3 -2
  56. package/types/panel/tickets.d.ts +26 -4
  57. package/types/primitives.d.ts +15 -2
  58. package/types/runner.d.ts +112 -72
  59. package/types/summary-words.d.ts +22 -3
  60. package/types/ticket-draft.d.ts +40 -32
  61. package/types/ticket-labels.d.ts +6 -0
  62. package/types/ticket-mcp.d.ts +18 -1
  63. package/types/ticket-next.d.ts +23 -0
  64. package/types/ticket-shape.d.ts +5 -0
  65. package/types/trigger-clock.d.ts +4 -3
  66. package/types/trigger-files.d.ts +1 -1
  67. package/types/trigger-tickets.d.ts +18 -4
package/types/runner.d.ts CHANGED
@@ -149,6 +149,32 @@ export function freezeInputs(runDir: string, sources: Array<{
149
149
  skip: string | null;
150
150
  red?: undefined;
151
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
+ })[];
152
178
  /** The send target's folder (M4e amendment 1, "Destination is any folder").
153
179
  * An absolute `file:/abs/path` is that folder, anywhere on the machine. A
154
180
  * relative path keeps its M0/M2 meaning: joined onto the install folder and
@@ -233,79 +259,16 @@ export function readArtifactsMapChecked(runDir: any, ids: any, { docxRoles }?: {
233
259
  red: string;
234
260
  };
235
261
  /**
236
- * Run one step to green (or hitl pass-through), looping under strikes and
237
- * the attempt fallback. Returns `{ ok:true, artifact, attempts }` on success
238
- * or `{ ok:false, outcome, red }` on any halt. Appends one audit row per
239
- * attempt via `deps.recordAudit`. Never throws for a model/close failure —
240
- * only a programmer error (a malformed step, an unreachable branch) escapes.
241
- *
242
- * @param {object} opts
243
- * @param {any} opts.step
244
- * @param {Record<string, any>} [opts.primitivesMap]
245
- * @param {Record<string, any>} opts.readsMap
246
- * @param {string} opts.businessDate
247
- * @param {(executorContext:object, grantedTools:Record<string,any>, stepMeta?:{class:string|null}, seam?:{stopRequested?:() => boolean}) => Promise<any>} opts.modelStep
248
- * @param {{ value: number }} opts.spent
249
- * @param {number} opts.capUsd
250
- * @param {number} opts.ceilingUsd
251
- * @param {(row: any, modelOutput?: any) => void} opts.recordAudit
252
- * @param {string|null} [opts.initialGap]
253
- * @param {number} [opts.attemptOffset]
254
- * @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
255
- * @param {boolean} [opts.thinkingBox] - M4d am25: the job's "Thinking on" box as this run's copy keeps it (default off)
256
- * @param {() => string} [opts.now] - M4a-2: stamps each audit row's `at`;
257
- * defaults to the real wall clock.
258
- * @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
259
- * @param {number} [opts.stepNo] - this step's 1-based number, for the words of a stop row
260
- * @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
261
- * @param {number} [opts.triesDone] - tries a Stop already closed on this step (they count against its limit)
262
- * @param {string|null} [opts.runDir] - M4d am29 item 2: the run's folder, where each try saves its checks
263
- * @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>}
264
268
  */
265
- export function runStepRalph({ step, primitivesMap, readsMap, businessDate, modelStep, spent, capUsd, ceilingUsd, recordAudit, initialGap, attemptOffset, thinkingBox, learnHints, now, readStop, stepNo, triesDone, runDir, prevStepId, }: {
266
- step: any;
267
- primitivesMap?: Record<string, any> | undefined;
268
- readsMap: Record<string, any>;
269
- businessDate: string;
270
- modelStep: (executorContext: object, grantedTools: Record<string, any>, stepMeta?: {
271
- class: string | null;
272
- }, seam?: {
273
- stopRequested?: () => boolean;
274
- }) => Promise<any>;
275
- spent: {
276
- value: number;
277
- };
278
- capUsd: number;
279
- ceilingUsd: number;
280
- recordAudit: (row: any, modelOutput?: any) => void;
281
- initialGap?: string | null | undefined;
282
- attemptOffset?: number | undefined;
283
- learnHints?: (() => {
284
- text: string;
285
- ids: string[];
286
- } | null) | null | undefined;
287
- thinkingBox?: boolean | undefined;
288
- now?: (() => string) | undefined;
289
- readStop?: (() => boolean) | null | undefined;
290
- stepNo?: number | undefined;
291
- prevStepId?: string | null | undefined;
292
- triesDone?: number | undefined;
293
- runDir?: string | null | undefined;
294
- }): Promise<{
295
- ok: true;
296
- artifact: any;
297
- attempts: number;
298
- hitl?: boolean;
299
- } | {
300
- ok: false;
301
- outcome: string;
302
- red: string;
303
- stop?: {
304
- where: string;
305
- book: Record<string, any>;
306
- step?: string | null;
307
- };
308
- }>;
269
+ export function runStepRalph({ mcpServer, ...opts }: Parameters<typeof runStepTries>[0] & {
270
+ mcpServer?: string | null;
271
+ }): ReturnType<typeof runStepTries>;
309
272
  /**
310
273
  * @param {object} opts
311
274
  * @param {string} opts.root - the flows root directory (M1's `readFlow` root).
@@ -571,3 +534,80 @@ export const HALT_FILE: "halt.json";
571
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 */
572
535
  export const LEARN_ERROR_FILE: "learn-error.jsonl";
573
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;
@@ -90,9 +96,10 @@ export function startedWords(rec: any, startMs: number | null, home?: string): s
90
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;
91
97
  * - refused: `refused: <why> · next: fix it in Cancel / modify schedule`, red until a later good start.
92
98
  * `next` otherwise: `next <day stamp>`, `next: waiting for a new file` (file schedule) or `next: not armed yet`.
93
- * @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
94
101
  * `problem`: the newest fire when it started nothing (busy, monthly-exhausted, refused), else null.
95
- * @returns {{line1: string, line2: string|null, red: boolean}}
102
+ * @returns {{line1: string, line2: string|null, red: boolean, grey?: boolean}}
96
103
  */
97
104
  export function scheduleBlockWords(f: {
98
105
  trigger: Trigger | null;
@@ -105,12 +112,18 @@ export function scheduleBlockWords(f: {
105
112
  } | null;
106
113
  nextSlotMs: number | null;
107
114
  armed: boolean;
115
+ waiting?: boolean;
116
+ lookProblem?: {
117
+ at: number;
118
+ why: string;
119
+ } | null;
108
120
  problem: any;
109
121
  nowMs?: number;
110
122
  }): {
111
123
  line1: string;
112
124
  line2: string | null;
113
125
  red: boolean;
126
+ grey?: boolean;
114
127
  };
115
128
  /**
116
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
@@ -153,6 +166,12 @@ export function needsLeftWords(left: {
153
166
  } | null): string | null;
154
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 */
155
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;
156
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. */
157
176
  export const SCHEDULE_BUSY_SAY: "a run of this job was still working";
158
177
  export function startedNothing(row: any): any;
@@ -1,37 +1,38 @@
1
- /** 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}[]} */
2
- export function ticketRefusals(ticketRole: string | null, body: any): {
3
- field: string;
4
- say: string;
5
- }[];
6
- /** 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[]} */
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[]} */
7
2
  export function userMcpServers(configPath?: string): string[];
8
3
  /**
9
- * The lines under "Inputs" for one ticket role. The first is F90c's, word for word; the rest tell the drafter the two optional fields it may suggest.
10
- * @param {string} role @param {string[]} servers @returns {string[]}
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
11
15
  */
12
- export function ticketFactsLines(role: string, servers: string[]): string[];
13
- /** the schema parts a job with a ticket role adds: top-level `mcp` and `ticketFilter`, per-step `mcpTools` @param {string[]} servers */
14
- export function ticketSchemaParts(servers: string[]): {
16
+ export function ticketSchemaParts({ flowType, tools }: {
17
+ flowType: "mcp" | "tickets";
18
+ tools: string[];
19
+ }): {
15
20
  top: {
16
- mcp: {
21
+ ticketFilter?: undefined;
22
+ ticketWatch?: undefined;
23
+ };
24
+ step: {
25
+ mcpTools: {
17
26
  type: string;
18
- properties: {
19
- server: {
20
- type: string;
21
- enum: string[];
22
- };
23
- tools: {
24
- type: string;
25
- items: {
26
- type: string;
27
- enum: string[];
28
- };
29
- };
27
+ items: {
28
+ type: string;
29
+ enum: string[];
30
30
  };
31
- required: string[];
32
- additionalProperties: boolean;
33
31
  description: string;
34
32
  };
33
+ };
34
+ } | {
35
+ top: {
35
36
  ticketFilter: {
36
37
  type: string;
37
38
  properties: {
@@ -75,12 +76,18 @@ export function ticketSchemaParts(servers: string[]): {
75
76
  };
76
77
  };
77
78
  /**
78
- * Reds a draft with a ticket role must not pass with: no `mcp`, a server the person's config does not have, or no step that reads the ticket and holds the tool.
79
- * @param {Record<string, any>} declaration @param {Array<{role: string}>} ticketSources @param {string[]} servers @returns {string[]}
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[]}
80
82
  */
81
- export function ticketReds(declaration: Record<string, any>, ticketSources: Array<{
82
- role: string;
83
- }>, servers: string[]): string[];
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[];
84
91
  /** the one tool the first slice reads a ticket with */
85
92
  export const TICKET_TOOL: "issue_read";
86
93
  export function isTicketListUrl(url: unknown): boolean;
@@ -93,4 +100,5 @@ export function ticketSourcesOf(sources: Array<{
93
100
  role: string;
94
101
  path: string;
95
102
  }[];
96
- export function ticketNumberOf(v: unknown): number | null;
103
+ /** the one tool a Tickets job looks for new tickets with (src/panel/authortrigger.js) */
104
+ export const LOOK_TOOL: "list_issues";
@@ -17,6 +17,12 @@ export function readTicketFields(text: string): {
17
17
  } | {
18
18
  ok: false;
19
19
  };
20
+ /**
21
+ * 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`
22
+ * 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.
23
+ * @param {any} entry @returns {boolean}
24
+ */
25
+ export function filterUnsure(entry: any): boolean;
20
26
  /**
21
27
  * @param {{text: string, filter?: {priority?: string[], labels?: string[]}}} a `filter` = the job's signed `ticketFilter` (or absent)
22
28
  * @returns {{outcome: 'run', unsure?: string}|{outcome: 'skip', reason: string}}
@@ -1,10 +1,19 @@
1
+ /**
2
+ * 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,
3
+ * the one decider), or `~/.mcp.json` when no place has it. `remote` true = the winner has no start command (listed, not usable).
4
+ * @param {string} server @param {string} [explicit] @returns {{ file: string, remote: boolean }}
5
+ */
6
+ export function configForServer(server: string, explicit?: string): {
7
+ file: string;
8
+ remote: boolean;
9
+ };
1
10
  /**
2
11
  * Read ticket `number` of the list at `listUrl` with the job's `issue_read`.
3
12
  * @param {{listUrl: string, number: number, mcp: {server: string, tools: string[]}, configPath?: string, timeoutMs?: number}} o
4
13
  * @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}>}
5
14
  * `record` is what the run keeps (in its `run.json` input entry): what the server exposed and lacked, and each call made.
6
15
  */
7
- export function readTicketMcp({ listUrl, number, mcp, configPath, timeoutMs }: {
16
+ export function readTicketMcp({ listUrl, number, mcp, configPath: explicitConfig, timeoutMs }: {
8
17
  listUrl: string;
9
18
  number: number;
10
19
  mcp: {
@@ -35,6 +44,14 @@ export function readTicketMcp({ listUrl, number, mcp, configPath, timeoutMs }: {
35
44
  ok: false;
36
45
  error: string;
37
46
  }>;
47
+ /** 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 */
48
+ export const MCP_PASS_ENV: string[];
49
+ export function mcpStartOpts(): {
50
+ passEnv: string[];
51
+ cwd: string;
52
+ };
53
+ export function startRefusal(server: string, e: any): string;
38
54
  export function USER_MCP_CONFIG(): string;
55
+ export function remoteRefusal(server: string): string;
39
56
  export function firstLine(e: any): string;
40
57
  export function isDeviceLogin(text: any): any;
@@ -0,0 +1,23 @@
1
+ /** the ticket numbers this job's runs have read @param {string} flowDir @returns {Set<number>} */
2
+ export function ranTicketNumbers(flowDir: string): Set<number>;
3
+ /**
4
+ * @param {{flowDir: string, listUrl: string, mcp: {server: string, tool: string}, configPath?: string, look?: typeof lookTickets}} o `look` is a test seam
5
+ * @returns {Promise<{ok: true, number: number} | {ok: false, say: string}>}
6
+ */
7
+ export function newestUnrunTicket({ flowDir, listUrl, mcp, configPath, look }: {
8
+ flowDir: string;
9
+ listUrl: string;
10
+ mcp: {
11
+ server: string;
12
+ tool: string;
13
+ };
14
+ configPath?: string;
15
+ look?: typeof lookTickets;
16
+ }): Promise<{
17
+ ok: true;
18
+ number: number;
19
+ } | {
20
+ ok: false;
21
+ say: string;
22
+ }>;
23
+ import { lookTickets } from './trigger-tickets.js';
@@ -23,3 +23,8 @@ export function ticketListsOf(arbiter: {
23
23
  export const WATCHABLE: readonly string[];
24
24
  /** the shape of a ticket list address: owner and repo are the two groups */
25
25
  export const LIST_URL: RegExp;
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: 9999999999;
28
+ export function isTicketNumber(n: unknown): n is number;
29
+ /** The words every refusal of a ticket number uses. */
30
+ export const TICKET_NUMBER_WORDS: string;
@@ -22,15 +22,15 @@ export function due(schedule: Schedule, rows: ClockRow[], now: number): Due;
22
22
  export function nextSlot(schedule: Schedule, afterMs: number): number;
23
23
  /** @param {string} file @param {string} [sig] M9 am20: only the rows of that schedule signing (the one schedule ledger carries every signing's rows); absent = every row @returns {ClockRow[]} every row on disk that parses, oldest first; a missing file is no rows; a line a crash tore mid-append is skipped (`appendOnce` starts each append on a fresh line, so it never glues onto the next row). */
24
24
  export function readRows(file: string, sig?: string): ClockRow[];
25
- /** The trigger was set at `now`: no slot before this ever fires. @param {string} file @param {number} now @param {string} [sig] */
26
- export function armTrigger(file: string, now: number, sig?: string): void;
25
+ /** 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] */
26
+ export function armTrigger(file: string, now: number, sig?: string, ticketN?: number): void;
27
27
  /**
28
28
  * Record that the run for this due slot is starting. Call BEFORE starting the run: a crash loses a run, never doubles one.
29
29
  * @param {string} file @param {Due} d the result of `due` with fire true @param {number} now @param {string} [sig]
30
30
  */
31
31
  export function recordFire(file: string, d: Due, now: number, sig?: string): void;
32
32
  /** @typedef {{kind:'daily'|'weekdays', hour:number, minute:number} | {kind:'weekly', day:string, hour:number, minute:number}} Schedule */
33
- /** @typedef {{id:string, kind:'armed'|'fire', at:number, slot?:number, catchUp?:boolean, missed?:number, sig?:string}} ClockRow */
33
+ /** @typedef {{id:string, kind:'armed'|'fire', at:number, slot?:number, catchUp?:boolean, missed?:number, sig?:string, ticketN?:number}} ClockRow */
34
34
  /** @typedef {{fire:boolean, catchUp:boolean, missed:number, slot?:number}} Due */
35
35
  /** A slot seen MORE than this after its set time is a catch-up (M9 am2 item 1). Exactly this late is on time. */
36
36
  export const GRACE_MS: 120000;
@@ -52,6 +52,7 @@ export type ClockRow = {
52
52
  catchUp?: boolean;
53
53
  missed?: number;
54
54
  sig?: string;
55
+ ticketN?: number;
55
56
  };
56
57
  export type Due = {
57
58
  fire: boolean;
@@ -14,7 +14,7 @@ export function recordDropped(ledger: string, item: {
14
14
  id?: string;
15
15
  }, why: "deleted" | "changed" | "schedule-changed" | "carried", at: number, sig?: string): boolean;
16
16
  /**
17
- * The queue: arrived and neither ran nor dropped, oldest arrival first. Identical arrival times: by name, then by sha (deterministic).
17
+ * 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`).
18
18
  * @param {SeenRow[]} rows @returns {(SeenRow & {path:string})[]}
19
19
  */
20
20
  export function queueOf(rows: SeenRow[]): (SeenRow & {
@@ -12,10 +12,12 @@ export function reasonFor(prev: {
12
12
  * 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
13
13
  * 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`.
14
14
  * Every failure is `{ok:false, error}` naming its cause, at $0; none reads as "0 new".
15
- * @param {{listUrl: string, mcp: {server: string, tool: string}, configPath?: string, seen: Set<number>|null, last: Map<number, {state: string, labels: string[]}>, watch: string[], perPage?: number, timeoutMs?: number}} o
16
- * @returns {Promise<{ok: true, first: boolean, 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}>}
15
+ * 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
16
+ * every ticket that came in after that run started is seen; `recordLook` then baselines the ones up to `cut` and lets the rest arrive.
17
+ * @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
18
+ * @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}>}
17
19
  */
18
- export function lookTickets({ listUrl, mcp, configPath, seen, last, watch, perPage, timeoutMs, }: {
20
+ export function lookTickets({ listUrl, mcp, configPath: explicitConfig, seen, last, watch, cut, perPage, timeoutMs, }: {
19
21
  listUrl: string;
20
22
  mcp: {
21
23
  server: string;
@@ -28,11 +30,14 @@ export function lookTickets({ listUrl, mcp, configPath, seen, last, watch, perPa
28
30
  labels: string[];
29
31
  }>;
30
32
  watch: string[];
33
+ cut?: number;
31
34
  perPage?: number;
32
35
  timeoutMs?: number;
33
36
  }): Promise<{
34
37
  ok: true;
35
38
  first: boolean;
39
+ cut?: number;
40
+ ignored?: number[];
36
41
  found: Array<{
37
42
  number: number;
38
43
  state: string;
@@ -57,6 +62,15 @@ export function lastSeen(ledger: string, sig: string): Map<number, {
57
62
  state: string;
58
63
  labels: string[];
59
64
  }>;
65
+ /** Has this signing had its first look (its baseline written)? @param {string} ledger @param {string} sig */
66
+ /**
67
+ * 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
68
+ * (its `looked`, `baseline` or `arrived` row). @param {import('./trigger-files.js').SeenRow[]} rows @returns {{at: number, why: string}|null}
69
+ */
70
+ export function lookProblemOf(rows: import("./trigger-files.js").SeenRow[]): {
71
+ at: number;
72
+ why: string;
73
+ } | null;
60
74
  /**
61
75
  * Write what a look found, once. First look: a `baseline` row per ticket on the page (never runs). Later: an `arrived` row per new ticket, oldest first (its arrival
62
76
  * time is this clock), and one `arrived` row per watched change with its `reason`. A look that could not read writes one `unreadable` row with its cause.
@@ -88,4 +102,4 @@ export function watchedOf(i: any): {
88
102
  state: string;
89
103
  labels: any;
90
104
  };
91
- export function hasBaseline(ledger: string, sig: string): boolean;
105
+ export function hasBaseline(ledger: any, sig: any): boolean;