@cortexkit/aft 0.53.0 → 0.55.0
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/index.js
CHANGED
|
@@ -517,8 +517,65 @@ var CONFLICT_HINT = `
|
|
|
517
517
|
[Hint] Use aft_conflicts to see all conflict regions across files in a single call.`, GREP_SEARCH_AFT_SEARCH_HINT = "DO NOT search code by running grep/rg in bash — it is unindexed, unranked, and serial. Use the `aft_search` tool instead (it auto-routes concepts, identifiers, regex, and literals).", GREP_SEARCH_GREP_HINT = "DO NOT search code by running grep/rg in bash — it is unindexed, unranked, and serial. Use the `grep` tool instead (indexed and ranked).", GREP_SEARCH_HINT_PREFIX = "DO NOT search code by running grep/rg in bash —", GREP_SEARCH_FRESHNESS_WINDOW_MS = 60000;
|
|
518
518
|
var init_bash_hints = () => {};
|
|
519
519
|
|
|
520
|
+
// ../aft-bridge/dist/storage-paths.js
|
|
521
|
+
import { homedir as homedir2 } from "node:os";
|
|
522
|
+
import { join as join2, resolve as resolve2 } from "node:path";
|
|
523
|
+
function homeDir() {
|
|
524
|
+
if (process.platform === "win32")
|
|
525
|
+
return process.env.USERPROFILE || process.env.HOME || homedir2();
|
|
526
|
+
return process.env.HOME || homedir2();
|
|
527
|
+
}
|
|
528
|
+
function dataHome() {
|
|
529
|
+
const xdg = process.env.XDG_DATA_HOME;
|
|
530
|
+
if (xdg)
|
|
531
|
+
return xdg;
|
|
532
|
+
if (process.platform === "win32") {
|
|
533
|
+
return process.env.LOCALAPPDATA || process.env.APPDATA || join2(homeDir(), "AppData", "Local");
|
|
534
|
+
}
|
|
535
|
+
return join2(homeDir(), ".local", "share");
|
|
536
|
+
}
|
|
537
|
+
function resolveStoragePath(raw) {
|
|
538
|
+
let expanded = raw;
|
|
539
|
+
if (raw === "~") {
|
|
540
|
+
expanded = homeDir();
|
|
541
|
+
} else if (raw.startsWith("~/") || raw.startsWith("~\\")) {
|
|
542
|
+
expanded = join2(homeDir(), raw.slice(2));
|
|
543
|
+
}
|
|
544
|
+
return resolve2(expanded);
|
|
545
|
+
}
|
|
546
|
+
function resolveCortexKitStorageRoot() {
|
|
547
|
+
const override = process.env.AFT_STORAGE_DIR;
|
|
548
|
+
if (override)
|
|
549
|
+
return resolveStoragePath(override);
|
|
550
|
+
return resolveStoragePath(join2(dataHome(), "cortexkit", "aft"));
|
|
551
|
+
}
|
|
552
|
+
function resolveAftStorageRoot(configuredRoot) {
|
|
553
|
+
if (process.env.AFT_STORAGE_DIR)
|
|
554
|
+
return resolveCortexKitStorageRoot();
|
|
555
|
+
if (configuredRoot)
|
|
556
|
+
return configuredRoot;
|
|
557
|
+
return resolveCortexKitStorageRoot();
|
|
558
|
+
}
|
|
559
|
+
function resolveAftLogPath(filename, configuredRoot) {
|
|
560
|
+
return join2(resolveAftStorageRoot(configuredRoot), "logs", filename);
|
|
561
|
+
}
|
|
562
|
+
var init_storage_paths = () => {};
|
|
563
|
+
|
|
520
564
|
// ../aft-bridge/dist/bash-host-fallback.js
|
|
521
565
|
import { spawn } from "node:child_process";
|
|
566
|
+
import { existsSync } from "node:fs";
|
|
567
|
+
import { delimiter, join as join3 } from "node:path";
|
|
568
|
+
function hostFallbackPathWithShims(env) {
|
|
569
|
+
const storageRoot = env.AFT_STORAGE_DIR ? resolveStoragePath(env.AFT_STORAGE_DIR) : resolveCortexKitStorageRoot();
|
|
570
|
+
const shimsDir = join3(storageRoot, "shims");
|
|
571
|
+
if (!existsSync(join3(shimsDir, "gh")))
|
|
572
|
+
return env.PATH;
|
|
573
|
+
const inherited = env.PATH ?? "";
|
|
574
|
+
const entries = inherited.split(delimiter).filter((entry) => entry.length > 0);
|
|
575
|
+
if (entries[0] === shimsDir)
|
|
576
|
+
return inherited;
|
|
577
|
+
return [shimsDir, ...entries.filter((entry) => entry !== shimsDir)].join(delimiter);
|
|
578
|
+
}
|
|
522
579
|
function bashHostFallbackAskPattern(command, cwd) {
|
|
523
580
|
return `AFT UNAVAILABLE - host fallback execution:
|
|
524
581
|
|
|
@@ -551,11 +608,17 @@ async function runBashHostFallback(options) {
|
|
|
551
608
|
if (options.signal?.aborted) {
|
|
552
609
|
throw new DOMException("The host fallback command was aborted", "AbortError");
|
|
553
610
|
}
|
|
554
|
-
return await new Promise((
|
|
611
|
+
return await new Promise((resolve3, reject) => {
|
|
555
612
|
const child = spawn(options.command, {
|
|
556
613
|
cwd: options.projectRoot,
|
|
557
614
|
shell: true,
|
|
558
|
-
env:
|
|
615
|
+
env: (() => {
|
|
616
|
+
const merged = { ...process.env, ...options.env };
|
|
617
|
+
const path2 = hostFallbackPathWithShims(merged);
|
|
618
|
+
if (path2 !== undefined)
|
|
619
|
+
merged.PATH = path2;
|
|
620
|
+
return merged;
|
|
621
|
+
})(),
|
|
559
622
|
stdio: ["ignore", "pipe", "pipe"],
|
|
560
623
|
detached: process.platform !== "win32",
|
|
561
624
|
windowsHide: true
|
|
@@ -618,7 +681,7 @@ async function runBashHostFallback(options) {
|
|
|
618
681
|
return;
|
|
619
682
|
}
|
|
620
683
|
const exitCode = timedOut ? 124 : code ?? 1;
|
|
621
|
-
|
|
684
|
+
resolve3({
|
|
622
685
|
success: true,
|
|
623
686
|
output: renderOutput(Buffer.concat(chunks), exitCode),
|
|
624
687
|
exit_code: exitCode,
|
|
@@ -629,6 +692,7 @@ async function runBashHostFallback(options) {
|
|
|
629
692
|
}
|
|
630
693
|
var BASH_HOST_FALLBACK_BANNER = "[AFT host fallback - module transport down; no rewrites/compression/background]", BASH_HOST_FALLBACK_MAX_OUTPUT_BYTES, BASH_HOST_FALLBACK_MAX_TIMEOUT_MS, BASH_HOST_FALLBACK_REFUSAL = "AFT transport is down; only foreground execution is available in host fallback";
|
|
631
694
|
var init_bash_host_fallback = __esm(() => {
|
|
695
|
+
init_storage_paths();
|
|
632
696
|
BASH_HOST_FALLBACK_MAX_OUTPUT_BYTES = 100 * 1024;
|
|
633
697
|
BASH_HOST_FALLBACK_MAX_TIMEOUT_MS = 10 * 60 * 1000;
|
|
634
698
|
});
|
|
@@ -670,8 +734,8 @@ var init_command_timeouts = __esm(() => {
|
|
|
670
734
|
import { spawn as spawn2 } from "node:child_process";
|
|
671
735
|
import { createHash } from "node:crypto";
|
|
672
736
|
import { readFileSync } from "node:fs";
|
|
673
|
-
import { homedir as
|
|
674
|
-
import { join as
|
|
737
|
+
import { homedir as homedir3 } from "node:os";
|
|
738
|
+
import { join as join4 } from "node:path";
|
|
675
739
|
import { StringDecoder } from "node:string_decoder";
|
|
676
740
|
function isTerminalBashStatus(status) {
|
|
677
741
|
return typeof status === "string" && TERMINAL_BASH_STATUSES.has(status);
|
|
@@ -1046,6 +1110,21 @@ var init_bridge = __esm(() => {
|
|
|
1046
1110
|
}
|
|
1047
1111
|
return this.sendWithVersionMismatchRetry(command, dispatchParams, options, true);
|
|
1048
1112
|
}
|
|
1113
|
+
listenForRequestAbort(requestId, signal) {
|
|
1114
|
+
if (!signal)
|
|
1115
|
+
return () => {};
|
|
1116
|
+
let fired = false;
|
|
1117
|
+
const onAbort = () => {
|
|
1118
|
+
if (fired)
|
|
1119
|
+
return;
|
|
1120
|
+
fired = true;
|
|
1121
|
+
this.send("cancel_request", { id: requestId }, { keepBridgeOnTimeout: true }).catch(() => {});
|
|
1122
|
+
};
|
|
1123
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
1124
|
+
if (signal.aborted)
|
|
1125
|
+
onAbort();
|
|
1126
|
+
return () => signal.removeEventListener("abort", onAbort);
|
|
1127
|
+
}
|
|
1049
1128
|
async toolCall(sessionId, name, rawArgs = {}, options) {
|
|
1050
1129
|
const params = { name, arguments: rawArgs };
|
|
1051
1130
|
if (sessionId)
|
|
@@ -1068,7 +1147,7 @@ var init_bridge = __esm(() => {
|
|
|
1068
1147
|
if (this._shuttingDown) {
|
|
1069
1148
|
throw new BridgeTransportUnavailableError(`${this.errorPrefix} Bridge is shutting down, cannot send "${command}"`);
|
|
1070
1149
|
}
|
|
1071
|
-
if (Object.hasOwn(params, "id")) {
|
|
1150
|
+
if (Object.hasOwn(params, "id") && command !== "cancel_request") {
|
|
1072
1151
|
throw new Error("params cannot contain reserved key 'id'");
|
|
1073
1152
|
}
|
|
1074
1153
|
const requestSessionId = typeof params.session_id === "string" && params.session_id.length > 0 ? params.session_id : undefined;
|
|
@@ -1122,7 +1201,7 @@ var init_bridge = __esm(() => {
|
|
|
1122
1201
|
}
|
|
1123
1202
|
const id = String(this.nextId++);
|
|
1124
1203
|
let request;
|
|
1125
|
-
if (Object.hasOwn(params, "command") || Object.hasOwn(params, "method")) {
|
|
1204
|
+
if (command === "cancel_request" || Object.hasOwn(params, "command") || Object.hasOwn(params, "method")) {
|
|
1126
1205
|
const nested = { ...params };
|
|
1127
1206
|
const reserved = {};
|
|
1128
1207
|
for (const key of ["session_id", "lsp_hints"]) {
|
|
@@ -1140,13 +1219,14 @@ var init_bridge = __esm(() => {
|
|
|
1140
1219
|
const keepBridgeOnTimeout = passive || options?.keepBridgeOnTimeout === true;
|
|
1141
1220
|
let requestSentAt = Date.now();
|
|
1142
1221
|
const child = this.process;
|
|
1143
|
-
const response = await new Promise((
|
|
1222
|
+
const response = await new Promise((resolve3, reject) => {
|
|
1144
1223
|
const timer = setTimeout(() => {
|
|
1145
|
-
const
|
|
1146
|
-
if (!
|
|
1224
|
+
const entry2 = this.pending.get(id);
|
|
1225
|
+
if (!entry2)
|
|
1147
1226
|
return;
|
|
1148
1227
|
this.pending.delete(id);
|
|
1149
|
-
clearTimeout(
|
|
1228
|
+
clearTimeout(entry2.timer);
|
|
1229
|
+
entry2.onSettled?.();
|
|
1150
1230
|
if (keepBridgeOnTimeout) {
|
|
1151
1231
|
const timeoutMsg2 = `Request "${command}" (id=${id}) timed out after ${effectiveTimeoutMs}ms`;
|
|
1152
1232
|
if (requestSessionId) {
|
|
@@ -1154,7 +1234,7 @@ var init_bridge = __esm(() => {
|
|
|
1154
1234
|
} else {
|
|
1155
1235
|
this.warnVia(timeoutMsg2);
|
|
1156
1236
|
}
|
|
1157
|
-
|
|
1237
|
+
entry2.reject(new BridgeTransportTimeoutError(command, effectiveTimeoutMs, `${this.errorPrefix} Request "${command}" (id=${id}) timed out after ${effectiveTimeoutMs}ms`));
|
|
1158
1238
|
return;
|
|
1159
1239
|
}
|
|
1160
1240
|
const childActiveSinceRequest = this.lastChildActivityAt > requestSentAt;
|
|
@@ -1169,13 +1249,20 @@ var init_bridge = __esm(() => {
|
|
|
1169
1249
|
this.warnVia(timeoutMsg);
|
|
1170
1250
|
}
|
|
1171
1251
|
if (keepWarm) {
|
|
1172
|
-
|
|
1252
|
+
entry2.reject(new Error(`${this.errorPrefix} request "${command}" timed out after ${effectiveTimeoutMs}ms (bridge busy/under load); bridge kept warm — retry`));
|
|
1173
1253
|
return;
|
|
1174
1254
|
}
|
|
1175
|
-
|
|
1255
|
+
entry2.reject(new Error(`${this.errorPrefix} Request "${command}" (id=${id}) timed out after ${effectiveTimeoutMs}ms`));
|
|
1176
1256
|
this.handleTimeout(requestSessionId);
|
|
1177
1257
|
}, effectiveTimeoutMs);
|
|
1178
|
-
|
|
1258
|
+
const entry = {
|
|
1259
|
+
resolve: resolve3,
|
|
1260
|
+
reject,
|
|
1261
|
+
timer,
|
|
1262
|
+
onProgress: options?.onProgress,
|
|
1263
|
+
command
|
|
1264
|
+
};
|
|
1265
|
+
this.pending.set(id, entry);
|
|
1179
1266
|
if (!child?.stdin?.writable) {
|
|
1180
1267
|
this.pending.delete(id);
|
|
1181
1268
|
clearTimeout(timer);
|
|
@@ -1189,11 +1276,12 @@ var init_bridge = __esm(() => {
|
|
|
1189
1276
|
const handleWriteFailure = (cause) => {
|
|
1190
1277
|
const writeError = cause instanceof Error ? cause : new Error(String(cause));
|
|
1191
1278
|
const error2 = new BridgeTransportUnknownOutcomeError(`${this.errorPrefix} Failed to write to stdin: ${writeError.message}`, { cause: writeError });
|
|
1192
|
-
const
|
|
1193
|
-
if (
|
|
1279
|
+
const entry2 = this.pending.get(id);
|
|
1280
|
+
if (entry2) {
|
|
1194
1281
|
this.pending.delete(id);
|
|
1195
|
-
clearTimeout(
|
|
1196
|
-
|
|
1282
|
+
clearTimeout(entry2.timer);
|
|
1283
|
+
entry2.onSettled?.();
|
|
1284
|
+
entry2.reject(error2);
|
|
1197
1285
|
}
|
|
1198
1286
|
if (this.process === child)
|
|
1199
1287
|
this.invalidateTransportProcess(error2);
|
|
@@ -1206,6 +1294,9 @@ var init_bridge = __esm(() => {
|
|
|
1206
1294
|
} catch (err) {
|
|
1207
1295
|
handleWriteFailure(err);
|
|
1208
1296
|
}
|
|
1297
|
+
if (this.pending.has(id)) {
|
|
1298
|
+
entry.onSettled = this.listenForRequestAbort(id, options?.abortSignal);
|
|
1299
|
+
}
|
|
1209
1300
|
});
|
|
1210
1301
|
if (command === "configure" && response.success === true && options?.markConfiguredOnSuccess !== false) {
|
|
1211
1302
|
this.configured = true;
|
|
@@ -1293,15 +1384,15 @@ var init_bridge = __esm(() => {
|
|
|
1293
1384
|
if (this.process) {
|
|
1294
1385
|
const proc = this.process;
|
|
1295
1386
|
this.process = null;
|
|
1296
|
-
return new Promise((
|
|
1387
|
+
return new Promise((resolve3) => {
|
|
1297
1388
|
const forceKillTimer = setTimeout(() => {
|
|
1298
1389
|
proc.kill("SIGKILL");
|
|
1299
|
-
|
|
1390
|
+
resolve3();
|
|
1300
1391
|
}, 5000);
|
|
1301
1392
|
proc.once("exit", () => {
|
|
1302
1393
|
clearTimeout(forceKillTimer);
|
|
1303
1394
|
this.logVia("Process exited during shutdown");
|
|
1304
|
-
|
|
1395
|
+
resolve3();
|
|
1305
1396
|
});
|
|
1306
1397
|
proc.kill("SIGTERM");
|
|
1307
1398
|
});
|
|
@@ -1349,15 +1440,15 @@ var init_bridge = __esm(() => {
|
|
|
1349
1440
|
return;
|
|
1350
1441
|
const proc = this.process;
|
|
1351
1442
|
this.process = null;
|
|
1352
|
-
await new Promise((
|
|
1443
|
+
await new Promise((resolve3) => {
|
|
1353
1444
|
const forceKillTimer = setTimeout(() => {
|
|
1354
1445
|
proc.kill("SIGKILL");
|
|
1355
|
-
|
|
1446
|
+
resolve3();
|
|
1356
1447
|
}, 5000);
|
|
1357
1448
|
proc.once("exit", () => {
|
|
1358
1449
|
clearTimeout(forceKillTimer);
|
|
1359
1450
|
this.logVia("Process exited during coordinated binary replacement");
|
|
1360
|
-
|
|
1451
|
+
resolve3();
|
|
1361
1452
|
});
|
|
1362
1453
|
proc.kill("SIGTERM");
|
|
1363
1454
|
});
|
|
@@ -1387,7 +1478,7 @@ var init_bridge = __esm(() => {
|
|
|
1387
1478
|
})();
|
|
1388
1479
|
const useFastembedBackend = semanticBackend === undefined || semanticBackend === "fastembed" || semanticBackend === "";
|
|
1389
1480
|
const ortDir = typeof this.configOverrides._ort_dylib_dir === "string" && useFastembedBackend ? this.configOverrides._ort_dylib_dir : null;
|
|
1390
|
-
const ortLibraryPath = ortDir == null ? null :
|
|
1481
|
+
const ortLibraryPath = ortDir == null ? null : join4(ortDir, process.platform === "win32" ? "onnxruntime.dll" : process.platform === "darwin" ? "libonnxruntime.dylib" : "libonnxruntime.so");
|
|
1391
1482
|
const envPath = process.platform === "win32" && ortDir ? `${ortDir};${process.env.PATH ?? ""}` : process.env.PATH;
|
|
1392
1483
|
const env = {
|
|
1393
1484
|
...process.env,
|
|
@@ -1395,7 +1486,7 @@ var init_bridge = __esm(() => {
|
|
|
1395
1486
|
};
|
|
1396
1487
|
this.logVia(`bridge.spawnProcess: useFastembedBackend=${useFastembedBackend}, ` + `parentORT=${process.env.ORT_DYLIB_PATH ?? "(unset)"}, ` + `ortLibraryPath=${ortLibraryPath ?? "(none)"}`);
|
|
1397
1488
|
if (useFastembedBackend) {
|
|
1398
|
-
env.FASTEMBED_CACHE_DIR = process.env.FASTEMBED_CACHE_DIR || (typeof this.configOverrides.storage_dir === "string" ?
|
|
1489
|
+
env.FASTEMBED_CACHE_DIR = process.env.FASTEMBED_CACHE_DIR || (typeof this.configOverrides.storage_dir === "string" ? join4(this.configOverrides.storage_dir, "semantic", "models") : join4(homedir3() || "", ".cache", "fastembed"));
|
|
1399
1490
|
if (process.env.ORT_DYLIB_PATH) {
|
|
1400
1491
|
this.logVia(`ORT_DYLIB_PATH inherited from parent env: ${process.env.ORT_DYLIB_PATH}`);
|
|
1401
1492
|
} else if (ortLibraryPath) {
|
|
@@ -1574,6 +1665,7 @@ var init_bridge = __esm(() => {
|
|
|
1574
1665
|
if (requestId && entry) {
|
|
1575
1666
|
this.pending.delete(requestId);
|
|
1576
1667
|
clearTimeout(entry.timer);
|
|
1668
|
+
entry.onSettled?.();
|
|
1577
1669
|
entry.resolve({
|
|
1578
1670
|
success: false,
|
|
1579
1671
|
code: "permission_required",
|
|
@@ -1615,6 +1707,7 @@ var init_bridge = __esm(() => {
|
|
|
1615
1707
|
return;
|
|
1616
1708
|
this.pending.delete(id);
|
|
1617
1709
|
clearTimeout(entry.timer);
|
|
1710
|
+
entry.onSettled?.();
|
|
1618
1711
|
this.consecutiveRequestTimeouts = 0;
|
|
1619
1712
|
this.scheduleRestartCountReset();
|
|
1620
1713
|
this.accountForBashTaskResponse(entry.command, response);
|
|
@@ -1705,6 +1798,7 @@ var init_bridge = __esm(() => {
|
|
|
1705
1798
|
rejectAllPending(error2) {
|
|
1706
1799
|
for (const [_id, entry] of this.pending) {
|
|
1707
1800
|
clearTimeout(entry.timer);
|
|
1801
|
+
entry.onSettled?.();
|
|
1708
1802
|
entry.reject(error2);
|
|
1709
1803
|
}
|
|
1710
1804
|
this.pending.clear();
|
|
@@ -1726,34 +1820,40 @@ var init_bridge = __esm(() => {
|
|
|
1726
1820
|
});
|
|
1727
1821
|
|
|
1728
1822
|
// ../aft-bridge/dist/cache-paths.js
|
|
1729
|
-
import { homedir as
|
|
1730
|
-
import { join as
|
|
1731
|
-
function
|
|
1732
|
-
return (process.platform === "win32" ? env.USERPROFILE || env.HOME : env.HOME) ||
|
|
1823
|
+
import { homedir as homedir4 } from "node:os";
|
|
1824
|
+
import { join as join5 } from "node:path";
|
|
1825
|
+
function homeDir2(env) {
|
|
1826
|
+
return (process.platform === "win32" ? env.USERPROFILE || env.HOME : env.HOME) || homedir4();
|
|
1827
|
+
}
|
|
1828
|
+
function getOpenCodeCacheRoot(env = process.env, home = homedir4()) {
|
|
1829
|
+
return join5(env.XDG_CACHE_HOME || join5(home, ".cache"), "opencode");
|
|
1830
|
+
}
|
|
1831
|
+
function getOpenCodeConfigRoot(env = process.env, home = homedir4()) {
|
|
1832
|
+
return join5(env.XDG_CONFIG_HOME || join5(home, ".config"), "opencode");
|
|
1733
1833
|
}
|
|
1734
1834
|
function getAftCacheRoot(env = process.env) {
|
|
1735
1835
|
if (env.AFT_CACHE_DIR)
|
|
1736
1836
|
return env.AFT_CACHE_DIR;
|
|
1737
1837
|
if (process.platform === "win32") {
|
|
1738
|
-
const base2 = env.LOCALAPPDATA || env.APPDATA ||
|
|
1739
|
-
return
|
|
1838
|
+
const base2 = env.LOCALAPPDATA || env.APPDATA || join5(homeDir2(env), "AppData", "Local");
|
|
1839
|
+
return join5(base2, "aft");
|
|
1740
1840
|
}
|
|
1741
|
-
const base = env.XDG_CACHE_HOME ||
|
|
1742
|
-
return
|
|
1841
|
+
const base = env.XDG_CACHE_HOME || join5(homeDir2(env), ".cache");
|
|
1842
|
+
return join5(base, "aft");
|
|
1743
1843
|
}
|
|
1744
1844
|
function getAftBinaryCacheDir(env = process.env) {
|
|
1745
|
-
return
|
|
1845
|
+
return join5(getAftCacheRoot(env), "bin");
|
|
1746
1846
|
}
|
|
1747
1847
|
function getAftLspPackagesDir(env = process.env) {
|
|
1748
|
-
return
|
|
1848
|
+
return join5(getAftCacheRoot(env), "lsp-packages");
|
|
1749
1849
|
}
|
|
1750
1850
|
function getAftLspBinariesDir(env = process.env) {
|
|
1751
|
-
return
|
|
1851
|
+
return join5(getAftCacheRoot(env), "lsp-binaries");
|
|
1752
1852
|
}
|
|
1753
1853
|
var init_cache_paths = () => {};
|
|
1754
1854
|
|
|
1755
1855
|
// ../aft-bridge/dist/callgraph-format.js
|
|
1756
|
-
import { homedir as
|
|
1856
|
+
import { homedir as homedir5 } from "node:os";
|
|
1757
1857
|
function asRecord(value) {
|
|
1758
1858
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
1759
1859
|
return;
|
|
@@ -1772,7 +1872,7 @@ function asBoolean(value) {
|
|
|
1772
1872
|
return typeof value === "boolean" ? value : undefined;
|
|
1773
1873
|
}
|
|
1774
1874
|
function shortenPath(path2) {
|
|
1775
|
-
const home =
|
|
1875
|
+
const home = homedir5();
|
|
1776
1876
|
if (path2.startsWith(home))
|
|
1777
1877
|
return `~${path2.slice(home.length)}`;
|
|
1778
1878
|
return path2;
|
|
@@ -2140,26 +2240,26 @@ var init_config_keys = __esm(() => {
|
|
|
2140
2240
|
});
|
|
2141
2241
|
|
|
2142
2242
|
// ../aft-bridge/dist/config-tiers.js
|
|
2143
|
-
import { existsSync, readFileSync as readFileSync2 } from "node:fs";
|
|
2144
|
-
import { resolve as
|
|
2243
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "node:fs";
|
|
2244
|
+
import { resolve as resolve3 } from "node:path";
|
|
2145
2245
|
function readConfigTiers(opts) {
|
|
2146
2246
|
const tiers = [];
|
|
2147
2247
|
try {
|
|
2148
|
-
if (
|
|
2248
|
+
if (existsSync2(opts.userConfigPath)) {
|
|
2149
2249
|
const doc = readFileSync2(opts.userConfigPath, "utf-8");
|
|
2150
2250
|
tiers.push({
|
|
2151
2251
|
tier: "user",
|
|
2152
|
-
source:
|
|
2252
|
+
source: resolve3(opts.userConfigPath),
|
|
2153
2253
|
doc
|
|
2154
2254
|
});
|
|
2155
2255
|
}
|
|
2156
2256
|
} catch {}
|
|
2157
2257
|
try {
|
|
2158
|
-
if (
|
|
2258
|
+
if (existsSync2(opts.projectConfigPath)) {
|
|
2159
2259
|
const doc = readFileSync2(opts.projectConfigPath, "utf-8");
|
|
2160
2260
|
tiers.push({
|
|
2161
2261
|
tier: "project",
|
|
2162
|
-
source:
|
|
2262
|
+
source: resolve3(opts.projectConfigPath),
|
|
2163
2263
|
doc
|
|
2164
2264
|
});
|
|
2165
2265
|
}
|
|
@@ -2198,9 +2298,9 @@ var init_platform = __esm(() => {
|
|
|
2198
2298
|
// ../aft-bridge/dist/downloader.js
|
|
2199
2299
|
import { spawnSync } from "node:child_process";
|
|
2200
2300
|
import { createHash as createHash2, randomUUID } from "node:crypto";
|
|
2201
|
-
import { chmodSync, closeSync, copyFileSync, createWriteStream, existsSync as
|
|
2301
|
+
import { chmodSync, closeSync, copyFileSync, createWriteStream, existsSync as existsSync3, mkdirSync, openSync, readdirSync, readFileSync as readFileSync3, renameSync, rmSync, statSync as statSync2, unlinkSync, writeSync } from "node:fs";
|
|
2202
2302
|
import { hostname } from "node:os";
|
|
2203
|
-
import { join as
|
|
2303
|
+
import { join as join6 } from "node:path";
|
|
2204
2304
|
import { Readable } from "node:stream";
|
|
2205
2305
|
import { pipeline } from "node:stream/promises";
|
|
2206
2306
|
function readBinaryVersion(binaryPath) {
|
|
@@ -2237,8 +2337,8 @@ function getBinaryName() {
|
|
|
2237
2337
|
function getCachedBinaryPath(version) {
|
|
2238
2338
|
if (!version)
|
|
2239
2339
|
return null;
|
|
2240
|
-
const binaryPath =
|
|
2241
|
-
return
|
|
2340
|
+
const binaryPath = join6(getAftBinaryCacheDir(), version, getBinaryName());
|
|
2341
|
+
return existsSync3(binaryPath) ? binaryPath : null;
|
|
2242
2342
|
}
|
|
2243
2343
|
async function downloadBinary(version) {
|
|
2244
2344
|
const archMap = PLATFORM_ARCH_MAP[process.platform] ?? {};
|
|
@@ -2254,16 +2354,16 @@ async function downloadBinary(version) {
|
|
|
2254
2354
|
return null;
|
|
2255
2355
|
}
|
|
2256
2356
|
const tag = rawTag.startsWith("v") ? rawTag : `v${rawTag}`;
|
|
2257
|
-
const versionedCacheDir =
|
|
2357
|
+
const versionedCacheDir = join6(getAftBinaryCacheDir(), tag);
|
|
2258
2358
|
const binaryName = getBinaryName();
|
|
2259
|
-
const binaryPath =
|
|
2260
|
-
if (
|
|
2359
|
+
const binaryPath = join6(versionedCacheDir, binaryName);
|
|
2360
|
+
if (existsSync3(binaryPath) && isExpectedCachedBinary(binaryPath, tag)) {
|
|
2261
2361
|
return binaryPath;
|
|
2262
2362
|
}
|
|
2263
2363
|
const downloadUrl = `https://github.com/${REPO}/releases/download/${tag}/${assetName}`;
|
|
2264
2364
|
const checksumUrl = `https://github.com/${REPO}/releases/download/${tag}/checksums.sha256`;
|
|
2265
2365
|
log(`Downloading AFT binary (${tag}) for ${platformKey}...`);
|
|
2266
|
-
const lockPath =
|
|
2366
|
+
const lockPath = join6(versionedCacheDir, ".download.lock");
|
|
2267
2367
|
let releaseLock = null;
|
|
2268
2368
|
let binaryController = null;
|
|
2269
2369
|
let checksumController = null;
|
|
@@ -2272,7 +2372,7 @@ async function downloadBinary(version) {
|
|
|
2272
2372
|
const tmpPath = `${binaryPath}.${process.pid}.${Date.now()}.${Math.random().toString(16).slice(2)}.tmp`;
|
|
2273
2373
|
const cleanUpPartialDownload = () => {
|
|
2274
2374
|
try {
|
|
2275
|
-
if (
|
|
2375
|
+
if (existsSync3(tmpPath))
|
|
2276
2376
|
unlinkSync(tmpPath);
|
|
2277
2377
|
} catch {}
|
|
2278
2378
|
};
|
|
@@ -2296,12 +2396,12 @@ async function downloadBinary(version) {
|
|
|
2296
2396
|
process.once("SIGINT", handleSigint);
|
|
2297
2397
|
process.once("exit", handleExit);
|
|
2298
2398
|
try {
|
|
2299
|
-
if (!
|
|
2399
|
+
if (!existsSync3(versionedCacheDir)) {
|
|
2300
2400
|
mkdirSync(versionedCacheDir, { recursive: true });
|
|
2301
2401
|
}
|
|
2302
2402
|
releaseLock = await acquireDownloadLock(lockPath);
|
|
2303
2403
|
sweepStaleDownloadTemps(versionedCacheDir, binaryName);
|
|
2304
|
-
if (
|
|
2404
|
+
if (existsSync3(binaryPath) && isExpectedCachedBinary(binaryPath, tag)) {
|
|
2305
2405
|
return binaryPath;
|
|
2306
2406
|
}
|
|
2307
2407
|
binaryController = new AbortController;
|
|
@@ -2366,7 +2466,7 @@ async function downloadBinary(version) {
|
|
|
2366
2466
|
renameSync(tmpPath, binaryPath);
|
|
2367
2467
|
}
|
|
2368
2468
|
try {
|
|
2369
|
-
if (
|
|
2469
|
+
if (existsSync3(tmpPath))
|
|
2370
2470
|
unlinkSync(tmpPath);
|
|
2371
2471
|
} catch {
|
|
2372
2472
|
warn(`Could not clean up temporary download file ${tmpPath} — it can be removed manually.`);
|
|
@@ -2481,7 +2581,7 @@ function sweepStaleDownloadTemps(versionedCacheDir, binaryName) {
|
|
|
2481
2581
|
if (!entry.isFile() || !entry.name.startsWith(tempPrefix) || !entry.name.endsWith(".tmp")) {
|
|
2482
2582
|
continue;
|
|
2483
2583
|
}
|
|
2484
|
-
const tempPath =
|
|
2584
|
+
const tempPath = join6(versionedCacheDir, entry.name);
|
|
2485
2585
|
const ageMs = Date.now() - statSync2(tempPath).mtimeMs;
|
|
2486
2586
|
if (Math.abs(ageMs) > DOWNLOAD_LOCK_STALE_MS)
|
|
2487
2587
|
unlinkSync(tempPath);
|
|
@@ -2530,7 +2630,7 @@ async function acquireDownloadLock(lockPath, timing = {}) {
|
|
|
2530
2630
|
if (Date.now() - startedAt > timeoutMs) {
|
|
2531
2631
|
throw new Error(`Timed out waiting for download lock: ${lockPath}`);
|
|
2532
2632
|
}
|
|
2533
|
-
await new Promise((
|
|
2633
|
+
await new Promise((resolve4) => setTimeout(resolve4, pollIntervalMs));
|
|
2534
2634
|
}
|
|
2535
2635
|
}
|
|
2536
2636
|
}
|
|
@@ -2577,50 +2677,6 @@ var init_downloader = __esm(() => {
|
|
|
2577
2677
|
ensureBinaryInFlight = new Map;
|
|
2578
2678
|
});
|
|
2579
2679
|
|
|
2580
|
-
// ../aft-bridge/dist/storage-paths.js
|
|
2581
|
-
import { homedir as homedir5 } from "node:os";
|
|
2582
|
-
import { join as join5, resolve as resolve3 } from "node:path";
|
|
2583
|
-
function homeDir2() {
|
|
2584
|
-
if (process.platform === "win32")
|
|
2585
|
-
return process.env.USERPROFILE || process.env.HOME || homedir5();
|
|
2586
|
-
return process.env.HOME || homedir5();
|
|
2587
|
-
}
|
|
2588
|
-
function dataHome() {
|
|
2589
|
-
const xdg = process.env.XDG_DATA_HOME;
|
|
2590
|
-
if (xdg)
|
|
2591
|
-
return xdg;
|
|
2592
|
-
if (process.platform === "win32") {
|
|
2593
|
-
return process.env.LOCALAPPDATA || process.env.APPDATA || join5(homeDir2(), "AppData", "Local");
|
|
2594
|
-
}
|
|
2595
|
-
return join5(homeDir2(), ".local", "share");
|
|
2596
|
-
}
|
|
2597
|
-
function resolveStoragePath(raw) {
|
|
2598
|
-
let expanded = raw;
|
|
2599
|
-
if (raw === "~") {
|
|
2600
|
-
expanded = homeDir2();
|
|
2601
|
-
} else if (raw.startsWith("~/") || raw.startsWith("~\\")) {
|
|
2602
|
-
expanded = join5(homeDir2(), raw.slice(2));
|
|
2603
|
-
}
|
|
2604
|
-
return resolve3(expanded);
|
|
2605
|
-
}
|
|
2606
|
-
function resolveCortexKitStorageRoot() {
|
|
2607
|
-
const override = process.env.AFT_STORAGE_DIR;
|
|
2608
|
-
if (override)
|
|
2609
|
-
return resolveStoragePath(override);
|
|
2610
|
-
return resolveStoragePath(join5(dataHome(), "cortexkit", "aft"));
|
|
2611
|
-
}
|
|
2612
|
-
function resolveAftStorageRoot(configuredRoot) {
|
|
2613
|
-
if (process.env.AFT_STORAGE_DIR)
|
|
2614
|
-
return resolveCortexKitStorageRoot();
|
|
2615
|
-
if (configuredRoot)
|
|
2616
|
-
return configuredRoot;
|
|
2617
|
-
return resolveCortexKitStorageRoot();
|
|
2618
|
-
}
|
|
2619
|
-
function resolveAftLogPath(filename, configuredRoot) {
|
|
2620
|
-
return join5(resolveAftStorageRoot(configuredRoot), "logs", filename);
|
|
2621
|
-
}
|
|
2622
|
-
var init_storage_paths = () => {};
|
|
2623
|
-
|
|
2624
2680
|
// ../aft-bridge/dist/durable-log.js
|
|
2625
2681
|
import { appendFile, mkdir, rename, rm, stat } from "node:fs/promises";
|
|
2626
2682
|
import { dirname } from "node:path";
|
|
@@ -4720,7 +4776,7 @@ function projectRootKeyHash(dir) {
|
|
|
4720
4776
|
var init_project_identity = () => {};
|
|
4721
4777
|
|
|
4722
4778
|
// ../aft-bridge/dist/subc-transport.js
|
|
4723
|
-
import { existsSync as
|
|
4779
|
+
import { existsSync as existsSync4, statSync as statSync3 } from "node:fs";
|
|
4724
4780
|
function reconnectBackoffMs(attempt) {
|
|
4725
4781
|
return Math.min(RECONNECT_RETRY_FLOOR_MS * 2 ** Math.min(attempt, 6), RECONNECT_RETRY_CAP_MS);
|
|
4726
4782
|
}
|
|
@@ -5211,7 +5267,7 @@ class SubcTransportPool {
|
|
|
5211
5267
|
this.dormantRoots.delete(root);
|
|
5212
5268
|
return true;
|
|
5213
5269
|
}
|
|
5214
|
-
const reclaimedMarkerPresent =
|
|
5270
|
+
const reclaimedMarkerPresent = existsSync4(`${root}.reclaimed`);
|
|
5215
5271
|
if (reclaimedMarkerPresent) {
|
|
5216
5272
|
this.markRootDormant(root);
|
|
5217
5273
|
return false;
|
|
@@ -6121,9 +6177,9 @@ function stripJsoncSymbols(value) {
|
|
|
6121
6177
|
}
|
|
6122
6178
|
|
|
6123
6179
|
// ../aft-bridge/dist/paths.js
|
|
6124
|
-
import { existsSync as
|
|
6180
|
+
import { existsSync as existsSync5, mkdirSync as mkdirSync2, readFileSync as readFileSync4, renameSync as renameSync2, writeFileSync } from "node:fs";
|
|
6125
6181
|
import { homedir as homedir6 } from "node:os";
|
|
6126
|
-
import { dirname as dirname2, isAbsolute as isAbsolute2, join as
|
|
6182
|
+
import { dirname as dirname2, isAbsolute as isAbsolute2, join as join7, resolve as resolve5 } from "node:path";
|
|
6127
6183
|
function homeDir3() {
|
|
6128
6184
|
if (process.platform === "win32")
|
|
6129
6185
|
return process.env.USERPROFILE || process.env.HOME || homedir6();
|
|
@@ -6133,16 +6189,16 @@ function configHome() {
|
|
|
6133
6189
|
const xdg = process.env.XDG_CONFIG_HOME;
|
|
6134
6190
|
if (xdg && isAbsolute2(xdg))
|
|
6135
6191
|
return xdg;
|
|
6136
|
-
return
|
|
6192
|
+
return join7(homeDir3(), ".config");
|
|
6137
6193
|
}
|
|
6138
6194
|
function legacyOpenCodeConfigDir() {
|
|
6139
6195
|
const envDir = process.env.OPENCODE_CONFIG_DIR?.trim();
|
|
6140
6196
|
if (envDir)
|
|
6141
6197
|
return resolve5(envDir);
|
|
6142
|
-
return
|
|
6198
|
+
return join7(configHome(), "opencode");
|
|
6143
6199
|
}
|
|
6144
6200
|
function legacyPiAgentDir() {
|
|
6145
|
-
return
|
|
6201
|
+
return join7(homeDir3(), ".pi", "agent");
|
|
6146
6202
|
}
|
|
6147
6203
|
function legacySources(basePath, label, harness) {
|
|
6148
6204
|
return [
|
|
@@ -6151,10 +6207,10 @@ function legacySources(basePath, label, harness) {
|
|
|
6151
6207
|
];
|
|
6152
6208
|
}
|
|
6153
6209
|
function resolveCortexKitUserConfigPath() {
|
|
6154
|
-
return
|
|
6210
|
+
return join7(configHome(), "cortexkit", "aft.jsonc");
|
|
6155
6211
|
}
|
|
6156
6212
|
function resolveCortexKitProjectConfigPath(projectDirectory) {
|
|
6157
|
-
return
|
|
6213
|
+
return join7(projectDirectory, ".cortexkit", "aft.jsonc");
|
|
6158
6214
|
}
|
|
6159
6215
|
function resolveCortexKitConfigPaths(projectDirectory) {
|
|
6160
6216
|
return {
|
|
@@ -6165,22 +6221,22 @@ function resolveCortexKitConfigPaths(projectDirectory) {
|
|
|
6165
6221
|
function resolveLegacyAftConfigSources(projectDirectory) {
|
|
6166
6222
|
return {
|
|
6167
6223
|
user: [
|
|
6168
|
-
...legacySources(
|
|
6169
|
-
...legacySources(
|
|
6224
|
+
...legacySources(join7(legacyOpenCodeConfigDir(), "aft"), "OpenCode user", "opencode"),
|
|
6225
|
+
...legacySources(join7(legacyPiAgentDir(), "aft"), "Pi user", "pi")
|
|
6170
6226
|
],
|
|
6171
6227
|
project: [
|
|
6172
|
-
...legacySources(
|
|
6173
|
-
...legacySources(
|
|
6228
|
+
...legacySources(join7(projectDirectory, ".opencode", "aft"), "OpenCode project", "opencode"),
|
|
6229
|
+
...legacySources(join7(projectDirectory, ".pi", "aft"), "Pi project", "pi")
|
|
6174
6230
|
]
|
|
6175
6231
|
};
|
|
6176
6232
|
}
|
|
6177
6233
|
function resolveHarnessStoragePath(storageRoot, harness, ...segments) {
|
|
6178
|
-
return
|
|
6234
|
+
return join7(storageRoot, harness, ...segments);
|
|
6179
6235
|
}
|
|
6180
6236
|
function repairRootScopedStorageFile(storageRoot, harness, fileName) {
|
|
6181
6237
|
const harnessPath = resolveHarnessStoragePath(storageRoot, harness, fileName);
|
|
6182
|
-
const rootPath =
|
|
6183
|
-
if (
|
|
6238
|
+
const rootPath = join7(storageRoot, fileName);
|
|
6239
|
+
if (existsSync5(harnessPath) || !existsSync5(rootPath))
|
|
6184
6240
|
return harnessPath;
|
|
6185
6241
|
try {
|
|
6186
6242
|
mkdirSync2(dirname2(harnessPath), { recursive: true });
|
|
@@ -6194,7 +6250,7 @@ function shouldShowAnnouncement(storageRoot, harness, currentVersion) {
|
|
|
6194
6250
|
const versionFile = repairRootScopedStorageFile(storageRoot, harness, "last_announced_version");
|
|
6195
6251
|
let lastVersion = "";
|
|
6196
6252
|
try {
|
|
6197
|
-
if (
|
|
6253
|
+
if (existsSync5(versionFile)) {
|
|
6198
6254
|
lastVersion = readFileSync4(versionFile, "utf-8").trim();
|
|
6199
6255
|
}
|
|
6200
6256
|
} catch {
|
|
@@ -6267,10 +6323,10 @@ var init_paths = () => {};
|
|
|
6267
6323
|
|
|
6268
6324
|
// ../aft-bridge/dist/resolver.js
|
|
6269
6325
|
import { execSync } from "node:child_process";
|
|
6270
|
-
import { chmodSync as chmodSync2, closeSync as closeSync2, copyFileSync as copyFileSync2, existsSync as
|
|
6326
|
+
import { chmodSync as chmodSync2, closeSync as closeSync2, copyFileSync as copyFileSync2, existsSync as existsSync6, mkdirSync as mkdirSync3, openSync as openSync2, readSync, renameSync as renameSync3, unlinkSync as unlinkSync2 } from "node:fs";
|
|
6271
6327
|
import { createRequire } from "node:module";
|
|
6272
6328
|
import { homedir as homedir7 } from "node:os";
|
|
6273
|
-
import { join as
|
|
6329
|
+
import { join as join8 } from "node:path";
|
|
6274
6330
|
function copyToVersionedCache(npmBinaryPath, knownVersion) {
|
|
6275
6331
|
try {
|
|
6276
6332
|
const version = knownVersion ?? readBinaryVersion(npmBinaryPath);
|
|
@@ -6278,10 +6334,10 @@ function copyToVersionedCache(npmBinaryPath, knownVersion) {
|
|
|
6278
6334
|
return null;
|
|
6279
6335
|
const tag = version.startsWith("v") ? version : `v${version}`;
|
|
6280
6336
|
const cacheDir = getAftBinaryCacheDir();
|
|
6281
|
-
const versionedDir =
|
|
6337
|
+
const versionedDir = join8(cacheDir, tag);
|
|
6282
6338
|
const ext = process.platform === "win32" ? ".exe" : "";
|
|
6283
|
-
const cachedPath =
|
|
6284
|
-
if (
|
|
6339
|
+
const cachedPath = join8(versionedDir, `aft${ext}`);
|
|
6340
|
+
if (existsSync6(cachedPath)) {
|
|
6285
6341
|
const cachedVersion = readBinaryVersion(cachedPath);
|
|
6286
6342
|
if (cachedVersion === version)
|
|
6287
6343
|
return cachedPath;
|
|
@@ -6293,7 +6349,7 @@ function copyToVersionedCache(npmBinaryPath, knownVersion) {
|
|
|
6293
6349
|
if (process.platform !== "win32") {
|
|
6294
6350
|
chmodSync2(tmpPath, 493);
|
|
6295
6351
|
}
|
|
6296
|
-
if (process.platform === "win32" &&
|
|
6352
|
+
if (process.platform === "win32" && existsSync6(cachedPath)) {
|
|
6297
6353
|
try {
|
|
6298
6354
|
unlinkSync2(cachedPath);
|
|
6299
6355
|
} catch {}
|
|
@@ -6313,8 +6369,8 @@ function homeDirFromEnv(env) {
|
|
|
6313
6369
|
return (process.platform === "win32" ? env.USERPROFILE || env.HOME : env.HOME) || homedir7();
|
|
6314
6370
|
}
|
|
6315
6371
|
function cachedBinaryPathFromEnv(version, env, ext) {
|
|
6316
|
-
const binaryPath =
|
|
6317
|
-
return
|
|
6372
|
+
const binaryPath = join8(getAftBinaryCacheDir(env), version, `aft${ext}`);
|
|
6373
|
+
return existsSync6(binaryPath) ? binaryPath : null;
|
|
6318
6374
|
}
|
|
6319
6375
|
function isExpectedCachedBinary2(binaryPath, expectedVersion) {
|
|
6320
6376
|
const expected = normalizeBareVersion(expectedVersion);
|
|
@@ -6413,7 +6469,7 @@ function findBinarySyncInner(expectedVersion) {
|
|
|
6413
6469
|
const packageBin = `@cortexkit/aft-${key}/bin/aft${ext}`;
|
|
6414
6470
|
const req = createRequire(import.meta.url);
|
|
6415
6471
|
const resolved = req.resolve(packageBin);
|
|
6416
|
-
if (
|
|
6472
|
+
if (existsSync6(resolved)) {
|
|
6417
6473
|
const npmVersion = readBinaryVersion(resolved);
|
|
6418
6474
|
if (npmVersion === null) {
|
|
6419
6475
|
warn(`npm platform package binary at ${resolved} did not report a version; skipping (continuing to PATH lookup)`);
|
|
@@ -6442,8 +6498,8 @@ function findBinarySyncInner(expectedVersion) {
|
|
|
6442
6498
|
return { path: usable, source: "PATH" };
|
|
6443
6499
|
}
|
|
6444
6500
|
} catch {}
|
|
6445
|
-
const cargoPath =
|
|
6446
|
-
if (
|
|
6501
|
+
const cargoPath = join8(homeDirFromEnv(env), ".cargo", "bin", `aft${ext}`);
|
|
6502
|
+
if (existsSync6(cargoPath)) {
|
|
6447
6503
|
const usable = probeBinaryCandidate(cargoPath, "cargo", expectedVersion);
|
|
6448
6504
|
if (usable)
|
|
6449
6505
|
return { path: usable, source: "cargo" };
|
|
@@ -6491,16 +6547,16 @@ var init_resolver = __esm(() => {
|
|
|
6491
6547
|
|
|
6492
6548
|
// ../aft-bridge/dist/migration.js
|
|
6493
6549
|
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
6494
|
-
import { closeSync as closeSync3, existsSync as
|
|
6550
|
+
import { closeSync as closeSync3, existsSync as existsSync7, mkdirSync as mkdirSync4, openSync as openSync3, readFileSync as readFileSync5, renameSync as renameSync4, rmSync as rmSync2, statSync as statSync4, unlinkSync as unlinkSync3, writeFileSync as writeFileSync2 } from "node:fs";
|
|
6495
6551
|
import { homedir as homedir8, tmpdir } from "node:os";
|
|
6496
|
-
import { basename, dirname as dirname3, join as
|
|
6552
|
+
import { basename, dirname as dirname3, join as join9, resolve as resolve6 } from "node:path";
|
|
6497
6553
|
function dataHome2() {
|
|
6498
6554
|
if (process.env.XDG_DATA_HOME)
|
|
6499
6555
|
return process.env.XDG_DATA_HOME;
|
|
6500
6556
|
if (process.platform === "win32") {
|
|
6501
|
-
return process.env.LOCALAPPDATA || process.env.APPDATA ||
|
|
6557
|
+
return process.env.LOCALAPPDATA || process.env.APPDATA || join9(homeDir4(), "AppData", "Local");
|
|
6502
6558
|
}
|
|
6503
|
-
return
|
|
6559
|
+
return join9(homeDir4(), ".local", "share");
|
|
6504
6560
|
}
|
|
6505
6561
|
function homeDir4() {
|
|
6506
6562
|
if (process.platform === "win32")
|
|
@@ -6509,8 +6565,8 @@ function homeDir4() {
|
|
|
6509
6565
|
}
|
|
6510
6566
|
function resolveLegacyStorageRoot(harness) {
|
|
6511
6567
|
if (harness === "pi")
|
|
6512
|
-
return
|
|
6513
|
-
return
|
|
6568
|
+
return join9(homeDir4(), ".pi", "agent", "aft");
|
|
6569
|
+
return join9(dataHome2(), "opencode", "storage", "plugin", "aft");
|
|
6514
6570
|
}
|
|
6515
6571
|
function stripJsoncForParse(input) {
|
|
6516
6572
|
let out = "";
|
|
@@ -6640,7 +6696,7 @@ function acquireConfigMigrationLock(lockDir) {
|
|
|
6640
6696
|
}
|
|
6641
6697
|
function atomicCopyConfigFile(sourcePath, targetPath) {
|
|
6642
6698
|
mkdirSync4(dirname3(targetPath), { recursive: true });
|
|
6643
|
-
const tmpPath =
|
|
6699
|
+
const tmpPath = join9(dirname3(targetPath), `.${basename(targetPath)}.${process.pid}.${Date.now()}.${Math.random().toString(16).slice(2)}.tmp`);
|
|
6644
6700
|
let fd = null;
|
|
6645
6701
|
try {
|
|
6646
6702
|
fd = openSync3(tmpPath, "wx", 384);
|
|
@@ -6662,7 +6718,7 @@ function atomicCopyConfigFile(sourcePath, targetPath) {
|
|
|
6662
6718
|
}
|
|
6663
6719
|
function atomicWriteConfigFile(targetPath, content) {
|
|
6664
6720
|
mkdirSync4(dirname3(targetPath), { recursive: true });
|
|
6665
|
-
const tmpPath =
|
|
6721
|
+
const tmpPath = join9(dirname3(targetPath), `.${basename(targetPath)}.${process.pid}.${Date.now()}.${Math.random().toString(16).slice(2)}.tmp`);
|
|
6666
6722
|
let fd = null;
|
|
6667
6723
|
try {
|
|
6668
6724
|
fd = openSync3(tmpPath, "wx", 384);
|
|
@@ -6683,11 +6739,11 @@ function atomicWriteConfigFile(targetPath, content) {
|
|
|
6683
6739
|
}
|
|
6684
6740
|
}
|
|
6685
6741
|
function nonClobberingSidecarPath(desiredPath) {
|
|
6686
|
-
if (!
|
|
6742
|
+
if (!existsSync7(desiredPath))
|
|
6687
6743
|
return desiredPath;
|
|
6688
6744
|
for (let index = 1;index < Number.MAX_SAFE_INTEGER; index++) {
|
|
6689
6745
|
const candidate = `${desiredPath}.${index}`;
|
|
6690
|
-
if (!
|
|
6746
|
+
if (!existsSync7(candidate))
|
|
6691
6747
|
return candidate;
|
|
6692
6748
|
}
|
|
6693
6749
|
throw new Error(`could not find available preservation sidecar path for ${desiredPath}`);
|
|
@@ -6780,7 +6836,7 @@ function visibleConfigMigrationWarning(scope, targetPath, paths, reason) {
|
|
|
6780
6836
|
function migrateAftConfigFile(opts) {
|
|
6781
6837
|
const warnings = [];
|
|
6782
6838
|
const resolvedTarget = resolve6(opts.targetPath);
|
|
6783
|
-
const existingSources = opts.legacySources.filter((source) =>
|
|
6839
|
+
const existingSources = opts.legacySources.filter((source) => existsSync7(source.path) && resolve6(source.path) !== resolvedTarget);
|
|
6784
6840
|
const info = opts.logger?.info ?? opts.logger?.log;
|
|
6785
6841
|
if (existingSources.length === 0) {
|
|
6786
6842
|
return { migrated: false, conflict: false, targetPath: opts.targetPath, warnings };
|
|
@@ -6792,7 +6848,7 @@ function migrateAftConfigFile(opts) {
|
|
|
6792
6848
|
...source,
|
|
6793
6849
|
content: readFileSync5(source.path, "utf-8")
|
|
6794
6850
|
}));
|
|
6795
|
-
if (
|
|
6851
|
+
if (existsSync7(opts.targetPath)) {
|
|
6796
6852
|
const targetContent = readFileSync5(opts.targetPath, "utf-8");
|
|
6797
6853
|
for (const source of sources) {
|
|
6798
6854
|
if (fileSemanticsMatch(source.content, targetContent))
|
|
@@ -6842,12 +6898,12 @@ function spawnErrorLabel(error2) {
|
|
|
6842
6898
|
return [code, error2.message].filter(Boolean).join(": ");
|
|
6843
6899
|
}
|
|
6844
6900
|
function migrationLogPath(newRoot, harness, logger) {
|
|
6845
|
-
const desired =
|
|
6901
|
+
const desired = join9(newRoot, "logs", "migration", `${harness}-${Date.now()}.jsonl`);
|
|
6846
6902
|
try {
|
|
6847
6903
|
mkdirSync4(dirname3(desired), { recursive: true });
|
|
6848
6904
|
return desired;
|
|
6849
6905
|
} catch (err) {
|
|
6850
|
-
const fallback =
|
|
6906
|
+
const fallback = join9(tmpdir(), `aft-migration-${harness}-${Date.now()}.jsonl`);
|
|
6851
6907
|
logger?.warn?.(`Failed to create AFT migration log directory ${dirname3(desired)}: ${err instanceof Error ? err.message : String(err)}. ` + `Using fallback log path ${fallback}.`);
|
|
6852
6908
|
return fallback;
|
|
6853
6909
|
}
|
|
@@ -6857,11 +6913,11 @@ async function ensureStorageMigrated(opts) {
|
|
|
6857
6913
|
const newRoot = resolveCortexKitStorageRoot();
|
|
6858
6914
|
const targetMarker = resolveHarnessStoragePath(newRoot, opts.harness, TARGET_MARKER);
|
|
6859
6915
|
const info = opts.logger?.info ?? opts.logger?.log;
|
|
6860
|
-
if (
|
|
6916
|
+
if (existsSync7(targetMarker)) {
|
|
6861
6917
|
info?.(`AFT storage already migrated for ${opts.harness}; using ${newRoot}`);
|
|
6862
6918
|
return;
|
|
6863
6919
|
}
|
|
6864
|
-
if (!
|
|
6920
|
+
if (!existsSync7(legacyRoot)) {
|
|
6865
6921
|
info?.(`AFT storage migration skipped for ${opts.harness}: no legacy data at ${legacyRoot}; ` + `using ${newRoot} for fresh install`);
|
|
6866
6922
|
return;
|
|
6867
6923
|
}
|
|
@@ -6949,10 +7005,10 @@ var init_migration = __esm(() => {
|
|
|
6949
7005
|
});
|
|
6950
7006
|
|
|
6951
7007
|
// ../aft-bridge/dist/npm-resolver.js
|
|
6952
|
-
import {
|
|
7008
|
+
import { spawn as spawn3, spawnSync as spawnSync3 } from "node:child_process";
|
|
6953
7009
|
import { readdirSync as readdirSync2, statSync as statSync5 } from "node:fs";
|
|
6954
7010
|
import { homedir as homedir9 } from "node:os";
|
|
6955
|
-
import { delimiter, dirname as dirname4, isAbsolute as isAbsolute3, join as
|
|
7011
|
+
import { delimiter as delimiter2, dirname as dirname4, isAbsolute as isAbsolute3, join as join10 } from "node:path";
|
|
6956
7012
|
function defaultDeps() {
|
|
6957
7013
|
return {
|
|
6958
7014
|
platform: process.platform,
|
|
@@ -6974,18 +7030,18 @@ function isFile(p) {
|
|
|
6974
7030
|
function npmFromPath(deps) {
|
|
6975
7031
|
const name = npmBinaryName(deps.platform);
|
|
6976
7032
|
const raw = deps.env.PATH ?? deps.env.Path ?? "";
|
|
6977
|
-
for (const entry of raw.split(
|
|
7033
|
+
for (const entry of raw.split(delimiter2)) {
|
|
6978
7034
|
const dir = entry.trim().replace(/^"|"$/g, "");
|
|
6979
7035
|
if (!dir || !isAbsolute3(dir))
|
|
6980
7036
|
continue;
|
|
6981
|
-
if (isFile(
|
|
7037
|
+
if (isFile(join10(dir, name)))
|
|
6982
7038
|
return dir;
|
|
6983
7039
|
}
|
|
6984
7040
|
return null;
|
|
6985
7041
|
}
|
|
6986
7042
|
function npmAdjacentToNode(deps) {
|
|
6987
7043
|
const dir = dirname4(deps.execPath);
|
|
6988
|
-
return isFile(
|
|
7044
|
+
return isFile(join10(dir, npmBinaryName(deps.platform))) ? dir : null;
|
|
6989
7045
|
}
|
|
6990
7046
|
function highestVersionedNodeBin(installsDir, name) {
|
|
6991
7047
|
let entries;
|
|
@@ -6994,8 +7050,8 @@ function highestVersionedNodeBin(installsDir, name) {
|
|
|
6994
7050
|
} catch {
|
|
6995
7051
|
return null;
|
|
6996
7052
|
}
|
|
6997
|
-
const candidates = entries.filter((v) => isFile(
|
|
6998
|
-
return candidates.length > 0 ?
|
|
7053
|
+
const candidates = entries.filter((v) => isFile(join10(installsDir, v, "bin", name))).sort((a, b) => compareVersionsDesc(a, b));
|
|
7054
|
+
return candidates.length > 0 ? join10(installsDir, candidates[0], "bin") : null;
|
|
6999
7055
|
}
|
|
7000
7056
|
function compareVersionsDesc(a, b) {
|
|
7001
7057
|
const pa = a.replace(/^v/, "").split(".").map((n) => Number.parseInt(n, 10));
|
|
@@ -7020,22 +7076,22 @@ function wellKnownNpmDirs(deps) {
|
|
|
7020
7076
|
const programFiles = env.ProgramFiles || "C:\\Program Files";
|
|
7021
7077
|
const appData = env.APPDATA;
|
|
7022
7078
|
const localAppData = env.LOCALAPPDATA;
|
|
7023
|
-
push(
|
|
7079
|
+
push(join10(programFiles, "nodejs"));
|
|
7024
7080
|
if (appData)
|
|
7025
|
-
push(
|
|
7081
|
+
push(join10(appData, "npm"));
|
|
7026
7082
|
if (localAppData)
|
|
7027
|
-
push(
|
|
7083
|
+
push(join10(localAppData, "Volta", "bin"));
|
|
7028
7084
|
if (env.NVM_SYMLINK)
|
|
7029
7085
|
push(env.NVM_SYMLINK);
|
|
7030
7086
|
} else {
|
|
7031
7087
|
if (env.NVM_BIN)
|
|
7032
7088
|
push(env.NVM_BIN);
|
|
7033
|
-
push(highestVersionedNodeBin(
|
|
7034
|
-
push(highestVersionedNodeBin(
|
|
7035
|
-
push(highestVersionedNodeBin(
|
|
7036
|
-
push(
|
|
7037
|
-
push(
|
|
7038
|
-
const systemDirs = deps.systemNpmDirs ?? (platform === "darwin" ? ["/opt/homebrew/bin", "/usr/local/bin"] : ["/usr/local/bin", "/usr/bin",
|
|
7089
|
+
push(highestVersionedNodeBin(join10(home, ".nvm", "versions", "node"), name));
|
|
7090
|
+
push(highestVersionedNodeBin(join10(home, ".local", "share", "mise", "installs", "node"), name));
|
|
7091
|
+
push(highestVersionedNodeBin(join10(home, ".asdf", "installs", "nodejs"), name));
|
|
7092
|
+
push(join10(home, ".volta", "bin"));
|
|
7093
|
+
push(join10(home, ".asdf", "shims"));
|
|
7094
|
+
const systemDirs = deps.systemNpmDirs ?? (platform === "darwin" ? ["/opt/homebrew/bin", "/usr/local/bin"] : ["/usr/local/bin", "/usr/bin", join10(home, ".local", "bin")]);
|
|
7039
7095
|
for (const dir of systemDirs)
|
|
7040
7096
|
push(dir);
|
|
7041
7097
|
}
|
|
@@ -7045,22 +7101,197 @@ function resolveNpm(deps = defaultDeps()) {
|
|
|
7045
7101
|
const name = npmBinaryName(deps.platform);
|
|
7046
7102
|
const onPath = npmFromPath(deps);
|
|
7047
7103
|
if (onPath)
|
|
7048
|
-
return { command:
|
|
7104
|
+
return { command: join10(onPath, name), binDir: onPath };
|
|
7049
7105
|
const adjacent = npmAdjacentToNode(deps);
|
|
7050
7106
|
if (adjacent)
|
|
7051
|
-
return { command:
|
|
7107
|
+
return { command: join10(adjacent, name), binDir: adjacent };
|
|
7052
7108
|
for (const dir of wellKnownNpmDirs(deps)) {
|
|
7053
|
-
const candidate =
|
|
7109
|
+
const candidate = join10(dir, name);
|
|
7054
7110
|
if (isFile(candidate))
|
|
7055
7111
|
return { command: candidate, binDir: dir };
|
|
7056
7112
|
}
|
|
7057
7113
|
return null;
|
|
7058
7114
|
}
|
|
7115
|
+
function quoteCmdArgument(value) {
|
|
7116
|
+
if (/[\0\r\n"%]/.test(value)) {
|
|
7117
|
+
throw new Error(`npm argument cannot be represented safely for cmd.exe: ${JSON.stringify(value)}`);
|
|
7118
|
+
}
|
|
7119
|
+
return `"${value}"`;
|
|
7120
|
+
}
|
|
7121
|
+
function npmInvocation(resolved, npmArgs, platform = process.platform, env = process.env) {
|
|
7122
|
+
if (platform !== "win32" || !/\.(?:cmd|bat)$/i.test(resolved.command)) {
|
|
7123
|
+
return { command: resolved.command, args: [...npmArgs] };
|
|
7124
|
+
}
|
|
7125
|
+
if (/[\0\r\n"]/.test(resolved.command)) {
|
|
7126
|
+
throw new Error(`npm command cannot be represented safely for cmd.exe: ${JSON.stringify(resolved.command)}`);
|
|
7127
|
+
}
|
|
7128
|
+
const commandEnvName = "AFT_NPM_COMMAND";
|
|
7129
|
+
const quotedArgs = npmArgs.map(quoteCmdArgument);
|
|
7130
|
+
const commandLine = `""%${commandEnvName}%"${quotedArgs.length > 0 ? ` ${quotedArgs.join(" ")}` : ""}"`;
|
|
7131
|
+
return {
|
|
7132
|
+
command: env.ComSpec ?? env.COMSPEC ?? "cmd.exe",
|
|
7133
|
+
args: ["/d", "/s", "/v:off", "/c", commandLine],
|
|
7134
|
+
env: { [commandEnvName]: resolved.command },
|
|
7135
|
+
windowsVerbatimArguments: true,
|
|
7136
|
+
windowsCmdShim: true
|
|
7137
|
+
};
|
|
7138
|
+
}
|
|
7139
|
+
function terminateDirectNpmChild(child, gracePeriodMs) {
|
|
7140
|
+
if (child.exitCode !== null || child.signalCode !== null)
|
|
7141
|
+
return Promise.resolve();
|
|
7142
|
+
return new Promise((resolve7, reject) => {
|
|
7143
|
+
let settled = false;
|
|
7144
|
+
let forceTimer = null;
|
|
7145
|
+
let confirmationTimer = null;
|
|
7146
|
+
let signalFailure = null;
|
|
7147
|
+
const cleanup = () => {
|
|
7148
|
+
if (forceTimer)
|
|
7149
|
+
clearTimeout(forceTimer);
|
|
7150
|
+
if (confirmationTimer)
|
|
7151
|
+
clearTimeout(confirmationTimer);
|
|
7152
|
+
child.removeListener("exit", finish);
|
|
7153
|
+
child.removeListener("error", onChildError);
|
|
7154
|
+
};
|
|
7155
|
+
const finish = () => {
|
|
7156
|
+
if (settled)
|
|
7157
|
+
return;
|
|
7158
|
+
settled = true;
|
|
7159
|
+
cleanup();
|
|
7160
|
+
resolve7();
|
|
7161
|
+
};
|
|
7162
|
+
const fail = () => {
|
|
7163
|
+
if (settled)
|
|
7164
|
+
return;
|
|
7165
|
+
if (child.exitCode !== null || child.signalCode !== null) {
|
|
7166
|
+
finish();
|
|
7167
|
+
return;
|
|
7168
|
+
}
|
|
7169
|
+
settled = true;
|
|
7170
|
+
cleanup();
|
|
7171
|
+
reject(new NpmTerminationUnknownError(signalFailure ?? `direct npm child did not exit after SIGKILL within ${gracePeriodMs}ms`));
|
|
7172
|
+
};
|
|
7173
|
+
const onChildError = (error2) => {
|
|
7174
|
+
signalFailure = `direct npm child error during termination: ${String(error2)}`;
|
|
7175
|
+
};
|
|
7176
|
+
const signal = (value) => {
|
|
7177
|
+
try {
|
|
7178
|
+
if (!child.kill(value)) {
|
|
7179
|
+
signalFailure = `direct npm child rejected ${value ?? "SIGTERM"}`;
|
|
7180
|
+
}
|
|
7181
|
+
} catch (error2) {
|
|
7182
|
+
signalFailure = `direct npm child ${value ?? "SIGTERM"} failed: ${String(error2)}`;
|
|
7183
|
+
}
|
|
7184
|
+
};
|
|
7185
|
+
child.once("exit", finish);
|
|
7186
|
+
child.on("error", onChildError);
|
|
7187
|
+
forceTimer = setTimeout(() => {
|
|
7188
|
+
signal("SIGKILL");
|
|
7189
|
+
confirmationTimer = setTimeout(fail, gracePeriodMs);
|
|
7190
|
+
}, gracePeriodMs);
|
|
7191
|
+
signal();
|
|
7192
|
+
if (child.exitCode !== null || child.signalCode !== null)
|
|
7193
|
+
finish();
|
|
7194
|
+
});
|
|
7195
|
+
}
|
|
7196
|
+
function terminateNpmProcessTree(child, invocation, env = process.env, gracePeriodMs = 5000) {
|
|
7197
|
+
if (!invocation.windowsCmdShim)
|
|
7198
|
+
return terminateDirectNpmChild(child, gracePeriodMs);
|
|
7199
|
+
const exitedSuccessfully = () => child.exitCode === 0 && child.signalCode === null;
|
|
7200
|
+
if (exitedSuccessfully())
|
|
7201
|
+
return Promise.resolve();
|
|
7202
|
+
if (child.pid === undefined) {
|
|
7203
|
+
return Promise.reject(new NpmTerminationUnknownError("cmd.exe child has no process ID"));
|
|
7204
|
+
}
|
|
7205
|
+
return new Promise((resolve7, reject) => {
|
|
7206
|
+
let settled = false;
|
|
7207
|
+
let childExited = child.exitCode !== null || child.signalCode !== null;
|
|
7208
|
+
let treeKillConfirmed = false;
|
|
7209
|
+
let treeKillFailure = null;
|
|
7210
|
+
let killer = null;
|
|
7211
|
+
const timeout = setTimeout(() => {
|
|
7212
|
+
try {
|
|
7213
|
+
killer?.kill();
|
|
7214
|
+
} catch {}
|
|
7215
|
+
if (treeKillConfirmed || exitedSuccessfully()) {
|
|
7216
|
+
settled = true;
|
|
7217
|
+
cleanup();
|
|
7218
|
+
resolve7();
|
|
7219
|
+
return;
|
|
7220
|
+
}
|
|
7221
|
+
fail(treeKillFailure ?? `taskkill.exe did not finish within ${gracePeriodMs}ms`);
|
|
7222
|
+
}, gracePeriodMs);
|
|
7223
|
+
const cleanup = () => {
|
|
7224
|
+
clearTimeout(timeout);
|
|
7225
|
+
child.removeListener("exit", onChildExit);
|
|
7226
|
+
};
|
|
7227
|
+
const succeedIfConfirmed = () => {
|
|
7228
|
+
if (settled || !childExited || !treeKillConfirmed)
|
|
7229
|
+
return;
|
|
7230
|
+
settled = true;
|
|
7231
|
+
cleanup();
|
|
7232
|
+
resolve7();
|
|
7233
|
+
};
|
|
7234
|
+
const fail = (detail) => {
|
|
7235
|
+
if (settled)
|
|
7236
|
+
return;
|
|
7237
|
+
settled = true;
|
|
7238
|
+
cleanup();
|
|
7239
|
+
reject(new NpmTerminationUnknownError(detail));
|
|
7240
|
+
};
|
|
7241
|
+
function onChildExit() {
|
|
7242
|
+
childExited = true;
|
|
7243
|
+
if (treeKillFailure !== null) {
|
|
7244
|
+
if (exitedSuccessfully()) {
|
|
7245
|
+
settled = true;
|
|
7246
|
+
cleanup();
|
|
7247
|
+
resolve7();
|
|
7248
|
+
} else {
|
|
7249
|
+
fail(treeKillFailure);
|
|
7250
|
+
}
|
|
7251
|
+
return;
|
|
7252
|
+
}
|
|
7253
|
+
succeedIfConfirmed();
|
|
7254
|
+
}
|
|
7255
|
+
const recordTreeKillFailure = (detail) => {
|
|
7256
|
+
if (settled)
|
|
7257
|
+
return;
|
|
7258
|
+
if (exitedSuccessfully()) {
|
|
7259
|
+
settled = true;
|
|
7260
|
+
cleanup();
|
|
7261
|
+
resolve7();
|
|
7262
|
+
return;
|
|
7263
|
+
}
|
|
7264
|
+
treeKillFailure = detail;
|
|
7265
|
+
if (childExited)
|
|
7266
|
+
fail(detail);
|
|
7267
|
+
};
|
|
7268
|
+
child.once("exit", onChildExit);
|
|
7269
|
+
const systemRoot = env.SystemRoot ?? env.SYSTEMROOT;
|
|
7270
|
+
const taskkill = systemRoot ? join10(systemRoot, "System32", "taskkill.exe") : "taskkill.exe";
|
|
7271
|
+
try {
|
|
7272
|
+
killer = spawn3(taskkill, ["/pid", String(child.pid), "/t", "/f"], {
|
|
7273
|
+
stdio: "ignore",
|
|
7274
|
+
windowsHide: true
|
|
7275
|
+
});
|
|
7276
|
+
killer.once("error", (error2) => recordTreeKillFailure(`taskkill.exe failed to start: ${String(error2)}`));
|
|
7277
|
+
killer.once("exit", (code) => {
|
|
7278
|
+
if (code !== 0) {
|
|
7279
|
+
recordTreeKillFailure(`taskkill.exe exited with code ${code ?? "unknown"}`);
|
|
7280
|
+
return;
|
|
7281
|
+
}
|
|
7282
|
+
treeKillConfirmed = true;
|
|
7283
|
+
succeedIfConfirmed();
|
|
7284
|
+
});
|
|
7285
|
+
} catch (error2) {
|
|
7286
|
+
recordTreeKillFailure(`taskkill.exe failed to start: ${String(error2)}`);
|
|
7287
|
+
}
|
|
7288
|
+
});
|
|
7289
|
+
}
|
|
7059
7290
|
function npmSpawnEnv(resolved, baseEnv = process.env) {
|
|
7060
7291
|
if (!resolved.binDir)
|
|
7061
7292
|
return { ...baseEnv };
|
|
7062
7293
|
const existing = baseEnv.PATH ?? baseEnv.Path ?? "";
|
|
7063
|
-
const next = existing ? `${resolved.binDir}${
|
|
7294
|
+
const next = existing ? `${resolved.binDir}${delimiter2}${existing}` : resolved.binDir;
|
|
7064
7295
|
return { ...baseEnv, PATH: next };
|
|
7065
7296
|
}
|
|
7066
7297
|
function isNpmAvailable(deps = defaultDeps()) {
|
|
@@ -7068,25 +7299,38 @@ function isNpmAvailable(deps = defaultDeps()) {
|
|
|
7068
7299
|
}
|
|
7069
7300
|
function probeNpmVersion(resolved) {
|
|
7070
7301
|
try {
|
|
7071
|
-
const
|
|
7072
|
-
|
|
7302
|
+
const invocation = npmInvocation(resolved, ["--version"]);
|
|
7303
|
+
const result = spawnSync3(invocation.command, invocation.args, {
|
|
7304
|
+
env: { ...npmSpawnEnv(resolved), ...invocation.env },
|
|
7073
7305
|
encoding: "utf-8",
|
|
7074
7306
|
timeout: 5000,
|
|
7075
|
-
stdio: ["ignore", "pipe", "ignore"]
|
|
7307
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
7308
|
+
windowsVerbatimArguments: invocation.windowsVerbatimArguments
|
|
7076
7309
|
});
|
|
7077
|
-
|
|
7078
|
-
|
|
7310
|
+
if (result.error || result.status !== 0)
|
|
7311
|
+
return null;
|
|
7312
|
+
const version = result.stdout.trim();
|
|
7313
|
+
return /^\d+\.\d+\.\d+/.test(version) ? version : null;
|
|
7079
7314
|
} catch {
|
|
7080
7315
|
return null;
|
|
7081
7316
|
}
|
|
7082
7317
|
}
|
|
7083
|
-
var
|
|
7318
|
+
var NpmTerminationUnknownError;
|
|
7319
|
+
var init_npm_resolver = __esm(() => {
|
|
7320
|
+
NpmTerminationUnknownError = class NpmTerminationUnknownError extends Error {
|
|
7321
|
+
code = "npm_termination_unknown";
|
|
7322
|
+
constructor(detail) {
|
|
7323
|
+
super(`npm process-tree termination could not be confirmed: ${detail}`);
|
|
7324
|
+
this.name = "NpmTerminationUnknownError";
|
|
7325
|
+
}
|
|
7326
|
+
};
|
|
7327
|
+
});
|
|
7084
7328
|
|
|
7085
7329
|
// ../aft-bridge/dist/onnx-runtime.js
|
|
7086
|
-
import { execFileSync
|
|
7330
|
+
import { execFileSync } from "node:child_process";
|
|
7087
7331
|
import { createHash as createHash4 } from "node:crypto";
|
|
7088
|
-
import { chmodSync as chmodSync3, closeSync as closeSync4, copyFileSync as copyFileSync3, createWriteStream as createWriteStream2, existsSync as
|
|
7089
|
-
import { basename as basename2, dirname as dirname5, isAbsolute as isAbsolute4, join as
|
|
7332
|
+
import { chmodSync as chmodSync3, closeSync as closeSync4, copyFileSync as copyFileSync3, createWriteStream as createWriteStream2, existsSync as existsSync8, lstatSync, mkdirSync as mkdirSync5, openSync as openSync4, readdirSync as readdirSync3, readFileSync as readFileSync6, readlinkSync, realpathSync as realpathSync2, rmSync as rmSync3, statSync as statSync6, symlinkSync, unlinkSync as unlinkSync4, writeFileSync as writeFileSync3 } from "node:fs";
|
|
7333
|
+
import { basename as basename2, dirname as dirname5, isAbsolute as isAbsolute4, join as join11, relative as relative2, resolve as resolve7, win32 } from "node:path";
|
|
7090
7334
|
import { Readable as Readable2 } from "node:stream";
|
|
7091
7335
|
import { pipeline as pipeline2 } from "node:stream/promises";
|
|
7092
7336
|
function getPlatformInfo() {
|
|
@@ -7112,11 +7356,11 @@ function getManualInstallHint() {
|
|
|
7112
7356
|
}
|
|
7113
7357
|
async function ensureOnnxRuntime(storageDir) {
|
|
7114
7358
|
const info = getPlatformInfo();
|
|
7115
|
-
const ortVersionDir =
|
|
7359
|
+
const ortVersionDir = join11(storageDir, "onnxruntime", ORT_VERSION);
|
|
7116
7360
|
const libName = info?.libName ?? "libonnxruntime.dylib";
|
|
7117
7361
|
const resolvedOrtDir = resolveCachedOnnxRuntimeDir(ortVersionDir, libName);
|
|
7118
|
-
const libPath =
|
|
7119
|
-
if (
|
|
7362
|
+
const libPath = join11(resolvedOrtDir, libName);
|
|
7363
|
+
if (existsSync8(libPath)) {
|
|
7120
7364
|
const meta = readOnnxInstalledMeta(ortVersionDir);
|
|
7121
7365
|
if (meta?.sha256) {
|
|
7122
7366
|
try {
|
|
@@ -7145,9 +7389,9 @@ async function ensureOnnxRuntime(storageDir) {
|
|
|
7145
7389
|
warn(`ONNX Runtime auto-download not available for ${process.platform}/${process.arch}. Install manually: ${getManualInstallHint()}`);
|
|
7146
7390
|
return null;
|
|
7147
7391
|
}
|
|
7148
|
-
const onnxBaseDir =
|
|
7392
|
+
const onnxBaseDir = join11(storageDir, "onnxruntime");
|
|
7149
7393
|
mkdirSync5(onnxBaseDir, { recursive: true });
|
|
7150
|
-
const lockPath =
|
|
7394
|
+
const lockPath = join11(onnxBaseDir, ONNX_LOCK_FILE);
|
|
7151
7395
|
cleanupAbandonedStagingDirs(onnxBaseDir);
|
|
7152
7396
|
if (!acquireLock(lockPath)) {
|
|
7153
7397
|
warn(`ONNX Runtime install already in progress in another process (lock: ${lockPath}). Skipping.`);
|
|
@@ -7166,7 +7410,7 @@ function cleanupAbandonedStagingDirs(onnxBaseDir) {
|
|
|
7166
7410
|
for (const entry of entries) {
|
|
7167
7411
|
if (!entry.startsWith(`${ORT_VERSION}.tmp.`))
|
|
7168
7412
|
continue;
|
|
7169
|
-
const stagingDir =
|
|
7413
|
+
const stagingDir = join11(onnxBaseDir, entry);
|
|
7170
7414
|
const parts = entry.split(".");
|
|
7171
7415
|
const pidStr = parts[parts.length - 2];
|
|
7172
7416
|
const pid = pidStr ? Number.parseInt(pidStr, 10) : NaN;
|
|
@@ -7203,7 +7447,7 @@ function cleanupAbandonedStagingDirs(onnxBaseDir) {
|
|
|
7203
7447
|
}
|
|
7204
7448
|
function cleanupIncompleteTargetIfUnowned(ortDir) {
|
|
7205
7449
|
try {
|
|
7206
|
-
if (
|
|
7450
|
+
if (existsSync8(ortDir) && !existsSync8(join11(ortDir, ONNX_INSTALLED_META_FILE))) {
|
|
7207
7451
|
log(`[onnx] removing half-populated install dir ${ortDir} (no meta file)`);
|
|
7208
7452
|
rmSync3(ortDir, { recursive: true, force: true });
|
|
7209
7453
|
}
|
|
@@ -7248,8 +7492,8 @@ function detectOnnxVersion(libDir, libName) {
|
|
|
7248
7492
|
if (version)
|
|
7249
7493
|
return version;
|
|
7250
7494
|
}
|
|
7251
|
-
const base =
|
|
7252
|
-
if (
|
|
7495
|
+
const base = join11(libDir, libName);
|
|
7496
|
+
if (existsSync8(base)) {
|
|
7253
7497
|
try {
|
|
7254
7498
|
const real = realpathSync2(base);
|
|
7255
7499
|
const version = parseOnnxVersionFromPath(real) ?? parseOnnxVersionFromDirectoryPath(real);
|
|
@@ -7280,8 +7524,8 @@ function pathEnvValue() {
|
|
|
7280
7524
|
return process.env.PATH ?? process.env.Path ?? process.env.path ?? "";
|
|
7281
7525
|
}
|
|
7282
7526
|
function pathEntriesForPlatform() {
|
|
7283
|
-
const
|
|
7284
|
-
return pathEnvValue().split(
|
|
7527
|
+
const delimiter3 = process.platform === "win32" ? ";" : ":";
|
|
7528
|
+
return pathEnvValue().split(delimiter3).map((entry) => entry.trim().replace(/^"|"$/g, "")).filter((entry) => {
|
|
7285
7529
|
if (!entry || entry === "." || entry.includes("\x00"))
|
|
7286
7530
|
return false;
|
|
7287
7531
|
return isAbsolute4(entry) || win32.isAbsolute(entry);
|
|
@@ -7311,10 +7555,10 @@ function directoryContainsLibrary(dir, libName) {
|
|
|
7311
7555
|
}
|
|
7312
7556
|
}
|
|
7313
7557
|
function resolveCachedOnnxRuntimeDir(ortVersionDir, libName) {
|
|
7314
|
-
if (
|
|
7558
|
+
if (existsSync8(join11(ortVersionDir, libName)))
|
|
7315
7559
|
return ortVersionDir;
|
|
7316
|
-
const libSubdir =
|
|
7317
|
-
if (
|
|
7560
|
+
const libSubdir = join11(ortVersionDir, "lib");
|
|
7561
|
+
if (existsSync8(join11(libSubdir, libName)))
|
|
7318
7562
|
return libSubdir;
|
|
7319
7563
|
return ortVersionDir;
|
|
7320
7564
|
}
|
|
@@ -7329,13 +7573,13 @@ function findSystemOnnxRuntime(libName) {
|
|
|
7329
7573
|
} else if (process.platform === "win32") {
|
|
7330
7574
|
const programFiles = process.env.ProgramFiles ?? "C:\\Program Files";
|
|
7331
7575
|
const programFilesX86 = process.env["ProgramFiles(x86)"] ?? "C:\\Program Files (x86)";
|
|
7332
|
-
searchPaths.push(
|
|
7576
|
+
searchPaths.push(join11(programFiles, "onnxruntime", "lib"), join11(programFiles, "Microsoft ONNX Runtime", "lib"), join11(programFiles, "Microsoft Machine Learning", "lib"), join11(programFilesX86, "onnxruntime", "lib"), ...(() => {
|
|
7333
7577
|
const nugetPaths = [];
|
|
7334
7578
|
const userProfile = process.env.USERPROFILE ?? "";
|
|
7335
7579
|
if (!userProfile)
|
|
7336
7580
|
return nugetPaths;
|
|
7337
|
-
const nugetPackageDir =
|
|
7338
|
-
if (!
|
|
7581
|
+
const nugetPackageDir = join11(userProfile, ".nuget", "packages", "microsoft.ml.onnxruntime");
|
|
7582
|
+
if (!existsSync8(nugetPackageDir))
|
|
7339
7583
|
return nugetPaths;
|
|
7340
7584
|
try {
|
|
7341
7585
|
for (const entry of readdirSync3(nugetPackageDir, { withFileTypes: true })) {
|
|
@@ -7343,7 +7587,7 @@ function findSystemOnnxRuntime(libName) {
|
|
|
7343
7587
|
continue;
|
|
7344
7588
|
if (entry.name === "__globalPackagesFolder" || entry.name.startsWith("."))
|
|
7345
7589
|
continue;
|
|
7346
|
-
nugetPaths.push(
|
|
7590
|
+
nugetPaths.push(join11(nugetPackageDir, entry.name, "runtimes", "win-x64", "native"), join11(nugetPackageDir, entry.name, "runtimes", "win-arm64", "native"));
|
|
7347
7591
|
}
|
|
7348
7592
|
} catch (err) {
|
|
7349
7593
|
warn(`Failed to scan NuGet ONNX Runtime cache ${nugetPackageDir}: ${err instanceof Error ? err.message : String(err)}`);
|
|
@@ -7365,11 +7609,11 @@ function findSystemOnnxRuntime(libName) {
|
|
|
7365
7609
|
});
|
|
7366
7610
|
const unknownVersionPaths = [];
|
|
7367
7611
|
for (const dir of uniquePaths) {
|
|
7368
|
-
const libPath =
|
|
7612
|
+
const libPath = join11(dir, libName);
|
|
7369
7613
|
if (process.platform === "win32") {
|
|
7370
7614
|
if (!directoryContainsLibrary(dir, libName))
|
|
7371
7615
|
continue;
|
|
7372
|
-
} else if (!
|
|
7616
|
+
} else if (!existsSync8(libPath)) {
|
|
7373
7617
|
continue;
|
|
7374
7618
|
}
|
|
7375
7619
|
const version = detectOnnxVersion(dir, libName);
|
|
@@ -7435,7 +7679,7 @@ function validateExtractedTree(stagingRoot) {
|
|
|
7435
7679
|
const walk = (dir) => {
|
|
7436
7680
|
const entries = readdirSync3(dir);
|
|
7437
7681
|
for (const entry of entries) {
|
|
7438
|
-
const fullPath =
|
|
7682
|
+
const fullPath = join11(dir, entry);
|
|
7439
7683
|
const lst = lstatSync(fullPath);
|
|
7440
7684
|
if (lst.isSymbolicLink()) {
|
|
7441
7685
|
const linkTarget = readlinkSync(fullPath);
|
|
@@ -7470,12 +7714,12 @@ async function downloadOnnxRuntime(info, targetDir) {
|
|
|
7470
7714
|
const tmpDir = `${targetDir}.tmp.${process.pid}.${Date.now().toString(36)}`;
|
|
7471
7715
|
try {
|
|
7472
7716
|
mkdirSync5(tmpDir, { recursive: true });
|
|
7473
|
-
const archivePath =
|
|
7717
|
+
const archivePath = join11(tmpDir, `onnxruntime.${info.archiveType}`);
|
|
7474
7718
|
await downloadFileWithCap(url, archivePath);
|
|
7475
7719
|
const archiveSha256 = sha256File(archivePath);
|
|
7476
7720
|
log(`ONNX Runtime archive sha256=${archiveSha256}`);
|
|
7477
7721
|
if (info.archiveType === "tgz") {
|
|
7478
|
-
|
|
7722
|
+
execFileSync("tar", ["xzf", archivePath, "-C", tmpDir], {
|
|
7479
7723
|
stdio: "pipe",
|
|
7480
7724
|
timeout: 120000
|
|
7481
7725
|
});
|
|
@@ -7486,8 +7730,8 @@ async function downloadOnnxRuntime(info, targetDir) {
|
|
|
7486
7730
|
unlinkSync4(archivePath);
|
|
7487
7731
|
} catch {}
|
|
7488
7732
|
validateExtractedTree(tmpDir);
|
|
7489
|
-
const extractedDir =
|
|
7490
|
-
if (!
|
|
7733
|
+
const extractedDir = join11(tmpDir, info.assetName, "lib");
|
|
7734
|
+
if (!existsSync8(extractedDir)) {
|
|
7491
7735
|
throw new Error(`Expected directory not found: ${extractedDir}`);
|
|
7492
7736
|
}
|
|
7493
7737
|
mkdirSync5(targetDir, { recursive: true });
|
|
@@ -7495,7 +7739,7 @@ async function downloadOnnxRuntime(info, targetDir) {
|
|
|
7495
7739
|
const realFiles = [];
|
|
7496
7740
|
const symlinks = [];
|
|
7497
7741
|
for (const libFile of libFiles) {
|
|
7498
|
-
const src =
|
|
7742
|
+
const src = join11(extractedDir, libFile);
|
|
7499
7743
|
try {
|
|
7500
7744
|
const stat2 = lstatSync(src);
|
|
7501
7745
|
log(`ORT extract: ${libFile} — isSymlink=${stat2.isSymbolicLink()}, isFile=${stat2.isFile()}, size=${stat2.size}`);
|
|
@@ -7510,7 +7754,7 @@ async function downloadOnnxRuntime(info, targetDir) {
|
|
|
7510
7754
|
}
|
|
7511
7755
|
}
|
|
7512
7756
|
copyOnnxLibraries(info, extractedDir, targetDir, realFiles, symlinks);
|
|
7513
|
-
const libPath =
|
|
7757
|
+
const libPath = join11(targetDir, info.libName);
|
|
7514
7758
|
let libHash = null;
|
|
7515
7759
|
try {
|
|
7516
7760
|
libHash = sha256File(libPath);
|
|
@@ -7535,8 +7779,8 @@ async function downloadOnnxRuntime(info, targetDir) {
|
|
|
7535
7779
|
function copyOnnxLibraries(info, extractedDir, targetDir, realFiles, symlinks, copyFile = copyFileSync3) {
|
|
7536
7780
|
const requiredLibs = new Set([info.libName]);
|
|
7537
7781
|
for (const libFile of realFiles) {
|
|
7538
|
-
const src =
|
|
7539
|
-
const dst =
|
|
7782
|
+
const src = join11(extractedDir, libFile);
|
|
7783
|
+
const dst = join11(targetDir, libFile);
|
|
7540
7784
|
try {
|
|
7541
7785
|
copyFile(src, dst);
|
|
7542
7786
|
if (process.platform !== "win32") {
|
|
@@ -7552,11 +7796,11 @@ function copyOnnxLibraries(info, extractedDir, targetDir, realFiles, symlinks, c
|
|
|
7552
7796
|
}
|
|
7553
7797
|
const targetRoot = realpathSync2(targetDir);
|
|
7554
7798
|
for (const link of symlinks) {
|
|
7555
|
-
const dst =
|
|
7799
|
+
const dst = join11(targetDir, link.name);
|
|
7556
7800
|
try {
|
|
7557
7801
|
unlinkSync4(dst);
|
|
7558
7802
|
} catch {}
|
|
7559
|
-
const dstForContainment =
|
|
7803
|
+
const dstForContainment = join11(targetRoot, link.name);
|
|
7560
7804
|
const resolvedTarget = resolve7(dirname5(dstForContainment), link.target);
|
|
7561
7805
|
if (!isPathInsideRoot(targetRoot, resolvedTarget)) {
|
|
7562
7806
|
const message = `ONNX Runtime symlink ${link.name} points outside install dir: ${link.target}`;
|
|
@@ -7577,21 +7821,21 @@ function copyOnnxLibraries(info, extractedDir, targetDir, realFiles, symlinks, c
|
|
|
7577
7821
|
log(`ORT extract: failed to symlink optional ${link.name}: ${symlinkErr}`);
|
|
7578
7822
|
}
|
|
7579
7823
|
}
|
|
7580
|
-
const requiredPath =
|
|
7581
|
-
if (!
|
|
7824
|
+
const requiredPath = join11(targetDir, info.libName);
|
|
7825
|
+
if (!existsSync8(requiredPath)) {
|
|
7582
7826
|
rmSync3(targetDir, { recursive: true, force: true });
|
|
7583
7827
|
throw new Error(`Required ONNX Runtime library missing after install: ${requiredPath}`);
|
|
7584
7828
|
}
|
|
7585
7829
|
}
|
|
7586
7830
|
async function extractZipArchive(archivePath, destinationDir) {
|
|
7587
7831
|
if (process.platform === "win32") {
|
|
7588
|
-
|
|
7832
|
+
execFileSync("tar.exe", ["-xf", archivePath, "-C", destinationDir], {
|
|
7589
7833
|
stdio: "pipe",
|
|
7590
7834
|
timeout: 120000
|
|
7591
7835
|
});
|
|
7592
7836
|
return;
|
|
7593
7837
|
}
|
|
7594
|
-
|
|
7838
|
+
execFileSync("unzip", ["-q", archivePath, "-d", destinationDir], {
|
|
7595
7839
|
stdio: "pipe",
|
|
7596
7840
|
timeout: 120000
|
|
7597
7841
|
});
|
|
@@ -7604,13 +7848,13 @@ function writeOnnxInstalledMeta(installDir, version, sha256, archiveSha256) {
|
|
|
7604
7848
|
...sha256 ? { sha256 } : {},
|
|
7605
7849
|
archiveSha256
|
|
7606
7850
|
};
|
|
7607
|
-
writeFileSync3(
|
|
7851
|
+
writeFileSync3(join11(installDir, ONNX_INSTALLED_META_FILE), JSON.stringify(meta), "utf8");
|
|
7608
7852
|
} catch (err) {
|
|
7609
7853
|
log(`[onnx] failed to write installed-meta in ${installDir}: ${err}`);
|
|
7610
7854
|
}
|
|
7611
7855
|
}
|
|
7612
7856
|
function readOnnxInstalledMeta(installDir) {
|
|
7613
|
-
const path2 =
|
|
7857
|
+
const path2 = join11(installDir, ONNX_INSTALLED_META_FILE);
|
|
7614
7858
|
try {
|
|
7615
7859
|
if (!statSync6(path2).isFile())
|
|
7616
7860
|
return null;
|
|
@@ -7722,7 +7966,7 @@ function isWindowsProcessAlive(pid) {
|
|
|
7722
7966
|
if (!Number.isInteger(pid) || pid <= 0)
|
|
7723
7967
|
return false;
|
|
7724
7968
|
try {
|
|
7725
|
-
const output =
|
|
7969
|
+
const output = execFileSync("tasklist.exe", ["/FI", `PID eq ${pid}`, "/FO", "CSV", "/NH"], {
|
|
7726
7970
|
encoding: "utf8",
|
|
7727
7971
|
timeout: 2000,
|
|
7728
7972
|
windowsHide: true
|
|
@@ -7748,8 +7992,8 @@ function isProcessAlive2(pid) {
|
|
|
7748
7992
|
}
|
|
7749
7993
|
function cleanupOnnxRuntime(storageDir) {
|
|
7750
7994
|
try {
|
|
7751
|
-
const ortBase =
|
|
7752
|
-
if (
|
|
7995
|
+
const ortBase = join11(storageDir, "onnxruntime");
|
|
7996
|
+
if (existsSync8(ortBase)) {
|
|
7753
7997
|
rmSync3(ortBase, { recursive: true, force: true });
|
|
7754
7998
|
}
|
|
7755
7999
|
} catch {}
|
|
@@ -8054,7 +8298,7 @@ function editModesPresent(record) {
|
|
|
8054
8298
|
const hasSymbol = isNonEmptyString(record.symbol);
|
|
8055
8299
|
if (!hasSymbol) {
|
|
8056
8300
|
delete record.symbol;
|
|
8057
|
-
if (record.content
|
|
8301
|
+
if (isNullOrEmptyString(record.content))
|
|
8058
8302
|
delete record.content;
|
|
8059
8303
|
} else if (record.content === null) {
|
|
8060
8304
|
delete record.content;
|
|
@@ -8083,16 +8327,26 @@ function editModesPresent(record) {
|
|
|
8083
8327
|
function isNonEmptyString(value) {
|
|
8084
8328
|
return typeof value === "string" && value.length > 0;
|
|
8085
8329
|
}
|
|
8330
|
+
function isNullOrEmptyString(value) {
|
|
8331
|
+
return value === null || value === "";
|
|
8332
|
+
}
|
|
8086
8333
|
function isEditSentinelItem(item) {
|
|
8087
8334
|
if (!item || typeof item !== "object" || Array.isArray(item))
|
|
8088
8335
|
return false;
|
|
8089
8336
|
const record = item;
|
|
8090
|
-
|
|
8337
|
+
const oldStringEmpty = hasOwn(record, "oldString") && isNullOrEmptyString(record.oldString);
|
|
8338
|
+
if (!oldStringEmpty)
|
|
8091
8339
|
return false;
|
|
8092
|
-
|
|
8093
|
-
if (!newStringEmpty)
|
|
8340
|
+
if (record.oldString === null && ["startLine", "endLine"].some((key) => hasOwn(record, key) && record[key] !== null)) {
|
|
8094
8341
|
return false;
|
|
8095
|
-
|
|
8342
|
+
}
|
|
8343
|
+
return (!hasOwn(record, "newString") || isNullOrEmptyString(record.newString)) && (!hasOwn(record, "content") || isNullOrEmptyString(record.content)) && (!hasOwn(record, "replaceAll") || record.replaceAll === null || record.replaceAll === false) && isDefaultOccurrence(record.occurrence);
|
|
8344
|
+
}
|
|
8345
|
+
function hasMeaningfulFindPayload(item) {
|
|
8346
|
+
return isNonEmptyString(item.oldString);
|
|
8347
|
+
}
|
|
8348
|
+
function isDefaultOccurrence(value) {
|
|
8349
|
+
return value === undefined || value === null || value === 1;
|
|
8096
8350
|
}
|
|
8097
8351
|
function normalizeEditArraySentinels(record) {
|
|
8098
8352
|
const value = record.edits;
|
|
@@ -8145,9 +8399,33 @@ function parseEditArray(value) {
|
|
|
8145
8399
|
}
|
|
8146
8400
|
return value;
|
|
8147
8401
|
}
|
|
8148
|
-
function
|
|
8149
|
-
const
|
|
8150
|
-
|
|
8402
|
+
function normalizeEditItemSentinels(item) {
|
|
8403
|
+
const hadRangeFields = ["startLine", "endLine", "content"].some((key) => hasOwn(item, key));
|
|
8404
|
+
for (const key of [
|
|
8405
|
+
"oldString",
|
|
8406
|
+
"newString",
|
|
8407
|
+
"replaceAll",
|
|
8408
|
+
"occurrence",
|
|
8409
|
+
"startLine",
|
|
8410
|
+
"endLine",
|
|
8411
|
+
"content"
|
|
8412
|
+
]) {
|
|
8413
|
+
if (item[key] === null)
|
|
8414
|
+
delete item[key];
|
|
8415
|
+
}
|
|
8416
|
+
const contentIsEmpty = item.content === "";
|
|
8417
|
+
if (hasMeaningfulFindPayload(item) && (!hasOwn(item, "content") || contentIsEmpty)) {
|
|
8418
|
+
for (const key of ["startLine", "endLine", "content"])
|
|
8419
|
+
delete item[key];
|
|
8420
|
+
if (hadRangeFields) {
|
|
8421
|
+
if (item.replaceAll === false)
|
|
8422
|
+
delete item.replaceAll;
|
|
8423
|
+
if (hasOwn(item, "occurrence") && isDefaultOccurrence(item.occurrence))
|
|
8424
|
+
delete item.occurrence;
|
|
8425
|
+
}
|
|
8426
|
+
return;
|
|
8427
|
+
}
|
|
8428
|
+
if (!isNonEmptyString(item.content))
|
|
8151
8429
|
return;
|
|
8152
8430
|
if (item.oldString === "")
|
|
8153
8431
|
delete item.oldString;
|
|
@@ -8155,7 +8433,7 @@ function stripLineRangeSentinels(item) {
|
|
|
8155
8433
|
delete item.newString;
|
|
8156
8434
|
if (item.replaceAll === false)
|
|
8157
8435
|
delete item.replaceAll;
|
|
8158
|
-
if (item
|
|
8436
|
+
if (hasOwn(item, "occurrence") && isDefaultOccurrence(item.occurrence))
|
|
8159
8437
|
delete item.occurrence;
|
|
8160
8438
|
}
|
|
8161
8439
|
function normalizeEditItem(value, index) {
|
|
@@ -8166,7 +8444,7 @@ function normalizeEditItem(value, index) {
|
|
|
8166
8444
|
const item = copyOwnProperties(source);
|
|
8167
8445
|
normalizeItemAlias(item, "oldString", "oldText");
|
|
8168
8446
|
normalizeItemAlias(item, "newString", "newText");
|
|
8169
|
-
|
|
8447
|
+
normalizeEditItemSentinels(item);
|
|
8170
8448
|
const hasFindField = ["oldString", "newString", "replaceAll", "occurrence"].some((key) => hasOwn(item, key));
|
|
8171
8449
|
const hasRangeField = ["startLine", "endLine", "content"].some((key) => hasOwn(item, key));
|
|
8172
8450
|
if (hasFindField && hasRangeField) {
|
|
@@ -8925,17 +9203,17 @@ function formatReadFooter(agentSpecifiedRange, data, options) {
|
|
|
8925
9203
|
}
|
|
8926
9204
|
|
|
8927
9205
|
// ../aft-bridge/dist/transport-factory.js
|
|
8928
|
-
import { existsSync as
|
|
9206
|
+
import { existsSync as existsSync9 } from "node:fs";
|
|
8929
9207
|
import { homedir as homedir11 } from "node:os";
|
|
8930
|
-
import { isAbsolute as isAbsolute5, join as
|
|
9208
|
+
import { isAbsolute as isAbsolute5, join as join12 } from "node:path";
|
|
8931
9209
|
function resolveConnectionFilePath(raw) {
|
|
8932
9210
|
const trimmed = raw.trim();
|
|
8933
9211
|
if (trimmed.startsWith("~")) {
|
|
8934
|
-
return
|
|
9212
|
+
return join12(homedir11(), trimmed.slice(1).replace(/^[/\\]/, ""));
|
|
8935
9213
|
}
|
|
8936
9214
|
if (isAbsolute5(trimmed))
|
|
8937
9215
|
return trimmed;
|
|
8938
|
-
return
|
|
9216
|
+
return join12(homedir11(), trimmed);
|
|
8939
9217
|
}
|
|
8940
9218
|
function booleanOption(value) {
|
|
8941
9219
|
return typeof value === "boolean" ? value : undefined;
|
|
@@ -9008,7 +9286,7 @@ async function createConcreteAftTransportPool(opts) {
|
|
|
9008
9286
|
consumerIdentity: opts.subcConsumerIdentity,
|
|
9009
9287
|
onBgEventsNudge: opts.onBgEventsNudge,
|
|
9010
9288
|
onBgEventsNudgeRef: opts.onBgEventsNudgeRef,
|
|
9011
|
-
lifecycleDemandCheck: opts.subcLifecycleDemandCheck ?? ((root) =>
|
|
9289
|
+
lifecycleDemandCheck: opts.subcLifecycleDemandCheck ?? ((root) => existsSync9(root))
|
|
9012
9290
|
});
|
|
9013
9291
|
}
|
|
9014
9292
|
return new BridgePool(opts.binaryPath, opts.poolOptions, opts.configOverrides);
|
|
@@ -9148,6 +9426,7 @@ __export(exports_dist, {
|
|
|
9148
9426
|
HomeProjectRootError: () => HomeProjectRootError,
|
|
9149
9427
|
InvalidRequestError: () => InvalidRequestError,
|
|
9150
9428
|
LONG_RUNNING_COMMAND_TIMEOUT_MS: () => LONG_RUNNING_COMMAND_TIMEOUT_MS,
|
|
9429
|
+
NpmTerminationUnknownError: () => NpmTerminationUnknownError,
|
|
9151
9430
|
OPENCODE_ONLY_KEYS: () => OPENCODE_ONLY_KEYS,
|
|
9152
9431
|
PI_ONLY_KEYS: () => PI_ONLY_KEYS,
|
|
9153
9432
|
PLAIN_CALLGRAPH_THEME: () => PLAIN_CALLGRAPH_THEME,
|
|
@@ -9197,6 +9476,8 @@ __export(exports_dist, {
|
|
|
9197
9476
|
getCachedBinaryPath: () => getCachedBinaryPath,
|
|
9198
9477
|
getManualInstallHint: () => getManualInstallHint,
|
|
9199
9478
|
getMigrationStatus: () => getMigrationStatus,
|
|
9479
|
+
getOpenCodeCacheRoot: () => getOpenCodeCacheRoot,
|
|
9480
|
+
getOpenCodeConfigRoot: () => getOpenCodeConfigRoot,
|
|
9200
9481
|
inlineUserConfigTier: () => inlineUserConfigTier,
|
|
9201
9482
|
isBashTransportDeadError: () => isBashTransportDeadError,
|
|
9202
9483
|
isBridgeTransportTimeout: () => isBridgeTransportTimeout,
|
|
@@ -9212,6 +9493,7 @@ __export(exports_dist, {
|
|
|
9212
9493
|
maybeAppendConflictsHint: () => maybeAppendConflictsHint,
|
|
9213
9494
|
maybeAppendGrepSearchHint: () => maybeAppendGrepSearchHint,
|
|
9214
9495
|
migrateAftConfigFile: () => migrateAftConfigFile,
|
|
9496
|
+
npmInvocation: () => npmInvocation,
|
|
9215
9497
|
npmSpawnEnv: () => npmSpawnEnv,
|
|
9216
9498
|
platformKey: () => platformKey,
|
|
9217
9499
|
prepareCanonicalEditArguments: () => prepareCanonicalEditArguments,
|
|
@@ -9239,6 +9521,7 @@ __export(exports_dist, {
|
|
|
9239
9521
|
stripHarnessSpecificConfigKeys: () => stripHarnessSpecificConfigKeys,
|
|
9240
9522
|
stripJsoncSymbols: () => stripJsoncSymbols,
|
|
9241
9523
|
tagStderrLine: () => tagStderrLine,
|
|
9524
|
+
terminateNpmProcessTree: () => terminateNpmProcessTree,
|
|
9242
9525
|
timeoutForCommand: () => timeoutForCommand,
|
|
9243
9526
|
toolErrorFromResponse: () => toolErrorFromResponse,
|
|
9244
9527
|
unwrapRustZoomBatchEnvelope: () => unwrapRustZoomBatchEnvelope
|
|
@@ -9273,7 +9556,7 @@ var init_dist2 = __esm(() => {
|
|
|
9273
9556
|
|
|
9274
9557
|
// src/lib/paths.ts
|
|
9275
9558
|
import { homedir as homedir12 } from "node:os";
|
|
9276
|
-
import { join as
|
|
9559
|
+
import { join as join13 } from "node:path";
|
|
9277
9560
|
function getAftBinaryName() {
|
|
9278
9561
|
return process.platform === "win32" ? "aft.exe" : "aft";
|
|
9279
9562
|
}
|
|
@@ -9286,25 +9569,25 @@ function dataHome3() {
|
|
|
9286
9569
|
if (process.env.XDG_DATA_HOME)
|
|
9287
9570
|
return process.env.XDG_DATA_HOME;
|
|
9288
9571
|
if (process.platform === "win32") {
|
|
9289
|
-
return process.env.LOCALAPPDATA || process.env.APPDATA ||
|
|
9572
|
+
return process.env.LOCALAPPDATA || process.env.APPDATA || join13(homeDir5(), "AppData", "Local");
|
|
9290
9573
|
}
|
|
9291
|
-
return
|
|
9574
|
+
return join13(homeDir5(), ".local", "share");
|
|
9292
9575
|
}
|
|
9293
9576
|
function getCortexKitStorageRoot() {
|
|
9294
9577
|
if (process.env.AFT_CACHE_DIR)
|
|
9295
|
-
return
|
|
9296
|
-
return
|
|
9578
|
+
return join13(process.env.AFT_CACHE_DIR, "aft");
|
|
9579
|
+
return join13(dataHome3(), "cortexkit", "aft");
|
|
9297
9580
|
}
|
|
9298
9581
|
var init_paths2 = __esm(() => {
|
|
9299
9582
|
init_dist2();
|
|
9300
9583
|
});
|
|
9301
9584
|
|
|
9302
9585
|
// src/lib/binary-probe.ts
|
|
9303
|
-
import { execSync as execSync2, spawnSync as
|
|
9304
|
-
import { existsSync as
|
|
9586
|
+
import { execSync as execSync2, spawnSync as spawnSync4 } from "node:child_process";
|
|
9587
|
+
import { existsSync as existsSync10 } from "node:fs";
|
|
9305
9588
|
import { createRequire as createRequire2 } from "node:module";
|
|
9306
9589
|
import { homedir as homedir13 } from "node:os";
|
|
9307
|
-
import { join as
|
|
9590
|
+
import { join as join14 } from "node:path";
|
|
9308
9591
|
async function loadPluginVersion() {
|
|
9309
9592
|
try {
|
|
9310
9593
|
const bridge = await Promise.resolve().then(() => (init_dist2(), exports_dist));
|
|
@@ -9356,9 +9639,9 @@ function probeAftBinary(preferredVersion) {
|
|
|
9356
9639
|
const candidates = [];
|
|
9357
9640
|
for (const candidate of aftBinaryCandidates(preferredVersion)) {
|
|
9358
9641
|
try {
|
|
9359
|
-
if (!
|
|
9642
|
+
if (!existsSync10(candidate))
|
|
9360
9643
|
continue;
|
|
9361
|
-
const result =
|
|
9644
|
+
const result = spawnSync4(candidate, ["--version"], {
|
|
9362
9645
|
stdio: ["ignore", "pipe", "pipe"],
|
|
9363
9646
|
encoding: "utf-8",
|
|
9364
9647
|
timeout: 5000,
|
|
@@ -9407,7 +9690,7 @@ function pushCandidate(candidates, candidate) {
|
|
|
9407
9690
|
function firstExisting(candidates) {
|
|
9408
9691
|
for (const candidate of candidates) {
|
|
9409
9692
|
try {
|
|
9410
|
-
if (!
|
|
9693
|
+
if (!existsSync10(candidate))
|
|
9411
9694
|
continue;
|
|
9412
9695
|
return candidate;
|
|
9413
9696
|
} catch {}
|
|
@@ -9426,7 +9709,7 @@ function aftBinaryCandidates(preferredVersion) {
|
|
|
9426
9709
|
const candidates = [];
|
|
9427
9710
|
if (preferredVersion) {
|
|
9428
9711
|
const tag = preferredVersion.startsWith("v") ? preferredVersion : `v${preferredVersion}`;
|
|
9429
|
-
pushCandidate(candidates,
|
|
9712
|
+
pushCandidate(candidates, join14(getAftBinaryCacheDir(), tag, getAftBinaryName()));
|
|
9430
9713
|
}
|
|
9431
9714
|
const key = platformKey2();
|
|
9432
9715
|
if (key) {
|
|
@@ -9449,7 +9732,7 @@ function aftBinaryCandidates(preferredVersion) {
|
|
|
9449
9732
|
}
|
|
9450
9733
|
}
|
|
9451
9734
|
} catch {}
|
|
9452
|
-
pushCandidate(candidates,
|
|
9735
|
+
pushCandidate(candidates, join14(homedir13(), ".cargo", "bin", getAftBinaryName()));
|
|
9453
9736
|
return candidates;
|
|
9454
9737
|
}
|
|
9455
9738
|
function findAftBinary(preferredVersion) {
|
|
@@ -9464,10 +9747,10 @@ var init_binary_probe = __esm(async () => {
|
|
|
9464
9747
|
});
|
|
9465
9748
|
|
|
9466
9749
|
// src/lib/fs-util.ts
|
|
9467
|
-
import { existsSync as
|
|
9468
|
-
import { join as
|
|
9750
|
+
import { existsSync as existsSync11, readdirSync as readdirSync4, statSync as statSync7 } from "node:fs";
|
|
9751
|
+
import { join as join15 } from "node:path";
|
|
9469
9752
|
function dirSize(path2) {
|
|
9470
|
-
if (!
|
|
9753
|
+
if (!existsSync11(path2)) {
|
|
9471
9754
|
return 0;
|
|
9472
9755
|
}
|
|
9473
9756
|
const stat2 = statSync7(path2);
|
|
@@ -9479,7 +9762,7 @@ function dirSize(path2) {
|
|
|
9479
9762
|
}
|
|
9480
9763
|
let total = 0;
|
|
9481
9764
|
for (const entry of readdirSync4(path2)) {
|
|
9482
|
-
total += dirSize(
|
|
9765
|
+
total += dirSize(join15(path2, entry));
|
|
9483
9766
|
}
|
|
9484
9767
|
return total;
|
|
9485
9768
|
}
|
|
@@ -17087,9 +17370,9 @@ var require_stringify = __commonJS(function(exports, module) {
|
|
|
17087
17370
|
if (line_breaks_before === null) {
|
|
17088
17371
|
line_breaks_before = inline ? 0 : 1;
|
|
17089
17372
|
}
|
|
17090
|
-
const
|
|
17373
|
+
const delimiter3 = line_breaks_before > 0 ? repeat_line_breaks(line_breaks_before, deeper_gap) : inline ? SPACE : i === 0 ? EMPTY : LF + deeper_gap;
|
|
17091
17374
|
const is_line_comment = type === "LineComment";
|
|
17092
|
-
str +=
|
|
17375
|
+
str += delimiter3 + comment_stringify(value, is_line_comment);
|
|
17093
17376
|
last_comment = comment;
|
|
17094
17377
|
});
|
|
17095
17378
|
const default_line_breaks_after = display_block || last_comment.type === "LineComment" ? 1 : 0;
|
|
@@ -17102,10 +17385,10 @@ var require_stringify = __commonJS(function(exports, module) {
|
|
|
17102
17385
|
replacer = null;
|
|
17103
17386
|
indent = EMPTY;
|
|
17104
17387
|
};
|
|
17105
|
-
var
|
|
17388
|
+
var join16 = (one, two, gap) => one ? two ? one + two.trim() + LF + gap : one.trimRight() + repeat_line_breaks(Math.max(1, count_trailing_line_breaks(one, gap)), gap) : two ? two.trimRight() + repeat_line_breaks(Math.max(1, count_trailing_line_breaks(two, gap)), gap) : EMPTY;
|
|
17106
17389
|
var join_content = (inside, value, gap) => {
|
|
17107
17390
|
const comment = process_comments(value, PREFIX_BEFORE, gap + indent, true);
|
|
17108
|
-
return
|
|
17391
|
+
return join16(comment, inside, gap);
|
|
17109
17392
|
};
|
|
17110
17393
|
var stringify_string = (holder, key, value) => {
|
|
17111
17394
|
const raw = get_raw_string_literal(holder, key);
|
|
@@ -17127,13 +17410,13 @@ var require_stringify = __commonJS(function(exports, module) {
|
|
|
17127
17410
|
if (i !== 0) {
|
|
17128
17411
|
inside += COMMA;
|
|
17129
17412
|
}
|
|
17130
|
-
const before =
|
|
17413
|
+
const before = join16(after_comma, process_comments(value, BEFORE(i), deeper_gap), deeper_gap);
|
|
17131
17414
|
inside += before || LF + deeper_gap;
|
|
17132
17415
|
inside += stringify(i, value, deeper_gap) || STR_NULL;
|
|
17133
17416
|
inside += process_comments(value, AFTER_VALUE(i), deeper_gap);
|
|
17134
17417
|
after_comma = process_comments(value, AFTER(i), deeper_gap);
|
|
17135
17418
|
}
|
|
17136
|
-
inside +=
|
|
17419
|
+
inside += join16(after_comma, process_comments(value, PREFIX_AFTER, deeper_gap), deeper_gap);
|
|
17137
17420
|
return BRACKET_OPEN + join_content(inside, value, gap) + BRACKET_CLOSE;
|
|
17138
17421
|
};
|
|
17139
17422
|
var object_stringify = (value, gap) => {
|
|
@@ -17154,13 +17437,13 @@ var require_stringify = __commonJS(function(exports, module) {
|
|
|
17154
17437
|
inside += COMMA;
|
|
17155
17438
|
}
|
|
17156
17439
|
first = false;
|
|
17157
|
-
const before =
|
|
17440
|
+
const before = join16(after_comma, process_comments(value, BEFORE(key), deeper_gap), deeper_gap);
|
|
17158
17441
|
inside += before || LF + deeper_gap;
|
|
17159
17442
|
inside += quote(key) + process_comments(value, AFTER_PROP(key), deeper_gap) + COLON + process_comments(value, AFTER_COLON(key), deeper_gap) + SPACE + sv + process_comments(value, AFTER_VALUE(key), deeper_gap);
|
|
17160
17443
|
after_comma = process_comments(value, AFTER(key), deeper_gap);
|
|
17161
17444
|
};
|
|
17162
17445
|
keys.forEach(iteratee);
|
|
17163
|
-
inside +=
|
|
17446
|
+
inside += join16(after_comma, process_comments(value, PREFIX_AFTER, deeper_gap), deeper_gap);
|
|
17164
17447
|
return CURLY_BRACKET_OPEN + join_content(inside, value, gap) + CURLY_BRACKET_CLOSE;
|
|
17165
17448
|
};
|
|
17166
17449
|
function stringify(key, holder, gap) {
|
|
@@ -17253,21 +17536,21 @@ var require_src2 = __commonJS(function(exports, module) {
|
|
|
17253
17536
|
});
|
|
17254
17537
|
|
|
17255
17538
|
// src/lib/jsonc.ts
|
|
17256
|
-
import { existsSync as
|
|
17539
|
+
import { existsSync as existsSync12, mkdirSync as mkdirSync6, readFileSync as readFileSync7, writeFileSync as writeFileSync4 } from "node:fs";
|
|
17257
17540
|
import { dirname as dirname6 } from "node:path";
|
|
17258
17541
|
function detectJsoncFile(configDir, baseName) {
|
|
17259
17542
|
const jsoncPath = `${configDir}/${baseName}.jsonc`;
|
|
17260
17543
|
const jsonPath = `${configDir}/${baseName}.json`;
|
|
17261
|
-
if (
|
|
17544
|
+
if (existsSync12(jsoncPath)) {
|
|
17262
17545
|
return { path: jsoncPath, format: "jsonc" };
|
|
17263
17546
|
}
|
|
17264
|
-
if (
|
|
17547
|
+
if (existsSync12(jsonPath)) {
|
|
17265
17548
|
return { path: jsonPath, format: "json" };
|
|
17266
17549
|
}
|
|
17267
17550
|
return { path: jsonPath, format: "none" };
|
|
17268
17551
|
}
|
|
17269
17552
|
function readJsoncFile(path2) {
|
|
17270
|
-
if (!
|
|
17553
|
+
if (!existsSync12(path2)) {
|
|
17271
17554
|
return { value: null };
|
|
17272
17555
|
}
|
|
17273
17556
|
try {
|
|
@@ -17288,7 +17571,7 @@ function writeJsoncFile(path2, value, format = "json") {
|
|
|
17288
17571
|
`);
|
|
17289
17572
|
}
|
|
17290
17573
|
function ensureAftSchemaUrl(path2, format) {
|
|
17291
|
-
const existed =
|
|
17574
|
+
const existed = existsSync12(path2);
|
|
17292
17575
|
if (!existed) {
|
|
17293
17576
|
const writeFormat = format === "jsonc" ? "jsonc" : "json";
|
|
17294
17577
|
writeJsoncFile(path2, { $schema: AFT_SCHEMA_URL }, writeFormat);
|
|
@@ -17341,26 +17624,36 @@ var init_self_version = () => {};
|
|
|
17341
17624
|
|
|
17342
17625
|
// src/adapters/opencode.ts
|
|
17343
17626
|
import { execSync as execSync3 } from "node:child_process";
|
|
17344
|
-
import { existsSync as
|
|
17627
|
+
import { existsSync as existsSync13, readFileSync as readFileSync8, rmSync as rmSync4, statSync as statSync8 } from "node:fs";
|
|
17345
17628
|
import { homedir as homedir14 } from "node:os";
|
|
17346
|
-
import { dirname as dirname7, join as
|
|
17629
|
+
import { dirname as dirname7, join as join16, parse, resolve as resolve8 } from "node:path";
|
|
17347
17630
|
import { fileURLToPath } from "node:url";
|
|
17348
17631
|
function getOpenCodeConfigDir() {
|
|
17349
17632
|
const envDir = process.env.OPENCODE_CONFIG_DIR?.trim();
|
|
17350
17633
|
if (envDir)
|
|
17351
17634
|
return resolve8(envDir);
|
|
17352
|
-
|
|
17353
|
-
return join15(xdg, "opencode");
|
|
17635
|
+
return getOpenCodeConfigRoot();
|
|
17354
17636
|
}
|
|
17355
|
-
function
|
|
17356
|
-
|
|
17357
|
-
|
|
17358
|
-
|
|
17359
|
-
|
|
17360
|
-
|
|
17361
|
-
|
|
17637
|
+
function getLegacyOpenCodePluginCachePath(primaryPath) {
|
|
17638
|
+
if (process.platform !== "win32")
|
|
17639
|
+
return null;
|
|
17640
|
+
const localAppData = process.env.LOCALAPPDATA ?? join16(homedir14(), "AppData", "Local");
|
|
17641
|
+
const legacyPath = join16(localAppData, "opencode", "packages", PLUGIN_ENTRY);
|
|
17642
|
+
return resolve8(legacyPath) === resolve8(primaryPath) ? null : legacyPath;
|
|
17643
|
+
}
|
|
17644
|
+
function clearLegacyOpenCodePluginCache(primaryPath) {
|
|
17645
|
+
const legacyPath = getLegacyOpenCodePluginCachePath(primaryPath);
|
|
17646
|
+
if (!legacyPath || !existsSync13(legacyPath))
|
|
17647
|
+
return { clearedPath: null };
|
|
17648
|
+
try {
|
|
17649
|
+
rmSync4(legacyPath, { recursive: true, force: true });
|
|
17650
|
+
return { clearedPath: legacyPath };
|
|
17651
|
+
} catch (error2) {
|
|
17652
|
+
return { clearedPath: null, error: error2 instanceof Error ? error2.message : String(error2) };
|
|
17362
17653
|
}
|
|
17363
|
-
|
|
17654
|
+
}
|
|
17655
|
+
function getOpenCodeCacheDir() {
|
|
17656
|
+
return getOpenCodeCacheRoot();
|
|
17364
17657
|
}
|
|
17365
17658
|
function hasOpenCodeCli() {
|
|
17366
17659
|
try {
|
|
@@ -17373,16 +17666,16 @@ function hasOpenCodeCli() {
|
|
|
17373
17666
|
function openCodeDesktopAppExists() {
|
|
17374
17667
|
const candidates = [];
|
|
17375
17668
|
if (process.platform === "darwin") {
|
|
17376
|
-
candidates.push("/Applications/OpenCode.app", "/Applications/OpenCode Beta.app",
|
|
17669
|
+
candidates.push("/Applications/OpenCode.app", "/Applications/OpenCode Beta.app", join16(homedir14(), "Applications", "OpenCode.app"), join16(homedir14(), "Applications", "OpenCode Beta.app"));
|
|
17377
17670
|
} else if (process.platform === "win32") {
|
|
17378
|
-
const localAppData = process.env.LOCALAPPDATA ??
|
|
17379
|
-
candidates.push(
|
|
17671
|
+
const localAppData = process.env.LOCALAPPDATA ?? join16(homedir14(), "AppData", "Local");
|
|
17672
|
+
candidates.push(join16(localAppData, "Programs", "opencode"), join16(localAppData, "opencode"));
|
|
17380
17673
|
} else {
|
|
17381
|
-
candidates.push("/opt/OpenCode", "/usr/lib/opencode",
|
|
17674
|
+
candidates.push("/opt/OpenCode", "/usr/lib/opencode", join16(homedir14(), ".local", "share", "applications", "opencode.desktop"));
|
|
17382
17675
|
}
|
|
17383
17676
|
return candidates.some((p) => {
|
|
17384
17677
|
try {
|
|
17385
|
-
return
|
|
17678
|
+
return existsSync13(p);
|
|
17386
17679
|
} catch {
|
|
17387
17680
|
return false;
|
|
17388
17681
|
}
|
|
@@ -17405,13 +17698,13 @@ function pathPointsToOurPlugin(entry) {
|
|
|
17405
17698
|
if (!fsPath)
|
|
17406
17699
|
return false;
|
|
17407
17700
|
try {
|
|
17408
|
-
if (!
|
|
17701
|
+
if (!existsSync13(fsPath))
|
|
17409
17702
|
return false;
|
|
17410
17703
|
let searchDir = statSync8(fsPath).isDirectory() ? fsPath : dirname7(fsPath);
|
|
17411
17704
|
let pkgJsonPath = null;
|
|
17412
17705
|
while (true) {
|
|
17413
|
-
const candidate =
|
|
17414
|
-
if (
|
|
17706
|
+
const candidate = join16(searchDir, "package.json");
|
|
17707
|
+
if (existsSync13(candidate)) {
|
|
17415
17708
|
pkgJsonPath = candidate;
|
|
17416
17709
|
break;
|
|
17417
17710
|
}
|
|
@@ -17442,7 +17735,7 @@ class OpenCodeAdapter {
|
|
|
17442
17735
|
pluginPackageName = PLUGIN_NAME;
|
|
17443
17736
|
pluginEntryWithVersion = PLUGIN_ENTRY;
|
|
17444
17737
|
isInstalled() {
|
|
17445
|
-
if (
|
|
17738
|
+
if (existsSync13(getOpenCodeConfigDir()))
|
|
17446
17739
|
return true;
|
|
17447
17740
|
if (openCodeDesktopAppExists())
|
|
17448
17741
|
return true;
|
|
@@ -17463,7 +17756,7 @@ class OpenCodeAdapter {
|
|
|
17463
17756
|
const configDir = getOpenCodeConfigDir();
|
|
17464
17757
|
const harness = detectJsoncFile(configDir, "opencode");
|
|
17465
17758
|
const aftConfigPath = resolveCortexKitUserConfigPath();
|
|
17466
|
-
const aftConfigExists =
|
|
17759
|
+
const aftConfigExists = existsSync13(aftConfigPath);
|
|
17467
17760
|
const tui = detectJsoncFile(configDir, "tui");
|
|
17468
17761
|
return {
|
|
17469
17762
|
configDir,
|
|
@@ -17581,11 +17874,11 @@ class OpenCodeAdapter {
|
|
|
17581
17874
|
};
|
|
17582
17875
|
}
|
|
17583
17876
|
getPluginCacheInfo() {
|
|
17584
|
-
const path2 =
|
|
17877
|
+
const path2 = join16(getOpenCodeCacheDir(), "packages", PLUGIN_ENTRY);
|
|
17585
17878
|
let cached;
|
|
17586
17879
|
try {
|
|
17587
|
-
const installedPkgPath =
|
|
17588
|
-
if (
|
|
17880
|
+
const installedPkgPath = join16(path2, "node_modules", "@cortexkit", "aft-opencode", "package.json");
|
|
17881
|
+
if (existsSync13(installedPkgPath)) {
|
|
17589
17882
|
const pkg = JSON.parse(readFileSync8(installedPkgPath, "utf-8"));
|
|
17590
17883
|
cached = typeof pkg.version === "string" ? pkg.version : undefined;
|
|
17591
17884
|
}
|
|
@@ -17596,7 +17889,7 @@ class OpenCodeAdapter {
|
|
|
17596
17889
|
path: path2,
|
|
17597
17890
|
cached,
|
|
17598
17891
|
latest: getSelfVersion(),
|
|
17599
|
-
exists:
|
|
17892
|
+
exists: existsSync13(path2)
|
|
17600
17893
|
};
|
|
17601
17894
|
}
|
|
17602
17895
|
getStorageDir() {
|
|
@@ -17610,8 +17903,21 @@ class OpenCodeAdapter {
|
|
|
17610
17903
|
}
|
|
17611
17904
|
async clearPluginCache(force) {
|
|
17612
17905
|
const info = this.getPluginCacheInfo();
|
|
17906
|
+
const clearLegacy = force ? clearLegacyOpenCodePluginCache(info.path) : { clearedPath: null };
|
|
17907
|
+
if (clearLegacy.error) {
|
|
17908
|
+
return {
|
|
17909
|
+
action: "error",
|
|
17910
|
+
path: info.path,
|
|
17911
|
+
error: `Could not clear legacy OpenCode cache: ${clearLegacy.error}`,
|
|
17912
|
+
...clearLegacy.clearedPath ? { legacy_path_cleared: clearLegacy.clearedPath } : {}
|
|
17913
|
+
};
|
|
17914
|
+
}
|
|
17613
17915
|
if (!info.exists) {
|
|
17614
|
-
return
|
|
17916
|
+
return clearLegacy.clearedPath ? {
|
|
17917
|
+
action: "legacy_path_cleared",
|
|
17918
|
+
path: clearLegacy.clearedPath,
|
|
17919
|
+
legacy_path_cleared: clearLegacy.clearedPath
|
|
17920
|
+
} : { action: "not_found", path: info.path };
|
|
17615
17921
|
}
|
|
17616
17922
|
if (!force && info.cached && info.cached === info.latest) {
|
|
17617
17923
|
return {
|
|
@@ -17627,7 +17933,8 @@ class OpenCodeAdapter {
|
|
|
17627
17933
|
action: "cleared",
|
|
17628
17934
|
path: info.path,
|
|
17629
17935
|
cached: info.cached,
|
|
17630
|
-
latest: info.latest
|
|
17936
|
+
latest: info.latest,
|
|
17937
|
+
...clearLegacy.clearedPath ? { legacy_path_cleared: clearLegacy.clearedPath } : {}
|
|
17631
17938
|
};
|
|
17632
17939
|
} catch (error2) {
|
|
17633
17940
|
return {
|
|
@@ -17645,12 +17952,12 @@ class OpenCodeAdapter {
|
|
|
17645
17952
|
describeStorageSubtrees() {
|
|
17646
17953
|
const storage = this.getStorageDir();
|
|
17647
17954
|
return {
|
|
17648
|
-
index: dirSize(
|
|
17649
|
-
semantic: dirSize(
|
|
17650
|
-
backups: dirSize(
|
|
17651
|
-
url_cache: dirSize(
|
|
17652
|
-
onnxruntime: dirSize(
|
|
17653
|
-
logs: dirSize(
|
|
17955
|
+
index: dirSize(join16(storage, "index")),
|
|
17956
|
+
semantic: dirSize(join16(storage, "semantic")),
|
|
17957
|
+
backups: dirSize(join16(storage, "backups")),
|
|
17958
|
+
url_cache: dirSize(join16(storage, "url_cache")),
|
|
17959
|
+
onnxruntime: dirSize(join16(storage, "onnxruntime")),
|
|
17960
|
+
logs: dirSize(join16(storage, "logs"))
|
|
17654
17961
|
};
|
|
17655
17962
|
}
|
|
17656
17963
|
}
|
|
@@ -17665,21 +17972,21 @@ var init_opencode = __esm(() => {
|
|
|
17665
17972
|
});
|
|
17666
17973
|
|
|
17667
17974
|
// src/adapters/pi.ts
|
|
17668
|
-
import { execSync as execSync4, spawnSync as
|
|
17669
|
-
import { existsSync as
|
|
17975
|
+
import { execSync as execSync4, spawnSync as spawnSync5 } from "node:child_process";
|
|
17976
|
+
import { existsSync as existsSync14, readFileSync as readFileSync9 } from "node:fs";
|
|
17670
17977
|
import { homedir as homedir15 } from "node:os";
|
|
17671
|
-
import { join as
|
|
17978
|
+
import { join as join17, resolve as resolve9 } from "node:path";
|
|
17672
17979
|
function getPiAgentDir() {
|
|
17673
17980
|
const configuredDir = process.env.PI_CODING_AGENT_DIR?.trim();
|
|
17674
17981
|
if (configuredDir)
|
|
17675
17982
|
return resolve9(configuredDir);
|
|
17676
17983
|
const envHome = process.platform === "win32" ? process.env.USERPROFILE : process.env.HOME;
|
|
17677
17984
|
const home = envHome && envHome.length > 0 ? envHome : homedir15();
|
|
17678
|
-
return
|
|
17985
|
+
return join17(home, ".pi", "agent");
|
|
17679
17986
|
}
|
|
17680
17987
|
function readPiExtensionIndex() {
|
|
17681
|
-
const settingsPath =
|
|
17682
|
-
if (
|
|
17988
|
+
const settingsPath = join17(getPiAgentDir(), "settings.json");
|
|
17989
|
+
if (existsSync14(settingsPath)) {
|
|
17683
17990
|
try {
|
|
17684
17991
|
const raw = readFileSync9(settingsPath, "utf-8");
|
|
17685
17992
|
const trimmed = raw.replace(/^\uFEFF/, "");
|
|
@@ -17699,13 +18006,13 @@ function readPiExtensionIndex() {
|
|
|
17699
18006
|
} catch {}
|
|
17700
18007
|
}
|
|
17701
18008
|
const candidates = [
|
|
17702
|
-
|
|
17703
|
-
|
|
17704
|
-
|
|
17705
|
-
|
|
18009
|
+
join17(getPiAgentDir(), "extensions.json"),
|
|
18010
|
+
join17(getPiAgentDir(), "extensions.jsonc"),
|
|
18011
|
+
join17(getPiAgentDir(), "config.json"),
|
|
18012
|
+
join17(getPiAgentDir(), "config.jsonc")
|
|
17706
18013
|
];
|
|
17707
18014
|
for (const path2 of candidates) {
|
|
17708
|
-
if (!
|
|
18015
|
+
if (!existsSync14(path2))
|
|
17709
18016
|
continue;
|
|
17710
18017
|
try {
|
|
17711
18018
|
const { value } = readJsoncFile(path2);
|
|
@@ -17738,15 +18045,15 @@ function piEntryMatchesAft(entry) {
|
|
|
17738
18045
|
} else if (entry.startsWith("/")) {
|
|
17739
18046
|
resolved = entry;
|
|
17740
18047
|
} else if (entry.length > 0) {
|
|
17741
|
-
resolved =
|
|
18048
|
+
resolved = join17(getPiAgentDir(), entry);
|
|
17742
18049
|
}
|
|
17743
18050
|
if (!resolved)
|
|
17744
18051
|
return false;
|
|
17745
18052
|
try {
|
|
17746
|
-
if (!
|
|
18053
|
+
if (!existsSync14(resolved))
|
|
17747
18054
|
return false;
|
|
17748
|
-
const pkgPath =
|
|
17749
|
-
if (!
|
|
18055
|
+
const pkgPath = join17(resolved, "package.json");
|
|
18056
|
+
if (!existsSync14(pkgPath))
|
|
17750
18057
|
return false;
|
|
17751
18058
|
const pkg = JSON.parse(readFileSync9(pkgPath, "utf-8"));
|
|
17752
18059
|
return pkg.name === PLUGIN_NAME2;
|
|
@@ -17774,7 +18081,7 @@ class PiAdapter {
|
|
|
17774
18081
|
}
|
|
17775
18082
|
getHostVersion() {
|
|
17776
18083
|
try {
|
|
17777
|
-
const result =
|
|
18084
|
+
const result = spawnSync5("pi", ["--version"], {
|
|
17778
18085
|
stdio: ["ignore", "pipe", "pipe"],
|
|
17779
18086
|
encoding: "utf-8",
|
|
17780
18087
|
timeout: 5000
|
|
@@ -17794,10 +18101,10 @@ class PiAdapter {
|
|
|
17794
18101
|
const configDir = getPiAgentDir();
|
|
17795
18102
|
const index = readPiExtensionIndex();
|
|
17796
18103
|
const aftConfigPath = resolveCortexKitUserConfigPath();
|
|
17797
|
-
const aftConfigExists =
|
|
18104
|
+
const aftConfigExists = existsSync14(aftConfigPath);
|
|
17798
18105
|
return {
|
|
17799
18106
|
configDir,
|
|
17800
|
-
harnessConfig: index.path ??
|
|
18107
|
+
harnessConfig: index.path ?? join17(configDir, "extensions.json"),
|
|
17801
18108
|
harnessConfigFormat: index.path ? "json" : "none",
|
|
17802
18109
|
aftConfig: aftConfigPath,
|
|
17803
18110
|
aftConfigFormat: aftConfigExists ? "jsonc" : "none"
|
|
@@ -17842,12 +18149,12 @@ class PiAdapter {
|
|
|
17842
18149
|
}
|
|
17843
18150
|
getPluginCacheInfo() {
|
|
17844
18151
|
const candidates = [
|
|
17845
|
-
|
|
17846
|
-
|
|
17847
|
-
|
|
18152
|
+
join17(getPiAgentDir(), "npm", "node_modules", "@cortexkit", "aft-pi", "package.json"),
|
|
18153
|
+
join17(getPiAgentDir(), "node_modules", "@cortexkit", "aft-pi", "package.json"),
|
|
18154
|
+
join17(getPiAgentDir(), "extensions", "node_modules", "@cortexkit", "aft-pi", "package.json")
|
|
17848
18155
|
];
|
|
17849
18156
|
for (const candidate of candidates) {
|
|
17850
|
-
if (!
|
|
18157
|
+
if (!existsSync14(candidate))
|
|
17851
18158
|
continue;
|
|
17852
18159
|
try {
|
|
17853
18160
|
const pkg = JSON.parse(readFileSync9(candidate, "utf-8"));
|
|
@@ -17861,7 +18168,7 @@ class PiAdapter {
|
|
|
17861
18168
|
} catch {}
|
|
17862
18169
|
}
|
|
17863
18170
|
return {
|
|
17864
|
-
path:
|
|
18171
|
+
path: join17(getPiAgentDir(), "npm", "node_modules", "@cortexkit", "aft-pi", "package.json"),
|
|
17865
18172
|
exists: false
|
|
17866
18173
|
};
|
|
17867
18174
|
}
|
|
@@ -17883,12 +18190,12 @@ class PiAdapter {
|
|
|
17883
18190
|
describeStorageSubtrees() {
|
|
17884
18191
|
const storage = this.getStorageDir();
|
|
17885
18192
|
return {
|
|
17886
|
-
index: dirSize(
|
|
17887
|
-
semantic: dirSize(
|
|
17888
|
-
backups: dirSize(
|
|
17889
|
-
url_cache: dirSize(
|
|
17890
|
-
onnxruntime: dirSize(
|
|
17891
|
-
logs: dirSize(
|
|
18193
|
+
index: dirSize(join17(storage, "index")),
|
|
18194
|
+
semantic: dirSize(join17(storage, "semantic")),
|
|
18195
|
+
backups: dirSize(join17(storage, "backups")),
|
|
18196
|
+
url_cache: dirSize(join17(storage, "url_cache")),
|
|
18197
|
+
onnxruntime: dirSize(join17(storage, "onnxruntime")),
|
|
18198
|
+
logs: dirSize(join17(storage, "logs"))
|
|
17892
18199
|
};
|
|
17893
18200
|
}
|
|
17894
18201
|
}
|
|
@@ -19345,14 +19652,14 @@ var exports_commands = {};
|
|
|
19345
19652
|
__export(exports_commands, {
|
|
19346
19653
|
runIndex: () => runIndex
|
|
19347
19654
|
});
|
|
19348
|
-
import { spawnSync as
|
|
19655
|
+
import { spawnSync as spawnSync6 } from "node:child_process";
|
|
19349
19656
|
function runIndex(argv) {
|
|
19350
19657
|
const binary = findAftBinary();
|
|
19351
19658
|
if (!binary) {
|
|
19352
19659
|
console.error("aft index requires a native AFT binary; run `aft doctor` to install or repair it.");
|
|
19353
19660
|
return 1;
|
|
19354
19661
|
}
|
|
19355
|
-
const result =
|
|
19662
|
+
const result = spawnSync6(binary, ["index", ...argv], {
|
|
19356
19663
|
stdio: "inherit",
|
|
19357
19664
|
env: process.env
|
|
19358
19665
|
});
|
|
@@ -19367,7 +19674,7 @@ var init_commands = __esm(async () => {
|
|
|
19367
19674
|
});
|
|
19368
19675
|
|
|
19369
19676
|
// src/lib/aft-bridge.ts
|
|
19370
|
-
import { spawn as
|
|
19677
|
+
import { spawn as spawn4 } from "node:child_process";
|
|
19371
19678
|
function isResponseForRequest(parsed, expectedIds) {
|
|
19372
19679
|
if (!parsed || typeof parsed !== "object")
|
|
19373
19680
|
return false;
|
|
@@ -19386,7 +19693,7 @@ async function sendAftRequest(binaryPath, request) {
|
|
|
19386
19693
|
}
|
|
19387
19694
|
async function sendAftRequests(binaryPath, requests) {
|
|
19388
19695
|
return new Promise((resolve10, reject) => {
|
|
19389
|
-
const child =
|
|
19696
|
+
const child = spawn4(binaryPath, [], {
|
|
19390
19697
|
stdio: ["pipe", "pipe", "pipe"]
|
|
19391
19698
|
});
|
|
19392
19699
|
const responses = [];
|
|
@@ -19501,21 +19808,21 @@ __export(exports_lsp, {
|
|
|
19501
19808
|
runLspDoctor: () => runLspDoctor,
|
|
19502
19809
|
typescriptPackageWarning: () => typescriptPackageWarning
|
|
19503
19810
|
});
|
|
19504
|
-
import { existsSync as
|
|
19811
|
+
import { existsSync as existsSync15, readdirSync as readdirSync5, statSync as statSync9 } from "node:fs";
|
|
19505
19812
|
import { createRequire as createRequire4 } from "node:module";
|
|
19506
|
-
import { dirname as dirname8, join as
|
|
19813
|
+
import { dirname as dirname8, join as join18, resolve as resolve10 } from "node:path";
|
|
19507
19814
|
function findProjectRootForFile(filePath, fallbackCwd = process.cwd()) {
|
|
19508
19815
|
const resolvedFile = resolve10(fallbackCwd, filePath);
|
|
19509
19816
|
let dir = dirname8(resolvedFile);
|
|
19510
19817
|
try {
|
|
19511
|
-
if (
|
|
19818
|
+
if (existsSync15(resolvedFile) && statSync9(resolvedFile).isDirectory()) {
|
|
19512
19819
|
dir = resolvedFile;
|
|
19513
19820
|
}
|
|
19514
19821
|
} catch {
|
|
19515
19822
|
dir = dirname8(resolvedFile);
|
|
19516
19823
|
}
|
|
19517
19824
|
while (true) {
|
|
19518
|
-
if (PROJECT_ROOT_MARKERS.some((marker) =>
|
|
19825
|
+
if (PROJECT_ROOT_MARKERS.some((marker) => existsSync15(join18(dir, marker)))) {
|
|
19519
19826
|
return dir;
|
|
19520
19827
|
}
|
|
19521
19828
|
const parent = dirname8(dir);
|
|
@@ -19652,9 +19959,9 @@ function parseFileArg(argv) {
|
|
|
19652
19959
|
function buildConfigureParams(adapter, projectRoot) {
|
|
19653
19960
|
const userConfigPath = adapter.detectConfigPaths().aftConfig;
|
|
19654
19961
|
const dir = adapter.kind === "pi" ? ".pi" : ".opencode";
|
|
19655
|
-
const projectJsonc =
|
|
19656
|
-
const projectJson =
|
|
19657
|
-
const projectConfigPath =
|
|
19962
|
+
const projectJsonc = join18(projectRoot, dir, "aft.jsonc");
|
|
19963
|
+
const projectJson = join18(projectRoot, dir, "aft.json");
|
|
19964
|
+
const projectConfigPath = existsSync15(projectJsonc) ? projectJsonc : projectJson;
|
|
19658
19965
|
return {
|
|
19659
19966
|
id: "doctor-lsp-configure",
|
|
19660
19967
|
command: "configure",
|
|
@@ -19667,18 +19974,18 @@ function buildConfigureParams(adapter, projectRoot) {
|
|
|
19667
19974
|
function inferLspPathsExtra(_lsp) {
|
|
19668
19975
|
const paths = new Set;
|
|
19669
19976
|
for (const entry of childDirs(getAftLspPackagesDir())) {
|
|
19670
|
-
paths.add(
|
|
19977
|
+
paths.add(join18(entry, "node_modules", ".bin"));
|
|
19671
19978
|
}
|
|
19672
19979
|
for (const entry of childDirs(getAftLspBinariesDir())) {
|
|
19673
|
-
paths.add(
|
|
19980
|
+
paths.add(join18(entry, "bin"));
|
|
19674
19981
|
}
|
|
19675
19982
|
return [...paths];
|
|
19676
19983
|
}
|
|
19677
19984
|
function childDirs(path2) {
|
|
19678
|
-
if (!
|
|
19985
|
+
if (!existsSync15(path2))
|
|
19679
19986
|
return [];
|
|
19680
19987
|
try {
|
|
19681
|
-
return readdirSync5(path2).map((entry) =>
|
|
19988
|
+
return readdirSync5(path2).map((entry) => join18(path2, entry)).filter((entry) => {
|
|
19682
19989
|
try {
|
|
19683
19990
|
return statSync9(entry).isDirectory();
|
|
19684
19991
|
} catch {
|
|
@@ -19720,7 +20027,7 @@ function typescriptPackageWarning(response) {
|
|
|
19720
20027
|
if (!typescriptServerSpawned || !response.project_root || diagnosticsCount > 0)
|
|
19721
20028
|
return null;
|
|
19722
20029
|
try {
|
|
19723
|
-
createRequire4(
|
|
20030
|
+
createRequire4(join18(response.project_root, "package.json")).resolve("typescript");
|
|
19724
20031
|
return null;
|
|
19725
20032
|
} catch {
|
|
19726
20033
|
return "typescript package not resolvable from project — server will produce no diagnostics";
|
|
@@ -19768,7 +20075,7 @@ __export(exports_doctor_filters, {
|
|
|
19768
20075
|
renderTrustedProjects: () => renderTrustedProjects,
|
|
19769
20076
|
runDoctorFilters: () => runDoctorFilters
|
|
19770
20077
|
});
|
|
19771
|
-
import { existsSync as
|
|
20078
|
+
import { existsSync as existsSync16 } from "node:fs";
|
|
19772
20079
|
import { homedir as homedir16 } from "node:os";
|
|
19773
20080
|
import { relative as relative3, resolve as resolve11 } from "node:path";
|
|
19774
20081
|
function printDoctorFiltersHelp() {
|
|
@@ -19811,7 +20118,7 @@ async function runDoctorFilters(options) {
|
|
|
19811
20118
|
log2.error(list.message ?? list.code ?? "list_filters failed");
|
|
19812
20119
|
return 1;
|
|
19813
20120
|
}
|
|
19814
|
-
list.project_dir_exists = list.project_dir ?
|
|
20121
|
+
list.project_dir_exists = list.project_dir ? existsSync16(list.project_dir) : false;
|
|
19815
20122
|
if (mode.kind === "list") {
|
|
19816
20123
|
console.log(renderFilterList(list, projectRoot));
|
|
19817
20124
|
return 0;
|
|
@@ -20010,11 +20317,11 @@ var init_doctor_filters = __esm(async () => {
|
|
|
20010
20317
|
});
|
|
20011
20318
|
|
|
20012
20319
|
// src/lib/binary-cache.ts
|
|
20013
|
-
import { existsSync as
|
|
20014
|
-
import { join as
|
|
20320
|
+
import { existsSync as existsSync17, readdirSync as readdirSync6, statSync as statSync10 } from "node:fs";
|
|
20321
|
+
import { join as join19 } from "node:path";
|
|
20015
20322
|
function getBinaryCacheInfo(activeVersion) {
|
|
20016
20323
|
const path2 = getAftBinaryCacheDir();
|
|
20017
|
-
if (!
|
|
20324
|
+
if (!existsSync17(path2)) {
|
|
20018
20325
|
return {
|
|
20019
20326
|
versions: [],
|
|
20020
20327
|
activeVersion: null,
|
|
@@ -20024,7 +20331,7 @@ function getBinaryCacheInfo(activeVersion) {
|
|
|
20024
20331
|
}
|
|
20025
20332
|
const versions = readdirSync6(path2).filter((entry) => {
|
|
20026
20333
|
try {
|
|
20027
|
-
return statSync10(
|
|
20334
|
+
return statSync10(join19(path2, entry)).isDirectory();
|
|
20028
20335
|
} catch {
|
|
20029
20336
|
return false;
|
|
20030
20337
|
}
|
|
@@ -20122,13 +20429,13 @@ var init_sanitize = __esm(() => {
|
|
|
20122
20429
|
});
|
|
20123
20430
|
|
|
20124
20431
|
// src/lib/bridge-tool-failures.ts
|
|
20125
|
-
import { closeSync as closeSync5, existsSync as
|
|
20432
|
+
import { closeSync as closeSync5, existsSync as existsSync18, openSync as openSync5, readSync as readSync2, statSync as statSync11 } from "node:fs";
|
|
20126
20433
|
function resolveBridgePluginLogPath() {
|
|
20127
20434
|
const isTestEnv = process.env.BUN_TEST === "1" || false;
|
|
20128
20435
|
return resolveAftLogPath(isTestEnv ? "aft-plugin-test.log" : "aft-plugin.log");
|
|
20129
20436
|
}
|
|
20130
20437
|
function tailLogFileBytes(path2, maxBytes) {
|
|
20131
|
-
if (!
|
|
20438
|
+
if (!existsSync18(path2) || maxBytes <= 0)
|
|
20132
20439
|
return "";
|
|
20133
20440
|
let fd = null;
|
|
20134
20441
|
try {
|
|
@@ -20264,15 +20571,15 @@ var init_bridge_tool_failures = __esm(() => {
|
|
|
20264
20571
|
});
|
|
20265
20572
|
|
|
20266
20573
|
// src/lib/build-breaker.ts
|
|
20267
|
-
import { existsSync as
|
|
20268
|
-
import { join as
|
|
20574
|
+
import { existsSync as existsSync19, readdirSync as readdirSync7 } from "node:fs";
|
|
20575
|
+
import { join as join20 } from "node:path";
|
|
20269
20576
|
import { DatabaseSync } from "node:sqlite";
|
|
20270
20577
|
function buildBreakerDatabases(storageRoot) {
|
|
20271
|
-
const callgraphRoot =
|
|
20272
|
-
if (!
|
|
20578
|
+
const callgraphRoot = join20(storageRoot, "callgraph");
|
|
20579
|
+
if (!existsSync19(callgraphRoot))
|
|
20273
20580
|
return [];
|
|
20274
20581
|
try {
|
|
20275
|
-
return readdirSync7(callgraphRoot, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) =>
|
|
20582
|
+
return readdirSync7(callgraphRoot, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => join20(callgraphRoot, entry.name, "build-breaker.sqlite")).filter((path2) => existsSync19(path2));
|
|
20276
20583
|
} catch {
|
|
20277
20584
|
return [];
|
|
20278
20585
|
}
|
|
@@ -20348,20 +20655,20 @@ var init_build_breaker = __esm(() => {
|
|
|
20348
20655
|
});
|
|
20349
20656
|
|
|
20350
20657
|
// src/lib/legacy-storage.ts
|
|
20351
|
-
import { existsSync as
|
|
20352
|
-
import { join as
|
|
20658
|
+
import { existsSync as existsSync20, readdirSync as readdirSync8, statSync as statSync12 } from "node:fs";
|
|
20659
|
+
import { join as join21 } from "node:path";
|
|
20353
20660
|
function summarizeLegacyPartitionDuplication(storageRoot) {
|
|
20354
|
-
if (!
|
|
20661
|
+
if (!existsSync20(storageRoot)) {
|
|
20355
20662
|
return { totalPartitions: 0, totalBytes: 0, byHarness: [] };
|
|
20356
20663
|
}
|
|
20357
20664
|
const byHarness = [];
|
|
20358
20665
|
for (const harness of safeReadDir(storageRoot)) {
|
|
20359
|
-
const harnessPath =
|
|
20666
|
+
const harnessPath = join21(storageRoot, harness);
|
|
20360
20667
|
if (!isDirectory(harnessPath))
|
|
20361
20668
|
continue;
|
|
20362
20669
|
const partitions = new Map;
|
|
20363
|
-
collectCallgraphPartitions(
|
|
20364
|
-
collectInspectPartitions(
|
|
20670
|
+
collectCallgraphPartitions(join21(harnessPath, "callgraph"), partitions);
|
|
20671
|
+
collectInspectPartitions(join21(harnessPath, "inspect"), partitions);
|
|
20365
20672
|
if (partitions.size === 0)
|
|
20366
20673
|
continue;
|
|
20367
20674
|
let bytes = 0;
|
|
@@ -20380,7 +20687,7 @@ function collectCallgraphPartitions(domainPath, partitions) {
|
|
|
20380
20687
|
if (!isDirectory(domainPath))
|
|
20381
20688
|
return;
|
|
20382
20689
|
for (const name of safeReadDir(domainPath)) {
|
|
20383
|
-
const path2 =
|
|
20690
|
+
const path2 = join21(domainPath, name);
|
|
20384
20691
|
if (isDirectory(path2)) {
|
|
20385
20692
|
if (!looksLikePartitionKey(name))
|
|
20386
20693
|
continue;
|
|
@@ -20397,7 +20704,7 @@ function collectInspectPartitions(domainPath, partitions) {
|
|
|
20397
20704
|
if (!isDirectory(domainPath))
|
|
20398
20705
|
return;
|
|
20399
20706
|
for (const name of safeReadDir(domainPath)) {
|
|
20400
|
-
const path2 =
|
|
20707
|
+
const path2 = join21(domainPath, name);
|
|
20401
20708
|
if (isDirectory(path2)) {
|
|
20402
20709
|
if (!looksLikePartitionKey(name))
|
|
20403
20710
|
continue;
|
|
@@ -20472,10 +20779,10 @@ var init_legacy_storage = __esm(() => {
|
|
|
20472
20779
|
});
|
|
20473
20780
|
|
|
20474
20781
|
// src/lib/lsp-cache.ts
|
|
20475
|
-
import { existsSync as
|
|
20476
|
-
import { join as
|
|
20782
|
+
import { existsSync as existsSync21, readdirSync as readdirSync9, rmSync as rmSync5, statSync as statSync13 } from "node:fs";
|
|
20783
|
+
import { join as join22 } from "node:path";
|
|
20477
20784
|
function inspectDir(path2) {
|
|
20478
|
-
if (!
|
|
20785
|
+
if (!existsSync21(path2)) {
|
|
20479
20786
|
return { entries: [], totalSize: 0 };
|
|
20480
20787
|
}
|
|
20481
20788
|
const entries = [];
|
|
@@ -20487,7 +20794,7 @@ function inspectDir(path2) {
|
|
|
20487
20794
|
return { entries: [], totalSize: 0 };
|
|
20488
20795
|
}
|
|
20489
20796
|
for (const name of names) {
|
|
20490
|
-
const full =
|
|
20797
|
+
const full = join22(path2, name);
|
|
20491
20798
|
try {
|
|
20492
20799
|
if (!statSync13(full).isDirectory())
|
|
20493
20800
|
continue;
|
|
@@ -20545,8 +20852,8 @@ var init_lsp_cache = __esm(() => {
|
|
|
20545
20852
|
});
|
|
20546
20853
|
|
|
20547
20854
|
// src/lib/onnx.ts
|
|
20548
|
-
import { existsSync as
|
|
20549
|
-
import { basename as basename3, isAbsolute as isAbsolute6, join as
|
|
20855
|
+
import { existsSync as existsSync22, readdirSync as readdirSync10, readlinkSync as readlinkSync2, realpathSync as realpathSync4 } from "node:fs";
|
|
20856
|
+
import { basename as basename3, isAbsolute as isAbsolute6, join as join23, resolve as resolve12, win32 as win322 } from "node:path";
|
|
20550
20857
|
function getOnnxLibraryName() {
|
|
20551
20858
|
if (process.platform === "darwin")
|
|
20552
20859
|
return "libonnxruntime.dylib";
|
|
@@ -20579,8 +20886,8 @@ function pathEnvValue2() {
|
|
|
20579
20886
|
return process.env.PATH ?? process.env.Path ?? process.env.path ?? "";
|
|
20580
20887
|
}
|
|
20581
20888
|
function pathEntriesForPlatform2() {
|
|
20582
|
-
const
|
|
20583
|
-
return pathEnvValue2().split(
|
|
20889
|
+
const delimiter3 = process.platform === "win32" ? ";" : ":";
|
|
20890
|
+
return pathEnvValue2().split(delimiter3).map((entry) => entry.trim().replace(/^"|"$/g, "")).filter((entry) => {
|
|
20584
20891
|
if (!entry || entry === "." || entry.includes("\x00"))
|
|
20585
20892
|
return false;
|
|
20586
20893
|
return isAbsolute6(entry) || win322.isAbsolute(entry);
|
|
@@ -20617,7 +20924,7 @@ function findIgnoredWindowsSystemOnnxRuntime() {
|
|
|
20617
20924
|
for (const root of windowsRoots) {
|
|
20618
20925
|
if (!root)
|
|
20619
20926
|
continue;
|
|
20620
|
-
const systemDir =
|
|
20927
|
+
const systemDir = join23(root, "System32");
|
|
20621
20928
|
const key = win322.resolve(systemDir).toLowerCase();
|
|
20622
20929
|
if (seen.has(key))
|
|
20623
20930
|
continue;
|
|
@@ -20638,13 +20945,13 @@ function findSystemOnnxRuntime2() {
|
|
|
20638
20945
|
searchPaths.push(...pathEntriesForPlatform2());
|
|
20639
20946
|
const programFiles = process.env.ProgramFiles ?? "C:\\Program Files";
|
|
20640
20947
|
const programFilesX86 = process.env["ProgramFiles(x86)"] ?? "C:\\Program Files (x86)";
|
|
20641
|
-
searchPaths.push(
|
|
20948
|
+
searchPaths.push(join23(programFiles, "onnxruntime", "lib"), join23(programFiles, "Microsoft ONNX Runtime", "lib"), join23(programFiles, "Microsoft Machine Learning", "lib"), join23(programFilesX86, "onnxruntime", "lib"), ...(() => {
|
|
20642
20949
|
const nugetPaths = [];
|
|
20643
20950
|
const userProfile = process.env.USERPROFILE ?? "";
|
|
20644
20951
|
if (!userProfile)
|
|
20645
20952
|
return nugetPaths;
|
|
20646
|
-
const nugetPackageDir =
|
|
20647
|
-
if (!
|
|
20953
|
+
const nugetPackageDir = join23(userProfile, ".nuget", "packages", "microsoft.ml.onnxruntime");
|
|
20954
|
+
if (!existsSync22(nugetPackageDir))
|
|
20648
20955
|
return nugetPaths;
|
|
20649
20956
|
try {
|
|
20650
20957
|
for (const entry of readdirSync10(nugetPackageDir, { withFileTypes: true })) {
|
|
@@ -20652,7 +20959,7 @@ function findSystemOnnxRuntime2() {
|
|
|
20652
20959
|
continue;
|
|
20653
20960
|
if (entry.name === "__globalPackagesFolder" || entry.name.startsWith("."))
|
|
20654
20961
|
continue;
|
|
20655
|
-
nugetPaths.push(
|
|
20962
|
+
nugetPaths.push(join23(nugetPackageDir, entry.name, "runtimes", "win-x64", "native"), join23(nugetPackageDir, entry.name, "runtimes", "win-arm64", "native"));
|
|
20656
20963
|
}
|
|
20657
20964
|
} catch {}
|
|
20658
20965
|
return nugetPaths;
|
|
@@ -20684,12 +20991,12 @@ function findSystemOnnxRuntime2() {
|
|
|
20684
20991
|
return unknownVersionPaths[0] ?? null;
|
|
20685
20992
|
}
|
|
20686
20993
|
function findCachedOnnxRuntime(storageDir) {
|
|
20687
|
-
const ortDir =
|
|
20994
|
+
const ortDir = join23(storageDir, "onnxruntime", ONNX_RUNTIME_VERSION);
|
|
20688
20995
|
const libName = getOnnxLibraryName();
|
|
20689
|
-
if (
|
|
20996
|
+
if (existsSync22(join23(ortDir, libName)))
|
|
20690
20997
|
return ortDir;
|
|
20691
|
-
const libSubdir =
|
|
20692
|
-
if (
|
|
20998
|
+
const libSubdir = join23(ortDir, "lib");
|
|
20999
|
+
if (existsSync22(join23(libSubdir, libName)))
|
|
20693
21000
|
return libSubdir;
|
|
20694
21001
|
return null;
|
|
20695
21002
|
}
|
|
@@ -20710,7 +21017,7 @@ function parseOrtVersionFromDirectoryPath(value) {
|
|
|
20710
21017
|
return null;
|
|
20711
21018
|
}
|
|
20712
21019
|
function detectOrtVersion(libDir) {
|
|
20713
|
-
if (!
|
|
21020
|
+
if (!existsSync22(libDir))
|
|
20714
21021
|
return null;
|
|
20715
21022
|
const libName = getOnnxLibraryName();
|
|
20716
21023
|
try {
|
|
@@ -20725,8 +21032,8 @@ function detectOrtVersion(libDir) {
|
|
|
20725
21032
|
if (version)
|
|
20726
21033
|
return version;
|
|
20727
21034
|
}
|
|
20728
|
-
const base =
|
|
20729
|
-
if (
|
|
21035
|
+
const base = join23(libDir, libName);
|
|
21036
|
+
if (existsSync22(base)) {
|
|
20730
21037
|
try {
|
|
20731
21038
|
const real = realpathSync4(base);
|
|
20732
21039
|
const version = parseOrtVersionFromPath(real) ?? parseOrtVersionFromDirectoryPath(real);
|
|
@@ -20761,7 +21068,7 @@ import {
|
|
|
20761
21068
|
accessSync,
|
|
20762
21069
|
closeSync as closeSync6,
|
|
20763
21070
|
constants,
|
|
20764
|
-
existsSync as
|
|
21071
|
+
existsSync as existsSync23,
|
|
20765
21072
|
openSync as openSync6,
|
|
20766
21073
|
readSync as readSync3,
|
|
20767
21074
|
statSync as statSync14
|
|
@@ -20800,7 +21107,7 @@ async function diagnoseHarness(adapter) {
|
|
|
20800
21107
|
const logPath = adapter.getLogFile();
|
|
20801
21108
|
const pluginCache = adapter.getPluginCacheInfo();
|
|
20802
21109
|
const storageAccessible = (() => {
|
|
20803
|
-
if (!
|
|
21110
|
+
if (!existsSync23(storage))
|
|
20804
21111
|
return false;
|
|
20805
21112
|
try {
|
|
20806
21113
|
accessSync(storage, constants.R_OK | constants.W_OK);
|
|
@@ -20825,7 +21132,7 @@ async function diagnoseHarness(adapter) {
|
|
|
20825
21132
|
pluginRegistered: adapter.hasPluginEntry(),
|
|
20826
21133
|
configPaths,
|
|
20827
21134
|
aftConfig: {
|
|
20828
|
-
exists:
|
|
21135
|
+
exists: existsSync23(configPaths.aftConfig),
|
|
20829
21136
|
...aftConfigRead.error ? { parseError: aftConfigRead.error } : {},
|
|
20830
21137
|
enabled: aftEnabled,
|
|
20831
21138
|
...aftEnabledSource ? { enabledSource: aftEnabledSource } : {},
|
|
@@ -20834,7 +21141,7 @@ async function diagnoseHarness(adapter) {
|
|
|
20834
21141
|
pluginCache,
|
|
20835
21142
|
storageDir: {
|
|
20836
21143
|
path: storage,
|
|
20837
|
-
exists:
|
|
21144
|
+
exists: existsSync23(storage),
|
|
20838
21145
|
accessible: storageAccessible,
|
|
20839
21146
|
sizesByKey: describeStorage,
|
|
20840
21147
|
...legacyDuplication.totalPartitions > 0 ? { legacyDuplication } : {}
|
|
@@ -20855,8 +21162,8 @@ async function diagnoseHarness(adapter) {
|
|
|
20855
21162
|
},
|
|
20856
21163
|
logFile: {
|
|
20857
21164
|
path: logPath,
|
|
20858
|
-
exists:
|
|
20859
|
-
sizeKb:
|
|
21165
|
+
exists: existsSync23(logPath),
|
|
21166
|
+
sizeKb: existsSync23(logPath) ? Math.round(statSync14(logPath).size / 1024) : 0
|
|
20860
21167
|
}
|
|
20861
21168
|
};
|
|
20862
21169
|
}
|
|
@@ -21053,7 +21360,7 @@ function formatDiagnosticIssuesSection(report) {
|
|
|
21053
21360
|
return lines;
|
|
21054
21361
|
}
|
|
21055
21362
|
function tailLogFile(path2, lines) {
|
|
21056
|
-
if (!
|
|
21363
|
+
if (!existsSync23(path2))
|
|
21057
21364
|
return "";
|
|
21058
21365
|
if (lines <= 0)
|
|
21059
21366
|
return "";
|
|
@@ -21103,7 +21410,7 @@ var init_diagnostics = __esm(async () => {
|
|
|
21103
21410
|
});
|
|
21104
21411
|
|
|
21105
21412
|
// src/lib/github.ts
|
|
21106
|
-
import { execSync as execSync5, spawnSync as
|
|
21413
|
+
import { execSync as execSync5, spawnSync as spawnSync7 } from "node:child_process";
|
|
21107
21414
|
function isGhInstalled() {
|
|
21108
21415
|
try {
|
|
21109
21416
|
execSync5("gh --version", { stdio: "ignore" });
|
|
@@ -21119,14 +21426,14 @@ function openBrowser(url) {
|
|
|
21119
21426
|
const commands = getOpenBrowserCommand(url);
|
|
21120
21427
|
try {
|
|
21121
21428
|
const [cmd, args] = commands;
|
|
21122
|
-
|
|
21429
|
+
spawnSync7(cmd, args, { stdio: "ignore" });
|
|
21123
21430
|
} catch {}
|
|
21124
21431
|
}
|
|
21125
21432
|
function createGitHubIssue(repo, title, body) {
|
|
21126
21433
|
if (!isGhInstalled()) {
|
|
21127
21434
|
return { url: null, stderr: "gh CLI not installed" };
|
|
21128
21435
|
}
|
|
21129
|
-
const result =
|
|
21436
|
+
const result = spawnSync7("gh", ["issue", "create", "--repo", repo, "--title", title, "--body-file", "-"], {
|
|
21130
21437
|
input: body,
|
|
21131
21438
|
encoding: "utf-8",
|
|
21132
21439
|
stdio: ["pipe", "pipe", "pipe"]
|
|
@@ -21242,14 +21549,14 @@ var init_issue_body = __esm(() => {
|
|
|
21242
21549
|
});
|
|
21243
21550
|
|
|
21244
21551
|
// src/lib/onnx-fix.ts
|
|
21245
|
-
import { existsSync as
|
|
21246
|
-
import { join as
|
|
21552
|
+
import { existsSync as existsSync24, rmSync as rmSync6 } from "node:fs";
|
|
21553
|
+
import { join as join24 } from "node:path";
|
|
21247
21554
|
function findOnnxFixCandidates(report) {
|
|
21248
21555
|
const candidates = [];
|
|
21249
21556
|
for (const harness of report.harnesses) {
|
|
21250
21557
|
if (!harness.onnxRuntime.required)
|
|
21251
21558
|
continue;
|
|
21252
|
-
const storageOnnxDir =
|
|
21559
|
+
const storageOnnxDir = join24(harness.storageDir.path, "onnxruntime");
|
|
21253
21560
|
const systemTooOld = harness.onnxRuntime.systemPath !== null && harness.onnxRuntime.systemCompatible === false;
|
|
21254
21561
|
const cachedTooOld = harness.onnxRuntime.cachedPath !== null && harness.onnxRuntime.cachedCompatible === false;
|
|
21255
21562
|
const hasCompatibleCached = harness.onnxRuntime.cachedCompatible === true;
|
|
@@ -21258,7 +21565,7 @@ function findOnnxFixCandidates(report) {
|
|
|
21258
21565
|
harness,
|
|
21259
21566
|
reason: `cached ONNX Runtime at ${harness.onnxRuntime.cachedPath} is v${harness.onnxRuntime.cachedVersion}, but AFT requires ${harness.onnxRuntime.requirement}. Clearing it allows an immediate managed download.`,
|
|
21260
21567
|
storageOnnxDir,
|
|
21261
|
-
storageOnnxBytes:
|
|
21568
|
+
storageOnnxBytes: existsSync24(storageOnnxDir) ? dirSize(storageOnnxDir) : 0
|
|
21262
21569
|
});
|
|
21263
21570
|
continue;
|
|
21264
21571
|
}
|
|
@@ -21267,7 +21574,7 @@ function findOnnxFixCandidates(report) {
|
|
|
21267
21574
|
harness,
|
|
21268
21575
|
reason: `system ONNX Runtime at ${harness.onnxRuntime.systemPath} is v${harness.onnxRuntime.systemVersion}, but AFT requires ${harness.onnxRuntime.requirement}, and no AFT-managed install is present. AFT will leave the system copy untouched and download v1.24 into managed storage.`,
|
|
21269
21576
|
storageOnnxDir,
|
|
21270
|
-
storageOnnxBytes:
|
|
21577
|
+
storageOnnxBytes: existsSync24(storageOnnxDir) ? dirSize(storageOnnxDir) : 0
|
|
21271
21578
|
});
|
|
21272
21579
|
continue;
|
|
21273
21580
|
}
|
|
@@ -21277,7 +21584,7 @@ function findOnnxFixCandidates(report) {
|
|
|
21277
21584
|
harness,
|
|
21278
21585
|
reason: `no compatible ONNX Runtime is installed.${ignoredCopy} AFT will download v1.24 into managed storage.`,
|
|
21279
21586
|
storageOnnxDir,
|
|
21280
|
-
storageOnnxBytes:
|
|
21587
|
+
storageOnnxBytes: existsSync24(storageOnnxDir) ? dirSize(storageOnnxDir) : 0
|
|
21281
21588
|
});
|
|
21282
21589
|
}
|
|
21283
21590
|
}
|
|
@@ -21307,7 +21614,7 @@ async function runOnnxFix(adapters, report, options = {}) {
|
|
|
21307
21614
|
const rmFn = options.rmFn ?? rmSync6;
|
|
21308
21615
|
const ensureFn = options.ensureFn ?? ensureOnnxRuntime;
|
|
21309
21616
|
for (const candidate of candidates) {
|
|
21310
|
-
if (
|
|
21617
|
+
if (existsSync24(candidate.storageOnnxDir)) {
|
|
21311
21618
|
try {
|
|
21312
21619
|
rmFn(candidate.storageOnnxDir, { recursive: true, force: true });
|
|
21313
21620
|
result.cleared += 1;
|
|
@@ -21349,10 +21656,10 @@ var init_onnx_fix = __esm(() => {
|
|
|
21349
21656
|
});
|
|
21350
21657
|
|
|
21351
21658
|
// src/lib/sessions.ts
|
|
21352
|
-
import { existsSync as
|
|
21659
|
+
import { existsSync as existsSync25, readdirSync as readdirSync11, readFileSync as readFileSync10, statSync as statSync15 } from "node:fs";
|
|
21353
21660
|
import { createRequire as createRequire5 } from "node:module";
|
|
21354
21661
|
import { homedir as homedir18 } from "node:os";
|
|
21355
|
-
import { basename as basename4, join as
|
|
21662
|
+
import { basename as basename4, join as join25 } from "node:path";
|
|
21356
21663
|
function listRecentSessions(adapter) {
|
|
21357
21664
|
try {
|
|
21358
21665
|
if (adapter.kind === "opencode")
|
|
@@ -21381,8 +21688,8 @@ function mapOpenCodeSessionRows(rows) {
|
|
|
21381
21688
|
}).filter((session) => session !== null).sort((a3, b) => b.lastActivity - a3.lastActivity).slice(0, MAX_RECENT_SESSIONS);
|
|
21382
21689
|
}
|
|
21383
21690
|
function listRecentOpenCodeSessions() {
|
|
21384
|
-
const dbPath =
|
|
21385
|
-
if (!
|
|
21691
|
+
const dbPath = join25(getXdgDataHome(), "opencode", "opencode.db");
|
|
21692
|
+
if (!existsSync25(dbPath))
|
|
21386
21693
|
return [];
|
|
21387
21694
|
let db = null;
|
|
21388
21695
|
try {
|
|
@@ -21401,10 +21708,10 @@ function listRecentOpenCodeSessions() {
|
|
|
21401
21708
|
}
|
|
21402
21709
|
function getXdgDataHome() {
|
|
21403
21710
|
const xdgDataHome = process.env.XDG_DATA_HOME;
|
|
21404
|
-
return xdgDataHome && xdgDataHome.length > 0 ? xdgDataHome :
|
|
21711
|
+
return xdgDataHome && xdgDataHome.length > 0 ? xdgDataHome : join25(homedir18(), ".local", "share");
|
|
21405
21712
|
}
|
|
21406
21713
|
function listRecentPiSessions() {
|
|
21407
|
-
return listPiSessionsFromDir(
|
|
21714
|
+
return listPiSessionsFromDir(join25(getHomeDir(), ".pi", "agent", "sessions"));
|
|
21408
21715
|
}
|
|
21409
21716
|
function getHomeDir() {
|
|
21410
21717
|
const envHome = process.platform === "win32" ? process.env.USERPROFILE : process.env.HOME;
|
|
@@ -21412,7 +21719,7 @@ function getHomeDir() {
|
|
|
21412
21719
|
}
|
|
21413
21720
|
function listPiSessionsFromDir(sessionsDir) {
|
|
21414
21721
|
try {
|
|
21415
|
-
if (!
|
|
21722
|
+
if (!existsSync25(sessionsDir))
|
|
21416
21723
|
return [];
|
|
21417
21724
|
const files = collectJsonlFiles(sessionsDir).map((filePath) => {
|
|
21418
21725
|
try {
|
|
@@ -21450,7 +21757,7 @@ function collectJsonlFiles(root) {
|
|
|
21450
21757
|
continue;
|
|
21451
21758
|
}
|
|
21452
21759
|
for (const entry of entries) {
|
|
21453
|
-
const path2 =
|
|
21760
|
+
const path2 = join25(dir, entry.name);
|
|
21454
21761
|
if (entry.isDirectory()) {
|
|
21455
21762
|
stack.push(path2);
|
|
21456
21763
|
} else if (entry.isFile() && entry.name.endsWith(".jsonl")) {
|
|
@@ -21550,10 +21857,10 @@ __export(exports_doctor, {
|
|
|
21550
21857
|
runDoctorBuildBreakerReset: () => runDoctorBuildBreakerReset,
|
|
21551
21858
|
shouldSkipDoctorFixConfirmation: () => shouldSkipDoctorFixConfirmation
|
|
21552
21859
|
});
|
|
21553
|
-
import {
|
|
21860
|
+
import { spawn as spawn5 } from "node:child_process";
|
|
21554
21861
|
import {
|
|
21555
21862
|
chmodSync as chmodSync4,
|
|
21556
|
-
existsSync as
|
|
21863
|
+
existsSync as existsSync26,
|
|
21557
21864
|
mkdirSync as mkdirSync7,
|
|
21558
21865
|
mkdtempSync,
|
|
21559
21866
|
readFileSync as readFileSync11,
|
|
@@ -21563,7 +21870,7 @@ import {
|
|
|
21563
21870
|
writeFileSync as writeFileSync5
|
|
21564
21871
|
} from "node:fs";
|
|
21565
21872
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
21566
|
-
import { join as
|
|
21873
|
+
import { join as join26 } from "node:path";
|
|
21567
21874
|
async function runDoctor(options) {
|
|
21568
21875
|
if (options.issue) {
|
|
21569
21876
|
return runIssueFlow(options.argv);
|
|
@@ -21852,7 +22159,7 @@ function clearOldBinaries() {
|
|
|
21852
22159
|
errors: [],
|
|
21853
22160
|
keptVersion: keepTag
|
|
21854
22161
|
};
|
|
21855
|
-
if (!
|
|
22162
|
+
if (!existsSync26(info.path)) {
|
|
21856
22163
|
log2.info(`Binary cache: nothing to clear at ${info.path}`);
|
|
21857
22164
|
return result;
|
|
21858
22165
|
}
|
|
@@ -21862,7 +22169,7 @@ function clearOldBinaries() {
|
|
|
21862
22169
|
return result;
|
|
21863
22170
|
}
|
|
21864
22171
|
for (const version of stale) {
|
|
21865
|
-
const dir =
|
|
22172
|
+
const dir = join26(info.path, version);
|
|
21866
22173
|
let bytes = 0;
|
|
21867
22174
|
try {
|
|
21868
22175
|
bytes = statSync16(dir).isDirectory() ? dirSize(dir) : 0;
|
|
@@ -21931,6 +22238,64 @@ function findSchemaFixTargets(adapters) {
|
|
|
21931
22238
|
}
|
|
21932
22239
|
return targets;
|
|
21933
22240
|
}
|
|
22241
|
+
async function runDoctorNpmInstall(npm, installDir) {
|
|
22242
|
+
const invocation = npmInvocation(npm, [
|
|
22243
|
+
"install",
|
|
22244
|
+
"--no-audit",
|
|
22245
|
+
"--no-fund",
|
|
22246
|
+
"--no-progress",
|
|
22247
|
+
"--ignore-scripts"
|
|
22248
|
+
]);
|
|
22249
|
+
await new Promise((resolve13, reject) => {
|
|
22250
|
+
const child = spawn5(invocation.command, invocation.args, {
|
|
22251
|
+
cwd: installDir,
|
|
22252
|
+
env: { ...npmSpawnEnv(npm), ...invocation.env },
|
|
22253
|
+
stdio: ["ignore", "ignore", "pipe"],
|
|
22254
|
+
windowsVerbatimArguments: invocation.windowsVerbatimArguments
|
|
22255
|
+
});
|
|
22256
|
+
let stderr = "";
|
|
22257
|
+
let settled = false;
|
|
22258
|
+
let terminating = false;
|
|
22259
|
+
let timeout = null;
|
|
22260
|
+
const finish = (error2) => {
|
|
22261
|
+
if (settled)
|
|
22262
|
+
return;
|
|
22263
|
+
settled = true;
|
|
22264
|
+
if (timeout)
|
|
22265
|
+
clearTimeout(timeout);
|
|
22266
|
+
if (error2)
|
|
22267
|
+
reject(error2);
|
|
22268
|
+
else
|
|
22269
|
+
resolve13();
|
|
22270
|
+
};
|
|
22271
|
+
child.stderr?.on("data", (chunk) => {
|
|
22272
|
+
stderr += chunk.toString("utf8");
|
|
22273
|
+
if (stderr.length > 16 * 1024)
|
|
22274
|
+
stderr = stderr.slice(-16 * 1024);
|
|
22275
|
+
});
|
|
22276
|
+
child.once("error", (error2) => {
|
|
22277
|
+
if (terminating)
|
|
22278
|
+
return;
|
|
22279
|
+
finish(error2);
|
|
22280
|
+
});
|
|
22281
|
+
child.once("exit", (code) => {
|
|
22282
|
+
if (terminating)
|
|
22283
|
+
return;
|
|
22284
|
+
const detail = stderr.trim();
|
|
22285
|
+
if (code !== 0) {
|
|
22286
|
+
finish(new Error(`npm install exited with code ${code}${detail ? `: ${detail}` : ""}`));
|
|
22287
|
+
} else {
|
|
22288
|
+
finish();
|
|
22289
|
+
}
|
|
22290
|
+
});
|
|
22291
|
+
timeout = setTimeout(() => {
|
|
22292
|
+
if (settled)
|
|
22293
|
+
return;
|
|
22294
|
+
terminating = true;
|
|
22295
|
+
terminateNpmProcessTree(child, invocation).then(() => finish(new Error("npm install timed out after 120000ms")), (error2) => finish(new Error(`npm install timed out and termination outcome is unknown: ${String(error2)}`)));
|
|
22296
|
+
}, 120000);
|
|
22297
|
+
});
|
|
22298
|
+
}
|
|
21934
22299
|
async function applyPluginUpdates(targets) {
|
|
21935
22300
|
let updated = 0;
|
|
21936
22301
|
let errors = 0;
|
|
@@ -21944,12 +22309,7 @@ async function applyPluginUpdates(targets) {
|
|
|
21944
22309
|
}
|
|
21945
22310
|
for (const target of targets) {
|
|
21946
22311
|
try {
|
|
21947
|
-
|
|
21948
|
-
cwd: target.installDir,
|
|
21949
|
-
env: npmSpawnEnv(npm),
|
|
21950
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
21951
|
-
timeout: 120000
|
|
21952
|
-
});
|
|
22312
|
+
await runDoctorNpmInstall(npm, target.installDir);
|
|
21953
22313
|
updated += 1;
|
|
21954
22314
|
log2.success(`${target.adapter.displayName}: plugin updated ${target.cached} → ${target.latest} (restart ${target.adapter.displayName} to apply)`);
|
|
21955
22315
|
} catch (err) {
|
|
@@ -22209,7 +22569,7 @@ function ensureStorageDirsForRegisteredPlugins(adapters) {
|
|
|
22209
22569
|
if (!adapter.isInstalled() || !adapter.hasPluginEntry())
|
|
22210
22570
|
continue;
|
|
22211
22571
|
const storageDir = adapter.getStorageDir();
|
|
22212
|
-
if (
|
|
22572
|
+
if (existsSync26(storageDir))
|
|
22213
22573
|
continue;
|
|
22214
22574
|
mkdirSync7(storageDir, { recursive: true });
|
|
22215
22575
|
summary.created += 1;
|
|
@@ -22225,7 +22585,10 @@ async function clearPluginCache(adapter, includeBytes) {
|
|
|
22225
22585
|
const info = adapter.getPluginCacheInfo();
|
|
22226
22586
|
const bytes = info.exists ? dirSize(info.path) : 0;
|
|
22227
22587
|
const result = await adapter.clearPluginCache(true);
|
|
22228
|
-
if (result.
|
|
22588
|
+
if (result.legacy_path_cleared) {
|
|
22589
|
+
log2.success(`${adapter.displayName}: legacy_path_cleared at ${result.legacy_path_cleared}`);
|
|
22590
|
+
}
|
|
22591
|
+
if (result.action === "cleared" || result.action === "legacy_path_cleared") {
|
|
22229
22592
|
const suffix = includeBytes ? `, reclaimed ${formatBytes(bytes)}` : "";
|
|
22230
22593
|
log2.success(`${adapter.displayName}: cleared plugin cache at ${result.path}${suffix}`);
|
|
22231
22594
|
return { action: "cleared", bytes };
|
|
@@ -22334,11 +22697,11 @@ function deriveIssueTitleFromBody(body) {
|
|
|
22334
22697
|
function writeIssueReviewFile(body) {
|
|
22335
22698
|
let reviewDir = null;
|
|
22336
22699
|
try {
|
|
22337
|
-
reviewDir = mkdtempSync(
|
|
22700
|
+
reviewDir = mkdtempSync(join26(tmpdir2(), "aft-issue-"));
|
|
22338
22701
|
if (process.platform !== "win32") {
|
|
22339
22702
|
chmodSync4(reviewDir, 448);
|
|
22340
22703
|
}
|
|
22341
|
-
const outPath =
|
|
22704
|
+
const outPath = join26(reviewDir, "issue.md");
|
|
22342
22705
|
writeFileSync5(outPath, `${body}
|
|
22343
22706
|
`, { encoding: "utf8", mode: 384, flag: "wx" });
|
|
22344
22707
|
return { path: outPath, realPath: realpathSync5(outPath) };
|