fwdloop 0.37.0 → 0.39.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 (140) hide show
  1. package/README.md +5 -19
  2. package/bin/fwdloop +51 -29
  3. package/package.json +1 -1
  4. package/src/ask.js +70 -148
  5. package/src/audit-fold.js +5 -4
  6. package/src/auditchecks.js +6 -4
  7. package/src/authoring.js +36 -64
  8. package/src/blockasks.js +2 -1
  9. package/src/blockassemble.js +7 -9
  10. package/src/blockdraft.js +2 -2
  11. package/src/blockpick.js +5 -5
  12. package/src/books.js +217 -12
  13. package/src/checkblock.js +25 -55
  14. package/src/checked.js +2 -3
  15. package/src/checklistsign.js +26 -5
  16. package/src/checklook.js +3 -1
  17. package/src/checkpick.js +5 -76
  18. package/src/cited-source.js +4 -4
  19. package/src/citedcheck.js +6 -11
  20. package/src/citedwords.js +9 -8
  21. package/src/closers.js +9 -6
  22. package/src/declaration.js +22 -55
  23. package/src/diary.js +23 -1
  24. package/src/draft-steps.js +11 -1
  25. package/src/drafter.js +28 -23
  26. package/src/draftfiles.js +127 -0
  27. package/src/draftspend.js +165 -17
  28. package/src/flow.js +42 -87
  29. package/src/flowmodel.js +1 -1
  30. package/src/index.js +3 -2
  31. package/src/inside.js +86 -0
  32. package/src/isrec.js +2 -0
  33. package/src/jsonl-append.js +33 -1
  34. package/src/learn.js +1 -1
  35. package/src/learnstore.js +20 -22
  36. package/src/line-checks.js +2 -3
  37. package/src/liveness.js +3 -0
  38. package/src/mcp-use.js +8 -9
  39. package/src/memo.js +13 -16
  40. package/src/minrule.js +16 -0
  41. package/src/model-step.js +3 -3
  42. package/src/page-words.js +8 -0
  43. package/src/pageask.js +8 -3
  44. package/src/pagebits.js +8 -1
  45. package/src/pagedropwords.js +1 -1
  46. package/src/pagerules.js +6 -3
  47. package/src/panel/author.js +121 -78
  48. package/src/panel/authorcard.js +21 -8
  49. package/src/panel/authorflows.js +3 -3
  50. package/src/panel/authorresume.js +3 -3
  51. package/src/panel/authorstart.js +15 -16
  52. package/src/panel/authortrigger.js +43 -70
  53. package/src/panel/data.js +125 -168
  54. package/src/panel/index.html +154 -63
  55. package/src/panel/jobgrid.js +3 -7
  56. package/src/panel/result.js +7 -10
  57. package/src/panel/resume.js +4 -3
  58. package/src/panel/scheduler.js +9 -9
  59. package/src/panel/server.js +8 -4
  60. package/src/panel/spawn.js +22 -11
  61. package/src/panel/tickets.js +2 -2
  62. package/src/pickrecord.js +51 -31
  63. package/src/placerule.js +3 -4
  64. package/src/planrebuild.js +19 -19
  65. package/src/primitives.js +1 -1
  66. package/src/provider.js +1 -1
  67. package/src/reasons.js +25 -0
  68. package/src/report.js +2 -1
  69. package/src/runfile.js +26 -2
  70. package/src/runner.js +57 -105
  71. package/src/runvalues.js +47 -24
  72. package/src/schedule-choices.js +41 -0
  73. package/src/schedule-shape.js +39 -0
  74. package/src/schedule.js +9 -8
  75. package/src/setup.js +20 -36
  76. package/src/shaperows.js +2 -2
  77. package/src/sheet-record.js +1 -2
  78. package/src/sheetblock.js +3 -4
  79. package/src/sheetbuild.js +5 -5
  80. package/src/sheetchecks.js +1 -2
  81. package/src/sheetclaims.js +1 -2
  82. package/src/sheetoffer.js +1 -1
  83. package/src/sheetrun.js +5 -7
  84. package/src/summary-words.js +2 -1
  85. package/src/thinking.js +5 -2
  86. package/src/ticketrows.js +8 -30
  87. package/src/trigger-clock.js +9 -23
  88. package/src/trigger-files.js +30 -22
  89. package/src/trigger-tickets.js +15 -14
  90. package/src/try-checks.js +2 -1
  91. package/src/types.js +2 -0
  92. package/types/ask.d.ts +25 -20
  93. package/types/authoring.d.ts +8 -42
  94. package/types/blockassemble.d.ts +0 -1
  95. package/types/blockpick.d.ts +1 -1
  96. package/types/books.d.ts +256 -4
  97. package/types/checkblock.d.ts +2 -25
  98. package/types/checklist.d.ts +3 -3
  99. package/types/checklistsign.d.ts +7 -0
  100. package/types/checkpick.d.ts +0 -21
  101. package/types/citedwords.d.ts +7 -4
  102. package/types/closers.d.ts +1 -0
  103. package/types/declaration.d.ts +4 -14
  104. package/types/diary.d.ts +14 -1
  105. package/types/draft-steps.d.ts +7 -0
  106. package/types/drafter.d.ts +3 -2
  107. package/types/draftfiles.d.ts +89 -0
  108. package/types/draftspend.d.ts +74 -0
  109. package/types/flow.d.ts +32 -54
  110. package/types/index.d.ts +3 -3
  111. package/types/inside.d.ts +58 -0
  112. package/types/isrec.d.ts +1 -0
  113. package/types/jsonl-append.d.ts +20 -0
  114. package/types/learnstore.d.ts +0 -2
  115. package/types/liveness.d.ts +1 -0
  116. package/types/minrule.d.ts +6 -0
  117. package/types/page-words.d.ts +6 -0
  118. package/types/pageask.d.ts +2 -0
  119. package/types/pagebits.d.ts +3 -0
  120. package/types/pagerules.d.ts +1 -0
  121. package/types/panel/author.d.ts +7 -3
  122. package/types/panel/authorcard.d.ts +0 -6
  123. package/types/panel/authorflows.d.ts +4 -4
  124. package/types/panel/authortrigger.d.ts +16 -2
  125. package/types/panel/data.d.ts +36 -11
  126. package/types/panel/spawn.d.ts +18 -2
  127. package/types/pickrecord.d.ts +29 -0
  128. package/types/reasons.d.ts +23 -0
  129. package/types/runfile.d.ts +14 -0
  130. package/types/runner.d.ts +6 -38
  131. package/types/runvalues.d.ts +17 -2
  132. package/types/schedule-choices.d.ts +9 -0
  133. package/types/schedule-shape.d.ts +15 -0
  134. package/types/sheetbuild.d.ts +1 -1
  135. package/types/sheetclaims.d.ts +0 -1
  136. package/types/thinking.d.ts +1 -0
  137. package/types/ticketrows.d.ts +0 -9
  138. package/types/trigger-clock.d.ts +3 -2
  139. package/types/trigger-files.d.ts +15 -4
  140. package/types/types.d.ts +8 -0
@@ -0,0 +1,58 @@
1
+ /**
2
+ * F48 round 3 (docs/logs/FINDINGS.md): the ONE mechanism every book reader
3
+ * in src/ and bin/ routes through to read a file that lives inside a run
4
+ * dir or flow dir — closing the symlink-escape class at the source instead
5
+ * of patching each reader a second time. `resolveInside(baseDir, relPath)`
6
+ * requires the target to both (a) not itself be a symlink and (b) realpath
7
+ * to somewhere inside `realpath(baseDir)` — the second check alone also
8
+ * catches a symlinked ANCESTOR directory partway down `relPath` (e.g.
9
+ * `asks/` itself replaced by a symlink to an outside directory), the same
10
+ * shape `readFlow`'s own `runs/` check and `resolveRunDir` already apply one
11
+ * level up. A path that does not exist yet is reported as `missing: true`
12
+ * (never a red) so every existing caller keeps its own "not written yet"
13
+ * behaviour unchanged.
14
+ *
15
+ * @param {string} baseDir
16
+ * @param {string} relPath
17
+ * @returns {{ok:true, full:string}|{ok:false, missing:true}|{ok:false, missing:false, red:string}}
18
+ */
19
+ export function resolveInside(baseDir: string, relPath: string): {
20
+ ok: true;
21
+ full: string;
22
+ } | {
23
+ ok: false;
24
+ missing: true;
25
+ } | {
26
+ ok: false;
27
+ missing: false;
28
+ red: string;
29
+ };
30
+ /**
31
+ * `resolveInside` plus the actual read — every raw-text book reader's one
32
+ * gateway. Same result shape as `resolveInside`, plus `{ok:true, text}`.
33
+ * @param {string} baseDir
34
+ * @param {string} relPath
35
+ * @returns {{ok:true, text:string}|{ok:false, missing:true}|{ok:false, missing:false, red:string}}
36
+ */
37
+ export function readFileInside(baseDir: string, relPath: string): {
38
+ ok: true;
39
+ text: string;
40
+ } | {
41
+ ok: false;
42
+ missing: true;
43
+ } | {
44
+ ok: false;
45
+ missing: false;
46
+ red: string;
47
+ };
48
+ /**
49
+ * `readdirSync` guarded the same way: refuses (returns `[]`) when `relDir`
50
+ * itself is a symlink or resolves outside `baseDir`, and skips (never
51
+ * follows) any individual entry that is itself a symlink — a directory
52
+ * listing must never hand a caller a name that, joined back onto `relDir`,
53
+ * would escape `baseDir`. `[]` when `relDir` doesn't exist.
54
+ * @param {string} baseDir
55
+ * @param {string} relDir
56
+ * @returns {string[]}
57
+ */
58
+ export function readdirInside(baseDir: string, relDir: string): string[];
@@ -0,0 +1 @@
1
+ export function isRec(v: unknown): boolean;
@@ -4,3 +4,23 @@ export function ledgerText(file: string): string;
4
4
  export function appendRow(file: string, row: unknown, options?: {
5
5
  mode?: number;
6
6
  }): void;
7
+ /** M20 am3 item 12: the ONE tolerant JSONL parse: every line of the text that parses, in order; a blank, torn or unparseable line is skipped. @param {string} text @returns {any[]} */
8
+ export function parseJsonl(text: string): any[];
9
+ /**
10
+ * The ONE reader of a trigger ledger (the files ledger and the schedule ledger): every row on disk that parses, oldest first; a missing file is no rows;
11
+ * a line a crash tore mid-append is skipped (it counts as not written; `appendTriggerLedger` starts each append on a fresh line, so it never glues onto the next row).
12
+ * @param {string} file @param {string} [sig] M9 am20: only the rows of that schedule signing (the one schedule ledger carries every signing's rows); absent = every row
13
+ * @returns {any[]}
14
+ */
15
+ export function readTriggerLedger(file: string, sig?: string): any[];
16
+ /**
17
+ * The ONE appender of a trigger ledger: write-once by id within a signing (a second row with the same id is not written). `sig` is stamped on the row.
18
+ * @param {string} file @param {{id: string, [k: string]: any}} row @param {string} [sig] @param {{throwIfWritten?: boolean}} [o] `throwIfWritten`: a row already on disk is an error, not `false`
19
+ * @returns {boolean} written
20
+ */
21
+ export function appendTriggerLedger(file: string, row: {
22
+ id: string;
23
+ [k: string]: any;
24
+ }, sig?: string, { throwIfWritten }?: {
25
+ throwIfWritten?: boolean;
26
+ }): boolean;
@@ -163,5 +163,3 @@ export function hintsForRun({ home, spec, specHash, now }: {
163
163
  text: string;
164
164
  ids: string[];
165
165
  } | null;
166
- /** M8 am4 item 2: a run waiting at an ask has not ended ('paused', or a Stop whose set-aside failed). ONE decider: the runner's run-end tally and the seed both read it. */
167
- export const NOT_A_RUN_END: Set<string>;
@@ -69,6 +69,7 @@ export function readResumeLock(runDir: string): {
69
69
  export function booksFresh(runDir: string, nowMs?: number): boolean;
70
70
  /** The words the runner's refusal uses for a lock it cannot clear; the panel reads the same constant (M4c amendment 3 (e)). */
71
71
  export const LOCK_NO_HOLDER: "with no recorded holder";
72
+ export function lockMayBeHeld(state: unknown): boolean;
72
73
  declare namespace REAL_PROC {
73
74
  function cmdline(pid: number): string;
74
75
  function stat(pid: number): string;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @param {string} prose the job prose `fwdloop draft` reads
3
+ * @returns {string|null} the refusal words, or null when the prose carries at least one `~` rule. Prose the reader cannot parse is not this gate's to refuse (the drafter's own red wins).
4
+ */
5
+ export function minRuleRefusal(prose: string): string | null;
6
+ export const MIN_RULE_REFUSAL: "Add at least one rule (~) for this job \u2014 for example what the result must include, or what must stay true.";
@@ -0,0 +1,6 @@
1
+ export function pageWords(): {
2
+ tags: Record<string, string>;
3
+ reasonDecisions: string[];
4
+ reviseRunning: string[];
5
+ notGreen: string[];
6
+ };
@@ -71,3 +71,5 @@ 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 isShapeAsk(ask: unknown): boolean;
75
+ export function HOW_TO_ANSWER(line: number, agree: boolean): string;
@@ -26,6 +26,9 @@ export const MAX_CURRENCIES: 3;
26
26
  export const MAX_UNITS: 10;
27
27
  export const MAX_UNIT_CHARS: 100;
28
28
  export function asList(v: unknown): string[];
29
+ export function isPhraseShape(shape: unknown): boolean;
30
+ export function isLegalCount(c: any): boolean;
31
+ export function isAmountShape(shape: unknown): boolean;
29
32
  export function boundOk(shape: string, v: unknown): boolean;
30
33
  export function squash(t: string): string;
31
34
  export function boundInWords(b: unknown, said: string): boolean;
@@ -48,6 +48,7 @@ export function applyPageRules(text: string, mapping: PageMap, jobLines: {
48
48
  facts: KeptFact[];
49
49
  dropped: Dropped[];
50
50
  };
51
+ export function canReadLimit(shape: unknown): shape is "money" | "time";
51
52
  export function linesOf(text: string): string[];
52
53
  /**
53
54
  * what a `~` rule means as a limit (PRD v1.107 Part 5b): the same shape as a signed fact rule
@@ -201,7 +201,7 @@ export function createAuthor(opts: {
201
201
  flowHash: string;
202
202
  sig: string | null;
203
203
  armed: boolean;
204
- armedAt: number | null;
204
+ armedAt: any;
205
205
  nextSlotMs: number | null;
206
206
  lastOutcome: any;
207
207
  hasGreenRun: boolean;
@@ -223,7 +223,7 @@ export function createAuthor(opts: {
223
223
  flowHash: string;
224
224
  sig: string | null;
225
225
  armed: boolean;
226
- armedAt: number | null;
226
+ armedAt: any;
227
227
  nextSlotMs: number | null;
228
228
  lastOutcome: any;
229
229
  hasGreenRun: boolean;
@@ -450,7 +450,7 @@ export function createAuthor(opts: {
450
450
  body: any;
451
451
  };
452
452
  /**
453
- * `POST /api/author/:id/abandon`: stop the child (by its recorded pid, only after `isFwdloopAlive` says it is ours),
453
+ * `POST /api/author/:id/abandon`: stop the child (by its recorded pid, only after `childState` says it is ours),
454
454
  * confirm it is gone, then write `abandoned.json`. No further model call; the spend already booked stays booked.
455
455
  * @param {string} id
456
456
  */
@@ -485,4 +485,8 @@ export function createAuthor(opts: {
485
485
  };
486
486
  /** Up to 2 revises per draft (amendment 14 item 3); a revise is used once its `draft-<n>/` exists (a refusal at $0 makes none). */
487
487
  export const MAX_REVISES: 2;
488
+ /** M20 am8a: the phases in which a revise or the redraft after the human's answers is running over an existing plan (a first draft is `drafting`: another refusal). The panel hands the list to the page. */
489
+ export const REVISE_PHASES: readonly string[];
490
+ /** M20 am8a: the phases where the draft ended not green, red or stopped (the card is open to fix and draft again). The panel hands the list to the page. */
491
+ export const NOT_GREEN_PHASES: readonly string[];
488
492
  import { thinkingSupport as bareagentThinkingSupport } from '../thinking.js';
@@ -110,13 +110,7 @@ export function parseInputLines(text: string): {
110
110
  */
111
111
  export function cardFields(body: any): {
112
112
  schedule?: {
113
- kind: string;
114
- hour?: undefined;
115
- minute?: undefined;
116
- } | {
117
113
  kind: any;
118
- hour: any;
119
- minute: any;
120
114
  } | undefined;
121
115
  flowType?: string | undefined;
122
116
  mcp?: string | undefined;
@@ -95,7 +95,7 @@ export function createFlowsDoor(opts: {
95
95
  } | {
96
96
  ok: boolean;
97
97
  card: {
98
- flowType?: "tickets" | "mcp" | "plain" | undefined;
98
+ flowType?: "mcp" | "plain" | "tickets" | undefined;
99
99
  mcp?: any;
100
100
  job: string;
101
101
  inputs: string;
@@ -123,7 +123,7 @@ export function createFlowsDoor(opts: {
123
123
  roles: any;
124
124
  pages: Record<string, string>;
125
125
  tickets: string[];
126
- flowType: "tickets" | "mcp" | "plain";
126
+ flowType: "mcp" | "plain" | "tickets";
127
127
  mcp: any;
128
128
  nextRunId: string;
129
129
  lastRunId: string | null;
@@ -188,7 +188,7 @@ export function createFlowsDoor(opts: {
188
188
  } | {
189
189
  ok: boolean;
190
190
  card: {
191
- flowType?: "tickets" | "mcp" | "plain" | undefined;
191
+ flowType?: "mcp" | "plain" | "tickets" | undefined;
192
192
  mcp?: any;
193
193
  job: string;
194
194
  inputs: string;
@@ -216,7 +216,7 @@ export function createFlowsDoor(opts: {
216
216
  roles: any;
217
217
  pages: Record<string, string>;
218
218
  tickets: string[];
219
- flowType: "tickets" | "mcp" | "plain";
219
+ flowType: "mcp" | "plain" | "tickets";
220
220
  mcp: any;
221
221
  nextRunId: string;
222
222
  lastRunId: string | null;
@@ -2,6 +2,17 @@
2
2
  export function readOutcomes(flowDir: string): any[];
3
3
  /** The ONE writer of `triggers.jsonl`: append-only, one line per fire outcome. @param {string} flowDir @param {Record<string, any>} row */
4
4
  export function appendOutcome(flowDir: string, row: Record<string, any>): void;
5
+ /**
6
+ * M9 item 1 and 2: the runs that count as "one green run" for this job, in run-name order. THE decider: a passed run counts when the job it ran (its own
7
+ * `job/` copy) is the job as it is now (prose and declaration, byte for byte: a schedule is its own file, so setting one never changes the job).
8
+ * A run from before runs kept a job copy has none to compare, so it counts only when its history row's signature is the job's current one.
9
+ * @param {string} flowDir @returns {Generator<{runId: string, runDir: string, at: string}>}
10
+ */
11
+ export function greenRuns(flowDir: string): Generator<{
12
+ runId: string;
13
+ runDir: string;
14
+ at: string;
15
+ }>;
5
16
  /** M9 item 1 and 2: does this job have "one green run"? @param {string} flowDir */
6
17
  export function hasGreenRunForJob(flowDir: string): boolean;
7
18
  /**
@@ -239,7 +250,7 @@ export function createTriggerDoor(opts: {
239
250
  flowHash: string;
240
251
  sig: string | null;
241
252
  armed: boolean;
242
- armedAt: number | null;
253
+ armedAt: any;
243
254
  nextSlotMs: number | null;
244
255
  lastOutcome: any;
245
256
  hasGreenRun: boolean;
@@ -267,7 +278,7 @@ export function createTriggerDoor(opts: {
267
278
  flowHash: string;
268
279
  sig: string | null;
269
280
  armed: boolean;
270
- armedAt: number | null;
281
+ armedAt: any;
271
282
  nextSlotMs: number | null;
272
283
  lastOutcome: any;
273
284
  hasGreenRun: boolean;
@@ -296,3 +307,6 @@ export const TICKET_LOOK_TOOL: "list_issues";
296
307
  export const NO_GREEN_SAY: "This job has not had a good run yet. Run it once by hand and get it right first; then you can set when it runs. Nothing was changed.";
297
308
  export type Trigger = import("../trigger-line.js").Trigger;
298
309
  export type Schedule = import("../schedule.js").Schedule;
310
+ export type FileTrigger = Extract<Trigger, {
311
+ kind: "file-updated" | "new-file";
312
+ }>;
@@ -40,17 +40,16 @@ export function resolveFlowDir(root: string, flowName: string): {
40
40
  */
41
41
  export function hasConsumedAnswer(runDir: string, askId: string | null): boolean;
42
42
  /**
43
- * M4b piece 2: a SAVED, not-yet-consumed answer — `answer.json` (what
44
- * `answerAsk` writes; the resume consumes it by renaming it away, F44). Read
45
- * through `readFileInside` (a symlinked file is "none"). `null` when there is
46
- * none or it is unreadable/unparseable or names no askId.
43
+ * M4b piece 2: a SAVED, not-yet-consumed answer, as the panel shows it: `readSavedAnswer` (src/books.js, the one reader) read for an answer that names an ask.
44
+ * `null` when there is none or it is unreadable, unparseable or names no askId. `broken` is the reader's own field (M20 am3b item 1).
47
45
  * @param {string} runDir
48
- * @returns {{askId: string, decision: string|null, answeredAt: string|null}|null}
46
+ * @returns {{askId: string, decision: string|null, answeredAt: string|null, broken: boolean}|null}
49
47
  */
50
- export function readSavedAnswer(runDir: string): {
48
+ export function savedAnswerOf(runDir: string): {
51
49
  askId: string;
52
50
  decision: string | null;
53
51
  answeredAt: string | null;
52
+ broken: boolean;
54
53
  } | null;
55
54
  /**
56
55
  * M4b amendment 1 scope 2: the ONE derivation of "answer saved, resume not
@@ -62,7 +61,7 @@ export function readSavedAnswer(runDir: string): {
62
61
  * answer for that ask that was NOT saved in time, once the deadline has passed, is not a resumable answer: it reads
63
62
  * as none, so the ask is expired and offers the reopen (M4c-fix amendment 1 (b)). One with no readable time, before
64
63
  * the deadline, reads `broken` (amendment 1 (a)).
65
- * @param {{savedAnswer: {askId:string, decision:string|null, answeredAt?:string|null}|null, attempt: any, ask?: any}} ctx
64
+ * @param {{savedAnswer: {askId:string, decision:string|null, answeredAt?:string|null, broken?: boolean}|null, attempt: any, ask?: any}} ctx
66
65
  * @returns {{state: 'starting'|'not-started'|'broken'|'took-over', askId: string|null, tries: number|null, maxTries: number|null, reason: string|null, label: string}|null}
67
66
  */
68
67
  export function deriveResumeState({ savedAnswer: savedOnDisk, attempt, ask }: {
@@ -70,6 +69,7 @@ export function deriveResumeState({ savedAnswer: savedOnDisk, attempt, ask }: {
70
69
  askId: string;
71
70
  decision: string | null;
72
71
  answeredAt?: string | null;
72
+ broken?: boolean;
73
73
  } | null;
74
74
  attempt: any;
75
75
  ask?: any;
@@ -86,10 +86,13 @@ export function deriveResumeState({ savedAnswer: savedOnDisk, attempt, ask }: {
86
86
  * opens with the word ("stuck — …") or is the word itself ("passed") loses that repeat, so it is never said twice.
87
87
  * `noWord`: a run the human ended on purpose with rerun wears `[✗]` but is never called "failed" (M4b amendment 3),
88
88
  * so it shows its plain line alone.
89
- * @param {string} glyph a `computeGlyph` sign @param {string} label its plain line @param {boolean} [noWord]
89
+ * @param {string} glyph a `computeGlyph` sign @param {string} label its plain line @param {boolean} [noWord] @param {{outcome: string|null|undefined, resumable: boolean}|null} [ending] the run's end row outcome and whether it can be continued
90
90
  * @returns {{word: string|null, line: string|null}}
91
91
  */
92
- export function signParts(glyph: string, label: string, noWord?: boolean): {
92
+ export function signParts(glyph: string, label: string, noWord?: boolean, ending?: {
93
+ outcome: string | null | undefined;
94
+ resumable: boolean;
95
+ } | null): {
93
96
  word: string | null;
94
97
  line: string | null;
95
98
  };
@@ -316,7 +319,22 @@ export function deriveAuditToolsPhrase(row: any): string | null;
316
319
  * @returns {string|null}
317
320
  */
318
321
  export function deriveAuditAtWhy(row: any): string | null;
319
- export function isBlockedVerdict(verdict: any): boolean;
322
+ /**
323
+ * hamr's 2026-09-27 exit-check review #2: the Audit tab's Blocked filter —
324
+ * ONE server-side function naming exactly which verdicts count as "did not
325
+ * pass", derived strictly from a row's own `verdict` string (never a second,
326
+ * client-side guess). Blocked: `not-done`, `red` (a mechanical close miss OR
327
+ * a human's own redo on a hitl step — both are "this attempt did not
328
+ * pass"), `refused` (a blank redo/rerun reason), `ask-timeout` and
329
+ * `ask-expired` (the human never answered in time), `cap-halt`,
330
+ * `provider-red`, `pricing-red`, `close-casualty` (every other halt shape
331
+ * `src/runner.js` records). NOT blocked: `green`/`hitl` (passed), `paused`
332
+ * (still open — waiting, not yet failed), `stale-answer-ignored` (a book
333
+ * hygiene note about a late answer, not an attempt outcome).
334
+ * @param {string|null|undefined} verdict
335
+ * @returns {boolean}
336
+ */
337
+ export function isBlockedVerdict(verdict: string | null | undefined): boolean;
320
338
  /**
321
339
  * One mark per try, in try order — mirrors `computeTryCount`'s own pairing
322
340
  * exactly (a `hitl` step's `paused` row plus its next resolving row is ONE
@@ -582,6 +600,12 @@ export function listScheduled({ root, triggerRead, now, home, rows, }: {
582
600
  words: string;
583
601
  runId: string | null;
584
602
  }[];
603
+ /**
604
+ * M20 am1 item 8: the Run tab's NOW row, "AI working · M:SS", only while the run is live (`[▶]`, no end row) and a model step's try is running: the newest
605
+ * `try-start` row has no audit row written at or after it. Anything else is null (nothing is made up between tries). The time moves in 30 s steps (`stepped`).
606
+ * @param {any} ctx `loadRunContext`'s result @param {string} glyph `computeGlyph`'s sign @param {number} nowMs @returns {string|null}
607
+ */
608
+ export function nowOf(ctx: any, glyph: string, nowMs: number): string | null;
585
609
  /**
586
610
  * `GET /api/runs/:flow/:runId` — the Run tab (M4a scope item 2): the step
587
611
  * map from `declaration.steps`, step cards -> attempts from `audit.jsonl`
@@ -787,7 +811,7 @@ export function getJobGrid({ root, flow, catalogue, now, }: {
787
811
  spentUsd: number | null;
788
812
  spentComplete: boolean;
789
813
  };
790
- flowType: "tickets" | "mcp" | "plain" | null;
814
+ flowType: "mcp" | "plain" | "tickets" | null;
791
815
  } | null;
792
816
  /**
793
817
  * `GET /api/runs/:flow/:runId/download?i=<n>` (M10 am4): one saved file, or why not.
@@ -927,6 +951,7 @@ export function inboxOpenCount(rows: any[]): number;
927
951
  /** What the `resume` field says when the panel has no attempt record for a run
928
952
  * (it restarted since the answer was saved) — said so, never blank. */
929
953
  export const RESUME_REASON_UNKNOWN: "reason unknown: the panel restarted, so it has no record of the resume attempt";
954
+ export function answerPickedUp(resume: any, askId: unknown): boolean;
930
955
  export const WAITING_LABEL: "waiting on you (parked, unanswered)";
931
956
  export const STUCK_LABEL: "stuck \u2014 your answer is saved; the run stopped before using it";
932
957
  export const STUCK_LOCK_LABEL: "stuck \u2014 an old resume lock is in the way";
@@ -14,8 +14,24 @@ export function spawnDetached({ bin, argv, env, logPath, }: {
14
14
  * @param {string} dir @param {import('node:child_process').ChildProcess} child
15
15
  */
16
16
  export function writePidFile(dir: string, child: import("node:child_process").ChildProcess): void;
17
- /** One JSON file of a panel folder through the one safe gateway; null when missing, unreadable or not an object. @param {string} dir @param {string} rel */
18
- export function readJsonFile(dir: string, rel: string): any;
17
+ /**
18
+ * M20 am3 item 8: the ONE owner of "is the draft/start child alive": the child recorded in `<dir>/pid.json` (null when none is
19
+ * recorded) and whether it is ours and running now: true / false, or null when it cannot be told (no /proc). `childRunning` and the
20
+ * draft door's abandon both ask it.
21
+ * @param {string} dir
22
+ * @returns {{pid: number, procStart: string|null, startedAt: unknown, alive: boolean|null}|null}
23
+ */
24
+ export function childState(dir: string): {
25
+ pid: number;
26
+ procStart: string | null;
27
+ startedAt: unknown;
28
+ alive: boolean | null;
29
+ } | null;
30
+ /** The same question again for a child `childState` returned (the abandon loop asks it after each signal). @param {{pid: number, procStart: string|null}} child @returns {boolean|null} */
31
+ export function childAlive(child: {
32
+ pid: number;
33
+ procStart: string | null;
34
+ }): boolean | null;
19
35
  /**
20
36
  * Is the child recorded in `<dir>/pid.json` running? true / false, never null: no pid.json = nothing known to be running =
21
37
  * false; a liveness that cannot be told (no /proc) reads as running only while pid.json is fresh (M4c's rule).
@@ -132,6 +132,35 @@ export function columnsOnLines(entries: {
132
132
  word: string;
133
133
  column: string;
134
134
  }[];
135
+ /**
136
+ * M20 am3e item 19: the record's `kept` list, the ONE reader (the plan card, the setup row and the sign-time card check all ask it). `kept` is the list as written, or null
137
+ * when there is none to read (no file, refused by the gateway, not a JSON object, no list). `torn` tells an unreadable record from an empty one: the file was read and
138
+ * is not JSON. The sign-time card check skips on a torn record; the other two read it as no list.
139
+ * @param {string} dir the folder that holds the plan folder @param {string} [rel] `draft`, `draft-<n>` or `.` (the plan folder itself)
140
+ * @returns {{kept: any[]|null, torn: boolean}}
141
+ */
142
+ export function readKept(dir: string, rel?: string): {
143
+ kept: any[] | null;
144
+ torn: boolean;
145
+ };
146
+ /**
147
+ * M20 am4: the counts the person switched on with Add, from the plan's `rowChoices` (the entries `readRowChoices` gives, or the block's own `choicesRecord()`): a set of
148
+ * `<line>:min:<n>` / `<line>:max:<n>` strings, one per number of an Added `count.<min>-<max>` row, the line found by its words as the record ties it. The count check
149
+ * (src/citedwords.js `countReds`) reads a number in this set as said: the Add says it.
150
+ * @param {{lineWords: string, occurrence: number, tail: string, choice: string}[]|null|undefined} entries @param {{n: number, text: string}[]} lines @returns {Set<string>}
151
+ */
152
+ export function addedCountsOf(entries: {
153
+ lineWords: string;
154
+ occurrence: number;
155
+ tail: string;
156
+ choice: string;
157
+ }[] | null | undefined, lines: {
158
+ n: number;
159
+ text: string;
160
+ }[]): Set<string>;
161
+ /** M20 am8: the one list of a person's row choices on the plan card, and the one question "is this a legal Drop or Add choice" (the row-edit door, the record's reader and the check block ask it) */
162
+ export const ROW_CHOICES: readonly string[];
163
+ export function isRowChoice(choice: unknown): boolean;
135
164
  /** the record's file, inside a drafting folder only (never a run folder) */
136
165
  export const RECORD_FILE: "picks-record.json";
137
166
  /** the exact words a kept pick is marked with in the draft log, the Audit and the plan card (M10 am17 (6)) */
@@ -0,0 +1,23 @@
1
+ /** the plain reasons code gives, in one place (the card, the Job tab and the Audit read them from the row) */
2
+ export const REASON: Readonly<{
3
+ left: "You chose to leave it Not checked, so you judge it at Accept.";
4
+ nothingOnPage: "Your own words are on the line; the machine has no check for them, so you judge it at Accept.";
5
+ noRule: "No rule can check this, so you judge it at Accept.";
6
+ waitingPick: "waiting for your answer on the proposed check";
7
+ waitingReading: "waiting for your answer on the reading";
8
+ onePerLine: "this line finds facts, so it has no text to quote";
9
+ manyInputs: "the job has more than one input and code cannot pick which one the claims quote";
10
+ oneSidedTime: "a time limit the AI proposes must be a range, so you judge it at Accept.";
11
+ countNeedsFact: "a result count needs a fact to count; this line has none";
12
+ countNeedsSuggested: "a result count needs a fact to count; add the suggested fact on this line to count its results";
13
+ lookNoWords: "the page does not hold the words of the look's fact for this rule";
14
+ afterLast: "no more tries: Start over (rows are never changed by the AI after the last try)";
15
+ noPick: "No check was picked for it, so you judge it at Accept.";
16
+ itemCountByRule: "your rule on this line sets the item count";
17
+ negated: "it says what is not needed, so there is nothing to check";
18
+ dropped: "You dropped it.";
19
+ suggested: "Suggested: not in your job, so it is not checked unless you add it.";
20
+ sheetLine: "this line reads a sheet and its rules are checked by the sheet checks, so a row edit about it is not used";
21
+ sheetFacts: "this line reads a sheet, so it is checked by its sheet checks and not by page facts";
22
+ columnRule: "this rule only names a column; the agent's checks on this line use it";
23
+ }>;
@@ -10,6 +10,11 @@ export function readRunRecord(runDir: string | null): {
10
10
  code: "missing" | "unreadable" | "invalid";
11
11
  red: string;
12
12
  };
13
+ /**
14
+ * M20 am3 item 12: the ONE test for "this run began as a rerun": the human's words its `run.json` carries (`rerun.decision` is `rerun` and
15
+ * `rerun.words` is a string), or null. The Audit's first step and the carry memo ask it. @param {string|null} runDir @returns {string|null}
16
+ */
17
+ export function readRerunWords(runDir: string | null): string | null;
13
18
  /**
14
19
  * M4d am26: the run's OWN record of the box (`thinking` in `<run>/run.json`) and nothing else: `true`/`false`, or `null` when the run has none (a run from before am25).
15
20
  * An unreadable record is box off, as `readJobThinking` has always read it. @param {string|null} runDir @returns {boolean|null}
@@ -29,6 +34,12 @@ export function readRunInputs(runDir: string | null): {
29
34
  code: "missing" | "unreadable" | "invalid";
30
35
  red: string;
31
36
  };
37
+ /**
38
+ * M20 am3e item 16: the place-rule rows the run recorded at its start (`placeRules.rows`), or null when there are none to read (no record, a refused or torn file,
39
+ * no `placeRules` section, rows that are not a list). Each caller maps null to its own none: the carry-forward reads it as no rows, a resume refuses by name.
40
+ * @param {string|null} runDir @returns {any[]|null}
41
+ */
42
+ export function readPlaceRows(runDir: string | null): any[] | null;
32
43
  /**
33
44
  * 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
45
  * 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
@@ -53,3 +64,6 @@ export function writeRunStart(runDir: string, { model, thinking, inputs, rerun,
53
64
  }): void;
54
65
  /** the file's name in the run's folder */
55
66
  export const RUN_FILE: "run.json";
67
+ /** the folder inside a run that holds the frozen copy of each input */
68
+ export const INPUTS_DIR: "inputs";
69
+ export function frozenRel(name: string): string;
package/types/runner.d.ts CHANGED
@@ -12,23 +12,6 @@ export function readStopRequest(runDir: string, now?: () => string): {
12
12
  } | null;
13
13
  /** Is a stop pending for this run? (read-only) @param {string} runDir */
14
14
  export function stopPending(runDir: string): boolean;
15
- /** The one reader of halt.json: `{ok:true, halt}`, `{ok:false, missing:true}` (not resumable), or `{ok:false, red}`. @param {string} runDir */
16
- export function readHaltRecord(runDir: string): {
17
- ok: boolean;
18
- missing: boolean;
19
- red?: undefined;
20
- halt?: undefined;
21
- } | {
22
- ok: boolean;
23
- red: string;
24
- missing?: undefined;
25
- halt?: undefined;
26
- } | {
27
- ok: boolean;
28
- halt: any;
29
- missing?: undefined;
30
- red?: undefined;
31
- };
32
15
  /** @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
16
  export function buildExecutorContext(opts: {
34
17
  goal: string;
@@ -400,8 +383,7 @@ export function runFlow({ root, name, runId, sources, catalogue, modelStep, askS
400
383
  nowMs?: (() => number) | undefined;
401
384
  }): Promise<any>;
402
385
  /** An ask step that never waits — it immediately tells the fold to park.
403
- * The counterpart to `makeFileAskStep`'s in-process poll (M2 scope item 6);
404
- * a caller wanting park-and-exit behaviour from a FRESH `runFlow` call
386
+ * A caller wanting park-and-exit behaviour from a FRESH `runFlow` call
405
387
  * passes this (or an equivalent) as `askStep`.
406
388
  * @returns {(opts?: any) => Promise<{decision: 'park'}>} */
407
389
  export function makeParkingAskStep(): (opts?: any) => Promise<{
@@ -538,23 +520,6 @@ export function stopParkedRun({ root, name, runId, catalogue, clock, nowMs, }: {
538
520
  clock?: (() => string) | undefined;
539
521
  nowMs?: (() => number) | undefined;
540
522
  }): Promise<any>;
541
- /**
542
- * `writeLog`'s own sibling reader (M4a piece 2, docs/wiki/the-module-
543
- * ladder.md M4a scope item 2: "one reader per book") — `null` when the run
544
- * hasn't reached an exit path yet (still running, or parked before any
545
- * halt/complete), or the file is present but not valid JSON (a torn write),
546
- * never a thrown error.
547
- * @param {string} runDir
548
- * @returns {any|null}
549
- */
550
- export function readLog(runDir: string): any | null;
551
- /**
552
- * `state.json`'s own sibling reader (same rule as {@link readLog}) — `null`
553
- * when the run has never parked, or the file is present but not valid JSON.
554
- * @param {string} runDir
555
- * @returns {any|null}
556
- */
557
- export function readRunState(runDir: string): any | null;
558
523
  /**
559
524
  * `ask.json`'s own sibling reader (same rule as {@link readLog}) — the
560
525
  * parking ask protocol's own writer lives in {@link runAskSlot} above.
@@ -583,9 +548,12 @@ export const MAX_ATTEMPTS: 4;
583
548
  * a few hundredths of a cent and up), so nothing a real tamper produces can hide inside it. */
584
549
  export const SPEND_TOLERANCE_USD: 1e-9;
585
550
  export const STOP_FILE: "stop.request";
586
- export const HALT_FILE: "halt.json";
551
+ export { HALT_FILE };
587
552
  /** where a failure of learnings work that must not stop the run is recorded (one appended row, in the run's own folder): the run-end tally (`recordRunNotes`) and the take of the draft's learnings record (`takeLearningsRecord`, in runFlow). The run itself is unaffected */
588
553
  export const LEARN_ERROR_FILE: "learn-error.jsonl";
554
+ export function endsRun(r: {
555
+ type?: unknown;
556
+ }): boolean;
589
557
  import { readTicketMcp } from './ticket-mcp.js';
590
558
  /**
591
559
  * Run one step to green (or hitl pass-through), looping under strikes and
@@ -667,4 +635,4 @@ declare function runStepTries({ step, primitivesMap, readsMap, businessDate, mod
667
635
  step?: string | null;
668
636
  };
669
637
  }>;
670
- export {};
638
+ import { HALT_FILE } from './books.js';
@@ -57,10 +57,26 @@ export function writeRunValues(runDir: string, record: {
57
57
  ok: false;
58
58
  red: string;
59
59
  };
60
+ /**
61
+ * Every signed values file in the run folder, oldest version first, each read by `readValuesFile` (the Audit lists them; a refused one
62
+ * shows as refused).
63
+ * @param {string} runDir
64
+ * @returns {Array<{file: string, version: number} & ({ok: true, record: any} | {ok: false, red: string})>}
65
+ */
66
+ export function listRunValues(runDir: string): Array<{
67
+ file: string;
68
+ version: number;
69
+ } & ({
70
+ ok: true;
71
+ record: any;
72
+ } | {
73
+ ok: false;
74
+ red: string;
75
+ })>;
60
76
  /**
61
77
  * The ONE decision "which signed version does this run use": the highest version file in the run folder.
62
78
  * `{ok:true, none:true}` = the flow's own values; `{ok:true, version, record}`; `{ok:false, red}` = a file that cannot be trusted
63
- * (unreadable, not JSON, wrong shape, a hash that does not match its fields, a name that disagrees with its version).
79
+ * (see `readValuesFile`).
64
80
  * @param {string} runDir
65
81
  * @returns {{ok: true, none: true} | {ok: true, none?: false, version: number, record: any} | {ok: false, red: string}}
66
82
  */
@@ -98,5 +114,4 @@ export function applyRunValues(arbiter: any, flow: string, flowSignatureHash: st
98
114
  * @param {string} runDir @returns {boolean} true when the file was removed
99
115
  */
100
116
  export function dropUnstartedValues(runDir: string): boolean;
101
- export const VALUES_FILE_RE: RegExp;
102
117
  export function valuesFileName(version: number): string;
@@ -0,0 +1,9 @@
1
+ /** the whole list as the page takes it: per flow type, `{kind, clock, file, label, newCardLabel}` (clock, file: the one answers of isClockKind and isFileKind) @returns {Record<string, {kind: string, clock: boolean, file: boolean, label: string, newCardLabel: string}[]>} */
2
+ export function scheduleChoices(): Record<string, {
3
+ kind: string;
4
+ clock: boolean;
5
+ file: boolean;
6
+ label: string;
7
+ newCardLabel: string;
8
+ }[]>;
9
+ export function scheduleKindsOf(flowType: unknown): string[];
@@ -0,0 +1,15 @@
1
+ /** @typedef {import('./trigger-line.js').Trigger} Trigger */
2
+ /**
3
+ * The trigger a body asks for, checked as data: null (By hand) or exactly one of the five shapes, the role one of the job's inputs, a full
4
+ * path. Returns the typed trigger or the sentence that says what to fix.
5
+ * @param {unknown} t @param {string[]} roles
6
+ * @returns {{ok: true, trigger: Trigger|null} | {ok: false, say: string}}
7
+ */
8
+ export function shapeOf(t: unknown, roles: string[]): {
9
+ ok: true;
10
+ trigger: Trigger | null;
11
+ } | {
12
+ ok: false;
13
+ say: string;
14
+ };
15
+ export type Trigger = import("./trigger-line.js").Trigger;