lobstah 0.7.10 → 0.7.11

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/dist/runner.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // packages/runner/src/index.ts
2
- import * as fs29 from "node:fs";
3
- import * as path25 from "node:path";
2
+ import * as fs30 from "node:fs";
3
+ import * as path26 from "node:path";
4
4
 
5
5
  // packages/core/dist/types.js
6
6
  var VERBS = ["working", "needs-decision", "blocked", "paused", "done", "failed"];
@@ -9,8 +9,8 @@ var WAITING_ON = ["review", "pr", "deploy", "person", "external"];
9
9
  var WAITING_ON_VERBS = ["paused", "needs-decision", "blocked"];
10
10
 
11
11
  // packages/core/dist/queue.js
12
- import * as fs22 from "node:fs";
13
- import * as path18 from "node:path";
12
+ import * as fs23 from "node:fs";
13
+ import * as path19 from "node:path";
14
14
 
15
15
  // packages/core/dist/paths.js
16
16
  import * as os from "node:os";
@@ -36,8 +36,8 @@ function readDirIfPresent(dir) {
36
36
  try {
37
37
  return fs.readdirSync(dir);
38
38
  } catch (e) {
39
- const code = e.code;
40
- if (code === "ENOENT" || code === "ENOTDIR")
39
+ const code2 = e.code;
40
+ if (code2 === "ENOENT" || code2 === "ENOTDIR")
41
41
  return [];
42
42
  throw e;
43
43
  }
@@ -75,7 +75,7 @@ function evidencePath(id, lane) {
75
75
  }
76
76
 
77
77
  // packages/core/dist/status.js
78
- import * as fs21 from "node:fs";
78
+ import * as fs22 from "node:fs";
79
79
 
80
80
  // packages/core/dist/activity.js
81
81
  import * as fs2 from "node:fs";
@@ -285,8 +285,132 @@ var ActivityTracker = class {
285
285
  };
286
286
 
287
287
  // packages/core/dist/stats.js
288
- import * as fs20 from "node:fs";
289
- import * as path17 from "node:path";
288
+ import * as fs21 from "node:fs";
289
+ import * as path18 from "node:path";
290
+
291
+ // packages/core/dist/dir-lock.js
292
+ import fs3 from "node:fs";
293
+ import * as path3 from "node:path";
294
+ import { randomUUID as randomUUID2 } from "node:crypto";
295
+ var LOCK_CEILING_MS = 60 * 6e4;
296
+ var OWNER = "owner";
297
+ var TRANSIENT = ["EPERM", "EBUSY", "EACCES", "ENOTEMPTY"];
298
+ var pause = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
299
+ var code = (err) => err.code ?? "";
300
+ function pidAlive(pid) {
301
+ try {
302
+ process.kill(pid, 0);
303
+ return true;
304
+ } catch (err) {
305
+ return code(err) === "EPERM";
306
+ }
307
+ }
308
+ function readOwner(lock) {
309
+ try {
310
+ const o = JSON.parse(fs3.readFileSync(path3.join(lock, OWNER), "utf8"));
311
+ return typeof o.pid === "number" && typeof o.token === "string" ? o : void 0;
312
+ } catch {
313
+ return void 0;
314
+ }
315
+ }
316
+ function removeLock(dir, deadline) {
317
+ for (; ; ) {
318
+ try {
319
+ fs3.rmSync(path3.join(dir, OWNER), { force: true });
320
+ fs3.rmdirSync(dir);
321
+ return;
322
+ } catch (err) {
323
+ if (code(err) === "ENOENT")
324
+ return;
325
+ if (!TRANSIENT.includes(code(err)) || Date.now() >= deadline)
326
+ throw err;
327
+ pause(10);
328
+ }
329
+ }
330
+ }
331
+ function takeOver(lock, staleMs, now2) {
332
+ let age;
333
+ try {
334
+ age = now2 - fs3.statSync(lock).mtimeMs;
335
+ } catch {
336
+ return;
337
+ }
338
+ if (age <= staleMs)
339
+ return;
340
+ const owner = readOwner(lock);
341
+ if (owner && age <= LOCK_CEILING_MS && pidAlive(owner.pid))
342
+ return;
343
+ const aside = `${lock}.stale-${process.pid}-${randomUUID2()}`;
344
+ try {
345
+ fs3.renameSync(lock, aside);
346
+ } catch {
347
+ return;
348
+ }
349
+ if (readOwner(aside)?.token !== owner?.token) {
350
+ try {
351
+ fs3.renameSync(aside, lock);
352
+ return;
353
+ } catch {
354
+ }
355
+ }
356
+ try {
357
+ removeLock(aside, Date.now() + 2e3);
358
+ } catch {
359
+ }
360
+ }
361
+ function attempt(lock, staleMs, now2) {
362
+ for (let n = 0; n < 2; n++) {
363
+ try {
364
+ fs3.mkdirSync(lock);
365
+ } catch (err) {
366
+ if (TRANSIENT.includes(code(err)))
367
+ return { busy: true, error: err };
368
+ if (code(err) !== "EEXIST")
369
+ throw err;
370
+ if (n === 0)
371
+ takeOver(lock, staleMs, now2);
372
+ continue;
373
+ }
374
+ const mine = { pid: process.pid, token: randomUUID2(), at: (/* @__PURE__ */ new Date()).toISOString() };
375
+ try {
376
+ fs3.writeFileSync(path3.join(lock, OWNER), JSON.stringify(mine));
377
+ } catch (err) {
378
+ try {
379
+ fs3.rmdirSync(lock);
380
+ } catch {
381
+ }
382
+ throw err;
383
+ }
384
+ let released = false;
385
+ return {
386
+ held: {
387
+ release(deadline = Date.now() + 2e3) {
388
+ if (released)
389
+ return;
390
+ released = true;
391
+ if (readOwner(lock)?.token !== mine.token)
392
+ return;
393
+ removeLock(lock, deadline);
394
+ }
395
+ }
396
+ };
397
+ }
398
+ return { busy: true };
399
+ }
400
+ function withDirLock(lock, action, opts) {
401
+ const deadline = Date.now() + opts.waitMs;
402
+ let a;
403
+ while (!("held" in (a = attempt(lock, opts.staleMs, Date.now())))) {
404
+ if (Date.now() >= deadline)
405
+ throw a.error ?? opts.busy();
406
+ pause(opts.pauseMs ?? 10);
407
+ }
408
+ try {
409
+ return action();
410
+ } finally {
411
+ a.held.release(deadline);
412
+ }
413
+ }
290
414
 
291
415
  // packages/core/dist/worker-metadata.js
292
416
  var WORKER_EFFORTS = ["none", "minimal", "low", "medium", "high", "xhigh", "max", "ultra"];
@@ -379,14 +503,14 @@ function sanitizeWorker(value) {
379
503
  }
380
504
 
381
505
  // packages/core/dist/soak.js
382
- import * as fs18 from "node:fs";
383
- import * as path15 from "node:path";
506
+ import * as fs19 from "node:fs";
507
+ import * as path16 from "node:path";
384
508
 
385
509
  // packages/core/dist/evidence.js
386
- import * as fs3 from "node:fs";
510
+ import * as fs4 from "node:fs";
387
511
  function readEvidence(id, lane) {
388
512
  try {
389
- return JSON.parse(fs3.readFileSync(evidencePath(id, lane), "utf8"));
513
+ return JSON.parse(fs4.readFileSync(evidencePath(id, lane), "utf8"));
390
514
  } catch {
391
515
  return {};
392
516
  }
@@ -394,13 +518,13 @@ function readEvidence(id, lane) {
394
518
  function mergeEvidence(id, lane, patch) {
395
519
  const file2 = evidencePath(id, lane);
396
520
  const tmp = uniqueTempPath(file2);
397
- fs3.writeFileSync(tmp, JSON.stringify({ ...readEvidence(id, lane), ...patch }, null, 2));
521
+ fs4.writeFileSync(tmp, JSON.stringify({ ...readEvidence(id, lane), ...patch }, null, 2));
398
522
  atomicRenameSync(tmp, file2);
399
523
  }
400
524
 
401
525
  // packages/core/dist/pushes.js
402
- import * as fs4 from "node:fs";
403
- import * as path3 from "node:path";
526
+ import * as fs5 from "node:fs";
527
+ import * as path4 from "node:path";
404
528
  var MAX_PUSHES = 20;
405
529
  var PUSH_HEAD = "HEAD";
406
530
  var VALUE_OPTIONS = /* @__PURE__ */ new Set(["-o", "--push-option", "--repo", "--receive-pack", "--exec"]);
@@ -455,18 +579,18 @@ function gitPushTargets(command) {
455
579
  return found ? [...new Set(targets)] : void 0;
456
580
  }
457
581
  function gitDirAt(dir) {
458
- let at = path3.resolve(dir);
582
+ let at = path4.resolve(dir);
459
583
  for (; ; ) {
460
- const dotGit = path3.join(at, ".git");
584
+ const dotGit = path4.join(at, ".git");
461
585
  try {
462
- const stat = fs4.statSync(dotGit);
586
+ const stat = fs5.statSync(dotGit);
463
587
  if (stat.isDirectory())
464
588
  return dotGit;
465
- const m = /^gitdir:\s*(.+)$/m.exec(fs4.readFileSync(dotGit, "utf8"));
466
- return m ? path3.resolve(at, m[1].trim()) : void 0;
589
+ const m = /^gitdir:\s*(.+)$/m.exec(fs5.readFileSync(dotGit, "utf8"));
590
+ return m ? path4.resolve(at, m[1].trim()) : void 0;
467
591
  } catch {
468
592
  }
469
- const up = path3.dirname(at);
593
+ const up = path4.dirname(at);
470
594
  if (up === at)
471
595
  return void 0;
472
596
  at = up;
@@ -477,7 +601,7 @@ function currentBranchAt(dir) {
477
601
  if (!gitDir)
478
602
  return void 0;
479
603
  try {
480
- const m = /^ref:\s*refs\/heads\/(.+)$/m.exec(fs4.readFileSync(path3.join(gitDir, "HEAD"), "utf8"));
604
+ const m = /^ref:\s*refs\/heads\/(.+)$/m.exec(fs5.readFileSync(path4.join(gitDir, "HEAD"), "utf8"));
481
605
  return m ? m[1].trim() : void 0;
482
606
  } catch {
483
607
  return void 0;
@@ -496,13 +620,13 @@ function recordPush(id, lane, branches, at = (/* @__PURE__ */ new Date()).toISOS
496
620
  }
497
621
 
498
622
  // packages/core/dist/notices.js
499
- import fs16 from "node:fs";
500
- import * as path13 from "node:path";
623
+ import fs17 from "node:fs";
624
+ import * as path14 from "node:path";
501
625
 
502
626
  // packages/core/dist/config.js
503
- import * as fs5 from "node:fs";
627
+ import * as fs6 from "node:fs";
504
628
  import * as os2 from "node:os";
505
- import * as path4 from "node:path";
629
+ import * as path5 from "node:path";
506
630
 
507
631
  // node_modules/.pnpm/smol-toml@1.8.0/node_modules/smol-toml/dist/date.js
508
632
  var DATE_TIME_RE = /^(\d{4}-\d{2}-\d{2})?[T ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|[-+]\d{2}:\d{2})?$/i;
@@ -1331,6 +1455,49 @@ function parseHooks(raw) {
1331
1455
  out.pickupNotify = { command: command(h.pickupNotify, "[hooks.pickupNotify]") };
1332
1456
  return out;
1333
1457
  }
1458
+ function parseCodexRules(raw) {
1459
+ const out = { forbidden: [], prompt: [], allow: [] };
1460
+ if (raw === void 0)
1461
+ return out;
1462
+ if (typeof raw !== "object" || raw === null || Array.isArray(raw))
1463
+ throw new Error("[permissions.codex] must be a table");
1464
+ for (const [key, value] of Object.entries(raw)) {
1465
+ if (key !== "forbidden" && key !== "prompt" && key !== "allow")
1466
+ throw new Error(`[permissions.codex].${key} is not a key: use forbidden, prompt, or allow`);
1467
+ const prefix = (v) => Array.isArray(v) && v.length > 0 && v.every((w) => typeof w === "string" && w.trim() && !/\s/.test(w));
1468
+ if (!Array.isArray(value) || !value.every(prefix)) {
1469
+ throw new Error(`[permissions.codex].${key} must be a list of command prefixes, each a list of words, e.g. [["wrangler", "dev"]]`);
1470
+ }
1471
+ const seen = /* @__PURE__ */ new Set();
1472
+ out[key] = value.filter((p) => !seen.has(JSON.stringify(p)) && seen.add(JSON.stringify(p)));
1473
+ }
1474
+ return out;
1475
+ }
1476
+ var PERMISSION_RULE = /^[A-Za-z][\w-]*(\(.+\))?$/;
1477
+ function parsePermissions(raw) {
1478
+ const out = { environment: [], allow: [], deny: [], codex: parseCodexRules(void 0) };
1479
+ if (raw === void 0)
1480
+ return out;
1481
+ if (typeof raw !== "object" || raw === null || Array.isArray(raw))
1482
+ throw new Error("[permissions] must be a table");
1483
+ for (const [key, value] of Object.entries(raw)) {
1484
+ if (key === "codex") {
1485
+ out.codex = parseCodexRules(value);
1486
+ continue;
1487
+ }
1488
+ if (key !== "environment" && key !== "allow" && key !== "deny")
1489
+ throw new Error(`[permissions].${key} is not a key: use environment, allow, deny, or [permissions.codex]`);
1490
+ if (!Array.isArray(value) || value.some((v) => typeof v !== "string" || !v.trim()))
1491
+ throw new Error(`[permissions].${key} must be a list of non-empty strings`);
1492
+ if (key !== "environment") {
1493
+ const bad = value.find((v) => !PERMISSION_RULE.test(v));
1494
+ if (bad !== void 0)
1495
+ throw new Error(`[permissions].${key}: "${bad}" is not a permission rule \u2014 write Tool or Tool(specifier), e.g. Bash(npm run test *)`);
1496
+ }
1497
+ out[key] = [...new Set(value)];
1498
+ }
1499
+ return out;
1500
+ }
1334
1501
  var ATTENTION_KINDS = ["question", "decision", "landed", "pr:draft", "pr:review", "pr:checks", "pr:conflict", "pr:ready", "report", "stack-ready", "review"];
1335
1502
  var DEFAULT_ATTENTION_KINDS = ["question", "decision", "pr:ready", "pr:review", "pr:conflict", "pr:checks"];
1336
1503
  function parseAttentionKinds(raw) {
@@ -1402,14 +1569,14 @@ function withConfigPath(parse2) {
1402
1569
  }
1403
1570
  }
1404
1571
  function configPath() {
1405
- return path4.join(lobstahHome(), "config.toml");
1572
+ return path5.join(lobstahHome(), "config.toml");
1406
1573
  }
1407
1574
  function expandHome(p) {
1408
- return p.startsWith("~/") ? path4.join(os2.homedir(), p.slice(2)) : p;
1575
+ return p.startsWith("~/") ? path5.join(os2.homedir(), p.slice(2)) : p;
1409
1576
  }
1410
1577
  function loadConfig() {
1411
1578
  const file2 = configPath();
1412
- const raw = fs5.existsSync(file2) ? parse(fs5.readFileSync(file2, "utf8")) : {};
1579
+ const raw = fs6.existsSync(file2) ? parse(fs6.readFileSync(file2, "utf8")) : {};
1413
1580
  const petOpen = raw.pet?.open ?? "tab";
1414
1581
  if (!["tab", "app", "helm"].includes(petOpen))
1415
1582
  throw new Error(`[pet].open must be "tab", "app", or "helm" in ${configPath()}`);
@@ -1501,7 +1668,8 @@ function loadConfig() {
1501
1668
  remindSecs: raw.remindSecs !== void 0 ? Number(raw.remindSecs) : void 0,
1502
1669
  readySettleSecs,
1503
1670
  attentionKinds: parseAttentionKinds(raw.attentionKinds),
1504
- reviews: withConfigPath(() => parseReviews(raw.reviews, reposRaw))
1671
+ reviews: withConfigPath(() => parseReviews(raw.reviews, reposRaw)),
1672
+ permissions: withConfigPath(() => parsePermissions(raw.permissions))
1505
1673
  };
1506
1674
  }
1507
1675
  function resolveDispatch(d, cfg) {
@@ -1545,25 +1713,25 @@ function firstMeaningfulLine(...outputs) {
1545
1713
  }
1546
1714
 
1547
1715
  // packages/core/dist/pr-poll.js
1548
- import * as fs9 from "node:fs";
1549
- import * as path8 from "node:path";
1716
+ import * as fs10 from "node:fs";
1717
+ import * as path9 from "node:path";
1550
1718
 
1551
1719
  // packages/core/dist/prs.js
1552
- import * as fs6 from "node:fs";
1553
- import * as path5 from "node:path";
1720
+ import * as fs7 from "node:fs";
1721
+ import * as path6 from "node:path";
1554
1722
  function prsDir() {
1555
- return path5.join(lobstahHome(), "prs");
1723
+ return path6.join(lobstahHome(), "prs");
1556
1724
  }
1557
1725
  function prRecordFile(key) {
1558
1726
  const ref = parsePrRef(key);
1559
1727
  if (!ref)
1560
1728
  throw new Error(`not a PR key: ${key}`);
1561
1729
  const safe = (s) => s.replace(/[^A-Za-z0-9._-]/g, "_");
1562
- return path5.join(prsDir(), `${safe(ref.owner)}__${safe(ref.repo)}__${ref.number}.json`);
1730
+ return path6.join(prsDir(), `${safe(ref.owner)}__${safe(ref.repo)}__${ref.number}.json`);
1563
1731
  }
1564
1732
  function readPr(key) {
1565
1733
  try {
1566
- return JSON.parse(fs6.readFileSync(prRecordFile(key), "utf8"));
1734
+ return JSON.parse(fs7.readFileSync(prRecordFile(key), "utf8"));
1567
1735
  } catch {
1568
1736
  return void 0;
1569
1737
  }
@@ -1571,13 +1739,13 @@ function readPr(key) {
1571
1739
  function readPrs() {
1572
1740
  let files;
1573
1741
  try {
1574
- files = fs6.readdirSync(prsDir()).filter((f) => f.endsWith(".json"));
1742
+ files = fs7.readdirSync(prsDir()).filter((f) => f.endsWith(".json"));
1575
1743
  } catch {
1576
1744
  return [];
1577
1745
  }
1578
1746
  return files.flatMap((f) => {
1579
1747
  try {
1580
- const r = JSON.parse(fs6.readFileSync(path5.join(prsDir(), f), "utf8"));
1748
+ const r = JSON.parse(fs7.readFileSync(path6.join(prsDir(), f), "utf8"));
1581
1749
  return typeof r.key === "string" && typeof r.url === "string" ? [r] : [];
1582
1750
  } catch {
1583
1751
  return [];
@@ -1586,16 +1754,16 @@ function readPrs() {
1586
1754
  }
1587
1755
 
1588
1756
  // packages/core/dist/watch.js
1589
- import fs8 from "node:fs";
1590
- import * as path7 from "node:path";
1757
+ import fs9 from "node:fs";
1758
+ import * as path8 from "node:path";
1591
1759
 
1592
1760
  // packages/core/dist/github-budget.js
1593
- import * as fs7 from "node:fs";
1594
- import * as path6 from "node:path";
1595
- var file = () => path6.join(lobstahHome(), "github-budget.json");
1761
+ import * as fs8 from "node:fs";
1762
+ import * as path7 from "node:path";
1763
+ var file = () => path7.join(lobstahHome(), "github-budget.json");
1596
1764
  function read() {
1597
1765
  try {
1598
- return JSON.parse(fs7.readFileSync(file(), "utf8"));
1766
+ return JSON.parse(fs8.readFileSync(file(), "utf8"));
1599
1767
  } catch {
1600
1768
  return { resources: {} };
1601
1769
  }
@@ -1609,27 +1777,27 @@ function githubBlockedUntil(now2 = Date.now()) {
1609
1777
 
1610
1778
  // packages/core/dist/watch.js
1611
1779
  function watchesDir() {
1612
- return path7.join(lobstahHome(), "watches");
1780
+ return path8.join(lobstahHome(), "watches");
1613
1781
  }
1614
1782
  function slug(key) {
1615
1783
  return key.replace(/[^A-Za-z0-9._-]+/g, "-");
1616
1784
  }
1617
1785
  function watchPath(key) {
1618
- return path7.join(watchesDir(), `${slug(key)}.json`);
1786
+ return path8.join(watchesDir(), `${slug(key)}.json`);
1619
1787
  }
1620
1788
  function readWatch(key) {
1621
1789
  try {
1622
- return JSON.parse(fs8.readFileSync(watchPath(key), "utf8"));
1790
+ return JSON.parse(fs9.readFileSync(watchPath(key), "utf8"));
1623
1791
  } catch {
1624
1792
  return void 0;
1625
1793
  }
1626
1794
  }
1627
1795
 
1628
1796
  // packages/core/dist/pr-poll.js
1629
- var cycleFile = (repo) => path8.join(lobstahHome(), "pr-polls", `${repo.replace(/[^\w.-]/g, "_")}.json`);
1797
+ var cycleFile = (repo) => path9.join(lobstahHome(), "pr-polls", `${repo.replace(/[^\w.-]/g, "_")}.json`);
1630
1798
  var readCycle = (repo) => {
1631
1799
  try {
1632
- return JSON.parse(fs9.readFileSync(cycleFile(repo), "utf8"));
1800
+ return JSON.parse(fs10.readFileSync(cycleFile(repo), "utf8"));
1633
1801
  } catch {
1634
1802
  return void 0;
1635
1803
  }
@@ -1722,23 +1890,23 @@ function parseUnresolvedThreads(stdout) {
1722
1890
  }
1723
1891
 
1724
1892
  // packages/core/dist/worktrees.js
1725
- import * as fs10 from "node:fs";
1726
- import * as path9 from "node:path";
1893
+ import * as fs11 from "node:fs";
1894
+ import * as path10 from "node:path";
1727
1895
  var LANES = ["work", "chore"];
1728
1896
  function worktreePath(id) {
1729
- return path9.join(lobstahHome(), "worktrees", id);
1897
+ return path10.join(lobstahHome(), "worktrees", id);
1730
1898
  }
1731
1899
  function readRecord(file2) {
1732
1900
  try {
1733
- const r = JSON.parse(fs10.readFileSync(file2, "utf8"));
1901
+ const r = JSON.parse(fs11.readFileSync(file2, "utf8"));
1734
1902
  return typeof r.path === "string" ? r : void 0;
1735
1903
  } catch {
1736
1904
  return void 0;
1737
1905
  }
1738
1906
  }
1739
1907
  function ownerOfPath(p) {
1740
- const rel = path9.relative(path9.join(lobstahHome(), "worktrees"), p);
1741
- if (!rel || rel.startsWith("..") || path9.isAbsolute(rel))
1908
+ const rel = path10.relative(path10.join(lobstahHome(), "worktrees"), p);
1909
+ if (!rel || rel.startsWith("..") || path10.isAbsolute(rel))
1742
1910
  return void 0;
1743
1911
  return rel.split(/[\\/]/)[0];
1744
1912
  }
@@ -1751,7 +1919,7 @@ function dispatchWorktree(id, lane) {
1751
1919
  }
1752
1920
  const dirs = laneDirs(l);
1753
1921
  for (const dir of [dirs.active, dirs.done]) {
1754
- const rec = readRecord(path9.join(dir, id, "worktree.json"));
1922
+ const rec = readRecord(path10.join(dir, id, "worktree.json"));
1755
1923
  if (rec) {
1756
1924
  const owner = rec.of ?? ownerOfPath(rec.path) ?? id;
1757
1925
  return { path: rec.path, owner, reused: owner !== id };
@@ -1763,7 +1931,7 @@ function dispatchWorktree(id, lane) {
1763
1931
  function laneOf(id) {
1764
1932
  for (const l of LANES) {
1765
1933
  const d = laneDirs(l);
1766
- if (fs10.existsSync(path9.join(d.queue, `${id}.json`)) || fs10.existsSync(path9.join(d.active, id)) || fs10.existsSync(path9.join(d.done, id))) {
1934
+ if (fs11.existsSync(path10.join(d.queue, `${id}.json`)) || fs11.existsSync(path10.join(d.active, id)) || fs11.existsSync(path10.join(d.done, id))) {
1767
1935
  return l;
1768
1936
  }
1769
1937
  }
@@ -1783,7 +1951,7 @@ function followUpAncestors(id, lane) {
1783
1951
  function chainWorktree(followUp) {
1784
1952
  for (const id of [followUp, ...followUpAncestors(followUp)]) {
1785
1953
  const wt = dispatchWorktree(id, laneOf(id));
1786
- if (fs10.existsSync(wt.path))
1954
+ if (fs11.existsSync(wt.path))
1787
1955
  return { ...wt, from: id };
1788
1956
  }
1789
1957
  return void 0;
@@ -1798,27 +1966,27 @@ function processAlive(pid) {
1798
1966
  }
1799
1967
  }
1800
1968
  function worktreeGitDir(wt) {
1801
- const dotGit = path9.join(wt, ".git");
1969
+ const dotGit = path10.join(wt, ".git");
1802
1970
  try {
1803
- const st = fs10.statSync(dotGit);
1971
+ const st = fs11.statSync(dotGit);
1804
1972
  if (st.isDirectory())
1805
1973
  return dotGit;
1806
- const m = /^gitdir:\s*(.+?)\s*$/m.exec(fs10.readFileSync(dotGit, "utf8"));
1807
- return m ? path9.resolve(wt, m[1]) : void 0;
1974
+ const m = /^gitdir:\s*(.+?)\s*$/m.exec(fs11.readFileSync(dotGit, "utf8"));
1975
+ return m ? path10.resolve(wt, m[1]) : void 0;
1808
1976
  } catch {
1809
1977
  return void 0;
1810
1978
  }
1811
1979
  }
1812
1980
  function worktreeLockFile(wt) {
1813
1981
  const gitDir = worktreeGitDir(wt);
1814
- return gitDir ? path9.join(gitDir, "lobstah.lock") : void 0;
1982
+ return gitDir ? path10.join(gitDir, "lobstah.lock") : void 0;
1815
1983
  }
1816
1984
  function readWorktreeLock(wt) {
1817
1985
  const file2 = worktreeLockFile(wt);
1818
1986
  if (!file2)
1819
1987
  return void 0;
1820
1988
  try {
1821
- return JSON.parse(fs10.readFileSync(file2, "utf8"));
1989
+ return JSON.parse(fs11.readFileSync(file2, "utf8"));
1822
1990
  } catch {
1823
1991
  return void 0;
1824
1992
  }
@@ -1826,7 +1994,7 @@ function readWorktreeLock(wt) {
1826
1994
  function lockIsLive(lock) {
1827
1995
  if (lock.kind === "warm")
1828
1996
  return processAlive(lock.pid) && Date.now() - (Date.parse(lock.at) || 0) < WARM_LOCK_MAX_MS;
1829
- return fs10.existsSync(path9.join(laneDirs(lock.lane).active, lock.id));
1997
+ return fs11.existsSync(path10.join(laneDirs(lock.lane).active, lock.id));
1830
1998
  }
1831
1999
  function worktreeHolder(wt) {
1832
2000
  const lock = readWorktreeLock(wt);
@@ -1837,9 +2005,9 @@ function acquireWorktreeLock(wt, id, lane, kind) {
1837
2005
  const mine = { id, lane, pid: process.pid, at: (/* @__PURE__ */ new Date()).toISOString(), ...kind ? { kind } : {} };
1838
2006
  if (!file2)
1839
2007
  return { id: "(no git dir)", lane, pid: 0, at: mine.at };
1840
- for (let attempt = 0; attempt < 3; attempt++) {
2008
+ for (let attempt2 = 0; attempt2 < 3; attempt2++) {
1841
2009
  try {
1842
- fs10.writeFileSync(file2, JSON.stringify(mine, null, 2), { flag: "wx" });
2010
+ fs11.writeFileSync(file2, JSON.stringify(mine, null, 2), { flag: "wx" });
1843
2011
  return void 0;
1844
2012
  } catch (err) {
1845
2013
  if (err.code !== "EEXIST")
@@ -1847,7 +2015,7 @@ function acquireWorktreeLock(wt, id, lane, kind) {
1847
2015
  }
1848
2016
  let raw;
1849
2017
  try {
1850
- raw = fs10.readFileSync(file2, "utf8");
2018
+ raw = fs11.readFileSync(file2, "utf8");
1851
2019
  } catch {
1852
2020
  continue;
1853
2021
  }
@@ -1858,14 +2026,14 @@ function acquireWorktreeLock(wt, id, lane, kind) {
1858
2026
  held2 = void 0;
1859
2027
  }
1860
2028
  if (held2?.id === id) {
1861
- fs10.writeFileSync(file2, JSON.stringify(mine, null, 2));
2029
+ fs11.writeFileSync(file2, JSON.stringify(mine, null, 2));
1862
2030
  return void 0;
1863
2031
  }
1864
2032
  if (held2 && lockIsLive(held2))
1865
2033
  return held2;
1866
2034
  try {
1867
- if (fs10.readFileSync(file2, "utf8") === raw)
1868
- fs10.rmSync(file2, { force: true });
2035
+ if (fs11.readFileSync(file2, "utf8") === raw)
2036
+ fs11.rmSync(file2, { force: true });
1869
2037
  } catch {
1870
2038
  }
1871
2039
  }
@@ -1877,22 +2045,22 @@ function releaseWorktreeLock(wt, id) {
1877
2045
  if (!file2)
1878
2046
  return;
1879
2047
  if (readWorktreeLock(wt)?.id === id)
1880
- fs10.rmSync(file2, { force: true });
2048
+ fs11.rmSync(file2, { force: true });
1881
2049
  }
1882
2050
 
1883
2051
  // packages/core/dist/events.js
1884
- import * as fs11 from "node:fs";
2052
+ import * as fs12 from "node:fs";
1885
2053
  function appendEvent(id, lane, ev) {
1886
- fs11.appendFileSync(eventsPath(id, lane), `${JSON.stringify(ev)}
2054
+ fs12.appendFileSync(eventsPath(id, lane), `${JSON.stringify(ev)}
1887
2055
  `);
1888
2056
  }
1889
2057
  function touchEvents(id, lane, at = /* @__PURE__ */ new Date()) {
1890
2058
  const file2 = eventsPath(id, lane);
1891
2059
  try {
1892
- fs11.utimesSync(file2, at, at);
2060
+ fs12.utimesSync(file2, at, at);
1893
2061
  } catch {
1894
- fs11.appendFileSync(file2, "");
1895
- fs11.utimesSync(file2, at, at);
2062
+ fs12.appendFileSync(file2, "");
2063
+ fs12.utimesSync(file2, at, at);
1896
2064
  }
1897
2065
  }
1898
2066
 
@@ -1906,31 +2074,31 @@ function isFinished(id, lane) {
1906
2074
  }
1907
2075
 
1908
2076
  // packages/core/dist/pools.js
1909
- import * as fs12 from "node:fs";
1910
- import * as path10 from "node:path";
2077
+ import * as fs13 from "node:fs";
2078
+ import * as path11 from "node:path";
1911
2079
  function poolsRoot() {
1912
- return path10.join(lobstahHome(), "pools");
2080
+ return path11.join(lobstahHome(), "pools");
1913
2081
  }
1914
2082
  function poolDir(pool) {
1915
- return path10.join(poolsRoot(), pool);
2083
+ return path11.join(poolsRoot(), pool);
1916
2084
  }
1917
2085
  function poolSlotPath(pool, slot) {
1918
- return path10.join(poolDir(pool), String(slot));
2086
+ return path11.join(poolDir(pool), String(slot));
1919
2087
  }
1920
2088
  function slotsDir(pool) {
1921
- return path10.join(poolDir(pool), ".slots");
2089
+ return path11.join(poolDir(pool), ".slots");
1922
2090
  }
1923
2091
  function poolSlotOf(p) {
1924
2092
  const real = (x) => {
1925
2093
  try {
1926
- return fs12.realpathSync.native(x);
2094
+ return fs13.realpathSync.native(x);
1927
2095
  } catch {
1928
- return path10.resolve(x);
2096
+ return path11.resolve(x);
1929
2097
  }
1930
2098
  };
1931
- for (const [rootDir, dir] of [[poolsRoot(), path10.resolve(p)], [real(poolsRoot()), real(p)]]) {
1932
- const rel = path10.relative(rootDir, dir);
1933
- if (!rel || rel.startsWith("..") || path10.isAbsolute(rel))
2099
+ for (const [rootDir, dir] of [[poolsRoot(), path11.resolve(p)], [real(poolsRoot()), real(p)]]) {
2100
+ const rel = path11.relative(rootDir, dir);
2101
+ if (!rel || rel.startsWith("..") || path11.isAbsolute(rel))
1934
2102
  continue;
1935
2103
  const parts = rel.split(/[\\/]/);
1936
2104
  if (parts.length !== 2 || !/^[1-9][0-9]*$/.test(parts[1]))
@@ -1944,20 +2112,20 @@ function poolSlotLabel(pool, slot) {
1944
2112
  }
1945
2113
  function readJson(file2) {
1946
2114
  try {
1947
- return JSON.parse(fs12.readFileSync(file2, "utf8"));
2115
+ return JSON.parse(fs13.readFileSync(file2, "utf8"));
1948
2116
  } catch {
1949
2117
  return void 0;
1950
2118
  }
1951
2119
  }
1952
2120
  function writeJson(file2, value) {
1953
- fs12.mkdirSync(path10.dirname(file2), { recursive: true });
2121
+ fs13.mkdirSync(path11.dirname(file2), { recursive: true });
1954
2122
  const tmp = uniqueTempPath(file2);
1955
- fs12.writeFileSync(tmp, JSON.stringify(value, null, 2));
2123
+ fs13.writeFileSync(tmp, JSON.stringify(value, null, 2));
1956
2124
  atomicRenameSync(tmp, file2);
1957
2125
  }
1958
- var metaFile = (pool, slot) => path10.join(slotsDir(pool), `${slot}.json`);
1959
- var claimFile = (pool, slot) => path10.join(slotsDir(pool), `${slot}.claim.json`);
1960
- var outFile = (pool, slot) => path10.join(slotsDir(pool), `${slot}.out.json`);
2126
+ var metaFile = (pool, slot) => path11.join(slotsDir(pool), `${slot}.json`);
2127
+ var claimFile = (pool, slot) => path11.join(slotsDir(pool), `${slot}.claim.json`);
2128
+ var outFile = (pool, slot) => path11.join(slotsDir(pool), `${slot}.out.json`);
1961
2129
  function readSlotMeta(pool, slot) {
1962
2130
  return readJson(metaFile(pool, slot)) ?? {};
1963
2131
  }
@@ -1977,7 +2145,7 @@ function writeSlotOut(pool, slot, out) {
1977
2145
  writeJson(outFile(pool, slot), out);
1978
2146
  }
1979
2147
  function clearSlotOut(pool, slot) {
1980
- fs12.rmSync(outFile(pool, slot), { force: true });
2148
+ fs13.rmSync(outFile(pool, slot), { force: true });
1981
2149
  }
1982
2150
  function dispatchHolder(dir) {
1983
2151
  const lock = readWorktreeLock(dir);
@@ -1987,7 +2155,7 @@ function poolSlotView(pool, slot) {
1987
2155
  const dir = poolSlotPath(pool, slot);
1988
2156
  const lastClaim = readSlotClaim(pool, slot)?.id;
1989
2157
  const base = { slot, path: dir, ...lastClaim ? { lastClaim } : {} };
1990
- if (!fs12.existsSync(dir)) {
2158
+ if (!fs13.existsSync(dir)) {
1991
2159
  const meta2 = readSlotMeta(pool, slot);
1992
2160
  return { ...base, state: "missing", ...meta2.error ? { reason: meta2.error } : {} };
1993
2161
  }
@@ -2002,8 +2170,8 @@ function poolSlotView(pool, slot) {
2002
2170
  return { ...base, state: "warming", ...meta.error ? { reason: meta.error } : {} };
2003
2171
  return { ...base, state: "free" };
2004
2172
  }
2005
- var warmStateFile = (pool) => path10.join(poolDir(pool), ".warm-state.json");
2006
- var warmLockFile = (pool) => path10.join(poolDir(pool), ".warm.lock");
2173
+ var warmStateFile = (pool) => path11.join(poolDir(pool), ".warm-state.json");
2174
+ var warmLockFile = (pool) => path11.join(poolDir(pool), ".warm.lock");
2007
2175
  var POOL_WARM_MAX_MS = 60 * 6e4;
2008
2176
  function readPoolWarmState(pool) {
2009
2177
  return readJson(warmStateFile(pool)) ?? {};
@@ -2011,7 +2179,7 @@ function readPoolWarmState(pool) {
2011
2179
  function writePoolWarmState(pool, state) {
2012
2180
  writeJson(warmStateFile(pool), state);
2013
2181
  }
2014
- function pidAlive(pid) {
2182
+ function pidAlive2(pid) {
2015
2183
  try {
2016
2184
  process.kill(pid, 0);
2017
2185
  return true;
@@ -2021,19 +2189,19 @@ function pidAlive(pid) {
2021
2189
  }
2022
2190
  function poolWarmRunning(pool, now2 = Date.now()) {
2023
2191
  const lock = readJson(warmLockFile(pool));
2024
- return !!lock && pidAlive(lock.pid) && now2 - (Date.parse(lock.at) || 0) < POOL_WARM_MAX_MS;
2192
+ return !!lock && pidAlive2(lock.pid) && now2 - (Date.parse(lock.at) || 0) < POOL_WARM_MAX_MS;
2025
2193
  }
2026
2194
  function takePoolWarmLock(pool) {
2027
2195
  const file2 = warmLockFile(pool);
2028
- fs12.mkdirSync(path10.dirname(file2), { recursive: true });
2196
+ fs13.mkdirSync(path11.dirname(file2), { recursive: true });
2029
2197
  const mine = JSON.stringify({ pid: process.pid, at: (/* @__PURE__ */ new Date()).toISOString() });
2030
- for (let attempt = 0; attempt < 2; attempt++) {
2198
+ for (let attempt2 = 0; attempt2 < 2; attempt2++) {
2031
2199
  try {
2032
- fs12.writeFileSync(file2, mine, { flag: "wx" });
2200
+ fs13.writeFileSync(file2, mine, { flag: "wx" });
2033
2201
  return () => {
2034
2202
  try {
2035
- if (fs12.readFileSync(file2, "utf8") === mine)
2036
- fs12.rmSync(file2, { force: true });
2203
+ if (fs13.readFileSync(file2, "utf8") === mine)
2204
+ fs13.rmSync(file2, { force: true });
2037
2205
  } catch {
2038
2206
  }
2039
2207
  };
@@ -2043,7 +2211,7 @@ function takePoolWarmLock(pool) {
2043
2211
  }
2044
2212
  if (poolWarmRunning(pool))
2045
2213
  return void 0;
2046
- fs12.rmSync(file2, { force: true });
2214
+ fs13.rmSync(file2, { force: true });
2047
2215
  }
2048
2216
  return void 0;
2049
2217
  }
@@ -2052,10 +2220,10 @@ var POOL_FETCH_MS = 10 * 6e4;
2052
2220
  var POOL_RECHECK_MS = 5 * 6e4;
2053
2221
 
2054
2222
  // packages/core/dist/disk.js
2055
- import * as fs13 from "node:fs";
2223
+ import * as fs14 from "node:fs";
2056
2224
  var GB = 1024 ** 3;
2057
2225
  var statfsFreeBytes = (dir) => {
2058
- const s = fs13.statfsSync(dir);
2226
+ const s = fs14.statfsSync(dir);
2059
2227
  return Number(s.bavail) * Number(s.bsize);
2060
2228
  };
2061
2229
  function formatGB(bytes) {
@@ -2063,30 +2231,30 @@ function formatGB(bytes) {
2063
2231
  }
2064
2232
 
2065
2233
  // packages/core/dist/inbox.js
2066
- import * as fs14 from "node:fs";
2067
- import * as path11 from "node:path";
2234
+ import * as fs15 from "node:fs";
2235
+ import * as path12 from "node:path";
2068
2236
  var metaName = (file2) => file2.replace(/\.msg$/, ".meta.json");
2069
2237
  function inboxDir(id, lane) {
2070
- return path11.join(laneDirs(lane).inbox, id);
2238
+ return path12.join(laneDirs(lane).inbox, id);
2071
2239
  }
2072
2240
  function unhandled(id, lane) {
2073
2241
  const dir = inboxDir(id, lane);
2074
- return readDirIfPresent(dir).filter((f) => f.endsWith(".msg")).sort().map((f) => ({ file: f, text: fs14.readFileSync(path11.join(dir, f), "utf8") }));
2242
+ return readDirIfPresent(dir).filter((f) => f.endsWith(".msg")).sort().map((f) => ({ file: f, text: fs15.readFileSync(path12.join(dir, f), "utf8") }));
2075
2243
  }
2076
2244
  function acknowledge(id, lane, file2) {
2077
2245
  const dir = inboxDir(id, lane);
2078
- fs14.mkdirSync(path11.join(dir, "handled"), { recursive: true });
2079
- fs14.renameSync(path11.join(dir, file2), path11.join(dir, "handled", file2));
2246
+ fs15.mkdirSync(path12.join(dir, "handled"), { recursive: true });
2247
+ fs15.renameSync(path12.join(dir, file2), path12.join(dir, "handled", file2));
2080
2248
  try {
2081
- fs14.renameSync(path11.join(dir, metaName(file2)), path11.join(dir, "handled", metaName(file2)));
2249
+ fs15.renameSync(path12.join(dir, metaName(file2)), path12.join(dir, "handled", metaName(file2)));
2082
2250
  } catch {
2083
2251
  }
2084
2252
  }
2085
2253
 
2086
2254
  // packages/core/dist/resume.js
2087
- import * as fs15 from "node:fs";
2255
+ import * as fs16 from "node:fs";
2088
2256
  import * as os3 from "node:os";
2089
- import * as path12 from "node:path";
2257
+ import * as path13 from "node:path";
2090
2258
  import { spawnSync as spawnSync2 } from "node:child_process";
2091
2259
  var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-([0-9a-f])[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
2092
2260
  function harnessFromSessionId(sessionId) {
@@ -2097,7 +2265,7 @@ function claimOf(id, lane) {
2097
2265
  const dirs = laneDirs(lane);
2098
2266
  for (const dir of [dirs.active, dirs.done]) {
2099
2267
  try {
2100
- return JSON.parse(fs15.readFileSync(path12.join(dir, id, "claim.json"), "utf8"));
2268
+ return JSON.parse(fs16.readFileSync(path13.join(dir, id, "claim.json"), "utf8"));
2101
2269
  } catch {
2102
2270
  }
2103
2271
  }
@@ -2147,7 +2315,7 @@ function isUnresumable(error) {
2147
2315
  return error !== void 0 && UNRESUMABLE.test(error);
2148
2316
  }
2149
2317
  function worktreeProgress(worktree, trunk) {
2150
- if (!worktree || !fs15.existsSync(worktree))
2318
+ if (!worktree || !fs16.existsSync(worktree))
2151
2319
  return "No worktree progress recorded.";
2152
2320
  const git2 = (...a) => spawnSync2("git", a, { cwd: worktree, encoding: "utf8" }).stdout?.trim() ?? "";
2153
2321
  const commits = trunk ? git2("log", "--oneline", `origin/${trunk}..HEAD`) : git2("log", "--oneline", "-15");
@@ -2180,31 +2348,31 @@ function handoffNote(fromHarness, progress, why) {
2180
2348
  ${progress}`;
2181
2349
  }
2182
2350
  function codexHome(env = process.env) {
2183
- return env.CODEX_HOME ?? path12.join(os3.homedir(), ".codex");
2351
+ return env.CODEX_HOME ?? path13.join(os3.homedir(), ".codex");
2184
2352
  }
2185
2353
  function codexRolloutFile(threadId, home = codexHome()) {
2186
2354
  const suffix = `-${threadId}.jsonl`;
2187
2355
  const walk = (dir, depth) => {
2188
2356
  let entries;
2189
2357
  try {
2190
- entries = fs15.readdirSync(dir, { withFileTypes: true });
2358
+ entries = fs16.readdirSync(dir, { withFileTypes: true });
2191
2359
  } catch {
2192
2360
  return void 0;
2193
2361
  }
2194
2362
  for (const e of entries) {
2195
2363
  if (e.isFile() && e.name.startsWith("rollout-") && e.name.endsWith(suffix))
2196
- return path12.join(dir, e.name);
2364
+ return path13.join(dir, e.name);
2197
2365
  }
2198
2366
  if (depth === 0)
2199
2367
  return void 0;
2200
2368
  for (const e of entries.filter((x) => x.isDirectory()).sort((a, b) => b.name.localeCompare(a.name))) {
2201
- const hit = walk(path12.join(dir, e.name), depth - 1);
2369
+ const hit = walk(path13.join(dir, e.name), depth - 1);
2202
2370
  if (hit)
2203
2371
  return hit;
2204
2372
  }
2205
2373
  return void 0;
2206
2374
  };
2207
- return walk(path12.join(home, "sessions"), 3) ?? walk(path12.join(home, "archived_sessions"), 0);
2375
+ return walk(path13.join(home, "sessions"), 3) ?? walk(path13.join(home, "archived_sessions"), 0);
2208
2376
  }
2209
2377
  function codexDesktopThread(threadId, home = codexHome()) {
2210
2378
  const file2 = codexRolloutFile(threadId, home);
@@ -2212,12 +2380,12 @@ function codexDesktopThread(threadId, home = codexHome()) {
2212
2380
  return void 0;
2213
2381
  let head = "";
2214
2382
  try {
2215
- const fd = fs15.openSync(file2, "r");
2383
+ const fd = fs16.openSync(file2, "r");
2216
2384
  try {
2217
2385
  const buf = Buffer.alloc(4096);
2218
- head = buf.subarray(0, fs15.readSync(fd, buf, 0, buf.length, 0)).toString("utf8");
2386
+ head = buf.subarray(0, fs16.readSync(fd, buf, 0, buf.length, 0)).toString("utf8");
2219
2387
  } finally {
2220
- fs15.closeSync(fd);
2388
+ fs16.closeSync(fd);
2221
2389
  }
2222
2390
  } catch {
2223
2391
  return void 0;
@@ -2229,16 +2397,16 @@ var CODEX_DESKTOP_THREAD = "Codex desktop thread; not resumable from the CLI";
2229
2397
 
2230
2398
  // packages/core/dist/notices.js
2231
2399
  function noticesDir() {
2232
- return path13.join(lobstahHome(), "notices");
2400
+ return path14.join(lobstahHome(), "notices");
2233
2401
  }
2234
2402
  var counter = 0;
2235
2403
  function postNotice(n) {
2236
2404
  const dir = noticesDir();
2237
- fs16.mkdirSync(dir, { recursive: true });
2405
+ fs17.mkdirSync(dir, { recursive: true });
2238
2406
  if (n.dedupeKey) {
2239
- const marker = path13.join(dir, `.dedupe-${n.dedupeKey.replace(/[^A-Za-z0-9_-]/g, "_")}`);
2407
+ const marker = path14.join(dir, `.dedupe-${n.dedupeKey.replace(/[^A-Za-z0-9_-]/g, "_")}`);
2240
2408
  try {
2241
- fs16.writeFileSync(marker, "", { flag: "wx" });
2409
+ fs17.writeFileSync(marker, "", { flag: "wx" });
2242
2410
  } catch {
2243
2411
  return void 0;
2244
2412
  }
@@ -2256,9 +2424,9 @@ function postNotice(n) {
2256
2424
  ...n.quiet ? { quiet: true } : {},
2257
2425
  ...n.stateHash ? { stateHash: n.stateHash } : {}
2258
2426
  };
2259
- const file2 = path13.join(dir, `${seq}.json`);
2427
+ const file2 = path14.join(dir, `${seq}.json`);
2260
2428
  const tmp = uniqueTempPath(file2);
2261
- fs16.writeFileSync(tmp, JSON.stringify(notice, null, 2));
2429
+ fs17.writeFileSync(tmp, JSON.stringify(notice, null, 2));
2262
2430
  atomicRenameSync(tmp, file2);
2263
2431
  return notice;
2264
2432
  }
@@ -2275,14 +2443,14 @@ function attachmentBlock(attachments) {
2275
2443
  }
2276
2444
 
2277
2445
  // packages/core/dist/helm.js
2278
- import * as fs17 from "node:fs";
2279
- import * as path14 from "node:path";
2446
+ import * as fs18 from "node:fs";
2447
+ import * as path15 from "node:path";
2280
2448
  function helmDir() {
2281
- return path14.join(lobstahHome(), "helm");
2449
+ return path15.join(lobstahHome(), "helm");
2282
2450
  }
2283
2451
  function listHelms() {
2284
2452
  try {
2285
- return fs17.readdirSync(helmDir()).filter((f) => f.endsWith(".json")).map((f) => JSON.parse(fs17.readFileSync(path14.join(helmDir(), f), "utf8")));
2453
+ return fs18.readdirSync(helmDir()).filter((f) => f.endsWith(".json")).map((f) => JSON.parse(fs18.readFileSync(path15.join(helmDir(), f), "utf8")));
2286
2454
  } catch {
2287
2455
  return [];
2288
2456
  }
@@ -2293,39 +2461,39 @@ function liveHelms(ttlMs, now2 = Date.now()) {
2293
2461
 
2294
2462
  // packages/core/dist/soak.js
2295
2463
  function regPath(trapId) {
2296
- return path15.join(soakingDir(), `${trapId}.json`);
2464
+ return path16.join(soakingDir(), `${trapId}.json`);
2297
2465
  }
2298
2466
  function readTrap(trapId) {
2299
2467
  try {
2300
- return JSON.parse(fs18.readFileSync(regPath(trapId), "utf8"));
2468
+ return JSON.parse(fs19.readFileSync(regPath(trapId), "utf8"));
2301
2469
  } catch {
2302
2470
  return void 0;
2303
2471
  }
2304
2472
  }
2305
2473
  function listTraps() {
2306
2474
  try {
2307
- return fs18.readdirSync(soakingDir()).filter((f) => f.endsWith(".json")).map((f) => JSON.parse(fs18.readFileSync(path15.join(soakingDir(), f), "utf8"))).filter((r) => typeof r.trapId === "string");
2475
+ return fs19.readdirSync(soakingDir()).filter((f) => f.endsWith(".json")).map((f) => JSON.parse(fs19.readFileSync(path16.join(soakingDir(), f), "utf8"))).filter((r) => typeof r.trapId === "string");
2308
2476
  } catch {
2309
2477
  return [];
2310
2478
  }
2311
2479
  }
2312
2480
  function claimPath(id, lane) {
2313
- return path15.join(laneDirs(lane).active, id, "claim.json");
2481
+ return path16.join(laneDirs(lane).active, id, "claim.json");
2314
2482
  }
2315
2483
  function readSessionClaim(id, lane) {
2316
2484
  try {
2317
- return JSON.parse(fs18.readFileSync(claimPath(id, lane), "utf8"));
2485
+ return JSON.parse(fs19.readFileSync(claimPath(id, lane), "utf8"));
2318
2486
  } catch {
2319
2487
  return void 0;
2320
2488
  }
2321
2489
  }
2322
2490
 
2323
2491
  // packages/core/dist/catch-context.js
2324
- import * as fs19 from "node:fs";
2325
- import * as path16 from "node:path";
2492
+ import * as fs20 from "node:fs";
2493
+ import * as path17 from "node:path";
2326
2494
  function readCatchContext(dir, id) {
2327
2495
  try {
2328
- return JSON.parse(fs19.readFileSync(path16.join(dir, `${id}.catch-context`), "utf8"));
2496
+ return JSON.parse(fs20.readFileSync(path17.join(dir, `${id}.catch-context`), "utf8"));
2329
2497
  } catch {
2330
2498
  return {};
2331
2499
  }
@@ -2338,19 +2506,19 @@ function observeLocalCatch(id, lane, phase, now2 = Date.now()) {
2338
2506
  const helms = liveHelms(cfg.helm.ttlSecs * 1e3, now2);
2339
2507
  const present = repo ? helms.some((h) => h.repos.includes(repo)) : null;
2340
2508
  const next = phase === "claim" ? { claimHelm: present, location: "local" } : { ...old, location: "local", helm: old.claimHelm === true || present === true ? true : old.claimHelm === false && present === false ? false : null };
2341
- const file2 = path16.join(dir, `${id}.catch-context`), tmp = uniqueTempPath(file2);
2509
+ const file2 = path17.join(dir, `${id}.catch-context`), tmp = uniqueTempPath(file2);
2342
2510
  try {
2343
- fs19.writeFileSync(tmp, JSON.stringify(next));
2344
- fs19.renameSync(tmp, file2);
2511
+ fs20.writeFileSync(tmp, JSON.stringify(next));
2512
+ fs20.renameSync(tmp, file2);
2345
2513
  } finally {
2346
- fs19.rmSync(tmp, { force: true });
2514
+ fs20.rmSync(tmp, { force: true });
2347
2515
  }
2348
2516
  }
2349
2517
 
2350
2518
  // packages/core/dist/stats.js
2351
2519
  var DAILY_RETENTION_DAYS = 400;
2352
2520
  function statsPath() {
2353
- return path17.join(lobstahHome(), "stats.json");
2521
+ return path18.join(lobstahHome(), "stats.json");
2354
2522
  }
2355
2523
  function shiftDay(day, days) {
2356
2524
  const [y, m, d] = day.split("-").map(Number);
@@ -2363,7 +2531,7 @@ function localDay(at = Date.now()) {
2363
2531
  function readCatchFacts(stateDir, id) {
2364
2532
  let last;
2365
2533
  try {
2366
- for (const line of fs20.readFileSync(path17.join(stateDir, `${id}.status`), "utf8").split("\n")) {
2534
+ for (const line of fs21.readFileSync(path18.join(stateDir, `${id}.status`), "utf8").split("\n")) {
2367
2535
  if (!line.trim())
2368
2536
  continue;
2369
2537
  try {
@@ -2379,7 +2547,7 @@ function readCatchFacts(stateDir, id) {
2379
2547
  let trap;
2380
2548
  let worker = workerProfile();
2381
2549
  try {
2382
- const evidence = JSON.parse(fs20.readFileSync(path17.join(stateDir, `${id}.evidence`), "utf8"));
2550
+ const evidence = JSON.parse(fs21.readFileSync(path18.join(stateDir, `${id}.evidence`), "utf8"));
2383
2551
  const to = evidence.deliveredTo;
2384
2552
  if (typeof to === "string" && to.startsWith("wt:"))
2385
2553
  trap = to;
@@ -2462,7 +2630,7 @@ function add(store, facts, now2) {
2462
2630
  }
2463
2631
  function backfillSources() {
2464
2632
  const live = ["work", "chore"].map((lane) => ({ dir: laneDirs(lane).state, live: true }));
2465
- const backups = readDirIfPresent(lobstahHome()).filter((name) => name.startsWith("state-backup-")).sort().map((name) => ({ dir: path17.join(lobstahHome(), name), live: false })).filter((s) => fs20.statSync(s.dir).isDirectory());
2633
+ const backups = readDirIfPresent(lobstahHome()).filter((name) => name.startsWith("state-backup-")).sort().map((name) => ({ dir: path18.join(lobstahHome(), name), live: false })).filter((s) => fs21.statSync(s.dir).isDirectory());
2466
2634
  return [...live, ...backups];
2467
2635
  }
2468
2636
  function backfillStats(now2 = Date.now(), alreadyCounted) {
@@ -2534,42 +2702,23 @@ function parseStore(text) {
2534
2702
  var complete2 = (s) => !!s && s.daily !== void 0;
2535
2703
  function writeStore(store) {
2536
2704
  const file2 = statsPath();
2537
- fs20.mkdirSync(path17.dirname(file2), { recursive: true });
2705
+ fs21.mkdirSync(path18.dirname(file2), { recursive: true });
2538
2706
  const tmp = uniqueTempPath(file2);
2539
- fs20.writeFileSync(tmp, JSON.stringify(store));
2707
+ fs21.writeFileSync(tmp, JSON.stringify(store));
2540
2708
  atomicRenameSync(tmp, file2);
2541
2709
  }
2542
2710
  function withStatsLock(action) {
2543
- fs20.mkdirSync(lobstahHome(), { recursive: true });
2544
- const lock = `${statsPath()}.lock`;
2545
- const deadline = Date.now() + 1e4;
2546
- for (; ; ) {
2547
- try {
2548
- fs20.mkdirSync(lock);
2549
- break;
2550
- } catch (err) {
2551
- if (err.code !== "EEXIST")
2552
- throw err;
2553
- try {
2554
- if (Date.now() - fs20.statSync(lock).mtimeMs > 12e4)
2555
- fs20.rmdirSync(lock);
2556
- } catch {
2557
- }
2558
- if (Date.now() >= deadline)
2559
- throw new Error("stats store locked");
2560
- Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 10);
2561
- }
2562
- }
2563
- try {
2564
- return action();
2565
- } finally {
2566
- fs20.rmdirSync(lock);
2567
- }
2711
+ fs21.mkdirSync(lobstahHome(), { recursive: true });
2712
+ return withDirLock(`${statsPath()}.lock`, action, {
2713
+ staleMs: 12e4,
2714
+ waitMs: 1e4,
2715
+ busy: () => new Error("stats store locked")
2716
+ });
2568
2717
  }
2569
2718
  function loadOrBackfill(now2) {
2570
2719
  let text;
2571
2720
  try {
2572
- text = fs20.readFileSync(statsPath(), "utf8");
2721
+ text = fs21.readFileSync(statsPath(), "utf8");
2573
2722
  } catch (err) {
2574
2723
  if (err.code !== "ENOENT")
2575
2724
  throw err;
@@ -2596,7 +2745,7 @@ function loadOrBackfill(now2) {
2596
2745
  return store2;
2597
2746
  }
2598
2747
  if (text !== void 0)
2599
- fs20.renameSync(statsPath(), `${statsPath()}.unreadable-${now2}`);
2748
+ fs21.renameSync(statsPath(), `${statsPath()}.unreadable-${now2}`);
2600
2749
  const store = backfillStats(now2);
2601
2750
  writeStore(store);
2602
2751
  return store;
@@ -2683,7 +2832,7 @@ function appendStatus(id, lane, verb, note, at, waiting, reported = false) {
2683
2832
  } catch {
2684
2833
  }
2685
2834
  }
2686
- fs21.appendFileSync(statusPath(id, lane), `${JSON.stringify(entry)}
2835
+ fs22.appendFileSync(statusPath(id, lane), `${JSON.stringify(entry)}
2687
2836
  `);
2688
2837
  if (verb === "done") {
2689
2838
  try {
@@ -2695,9 +2844,9 @@ function appendStatus(id, lane, verb, note, at, waiting, reported = false) {
2695
2844
  }
2696
2845
  function readStatusLog(id, lane) {
2697
2846
  const file2 = statusPath(id, lane);
2698
- if (!fs21.existsSync(file2))
2847
+ if (!fs22.existsSync(file2))
2699
2848
  return [];
2700
- return fs21.readFileSync(file2, "utf8").split("\n").filter(Boolean).flatMap((line) => {
2849
+ return fs22.readFileSync(file2, "utf8").split("\n").filter(Boolean).flatMap((line) => {
2701
2850
  try {
2702
2851
  const parsed = JSON.parse(line);
2703
2852
  return isVerb(parsed.verb) ? [parsed] : [];
@@ -2713,28 +2862,28 @@ function pausedWaiting(entry) {
2713
2862
  // packages/core/dist/queue.js
2714
2863
  function requeue(id, lane) {
2715
2864
  const dirs = laneDirs(lane);
2716
- const activeDir = path18.join(dirs.active, id);
2717
- const file2 = path18.join(activeDir, "descriptor.json");
2865
+ const activeDir = path19.join(dirs.active, id);
2866
+ const file2 = path19.join(activeDir, "descriptor.json");
2718
2867
  const d = { ...readDescriptor(id, lane), queuedAt: (/* @__PURE__ */ new Date()).toISOString() };
2719
2868
  const tmp = uniqueTempPath(file2);
2720
- fs22.writeFileSync(tmp, JSON.stringify(d, null, 2));
2869
+ fs23.writeFileSync(tmp, JSON.stringify(d, null, 2));
2721
2870
  atomicRenameSync(tmp, file2);
2722
- fs22.renameSync(file2, path18.join(dirs.queue, `${id}.json`));
2723
- fs22.rmSync(activeDir, { recursive: true, force: true });
2871
+ fs23.renameSync(file2, path19.join(dirs.queue, `${id}.json`));
2872
+ fs23.rmSync(activeDir, { recursive: true, force: true });
2724
2873
  }
2725
2874
  function readDescriptor(id, lane) {
2726
- const file2 = path18.join(laneDirs(lane).active, id, "descriptor.json");
2727
- return JSON.parse(fs22.readFileSync(file2, "utf8"));
2875
+ const file2 = path19.join(laneDirs(lane).active, id, "descriptor.json");
2876
+ return JSON.parse(fs23.readFileSync(file2, "utf8"));
2728
2877
  }
2729
2878
  function storedDescriptor(id, lane) {
2730
2879
  const dirs = laneDirs(lane);
2731
2880
  for (const file2 of [
2732
- path18.join(dirs.queue, `${id}.json`),
2733
- path18.join(dirs.active, id, "descriptor.json"),
2734
- path18.join(dirs.done, id, "descriptor.json")
2881
+ path19.join(dirs.queue, `${id}.json`),
2882
+ path19.join(dirs.active, id, "descriptor.json"),
2883
+ path19.join(dirs.done, id, "descriptor.json")
2735
2884
  ]) {
2736
2885
  try {
2737
- return JSON.parse(fs22.readFileSync(file2, "utf8"));
2886
+ return JSON.parse(fs23.readFileSync(file2, "utf8"));
2738
2887
  } catch {
2739
2888
  }
2740
2889
  }
@@ -2745,10 +2894,10 @@ function activeIds(lane) {
2745
2894
  }
2746
2895
  function complete(id, lane) {
2747
2896
  const dirs = laneDirs(lane);
2748
- fs22.renameSync(path18.join(dirs.active, id), path18.join(dirs.done, id));
2897
+ fs23.renameSync(path19.join(dirs.active, id), path19.join(dirs.done, id));
2749
2898
  }
2750
2899
  function cancelRequested(id, lane) {
2751
- return fs22.existsSync(path18.join(laneDirs(lane).active, id, "cancel"));
2900
+ return fs23.existsSync(path19.join(laneDirs(lane).active, id, "cancel"));
2752
2901
  }
2753
2902
 
2754
2903
  // packages/core/dist/backend.js
@@ -2797,21 +2946,21 @@ var ANSWER_EXTENSIONS = Object.keys(ANSWER_TYPES);
2797
2946
  var ONCE_TTL_MS = 60 * 60 * 1e3;
2798
2947
 
2799
2948
  // packages/core/dist/harness.js
2800
- import * as fs23 from "node:fs";
2801
- import * as path19 from "node:path";
2949
+ import * as fs24 from "node:fs";
2950
+ import * as path20 from "node:path";
2802
2951
  import { createRequire } from "node:module";
2803
2952
  function resolveOnPath(bin, pathVar = process.env.PATH) {
2804
2953
  if (!pathVar)
2805
2954
  return void 0;
2806
2955
  const names = process.platform === "win32" ? [bin, `${bin}.exe`, `${bin}.cmd`, `${bin}.bat`] : [bin];
2807
- for (const dir of pathVar.split(path19.delimiter)) {
2956
+ for (const dir of pathVar.split(path20.delimiter)) {
2808
2957
  if (!dir)
2809
2958
  continue;
2810
2959
  for (const name of names) {
2811
- const candidate = path19.join(dir, name);
2960
+ const candidate = path20.join(dir, name);
2812
2961
  try {
2813
- fs23.accessSync(candidate, fs23.constants.X_OK);
2814
- if (fs23.statSync(candidate).isFile())
2962
+ fs24.accessSync(candidate, fs24.constants.X_OK);
2963
+ if (fs24.statSync(candidate).isFile())
2815
2964
  return candidate;
2816
2965
  } catch {
2817
2966
  }
@@ -2832,8 +2981,8 @@ function codexInvocation(argv) {
2832
2981
  } catch {
2833
2982
  }
2834
2983
  for (const dir of require_.resolve.paths("@openai/codex") ?? []) {
2835
- const cli = path19.join(dir, "@openai", "codex", "bin", "codex.js");
2836
- if (fs23.existsSync(cli))
2984
+ const cli = path20.join(dir, "@openai", "codex", "bin", "codex.js");
2985
+ if (fs24.existsSync(cli))
2837
2986
  return { file: process.execPath, argv: [cli, ...argv] };
2838
2987
  }
2839
2988
  return void 0;
@@ -2906,8 +3055,8 @@ function droppedModelNote(harness, dropped) {
2906
3055
  }
2907
3056
 
2908
3057
  // packages/runner/src/run.ts
2909
- import * as fs28 from "node:fs";
2910
- import * as path24 from "node:path";
3058
+ import * as fs29 from "node:fs";
3059
+ import * as path25 from "node:path";
2911
3060
  import { execFileSync as execFileSync2 } from "node:child_process";
2912
3061
  import { fileURLToPath as fileURLToPath2 } from "node:url";
2913
3062
 
@@ -3117,13 +3266,13 @@ function startClaudeCli(invocation, opts) {
3117
3266
  events.close();
3118
3267
  resolve9({ sessionId, error: err.message });
3119
3268
  });
3120
- child.on("exit", (code) => {
3269
+ child.on("exit", (code2) => {
3121
3270
  events.close();
3122
- if (code === 0)
3271
+ if (code2 === 0)
3123
3272
  resolve9({ sessionId });
3124
3273
  else {
3125
3274
  const detail = stderrTail.trim().split("\n").at(-1);
3126
- const error = `claude exited ${code}${detail ? ` \u2014 ${detail}` : ""}`;
3275
+ const error = `claude exited ${code2}${detail ? ` \u2014 ${detail}` : ""}`;
3127
3276
  resolve9({ sessionId, error });
3128
3277
  }
3129
3278
  });
@@ -3203,25 +3352,25 @@ function createClaudeAdapter() {
3203
3352
  }
3204
3353
 
3205
3354
  // packages/adapters/dist/codex.js
3206
- import * as fs24 from "node:fs";
3355
+ import * as fs25 from "node:fs";
3207
3356
  import * as os4 from "node:os";
3208
- import * as path20 from "node:path";
3357
+ import * as path21 from "node:path";
3209
3358
  import { spawn as spawn2 } from "node:child_process";
3210
3359
  function isolatedCodexHome() {
3211
- const dir = path20.join(lobstahHome(), "codex-home");
3212
- fs24.mkdirSync(dir, { recursive: true });
3213
- const auth = path20.join(dir, "auth.json");
3214
- const realAuth = path20.join(os4.homedir(), ".codex", "auth.json");
3215
- if (!fs24.existsSync(auth) && fs24.existsSync(realAuth)) {
3360
+ const dir = path21.join(lobstahHome(), "codex-home");
3361
+ fs25.mkdirSync(dir, { recursive: true });
3362
+ const auth = path21.join(dir, "auth.json");
3363
+ const realAuth = path21.join(os4.homedir(), ".codex", "auth.json");
3364
+ if (!fs25.existsSync(auth) && fs25.existsSync(realAuth)) {
3216
3365
  try {
3217
- fs24.symlinkSync(realAuth, auth);
3366
+ fs25.symlinkSync(realAuth, auth);
3218
3367
  } catch {
3219
- fs24.copyFileSync(realAuth, auth);
3368
+ fs25.copyFileSync(realAuth, auth);
3220
3369
  }
3221
3370
  }
3222
- const cfg = path20.join(dir, "config.toml");
3223
- if (!fs24.existsSync(cfg)) {
3224
- fs24.writeFileSync(cfg, "# lobstah-managed: auth inherited from ~/.codex, interactive config not\n");
3371
+ const cfg = path21.join(dir, "config.toml");
3372
+ if (!fs25.existsSync(cfg)) {
3373
+ fs25.writeFileSync(cfg, "# lobstah-managed: auth inherited from ~/.codex, interactive config not\n");
3225
3374
  }
3226
3375
  return dir;
3227
3376
  }
@@ -3305,13 +3454,13 @@ function startCodexCli(invoke, opts) {
3305
3454
  }
3306
3455
  });
3307
3456
  child.on("error", (err) => resolve9(err.message));
3308
- child.on("exit", (code) => {
3457
+ child.on("exit", (code2) => {
3309
3458
  if (turnError)
3310
3459
  return resolve9(turnError);
3311
- if (code === 0 || killed)
3460
+ if (code2 === 0 || killed)
3312
3461
  return resolve9(void 0);
3313
3462
  const detail = stderrTail.trim().split("\n").at(-1);
3314
- resolve9(`codex exited ${code}${detail ? ` \u2014 ${detail}` : ""}`);
3463
+ resolve9(`codex exited ${code2}${detail ? ` \u2014 ${detail}` : ""}`);
3315
3464
  });
3316
3465
  });
3317
3466
  }
@@ -3424,15 +3573,15 @@ function loadAdapter(name) {
3424
3573
  }
3425
3574
 
3426
3575
  // packages/worktree/dist/index.js
3427
- import * as fs26 from "node:fs";
3428
- import * as path22 from "node:path";
3576
+ import * as fs27 from "node:fs";
3577
+ import * as path23 from "node:path";
3429
3578
  import { createHash } from "node:crypto";
3430
3579
  import { exec, execFile as execFile2, execFileSync } from "node:child_process";
3431
3580
  import { promisify as promisify2 } from "node:util";
3432
3581
 
3433
3582
  // packages/worktree/dist/pool.js
3434
- import * as fs25 from "node:fs";
3435
- import * as path21 from "node:path";
3583
+ import * as fs26 from "node:fs";
3584
+ import * as path22 from "node:path";
3436
3585
  import { execFile } from "node:child_process";
3437
3586
  import { promisify } from "node:util";
3438
3587
  var run = promisify(execFile);
@@ -3494,17 +3643,17 @@ function takeOut(name, pool, slot, reason, dispatch, notice = true) {
3494
3643
  function trapIn(dir) {
3495
3644
  const real = (p) => {
3496
3645
  try {
3497
- return fs25.realpathSync.native(p);
3646
+ return fs26.realpathSync.native(p);
3498
3647
  } catch {
3499
- return path21.resolve(p);
3648
+ return path22.resolve(p);
3500
3649
  }
3501
3650
  };
3502
3651
  const here = real(dir);
3503
3652
  return listTraps().some((t) => {
3504
3653
  if (typeof t.worktree !== "string")
3505
3654
  return false;
3506
- const rel = path21.relative(here, real(t.worktree));
3507
- return rel === "" || !rel.startsWith("..") && !path21.isAbsolute(rel);
3655
+ const rel = path22.relative(here, real(t.worktree));
3656
+ return rel === "" || !rel.startsWith("..") && !path22.isAbsolute(rel);
3508
3657
  });
3509
3658
  }
3510
3659
  async function claimPoolSlot(input) {
@@ -3512,7 +3661,7 @@ async function claimPoolSlot(input) {
3512
3661
  const refused = [];
3513
3662
  for (let slot = 1; slot <= pool.size; slot++) {
3514
3663
  const dir = poolSlotPath(name, slot);
3515
- if (fs25.existsSync(dir) && readWorktreeLock(dir)?.id === id && readWorktreeLock(dir)?.kind !== "warm") {
3664
+ if (fs26.existsSync(dir) && readWorktreeLock(dir)?.id === id && readWorktreeLock(dir)?.kind !== "warm") {
3516
3665
  writeSlotClaim(name, slot, { id, lane, at: (/* @__PURE__ */ new Date()).toISOString() });
3517
3666
  return { claimed: true, dir, slot, label: poolSlotLabel(name, slot) };
3518
3667
  }
@@ -3560,7 +3709,7 @@ async function resetPoolWorktree(repo, dir, id, fromRemoteBranch = repo.trunk) {
3560
3709
  }
3561
3710
  var WARM_ID = "pool-warm";
3562
3711
  async function createSlot(repo, dir) {
3563
- fs25.mkdirSync(path21.dirname(dir), { recursive: true });
3712
+ fs26.mkdirSync(path22.dirname(dir), { recursive: true });
3564
3713
  await oneAtATime(repo.path, async () => {
3565
3714
  await tryGit(repo.path, "worktree", "prune");
3566
3715
  await gitShared(repo.path, "worktree", "add", "--detach", dir, `origin/${repo.trunk}`);
@@ -3582,7 +3731,7 @@ async function warmPool(name, opts = {}) {
3582
3731
  if (!release)
3583
3732
  return false;
3584
3733
  try {
3585
- if (!fs25.existsSync(repo.path)) {
3734
+ if (!fs26.existsSync(repo.path)) {
3586
3735
  if (!repo.origin)
3587
3736
  throw new Error(`repo path ${repo.path} missing and no origin configured`);
3588
3737
  await run("git", ["clone", repo.origin, repo.path], { env: process.env });
@@ -3595,8 +3744,8 @@ async function warmPool(name, opts = {}) {
3595
3744
  const dir = poolSlotPath(name, slot);
3596
3745
  const label = poolSlotLabel(name, slot);
3597
3746
  const meta = readSlotMeta(name, slot);
3598
- if (!fs25.existsSync(dir)) {
3599
- fs25.mkdirSync(poolsRoot(), { recursive: true });
3747
+ if (!fs26.existsSync(dir)) {
3748
+ fs26.mkdirSync(poolsRoot(), { recursive: true });
3600
3749
  let free = Infinity;
3601
3750
  try {
3602
3751
  free = need > 0 ? read2(poolsRoot()) : Infinity;
@@ -3712,23 +3861,23 @@ ${err instanceof Error ? err.message : ""}`;
3712
3861
  }
3713
3862
  var ATTEMPTS = 6;
3714
3863
  async function gitShared(cwd, ...args) {
3715
- for (let attempt = 1; ; attempt++) {
3864
+ for (let attempt2 = 1; ; attempt2++) {
3716
3865
  try {
3717
3866
  return await git(cwd, ...args);
3718
3867
  } catch (err) {
3719
3868
  if (!isLockContention(err))
3720
3869
  throw err;
3721
- if (attempt >= ATTEMPTS) {
3722
- throw new Error(`git ${args.join(" ")}: lock contention, ${attempt} attempts
3870
+ if (attempt2 >= ATTEMPTS) {
3871
+ throw new Error(`git ${args.join(" ")}: lock contention, ${attempt2} attempts
3723
3872
  ${gitStderr(err)}`, { cause: err });
3724
3873
  }
3725
- await new Promise((r) => setTimeout(r, 100 * 2 ** (attempt - 1) * (0.5 + Math.random())));
3874
+ await new Promise((r) => setTimeout(r, 100 * 2 ** (attempt2 - 1) * (0.5 + Math.random())));
3726
3875
  }
3727
3876
  }
3728
3877
  }
3729
3878
  var REPO_LOCK_WAIT_MS = 5 * 6e4;
3730
3879
  var repoQueues = /* @__PURE__ */ new Map();
3731
- function pidAlive2(pid) {
3880
+ function pidAlive3(pid) {
3732
3881
  try {
3733
3882
  process.kill(pid, 0);
3734
3883
  return true;
@@ -3739,18 +3888,18 @@ function pidAlive2(pid) {
3739
3888
  var BUSY = /* @__PURE__ */ new Set(["EPERM", "EACCES", "EBUSY"]);
3740
3889
  function takeRepoLock(file2, mine) {
3741
3890
  try {
3742
- fs26.writeFileSync(file2, mine, { flag: "wx" });
3891
+ fs27.writeFileSync(file2, mine, { flag: "wx" });
3743
3892
  return { state: "held" };
3744
3893
  } catch (err) {
3745
- const code = err.code ?? "";
3746
- if (code !== "EEXIST" && !BUSY.has(code))
3894
+ const code2 = err.code ?? "";
3895
+ if (code2 !== "EEXIST" && !BUSY.has(code2))
3747
3896
  throw err;
3748
3897
  }
3749
3898
  let raw = "";
3750
3899
  let age = 0;
3751
3900
  try {
3752
- raw = fs26.readFileSync(file2, "utf8");
3753
- age = Date.now() - fs26.statSync(file2).mtimeMs;
3901
+ raw = fs27.readFileSync(file2, "utf8");
3902
+ age = Date.now() - fs27.statSync(file2).mtimeMs;
3754
3903
  } catch {
3755
3904
  return { state: "retry" };
3756
3905
  }
@@ -3760,11 +3909,11 @@ function takeRepoLock(file2, mine) {
3760
3909
  } catch {
3761
3910
  holder = void 0;
3762
3911
  }
3763
- const stale = age > REPO_LOCK_WAIT_MS || (holder ? !pidAlive2(holder.pid) : age > 5e3);
3912
+ const stale = age > REPO_LOCK_WAIT_MS || (holder ? !pidAlive3(holder.pid) : age > 5e3);
3764
3913
  if (stale) {
3765
3914
  try {
3766
- if (fs26.readFileSync(file2, "utf8") === raw)
3767
- fs26.rmSync(file2, { force: true });
3915
+ if (fs27.readFileSync(file2, "utf8") === raw)
3916
+ fs27.rmSync(file2, { force: true });
3768
3917
  } catch {
3769
3918
  }
3770
3919
  return { state: "retry" };
@@ -3773,13 +3922,13 @@ function takeRepoLock(file2, mine) {
3773
3922
  }
3774
3923
  function releaseRepoLock(file2, mine) {
3775
3924
  try {
3776
- if (fs26.readFileSync(file2, "utf8") === mine)
3777
- fs26.rmSync(file2, { force: true, recursive: true, maxRetries: 5 });
3925
+ if (fs27.readFileSync(file2, "utf8") === mine)
3926
+ fs27.rmSync(file2, { force: true, recursive: true, maxRetries: 5 });
3778
3927
  } catch {
3779
3928
  }
3780
3929
  }
3781
3930
  async function withRepoLock(common, fn) {
3782
- const file2 = path22.join(common, "lobstah-git.lock");
3931
+ const file2 = path23.join(common, "lobstah-git.lock");
3783
3932
  const mine = JSON.stringify({ pid: process.pid, at: (/* @__PURE__ */ new Date()).toISOString() });
3784
3933
  const deadline = Date.now() + REPO_LOCK_WAIT_MS;
3785
3934
  let held = false;
@@ -3815,7 +3964,7 @@ async function oneAtATime(cwd, fn) {
3815
3964
  }
3816
3965
  function fetchStamps(common) {
3817
3966
  try {
3818
- return JSON.parse(fs26.readFileSync(path22.join(common, "lobstah-fetch.json"), "utf8"));
3967
+ return JSON.parse(fs27.readFileSync(path23.join(common, "lobstah-fetch.json"), "utf8"));
3819
3968
  } catch {
3820
3969
  return {};
3821
3970
  }
@@ -3829,15 +3978,15 @@ async function fetchShared(cwd, remote, ref) {
3829
3978
  const started = Date.now();
3830
3979
  await gitShared(cwd, "fetch", remote, ref);
3831
3980
  const stamps = { ...fetchStamps(common), [key]: started };
3832
- fs26.writeFileSync(path22.join(common, "lobstah-fetch.json"), JSON.stringify(stamps, null, 2));
3981
+ fs27.writeFileSync(path23.join(common, "lobstah-fetch.json"), JSON.stringify(stamps, null, 2));
3833
3982
  });
3834
3983
  }
3835
3984
  async function allocate(repo, id, fromRemoteBranch = repo.trunk) {
3836
3985
  const dir = worktreePath(id);
3837
- if (fs26.existsSync(dir)) {
3986
+ if (fs27.existsSync(dir)) {
3838
3987
  throw new Error(`worktree for ${id} already exists at ${dir} \u2014 never allocate a second`);
3839
3988
  }
3840
- if (!fs26.existsSync(repo.path)) {
3989
+ if (!fs27.existsSync(repo.path)) {
3841
3990
  if (!repo.origin)
3842
3991
  throw new Error(`repo path ${repo.path} missing and no origin configured`);
3843
3992
  await run2("git", ["clone", repo.origin, repo.path], { env: process.env });
@@ -3852,7 +4001,7 @@ async function allocate(repo, id, fromRemoteBranch = repo.trunk) {
3852
4001
  async function recoverWorktree(repo, id) {
3853
4002
  const dir = worktreePath(id);
3854
4003
  try {
3855
- if (fs26.statSync(path22.join(dir, ".git")).isFile()) {
4004
+ if (fs27.statSync(path23.join(dir, ".git")).isFile()) {
3856
4005
  const branch = await git(dir, "symbolic-ref", "--quiet", "HEAD");
3857
4006
  const root = await git(dir, "rev-parse", "--show-toplevel");
3858
4007
  const common = await git(dir, "rev-parse", "--path-format=absolute", "--git-common-dir");
@@ -3890,27 +4039,27 @@ function setupHash(repo, dir) {
3890
4039
  const h = createHash("sha256");
3891
4040
  h.update(JSON.stringify(repo.setup ?? []));
3892
4041
  for (const name of LOCKFILES) {
3893
- const file2 = path22.join(dir, name);
3894
- if (!fs26.existsSync(file2))
4042
+ const file2 = path23.join(dir, name);
4043
+ if (!fs27.existsSync(file2))
3895
4044
  continue;
3896
4045
  h.update(`\0${name}\0`);
3897
- h.update(fs26.readFileSync(file2));
4046
+ h.update(fs27.readFileSync(file2));
3898
4047
  }
3899
4048
  return h.digest("hex");
3900
4049
  }
3901
4050
  function setupRecordFile(dir) {
3902
4051
  const gitDir = worktreeGitDir(dir);
3903
- return gitDir ? path22.join(gitDir, "lobstah-setup.json") : void 0;
4052
+ return gitDir ? path23.join(gitDir, "lobstah-setup.json") : void 0;
3904
4053
  }
3905
4054
  function recordSetup(repo, dir) {
3906
4055
  const file2 = setupRecordFile(dir);
3907
4056
  if (file2)
3908
- fs26.writeFileSync(file2, JSON.stringify({ hash: setupHash(repo, dir), at: (/* @__PURE__ */ new Date()).toISOString() }, null, 2));
4057
+ fs27.writeFileSync(file2, JSON.stringify({ hash: setupHash(repo, dir), at: (/* @__PURE__ */ new Date()).toISOString() }, null, 2));
3909
4058
  }
3910
4059
  function recordedSetupHash(dir) {
3911
4060
  const file2 = setupRecordFile(dir);
3912
4061
  try {
3913
- return file2 ? JSON.parse(fs26.readFileSync(file2, "utf8")).hash : void 0;
4062
+ return file2 ? JSON.parse(fs27.readFileSync(file2, "utf8")).hash : void 0;
3914
4063
  } catch {
3915
4064
  return void 0;
3916
4065
  }
@@ -3923,9 +4072,9 @@ function poolReused(slot, by) {
3923
4072
  function realpath(p) {
3924
4073
  let r;
3925
4074
  try {
3926
- r = fs26.realpathSync.native(p);
4075
+ r = fs27.realpathSync.native(p);
3927
4076
  } catch {
3928
- r = path22.resolve(p);
4077
+ r = path23.resolve(p);
3929
4078
  }
3930
4079
  return process.platform === "win32" ? r.toLowerCase() : r;
3931
4080
  }
@@ -3973,8 +4122,8 @@ async function chooseWorktree(input) {
3973
4122
  for (const t of listTraps()) {
3974
4123
  if (typeof t.worktree !== "string")
3975
4124
  continue;
3976
- const rel = path22.relative(here, realpath(t.worktree));
3977
- if (!rel.startsWith("..") && !path22.isAbsolute(rel))
4125
+ const rel = path23.relative(here, realpath(t.worktree));
4126
+ if (!rel.startsWith("..") && !path23.isAbsolute(rel))
3978
4127
  return { reuse: false, reason: "origin worktree is a trap\u2019s" };
3979
4128
  }
3980
4129
  for (const l of ["work", "chore"]) {
@@ -4402,8 +4551,8 @@ function startWallClock(opts) {
4402
4551
  import { execFile as execFile3 } from "node:child_process";
4403
4552
  import { promisify as promisify3 } from "node:util";
4404
4553
  import { fileURLToPath } from "node:url";
4405
- import * as fs27 from "node:fs";
4406
- import * as path23 from "node:path";
4554
+ import * as fs28 from "node:fs";
4555
+ import * as path24 from "node:path";
4407
4556
  var exec2 = promisify3(execFile3);
4408
4557
  function firstLine(err) {
4409
4558
  const stderr = err && typeof err === "object" && "stderr" in err ? String(err.stderr).trim() : "";
@@ -4433,10 +4582,10 @@ function keepRemote(opts) {
4433
4582
  const note = (message) => mergeEvidence(id, lane, { note: message.slice(0, 300) });
4434
4583
  if (existingPrUrl) mergeEvidence(id, lane, { prUrl: existingPrUrl });
4435
4584
  const registerWatch = async (url) => {
4436
- const root = path23.resolve(path23.dirname(fileURLToPath(import.meta.url)), "..", "..", "..");
4437
- const localCli = path23.join(root, "apps", "cli", "dist", "main.js");
4585
+ const root = path24.resolve(path24.dirname(fileURLToPath(import.meta.url)), "..", "..", "..");
4586
+ const localCli = path24.join(root, "apps", "cli", "dist", "main.js");
4438
4587
  const args = ["watch", "add", url, "--for", id];
4439
- if (fs27.existsSync(localCli)) await command(process.execPath, [localCli, ...args], 15e3);
4588
+ if (fs28.existsSync(localCli)) await command(process.execPath, [localCli, ...args], 15e3);
4440
4589
  else await command("lobstah", args, 15e3);
4441
4590
  };
4442
4591
  let lastSeenHead;
@@ -4628,16 +4777,16 @@ function coldNote(cold, cwd, trunk) {
4628
4777
  }
4629
4778
  async function main(activeDir, lane, seams = {}) {
4630
4779
  const deps = { ...defaultDeps, ...seams };
4631
- const id = path24.basename(activeDir);
4780
+ const id = path25.basename(activeDir);
4632
4781
  if (isTrapCatch(id, lane)) throw new Error(`refusing headless runner for trap catch ${id}`);
4633
4782
  const status = (verb, note) => appendStatus(id, lane, verb, note);
4634
4783
  const cfg = loadConfig();
4635
- const descriptor = JSON.parse(fs28.readFileSync(path24.join(activeDir, "descriptor.json"), "utf8"));
4784
+ const descriptor = JSON.parse(fs29.readFileSync(path25.join(activeDir, "descriptor.json"), "utf8"));
4636
4785
  const resolved = resolveDispatch(descriptor, cfg);
4637
4786
  const repo = cfg.repos[descriptor.repo];
4638
- const briefFile = path24.join(activeDir, "brief.md");
4639
- if (!fs28.existsSync(briefFile)) fs28.writeFileSync(briefFile, descriptor.brief);
4640
- const brief = fs28.readFileSync(briefFile, "utf8");
4787
+ const briefFile = path25.join(activeDir, "brief.md");
4788
+ if (!fs29.existsSync(briefFile)) fs29.writeFileSync(briefFile, descriptor.brief);
4789
+ const brief = fs29.readFileSync(briefFile, "utf8");
4641
4790
  const attempts = Number(process.env.LOBSTAH_ATTEMPTS ?? "1");
4642
4791
  const wake = process.env.LOBSTAH_WAKE;
4643
4792
  const runnerInfo = {
@@ -4645,7 +4794,7 @@ async function main(activeDir, lane, seams = {}) {
4645
4794
  startedAt: (/* @__PURE__ */ new Date()).toISOString(),
4646
4795
  attempts
4647
4796
  };
4648
- fs28.writeFileSync(path24.join(activeDir, "runner.json"), JSON.stringify(runnerInfo, null, 2));
4797
+ fs29.writeFileSync(path25.join(activeDir, "runner.json"), JSON.stringify(runnerInfo, null, 2));
4649
4798
  if (descriptor.systemRepair && descriptor.pr?.url) {
4650
4799
  const state = deps.prState(descriptor.pr.url) ?? readPr(parsePrRef(descriptor.pr.url)?.key ?? "")?.state;
4651
4800
  if (state === "MERGED" || state === "CLOSED") {
@@ -4662,14 +4811,14 @@ async function main(activeDir, lane, seams = {}) {
4662
4811
  resolvedHarness: resolved.harness,
4663
4812
  envResume: process.env.LOBSTAH_RESUME
4664
4813
  });
4665
- const wtFile = path24.join(activeDir, "worktree.json");
4814
+ const wtFile = path25.join(activeDir, "worktree.json");
4666
4815
  let recorded;
4667
4816
  let recovered = false;
4668
4817
  let choice3;
4669
- if (fs28.existsSync(wtFile)) {
4670
- recorded = JSON.parse(fs28.readFileSync(wtFile, "utf8")).path;
4671
- if (!fs28.existsSync(recorded)) throw new Error(`recorded worktree ${recorded} is gone`);
4672
- } else if (fs28.existsSync(worktreePath(id))) {
4818
+ if (fs29.existsSync(wtFile)) {
4819
+ recorded = JSON.parse(fs29.readFileSync(wtFile, "utf8")).path;
4820
+ if (!fs29.existsSync(recorded)) throw new Error(`recorded worktree ${recorded} is gone`);
4821
+ } else if (fs29.existsSync(worktreePath(id))) {
4673
4822
  recorded = await recoverWorktree(repo, id);
4674
4823
  recovered = true;
4675
4824
  } else if (descriptor.followUp && cfg.limits.reuseWorktree !== false) {
@@ -4724,7 +4873,7 @@ async function main(activeDir, lane, seams = {}) {
4724
4873
  if (held) throw new Error(`worktree at ${cwd} is in use by ${held.id} \u2014 wait for that dispatch to release it before retrying`);
4725
4874
  if (recovered) {
4726
4875
  await deps.prepareReuse(repo, cwd);
4727
- fs28.writeFileSync(wtFile, JSON.stringify({ path: cwd }, null, 2));
4876
+ fs29.writeFileSync(wtFile, JSON.stringify({ path: cwd }, null, 2));
4728
4877
  }
4729
4878
  } else if (choice3?.reuse) {
4730
4879
  cwd = choice3.path;
@@ -4735,17 +4884,17 @@ async function main(activeDir, lane, seams = {}) {
4735
4884
  type: "runner",
4736
4885
  data: { worktree: cwd, worktreeOf: choice3.owner, setupRan }
4737
4886
  });
4738
- fs28.writeFileSync(wtFile, JSON.stringify({ path: cwd, of: choice3.owner }, null, 2));
4887
+ fs29.writeFileSync(wtFile, JSON.stringify({ path: cwd, of: choice3.owner }, null, 2));
4739
4888
  } else if (poolClaim) {
4740
4889
  cwd = poolClaim.dir;
4741
4890
  await deps.resetPool(repo, cwd, id, descriptor.systemRepair ? descriptor.pr?.headRefName : void 0);
4742
- fs28.writeFileSync(wtFile, JSON.stringify({ path: cwd, pool: poolClaim.label }, null, 2));
4891
+ fs29.writeFileSync(wtFile, JSON.stringify({ path: cwd, pool: poolClaim.label }, null, 2));
4743
4892
  } else {
4744
4893
  cwd = await deps.allocate(repo, id, descriptor.systemRepair ? descriptor.pr?.headRefName : void 0);
4745
4894
  acquireWorktreeLock(cwd, id, lane);
4746
- fs28.writeFileSync(wtFile, JSON.stringify({ path: cwd }, null, 2));
4895
+ fs29.writeFileSync(wtFile, JSON.stringify({ path: cwd }, null, 2));
4747
4896
  }
4748
- const worktreeOf = JSON.parse(fs28.readFileSync(wtFile, "utf8")).of;
4897
+ const worktreeOf = JSON.parse(fs29.readFileSync(wtFile, "utf8")).of;
4749
4898
  const inPool = poolSlotOf(cwd);
4750
4899
  mergeEvidence(id, lane, { worktree: cwd, worktreeOf, ...inPool ? { pool: poolSlotLabel(inPool.pool, inPool.slot) } : {} });
4751
4900
  const existingPr = boundPr(descriptor, lane);
@@ -4773,14 +4922,14 @@ async function main(activeDir, lane, seams = {}) {
4773
4922
  const envNudge = [process.env.LOBSTAH_NUDGE, wakeNote()].filter(Boolean).join("\n\n") || void 0;
4774
4923
  const planNudge = plan.cold && !envNudge ? coldNote(plan.cold, cwd, repo.trunk) : void 0;
4775
4924
  const promptWith = (nudge) => buildPrompt(brief, { id, nudge, attachments: descriptor.attachments, existingPr });
4776
- const binDir = path24.resolve(path24.dirname(fileURLToPath2(import.meta.url)), "..", "..", "..", "bin");
4777
- const workerPath = fs28.existsSync(path24.join(binDir, "lobstah")) ? `${binDir}${path24.delimiter}${process.env.PATH ?? ""}` : void 0;
4925
+ const binDir = path25.resolve(path25.dirname(fileURLToPath2(import.meta.url)), "..", "..", "..", "bin");
4926
+ const workerPath = fs29.existsSync(path25.join(binDir, "lobstah")) ? `${binDir}${path25.delimiter}${process.env.PATH ?? ""}` : void 0;
4778
4927
  let wallClockHit = false;
4779
4928
  let current;
4780
- const wallFile = path24.join(activeDir, "wallclock.json");
4929
+ const wallFile = path25.join(activeDir, "wallclock.json");
4781
4930
  const wallState = (() => {
4782
4931
  try {
4783
- return JSON.parse(fs28.readFileSync(wallFile, "utf8"));
4932
+ return JSON.parse(fs29.readFileSync(wallFile, "utf8"));
4784
4933
  } catch {
4785
4934
  return { elapsedMs: 0, windowMs: resolved.limits.wallClockSecs * 1e3 };
4786
4935
  }
@@ -4799,8 +4948,8 @@ async function main(activeDir, lane, seams = {}) {
4799
4948
  ) * 1e3;
4800
4949
  const persistWall = (elapsedMs, windowMs) => {
4801
4950
  const tmp = uniqueTempPath(wallFile);
4802
- fs28.writeFileSync(tmp, JSON.stringify({ ...wallState, elapsedMs, windowMs }));
4803
- fs28.renameSync(tmp, wallFile);
4951
+ fs29.writeFileSync(tmp, JSON.stringify({ ...wallState, elapsedMs, windowMs }));
4952
+ fs29.renameSync(tmp, wallFile);
4804
4953
  };
4805
4954
  const madeProgress = () => {
4806
4955
  const activity = readActivity(id, lane);
@@ -5104,13 +5253,13 @@ async function reapStarted(root = process.pid, graceMs) {
5104
5253
  var EXIT_LINGER_MS = 5e3;
5105
5254
  function runRunner(activeDirArg2, laneArg2) {
5106
5255
  const lane = laneArg2 === "chore" ? "chore" : "work";
5107
- const id = path25.basename(activeDirArg2);
5256
+ const id = path26.basename(activeDirArg2);
5108
5257
  main(activeDirArg2, lane, { reap: () => reapStarted(process.pid) }).catch((err) => {
5109
5258
  try {
5110
5259
  if (!isFinished(id, lane)) {
5111
5260
  appendStatus(id, lane, "failed", String(err instanceof Error ? err.message : err).slice(0, 500));
5112
5261
  }
5113
- fs29.renameSync(activeDirArg2, path25.join(laneDirs(lane).done, id));
5262
+ fs30.renameSync(activeDirArg2, path26.join(laneDirs(lane).done, id));
5114
5263
  } catch {
5115
5264
  }
5116
5265
  process.exitCode = 1;