fwdloop 0.28.0 → 0.30.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 (74) hide show
  1. package/README.md +1 -1
  2. package/bin/fwdloop +27 -5
  3. package/package.json +3 -3
  4. package/src/added-end.js +60 -0
  5. package/src/ask.js +1 -1
  6. package/src/audit-fold.js +9 -1
  7. package/src/authoring.js +18 -7
  8. package/src/checked.js +14 -9
  9. package/src/checkpick.js +318 -0
  10. package/src/checkwords.js +29 -0
  11. package/src/citedcheck.js +14 -0
  12. package/src/closers.js +40 -3
  13. package/src/declaration.js +102 -5
  14. package/src/draft-steps.js +3 -3
  15. package/src/drafter.js +151 -38
  16. package/src/jobkey.js +3 -1
  17. package/src/learn.js +1 -1
  18. package/src/learnstore.js +6 -6
  19. package/src/memo.js +120 -0
  20. package/src/model-step.js +103 -25
  21. package/src/pageask.js +12 -6
  22. package/src/pagedropwords.js +9 -0
  23. package/src/panel/author.js +33 -10
  24. package/src/panel/authorcard.js +59 -6
  25. package/src/panel/data.js +16 -10
  26. package/src/panel/index.html +151 -59
  27. package/src/panel/result.js +28 -7
  28. package/src/panel/server.js +2 -1
  29. package/src/pickrecord.js +146 -0
  30. package/src/plain-checks.js +16 -3
  31. package/src/provider.js +4 -1
  32. package/src/repairs.js +38 -0
  33. package/src/runfile.js +4 -2
  34. package/src/runner.js +129 -40
  35. package/src/send.js +71 -4
  36. package/src/setup.js +13 -1
  37. package/src/sheetblock.js +2 -1
  38. package/src/ticket-draft.js +2 -2
  39. package/src/ticket-labels.js +2 -2
  40. package/src/try-checks.js +13 -3
  41. package/src/whole-job.js +71 -0
  42. package/types/added-end.d.ts +62 -0
  43. package/types/ask.d.ts +2 -1
  44. package/types/audit-fold.d.ts +13 -2
  45. package/types/authoring.d.ts +6 -2
  46. package/types/checked.d.ts +7 -2
  47. package/types/checkpick.d.ts +183 -0
  48. package/types/checkwords.d.ts +18 -0
  49. package/types/citedcheck.d.ts +6 -0
  50. package/types/closers.d.ts +6 -3
  51. package/types/declaration.d.ts +12 -0
  52. package/types/drafter.d.ts +28 -25
  53. package/types/learn.d.ts +1 -0
  54. package/types/learnstore.d.ts +2 -3
  55. package/types/memo.d.ts +15 -0
  56. package/types/model-step.d.ts +23 -3
  57. package/types/pageask.d.ts +9 -2
  58. package/types/pagedropwords.d.ts +1 -0
  59. package/types/panel/author.d.ts +1 -1
  60. package/types/panel/authorcard.d.ts +41 -0
  61. package/types/panel/data.d.ts +1 -1
  62. package/types/panel/jobgrid.d.ts +1 -1
  63. package/types/panel/result.d.ts +9 -3
  64. package/types/pickrecord.d.ts +88 -0
  65. package/types/plain-checks.d.ts +9 -1
  66. package/types/repairs.d.ts +13 -0
  67. package/types/runfile.d.ts +7 -2
  68. package/types/runner.d.ts +16 -5
  69. package/types/send.d.ts +10 -2
  70. package/types/setup.d.ts +1 -56
  71. package/types/try-checks.d.ts +1 -7
  72. package/types/whole-job.d.ts +70 -0
  73. package/src/attemptdiff.js +0 -118
  74. package/types/attemptdiff.d.ts +0 -38
@@ -91,12 +91,6 @@ export function buildDeclarationSchema(menu: any[], { sheets, ticket }?: {
91
91
  enum: string[];
92
92
  description: string;
93
93
  };
94
- shape: {
95
- type: string;
96
- properties: {};
97
- additionalProperties: boolean;
98
- description: string;
99
- };
100
94
  cited: Readonly<{
101
95
  type: "object";
102
96
  description: "only on a green step that checks quotes from a web page or a document input: the facts every result must hold. Omit on any other step";
@@ -337,12 +331,6 @@ export function buildDeclarationSchema(menu: any[], { sheets, ticket }?: {
337
331
  enum: string[];
338
332
  description: string;
339
333
  };
340
- shape: {
341
- type: string;
342
- properties: {};
343
- additionalProperties: boolean;
344
- description: string;
345
- };
346
334
  cited: Readonly<{
347
335
  type: "object";
348
336
  description: "only on a green step that checks quotes from a web page or a document input: the facts every result must hold. Omit on any other step";
@@ -578,12 +566,6 @@ export function buildRoundSchema(menu: any[], { questions, sheets, ticket }?: {
578
566
  enum: string[];
579
567
  description: string;
580
568
  };
581
- shape: {
582
- type: string;
583
- properties: {};
584
- additionalProperties: boolean;
585
- description: string;
586
- };
587
569
  cited: Readonly<{
588
570
  type: "object";
589
571
  description: "only on a green step that checks quotes from a web page or a document input: the facts every result must hold. Omit on any other step";
@@ -831,12 +813,6 @@ export function buildRoundSchema(menu: any[], { questions, sheets, ticket }?: {
831
813
  enum: string[];
832
814
  description: string;
833
815
  };
834
- shape: {
835
- type: string;
836
- properties: {};
837
- additionalProperties: boolean;
838
- description: string;
839
- };
840
816
  cited: Readonly<{
841
817
  type: "object";
842
818
  description: "only on a green step that checks quotes from a web page or a document input: the facts every result must hold. Omit on any other step";
@@ -991,6 +967,22 @@ export function normalizeQuestions(raw: any, failedLines: any): {
991
967
  kept: any[];
992
968
  dropped: any[];
993
969
  };
970
+ /**
971
+ * The job lines as the page look may see them (no count rule), and `toOriginal`, which takes a look fact's / dropped entry's visible rule number back to the guardrail's own number.
972
+ * @param {{n: number, text: string, rule?: string}[]} jobLines
973
+ */
974
+ export function hideCounts(jobLines: {
975
+ n: number;
976
+ text: string;
977
+ rule?: string;
978
+ }[]): {
979
+ seenLines: {
980
+ rule?: string | undefined;
981
+ n: number;
982
+ text: string;
983
+ }[];
984
+ toOriginal: (f: any) => any;
985
+ };
994
986
  export function buildSystemPrompt({ menu, lines, arbiter, factsInfo }: {
995
987
  menu: any;
996
988
  lines: any;
@@ -1020,7 +1012,7 @@ export function goalForLine(fromLine: any, lines: any): any;
1020
1012
  * `learnHints` (M8 item 5a): the earlier runs' notes block (src/learnstore.js hintsForRun), appended to the drafter's system prompt; null = nothing.
1021
1013
  * `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`.
1022
1014
  */
1023
- export function draft({ proseText, slot, model, provider: injected, rates: injectedRates, modelId: injectedModelId, env, priorSpend, skills, makeProviderFn, onBook, offerQuestions, draftThinking, draftDir, fetchPage, leftRules, learnHints, mcpServers, flowType, mcp, }: {
1015
+ export function draft({ proseText, slot, model, provider: injected, rates: injectedRates, modelId: injectedModelId, env, priorSpend, skills, makeProviderFn, onBook, offerQuestions, draftThinking, draftDir, fetchPage, leftRules, checkPicks, carriedPicks, onPickRecord, learnHints, mcpServers, flowType, mcp, }: {
1024
1016
  proseText: any;
1025
1017
  slot: any;
1026
1018
  model: any;
@@ -1040,6 +1032,17 @@ export function draft({ proseText, slot, model, provider: injected, rates: injec
1040
1032
  line: number;
1041
1033
  rule: number;
1042
1034
  }[] | undefined;
1035
+ checkPicks?: import("./checkpick.js").Pick[] | undefined;
1036
+ carriedPicks?: import("./pickrecord.js").Entry[] | undefined;
1037
+ onPickRecord?: ((r: {
1038
+ picks: import("./pickrecord.js").Entry[];
1039
+ kept: {
1040
+ line: number;
1041
+ rule: number;
1042
+ ruleText: string;
1043
+ check: Record<string, any> | null;
1044
+ }[];
1045
+ }) => void) | null | undefined;
1043
1046
  learnHints?: {
1044
1047
  text: string;
1045
1048
  ids: string[];
package/types/learn.d.ts CHANGED
@@ -343,6 +343,7 @@ export const SUSPECT_KEEP: 100;
343
343
  * src/authoring.js; a test fails if the two drift apart). Anything else in a bracket is NOT a kind.
344
344
  */
345
345
  export const ALLOWED_KINDS: readonly string[];
346
+ export function nameOf(g: string): string;
346
347
  export function keyOfCard(c: {
347
348
  check: string;
348
349
  kinds: string[];
@@ -110,15 +110,14 @@ export function eventsOfRun(runDir: string, workflow: string): {
110
110
  * with a signed ask included; there is no hold. It runs whether `learningHints` is on or off. `questions` (bareloop's stageQuestionsByName) is, here, the failing check's own text from
111
111
  * the run's diary.jsonl, so a check with no checks row there (a run from before am29) has no `meaning`.
112
112
  * Borrowed-from: bareloop src/learnstore.js@v0.47.0:124 (learnAtRunEnd).
113
- * @param {{home?: string, workflow: string, runId: string, runDir: string, specHash: string|null, now?: Date}} o
113
+ * @param {{home?: string, workflow: string, runId: string, runDir: string, now?: Date}} o
114
114
  * @returns {{wrote: boolean, counted: number, held: number, problem: string|null, noise: string|null, cards: number}}
115
115
  */
116
- export function learnAtRunEnd({ home, workflow, runId, runDir, specHash, now }: {
116
+ export function learnAtRunEnd({ home, workflow, runId, runDir, now }: {
117
117
  home?: string;
118
118
  workflow: string;
119
119
  runId: string;
120
120
  runDir: string;
121
- specHash: string | null;
122
121
  now?: Date;
123
122
  }): {
124
123
  wrote: boolean;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The memo for the try about to run, as text; `''` when nothing has happened yet in this run (no human line, no earlier try).
3
+ * @param {string|null} runDir the run's folder (null = no record = nothing happened)
4
+ * @param {{step: string|null, cap?: number}} o `step` = the step the try belongs to (names its earlier tries and tells a retry from a later step's first try)
5
+ * @returns {string}
6
+ */
7
+ export function buildMemo(runDir: string | null, { step, cap }: {
8
+ step: string | null;
9
+ cap?: number;
10
+ }): string;
11
+ /** M14 am1 item 2: the memo's fixed words */
12
+ export const MEMO_HEADING: "What happened so far in this run (written by code, from the record)";
13
+ export const MEMO_CUT_NOTE: "(older lines cut to fit)";
14
+ /** M14 item 5 */
15
+ export const MEMO_CAP: 4000;
@@ -15,8 +15,8 @@ export function isTransportFailure(err: any): boolean;
15
15
  * only (plus, for a green step that quotes a saved page, the form of its answer).
16
16
  * `stepClass` is `'green' | 'softgreen' | 'hitl' | null | undefined`; `cited` is true for that green step.
17
17
  */
18
- /** @param {string|null|undefined} stepClass @param {boolean} [cited] @param {any[]|null} [sheet] M10b piece 2: the step's `close.sheet` (its claim boxes become the answer) */
19
- export function buildEmitArtifactSchema(stepClass: string | null | undefined, cited?: boolean, sheet?: any[] | null): Readonly<{
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<{
20
20
  type: "object";
21
21
  properties: {
22
22
  done: {
@@ -93,6 +93,19 @@ export function buildEmitArtifactSchema(stepClass: string | null | undefined, ci
93
93
  type: string[];
94
94
  description: string;
95
95
  };
96
+ text: {
97
+ type: string;
98
+ };
99
+ } | {
100
+ done: {
101
+ type: string;
102
+ description: string;
103
+ };
104
+ blocker: {
105
+ type: string[];
106
+ description: string;
107
+ };
108
+ text?: undefined;
96
109
  };
97
110
  required: string[];
98
111
  additionalProperties: boolean;
@@ -106,7 +119,7 @@ export function buildEmitArtifactSchema(stepClass: string | null | undefined, ci
106
119
  * @param {{in:number,out:number}} [opts.rates]
107
120
  * @param {string} [opts.modelId]
108
121
  * @param {Record<string,string|undefined>} [opts.env] - the merged shell+keys-file env the key is read from (default process.env).
109
- * @returns {(executorContext:object, grantedTools:Record<string,any>, stepMeta?:{class?:string, attempt?:number, step?:string|null, cited?:any, sheet?:any[]|null, thinkingMode?:'on'|'off'}, seam?:{stopRequested?:() => boolean}) => Promise<any>}
122
+ * @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>}
110
123
  */
111
124
  export function makeLiveModelStep({ slot, model, spendPath, provider: injectedProvider, rates: injectedRates, modelId: injectedModelId, env, }: {
112
125
  slot?: string | undefined;
@@ -125,6 +138,8 @@ export function makeLiveModelStep({ slot, model, spendPath, provider: injectedPr
125
138
  step?: string | null;
126
139
  cited?: any;
127
140
  sheet?: any[] | null;
141
+ withText?: boolean;
142
+ picked?: any[] | null;
128
143
  thinkingMode?: "on" | "off";
129
144
  }, seam?: {
130
145
  stopRequested?: () => boolean;
@@ -133,3 +148,8 @@ export const LIVE_PROVIDER_OPTIONS: Readonly<{
133
148
  timeoutMs: 300000;
134
149
  deadlineMs: 240000;
135
150
  }>;
151
+ /** M4d am37: the one fixed line a step that answered in text is sent, from code; the model never writes it and it never changes. */
152
+ export const NUDGE: "You answered in text. Call emit_artifact now with that answer; do not reply in text.";
153
+ /** M4d am37: a provider that says it does not send `toolChoice` (`makeProvider` sets the flag from the row's shape) ignores a forced call; round 2 then sends the line unforced and a save there is the fallback. */
154
+ /** Ruling A (hamr 2026-11-03): the fixed say on the audit row of a try whose forced call was refused with no usage returned; it books $0. */
155
+ export const FORCED_REFUSED_SAY: "refused, no bill returned";
@@ -44,22 +44,29 @@ export function tooManyAsksText(asks: {
44
44
  * What a typed answer to a look ask does, the ONE place that decides (the panel's answer route, the setup record and the Result tab all read it).
45
45
  * `agree` / `yes` to a reading ask takes the code's reading; `drop it` to a can't-check ask leaves the rule Not checked (no `~` line); anything else is the
46
46
  * person's own words, taken word for word with newlines folded to spaces. A question that is not a look ask is never changed: its answer is its rule.
47
- * @param {{source?: string, ask?: string, proposal?: string|null}} q @param {unknown} typed
48
- * @returns {{rule: string|null, left: boolean}} `rule` = the words written as a new `~` rule (null when the rule is left Not checked)
47
+ * M10 am16: a shape guardrail's ask (`ask: 'check'` proposes a check, `'no-check'` found none) takes the same words: `agree` takes the proposal (and the check it
48
+ * carries, `check`), `drop it` leaves the rule Not checked (either kind), anything else is the person's own words (`own`: a `~` rule on the line, no check).
49
+ * @param {{source?: string, ask?: string, proposal?: string|null, check?: Record<string, any>}} q @param {unknown} typed
50
+ * @returns {{rule: string|null, left: boolean, check?: Record<string, any>, own?: boolean}} `rule` = the words written as a new `~` rule (null when the rule is left Not checked)
49
51
  */
50
52
  export function ruleOfAnswer(q: {
51
53
  source?: string;
52
54
  ask?: string;
53
55
  proposal?: string | null;
56
+ check?: Record<string, any>;
54
57
  }, typed: unknown): {
55
58
  rule: string | null;
56
59
  left: boolean;
60
+ check?: Record<string, any>;
61
+ own?: boolean;
57
62
  };
58
63
  /** the most asks before drafting; more than this is a job to rewrite, not a questionnaire (am1) */
59
64
  export const MAX_LOOK_ASKS: 3;
60
65
  /** the answer that drops a `~` rule the page cannot check: the person types it (any case, a closing full stop allowed) */
61
66
  export const DROP_IT: "drop it";
62
67
  export function isDropIt(text: unknown): boolean;
68
+ /** the answers that accept the code's reading of a rule; anything else the person types is their own reading */
69
+ export const AGREE_WORDS: string[];
63
70
  export function isAgree(text: unknown): boolean;
64
71
  export function stripAgreeLead(text: string): string;
65
72
  /**
@@ -37,4 +37,5 @@ 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;
40
41
  export type Dropped = import("./pagerules.js").Dropped;
@@ -377,7 +377,7 @@ export function createAuthor(opts: {
377
377
  * `POST /api/author/:id/answer` body `{ k, answer }` (M4e amendments 24, 25): the human's answer to the plan's question `k` of `n`, one at a time.
378
378
  * A blank answer is refused and the question stays open; there is no skip. The answer is written ONCE ('wx') as `<plan>/answer-<k>.json`. After
379
379
  * the LAST answer the plan is drafted again as a fresh plain `fwdloop draft --no-questions` child (it never asks), from the submitted card with
380
- * each answer added word for word as a `~` guardrail under its line (the one `appendAnswersToJob`, then the one `cardToProse`). It is booked as
380
+ * each answer added word for word as a `~` guardrail under its line (the one `applyAnswers`, then the one `cardToProse`). It is booked as
381
381
  * an answer redraft (`redraft-<n>.json`), not a revise: it uses none of the 2. Synchronous, like `revise`; a refusal at $0 writes nothing.
382
382
  * @param {string} id @param {any} body
383
383
  */
@@ -36,6 +36,47 @@ export function appendAnswersToJob(job: string, answers: {
36
36
  job: string;
37
37
  added: number;
38
38
  };
39
+ /**
40
+ * M10 am21: the submitted job box with ONE `~` line of a job line replaced by the words of an answer (the edited added line the ask was about). Pure.
41
+ * @param {string} job @param {number} line the job line (step) number @param {string} oldText the `~` words to replace (case and spacing aside) @param {string} newText
42
+ * @returns {{ job: string, replaced: boolean }}
43
+ */
44
+ export function replaceRuleOnJob(job: string, line: number, oldText: string, newText: string): {
45
+ job: string;
46
+ replaced: boolean;
47
+ };
48
+ /**
49
+ * THE one writer of what a set of answers does to the job box and to the picks (M4e am24, M10 am16 (4), M10 am21): an answer is one more `~` line under its job line
50
+ * (`appendAnswersToJob`), EXCEPT the answer to an ask about an edited added line (`pairRule`), which REPLACES that line's words (the old added line never comes back).
51
+ * Picks and left rules are numbered as the asks carried them; an edited-line pick is kept under its source's number (`pairRule`), with the edited words as `added`.
52
+ * @param {string} job @param {{line: number, rule: string|null, left: boolean, check?: Record<string, any>|null, own?: boolean, ruleNo?: number, ruleText?: string, ask?: string, pairRule?: number}[]} all
53
+ * @returns {{job: string, added: number, picks: {line: number, rule: number|undefined, check: Record<string, any>|null, added: string, own?: boolean}[], left: {line: number, rule: number|undefined}[]}}
54
+ */
55
+ export function applyAnswers(job: string, all: {
56
+ line: number;
57
+ rule: string | null;
58
+ left: boolean;
59
+ check?: Record<string, any> | null;
60
+ own?: boolean;
61
+ ruleNo?: number;
62
+ ruleText?: string;
63
+ ask?: string;
64
+ pairRule?: number;
65
+ }[]): {
66
+ job: string;
67
+ added: number;
68
+ picks: {
69
+ line: number;
70
+ rule: number | undefined;
71
+ check: Record<string, any> | null;
72
+ added: string;
73
+ own?: boolean;
74
+ }[];
75
+ left: {
76
+ line: number;
77
+ rule: number | undefined;
78
+ }[];
79
+ };
39
80
  /**
40
81
  * THE one place a step's `~` lines become its guardrail: several `~` lines under one step are ONE continuous guardrail (hamr ruling 2026-10-09),
41
82
  * each part verbatim (trimmed), in typed order, joined by "; ". An answer (am24) is one more `~` line, so it joins here too. The signed-text parser
@@ -756,7 +756,7 @@ export function getJobGrid({ root, flow, catalogue, now, }: {
756
756
  name: string;
757
757
  title: string | null;
758
758
  number: number | null;
759
- bucket: "done" | "skip" | "stop" | "wait";
759
+ bucket: "wait" | "done" | "skip" | "stop";
760
760
  glyph: string;
761
761
  at: number;
762
762
  ex: "r" | "n" | "g" | "q";
@@ -69,7 +69,7 @@ export function buildJobGrid({ runs, anyway, now }: {
69
69
  name: string;
70
70
  title: string | null;
71
71
  number: number | null;
72
- bucket: "done" | "skip" | "stop" | "wait";
72
+ bucket: "wait" | "done" | "skip" | "stop";
73
73
  glyph: string;
74
74
  at: number;
75
75
  ex: "r" | "n" | "g" | "q";
@@ -3,6 +3,12 @@
3
3
  * @param {any} arbiter @returns {boolean}
4
4
  */
5
5
  export function isResultRun(arbiter: any): boolean;
6
+ /**
7
+ * M15 item 1: the ONE decider of the Result tab and of its cards. Every job has it; a Tickets MCP job keeps what it had (M13 am2: the grid, and M10's cards only when
8
+ * it reads a page, a CSV or a .docx). Read off the signed declaration and arbiter.
9
+ * @param {any} arbiter @param {any} declaration @returns {boolean}
10
+ */
11
+ export function hasResultCards(arbiter: any, declaration: any): boolean;
6
12
  /** The run's check type: its distinct close classes, in step order (`hitl + softgreen`). `—` for a declaration with none.
7
13
  * @param {any} declaration @returns {string} */
8
14
  export function checkTypeOf(declaration: any): string;
@@ -55,9 +61,9 @@ export function readDelivered(rec: {
55
61
  buf: null;
56
62
  };
57
63
  /**
58
- * The files this run's signed sends wrote: for each signed send whose send step ended green in the audit, the file `<flow>-<runId>-<emits>.json`
59
- * in the signed folder, with the sha256 the human's accept recorded for the ask that send reads (`readAcceptedHashesByEmits`, the same record the
60
- * send itself checked). No accepted hash = recorded as null, which reads as "changed", never as ok.
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`
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
+ * send reads (`readAcceptedHashesByEmits`, the same record the send itself checked). No accepted hash = recorded as null, which reads as "changed", never as ok.
61
67
  * @returns {{path: string, dir: string|null, name: string, sha256: string|null}[]}
62
68
  */
63
69
  export function deliveredOf({ arbiter, declaration, runDir, root, flow, runId, auditRows, }: {
@@ -0,0 +1,88 @@
1
+ /**
2
+ * The key of every job line: its own words, plus how many lines before it have the same words (equal lines match in their order).
3
+ * @param {{n: number, text: string}[]} lines @returns {Map<number, {lineWords: string, occurrence: number}>}
4
+ */
5
+ export function lineKeys(lines: {
6
+ n: number;
7
+ text: string;
8
+ }[]): Map<number, {
9
+ lineWords: string;
10
+ occurrence: number;
11
+ }>;
12
+ /**
13
+ * The entries for answers just given, numbered on THIS card (the answer redraft's card: its line and rule numbers are the ones the asks carried).
14
+ * @param {{n: number, text: string}[]} lines @param {Rule[]} rules
15
+ * @param {{line: number, rule: number, check?: Record<string, any>|null, added?: string|null, own?: boolean}[]} picks @param {{line: number, rule: number}[]} left
16
+ * @returns {Entry[]}
17
+ */
18
+ export function entriesFromAnswers(lines: {
19
+ n: number;
20
+ text: string;
21
+ }[], rules: Rule[], picks: {
22
+ line: number;
23
+ rule: number;
24
+ check?: Record<string, any> | null;
25
+ added?: string | null;
26
+ own?: boolean;
27
+ }[], left: {
28
+ line: number;
29
+ rule: number;
30
+ }[]): Entry[];
31
+ /**
32
+ * Decide, for the card in hand, which stored picks are kept and which guardrails must be asked.
33
+ * A pick is KEPT when the job line with its words (same order among equal lines) still has its source guardrail with the exact words and, if the pick wrote a `~` line,
34
+ * that line with its exact words too. Otherwise the pick is dropped (never partly kept) and its guardrails are asked: a pair broken on one side is ONE ask, so the
35
+ * partner left on the card is folded (neither asked nor given the old check) - except an EDITED added line (M10 am21): that one is asked (`pairRule` = its source's number) and the source is folded. Pure.
36
+ * @param {Entry[]} entries @param {{n: number, text: string}[]} lines @param {Rule[]} rules every guardrail the call settles
37
+ * @returns {{picks: {line: number, rule: number, check: Record<string, any>|null, added?: string, own?: boolean}[], left: {line: number, rule: number}[],
38
+ * kept: {line: number, rule: number, entry: Entry}[], askRules: (Rule & {pairRule?: number})[]}}
39
+ */
40
+ export function matchRecord(entries: Entry[], lines: {
41
+ n: number;
42
+ text: string;
43
+ }[], rules: Rule[]): {
44
+ picks: {
45
+ line: number;
46
+ rule: number;
47
+ check: Record<string, any> | null;
48
+ added?: string;
49
+ own?: boolean;
50
+ }[];
51
+ left: {
52
+ line: number;
53
+ rule: number;
54
+ }[];
55
+ kept: {
56
+ line: number;
57
+ rule: number;
58
+ entry: Entry;
59
+ }[];
60
+ askRules: (Rule & {
61
+ pairRule?: number;
62
+ })[];
63
+ };
64
+ /**
65
+ * Read a carried record (the folder's file). A missing or unreadable file is no record (a plan from before am17 has none).
66
+ * @param {string} file @returns {Entry[]|null}
67
+ */
68
+ export function readRecordFile(file: string): Entry[] | null;
69
+ /** the record's file, inside a drafting folder only (never a run folder) */
70
+ export const RECORD_FILE: "picks-record.json";
71
+ /** the exact words a kept pick is marked with in the draft log, the Audit and the plan card (M10 am17 (6)) */
72
+ export const KEPT_WORDS: "kept from last draft";
73
+ export function sameWords(a: unknown, b: unknown): boolean;
74
+ export function recordPath(planDir: string): string;
75
+ export type Entry = {
76
+ lineWords: string;
77
+ occurrence: number;
78
+ ruleText: string;
79
+ added: string | null;
80
+ check: Record<string, any> | null;
81
+ own: boolean;
82
+ left: boolean;
83
+ };
84
+ export type Rule = {
85
+ line: number;
86
+ rule: number;
87
+ text: string;
88
+ };
@@ -1,3 +1,9 @@
1
+ /**
2
+ * M4d amendment 38 item 1: the ONE decision of which red is explained: the first red a `first` rule matches, else the first red (am15 item 3).
3
+ * @param {ReadonlyArray<string>} reds
4
+ * @returns {string|undefined}
5
+ */
6
+ export function pickPlanRed(reds: ReadonlyArray<string>): string | undefined;
1
7
  /**
2
8
  * @param {unknown} raw one raw refusal text
3
9
  * @returns {{ say: string, reason: string, fix: string, raw: string }}
@@ -8,15 +14,17 @@ export function plainPlanCheck(raw: unknown): {
8
14
  fix: string;
9
15
  raw: string;
10
16
  };
11
- /** @type {ReadonlyArray<{re: RegExp, say: string|null, fix: string}>} `say` null = the checker's own sentence, as it is without its "declaration: " prefix */
17
+ /** @type {ReadonlyArray<{re: RegExp, say: string|null, fix: string, first?: boolean}>} `say` null = the checker's own sentence, as it is without its "declaration: " prefix */
12
18
  export const PLAN_CHECK_RULES: ReadonlyArray<{
13
19
  re: RegExp;
14
20
  say: string | null;
15
21
  fix: string;
22
+ first?: boolean;
16
23
  }>;
17
24
  export const GENERIC_SAY: "One of the checks on the plan failed.";
18
25
  export const GENERIC_FIX: "Draft again.";
19
26
  export function pageRules(): {
27
+ first?: boolean | undefined;
20
28
  re: string;
21
29
  say: string | null;
22
30
  }[];
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @param {any} declaration the drafter's declaration (not changed) @param {{sources?: {role?: string, kind?: string}[]}} arbiter
3
+ * @returns {{declaration: any, repaired: string[]}}
4
+ */
5
+ export function repairDeclaration(declaration: any, arbiter: {
6
+ sources?: {
7
+ role?: string;
8
+ kind?: string;
9
+ }[];
10
+ }): {
11
+ declaration: any;
12
+ repaired: string[];
13
+ };
@@ -33,15 +33,20 @@ 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[] }} 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 }} start
37
37
  */
38
- export function writeRunStart(runDir: string, { model, thinking, inputs }: {
38
+ export function writeRunStart(runDir: string, { model, thinking, inputs, rerun }: {
39
39
  model: {
40
40
  slot: string;
41
41
  model: string;
42
42
  } | null;
43
43
  thinking: boolean;
44
44
  inputs: any[];
45
+ rerun?: {
46
+ decision: "rerun";
47
+ words: string;
48
+ afterStep: string | null;
49
+ } | null;
45
50
  }): void;
46
51
  /** the file's name in the run's folder */
47
52
  export const RUN_FILE: "run.json";
package/types/runner.d.ts CHANGED
@@ -29,13 +29,14 @@ export function readHaltRecord(runDir: string): {
29
29
  missing?: undefined;
30
30
  red?: undefined;
31
31
  };
32
- /** @param {{goal:string, primitives?:string[], reads?:Record<string,any>, gap?:string|null, hints?:string|null}} opts `hints` (M8 am7): the earlier runs' block, text only, for a retry / redo / rerun try */
32
+ /** @param {{goal:string, primitives?:string[], reads?:Record<string,any>, gap?:string|null, hints?:string|null, memo?:string|null}} opts `hints` (M8 am7): the earlier runs' block, text only, for a retry / redo / rerun try; `memo` (M14): what happened so far in this run, text only, every try */
33
33
  export function buildExecutorContext(opts: {
34
34
  goal: string;
35
35
  primitives?: string[];
36
36
  reads?: Record<string, any>;
37
37
  gap?: string | null;
38
38
  hints?: string | null;
39
+ memo?: string | null;
39
40
  }): Readonly<{
40
41
  goal: string;
41
42
  primitives: readonly string[];
@@ -44,6 +45,7 @@ export function buildExecutorContext(opts: {
44
45
  }>;
45
46
  gap: string | null;
46
47
  hints: string | null;
48
+ memo: string | null;
47
49
  }>;
48
50
  /**
49
51
  * @param {unknown} value
@@ -278,13 +280,14 @@ export function runStepRalph({ mcpServer, ...opts }: Parameters<typeof runStepTr
278
280
  * @param {unknown} opts.catalogue - passed straight through to `readFlow`.
279
281
  * @param {(executorContext:object, grantedTools:Record<string,any>, stepMeta?:{class:string|null}) => Promise<{ok:boolean, artifact?:unknown, costUsd:number|null, red?:string, transport?:boolean, model?:string, modelMatch?:boolean}>} opts.modelStep
280
282
  * @param {(opts:{question:string, evidence:unknown, runDir:string}) => Promise<{decision:'accept'|'redo'|'rerun'|'timeout'|'park', reason?:string, artifactSha256?:string}>} opts.askStep
281
- * @param {(target:string, filename:string, content:unknown, acceptedSha256?:string|null) => Promise<{ok:boolean, red?:string, bytes?:number}>} opts.sendStep
283
+ * @param {(target:string, filename:string, content:unknown, acceptedSha256?:string|null) => Promise<{ok:boolean, red?:string, bytes?:number, sha256?:string}>} opts.sendStep
282
284
  * @param {Record<string, any>} [opts.primitives] - injected primitive implementations, keyed by catalogue verb.
283
285
  * @param {string[]} [opts.primitiveReds] - `resolvePrimitives`'s own `reds` (e.g. bareguard refusing a symlinked file scope); any entry refuses the run at $0 like an unwired verb, before the run dir exists.
284
286
  * @param {() => string} [opts.clock] - returns the current ISO timestamp; defaults to the wall clock.
285
287
  * @param {string} opts.businessDate - the run's explicit "as of today", never the wall clock.
286
288
  * @param {number} [opts.ceilingUsd] - per-attempt ceiling override; the model's hold from Settings prices (`ceilingCostUsd`); absent = no hold.
287
289
  * @param {{slot: string, model: string}} [opts.runModel] - M4d am33: the model this run started on; recorded once in the run folder (run.json) and kept by every resume/continue.
290
+ * @param {{decision: 'rerun', words: string, afterStep: string|null}} [opts.rerunOf] - M14 am1 item 1: only `resumeRun`'s rerun path passes it; kept in the new run's run.json
288
291
  * @param {string|null} [opts.initialGap] - M3 scope item 7 (rerun as a fresh
289
292
  * run): a human's rerun reason, carried as the FIRST ordinary step's
290
293
  * starting gap. Never used by a plain `runFlow` call outside `resumeRun`'s
@@ -294,7 +297,7 @@ export function runStepRalph({ mcpServer, ...opts }: Parameters<typeof runStepTr
294
297
  * epoch ms; defaults to the wall clock. Mirrors `clock` (ISO) so a test
295
298
  * can advance wall time across a park/resume boundary without a real wait.
296
299
  */
297
- export function runFlow({ root, name, runId, sources, catalogue, modelStep, askStep, sendStep, primitives, primitiveReds, clock, businessDate, ceilingUsd, initialGap, fetchPage, runModel, nowMs, }: {
300
+ export function runFlow({ root, name, runId, sources, catalogue, modelStep, askStep, sendStep, primitives, primitiveReds, clock, businessDate, ceilingUsd, initialGap, fetchPage, rerunOf, runModel, nowMs, }: {
298
301
  root: string;
299
302
  name: string;
300
303
  runId: string;
@@ -327,6 +330,7 @@ export function runFlow({ root, name, runId, sources, catalogue, modelStep, askS
327
330
  ok: boolean;
328
331
  red?: string;
329
332
  bytes?: number;
333
+ sha256?: string;
330
334
  }>;
331
335
  primitives?: Record<string, any> | undefined;
332
336
  primitiveReds?: string[] | undefined;
@@ -337,6 +341,11 @@ export function runFlow({ root, name, runId, sources, catalogue, modelStep, askS
337
341
  slot: string;
338
342
  model: string;
339
343
  } | undefined;
344
+ rerunOf?: {
345
+ decision: "rerun";
346
+ words: string;
347
+ afterStep: string | null;
348
+ } | undefined;
340
349
  initialGap?: string | null | undefined;
341
350
  fetchPage?: ((url: string) => Promise<{
342
351
  ok: true;
@@ -372,7 +381,7 @@ export function makeParkingAskStep(): (opts?: any) => Promise<{
372
381
  * @param {string} opts.runId
373
382
  * @param {unknown} opts.catalogue
374
383
  * @param {(executorContext:object, grantedTools:Record<string,any>, stepMeta?:{class:string|null}) => Promise<any>} opts.modelStep
375
- * @param {(target:string, filename:string, content:unknown) => Promise<{ok:boolean, red?:string, bytes?:number}>} opts.sendStep
384
+ * @param {(target:string, filename:string, content:unknown) => Promise<{ok:boolean, red?:string, bytes?:number, sha256?:string}>} opts.sendStep
376
385
  * @param {Record<string, any>} [opts.primitives]
377
386
  * @param {string[]} [opts.primitiveReds] - see `runFlow`'s own.
378
387
  * @param {() => string} [opts.clock]
@@ -394,6 +403,7 @@ export function resumeRun({ root, name, runId, catalogue, modelStep, sendStep, p
394
403
  ok: boolean;
395
404
  red?: string;
396
405
  bytes?: number;
406
+ sha256?: string;
397
407
  }>;
398
408
  primitives?: Record<string, any> | undefined;
399
409
  primitiveReds?: string[] | undefined;
@@ -436,7 +446,7 @@ export function auditSpend(runDir: string): {
436
446
  * @param {string} opts.runId
437
447
  * @param {unknown} opts.catalogue
438
448
  * @param {(executorContext:object, grantedTools:Record<string,any>, stepMeta?:{class:string|null}) => Promise<any>} opts.modelStep
439
- * @param {(target:string, filename:string, content:unknown) => Promise<{ok:boolean, red?:string, bytes?:number}>} opts.sendStep
449
+ * @param {(target:string, filename:string, content:unknown) => Promise<{ok:boolean, red?:string, bytes?:number, sha256?:string}>} opts.sendStep
440
450
  * @param {Record<string, any>} [opts.primitives]
441
451
  * @param {string[]} [opts.primitiveReds]
442
452
  * @param {() => string} [opts.clock]
@@ -456,6 +466,7 @@ export function continueRun({ root, name, runId, catalogue, modelStep, sendStep,
456
466
  ok: boolean;
457
467
  red?: string;
458
468
  bytes?: number;
469
+ sha256?: string;
459
470
  }>;
460
471
  primitives?: Record<string, any> | undefined;
461
472
  primitiveReds?: string[] | undefined;
package/types/send.d.ts CHANGED
@@ -1,12 +1,19 @@
1
+ /**
2
+ * M15 items 3 and am1, am2: the accepted answer as the plain-text file the send writes. `{text}` alone is the text exactly; any other flat object is one
3
+ * `Name words: value` line per field; a list of results is one `## Result k` block per result with one line per value, in the order the answer holds
4
+ * them, then `from the page: "<quote>"`. Never JSON braces, never check marks. What it throws away: a result's keys other than `quote` and `values`.
5
+ * @param {Record<string, any>} content @returns {string}
6
+ */
7
+ export function renderSentMd(content: Record<string, any>): string;
1
8
  /**
2
9
  * @param {string} target - a signed arbiter target, e.g. `file:poc/m0/out`.
3
10
  * @param {string} filename
4
- * @param {unknown} content - JSON-serialised before writing.
11
+ * @param {unknown} content - the accepted artifact; hash-checked as its JSON, written as plain text (`renderSentMd`).
5
12
  * @param {string|null} [acceptedSha256] - the sha256 the human's accept recorded
6
13
  * (`answerAsk`, M4b piece 3). Required: none recorded (an answer written by an
7
14
  * older version, or no accept in this process) refuses by name.
8
15
  * @param {{root?: string, runDir?: string}} [ctx] the flow root and this run's folder, for the destination refusals
9
- * @returns {Promise<{ok:true, path:string, bytes:number} | {ok:false, red:string}>}
16
+ * @returns {Promise<{ok:true, path:string, bytes:number, sha256:string} | {ok:false, red:string}>}
10
17
  */
11
18
  export function sendViaPrimitive(target: string, filename: string, content: unknown, acceptedSha256?: string | null, ctx?: {
12
19
  root?: string;
@@ -15,6 +22,7 @@ export function sendViaPrimitive(target: string, filename: string, content: unkn
15
22
  ok: true;
16
23
  path: string;
17
24
  bytes: number;
25
+ sha256: string;
18
26
  } | {
19
27
  ok: false;
20
28
  red: string;