fwdloop 0.22.0 → 0.24.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 (63) hide show
  1. package/bin/fwdloop +31 -8
  2. package/package.json +2 -2
  3. package/src/ask.js +34 -4
  4. package/src/attemptdiff.js +118 -0
  5. package/src/audit-fold.js +2 -0
  6. package/src/authoring.js +36 -2
  7. package/src/canrun.js +5 -0
  8. package/src/checked.js +14 -3
  9. package/src/citedcheck.js +16 -1
  10. package/src/citedwords.js +36 -2
  11. package/src/closers.js +13 -223
  12. package/src/config.js +5 -1
  13. package/src/csv.js +69 -12
  14. package/src/declaration.js +64 -6
  15. package/src/drafter.js +43 -17
  16. package/src/flowmodel.js +56 -1
  17. package/src/learn.js +952 -0
  18. package/src/learnstore.js +346 -0
  19. package/src/model-step.js +15 -21
  20. package/src/pagedry.js +3 -4
  21. package/src/pagefetch.js +9 -2
  22. package/src/pagerules.js +28 -5
  23. package/src/panel/author.js +2 -1
  24. package/src/panel/authorcard.js +9 -2
  25. package/src/panel/data.js +80 -17
  26. package/src/panel/index.html +186 -12
  27. package/src/panel/result.js +6 -0
  28. package/src/redact.js +6 -6
  29. package/src/runner.js +151 -24
  30. package/src/sheet-record.js +57 -0
  31. package/src/sheetblock.js +170 -0
  32. package/src/sheetchecks.js +206 -0
  33. package/src/sheetclaims.js +78 -0
  34. package/src/sheetoffer.js +125 -0
  35. package/src/sheetrun.js +105 -0
  36. package/src/thinking.js +11 -0
  37. package/src/try-checks.js +6 -0
  38. package/src/types.js +1 -9
  39. package/types/ask.d.ts +8 -2
  40. package/types/attemptdiff.d.ts +38 -0
  41. package/types/checked.d.ts +9 -3
  42. package/types/citedwords.d.ts +14 -0
  43. package/types/closers.d.ts +6 -31
  44. package/types/csv.d.ts +25 -4
  45. package/types/declaration.d.ts +6 -1
  46. package/types/drafter.d.ts +28 -9
  47. package/types/flowmodel.d.ts +36 -0
  48. package/types/learn.d.ts +576 -0
  49. package/types/learnstore.d.ts +168 -0
  50. package/types/model-step.d.ts +19 -30
  51. package/types/pagerules.d.ts +7 -0
  52. package/types/panel/authorcard.d.ts +2 -1
  53. package/types/panel/data.d.ts +2 -1
  54. package/types/panel/result.d.ts +1 -1
  55. package/types/runner.d.ts +19 -6
  56. package/types/sheet-record.d.ts +24 -0
  57. package/types/sheetblock.d.ts +116 -0
  58. package/types/sheetchecks.d.ts +70 -0
  59. package/types/sheetclaims.d.ts +26 -0
  60. package/types/sheetoffer.d.ts +25 -0
  61. package/types/sheetrun.d.ts +35 -0
  62. package/types/thinking.d.ts +11 -0
  63. package/types/types.d.ts +16 -11
@@ -0,0 +1,168 @@
1
+ /**
2
+ * M8 item 5a (loose end): the ONE function that turns a source as written into a place. The run-end notes (`learnAtRunEnd`: a path the panel/CLI gave the run) and
3
+ * the drafter's hints (`hintsForRun`: the step's first input, or at draft time the path as typed in the prose) both pass through it, so the same file cannot be two places. A leading `~` or `~/` is the
4
+ * home folder (`path.resolve` alone would make it `<cwd>/~/...`); then `path.resolve` (lexical, no fs: the F48 guard keeps realpathSync out of this file).
5
+ * A web address stays its host (placeOf). Not copied from bareloop: this is the fwdloop-only part of the place.
6
+ * @param {string} p @returns {string}
7
+ */
8
+ export function resolvePlace(p: string): string;
9
+ /**
10
+ * M8 am8: the ONE function that gives a run's place spec: `{job, inputs}` for `placeOf`, from the run's first input AS THE RUN READS IT (`inputsManifest[0].source`,
11
+ * a path the panel or CLI gave the run), never the path written in the signed job. The step's hints (`stepHintsReader`), the run-end tally (`learnAtRunEnd`) and the
12
+ * drafter's hints (src/authoring.js) all build their spec here. No source (a job with no file input) is no place.
13
+ * @param {string} job the workflow name
14
+ * @param {string|null|undefined} source the run's first input as it reads it
15
+ * @returns {{job: string, inputs: {value: string}[]}}
16
+ */
17
+ export function placeSpecOf(job: string, source: string | null | undefined): {
18
+ job: string;
19
+ inputs: {
20
+ value: string;
21
+ }[];
22
+ };
23
+ /**
24
+ * `<configHome>/learn/ledger.json`. Under a test process (NODE_ENV=test or node --test) the home is the explicit one or
25
+ * FWDLOOP_CONFIG_HOME; with neither it THROWS rather than fall back to the real ~/.config/fwdloop.
26
+ * @param {string} [home] test seam; production never passes it
27
+ * @returns {string}
28
+ */
29
+ export function ledgerPath(home?: string): string;
30
+ /**
31
+ * Read the ledger. A missing file is an empty ledger; an unreadable or wrong-shaped one is reported as `problem` (and the
32
+ * writer then refuses to replace it: an append-only record is never silently reset).
33
+ * @param {string} [home]
34
+ * @returns {{ledger: import('./learn.js').Ledger, exists: boolean, problem: string|null}}
35
+ */
36
+ export function readLedger(home?: string): {
37
+ ledger: import("./learn.js").Ledger;
38
+ exists: boolean;
39
+ problem: string | null;
40
+ };
41
+ /**
42
+ * Write the ledger atomically (temp + rename, mode 600), every string masked through the one secret inventory.
43
+ * @param {import('./learn.js').Ledger} ledger @param {string} [home]
44
+ * @returns {string} the file written
45
+ */
46
+ export function writeLedger(ledger: import("./learn.js").Ledger, home?: string): string;
47
+ /**
48
+ * Fold ONE finished run into the ledger on disk: every run's cards COUNT now, rubric jobs too (trust kept on new rows;
49
+ * bareloop v0.47.0). `held` is always 0 (kept in the shape for callers). The run's health line is recorded. Never throws on a bad ledger file: it reports `problem` and writes nothing.
50
+ * @param {{home?: string, runid: string, build: import('./learn.js').CardBuild, workflow: string, place: string|null, specHash: string|null, trust: 'deterministic'|'rubric', at: string, now?: Date}} o
51
+ * @returns {{wrote: boolean, counted: number, held: number, problem: string|null}}
52
+ */
53
+ export function foldRunIntoLedger({ home, runid, build, workflow, place, specHash, trust, at, now }: {
54
+ home?: string;
55
+ runid: string;
56
+ build: import("./learn.js").CardBuild;
57
+ workflow: string;
58
+ place: string | null;
59
+ specHash: string | null;
60
+ trust: "deterministic" | "rubric";
61
+ at: string;
62
+ now?: Date;
63
+ }): {
64
+ wrote: boolean;
65
+ counted: number;
66
+ held: number;
67
+ problem: string | null;
68
+ };
69
+ /**
70
+ * The human Accept at the review door: release a hold an older version wrote for the run so it counts (new runs write none; only forward, only here).
71
+ * @param {{home?: string, runid: string, now?: Date}} o
72
+ * @returns {{released: number, problem: string|null}}
73
+ */
74
+ export function releaseRun({ home, runid, now }: {
75
+ home?: string;
76
+ runid: string;
77
+ now?: Date;
78
+ }): {
79
+ released: number;
80
+ problem: string | null;
81
+ };
82
+ /**
83
+ * M8 am1: the ONE setting, `learningHints` in config.json. Ships OFF (absent = off). OFF still writes the tally ($0); the drafter
84
+ * is simply handed nothing. Copied from bareloop learnstore.js@v0.47.0:96 (borrowed-from header above). Difference: bareloop's
85
+ * `readConfig` returns a problem, fwdloop's THROWS ConfigError on an unreadable / non-JSON / invalid file. The safe reading is kept:
86
+ * a bad or unreadable config reads as OFF (never ON). Under a test process with no explicit home and no FWDLOOP_CONFIG_HOME it
87
+ * reads nothing (OFF), so a test can never reach the real ~/.config/fwdloop.
88
+ * @param {string} [home]
89
+ * @returns {boolean}
90
+ */
91
+ export function learningHintsOn(home?: string): boolean;
92
+ /**
93
+ * One finished run's folder -> the event list buildCards reads, plus the check texts and the model. ONE adapter, map never invent
94
+ * (F79). Check name = `<step> (line <job line>, <close class>)`; a try with verdict red or not-done and a gap = a red moment (the gap
95
+ * verbatim = B1's flagged line); a later try of the same check that is not red = the pass; Fix touched = `artifacts/<step>.json`;
96
+ * What changed = a -U1 line diff of the try's modelOutput (log.json) against the step's previous try. Reads only the run's own books.
97
+ * Refused drafts make no run folder, and a human redo is not a try (isTry), so neither makes a note.
98
+ * @param {string} runDir @param {string} workflow
99
+ * @returns {{events: any[], questions: Map<string, string|null>, model: string|null, source: string|null}|null} null when the run has no try
100
+ */
101
+ export function eventsOfRun(runDir: string, workflow: string): {
102
+ events: any[];
103
+ questions: Map<string, string | null>;
104
+ model: string | null;
105
+ source: string | null;
106
+ } | null;
107
+ /**
108
+ * THE RUN-END TALLY ($0, code only, no model; M8 item 2): turn a finished run's folder into cards and fold them into the ledger.
109
+ * The place is the first input's source made absolute lexically (`path.resolve`, no fs: the F48 guard keeps realpathSync out of this file, so a symlinked source is not followed). The ledger run id is `<workflow>/<runId>` (fwdloop's run ids repeat across workflows, bareloop's do not). M8 am4: every run's notes COUNT at once (trust 'deterministic'), a run
110
+ * with a signed ask included; there is no hold. It runs whether `learningHints` is on or off. `questions` (bareloop's stageQuestionsByName) is, here, the failing check's own text from
111
+ * the run's checks.jsonl, so a check with no checks.jsonl row (a run from before am29) has no `meaning`.
112
+ * Borrowed-from: bareloop src/learnstore.js@v0.47.0:124 (learnAtRunEnd).
113
+ * @param {{home?: string, workflow: string, runId: string, runDir: string, specHash: string|null, now?: Date}} o
114
+ * @returns {{wrote: boolean, counted: number, held: number, problem: string|null, noise: string|null, cards: number}}
115
+ */
116
+ export function learnAtRunEnd({ home, workflow, runId, runDir, specHash, now }: {
117
+ home?: string;
118
+ workflow: string;
119
+ runId: string;
120
+ runDir: string;
121
+ specHash: string | null;
122
+ now?: Date;
123
+ }): {
124
+ wrote: boolean;
125
+ counted: number;
126
+ held: number;
127
+ problem: string | null;
128
+ noise: string | null;
129
+ cards: number;
130
+ };
131
+ /**
132
+ * M8 am6: seed the ledger from every run already recorded under `root` (every job, every ended run), oldest first by the run's own end time
133
+ * (the last history row that is a run end). Each run goes through `learnAtRunEnd` (the one note builder) with `now` = its own end time, so
134
+ * ages, decay and lastSeen come from the run. A run already in the ledger (its `<workflow>/<runId>` has a health line) is skipped, so a second seed adds nothing.
135
+ * Code only, $0. A run it cannot read is counted and the seed goes on; a bad ledger file stops it at once (nothing is rewritten).
136
+ * Under a test process with no door nothing is read or written (`skippedNoDoor`).
137
+ * @param {{root: string, home?: string}} o `home` is a test seam; production leaves it out
138
+ * @returns {{read: number, added: number, skipped: Record<'already-in'|'still-waiting'|'no-end'|'unreadable'|'noise', number>, problem: string|null, skippedNoDoor: boolean}}
139
+ */
140
+ export function seedLedger({ root, home }: {
141
+ root: string;
142
+ home?: string;
143
+ }): {
144
+ read: number;
145
+ added: number;
146
+ skipped: Record<"already-in" | "still-waiting" | "no-end" | "unreadable" | "noise", number>;
147
+ problem: string | null;
148
+ skippedNoDoor: boolean;
149
+ };
150
+ /**
151
+ * M8 item 5a: the block the DRAFTER is handed for this job, made from the ledger as it stood: null when `learningHints` is off,
152
+ * when there is no ledger, or when nothing is readable; an unreadable ledger THROWS (the caller hands nothing and records why). The one `renderHints` render (2,000 characters at most),
153
+ * never a second. Age (56 days), job version and level are worked out here, at read time, by renderHints.
154
+ * Borrowed-from: bareloop src/learnstore.js@v0.47.0:140 (hintsForRun). `spec` is `{job, inputs: [{value}]}` (job = the workflow name).
155
+ * @param {{home?: string, spec: any, specHash: string|null, now?: Date}} o
156
+ * @returns {{text: string, ids: string[]}|null}
157
+ */
158
+ export function hintsForRun({ home, spec, specHash, now }: {
159
+ home?: string;
160
+ spec: any;
161
+ specHash: string | null;
162
+ now?: Date;
163
+ }): {
164
+ text: string;
165
+ ids: string[];
166
+ } | null;
167
+ /** M8 am4 item 2: a run waiting at an ask has not ended ('paused', or a Stop whose set-aside failed). ONE decider: the runner's run-end tally and the seed both read it. */
168
+ export const NOT_A_RUN_END: Set<string>;
@@ -15,34 +15,8 @@ export function isTransportFailure(err: any): boolean;
15
15
  * only (plus, for a green step that quotes a saved page, the form of its answer).
16
16
  * `stepClass` is `'green' | 'softgreen' | 'hitl' | null | undefined`; `cited` is true for that green step.
17
17
  */
18
- export function buildEmitArtifactSchema(stepClass: any, cited?: boolean): Readonly<{
19
- type: "object";
20
- properties: {
21
- done: {
22
- type: string;
23
- description: string;
24
- };
25
- blocker: {
26
- type: string[];
27
- description: string;
28
- };
29
- fields: {
30
- type: string;
31
- additionalProperties: {
32
- type: string;
33
- properties: {
34
- value: {};
35
- cite: {
36
- type: string;
37
- description: string;
38
- };
39
- };
40
- required: string[];
41
- };
42
- };
43
- };
44
- required: string[];
45
- }> | Readonly<{
18
+ /** @param {string|null|undefined} stepClass @param {boolean} [cited] @param {any[]|null} [sheet] M10b piece 2: the step's `close.sheet` (its claim boxes become the answer) */
19
+ export function buildEmitArtifactSchema(stepClass: string | null | undefined, cited?: boolean, sheet?: any[] | null): Readonly<{
46
20
  type: "object";
47
21
  properties: {
48
22
  done: {
@@ -108,7 +82,21 @@ export function buildEmitArtifactSchema(stepClass: any, cited?: boolean): Readon
108
82
  };
109
83
  required: string[];
110
84
  additionalProperties: false;
111
- }>;
85
+ }> | {
86
+ type: string;
87
+ properties: {
88
+ done: {
89
+ type: string;
90
+ description: string;
91
+ };
92
+ blocker: {
93
+ type: string[];
94
+ description: string;
95
+ };
96
+ };
97
+ required: string[];
98
+ additionalProperties: boolean;
99
+ };
112
100
  /**
113
101
  * @param {object} opts
114
102
  * @param {string} [opts.slot] - a provider row (the name of a key in the keys file); required when `provider` isn't injected.
@@ -118,7 +106,7 @@ export function buildEmitArtifactSchema(stepClass: any, cited?: boolean): Readon
118
106
  * @param {{in:number,out:number}} [opts.rates]
119
107
  * @param {string} [opts.modelId]
120
108
  * @param {Record<string,string|undefined>} [opts.env] - the merged shell+keys-file env the key is read from (default process.env).
121
- * @returns {(executorContext:object, grantedTools:Record<string,any>, stepMeta?:{class?:string, attempt?:number, step?:string|null, cited?:any, thinkingMode?:'on'|'off'}, seam?:{stopRequested?:() => boolean}) => Promise<any>}
109
+ * @returns {(executorContext:object, grantedTools:Record<string,any>, stepMeta?:{class?:string, attempt?:number, step?:string|null, cited?:any, sheet?:any[]|null, thinkingMode?:'on'|'off'}, seam?:{stopRequested?:() => boolean}) => Promise<any>}
122
110
  */
123
111
  export function makeLiveModelStep({ slot, model, spendPath, provider: injectedProvider, rates: injectedRates, modelId: injectedModelId, env, }: {
124
112
  slot?: string | undefined;
@@ -136,6 +124,7 @@ export function makeLiveModelStep({ slot, model, spendPath, provider: injectedPr
136
124
  attempt?: number;
137
125
  step?: string | null;
138
126
  cited?: any;
127
+ sheet?: any[] | null;
139
128
  thinkingMode?: "on" | "off";
140
129
  }, seam?: {
141
130
  stopRequested?: () => boolean;
@@ -19,6 +19,13 @@ export function tieOf(from: unknown, jobLines: {
19
19
  * @param {unknown} shape @param {unknown} r @returns {boolean}
20
20
  */
21
21
  export function validReading(shape: unknown, r: unknown): boolean;
22
+ /** a number as the page writes it: digits, thousands commas, optional decimals (a currency sign next to it is not part of it) */
23
+ /**
24
+ * The number written at the very end of `s` (only whitespace after it): the leftmost match of NUM followed by `\s*$`. Shared with src/pagedry.js (one copy). Scans back from the end, so a
25
+ * long run of digits and commas costs O(n) where a backtracking regex is quadratic.
26
+ * @param {string} s @returns {string|undefined}
27
+ */
28
+ export function numberAtEnd(s: string): string | undefined;
22
29
  /**
23
30
  * Apply the rules to the AI's map over one saved page. Returns the kept facts and, for everything a rule removed, one `dropped` entry.
24
31
  * The order of the rules is the POC's (apply-v3.mjs): found-on-page, then the rules that read the page. A place is read as a phrase.
@@ -24,7 +24,8 @@ export function parseJobBox(text: string): {
24
24
  * M4e amendment 24 item 3: the submitted job box with each answer added WORD FOR WORD as a `~` line under the job line it is about, after
25
25
  * that line's own `~` lines (several answers for one line keep their order). The job box's own lines are untouched; the card -> prose path
26
26
  * (`cardToProse`) then writes the answer as that line's guardrail, so it reaches the signed text and the hash. Pure. An answer for a line
27
- * the box does not have is NOT added (the caller sees the count).
27
+ * the box does not have is NOT added (the caller sees the count). An answer equal (exact string, after trim) to a `~` rule already on that line is not added
28
+ * again, and still counts: it is taken, the line already says it.
28
29
  * @param {string} job @param {{ line: number, answer: string }[]} answers
29
30
  * @returns {{ job: string, added: number }}
30
31
  */
@@ -658,7 +658,7 @@ export function getDraftBlock(flowDir: string, runDir: string): {
658
658
  * shared-sidecar contamination risk here the way bareloop's gate-audit
659
659
  * sidecar had). `null` when the flow/runId doesn't resolve (404).
660
660
  * @param {{root: string, flow: string, runId: string, scheduleRead?: (flow: string) => any, home?: string, catalogue?: any, resumeAttempt?: (flow: string, runId: string) => any, startingRun?: (flow: string, runId: string) => boolean, now?: () => number}} opts
661
- * @returns {{flow:string, runId:string, rows:any[], groups:any[], draft:ReturnType<typeof getDraftBlock>, needsLeft: string|null, schedule: ReturnType<typeof scheduleAuditWords>, empty:boolean, why:string|null}|null}
661
+ * @returns {{flow:string, runId:string, rows:any[], groups:any[], draft:ReturnType<typeof getDraftBlock>, learnings: any[], needsLeft: string|null, schedule: ReturnType<typeof scheduleAuditWords>, empty:boolean, why:string|null}|null}
662
662
  */
663
663
  export function getRunAudit({ root, flow, runId, scheduleRead, home, catalogue, resumeAttempt, startingRun, now, }: {
664
664
  root: string;
@@ -676,6 +676,7 @@ export function getRunAudit({ root, flow, runId, scheduleRead, home, catalogue,
676
676
  rows: any[];
677
677
  groups: any[];
678
678
  draft: ReturnType<typeof getDraftBlock>;
679
+ learnings: any[];
679
680
  needsLeft: string | null;
680
681
  schedule: ReturnType<typeof scheduleAuditWords>;
681
682
  empty: boolean;
@@ -109,7 +109,7 @@ export function buildResult({ flow, runId, runDir, root, flowRead, arbiter, hist
109
109
  path: string;
110
110
  name: string;
111
111
  bytes: number | null;
112
- state: "ok" | "gone" | "changed";
112
+ state: "ok" | "changed" | "gone";
113
113
  words: string | null;
114
114
  }[];
115
115
  gap: {
package/types/runner.d.ts CHANGED
@@ -29,12 +29,13 @@ 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}} opts */
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 */
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
+ hints?: string | null;
38
39
  }): Readonly<{
39
40
  goal: string;
40
41
  primitives: readonly string[];
@@ -42,6 +43,7 @@ export function buildExecutorContext(opts: {
42
43
  [x: string]: any;
43
44
  }>;
44
45
  gap: string | null;
46
+ hints: string | null;
45
47
  }>;
46
48
  /**
47
49
  * @param {unknown} value
@@ -98,11 +100,14 @@ export function freezePage(dir: string, id: string, url: string, { fetchPage }?:
98
100
  * unreadable source refuses by name. A source that is a web address
99
101
  * (M10 item 1) is fetched and frozen by `freezePage`, in the same manifest.
100
102
  * @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] */
103
+ * M10b amendment 1: a CSV input named in `tableRoles` (the sheets a step's `close.sheet` reads) also gets its `tableSha` (bareguard's fingerprint of the table made
104
+ * from the FROZEN copy) in its manifest entry - the ONE place it is written, once, with the run's inputs; every sheet check of the run uses this recorded value.
105
+ * A sheet bareguard cannot read as a table refuses the run here, naming the input.
106
+ * @param {{fetchPage?: (url: string) => Promise<{ok: true, text: string, url: string}|{ok: false, error: string}>, tableRoles?: string[]}} [o] */
102
107
  export function freezeInputs(runDir: string, sources: Array<{
103
108
  id: string;
104
109
  path: string;
105
- }>, { fetchPage }?: {
110
+ }>, { fetchPage, tableRoles }?: {
106
111
  fetchPage?: (url: string) => Promise<{
107
112
  ok: true;
108
113
  text: string;
@@ -111,19 +116,20 @@ export function freezeInputs(runDir: string, sources: Array<{
111
116
  ok: false;
112
117
  error: string;
113
118
  }>;
119
+ tableRoles?: string[];
114
120
  }): Promise<{
115
121
  ok: boolean;
116
122
  red: string;
117
123
  manifest?: undefined;
118
124
  } | {
119
125
  ok: boolean;
120
- manifest: {
126
+ manifest: (Record<string, any> | {
121
127
  id: string;
122
128
  source: string;
123
129
  frozen: string;
124
130
  sha256: string;
125
131
  bytes: number;
126
- }[];
132
+ })[];
127
133
  red?: undefined;
128
134
  }>;
129
135
  /** The send target's folder (M4e amendment 1, "Destination is any folder").
@@ -228,6 +234,7 @@ export function readArtifactsMapChecked(runDir: any, ids: any, { docxRoles }?: {
228
234
  * @param {(row: any, modelOutput?: any) => void} opts.recordAudit
229
235
  * @param {string|null} [opts.initialGap]
230
236
  * @param {number} [opts.attemptOffset]
237
+ * @param {(() => {text: string, ids: string[]}|null)|null} [opts.learnHints] - M8 am7: `stepHintsReader`'s closure (the drafter's one block function); asked only on a retry, redo or rerun try
231
238
  * @param {boolean} [opts.thinkingBox] - M4d am25: the job's "Thinking on" box as this run's copy keeps it (default off)
232
239
  * @param {() => string} [opts.now] - M4a-2: stamps each audit row's `at`;
233
240
  * defaults to the real wall clock.
@@ -238,7 +245,7 @@ export function readArtifactsMapChecked(runDir: any, ids: any, { docxRoles }?: {
238
245
  * @param {string|null} [opts.runDir] - M4d am29 item 2: the run's folder, where each try saves its checks
239
246
  * @returns {Promise<{ok:true, artifact:any, attempts:number, hitl?:boolean} | {ok:false, outcome:string, red:string, stop?:{where:string, book:Record<string, any>, step?:string|null}}>}
240
247
  */
241
- export function runStepRalph({ step, primitivesMap, readsMap, businessDate, modelStep, spent, capUsd, ceilingUsd, recordAudit, initialGap, attemptOffset, thinkingBox, now, readStop, stepNo, triesDone, runDir, prevStepId, }: {
248
+ export function runStepRalph({ step, primitivesMap, readsMap, businessDate, modelStep, spent, capUsd, ceilingUsd, recordAudit, initialGap, attemptOffset, thinkingBox, learnHints, now, readStop, stepNo, triesDone, runDir, prevStepId, }: {
242
249
  step: any;
243
250
  primitivesMap?: Record<string, any> | undefined;
244
251
  readsMap: Record<string, any>;
@@ -256,6 +263,10 @@ export function runStepRalph({ step, primitivesMap, readsMap, businessDate, mode
256
263
  recordAudit: (row: any, modelOutput?: any) => void;
257
264
  initialGap?: string | null | undefined;
258
265
  attemptOffset?: number | undefined;
266
+ learnHints?: (() => {
267
+ text: string;
268
+ ids: string[];
269
+ } | null) | null | undefined;
259
270
  thinkingBox?: boolean | undefined;
260
271
  now?: (() => string) | undefined;
261
272
  readStop?: (() => boolean) | null | undefined;
@@ -540,3 +551,5 @@ export const MAX_ATTEMPTS: 4;
540
551
  export const SPEND_TOLERANCE_USD: 1e-9;
541
552
  export const STOP_FILE: "stop.request";
542
553
  export const HALT_FILE: "halt.json";
554
+ /** where a failure of learnings work that must not stop the run is recorded (one appended row, in the run's own folder): the run-end tally (`recordRunNotes`) and the take of the draft's learnings record (`takeLearningsRecord`, in runFlow). The run itself is unaffected */
555
+ export const LEARN_ERROR_FILE: "learn-error.jsonl";
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @param {string} runDir @param {{n: number, try: number, checks: any[], closed: {verdict: string, red?: string|null, sheetRecord?: any}}} o
3
+ * @returns {void}
4
+ */
5
+ export function writeSheetLine(runDir: string, { n, try: attempt, checks, closed }: {
6
+ n: number;
7
+ try: number;
8
+ checks: any[];
9
+ closed: {
10
+ verdict: string;
11
+ red?: string | null;
12
+ sheetRecord?: any;
13
+ };
14
+ }): void;
15
+ /**
16
+ * The reader of the record, for the Result tab and the separate checker: `{lines: [...]}`, or null when the file is missing or is not that shape (the page then
17
+ * shows no verdicts, never a half-read record). Read through the safe gateway.
18
+ * @param {string} runDir @returns {{lines: any[]}|null}
19
+ */
20
+ export function readSheetChecks(runDir: string): {
21
+ lines: any[];
22
+ } | null;
23
+ /** the record's name in the run's own folder */
24
+ export const SHEET_CHECKS_FILE: "sheet-checks.json";
@@ -0,0 +1,116 @@
1
+ /** the ops of bareguard that a name is needed for @returns {string[]} */
2
+ export function vocabularyOps(): string[];
3
+ /** @param {any} check a bareguard cells / table check @returns {string} the short name: `rows`, `count`, `sum`, `no duplicate Invoice #` ... */
4
+ export function sheetCheckName(check: any): string;
5
+ /**
6
+ * What the step claimed for one check, in plain words (a green check's "found"). Null when the claim has nothing to say (a `table` check, a missing box, a string).
7
+ * @param {any} check @param {unknown} claims the step's answer @returns {string|null}
8
+ */
9
+ export function sheetFoundWords(check: any, claims: unknown): string | null;
10
+ /**
11
+ * The block of every job line whose step reads a sheet. A line qualifies when its green step carries `close.sheet`, or (with `csvRoles`) reads a CSV input and carries no
12
+ * older `close.columns` / `close.cited` check (then every guardrail is Not checked).
13
+ * @param {{declaration: any, lines: Array<{n: number, rules?: string[], guardrail?: string, rule?: string}>, csvRoles?: string[], record?: any}} o
14
+ * `record` = the parsed `sheet-checks.json` (`{lines: [...]}`), only after a run
15
+ * @returns {Array<{line: number, guardrails: string[], checked: Array<{id: string, name: string, words: string, covers: string[], coversWords: string, text: string, ok?: boolean, found?: string}>, notChecked: string[]|'none'}>}
16
+ */
17
+ export function sheetLineBlocks({ declaration, lines, csvRoles, record }: {
18
+ declaration: any;
19
+ lines: Array<{
20
+ n: number;
21
+ rules?: string[];
22
+ guardrail?: string;
23
+ rule?: string;
24
+ }>;
25
+ csvRoles?: string[];
26
+ record?: any;
27
+ }): Array<{
28
+ line: number;
29
+ guardrails: string[];
30
+ checked: Array<{
31
+ id: string;
32
+ name: string;
33
+ words: string;
34
+ covers: string[];
35
+ coversWords: string;
36
+ text: string;
37
+ ok?: boolean;
38
+ found?: string;
39
+ }>;
40
+ notChecked: string[] | "none";
41
+ }>;
42
+ /**
43
+ * The guardrail rules of a sheet step that no check covers, as the drafter's Not-checked lines (`line N: "rule" - no sheet check covers it`): the block's own
44
+ * `notChecked`, one list for the plan card and the drafter's saved record.
45
+ * @param {any} declaration @param {Array<{n: number, rules?: string[], guardrail?: string, rule?: string}>} lines @param {string[]} csvRoles @returns {string[]}
46
+ */
47
+ export function uncoveredRules(declaration: any, lines: Array<{
48
+ n: number;
49
+ rules?: string[];
50
+ guardrail?: string;
51
+ rule?: string;
52
+ }>, csvRoles: string[]): string[];
53
+ /** @param {any} arbiter @returns {string[]} the roles of the signed sources that are a CSV file (the sheets a check reads) */
54
+ export function csvRolesOf(arbiter: any): string[];
55
+ /**
56
+ * M10b am4: the step's answer (its claim boxes) value by value, one line each: `invoiceCount: 8`, `daysPastDue: row 2 -> 124`. A list is one line per entry (a list of row
57
+ * numbers reads `row N`); a map is one line per key (`row <key> -> <value>`). An empty list or map reads `<name>: none`, never no line.
58
+ * Throws away: nothing but the box's own key (`value`, `rows`, `days`...), which the line's words already say.
59
+ * @param {unknown} claims the step's answer @returns {string[]}
60
+ */
61
+ export function claimLines(claims: unknown): string[];
62
+ /**
63
+ * M10b am4: what an ask card shows for the claim boxes it was given. The step is the sheet step whose saved try (`sheet-checks.json`) holds exactly these claims; its block is
64
+ * the Result tab's own (`sheetLineBlocks`, that try's verdicts), and `answer` is the claims value by value. Null when no saved try matches: the caller then keeps the old line.
65
+ * @param {{claims: unknown, declaration: any, lines: Array<{n: number, rules?: string[], guardrail?: string, rule?: string}>, csvRoles?: string[], record?: any}} o
66
+ * @returns {{block: ReturnType<typeof sheetLineBlocks>[number], answer: string[]}|null}
67
+ */
68
+ export function askSheetCard({ claims, declaration, lines, csvRoles, record }: {
69
+ claims: unknown;
70
+ declaration: any;
71
+ lines: Array<{
72
+ n: number;
73
+ rules?: string[];
74
+ guardrail?: string;
75
+ rule?: string;
76
+ }>;
77
+ csvRoles?: string[];
78
+ record?: any;
79
+ }): {
80
+ block: ReturnType<typeof sheetLineBlocks>[number];
81
+ answer: string[];
82
+ } | null;
83
+ /** the short plain name of each bareguard op (the ONE table; a test fails when bareguard gains an op this table does not name). `noDuplicates` and `noEmpty` add the column. */
84
+ export const SHEET_OP_NAMES: Readonly<{
85
+ count: "count";
86
+ countEmpty: "empty count";
87
+ countIf: "count";
88
+ uniqueCount: "unique count";
89
+ sum: "sum";
90
+ sumIf: "sum";
91
+ average: "average";
92
+ averageIf: "average";
93
+ median: "median";
94
+ min: "min";
95
+ max: "max";
96
+ found: "found";
97
+ lookup: "lookup";
98
+ rows: "rows";
99
+ topN: "top";
100
+ duplicates: "duplicates";
101
+ groupTotals: "group totals";
102
+ percentOfTotal: "percent of total";
103
+ band: "bucket";
104
+ daysBetween: "days between";
105
+ daysSince: "date";
106
+ earliest: "earliest date";
107
+ latest: "latest date";
108
+ allNumbers: "all numbers";
109
+ allDates: "all dates";
110
+ noEmpty: "no empty";
111
+ noDuplicates: "no duplicate";
112
+ rowCount: "row count";
113
+ rowMath: "row math";
114
+ }>;
115
+ export function rulesOfLine(l: any): string[];
116
+ export function coversWords(rules: string[]): string;
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Every column name one check holds: its own `column`, `keyColumn`, `groupColumn`, `result`, a row-math operand `a` / `b` (a name; `{const}` is no column), the
3
+ * date cells `from` / `to` / `cell`, and the column of each `where` condition and `dateFormats` entry.
4
+ * @param {any} check @returns {string[]}
5
+ */
6
+ export function sheetCheckColumns(check: any): string[];
7
+ /**
8
+ * The plain words of ONE sheet check, written from its typed fields (never from model text). The ONE function; the plan card, the readout and the Checked
9
+ * list all call it. An op with no sentence of its own reads `<rule> <op> on <column>` plus its conditions, so a check can never be shown as nothing.
10
+ * @param {any} check a bareguard cells / table check object @returns {string}
11
+ */
12
+ export function sheetCheckSentence(check: any): string;
13
+ /**
14
+ * M10b piece 4: a signed check may carry fwdloop's own `covers` (the numbers of the job line's `~` rules the drafter tagged it to; signed, so the person sees it).
15
+ * bareguard does not know it, so the checks are cleaned HERE, the ONE place, on the way into bareguard (`createRubric` at sign time and at run time).
16
+ * @param {any[]} checks @returns {any[]} a copy without `covers`
17
+ */
18
+ export function bareguardChecks(checks: any[]): any[];
19
+ /**
20
+ * M10b piece 4: `covers`, when a check has it, is a list of rule numbers of its job line (counted from 1 over the line's `~` rules). A check without it is fine (an old draft).
21
+ * @param {any[]} checks @param {{n: number, rule?: string, rules?: string[]}} jobLine @returns {string[]} reds, each naming the line and the check
22
+ */
23
+ export function sheetCoversReds(checks: any[], jobLine: {
24
+ n: number;
25
+ rule?: string;
26
+ rules?: string[];
27
+ }): string[];
28
+ /** The rows for a step's `close.sheet`, one per check, in order. @param {unknown} sheet @returns {string[]} */
29
+ export function sheetCheckRows(sheet: unknown): string[];
30
+ /**
31
+ * The $0 sign-time test of one step's sheet checks (M10b item 4): bareguard's `createRubric` is given the checks and the signed fingerprint of each sheet
32
+ * they read (`tableSha` of the drafting copy's table). A refusal is a red that names the job line (and the check). A column that is no header of its sheet is
33
+ * a red naming the line and the column. Never throws.
34
+ * @param {any[]} checks the step's `close.sheet` (already known to be a list of objects) @param {number} line the job line the step comes from
35
+ * @param {Record<string, {header: string[], rows: any[]}>} tables the drafting copy's table of each sheet role @returns {string[]} reds, each naming the line
36
+ */
37
+ export function sheetCheckReds(checks: any[], line: number, tables: Record<string, {
38
+ header: string[];
39
+ rows: any[];
40
+ }>): string[];
41
+ /**
42
+ * M10b piece 3: a number or a date in a check comes from the job, never from the model. Every number in a `where` condition (gt gte lt lte eq between) must be a
43
+ * number the person said on the job line or its `~` rules (the SAME reader as the page number rules, src/citedwords.js `numbersSaid`: a bare number or an amount,
44
+ * not a piece of a time, a date or another amount), and every date (`asOf`, and the values of before / after / dateOn / dateBetween) must be a date they wrote
45
+ * exactly. Throws away: a text value (`equals`, `needle`), band bounds, `n`, `tolerance`, `range` are not read here (the job's words do not have to carry them).
46
+ * @param {any[]} checks the step's `close.sheet` @param {{n: number, text?: string, rule?: string, rules?: string[]}} jobLine @returns {string[]} reds, each naming the line
47
+ */
48
+ export function sheetCheckWordReds(checks: any[], jobLine: {
49
+ n: number;
50
+ text?: string;
51
+ rule?: string;
52
+ rules?: string[];
53
+ }): string[];
54
+ /**
55
+ * M10b piece 3: a step whose sheet checks are ALL `table` checks has nothing to answer (a table check judges the sheet itself and carries no claim), so the
56
+ * step would be asked for nothing. Refused at $0, naming the line. @param {any[]} checks @param {number} line @returns {string[]}
57
+ */
58
+ export function sheetNoClaimReds(checks: any[], line: number): string[];
59
+ /** the bareguard rules a sheet check may use (`diff` is out of scope for M10b) */
60
+ export const SHEET_RULES: readonly string[];
61
+ /** most checks one step may carry */
62
+ export const MAX_SHEET_CHECKS: 20;
63
+ /** the fields of a check that hold a column name as a plain string (the ONE list: {@link sheetCheckColumns} reads it, the drafter's tool schema offers a header enum on each) */
64
+ export const COLUMN_STRING_FIELDS: readonly string[];
65
+ /** the row-math operands: a column name, or (for `b`) `{const}` */
66
+ export const COLUMN_OPERAND_FIELDS: readonly string[];
67
+ /** the date-cell fields: `{column, row}` */
68
+ export const COLUMN_CELL_FIELDS: readonly string[];
69
+ /** the list fields whose entries hold a `column` */
70
+ export const COLUMN_LIST_FIELDS: readonly string[];
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The claim box of every `cells` check in the list: `[{claim, example}]`, one per claim name, in order. `example` is the op's worked-example answer (the box's shape
3
+ * with example values). A check bareguard has no example for, and a `table` check, add nothing.
4
+ * @param {any[]} checks a step's `close.sheet` @returns {Array<{claim: string, example: Record<string, any>, ops: string[]}>}
5
+ */
6
+ export function sheetClaims(checks: any[]): Array<{
7
+ claim: string;
8
+ example: Record<string, any>;
9
+ ops: string[];
10
+ }>;
11
+ /**
12
+ * The `emit_artifact` tool's properties for a step that reads a sheet: one typed box per claim, each required. (`done` is added by the caller, as for every step.)
13
+ * @param {any[]} checks @returns {{properties: Record<string, any>, required: string[]}}
14
+ */
15
+ export function sheetAnswerProps(checks: any[]): {
16
+ properties: Record<string, any>;
17
+ required: string[];
18
+ };
19
+ /**
20
+ * What the step is told about its answer (one key of its request): the name and the shape of each box, with the worked example's values. Never the check.
21
+ * @param {any[]} checks @returns {{answer: string, fields: Record<string, Record<string, any>>}}
22
+ */
23
+ export function sheetBrief(checks: any[]): {
24
+ answer: string;
25
+ fields: Record<string, Record<string, any>>;
26
+ };