fwdloop 0.32.0 → 0.34.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 (114) hide show
  1. package/bin/fwdloop +20 -2
  2. package/package.json +2 -2
  3. package/src/auditchecks.js +55 -0
  4. package/src/authoring.js +53 -12
  5. package/src/blockasks.js +45 -0
  6. package/src/blockassemble.js +159 -0
  7. package/src/blockdraft.js +86 -0
  8. package/src/blocklines.js +30 -0
  9. package/src/blockpick.js +175 -0
  10. package/src/cardlist.js +19 -0
  11. package/src/checkblock.js +843 -0
  12. package/src/checked.js +48 -9
  13. package/src/checklist.js +99 -0
  14. package/src/checklistsign.js +93 -0
  15. package/src/checkpick.js +7 -73
  16. package/src/checkwords.js +20 -1
  17. package/src/cited-record.js +21 -1
  18. package/src/citedcheck.js +162 -7
  19. package/src/closers.js +41 -3
  20. package/src/declaration.js +34 -9
  21. package/src/declaredclose.js +4 -0
  22. package/src/draft-steps.js +3 -1
  23. package/src/drafter.js +311 -206
  24. package/src/factwords.js +112 -0
  25. package/src/inputlook.js +53 -0
  26. package/src/labelscan.js +162 -0
  27. package/src/noteask.js +62 -0
  28. package/src/pageask.js +9 -69
  29. package/src/pagedropwords.js +11 -1
  30. package/src/pagedry.js +27 -4
  31. package/src/pagerules.js +19 -3
  32. package/src/panel/author.js +76 -7
  33. package/src/panel/authorcard.js +43 -17
  34. package/src/panel/data.js +41 -9
  35. package/src/panel/index.html +208 -13
  36. package/src/panel/result.js +4 -3
  37. package/src/panel/server.js +3 -1
  38. package/src/pickrecord.js +70 -54
  39. package/src/placerule.js +398 -0
  40. package/src/planrebuild.js +216 -0
  41. package/src/rowedit.js +148 -0
  42. package/src/rubricstep.js +272 -0
  43. package/src/runfile.js +4 -2
  44. package/src/runner.js +67 -10
  45. package/src/setup.js +11 -5
  46. package/src/sheetblock.js +22 -8
  47. package/src/sheetbuild.js +151 -0
  48. package/src/sheetchecks.js +52 -66
  49. package/src/sheetclaims.js +12 -32
  50. package/src/sheetfind.js +4 -4
  51. package/src/sheetlook.js +14 -3
  52. package/src/sheetoffer.js +74 -57
  53. package/src/sheetrows.js +123 -0
  54. package/src/sheetrun.js +13 -10
  55. package/src/summary-words.js +3 -3
  56. package/src/ticket-draft.js +4 -21
  57. package/src/ticketrows.js +100 -0
  58. package/src/try-checks.js +31 -12
  59. package/src/types.js +1 -0
  60. package/types/auditchecks.d.ts +25 -0
  61. package/types/authoring.d.ts +21 -2
  62. package/types/blockasks.d.ts +36 -0
  63. package/types/blockassemble.d.ts +50 -0
  64. package/types/blockdraft.d.ts +75 -0
  65. package/types/blocklines.d.ts +31 -0
  66. package/types/blockpick.d.ts +46 -0
  67. package/types/cardlist.d.ts +21 -0
  68. package/types/checkblock.d.ts +378 -0
  69. package/types/checked.d.ts +16 -2
  70. package/types/checklist.d.ts +115 -0
  71. package/types/checklistsign.d.ts +27 -0
  72. package/types/checkpick.d.ts +4 -34
  73. package/types/checkwords.d.ts +5 -0
  74. package/types/cited-record.d.ts +9 -0
  75. package/types/citedcheck.d.ts +33 -2
  76. package/types/closers.d.ts +24 -2
  77. package/types/declaration.d.ts +7 -0
  78. package/types/declaredclose.d.ts +2 -0
  79. package/types/drafter.d.ts +29 -715
  80. package/types/factwords.d.ts +38 -0
  81. package/types/inputlook.d.ts +49 -0
  82. package/types/labelscan.d.ts +35 -0
  83. package/types/noteask.d.ts +52 -0
  84. package/types/pageask.d.ts +2 -35
  85. package/types/pagedry.d.ts +13 -0
  86. package/types/pagerules.d.ts +7 -0
  87. package/types/panel/author.d.ts +41 -0
  88. package/types/panel/authorcard.d.ts +14 -9
  89. package/types/panel/authorflows.d.ts +4 -4
  90. package/types/panel/data.d.ts +5 -3
  91. package/types/panel/jobgrid.d.ts +1 -1
  92. package/types/pickrecord.d.ts +69 -13
  93. package/types/placerule.d.ts +208 -0
  94. package/types/planrebuild.d.ts +52 -0
  95. package/types/provider.d.ts +1 -1
  96. package/types/rowedit.d.ts +48 -0
  97. package/types/rubricstep.d.ts +63 -0
  98. package/types/runfile.d.ts +5 -2
  99. package/types/runner.d.ts +45 -1
  100. package/types/sheetblock.d.ts +12 -4
  101. package/types/sheetbuild.d.ts +84 -0
  102. package/types/sheetchecks.d.ts +12 -18
  103. package/types/sheetclaims.d.ts +2 -1
  104. package/types/sheetfind.d.ts +2 -2
  105. package/types/sheetoffer.d.ts +31 -6
  106. package/types/sheetrows.d.ts +81 -0
  107. package/types/sheetrun.d.ts +4 -4
  108. package/types/summary-words.d.ts +2 -1
  109. package/types/ticket-draft.d.ts +3 -49
  110. package/types/ticketrows.d.ts +61 -0
  111. package/types/try-checks.d.ts +4 -2
  112. package/types/types.d.ts +8 -0
  113. package/src/repairs.js +0 -38
  114. package/types/repairs.d.ts +0 -13
@@ -0,0 +1,208 @@
1
+ /**
2
+ * @typedef {{kind: 'headingBetween'|'headingDateAfter', prefix: string, end: string, shape: string, skip: string[]}} PlaceRule
3
+ * @typedef {{found: true, value: string, lineIndex: number}|{found: false, reason: string}} PlaceRead
4
+ */
5
+ /**
6
+ * Why a rule is not a legal place rule, or null when it is. Pure.
7
+ * @param {unknown} rule @returns {string|null}
8
+ */
9
+ export function placeRuleProblem(rule: unknown): string | null;
10
+ /**
11
+ * Heading lines at the rule's level: lines outside ``` / ~~~ fences that start with the level mark (for example "## "). Pure.
12
+ * @param {string} text @param {string} prefix @returns {{i: number, line: string}[]}
13
+ */
14
+ export function levelLines(text: string, prefix: string): {
15
+ i: number;
16
+ line: string;
17
+ }[];
18
+ /**
19
+ * The mixed-level guard: every non-fenced heading line is scanned; semver-carrying headings at MORE THAN ONE level mean mixed. A heading with no
20
+ * semver (a "# Changelog" title, "### Fixed") is ignored. It only ever turns a read into not found, never into a value.
21
+ * @param {string} text @returns {boolean}
22
+ */
23
+ export function mixedLevels(text: string): boolean;
24
+ /**
25
+ * Read one rule against one input text: the run-start function, code only. A rule that is not legal throws (the signed spec was validated, so a bad one
26
+ * is a defect, never a read).
27
+ * @param {PlaceRule} rule @param {string} text @returns {PlaceRead}
28
+ */
29
+ export function readPlace(rule: PlaceRule, text: string): PlaceRead;
30
+ /**
31
+ * Fit a place rule to a fact's own words, by CODE, at drafting. The words must be exactly one version (X.Y.Z) or exactly one ISO date; the frozen
32
+ * candidates are walked in order, and the first whose strict first-heading read on the input's own text returns exactly those words wins. Null =
33
+ * no fit (a version and a date together, any other words, another date form, a mixed-level file, no text, or no candidate reading them): the caller
34
+ * refuses the words as week-only exactly as before. Only the two kinds are handled. Pure.
35
+ * @param {string} words @param {string|null|undefined} text
36
+ * @returns {PlaceRule|null}
37
+ */
38
+ export function fitPlaceRule(words: string, text: string | null | undefined): PlaceRule | null;
39
+ /**
40
+ * STRIP (P1b, hamr 2026-11-11): the words of a phrase fact that are a piece of the newest release heading ("## [0.54.1]", "[0.54.1] -", "0.54.1",
41
+ * "2026-11-04", "## [0.54.1] - 2026-11-04") are stripped by code to their value(s). The words hold exactly one version (X.Y.Z, an optional leading v) and/or
42
+ * exactly one ISO date and nothing else but heading marks; each value is fitted with {@link fitPlaceRule} on the input's own text, and when both are
43
+ * present both must sit on the SAME first release heading line. Returns the values (version first) each with its rule, or null: two versions, two dates,
44
+ * any other word, another date form, a value that is not at the first release heading, no text. Pure.
45
+ * @param {string} words @param {string|null|undefined} text
46
+ * @returns {{kind: 'version'|'date', value: string, rule: PlaceRule}[]|null}
47
+ */
48
+ export function fitPlacePhrase(words: string, text: string | null | undefined): {
49
+ kind: "version" | "date";
50
+ value: string;
51
+ rule: PlaceRule;
52
+ }[] | null;
53
+ /**
54
+ * @typedef {{key: string, name: string, source: string, stage: number, part: number, fact: number, place: PlaceRule, phrase: string}} PlaceFact
55
+ */
56
+ /**
57
+ * Every place-rule fact of a spec, in stage / part / fact order. The key is the stage's name and the fact's name (both stable across the runs of one
58
+ * workflow), so an earlier run's record finds the same fact. Pure.
59
+ * @param {any} spec @returns {PlaceFact[]}
60
+ */
61
+ export function placeFactsOf(spec: any): PlaceFact[];
62
+ /**
63
+ * fwd's shape of {@link placeFactsOf}: a place fact lives on a step's `close.cited.facts[]` (the fact part of a green step that quotes an input), not in a
64
+ * bareloop closeDecl stage. Same PlaceFact record (`stage` = the step's index, `part` = 0, `fact` = the fact's index); the key is the step's `emits` and the fact's name.
65
+ * Pure. @param {any[]} steps @returns {PlaceFact[]}
66
+ */
67
+ export function citedPlaceFactsOf(steps: any[]): PlaceFact[];
68
+ /**
69
+ * A copy of the steps with each place fact's phrase replaced by the value the run read (fwd's shape of {@link bindPlaceValues}). The input is never touched, so the
70
+ * signed declaration and its hash stay as signed. A key with no value keeps the signed drafting words. @param {any[]} steps @param {Record<string, string>} values @returns {any[]}
71
+ */
72
+ export function bindCitedPlaceValues(steps: any[], values: Record<string, string>): any[];
73
+ /**
74
+ * A copy of the spec with each place fact's phrase replaced by the value the run read. The input spec is never touched (the signed spec and its hash
75
+ * stay as signed); the copy is for this run's planner and close only. A key with no value is left as the signed drafting words.
76
+ * @param {any} spec @param {Record<string, string>} values place-fact key to the value read @returns {any}
77
+ */
78
+ export function bindPlaceValues(spec: any, values: Record<string, string>): any;
79
+ /**
80
+ * The value the drafting words themselves hold for this rule: the first version for headingBetween, the first ISO date for headingDateAfter. Null when
81
+ * the words hold none. Used as "last read" when no earlier run has one.
82
+ * @param {PlaceRule} rule @param {string} words @returns {string|null}
83
+ */
84
+ export function valueInWords(rule: PlaceRule, words: string): string | null;
85
+ /**
86
+ * Re-read EVERY place fact against the run's own input text, one by one, before any spend. A row is same / new / notfound. Any notfound stops the run;
87
+ * otherwise the run proceeds with the new words.
88
+ * @param {{fact: PlaceFact, text: string|null, was: string|null}[]} items `text` null = the input could not be read
89
+ * @returns {{proceed: boolean, rows: {key: string, name: string, kind: string, found: boolean, value: string|null, was: string|null, reason: string|null}[], values: Record<string, string>}}
90
+ */
91
+ export function readPlaceRules(items: {
92
+ fact: PlaceFact;
93
+ text: string | null;
94
+ was: string | null;
95
+ }[]): {
96
+ proceed: boolean;
97
+ rows: {
98
+ key: string;
99
+ name: string;
100
+ kind: string;
101
+ found: boolean;
102
+ value: string | null;
103
+ was: string | null;
104
+ reason: string | null;
105
+ }[];
106
+ values: Record<string, string>;
107
+ };
108
+ /**
109
+ * The words of the $0 stop, plain words from code. Every rule is listed, found or not: "<name>: found <value>" (with "(was <last>)" when the value is
110
+ * new) or "<name>: not found (<plain reason>)", then the closing line. The reasons come only from the closed list.
111
+ * @param {{name: string, found: boolean, value: string|null, was: string|null, reason: string|null}[]} rows @returns {string}
112
+ */
113
+ export function stopWords(rows: {
114
+ name: string;
115
+ found: boolean;
116
+ value: string | null;
117
+ was: string | null;
118
+ reason: string | null;
119
+ }[]): string;
120
+ /**
121
+ * The values of the LAST `place-rules` record in a run's own events (key to value): what a RESUME of that run rebinds, since a resume does not re-read. Null when
122
+ * there is no record, or any of its rows was not found.
123
+ * @param {any[]} events @returns {Record<string, string>|null}
124
+ */
125
+ export function placeValuesOfEvents(events: any[]): Record<string, string> | null;
126
+ /**
127
+ * What the newest EARLIER run of the same workflow read, per fact key: "last read". `rows` are the run list's rows (file order, oldest first). Candidates are
128
+ * the rows of the same job, newest first, at most {@link LAST_READ_LOOK} of them; the first whose spine holds a `place-rules` record of the same workflow key
129
+ * answers. An unreadable spine is skipped. Empty when there is none (the caller falls back to the drafting words).
130
+ * @param {{rows: {runid: string, job: string, spine: string}[], job: string, workflowKey: string, runid: string}} o @returns {Record<string, string>}
131
+ */
132
+ export function lastPlaceRead({ rows, job, workflowKey, runid }: {
133
+ rows: {
134
+ runid: string;
135
+ job: string;
136
+ spine: string;
137
+ }[];
138
+ job: string;
139
+ workflowKey: string;
140
+ runid: string;
141
+ }): Record<string, string>;
142
+ /**
143
+ * fwd's "last read" (bareloop's lastPlaceRead reads spines; fwd has none): per fact key, the value the newest EARLIER run of the same flow recorded in its run.json
144
+ * `placeRules` (runs are `run-<n>`; at most {@link LAST_READ_LOOK} earlier runs are looked at; a run with no record, or an unreadable one, is skipped). Empty when none.
145
+ * @param {{flowDir: string, runId: string}} o @returns {Record<string, string>}
146
+ */
147
+ export function lastRunPlaceRead({ flowDir, runId }: {
148
+ flowDir: string;
149
+ runId: string;
150
+ }): Record<string, string>;
151
+ /** the two rule kinds on the menu: the version in a heading, and the date on the same heading line */
152
+ export const PLACE_KINDS: readonly string[];
153
+ /** the end-of-line end mark */
154
+ export const EOL: "$EOL";
155
+ /** the field a place rule may carry */
156
+ export const PLACE_FIELDS: readonly string[];
157
+ /** the closed list of reasons a read can end not found */
158
+ export const PLACE_REASONS: readonly string[];
159
+ /** plain words for each reason, from code (the person never reads a raw code) */
160
+ export const PLAIN_REASONS: Readonly<{
161
+ 'mixed-levels': "the file writes its version headings at more than one level";
162
+ 'no-heading-line': "the file has no heading at the level the rule reads";
163
+ 'first-heading-mismatch': "the newest heading does not start the way the rule says";
164
+ 'end-mark-missing': "the newest heading does not have the mark the rule reads up to";
165
+ 'capture-not-shape': "the newest heading does not carry a version number";
166
+ 'only-skipped-headings': "the file has only an Unreleased heading and no release after it";
167
+ 'no-date-on-line': "the newest heading line carries no date";
168
+ 'no-file': "the input could not be read";
169
+ 'empty-text': "the input is empty";
170
+ }>;
171
+ /** the frozen candidate list: 9 prefixes crossed with 3 ends, prefix-major (27) */
172
+ export const PLACE_CANDIDATES: readonly Readonly<{
173
+ prefix: string;
174
+ end: string;
175
+ }>[];
176
+ /** the end of the stop words: what the person can do, and that nothing ran or was spent */
177
+ export const STOP_TAIL: "Reuse workflow and adjust the rules, or check the input. The run did not start. Nothing spent.";
178
+ /** the plain words of the door's refusal when a place-rule run has no record of the values it read */
179
+ export const NO_PLACE_RECORD_WORDS: "This run has no record of the values it read, so it cannot be checked again. Use Reuse workflow.";
180
+ /** the spine event a run writes, once, after job-start */
181
+ export const PLACE_EVENT: "place-rules";
182
+ /** how many earlier runs of the job are looked at for "last read" */
183
+ export const LAST_READ_LOOK: 25;
184
+ export type PlaceRule = {
185
+ kind: "headingBetween" | "headingDateAfter";
186
+ prefix: string;
187
+ end: string;
188
+ shape: string;
189
+ skip: string[];
190
+ };
191
+ export type PlaceRead = {
192
+ found: true;
193
+ value: string;
194
+ lineIndex: number;
195
+ } | {
196
+ found: false;
197
+ reason: string;
198
+ };
199
+ export type PlaceFact = {
200
+ key: string;
201
+ name: string;
202
+ source: string;
203
+ stage: number;
204
+ part: number;
205
+ fact: number;
206
+ place: PlaceRule;
207
+ phrase: string;
208
+ };
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Rebuild the block of a saved plan at $0. `choices` = the Drop/Add choices the plan was made with (its record's `rowChoices`).
3
+ * @param {{planDir: string, asks: boolean}} o
4
+ * @returns {{ok: true, block: import('./checkblock.js').CheckBlock, declaration: any, lines: any[], lineSet: Set<number>, parsed: any, texts: Record<string, string>, look: {facts: any[], dropped: any[]}, record: any, log: any, proseText: string}|{ok: false, say: string}}
5
+ */
6
+ export function rebuildBlock({ planDir, asks }: {
7
+ planDir: string;
8
+ asks: boolean;
9
+ }): {
10
+ ok: true;
11
+ block: import("./checkblock.js").CheckBlock;
12
+ declaration: any;
13
+ lines: any[];
14
+ lineSet: Set<number>;
15
+ parsed: any;
16
+ texts: Record<string, string>;
17
+ look: {
18
+ facts: any[];
19
+ dropped: any[];
20
+ };
21
+ record: any;
22
+ log: any;
23
+ proseText: string;
24
+ } | {
25
+ ok: false;
26
+ say: string;
27
+ };
28
+ /**
29
+ * Drop or Add a row of a saved plan, at $0. Returns the files of the NEW plan folder (the caller writes them once); the old plan is never touched.
30
+ * @param {{planDir: string, op: 'drop'|'add', key: string, asks?: boolean}} o
31
+ * @returns {{ok: true, files: Record<string, string>, pages: Record<string, string>, logRow: Record<string, any>, hash: string}|{ok: false, say: string, refused?: string}}
32
+ */
33
+ export function rowEditPlan({ planDir, op, key, asks }: {
34
+ planDir: string;
35
+ op: "drop" | "add";
36
+ key: string;
37
+ asks?: boolean;
38
+ }): {
39
+ ok: true;
40
+ files: Record<string, string>;
41
+ pages: Record<string, string>;
42
+ logRow: Record<string, any>;
43
+ hash: string;
44
+ } | {
45
+ ok: false;
46
+ say: string;
47
+ refused?: string;
48
+ };
49
+ /** what a person is told when the saved inputs no longer give the saved list: nothing is written */
50
+ export const REBUILD_CHANGED_SAY: "The inputs of this plan have changed since it was drafted, so its checks cannot be changed here. Draft again from the card. Nothing was changed.";
51
+ /** a plan that has no list (drafted before M16) */
52
+ export const NO_LIST_SAY: "This plan has no list of checks to change. Nothing was changed.";
@@ -138,7 +138,7 @@ export function ceilingCostUsd(rates: {
138
138
  * (the one that matters — the signed hash records the request, not what
139
139
  * ran); `unreported` the provider told us nothing.
140
140
  */
141
- export function classifyModelId(requested: any, returned: any): "unreported" | "match" | "prefix" | "substituted";
141
+ export function classifyModelId(requested: any, returned: any): "prefix" | "unreported" | "match" | "substituted";
142
142
  /**
143
143
  * Sum every round of one model attempt into one meter. Money honesty in the
144
144
  * strict direction: if ANY round has no priced cost, `costUsd` is `null` —
@@ -0,0 +1,48 @@
1
+ /**
2
+ * The facts a person-facing turn must not ask about (R5 finding F285): the confirm turn asked "which ticket, and is it P1?" in 5 of 10 live drafts. ONE owner of these words;
3
+ * the confirm prompt and the drafting prompt both carry them, for a Tickets job only.
4
+ * @returns {string}
5
+ */
6
+ export function ticketPerRunFacts(): string;
7
+ /**
8
+ * What the drafter is told when the job reads tickets (appended to the authoring prompt only then; a plain job's prompt is untouched).
9
+ * Adapted from fwd's `ticketFactsLines` (v0.29.0): the same MUST, the same "never invent a label".
10
+ * @returns {string}
11
+ */
12
+ export function ticketFilterBlock(): string;
13
+ /**
14
+ * The ONE user message: the person's job lines (their `~` rules numbered), the look, the inputs (bounded).
15
+ * @param {{jobLines: any[], look: any, texts: Record<string, string>}} o
16
+ * @returns {string}
17
+ */
18
+ export function rowEditUserText({ jobLines, look, texts }: {
19
+ jobLines: any[];
20
+ look: any;
21
+ texts: Record<string, string>;
22
+ }): string;
23
+ export const TICKET_FILTER_SCHEMA_WORDS: "REQUIRED when a job line names a priority or a label (leave it out only when none does). The person signs it; code decides at run start. Listing the line under \"refused\" does not filter anything: only this key does";
24
+ /** a legal filter, as the drafter is shown it */
25
+ export const TICKET_FILTER_EXAMPLE: "{\"priority\": [\"P1\"], \"labels\": [\"bug\"]}";
26
+ export const TICKET_READ_FACT: "A step that reads the ticket input still lists \"read\" in its tools: the ticket is already frozen at run start, but reading it is a grant, so a step without \"read\" cannot see it.";
27
+ /** the tool a row-edit reply is delivered through */
28
+ export const ROW_EDIT_TOOL: "submit_edits";
29
+ /** what an acknowledged reply returns (the loop ends the call the moment the tool fires) */
30
+ export const ROW_EDIT_ACK: "edits received";
31
+ /** the drafter's system text for the row-edit turn (a prompt register: src/promptregisters.js) */
32
+ export const ROW_EDIT_SYSTEM: string;
33
+ /** the fixed sentence that follows the refusals in a revise turn (the turn carries each refusal's own reason and nothing else) */
34
+ export const ROW_EDIT_REVISE: "Send corrected edits only (an empty \"edits\" list is a good answer).";
35
+ export function rowEditChannel(ticket?: boolean, sheetChecks?: Record<string, any> | null): {
36
+ name: string;
37
+ instruction: string;
38
+ textPath: string;
39
+ tool: (box: {
40
+ calls: any[];
41
+ }) => {
42
+ name: string;
43
+ description: string;
44
+ parameters: Record<string, any>;
45
+ execute: (args: any) => Promise<string>;
46
+ };
47
+ };
48
+ export function editsOf(artifact: any): any[];
@@ -0,0 +1,63 @@
1
+ /**
2
+ * The SHAPE of a `rubric-step` stage's parameters — what a part may carry — and nothing about which class is allowed in
3
+ * this build (that is `checkRubricParts`, which also sees the whole job). Pure, never throws.
4
+ * @param {unknown} p the stage's `params`
5
+ * @param {string} at the path prefix for reds, e.g. `stages[1].params`
6
+ * @returns {ShapeRed[]}
7
+ */
8
+ export function rubricStepShapeReds(p: unknown, at: string): ShapeRed[];
9
+ /**
10
+ * Does this rule text hold more than one amount (money) or more than one time range (time)? The ONE guard code's own limit read and an AI
11
+ * reading edit both use: "under $450 or over $900" is two limits, and one reading of it would be a wrong check.
12
+ * @param {string} shape @param {string} text @returns {boolean}
13
+ */
14
+ export function holdsManyBounds(shape: string, text: string): boolean;
15
+ /**
16
+ * The limit the person's own words give a fact of this shape: `{reading}` or `{why}` (a plain reason; the rule then stays Not checked).
17
+ * @param {string} shape money or time @param {string} text the `~` rule's words @param {any} [fact] the look fact (its currency and unit lists must fit)
18
+ * @returns {{reading: {op: 'lt'|'lte'|'gt'|'gte', value: number} | {op: 'between', lo: number|string, hi: number|string}} | {why: string}}
19
+ */
20
+ export function readLimit(shape: string, text: string, fact?: any): {
21
+ reading: {
22
+ op: "lt" | "lte" | "gt" | "gte";
23
+ value: number;
24
+ } | {
25
+ op: "between";
26
+ lo: number | string;
27
+ hi: number | string;
28
+ };
29
+ } | {
30
+ why: string;
31
+ };
32
+ /**
33
+ * The sign-time check of a close that carries the one check list: every BUILT row (the mechanical floor aside) points at a part that is really in the close, and every real check part
34
+ * (countable or fact) has at least one built row pointing at it, so a check cannot be in the close with no row and a row cannot claim a check the close does not run. A close with no list is
35
+ * not examined here. Pure.
36
+ * @param {any} closeDecl @returns {{ok: true}|{ok: false, error: string}}
37
+ */
38
+ export function listMatchesClose(closeDecl: any): {
39
+ ok: true;
40
+ } | {
41
+ ok: false;
42
+ error: string;
43
+ };
44
+ /** the closed set of classes a part is sorted into; `none` = "I could not sort this one" (a red, in plain words, never a guess) */
45
+ export const PART_CLASSES: readonly string[];
46
+ /**
47
+ * The counted/quoted checks a `countable` part may name, with the fields each needs — read off bareguard's own rule table
48
+ * (`rubricVocabulary`): the names are bareguard's, so a check this build cannot run is inexpressible, not rejected late.
49
+ * (`max`/`min` need a numeric field the step file does not have, so they are not offered.)
50
+ * @type {Readonly<Record<string, readonly string[]>>}
51
+ */
52
+ export const COUNT_CHECKS: Readonly<Record<string, readonly string[]>>;
53
+ export function boundInWords(b: unknown, said: string): boolean;
54
+ export const NEGATING_RE: RegExp;
55
+ /** the plain reason a rule's amount is in a currency the page fact does not use; `readLimit` gives it and the check list reads it, one spelling */
56
+ export const WHY_OTHER_CURRENCY: "the amount is in another currency than the page fact";
57
+ export function defaultCitedText(label: string): string;
58
+ export function defaultNoteText(n: number): string;
59
+ export type ShapeRed = {
60
+ code: string;
61
+ path: string;
62
+ detail: string;
63
+ };
@@ -33,9 +33,9 @@ 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[], rerun?: {decision: 'rerun', words: string, afterStep: string|null}|null }} 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, placeRules?: {rows: any[]}|null }} start
37
37
  */
38
- export function writeRunStart(runDir: string, { model, thinking, inputs, rerun }: {
38
+ export function writeRunStart(runDir: string, { model, thinking, inputs, rerun, placeRules }: {
39
39
  model: {
40
40
  slot: string;
41
41
  model: string;
@@ -47,6 +47,9 @@ export function writeRunStart(runDir: string, { model, thinking, inputs, rerun }
47
47
  words: string;
48
48
  afterStep: string | null;
49
49
  } | null;
50
+ placeRules?: {
51
+ rows: any[];
52
+ } | null;
50
53
  }): void;
51
54
  /** the file's name in the run's folder */
52
55
  export const RUN_FILE: "run.json";
package/types/runner.d.ts CHANGED
@@ -151,6 +151,48 @@ export function freezeInputs(runDir: string, sources: Array<{
151
151
  skip: string | null;
152
152
  red?: undefined;
153
153
  }>;
154
+ /**
155
+ * M16 item 1: read every place-rule fact of the job's steps from the run's OWN frozen copy of its input, by code, before any provider call. `{ok:false, words}` = a rule
156
+ * was not found (bareloop's stop words); `{ok:true, rows, values}` = the rows to record in run.json and the key-to-value map to bind in memory. No place fact = nothing read.
157
+ * @param {string} runDir @param {any[]} steps @param {any[]} manifest freezeInputs' manifest @param {Record<string, string>} [earlier] key to the value the newest earlier run read ("was")
158
+ */
159
+ export function readRunPlaceRules(runDir: string, steps: any[], manifest: any[], earlier?: Record<string, string>): {
160
+ ok: true;
161
+ rows: null;
162
+ values: {};
163
+ words?: undefined;
164
+ } | {
165
+ ok: false;
166
+ words: string;
167
+ rows?: undefined;
168
+ values?: undefined;
169
+ } | {
170
+ ok: true;
171
+ rows: {
172
+ key: string;
173
+ kind: string;
174
+ found: boolean;
175
+ value: string | null;
176
+ was: string | null;
177
+ reason: string | null;
178
+ }[];
179
+ values: Record<string, string>;
180
+ words?: undefined;
181
+ };
182
+ /**
183
+ * M16 item 1: the steps a RESUMED / continued run carries on with: the signed steps, each place fact's phrase set to the value its own run.json recorded at the start.
184
+ * A job with no place fact returns its steps as they are; a run whose record is missing or has a rule not found is `{ok:false, words: NO_PLACE_RECORD_WORDS}`.
185
+ * @param {string} runDir @param {any[]} steps
186
+ */
187
+ export function stepsWithRecordedPlaces(runDir: string, steps: any[]): {
188
+ ok: true;
189
+ steps: any[];
190
+ words?: undefined;
191
+ } | {
192
+ ok: false;
193
+ words: string;
194
+ steps?: undefined;
195
+ };
154
196
  /**
155
197
  * 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
198
  * ticket mark, so the rerun reads the ticket through the job's MCP tools and the signed filter, not as a web page.
@@ -573,10 +615,11 @@ import { readTicketMcp } from './ticket-mcp.js';
573
615
  * @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
616
  * @param {number} [opts.triesDone] - tries a Stop already closed on this step (they count against its limit)
575
617
  * @param {string|null} [opts.runDir] - M4d am29 item 2: the run's folder, where each try saves its checks
618
+ * @param {any[]} [opts.checkList] - M16 item 5: the plan's signed list; a list line's checks carry the row's `by`
576
619
  * @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
620
  * @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
621
  */
579
- declare function runStepTries({ step, primitivesMap, readsMap, businessDate, modelStep, spent, capUsd, ceilingUsd, recordAudit, initialGap, attemptOffset, thinkingBox, learnHints, now, readStop, stepNo, triesDone, runDir, prevStepId, mcpGranted, }: {
622
+ declare function runStepTries({ step, primitivesMap, readsMap, businessDate, modelStep, spent, capUsd, ceilingUsd, recordAudit, initialGap, attemptOffset, thinkingBox, learnHints, now, readStop, stepNo, triesDone, runDir, prevStepId, mcpGranted, checkList, }: {
580
623
  step: any;
581
624
  primitivesMap?: Record<string, any> | undefined;
582
625
  readsMap: Record<string, any>;
@@ -605,6 +648,7 @@ declare function runStepTries({ step, primitivesMap, readsMap, businessDate, mod
605
648
  prevStepId?: string | null | undefined;
606
649
  triesDone?: number | undefined;
607
650
  runDir?: string | null | undefined;
651
+ checkList?: any[] | undefined;
608
652
  mcpGranted?: Record<string, any> | undefined;
609
653
  }): Promise<{
610
654
  ok: true;
@@ -12,7 +12,7 @@ export function sheetFoundWords(check: any, claims: unknown): string | null;
12
12
  * older `close.columns` / `close.cited` check (then every guardrail is Not checked).
13
13
  * @param {{declaration: any, lines: Array<{n: number, rules?: string[], guardrail?: string, rule?: string}>, csvRoles?: string[], record?: any}} o
14
14
  * `record` = the `sheet` section of `line-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'}>}
15
+ * @returns {Array<{line: number, codeBuilt: boolean, guardrails: string[], checked: Array<{id: string, name: string, words: string, covers: string[], coversWords: string, by: 'you'|'agent', text: string, ok?: boolean, found?: string}>, notChecked: string[]|'none'}>}
16
16
  */
17
17
  export function sheetLineBlocks({ declaration, lines, csvRoles, record }: {
18
18
  declaration: any;
@@ -26,6 +26,7 @@ export function sheetLineBlocks({ declaration, lines, csvRoles, record }: {
26
26
  record?: any;
27
27
  }): Array<{
28
28
  line: number;
29
+ codeBuilt: boolean;
29
30
  guardrails: string[];
30
31
  checked: Array<{
31
32
  id: string;
@@ -33,6 +34,7 @@ export function sheetLineBlocks({ declaration, lines, csvRoles, record }: {
33
34
  words: string;
34
35
  covers: string[];
35
36
  coversWords: string;
37
+ by: "you" | "agent";
36
38
  text: string;
37
39
  ok?: boolean;
38
40
  found?: string;
@@ -40,16 +42,19 @@ export function sheetLineBlocks({ declaration, lines, csvRoles, record }: {
40
42
  notChecked: string[] | "none";
41
43
  }>;
42
44
  /**
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
45
+ * The guardrail rules of a sheet step that no check covers, as the drafter's Not-checked lines (`line N: "rule" - <reason>`): the block's own
44
46
  * `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[]}
47
+ * M17 am2: `built` (the builder's answer, src/sheetbuild.js) gives the reason a rule is Not checked (the refusal that named it).
48
+ * @param {any} declaration @param {Array<{n: number, rules?: string[], guardrail?: string, rule?: string}>} lines @param {string[]} csvRoles @param {{notChecked: Record<string, string>}} [built] @returns {string[]}
46
49
  */
47
50
  export function uncoveredRules(declaration: any, lines: Array<{
48
51
  n: number;
49
52
  rules?: string[];
50
53
  guardrail?: string;
51
54
  rule?: string;
52
- }>, csvRoles: string[]): string[];
55
+ }>, csvRoles: string[], built?: {
56
+ notChecked: Record<string, string>;
57
+ }): string[];
53
58
  /** @param {any} arbiter @returns {string[]} the roles of the signed sources that are a CSV file (the sheets a check reads) */
54
59
  export function csvRolesOf(arbiter: any): string[];
55
60
  /**
@@ -112,5 +117,8 @@ export const SHEET_OP_NAMES: Readonly<{
112
117
  rowCount: "row count";
113
118
  rowMath: "row math";
114
119
  }>;
120
+ export function isCodeBuiltId(id: unknown): boolean;
121
+ export function sheetByCheck(c: any, rules: string[]): "agent" | "you";
115
122
  export function rulesOfLine(l: any): string[];
123
+ export function sheetPlainText(name: string, words: string, cw: string): string;
116
124
  export function coversWords(rules: string[]): string;
@@ -0,0 +1,84 @@
1
+ /**
2
+ * @param {any} ai a suggestion as the AI sent it @returns {{covers: number[], fields: Record<string, any>}}
3
+ */
4
+ export function toSuggestion(ai: any): {
5
+ covers: number[];
6
+ fields: Record<string, any>;
7
+ };
8
+ /**
9
+ * @typedef {{check: any, covers: number[]}} Placed
10
+ * @typedef {{rule: number, text: string, state: 'built'|'column'|'agent-row'|'not-checked', reason: string|null, id: string|null}} RuleState
11
+ * @param {{line: {n: number, text?: string, rules?: string[], guardrail?: string, rule?: string}, tables: Record<string, {header: string[], rows: any[]}>, suggestions: any[]}} o
12
+ * @returns {Promise<{rows: RuleState[], ruleRows: Placed[], agentRows: Placed[], checks: any[], refused: {helper: string, why: string}[]}>}
13
+ */
14
+ export function buildSheetLine({ line, tables, suggestions }: {
15
+ line: {
16
+ n: number;
17
+ text?: string;
18
+ rules?: string[];
19
+ guardrail?: string;
20
+ rule?: string;
21
+ };
22
+ tables: Record<string, {
23
+ header: string[];
24
+ rows: any[];
25
+ }>;
26
+ suggestions: any[];
27
+ }): Promise<{
28
+ rows: RuleState[];
29
+ ruleRows: Placed[];
30
+ agentRows: Placed[];
31
+ checks: any[];
32
+ refused: {
33
+ helper: string;
34
+ why: string;
35
+ }[];
36
+ }>;
37
+ /**
38
+ * The declaration with every green sheet step's `close.sheet` REWRITTEN by code from what the AI suggested there (`buildSheetLine`). A step with no suggestion is left alone; a step none of whose
39
+ * suggestions can be built loses `close.sheet` (its rules are Not checked with their reasons). Pure over the declaration it is given (a copy is returned).
40
+ * @param {{declaration: any, lines: {n: number, text?: string, rules?: string[], guardrail?: string, rule?: string}[], tables: Record<string, {header: string[], rows: any[]}>}} o
41
+ * @returns {Promise<{declaration: any, notChecked: Record<string, string>, refused: {line: number, helper: string, why: string}[], unbuilt: {line: number, lost: string[]}[]}>} `unbuilt`: the green sheet steps left with no check, each with its rules as Not-checked lines. `notChecked`: `line N: "rule"` -> the refusal that named it (or `NO_SUGGESTION`), for each rule of a
42
+ * rewritten line that no check holds
43
+ */
44
+ export function buildSheetChecks({ declaration, lines, tables }: {
45
+ declaration: any;
46
+ lines: {
47
+ n: number;
48
+ text?: string;
49
+ rules?: string[];
50
+ guardrail?: string;
51
+ rule?: string;
52
+ }[];
53
+ tables: Record<string, {
54
+ header: string[];
55
+ rows: any[];
56
+ }>;
57
+ }): Promise<{
58
+ declaration: any;
59
+ notChecked: Record<string, string>;
60
+ refused: {
61
+ line: number;
62
+ helper: string;
63
+ why: string;
64
+ }[];
65
+ unbuilt: {
66
+ line: number;
67
+ lost: string[];
68
+ }[];
69
+ }>;
70
+ /** the fields of a suggestion code does not read: it names every check itself */
71
+ export const SUGGESTION_DROPPED: readonly string[];
72
+ /** M17 am7 item 2: the words of a rule no check holds and nothing refused: the one no-pick sentence (src/ticketrows.js), not a third copy */
73
+ export const NO_SUGGESTION: "No check was picked for it, so you judge it at the Ask.";
74
+ export type Placed = {
75
+ check: any;
76
+ covers: number[];
77
+ };
78
+ export type RuleState = {
79
+ rule: number;
80
+ text: string;
81
+ state: "built" | "column" | "agent-row" | "not-checked";
82
+ reason: string | null;
83
+ id: string | null;
84
+ };