lobstah 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js +1918 -1503
- package/dist/runner.js +612 -293
- package/docs/configuration.md +4 -0
- 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,6 +1395,79 @@ 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
1473
|
function parseHarness(raw, where) {
|
|
@@ -1566,7 +1639,9 @@ var DEFAULT_HELM = {
|
|
|
1566
1639
|
ttlSecs: 1800,
|
|
1567
1640
|
reportSecs: 900,
|
|
1568
1641
|
armGraceSecs: 5,
|
|
1569
|
-
todoStaleDays: 3
|
|
1642
|
+
todoStaleDays: 3,
|
|
1643
|
+
briefTodoLimit: 5,
|
|
1644
|
+
goalsNudgeSecs: 7200
|
|
1570
1645
|
};
|
|
1571
1646
|
var DEFAULT_GLASS = { port: 4949 };
|
|
1572
1647
|
var DEFAULT_WAIT = { baseTimeoutSecs: 900, baseRepeats: 3, maxTimeoutSecs: 14400 };
|
|
@@ -1586,6 +1661,7 @@ var DEFAULT_LIMITS = {
|
|
|
1586
1661
|
attachmentMaxBytes: 25 * 1024 * 1024,
|
|
1587
1662
|
retentionDays: 0,
|
|
1588
1663
|
minFreeGB: 0,
|
|
1664
|
+
cacheMinFreeGB: 50,
|
|
1589
1665
|
reuseWorktree: true,
|
|
1590
1666
|
releaseOnMerge: false
|
|
1591
1667
|
};
|
|
@@ -1597,14 +1673,17 @@ function withConfigPath(parse2) {
|
|
|
1597
1673
|
}
|
|
1598
1674
|
}
|
|
1599
1675
|
function configPath() {
|
|
1600
|
-
return
|
|
1676
|
+
return path6.join(lobstahHome(), "config.toml");
|
|
1601
1677
|
}
|
|
1602
1678
|
function expandHome(p) {
|
|
1603
|
-
return p.startsWith("~/") ?
|
|
1679
|
+
return p.startsWith("~/") ? path6.join(os2.homedir(), p.slice(2)) : p;
|
|
1604
1680
|
}
|
|
1605
1681
|
function loadConfig() {
|
|
1606
1682
|
const file2 = configPath();
|
|
1607
|
-
const raw =
|
|
1683
|
+
const raw = fs7.existsSync(file2) ? parse(fs7.readFileSync(file2, "utf8")) : {};
|
|
1684
|
+
const cacheMinFreeGB = raw.limits?.cacheMinFreeGB ?? DEFAULT_LIMITS.cacheMinFreeGB;
|
|
1685
|
+
if (typeof cacheMinFreeGB !== "number" || !Number.isFinite(cacheMinFreeGB) || cacheMinFreeGB < 0)
|
|
1686
|
+
throw new Error("[limits].cacheMinFreeGB must be a non-negative number");
|
|
1608
1687
|
const petOpen = raw.pet?.open ?? "tab";
|
|
1609
1688
|
if (!["tab", "app", "helm"].includes(petOpen))
|
|
1610
1689
|
throw new Error(`[pet].open must be "tab", "app", or "helm" in ${configPath()}`);
|
|
@@ -1612,6 +1691,10 @@ function loadConfig() {
|
|
|
1612
1691
|
const helm = { ...DEFAULT_HELM, ...raw.helm ?? {} };
|
|
1613
1692
|
if (helm.chat !== "full" && helm.chat !== "brief")
|
|
1614
1693
|
throw new Error('[helm].chat must be "full" or "brief"');
|
|
1694
|
+
for (const key of ["briefTodoLimit", "goalsNudgeSecs"]) {
|
|
1695
|
+
if (typeof helm[key] !== "number" || !Number.isSafeInteger(helm[key]) || helm[key] < 0)
|
|
1696
|
+
throw new Error(`[helm].${key} must be a non-negative whole number in ${configPath()}`);
|
|
1697
|
+
}
|
|
1615
1698
|
const wait = { ...DEFAULT_WAIT, ...raw.wait ?? {} };
|
|
1616
1699
|
for (const key of ["baseTimeoutSecs", "baseRepeats", "maxTimeoutSecs"]) {
|
|
1617
1700
|
if (typeof wait[key] !== "number" || !Number.isSafeInteger(wait[key]) || wait[key] <= 0)
|
|
@@ -1644,6 +1727,8 @@ function loadConfig() {
|
|
|
1644
1727
|
refuseMoved(raw, reposRaw);
|
|
1645
1728
|
const repos = {};
|
|
1646
1729
|
for (const [key, r] of Object.entries(reposRaw)) {
|
|
1730
|
+
if (r.cacheDirs !== void 0 && (!Array.isArray(r.cacheDirs) || r.cacheDirs.some((glob) => typeof glob !== "string" || !validCacheGlob(glob))))
|
|
1731
|
+
throw new Error(`[repos.${key}].cacheDirs must be relative globs inside the worktree, without .. or absolute paths`);
|
|
1647
1732
|
if (r.traps !== void 0 && (typeof r.traps !== "number" || !Number.isSafeInteger(r.traps) || r.traps < 0)) {
|
|
1648
1733
|
throw new Error(`[repos.${key}].traps must be a non-negative whole number`);
|
|
1649
1734
|
}
|
|
@@ -1656,6 +1741,7 @@ function loadConfig() {
|
|
|
1656
1741
|
origin: r.origin ? String(r.origin) : void 0,
|
|
1657
1742
|
trunk: String(r.trunk ?? "main"),
|
|
1658
1743
|
setup: Array.isArray(r.setup) ? r.setup.map(String) : void 0,
|
|
1744
|
+
cacheDirs: r.cacheDirs,
|
|
1659
1745
|
env: r.env ?? void 0,
|
|
1660
1746
|
harness: parseHarness(r.harness, `[repos.${key}.harness]`),
|
|
1661
1747
|
pickup: r.pickup === void 0 ? void 0 : Boolean(r.pickup),
|
|
@@ -1743,25 +1829,25 @@ function firstMeaningfulLine(...outputs) {
|
|
|
1743
1829
|
}
|
|
1744
1830
|
|
|
1745
1831
|
// packages/core/dist/pr-poll.js
|
|
1746
|
-
import * as
|
|
1747
|
-
import * as
|
|
1832
|
+
import * as fs11 from "node:fs";
|
|
1833
|
+
import * as path10 from "node:path";
|
|
1748
1834
|
|
|
1749
1835
|
// packages/core/dist/prs.js
|
|
1750
|
-
import * as
|
|
1751
|
-
import * as
|
|
1836
|
+
import * as fs8 from "node:fs";
|
|
1837
|
+
import * as path7 from "node:path";
|
|
1752
1838
|
function prsDir() {
|
|
1753
|
-
return
|
|
1839
|
+
return path7.join(lobstahHome(), "prs");
|
|
1754
1840
|
}
|
|
1755
1841
|
function prRecordFile(key) {
|
|
1756
1842
|
const ref = parsePrRef(key);
|
|
1757
1843
|
if (!ref)
|
|
1758
1844
|
throw new Error(`not a PR key: ${key}`);
|
|
1759
1845
|
const safe = (s) => s.replace(/[^A-Za-z0-9._-]/g, "_");
|
|
1760
|
-
return
|
|
1846
|
+
return path7.join(prsDir(), `${safe(ref.owner)}__${safe(ref.repo)}__${ref.number}.json`);
|
|
1761
1847
|
}
|
|
1762
1848
|
function readPr(key) {
|
|
1763
1849
|
try {
|
|
1764
|
-
return JSON.parse(
|
|
1850
|
+
return JSON.parse(fs8.readFileSync(prRecordFile(key), "utf8"));
|
|
1765
1851
|
} catch {
|
|
1766
1852
|
return void 0;
|
|
1767
1853
|
}
|
|
@@ -1769,13 +1855,13 @@ function readPr(key) {
|
|
|
1769
1855
|
function readPrs() {
|
|
1770
1856
|
let files;
|
|
1771
1857
|
try {
|
|
1772
|
-
files =
|
|
1858
|
+
files = fs8.readdirSync(prsDir()).filter((f) => f.endsWith(".json"));
|
|
1773
1859
|
} catch {
|
|
1774
1860
|
return [];
|
|
1775
1861
|
}
|
|
1776
1862
|
return files.flatMap((f) => {
|
|
1777
1863
|
try {
|
|
1778
|
-
const r = JSON.parse(
|
|
1864
|
+
const r = JSON.parse(fs8.readFileSync(path7.join(prsDir(), f), "utf8"));
|
|
1779
1865
|
return typeof r.key === "string" && typeof r.url === "string" ? [r] : [];
|
|
1780
1866
|
} catch {
|
|
1781
1867
|
return [];
|
|
@@ -1784,16 +1870,16 @@ function readPrs() {
|
|
|
1784
1870
|
}
|
|
1785
1871
|
|
|
1786
1872
|
// packages/core/dist/watch.js
|
|
1787
|
-
import
|
|
1788
|
-
import * as
|
|
1873
|
+
import fs10 from "node:fs";
|
|
1874
|
+
import * as path9 from "node:path";
|
|
1789
1875
|
|
|
1790
1876
|
// packages/core/dist/github-budget.js
|
|
1791
|
-
import * as
|
|
1792
|
-
import * as
|
|
1793
|
-
var file = () =>
|
|
1877
|
+
import * as fs9 from "node:fs";
|
|
1878
|
+
import * as path8 from "node:path";
|
|
1879
|
+
var file = () => path8.join(lobstahHome(), "github-budget.json");
|
|
1794
1880
|
function read() {
|
|
1795
1881
|
try {
|
|
1796
|
-
return JSON.parse(
|
|
1882
|
+
return JSON.parse(fs9.readFileSync(file(), "utf8"));
|
|
1797
1883
|
} catch {
|
|
1798
1884
|
return { resources: {} };
|
|
1799
1885
|
}
|
|
@@ -1807,27 +1893,27 @@ function githubBlockedUntil(now2 = Date.now()) {
|
|
|
1807
1893
|
|
|
1808
1894
|
// packages/core/dist/watch.js
|
|
1809
1895
|
function watchesDir() {
|
|
1810
|
-
return
|
|
1896
|
+
return path9.join(lobstahHome(), "watches");
|
|
1811
1897
|
}
|
|
1812
1898
|
function slug(key) {
|
|
1813
1899
|
return key.replace(/[^A-Za-z0-9._-]+/g, "-");
|
|
1814
1900
|
}
|
|
1815
1901
|
function watchPath(key) {
|
|
1816
|
-
return
|
|
1902
|
+
return path9.join(watchesDir(), `${slug(key)}.json`);
|
|
1817
1903
|
}
|
|
1818
1904
|
function readWatch(key) {
|
|
1819
1905
|
try {
|
|
1820
|
-
return JSON.parse(
|
|
1906
|
+
return JSON.parse(fs10.readFileSync(watchPath(key), "utf8"));
|
|
1821
1907
|
} catch {
|
|
1822
1908
|
return void 0;
|
|
1823
1909
|
}
|
|
1824
1910
|
}
|
|
1825
1911
|
|
|
1826
1912
|
// packages/core/dist/pr-poll.js
|
|
1827
|
-
var cycleFile = (repo) =>
|
|
1913
|
+
var cycleFile = (repo) => path10.join(lobstahHome(), "pr-polls", `${repo.replace(/[^\w.-]/g, "_")}.json`);
|
|
1828
1914
|
var readCycle = (repo) => {
|
|
1829
1915
|
try {
|
|
1830
|
-
return JSON.parse(
|
|
1916
|
+
return JSON.parse(fs11.readFileSync(cycleFile(repo), "utf8"));
|
|
1831
1917
|
} catch {
|
|
1832
1918
|
return void 0;
|
|
1833
1919
|
}
|
|
@@ -1920,23 +2006,23 @@ function parseUnresolvedThreads(stdout) {
|
|
|
1920
2006
|
}
|
|
1921
2007
|
|
|
1922
2008
|
// packages/core/dist/worktrees.js
|
|
1923
|
-
import * as
|
|
1924
|
-
import * as
|
|
2009
|
+
import * as fs12 from "node:fs";
|
|
2010
|
+
import * as path11 from "node:path";
|
|
1925
2011
|
var LANES = ["work", "chore"];
|
|
1926
2012
|
function worktreePath(id) {
|
|
1927
|
-
return
|
|
2013
|
+
return path11.join(lobstahHome(), "worktrees", id);
|
|
1928
2014
|
}
|
|
1929
2015
|
function readRecord(file2) {
|
|
1930
2016
|
try {
|
|
1931
|
-
const r = JSON.parse(
|
|
2017
|
+
const r = JSON.parse(fs12.readFileSync(file2, "utf8"));
|
|
1932
2018
|
return typeof r.path === "string" ? r : void 0;
|
|
1933
2019
|
} catch {
|
|
1934
2020
|
return void 0;
|
|
1935
2021
|
}
|
|
1936
2022
|
}
|
|
1937
2023
|
function ownerOfPath(p) {
|
|
1938
|
-
const rel =
|
|
1939
|
-
if (!rel || rel.startsWith("..") ||
|
|
2024
|
+
const rel = path11.relative(path11.join(lobstahHome(), "worktrees"), p);
|
|
2025
|
+
if (!rel || rel.startsWith("..") || path11.isAbsolute(rel))
|
|
1940
2026
|
return void 0;
|
|
1941
2027
|
return rel.split(/[\\/]/)[0];
|
|
1942
2028
|
}
|
|
@@ -1949,7 +2035,7 @@ function dispatchWorktree(id, lane) {
|
|
|
1949
2035
|
}
|
|
1950
2036
|
const dirs = laneDirs(l);
|
|
1951
2037
|
for (const dir of [dirs.active, dirs.done]) {
|
|
1952
|
-
const rec = readRecord(
|
|
2038
|
+
const rec = readRecord(path11.join(dir, id, "worktree.json"));
|
|
1953
2039
|
if (rec) {
|
|
1954
2040
|
const owner = rec.of ?? ownerOfPath(rec.path) ?? id;
|
|
1955
2041
|
return { path: rec.path, owner, reused: owner !== id };
|
|
@@ -1961,7 +2047,7 @@ function dispatchWorktree(id, lane) {
|
|
|
1961
2047
|
function laneOf(id) {
|
|
1962
2048
|
for (const l of LANES) {
|
|
1963
2049
|
const d = laneDirs(l);
|
|
1964
|
-
if (
|
|
2050
|
+
if (fs12.existsSync(path11.join(d.queue, `${id}.json`)) || fs12.existsSync(path11.join(d.active, id)) || fs12.existsSync(path11.join(d.done, id))) {
|
|
1965
2051
|
return l;
|
|
1966
2052
|
}
|
|
1967
2053
|
}
|
|
@@ -1981,7 +2067,7 @@ function followUpAncestors(id, lane) {
|
|
|
1981
2067
|
function chainWorktree(followUp) {
|
|
1982
2068
|
for (const id of [followUp, ...followUpAncestors(followUp)]) {
|
|
1983
2069
|
const wt = dispatchWorktree(id, laneOf(id));
|
|
1984
|
-
if (
|
|
2070
|
+
if (fs12.existsSync(wt.path))
|
|
1985
2071
|
return { ...wt, from: id };
|
|
1986
2072
|
}
|
|
1987
2073
|
return void 0;
|
|
@@ -1996,27 +2082,27 @@ function processAlive(pid) {
|
|
|
1996
2082
|
}
|
|
1997
2083
|
}
|
|
1998
2084
|
function worktreeGitDir(wt) {
|
|
1999
|
-
const dotGit =
|
|
2085
|
+
const dotGit = path11.join(wt, ".git");
|
|
2000
2086
|
try {
|
|
2001
|
-
const st =
|
|
2087
|
+
const st = fs12.statSync(dotGit);
|
|
2002
2088
|
if (st.isDirectory())
|
|
2003
2089
|
return dotGit;
|
|
2004
|
-
const m = /^gitdir:\s*(.+?)\s*$/m.exec(
|
|
2005
|
-
return m ?
|
|
2090
|
+
const m = /^gitdir:\s*(.+?)\s*$/m.exec(fs12.readFileSync(dotGit, "utf8"));
|
|
2091
|
+
return m ? path11.resolve(wt, m[1]) : void 0;
|
|
2006
2092
|
} catch {
|
|
2007
2093
|
return void 0;
|
|
2008
2094
|
}
|
|
2009
2095
|
}
|
|
2010
2096
|
function worktreeLockFile(wt) {
|
|
2011
2097
|
const gitDir = worktreeGitDir(wt);
|
|
2012
|
-
return gitDir ?
|
|
2098
|
+
return gitDir ? path11.join(gitDir, "lobstah.lock") : void 0;
|
|
2013
2099
|
}
|
|
2014
2100
|
function readWorktreeLock(wt) {
|
|
2015
2101
|
const file2 = worktreeLockFile(wt);
|
|
2016
2102
|
if (!file2)
|
|
2017
2103
|
return void 0;
|
|
2018
2104
|
try {
|
|
2019
|
-
return JSON.parse(
|
|
2105
|
+
return JSON.parse(fs12.readFileSync(file2, "utf8"));
|
|
2020
2106
|
} catch {
|
|
2021
2107
|
return void 0;
|
|
2022
2108
|
}
|
|
@@ -2024,7 +2110,7 @@ function readWorktreeLock(wt) {
|
|
|
2024
2110
|
function lockIsLive(lock) {
|
|
2025
2111
|
if (lock.kind === "warm")
|
|
2026
2112
|
return processAlive(lock.pid) && Date.now() - (Date.parse(lock.at) || 0) < WARM_LOCK_MAX_MS;
|
|
2027
|
-
return
|
|
2113
|
+
return fs12.existsSync(path11.join(laneDirs(lock.lane).active, lock.id));
|
|
2028
2114
|
}
|
|
2029
2115
|
function worktreeHolder(wt) {
|
|
2030
2116
|
const lock = readWorktreeLock(wt);
|
|
@@ -2037,7 +2123,7 @@ function acquireWorktreeLock(wt, id, lane, kind) {
|
|
|
2037
2123
|
return { id: "(no git dir)", lane, pid: 0, at: mine.at };
|
|
2038
2124
|
for (let attempt2 = 0; attempt2 < 3; attempt2++) {
|
|
2039
2125
|
try {
|
|
2040
|
-
|
|
2126
|
+
fs12.writeFileSync(file2, JSON.stringify(mine, null, 2), { flag: "wx" });
|
|
2041
2127
|
return void 0;
|
|
2042
2128
|
} catch (err) {
|
|
2043
2129
|
if (err.code !== "EEXIST")
|
|
@@ -2045,7 +2131,7 @@ function acquireWorktreeLock(wt, id, lane, kind) {
|
|
|
2045
2131
|
}
|
|
2046
2132
|
let raw;
|
|
2047
2133
|
try {
|
|
2048
|
-
raw =
|
|
2134
|
+
raw = fs12.readFileSync(file2, "utf8");
|
|
2049
2135
|
} catch {
|
|
2050
2136
|
continue;
|
|
2051
2137
|
}
|
|
@@ -2056,14 +2142,14 @@ function acquireWorktreeLock(wt, id, lane, kind) {
|
|
|
2056
2142
|
held2 = void 0;
|
|
2057
2143
|
}
|
|
2058
2144
|
if (held2?.id === id) {
|
|
2059
|
-
|
|
2145
|
+
fs12.writeFileSync(file2, JSON.stringify(mine, null, 2));
|
|
2060
2146
|
return void 0;
|
|
2061
2147
|
}
|
|
2062
2148
|
if (held2 && lockIsLive(held2))
|
|
2063
2149
|
return held2;
|
|
2064
2150
|
try {
|
|
2065
|
-
if (
|
|
2066
|
-
|
|
2151
|
+
if (fs12.readFileSync(file2, "utf8") === raw)
|
|
2152
|
+
fs12.rmSync(file2, { force: true });
|
|
2067
2153
|
} catch {
|
|
2068
2154
|
}
|
|
2069
2155
|
}
|
|
@@ -2075,22 +2161,22 @@ function releaseWorktreeLock(wt, id) {
|
|
|
2075
2161
|
if (!file2)
|
|
2076
2162
|
return;
|
|
2077
2163
|
if (readWorktreeLock(wt)?.id === id)
|
|
2078
|
-
|
|
2164
|
+
fs12.rmSync(file2, { force: true });
|
|
2079
2165
|
}
|
|
2080
2166
|
|
|
2081
2167
|
// packages/core/dist/events.js
|
|
2082
|
-
import * as
|
|
2168
|
+
import * as fs13 from "node:fs";
|
|
2083
2169
|
function appendEvent(id, lane, ev) {
|
|
2084
|
-
|
|
2170
|
+
fs13.appendFileSync(eventsPath(id, lane), `${JSON.stringify(ev)}
|
|
2085
2171
|
`);
|
|
2086
2172
|
}
|
|
2087
2173
|
function touchEvents(id, lane, at = /* @__PURE__ */ new Date()) {
|
|
2088
2174
|
const file2 = eventsPath(id, lane);
|
|
2089
2175
|
try {
|
|
2090
|
-
|
|
2176
|
+
fs13.utimesSync(file2, at, at);
|
|
2091
2177
|
} catch {
|
|
2092
|
-
|
|
2093
|
-
|
|
2178
|
+
fs13.appendFileSync(file2, "");
|
|
2179
|
+
fs13.utimesSync(file2, at, at);
|
|
2094
2180
|
}
|
|
2095
2181
|
}
|
|
2096
2182
|
|
|
@@ -2104,31 +2190,31 @@ function isFinished(id, lane) {
|
|
|
2104
2190
|
}
|
|
2105
2191
|
|
|
2106
2192
|
// packages/core/dist/pools.js
|
|
2107
|
-
import * as
|
|
2108
|
-
import * as
|
|
2193
|
+
import * as fs14 from "node:fs";
|
|
2194
|
+
import * as path12 from "node:path";
|
|
2109
2195
|
function poolsRoot() {
|
|
2110
|
-
return
|
|
2196
|
+
return path12.join(lobstahHome(), "pools");
|
|
2111
2197
|
}
|
|
2112
2198
|
function poolDir(pool) {
|
|
2113
|
-
return
|
|
2199
|
+
return path12.join(poolsRoot(), pool);
|
|
2114
2200
|
}
|
|
2115
2201
|
function poolSlotPath(pool, slot) {
|
|
2116
|
-
return
|
|
2202
|
+
return path12.join(poolDir(pool), String(slot));
|
|
2117
2203
|
}
|
|
2118
2204
|
function slotsDir(pool) {
|
|
2119
|
-
return
|
|
2205
|
+
return path12.join(poolDir(pool), ".slots");
|
|
2120
2206
|
}
|
|
2121
2207
|
function poolSlotOf(p) {
|
|
2122
2208
|
const real = (x) => {
|
|
2123
2209
|
try {
|
|
2124
|
-
return
|
|
2210
|
+
return fs14.realpathSync.native(x);
|
|
2125
2211
|
} catch {
|
|
2126
|
-
return
|
|
2212
|
+
return path12.resolve(x);
|
|
2127
2213
|
}
|
|
2128
2214
|
};
|
|
2129
|
-
for (const [rootDir, dir] of [[poolsRoot(),
|
|
2130
|
-
const rel =
|
|
2131
|
-
if (!rel || rel.startsWith("..") ||
|
|
2215
|
+
for (const [rootDir, dir] of [[poolsRoot(), path12.resolve(p)], [real(poolsRoot()), real(p)]]) {
|
|
2216
|
+
const rel = path12.relative(rootDir, dir);
|
|
2217
|
+
if (!rel || rel.startsWith("..") || path12.isAbsolute(rel))
|
|
2132
2218
|
continue;
|
|
2133
2219
|
const parts = rel.split(/[\\/]/);
|
|
2134
2220
|
if (parts.length !== 2 || !/^[1-9][0-9]*$/.test(parts[1]))
|
|
@@ -2142,20 +2228,20 @@ function poolSlotLabel(pool, slot) {
|
|
|
2142
2228
|
}
|
|
2143
2229
|
function readJson(file2) {
|
|
2144
2230
|
try {
|
|
2145
|
-
return JSON.parse(
|
|
2231
|
+
return JSON.parse(fs14.readFileSync(file2, "utf8"));
|
|
2146
2232
|
} catch {
|
|
2147
2233
|
return void 0;
|
|
2148
2234
|
}
|
|
2149
2235
|
}
|
|
2150
2236
|
function writeJson(file2, value) {
|
|
2151
|
-
|
|
2237
|
+
fs14.mkdirSync(path12.dirname(file2), { recursive: true });
|
|
2152
2238
|
const tmp = uniqueTempPath(file2);
|
|
2153
|
-
|
|
2239
|
+
fs14.writeFileSync(tmp, JSON.stringify(value, null, 2));
|
|
2154
2240
|
atomicRenameSync(tmp, file2);
|
|
2155
2241
|
}
|
|
2156
|
-
var metaFile = (pool, slot) =>
|
|
2157
|
-
var claimFile = (pool, slot) =>
|
|
2158
|
-
var outFile = (pool, slot) =>
|
|
2242
|
+
var metaFile = (pool, slot) => path12.join(slotsDir(pool), `${slot}.json`);
|
|
2243
|
+
var claimFile = (pool, slot) => path12.join(slotsDir(pool), `${slot}.claim.json`);
|
|
2244
|
+
var outFile = (pool, slot) => path12.join(slotsDir(pool), `${slot}.out.json`);
|
|
2159
2245
|
function readSlotMeta(pool, slot) {
|
|
2160
2246
|
return readJson(metaFile(pool, slot)) ?? {};
|
|
2161
2247
|
}
|
|
@@ -2175,7 +2261,7 @@ function writeSlotOut(pool, slot, out) {
|
|
|
2175
2261
|
writeJson(outFile(pool, slot), out);
|
|
2176
2262
|
}
|
|
2177
2263
|
function clearSlotOut(pool, slot) {
|
|
2178
|
-
|
|
2264
|
+
fs14.rmSync(outFile(pool, slot), { force: true });
|
|
2179
2265
|
}
|
|
2180
2266
|
function dispatchHolder(dir) {
|
|
2181
2267
|
const lock = readWorktreeLock(dir);
|
|
@@ -2185,7 +2271,7 @@ function poolSlotView(pool, slot) {
|
|
|
2185
2271
|
const dir = poolSlotPath(pool, slot);
|
|
2186
2272
|
const lastClaim = readSlotClaim(pool, slot)?.id;
|
|
2187
2273
|
const base = { slot, path: dir, ...lastClaim ? { lastClaim } : {} };
|
|
2188
|
-
if (!
|
|
2274
|
+
if (!fs14.existsSync(dir)) {
|
|
2189
2275
|
const meta2 = readSlotMeta(pool, slot);
|
|
2190
2276
|
return { ...base, state: "missing", ...meta2.error ? { reason: meta2.error } : {} };
|
|
2191
2277
|
}
|
|
@@ -2200,8 +2286,8 @@ function poolSlotView(pool, slot) {
|
|
|
2200
2286
|
return { ...base, state: "warming", ...meta.error ? { reason: meta.error } : {} };
|
|
2201
2287
|
return { ...base, state: "free" };
|
|
2202
2288
|
}
|
|
2203
|
-
var warmStateFile = (pool) =>
|
|
2204
|
-
var warmLockFile = (pool) =>
|
|
2289
|
+
var warmStateFile = (pool) => path12.join(poolDir(pool), ".warm-state.json");
|
|
2290
|
+
var warmLockFile = (pool) => path12.join(poolDir(pool), ".warm.lock");
|
|
2205
2291
|
var POOL_WARM_MAX_MS = 60 * 6e4;
|
|
2206
2292
|
function readPoolWarmState(pool) {
|
|
2207
2293
|
return readJson(warmStateFile(pool)) ?? {};
|
|
@@ -2223,15 +2309,15 @@ function poolWarmRunning(pool, now2 = Date.now()) {
|
|
|
2223
2309
|
}
|
|
2224
2310
|
function takePoolWarmLock(pool) {
|
|
2225
2311
|
const file2 = warmLockFile(pool);
|
|
2226
|
-
|
|
2312
|
+
fs14.mkdirSync(path12.dirname(file2), { recursive: true });
|
|
2227
2313
|
const mine = JSON.stringify({ pid: process.pid, at: (/* @__PURE__ */ new Date()).toISOString() });
|
|
2228
2314
|
for (let attempt2 = 0; attempt2 < 2; attempt2++) {
|
|
2229
2315
|
try {
|
|
2230
|
-
|
|
2316
|
+
fs14.writeFileSync(file2, mine, { flag: "wx" });
|
|
2231
2317
|
return () => {
|
|
2232
2318
|
try {
|
|
2233
|
-
if (
|
|
2234
|
-
|
|
2319
|
+
if (fs14.readFileSync(file2, "utf8") === mine)
|
|
2320
|
+
fs14.rmSync(file2, { force: true });
|
|
2235
2321
|
} catch {
|
|
2236
2322
|
}
|
|
2237
2323
|
};
|
|
@@ -2241,7 +2327,7 @@ function takePoolWarmLock(pool) {
|
|
|
2241
2327
|
}
|
|
2242
2328
|
if (poolWarmRunning(pool))
|
|
2243
2329
|
return void 0;
|
|
2244
|
-
|
|
2330
|
+
fs14.rmSync(file2, { force: true });
|
|
2245
2331
|
}
|
|
2246
2332
|
return void 0;
|
|
2247
2333
|
}
|
|
@@ -2250,41 +2336,70 @@ var POOL_FETCH_MS = 10 * 6e4;
|
|
|
2250
2336
|
var POOL_RECHECK_MS = 5 * 6e4;
|
|
2251
2337
|
|
|
2252
2338
|
// packages/core/dist/disk.js
|
|
2253
|
-
import * as
|
|
2339
|
+
import * as fs15 from "node:fs";
|
|
2254
2340
|
var GB = 1024 ** 3;
|
|
2255
2341
|
var statfsFreeBytes = (dir) => {
|
|
2256
|
-
const s =
|
|
2342
|
+
const s = fs15.statfsSync(dir);
|
|
2257
2343
|
return Number(s.bavail) * Number(s.bsize);
|
|
2258
2344
|
};
|
|
2259
2345
|
function formatGB(bytes) {
|
|
2260
2346
|
return `${(bytes / GB).toFixed(1).replace(/\.0$/, "")} GB`;
|
|
2261
2347
|
}
|
|
2262
2348
|
|
|
2349
|
+
// packages/core/dist/roster.js
|
|
2350
|
+
import * as fs16 from "node:fs";
|
|
2351
|
+
import * as path13 from "node:path";
|
|
2352
|
+
function rosterDir() {
|
|
2353
|
+
return path13.join(lobstahHome(), "roster");
|
|
2354
|
+
}
|
|
2355
|
+
function rosterPath(trapId) {
|
|
2356
|
+
return path13.join(rosterDir(), `${trapId}.json`);
|
|
2357
|
+
}
|
|
2358
|
+
function readRoster(trapId) {
|
|
2359
|
+
if (!/^[a-z0-9-]+$/.test(trapId))
|
|
2360
|
+
return void 0;
|
|
2361
|
+
try {
|
|
2362
|
+
const parsed = JSON.parse(fs16.readFileSync(rosterPath(trapId), "utf8"));
|
|
2363
|
+
return parsed.trapId === trapId && typeof parsed.name === "string" ? parsed : void 0;
|
|
2364
|
+
} catch {
|
|
2365
|
+
return void 0;
|
|
2366
|
+
}
|
|
2367
|
+
}
|
|
2368
|
+
function listRoster() {
|
|
2369
|
+
let files;
|
|
2370
|
+
try {
|
|
2371
|
+
files = fs16.readdirSync(rosterDir()).filter((f) => f.endsWith(".json"));
|
|
2372
|
+
} catch {
|
|
2373
|
+
return [];
|
|
2374
|
+
}
|
|
2375
|
+
return files.map((f) => readRoster(f.slice(0, -".json".length))).filter((e) => e !== void 0).sort((a, b) => a.name.localeCompare(b.name));
|
|
2376
|
+
}
|
|
2377
|
+
|
|
2263
2378
|
// packages/core/dist/inbox.js
|
|
2264
|
-
import * as
|
|
2265
|
-
import * as
|
|
2379
|
+
import * as fs17 from "node:fs";
|
|
2380
|
+
import * as path14 from "node:path";
|
|
2266
2381
|
var metaName = (file2) => file2.replace(/\.msg$/, ".meta.json");
|
|
2267
2382
|
function inboxDir(id, lane) {
|
|
2268
|
-
return
|
|
2383
|
+
return path14.join(laneDirs(lane).inbox, id);
|
|
2269
2384
|
}
|
|
2270
2385
|
function unhandled(id, lane) {
|
|
2271
2386
|
const dir = inboxDir(id, lane);
|
|
2272
|
-
return readDirIfPresent(dir).filter((f) => f.endsWith(".msg")).sort().map((f) => ({ file: f, text:
|
|
2387
|
+
return readDirIfPresent(dir).filter((f) => f.endsWith(".msg")).sort().map((f) => ({ file: f, text: fs17.readFileSync(path14.join(dir, f), "utf8") }));
|
|
2273
2388
|
}
|
|
2274
2389
|
function acknowledge(id, lane, file2) {
|
|
2275
2390
|
const dir = inboxDir(id, lane);
|
|
2276
|
-
|
|
2277
|
-
|
|
2391
|
+
fs17.mkdirSync(path14.join(dir, "handled"), { recursive: true });
|
|
2392
|
+
fs17.renameSync(path14.join(dir, file2), path14.join(dir, "handled", file2));
|
|
2278
2393
|
try {
|
|
2279
|
-
|
|
2394
|
+
fs17.renameSync(path14.join(dir, metaName(file2)), path14.join(dir, "handled", metaName(file2)));
|
|
2280
2395
|
} catch {
|
|
2281
2396
|
}
|
|
2282
2397
|
}
|
|
2283
2398
|
|
|
2284
2399
|
// packages/core/dist/resume.js
|
|
2285
|
-
import * as
|
|
2400
|
+
import * as fs18 from "node:fs";
|
|
2286
2401
|
import * as os3 from "node:os";
|
|
2287
|
-
import * as
|
|
2402
|
+
import * as path15 from "node:path";
|
|
2288
2403
|
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
2289
2404
|
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-([0-9a-f])[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
2290
2405
|
function harnessFromSessionId(sessionId) {
|
|
@@ -2295,7 +2410,7 @@ function claimOf(id, lane) {
|
|
|
2295
2410
|
const dirs = laneDirs(lane);
|
|
2296
2411
|
for (const dir of [dirs.active, dirs.done]) {
|
|
2297
2412
|
try {
|
|
2298
|
-
return JSON.parse(
|
|
2413
|
+
return JSON.parse(fs18.readFileSync(path15.join(dir, id, "claim.json"), "utf8"));
|
|
2299
2414
|
} catch {
|
|
2300
2415
|
}
|
|
2301
2416
|
}
|
|
@@ -2345,11 +2460,11 @@ function isUnresumable(error) {
|
|
|
2345
2460
|
return error !== void 0 && UNRESUMABLE.test(error);
|
|
2346
2461
|
}
|
|
2347
2462
|
function worktreeProgress(worktree, trunk) {
|
|
2348
|
-
if (!worktree || !
|
|
2463
|
+
if (!worktree || !fs18.existsSync(worktree))
|
|
2349
2464
|
return "No worktree progress recorded.";
|
|
2350
|
-
const
|
|
2351
|
-
const commits = trunk ?
|
|
2352
|
-
const status =
|
|
2465
|
+
const git3 = (...a) => spawnSync2("git", a, { cwd: worktree, encoding: "utf8" }).stdout?.trim() ?? "";
|
|
2466
|
+
const commits = trunk ? git3("log", "--oneline", `origin/${trunk}..HEAD`) : git3("log", "--oneline", "-15");
|
|
2467
|
+
const status = git3("status", "--short");
|
|
2353
2468
|
return `Commits so far:
|
|
2354
2469
|
${commits || "(none)"}
|
|
2355
2470
|
|
|
@@ -2378,31 +2493,31 @@ function handoffNote(fromHarness, progress, why) {
|
|
|
2378
2493
|
${progress}`;
|
|
2379
2494
|
}
|
|
2380
2495
|
function codexHome(env = process.env) {
|
|
2381
|
-
return env.CODEX_HOME ??
|
|
2496
|
+
return env.CODEX_HOME ?? path15.join(os3.homedir(), ".codex");
|
|
2382
2497
|
}
|
|
2383
2498
|
function codexRolloutFile(threadId, home = codexHome()) {
|
|
2384
2499
|
const suffix = `-${threadId}.jsonl`;
|
|
2385
2500
|
const walk = (dir, depth) => {
|
|
2386
2501
|
let entries;
|
|
2387
2502
|
try {
|
|
2388
|
-
entries =
|
|
2503
|
+
entries = fs18.readdirSync(dir, { withFileTypes: true });
|
|
2389
2504
|
} catch {
|
|
2390
2505
|
return void 0;
|
|
2391
2506
|
}
|
|
2392
2507
|
for (const e of entries) {
|
|
2393
2508
|
if (e.isFile() && e.name.startsWith("rollout-") && e.name.endsWith(suffix))
|
|
2394
|
-
return
|
|
2509
|
+
return path15.join(dir, e.name);
|
|
2395
2510
|
}
|
|
2396
2511
|
if (depth === 0)
|
|
2397
2512
|
return void 0;
|
|
2398
2513
|
for (const e of entries.filter((x) => x.isDirectory()).sort((a, b) => b.name.localeCompare(a.name))) {
|
|
2399
|
-
const hit = walk(
|
|
2514
|
+
const hit = walk(path15.join(dir, e.name), depth - 1);
|
|
2400
2515
|
if (hit)
|
|
2401
2516
|
return hit;
|
|
2402
2517
|
}
|
|
2403
2518
|
return void 0;
|
|
2404
2519
|
};
|
|
2405
|
-
return walk(
|
|
2520
|
+
return walk(path15.join(home, "sessions"), 3) ?? walk(path15.join(home, "archived_sessions"), 0);
|
|
2406
2521
|
}
|
|
2407
2522
|
function codexDesktopThread(threadId, home = codexHome()) {
|
|
2408
2523
|
const file2 = codexRolloutFile(threadId, home);
|
|
@@ -2410,12 +2525,12 @@ function codexDesktopThread(threadId, home = codexHome()) {
|
|
|
2410
2525
|
return void 0;
|
|
2411
2526
|
let head = "";
|
|
2412
2527
|
try {
|
|
2413
|
-
const fd =
|
|
2528
|
+
const fd = fs18.openSync(file2, "r");
|
|
2414
2529
|
try {
|
|
2415
2530
|
const buf = Buffer.alloc(4096);
|
|
2416
|
-
head = buf.subarray(0,
|
|
2531
|
+
head = buf.subarray(0, fs18.readSync(fd, buf, 0, buf.length, 0)).toString("utf8");
|
|
2417
2532
|
} finally {
|
|
2418
|
-
|
|
2533
|
+
fs18.closeSync(fd);
|
|
2419
2534
|
}
|
|
2420
2535
|
} catch {
|
|
2421
2536
|
return void 0;
|
|
@@ -2429,16 +2544,16 @@ var CODEX_DESKTOP_THREAD = "Codex desktop thread; not resumable from the CLI";
|
|
|
2429
2544
|
|
|
2430
2545
|
// packages/core/dist/notices.js
|
|
2431
2546
|
function noticesDir() {
|
|
2432
|
-
return
|
|
2547
|
+
return path16.join(lobstahHome(), "notices");
|
|
2433
2548
|
}
|
|
2434
2549
|
var counter = 0;
|
|
2435
2550
|
function postNotice(n) {
|
|
2436
2551
|
const dir = noticesDir();
|
|
2437
|
-
|
|
2552
|
+
fs19.mkdirSync(dir, { recursive: true });
|
|
2438
2553
|
if (n.dedupeKey) {
|
|
2439
|
-
const marker =
|
|
2554
|
+
const marker = path16.join(dir, `.dedupe-${n.dedupeKey.replace(/[^A-Za-z0-9_-]/g, "_")}`);
|
|
2440
2555
|
try {
|
|
2441
|
-
|
|
2556
|
+
fs19.writeFileSync(marker, "", { flag: "wx" });
|
|
2442
2557
|
} catch {
|
|
2443
2558
|
return void 0;
|
|
2444
2559
|
}
|
|
@@ -2456,9 +2571,9 @@ function postNotice(n) {
|
|
|
2456
2571
|
...n.quiet ? { quiet: true } : {},
|
|
2457
2572
|
...n.stateHash ? { stateHash: n.stateHash } : {}
|
|
2458
2573
|
};
|
|
2459
|
-
const file2 =
|
|
2574
|
+
const file2 = path16.join(dir, `${seq}.json`);
|
|
2460
2575
|
const tmp = uniqueTempPath(file2);
|
|
2461
|
-
|
|
2576
|
+
fs19.writeFileSync(tmp, JSON.stringify(notice, null, 2));
|
|
2462
2577
|
atomicRenameSync(tmp, file2);
|
|
2463
2578
|
return notice;
|
|
2464
2579
|
}
|
|
@@ -2474,15 +2589,208 @@ function attachmentBlock(attachments) {
|
|
|
2474
2589
|
].join("\n");
|
|
2475
2590
|
}
|
|
2476
2591
|
|
|
2592
|
+
// packages/core/dist/cache-cleanup.js
|
|
2593
|
+
import * as fs20 from "node:fs";
|
|
2594
|
+
import * as path17 from "node:path";
|
|
2595
|
+
import { execFileSync } from "node:child_process";
|
|
2596
|
+
var git = (dir, args) => execFileSync("git", ["-C", dir, ...args], {
|
|
2597
|
+
encoding: "utf8",
|
|
2598
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
2599
|
+
maxBuffer: 64 * 1024 * 1024
|
|
2600
|
+
});
|
|
2601
|
+
function repoCachesConfigured(repo) {
|
|
2602
|
+
try {
|
|
2603
|
+
return repo !== void 0 && !!loadConfig().repos[repo]?.cacheDirs?.length;
|
|
2604
|
+
} catch {
|
|
2605
|
+
return false;
|
|
2606
|
+
}
|
|
2607
|
+
}
|
|
2608
|
+
function cacheTrapIdle(trap) {
|
|
2609
|
+
const live = readTrap(trap.trapId);
|
|
2610
|
+
if (!live?.claimed)
|
|
2611
|
+
return true;
|
|
2612
|
+
const lane = laneOf(live.claimed);
|
|
2613
|
+
if (!lane)
|
|
2614
|
+
return false;
|
|
2615
|
+
const verb = readStatusLog(live.claimed, lane).at(-1)?.verb;
|
|
2616
|
+
return verb !== void 0 && verb !== "working";
|
|
2617
|
+
}
|
|
2618
|
+
function cacheWorktree(root, repoPath) {
|
|
2619
|
+
const canonical = (dir) => {
|
|
2620
|
+
const real = fs20.realpathSync.native(dir);
|
|
2621
|
+
return process.platform === "win32" ? real.toLowerCase() : real;
|
|
2622
|
+
};
|
|
2623
|
+
if (fs20.lstatSync(root).isSymbolicLink())
|
|
2624
|
+
return false;
|
|
2625
|
+
const top = git(root, ["rev-parse", "--show-toplevel"]).trim();
|
|
2626
|
+
const common = path17.resolve(root, git(root, ["rev-parse", "--git-common-dir"]).trim());
|
|
2627
|
+
const privateGit = git(root, ["rev-parse", "--absolute-git-dir"]).trim();
|
|
2628
|
+
const repoCommon = path17.resolve(repoPath, git(repoPath, ["rev-parse", "--git-common-dir"]).trim());
|
|
2629
|
+
return canonical(root) === canonical(top) && canonical(common) !== canonical(privateGit) && canonical(common) === canonical(repoCommon);
|
|
2630
|
+
}
|
|
2631
|
+
function safeCacheTarget(root, target, tracked) {
|
|
2632
|
+
const relative6 = path17.relative(root, target);
|
|
2633
|
+
if (fs20.lstatSync(root).isSymbolicLink())
|
|
2634
|
+
return false;
|
|
2635
|
+
if (!relative6 || relative6.startsWith("..") || path17.isAbsolute(relative6))
|
|
2636
|
+
return false;
|
|
2637
|
+
let current = root;
|
|
2638
|
+
for (const part of relative6.split(path17.sep)) {
|
|
2639
|
+
current = path17.join(current, part);
|
|
2640
|
+
if (part.toLowerCase() === ".git" || fs20.lstatSync(current).isSymbolicLink())
|
|
2641
|
+
return false;
|
|
2642
|
+
}
|
|
2643
|
+
const name = relative6.split(path17.sep).join("/").toLowerCase();
|
|
2644
|
+
return !tracked.some((trackedPath) => {
|
|
2645
|
+
const file2 = trackedPath.toLowerCase();
|
|
2646
|
+
return file2 === name || file2.startsWith(name + "/") || name.startsWith(file2 + "/");
|
|
2647
|
+
});
|
|
2648
|
+
}
|
|
2649
|
+
function cacheBytes(target) {
|
|
2650
|
+
const stat = fs20.lstatSync(target);
|
|
2651
|
+
if (stat.isSymbolicLink())
|
|
2652
|
+
return 0;
|
|
2653
|
+
if (!stat.isDirectory())
|
|
2654
|
+
return process.platform === "win32" || stat.blocks === void 0 ? stat.size : stat.blocks * 512;
|
|
2655
|
+
const entries = fs20.readdirSync(target);
|
|
2656
|
+
if (entries.some((name) => name.toLowerCase() === ".git"))
|
|
2657
|
+
throw new Error("nested repository is not a cache");
|
|
2658
|
+
return entries.reduce((bytes, name) => bytes + cacheBytes(path17.join(target, name)), 0);
|
|
2659
|
+
}
|
|
2660
|
+
function planTrapCache(trap, cfg) {
|
|
2661
|
+
const repo = trap.repo ? cfg.repos[trap.repo] : void 0;
|
|
2662
|
+
if (!repo?.cacheDirs?.length || !cacheTrapIdle(trap))
|
|
2663
|
+
return void 0;
|
|
2664
|
+
try {
|
|
2665
|
+
const root = fs20.realpathSync.native(trap.worktree);
|
|
2666
|
+
if (!cacheWorktree(trap.worktree, repo.path))
|
|
2667
|
+
return void 0;
|
|
2668
|
+
const tracked = git(root, ["ls-files", "-z"]).split("\0").filter(Boolean);
|
|
2669
|
+
const targets = [];
|
|
2670
|
+
let bytes = 0;
|
|
2671
|
+
for (const target of cacheDirectories(root, repo.cacheDirs)) {
|
|
2672
|
+
try {
|
|
2673
|
+
if (!safeCacheTarget(root, target, tracked))
|
|
2674
|
+
continue;
|
|
2675
|
+
const size = cacheBytes(target);
|
|
2676
|
+
targets.push(target);
|
|
2677
|
+
bytes += size;
|
|
2678
|
+
} catch {
|
|
2679
|
+
}
|
|
2680
|
+
}
|
|
2681
|
+
return targets.length ? { trapId: trap.trapId, repo: trap.repo, worktree: root, targets, bytes } : void 0;
|
|
2682
|
+
} catch {
|
|
2683
|
+
return void 0;
|
|
2684
|
+
}
|
|
2685
|
+
}
|
|
2686
|
+
function planTrapCaches(cfg = loadConfig()) {
|
|
2687
|
+
const traps = new Map([...listRoster(), ...listTraps()].map((trap) => [trap.trapId, trap]));
|
|
2688
|
+
return [...traps.values()].flatMap((trap) => {
|
|
2689
|
+
const plan = planTrapCache(trap, cfg);
|
|
2690
|
+
return plan ? [plan] : [];
|
|
2691
|
+
}).sort((a, b) => b.bytes - a.bytes || a.trapId.localeCompare(b.trapId));
|
|
2692
|
+
}
|
|
2693
|
+
function clearTrapCaches(trap, cfg = loadConfig()) {
|
|
2694
|
+
if (!trap.repo || !cfg.repos[trap.repo]?.cacheDirs?.length)
|
|
2695
|
+
return 0;
|
|
2696
|
+
return withTrapCacheLock(trap.trapId, () => {
|
|
2697
|
+
const plan = planTrapCache(trap, cfg);
|
|
2698
|
+
if (!plan)
|
|
2699
|
+
return 0;
|
|
2700
|
+
let bytes = 0;
|
|
2701
|
+
for (const target of plan.targets) {
|
|
2702
|
+
try {
|
|
2703
|
+
const tracked = git(plan.worktree, ["ls-files", "-z"]).split("\0").filter(Boolean);
|
|
2704
|
+
if (!cacheTrapIdle(trap) || !safeCacheTarget(plan.worktree, target, tracked))
|
|
2705
|
+
continue;
|
|
2706
|
+
const size = cacheBytes(target);
|
|
2707
|
+
fs20.rmSync(target, { recursive: true, force: true });
|
|
2708
|
+
bytes += size;
|
|
2709
|
+
} catch {
|
|
2710
|
+
}
|
|
2711
|
+
}
|
|
2712
|
+
return bytes;
|
|
2713
|
+
});
|
|
2714
|
+
}
|
|
2715
|
+
function clearFinishedTrapCaches(trap, reason) {
|
|
2716
|
+
if (!repoCachesConfigured(trap.repo))
|
|
2717
|
+
return;
|
|
2718
|
+
try {
|
|
2719
|
+
const free = () => {
|
|
2720
|
+
try {
|
|
2721
|
+
return statfsFreeBytes(trap.worktree);
|
|
2722
|
+
} catch {
|
|
2723
|
+
return void 0;
|
|
2724
|
+
}
|
|
2725
|
+
};
|
|
2726
|
+
const before = free();
|
|
2727
|
+
const bytes = clearTrapCaches(trap);
|
|
2728
|
+
const after = free();
|
|
2729
|
+
const recovered = before !== void 0 && after !== void 0 ? Math.max(0, after - before) : void 0;
|
|
2730
|
+
if (bytes > 0)
|
|
2731
|
+
postNotice({
|
|
2732
|
+
kind: "caches-cleared",
|
|
2733
|
+
repo: trap.repo,
|
|
2734
|
+
refId: trap.trapId,
|
|
2735
|
+
quiet: true,
|
|
2736
|
+
text: `trap ${trap.trapId} ${reason}: cleared ${bytes} cache bytes (${formatGB(bytes)})` + (recovered !== void 0 ? `; ${recovered} free bytes recovered` : "")
|
|
2737
|
+
});
|
|
2738
|
+
} catch {
|
|
2739
|
+
}
|
|
2740
|
+
}
|
|
2741
|
+
function recoverTrapCaches(cfg, volume, readFree = statfsFreeBytes, log = () => {
|
|
2742
|
+
}) {
|
|
2743
|
+
if (!Object.values(cfg.repos).some((repo) => repo.cacheDirs?.length))
|
|
2744
|
+
return 0;
|
|
2745
|
+
if (cfg.limits.cacheMinFreeGB === 0)
|
|
2746
|
+
return 0;
|
|
2747
|
+
const threshold = Math.max(cfg.limits.cacheMinFreeGB ?? 50, cfg.limits.minFreeGB ?? 0) * GB;
|
|
2748
|
+
if (!(threshold > 0))
|
|
2749
|
+
return 0;
|
|
2750
|
+
try {
|
|
2751
|
+
const before = readFree(volume);
|
|
2752
|
+
if (before >= threshold)
|
|
2753
|
+
return 0;
|
|
2754
|
+
let bytes = 0;
|
|
2755
|
+
let traps = 0;
|
|
2756
|
+
const device = fs20.statSync(volume).dev;
|
|
2757
|
+
for (const plan of planTrapCaches(cfg)) {
|
|
2758
|
+
if (readFree(volume) >= threshold)
|
|
2759
|
+
break;
|
|
2760
|
+
try {
|
|
2761
|
+
if (fs20.statSync(plan.worktree).dev !== device)
|
|
2762
|
+
continue;
|
|
2763
|
+
const removed = clearTrapCaches(plan, cfg);
|
|
2764
|
+
if (removed > 0) {
|
|
2765
|
+
bytes += removed;
|
|
2766
|
+
traps++;
|
|
2767
|
+
}
|
|
2768
|
+
} catch (error) {
|
|
2769
|
+
log(`cache cleanup kept trap ${plan.trapId}: ${error instanceof Error ? error.message : String(error)}`);
|
|
2770
|
+
}
|
|
2771
|
+
}
|
|
2772
|
+
if (bytes > 0) {
|
|
2773
|
+
const recovered = Math.max(0, readFree(volume) - before);
|
|
2774
|
+
const text = `cache pressure cleanup: ${bytes} cache bytes cleared in ${traps} idle trap(s); ${recovered} free bytes recovered (${formatGB(recovered)})`;
|
|
2775
|
+
postNotice({ kind: "caches-cleared", text });
|
|
2776
|
+
log(text);
|
|
2777
|
+
}
|
|
2778
|
+
return bytes;
|
|
2779
|
+
} catch (error) {
|
|
2780
|
+
log(`cache pressure cleanup skipped: ${error instanceof Error ? error.message : String(error)}`);
|
|
2781
|
+
return 0;
|
|
2782
|
+
}
|
|
2783
|
+
}
|
|
2784
|
+
|
|
2477
2785
|
// packages/core/dist/helm.js
|
|
2478
|
-
import * as
|
|
2479
|
-
import * as
|
|
2786
|
+
import * as fs21 from "node:fs";
|
|
2787
|
+
import * as path18 from "node:path";
|
|
2480
2788
|
function helmDir() {
|
|
2481
|
-
return
|
|
2789
|
+
return path18.join(lobstahHome(), "helm");
|
|
2482
2790
|
}
|
|
2483
2791
|
function listHelms() {
|
|
2484
2792
|
try {
|
|
2485
|
-
return
|
|
2793
|
+
return fs21.readdirSync(helmDir()).filter((f) => f.endsWith(".json")).map((f) => JSON.parse(fs21.readFileSync(path18.join(helmDir(), f), "utf8")));
|
|
2486
2794
|
} catch {
|
|
2487
2795
|
return [];
|
|
2488
2796
|
}
|
|
@@ -2493,39 +2801,39 @@ function liveHelms(ttlMs, now2 = Date.now()) {
|
|
|
2493
2801
|
|
|
2494
2802
|
// packages/core/dist/soak.js
|
|
2495
2803
|
function regPath(trapId) {
|
|
2496
|
-
return
|
|
2804
|
+
return path19.join(soakingDir(), `${trapId}.json`);
|
|
2497
2805
|
}
|
|
2498
2806
|
function readTrap(trapId) {
|
|
2499
2807
|
try {
|
|
2500
|
-
return JSON.parse(
|
|
2808
|
+
return JSON.parse(fs22.readFileSync(regPath(trapId), "utf8"));
|
|
2501
2809
|
} catch {
|
|
2502
2810
|
return void 0;
|
|
2503
2811
|
}
|
|
2504
2812
|
}
|
|
2505
2813
|
function listTraps() {
|
|
2506
2814
|
try {
|
|
2507
|
-
return
|
|
2815
|
+
return fs22.readdirSync(soakingDir()).filter((f) => f.endsWith(".json")).map((f) => JSON.parse(fs22.readFileSync(path19.join(soakingDir(), f), "utf8"))).filter((r) => typeof r.trapId === "string");
|
|
2508
2816
|
} catch {
|
|
2509
2817
|
return [];
|
|
2510
2818
|
}
|
|
2511
2819
|
}
|
|
2512
2820
|
function claimPath(id, lane) {
|
|
2513
|
-
return
|
|
2821
|
+
return path19.join(laneDirs(lane).active, id, "claim.json");
|
|
2514
2822
|
}
|
|
2515
2823
|
function readSessionClaim(id, lane) {
|
|
2516
2824
|
try {
|
|
2517
|
-
return JSON.parse(
|
|
2825
|
+
return JSON.parse(fs22.readFileSync(claimPath(id, lane), "utf8"));
|
|
2518
2826
|
} catch {
|
|
2519
2827
|
return void 0;
|
|
2520
2828
|
}
|
|
2521
2829
|
}
|
|
2522
2830
|
|
|
2523
2831
|
// packages/core/dist/catch-context.js
|
|
2524
|
-
import * as
|
|
2525
|
-
import * as
|
|
2832
|
+
import * as fs23 from "node:fs";
|
|
2833
|
+
import * as path20 from "node:path";
|
|
2526
2834
|
function readCatchContext(dir, id) {
|
|
2527
2835
|
try {
|
|
2528
|
-
return JSON.parse(
|
|
2836
|
+
return JSON.parse(fs23.readFileSync(path20.join(dir, `${id}.catch-context`), "utf8"));
|
|
2529
2837
|
} catch {
|
|
2530
2838
|
return {};
|
|
2531
2839
|
}
|
|
@@ -2538,19 +2846,19 @@ function observeLocalCatch(id, lane, phase, now2 = Date.now()) {
|
|
|
2538
2846
|
const helms = liveHelms(cfg.helm.ttlSecs * 1e3, now2);
|
|
2539
2847
|
const present = repo ? helms.some((h) => h.repos.includes(repo)) : null;
|
|
2540
2848
|
const next = phase === "claim" ? { claimHelm: present, location: "local" } : { ...old, location: "local", helm: old.claimHelm === true || present === true ? true : old.claimHelm === false && present === false ? false : null };
|
|
2541
|
-
const file2 =
|
|
2849
|
+
const file2 = path20.join(dir, `${id}.catch-context`), tmp = uniqueTempPath(file2);
|
|
2542
2850
|
try {
|
|
2543
|
-
|
|
2544
|
-
|
|
2851
|
+
fs23.writeFileSync(tmp, JSON.stringify(next));
|
|
2852
|
+
fs23.renameSync(tmp, file2);
|
|
2545
2853
|
} finally {
|
|
2546
|
-
|
|
2854
|
+
fs23.rmSync(tmp, { force: true });
|
|
2547
2855
|
}
|
|
2548
2856
|
}
|
|
2549
2857
|
|
|
2550
2858
|
// packages/core/dist/stats.js
|
|
2551
2859
|
var DAILY_RETENTION_DAYS = 400;
|
|
2552
2860
|
function statsPath() {
|
|
2553
|
-
return
|
|
2861
|
+
return path21.join(lobstahHome(), "stats.json");
|
|
2554
2862
|
}
|
|
2555
2863
|
function shiftDay(day, days) {
|
|
2556
2864
|
const [y, m, d] = day.split("-").map(Number);
|
|
@@ -2563,7 +2871,7 @@ function localDay(at = Date.now()) {
|
|
|
2563
2871
|
function readCatchFacts(stateDir, id) {
|
|
2564
2872
|
let last;
|
|
2565
2873
|
try {
|
|
2566
|
-
for (const line of
|
|
2874
|
+
for (const line of fs24.readFileSync(path21.join(stateDir, `${id}.status`), "utf8").split("\n")) {
|
|
2567
2875
|
if (!line.trim())
|
|
2568
2876
|
continue;
|
|
2569
2877
|
try {
|
|
@@ -2579,7 +2887,7 @@ function readCatchFacts(stateDir, id) {
|
|
|
2579
2887
|
let trap;
|
|
2580
2888
|
let worker = workerProfile();
|
|
2581
2889
|
try {
|
|
2582
|
-
const evidence = JSON.parse(
|
|
2890
|
+
const evidence = JSON.parse(fs24.readFileSync(path21.join(stateDir, `${id}.evidence`), "utf8"));
|
|
2583
2891
|
const to = evidence.deliveredTo;
|
|
2584
2892
|
if (typeof to === "string" && to.startsWith("wt:"))
|
|
2585
2893
|
trap = to;
|
|
@@ -2662,7 +2970,7 @@ function add(store, facts, now2) {
|
|
|
2662
2970
|
}
|
|
2663
2971
|
function backfillSources() {
|
|
2664
2972
|
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:
|
|
2973
|
+
const backups = readDirIfPresent(lobstahHome()).filter((name) => name.startsWith("state-backup-")).sort().map((name) => ({ dir: path21.join(lobstahHome(), name), live: false })).filter((s) => fs24.statSync(s.dir).isDirectory());
|
|
2666
2974
|
return [...live, ...backups];
|
|
2667
2975
|
}
|
|
2668
2976
|
function backfillStats(now2 = Date.now(), alreadyCounted) {
|
|
@@ -2734,13 +3042,13 @@ function parseStore(text) {
|
|
|
2734
3042
|
var complete2 = (s) => !!s && s.daily !== void 0;
|
|
2735
3043
|
function writeStore(store) {
|
|
2736
3044
|
const file2 = statsPath();
|
|
2737
|
-
|
|
3045
|
+
fs24.mkdirSync(path21.dirname(file2), { recursive: true });
|
|
2738
3046
|
const tmp = uniqueTempPath(file2);
|
|
2739
|
-
|
|
3047
|
+
fs24.writeFileSync(tmp, JSON.stringify(store));
|
|
2740
3048
|
atomicRenameSync(tmp, file2);
|
|
2741
3049
|
}
|
|
2742
3050
|
function withStatsLock(action) {
|
|
2743
|
-
|
|
3051
|
+
fs24.mkdirSync(lobstahHome(), { recursive: true });
|
|
2744
3052
|
return withDirLock(`${statsPath()}.lock`, action, {
|
|
2745
3053
|
staleMs: 12e4,
|
|
2746
3054
|
waitMs: 1e4,
|
|
@@ -2750,7 +3058,7 @@ function withStatsLock(action) {
|
|
|
2750
3058
|
function loadOrBackfill(now2) {
|
|
2751
3059
|
let text;
|
|
2752
3060
|
try {
|
|
2753
|
-
text =
|
|
3061
|
+
text = fs24.readFileSync(statsPath(), "utf8");
|
|
2754
3062
|
} catch (err) {
|
|
2755
3063
|
if (err.code !== "ENOENT")
|
|
2756
3064
|
throw err;
|
|
@@ -2777,7 +3085,7 @@ function loadOrBackfill(now2) {
|
|
|
2777
3085
|
return store2;
|
|
2778
3086
|
}
|
|
2779
3087
|
if (text !== void 0)
|
|
2780
|
-
|
|
3088
|
+
fs24.renameSync(statsPath(), `${statsPath()}.unreadable-${now2}`);
|
|
2781
3089
|
const store = backfillStats(now2);
|
|
2782
3090
|
writeStore(store);
|
|
2783
3091
|
return store;
|
|
@@ -2864,8 +3172,18 @@ function appendStatus(id, lane, verb, note, at, waiting, reported = false) {
|
|
|
2864
3172
|
} catch {
|
|
2865
3173
|
}
|
|
2866
3174
|
}
|
|
2867
|
-
|
|
3175
|
+
const claim = readSessionClaim(id, lane);
|
|
3176
|
+
const trap = claim?.by.startsWith("wt:") ? readTrap(claim.by.slice(3)) : void 0;
|
|
3177
|
+
const write = () => {
|
|
3178
|
+
fs25.appendFileSync(statusPath(id, lane), `${JSON.stringify(entry)}
|
|
2868
3179
|
`);
|
|
3180
|
+
};
|
|
3181
|
+
if (trap && repoCachesConfigured(trap.repo))
|
|
3182
|
+
withTrapCacheLock(trap.trapId, write);
|
|
3183
|
+
else
|
|
3184
|
+
write();
|
|
3185
|
+
if (trap && trap.claimed === id && (verb === "done" || verb === "failed"))
|
|
3186
|
+
clearFinishedTrapCaches(trap, verb);
|
|
2869
3187
|
if (verb === "done") {
|
|
2870
3188
|
try {
|
|
2871
3189
|
recordCatch(id, lane);
|
|
@@ -2876,9 +3194,9 @@ function appendStatus(id, lane, verb, note, at, waiting, reported = false) {
|
|
|
2876
3194
|
}
|
|
2877
3195
|
function readStatusLog(id, lane) {
|
|
2878
3196
|
const file2 = statusPath(id, lane);
|
|
2879
|
-
if (!
|
|
3197
|
+
if (!fs25.existsSync(file2))
|
|
2880
3198
|
return [];
|
|
2881
|
-
return
|
|
3199
|
+
return fs25.readFileSync(file2, "utf8").split("\n").filter(Boolean).flatMap((line) => {
|
|
2882
3200
|
try {
|
|
2883
3201
|
const parsed = JSON.parse(line);
|
|
2884
3202
|
return isVerb(parsed.verb) ? [parsed] : [];
|
|
@@ -2894,28 +3212,28 @@ function pausedWaiting(entry) {
|
|
|
2894
3212
|
// packages/core/dist/queue.js
|
|
2895
3213
|
function requeue(id, lane) {
|
|
2896
3214
|
const dirs = laneDirs(lane);
|
|
2897
|
-
const activeDir =
|
|
2898
|
-
const file2 =
|
|
3215
|
+
const activeDir = path22.join(dirs.active, id);
|
|
3216
|
+
const file2 = path22.join(activeDir, "descriptor.json");
|
|
2899
3217
|
const d = { ...readDescriptor(id, lane), queuedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
2900
3218
|
const tmp = uniqueTempPath(file2);
|
|
2901
|
-
|
|
3219
|
+
fs26.writeFileSync(tmp, JSON.stringify(d, null, 2));
|
|
2902
3220
|
atomicRenameSync(tmp, file2);
|
|
2903
|
-
|
|
2904
|
-
|
|
3221
|
+
fs26.renameSync(file2, path22.join(dirs.queue, `${id}.json`));
|
|
3222
|
+
fs26.rmSync(activeDir, { recursive: true, force: true });
|
|
2905
3223
|
}
|
|
2906
3224
|
function readDescriptor(id, lane) {
|
|
2907
|
-
const file2 =
|
|
2908
|
-
return JSON.parse(
|
|
3225
|
+
const file2 = path22.join(laneDirs(lane).active, id, "descriptor.json");
|
|
3226
|
+
return JSON.parse(fs26.readFileSync(file2, "utf8"));
|
|
2909
3227
|
}
|
|
2910
3228
|
function storedDescriptor(id, lane) {
|
|
2911
3229
|
const dirs = laneDirs(lane);
|
|
2912
3230
|
for (const file2 of [
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
3231
|
+
path22.join(dirs.queue, `${id}.json`),
|
|
3232
|
+
path22.join(dirs.active, id, "descriptor.json"),
|
|
3233
|
+
path22.join(dirs.done, id, "descriptor.json")
|
|
2916
3234
|
]) {
|
|
2917
3235
|
try {
|
|
2918
|
-
return JSON.parse(
|
|
3236
|
+
return JSON.parse(fs26.readFileSync(file2, "utf8"));
|
|
2919
3237
|
} catch {
|
|
2920
3238
|
}
|
|
2921
3239
|
}
|
|
@@ -2926,10 +3244,10 @@ function activeIds(lane) {
|
|
|
2926
3244
|
}
|
|
2927
3245
|
function complete(id, lane) {
|
|
2928
3246
|
const dirs = laneDirs(lane);
|
|
2929
|
-
|
|
3247
|
+
fs26.renameSync(path22.join(dirs.active, id), path22.join(dirs.done, id));
|
|
2930
3248
|
}
|
|
2931
3249
|
function cancelRequested(id, lane) {
|
|
2932
|
-
return
|
|
3250
|
+
return fs26.existsSync(path22.join(laneDirs(lane).active, id, "cancel"));
|
|
2933
3251
|
}
|
|
2934
3252
|
|
|
2935
3253
|
// packages/core/dist/backend.js
|
|
@@ -2978,21 +3296,21 @@ var ANSWER_EXTENSIONS = Object.keys(ANSWER_TYPES);
|
|
|
2978
3296
|
var ONCE_TTL_MS = 60 * 60 * 1e3;
|
|
2979
3297
|
|
|
2980
3298
|
// packages/core/dist/harness.js
|
|
2981
|
-
import * as
|
|
2982
|
-
import * as
|
|
3299
|
+
import * as fs27 from "node:fs";
|
|
3300
|
+
import * as path23 from "node:path";
|
|
2983
3301
|
import { createRequire } from "node:module";
|
|
2984
3302
|
function resolveOnPath(bin, pathVar = process.env.PATH) {
|
|
2985
3303
|
if (!pathVar)
|
|
2986
3304
|
return void 0;
|
|
2987
3305
|
const names = process.platform === "win32" ? [bin, `${bin}.exe`, `${bin}.cmd`, `${bin}.bat`] : [bin];
|
|
2988
|
-
for (const dir of pathVar.split(
|
|
3306
|
+
for (const dir of pathVar.split(path23.delimiter)) {
|
|
2989
3307
|
if (!dir)
|
|
2990
3308
|
continue;
|
|
2991
3309
|
for (const name of names) {
|
|
2992
|
-
const candidate =
|
|
3310
|
+
const candidate = path23.join(dir, name);
|
|
2993
3311
|
try {
|
|
2994
|
-
|
|
2995
|
-
if (
|
|
3312
|
+
fs27.accessSync(candidate, fs27.constants.X_OK);
|
|
3313
|
+
if (fs27.statSync(candidate).isFile())
|
|
2996
3314
|
return candidate;
|
|
2997
3315
|
} catch {
|
|
2998
3316
|
}
|
|
@@ -3013,8 +3331,8 @@ function codexInvocation(argv) {
|
|
|
3013
3331
|
} catch {
|
|
3014
3332
|
}
|
|
3015
3333
|
for (const dir of require_.resolve.paths("@openai/codex") ?? []) {
|
|
3016
|
-
const cli =
|
|
3017
|
-
if (
|
|
3334
|
+
const cli = path23.join(dir, "@openai", "codex", "bin", "codex.js");
|
|
3335
|
+
if (fs27.existsSync(cli))
|
|
3018
3336
|
return { file: process.execPath, argv: [cli, ...argv] };
|
|
3019
3337
|
}
|
|
3020
3338
|
return void 0;
|
|
@@ -3087,9 +3405,9 @@ function droppedModelNote(harness, dropped) {
|
|
|
3087
3405
|
}
|
|
3088
3406
|
|
|
3089
3407
|
// packages/runner/src/run.ts
|
|
3090
|
-
import * as
|
|
3091
|
-
import * as
|
|
3092
|
-
import { execFileSync as
|
|
3408
|
+
import * as fs32 from "node:fs";
|
|
3409
|
+
import * as path28 from "node:path";
|
|
3410
|
+
import { execFileSync as execFileSync3 } from "node:child_process";
|
|
3093
3411
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
3094
3412
|
|
|
3095
3413
|
// packages/adapters/dist/claude.js
|
|
@@ -3122,7 +3440,7 @@ var AsyncQueue = class {
|
|
|
3122
3440
|
return Promise.resolve({ value: item, done: false });
|
|
3123
3441
|
if (this.closed)
|
|
3124
3442
|
return Promise.resolve({ value: void 0, done: true });
|
|
3125
|
-
return new Promise((
|
|
3443
|
+
return new Promise((resolve10) => this.waiters.push(resolve10));
|
|
3126
3444
|
}
|
|
3127
3445
|
};
|
|
3128
3446
|
}
|
|
@@ -3147,7 +3465,7 @@ var InputGate = class {
|
|
|
3147
3465
|
return msg;
|
|
3148
3466
|
if (this.ended)
|
|
3149
3467
|
return void 0;
|
|
3150
|
-
await new Promise((
|
|
3468
|
+
await new Promise((resolve10) => this.waiter = resolve10);
|
|
3151
3469
|
this.waiter = null;
|
|
3152
3470
|
}
|
|
3153
3471
|
}
|
|
@@ -3292,20 +3610,20 @@ function startClaudeCli(invocation, opts) {
|
|
|
3292
3610
|
}
|
|
3293
3611
|
}
|
|
3294
3612
|
});
|
|
3295
|
-
const done = new Promise((
|
|
3613
|
+
const done = new Promise((resolve10) => {
|
|
3296
3614
|
child.on("error", (err) => {
|
|
3297
3615
|
events.push({ at: now(), type: "error", data: { message: err.message } });
|
|
3298
3616
|
events.close();
|
|
3299
|
-
|
|
3617
|
+
resolve10({ sessionId, error: err.message });
|
|
3300
3618
|
});
|
|
3301
3619
|
child.on("exit", (code2) => {
|
|
3302
3620
|
events.close();
|
|
3303
3621
|
if (code2 === 0)
|
|
3304
|
-
|
|
3622
|
+
resolve10({ sessionId });
|
|
3305
3623
|
else {
|
|
3306
3624
|
const detail = stderrTail.trim().split("\n").at(-1);
|
|
3307
3625
|
const error = `claude exited ${code2}${detail ? ` \u2014 ${detail}` : ""}`;
|
|
3308
|
-
|
|
3626
|
+
resolve10({ sessionId, error });
|
|
3309
3627
|
}
|
|
3310
3628
|
});
|
|
3311
3629
|
});
|
|
@@ -3384,25 +3702,25 @@ function createClaudeAdapter() {
|
|
|
3384
3702
|
}
|
|
3385
3703
|
|
|
3386
3704
|
// packages/adapters/dist/codex.js
|
|
3387
|
-
import * as
|
|
3705
|
+
import * as fs28 from "node:fs";
|
|
3388
3706
|
import * as os4 from "node:os";
|
|
3389
|
-
import * as
|
|
3707
|
+
import * as path24 from "node:path";
|
|
3390
3708
|
import { spawn as spawn2 } from "node:child_process";
|
|
3391
3709
|
function isolatedCodexHome() {
|
|
3392
|
-
const dir =
|
|
3393
|
-
|
|
3394
|
-
const auth =
|
|
3395
|
-
const realAuth =
|
|
3396
|
-
if (!
|
|
3710
|
+
const dir = path24.join(lobstahHome(), "codex-home");
|
|
3711
|
+
fs28.mkdirSync(dir, { recursive: true });
|
|
3712
|
+
const auth = path24.join(dir, "auth.json");
|
|
3713
|
+
const realAuth = path24.join(os4.homedir(), ".codex", "auth.json");
|
|
3714
|
+
if (!fs28.existsSync(auth) && fs28.existsSync(realAuth)) {
|
|
3397
3715
|
try {
|
|
3398
|
-
|
|
3716
|
+
fs28.symlinkSync(realAuth, auth);
|
|
3399
3717
|
} catch {
|
|
3400
|
-
|
|
3718
|
+
fs28.copyFileSync(realAuth, auth);
|
|
3401
3719
|
}
|
|
3402
3720
|
}
|
|
3403
|
-
const cfg =
|
|
3404
|
-
if (!
|
|
3405
|
-
|
|
3721
|
+
const cfg = path24.join(dir, "config.toml");
|
|
3722
|
+
if (!fs28.existsSync(cfg)) {
|
|
3723
|
+
fs28.writeFileSync(cfg, "# lobstah-managed: auth inherited from ~/.codex, interactive config not\n");
|
|
3406
3724
|
}
|
|
3407
3725
|
return dir;
|
|
3408
3726
|
}
|
|
@@ -3454,7 +3772,7 @@ function startCodexCli(invoke, opts) {
|
|
|
3454
3772
|
let current;
|
|
3455
3773
|
let killed = false;
|
|
3456
3774
|
function runTurn(prompt, resumeThread) {
|
|
3457
|
-
return new Promise((
|
|
3775
|
+
return new Promise((resolve10) => {
|
|
3458
3776
|
const inv = invoke(codexExecArgs(opts, prompt, resumeThread));
|
|
3459
3777
|
const child = spawn2(inv.file, inv.argv, {
|
|
3460
3778
|
cwd: opts.cwd,
|
|
@@ -3485,14 +3803,14 @@ function startCodexCli(invoke, opts) {
|
|
|
3485
3803
|
}
|
|
3486
3804
|
}
|
|
3487
3805
|
});
|
|
3488
|
-
child.on("error", (err) =>
|
|
3806
|
+
child.on("error", (err) => resolve10(err.message));
|
|
3489
3807
|
child.on("exit", (code2) => {
|
|
3490
3808
|
if (turnError)
|
|
3491
|
-
return
|
|
3809
|
+
return resolve10(turnError);
|
|
3492
3810
|
if (code2 === 0 || killed)
|
|
3493
|
-
return
|
|
3811
|
+
return resolve10(void 0);
|
|
3494
3812
|
const detail = stderrTail.trim().split("\n").at(-1);
|
|
3495
|
-
|
|
3813
|
+
resolve10(`codex exited ${code2}${detail ? ` \u2014 ${detail}` : ""}`);
|
|
3496
3814
|
});
|
|
3497
3815
|
});
|
|
3498
3816
|
}
|
|
@@ -3605,15 +3923,15 @@ function loadAdapter(name) {
|
|
|
3605
3923
|
}
|
|
3606
3924
|
|
|
3607
3925
|
// packages/worktree/dist/index.js
|
|
3608
|
-
import * as
|
|
3609
|
-
import * as
|
|
3926
|
+
import * as fs30 from "node:fs";
|
|
3927
|
+
import * as path26 from "node:path";
|
|
3610
3928
|
import { createHash } from "node:crypto";
|
|
3611
|
-
import { exec, execFile as execFile2, execFileSync } from "node:child_process";
|
|
3929
|
+
import { exec, execFile as execFile2, execFileSync as execFileSync2 } from "node:child_process";
|
|
3612
3930
|
import { promisify as promisify2 } from "node:util";
|
|
3613
3931
|
|
|
3614
3932
|
// packages/worktree/dist/pool.js
|
|
3615
|
-
import * as
|
|
3616
|
-
import * as
|
|
3933
|
+
import * as fs29 from "node:fs";
|
|
3934
|
+
import * as path25 from "node:path";
|
|
3617
3935
|
import { execFile } from "node:child_process";
|
|
3618
3936
|
import { promisify } from "node:util";
|
|
3619
3937
|
var run = promisify(execFile);
|
|
@@ -3675,17 +3993,17 @@ function takeOut(name, pool, slot, reason, dispatch, notice = true) {
|
|
|
3675
3993
|
function trapIn(dir) {
|
|
3676
3994
|
const real = (p) => {
|
|
3677
3995
|
try {
|
|
3678
|
-
return
|
|
3996
|
+
return fs29.realpathSync.native(p);
|
|
3679
3997
|
} catch {
|
|
3680
|
-
return
|
|
3998
|
+
return path25.resolve(p);
|
|
3681
3999
|
}
|
|
3682
4000
|
};
|
|
3683
4001
|
const here = real(dir);
|
|
3684
4002
|
return listTraps().some((t) => {
|
|
3685
4003
|
if (typeof t.worktree !== "string")
|
|
3686
4004
|
return false;
|
|
3687
|
-
const rel =
|
|
3688
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
4005
|
+
const rel = path25.relative(here, real(t.worktree));
|
|
4006
|
+
return rel === "" || !rel.startsWith("..") && !path25.isAbsolute(rel);
|
|
3689
4007
|
});
|
|
3690
4008
|
}
|
|
3691
4009
|
async function claimPoolSlot(input) {
|
|
@@ -3693,7 +4011,7 @@ async function claimPoolSlot(input) {
|
|
|
3693
4011
|
const refused = [];
|
|
3694
4012
|
for (let slot = 1; slot <= pool.size; slot++) {
|
|
3695
4013
|
const dir = poolSlotPath(name, slot);
|
|
3696
|
-
if (
|
|
4014
|
+
if (fs29.existsSync(dir) && readWorktreeLock(dir)?.id === id && readWorktreeLock(dir)?.kind !== "warm") {
|
|
3697
4015
|
writeSlotClaim(name, slot, { id, lane, at: (/* @__PURE__ */ new Date()).toISOString() });
|
|
3698
4016
|
return { claimed: true, dir, slot, label: poolSlotLabel(name, slot) };
|
|
3699
4017
|
}
|
|
@@ -3741,7 +4059,7 @@ async function resetPoolWorktree(repo, dir, id, fromRemoteBranch = repo.trunk) {
|
|
|
3741
4059
|
}
|
|
3742
4060
|
var WARM_ID = "pool-warm";
|
|
3743
4061
|
async function createSlot(repo, dir) {
|
|
3744
|
-
|
|
4062
|
+
fs29.mkdirSync(path25.dirname(dir), { recursive: true });
|
|
3745
4063
|
await oneAtATime(repo.path, async () => {
|
|
3746
4064
|
await tryGit(repo.path, "worktree", "prune");
|
|
3747
4065
|
await gitShared(repo.path, "worktree", "add", "--detach", dir, `origin/${repo.trunk}`);
|
|
@@ -3763,7 +4081,7 @@ async function warmPool(name, opts = {}) {
|
|
|
3763
4081
|
if (!release)
|
|
3764
4082
|
return false;
|
|
3765
4083
|
try {
|
|
3766
|
-
if (!
|
|
4084
|
+
if (!fs29.existsSync(repo.path)) {
|
|
3767
4085
|
if (!repo.origin)
|
|
3768
4086
|
throw new Error(`repo path ${repo.path} missing and no origin configured`);
|
|
3769
4087
|
await run("git", ["clone", repo.origin, repo.path], { env: process.env });
|
|
@@ -3776,8 +4094,9 @@ async function warmPool(name, opts = {}) {
|
|
|
3776
4094
|
const dir = poolSlotPath(name, slot);
|
|
3777
4095
|
const label = poolSlotLabel(name, slot);
|
|
3778
4096
|
const meta = readSlotMeta(name, slot);
|
|
3779
|
-
if (!
|
|
3780
|
-
|
|
4097
|
+
if (!fs29.existsSync(dir)) {
|
|
4098
|
+
fs29.mkdirSync(poolsRoot(), { recursive: true });
|
|
4099
|
+
recoverTrapCaches(cfg, poolsRoot(), read2, log);
|
|
3781
4100
|
let free = Infinity;
|
|
3782
4101
|
try {
|
|
3783
4102
|
free = need > 0 ? read2(poolsRoot()) : Infinity;
|
|
@@ -3853,7 +4172,7 @@ async function warmPool(name, opts = {}) {
|
|
|
3853
4172
|
// packages/worktree/dist/index.js
|
|
3854
4173
|
var run2 = promisify2(execFile2);
|
|
3855
4174
|
var shell = promisify2(exec);
|
|
3856
|
-
async function
|
|
4175
|
+
async function git2(cwd, ...args) {
|
|
3857
4176
|
const { stdout } = await run2("git", args, { cwd, env: process.env });
|
|
3858
4177
|
return stdout.trim();
|
|
3859
4178
|
}
|
|
@@ -3895,7 +4214,7 @@ var ATTEMPTS = 6;
|
|
|
3895
4214
|
async function gitShared(cwd, ...args) {
|
|
3896
4215
|
for (let attempt2 = 1; ; attempt2++) {
|
|
3897
4216
|
try {
|
|
3898
|
-
return await
|
|
4217
|
+
return await git2(cwd, ...args);
|
|
3899
4218
|
} catch (err) {
|
|
3900
4219
|
if (!isLockContention(err))
|
|
3901
4220
|
throw err;
|
|
@@ -3920,7 +4239,7 @@ function pidAlive3(pid) {
|
|
|
3920
4239
|
var BUSY = /* @__PURE__ */ new Set(["EPERM", "EACCES", "EBUSY"]);
|
|
3921
4240
|
function takeRepoLock(file2, mine) {
|
|
3922
4241
|
try {
|
|
3923
|
-
|
|
4242
|
+
fs30.writeFileSync(file2, mine, { flag: "wx" });
|
|
3924
4243
|
return { state: "held" };
|
|
3925
4244
|
} catch (err) {
|
|
3926
4245
|
const code2 = err.code ?? "";
|
|
@@ -3930,8 +4249,8 @@ function takeRepoLock(file2, mine) {
|
|
|
3930
4249
|
let raw = "";
|
|
3931
4250
|
let age = 0;
|
|
3932
4251
|
try {
|
|
3933
|
-
raw =
|
|
3934
|
-
age = Date.now() -
|
|
4252
|
+
raw = fs30.readFileSync(file2, "utf8");
|
|
4253
|
+
age = Date.now() - fs30.statSync(file2).mtimeMs;
|
|
3935
4254
|
} catch {
|
|
3936
4255
|
return { state: "retry" };
|
|
3937
4256
|
}
|
|
@@ -3944,8 +4263,8 @@ function takeRepoLock(file2, mine) {
|
|
|
3944
4263
|
const stale = age > REPO_LOCK_WAIT_MS || (holder ? !pidAlive3(holder.pid) : age > 5e3);
|
|
3945
4264
|
if (stale) {
|
|
3946
4265
|
try {
|
|
3947
|
-
if (
|
|
3948
|
-
|
|
4266
|
+
if (fs30.readFileSync(file2, "utf8") === raw)
|
|
4267
|
+
fs30.rmSync(file2, { force: true });
|
|
3949
4268
|
} catch {
|
|
3950
4269
|
}
|
|
3951
4270
|
return { state: "retry" };
|
|
@@ -3954,13 +4273,13 @@ function takeRepoLock(file2, mine) {
|
|
|
3954
4273
|
}
|
|
3955
4274
|
function releaseRepoLock(file2, mine) {
|
|
3956
4275
|
try {
|
|
3957
|
-
if (
|
|
3958
|
-
|
|
4276
|
+
if (fs30.readFileSync(file2, "utf8") === mine)
|
|
4277
|
+
fs30.rmSync(file2, { force: true, recursive: true, maxRetries: 5 });
|
|
3959
4278
|
} catch {
|
|
3960
4279
|
}
|
|
3961
4280
|
}
|
|
3962
4281
|
async function withRepoLock(common, fn) {
|
|
3963
|
-
const file2 =
|
|
4282
|
+
const file2 = path26.join(common, "lobstah-git.lock");
|
|
3964
4283
|
const mine = JSON.stringify({ pid: process.pid, at: (/* @__PURE__ */ new Date()).toISOString() });
|
|
3965
4284
|
const deadline = Date.now() + REPO_LOCK_WAIT_MS;
|
|
3966
4285
|
let held = false;
|
|
@@ -3981,7 +4300,7 @@ async function withRepoLock(common, fn) {
|
|
|
3981
4300
|
}
|
|
3982
4301
|
}
|
|
3983
4302
|
async function oneAtATime(cwd, fn) {
|
|
3984
|
-
const common = await
|
|
4303
|
+
const common = await git2(cwd, "rev-parse", "--path-format=absolute", "--git-common-dir");
|
|
3985
4304
|
const key = realpath(common);
|
|
3986
4305
|
const run3 = (repoQueues.get(key) ?? Promise.resolve()).then(() => withRepoLock(common, () => fn(common)));
|
|
3987
4306
|
const tail = run3.catch(() => {
|
|
@@ -3996,7 +4315,7 @@ async function oneAtATime(cwd, fn) {
|
|
|
3996
4315
|
}
|
|
3997
4316
|
function fetchStamps(common) {
|
|
3998
4317
|
try {
|
|
3999
|
-
return JSON.parse(
|
|
4318
|
+
return JSON.parse(fs30.readFileSync(path26.join(common, "lobstah-fetch.json"), "utf8"));
|
|
4000
4319
|
} catch {
|
|
4001
4320
|
return {};
|
|
4002
4321
|
}
|
|
@@ -4010,15 +4329,15 @@ async function fetchShared(cwd, remote, ref) {
|
|
|
4010
4329
|
const started = Date.now();
|
|
4011
4330
|
await gitShared(cwd, "fetch", remote, ref);
|
|
4012
4331
|
const stamps = { ...fetchStamps(common), [key]: started };
|
|
4013
|
-
|
|
4332
|
+
fs30.writeFileSync(path26.join(common, "lobstah-fetch.json"), JSON.stringify(stamps, null, 2));
|
|
4014
4333
|
});
|
|
4015
4334
|
}
|
|
4016
4335
|
async function allocate(repo, id, fromRemoteBranch = repo.trunk) {
|
|
4017
4336
|
const dir = worktreePath(id);
|
|
4018
|
-
if (
|
|
4337
|
+
if (fs30.existsSync(dir)) {
|
|
4019
4338
|
throw new Error(`worktree for ${id} already exists at ${dir} \u2014 never allocate a second`);
|
|
4020
4339
|
}
|
|
4021
|
-
if (!
|
|
4340
|
+
if (!fs30.existsSync(repo.path)) {
|
|
4022
4341
|
if (!repo.origin)
|
|
4023
4342
|
throw new Error(`repo path ${repo.path} missing and no origin configured`);
|
|
4024
4343
|
await run2("git", ["clone", repo.origin, repo.path], { env: process.env });
|
|
@@ -4033,11 +4352,11 @@ async function allocate(repo, id, fromRemoteBranch = repo.trunk) {
|
|
|
4033
4352
|
async function recoverWorktree(repo, id) {
|
|
4034
4353
|
const dir = worktreePath(id);
|
|
4035
4354
|
try {
|
|
4036
|
-
if (
|
|
4037
|
-
const branch = await
|
|
4038
|
-
const root = await
|
|
4039
|
-
const common = await
|
|
4040
|
-
const mine = await
|
|
4355
|
+
if (fs30.statSync(path26.join(dir, ".git")).isFile()) {
|
|
4356
|
+
const branch = await git2(dir, "symbolic-ref", "--quiet", "HEAD");
|
|
4357
|
+
const root = await git2(dir, "rev-parse", "--show-toplevel");
|
|
4358
|
+
const common = await git2(dir, "rev-parse", "--path-format=absolute", "--git-common-dir");
|
|
4359
|
+
const mine = await git2(repo.path, "rev-parse", "--path-format=absolute", "--git-common-dir");
|
|
4041
4360
|
if (branch === `refs/heads/lobstah/${id}` && realpath(root) === realpath(dir) && realpath(common) === realpath(mine))
|
|
4042
4361
|
return dir;
|
|
4043
4362
|
}
|
|
@@ -4071,27 +4390,27 @@ function setupHash(repo, dir) {
|
|
|
4071
4390
|
const h = createHash("sha256");
|
|
4072
4391
|
h.update(JSON.stringify(repo.setup ?? []));
|
|
4073
4392
|
for (const name of LOCKFILES) {
|
|
4074
|
-
const file2 =
|
|
4075
|
-
if (!
|
|
4393
|
+
const file2 = path26.join(dir, name);
|
|
4394
|
+
if (!fs30.existsSync(file2))
|
|
4076
4395
|
continue;
|
|
4077
4396
|
h.update(`\0${name}\0`);
|
|
4078
|
-
h.update(
|
|
4397
|
+
h.update(fs30.readFileSync(file2));
|
|
4079
4398
|
}
|
|
4080
4399
|
return h.digest("hex");
|
|
4081
4400
|
}
|
|
4082
4401
|
function setupRecordFile(dir) {
|
|
4083
4402
|
const gitDir = worktreeGitDir(dir);
|
|
4084
|
-
return gitDir ?
|
|
4403
|
+
return gitDir ? path26.join(gitDir, "lobstah-setup.json") : void 0;
|
|
4085
4404
|
}
|
|
4086
4405
|
function recordSetup(repo, dir) {
|
|
4087
4406
|
const file2 = setupRecordFile(dir);
|
|
4088
4407
|
if (file2)
|
|
4089
|
-
|
|
4408
|
+
fs30.writeFileSync(file2, JSON.stringify({ hash: setupHash(repo, dir), at: (/* @__PURE__ */ new Date()).toISOString() }, null, 2));
|
|
4090
4409
|
}
|
|
4091
4410
|
function recordedSetupHash(dir) {
|
|
4092
4411
|
const file2 = setupRecordFile(dir);
|
|
4093
4412
|
try {
|
|
4094
|
-
return file2 ? JSON.parse(
|
|
4413
|
+
return file2 ? JSON.parse(fs30.readFileSync(file2, "utf8")).hash : void 0;
|
|
4095
4414
|
} catch {
|
|
4096
4415
|
return void 0;
|
|
4097
4416
|
}
|
|
@@ -4104,9 +4423,9 @@ function poolReused(slot, by) {
|
|
|
4104
4423
|
function realpath(p) {
|
|
4105
4424
|
let r;
|
|
4106
4425
|
try {
|
|
4107
|
-
r =
|
|
4426
|
+
r = fs30.realpathSync.native(p);
|
|
4108
4427
|
} catch {
|
|
4109
|
-
r =
|
|
4428
|
+
r = path26.resolve(p);
|
|
4110
4429
|
}
|
|
4111
4430
|
return process.platform === "win32" ? r.toLowerCase() : r;
|
|
4112
4431
|
}
|
|
@@ -4137,8 +4456,8 @@ async function chooseWorktree(input) {
|
|
|
4137
4456
|
return { reuse: false, reason: `origin worktree belongs to repo ${ownerRepo}` };
|
|
4138
4457
|
}
|
|
4139
4458
|
try {
|
|
4140
|
-
const common = await
|
|
4141
|
-
const mine = await
|
|
4459
|
+
const common = await git2(found.path, "rev-parse", "--path-format=absolute", "--git-common-dir");
|
|
4460
|
+
const mine = await git2(repo.path, "rev-parse", "--path-format=absolute", "--git-common-dir");
|
|
4142
4461
|
if (realpath(common) !== realpath(mine))
|
|
4143
4462
|
return { reuse: false, reason: "origin worktree belongs to another repo" };
|
|
4144
4463
|
} catch {
|
|
@@ -4154,8 +4473,8 @@ async function chooseWorktree(input) {
|
|
|
4154
4473
|
for (const t of listTraps()) {
|
|
4155
4474
|
if (typeof t.worktree !== "string")
|
|
4156
4475
|
continue;
|
|
4157
|
-
const rel =
|
|
4158
|
-
if (!rel.startsWith("..") && !
|
|
4476
|
+
const rel = path26.relative(here, realpath(t.worktree));
|
|
4477
|
+
if (!rel.startsWith("..") && !path26.isAbsolute(rel))
|
|
4159
4478
|
return { reuse: false, reason: "origin worktree is a trap\u2019s" };
|
|
4160
4479
|
}
|
|
4161
4480
|
for (const l of ["work", "chore"]) {
|
|
@@ -4172,7 +4491,7 @@ async function chooseWorktree(input) {
|
|
|
4172
4491
|
return { reuse: false, reason: `origin worktree is in use by ${short(holder.id)}` };
|
|
4173
4492
|
let porcelain;
|
|
4174
4493
|
try {
|
|
4175
|
-
porcelain = await
|
|
4494
|
+
porcelain = await git2(found.path, "status", "--porcelain");
|
|
4176
4495
|
} catch {
|
|
4177
4496
|
return { reuse: false, reason: "origin worktree is not a readable git checkout" };
|
|
4178
4497
|
}
|
|
@@ -4202,8 +4521,8 @@ async function prepareReuse(repo, dir) {
|
|
|
4202
4521
|
return { setupRan: true };
|
|
4203
4522
|
}
|
|
4204
4523
|
async function collectEvidence(repo, dir) {
|
|
4205
|
-
const branch = await
|
|
4206
|
-
const log = await
|
|
4524
|
+
const branch = await git2(dir, "rev-parse", "--abbrev-ref", "HEAD");
|
|
4525
|
+
const log = await git2(dir, "log", "--oneline", `origin/${repo.trunk}..HEAD`);
|
|
4207
4526
|
return { branch, commits: log ? log.split("\n") : [] };
|
|
4208
4527
|
}
|
|
4209
4528
|
async function tryGit(cwd, ...args) {
|
|
@@ -4253,7 +4572,7 @@ async function* until(source, stop) {
|
|
|
4253
4572
|
yield next.value;
|
|
4254
4573
|
}
|
|
4255
4574
|
}
|
|
4256
|
-
var sleep = (ms) => new Promise((
|
|
4575
|
+
var sleep = (ms) => new Promise((resolve10) => setTimeout(resolve10, ms));
|
|
4257
4576
|
function deliver(run3, id, lane) {
|
|
4258
4577
|
const msgs = unhandled(id, lane);
|
|
4259
4578
|
for (const m of msgs) {
|
|
@@ -4299,7 +4618,7 @@ async function drive(run3, opts) {
|
|
|
4299
4618
|
let finalAt = 0;
|
|
4300
4619
|
let exit;
|
|
4301
4620
|
let abandon;
|
|
4302
|
-
const abandoned = new Promise((
|
|
4621
|
+
const abandoned = new Promise((resolve10) => abandon = resolve10);
|
|
4303
4622
|
const clearExit = () => {
|
|
4304
4623
|
if (!exit) return;
|
|
4305
4624
|
clearInterval(exit.poll);
|
|
@@ -4583,8 +4902,8 @@ function startWallClock(opts) {
|
|
|
4583
4902
|
import { execFile as execFile3 } from "node:child_process";
|
|
4584
4903
|
import { promisify as promisify3 } from "node:util";
|
|
4585
4904
|
import { fileURLToPath } from "node:url";
|
|
4586
|
-
import * as
|
|
4587
|
-
import * as
|
|
4905
|
+
import * as fs31 from "node:fs";
|
|
4906
|
+
import * as path27 from "node:path";
|
|
4588
4907
|
var exec2 = promisify3(execFile3);
|
|
4589
4908
|
function firstLine(err) {
|
|
4590
4909
|
const stderr = err && typeof err === "object" && "stderr" in err ? String(err.stderr).trim() : "";
|
|
@@ -4610,14 +4929,14 @@ function keepRemote(opts) {
|
|
|
4610
4929
|
shell: process.platform === "win32" && /\.(?:cmd|bat)$/i.test(file2)
|
|
4611
4930
|
})).stdout.trim();
|
|
4612
4931
|
};
|
|
4613
|
-
const
|
|
4932
|
+
const git3 = (...args) => command("git", args);
|
|
4614
4933
|
const note = (message) => mergeEvidence(id, lane, { note: message.slice(0, 300) });
|
|
4615
4934
|
if (existingPrUrl) mergeEvidence(id, lane, { prUrl: existingPrUrl });
|
|
4616
4935
|
const registerWatch = async (url) => {
|
|
4617
|
-
const root =
|
|
4618
|
-
const localCli =
|
|
4936
|
+
const root = path27.resolve(path27.dirname(fileURLToPath(import.meta.url)), "..", "..", "..");
|
|
4937
|
+
const localCli = path27.join(root, "apps", "cli", "dist", "main.js");
|
|
4619
4938
|
const args = ["watch", "add", url, "--for", id];
|
|
4620
|
-
if (
|
|
4939
|
+
if (fs31.existsSync(localCli)) await command(process.execPath, [localCli, ...args], 15e3);
|
|
4621
4940
|
else await command("lobstah", args, 15e3);
|
|
4622
4941
|
};
|
|
4623
4942
|
let lastSeenHead;
|
|
@@ -4634,7 +4953,7 @@ function keepRemote(opts) {
|
|
|
4634
4953
|
await registerWatch(existingWatch.url).catch((err) => note(`PR watch unavailable: ${firstLine(err)}`));
|
|
4635
4954
|
})() : void 0;
|
|
4636
4955
|
const branchName = async () => {
|
|
4637
|
-
const branch = await
|
|
4956
|
+
const branch = await git3("symbolic-ref", "--quiet", "--short", "HEAD").catch(() => "");
|
|
4638
4957
|
if (!branch || branch === trunk || branch === `origin/${trunk}`) return void 0;
|
|
4639
4958
|
return branch;
|
|
4640
4959
|
};
|
|
@@ -4678,14 +4997,14 @@ function keepRemote(opts) {
|
|
|
4678
4997
|
if (!policy.pushEarly || trapClaimed() || existingPrUrl) return;
|
|
4679
4998
|
const branch = await branchName();
|
|
4680
4999
|
if (!branch) return;
|
|
4681
|
-
const head = await
|
|
4682
|
-
const ahead = await
|
|
5000
|
+
const head = await git3("rev-parse", "HEAD");
|
|
5001
|
+
const ahead = await git3("rev-list", "--count", `origin/${trunk}..HEAD`).catch(() => "1");
|
|
4683
5002
|
if (ahead === "0") return;
|
|
4684
5003
|
if (head === lastSeenHead) return;
|
|
4685
5004
|
lastSeenHead = head;
|
|
4686
5005
|
if (head === pushedHead) return;
|
|
4687
5006
|
try {
|
|
4688
|
-
await
|
|
5007
|
+
await git3("push", "-u", "origin", branch);
|
|
4689
5008
|
pushedHead = head;
|
|
4690
5009
|
pushProblem = void 0;
|
|
4691
5010
|
mergeEvidence(id, lane, { branch });
|
|
@@ -4731,12 +5050,12 @@ function keepRemote(opts) {
|
|
|
4731
5050
|
let saved = "no working-tree changes";
|
|
4732
5051
|
if (policy.checkpointOnStop) {
|
|
4733
5052
|
try {
|
|
4734
|
-
const paths = (await
|
|
5053
|
+
const paths = (await git3("ls-files", "-m", "-o", "-d", "--exclude-standard", "-z")).split("\0").filter(Boolean).filter(checkpointAllowed);
|
|
4735
5054
|
if (paths.length) {
|
|
4736
|
-
await
|
|
4737
|
-
const staged = await
|
|
5055
|
+
await git3("add", "-A", "--", ...paths);
|
|
5056
|
+
const staged = await git3("diff", "--cached", "--name-only", "--", ...paths);
|
|
4738
5057
|
if (staged) {
|
|
4739
|
-
await
|
|
5058
|
+
await git3("commit", "--only", "-m", "Checkpoint before runner stop", "--", ...paths);
|
|
4740
5059
|
saved = `checkpoint committed (${staged.split("\n").length} files)`;
|
|
4741
5060
|
}
|
|
4742
5061
|
}
|
|
@@ -4747,7 +5066,7 @@ function keepRemote(opts) {
|
|
|
4747
5066
|
await check().catch((err) => note(`final push unavailable: ${firstLine(err)}`));
|
|
4748
5067
|
await opening;
|
|
4749
5068
|
await watching;
|
|
4750
|
-
const head = await
|
|
5069
|
+
const head = await git3("rev-parse", "--short", "HEAD").catch(() => "unknown");
|
|
4751
5070
|
const pr = readEvidence(id, lane).prUrl;
|
|
4752
5071
|
const message = `${saved}; ${branch}@${head}${pr ? `; ${existingPrUrl ? "existing" : "draft"} PR ${pr}` : ""}${pushProblem ? `; ${pushProblem}` : ""}${draftProblem ? `; ${draftProblem}` : ""}`;
|
|
4753
5072
|
note(message);
|
|
@@ -4780,7 +5099,7 @@ var defaultDeps = {
|
|
|
4780
5099
|
var DONE_WAIT_MS = 2e3;
|
|
4781
5100
|
function within(p, ms, fallback) {
|
|
4782
5101
|
let timer;
|
|
4783
|
-
const late = new Promise((
|
|
5102
|
+
const late = new Promise((resolve10) => timer = setTimeout(() => resolve10(fallback), ms));
|
|
4784
5103
|
return Promise.race([p, late]).finally(() => clearTimeout(timer));
|
|
4785
5104
|
}
|
|
4786
5105
|
var short3 = (s) => s.slice(0, 8);
|
|
@@ -4809,16 +5128,16 @@ function coldNote(cold, cwd, trunk) {
|
|
|
4809
5128
|
}
|
|
4810
5129
|
async function main(activeDir, lane, seams = {}) {
|
|
4811
5130
|
const deps = { ...defaultDeps, ...seams };
|
|
4812
|
-
const id =
|
|
5131
|
+
const id = path28.basename(activeDir);
|
|
4813
5132
|
if (isTrapCatch(id, lane)) throw new Error(`refusing headless runner for trap catch ${id}`);
|
|
4814
5133
|
const status = (verb, note) => appendStatus(id, lane, verb, note);
|
|
4815
5134
|
const cfg = loadConfig();
|
|
4816
|
-
const descriptor = JSON.parse(
|
|
5135
|
+
const descriptor = JSON.parse(fs32.readFileSync(path28.join(activeDir, "descriptor.json"), "utf8"));
|
|
4817
5136
|
const resolved = resolveDispatch(descriptor, cfg);
|
|
4818
5137
|
const repo = cfg.repos[descriptor.repo];
|
|
4819
|
-
const briefFile =
|
|
4820
|
-
if (!
|
|
4821
|
-
const brief =
|
|
5138
|
+
const briefFile = path28.join(activeDir, "brief.md");
|
|
5139
|
+
if (!fs32.existsSync(briefFile)) fs32.writeFileSync(briefFile, descriptor.brief);
|
|
5140
|
+
const brief = fs32.readFileSync(briefFile, "utf8");
|
|
4822
5141
|
const attempts = Number(process.env.LOBSTAH_ATTEMPTS ?? "1");
|
|
4823
5142
|
const wake = process.env.LOBSTAH_WAKE;
|
|
4824
5143
|
const runnerInfo = {
|
|
@@ -4826,7 +5145,7 @@ async function main(activeDir, lane, seams = {}) {
|
|
|
4826
5145
|
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4827
5146
|
attempts
|
|
4828
5147
|
};
|
|
4829
|
-
|
|
5148
|
+
fs32.writeFileSync(path28.join(activeDir, "runner.json"), JSON.stringify(runnerInfo, null, 2));
|
|
4830
5149
|
if (descriptor.systemRepair && descriptor.pr?.url) {
|
|
4831
5150
|
const state = deps.prState(descriptor.pr.url) ?? readPr(parsePrRef(descriptor.pr.url)?.key ?? "")?.state;
|
|
4832
5151
|
if (state === "MERGED" || state === "CLOSED") {
|
|
@@ -4843,14 +5162,14 @@ async function main(activeDir, lane, seams = {}) {
|
|
|
4843
5162
|
resolvedHarness: resolved.harness,
|
|
4844
5163
|
envResume: process.env.LOBSTAH_RESUME
|
|
4845
5164
|
});
|
|
4846
|
-
const wtFile =
|
|
5165
|
+
const wtFile = path28.join(activeDir, "worktree.json");
|
|
4847
5166
|
let recorded;
|
|
4848
5167
|
let recovered = false;
|
|
4849
5168
|
let choice3;
|
|
4850
|
-
if (
|
|
4851
|
-
recorded = JSON.parse(
|
|
4852
|
-
if (!
|
|
4853
|
-
} else if (
|
|
5169
|
+
if (fs32.existsSync(wtFile)) {
|
|
5170
|
+
recorded = JSON.parse(fs32.readFileSync(wtFile, "utf8")).path;
|
|
5171
|
+
if (!fs32.existsSync(recorded)) throw new Error(`recorded worktree ${recorded} is gone`);
|
|
5172
|
+
} else if (fs32.existsSync(worktreePath(id))) {
|
|
4854
5173
|
recorded = await recoverWorktree(repo, id);
|
|
4855
5174
|
recovered = true;
|
|
4856
5175
|
} else if (descriptor.followUp && cfg.limits.reuseWorktree !== false) {
|
|
@@ -4905,7 +5224,7 @@ async function main(activeDir, lane, seams = {}) {
|
|
|
4905
5224
|
if (held) throw new Error(`worktree at ${cwd} is in use by ${held.id} \u2014 wait for that dispatch to release it before retrying`);
|
|
4906
5225
|
if (recovered) {
|
|
4907
5226
|
await deps.prepareReuse(repo, cwd);
|
|
4908
|
-
|
|
5227
|
+
fs32.writeFileSync(wtFile, JSON.stringify({ path: cwd }, null, 2));
|
|
4909
5228
|
}
|
|
4910
5229
|
} else if (choice3?.reuse) {
|
|
4911
5230
|
cwd = choice3.path;
|
|
@@ -4916,17 +5235,17 @@ async function main(activeDir, lane, seams = {}) {
|
|
|
4916
5235
|
type: "runner",
|
|
4917
5236
|
data: { worktree: cwd, worktreeOf: choice3.owner, setupRan }
|
|
4918
5237
|
});
|
|
4919
|
-
|
|
5238
|
+
fs32.writeFileSync(wtFile, JSON.stringify({ path: cwd, of: choice3.owner }, null, 2));
|
|
4920
5239
|
} else if (poolClaim) {
|
|
4921
5240
|
cwd = poolClaim.dir;
|
|
4922
5241
|
await deps.resetPool(repo, cwd, id, descriptor.systemRepair ? descriptor.pr?.headRefName : void 0);
|
|
4923
|
-
|
|
5242
|
+
fs32.writeFileSync(wtFile, JSON.stringify({ path: cwd, pool: poolClaim.label }, null, 2));
|
|
4924
5243
|
} else {
|
|
4925
5244
|
cwd = await deps.allocate(repo, id, descriptor.systemRepair ? descriptor.pr?.headRefName : void 0);
|
|
4926
5245
|
acquireWorktreeLock(cwd, id, lane);
|
|
4927
|
-
|
|
5246
|
+
fs32.writeFileSync(wtFile, JSON.stringify({ path: cwd }, null, 2));
|
|
4928
5247
|
}
|
|
4929
|
-
const worktreeOf = JSON.parse(
|
|
5248
|
+
const worktreeOf = JSON.parse(fs32.readFileSync(wtFile, "utf8")).of;
|
|
4930
5249
|
const inPool = poolSlotOf(cwd);
|
|
4931
5250
|
mergeEvidence(id, lane, { worktree: cwd, worktreeOf, ...inPool ? { pool: poolSlotLabel(inPool.pool, inPool.slot) } : {} });
|
|
4932
5251
|
const existingPr = boundPr(descriptor, lane);
|
|
@@ -4954,21 +5273,21 @@ async function main(activeDir, lane, seams = {}) {
|
|
|
4954
5273
|
const envNudge = [process.env.LOBSTAH_NUDGE, wakeNote()].filter(Boolean).join("\n\n") || void 0;
|
|
4955
5274
|
const planNudge = plan.cold && !envNudge ? coldNote(plan.cold, cwd, repo.trunk) : void 0;
|
|
4956
5275
|
const promptWith = (nudge) => buildPrompt(brief, { id, nudge, attachments: descriptor.attachments, existingPr });
|
|
4957
|
-
const binDir =
|
|
4958
|
-
const workerPath =
|
|
5276
|
+
const binDir = path28.resolve(path28.dirname(fileURLToPath2(import.meta.url)), "..", "..", "..", "bin");
|
|
5277
|
+
const workerPath = fs32.existsSync(path28.join(binDir, "lobstah")) ? `${binDir}${path28.delimiter}${process.env.PATH ?? ""}` : void 0;
|
|
4959
5278
|
let wallClockHit = false;
|
|
4960
5279
|
let current;
|
|
4961
|
-
const wallFile =
|
|
5280
|
+
const wallFile = path28.join(activeDir, "wallclock.json");
|
|
4962
5281
|
const wallState = (() => {
|
|
4963
5282
|
try {
|
|
4964
|
-
return JSON.parse(
|
|
5283
|
+
return JSON.parse(fs32.readFileSync(wallFile, "utf8"));
|
|
4965
5284
|
} catch {
|
|
4966
5285
|
return { elapsedMs: 0, windowMs: resolved.limits.wallClockSecs * 1e3 };
|
|
4967
5286
|
}
|
|
4968
5287
|
})();
|
|
4969
5288
|
const head = () => {
|
|
4970
5289
|
try {
|
|
4971
|
-
return
|
|
5290
|
+
return execFileSync3("git", ["rev-parse", "HEAD"], { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
4972
5291
|
} catch {
|
|
4973
5292
|
return void 0;
|
|
4974
5293
|
}
|
|
@@ -4980,8 +5299,8 @@ async function main(activeDir, lane, seams = {}) {
|
|
|
4980
5299
|
) * 1e3;
|
|
4981
5300
|
const persistWall = (elapsedMs, windowMs) => {
|
|
4982
5301
|
const tmp = uniqueTempPath(wallFile);
|
|
4983
|
-
|
|
4984
|
-
|
|
5302
|
+
fs32.writeFileSync(tmp, JSON.stringify({ ...wallState, elapsedMs, windowMs }));
|
|
5303
|
+
fs32.renameSync(tmp, wallFile);
|
|
4985
5304
|
};
|
|
4986
5305
|
const madeProgress = () => {
|
|
4987
5306
|
const activity = readActivity(id, lane);
|
|
@@ -5147,7 +5466,7 @@ async function main(activeDir, lane, seams = {}) {
|
|
|
5147
5466
|
}
|
|
5148
5467
|
|
|
5149
5468
|
// packages/runner/src/reap.ts
|
|
5150
|
-
import { execFileSync as
|
|
5469
|
+
import { execFileSync as execFileSync4 } from "node:child_process";
|
|
5151
5470
|
|
|
5152
5471
|
// packages/runner/src/windows-processes.ts
|
|
5153
5472
|
var WINDOWS_PROCESS_SNAPSHOT = String.raw`
|
|
@@ -5197,7 +5516,7 @@ public static class LobstahProcessSnapshot {
|
|
|
5197
5516
|
// packages/runner/src/reap.ts
|
|
5198
5517
|
function listProcesses() {
|
|
5199
5518
|
if (process.platform === "win32") {
|
|
5200
|
-
const out2 =
|
|
5519
|
+
const out2 = execFileSync4(
|
|
5201
5520
|
"powershell.exe",
|
|
5202
5521
|
[
|
|
5203
5522
|
"-NoProfile",
|
|
@@ -5209,7 +5528,7 @@ function listProcesses() {
|
|
|
5209
5528
|
);
|
|
5210
5529
|
return out2.split(/\r?\n/).map((l) => l.trim().split(/\s+/).map(Number)).filter(([pid, ppid]) => Number.isInteger(pid) && Number.isInteger(ppid)).map(([pid, ppid]) => ({ pid, ppid }));
|
|
5211
5530
|
}
|
|
5212
|
-
const out =
|
|
5531
|
+
const out = execFileSync4("ps", ["-A", "-o", "pid=,ppid=,pgid="], {
|
|
5213
5532
|
encoding: "utf8",
|
|
5214
5533
|
timeout: 3e4,
|
|
5215
5534
|
stdio: ["ignore", "pipe", "ignore"]
|
|
@@ -5252,7 +5571,7 @@ async function stopPids(pids, graceMs = 2e3) {
|
|
|
5252
5571
|
if (process.platform === "win32") {
|
|
5253
5572
|
for (const pid of pids) {
|
|
5254
5573
|
try {
|
|
5255
|
-
|
|
5574
|
+
execFileSync4("taskkill", ["/pid", String(pid), "/T", "/F"], { stdio: "ignore", windowsHide: true, timeout: 3e4 });
|
|
5256
5575
|
} catch {
|
|
5257
5576
|
}
|
|
5258
5577
|
}
|
|
@@ -5285,13 +5604,13 @@ async function reapStarted(root = process.pid, graceMs) {
|
|
|
5285
5604
|
var EXIT_LINGER_MS = 5e3;
|
|
5286
5605
|
function runRunner(activeDirArg2, laneArg2) {
|
|
5287
5606
|
const lane = laneArg2 === "chore" ? "chore" : "work";
|
|
5288
|
-
const id =
|
|
5607
|
+
const id = path29.basename(activeDirArg2);
|
|
5289
5608
|
main(activeDirArg2, lane, { reap: () => reapStarted(process.pid) }).catch((err) => {
|
|
5290
5609
|
try {
|
|
5291
5610
|
if (!isFinished(id, lane)) {
|
|
5292
5611
|
appendStatus(id, lane, "failed", String(err instanceof Error ? err.message : err).slice(0, 500));
|
|
5293
5612
|
}
|
|
5294
|
-
|
|
5613
|
+
fs33.renameSync(activeDirArg2, path29.join(laneDirs(lane).done, id));
|
|
5295
5614
|
} catch {
|
|
5296
5615
|
}
|
|
5297
5616
|
process.exitCode = 1;
|