@adhdev/daemon-core 0.9.50 → 0.9.51
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 +461 -399
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +457 -395
- package/dist/index.mjs.map +1 -1
- package/node_modules/@adhdev/session-host-core/package.json +1 -1
- package/package.json +1 -1
- package/src/commands/chat-commands.ts +73 -0
package/dist/index.js
CHANGED
|
@@ -1340,11 +1340,11 @@ function loadNodePty() {
|
|
|
1340
1340
|
}
|
|
1341
1341
|
return cachedPty;
|
|
1342
1342
|
}
|
|
1343
|
-
var
|
|
1343
|
+
var os8, cachedPty, NodePtyRuntimeTransport, NodePtyTransportFactory;
|
|
1344
1344
|
var init_pty_transport = __esm({
|
|
1345
1345
|
"src/cli-adapters/pty-transport.ts"() {
|
|
1346
1346
|
"use strict";
|
|
1347
|
-
|
|
1347
|
+
os8 = __toESM(require("os"));
|
|
1348
1348
|
init_spawn_env();
|
|
1349
1349
|
NodePtyRuntimeTransport = class {
|
|
1350
1350
|
constructor(handle) {
|
|
@@ -1381,11 +1381,11 @@ var init_pty_transport = __esm({
|
|
|
1381
1381
|
let cwd = options.cwd;
|
|
1382
1382
|
if (cwd) {
|
|
1383
1383
|
try {
|
|
1384
|
-
const
|
|
1385
|
-
const stat =
|
|
1386
|
-
if (!stat.isDirectory()) cwd =
|
|
1384
|
+
const fs16 = require("fs");
|
|
1385
|
+
const stat = fs16.statSync(cwd);
|
|
1386
|
+
if (!stat.isDirectory()) cwd = os8.homedir();
|
|
1387
1387
|
} catch {
|
|
1388
|
-
cwd =
|
|
1388
|
+
cwd = os8.homedir();
|
|
1389
1389
|
}
|
|
1390
1390
|
}
|
|
1391
1391
|
const handle = pty.spawn(command, args, {
|
|
@@ -1465,11 +1465,11 @@ function buildCliScreenSnapshot(text) {
|
|
|
1465
1465
|
function findBinary(name) {
|
|
1466
1466
|
const trimmed = String(name || "").trim();
|
|
1467
1467
|
if (!trimmed) return trimmed;
|
|
1468
|
-
const expanded = trimmed.startsWith("~") ?
|
|
1469
|
-
if (
|
|
1470
|
-
return
|
|
1468
|
+
const expanded = trimmed.startsWith("~") ? path10.join(os9.homedir(), trimmed.slice(1)) : trimmed;
|
|
1469
|
+
if (path10.isAbsolute(expanded) || expanded.includes("/") || expanded.includes("\\")) {
|
|
1470
|
+
return path10.isAbsolute(expanded) ? expanded : path10.resolve(expanded);
|
|
1471
1471
|
}
|
|
1472
|
-
const isWin =
|
|
1472
|
+
const isWin = os9.platform() === "win32";
|
|
1473
1473
|
try {
|
|
1474
1474
|
const cmd = isWin ? `where ${trimmed}` : `which ${trimmed}`;
|
|
1475
1475
|
return (0, import_child_process4.execSync)(cmd, {
|
|
@@ -1483,14 +1483,14 @@ function findBinary(name) {
|
|
|
1483
1483
|
}
|
|
1484
1484
|
}
|
|
1485
1485
|
function isScriptBinary(binaryPath) {
|
|
1486
|
-
if (!
|
|
1486
|
+
if (!path10.isAbsolute(binaryPath)) return false;
|
|
1487
1487
|
try {
|
|
1488
|
-
const
|
|
1489
|
-
const resolved =
|
|
1488
|
+
const fs16 = require("fs");
|
|
1489
|
+
const resolved = fs16.realpathSync(binaryPath);
|
|
1490
1490
|
const head = Buffer.alloc(8);
|
|
1491
|
-
const fd =
|
|
1492
|
-
|
|
1493
|
-
|
|
1491
|
+
const fd = fs16.openSync(resolved, "r");
|
|
1492
|
+
fs16.readSync(fd, head, 0, 8, 0);
|
|
1493
|
+
fs16.closeSync(fd);
|
|
1494
1494
|
let i = 0;
|
|
1495
1495
|
if (head[0] === 239 && head[1] === 187 && head[2] === 191) i = 3;
|
|
1496
1496
|
return head[i] === 35 && head[i + 1] === 33;
|
|
@@ -1499,14 +1499,14 @@ function isScriptBinary(binaryPath) {
|
|
|
1499
1499
|
}
|
|
1500
1500
|
}
|
|
1501
1501
|
function looksLikeMachOOrElf(filePath) {
|
|
1502
|
-
if (!
|
|
1502
|
+
if (!path10.isAbsolute(filePath)) return false;
|
|
1503
1503
|
try {
|
|
1504
|
-
const
|
|
1505
|
-
const resolved =
|
|
1504
|
+
const fs16 = require("fs");
|
|
1505
|
+
const resolved = fs16.realpathSync(filePath);
|
|
1506
1506
|
const buf = Buffer.alloc(8);
|
|
1507
|
-
const fd =
|
|
1508
|
-
|
|
1509
|
-
|
|
1507
|
+
const fd = fs16.openSync(resolved, "r");
|
|
1508
|
+
fs16.readSync(fd, buf, 0, 8, 0);
|
|
1509
|
+
fs16.closeSync(fd);
|
|
1510
1510
|
let i = 0;
|
|
1511
1511
|
if (buf[0] === 239 && buf[1] === 187 && buf[2] === 191) i = 3;
|
|
1512
1512
|
const b = buf.subarray(i);
|
|
@@ -1522,7 +1522,7 @@ function looksLikeMachOOrElf(filePath) {
|
|
|
1522
1522
|
}
|
|
1523
1523
|
function shSingleQuote(arg) {
|
|
1524
1524
|
if (/^[a-zA-Z0-9@%_+=:,./-]+$/.test(arg)) return arg;
|
|
1525
|
-
if (
|
|
1525
|
+
if (os9.platform() === "win32") {
|
|
1526
1526
|
return `"${arg.replace(/"/g, '""')}"`;
|
|
1527
1527
|
}
|
|
1528
1528
|
return `'${arg.replace(/'/g, `'\\''`)}'`;
|
|
@@ -1649,12 +1649,12 @@ function normalizeCliProviderForRuntime(raw) {
|
|
|
1649
1649
|
}
|
|
1650
1650
|
};
|
|
1651
1651
|
}
|
|
1652
|
-
var
|
|
1652
|
+
var os9, path10, import_child_process4, buildCliSpawnEnv, COMMON_COMPARABLE_WRAP_WORDS;
|
|
1653
1653
|
var init_provider_cli_shared = __esm({
|
|
1654
1654
|
"src/cli-adapters/provider-cli-shared.ts"() {
|
|
1655
1655
|
"use strict";
|
|
1656
|
-
|
|
1657
|
-
|
|
1656
|
+
os9 = __toESM(require("os"));
|
|
1657
|
+
path10 = __toESM(require("path"));
|
|
1658
1658
|
import_child_process4 = require("child_process");
|
|
1659
1659
|
init_spawn_env();
|
|
1660
1660
|
buildCliSpawnEnv = import_session_host_core.sanitizeSpawnEnv;
|
|
@@ -1967,13 +1967,13 @@ function resolveCliSpawnPlan(options) {
|
|
|
1967
1967
|
const { spawn: spawnConfig } = provider;
|
|
1968
1968
|
const configuredCommand = typeof runtimeSettings.executablePath === "string" && runtimeSettings.executablePath.trim() ? runtimeSettings.executablePath.trim() : spawnConfig.command;
|
|
1969
1969
|
const binaryPath = findBinary(configuredCommand);
|
|
1970
|
-
const isWin =
|
|
1970
|
+
const isWin = os10.platform() === "win32";
|
|
1971
1971
|
const allArgs = [...spawnConfig.args, ...extraArgs];
|
|
1972
1972
|
let shellCmd;
|
|
1973
1973
|
let shellArgs;
|
|
1974
|
-
const useShellUnix = !isWin && (!!spawnConfig.shell || !
|
|
1974
|
+
const useShellUnix = !isWin && (!!spawnConfig.shell || !path11.isAbsolute(binaryPath) || isScriptBinary(binaryPath) || !looksLikeMachOOrElf(binaryPath));
|
|
1975
1975
|
const isCmdShim = isWin && /\.(cmd|bat)$/i.test(binaryPath);
|
|
1976
|
-
const useShellWin = !!spawnConfig.shell || isCmdShim || !
|
|
1976
|
+
const useShellWin = !!spawnConfig.shell || isCmdShim || !path11.isAbsolute(binaryPath) || isScriptBinary(binaryPath);
|
|
1977
1977
|
const useShell = isWin ? useShellWin : useShellUnix;
|
|
1978
1978
|
if (useShell) {
|
|
1979
1979
|
shellCmd = isWin ? "cmd.exe" : process.env.SHELL || "/bin/zsh";
|
|
@@ -2049,12 +2049,12 @@ function respondToCliTerminalQueries(options) {
|
|
|
2049
2049
|
}
|
|
2050
2050
|
return "";
|
|
2051
2051
|
}
|
|
2052
|
-
var
|
|
2052
|
+
var os10, path11, import_session_host_core2;
|
|
2053
2053
|
var init_provider_cli_runtime = __esm({
|
|
2054
2054
|
"src/cli-adapters/provider-cli-runtime.ts"() {
|
|
2055
2055
|
"use strict";
|
|
2056
|
-
|
|
2057
|
-
|
|
2056
|
+
os10 = __toESM(require("os"));
|
|
2057
|
+
path11 = __toESM(require("path"));
|
|
2058
2058
|
import_session_host_core2 = require("@adhdev/session-host-core");
|
|
2059
2059
|
init_provider_cli_shared();
|
|
2060
2060
|
}
|
|
@@ -2176,11 +2176,11 @@ function trimLastAssistantEchoForCliMessages(messages, prompt) {
|
|
|
2176
2176
|
return;
|
|
2177
2177
|
}
|
|
2178
2178
|
}
|
|
2179
|
-
var
|
|
2179
|
+
var os11, COMMITTED_ACTIVITY_PREFIX_BLOCK_RE, ProviderCliAdapter;
|
|
2180
2180
|
var init_provider_cli_adapter = __esm({
|
|
2181
2181
|
"src/cli-adapters/provider-cli-adapter.ts"() {
|
|
2182
2182
|
"use strict";
|
|
2183
|
-
|
|
2183
|
+
os11 = __toESM(require("os"));
|
|
2184
2184
|
init_logger();
|
|
2185
2185
|
init_debug_config();
|
|
2186
2186
|
init_terminal_screen();
|
|
@@ -2200,7 +2200,7 @@ var init_provider_cli_adapter = __esm({
|
|
|
2200
2200
|
this.transportFactory = transportFactory;
|
|
2201
2201
|
this.cliType = provider.type;
|
|
2202
2202
|
this.cliName = provider.name;
|
|
2203
|
-
this.workingDir = workingDir.startsWith("~") ? workingDir.replace(/^~/,
|
|
2203
|
+
this.workingDir = workingDir.startsWith("~") ? workingDir.replace(/^~/, os11.homedir()) : workingDir;
|
|
2204
2204
|
const resolvedConfig = resolveCliAdapterConfig(provider);
|
|
2205
2205
|
this.timeouts = resolvedConfig.timeouts;
|
|
2206
2206
|
this.approvalKeys = resolvedConfig.approvalKeys;
|
|
@@ -5275,17 +5275,17 @@ function checkPathExists(paths) {
|
|
|
5275
5275
|
return null;
|
|
5276
5276
|
}
|
|
5277
5277
|
async function detectIDEs(providerLoader) {
|
|
5278
|
-
const
|
|
5278
|
+
const os21 = (0, import_os2.platform)();
|
|
5279
5279
|
const results = [];
|
|
5280
5280
|
for (const def of getMergedDefinitions()) {
|
|
5281
5281
|
const cliPath = findCliCommand(providerLoader?.getIdeCliCommand(def.id, def.cli) || def.cli);
|
|
5282
|
-
const appPath = checkPathExists(providerLoader?.getIdePathCandidates(def.id, def.paths[
|
|
5282
|
+
const appPath = checkPathExists(providerLoader?.getIdePathCandidates(def.id, def.paths[os21] || []) || []);
|
|
5283
5283
|
let resolvedCli = cliPath;
|
|
5284
|
-
if (!resolvedCli && appPath &&
|
|
5284
|
+
if (!resolvedCli && appPath && os21 === "darwin") {
|
|
5285
5285
|
const bundledCli = `${appPath}/Contents/Resources/app/bin/${def.cli}`;
|
|
5286
5286
|
if ((0, import_fs3.existsSync)(bundledCli)) resolvedCli = bundledCli;
|
|
5287
5287
|
}
|
|
5288
|
-
if (!resolvedCli && appPath &&
|
|
5288
|
+
if (!resolvedCli && appPath && os21 === "win32") {
|
|
5289
5289
|
const { dirname: dirname7 } = await import("path");
|
|
5290
5290
|
const appDir = dirname7(appPath);
|
|
5291
5291
|
const candidates = [
|
|
@@ -5302,7 +5302,7 @@ async function detectIDEs(providerLoader) {
|
|
|
5302
5302
|
}
|
|
5303
5303
|
}
|
|
5304
5304
|
}
|
|
5305
|
-
const installed =
|
|
5305
|
+
const installed = os21 === "darwin" ? !!(resolvedCli || appPath) : !!resolvedCli;
|
|
5306
5306
|
const version = resolvedCli ? getIdeVersion(resolvedCli) : null;
|
|
5307
5307
|
results.push({
|
|
5308
5308
|
id: def.id,
|
|
@@ -10466,6 +10466,10 @@ function resolveLegacyProviderScript(fn, scriptName, params) {
|
|
|
10466
10466
|
}
|
|
10467
10467
|
|
|
10468
10468
|
// src/commands/chat-commands.ts
|
|
10469
|
+
var fs4 = __toESM(require("fs"));
|
|
10470
|
+
var os6 = __toESM(require("os"));
|
|
10471
|
+
var path8 = __toESM(require("path"));
|
|
10472
|
+
var import_node_crypto = require("crypto");
|
|
10469
10473
|
init_contracts();
|
|
10470
10474
|
|
|
10471
10475
|
// src/providers/provider-input-support.ts
|
|
@@ -11155,6 +11159,50 @@ function buildDebugBundleText(bundle) {
|
|
|
11155
11159
|
"```"
|
|
11156
11160
|
].join("\n");
|
|
11157
11161
|
}
|
|
11162
|
+
function getChatDebugBundleDir() {
|
|
11163
|
+
const override = typeof process.env.ADHDEV_DEBUG_BUNDLE_DIR === "string" ? process.env.ADHDEV_DEBUG_BUNDLE_DIR.trim() : "";
|
|
11164
|
+
return override || path8.join(os6.homedir(), ".adhdev", "debug-bundles", "chat");
|
|
11165
|
+
}
|
|
11166
|
+
function safeBundleIdSegment(value, fallback) {
|
|
11167
|
+
const normalized = String(value || fallback).trim().replace(/[^A-Za-z0-9_.-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 80);
|
|
11168
|
+
return normalized || fallback;
|
|
11169
|
+
}
|
|
11170
|
+
function createChatDebugBundleId(targetSessionId) {
|
|
11171
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[-:.]/g, "").replace("T", "T").replace("Z", "Z");
|
|
11172
|
+
const sessionSegment = safeBundleIdSegment(targetSessionId, "unknown-session");
|
|
11173
|
+
return `chat-debug-${timestamp}-${sessionSegment}-${(0, import_node_crypto.randomUUID)().slice(0, 8)}`;
|
|
11174
|
+
}
|
|
11175
|
+
function buildChatDebugBundleSummary(bundle) {
|
|
11176
|
+
const target = bundle.target && typeof bundle.target === "object" ? bundle.target : {};
|
|
11177
|
+
const readChat = bundle.readChat && typeof bundle.readChat === "object" ? bundle.readChat : {};
|
|
11178
|
+
const cli = bundle.cli && typeof bundle.cli === "object" ? bundle.cli : null;
|
|
11179
|
+
const frontend = bundle.frontend && typeof bundle.frontend === "object" ? bundle.frontend : null;
|
|
11180
|
+
return {
|
|
11181
|
+
createdAt: bundle.createdAt,
|
|
11182
|
+
targetSessionId: target.targetSessionId,
|
|
11183
|
+
providerType: target.providerType,
|
|
11184
|
+
transport: target.transport,
|
|
11185
|
+
readChatSuccess: readChat.success,
|
|
11186
|
+
readChatStatus: readChat.status,
|
|
11187
|
+
readChatTotalMessages: readChat.totalMessages,
|
|
11188
|
+
cliStatus: cli?.status,
|
|
11189
|
+
cliMessageCount: cli?.messageCount,
|
|
11190
|
+
hasFrontendSnapshot: !!frontend
|
|
11191
|
+
};
|
|
11192
|
+
}
|
|
11193
|
+
function storeChatDebugBundleOnDaemon(bundle, targetSessionId) {
|
|
11194
|
+
const bundleId = createChatDebugBundleId(targetSessionId);
|
|
11195
|
+
const dir = getChatDebugBundleDir();
|
|
11196
|
+
fs4.mkdirSync(dir, { recursive: true });
|
|
11197
|
+
const savedPath = path8.join(dir, `${bundleId}.json`);
|
|
11198
|
+
const json = `${JSON.stringify(bundle, null, 2)}
|
|
11199
|
+
`;
|
|
11200
|
+
fs4.writeFileSync(savedPath, json, { encoding: "utf8", mode: 384 });
|
|
11201
|
+
return { bundleId, savedPath, sizeBytes: Buffer.byteLength(json, "utf8") };
|
|
11202
|
+
}
|
|
11203
|
+
function isDaemonFileDebugDelivery(args) {
|
|
11204
|
+
return args?.delivery === "daemon_file" || args?.delivery === "file";
|
|
11205
|
+
}
|
|
11158
11206
|
async function handleGetChatDebugBundle(h, args) {
|
|
11159
11207
|
const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
|
|
11160
11208
|
if (!targetSessionId && !h.currentSession) {
|
|
@@ -11266,6 +11314,20 @@ async function handleGetChatDebugBundle(h, args) {
|
|
|
11266
11314
|
recentDebugTrace: getRecentDebugTrace({ limit: 120 })
|
|
11267
11315
|
};
|
|
11268
11316
|
const bundle = sanitizeDebugBundleValue(rawBundle);
|
|
11317
|
+
if (isDaemonFileDebugDelivery(args)) {
|
|
11318
|
+
const summary = buildChatDebugBundleSummary(bundle);
|
|
11319
|
+
const stored = storeChatDebugBundleOnDaemon(bundle, targetSessionId || String(summary.targetSessionId || "unknown-session"));
|
|
11320
|
+
LOG.info("Command", `[get_chat_debug_bundle] saved daemon_file bundle id=${stored.bundleId} path=${stored.savedPath} sizeBytes=${stored.sizeBytes} targetSessionId=${summary.targetSessionId || ""} providerType=${summary.providerType || ""} transport=${summary.transport || ""}`);
|
|
11321
|
+
return {
|
|
11322
|
+
success: true,
|
|
11323
|
+
delivery: "daemon_file",
|
|
11324
|
+
bundleId: stored.bundleId,
|
|
11325
|
+
savedPath: stored.savedPath,
|
|
11326
|
+
sizeBytes: stored.sizeBytes,
|
|
11327
|
+
createdAt: bundle.createdAt,
|
|
11328
|
+
summary
|
|
11329
|
+
};
|
|
11330
|
+
}
|
|
11269
11331
|
return {
|
|
11270
11332
|
success: true,
|
|
11271
11333
|
bundle,
|
|
@@ -12247,9 +12309,9 @@ async function handleResolveAction(h, args) {
|
|
|
12247
12309
|
}
|
|
12248
12310
|
|
|
12249
12311
|
// src/commands/cdp-commands.ts
|
|
12250
|
-
var
|
|
12251
|
-
var
|
|
12252
|
-
var
|
|
12312
|
+
var fs5 = __toESM(require("fs"));
|
|
12313
|
+
var path9 = __toESM(require("path"));
|
|
12314
|
+
var os7 = __toESM(require("os"));
|
|
12253
12315
|
var KEY_TO_VK = {
|
|
12254
12316
|
Backspace: 8,
|
|
12255
12317
|
Tab: 9,
|
|
@@ -12503,27 +12565,27 @@ function normalizeWindowsRequestedPath(requestedPath) {
|
|
|
12503
12565
|
function resolveSafePath(requestedPath) {
|
|
12504
12566
|
const rawPath = typeof requestedPath === "string" ? requestedPath.trim() : "";
|
|
12505
12567
|
const inputPath = rawPath || ".";
|
|
12506
|
-
const home =
|
|
12568
|
+
const home = os7.homedir();
|
|
12507
12569
|
if (inputPath.startsWith("~")) {
|
|
12508
|
-
return
|
|
12570
|
+
return path9.resolve(path9.join(home, inputPath.slice(1)));
|
|
12509
12571
|
}
|
|
12510
12572
|
if (process.platform === "win32") {
|
|
12511
12573
|
const normalized = normalizeWindowsRequestedPath(inputPath);
|
|
12512
|
-
if (
|
|
12513
|
-
return
|
|
12574
|
+
if (path9.win32.isAbsolute(normalized)) {
|
|
12575
|
+
return path9.win32.normalize(normalized);
|
|
12514
12576
|
}
|
|
12515
|
-
return
|
|
12577
|
+
return path9.win32.resolve(normalized);
|
|
12516
12578
|
}
|
|
12517
|
-
if (
|
|
12518
|
-
return
|
|
12579
|
+
if (path9.isAbsolute(inputPath)) {
|
|
12580
|
+
return path9.normalize(inputPath);
|
|
12519
12581
|
}
|
|
12520
|
-
return
|
|
12582
|
+
return path9.resolve(inputPath);
|
|
12521
12583
|
}
|
|
12522
12584
|
function listDirectoryEntriesSafe(dirPath) {
|
|
12523
|
-
const entries =
|
|
12585
|
+
const entries = fs5.readdirSync(dirPath, { withFileTypes: true });
|
|
12524
12586
|
const files = [];
|
|
12525
12587
|
for (const entry of entries) {
|
|
12526
|
-
const entryPath =
|
|
12588
|
+
const entryPath = path9.join(dirPath, entry.name);
|
|
12527
12589
|
try {
|
|
12528
12590
|
if (entry.isDirectory()) {
|
|
12529
12591
|
files.push({ name: entry.name, type: "directory" });
|
|
@@ -12532,14 +12594,14 @@ function listDirectoryEntriesSafe(dirPath) {
|
|
|
12532
12594
|
if (entry.isFile()) {
|
|
12533
12595
|
let size;
|
|
12534
12596
|
try {
|
|
12535
|
-
size =
|
|
12597
|
+
size = fs5.statSync(entryPath).size;
|
|
12536
12598
|
} catch {
|
|
12537
12599
|
size = void 0;
|
|
12538
12600
|
}
|
|
12539
12601
|
files.push({ name: entry.name, type: "file", size });
|
|
12540
12602
|
continue;
|
|
12541
12603
|
}
|
|
12542
|
-
const stat =
|
|
12604
|
+
const stat = fs5.statSync(entryPath);
|
|
12543
12605
|
files.push({
|
|
12544
12606
|
name: entry.name,
|
|
12545
12607
|
type: stat.isDirectory() ? "directory" : "file",
|
|
@@ -12557,7 +12619,7 @@ function listWindowsDriveEntries(excludePath) {
|
|
|
12557
12619
|
const letter = String.fromCharCode(code);
|
|
12558
12620
|
const root = `${letter}:\\`;
|
|
12559
12621
|
try {
|
|
12560
|
-
if (!
|
|
12622
|
+
if (!fs5.existsSync(root)) continue;
|
|
12561
12623
|
if (excluded && root.toLowerCase() === excluded) continue;
|
|
12562
12624
|
drives.push({ name: `${letter}:`, type: "directory", path: root });
|
|
12563
12625
|
} catch {
|
|
@@ -12568,7 +12630,7 @@ function listWindowsDriveEntries(excludePath) {
|
|
|
12568
12630
|
async function handleFileRead(h, args) {
|
|
12569
12631
|
try {
|
|
12570
12632
|
const filePath = resolveSafePath(args?.path);
|
|
12571
|
-
const content =
|
|
12633
|
+
const content = fs5.readFileSync(filePath, "utf-8");
|
|
12572
12634
|
return { success: true, content, path: filePath };
|
|
12573
12635
|
} catch (e) {
|
|
12574
12636
|
return { success: false, error: e.message };
|
|
@@ -12577,8 +12639,8 @@ async function handleFileRead(h, args) {
|
|
|
12577
12639
|
async function handleFileWrite(h, args) {
|
|
12578
12640
|
try {
|
|
12579
12641
|
const filePath = resolveSafePath(args?.path);
|
|
12580
|
-
|
|
12581
|
-
|
|
12642
|
+
fs5.mkdirSync(path9.dirname(filePath), { recursive: true });
|
|
12643
|
+
fs5.writeFileSync(filePath, args?.content || "", "utf-8");
|
|
12582
12644
|
return { success: true, path: filePath };
|
|
12583
12645
|
} catch (e) {
|
|
12584
12646
|
return { success: false, error: e.message };
|
|
@@ -13679,8 +13741,8 @@ var DaemonCommandHandler = class {
|
|
|
13679
13741
|
};
|
|
13680
13742
|
|
|
13681
13743
|
// src/commands/cli-manager.ts
|
|
13682
|
-
var
|
|
13683
|
-
var
|
|
13744
|
+
var os13 = __toESM(require("os"));
|
|
13745
|
+
var path13 = __toESM(require("path"));
|
|
13684
13746
|
var crypto4 = __toESM(require("crypto"));
|
|
13685
13747
|
var import_fs5 = require("fs");
|
|
13686
13748
|
var import_child_process6 = require("child_process");
|
|
@@ -13689,10 +13751,10 @@ init_provider_cli_adapter();
|
|
|
13689
13751
|
init_config();
|
|
13690
13752
|
|
|
13691
13753
|
// src/providers/cli-provider-instance.ts
|
|
13692
|
-
var
|
|
13693
|
-
var
|
|
13754
|
+
var os12 = __toESM(require("os"));
|
|
13755
|
+
var path12 = __toESM(require("path"));
|
|
13694
13756
|
var crypto3 = __toESM(require("crypto"));
|
|
13695
|
-
var
|
|
13757
|
+
var fs6 = __toESM(require("fs"));
|
|
13696
13758
|
var import_node_module = require("module");
|
|
13697
13759
|
init_contracts();
|
|
13698
13760
|
init_provider_cli_adapter();
|
|
@@ -13751,7 +13813,7 @@ function buildIncrementalHistoryAppendMessages(previousMessages, currentMessages
|
|
|
13751
13813
|
var CachedDatabaseSync = null;
|
|
13752
13814
|
function getDatabaseSync() {
|
|
13753
13815
|
if (CachedDatabaseSync) return CachedDatabaseSync;
|
|
13754
|
-
const requireFn = typeof require === "function" ? require : (0, import_node_module.createRequire)(
|
|
13816
|
+
const requireFn = typeof require === "function" ? require : (0, import_node_module.createRequire)(path12.join(process.cwd(), "__adhdev_sqlite_loader__.js"));
|
|
13755
13817
|
const sqliteModule = requireFn(`node:${"sqlite"}`);
|
|
13756
13818
|
CachedDatabaseSync = sqliteModule.DatabaseSync;
|
|
13757
13819
|
if (!CachedDatabaseSync) {
|
|
@@ -13901,10 +13963,10 @@ var CliProviderInstance = class {
|
|
|
13901
13963
|
* Replaces the previously duplicated probeOpenCode/Codex/Goose functions.
|
|
13902
13964
|
*/
|
|
13903
13965
|
probeSessionIdFromConfig(probe) {
|
|
13904
|
-
const resolvedDbPath = probe.dbPath.replace(/^~/,
|
|
13966
|
+
const resolvedDbPath = probe.dbPath.replace(/^~/, os12.homedir());
|
|
13905
13967
|
const now = Date.now();
|
|
13906
13968
|
if (this.cachedSqliteDbMissingUntil > now) return null;
|
|
13907
|
-
if (!
|
|
13969
|
+
if (!fs6.existsSync(resolvedDbPath)) {
|
|
13908
13970
|
this.cachedSqliteDbMissingUntil = now + 1e4;
|
|
13909
13971
|
return null;
|
|
13910
13972
|
}
|
|
@@ -14636,7 +14698,7 @@ ${effect.notification.body || ""}`.trim();
|
|
|
14636
14698
|
};
|
|
14637
14699
|
addDir(this.workingDir);
|
|
14638
14700
|
try {
|
|
14639
|
-
addDir(
|
|
14701
|
+
addDir(fs6.realpathSync.native(this.workingDir));
|
|
14640
14702
|
} catch {
|
|
14641
14703
|
}
|
|
14642
14704
|
return Array.from(dirs);
|
|
@@ -15835,11 +15897,11 @@ function shouldRestoreHostedRuntime(record, managerTag) {
|
|
|
15835
15897
|
// src/commands/cli-manager.ts
|
|
15836
15898
|
function isExplicitCommand(command) {
|
|
15837
15899
|
const trimmed = command.trim();
|
|
15838
|
-
return
|
|
15900
|
+
return path13.isAbsolute(trimmed) || trimmed.includes("/") || trimmed.includes("\\") || trimmed.startsWith("~");
|
|
15839
15901
|
}
|
|
15840
15902
|
function expandExecutable(command) {
|
|
15841
15903
|
const trimmed = command.trim();
|
|
15842
|
-
return trimmed.startsWith("~") ?
|
|
15904
|
+
return trimmed.startsWith("~") ? path13.join(os13.homedir(), trimmed.slice(1)) : trimmed;
|
|
15843
15905
|
}
|
|
15844
15906
|
function commandExists(command) {
|
|
15845
15907
|
const trimmed = command.trim();
|
|
@@ -16120,7 +16182,7 @@ var DaemonCliManager = class {
|
|
|
16120
16182
|
async startSession(cliType, workingDir, cliArgs, initialModel, options) {
|
|
16121
16183
|
const trimmed = (workingDir || "").trim();
|
|
16122
16184
|
if (!trimmed) throw new Error("working directory required");
|
|
16123
|
-
const resolvedDir = trimmed.startsWith("~") ? trimmed.replace(/^~/,
|
|
16185
|
+
const resolvedDir = trimmed.startsWith("~") ? trimmed.replace(/^~/, os13.homedir()) : path13.resolve(trimmed);
|
|
16124
16186
|
const normalizedType = this.providerLoader.resolveAlias(cliType);
|
|
16125
16187
|
const rawProvider = this.providerLoader.getByAlias(cliType);
|
|
16126
16188
|
const provider = rawProvider ? this.providerLoader.resolve(normalizedType) || rawProvider : void 0;
|
|
@@ -16620,13 +16682,13 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
16620
16682
|
// src/launch.ts
|
|
16621
16683
|
var import_child_process7 = require("child_process");
|
|
16622
16684
|
var net = __toESM(require("net"));
|
|
16623
|
-
var
|
|
16624
|
-
var
|
|
16685
|
+
var os15 = __toESM(require("os"));
|
|
16686
|
+
var path15 = __toESM(require("path"));
|
|
16625
16687
|
|
|
16626
16688
|
// src/providers/provider-loader.ts
|
|
16627
|
-
var
|
|
16628
|
-
var
|
|
16629
|
-
var
|
|
16689
|
+
var fs7 = __toESM(require("fs"));
|
|
16690
|
+
var path14 = __toESM(require("path"));
|
|
16691
|
+
var os14 = __toESM(require("os"));
|
|
16630
16692
|
var chokidar = __toESM(require("chokidar"));
|
|
16631
16693
|
init_logger();
|
|
16632
16694
|
|
|
@@ -16888,9 +16950,9 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
16888
16950
|
static siblingStderrLogged = /* @__PURE__ */ new Set();
|
|
16889
16951
|
static looksLikeProviderRoot(candidate) {
|
|
16890
16952
|
try {
|
|
16891
|
-
if (!
|
|
16953
|
+
if (!fs7.existsSync(candidate) || !fs7.statSync(candidate).isDirectory()) return false;
|
|
16892
16954
|
return ["ide", "extension", "cli", "acp"].some(
|
|
16893
|
-
(category) =>
|
|
16955
|
+
(category) => fs7.existsSync(path14.join(candidate, category))
|
|
16894
16956
|
);
|
|
16895
16957
|
} catch {
|
|
16896
16958
|
return false;
|
|
@@ -16898,20 +16960,20 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
16898
16960
|
}
|
|
16899
16961
|
static hasProviderRootMarker(candidate) {
|
|
16900
16962
|
try {
|
|
16901
|
-
return
|
|
16963
|
+
return fs7.existsSync(path14.join(candidate, _ProviderLoader.SIBLING_MARKER_FILE));
|
|
16902
16964
|
} catch {
|
|
16903
16965
|
return false;
|
|
16904
16966
|
}
|
|
16905
16967
|
}
|
|
16906
16968
|
detectDefaultUserDir() {
|
|
16907
|
-
const fallback =
|
|
16969
|
+
const fallback = path14.join(os14.homedir(), ".adhdev", "providers");
|
|
16908
16970
|
const envOptIn = process.env[_ProviderLoader.SIBLING_ENV_VAR] === "1";
|
|
16909
16971
|
const visited = /* @__PURE__ */ new Set();
|
|
16910
16972
|
for (const start of this.probeStarts) {
|
|
16911
|
-
let current =
|
|
16973
|
+
let current = path14.resolve(start);
|
|
16912
16974
|
while (!visited.has(current)) {
|
|
16913
16975
|
visited.add(current);
|
|
16914
|
-
const siblingCandidate =
|
|
16976
|
+
const siblingCandidate = path14.join(path14.dirname(current), _ProviderLoader.REPO_PROVIDER_DIRNAME);
|
|
16915
16977
|
if (_ProviderLoader.looksLikeProviderRoot(siblingCandidate)) {
|
|
16916
16978
|
const hasMarker = _ProviderLoader.hasProviderRootMarker(siblingCandidate);
|
|
16917
16979
|
if (envOptIn || hasMarker) {
|
|
@@ -16933,7 +16995,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
16933
16995
|
return { path: siblingCandidate, source };
|
|
16934
16996
|
}
|
|
16935
16997
|
}
|
|
16936
|
-
const parent =
|
|
16998
|
+
const parent = path14.dirname(current);
|
|
16937
16999
|
if (parent === current) break;
|
|
16938
17000
|
current = parent;
|
|
16939
17001
|
}
|
|
@@ -16943,11 +17005,11 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
16943
17005
|
constructor(options) {
|
|
16944
17006
|
this.logFn = options?.logFn || LOG.forComponent("Provider").asLogFn();
|
|
16945
17007
|
this.probeStarts = options?.probeStarts ?? [process.cwd(), __dirname];
|
|
16946
|
-
this.defaultProvidersDir =
|
|
17008
|
+
this.defaultProvidersDir = path14.join(os14.homedir(), ".adhdev", "providers");
|
|
16947
17009
|
const detected = this.detectDefaultUserDir();
|
|
16948
17010
|
this.userDir = detected.path;
|
|
16949
17011
|
this.userDirSource = detected.source;
|
|
16950
|
-
this.upstreamDir =
|
|
17012
|
+
this.upstreamDir = path14.join(this.defaultProvidersDir, ".upstream");
|
|
16951
17013
|
this.disableUpstream = false;
|
|
16952
17014
|
this.applySourceConfig({
|
|
16953
17015
|
userDir: options?.userDir,
|
|
@@ -17006,7 +17068,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17006
17068
|
this.userDir = detected.path;
|
|
17007
17069
|
this.userDirSource = detected.source;
|
|
17008
17070
|
}
|
|
17009
|
-
this.upstreamDir =
|
|
17071
|
+
this.upstreamDir = path14.join(this.defaultProvidersDir, ".upstream");
|
|
17010
17072
|
this.disableUpstream = this.sourceMode === "no-upstream";
|
|
17011
17073
|
if (this.explicitProviderDir) {
|
|
17012
17074
|
this.log(`Config 'providerDir' applied: ${this.userDir}`);
|
|
@@ -17020,7 +17082,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17020
17082
|
* Canonical provider directory shape for a given root.
|
|
17021
17083
|
*/
|
|
17022
17084
|
getProviderDir(root, category, type) {
|
|
17023
|
-
return
|
|
17085
|
+
return path14.join(root, category, type);
|
|
17024
17086
|
}
|
|
17025
17087
|
/**
|
|
17026
17088
|
* Canonical user override directory for a provider.
|
|
@@ -17047,7 +17109,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17047
17109
|
resolveProviderFile(type, ...segments) {
|
|
17048
17110
|
const dir = this.findProviderDirInternal(type);
|
|
17049
17111
|
if (!dir) return null;
|
|
17050
|
-
return
|
|
17112
|
+
return path14.join(dir, ...segments);
|
|
17051
17113
|
}
|
|
17052
17114
|
/**
|
|
17053
17115
|
* Load all providers (3-tier priority)
|
|
@@ -17060,7 +17122,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17060
17122
|
this.providers.clear();
|
|
17061
17123
|
this.providerAvailability.clear();
|
|
17062
17124
|
let upstreamCount = 0;
|
|
17063
|
-
if (!this.disableUpstream &&
|
|
17125
|
+
if (!this.disableUpstream && fs7.existsSync(this.upstreamDir)) {
|
|
17064
17126
|
upstreamCount = this.loadDir(this.upstreamDir);
|
|
17065
17127
|
if (upstreamCount > 0) {
|
|
17066
17128
|
this.log(`Loaded ${upstreamCount} upstream providers (auto-updated)`);
|
|
@@ -17068,7 +17130,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17068
17130
|
} else if (this.disableUpstream) {
|
|
17069
17131
|
this.log("Upstream loading disabled (sourceMode=no-upstream)");
|
|
17070
17132
|
}
|
|
17071
|
-
if (
|
|
17133
|
+
if (fs7.existsSync(this.userDir)) {
|
|
17072
17134
|
const userCount = this.loadDir(this.userDir, [".upstream"]);
|
|
17073
17135
|
if (userCount > 0) {
|
|
17074
17136
|
this.log(`Loaded ${userCount} user custom providers (never auto-updated)`);
|
|
@@ -17083,10 +17145,10 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17083
17145
|
* Check if upstream directory exists and has providers.
|
|
17084
17146
|
*/
|
|
17085
17147
|
hasUpstream() {
|
|
17086
|
-
if (!
|
|
17148
|
+
if (!fs7.existsSync(this.upstreamDir)) return false;
|
|
17087
17149
|
try {
|
|
17088
|
-
return
|
|
17089
|
-
(d) =>
|
|
17150
|
+
return fs7.readdirSync(this.upstreamDir).some(
|
|
17151
|
+
(d) => fs7.statSync(path14.join(this.upstreamDir, d)).isDirectory()
|
|
17090
17152
|
);
|
|
17091
17153
|
} catch {
|
|
17092
17154
|
return false;
|
|
@@ -17583,8 +17645,8 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17583
17645
|
resolved._resolvedScriptDir = entry.scriptDir;
|
|
17584
17646
|
resolved._resolvedScriptsSource = `compatibility:${entry.ideVersion}`;
|
|
17585
17647
|
if (providerDir) {
|
|
17586
|
-
const fullDir =
|
|
17587
|
-
resolved._resolvedScriptsPath =
|
|
17648
|
+
const fullDir = path14.join(providerDir, entry.scriptDir);
|
|
17649
|
+
resolved._resolvedScriptsPath = fs7.existsSync(path14.join(fullDir, "scripts.js")) ? path14.join(fullDir, "scripts.js") : fullDir;
|
|
17588
17650
|
}
|
|
17589
17651
|
matched = true;
|
|
17590
17652
|
}
|
|
@@ -17599,8 +17661,8 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17599
17661
|
resolved._resolvedScriptDir = base.defaultScriptDir;
|
|
17600
17662
|
resolved._resolvedScriptsSource = "defaultScriptDir:version_miss";
|
|
17601
17663
|
if (providerDir) {
|
|
17602
|
-
const fullDir =
|
|
17603
|
-
resolved._resolvedScriptsPath =
|
|
17664
|
+
const fullDir = path14.join(providerDir, base.defaultScriptDir);
|
|
17665
|
+
resolved._resolvedScriptsPath = fs7.existsSync(path14.join(fullDir, "scripts.js")) ? path14.join(fullDir, "scripts.js") : fullDir;
|
|
17604
17666
|
}
|
|
17605
17667
|
}
|
|
17606
17668
|
resolved._versionWarning = `Version ${currentVersion} not in compatibility matrix. Using default scripts.`;
|
|
@@ -17617,8 +17679,8 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17617
17679
|
resolved._resolvedScriptDir = dirOverride;
|
|
17618
17680
|
resolved._resolvedScriptsSource = `versions:${range}`;
|
|
17619
17681
|
if (providerDir) {
|
|
17620
|
-
const fullDir =
|
|
17621
|
-
resolved._resolvedScriptsPath =
|
|
17682
|
+
const fullDir = path14.join(providerDir, dirOverride);
|
|
17683
|
+
resolved._resolvedScriptsPath = fs7.existsSync(path14.join(fullDir, "scripts.js")) ? path14.join(fullDir, "scripts.js") : fullDir;
|
|
17622
17684
|
}
|
|
17623
17685
|
}
|
|
17624
17686
|
} else if (override.scripts) {
|
|
@@ -17634,8 +17696,8 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17634
17696
|
resolved._resolvedScriptDir = base.defaultScriptDir;
|
|
17635
17697
|
resolved._resolvedScriptsSource = "defaultScriptDir:no_version";
|
|
17636
17698
|
if (providerDir) {
|
|
17637
|
-
const fullDir =
|
|
17638
|
-
resolved._resolvedScriptsPath =
|
|
17699
|
+
const fullDir = path14.join(providerDir, base.defaultScriptDir);
|
|
17700
|
+
resolved._resolvedScriptsPath = fs7.existsSync(path14.join(fullDir, "scripts.js")) ? path14.join(fullDir, "scripts.js") : fullDir;
|
|
17639
17701
|
}
|
|
17640
17702
|
}
|
|
17641
17703
|
}
|
|
@@ -17667,15 +17729,15 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17667
17729
|
this.log(` [loadScriptsFromDir] ${type}: providerDir not found`);
|
|
17668
17730
|
return null;
|
|
17669
17731
|
}
|
|
17670
|
-
const dir =
|
|
17671
|
-
if (!
|
|
17732
|
+
const dir = path14.join(providerDir, scriptDir);
|
|
17733
|
+
if (!fs7.existsSync(dir)) {
|
|
17672
17734
|
this.log(` [loadScriptsFromDir] ${type}: dir not found: ${dir}`);
|
|
17673
17735
|
return null;
|
|
17674
17736
|
}
|
|
17675
17737
|
const cached = this.scriptsCache.get(dir);
|
|
17676
17738
|
if (cached) return cached;
|
|
17677
|
-
const scriptsJs =
|
|
17678
|
-
if (
|
|
17739
|
+
const scriptsJs = path14.join(dir, "scripts.js");
|
|
17740
|
+
if (fs7.existsSync(scriptsJs)) {
|
|
17679
17741
|
try {
|
|
17680
17742
|
delete require.cache[require.resolve(scriptsJs)];
|
|
17681
17743
|
const loaded = require(scriptsJs);
|
|
@@ -17696,9 +17758,9 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17696
17758
|
watch() {
|
|
17697
17759
|
this.stopWatch();
|
|
17698
17760
|
const watchDir = (dir) => {
|
|
17699
|
-
if (!
|
|
17761
|
+
if (!fs7.existsSync(dir)) {
|
|
17700
17762
|
try {
|
|
17701
|
-
|
|
17763
|
+
fs7.mkdirSync(dir, { recursive: true });
|
|
17702
17764
|
} catch {
|
|
17703
17765
|
return;
|
|
17704
17766
|
}
|
|
@@ -17716,7 +17778,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17716
17778
|
return;
|
|
17717
17779
|
}
|
|
17718
17780
|
if (filePath.endsWith(".js") || filePath.endsWith(".json")) {
|
|
17719
|
-
this.log(`File changed: ${
|
|
17781
|
+
this.log(`File changed: ${path14.basename(filePath)}, reloading...`);
|
|
17720
17782
|
this.reload();
|
|
17721
17783
|
}
|
|
17722
17784
|
};
|
|
@@ -17771,12 +17833,12 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17771
17833
|
}
|
|
17772
17834
|
const https = require("https");
|
|
17773
17835
|
const { execSync: execSync7 } = require("child_process");
|
|
17774
|
-
const metaPath =
|
|
17836
|
+
const metaPath = path14.join(this.upstreamDir, _ProviderLoader.META_FILE);
|
|
17775
17837
|
let prevEtag = "";
|
|
17776
17838
|
let prevTimestamp = 0;
|
|
17777
17839
|
try {
|
|
17778
|
-
if (
|
|
17779
|
-
const meta = JSON.parse(
|
|
17840
|
+
if (fs7.existsSync(metaPath)) {
|
|
17841
|
+
const meta = JSON.parse(fs7.readFileSync(metaPath, "utf-8"));
|
|
17780
17842
|
prevEtag = meta.etag || "";
|
|
17781
17843
|
prevTimestamp = meta.timestamp || 0;
|
|
17782
17844
|
}
|
|
@@ -17831,39 +17893,39 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17831
17893
|
return { updated: false };
|
|
17832
17894
|
}
|
|
17833
17895
|
this.log("Downloading latest providers from GitHub...");
|
|
17834
|
-
const tmpTar =
|
|
17835
|
-
const tmpExtract =
|
|
17896
|
+
const tmpTar = path14.join(os14.tmpdir(), `adhdev-providers-${Date.now()}.tar.gz`);
|
|
17897
|
+
const tmpExtract = path14.join(os14.tmpdir(), `adhdev-providers-extract-${Date.now()}`);
|
|
17836
17898
|
await this.downloadFile(_ProviderLoader.GITHUB_TARBALL_URL, tmpTar);
|
|
17837
|
-
|
|
17899
|
+
fs7.mkdirSync(tmpExtract, { recursive: true });
|
|
17838
17900
|
execSync7(`tar -xzf "${tmpTar}" -C "${tmpExtract}"`, { timeout: 3e4 });
|
|
17839
|
-
const extracted =
|
|
17901
|
+
const extracted = fs7.readdirSync(tmpExtract);
|
|
17840
17902
|
const rootDir = extracted.find(
|
|
17841
|
-
(d) =>
|
|
17903
|
+
(d) => fs7.statSync(path14.join(tmpExtract, d)).isDirectory() && d.startsWith("adhdev-providers")
|
|
17842
17904
|
);
|
|
17843
17905
|
if (!rootDir) throw new Error("Unexpected tarball structure");
|
|
17844
|
-
const sourceDir =
|
|
17906
|
+
const sourceDir = path14.join(tmpExtract, rootDir);
|
|
17845
17907
|
const backupDir = this.upstreamDir + ".bak";
|
|
17846
|
-
if (
|
|
17847
|
-
if (
|
|
17848
|
-
|
|
17908
|
+
if (fs7.existsSync(this.upstreamDir)) {
|
|
17909
|
+
if (fs7.existsSync(backupDir)) fs7.rmSync(backupDir, { recursive: true, force: true });
|
|
17910
|
+
fs7.renameSync(this.upstreamDir, backupDir);
|
|
17849
17911
|
}
|
|
17850
17912
|
try {
|
|
17851
17913
|
this.copyDirRecursive(sourceDir, this.upstreamDir);
|
|
17852
17914
|
this.writeMeta(metaPath, etag || `ts-${Date.now()}`, Date.now());
|
|
17853
|
-
if (
|
|
17915
|
+
if (fs7.existsSync(backupDir)) fs7.rmSync(backupDir, { recursive: true, force: true });
|
|
17854
17916
|
} catch (e) {
|
|
17855
|
-
if (
|
|
17856
|
-
if (
|
|
17857
|
-
|
|
17917
|
+
if (fs7.existsSync(backupDir)) {
|
|
17918
|
+
if (fs7.existsSync(this.upstreamDir)) fs7.rmSync(this.upstreamDir, { recursive: true, force: true });
|
|
17919
|
+
fs7.renameSync(backupDir, this.upstreamDir);
|
|
17858
17920
|
}
|
|
17859
17921
|
throw e;
|
|
17860
17922
|
}
|
|
17861
17923
|
try {
|
|
17862
|
-
|
|
17924
|
+
fs7.rmSync(tmpTar, { force: true });
|
|
17863
17925
|
} catch {
|
|
17864
17926
|
}
|
|
17865
17927
|
try {
|
|
17866
|
-
|
|
17928
|
+
fs7.rmSync(tmpExtract, { recursive: true, force: true });
|
|
17867
17929
|
} catch {
|
|
17868
17930
|
}
|
|
17869
17931
|
const upstreamCount = this.countProviders(this.upstreamDir);
|
|
@@ -17895,7 +17957,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17895
17957
|
reject(new Error(`HTTP ${res.statusCode}`));
|
|
17896
17958
|
return;
|
|
17897
17959
|
}
|
|
17898
|
-
const ws =
|
|
17960
|
+
const ws = fs7.createWriteStream(destPath);
|
|
17899
17961
|
res.pipe(ws);
|
|
17900
17962
|
ws.on("finish", () => {
|
|
17901
17963
|
ws.close();
|
|
@@ -17914,22 +17976,22 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17914
17976
|
}
|
|
17915
17977
|
/** Recursive directory copy */
|
|
17916
17978
|
copyDirRecursive(src, dest) {
|
|
17917
|
-
|
|
17918
|
-
for (const entry of
|
|
17919
|
-
const srcPath =
|
|
17920
|
-
const destPath =
|
|
17979
|
+
fs7.mkdirSync(dest, { recursive: true });
|
|
17980
|
+
for (const entry of fs7.readdirSync(src, { withFileTypes: true })) {
|
|
17981
|
+
const srcPath = path14.join(src, entry.name);
|
|
17982
|
+
const destPath = path14.join(dest, entry.name);
|
|
17921
17983
|
if (entry.isDirectory()) {
|
|
17922
17984
|
this.copyDirRecursive(srcPath, destPath);
|
|
17923
17985
|
} else {
|
|
17924
|
-
|
|
17986
|
+
fs7.copyFileSync(srcPath, destPath);
|
|
17925
17987
|
}
|
|
17926
17988
|
}
|
|
17927
17989
|
}
|
|
17928
17990
|
/** .meta.json save */
|
|
17929
17991
|
writeMeta(metaPath, etag, timestamp) {
|
|
17930
17992
|
try {
|
|
17931
|
-
|
|
17932
|
-
|
|
17993
|
+
fs7.mkdirSync(path14.dirname(metaPath), { recursive: true });
|
|
17994
|
+
fs7.writeFileSync(metaPath, JSON.stringify({
|
|
17933
17995
|
etag,
|
|
17934
17996
|
timestamp,
|
|
17935
17997
|
lastCheck: new Date(timestamp).toISOString(),
|
|
@@ -17940,12 +18002,12 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17940
18002
|
}
|
|
17941
18003
|
/** Count provider files (provider.js or provider.json) */
|
|
17942
18004
|
countProviders(dir) {
|
|
17943
|
-
if (!
|
|
18005
|
+
if (!fs7.existsSync(dir)) return 0;
|
|
17944
18006
|
let count = 0;
|
|
17945
18007
|
const scan = (d) => {
|
|
17946
18008
|
try {
|
|
17947
|
-
for (const entry of
|
|
17948
|
-
if (entry.isDirectory()) scan(
|
|
18009
|
+
for (const entry of fs7.readdirSync(d, { withFileTypes: true })) {
|
|
18010
|
+
if (entry.isDirectory()) scan(path14.join(d, entry.name));
|
|
17949
18011
|
else if (entry.name === "provider.json") count++;
|
|
17950
18012
|
}
|
|
17951
18013
|
} catch {
|
|
@@ -18171,19 +18233,19 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
18171
18233
|
const cat = provider.category;
|
|
18172
18234
|
const searchRoots = this.getProviderRoots();
|
|
18173
18235
|
for (const root of searchRoots) {
|
|
18174
|
-
if (!
|
|
18236
|
+
if (!fs7.existsSync(root)) continue;
|
|
18175
18237
|
const candidate = this.getProviderDir(root, cat, type);
|
|
18176
|
-
if (
|
|
18177
|
-
const catDir =
|
|
18178
|
-
if (
|
|
18238
|
+
if (fs7.existsSync(path14.join(candidate, "provider.json"))) return candidate;
|
|
18239
|
+
const catDir = path14.join(root, cat);
|
|
18240
|
+
if (fs7.existsSync(catDir)) {
|
|
18179
18241
|
try {
|
|
18180
|
-
for (const entry of
|
|
18242
|
+
for (const entry of fs7.readdirSync(catDir, { withFileTypes: true })) {
|
|
18181
18243
|
if (!entry.isDirectory()) continue;
|
|
18182
|
-
const jsonPath =
|
|
18183
|
-
if (
|
|
18244
|
+
const jsonPath = path14.join(catDir, entry.name, "provider.json");
|
|
18245
|
+
if (fs7.existsSync(jsonPath)) {
|
|
18184
18246
|
try {
|
|
18185
|
-
const data = JSON.parse(
|
|
18186
|
-
if (data.type === type) return
|
|
18247
|
+
const data = JSON.parse(fs7.readFileSync(jsonPath, "utf-8"));
|
|
18248
|
+
if (data.type === type) return path14.join(catDir, entry.name);
|
|
18187
18249
|
} catch {
|
|
18188
18250
|
}
|
|
18189
18251
|
}
|
|
@@ -18200,8 +18262,8 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
18200
18262
|
* (template substitution is NOT applied here — scripts.js handles that)
|
|
18201
18263
|
*/
|
|
18202
18264
|
buildScriptWrappersFromDir(dir) {
|
|
18203
|
-
const scriptsJs =
|
|
18204
|
-
if (
|
|
18265
|
+
const scriptsJs = path14.join(dir, "scripts.js");
|
|
18266
|
+
if (fs7.existsSync(scriptsJs)) {
|
|
18205
18267
|
try {
|
|
18206
18268
|
delete require.cache[require.resolve(scriptsJs)];
|
|
18207
18269
|
return require(scriptsJs);
|
|
@@ -18211,13 +18273,13 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
18211
18273
|
const toCamel = (name) => name.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
|
|
18212
18274
|
const result = {};
|
|
18213
18275
|
try {
|
|
18214
|
-
for (const file of
|
|
18276
|
+
for (const file of fs7.readdirSync(dir)) {
|
|
18215
18277
|
if (!file.endsWith(".js")) continue;
|
|
18216
18278
|
const scriptName = toCamel(file.replace(".js", ""));
|
|
18217
|
-
const filePath =
|
|
18279
|
+
const filePath = path14.join(dir, file);
|
|
18218
18280
|
result[scriptName] = (...args) => {
|
|
18219
18281
|
try {
|
|
18220
|
-
let content =
|
|
18282
|
+
let content = fs7.readFileSync(filePath, "utf-8");
|
|
18221
18283
|
if (args[0] && typeof args[0] === "object") {
|
|
18222
18284
|
for (const [key, val] of Object.entries(args[0])) {
|
|
18223
18285
|
let v = val;
|
|
@@ -18263,20 +18325,20 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
18263
18325
|
* Structure: dir/category/agent-name/provider.{json,js}
|
|
18264
18326
|
*/
|
|
18265
18327
|
loadDir(dir, excludeDirs) {
|
|
18266
|
-
if (!
|
|
18328
|
+
if (!fs7.existsSync(dir)) return 0;
|
|
18267
18329
|
let count = 0;
|
|
18268
18330
|
const scan = (d) => {
|
|
18269
18331
|
let entries;
|
|
18270
18332
|
try {
|
|
18271
|
-
entries =
|
|
18333
|
+
entries = fs7.readdirSync(d, { withFileTypes: true });
|
|
18272
18334
|
} catch {
|
|
18273
18335
|
return;
|
|
18274
18336
|
}
|
|
18275
18337
|
const hasJson = entries.some((e) => e.name === "provider.json");
|
|
18276
18338
|
if (hasJson) {
|
|
18277
|
-
const jsonPath =
|
|
18339
|
+
const jsonPath = path14.join(d, "provider.json");
|
|
18278
18340
|
try {
|
|
18279
|
-
const raw =
|
|
18341
|
+
const raw = fs7.readFileSync(jsonPath, "utf-8");
|
|
18280
18342
|
const mod = JSON.parse(raw);
|
|
18281
18343
|
if (typeof mod.extensionIdPattern === "string") {
|
|
18282
18344
|
const flags = mod.extensionIdPattern_flags || "";
|
|
@@ -18295,8 +18357,8 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
18295
18357
|
this.log(`\u26A0 Invalid provider at ${jsonPath}: ${validation.errors.join("; ")}`);
|
|
18296
18358
|
} else {
|
|
18297
18359
|
const hasCompatibility = Array.isArray(normalizedProvider.compatibility);
|
|
18298
|
-
const scriptsPath =
|
|
18299
|
-
if (!hasCompatibility &&
|
|
18360
|
+
const scriptsPath = path14.join(d, "scripts.js");
|
|
18361
|
+
if (!hasCompatibility && fs7.existsSync(scriptsPath)) {
|
|
18300
18362
|
try {
|
|
18301
18363
|
delete require.cache[require.resolve(scriptsPath)];
|
|
18302
18364
|
const scripts = require(scriptsPath);
|
|
@@ -18321,7 +18383,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
18321
18383
|
if (!entry.isDirectory()) continue;
|
|
18322
18384
|
if (entry.name.startsWith("_") || entry.name.startsWith(".")) continue;
|
|
18323
18385
|
if (excludeDirs && d === dir && excludeDirs.includes(entry.name)) continue;
|
|
18324
|
-
scan(
|
|
18386
|
+
scan(path14.join(d, entry.name));
|
|
18325
18387
|
}
|
|
18326
18388
|
}
|
|
18327
18389
|
};
|
|
@@ -18511,7 +18573,7 @@ async function isCdpActive(port) {
|
|
|
18511
18573
|
});
|
|
18512
18574
|
}
|
|
18513
18575
|
async function killIdeProcess(ideId) {
|
|
18514
|
-
const plat =
|
|
18576
|
+
const plat = os15.platform();
|
|
18515
18577
|
const appName = getMacAppIdentifiers()[ideId];
|
|
18516
18578
|
const winProcesses = getWinProcessNames()[ideId];
|
|
18517
18579
|
try {
|
|
@@ -18572,7 +18634,7 @@ async function killIdeProcess(ideId) {
|
|
|
18572
18634
|
}
|
|
18573
18635
|
}
|
|
18574
18636
|
function isIdeRunning(ideId) {
|
|
18575
|
-
const plat =
|
|
18637
|
+
const plat = os15.platform();
|
|
18576
18638
|
try {
|
|
18577
18639
|
if (plat === "darwin") {
|
|
18578
18640
|
const appName = getMacAppIdentifiers()[ideId];
|
|
@@ -18627,7 +18689,7 @@ function isIdeRunning(ideId) {
|
|
|
18627
18689
|
}
|
|
18628
18690
|
}
|
|
18629
18691
|
function detectCurrentWorkspace(ideId) {
|
|
18630
|
-
const plat =
|
|
18692
|
+
const plat = os15.platform();
|
|
18631
18693
|
if (plat === "darwin") {
|
|
18632
18694
|
try {
|
|
18633
18695
|
const appName = getMacAppIdentifiers()[ideId];
|
|
@@ -18642,17 +18704,17 @@ function detectCurrentWorkspace(ideId) {
|
|
|
18642
18704
|
}
|
|
18643
18705
|
} else if (plat === "win32") {
|
|
18644
18706
|
try {
|
|
18645
|
-
const
|
|
18707
|
+
const fs16 = require("fs");
|
|
18646
18708
|
const appNameMap = getMacAppIdentifiers();
|
|
18647
18709
|
const appName = appNameMap[ideId];
|
|
18648
18710
|
if (appName) {
|
|
18649
|
-
const storagePath =
|
|
18650
|
-
process.env.APPDATA ||
|
|
18711
|
+
const storagePath = path15.join(
|
|
18712
|
+
process.env.APPDATA || path15.join(os15.homedir(), "AppData", "Roaming"),
|
|
18651
18713
|
appName,
|
|
18652
18714
|
"storage.json"
|
|
18653
18715
|
);
|
|
18654
|
-
if (
|
|
18655
|
-
const data = JSON.parse(
|
|
18716
|
+
if (fs16.existsSync(storagePath)) {
|
|
18717
|
+
const data = JSON.parse(fs16.readFileSync(storagePath, "utf-8"));
|
|
18656
18718
|
const workspaces = data?.openedPathsList?.workspaces3 || data?.openedPathsList?.entries || [];
|
|
18657
18719
|
if (workspaces.length > 0) {
|
|
18658
18720
|
const recent = workspaces[0];
|
|
@@ -18669,7 +18731,7 @@ function detectCurrentWorkspace(ideId) {
|
|
|
18669
18731
|
return void 0;
|
|
18670
18732
|
}
|
|
18671
18733
|
async function launchWithCdp(options = {}) {
|
|
18672
|
-
const platform10 =
|
|
18734
|
+
const platform10 = os15.platform();
|
|
18673
18735
|
let targetIde;
|
|
18674
18736
|
const ides = await detectIDEs(getProviderLoader());
|
|
18675
18737
|
if (options.ideId) {
|
|
@@ -18824,14 +18886,14 @@ init_config();
|
|
|
18824
18886
|
init_logger();
|
|
18825
18887
|
|
|
18826
18888
|
// src/logging/command-log.ts
|
|
18827
|
-
var
|
|
18828
|
-
var
|
|
18829
|
-
var
|
|
18830
|
-
var LOG_DIR2 = process.platform === "win32" ?
|
|
18889
|
+
var fs8 = __toESM(require("fs"));
|
|
18890
|
+
var path16 = __toESM(require("path"));
|
|
18891
|
+
var os16 = __toESM(require("os"));
|
|
18892
|
+
var LOG_DIR2 = process.platform === "win32" ? path16.join(process.env.LOCALAPPDATA || process.env.APPDATA || path16.join(os16.homedir(), "AppData", "Local"), "adhdev", "logs") : process.platform === "darwin" ? path16.join(os16.homedir(), "Library", "Logs", "adhdev") : path16.join(os16.homedir(), ".local", "share", "adhdev", "logs");
|
|
18831
18893
|
var MAX_FILE_SIZE = 5 * 1024 * 1024;
|
|
18832
18894
|
var MAX_DAYS = 7;
|
|
18833
18895
|
try {
|
|
18834
|
-
|
|
18896
|
+
fs8.mkdirSync(LOG_DIR2, { recursive: true });
|
|
18835
18897
|
} catch {
|
|
18836
18898
|
}
|
|
18837
18899
|
var SENSITIVE_KEYS = /* @__PURE__ */ new Set([
|
|
@@ -18865,19 +18927,19 @@ function getDateStr2() {
|
|
|
18865
18927
|
return (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
18866
18928
|
}
|
|
18867
18929
|
var currentDate2 = getDateStr2();
|
|
18868
|
-
var currentFile =
|
|
18930
|
+
var currentFile = path16.join(LOG_DIR2, `commands-${currentDate2}.jsonl`);
|
|
18869
18931
|
var writeCount2 = 0;
|
|
18870
18932
|
function checkRotation() {
|
|
18871
18933
|
const today = getDateStr2();
|
|
18872
18934
|
if (today !== currentDate2) {
|
|
18873
18935
|
currentDate2 = today;
|
|
18874
|
-
currentFile =
|
|
18936
|
+
currentFile = path16.join(LOG_DIR2, `commands-${currentDate2}.jsonl`);
|
|
18875
18937
|
cleanOldFiles();
|
|
18876
18938
|
}
|
|
18877
18939
|
}
|
|
18878
18940
|
function cleanOldFiles() {
|
|
18879
18941
|
try {
|
|
18880
|
-
const files =
|
|
18942
|
+
const files = fs8.readdirSync(LOG_DIR2).filter((f) => f.startsWith("commands-") && f.endsWith(".jsonl"));
|
|
18881
18943
|
const cutoff = /* @__PURE__ */ new Date();
|
|
18882
18944
|
cutoff.setDate(cutoff.getDate() - MAX_DAYS);
|
|
18883
18945
|
const cutoffStr = cutoff.toISOString().slice(0, 10);
|
|
@@ -18885,7 +18947,7 @@ function cleanOldFiles() {
|
|
|
18885
18947
|
const dateMatch = file.match(/commands-(\d{4}-\d{2}-\d{2})/);
|
|
18886
18948
|
if (dateMatch && dateMatch[1] < cutoffStr) {
|
|
18887
18949
|
try {
|
|
18888
|
-
|
|
18950
|
+
fs8.unlinkSync(path16.join(LOG_DIR2, file));
|
|
18889
18951
|
} catch {
|
|
18890
18952
|
}
|
|
18891
18953
|
}
|
|
@@ -18895,14 +18957,14 @@ function cleanOldFiles() {
|
|
|
18895
18957
|
}
|
|
18896
18958
|
function checkSize() {
|
|
18897
18959
|
try {
|
|
18898
|
-
const stat =
|
|
18960
|
+
const stat = fs8.statSync(currentFile);
|
|
18899
18961
|
if (stat.size > MAX_FILE_SIZE) {
|
|
18900
18962
|
const backup = currentFile.replace(".jsonl", ".1.jsonl");
|
|
18901
18963
|
try {
|
|
18902
|
-
|
|
18964
|
+
fs8.unlinkSync(backup);
|
|
18903
18965
|
} catch {
|
|
18904
18966
|
}
|
|
18905
|
-
|
|
18967
|
+
fs8.renameSync(currentFile, backup);
|
|
18906
18968
|
}
|
|
18907
18969
|
} catch {
|
|
18908
18970
|
}
|
|
@@ -18935,14 +18997,14 @@ function logCommand(entry) {
|
|
|
18935
18997
|
...entry.error ? { err: entry.error } : {},
|
|
18936
18998
|
...entry.durationMs !== void 0 ? { ms: entry.durationMs } : {}
|
|
18937
18999
|
});
|
|
18938
|
-
|
|
19000
|
+
fs8.appendFileSync(currentFile, line + "\n");
|
|
18939
19001
|
} catch {
|
|
18940
19002
|
}
|
|
18941
19003
|
}
|
|
18942
19004
|
function getRecentCommands(count = 50) {
|
|
18943
19005
|
try {
|
|
18944
|
-
if (!
|
|
18945
|
-
const content =
|
|
19006
|
+
if (!fs8.existsSync(currentFile)) return [];
|
|
19007
|
+
const content = fs8.readFileSync(currentFile, "utf-8");
|
|
18946
19008
|
const lines = content.trim().split("\n").filter(Boolean);
|
|
18947
19009
|
return lines.slice(-count).map((line) => {
|
|
18948
19010
|
try {
|
|
@@ -18971,7 +19033,7 @@ cleanOldFiles();
|
|
|
18971
19033
|
init_logger();
|
|
18972
19034
|
|
|
18973
19035
|
// src/status/snapshot.ts
|
|
18974
|
-
var
|
|
19036
|
+
var os17 = __toESM(require("os"));
|
|
18975
19037
|
init_config();
|
|
18976
19038
|
init_terminal_screen();
|
|
18977
19039
|
init_logger();
|
|
@@ -19026,8 +19088,8 @@ function buildAvailableProviders(providerLoader) {
|
|
|
19026
19088
|
}
|
|
19027
19089
|
function buildMachineInfo(profile = "full") {
|
|
19028
19090
|
const base = {
|
|
19029
|
-
hostname:
|
|
19030
|
-
platform:
|
|
19091
|
+
hostname: os17.hostname(),
|
|
19092
|
+
platform: os17.platform()
|
|
19031
19093
|
};
|
|
19032
19094
|
if (profile === "live") {
|
|
19033
19095
|
return base;
|
|
@@ -19036,23 +19098,23 @@ function buildMachineInfo(profile = "full") {
|
|
|
19036
19098
|
const memSnap2 = getHostMemorySnapshot();
|
|
19037
19099
|
return {
|
|
19038
19100
|
...base,
|
|
19039
|
-
arch:
|
|
19040
|
-
cpus:
|
|
19101
|
+
arch: os17.arch(),
|
|
19102
|
+
cpus: os17.cpus().length,
|
|
19041
19103
|
totalMem: memSnap2.totalMem,
|
|
19042
|
-
release:
|
|
19104
|
+
release: os17.release()
|
|
19043
19105
|
};
|
|
19044
19106
|
}
|
|
19045
19107
|
const memSnap = getHostMemorySnapshot();
|
|
19046
19108
|
return {
|
|
19047
19109
|
...base,
|
|
19048
|
-
arch:
|
|
19049
|
-
cpus:
|
|
19110
|
+
arch: os17.arch(),
|
|
19111
|
+
cpus: os17.cpus().length,
|
|
19050
19112
|
totalMem: memSnap.totalMem,
|
|
19051
19113
|
freeMem: memSnap.freeMem,
|
|
19052
19114
|
availableMem: memSnap.availableMem,
|
|
19053
|
-
loadavg:
|
|
19054
|
-
uptime:
|
|
19055
|
-
release:
|
|
19115
|
+
loadavg: os17.loadavg(),
|
|
19116
|
+
uptime: os17.uptime(),
|
|
19117
|
+
release: os17.release()
|
|
19056
19118
|
};
|
|
19057
19119
|
}
|
|
19058
19120
|
function parseMessageTime(value) {
|
|
@@ -19279,42 +19341,42 @@ function buildStatusSnapshot(options) {
|
|
|
19279
19341
|
// src/commands/upgrade-helper.ts
|
|
19280
19342
|
var import_child_process8 = require("child_process");
|
|
19281
19343
|
var import_child_process9 = require("child_process");
|
|
19282
|
-
var
|
|
19283
|
-
var
|
|
19284
|
-
var
|
|
19344
|
+
var fs9 = __toESM(require("fs"));
|
|
19345
|
+
var os18 = __toESM(require("os"));
|
|
19346
|
+
var path17 = __toESM(require("path"));
|
|
19285
19347
|
var UPGRADE_HELPER_ENV = "ADHDEV_DAEMON_UPGRADE_HELPER";
|
|
19286
19348
|
function getUpgradeLogPath() {
|
|
19287
|
-
const home =
|
|
19288
|
-
const dir =
|
|
19289
|
-
|
|
19290
|
-
return
|
|
19349
|
+
const home = os18.homedir();
|
|
19350
|
+
const dir = path17.join(home, ".adhdev");
|
|
19351
|
+
fs9.mkdirSync(dir, { recursive: true });
|
|
19352
|
+
return path17.join(dir, "daemon-upgrade.log");
|
|
19291
19353
|
}
|
|
19292
19354
|
function appendUpgradeLog(message) {
|
|
19293
19355
|
const line = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${message}
|
|
19294
19356
|
`;
|
|
19295
19357
|
try {
|
|
19296
|
-
|
|
19358
|
+
fs9.appendFileSync(getUpgradeLogPath(), line, "utf8");
|
|
19297
19359
|
} catch {
|
|
19298
19360
|
}
|
|
19299
19361
|
}
|
|
19300
19362
|
function resolveSiblingNpmInvocation(nodeExecutable, platform10 = process.platform) {
|
|
19301
|
-
const binDir =
|
|
19363
|
+
const binDir = path17.dirname(nodeExecutable);
|
|
19302
19364
|
if (platform10 === "win32") {
|
|
19303
|
-
const npmCliPath =
|
|
19304
|
-
if (
|
|
19365
|
+
const npmCliPath = path17.join(binDir, "node_modules", "npm", "bin", "npm-cli.js");
|
|
19366
|
+
if (fs9.existsSync(npmCliPath)) {
|
|
19305
19367
|
return { executable: nodeExecutable, argsPrefix: [npmCliPath], execOptions: getNpmExecOptions(platform10) };
|
|
19306
19368
|
}
|
|
19307
19369
|
for (const candidate of ["npm.exe", "npm"]) {
|
|
19308
|
-
const candidatePath =
|
|
19309
|
-
if (
|
|
19370
|
+
const candidatePath = path17.join(binDir, candidate);
|
|
19371
|
+
if (fs9.existsSync(candidatePath)) {
|
|
19310
19372
|
return { executable: candidatePath, argsPrefix: [], execOptions: getNpmExecOptions(platform10) };
|
|
19311
19373
|
}
|
|
19312
19374
|
}
|
|
19313
19375
|
return { executable: nodeExecutable, argsPrefix: [npmCliPath], execOptions: getNpmExecOptions(platform10) };
|
|
19314
19376
|
}
|
|
19315
19377
|
for (const candidate of ["npm"]) {
|
|
19316
|
-
const candidatePath =
|
|
19317
|
-
if (
|
|
19378
|
+
const candidatePath = path17.join(binDir, candidate);
|
|
19379
|
+
if (fs9.existsSync(candidatePath)) {
|
|
19318
19380
|
return { executable: candidatePath, argsPrefix: [], execOptions: getNpmExecOptions(platform10) };
|
|
19319
19381
|
}
|
|
19320
19382
|
}
|
|
@@ -19324,22 +19386,22 @@ function findCurrentPackageRoot(currentCliPath, packageName) {
|
|
|
19324
19386
|
if (!currentCliPath) return null;
|
|
19325
19387
|
let resolvedPath = currentCliPath;
|
|
19326
19388
|
try {
|
|
19327
|
-
resolvedPath =
|
|
19389
|
+
resolvedPath = fs9.realpathSync.native(currentCliPath);
|
|
19328
19390
|
} catch {
|
|
19329
19391
|
}
|
|
19330
19392
|
let currentDir = resolvedPath;
|
|
19331
19393
|
try {
|
|
19332
|
-
if (
|
|
19333
|
-
currentDir =
|
|
19394
|
+
if (fs9.statSync(resolvedPath).isFile()) {
|
|
19395
|
+
currentDir = path17.dirname(resolvedPath);
|
|
19334
19396
|
}
|
|
19335
19397
|
} catch {
|
|
19336
|
-
currentDir =
|
|
19398
|
+
currentDir = path17.dirname(resolvedPath);
|
|
19337
19399
|
}
|
|
19338
19400
|
while (true) {
|
|
19339
|
-
const packageJsonPath =
|
|
19401
|
+
const packageJsonPath = path17.join(currentDir, "package.json");
|
|
19340
19402
|
try {
|
|
19341
|
-
if (
|
|
19342
|
-
const parsed = JSON.parse(
|
|
19403
|
+
if (fs9.existsSync(packageJsonPath)) {
|
|
19404
|
+
const parsed = JSON.parse(fs9.readFileSync(packageJsonPath, "utf8"));
|
|
19343
19405
|
if (parsed?.name === packageName) {
|
|
19344
19406
|
const normalized = currentDir.replace(/\\/g, "/");
|
|
19345
19407
|
return normalized.includes("/node_modules/") ? currentDir : null;
|
|
@@ -19347,7 +19409,7 @@ function findCurrentPackageRoot(currentCliPath, packageName) {
|
|
|
19347
19409
|
}
|
|
19348
19410
|
} catch {
|
|
19349
19411
|
}
|
|
19350
|
-
const parentDir =
|
|
19412
|
+
const parentDir = path17.dirname(currentDir);
|
|
19351
19413
|
if (parentDir === currentDir) {
|
|
19352
19414
|
return null;
|
|
19353
19415
|
}
|
|
@@ -19355,13 +19417,13 @@ function findCurrentPackageRoot(currentCliPath, packageName) {
|
|
|
19355
19417
|
}
|
|
19356
19418
|
}
|
|
19357
19419
|
function resolveInstallPrefixFromPackageRoot(packageRoot, packageName) {
|
|
19358
|
-
const nodeModulesDir = packageName.startsWith("@") ?
|
|
19359
|
-
if (
|
|
19420
|
+
const nodeModulesDir = packageName.startsWith("@") ? path17.dirname(path17.dirname(packageRoot)) : path17.dirname(packageRoot);
|
|
19421
|
+
if (path17.basename(nodeModulesDir) !== "node_modules") {
|
|
19360
19422
|
return null;
|
|
19361
19423
|
}
|
|
19362
|
-
const maybeLibDir =
|
|
19363
|
-
if (
|
|
19364
|
-
return
|
|
19424
|
+
const maybeLibDir = path17.dirname(nodeModulesDir);
|
|
19425
|
+
if (path17.basename(maybeLibDir) === "lib") {
|
|
19426
|
+
return path17.dirname(maybeLibDir);
|
|
19365
19427
|
}
|
|
19366
19428
|
return maybeLibDir;
|
|
19367
19429
|
}
|
|
@@ -19476,10 +19538,10 @@ async function waitForPidExit(pid, timeoutMs) {
|
|
|
19476
19538
|
}
|
|
19477
19539
|
}
|
|
19478
19540
|
function stopSessionHostProcesses(appName) {
|
|
19479
|
-
const pidFile =
|
|
19541
|
+
const pidFile = path17.join(os18.homedir(), ".adhdev", `${appName}-session-host.pid`);
|
|
19480
19542
|
try {
|
|
19481
|
-
if (
|
|
19482
|
-
const pid = Number.parseInt(
|
|
19543
|
+
if (fs9.existsSync(pidFile)) {
|
|
19544
|
+
const pid = Number.parseInt(fs9.readFileSync(pidFile, "utf8").trim(), 10);
|
|
19483
19545
|
if (Number.isFinite(pid) && pid !== process.pid && isManagedSessionHostPid(pid)) {
|
|
19484
19546
|
killPid(pid);
|
|
19485
19547
|
}
|
|
@@ -19487,15 +19549,15 @@ function stopSessionHostProcesses(appName) {
|
|
|
19487
19549
|
} catch {
|
|
19488
19550
|
} finally {
|
|
19489
19551
|
try {
|
|
19490
|
-
|
|
19552
|
+
fs9.unlinkSync(pidFile);
|
|
19491
19553
|
} catch {
|
|
19492
19554
|
}
|
|
19493
19555
|
}
|
|
19494
19556
|
}
|
|
19495
19557
|
function removeDaemonPidFile() {
|
|
19496
|
-
const pidFile =
|
|
19558
|
+
const pidFile = path17.join(os18.homedir(), ".adhdev", "daemon.pid");
|
|
19497
19559
|
try {
|
|
19498
|
-
|
|
19560
|
+
fs9.unlinkSync(pidFile);
|
|
19499
19561
|
} catch {
|
|
19500
19562
|
}
|
|
19501
19563
|
}
|
|
@@ -19504,7 +19566,7 @@ function cleanupStaleGlobalInstallDirs(pkgName, surface) {
|
|
|
19504
19566
|
const npmRoot = String(execNpmCommandSync(["root", "-g", ...prefixArgs], { encoding: "utf8" }, surface)).trim();
|
|
19505
19567
|
if (!npmRoot) return;
|
|
19506
19568
|
const npmPrefix = surface.installPrefix || String(execNpmCommandSync(["prefix", "-g", ...prefixArgs], { encoding: "utf8" }, surface)).trim();
|
|
19507
|
-
const binDir = process.platform === "win32" ? npmPrefix :
|
|
19569
|
+
const binDir = process.platform === "win32" ? npmPrefix : path17.join(npmPrefix, "bin");
|
|
19508
19570
|
const packageBaseName = pkgName.startsWith("@") ? pkgName.split("/")[1] : pkgName;
|
|
19509
19571
|
const binNames = /* @__PURE__ */ new Set([packageBaseName]);
|
|
19510
19572
|
if (pkgName === "@adhdev/daemon-standalone") {
|
|
@@ -19512,25 +19574,25 @@ function cleanupStaleGlobalInstallDirs(pkgName, surface) {
|
|
|
19512
19574
|
}
|
|
19513
19575
|
if (pkgName.startsWith("@")) {
|
|
19514
19576
|
const [scope, name] = pkgName.split("/");
|
|
19515
|
-
const scopeDir =
|
|
19516
|
-
if (!
|
|
19517
|
-
for (const entry of
|
|
19577
|
+
const scopeDir = path17.join(npmRoot, scope);
|
|
19578
|
+
if (!fs9.existsSync(scopeDir)) return;
|
|
19579
|
+
for (const entry of fs9.readdirSync(scopeDir)) {
|
|
19518
19580
|
if (!entry.startsWith(`.${name}-`)) continue;
|
|
19519
|
-
|
|
19520
|
-
appendUpgradeLog(`Removed stale scoped staging dir: ${
|
|
19581
|
+
fs9.rmSync(path17.join(scopeDir, entry), { recursive: true, force: true });
|
|
19582
|
+
appendUpgradeLog(`Removed stale scoped staging dir: ${path17.join(scopeDir, entry)}`);
|
|
19521
19583
|
}
|
|
19522
19584
|
} else {
|
|
19523
|
-
for (const entry of
|
|
19585
|
+
for (const entry of fs9.readdirSync(npmRoot)) {
|
|
19524
19586
|
if (!entry.startsWith(`.${pkgName}-`)) continue;
|
|
19525
|
-
|
|
19526
|
-
appendUpgradeLog(`Removed stale staging dir: ${
|
|
19587
|
+
fs9.rmSync(path17.join(npmRoot, entry), { recursive: true, force: true });
|
|
19588
|
+
appendUpgradeLog(`Removed stale staging dir: ${path17.join(npmRoot, entry)}`);
|
|
19527
19589
|
}
|
|
19528
19590
|
}
|
|
19529
|
-
if (
|
|
19530
|
-
for (const entry of
|
|
19591
|
+
if (fs9.existsSync(binDir)) {
|
|
19592
|
+
for (const entry of fs9.readdirSync(binDir)) {
|
|
19531
19593
|
if (!Array.from(binNames).some((name) => entry.startsWith(`.${name}-`))) continue;
|
|
19532
|
-
|
|
19533
|
-
appendUpgradeLog(`Removed stale bin staging entry: ${
|
|
19594
|
+
fs9.rmSync(path17.join(binDir, entry), { recursive: true, force: true });
|
|
19595
|
+
appendUpgradeLog(`Removed stale bin staging entry: ${path17.join(binDir, entry)}`);
|
|
19534
19596
|
}
|
|
19535
19597
|
}
|
|
19536
19598
|
}
|
|
@@ -19615,7 +19677,7 @@ async function maybeRunDaemonUpgradeHelperFromEnv() {
|
|
|
19615
19677
|
}
|
|
19616
19678
|
|
|
19617
19679
|
// src/commands/router.ts
|
|
19618
|
-
var
|
|
19680
|
+
var fs10 = __toESM(require("fs"));
|
|
19619
19681
|
var CHAT_COMMANDS = [
|
|
19620
19682
|
"send_chat",
|
|
19621
19683
|
"new_chat",
|
|
@@ -19851,8 +19913,8 @@ var DaemonCommandRouter = class {
|
|
|
19851
19913
|
if (sinceTs > 0) {
|
|
19852
19914
|
return { success: true, logs: [], totalBuffered: 0 };
|
|
19853
19915
|
}
|
|
19854
|
-
if (
|
|
19855
|
-
const content =
|
|
19916
|
+
if (fs10.existsSync(LOG_PATH)) {
|
|
19917
|
+
const content = fs10.readFileSync(LOG_PATH, "utf-8");
|
|
19856
19918
|
const allLines = content.split("\n");
|
|
19857
19919
|
const recent = allLines.slice(-count).join("\n");
|
|
19858
19920
|
return { success: true, logs: recent, totalLines: allLines.length };
|
|
@@ -22007,12 +22069,12 @@ init_io_contracts();
|
|
|
22007
22069
|
init_chat_message_normalization();
|
|
22008
22070
|
|
|
22009
22071
|
// src/providers/version-archive.ts
|
|
22010
|
-
var
|
|
22011
|
-
var
|
|
22012
|
-
var
|
|
22072
|
+
var fs11 = __toESM(require("fs"));
|
|
22073
|
+
var path18 = __toESM(require("path"));
|
|
22074
|
+
var os19 = __toESM(require("os"));
|
|
22013
22075
|
var import_child_process10 = require("child_process");
|
|
22014
22076
|
var import_os3 = require("os");
|
|
22015
|
-
var ARCHIVE_PATH =
|
|
22077
|
+
var ARCHIVE_PATH = path18.join(os19.homedir(), ".adhdev", "version-history.json");
|
|
22016
22078
|
var MAX_ENTRIES_PER_PROVIDER = 20;
|
|
22017
22079
|
var VersionArchive = class {
|
|
22018
22080
|
history = {};
|
|
@@ -22021,8 +22083,8 @@ var VersionArchive = class {
|
|
|
22021
22083
|
}
|
|
22022
22084
|
load() {
|
|
22023
22085
|
try {
|
|
22024
|
-
if (
|
|
22025
|
-
this.history = JSON.parse(
|
|
22086
|
+
if (fs11.existsSync(ARCHIVE_PATH)) {
|
|
22087
|
+
this.history = JSON.parse(fs11.readFileSync(ARCHIVE_PATH, "utf-8"));
|
|
22026
22088
|
}
|
|
22027
22089
|
} catch {
|
|
22028
22090
|
this.history = {};
|
|
@@ -22059,8 +22121,8 @@ var VersionArchive = class {
|
|
|
22059
22121
|
}
|
|
22060
22122
|
save() {
|
|
22061
22123
|
try {
|
|
22062
|
-
|
|
22063
|
-
|
|
22124
|
+
fs11.mkdirSync(path18.dirname(ARCHIVE_PATH), { recursive: true });
|
|
22125
|
+
fs11.writeFileSync(ARCHIVE_PATH, JSON.stringify(this.history, null, 2));
|
|
22064
22126
|
} catch {
|
|
22065
22127
|
}
|
|
22066
22128
|
}
|
|
@@ -22115,19 +22177,19 @@ function getVersion(binary, versionCommand) {
|
|
|
22115
22177
|
function checkPathExists2(paths) {
|
|
22116
22178
|
for (const p of paths) {
|
|
22117
22179
|
if (p.includes("*")) {
|
|
22118
|
-
const home =
|
|
22119
|
-
const resolved = p.replace(/\*/g, home.split(
|
|
22120
|
-
if (
|
|
22180
|
+
const home = os19.homedir();
|
|
22181
|
+
const resolved = p.replace(/\*/g, home.split(path18.sep).pop() || "");
|
|
22182
|
+
if (fs11.existsSync(resolved)) return resolved;
|
|
22121
22183
|
} else {
|
|
22122
|
-
if (
|
|
22184
|
+
if (fs11.existsSync(p)) return p;
|
|
22123
22185
|
}
|
|
22124
22186
|
}
|
|
22125
22187
|
return null;
|
|
22126
22188
|
}
|
|
22127
22189
|
function getMacAppVersion(appPath) {
|
|
22128
22190
|
if ((0, import_os3.platform)() !== "darwin" || !appPath.endsWith(".app")) return null;
|
|
22129
|
-
const plistPath =
|
|
22130
|
-
if (!
|
|
22191
|
+
const plistPath = path18.join(appPath, "Contents", "Info.plist");
|
|
22192
|
+
if (!fs11.existsSync(plistPath)) return null;
|
|
22131
22193
|
const raw = runCommand(`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${plistPath}"`);
|
|
22132
22194
|
return raw || null;
|
|
22133
22195
|
}
|
|
@@ -22152,8 +22214,8 @@ async function detectAllVersions(loader, archive) {
|
|
|
22152
22214
|
const cliBin = provider.cli ? findBinary2(provider.cli) : null;
|
|
22153
22215
|
let resolvedBin = cliBin;
|
|
22154
22216
|
if (!resolvedBin && appPath && currentOs === "darwin") {
|
|
22155
|
-
const bundled =
|
|
22156
|
-
if (provider.cli &&
|
|
22217
|
+
const bundled = path18.join(appPath, "Contents", "Resources", "app", "bin", provider.cli || "");
|
|
22218
|
+
if (provider.cli && fs11.existsSync(bundled)) resolvedBin = bundled;
|
|
22157
22219
|
}
|
|
22158
22220
|
info.installed = !!(appPath || resolvedBin);
|
|
22159
22221
|
info.path = appPath || null;
|
|
@@ -22192,8 +22254,8 @@ async function detectAllVersions(loader, archive) {
|
|
|
22192
22254
|
|
|
22193
22255
|
// src/daemon/dev-server.ts
|
|
22194
22256
|
var http2 = __toESM(require("http"));
|
|
22195
|
-
var
|
|
22196
|
-
var
|
|
22257
|
+
var fs15 = __toESM(require("fs"));
|
|
22258
|
+
var path22 = __toESM(require("path"));
|
|
22197
22259
|
init_config();
|
|
22198
22260
|
|
|
22199
22261
|
// src/daemon/scaffold-template.ts
|
|
@@ -22543,8 +22605,8 @@ async (params) => {
|
|
|
22543
22605
|
init_logger();
|
|
22544
22606
|
|
|
22545
22607
|
// src/daemon/dev-cdp-handlers.ts
|
|
22546
|
-
var
|
|
22547
|
-
var
|
|
22608
|
+
var fs12 = __toESM(require("fs"));
|
|
22609
|
+
var path19 = __toESM(require("path"));
|
|
22548
22610
|
init_logger();
|
|
22549
22611
|
async function handleCdpEvaluate(ctx, req, res) {
|
|
22550
22612
|
const body = await ctx.readBody(req);
|
|
@@ -22723,18 +22785,18 @@ async function handleScriptHints(ctx, type, _req, res) {
|
|
|
22723
22785
|
return;
|
|
22724
22786
|
}
|
|
22725
22787
|
let scriptsPath = "";
|
|
22726
|
-
const directScripts =
|
|
22727
|
-
if (
|
|
22788
|
+
const directScripts = path19.join(dir, "scripts.js");
|
|
22789
|
+
if (fs12.existsSync(directScripts)) {
|
|
22728
22790
|
scriptsPath = directScripts;
|
|
22729
22791
|
} else {
|
|
22730
|
-
const scriptsDir =
|
|
22731
|
-
if (
|
|
22732
|
-
const versions =
|
|
22733
|
-
return
|
|
22792
|
+
const scriptsDir = path19.join(dir, "scripts");
|
|
22793
|
+
if (fs12.existsSync(scriptsDir)) {
|
|
22794
|
+
const versions = fs12.readdirSync(scriptsDir).filter((d) => {
|
|
22795
|
+
return fs12.statSync(path19.join(scriptsDir, d)).isDirectory();
|
|
22734
22796
|
}).sort().reverse();
|
|
22735
22797
|
for (const ver of versions) {
|
|
22736
|
-
const p =
|
|
22737
|
-
if (
|
|
22798
|
+
const p = path19.join(scriptsDir, ver, "scripts.js");
|
|
22799
|
+
if (fs12.existsSync(p)) {
|
|
22738
22800
|
scriptsPath = p;
|
|
22739
22801
|
break;
|
|
22740
22802
|
}
|
|
@@ -22746,7 +22808,7 @@ async function handleScriptHints(ctx, type, _req, res) {
|
|
|
22746
22808
|
return;
|
|
22747
22809
|
}
|
|
22748
22810
|
try {
|
|
22749
|
-
const source =
|
|
22811
|
+
const source = fs12.readFileSync(scriptsPath, "utf-8");
|
|
22750
22812
|
const hints = {};
|
|
22751
22813
|
const funcRegex = /module\.exports\.(\w+)\s*=\s*function\s+\w+\s*\(params\)/g;
|
|
22752
22814
|
let match;
|
|
@@ -23561,8 +23623,8 @@ async function handleDomContext(ctx, type, req, res) {
|
|
|
23561
23623
|
}
|
|
23562
23624
|
|
|
23563
23625
|
// src/daemon/dev-cli-debug.ts
|
|
23564
|
-
var
|
|
23565
|
-
var
|
|
23626
|
+
var fs13 = __toESM(require("fs"));
|
|
23627
|
+
var path20 = __toESM(require("path"));
|
|
23566
23628
|
function slugifyFixtureName(value) {
|
|
23567
23629
|
const normalized = String(value || "").trim().toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
23568
23630
|
return normalized || `fixture-${Date.now()}`;
|
|
@@ -23572,15 +23634,15 @@ function getCliFixtureDir(ctx, type) {
|
|
|
23572
23634
|
if (!providerDir) {
|
|
23573
23635
|
throw new Error(`Provider directory not found for '${type}'`);
|
|
23574
23636
|
}
|
|
23575
|
-
return
|
|
23637
|
+
return path20.join(providerDir, "fixtures");
|
|
23576
23638
|
}
|
|
23577
23639
|
function readCliFixture(ctx, type, name) {
|
|
23578
23640
|
const fixtureDir = getCliFixtureDir(ctx, type);
|
|
23579
|
-
const filePath =
|
|
23580
|
-
if (!
|
|
23641
|
+
const filePath = path20.join(fixtureDir, `${name}.json`);
|
|
23642
|
+
if (!fs13.existsSync(filePath)) {
|
|
23581
23643
|
throw new Error(`Fixture not found: ${filePath}`);
|
|
23582
23644
|
}
|
|
23583
|
-
return JSON.parse(
|
|
23645
|
+
return JSON.parse(fs13.readFileSync(filePath, "utf-8"));
|
|
23584
23646
|
}
|
|
23585
23647
|
function getExerciseTranscriptText(result) {
|
|
23586
23648
|
const parts = [];
|
|
@@ -24316,7 +24378,7 @@ async function handleCliFixtureCapture(ctx, req, res) {
|
|
|
24316
24378
|
return;
|
|
24317
24379
|
}
|
|
24318
24380
|
const fixtureDir = getCliFixtureDir(ctx, type);
|
|
24319
|
-
|
|
24381
|
+
fs13.mkdirSync(fixtureDir, { recursive: true });
|
|
24320
24382
|
const name = slugifyFixtureName(String(body?.name || `${type}-${Date.now()}`));
|
|
24321
24383
|
const result = await runCliExerciseInternal(ctx, { ...request, type });
|
|
24322
24384
|
const fixture = {
|
|
@@ -24343,8 +24405,8 @@ async function handleCliFixtureCapture(ctx, req, res) {
|
|
|
24343
24405
|
},
|
|
24344
24406
|
notes: typeof body?.notes === "string" ? body.notes : void 0
|
|
24345
24407
|
};
|
|
24346
|
-
const filePath =
|
|
24347
|
-
|
|
24408
|
+
const filePath = path20.join(fixtureDir, `${name}.json`);
|
|
24409
|
+
fs13.writeFileSync(filePath, JSON.stringify(fixture, null, 2));
|
|
24348
24410
|
ctx.json(res, 200, {
|
|
24349
24411
|
saved: true,
|
|
24350
24412
|
name,
|
|
@@ -24362,14 +24424,14 @@ async function handleCliFixtureCapture(ctx, req, res) {
|
|
|
24362
24424
|
async function handleCliFixtureList(ctx, type, _req, res) {
|
|
24363
24425
|
try {
|
|
24364
24426
|
const fixtureDir = getCliFixtureDir(ctx, type);
|
|
24365
|
-
if (!
|
|
24427
|
+
if (!fs13.existsSync(fixtureDir)) {
|
|
24366
24428
|
ctx.json(res, 200, { fixtures: [], count: 0 });
|
|
24367
24429
|
return;
|
|
24368
24430
|
}
|
|
24369
|
-
const fixtures =
|
|
24370
|
-
const fullPath =
|
|
24431
|
+
const fixtures = fs13.readdirSync(fixtureDir).filter((file) => file.endsWith(".json")).sort((a, b) => b.localeCompare(a, void 0, { numeric: true, sensitivity: "base" })).map((file) => {
|
|
24432
|
+
const fullPath = path20.join(fixtureDir, file);
|
|
24371
24433
|
try {
|
|
24372
|
-
const raw = JSON.parse(
|
|
24434
|
+
const raw = JSON.parse(fs13.readFileSync(fullPath, "utf-8"));
|
|
24373
24435
|
return {
|
|
24374
24436
|
name: raw.name || file.replace(/\.json$/i, ""),
|
|
24375
24437
|
path: fullPath,
|
|
@@ -24502,9 +24564,9 @@ async function handleCliRaw(ctx, req, res) {
|
|
|
24502
24564
|
}
|
|
24503
24565
|
|
|
24504
24566
|
// src/daemon/dev-auto-implement.ts
|
|
24505
|
-
var
|
|
24506
|
-
var
|
|
24507
|
-
var
|
|
24567
|
+
var fs14 = __toESM(require("fs"));
|
|
24568
|
+
var path21 = __toESM(require("path"));
|
|
24569
|
+
var os20 = __toESM(require("os"));
|
|
24508
24570
|
function getAutoImplPid(ctx) {
|
|
24509
24571
|
const pid = ctx.autoImplProcess?.pid;
|
|
24510
24572
|
return typeof pid === "number" && pid > 0 ? pid : null;
|
|
@@ -24550,38 +24612,38 @@ function resolveAutoImplReference(ctx, category, requestedReference, targetType)
|
|
|
24550
24612
|
return fallback?.type || null;
|
|
24551
24613
|
}
|
|
24552
24614
|
function getLatestScriptVersionDir(scriptsDir) {
|
|
24553
|
-
if (!
|
|
24554
|
-
const versions =
|
|
24615
|
+
if (!fs14.existsSync(scriptsDir)) return null;
|
|
24616
|
+
const versions = fs14.readdirSync(scriptsDir).filter((d) => {
|
|
24555
24617
|
try {
|
|
24556
|
-
return
|
|
24618
|
+
return fs14.statSync(path21.join(scriptsDir, d)).isDirectory();
|
|
24557
24619
|
} catch {
|
|
24558
24620
|
return false;
|
|
24559
24621
|
}
|
|
24560
24622
|
}).sort((a, b) => b.localeCompare(a, void 0, { numeric: true, sensitivity: "base" }));
|
|
24561
24623
|
if (versions.length === 0) return null;
|
|
24562
|
-
return
|
|
24624
|
+
return path21.join(scriptsDir, versions[0]);
|
|
24563
24625
|
}
|
|
24564
24626
|
function resolveAutoImplWritableProviderDir(ctx, category, type, requestedDir) {
|
|
24565
|
-
const canonicalUserDir =
|
|
24566
|
-
const desiredDir = requestedDir ?
|
|
24567
|
-
const upstreamRoot =
|
|
24568
|
-
if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${
|
|
24627
|
+
const canonicalUserDir = path21.resolve(ctx.providerLoader.getUserProviderDir(category, type));
|
|
24628
|
+
const desiredDir = requestedDir ? path21.resolve(requestedDir) : canonicalUserDir;
|
|
24629
|
+
const upstreamRoot = path21.resolve(ctx.providerLoader.getUpstreamDir());
|
|
24630
|
+
if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${path21.sep}`)) {
|
|
24569
24631
|
return { dir: null, reason: `Refusing to write into upstream provider directory: ${desiredDir}` };
|
|
24570
24632
|
}
|
|
24571
|
-
if (
|
|
24633
|
+
if (path21.basename(desiredDir) !== type) {
|
|
24572
24634
|
return { dir: null, reason: `Requested writable provider directory must end with '${type}': ${desiredDir}` };
|
|
24573
24635
|
}
|
|
24574
24636
|
const sourceDir = ctx.findProviderDir(type);
|
|
24575
24637
|
if (!sourceDir) {
|
|
24576
24638
|
return { dir: null, reason: `Provider source directory not found for '${type}'` };
|
|
24577
24639
|
}
|
|
24578
|
-
if (!
|
|
24579
|
-
|
|
24580
|
-
|
|
24640
|
+
if (!fs14.existsSync(desiredDir)) {
|
|
24641
|
+
fs14.mkdirSync(path21.dirname(desiredDir), { recursive: true });
|
|
24642
|
+
fs14.cpSync(sourceDir, desiredDir, { recursive: true });
|
|
24581
24643
|
ctx.log(`Auto-implement writable copy created: ${desiredDir}`);
|
|
24582
24644
|
}
|
|
24583
|
-
const providerJson =
|
|
24584
|
-
if (!
|
|
24645
|
+
const providerJson = path21.join(desiredDir, "provider.json");
|
|
24646
|
+
if (!fs14.existsSync(providerJson)) {
|
|
24585
24647
|
return { dir: null, reason: `provider.json not found in writable provider directory: ${desiredDir}` };
|
|
24586
24648
|
}
|
|
24587
24649
|
return { dir: desiredDir };
|
|
@@ -24589,15 +24651,15 @@ function resolveAutoImplWritableProviderDir(ctx, category, type, requestedDir) {
|
|
|
24589
24651
|
function loadAutoImplReferenceScripts(ctx, referenceType) {
|
|
24590
24652
|
if (!referenceType) return {};
|
|
24591
24653
|
const refDir = ctx.findProviderDir(referenceType);
|
|
24592
|
-
if (!refDir || !
|
|
24654
|
+
if (!refDir || !fs14.existsSync(refDir)) return {};
|
|
24593
24655
|
const referenceScripts = {};
|
|
24594
|
-
const scriptsDir =
|
|
24656
|
+
const scriptsDir = path21.join(refDir, "scripts");
|
|
24595
24657
|
const latestDir = getLatestScriptVersionDir(scriptsDir);
|
|
24596
24658
|
if (!latestDir) return referenceScripts;
|
|
24597
|
-
for (const file of
|
|
24659
|
+
for (const file of fs14.readdirSync(latestDir)) {
|
|
24598
24660
|
if (!file.endsWith(".js")) continue;
|
|
24599
24661
|
try {
|
|
24600
|
-
referenceScripts[file] =
|
|
24662
|
+
referenceScripts[file] = fs14.readFileSync(path21.join(latestDir, file), "utf-8");
|
|
24601
24663
|
} catch {
|
|
24602
24664
|
}
|
|
24603
24665
|
}
|
|
@@ -24705,16 +24767,16 @@ async function handleAutoImplement(ctx, type, req, res) {
|
|
|
24705
24767
|
});
|
|
24706
24768
|
const referenceScripts = loadAutoImplReferenceScripts(ctx, resolvedReference);
|
|
24707
24769
|
const prompt = buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domContext, referenceScripts, comment, resolvedReference, verification);
|
|
24708
|
-
const tmpDir =
|
|
24709
|
-
if (!
|
|
24710
|
-
const promptFile =
|
|
24711
|
-
|
|
24770
|
+
const tmpDir = path21.join(os20.tmpdir(), "adhdev-autoimpl");
|
|
24771
|
+
if (!fs14.existsSync(tmpDir)) fs14.mkdirSync(tmpDir, { recursive: true });
|
|
24772
|
+
const promptFile = path21.join(tmpDir, `prompt-${type}-${Date.now()}.md`);
|
|
24773
|
+
fs14.writeFileSync(promptFile, prompt, "utf-8");
|
|
24712
24774
|
ctx.log(`Auto-implement prompt written to ${promptFile} (${prompt.length} chars)`);
|
|
24713
24775
|
const agentProvider = ctx.providerLoader.resolve(agent) || ctx.providerLoader.getMeta(agent);
|
|
24714
24776
|
const spawn4 = agentProvider?.spawn;
|
|
24715
24777
|
if (!spawn4?.command) {
|
|
24716
24778
|
try {
|
|
24717
|
-
|
|
24779
|
+
fs14.unlinkSync(promptFile);
|
|
24718
24780
|
} catch {
|
|
24719
24781
|
}
|
|
24720
24782
|
ctx.json(res, 400, { error: `Agent '${agent}' has no spawn config. Select a CLI provider with a spawn configuration.` });
|
|
@@ -24816,7 +24878,7 @@ async function handleAutoImplement(ctx, type, req, res) {
|
|
|
24816
24878
|
} catch {
|
|
24817
24879
|
}
|
|
24818
24880
|
try {
|
|
24819
|
-
|
|
24881
|
+
fs14.unlinkSync(promptFile);
|
|
24820
24882
|
} catch {
|
|
24821
24883
|
}
|
|
24822
24884
|
ctx.log(`Auto-implement (ACP) ${success ? "completed" : "failed"}: ${type} (exit: ${code})`);
|
|
@@ -24860,7 +24922,7 @@ async function handleAutoImplement(ctx, type, req, res) {
|
|
|
24860
24922
|
const interactiveFlags = ["--yolo", "--interactive", "-i"];
|
|
24861
24923
|
const baseArgs = [...spawn4.args || []].filter((a) => !interactiveFlags.includes(a));
|
|
24862
24924
|
let shellCmd;
|
|
24863
|
-
const isWin =
|
|
24925
|
+
const isWin = os20.platform() === "win32";
|
|
24864
24926
|
const escapeArg = (a) => isWin ? `"${a.replace(/"/g, '""')}"` : `'${a.replace(/'/g, "'\\''")}'`;
|
|
24865
24927
|
const promptMode = autoImpl?.promptMode ?? "stdin";
|
|
24866
24928
|
const extraArgs = autoImpl?.extraArgs ?? [];
|
|
@@ -24899,7 +24961,7 @@ async function handleAutoImplement(ctx, type, req, res) {
|
|
|
24899
24961
|
try {
|
|
24900
24962
|
const pty = require("node-pty");
|
|
24901
24963
|
ctx.log(`Auto-implement spawn (PTY): ${shellCmd}`);
|
|
24902
|
-
const isWin2 =
|
|
24964
|
+
const isWin2 = os20.platform() === "win32";
|
|
24903
24965
|
child = pty.spawn(isWin2 ? "cmd.exe" : process.env.SHELL || "/bin/zsh", [isWin2 ? "/c" : "-c", shellCmd], {
|
|
24904
24966
|
name: "xterm-256color",
|
|
24905
24967
|
cols: 120,
|
|
@@ -25042,7 +25104,7 @@ async function handleAutoImplement(ctx, type, req, res) {
|
|
|
25042
25104
|
}
|
|
25043
25105
|
});
|
|
25044
25106
|
try {
|
|
25045
|
-
|
|
25107
|
+
fs14.unlinkSync(promptFile);
|
|
25046
25108
|
} catch {
|
|
25047
25109
|
}
|
|
25048
25110
|
ctx.log(`Auto-implement ${success ? "completed" : "failed"}: ${type} (exit: ${code})${verificationSummary ? ` verify=${verificationSummary.pass ? "pass" : "fail"}` : ""}`);
|
|
@@ -25139,7 +25201,7 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
|
|
|
25139
25201
|
setMode: "set_mode.js"
|
|
25140
25202
|
};
|
|
25141
25203
|
const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
|
|
25142
|
-
const scriptsDir =
|
|
25204
|
+
const scriptsDir = path21.join(providerDir, "scripts");
|
|
25143
25205
|
const latestScriptsDir = getLatestScriptVersionDir(scriptsDir);
|
|
25144
25206
|
if (latestScriptsDir) {
|
|
25145
25207
|
lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
|
|
@@ -25147,10 +25209,10 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
|
|
|
25147
25209
|
lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
|
|
25148
25210
|
lines.push("These are the ONLY files you are allowed to modify. Replace the TODO stubs with working implementations.");
|
|
25149
25211
|
lines.push("");
|
|
25150
|
-
for (const file of
|
|
25212
|
+
for (const file of fs14.readdirSync(latestScriptsDir)) {
|
|
25151
25213
|
if (file.endsWith(".js") && targetFileNames.has(file)) {
|
|
25152
25214
|
try {
|
|
25153
|
-
const content =
|
|
25215
|
+
const content = fs14.readFileSync(path21.join(latestScriptsDir, file), "utf-8");
|
|
25154
25216
|
lines.push(`### \`${file}\` \u270F\uFE0F EDIT`);
|
|
25155
25217
|
lines.push("```javascript");
|
|
25156
25218
|
lines.push(content);
|
|
@@ -25160,14 +25222,14 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
|
|
|
25160
25222
|
}
|
|
25161
25223
|
}
|
|
25162
25224
|
}
|
|
25163
|
-
const refFiles =
|
|
25225
|
+
const refFiles = fs14.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
|
|
25164
25226
|
if (refFiles.length > 0) {
|
|
25165
25227
|
lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
|
|
25166
25228
|
lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
|
|
25167
25229
|
lines.push("");
|
|
25168
25230
|
for (const file of refFiles) {
|
|
25169
25231
|
try {
|
|
25170
|
-
const content =
|
|
25232
|
+
const content = fs14.readFileSync(path21.join(latestScriptsDir, file), "utf-8");
|
|
25171
25233
|
lines.push(`### \`${file}\` \u{1F512}`);
|
|
25172
25234
|
lines.push("```javascript");
|
|
25173
25235
|
lines.push(content);
|
|
@@ -25208,11 +25270,11 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
|
|
|
25208
25270
|
lines.push("");
|
|
25209
25271
|
}
|
|
25210
25272
|
}
|
|
25211
|
-
const docsDir =
|
|
25273
|
+
const docsDir = path21.join(providerDir, "../../docs");
|
|
25212
25274
|
const loadGuide = (name) => {
|
|
25213
25275
|
try {
|
|
25214
|
-
const p =
|
|
25215
|
-
if (
|
|
25276
|
+
const p = path21.join(docsDir, name);
|
|
25277
|
+
if (fs14.existsSync(p)) return fs14.readFileSync(p, "utf-8");
|
|
25216
25278
|
} catch {
|
|
25217
25279
|
}
|
|
25218
25280
|
return null;
|
|
@@ -25448,7 +25510,7 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
|
|
|
25448
25510
|
parseApproval: "parse_approval.js"
|
|
25449
25511
|
};
|
|
25450
25512
|
const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
|
|
25451
|
-
const scriptsDir =
|
|
25513
|
+
const scriptsDir = path21.join(providerDir, "scripts");
|
|
25452
25514
|
const latestScriptsDir = getLatestScriptVersionDir(scriptsDir);
|
|
25453
25515
|
if (latestScriptsDir) {
|
|
25454
25516
|
lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
|
|
@@ -25456,11 +25518,11 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
|
|
|
25456
25518
|
lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
|
|
25457
25519
|
lines.push("These are the ONLY files you are allowed to modify. Replace TODO or heuristic-only logic with working PTY-aware implementations.");
|
|
25458
25520
|
lines.push("");
|
|
25459
|
-
for (const file of
|
|
25521
|
+
for (const file of fs14.readdirSync(latestScriptsDir)) {
|
|
25460
25522
|
if (!file.endsWith(".js")) continue;
|
|
25461
25523
|
if (!targetFileNames.has(file)) continue;
|
|
25462
25524
|
try {
|
|
25463
|
-
const content =
|
|
25525
|
+
const content = fs14.readFileSync(path21.join(latestScriptsDir, file), "utf-8");
|
|
25464
25526
|
lines.push(`### \`${file}\` \u270F\uFE0F EDIT`);
|
|
25465
25527
|
lines.push("```javascript");
|
|
25466
25528
|
lines.push(content);
|
|
@@ -25469,14 +25531,14 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
|
|
|
25469
25531
|
} catch {
|
|
25470
25532
|
}
|
|
25471
25533
|
}
|
|
25472
|
-
const refFiles =
|
|
25534
|
+
const refFiles = fs14.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
|
|
25473
25535
|
if (refFiles.length > 0) {
|
|
25474
25536
|
lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
|
|
25475
25537
|
lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
|
|
25476
25538
|
lines.push("");
|
|
25477
25539
|
for (const file of refFiles) {
|
|
25478
25540
|
try {
|
|
25479
|
-
const content =
|
|
25541
|
+
const content = fs14.readFileSync(path21.join(latestScriptsDir, file), "utf-8");
|
|
25480
25542
|
lines.push(`### \`${file}\` \u{1F512}`);
|
|
25481
25543
|
lines.push("```javascript");
|
|
25482
25544
|
lines.push(content);
|
|
@@ -25509,11 +25571,11 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
|
|
|
25509
25571
|
lines.push("");
|
|
25510
25572
|
}
|
|
25511
25573
|
}
|
|
25512
|
-
const docsDir =
|
|
25574
|
+
const docsDir = path21.join(providerDir, "../../docs");
|
|
25513
25575
|
const loadGuide = (name) => {
|
|
25514
25576
|
try {
|
|
25515
|
-
const p =
|
|
25516
|
-
if (
|
|
25577
|
+
const p = path21.join(docsDir, name);
|
|
25578
|
+
if (fs14.existsSync(p)) return fs14.readFileSync(p, "utf-8");
|
|
25517
25579
|
} catch {
|
|
25518
25580
|
}
|
|
25519
25581
|
return null;
|
|
@@ -25959,8 +26021,8 @@ var DevServer = class _DevServer {
|
|
|
25959
26021
|
}
|
|
25960
26022
|
getEndpointList() {
|
|
25961
26023
|
return this.routes.map((r) => {
|
|
25962
|
-
const
|
|
25963
|
-
return `${r.method.padEnd(5)} ${
|
|
26024
|
+
const path23 = typeof r.pattern === "string" ? r.pattern : r.pattern.source.replace(/\\\//g, "/").replace(/\(\[.*?\]\+\)/g, ":type").replace(/[\^$]/g, "");
|
|
26025
|
+
return `${r.method.padEnd(5)} ${path23}`;
|
|
25964
26026
|
});
|
|
25965
26027
|
}
|
|
25966
26028
|
async start(port = DEV_SERVER_PORT) {
|
|
@@ -26248,12 +26310,12 @@ var DevServer = class _DevServer {
|
|
|
26248
26310
|
// ─── DevConsole SPA ───
|
|
26249
26311
|
getConsoleDistDir() {
|
|
26250
26312
|
const candidates = [
|
|
26251
|
-
|
|
26252
|
-
|
|
26253
|
-
|
|
26313
|
+
path22.resolve(__dirname, "../../web-devconsole/dist"),
|
|
26314
|
+
path22.resolve(__dirname, "../../../web-devconsole/dist"),
|
|
26315
|
+
path22.join(process.cwd(), "packages/web-devconsole/dist")
|
|
26254
26316
|
];
|
|
26255
26317
|
for (const dir of candidates) {
|
|
26256
|
-
if (
|
|
26318
|
+
if (fs15.existsSync(path22.join(dir, "index.html"))) return dir;
|
|
26257
26319
|
}
|
|
26258
26320
|
return null;
|
|
26259
26321
|
}
|
|
@@ -26263,9 +26325,9 @@ var DevServer = class _DevServer {
|
|
|
26263
26325
|
this.json(res, 500, { error: "DevConsole not found. Run: npm run build -w packages/web-devconsole" });
|
|
26264
26326
|
return;
|
|
26265
26327
|
}
|
|
26266
|
-
const htmlPath =
|
|
26328
|
+
const htmlPath = path22.join(distDir, "index.html");
|
|
26267
26329
|
try {
|
|
26268
|
-
const html =
|
|
26330
|
+
const html = fs15.readFileSync(htmlPath, "utf-8");
|
|
26269
26331
|
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
26270
26332
|
res.end(html);
|
|
26271
26333
|
} catch (e) {
|
|
@@ -26288,15 +26350,15 @@ var DevServer = class _DevServer {
|
|
|
26288
26350
|
this.json(res, 404, { error: "Not found" });
|
|
26289
26351
|
return;
|
|
26290
26352
|
}
|
|
26291
|
-
const safePath =
|
|
26292
|
-
const filePath =
|
|
26353
|
+
const safePath = path22.normalize(pathname).replace(/^\.\.\//, "");
|
|
26354
|
+
const filePath = path22.join(distDir, safePath);
|
|
26293
26355
|
if (!filePath.startsWith(distDir)) {
|
|
26294
26356
|
this.json(res, 403, { error: "Forbidden" });
|
|
26295
26357
|
return;
|
|
26296
26358
|
}
|
|
26297
26359
|
try {
|
|
26298
|
-
const content =
|
|
26299
|
-
const ext =
|
|
26360
|
+
const content = fs15.readFileSync(filePath);
|
|
26361
|
+
const ext = path22.extname(filePath);
|
|
26300
26362
|
const contentType = _DevServer.MIME_MAP[ext] || "application/octet-stream";
|
|
26301
26363
|
res.writeHead(200, { "Content-Type": contentType, "Cache-Control": "public, max-age=31536000, immutable" });
|
|
26302
26364
|
res.end(content);
|
|
@@ -26404,14 +26466,14 @@ var DevServer = class _DevServer {
|
|
|
26404
26466
|
const files = [];
|
|
26405
26467
|
const scan = (d, prefix) => {
|
|
26406
26468
|
try {
|
|
26407
|
-
for (const entry of
|
|
26469
|
+
for (const entry of fs15.readdirSync(d, { withFileTypes: true })) {
|
|
26408
26470
|
if (entry.name.startsWith(".") || entry.name.endsWith(".bak")) continue;
|
|
26409
26471
|
const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
26410
26472
|
if (entry.isDirectory()) {
|
|
26411
26473
|
files.push({ path: rel, size: 0, type: "dir" });
|
|
26412
|
-
scan(
|
|
26474
|
+
scan(path22.join(d, entry.name), rel);
|
|
26413
26475
|
} else {
|
|
26414
|
-
const stat =
|
|
26476
|
+
const stat = fs15.statSync(path22.join(d, entry.name));
|
|
26415
26477
|
files.push({ path: rel, size: stat.size, type: "file" });
|
|
26416
26478
|
}
|
|
26417
26479
|
}
|
|
@@ -26434,16 +26496,16 @@ var DevServer = class _DevServer {
|
|
|
26434
26496
|
this.json(res, 404, { error: `Provider directory not found: ${type}` });
|
|
26435
26497
|
return;
|
|
26436
26498
|
}
|
|
26437
|
-
const fullPath =
|
|
26499
|
+
const fullPath = path22.resolve(dir, path22.normalize(filePath));
|
|
26438
26500
|
if (!fullPath.startsWith(dir)) {
|
|
26439
26501
|
this.json(res, 403, { error: "Forbidden" });
|
|
26440
26502
|
return;
|
|
26441
26503
|
}
|
|
26442
|
-
if (!
|
|
26504
|
+
if (!fs15.existsSync(fullPath) || fs15.statSync(fullPath).isDirectory()) {
|
|
26443
26505
|
this.json(res, 404, { error: `File not found: ${filePath}` });
|
|
26444
26506
|
return;
|
|
26445
26507
|
}
|
|
26446
|
-
const content =
|
|
26508
|
+
const content = fs15.readFileSync(fullPath, "utf-8");
|
|
26447
26509
|
this.json(res, 200, { type, path: filePath, content, lines: content.split("\n").length });
|
|
26448
26510
|
}
|
|
26449
26511
|
/** POST /api/providers/:type/file — write a file { path, content } */
|
|
@@ -26459,15 +26521,15 @@ var DevServer = class _DevServer {
|
|
|
26459
26521
|
this.json(res, 404, { error: `Provider directory not found: ${type}` });
|
|
26460
26522
|
return;
|
|
26461
26523
|
}
|
|
26462
|
-
const fullPath =
|
|
26524
|
+
const fullPath = path22.resolve(dir, path22.normalize(filePath));
|
|
26463
26525
|
if (!fullPath.startsWith(dir)) {
|
|
26464
26526
|
this.json(res, 403, { error: "Forbidden" });
|
|
26465
26527
|
return;
|
|
26466
26528
|
}
|
|
26467
26529
|
try {
|
|
26468
|
-
if (
|
|
26469
|
-
|
|
26470
|
-
|
|
26530
|
+
if (fs15.existsSync(fullPath)) fs15.copyFileSync(fullPath, fullPath + ".bak");
|
|
26531
|
+
fs15.mkdirSync(path22.dirname(fullPath), { recursive: true });
|
|
26532
|
+
fs15.writeFileSync(fullPath, content, "utf-8");
|
|
26471
26533
|
this.log(`File saved: ${fullPath} (${content.length} chars)`);
|
|
26472
26534
|
this.providerLoader.reload();
|
|
26473
26535
|
this.json(res, 200, { saved: true, path: filePath, chars: content.length });
|
|
@@ -26483,9 +26545,9 @@ var DevServer = class _DevServer {
|
|
|
26483
26545
|
return;
|
|
26484
26546
|
}
|
|
26485
26547
|
for (const name of ["scripts.js", "provider.json"]) {
|
|
26486
|
-
const p =
|
|
26487
|
-
if (
|
|
26488
|
-
const source =
|
|
26548
|
+
const p = path22.join(dir, name);
|
|
26549
|
+
if (fs15.existsSync(p)) {
|
|
26550
|
+
const source = fs15.readFileSync(p, "utf-8");
|
|
26489
26551
|
this.json(res, 200, { type, path: p, source, lines: source.split("\n").length });
|
|
26490
26552
|
return;
|
|
26491
26553
|
}
|
|
@@ -26504,11 +26566,11 @@ var DevServer = class _DevServer {
|
|
|
26504
26566
|
this.json(res, 404, { error: `Provider not found: ${type}` });
|
|
26505
26567
|
return;
|
|
26506
26568
|
}
|
|
26507
|
-
const target =
|
|
26508
|
-
const targetPath =
|
|
26569
|
+
const target = fs15.existsSync(path22.join(dir, "scripts.js")) ? "scripts.js" : "provider.json";
|
|
26570
|
+
const targetPath = path22.join(dir, target);
|
|
26509
26571
|
try {
|
|
26510
|
-
if (
|
|
26511
|
-
|
|
26572
|
+
if (fs15.existsSync(targetPath)) fs15.copyFileSync(targetPath, targetPath + ".bak");
|
|
26573
|
+
fs15.writeFileSync(targetPath, source, "utf-8");
|
|
26512
26574
|
this.log(`Saved provider: ${targetPath} (${source.length} chars)`);
|
|
26513
26575
|
this.providerLoader.reload();
|
|
26514
26576
|
this.json(res, 200, { saved: true, path: targetPath, chars: source.length });
|
|
@@ -26652,21 +26714,21 @@ var DevServer = class _DevServer {
|
|
|
26652
26714
|
}
|
|
26653
26715
|
let targetDir;
|
|
26654
26716
|
targetDir = this.providerLoader.getUserProviderDir(category, type);
|
|
26655
|
-
const jsonPath =
|
|
26656
|
-
if (
|
|
26717
|
+
const jsonPath = path22.join(targetDir, "provider.json");
|
|
26718
|
+
if (fs15.existsSync(jsonPath)) {
|
|
26657
26719
|
this.json(res, 409, { error: `Provider already exists at ${targetDir}`, path: targetDir });
|
|
26658
26720
|
return;
|
|
26659
26721
|
}
|
|
26660
26722
|
try {
|
|
26661
26723
|
const result = generateFiles(type, name, category, { cdpPorts, cli, processName, installPath, binary, extensionId, version, osPaths, processNames });
|
|
26662
|
-
|
|
26663
|
-
|
|
26724
|
+
fs15.mkdirSync(targetDir, { recursive: true });
|
|
26725
|
+
fs15.writeFileSync(jsonPath, result["provider.json"], "utf-8");
|
|
26664
26726
|
const createdFiles = ["provider.json"];
|
|
26665
26727
|
if (result.files) {
|
|
26666
26728
|
for (const [relPath, content] of Object.entries(result.files)) {
|
|
26667
|
-
const fullPath =
|
|
26668
|
-
|
|
26669
|
-
|
|
26729
|
+
const fullPath = path22.join(targetDir, relPath);
|
|
26730
|
+
fs15.mkdirSync(path22.dirname(fullPath), { recursive: true });
|
|
26731
|
+
fs15.writeFileSync(fullPath, content, "utf-8");
|
|
26670
26732
|
createdFiles.push(relPath);
|
|
26671
26733
|
}
|
|
26672
26734
|
}
|
|
@@ -26715,38 +26777,38 @@ var DevServer = class _DevServer {
|
|
|
26715
26777
|
}
|
|
26716
26778
|
// ─── Phase 2: Auto-Implement Backend ───
|
|
26717
26779
|
getLatestScriptVersionDir(scriptsDir) {
|
|
26718
|
-
if (!
|
|
26719
|
-
const versions =
|
|
26780
|
+
if (!fs15.existsSync(scriptsDir)) return null;
|
|
26781
|
+
const versions = fs15.readdirSync(scriptsDir).filter((d) => {
|
|
26720
26782
|
try {
|
|
26721
|
-
return
|
|
26783
|
+
return fs15.statSync(path22.join(scriptsDir, d)).isDirectory();
|
|
26722
26784
|
} catch {
|
|
26723
26785
|
return false;
|
|
26724
26786
|
}
|
|
26725
26787
|
}).sort((a, b) => b.localeCompare(a, void 0, { numeric: true, sensitivity: "base" }));
|
|
26726
26788
|
if (versions.length === 0) return null;
|
|
26727
|
-
return
|
|
26789
|
+
return path22.join(scriptsDir, versions[0]);
|
|
26728
26790
|
}
|
|
26729
26791
|
resolveAutoImplWritableProviderDir(category, type, requestedDir) {
|
|
26730
|
-
const canonicalUserDir =
|
|
26731
|
-
const desiredDir = requestedDir ?
|
|
26732
|
-
const upstreamRoot =
|
|
26733
|
-
if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${
|
|
26792
|
+
const canonicalUserDir = path22.resolve(this.providerLoader.getUserProviderDir(category, type));
|
|
26793
|
+
const desiredDir = requestedDir ? path22.resolve(requestedDir) : canonicalUserDir;
|
|
26794
|
+
const upstreamRoot = path22.resolve(this.providerLoader.getUpstreamDir());
|
|
26795
|
+
if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${path22.sep}`)) {
|
|
26734
26796
|
return { dir: null, reason: `Refusing to write into upstream provider directory: ${desiredDir}` };
|
|
26735
26797
|
}
|
|
26736
|
-
if (
|
|
26798
|
+
if (path22.basename(desiredDir) !== type) {
|
|
26737
26799
|
return { dir: null, reason: `Requested writable provider directory must end with '${type}': ${desiredDir}` };
|
|
26738
26800
|
}
|
|
26739
26801
|
const sourceDir = this.findProviderDir(type);
|
|
26740
26802
|
if (!sourceDir) {
|
|
26741
26803
|
return { dir: null, reason: `Provider source directory not found for '${type}'` };
|
|
26742
26804
|
}
|
|
26743
|
-
if (!
|
|
26744
|
-
|
|
26745
|
-
|
|
26805
|
+
if (!fs15.existsSync(desiredDir)) {
|
|
26806
|
+
fs15.mkdirSync(path22.dirname(desiredDir), { recursive: true });
|
|
26807
|
+
fs15.cpSync(sourceDir, desiredDir, { recursive: true });
|
|
26746
26808
|
this.log(`Auto-implement writable copy created: ${desiredDir}`);
|
|
26747
26809
|
}
|
|
26748
|
-
const providerJson =
|
|
26749
|
-
if (!
|
|
26810
|
+
const providerJson = path22.join(desiredDir, "provider.json");
|
|
26811
|
+
if (!fs15.existsSync(providerJson)) {
|
|
26750
26812
|
return { dir: null, reason: `provider.json not found in writable provider directory: ${desiredDir}` };
|
|
26751
26813
|
}
|
|
26752
26814
|
return { dir: desiredDir };
|
|
@@ -26781,7 +26843,7 @@ var DevServer = class _DevServer {
|
|
|
26781
26843
|
setMode: "set_mode.js"
|
|
26782
26844
|
};
|
|
26783
26845
|
const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
|
|
26784
|
-
const scriptsDir =
|
|
26846
|
+
const scriptsDir = path22.join(providerDir, "scripts");
|
|
26785
26847
|
const latestScriptsDir = this.getLatestScriptVersionDir(scriptsDir);
|
|
26786
26848
|
if (latestScriptsDir) {
|
|
26787
26849
|
lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
|
|
@@ -26789,10 +26851,10 @@ var DevServer = class _DevServer {
|
|
|
26789
26851
|
lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
|
|
26790
26852
|
lines.push("These are the ONLY files you are allowed to modify. Replace the TODO stubs with working implementations.");
|
|
26791
26853
|
lines.push("");
|
|
26792
|
-
for (const file of
|
|
26854
|
+
for (const file of fs15.readdirSync(latestScriptsDir)) {
|
|
26793
26855
|
if (file.endsWith(".js") && targetFileNames.has(file)) {
|
|
26794
26856
|
try {
|
|
26795
|
-
const content =
|
|
26857
|
+
const content = fs15.readFileSync(path22.join(latestScriptsDir, file), "utf-8");
|
|
26796
26858
|
lines.push(`### \`${file}\` \u270F\uFE0F EDIT`);
|
|
26797
26859
|
lines.push("```javascript");
|
|
26798
26860
|
lines.push(content);
|
|
@@ -26802,14 +26864,14 @@ var DevServer = class _DevServer {
|
|
|
26802
26864
|
}
|
|
26803
26865
|
}
|
|
26804
26866
|
}
|
|
26805
|
-
const refFiles =
|
|
26867
|
+
const refFiles = fs15.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
|
|
26806
26868
|
if (refFiles.length > 0) {
|
|
26807
26869
|
lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
|
|
26808
26870
|
lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
|
|
26809
26871
|
lines.push("");
|
|
26810
26872
|
for (const file of refFiles) {
|
|
26811
26873
|
try {
|
|
26812
|
-
const content =
|
|
26874
|
+
const content = fs15.readFileSync(path22.join(latestScriptsDir, file), "utf-8");
|
|
26813
26875
|
lines.push(`### \`${file}\` \u{1F512}`);
|
|
26814
26876
|
lines.push("```javascript");
|
|
26815
26877
|
lines.push(content);
|
|
@@ -26850,11 +26912,11 @@ var DevServer = class _DevServer {
|
|
|
26850
26912
|
lines.push("");
|
|
26851
26913
|
}
|
|
26852
26914
|
}
|
|
26853
|
-
const docsDir =
|
|
26915
|
+
const docsDir = path22.join(providerDir, "../../docs");
|
|
26854
26916
|
const loadGuide = (name) => {
|
|
26855
26917
|
try {
|
|
26856
|
-
const p =
|
|
26857
|
-
if (
|
|
26918
|
+
const p = path22.join(docsDir, name);
|
|
26919
|
+
if (fs15.existsSync(p)) return fs15.readFileSync(p, "utf-8");
|
|
26858
26920
|
} catch {
|
|
26859
26921
|
}
|
|
26860
26922
|
return null;
|
|
@@ -27027,7 +27089,7 @@ var DevServer = class _DevServer {
|
|
|
27027
27089
|
parseApproval: "parse_approval.js"
|
|
27028
27090
|
};
|
|
27029
27091
|
const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
|
|
27030
|
-
const scriptsDir =
|
|
27092
|
+
const scriptsDir = path22.join(providerDir, "scripts");
|
|
27031
27093
|
const latestScriptsDir = this.getLatestScriptVersionDir(scriptsDir);
|
|
27032
27094
|
if (latestScriptsDir) {
|
|
27033
27095
|
lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
|
|
@@ -27035,11 +27097,11 @@ var DevServer = class _DevServer {
|
|
|
27035
27097
|
lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
|
|
27036
27098
|
lines.push("These are the ONLY files you are allowed to modify. Replace TODO or heuristic-only logic with working PTY-aware implementations.");
|
|
27037
27099
|
lines.push("");
|
|
27038
|
-
for (const file of
|
|
27100
|
+
for (const file of fs15.readdirSync(latestScriptsDir)) {
|
|
27039
27101
|
if (!file.endsWith(".js")) continue;
|
|
27040
27102
|
if (!targetFileNames.has(file)) continue;
|
|
27041
27103
|
try {
|
|
27042
|
-
const content =
|
|
27104
|
+
const content = fs15.readFileSync(path22.join(latestScriptsDir, file), "utf-8");
|
|
27043
27105
|
lines.push(`### \`${file}\` \u270F\uFE0F EDIT`);
|
|
27044
27106
|
lines.push("```javascript");
|
|
27045
27107
|
lines.push(content);
|
|
@@ -27048,14 +27110,14 @@ var DevServer = class _DevServer {
|
|
|
27048
27110
|
} catch {
|
|
27049
27111
|
}
|
|
27050
27112
|
}
|
|
27051
|
-
const refFiles =
|
|
27113
|
+
const refFiles = fs15.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
|
|
27052
27114
|
if (refFiles.length > 0) {
|
|
27053
27115
|
lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
|
|
27054
27116
|
lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
|
|
27055
27117
|
lines.push("");
|
|
27056
27118
|
for (const file of refFiles) {
|
|
27057
27119
|
try {
|
|
27058
|
-
const content =
|
|
27120
|
+
const content = fs15.readFileSync(path22.join(latestScriptsDir, file), "utf-8");
|
|
27059
27121
|
lines.push(`### \`${file}\` \u{1F512}`);
|
|
27060
27122
|
lines.push("```javascript");
|
|
27061
27123
|
lines.push(content);
|
|
@@ -27088,11 +27150,11 @@ var DevServer = class _DevServer {
|
|
|
27088
27150
|
lines.push("");
|
|
27089
27151
|
}
|
|
27090
27152
|
}
|
|
27091
|
-
const docsDir =
|
|
27153
|
+
const docsDir = path22.join(providerDir, "../../docs");
|
|
27092
27154
|
const loadGuide = (name) => {
|
|
27093
27155
|
try {
|
|
27094
|
-
const p =
|
|
27095
|
-
if (
|
|
27156
|
+
const p = path22.join(docsDir, name);
|
|
27157
|
+
if (fs15.existsSync(p)) return fs15.readFileSync(p, "utf-8");
|
|
27096
27158
|
} catch {
|
|
27097
27159
|
}
|
|
27098
27160
|
return null;
|
|
@@ -27967,8 +28029,8 @@ async function installExtension(ide, extension) {
|
|
|
27967
28029
|
const res = await fetch(extension.vsixUrl);
|
|
27968
28030
|
if (res.ok) {
|
|
27969
28031
|
const buffer = Buffer.from(await res.arrayBuffer());
|
|
27970
|
-
const
|
|
27971
|
-
|
|
28032
|
+
const fs16 = await import("fs");
|
|
28033
|
+
fs16.writeFileSync(vsixPath, buffer);
|
|
27972
28034
|
return new Promise((resolve12) => {
|
|
27973
28035
|
const cmd = `"${ide.cliCommand}" --install-extension "${vsixPath}" --force`;
|
|
27974
28036
|
(0, import_child_process11.exec)(cmd, { timeout: 6e4 }, (error, _stdout, stderr) => {
|