fwdloop 0.9.0 → 0.11.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.
package/src/runner.js CHANGED
@@ -49,11 +49,14 @@ import {
49
49
  readFlow, resolveRunDir, readFileInside, resolveInside,
50
50
  } from './flow.js';
51
51
  import {
52
- writeAskArchive, readAcceptedHashesByEmits, serializeArtifact, normalizeDecision,
52
+ writeAskArchive, readAcceptedHashesByEmits, serializeArtifact, normalizeDecision, answerTiming, effectiveExpiresAt, withReopen,
53
53
  } from './ask.js';
54
54
  import { WIRED_VERBS } from './primitives.js';
55
55
  import { closeByClass } from './closers.js';
56
56
  import { appendAudit, appendHistory } from './books.js';
57
+ import {
58
+ readResumeLock, recordPid, writeLockHolder, procStartOf, LOCK_NO_HOLDER,
59
+ } from './liveness.js';
57
60
 
58
61
  const __dirname = dirname(fileURLToPath(import.meta.url));
59
62
  const REPO_ROOT = resolve(__dirname, '..');
@@ -628,8 +631,19 @@ async function runStepRalph({
628
631
  // never retried (M2 scope item 8) — both are the caller's own
629
632
  // `modelStep`'s job to distinguish; this loop only ever retries the
630
633
  // `transport: true` shape, exactly once.
634
+ const first = result;
631
635
  // eslint-disable-next-line no-await-in-loop
632
636
  result = await modelStep(executorContext, grantedTools, stepMeta);
637
+ // The first call's gate refusals and tool tally belong to this attempt's
638
+ // audit row too (the retry's collector starts empty). Only refused /
639
+ // tools / ungranted are merged — cost is never touched here.
640
+ if (result && typeof result === 'object') {
641
+ const refused = [...(first.refused ?? []), ...(result.refused ?? [])];
642
+ const tools = first.tools || result.tools ? { ...(first.tools ?? {}) } : null;
643
+ if (tools) for (const [k, v] of Object.entries(result.tools ?? {})) tools[k] = (tools[k] ?? 0) + v;
644
+ const ungranted = [...new Set([...(first.ungranted ?? []), ...(result.ungranted ?? [])])].sort();
645
+ result = { ...result, refused, tools, ...(ungranted.length > 0 ? { ungranted } : {}) };
646
+ }
633
647
  }
634
648
  const wallMs = Date.now() - startedAt;
635
649
 
@@ -856,6 +870,8 @@ export async function runFlow({
856
870
  flowDir, runDir, runId, capUsd, startedAt, now, nowMs: getNowMs, signatureHash: signature.flow, outcome: 'preflight-red', red: frozen.red, spent: { value: 0 },
857
871
  });
858
872
  }
873
+ // M4c: every guard above has passed — this process records itself (pid row) before its first step.
874
+ recordPid(runDir, 'run', now());
859
875
 
860
876
  const artifacts = {};
861
877
  const auditRows = [];
@@ -1475,11 +1491,80 @@ function sumAuditUsd(runDir) {
1475
1491
  return { ok: true, total };
1476
1492
  }
1477
1493
 
1494
+ /** Unlink `resume.lock` only when its recorded holder is still THIS process (`readResumeLock`'s holder pid + start
1495
+ * time against our own). A lock a later taker made in its place is never touched. */
1496
+ function releaseResumeLock(runDir, lockPath) {
1497
+ const lock = readResumeLock(runDir);
1498
+ if (lock.pid === process.pid && lock.procStart === procStartOf('self')) {
1499
+ try { unlinkSync(lockPath); } catch { /* already gone */ }
1500
+ }
1501
+ }
1502
+
1503
+ /**
1504
+ * M4c amendment 2 (d): create `resume.lock` with `wx` and write the holder into it.
1505
+ * An existing lock is read: holder alive (or cannot be told) -> refuse by name
1506
+ * ("locked by another resumer", the panel's one retried refusal); no readable
1507
+ * holder -> refuse by name with the lock path; holder gone -> unlink and retake
1508
+ * with `wx` once (a racing second taker loses cleanly on EEXIST).
1509
+ * @returns {Promise<{ok:true, lockFd:number}|{ok:false, red:string}>}
1510
+ */
1511
+ async function takeResumeLock(runDir, runId, lockPath) {
1512
+ for (let attempt = 0; attempt < 2; attempt += 1) {
1513
+ try {
1514
+ const lockFd = openSync(lockPath, 'wx');
1515
+ try { writeLockHolder(lockFd); } catch (err) {
1516
+ // This call's own `wx` just created the file and no holder is in it yet, so it is ours to remove
1517
+ // (`releaseResumeLock` would skip it: it unlinks only a lock whose holder names this process).
1518
+ try { unlinkSync(lockPath); } catch { /* already gone */ }
1519
+ try { closeSync(lockFd); } catch { /* ignore */ }
1520
+ return { ok: false, red: `resume: could not record the lock holder in ${lockPath} — ${err.message}` };
1521
+ }
1522
+ return { ok: true, lockFd };
1523
+ } catch (err) {
1524
+ if (err.code !== 'EEXIST') return { ok: false, red: `resume: could not create lock ${lockPath} — ${err.message}` };
1525
+ }
1526
+ let lock = readResumeLock(runDir);
1527
+ if (lock.state === 'empty') {
1528
+ // A taker between its `wx` create and its holder write looks empty for an instant.
1529
+ // eslint-disable-next-line no-await-in-loop
1530
+ await new Promise((r) => { setTimeout(r, 150); });
1531
+ lock = readResumeLock(runDir);
1532
+ }
1533
+ if (lock.state === 'live' || lock.state === 'unknown') {
1534
+ return { ok: false, red: `resume: run "${runId}" is locked by another resumer (pid ${lock.pid}, ${lockPath})` };
1535
+ }
1536
+ if (lock.state === 'empty') {
1537
+ return { ok: false, red: `resume: run "${runId}" has a resume lock ${LOCK_NO_HOLDER} (${lockPath}) — it predates the holder record, so it cannot be told apart from a live resume; remove that file by hand if no resume is running` };
1538
+ }
1539
+ if (lock.state === 'dead') {
1540
+ // Re-read right before the unlink: a racing taker may have cleared this lock and retaken it
1541
+ // already, and must not lose its fresh lock. Same holder (pid and start time) as judged dead.
1542
+ // The window left is one syscall wide, and the answer's rename-to-consume (F44) still lets only
1543
+ // one resume act on the answer.
1544
+ const again = readResumeLock(runDir);
1545
+ if (again.state === 'dead' && again.pid === lock.pid && again.procStart === lock.procStart) {
1546
+ try { unlinkSync(lockPath); } catch { /* another taker already cleared it: retry wx */ }
1547
+ }
1548
+ }
1549
+ }
1550
+ return { ok: false, red: `resume: run "${runId}" is locked by another resumer (${lockPath})` };
1551
+ }
1552
+
1553
+ /** Two roots are the same flow location when their real paths agree: a run parked through a symlinked `--root`
1554
+ * recorded the typed link path, and a resume (or a CLI that realpaths its root) names the real one. A path that
1555
+ * cannot be resolved is compared as typed. */
1556
+ function sameRoot(recorded, requested) {
1557
+ if (typeof recorded !== 'string' || typeof requested !== 'string') return false;
1558
+ const real = (p) => { try { return realpathSync(p); } catch { return p; } };
1559
+ return recorded === requested || real(recorded) === real(requested);
1560
+ }
1561
+
1478
1562
  /**
1479
1563
  * M3 scope items 4-6: re-enter a parked run's SAME fold from a separate
1480
- * process. Takes an exclusive `resume.lock` (refuses by name if already
1481
- * held; a lock left behind by a killed resumer is a red naming it, never
1482
- * stolen), re-reads the flow, refuses by name at $0 on any signature/input/
1564
+ * process. Takes an exclusive `resume.lock` that records its holder's
1565
+ * `{pid, procStart}` (M4c amendment 2: refuses by name if the holder is alive
1566
+ * or the lock has no readable holder; a lock whose holder is gone is cleared
1567
+ * and retaken, losing cleanly on a race), re-reads the flow, refuses by name at $0 on any signature/input/
1483
1568
  * missing-artifact mismatch, consumes `answer.json` by atomic rename BEFORE
1484
1569
  * acting (F44), then either cancels an expired ask ($0, nothing sent) or
1485
1570
  * resolves it and folds on to `complete`/the next pause/a halt.
@@ -1540,15 +1625,9 @@ export async function resumeRun({
1540
1625
 
1541
1626
  const lockPath = join(runDir, 'resume.lock');
1542
1627
 
1543
- let lockFd;
1544
- try {
1545
- lockFd = openSync(lockPath, 'wx');
1546
- } catch (err) {
1547
- if (err.code === 'EEXIST') {
1548
- return { outcome: 'refused', red: `resume: run "${runId}" is locked by another resumer (${lockPath})` };
1549
- }
1550
- return { outcome: 'refused', red: `resume: could not create lock ${lockPath} — ${err.message}` };
1551
- }
1628
+ const took = await takeResumeLock(runDir, runId, lockPath);
1629
+ if (!took.ok) return { outcome: 'refused', red: took.red };
1630
+ const { lockFd } = took;
1552
1631
 
1553
1632
  try {
1554
1633
  const statePath = join(runDir, 'state.json');
@@ -1584,7 +1663,7 @@ export async function resumeRun({
1584
1663
  // parked run whose recorded flow location disagrees with what THIS call
1585
1664
  // was asked to resume is refused by name, never re-read from wherever
1586
1665
  // the state file happens to point.
1587
- if (state.flow?.root !== root || state.flow?.name !== name) {
1666
+ if (!sameRoot(state.flow?.root, root) || state.flow?.name !== name) {
1588
1667
  return {
1589
1668
  outcome: 'refused',
1590
1669
  red: `resume: run "${runId}" was parked against flow "${state.flow?.root}/${state.flow?.name}", `
@@ -1710,6 +1789,10 @@ export async function resumeRun({
1710
1789
  } catch (err) {
1711
1790
  return { outcome: 'refused', red: `resume: answer.json for run "${runId}" is not valid JSON — ${err.message}` };
1712
1791
  }
1792
+ // Valid JSON that is not an object (`null`, a number, a string, an array) has no askId to read: refused by name.
1793
+ if (answer === null || typeof answer !== 'object' || Array.isArray(answer)) {
1794
+ return { outcome: 'refused', red: `resume: answer.json for run "${runId}" is not a JSON object (it holds ${answer === null ? 'null' : Array.isArray(answer) ? 'an array' : `a ${typeof answer}`})` };
1795
+ }
1713
1796
  // M4b amendment 3: a consumed/saved answer that says `reject` (an older
1714
1797
  // version's file) is read as `redo`; the file on disk is never rewritten.
1715
1798
  answer = { ...answer, decision: normalizeDecision(answer.decision) };
@@ -1717,6 +1800,13 @@ export async function resumeRun({
1717
1800
  return { outcome: 'refused', red: `resume: answer askId "${answer.askId}" does not match open askId "${state.askId}" for run "${runId}"` };
1718
1801
  }
1719
1802
 
1803
+ // M4c amendment 3: an answer's saved time, never the restart's clock, says whether it was on time. A missing or
1804
+ // unreadable one is refused by name here, before the consume, so the answer stays replayable.
1805
+ const timing = answerTiming(answer.answeredAt, effectiveExpiresAt(runDir, state.askId, state.expiresAt));
1806
+ if (timing === 'unreadable') {
1807
+ return { outcome: 'refused', red: `resume: answer.json for run "${runId}" has a missing or unreadable answeredAt ("${answer.answeredAt}") — refusing rather than treating it as on time` };
1808
+ }
1809
+
1720
1810
  // M4b amendment 2: hashes recorded by earlier-process accepts, read back
1721
1811
  // from the archive + consumed markers. Refused BEFORE the consume below so
1722
1812
  // the answer stays replayable.
@@ -1727,12 +1817,12 @@ export async function resumeRun({
1727
1817
  // itself a one-winner gate, on top of the lock above.
1728
1818
  const consumedPath = join(runDir, `answer.${answer.askId}.consumed.json`);
1729
1819
  renameSync(answerPath, consumedPath);
1820
+ // M4c: the answer is ours and every guard has passed — record this resume process before its first step.
1821
+ recordPid(runDir, 'resume', now());
1730
1822
 
1731
- // The run's own injected clock governs expiry, exactly like every other
1732
- // "now" in this module (never the bare wall clock) — the same fixed
1733
- // clock a test controls for `runFlow` also controls what "expired" means
1734
- // for `resumeRun`, with no real wait required to prove it.
1735
- if (Date.parse(now()) > Date.parse(state.expiresAt)) {
1823
+ // M4c amendment 3: expiry is when the answer was SAVED against the deadline (`timing`, above),
1824
+ // not this process's clock at restart.
1825
+ if (timing === 'late') {
1736
1826
  // Negative (i): an answer arriving after expiry cancels the run —
1737
1827
  // adds NOTHING further, but the run's own already-spent total is
1738
1828
  // real money and must be reported, never coerced to 0 (orchestrator
@@ -1959,8 +2049,8 @@ export async function resumeRun({
1959
2049
  if (result.outcome === 'complete') return { ...result, auditRows };
1960
2050
  return result;
1961
2051
  } finally {
2052
+ releaseResumeLock(runDir, lockPath);
1962
2053
  try { closeSync(lockFd); } catch { /* already closed */ }
1963
- try { unlinkSync(lockPath); } catch { /* already gone */ }
1964
2054
  }
1965
2055
  }
1966
2056
 
@@ -2009,7 +2099,8 @@ export function readRunState(runDir) {
2009
2099
  export function readAsk(runDir) {
2010
2100
  const result = readFileInside(runDir, 'ask.json');
2011
2101
  if (!result.ok) return null;
2012
- try { return JSON.parse(result.text); } catch { return null; }
2102
+ // The deadline every reader sees is the effective one (`withReopen`: a reopened ask's new deadline).
2103
+ try { return withReopen(runDir, JSON.parse(result.text)); } catch { return null; }
2013
2104
  }
2014
2105
 
2015
2106
  /**
package/types/ask.d.ts CHANGED
@@ -1,3 +1,15 @@
1
+ /**
2
+ * M4c amendment 3: the ONE rule for "was this answer saved in time" — the
3
+ * answer's own saved time (`answeredAt`, written by `answerAsk`) against the
4
+ * ask's deadline, never the clock at the moment a resume restarts.
5
+ * on-time - answeredAt parses and is not after expiresAt
6
+ * late - answeredAt parses and is after expiresAt
7
+ * unreadable - answeredAt or expiresAt missing/unparseable: never on time
8
+ * @param {unknown} answeredAt
9
+ * @param {unknown} expiresAt
10
+ * @returns {'on-time'|'late'|'unreadable'}
11
+ */
12
+ export function answerTiming(answeredAt: unknown, expiresAt: unknown): "on-time" | "late" | "unreadable";
1
13
  /**
2
14
  * M4b amendment 3 (SIGNED by hamr 2026-09-30): the ONE translation of a
3
15
  * decision. The answer that was spelled `reject` is `redo`; `reject` is still
@@ -10,6 +22,13 @@
10
22
  * @returns {string}
11
23
  */
12
24
  export function normalizeDecision(decision: string): string;
25
+ /** Terminal control codes out of text a model wrote, before it reaches a terminal: C0 (incl. ESC, which starts
26
+ * every CSI/OSC sequence), DEL and C1 (incl. the one-byte CSI, U+009B). Keeps \n and \t. A stripped ESC leaves the
27
+ * sequence's printable tail ("[2J") visible, which is inert. */
28
+ export function stripControl(text: any): string;
29
+ /** The status for a decision word read from disk, or undefined for anything that is not one of the table's OWN
30
+ * entries ("constructor", "toString" and the rest of Object.prototype read as unrecognised). */
31
+ export function decisionStatus(decision: any): any;
13
32
  /**
14
33
  * @param {{ timeoutMs?: number, pollMs?: number, clock?: () => string, writeLine?: (line:string) => void }} [opts]
15
34
  * @returns {(opts:{question:string, evidence:unknown, runDir:string, ttlMs?: number}) => Promise<{decision:string, reason?:string}>}
@@ -61,9 +80,70 @@ export function serializeArtifact(artifact: unknown): string;
61
80
  * @returns {string}
62
81
  */
63
82
  export function sha256Hex(serialised: string): string;
83
+ /**
84
+ * M4c-fix amendment 1 (a): why a saved `answer.json` is not a usable answer for the open ask `openAskId`, or `null`
85
+ * when it is usable. The resume refuses each of these by name before it consumes the file, so without a way aside
86
+ * the file would block every new answer (`answerAsk`'s exclusive create).
87
+ * @param {string} text the file's text @param {string} openAskId
88
+ * @returns {string|null}
89
+ */
90
+ export function brokenAnswerWhy(text: string, openAskId: string): string | null;
91
+ /**
92
+ * Move `answer.json` aside as a record: `answer.<askId>.<kind>.<n>.json`, `n` the first free number. Write-once:
93
+ * the new name is created with a hard link (`EEXIST` = taken, try the next), then the old name is removed — never
94
+ * a rename, which would overwrite; never a delete of the content. A symlinked `answer.json` is refused, not followed.
95
+ * @param {string} runDir @param {string} askId @param {'broken'|'late'} kind
96
+ * @returns {{ ok: true, name: string } | { ok: false, red: string }}
97
+ */
98
+ export function setAsideAnswer(runDir: string, askId: string, kind: "broken" | "late"): {
99
+ ok: true;
100
+ name: string;
101
+ } | {
102
+ ok: false;
103
+ red: string;
104
+ };
105
+ /**
106
+ * The deadline an ask is judged against: the newest valid reopen record's `expiresAt`, else `original`.
107
+ * A record that is unreadable, names another ask, or holds no parseable `expiresAt` is ignored.
108
+ * @param {string} runDir @param {string} askId @param {string} original the ask's own `expiresAt`
109
+ * @returns {string}
110
+ */
111
+ export function effectiveExpiresAt(runDir: string, askId: string, original: string): string;
112
+ /**
113
+ * An `ask.json`-shaped object as every reader should see it: `expiresAt` is the effective deadline, and `waitMs`
114
+ * is the signed wait the ask was parked with (its own `expiresAt` minus `askedAt`, written from the signed ttl),
115
+ * which a reopen repeats. `waitMs` is `null` when either time cannot be read.
116
+ * @param {string} runDir @param {any} ask
117
+ * @returns {any}
118
+ */
119
+ export function withReopen(runDir: string, ask: any): any;
120
+ /**
121
+ * Reopen an expired ask: a fresh window of the same signed length, starting now, on the same ask (the same draft;
122
+ * nothing about the run changes). Human only — the caller names who (`by`); no runner, agent or resume path calls this.
123
+ * Refused, by name, when: there is no such open ask, its answer was already taken, it has not expired, or a saved
124
+ * answer made in time is waiting (that one is resumed, not reopened). A late or broken saved answer is moved aside
125
+ * as a record (`answer.<askId>.late.<n>.json`, never deleted). Two clicks race on the record's exclusive create:
126
+ * the loser is refused "already reopened", so a double click opens one window, not two.
127
+ * @param {{ runDir: string, askId: string, by: string, clock?: () => string }} opts
128
+ * @returns {{ ok: true, expiresAt: string, n: number, setAside: string|null } | { ok: false, red: string }}
129
+ */
130
+ export function reopenAsk({ runDir, askId, by, clock, }: {
131
+ runDir: string;
132
+ askId: string;
133
+ by: string;
134
+ clock?: () => string;
135
+ }): {
136
+ ok: true;
137
+ expiresAt: string;
138
+ n: number;
139
+ setAside: string | null;
140
+ } | {
141
+ ok: false;
142
+ red: string;
143
+ };
64
144
  /**
65
145
  * @param {{ runDir: string, askId: string, decision: 'accept'|'redo'|'reject'|'rerun', reason?: string, clock?: () => string }} opts
66
- * @returns {{ ok: true } | { ok: false, red: string }}
146
+ * @returns {{ ok: true, setAside: string|null } | { ok: false, red: string }}
67
147
  */
68
148
  export function answerAsk({ runDir, askId, decision: givenDecision, reason, clock, }: {
69
149
  runDir: string;
@@ -73,6 +153,7 @@ export function answerAsk({ runDir, askId, decision: givenDecision, reason, cloc
73
153
  clock?: () => string;
74
154
  }): {
75
155
  ok: true;
156
+ setAside: string | null;
76
157
  } | {
77
158
  ok: false;
78
159
  red: string;
@@ -24,7 +24,7 @@ export function sweepForSecrets(dir: any, secrets: any): number;
24
24
  /** Exact signed TTL with its unit, never rounded: 2h / 30m / 20s / 1500ms (the largest unit that divides it exactly). */
25
25
  export function fmtTtl(ms: any): string;
26
26
  /** Plain-text readout of what the human is about to sign. Pure. */
27
- export function buildReadout({ declaration, arbiter, lines, name, modelId, costUsd, rounds, spendComplete }: {
27
+ export function buildReadout({ declaration, arbiter, lines, name, modelId, costUsd, rounds, spendComplete, root, }: {
28
28
  declaration: any;
29
29
  arbiter: any;
30
30
  lines: any;
@@ -33,6 +33,7 @@ export function buildReadout({ declaration, arbiter, lines, name, modelId, costU
33
33
  costUsd: any;
34
34
  rounds: any;
35
35
  spendComplete: any;
36
+ root: any;
36
37
  }): string;
37
38
  /** Read the prose file. Refuses (a red, never a throw) on unreadable or blank. */
38
39
  export function readProseFile(file: any): {
@@ -98,7 +99,7 @@ export function draftToDir({ proseFile, dir, root, name, slot, model, budgetUsd,
98
99
  wrote: boolean;
99
100
  dir: any;
100
101
  hash: string | null;
101
- reds: string[];
102
+ reds: any;
102
103
  costUsd: number | null;
103
104
  spendComplete: boolean;
104
105
  stop: string | null;
package/types/books.d.ts CHANGED
@@ -1,3 +1,22 @@
1
+ /**
2
+ * M4c piece 1: the ONE writer of a run dir's `pids.jsonl` — append-only, never
3
+ * rewritten, not a book the arbiter reads. One row per process that works on
4
+ * the run (`src/liveness.js` `recordPid` builds the row).
5
+ * @param {string} runDir
6
+ * @param {{pid: number, startedAt: string, procStart: string|null, leg: 'run'|'resume'}} row
7
+ */
8
+ export function appendPidRow(runDir: string, row: {
9
+ pid: number;
10
+ startedAt: string;
11
+ procStart: string | null;
12
+ leg: "run" | "resume";
13
+ }): void;
14
+ /**
15
+ * The one reader of `pids.jsonl` (same tolerant `readLines` every book uses).
16
+ * @param {string} runDir
17
+ * @returns {any[]}
18
+ */
19
+ export function readPidRows(runDir: string): any[];
1
20
  /**
2
21
  * One row per attempt (also used for one row per ask and one row per send —
3
22
  * M2 scope item 9). `row` shape: `{ step, attempt, class, verdict, gap, usd,
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Field 22 (`starttime`, clock ticks since boot) of /proc/<pid>/stat, as a
3
+ * string; `null` when unreadable. The comm field (2) may contain spaces and
4
+ * parens, so fields are counted from the LAST ')'.
5
+ * @param {number|'self'} pid
6
+ * @returns {string|null}
7
+ */
8
+ export function procStartOf(pid: number | "self"): string | null;
9
+ /**
10
+ * Is `pid` a live fwdloop process — and, when `procStart` is given, the SAME
11
+ * process that recorded it?
12
+ * true - exists AND its command line is fwdloop (AND its starttime matches)
13
+ * false - gone, a zombie, alive but something else, or a different process on a recycled pid
14
+ * null - cannot tell (no /proc, or not ours to read): caller falls back to the 10-minute rule
15
+ * @param {number} pid
16
+ * @param {string|null} [procStart] the starttime recorded by the process itself; absent/null = not compared
17
+ * @returns {boolean|null}
18
+ */
19
+ export function isFwdloopAlive(pid: number, procStart?: string | null): boolean | null;
20
+ /**
21
+ * The one writer call: this process records itself in the run dir's
22
+ * `pids.jsonl`, before its first step.
23
+ * @param {string} runDir
24
+ * @param {'run'|'resume'} leg
25
+ * @param {string} at ISO timestamp from the run's own clock
26
+ */
27
+ export function recordPid(runDir: string, leg: "run" | "resume", at: string): void;
28
+ /**
29
+ * Is the process that last worked on this run still alive? Reads the newest
30
+ * `pids.jsonl` row (the one reader, `readPidRows`).
31
+ * `unknown` = no row (a pre-M4c run), a malformed row, or the check said `null`.
32
+ * @param {string} runDir
33
+ * @returns {'running'|'gone'|'unknown'}
34
+ */
35
+ export function runLiveness(runDir: string): "running" | "gone" | "unknown";
36
+ /**
37
+ * M4c amendment 2 (d): the resume lock records who holds it. The one writer:
38
+ * `resumeRun` calls this on the fd it just created with `wx`.
39
+ * @param {number} fd
40
+ */
41
+ export function writeLockHolder(fd: number): void;
42
+ /**
43
+ * The one reader of `resume.lock`. Through `lstat` (a symlinked lock is read as
44
+ * `empty`, never followed).
45
+ * none - no lock file
46
+ * live - the holder is a live fwdloop process (same rule as `[▶]`)
47
+ * dead - the holder is gone (or a different process on a recycled pid)
48
+ * unknown - liveness cannot be told (no /proc): never treated as dead
49
+ * empty - a lock with no readable holder (pre-amendment resumer, torn write)
50
+ * @param {string} runDir
51
+ * @returns {{state: 'none'|'live'|'dead'|'unknown'|'empty', pid: number|null, procStart: string|null, path: string}}
52
+ */
53
+ export function readResumeLock(runDir: string): {
54
+ state: "none" | "live" | "dead" | "unknown" | "empty";
55
+ pid: number | null;
56
+ procStart: string | null;
57
+ path: string;
58
+ };
59
+ /**
60
+ * bareloop's fallback (signed M4c scope item 2): when liveness is `unknown`
61
+ * (a pre-M4c run with no pid row, or /proc unreadable), a run with no end row
62
+ * whose books changed in the last 10 minutes is still working; older is not.
63
+ * Symlinked files are skipped (lstat), never followed.
64
+ * @param {string} runDir
65
+ * @param {number} [nowMs]
66
+ * @returns {boolean}
67
+ */
68
+ export function booksFresh(runDir: string, nowMs?: number): boolean;
69
+ /** The words the runner's refusal uses for a lock it cannot clear; the panel reads the same constant (M4c amendment 3 (e)). */
70
+ export const LOCK_NO_HOLDER: "with no recorded holder";