@amaster.ai/employee-runtime-connector 0.1.1-beta.91 → 0.1.1-beta.93
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/amaster-runtime-daemon.mjs +257 -210
- package/dist/amaster-runtime.mjs +1 -1
- package/package.json +1 -1
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
// src/amaster-runtime-daemon.mjs
|
|
5
5
|
import { createHash as createHash14 } from "node:crypto";
|
|
6
6
|
import { createRequire } from "node:module";
|
|
7
|
-
import { chmodSync as chmodSync7, copyFileSync as copyFileSync2, existsSync as
|
|
7
|
+
import { chmodSync as chmodSync7, copyFileSync as copyFileSync2, existsSync as existsSync14, lstatSync as lstatSync7, mkdirSync as mkdirSync9, mkdtempSync as mkdtempSync2, readFileSync as readFileSync13, readdirSync as readdirSync10, realpathSync as realpathSync5, renameSync as renameSync8, rmSync as rmSync8, statSync as statSync9, symlinkSync as symlinkSync2, unlinkSync as unlinkSync3, writeFileSync as writeFileSync10 } from "node:fs";
|
|
8
8
|
import { arch as arch3, homedir as homedir3, hostname as hostname2, platform as platform3, tmpdir } from "node:os";
|
|
9
|
-
import { basename as basename6, delimiter as delimiter3, dirname as dirname10, extname as extname3, isAbsolute as
|
|
9
|
+
import { basename as basename6, delimiter as delimiter3, dirname as dirname10, extname as extname3, isAbsolute as isAbsolute8, join as join15, relative as relative7, resolve as resolve11 } from "node:path";
|
|
10
10
|
import { spawn, spawnSync as spawnSync5 } from "node:child_process";
|
|
11
11
|
|
|
12
12
|
// src/amaster-runtime-daemon/common.mjs
|
|
@@ -432,10 +432,10 @@ function preparePiExecutorAccess(input) {
|
|
|
432
432
|
|
|
433
433
|
// src/amaster-runtime-daemon/codex-managed-mcp-profile.mjs
|
|
434
434
|
import { createHash } from "node:crypto";
|
|
435
|
-
import { chmodSync as chmodSync2, existsSync, lstatSync as lstatSync2, mkdirSync, readFileSync, realpathSync, readdirSync as readdirSync2, rmSync, statSync, writeFileSync } from "node:fs";
|
|
435
|
+
import { chmodSync as chmodSync2, existsSync as existsSync2, lstatSync as lstatSync2, mkdirSync, readFileSync, realpathSync, readdirSync as readdirSync2, rmSync, statSync, writeFileSync } from "node:fs";
|
|
436
436
|
import { arch, platform } from "node:os";
|
|
437
|
-
import { basename, dirname, isAbsolute, join as join2, relative, resolve as resolve2 } from "node:path";
|
|
438
|
-
import { spawnSync } from "node:child_process";
|
|
437
|
+
import { basename, dirname, isAbsolute as isAbsolute2, join as join2, relative, resolve as resolve2 } from "node:path";
|
|
438
|
+
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
439
439
|
|
|
440
440
|
// ../../node_modules/.pnpm/smol-toml@1.7.0/node_modules/smol-toml/dist/date.js
|
|
441
441
|
var DATE_TIME_RE = /^(\d{4}-\d{2}-\d{2})?[T ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|[-+]\d{2}:\d{2})?$/i;
|
|
@@ -1258,6 +1258,109 @@ function stringify(obj, { maxDepth = 1e3, numbersAsFloat = false } = {}) {
|
|
|
1258
1258
|
return str;
|
|
1259
1259
|
}
|
|
1260
1260
|
|
|
1261
|
+
// src/amaster-runtime-daemon/executor-discovery.mjs
|
|
1262
|
+
import { spawnSync } from "node:child_process";
|
|
1263
|
+
import { existsSync } from "node:fs";
|
|
1264
|
+
import { delimiter, isAbsolute } from "node:path";
|
|
1265
|
+
var KNOWN_EXECUTORS = [
|
|
1266
|
+
["codex", "codex"],
|
|
1267
|
+
["claude", "claude"],
|
|
1268
|
+
["cursor", "cursor"],
|
|
1269
|
+
["opencode", "opencode"],
|
|
1270
|
+
["hermes", "hermes"],
|
|
1271
|
+
["pi", "pi"],
|
|
1272
|
+
["openclaw", "openclaw"]
|
|
1273
|
+
];
|
|
1274
|
+
function executorDiscoveryEnv(env = process.env) {
|
|
1275
|
+
const extraPaths = splitList(env.AMASTER_EXECUTOR_PATHS);
|
|
1276
|
+
if (extraPaths.length === 0) return env;
|
|
1277
|
+
return {
|
|
1278
|
+
...env,
|
|
1279
|
+
PATH: [...extraPaths, env.PATH ?? ""].filter(Boolean).join(delimiter)
|
|
1280
|
+
};
|
|
1281
|
+
}
|
|
1282
|
+
function commandExists(command, env = process.env) {
|
|
1283
|
+
if (process.platform === "win32") {
|
|
1284
|
+
return Boolean(resolveExecutorCommand(command, env));
|
|
1285
|
+
}
|
|
1286
|
+
const commandEnv = executorDiscoveryEnv(env);
|
|
1287
|
+
const result3 = spawnSync("sh", ["-lc", `command -v ${quoteShell(command)} >/dev/null 2>&1`], {
|
|
1288
|
+
env: commandEnv,
|
|
1289
|
+
stdio: "ignore"
|
|
1290
|
+
});
|
|
1291
|
+
return result3.status === 0;
|
|
1292
|
+
}
|
|
1293
|
+
function commandVersion(command, env = process.env) {
|
|
1294
|
+
const commandEnv = executorDiscoveryEnv(env);
|
|
1295
|
+
const executable = resolveExecutorCommand(command, env);
|
|
1296
|
+
if (!executable) return void 0;
|
|
1297
|
+
const result3 = spawnSync(executable, ["--version"], {
|
|
1298
|
+
env: commandEnv,
|
|
1299
|
+
encoding: "utf8",
|
|
1300
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
1301
|
+
timeout: 3e3,
|
|
1302
|
+
...isWindowsCommandShim(executable) ? { shell: true } : {}
|
|
1303
|
+
});
|
|
1304
|
+
if (result3.status !== 0) return void 0;
|
|
1305
|
+
return result3.stdout.trim().split(/\r?\n/)[0]?.slice(0, 120) || void 0;
|
|
1306
|
+
}
|
|
1307
|
+
function resolveExecutorCommand(command, env = process.env) {
|
|
1308
|
+
const normalized = String(command ?? "").trim();
|
|
1309
|
+
if (!normalized) return null;
|
|
1310
|
+
if (process.platform !== "win32") return normalized;
|
|
1311
|
+
if (isAbsolute(normalized) || normalized.includes("/") || normalized.includes("\\")) {
|
|
1312
|
+
if (existsSync(normalized)) return normalized;
|
|
1313
|
+
for (const suffix of [".cmd", ".bat", ".exe"]) {
|
|
1314
|
+
const candidate = `${normalized}${suffix}`;
|
|
1315
|
+
if (existsSync(candidate)) return candidate;
|
|
1316
|
+
}
|
|
1317
|
+
return null;
|
|
1318
|
+
}
|
|
1319
|
+
const commandEnv = executorDiscoveryEnv(env);
|
|
1320
|
+
const result3 = spawnSync("where.exe", [normalized], {
|
|
1321
|
+
env: commandEnv,
|
|
1322
|
+
encoding: "utf8",
|
|
1323
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
1324
|
+
});
|
|
1325
|
+
if (result3.status !== 0) return null;
|
|
1326
|
+
const candidates = String(result3.stdout ?? "").split(/\r?\n/).map((value) => value.trim()).filter(Boolean);
|
|
1327
|
+
return candidates.find((candidate) => /\.(?:cmd|bat|exe)$/i.test(candidate)) ?? candidates[0] ?? null;
|
|
1328
|
+
}
|
|
1329
|
+
function isWindowsCommandShim(command) {
|
|
1330
|
+
return process.platform === "win32" && /\.(?:cmd|bat)$/i.test(String(command ?? ""));
|
|
1331
|
+
}
|
|
1332
|
+
function discoverExecutors(options = {}) {
|
|
1333
|
+
const knownExecutors = options.knownExecutors ?? KNOWN_EXECUTORS;
|
|
1334
|
+
const env = options.env ?? process.env;
|
|
1335
|
+
return knownExecutors.filter(([, command]) => commandExists(command, env)).map(([kind, command]) => {
|
|
1336
|
+
const version = commandVersion(command, env);
|
|
1337
|
+
return {
|
|
1338
|
+
kind,
|
|
1339
|
+
command,
|
|
1340
|
+
...version ? { version } : {}
|
|
1341
|
+
};
|
|
1342
|
+
});
|
|
1343
|
+
}
|
|
1344
|
+
function parseExecutors(value, options = {}) {
|
|
1345
|
+
const configured = splitList(value);
|
|
1346
|
+
if (configured.length === 0) {
|
|
1347
|
+
const discovered = discoverExecutors(options);
|
|
1348
|
+
return discovered.length > 0 ? discovered : [{ kind: "custom", command: "replace-with-executor-command" }];
|
|
1349
|
+
}
|
|
1350
|
+
return configured.map((entry) => {
|
|
1351
|
+
const [kind, command, ...versionParts] = entry.split(":");
|
|
1352
|
+
if (!kind?.trim() || !command?.trim()) {
|
|
1353
|
+
throw new Error(`Invalid AMASTER_EXECUTORS entry: ${entry}`);
|
|
1354
|
+
}
|
|
1355
|
+
const version = versionParts.join(":").trim();
|
|
1356
|
+
return {
|
|
1357
|
+
kind: kind.trim(),
|
|
1358
|
+
command: command.trim(),
|
|
1359
|
+
...version ? { version } : {}
|
|
1360
|
+
};
|
|
1361
|
+
});
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1261
1364
|
// src/amaster-runtime-daemon/codex-managed-mcp-profile.mjs
|
|
1262
1365
|
var SUPPORTED_SCHEMA_VERSION = "amaster.governed-mcp.v1";
|
|
1263
1366
|
var SUPPORTED_SERVER_NAME = "amaster";
|
|
@@ -1327,7 +1430,7 @@ function tomlString(value) {
|
|
|
1327
1430
|
}
|
|
1328
1431
|
function within(candidate, root) {
|
|
1329
1432
|
const rel = relative(root, candidate);
|
|
1330
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
1433
|
+
return rel === "" || !rel.startsWith("..") && !isAbsolute2(rel);
|
|
1331
1434
|
}
|
|
1332
1435
|
function writePrivateFile(filePath, contents) {
|
|
1333
1436
|
writeFileSync(filePath, contents, { mode: 384, flag: "wx" });
|
|
@@ -1340,7 +1443,7 @@ function makePrivateDir(dirPath) {
|
|
|
1340
1443
|
chmodSync2(dirPath, 448);
|
|
1341
1444
|
}
|
|
1342
1445
|
function findSessionRollout(sessionsRoot, sessionId) {
|
|
1343
|
-
if (!
|
|
1446
|
+
if (!existsSync2(sessionsRoot)) return null;
|
|
1344
1447
|
const matches = [];
|
|
1345
1448
|
const pending = [sessionsRoot];
|
|
1346
1449
|
while (pending.length > 0) {
|
|
@@ -1379,7 +1482,7 @@ function restoreManagedCodexSessionRollout(input, codexHome, runDir, executorHom
|
|
|
1379
1482
|
const executorRelativePath = relative(runDir, executorHome);
|
|
1380
1483
|
const cacheRoot = join2(sourceRunDirs[0], executorRelativePath, "session-rollout");
|
|
1381
1484
|
const markerPath = join2(cacheRoot, SESSION_ROLLOUT_MARKER);
|
|
1382
|
-
if (!
|
|
1485
|
+
if (!existsSync2(markerPath) || lstatSync2(markerPath).isSymbolicLink() || !lstatSync2(markerPath).isFile()) {
|
|
1383
1486
|
throw new Error("codex_managed_mcp_session_rollout_missing: source rollout marker is unavailable");
|
|
1384
1487
|
}
|
|
1385
1488
|
const marker = JSON.parse(readFileSync(markerPath, "utf8"));
|
|
@@ -1413,7 +1516,7 @@ function collectAuthSecretStrings(value, output = []) {
|
|
|
1413
1516
|
}
|
|
1414
1517
|
function sharedCodexModelRoute(sourceHome) {
|
|
1415
1518
|
const configPath = join2(sourceHome, "config.toml");
|
|
1416
|
-
if (!
|
|
1519
|
+
if (!existsSync2(configPath)) return { root: [], table: [], mode: "default", protectedValues: [] };
|
|
1417
1520
|
if (!statSync(configPath).isFile()) throw new Error("codex_managed_mcp_source_config_invalid: config.toml is not a file");
|
|
1418
1521
|
let config;
|
|
1419
1522
|
try {
|
|
@@ -1495,12 +1598,14 @@ function parseCodexVersion(stdout) {
|
|
|
1495
1598
|
return tuple.join(".");
|
|
1496
1599
|
}
|
|
1497
1600
|
function runAttestation(executorCommand, env, cwd, gatewayUrl, expectedHeaders) {
|
|
1498
|
-
const
|
|
1601
|
+
const resolvedExecutorCommand = resolveExecutorCommand(executorCommand, env) ?? executorCommand;
|
|
1602
|
+
const shellOptions = isWindowsCommandShim(resolvedExecutorCommand) ? { shell: true } : {};
|
|
1603
|
+
const versionResult = spawnSync2(resolvedExecutorCommand, ["--version"], { cwd, env, encoding: "utf8", timeout: 1e4, maxBuffer: 1024 * 1024, ...shellOptions });
|
|
1499
1604
|
if (versionResult.error || versionResult.status !== 0) {
|
|
1500
1605
|
throw new Error(`codex_managed_mcp_attestation_failed: --version exit=${versionResult.status ?? "spawn_error"}`);
|
|
1501
1606
|
}
|
|
1502
1607
|
const executorVersion = parseCodexVersion(versionResult.stdout);
|
|
1503
|
-
const listResult =
|
|
1608
|
+
const listResult = spawnSync2(resolvedExecutorCommand, ["mcp", "list", "--json"], { cwd, env, encoding: "utf8", timeout: 1e4, maxBuffer: 1024 * 1024, ...shellOptions });
|
|
1504
1609
|
if (listResult.error || listResult.status !== 0) {
|
|
1505
1610
|
throw new Error(`codex_managed_mcp_attestation_failed: mcp list exit=${listResult.status ?? "spawn_error"}`);
|
|
1506
1611
|
}
|
|
@@ -1632,7 +1737,7 @@ function assertNoProjectAmasterOverride(cwd, runDir) {
|
|
|
1632
1737
|
if (!within(cursor, boundary)) throw new Error("codex_managed_mcp_owner_mismatch: cwd is outside the managed run");
|
|
1633
1738
|
while (within(cursor, boundary)) {
|
|
1634
1739
|
const configPath = join2(cursor, ".codex", "config.toml");
|
|
1635
|
-
if (
|
|
1740
|
+
if (existsSync2(configPath)) {
|
|
1636
1741
|
const source = readFileSync(configPath, "utf8");
|
|
1637
1742
|
const sameName = /mcp_servers\s*(?:\.\s*(?:["']amaster["']|amaster)|=\s*\{[\s\S]*?(?:["']amaster["']|amaster)\s*=)/m.test(source);
|
|
1638
1743
|
if (sameName) throw new Error(`codex_managed_mcp_project_override_blocked: ${configPath}`);
|
|
@@ -1651,7 +1756,7 @@ function seedCodexAuth(input, codexHome) {
|
|
|
1651
1756
|
}
|
|
1652
1757
|
const sourceHome = typeof input.baseEnv?.CODEX_HOME === "string" && input.baseEnv.CODEX_HOME.trim() ? resolve2(input.baseEnv.CODEX_HOME) : join2(typeof input.baseEnv?.HOME === "string" && input.baseEnv.HOME.trim() ? resolve2(input.baseEnv.HOME) : dirname(resolve2(input.executorHome)), ".codex");
|
|
1653
1758
|
const source = join2(sourceHome, "auth.json");
|
|
1654
|
-
if (!
|
|
1759
|
+
if (!existsSync2(source) || !statSync(source).isFile()) throw new Error("codex_managed_mcp_auth_missing: isolated Codex run has no usable auth source");
|
|
1655
1760
|
const sourceContents = readFileSync(source);
|
|
1656
1761
|
let parsedAuth;
|
|
1657
1762
|
try {
|
|
@@ -1694,7 +1799,7 @@ function prepareManagedCodexMcpProfile(input) {
|
|
|
1694
1799
|
if (!within(executorHome, join2(runDir, "executors"))) throw new Error("codex_managed_mcp_owner_mismatch: executorHome is outside the managed run");
|
|
1695
1800
|
assertNoProjectAmasterOverride(nonEmpty(input.cwd, "cwd"), runDir);
|
|
1696
1801
|
const profileRoot = join2(executorHome, "managed-mcp");
|
|
1697
|
-
if (
|
|
1802
|
+
if (existsSync2(profileRoot)) throw new Error(`codex_managed_mcp_profile_exists: ${profileRoot}`);
|
|
1698
1803
|
const home = join2(profileRoot, "home");
|
|
1699
1804
|
const codexHome = join2(profileRoot, "codex-home");
|
|
1700
1805
|
const tmp = join2(profileRoot, "tmp");
|
|
@@ -1788,11 +1893,11 @@ function preserveManagedCodexSessionRollout(profile, input) {
|
|
|
1788
1893
|
const sessionsRoot = join2(resolve2(nonEmpty(profile?.env?.CODEX_HOME, "profile.env.CODEX_HOME")), "sessions");
|
|
1789
1894
|
const sourceRollout = findSessionRollout(sessionsRoot, sessionId);
|
|
1790
1895
|
const rolloutRelativePath = relative(sessionsRoot, sourceRollout);
|
|
1791
|
-
if (!rolloutRelativePath || rolloutRelativePath.startsWith("..") ||
|
|
1896
|
+
if (!rolloutRelativePath || rolloutRelativePath.startsWith("..") || isAbsolute2(rolloutRelativePath)) {
|
|
1792
1897
|
throw new Error("codex_managed_mcp_session_rollout_unsafe: rollout escaped the managed Codex home");
|
|
1793
1898
|
}
|
|
1794
1899
|
const cacheRoot = join2(dirname(resolve2(profile.profileRoot)), "session-rollout");
|
|
1795
|
-
if (
|
|
1900
|
+
if (existsSync2(cacheRoot)) rmSync(cacheRoot, { recursive: true, force: false });
|
|
1796
1901
|
makePrivateDir(cacheRoot);
|
|
1797
1902
|
const targetRollout = join2(cacheRoot, rolloutRelativePath);
|
|
1798
1903
|
makePrivateDir(dirname(targetRollout));
|
|
@@ -1817,13 +1922,13 @@ function cleanupRestoredManagedCodexSessionRollout(profile) {
|
|
|
1817
1922
|
const restored = profile?.restoredNativeSession;
|
|
1818
1923
|
if (!restored?.cacheRoot) return { status: "not_restored" };
|
|
1819
1924
|
const cacheRoot = resolve2(restored.cacheRoot);
|
|
1820
|
-
if (!
|
|
1925
|
+
if (!existsSync2(cacheRoot)) return { status: "already_removed" };
|
|
1821
1926
|
const cacheStat = lstatSync2(cacheRoot);
|
|
1822
1927
|
if (!cacheStat.isDirectory() || cacheStat.isSymbolicLink()) {
|
|
1823
1928
|
throw new Error("codex_managed_mcp_session_rollout_cleanup_unsafe: cache root is not a private directory");
|
|
1824
1929
|
}
|
|
1825
1930
|
const markerPath = join2(cacheRoot, SESSION_ROLLOUT_MARKER);
|
|
1826
|
-
if (!
|
|
1931
|
+
if (!existsSync2(markerPath) || lstatSync2(markerPath).isSymbolicLink() || !lstatSync2(markerPath).isFile()) {
|
|
1827
1932
|
throw new Error("codex_managed_mcp_session_rollout_cleanup_unsafe: ownership marker is unavailable");
|
|
1828
1933
|
}
|
|
1829
1934
|
const marker = JSON.parse(readFileSync(markerPath, "utf8"));
|
|
@@ -1831,18 +1936,18 @@ function cleanupRestoredManagedCodexSessionRollout(profile) {
|
|
|
1831
1936
|
throw new Error("codex_managed_mcp_session_rollout_cleanup_unsafe: ownership marker does not match restored authority");
|
|
1832
1937
|
}
|
|
1833
1938
|
rmSync(cacheRoot, { recursive: true, force: false });
|
|
1834
|
-
if (
|
|
1939
|
+
if (existsSync2(cacheRoot)) throw new Error("codex_managed_mcp_session_rollout_cleanup_failed: cache root still exists");
|
|
1835
1940
|
return { status: "removed" };
|
|
1836
1941
|
}
|
|
1837
1942
|
function cleanupManagedCodexMcpProfile(profile, owner) {
|
|
1838
1943
|
const profileRoot = resolve2(nonEmpty(profile?.profileRoot, "profileRoot"));
|
|
1839
|
-
if (!
|
|
1944
|
+
if (!existsSync2(profileRoot)) return { status: "already_removed", profileRoot };
|
|
1840
1945
|
const rootStat = lstatSync2(profileRoot);
|
|
1841
1946
|
if (!rootStat.isDirectory() || rootStat.isSymbolicLink()) {
|
|
1842
1947
|
throw new Error("codex_managed_mcp_cleanup_owner_mismatch: profile root is not an owned directory");
|
|
1843
1948
|
}
|
|
1844
1949
|
const markerPath = join2(profileRoot, PROFILE_MARKER);
|
|
1845
|
-
const markerStat =
|
|
1950
|
+
const markerStat = existsSync2(markerPath) ? lstatSync2(markerPath) : null;
|
|
1846
1951
|
if (!markerStat?.isFile() || markerStat.isSymbolicLink()) {
|
|
1847
1952
|
throw new Error("codex_managed_mcp_cleanup_owner_mismatch: ownership marker is missing or unsafe");
|
|
1848
1953
|
}
|
|
@@ -1856,12 +1961,12 @@ function cleanupManagedCodexMcpProfile(profile, owner) {
|
|
|
1856
1961
|
throw new Error("codex_managed_mcp_cleanup_owner_mismatch: ownership marker does not match command/run");
|
|
1857
1962
|
}
|
|
1858
1963
|
rmSync(profileRoot, { recursive: true, force: false });
|
|
1859
|
-
if (
|
|
1964
|
+
if (existsSync2(profileRoot)) throw new Error("codex_managed_mcp_cleanup_failed: profile root still exists");
|
|
1860
1965
|
return { status: "removed", profileRoot };
|
|
1861
1966
|
}
|
|
1862
1967
|
function reconcileManagedCodexMcpProfiles(rootPath, options = {}) {
|
|
1863
1968
|
const root = resolve2(rootPath);
|
|
1864
|
-
if (!
|
|
1969
|
+
if (!existsSync2(root)) return { scanned: 0, removed: 0, removedProfiles: 0, removedRollouts: 0, failed: 0, failures: [] };
|
|
1865
1970
|
const canonicalRoot = realpathSync(root);
|
|
1866
1971
|
const profileMarkers = [];
|
|
1867
1972
|
const rolloutMarkers = [];
|
|
@@ -1887,7 +1992,7 @@ function reconcileManagedCodexMcpProfiles(rootPath, options = {}) {
|
|
|
1887
1992
|
try {
|
|
1888
1993
|
const marker = JSON.parse(readFileSync(markerPath, "utf8"));
|
|
1889
1994
|
const markerProfileRoot = typeof marker?.profileRoot === "string" ? resolve2(marker.profileRoot) : null;
|
|
1890
|
-
if (!markerProfileRoot || !
|
|
1995
|
+
if (!markerProfileRoot || !existsSync2(markerProfileRoot) || !within(realpathSync(profileRoot), canonicalRoot) || realpathSync(markerProfileRoot) !== realpathSync(profileRoot)) {
|
|
1891
1996
|
throw new Error("ownership marker root mismatch");
|
|
1892
1997
|
}
|
|
1893
1998
|
if (protectedCommandIds.has(marker?.commandId)) {
|
|
@@ -1909,14 +2014,14 @@ function reconcileManagedCodexMcpProfiles(rootPath, options = {}) {
|
|
|
1909
2014
|
const cacheStat = lstatSync2(cacheRoot);
|
|
1910
2015
|
const marker = JSON.parse(readFileSync(markerPath, "utf8"));
|
|
1911
2016
|
const markerCacheRoot = typeof marker?.cacheRoot === "string" ? resolve2(marker.cacheRoot) : null;
|
|
1912
|
-
if (!within(realpathSync(cacheRoot), canonicalRoot) || basename(cacheRoot) !== "session-rollout" || markerStat.isSymbolicLink() || !markerStat.isFile() || cacheStat.isSymbolicLink() || !cacheStat.isDirectory() || marker?.version !== 1 || typeof marker?.companyId !== "string" || typeof marker?.agentId !== "string" || typeof marker?.sourceRunId !== "string" || typeof marker?.sourceCommandId !== "string" || typeof marker?.sessionId !== "string" || markerCacheRoot != null && (!
|
|
2017
|
+
if (!within(realpathSync(cacheRoot), canonicalRoot) || basename(cacheRoot) !== "session-rollout" || markerStat.isSymbolicLink() || !markerStat.isFile() || cacheStat.isSymbolicLink() || !cacheStat.isDirectory() || marker?.version !== 1 || typeof marker?.companyId !== "string" || typeof marker?.agentId !== "string" || typeof marker?.sourceRunId !== "string" || typeof marker?.sourceCommandId !== "string" || typeof marker?.sessionId !== "string" || markerCacheRoot != null && (!existsSync2(markerCacheRoot) || realpathSync(markerCacheRoot) !== realpathSync(cacheRoot))) {
|
|
1913
2018
|
throw new Error("session rollout ownership marker mismatch");
|
|
1914
2019
|
}
|
|
1915
2020
|
const preservedAtMs = typeof marker.preservedAt === "string" ? Date.parse(marker.preservedAt) : Number.NaN;
|
|
1916
2021
|
const markerAgeMs = nowMs - (Number.isFinite(preservedAtMs) ? preservedAtMs : markerStat.mtimeMs);
|
|
1917
2022
|
if (markerAgeMs < rolloutTtlMs) continue;
|
|
1918
2023
|
rmSync(cacheRoot, { recursive: true, force: false });
|
|
1919
|
-
if (
|
|
2024
|
+
if (existsSync2(cacheRoot)) throw new Error("session rollout cache still exists");
|
|
1920
2025
|
removedRollouts += 1;
|
|
1921
2026
|
} catch (error) {
|
|
1922
2027
|
failures.push({ profileRoot: cacheRoot, error: error instanceof Error ? error.message : String(error) });
|
|
@@ -1939,7 +2044,7 @@ import {
|
|
|
1939
2044
|
chmodSync as chmodSync4,
|
|
1940
2045
|
chownSync as chownSync2,
|
|
1941
2046
|
copyFileSync,
|
|
1942
|
-
existsSync as
|
|
2047
|
+
existsSync as existsSync4,
|
|
1943
2048
|
lstatSync as lstatSync3,
|
|
1944
2049
|
mkdirSync as mkdirSync3,
|
|
1945
2050
|
readFileSync as readFileSync4,
|
|
@@ -1953,11 +2058,11 @@ import {
|
|
|
1953
2058
|
writeFileSync as writeFileSync4
|
|
1954
2059
|
} from "node:fs";
|
|
1955
2060
|
import { arch as arch2, platform as platform2 } from "node:os";
|
|
1956
|
-
import { basename as basename2, delimiter, dirname as dirname4, isAbsolute as
|
|
1957
|
-
import { spawnSync as
|
|
2061
|
+
import { basename as basename2, delimiter as delimiter2, dirname as dirname4, isAbsolute as isAbsolute3, join as join5, relative as relative2, resolve as resolve3, sep as sep2 } from "node:path";
|
|
2062
|
+
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
1958
2063
|
|
|
1959
2064
|
// src/amaster-runtime-daemon/pi-provider-config.mjs
|
|
1960
|
-
import { existsSync as
|
|
2065
|
+
import { existsSync as existsSync3, mkdirSync as mkdirSync2, readFileSync as readFileSync2, renameSync, writeFileSync as writeFileSync2 } from "node:fs";
|
|
1961
2066
|
import { dirname as dirname2, join as join3 } from "node:path";
|
|
1962
2067
|
var AMASTER_API_KEY_ENV_REFERENCE = "${AMASTER_API_KEY}";
|
|
1963
2068
|
var AMASTER_BILLING_TURN_HEADER_ENV_REFERENCE = "${AMASTER_BILLING_TURN_ID}";
|
|
@@ -2073,7 +2178,7 @@ function syncAmasterProviderSettings(agentDir, executorEnv) {
|
|
|
2073
2178
|
const apiKey = readString(executorEnv.AMASTER_API_KEY);
|
|
2074
2179
|
if (!apiKey) return false;
|
|
2075
2180
|
const settingsPath = join3(agentDir, "settings.json");
|
|
2076
|
-
if (!
|
|
2181
|
+
if (!existsSync3(settingsPath)) return false;
|
|
2077
2182
|
const settings = readJsonFile(settingsPath);
|
|
2078
2183
|
const baseUrl = readString(executorEnv.AMASTER_PROVIDER_BASE_URL);
|
|
2079
2184
|
const imageGenBaseUrl = imageGenBaseUrlFromProviderBaseUrl(baseUrl);
|
|
@@ -3225,7 +3330,7 @@ function applyManagedPiRunExitClosureArgs(args, profile) {
|
|
|
3225
3330
|
return closureArgs;
|
|
3226
3331
|
}
|
|
3227
3332
|
function createManagedPiMcpProfileApi(options = {}) {
|
|
3228
|
-
const spawnSyncImpl = typeof options.spawnSync === "function" ? options.spawnSync :
|
|
3333
|
+
const spawnSyncImpl = typeof options.spawnSync === "function" ? options.spawnSync : spawnSync3;
|
|
3229
3334
|
const chownSyncImpl = typeof options.chownSync === "function" ? options.chownSync : chownSync2;
|
|
3230
3335
|
const ownershipStatSyncImpl = typeof options.ownershipStatSync === "function" ? options.ownershipStatSync : statSync2;
|
|
3231
3336
|
const nowImpl = typeof options.now === "function" ? options.now : Date.now;
|
|
@@ -3389,7 +3494,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
3389
3494
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
3390
3495
|
}
|
|
3391
3496
|
function readJsonObjectFile(filePath) {
|
|
3392
|
-
if (!
|
|
3497
|
+
if (!existsSync4(filePath)) return {};
|
|
3393
3498
|
try {
|
|
3394
3499
|
const value = JSON.parse(readFileSync4(filePath, "utf8"));
|
|
3395
3500
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
@@ -3406,7 +3511,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
3406
3511
|
}
|
|
3407
3512
|
function within2(candidate, root) {
|
|
3408
3513
|
const rel = relative2(root, candidate);
|
|
3409
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
3514
|
+
return rel === "" || !rel.startsWith("..") && !isAbsolute3(rel);
|
|
3410
3515
|
}
|
|
3411
3516
|
function writePrivateFile2(filePath, contents) {
|
|
3412
3517
|
writeFileSync4(filePath, contents, { mode: 384, flag: "wx" });
|
|
@@ -3415,7 +3520,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
3415
3520
|
if (mode !== 384) throw new Error(`pi_managed_mcp_permissions_failed: ${filePath} mode=${mode.toString(8)}`);
|
|
3416
3521
|
}
|
|
3417
3522
|
function copyPrivateFile(source, target) {
|
|
3418
|
-
if (!
|
|
3523
|
+
if (!existsSync4(source)) return false;
|
|
3419
3524
|
const sourceStat = lstatSync3(source);
|
|
3420
3525
|
if (!sourceStat.isFile() || sourceStat.isSymbolicLink()) {
|
|
3421
3526
|
throw new Error(`pi_managed_mcp_source_config_unsafe: ${source}`);
|
|
@@ -3425,7 +3530,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
3425
3530
|
return true;
|
|
3426
3531
|
}
|
|
3427
3532
|
function findPiSessionRollout(sessionsRoot, sessionId) {
|
|
3428
|
-
if (!
|
|
3533
|
+
if (!existsSync4(sessionsRoot)) return null;
|
|
3429
3534
|
const matches = [];
|
|
3430
3535
|
const pending = [sessionsRoot];
|
|
3431
3536
|
while (pending.length > 0) {
|
|
@@ -3463,7 +3568,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
3463
3568
|
}
|
|
3464
3569
|
const cacheRoot = join5(sourceRunDirs[0], relative2(runDir, executorHome), "session-rollout");
|
|
3465
3570
|
const markerPath = join5(cacheRoot, SESSION_ROLLOUT_MARKER2);
|
|
3466
|
-
if (!
|
|
3571
|
+
if (!existsSync4(markerPath) || lstatSync3(markerPath).isSymbolicLink() || !lstatSync3(markerPath).isFile()) {
|
|
3467
3572
|
throw new Error("pi_managed_mcp_session_rollout_missing: source rollout marker is unavailable");
|
|
3468
3573
|
}
|
|
3469
3574
|
const marker = JSON.parse(readFileSync4(markerPath, "utf8"));
|
|
@@ -3589,7 +3694,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
3589
3694
|
for (let depth = 0; depth < 4; depth += 1) {
|
|
3590
3695
|
const packagePath = join5(cursor, "package.json");
|
|
3591
3696
|
const loaderPath = join5(cursor, "dist", "core", "extensions", "loader.js");
|
|
3592
|
-
if (
|
|
3697
|
+
if (existsSync4(packagePath) && existsSync4(loaderPath)) {
|
|
3593
3698
|
const packageJson = JSON.parse(readFileSync4(packagePath, "utf8"));
|
|
3594
3699
|
return sha2563(stablePiJson({
|
|
3595
3700
|
name: packageJson.name,
|
|
@@ -3636,7 +3741,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
3636
3741
|
const sourceCachePath = join5(entryPath, "jiti");
|
|
3637
3742
|
const runCachePath = join5(tmpPath, "jiti");
|
|
3638
3743
|
let status = "miss";
|
|
3639
|
-
if (
|
|
3744
|
+
if (existsSync4(entryPath)) {
|
|
3640
3745
|
try {
|
|
3641
3746
|
const entryStat = lstatSync3(entryPath);
|
|
3642
3747
|
const markerStat = lstatSync3(markerPath);
|
|
@@ -3658,12 +3763,12 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
3658
3763
|
}
|
|
3659
3764
|
function publishEffectiveToolsBootstrapCache(cache) {
|
|
3660
3765
|
if (cache.status === "hit") return "hit";
|
|
3661
|
-
if (!
|
|
3766
|
+
if (!existsSync4(cache.runCachePath)) return `${cache.status}_unavailable`;
|
|
3662
3767
|
const runCacheStat = lstatSync3(cache.runCachePath);
|
|
3663
3768
|
if (!runCacheStat.isDirectory() || runCacheStat.isSymbolicLink()) {
|
|
3664
3769
|
throw new Error("pi_managed_mcp_bootstrap_cache_unsafe: run cache");
|
|
3665
3770
|
}
|
|
3666
|
-
if (
|
|
3771
|
+
if (existsSync4(cache.entryPath)) return "hit_raced";
|
|
3667
3772
|
const stagingPath = `${cache.entryPath}.tmp-${process.pid}-${currentTimeMs()}`;
|
|
3668
3773
|
try {
|
|
3669
3774
|
mkdirSync3(stagingPath, { mode: 448 });
|
|
@@ -3682,16 +3787,16 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
3682
3787
|
if (error?.code !== "EEXIST" && error?.code !== "ENOTEMPTY") throw error;
|
|
3683
3788
|
}
|
|
3684
3789
|
} finally {
|
|
3685
|
-
if (
|
|
3790
|
+
if (existsSync4(stagingPath)) {
|
|
3686
3791
|
makeTrustedTreeWritable(stagingPath);
|
|
3687
3792
|
rmSync3(stagingPath, { recursive: true, force: true });
|
|
3688
3793
|
}
|
|
3689
3794
|
}
|
|
3690
|
-
return
|
|
3795
|
+
return existsSync4(cache.entryPath) ? `${cache.status}_published` : `${cache.status}_unavailable`;
|
|
3691
3796
|
}
|
|
3692
3797
|
function writeEffectiveToolsProbePhase(phasePath, phase, attempt) {
|
|
3693
3798
|
let history = [];
|
|
3694
|
-
if (
|
|
3799
|
+
if (existsSync4(phasePath)) {
|
|
3695
3800
|
try {
|
|
3696
3801
|
const parsed = JSON.parse(readFileSync4(phasePath, "utf8"));
|
|
3697
3802
|
history = Array.isArray(parsed.history) ? parsed.history.slice(0, 16) : [];
|
|
@@ -3703,7 +3808,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
3703
3808
|
history.push({ phase, attempt, atMs });
|
|
3704
3809
|
const contents = `${JSON.stringify({ phase, attempt, atMs, history })}
|
|
3705
3810
|
`;
|
|
3706
|
-
if (
|
|
3811
|
+
if (existsSync4(phasePath)) {
|
|
3707
3812
|
const phaseStat = lstatSync3(phasePath);
|
|
3708
3813
|
if (!phaseStat.isFile() || phaseStat.isSymbolicLink()) {
|
|
3709
3814
|
throw new Error("pi_managed_mcp_probe_phase_unsafe");
|
|
@@ -3803,7 +3908,17 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
3803
3908
|
return { setHash, tools: normalized.sort((left, right) => left.name.localeCompare(right.name)), kind: catalogKind };
|
|
3804
3909
|
}
|
|
3805
3910
|
function resolvePiExecutablePath(executorCommand, env) {
|
|
3806
|
-
if (
|
|
3911
|
+
if (platform2() === "win32") {
|
|
3912
|
+
const resolved = resolveExecutorCommand(executorCommand, env);
|
|
3913
|
+
if (!resolved) throw new Error("pi_managed_mcp_attestation_failed: --version error=ENOENT");
|
|
3914
|
+
try {
|
|
3915
|
+
return realpathSync2(resolved);
|
|
3916
|
+
} catch (error) {
|
|
3917
|
+
const errorCode = typeof error?.code === "string" ? error.code : "UNKNOWN";
|
|
3918
|
+
throw new Error(`pi_managed_mcp_attestation_failed: --version error=${errorCode}`);
|
|
3919
|
+
}
|
|
3920
|
+
}
|
|
3921
|
+
if (isAbsolute3(executorCommand) || executorCommand.includes("/") || executorCommand.includes("\\")) {
|
|
3807
3922
|
try {
|
|
3808
3923
|
return realpathSync2(executorCommand);
|
|
3809
3924
|
} catch (error) {
|
|
@@ -3811,7 +3926,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
3811
3926
|
throw new Error(`pi_managed_mcp_attestation_failed: --version error=${errorCode}`);
|
|
3812
3927
|
}
|
|
3813
3928
|
}
|
|
3814
|
-
const pathEntries = String(env?.PATH ?? "").split(
|
|
3929
|
+
const pathEntries = String(env?.PATH ?? "").split(delimiter2).filter(Boolean);
|
|
3815
3930
|
for (const entry of pathEntries) {
|
|
3816
3931
|
try {
|
|
3817
3932
|
const candidate = realpathSync2(join5(entry, executorCommand));
|
|
@@ -3965,7 +4080,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
3965
4080
|
if (sourceAcquisition?.profile?.transport?.browserMode === "existing") {
|
|
3966
4081
|
const userDataDir = sourceAcquisition.userDataDir;
|
|
3967
4082
|
const leaseId = sourceAcquisition.profile?.access?.browserLeaseId;
|
|
3968
|
-
if (!
|
|
4083
|
+
if (!isAbsolute3(userDataDir ?? "") || typeof leaseId !== "string" || !leaseId) {
|
|
3969
4084
|
throw new Error("source_acquisition_browser_profile_invalid");
|
|
3970
4085
|
}
|
|
3971
4086
|
return {
|
|
@@ -3976,7 +4091,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
3976
4091
|
}
|
|
3977
4092
|
if (sourceAcquisition?.profile?.transport?.browserMode !== "isolated") return env;
|
|
3978
4093
|
const executable = typeof baseEnv?.AMASTER_BROWSER_EXECUTABLE_PATH === "string" ? baseEnv.AMASTER_BROWSER_EXECUTABLE_PATH.trim() : "";
|
|
3979
|
-
if (!executable || !
|
|
4094
|
+
if (!executable || !isAbsolute3(executable)) {
|
|
3980
4095
|
throw new Error("source_acquisition_browser_executable_unavailable");
|
|
3981
4096
|
}
|
|
3982
4097
|
let stat;
|
|
@@ -3994,7 +4109,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
3994
4109
|
};
|
|
3995
4110
|
}
|
|
3996
4111
|
function projectMcpConfigHasContent(filePath) {
|
|
3997
|
-
if (!
|
|
4112
|
+
if (!existsSync4(filePath)) return false;
|
|
3998
4113
|
let parsed;
|
|
3999
4114
|
try {
|
|
4000
4115
|
parsed = JSON.parse(readFileSync4(filePath, "utf8"));
|
|
@@ -4052,7 +4167,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
4052
4167
|
return isWorkspaceMcpConfigPath(target) && within2(target, managedRunRootForProfile(profileRoot));
|
|
4053
4168
|
}
|
|
4054
4169
|
function writeOwnedFileAtomic(filePath, contents) {
|
|
4055
|
-
if (
|
|
4170
|
+
if (existsSync4(filePath)) {
|
|
4056
4171
|
const stat = lstatSync3(filePath);
|
|
4057
4172
|
if (!stat.isFile() || stat.isSymbolicLink()) {
|
|
4058
4173
|
throw new Error(`pi_managed_mcp_workspace_config_unsafe: ${filePath}`);
|
|
@@ -4074,7 +4189,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
4074
4189
|
}
|
|
4075
4190
|
const settingsPath = join5(home, "settings.json");
|
|
4076
4191
|
let settings = {};
|
|
4077
|
-
if (
|
|
4192
|
+
if (existsSync4(settingsPath)) {
|
|
4078
4193
|
try {
|
|
4079
4194
|
settings = record6(JSON.parse(readFileSync4(settingsPath, "utf8")));
|
|
4080
4195
|
} catch {
|
|
@@ -4092,7 +4207,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
4092
4207
|
function readSkillProfile(piHome, skillProfile) {
|
|
4093
4208
|
const agentsRoot = resolve3(piHome, "agents");
|
|
4094
4209
|
const agentFile = resolve3(agentsRoot, `${skillProfile}.md`);
|
|
4095
|
-
if (!SKILL_PROFILE_NAME.test(skillProfile) || !within2(agentFile, agentsRoot) || !
|
|
4210
|
+
if (!SKILL_PROFILE_NAME.test(skillProfile) || !within2(agentFile, agentsRoot) || !existsSync4(agentFile)) {
|
|
4096
4211
|
throw new Error(`pi_managed_mcp_skill_profile_unknown:${skillProfile}`);
|
|
4097
4212
|
}
|
|
4098
4213
|
const declared = readFileSync4(agentFile, "utf8").match(/^---\r?\n([\s\S]*?)\r?\n---/)?.[1].match(/^skills:\s*(.+)$/m)?.[1].split(",").map((entry) => entry.trim()).filter(Boolean) ?? [];
|
|
@@ -4100,12 +4215,12 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
4100
4215
|
const profile = [];
|
|
4101
4216
|
for (const name of declared) {
|
|
4102
4217
|
let source = join5(bundlesRoot, skillProfile, "skills", name);
|
|
4103
|
-
if (!
|
|
4218
|
+
if (!existsSync4(join5(source, "SKILL.md"))) {
|
|
4104
4219
|
const candidates = [];
|
|
4105
4220
|
for (const category of readdirSync3(bundlesRoot).sort()) {
|
|
4106
4221
|
if (category === skillProfile) continue;
|
|
4107
4222
|
const candidate = join5(bundlesRoot, category, "skills", name);
|
|
4108
|
-
if (
|
|
4223
|
+
if (existsSync4(join5(candidate, "SKILL.md"))) candidates.push(candidate);
|
|
4109
4224
|
}
|
|
4110
4225
|
if (candidates.length > 1) {
|
|
4111
4226
|
throw new Error(`pi_managed_mcp_skill_profile_ambiguous:${skillProfile}:${name}`);
|
|
@@ -4121,10 +4236,10 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
4121
4236
|
}
|
|
4122
4237
|
function readCommonRoleSkills(piHome) {
|
|
4123
4238
|
const skillsRoot = resolve3(piHome, "bundles", "common", "skills");
|
|
4124
|
-
if (!
|
|
4239
|
+
if (!existsSync4(skillsRoot)) return [];
|
|
4125
4240
|
return readdirSync3(skillsRoot).sort().flatMap((name) => {
|
|
4126
4241
|
const source = join5(skillsRoot, name);
|
|
4127
|
-
return
|
|
4242
|
+
return existsSync4(join5(source, "SKILL.md")) ? [{ name, source }] : [];
|
|
4128
4243
|
});
|
|
4129
4244
|
}
|
|
4130
4245
|
function resolveManagedRoleSkills(piHome, skillProfiles) {
|
|
@@ -4191,7 +4306,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
4191
4306
|
}
|
|
4192
4307
|
}
|
|
4193
4308
|
const authSource = join5(source, "auth.json");
|
|
4194
|
-
if (
|
|
4309
|
+
if (existsSync4(authSource)) {
|
|
4195
4310
|
try {
|
|
4196
4311
|
collectAuthSecretStrings2(JSON.parse(readFileSync4(authSource, "utf8")), protectedValues);
|
|
4197
4312
|
} catch {
|
|
@@ -4212,6 +4327,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
4212
4327
|
timeout: PI_VERSION_ATTESTATION_TIMEOUT_MS,
|
|
4213
4328
|
killSignal: "SIGKILL",
|
|
4214
4329
|
maxBuffer: 1024 * 1024,
|
|
4330
|
+
...isWindowsCommandShim(resolvedExecutorCommand) ? { shell: true } : {},
|
|
4215
4331
|
...spawnIdentity ?? {}
|
|
4216
4332
|
});
|
|
4217
4333
|
if (result3.error?.code === "ETIMEDOUT" && attempt < PI_ATTESTATION_MAX_ATTEMPTS) continue;
|
|
@@ -4276,7 +4392,7 @@ ${result3.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
4276
4392
|
function inspectEffectiveToolsProbeReceipt(receiptPath, phasePath) {
|
|
4277
4393
|
let phase = "missing";
|
|
4278
4394
|
let history = [];
|
|
4279
|
-
if (
|
|
4395
|
+
if (existsSync4(phasePath)) {
|
|
4280
4396
|
try {
|
|
4281
4397
|
const phaseState = JSON.parse(readFileSync4(phasePath, "utf8"));
|
|
4282
4398
|
phase = typeof phaseState.phase === "string" ? phaseState.phase : "present";
|
|
@@ -4285,7 +4401,7 @@ ${result3.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
4285
4401
|
phase = "invalid";
|
|
4286
4402
|
}
|
|
4287
4403
|
}
|
|
4288
|
-
if (!
|
|
4404
|
+
if (!existsSync4(receiptPath)) return { phase, history, receipt: null };
|
|
4289
4405
|
try {
|
|
4290
4406
|
const receipt = JSON.parse(readFileSync4(receiptPath, "utf8"));
|
|
4291
4407
|
const receiptPhase = receipt?.status === "attested" || receipt?.status === "rejected" ? receipt.status : phase === "missing" ? "present" : phase;
|
|
@@ -4330,7 +4446,8 @@ ${result3.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
4330
4446
|
const timeout = attempts[index];
|
|
4331
4447
|
completedAttempts = attempt;
|
|
4332
4448
|
writeEffectiveToolsProbePhase(input.phasePath, "spawned", attempt);
|
|
4333
|
-
|
|
4449
|
+
const resolvedExecutorCommand = resolveExecutorCommand(executorCommand, env) ?? executorCommand;
|
|
4450
|
+
result3 = spawnSyncImpl(resolvedExecutorCommand, [
|
|
4334
4451
|
"--no-session",
|
|
4335
4452
|
"--no-approve",
|
|
4336
4453
|
"--no-skills",
|
|
@@ -4352,6 +4469,7 @@ ${result3.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
4352
4469
|
timeout,
|
|
4353
4470
|
killSignal: "SIGKILL",
|
|
4354
4471
|
maxBuffer: 1024 * 1024,
|
|
4472
|
+
...isWindowsCommandShim(resolvedExecutorCommand) ? { shell: true } : {},
|
|
4355
4473
|
...spawnIdentity ?? {}
|
|
4356
4474
|
});
|
|
4357
4475
|
if (result3.error?.code === "ETIMEDOUT" && attempt < attempts.length) continue;
|
|
@@ -4446,7 +4564,7 @@ ${result3.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
4446
4564
|
if (!within2(executorHome, join5(runDir, "executors"))) throw new Error("pi_managed_mcp_owner_mismatch: executorHome is outside the managed run");
|
|
4447
4565
|
assertWorkspaceMcpOverrideClear(cwd, runDir);
|
|
4448
4566
|
const profileRoot = join5(executorHome, "managed-mcp");
|
|
4449
|
-
if (
|
|
4567
|
+
if (existsSync4(profileRoot)) throw new Error(`pi_managed_mcp_profile_exists: ${profileRoot}`);
|
|
4450
4568
|
const home = join5(profileRoot, "home");
|
|
4451
4569
|
const piAgentHome = join5(profileRoot, "pi-agent-home");
|
|
4452
4570
|
const sessionsRoot = join5(profileRoot, "sessions");
|
|
@@ -4511,7 +4629,7 @@ ${result3.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
4511
4629
|
"pi-mcp-adapter",
|
|
4512
4630
|
"index.ts"
|
|
4513
4631
|
);
|
|
4514
|
-
if (!
|
|
4632
|
+
if (!existsSync4(adapterExtensionPath)) {
|
|
4515
4633
|
throw new Error("pi_managed_mcp_adapter_extension_missing");
|
|
4516
4634
|
}
|
|
4517
4635
|
const adapterExtensionStat = lstatSync3(adapterExtensionPath);
|
|
@@ -4823,7 +4941,7 @@ ${result3.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
4823
4941
|
if (!within2(path, profileRoot)) throw new Error("pi_run_exit_closure_baseline_path_mismatch");
|
|
4824
4942
|
}
|
|
4825
4943
|
for (const path of [cachePath, manifestPath, configPath, receiptPath]) {
|
|
4826
|
-
if (
|
|
4944
|
+
if (existsSync4(path)) {
|
|
4827
4945
|
const stat = lstatSync3(path);
|
|
4828
4946
|
if (!stat.isFile() || stat.isSymbolicLink()) {
|
|
4829
4947
|
throw new Error(`pi_run_exit_closure_baseline_unsafe: ${path}`);
|
|
@@ -4840,7 +4958,7 @@ ${result3.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
4840
4958
|
throw new Error("pi_run_exit_closure_baseline_cache_digest_mismatch");
|
|
4841
4959
|
}
|
|
4842
4960
|
const baselineCacheOwnership = record6(baseline.cacheOwnership);
|
|
4843
|
-
const cacheOwnership = Number.isSafeInteger(baselineCacheOwnership.uid) && baselineCacheOwnership.uid >= 0 && Number.isSafeInteger(baselineCacheOwnership.gid) && baselineCacheOwnership.gid >= 0 ? { uid: baselineCacheOwnership.uid, gid: baselineCacheOwnership.gid } :
|
|
4961
|
+
const cacheOwnership = Number.isSafeInteger(baselineCacheOwnership.uid) && baselineCacheOwnership.uid >= 0 && Number.isSafeInteger(baselineCacheOwnership.gid) && baselineCacheOwnership.gid >= 0 ? { uid: baselineCacheOwnership.uid, gid: baselineCacheOwnership.gid } : existsSync4(cachePath) ? ownershipStatSyncImpl(cachePath) : null;
|
|
4844
4962
|
if (!cacheOwnership) {
|
|
4845
4963
|
throw new Error("pi_run_exit_closure_baseline_cache_owner_missing");
|
|
4846
4964
|
}
|
|
@@ -4894,7 +5012,7 @@ ${result3.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
4894
5012
|
ownership: baselineCacheOwnership,
|
|
4895
5013
|
label: "cache"
|
|
4896
5014
|
}];
|
|
4897
|
-
if (
|
|
5015
|
+
if (existsSync4(receiptPath)) rmSync3(receiptPath);
|
|
4898
5016
|
for (const entry of phaseContents) {
|
|
4899
5017
|
if (sha2563(entry.bytes) !== entry.expectedSha256) {
|
|
4900
5018
|
throw new Error(`pi_run_exit_closure_${entry.label}_digest_mismatch`);
|
|
@@ -4929,7 +5047,7 @@ ${result3.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
4929
5047
|
const profileRoot = resolve3(nonEmpty2(baseline.profileRoot, "runExitClosureBaseline.profileRoot"));
|
|
4930
5048
|
const receiptPath = resolve3(nonEmpty2(baseline.receiptPath, "runExitClosureBaseline.receiptPath"));
|
|
4931
5049
|
if (!within2(receiptPath, profileRoot)) throw new Error("pi_run_exit_closure_baseline_path_mismatch");
|
|
4932
|
-
if (!
|
|
5050
|
+
if (!existsSync4(receiptPath)) return { status: "missing" };
|
|
4933
5051
|
const stat = lstatSync3(receiptPath);
|
|
4934
5052
|
if (!stat.isFile() || stat.isSymbolicLink()) {
|
|
4935
5053
|
throw new Error(`pi_run_exit_closure_baseline_unsafe: ${receiptPath}`);
|
|
@@ -4959,7 +5077,7 @@ ${result3.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
4959
5077
|
const executorHome = resolve3(nonEmpty2(input.executorHome, "executorHome"));
|
|
4960
5078
|
if (!within2(executorHome, join5(runDir, "executors"))) throw new Error("pi_delegated_mcp_owner_mismatch: executorHome is outside the managed run");
|
|
4961
5079
|
const profileRoot = join5(executorHome, "delegated-mcp");
|
|
4962
|
-
if (
|
|
5080
|
+
if (existsSync4(profileRoot)) throw new Error(`pi_delegated_mcp_profile_exists: ${profileRoot}`);
|
|
4963
5081
|
const piCodingAgentDir = join5(profileRoot, "pi-coding-agent-dir");
|
|
4964
5082
|
const sessionsRoot = join5(profileRoot, "sessions");
|
|
4965
5083
|
const tmp = join5(profileRoot, "tmp");
|
|
@@ -5078,11 +5196,11 @@ ${result3.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
5078
5196
|
const sessionsRoot = resolve3(nonEmpty2(profile?.env?.["AMASTER-CLI_CODING_AGENT_SESSION_DIR"], "profile session dir"));
|
|
5079
5197
|
const sourceRollout = findPiSessionRollout(sessionsRoot, sessionId);
|
|
5080
5198
|
const rolloutRelativePath = relative2(sessionsRoot, sourceRollout);
|
|
5081
|
-
if (!rolloutRelativePath || rolloutRelativePath.startsWith("..") ||
|
|
5199
|
+
if (!rolloutRelativePath || rolloutRelativePath.startsWith("..") || isAbsolute3(rolloutRelativePath)) {
|
|
5082
5200
|
throw new Error("pi_managed_mcp_session_rollout_unsafe: rollout escaped the managed Pi home");
|
|
5083
5201
|
}
|
|
5084
5202
|
const cacheRoot = join5(dirname4(resolve3(profile.profileRoot)), "session-rollout");
|
|
5085
|
-
if (
|
|
5203
|
+
if (existsSync4(cacheRoot)) rmSync3(cacheRoot, { recursive: true, force: false });
|
|
5086
5204
|
mkdirSync3(cacheRoot, { recursive: true, mode: 448 });
|
|
5087
5205
|
const targetRollout = join5(cacheRoot, rolloutRelativePath);
|
|
5088
5206
|
mkdirSync3(dirname4(targetRollout), { recursive: true, mode: 448 });
|
|
@@ -5122,7 +5240,7 @@ ${result3.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
5122
5240
|
}
|
|
5123
5241
|
function cleanupManagedPiMcpProfile2(profile, owner) {
|
|
5124
5242
|
const profileRoot = resolve3(nonEmpty2(profile?.profileRoot, "profileRoot"));
|
|
5125
|
-
if (!
|
|
5243
|
+
if (!existsSync4(profileRoot)) {
|
|
5126
5244
|
if (typeof profile?.workspaceMcpConfigPath === "string") {
|
|
5127
5245
|
removeWorkspaceMcpConfig(profile.workspaceMcpConfigPath, profileRoot);
|
|
5128
5246
|
}
|
|
@@ -5133,7 +5251,7 @@ ${result3.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
5133
5251
|
throw new Error("pi_managed_mcp_cleanup_owner_mismatch: profile root is not an owned directory");
|
|
5134
5252
|
}
|
|
5135
5253
|
const markerPath = join5(profileRoot, PROFILE_MARKER2);
|
|
5136
|
-
const markerStat =
|
|
5254
|
+
const markerStat = existsSync4(markerPath) ? lstatSync3(markerPath) : null;
|
|
5137
5255
|
if (!markerStat?.isFile() || markerStat.isSymbolicLink()) {
|
|
5138
5256
|
throw new Error("pi_managed_mcp_cleanup_owner_mismatch: ownership marker is missing or unsafe");
|
|
5139
5257
|
}
|
|
@@ -5147,7 +5265,7 @@ ${result3.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
5147
5265
|
throw new Error("pi_managed_mcp_cleanup_owner_mismatch: ownership marker does not match command/run");
|
|
5148
5266
|
}
|
|
5149
5267
|
rmSync3(profileRoot, { recursive: true, force: false });
|
|
5150
|
-
if (
|
|
5268
|
+
if (existsSync4(profileRoot)) throw new Error("pi_managed_mcp_cleanup_failed: profile root still exists");
|
|
5151
5269
|
if (typeof profile?.workspaceMcpConfigPath === "string") {
|
|
5152
5270
|
removeWorkspaceMcpConfig(profile.workspaceMcpConfigPath, profileRoot);
|
|
5153
5271
|
}
|
|
@@ -5155,13 +5273,13 @@ ${result3.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
5155
5273
|
}
|
|
5156
5274
|
function cleanupDelegatedPiMcpProfile2(profile, owner) {
|
|
5157
5275
|
const profileRoot = resolve3(nonEmpty2(profile?.profileRoot, "profileRoot"));
|
|
5158
|
-
if (!
|
|
5276
|
+
if (!existsSync4(profileRoot)) return { status: "already_removed", profileRoot };
|
|
5159
5277
|
const rootStat = lstatSync3(profileRoot);
|
|
5160
5278
|
if (!rootStat.isDirectory() || rootStat.isSymbolicLink()) {
|
|
5161
5279
|
throw new Error("pi_delegated_mcp_cleanup_owner_mismatch: profile root is not an owned directory");
|
|
5162
5280
|
}
|
|
5163
5281
|
const markerPath = join5(profileRoot, DELEGATED_PROFILE_MARKER);
|
|
5164
|
-
const markerStat =
|
|
5282
|
+
const markerStat = existsSync4(markerPath) ? lstatSync3(markerPath) : null;
|
|
5165
5283
|
if (!markerStat?.isFile() || markerStat.isSymbolicLink()) {
|
|
5166
5284
|
throw new Error("pi_delegated_mcp_cleanup_owner_mismatch: ownership marker is missing or unsafe");
|
|
5167
5285
|
}
|
|
@@ -5175,12 +5293,12 @@ ${result3.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
5175
5293
|
throw new Error("pi_delegated_mcp_cleanup_owner_mismatch: ownership marker does not match command/run");
|
|
5176
5294
|
}
|
|
5177
5295
|
rmSync3(profileRoot, { recursive: true, force: false });
|
|
5178
|
-
if (
|
|
5296
|
+
if (existsSync4(profileRoot)) throw new Error("pi_delegated_mcp_cleanup_failed: profile root still exists");
|
|
5179
5297
|
return { status: "removed", profileRoot };
|
|
5180
5298
|
}
|
|
5181
5299
|
function reconcileManagedPiMcpProfiles2(rootPath, options2 = {}) {
|
|
5182
5300
|
const root = resolve3(rootPath);
|
|
5183
|
-
if (!
|
|
5301
|
+
if (!existsSync4(root)) return { scanned: 0, removed: 0, removedProfiles: 0, removedRollouts: 0, failed: 0, failures: [] };
|
|
5184
5302
|
const canonicalRoot = realpathSync2(root);
|
|
5185
5303
|
const profileMarkers = [];
|
|
5186
5304
|
const rolloutMarkers = [];
|
|
@@ -5206,7 +5324,7 @@ ${result3.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
5206
5324
|
try {
|
|
5207
5325
|
const marker = JSON.parse(readFileSync4(markerPath, "utf8"));
|
|
5208
5326
|
const markerProfileRoot = typeof marker?.profileRoot === "string" ? resolve3(marker.profileRoot) : null;
|
|
5209
|
-
if (!markerProfileRoot || !
|
|
5327
|
+
if (!markerProfileRoot || !existsSync4(markerProfileRoot) || !within2(realpathSync2(profileRoot), canonicalRoot) || realpathSync2(markerProfileRoot) !== realpathSync2(profileRoot)) throw new Error("ownership marker root mismatch");
|
|
5210
5328
|
if (protectedCommandIds.has(marker?.commandId)) {
|
|
5211
5329
|
preservedProfiles += 1;
|
|
5212
5330
|
continue;
|
|
@@ -5233,12 +5351,12 @@ ${result3.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
5233
5351
|
const cacheStat = lstatSync3(cacheRoot);
|
|
5234
5352
|
const marker = JSON.parse(readFileSync4(markerPath, "utf8"));
|
|
5235
5353
|
const markerCacheRoot = typeof marker?.cacheRoot === "string" ? resolve3(marker.cacheRoot) : null;
|
|
5236
|
-
if (!within2(realpathSync2(cacheRoot), canonicalRoot) || basename2(cacheRoot) !== "session-rollout" || markerStat.isSymbolicLink() || !markerStat.isFile() || cacheStat.isSymbolicLink() || !cacheStat.isDirectory() || marker?.version !== 1 || typeof marker?.companyId !== "string" || typeof marker?.agentId !== "string" || typeof marker?.sourceRunId !== "string" || typeof marker?.sourceCommandId !== "string" || typeof marker?.sessionId !== "string" || !markerCacheRoot || !
|
|
5354
|
+
if (!within2(realpathSync2(cacheRoot), canonicalRoot) || basename2(cacheRoot) !== "session-rollout" || markerStat.isSymbolicLink() || !markerStat.isFile() || cacheStat.isSymbolicLink() || !cacheStat.isDirectory() || marker?.version !== 1 || typeof marker?.companyId !== "string" || typeof marker?.agentId !== "string" || typeof marker?.sourceRunId !== "string" || typeof marker?.sourceCommandId !== "string" || typeof marker?.sessionId !== "string" || !markerCacheRoot || !existsSync4(markerCacheRoot) || realpathSync2(markerCacheRoot) !== realpathSync2(cacheRoot)) throw new Error("session rollout ownership marker mismatch");
|
|
5237
5355
|
const preservedAtMs = typeof marker.preservedAt === "string" ? Date.parse(marker.preservedAt) : Number.NaN;
|
|
5238
5356
|
const markerAgeMs = nowMs - (Number.isFinite(preservedAtMs) ? preservedAtMs : markerStat.mtimeMs);
|
|
5239
5357
|
if (markerAgeMs < rolloutTtlMs) continue;
|
|
5240
5358
|
rmSync3(cacheRoot, { recursive: true, force: false });
|
|
5241
|
-
if (
|
|
5359
|
+
if (existsSync4(cacheRoot)) throw new Error("session rollout cache still exists");
|
|
5242
5360
|
removedRollouts += 1;
|
|
5243
5361
|
} catch (error) {
|
|
5244
5362
|
failures.push({ profileRoot: cacheRoot, error: error instanceof Error ? error.message : String(error) });
|
|
@@ -5391,7 +5509,7 @@ function isTerminalResultOutboxStatus(status) {
|
|
|
5391
5509
|
}
|
|
5392
5510
|
|
|
5393
5511
|
// src/amaster-runtime-daemon/run-completion-state.mjs
|
|
5394
|
-
import { existsSync as
|
|
5512
|
+
import { existsSync as existsSync5, mkdirSync as mkdirSync4, readFileSync as readFileSync6, readdirSync as readdirSync5, renameSync as renameSync4, unlinkSync, writeFileSync as writeFileSync5 } from "node:fs";
|
|
5395
5513
|
import { join as join6 } from "node:path";
|
|
5396
5514
|
var RUN_COMPLETION_STATE_VERSION = 1;
|
|
5397
5515
|
var RUN_COMPLETION_USAGE_SCHEMA_VERSION = "runtime-command-usage-v1";
|
|
@@ -5656,12 +5774,12 @@ function readRunCompletionState(filePath) {
|
|
|
5656
5774
|
return assertValidRunCompletionState(JSON.parse(readFileSync6(filePath, "utf8")));
|
|
5657
5775
|
}
|
|
5658
5776
|
function listRunCompletionStateFiles(directory) {
|
|
5659
|
-
if (!
|
|
5777
|
+
if (!existsSync5(directory)) return [];
|
|
5660
5778
|
return readdirSync5(directory).filter((name) => name.endsWith(".json")).sort().map((name) => join6(directory, name));
|
|
5661
5779
|
}
|
|
5662
5780
|
function removeRunCompletionState(directory, commandId) {
|
|
5663
5781
|
const filePath = join6(directory, runCompletionStateFileName(commandId));
|
|
5664
|
-
if (
|
|
5782
|
+
if (existsSync5(filePath)) unlinkSync(filePath);
|
|
5665
5783
|
}
|
|
5666
5784
|
|
|
5667
5785
|
// src/amaster-runtime-daemon/source-output-retention.mjs
|
|
@@ -8059,82 +8177,9 @@ function resolveAgentInstructionSystemKernelBundle(bundle, options = {}) {
|
|
|
8059
8177
|
}
|
|
8060
8178
|
|
|
8061
8179
|
// src/amaster-runtime-daemon/config-state.mjs
|
|
8062
|
-
import { existsSync as
|
|
8180
|
+
import { existsSync as existsSync6, mkdirSync as mkdirSync5, readFileSync as readFileSync7, renameSync as renameSync5, rmSync as rmSync4, writeFileSync as writeFileSync6 } from "node:fs";
|
|
8063
8181
|
import { homedir as homedir2, hostname } from "node:os";
|
|
8064
8182
|
import { dirname as dirname5, join as join7 } from "node:path";
|
|
8065
|
-
|
|
8066
|
-
// src/amaster-runtime-daemon/executor-discovery.mjs
|
|
8067
|
-
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
8068
|
-
import { delimiter as delimiter2 } from "node:path";
|
|
8069
|
-
var KNOWN_EXECUTORS = [
|
|
8070
|
-
["codex", "codex"],
|
|
8071
|
-
["claude", "claude"],
|
|
8072
|
-
["cursor", "cursor"],
|
|
8073
|
-
["opencode", "opencode"],
|
|
8074
|
-
["hermes", "hermes"],
|
|
8075
|
-
["pi", "pi"],
|
|
8076
|
-
["openclaw", "openclaw"]
|
|
8077
|
-
];
|
|
8078
|
-
function executorDiscoveryEnv(env = process.env) {
|
|
8079
|
-
const extraPaths = splitList(env.AMASTER_EXECUTOR_PATHS);
|
|
8080
|
-
if (extraPaths.length === 0) return env;
|
|
8081
|
-
return {
|
|
8082
|
-
...env,
|
|
8083
|
-
PATH: [...extraPaths, env.PATH ?? ""].filter(Boolean).join(delimiter2)
|
|
8084
|
-
};
|
|
8085
|
-
}
|
|
8086
|
-
function commandExists(command, env = process.env) {
|
|
8087
|
-
const commandEnv = executorDiscoveryEnv(env);
|
|
8088
|
-
const result3 = spawnSync3("sh", ["-lc", `command -v ${quoteShell(command)} >/dev/null 2>&1`], {
|
|
8089
|
-
env: commandEnv,
|
|
8090
|
-
stdio: "ignore"
|
|
8091
|
-
});
|
|
8092
|
-
return result3.status === 0;
|
|
8093
|
-
}
|
|
8094
|
-
function commandVersion(command, env = process.env) {
|
|
8095
|
-
const commandEnv = executorDiscoveryEnv(env);
|
|
8096
|
-
const result3 = spawnSync3(command, ["--version"], {
|
|
8097
|
-
env: commandEnv,
|
|
8098
|
-
encoding: "utf8",
|
|
8099
|
-
stdio: ["ignore", "pipe", "ignore"],
|
|
8100
|
-
timeout: 3e3
|
|
8101
|
-
});
|
|
8102
|
-
if (result3.status !== 0) return void 0;
|
|
8103
|
-
return result3.stdout.trim().split(/\r?\n/)[0]?.slice(0, 120) || void 0;
|
|
8104
|
-
}
|
|
8105
|
-
function discoverExecutors(options = {}) {
|
|
8106
|
-
const knownExecutors = options.knownExecutors ?? KNOWN_EXECUTORS;
|
|
8107
|
-
const env = options.env ?? process.env;
|
|
8108
|
-
return knownExecutors.filter(([, command]) => commandExists(command, env)).map(([kind, command]) => {
|
|
8109
|
-
const version = commandVersion(command, env);
|
|
8110
|
-
return {
|
|
8111
|
-
kind,
|
|
8112
|
-
command,
|
|
8113
|
-
...version ? { version } : {}
|
|
8114
|
-
};
|
|
8115
|
-
});
|
|
8116
|
-
}
|
|
8117
|
-
function parseExecutors(value, options = {}) {
|
|
8118
|
-
const configured = splitList(value);
|
|
8119
|
-
if (configured.length === 0) {
|
|
8120
|
-
const discovered = discoverExecutors(options);
|
|
8121
|
-
return discovered.length > 0 ? discovered : [{ kind: "custom", command: "replace-with-executor-command" }];
|
|
8122
|
-
}
|
|
8123
|
-
return configured.map((entry) => {
|
|
8124
|
-
const [kind, command, ...versionParts] = entry.split(":");
|
|
8125
|
-
if (!kind?.trim() || !command?.trim()) {
|
|
8126
|
-
throw new Error(`Invalid AMASTER_EXECUTORS entry: ${entry}`);
|
|
8127
|
-
}
|
|
8128
|
-
const version = versionParts.join(":").trim();
|
|
8129
|
-
return {
|
|
8130
|
-
kind: kind.trim(),
|
|
8131
|
-
command: command.trim(),
|
|
8132
|
-
...version ? { version } : {}
|
|
8133
|
-
};
|
|
8134
|
-
});
|
|
8135
|
-
}
|
|
8136
|
-
|
|
8137
|
-
// src/amaster-runtime-daemon/config-state.mjs
|
|
8138
8183
|
var CAPABILITIES = [
|
|
8139
8184
|
"remote_registration",
|
|
8140
8185
|
"heartbeat",
|
|
@@ -8204,14 +8249,14 @@ function corruptStatePath(path) {
|
|
|
8204
8249
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/\D/g, "").slice(0, 14);
|
|
8205
8250
|
const base = `${path}.corrupt-${timestamp}Z`;
|
|
8206
8251
|
let candidate = base;
|
|
8207
|
-
for (let suffix = 1;
|
|
8252
|
+
for (let suffix = 1; existsSync6(candidate); suffix += 1) {
|
|
8208
8253
|
candidate = `${base}.${suffix}`;
|
|
8209
8254
|
}
|
|
8210
8255
|
return candidate;
|
|
8211
8256
|
}
|
|
8212
8257
|
function readState(env) {
|
|
8213
8258
|
const path = stateFilePath(env);
|
|
8214
|
-
if (!
|
|
8259
|
+
if (!existsSync6(path)) return {};
|
|
8215
8260
|
try {
|
|
8216
8261
|
const state = JSON.parse(readFileSync7(path, "utf8"));
|
|
8217
8262
|
if (!state || typeof state !== "object" || Array.isArray(state)) {
|
|
@@ -10052,7 +10097,7 @@ var bestEffortPostJson = bestEffortPostRuntimeConnectorJson;
|
|
|
10052
10097
|
// src/amaster-runtime-daemon/runtime-artifact-upload.mjs
|
|
10053
10098
|
import { createHash as createHash8 } from "node:crypto";
|
|
10054
10099
|
import { closeSync, constants, fstatSync, lstatSync as lstatSync4, openSync, readFileSync as readFileSync8, realpathSync as realpathSync3 } from "node:fs";
|
|
10055
|
-
import { isAbsolute as
|
|
10100
|
+
import { isAbsolute as isAbsolute4, relative as relative3, resolve as resolve4 } from "node:path";
|
|
10056
10101
|
var SHA256_PATTERN = /^[a-f0-9]{64}$/;
|
|
10057
10102
|
function requiredString(value, name) {
|
|
10058
10103
|
if (typeof value !== "string" || !value.trim()) throw new Error(`Runtime Artifact ${name} is required`);
|
|
@@ -10065,7 +10110,7 @@ function ownedRelativePath(value) {
|
|
|
10065
10110
|
}
|
|
10066
10111
|
function pathWithin(candidate, root) {
|
|
10067
10112
|
const rel = relative3(root, candidate);
|
|
10068
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
10113
|
+
return rel === "" || !rel.startsWith("..") && !isAbsolute4(rel);
|
|
10069
10114
|
}
|
|
10070
10115
|
function sameFileSnapshot(left, right) {
|
|
10071
10116
|
return left.dev === right.dev && left.ino === right.ino && left.size === right.size && left.mtimeMs === right.mtimeMs && left.ctimeMs === right.ctimeMs;
|
|
@@ -10388,11 +10433,11 @@ function createRuntimeArtifactIngestQueue({ ingest, onError }) {
|
|
|
10388
10433
|
|
|
10389
10434
|
// src/amaster-runtime-daemon/workspace-guard.mjs
|
|
10390
10435
|
import { createHash as createHash10 } from "node:crypto";
|
|
10391
|
-
import { existsSync as
|
|
10392
|
-
import { basename as basename4, join as join9, isAbsolute as
|
|
10436
|
+
import { existsSync as existsSync8, mkdirSync as mkdirSync6, realpathSync as realpathSync4, statSync as statSync4 } from "node:fs";
|
|
10437
|
+
import { basename as basename4, join as join9, isAbsolute as isAbsolute5, relative as relative4, resolve as resolve5 } from "node:path";
|
|
10393
10438
|
|
|
10394
10439
|
// src/amaster-runtime-daemon/workspace-manifest.mjs
|
|
10395
|
-
import { chownSync as chownSync3, existsSync as
|
|
10440
|
+
import { chownSync as chownSync3, existsSync as existsSync7, readFileSync as readFileSync9, renameSync as renameSync6, rmSync as rmSync5, statSync as statSync3, writeFileSync as writeFileSync7 } from "node:fs";
|
|
10396
10441
|
import { basename as basename3, dirname as dirname6, join as join8 } from "node:path";
|
|
10397
10442
|
var WORKSPACE_MANIFEST_FILENAME = ".amaster-runtime.json";
|
|
10398
10443
|
function syncManifestDirOwnership(manifestPath, deps = {}) {
|
|
@@ -10419,7 +10464,7 @@ function workspaceManifestPath(workspaceOrCwd) {
|
|
|
10419
10464
|
return null;
|
|
10420
10465
|
}
|
|
10421
10466
|
function readWorkspaceManifest(manifestPath) {
|
|
10422
|
-
if (!manifestPath || !
|
|
10467
|
+
if (!manifestPath || !existsSync7(manifestPath)) return null;
|
|
10423
10468
|
try {
|
|
10424
10469
|
const parsed = JSON.parse(readFileSync9(manifestPath, "utf8"));
|
|
10425
10470
|
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
|
|
@@ -10489,7 +10534,7 @@ function updateWorkspaceManifest(workspaceOrManifestPath, patch = {}) {
|
|
|
10489
10534
|
// src/amaster-runtime-daemon/workspace-guard.mjs
|
|
10490
10535
|
function pathWithin2(candidate, root) {
|
|
10491
10536
|
const rel = relative4(root, candidate);
|
|
10492
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
10537
|
+
return rel === "" || !rel.startsWith("..") && !isAbsolute5(rel);
|
|
10493
10538
|
}
|
|
10494
10539
|
function resolveWorkspaceCwd(config, command) {
|
|
10495
10540
|
const payload = asRecord(command.payload);
|
|
@@ -10507,7 +10552,7 @@ function resolveWorkspaceCwd(config, command) {
|
|
|
10507
10552
|
if (!allowed) {
|
|
10508
10553
|
throw new Error(`Workspace path is outside AMASTER_WORKSPACE_ALLOWLIST: ${cwd}`);
|
|
10509
10554
|
}
|
|
10510
|
-
if (!
|
|
10555
|
+
if (!existsSync8(cwd) || !statSync4(cwd).isDirectory()) {
|
|
10511
10556
|
throw new Error(`Workspace path does not exist or is not a directory: ${cwd}`);
|
|
10512
10557
|
}
|
|
10513
10558
|
return cwd;
|
|
@@ -10577,7 +10622,7 @@ function resolveExecutionWorkspace(config, command, opts = {}) {
|
|
|
10577
10622
|
}
|
|
10578
10623
|
|
|
10579
10624
|
// src/amaster-runtime-daemon/workspace-gc.mjs
|
|
10580
|
-
import { existsSync as
|
|
10625
|
+
import { existsSync as existsSync9, readdirSync as readdirSync6, statSync as statSync5 } from "node:fs";
|
|
10581
10626
|
import { join as join10, resolve as resolve6 } from "node:path";
|
|
10582
10627
|
function readIsoTime(value) {
|
|
10583
10628
|
if (typeof value !== "string" || !value.trim()) return null;
|
|
@@ -10602,7 +10647,7 @@ function walkWorkdirs(root) {
|
|
|
10602
10647
|
for (const entry of entries) {
|
|
10603
10648
|
if (!entry.isDirectory()) continue;
|
|
10604
10649
|
const fullPath = join10(current, entry.name);
|
|
10605
|
-
if (entry.name === "workdir" &&
|
|
10650
|
+
if (entry.name === "workdir" && existsSync9(workspaceManifestPath(fullPath))) {
|
|
10606
10651
|
workdirs.push(fullPath);
|
|
10607
10652
|
continue;
|
|
10608
10653
|
}
|
|
@@ -10677,7 +10722,7 @@ function planManagedWorkspaceGcDryRun(input) {
|
|
|
10677
10722
|
candidates: [],
|
|
10678
10723
|
protected: []
|
|
10679
10724
|
};
|
|
10680
|
-
if (!root || !
|
|
10725
|
+
if (!root || !existsSync9(root)) return result3;
|
|
10681
10726
|
for (const workdir of walkWorkdirs(root)) {
|
|
10682
10727
|
const manifest = readWorkspaceManifest(workspaceManifestPath(workdir));
|
|
10683
10728
|
if (!manifest || manifest.managed !== true) continue;
|
|
@@ -10708,7 +10753,7 @@ function planManagedWorkspaceGcDryRun(input) {
|
|
|
10708
10753
|
import { createHash as createHash11 } from "node:crypto";
|
|
10709
10754
|
import {
|
|
10710
10755
|
chmodSync as chmodSync5,
|
|
10711
|
-
existsSync as
|
|
10756
|
+
existsSync as existsSync10,
|
|
10712
10757
|
lstatSync as lstatSync5,
|
|
10713
10758
|
mkdirSync as mkdirSync7,
|
|
10714
10759
|
mkdtempSync,
|
|
@@ -10719,7 +10764,7 @@ import {
|
|
|
10719
10764
|
unlinkSync as unlinkSync2,
|
|
10720
10765
|
writeFileSync as writeFileSync8
|
|
10721
10766
|
} from "node:fs";
|
|
10722
|
-
import { dirname as dirname7, extname, isAbsolute as
|
|
10767
|
+
import { dirname as dirname7, extname, isAbsolute as isAbsolute6, join as join11, parse as parse2, resolve as resolve7, sep as sep3 } from "node:path";
|
|
10723
10768
|
import { fileURLToPath } from "node:url";
|
|
10724
10769
|
var PRESET_TEMPLATE_MANIFEST_FILE = ".mirrorx-preset-templates.json";
|
|
10725
10770
|
var MAX_PRESET_TEMPLATE_FILES = 256;
|
|
@@ -10737,7 +10782,7 @@ function lstatIfExists(path) {
|
|
|
10737
10782
|
}
|
|
10738
10783
|
}
|
|
10739
10784
|
function validTemplateName(value) {
|
|
10740
|
-
return typeof value === "string" && value.length > 0 && value !== "." && value !== ".." && !value.includes("\0") && !value.includes("/") && !value.includes("\\") && !
|
|
10785
|
+
return typeof value === "string" && value.length > 0 && value !== "." && value !== ".." && !value.includes("\0") && !value.includes("/") && !value.includes("\\") && !isAbsolute6(value) && parse2(value).base === value && extname(value).toLowerCase() === ".md";
|
|
10741
10786
|
}
|
|
10742
10787
|
function readManifest(manifestPath, { strict }) {
|
|
10743
10788
|
try {
|
|
@@ -10785,7 +10830,7 @@ function removeRetiredPresetFiles(targetDir, previousManifest, nextNames) {
|
|
|
10785
10830
|
for (const entry of previousManifest.files) {
|
|
10786
10831
|
if (nextNames.has(entry.name)) continue;
|
|
10787
10832
|
const targetPath = join11(targetDir, entry.name);
|
|
10788
|
-
if (!
|
|
10833
|
+
if (!existsSync10(targetPath)) continue;
|
|
10789
10834
|
const stat = lstatSync5(targetPath);
|
|
10790
10835
|
if (stat.isDirectory()) {
|
|
10791
10836
|
throw new Error(`preset_template_target_conflict: ${entry.name}`);
|
|
@@ -10852,7 +10897,7 @@ function materializeRuntimePresetTemplates(env = process.env, options = {}) {
|
|
|
10852
10897
|
}
|
|
10853
10898
|
|
|
10854
10899
|
// src/amaster-runtime-daemon/runtime-status-summary.mjs
|
|
10855
|
-
import { existsSync as
|
|
10900
|
+
import { existsSync as existsSync11, readdirSync as readdirSync8, statSync as statSync6 } from "node:fs";
|
|
10856
10901
|
import { dirname as dirname8, join as join12, resolve as resolve8 } from "node:path";
|
|
10857
10902
|
function runtimeStatusDirectoryEntries(path) {
|
|
10858
10903
|
try {
|
|
@@ -10886,7 +10931,7 @@ function runtimeStatusDirectorySizeBytes(path) {
|
|
|
10886
10931
|
}
|
|
10887
10932
|
function walkRuntimeStatusManagedWorkdirs(root) {
|
|
10888
10933
|
const workdirs = [];
|
|
10889
|
-
if (!root || !
|
|
10934
|
+
if (!root || !existsSync11(root)) return workdirs;
|
|
10890
10935
|
const stack = [root];
|
|
10891
10936
|
while (stack.length > 0) {
|
|
10892
10937
|
const current = stack.pop();
|
|
@@ -10894,7 +10939,7 @@ function walkRuntimeStatusManagedWorkdirs(root) {
|
|
|
10894
10939
|
for (const entry of runtimeStatusDirectoryEntries(current)) {
|
|
10895
10940
|
if (!entry.isDirectory()) continue;
|
|
10896
10941
|
const fullPath = join12(current, entry.name);
|
|
10897
|
-
if (entry.name === "workdir" &&
|
|
10942
|
+
if (entry.name === "workdir" && existsSync11(workspaceManifestPath(fullPath))) {
|
|
10898
10943
|
workdirs.push(fullPath);
|
|
10899
10944
|
continue;
|
|
10900
10945
|
}
|
|
@@ -10948,7 +10993,7 @@ function runtimeStatusRunCompletionDir(config) {
|
|
|
10948
10993
|
})), "run-completion-state");
|
|
10949
10994
|
}
|
|
10950
10995
|
function countRuntimeStatusJsonEntries(dir) {
|
|
10951
|
-
if (!
|
|
10996
|
+
if (!existsSync11(dir)) return 0;
|
|
10952
10997
|
return runtimeStatusDirectoryEntries(dir).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).length;
|
|
10953
10998
|
}
|
|
10954
10999
|
function summarizeRuntimeLocalState(input) {
|
|
@@ -11106,8 +11151,8 @@ function summarizeAmasterRuntimeVersionDrift(input = {}) {
|
|
|
11106
11151
|
// src/amaster-runtime-daemon/workspace-status.mjs
|
|
11107
11152
|
import { spawnSync as spawnSync4 } from "node:child_process";
|
|
11108
11153
|
import { createHash as createHash12 } from "node:crypto";
|
|
11109
|
-
import { existsSync as
|
|
11110
|
-
import { basename as basename5, extname as extname2, isAbsolute as
|
|
11154
|
+
import { existsSync as existsSync12, readdirSync as readdirSync9, readFileSync as readFileSync11, statSync as statSync7 } from "node:fs";
|
|
11155
|
+
import { basename as basename5, extname as extname2, isAbsolute as isAbsolute7, join as join13, relative as relative5, resolve as resolve9 } from "node:path";
|
|
11111
11156
|
var WORKSPACE_RUNTIME_SERVICES_FILENAME = ".amaster-runtime-services.json";
|
|
11112
11157
|
var ARTIFACT_EXTENSIONS = /* @__PURE__ */ new Map([
|
|
11113
11158
|
[".md", "markdown"],
|
|
@@ -11153,7 +11198,7 @@ var SAFE_RUNTIME_SERVICE_HEALTH_STATUSES = /* @__PURE__ */ new Set(["unknown", "
|
|
|
11153
11198
|
var SAFE_RUNTIME_SERVICE_LIFECYCLES = /* @__PURE__ */ new Set(["shared", "ephemeral"]);
|
|
11154
11199
|
function statusPathWithin(candidate, root) {
|
|
11155
11200
|
const rel = relative5(root, candidate);
|
|
11156
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
11201
|
+
return rel === "" || !rel.startsWith("..") && !isAbsolute7(rel);
|
|
11157
11202
|
}
|
|
11158
11203
|
function normalizeRelativePath(root, filePath) {
|
|
11159
11204
|
return relative5(root, filePath).split(/[\\/]+/).join("/");
|
|
@@ -11304,7 +11349,7 @@ function sanitizeRuntimeService(entry) {
|
|
|
11304
11349
|
}
|
|
11305
11350
|
function readRuntimeServicesSnapshot(cwd) {
|
|
11306
11351
|
const snapshotPath = join13(resolve9(cwd), WORKSPACE_RUNTIME_SERVICES_FILENAME);
|
|
11307
|
-
if (!
|
|
11352
|
+
if (!existsSync12(snapshotPath)) return [];
|
|
11308
11353
|
try {
|
|
11309
11354
|
const parsed = JSON.parse(readFileSync11(snapshotPath, "utf8"));
|
|
11310
11355
|
const rawServices = Array.isArray(parsed) ? parsed : Array.isArray(parsed?.services) ? parsed.services : [];
|
|
@@ -11539,7 +11584,7 @@ async function executeBrowserSessionCommand(command, dependencies = {}) {
|
|
|
11539
11584
|
import { createHash as createHash13 } from "node:crypto";
|
|
11540
11585
|
import {
|
|
11541
11586
|
chmodSync as chmodSync6,
|
|
11542
|
-
existsSync as
|
|
11587
|
+
existsSync as existsSync13,
|
|
11543
11588
|
lstatSync as lstatSync6,
|
|
11544
11589
|
mkdirSync as mkdirSync8,
|
|
11545
11590
|
readFileSync as readFileSync12,
|
|
@@ -11568,7 +11613,7 @@ function ensureExecutable(path) {
|
|
|
11568
11613
|
}
|
|
11569
11614
|
function ensurePrivateRoot(stateRoot) {
|
|
11570
11615
|
const root = resolve10(stateRoot);
|
|
11571
|
-
if (
|
|
11616
|
+
if (existsSync13(root) && lstatSync6(root).isSymbolicLink()) {
|
|
11572
11617
|
throw brokerError("browser_session_profile_root_symlink");
|
|
11573
11618
|
}
|
|
11574
11619
|
mkdirSync8(root, { recursive: true, mode: 448 });
|
|
@@ -11597,10 +11642,10 @@ function exactProfile(stateRoot, payload, { create = false } = {}) {
|
|
|
11597
11642
|
if (!pathWithin3(profilePath, root) || dirname9(profilePath) !== root) {
|
|
11598
11643
|
throw brokerError("browser_session_profile_path_invalid");
|
|
11599
11644
|
}
|
|
11600
|
-
if (
|
|
11645
|
+
if (existsSync13(profilePath) && lstatSync6(profilePath).isSymbolicLink()) {
|
|
11601
11646
|
throw brokerError("browser_session_profile_symlink");
|
|
11602
11647
|
}
|
|
11603
|
-
if (!
|
|
11648
|
+
if (!existsSync13(profilePath)) {
|
|
11604
11649
|
if (!create) throw brokerError("browser_session_profile_not_found");
|
|
11605
11650
|
mkdirSync8(profilePath, { mode: 448 });
|
|
11606
11651
|
chmodSync6(profilePath, 448);
|
|
@@ -11846,7 +11891,7 @@ var source_acquisition_compatibility_default = {
|
|
|
11846
11891
|
};
|
|
11847
11892
|
|
|
11848
11893
|
// src/amaster-runtime-daemon.mjs
|
|
11849
|
-
var CONNECTOR_VERSION = "0.1.1-beta.
|
|
11894
|
+
var CONNECTOR_VERSION = "0.1.1-beta.93";
|
|
11850
11895
|
var CONNECTOR_CONTRACT_VERSION = "2026-06-04.v1";
|
|
11851
11896
|
var SOURCE_ACQUISITION_CAPABILITY = source_acquisition_compatibility_default.profileVersion;
|
|
11852
11897
|
var daemonRequire = createRequire(import.meta.url);
|
|
@@ -11886,7 +11931,7 @@ function updateActiveRunWorkspaceManifest(commandId, manifestPath, patch = {}) {
|
|
|
11886
11931
|
}
|
|
11887
11932
|
function resultOutboxPendingCount(config) {
|
|
11888
11933
|
const dir = resultOutboxDir(config);
|
|
11889
|
-
if (!
|
|
11934
|
+
if (!existsSync14(dir)) return 0;
|
|
11890
11935
|
try {
|
|
11891
11936
|
let pending = 0;
|
|
11892
11937
|
for (const file of readdirSync10(dir).filter((name) => name.endsWith(".json"))) {
|
|
@@ -11963,7 +12008,7 @@ function piCompletionOutputType(event) {
|
|
|
11963
12008
|
}
|
|
11964
12009
|
function resultOutboxActiveRunCommands(config) {
|
|
11965
12010
|
const dir = resultOutboxDir(config);
|
|
11966
|
-
if (!
|
|
12011
|
+
if (!existsSync14(dir)) return [];
|
|
11967
12012
|
const outboxPending = resultOutboxPendingCount(config);
|
|
11968
12013
|
const entries = [];
|
|
11969
12014
|
for (const file of readdirSync10(dir).filter((name) => name.endsWith(".json")).sort()) {
|
|
@@ -11997,7 +12042,7 @@ function resultOutboxActiveRunCommands(config) {
|
|
|
11997
12042
|
}
|
|
11998
12043
|
function resultOutboxFailedRunCommands(config) {
|
|
11999
12044
|
const dir = resultOutboxInvalidDir(config);
|
|
12000
|
-
if (!
|
|
12045
|
+
if (!existsSync14(dir)) return [];
|
|
12001
12046
|
const entries = [];
|
|
12002
12047
|
for (const file of readdirSync10(dir).filter((name) => name.endsWith(".json")).sort().slice(-100)) {
|
|
12003
12048
|
let entry;
|
|
@@ -12115,7 +12160,7 @@ function safeSkillRootSummary(kind, source, pathValue) {
|
|
|
12115
12160
|
const skillDir = join15(pathValue, name);
|
|
12116
12161
|
try {
|
|
12117
12162
|
if (!statSync9(skillDir).isDirectory()) continue;
|
|
12118
|
-
if (!
|
|
12163
|
+
if (!existsSync14(join15(skillDir, "SKILL.md"))) continue;
|
|
12119
12164
|
skillCount += 1;
|
|
12120
12165
|
if (skillCount >= MAX_PI_CAPABILITY_SOURCE_ENTRIES) {
|
|
12121
12166
|
truncated = true;
|
|
@@ -12309,7 +12354,7 @@ function sourceAcquisitionPackageMetadata(packageName) {
|
|
|
12309
12354
|
...packageName.split("/"),
|
|
12310
12355
|
"package.json"
|
|
12311
12356
|
);
|
|
12312
|
-
if (!
|
|
12357
|
+
if (!existsSync14(packagePath)) return null;
|
|
12313
12358
|
const stat = lstatSync7(packagePath);
|
|
12314
12359
|
if (!stat.isFile() || stat.isSymbolicLink()) return null;
|
|
12315
12360
|
const metadata = readJsonFile2(packagePath);
|
|
@@ -12317,7 +12362,7 @@ function sourceAcquisitionPackageMetadata(packageName) {
|
|
|
12317
12362
|
}
|
|
12318
12363
|
function sourceAcquisitionBrowserExecutableReady() {
|
|
12319
12364
|
const executable = readString(process.env.AMASTER_BROWSER_EXECUTABLE_PATH);
|
|
12320
|
-
if (!executable || !
|
|
12365
|
+
if (!executable || !isAbsolute8(executable)) return false;
|
|
12321
12366
|
try {
|
|
12322
12367
|
const stat = statSync9(executable);
|
|
12323
12368
|
return stat.isFile() && (stat.mode & 73) !== 0;
|
|
@@ -12915,10 +12960,10 @@ function buildActiveRunCommandStatus(config, entry) {
|
|
|
12915
12960
|
const base = {
|
|
12916
12961
|
...entry,
|
|
12917
12962
|
phase: readString(entry.phase) ?? "executing",
|
|
12918
|
-
managedWorkdirPresent: entry.workspacePath ?
|
|
12963
|
+
managedWorkdirPresent: entry.workspacePath ? existsSync14(entry.workspacePath) : false,
|
|
12919
12964
|
outboxPending: resultOutboxPendingCount(config)
|
|
12920
12965
|
};
|
|
12921
|
-
if (!entry.workspacePath || !
|
|
12966
|
+
if (!entry.workspacePath || !existsSync14(entry.workspacePath)) return base;
|
|
12922
12967
|
const manifestPath = entry.manifestPath ?? workspaceManifestPath(entry.workspacePath);
|
|
12923
12968
|
const status = readWorkspaceStatus(entry.workspacePath, { hashCache: workspaceStatusHashCache });
|
|
12924
12969
|
const artifactCandidates = status.artifacts.slice(0, 20);
|
|
@@ -13146,7 +13191,7 @@ async function sourceAcquisitionRuntimeProfile(config, command) {
|
|
|
13146
13191
|
const userDataDir = resolve11(stateRoot, profileName2);
|
|
13147
13192
|
if (!pathWithin2(userDataDir, stateRoot)) throw new Error("source_acquisition_browser_profile_invalid");
|
|
13148
13193
|
const markerPath = join15(userDataDir, ".amaster-browser-session.json");
|
|
13149
|
-
if (!
|
|
13194
|
+
if (!existsSync14(userDataDir) || lstatSync7(userDataDir).isSymbolicLink() || !lstatSync7(userDataDir).isDirectory() || !existsSync14(markerPath) || lstatSync7(markerPath).isSymbolicLink()) throw new Error("source_acquisition_browser_profile_invalid");
|
|
13150
13195
|
const marker = readJsonFile2(markerPath);
|
|
13151
13196
|
if (marker.version !== 1 || marker.companyId !== companyId || marker.bindingId !== bindingId || marker.localOpaqueRef !== localOpaqueRef || !readString(marker.provider) || marker.origin !== exactOrigin || Object.keys(marker).length !== 6) {
|
|
13152
13197
|
throw new Error("source_acquisition_browser_profile_invalid");
|
|
@@ -13205,7 +13250,7 @@ function safeAgentInstructionMaterializationTarget(workspace, filePath) {
|
|
|
13205
13250
|
const raw = readString(filePath);
|
|
13206
13251
|
if (!raw || raw.includes("\0")) return null;
|
|
13207
13252
|
const normalized = raw.replace(/\\/g, "/");
|
|
13208
|
-
if (
|
|
13253
|
+
if (isAbsolute8(normalized)) return null;
|
|
13209
13254
|
const segments = normalized.split("/").filter(Boolean);
|
|
13210
13255
|
if (segments.length === 0 || segments.some((segment) => segment === "." || segment === "..")) return null;
|
|
13211
13256
|
const relativePath = segments.join("/");
|
|
@@ -13255,7 +13300,7 @@ function wikiTreePathForCommand(command, workspaceBindings) {
|
|
|
13255
13300
|
}
|
|
13256
13301
|
for (const candidate of candidates) {
|
|
13257
13302
|
try {
|
|
13258
|
-
if (
|
|
13303
|
+
if (existsSync14(candidate)) return candidate;
|
|
13259
13304
|
} catch {
|
|
13260
13305
|
}
|
|
13261
13306
|
}
|
|
@@ -14059,7 +14104,7 @@ function realOrResolvedPath(value) {
|
|
|
14059
14104
|
return resolve11(value);
|
|
14060
14105
|
}
|
|
14061
14106
|
}
|
|
14062
|
-
var LSOF_COMMAND = process.platform === "darwin" &&
|
|
14107
|
+
var LSOF_COMMAND = process.platform === "darwin" && existsSync14("/usr/sbin/lsof") ? "/usr/sbin/lsof" : "lsof";
|
|
14063
14108
|
function processCwdForPid(pid) {
|
|
14064
14109
|
if (process.platform === "linux") {
|
|
14065
14110
|
try {
|
|
@@ -14181,7 +14226,7 @@ function killWorkspaceResidentProcesses(cwd, processGroupId, options = {}) {
|
|
|
14181
14226
|
}
|
|
14182
14227
|
function walkManagedWorkdirs(root) {
|
|
14183
14228
|
const workdirs = [];
|
|
14184
|
-
if (!root || !
|
|
14229
|
+
if (!root || !existsSync14(root)) return workdirs;
|
|
14185
14230
|
const stack = [root];
|
|
14186
14231
|
while (stack.length > 0) {
|
|
14187
14232
|
const current = stack.pop();
|
|
@@ -14195,7 +14240,7 @@ function walkManagedWorkdirs(root) {
|
|
|
14195
14240
|
for (const entry of entries) {
|
|
14196
14241
|
if (!entry.isDirectory()) continue;
|
|
14197
14242
|
const fullPath = join15(current, entry.name);
|
|
14198
|
-
if (entry.name === "workdir" &&
|
|
14243
|
+
if (entry.name === "workdir" && existsSync14(workspaceManifestPath(fullPath))) {
|
|
14199
14244
|
workdirs.push(fullPath);
|
|
14200
14245
|
continue;
|
|
14201
14246
|
}
|
|
@@ -14234,7 +14279,7 @@ function manifestMatchesActiveRuntimeRef(manifest, refs, workdir = null) {
|
|
|
14234
14279
|
function buildOrphanReaperSample(root, workdir, manifest, residents) {
|
|
14235
14280
|
const relativeWorkdir = (() => {
|
|
14236
14281
|
const value = relative7(root, workdir);
|
|
14237
|
-
return value && !value.startsWith("..") && !
|
|
14282
|
+
return value && !value.startsWith("..") && !isAbsolute8(value) ? value : basename6(workdir);
|
|
14238
14283
|
})();
|
|
14239
14284
|
return {
|
|
14240
14285
|
workdir: relativeWorkdir,
|
|
@@ -14345,10 +14390,12 @@ function runExecutor(command, args, options) {
|
|
|
14345
14390
|
const maxRssBytes = maxRssMb * 1024 * 1024;
|
|
14346
14391
|
const managedInputs = sourceAcquisitionManagedInputs(options);
|
|
14347
14392
|
const spawnIdentity = asRecord(options.spawnIdentity);
|
|
14348
|
-
const
|
|
14393
|
+
const executable = process.platform === "win32" ? resolveExecutorCommand(command, options.env) ?? command : command;
|
|
14394
|
+
const child = spawn(executable, args, {
|
|
14349
14395
|
cwd: options.cwd,
|
|
14350
14396
|
env: options.env,
|
|
14351
14397
|
detached: process.platform !== "win32",
|
|
14398
|
+
...isWindowsCommandShim(executable) ? { shell: true } : {},
|
|
14352
14399
|
stdio: sourceAcquisitionManagedStdio(managedInputs),
|
|
14353
14400
|
...Number.isSafeInteger(spawnIdentity.uid) && Number.isSafeInteger(spawnIdentity.gid) ? { uid: spawnIdentity.uid, gid: spawnIdentity.gid } : {}
|
|
14354
14401
|
});
|
|
@@ -15699,7 +15746,7 @@ async function flushRunCompletionStates(config) {
|
|
|
15699
15746
|
for (const { filePath, state: listedState } of runCompletionStateEntries(config)) {
|
|
15700
15747
|
try {
|
|
15701
15748
|
if (runCompletionFlights.has(listedState.commandId)) continue;
|
|
15702
|
-
if (!
|
|
15749
|
+
if (!existsSync14(filePath)) continue;
|
|
15703
15750
|
const state = readValidRunCompletionStateOrQuarantine(config, filePath);
|
|
15704
15751
|
if (!state) continue;
|
|
15705
15752
|
const outcome = await coordinateRunCompletionSingleFlight(config, state);
|
|
@@ -15990,7 +16037,7 @@ function quarantineResultOutboxEntry(config, fullPath, file, entry, reason, err)
|
|
|
15990
16037
|
}
|
|
15991
16038
|
async function flushResultOutbox(config) {
|
|
15992
16039
|
const dir = resultOutboxDir(config);
|
|
15993
|
-
if (!
|
|
16040
|
+
if (!existsSync14(dir)) return { attempted: 0, completed: 0 };
|
|
15994
16041
|
const files = readdirSync10(dir).filter((name) => name.endsWith(".json")).sort();
|
|
15995
16042
|
let completed = 0;
|
|
15996
16043
|
for (const file of files) {
|
|
@@ -16358,14 +16405,14 @@ function issueCheckpointDir(workspace) {
|
|
|
16358
16405
|
}
|
|
16359
16406
|
async function clearIssueCheckpoint(config, command, workspace, reason) {
|
|
16360
16407
|
const checkpointDir = issueCheckpointDir(workspace);
|
|
16361
|
-
if (!
|
|
16408
|
+
if (!existsSync14(checkpointDir)) return false;
|
|
16362
16409
|
rmSync8(checkpointDir, { recursive: true, force: true });
|
|
16363
16410
|
await ingestLog(config, command, "system", "info", "Cleared issue continuation checkpoint", { reason });
|
|
16364
16411
|
return true;
|
|
16365
16412
|
}
|
|
16366
16413
|
function safeCheckpointRelativePath(rawPath) {
|
|
16367
16414
|
const raw = String(rawPath ?? "").trim();
|
|
16368
|
-
if (
|
|
16415
|
+
if (isAbsolute8(raw) || /^[A-Za-z]:[\\/]/.test(raw)) return null;
|
|
16369
16416
|
const normalized = raw.split(/[\\/]+/).filter(Boolean).join("/");
|
|
16370
16417
|
if (!normalized || normalized.startsWith("../") || normalized.split("/").some((segment) => segment.startsWith("."))) return null;
|
|
16371
16418
|
if (normalized.startsWith("input-attachments/") || isRuntimeMetadataArtifactPath(normalized)) return null;
|
|
@@ -16377,7 +16424,7 @@ function hashFileSha256(filePath) {
|
|
|
16377
16424
|
async function materializeIssueCheckpoint(config, command, workspace) {
|
|
16378
16425
|
const checkpointDir = issueCheckpointDir(workspace);
|
|
16379
16426
|
const manifestPath = join15(checkpointDir, "manifest.json");
|
|
16380
|
-
if (!
|
|
16427
|
+
if (!existsSync14(manifestPath)) return [];
|
|
16381
16428
|
let manifest;
|
|
16382
16429
|
try {
|
|
16383
16430
|
manifest = asRecord(JSON.parse(readFileSync13(manifestPath, "utf8")));
|
|
@@ -16406,7 +16453,7 @@ async function materializeIssueCheckpoint(config, command, workspace) {
|
|
|
16406
16453
|
if (!pathWithin2(sourceCandidate, filesRoot) || !pathWithin2(target, workspaceRoot)) {
|
|
16407
16454
|
throw new Error(`issue checkpoint path escapes its workspace: ${relativePath}`);
|
|
16408
16455
|
}
|
|
16409
|
-
if (!
|
|
16456
|
+
if (!existsSync14(sourceCandidate)) throw new Error(`issue checkpoint file is missing: ${relativePath}`);
|
|
16410
16457
|
const source = realpathSync5(sourceCandidate);
|
|
16411
16458
|
if (!pathWithin2(source, filesRoot) || !statSync9(source).isFile()) {
|
|
16412
16459
|
throw new Error(`issue checkpoint source escapes its storage root: ${relativePath}`);
|
|
@@ -16469,7 +16516,7 @@ async function saveIssueCheckpoint(config, command, workspace, candidates) {
|
|
|
16469
16516
|
for (const candidate of candidates.slice(0, 20)) {
|
|
16470
16517
|
const relativePath = safeCheckpointRelativePath(candidate.rawPath);
|
|
16471
16518
|
const source = readString(candidate.filePath);
|
|
16472
|
-
if (!relativePath || !source || !
|
|
16519
|
+
if (!relativePath || !source || !existsSync14(source) || !statSync9(source).isFile()) continue;
|
|
16473
16520
|
const ownedSource = realpathSync5(source);
|
|
16474
16521
|
if (!pathWithin2(ownedSource, workspaceRoot)) {
|
|
16475
16522
|
throw new Error(`issue checkpoint source escapes its execution workspace: ${relativePath}`);
|