fwdloop 0.21.0 → 0.23.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 (104) hide show
  1. package/bin/fwdloop +85 -34
  2. package/package.json +4 -3
  3. package/src/ask.js +20 -4
  4. package/src/audit-fold.js +5 -1
  5. package/src/authoring.js +36 -6
  6. package/src/canrun.js +5 -0
  7. package/src/checked.js +32 -4
  8. package/src/cited-record.js +138 -0
  9. package/src/cited-source.js +49 -0
  10. package/src/citedcheck.js +321 -0
  11. package/src/citedwords.js +197 -0
  12. package/src/closers.js +37 -198
  13. package/src/csv.js +69 -12
  14. package/src/ctx-tools.js +2 -14
  15. package/src/declaration.js +143 -5
  16. package/src/diary.js +2 -2
  17. package/src/docx.js +16 -2
  18. package/src/draft-steps.js +1 -1
  19. package/src/drafter.js +322 -33
  20. package/src/flow.js +33 -7
  21. package/src/flowmodel.js +21 -0
  22. package/src/input-facts.js +20 -3
  23. package/src/model-step.js +38 -21
  24. package/src/pageask.js +136 -0
  25. package/src/pagebits.js +107 -0
  26. package/src/pagedropwords.js +171 -0
  27. package/src/pagedry.js +120 -0
  28. package/src/pagefetch.js +164 -0
  29. package/src/pagelook.js +155 -0
  30. package/src/pagemap.js +55 -0
  31. package/src/pageplace.js +103 -0
  32. package/src/pagerules.js +318 -0
  33. package/src/panel/author.js +43 -21
  34. package/src/panel/authorcard.js +20 -3
  35. package/src/panel/authorflows.js +21 -15
  36. package/src/panel/authorstart.js +2 -4
  37. package/src/panel/authortrigger.js +14 -4
  38. package/src/panel/data.js +102 -6
  39. package/src/panel/index.html +321 -12
  40. package/src/panel/result.js +301 -0
  41. package/src/panel/server.js +27 -3
  42. package/src/primitives.js +2 -3
  43. package/src/provider.js +5 -2
  44. package/src/redact.js +17 -0
  45. package/src/runner.js +102 -14
  46. package/src/schedule.js +3 -3
  47. package/src/setup.js +16 -1
  48. package/src/sheet-record.js +57 -0
  49. package/src/sheetblock.js +170 -0
  50. package/src/sheetchecks.js +206 -0
  51. package/src/sheetclaims.js +78 -0
  52. package/src/sheetfind.js +50 -0
  53. package/src/sheetlook.js +157 -0
  54. package/src/sheetoffer.js +125 -0
  55. package/src/sheetrun.js +105 -0
  56. package/src/signed-text.js +11 -1
  57. package/src/thinking.js +1 -1
  58. package/src/try-checks.js +12 -0
  59. package/src/types.js +4 -11
  60. package/types/ask.d.ts +2 -1
  61. package/types/authoring.d.ts +19 -2
  62. package/types/checked.d.ts +19 -3
  63. package/types/cited-record.d.ts +21 -0
  64. package/types/cited-source.d.ts +18 -0
  65. package/types/citedcheck.d.ts +95 -0
  66. package/types/citedwords.d.ts +97 -0
  67. package/types/closers.d.ts +37 -10
  68. package/types/csv.d.ts +25 -4
  69. package/types/ctx-tools.d.ts +0 -1
  70. package/types/declaration.d.ts +20 -1
  71. package/types/docx.d.ts +14 -0
  72. package/types/drafter.d.ts +264 -8
  73. package/types/flow.d.ts +21 -0
  74. package/types/flowmodel.d.ts +15 -0
  75. package/types/input-facts.d.ts +12 -2
  76. package/types/model-step.d.ts +40 -19
  77. package/types/pageask.d.ts +75 -0
  78. package/types/pagebits.d.ts +32 -0
  79. package/types/pagedropwords.d.ts +40 -0
  80. package/types/pagedry.d.ts +38 -0
  81. package/types/pagefetch.d.ts +86 -0
  82. package/types/pagelook.d.ts +75 -0
  83. package/types/pagemap.d.ts +31 -0
  84. package/types/pageplace.d.ts +22 -0
  85. package/types/pagerules.d.ts +86 -0
  86. package/types/panel/authorcard.d.ts +4 -1
  87. package/types/panel/authorflows.d.ts +2 -0
  88. package/types/panel/data.d.ts +26 -0
  89. package/types/panel/result.d.ts +156 -0
  90. package/types/provider.d.ts +3 -1
  91. package/types/redact.d.ts +1 -0
  92. package/types/runner.d.ts +162 -9
  93. package/types/schedule.d.ts +0 -11
  94. package/types/setup.d.ts +13 -0
  95. package/types/sheet-record.d.ts +24 -0
  96. package/types/sheetblock.d.ts +116 -0
  97. package/types/sheetchecks.d.ts +70 -0
  98. package/types/sheetclaims.d.ts +26 -0
  99. package/types/sheetfind.d.ts +46 -0
  100. package/types/sheetlook.d.ts +120 -0
  101. package/types/sheetoffer.d.ts +25 -0
  102. package/types/sheetrun.d.ts +35 -0
  103. package/types/thinking.d.ts +1 -1
  104. package/types/types.d.ts +27 -14
@@ -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
+ };
@@ -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;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * The tool schema of `close.sheet`: a list of bareguard cells / table checks. Every field is a field of bareguard's vocabulary; every column-bearing field
3
+ * (`column keyColumn groupColumn result a b from to cell where[].column dateFormats[].column`) is an enum of the sheet's exact header. `covers` is fwdloop's own field
4
+ * (which `~` rules of the job line the check covers), kept and signed.
5
+ * @param {Record<string, {header: string[]}>} tables the drafting copy's table of each CSV input role
6
+ * @returns {Record<string, any>|null} null when there is no sheet with a header to pick from
7
+ */
8
+ export function sheetChecksProp(tables: Record<string, {
9
+ header: string[];
10
+ }>): Record<string, any> | null;
11
+ /**
12
+ * Every op of the cells and table rules with its summary, what it requires and allows, its claim shape and bareguard's worked example check. Generated from the
13
+ * vocabulary; a new op bareguard adds shows up here by itself.
14
+ * @returns {string[]} lines for the system prompt
15
+ */
16
+ export function sheetOpsBrief(): string[];
17
+ /**
18
+ * The rules the validator enforces on `close.sheet`, as lines for the drafter (every one of them is a refusal at $0 in src/declaration.js / src/sheetchecks.js).
19
+ * @param {string[]} roles the CSV input roles @returns {string[]}
20
+ */
21
+ export function sheetOfferRules(roles: string[]): string[];
22
+ /** @param {unknown} rule @returns {boolean} true for the `use the column 'X' for 'Y'` rule an agreed column ask writes ({@link columnRuleWords}) */
23
+ export function isColumnChoiceRule(rule: unknown): boolean;
24
+ /** The comparisons of a `where` condition. bareguard publishes them only inside the `where` description (no list), so this is the one copy; a test proves each is named there. */
25
+ export const WHERE_CMPS: readonly string[];
@@ -0,0 +1,35 @@
1
+ /** The sheet inputs any step's `close.sheet` reads, once each, in order. @param {any[]} steps @returns {string[]} */
2
+ export function sheetRolesOf(steps: any[]): string[];
3
+ /**
4
+ * bareguard's `tableSha` of the run's frozen CSV `<runDir>/inputs/<name>` (its table from src/csv.js `sheetTable`), read through the one safe gateway; null when the copy
5
+ * cannot be read or bareguard cannot read it as a table (a ragged row, a repeated header).
6
+ * @param {string} runDir @param {string} name the frozen file's name @returns {string|null}
7
+ */
8
+ export function tableShaOfFrozen(runDir: string, name: string): string | null;
9
+ /**
10
+ * What a sheet check reads in a run: the run's OWN frozen copy of each sheet its checks name, as bareguard's table, and the `tableSha` recorded in `inputs.json` at
11
+ * the run's start. The table is NOT compared here: bareguard compares it to the recorded sha when it checks (and stops if it differs).
12
+ * @param {string} runDir @param {any[]} checks the step's `close.sheet`
13
+ * @returns {{ok: true, tables: Record<string, {header: string[], rows: any[]}>, inputs: Array<{name: string, sha256: string}>}|{ok: false, red: string}}
14
+ */
15
+ export function readRunSheets(runDir: string, checks: any[]): {
16
+ ok: true;
17
+ tables: Record<string, {
18
+ header: string[];
19
+ rows: any[];
20
+ }>;
21
+ inputs: Array<{
22
+ name: string;
23
+ sha256: string;
24
+ }>;
25
+ } | {
26
+ ok: false;
27
+ red: string;
28
+ };
29
+ /**
30
+ * The close of a green step that reads a sheet. `sheet` = `readRunSheets`' answer. `artifact` is the step's typed answer (its claim boxes). Gaps come from bareguard
31
+ * (`renderGaps`: row numbers and counts, a data problem first); each signed check is also listed with its own pass or fail for the Checked list.
32
+ * @param {any[]} checks the step's `close.sheet` @param {unknown} artifact @param {ReturnType<typeof readRunSheets>|null|undefined} sheet
33
+ * @returns {Promise<import('./types.js').CloseVerdict>}
34
+ */
35
+ export function closeSheet(checks: any[], artifact: unknown, sheet: ReturnType<typeof readRunSheets> | null | undefined): Promise<import("./types.js").CloseVerdict>;
@@ -42,7 +42,7 @@ export function thinkingRuleWords(boxOn: boolean | null): "—" | "always on" |
42
42
  /**
43
43
  * M4d am25 item 1/2: the ONE owner of what thinking a step's model call asks for. Code decides, never the model.
44
44
  * Box ticked (the job's Chat "Thinking on" box, kept with the job): every try 'on'. Box off: the 1st try 'off'; the 2nd and later tries 'on'.
45
- * A step redone after a human Redo is numbered from its redo count (the runner's `attemptOffset`), so it is always a 2nd-or-later try and thinks 'on'.
45
+ * A step redone after a human Redo is numbered after the step's last try (the runner's `attemptOffset`, am30), so it is always a 2nd-or-later try and thinks 'on'.
46
46
  * @param {{boxOn: boolean, attempt: number}} a the runner's 1-based attempt number for this step
47
47
  * @returns {'on'|'off'}
48
48
  */
package/types/types.d.ts CHANGED
@@ -56,11 +56,11 @@ export type SourceSlot = {
56
56
  */
57
57
  role: string;
58
58
  /**
59
- * - only `file:` sources are available before M9.
59
+ * - `file:` (a path) or `page:` (a web address, M10 am3); nothing else is available.
60
60
  */
61
- kind: "file";
61
+ kind: "file" | "page";
62
62
  /**
63
- * - everything after `file:` to end of line, trimmed.
63
+ * - everything after `file:` / `page:` to end of line, trimmed.
64
64
  */
65
65
  path: string;
66
66
  };
@@ -255,17 +255,6 @@ export type ExecutorContext = {
255
255
  reads: Record<string, any>;
256
256
  gap: string | null;
257
257
  };
258
- /**
259
- * A green-class field value: `value` is the number/ISO-date/text claimed;
260
- * `cite` resolves it (src/closers.js's own grammar).
261
- */
262
- export type GreenField = {
263
- value: string | number;
264
- cite: string;
265
- };
266
- export type GreenArtifact = {
267
- fields: Record<string, GreenField>;
268
- };
269
258
  export type SoftgreenArtifact = {
270
259
  text: string;
271
260
  lines?: string[];
@@ -286,6 +275,30 @@ export type CloseVerdict = {
286
275
  ok: boolean;
287
276
  result: string | null;
288
277
  }[] | undefined;
278
+ /**
279
+ * a cited green close (M10 piece 4): the fact part and the check's own answer, for the run's cited-check record
280
+ */
281
+ cited?: {
282
+ part: any;
283
+ check: any;
284
+ results?: unknown;
285
+ } | undefined;
286
+ /**
287
+ * a sheet close (M10b piece 2): what the run's sheet-check record keeps
288
+ */
289
+ sheetRecord?: {
290
+ inputs: Array<{
291
+ name: string;
292
+ sha256: string;
293
+ }>;
294
+ claims: unknown;
295
+ checks: Array<{
296
+ id: string;
297
+ text: string;
298
+ ok: boolean;
299
+ result: string | null;
300
+ }>;
301
+ } | undefined;
289
302
  };
290
303
  /**
291
304
  * One row appended to `runs/<run-id>/audit.jsonl` (M2 scope item 9).