fwdloop 0.8.1 → 0.10.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.
@@ -1,3 +1,83 @@
1
+ /**
2
+ * M4b piece 2: a SAVED, not-yet-consumed answer — `answer.json` (what
3
+ * `answerAsk` writes; the resume consumes it by renaming it away, F44). Read
4
+ * through `readFileInside` (a symlinked file is "none"). `null` when there is
5
+ * none or it is unreadable/unparseable or names no askId.
6
+ * @param {string} runDir
7
+ * @returns {{askId: string, decision: string|null, answeredAt: string|null}|null}
8
+ */
9
+ export function readSavedAnswer(runDir: string): {
10
+ askId: string;
11
+ decision: string | null;
12
+ answeredAt: string | null;
13
+ } | null;
14
+ /**
15
+ * M4b amendment 1 scope 2: the ONE derivation of "answer saved, resume not
16
+ * started". From the books: an answer saved (`answer.json` present) and so
17
+ * unconsumed. From the panel's in-memory attempt record (`attempt`, may be
18
+ * null): whether a resume is still being started, and the resume's own refusal.
19
+ * `null` when there is nothing to say (no saved answer and no attempt).
20
+ * M4c amendment 3: `ask` (the run's open `ask.json`, may be null). A saved answer for that ask that was
21
+ * NOT saved in time (`answerTiming`) once the deadline has passed is not a resumable answer: it reads as
22
+ * none, so the run is `[!]` expired, the same as an ask nobody answered.
23
+ * @param {{savedAnswer: {askId:string, decision:string|null, answeredAt?:string|null}|null, attempt: any, ask?: any}} ctx
24
+ * @returns {{state: 'starting'|'not-started'|'took-over', askId: string|null, tries: number|null, maxTries: number|null, reason: string|null, label: string}|null}
25
+ */
26
+ export function deriveResumeState({ savedAnswer: saved, attempt, ask }: {
27
+ savedAnswer: {
28
+ askId: string;
29
+ decision: string | null;
30
+ answeredAt?: string | null;
31
+ } | null;
32
+ attempt: any;
33
+ ask?: any;
34
+ }): {
35
+ state: "starting" | "not-started" | "took-over";
36
+ askId: string | null;
37
+ tries: number | null;
38
+ maxTries: number | null;
39
+ reason: string | null;
40
+ label: string;
41
+ } | null;
42
+ /**
43
+ * M4c amendment 2 (a): the ONE rule for "stuck". The answer is saved and not yet
44
+ * taken (`resume.state === 'not-started'`: `answer.json` is on disk; the panel's
45
+ * transient 'starting' is not stuck) and nothing is carrying the run on: the
46
+ * newest pid row's process is not alive AND the resume lock is not held by a
47
+ * live process (`readResumeLock`, src/liveness.js). computeGlyph, the Inbox
48
+ * (`listStops`) and Runs (`listRuns`) all read this, never a second copy.
49
+ * @param {{resume?: any, liveness?: 'running'|'gone'|'unknown', lock?: string}} ctx
50
+ * @returns {boolean}
51
+ */
52
+ export function isStuck({ resume, liveness, lock }: {
53
+ resume?: any;
54
+ liveness?: "running" | "gone" | "unknown";
55
+ lock?: string;
56
+ }): boolean;
57
+ /**
58
+ * M4c amendment 3 (e): the ONE choice of the stuck label. After a "Try the resume again" the runner
59
+ * refused for a lock with no recorded holder (`LOCK_NO_HOLDER`, src/liveness.js) and that lock is
60
+ * still there unreadable (`lock === 'empty'`), trying again can never work: the label says to remove
61
+ * the file by hand. Every other stuck run keeps `STUCK_LABEL`.
62
+ * @param {{resume?: any, lock?: string}} ctx
63
+ * @returns {string}
64
+ */
65
+ export function stuckLabelFor({ resume, lock }: {
66
+ resume?: any;
67
+ lock?: string;
68
+ }): string;
69
+ /**
70
+ * M4c item 1: does this sign pulse? Only `[▶]` running and `[·]` WAITING ON YOU
71
+ * do, and `[II]` stuck (M4c amendment 2: it is not a final state). The other
72
+ * `[·]` states (answered not resumed, resume starting) are not waiting on the
73
+ * human, so they stay still. The one place that decides.
74
+ * @param {{glyph: string, label: string}} g a `computeGlyph` result
75
+ * @returns {boolean}
76
+ */
77
+ export function glyphPulses(g: {
78
+ glyph: string;
79
+ label: string;
80
+ }): boolean;
1
81
  /**
2
82
  * The glyph + human-words label for one run — ported verbatim (in spirit,
3
83
  * from real derivation, not a shortcut) from `poc/m4/panel-data.mjs`'s
@@ -19,20 +99,36 @@
19
99
  * - `[·]` answered, not resumed yet — parked, a consumed answer exists, but
20
100
  * no history row yet (resume hasn't finished) — always in words, never
21
101
  * the same line as "waiting on you", never `[?]`.
22
- * - `[?]` died / unknown — no history row, no open ask, no consumed answer:
23
- * `resume.lock` carries no pid and nothing checks liveness (M4a's own
24
- * open POC question), so a crashed resumer and a live one look the same
25
- * on disk. Never guessed into `[✗]` or `[✓]`.
26
- * @param {{historyRow: any, askJson: any, consumedAnswerExists: boolean, hasStateJson: boolean}} ctx
27
- * @returns {{glyph: '[✓]'|'[✗]'|'[·]'|'[!]'|'[?]', label: string}}
102
+ * - `[?]` died / unknown — no history row, no open ask, and either the
103
+ * pid row's process is gone (M4c), or there is no pid row / no /proc and
104
+ * the books are older than 10 minutes. Never guessed into `[✗]` or `[✓]`.
105
+ * - `[·]` answer saved, resume not started / starting (M4b amendment 1) —
106
+ * `answer.json` still on disk (`resume` = `deriveResumeState`): never
107
+ * "waiting on you" (the human already answered) and never a success.
108
+ * - `[▶]` running (M4c) — no end row, no open unanswered ask, and either the
109
+ * newest pid row's process is alive and is fwdloop (`liveness`, src/liveness.js)
110
+ * or (`liveness` unknown) the run's books changed in the last 10 minutes
111
+ * (`booksFresh`). A gone process is `[?]`. Absent `liveness`/`booksFresh`
112
+ * (a direct caller) reads as unknown / not fresh.
113
+ * - `[II]` stuck (M4c amendment 2, `isStuck`) — the answer is saved, not taken,
114
+ * and no live process (pid row or resume lock holder) carries the run on.
115
+ * A saved answer with a live process is `[▶]` working on your answer.
116
+ * - `[?]` crashed after taking your answer (amendment 2 (f)) — the answer was
117
+ * consumed, the process is gone, no end row: cannot be carried on.
118
+ * @param {{historyRow: any, askJson: any, consumedAnswerExists: boolean, hasStateJson: boolean, resume?: any, liveness?: 'running'|'gone'|'unknown', booksFresh?: boolean, lock?: string}} ctx
119
+ * @returns {{glyph: '[✓]'|'[✗]'|'[·]'|'[!]'|'[▶]'|'[?]'|'[II]', label: string}}
28
120
  */
29
- export function computeGlyph({ historyRow, askJson, consumedAnswerExists, hasStateJson, }: {
121
+ export function computeGlyph({ historyRow, askJson, consumedAnswerExists, hasStateJson, resume, liveness, booksFresh, lock, }: {
30
122
  historyRow: any;
31
123
  askJson: any;
32
124
  consumedAnswerExists: boolean;
33
125
  hasStateJson: boolean;
126
+ resume?: any;
127
+ liveness?: "running" | "gone" | "unknown";
128
+ booksFresh?: boolean;
129
+ lock?: string;
34
130
  }): {
35
- glyph: "[\u2713]" | "[\u2717]" | "[\u00B7]" | "[!]" | "[?]";
131
+ glyph: "[\u2713]" | "[\u2717]" | "[\u00B7]" | "[!]" | "[\u25B6]" | "[?]" | "[II]";
36
132
  label: string;
37
133
  };
38
134
  /**
@@ -85,7 +181,7 @@ export function deriveRunModel(auditRows: any[]): string | null;
85
181
  * place that ever passes a third argument (`unjudgedCount`) into
86
182
  * `recordAudit`, so `Object.prototype.hasOwnProperty.call(row,
87
183
  * 'unjudgedCount')` is true for exactly that step's own rows (paused,
88
- * and the human's own accept/reject/rerun/refused answers) and false for
184
+ * and the human's own accept/redo/rerun/refused answers) and false for
89
185
  * every other row shape in the book — a real, always-present marker
90
186
  * (`unjudgedCount` is a number, 0 included, never omitted on an ask row),
91
187
  * never the step's close class (a NON-ask hitl step, e.g. a plain write
@@ -243,16 +339,30 @@ export function summarizeSpendRows(spendRows: any[]): {
243
339
  * `GET /api/runs` — every flow under `root`, every run under each flow
244
340
  * (M4a scope item 2). A flow with zero runs still gets one row (`runId:
245
341
  * null`, an explicit `why`) — no flow is silently missing from the list.
246
- * Newest-first by history `at` where known; a row with no history row (died
247
- * or still parked) sorts after every row that has one, in flow/run order
248
- * (a real ordering, never `Date.now()` guessed in for a missing `at`).
249
- * @param {{root: string, catalogue: any}} opts
342
+ * Ordered by `orderRuns` (waiting on you, running, then newest `at` first; a row
343
+ * with no `at` is never given a guessed one).
344
+ * @param {{root: string, catalogue: any, resumeAttempt?: (flow: string, runId: string) => any}} opts
345
+ * `resumeAttempt`: the panel's in-memory resume-attempt lookup (M4b piece 2); absent = none.
250
346
  * @returns {any[]}
251
347
  */
252
- export function listRuns({ root, catalogue }: {
348
+ export function listRuns({ root, catalogue, resumeAttempt }: {
253
349
  root: string;
254
350
  catalogue: any;
351
+ resumeAttempt?: (flow: string, runId: string) => any;
255
352
  }): any[];
353
+ /**
354
+ * The ONE ordering of Runs — History and Workflows both render the list in the
355
+ * order given (M4c amendment 1 (c)); a flow's top row is therefore the first
356
+ * run of that flow here, so a waiting run is the parent with no second rule:
357
+ * 1 waiting on you — least time left first; a stuck run (`[II]`, amendment 2)
358
+ * after the ones with a timer;
359
+ * 2 running (`[▶]`, the glyph's own liveness rule);
360
+ * 3 everything else — finish time `at`, newest first.
361
+ * A row with no known time keeps input order at the end of its section.
362
+ * @param {any[]} rows
363
+ * @returns {any[]}
364
+ */
365
+ export function orderRuns(rows: any[]): any[];
256
366
  /**
257
367
  * `GET /api/runs/:flow/:runId` — the Run tab (M4a scope item 2): the step
258
368
  * map from `declaration.steps`, step cards -> attempts from `audit.jsonl`
@@ -260,14 +370,15 @@ export function listRuns({ root, catalogue }: {
260
370
  * `log.json`. `null` when the flow/runId doesn't resolve to a real run
261
371
  * directory at all (caller renders 404); a `red` field names why a
262
372
  * sub-derivation couldn't fill (never invented).
263
- * @param {{root: string, flow: string, runId: string, catalogue: any}} opts
373
+ * @param {{root: string, flow: string, runId: string, catalogue: any, resumeAttempt?: (flow: string, runId: string) => any}} opts
264
374
  * @returns {any|null}
265
375
  */
266
- export function getRunDetail({ root, flow, runId, catalogue, }: {
376
+ export function getRunDetail({ root, flow, runId, catalogue, resumeAttempt, }: {
267
377
  root: string;
268
378
  flow: string;
269
379
  runId: string;
270
380
  catalogue: any;
381
+ resumeAttempt?: (flow: string, runId: string) => any;
271
382
  }): any | null;
272
383
  /**
273
384
  * `GET /api/runs/:flow/:runId/audit` — the Audit/logs tab (M4a scope item
@@ -386,6 +497,20 @@ export function deriveAskStepInfo(orderedAsks: any[], auditRows: any[], declStep
386
497
  line: number | null;
387
498
  why: string | null;
388
499
  }>;
500
+ /**
501
+ * M4c item 5 — the Ask tab's ONE grouping function: one block per signed ask
502
+ * line. Key = the archive's recorded `emits`, else the step the ask's own "paused" audit row names (`stepName`,
503
+ * `deriveAskStepInfo`); when the books cannot name a step (count mismatch, a
504
+ * pre-M4a-1 run) the key falls back to the question text, then to one shared
505
+ * "unknown" key — never a guessed pairing. Draft numbers are the ask's 1-based
506
+ * position within its own block (how many times this line has parked).
507
+ * `current` is the newest draft; `answers` is one row per draft that has a
508
+ * recorded decision (the newest draft only when it is not itself open),
509
+ * decision word via `DECISION_STATUS` (old `reject` files already read `redo`).
510
+ * @param {any[]} asks rows as built by `getRunAsks` (oldest first)
511
+ * @returns {any[]}
512
+ */
513
+ export function groupAskBlocks(asks: any[]): any[];
389
514
  /**
390
515
  * `GET /api/runs/:flow/:runId/asks` — the Ask tab (M4a-1 scope item 1):
391
516
  * every ask this run's books can name, in order, each carrying full
@@ -397,18 +522,24 @@ export function deriveAskStepInfo(orderedAsks: any[], auditRows: any[], declStep
397
522
  * 3" — a plain array position, not derived from any book) and `stepName`/
398
523
  * `stepLine`/`stepWhy` (`deriveAskStepInfo`) so the Ask tab's header can
399
524
  * name which ask is open without the client re-deriving any of it.
400
- * @param {{root: string, flow: string, runId: string, catalogue: any}} opts
401
- * @returns {{flow:string, runId:string, asks:any[]}|null}
525
+ * M4b piece 4: also carries `resume` (the SAME `deriveResumeState` the run
526
+ * detail carries, `null` for a finished run or nothing to say) so the Ask tab
527
+ * can tell "open, answerable" from "answer saved" without a second fetch.
528
+ * @param {{root: string, flow: string, runId: string, catalogue: any, resumeAttempt?: (flow: string, runId: string) => any}} opts
529
+ * @returns {{flow:string, runId:string, asks:any[], resume: any, blocks: any[]}|null}
402
530
  */
403
- export function getRunAsks({ root, flow, runId, catalogue, }: {
531
+ export function getRunAsks({ root, flow, runId, catalogue, resumeAttempt, }: {
404
532
  root: string;
405
533
  flow: string;
406
534
  runId: string;
407
535
  catalogue: any;
536
+ resumeAttempt?: (flow: string, runId: string) => any;
408
537
  }): {
409
538
  flow: string;
410
539
  runId: string;
411
540
  asks: any[];
541
+ resume: any;
542
+ blocks: any[];
412
543
  } | null;
413
544
  /**
414
545
  * `GET /api/inbox` — every stop (parked ask, open or past) across every
@@ -425,9 +556,40 @@ export function getRunAsks({ root, flow, runId, catalogue, }: {
425
556
  * force-`false` here as a second, independent check (belt-and-braces on the
426
557
  * one thing the brief calls out by name: "the Inbox tab's open count counts
427
558
  * only truly open asks — parked run, no history row, unexpired, unanswered").
428
- * @param {{root: string}} opts
559
+ * @param {{root: string, resumeAttempt?: (flow: string, runId: string) => any}} opts
429
560
  * @returns {any[]}
430
561
  */
431
- export function listStops({ root }: {
562
+ export function listStops({ root, resumeAttempt }: {
432
563
  root: string;
564
+ resumeAttempt?: (flow: string, runId: string) => any;
433
565
  }): any[];
566
+ /**
567
+ * The ONE ordering of the Inbox (M4c item 4, hamr 2026-09-30); the page renders
568
+ * in the order given and stamps each row's `section`:
569
+ * 1 waiting on you — least time left first ("runs out first"); a stuck run
570
+ * (amendment 2: answer saved, nobody carrying it on) after the timed asks;
571
+ * 2 working on an answer you gave (`working`), or answer saved and resume not
572
+ * started (`resume`) — newest answer first;
573
+ * 3 answered and expired asks — newest first (answeredAt, else expiresAt).
574
+ * A row with no known time sorts last within its section, ties by input order.
575
+ * @param {any[]} rows
576
+ * @returns {any[]}
577
+ */
578
+ export function orderStops(rows: any[]): any[];
579
+ /**
580
+ * N for `Inbox (N)` (M4c item 3): asks open and not expired, across every flow
581
+ * and run, plus stuck runs (amendment 2: the human must act). An answered ask
582
+ * whose resume is carried on is not `waiting`, so not counted; a crashed one
583
+ * (answer taken, process gone) is not stuck and not counted;
584
+ * an expired ask is not `open`. The page only shows this number.
585
+ * @param {any[]} rows `listStops` rows
586
+ * @returns {number}
587
+ */
588
+ export function inboxOpenCount(rows: any[]): number;
589
+ /** What the `resume` field says when the panel has no attempt record for a run
590
+ * (it restarted since the answer was saved) — said so, never blank. */
591
+ export const RESUME_REASON_UNKNOWN: "reason unknown: the panel restarted, so it has no record of the resume attempt";
592
+ export const WAITING_LABEL: "waiting on you (parked, unanswered)";
593
+ export const STUCK_LABEL: "stuck \u2014 answer saved, click try the resume again";
594
+ export const STUCK_LOCK_LABEL: "stuck \u2014 remove the old resume lock by hand, then try again";
595
+ export const CRASHED_LABEL: "crashed after taking your answer \u2014 start a fresh run";
@@ -0,0 +1,51 @@
1
+ /**
2
+ * @param {{ root: string, env?: Record<string, string|undefined>, bin?: string, logDir?: string,
3
+ * maxTries?: number, windowMs?: number, slotMs?: number }} opts
4
+ * `env`/`bin`/`logDir`/`maxTries`/`windowMs`/`slotMs` are injectable so tests neither sleep 10 s
5
+ * nor need a live key; production passes none of them. `slotMs` (default `windowMs / maxTries`,
6
+ * i.e. 2000 ms) is only the spacing between tries: a test sets it small and `windowMs` (the
7
+ * per-try "did it take over" deadline) large, so CPU load cannot turn a slow child start into a
8
+ * false "stuck".
9
+ */
10
+ export function createResumer(opts: {
11
+ root: string;
12
+ env?: Record<string, string | undefined>;
13
+ bin?: string;
14
+ logDir?: string;
15
+ maxTries?: number;
16
+ windowMs?: number;
17
+ slotMs?: number;
18
+ }): {
19
+ /**
20
+ * Start the detached resume for a saved answer and return at once with the
21
+ * attempt record (a copy); the verify/retry loop runs in the background.
22
+ * @param {{ flow: string, runId: string, runDir: string, askId: string }} a
23
+ */
24
+ start({ flow, runId, runDir, askId, }: {
25
+ flow: string;
26
+ runId: string;
27
+ runDir: string;
28
+ askId: string;
29
+ }): {
30
+ flow: string;
31
+ runId: string;
32
+ askId: string;
33
+ state: string;
34
+ tries: number;
35
+ maxTries: number;
36
+ windowMs: number;
37
+ refusal: null;
38
+ startedAt: number;
39
+ endedAt: null;
40
+ logPath: null;
41
+ superseded: boolean;
42
+ };
43
+ /** A copy of the run's attempt record, or null (none yet, or the panel restarted).
44
+ * @param {string} flow @param {string} runId */
45
+ get(flow: string, runId: string): any;
46
+ /** Every log file this resumer has written (for tests and hygiene checks). */
47
+ logPaths(): any[];
48
+ };
49
+ /** Signed with M4b amendment 1, scope 1: up to 5 tries within 10 seconds. */
50
+ export const RESUME_MAX_TRIES: 5;
51
+ export const RESUME_WINDOW_MS: 10000;
@@ -1,14 +1,16 @@
1
1
  /**
2
- * Handle one request against the read-only API + the page. Exported
2
+ * Handle one request against the API + the page. Exported
3
3
  * separately from {@link createPanelServer} so tests can drive it without a
4
4
  * real listening socket where that is simpler.
5
5
  * @param {import('node:http').IncomingMessage} req
6
6
  * @param {import('node:http').ServerResponse} res
7
- * @param {{ root: string, port: number }} opts
7
+ * @param {{ root: string, port: number, token: string, resumer: ReturnType<typeof createResumer> }} opts
8
8
  */
9
9
  export function handleRequest(req: import("node:http").IncomingMessage, res: import("node:http").ServerResponse, opts: {
10
10
  root: string;
11
11
  port: number;
12
+ token: string;
13
+ resumer: ReturnType<typeof createResumer>;
12
14
  }): void;
13
15
  /**
14
16
  * Start the panel server. Binds `127.0.0.1` ONLY. A taken port is a LOUD,
@@ -16,12 +18,21 @@ export function handleRequest(req: import("node:http").IncomingMessage, res: imp
16
18
  * header). Resolves once actually listening; rejects on a bind error
17
19
  * (including `EADDRINUSE`) with a `.port` field on the error for the
18
20
  * caller's message.
19
- * @param {{ port?: number, root: string }} opts
21
+ * @param {{ port?: number, root: string, resume?: { env?: Record<string,string|undefined>, bin?: string, logDir?: string, maxTries?: number, windowMs?: number, slotMs?: number } }} opts
22
+ * `resume` is for tests only (a fake env/bin, a short retry window); the CLI passes none.
20
23
  * @returns {Promise<{ server: import('node:http').Server, port: number, close: () => Promise<void> }>}
21
24
  */
22
25
  export function createPanelServer(opts: {
23
26
  port?: number;
24
27
  root: string;
28
+ resume?: {
29
+ env?: Record<string, string | undefined>;
30
+ bin?: string;
31
+ logDir?: string;
32
+ maxTries?: number;
33
+ windowMs?: number;
34
+ slotMs?: number;
35
+ };
25
36
  }): Promise<{
26
37
  server: import("node:http").Server;
27
38
  port: number;
@@ -43,3 +54,4 @@ export function panelMain(argv: string[], ctx: {
43
54
  * is 4800 — bareloop owns 4700, and the two panels must be able to run
44
55
  * side by side. */
45
56
  export const DEFAULT_PORT: 4800;
57
+ import { createResumer } from './resume.js';
package/types/runner.d.ts CHANGED
@@ -117,8 +117,8 @@ export function readArtifact(runDir: any, id: any): any;
117
117
  * @param {Array<{id:string, path:string}>} opts.sources - the real files to freeze for this run.
118
118
  * @param {unknown} opts.catalogue - passed straight through to `readFlow`.
119
119
  * @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
120
- * @param {(opts:{question:string, evidence:unknown, runDir:string}) => Promise<{decision:'accept'|'reject'|'rerun'|'timeout'|'park', reason?:string}>} opts.askStep
121
- * @param {(target:string, filename:string, content:unknown) => Promise<{ok:boolean, red?:string, bytes?:number}>} opts.sendStep
120
+ * @param {(opts:{question:string, evidence:unknown, runDir:string}) => Promise<{decision:'accept'|'redo'|'rerun'|'timeout'|'park', reason?:string, artifactSha256?:string}>} opts.askStep
121
+ * @param {(target:string, filename:string, content:unknown, acceptedSha256?:string|null) => Promise<{ok:boolean, red?:string, bytes?:number}>} opts.sendStep
122
122
  * @param {Record<string, any>} [opts.primitives] - injected primitive implementations, keyed by catalogue verb.
123
123
  * @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.
124
124
  * @param {() => string} [opts.clock] - returns the current ISO timestamp; defaults to the wall clock.
@@ -157,10 +157,11 @@ export function runFlow({ root, name, runId, sources, catalogue, modelStep, askS
157
157
  evidence: unknown;
158
158
  runDir: string;
159
159
  }) => Promise<{
160
- decision: "accept" | "reject" | "rerun" | "timeout" | "park";
160
+ decision: "accept" | "redo" | "rerun" | "timeout" | "park";
161
161
  reason?: string;
162
+ artifactSha256?: string;
162
163
  }>;
163
- sendStep: (target: string, filename: string, content: unknown) => Promise<{
164
+ sendStep: (target: string, filename: string, content: unknown, acceptedSha256?: string | null) => Promise<{
164
165
  ok: boolean;
165
166
  red?: string;
166
167
  bytes?: number;
@@ -183,9 +184,10 @@ export function makeParkingAskStep(): (opts?: any) => Promise<{
183
184
  }>;
184
185
  /**
185
186
  * M3 scope items 4-6: re-enter a parked run's SAME fold from a separate
186
- * process. Takes an exclusive `resume.lock` (refuses by name if already
187
- * held; a lock left behind by a killed resumer is a red naming it, never
188
- * stolen), re-reads the flow, refuses by name at $0 on any signature/input/
187
+ * process. Takes an exclusive `resume.lock` that records its holder's
188
+ * `{pid, procStart}` (M4c amendment 2: refuses by name if the holder is alive
189
+ * or the lock has no readable holder; a lock whose holder is gone is cleared
190
+ * and retaken, losing cleanly on a race), re-reads the flow, refuses by name at $0 on any signature/input/
189
191
  * missing-artifact mismatch, consumes `answer.json` by atomic rename BEFORE
190
192
  * acting (F44), then either cancels an expired ask ($0, nothing sent) or
191
193
  * resolves it and folds on to `complete`/the next pause/a halt.
package/types/send.d.ts CHANGED
@@ -2,9 +2,12 @@
2
2
  * @param {string} target - a signed arbiter target, e.g. `file:poc/m0/out`.
3
3
  * @param {string} filename
4
4
  * @param {unknown} content - JSON-serialised before writing.
5
+ * @param {string|null} [acceptedSha256] - the sha256 the human's accept recorded
6
+ * (`answerAsk`, M4b piece 3). Required: none recorded (an answer written by an
7
+ * older version, or no accept in this process) refuses by name.
5
8
  * @returns {Promise<{ok:true, path:string, bytes:number} | {ok:false, red:string}>}
6
9
  */
7
- export function sendViaPrimitive(target: string, filename: string, content: unknown): Promise<{
10
+ export function sendViaPrimitive(target: string, filename: string, content: unknown, acceptedSha256?: string | null): Promise<{
8
11
  ok: true;
9
12
  path: string;
10
13
  bytes: number;