lobstah 0.7.3 → 0.7.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/runner.js CHANGED
@@ -9,13 +9,29 @@ 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/stats.js
12
- import * as fs17 from "node:fs";
12
+ import * as fs18 from "node:fs";
13
13
  import * as path14 from "node:path";
14
14
 
15
15
  // packages/core/dist/paths.js
16
16
  import * as os from "node:os";
17
17
  import * as path from "node:path";
18
- import * as fs from "node:fs";
18
+ import fs from "node:fs";
19
+ import { randomUUID } from "node:crypto";
20
+ function uniqueTempPath(file2) {
21
+ return `${file2}.tmp-${process.pid}-${randomUUID()}`;
22
+ }
23
+ function atomicRenameSync(source, target, deadline = Date.now() + 1e4) {
24
+ for (; ; ) {
25
+ try {
26
+ fs.renameSync(source, target);
27
+ return;
28
+ } catch (err) {
29
+ if (!["EPERM", "EBUSY", "EACCES"].includes(err.code ?? "") || Date.now() >= deadline)
30
+ throw err;
31
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 10);
32
+ }
33
+ }
34
+ }
19
35
  function readDirIfPresent(dir) {
20
36
  try {
21
37
  return fs.readdirSync(dir);
@@ -149,7 +165,7 @@ function sanitizeWorker(value) {
149
165
  }
150
166
 
151
167
  // packages/core/dist/soak.js
152
- import * as fs16 from "node:fs";
168
+ import * as fs17 from "node:fs";
153
169
  import * as path13 from "node:path";
154
170
 
155
171
  // packages/core/dist/queue.js
@@ -283,9 +299,9 @@ function activityFromEvent(ev, root) {
283
299
  }
284
300
  }
285
301
  function atomicWrite(file2, content) {
286
- const tmp = `${file2}.tmp-${process.pid}`;
302
+ const tmp = uniqueTempPath(file2);
287
303
  fs2.writeFileSync(tmp, content);
288
- fs2.renameSync(tmp, file2);
304
+ atomicRenameSync(tmp, file2);
289
305
  }
290
306
  function writeActivity(id, lane, a) {
291
307
  const safe = { at: a.at, kind: a.kind, summary: redactSummary(a.summary) };
@@ -456,9 +472,18 @@ function pausedWaiting(entry) {
456
472
  function requeue(id, lane) {
457
473
  const dirs = laneDirs(lane);
458
474
  const activeDir = path3.join(dirs.active, id);
459
- fs4.renameSync(path3.join(activeDir, "descriptor.json"), path3.join(dirs.queue, `${id}.json`));
475
+ const file2 = path3.join(activeDir, "descriptor.json");
476
+ const d = { ...readDescriptor(id, lane), queuedAt: (/* @__PURE__ */ new Date()).toISOString() };
477
+ const tmp = uniqueTempPath(file2);
478
+ fs4.writeFileSync(tmp, JSON.stringify(d, null, 2));
479
+ atomicRenameSync(tmp, file2);
480
+ fs4.renameSync(file2, path3.join(dirs.queue, `${id}.json`));
460
481
  fs4.rmSync(activeDir, { recursive: true, force: true });
461
482
  }
483
+ function readDescriptor(id, lane) {
484
+ const file2 = path3.join(laneDirs(lane).active, id, "descriptor.json");
485
+ return JSON.parse(fs4.readFileSync(file2, "utf8"));
486
+ }
462
487
  function storedDescriptor(id, lane) {
463
488
  const dirs = laneDirs(lane);
464
489
  for (const file2 of [
@@ -495,9 +520,9 @@ function readEvidence(id, lane) {
495
520
  }
496
521
  function mergeEvidence(id, lane, patch) {
497
522
  const file2 = evidencePath(id, lane);
498
- const tmp = `${file2}.tmp-${process.pid}`;
523
+ const tmp = uniqueTempPath(file2);
499
524
  fs5.writeFileSync(tmp, JSON.stringify({ ...readEvidence(id, lane), ...patch }, null, 2));
500
- fs5.renameSync(tmp, file2);
525
+ atomicRenameSync(tmp, file2);
501
526
  }
502
527
 
503
528
  // packages/core/dist/pushes.js
@@ -598,8 +623,8 @@ function recordPush(id, lane, branches, at = (/* @__PURE__ */ new Date()).toISOS
598
623
  }
599
624
 
600
625
  // packages/core/dist/notices.js
601
- import fs12 from "node:fs";
602
- import * as path10 from "node:path";
626
+ import fs16 from "node:fs";
627
+ import * as path12 from "node:path";
603
628
 
604
629
  // packages/core/dist/config.js
605
630
  import * as fs7 from "node:fs";
@@ -1251,6 +1276,30 @@ function parse(toml, { maxDepth = 1e3, integersAsBigInt } = {}) {
1251
1276
  return res;
1252
1277
  }
1253
1278
 
1279
+ // packages/core/dist/pr-review.js
1280
+ var REVIEW_PRESETS = {
1281
+ github: "https://github.com/{owner}/{repo}/pull/{number}",
1282
+ graphite: "https://app.graphite.com/github/pr/{owner}/{repo}/{number}",
1283
+ linear: "https://linear.review/{owner}/{repo}/pull/{number}",
1284
+ "linear-app": "linear://review/{owner}/{repo}/pull/{number}"
1285
+ };
1286
+ function validReviewTool(value) {
1287
+ if (typeof value !== "string")
1288
+ return false;
1289
+ if (Object.hasOwn(REVIEW_PRESETS, value))
1290
+ return true;
1291
+ if (value.length > 2048 || !["owner", "repo", "number"].every((key) => value.includes(`{${key}}`)))
1292
+ return false;
1293
+ if (/\{(?!owner\}|repo\}|number\})|[\s<>]/.test(value))
1294
+ return false;
1295
+ try {
1296
+ const url = new URL(value.replaceAll("{owner}", "owner").replaceAll("{repo}", "repo").replaceAll("{number}", "1"));
1297
+ return url.protocol === "https:" && !url.username && !url.password;
1298
+ } catch {
1299
+ return false;
1300
+ }
1301
+ }
1302
+
1254
1303
  // packages/core/dist/config.js
1255
1304
  var POOL_NAME = /^[A-Za-z0-9_-]+$/;
1256
1305
  function parsePools(raw, repos) {
@@ -1319,6 +1368,9 @@ var DEFAULT_SOAK = {
1319
1368
  signOffGraceSecs: 600
1320
1369
  };
1321
1370
  var DEFAULT_HELM = {
1371
+ queuedNoticeSecs: 180,
1372
+ stalledNoticeSecs: 1200,
1373
+ idleWorkingNoticeSecs: 60,
1322
1374
  ttlSecs: 1800,
1323
1375
  reportSecs: 900,
1324
1376
  armGraceSecs: 5
@@ -1352,7 +1404,16 @@ function expandHome(p) {
1352
1404
  function loadConfig() {
1353
1405
  const file2 = configPath();
1354
1406
  const raw = fs7.existsSync(file2) ? parse(fs7.readFileSync(file2, "utf8")) : {};
1407
+ const petOpen = raw.pet?.open ?? "tab";
1408
+ if (!["tab", "app", "helm"].includes(petOpen))
1409
+ throw new Error(`[pet].open must be "tab", "app", or "helm" in ${configPath()}`);
1355
1410
  const watch = { ...DEFAULT_WATCH, ...raw.watch ?? {} };
1411
+ const helm = { ...DEFAULT_HELM, ...raw.helm ?? {} };
1412
+ for (const key of ["queuedNoticeSecs", "stalledNoticeSecs", "idleWorkingNoticeSecs"]) {
1413
+ if (typeof helm[key] !== "number" || !Number.isFinite(helm[key]) || helm[key] < 0) {
1414
+ throw new Error(`[helm].${key} must be a non-negative number in ${configPath()}`);
1415
+ }
1416
+ }
1356
1417
  if (typeof watch.repairCooldownSecs !== "number" || !Number.isFinite(watch.repairCooldownSecs) || watch.repairCooldownSecs < 0) {
1357
1418
  throw new Error(`[watch].repairCooldownSecs must be a non-negative number in ${configPath()}`);
1358
1419
  }
@@ -1363,8 +1424,11 @@ function loadConfig() {
1363
1424
  const reposRaw = raw.repos ?? {};
1364
1425
  const repos = {};
1365
1426
  for (const [key, r] of Object.entries(reposRaw)) {
1427
+ if (r.review !== void 0 && !validReviewTool(r.review))
1428
+ throw new Error(`[repos.${key}].review must be github, graphite, linear, linear-app, or an HTTPS template with {owner}, {repo}, {number}`);
1366
1429
  repos[key] = {
1367
1430
  path: expandHome(String(r.path ?? "")),
1431
+ ...r.review !== void 0 ? { review: r.review } : {},
1368
1432
  origin: r.origin ? String(r.origin) : void 0,
1369
1433
  trunk: String(r.trunk ?? "main"),
1370
1434
  setup: Array.isArray(r.setup) ? r.setup.map(String) : void 0,
@@ -1390,8 +1454,9 @@ function loadConfig() {
1390
1454
  harness: raw.harness ?? {},
1391
1455
  limits: { ...DEFAULT_LIMITS, ...raw.limits ?? {} },
1392
1456
  soak: parseSoak(raw.soak),
1393
- helm: { ...DEFAULT_HELM, ...raw.helm ?? {} },
1457
+ helm,
1394
1458
  glass: { ...DEFAULT_GLASS, ...raw.glass ?? {} },
1459
+ pet: { open: petOpen },
1395
1460
  watch,
1396
1461
  grounds,
1397
1462
  pools: parsePools(raw.pools, repos),
@@ -1484,7 +1549,7 @@ function readPrs() {
1484
1549
  }
1485
1550
 
1486
1551
  // packages/core/dist/watch.js
1487
- import * as fs10 from "node:fs";
1552
+ import fs10 from "node:fs";
1488
1553
  import * as path8 from "node:path";
1489
1554
 
1490
1555
  // packages/core/dist/github-budget.js
@@ -1547,7 +1612,7 @@ function cachedPrView(ref) {
1547
1612
  const cached = cycle.snapshots[ref.key];
1548
1613
  if (cached?.error)
1549
1614
  throw new Error(cached.error);
1550
- return cached?.view;
1615
+ return cached ? { ...cached.view, fetchedAt: new Date(cached.at).toISOString() } : void 0;
1551
1616
  }
1552
1617
 
1553
1618
  // packages/core/dist/pr.js
@@ -1600,6 +1665,7 @@ function ghPrViewDirect(ref) {
1600
1665
  if (threads !== void 0)
1601
1666
  view.unresolvedThreads = threads;
1602
1667
  }
1668
+ view.fetchedAt = (/* @__PURE__ */ new Date()).toISOString();
1603
1669
  return view;
1604
1670
  }
1605
1671
  var THREADS_QUERY = "query($owner:String!,$repo:String!,$n:Int!){repository(owner:$owner,name:$repo){pullRequest(number:$n){reviewThreads(first:100){nodes{isResolved}}}}}";
@@ -1618,71 +1684,24 @@ function parseUnresolvedThreads(stdout) {
1618
1684
  }
1619
1685
  }
1620
1686
 
1621
- // packages/core/dist/notices.js
1622
- function noticesDir() {
1623
- return path10.join(lobstahHome(), "notices");
1624
- }
1625
- var counter = 0;
1626
- function postNotice(n) {
1627
- const dir = noticesDir();
1628
- fs12.mkdirSync(dir, { recursive: true });
1629
- if (n.dedupeKey) {
1630
- const marker = path10.join(dir, `.dedupe-${n.dedupeKey.replace(/[^A-Za-z0-9_-]/g, "_")}`);
1631
- try {
1632
- fs12.writeFileSync(marker, "", { flag: "wx" });
1633
- } catch {
1634
- return void 0;
1635
- }
1636
- }
1637
- const seq = `${String(Date.now()).padStart(15, "0")}-${process.pid}-${String(counter++).padStart(8, "0")}`;
1638
- const notice = {
1639
- seq,
1640
- kind: n.kind,
1641
- at: (/* @__PURE__ */ new Date()).toISOString(),
1642
- text: n.text,
1643
- refId: n.refId,
1644
- ...n.url ? { url: n.url } : {},
1645
- repo: n.repo,
1646
- by: n.by,
1647
- ...n.quiet ? { quiet: true } : {},
1648
- ...n.stateHash ? { stateHash: n.stateHash } : {}
1649
- };
1650
- const file2 = path10.join(dir, `${seq}.json`);
1651
- const tmp = `${file2}.tmp`;
1652
- fs12.writeFileSync(tmp, JSON.stringify(notice, null, 2));
1653
- fs12.renameSync(tmp, file2);
1654
- return notice;
1655
- }
1656
-
1657
- // packages/core/dist/attachments.js
1658
- function attachmentBlock(attachments) {
1659
- if (attachments.length === 0)
1660
- return "";
1661
- return [
1662
- "--- ATTACHMENTS ---",
1663
- ...attachments.map((a) => `${a.name} (${a.type}, ${a.bytes} bytes) at ${a.path}`),
1664
- "Images and PDFs can be read directly with your file tools."
1665
- ].join("\n");
1666
- }
1667
-
1668
1687
  // packages/core/dist/worktrees.js
1669
- import * as fs13 from "node:fs";
1670
- import * as path11 from "node:path";
1688
+ import * as fs12 from "node:fs";
1689
+ import * as path10 from "node:path";
1671
1690
  var LANES = ["work", "chore"];
1672
1691
  function worktreePath(id) {
1673
- return path11.join(lobstahHome(), "worktrees", id);
1692
+ return path10.join(lobstahHome(), "worktrees", id);
1674
1693
  }
1675
1694
  function readRecord(file2) {
1676
1695
  try {
1677
- const r = JSON.parse(fs13.readFileSync(file2, "utf8"));
1696
+ const r = JSON.parse(fs12.readFileSync(file2, "utf8"));
1678
1697
  return typeof r.path === "string" ? r : void 0;
1679
1698
  } catch {
1680
1699
  return void 0;
1681
1700
  }
1682
1701
  }
1683
1702
  function ownerOfPath(p) {
1684
- const rel = path11.relative(path11.join(lobstahHome(), "worktrees"), p);
1685
- if (!rel || rel.startsWith("..") || path11.isAbsolute(rel))
1703
+ const rel = path10.relative(path10.join(lobstahHome(), "worktrees"), p);
1704
+ if (!rel || rel.startsWith("..") || path10.isAbsolute(rel))
1686
1705
  return void 0;
1687
1706
  return rel.split(/[\\/]/)[0];
1688
1707
  }
@@ -1695,7 +1714,7 @@ function dispatchWorktree(id, lane) {
1695
1714
  }
1696
1715
  const dirs = laneDirs(l);
1697
1716
  for (const dir of [dirs.active, dirs.done]) {
1698
- const rec = readRecord(path11.join(dir, id, "worktree.json"));
1717
+ const rec = readRecord(path10.join(dir, id, "worktree.json"));
1699
1718
  if (rec) {
1700
1719
  const owner = rec.of ?? ownerOfPath(rec.path) ?? id;
1701
1720
  return { path: rec.path, owner, reused: owner !== id };
@@ -1707,7 +1726,7 @@ function dispatchWorktree(id, lane) {
1707
1726
  function laneOf(id) {
1708
1727
  for (const l of LANES) {
1709
1728
  const d = laneDirs(l);
1710
- if (fs13.existsSync(path11.join(d.queue, `${id}.json`)) || fs13.existsSync(path11.join(d.active, id)) || fs13.existsSync(path11.join(d.done, id))) {
1729
+ if (fs12.existsSync(path10.join(d.queue, `${id}.json`)) || fs12.existsSync(path10.join(d.active, id)) || fs12.existsSync(path10.join(d.done, id))) {
1711
1730
  return l;
1712
1731
  }
1713
1732
  }
@@ -1727,7 +1746,7 @@ function followUpAncestors(id, lane) {
1727
1746
  function chainWorktree(followUp) {
1728
1747
  for (const id of [followUp, ...followUpAncestors(followUp)]) {
1729
1748
  const wt = dispatchWorktree(id, laneOf(id));
1730
- if (fs13.existsSync(wt.path))
1749
+ if (fs12.existsSync(wt.path))
1731
1750
  return { ...wt, from: id };
1732
1751
  }
1733
1752
  return void 0;
@@ -1742,27 +1761,27 @@ function processAlive(pid) {
1742
1761
  }
1743
1762
  }
1744
1763
  function worktreeGitDir(wt) {
1745
- const dotGit = path11.join(wt, ".git");
1764
+ const dotGit = path10.join(wt, ".git");
1746
1765
  try {
1747
- const st = fs13.statSync(dotGit);
1766
+ const st = fs12.statSync(dotGit);
1748
1767
  if (st.isDirectory())
1749
1768
  return dotGit;
1750
- const m = /^gitdir:\s*(.+?)\s*$/m.exec(fs13.readFileSync(dotGit, "utf8"));
1751
- return m ? path11.resolve(wt, m[1]) : void 0;
1769
+ const m = /^gitdir:\s*(.+?)\s*$/m.exec(fs12.readFileSync(dotGit, "utf8"));
1770
+ return m ? path10.resolve(wt, m[1]) : void 0;
1752
1771
  } catch {
1753
1772
  return void 0;
1754
1773
  }
1755
1774
  }
1756
1775
  function worktreeLockFile(wt) {
1757
1776
  const gitDir = worktreeGitDir(wt);
1758
- return gitDir ? path11.join(gitDir, "lobstah.lock") : void 0;
1777
+ return gitDir ? path10.join(gitDir, "lobstah.lock") : void 0;
1759
1778
  }
1760
1779
  function readWorktreeLock(wt) {
1761
1780
  const file2 = worktreeLockFile(wt);
1762
1781
  if (!file2)
1763
1782
  return void 0;
1764
1783
  try {
1765
- return JSON.parse(fs13.readFileSync(file2, "utf8"));
1784
+ return JSON.parse(fs12.readFileSync(file2, "utf8"));
1766
1785
  } catch {
1767
1786
  return void 0;
1768
1787
  }
@@ -1770,7 +1789,7 @@ function readWorktreeLock(wt) {
1770
1789
  function lockIsLive(lock) {
1771
1790
  if (lock.kind === "warm")
1772
1791
  return processAlive(lock.pid) && Date.now() - (Date.parse(lock.at) || 0) < WARM_LOCK_MAX_MS;
1773
- return fs13.existsSync(path11.join(laneDirs(lock.lane).active, lock.id));
1792
+ return fs12.existsSync(path10.join(laneDirs(lock.lane).active, lock.id));
1774
1793
  }
1775
1794
  function worktreeHolder(wt) {
1776
1795
  const lock = readWorktreeLock(wt);
@@ -1783,7 +1802,7 @@ function acquireWorktreeLock(wt, id, lane, kind) {
1783
1802
  return { id: "(no git dir)", lane, pid: 0, at: mine.at };
1784
1803
  for (let attempt = 0; attempt < 3; attempt++) {
1785
1804
  try {
1786
- fs13.writeFileSync(file2, JSON.stringify(mine, null, 2), { flag: "wx" });
1805
+ fs12.writeFileSync(file2, JSON.stringify(mine, null, 2), { flag: "wx" });
1787
1806
  return void 0;
1788
1807
  } catch (err) {
1789
1808
  if (err.code !== "EEXIST")
@@ -1791,7 +1810,7 @@ function acquireWorktreeLock(wt, id, lane, kind) {
1791
1810
  }
1792
1811
  let raw;
1793
1812
  try {
1794
- raw = fs13.readFileSync(file2, "utf8");
1813
+ raw = fs12.readFileSync(file2, "utf8");
1795
1814
  } catch {
1796
1815
  continue;
1797
1816
  }
@@ -1802,14 +1821,14 @@ function acquireWorktreeLock(wt, id, lane, kind) {
1802
1821
  held2 = void 0;
1803
1822
  }
1804
1823
  if (held2?.id === id) {
1805
- fs13.writeFileSync(file2, JSON.stringify(mine, null, 2));
1824
+ fs12.writeFileSync(file2, JSON.stringify(mine, null, 2));
1806
1825
  return void 0;
1807
1826
  }
1808
1827
  if (held2 && lockIsLive(held2))
1809
1828
  return held2;
1810
1829
  try {
1811
- if (fs13.readFileSync(file2, "utf8") === raw)
1812
- fs13.rmSync(file2, { force: true });
1830
+ if (fs12.readFileSync(file2, "utf8") === raw)
1831
+ fs12.rmSync(file2, { force: true });
1813
1832
  } catch {
1814
1833
  }
1815
1834
  }
@@ -1821,23 +1840,24 @@ function releaseWorktreeLock(wt, id) {
1821
1840
  if (!file2)
1822
1841
  return;
1823
1842
  if (readWorktreeLock(wt)?.id === id)
1824
- fs13.rmSync(file2, { force: true });
1843
+ fs12.rmSync(file2, { force: true });
1825
1844
  }
1826
1845
 
1827
- // packages/core/dist/disk.js
1828
- import * as fs14 from "node:fs";
1829
- var GB = 1024 ** 3;
1830
- var statfsFreeBytes = (dir) => {
1831
- const s = fs14.statfsSync(dir);
1832
- return Number(s.bavail) * Number(s.bsize);
1833
- };
1834
- function formatGB(bytes) {
1835
- return `${(bytes / GB).toFixed(1).replace(/\.0$/, "")} GB`;
1846
+ // packages/core/dist/events.js
1847
+ import * as fs13 from "node:fs";
1848
+ function appendEvent(id, lane, ev) {
1849
+ fs13.appendFileSync(eventsPath(id, lane), `${JSON.stringify(ev)}
1850
+ `);
1851
+ }
1852
+ function touchEvents(id, lane, at = /* @__PURE__ */ new Date()) {
1853
+ const file2 = eventsPath(id, lane);
1854
+ try {
1855
+ fs13.utimesSync(file2, at, at);
1856
+ } catch {
1857
+ fs13.appendFileSync(file2, "");
1858
+ fs13.utimesSync(file2, at, at);
1859
+ }
1836
1860
  }
1837
-
1838
- // packages/core/dist/pools.js
1839
- import * as fs15 from "node:fs";
1840
- import * as path12 from "node:path";
1841
1861
 
1842
1862
  // packages/core/dist/slots.js
1843
1863
  function isTrapCatch(id, lane) {
@@ -1849,29 +1869,31 @@ function isFinished(id, lane) {
1849
1869
  }
1850
1870
 
1851
1871
  // packages/core/dist/pools.js
1872
+ import * as fs14 from "node:fs";
1873
+ import * as path11 from "node:path";
1852
1874
  function poolsRoot() {
1853
- return path12.join(lobstahHome(), "pools");
1875
+ return path11.join(lobstahHome(), "pools");
1854
1876
  }
1855
1877
  function poolDir(pool) {
1856
- return path12.join(poolsRoot(), pool);
1878
+ return path11.join(poolsRoot(), pool);
1857
1879
  }
1858
1880
  function poolSlotPath(pool, slot) {
1859
- return path12.join(poolDir(pool), String(slot));
1881
+ return path11.join(poolDir(pool), String(slot));
1860
1882
  }
1861
1883
  function slotsDir(pool) {
1862
- return path12.join(poolDir(pool), ".slots");
1884
+ return path11.join(poolDir(pool), ".slots");
1863
1885
  }
1864
1886
  function poolSlotOf(p) {
1865
1887
  const real = (x) => {
1866
1888
  try {
1867
- return fs15.realpathSync.native(x);
1889
+ return fs14.realpathSync.native(x);
1868
1890
  } catch {
1869
- return path12.resolve(x);
1891
+ return path11.resolve(x);
1870
1892
  }
1871
1893
  };
1872
- for (const [rootDir, dir] of [[poolsRoot(), path12.resolve(p)], [real(poolsRoot()), real(p)]]) {
1873
- const rel = path12.relative(rootDir, dir);
1874
- if (!rel || rel.startsWith("..") || path12.isAbsolute(rel))
1894
+ for (const [rootDir, dir] of [[poolsRoot(), path11.resolve(p)], [real(poolsRoot()), real(p)]]) {
1895
+ const rel = path11.relative(rootDir, dir);
1896
+ if (!rel || rel.startsWith("..") || path11.isAbsolute(rel))
1875
1897
  continue;
1876
1898
  const parts = rel.split(/[\\/]/);
1877
1899
  if (parts.length !== 2 || !/^[1-9][0-9]*$/.test(parts[1]))
@@ -1885,20 +1907,20 @@ function poolSlotLabel(pool, slot) {
1885
1907
  }
1886
1908
  function readJson(file2) {
1887
1909
  try {
1888
- return JSON.parse(fs15.readFileSync(file2, "utf8"));
1910
+ return JSON.parse(fs14.readFileSync(file2, "utf8"));
1889
1911
  } catch {
1890
1912
  return void 0;
1891
1913
  }
1892
1914
  }
1893
1915
  function writeJson(file2, value) {
1894
- fs15.mkdirSync(path12.dirname(file2), { recursive: true });
1895
- const tmp = `${file2}.tmp-${process.pid}-${Date.now()}`;
1896
- fs15.writeFileSync(tmp, JSON.stringify(value, null, 2));
1897
- fs15.renameSync(tmp, file2);
1898
- }
1899
- var metaFile = (pool, slot) => path12.join(slotsDir(pool), `${slot}.json`);
1900
- var claimFile = (pool, slot) => path12.join(slotsDir(pool), `${slot}.claim.json`);
1901
- var outFile = (pool, slot) => path12.join(slotsDir(pool), `${slot}.out.json`);
1916
+ fs14.mkdirSync(path11.dirname(file2), { recursive: true });
1917
+ const tmp = uniqueTempPath(file2);
1918
+ fs14.writeFileSync(tmp, JSON.stringify(value, null, 2));
1919
+ atomicRenameSync(tmp, file2);
1920
+ }
1921
+ var metaFile = (pool, slot) => path11.join(slotsDir(pool), `${slot}.json`);
1922
+ var claimFile = (pool, slot) => path11.join(slotsDir(pool), `${slot}.claim.json`);
1923
+ var outFile = (pool, slot) => path11.join(slotsDir(pool), `${slot}.out.json`);
1902
1924
  function readSlotMeta(pool, slot) {
1903
1925
  return readJson(metaFile(pool, slot)) ?? {};
1904
1926
  }
@@ -1918,7 +1940,7 @@ function writeSlotOut(pool, slot, out) {
1918
1940
  writeJson(outFile(pool, slot), out);
1919
1941
  }
1920
1942
  function clearSlotOut(pool, slot) {
1921
- fs15.rmSync(outFile(pool, slot), { force: true });
1943
+ fs14.rmSync(outFile(pool, slot), { force: true });
1922
1944
  }
1923
1945
  function dispatchHolder(dir) {
1924
1946
  const lock = readWorktreeLock(dir);
@@ -1928,7 +1950,7 @@ function poolSlotView(pool, slot) {
1928
1950
  const dir = poolSlotPath(pool, slot);
1929
1951
  const lastClaim = readSlotClaim(pool, slot)?.id;
1930
1952
  const base = { slot, path: dir, ...lastClaim ? { lastClaim } : {} };
1931
- if (!fs15.existsSync(dir)) {
1953
+ if (!fs14.existsSync(dir)) {
1932
1954
  const meta2 = readSlotMeta(pool, slot);
1933
1955
  return { ...base, state: "missing", ...meta2.error ? { reason: meta2.error } : {} };
1934
1956
  }
@@ -1943,8 +1965,8 @@ function poolSlotView(pool, slot) {
1943
1965
  return { ...base, state: "warming", ...meta.error ? { reason: meta.error } : {} };
1944
1966
  return { ...base, state: "free" };
1945
1967
  }
1946
- var warmStateFile = (pool) => path12.join(poolDir(pool), ".warm-state.json");
1947
- var warmLockFile = (pool) => path12.join(poolDir(pool), ".warm.lock");
1968
+ var warmStateFile = (pool) => path11.join(poolDir(pool), ".warm-state.json");
1969
+ var warmLockFile = (pool) => path11.join(poolDir(pool), ".warm.lock");
1948
1970
  var POOL_WARM_MAX_MS = 60 * 6e4;
1949
1971
  function readPoolWarmState(pool) {
1950
1972
  return readJson(warmStateFile(pool)) ?? {};
@@ -1966,15 +1988,15 @@ function poolWarmRunning(pool, now2 = Date.now()) {
1966
1988
  }
1967
1989
  function takePoolWarmLock(pool) {
1968
1990
  const file2 = warmLockFile(pool);
1969
- fs15.mkdirSync(path12.dirname(file2), { recursive: true });
1991
+ fs14.mkdirSync(path11.dirname(file2), { recursive: true });
1970
1992
  const mine = JSON.stringify({ pid: process.pid, at: (/* @__PURE__ */ new Date()).toISOString() });
1971
1993
  for (let attempt = 0; attempt < 2; attempt++) {
1972
1994
  try {
1973
- fs15.writeFileSync(file2, mine, { flag: "wx" });
1995
+ fs14.writeFileSync(file2, mine, { flag: "wx" });
1974
1996
  return () => {
1975
1997
  try {
1976
- if (fs15.readFileSync(file2, "utf8") === mine)
1977
- fs15.rmSync(file2, { force: true });
1998
+ if (fs14.readFileSync(file2, "utf8") === mine)
1999
+ fs14.rmSync(file2, { force: true });
1978
2000
  } catch {
1979
2001
  }
1980
2002
  };
@@ -1984,7 +2006,7 @@ function takePoolWarmLock(pool) {
1984
2006
  }
1985
2007
  if (poolWarmRunning(pool))
1986
2008
  return void 0;
1987
- fs15.rmSync(file2, { force: true });
2009
+ fs14.rmSync(file2, { force: true });
1988
2010
  }
1989
2011
  return void 0;
1990
2012
  }
@@ -1992,20 +2014,78 @@ var POOL_RETRY_MS = 10 * 6e4;
1992
2014
  var POOL_FETCH_MS = 10 * 6e4;
1993
2015
  var POOL_RECHECK_MS = 5 * 6e4;
1994
2016
 
2017
+ // packages/core/dist/disk.js
2018
+ import * as fs15 from "node:fs";
2019
+ var GB = 1024 ** 3;
2020
+ var statfsFreeBytes = (dir) => {
2021
+ const s = fs15.statfsSync(dir);
2022
+ return Number(s.bavail) * Number(s.bsize);
2023
+ };
2024
+ function formatGB(bytes) {
2025
+ return `${(bytes / GB).toFixed(1).replace(/\.0$/, "")} GB`;
2026
+ }
2027
+
2028
+ // packages/core/dist/notices.js
2029
+ function noticesDir() {
2030
+ return path12.join(lobstahHome(), "notices");
2031
+ }
2032
+ var counter = 0;
2033
+ function postNotice(n) {
2034
+ const dir = noticesDir();
2035
+ fs16.mkdirSync(dir, { recursive: true });
2036
+ if (n.dedupeKey) {
2037
+ const marker = path12.join(dir, `.dedupe-${n.dedupeKey.replace(/[^A-Za-z0-9_-]/g, "_")}`);
2038
+ try {
2039
+ fs16.writeFileSync(marker, "", { flag: "wx" });
2040
+ } catch {
2041
+ return void 0;
2042
+ }
2043
+ }
2044
+ const seq = `${String(Date.now()).padStart(15, "0")}-${process.pid}-${String(counter++).padStart(8, "0")}`;
2045
+ const notice = {
2046
+ seq,
2047
+ kind: n.kind,
2048
+ at: (/* @__PURE__ */ new Date()).toISOString(),
2049
+ text: n.text,
2050
+ refId: n.refId,
2051
+ ...n.url ? { url: n.url } : {},
2052
+ repo: n.repo,
2053
+ by: n.by,
2054
+ ...n.quiet ? { quiet: true } : {},
2055
+ ...n.stateHash ? { stateHash: n.stateHash } : {}
2056
+ };
2057
+ const file2 = path12.join(dir, `${seq}.json`);
2058
+ const tmp = uniqueTempPath(file2);
2059
+ fs16.writeFileSync(tmp, JSON.stringify(notice, null, 2));
2060
+ atomicRenameSync(tmp, file2);
2061
+ return notice;
2062
+ }
2063
+
2064
+ // packages/core/dist/attachments.js
2065
+ function attachmentBlock(attachments) {
2066
+ if (attachments.length === 0)
2067
+ return "";
2068
+ return [
2069
+ "--- ATTACHMENTS ---",
2070
+ ...attachments.map((a) => `${a.name} (${a.type}, ${a.bytes} bytes) at ${a.path}`),
2071
+ "Images and PDFs can be read directly with your file tools."
2072
+ ].join("\n");
2073
+ }
2074
+
1995
2075
  // packages/core/dist/soak.js
1996
2076
  function regPath(trapId) {
1997
2077
  return path13.join(soakingDir(), `${trapId}.json`);
1998
2078
  }
1999
2079
  function readTrap(trapId) {
2000
2080
  try {
2001
- return JSON.parse(fs16.readFileSync(regPath(trapId), "utf8"));
2081
+ return JSON.parse(fs17.readFileSync(regPath(trapId), "utf8"));
2002
2082
  } catch {
2003
2083
  return void 0;
2004
2084
  }
2005
2085
  }
2006
2086
  function listTraps() {
2007
2087
  try {
2008
- return fs16.readdirSync(soakingDir()).filter((f) => f.endsWith(".json")).map((f) => JSON.parse(fs16.readFileSync(path13.join(soakingDir(), f), "utf8"))).filter((r) => typeof r.trapId === "string");
2088
+ return fs17.readdirSync(soakingDir()).filter((f) => f.endsWith(".json")).map((f) => JSON.parse(fs17.readFileSync(path13.join(soakingDir(), f), "utf8"))).filter((r) => typeof r.trapId === "string");
2009
2089
  } catch {
2010
2090
  return [];
2011
2091
  }
@@ -2015,7 +2095,7 @@ function claimPath(id, lane) {
2015
2095
  }
2016
2096
  function readSessionClaim(id, lane) {
2017
2097
  try {
2018
- return JSON.parse(fs16.readFileSync(claimPath(id, lane), "utf8"));
2098
+ return JSON.parse(fs17.readFileSync(claimPath(id, lane), "utf8"));
2019
2099
  } catch {
2020
2100
  return void 0;
2021
2101
  }
@@ -2037,7 +2117,7 @@ function localDay(at = Date.now()) {
2037
2117
  function readCatchFacts(stateDir, id) {
2038
2118
  let last;
2039
2119
  try {
2040
- for (const line of fs17.readFileSync(path14.join(stateDir, `${id}.status`), "utf8").split("\n")) {
2120
+ for (const line of fs18.readFileSync(path14.join(stateDir, `${id}.status`), "utf8").split("\n")) {
2041
2121
  if (!line.trim())
2042
2122
  continue;
2043
2123
  try {
@@ -2053,7 +2133,7 @@ function readCatchFacts(stateDir, id) {
2053
2133
  let trap;
2054
2134
  let worker = workerProfile();
2055
2135
  try {
2056
- const evidence = JSON.parse(fs17.readFileSync(path14.join(stateDir, `${id}.evidence`), "utf8"));
2136
+ const evidence = JSON.parse(fs18.readFileSync(path14.join(stateDir, `${id}.evidence`), "utf8"));
2057
2137
  const to = evidence.deliveredTo;
2058
2138
  if (typeof to === "string" && to.startsWith("wt:"))
2059
2139
  trap = to;
@@ -2126,7 +2206,7 @@ function add(store, facts, now2) {
2126
2206
  }
2127
2207
  function backfillSources() {
2128
2208
  const live = ["work", "chore"].map((lane) => ({ dir: laneDirs(lane).state, live: true }));
2129
- const backups = readDirIfPresent(lobstahHome()).filter((name) => name.startsWith("state-backup-")).sort().map((name) => ({ dir: path14.join(lobstahHome(), name), live: false })).filter((s) => fs17.statSync(s.dir).isDirectory());
2209
+ const backups = readDirIfPresent(lobstahHome()).filter((name) => name.startsWith("state-backup-")).sort().map((name) => ({ dir: path14.join(lobstahHome(), name), live: false })).filter((s) => fs18.statSync(s.dir).isDirectory());
2130
2210
  return [...live, ...backups];
2131
2211
  }
2132
2212
  function backfillStats(now2 = Date.now(), alreadyCounted) {
@@ -2198,25 +2278,25 @@ function parseStore(text) {
2198
2278
  var complete2 = (s) => !!s && s.daily !== void 0;
2199
2279
  function writeStore(store) {
2200
2280
  const file2 = statsPath();
2201
- fs17.mkdirSync(path14.dirname(file2), { recursive: true });
2202
- const tmp = `${file2}.tmp-${process.pid}`;
2203
- fs17.writeFileSync(tmp, JSON.stringify(store));
2204
- fs17.renameSync(tmp, file2);
2281
+ fs18.mkdirSync(path14.dirname(file2), { recursive: true });
2282
+ const tmp = uniqueTempPath(file2);
2283
+ fs18.writeFileSync(tmp, JSON.stringify(store));
2284
+ atomicRenameSync(tmp, file2);
2205
2285
  }
2206
2286
  function withStatsLock(action) {
2207
- fs17.mkdirSync(lobstahHome(), { recursive: true });
2287
+ fs18.mkdirSync(lobstahHome(), { recursive: true });
2208
2288
  const lock = `${statsPath()}.lock`;
2209
2289
  const deadline = Date.now() + 1e4;
2210
2290
  for (; ; ) {
2211
2291
  try {
2212
- fs17.mkdirSync(lock);
2292
+ fs18.mkdirSync(lock);
2213
2293
  break;
2214
2294
  } catch (err) {
2215
2295
  if (err.code !== "EEXIST")
2216
2296
  throw err;
2217
2297
  try {
2218
- if (Date.now() - fs17.statSync(lock).mtimeMs > 12e4)
2219
- fs17.rmdirSync(lock);
2298
+ if (Date.now() - fs18.statSync(lock).mtimeMs > 12e4)
2299
+ fs18.rmdirSync(lock);
2220
2300
  } catch {
2221
2301
  }
2222
2302
  if (Date.now() >= deadline)
@@ -2227,13 +2307,13 @@ function withStatsLock(action) {
2227
2307
  try {
2228
2308
  return action();
2229
2309
  } finally {
2230
- fs17.rmdirSync(lock);
2310
+ fs18.rmdirSync(lock);
2231
2311
  }
2232
2312
  }
2233
2313
  function loadOrBackfill(now2) {
2234
2314
  let text;
2235
2315
  try {
2236
- text = fs17.readFileSync(statsPath(), "utf8");
2316
+ text = fs18.readFileSync(statsPath(), "utf8");
2237
2317
  } catch (err) {
2238
2318
  if (err.code !== "ENOENT")
2239
2319
  throw err;
@@ -2260,7 +2340,7 @@ function loadOrBackfill(now2) {
2260
2340
  return store2;
2261
2341
  }
2262
2342
  if (text !== void 0)
2263
- fs17.renameSync(statsPath(), `${statsPath()}.unreadable-${now2}`);
2343
+ fs18.renameSync(statsPath(), `${statsPath()}.unreadable-${now2}`);
2264
2344
  const store = backfillStats(now2);
2265
2345
  writeStore(store);
2266
2346
  return store;
@@ -2303,7 +2383,7 @@ var ANSWER_TYPES = {
2303
2383
  var ANSWER_EXTENSIONS = Object.keys(ANSWER_TYPES);
2304
2384
 
2305
2385
  // packages/core/dist/inbox.js
2306
- import * as fs18 from "node:fs";
2386
+ import * as fs19 from "node:fs";
2307
2387
  import * as path15 from "node:path";
2308
2388
  var metaName = (file2) => file2.replace(/\.msg$/, ".meta.json");
2309
2389
  function inboxDir(id, lane) {
@@ -2311,31 +2391,15 @@ function inboxDir(id, lane) {
2311
2391
  }
2312
2392
  function unhandled(id, lane) {
2313
2393
  const dir = inboxDir(id, lane);
2314
- return readDirIfPresent(dir).filter((f) => f.endsWith(".msg")).sort().map((f) => ({ file: f, text: fs18.readFileSync(path15.join(dir, f), "utf8") }));
2394
+ return readDirIfPresent(dir).filter((f) => f.endsWith(".msg")).sort().map((f) => ({ file: f, text: fs19.readFileSync(path15.join(dir, f), "utf8") }));
2315
2395
  }
2316
2396
  function acknowledge(id, lane, file2) {
2317
2397
  const dir = inboxDir(id, lane);
2318
- fs18.mkdirSync(path15.join(dir, "handled"), { recursive: true });
2319
- fs18.renameSync(path15.join(dir, file2), path15.join(dir, "handled", file2));
2320
- try {
2321
- fs18.renameSync(path15.join(dir, metaName(file2)), path15.join(dir, "handled", metaName(file2)));
2322
- } catch {
2323
- }
2324
- }
2325
-
2326
- // packages/core/dist/events.js
2327
- import * as fs19 from "node:fs";
2328
- function appendEvent(id, lane, ev) {
2329
- fs19.appendFileSync(eventsPath(id, lane), `${JSON.stringify(ev)}
2330
- `);
2331
- }
2332
- function touchEvents(id, lane, at = /* @__PURE__ */ new Date()) {
2333
- const file2 = eventsPath(id, lane);
2398
+ fs19.mkdirSync(path15.join(dir, "handled"), { recursive: true });
2399
+ fs19.renameSync(path15.join(dir, file2), path15.join(dir, "handled", file2));
2334
2400
  try {
2335
- fs19.utimesSync(file2, at, at);
2401
+ fs19.renameSync(path15.join(dir, metaName(file2)), path15.join(dir, "handled", metaName(file2)));
2336
2402
  } catch {
2337
- fs19.appendFileSync(file2, "");
2338
- fs19.utimesSync(file2, at, at);
2339
2403
  }
2340
2404
  }
2341
2405
 
@@ -4478,7 +4542,7 @@ async function main(activeDir, lane, seams = {}) {
4478
4542
  cfg.limits.maxWallClockSecs ?? (resolved.limits.wallClockSecs ?? 0) * 4
4479
4543
  ) * 1e3;
4480
4544
  const persistWall = (elapsedMs, windowMs) => {
4481
- const tmp = `${wallFile}.tmp-${process.pid}`;
4545
+ const tmp = uniqueTempPath(wallFile);
4482
4546
  fs26.writeFileSync(tmp, JSON.stringify({ ...wallState, elapsedMs, windowMs }));
4483
4547
  fs26.renameSync(tmp, wallFile);
4484
4548
  };
@@ -4647,6 +4711,53 @@ async function main(activeDir, lane, seams = {}) {
4647
4711
 
4648
4712
  // packages/runner/src/reap.ts
4649
4713
  import { execFileSync as execFileSync3 } from "node:child_process";
4714
+
4715
+ // packages/runner/src/windows-processes.ts
4716
+ var WINDOWS_PROCESS_SNAPSHOT = String.raw`
4717
+ $ErrorActionPreference = 'Stop'
4718
+ Add-Type -TypeDefinition @'
4719
+ using System;
4720
+ using System.ComponentModel;
4721
+ using System.Runtime.InteropServices;
4722
+ public static class LobstahProcessSnapshot {
4723
+ [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
4724
+ public struct Entry {
4725
+ public uint size, usage, pid;
4726
+ public UIntPtr heap;
4727
+ public uint module, threads, parent;
4728
+ public int priority;
4729
+ public uint flags;
4730
+ [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] public string exe;
4731
+ }
4732
+ [DllImport("kernel32.dll", SetLastError = true)]
4733
+ static extern IntPtr CreateToolhelp32Snapshot(uint flags, uint pid);
4734
+ [DllImport("kernel32.dll", EntryPoint = "Process32FirstW", ExactSpelling = true, SetLastError = true)]
4735
+ static extern bool First(IntPtr snapshot, ref Entry entry);
4736
+ [DllImport("kernel32.dll", EntryPoint = "Process32NextW", ExactSpelling = true, SetLastError = true)]
4737
+ static extern bool Next(IntPtr snapshot, ref Entry entry);
4738
+ [DllImport("kernel32.dll")]
4739
+ static extern bool CloseHandle(IntPtr handle);
4740
+ public static void Print() {
4741
+ IntPtr snapshot = CreateToolhelp32Snapshot(2, 0); // TH32CS_SNAPPROCESS only
4742
+ if (snapshot == new IntPtr(-1)) throw new Win32Exception(Marshal.GetLastWin32Error());
4743
+ try {
4744
+ Entry entry = new Entry();
4745
+ entry.size = (uint)Marshal.SizeOf(typeof(Entry));
4746
+ bool more = First(snapshot, ref entry);
4747
+ while (more) {
4748
+ Console.WriteLine("{0} {1}", entry.pid, entry.parent);
4749
+ more = Next(snapshot, ref entry);
4750
+ }
4751
+ int error = Marshal.GetLastWin32Error();
4752
+ if (error != 18) throw new Win32Exception(error); // ERROR_NO_MORE_FILES
4753
+ } finally { CloseHandle(snapshot); }
4754
+ }
4755
+ }
4756
+ '@
4757
+ [LobstahProcessSnapshot]::Print()
4758
+ `;
4759
+
4760
+ // packages/runner/src/reap.ts
4650
4761
  function listProcesses() {
4651
4762
  if (process.platform === "win32") {
4652
4763
  const out2 = execFileSync3(
@@ -4655,7 +4766,7 @@ function listProcesses() {
4655
4766
  "-NoProfile",
4656
4767
  "-NonInteractive",
4657
4768
  "-Command",
4658
- 'Get-CimInstance Win32_Process | ForEach-Object { "$($_.ProcessId) $($_.ParentProcessId)" }'
4769
+ WINDOWS_PROCESS_SNAPSHOT
4659
4770
  ],
4660
4771
  { encoding: "utf8", windowsHide: true, timeout: 3e4, stdio: ["ignore", "pipe", "ignore"] }
4661
4772
  );