@locusai/cli 0.20.1 → 0.20.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/bin/locus.js +667 -264
- package/package.json +1 -1
package/bin/locus.js
CHANGED
|
@@ -1280,6 +1280,177 @@ var init_version_check = __esm(() => {
|
|
|
1280
1280
|
CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000;
|
|
1281
1281
|
});
|
|
1282
1282
|
|
|
1283
|
+
// src/core/ecosystem.ts
|
|
1284
|
+
import { existsSync as existsSync5 } from "node:fs";
|
|
1285
|
+
import { join as join5 } from "node:path";
|
|
1286
|
+
function detectProjectEcosystem(projectRoot) {
|
|
1287
|
+
for (const signal of ECOSYSTEM_SIGNALS) {
|
|
1288
|
+
for (const marker of signal.markers) {
|
|
1289
|
+
if (marker.startsWith("*")) {
|
|
1290
|
+
continue;
|
|
1291
|
+
}
|
|
1292
|
+
if (existsSync5(join5(projectRoot, marker))) {
|
|
1293
|
+
return signal.ecosystem;
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
return "unknown";
|
|
1298
|
+
}
|
|
1299
|
+
function isJavaScriptEcosystem(ecosystem) {
|
|
1300
|
+
return ecosystem === "javascript";
|
|
1301
|
+
}
|
|
1302
|
+
function generateSandboxSetupTemplate(ecosystem) {
|
|
1303
|
+
switch (ecosystem) {
|
|
1304
|
+
case "javascript":
|
|
1305
|
+
return null;
|
|
1306
|
+
case "rust":
|
|
1307
|
+
return `#!/bin/sh
|
|
1308
|
+
# Sandbox setup for Rust projects
|
|
1309
|
+
# This script runs inside the Docker sandbox after creation.
|
|
1310
|
+
# Uncomment or modify the commands below for your project.
|
|
1311
|
+
|
|
1312
|
+
# Install Rust toolchain (if not pre-installed)
|
|
1313
|
+
# curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
|
|
1314
|
+
# . "$HOME/.cargo/env"
|
|
1315
|
+
|
|
1316
|
+
# Build the project
|
|
1317
|
+
# cargo build
|
|
1318
|
+
|
|
1319
|
+
echo "Rust sandbox setup complete"
|
|
1320
|
+
`;
|
|
1321
|
+
case "go":
|
|
1322
|
+
return `#!/bin/sh
|
|
1323
|
+
# Sandbox setup for Go projects
|
|
1324
|
+
# This script runs inside the Docker sandbox after creation.
|
|
1325
|
+
|
|
1326
|
+
# Download dependencies
|
|
1327
|
+
# go mod download
|
|
1328
|
+
|
|
1329
|
+
# Build the project
|
|
1330
|
+
# go build ./...
|
|
1331
|
+
|
|
1332
|
+
echo "Go sandbox setup complete"
|
|
1333
|
+
`;
|
|
1334
|
+
case "python":
|
|
1335
|
+
return `#!/bin/sh
|
|
1336
|
+
# Sandbox setup for Python projects
|
|
1337
|
+
# This script runs inside the Docker sandbox after creation.
|
|
1338
|
+
|
|
1339
|
+
# Create virtual environment and install dependencies
|
|
1340
|
+
# python3 -m venv .venv
|
|
1341
|
+
# . .venv/bin/activate
|
|
1342
|
+
# pip install -r requirements.txt
|
|
1343
|
+
# OR: pip install -e .
|
|
1344
|
+
|
|
1345
|
+
echo "Python sandbox setup complete"
|
|
1346
|
+
`;
|
|
1347
|
+
case "java":
|
|
1348
|
+
return `#!/bin/sh
|
|
1349
|
+
# Sandbox setup for Java/JVM projects
|
|
1350
|
+
# This script runs inside the Docker sandbox after creation.
|
|
1351
|
+
|
|
1352
|
+
# Maven
|
|
1353
|
+
# mvn install -DskipTests
|
|
1354
|
+
|
|
1355
|
+
# Gradle
|
|
1356
|
+
# ./gradlew build -x test
|
|
1357
|
+
|
|
1358
|
+
echo "Java sandbox setup complete"
|
|
1359
|
+
`;
|
|
1360
|
+
case "ruby":
|
|
1361
|
+
return `#!/bin/sh
|
|
1362
|
+
# Sandbox setup for Ruby projects
|
|
1363
|
+
# This script runs inside the Docker sandbox after creation.
|
|
1364
|
+
|
|
1365
|
+
# Install dependencies
|
|
1366
|
+
# bundle install
|
|
1367
|
+
|
|
1368
|
+
echo "Ruby sandbox setup complete"
|
|
1369
|
+
`;
|
|
1370
|
+
case "elixir":
|
|
1371
|
+
return `#!/bin/sh
|
|
1372
|
+
# Sandbox setup for Elixir projects
|
|
1373
|
+
# This script runs inside the Docker sandbox after creation.
|
|
1374
|
+
|
|
1375
|
+
# Install dependencies
|
|
1376
|
+
# mix deps.get
|
|
1377
|
+
# mix compile
|
|
1378
|
+
|
|
1379
|
+
echo "Elixir sandbox setup complete"
|
|
1380
|
+
`;
|
|
1381
|
+
case "dotnet":
|
|
1382
|
+
return `#!/bin/sh
|
|
1383
|
+
# Sandbox setup for .NET projects
|
|
1384
|
+
# This script runs inside the Docker sandbox after creation.
|
|
1385
|
+
|
|
1386
|
+
# Restore packages
|
|
1387
|
+
# dotnet restore
|
|
1388
|
+
|
|
1389
|
+
# Build
|
|
1390
|
+
# dotnet build
|
|
1391
|
+
|
|
1392
|
+
echo ".NET sandbox setup complete"
|
|
1393
|
+
`;
|
|
1394
|
+
case "unknown":
|
|
1395
|
+
return `#!/bin/sh
|
|
1396
|
+
# Sandbox setup script
|
|
1397
|
+
# This script runs inside the Docker sandbox after creation.
|
|
1398
|
+
# Add any commands needed to prepare the build environment.
|
|
1399
|
+
|
|
1400
|
+
# Example: install system dependencies
|
|
1401
|
+
# apt-get update && apt-get install -y <packages>
|
|
1402
|
+
|
|
1403
|
+
# Example: install project dependencies
|
|
1404
|
+
# <your-package-manager> install
|
|
1405
|
+
|
|
1406
|
+
echo "Sandbox setup complete"
|
|
1407
|
+
`;
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
var ECOSYSTEM_SIGNALS;
|
|
1411
|
+
var init_ecosystem = __esm(() => {
|
|
1412
|
+
ECOSYSTEM_SIGNALS = [
|
|
1413
|
+
{
|
|
1414
|
+
ecosystem: "javascript",
|
|
1415
|
+
markers: ["package.json"]
|
|
1416
|
+
},
|
|
1417
|
+
{
|
|
1418
|
+
ecosystem: "rust",
|
|
1419
|
+
markers: ["Cargo.toml"]
|
|
1420
|
+
},
|
|
1421
|
+
{
|
|
1422
|
+
ecosystem: "go",
|
|
1423
|
+
markers: ["go.mod"]
|
|
1424
|
+
},
|
|
1425
|
+
{
|
|
1426
|
+
ecosystem: "python",
|
|
1427
|
+
markers: [
|
|
1428
|
+
"pyproject.toml",
|
|
1429
|
+
"setup.py",
|
|
1430
|
+
"setup.cfg",
|
|
1431
|
+
"Pipfile",
|
|
1432
|
+
"requirements.txt"
|
|
1433
|
+
]
|
|
1434
|
+
},
|
|
1435
|
+
{
|
|
1436
|
+
ecosystem: "java",
|
|
1437
|
+
markers: ["pom.xml", "build.gradle", "build.gradle.kts"]
|
|
1438
|
+
},
|
|
1439
|
+
{
|
|
1440
|
+
ecosystem: "ruby",
|
|
1441
|
+
markers: ["Gemfile"]
|
|
1442
|
+
},
|
|
1443
|
+
{
|
|
1444
|
+
ecosystem: "elixir",
|
|
1445
|
+
markers: ["mix.exs"]
|
|
1446
|
+
},
|
|
1447
|
+
{
|
|
1448
|
+
ecosystem: "dotnet",
|
|
1449
|
+
markers: ["*.csproj", "*.fsproj", "*.sln"]
|
|
1450
|
+
}
|
|
1451
|
+
];
|
|
1452
|
+
});
|
|
1453
|
+
|
|
1283
1454
|
// src/core/github.ts
|
|
1284
1455
|
import {
|
|
1285
1456
|
execFileSync,
|
|
@@ -1476,7 +1647,18 @@ function reopenMilestone(owner, repo, milestoneNumber, options = {}) {
|
|
|
1476
1647
|
gh(`api repos/${owner}/${repo}/milestones/${milestoneNumber} -X PATCH -f state=open`, options);
|
|
1477
1648
|
}
|
|
1478
1649
|
function createPR(title, body, head, base, options = {}) {
|
|
1479
|
-
const result = ghExec([
|
|
1650
|
+
const result = ghExec([
|
|
1651
|
+
"pr",
|
|
1652
|
+
"create",
|
|
1653
|
+
"--title",
|
|
1654
|
+
title,
|
|
1655
|
+
"--body",
|
|
1656
|
+
body,
|
|
1657
|
+
"--head",
|
|
1658
|
+
head,
|
|
1659
|
+
"--base",
|
|
1660
|
+
base
|
|
1661
|
+
], options);
|
|
1480
1662
|
const match = result.match(/\/pull\/(\d+)/);
|
|
1481
1663
|
if (!match) {
|
|
1482
1664
|
throw new Error(`Could not extract PR number from: ${result}`);
|
|
@@ -1630,8 +1812,8 @@ var exports_init = {};
|
|
|
1630
1812
|
__export(exports_init, {
|
|
1631
1813
|
initCommand: () => initCommand
|
|
1632
1814
|
});
|
|
1633
|
-
import { existsSync as
|
|
1634
|
-
import { join as
|
|
1815
|
+
import { existsSync as existsSync6, mkdirSync as mkdirSync5, readFileSync as readFileSync4, writeFileSync as writeFileSync4 } from "node:fs";
|
|
1816
|
+
import { join as join6 } from "node:path";
|
|
1635
1817
|
async function initCommand(cwd) {
|
|
1636
1818
|
const log = getLogger();
|
|
1637
1819
|
process.stderr.write(`
|
|
@@ -1675,17 +1857,17 @@ ${bold("Initializing Locus...")}
|
|
|
1675
1857
|
}
|
|
1676
1858
|
process.stderr.write(`${green("✓")} Repository: ${bold(`${context.owner}/${context.repo}`)} (branch: ${context.defaultBranch})
|
|
1677
1859
|
`);
|
|
1678
|
-
const locusDir =
|
|
1860
|
+
const locusDir = join6(cwd, ".locus");
|
|
1679
1861
|
const dirs = [
|
|
1680
1862
|
locusDir,
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1863
|
+
join6(locusDir, "sessions"),
|
|
1864
|
+
join6(locusDir, "discussions"),
|
|
1865
|
+
join6(locusDir, "artifacts"),
|
|
1866
|
+
join6(locusDir, "plans"),
|
|
1867
|
+
join6(locusDir, "logs")
|
|
1686
1868
|
];
|
|
1687
1869
|
for (const dir of dirs) {
|
|
1688
|
-
if (!
|
|
1870
|
+
if (!existsSync6(dir)) {
|
|
1689
1871
|
mkdirSync5(dir, { recursive: true });
|
|
1690
1872
|
}
|
|
1691
1873
|
}
|
|
@@ -1706,7 +1888,7 @@ ${bold("Initializing Locus...")}
|
|
|
1706
1888
|
};
|
|
1707
1889
|
if (isReInit) {
|
|
1708
1890
|
try {
|
|
1709
|
-
const existing = JSON.parse(readFileSync4(
|
|
1891
|
+
const existing = JSON.parse(readFileSync4(join6(locusDir, "config.json"), "utf-8"));
|
|
1710
1892
|
if (existing.ai)
|
|
1711
1893
|
config.ai = { ...config.ai, ...existing.ai };
|
|
1712
1894
|
if (existing.agent)
|
|
@@ -1725,8 +1907,8 @@ ${bold("Initializing Locus...")}
|
|
|
1725
1907
|
`);
|
|
1726
1908
|
}
|
|
1727
1909
|
saveConfig(cwd, config);
|
|
1728
|
-
const locusMdPath =
|
|
1729
|
-
if (!
|
|
1910
|
+
const locusMdPath = join6(locusDir, "LOCUS.md");
|
|
1911
|
+
if (!existsSync6(locusMdPath)) {
|
|
1730
1912
|
writeFileSync4(locusMdPath, LOCUS_MD_TEMPLATE, "utf-8");
|
|
1731
1913
|
process.stderr.write(`${green("✓")} Generated LOCUS.md (edit to add project context)
|
|
1732
1914
|
`);
|
|
@@ -1734,8 +1916,8 @@ ${bold("Initializing Locus...")}
|
|
|
1734
1916
|
process.stderr.write(`${dim("○")} LOCUS.md already exists (preserved)
|
|
1735
1917
|
`);
|
|
1736
1918
|
}
|
|
1737
|
-
const learningsMdPath =
|
|
1738
|
-
if (!
|
|
1919
|
+
const learningsMdPath = join6(locusDir, "LEARNINGS.md");
|
|
1920
|
+
if (!existsSync6(learningsMdPath)) {
|
|
1739
1921
|
writeFileSync4(learningsMdPath, LEARNINGS_MD_TEMPLATE, "utf-8");
|
|
1740
1922
|
process.stderr.write(`${green("✓")} Generated LEARNINGS.md
|
|
1741
1923
|
`);
|
|
@@ -1743,13 +1925,29 @@ ${bold("Initializing Locus...")}
|
|
|
1743
1925
|
process.stderr.write(`${dim("○")} LEARNINGS.md already exists (preserved)
|
|
1744
1926
|
`);
|
|
1745
1927
|
}
|
|
1746
|
-
const sandboxIgnorePath =
|
|
1747
|
-
if (!
|
|
1928
|
+
const sandboxIgnorePath = join6(cwd, ".sandboxignore");
|
|
1929
|
+
if (!existsSync6(sandboxIgnorePath)) {
|
|
1748
1930
|
writeFileSync4(sandboxIgnorePath, SANDBOXIGNORE_TEMPLATE, "utf-8");
|
|
1749
1931
|
process.stderr.write(`${green("✓")} Generated .sandboxignore
|
|
1750
1932
|
`);
|
|
1751
1933
|
} else {
|
|
1752
1934
|
process.stderr.write(`${dim("○")} .sandboxignore already exists (preserved)
|
|
1935
|
+
`);
|
|
1936
|
+
}
|
|
1937
|
+
const ecosystem = detectProjectEcosystem(cwd);
|
|
1938
|
+
const sandboxSetupPath = join6(locusDir, "sandbox-setup.sh");
|
|
1939
|
+
if (!existsSync6(sandboxSetupPath)) {
|
|
1940
|
+
const template = generateSandboxSetupTemplate(ecosystem);
|
|
1941
|
+
if (template) {
|
|
1942
|
+
writeFileSync4(sandboxSetupPath, template, {
|
|
1943
|
+
encoding: "utf-8",
|
|
1944
|
+
mode: 493
|
|
1945
|
+
});
|
|
1946
|
+
process.stderr.write(`${green("✓")} Generated .locus/sandbox-setup.sh (${ecosystem} project detected)
|
|
1947
|
+
`);
|
|
1948
|
+
}
|
|
1949
|
+
} else {
|
|
1950
|
+
process.stderr.write(`${dim("○")} sandbox-setup.sh already exists (preserved)
|
|
1753
1951
|
`);
|
|
1754
1952
|
}
|
|
1755
1953
|
process.stderr.write(`${cyan("●")} Creating GitHub labels...`);
|
|
@@ -1761,9 +1959,9 @@ ${bold("Initializing Locus...")}
|
|
|
1761
1959
|
process.stderr.write(`\r${yellow("⚠")} Some labels could not be created: ${e.message}
|
|
1762
1960
|
`);
|
|
1763
1961
|
}
|
|
1764
|
-
const gitignorePath =
|
|
1962
|
+
const gitignorePath = join6(cwd, ".gitignore");
|
|
1765
1963
|
let gitignoreContent = "";
|
|
1766
|
-
if (
|
|
1964
|
+
if (existsSync6(gitignorePath)) {
|
|
1767
1965
|
gitignoreContent = readFileSync4(gitignorePath, "utf-8");
|
|
1768
1966
|
}
|
|
1769
1967
|
const entriesToAdd = GITIGNORE_ENTRIES.filter((entry) => entry && !gitignoreContent.includes(entry.trim()));
|
|
@@ -1996,6 +2194,7 @@ It is read by AI agents before every task to avoid repeating mistakes and to fol
|
|
|
1996
2194
|
var init_init = __esm(() => {
|
|
1997
2195
|
init_config();
|
|
1998
2196
|
init_context();
|
|
2197
|
+
init_ecosystem();
|
|
1999
2198
|
init_github();
|
|
2000
2199
|
init_logger();
|
|
2001
2200
|
init_terminal();
|
|
@@ -2017,33 +2216,33 @@ var init_init = __esm(() => {
|
|
|
2017
2216
|
|
|
2018
2217
|
// src/packages/registry.ts
|
|
2019
2218
|
import {
|
|
2020
|
-
existsSync as
|
|
2219
|
+
existsSync as existsSync7,
|
|
2021
2220
|
mkdirSync as mkdirSync6,
|
|
2022
2221
|
readFileSync as readFileSync5,
|
|
2023
2222
|
renameSync,
|
|
2024
2223
|
writeFileSync as writeFileSync5
|
|
2025
2224
|
} from "node:fs";
|
|
2026
2225
|
import { homedir as homedir2 } from "node:os";
|
|
2027
|
-
import { join as
|
|
2226
|
+
import { join as join7 } from "node:path";
|
|
2028
2227
|
function getPackagesDir() {
|
|
2029
2228
|
const home = process.env.HOME || homedir2();
|
|
2030
|
-
const dir =
|
|
2031
|
-
if (!
|
|
2229
|
+
const dir = join7(home, ".locus", "packages");
|
|
2230
|
+
if (!existsSync7(dir)) {
|
|
2032
2231
|
mkdirSync6(dir, { recursive: true });
|
|
2033
2232
|
}
|
|
2034
|
-
const pkgJson =
|
|
2035
|
-
if (!
|
|
2233
|
+
const pkgJson = join7(dir, "package.json");
|
|
2234
|
+
if (!existsSync7(pkgJson)) {
|
|
2036
2235
|
writeFileSync5(pkgJson, `${JSON.stringify({ private: true }, null, 2)}
|
|
2037
2236
|
`, "utf-8");
|
|
2038
2237
|
}
|
|
2039
2238
|
return dir;
|
|
2040
2239
|
}
|
|
2041
2240
|
function getRegistryPath() {
|
|
2042
|
-
return
|
|
2241
|
+
return join7(getPackagesDir(), "registry.json");
|
|
2043
2242
|
}
|
|
2044
2243
|
function loadRegistry() {
|
|
2045
2244
|
const registryPath = getRegistryPath();
|
|
2046
|
-
if (!
|
|
2245
|
+
if (!existsSync7(registryPath)) {
|
|
2047
2246
|
return { packages: {} };
|
|
2048
2247
|
}
|
|
2049
2248
|
try {
|
|
@@ -2066,8 +2265,8 @@ function saveRegistry(registry) {
|
|
|
2066
2265
|
}
|
|
2067
2266
|
function resolvePackageBinary(packageName) {
|
|
2068
2267
|
const fullName = normalizePackageName(packageName);
|
|
2069
|
-
const binPath =
|
|
2070
|
-
return
|
|
2268
|
+
const binPath = join7(getPackagesDir(), "node_modules", ".bin", fullName);
|
|
2269
|
+
return existsSync7(binPath) ? binPath : null;
|
|
2071
2270
|
}
|
|
2072
2271
|
function normalizePackageName(input) {
|
|
2073
2272
|
if (input.startsWith("@")) {
|
|
@@ -2087,7 +2286,7 @@ __export(exports_pkg, {
|
|
|
2087
2286
|
listInstalledPackages: () => listInstalledPackages
|
|
2088
2287
|
});
|
|
2089
2288
|
import { spawn } from "node:child_process";
|
|
2090
|
-
import { existsSync as
|
|
2289
|
+
import { existsSync as existsSync8 } from "node:fs";
|
|
2091
2290
|
function listInstalledPackages() {
|
|
2092
2291
|
const registry = loadRegistry();
|
|
2093
2292
|
const entries = Object.values(registry.packages);
|
|
@@ -2165,7 +2364,7 @@ async function pkgCommand(args, _flags) {
|
|
|
2165
2364
|
return;
|
|
2166
2365
|
}
|
|
2167
2366
|
const binaryPath = entry.binaryPath;
|
|
2168
|
-
if (!binaryPath || !
|
|
2367
|
+
if (!binaryPath || !existsSync8(binaryPath)) {
|
|
2169
2368
|
process.stderr.write(`${red("✗")} Binary for ${bold(packageName)} not found on disk.
|
|
2170
2369
|
`);
|
|
2171
2370
|
if (binaryPath) {
|
|
@@ -2291,8 +2490,8 @@ __export(exports_install, {
|
|
|
2291
2490
|
installCommand: () => installCommand
|
|
2292
2491
|
});
|
|
2293
2492
|
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
2294
|
-
import { existsSync as
|
|
2295
|
-
import { join as
|
|
2493
|
+
import { existsSync as existsSync9, readFileSync as readFileSync6 } from "node:fs";
|
|
2494
|
+
import { join as join8 } from "node:path";
|
|
2296
2495
|
function parsePackageArg(raw) {
|
|
2297
2496
|
if (raw.startsWith("@")) {
|
|
2298
2497
|
const slashIdx = raw.indexOf("/");
|
|
@@ -2369,8 +2568,8 @@ ${red("✗")} Failed to install ${bold(packageSpec)}.
|
|
|
2369
2568
|
process.exit(1);
|
|
2370
2569
|
return;
|
|
2371
2570
|
}
|
|
2372
|
-
const installedPkgJsonPath =
|
|
2373
|
-
if (!
|
|
2571
|
+
const installedPkgJsonPath = join8(packagesDir, "node_modules", packageName, "package.json");
|
|
2572
|
+
if (!existsSync9(installedPkgJsonPath)) {
|
|
2374
2573
|
process.stderr.write(`
|
|
2375
2574
|
${red("✗")} Package installed but package.json not found at:
|
|
2376
2575
|
`);
|
|
@@ -2645,16 +2844,16 @@ __export(exports_logs, {
|
|
|
2645
2844
|
logsCommand: () => logsCommand
|
|
2646
2845
|
});
|
|
2647
2846
|
import {
|
|
2648
|
-
existsSync as
|
|
2847
|
+
existsSync as existsSync10,
|
|
2649
2848
|
readdirSync as readdirSync2,
|
|
2650
2849
|
readFileSync as readFileSync7,
|
|
2651
2850
|
statSync as statSync2,
|
|
2652
2851
|
unlinkSync as unlinkSync2
|
|
2653
2852
|
} from "node:fs";
|
|
2654
|
-
import { join as
|
|
2853
|
+
import { join as join9 } from "node:path";
|
|
2655
2854
|
async function logsCommand(cwd, options) {
|
|
2656
|
-
const logsDir =
|
|
2657
|
-
if (!
|
|
2855
|
+
const logsDir = join9(cwd, ".locus", "logs");
|
|
2856
|
+
if (!existsSync10(logsDir)) {
|
|
2658
2857
|
process.stderr.write(`${dim("No logs found.")}
|
|
2659
2858
|
`);
|
|
2660
2859
|
return;
|
|
@@ -2709,8 +2908,8 @@ async function tailLog(logFile, levelFilter) {
|
|
|
2709
2908
|
process.stderr.write(`${bold("Tailing:")} ${dim(logFile)} ${dim("(Ctrl+C to stop)")}
|
|
2710
2909
|
|
|
2711
2910
|
`);
|
|
2712
|
-
let lastSize =
|
|
2713
|
-
if (
|
|
2911
|
+
let lastSize = existsSync10(logFile) ? statSync2(logFile).size : 0;
|
|
2912
|
+
if (existsSync10(logFile)) {
|
|
2714
2913
|
const content = readFileSync7(logFile, "utf-8");
|
|
2715
2914
|
const lines = content.trim().split(`
|
|
2716
2915
|
`).filter(Boolean);
|
|
@@ -2729,7 +2928,7 @@ async function tailLog(logFile, levelFilter) {
|
|
|
2729
2928
|
}
|
|
2730
2929
|
return new Promise((resolve) => {
|
|
2731
2930
|
const interval = setInterval(() => {
|
|
2732
|
-
if (!
|
|
2931
|
+
if (!existsSync10(logFile))
|
|
2733
2932
|
return;
|
|
2734
2933
|
const currentSize = statSync2(logFile).size;
|
|
2735
2934
|
if (currentSize <= lastSize)
|
|
@@ -2789,7 +2988,7 @@ function cleanLogs(logsDir) {
|
|
|
2789
2988
|
`);
|
|
2790
2989
|
}
|
|
2791
2990
|
function getLogFiles(logsDir) {
|
|
2792
|
-
return readdirSync2(logsDir).filter((f) => f.startsWith("locus-") && f.endsWith(".log")).map((f) =>
|
|
2991
|
+
return readdirSync2(logsDir).filter((f) => f.startsWith("locus-") && f.endsWith(".log")).map((f) => join9(logsDir, f)).sort((a, b) => statSync2(b).mtimeMs - statSync2(a).mtimeMs);
|
|
2793
2992
|
}
|
|
2794
2993
|
function formatEntry(entry) {
|
|
2795
2994
|
const time = dim(new Date(entry.ts).toLocaleTimeString());
|
|
@@ -3099,9 +3298,9 @@ var init_stream_renderer = __esm(() => {
|
|
|
3099
3298
|
|
|
3100
3299
|
// src/repl/clipboard.ts
|
|
3101
3300
|
import { execSync as execSync4 } from "node:child_process";
|
|
3102
|
-
import { existsSync as
|
|
3301
|
+
import { existsSync as existsSync11, mkdirSync as mkdirSync7 } from "node:fs";
|
|
3103
3302
|
import { tmpdir } from "node:os";
|
|
3104
|
-
import { join as
|
|
3303
|
+
import { join as join10 } from "node:path";
|
|
3105
3304
|
function readClipboardImage() {
|
|
3106
3305
|
if (process.platform === "darwin") {
|
|
3107
3306
|
return readMacOSClipboardImage();
|
|
@@ -3112,14 +3311,14 @@ function readClipboardImage() {
|
|
|
3112
3311
|
return null;
|
|
3113
3312
|
}
|
|
3114
3313
|
function ensureStableDir() {
|
|
3115
|
-
if (!
|
|
3314
|
+
if (!existsSync11(STABLE_DIR)) {
|
|
3116
3315
|
mkdirSync7(STABLE_DIR, { recursive: true });
|
|
3117
3316
|
}
|
|
3118
3317
|
}
|
|
3119
3318
|
function readMacOSClipboardImage() {
|
|
3120
3319
|
try {
|
|
3121
3320
|
ensureStableDir();
|
|
3122
|
-
const destPath =
|
|
3321
|
+
const destPath = join10(STABLE_DIR, `clipboard-${Date.now()}.png`);
|
|
3123
3322
|
const script = [
|
|
3124
3323
|
`set destPath to POSIX file "${destPath}"`,
|
|
3125
3324
|
"try",
|
|
@@ -3143,7 +3342,7 @@ function readMacOSClipboardImage() {
|
|
|
3143
3342
|
timeout: 5000,
|
|
3144
3343
|
stdio: ["pipe", "pipe", "pipe"]
|
|
3145
3344
|
}).trim();
|
|
3146
|
-
if (result === "ok" &&
|
|
3345
|
+
if (result === "ok" && existsSync11(destPath)) {
|
|
3147
3346
|
return destPath;
|
|
3148
3347
|
}
|
|
3149
3348
|
} catch {}
|
|
@@ -3156,9 +3355,9 @@ function readLinuxClipboardImage() {
|
|
|
3156
3355
|
return null;
|
|
3157
3356
|
}
|
|
3158
3357
|
ensureStableDir();
|
|
3159
|
-
const destPath =
|
|
3358
|
+
const destPath = join10(STABLE_DIR, `clipboard-${Date.now()}.png`);
|
|
3160
3359
|
execSync4(`xclip -selection clipboard -t image/png -o > "${destPath}" 2>/dev/null`, { timeout: 5000 });
|
|
3161
|
-
if (
|
|
3360
|
+
if (existsSync11(destPath)) {
|
|
3162
3361
|
return destPath;
|
|
3163
3362
|
}
|
|
3164
3363
|
} catch {}
|
|
@@ -3166,13 +3365,13 @@ function readLinuxClipboardImage() {
|
|
|
3166
3365
|
}
|
|
3167
3366
|
var STABLE_DIR;
|
|
3168
3367
|
var init_clipboard = __esm(() => {
|
|
3169
|
-
STABLE_DIR =
|
|
3368
|
+
STABLE_DIR = join10(tmpdir(), "locus-images");
|
|
3170
3369
|
});
|
|
3171
3370
|
|
|
3172
3371
|
// src/repl/image-detect.ts
|
|
3173
|
-
import { copyFileSync, existsSync as
|
|
3372
|
+
import { copyFileSync, existsSync as existsSync12, mkdirSync as mkdirSync8 } from "node:fs";
|
|
3174
3373
|
import { homedir as homedir3, tmpdir as tmpdir2 } from "node:os";
|
|
3175
|
-
import { basename, extname, join as
|
|
3374
|
+
import { basename, extname, join as join11, resolve } from "node:path";
|
|
3176
3375
|
function detectImages(input) {
|
|
3177
3376
|
const detected = [];
|
|
3178
3377
|
const byResolved = new Map;
|
|
@@ -3266,15 +3465,15 @@ function collectReferencedAttachments(input, attachments) {
|
|
|
3266
3465
|
return dedupeByResolvedPath(selected);
|
|
3267
3466
|
}
|
|
3268
3467
|
function relocateImages(images, projectRoot) {
|
|
3269
|
-
const targetDir =
|
|
3468
|
+
const targetDir = join11(projectRoot, ".locus", "tmp", "images");
|
|
3270
3469
|
for (const img of images) {
|
|
3271
3470
|
if (!img.exists)
|
|
3272
3471
|
continue;
|
|
3273
3472
|
try {
|
|
3274
|
-
if (!
|
|
3473
|
+
if (!existsSync12(targetDir)) {
|
|
3275
3474
|
mkdirSync8(targetDir, { recursive: true });
|
|
3276
3475
|
}
|
|
3277
|
-
const dest =
|
|
3476
|
+
const dest = join11(targetDir, basename(img.stablePath));
|
|
3278
3477
|
copyFileSync(img.stablePath, dest);
|
|
3279
3478
|
img.stablePath = dest;
|
|
3280
3479
|
} catch {}
|
|
@@ -3286,7 +3485,7 @@ function addIfImage(rawPath, rawMatch, detected, byResolved) {
|
|
|
3286
3485
|
return;
|
|
3287
3486
|
let resolved = stripQuotes(rawPath).replace(/\\ /g, " ");
|
|
3288
3487
|
if (resolved.startsWith("~/")) {
|
|
3289
|
-
resolved =
|
|
3488
|
+
resolved = join11(homedir3(), resolved.slice(2));
|
|
3290
3489
|
}
|
|
3291
3490
|
resolved = resolve(resolved);
|
|
3292
3491
|
const existing = byResolved.get(resolved);
|
|
@@ -3299,7 +3498,7 @@ function addIfImage(rawPath, rawMatch, detected, byResolved) {
|
|
|
3299
3498
|
]);
|
|
3300
3499
|
return;
|
|
3301
3500
|
}
|
|
3302
|
-
const exists =
|
|
3501
|
+
const exists = existsSync12(resolved);
|
|
3303
3502
|
let stablePath = resolved;
|
|
3304
3503
|
if (exists) {
|
|
3305
3504
|
stablePath = copyToStable(resolved);
|
|
@@ -3353,10 +3552,10 @@ function dedupeByResolvedPath(images) {
|
|
|
3353
3552
|
}
|
|
3354
3553
|
function copyToStable(sourcePath) {
|
|
3355
3554
|
try {
|
|
3356
|
-
if (!
|
|
3555
|
+
if (!existsSync12(STABLE_DIR2)) {
|
|
3357
3556
|
mkdirSync8(STABLE_DIR2, { recursive: true });
|
|
3358
3557
|
}
|
|
3359
|
-
const dest =
|
|
3558
|
+
const dest = join11(STABLE_DIR2, `${Date.now()}-${basename(sourcePath)}`);
|
|
3360
3559
|
copyFileSync(sourcePath, dest);
|
|
3361
3560
|
return dest;
|
|
3362
3561
|
} catch {
|
|
@@ -3376,7 +3575,7 @@ var init_image_detect = __esm(() => {
|
|
|
3376
3575
|
".tif",
|
|
3377
3576
|
".tiff"
|
|
3378
3577
|
]);
|
|
3379
|
-
STABLE_DIR2 =
|
|
3578
|
+
STABLE_DIR2 = join11(tmpdir2(), "locus-images");
|
|
3380
3579
|
PLACEHOLDER_ID_PATTERN = /\(locus:\/\/screenshot-(\d+)\)/g;
|
|
3381
3580
|
});
|
|
3382
3581
|
|
|
@@ -4160,10 +4359,7 @@ __export(exports_claude, {
|
|
|
4160
4359
|
});
|
|
4161
4360
|
import { execSync as execSync5, spawn as spawn2 } from "node:child_process";
|
|
4162
4361
|
function buildClaudeArgs(options) {
|
|
4163
|
-
const args = [
|
|
4164
|
-
"--dangerously-skip-permissions",
|
|
4165
|
-
"--no-session-persistence"
|
|
4166
|
-
];
|
|
4362
|
+
const args = ["--dangerously-skip-permissions", "--no-session-persistence"];
|
|
4167
4363
|
if (options.model) {
|
|
4168
4364
|
args.push("--model", options.model);
|
|
4169
4365
|
}
|
|
@@ -4355,11 +4551,11 @@ var init_claude = __esm(() => {
|
|
|
4355
4551
|
|
|
4356
4552
|
// src/core/sandbox-ignore.ts
|
|
4357
4553
|
import { exec } from "node:child_process";
|
|
4358
|
-
import { existsSync as
|
|
4359
|
-
import { join as
|
|
4554
|
+
import { existsSync as existsSync13, readFileSync as readFileSync8 } from "node:fs";
|
|
4555
|
+
import { join as join12 } from "node:path";
|
|
4360
4556
|
import { promisify } from "node:util";
|
|
4361
4557
|
function parseIgnoreFile(filePath) {
|
|
4362
|
-
if (!
|
|
4558
|
+
if (!existsSync13(filePath))
|
|
4363
4559
|
return [];
|
|
4364
4560
|
const content = readFileSync8(filePath, "utf-8");
|
|
4365
4561
|
const rules = [];
|
|
@@ -4406,7 +4602,7 @@ function buildCleanupScript(rules, workspacePath) {
|
|
|
4406
4602
|
}
|
|
4407
4603
|
async function enforceSandboxIgnore(sandboxName, projectRoot) {
|
|
4408
4604
|
const log = getLogger();
|
|
4409
|
-
const ignorePath =
|
|
4605
|
+
const ignorePath = join12(projectRoot, ".sandboxignore");
|
|
4410
4606
|
const rules = parseIgnoreFile(ignorePath);
|
|
4411
4607
|
if (rules.length === 0)
|
|
4412
4608
|
return;
|
|
@@ -6685,8 +6881,8 @@ var init_sprint = __esm(() => {
|
|
|
6685
6881
|
|
|
6686
6882
|
// src/core/prompt-builder.ts
|
|
6687
6883
|
import { execSync as execSync7 } from "node:child_process";
|
|
6688
|
-
import { existsSync as
|
|
6689
|
-
import { join as
|
|
6884
|
+
import { existsSync as existsSync14, readdirSync as readdirSync3, readFileSync as readFileSync9 } from "node:fs";
|
|
6885
|
+
import { join as join13 } from "node:path";
|
|
6690
6886
|
function buildExecutionPrompt(ctx) {
|
|
6691
6887
|
const sections = [];
|
|
6692
6888
|
sections.push(buildSystemContext(ctx.projectRoot));
|
|
@@ -6716,13 +6912,13 @@ function buildFeedbackPrompt(ctx) {
|
|
|
6716
6912
|
}
|
|
6717
6913
|
function buildReplPrompt(userMessage, projectRoot, _config, previousMessages) {
|
|
6718
6914
|
const sections = [];
|
|
6719
|
-
const locusmd = readFileSafe(
|
|
6915
|
+
const locusmd = readFileSafe(join13(projectRoot, ".locus", "LOCUS.md"));
|
|
6720
6916
|
if (locusmd) {
|
|
6721
6917
|
sections.push(`<project-instructions>
|
|
6722
6918
|
${locusmd}
|
|
6723
6919
|
</project-instructions>`);
|
|
6724
6920
|
}
|
|
6725
|
-
const learnings = readFileSafe(
|
|
6921
|
+
const learnings = readFileSafe(join13(projectRoot, ".locus", "LEARNINGS.md"));
|
|
6726
6922
|
if (learnings) {
|
|
6727
6923
|
sections.push(`<past-learnings>
|
|
6728
6924
|
${learnings}
|
|
@@ -6748,24 +6944,24 @@ ${userMessage}
|
|
|
6748
6944
|
}
|
|
6749
6945
|
function buildSystemContext(projectRoot) {
|
|
6750
6946
|
const parts = [];
|
|
6751
|
-
const locusmd = readFileSafe(
|
|
6947
|
+
const locusmd = readFileSafe(join13(projectRoot, ".locus", "LOCUS.md"));
|
|
6752
6948
|
if (locusmd) {
|
|
6753
6949
|
parts.push(`<project-instructions>
|
|
6754
6950
|
${locusmd}
|
|
6755
6951
|
</project-instructions>`);
|
|
6756
6952
|
}
|
|
6757
|
-
const learnings = readFileSafe(
|
|
6953
|
+
const learnings = readFileSafe(join13(projectRoot, ".locus", "LEARNINGS.md"));
|
|
6758
6954
|
if (learnings) {
|
|
6759
6955
|
parts.push(`<past-learnings>
|
|
6760
6956
|
${learnings}
|
|
6761
6957
|
</past-learnings>`);
|
|
6762
6958
|
}
|
|
6763
|
-
const discussionsDir =
|
|
6764
|
-
if (
|
|
6959
|
+
const discussionsDir = join13(projectRoot, ".locus", "discussions");
|
|
6960
|
+
if (existsSync14(discussionsDir)) {
|
|
6765
6961
|
try {
|
|
6766
6962
|
const files = readdirSync3(discussionsDir).filter((f) => f.endsWith(".md")).slice(0, 3);
|
|
6767
6963
|
for (const file of files) {
|
|
6768
|
-
const content = readFileSafe(
|
|
6964
|
+
const content = readFileSafe(join13(discussionsDir, file));
|
|
6769
6965
|
if (content) {
|
|
6770
6966
|
const name = file.replace(".md", "");
|
|
6771
6967
|
parts.push(`<discussion name="${name}">
|
|
@@ -6916,7 +7112,7 @@ function buildFeedbackInstructions() {
|
|
|
6916
7112
|
}
|
|
6917
7113
|
function readFileSafe(path) {
|
|
6918
7114
|
try {
|
|
6919
|
-
if (!
|
|
7115
|
+
if (!existsSync14(path))
|
|
6920
7116
|
return null;
|
|
6921
7117
|
return readFileSync9(path, "utf-8");
|
|
6922
7118
|
} catch {
|
|
@@ -7382,7 +7578,7 @@ var init_commands = __esm(() => {
|
|
|
7382
7578
|
|
|
7383
7579
|
// src/repl/completions.ts
|
|
7384
7580
|
import { readdirSync as readdirSync4 } from "node:fs";
|
|
7385
|
-
import { basename as basename2, dirname as dirname3, join as
|
|
7581
|
+
import { basename as basename2, dirname as dirname3, join as join14 } from "node:path";
|
|
7386
7582
|
|
|
7387
7583
|
class SlashCommandCompletion {
|
|
7388
7584
|
commands;
|
|
@@ -7437,7 +7633,7 @@ class FilePathCompletion {
|
|
|
7437
7633
|
}
|
|
7438
7634
|
findMatches(partial) {
|
|
7439
7635
|
try {
|
|
7440
|
-
const dir = partial.includes("/") ?
|
|
7636
|
+
const dir = partial.includes("/") ? join14(this.projectRoot, dirname3(partial)) : this.projectRoot;
|
|
7441
7637
|
const prefix = basename2(partial);
|
|
7442
7638
|
const entries = readdirSync4(dir, { withFileTypes: true });
|
|
7443
7639
|
return entries.filter((e) => {
|
|
@@ -7473,14 +7669,14 @@ class CombinedCompletion {
|
|
|
7473
7669
|
var init_completions = () => {};
|
|
7474
7670
|
|
|
7475
7671
|
// src/repl/input-history.ts
|
|
7476
|
-
import { existsSync as
|
|
7477
|
-
import { dirname as dirname4, join as
|
|
7672
|
+
import { existsSync as existsSync15, mkdirSync as mkdirSync9, readFileSync as readFileSync10, writeFileSync as writeFileSync6 } from "node:fs";
|
|
7673
|
+
import { dirname as dirname4, join as join15 } from "node:path";
|
|
7478
7674
|
|
|
7479
7675
|
class InputHistory {
|
|
7480
7676
|
entries = [];
|
|
7481
7677
|
filePath;
|
|
7482
7678
|
constructor(projectRoot) {
|
|
7483
|
-
this.filePath =
|
|
7679
|
+
this.filePath = join15(projectRoot, ".locus", "sessions", ".input-history");
|
|
7484
7680
|
this.load();
|
|
7485
7681
|
}
|
|
7486
7682
|
add(text) {
|
|
@@ -7519,7 +7715,7 @@ class InputHistory {
|
|
|
7519
7715
|
}
|
|
7520
7716
|
load() {
|
|
7521
7717
|
try {
|
|
7522
|
-
if (!
|
|
7718
|
+
if (!existsSync15(this.filePath))
|
|
7523
7719
|
return;
|
|
7524
7720
|
const content = readFileSync10(this.filePath, "utf-8");
|
|
7525
7721
|
this.entries = content.split(`
|
|
@@ -7529,7 +7725,7 @@ class InputHistory {
|
|
|
7529
7725
|
save() {
|
|
7530
7726
|
try {
|
|
7531
7727
|
const dir = dirname4(this.filePath);
|
|
7532
|
-
if (!
|
|
7728
|
+
if (!existsSync15(dir)) {
|
|
7533
7729
|
mkdirSync9(dir, { recursive: true });
|
|
7534
7730
|
}
|
|
7535
7731
|
const content = this.entries.map((e) => this.escape(e)).join(`
|
|
@@ -7560,20 +7756,20 @@ var init_model_config = __esm(() => {
|
|
|
7560
7756
|
|
|
7561
7757
|
// src/repl/session-manager.ts
|
|
7562
7758
|
import {
|
|
7563
|
-
existsSync as
|
|
7759
|
+
existsSync as existsSync16,
|
|
7564
7760
|
mkdirSync as mkdirSync10,
|
|
7565
7761
|
readdirSync as readdirSync5,
|
|
7566
7762
|
readFileSync as readFileSync11,
|
|
7567
7763
|
unlinkSync as unlinkSync3,
|
|
7568
7764
|
writeFileSync as writeFileSync7
|
|
7569
7765
|
} from "node:fs";
|
|
7570
|
-
import { basename as basename3, join as
|
|
7766
|
+
import { basename as basename3, join as join16 } from "node:path";
|
|
7571
7767
|
|
|
7572
7768
|
class SessionManager {
|
|
7573
7769
|
sessionsDir;
|
|
7574
7770
|
constructor(projectRoot) {
|
|
7575
|
-
this.sessionsDir =
|
|
7576
|
-
if (!
|
|
7771
|
+
this.sessionsDir = join16(projectRoot, ".locus", "sessions");
|
|
7772
|
+
if (!existsSync16(this.sessionsDir)) {
|
|
7577
7773
|
mkdirSync10(this.sessionsDir, { recursive: true });
|
|
7578
7774
|
}
|
|
7579
7775
|
}
|
|
@@ -7599,12 +7795,12 @@ class SessionManager {
|
|
|
7599
7795
|
}
|
|
7600
7796
|
isPersisted(sessionOrId) {
|
|
7601
7797
|
const sessionId = typeof sessionOrId === "string" ? sessionOrId : sessionOrId.id;
|
|
7602
|
-
return
|
|
7798
|
+
return existsSync16(this.getSessionPath(sessionId));
|
|
7603
7799
|
}
|
|
7604
7800
|
load(idOrPrefix) {
|
|
7605
7801
|
const files = this.listSessionFiles();
|
|
7606
7802
|
const exactPath = this.getSessionPath(idOrPrefix);
|
|
7607
|
-
if (
|
|
7803
|
+
if (existsSync16(exactPath)) {
|
|
7608
7804
|
try {
|
|
7609
7805
|
return JSON.parse(readFileSync11(exactPath, "utf-8"));
|
|
7610
7806
|
} catch {
|
|
@@ -7654,7 +7850,7 @@ class SessionManager {
|
|
|
7654
7850
|
}
|
|
7655
7851
|
delete(sessionId) {
|
|
7656
7852
|
const path = this.getSessionPath(sessionId);
|
|
7657
|
-
if (
|
|
7853
|
+
if (existsSync16(path)) {
|
|
7658
7854
|
unlinkSync3(path);
|
|
7659
7855
|
return true;
|
|
7660
7856
|
}
|
|
@@ -7684,7 +7880,7 @@ class SessionManager {
|
|
|
7684
7880
|
const remaining = withStats.length - pruned;
|
|
7685
7881
|
if (remaining > MAX_SESSIONS) {
|
|
7686
7882
|
const toRemove = remaining - MAX_SESSIONS;
|
|
7687
|
-
const alive = withStats.filter((e) =>
|
|
7883
|
+
const alive = withStats.filter((e) => existsSync16(e.path));
|
|
7688
7884
|
for (let i = 0;i < toRemove && i < alive.length; i++) {
|
|
7689
7885
|
try {
|
|
7690
7886
|
unlinkSync3(alive[i].path);
|
|
@@ -7699,7 +7895,7 @@ class SessionManager {
|
|
|
7699
7895
|
}
|
|
7700
7896
|
listSessionFiles() {
|
|
7701
7897
|
try {
|
|
7702
|
-
return readdirSync5(this.sessionsDir).filter((f) => f.endsWith(".json") && !f.startsWith(".")).map((f) =>
|
|
7898
|
+
return readdirSync5(this.sessionsDir).filter((f) => f.endsWith(".json") && !f.startsWith(".")).map((f) => join16(this.sessionsDir, f));
|
|
7703
7899
|
} catch {
|
|
7704
7900
|
return [];
|
|
7705
7901
|
}
|
|
@@ -7708,7 +7904,7 @@ class SessionManager {
|
|
|
7708
7904
|
return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
7709
7905
|
}
|
|
7710
7906
|
getSessionPath(sessionId) {
|
|
7711
|
-
return
|
|
7907
|
+
return join16(this.sessionsDir, `${sessionId}.json`);
|
|
7712
7908
|
}
|
|
7713
7909
|
}
|
|
7714
7910
|
var MAX_SESSIONS = 50, SESSION_MAX_AGE_MS;
|
|
@@ -8185,8 +8381,167 @@ var init_exec = __esm(() => {
|
|
|
8185
8381
|
init_session_manager();
|
|
8186
8382
|
});
|
|
8187
8383
|
|
|
8188
|
-
// src/core/
|
|
8384
|
+
// src/core/submodule.ts
|
|
8189
8385
|
import { execSync as execSync10 } from "node:child_process";
|
|
8386
|
+
import { existsSync as existsSync17 } from "node:fs";
|
|
8387
|
+
import { join as join17 } from "node:path";
|
|
8388
|
+
function git2(args, cwd) {
|
|
8389
|
+
return execSync10(`git ${args}`, {
|
|
8390
|
+
cwd,
|
|
8391
|
+
encoding: "utf-8",
|
|
8392
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
8393
|
+
});
|
|
8394
|
+
}
|
|
8395
|
+
function gitSafe(args, cwd) {
|
|
8396
|
+
try {
|
|
8397
|
+
return git2(args, cwd);
|
|
8398
|
+
} catch {
|
|
8399
|
+
return null;
|
|
8400
|
+
}
|
|
8401
|
+
}
|
|
8402
|
+
function hasSubmodules(cwd) {
|
|
8403
|
+
return existsSync17(join17(cwd, ".gitmodules"));
|
|
8404
|
+
}
|
|
8405
|
+
function listSubmodules(cwd) {
|
|
8406
|
+
if (!hasSubmodules(cwd))
|
|
8407
|
+
return [];
|
|
8408
|
+
const log = getLogger();
|
|
8409
|
+
const submodules = [];
|
|
8410
|
+
try {
|
|
8411
|
+
const output = git2("submodule status", cwd);
|
|
8412
|
+
for (const line of output.trim().split(`
|
|
8413
|
+
`)) {
|
|
8414
|
+
if (!line.trim())
|
|
8415
|
+
continue;
|
|
8416
|
+
const dirty = line.startsWith("+");
|
|
8417
|
+
const parts = line.trim().replace(/^[+-]/, "").split(/\s+/);
|
|
8418
|
+
const path = parts[1];
|
|
8419
|
+
if (!path)
|
|
8420
|
+
continue;
|
|
8421
|
+
submodules.push({
|
|
8422
|
+
path,
|
|
8423
|
+
absolutePath: join17(cwd, path),
|
|
8424
|
+
dirty
|
|
8425
|
+
});
|
|
8426
|
+
}
|
|
8427
|
+
} catch (e) {
|
|
8428
|
+
log.warn(`Failed to list submodules: ${e}`);
|
|
8429
|
+
}
|
|
8430
|
+
return submodules;
|
|
8431
|
+
}
|
|
8432
|
+
function getDirtySubmodules(cwd) {
|
|
8433
|
+
const submodules = listSubmodules(cwd);
|
|
8434
|
+
const dirty = [];
|
|
8435
|
+
for (const sub of submodules) {
|
|
8436
|
+
if (!existsSync17(sub.absolutePath))
|
|
8437
|
+
continue;
|
|
8438
|
+
const status = gitSafe("status --porcelain", sub.absolutePath);
|
|
8439
|
+
if (status && status.trim().length > 0) {
|
|
8440
|
+
dirty.push({ ...sub, dirty: true });
|
|
8441
|
+
}
|
|
8442
|
+
}
|
|
8443
|
+
return dirty;
|
|
8444
|
+
}
|
|
8445
|
+
function commitDirtySubmodules(cwd, issueNumber, issueTitle) {
|
|
8446
|
+
const log = getLogger();
|
|
8447
|
+
const dirtySubmodules = getDirtySubmodules(cwd);
|
|
8448
|
+
if (dirtySubmodules.length === 0)
|
|
8449
|
+
return [];
|
|
8450
|
+
const committed = [];
|
|
8451
|
+
for (const sub of dirtySubmodules) {
|
|
8452
|
+
try {
|
|
8453
|
+
git2("add -A", sub.absolutePath);
|
|
8454
|
+
const message = `chore: complete #${issueNumber} - ${issueTitle}
|
|
8455
|
+
|
|
8456
|
+
Co-Authored-By: LocusAgent <agent@locusai.team>`;
|
|
8457
|
+
execSync10("git commit -F -", {
|
|
8458
|
+
input: message,
|
|
8459
|
+
cwd: sub.absolutePath,
|
|
8460
|
+
encoding: "utf-8",
|
|
8461
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
8462
|
+
});
|
|
8463
|
+
committed.push(sub.path);
|
|
8464
|
+
log.info(`Committed submodule changes: ${sub.path} for #${issueNumber}`);
|
|
8465
|
+
} catch {
|
|
8466
|
+
log.verbose(`No committable changes in submodule ${sub.path}`);
|
|
8467
|
+
}
|
|
8468
|
+
}
|
|
8469
|
+
if (committed.length > 0) {
|
|
8470
|
+
for (const subPath of committed) {
|
|
8471
|
+
gitSafe(`add ${subPath}`, cwd);
|
|
8472
|
+
}
|
|
8473
|
+
}
|
|
8474
|
+
return committed;
|
|
8475
|
+
}
|
|
8476
|
+
function initSubmodules(cwd) {
|
|
8477
|
+
if (!hasSubmodules(cwd))
|
|
8478
|
+
return;
|
|
8479
|
+
const log = getLogger();
|
|
8480
|
+
try {
|
|
8481
|
+
git2("submodule update --init --recursive", cwd);
|
|
8482
|
+
log.info("Initialized submodules");
|
|
8483
|
+
} catch (e) {
|
|
8484
|
+
log.warn(`Failed to initialize submodules: ${e}`);
|
|
8485
|
+
}
|
|
8486
|
+
}
|
|
8487
|
+
function updateSubmodulesAfterRebase(cwd) {
|
|
8488
|
+
if (!hasSubmodules(cwd))
|
|
8489
|
+
return;
|
|
8490
|
+
const log = getLogger();
|
|
8491
|
+
try {
|
|
8492
|
+
git2("submodule update --recursive", cwd);
|
|
8493
|
+
log.info("Updated submodules after rebase");
|
|
8494
|
+
} catch (e) {
|
|
8495
|
+
log.warn(`Failed to update submodules after rebase: ${e}`);
|
|
8496
|
+
}
|
|
8497
|
+
}
|
|
8498
|
+
function getSubmoduleChangeSummary(cwd, baseBranch) {
|
|
8499
|
+
if (!hasSubmodules(cwd))
|
|
8500
|
+
return null;
|
|
8501
|
+
const diff = gitSafe(`diff origin/${baseBranch}..HEAD --submodule=short`, cwd);
|
|
8502
|
+
if (!diff || !diff.trim())
|
|
8503
|
+
return null;
|
|
8504
|
+
const submoduleChanges = [];
|
|
8505
|
+
for (const line of diff.split(`
|
|
8506
|
+
`)) {
|
|
8507
|
+
if (line.startsWith("Submodule ")) {
|
|
8508
|
+
submoduleChanges.push(line.trim());
|
|
8509
|
+
}
|
|
8510
|
+
}
|
|
8511
|
+
if (submoduleChanges.length === 0)
|
|
8512
|
+
return null;
|
|
8513
|
+
return `### Submodule Changes
|
|
8514
|
+
${submoduleChanges.map((c) => `- ${c}`).join(`
|
|
8515
|
+
`)}`;
|
|
8516
|
+
}
|
|
8517
|
+
function pushSubmoduleBranches(cwd) {
|
|
8518
|
+
if (!hasSubmodules(cwd))
|
|
8519
|
+
return;
|
|
8520
|
+
const log = getLogger();
|
|
8521
|
+
const submodules = listSubmodules(cwd);
|
|
8522
|
+
for (const sub of submodules) {
|
|
8523
|
+
if (!existsSync17(sub.absolutePath))
|
|
8524
|
+
continue;
|
|
8525
|
+
const branch = gitSafe("rev-parse --abbrev-ref HEAD", sub.absolutePath)?.trim();
|
|
8526
|
+
if (!branch || branch === "HEAD")
|
|
8527
|
+
continue;
|
|
8528
|
+
const unpushed = gitSafe(`log origin/${branch}..HEAD --oneline`, sub.absolutePath)?.trim();
|
|
8529
|
+
if (unpushed) {
|
|
8530
|
+
try {
|
|
8531
|
+
git2(`push origin ${branch}`, sub.absolutePath);
|
|
8532
|
+
log.info(`Pushed submodule ${sub.path} branch ${branch}`);
|
|
8533
|
+
} catch (e) {
|
|
8534
|
+
log.warn(`Failed to push submodule ${sub.path}: ${e}`);
|
|
8535
|
+
}
|
|
8536
|
+
}
|
|
8537
|
+
}
|
|
8538
|
+
}
|
|
8539
|
+
var init_submodule = __esm(() => {
|
|
8540
|
+
init_logger();
|
|
8541
|
+
});
|
|
8542
|
+
|
|
8543
|
+
// src/core/agent.ts
|
|
8544
|
+
import { execSync as execSync11 } from "node:child_process";
|
|
8190
8545
|
async function executeIssue(projectRoot, options) {
|
|
8191
8546
|
const log = getLogger();
|
|
8192
8547
|
const timer = createTimer();
|
|
@@ -8215,7 +8570,7 @@ ${cyan("●")} ${bold(`#${issueNumber}`)} ${issue.title}
|
|
|
8215
8570
|
}
|
|
8216
8571
|
let issueComments = [];
|
|
8217
8572
|
try {
|
|
8218
|
-
const commentsRaw =
|
|
8573
|
+
const commentsRaw = execSync11(`gh issue view ${issueNumber} --json comments --jq '.comments[].body'`, { cwd: projectRoot, encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] }).trim();
|
|
8219
8574
|
if (commentsRaw) {
|
|
8220
8575
|
issueComments = commentsRaw.split(`
|
|
8221
8576
|
`).filter(Boolean);
|
|
@@ -8379,12 +8734,12 @@ ${aiResult.success ? green("✓") : red("✗")} Iteration ${aiResult.success ? "
|
|
|
8379
8734
|
}
|
|
8380
8735
|
async function createIssuePR(projectRoot, config, issue) {
|
|
8381
8736
|
try {
|
|
8382
|
-
const currentBranch =
|
|
8737
|
+
const currentBranch = execSync11("git rev-parse --abbrev-ref HEAD", {
|
|
8383
8738
|
cwd: projectRoot,
|
|
8384
8739
|
encoding: "utf-8",
|
|
8385
8740
|
stdio: ["pipe", "pipe", "pipe"]
|
|
8386
8741
|
}).trim();
|
|
8387
|
-
const diff =
|
|
8742
|
+
const diff = execSync11(`git diff origin/${config.agent.baseBranch}..HEAD --stat`, {
|
|
8388
8743
|
cwd: projectRoot,
|
|
8389
8744
|
encoding: "utf-8",
|
|
8390
8745
|
stdio: ["pipe", "pipe", "pipe"]
|
|
@@ -8393,17 +8748,25 @@ async function createIssuePR(projectRoot, config, issue) {
|
|
|
8393
8748
|
getLogger().verbose("No changes to create PR for");
|
|
8394
8749
|
return;
|
|
8395
8750
|
}
|
|
8396
|
-
|
|
8751
|
+
pushSubmoduleBranches(projectRoot);
|
|
8752
|
+
execSync11(`git push -u origin ${currentBranch}`, {
|
|
8397
8753
|
cwd: projectRoot,
|
|
8398
8754
|
encoding: "utf-8",
|
|
8399
8755
|
stdio: ["pipe", "pipe", "pipe"]
|
|
8400
8756
|
});
|
|
8401
|
-
const
|
|
8402
|
-
|
|
8757
|
+
const submoduleSummary = getSubmoduleChangeSummary(projectRoot, config.agent.baseBranch);
|
|
8758
|
+
let prBody = `Closes #${issue.number}`;
|
|
8759
|
+
if (submoduleSummary) {
|
|
8760
|
+
prBody += `
|
|
8761
|
+
|
|
8762
|
+
${submoduleSummary}`;
|
|
8763
|
+
}
|
|
8764
|
+
prBody += `
|
|
8403
8765
|
|
|
8404
8766
|
---
|
|
8405
8767
|
|
|
8406
8768
|
\uD83E\uDD16 Automated by [Locus](https://github.com/locusai/locus)`;
|
|
8769
|
+
const prTitle = `${issue.title} (#${issue.number})`;
|
|
8407
8770
|
const prNumber = createPR(prTitle, prBody, currentBranch, config.agent.baseBranch, { cwd: projectRoot });
|
|
8408
8771
|
process.stderr.write(` ${green("✓")} Created PR #${prNumber}
|
|
8409
8772
|
`);
|
|
@@ -8437,20 +8800,21 @@ var init_agent = __esm(() => {
|
|
|
8437
8800
|
init_logger();
|
|
8438
8801
|
init_prompt_builder();
|
|
8439
8802
|
init_sandbox();
|
|
8803
|
+
init_submodule();
|
|
8440
8804
|
});
|
|
8441
8805
|
|
|
8442
8806
|
// src/core/conflict.ts
|
|
8443
|
-
import { execSync as
|
|
8444
|
-
function
|
|
8445
|
-
return
|
|
8807
|
+
import { execSync as execSync12 } from "node:child_process";
|
|
8808
|
+
function git3(args, cwd) {
|
|
8809
|
+
return execSync12(`git ${args}`, {
|
|
8446
8810
|
cwd,
|
|
8447
8811
|
encoding: "utf-8",
|
|
8448
8812
|
stdio: ["pipe", "pipe", "pipe"]
|
|
8449
8813
|
});
|
|
8450
8814
|
}
|
|
8451
|
-
function
|
|
8815
|
+
function gitSafe2(args, cwd) {
|
|
8452
8816
|
try {
|
|
8453
|
-
return
|
|
8817
|
+
return git3(args, cwd);
|
|
8454
8818
|
} catch {
|
|
8455
8819
|
return null;
|
|
8456
8820
|
}
|
|
@@ -8458,7 +8822,7 @@ function gitSafe(args, cwd) {
|
|
|
8458
8822
|
function checkForConflicts(cwd, baseBranch) {
|
|
8459
8823
|
const log = getLogger();
|
|
8460
8824
|
try {
|
|
8461
|
-
|
|
8825
|
+
git3(`fetch origin ${baseBranch}`, cwd);
|
|
8462
8826
|
log.debug("Fetched latest from origin", { baseBranch });
|
|
8463
8827
|
} catch (e) {
|
|
8464
8828
|
log.warn(`Could not fetch origin/${baseBranch}: ${e}`);
|
|
@@ -8469,8 +8833,8 @@ function checkForConflicts(cwd, baseBranch) {
|
|
|
8469
8833
|
newCommits: 0
|
|
8470
8834
|
};
|
|
8471
8835
|
}
|
|
8472
|
-
const currentBranch =
|
|
8473
|
-
const mergeBase =
|
|
8836
|
+
const currentBranch = gitSafe2("rev-parse --abbrev-ref HEAD", cwd)?.trim() ?? "";
|
|
8837
|
+
const mergeBase = gitSafe2(`merge-base ${currentBranch} origin/${baseBranch}`, cwd)?.trim();
|
|
8474
8838
|
if (!mergeBase) {
|
|
8475
8839
|
log.debug("Could not find merge base — branches may be unrelated");
|
|
8476
8840
|
return {
|
|
@@ -8480,7 +8844,7 @@ function checkForConflicts(cwd, baseBranch) {
|
|
|
8480
8844
|
newCommits: 0
|
|
8481
8845
|
};
|
|
8482
8846
|
}
|
|
8483
|
-
const remoteTip =
|
|
8847
|
+
const remoteTip = gitSafe2(`rev-parse origin/${baseBranch}`, cwd)?.trim();
|
|
8484
8848
|
if (!remoteTip || remoteTip === mergeBase) {
|
|
8485
8849
|
log.debug("Base branch has not advanced");
|
|
8486
8850
|
return {
|
|
@@ -8490,16 +8854,16 @@ function checkForConflicts(cwd, baseBranch) {
|
|
|
8490
8854
|
newCommits: 0
|
|
8491
8855
|
};
|
|
8492
8856
|
}
|
|
8493
|
-
const newCommitsOutput =
|
|
8857
|
+
const newCommitsOutput = gitSafe2(`rev-list --count ${mergeBase}..origin/${baseBranch}`, cwd)?.trim() ?? "0";
|
|
8494
8858
|
const newCommits = Number.parseInt(newCommitsOutput, 10);
|
|
8495
8859
|
log.verbose(`Base branch has ${newCommits} new commits`, {
|
|
8496
8860
|
baseBranch,
|
|
8497
8861
|
mergeBase: mergeBase.slice(0, 8),
|
|
8498
8862
|
remoteTip: remoteTip.slice(0, 8)
|
|
8499
8863
|
});
|
|
8500
|
-
const ourChanges =
|
|
8864
|
+
const ourChanges = gitSafe2(`diff --name-only ${mergeBase}..HEAD`, cwd)?.trim().split(`
|
|
8501
8865
|
`).filter(Boolean) ?? [];
|
|
8502
|
-
const theirChanges =
|
|
8866
|
+
const theirChanges = gitSafe2(`diff --name-only ${mergeBase}..origin/${baseBranch}`, cwd)?.trim().split(`
|
|
8503
8867
|
`).filter(Boolean) ?? [];
|
|
8504
8868
|
const overlapping = ourChanges.filter((f) => theirChanges.includes(f));
|
|
8505
8869
|
return {
|
|
@@ -8512,18 +8876,19 @@ function checkForConflicts(cwd, baseBranch) {
|
|
|
8512
8876
|
function attemptRebase(cwd, baseBranch) {
|
|
8513
8877
|
const log = getLogger();
|
|
8514
8878
|
try {
|
|
8515
|
-
|
|
8879
|
+
git3(`rebase origin/${baseBranch}`, cwd);
|
|
8516
8880
|
log.info(`Successfully rebased onto origin/${baseBranch}`);
|
|
8881
|
+
updateSubmodulesAfterRebase(cwd);
|
|
8517
8882
|
return { success: true };
|
|
8518
8883
|
} catch (_e) {
|
|
8519
8884
|
log.warn("Rebase failed, aborting");
|
|
8520
8885
|
const conflicts = [];
|
|
8521
8886
|
try {
|
|
8522
|
-
const status =
|
|
8887
|
+
const status = git3("diff --name-only --diff-filter=U", cwd);
|
|
8523
8888
|
conflicts.push(...status.trim().split(`
|
|
8524
8889
|
`).filter(Boolean));
|
|
8525
8890
|
} catch {}
|
|
8526
|
-
|
|
8891
|
+
gitSafe2("rebase --abort", cwd);
|
|
8527
8892
|
return { success: false, conflicts };
|
|
8528
8893
|
}
|
|
8529
8894
|
}
|
|
@@ -8565,23 +8930,24 @@ ${bold(yellow("⚠"))} Base branch has ${result.newCommits} new commit${result.n
|
|
|
8565
8930
|
var init_conflict = __esm(() => {
|
|
8566
8931
|
init_terminal();
|
|
8567
8932
|
init_logger();
|
|
8933
|
+
init_submodule();
|
|
8568
8934
|
});
|
|
8569
8935
|
|
|
8570
8936
|
// src/core/run-state.ts
|
|
8571
8937
|
import {
|
|
8572
|
-
existsSync as
|
|
8938
|
+
existsSync as existsSync18,
|
|
8573
8939
|
mkdirSync as mkdirSync11,
|
|
8574
8940
|
readFileSync as readFileSync12,
|
|
8575
8941
|
unlinkSync as unlinkSync4,
|
|
8576
8942
|
writeFileSync as writeFileSync8
|
|
8577
8943
|
} from "node:fs";
|
|
8578
|
-
import { dirname as dirname5, join as
|
|
8944
|
+
import { dirname as dirname5, join as join18 } from "node:path";
|
|
8579
8945
|
function getRunStatePath(projectRoot) {
|
|
8580
|
-
return
|
|
8946
|
+
return join18(projectRoot, ".locus", "run-state.json");
|
|
8581
8947
|
}
|
|
8582
8948
|
function loadRunState(projectRoot) {
|
|
8583
8949
|
const path = getRunStatePath(projectRoot);
|
|
8584
|
-
if (!
|
|
8950
|
+
if (!existsSync18(path))
|
|
8585
8951
|
return null;
|
|
8586
8952
|
try {
|
|
8587
8953
|
return JSON.parse(readFileSync12(path, "utf-8"));
|
|
@@ -8593,7 +8959,7 @@ function loadRunState(projectRoot) {
|
|
|
8593
8959
|
function saveRunState(projectRoot, state) {
|
|
8594
8960
|
const path = getRunStatePath(projectRoot);
|
|
8595
8961
|
const dir = dirname5(path);
|
|
8596
|
-
if (!
|
|
8962
|
+
if (!existsSync18(dir)) {
|
|
8597
8963
|
mkdirSync11(dir, { recursive: true });
|
|
8598
8964
|
}
|
|
8599
8965
|
writeFileSync8(path, `${JSON.stringify(state, null, 2)}
|
|
@@ -8601,7 +8967,7 @@ function saveRunState(projectRoot, state) {
|
|
|
8601
8967
|
}
|
|
8602
8968
|
function clearRunState(projectRoot) {
|
|
8603
8969
|
const path = getRunStatePath(projectRoot);
|
|
8604
|
-
if (
|
|
8970
|
+
if (existsSync18(path)) {
|
|
8605
8971
|
unlinkSync4(path);
|
|
8606
8972
|
}
|
|
8607
8973
|
}
|
|
@@ -8741,28 +9107,28 @@ var init_shutdown = __esm(() => {
|
|
|
8741
9107
|
});
|
|
8742
9108
|
|
|
8743
9109
|
// src/core/worktree.ts
|
|
8744
|
-
import { execSync as
|
|
8745
|
-
import { existsSync as
|
|
8746
|
-
import { join as
|
|
8747
|
-
function
|
|
8748
|
-
return
|
|
9110
|
+
import { execSync as execSync13 } from "node:child_process";
|
|
9111
|
+
import { existsSync as existsSync19, readdirSync as readdirSync6, realpathSync, statSync as statSync3 } from "node:fs";
|
|
9112
|
+
import { join as join19 } from "node:path";
|
|
9113
|
+
function git4(args, cwd) {
|
|
9114
|
+
return execSync13(`git ${args}`, {
|
|
8749
9115
|
cwd,
|
|
8750
9116
|
encoding: "utf-8",
|
|
8751
9117
|
stdio: ["pipe", "pipe", "pipe"]
|
|
8752
9118
|
});
|
|
8753
9119
|
}
|
|
8754
|
-
function
|
|
9120
|
+
function gitSafe3(args, cwd) {
|
|
8755
9121
|
try {
|
|
8756
|
-
return
|
|
9122
|
+
return git4(args, cwd);
|
|
8757
9123
|
} catch {
|
|
8758
9124
|
return null;
|
|
8759
9125
|
}
|
|
8760
9126
|
}
|
|
8761
9127
|
function getWorktreeDir(projectRoot) {
|
|
8762
|
-
return
|
|
9128
|
+
return join19(projectRoot, ".locus", "worktrees");
|
|
8763
9129
|
}
|
|
8764
9130
|
function getWorktreePath(projectRoot, issueNumber) {
|
|
8765
|
-
return
|
|
9131
|
+
return join19(getWorktreeDir(projectRoot), `issue-${issueNumber}`);
|
|
8766
9132
|
}
|
|
8767
9133
|
function generateBranchName(issueNumber) {
|
|
8768
9134
|
const randomSuffix = Math.random().toString(36).slice(2, 8);
|
|
@@ -8770,7 +9136,7 @@ function generateBranchName(issueNumber) {
|
|
|
8770
9136
|
}
|
|
8771
9137
|
function getWorktreeBranch(worktreePath) {
|
|
8772
9138
|
try {
|
|
8773
|
-
return
|
|
9139
|
+
return execSync13("git branch --show-current", {
|
|
8774
9140
|
cwd: worktreePath,
|
|
8775
9141
|
encoding: "utf-8",
|
|
8776
9142
|
stdio: ["pipe", "pipe", "pipe"]
|
|
@@ -8782,7 +9148,7 @@ function getWorktreeBranch(worktreePath) {
|
|
|
8782
9148
|
function createWorktree(projectRoot, issueNumber, baseBranch) {
|
|
8783
9149
|
const log = getLogger();
|
|
8784
9150
|
const worktreePath = getWorktreePath(projectRoot, issueNumber);
|
|
8785
|
-
if (
|
|
9151
|
+
if (existsSync19(worktreePath)) {
|
|
8786
9152
|
log.verbose(`Worktree already exists for issue #${issueNumber}`);
|
|
8787
9153
|
const existingBranch = getWorktreeBranch(worktreePath) ?? `locus/issue-${issueNumber}`;
|
|
8788
9154
|
return {
|
|
@@ -8793,7 +9159,8 @@ function createWorktree(projectRoot, issueNumber, baseBranch) {
|
|
|
8793
9159
|
};
|
|
8794
9160
|
}
|
|
8795
9161
|
const branch = generateBranchName(issueNumber);
|
|
8796
|
-
|
|
9162
|
+
git4(`worktree add ${JSON.stringify(worktreePath)} -b ${branch} ${baseBranch}`, projectRoot);
|
|
9163
|
+
initSubmodules(worktreePath);
|
|
8797
9164
|
log.info(`Created worktree for issue #${issueNumber}`, {
|
|
8798
9165
|
path: worktreePath,
|
|
8799
9166
|
branch,
|
|
@@ -8809,30 +9176,30 @@ function createWorktree(projectRoot, issueNumber, baseBranch) {
|
|
|
8809
9176
|
function removeWorktree(projectRoot, issueNumber) {
|
|
8810
9177
|
const log = getLogger();
|
|
8811
9178
|
const worktreePath = getWorktreePath(projectRoot, issueNumber);
|
|
8812
|
-
if (!
|
|
9179
|
+
if (!existsSync19(worktreePath)) {
|
|
8813
9180
|
log.verbose(`Worktree for issue #${issueNumber} does not exist`);
|
|
8814
9181
|
return;
|
|
8815
9182
|
}
|
|
8816
9183
|
const branch = getWorktreeBranch(worktreePath);
|
|
8817
9184
|
try {
|
|
8818
|
-
|
|
9185
|
+
git4(`worktree remove ${JSON.stringify(worktreePath)} --force`, projectRoot);
|
|
8819
9186
|
log.info(`Removed worktree for issue #${issueNumber}`);
|
|
8820
9187
|
} catch (e) {
|
|
8821
9188
|
log.warn(`Failed to remove worktree: ${e}`);
|
|
8822
|
-
|
|
9189
|
+
gitSafe3(`worktree remove ${JSON.stringify(worktreePath)} --force`, projectRoot);
|
|
8823
9190
|
}
|
|
8824
9191
|
if (branch) {
|
|
8825
|
-
|
|
9192
|
+
gitSafe3(`branch -D ${branch}`, projectRoot);
|
|
8826
9193
|
}
|
|
8827
9194
|
}
|
|
8828
9195
|
function listWorktrees(projectRoot) {
|
|
8829
9196
|
const log = getLogger();
|
|
8830
9197
|
const worktreeDir = getWorktreeDir(projectRoot);
|
|
8831
|
-
if (!
|
|
9198
|
+
if (!existsSync19(worktreeDir)) {
|
|
8832
9199
|
return [];
|
|
8833
9200
|
}
|
|
8834
9201
|
const entries = readdirSync6(worktreeDir).filter((entry) => entry.startsWith("issue-"));
|
|
8835
|
-
const gitWorktreeList =
|
|
9202
|
+
const gitWorktreeList = gitSafe3("worktree list --porcelain", projectRoot);
|
|
8836
9203
|
const activeWorktrees = new Set;
|
|
8837
9204
|
if (gitWorktreeList) {
|
|
8838
9205
|
for (const line of gitWorktreeList.split(`
|
|
@@ -8848,7 +9215,7 @@ function listWorktrees(projectRoot) {
|
|
|
8848
9215
|
if (!match)
|
|
8849
9216
|
continue;
|
|
8850
9217
|
const issueNumber = Number.parseInt(match[1], 10);
|
|
8851
|
-
const path =
|
|
9218
|
+
const path = join19(worktreeDir, entry);
|
|
8852
9219
|
const branch = getWorktreeBranch(path) ?? `locus/issue-${issueNumber}`;
|
|
8853
9220
|
let resolvedPath;
|
|
8854
9221
|
try {
|
|
@@ -8882,12 +9249,13 @@ function cleanupStaleWorktrees(projectRoot) {
|
|
|
8882
9249
|
}
|
|
8883
9250
|
}
|
|
8884
9251
|
if (cleaned > 0) {
|
|
8885
|
-
|
|
9252
|
+
gitSafe3("worktree prune", projectRoot);
|
|
8886
9253
|
}
|
|
8887
9254
|
return cleaned;
|
|
8888
9255
|
}
|
|
8889
9256
|
var init_worktree = __esm(() => {
|
|
8890
9257
|
init_logger();
|
|
9258
|
+
init_submodule();
|
|
8891
9259
|
});
|
|
8892
9260
|
|
|
8893
9261
|
// src/commands/run.ts
|
|
@@ -8895,7 +9263,7 @@ var exports_run = {};
|
|
|
8895
9263
|
__export(exports_run, {
|
|
8896
9264
|
runCommand: () => runCommand
|
|
8897
9265
|
});
|
|
8898
|
-
import { execSync as
|
|
9266
|
+
import { execSync as execSync14 } from "node:child_process";
|
|
8899
9267
|
function resolveExecutionContext(config, modelOverride) {
|
|
8900
9268
|
const model = modelOverride ?? config.ai.model;
|
|
8901
9269
|
const provider = inferProviderFromModel(model) ?? config.ai.provider;
|
|
@@ -9046,7 +9414,7 @@ ${yellow("⚠")} A sprint run is already in progress.
|
|
|
9046
9414
|
}
|
|
9047
9415
|
if (!flags.dryRun) {
|
|
9048
9416
|
try {
|
|
9049
|
-
|
|
9417
|
+
execSync14(`git checkout -B ${branchName}`, {
|
|
9050
9418
|
cwd: projectRoot,
|
|
9051
9419
|
encoding: "utf-8",
|
|
9052
9420
|
stdio: ["pipe", "pipe", "pipe"]
|
|
@@ -9096,7 +9464,7 @@ ${red("✗")} Auto-rebase failed. Resolve manually.
|
|
|
9096
9464
|
let sprintContext;
|
|
9097
9465
|
if (i > 0 && !flags.dryRun) {
|
|
9098
9466
|
try {
|
|
9099
|
-
sprintContext =
|
|
9467
|
+
sprintContext = execSync14(`git diff origin/${config.agent.baseBranch}..HEAD`, {
|
|
9100
9468
|
cwd: projectRoot,
|
|
9101
9469
|
encoding: "utf-8",
|
|
9102
9470
|
stdio: ["pipe", "pipe", "pipe"]
|
|
@@ -9161,7 +9529,7 @@ ${bold("Summary:")}
|
|
|
9161
9529
|
const prNumber = await createSprintPR(projectRoot, config, sprintName, branchName, completedTasks);
|
|
9162
9530
|
if (prNumber !== undefined) {
|
|
9163
9531
|
try {
|
|
9164
|
-
|
|
9532
|
+
execSync14(`git checkout ${config.agent.baseBranch}`, {
|
|
9165
9533
|
cwd: projectRoot,
|
|
9166
9534
|
encoding: "utf-8",
|
|
9167
9535
|
stdio: ["pipe", "pipe", "pipe"]
|
|
@@ -9176,6 +9544,7 @@ ${bold("Summary:")}
|
|
|
9176
9544
|
}
|
|
9177
9545
|
}
|
|
9178
9546
|
async function handleSingleIssue(projectRoot, config, issueNumber, flags, sandboxed) {
|
|
9547
|
+
const log = getLogger();
|
|
9179
9548
|
const execution = resolveExecutionContext(config, flags.model);
|
|
9180
9549
|
let isSprintIssue = false;
|
|
9181
9550
|
try {
|
|
@@ -9184,7 +9553,7 @@ async function handleSingleIssue(projectRoot, config, issueNumber, flags, sandbo
|
|
|
9184
9553
|
} catch {}
|
|
9185
9554
|
if (isSprintIssue) {
|
|
9186
9555
|
process.stderr.write(`
|
|
9187
|
-
${bold("Running sprint issue")} ${cyan(`#${issueNumber}`)} ${dim("(sequential
|
|
9556
|
+
${bold("Running sprint issue")} ${cyan(`#${issueNumber}`)} ${dim("(sequential)")}
|
|
9188
9557
|
|
|
9189
9558
|
`);
|
|
9190
9559
|
await executeIssue(projectRoot, {
|
|
@@ -9197,42 +9566,48 @@ ${bold("Running sprint issue")} ${cyan(`#${issueNumber}`)} ${dim("(sequential, n
|
|
|
9197
9566
|
});
|
|
9198
9567
|
return;
|
|
9199
9568
|
}
|
|
9569
|
+
const randomSuffix = Math.random().toString(36).slice(2, 8);
|
|
9570
|
+
const branchName = `locus/issue-${issueNumber}-${randomSuffix}`;
|
|
9200
9571
|
process.stderr.write(`
|
|
9201
|
-
${bold("Running issue")} ${cyan(`#${issueNumber}`)} ${dim(
|
|
9572
|
+
${bold("Running issue")} ${cyan(`#${issueNumber}`)} ${dim(`(branch: ${branchName})`)}
|
|
9202
9573
|
|
|
9203
9574
|
`);
|
|
9204
|
-
let worktreePath;
|
|
9205
9575
|
if (!flags.dryRun) {
|
|
9206
9576
|
try {
|
|
9207
|
-
|
|
9208
|
-
|
|
9209
|
-
|
|
9210
|
-
|
|
9211
|
-
|
|
9577
|
+
execSync14(`git checkout -B ${branchName} ${config.agent.baseBranch}`, {
|
|
9578
|
+
cwd: projectRoot,
|
|
9579
|
+
encoding: "utf-8",
|
|
9580
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
9581
|
+
});
|
|
9582
|
+
log.info(`Checked out branch ${branchName}`);
|
|
9212
9583
|
} catch (e) {
|
|
9213
|
-
process.stderr.write(`${yellow("⚠")} Could not create
|
|
9584
|
+
process.stderr.write(`${yellow("⚠")} Could not create branch: ${e}
|
|
9214
9585
|
`);
|
|
9215
|
-
process.stderr.write(` ${dim("
|
|
9586
|
+
process.stderr.write(` ${dim("Running on current branch instead.")}
|
|
9216
9587
|
|
|
9217
9588
|
`);
|
|
9218
9589
|
}
|
|
9219
9590
|
}
|
|
9220
9591
|
const result = await executeIssue(projectRoot, {
|
|
9221
9592
|
issueNumber,
|
|
9222
|
-
worktreePath,
|
|
9223
9593
|
provider: execution.provider,
|
|
9224
9594
|
model: execution.model,
|
|
9225
9595
|
dryRun: flags.dryRun,
|
|
9226
9596
|
sandboxed,
|
|
9227
9597
|
sandboxName: execution.sandboxName
|
|
9228
9598
|
});
|
|
9229
|
-
if (
|
|
9599
|
+
if (!flags.dryRun) {
|
|
9230
9600
|
if (result.success) {
|
|
9231
|
-
|
|
9232
|
-
|
|
9233
|
-
|
|
9601
|
+
try {
|
|
9602
|
+
execSync14(`git checkout ${config.agent.baseBranch}`, {
|
|
9603
|
+
cwd: projectRoot,
|
|
9604
|
+
encoding: "utf-8",
|
|
9605
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
9606
|
+
});
|
|
9607
|
+
log.info(`Checked out ${config.agent.baseBranch}`);
|
|
9608
|
+
} catch {}
|
|
9234
9609
|
} else {
|
|
9235
|
-
process.stderr.write(` ${yellow("⚠")}
|
|
9610
|
+
process.stderr.write(` ${yellow("⚠")} Branch ${dim(branchName)} preserved for debugging.
|
|
9236
9611
|
`);
|
|
9237
9612
|
}
|
|
9238
9613
|
}
|
|
@@ -9361,13 +9736,13 @@ ${bold("Resuming")} ${state.type} run ${dim(state.runId)}
|
|
|
9361
9736
|
`);
|
|
9362
9737
|
if (state.type === "sprint" && state.branch) {
|
|
9363
9738
|
try {
|
|
9364
|
-
const currentBranch =
|
|
9739
|
+
const currentBranch = execSync14("git rev-parse --abbrev-ref HEAD", {
|
|
9365
9740
|
cwd: projectRoot,
|
|
9366
9741
|
encoding: "utf-8",
|
|
9367
9742
|
stdio: ["pipe", "pipe", "pipe"]
|
|
9368
9743
|
}).trim();
|
|
9369
9744
|
if (currentBranch !== state.branch) {
|
|
9370
|
-
|
|
9745
|
+
execSync14(`git checkout ${state.branch}`, {
|
|
9371
9746
|
cwd: projectRoot,
|
|
9372
9747
|
encoding: "utf-8",
|
|
9373
9748
|
stdio: ["pipe", "pipe", "pipe"]
|
|
@@ -9434,7 +9809,7 @@ ${bold("Resume complete:")} ${green(`✓ ${finalStats.done}`)} ${finalStats.fail
|
|
|
9434
9809
|
const prNumber = await createSprintPR(projectRoot, config, state.sprint, state.branch, completedTasks);
|
|
9435
9810
|
if (prNumber !== undefined) {
|
|
9436
9811
|
try {
|
|
9437
|
-
|
|
9812
|
+
execSync14(`git checkout ${config.agent.baseBranch}`, {
|
|
9438
9813
|
cwd: projectRoot,
|
|
9439
9814
|
encoding: "utf-8",
|
|
9440
9815
|
stdio: ["pipe", "pipe", "pipe"]
|
|
@@ -9465,14 +9840,19 @@ function getOrder2(issue) {
|
|
|
9465
9840
|
}
|
|
9466
9841
|
function ensureTaskCommit(projectRoot, issueNumber, issueTitle) {
|
|
9467
9842
|
try {
|
|
9468
|
-
const
|
|
9843
|
+
const committedSubmodules = commitDirtySubmodules(projectRoot, issueNumber, issueTitle);
|
|
9844
|
+
if (committedSubmodules.length > 0) {
|
|
9845
|
+
process.stderr.write(` ${dim(`Committed submodule changes: ${committedSubmodules.join(", ")}`)}
|
|
9846
|
+
`);
|
|
9847
|
+
}
|
|
9848
|
+
const status = execSync14("git status --porcelain", {
|
|
9469
9849
|
cwd: projectRoot,
|
|
9470
9850
|
encoding: "utf-8",
|
|
9471
9851
|
stdio: ["pipe", "pipe", "pipe"]
|
|
9472
9852
|
}).trim();
|
|
9473
9853
|
if (!status)
|
|
9474
9854
|
return;
|
|
9475
|
-
|
|
9855
|
+
execSync14("git add -A", {
|
|
9476
9856
|
cwd: projectRoot,
|
|
9477
9857
|
encoding: "utf-8",
|
|
9478
9858
|
stdio: ["pipe", "pipe", "pipe"]
|
|
@@ -9480,7 +9860,7 @@ function ensureTaskCommit(projectRoot, issueNumber, issueTitle) {
|
|
|
9480
9860
|
const message = `chore: complete #${issueNumber} - ${issueTitle}
|
|
9481
9861
|
|
|
9482
9862
|
Co-Authored-By: LocusAgent <agent@locusai.team>`;
|
|
9483
|
-
|
|
9863
|
+
execSync14(`git commit -F -`, {
|
|
9484
9864
|
input: message,
|
|
9485
9865
|
cwd: projectRoot,
|
|
9486
9866
|
encoding: "utf-8",
|
|
@@ -9494,7 +9874,7 @@ async function createSprintPR(projectRoot, config, sprintName, branchName, tasks
|
|
|
9494
9874
|
if (!config.agent.autoPR)
|
|
9495
9875
|
return;
|
|
9496
9876
|
try {
|
|
9497
|
-
const diff =
|
|
9877
|
+
const diff = execSync14(`git diff origin/${config.agent.baseBranch}..HEAD --stat`, {
|
|
9498
9878
|
cwd: projectRoot,
|
|
9499
9879
|
encoding: "utf-8",
|
|
9500
9880
|
stdio: ["pipe", "pipe", "pipe"]
|
|
@@ -9504,16 +9884,24 @@ async function createSprintPR(projectRoot, config, sprintName, branchName, tasks
|
|
|
9504
9884
|
`);
|
|
9505
9885
|
return;
|
|
9506
9886
|
}
|
|
9507
|
-
|
|
9887
|
+
pushSubmoduleBranches(projectRoot);
|
|
9888
|
+
execSync14(`git push -u origin ${branchName}`, {
|
|
9508
9889
|
cwd: projectRoot,
|
|
9509
9890
|
encoding: "utf-8",
|
|
9510
9891
|
stdio: ["pipe", "pipe", "pipe"]
|
|
9511
9892
|
});
|
|
9512
9893
|
const taskLines = tasks.map((t) => `- Closes #${t.issue}${t.title ? `: ${t.title}` : ""}`).join(`
|
|
9513
9894
|
`);
|
|
9514
|
-
const
|
|
9895
|
+
const submoduleSummary = getSubmoduleChangeSummary(projectRoot, config.agent.baseBranch);
|
|
9896
|
+
let prBody = `## Sprint: ${sprintName}
|
|
9515
9897
|
|
|
9516
|
-
${taskLines}
|
|
9898
|
+
${taskLines}`;
|
|
9899
|
+
if (submoduleSummary) {
|
|
9900
|
+
prBody += `
|
|
9901
|
+
|
|
9902
|
+
${submoduleSummary}`;
|
|
9903
|
+
}
|
|
9904
|
+
prBody += `
|
|
9517
9905
|
|
|
9518
9906
|
---
|
|
9519
9907
|
|
|
@@ -9530,8 +9918,8 @@ ${taskLines}
|
|
|
9530
9918
|
}
|
|
9531
9919
|
}
|
|
9532
9920
|
var init_run = __esm(() => {
|
|
9533
|
-
init_ai_models();
|
|
9534
9921
|
init_agent();
|
|
9922
|
+
init_ai_models();
|
|
9535
9923
|
init_config();
|
|
9536
9924
|
init_conflict();
|
|
9537
9925
|
init_github();
|
|
@@ -9540,6 +9928,7 @@ var init_run = __esm(() => {
|
|
|
9540
9928
|
init_run_state();
|
|
9541
9929
|
init_sandbox();
|
|
9542
9930
|
init_shutdown();
|
|
9931
|
+
init_submodule();
|
|
9543
9932
|
init_worktree();
|
|
9544
9933
|
init_progress();
|
|
9545
9934
|
init_terminal();
|
|
@@ -9654,13 +10043,13 @@ __export(exports_plan, {
|
|
|
9654
10043
|
parsePlanArgs: () => parsePlanArgs
|
|
9655
10044
|
});
|
|
9656
10045
|
import {
|
|
9657
|
-
existsSync as
|
|
10046
|
+
existsSync as existsSync20,
|
|
9658
10047
|
mkdirSync as mkdirSync12,
|
|
9659
10048
|
readdirSync as readdirSync7,
|
|
9660
10049
|
readFileSync as readFileSync13,
|
|
9661
10050
|
writeFileSync as writeFileSync9
|
|
9662
10051
|
} from "node:fs";
|
|
9663
|
-
import { join as
|
|
10052
|
+
import { join as join20 } from "node:path";
|
|
9664
10053
|
function printHelp() {
|
|
9665
10054
|
process.stderr.write(`
|
|
9666
10055
|
${bold("locus plan")} — AI-powered sprint planning
|
|
@@ -9691,11 +10080,11 @@ function normalizeSprintName(name) {
|
|
|
9691
10080
|
return name.trim().toLowerCase();
|
|
9692
10081
|
}
|
|
9693
10082
|
function getPlansDir(projectRoot) {
|
|
9694
|
-
return
|
|
10083
|
+
return join20(projectRoot, ".locus", "plans");
|
|
9695
10084
|
}
|
|
9696
10085
|
function ensurePlansDir(projectRoot) {
|
|
9697
10086
|
const dir = getPlansDir(projectRoot);
|
|
9698
|
-
if (!
|
|
10087
|
+
if (!existsSync20(dir)) {
|
|
9699
10088
|
mkdirSync12(dir, { recursive: true });
|
|
9700
10089
|
}
|
|
9701
10090
|
return dir;
|
|
@@ -9705,14 +10094,14 @@ function generateId() {
|
|
|
9705
10094
|
}
|
|
9706
10095
|
function loadPlanFile(projectRoot, id) {
|
|
9707
10096
|
const dir = getPlansDir(projectRoot);
|
|
9708
|
-
if (!
|
|
10097
|
+
if (!existsSync20(dir))
|
|
9709
10098
|
return null;
|
|
9710
10099
|
const files = readdirSync7(dir).filter((f) => f.endsWith(".json"));
|
|
9711
10100
|
const match = files.find((f) => f.startsWith(id));
|
|
9712
10101
|
if (!match)
|
|
9713
10102
|
return null;
|
|
9714
10103
|
try {
|
|
9715
|
-
const content = readFileSync13(
|
|
10104
|
+
const content = readFileSync13(join20(dir, match), "utf-8");
|
|
9716
10105
|
return JSON.parse(content);
|
|
9717
10106
|
} catch {
|
|
9718
10107
|
return null;
|
|
@@ -9758,7 +10147,7 @@ async function planCommand(projectRoot, args, flags = {}) {
|
|
|
9758
10147
|
}
|
|
9759
10148
|
function handleListPlans(projectRoot) {
|
|
9760
10149
|
const dir = getPlansDir(projectRoot);
|
|
9761
|
-
if (!
|
|
10150
|
+
if (!existsSync20(dir)) {
|
|
9762
10151
|
process.stderr.write(`${dim("No saved plans yet.")}
|
|
9763
10152
|
`);
|
|
9764
10153
|
return;
|
|
@@ -9776,7 +10165,7 @@ ${bold("Saved Plans:")}
|
|
|
9776
10165
|
for (const file of files) {
|
|
9777
10166
|
const id = file.replace(".json", "");
|
|
9778
10167
|
try {
|
|
9779
|
-
const content = readFileSync13(
|
|
10168
|
+
const content = readFileSync13(join20(dir, file), "utf-8");
|
|
9780
10169
|
const plan = JSON.parse(content);
|
|
9781
10170
|
const date = plan.createdAt ? plan.createdAt.slice(0, 10) : "";
|
|
9782
10171
|
const issueCount = Array.isArray(plan.issues) ? plan.issues.length : 0;
|
|
@@ -9887,7 +10276,7 @@ ${bold("Approving plan:")}
|
|
|
9887
10276
|
async function handleAIPlan(projectRoot, config, directive, sprintName, flags) {
|
|
9888
10277
|
const id = generateId();
|
|
9889
10278
|
const plansDir = ensurePlansDir(projectRoot);
|
|
9890
|
-
const planPath =
|
|
10279
|
+
const planPath = join20(plansDir, `${id}.json`);
|
|
9891
10280
|
const planPathRelative = `.locus/plans/${id}.json`;
|
|
9892
10281
|
const displayDirective = directive;
|
|
9893
10282
|
process.stderr.write(`
|
|
@@ -9921,7 +10310,7 @@ ${red("✗")} Planning failed: ${aiResult.error}
|
|
|
9921
10310
|
`);
|
|
9922
10311
|
return;
|
|
9923
10312
|
}
|
|
9924
|
-
if (!
|
|
10313
|
+
if (!existsSync20(planPath)) {
|
|
9925
10314
|
process.stderr.write(`
|
|
9926
10315
|
${yellow("⚠")} Plan file was not created at ${bold(planPathRelative)}.
|
|
9927
10316
|
`);
|
|
@@ -10094,15 +10483,15 @@ ${directive}${sprintName ? `
|
|
|
10094
10483
|
|
|
10095
10484
|
**Sprint:** ${sprintName}` : ""}
|
|
10096
10485
|
</directive>`);
|
|
10097
|
-
const locusPath =
|
|
10098
|
-
if (
|
|
10486
|
+
const locusPath = join20(projectRoot, ".locus", "LOCUS.md");
|
|
10487
|
+
if (existsSync20(locusPath)) {
|
|
10099
10488
|
const content = readFileSync13(locusPath, "utf-8");
|
|
10100
10489
|
parts.push(`<project-context>
|
|
10101
10490
|
${content.slice(0, 3000)}
|
|
10102
10491
|
</project-context>`);
|
|
10103
10492
|
}
|
|
10104
|
-
const learningsPath =
|
|
10105
|
-
if (
|
|
10493
|
+
const learningsPath = join20(projectRoot, ".locus", "LEARNINGS.md");
|
|
10494
|
+
if (existsSync20(learningsPath)) {
|
|
10106
10495
|
const content = readFileSync13(learningsPath, "utf-8");
|
|
10107
10496
|
parts.push(`<past-learnings>
|
|
10108
10497
|
${content.slice(0, 2000)}
|
|
@@ -10273,8 +10662,8 @@ var init_plan = __esm(() => {
|
|
|
10273
10662
|
init_run_ai();
|
|
10274
10663
|
init_config();
|
|
10275
10664
|
init_github();
|
|
10276
|
-
init_terminal();
|
|
10277
10665
|
init_sandbox();
|
|
10666
|
+
init_terminal();
|
|
10278
10667
|
});
|
|
10279
10668
|
|
|
10280
10669
|
// src/commands/review.ts
|
|
@@ -10282,9 +10671,9 @@ var exports_review = {};
|
|
|
10282
10671
|
__export(exports_review, {
|
|
10283
10672
|
reviewCommand: () => reviewCommand
|
|
10284
10673
|
});
|
|
10285
|
-
import { execSync as
|
|
10286
|
-
import { existsSync as
|
|
10287
|
-
import { join as
|
|
10674
|
+
import { execSync as execSync15 } from "node:child_process";
|
|
10675
|
+
import { existsSync as existsSync21, readFileSync as readFileSync14 } from "node:fs";
|
|
10676
|
+
import { join as join21 } from "node:path";
|
|
10288
10677
|
function printHelp2() {
|
|
10289
10678
|
process.stderr.write(`
|
|
10290
10679
|
${bold("locus review")} — AI-powered code review
|
|
@@ -10360,7 +10749,7 @@ ${bold("Review complete:")} ${green(`✓ ${reviewed}`)}${failed > 0 ? ` ${red(`
|
|
|
10360
10749
|
async function reviewSinglePR(projectRoot, config, prNumber, focus, flags) {
|
|
10361
10750
|
let prInfo;
|
|
10362
10751
|
try {
|
|
10363
|
-
const result =
|
|
10752
|
+
const result = execSync15(`gh pr view ${prNumber} --json number,title,body,state,headRefName,baseRefName,labels,url,createdAt`, { cwd: projectRoot, encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
10364
10753
|
const raw = JSON.parse(result);
|
|
10365
10754
|
prInfo = {
|
|
10366
10755
|
number: raw.number,
|
|
@@ -10426,7 +10815,7 @@ ${output.slice(0, 60000)}
|
|
|
10426
10815
|
|
|
10427
10816
|
---
|
|
10428
10817
|
_Reviewed by Locus AI (${config.ai.provider}/${flags.model ?? config.ai.model})_`;
|
|
10429
|
-
|
|
10818
|
+
execSync15(`gh pr comment ${pr.number} --body ${JSON.stringify(reviewBody)}`, { cwd: projectRoot, encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
10430
10819
|
process.stderr.write(` ${green("✓")} Review posted ${dim(`(${timer.formatted()})`)}
|
|
10431
10820
|
`);
|
|
10432
10821
|
} catch (e) {
|
|
@@ -10444,8 +10833,8 @@ function buildReviewPrompt(projectRoot, config, pr, diff, focus) {
|
|
|
10444
10833
|
parts.push(`<role>
|
|
10445
10834
|
You are an expert code reviewer for the ${config.github.owner}/${config.github.repo} repository.
|
|
10446
10835
|
</role>`);
|
|
10447
|
-
const locusPath =
|
|
10448
|
-
if (
|
|
10836
|
+
const locusPath = join21(projectRoot, ".locus", "LOCUS.md");
|
|
10837
|
+
if (existsSync21(locusPath)) {
|
|
10449
10838
|
const content = readFileSync14(locusPath, "utf-8");
|
|
10450
10839
|
parts.push(`<project-context>
|
|
10451
10840
|
${content.slice(0, 2000)}
|
|
@@ -10506,7 +10895,7 @@ var exports_iterate = {};
|
|
|
10506
10895
|
__export(exports_iterate, {
|
|
10507
10896
|
iterateCommand: () => iterateCommand
|
|
10508
10897
|
});
|
|
10509
|
-
import { execSync as
|
|
10898
|
+
import { execSync as execSync16 } from "node:child_process";
|
|
10510
10899
|
function printHelp3() {
|
|
10511
10900
|
process.stderr.write(`
|
|
10512
10901
|
${bold("locus iterate")} — Re-execute tasks with PR feedback
|
|
@@ -10716,12 +11105,12 @@ ${bold("Summary:")} ${green(`✓ ${succeeded}`)}${failed > 0 ? ` ${red(`✗ ${fa
|
|
|
10716
11105
|
}
|
|
10717
11106
|
function findPRForIssue(projectRoot, issueNumber) {
|
|
10718
11107
|
try {
|
|
10719
|
-
const result =
|
|
11108
|
+
const result = execSync16(`gh pr list --search "Closes #${issueNumber}" --json number --state open`, { cwd: projectRoot, encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
10720
11109
|
const parsed = JSON.parse(result);
|
|
10721
11110
|
if (parsed.length > 0) {
|
|
10722
11111
|
return parsed[0].number;
|
|
10723
11112
|
}
|
|
10724
|
-
const branchResult =
|
|
11113
|
+
const branchResult = execSync16(`gh pr list --head "locus/issue-${issueNumber}" --json number --state open`, { cwd: projectRoot, encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
10725
11114
|
const branchParsed = JSON.parse(branchResult);
|
|
10726
11115
|
if (branchParsed.length > 0) {
|
|
10727
11116
|
return branchParsed[0].number;
|
|
@@ -10756,14 +11145,14 @@ __export(exports_discuss, {
|
|
|
10756
11145
|
discussCommand: () => discussCommand
|
|
10757
11146
|
});
|
|
10758
11147
|
import {
|
|
10759
|
-
existsSync as
|
|
11148
|
+
existsSync as existsSync22,
|
|
10760
11149
|
mkdirSync as mkdirSync13,
|
|
10761
11150
|
readdirSync as readdirSync8,
|
|
10762
11151
|
readFileSync as readFileSync15,
|
|
10763
11152
|
unlinkSync as unlinkSync5,
|
|
10764
11153
|
writeFileSync as writeFileSync10
|
|
10765
11154
|
} from "node:fs";
|
|
10766
|
-
import { join as
|
|
11155
|
+
import { join as join22 } from "node:path";
|
|
10767
11156
|
function printHelp4() {
|
|
10768
11157
|
process.stderr.write(`
|
|
10769
11158
|
${bold("locus discuss")} — AI-powered architectural discussions
|
|
@@ -10785,11 +11174,11 @@ ${bold("Examples:")}
|
|
|
10785
11174
|
`);
|
|
10786
11175
|
}
|
|
10787
11176
|
function getDiscussionsDir(projectRoot) {
|
|
10788
|
-
return
|
|
11177
|
+
return join22(projectRoot, ".locus", "discussions");
|
|
10789
11178
|
}
|
|
10790
11179
|
function ensureDiscussionsDir(projectRoot) {
|
|
10791
11180
|
const dir = getDiscussionsDir(projectRoot);
|
|
10792
|
-
if (!
|
|
11181
|
+
if (!existsSync22(dir)) {
|
|
10793
11182
|
mkdirSync13(dir, { recursive: true });
|
|
10794
11183
|
}
|
|
10795
11184
|
return dir;
|
|
@@ -10824,7 +11213,7 @@ async function discussCommand(projectRoot, args, flags = {}) {
|
|
|
10824
11213
|
}
|
|
10825
11214
|
function listDiscussions(projectRoot) {
|
|
10826
11215
|
const dir = getDiscussionsDir(projectRoot);
|
|
10827
|
-
if (!
|
|
11216
|
+
if (!existsSync22(dir)) {
|
|
10828
11217
|
process.stderr.write(`${dim("No discussions yet.")}
|
|
10829
11218
|
`);
|
|
10830
11219
|
return;
|
|
@@ -10841,7 +11230,7 @@ ${bold("Discussions:")}
|
|
|
10841
11230
|
`);
|
|
10842
11231
|
for (const file of files) {
|
|
10843
11232
|
const id = file.replace(".md", "");
|
|
10844
|
-
const content = readFileSync15(
|
|
11233
|
+
const content = readFileSync15(join22(dir, file), "utf-8");
|
|
10845
11234
|
const titleMatch = content.match(/^#\s+(.+)/m);
|
|
10846
11235
|
const title = titleMatch ? titleMatch[1] : id;
|
|
10847
11236
|
const dateMatch = content.match(/\*\*Date:\*\*\s*(.+)/);
|
|
@@ -10859,7 +11248,7 @@ function showDiscussion(projectRoot, id) {
|
|
|
10859
11248
|
return;
|
|
10860
11249
|
}
|
|
10861
11250
|
const dir = getDiscussionsDir(projectRoot);
|
|
10862
|
-
if (!
|
|
11251
|
+
if (!existsSync22(dir)) {
|
|
10863
11252
|
process.stderr.write(`${red("✗")} No discussions found.
|
|
10864
11253
|
`);
|
|
10865
11254
|
return;
|
|
@@ -10871,7 +11260,7 @@ function showDiscussion(projectRoot, id) {
|
|
|
10871
11260
|
`);
|
|
10872
11261
|
return;
|
|
10873
11262
|
}
|
|
10874
|
-
const content = readFileSync15(
|
|
11263
|
+
const content = readFileSync15(join22(dir, match), "utf-8");
|
|
10875
11264
|
process.stdout.write(`${content}
|
|
10876
11265
|
`);
|
|
10877
11266
|
}
|
|
@@ -10882,7 +11271,7 @@ function deleteDiscussion(projectRoot, id) {
|
|
|
10882
11271
|
return;
|
|
10883
11272
|
}
|
|
10884
11273
|
const dir = getDiscussionsDir(projectRoot);
|
|
10885
|
-
if (!
|
|
11274
|
+
if (!existsSync22(dir)) {
|
|
10886
11275
|
process.stderr.write(`${red("✗")} No discussions found.
|
|
10887
11276
|
`);
|
|
10888
11277
|
return;
|
|
@@ -10894,7 +11283,7 @@ function deleteDiscussion(projectRoot, id) {
|
|
|
10894
11283
|
`);
|
|
10895
11284
|
return;
|
|
10896
11285
|
}
|
|
10897
|
-
unlinkSync5(
|
|
11286
|
+
unlinkSync5(join22(dir, match));
|
|
10898
11287
|
process.stderr.write(`${green("✓")} Deleted discussion: ${match.replace(".md", "")}
|
|
10899
11288
|
`);
|
|
10900
11289
|
}
|
|
@@ -10907,7 +11296,7 @@ async function convertDiscussionToPlan(projectRoot, id) {
|
|
|
10907
11296
|
return;
|
|
10908
11297
|
}
|
|
10909
11298
|
const dir = getDiscussionsDir(projectRoot);
|
|
10910
|
-
if (!
|
|
11299
|
+
if (!existsSync22(dir)) {
|
|
10911
11300
|
process.stderr.write(`${red("✗")} No discussions found.
|
|
10912
11301
|
`);
|
|
10913
11302
|
return;
|
|
@@ -10919,7 +11308,7 @@ async function convertDiscussionToPlan(projectRoot, id) {
|
|
|
10919
11308
|
`);
|
|
10920
11309
|
return;
|
|
10921
11310
|
}
|
|
10922
|
-
const content = readFileSync15(
|
|
11311
|
+
const content = readFileSync15(join22(dir, match), "utf-8");
|
|
10923
11312
|
const titleMatch = content.match(/^#\s+(.+)/m);
|
|
10924
11313
|
const discussionTitle = titleMatch ? titleMatch[1].trim() : id;
|
|
10925
11314
|
await planCommand(projectRoot, [
|
|
@@ -11033,7 +11422,7 @@ ${turn.content}`;
|
|
|
11033
11422
|
...conversation.length > 1 ? [`---`, ``, `## Discussion Transcript`, ``, transcript, ``] : []
|
|
11034
11423
|
].join(`
|
|
11035
11424
|
`);
|
|
11036
|
-
writeFileSync10(
|
|
11425
|
+
writeFileSync10(join22(dir, `${id}.md`), markdown, "utf-8");
|
|
11037
11426
|
process.stderr.write(`
|
|
11038
11427
|
${green("✓")} Discussion saved: ${cyan(id)} ${dim(`(${timer.formatted()})`)}
|
|
11039
11428
|
`);
|
|
@@ -11048,15 +11437,15 @@ function buildDiscussionPrompt(projectRoot, config, topic, conversation, forceFi
|
|
|
11048
11437
|
parts.push(`<role>
|
|
11049
11438
|
You are a senior software architect and consultant for the ${config.github.owner}/${config.github.repo} project.
|
|
11050
11439
|
</role>`);
|
|
11051
|
-
const locusPath =
|
|
11052
|
-
if (
|
|
11440
|
+
const locusPath = join22(projectRoot, ".locus", "LOCUS.md");
|
|
11441
|
+
if (existsSync22(locusPath)) {
|
|
11053
11442
|
const content = readFileSync15(locusPath, "utf-8");
|
|
11054
11443
|
parts.push(`<project-context>
|
|
11055
11444
|
${content.slice(0, 3000)}
|
|
11056
11445
|
</project-context>`);
|
|
11057
11446
|
}
|
|
11058
|
-
const learningsPath =
|
|
11059
|
-
if (
|
|
11447
|
+
const learningsPath = join22(projectRoot, ".locus", "LEARNINGS.md");
|
|
11448
|
+
if (existsSync22(learningsPath)) {
|
|
11060
11449
|
const content = readFileSync15(learningsPath, "utf-8");
|
|
11061
11450
|
parts.push(`<past-learnings>
|
|
11062
11451
|
${content.slice(0, 2000)}
|
|
@@ -11128,8 +11517,8 @@ __export(exports_artifacts, {
|
|
|
11128
11517
|
formatDate: () => formatDate2,
|
|
11129
11518
|
artifactsCommand: () => artifactsCommand
|
|
11130
11519
|
});
|
|
11131
|
-
import { existsSync as
|
|
11132
|
-
import { join as
|
|
11520
|
+
import { existsSync as existsSync23, readdirSync as readdirSync9, readFileSync as readFileSync16, statSync as statSync4 } from "node:fs";
|
|
11521
|
+
import { join as join23 } from "node:path";
|
|
11133
11522
|
function printHelp5() {
|
|
11134
11523
|
process.stderr.write(`
|
|
11135
11524
|
${bold("locus artifacts")} — View and manage AI-generated artifacts
|
|
@@ -11149,14 +11538,14 @@ ${dim("Artifact names support partial matching.")}
|
|
|
11149
11538
|
`);
|
|
11150
11539
|
}
|
|
11151
11540
|
function getArtifactsDir(projectRoot) {
|
|
11152
|
-
return
|
|
11541
|
+
return join23(projectRoot, ".locus", "artifacts");
|
|
11153
11542
|
}
|
|
11154
11543
|
function listArtifacts(projectRoot) {
|
|
11155
11544
|
const dir = getArtifactsDir(projectRoot);
|
|
11156
|
-
if (!
|
|
11545
|
+
if (!existsSync23(dir))
|
|
11157
11546
|
return [];
|
|
11158
11547
|
return readdirSync9(dir).filter((f) => f.endsWith(".md")).map((fileName) => {
|
|
11159
|
-
const filePath =
|
|
11548
|
+
const filePath = join23(dir, fileName);
|
|
11160
11549
|
const stat = statSync4(filePath);
|
|
11161
11550
|
return {
|
|
11162
11551
|
name: fileName.replace(/\.md$/, ""),
|
|
@@ -11169,8 +11558,8 @@ function listArtifacts(projectRoot) {
|
|
|
11169
11558
|
function readArtifact(projectRoot, name) {
|
|
11170
11559
|
const dir = getArtifactsDir(projectRoot);
|
|
11171
11560
|
const fileName = name.endsWith(".md") ? name : `${name}.md`;
|
|
11172
|
-
const filePath =
|
|
11173
|
-
if (!
|
|
11561
|
+
const filePath = join23(dir, fileName);
|
|
11562
|
+
if (!existsSync23(filePath))
|
|
11174
11563
|
return null;
|
|
11175
11564
|
const stat = statSync4(filePath);
|
|
11176
11565
|
return {
|
|
@@ -11340,10 +11729,10 @@ __export(exports_sandbox2, {
|
|
|
11340
11729
|
parseSandboxInstallArgs: () => parseSandboxInstallArgs,
|
|
11341
11730
|
parseSandboxExecArgs: () => parseSandboxExecArgs
|
|
11342
11731
|
});
|
|
11343
|
-
import { execSync as
|
|
11732
|
+
import { execSync as execSync17, spawn as spawn6 } from "node:child_process";
|
|
11344
11733
|
import { createHash } from "node:crypto";
|
|
11345
|
-
import { existsSync as
|
|
11346
|
-
import { basename as basename4, join as
|
|
11734
|
+
import { existsSync as existsSync24, readFileSync as readFileSync17 } from "node:fs";
|
|
11735
|
+
import { basename as basename4, join as join24 } from "node:path";
|
|
11347
11736
|
function printSandboxHelp() {
|
|
11348
11737
|
process.stderr.write(`
|
|
11349
11738
|
${bold("locus sandbox")} — Manage Docker sandbox lifecycle
|
|
@@ -11519,7 +11908,7 @@ function handleRemove(projectRoot) {
|
|
|
11519
11908
|
process.stderr.write(`Removing sandbox ${bold(sandboxName)}...
|
|
11520
11909
|
`);
|
|
11521
11910
|
try {
|
|
11522
|
-
|
|
11911
|
+
execSync17(`docker sandbox rm ${sandboxName}`, {
|
|
11523
11912
|
encoding: "utf-8",
|
|
11524
11913
|
stdio: ["pipe", "pipe", "pipe"],
|
|
11525
11914
|
timeout: 15000
|
|
@@ -11793,7 +12182,7 @@ async function handleLogs(projectRoot, args) {
|
|
|
11793
12182
|
}
|
|
11794
12183
|
function detectPackageManager(projectRoot) {
|
|
11795
12184
|
try {
|
|
11796
|
-
const raw = readFileSync17(
|
|
12185
|
+
const raw = readFileSync17(join24(projectRoot, "package.json"), "utf-8");
|
|
11797
12186
|
const pkgJson = JSON.parse(raw);
|
|
11798
12187
|
if (typeof pkgJson.packageManager === "string") {
|
|
11799
12188
|
const name = pkgJson.packageManager.split("@")[0];
|
|
@@ -11802,13 +12191,13 @@ function detectPackageManager(projectRoot) {
|
|
|
11802
12191
|
}
|
|
11803
12192
|
}
|
|
11804
12193
|
} catch {}
|
|
11805
|
-
if (
|
|
12194
|
+
if (existsSync24(join24(projectRoot, "bun.lock")) || existsSync24(join24(projectRoot, "bun.lockb"))) {
|
|
11806
12195
|
return "bun";
|
|
11807
12196
|
}
|
|
11808
|
-
if (
|
|
12197
|
+
if (existsSync24(join24(projectRoot, "yarn.lock"))) {
|
|
11809
12198
|
return "yarn";
|
|
11810
12199
|
}
|
|
11811
|
-
if (
|
|
12200
|
+
if (existsSync24(join24(projectRoot, "pnpm-lock.yaml"))) {
|
|
11812
12201
|
return "pnpm";
|
|
11813
12202
|
}
|
|
11814
12203
|
return "npm";
|
|
@@ -11826,31 +12215,39 @@ function getInstallCommand(pm) {
|
|
|
11826
12215
|
}
|
|
11827
12216
|
}
|
|
11828
12217
|
async function runSandboxSetup(sandboxName, projectRoot) {
|
|
11829
|
-
const
|
|
11830
|
-
|
|
11831
|
-
|
|
11832
|
-
|
|
11833
|
-
|
|
11834
|
-
|
|
12218
|
+
const ecosystem = detectProjectEcosystem(projectRoot);
|
|
12219
|
+
const isJS = isJavaScriptEcosystem(ecosystem);
|
|
12220
|
+
if (isJS) {
|
|
12221
|
+
const pm = detectPackageManager(projectRoot);
|
|
12222
|
+
if (pm !== "npm") {
|
|
12223
|
+
await ensurePackageManagerInSandbox(sandboxName, pm);
|
|
12224
|
+
}
|
|
12225
|
+
const installCmd = getInstallCommand(pm);
|
|
12226
|
+
process.stderr.write(`
|
|
11835
12227
|
Installing dependencies (${bold(installCmd.join(" "))}) in sandbox ${dim(sandboxName)}...
|
|
11836
12228
|
`);
|
|
11837
|
-
|
|
11838
|
-
|
|
11839
|
-
|
|
11840
|
-
|
|
11841
|
-
|
|
11842
|
-
|
|
11843
|
-
|
|
11844
|
-
|
|
11845
|
-
|
|
11846
|
-
|
|
12229
|
+
const installOk = await runInteractiveCommand("docker", [
|
|
12230
|
+
"sandbox",
|
|
12231
|
+
"exec",
|
|
12232
|
+
"-w",
|
|
12233
|
+
projectRoot,
|
|
12234
|
+
sandboxName,
|
|
12235
|
+
...installCmd
|
|
12236
|
+
]);
|
|
12237
|
+
if (!installOk) {
|
|
12238
|
+
process.stderr.write(`${red("✗")} Dependency install failed in sandbox ${dim(sandboxName)}.
|
|
11847
12239
|
`);
|
|
11848
|
-
|
|
11849
|
-
|
|
11850
|
-
|
|
12240
|
+
return false;
|
|
12241
|
+
}
|
|
12242
|
+
process.stderr.write(`${green("✓")} Dependencies installed in sandbox ${dim(sandboxName)}.
|
|
12243
|
+
`);
|
|
12244
|
+
} else {
|
|
12245
|
+
process.stderr.write(`
|
|
12246
|
+
${dim(`Detected ${ecosystem} project — skipping JS package install.`)}
|
|
11851
12247
|
`);
|
|
11852
|
-
|
|
11853
|
-
|
|
12248
|
+
}
|
|
12249
|
+
const setupScript = join24(projectRoot, ".locus", "sandbox-setup.sh");
|
|
12250
|
+
if (existsSync24(setupScript)) {
|
|
11854
12251
|
process.stderr.write(`Running ${bold(".locus/sandbox-setup.sh")} in sandbox ${dim(sandboxName)}...
|
|
11855
12252
|
`);
|
|
11856
12253
|
const hookOk = await runInteractiveCommand("docker", [
|
|
@@ -11866,6 +12263,11 @@ Installing dependencies (${bold(installCmd.join(" "))}) in sandbox ${dim(sandbox
|
|
|
11866
12263
|
process.stderr.write(`${yellow("⚠")} Setup hook failed in sandbox ${dim(sandboxName)}.
|
|
11867
12264
|
`);
|
|
11868
12265
|
}
|
|
12266
|
+
} else if (!isJS) {
|
|
12267
|
+
process.stderr.write(`${yellow("⚠")} No ${bold(".locus/sandbox-setup.sh")} found. Create one to install ${ecosystem} toolchain in the sandbox.
|
|
12268
|
+
`);
|
|
12269
|
+
process.stderr.write(` Re-run ${cyan("locus init")} to auto-generate a template, or create it manually.
|
|
12270
|
+
`);
|
|
11869
12271
|
}
|
|
11870
12272
|
return true;
|
|
11871
12273
|
}
|
|
@@ -11933,7 +12335,7 @@ function runInteractiveCommand(command, args) {
|
|
|
11933
12335
|
}
|
|
11934
12336
|
async function createProviderSandbox(provider, sandboxName, projectRoot) {
|
|
11935
12337
|
try {
|
|
11936
|
-
|
|
12338
|
+
execSync17(`docker sandbox create --name ${sandboxName} claude ${projectRoot}`, {
|
|
11937
12339
|
stdio: ["pipe", "pipe", "pipe"],
|
|
11938
12340
|
timeout: 120000
|
|
11939
12341
|
});
|
|
@@ -11949,7 +12351,7 @@ async function createProviderSandbox(provider, sandboxName, projectRoot) {
|
|
|
11949
12351
|
}
|
|
11950
12352
|
async function ensurePackageManagerInSandbox(sandboxName, pm) {
|
|
11951
12353
|
try {
|
|
11952
|
-
|
|
12354
|
+
execSync17(`docker sandbox exec ${sandboxName} which ${pm}`, {
|
|
11953
12355
|
stdio: ["pipe", "pipe", "pipe"],
|
|
11954
12356
|
timeout: 5000
|
|
11955
12357
|
});
|
|
@@ -11958,7 +12360,7 @@ async function ensurePackageManagerInSandbox(sandboxName, pm) {
|
|
|
11958
12360
|
process.stderr.write(`Installing ${bold(pm)} in sandbox...
|
|
11959
12361
|
`);
|
|
11960
12362
|
try {
|
|
11961
|
-
|
|
12363
|
+
execSync17(`docker sandbox exec ${sandboxName} npm install -g ${npmPkg}`, {
|
|
11962
12364
|
stdio: "inherit",
|
|
11963
12365
|
timeout: 120000
|
|
11964
12366
|
});
|
|
@@ -11970,7 +12372,7 @@ async function ensurePackageManagerInSandbox(sandboxName, pm) {
|
|
|
11970
12372
|
}
|
|
11971
12373
|
async function ensureCodexInSandbox(sandboxName) {
|
|
11972
12374
|
try {
|
|
11973
|
-
|
|
12375
|
+
execSync17(`docker sandbox exec ${sandboxName} which codex`, {
|
|
11974
12376
|
stdio: ["pipe", "pipe", "pipe"],
|
|
11975
12377
|
timeout: 5000
|
|
11976
12378
|
});
|
|
@@ -11978,7 +12380,7 @@ async function ensureCodexInSandbox(sandboxName) {
|
|
|
11978
12380
|
process.stderr.write(`Installing codex in sandbox...
|
|
11979
12381
|
`);
|
|
11980
12382
|
try {
|
|
11981
|
-
|
|
12383
|
+
execSync17(`docker sandbox exec ${sandboxName} npm install -g @openai/codex`, { stdio: "inherit", timeout: 120000 });
|
|
11982
12384
|
} catch {
|
|
11983
12385
|
process.stderr.write(`${red("✗")} Failed to install codex in sandbox.
|
|
11984
12386
|
`);
|
|
@@ -11987,7 +12389,7 @@ async function ensureCodexInSandbox(sandboxName) {
|
|
|
11987
12389
|
}
|
|
11988
12390
|
function isSandboxAlive(name) {
|
|
11989
12391
|
try {
|
|
11990
|
-
const output =
|
|
12392
|
+
const output = execSync17("docker sandbox ls", {
|
|
11991
12393
|
encoding: "utf-8",
|
|
11992
12394
|
stdio: ["pipe", "pipe", "pipe"],
|
|
11993
12395
|
timeout: 5000
|
|
@@ -12000,6 +12402,7 @@ function isSandboxAlive(name) {
|
|
|
12000
12402
|
var PROVIDERS;
|
|
12001
12403
|
var init_sandbox2 = __esm(() => {
|
|
12002
12404
|
init_config();
|
|
12405
|
+
init_ecosystem();
|
|
12003
12406
|
init_sandbox();
|
|
12004
12407
|
init_sandbox_ignore();
|
|
12005
12408
|
init_terminal();
|
|
@@ -12012,13 +12415,13 @@ init_context();
|
|
|
12012
12415
|
init_logger();
|
|
12013
12416
|
init_rate_limiter();
|
|
12014
12417
|
init_terminal();
|
|
12015
|
-
import { existsSync as
|
|
12016
|
-
import { join as
|
|
12418
|
+
import { existsSync as existsSync25, readFileSync as readFileSync18 } from "node:fs";
|
|
12419
|
+
import { join as join25 } from "node:path";
|
|
12017
12420
|
import { fileURLToPath } from "node:url";
|
|
12018
12421
|
function getCliVersion() {
|
|
12019
12422
|
const fallbackVersion = "0.0.0";
|
|
12020
|
-
const packageJsonPath =
|
|
12021
|
-
if (!
|
|
12423
|
+
const packageJsonPath = join25(fileURLToPath(new URL(".", import.meta.url)), "..", "package.json");
|
|
12424
|
+
if (!existsSync25(packageJsonPath)) {
|
|
12022
12425
|
return fallbackVersion;
|
|
12023
12426
|
}
|
|
12024
12427
|
try {
|
|
@@ -12283,7 +12686,7 @@ async function main() {
|
|
|
12283
12686
|
try {
|
|
12284
12687
|
const root = getGitRoot(cwd);
|
|
12285
12688
|
if (isInitialized(root)) {
|
|
12286
|
-
logDir =
|
|
12689
|
+
logDir = join25(root, ".locus", "logs");
|
|
12287
12690
|
getRateLimiter(root);
|
|
12288
12691
|
}
|
|
12289
12692
|
} catch {}
|