lobstah 0.7.4 → 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,17 +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
19
  import { randomUUID } from "node:crypto";
20
20
  function uniqueTempPath(file2) {
21
21
  return `${file2}.tmp-${process.pid}-${randomUUID()}`;
22
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
+ }
23
35
  function readDirIfPresent(dir) {
24
36
  try {
25
37
  return fs.readdirSync(dir);
@@ -153,7 +165,7 @@ function sanitizeWorker(value) {
153
165
  }
154
166
 
155
167
  // packages/core/dist/soak.js
156
- import * as fs16 from "node:fs";
168
+ import * as fs17 from "node:fs";
157
169
  import * as path13 from "node:path";
158
170
 
159
171
  // packages/core/dist/queue.js
@@ -289,7 +301,7 @@ function activityFromEvent(ev, root) {
289
301
  function atomicWrite(file2, content) {
290
302
  const tmp = uniqueTempPath(file2);
291
303
  fs2.writeFileSync(tmp, content);
292
- fs2.renameSync(tmp, file2);
304
+ atomicRenameSync(tmp, file2);
293
305
  }
294
306
  function writeActivity(id, lane, a) {
295
307
  const safe = { at: a.at, kind: a.kind, summary: redactSummary(a.summary) };
@@ -460,9 +472,18 @@ function pausedWaiting(entry) {
460
472
  function requeue(id, lane) {
461
473
  const dirs = laneDirs(lane);
462
474
  const activeDir = path3.join(dirs.active, id);
463
- 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`));
464
481
  fs4.rmSync(activeDir, { recursive: true, force: true });
465
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
+ }
466
487
  function storedDescriptor(id, lane) {
467
488
  const dirs = laneDirs(lane);
468
489
  for (const file2 of [
@@ -501,7 +522,7 @@ function mergeEvidence(id, lane, patch) {
501
522
  const file2 = evidencePath(id, lane);
502
523
  const tmp = uniqueTempPath(file2);
503
524
  fs5.writeFileSync(tmp, JSON.stringify({ ...readEvidence(id, lane), ...patch }, null, 2));
504
- fs5.renameSync(tmp, file2);
525
+ atomicRenameSync(tmp, file2);
505
526
  }
506
527
 
507
528
  // packages/core/dist/pushes.js
@@ -602,8 +623,8 @@ function recordPush(id, lane, branches, at = (/* @__PURE__ */ new Date()).toISOS
602
623
  }
603
624
 
604
625
  // packages/core/dist/notices.js
605
- import fs12 from "node:fs";
606
- import * as path10 from "node:path";
626
+ import fs16 from "node:fs";
627
+ import * as path12 from "node:path";
607
628
 
608
629
  // packages/core/dist/config.js
609
630
  import * as fs7 from "node:fs";
@@ -1255,6 +1276,30 @@ function parse(toml, { maxDepth = 1e3, integersAsBigInt } = {}) {
1255
1276
  return res;
1256
1277
  }
1257
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
+
1258
1303
  // packages/core/dist/config.js
1259
1304
  var POOL_NAME = /^[A-Za-z0-9_-]+$/;
1260
1305
  function parsePools(raw, repos) {
@@ -1323,6 +1368,9 @@ var DEFAULT_SOAK = {
1323
1368
  signOffGraceSecs: 600
1324
1369
  };
1325
1370
  var DEFAULT_HELM = {
1371
+ queuedNoticeSecs: 180,
1372
+ stalledNoticeSecs: 1200,
1373
+ idleWorkingNoticeSecs: 60,
1326
1374
  ttlSecs: 1800,
1327
1375
  reportSecs: 900,
1328
1376
  armGraceSecs: 5
@@ -1356,7 +1404,16 @@ function expandHome(p) {
1356
1404
  function loadConfig() {
1357
1405
  const file2 = configPath();
1358
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()}`);
1359
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
+ }
1360
1417
  if (typeof watch.repairCooldownSecs !== "number" || !Number.isFinite(watch.repairCooldownSecs) || watch.repairCooldownSecs < 0) {
1361
1418
  throw new Error(`[watch].repairCooldownSecs must be a non-negative number in ${configPath()}`);
1362
1419
  }
@@ -1367,8 +1424,11 @@ function loadConfig() {
1367
1424
  const reposRaw = raw.repos ?? {};
1368
1425
  const repos = {};
1369
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}`);
1370
1429
  repos[key] = {
1371
1430
  path: expandHome(String(r.path ?? "")),
1431
+ ...r.review !== void 0 ? { review: r.review } : {},
1372
1432
  origin: r.origin ? String(r.origin) : void 0,
1373
1433
  trunk: String(r.trunk ?? "main"),
1374
1434
  setup: Array.isArray(r.setup) ? r.setup.map(String) : void 0,
@@ -1394,8 +1454,9 @@ function loadConfig() {
1394
1454
  harness: raw.harness ?? {},
1395
1455
  limits: { ...DEFAULT_LIMITS, ...raw.limits ?? {} },
1396
1456
  soak: parseSoak(raw.soak),
1397
- helm: { ...DEFAULT_HELM, ...raw.helm ?? {} },
1457
+ helm,
1398
1458
  glass: { ...DEFAULT_GLASS, ...raw.glass ?? {} },
1459
+ pet: { open: petOpen },
1399
1460
  watch,
1400
1461
  grounds,
1401
1462
  pools: parsePools(raw.pools, repos),
@@ -1623,71 +1684,24 @@ function parseUnresolvedThreads(stdout) {
1623
1684
  }
1624
1685
  }
1625
1686
 
1626
- // packages/core/dist/notices.js
1627
- function noticesDir() {
1628
- return path10.join(lobstahHome(), "notices");
1629
- }
1630
- var counter = 0;
1631
- function postNotice(n) {
1632
- const dir = noticesDir();
1633
- fs12.mkdirSync(dir, { recursive: true });
1634
- if (n.dedupeKey) {
1635
- const marker = path10.join(dir, `.dedupe-${n.dedupeKey.replace(/[^A-Za-z0-9_-]/g, "_")}`);
1636
- try {
1637
- fs12.writeFileSync(marker, "", { flag: "wx" });
1638
- } catch {
1639
- return void 0;
1640
- }
1641
- }
1642
- const seq = `${String(Date.now()).padStart(15, "0")}-${process.pid}-${String(counter++).padStart(8, "0")}`;
1643
- const notice = {
1644
- seq,
1645
- kind: n.kind,
1646
- at: (/* @__PURE__ */ new Date()).toISOString(),
1647
- text: n.text,
1648
- refId: n.refId,
1649
- ...n.url ? { url: n.url } : {},
1650
- repo: n.repo,
1651
- by: n.by,
1652
- ...n.quiet ? { quiet: true } : {},
1653
- ...n.stateHash ? { stateHash: n.stateHash } : {}
1654
- };
1655
- const file2 = path10.join(dir, `${seq}.json`);
1656
- const tmp = uniqueTempPath(file2);
1657
- fs12.writeFileSync(tmp, JSON.stringify(notice, null, 2));
1658
- fs12.renameSync(tmp, file2);
1659
- return notice;
1660
- }
1661
-
1662
- // packages/core/dist/attachments.js
1663
- function attachmentBlock(attachments) {
1664
- if (attachments.length === 0)
1665
- return "";
1666
- return [
1667
- "--- ATTACHMENTS ---",
1668
- ...attachments.map((a) => `${a.name} (${a.type}, ${a.bytes} bytes) at ${a.path}`),
1669
- "Images and PDFs can be read directly with your file tools."
1670
- ].join("\n");
1671
- }
1672
-
1673
1687
  // packages/core/dist/worktrees.js
1674
- import * as fs13 from "node:fs";
1675
- import * as path11 from "node:path";
1688
+ import * as fs12 from "node:fs";
1689
+ import * as path10 from "node:path";
1676
1690
  var LANES = ["work", "chore"];
1677
1691
  function worktreePath(id) {
1678
- return path11.join(lobstahHome(), "worktrees", id);
1692
+ return path10.join(lobstahHome(), "worktrees", id);
1679
1693
  }
1680
1694
  function readRecord(file2) {
1681
1695
  try {
1682
- const r = JSON.parse(fs13.readFileSync(file2, "utf8"));
1696
+ const r = JSON.parse(fs12.readFileSync(file2, "utf8"));
1683
1697
  return typeof r.path === "string" ? r : void 0;
1684
1698
  } catch {
1685
1699
  return void 0;
1686
1700
  }
1687
1701
  }
1688
1702
  function ownerOfPath(p) {
1689
- const rel = path11.relative(path11.join(lobstahHome(), "worktrees"), p);
1690
- 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))
1691
1705
  return void 0;
1692
1706
  return rel.split(/[\\/]/)[0];
1693
1707
  }
@@ -1700,7 +1714,7 @@ function dispatchWorktree(id, lane) {
1700
1714
  }
1701
1715
  const dirs = laneDirs(l);
1702
1716
  for (const dir of [dirs.active, dirs.done]) {
1703
- const rec = readRecord(path11.join(dir, id, "worktree.json"));
1717
+ const rec = readRecord(path10.join(dir, id, "worktree.json"));
1704
1718
  if (rec) {
1705
1719
  const owner = rec.of ?? ownerOfPath(rec.path) ?? id;
1706
1720
  return { path: rec.path, owner, reused: owner !== id };
@@ -1712,7 +1726,7 @@ function dispatchWorktree(id, lane) {
1712
1726
  function laneOf(id) {
1713
1727
  for (const l of LANES) {
1714
1728
  const d = laneDirs(l);
1715
- 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))) {
1716
1730
  return l;
1717
1731
  }
1718
1732
  }
@@ -1732,7 +1746,7 @@ function followUpAncestors(id, lane) {
1732
1746
  function chainWorktree(followUp) {
1733
1747
  for (const id of [followUp, ...followUpAncestors(followUp)]) {
1734
1748
  const wt = dispatchWorktree(id, laneOf(id));
1735
- if (fs13.existsSync(wt.path))
1749
+ if (fs12.existsSync(wt.path))
1736
1750
  return { ...wt, from: id };
1737
1751
  }
1738
1752
  return void 0;
@@ -1747,27 +1761,27 @@ function processAlive(pid) {
1747
1761
  }
1748
1762
  }
1749
1763
  function worktreeGitDir(wt) {
1750
- const dotGit = path11.join(wt, ".git");
1764
+ const dotGit = path10.join(wt, ".git");
1751
1765
  try {
1752
- const st = fs13.statSync(dotGit);
1766
+ const st = fs12.statSync(dotGit);
1753
1767
  if (st.isDirectory())
1754
1768
  return dotGit;
1755
- const m = /^gitdir:\s*(.+?)\s*$/m.exec(fs13.readFileSync(dotGit, "utf8"));
1756
- 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;
1757
1771
  } catch {
1758
1772
  return void 0;
1759
1773
  }
1760
1774
  }
1761
1775
  function worktreeLockFile(wt) {
1762
1776
  const gitDir = worktreeGitDir(wt);
1763
- return gitDir ? path11.join(gitDir, "lobstah.lock") : void 0;
1777
+ return gitDir ? path10.join(gitDir, "lobstah.lock") : void 0;
1764
1778
  }
1765
1779
  function readWorktreeLock(wt) {
1766
1780
  const file2 = worktreeLockFile(wt);
1767
1781
  if (!file2)
1768
1782
  return void 0;
1769
1783
  try {
1770
- return JSON.parse(fs13.readFileSync(file2, "utf8"));
1784
+ return JSON.parse(fs12.readFileSync(file2, "utf8"));
1771
1785
  } catch {
1772
1786
  return void 0;
1773
1787
  }
@@ -1775,7 +1789,7 @@ function readWorktreeLock(wt) {
1775
1789
  function lockIsLive(lock) {
1776
1790
  if (lock.kind === "warm")
1777
1791
  return processAlive(lock.pid) && Date.now() - (Date.parse(lock.at) || 0) < WARM_LOCK_MAX_MS;
1778
- return fs13.existsSync(path11.join(laneDirs(lock.lane).active, lock.id));
1792
+ return fs12.existsSync(path10.join(laneDirs(lock.lane).active, lock.id));
1779
1793
  }
1780
1794
  function worktreeHolder(wt) {
1781
1795
  const lock = readWorktreeLock(wt);
@@ -1788,7 +1802,7 @@ function acquireWorktreeLock(wt, id, lane, kind) {
1788
1802
  return { id: "(no git dir)", lane, pid: 0, at: mine.at };
1789
1803
  for (let attempt = 0; attempt < 3; attempt++) {
1790
1804
  try {
1791
- fs13.writeFileSync(file2, JSON.stringify(mine, null, 2), { flag: "wx" });
1805
+ fs12.writeFileSync(file2, JSON.stringify(mine, null, 2), { flag: "wx" });
1792
1806
  return void 0;
1793
1807
  } catch (err) {
1794
1808
  if (err.code !== "EEXIST")
@@ -1796,7 +1810,7 @@ function acquireWorktreeLock(wt, id, lane, kind) {
1796
1810
  }
1797
1811
  let raw;
1798
1812
  try {
1799
- raw = fs13.readFileSync(file2, "utf8");
1813
+ raw = fs12.readFileSync(file2, "utf8");
1800
1814
  } catch {
1801
1815
  continue;
1802
1816
  }
@@ -1807,14 +1821,14 @@ function acquireWorktreeLock(wt, id, lane, kind) {
1807
1821
  held2 = void 0;
1808
1822
  }
1809
1823
  if (held2?.id === id) {
1810
- fs13.writeFileSync(file2, JSON.stringify(mine, null, 2));
1824
+ fs12.writeFileSync(file2, JSON.stringify(mine, null, 2));
1811
1825
  return void 0;
1812
1826
  }
1813
1827
  if (held2 && lockIsLive(held2))
1814
1828
  return held2;
1815
1829
  try {
1816
- if (fs13.readFileSync(file2, "utf8") === raw)
1817
- fs13.rmSync(file2, { force: true });
1830
+ if (fs12.readFileSync(file2, "utf8") === raw)
1831
+ fs12.rmSync(file2, { force: true });
1818
1832
  } catch {
1819
1833
  }
1820
1834
  }
@@ -1826,23 +1840,24 @@ function releaseWorktreeLock(wt, id) {
1826
1840
  if (!file2)
1827
1841
  return;
1828
1842
  if (readWorktreeLock(wt)?.id === id)
1829
- fs13.rmSync(file2, { force: true });
1843
+ fs12.rmSync(file2, { force: true });
1830
1844
  }
1831
1845
 
1832
- // packages/core/dist/disk.js
1833
- import * as fs14 from "node:fs";
1834
- var GB = 1024 ** 3;
1835
- var statfsFreeBytes = (dir) => {
1836
- const s = fs14.statfsSync(dir);
1837
- return Number(s.bavail) * Number(s.bsize);
1838
- };
1839
- function formatGB(bytes) {
1840
- 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
+ }
1841
1860
  }
1842
-
1843
- // packages/core/dist/pools.js
1844
- import * as fs15 from "node:fs";
1845
- import * as path12 from "node:path";
1846
1861
 
1847
1862
  // packages/core/dist/slots.js
1848
1863
  function isTrapCatch(id, lane) {
@@ -1854,29 +1869,31 @@ function isFinished(id, lane) {
1854
1869
  }
1855
1870
 
1856
1871
  // packages/core/dist/pools.js
1872
+ import * as fs14 from "node:fs";
1873
+ import * as path11 from "node:path";
1857
1874
  function poolsRoot() {
1858
- return path12.join(lobstahHome(), "pools");
1875
+ return path11.join(lobstahHome(), "pools");
1859
1876
  }
1860
1877
  function poolDir(pool) {
1861
- return path12.join(poolsRoot(), pool);
1878
+ return path11.join(poolsRoot(), pool);
1862
1879
  }
1863
1880
  function poolSlotPath(pool, slot) {
1864
- return path12.join(poolDir(pool), String(slot));
1881
+ return path11.join(poolDir(pool), String(slot));
1865
1882
  }
1866
1883
  function slotsDir(pool) {
1867
- return path12.join(poolDir(pool), ".slots");
1884
+ return path11.join(poolDir(pool), ".slots");
1868
1885
  }
1869
1886
  function poolSlotOf(p) {
1870
1887
  const real = (x) => {
1871
1888
  try {
1872
- return fs15.realpathSync.native(x);
1889
+ return fs14.realpathSync.native(x);
1873
1890
  } catch {
1874
- return path12.resolve(x);
1891
+ return path11.resolve(x);
1875
1892
  }
1876
1893
  };
1877
- for (const [rootDir, dir] of [[poolsRoot(), path12.resolve(p)], [real(poolsRoot()), real(p)]]) {
1878
- const rel = path12.relative(rootDir, dir);
1879
- 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))
1880
1897
  continue;
1881
1898
  const parts = rel.split(/[\\/]/);
1882
1899
  if (parts.length !== 2 || !/^[1-9][0-9]*$/.test(parts[1]))
@@ -1890,20 +1907,20 @@ function poolSlotLabel(pool, slot) {
1890
1907
  }
1891
1908
  function readJson(file2) {
1892
1909
  try {
1893
- return JSON.parse(fs15.readFileSync(file2, "utf8"));
1910
+ return JSON.parse(fs14.readFileSync(file2, "utf8"));
1894
1911
  } catch {
1895
1912
  return void 0;
1896
1913
  }
1897
1914
  }
1898
1915
  function writeJson(file2, value) {
1899
- fs15.mkdirSync(path12.dirname(file2), { recursive: true });
1916
+ fs14.mkdirSync(path11.dirname(file2), { recursive: true });
1900
1917
  const tmp = uniqueTempPath(file2);
1901
- fs15.writeFileSync(tmp, JSON.stringify(value, null, 2));
1902
- fs15.renameSync(tmp, file2);
1918
+ fs14.writeFileSync(tmp, JSON.stringify(value, null, 2));
1919
+ atomicRenameSync(tmp, file2);
1903
1920
  }
1904
- var metaFile = (pool, slot) => path12.join(slotsDir(pool), `${slot}.json`);
1905
- var claimFile = (pool, slot) => path12.join(slotsDir(pool), `${slot}.claim.json`);
1906
- var outFile = (pool, slot) => path12.join(slotsDir(pool), `${slot}.out.json`);
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`);
1907
1924
  function readSlotMeta(pool, slot) {
1908
1925
  return readJson(metaFile(pool, slot)) ?? {};
1909
1926
  }
@@ -1923,7 +1940,7 @@ function writeSlotOut(pool, slot, out) {
1923
1940
  writeJson(outFile(pool, slot), out);
1924
1941
  }
1925
1942
  function clearSlotOut(pool, slot) {
1926
- fs15.rmSync(outFile(pool, slot), { force: true });
1943
+ fs14.rmSync(outFile(pool, slot), { force: true });
1927
1944
  }
1928
1945
  function dispatchHolder(dir) {
1929
1946
  const lock = readWorktreeLock(dir);
@@ -1933,7 +1950,7 @@ function poolSlotView(pool, slot) {
1933
1950
  const dir = poolSlotPath(pool, slot);
1934
1951
  const lastClaim = readSlotClaim(pool, slot)?.id;
1935
1952
  const base = { slot, path: dir, ...lastClaim ? { lastClaim } : {} };
1936
- if (!fs15.existsSync(dir)) {
1953
+ if (!fs14.existsSync(dir)) {
1937
1954
  const meta2 = readSlotMeta(pool, slot);
1938
1955
  return { ...base, state: "missing", ...meta2.error ? { reason: meta2.error } : {} };
1939
1956
  }
@@ -1948,8 +1965,8 @@ function poolSlotView(pool, slot) {
1948
1965
  return { ...base, state: "warming", ...meta.error ? { reason: meta.error } : {} };
1949
1966
  return { ...base, state: "free" };
1950
1967
  }
1951
- var warmStateFile = (pool) => path12.join(poolDir(pool), ".warm-state.json");
1952
- 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");
1953
1970
  var POOL_WARM_MAX_MS = 60 * 6e4;
1954
1971
  function readPoolWarmState(pool) {
1955
1972
  return readJson(warmStateFile(pool)) ?? {};
@@ -1971,15 +1988,15 @@ function poolWarmRunning(pool, now2 = Date.now()) {
1971
1988
  }
1972
1989
  function takePoolWarmLock(pool) {
1973
1990
  const file2 = warmLockFile(pool);
1974
- fs15.mkdirSync(path12.dirname(file2), { recursive: true });
1991
+ fs14.mkdirSync(path11.dirname(file2), { recursive: true });
1975
1992
  const mine = JSON.stringify({ pid: process.pid, at: (/* @__PURE__ */ new Date()).toISOString() });
1976
1993
  for (let attempt = 0; attempt < 2; attempt++) {
1977
1994
  try {
1978
- fs15.writeFileSync(file2, mine, { flag: "wx" });
1995
+ fs14.writeFileSync(file2, mine, { flag: "wx" });
1979
1996
  return () => {
1980
1997
  try {
1981
- if (fs15.readFileSync(file2, "utf8") === mine)
1982
- fs15.rmSync(file2, { force: true });
1998
+ if (fs14.readFileSync(file2, "utf8") === mine)
1999
+ fs14.rmSync(file2, { force: true });
1983
2000
  } catch {
1984
2001
  }
1985
2002
  };
@@ -1989,7 +2006,7 @@ function takePoolWarmLock(pool) {
1989
2006
  }
1990
2007
  if (poolWarmRunning(pool))
1991
2008
  return void 0;
1992
- fs15.rmSync(file2, { force: true });
2009
+ fs14.rmSync(file2, { force: true });
1993
2010
  }
1994
2011
  return void 0;
1995
2012
  }
@@ -1997,20 +2014,78 @@ var POOL_RETRY_MS = 10 * 6e4;
1997
2014
  var POOL_FETCH_MS = 10 * 6e4;
1998
2015
  var POOL_RECHECK_MS = 5 * 6e4;
1999
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
+
2000
2075
  // packages/core/dist/soak.js
2001
2076
  function regPath(trapId) {
2002
2077
  return path13.join(soakingDir(), `${trapId}.json`);
2003
2078
  }
2004
2079
  function readTrap(trapId) {
2005
2080
  try {
2006
- return JSON.parse(fs16.readFileSync(regPath(trapId), "utf8"));
2081
+ return JSON.parse(fs17.readFileSync(regPath(trapId), "utf8"));
2007
2082
  } catch {
2008
2083
  return void 0;
2009
2084
  }
2010
2085
  }
2011
2086
  function listTraps() {
2012
2087
  try {
2013
- 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");
2014
2089
  } catch {
2015
2090
  return [];
2016
2091
  }
@@ -2020,7 +2095,7 @@ function claimPath(id, lane) {
2020
2095
  }
2021
2096
  function readSessionClaim(id, lane) {
2022
2097
  try {
2023
- return JSON.parse(fs16.readFileSync(claimPath(id, lane), "utf8"));
2098
+ return JSON.parse(fs17.readFileSync(claimPath(id, lane), "utf8"));
2024
2099
  } catch {
2025
2100
  return void 0;
2026
2101
  }
@@ -2042,7 +2117,7 @@ function localDay(at = Date.now()) {
2042
2117
  function readCatchFacts(stateDir, id) {
2043
2118
  let last;
2044
2119
  try {
2045
- 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")) {
2046
2121
  if (!line.trim())
2047
2122
  continue;
2048
2123
  try {
@@ -2058,7 +2133,7 @@ function readCatchFacts(stateDir, id) {
2058
2133
  let trap;
2059
2134
  let worker = workerProfile();
2060
2135
  try {
2061
- 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"));
2062
2137
  const to = evidence.deliveredTo;
2063
2138
  if (typeof to === "string" && to.startsWith("wt:"))
2064
2139
  trap = to;
@@ -2131,7 +2206,7 @@ function add(store, facts, now2) {
2131
2206
  }
2132
2207
  function backfillSources() {
2133
2208
  const live = ["work", "chore"].map((lane) => ({ dir: laneDirs(lane).state, live: true }));
2134
- 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());
2135
2210
  return [...live, ...backups];
2136
2211
  }
2137
2212
  function backfillStats(now2 = Date.now(), alreadyCounted) {
@@ -2203,25 +2278,25 @@ function parseStore(text) {
2203
2278
  var complete2 = (s) => !!s && s.daily !== void 0;
2204
2279
  function writeStore(store) {
2205
2280
  const file2 = statsPath();
2206
- fs17.mkdirSync(path14.dirname(file2), { recursive: true });
2281
+ fs18.mkdirSync(path14.dirname(file2), { recursive: true });
2207
2282
  const tmp = uniqueTempPath(file2);
2208
- fs17.writeFileSync(tmp, JSON.stringify(store));
2209
- fs17.renameSync(tmp, file2);
2283
+ fs18.writeFileSync(tmp, JSON.stringify(store));
2284
+ atomicRenameSync(tmp, file2);
2210
2285
  }
2211
2286
  function withStatsLock(action) {
2212
- fs17.mkdirSync(lobstahHome(), { recursive: true });
2287
+ fs18.mkdirSync(lobstahHome(), { recursive: true });
2213
2288
  const lock = `${statsPath()}.lock`;
2214
2289
  const deadline = Date.now() + 1e4;
2215
2290
  for (; ; ) {
2216
2291
  try {
2217
- fs17.mkdirSync(lock);
2292
+ fs18.mkdirSync(lock);
2218
2293
  break;
2219
2294
  } catch (err) {
2220
2295
  if (err.code !== "EEXIST")
2221
2296
  throw err;
2222
2297
  try {
2223
- if (Date.now() - fs17.statSync(lock).mtimeMs > 12e4)
2224
- fs17.rmdirSync(lock);
2298
+ if (Date.now() - fs18.statSync(lock).mtimeMs > 12e4)
2299
+ fs18.rmdirSync(lock);
2225
2300
  } catch {
2226
2301
  }
2227
2302
  if (Date.now() >= deadline)
@@ -2232,13 +2307,13 @@ function withStatsLock(action) {
2232
2307
  try {
2233
2308
  return action();
2234
2309
  } finally {
2235
- fs17.rmdirSync(lock);
2310
+ fs18.rmdirSync(lock);
2236
2311
  }
2237
2312
  }
2238
2313
  function loadOrBackfill(now2) {
2239
2314
  let text;
2240
2315
  try {
2241
- text = fs17.readFileSync(statsPath(), "utf8");
2316
+ text = fs18.readFileSync(statsPath(), "utf8");
2242
2317
  } catch (err) {
2243
2318
  if (err.code !== "ENOENT")
2244
2319
  throw err;
@@ -2265,7 +2340,7 @@ function loadOrBackfill(now2) {
2265
2340
  return store2;
2266
2341
  }
2267
2342
  if (text !== void 0)
2268
- fs17.renameSync(statsPath(), `${statsPath()}.unreadable-${now2}`);
2343
+ fs18.renameSync(statsPath(), `${statsPath()}.unreadable-${now2}`);
2269
2344
  const store = backfillStats(now2);
2270
2345
  writeStore(store);
2271
2346
  return store;
@@ -2308,7 +2383,7 @@ var ANSWER_TYPES = {
2308
2383
  var ANSWER_EXTENSIONS = Object.keys(ANSWER_TYPES);
2309
2384
 
2310
2385
  // packages/core/dist/inbox.js
2311
- import * as fs18 from "node:fs";
2386
+ import * as fs19 from "node:fs";
2312
2387
  import * as path15 from "node:path";
2313
2388
  var metaName = (file2) => file2.replace(/\.msg$/, ".meta.json");
2314
2389
  function inboxDir(id, lane) {
@@ -2316,31 +2391,15 @@ function inboxDir(id, lane) {
2316
2391
  }
2317
2392
  function unhandled(id, lane) {
2318
2393
  const dir = inboxDir(id, lane);
2319
- 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") }));
2320
2395
  }
2321
2396
  function acknowledge(id, lane, file2) {
2322
2397
  const dir = inboxDir(id, lane);
2323
- fs18.mkdirSync(path15.join(dir, "handled"), { recursive: true });
2324
- fs18.renameSync(path15.join(dir, file2), path15.join(dir, "handled", file2));
2325
- try {
2326
- fs18.renameSync(path15.join(dir, metaName(file2)), path15.join(dir, "handled", metaName(file2)));
2327
- } catch {
2328
- }
2329
- }
2330
-
2331
- // packages/core/dist/events.js
2332
- import * as fs19 from "node:fs";
2333
- function appendEvent(id, lane, ev) {
2334
- fs19.appendFileSync(eventsPath(id, lane), `${JSON.stringify(ev)}
2335
- `);
2336
- }
2337
- function touchEvents(id, lane, at = /* @__PURE__ */ new Date()) {
2338
- 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));
2339
2400
  try {
2340
- fs19.utimesSync(file2, at, at);
2401
+ fs19.renameSync(path15.join(dir, metaName(file2)), path15.join(dir, "handled", metaName(file2)));
2341
2402
  } catch {
2342
- fs19.appendFileSync(file2, "");
2343
- fs19.utimesSync(file2, at, at);
2344
2403
  }
2345
2404
  }
2346
2405
 
@@ -4652,6 +4711,53 @@ async function main(activeDir, lane, seams = {}) {
4652
4711
 
4653
4712
  // packages/runner/src/reap.ts
4654
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
4655
4761
  function listProcesses() {
4656
4762
  if (process.platform === "win32") {
4657
4763
  const out2 = execFileSync3(
@@ -4660,7 +4766,7 @@ function listProcesses() {
4660
4766
  "-NoProfile",
4661
4767
  "-NonInteractive",
4662
4768
  "-Command",
4663
- 'Get-CimInstance Win32_Process | ForEach-Object { "$($_.ProcessId) $($_.ParentProcessId)" }'
4769
+ WINDOWS_PROCESS_SNAPSHOT
4664
4770
  ],
4665
4771
  { encoding: "utf8", windowsHide: true, timeout: 3e4, stdio: ["ignore", "pipe", "ignore"] }
4666
4772
  );