lobstah 0.7.11 → 0.8.1

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 fs30 from "node:fs";
3
- import * as path26 from "node:path";
2
+ import * as fs33 from "node:fs";
3
+ import * as path29 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 fs23 from "node:fs";
13
- import * as path19 from "node:path";
12
+ import * as fs26 from "node:fs";
13
+ import * as path22 from "node:path";
14
14
 
15
15
  // packages/core/dist/paths.js
16
16
  import * as os from "node:os";
@@ -75,7 +75,7 @@ function evidencePath(id, lane) {
75
75
  }
76
76
 
77
77
  // packages/core/dist/status.js
78
- import * as fs22 from "node:fs";
78
+ import * as fs25 from "node:fs";
79
79
 
80
80
  // packages/core/dist/activity.js
81
81
  import * as fs2 from "node:fs";
@@ -285,8 +285,8 @@ var ActivityTracker = class {
285
285
  };
286
286
 
287
287
  // packages/core/dist/stats.js
288
- import * as fs21 from "node:fs";
289
- import * as path18 from "node:path";
288
+ import * as fs24 from "node:fs";
289
+ import * as path21 from "node:path";
290
290
 
291
291
  // packages/core/dist/dir-lock.js
292
292
  import fs3 from "node:fs";
@@ -503,8 +503,8 @@ function sanitizeWorker(value) {
503
503
  }
504
504
 
505
505
  // packages/core/dist/soak.js
506
- import * as fs19 from "node:fs";
507
- import * as path16 from "node:path";
506
+ import * as fs22 from "node:fs";
507
+ import * as path19 from "node:path";
508
508
 
509
509
  // packages/core/dist/evidence.js
510
510
  import * as fs4 from "node:fs";
@@ -620,13 +620,13 @@ function recordPush(id, lane, branches, at = (/* @__PURE__ */ new Date()).toISOS
620
620
  }
621
621
 
622
622
  // packages/core/dist/notices.js
623
- import fs17 from "node:fs";
624
- import * as path14 from "node:path";
623
+ import fs19 from "node:fs";
624
+ import * as path16 from "node:path";
625
625
 
626
626
  // packages/core/dist/config.js
627
- import * as fs6 from "node:fs";
627
+ import * as fs7 from "node:fs";
628
628
  import * as os2 from "node:os";
629
- import * as path5 from "node:path";
629
+ import * as path6 from "node:path";
630
630
 
631
631
  // node_modules/.pnpm/smol-toml@1.8.0/node_modules/smol-toml/dist/date.js
632
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;
@@ -794,7 +794,7 @@ function skipVoid(ctx, banNewLines, banComments) {
794
794
  skipComment(ctx);
795
795
  }
796
796
  }
797
- function skipUntil(ctx, sep, end) {
797
+ function skipUntil(ctx, sep3, end) {
798
798
  let ptr = ctx.p;
799
799
  if (!end) {
800
800
  ptr = indexOfNewline(ctx.s, ptr);
@@ -805,7 +805,7 @@ function skipUntil(ctx, sep, end) {
805
805
  let c = ctx.s.charCodeAt(ctx.p);
806
806
  if (c === 35) {
807
807
  skipComment(ctx);
808
- } else if (c === end || c === sep) {
808
+ } else if (c === end || c === sep3) {
809
809
  return;
810
810
  }
811
811
  }
@@ -1300,10 +1300,13 @@ function validReviewTool(value) {
1300
1300
  // packages/core/dist/reviews.js
1301
1301
  var REVIEW_WORK = ["off", "trap", "headless"];
1302
1302
  var REVIEW_POST = ["draft", "auto"];
1303
+ var REVIEW_MODES = ["notify", "on-demand", "auto-draft", "auto-review"];
1303
1304
  var DEFAULT_REVIEWS = {
1304
1305
  enabled: false,
1306
+ mode: "notify",
1307
+ publish: false,
1305
1308
  repos: "configured",
1306
- work: "trap",
1309
+ work: "off",
1307
1310
  post: "draft",
1308
1311
  limits: { wallClockSecs: 900, maxTurns: 40 },
1309
1312
  trapWaitSecs: 600,
@@ -1329,6 +1332,19 @@ function strings(value, where) {
1329
1332
  }
1330
1333
  function parseSettings(raw, where) {
1331
1334
  const out = {};
1335
+ if (raw.mode !== void 0)
1336
+ out.mode = oneOf(raw.mode, REVIEW_MODES, `${where}.mode`);
1337
+ else if (raw.post === "auto")
1338
+ out.mode = "auto-review";
1339
+ else if (raw.work === "off")
1340
+ out.mode = "on-demand";
1341
+ else if (raw.work !== void 0 || raw.post !== void 0)
1342
+ out.mode = "auto-draft";
1343
+ if (raw.publish !== void 0) {
1344
+ if (typeof raw.publish !== "boolean")
1345
+ throw new Error(`${where}.publish must be a boolean`);
1346
+ out.publish = raw.publish;
1347
+ }
1332
1348
  if (raw.work !== void 0)
1333
1349
  out.work = oneOf(raw.work, REVIEW_WORK, `${where}.work`);
1334
1350
  if (raw.post !== void 0)
@@ -1355,6 +1371,9 @@ function parseReviews(raw, reposRaw = {}) {
1355
1371
  if (typeof r !== "object" || Array.isArray(r))
1356
1372
  throw new Error("[reviews] must be a table");
1357
1373
  const base = parseSettings(r, "[reviews]");
1374
+ const requestedMode = base.mode ?? "notify";
1375
+ const publish = base.publish ?? requestedMode === "auto-review";
1376
+ const mode = requestedMode.startsWith("auto-") ? publish ? "auto-review" : "auto-draft" : requestedMode;
1358
1377
  const perRepo = {};
1359
1378
  for (const [key, repo] of Object.entries(reposRaw)) {
1360
1379
  if (repo.reviews !== void 0)
@@ -1363,6 +1382,11 @@ function parseReviews(raw, reposRaw = {}) {
1363
1382
  return {
1364
1383
  ...DEFAULT_REVIEWS,
1365
1384
  ...base,
1385
+ mode,
1386
+ publish,
1387
+ work: mode.startsWith("auto-") ? base.work && base.work !== "off" ? base.work : "trap" : "off",
1388
+ post: publish ? "auto" : "draft",
1389
+ ...Object.fromEntries(["identity", "tokenCommand", "tokenEnv", "tokenFile"].filter((k) => r[k] !== void 0).map((k) => [k, String(r[k])])),
1366
1390
  limits: { ...DEFAULT_REVIEWS.limits, ...base.limits },
1367
1391
  enabled: r.enabled === void 0 ? false : Boolean(r.enabled),
1368
1392
  repos: r.repos === void 0 ? "configured" : oneOf(r.repos, ["configured", "any"], "[reviews].repos"),
@@ -1371,6 +1395,79 @@ function parseReviews(raw, reposRaw = {}) {
1371
1395
  };
1372
1396
  }
1373
1397
 
1398
+ // packages/core/dist/cache-paths.js
1399
+ import * as fs6 from "node:fs";
1400
+ import * as path5 from "node:path";
1401
+ var heldCacheLocks = /* @__PURE__ */ new Set();
1402
+ function validCacheGlob(pattern) {
1403
+ return pattern.length > 0 && !/[\\\0:]/.test(pattern) && !path5.posix.isAbsolute(pattern) && !pattern.split("/").some((part) => !part || part === "." || part === ".." || part.toLowerCase() === ".git");
1404
+ }
1405
+ function withTrapCacheLock(trapId, action) {
1406
+ if (heldCacheLocks.has(trapId))
1407
+ return action();
1408
+ const dir = path5.join(lobstahHome(), "cache-locks");
1409
+ fs6.mkdirSync(dir, { recursive: true });
1410
+ return withDirLock(path5.join(dir, `trap-${encodeURIComponent(trapId)}`), () => {
1411
+ heldCacheLocks.add(trapId);
1412
+ try {
1413
+ return action();
1414
+ } finally {
1415
+ heldCacheLocks.delete(trapId);
1416
+ }
1417
+ }, {
1418
+ staleMs: 5e3,
1419
+ waitMs: 5e3,
1420
+ busy: () => new Error(`trap ${trapId} cache cleanup is busy; try again`)
1421
+ });
1422
+ }
1423
+ function segmentPattern(segment) {
1424
+ let source = "";
1425
+ for (let i = 0; i < segment.length; i++) {
1426
+ const char = segment[i];
1427
+ if (char === "*")
1428
+ source += ".*";
1429
+ else if (char === "?")
1430
+ source += ".";
1431
+ else if (char === "[" && segment.indexOf("]", i + 1) > i + 1) {
1432
+ const end = segment.indexOf("]", i + 1);
1433
+ const group = segment.slice(i + 1, end).replace(/^!/, "^");
1434
+ source += `[${group.replace(/\\/g, "\\\\")}]`;
1435
+ i = end;
1436
+ } else
1437
+ source += char.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1438
+ }
1439
+ return new RegExp(`^${source}$`);
1440
+ }
1441
+ function cacheDirectories(root, patterns) {
1442
+ const matches = /* @__PURE__ */ new Set();
1443
+ const walk = (dir, parts, index) => {
1444
+ if (index === parts.length) {
1445
+ if (dir !== root)
1446
+ matches.add(dir);
1447
+ return;
1448
+ }
1449
+ const part = parts[index];
1450
+ if (part === "**")
1451
+ walk(dir, parts, index + 1);
1452
+ const matcher = segmentPattern(part);
1453
+ for (const entry of fs6.readdirSync(dir, { withFileTypes: true })) {
1454
+ if (!entry.isDirectory() || entry.isSymbolicLink() || entry.name.toLowerCase() === ".git")
1455
+ continue;
1456
+ const child = path5.join(dir, entry.name);
1457
+ if (part === "**")
1458
+ walk(child, parts, index);
1459
+ else if (matcher.test(entry.name))
1460
+ walk(child, parts, index + 1);
1461
+ }
1462
+ };
1463
+ for (const pattern of patterns) {
1464
+ if (!validCacheGlob(pattern))
1465
+ continue;
1466
+ walk(root, pattern.split("/"), 0);
1467
+ }
1468
+ return [...matches].sort().filter((dir, _i, dirs) => !dirs.some((parent) => dir !== parent && dir.startsWith(parent + path5.sep)));
1469
+ }
1470
+
1374
1471
  // packages/core/dist/config.js
1375
1472
  var TRAP_PERMISSION_MODES = ["auto", "bypass", "bypassPermissions", "default", "acceptEdits", "plan", "dontAsk"];
1376
1473
  function parseHarness(raw, where) {
@@ -1515,6 +1612,8 @@ function parseAttentionKinds(raw) {
1515
1612
  }
1516
1613
  function parseSoak(raw) {
1517
1614
  const soak = { ...DEFAULT_SOAK, ...raw ?? {} };
1615
+ if (!Number.isInteger(soak.codexStartSecs) || soak.codexStartSecs < 1)
1616
+ throw new Error("soak.codexStartSecs must be a positive whole number");
1518
1617
  if (typeof soak.acceptWharfStarts !== "boolean")
1519
1618
  throw new Error("soak.acceptWharfStarts must be true or false");
1520
1619
  if (soak.terminal !== void 0 && soak.terminal !== "terminal" && soak.terminal !== "iterm") {
@@ -1523,6 +1622,7 @@ function parseSoak(raw) {
1523
1622
  return soak;
1524
1623
  }
1525
1624
  var DEFAULT_SOAK = {
1625
+ codexStartSecs: 600,
1526
1626
  acceptWharfStarts: false,
1527
1627
  deferSecs: 90,
1528
1628
  claimIdleNoticeSecs: 180,
@@ -1532,13 +1632,16 @@ var DEFAULT_SOAK = {
1532
1632
  signOffGraceSecs: 600
1533
1633
  };
1534
1634
  var DEFAULT_HELM = {
1635
+ chat: "full",
1535
1636
  queuedNoticeSecs: 180,
1536
1637
  stalledNoticeSecs: 1200,
1537
1638
  idleWorkingNoticeSecs: 60,
1538
1639
  ttlSecs: 1800,
1539
1640
  reportSecs: 900,
1540
1641
  armGraceSecs: 5,
1541
- todoStaleDays: 3
1642
+ todoStaleDays: 3,
1643
+ briefTodoLimit: 5,
1644
+ goalsNudgeSecs: 7200
1542
1645
  };
1543
1646
  var DEFAULT_GLASS = { port: 4949 };
1544
1647
  var DEFAULT_WAIT = { baseTimeoutSecs: 900, baseRepeats: 3, maxTimeoutSecs: 14400 };
@@ -1558,6 +1661,7 @@ var DEFAULT_LIMITS = {
1558
1661
  attachmentMaxBytes: 25 * 1024 * 1024,
1559
1662
  retentionDays: 0,
1560
1663
  minFreeGB: 0,
1664
+ cacheMinFreeGB: 50,
1561
1665
  reuseWorktree: true,
1562
1666
  releaseOnMerge: false
1563
1667
  };
@@ -1569,19 +1673,28 @@ function withConfigPath(parse2) {
1569
1673
  }
1570
1674
  }
1571
1675
  function configPath() {
1572
- return path5.join(lobstahHome(), "config.toml");
1676
+ return path6.join(lobstahHome(), "config.toml");
1573
1677
  }
1574
1678
  function expandHome(p) {
1575
- return p.startsWith("~/") ? path5.join(os2.homedir(), p.slice(2)) : p;
1679
+ return p.startsWith("~/") ? path6.join(os2.homedir(), p.slice(2)) : p;
1576
1680
  }
1577
1681
  function loadConfig() {
1578
1682
  const file2 = configPath();
1579
- const raw = fs6.existsSync(file2) ? parse(fs6.readFileSync(file2, "utf8")) : {};
1683
+ const raw = fs7.existsSync(file2) ? parse(fs7.readFileSync(file2, "utf8")) : {};
1684
+ const cacheMinFreeGB = raw.limits?.cacheMinFreeGB ?? DEFAULT_LIMITS.cacheMinFreeGB;
1685
+ if (typeof cacheMinFreeGB !== "number" || !Number.isFinite(cacheMinFreeGB) || cacheMinFreeGB < 0)
1686
+ throw new Error("[limits].cacheMinFreeGB must be a non-negative number");
1580
1687
  const petOpen = raw.pet?.open ?? "tab";
1581
1688
  if (!["tab", "app", "helm"].includes(petOpen))
1582
1689
  throw new Error(`[pet].open must be "tab", "app", or "helm" in ${configPath()}`);
1583
1690
  const watch = { ...DEFAULT_WATCH, ...raw.watch ?? {} };
1584
1691
  const helm = { ...DEFAULT_HELM, ...raw.helm ?? {} };
1692
+ if (helm.chat !== "full" && helm.chat !== "brief")
1693
+ throw new Error('[helm].chat must be "full" or "brief"');
1694
+ for (const key of ["briefTodoLimit", "goalsNudgeSecs"]) {
1695
+ if (typeof helm[key] !== "number" || !Number.isSafeInteger(helm[key]) || helm[key] < 0)
1696
+ throw new Error(`[helm].${key} must be a non-negative whole number in ${configPath()}`);
1697
+ }
1585
1698
  const wait = { ...DEFAULT_WAIT, ...raw.wait ?? {} };
1586
1699
  for (const key of ["baseTimeoutSecs", "baseRepeats", "maxTimeoutSecs"]) {
1587
1700
  if (typeof wait[key] !== "number" || !Number.isSafeInteger(wait[key]) || wait[key] <= 0)
@@ -1614,6 +1727,8 @@ function loadConfig() {
1614
1727
  refuseMoved(raw, reposRaw);
1615
1728
  const repos = {};
1616
1729
  for (const [key, r] of Object.entries(reposRaw)) {
1730
+ if (r.cacheDirs !== void 0 && (!Array.isArray(r.cacheDirs) || r.cacheDirs.some((glob) => typeof glob !== "string" || !validCacheGlob(glob))))
1731
+ throw new Error(`[repos.${key}].cacheDirs must be relative globs inside the worktree, without .. or absolute paths`);
1617
1732
  if (r.traps !== void 0 && (typeof r.traps !== "number" || !Number.isSafeInteger(r.traps) || r.traps < 0)) {
1618
1733
  throw new Error(`[repos.${key}].traps must be a non-negative whole number`);
1619
1734
  }
@@ -1626,6 +1741,7 @@ function loadConfig() {
1626
1741
  origin: r.origin ? String(r.origin) : void 0,
1627
1742
  trunk: String(r.trunk ?? "main"),
1628
1743
  setup: Array.isArray(r.setup) ? r.setup.map(String) : void 0,
1744
+ cacheDirs: r.cacheDirs,
1629
1745
  env: r.env ?? void 0,
1630
1746
  harness: parseHarness(r.harness, `[repos.${key}.harness]`),
1631
1747
  pickup: r.pickup === void 0 ? void 0 : Boolean(r.pickup),
@@ -1667,7 +1783,7 @@ function loadConfig() {
1667
1783
  hooks: parseHooks(raw.hooks),
1668
1784
  remindSecs: raw.remindSecs !== void 0 ? Number(raw.remindSecs) : void 0,
1669
1785
  readySettleSecs,
1670
- attentionKinds: parseAttentionKinds(raw.attentionKinds),
1786
+ attentionKinds: parseAttentionKinds(raw.attentionKinds ?? (raw.reviews?.enabled ? [...DEFAULT_ATTENTION_KINDS, "review"] : void 0)),
1671
1787
  reviews: withConfigPath(() => parseReviews(raw.reviews, reposRaw)),
1672
1788
  permissions: withConfigPath(() => parsePermissions(raw.permissions))
1673
1789
  };
@@ -1713,25 +1829,25 @@ function firstMeaningfulLine(...outputs) {
1713
1829
  }
1714
1830
 
1715
1831
  // packages/core/dist/pr-poll.js
1716
- import * as fs10 from "node:fs";
1717
- import * as path9 from "node:path";
1832
+ import * as fs11 from "node:fs";
1833
+ import * as path10 from "node:path";
1718
1834
 
1719
1835
  // packages/core/dist/prs.js
1720
- import * as fs7 from "node:fs";
1721
- import * as path6 from "node:path";
1836
+ import * as fs8 from "node:fs";
1837
+ import * as path7 from "node:path";
1722
1838
  function prsDir() {
1723
- return path6.join(lobstahHome(), "prs");
1839
+ return path7.join(lobstahHome(), "prs");
1724
1840
  }
1725
1841
  function prRecordFile(key) {
1726
1842
  const ref = parsePrRef(key);
1727
1843
  if (!ref)
1728
1844
  throw new Error(`not a PR key: ${key}`);
1729
1845
  const safe = (s) => s.replace(/[^A-Za-z0-9._-]/g, "_");
1730
- return path6.join(prsDir(), `${safe(ref.owner)}__${safe(ref.repo)}__${ref.number}.json`);
1846
+ return path7.join(prsDir(), `${safe(ref.owner)}__${safe(ref.repo)}__${ref.number}.json`);
1731
1847
  }
1732
1848
  function readPr(key) {
1733
1849
  try {
1734
- return JSON.parse(fs7.readFileSync(prRecordFile(key), "utf8"));
1850
+ return JSON.parse(fs8.readFileSync(prRecordFile(key), "utf8"));
1735
1851
  } catch {
1736
1852
  return void 0;
1737
1853
  }
@@ -1739,13 +1855,13 @@ function readPr(key) {
1739
1855
  function readPrs() {
1740
1856
  let files;
1741
1857
  try {
1742
- files = fs7.readdirSync(prsDir()).filter((f) => f.endsWith(".json"));
1858
+ files = fs8.readdirSync(prsDir()).filter((f) => f.endsWith(".json"));
1743
1859
  } catch {
1744
1860
  return [];
1745
1861
  }
1746
1862
  return files.flatMap((f) => {
1747
1863
  try {
1748
- const r = JSON.parse(fs7.readFileSync(path6.join(prsDir(), f), "utf8"));
1864
+ const r = JSON.parse(fs8.readFileSync(path7.join(prsDir(), f), "utf8"));
1749
1865
  return typeof r.key === "string" && typeof r.url === "string" ? [r] : [];
1750
1866
  } catch {
1751
1867
  return [];
@@ -1754,16 +1870,16 @@ function readPrs() {
1754
1870
  }
1755
1871
 
1756
1872
  // packages/core/dist/watch.js
1757
- import fs9 from "node:fs";
1758
- import * as path8 from "node:path";
1873
+ import fs10 from "node:fs";
1874
+ import * as path9 from "node:path";
1759
1875
 
1760
1876
  // packages/core/dist/github-budget.js
1761
- import * as fs8 from "node:fs";
1762
- import * as path7 from "node:path";
1763
- var file = () => path7.join(lobstahHome(), "github-budget.json");
1877
+ import * as fs9 from "node:fs";
1878
+ import * as path8 from "node:path";
1879
+ var file = () => path8.join(lobstahHome(), "github-budget.json");
1764
1880
  function read() {
1765
1881
  try {
1766
- return JSON.parse(fs8.readFileSync(file(), "utf8"));
1882
+ return JSON.parse(fs9.readFileSync(file(), "utf8"));
1767
1883
  } catch {
1768
1884
  return { resources: {} };
1769
1885
  }
@@ -1777,27 +1893,27 @@ function githubBlockedUntil(now2 = Date.now()) {
1777
1893
 
1778
1894
  // packages/core/dist/watch.js
1779
1895
  function watchesDir() {
1780
- return path8.join(lobstahHome(), "watches");
1896
+ return path9.join(lobstahHome(), "watches");
1781
1897
  }
1782
1898
  function slug(key) {
1783
1899
  return key.replace(/[^A-Za-z0-9._-]+/g, "-");
1784
1900
  }
1785
1901
  function watchPath(key) {
1786
- return path8.join(watchesDir(), `${slug(key)}.json`);
1902
+ return path9.join(watchesDir(), `${slug(key)}.json`);
1787
1903
  }
1788
1904
  function readWatch(key) {
1789
1905
  try {
1790
- return JSON.parse(fs9.readFileSync(watchPath(key), "utf8"));
1906
+ return JSON.parse(fs10.readFileSync(watchPath(key), "utf8"));
1791
1907
  } catch {
1792
1908
  return void 0;
1793
1909
  }
1794
1910
  }
1795
1911
 
1796
1912
  // packages/core/dist/pr-poll.js
1797
- var cycleFile = (repo) => path9.join(lobstahHome(), "pr-polls", `${repo.replace(/[^\w.-]/g, "_")}.json`);
1913
+ var cycleFile = (repo) => path10.join(lobstahHome(), "pr-polls", `${repo.replace(/[^\w.-]/g, "_")}.json`);
1798
1914
  var readCycle = (repo) => {
1799
1915
  try {
1800
- return JSON.parse(fs10.readFileSync(cycleFile(repo), "utf8"));
1916
+ return JSON.parse(fs11.readFileSync(cycleFile(repo), "utf8"));
1801
1917
  } catch {
1802
1918
  return void 0;
1803
1919
  }
@@ -1890,23 +2006,23 @@ function parseUnresolvedThreads(stdout) {
1890
2006
  }
1891
2007
 
1892
2008
  // packages/core/dist/worktrees.js
1893
- import * as fs11 from "node:fs";
1894
- import * as path10 from "node:path";
2009
+ import * as fs12 from "node:fs";
2010
+ import * as path11 from "node:path";
1895
2011
  var LANES = ["work", "chore"];
1896
2012
  function worktreePath(id) {
1897
- return path10.join(lobstahHome(), "worktrees", id);
2013
+ return path11.join(lobstahHome(), "worktrees", id);
1898
2014
  }
1899
2015
  function readRecord(file2) {
1900
2016
  try {
1901
- const r = JSON.parse(fs11.readFileSync(file2, "utf8"));
2017
+ const r = JSON.parse(fs12.readFileSync(file2, "utf8"));
1902
2018
  return typeof r.path === "string" ? r : void 0;
1903
2019
  } catch {
1904
2020
  return void 0;
1905
2021
  }
1906
2022
  }
1907
2023
  function ownerOfPath(p) {
1908
- const rel = path10.relative(path10.join(lobstahHome(), "worktrees"), p);
1909
- if (!rel || rel.startsWith("..") || path10.isAbsolute(rel))
2024
+ const rel = path11.relative(path11.join(lobstahHome(), "worktrees"), p);
2025
+ if (!rel || rel.startsWith("..") || path11.isAbsolute(rel))
1910
2026
  return void 0;
1911
2027
  return rel.split(/[\\/]/)[0];
1912
2028
  }
@@ -1919,7 +2035,7 @@ function dispatchWorktree(id, lane) {
1919
2035
  }
1920
2036
  const dirs = laneDirs(l);
1921
2037
  for (const dir of [dirs.active, dirs.done]) {
1922
- const rec = readRecord(path10.join(dir, id, "worktree.json"));
2038
+ const rec = readRecord(path11.join(dir, id, "worktree.json"));
1923
2039
  if (rec) {
1924
2040
  const owner = rec.of ?? ownerOfPath(rec.path) ?? id;
1925
2041
  return { path: rec.path, owner, reused: owner !== id };
@@ -1931,7 +2047,7 @@ function dispatchWorktree(id, lane) {
1931
2047
  function laneOf(id) {
1932
2048
  for (const l of LANES) {
1933
2049
  const d = laneDirs(l);
1934
- if (fs11.existsSync(path10.join(d.queue, `${id}.json`)) || fs11.existsSync(path10.join(d.active, id)) || fs11.existsSync(path10.join(d.done, id))) {
2050
+ if (fs12.existsSync(path11.join(d.queue, `${id}.json`)) || fs12.existsSync(path11.join(d.active, id)) || fs12.existsSync(path11.join(d.done, id))) {
1935
2051
  return l;
1936
2052
  }
1937
2053
  }
@@ -1951,7 +2067,7 @@ function followUpAncestors(id, lane) {
1951
2067
  function chainWorktree(followUp) {
1952
2068
  for (const id of [followUp, ...followUpAncestors(followUp)]) {
1953
2069
  const wt = dispatchWorktree(id, laneOf(id));
1954
- if (fs11.existsSync(wt.path))
2070
+ if (fs12.existsSync(wt.path))
1955
2071
  return { ...wt, from: id };
1956
2072
  }
1957
2073
  return void 0;
@@ -1966,27 +2082,27 @@ function processAlive(pid) {
1966
2082
  }
1967
2083
  }
1968
2084
  function worktreeGitDir(wt) {
1969
- const dotGit = path10.join(wt, ".git");
2085
+ const dotGit = path11.join(wt, ".git");
1970
2086
  try {
1971
- const st = fs11.statSync(dotGit);
2087
+ const st = fs12.statSync(dotGit);
1972
2088
  if (st.isDirectory())
1973
2089
  return dotGit;
1974
- const m = /^gitdir:\s*(.+?)\s*$/m.exec(fs11.readFileSync(dotGit, "utf8"));
1975
- return m ? path10.resolve(wt, m[1]) : void 0;
2090
+ const m = /^gitdir:\s*(.+?)\s*$/m.exec(fs12.readFileSync(dotGit, "utf8"));
2091
+ return m ? path11.resolve(wt, m[1]) : void 0;
1976
2092
  } catch {
1977
2093
  return void 0;
1978
2094
  }
1979
2095
  }
1980
2096
  function worktreeLockFile(wt) {
1981
2097
  const gitDir = worktreeGitDir(wt);
1982
- return gitDir ? path10.join(gitDir, "lobstah.lock") : void 0;
2098
+ return gitDir ? path11.join(gitDir, "lobstah.lock") : void 0;
1983
2099
  }
1984
2100
  function readWorktreeLock(wt) {
1985
2101
  const file2 = worktreeLockFile(wt);
1986
2102
  if (!file2)
1987
2103
  return void 0;
1988
2104
  try {
1989
- return JSON.parse(fs11.readFileSync(file2, "utf8"));
2105
+ return JSON.parse(fs12.readFileSync(file2, "utf8"));
1990
2106
  } catch {
1991
2107
  return void 0;
1992
2108
  }
@@ -1994,7 +2110,7 @@ function readWorktreeLock(wt) {
1994
2110
  function lockIsLive(lock) {
1995
2111
  if (lock.kind === "warm")
1996
2112
  return processAlive(lock.pid) && Date.now() - (Date.parse(lock.at) || 0) < WARM_LOCK_MAX_MS;
1997
- return fs11.existsSync(path10.join(laneDirs(lock.lane).active, lock.id));
2113
+ return fs12.existsSync(path11.join(laneDirs(lock.lane).active, lock.id));
1998
2114
  }
1999
2115
  function worktreeHolder(wt) {
2000
2116
  const lock = readWorktreeLock(wt);
@@ -2007,7 +2123,7 @@ function acquireWorktreeLock(wt, id, lane, kind) {
2007
2123
  return { id: "(no git dir)", lane, pid: 0, at: mine.at };
2008
2124
  for (let attempt2 = 0; attempt2 < 3; attempt2++) {
2009
2125
  try {
2010
- fs11.writeFileSync(file2, JSON.stringify(mine, null, 2), { flag: "wx" });
2126
+ fs12.writeFileSync(file2, JSON.stringify(mine, null, 2), { flag: "wx" });
2011
2127
  return void 0;
2012
2128
  } catch (err) {
2013
2129
  if (err.code !== "EEXIST")
@@ -2015,7 +2131,7 @@ function acquireWorktreeLock(wt, id, lane, kind) {
2015
2131
  }
2016
2132
  let raw;
2017
2133
  try {
2018
- raw = fs11.readFileSync(file2, "utf8");
2134
+ raw = fs12.readFileSync(file2, "utf8");
2019
2135
  } catch {
2020
2136
  continue;
2021
2137
  }
@@ -2026,14 +2142,14 @@ function acquireWorktreeLock(wt, id, lane, kind) {
2026
2142
  held2 = void 0;
2027
2143
  }
2028
2144
  if (held2?.id === id) {
2029
- fs11.writeFileSync(file2, JSON.stringify(mine, null, 2));
2145
+ fs12.writeFileSync(file2, JSON.stringify(mine, null, 2));
2030
2146
  return void 0;
2031
2147
  }
2032
2148
  if (held2 && lockIsLive(held2))
2033
2149
  return held2;
2034
2150
  try {
2035
- if (fs11.readFileSync(file2, "utf8") === raw)
2036
- fs11.rmSync(file2, { force: true });
2151
+ if (fs12.readFileSync(file2, "utf8") === raw)
2152
+ fs12.rmSync(file2, { force: true });
2037
2153
  } catch {
2038
2154
  }
2039
2155
  }
@@ -2045,22 +2161,22 @@ function releaseWorktreeLock(wt, id) {
2045
2161
  if (!file2)
2046
2162
  return;
2047
2163
  if (readWorktreeLock(wt)?.id === id)
2048
- fs11.rmSync(file2, { force: true });
2164
+ fs12.rmSync(file2, { force: true });
2049
2165
  }
2050
2166
 
2051
2167
  // packages/core/dist/events.js
2052
- import * as fs12 from "node:fs";
2168
+ import * as fs13 from "node:fs";
2053
2169
  function appendEvent(id, lane, ev) {
2054
- fs12.appendFileSync(eventsPath(id, lane), `${JSON.stringify(ev)}
2170
+ fs13.appendFileSync(eventsPath(id, lane), `${JSON.stringify(ev)}
2055
2171
  `);
2056
2172
  }
2057
2173
  function touchEvents(id, lane, at = /* @__PURE__ */ new Date()) {
2058
2174
  const file2 = eventsPath(id, lane);
2059
2175
  try {
2060
- fs12.utimesSync(file2, at, at);
2176
+ fs13.utimesSync(file2, at, at);
2061
2177
  } catch {
2062
- fs12.appendFileSync(file2, "");
2063
- fs12.utimesSync(file2, at, at);
2178
+ fs13.appendFileSync(file2, "");
2179
+ fs13.utimesSync(file2, at, at);
2064
2180
  }
2065
2181
  }
2066
2182
 
@@ -2074,31 +2190,31 @@ function isFinished(id, lane) {
2074
2190
  }
2075
2191
 
2076
2192
  // packages/core/dist/pools.js
2077
- import * as fs13 from "node:fs";
2078
- import * as path11 from "node:path";
2193
+ import * as fs14 from "node:fs";
2194
+ import * as path12 from "node:path";
2079
2195
  function poolsRoot() {
2080
- return path11.join(lobstahHome(), "pools");
2196
+ return path12.join(lobstahHome(), "pools");
2081
2197
  }
2082
2198
  function poolDir(pool) {
2083
- return path11.join(poolsRoot(), pool);
2199
+ return path12.join(poolsRoot(), pool);
2084
2200
  }
2085
2201
  function poolSlotPath(pool, slot) {
2086
- return path11.join(poolDir(pool), String(slot));
2202
+ return path12.join(poolDir(pool), String(slot));
2087
2203
  }
2088
2204
  function slotsDir(pool) {
2089
- return path11.join(poolDir(pool), ".slots");
2205
+ return path12.join(poolDir(pool), ".slots");
2090
2206
  }
2091
2207
  function poolSlotOf(p) {
2092
2208
  const real = (x) => {
2093
2209
  try {
2094
- return fs13.realpathSync.native(x);
2210
+ return fs14.realpathSync.native(x);
2095
2211
  } catch {
2096
- return path11.resolve(x);
2212
+ return path12.resolve(x);
2097
2213
  }
2098
2214
  };
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))
2215
+ for (const [rootDir, dir] of [[poolsRoot(), path12.resolve(p)], [real(poolsRoot()), real(p)]]) {
2216
+ const rel = path12.relative(rootDir, dir);
2217
+ if (!rel || rel.startsWith("..") || path12.isAbsolute(rel))
2102
2218
  continue;
2103
2219
  const parts = rel.split(/[\\/]/);
2104
2220
  if (parts.length !== 2 || !/^[1-9][0-9]*$/.test(parts[1]))
@@ -2112,20 +2228,20 @@ function poolSlotLabel(pool, slot) {
2112
2228
  }
2113
2229
  function readJson(file2) {
2114
2230
  try {
2115
- return JSON.parse(fs13.readFileSync(file2, "utf8"));
2231
+ return JSON.parse(fs14.readFileSync(file2, "utf8"));
2116
2232
  } catch {
2117
2233
  return void 0;
2118
2234
  }
2119
2235
  }
2120
2236
  function writeJson(file2, value) {
2121
- fs13.mkdirSync(path11.dirname(file2), { recursive: true });
2237
+ fs14.mkdirSync(path12.dirname(file2), { recursive: true });
2122
2238
  const tmp = uniqueTempPath(file2);
2123
- fs13.writeFileSync(tmp, JSON.stringify(value, null, 2));
2239
+ fs14.writeFileSync(tmp, JSON.stringify(value, null, 2));
2124
2240
  atomicRenameSync(tmp, file2);
2125
2241
  }
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`);
2242
+ var metaFile = (pool, slot) => path12.join(slotsDir(pool), `${slot}.json`);
2243
+ var claimFile = (pool, slot) => path12.join(slotsDir(pool), `${slot}.claim.json`);
2244
+ var outFile = (pool, slot) => path12.join(slotsDir(pool), `${slot}.out.json`);
2129
2245
  function readSlotMeta(pool, slot) {
2130
2246
  return readJson(metaFile(pool, slot)) ?? {};
2131
2247
  }
@@ -2145,7 +2261,7 @@ function writeSlotOut(pool, slot, out) {
2145
2261
  writeJson(outFile(pool, slot), out);
2146
2262
  }
2147
2263
  function clearSlotOut(pool, slot) {
2148
- fs13.rmSync(outFile(pool, slot), { force: true });
2264
+ fs14.rmSync(outFile(pool, slot), { force: true });
2149
2265
  }
2150
2266
  function dispatchHolder(dir) {
2151
2267
  const lock = readWorktreeLock(dir);
@@ -2155,7 +2271,7 @@ function poolSlotView(pool, slot) {
2155
2271
  const dir = poolSlotPath(pool, slot);
2156
2272
  const lastClaim = readSlotClaim(pool, slot)?.id;
2157
2273
  const base = { slot, path: dir, ...lastClaim ? { lastClaim } : {} };
2158
- if (!fs13.existsSync(dir)) {
2274
+ if (!fs14.existsSync(dir)) {
2159
2275
  const meta2 = readSlotMeta(pool, slot);
2160
2276
  return { ...base, state: "missing", ...meta2.error ? { reason: meta2.error } : {} };
2161
2277
  }
@@ -2170,8 +2286,8 @@ function poolSlotView(pool, slot) {
2170
2286
  return { ...base, state: "warming", ...meta.error ? { reason: meta.error } : {} };
2171
2287
  return { ...base, state: "free" };
2172
2288
  }
2173
- var warmStateFile = (pool) => path11.join(poolDir(pool), ".warm-state.json");
2174
- var warmLockFile = (pool) => path11.join(poolDir(pool), ".warm.lock");
2289
+ var warmStateFile = (pool) => path12.join(poolDir(pool), ".warm-state.json");
2290
+ var warmLockFile = (pool) => path12.join(poolDir(pool), ".warm.lock");
2175
2291
  var POOL_WARM_MAX_MS = 60 * 6e4;
2176
2292
  function readPoolWarmState(pool) {
2177
2293
  return readJson(warmStateFile(pool)) ?? {};
@@ -2193,15 +2309,15 @@ function poolWarmRunning(pool, now2 = Date.now()) {
2193
2309
  }
2194
2310
  function takePoolWarmLock(pool) {
2195
2311
  const file2 = warmLockFile(pool);
2196
- fs13.mkdirSync(path11.dirname(file2), { recursive: true });
2312
+ fs14.mkdirSync(path12.dirname(file2), { recursive: true });
2197
2313
  const mine = JSON.stringify({ pid: process.pid, at: (/* @__PURE__ */ new Date()).toISOString() });
2198
2314
  for (let attempt2 = 0; attempt2 < 2; attempt2++) {
2199
2315
  try {
2200
- fs13.writeFileSync(file2, mine, { flag: "wx" });
2316
+ fs14.writeFileSync(file2, mine, { flag: "wx" });
2201
2317
  return () => {
2202
2318
  try {
2203
- if (fs13.readFileSync(file2, "utf8") === mine)
2204
- fs13.rmSync(file2, { force: true });
2319
+ if (fs14.readFileSync(file2, "utf8") === mine)
2320
+ fs14.rmSync(file2, { force: true });
2205
2321
  } catch {
2206
2322
  }
2207
2323
  };
@@ -2211,7 +2327,7 @@ function takePoolWarmLock(pool) {
2211
2327
  }
2212
2328
  if (poolWarmRunning(pool))
2213
2329
  return void 0;
2214
- fs13.rmSync(file2, { force: true });
2330
+ fs14.rmSync(file2, { force: true });
2215
2331
  }
2216
2332
  return void 0;
2217
2333
  }
@@ -2220,41 +2336,70 @@ var POOL_FETCH_MS = 10 * 6e4;
2220
2336
  var POOL_RECHECK_MS = 5 * 6e4;
2221
2337
 
2222
2338
  // packages/core/dist/disk.js
2223
- import * as fs14 from "node:fs";
2339
+ import * as fs15 from "node:fs";
2224
2340
  var GB = 1024 ** 3;
2225
2341
  var statfsFreeBytes = (dir) => {
2226
- const s = fs14.statfsSync(dir);
2342
+ const s = fs15.statfsSync(dir);
2227
2343
  return Number(s.bavail) * Number(s.bsize);
2228
2344
  };
2229
2345
  function formatGB(bytes) {
2230
2346
  return `${(bytes / GB).toFixed(1).replace(/\.0$/, "")} GB`;
2231
2347
  }
2232
2348
 
2349
+ // packages/core/dist/roster.js
2350
+ import * as fs16 from "node:fs";
2351
+ import * as path13 from "node:path";
2352
+ function rosterDir() {
2353
+ return path13.join(lobstahHome(), "roster");
2354
+ }
2355
+ function rosterPath(trapId) {
2356
+ return path13.join(rosterDir(), `${trapId}.json`);
2357
+ }
2358
+ function readRoster(trapId) {
2359
+ if (!/^[a-z0-9-]+$/.test(trapId))
2360
+ return void 0;
2361
+ try {
2362
+ const parsed = JSON.parse(fs16.readFileSync(rosterPath(trapId), "utf8"));
2363
+ return parsed.trapId === trapId && typeof parsed.name === "string" ? parsed : void 0;
2364
+ } catch {
2365
+ return void 0;
2366
+ }
2367
+ }
2368
+ function listRoster() {
2369
+ let files;
2370
+ try {
2371
+ files = fs16.readdirSync(rosterDir()).filter((f) => f.endsWith(".json"));
2372
+ } catch {
2373
+ return [];
2374
+ }
2375
+ return files.map((f) => readRoster(f.slice(0, -".json".length))).filter((e) => e !== void 0).sort((a, b) => a.name.localeCompare(b.name));
2376
+ }
2377
+
2233
2378
  // packages/core/dist/inbox.js
2234
- import * as fs15 from "node:fs";
2235
- import * as path12 from "node:path";
2379
+ import * as fs17 from "node:fs";
2380
+ import * as path14 from "node:path";
2236
2381
  var metaName = (file2) => file2.replace(/\.msg$/, ".meta.json");
2237
2382
  function inboxDir(id, lane) {
2238
- return path12.join(laneDirs(lane).inbox, id);
2383
+ return path14.join(laneDirs(lane).inbox, id);
2239
2384
  }
2240
2385
  function unhandled(id, lane) {
2241
2386
  const dir = inboxDir(id, lane);
2242
- return readDirIfPresent(dir).filter((f) => f.endsWith(".msg")).sort().map((f) => ({ file: f, text: fs15.readFileSync(path12.join(dir, f), "utf8") }));
2387
+ return readDirIfPresent(dir).filter((f) => f.endsWith(".msg")).sort().map((f) => ({ file: f, text: fs17.readFileSync(path14.join(dir, f), "utf8") }));
2243
2388
  }
2244
2389
  function acknowledge(id, lane, file2) {
2245
2390
  const dir = inboxDir(id, lane);
2246
- fs15.mkdirSync(path12.join(dir, "handled"), { recursive: true });
2247
- fs15.renameSync(path12.join(dir, file2), path12.join(dir, "handled", file2));
2391
+ fs17.mkdirSync(path14.join(dir, "handled"), { recursive: true });
2392
+ fs17.renameSync(path14.join(dir, file2), path14.join(dir, "handled", file2));
2248
2393
  try {
2249
- fs15.renameSync(path12.join(dir, metaName(file2)), path12.join(dir, "handled", metaName(file2)));
2394
+ fs17.renameSync(path14.join(dir, metaName(file2)), path14.join(dir, "handled", metaName(file2)));
2250
2395
  } catch {
2251
2396
  }
2252
2397
  }
2253
2398
 
2254
2399
  // packages/core/dist/resume.js
2255
- import * as fs16 from "node:fs";
2400
+ import * as fs18 from "node:fs";
2256
2401
  import * as os3 from "node:os";
2257
- import * as path13 from "node:path";
2402
+ import * as path15 from "node:path";
2258
2403
  import { spawnSync as spawnSync2 } from "node:child_process";
2259
2404
  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;
2260
2405
  function harnessFromSessionId(sessionId) {
@@ -2265,7 +2410,7 @@ function claimOf(id, lane) {
2265
2410
  const dirs = laneDirs(lane);
2266
2411
  for (const dir of [dirs.active, dirs.done]) {
2267
2412
  try {
2268
- return JSON.parse(fs16.readFileSync(path13.join(dir, id, "claim.json"), "utf8"));
2413
+ return JSON.parse(fs18.readFileSync(path15.join(dir, id, "claim.json"), "utf8"));
2269
2414
  } catch {
2270
2415
  }
2271
2416
  }
@@ -2315,11 +2460,11 @@ function isUnresumable(error) {
2315
2460
  return error !== void 0 && UNRESUMABLE.test(error);
2316
2461
  }
2317
2462
  function worktreeProgress(worktree, trunk) {
2318
- if (!worktree || !fs16.existsSync(worktree))
2463
+ if (!worktree || !fs18.existsSync(worktree))
2319
2464
  return "No worktree progress recorded.";
2320
- const git2 = (...a) => spawnSync2("git", a, { cwd: worktree, encoding: "utf8" }).stdout?.trim() ?? "";
2321
- const commits = trunk ? git2("log", "--oneline", `origin/${trunk}..HEAD`) : git2("log", "--oneline", "-15");
2322
- const status = git2("status", "--short");
2465
+ const git3 = (...a) => spawnSync2("git", a, { cwd: worktree, encoding: "utf8" }).stdout?.trim() ?? "";
2466
+ const commits = trunk ? git3("log", "--oneline", `origin/${trunk}..HEAD`) : git3("log", "--oneline", "-15");
2467
+ const status = git3("status", "--short");
2323
2468
  return `Commits so far:
2324
2469
  ${commits || "(none)"}
2325
2470
 
@@ -2348,31 +2493,31 @@ function handoffNote(fromHarness, progress, why) {
2348
2493
  ${progress}`;
2349
2494
  }
2350
2495
  function codexHome(env = process.env) {
2351
- return env.CODEX_HOME ?? path13.join(os3.homedir(), ".codex");
2496
+ return env.CODEX_HOME ?? path15.join(os3.homedir(), ".codex");
2352
2497
  }
2353
2498
  function codexRolloutFile(threadId, home = codexHome()) {
2354
2499
  const suffix = `-${threadId}.jsonl`;
2355
2500
  const walk = (dir, depth) => {
2356
2501
  let entries;
2357
2502
  try {
2358
- entries = fs16.readdirSync(dir, { withFileTypes: true });
2503
+ entries = fs18.readdirSync(dir, { withFileTypes: true });
2359
2504
  } catch {
2360
2505
  return void 0;
2361
2506
  }
2362
2507
  for (const e of entries) {
2363
2508
  if (e.isFile() && e.name.startsWith("rollout-") && e.name.endsWith(suffix))
2364
- return path13.join(dir, e.name);
2509
+ return path15.join(dir, e.name);
2365
2510
  }
2366
2511
  if (depth === 0)
2367
2512
  return void 0;
2368
2513
  for (const e of entries.filter((x) => x.isDirectory()).sort((a, b) => b.name.localeCompare(a.name))) {
2369
- const hit = walk(path13.join(dir, e.name), depth - 1);
2514
+ const hit = walk(path15.join(dir, e.name), depth - 1);
2370
2515
  if (hit)
2371
2516
  return hit;
2372
2517
  }
2373
2518
  return void 0;
2374
2519
  };
2375
- return walk(path13.join(home, "sessions"), 3) ?? walk(path13.join(home, "archived_sessions"), 0);
2520
+ return walk(path15.join(home, "sessions"), 3) ?? walk(path15.join(home, "archived_sessions"), 0);
2376
2521
  }
2377
2522
  function codexDesktopThread(threadId, home = codexHome()) {
2378
2523
  const file2 = codexRolloutFile(threadId, home);
@@ -2380,16 +2525,18 @@ function codexDesktopThread(threadId, home = codexHome()) {
2380
2525
  return void 0;
2381
2526
  let head = "";
2382
2527
  try {
2383
- const fd = fs16.openSync(file2, "r");
2528
+ const fd = fs18.openSync(file2, "r");
2384
2529
  try {
2385
2530
  const buf = Buffer.alloc(4096);
2386
- head = buf.subarray(0, fs16.readSync(fd, buf, 0, buf.length, 0)).toString("utf8");
2531
+ head = buf.subarray(0, fs18.readSync(fd, buf, 0, buf.length, 0)).toString("utf8");
2387
2532
  } finally {
2388
- fs16.closeSync(fd);
2533
+ fs18.closeSync(fd);
2389
2534
  }
2390
2535
  } catch {
2391
2536
  return void 0;
2392
2537
  }
2538
+ if (/"source"\s*:\s*"vscode"/.test(head))
2539
+ return "VS Code extension";
2393
2540
  const originator = /"originator"\s*:\s*"([^"]*)"/.exec(head)?.[1];
2394
2541
  return originator && /desktop/i.test(originator) ? originator : void 0;
2395
2542
  }
@@ -2397,16 +2544,16 @@ var CODEX_DESKTOP_THREAD = "Codex desktop thread; not resumable from the CLI";
2397
2544
 
2398
2545
  // packages/core/dist/notices.js
2399
2546
  function noticesDir() {
2400
- return path14.join(lobstahHome(), "notices");
2547
+ return path16.join(lobstahHome(), "notices");
2401
2548
  }
2402
2549
  var counter = 0;
2403
2550
  function postNotice(n) {
2404
2551
  const dir = noticesDir();
2405
- fs17.mkdirSync(dir, { recursive: true });
2552
+ fs19.mkdirSync(dir, { recursive: true });
2406
2553
  if (n.dedupeKey) {
2407
- const marker = path14.join(dir, `.dedupe-${n.dedupeKey.replace(/[^A-Za-z0-9_-]/g, "_")}`);
2554
+ const marker = path16.join(dir, `.dedupe-${n.dedupeKey.replace(/[^A-Za-z0-9_-]/g, "_")}`);
2408
2555
  try {
2409
- fs17.writeFileSync(marker, "", { flag: "wx" });
2556
+ fs19.writeFileSync(marker, "", { flag: "wx" });
2410
2557
  } catch {
2411
2558
  return void 0;
2412
2559
  }
@@ -2424,9 +2571,9 @@ function postNotice(n) {
2424
2571
  ...n.quiet ? { quiet: true } : {},
2425
2572
  ...n.stateHash ? { stateHash: n.stateHash } : {}
2426
2573
  };
2427
- const file2 = path14.join(dir, `${seq}.json`);
2574
+ const file2 = path16.join(dir, `${seq}.json`);
2428
2575
  const tmp = uniqueTempPath(file2);
2429
- fs17.writeFileSync(tmp, JSON.stringify(notice, null, 2));
2576
+ fs19.writeFileSync(tmp, JSON.stringify(notice, null, 2));
2430
2577
  atomicRenameSync(tmp, file2);
2431
2578
  return notice;
2432
2579
  }
@@ -2442,15 +2589,208 @@ function attachmentBlock(attachments) {
2442
2589
  ].join("\n");
2443
2590
  }
2444
2591
 
2592
+ // packages/core/dist/cache-cleanup.js
2593
+ import * as fs20 from "node:fs";
2594
+ import * as path17 from "node:path";
2595
+ import { execFileSync } from "node:child_process";
2596
+ var git = (dir, args) => execFileSync("git", ["-C", dir, ...args], {
2597
+ encoding: "utf8",
2598
+ stdio: ["ignore", "pipe", "ignore"],
2599
+ maxBuffer: 64 * 1024 * 1024
2600
+ });
2601
+ function repoCachesConfigured(repo) {
2602
+ try {
2603
+ return repo !== void 0 && !!loadConfig().repos[repo]?.cacheDirs?.length;
2604
+ } catch {
2605
+ return false;
2606
+ }
2607
+ }
2608
+ function cacheTrapIdle(trap) {
2609
+ const live = readTrap(trap.trapId);
2610
+ if (!live?.claimed)
2611
+ return true;
2612
+ const lane = laneOf(live.claimed);
2613
+ if (!lane)
2614
+ return false;
2615
+ const verb = readStatusLog(live.claimed, lane).at(-1)?.verb;
2616
+ return verb !== void 0 && verb !== "working";
2617
+ }
2618
+ function cacheWorktree(root, repoPath) {
2619
+ const canonical = (dir) => {
2620
+ const real = fs20.realpathSync.native(dir);
2621
+ return process.platform === "win32" ? real.toLowerCase() : real;
2622
+ };
2623
+ if (fs20.lstatSync(root).isSymbolicLink())
2624
+ return false;
2625
+ const top = git(root, ["rev-parse", "--show-toplevel"]).trim();
2626
+ const common = path17.resolve(root, git(root, ["rev-parse", "--git-common-dir"]).trim());
2627
+ const privateGit = git(root, ["rev-parse", "--absolute-git-dir"]).trim();
2628
+ const repoCommon = path17.resolve(repoPath, git(repoPath, ["rev-parse", "--git-common-dir"]).trim());
2629
+ return canonical(root) === canonical(top) && canonical(common) !== canonical(privateGit) && canonical(common) === canonical(repoCommon);
2630
+ }
2631
+ function safeCacheTarget(root, target, tracked) {
2632
+ const relative6 = path17.relative(root, target);
2633
+ if (fs20.lstatSync(root).isSymbolicLink())
2634
+ return false;
2635
+ if (!relative6 || relative6.startsWith("..") || path17.isAbsolute(relative6))
2636
+ return false;
2637
+ let current = root;
2638
+ for (const part of relative6.split(path17.sep)) {
2639
+ current = path17.join(current, part);
2640
+ if (part.toLowerCase() === ".git" || fs20.lstatSync(current).isSymbolicLink())
2641
+ return false;
2642
+ }
2643
+ const name = relative6.split(path17.sep).join("/").toLowerCase();
2644
+ return !tracked.some((trackedPath) => {
2645
+ const file2 = trackedPath.toLowerCase();
2646
+ return file2 === name || file2.startsWith(name + "/") || name.startsWith(file2 + "/");
2647
+ });
2648
+ }
2649
+ function cacheBytes(target) {
2650
+ const stat = fs20.lstatSync(target);
2651
+ if (stat.isSymbolicLink())
2652
+ return 0;
2653
+ if (!stat.isDirectory())
2654
+ return process.platform === "win32" || stat.blocks === void 0 ? stat.size : stat.blocks * 512;
2655
+ const entries = fs20.readdirSync(target);
2656
+ if (entries.some((name) => name.toLowerCase() === ".git"))
2657
+ throw new Error("nested repository is not a cache");
2658
+ return entries.reduce((bytes, name) => bytes + cacheBytes(path17.join(target, name)), 0);
2659
+ }
2660
+ function planTrapCache(trap, cfg) {
2661
+ const repo = trap.repo ? cfg.repos[trap.repo] : void 0;
2662
+ if (!repo?.cacheDirs?.length || !cacheTrapIdle(trap))
2663
+ return void 0;
2664
+ try {
2665
+ const root = fs20.realpathSync.native(trap.worktree);
2666
+ if (!cacheWorktree(trap.worktree, repo.path))
2667
+ return void 0;
2668
+ const tracked = git(root, ["ls-files", "-z"]).split("\0").filter(Boolean);
2669
+ const targets = [];
2670
+ let bytes = 0;
2671
+ for (const target of cacheDirectories(root, repo.cacheDirs)) {
2672
+ try {
2673
+ if (!safeCacheTarget(root, target, tracked))
2674
+ continue;
2675
+ const size = cacheBytes(target);
2676
+ targets.push(target);
2677
+ bytes += size;
2678
+ } catch {
2679
+ }
2680
+ }
2681
+ return targets.length ? { trapId: trap.trapId, repo: trap.repo, worktree: root, targets, bytes } : void 0;
2682
+ } catch {
2683
+ return void 0;
2684
+ }
2685
+ }
2686
+ function planTrapCaches(cfg = loadConfig()) {
2687
+ const traps = new Map([...listRoster(), ...listTraps()].map((trap) => [trap.trapId, trap]));
2688
+ return [...traps.values()].flatMap((trap) => {
2689
+ const plan = planTrapCache(trap, cfg);
2690
+ return plan ? [plan] : [];
2691
+ }).sort((a, b) => b.bytes - a.bytes || a.trapId.localeCompare(b.trapId));
2692
+ }
2693
+ function clearTrapCaches(trap, cfg = loadConfig()) {
2694
+ if (!trap.repo || !cfg.repos[trap.repo]?.cacheDirs?.length)
2695
+ return 0;
2696
+ return withTrapCacheLock(trap.trapId, () => {
2697
+ const plan = planTrapCache(trap, cfg);
2698
+ if (!plan)
2699
+ return 0;
2700
+ let bytes = 0;
2701
+ for (const target of plan.targets) {
2702
+ try {
2703
+ const tracked = git(plan.worktree, ["ls-files", "-z"]).split("\0").filter(Boolean);
2704
+ if (!cacheTrapIdle(trap) || !safeCacheTarget(plan.worktree, target, tracked))
2705
+ continue;
2706
+ const size = cacheBytes(target);
2707
+ fs20.rmSync(target, { recursive: true, force: true });
2708
+ bytes += size;
2709
+ } catch {
2710
+ }
2711
+ }
2712
+ return bytes;
2713
+ });
2714
+ }
2715
+ function clearFinishedTrapCaches(trap, reason) {
2716
+ if (!repoCachesConfigured(trap.repo))
2717
+ return;
2718
+ try {
2719
+ const free = () => {
2720
+ try {
2721
+ return statfsFreeBytes(trap.worktree);
2722
+ } catch {
2723
+ return void 0;
2724
+ }
2725
+ };
2726
+ const before = free();
2727
+ const bytes = clearTrapCaches(trap);
2728
+ const after = free();
2729
+ const recovered = before !== void 0 && after !== void 0 ? Math.max(0, after - before) : void 0;
2730
+ if (bytes > 0)
2731
+ postNotice({
2732
+ kind: "caches-cleared",
2733
+ repo: trap.repo,
2734
+ refId: trap.trapId,
2735
+ quiet: true,
2736
+ text: `trap ${trap.trapId} ${reason}: cleared ${bytes} cache bytes (${formatGB(bytes)})` + (recovered !== void 0 ? `; ${recovered} free bytes recovered` : "")
2737
+ });
2738
+ } catch {
2739
+ }
2740
+ }
2741
+ function recoverTrapCaches(cfg, volume, readFree = statfsFreeBytes, log = () => {
2742
+ }) {
2743
+ if (!Object.values(cfg.repos).some((repo) => repo.cacheDirs?.length))
2744
+ return 0;
2745
+ if (cfg.limits.cacheMinFreeGB === 0)
2746
+ return 0;
2747
+ const threshold = Math.max(cfg.limits.cacheMinFreeGB ?? 50, cfg.limits.minFreeGB ?? 0) * GB;
2748
+ if (!(threshold > 0))
2749
+ return 0;
2750
+ try {
2751
+ const before = readFree(volume);
2752
+ if (before >= threshold)
2753
+ return 0;
2754
+ let bytes = 0;
2755
+ let traps = 0;
2756
+ const device = fs20.statSync(volume).dev;
2757
+ for (const plan of planTrapCaches(cfg)) {
2758
+ if (readFree(volume) >= threshold)
2759
+ break;
2760
+ try {
2761
+ if (fs20.statSync(plan.worktree).dev !== device)
2762
+ continue;
2763
+ const removed = clearTrapCaches(plan, cfg);
2764
+ if (removed > 0) {
2765
+ bytes += removed;
2766
+ traps++;
2767
+ }
2768
+ } catch (error) {
2769
+ log(`cache cleanup kept trap ${plan.trapId}: ${error instanceof Error ? error.message : String(error)}`);
2770
+ }
2771
+ }
2772
+ if (bytes > 0) {
2773
+ const recovered = Math.max(0, readFree(volume) - before);
2774
+ const text = `cache pressure cleanup: ${bytes} cache bytes cleared in ${traps} idle trap(s); ${recovered} free bytes recovered (${formatGB(recovered)})`;
2775
+ postNotice({ kind: "caches-cleared", text });
2776
+ log(text);
2777
+ }
2778
+ return bytes;
2779
+ } catch (error) {
2780
+ log(`cache pressure cleanup skipped: ${error instanceof Error ? error.message : String(error)}`);
2781
+ return 0;
2782
+ }
2783
+ }
2784
+
2445
2785
  // packages/core/dist/helm.js
2446
- import * as fs18 from "node:fs";
2447
- import * as path15 from "node:path";
2786
+ import * as fs21 from "node:fs";
2787
+ import * as path18 from "node:path";
2448
2788
  function helmDir() {
2449
- return path15.join(lobstahHome(), "helm");
2789
+ return path18.join(lobstahHome(), "helm");
2450
2790
  }
2451
2791
  function listHelms() {
2452
2792
  try {
2453
- return fs18.readdirSync(helmDir()).filter((f) => f.endsWith(".json")).map((f) => JSON.parse(fs18.readFileSync(path15.join(helmDir(), f), "utf8")));
2793
+ return fs21.readdirSync(helmDir()).filter((f) => f.endsWith(".json")).map((f) => JSON.parse(fs21.readFileSync(path18.join(helmDir(), f), "utf8")));
2454
2794
  } catch {
2455
2795
  return [];
2456
2796
  }
@@ -2461,39 +2801,39 @@ function liveHelms(ttlMs, now2 = Date.now()) {
2461
2801
 
2462
2802
  // packages/core/dist/soak.js
2463
2803
  function regPath(trapId) {
2464
- return path16.join(soakingDir(), `${trapId}.json`);
2804
+ return path19.join(soakingDir(), `${trapId}.json`);
2465
2805
  }
2466
2806
  function readTrap(trapId) {
2467
2807
  try {
2468
- return JSON.parse(fs19.readFileSync(regPath(trapId), "utf8"));
2808
+ return JSON.parse(fs22.readFileSync(regPath(trapId), "utf8"));
2469
2809
  } catch {
2470
2810
  return void 0;
2471
2811
  }
2472
2812
  }
2473
2813
  function listTraps() {
2474
2814
  try {
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");
2815
+ return fs22.readdirSync(soakingDir()).filter((f) => f.endsWith(".json")).map((f) => JSON.parse(fs22.readFileSync(path19.join(soakingDir(), f), "utf8"))).filter((r) => typeof r.trapId === "string");
2476
2816
  } catch {
2477
2817
  return [];
2478
2818
  }
2479
2819
  }
2480
2820
  function claimPath(id, lane) {
2481
- return path16.join(laneDirs(lane).active, id, "claim.json");
2821
+ return path19.join(laneDirs(lane).active, id, "claim.json");
2482
2822
  }
2483
2823
  function readSessionClaim(id, lane) {
2484
2824
  try {
2485
- return JSON.parse(fs19.readFileSync(claimPath(id, lane), "utf8"));
2825
+ return JSON.parse(fs22.readFileSync(claimPath(id, lane), "utf8"));
2486
2826
  } catch {
2487
2827
  return void 0;
2488
2828
  }
2489
2829
  }
2490
2830
 
2491
2831
  // packages/core/dist/catch-context.js
2492
- import * as fs20 from "node:fs";
2493
- import * as path17 from "node:path";
2832
+ import * as fs23 from "node:fs";
2833
+ import * as path20 from "node:path";
2494
2834
  function readCatchContext(dir, id) {
2495
2835
  try {
2496
- return JSON.parse(fs20.readFileSync(path17.join(dir, `${id}.catch-context`), "utf8"));
2836
+ return JSON.parse(fs23.readFileSync(path20.join(dir, `${id}.catch-context`), "utf8"));
2497
2837
  } catch {
2498
2838
  return {};
2499
2839
  }
@@ -2506,19 +2846,19 @@ function observeLocalCatch(id, lane, phase, now2 = Date.now()) {
2506
2846
  const helms = liveHelms(cfg.helm.ttlSecs * 1e3, now2);
2507
2847
  const present = repo ? helms.some((h) => h.repos.includes(repo)) : null;
2508
2848
  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 };
2509
- const file2 = path17.join(dir, `${id}.catch-context`), tmp = uniqueTempPath(file2);
2849
+ const file2 = path20.join(dir, `${id}.catch-context`), tmp = uniqueTempPath(file2);
2510
2850
  try {
2511
- fs20.writeFileSync(tmp, JSON.stringify(next));
2512
- fs20.renameSync(tmp, file2);
2851
+ fs23.writeFileSync(tmp, JSON.stringify(next));
2852
+ fs23.renameSync(tmp, file2);
2513
2853
  } finally {
2514
- fs20.rmSync(tmp, { force: true });
2854
+ fs23.rmSync(tmp, { force: true });
2515
2855
  }
2516
2856
  }
2517
2857
 
2518
2858
  // packages/core/dist/stats.js
2519
2859
  var DAILY_RETENTION_DAYS = 400;
2520
2860
  function statsPath() {
2521
- return path18.join(lobstahHome(), "stats.json");
2861
+ return path21.join(lobstahHome(), "stats.json");
2522
2862
  }
2523
2863
  function shiftDay(day, days) {
2524
2864
  const [y, m, d] = day.split("-").map(Number);
@@ -2531,7 +2871,7 @@ function localDay(at = Date.now()) {
2531
2871
  function readCatchFacts(stateDir, id) {
2532
2872
  let last;
2533
2873
  try {
2534
- for (const line of fs21.readFileSync(path18.join(stateDir, `${id}.status`), "utf8").split("\n")) {
2874
+ for (const line of fs24.readFileSync(path21.join(stateDir, `${id}.status`), "utf8").split("\n")) {
2535
2875
  if (!line.trim())
2536
2876
  continue;
2537
2877
  try {
@@ -2547,7 +2887,7 @@ function readCatchFacts(stateDir, id) {
2547
2887
  let trap;
2548
2888
  let worker = workerProfile();
2549
2889
  try {
2550
- const evidence = JSON.parse(fs21.readFileSync(path18.join(stateDir, `${id}.evidence`), "utf8"));
2890
+ const evidence = JSON.parse(fs24.readFileSync(path21.join(stateDir, `${id}.evidence`), "utf8"));
2551
2891
  const to = evidence.deliveredTo;
2552
2892
  if (typeof to === "string" && to.startsWith("wt:"))
2553
2893
  trap = to;
@@ -2630,7 +2970,7 @@ function add(store, facts, now2) {
2630
2970
  }
2631
2971
  function backfillSources() {
2632
2972
  const live = ["work", "chore"].map((lane) => ({ dir: laneDirs(lane).state, live: true }));
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());
2973
+ const backups = readDirIfPresent(lobstahHome()).filter((name) => name.startsWith("state-backup-")).sort().map((name) => ({ dir: path21.join(lobstahHome(), name), live: false })).filter((s) => fs24.statSync(s.dir).isDirectory());
2634
2974
  return [...live, ...backups];
2635
2975
  }
2636
2976
  function backfillStats(now2 = Date.now(), alreadyCounted) {
@@ -2702,13 +3042,13 @@ function parseStore(text) {
2702
3042
  var complete2 = (s) => !!s && s.daily !== void 0;
2703
3043
  function writeStore(store) {
2704
3044
  const file2 = statsPath();
2705
- fs21.mkdirSync(path18.dirname(file2), { recursive: true });
3045
+ fs24.mkdirSync(path21.dirname(file2), { recursive: true });
2706
3046
  const tmp = uniqueTempPath(file2);
2707
- fs21.writeFileSync(tmp, JSON.stringify(store));
3047
+ fs24.writeFileSync(tmp, JSON.stringify(store));
2708
3048
  atomicRenameSync(tmp, file2);
2709
3049
  }
2710
3050
  function withStatsLock(action) {
2711
- fs21.mkdirSync(lobstahHome(), { recursive: true });
3051
+ fs24.mkdirSync(lobstahHome(), { recursive: true });
2712
3052
  return withDirLock(`${statsPath()}.lock`, action, {
2713
3053
  staleMs: 12e4,
2714
3054
  waitMs: 1e4,
@@ -2718,7 +3058,7 @@ function withStatsLock(action) {
2718
3058
  function loadOrBackfill(now2) {
2719
3059
  let text;
2720
3060
  try {
2721
- text = fs21.readFileSync(statsPath(), "utf8");
3061
+ text = fs24.readFileSync(statsPath(), "utf8");
2722
3062
  } catch (err) {
2723
3063
  if (err.code !== "ENOENT")
2724
3064
  throw err;
@@ -2745,7 +3085,7 @@ function loadOrBackfill(now2) {
2745
3085
  return store2;
2746
3086
  }
2747
3087
  if (text !== void 0)
2748
- fs21.renameSync(statsPath(), `${statsPath()}.unreadable-${now2}`);
3088
+ fs24.renameSync(statsPath(), `${statsPath()}.unreadable-${now2}`);
2749
3089
  const store = backfillStats(now2);
2750
3090
  writeStore(store);
2751
3091
  return store;
@@ -2832,8 +3172,18 @@ function appendStatus(id, lane, verb, note, at, waiting, reported = false) {
2832
3172
  } catch {
2833
3173
  }
2834
3174
  }
2835
- fs22.appendFileSync(statusPath(id, lane), `${JSON.stringify(entry)}
3175
+ const claim = readSessionClaim(id, lane);
3176
+ const trap = claim?.by.startsWith("wt:") ? readTrap(claim.by.slice(3)) : void 0;
3177
+ const write = () => {
3178
+ fs25.appendFileSync(statusPath(id, lane), `${JSON.stringify(entry)}
2836
3179
  `);
3180
+ };
3181
+ if (trap && repoCachesConfigured(trap.repo))
3182
+ withTrapCacheLock(trap.trapId, write);
3183
+ else
3184
+ write();
3185
+ if (trap && trap.claimed === id && (verb === "done" || verb === "failed"))
3186
+ clearFinishedTrapCaches(trap, verb);
2837
3187
  if (verb === "done") {
2838
3188
  try {
2839
3189
  recordCatch(id, lane);
@@ -2844,9 +3194,9 @@ function appendStatus(id, lane, verb, note, at, waiting, reported = false) {
2844
3194
  }
2845
3195
  function readStatusLog(id, lane) {
2846
3196
  const file2 = statusPath(id, lane);
2847
- if (!fs22.existsSync(file2))
3197
+ if (!fs25.existsSync(file2))
2848
3198
  return [];
2849
- return fs22.readFileSync(file2, "utf8").split("\n").filter(Boolean).flatMap((line) => {
3199
+ return fs25.readFileSync(file2, "utf8").split("\n").filter(Boolean).flatMap((line) => {
2850
3200
  try {
2851
3201
  const parsed = JSON.parse(line);
2852
3202
  return isVerb(parsed.verb) ? [parsed] : [];
@@ -2862,28 +3212,28 @@ function pausedWaiting(entry) {
2862
3212
  // packages/core/dist/queue.js
2863
3213
  function requeue(id, lane) {
2864
3214
  const dirs = laneDirs(lane);
2865
- const activeDir = path19.join(dirs.active, id);
2866
- const file2 = path19.join(activeDir, "descriptor.json");
3215
+ const activeDir = path22.join(dirs.active, id);
3216
+ const file2 = path22.join(activeDir, "descriptor.json");
2867
3217
  const d = { ...readDescriptor(id, lane), queuedAt: (/* @__PURE__ */ new Date()).toISOString() };
2868
3218
  const tmp = uniqueTempPath(file2);
2869
- fs23.writeFileSync(tmp, JSON.stringify(d, null, 2));
3219
+ fs26.writeFileSync(tmp, JSON.stringify(d, null, 2));
2870
3220
  atomicRenameSync(tmp, file2);
2871
- fs23.renameSync(file2, path19.join(dirs.queue, `${id}.json`));
2872
- fs23.rmSync(activeDir, { recursive: true, force: true });
3221
+ fs26.renameSync(file2, path22.join(dirs.queue, `${id}.json`));
3222
+ fs26.rmSync(activeDir, { recursive: true, force: true });
2873
3223
  }
2874
3224
  function readDescriptor(id, lane) {
2875
- const file2 = path19.join(laneDirs(lane).active, id, "descriptor.json");
2876
- return JSON.parse(fs23.readFileSync(file2, "utf8"));
3225
+ const file2 = path22.join(laneDirs(lane).active, id, "descriptor.json");
3226
+ return JSON.parse(fs26.readFileSync(file2, "utf8"));
2877
3227
  }
2878
3228
  function storedDescriptor(id, lane) {
2879
3229
  const dirs = laneDirs(lane);
2880
3230
  for (const file2 of [
2881
- path19.join(dirs.queue, `${id}.json`),
2882
- path19.join(dirs.active, id, "descriptor.json"),
2883
- path19.join(dirs.done, id, "descriptor.json")
3231
+ path22.join(dirs.queue, `${id}.json`),
3232
+ path22.join(dirs.active, id, "descriptor.json"),
3233
+ path22.join(dirs.done, id, "descriptor.json")
2884
3234
  ]) {
2885
3235
  try {
2886
- return JSON.parse(fs23.readFileSync(file2, "utf8"));
3236
+ return JSON.parse(fs26.readFileSync(file2, "utf8"));
2887
3237
  } catch {
2888
3238
  }
2889
3239
  }
@@ -2894,10 +3244,10 @@ function activeIds(lane) {
2894
3244
  }
2895
3245
  function complete(id, lane) {
2896
3246
  const dirs = laneDirs(lane);
2897
- fs23.renameSync(path19.join(dirs.active, id), path19.join(dirs.done, id));
3247
+ fs26.renameSync(path22.join(dirs.active, id), path22.join(dirs.done, id));
2898
3248
  }
2899
3249
  function cancelRequested(id, lane) {
2900
- return fs23.existsSync(path19.join(laneDirs(lane).active, id, "cancel"));
3250
+ return fs26.existsSync(path22.join(laneDirs(lane).active, id, "cancel"));
2901
3251
  }
2902
3252
 
2903
3253
  // packages/core/dist/backend.js
@@ -2946,21 +3296,21 @@ var ANSWER_EXTENSIONS = Object.keys(ANSWER_TYPES);
2946
3296
  var ONCE_TTL_MS = 60 * 60 * 1e3;
2947
3297
 
2948
3298
  // packages/core/dist/harness.js
2949
- import * as fs24 from "node:fs";
2950
- import * as path20 from "node:path";
3299
+ import * as fs27 from "node:fs";
3300
+ import * as path23 from "node:path";
2951
3301
  import { createRequire } from "node:module";
2952
3302
  function resolveOnPath(bin, pathVar = process.env.PATH) {
2953
3303
  if (!pathVar)
2954
3304
  return void 0;
2955
3305
  const names = process.platform === "win32" ? [bin, `${bin}.exe`, `${bin}.cmd`, `${bin}.bat`] : [bin];
2956
- for (const dir of pathVar.split(path20.delimiter)) {
3306
+ for (const dir of pathVar.split(path23.delimiter)) {
2957
3307
  if (!dir)
2958
3308
  continue;
2959
3309
  for (const name of names) {
2960
- const candidate = path20.join(dir, name);
3310
+ const candidate = path23.join(dir, name);
2961
3311
  try {
2962
- fs24.accessSync(candidate, fs24.constants.X_OK);
2963
- if (fs24.statSync(candidate).isFile())
3312
+ fs27.accessSync(candidate, fs27.constants.X_OK);
3313
+ if (fs27.statSync(candidate).isFile())
2964
3314
  return candidate;
2965
3315
  } catch {
2966
3316
  }
@@ -2981,8 +3331,8 @@ function codexInvocation(argv) {
2981
3331
  } catch {
2982
3332
  }
2983
3333
  for (const dir of require_.resolve.paths("@openai/codex") ?? []) {
2984
- const cli = path20.join(dir, "@openai", "codex", "bin", "codex.js");
2985
- if (fs24.existsSync(cli))
3334
+ const cli = path23.join(dir, "@openai", "codex", "bin", "codex.js");
3335
+ if (fs27.existsSync(cli))
2986
3336
  return { file: process.execPath, argv: [cli, ...argv] };
2987
3337
  }
2988
3338
  return void 0;
@@ -3055,9 +3405,9 @@ function droppedModelNote(harness, dropped) {
3055
3405
  }
3056
3406
 
3057
3407
  // packages/runner/src/run.ts
3058
- import * as fs29 from "node:fs";
3059
- import * as path25 from "node:path";
3060
- import { execFileSync as execFileSync2 } from "node:child_process";
3408
+ import * as fs32 from "node:fs";
3409
+ import * as path28 from "node:path";
3410
+ import { execFileSync as execFileSync3 } from "node:child_process";
3061
3411
  import { fileURLToPath as fileURLToPath2 } from "node:url";
3062
3412
 
3063
3413
  // packages/adapters/dist/claude.js
@@ -3090,7 +3440,7 @@ var AsyncQueue = class {
3090
3440
  return Promise.resolve({ value: item, done: false });
3091
3441
  if (this.closed)
3092
3442
  return Promise.resolve({ value: void 0, done: true });
3093
- return new Promise((resolve9) => this.waiters.push(resolve9));
3443
+ return new Promise((resolve10) => this.waiters.push(resolve10));
3094
3444
  }
3095
3445
  };
3096
3446
  }
@@ -3115,7 +3465,7 @@ var InputGate = class {
3115
3465
  return msg;
3116
3466
  if (this.ended)
3117
3467
  return void 0;
3118
- await new Promise((resolve9) => this.waiter = resolve9);
3468
+ await new Promise((resolve10) => this.waiter = resolve10);
3119
3469
  this.waiter = null;
3120
3470
  }
3121
3471
  }
@@ -3260,20 +3610,20 @@ function startClaudeCli(invocation, opts) {
3260
3610
  }
3261
3611
  }
3262
3612
  });
3263
- const done = new Promise((resolve9) => {
3613
+ const done = new Promise((resolve10) => {
3264
3614
  child.on("error", (err) => {
3265
3615
  events.push({ at: now(), type: "error", data: { message: err.message } });
3266
3616
  events.close();
3267
- resolve9({ sessionId, error: err.message });
3617
+ resolve10({ sessionId, error: err.message });
3268
3618
  });
3269
3619
  child.on("exit", (code2) => {
3270
3620
  events.close();
3271
3621
  if (code2 === 0)
3272
- resolve9({ sessionId });
3622
+ resolve10({ sessionId });
3273
3623
  else {
3274
3624
  const detail = stderrTail.trim().split("\n").at(-1);
3275
3625
  const error = `claude exited ${code2}${detail ? ` \u2014 ${detail}` : ""}`;
3276
- resolve9({ sessionId, error });
3626
+ resolve10({ sessionId, error });
3277
3627
  }
3278
3628
  });
3279
3629
  });
@@ -3352,25 +3702,25 @@ function createClaudeAdapter() {
3352
3702
  }
3353
3703
 
3354
3704
  // packages/adapters/dist/codex.js
3355
- import * as fs25 from "node:fs";
3705
+ import * as fs28 from "node:fs";
3356
3706
  import * as os4 from "node:os";
3357
- import * as path21 from "node:path";
3707
+ import * as path24 from "node:path";
3358
3708
  import { spawn as spawn2 } from "node:child_process";
3359
3709
  function isolatedCodexHome() {
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)) {
3710
+ const dir = path24.join(lobstahHome(), "codex-home");
3711
+ fs28.mkdirSync(dir, { recursive: true });
3712
+ const auth = path24.join(dir, "auth.json");
3713
+ const realAuth = path24.join(os4.homedir(), ".codex", "auth.json");
3714
+ if (!fs28.existsSync(auth) && fs28.existsSync(realAuth)) {
3365
3715
  try {
3366
- fs25.symlinkSync(realAuth, auth);
3716
+ fs28.symlinkSync(realAuth, auth);
3367
3717
  } catch {
3368
- fs25.copyFileSync(realAuth, auth);
3718
+ fs28.copyFileSync(realAuth, auth);
3369
3719
  }
3370
3720
  }
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");
3721
+ const cfg = path24.join(dir, "config.toml");
3722
+ if (!fs28.existsSync(cfg)) {
3723
+ fs28.writeFileSync(cfg, "# lobstah-managed: auth inherited from ~/.codex, interactive config not\n");
3374
3724
  }
3375
3725
  return dir;
3376
3726
  }
@@ -3422,7 +3772,7 @@ function startCodexCli(invoke, opts) {
3422
3772
  let current;
3423
3773
  let killed = false;
3424
3774
  function runTurn(prompt, resumeThread) {
3425
- return new Promise((resolve9) => {
3775
+ return new Promise((resolve10) => {
3426
3776
  const inv = invoke(codexExecArgs(opts, prompt, resumeThread));
3427
3777
  const child = spawn2(inv.file, inv.argv, {
3428
3778
  cwd: opts.cwd,
@@ -3453,14 +3803,14 @@ function startCodexCli(invoke, opts) {
3453
3803
  }
3454
3804
  }
3455
3805
  });
3456
- child.on("error", (err) => resolve9(err.message));
3806
+ child.on("error", (err) => resolve10(err.message));
3457
3807
  child.on("exit", (code2) => {
3458
3808
  if (turnError)
3459
- return resolve9(turnError);
3809
+ return resolve10(turnError);
3460
3810
  if (code2 === 0 || killed)
3461
- return resolve9(void 0);
3811
+ return resolve10(void 0);
3462
3812
  const detail = stderrTail.trim().split("\n").at(-1);
3463
- resolve9(`codex exited ${code2}${detail ? ` \u2014 ${detail}` : ""}`);
3813
+ resolve10(`codex exited ${code2}${detail ? ` \u2014 ${detail}` : ""}`);
3464
3814
  });
3465
3815
  });
3466
3816
  }
@@ -3573,15 +3923,15 @@ function loadAdapter(name) {
3573
3923
  }
3574
3924
 
3575
3925
  // packages/worktree/dist/index.js
3576
- import * as fs27 from "node:fs";
3577
- import * as path23 from "node:path";
3926
+ import * as fs30 from "node:fs";
3927
+ import * as path26 from "node:path";
3578
3928
  import { createHash } from "node:crypto";
3579
- import { exec, execFile as execFile2, execFileSync } from "node:child_process";
3929
+ import { exec, execFile as execFile2, execFileSync as execFileSync2 } from "node:child_process";
3580
3930
  import { promisify as promisify2 } from "node:util";
3581
3931
 
3582
3932
  // packages/worktree/dist/pool.js
3583
- import * as fs26 from "node:fs";
3584
- import * as path22 from "node:path";
3933
+ import * as fs29 from "node:fs";
3934
+ import * as path25 from "node:path";
3585
3935
  import { execFile } from "node:child_process";
3586
3936
  import { promisify } from "node:util";
3587
3937
  var run = promisify(execFile);
@@ -3643,17 +3993,17 @@ function takeOut(name, pool, slot, reason, dispatch, notice = true) {
3643
3993
  function trapIn(dir) {
3644
3994
  const real = (p) => {
3645
3995
  try {
3646
- return fs26.realpathSync.native(p);
3996
+ return fs29.realpathSync.native(p);
3647
3997
  } catch {
3648
- return path22.resolve(p);
3998
+ return path25.resolve(p);
3649
3999
  }
3650
4000
  };
3651
4001
  const here = real(dir);
3652
4002
  return listTraps().some((t) => {
3653
4003
  if (typeof t.worktree !== "string")
3654
4004
  return false;
3655
- const rel = path22.relative(here, real(t.worktree));
3656
- return rel === "" || !rel.startsWith("..") && !path22.isAbsolute(rel);
4005
+ const rel = path25.relative(here, real(t.worktree));
4006
+ return rel === "" || !rel.startsWith("..") && !path25.isAbsolute(rel);
3657
4007
  });
3658
4008
  }
3659
4009
  async function claimPoolSlot(input) {
@@ -3661,7 +4011,7 @@ async function claimPoolSlot(input) {
3661
4011
  const refused = [];
3662
4012
  for (let slot = 1; slot <= pool.size; slot++) {
3663
4013
  const dir = poolSlotPath(name, slot);
3664
- if (fs26.existsSync(dir) && readWorktreeLock(dir)?.id === id && readWorktreeLock(dir)?.kind !== "warm") {
4014
+ if (fs29.existsSync(dir) && readWorktreeLock(dir)?.id === id && readWorktreeLock(dir)?.kind !== "warm") {
3665
4015
  writeSlotClaim(name, slot, { id, lane, at: (/* @__PURE__ */ new Date()).toISOString() });
3666
4016
  return { claimed: true, dir, slot, label: poolSlotLabel(name, slot) };
3667
4017
  }
@@ -3709,7 +4059,7 @@ async function resetPoolWorktree(repo, dir, id, fromRemoteBranch = repo.trunk) {
3709
4059
  }
3710
4060
  var WARM_ID = "pool-warm";
3711
4061
  async function createSlot(repo, dir) {
3712
- fs26.mkdirSync(path22.dirname(dir), { recursive: true });
4062
+ fs29.mkdirSync(path25.dirname(dir), { recursive: true });
3713
4063
  await oneAtATime(repo.path, async () => {
3714
4064
  await tryGit(repo.path, "worktree", "prune");
3715
4065
  await gitShared(repo.path, "worktree", "add", "--detach", dir, `origin/${repo.trunk}`);
@@ -3731,7 +4081,7 @@ async function warmPool(name, opts = {}) {
3731
4081
  if (!release)
3732
4082
  return false;
3733
4083
  try {
3734
- if (!fs26.existsSync(repo.path)) {
4084
+ if (!fs29.existsSync(repo.path)) {
3735
4085
  if (!repo.origin)
3736
4086
  throw new Error(`repo path ${repo.path} missing and no origin configured`);
3737
4087
  await run("git", ["clone", repo.origin, repo.path], { env: process.env });
@@ -3744,8 +4094,9 @@ async function warmPool(name, opts = {}) {
3744
4094
  const dir = poolSlotPath(name, slot);
3745
4095
  const label = poolSlotLabel(name, slot);
3746
4096
  const meta = readSlotMeta(name, slot);
3747
- if (!fs26.existsSync(dir)) {
3748
- fs26.mkdirSync(poolsRoot(), { recursive: true });
4097
+ if (!fs29.existsSync(dir)) {
4098
+ fs29.mkdirSync(poolsRoot(), { recursive: true });
4099
+ recoverTrapCaches(cfg, poolsRoot(), read2, log);
3749
4100
  let free = Infinity;
3750
4101
  try {
3751
4102
  free = need > 0 ? read2(poolsRoot()) : Infinity;
@@ -3821,7 +4172,7 @@ async function warmPool(name, opts = {}) {
3821
4172
  // packages/worktree/dist/index.js
3822
4173
  var run2 = promisify2(execFile2);
3823
4174
  var shell = promisify2(exec);
3824
- async function git(cwd, ...args) {
4175
+ async function git2(cwd, ...args) {
3825
4176
  const { stdout } = await run2("git", args, { cwd, env: process.env });
3826
4177
  return stdout.trim();
3827
4178
  }
@@ -3863,7 +4214,7 @@ var ATTEMPTS = 6;
3863
4214
  async function gitShared(cwd, ...args) {
3864
4215
  for (let attempt2 = 1; ; attempt2++) {
3865
4216
  try {
3866
- return await git(cwd, ...args);
4217
+ return await git2(cwd, ...args);
3867
4218
  } catch (err) {
3868
4219
  if (!isLockContention(err))
3869
4220
  throw err;
@@ -3888,7 +4239,7 @@ function pidAlive3(pid) {
3888
4239
  var BUSY = /* @__PURE__ */ new Set(["EPERM", "EACCES", "EBUSY"]);
3889
4240
  function takeRepoLock(file2, mine) {
3890
4241
  try {
3891
- fs27.writeFileSync(file2, mine, { flag: "wx" });
4242
+ fs30.writeFileSync(file2, mine, { flag: "wx" });
3892
4243
  return { state: "held" };
3893
4244
  } catch (err) {
3894
4245
  const code2 = err.code ?? "";
@@ -3898,8 +4249,8 @@ function takeRepoLock(file2, mine) {
3898
4249
  let raw = "";
3899
4250
  let age = 0;
3900
4251
  try {
3901
- raw = fs27.readFileSync(file2, "utf8");
3902
- age = Date.now() - fs27.statSync(file2).mtimeMs;
4252
+ raw = fs30.readFileSync(file2, "utf8");
4253
+ age = Date.now() - fs30.statSync(file2).mtimeMs;
3903
4254
  } catch {
3904
4255
  return { state: "retry" };
3905
4256
  }
@@ -3912,8 +4263,8 @@ function takeRepoLock(file2, mine) {
3912
4263
  const stale = age > REPO_LOCK_WAIT_MS || (holder ? !pidAlive3(holder.pid) : age > 5e3);
3913
4264
  if (stale) {
3914
4265
  try {
3915
- if (fs27.readFileSync(file2, "utf8") === raw)
3916
- fs27.rmSync(file2, { force: true });
4266
+ if (fs30.readFileSync(file2, "utf8") === raw)
4267
+ fs30.rmSync(file2, { force: true });
3917
4268
  } catch {
3918
4269
  }
3919
4270
  return { state: "retry" };
@@ -3922,13 +4273,13 @@ function takeRepoLock(file2, mine) {
3922
4273
  }
3923
4274
  function releaseRepoLock(file2, mine) {
3924
4275
  try {
3925
- if (fs27.readFileSync(file2, "utf8") === mine)
3926
- fs27.rmSync(file2, { force: true, recursive: true, maxRetries: 5 });
4276
+ if (fs30.readFileSync(file2, "utf8") === mine)
4277
+ fs30.rmSync(file2, { force: true, recursive: true, maxRetries: 5 });
3927
4278
  } catch {
3928
4279
  }
3929
4280
  }
3930
4281
  async function withRepoLock(common, fn) {
3931
- const file2 = path23.join(common, "lobstah-git.lock");
4282
+ const file2 = path26.join(common, "lobstah-git.lock");
3932
4283
  const mine = JSON.stringify({ pid: process.pid, at: (/* @__PURE__ */ new Date()).toISOString() });
3933
4284
  const deadline = Date.now() + REPO_LOCK_WAIT_MS;
3934
4285
  let held = false;
@@ -3949,7 +4300,7 @@ async function withRepoLock(common, fn) {
3949
4300
  }
3950
4301
  }
3951
4302
  async function oneAtATime(cwd, fn) {
3952
- const common = await git(cwd, "rev-parse", "--path-format=absolute", "--git-common-dir");
4303
+ const common = await git2(cwd, "rev-parse", "--path-format=absolute", "--git-common-dir");
3953
4304
  const key = realpath(common);
3954
4305
  const run3 = (repoQueues.get(key) ?? Promise.resolve()).then(() => withRepoLock(common, () => fn(common)));
3955
4306
  const tail = run3.catch(() => {
@@ -3964,7 +4315,7 @@ async function oneAtATime(cwd, fn) {
3964
4315
  }
3965
4316
  function fetchStamps(common) {
3966
4317
  try {
3967
- return JSON.parse(fs27.readFileSync(path23.join(common, "lobstah-fetch.json"), "utf8"));
4318
+ return JSON.parse(fs30.readFileSync(path26.join(common, "lobstah-fetch.json"), "utf8"));
3968
4319
  } catch {
3969
4320
  return {};
3970
4321
  }
@@ -3978,15 +4329,15 @@ async function fetchShared(cwd, remote, ref) {
3978
4329
  const started = Date.now();
3979
4330
  await gitShared(cwd, "fetch", remote, ref);
3980
4331
  const stamps = { ...fetchStamps(common), [key]: started };
3981
- fs27.writeFileSync(path23.join(common, "lobstah-fetch.json"), JSON.stringify(stamps, null, 2));
4332
+ fs30.writeFileSync(path26.join(common, "lobstah-fetch.json"), JSON.stringify(stamps, null, 2));
3982
4333
  });
3983
4334
  }
3984
4335
  async function allocate(repo, id, fromRemoteBranch = repo.trunk) {
3985
4336
  const dir = worktreePath(id);
3986
- if (fs27.existsSync(dir)) {
4337
+ if (fs30.existsSync(dir)) {
3987
4338
  throw new Error(`worktree for ${id} already exists at ${dir} \u2014 never allocate a second`);
3988
4339
  }
3989
- if (!fs27.existsSync(repo.path)) {
4340
+ if (!fs30.existsSync(repo.path)) {
3990
4341
  if (!repo.origin)
3991
4342
  throw new Error(`repo path ${repo.path} missing and no origin configured`);
3992
4343
  await run2("git", ["clone", repo.origin, repo.path], { env: process.env });
@@ -4001,11 +4352,11 @@ async function allocate(repo, id, fromRemoteBranch = repo.trunk) {
4001
4352
  async function recoverWorktree(repo, id) {
4002
4353
  const dir = worktreePath(id);
4003
4354
  try {
4004
- if (fs27.statSync(path23.join(dir, ".git")).isFile()) {
4005
- const branch = await git(dir, "symbolic-ref", "--quiet", "HEAD");
4006
- const root = await git(dir, "rev-parse", "--show-toplevel");
4007
- const common = await git(dir, "rev-parse", "--path-format=absolute", "--git-common-dir");
4008
- const mine = await git(repo.path, "rev-parse", "--path-format=absolute", "--git-common-dir");
4355
+ if (fs30.statSync(path26.join(dir, ".git")).isFile()) {
4356
+ const branch = await git2(dir, "symbolic-ref", "--quiet", "HEAD");
4357
+ const root = await git2(dir, "rev-parse", "--show-toplevel");
4358
+ const common = await git2(dir, "rev-parse", "--path-format=absolute", "--git-common-dir");
4359
+ const mine = await git2(repo.path, "rev-parse", "--path-format=absolute", "--git-common-dir");
4009
4360
  if (branch === `refs/heads/lobstah/${id}` && realpath(root) === realpath(dir) && realpath(common) === realpath(mine))
4010
4361
  return dir;
4011
4362
  }
@@ -4039,27 +4390,27 @@ function setupHash(repo, dir) {
4039
4390
  const h = createHash("sha256");
4040
4391
  h.update(JSON.stringify(repo.setup ?? []));
4041
4392
  for (const name of LOCKFILES) {
4042
- const file2 = path23.join(dir, name);
4043
- if (!fs27.existsSync(file2))
4393
+ const file2 = path26.join(dir, name);
4394
+ if (!fs30.existsSync(file2))
4044
4395
  continue;
4045
4396
  h.update(`\0${name}\0`);
4046
- h.update(fs27.readFileSync(file2));
4397
+ h.update(fs30.readFileSync(file2));
4047
4398
  }
4048
4399
  return h.digest("hex");
4049
4400
  }
4050
4401
  function setupRecordFile(dir) {
4051
4402
  const gitDir = worktreeGitDir(dir);
4052
- return gitDir ? path23.join(gitDir, "lobstah-setup.json") : void 0;
4403
+ return gitDir ? path26.join(gitDir, "lobstah-setup.json") : void 0;
4053
4404
  }
4054
4405
  function recordSetup(repo, dir) {
4055
4406
  const file2 = setupRecordFile(dir);
4056
4407
  if (file2)
4057
- fs27.writeFileSync(file2, JSON.stringify({ hash: setupHash(repo, dir), at: (/* @__PURE__ */ new Date()).toISOString() }, null, 2));
4408
+ fs30.writeFileSync(file2, JSON.stringify({ hash: setupHash(repo, dir), at: (/* @__PURE__ */ new Date()).toISOString() }, null, 2));
4058
4409
  }
4059
4410
  function recordedSetupHash(dir) {
4060
4411
  const file2 = setupRecordFile(dir);
4061
4412
  try {
4062
- return file2 ? JSON.parse(fs27.readFileSync(file2, "utf8")).hash : void 0;
4413
+ return file2 ? JSON.parse(fs30.readFileSync(file2, "utf8")).hash : void 0;
4063
4414
  } catch {
4064
4415
  return void 0;
4065
4416
  }
@@ -4072,9 +4423,9 @@ function poolReused(slot, by) {
4072
4423
  function realpath(p) {
4073
4424
  let r;
4074
4425
  try {
4075
- r = fs27.realpathSync.native(p);
4426
+ r = fs30.realpathSync.native(p);
4076
4427
  } catch {
4077
- r = path23.resolve(p);
4428
+ r = path26.resolve(p);
4078
4429
  }
4079
4430
  return process.platform === "win32" ? r.toLowerCase() : r;
4080
4431
  }
@@ -4105,8 +4456,8 @@ async function chooseWorktree(input) {
4105
4456
  return { reuse: false, reason: `origin worktree belongs to repo ${ownerRepo}` };
4106
4457
  }
4107
4458
  try {
4108
- const common = await git(found.path, "rev-parse", "--path-format=absolute", "--git-common-dir");
4109
- const mine = await git(repo.path, "rev-parse", "--path-format=absolute", "--git-common-dir");
4459
+ const common = await git2(found.path, "rev-parse", "--path-format=absolute", "--git-common-dir");
4460
+ const mine = await git2(repo.path, "rev-parse", "--path-format=absolute", "--git-common-dir");
4110
4461
  if (realpath(common) !== realpath(mine))
4111
4462
  return { reuse: false, reason: "origin worktree belongs to another repo" };
4112
4463
  } catch {
@@ -4122,8 +4473,8 @@ async function chooseWorktree(input) {
4122
4473
  for (const t of listTraps()) {
4123
4474
  if (typeof t.worktree !== "string")
4124
4475
  continue;
4125
- const rel = path23.relative(here, realpath(t.worktree));
4126
- if (!rel.startsWith("..") && !path23.isAbsolute(rel))
4476
+ const rel = path26.relative(here, realpath(t.worktree));
4477
+ if (!rel.startsWith("..") && !path26.isAbsolute(rel))
4127
4478
  return { reuse: false, reason: "origin worktree is a trap\u2019s" };
4128
4479
  }
4129
4480
  for (const l of ["work", "chore"]) {
@@ -4140,7 +4491,7 @@ async function chooseWorktree(input) {
4140
4491
  return { reuse: false, reason: `origin worktree is in use by ${short(holder.id)}` };
4141
4492
  let porcelain;
4142
4493
  try {
4143
- porcelain = await git(found.path, "status", "--porcelain");
4494
+ porcelain = await git2(found.path, "status", "--porcelain");
4144
4495
  } catch {
4145
4496
  return { reuse: false, reason: "origin worktree is not a readable git checkout" };
4146
4497
  }
@@ -4170,8 +4521,8 @@ async function prepareReuse(repo, dir) {
4170
4521
  return { setupRan: true };
4171
4522
  }
4172
4523
  async function collectEvidence(repo, dir) {
4173
- const branch = await git(dir, "rev-parse", "--abbrev-ref", "HEAD");
4174
- const log = await git(dir, "log", "--oneline", `origin/${repo.trunk}..HEAD`);
4524
+ const branch = await git2(dir, "rev-parse", "--abbrev-ref", "HEAD");
4525
+ const log = await git2(dir, "log", "--oneline", `origin/${repo.trunk}..HEAD`);
4175
4526
  return { branch, commits: log ? log.split("\n") : [] };
4176
4527
  }
4177
4528
  async function tryGit(cwd, ...args) {
@@ -4221,7 +4572,7 @@ async function* until(source, stop) {
4221
4572
  yield next.value;
4222
4573
  }
4223
4574
  }
4224
- var sleep = (ms) => new Promise((resolve9) => setTimeout(resolve9, ms));
4575
+ var sleep = (ms) => new Promise((resolve10) => setTimeout(resolve10, ms));
4225
4576
  function deliver(run3, id, lane) {
4226
4577
  const msgs = unhandled(id, lane);
4227
4578
  for (const m of msgs) {
@@ -4267,7 +4618,7 @@ async function drive(run3, opts) {
4267
4618
  let finalAt = 0;
4268
4619
  let exit;
4269
4620
  let abandon;
4270
- const abandoned = new Promise((resolve9) => abandon = resolve9);
4621
+ const abandoned = new Promise((resolve10) => abandon = resolve10);
4271
4622
  const clearExit = () => {
4272
4623
  if (!exit) return;
4273
4624
  clearInterval(exit.poll);
@@ -4551,8 +4902,8 @@ function startWallClock(opts) {
4551
4902
  import { execFile as execFile3 } from "node:child_process";
4552
4903
  import { promisify as promisify3 } from "node:util";
4553
4904
  import { fileURLToPath } from "node:url";
4554
- import * as fs28 from "node:fs";
4555
- import * as path24 from "node:path";
4905
+ import * as fs31 from "node:fs";
4906
+ import * as path27 from "node:path";
4556
4907
  var exec2 = promisify3(execFile3);
4557
4908
  function firstLine(err) {
4558
4909
  const stderr = err && typeof err === "object" && "stderr" in err ? String(err.stderr).trim() : "";
@@ -4578,14 +4929,14 @@ function keepRemote(opts) {
4578
4929
  shell: process.platform === "win32" && /\.(?:cmd|bat)$/i.test(file2)
4579
4930
  })).stdout.trim();
4580
4931
  };
4581
- const git2 = (...args) => command("git", args);
4932
+ const git3 = (...args) => command("git", args);
4582
4933
  const note = (message) => mergeEvidence(id, lane, { note: message.slice(0, 300) });
4583
4934
  if (existingPrUrl) mergeEvidence(id, lane, { prUrl: existingPrUrl });
4584
4935
  const registerWatch = async (url) => {
4585
- const root = path24.resolve(path24.dirname(fileURLToPath(import.meta.url)), "..", "..", "..");
4586
- const localCli = path24.join(root, "apps", "cli", "dist", "main.js");
4936
+ const root = path27.resolve(path27.dirname(fileURLToPath(import.meta.url)), "..", "..", "..");
4937
+ const localCli = path27.join(root, "apps", "cli", "dist", "main.js");
4587
4938
  const args = ["watch", "add", url, "--for", id];
4588
- if (fs28.existsSync(localCli)) await command(process.execPath, [localCli, ...args], 15e3);
4939
+ if (fs31.existsSync(localCli)) await command(process.execPath, [localCli, ...args], 15e3);
4589
4940
  else await command("lobstah", args, 15e3);
4590
4941
  };
4591
4942
  let lastSeenHead;
@@ -4602,7 +4953,7 @@ function keepRemote(opts) {
4602
4953
  await registerWatch(existingWatch.url).catch((err) => note(`PR watch unavailable: ${firstLine(err)}`));
4603
4954
  })() : void 0;
4604
4955
  const branchName = async () => {
4605
- const branch = await git2("symbolic-ref", "--quiet", "--short", "HEAD").catch(() => "");
4956
+ const branch = await git3("symbolic-ref", "--quiet", "--short", "HEAD").catch(() => "");
4606
4957
  if (!branch || branch === trunk || branch === `origin/${trunk}`) return void 0;
4607
4958
  return branch;
4608
4959
  };
@@ -4646,14 +4997,14 @@ function keepRemote(opts) {
4646
4997
  if (!policy.pushEarly || trapClaimed() || existingPrUrl) return;
4647
4998
  const branch = await branchName();
4648
4999
  if (!branch) return;
4649
- const head = await git2("rev-parse", "HEAD");
4650
- const ahead = await git2("rev-list", "--count", `origin/${trunk}..HEAD`).catch(() => "1");
5000
+ const head = await git3("rev-parse", "HEAD");
5001
+ const ahead = await git3("rev-list", "--count", `origin/${trunk}..HEAD`).catch(() => "1");
4651
5002
  if (ahead === "0") return;
4652
5003
  if (head === lastSeenHead) return;
4653
5004
  lastSeenHead = head;
4654
5005
  if (head === pushedHead) return;
4655
5006
  try {
4656
- await git2("push", "-u", "origin", branch);
5007
+ await git3("push", "-u", "origin", branch);
4657
5008
  pushedHead = head;
4658
5009
  pushProblem = void 0;
4659
5010
  mergeEvidence(id, lane, { branch });
@@ -4699,12 +5050,12 @@ function keepRemote(opts) {
4699
5050
  let saved = "no working-tree changes";
4700
5051
  if (policy.checkpointOnStop) {
4701
5052
  try {
4702
- const paths = (await git2("ls-files", "-m", "-o", "-d", "--exclude-standard", "-z")).split("\0").filter(Boolean).filter(checkpointAllowed);
5053
+ const paths = (await git3("ls-files", "-m", "-o", "-d", "--exclude-standard", "-z")).split("\0").filter(Boolean).filter(checkpointAllowed);
4703
5054
  if (paths.length) {
4704
- await git2("add", "-A", "--", ...paths);
4705
- const staged = await git2("diff", "--cached", "--name-only", "--", ...paths);
5055
+ await git3("add", "-A", "--", ...paths);
5056
+ const staged = await git3("diff", "--cached", "--name-only", "--", ...paths);
4706
5057
  if (staged) {
4707
- await git2("commit", "--only", "-m", "Checkpoint before runner stop", "--", ...paths);
5058
+ await git3("commit", "--only", "-m", "Checkpoint before runner stop", "--", ...paths);
4708
5059
  saved = `checkpoint committed (${staged.split("\n").length} files)`;
4709
5060
  }
4710
5061
  }
@@ -4715,7 +5066,7 @@ function keepRemote(opts) {
4715
5066
  await check().catch((err) => note(`final push unavailable: ${firstLine(err)}`));
4716
5067
  await opening;
4717
5068
  await watching;
4718
- const head = await git2("rev-parse", "--short", "HEAD").catch(() => "unknown");
5069
+ const head = await git3("rev-parse", "--short", "HEAD").catch(() => "unknown");
4719
5070
  const pr = readEvidence(id, lane).prUrl;
4720
5071
  const message = `${saved}; ${branch}@${head}${pr ? `; ${existingPrUrl ? "existing" : "draft"} PR ${pr}` : ""}${pushProblem ? `; ${pushProblem}` : ""}${draftProblem ? `; ${draftProblem}` : ""}`;
4721
5072
  note(message);
@@ -4748,7 +5099,7 @@ var defaultDeps = {
4748
5099
  var DONE_WAIT_MS = 2e3;
4749
5100
  function within(p, ms, fallback) {
4750
5101
  let timer;
4751
- const late = new Promise((resolve9) => timer = setTimeout(() => resolve9(fallback), ms));
5102
+ const late = new Promise((resolve10) => timer = setTimeout(() => resolve10(fallback), ms));
4752
5103
  return Promise.race([p, late]).finally(() => clearTimeout(timer));
4753
5104
  }
4754
5105
  var short3 = (s) => s.slice(0, 8);
@@ -4777,16 +5128,16 @@ function coldNote(cold, cwd, trunk) {
4777
5128
  }
4778
5129
  async function main(activeDir, lane, seams = {}) {
4779
5130
  const deps = { ...defaultDeps, ...seams };
4780
- const id = path25.basename(activeDir);
5131
+ const id = path28.basename(activeDir);
4781
5132
  if (isTrapCatch(id, lane)) throw new Error(`refusing headless runner for trap catch ${id}`);
4782
5133
  const status = (verb, note) => appendStatus(id, lane, verb, note);
4783
5134
  const cfg = loadConfig();
4784
- const descriptor = JSON.parse(fs29.readFileSync(path25.join(activeDir, "descriptor.json"), "utf8"));
5135
+ const descriptor = JSON.parse(fs32.readFileSync(path28.join(activeDir, "descriptor.json"), "utf8"));
4785
5136
  const resolved = resolveDispatch(descriptor, cfg);
4786
5137
  const repo = cfg.repos[descriptor.repo];
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");
5138
+ const briefFile = path28.join(activeDir, "brief.md");
5139
+ if (!fs32.existsSync(briefFile)) fs32.writeFileSync(briefFile, descriptor.brief);
5140
+ const brief = fs32.readFileSync(briefFile, "utf8");
4790
5141
  const attempts = Number(process.env.LOBSTAH_ATTEMPTS ?? "1");
4791
5142
  const wake = process.env.LOBSTAH_WAKE;
4792
5143
  const runnerInfo = {
@@ -4794,7 +5145,7 @@ async function main(activeDir, lane, seams = {}) {
4794
5145
  startedAt: (/* @__PURE__ */ new Date()).toISOString(),
4795
5146
  attempts
4796
5147
  };
4797
- fs29.writeFileSync(path25.join(activeDir, "runner.json"), JSON.stringify(runnerInfo, null, 2));
5148
+ fs32.writeFileSync(path28.join(activeDir, "runner.json"), JSON.stringify(runnerInfo, null, 2));
4798
5149
  if (descriptor.systemRepair && descriptor.pr?.url) {
4799
5150
  const state = deps.prState(descriptor.pr.url) ?? readPr(parsePrRef(descriptor.pr.url)?.key ?? "")?.state;
4800
5151
  if (state === "MERGED" || state === "CLOSED") {
@@ -4811,14 +5162,14 @@ async function main(activeDir, lane, seams = {}) {
4811
5162
  resolvedHarness: resolved.harness,
4812
5163
  envResume: process.env.LOBSTAH_RESUME
4813
5164
  });
4814
- const wtFile = path25.join(activeDir, "worktree.json");
5165
+ const wtFile = path28.join(activeDir, "worktree.json");
4815
5166
  let recorded;
4816
5167
  let recovered = false;
4817
5168
  let choice3;
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))) {
5169
+ if (fs32.existsSync(wtFile)) {
5170
+ recorded = JSON.parse(fs32.readFileSync(wtFile, "utf8")).path;
5171
+ if (!fs32.existsSync(recorded)) throw new Error(`recorded worktree ${recorded} is gone`);
5172
+ } else if (fs32.existsSync(worktreePath(id))) {
4822
5173
  recorded = await recoverWorktree(repo, id);
4823
5174
  recovered = true;
4824
5175
  } else if (descriptor.followUp && cfg.limits.reuseWorktree !== false) {
@@ -4873,7 +5224,7 @@ async function main(activeDir, lane, seams = {}) {
4873
5224
  if (held) throw new Error(`worktree at ${cwd} is in use by ${held.id} \u2014 wait for that dispatch to release it before retrying`);
4874
5225
  if (recovered) {
4875
5226
  await deps.prepareReuse(repo, cwd);
4876
- fs29.writeFileSync(wtFile, JSON.stringify({ path: cwd }, null, 2));
5227
+ fs32.writeFileSync(wtFile, JSON.stringify({ path: cwd }, null, 2));
4877
5228
  }
4878
5229
  } else if (choice3?.reuse) {
4879
5230
  cwd = choice3.path;
@@ -4884,17 +5235,17 @@ async function main(activeDir, lane, seams = {}) {
4884
5235
  type: "runner",
4885
5236
  data: { worktree: cwd, worktreeOf: choice3.owner, setupRan }
4886
5237
  });
4887
- fs29.writeFileSync(wtFile, JSON.stringify({ path: cwd, of: choice3.owner }, null, 2));
5238
+ fs32.writeFileSync(wtFile, JSON.stringify({ path: cwd, of: choice3.owner }, null, 2));
4888
5239
  } else if (poolClaim) {
4889
5240
  cwd = poolClaim.dir;
4890
5241
  await deps.resetPool(repo, cwd, id, descriptor.systemRepair ? descriptor.pr?.headRefName : void 0);
4891
- fs29.writeFileSync(wtFile, JSON.stringify({ path: cwd, pool: poolClaim.label }, null, 2));
5242
+ fs32.writeFileSync(wtFile, JSON.stringify({ path: cwd, pool: poolClaim.label }, null, 2));
4892
5243
  } else {
4893
5244
  cwd = await deps.allocate(repo, id, descriptor.systemRepair ? descriptor.pr?.headRefName : void 0);
4894
5245
  acquireWorktreeLock(cwd, id, lane);
4895
- fs29.writeFileSync(wtFile, JSON.stringify({ path: cwd }, null, 2));
5246
+ fs32.writeFileSync(wtFile, JSON.stringify({ path: cwd }, null, 2));
4896
5247
  }
4897
- const worktreeOf = JSON.parse(fs29.readFileSync(wtFile, "utf8")).of;
5248
+ const worktreeOf = JSON.parse(fs32.readFileSync(wtFile, "utf8")).of;
4898
5249
  const inPool = poolSlotOf(cwd);
4899
5250
  mergeEvidence(id, lane, { worktree: cwd, worktreeOf, ...inPool ? { pool: poolSlotLabel(inPool.pool, inPool.slot) } : {} });
4900
5251
  const existingPr = boundPr(descriptor, lane);
@@ -4922,21 +5273,21 @@ async function main(activeDir, lane, seams = {}) {
4922
5273
  const envNudge = [process.env.LOBSTAH_NUDGE, wakeNote()].filter(Boolean).join("\n\n") || void 0;
4923
5274
  const planNudge = plan.cold && !envNudge ? coldNote(plan.cold, cwd, repo.trunk) : void 0;
4924
5275
  const promptWith = (nudge) => buildPrompt(brief, { id, nudge, attachments: descriptor.attachments, existingPr });
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;
5276
+ const binDir = path28.resolve(path28.dirname(fileURLToPath2(import.meta.url)), "..", "..", "..", "bin");
5277
+ const workerPath = fs32.existsSync(path28.join(binDir, "lobstah")) ? `${binDir}${path28.delimiter}${process.env.PATH ?? ""}` : void 0;
4927
5278
  let wallClockHit = false;
4928
5279
  let current;
4929
- const wallFile = path25.join(activeDir, "wallclock.json");
5280
+ const wallFile = path28.join(activeDir, "wallclock.json");
4930
5281
  const wallState = (() => {
4931
5282
  try {
4932
- return JSON.parse(fs29.readFileSync(wallFile, "utf8"));
5283
+ return JSON.parse(fs32.readFileSync(wallFile, "utf8"));
4933
5284
  } catch {
4934
5285
  return { elapsedMs: 0, windowMs: resolved.limits.wallClockSecs * 1e3 };
4935
5286
  }
4936
5287
  })();
4937
5288
  const head = () => {
4938
5289
  try {
4939
- return execFileSync2("git", ["rev-parse", "HEAD"], { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
5290
+ return execFileSync3("git", ["rev-parse", "HEAD"], { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
4940
5291
  } catch {
4941
5292
  return void 0;
4942
5293
  }
@@ -4948,8 +5299,8 @@ async function main(activeDir, lane, seams = {}) {
4948
5299
  ) * 1e3;
4949
5300
  const persistWall = (elapsedMs, windowMs) => {
4950
5301
  const tmp = uniqueTempPath(wallFile);
4951
- fs29.writeFileSync(tmp, JSON.stringify({ ...wallState, elapsedMs, windowMs }));
4952
- fs29.renameSync(tmp, wallFile);
5302
+ fs32.writeFileSync(tmp, JSON.stringify({ ...wallState, elapsedMs, windowMs }));
5303
+ fs32.renameSync(tmp, wallFile);
4953
5304
  };
4954
5305
  const madeProgress = () => {
4955
5306
  const activity = readActivity(id, lane);
@@ -5115,7 +5466,7 @@ async function main(activeDir, lane, seams = {}) {
5115
5466
  }
5116
5467
 
5117
5468
  // packages/runner/src/reap.ts
5118
- import { execFileSync as execFileSync3 } from "node:child_process";
5469
+ import { execFileSync as execFileSync4 } from "node:child_process";
5119
5470
 
5120
5471
  // packages/runner/src/windows-processes.ts
5121
5472
  var WINDOWS_PROCESS_SNAPSHOT = String.raw`
@@ -5165,7 +5516,7 @@ public static class LobstahProcessSnapshot {
5165
5516
  // packages/runner/src/reap.ts
5166
5517
  function listProcesses() {
5167
5518
  if (process.platform === "win32") {
5168
- const out2 = execFileSync3(
5519
+ const out2 = execFileSync4(
5169
5520
  "powershell.exe",
5170
5521
  [
5171
5522
  "-NoProfile",
@@ -5177,7 +5528,7 @@ function listProcesses() {
5177
5528
  );
5178
5529
  return out2.split(/\r?\n/).map((l) => l.trim().split(/\s+/).map(Number)).filter(([pid, ppid]) => Number.isInteger(pid) && Number.isInteger(ppid)).map(([pid, ppid]) => ({ pid, ppid }));
5179
5530
  }
5180
- const out = execFileSync3("ps", ["-A", "-o", "pid=,ppid=,pgid="], {
5531
+ const out = execFileSync4("ps", ["-A", "-o", "pid=,ppid=,pgid="], {
5181
5532
  encoding: "utf8",
5182
5533
  timeout: 3e4,
5183
5534
  stdio: ["ignore", "pipe", "ignore"]
@@ -5220,7 +5571,7 @@ async function stopPids(pids, graceMs = 2e3) {
5220
5571
  if (process.platform === "win32") {
5221
5572
  for (const pid of pids) {
5222
5573
  try {
5223
- execFileSync3("taskkill", ["/pid", String(pid), "/T", "/F"], { stdio: "ignore", windowsHide: true, timeout: 3e4 });
5574
+ execFileSync4("taskkill", ["/pid", String(pid), "/T", "/F"], { stdio: "ignore", windowsHide: true, timeout: 3e4 });
5224
5575
  } catch {
5225
5576
  }
5226
5577
  }
@@ -5253,13 +5604,13 @@ async function reapStarted(root = process.pid, graceMs) {
5253
5604
  var EXIT_LINGER_MS = 5e3;
5254
5605
  function runRunner(activeDirArg2, laneArg2) {
5255
5606
  const lane = laneArg2 === "chore" ? "chore" : "work";
5256
- const id = path26.basename(activeDirArg2);
5607
+ const id = path29.basename(activeDirArg2);
5257
5608
  main(activeDirArg2, lane, { reap: () => reapStarted(process.pid) }).catch((err) => {
5258
5609
  try {
5259
5610
  if (!isFinished(id, lane)) {
5260
5611
  appendStatus(id, lane, "failed", String(err instanceof Error ? err.message : err).slice(0, 500));
5261
5612
  }
5262
- fs30.renameSync(activeDirArg2, path26.join(laneDirs(lane).done, id));
5613
+ fs33.renameSync(activeDirArg2, path29.join(laneDirs(lane).done, id));
5263
5614
  } catch {
5264
5615
  }
5265
5616
  process.exitCode = 1;