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.
Files changed (105) hide show
  1. package/README.md +1 -1
  2. package/bin/fwdloop +54 -13
  3. package/package.json +3 -3
  4. package/src/ask.js +1 -1
  5. package/src/audit-fold.js +9 -1
  6. package/src/authoring.js +22 -5
  7. package/src/canrun.js +19 -16
  8. package/src/checked.js +5 -2
  9. package/src/checkpick.js +257 -0
  10. package/src/checkwords.js +24 -0
  11. package/src/closers.js +8 -1
  12. package/src/config.js +18 -0
  13. package/src/declaration.js +85 -5
  14. package/src/drafter.js +143 -47
  15. package/src/flow.js +2 -1
  16. package/src/launcher.js +4 -2
  17. package/src/learn.js +1 -1
  18. package/src/learnstore.js +8 -7
  19. package/src/mcp-checks.js +50 -0
  20. package/src/mcp-pick.js +33 -0
  21. package/src/mcp-sources.js +84 -0
  22. package/src/mcp-use.js +54 -0
  23. package/src/memo.js +120 -0
  24. package/src/model-step.js +89 -17
  25. package/src/natural.js +23 -0
  26. package/src/pageask.js +9 -6
  27. package/src/pagedropwords.js +9 -0
  28. package/src/panel/author.js +50 -28
  29. package/src/panel/authorcard.js +86 -2
  30. package/src/panel/authorflows.js +18 -14
  31. package/src/panel/authortrigger.js +241 -84
  32. package/src/panel/data.js +99 -11
  33. package/src/panel/index.html +683 -210
  34. package/src/panel/jobgrid.js +127 -0
  35. package/src/panel/result.js +28 -7
  36. package/src/panel/scheduler.js +8 -2
  37. package/src/panel/server.js +17 -7
  38. package/src/panel/settings.js +119 -4
  39. package/src/panel/tickets.js +12 -7
  40. package/src/pickrecord.js +146 -0
  41. package/src/plain-checks.js +1 -0
  42. package/src/primitives.js +34 -5
  43. package/src/provider.js +4 -1
  44. package/src/runfile.js +4 -2
  45. package/src/runner.js +170 -45
  46. package/src/send.js +71 -4
  47. package/src/setup.js +13 -1
  48. package/src/summary-words.js +15 -3
  49. package/src/ticket-draft.js +40 -42
  50. package/src/ticket-labels.js +10 -0
  51. package/src/ticket-mcp.js +33 -10
  52. package/src/ticket-next.js +33 -0
  53. package/src/ticket-shape.js +9 -0
  54. package/src/trigger-clock.js +4 -4
  55. package/src/trigger-files.js +3 -3
  56. package/src/trigger-tickets.js +41 -12
  57. package/types/ask.d.ts +2 -1
  58. package/types/audit-fold.d.ts +13 -2
  59. package/types/authoring.d.ts +10 -2
  60. package/types/canrun.d.ts +5 -12
  61. package/types/checked.d.ts +7 -2
  62. package/types/checkpick.d.ts +149 -0
  63. package/types/checkwords.d.ts +14 -0
  64. package/types/closers.d.ts +2 -1
  65. package/types/config.d.ts +6 -0
  66. package/types/declaration.d.ts +17 -0
  67. package/types/drafter.d.ts +446 -50
  68. package/types/learn.d.ts +1 -0
  69. package/types/learnstore.d.ts +2 -3
  70. package/types/mcp-checks.d.ts +8 -0
  71. package/types/mcp-pick.d.ts +23 -0
  72. package/types/mcp-sources.d.ts +51 -0
  73. package/types/mcp-use.d.ts +12 -0
  74. package/types/memo.d.ts +15 -0
  75. package/types/model-step.d.ts +5 -0
  76. package/types/natural.d.ts +2 -0
  77. package/types/pageask.d.ts +9 -2
  78. package/types/pagedropwords.d.ts +1 -0
  79. package/types/panel/author.d.ts +37 -1
  80. package/types/panel/authorcard.d.ts +52 -0
  81. package/types/panel/authorflows.d.ts +9 -1
  82. package/types/panel/authortrigger.d.ts +73 -7
  83. package/types/panel/data.d.ts +56 -2
  84. package/types/panel/jobgrid.d.ts +109 -0
  85. package/types/panel/result.d.ts +9 -3
  86. package/types/panel/server.d.ts +5 -1
  87. package/types/panel/settings.d.ts +3 -2
  88. package/types/panel/tickets.d.ts +26 -4
  89. package/types/pickrecord.d.ts +88 -0
  90. package/types/primitives.d.ts +15 -2
  91. package/types/runfile.d.ts +7 -2
  92. package/types/runner.d.ts +128 -77
  93. package/types/send.d.ts +10 -2
  94. package/types/setup.d.ts +1 -56
  95. package/types/summary-words.d.ts +22 -3
  96. package/types/ticket-draft.d.ts +40 -32
  97. package/types/ticket-labels.d.ts +6 -0
  98. package/types/ticket-mcp.d.ts +18 -1
  99. package/types/ticket-next.d.ts +23 -0
  100. package/types/ticket-shape.d.ts +5 -0
  101. package/types/trigger-clock.d.ts +4 -3
  102. package/types/trigger-files.d.ts +1 -1
  103. package/types/trigger-tickets.d.ts +18 -4
  104. package/src/attemptdiff.js +0 -118
  105. package/types/attemptdiff.d.ts +0 -38
@@ -3,6 +3,12 @@
3
3
  * @param {any} arbiter @returns {boolean}
4
4
  */
5
5
  export function isResultRun(arbiter: any): boolean;
6
+ /**
7
+ * M15 item 1: the ONE decider of the Result tab and of its cards. Every job has it; a Tickets MCP job keeps what it had (M13 am2: the grid, and M10's cards only when
8
+ * it reads a page, a CSV or a .docx). Read off the signed declaration and arbiter.
9
+ * @param {any} arbiter @param {any} declaration @returns {boolean}
10
+ */
11
+ export function hasResultCards(arbiter: any, declaration: any): boolean;
6
12
  /** The run's check type: its distinct close classes, in step order (`hitl + softgreen`). `—` for a declaration with none.
7
13
  * @param {any} declaration @returns {string} */
8
14
  export function checkTypeOf(declaration: any): string;
@@ -55,9 +61,9 @@ export function readDelivered(rec: {
55
61
  buf: null;
56
62
  };
57
63
  /**
58
- * The files this run's signed sends wrote: for each signed send whose send step ended green in the audit, the file `<flow>-<runId>-<emits>.json`
59
- * in the signed folder, with the sha256 the human's accept recorded for the ask that send reads (`readAcceptedHashesByEmits`, the same record the
60
- * send itself checked). No accepted hash = recorded as null, which reads as "changed", never as ok.
64
+ * The files this run's signed sends wrote: for each signed send whose send step ended green in the audit, the file `<flow>-<runId>-<emits>.md`
65
+ * in the signed folder with the sha256 the send recorded for it (M15), or, for a send older than M15, `.json` with the sha256 the human's accept recorded for the ask that
66
+ * send reads (`readAcceptedHashesByEmits`, the same record the send itself checked). No accepted hash = recorded as null, which reads as "changed", never as ok.
61
67
  * @returns {{path: string, dir: string|null, name: string, sha256: string|null}[]}
62
68
  */
63
69
  export function deliveredOf({ arbiter, declaration, runDir, root, flow, runId, auditRows, }: {
@@ -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, ticketQueue: {arriveAnyway: Function} }} 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;
@@ -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>;
@@ -30,7 +30,7 @@ export function ticketListOf({ flowDir, runId, runIdsOf, glyphOf, atOf, readSche
30
30
  /**
31
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
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}}}} a
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
34
  * @returns {{status: number, body: Record<string, any>}}
35
35
  */
36
36
  export function ticketAnyway({ body, listOf, queue }: {
@@ -45,6 +45,7 @@ export function ticketAnyway({ body, listOf, queue }: {
45
45
  }) => {
46
46
  ok: boolean;
47
47
  say?: string;
48
+ started?: boolean;
48
49
  };
49
50
  };
50
51
  }): {
@@ -54,12 +55,20 @@ export function ticketAnyway({ body, listOf, queue }: {
54
55
  /**
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
56
57
  * arrival under the job's normal cap. A job with no live ticket schedule is refused by name, at $0, with nothing written.
57
- * @param {{scan: () => any[], now: () => number}} a
58
- * @returns {{arriveAnyway: (a: {flow: string, runId: string, number: number, reason: string}) => {ok: boolean, say?: string}}}
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}}}
59
61
  */
60
- export function arriveAnywayOf({ scan, now }: {
62
+ export function arriveAnywayOf({ scan, now, startAnyway }: {
61
63
  scan: () => any[];
62
64
  now: () => number;
65
+ startAnyway?: (a: {
66
+ flow: string;
67
+ number: number;
68
+ }) => {
69
+ ok: boolean;
70
+ say: string;
71
+ } | null;
63
72
  }): {
64
73
  arriveAnyway: (a: {
65
74
  flow: string;
@@ -69,6 +78,7 @@ export function arriveAnywayOf({ scan, now }: {
69
78
  }) => {
70
79
  ok: boolean;
71
80
  say?: string;
81
+ started?: boolean;
72
82
  };
73
83
  };
74
84
  /** the four groups, in the mockup's order: key, label, open at first. The page draws them; it types none of these words. */
@@ -77,5 +87,17 @@ export const TICKET_GROUPS: readonly {
77
87
  label: string;
78
88
  open: boolean;
79
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
+ }>;
80
102
  /** a "Run it anyway" reason: short, never blank. The same bar as a rerun's. */
81
103
  export const ANYWAY_REASON_MAX: 500;
@@ -0,0 +1,88 @@
1
+ /**
2
+ * The key of every job line: its own words, plus how many lines before it have the same words (equal lines match in their order).
3
+ * @param {{n: number, text: string}[]} lines @returns {Map<number, {lineWords: string, occurrence: number}>}
4
+ */
5
+ export function lineKeys(lines: {
6
+ n: number;
7
+ text: string;
8
+ }[]): Map<number, {
9
+ lineWords: string;
10
+ occurrence: number;
11
+ }>;
12
+ /**
13
+ * The entries for answers just given, numbered on THIS card (the answer redraft's card: its line and rule numbers are the ones the asks carried).
14
+ * @param {{n: number, text: string}[]} lines @param {Rule[]} rules
15
+ * @param {{line: number, rule: number, check?: Record<string, any>|null, added?: string|null, own?: boolean}[]} picks @param {{line: number, rule: number}[]} left
16
+ * @returns {Entry[]}
17
+ */
18
+ export function entriesFromAnswers(lines: {
19
+ n: number;
20
+ text: string;
21
+ }[], rules: Rule[], picks: {
22
+ line: number;
23
+ rule: number;
24
+ check?: Record<string, any> | null;
25
+ added?: string | null;
26
+ own?: boolean;
27
+ }[], left: {
28
+ line: number;
29
+ rule: number;
30
+ }[]): Entry[];
31
+ /**
32
+ * Decide, for the card in hand, which stored picks are kept and which guardrails must be asked.
33
+ * A pick is KEPT when the job line with its words (same order among equal lines) still has its source guardrail with the exact words and, if the pick wrote a `~` line,
34
+ * that line with its exact words too. Otherwise the pick is dropped (never partly kept) and its guardrails are asked: a pair broken on one side is ONE ask, so the
35
+ * partner left on the card is folded (neither asked nor given the old check) - except an EDITED added line (M10 am21): that one is asked (`pairRule` = its source's number) and the source is folded. Pure.
36
+ * @param {Entry[]} entries @param {{n: number, text: string}[]} lines @param {Rule[]} rules every guardrail the call settles
37
+ * @returns {{picks: {line: number, rule: number, check: Record<string, any>|null, added?: string, own?: boolean}[], left: {line: number, rule: number}[],
38
+ * kept: {line: number, rule: number, entry: Entry}[], askRules: (Rule & {pairRule?: number})[]}}
39
+ */
40
+ export function matchRecord(entries: Entry[], lines: {
41
+ n: number;
42
+ text: string;
43
+ }[], rules: Rule[]): {
44
+ picks: {
45
+ line: number;
46
+ rule: number;
47
+ check: Record<string, any> | null;
48
+ added?: string;
49
+ own?: boolean;
50
+ }[];
51
+ left: {
52
+ line: number;
53
+ rule: number;
54
+ }[];
55
+ kept: {
56
+ line: number;
57
+ rule: number;
58
+ entry: Entry;
59
+ }[];
60
+ askRules: (Rule & {
61
+ pairRule?: number;
62
+ })[];
63
+ };
64
+ /**
65
+ * Read a carried record (the folder's file). A missing or unreadable file is no record (a plan from before am17 has none).
66
+ * @param {string} file @returns {Entry[]|null}
67
+ */
68
+ export function readRecordFile(file: string): Entry[] | null;
69
+ /** the record's file, inside a drafting folder only (never a run folder) */
70
+ export const RECORD_FILE: "picks-record.json";
71
+ /** the exact words a kept pick is marked with in the draft log, the Audit and the plan card (M10 am17 (6)) */
72
+ export const KEPT_WORDS: "kept from last draft";
73
+ export function sameWords(a: unknown, b: unknown): boolean;
74
+ export function recordPath(planDir: string): string;
75
+ export type Entry = {
76
+ lineWords: string;
77
+ occurrence: number;
78
+ ruleText: string;
79
+ added: string | null;
80
+ check: Record<string, any> | null;
81
+ own: boolean;
82
+ left: boolean;
83
+ };
84
+ export type Rule = {
85
+ line: number;
86
+ rule: number;
87
+ text: string;
88
+ };
@@ -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;
@@ -33,15 +33,20 @@ export function readRunInputs(runDir: string | null): {
33
33
  * M8b item 1: the ONE writer of `run.json`, called once when a fresh run has frozen its inputs (`runFlow`); never over an existing record. `model` is the pick
34
34
  * the run started on (M4d am33; null = the section is left out), `thinking` the job's "Thinking on" box as it was at the start (M4d am25: written for every fresh
35
35
  * run, ticked or not), `inputs` the manifest `freezeInputs` returned. A fresh run always has `thinking` and `inputs`.
36
- * @param {string} runDir @param {{ model: { slot: string, model: string }|null, thinking: boolean, inputs: any[] }} start
36
+ * @param {string} runDir @param {{ model: { slot: string, model: string }|null, thinking: boolean, inputs: any[], rerun?: {decision: 'rerun', words: string, afterStep: string|null}|null }} start
37
37
  */
38
- export function writeRunStart(runDir: string, { model, thinking, inputs }: {
38
+ export function writeRunStart(runDir: string, { model, thinking, inputs, rerun }: {
39
39
  model: {
40
40
  slot: string;
41
41
  model: string;
42
42
  } | null;
43
43
  thinking: boolean;
44
44
  inputs: any[];
45
+ rerun?: {
46
+ decision: "rerun";
47
+ words: string;
48
+ afterStep: string | null;
49
+ } | null;
45
50
  }): void;
46
51
  /** the file's name in the run's folder */
47
52
  export const RUN_FILE: "run.json";
package/types/runner.d.ts CHANGED
@@ -29,13 +29,14 @@ export function readHaltRecord(runDir: string): {
29
29
  missing?: undefined;
30
30
  red?: undefined;
31
31
  };
32
- /** @param {{goal:string, primitives?:string[], reads?:Record<string,any>, gap?:string|null, hints?:string|null}} opts `hints` (M8 am7): the earlier runs' block, text only, for a retry / redo / rerun try */
32
+ /** @param {{goal:string, primitives?:string[], reads?:Record<string,any>, gap?:string|null, hints?:string|null, memo?:string|null}} opts `hints` (M8 am7): the earlier runs' block, text only, for a retry / redo / rerun try; `memo` (M14): what happened so far in this run, text only, every try */
33
33
  export function buildExecutorContext(opts: {
34
34
  goal: string;
35
35
  primitives?: string[];
36
36
  reads?: Record<string, any>;
37
37
  gap?: string | null;
38
38
  hints?: string | null;
39
+ memo?: string | null;
39
40
  }): Readonly<{
40
41
  goal: string;
41
42
  primitives: readonly string[];
@@ -44,6 +45,7 @@ export function buildExecutorContext(opts: {
44
45
  }>;
45
46
  gap: string | null;
46
47
  hints: string | null;
48
+ memo: string | null;
47
49
  }>;
48
50
  /**
49
51
  * @param {unknown} value
@@ -149,6 +151,32 @@ export function freezeInputs(runDir: string, sources: Array<{
149
151
  skip: string | null;
150
152
  red?: undefined;
151
153
  }>;
154
+ /**
155
+ * 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
156
+ * ticket mark, so the rerun reads the ticket through the job's MCP tools and the signed filter, not as a web page.
157
+ * @param {Array<{id: string, source: string, ticket?: {number: number}, filter?: {outcome?: string}}>} manifest
158
+ */
159
+ export function rerunSourcesOf(manifest: Array<{
160
+ id: string;
161
+ source: string;
162
+ ticket?: {
163
+ number: number;
164
+ };
165
+ filter?: {
166
+ outcome?: string;
167
+ };
168
+ }>): ({
169
+ id: string;
170
+ path: string;
171
+ ticket?: undefined;
172
+ } | {
173
+ id: string;
174
+ path: string;
175
+ ticket: {
176
+ anyway?: true | undefined;
177
+ number: number | undefined;
178
+ };
179
+ })[];
152
180
  /** The send target's folder (M4e amendment 1, "Destination is any folder").
153
181
  * An absolute `file:/abs/path` is that folder, anywhere on the machine. A
154
182
  * relative path keeps its M0/M2 meaning: joined onto the install folder and
@@ -233,79 +261,16 @@ export function readArtifactsMapChecked(runDir: any, ids: any, { docxRoles }?: {
233
261
  red: string;
234
262
  };
235
263
  /**
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}}>}
264
+ * 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
265
+ * 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
266
+ * 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
267
+ * (`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.
268
+ * @param {Parameters<typeof runStepTries>[0] & {mcpServer?: string|null}} opts - `mcpServer`: the job's signed `mcp.server`
269
+ * @returns {ReturnType<typeof runStepTries>}
264
270
  */
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
- }>;
271
+ export function runStepRalph({ mcpServer, ...opts }: Parameters<typeof runStepTries>[0] & {
272
+ mcpServer?: string | null;
273
+ }): ReturnType<typeof runStepTries>;
309
274
  /**
310
275
  * @param {object} opts
311
276
  * @param {string} opts.root - the flows root directory (M1's `readFlow` root).
@@ -315,13 +280,14 @@ export function runStepRalph({ step, primitivesMap, readsMap, businessDate, mode
315
280
  * @param {unknown} opts.catalogue - passed straight through to `readFlow`.
316
281
  * @param {(executorContext:object, grantedTools:Record<string,any>, stepMeta?:{class:string|null}) => Promise<{ok:boolean, artifact?:unknown, costUsd:number|null, red?:string, transport?:boolean, model?:string, modelMatch?:boolean}>} opts.modelStep
317
282
  * @param {(opts:{question:string, evidence:unknown, runDir:string}) => Promise<{decision:'accept'|'redo'|'rerun'|'timeout'|'park', reason?:string, artifactSha256?:string}>} opts.askStep
318
- * @param {(target:string, filename:string, content:unknown, acceptedSha256?:string|null) => Promise<{ok:boolean, red?:string, bytes?:number}>} opts.sendStep
283
+ * @param {(target:string, filename:string, content:unknown, acceptedSha256?:string|null) => Promise<{ok:boolean, red?:string, bytes?:number, sha256?:string}>} opts.sendStep
319
284
  * @param {Record<string, any>} [opts.primitives] - injected primitive implementations, keyed by catalogue verb.
320
285
  * @param {string[]} [opts.primitiveReds] - `resolvePrimitives`'s own `reds` (e.g. bareguard refusing a symlinked file scope); any entry refuses the run at $0 like an unwired verb, before the run dir exists.
321
286
  * @param {() => string} [opts.clock] - returns the current ISO timestamp; defaults to the wall clock.
322
287
  * @param {string} opts.businessDate - the run's explicit "as of today", never the wall clock.
323
288
  * @param {number} [opts.ceilingUsd] - per-attempt ceiling override; the model's hold from Settings prices (`ceilingCostUsd`); absent = no hold.
324
289
  * @param {{slot: string, model: string}} [opts.runModel] - M4d am33: the model this run started on; recorded once in the run folder (run.json) and kept by every resume/continue.
290
+ * @param {{decision: 'rerun', words: string, afterStep: string|null}} [opts.rerunOf] - M14 am1 item 1: only `resumeRun`'s rerun path passes it; kept in the new run's run.json
325
291
  * @param {string|null} [opts.initialGap] - M3 scope item 7 (rerun as a fresh
326
292
  * run): a human's rerun reason, carried as the FIRST ordinary step's
327
293
  * starting gap. Never used by a plain `runFlow` call outside `resumeRun`'s
@@ -331,7 +297,7 @@ export function runStepRalph({ step, primitivesMap, readsMap, businessDate, mode
331
297
  * epoch ms; defaults to the wall clock. Mirrors `clock` (ISO) so a test
332
298
  * can advance wall time across a park/resume boundary without a real wait.
333
299
  */
334
- export function runFlow({ root, name, runId, sources, catalogue, modelStep, askStep, sendStep, primitives, primitiveReds, clock, businessDate, ceilingUsd, initialGap, fetchPage, runModel, nowMs, }: {
300
+ export function runFlow({ root, name, runId, sources, catalogue, modelStep, askStep, sendStep, primitives, primitiveReds, clock, businessDate, ceilingUsd, initialGap, fetchPage, rerunOf, runModel, nowMs, }: {
335
301
  root: string;
336
302
  name: string;
337
303
  runId: string;
@@ -364,6 +330,7 @@ export function runFlow({ root, name, runId, sources, catalogue, modelStep, askS
364
330
  ok: boolean;
365
331
  red?: string;
366
332
  bytes?: number;
333
+ sha256?: string;
367
334
  }>;
368
335
  primitives?: Record<string, any> | undefined;
369
336
  primitiveReds?: string[] | undefined;
@@ -374,6 +341,11 @@ export function runFlow({ root, name, runId, sources, catalogue, modelStep, askS
374
341
  slot: string;
375
342
  model: string;
376
343
  } | undefined;
344
+ rerunOf?: {
345
+ decision: "rerun";
346
+ words: string;
347
+ afterStep: string | null;
348
+ } | undefined;
377
349
  initialGap?: string | null | undefined;
378
350
  fetchPage?: ((url: string) => Promise<{
379
351
  ok: true;
@@ -409,7 +381,7 @@ export function makeParkingAskStep(): (opts?: any) => Promise<{
409
381
  * @param {string} opts.runId
410
382
  * @param {unknown} opts.catalogue
411
383
  * @param {(executorContext:object, grantedTools:Record<string,any>, stepMeta?:{class:string|null}) => Promise<any>} opts.modelStep
412
- * @param {(target:string, filename:string, content:unknown) => Promise<{ok:boolean, red?:string, bytes?:number}>} opts.sendStep
384
+ * @param {(target:string, filename:string, content:unknown) => Promise<{ok:boolean, red?:string, bytes?:number, sha256?:string}>} opts.sendStep
413
385
  * @param {Record<string, any>} [opts.primitives]
414
386
  * @param {string[]} [opts.primitiveReds] - see `runFlow`'s own.
415
387
  * @param {() => string} [opts.clock]
@@ -431,6 +403,7 @@ export function resumeRun({ root, name, runId, catalogue, modelStep, sendStep, p
431
403
  ok: boolean;
432
404
  red?: string;
433
405
  bytes?: number;
406
+ sha256?: string;
434
407
  }>;
435
408
  primitives?: Record<string, any> | undefined;
436
409
  primitiveReds?: string[] | undefined;
@@ -473,7 +446,7 @@ export function auditSpend(runDir: string): {
473
446
  * @param {string} opts.runId
474
447
  * @param {unknown} opts.catalogue
475
448
  * @param {(executorContext:object, grantedTools:Record<string,any>, stepMeta?:{class:string|null}) => Promise<any>} opts.modelStep
476
- * @param {(target:string, filename:string, content:unknown) => Promise<{ok:boolean, red?:string, bytes?:number}>} opts.sendStep
449
+ * @param {(target:string, filename:string, content:unknown) => Promise<{ok:boolean, red?:string, bytes?:number, sha256?:string}>} opts.sendStep
477
450
  * @param {Record<string, any>} [opts.primitives]
478
451
  * @param {string[]} [opts.primitiveReds]
479
452
  * @param {() => string} [opts.clock]
@@ -493,6 +466,7 @@ export function continueRun({ root, name, runId, catalogue, modelStep, sendStep,
493
466
  ok: boolean;
494
467
  red?: string;
495
468
  bytes?: number;
469
+ sha256?: string;
496
470
  }>;
497
471
  primitives?: Record<string, any> | undefined;
498
472
  primitiveReds?: string[] | undefined;
@@ -571,3 +545,80 @@ export const HALT_FILE: "halt.json";
571
545
  /** 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
546
  export const LEARN_ERROR_FILE: "learn-error.jsonl";
573
547
  import { readTicketMcp } from './ticket-mcp.js';
548
+ /**
549
+ * Run one step to green (or hitl pass-through), looping under strikes and
550
+ * the attempt fallback. Returns `{ ok:true, artifact, attempts }` on success
551
+ * or `{ ok:false, outcome, red }` on any halt. Appends one audit row per
552
+ * attempt via `deps.recordAudit`. Never throws for a model/close failure —
553
+ * only a programmer error (a malformed step, an unreachable branch) escapes.
554
+ *
555
+ * @param {object} opts
556
+ * @param {any} opts.step
557
+ * @param {Record<string, any>} [opts.primitivesMap]
558
+ * @param {Record<string, any>} opts.readsMap
559
+ * @param {string} opts.businessDate
560
+ * @param {(executorContext:object, grantedTools:Record<string,any>, stepMeta?:{class:string|null}, seam?:{stopRequested?:() => boolean}) => Promise<any>} opts.modelStep
561
+ * @param {{ value: number }} opts.spent
562
+ * @param {number} opts.capUsd
563
+ * @param {number} opts.ceilingUsd
564
+ * @param {(row: any, modelOutput?: any) => void} opts.recordAudit
565
+ * @param {string|null} [opts.initialGap]
566
+ * @param {number} [opts.attemptOffset]
567
+ * @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
568
+ * @param {boolean} [opts.thinkingBox] - M4d am25: the job's "Thinking on" box as this run's copy keeps it (default off)
569
+ * @param {() => string} [opts.now] - M4a-2: stamps each audit row's `at`;
570
+ * defaults to the real wall clock.
571
+ * @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
572
+ * @param {number} [opts.stepNo] - this step's 1-based number, for the words of a stop row
573
+ * @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
574
+ * @param {number} [opts.triesDone] - tries a Stop already closed on this step (they count against its limit)
575
+ * @param {string|null} [opts.runDir] - M4d am29 item 2: the run's folder, where each try saves its checks
576
+ * @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
577
+ * @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}}>}
578
+ */
579
+ declare function runStepTries({ step, primitivesMap, readsMap, businessDate, modelStep, spent, capUsd, ceilingUsd, recordAudit, initialGap, attemptOffset, thinkingBox, learnHints, now, readStop, stepNo, triesDone, runDir, prevStepId, mcpGranted, }: {
580
+ step: any;
581
+ primitivesMap?: Record<string, any> | undefined;
582
+ readsMap: Record<string, any>;
583
+ businessDate: string;
584
+ modelStep: (executorContext: object, grantedTools: Record<string, any>, stepMeta?: {
585
+ class: string | null;
586
+ }, seam?: {
587
+ stopRequested?: () => boolean;
588
+ }) => Promise<any>;
589
+ spent: {
590
+ value: number;
591
+ };
592
+ capUsd: number;
593
+ ceilingUsd: number;
594
+ recordAudit: (row: any, modelOutput?: any) => void;
595
+ initialGap?: string | null | undefined;
596
+ attemptOffset?: number | undefined;
597
+ learnHints?: (() => {
598
+ text: string;
599
+ ids: string[];
600
+ } | null) | null | undefined;
601
+ thinkingBox?: boolean | undefined;
602
+ now?: (() => string) | undefined;
603
+ readStop?: (() => boolean) | null | undefined;
604
+ stepNo?: number | undefined;
605
+ prevStepId?: string | null | undefined;
606
+ triesDone?: number | undefined;
607
+ runDir?: string | null | undefined;
608
+ mcpGranted?: Record<string, any> | undefined;
609
+ }): Promise<{
610
+ ok: true;
611
+ artifact: any;
612
+ attempts: number;
613
+ hitl?: boolean;
614
+ } | {
615
+ ok: false;
616
+ outcome: string;
617
+ red: string;
618
+ stop?: {
619
+ where: string;
620
+ book: Record<string, any>;
621
+ step?: string | null;
622
+ };
623
+ }>;
624
+ export {};
package/types/send.d.ts CHANGED
@@ -1,12 +1,19 @@
1
+ /**
2
+ * M15 items 3 and am1, am2: the accepted answer as the plain-text file the send writes. `{text}` alone is the text exactly; any other flat object is one
3
+ * `Name words: value` line per field; a list of results is one `## Result k` block per result with one line per value, in the order the answer holds
4
+ * them, then `from the page: "<quote>"`. Never JSON braces, never check marks. What it throws away: a result's keys other than `quote` and `values`.
5
+ * @param {Record<string, any>} content @returns {string}
6
+ */
7
+ export function renderSentMd(content: Record<string, any>): string;
1
8
  /**
2
9
  * @param {string} target - a signed arbiter target, e.g. `file:poc/m0/out`.
3
10
  * @param {string} filename
4
- * @param {unknown} content - JSON-serialised before writing.
11
+ * @param {unknown} content - the accepted artifact; hash-checked as its JSON, written as plain text (`renderSentMd`).
5
12
  * @param {string|null} [acceptedSha256] - the sha256 the human's accept recorded
6
13
  * (`answerAsk`, M4b piece 3). Required: none recorded (an answer written by an
7
14
  * older version, or no accept in this process) refuses by name.
8
15
  * @param {{root?: string, runDir?: string}} [ctx] the flow root and this run's folder, for the destination refusals
9
- * @returns {Promise<{ok:true, path:string, bytes:number} | {ok:false, red:string}>}
16
+ * @returns {Promise<{ok:true, path:string, bytes:number, sha256:string} | {ok:false, red:string}>}
10
17
  */
11
18
  export function sendViaPrimitive(target: string, filename: string, content: unknown, acceptedSha256?: string | null, ctx?: {
12
19
  root?: string;
@@ -15,6 +22,7 @@ export function sendViaPrimitive(target: string, filename: string, content: unkn
15
22
  ok: true;
16
23
  path: string;
17
24
  bytes: number;
25
+ sha256: string;
18
26
  } | {
19
27
  ok: false;
20
28
  red: string;