fwdloop 0.20.0 → 0.22.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 (92) hide show
  1. package/README.md +2 -0
  2. package/bin/fwdloop +85 -34
  3. package/package.json +4 -3
  4. package/src/audit-fold.js +181 -0
  5. package/src/authoring.js +33 -7
  6. package/src/books.js +1 -1
  7. package/src/checked.js +18 -1
  8. package/src/cited-record.js +138 -0
  9. package/src/cited-source.js +49 -0
  10. package/src/citedcheck.js +306 -0
  11. package/src/citedwords.js +197 -0
  12. package/src/closers.js +105 -9
  13. package/src/ctx-tools.js +2 -14
  14. package/src/declaration.js +85 -5
  15. package/src/diary.js +49 -0
  16. package/src/docx.js +16 -2
  17. package/src/draft-steps.js +1 -1
  18. package/src/drafter.js +292 -25
  19. package/src/flow.js +33 -7
  20. package/src/flowmodel.js +63 -5
  21. package/src/input-facts.js +20 -3
  22. package/src/model-step.js +132 -9
  23. package/src/pageask.js +136 -0
  24. package/src/pagebits.js +107 -0
  25. package/src/pagedropwords.js +171 -0
  26. package/src/pagedry.js +120 -0
  27. package/src/pagefetch.js +164 -0
  28. package/src/pagelook.js +155 -0
  29. package/src/pagemap.js +55 -0
  30. package/src/pageplace.js +103 -0
  31. package/src/pagerules.js +318 -0
  32. package/src/panel/author.js +41 -20
  33. package/src/panel/authorcard.js +11 -1
  34. package/src/panel/authorflows.js +21 -15
  35. package/src/panel/authorstart.js +2 -4
  36. package/src/panel/authortrigger.js +14 -4
  37. package/src/panel/data.js +130 -10
  38. package/src/panel/index.html +499 -41
  39. package/src/panel/result.js +295 -0
  40. package/src/panel/server.js +27 -3
  41. package/src/primitives.js +43 -2
  42. package/src/provider.js +5 -2
  43. package/src/redact.js +17 -0
  44. package/src/runner.js +128 -21
  45. package/src/schedule.js +3 -3
  46. package/src/setup.js +16 -1
  47. package/src/sheetfind.js +50 -0
  48. package/src/sheetlook.js +157 -0
  49. package/src/signed-text.js +11 -1
  50. package/src/thinking.js +39 -0
  51. package/src/try-checks.js +68 -0
  52. package/src/types.js +4 -2
  53. package/types/audit-fold.d.ts +54 -0
  54. package/types/authoring.d.ts +20 -2
  55. package/types/books.d.ts +17 -0
  56. package/types/checked.d.ts +10 -0
  57. package/types/cited-record.d.ts +21 -0
  58. package/types/cited-source.d.ts +18 -0
  59. package/types/citedcheck.d.ts +95 -0
  60. package/types/citedwords.d.ts +97 -0
  61. package/types/closers.d.ts +55 -3
  62. package/types/declaration.d.ts +15 -1
  63. package/types/diary.d.ts +57 -0
  64. package/types/docx.d.ts +14 -0
  65. package/types/drafter.d.ts +244 -2
  66. package/types/flow.d.ts +21 -0
  67. package/types/flowmodel.d.ts +40 -3
  68. package/types/input-facts.d.ts +12 -2
  69. package/types/model-step.d.ts +38 -3
  70. package/types/pageask.d.ts +75 -0
  71. package/types/pagebits.d.ts +32 -0
  72. package/types/pagedropwords.d.ts +40 -0
  73. package/types/pagedry.d.ts +38 -0
  74. package/types/pagefetch.d.ts +86 -0
  75. package/types/pagelook.d.ts +75 -0
  76. package/types/pagemap.d.ts +31 -0
  77. package/types/pageplace.d.ts +22 -0
  78. package/types/pagerules.d.ts +86 -0
  79. package/types/panel/authorcard.d.ts +2 -0
  80. package/types/panel/authorflows.d.ts +2 -0
  81. package/types/panel/data.d.ts +26 -0
  82. package/types/panel/result.d.ts +156 -0
  83. package/types/provider.d.ts +3 -1
  84. package/types/redact.d.ts +1 -0
  85. package/types/runner.d.ts +156 -7
  86. package/types/schedule.d.ts +0 -11
  87. package/types/setup.d.ts +13 -0
  88. package/types/sheetfind.d.ts +46 -0
  89. package/types/sheetlook.d.ts +120 -0
  90. package/types/thinking.d.ts +31 -0
  91. package/types/try-checks.d.ts +55 -0
  92. package/types/types.d.ts +20 -3
@@ -72,6 +72,8 @@ export function cardFields(body: any): {
72
72
  capUsd: any;
73
73
  askWait: string;
74
74
  };
75
+ /** M10 am3: is this web address whole (a host after the scheme, no spaces)? The ONE reader of a typed page address. @param {string} v */
76
+ export function pageAddressOk(v: string): boolean;
75
77
  /** The Run-a-signed-flow door's rows (a role is fixed by the signed flow): what the page sent, as `{role, path}`. @param {any} v */
76
78
  export function runInputRows(v: any): {
77
79
  role: string;
@@ -119,6 +119,7 @@ export function createFlowsDoor(opts: {
119
119
  flow: string;
120
120
  capUsd: any;
121
121
  roles: any;
122
+ pages: Record<string, string>;
122
123
  nextRunId: string;
123
124
  lastRunId: string | null;
124
125
  lastSources: Record<string, string>;
@@ -206,6 +207,7 @@ export function createFlowsDoor(opts: {
206
207
  flow: string;
207
208
  capUsd: any;
208
209
  roles: any;
210
+ pages: Record<string, string>;
209
211
  nextRunId: string;
210
212
  lastRunId: string | null;
211
213
  lastSources: Record<string, string>;
@@ -701,6 +701,31 @@ export function getRunJob({ root, flow, runId, catalogue, scheduleRead, home, }:
701
701
  scheduleRead?: (flow: string) => any;
702
702
  home?: string;
703
703
  }): any | null;
704
+ /**
705
+ * `GET /api/runs/:flow/:runId/result` — the Result tab (M10 am4). The Not checked list is the Job tab's own (`buildJobPlan`), never a second spelling.
706
+ * @param {{root: string, flow: string, runId: string, catalogue: any, resumeAttempt?: (flow: string, runId: string) => any, now?: () => number}} a
707
+ * @returns {any|null}
708
+ */
709
+ export function getRunResult({ root, flow, runId, catalogue, resumeAttempt, now, }: {
710
+ root: string;
711
+ flow: string;
712
+ runId: string;
713
+ catalogue: any;
714
+ resumeAttempt?: (flow: string, runId: string) => any;
715
+ now?: () => number;
716
+ }): any | null;
717
+ /**
718
+ * `GET /api/runs/:flow/:runId/download?i=<n>` (M10 am4): one saved file, or why not.
719
+ * @param {{root: string, flow: string, runId: string, catalogue: any, index: unknown}} a
720
+ * @returns {ReturnType<typeof downloadOf>}
721
+ */
722
+ export function getRunDownload({ root, flow, runId, catalogue, index, }: {
723
+ root: string;
724
+ flow: string;
725
+ runId: string;
726
+ catalogue: any;
727
+ index: unknown;
728
+ }): ReturnType<typeof downloadOf>;
704
729
  /**
705
730
  * hamr's 2026-09-27 exit-check review #3: which declared step (and its
706
731
  * signed prose line) each ask in `orderedAsks` belongs to — no book field
@@ -862,3 +887,4 @@ export const NO_DRAFT_WORDS: "no draft record";
862
887
  /** M6: what the Job tab says for a run that started before runs kept a copy of their job. */
863
888
  export const NO_JOB_COPY_WORDS: "This run started before runs kept a copy of their job, so this shows the job as it is now.";
864
889
  import { scheduleAuditWords } from '../summary-words.js';
890
+ import { downloadOf } from './result.js';
@@ -0,0 +1,156 @@
1
+ /**
2
+ * M10 job = the run reads a web page, a CSV or a .docx (ladder, M10 am4 item 1). Read off the signed arbiter, never the run's files.
3
+ * @param {any} arbiter @returns {boolean}
4
+ */
5
+ export function isResultRun(arbiter: any): boolean;
6
+ /** The run's check type: its distinct close classes, in step order (`hitl + softgreen`). `—` for a declaration with none.
7
+ * @param {any} declaration @returns {string} */
8
+ export function checkTypeOf(declaration: any): string;
9
+ /**
10
+ * The ONE reader of the M10 cited-check record (`<run>/cited-checks.json`). Expected shape (typed, nothing parsed out of prose):
11
+ * { lines: [ { n: int, source: string (the role of a signed source), passed: boolean,
12
+ * facts: [ { name: string, kind: 'phrase'|'value', sentence: string, confirmed?: true } ],
13
+ * rows: [ { n: int, quote: string, cells: string[] (one per fact), proof?: { text: string, marks: [[start, end], ...] } } ] | null,
14
+ * notChecked?: string[] } ] }
15
+ * `{present:false}` = no file. `{present:true, ok:false, red}` = a record that does not match (named, never half-read). Else `{present:true, ok:true, lines}`.
16
+ * @param {string} runDir
17
+ * @returns {{present: false}|{present: true, ok: false, red: string}|{present: true, ok: true, lines: any[]}}
18
+ */
19
+ export function readCitedChecks(runDir: string): {
20
+ present: false;
21
+ } | {
22
+ present: true;
23
+ ok: false;
24
+ red: string;
25
+ } | {
26
+ present: true;
27
+ ok: true;
28
+ lines: any[];
29
+ };
30
+ /**
31
+ * The names of the facts of one job line whose limit came from an `agree` answer, read from the setup record's human rows (bareloop's confirmedFactNames,
32
+ * server.js@2959217): a look question on THIS line, answered agree / yes, whose reading (read back from the question's one spelling) is a signed `~` rule of
33
+ * the line word for word. A fact is confirmed when that reading starts with its name. No record, an own-words answer, another line or a reading that is not
34
+ * in the signed rule confirms nothing; nothing is guessed.
35
+ * @param {any[]} setupRows @param {number} lineN @param {string} signedRule the line's signed guardrail @param {string[]} factNames
36
+ * @returns {Set<string>}
37
+ */
38
+ export function confirmedFactNames(setupRows: any[], lineN: number, signedRule: string, factNames: string[]): Set<string>;
39
+ /**
40
+ * One saved file, read for the tab or a download, through the one safe gateway (`readFileInside`: not a symlink, real path inside the signed folder's
41
+ * real path, checked at USE time). It must also still hash to the recorded sha256. A missing, refused or changed file is a state, never content:
42
+ * stale bytes are never returned. (Text read, so a file that is not UTF-8 reads as "changed", never as ok.)
43
+ * @param {{name: string, dir: string|null, sha256: string|null}} rec
44
+ * @returns {{state: 'ok', buf: Buffer}|{state: 'gone'|'changed', buf: null}}
45
+ */
46
+ export function readDelivered(rec: {
47
+ name: string;
48
+ dir: string | null;
49
+ sha256: string | null;
50
+ }): {
51
+ state: "ok";
52
+ buf: Buffer;
53
+ } | {
54
+ state: "gone" | "changed";
55
+ buf: null;
56
+ };
57
+ /**
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.
61
+ * @returns {{path: string, dir: string|null, name: string, sha256: string|null}[]}
62
+ */
63
+ export function deliveredOf({ arbiter, declaration, runDir, root, flow, runId, auditRows, }: {
64
+ arbiter: any;
65
+ declaration: any;
66
+ runDir: any;
67
+ root: any;
68
+ flow: any;
69
+ runId: any;
70
+ auditRows: any;
71
+ }): {
72
+ path: string;
73
+ dir: string | null;
74
+ name: string;
75
+ sha256: string | null;
76
+ }[];
77
+ /**
78
+ * The Result tab's JSON for one run (`GET /api/runs/:flow/:runId/result`).
79
+ * @param {{flow: string, runId: string, runDir: string, root: string, flowRead: any, arbiter: any, historyRow: any, auditRows: any[], logJson: any, notChecked: string[], readNotes?: string[], setupRows?: any[], door?: {askId: string, draftNo: number}|null}} a
80
+ */
81
+ export function buildResult({ flow, runId, runDir, root, flowRead, arbiter, historyRow, auditRows, logJson, notChecked, readNotes, setupRows, door, }: {
82
+ flow: string;
83
+ runId: string;
84
+ runDir: string;
85
+ root: string;
86
+ flowRead: any;
87
+ arbiter: any;
88
+ historyRow: any;
89
+ auditRows: any[];
90
+ logJson: any;
91
+ notChecked: string[];
92
+ readNotes?: string[];
93
+ setupRows?: any[];
94
+ door?: {
95
+ askId: string;
96
+ draftNo: number;
97
+ } | null;
98
+ }): {
99
+ flow: string;
100
+ runId: string;
101
+ lines: any;
102
+ pages: string[];
103
+ pageNote: string | null;
104
+ notCheckedLabel: string;
105
+ notChecked: string[];
106
+ readNotes: string[];
107
+ delivered: {
108
+ i: number;
109
+ path: string;
110
+ name: string;
111
+ bytes: number | null;
112
+ state: "ok" | "gone" | "changed";
113
+ words: string | null;
114
+ }[];
115
+ gap: {
116
+ line: string;
117
+ more: number;
118
+ moreText: string | null;
119
+ } | null;
120
+ door: {
121
+ head: string;
122
+ ask: string;
123
+ askId: string;
124
+ draftNo: number;
125
+ } | null;
126
+ };
127
+ /**
128
+ * `GET /api/runs/:flow/:runId/download?i=<n>` — saved file `n` (an index into the run's own list), or why not. The path is the books', never the request's.
129
+ * @param {{index: unknown, ctx: any}} a
130
+ * @returns {{ok: true, name: string, type: string, buf: Buffer}|{ok: false, code: number, error: string}}
131
+ */
132
+ export function downloadOf({ index, ctx }: {
133
+ index: unknown;
134
+ ctx: any;
135
+ }): {
136
+ ok: true;
137
+ name: string;
138
+ type: string;
139
+ buf: Buffer;
140
+ } | {
141
+ ok: false;
142
+ code: number;
143
+ error: string;
144
+ };
145
+ /** the two sentences for a saved file that is no longer what the run wrote (code-owned, one spelling) */
146
+ export const RESULT_FILE_GONE: "the saved file is gone";
147
+ export const RESULT_FILE_CHANGED: "the saved file changed after the run";
148
+ /** the words beside a Result-tab page link: the page is read again from the web, so it can differ from what the run read */
149
+ export const RESULT_PAGE_MAY_CHANGE: "The page may have changed since this run.";
150
+ /** the words after a fact whose limit the person agreed to */
151
+ export const RESULT_YOU_CONFIRMED: "(you confirmed)";
152
+ /** the Your-call card's words (bareloop server.js@2959217 DOOR_WORDS.waiting.head and RESULT_DOOR_ASK); the page types none of them */
153
+ export const RESULT_DOOR_HEAD: "waiting for you";
154
+ export const RESULT_DOOR_ASK: "the checks passed; is this what you wanted?";
155
+ export { CITED_CHECKS_FILE };
156
+ import { CITED_CHECKS_FILE } from '../cited-record.js';
@@ -124,11 +124,13 @@ export function readPriceConfig(home?: string): Record<string, any>;
124
124
  * The money hold (USD) of one round: the picked model's OWN Settings prices (`rates`, per 1K tokens, from
125
125
  * `resolveUsableModel`) times the two token bounds above. Not a table, not a fallback.
126
126
  * @param {{ in: number, out: number }} rates
127
+ * @param {number} [promptChars] the length of a prompt known before the call (M10: a page-map prompt carries a whole saved page): the input bound is then
128
+ * the larger of the constant and a deliberately high estimate of that prompt (3 characters per token), never less than the constant.
127
129
  */
128
130
  export function ceilingCostUsd(rates: {
129
131
  in: number;
130
132
  out: number;
131
- }): number;
133
+ }, promptChars?: number): number;
132
134
  /**
133
135
  * Compare the model asked for against the model actually served.
134
136
  * `match` identical; `prefix` identical once a routing prefix is stripped;
@@ -0,0 +1 @@
1
+ export function redactSecrets(raw: unknown): string;
package/types/runner.d.ts CHANGED
@@ -64,24 +64,68 @@ export function checkFreshRunDir(runDir: any): {
64
64
  ok: boolean;
65
65
  red?: undefined;
66
66
  };
67
+ /** M10 item 1: fetch a web page and freeze its text as `<dir>/<id>.txt`; the sha256 is of the FROZEN bytes, like a file input. The ONE writer of a
68
+ * page's frozen copy: drafting calls it with its draft folder, a run start (via `freezeInputs`) with the run's `inputs/`, so the two are
69
+ * separate files and a run is only ever checked against its own. The fetch is tried once; a refusal names the input and says why in plain words.
70
+ * @param {string} dir @param {string} id @param {string} url
71
+ * @param {{fetchPage?: (url: string) => Promise<{ok: true, text: string, url: string}|{ok: false, error: string}>}} [o]
72
+ * @returns {Promise<{ok: true, text: string, entry: {id: string, source: string, frozen: string, sha256: string, bytes: number}}|{ok: false, red: string}>} `text` = the frozen text itself, for the caller that reads it (drafting) */
73
+ export function freezePage(dir: string, id: string, url: string, { fetchPage }?: {
74
+ fetchPage?: (url: string) => Promise<{
75
+ ok: true;
76
+ text: string;
77
+ url: string;
78
+ } | {
79
+ ok: false;
80
+ error: string;
81
+ }>;
82
+ }): Promise<{
83
+ ok: true;
84
+ text: string;
85
+ entry: {
86
+ id: string;
87
+ source: string;
88
+ frozen: string;
89
+ sha256: string;
90
+ bytes: number;
91
+ };
92
+ } | {
93
+ ok: false;
94
+ red: string;
95
+ }>;
67
96
  /** Copy each named source into `<runDir>/inputs/`, hash the FROZEN copy
68
97
  * (never the original again after this), write `inputs.json`. An
69
- * unreadable source refuses by name. */
70
- export function freezeInputs(runDir: any, sources: any): {
98
+ * unreadable source refuses by name. A source that is a web address
99
+ * (M10 item 1) is fetched and frozen by `freezePage`, in the same manifest.
100
+ * @param {string} runDir @param {Array<{id: string, path: string}>} sources
101
+ * @param {{fetchPage?: (url: string) => Promise<{ok: true, text: string, url: string}|{ok: false, error: string}>}} [o] */
102
+ export function freezeInputs(runDir: string, sources: Array<{
103
+ id: string;
104
+ path: string;
105
+ }>, { fetchPage }?: {
106
+ fetchPage?: (url: string) => Promise<{
107
+ ok: true;
108
+ text: string;
109
+ url: string;
110
+ } | {
111
+ ok: false;
112
+ error: string;
113
+ }>;
114
+ }): Promise<{
71
115
  ok: boolean;
72
116
  red: string;
73
117
  manifest?: undefined;
74
118
  } | {
75
119
  ok: boolean;
76
120
  manifest: {
77
- id: any;
78
- source: any;
121
+ id: string;
122
+ source: string;
79
123
  frozen: string;
80
124
  sha256: string;
81
125
  bytes: number;
82
126
  }[];
83
127
  red?: undefined;
84
- };
128
+ }>;
85
129
  /** The send target's folder (M4e amendment 1, "Destination is any folder").
86
130
  * An absolute `file:/abs/path` is that folder, anywhere on the machine. A
87
131
  * relative path keeps its M0/M2 meaning: joined onto the install folder and
@@ -148,6 +192,92 @@ export function readArtifactResult(runDir: any, id: any): {
148
192
  * `readArtifactResult`.
149
193
  */
150
194
  export function readArtifact(runDir: any, id: any): any;
195
+ /** `readArtifactResult` for a whole `reads` array. A genuinely-missing read
196
+ * (never written) still renders as `undefined` in the map, unchanged from
197
+ * before — but a REFUSED read (red) is never silently folded in as
198
+ * `undefined` alongside it; the caller gets `{ok:false, red}` instead and
199
+ * must halt rather than feed tampered/unreadable content (or a `undefined`
200
+ * indistinguishable from "not written yet") into a step.
201
+ * @returns {{ok:true, map:Record<string,any>} | {ok:false, red:string}}
202
+ */
203
+ export function readArtifactsMapChecked(runDir: any, ids: any, { docxRoles }?: {
204
+ docxRoles?: string[] | undefined;
205
+ }): {
206
+ ok: true;
207
+ map: Record<string, any>;
208
+ } | {
209
+ ok: false;
210
+ red: string;
211
+ };
212
+ /**
213
+ * Run one step to green (or hitl pass-through), looping under strikes and
214
+ * the attempt fallback. Returns `{ ok:true, artifact, attempts }` on success
215
+ * or `{ ok:false, outcome, red }` on any halt. Appends one audit row per
216
+ * attempt via `deps.recordAudit`. Never throws for a model/close failure —
217
+ * only a programmer error (a malformed step, an unreachable branch) escapes.
218
+ *
219
+ * @param {object} opts
220
+ * @param {any} opts.step
221
+ * @param {Record<string, any>} [opts.primitivesMap]
222
+ * @param {Record<string, any>} opts.readsMap
223
+ * @param {string} opts.businessDate
224
+ * @param {(executorContext:object, grantedTools:Record<string,any>, stepMeta?:{class:string|null}, seam?:{stopRequested?:() => boolean}) => Promise<any>} opts.modelStep
225
+ * @param {{ value: number }} opts.spent
226
+ * @param {number} opts.capUsd
227
+ * @param {number} opts.ceilingUsd
228
+ * @param {(row: any, modelOutput?: any) => void} opts.recordAudit
229
+ * @param {string|null} [opts.initialGap]
230
+ * @param {number} [opts.attemptOffset]
231
+ * @param {boolean} [opts.thinkingBox] - M4d am25: the job's "Thinking on" box as this run's copy keeps it (default off)
232
+ * @param {() => string} [opts.now] - M4a-2: stamps each audit row's `at`;
233
+ * defaults to the real wall clock.
234
+ * @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
235
+ * @param {number} [opts.stepNo] - this step's 1-based number, for the words of a stop row
236
+ * @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
237
+ * @param {number} [opts.triesDone] - tries a Stop already closed on this step (they count against its limit)
238
+ * @param {string|null} [opts.runDir] - M4d am29 item 2: the run's folder, where each try saves its checks
239
+ * @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}}>}
240
+ */
241
+ export function runStepRalph({ step, primitivesMap, readsMap, businessDate, modelStep, spent, capUsd, ceilingUsd, recordAudit, initialGap, attemptOffset, thinkingBox, now, readStop, stepNo, triesDone, runDir, prevStepId, }: {
242
+ step: any;
243
+ primitivesMap?: Record<string, any> | undefined;
244
+ readsMap: Record<string, any>;
245
+ businessDate: string;
246
+ modelStep: (executorContext: object, grantedTools: Record<string, any>, stepMeta?: {
247
+ class: string | null;
248
+ }, seam?: {
249
+ stopRequested?: () => boolean;
250
+ }) => Promise<any>;
251
+ spent: {
252
+ value: number;
253
+ };
254
+ capUsd: number;
255
+ ceilingUsd: number;
256
+ recordAudit: (row: any, modelOutput?: any) => void;
257
+ initialGap?: string | null | undefined;
258
+ attemptOffset?: number | undefined;
259
+ thinkingBox?: boolean | undefined;
260
+ now?: (() => string) | undefined;
261
+ readStop?: (() => boolean) | null | undefined;
262
+ stepNo?: number | undefined;
263
+ prevStepId?: string | null | undefined;
264
+ triesDone?: number | undefined;
265
+ runDir?: string | null | undefined;
266
+ }): Promise<{
267
+ ok: true;
268
+ artifact: any;
269
+ attempts: number;
270
+ hitl?: boolean;
271
+ } | {
272
+ ok: false;
273
+ outcome: string;
274
+ red: string;
275
+ stop?: {
276
+ where: string;
277
+ book: Record<string, any>;
278
+ step?: string | null;
279
+ };
280
+ }>;
151
281
  /**
152
282
  * @param {object} opts
153
283
  * @param {string} opts.root - the flows root directory (M1's `readFlow` root).
@@ -163,15 +293,17 @@ export function readArtifact(runDir: any, id: any): any;
163
293
  * @param {() => string} [opts.clock] - returns the current ISO timestamp; defaults to the wall clock.
164
294
  * @param {string} opts.businessDate - the run's explicit "as of today", never the wall clock.
165
295
  * @param {number} [opts.ceilingUsd] - per-attempt ceiling override; the model's hold from Settings prices (`ceilingCostUsd`); absent = no hold.
296
+ * @param {{slot: string, model: string}} [opts.runModel] - M4d am33: the model this run started on; recorded once in the run folder (run-model.json) and kept by every resume/continue.
166
297
  * @param {string|null} [opts.initialGap] - M3 scope item 7 (rerun as a fresh
167
298
  * run): a human's rerun reason, carried as the FIRST ordinary step's
168
299
  * starting gap. Never used by a plain `runFlow` call outside `resumeRun`'s
169
300
  * own rerun path.
301
+ * @param {(url: string) => Promise<{ok: true, text: string, url: string}|{ok: false, error: string}>} [opts.fetchPage] - M10: the web-page fetch (default barebrowse via src/pagefetch.js); a test injects one.
170
302
  * @param {() => number} [opts.nowMs] - F45 finding 3: returns the current
171
303
  * epoch ms; defaults to the wall clock. Mirrors `clock` (ISO) so a test
172
304
  * can advance wall time across a park/resume boundary without a real wait.
173
305
  */
174
- export function runFlow({ root, name, runId, sources, catalogue, modelStep, askStep, sendStep, primitives, primitiveReds, clock, businessDate, ceilingUsd, initialGap, nowMs, }: {
306
+ export function runFlow({ root, name, runId, sources, catalogue, modelStep, askStep, sendStep, primitives, primitiveReds, clock, businessDate, ceilingUsd, initialGap, fetchPage, runModel, nowMs, }: {
175
307
  root: string;
176
308
  name: string;
177
309
  runId: string;
@@ -210,7 +342,19 @@ export function runFlow({ root, name, runId, sources, catalogue, modelStep, askS
210
342
  clock?: (() => string) | undefined;
211
343
  businessDate: string;
212
344
  ceilingUsd?: number | undefined;
345
+ runModel?: {
346
+ slot: string;
347
+ model: string;
348
+ } | undefined;
213
349
  initialGap?: string | null | undefined;
350
+ fetchPage?: ((url: string) => Promise<{
351
+ ok: true;
352
+ text: string;
353
+ url: string;
354
+ } | {
355
+ ok: false;
356
+ error: string;
357
+ }>) | undefined;
214
358
  nowMs?: (() => number) | undefined;
215
359
  }): Promise<any>;
216
360
  /** An ask step that never waits — it immediately tells the fold to park.
@@ -243,10 +387,11 @@ export function makeParkingAskStep(): (opts?: any) => Promise<{
243
387
  * @param {() => string} [opts.clock]
244
388
  * @param {string} opts.businessDate
245
389
  * @param {number} [opts.ceilingUsd]
390
+ * @param {{slot: string, model: string}} [opts.runModel] - M4d am33: the model this run started on; recorded once in the run folder (run-model.json) and kept by every resume/continue.
246
391
  * @param {() => number} [opts.nowMs] - F45 finding 3; see `runFlow`'s own.
247
392
  * @param {(newRunDir:string) => void} [opts.onRerunStart] - amendment 16 C2: called with the new run's folder just before a `rerun` starts it.
248
393
  */
249
- export function resumeRun({ root, name, runId, catalogue, modelStep, sendStep, primitives, primitiveReds, clock, businessDate, ceilingUsd, nowMs, onRerunStart, }: {
394
+ export function resumeRun({ root, name, runId, catalogue, modelStep, sendStep, primitives, primitiveReds, clock, businessDate, ceilingUsd, runModel, nowMs, onRerunStart, }: {
250
395
  root: string;
251
396
  name: string;
252
397
  runId: string;
@@ -264,6 +409,10 @@ export function resumeRun({ root, name, runId, catalogue, modelStep, sendStep, p
264
409
  clock?: (() => string) | undefined;
265
410
  businessDate: string;
266
411
  ceilingUsd?: number | undefined;
412
+ runModel?: {
413
+ slot: string;
414
+ model: string;
415
+ } | undefined;
267
416
  nowMs?: (() => number) | undefined;
268
417
  onRerunStart?: ((newRunDir: string) => void) | undefined;
269
418
  }): Promise<any>;
@@ -26,17 +26,6 @@ export function carryQueue(flowDir: string, from: string, to: string): void;
26
26
  export function finishCarry(flowDir: string, from: string, nowMs: number): void;
27
27
  /** Cancel's own row in the ledger. @param {string} flowDir @param {string} sig @param {number} nowMs */
28
28
  export function recordCancelled(flowDir: string, sig: string, nowMs: number): void;
29
- /** @typedef {import('./trigger-line.js').Trigger} Trigger */
30
- /**
31
- * @typedef {{
32
- * v: 1, flow: string, trigger: Trigger, flowSignatureHash: string, bound: string, sig: string, signedBy: string, signedAt: string,
33
- * model: {slot: string, model: string}|null, destination: string|null, inputs: {role: string, path: string}[]|null,
34
- * plan: {run: string, flowHash: string, declSha: string}|null, from: string|null,
35
- * }} Schedule
36
- */
37
- export const SCHEDULE_FILE: "schedule.json";
38
- export const LEDGER_FILE: "schedule-ledger.jsonl";
39
- export function droppedSay(name: string): string;
40
29
  export function scheduleFileOf(flowDir: string): string;
41
30
  export function ledgerOf(flowDir: string): string;
42
31
  export function sigOf(bound: string, signedAt: string): string;
package/types/setup.d.ts CHANGED
@@ -31,6 +31,19 @@ export function buildSetupRows({ sessionDir, planDir, hash, signedBy, signedAt,
31
31
  verdict: string;
32
32
  hash: string | null;
33
33
  gap: string | null;
34
+ } | {
35
+ kind: string;
36
+ n: number;
37
+ at: string | null;
38
+ source: string;
39
+ ask: string | undefined;
40
+ question: string;
41
+ answer: string | null;
42
+ line: number;
43
+ ruleNo: number | undefined;
44
+ ruleText: string | undefined;
45
+ proposal: string | null;
46
+ rule: string | null;
34
47
  } | {
35
48
  kind: string;
36
49
  n: number;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @typedef {{kind: 'header', column: string}} FoundHeader the word IS a column (nothing to ask)
3
+ * @typedef {{kind: 'ask', column: string, numbers: number, rows: number}} FoundAsk exactly one column fits: the one ask
4
+ * @typedef {{kind: 'tie', columns: string[], rows: number}} FoundTie two or more columns fit equally: no ask
5
+ * @typedef {{kind: 'none', rows: number}} FoundNone no column fits: no ask
6
+ */
7
+ /**
8
+ * Where a job word lands in a sheet's columns.
9
+ * @param {string} csvText the sheet's text @param {string} word the job's word
10
+ * @returns {FoundHeader|FoundAsk|FoundTie|FoundNone}
11
+ */
12
+ export function findColumn(csvText: string, word: string): FoundHeader | FoundAsk | FoundTie | FoundNone;
13
+ /** a column fits when a plain number fills at least this share of the rows (F71 (b)) */
14
+ export const FIT_RATIO: 0.9;
15
+ export function columnQuestion(word: string, found: FoundAsk, line: number): string;
16
+ /**
17
+ * the word IS a column (nothing to ask)
18
+ */
19
+ export type FoundHeader = {
20
+ kind: "header";
21
+ column: string;
22
+ };
23
+ /**
24
+ * exactly one column fits: the one ask
25
+ */
26
+ export type FoundAsk = {
27
+ kind: "ask";
28
+ column: string;
29
+ numbers: number;
30
+ rows: number;
31
+ };
32
+ /**
33
+ * two or more columns fit equally: no ask
34
+ */
35
+ export type FoundTie = {
36
+ kind: "tie";
37
+ columns: string[];
38
+ rows: number;
39
+ };
40
+ /**
41
+ * no column fits: no ask
42
+ */
43
+ export type FoundNone = {
44
+ kind: "none";
45
+ rows: number;
46
+ };
@@ -0,0 +1,120 @@
1
+ /**
2
+ * What the AI is told for ONE sheet: the job, and the sheet's header and first rows. It names the job's word for each rule; it does not pick a column to offer.
3
+ * With `headings` (a .docx input, am8 item 3) the document's headings stand where a sheet's columns do and no data rows are shown.
4
+ * @param {{jobLines: {n: number, text: string, rule?: string, rules?: string[]}[], label: string, text: string, headings?: string[]}} o @returns {string}
5
+ */
6
+ export function sheetPrompt({ jobLines, label, text, headings }: {
7
+ jobLines: {
8
+ n: number;
9
+ text: string;
10
+ rule?: string;
11
+ rules?: string[];
12
+ }[];
13
+ label: string;
14
+ text: string;
15
+ headings?: string[];
16
+ }): string;
17
+ /**
18
+ * Read the AI's answer: ONE JSON object of the answer form, nothing else. No repair: text that is not JSON, or a fact without a `from`, a `word` or a kind of
19
+ * "number" / "other", is a malformed answer.
20
+ * @param {unknown} text @returns {{ok: true, words: {from: string, word: string, kind: 'number'|'other'}[]}|{ok: false}}
21
+ */
22
+ export function parseSheetAnswer(text: unknown): {
23
+ ok: true;
24
+ words: {
25
+ from: string;
26
+ word: string;
27
+ kind: "number" | "other";
28
+ }[];
29
+ } | {
30
+ ok: false;
31
+ };
32
+ /**
33
+ * Keep the words that are real columns; for the rest, find the column to offer (or say why none is). Decided by code from the word, the rule and the sheet.
34
+ * @param {string} text the sheet's text @param {{from: string, word: string, kind: 'number'|'other'}[]} words
35
+ * @param {{n: number, text?: string, rule?: string, rules?: string[]}[]} jobLines @param {string} label the input's role
36
+ * @returns {{facts: {line: number, forRule?: number, name: string, shape: 'column', column: string, words: string[], source: string}[], asks: {line: number, rule: number|null, source: 'look', ask: 'reading', ruleText: string, question: string, reading: string, word: string, column: string}[], dropped: import('./pagerules.js').Dropped[]}}
37
+ */
38
+ export function applySheetWords(text: string, words: {
39
+ from: string;
40
+ word: string;
41
+ kind: "number" | "other";
42
+ }[], jobLines: {
43
+ n: number;
44
+ text?: string;
45
+ rule?: string;
46
+ rules?: string[];
47
+ }[], label: string): {
48
+ facts: {
49
+ line: number;
50
+ forRule?: number;
51
+ name: string;
52
+ shape: "column";
53
+ column: string;
54
+ words: string[];
55
+ source: string;
56
+ }[];
57
+ asks: {
58
+ line: number;
59
+ rule: number | null;
60
+ source: "look";
61
+ ask: "reading";
62
+ ruleText: string;
63
+ question: string;
64
+ reading: string;
65
+ word: string;
66
+ column: string;
67
+ }[];
68
+ dropped: import("./pagerules.js").Dropped[];
69
+ };
70
+ /**
71
+ * am8 item 3: a .docx's words. A job word that is a heading is kept (the next steps' quotes are still checked word for word on the run's own copy); one that is not is
72
+ * Not checked with its reason, and NOTHING is asked. Same shape as {@link applySheetWords}, with no asks.
73
+ * @param {string[]} headings @param {{from: string, word: string, kind: 'number'|'other'}[]} words
74
+ * @param {{n: number, text?: string, rule?: string, rules?: string[]}[]} jobLines @param {string} label
75
+ * @returns {ReturnType<typeof applySheetWords>}
76
+ */
77
+ export function applyDocWords(headings: string[], words: {
78
+ from: string;
79
+ word: string;
80
+ kind: "number" | "other";
81
+ }[], jobLines: {
82
+ n: number;
83
+ text?: string;
84
+ rule?: string;
85
+ rules?: string[];
86
+ }[], label: string): ReturnType<typeof applySheetWords>;
87
+ /**
88
+ * Look at ONE sheet input: the call (once; once more if the answer is unreadable), then the rules.
89
+ * `callModel(content, attempt)` makes and meters ONE model round and returns `{text}`, `{text, cutOff: true}` or `{error}` (the same seam as `lookAtPage`).
90
+ * @param {{label: string, text: string, jobLines: {n: number, text: string, rule?: string, rules?: string[]}[], callModel: (content: string, attempt: number) => Promise<{text?: string, cutOff?: boolean, error?: string}>, headings?: string[]}} o
91
+ * @returns {Promise<({ok: true, attempts: number} & ReturnType<typeof applySheetWords>)|{ok: false, reason: string, attempts: number}>}
92
+ */
93
+ export function lookAtSheet({ label, text, jobLines, callModel, headings }: {
94
+ label: string;
95
+ text: string;
96
+ jobLines: {
97
+ n: number;
98
+ text: string;
99
+ rule?: string;
100
+ rules?: string[];
101
+ }[];
102
+ callModel: (content: string, attempt: number) => Promise<{
103
+ text?: string;
104
+ cutOff?: boolean;
105
+ error?: string;
106
+ }>;
107
+ headings?: string[];
108
+ }): Promise<({
109
+ ok: true;
110
+ attempts: number;
111
+ } & ReturnType<typeof applySheetWords>) | {
112
+ ok: false;
113
+ reason: string;
114
+ attempts: number;
115
+ }>;
116
+ /** how many data rows the prompt shows (the header is always shown): enough to see what a column holds, never the whole sheet */
117
+ export const SHEET_PROMPT_ROWS: 5;
118
+ /** the line every sheet prompt carries, so a test provider can tell a sheet call from a page call (the system words are the same) */
119
+ export const SHEET_MARK: "THE SHEET OR DOCUMENT:";
120
+ export function columnRuleWords(word: string, column: string): string;