fwdloop 0.36.0 → 0.37.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 (98) hide show
  1. package/README.md +1 -1
  2. package/bin/fwdloop +5 -2
  3. package/package.json +3 -3
  4. package/src/action-stop.js +1 -1
  5. package/src/auditchecks.js +41 -9
  6. package/src/authoring.js +74 -16
  7. package/src/blockasks.js +10 -12
  8. package/src/blockassemble.js +49 -43
  9. package/src/blockdraft.js +4 -2
  10. package/src/blockpick.js +10 -0
  11. package/src/canrun.js +2 -1
  12. package/src/cardlist.js +28 -5
  13. package/src/checkblock.js +610 -64
  14. package/src/checked.js +28 -33
  15. package/src/checklistsign.js +2 -1
  16. package/src/checklook.js +45 -0
  17. package/src/checkrows.js +202 -0
  18. package/src/cited-record.js +2 -2
  19. package/src/citedcheck.js +53 -12
  20. package/src/citedwords.js +7 -4
  21. package/src/closers.js +49 -2
  22. package/src/declaration.js +26 -4
  23. package/src/drafter.js +85 -61
  24. package/src/factwords.js +7 -4
  25. package/src/globprefix.js +26 -0
  26. package/src/model-step.js +22 -4
  27. package/src/pageask.js +0 -3
  28. package/src/pagedropwords.js +3 -11
  29. package/src/pagedry.js +75 -1
  30. package/src/pagefetch.js +11 -6
  31. package/src/pagelook.js +2 -1
  32. package/src/pagerules.js +8 -2
  33. package/src/panel/author.js +9 -3
  34. package/src/panel/data.js +3 -2
  35. package/src/panel/index.html +143 -33
  36. package/src/panel/result.js +34 -1
  37. package/src/pickrecord.js +14 -0
  38. package/src/planrebuild.js +55 -19
  39. package/src/ratelimit.js +117 -0
  40. package/src/report.js +14 -3
  41. package/src/rowresults.js +111 -0
  42. package/src/rubricstep.js +65 -2
  43. package/src/runner.js +38 -5
  44. package/src/shapebuild.js +281 -0
  45. package/src/shapelook.js +91 -0
  46. package/src/shapemenu.js +64 -0
  47. package/src/shaperesult.js +104 -0
  48. package/src/shaperows.js +263 -0
  49. package/src/shapewords.js +140 -0
  50. package/src/sheetbuild.js +41 -29
  51. package/src/sheetclaims.js +1 -1
  52. package/src/sheetrows.js +10 -64
  53. package/src/ticketrows.js +1 -1
  54. package/src/try-checks.js +39 -6
  55. package/src/types.js +1 -0
  56. package/src/whole-job.js +24 -8
  57. package/types/action-stop.d.ts +1 -1
  58. package/types/auditchecks.d.ts +13 -2
  59. package/types/authoring.d.ts +20 -2
  60. package/types/blockasks.d.ts +6 -10
  61. package/types/blockassemble.d.ts +13 -13
  62. package/types/blockdraft.d.ts +3 -2
  63. package/types/blockpick.d.ts +4 -0
  64. package/types/cardlist.d.ts +18 -2
  65. package/types/checkblock.d.ts +278 -28
  66. package/types/checked.d.ts +15 -6
  67. package/types/checklook.d.ts +36 -0
  68. package/types/checkrows.d.ts +119 -0
  69. package/types/citedcheck.d.ts +4 -2
  70. package/types/closers.d.ts +10 -1
  71. package/types/drafter.d.ts +8 -4
  72. package/types/globprefix.d.ts +5 -0
  73. package/types/model-step.d.ts +43 -2
  74. package/types/pageask.d.ts +0 -1
  75. package/types/pagedropwords.d.ts +0 -1
  76. package/types/pagedry.d.ts +27 -0
  77. package/types/pagefetch.d.ts +3 -2
  78. package/types/pagerules.d.ts +4 -0
  79. package/types/panel/result.d.ts +16 -1
  80. package/types/pickrecord.d.ts +10 -0
  81. package/types/ratelimit.d.ts +59 -0
  82. package/types/report.d.ts +2 -1
  83. package/types/rowresults.d.ts +28 -0
  84. package/types/rubricstep.d.ts +21 -0
  85. package/types/runner.d.ts +3 -1
  86. package/types/shapebuild.d.ts +97 -0
  87. package/types/shapelook.d.ts +76 -0
  88. package/types/shapemenu.d.ts +40 -0
  89. package/types/shaperesult.d.ts +40 -0
  90. package/types/shaperows.d.ts +102 -0
  91. package/types/shapewords.d.ts +43 -0
  92. package/types/sheetbuild.d.ts +31 -13
  93. package/types/sheetclaims.d.ts +1 -0
  94. package/types/sheetrows.d.ts +5 -36
  95. package/types/ticketrows.d.ts +1 -1
  96. package/types/try-checks.d.ts +2 -1
  97. package/types/types.d.ts +4 -0
  98. package/types/whole-job.d.ts +20 -4
@@ -22,9 +22,9 @@ export function factDecides(part: any): Record<string, any>[];
22
22
  * a phrase fact contributes its own signed words. A result that is not an object, or has no string quote, still becomes a claim (an empty one) so
23
23
  * bareguard reds it by name rather than the result vanishing.
24
24
  * `asWritten` (bareloop v0.56.0): per result, per fact index, the value as the page writes it, for the claim's words of a date or amount a page form signs.
25
- * @param {any} part @param {unknown} results @param {Record<number, string>[]} [asWritten] @returns {{claim: string, quote: string, values?: Record<string, string>}[]}
25
+ * @param {any} part @param {unknown} results @param {(Record<number, string>|undefined)[]} [asWritten] @returns {{claim: string, quote: string, values?: Record<string, string>}[]}
26
26
  */
27
- export function factClaims(part: any, results: unknown, asWritten?: Record<number, string>[]): {
27
+ export function factClaims(part: any, results: unknown, asWritten?: (Record<number, string> | undefined)[]): {
28
28
  claim: string;
29
29
  quote: string;
30
30
  values?: Record<string, string>;
@@ -114,6 +114,8 @@ export const FACT_SHAPES: readonly string[];
114
114
  /** bareguard signs at most this many decides on one `cited` check */
115
115
  export const MAX_FACTS: 10;
116
116
  export const CITED_ID: "facts";
117
+ export function phraseWordsOf(f: any): string[];
118
+ export function quotedWords(words: string[]): string;
117
119
  export function sha256Text(t: string): string;
118
120
  /** the languages whose month names bareguard 0.27 reads on a `date` fact (its `lang`), each with the name a person reads; absent `lang` = ISO YYYY-MM-DD only */
119
121
  export const FACT_LANGS: Readonly<{
@@ -22,6 +22,14 @@ export function closeCited(part: any, artifact: any, source: {
22
22
  ok: false;
23
23
  red: string;
24
24
  } | null | undefined): Promise<CloseVerdict>;
25
+ /**
26
+ * M19 S5: the list-of-items check of a line's close (`close.itemShape`, the signed shape part {fields, minItems?, maxItems?}; never `close.shape`, which stays the text shape of M10): ONE bareguard `itemShape` check over the
27
+ * answer's `results`. On a facts+shape line (`close.cited` beside it) the check is closed and also lists `quote` and `values`, and the item count stays with the fact part (src/shaperows.js `shapeItemCheck`), so a count fault is
28
+ * told once. A red names the item and the field in the tag's words (src/shapewords.js). Third outcomes, never green: an answer that is not an object (`unparseable`), a shape bareguard cannot build or a check that stopped (`crash`).
29
+ * `shapeGaps` carries bareguard's own gaps (names, counts and bounds, never a value) for the views that mark an item or a field.
30
+ * @param {any} step @param {unknown} artifact @returns {Promise<CloseVerdict>}
31
+ */
32
+ export function closeItemShape(step: any, artifact: unknown): Promise<CloseVerdict>;
25
33
  /**
26
34
  * M4e amendment 18: the soft checks run on bareguard 0.21.0. `softgreenSpec(shape)` is the ONE place a declared shape
27
35
  * becomes a rubric spec (signing and the run both build through `buildSoftgreenRubric`, so a shape that signs is a shape
@@ -85,7 +93,7 @@ export function closeSoftgreen(artifact: any, shape: {
85
93
  /**
86
94
  * The one dispatcher — `close by declared class` (M2 scope item 4).
87
95
  *
88
- * @param {{ close?: { class?: string, shape?: Record<string, any>, picked?: any[], cited?: any, columns?: {source: string, column: string}[], sheet?: any[], numbersFrom?: number[] } }} step
96
+ * @param {{ close?: { class?: string, shape?: Record<string, any>, picked?: any[], cited?: any, itemShape?: any, columns?: {source: string, column: string}[], sheet?: any[], numbersFrom?: number[] } }} step
89
97
  * @param {unknown} artifact
90
98
  * @param {{ reads: Record<string, any>, businessDate: string, source?: {ok: true, text: string, sha256: string}|{ok: false, red: string}|null, sheet?: any, numbers?: {quotes: Record<string, string[]>, missing: number[]} }} ctx
91
99
  * `source` (M10 piece 4) = the run's own frozen copy a cited step reads, from `readRunSource`; only a step whose close carries `cited` reads it
@@ -98,6 +106,7 @@ export function closeByClass(step: {
98
106
  shape?: Record<string, any>;
99
107
  picked?: any[];
100
108
  cited?: any;
109
+ itemShape?: any;
101
110
  columns?: {
102
111
  source: string;
103
112
  column: string;
@@ -311,11 +311,11 @@ export function goalForLine(fromLine: any, lines: any): any;
311
311
  * @returns {Promise<{ok:boolean, declaration:object|null, reds:string[], rounds:number, calls:number, spendComplete:boolean,
312
312
  * costUsd:number|null, modelReturned:string|null, modelId?:string, price?:object|null, tokens?:object|null, structureRetries:number, revisions:number, stop:string|null, log:object[],
313
313
  * questions?:{line:number, question:string}[], proseText?:string, action?:{line:number, by?:'agent'|'you', dropped?:true}|null, droppedQuestions?:object[], notChecked?:string[], thinking?:{asked:string, status:string|null, say:string|null}, inputs?:{role:string, detail:string}[],
314
- * checkCard?:ReturnType<typeof cardOfBlock>, notCheckedBy?:Record<string,'you'|'agent'|'default'>, look?:{facts:any[], dropped:any[]}, pageLooks?:{role:string, address:string, sha256:string, bytes:number, frozen:string, attempts:number, mapping:any}[], sheetLooks?:any[]}>}
314
+ * checkCard?:ReturnType<typeof cardOfPlanBlock>, sheetBuilt?:Awaited<ReturnType<typeof buildSheetChecks>>, notCheckedBy?:Record<string,'you'|'agent'|'default'>, look?:{facts:any[], dropped:any[]}, pageLooks?:{role:string, address:string, sha256:string, bytes:number, frozen:string, attempts:number, mapping:any}[], sheetLooks?:any[]}>}
315
315
  * `learnHints` (M8 item 5a): the earlier runs' notes block (src/learnstore.js hintsForRun), appended to the drafter's system prompt; null = nothing.
316
316
  * `look` / `pageLooks` (M10 item 3) are there when the job signs a web page: the kept facts (with their `reading`, the input a later ask reads), every drop, and per page its address, sha256 and the AI's map. Each drop is also a line in `notChecked`.
317
317
  */
318
- export function draft({ proseText, slot, model, provider: injected, rates: injectedRates, modelId: injectedModelId, env, priorSpend, skills, makeProviderFn, onBook, offerQuestions, draftThinking, draftDir, fetchPage, leftRules, columnAnswers, carriedColumns, onColumns, checkPicks, carriedPicks, carriedChoices, carriedSheetDropped, onSheetDropped, onChoices, onPickRecord, learnHints, mcpServers, flowType, mcp, actionMode, }: {
318
+ export function draft({ proseText, slot, model, provider: injected, rates: injectedRates, modelId: injectedModelId, env, priorSpend, skills, makeProviderFn, onBook, offerQuestions, draftThinking, draftDir, fetchPage, leftRules, columnAnswers, carriedColumns, onColumns, checkPicks, carriedPicks, carriedChoices, carriedSheetDropped, onSheetDropped, carriedShapeDropped, onShapeDropped, onChoices, onPickRecord, learnHints, mcpServers, flowType, mcp, actionMode, }: {
319
319
  proseText: any;
320
320
  slot: any;
321
321
  model: any;
@@ -347,6 +347,8 @@ export function draft({ proseText, slot, model, provider: injected, rates: injec
347
347
  carriedChoices?: any[] | null | undefined;
348
348
  carriedSheetDropped?: any[] | undefined;
349
349
  onSheetDropped?: ((rec: any[]) => void) | undefined;
350
+ carriedShapeDropped?: any[] | undefined;
351
+ onShapeDropped?: ((rec: any[]) => void) | undefined;
350
352
  onChoices?: ((rec: any[]) => void) | undefined;
351
353
  onPickRecord?: ((r: {
352
354
  picks: import("./pickrecord.js").Entry[];
@@ -402,7 +404,8 @@ export function draft({ proseText, slot, model, provider: injected, rates: injec
402
404
  role: string;
403
405
  detail: string;
404
406
  }[];
405
- checkCard?: ReturnType<typeof cardOfBlock>;
407
+ checkCard?: ReturnType<typeof cardOfPlanBlock>;
408
+ sheetBuilt?: Awaited<ReturnType<typeof buildSheetChecks>>;
406
409
  notCheckedBy?: Record<string, "you" | "agent" | "default">;
407
410
  look?: {
408
411
  facts: any[];
@@ -431,4 +434,5 @@ export const MAX_QUESTIONS: 2;
431
434
  /** Try 3 only, and only after tries 1 and 2 both failed validation. No digit and no number word anywhere (a test greps this): the machine, not the prompt, bounds the count. */
432
435
  export const QUESTIONS_PROMPT: string;
433
436
  import { makeProvider } from './provider.js';
434
- import { cardOfBlock } from './cardlist.js';
437
+ import { cardOfPlanBlock } from './cardlist.js';
438
+ import { buildSheetChecks } from './sheetbuild.js';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @param {string} scope
3
+ * @returns {string}
4
+ */
5
+ export function globToPrefix(scope: string): string;
@@ -16,7 +16,7 @@ export function isTransportFailure(err: any): boolean;
16
16
  * `stepClass` is `'green' | 'softgreen' | 'hitl' | null | undefined`; `cited` is true for that green step.
17
17
  */
18
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) @param {boolean} [withText] M10 am22: a fact step with the person's picks also answers in `text` (the picks read it) */
19
- export function buildEmitArtifactSchema(stepClass: string | null | undefined, cited?: boolean, sheet?: any[] | null, withText?: boolean): Readonly<{
19
+ export function buildEmitArtifactSchema(stepClass: string | null | undefined, cited?: boolean, sheet?: any[] | null, withText?: boolean, items?: boolean): Readonly<{
20
20
  type: "object";
21
21
  properties: {
22
22
  done: {
@@ -83,6 +83,45 @@ export function buildEmitArtifactSchema(stepClass: string | null | undefined, ci
83
83
  required: string[];
84
84
  additionalProperties: false;
85
85
  }> | {
86
+ properties: {
87
+ text: {
88
+ type: string;
89
+ };
90
+ done: {
91
+ type: string;
92
+ description: string;
93
+ };
94
+ blocker: {
95
+ type: string[];
96
+ description: string;
97
+ };
98
+ results: {
99
+ type: string;
100
+ items: {
101
+ type: string;
102
+ };
103
+ };
104
+ } | {
105
+ text?: undefined;
106
+ done: {
107
+ type: string;
108
+ description: string;
109
+ };
110
+ blocker: {
111
+ type: string[];
112
+ description: string;
113
+ };
114
+ results: {
115
+ type: string;
116
+ items: {
117
+ type: string;
118
+ };
119
+ };
120
+ };
121
+ required: string[];
122
+ type: "object";
123
+ additionalProperties: false;
124
+ } | {
86
125
  type: string;
87
126
  properties: {
88
127
  done: {
@@ -119,7 +158,7 @@ export function buildEmitArtifactSchema(stepClass: string | null | undefined, ci
119
158
  * @param {{in:number,out:number}} [opts.rates]
120
159
  * @param {string} [opts.modelId]
121
160
  * @param {Record<string,string|undefined>} [opts.env] - the merged shell+keys-file env the key is read from (default process.env).
122
- * @returns {(executorContext:object, grantedTools:Record<string,any>, stepMeta?:{class?:string, attempt?:number, step?:string|null, cited?:any, sheet?:any[]|null, withText?:boolean, picked?:any[]|null, thinkingMode?:'on'|'off'}, seam?:{stopRequested?:() => boolean}) => Promise<any>}
161
+ * @returns {(executorContext:object, grantedTools:Record<string,any>, stepMeta?:{class?:string, attempt?:number, step?:string|null, cited?:any, sheet?:any[]|null, withText?:boolean, itemShape?:any, line?:number|null, picked?:any[]|null, thinkingMode?:'on'|'off'}, seam?:{stopRequested?:() => boolean}) => Promise<any>}
123
162
  */
124
163
  export function makeLiveModelStep({ slot, model, spendPath, provider: injectedProvider, rates: injectedRates, modelId: injectedModelId, env, }: {
125
164
  slot?: string | undefined;
@@ -139,6 +178,8 @@ export function makeLiveModelStep({ slot, model, spendPath, provider: injectedPr
139
178
  cited?: any;
140
179
  sheet?: any[] | null;
141
180
  withText?: boolean;
181
+ itemShape?: any;
182
+ line?: number | null;
142
183
  picked?: any[] | null;
143
184
  thinkingMode?: "on" | "off";
144
185
  }, seam?: {
@@ -71,4 +71,3 @@ export const AGREE_WORDS: string[];
71
71
  export function isAgree(text: unknown): boolean;
72
72
  export function stripAgreeLead(text: string): string;
73
73
  export function readingQuestion(n: number, rule: string, reading: string): string;
74
- export function cantCheckQuestion(n: number, rule: string): string;
@@ -37,5 +37,4 @@ export function splitReadNotes(items: string[] | null | undefined, signed?: stri
37
37
  /** The names of the facts a signed declaration checks (every cited fact of every step). Pure. @param {any} declaration @returns {string[]} */
38
38
  export function signedFactNames(declaration: any): string[];
39
39
  export function leftRuleLine(rule: string): string;
40
- export function pickNoteLine(rule: string, reason: "no-pick" | "own-words"): string;
41
40
  export type Dropped = import("./pagerules.js").Dropped;
@@ -47,5 +47,32 @@ export function dryReadPhrases(text: string, facts: KeptFact[]): Promise<{
47
47
  dropped: Dropped[];
48
48
  reads: Record<string, number>;
49
49
  }>;
50
+ /**
51
+ * The candidate lines of a kept time fact: a LOOSE finder (it only collects). Every page line where a kept label word has a clock time anywhere
52
+ * after it; the value is that line's first time after the label. Whether the run's checker can read it is not decided here.
53
+ * @param {string} text @param {KeptFact} k @returns {{quote: string, value: string}[]}
54
+ */
55
+ export function timeCandidateLines(text: string, k: KeptFact): {
56
+ quote: string;
57
+ value: string;
58
+ }[];
59
+ /**
60
+ * AS SEEN (F337): the planner's example of one result's shape. When a signed fact's label sits on a different line than the result's first line
61
+ * (a hosted flights site: the price line, then `Departure time:` on the next), the worker must copy those lines whole; the planner is the one who can
62
+ * tell it, so the signed record keeps the exact input lines from the drafting copy. Result and label lines are found by the SAME finders the dry
63
+ * reads use (`moneyResultLines`, `timeCandidateLines`), one line at a time, so there is no second reader of "what holds this label". The first
64
+ * result is the first line holding the first labelled fact (money or time); its block runs to the next such line. Every other labelled fact must
65
+ * have its label on the first line or inside the block, else nothing is stored (never a half-example). Lines are the input's own bytes (secret-masked).
66
+ * @param {string} text the drafting copy of the input @param {any[]} facts the signed facts of one part @param {string} input the input's label
67
+ * @returns {{input: string, lines: string[], labels: string[]} | null} null when every label is on the first line, or nothing fits
68
+ */
69
+ export function asSeenOf(text: string, facts: any[], input: string): {
70
+ input: string;
71
+ lines: string[];
72
+ labels: string[];
73
+ } | null;
74
+ /** the longest "as seen" example kept: more lines or characters than this is not a result's few label lines, so nothing is stored */
75
+ export const AS_SEEN_MAX_LINES: 12;
76
+ export const AS_SEEN_MAX_CHARS: 3000;
50
77
  export type KeptFact = import("./pagerules.js").KeptFact;
51
78
  export type Dropped = import("./pagerules.js").Dropped;
@@ -66,9 +66,9 @@ export const MIN_CONTENT_CHARS: 100;
66
66
  export const PAGE_FETCH_TIMEOUT_MS: 90000;
67
67
  /**
68
68
  * @typedef {{goto: (url: string, timeout?: number) => Promise<{url: string, status: number}>, waitForNetworkIdle: (o?: {idle?: number, timeout?: number}) => Promise<void>,
69
- * snapshot: (o?: {mode?: string}) => Promise<string>, close: () => Promise<void>}} FetchPage the part of barebrowse's page handle the fetch uses
69
+ * snapshot: (o?: {mode?: string}) => Promise<string>, close: () => Promise<void>, botBlocked?: boolean}} FetchPage the part of barebrowse's page handle the fetch uses
70
70
  */
71
- /** the oldest barebrowse we accept: 0.21.0 honours CONNECT_OPTIONS (incognito, blockPrivateNetwork; an older one would drop both guards without a word); 0.24.1 tethers Chromium to its launcher, so a killed run or an Abandoned draft leaves no browser behind; 0.26.0 makes goto() resolve to {url, status}, the HTTP status an error page is refused on (M10 am13) */
71
+ /** the oldest barebrowse we accept: 0.21.0 honours CONNECT_OPTIONS (incognito, blockPrivateNetwork; an older one would drop both guards without a word); 0.24.1 tethers Chromium to its launcher, so a killed run or an Abandoned draft leaves no browser behind; 0.26.0 makes goto() resolve to {url, status}, the HTTP status an error page is refused on (M10 am13); 0.30.0 sets page.botBlocked, the flag a bot challenge is refused on (F222) */
72
72
  export const MIN_BAREBROWSE: number[];
73
73
  /**
74
74
  * the part of barebrowse's page handle the fetch uses
@@ -86,4 +86,5 @@ export type FetchPage = {
86
86
  mode?: string;
87
87
  }) => Promise<string>;
88
88
  close: () => Promise<void>;
89
+ botBlocked?: boolean;
89
90
  };
@@ -72,6 +72,10 @@ export type MapFact = {
72
72
  };
73
73
  export type PageMap = {
74
74
  facts: MapFact[];
75
+ cannot?: {
76
+ from?: string;
77
+ why?: string;
78
+ }[];
75
79
  };
76
80
  /**
77
81
  * `words` = what the page proves: the labels of a money/number/time fact, or the alternative phrases of a phrase fact (a place is a phrase)
@@ -61,7 +61,7 @@ export function readDelivered(rec: {
61
61
  buf: null;
62
62
  };
63
63
  /**
64
- * The files this run's signed sends wrote: for each signed send whose send step ended green in the audit, the file `<flow>-<runId>-<emits>.md`
64
+ * The files this run's signed sends wrote: for each signed send whose send step ended green in the audit, the file `<job>-YYYY-MM-DD[-n].md` (`sentName`, M15 am3; older runs: `<flow>-<runId>-<emits>.md`)
65
65
  * in the signed folder with the sha256 the send recorded for it (M15), or, for a send older than M15, `.json` with the sha256 the human's accept recorded for the ask that
66
66
  * send reads (`readAcceptedHashesByEmits`, the same record the send itself checked). No accepted hash = recorded as null, which reads as "changed", never as ok.
67
67
  * @returns {{path: string, dir: string|null, name: string, note: string|null, sha256: string|null}[]}
@@ -81,6 +81,21 @@ export function deliveredOf({ arbiter, declaration, runDir, root, flow, runId, a
81
81
  note: string | null;
82
82
  sha256: string | null;
83
83
  }[];
84
+ /**
85
+ * borrowed-from: bareloop src/panel/server.js@v0.61.0 (`shapeRedsFromRecords`, the gap-line half), adjusted to fwdloop's books: a run records the close's plain gap lines on its audit and log.json attempt rows (never bareguard's per-row record),
86
+ * and a red run's judged answer is the model output of that attempt in log.json. A shape line's answer for the Result tab: the delivered artifact (the step closed green: no item is red) or, for a red run, the step's last red attempt
87
+ * with the item reds read back from its plain gap lines through `shapeItemOfPlain`. Third outcome: nothing readable is `null` (the page says "no saved result to show").
88
+ * @param {{runDir: string, step: any, line: number, logJson: any}} a @returns {{results: any[], reds: string[]}|null}
89
+ */
90
+ export function shapeAnswerOf({ runDir, step, line, logJson }: {
91
+ runDir: string;
92
+ step: any;
93
+ line: number;
94
+ logJson: any;
95
+ }): {
96
+ results: any[];
97
+ reds: string[];
98
+ } | null;
84
99
  /**
85
100
  * The Result tab's JSON for one run (`GET /api/runs/:flow/:runId/result`).
86
101
  * @param {{flow: string, runId: string, runDir: string, root: string, flowRead: any, arbiter: any, historyRow: any, auditRows: any[], logJson: any, notChecked: string[], readNotes?: string[], setupRows?: any[], door?: {askId: string, draftNo: number}|null}} a
@@ -71,6 +71,16 @@ export function readRowChoices(file: string): {
71
71
  tail: string;
72
72
  choice: string;
73
73
  }[] | null;
74
+ /**
75
+ * Shape jobs (clause 4): the shape fields a person dropped from a plan, carried like the sheet's (the block's `shapeDroppedRecord`: `{lineWords, occurrence, name}` or `{lineWords, occurrence, rule}`), so a Revise keeps a Drop of the very same field. A missing or unreadable record is no record.
76
+ * @param {string} file @returns {{lineWords: string, occurrence: number, name?: string, rule?: number}[]|null}
77
+ */
78
+ export function readShapeDropped(file: string): {
79
+ lineWords: string;
80
+ occurrence: number;
81
+ name?: string;
82
+ rule?: number;
83
+ }[] | null;
74
84
  /**
75
85
  * The sheet checks the person dropped from a plan (hamr 2026-11-14: a Revise keeps a sheet Drop), carried like the page-row choices: the record's `sheetDropped` entries, each `{key, line, index, check, text}`;
76
86
  * the next draft drops a new check with the same id again. Read through readFileInside; a missing or unreadable record is no record.
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Is `err` an HTTP 429 (rate-limited) response? True ONLY for an explicit
3
+ * status of 429 on the error itself. Nothing else qualifies — not message
4
+ * text (a message merely containing "429" is not this), not `retryable`,
5
+ * not any other status. Symmetric with `isTransportFailure`'s own status
6
+ * check (src/transport.js), just reading the opposite branch of it.
7
+ * @param {any} err
8
+ * @returns {boolean}
9
+ */
10
+ export function isRateLimited(err: any): boolean;
11
+ /**
12
+ * The vendor's RAW stated wait, in milliseconds, parsed straight from the
13
+ * error message — no default, no margin, no cap. `null` when nothing in the
14
+ * message matches a known shape. Exported separately from `rateLimitWaitMs`
15
+ * so a caller that wants to report the vendor's own number on the spine
16
+ * (`statedMs`) never has to re-derive it from the margin-adjusted figure.
17
+ *
18
+ * bare-agent does not expose the vendor's `retry-after` /
19
+ * `x-ratelimit-reset-*` response headers on the thrown error (BA-26) — the
20
+ * delay exists only in the vendor's English message text, so this parses
21
+ * that text. Verified real shape (a hosted provider, run `8ev2sdkn`, 2026-09-08):
22
+ * "Please try again in 11.996s." This also supports "try again in 1.5
23
+ * seconds", "try again in 20ms", "retry after 30s", and "retry after 30
24
+ * seconds" — case-insensitive.
25
+ * @param {any} err
26
+ * @returns {number|null}
27
+ */
28
+ export function statedWaitMs(err: any): number | null;
29
+ /**
30
+ * How long to wait before retrying a 429, in milliseconds — or `null`
31
+ * meaning "do not retry at all" (either the parsed wait exceeds
32
+ * `RATE_LIMIT_MAX_WAIT_MS`, in which case waiting that long is the
33
+ * operator's decision, not ours).
34
+ *
35
+ * A parsed value gets `PARSED_DELAY_MARGIN_MS` added (the vendor's stated
36
+ * number is the earliest moment its window resets, not a safe one to fire
37
+ * on), capped so the margin itself can never push a parsed value over
38
+ * `RATE_LIMIT_MAX_WAIT_MS`. When nothing parses, `RATE_LIMIT_DEFAULT_WAIT_MS`
39
+ * is returned as-is, with no margin added (there is nothing to add margin
40
+ * to — it is already a conservative guess, not an earliest-moment reading).
41
+ * @param {any} err
42
+ * @returns {number|null}
43
+ */
44
+ export function rateLimitWaitMs(err: any): number | null;
45
+ /** The fixed retry budget: ONE extra attempt after a 429. Never read from a
46
+ * job spec or CLI flag — raising it is arbiter territory, mirroring
47
+ * transport.js's TRANSPORT_RETRIES exactly (tighten-only doctrine). */
48
+ export const RATE_LIMIT_RETRIES: 1;
49
+ /** bare-agent's `Retry.call` (if ever used) counts ATTEMPTS, not retries;
50
+ * this module's own hand-rolled ladder (src/planrun.js) does the same for
51
+ * symmetry with TRANSPORT_MAX_ATTEMPTS. */
52
+ export const RATE_LIMIT_MAX_ATTEMPTS: number;
53
+ /** The hard cap on how long we will ever wait for a vendor-stated 429 delay.
54
+ * A vendor asking for longer than this is not honoured — we do not retry at
55
+ * all in that case. Waiting that long is the operator's decision, not ours
56
+ * (arbiter territory: nothing here escalates the wait past what hamr set). */
57
+ export const RATE_LIMIT_MAX_WAIT_MS: 60000;
58
+ /** Used only when the vendor's message carries no parseable delay at all. */
59
+ export const RATE_LIMIT_DEFAULT_WAIT_MS: 5000;
package/types/report.d.ts CHANGED
@@ -10,7 +10,7 @@ export function runNumberOf(runId: string): number | null;
10
10
  /**
11
11
  * The body: every line before the send, in job order. A work line is `## <n>. <text>`, a `Rule:` per ~ rule, `### Checked by code` (bullets) and the AI's text under its heading; an Ask line is one line
12
12
  * in its place; a work line with nothing to write has no section. Pure.
13
- * @param {{n: number, kind: 'ask'|'work', text?: string, rules?: string[], artifact?: unknown, checks?: any[], okIds?: Set<string>|null, proseChecked?: boolean}[]} lines
13
+ * @param {{n: number, kind: 'ask'|'work', text?: string, rules?: string[], artifact?: unknown, checks?: any[], okIds?: Set<string>|null, proseChecked?: boolean, shape?: any}[]} lines
14
14
  * @param {Record<string, any>} tables the frozen sheets by input name
15
15
  * @returns {string}
16
16
  */
@@ -23,6 +23,7 @@ export function renderReportBody(lines: {
23
23
  checks?: any[];
24
24
  okIds?: Set<string> | null;
25
25
  proseChecked?: boolean;
26
+ shape?: any;
26
27
  }[], tables: Record<string, any>): string;
27
28
  /**
28
29
  * The file name for a report: `<job>-YYYY-MM-DD.md`, then `<job>-YYYY-MM-DD-2.md`, `-3`, ... the first one that is free in `dir` (the machine's local day). Never a taken name. `taken` = the first choice
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @typedef {{key: string, result: 'passed'|'failed'|'unread', why?: string}} RowResult
3
+ * @param {any[]|null|undefined} list the signed list (`closeDecl.list`) @param {{step: number, parts: any[]}} params the rubric-step stage's params
4
+ * @param {{verdict?: string, rawGaps?: any[], extraGaps?: string[], detail?: Record<string, any>, ruleCounts?: Record<number, {min?: number, max?: number}>}} graded `gradeStep`'s answer (`ruleCounts`: fwd's, the bounds of the rules that count items)
5
+ * @returns {{rows: RowResult[], unclaimed: string[], items?: string[]}}
6
+ */
7
+ export function rowResultsOf(list: any[] | null | undefined, params: {
8
+ step: number;
9
+ parts: any[];
10
+ }, graded: {
11
+ verdict?: string;
12
+ rawGaps?: any[];
13
+ extraGaps?: string[];
14
+ detail?: Record<string, any>;
15
+ ruleCounts?: Record<number, {
16
+ min?: number;
17
+ max?: number;
18
+ }>;
19
+ }): {
20
+ rows: RowResult[];
21
+ unclaimed: string[];
22
+ items?: string[];
23
+ };
24
+ export type RowResult = {
25
+ key: string;
26
+ result: "passed" | "failed" | "unread";
27
+ why?: string;
28
+ };
@@ -41,6 +41,27 @@ export function listMatchesClose(closeDecl: any): {
41
41
  ok: false;
42
42
  error: string;
43
43
  };
44
+ /**
45
+ * FACTS + SHAPE: the extra lines of a fact line's brief when its close also carries an itemShape part (code-written, never model-written): each result also carries the shape fields, in plain words, with ONE example result
46
+ * built by code (the quote and values placeholders, then a legal value for each shape field). Nothing is added for a line with no shape part.
47
+ * @param {any} shape the line's shape part ({fields, minItems?, maxItems?}) @param {any} fp the fact part @returns {string[]}
48
+ */
49
+ export function shapeBriefOf(shape: any, fp: any): string[];
50
+ /**
51
+ * A SHAPE line's brief (no fact part): the answer is a list of items, each field in plain words (the signed bounds, in the person's own form) and ONE worked example item, all written by code from the signed shape.
52
+ * `alsoText` = the line also carries the person's picks (its answer has `text` too).
53
+ * @param {number} n the job line @param {any} shape the line's shape part @param {boolean} [alsoText] @returns {string}
54
+ */
55
+ export function shapeLineBrief(n: number, shape: any, alsoText?: boolean): string;
56
+ /**
57
+ * The plain sentence of a bareguard gap of one line's answer, as the tag's `plainStepGap` takes it (step, why, gap, params). fwd's step has no file, so an itemShape gap's file is `the answer` (src/closers.js); only an itemShape gap
58
+ * is worded here (fwd's other gaps keep their own words in src/closers.js and src/citedcheck.js).
59
+ * @param {number} step the job line @param {string} _why @param {any} g a bareguard gap @param {any} [_params] @returns {string}
60
+ */
61
+ export function plainStepGap(step: number, _why: string, g: any, _params?: any): string;
62
+ export function stageKeyOf(name: string): string;
63
+ export function guardKeyOf(name: string): string;
64
+ export const FENCE_KEY: "J.$fence";
44
65
  /** 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
66
  export const PART_CLASSES: readonly string[];
46
67
  /**
package/types/runner.d.ts CHANGED
@@ -616,10 +616,11 @@ import { readTicketMcp } from './ticket-mcp.js';
616
616
  * @param {number} [opts.triesDone] - tries a Stop already closed on this step (they count against its limit)
617
617
  * @param {string|null} [opts.runDir] - M4d am29 item 2: the run's folder, where each try saves its checks
618
618
  * @param {any[]} [opts.checkList] - M16 item 5: the plan's signed list; a list line's checks carry the row's `by`
619
+ * @param {any[]} [opts.jobLines] - M19 am11 item 4: the signed job lines; the words of a list line's rows read the person's rule
619
620
  * @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
620
621
  * @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}}>}
621
622
  */
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, }: {
623
+ declare function runStepTries({ step, primitivesMap, readsMap, businessDate, modelStep, spent, capUsd, ceilingUsd, recordAudit, initialGap, attemptOffset, thinkingBox, learnHints, now, readStop, stepNo, triesDone, runDir, prevStepId, mcpGranted, checkList, jobLines, }: {
623
624
  step: any;
624
625
  primitivesMap?: Record<string, any> | undefined;
625
626
  readsMap: Record<string, any>;
@@ -649,6 +650,7 @@ declare function runStepTries({ step, primitivesMap, readsMap, businessDate, mod
649
650
  triesDone?: number | undefined;
650
651
  runDir?: string | null | undefined;
651
652
  checkList?: any[] | undefined;
653
+ jobLines?: any[] | undefined;
652
654
  mcpGranted?: Record<string, any> | undefined;
653
655
  }): Promise<{
654
656
  ok: true;
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Does a field carry at least ONE real bound the person's rule grounds (a number, a count of characters, words or entries, the one-of values, a yes/no value; `required` + `minChars: 1` is "each item has a title")?
3
+ * A modifier alone (a currency, a unit, how a number is read) is no bound. A list counts when its entries do.
4
+ * @param {Record<string, any>} bounds @returns {boolean}
5
+ */
6
+ export function hasRealBound(bounds: Record<string, any>): boolean;
7
+ /**
8
+ * @typedef {{name: string, kind: string, required: boolean, bounds: Record<string, any>, rule: number|null, by: 'you'|'agent', held: boolean, why?: string}} ShapeField
9
+ * @typedef {{rule: number, text: string, state: 'built'|'not-checked', reason: string|null, name: string|null}} ShapeRule
10
+ * @typedef {{line: number, ok: boolean, fields: ShapeField[], itemCount: {labels: string[], n: number}|null, rows: ShapeRule[], refused: {helper: string, why: string}[], reservedChecked: boolean}} LineShape
11
+ */
12
+ /**
13
+ * Is ONE bound value in the person's words? A number counts when it is written as a number there (an upper bound also when it is the written number minus one: "under 60" signs 59); a string value when it is
14
+ * written there, case and spacing aside.
15
+ * @param {string} key @param {unknown} v @param {string} text the person's words (the field's own rule) @param {boolean} required
16
+ * @returns {boolean}
17
+ */
18
+ export function boundGrounded(key: string, v: unknown, text: string, required?: boolean): boolean;
19
+ /**
20
+ * Build the shape of ONE job line from the AI's suggestion, or refuse each part with its plain reason.
21
+ * @param {{line: {n: number, text?: string, rules?: string[], rule?: string}, labels: string[], suggestion: unknown, nameRules?: ReturnType<typeof shapeNameRules>}} o
22
+ * @returns {LineShape}
23
+ */
24
+ export function buildShapeLine({ line, labels, suggestion, nameRules }: {
25
+ line: {
26
+ n: number;
27
+ text?: string;
28
+ rules?: string[];
29
+ rule?: string;
30
+ };
31
+ labels: string[];
32
+ suggestion: unknown;
33
+ nameRules?: ReturnType<typeof shapeNameRules>;
34
+ }): LineShape;
35
+ /**
36
+ * Build the shape of every candidate line from the reply's suggestions, each routed to its job line by its own `line`. A suggestion naming no candidate line, or not an object, is refused and listed.
37
+ * @param {{lines: {n: number, text?: string, rules?: string[], rule?: string}[], labels: string[], suggestions: unknown[], nameRules?: ReturnType<typeof shapeNameRules>}} o
38
+ * @returns {{built: Record<number, LineShape>, notChecked: Record<string, string>, refused: {line: number|null, helper: string, why: string}[]}}
39
+ * `built` holds only the lines whose shape stands (at least one field from a `~` rule); `notChecked`: `line N: "rule"` -> why, for each rule of a built line no field holds
40
+ */
41
+ export function buildShapes({ lines, labels, suggestions, nameRules }: {
42
+ lines: {
43
+ n: number;
44
+ text?: string;
45
+ rules?: string[];
46
+ rule?: string;
47
+ }[];
48
+ labels: string[];
49
+ suggestions: unknown[];
50
+ nameRules?: ReturnType<typeof shapeNameRules>;
51
+ }): {
52
+ built: Record<number, LineShape>;
53
+ notChecked: Record<string, string>;
54
+ refused: {
55
+ line: number | null;
56
+ helper: string;
57
+ why: string;
58
+ }[];
59
+ };
60
+ /** why a `~` rule no field holds is Not checked, when no field named it (judged at Accept, not at an Ask) */
61
+ export const NO_FIELD_WHY: "No field was picked for it, so you judge it at Accept.";
62
+ /** why a rule whose field carries no limit from its own words stays Not checked: a field with no bound checks nothing the person asked for (hamr 2026-11-19) */
63
+ export const NO_BOUND_WHY: "The field picked for it has no limit from your words, so it checks nothing; you judge it at Accept.";
64
+ export function fieldSpec(f: ShapeField): Record<string, any>;
65
+ export type ShapeField = {
66
+ name: string;
67
+ kind: string;
68
+ required: boolean;
69
+ bounds: Record<string, any>;
70
+ rule: number | null;
71
+ by: "you" | "agent";
72
+ held: boolean;
73
+ why?: string;
74
+ };
75
+ export type ShapeRule = {
76
+ rule: number;
77
+ text: string;
78
+ state: "built" | "not-checked";
79
+ reason: string | null;
80
+ name: string | null;
81
+ };
82
+ export type LineShape = {
83
+ line: number;
84
+ ok: boolean;
85
+ fields: ShapeField[];
86
+ itemCount: {
87
+ labels: string[];
88
+ n: number;
89
+ } | null;
90
+ rows: ShapeRule[];
91
+ refused: {
92
+ helper: string;
93
+ why: string;
94
+ }[];
95
+ reservedChecked: boolean;
96
+ };
97
+ import { shapeNameRules } from './shapemenu.js';
@@ -0,0 +1,76 @@
1
+ /** the menu as the drafter reads it, one line per kind of src/shapemenu.js (the one place it is named): ` boolean: bounds equals` @returns {string[]} */
2
+ export function shapeMenuLines(): string[];
3
+ /**
4
+ * What the AI is told: the job (its `~` rules numbered per line), the inputs (bounded), the kind menu and the answer form.
5
+ * @param {{jobLines: {n: number, text: string, rule?: string, rules?: string[]}[], lineNums: number[], texts: Record<string, string>, left?: {line: number, rules: number[]}[]}} o `lineNums` the lines a shape can be offered for, `left` the rules still without a check
6
+ * @returns {string}
7
+ */
8
+ export function shapeLookPrompt({ jobLines, lineNums, texts, left }: {
9
+ jobLines: {
10
+ n: number;
11
+ text: string;
12
+ rule?: string;
13
+ rules?: string[];
14
+ }[];
15
+ lineNums: number[];
16
+ texts: Record<string, string>;
17
+ left?: {
18
+ line: number;
19
+ rules: number[];
20
+ }[];
21
+ }): string;
22
+ /**
23
+ * Read the AI's answer: ONE JSON object `{"shapes":[...]}`, each shape an object with a whole `line`, its `fields` and `extraFields` lists (an absent list is none). No repair: anything else is a malformed answer. What a field MEANS is judged by code (src/shapebuild.js).
24
+ * @param {unknown} text @returns {{ok: true, shapes: Record<string, any>[]}|{ok: false}}
25
+ */
26
+ export function parseShapeAnswer(text: unknown): {
27
+ ok: true;
28
+ shapes: Record<string, any>[];
29
+ } | {
30
+ ok: false;
31
+ };
32
+ /**
33
+ * Look at the shape of the answer: the call (once; once more after an unreadable answer or one transport failure; a 429 waits the vendor's stated time once and is not an attempt).
34
+ * `callModel(content, attempt)` makes and meters ONE model round (the drafter's `makeCallModel('shape-map', SHAPE_SYSTEM)`) and returns `{text}`, `{text, cutOff: true}` or `{error}` (with `budget: true` when the cap stopped the call, `threw` when the provider threw).
35
+ * @param {{texts: Record<string, string>, jobLines: {n: number, text: string, rule?: string, rules?: string[]}[], lineNums: number[], left?: {line: number, rules: number[]}[], ceilingUsd?: number|null,
36
+ * callModel: (content: string, attempt: number) => Promise<{text?: string, cutOff?: boolean, error?: string, budget?: boolean, threw?: any}>, sleep?: (ms: number) => Promise<void>}} o
37
+ * @returns {Promise<{ok: true, shapes: Record<string, any>[], attempts: number}|{ok: false, reason: string, attempts: number}>}
38
+ */
39
+ export function lookAtShape({ texts, jobLines, lineNums, left, ceilingUsd, callModel, sleep }: {
40
+ texts: Record<string, string>;
41
+ jobLines: {
42
+ n: number;
43
+ text: string;
44
+ rule?: string;
45
+ rules?: string[];
46
+ }[];
47
+ lineNums: number[];
48
+ left?: {
49
+ line: number;
50
+ rules: number[];
51
+ }[];
52
+ ceilingUsd?: number | null;
53
+ callModel: (content: string, attempt: number) => Promise<{
54
+ text?: string;
55
+ cutOff?: boolean;
56
+ error?: string;
57
+ budget?: boolean;
58
+ threw?: any;
59
+ }>;
60
+ sleep?: (ms: number) => Promise<void>;
61
+ }): Promise<{
62
+ ok: true;
63
+ shapes: Record<string, any>[];
64
+ attempts: number;
65
+ } | {
66
+ ok: false;
67
+ reason: string;
68
+ attempts: number;
69
+ }>;
70
+ /** the label of the one paid call about a shape, as the drafting book and the progress line see it (the sibling of `SHEET_CALL_LABEL`) */
71
+ export const SHAPE_CALL_LABEL: "shape-map";
72
+ /** how much of each input the call is shown (the POC's bound, declared in its preregistration) */
73
+ export const SHAPE_SHOWN_CHARS: 8000;
74
+ /** at most this many fields in one suggestion (bareguard allows 50 per `fields` object; a person's rule list is far shorter) */
75
+ export const MAX_SHAPE_FIELDS: 20;
76
+ export const SHAPE_SYSTEM: "You map a person's job to the SHAPE of an answer: a list of items, each item with named fields. You never grade and never invent bounds: a bound is only what the person wrote. Reply with JSON only.";