lobstah 0.8.0 → 0.8.2
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/main.js +3411 -2315
- package/dist/runner.js +652 -296
- package/docs/configuration.md +46 -9
- package/package.json +1 -1
package/dist/runner.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// packages/runner/src/index.ts
|
|
2
|
-
import * as
|
|
3
|
-
import * as
|
|
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
|
|
13
|
-
import * as
|
|
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
|
|
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
|
|
289
|
-
import * as
|
|
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
|
|
507
|
-
import * as
|
|
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
|
|
624
|
-
import * as
|
|
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
|
|
627
|
+
import * as fs7 from "node:fs";
|
|
628
628
|
import * as os2 from "node:os";
|
|
629
|
-
import * as
|
|
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,
|
|
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 ===
|
|
808
|
+
} else if (c === end || c === sep3) {
|
|
809
809
|
return;
|
|
810
810
|
}
|
|
811
811
|
}
|
|
@@ -1395,17 +1395,100 @@ function parseReviews(raw, reposRaw = {}) {
|
|
|
1395
1395
|
};
|
|
1396
1396
|
}
|
|
1397
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
|
+
|
|
1398
1471
|
// packages/core/dist/config.js
|
|
1399
1472
|
var TRAP_PERMISSION_MODES = ["auto", "bypass", "bypassPermissions", "default", "acceptEdits", "plan", "dontAsk"];
|
|
1400
|
-
function
|
|
1473
|
+
function parsePermissionDefaults(raw, where) {
|
|
1401
1474
|
if (raw === void 0)
|
|
1402
1475
|
return void 0;
|
|
1476
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
1477
|
+
throw new Error(`${where} must be a table`);
|
|
1403
1478
|
const h = raw;
|
|
1404
|
-
if (h.permissionMode !== void 0 && !TRAP_PERMISSION_MODES.includes(
|
|
1479
|
+
if (h.permissionMode !== void 0 && (typeof h.permissionMode !== "string" || !TRAP_PERMISSION_MODES.includes(h.permissionMode))) {
|
|
1405
1480
|
throw new Error(`${where}.permissionMode must be one of ${TRAP_PERMISSION_MODES.join(", ")}`);
|
|
1406
1481
|
}
|
|
1407
1482
|
return h;
|
|
1408
1483
|
}
|
|
1484
|
+
function parseHarness(raw, where) {
|
|
1485
|
+
const defaults = parsePermissionDefaults(raw, where);
|
|
1486
|
+
if (defaults)
|
|
1487
|
+
for (const harness of ["claude", "codex"]) {
|
|
1488
|
+
parsePermissionDefaults(defaults[harness], `${where.slice(0, -1)}.${harness}]`);
|
|
1489
|
+
}
|
|
1490
|
+
return defaults;
|
|
1491
|
+
}
|
|
1409
1492
|
var POOL_NAME = /^[A-Za-z0-9_-]+$/;
|
|
1410
1493
|
function parsePools(raw, repos) {
|
|
1411
1494
|
const out = {};
|
|
@@ -1566,7 +1649,9 @@ var DEFAULT_HELM = {
|
|
|
1566
1649
|
ttlSecs: 1800,
|
|
1567
1650
|
reportSecs: 900,
|
|
1568
1651
|
armGraceSecs: 5,
|
|
1569
|
-
todoStaleDays: 3
|
|
1652
|
+
todoStaleDays: 3,
|
|
1653
|
+
briefTodoLimit: 5,
|
|
1654
|
+
goalsNudgeSecs: 7200
|
|
1570
1655
|
};
|
|
1571
1656
|
var DEFAULT_GLASS = { port: 4949 };
|
|
1572
1657
|
var DEFAULT_WAIT = { baseTimeoutSecs: 900, baseRepeats: 3, maxTimeoutSecs: 14400 };
|
|
@@ -1586,6 +1671,7 @@ var DEFAULT_LIMITS = {
|
|
|
1586
1671
|
attachmentMaxBytes: 25 * 1024 * 1024,
|
|
1587
1672
|
retentionDays: 0,
|
|
1588
1673
|
minFreeGB: 0,
|
|
1674
|
+
cacheMinFreeGB: 50,
|
|
1589
1675
|
reuseWorktree: true,
|
|
1590
1676
|
releaseOnMerge: false
|
|
1591
1677
|
};
|
|
@@ -1597,14 +1683,17 @@ function withConfigPath(parse2) {
|
|
|
1597
1683
|
}
|
|
1598
1684
|
}
|
|
1599
1685
|
function configPath() {
|
|
1600
|
-
return
|
|
1686
|
+
return path6.join(lobstahHome(), "config.toml");
|
|
1601
1687
|
}
|
|
1602
1688
|
function expandHome(p) {
|
|
1603
|
-
return p.startsWith("~/") ?
|
|
1689
|
+
return p.startsWith("~/") ? path6.join(os2.homedir(), p.slice(2)) : p;
|
|
1604
1690
|
}
|
|
1605
1691
|
function loadConfig() {
|
|
1606
1692
|
const file2 = configPath();
|
|
1607
|
-
const raw =
|
|
1693
|
+
const raw = fs7.existsSync(file2) ? parse(fs7.readFileSync(file2, "utf8")) : {};
|
|
1694
|
+
const cacheMinFreeGB = raw.limits?.cacheMinFreeGB ?? DEFAULT_LIMITS.cacheMinFreeGB;
|
|
1695
|
+
if (typeof cacheMinFreeGB !== "number" || !Number.isFinite(cacheMinFreeGB) || cacheMinFreeGB < 0)
|
|
1696
|
+
throw new Error("[limits].cacheMinFreeGB must be a non-negative number");
|
|
1608
1697
|
const petOpen = raw.pet?.open ?? "tab";
|
|
1609
1698
|
if (!["tab", "app", "helm"].includes(petOpen))
|
|
1610
1699
|
throw new Error(`[pet].open must be "tab", "app", or "helm" in ${configPath()}`);
|
|
@@ -1612,6 +1701,10 @@ function loadConfig() {
|
|
|
1612
1701
|
const helm = { ...DEFAULT_HELM, ...raw.helm ?? {} };
|
|
1613
1702
|
if (helm.chat !== "full" && helm.chat !== "brief")
|
|
1614
1703
|
throw new Error('[helm].chat must be "full" or "brief"');
|
|
1704
|
+
for (const key of ["briefTodoLimit", "goalsNudgeSecs"]) {
|
|
1705
|
+
if (typeof helm[key] !== "number" || !Number.isSafeInteger(helm[key]) || helm[key] < 0)
|
|
1706
|
+
throw new Error(`[helm].${key} must be a non-negative whole number in ${configPath()}`);
|
|
1707
|
+
}
|
|
1615
1708
|
const wait = { ...DEFAULT_WAIT, ...raw.wait ?? {} };
|
|
1616
1709
|
for (const key of ["baseTimeoutSecs", "baseRepeats", "maxTimeoutSecs"]) {
|
|
1617
1710
|
if (typeof wait[key] !== "number" || !Number.isSafeInteger(wait[key]) || wait[key] <= 0)
|
|
@@ -1644,6 +1737,8 @@ function loadConfig() {
|
|
|
1644
1737
|
refuseMoved(raw, reposRaw);
|
|
1645
1738
|
const repos = {};
|
|
1646
1739
|
for (const [key, r] of Object.entries(reposRaw)) {
|
|
1740
|
+
if (r.cacheDirs !== void 0 && (!Array.isArray(r.cacheDirs) || r.cacheDirs.some((glob) => typeof glob !== "string" || !validCacheGlob(glob))))
|
|
1741
|
+
throw new Error(`[repos.${key}].cacheDirs must be relative globs inside the worktree, without .. or absolute paths`);
|
|
1647
1742
|
if (r.traps !== void 0 && (typeof r.traps !== "number" || !Number.isSafeInteger(r.traps) || r.traps < 0)) {
|
|
1648
1743
|
throw new Error(`[repos.${key}].traps must be a non-negative whole number`);
|
|
1649
1744
|
}
|
|
@@ -1656,6 +1751,7 @@ function loadConfig() {
|
|
|
1656
1751
|
origin: r.origin ? String(r.origin) : void 0,
|
|
1657
1752
|
trunk: String(r.trunk ?? "main"),
|
|
1658
1753
|
setup: Array.isArray(r.setup) ? r.setup.map(String) : void 0,
|
|
1754
|
+
cacheDirs: r.cacheDirs,
|
|
1659
1755
|
env: r.env ?? void 0,
|
|
1660
1756
|
harness: parseHarness(r.harness, `[repos.${key}.harness]`),
|
|
1661
1757
|
pickup: r.pickup === void 0 ? void 0 : Boolean(r.pickup),
|
|
@@ -1743,25 +1839,25 @@ function firstMeaningfulLine(...outputs) {
|
|
|
1743
1839
|
}
|
|
1744
1840
|
|
|
1745
1841
|
// packages/core/dist/pr-poll.js
|
|
1746
|
-
import * as
|
|
1747
|
-
import * as
|
|
1842
|
+
import * as fs11 from "node:fs";
|
|
1843
|
+
import * as path10 from "node:path";
|
|
1748
1844
|
|
|
1749
1845
|
// packages/core/dist/prs.js
|
|
1750
|
-
import * as
|
|
1751
|
-
import * as
|
|
1846
|
+
import * as fs8 from "node:fs";
|
|
1847
|
+
import * as path7 from "node:path";
|
|
1752
1848
|
function prsDir() {
|
|
1753
|
-
return
|
|
1849
|
+
return path7.join(lobstahHome(), "prs");
|
|
1754
1850
|
}
|
|
1755
1851
|
function prRecordFile(key) {
|
|
1756
1852
|
const ref = parsePrRef(key);
|
|
1757
1853
|
if (!ref)
|
|
1758
1854
|
throw new Error(`not a PR key: ${key}`);
|
|
1759
1855
|
const safe = (s) => s.replace(/[^A-Za-z0-9._-]/g, "_");
|
|
1760
|
-
return
|
|
1856
|
+
return path7.join(prsDir(), `${safe(ref.owner)}__${safe(ref.repo)}__${ref.number}.json`);
|
|
1761
1857
|
}
|
|
1762
1858
|
function readPr(key) {
|
|
1763
1859
|
try {
|
|
1764
|
-
return JSON.parse(
|
|
1860
|
+
return JSON.parse(fs8.readFileSync(prRecordFile(key), "utf8"));
|
|
1765
1861
|
} catch {
|
|
1766
1862
|
return void 0;
|
|
1767
1863
|
}
|
|
@@ -1769,13 +1865,13 @@ function readPr(key) {
|
|
|
1769
1865
|
function readPrs() {
|
|
1770
1866
|
let files;
|
|
1771
1867
|
try {
|
|
1772
|
-
files =
|
|
1868
|
+
files = fs8.readdirSync(prsDir()).filter((f) => f.endsWith(".json"));
|
|
1773
1869
|
} catch {
|
|
1774
1870
|
return [];
|
|
1775
1871
|
}
|
|
1776
1872
|
return files.flatMap((f) => {
|
|
1777
1873
|
try {
|
|
1778
|
-
const r = JSON.parse(
|
|
1874
|
+
const r = JSON.parse(fs8.readFileSync(path7.join(prsDir(), f), "utf8"));
|
|
1779
1875
|
return typeof r.key === "string" && typeof r.url === "string" ? [r] : [];
|
|
1780
1876
|
} catch {
|
|
1781
1877
|
return [];
|
|
@@ -1784,16 +1880,16 @@ function readPrs() {
|
|
|
1784
1880
|
}
|
|
1785
1881
|
|
|
1786
1882
|
// packages/core/dist/watch.js
|
|
1787
|
-
import
|
|
1788
|
-
import * as
|
|
1883
|
+
import fs10 from "node:fs";
|
|
1884
|
+
import * as path9 from "node:path";
|
|
1789
1885
|
|
|
1790
1886
|
// packages/core/dist/github-budget.js
|
|
1791
|
-
import * as
|
|
1792
|
-
import * as
|
|
1793
|
-
var file = () =>
|
|
1887
|
+
import * as fs9 from "node:fs";
|
|
1888
|
+
import * as path8 from "node:path";
|
|
1889
|
+
var file = () => path8.join(lobstahHome(), "github-budget.json");
|
|
1794
1890
|
function read() {
|
|
1795
1891
|
try {
|
|
1796
|
-
return JSON.parse(
|
|
1892
|
+
return JSON.parse(fs9.readFileSync(file(), "utf8"));
|
|
1797
1893
|
} catch {
|
|
1798
1894
|
return { resources: {} };
|
|
1799
1895
|
}
|
|
@@ -1807,27 +1903,27 @@ function githubBlockedUntil(now2 = Date.now()) {
|
|
|
1807
1903
|
|
|
1808
1904
|
// packages/core/dist/watch.js
|
|
1809
1905
|
function watchesDir() {
|
|
1810
|
-
return
|
|
1906
|
+
return path9.join(lobstahHome(), "watches");
|
|
1811
1907
|
}
|
|
1812
1908
|
function slug(key) {
|
|
1813
1909
|
return key.replace(/[^A-Za-z0-9._-]+/g, "-");
|
|
1814
1910
|
}
|
|
1815
1911
|
function watchPath(key) {
|
|
1816
|
-
return
|
|
1912
|
+
return path9.join(watchesDir(), `${slug(key)}.json`);
|
|
1817
1913
|
}
|
|
1818
1914
|
function readWatch(key) {
|
|
1819
1915
|
try {
|
|
1820
|
-
return JSON.parse(
|
|
1916
|
+
return JSON.parse(fs10.readFileSync(watchPath(key), "utf8"));
|
|
1821
1917
|
} catch {
|
|
1822
1918
|
return void 0;
|
|
1823
1919
|
}
|
|
1824
1920
|
}
|
|
1825
1921
|
|
|
1826
1922
|
// packages/core/dist/pr-poll.js
|
|
1827
|
-
var cycleFile = (repo) =>
|
|
1923
|
+
var cycleFile = (repo) => path10.join(lobstahHome(), "pr-polls", `${repo.replace(/[^\w.-]/g, "_")}.json`);
|
|
1828
1924
|
var readCycle = (repo) => {
|
|
1829
1925
|
try {
|
|
1830
|
-
return JSON.parse(
|
|
1926
|
+
return JSON.parse(fs11.readFileSync(cycleFile(repo), "utf8"));
|
|
1831
1927
|
} catch {
|
|
1832
1928
|
return void 0;
|
|
1833
1929
|
}
|
|
@@ -1920,23 +2016,23 @@ function parseUnresolvedThreads(stdout) {
|
|
|
1920
2016
|
}
|
|
1921
2017
|
|
|
1922
2018
|
// packages/core/dist/worktrees.js
|
|
1923
|
-
import * as
|
|
1924
|
-
import * as
|
|
2019
|
+
import * as fs12 from "node:fs";
|
|
2020
|
+
import * as path11 from "node:path";
|
|
1925
2021
|
var LANES = ["work", "chore"];
|
|
1926
2022
|
function worktreePath(id) {
|
|
1927
|
-
return
|
|
2023
|
+
return path11.join(lobstahHome(), "worktrees", id);
|
|
1928
2024
|
}
|
|
1929
2025
|
function readRecord(file2) {
|
|
1930
2026
|
try {
|
|
1931
|
-
const r = JSON.parse(
|
|
2027
|
+
const r = JSON.parse(fs12.readFileSync(file2, "utf8"));
|
|
1932
2028
|
return typeof r.path === "string" ? r : void 0;
|
|
1933
2029
|
} catch {
|
|
1934
2030
|
return void 0;
|
|
1935
2031
|
}
|
|
1936
2032
|
}
|
|
1937
2033
|
function ownerOfPath(p) {
|
|
1938
|
-
const rel =
|
|
1939
|
-
if (!rel || rel.startsWith("..") ||
|
|
2034
|
+
const rel = path11.relative(path11.join(lobstahHome(), "worktrees"), p);
|
|
2035
|
+
if (!rel || rel.startsWith("..") || path11.isAbsolute(rel))
|
|
1940
2036
|
return void 0;
|
|
1941
2037
|
return rel.split(/[\\/]/)[0];
|
|
1942
2038
|
}
|
|
@@ -1949,7 +2045,7 @@ function dispatchWorktree(id, lane) {
|
|
|
1949
2045
|
}
|
|
1950
2046
|
const dirs = laneDirs(l);
|
|
1951
2047
|
for (const dir of [dirs.active, dirs.done]) {
|
|
1952
|
-
const rec = readRecord(
|
|
2048
|
+
const rec = readRecord(path11.join(dir, id, "worktree.json"));
|
|
1953
2049
|
if (rec) {
|
|
1954
2050
|
const owner = rec.of ?? ownerOfPath(rec.path) ?? id;
|
|
1955
2051
|
return { path: rec.path, owner, reused: owner !== id };
|
|
@@ -1961,7 +2057,7 @@ function dispatchWorktree(id, lane) {
|
|
|
1961
2057
|
function laneOf(id) {
|
|
1962
2058
|
for (const l of LANES) {
|
|
1963
2059
|
const d = laneDirs(l);
|
|
1964
|
-
if (
|
|
2060
|
+
if (fs12.existsSync(path11.join(d.queue, `${id}.json`)) || fs12.existsSync(path11.join(d.active, id)) || fs12.existsSync(path11.join(d.done, id))) {
|
|
1965
2061
|
return l;
|
|
1966
2062
|
}
|
|
1967
2063
|
}
|
|
@@ -1981,7 +2077,7 @@ function followUpAncestors(id, lane) {
|
|
|
1981
2077
|
function chainWorktree(followUp) {
|
|
1982
2078
|
for (const id of [followUp, ...followUpAncestors(followUp)]) {
|
|
1983
2079
|
const wt = dispatchWorktree(id, laneOf(id));
|
|
1984
|
-
if (
|
|
2080
|
+
if (fs12.existsSync(wt.path))
|
|
1985
2081
|
return { ...wt, from: id };
|
|
1986
2082
|
}
|
|
1987
2083
|
return void 0;
|
|
@@ -1996,27 +2092,27 @@ function processAlive(pid) {
|
|
|
1996
2092
|
}
|
|
1997
2093
|
}
|
|
1998
2094
|
function worktreeGitDir(wt) {
|
|
1999
|
-
const dotGit =
|
|
2095
|
+
const dotGit = path11.join(wt, ".git");
|
|
2000
2096
|
try {
|
|
2001
|
-
const st =
|
|
2097
|
+
const st = fs12.statSync(dotGit);
|
|
2002
2098
|
if (st.isDirectory())
|
|
2003
2099
|
return dotGit;
|
|
2004
|
-
const m = /^gitdir:\s*(.+?)\s*$/m.exec(
|
|
2005
|
-
return m ?
|
|
2100
|
+
const m = /^gitdir:\s*(.+?)\s*$/m.exec(fs12.readFileSync(dotGit, "utf8"));
|
|
2101
|
+
return m ? path11.resolve(wt, m[1]) : void 0;
|
|
2006
2102
|
} catch {
|
|
2007
2103
|
return void 0;
|
|
2008
2104
|
}
|
|
2009
2105
|
}
|
|
2010
2106
|
function worktreeLockFile(wt) {
|
|
2011
2107
|
const gitDir = worktreeGitDir(wt);
|
|
2012
|
-
return gitDir ?
|
|
2108
|
+
return gitDir ? path11.join(gitDir, "lobstah.lock") : void 0;
|
|
2013
2109
|
}
|
|
2014
2110
|
function readWorktreeLock(wt) {
|
|
2015
2111
|
const file2 = worktreeLockFile(wt);
|
|
2016
2112
|
if (!file2)
|
|
2017
2113
|
return void 0;
|
|
2018
2114
|
try {
|
|
2019
|
-
return JSON.parse(
|
|
2115
|
+
return JSON.parse(fs12.readFileSync(file2, "utf8"));
|
|
2020
2116
|
} catch {
|
|
2021
2117
|
return void 0;
|
|
2022
2118
|
}
|
|
@@ -2024,7 +2120,7 @@ function readWorktreeLock(wt) {
|
|
|
2024
2120
|
function lockIsLive(lock) {
|
|
2025
2121
|
if (lock.kind === "warm")
|
|
2026
2122
|
return processAlive(lock.pid) && Date.now() - (Date.parse(lock.at) || 0) < WARM_LOCK_MAX_MS;
|
|
2027
|
-
return
|
|
2123
|
+
return fs12.existsSync(path11.join(laneDirs(lock.lane).active, lock.id));
|
|
2028
2124
|
}
|
|
2029
2125
|
function worktreeHolder(wt) {
|
|
2030
2126
|
const lock = readWorktreeLock(wt);
|
|
@@ -2037,7 +2133,7 @@ function acquireWorktreeLock(wt, id, lane, kind) {
|
|
|
2037
2133
|
return { id: "(no git dir)", lane, pid: 0, at: mine.at };
|
|
2038
2134
|
for (let attempt2 = 0; attempt2 < 3; attempt2++) {
|
|
2039
2135
|
try {
|
|
2040
|
-
|
|
2136
|
+
fs12.writeFileSync(file2, JSON.stringify(mine, null, 2), { flag: "wx" });
|
|
2041
2137
|
return void 0;
|
|
2042
2138
|
} catch (err) {
|
|
2043
2139
|
if (err.code !== "EEXIST")
|
|
@@ -2045,7 +2141,7 @@ function acquireWorktreeLock(wt, id, lane, kind) {
|
|
|
2045
2141
|
}
|
|
2046
2142
|
let raw;
|
|
2047
2143
|
try {
|
|
2048
|
-
raw =
|
|
2144
|
+
raw = fs12.readFileSync(file2, "utf8");
|
|
2049
2145
|
} catch {
|
|
2050
2146
|
continue;
|
|
2051
2147
|
}
|
|
@@ -2056,14 +2152,14 @@ function acquireWorktreeLock(wt, id, lane, kind) {
|
|
|
2056
2152
|
held2 = void 0;
|
|
2057
2153
|
}
|
|
2058
2154
|
if (held2?.id === id) {
|
|
2059
|
-
|
|
2155
|
+
fs12.writeFileSync(file2, JSON.stringify(mine, null, 2));
|
|
2060
2156
|
return void 0;
|
|
2061
2157
|
}
|
|
2062
2158
|
if (held2 && lockIsLive(held2))
|
|
2063
2159
|
return held2;
|
|
2064
2160
|
try {
|
|
2065
|
-
if (
|
|
2066
|
-
|
|
2161
|
+
if (fs12.readFileSync(file2, "utf8") === raw)
|
|
2162
|
+
fs12.rmSync(file2, { force: true });
|
|
2067
2163
|
} catch {
|
|
2068
2164
|
}
|
|
2069
2165
|
}
|
|
@@ -2075,22 +2171,22 @@ function releaseWorktreeLock(wt, id) {
|
|
|
2075
2171
|
if (!file2)
|
|
2076
2172
|
return;
|
|
2077
2173
|
if (readWorktreeLock(wt)?.id === id)
|
|
2078
|
-
|
|
2174
|
+
fs12.rmSync(file2, { force: true });
|
|
2079
2175
|
}
|
|
2080
2176
|
|
|
2081
2177
|
// packages/core/dist/events.js
|
|
2082
|
-
import * as
|
|
2178
|
+
import * as fs13 from "node:fs";
|
|
2083
2179
|
function appendEvent(id, lane, ev) {
|
|
2084
|
-
|
|
2180
|
+
fs13.appendFileSync(eventsPath(id, lane), `${JSON.stringify(ev)}
|
|
2085
2181
|
`);
|
|
2086
2182
|
}
|
|
2087
2183
|
function touchEvents(id, lane, at = /* @__PURE__ */ new Date()) {
|
|
2088
2184
|
const file2 = eventsPath(id, lane);
|
|
2089
2185
|
try {
|
|
2090
|
-
|
|
2186
|
+
fs13.utimesSync(file2, at, at);
|
|
2091
2187
|
} catch {
|
|
2092
|
-
|
|
2093
|
-
|
|
2188
|
+
fs13.appendFileSync(file2, "");
|
|
2189
|
+
fs13.utimesSync(file2, at, at);
|
|
2094
2190
|
}
|
|
2095
2191
|
}
|
|
2096
2192
|
|
|
@@ -2104,31 +2200,31 @@ function isFinished(id, lane) {
|
|
|
2104
2200
|
}
|
|
2105
2201
|
|
|
2106
2202
|
// packages/core/dist/pools.js
|
|
2107
|
-
import * as
|
|
2108
|
-
import * as
|
|
2203
|
+
import * as fs14 from "node:fs";
|
|
2204
|
+
import * as path12 from "node:path";
|
|
2109
2205
|
function poolsRoot() {
|
|
2110
|
-
return
|
|
2206
|
+
return path12.join(lobstahHome(), "pools");
|
|
2111
2207
|
}
|
|
2112
2208
|
function poolDir(pool) {
|
|
2113
|
-
return
|
|
2209
|
+
return path12.join(poolsRoot(), pool);
|
|
2114
2210
|
}
|
|
2115
2211
|
function poolSlotPath(pool, slot) {
|
|
2116
|
-
return
|
|
2212
|
+
return path12.join(poolDir(pool), String(slot));
|
|
2117
2213
|
}
|
|
2118
2214
|
function slotsDir(pool) {
|
|
2119
|
-
return
|
|
2215
|
+
return path12.join(poolDir(pool), ".slots");
|
|
2120
2216
|
}
|
|
2121
2217
|
function poolSlotOf(p) {
|
|
2122
2218
|
const real = (x) => {
|
|
2123
2219
|
try {
|
|
2124
|
-
return
|
|
2220
|
+
return fs14.realpathSync.native(x);
|
|
2125
2221
|
} catch {
|
|
2126
|
-
return
|
|
2222
|
+
return path12.resolve(x);
|
|
2127
2223
|
}
|
|
2128
2224
|
};
|
|
2129
|
-
for (const [rootDir, dir] of [[poolsRoot(),
|
|
2130
|
-
const rel =
|
|
2131
|
-
if (!rel || rel.startsWith("..") ||
|
|
2225
|
+
for (const [rootDir, dir] of [[poolsRoot(), path12.resolve(p)], [real(poolsRoot()), real(p)]]) {
|
|
2226
|
+
const rel = path12.relative(rootDir, dir);
|
|
2227
|
+
if (!rel || rel.startsWith("..") || path12.isAbsolute(rel))
|
|
2132
2228
|
continue;
|
|
2133
2229
|
const parts = rel.split(/[\\/]/);
|
|
2134
2230
|
if (parts.length !== 2 || !/^[1-9][0-9]*$/.test(parts[1]))
|
|
@@ -2142,20 +2238,20 @@ function poolSlotLabel(pool, slot) {
|
|
|
2142
2238
|
}
|
|
2143
2239
|
function readJson(file2) {
|
|
2144
2240
|
try {
|
|
2145
|
-
return JSON.parse(
|
|
2241
|
+
return JSON.parse(fs14.readFileSync(file2, "utf8"));
|
|
2146
2242
|
} catch {
|
|
2147
2243
|
return void 0;
|
|
2148
2244
|
}
|
|
2149
2245
|
}
|
|
2150
2246
|
function writeJson(file2, value) {
|
|
2151
|
-
|
|
2247
|
+
fs14.mkdirSync(path12.dirname(file2), { recursive: true });
|
|
2152
2248
|
const tmp = uniqueTempPath(file2);
|
|
2153
|
-
|
|
2249
|
+
fs14.writeFileSync(tmp, JSON.stringify(value, null, 2));
|
|
2154
2250
|
atomicRenameSync(tmp, file2);
|
|
2155
2251
|
}
|
|
2156
|
-
var metaFile = (pool, slot) =>
|
|
2157
|
-
var claimFile = (pool, slot) =>
|
|
2158
|
-
var outFile = (pool, slot) =>
|
|
2252
|
+
var metaFile = (pool, slot) => path12.join(slotsDir(pool), `${slot}.json`);
|
|
2253
|
+
var claimFile = (pool, slot) => path12.join(slotsDir(pool), `${slot}.claim.json`);
|
|
2254
|
+
var outFile = (pool, slot) => path12.join(slotsDir(pool), `${slot}.out.json`);
|
|
2159
2255
|
function readSlotMeta(pool, slot) {
|
|
2160
2256
|
return readJson(metaFile(pool, slot)) ?? {};
|
|
2161
2257
|
}
|
|
@@ -2175,7 +2271,7 @@ function writeSlotOut(pool, slot, out) {
|
|
|
2175
2271
|
writeJson(outFile(pool, slot), out);
|
|
2176
2272
|
}
|
|
2177
2273
|
function clearSlotOut(pool, slot) {
|
|
2178
|
-
|
|
2274
|
+
fs14.rmSync(outFile(pool, slot), { force: true });
|
|
2179
2275
|
}
|
|
2180
2276
|
function dispatchHolder(dir) {
|
|
2181
2277
|
const lock = readWorktreeLock(dir);
|
|
@@ -2185,7 +2281,7 @@ function poolSlotView(pool, slot) {
|
|
|
2185
2281
|
const dir = poolSlotPath(pool, slot);
|
|
2186
2282
|
const lastClaim = readSlotClaim(pool, slot)?.id;
|
|
2187
2283
|
const base = { slot, path: dir, ...lastClaim ? { lastClaim } : {} };
|
|
2188
|
-
if (!
|
|
2284
|
+
if (!fs14.existsSync(dir)) {
|
|
2189
2285
|
const meta2 = readSlotMeta(pool, slot);
|
|
2190
2286
|
return { ...base, state: "missing", ...meta2.error ? { reason: meta2.error } : {} };
|
|
2191
2287
|
}
|
|
@@ -2200,8 +2296,8 @@ function poolSlotView(pool, slot) {
|
|
|
2200
2296
|
return { ...base, state: "warming", ...meta.error ? { reason: meta.error } : {} };
|
|
2201
2297
|
return { ...base, state: "free" };
|
|
2202
2298
|
}
|
|
2203
|
-
var warmStateFile = (pool) =>
|
|
2204
|
-
var warmLockFile = (pool) =>
|
|
2299
|
+
var warmStateFile = (pool) => path12.join(poolDir(pool), ".warm-state.json");
|
|
2300
|
+
var warmLockFile = (pool) => path12.join(poolDir(pool), ".warm.lock");
|
|
2205
2301
|
var POOL_WARM_MAX_MS = 60 * 6e4;
|
|
2206
2302
|
function readPoolWarmState(pool) {
|
|
2207
2303
|
return readJson(warmStateFile(pool)) ?? {};
|
|
@@ -2223,15 +2319,15 @@ function poolWarmRunning(pool, now2 = Date.now()) {
|
|
|
2223
2319
|
}
|
|
2224
2320
|
function takePoolWarmLock(pool) {
|
|
2225
2321
|
const file2 = warmLockFile(pool);
|
|
2226
|
-
|
|
2322
|
+
fs14.mkdirSync(path12.dirname(file2), { recursive: true });
|
|
2227
2323
|
const mine = JSON.stringify({ pid: process.pid, at: (/* @__PURE__ */ new Date()).toISOString() });
|
|
2228
2324
|
for (let attempt2 = 0; attempt2 < 2; attempt2++) {
|
|
2229
2325
|
try {
|
|
2230
|
-
|
|
2326
|
+
fs14.writeFileSync(file2, mine, { flag: "wx" });
|
|
2231
2327
|
return () => {
|
|
2232
2328
|
try {
|
|
2233
|
-
if (
|
|
2234
|
-
|
|
2329
|
+
if (fs14.readFileSync(file2, "utf8") === mine)
|
|
2330
|
+
fs14.rmSync(file2, { force: true });
|
|
2235
2331
|
} catch {
|
|
2236
2332
|
}
|
|
2237
2333
|
};
|
|
@@ -2241,7 +2337,7 @@ function takePoolWarmLock(pool) {
|
|
|
2241
2337
|
}
|
|
2242
2338
|
if (poolWarmRunning(pool))
|
|
2243
2339
|
return void 0;
|
|
2244
|
-
|
|
2340
|
+
fs14.rmSync(file2, { force: true });
|
|
2245
2341
|
}
|
|
2246
2342
|
return void 0;
|
|
2247
2343
|
}
|
|
@@ -2250,41 +2346,70 @@ var POOL_FETCH_MS = 10 * 6e4;
|
|
|
2250
2346
|
var POOL_RECHECK_MS = 5 * 6e4;
|
|
2251
2347
|
|
|
2252
2348
|
// packages/core/dist/disk.js
|
|
2253
|
-
import * as
|
|
2349
|
+
import * as fs15 from "node:fs";
|
|
2254
2350
|
var GB = 1024 ** 3;
|
|
2255
2351
|
var statfsFreeBytes = (dir) => {
|
|
2256
|
-
const s =
|
|
2352
|
+
const s = fs15.statfsSync(dir);
|
|
2257
2353
|
return Number(s.bavail) * Number(s.bsize);
|
|
2258
2354
|
};
|
|
2259
2355
|
function formatGB(bytes) {
|
|
2260
2356
|
return `${(bytes / GB).toFixed(1).replace(/\.0$/, "")} GB`;
|
|
2261
2357
|
}
|
|
2262
2358
|
|
|
2359
|
+
// packages/core/dist/roster.js
|
|
2360
|
+
import * as fs16 from "node:fs";
|
|
2361
|
+
import * as path13 from "node:path";
|
|
2362
|
+
function rosterDir() {
|
|
2363
|
+
return path13.join(lobstahHome(), "roster");
|
|
2364
|
+
}
|
|
2365
|
+
function rosterPath(trapId) {
|
|
2366
|
+
return path13.join(rosterDir(), `${trapId}.json`);
|
|
2367
|
+
}
|
|
2368
|
+
function readRoster(trapId) {
|
|
2369
|
+
if (!/^[a-z0-9-]+$/.test(trapId))
|
|
2370
|
+
return void 0;
|
|
2371
|
+
try {
|
|
2372
|
+
const parsed = JSON.parse(fs16.readFileSync(rosterPath(trapId), "utf8"));
|
|
2373
|
+
return parsed.trapId === trapId && typeof parsed.name === "string" ? parsed : void 0;
|
|
2374
|
+
} catch {
|
|
2375
|
+
return void 0;
|
|
2376
|
+
}
|
|
2377
|
+
}
|
|
2378
|
+
function listRoster() {
|
|
2379
|
+
let files;
|
|
2380
|
+
try {
|
|
2381
|
+
files = fs16.readdirSync(rosterDir()).filter((f) => f.endsWith(".json"));
|
|
2382
|
+
} catch {
|
|
2383
|
+
return [];
|
|
2384
|
+
}
|
|
2385
|
+
return files.map((f) => readRoster(f.slice(0, -".json".length))).filter((e) => e !== void 0).sort((a, b) => a.name.localeCompare(b.name));
|
|
2386
|
+
}
|
|
2387
|
+
|
|
2263
2388
|
// packages/core/dist/inbox.js
|
|
2264
|
-
import * as
|
|
2265
|
-
import * as
|
|
2389
|
+
import * as fs17 from "node:fs";
|
|
2390
|
+
import * as path14 from "node:path";
|
|
2266
2391
|
var metaName = (file2) => file2.replace(/\.msg$/, ".meta.json");
|
|
2267
2392
|
function inboxDir(id, lane) {
|
|
2268
|
-
return
|
|
2393
|
+
return path14.join(laneDirs(lane).inbox, id);
|
|
2269
2394
|
}
|
|
2270
2395
|
function unhandled(id, lane) {
|
|
2271
2396
|
const dir = inboxDir(id, lane);
|
|
2272
|
-
return readDirIfPresent(dir).filter((f) => f.endsWith(".msg")).sort().map((f) => ({ file: f, text:
|
|
2397
|
+
return readDirIfPresent(dir).filter((f) => f.endsWith(".msg")).sort().map((f) => ({ file: f, text: fs17.readFileSync(path14.join(dir, f), "utf8") }));
|
|
2273
2398
|
}
|
|
2274
2399
|
function acknowledge(id, lane, file2) {
|
|
2275
2400
|
const dir = inboxDir(id, lane);
|
|
2276
|
-
|
|
2277
|
-
|
|
2401
|
+
fs17.mkdirSync(path14.join(dir, "handled"), { recursive: true });
|
|
2402
|
+
fs17.renameSync(path14.join(dir, file2), path14.join(dir, "handled", file2));
|
|
2278
2403
|
try {
|
|
2279
|
-
|
|
2404
|
+
fs17.renameSync(path14.join(dir, metaName(file2)), path14.join(dir, "handled", metaName(file2)));
|
|
2280
2405
|
} catch {
|
|
2281
2406
|
}
|
|
2282
2407
|
}
|
|
2283
2408
|
|
|
2284
2409
|
// packages/core/dist/resume.js
|
|
2285
|
-
import * as
|
|
2410
|
+
import * as fs18 from "node:fs";
|
|
2286
2411
|
import * as os3 from "node:os";
|
|
2287
|
-
import * as
|
|
2412
|
+
import * as path15 from "node:path";
|
|
2288
2413
|
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
2289
2414
|
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;
|
|
2290
2415
|
function harnessFromSessionId(sessionId) {
|
|
@@ -2295,7 +2420,7 @@ function claimOf(id, lane) {
|
|
|
2295
2420
|
const dirs = laneDirs(lane);
|
|
2296
2421
|
for (const dir of [dirs.active, dirs.done]) {
|
|
2297
2422
|
try {
|
|
2298
|
-
return JSON.parse(
|
|
2423
|
+
return JSON.parse(fs18.readFileSync(path15.join(dir, id, "claim.json"), "utf8"));
|
|
2299
2424
|
} catch {
|
|
2300
2425
|
}
|
|
2301
2426
|
}
|
|
@@ -2345,11 +2470,11 @@ function isUnresumable(error) {
|
|
|
2345
2470
|
return error !== void 0 && UNRESUMABLE.test(error);
|
|
2346
2471
|
}
|
|
2347
2472
|
function worktreeProgress(worktree, trunk) {
|
|
2348
|
-
if (!worktree || !
|
|
2473
|
+
if (!worktree || !fs18.existsSync(worktree))
|
|
2349
2474
|
return "No worktree progress recorded.";
|
|
2350
|
-
const
|
|
2351
|
-
const commits = trunk ?
|
|
2352
|
-
const status =
|
|
2475
|
+
const git3 = (...a) => spawnSync2("git", a, { cwd: worktree, encoding: "utf8" }).stdout?.trim() ?? "";
|
|
2476
|
+
const commits = trunk ? git3("log", "--oneline", `origin/${trunk}..HEAD`) : git3("log", "--oneline", "-15");
|
|
2477
|
+
const status = git3("status", "--short");
|
|
2353
2478
|
return `Commits so far:
|
|
2354
2479
|
${commits || "(none)"}
|
|
2355
2480
|
|
|
@@ -2378,31 +2503,31 @@ function handoffNote(fromHarness, progress, why) {
|
|
|
2378
2503
|
${progress}`;
|
|
2379
2504
|
}
|
|
2380
2505
|
function codexHome(env = process.env) {
|
|
2381
|
-
return env.CODEX_HOME ??
|
|
2506
|
+
return env.CODEX_HOME ?? path15.join(os3.homedir(), ".codex");
|
|
2382
2507
|
}
|
|
2383
2508
|
function codexRolloutFile(threadId, home = codexHome()) {
|
|
2384
2509
|
const suffix = `-${threadId}.jsonl`;
|
|
2385
2510
|
const walk = (dir, depth) => {
|
|
2386
2511
|
let entries;
|
|
2387
2512
|
try {
|
|
2388
|
-
entries =
|
|
2513
|
+
entries = fs18.readdirSync(dir, { withFileTypes: true });
|
|
2389
2514
|
} catch {
|
|
2390
2515
|
return void 0;
|
|
2391
2516
|
}
|
|
2392
2517
|
for (const e of entries) {
|
|
2393
2518
|
if (e.isFile() && e.name.startsWith("rollout-") && e.name.endsWith(suffix))
|
|
2394
|
-
return
|
|
2519
|
+
return path15.join(dir, e.name);
|
|
2395
2520
|
}
|
|
2396
2521
|
if (depth === 0)
|
|
2397
2522
|
return void 0;
|
|
2398
2523
|
for (const e of entries.filter((x) => x.isDirectory()).sort((a, b) => b.name.localeCompare(a.name))) {
|
|
2399
|
-
const hit = walk(
|
|
2524
|
+
const hit = walk(path15.join(dir, e.name), depth - 1);
|
|
2400
2525
|
if (hit)
|
|
2401
2526
|
return hit;
|
|
2402
2527
|
}
|
|
2403
2528
|
return void 0;
|
|
2404
2529
|
};
|
|
2405
|
-
return walk(
|
|
2530
|
+
return walk(path15.join(home, "sessions"), 3) ?? walk(path15.join(home, "archived_sessions"), 0);
|
|
2406
2531
|
}
|
|
2407
2532
|
function codexDesktopThread(threadId, home = codexHome()) {
|
|
2408
2533
|
const file2 = codexRolloutFile(threadId, home);
|
|
@@ -2410,12 +2535,12 @@ function codexDesktopThread(threadId, home = codexHome()) {
|
|
|
2410
2535
|
return void 0;
|
|
2411
2536
|
let head = "";
|
|
2412
2537
|
try {
|
|
2413
|
-
const fd =
|
|
2538
|
+
const fd = fs18.openSync(file2, "r");
|
|
2414
2539
|
try {
|
|
2415
2540
|
const buf = Buffer.alloc(4096);
|
|
2416
|
-
head = buf.subarray(0,
|
|
2541
|
+
head = buf.subarray(0, fs18.readSync(fd, buf, 0, buf.length, 0)).toString("utf8");
|
|
2417
2542
|
} finally {
|
|
2418
|
-
|
|
2543
|
+
fs18.closeSync(fd);
|
|
2419
2544
|
}
|
|
2420
2545
|
} catch {
|
|
2421
2546
|
return void 0;
|
|
@@ -2429,16 +2554,16 @@ var CODEX_DESKTOP_THREAD = "Codex desktop thread; not resumable from the CLI";
|
|
|
2429
2554
|
|
|
2430
2555
|
// packages/core/dist/notices.js
|
|
2431
2556
|
function noticesDir() {
|
|
2432
|
-
return
|
|
2557
|
+
return path16.join(lobstahHome(), "notices");
|
|
2433
2558
|
}
|
|
2434
2559
|
var counter = 0;
|
|
2435
2560
|
function postNotice(n) {
|
|
2436
2561
|
const dir = noticesDir();
|
|
2437
|
-
|
|
2562
|
+
fs19.mkdirSync(dir, { recursive: true });
|
|
2438
2563
|
if (n.dedupeKey) {
|
|
2439
|
-
const marker =
|
|
2564
|
+
const marker = path16.join(dir, `.dedupe-${n.dedupeKey.replace(/[^A-Za-z0-9_-]/g, "_")}`);
|
|
2440
2565
|
try {
|
|
2441
|
-
|
|
2566
|
+
fs19.writeFileSync(marker, "", { flag: "wx" });
|
|
2442
2567
|
} catch {
|
|
2443
2568
|
return void 0;
|
|
2444
2569
|
}
|
|
@@ -2456,9 +2581,9 @@ function postNotice(n) {
|
|
|
2456
2581
|
...n.quiet ? { quiet: true } : {},
|
|
2457
2582
|
...n.stateHash ? { stateHash: n.stateHash } : {}
|
|
2458
2583
|
};
|
|
2459
|
-
const file2 =
|
|
2584
|
+
const file2 = path16.join(dir, `${seq}.json`);
|
|
2460
2585
|
const tmp = uniqueTempPath(file2);
|
|
2461
|
-
|
|
2586
|
+
fs19.writeFileSync(tmp, JSON.stringify(notice, null, 2));
|
|
2462
2587
|
atomicRenameSync(tmp, file2);
|
|
2463
2588
|
return notice;
|
|
2464
2589
|
}
|
|
@@ -2474,15 +2599,208 @@ function attachmentBlock(attachments) {
|
|
|
2474
2599
|
].join("\n");
|
|
2475
2600
|
}
|
|
2476
2601
|
|
|
2602
|
+
// packages/core/dist/cache-cleanup.js
|
|
2603
|
+
import * as fs20 from "node:fs";
|
|
2604
|
+
import * as path17 from "node:path";
|
|
2605
|
+
import { execFileSync } from "node:child_process";
|
|
2606
|
+
var git = (dir, args) => execFileSync("git", ["-C", dir, ...args], {
|
|
2607
|
+
encoding: "utf8",
|
|
2608
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
2609
|
+
maxBuffer: 64 * 1024 * 1024
|
|
2610
|
+
});
|
|
2611
|
+
function repoCachesConfigured(repo) {
|
|
2612
|
+
try {
|
|
2613
|
+
return repo !== void 0 && !!loadConfig().repos[repo]?.cacheDirs?.length;
|
|
2614
|
+
} catch {
|
|
2615
|
+
return false;
|
|
2616
|
+
}
|
|
2617
|
+
}
|
|
2618
|
+
function cacheTrapIdle(trap) {
|
|
2619
|
+
const live = readTrap(trap.trapId);
|
|
2620
|
+
if (!live?.claimed)
|
|
2621
|
+
return true;
|
|
2622
|
+
const lane = laneOf(live.claimed);
|
|
2623
|
+
if (!lane)
|
|
2624
|
+
return false;
|
|
2625
|
+
const verb = readStatusLog(live.claimed, lane).at(-1)?.verb;
|
|
2626
|
+
return verb !== void 0 && verb !== "working";
|
|
2627
|
+
}
|
|
2628
|
+
function cacheWorktree(root, repoPath) {
|
|
2629
|
+
const canonical = (dir) => {
|
|
2630
|
+
const real = fs20.realpathSync.native(dir);
|
|
2631
|
+
return process.platform === "win32" ? real.toLowerCase() : real;
|
|
2632
|
+
};
|
|
2633
|
+
if (fs20.lstatSync(root).isSymbolicLink())
|
|
2634
|
+
return false;
|
|
2635
|
+
const top = git(root, ["rev-parse", "--show-toplevel"]).trim();
|
|
2636
|
+
const common = path17.resolve(root, git(root, ["rev-parse", "--git-common-dir"]).trim());
|
|
2637
|
+
const privateGit = git(root, ["rev-parse", "--absolute-git-dir"]).trim();
|
|
2638
|
+
const repoCommon = path17.resolve(repoPath, git(repoPath, ["rev-parse", "--git-common-dir"]).trim());
|
|
2639
|
+
return canonical(root) === canonical(top) && canonical(common) !== canonical(privateGit) && canonical(common) === canonical(repoCommon);
|
|
2640
|
+
}
|
|
2641
|
+
function safeCacheTarget(root, target, tracked) {
|
|
2642
|
+
const relative6 = path17.relative(root, target);
|
|
2643
|
+
if (fs20.lstatSync(root).isSymbolicLink())
|
|
2644
|
+
return false;
|
|
2645
|
+
if (!relative6 || relative6.startsWith("..") || path17.isAbsolute(relative6))
|
|
2646
|
+
return false;
|
|
2647
|
+
let current = root;
|
|
2648
|
+
for (const part of relative6.split(path17.sep)) {
|
|
2649
|
+
current = path17.join(current, part);
|
|
2650
|
+
if (part.toLowerCase() === ".git" || fs20.lstatSync(current).isSymbolicLink())
|
|
2651
|
+
return false;
|
|
2652
|
+
}
|
|
2653
|
+
const name = relative6.split(path17.sep).join("/").toLowerCase();
|
|
2654
|
+
return !tracked.some((trackedPath) => {
|
|
2655
|
+
const file2 = trackedPath.toLowerCase();
|
|
2656
|
+
return file2 === name || file2.startsWith(name + "/") || name.startsWith(file2 + "/");
|
|
2657
|
+
});
|
|
2658
|
+
}
|
|
2659
|
+
function cacheBytes(target) {
|
|
2660
|
+
const stat = fs20.lstatSync(target);
|
|
2661
|
+
if (stat.isSymbolicLink())
|
|
2662
|
+
return 0;
|
|
2663
|
+
if (!stat.isDirectory())
|
|
2664
|
+
return process.platform === "win32" || stat.blocks === void 0 ? stat.size : stat.blocks * 512;
|
|
2665
|
+
const entries = fs20.readdirSync(target);
|
|
2666
|
+
if (entries.some((name) => name.toLowerCase() === ".git"))
|
|
2667
|
+
throw new Error("nested repository is not a cache");
|
|
2668
|
+
return entries.reduce((bytes, name) => bytes + cacheBytes(path17.join(target, name)), 0);
|
|
2669
|
+
}
|
|
2670
|
+
function planTrapCache(trap, cfg) {
|
|
2671
|
+
const repo = trap.repo ? cfg.repos[trap.repo] : void 0;
|
|
2672
|
+
if (!repo?.cacheDirs?.length || !cacheTrapIdle(trap))
|
|
2673
|
+
return void 0;
|
|
2674
|
+
try {
|
|
2675
|
+
const root = fs20.realpathSync.native(trap.worktree);
|
|
2676
|
+
if (!cacheWorktree(trap.worktree, repo.path))
|
|
2677
|
+
return void 0;
|
|
2678
|
+
const tracked = git(root, ["ls-files", "-z"]).split("\0").filter(Boolean);
|
|
2679
|
+
const targets = [];
|
|
2680
|
+
let bytes = 0;
|
|
2681
|
+
for (const target of cacheDirectories(root, repo.cacheDirs)) {
|
|
2682
|
+
try {
|
|
2683
|
+
if (!safeCacheTarget(root, target, tracked))
|
|
2684
|
+
continue;
|
|
2685
|
+
const size = cacheBytes(target);
|
|
2686
|
+
targets.push(target);
|
|
2687
|
+
bytes += size;
|
|
2688
|
+
} catch {
|
|
2689
|
+
}
|
|
2690
|
+
}
|
|
2691
|
+
return targets.length ? { trapId: trap.trapId, repo: trap.repo, worktree: root, targets, bytes } : void 0;
|
|
2692
|
+
} catch {
|
|
2693
|
+
return void 0;
|
|
2694
|
+
}
|
|
2695
|
+
}
|
|
2696
|
+
function planTrapCaches(cfg = loadConfig()) {
|
|
2697
|
+
const traps = new Map([...listRoster(), ...listTraps()].map((trap) => [trap.trapId, trap]));
|
|
2698
|
+
return [...traps.values()].flatMap((trap) => {
|
|
2699
|
+
const plan = planTrapCache(trap, cfg);
|
|
2700
|
+
return plan ? [plan] : [];
|
|
2701
|
+
}).sort((a, b) => b.bytes - a.bytes || a.trapId.localeCompare(b.trapId));
|
|
2702
|
+
}
|
|
2703
|
+
function clearTrapCaches(trap, cfg = loadConfig()) {
|
|
2704
|
+
if (!trap.repo || !cfg.repos[trap.repo]?.cacheDirs?.length)
|
|
2705
|
+
return 0;
|
|
2706
|
+
return withTrapCacheLock(trap.trapId, () => {
|
|
2707
|
+
const plan = planTrapCache(trap, cfg);
|
|
2708
|
+
if (!plan)
|
|
2709
|
+
return 0;
|
|
2710
|
+
let bytes = 0;
|
|
2711
|
+
for (const target of plan.targets) {
|
|
2712
|
+
try {
|
|
2713
|
+
const tracked = git(plan.worktree, ["ls-files", "-z"]).split("\0").filter(Boolean);
|
|
2714
|
+
if (!cacheTrapIdle(trap) || !safeCacheTarget(plan.worktree, target, tracked))
|
|
2715
|
+
continue;
|
|
2716
|
+
const size = cacheBytes(target);
|
|
2717
|
+
fs20.rmSync(target, { recursive: true, force: true });
|
|
2718
|
+
bytes += size;
|
|
2719
|
+
} catch {
|
|
2720
|
+
}
|
|
2721
|
+
}
|
|
2722
|
+
return bytes;
|
|
2723
|
+
});
|
|
2724
|
+
}
|
|
2725
|
+
function clearFinishedTrapCaches(trap, reason) {
|
|
2726
|
+
if (!repoCachesConfigured(trap.repo))
|
|
2727
|
+
return;
|
|
2728
|
+
try {
|
|
2729
|
+
const free = () => {
|
|
2730
|
+
try {
|
|
2731
|
+
return statfsFreeBytes(trap.worktree);
|
|
2732
|
+
} catch {
|
|
2733
|
+
return void 0;
|
|
2734
|
+
}
|
|
2735
|
+
};
|
|
2736
|
+
const before = free();
|
|
2737
|
+
const bytes = clearTrapCaches(trap);
|
|
2738
|
+
const after = free();
|
|
2739
|
+
const recovered = before !== void 0 && after !== void 0 ? Math.max(0, after - before) : void 0;
|
|
2740
|
+
if (bytes > 0)
|
|
2741
|
+
postNotice({
|
|
2742
|
+
kind: "caches-cleared",
|
|
2743
|
+
repo: trap.repo,
|
|
2744
|
+
refId: trap.trapId,
|
|
2745
|
+
quiet: true,
|
|
2746
|
+
text: `trap ${trap.trapId} ${reason}: cleared ${bytes} cache bytes (${formatGB(bytes)})` + (recovered !== void 0 ? `; ${recovered} free bytes recovered` : "")
|
|
2747
|
+
});
|
|
2748
|
+
} catch {
|
|
2749
|
+
}
|
|
2750
|
+
}
|
|
2751
|
+
function recoverTrapCaches(cfg, volume, readFree = statfsFreeBytes, log = () => {
|
|
2752
|
+
}) {
|
|
2753
|
+
if (!Object.values(cfg.repos).some((repo) => repo.cacheDirs?.length))
|
|
2754
|
+
return 0;
|
|
2755
|
+
if (cfg.limits.cacheMinFreeGB === 0)
|
|
2756
|
+
return 0;
|
|
2757
|
+
const threshold = Math.max(cfg.limits.cacheMinFreeGB ?? 50, cfg.limits.minFreeGB ?? 0) * GB;
|
|
2758
|
+
if (!(threshold > 0))
|
|
2759
|
+
return 0;
|
|
2760
|
+
try {
|
|
2761
|
+
const before = readFree(volume);
|
|
2762
|
+
if (before >= threshold)
|
|
2763
|
+
return 0;
|
|
2764
|
+
let bytes = 0;
|
|
2765
|
+
let traps = 0;
|
|
2766
|
+
const device = fs20.statSync(volume).dev;
|
|
2767
|
+
for (const plan of planTrapCaches(cfg)) {
|
|
2768
|
+
if (readFree(volume) >= threshold)
|
|
2769
|
+
break;
|
|
2770
|
+
try {
|
|
2771
|
+
if (fs20.statSync(plan.worktree).dev !== device)
|
|
2772
|
+
continue;
|
|
2773
|
+
const removed = clearTrapCaches(plan, cfg);
|
|
2774
|
+
if (removed > 0) {
|
|
2775
|
+
bytes += removed;
|
|
2776
|
+
traps++;
|
|
2777
|
+
}
|
|
2778
|
+
} catch (error) {
|
|
2779
|
+
log(`cache cleanup kept trap ${plan.trapId}: ${error instanceof Error ? error.message : String(error)}`);
|
|
2780
|
+
}
|
|
2781
|
+
}
|
|
2782
|
+
if (bytes > 0) {
|
|
2783
|
+
const recovered = Math.max(0, readFree(volume) - before);
|
|
2784
|
+
const text = `cache pressure cleanup: ${bytes} cache bytes cleared in ${traps} idle trap(s); ${recovered} free bytes recovered (${formatGB(recovered)})`;
|
|
2785
|
+
postNotice({ kind: "caches-cleared", text });
|
|
2786
|
+
log(text);
|
|
2787
|
+
}
|
|
2788
|
+
return bytes;
|
|
2789
|
+
} catch (error) {
|
|
2790
|
+
log(`cache pressure cleanup skipped: ${error instanceof Error ? error.message : String(error)}`);
|
|
2791
|
+
return 0;
|
|
2792
|
+
}
|
|
2793
|
+
}
|
|
2794
|
+
|
|
2477
2795
|
// packages/core/dist/helm.js
|
|
2478
|
-
import * as
|
|
2479
|
-
import * as
|
|
2796
|
+
import * as fs21 from "node:fs";
|
|
2797
|
+
import * as path18 from "node:path";
|
|
2480
2798
|
function helmDir() {
|
|
2481
|
-
return
|
|
2799
|
+
return path18.join(lobstahHome(), "helm");
|
|
2482
2800
|
}
|
|
2483
2801
|
function listHelms() {
|
|
2484
2802
|
try {
|
|
2485
|
-
return
|
|
2803
|
+
return fs21.readdirSync(helmDir()).filter((f) => f.endsWith(".json")).map((f) => JSON.parse(fs21.readFileSync(path18.join(helmDir(), f), "utf8")));
|
|
2486
2804
|
} catch {
|
|
2487
2805
|
return [];
|
|
2488
2806
|
}
|
|
@@ -2493,39 +2811,39 @@ function liveHelms(ttlMs, now2 = Date.now()) {
|
|
|
2493
2811
|
|
|
2494
2812
|
// packages/core/dist/soak.js
|
|
2495
2813
|
function regPath(trapId) {
|
|
2496
|
-
return
|
|
2814
|
+
return path19.join(soakingDir(), `${trapId}.json`);
|
|
2497
2815
|
}
|
|
2498
2816
|
function readTrap(trapId) {
|
|
2499
2817
|
try {
|
|
2500
|
-
return JSON.parse(
|
|
2818
|
+
return JSON.parse(fs22.readFileSync(regPath(trapId), "utf8"));
|
|
2501
2819
|
} catch {
|
|
2502
2820
|
return void 0;
|
|
2503
2821
|
}
|
|
2504
2822
|
}
|
|
2505
2823
|
function listTraps() {
|
|
2506
2824
|
try {
|
|
2507
|
-
return
|
|
2825
|
+
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");
|
|
2508
2826
|
} catch {
|
|
2509
2827
|
return [];
|
|
2510
2828
|
}
|
|
2511
2829
|
}
|
|
2512
2830
|
function claimPath(id, lane) {
|
|
2513
|
-
return
|
|
2831
|
+
return path19.join(laneDirs(lane).active, id, "claim.json");
|
|
2514
2832
|
}
|
|
2515
2833
|
function readSessionClaim(id, lane) {
|
|
2516
2834
|
try {
|
|
2517
|
-
return JSON.parse(
|
|
2835
|
+
return JSON.parse(fs22.readFileSync(claimPath(id, lane), "utf8"));
|
|
2518
2836
|
} catch {
|
|
2519
2837
|
return void 0;
|
|
2520
2838
|
}
|
|
2521
2839
|
}
|
|
2522
2840
|
|
|
2523
2841
|
// packages/core/dist/catch-context.js
|
|
2524
|
-
import * as
|
|
2525
|
-
import * as
|
|
2842
|
+
import * as fs23 from "node:fs";
|
|
2843
|
+
import * as path20 from "node:path";
|
|
2526
2844
|
function readCatchContext(dir, id) {
|
|
2527
2845
|
try {
|
|
2528
|
-
return JSON.parse(
|
|
2846
|
+
return JSON.parse(fs23.readFileSync(path20.join(dir, `${id}.catch-context`), "utf8"));
|
|
2529
2847
|
} catch {
|
|
2530
2848
|
return {};
|
|
2531
2849
|
}
|
|
@@ -2538,19 +2856,19 @@ function observeLocalCatch(id, lane, phase, now2 = Date.now()) {
|
|
|
2538
2856
|
const helms = liveHelms(cfg.helm.ttlSecs * 1e3, now2);
|
|
2539
2857
|
const present = repo ? helms.some((h) => h.repos.includes(repo)) : null;
|
|
2540
2858
|
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 };
|
|
2541
|
-
const file2 =
|
|
2859
|
+
const file2 = path20.join(dir, `${id}.catch-context`), tmp = uniqueTempPath(file2);
|
|
2542
2860
|
try {
|
|
2543
|
-
|
|
2544
|
-
|
|
2861
|
+
fs23.writeFileSync(tmp, JSON.stringify(next));
|
|
2862
|
+
fs23.renameSync(tmp, file2);
|
|
2545
2863
|
} finally {
|
|
2546
|
-
|
|
2864
|
+
fs23.rmSync(tmp, { force: true });
|
|
2547
2865
|
}
|
|
2548
2866
|
}
|
|
2549
2867
|
|
|
2550
2868
|
// packages/core/dist/stats.js
|
|
2551
2869
|
var DAILY_RETENTION_DAYS = 400;
|
|
2552
2870
|
function statsPath() {
|
|
2553
|
-
return
|
|
2871
|
+
return path21.join(lobstahHome(), "stats.json");
|
|
2554
2872
|
}
|
|
2555
2873
|
function shiftDay(day, days) {
|
|
2556
2874
|
const [y, m, d] = day.split("-").map(Number);
|
|
@@ -2563,7 +2881,7 @@ function localDay(at = Date.now()) {
|
|
|
2563
2881
|
function readCatchFacts(stateDir, id) {
|
|
2564
2882
|
let last;
|
|
2565
2883
|
try {
|
|
2566
|
-
for (const line of
|
|
2884
|
+
for (const line of fs24.readFileSync(path21.join(stateDir, `${id}.status`), "utf8").split("\n")) {
|
|
2567
2885
|
if (!line.trim())
|
|
2568
2886
|
continue;
|
|
2569
2887
|
try {
|
|
@@ -2579,7 +2897,7 @@ function readCatchFacts(stateDir, id) {
|
|
|
2579
2897
|
let trap;
|
|
2580
2898
|
let worker = workerProfile();
|
|
2581
2899
|
try {
|
|
2582
|
-
const evidence = JSON.parse(
|
|
2900
|
+
const evidence = JSON.parse(fs24.readFileSync(path21.join(stateDir, `${id}.evidence`), "utf8"));
|
|
2583
2901
|
const to = evidence.deliveredTo;
|
|
2584
2902
|
if (typeof to === "string" && to.startsWith("wt:"))
|
|
2585
2903
|
trap = to;
|
|
@@ -2662,7 +2980,7 @@ function add(store, facts, now2) {
|
|
|
2662
2980
|
}
|
|
2663
2981
|
function backfillSources() {
|
|
2664
2982
|
const live = ["work", "chore"].map((lane) => ({ dir: laneDirs(lane).state, live: true }));
|
|
2665
|
-
const backups = readDirIfPresent(lobstahHome()).filter((name) => name.startsWith("state-backup-")).sort().map((name) => ({ dir:
|
|
2983
|
+
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());
|
|
2666
2984
|
return [...live, ...backups];
|
|
2667
2985
|
}
|
|
2668
2986
|
function backfillStats(now2 = Date.now(), alreadyCounted) {
|
|
@@ -2734,13 +3052,13 @@ function parseStore(text) {
|
|
|
2734
3052
|
var complete2 = (s) => !!s && s.daily !== void 0;
|
|
2735
3053
|
function writeStore(store) {
|
|
2736
3054
|
const file2 = statsPath();
|
|
2737
|
-
|
|
3055
|
+
fs24.mkdirSync(path21.dirname(file2), { recursive: true });
|
|
2738
3056
|
const tmp = uniqueTempPath(file2);
|
|
2739
|
-
|
|
3057
|
+
fs24.writeFileSync(tmp, JSON.stringify(store));
|
|
2740
3058
|
atomicRenameSync(tmp, file2);
|
|
2741
3059
|
}
|
|
2742
3060
|
function withStatsLock(action) {
|
|
2743
|
-
|
|
3061
|
+
fs24.mkdirSync(lobstahHome(), { recursive: true });
|
|
2744
3062
|
return withDirLock(`${statsPath()}.lock`, action, {
|
|
2745
3063
|
staleMs: 12e4,
|
|
2746
3064
|
waitMs: 1e4,
|
|
@@ -2750,7 +3068,7 @@ function withStatsLock(action) {
|
|
|
2750
3068
|
function loadOrBackfill(now2) {
|
|
2751
3069
|
let text;
|
|
2752
3070
|
try {
|
|
2753
|
-
text =
|
|
3071
|
+
text = fs24.readFileSync(statsPath(), "utf8");
|
|
2754
3072
|
} catch (err) {
|
|
2755
3073
|
if (err.code !== "ENOENT")
|
|
2756
3074
|
throw err;
|
|
@@ -2777,7 +3095,7 @@ function loadOrBackfill(now2) {
|
|
|
2777
3095
|
return store2;
|
|
2778
3096
|
}
|
|
2779
3097
|
if (text !== void 0)
|
|
2780
|
-
|
|
3098
|
+
fs24.renameSync(statsPath(), `${statsPath()}.unreadable-${now2}`);
|
|
2781
3099
|
const store = backfillStats(now2);
|
|
2782
3100
|
writeStore(store);
|
|
2783
3101
|
return store;
|
|
@@ -2864,8 +3182,18 @@ function appendStatus(id, lane, verb, note, at, waiting, reported = false) {
|
|
|
2864
3182
|
} catch {
|
|
2865
3183
|
}
|
|
2866
3184
|
}
|
|
2867
|
-
|
|
3185
|
+
const claim = readSessionClaim(id, lane);
|
|
3186
|
+
const trap = claim?.by.startsWith("wt:") ? readTrap(claim.by.slice(3)) : void 0;
|
|
3187
|
+
const write = () => {
|
|
3188
|
+
fs25.appendFileSync(statusPath(id, lane), `${JSON.stringify(entry)}
|
|
2868
3189
|
`);
|
|
3190
|
+
};
|
|
3191
|
+
if (trap && repoCachesConfigured(trap.repo))
|
|
3192
|
+
withTrapCacheLock(trap.trapId, write);
|
|
3193
|
+
else
|
|
3194
|
+
write();
|
|
3195
|
+
if (trap && trap.claimed === id && (verb === "done" || verb === "failed"))
|
|
3196
|
+
clearFinishedTrapCaches(trap, verb);
|
|
2869
3197
|
if (verb === "done") {
|
|
2870
3198
|
try {
|
|
2871
3199
|
recordCatch(id, lane);
|
|
@@ -2876,9 +3204,9 @@ function appendStatus(id, lane, verb, note, at, waiting, reported = false) {
|
|
|
2876
3204
|
}
|
|
2877
3205
|
function readStatusLog(id, lane) {
|
|
2878
3206
|
const file2 = statusPath(id, lane);
|
|
2879
|
-
if (!
|
|
3207
|
+
if (!fs25.existsSync(file2))
|
|
2880
3208
|
return [];
|
|
2881
|
-
return
|
|
3209
|
+
return fs25.readFileSync(file2, "utf8").split("\n").filter(Boolean).flatMap((line) => {
|
|
2882
3210
|
try {
|
|
2883
3211
|
const parsed = JSON.parse(line);
|
|
2884
3212
|
return isVerb(parsed.verb) ? [parsed] : [];
|
|
@@ -2894,28 +3222,28 @@ function pausedWaiting(entry) {
|
|
|
2894
3222
|
// packages/core/dist/queue.js
|
|
2895
3223
|
function requeue(id, lane) {
|
|
2896
3224
|
const dirs = laneDirs(lane);
|
|
2897
|
-
const activeDir =
|
|
2898
|
-
const file2 =
|
|
3225
|
+
const activeDir = path22.join(dirs.active, id);
|
|
3226
|
+
const file2 = path22.join(activeDir, "descriptor.json");
|
|
2899
3227
|
const d = { ...readDescriptor(id, lane), queuedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
2900
3228
|
const tmp = uniqueTempPath(file2);
|
|
2901
|
-
|
|
3229
|
+
fs26.writeFileSync(tmp, JSON.stringify(d, null, 2));
|
|
2902
3230
|
atomicRenameSync(tmp, file2);
|
|
2903
|
-
|
|
2904
|
-
|
|
3231
|
+
fs26.renameSync(file2, path22.join(dirs.queue, `${id}.json`));
|
|
3232
|
+
fs26.rmSync(activeDir, { recursive: true, force: true });
|
|
2905
3233
|
}
|
|
2906
3234
|
function readDescriptor(id, lane) {
|
|
2907
|
-
const file2 =
|
|
2908
|
-
return JSON.parse(
|
|
3235
|
+
const file2 = path22.join(laneDirs(lane).active, id, "descriptor.json");
|
|
3236
|
+
return JSON.parse(fs26.readFileSync(file2, "utf8"));
|
|
2909
3237
|
}
|
|
2910
3238
|
function storedDescriptor(id, lane) {
|
|
2911
3239
|
const dirs = laneDirs(lane);
|
|
2912
3240
|
for (const file2 of [
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
3241
|
+
path22.join(dirs.queue, `${id}.json`),
|
|
3242
|
+
path22.join(dirs.active, id, "descriptor.json"),
|
|
3243
|
+
path22.join(dirs.done, id, "descriptor.json")
|
|
2916
3244
|
]) {
|
|
2917
3245
|
try {
|
|
2918
|
-
return JSON.parse(
|
|
3246
|
+
return JSON.parse(fs26.readFileSync(file2, "utf8"));
|
|
2919
3247
|
} catch {
|
|
2920
3248
|
}
|
|
2921
3249
|
}
|
|
@@ -2926,10 +3254,10 @@ function activeIds(lane) {
|
|
|
2926
3254
|
}
|
|
2927
3255
|
function complete(id, lane) {
|
|
2928
3256
|
const dirs = laneDirs(lane);
|
|
2929
|
-
|
|
3257
|
+
fs26.renameSync(path22.join(dirs.active, id), path22.join(dirs.done, id));
|
|
2930
3258
|
}
|
|
2931
3259
|
function cancelRequested(id, lane) {
|
|
2932
|
-
return
|
|
3260
|
+
return fs26.existsSync(path22.join(laneDirs(lane).active, id, "cancel"));
|
|
2933
3261
|
}
|
|
2934
3262
|
|
|
2935
3263
|
// packages/core/dist/backend.js
|
|
@@ -2978,21 +3306,21 @@ var ANSWER_EXTENSIONS = Object.keys(ANSWER_TYPES);
|
|
|
2978
3306
|
var ONCE_TTL_MS = 60 * 60 * 1e3;
|
|
2979
3307
|
|
|
2980
3308
|
// packages/core/dist/harness.js
|
|
2981
|
-
import * as
|
|
2982
|
-
import * as
|
|
3309
|
+
import * as fs27 from "node:fs";
|
|
3310
|
+
import * as path23 from "node:path";
|
|
2983
3311
|
import { createRequire } from "node:module";
|
|
2984
3312
|
function resolveOnPath(bin, pathVar = process.env.PATH) {
|
|
2985
3313
|
if (!pathVar)
|
|
2986
3314
|
return void 0;
|
|
2987
3315
|
const names = process.platform === "win32" ? [bin, `${bin}.exe`, `${bin}.cmd`, `${bin}.bat`] : [bin];
|
|
2988
|
-
for (const dir of pathVar.split(
|
|
3316
|
+
for (const dir of pathVar.split(path23.delimiter)) {
|
|
2989
3317
|
if (!dir)
|
|
2990
3318
|
continue;
|
|
2991
3319
|
for (const name of names) {
|
|
2992
|
-
const candidate =
|
|
3320
|
+
const candidate = path23.join(dir, name);
|
|
2993
3321
|
try {
|
|
2994
|
-
|
|
2995
|
-
if (
|
|
3322
|
+
fs27.accessSync(candidate, fs27.constants.X_OK);
|
|
3323
|
+
if (fs27.statSync(candidate).isFile())
|
|
2996
3324
|
return candidate;
|
|
2997
3325
|
} catch {
|
|
2998
3326
|
}
|
|
@@ -3013,8 +3341,8 @@ function codexInvocation(argv) {
|
|
|
3013
3341
|
} catch {
|
|
3014
3342
|
}
|
|
3015
3343
|
for (const dir of require_.resolve.paths("@openai/codex") ?? []) {
|
|
3016
|
-
const cli =
|
|
3017
|
-
if (
|
|
3344
|
+
const cli = path23.join(dir, "@openai", "codex", "bin", "codex.js");
|
|
3345
|
+
if (fs27.existsSync(cli))
|
|
3018
3346
|
return { file: process.execPath, argv: [cli, ...argv] };
|
|
3019
3347
|
}
|
|
3020
3348
|
return void 0;
|
|
@@ -3087,9 +3415,9 @@ function droppedModelNote(harness, dropped) {
|
|
|
3087
3415
|
}
|
|
3088
3416
|
|
|
3089
3417
|
// packages/runner/src/run.ts
|
|
3090
|
-
import * as
|
|
3091
|
-
import * as
|
|
3092
|
-
import { execFileSync as
|
|
3418
|
+
import * as fs32 from "node:fs";
|
|
3419
|
+
import * as path28 from "node:path";
|
|
3420
|
+
import { execFileSync as execFileSync3 } from "node:child_process";
|
|
3093
3421
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
3094
3422
|
|
|
3095
3423
|
// packages/adapters/dist/claude.js
|
|
@@ -3122,7 +3450,7 @@ var AsyncQueue = class {
|
|
|
3122
3450
|
return Promise.resolve({ value: item, done: false });
|
|
3123
3451
|
if (this.closed)
|
|
3124
3452
|
return Promise.resolve({ value: void 0, done: true });
|
|
3125
|
-
return new Promise((
|
|
3453
|
+
return new Promise((resolve10) => this.waiters.push(resolve10));
|
|
3126
3454
|
}
|
|
3127
3455
|
};
|
|
3128
3456
|
}
|
|
@@ -3147,7 +3475,7 @@ var InputGate = class {
|
|
|
3147
3475
|
return msg;
|
|
3148
3476
|
if (this.ended)
|
|
3149
3477
|
return void 0;
|
|
3150
|
-
await new Promise((
|
|
3478
|
+
await new Promise((resolve10) => this.waiter = resolve10);
|
|
3151
3479
|
this.waiter = null;
|
|
3152
3480
|
}
|
|
3153
3481
|
}
|
|
@@ -3292,20 +3620,20 @@ function startClaudeCli(invocation, opts) {
|
|
|
3292
3620
|
}
|
|
3293
3621
|
}
|
|
3294
3622
|
});
|
|
3295
|
-
const done = new Promise((
|
|
3623
|
+
const done = new Promise((resolve10) => {
|
|
3296
3624
|
child.on("error", (err) => {
|
|
3297
3625
|
events.push({ at: now(), type: "error", data: { message: err.message } });
|
|
3298
3626
|
events.close();
|
|
3299
|
-
|
|
3627
|
+
resolve10({ sessionId, error: err.message });
|
|
3300
3628
|
});
|
|
3301
3629
|
child.on("exit", (code2) => {
|
|
3302
3630
|
events.close();
|
|
3303
3631
|
if (code2 === 0)
|
|
3304
|
-
|
|
3632
|
+
resolve10({ sessionId });
|
|
3305
3633
|
else {
|
|
3306
3634
|
const detail = stderrTail.trim().split("\n").at(-1);
|
|
3307
3635
|
const error = `claude exited ${code2}${detail ? ` \u2014 ${detail}` : ""}`;
|
|
3308
|
-
|
|
3636
|
+
resolve10({ sessionId, error });
|
|
3309
3637
|
}
|
|
3310
3638
|
});
|
|
3311
3639
|
});
|
|
@@ -3384,25 +3712,25 @@ function createClaudeAdapter() {
|
|
|
3384
3712
|
}
|
|
3385
3713
|
|
|
3386
3714
|
// packages/adapters/dist/codex.js
|
|
3387
|
-
import * as
|
|
3715
|
+
import * as fs28 from "node:fs";
|
|
3388
3716
|
import * as os4 from "node:os";
|
|
3389
|
-
import * as
|
|
3717
|
+
import * as path24 from "node:path";
|
|
3390
3718
|
import { spawn as spawn2 } from "node:child_process";
|
|
3391
3719
|
function isolatedCodexHome() {
|
|
3392
|
-
const dir =
|
|
3393
|
-
|
|
3394
|
-
const auth =
|
|
3395
|
-
const realAuth =
|
|
3396
|
-
if (!
|
|
3720
|
+
const dir = path24.join(lobstahHome(), "codex-home");
|
|
3721
|
+
fs28.mkdirSync(dir, { recursive: true });
|
|
3722
|
+
const auth = path24.join(dir, "auth.json");
|
|
3723
|
+
const realAuth = path24.join(os4.homedir(), ".codex", "auth.json");
|
|
3724
|
+
if (!fs28.existsSync(auth) && fs28.existsSync(realAuth)) {
|
|
3397
3725
|
try {
|
|
3398
|
-
|
|
3726
|
+
fs28.symlinkSync(realAuth, auth);
|
|
3399
3727
|
} catch {
|
|
3400
|
-
|
|
3728
|
+
fs28.copyFileSync(realAuth, auth);
|
|
3401
3729
|
}
|
|
3402
3730
|
}
|
|
3403
|
-
const cfg =
|
|
3404
|
-
if (!
|
|
3405
|
-
|
|
3731
|
+
const cfg = path24.join(dir, "config.toml");
|
|
3732
|
+
if (!fs28.existsSync(cfg)) {
|
|
3733
|
+
fs28.writeFileSync(cfg, "# lobstah-managed: auth inherited from ~/.codex, interactive config not\n");
|
|
3406
3734
|
}
|
|
3407
3735
|
return dir;
|
|
3408
3736
|
}
|
|
@@ -3454,7 +3782,7 @@ function startCodexCli(invoke, opts) {
|
|
|
3454
3782
|
let current;
|
|
3455
3783
|
let killed = false;
|
|
3456
3784
|
function runTurn(prompt, resumeThread) {
|
|
3457
|
-
return new Promise((
|
|
3785
|
+
return new Promise((resolve10) => {
|
|
3458
3786
|
const inv = invoke(codexExecArgs(opts, prompt, resumeThread));
|
|
3459
3787
|
const child = spawn2(inv.file, inv.argv, {
|
|
3460
3788
|
cwd: opts.cwd,
|
|
@@ -3485,14 +3813,14 @@ function startCodexCli(invoke, opts) {
|
|
|
3485
3813
|
}
|
|
3486
3814
|
}
|
|
3487
3815
|
});
|
|
3488
|
-
child.on("error", (err) =>
|
|
3816
|
+
child.on("error", (err) => resolve10(err.message));
|
|
3489
3817
|
child.on("exit", (code2) => {
|
|
3490
3818
|
if (turnError)
|
|
3491
|
-
return
|
|
3819
|
+
return resolve10(turnError);
|
|
3492
3820
|
if (code2 === 0 || killed)
|
|
3493
|
-
return
|
|
3821
|
+
return resolve10(void 0);
|
|
3494
3822
|
const detail = stderrTail.trim().split("\n").at(-1);
|
|
3495
|
-
|
|
3823
|
+
resolve10(`codex exited ${code2}${detail ? ` \u2014 ${detail}` : ""}`);
|
|
3496
3824
|
});
|
|
3497
3825
|
});
|
|
3498
3826
|
}
|
|
@@ -3605,15 +3933,15 @@ function loadAdapter(name) {
|
|
|
3605
3933
|
}
|
|
3606
3934
|
|
|
3607
3935
|
// packages/worktree/dist/index.js
|
|
3608
|
-
import * as
|
|
3609
|
-
import * as
|
|
3936
|
+
import * as fs30 from "node:fs";
|
|
3937
|
+
import * as path26 from "node:path";
|
|
3610
3938
|
import { createHash } from "node:crypto";
|
|
3611
|
-
import { exec, execFile as execFile2, execFileSync } from "node:child_process";
|
|
3939
|
+
import { exec, execFile as execFile2, execFileSync as execFileSync2 } from "node:child_process";
|
|
3612
3940
|
import { promisify as promisify2 } from "node:util";
|
|
3613
3941
|
|
|
3614
3942
|
// packages/worktree/dist/pool.js
|
|
3615
|
-
import * as
|
|
3616
|
-
import * as
|
|
3943
|
+
import * as fs29 from "node:fs";
|
|
3944
|
+
import * as path25 from "node:path";
|
|
3617
3945
|
import { execFile } from "node:child_process";
|
|
3618
3946
|
import { promisify } from "node:util";
|
|
3619
3947
|
var run = promisify(execFile);
|
|
@@ -3675,17 +4003,17 @@ function takeOut(name, pool, slot, reason, dispatch, notice = true) {
|
|
|
3675
4003
|
function trapIn(dir) {
|
|
3676
4004
|
const real = (p) => {
|
|
3677
4005
|
try {
|
|
3678
|
-
return
|
|
4006
|
+
return fs29.realpathSync.native(p);
|
|
3679
4007
|
} catch {
|
|
3680
|
-
return
|
|
4008
|
+
return path25.resolve(p);
|
|
3681
4009
|
}
|
|
3682
4010
|
};
|
|
3683
4011
|
const here = real(dir);
|
|
3684
4012
|
return listTraps().some((t) => {
|
|
3685
4013
|
if (typeof t.worktree !== "string")
|
|
3686
4014
|
return false;
|
|
3687
|
-
const rel =
|
|
3688
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
4015
|
+
const rel = path25.relative(here, real(t.worktree));
|
|
4016
|
+
return rel === "" || !rel.startsWith("..") && !path25.isAbsolute(rel);
|
|
3689
4017
|
});
|
|
3690
4018
|
}
|
|
3691
4019
|
async function claimPoolSlot(input) {
|
|
@@ -3693,7 +4021,7 @@ async function claimPoolSlot(input) {
|
|
|
3693
4021
|
const refused = [];
|
|
3694
4022
|
for (let slot = 1; slot <= pool.size; slot++) {
|
|
3695
4023
|
const dir = poolSlotPath(name, slot);
|
|
3696
|
-
if (
|
|
4024
|
+
if (fs29.existsSync(dir) && readWorktreeLock(dir)?.id === id && readWorktreeLock(dir)?.kind !== "warm") {
|
|
3697
4025
|
writeSlotClaim(name, slot, { id, lane, at: (/* @__PURE__ */ new Date()).toISOString() });
|
|
3698
4026
|
return { claimed: true, dir, slot, label: poolSlotLabel(name, slot) };
|
|
3699
4027
|
}
|
|
@@ -3741,7 +4069,7 @@ async function resetPoolWorktree(repo, dir, id, fromRemoteBranch = repo.trunk) {
|
|
|
3741
4069
|
}
|
|
3742
4070
|
var WARM_ID = "pool-warm";
|
|
3743
4071
|
async function createSlot(repo, dir) {
|
|
3744
|
-
|
|
4072
|
+
fs29.mkdirSync(path25.dirname(dir), { recursive: true });
|
|
3745
4073
|
await oneAtATime(repo.path, async () => {
|
|
3746
4074
|
await tryGit(repo.path, "worktree", "prune");
|
|
3747
4075
|
await gitShared(repo.path, "worktree", "add", "--detach", dir, `origin/${repo.trunk}`);
|
|
@@ -3763,7 +4091,7 @@ async function warmPool(name, opts = {}) {
|
|
|
3763
4091
|
if (!release)
|
|
3764
4092
|
return false;
|
|
3765
4093
|
try {
|
|
3766
|
-
if (!
|
|
4094
|
+
if (!fs29.existsSync(repo.path)) {
|
|
3767
4095
|
if (!repo.origin)
|
|
3768
4096
|
throw new Error(`repo path ${repo.path} missing and no origin configured`);
|
|
3769
4097
|
await run("git", ["clone", repo.origin, repo.path], { env: process.env });
|
|
@@ -3776,8 +4104,9 @@ async function warmPool(name, opts = {}) {
|
|
|
3776
4104
|
const dir = poolSlotPath(name, slot);
|
|
3777
4105
|
const label = poolSlotLabel(name, slot);
|
|
3778
4106
|
const meta = readSlotMeta(name, slot);
|
|
3779
|
-
if (!
|
|
3780
|
-
|
|
4107
|
+
if (!fs29.existsSync(dir)) {
|
|
4108
|
+
fs29.mkdirSync(poolsRoot(), { recursive: true });
|
|
4109
|
+
recoverTrapCaches(cfg, poolsRoot(), read2, log);
|
|
3781
4110
|
let free = Infinity;
|
|
3782
4111
|
try {
|
|
3783
4112
|
free = need > 0 ? read2(poolsRoot()) : Infinity;
|
|
@@ -3853,7 +4182,7 @@ async function warmPool(name, opts = {}) {
|
|
|
3853
4182
|
// packages/worktree/dist/index.js
|
|
3854
4183
|
var run2 = promisify2(execFile2);
|
|
3855
4184
|
var shell = promisify2(exec);
|
|
3856
|
-
async function
|
|
4185
|
+
async function git2(cwd, ...args) {
|
|
3857
4186
|
const { stdout } = await run2("git", args, { cwd, env: process.env });
|
|
3858
4187
|
return stdout.trim();
|
|
3859
4188
|
}
|
|
@@ -3895,7 +4224,7 @@ var ATTEMPTS = 6;
|
|
|
3895
4224
|
async function gitShared(cwd, ...args) {
|
|
3896
4225
|
for (let attempt2 = 1; ; attempt2++) {
|
|
3897
4226
|
try {
|
|
3898
|
-
return await
|
|
4227
|
+
return await git2(cwd, ...args);
|
|
3899
4228
|
} catch (err) {
|
|
3900
4229
|
if (!isLockContention(err))
|
|
3901
4230
|
throw err;
|
|
@@ -3920,7 +4249,7 @@ function pidAlive3(pid) {
|
|
|
3920
4249
|
var BUSY = /* @__PURE__ */ new Set(["EPERM", "EACCES", "EBUSY"]);
|
|
3921
4250
|
function takeRepoLock(file2, mine) {
|
|
3922
4251
|
try {
|
|
3923
|
-
|
|
4252
|
+
fs30.writeFileSync(file2, mine, { flag: "wx" });
|
|
3924
4253
|
return { state: "held" };
|
|
3925
4254
|
} catch (err) {
|
|
3926
4255
|
const code2 = err.code ?? "";
|
|
@@ -3930,8 +4259,8 @@ function takeRepoLock(file2, mine) {
|
|
|
3930
4259
|
let raw = "";
|
|
3931
4260
|
let age = 0;
|
|
3932
4261
|
try {
|
|
3933
|
-
raw =
|
|
3934
|
-
age = Date.now() -
|
|
4262
|
+
raw = fs30.readFileSync(file2, "utf8");
|
|
4263
|
+
age = Date.now() - fs30.statSync(file2).mtimeMs;
|
|
3935
4264
|
} catch {
|
|
3936
4265
|
return { state: "retry" };
|
|
3937
4266
|
}
|
|
@@ -3944,8 +4273,8 @@ function takeRepoLock(file2, mine) {
|
|
|
3944
4273
|
const stale = age > REPO_LOCK_WAIT_MS || (holder ? !pidAlive3(holder.pid) : age > 5e3);
|
|
3945
4274
|
if (stale) {
|
|
3946
4275
|
try {
|
|
3947
|
-
if (
|
|
3948
|
-
|
|
4276
|
+
if (fs30.readFileSync(file2, "utf8") === raw)
|
|
4277
|
+
fs30.rmSync(file2, { force: true });
|
|
3949
4278
|
} catch {
|
|
3950
4279
|
}
|
|
3951
4280
|
return { state: "retry" };
|
|
@@ -3954,13 +4283,13 @@ function takeRepoLock(file2, mine) {
|
|
|
3954
4283
|
}
|
|
3955
4284
|
function releaseRepoLock(file2, mine) {
|
|
3956
4285
|
try {
|
|
3957
|
-
if (
|
|
3958
|
-
|
|
4286
|
+
if (fs30.readFileSync(file2, "utf8") === mine)
|
|
4287
|
+
fs30.rmSync(file2, { force: true, recursive: true, maxRetries: 5 });
|
|
3959
4288
|
} catch {
|
|
3960
4289
|
}
|
|
3961
4290
|
}
|
|
3962
4291
|
async function withRepoLock(common, fn) {
|
|
3963
|
-
const file2 =
|
|
4292
|
+
const file2 = path26.join(common, "lobstah-git.lock");
|
|
3964
4293
|
const mine = JSON.stringify({ pid: process.pid, at: (/* @__PURE__ */ new Date()).toISOString() });
|
|
3965
4294
|
const deadline = Date.now() + REPO_LOCK_WAIT_MS;
|
|
3966
4295
|
let held = false;
|
|
@@ -3981,7 +4310,7 @@ async function withRepoLock(common, fn) {
|
|
|
3981
4310
|
}
|
|
3982
4311
|
}
|
|
3983
4312
|
async function oneAtATime(cwd, fn) {
|
|
3984
|
-
const common = await
|
|
4313
|
+
const common = await git2(cwd, "rev-parse", "--path-format=absolute", "--git-common-dir");
|
|
3985
4314
|
const key = realpath(common);
|
|
3986
4315
|
const run3 = (repoQueues.get(key) ?? Promise.resolve()).then(() => withRepoLock(common, () => fn(common)));
|
|
3987
4316
|
const tail = run3.catch(() => {
|
|
@@ -3996,7 +4325,7 @@ async function oneAtATime(cwd, fn) {
|
|
|
3996
4325
|
}
|
|
3997
4326
|
function fetchStamps(common) {
|
|
3998
4327
|
try {
|
|
3999
|
-
return JSON.parse(
|
|
4328
|
+
return JSON.parse(fs30.readFileSync(path26.join(common, "lobstah-fetch.json"), "utf8"));
|
|
4000
4329
|
} catch {
|
|
4001
4330
|
return {};
|
|
4002
4331
|
}
|
|
@@ -4010,15 +4339,15 @@ async function fetchShared(cwd, remote, ref) {
|
|
|
4010
4339
|
const started = Date.now();
|
|
4011
4340
|
await gitShared(cwd, "fetch", remote, ref);
|
|
4012
4341
|
const stamps = { ...fetchStamps(common), [key]: started };
|
|
4013
|
-
|
|
4342
|
+
fs30.writeFileSync(path26.join(common, "lobstah-fetch.json"), JSON.stringify(stamps, null, 2));
|
|
4014
4343
|
});
|
|
4015
4344
|
}
|
|
4016
4345
|
async function allocate(repo, id, fromRemoteBranch = repo.trunk) {
|
|
4017
4346
|
const dir = worktreePath(id);
|
|
4018
|
-
if (
|
|
4347
|
+
if (fs30.existsSync(dir)) {
|
|
4019
4348
|
throw new Error(`worktree for ${id} already exists at ${dir} \u2014 never allocate a second`);
|
|
4020
4349
|
}
|
|
4021
|
-
if (!
|
|
4350
|
+
if (!fs30.existsSync(repo.path)) {
|
|
4022
4351
|
if (!repo.origin)
|
|
4023
4352
|
throw new Error(`repo path ${repo.path} missing and no origin configured`);
|
|
4024
4353
|
await run2("git", ["clone", repo.origin, repo.path], { env: process.env });
|
|
@@ -4033,11 +4362,11 @@ async function allocate(repo, id, fromRemoteBranch = repo.trunk) {
|
|
|
4033
4362
|
async function recoverWorktree(repo, id) {
|
|
4034
4363
|
const dir = worktreePath(id);
|
|
4035
4364
|
try {
|
|
4036
|
-
if (
|
|
4037
|
-
const branch = await
|
|
4038
|
-
const root = await
|
|
4039
|
-
const common = await
|
|
4040
|
-
const mine = await
|
|
4365
|
+
if (fs30.statSync(path26.join(dir, ".git")).isFile()) {
|
|
4366
|
+
const branch = await git2(dir, "symbolic-ref", "--quiet", "HEAD");
|
|
4367
|
+
const root = await git2(dir, "rev-parse", "--show-toplevel");
|
|
4368
|
+
const common = await git2(dir, "rev-parse", "--path-format=absolute", "--git-common-dir");
|
|
4369
|
+
const mine = await git2(repo.path, "rev-parse", "--path-format=absolute", "--git-common-dir");
|
|
4041
4370
|
if (branch === `refs/heads/lobstah/${id}` && realpath(root) === realpath(dir) && realpath(common) === realpath(mine))
|
|
4042
4371
|
return dir;
|
|
4043
4372
|
}
|
|
@@ -4045,9 +4374,36 @@ async function recoverWorktree(repo, id) {
|
|
|
4045
4374
|
}
|
|
4046
4375
|
throw new Error(`unrecorded worktree at ${dir} for ${id} \u2014 ownership not proven (expected lobstah/${id} in ${repo.path}); inspect and preserve it, then relocate the conflicting checkout before retrying`);
|
|
4047
4376
|
}
|
|
4377
|
+
function setupEnv(repo) {
|
|
4378
|
+
return { ...process.env, npm_config_confirm_modules_purge: "false", ...repo.env ?? {} };
|
|
4379
|
+
}
|
|
4380
|
+
var SetupCommandError = class extends Error {
|
|
4381
|
+
command;
|
|
4382
|
+
exitCode;
|
|
4383
|
+
outputTail;
|
|
4384
|
+
constructor(command, exitCode, outputTail2) {
|
|
4385
|
+
super(`setup command \`${command}\` failed${exitCode !== void 0 ? ` (exit ${exitCode})` : ""}${outputTail2 ? `: ${outputTail2}` : ""}`);
|
|
4386
|
+
this.command = command;
|
|
4387
|
+
this.exitCode = exitCode;
|
|
4388
|
+
this.outputTail = outputTail2;
|
|
4389
|
+
this.name = "SetupCommandError";
|
|
4390
|
+
}
|
|
4391
|
+
};
|
|
4392
|
+
function outputTail(stdout, stderr) {
|
|
4393
|
+
const last = (text) => text.split(/\r?\n/).map((l) => l.trim()).filter(Boolean).slice(-3);
|
|
4394
|
+
const tail = [...last(stdout), ...last(stderr)].join(" / ");
|
|
4395
|
+
return tail.length > 600 ? `\u2026${tail.slice(-600)}` : tail;
|
|
4396
|
+
}
|
|
4048
4397
|
async function runSetup(repo, dir) {
|
|
4049
4398
|
for (const cmd of repo.setup ?? []) {
|
|
4050
|
-
|
|
4399
|
+
const child = shell(cmd, { cwd: dir, env: setupEnv(repo) });
|
|
4400
|
+
child.child.stdin?.end();
|
|
4401
|
+
try {
|
|
4402
|
+
await child;
|
|
4403
|
+
} catch (err) {
|
|
4404
|
+
const e = err;
|
|
4405
|
+
throw new SetupCommandError(cmd, typeof e.code === "number" ? e.code : void 0, outputTail(e.stdout ?? "", e.stderr ?? ""));
|
|
4406
|
+
}
|
|
4051
4407
|
}
|
|
4052
4408
|
recordSetup(repo, dir);
|
|
4053
4409
|
}
|
|
@@ -4071,27 +4427,27 @@ function setupHash(repo, dir) {
|
|
|
4071
4427
|
const h = createHash("sha256");
|
|
4072
4428
|
h.update(JSON.stringify(repo.setup ?? []));
|
|
4073
4429
|
for (const name of LOCKFILES) {
|
|
4074
|
-
const file2 =
|
|
4075
|
-
if (!
|
|
4430
|
+
const file2 = path26.join(dir, name);
|
|
4431
|
+
if (!fs30.existsSync(file2))
|
|
4076
4432
|
continue;
|
|
4077
4433
|
h.update(`\0${name}\0`);
|
|
4078
|
-
h.update(
|
|
4434
|
+
h.update(fs30.readFileSync(file2));
|
|
4079
4435
|
}
|
|
4080
4436
|
return h.digest("hex");
|
|
4081
4437
|
}
|
|
4082
4438
|
function setupRecordFile(dir) {
|
|
4083
4439
|
const gitDir = worktreeGitDir(dir);
|
|
4084
|
-
return gitDir ?
|
|
4440
|
+
return gitDir ? path26.join(gitDir, "lobstah-setup.json") : void 0;
|
|
4085
4441
|
}
|
|
4086
4442
|
function recordSetup(repo, dir) {
|
|
4087
4443
|
const file2 = setupRecordFile(dir);
|
|
4088
4444
|
if (file2)
|
|
4089
|
-
|
|
4445
|
+
fs30.writeFileSync(file2, JSON.stringify({ hash: setupHash(repo, dir), at: (/* @__PURE__ */ new Date()).toISOString() }, null, 2));
|
|
4090
4446
|
}
|
|
4091
4447
|
function recordedSetupHash(dir) {
|
|
4092
4448
|
const file2 = setupRecordFile(dir);
|
|
4093
4449
|
try {
|
|
4094
|
-
return file2 ? JSON.parse(
|
|
4450
|
+
return file2 ? JSON.parse(fs30.readFileSync(file2, "utf8")).hash : void 0;
|
|
4095
4451
|
} catch {
|
|
4096
4452
|
return void 0;
|
|
4097
4453
|
}
|
|
@@ -4104,9 +4460,9 @@ function poolReused(slot, by) {
|
|
|
4104
4460
|
function realpath(p) {
|
|
4105
4461
|
let r;
|
|
4106
4462
|
try {
|
|
4107
|
-
r =
|
|
4463
|
+
r = fs30.realpathSync.native(p);
|
|
4108
4464
|
} catch {
|
|
4109
|
-
r =
|
|
4465
|
+
r = path26.resolve(p);
|
|
4110
4466
|
}
|
|
4111
4467
|
return process.platform === "win32" ? r.toLowerCase() : r;
|
|
4112
4468
|
}
|
|
@@ -4137,8 +4493,8 @@ async function chooseWorktree(input) {
|
|
|
4137
4493
|
return { reuse: false, reason: `origin worktree belongs to repo ${ownerRepo}` };
|
|
4138
4494
|
}
|
|
4139
4495
|
try {
|
|
4140
|
-
const common = await
|
|
4141
|
-
const mine = await
|
|
4496
|
+
const common = await git2(found.path, "rev-parse", "--path-format=absolute", "--git-common-dir");
|
|
4497
|
+
const mine = await git2(repo.path, "rev-parse", "--path-format=absolute", "--git-common-dir");
|
|
4142
4498
|
if (realpath(common) !== realpath(mine))
|
|
4143
4499
|
return { reuse: false, reason: "origin worktree belongs to another repo" };
|
|
4144
4500
|
} catch {
|
|
@@ -4154,8 +4510,8 @@ async function chooseWorktree(input) {
|
|
|
4154
4510
|
for (const t of listTraps()) {
|
|
4155
4511
|
if (typeof t.worktree !== "string")
|
|
4156
4512
|
continue;
|
|
4157
|
-
const rel =
|
|
4158
|
-
if (!rel.startsWith("..") && !
|
|
4513
|
+
const rel = path26.relative(here, realpath(t.worktree));
|
|
4514
|
+
if (!rel.startsWith("..") && !path26.isAbsolute(rel))
|
|
4159
4515
|
return { reuse: false, reason: "origin worktree is a trap\u2019s" };
|
|
4160
4516
|
}
|
|
4161
4517
|
for (const l of ["work", "chore"]) {
|
|
@@ -4172,7 +4528,7 @@ async function chooseWorktree(input) {
|
|
|
4172
4528
|
return { reuse: false, reason: `origin worktree is in use by ${short(holder.id)}` };
|
|
4173
4529
|
let porcelain;
|
|
4174
4530
|
try {
|
|
4175
|
-
porcelain = await
|
|
4531
|
+
porcelain = await git2(found.path, "status", "--porcelain");
|
|
4176
4532
|
} catch {
|
|
4177
4533
|
return { reuse: false, reason: "origin worktree is not a readable git checkout" };
|
|
4178
4534
|
}
|
|
@@ -4202,8 +4558,8 @@ async function prepareReuse(repo, dir) {
|
|
|
4202
4558
|
return { setupRan: true };
|
|
4203
4559
|
}
|
|
4204
4560
|
async function collectEvidence(repo, dir) {
|
|
4205
|
-
const branch = await
|
|
4206
|
-
const log = await
|
|
4561
|
+
const branch = await git2(dir, "rev-parse", "--abbrev-ref", "HEAD");
|
|
4562
|
+
const log = await git2(dir, "log", "--oneline", `origin/${repo.trunk}..HEAD`);
|
|
4207
4563
|
return { branch, commits: log ? log.split("\n") : [] };
|
|
4208
4564
|
}
|
|
4209
4565
|
async function tryGit(cwd, ...args) {
|
|
@@ -4253,7 +4609,7 @@ async function* until(source, stop) {
|
|
|
4253
4609
|
yield next.value;
|
|
4254
4610
|
}
|
|
4255
4611
|
}
|
|
4256
|
-
var sleep = (ms) => new Promise((
|
|
4612
|
+
var sleep = (ms) => new Promise((resolve10) => setTimeout(resolve10, ms));
|
|
4257
4613
|
function deliver(run3, id, lane) {
|
|
4258
4614
|
const msgs = unhandled(id, lane);
|
|
4259
4615
|
for (const m of msgs) {
|
|
@@ -4299,7 +4655,7 @@ async function drive(run3, opts) {
|
|
|
4299
4655
|
let finalAt = 0;
|
|
4300
4656
|
let exit;
|
|
4301
4657
|
let abandon;
|
|
4302
|
-
const abandoned = new Promise((
|
|
4658
|
+
const abandoned = new Promise((resolve10) => abandon = resolve10);
|
|
4303
4659
|
const clearExit = () => {
|
|
4304
4660
|
if (!exit) return;
|
|
4305
4661
|
clearInterval(exit.poll);
|
|
@@ -4583,8 +4939,8 @@ function startWallClock(opts) {
|
|
|
4583
4939
|
import { execFile as execFile3 } from "node:child_process";
|
|
4584
4940
|
import { promisify as promisify3 } from "node:util";
|
|
4585
4941
|
import { fileURLToPath } from "node:url";
|
|
4586
|
-
import * as
|
|
4587
|
-
import * as
|
|
4942
|
+
import * as fs31 from "node:fs";
|
|
4943
|
+
import * as path27 from "node:path";
|
|
4588
4944
|
var exec2 = promisify3(execFile3);
|
|
4589
4945
|
function firstLine(err) {
|
|
4590
4946
|
const stderr = err && typeof err === "object" && "stderr" in err ? String(err.stderr).trim() : "";
|
|
@@ -4610,14 +4966,14 @@ function keepRemote(opts) {
|
|
|
4610
4966
|
shell: process.platform === "win32" && /\.(?:cmd|bat)$/i.test(file2)
|
|
4611
4967
|
})).stdout.trim();
|
|
4612
4968
|
};
|
|
4613
|
-
const
|
|
4969
|
+
const git3 = (...args) => command("git", args);
|
|
4614
4970
|
const note = (message) => mergeEvidence(id, lane, { note: message.slice(0, 300) });
|
|
4615
4971
|
if (existingPrUrl) mergeEvidence(id, lane, { prUrl: existingPrUrl });
|
|
4616
4972
|
const registerWatch = async (url) => {
|
|
4617
|
-
const root =
|
|
4618
|
-
const localCli =
|
|
4973
|
+
const root = path27.resolve(path27.dirname(fileURLToPath(import.meta.url)), "..", "..", "..");
|
|
4974
|
+
const localCli = path27.join(root, "apps", "cli", "dist", "main.js");
|
|
4619
4975
|
const args = ["watch", "add", url, "--for", id];
|
|
4620
|
-
if (
|
|
4976
|
+
if (fs31.existsSync(localCli)) await command(process.execPath, [localCli, ...args], 15e3);
|
|
4621
4977
|
else await command("lobstah", args, 15e3);
|
|
4622
4978
|
};
|
|
4623
4979
|
let lastSeenHead;
|
|
@@ -4634,7 +4990,7 @@ function keepRemote(opts) {
|
|
|
4634
4990
|
await registerWatch(existingWatch.url).catch((err) => note(`PR watch unavailable: ${firstLine(err)}`));
|
|
4635
4991
|
})() : void 0;
|
|
4636
4992
|
const branchName = async () => {
|
|
4637
|
-
const branch = await
|
|
4993
|
+
const branch = await git3("symbolic-ref", "--quiet", "--short", "HEAD").catch(() => "");
|
|
4638
4994
|
if (!branch || branch === trunk || branch === `origin/${trunk}`) return void 0;
|
|
4639
4995
|
return branch;
|
|
4640
4996
|
};
|
|
@@ -4678,14 +5034,14 @@ function keepRemote(opts) {
|
|
|
4678
5034
|
if (!policy.pushEarly || trapClaimed() || existingPrUrl) return;
|
|
4679
5035
|
const branch = await branchName();
|
|
4680
5036
|
if (!branch) return;
|
|
4681
|
-
const head = await
|
|
4682
|
-
const ahead = await
|
|
5037
|
+
const head = await git3("rev-parse", "HEAD");
|
|
5038
|
+
const ahead = await git3("rev-list", "--count", `origin/${trunk}..HEAD`).catch(() => "1");
|
|
4683
5039
|
if (ahead === "0") return;
|
|
4684
5040
|
if (head === lastSeenHead) return;
|
|
4685
5041
|
lastSeenHead = head;
|
|
4686
5042
|
if (head === pushedHead) return;
|
|
4687
5043
|
try {
|
|
4688
|
-
await
|
|
5044
|
+
await git3("push", "-u", "origin", branch);
|
|
4689
5045
|
pushedHead = head;
|
|
4690
5046
|
pushProblem = void 0;
|
|
4691
5047
|
mergeEvidence(id, lane, { branch });
|
|
@@ -4731,12 +5087,12 @@ function keepRemote(opts) {
|
|
|
4731
5087
|
let saved = "no working-tree changes";
|
|
4732
5088
|
if (policy.checkpointOnStop) {
|
|
4733
5089
|
try {
|
|
4734
|
-
const paths = (await
|
|
5090
|
+
const paths = (await git3("ls-files", "-m", "-o", "-d", "--exclude-standard", "-z")).split("\0").filter(Boolean).filter(checkpointAllowed);
|
|
4735
5091
|
if (paths.length) {
|
|
4736
|
-
await
|
|
4737
|
-
const staged = await
|
|
5092
|
+
await git3("add", "-A", "--", ...paths);
|
|
5093
|
+
const staged = await git3("diff", "--cached", "--name-only", "--", ...paths);
|
|
4738
5094
|
if (staged) {
|
|
4739
|
-
await
|
|
5095
|
+
await git3("commit", "--only", "-m", "Checkpoint before runner stop", "--", ...paths);
|
|
4740
5096
|
saved = `checkpoint committed (${staged.split("\n").length} files)`;
|
|
4741
5097
|
}
|
|
4742
5098
|
}
|
|
@@ -4747,7 +5103,7 @@ function keepRemote(opts) {
|
|
|
4747
5103
|
await check().catch((err) => note(`final push unavailable: ${firstLine(err)}`));
|
|
4748
5104
|
await opening;
|
|
4749
5105
|
await watching;
|
|
4750
|
-
const head = await
|
|
5106
|
+
const head = await git3("rev-parse", "--short", "HEAD").catch(() => "unknown");
|
|
4751
5107
|
const pr = readEvidence(id, lane).prUrl;
|
|
4752
5108
|
const message = `${saved}; ${branch}@${head}${pr ? `; ${existingPrUrl ? "existing" : "draft"} PR ${pr}` : ""}${pushProblem ? `; ${pushProblem}` : ""}${draftProblem ? `; ${draftProblem}` : ""}`;
|
|
4753
5109
|
note(message);
|
|
@@ -4780,7 +5136,7 @@ var defaultDeps = {
|
|
|
4780
5136
|
var DONE_WAIT_MS = 2e3;
|
|
4781
5137
|
function within(p, ms, fallback) {
|
|
4782
5138
|
let timer;
|
|
4783
|
-
const late = new Promise((
|
|
5139
|
+
const late = new Promise((resolve10) => timer = setTimeout(() => resolve10(fallback), ms));
|
|
4784
5140
|
return Promise.race([p, late]).finally(() => clearTimeout(timer));
|
|
4785
5141
|
}
|
|
4786
5142
|
var short3 = (s) => s.slice(0, 8);
|
|
@@ -4809,16 +5165,16 @@ function coldNote(cold, cwd, trunk) {
|
|
|
4809
5165
|
}
|
|
4810
5166
|
async function main(activeDir, lane, seams = {}) {
|
|
4811
5167
|
const deps = { ...defaultDeps, ...seams };
|
|
4812
|
-
const id =
|
|
5168
|
+
const id = path28.basename(activeDir);
|
|
4813
5169
|
if (isTrapCatch(id, lane)) throw new Error(`refusing headless runner for trap catch ${id}`);
|
|
4814
5170
|
const status = (verb, note) => appendStatus(id, lane, verb, note);
|
|
4815
5171
|
const cfg = loadConfig();
|
|
4816
|
-
const descriptor = JSON.parse(
|
|
5172
|
+
const descriptor = JSON.parse(fs32.readFileSync(path28.join(activeDir, "descriptor.json"), "utf8"));
|
|
4817
5173
|
const resolved = resolveDispatch(descriptor, cfg);
|
|
4818
5174
|
const repo = cfg.repos[descriptor.repo];
|
|
4819
|
-
const briefFile =
|
|
4820
|
-
if (!
|
|
4821
|
-
const brief =
|
|
5175
|
+
const briefFile = path28.join(activeDir, "brief.md");
|
|
5176
|
+
if (!fs32.existsSync(briefFile)) fs32.writeFileSync(briefFile, descriptor.brief);
|
|
5177
|
+
const brief = fs32.readFileSync(briefFile, "utf8");
|
|
4822
5178
|
const attempts = Number(process.env.LOBSTAH_ATTEMPTS ?? "1");
|
|
4823
5179
|
const wake = process.env.LOBSTAH_WAKE;
|
|
4824
5180
|
const runnerInfo = {
|
|
@@ -4826,7 +5182,7 @@ async function main(activeDir, lane, seams = {}) {
|
|
|
4826
5182
|
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4827
5183
|
attempts
|
|
4828
5184
|
};
|
|
4829
|
-
|
|
5185
|
+
fs32.writeFileSync(path28.join(activeDir, "runner.json"), JSON.stringify(runnerInfo, null, 2));
|
|
4830
5186
|
if (descriptor.systemRepair && descriptor.pr?.url) {
|
|
4831
5187
|
const state = deps.prState(descriptor.pr.url) ?? readPr(parsePrRef(descriptor.pr.url)?.key ?? "")?.state;
|
|
4832
5188
|
if (state === "MERGED" || state === "CLOSED") {
|
|
@@ -4843,14 +5199,14 @@ async function main(activeDir, lane, seams = {}) {
|
|
|
4843
5199
|
resolvedHarness: resolved.harness,
|
|
4844
5200
|
envResume: process.env.LOBSTAH_RESUME
|
|
4845
5201
|
});
|
|
4846
|
-
const wtFile =
|
|
5202
|
+
const wtFile = path28.join(activeDir, "worktree.json");
|
|
4847
5203
|
let recorded;
|
|
4848
5204
|
let recovered = false;
|
|
4849
5205
|
let choice3;
|
|
4850
|
-
if (
|
|
4851
|
-
recorded = JSON.parse(
|
|
4852
|
-
if (!
|
|
4853
|
-
} else if (
|
|
5206
|
+
if (fs32.existsSync(wtFile)) {
|
|
5207
|
+
recorded = JSON.parse(fs32.readFileSync(wtFile, "utf8")).path;
|
|
5208
|
+
if (!fs32.existsSync(recorded)) throw new Error(`recorded worktree ${recorded} is gone`);
|
|
5209
|
+
} else if (fs32.existsSync(worktreePath(id))) {
|
|
4854
5210
|
recorded = await recoverWorktree(repo, id);
|
|
4855
5211
|
recovered = true;
|
|
4856
5212
|
} else if (descriptor.followUp && cfg.limits.reuseWorktree !== false) {
|
|
@@ -4905,7 +5261,7 @@ async function main(activeDir, lane, seams = {}) {
|
|
|
4905
5261
|
if (held) throw new Error(`worktree at ${cwd} is in use by ${held.id} \u2014 wait for that dispatch to release it before retrying`);
|
|
4906
5262
|
if (recovered) {
|
|
4907
5263
|
await deps.prepareReuse(repo, cwd);
|
|
4908
|
-
|
|
5264
|
+
fs32.writeFileSync(wtFile, JSON.stringify({ path: cwd }, null, 2));
|
|
4909
5265
|
}
|
|
4910
5266
|
} else if (choice3?.reuse) {
|
|
4911
5267
|
cwd = choice3.path;
|
|
@@ -4916,17 +5272,17 @@ async function main(activeDir, lane, seams = {}) {
|
|
|
4916
5272
|
type: "runner",
|
|
4917
5273
|
data: { worktree: cwd, worktreeOf: choice3.owner, setupRan }
|
|
4918
5274
|
});
|
|
4919
|
-
|
|
5275
|
+
fs32.writeFileSync(wtFile, JSON.stringify({ path: cwd, of: choice3.owner }, null, 2));
|
|
4920
5276
|
} else if (poolClaim) {
|
|
4921
5277
|
cwd = poolClaim.dir;
|
|
4922
5278
|
await deps.resetPool(repo, cwd, id, descriptor.systemRepair ? descriptor.pr?.headRefName : void 0);
|
|
4923
|
-
|
|
5279
|
+
fs32.writeFileSync(wtFile, JSON.stringify({ path: cwd, pool: poolClaim.label }, null, 2));
|
|
4924
5280
|
} else {
|
|
4925
5281
|
cwd = await deps.allocate(repo, id, descriptor.systemRepair ? descriptor.pr?.headRefName : void 0);
|
|
4926
5282
|
acquireWorktreeLock(cwd, id, lane);
|
|
4927
|
-
|
|
5283
|
+
fs32.writeFileSync(wtFile, JSON.stringify({ path: cwd }, null, 2));
|
|
4928
5284
|
}
|
|
4929
|
-
const worktreeOf = JSON.parse(
|
|
5285
|
+
const worktreeOf = JSON.parse(fs32.readFileSync(wtFile, "utf8")).of;
|
|
4930
5286
|
const inPool = poolSlotOf(cwd);
|
|
4931
5287
|
mergeEvidence(id, lane, { worktree: cwd, worktreeOf, ...inPool ? { pool: poolSlotLabel(inPool.pool, inPool.slot) } : {} });
|
|
4932
5288
|
const existingPr = boundPr(descriptor, lane);
|
|
@@ -4954,21 +5310,21 @@ async function main(activeDir, lane, seams = {}) {
|
|
|
4954
5310
|
const envNudge = [process.env.LOBSTAH_NUDGE, wakeNote()].filter(Boolean).join("\n\n") || void 0;
|
|
4955
5311
|
const planNudge = plan.cold && !envNudge ? coldNote(plan.cold, cwd, repo.trunk) : void 0;
|
|
4956
5312
|
const promptWith = (nudge) => buildPrompt(brief, { id, nudge, attachments: descriptor.attachments, existingPr });
|
|
4957
|
-
const binDir =
|
|
4958
|
-
const workerPath =
|
|
5313
|
+
const binDir = path28.resolve(path28.dirname(fileURLToPath2(import.meta.url)), "..", "..", "..", "bin");
|
|
5314
|
+
const workerPath = fs32.existsSync(path28.join(binDir, "lobstah")) ? `${binDir}${path28.delimiter}${process.env.PATH ?? ""}` : void 0;
|
|
4959
5315
|
let wallClockHit = false;
|
|
4960
5316
|
let current;
|
|
4961
|
-
const wallFile =
|
|
5317
|
+
const wallFile = path28.join(activeDir, "wallclock.json");
|
|
4962
5318
|
const wallState = (() => {
|
|
4963
5319
|
try {
|
|
4964
|
-
return JSON.parse(
|
|
5320
|
+
return JSON.parse(fs32.readFileSync(wallFile, "utf8"));
|
|
4965
5321
|
} catch {
|
|
4966
5322
|
return { elapsedMs: 0, windowMs: resolved.limits.wallClockSecs * 1e3 };
|
|
4967
5323
|
}
|
|
4968
5324
|
})();
|
|
4969
5325
|
const head = () => {
|
|
4970
5326
|
try {
|
|
4971
|
-
return
|
|
5327
|
+
return execFileSync3("git", ["rev-parse", "HEAD"], { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
4972
5328
|
} catch {
|
|
4973
5329
|
return void 0;
|
|
4974
5330
|
}
|
|
@@ -4980,8 +5336,8 @@ async function main(activeDir, lane, seams = {}) {
|
|
|
4980
5336
|
) * 1e3;
|
|
4981
5337
|
const persistWall = (elapsedMs, windowMs) => {
|
|
4982
5338
|
const tmp = uniqueTempPath(wallFile);
|
|
4983
|
-
|
|
4984
|
-
|
|
5339
|
+
fs32.writeFileSync(tmp, JSON.stringify({ ...wallState, elapsedMs, windowMs }));
|
|
5340
|
+
fs32.renameSync(tmp, wallFile);
|
|
4985
5341
|
};
|
|
4986
5342
|
const madeProgress = () => {
|
|
4987
5343
|
const activity = readActivity(id, lane);
|
|
@@ -5147,7 +5503,7 @@ async function main(activeDir, lane, seams = {}) {
|
|
|
5147
5503
|
}
|
|
5148
5504
|
|
|
5149
5505
|
// packages/runner/src/reap.ts
|
|
5150
|
-
import { execFileSync as
|
|
5506
|
+
import { execFileSync as execFileSync4 } from "node:child_process";
|
|
5151
5507
|
|
|
5152
5508
|
// packages/runner/src/windows-processes.ts
|
|
5153
5509
|
var WINDOWS_PROCESS_SNAPSHOT = String.raw`
|
|
@@ -5197,7 +5553,7 @@ public static class LobstahProcessSnapshot {
|
|
|
5197
5553
|
// packages/runner/src/reap.ts
|
|
5198
5554
|
function listProcesses() {
|
|
5199
5555
|
if (process.platform === "win32") {
|
|
5200
|
-
const out2 =
|
|
5556
|
+
const out2 = execFileSync4(
|
|
5201
5557
|
"powershell.exe",
|
|
5202
5558
|
[
|
|
5203
5559
|
"-NoProfile",
|
|
@@ -5209,7 +5565,7 @@ function listProcesses() {
|
|
|
5209
5565
|
);
|
|
5210
5566
|
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 }));
|
|
5211
5567
|
}
|
|
5212
|
-
const out =
|
|
5568
|
+
const out = execFileSync4("ps", ["-A", "-o", "pid=,ppid=,pgid="], {
|
|
5213
5569
|
encoding: "utf8",
|
|
5214
5570
|
timeout: 3e4,
|
|
5215
5571
|
stdio: ["ignore", "pipe", "ignore"]
|
|
@@ -5252,7 +5608,7 @@ async function stopPids(pids, graceMs = 2e3) {
|
|
|
5252
5608
|
if (process.platform === "win32") {
|
|
5253
5609
|
for (const pid of pids) {
|
|
5254
5610
|
try {
|
|
5255
|
-
|
|
5611
|
+
execFileSync4("taskkill", ["/pid", String(pid), "/T", "/F"], { stdio: "ignore", windowsHide: true, timeout: 3e4 });
|
|
5256
5612
|
} catch {
|
|
5257
5613
|
}
|
|
5258
5614
|
}
|
|
@@ -5285,13 +5641,13 @@ async function reapStarted(root = process.pid, graceMs) {
|
|
|
5285
5641
|
var EXIT_LINGER_MS = 5e3;
|
|
5286
5642
|
function runRunner(activeDirArg2, laneArg2) {
|
|
5287
5643
|
const lane = laneArg2 === "chore" ? "chore" : "work";
|
|
5288
|
-
const id =
|
|
5644
|
+
const id = path29.basename(activeDirArg2);
|
|
5289
5645
|
main(activeDirArg2, lane, { reap: () => reapStarted(process.pid) }).catch((err) => {
|
|
5290
5646
|
try {
|
|
5291
5647
|
if (!isFinished(id, lane)) {
|
|
5292
5648
|
appendStatus(id, lane, "failed", String(err instanceof Error ? err.message : err).slice(0, 500));
|
|
5293
5649
|
}
|
|
5294
|
-
|
|
5650
|
+
fs33.renameSync(activeDirArg2, path29.join(laneDirs(lane).done, id));
|
|
5295
5651
|
} catch {
|
|
5296
5652
|
}
|
|
5297
5653
|
process.exitCode = 1;
|