@hearsay-tools/squawk 0.18.0-dev.6593 → 0.18.0-dev.6602

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.
@@ -232,30 +232,6 @@ export declare class WaitEngine {
232
232
  deadline: string;
233
233
  seconds: number;
234
234
  note?: string | undefined;
235
- } | {
236
- id: string;
237
- source: "agent" | "cezar";
238
- via: "ask-line" | "budget" | "cez-message-wait" | "cez-worker-wait" | "cezar_ask" | "cezar_wait" | "cezar_wait_for_ci" | "completion" | "monitoring-line" | "native-ask" | "native-subagents" | "no-wait" | "schedule-wakeup";
239
- registeredAt: string;
240
- phase: "cancelled" | "delivered" | "open" | "resolved";
241
- resolvedAt?: string | undefined;
242
- deliveredAt?: string | undefined;
243
- cancelledAt?: string | undefined;
244
- turnId: string;
245
- kind: "process";
246
- deadline: string;
247
- timeoutSeconds: number;
248
- pid: number;
249
- startToken?: string | undefined;
250
- exitFile?: string | undefined;
251
- note?: string | undefined;
252
- result?: {
253
- outcome: "deadline" | "error" | "exit_file" | "exited";
254
- observedAt: string;
255
- exitCode?: number | undefined;
256
- exitFileNote?: "not-an-exit-code" | undefined;
257
- diagnostic?: string | undefined;
258
- } | undefined;
259
235
  } | {
260
236
  id: string;
261
237
  source: "agent" | "cezar";
@@ -316,6 +292,30 @@ export declare class WaitEngine {
316
292
  reason: "outcome" | "timeout";
317
293
  } | undefined;
318
294
  wakeInputId?: string | undefined;
295
+ } | {
296
+ id: string;
297
+ source: "agent" | "cezar";
298
+ via: "ask-line" | "budget" | "cez-message-wait" | "cez-worker-wait" | "cezar_ask" | "cezar_wait" | "cezar_wait_for_ci" | "completion" | "monitoring-line" | "native-ask" | "native-subagents" | "no-wait" | "schedule-wakeup";
299
+ registeredAt: string;
300
+ phase: "cancelled" | "delivered" | "open" | "resolved";
301
+ resolvedAt?: string | undefined;
302
+ deliveredAt?: string | undefined;
303
+ cancelledAt?: string | undefined;
304
+ turnId: string;
305
+ kind: "process";
306
+ deadline: string;
307
+ timeoutSeconds: number;
308
+ pid: number;
309
+ startToken?: string | undefined;
310
+ exitFile?: string | undefined;
311
+ note?: string | undefined;
312
+ result?: {
313
+ outcome: "deadline" | "error" | "exit_file" | "exited";
314
+ observedAt: string;
315
+ exitCode?: number | undefined;
316
+ exitFileNote?: "not-an-exit-code" | undefined;
317
+ diagnostic?: string | undefined;
318
+ } | undefined;
319
319
  } | {
320
320
  id: string;
321
321
  source: "agent" | "cezar";
@@ -426,30 +426,6 @@ export declare class WaitEngine {
426
426
  deadline: string;
427
427
  seconds: number;
428
428
  note?: string | undefined;
429
- } | {
430
- id: string;
431
- source: "agent" | "cezar";
432
- via: "ask-line" | "budget" | "cez-message-wait" | "cez-worker-wait" | "cezar_ask" | "cezar_wait" | "cezar_wait_for_ci" | "completion" | "monitoring-line" | "native-ask" | "native-subagents" | "no-wait" | "schedule-wakeup";
433
- registeredAt: string;
434
- phase: "cancelled" | "delivered" | "open" | "resolved";
435
- resolvedAt?: string | undefined;
436
- deliveredAt?: string | undefined;
437
- cancelledAt?: string | undefined;
438
- turnId: string;
439
- kind: "process";
440
- deadline: string;
441
- timeoutSeconds: number;
442
- pid: number;
443
- startToken?: string | undefined;
444
- exitFile?: string | undefined;
445
- note?: string | undefined;
446
- result?: {
447
- outcome: "deadline" | "error" | "exit_file" | "exited";
448
- observedAt: string;
449
- exitCode?: number | undefined;
450
- exitFileNote?: "not-an-exit-code" | undefined;
451
- diagnostic?: string | undefined;
452
- } | undefined;
453
429
  } | {
454
430
  id: string;
455
431
  source: "agent" | "cezar";
@@ -510,6 +486,30 @@ export declare class WaitEngine {
510
486
  reason: "outcome" | "timeout";
511
487
  } | undefined;
512
488
  wakeInputId?: string | undefined;
489
+ } | {
490
+ id: string;
491
+ source: "agent" | "cezar";
492
+ via: "ask-line" | "budget" | "cez-message-wait" | "cez-worker-wait" | "cezar_ask" | "cezar_wait" | "cezar_wait_for_ci" | "completion" | "monitoring-line" | "native-ask" | "native-subagents" | "no-wait" | "schedule-wakeup";
493
+ registeredAt: string;
494
+ phase: "cancelled" | "delivered" | "open" | "resolved";
495
+ resolvedAt?: string | undefined;
496
+ deliveredAt?: string | undefined;
497
+ cancelledAt?: string | undefined;
498
+ turnId: string;
499
+ kind: "process";
500
+ deadline: string;
501
+ timeoutSeconds: number;
502
+ pid: number;
503
+ startToken?: string | undefined;
504
+ exitFile?: string | undefined;
505
+ note?: string | undefined;
506
+ result?: {
507
+ outcome: "deadline" | "error" | "exit_file" | "exited";
508
+ observedAt: string;
509
+ exitCode?: number | undefined;
510
+ exitFileNote?: "not-an-exit-code" | undefined;
511
+ diagnostic?: string | undefined;
512
+ } | undefined;
513
513
  } | {
514
514
  id: string;
515
515
  source: "agent" | "cezar";
@@ -619,30 +619,6 @@ export declare class WaitEngine {
619
619
  deadline: string;
620
620
  seconds: number;
621
621
  note?: string | undefined;
622
- } | {
623
- id: string;
624
- source: "agent" | "cezar";
625
- via: "ask-line" | "budget" | "cez-message-wait" | "cez-worker-wait" | "cezar_ask" | "cezar_wait" | "cezar_wait_for_ci" | "completion" | "monitoring-line" | "native-ask" | "native-subagents" | "no-wait" | "schedule-wakeup";
626
- registeredAt: string;
627
- phase: "cancelled" | "delivered" | "open" | "resolved";
628
- resolvedAt?: string | undefined;
629
- deliveredAt?: string | undefined;
630
- cancelledAt?: string | undefined;
631
- turnId: string;
632
- kind: "process";
633
- deadline: string;
634
- timeoutSeconds: number;
635
- pid: number;
636
- startToken?: string | undefined;
637
- exitFile?: string | undefined;
638
- note?: string | undefined;
639
- result?: {
640
- outcome: "deadline" | "error" | "exit_file" | "exited";
641
- observedAt: string;
642
- exitCode?: number | undefined;
643
- exitFileNote?: "not-an-exit-code" | undefined;
644
- diagnostic?: string | undefined;
645
- } | undefined;
646
622
  } | {
647
623
  id: string;
648
624
  source: "agent" | "cezar";
@@ -703,6 +679,30 @@ export declare class WaitEngine {
703
679
  reason: "outcome" | "timeout";
704
680
  } | undefined;
705
681
  wakeInputId?: string | undefined;
682
+ } | {
683
+ id: string;
684
+ source: "agent" | "cezar";
685
+ via: "ask-line" | "budget" | "cez-message-wait" | "cez-worker-wait" | "cezar_ask" | "cezar_wait" | "cezar_wait_for_ci" | "completion" | "monitoring-line" | "native-ask" | "native-subagents" | "no-wait" | "schedule-wakeup";
686
+ registeredAt: string;
687
+ phase: "cancelled" | "delivered" | "open" | "resolved";
688
+ resolvedAt?: string | undefined;
689
+ deliveredAt?: string | undefined;
690
+ cancelledAt?: string | undefined;
691
+ turnId: string;
692
+ kind: "process";
693
+ deadline: string;
694
+ timeoutSeconds: number;
695
+ pid: number;
696
+ startToken?: string | undefined;
697
+ exitFile?: string | undefined;
698
+ note?: string | undefined;
699
+ result?: {
700
+ outcome: "deadline" | "error" | "exit_file" | "exited";
701
+ observedAt: string;
702
+ exitCode?: number | undefined;
703
+ exitFileNote?: "not-an-exit-code" | undefined;
704
+ diagnostic?: string | undefined;
705
+ } | undefined;
706
706
  } | {
707
707
  id: string;
708
708
  source: "agent" | "cezar";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hearsay-tools/squawk",
3
- "version": "0.18.0-dev.6593",
3
+ "version": "0.18.0-dev.6602",
4
4
  "description": "Local cockpit for running and tracking AI agent tasks in your repo. Uses your logged-in `claude` CLI and `gh` — zero config, zero database.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -31,6 +31,7 @@
31
31
  "install-as-command": "node scripts/install-as-command.mjs --mode link",
32
32
  "install-as-command:global": "node scripts/install-as-command.mjs --mode global",
33
33
  "uninstall-as-command": "node scripts/install-as-command.mjs --mode uninstall",
34
+ "bench:conversation-lookup": "node --import tsx scripts/benchmark-conversation-lookup.ts",
34
35
  "bench:family-reconcile": "node --import tsx scripts/benchmark-family-reconcile.ts",
35
36
  "bench:run-store": "node --import tsx scripts/benchmark-run-store.ts",
36
37
  "bench:stuck-destroys": "node --import tsx scripts/benchmark-stuck-destroys.ts",
@@ -61,8 +62,8 @@
61
62
  "devDependencies": {
62
63
  "@babel/parser": "^8.0.8",
63
64
  "@babel/types": "^8.0.8",
64
- "@open-mercato/cezar-api-client": "0.18.0-dev.6593",
65
- "@open-mercato/cezar-contract": "0.18.0-dev.6593",
65
+ "@open-mercato/cezar-api-client": "0.18.0-dev.6602",
66
+ "@open-mercato/cezar-contract": "0.18.0-dev.6602",
66
67
  "@types/node": "^24.19.1",
67
68
  "@types/ws": "^8.18.1",
68
69
  "esbuild": "^0.28.1",
@@ -79,5 +80,5 @@
79
80
  "publishConfig": {
80
81
  "access": "public"
81
82
  },
82
- "gitHead": "31da78f4556252ff2949349877eb354052ee4dee"
83
+ "gitHead": "812c0951f25e1a99c71ec0c14e67521b866c1c0f"
83
84
  }
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Conversation lookup benchmark: what it costs to find the root tasks whose conversation names a
3
+ * run. Every read of a root task with workers asks it through the completion gate
4
+ * (`openCompletionRequests` → `rootsAwaitingPeer`), and so does every settled root, on the event
5
+ * loop. Run it unchanged before and after a change to how the store answers that question.
6
+ *
7
+ * npm run bench:conversation-lookup -w @wjarka/cezarion
8
+ * node --import tsx packages/cezar/scripts/benchmark-conversation-lookup.ts --roots 100,1000,3000
9
+ *
10
+ * Flags: --roots (100,1000,3000) --conversation-share (0.33) --messages (40) --root-kb (300)
11
+ * --passes (5) --out (a JSON file for the result rows).
12
+ *
13
+ * Method:
14
+ * - Each size seeds one project's `runs.db` with the store's own row encoding: `--roots` archived
15
+ * `done` root tasks of about `--root-kb` each, a `--conversation-share` of them carrying a
16
+ * conversation of `--messages` peer messages with other roots. The defaults follow a busy local
17
+ * project: 1,332 roots, 438 of them with a conversation, 19,178 messages in all.
18
+ * - The store is opened as `serve` opens it. A lookup is `rootsAwaitingPeer` for one root that
19
+ * two other roots name, and `listConversationRootIds()` is the unnamed list recovery reads.
20
+ * - Times are the median of `--passes` calls, after one warm-up call.
21
+ */
22
+ import { randomUUID } from 'node:crypto';
23
+ import { cpus } from 'node:os';
24
+ import { performance } from 'node:perf_hooks';
25
+ import { parseArgs } from 'node:util';
26
+ import { makeRunRecord } from '@open-mercato/cezar-contract/test-factories.testkit';
27
+ import type { ConversationMessage } from '@open-mercato/cezar-contract';
28
+ import { benchAt as at, median, runSizes, withSeededStore } from './benchmark-store-fixture.ts';
29
+ import { rootsAwaitingPeer } from '../src/delegation/conversations.ts';
30
+ import type { RunRecord } from '../src/runs/store.ts';
31
+
32
+ export interface ConversationBenchOptions { roots: number; conversationShare: number; messages: number; rootKb: number; passes: number }
33
+ export interface ConversationBenchRow { roots: number; conversations: number; awaiting: number; lookupMs: number; listMs: number }
34
+
35
+ /** The roots, and the one root (`target`) that two conversations send an open request to: a
36
+ * lookup finds a few roots among many conversations, as a real one does. */
37
+ function records(options: ConversationBenchOptions): { rows: RunRecord[]; target: string; conversations: number } {
38
+ const ids = Array.from({ length: options.roots }, () => randomUUID());
39
+ const target = ids[0]!, task = 'x'.repeat(options.rootKb * 1024);
40
+ // Root 0 is the target, so at most every other root talks.
41
+ const talking = Math.min(Math.round(options.roots * options.conversationShare), options.roots - 1);
42
+ const rows = ids.map((id, index) => {
43
+ const messages: ConversationMessage[] = index > 0 && index <= talking ? Array.from({ length: options.messages }, (_, n) => ({
44
+ id: randomUUID(), senderRunId: id, recipientRunId: n === 0 && index <= 2 ? target : ids[1 + ((index + n) % (ids.length - 1))]!, kind: 'request', relationship: 'peer',
45
+ text: `message ${n}`, createdAt: at(index), requestHash: 'a'.repeat(64), state: 'accepted',
46
+ })) : [];
47
+ return makeRunRecord({ id, status: 'done', archived: true, task, createdAt: at(index), finishedAt: at(index + 1),
48
+ delegation: { role: 'root', permissions: ['spawn'], receipts: [], ...(messages.length ? { conversation: { messages, outcomes: [] } } : {}) } });
49
+ });
50
+ return { rows, target, conversations: talking };
51
+ }
52
+
53
+ /** Seed one temporary project, open its store and time the two lookups. */
54
+ export async function measureConversationLookup(options: ConversationBenchOptions): Promise<ConversationBenchRow> {
55
+ const { rows, target, conversations } = records(options);
56
+ return withSeededStore('cez-bench-conversations-', () => rows, async (store) => {
57
+ const time = (call: () => unknown) => { const t = performance.now(); call(); return performance.now() - t; };
58
+ const awaiting = rootsAwaitingPeer(store, target).length;
59
+ store.listConversationRootIds();
60
+ const lookupMs: number[] = [], listMs: number[] = [];
61
+ for (let i = 0; i < options.passes; i++) {
62
+ lookupMs.push(time(() => rootsAwaitingPeer(store, target)));
63
+ listMs.push(time(() => store.listConversationRootIds()));
64
+ }
65
+ return { roots: options.roots, conversations, awaiting,
66
+ lookupMs: Math.round(median(lookupMs)), listMs: Math.round(median(listMs)) };
67
+ });
68
+ }
69
+
70
+ export interface ConversationBenchArgs { sizes: number[]; base: Omit<ConversationBenchOptions, 'roots'>; out: string | undefined }
71
+
72
+ /** The command line as one run's settings; throws on a size or count it cannot use. */
73
+ export function parseConversationBenchArgs(args: string[]): ConversationBenchArgs {
74
+ const { values } = parseArgs({ args, options: {
75
+ roots: { type: 'string', default: '100,1000,3000' },
76
+ 'conversation-share': { type: 'string', default: '0.33' },
77
+ messages: { type: 'string', default: '40' },
78
+ 'root-kb': { type: 'string', default: '300' },
79
+ passes: { type: 'string', default: '5' },
80
+ out: { type: 'string' },
81
+ } });
82
+ const sizes = values.roots.split(',').map(Number);
83
+ const base = { conversationShare: Number(values['conversation-share']), messages: Number(values.messages), rootKb: Number(values['root-kb']), passes: Number(values.passes) };
84
+ if (sizes.some(size => !Number.isInteger(size) || size < 2) || !(base.conversationShare >= 0 && base.conversationShare <= 1) || !(Number.isInteger(base.messages) && base.messages >= 1) || !(Number.isInteger(base.passes) && base.passes >= 1)) {
85
+ throw new Error('--roots takes whole numbers >= 2; --conversation-share takes 0 to 1; --messages and --passes take whole numbers >= 1');
86
+ }
87
+ return { sizes, base, out: values.out };
88
+ }
89
+
90
+ /** The result as a Markdown table under one line naming the settings and the host. */
91
+ export function formatConversationTable(base: ConversationBenchArgs['base'], rows: readonly ConversationBenchRow[]): string {
92
+ return [
93
+ `root ${base.rootKb} KB, ${base.conversationShare} with a conversation of ${base.messages} messages, median of ${base.passes} calls, ${cpus().length} cores, Node ${process.version}`,
94
+ '| roots | with a conversation | awaiting the target | rootsAwaitingPeer ms | listConversationRootIds ms |',
95
+ '| ---: | ---: | ---: | ---: | ---: |',
96
+ ...rows.map(row => `| ${row.roots} | ${row.conversations} | ${row.awaiting} | ${row.lookupMs} | ${row.listMs} |`),
97
+ ].join('\n');
98
+ }
99
+
100
+ async function main(): Promise<void> {
101
+ const { sizes, base, out } = parseConversationBenchArgs(process.argv.slice(2));
102
+ await runSizes(sizes, out, roots => measureConversationLookup({ ...base, roots }), rows => formatConversationTable(base, rows));
103
+ }
104
+
105
+ if (import.meta.main) await main();
@@ -0,0 +1,43 @@
1
+ /** What the run-store benchmarks share: a temporary project seeded with the store's own rows. */
2
+ import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
3
+ import { tmpdir } from 'node:os';
4
+ import { join } from 'node:path';
5
+ import { prepareBenchmarkEnv } from './benchmark-home.ts';
6
+ import { installWindowsIdentityStore } from '../src/delegation/windows-identity-store.ts';
7
+ import { seedRuns } from '../src/runs/run-store.testkit.ts';
8
+ import { RunStore, type RunRecord } from '../src/runs/store.ts';
9
+
10
+ // The store reaches the worker ownership policy, which needs the host's identity store (ADR 0032).
11
+ installWindowsIdentityStore();
12
+
13
+ /** A fixed timestamp `minute` minutes after the fixtures' epoch. */
14
+ export const benchAt = (minute: number) => new Date(Date.UTC(2026, 9, 1) + minute * 60_000).toISOString();
15
+ export const median = (samples: readonly number[]) => [...samples].sort((a, b) => a - b)[Math.floor(samples.length / 2)]!;
16
+
17
+ /** Seed a temporary project with `records(root)`, open its store as `serve` does, run `measure`,
18
+ * then close the store and remove the project. */
19
+ export async function withSeededStore<T>(prefix: string, records: (root: string) => RunRecord[], measure: (store: RunStore, root: string) => Promise<T>): Promise<T> {
20
+ const root = mkdtempSync(join(tmpdir(), prefix));
21
+ try {
22
+ const dataDir = join(root, '.ai/cezar');
23
+ seedRuns(dataDir, records(root));
24
+ const store = RunStore.open(dataDir, { keepLive: true });
25
+ try { return await measure(store, root); } finally { store.close(); }
26
+ } finally {
27
+ rmSync(root, { recursive: true, force: true });
28
+ }
29
+ }
30
+
31
+ /** A benchmark's command-line run: one row per size in a sandboxed home, the table on stdout and
32
+ * the rows as JSON in `out`. */
33
+ export async function runSizes<Row>(sizes: readonly number[], out: string | undefined, measure: (size: number) => Promise<Row>, format: (rows: readonly Row[]) => string): Promise<void> {
34
+ const ownHome = prepareBenchmarkEnv();
35
+ try {
36
+ const rows: Row[] = [];
37
+ for (const size of sizes) rows.push(await measure(size));
38
+ console.log(format(rows));
39
+ if (out) writeFileSync(out, `${JSON.stringify(rows, null, 2)}\n`);
40
+ } finally {
41
+ if (ownHome) rmSync(ownHome, { recursive: true, force: true });
42
+ }
43
+ }
@@ -22,20 +22,15 @@
22
22
  * - Times are the median of `--passes` passes, after one warm-up pass.
23
23
  */
24
24
  import { randomUUID } from 'node:crypto';
25
- import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
26
- import { cpus, tmpdir } from 'node:os';
25
+ import { mkdirSync } from 'node:fs';
26
+ import { cpus } from 'node:os';
27
27
  import { join } from 'node:path';
28
28
  import { performance } from 'node:perf_hooks';
29
29
  import { parseArgs } from 'node:util';
30
30
  import { makeRunRecord } from '@open-mercato/cezar-contract/test-factories.testkit';
31
- import { prepareBenchmarkEnv } from './benchmark-home.ts';
32
- import { installWindowsIdentityStore } from '../src/delegation/windows-identity-store.ts';
31
+ import { benchAt as at, median, runSizes, withSeededStore } from './benchmark-store-fixture.ts';
33
32
  import { reclaimWorktrees } from '../src/runs/retention.ts';
34
- import { seedRuns } from '../src/runs/run-store.testkit.ts';
35
- import { RunStore, type RunRecord } from '../src/runs/store.ts';
36
-
37
- // The store reaches the worker ownership policy, which needs the host's identity store (ADR 0032).
38
- installWindowsIdentityStore();
33
+ import type { RunRecord } from '../src/runs/store.ts';
39
34
 
40
35
  export interface RetentionBenchOptions {
41
36
  /** Destroyed workers in the project. */
@@ -51,8 +46,6 @@ export interface RetentionBenchOptions {
51
46
  export interface RetentionBenchRow { workers: number; parents: number; candidates: number; listMs: number; passMs: number }
52
47
 
53
48
  const pad = (kb: number) => 'x'.repeat(kb * 1024);
54
- const at = (minute: number) => new Date(Date.UTC(2026, 9, 1) + minute * 60_000).toISOString();
55
- const median = (samples: number[]) => [...samples].sort((a, b) => a - b)[Math.floor(samples.length / 2)]!;
56
49
 
57
50
  /** One project's rows: destroyed worker families, then finished roots that still have a directory. */
58
51
  function records(options: RetentionBenchOptions, root: string): RunRecord[] {
@@ -81,30 +74,20 @@ function records(options: RetentionBenchOptions, root: string): RunRecord[] {
81
74
 
82
75
  /** Seed one temporary project, open its store and time `--passes` retention passes. */
83
76
  export async function measureRetention(options: RetentionBenchOptions): Promise<RetentionBenchRow> {
84
- const root = mkdtempSync(join(tmpdir(), 'cez-bench-retention-'));
85
- try {
86
- const dataDir = join(root, '.ai/cezar');
87
- seedRuns(dataDir, records(options, root));
88
- const store = RunStore.open(dataDir, { keepLive: true });
89
- try {
90
- const pass = async () => { const t = performance.now(); await reclaimWorktrees(root, store, 10, { claim: () => null }); return performance.now() - t; };
91
- await pass();
92
- const passMs: number[] = [], listMs: number[] = [];
93
- let candidates = 0;
94
- for (let i = 0; i < options.passes; i++) {
95
- passMs.push(await pass());
96
- const t = performance.now();
97
- candidates = store.listRunsWithWorktree().length;
98
- listMs.push(performance.now() - t);
99
- }
100
- return { workers: options.workers, parents: Math.ceil(options.workers / options.workersPerParent), candidates,
101
- listMs: Math.round(median(listMs)), passMs: Math.round(median(passMs)) };
102
- } finally {
103
- store.close();
77
+ return withSeededStore('cez-bench-retention-', root => records(options, root), async (store, root) => {
78
+ const pass = async () => { const t = performance.now(); await reclaimWorktrees(root, store, 10, { claim: () => null }); return performance.now() - t; };
79
+ await pass();
80
+ const passMs: number[] = [], listMs: number[] = [];
81
+ let candidates = 0;
82
+ for (let i = 0; i < options.passes; i++) {
83
+ passMs.push(await pass());
84
+ const t = performance.now();
85
+ candidates = store.listRunsWithWorktree().length;
86
+ listMs.push(performance.now() - t);
104
87
  }
105
- } finally {
106
- rmSync(root, { recursive: true, force: true });
107
- }
88
+ return { workers: options.workers, parents: Math.ceil(options.workers / options.workersPerParent), candidates,
89
+ listMs: Math.round(median(listMs)), passMs: Math.round(median(passMs)) };
90
+ });
108
91
  }
109
92
 
110
93
  export interface RetentionBenchArgs { sizes: number[]; base: Omit<RetentionBenchOptions, 'workers'>; out: string | undefined }
@@ -123,8 +106,8 @@ export function parseRetentionBenchArgs(args: string[]): RetentionBenchArgs {
123
106
  const sizes = values.workers.split(',').map(Number);
124
107
  const base = { workersPerParent: Number(values['workers-per-parent']), parentKb: Number(values['parent-kb']), workerKb: Number(values['worker-kb']),
125
108
  liveRoots: Number(values['live-roots']), passes: Number(values.passes) };
126
- if (sizes.some(size => !Number.isInteger(size) || size < 0) || !(base.workersPerParent >= 1) || !(base.passes >= 1)) {
127
- throw new Error('--workers takes whole numbers >= 0; --workers-per-parent and --passes take numbers >= 1');
109
+ if (sizes.some(size => !Number.isInteger(size) || size < 0) || !(Number.isInteger(base.workersPerParent) && base.workersPerParent >= 1) || !(Number.isInteger(base.passes) && base.passes >= 1)) {
110
+ throw new Error('--workers takes whole numbers >= 0; --workers-per-parent and --passes take whole numbers >= 1');
128
111
  }
129
112
  return { sizes, base, out: values.out };
130
113
  }
@@ -141,15 +124,7 @@ export function formatRetentionTable(base: RetentionBenchArgs['base'], rows: rea
141
124
 
142
125
  async function main(): Promise<void> {
143
126
  const { sizes, base, out } = parseRetentionBenchArgs(process.argv.slice(2));
144
- const ownHome = prepareBenchmarkEnv();
145
- try {
146
- const rows: RetentionBenchRow[] = [];
147
- for (const workers of sizes) rows.push(await measureRetention({ ...base, workers }));
148
- console.log(formatRetentionTable(base, rows));
149
- if (out) writeFileSync(out, `${JSON.stringify(rows, null, 2)}\n`);
150
- } finally {
151
- if (ownHome) rmSync(ownHome, { recursive: true, force: true });
152
- }
127
+ await runSizes(sizes, out, workers => measureRetention({ ...base, workers }), rows => formatRetentionTable(base, rows));
153
128
  }
154
129
 
155
130
  if (import.meta.main) await main();