@staix/agent-hub 0.12.4 → 0.12.5

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.
@@ -11,13 +11,108 @@ export function childEnv(source: NodeJS.ProcessEnv = process.env): NodeJS.Proces
11
11
  return env;
12
12
  }
13
13
 
14
+ /** One process: its identity is the pid with its start time (`lstart`, which exec keeps); group and command are evidence. */
15
+ export interface ProcRow {
16
+ pid: number;
17
+ ppid: number;
18
+ pgid: number;
19
+ started: string;
20
+ command: string;
21
+ }
22
+
23
+ /**
24
+ * `ps -axo pid=,ppid=,pgid=,stat=,lstart=,command=` output (unlimited width when not on a terminal), read in the C
25
+ * locale. A zombie is left out: it has exited, and only its parent's wait is missing.
26
+ */
27
+ export function parseProcessTable(text: string): ProcRow[] {
28
+ return text.split("\n").flatMap((line) => {
29
+ const m = /^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(\w{3} \w{3} [ \d]\d \d\d:\d\d:\d\d \d{4})\s+(.*)$/.exec(line);
30
+ return m && !m[4]!.startsWith("Z") ? [{ pid: Number(m[1]), ppid: Number(m[2]), pgid: Number(m[3]), started: m[5]!, command: m[6]! }] : [];
31
+ });
32
+ }
33
+
34
+ const PS = ["ps", "-axo", "pid=,ppid=,pgid=,stat=,lstart=,command="];
35
+ // `lstart` is local time: one zone for every reader, or a reader in another zone sees every identity as changed.
36
+ const PS_OPTIONS = { env: { ...process.env, LC_ALL: "C", TZ: "UTC" }, detached: true } as const;
37
+ /** The rows of one read, or undefined when they do not show the reader: a parse that found nothing is not a table. */
38
+ const own = (text: string) => { const rows = parseProcessTable(text); return rows.some((row) => row.pid === process.pid) ? rows : undefined; };
39
+
40
+ /**
41
+ * The process table, or undefined when it cannot be read or does not show this process: a parse that found nothing
42
+ * (a localized `lstart`, a changed `ps`) is not an empty table. Read with LC_ALL=C for that reason (and TZ=UTC, so
43
+ * start times compare across readers), by a `ps` in a
44
+ * process group of its own (a Ctrl-C to the caller's group would kill it), bounded, and tried twice.
45
+ */
46
+ export function processTable(): ProcRow[] | undefined {
47
+ for (let attempt = 0; attempt < 2; attempt++) {
48
+ try {
49
+ const r = Bun.spawnSync(PS, { ...PS_OPTIONS, stdout: "pipe", stderr: "pipe", timeout: 10_000 });
50
+ const rows = r.exitCode === 0 ? own(r.stdout.toString()) : undefined;
51
+ if (rows) return rows;
52
+ } catch {
53
+ // tried again below
54
+ }
55
+ }
56
+ return undefined;
57
+ }
58
+
59
+ /** `processTable`, without blocking the event loop: a hub stop reads the table many times while it keeps serving. */
60
+ export async function readProcessTable(): Promise<ProcRow[] | undefined> {
61
+ for (let attempt = 0; attempt < 2; attempt++) {
62
+ try {
63
+ const p = Bun.spawn(PS, { ...PS_OPTIONS, stdout: "pipe", stderr: "ignore" });
64
+ const timer = setTimeout(() => p.kill("SIGKILL"), 10_000);
65
+ const [text, code] = await Promise.all([new Response(p.stdout).text(), p.exited]).finally(() => clearTimeout(timer));
66
+ const rows = code === 0 ? own(text) : undefined;
67
+ if (rows) return rows;
68
+ } catch {
69
+ // tried again below
70
+ }
71
+ }
72
+ return undefined;
73
+ }
74
+
75
+ /** Every descendant of `pid` in `rows`, by parent links. */
76
+ export function descendantsOf(rows: ProcRow[], pid: number): ProcRow[] {
77
+ const out: ProcRow[] = [];
78
+ const parents = new Set([pid]);
79
+ for (let grew = true; grew; ) {
80
+ grew = false;
81
+ for (const row of rows) {
82
+ if (parents.has(row.ppid) && !parents.has(row.pid)) {
83
+ parents.add(row.pid);
84
+ out.push(row);
85
+ grew = true;
86
+ }
87
+ }
88
+ }
89
+ return out;
90
+ }
91
+
14
92
  /**
15
93
  * Stop a child owned by this hub and confirm that it exited. A timeout is an
16
94
  * incomplete shutdown, even after SIGKILL, because callers must not reuse a
17
95
  * port or claim ownership while the old process may still be alive.
96
+ *
97
+ * `group`: the child was spawned `detached` and leads its own process group; see `stopGroup`. `table` replaces the
98
+ * process table read (tests).
18
99
  */
19
- export async function stopOwnedProcess(proc: ChildProcess, termMs = 1_000, killMs = 2_000): Promise<void> {
20
- if (proc.exitCode !== null || proc.signalCode !== null || proc.pid === undefined) return;
100
+ export async function stopOwnedProcess(proc: ChildProcess, { termMs = 1_000, killMs = 2_000, group = false, table = readProcessTable }: { termMs?: number; killMs?: number; group?: boolean; table?: () => ProcRow[] | undefined | Promise<ProcRow[] | undefined> } = {}): Promise<void> {
101
+ if (proc.exitCode !== null || proc.signalCode !== null || proc.pid === undefined) {
102
+ // ponytail: a leader that exited before the stop (its launcher killed from outside) is not swept, as its pid may be
103
+ // reused once its group empties; its pipes are dropped so a survivor cannot keep the hub alive, and a group that
104
+ // still has members fails the stop instead of reading as done. Record the leader's start time at spawn to sweep it.
105
+ if (!group || proc.pid === undefined) return;
106
+ dropPipes(proc);
107
+ if (emptied.has(proc)) return; // its group was seen gone since: the id may be someone else's now
108
+ // A pid is not given out while a group with that id exists: a live process with the leader's pid means the group was
109
+ // emptied and the id is someone else's now. Members without it are what the leader left (zombies are not listed).
110
+ const rows = await table();
111
+ const members = rows ? (rows.some((r) => r.pid === proc.pid) ? [] : rows.filter((r) => r.pgid === proc.pid)) : undefined;
112
+ if (members ? members.length : !groupGone(proc.pid)) throw new Error(`owned child ${proc.pid} exited before the stop and its process group still has members${members ? ` (${members.map((r) => r.pid).join(", ")})` : ""}: not signalled; stop them to restart it`);
113
+ return;
114
+ }
115
+ if (group) return stopGroup(proc, proc.pid, termMs, killMs, table);
21
116
 
22
117
  const waitForExit = (timeoutMs: number): Promise<boolean> =>
23
118
  new Promise((resolve) => {
@@ -53,3 +148,129 @@ export async function stopOwnedProcess(proc: ChildProcess, termMs = 1_000, killM
53
148
  if (proc.exitCode !== null || proc.signalCode !== null || (await waitForExit(killMs))) return;
54
149
  throw new Error(`owned child ${proc.pid} shutdown incomplete after SIGKILL`);
55
150
  }
151
+
152
+ const dropPipes = (proc: ChildProcess) => {
153
+ proc.stdout?.destroy();
154
+ proc.stderr?.destroy();
155
+ };
156
+
157
+ const emptied = new WeakSet<ChildProcess>();
158
+ /**
159
+ * Follows the group of a child spawned `detached` after the child exits, until the group is gone: a later stop then
160
+ * never inspects the group id, which can be reused once the group is empty (issue #113).
161
+ */
162
+ export function trackGroup(proc: ChildProcess): void {
163
+ proc.once("exit", () => {
164
+ const pid = proc.pid;
165
+ if (pid === undefined) return;
166
+ const check = () => { if (groupGone(pid)) emptied.add(proc); else setTimeout(check, 1_000).unref(); };
167
+ check();
168
+ });
169
+ }
170
+
171
+ /** Whether no process is left in group `pgid` (macOS answers EPERM for a group of zombies). */
172
+ function groupGone(pgid: number): boolean {
173
+ try { process.kill(-pgid, 0); return false; } catch (error) {
174
+ const code = (error as NodeJS.ErrnoException).code;
175
+ return code === "ESRCH" || (code === "EPERM" && process.platform === "darwin");
176
+ }
177
+ }
178
+
179
+ /**
180
+ * Stops a child that leads its own process group, with everything it started (issue #113). A launcher that forwards
181
+ * signals to a native child (Codex's `codex.js`) otherwise dies alone at SIGKILL while its child, still at work, is
182
+ * re-parented to init with the launcher's pipes and keeps the hub alive; and the native child starts processes that
183
+ * lead groups of their own (Codex's MCP servers and tool commands), which no group signal reaches.
184
+ *
185
+ * SIGTERM to the group, a grace period in which what the tree starts is recorded while its parent still runs, then
186
+ * freeze, enumerate, kill: what is left is stopped (SIGSTOP) before the table is read again, because a stopped process
187
+ * starts nothing, so that read sees all of it; then SIGKILL. A snapshot taken while the tree runs misses what it starts
188
+ * next (three review rounds found such a gap). Done means the table shows none of it; without any table, the group's
189
+ * own answer (ESRCH, or EPERM on macOS for a group of zombies) is used, which cannot see groups below it.
190
+ */
191
+ async function stopGroup(proc: ChildProcess, pid: number, termMs: number, killMs: number, table: () => ProcRow[] | undefined | Promise<ProcRow[] | undefined>): Promise<void> {
192
+ const key = (r: { pid: number; started: string }) => `${r.pid}@${r.started}`;
193
+ const found = new Map<string, ProcRow>();
194
+ const exited = () => proc.exitCode !== null || proc.signalCode !== null;
195
+ let leader: ProcRow | undefined;
196
+ const live = (rows: ProcRow[], f: ProcRow) => rows.some((r) => r.pid === f.pid && r.started === f.started);
197
+ /** Reads the table and records what runs below the leader or anything recorded that still runs. */
198
+ const look = async (): Promise<ProcRow[] | undefined> => {
199
+ const rows = await table();
200
+ if (!rows) return undefined;
201
+ if (!leader && !exited()) leader = rows.find((r) => r.pid === pid); // never a pid taken over after the leader exited
202
+ const roots = [...(leader && live(rows, leader) ? [leader] : []), ...[...found.values()].filter((f) => live(rows, f))];
203
+ for (const root of roots) for (const r of descendantsOf(rows, root.pid)) found.set(key(r), r);
204
+ // A group is followed while it is known to be the same one: its leader or a recorded member still in it.
205
+ for (const id of [pid, ...[...found.values()].filter((f) => f.pgid === f.pid).map((f) => f.pid)]) {
206
+ // Current rows, never a recorded pgid: a member may have left the group since it was recorded.
207
+ const known = (id === pid && leader && live(rows, leader)) || rows.some((r) => r.pgid === id && r.pid !== id && found.has(key(r))) || rows.some((r) => r.pid === id && r.pgid === id && found.has(key(r)));
208
+ if (known) for (const r of rows) if (r.pgid === id && r.pid !== pid) found.set(key(r), r);
209
+ }
210
+ return rows;
211
+ };
212
+ const left = (rows: ProcRow[]) => [...found.values()].filter((f) => live(rows, f));
213
+ /**
214
+ * Running in the leader's group, or the group of a recorded process, without being recorded: after an empty moment the
215
+ * group id can be someone else's, so it is never signalled, but the stop is not done while it runs.
216
+ */
217
+ const unproven = (rows: ProcRow[]) => {
218
+ const ids = new Set([pid, ...[...found.values()].filter((f) => f.pgid === f.pid).map((f) => f.pid)]);
219
+ return rows.filter((r) => ids.has(r.pgid) && r.pid !== process.pid && !found.has(key(r)) && !(leader && r.pid === leader.pid && r.started === leader.started));
220
+ };
221
+ // Errors are not results here: the table read back decides. A sent signal says the target existed at that moment.
222
+ const signal = (target: number, sig: NodeJS.Signals) => { try { process.kill(target, sig); return true; } catch { return false; } };
223
+ const each = (rows: ProcRow[], sig: NodeJS.Signals) => rows.filter((r) => signal(r.pgid === r.pid ? -r.pid : r.pid, sig));
224
+ /** A read that takes longer than `ms` is given up: a frozen tree must not wait on a slow `ps` for its SIGKILL. */
225
+ const within = (ms: number) => Promise.race([look(), Bun.sleep(ms).then(() => undefined)]);
226
+ // What leads a group of its own (an MCP server, a tool command) gets a SIGTERM of its own and the same grace period:
227
+ // a git process stopped by SIGKILL leaves its index lock behind.
228
+ const termed = new Set<string>();
229
+ const term = (rows: ProcRow[] | undefined) => {
230
+ for (const r of rows ? left(rows) : []) if (r.pgid === r.pid && !termed.has(key(r))) { termed.add(key(r)); signal(-r.pid, "SIGTERM"); }
231
+ };
232
+ try {
233
+ const first = await look();
234
+ if (!exited()) signal(-pid, "SIGTERM"); // a reaped leader's group id is not proven any more
235
+ term(first);
236
+ // The grace period, for the leader and for what it started: what they start meanwhile is recorded while its parent
237
+ // still runs.
238
+ for (const end = Date.now() + termMs; Date.now() < end; ) {
239
+ await Bun.sleep(100);
240
+ const rows = await look();
241
+ term(rows);
242
+ if (exited() && rows && !left(rows).length) break;
243
+ }
244
+ // Freeze, enumerate, kill: a stopped process starts nothing, so a read after the freeze sees all of it.
245
+ for (const end = Date.now() + killMs; ; ) {
246
+ const rows = await look();
247
+ const rest = rows ? left(rows) : undefined;
248
+ const strangers = rows ? unproven(rows) : [];
249
+ if (exited() && !strangers.length && (rest ? !rest.length : !found.size && groupGone(pid))) return;
250
+ if (Date.now() >= end) {
251
+ throw new Error(`owned child ${pid}: ${rest ? `${rest.length + strangers.length} process(es) of its group or below it still running${strangers.length ? `, ${strangers.length} not proven its own and left alone` : ""}` : "the process table cannot be read to confirm what it started is gone"}`);
252
+ }
253
+ // What is stopped is killed or continued, never left frozen: the group by whether its STOP was sent (its id stays
254
+ // reserved while a member lives), each process by whether the read after the freeze still shows it. What a read
255
+ // after the freeze shows for the first time (started between the read and the STOPs, in a group of its own) is
256
+ // frozen too, and read again, before anything is killed.
257
+ const groupStopped = !exited() && signal(-pid, "SIGSTOP");
258
+ const stopped = new Map<string, ProcRow>();
259
+ let frozen: ProcRow[] | undefined;
260
+ for (let todo = rest ?? [], round = 0; ; round++) {
261
+ for (const r of each(todo, "SIGSTOP")) stopped.set(key(r), r);
262
+ frozen = await within(1_000);
263
+ todo = frozen ? left(frozen).filter((r) => !stopped.has(key(r))) : [];
264
+ if (!todo.length || round >= 4) break;
265
+ }
266
+ // Without a read after the freeze, only what the STOP reached is killed: a stopped process keeps its pid.
267
+ const kill = frozen ? left(frozen) : [...stopped.values()];
268
+ each(kill, "SIGKILL");
269
+ if (groupStopped) signal(-pid, "SIGKILL");
270
+ for (const r of stopped.values()) if (!kill.some((k) => k.pid === r.pid && k.started === r.started)) signal(r.pgid === r.pid ? -r.pid : r.pid, "SIGCONT");
271
+ await Bun.sleep(50);
272
+ }
273
+ } finally {
274
+ dropPipes(proc); // a process that left the tree between two reads may still hold them: it must not keep the hub alive
275
+ }
276
+ }
package/src/hub/daemon.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createHash, randomBytes, randomUUID } from "node:crypto";
2
- import { appendFileSync, chmodSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
2
+ import { appendFileSync, chmodSync, existsSync, fstatSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
3
3
  import { join, resolve } from "node:path";
4
4
  import { homedir } from "node:os";
5
5
  import { spawn } from "node:child_process";
@@ -28,7 +28,7 @@ import { Board, CLASSES, type Task, type TaskClass } from "./board.ts";
28
28
  import { Budget, claudeWindows, codexWindows, DEFAULT_BUDGET, type BudgetConfig } from "./budget.ts";
29
29
  import { HUB } from "./envelope.ts";
30
30
  import { trimToTokens } from "../memory/recall.ts";
31
- import { closeSync, openSync, readSync, statSync } from "node:fs";
31
+ import { closeSync, constants as fsConstants, openSync, readSync, statSync } from "node:fs";
32
32
  import { basename, isAbsolute } from "node:path";
33
33
  import { realPath } from "./project.ts";
34
34
  import type { BusEvent } from "./bus.ts";
@@ -539,15 +539,15 @@ export async function startDaemon(opts: DaemonOptions) {
539
539
  if (!factsOn()) return undefined;
540
540
  let offered: ReturnType<Facts["due"]>;
541
541
  try { offered = facts.due(peer, undefined, true); } catch (error) { log(`integration facts for ${peer}: ${(error as Error).message}`); return undefined; }
542
- if (offered) event({ type: "fact", peer, id: offered.id, files: offered.files, plans: offered.plans, unknown: offered.unknown, bytes: offered.bytes, via: "done" });
542
+ if (offered) event({ type: "fact", peer, id: offered.id, files: offered.files, plans: offered.plans, unknown: offered.unknown, named: offered.named, bytes: offered.bytes, via: "done" });
543
543
  return offered ? { id: offered.id, text: offered.text } : undefined;
544
544
  },
545
545
  ackFacts: (peer, id) => acked(peer, id, "done"),
546
546
  factsCurrent: (peer) => !factsOn() || facts.current(peer),
547
- since: hubStartedAt,
547
+ splitProfile: (peer) => splitProfile(peer),
548
548
  recordCohort: (c) => event({ type: "cohort", ...c }),
549
549
  // The trace holds peer names and numbers only (never task text): it is the inputs a later check of the prediction needs.
550
- recordSplit: (task, p) => event({ type: "split", task, verdict: p.verdict, ...(p.single ? { single: p.single, splitS: p.splitS, singleS: p.singleS } : {}), ...(p.verdict === "unknown" ? { reason: p.trace.at(-1)!.replace(/^ {2}unknown: /, "").slice(0, 200) } : {}), trace: p.trace.slice(1).map((l) => l.trim()).slice(0, 10) }),
550
+ recordSplit: (task, p, where) => event({ type: "split", task, where, verdict: p.verdict, ...(p.single ? { single: p.single, splitS: p.splitS, singleS: p.singleS } : {}), ...(p.verdict === "unknown" ? { reason: p.trace.at(-1)!.replace(/^ {2}unknown: /, "").slice(0, 200) } : {}), trace: p.trace.slice(1).map((l) => l.trim()).slice(0, 10) }),
551
551
  failing: () => bus.failingPeers(),
552
552
  held: () => Object.fromEntries(bus.knownPeers().flatMap((peer) => { const hold = queueHold(peer); return hold ? [[peer, hold]] : []; })),
553
553
  });
@@ -1018,6 +1018,46 @@ export async function startDaemon(opts: DaemonOptions) {
1018
1018
  };
1019
1019
  } catch { return {}; }
1020
1020
  };
1021
+ /**
1022
+ * Claude Code's version, from the last row of its transcript that names one (its rows carry it): the last MiB is read,
1023
+ * opened without blocking and only as a regular file, and the last version found is kept for a tail of big rows.
1024
+ */
1025
+ const claudeVersions = new Map<string, string>();
1026
+ const claudeVersion = (): string | undefined => {
1027
+ const path = claudeSession().transcriptPath;
1028
+ if (!path) return undefined;
1029
+ let fd: number | undefined;
1030
+ try {
1031
+ fd = openSync(path, fsConstants.O_RDONLY | fsConstants.O_NONBLOCK);
1032
+ const st = fstatSync(fd);
1033
+ if (!st.isFile()) return claudeVersions.get(path);
1034
+ const buf = Buffer.alloc(Math.min(st.size, 1024 * 1024));
1035
+ readSync(fd, buf, 0, buf.length, st.size - buf.length);
1036
+ for (const line of buf.toString("utf8").split("\n").reverse()) {
1037
+ try {
1038
+ const version = JSON.parse(line)?.version;
1039
+ const found = typeof version === "string" ? /^\d+\.\d+\.\d+(?:-[\w.]+)?/.exec(version)?.[0] : undefined;
1040
+ if (found) {
1041
+ claudeVersions.set(path, found);
1042
+ return found;
1043
+ }
1044
+ } catch { /* the cut first line, or not JSON */ }
1045
+ }
1046
+ } catch { /* no transcript yet */ } finally { if (fd !== undefined) closeSync(fd); }
1047
+ return claudeVersions.get(path);
1048
+ };
1049
+ /**
1050
+ * A peer's split profile (issue #109): the hub's version, its agent's, and the hook profile, which is the hub's own (a
1051
+ * turn-free project runs the facts hooks in Claude and steers facts into Codex). Undefined while a version is unknown.
1052
+ * ponytail: the user's and plugins' hooks are not seen here, and only Claude and Codex report a version; read hooks
1053
+ * from the native records, as the benchmark ledger does, and add other agents' versions when a pair needs them.
1054
+ */
1055
+ function splitProfile(peer: PeerId): string | undefined {
1056
+ try {
1057
+ const version = peer === "codex" ? (bus.peers.get("codex") as { version?: string } | undefined)?.version : peer === "claude" ? claudeVersion() : undefined;
1058
+ return version ? `hub ${VERSION}; ${peer} ${version}; ${turnFree() ? "turn-free" : "advisory"}` : undefined; // the regime in force: a PII task suspends turn-free
1059
+ } catch { return undefined; } // asked before the daemon finished starting
1060
+ }
1021
1061
  /** Claude persists projects/<slug>/<sessionId>.jsonl only with the first turn. Prefer the
1022
1062
  * path Claude itself reported through the status line; fall back to the slug computation. */
1023
1063
  const claudeTranscriptPersisted = (sessionId: string): boolean => {
@@ -1552,7 +1592,7 @@ export async function startDaemon(opts: DaemonOptions) {
1552
1592
  // Refused, it never went in: not an unread offer, and the next boundary offers it again. Unanswered, it may
1553
1593
  // have: its readback can still come.
1554
1594
  if (outcome === "refused") facts.drop("codex", offered.id);
1555
- event({ type: "fact", peer: "codex", id: offered.id, files: offered.files, plans: offered.plans, unknown: offered.unknown, bytes: offered.bytes, via: "steer", ms, ...(outcome === "accepted" ? { rttMs: Math.round(performance.now() - sent) } : {}), accepted: outcome === "accepted", ...(outcome === "unanswered" ? { unanswered: true } : {}), ...(offered.probe ? { probe: true } : {}), ...(offered.coverage ? { coverage: true } : {}) });
1595
+ event({ type: "fact", peer: "codex", id: offered.id, files: offered.files, plans: offered.plans, unknown: offered.unknown, named: offered.named, bytes: offered.bytes, via: "steer", ms, ...(outcome === "accepted" ? { rttMs: Math.round(performance.now() - sent) } : {}), accepted: outcome === "accepted", ...(outcome === "unanswered" ? { unanswered: true } : {}), ...(offered.probe ? { probe: true } : {}), ...(offered.coverage ? { coverage: true } : {}) });
1556
1596
  });
1557
1597
  },
1558
1598
  appPort: opts.codexAppPort,
@@ -2143,7 +2183,7 @@ export async function startDaemon(opts: DaemonOptions) {
2143
2183
  return void reply({ t: "facts", ok: true });
2144
2184
  }
2145
2185
  const offered = offerFor(peer, toolUseId);
2146
- if (offered) event({ type: "fact", peer, id: offered.id, files: offered.files, plans: offered.plans, unknown: offered.unknown, bytes: offered.bytes, via: "hook", ms: Math.round(performance.now() - started), ...(typeof msg.startedMs === "number" && Number.isFinite(msg.startedMs) ? { hookMs: Math.round(msg.startedMs) } : {}), ...(offered.probe ? { probe: true } : {}), ...(offered.coverage ? { coverage: true } : {}) });
2186
+ if (offered) event({ type: "fact", peer, id: offered.id, files: offered.files, plans: offered.plans, unknown: offered.unknown, named: offered.named, bytes: offered.bytes, via: "hook", ms: Math.round(performance.now() - started), ...(typeof msg.startedMs === "number" && Number.isFinite(msg.startedMs) ? { hookMs: Math.round(msg.startedMs) } : {}), ...(offered.probe ? { probe: true } : {}), ...(offered.coverage ? { coverage: true } : {}) });
2147
2187
  return void reply({ t: "facts", ok: true, ...(offered ? { text: offered.text, id: offered.id } : {}) });
2148
2188
  } catch (error) {
2149
2189
  log(`facts for ${c.peer}: ${(error as Error).message}`);
package/src/hub/events.ts CHANGED
@@ -12,10 +12,10 @@ export type HubEvent =
12
12
  | { type: "overflow" | "undeliverable"; id: string; from: string; peer: string }
13
13
  | { type: "stale"; id: string; from: string; peer: string; task?: string }
14
14
  | { type: "quiet"; id: string; from: string; peers: string[] }
15
- | { type: "fact"; peer: string; id: string; files: number; plans: number; unknown: number; bytes: number; via: "hook" | "steer" | "done"; ms?: number; hookMs?: number; rttMs?: number; accepted?: boolean; unanswered?: boolean; probe?: boolean; coverage?: boolean }
15
+ | { type: "fact"; peer: string; id: string; files: number; plans: number; unknown: number; named: number; bytes: number; via: "hook" | "steer" | "done"; ms?: number; hookMs?: number; rttMs?: number; accepted?: boolean; unanswered?: boolean; probe?: boolean; coverage?: boolean }
16
16
  | { type: "fact_ack"; peer: string; id: string; via: string; ms: number }
17
17
  | { type: "capability"; peer: string; state: "verified" | "lost"; via?: string }
18
- | { type: "split"; task: number; verdict: "split" | "single" | "unknown"; single?: string; splitS?: number; singleS?: number; reason?: string; trace?: string[] }
18
+ | { type: "split"; task: number; where?: "routing" | "cohort"; verdict: "split" | "single" | "unknown"; single?: string; splitS?: number; singleS?: number; reason?: string; trace?: string[] }
19
19
  | { type: "state"; peer: string; state: string }
20
20
  | { type: "turn_start"; peer: string; turn: string }
21
21
  | { type: "turn_end"; peer: string; turn: string; ms: number; tokens?: number; files?: number; snapshotMs?: number }