@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.mjs
CHANGED
|
@@ -1328,7 +1328,7 @@ var init_spawn_env = __esm({
|
|
|
1328
1328
|
});
|
|
1329
1329
|
|
|
1330
1330
|
// src/cli-adapters/pty-transport.ts
|
|
1331
|
-
import * as
|
|
1331
|
+
import * as os8 from "os";
|
|
1332
1332
|
function loadNodePty() {
|
|
1333
1333
|
if (cachedPty !== void 0) return cachedPty;
|
|
1334
1334
|
try {
|
|
@@ -1379,11 +1379,11 @@ var init_pty_transport = __esm({
|
|
|
1379
1379
|
let cwd = options.cwd;
|
|
1380
1380
|
if (cwd) {
|
|
1381
1381
|
try {
|
|
1382
|
-
const
|
|
1383
|
-
const stat =
|
|
1384
|
-
if (!stat.isDirectory()) cwd =
|
|
1382
|
+
const fs16 = __require("fs");
|
|
1383
|
+
const stat = fs16.statSync(cwd);
|
|
1384
|
+
if (!stat.isDirectory()) cwd = os8.homedir();
|
|
1385
1385
|
} catch {
|
|
1386
|
-
cwd =
|
|
1386
|
+
cwd = os8.homedir();
|
|
1387
1387
|
}
|
|
1388
1388
|
}
|
|
1389
1389
|
const handle = pty.spawn(command, args, {
|
|
@@ -1400,8 +1400,8 @@ var init_pty_transport = __esm({
|
|
|
1400
1400
|
});
|
|
1401
1401
|
|
|
1402
1402
|
// src/cli-adapters/provider-cli-shared.ts
|
|
1403
|
-
import * as
|
|
1404
|
-
import * as
|
|
1403
|
+
import * as os9 from "os";
|
|
1404
|
+
import * as path10 from "path";
|
|
1405
1405
|
import { execSync as execSync3 } from "child_process";
|
|
1406
1406
|
function stripAnsi(str) {
|
|
1407
1407
|
return str.replace(/\x1B\][^\x07]*\x07/g, "").replace(/\x1B\][\s\S]*?\x1B\\/g, "").replace(/\x1B[P^_X][\s\S]*?(?:\x07|\x1B\\)/g, "").replace(/\x1B\[\d*[A-HJKSTfG]/g, " ").replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g, "").replace(/ +/g, " ");
|
|
@@ -1466,11 +1466,11 @@ function buildCliScreenSnapshot(text) {
|
|
|
1466
1466
|
function findBinary(name) {
|
|
1467
1467
|
const trimmed = String(name || "").trim();
|
|
1468
1468
|
if (!trimmed) return trimmed;
|
|
1469
|
-
const expanded = trimmed.startsWith("~") ?
|
|
1470
|
-
if (
|
|
1471
|
-
return
|
|
1469
|
+
const expanded = trimmed.startsWith("~") ? path10.join(os9.homedir(), trimmed.slice(1)) : trimmed;
|
|
1470
|
+
if (path10.isAbsolute(expanded) || expanded.includes("/") || expanded.includes("\\")) {
|
|
1471
|
+
return path10.isAbsolute(expanded) ? expanded : path10.resolve(expanded);
|
|
1472
1472
|
}
|
|
1473
|
-
const isWin =
|
|
1473
|
+
const isWin = os9.platform() === "win32";
|
|
1474
1474
|
try {
|
|
1475
1475
|
const cmd = isWin ? `where ${trimmed}` : `which ${trimmed}`;
|
|
1476
1476
|
return execSync3(cmd, {
|
|
@@ -1484,14 +1484,14 @@ function findBinary(name) {
|
|
|
1484
1484
|
}
|
|
1485
1485
|
}
|
|
1486
1486
|
function isScriptBinary(binaryPath) {
|
|
1487
|
-
if (!
|
|
1487
|
+
if (!path10.isAbsolute(binaryPath)) return false;
|
|
1488
1488
|
try {
|
|
1489
|
-
const
|
|
1490
|
-
const resolved =
|
|
1489
|
+
const fs16 = __require("fs");
|
|
1490
|
+
const resolved = fs16.realpathSync(binaryPath);
|
|
1491
1491
|
const head = Buffer.alloc(8);
|
|
1492
|
-
const fd =
|
|
1493
|
-
|
|
1494
|
-
|
|
1492
|
+
const fd = fs16.openSync(resolved, "r");
|
|
1493
|
+
fs16.readSync(fd, head, 0, 8, 0);
|
|
1494
|
+
fs16.closeSync(fd);
|
|
1495
1495
|
let i = 0;
|
|
1496
1496
|
if (head[0] === 239 && head[1] === 187 && head[2] === 191) i = 3;
|
|
1497
1497
|
return head[i] === 35 && head[i + 1] === 33;
|
|
@@ -1500,14 +1500,14 @@ function isScriptBinary(binaryPath) {
|
|
|
1500
1500
|
}
|
|
1501
1501
|
}
|
|
1502
1502
|
function looksLikeMachOOrElf(filePath) {
|
|
1503
|
-
if (!
|
|
1503
|
+
if (!path10.isAbsolute(filePath)) return false;
|
|
1504
1504
|
try {
|
|
1505
|
-
const
|
|
1506
|
-
const resolved =
|
|
1505
|
+
const fs16 = __require("fs");
|
|
1506
|
+
const resolved = fs16.realpathSync(filePath);
|
|
1507
1507
|
const buf = Buffer.alloc(8);
|
|
1508
|
-
const fd =
|
|
1509
|
-
|
|
1510
|
-
|
|
1508
|
+
const fd = fs16.openSync(resolved, "r");
|
|
1509
|
+
fs16.readSync(fd, buf, 0, 8, 0);
|
|
1510
|
+
fs16.closeSync(fd);
|
|
1511
1511
|
let i = 0;
|
|
1512
1512
|
if (buf[0] === 239 && buf[1] === 187 && buf[2] === 191) i = 3;
|
|
1513
1513
|
const b = buf.subarray(i);
|
|
@@ -1523,7 +1523,7 @@ function looksLikeMachOOrElf(filePath) {
|
|
|
1523
1523
|
}
|
|
1524
1524
|
function shSingleQuote(arg) {
|
|
1525
1525
|
if (/^[a-zA-Z0-9@%_+=:,./-]+$/.test(arg)) return arg;
|
|
1526
|
-
if (
|
|
1526
|
+
if (os9.platform() === "win32") {
|
|
1527
1527
|
return `"${arg.replace(/"/g, '""')}"`;
|
|
1528
1528
|
}
|
|
1529
1529
|
return `'${arg.replace(/'/g, `'\\''`)}'`;
|
|
@@ -1960,21 +1960,21 @@ var init_provider_cli_config = __esm({
|
|
|
1960
1960
|
});
|
|
1961
1961
|
|
|
1962
1962
|
// src/cli-adapters/provider-cli-runtime.ts
|
|
1963
|
-
import * as
|
|
1964
|
-
import * as
|
|
1963
|
+
import * as os10 from "os";
|
|
1964
|
+
import * as path11 from "path";
|
|
1965
1965
|
import { DEFAULT_SESSION_HOST_COLS, DEFAULT_SESSION_HOST_ROWS } from "@adhdev/session-host-core";
|
|
1966
1966
|
function resolveCliSpawnPlan(options) {
|
|
1967
1967
|
const { provider, runtimeSettings, workingDir, extraArgs } = options;
|
|
1968
1968
|
const { spawn: spawnConfig } = provider;
|
|
1969
1969
|
const configuredCommand = typeof runtimeSettings.executablePath === "string" && runtimeSettings.executablePath.trim() ? runtimeSettings.executablePath.trim() : spawnConfig.command;
|
|
1970
1970
|
const binaryPath = findBinary(configuredCommand);
|
|
1971
|
-
const isWin =
|
|
1971
|
+
const isWin = os10.platform() === "win32";
|
|
1972
1972
|
const allArgs = [...spawnConfig.args, ...extraArgs];
|
|
1973
1973
|
let shellCmd;
|
|
1974
1974
|
let shellArgs;
|
|
1975
|
-
const useShellUnix = !isWin && (!!spawnConfig.shell || !
|
|
1975
|
+
const useShellUnix = !isWin && (!!spawnConfig.shell || !path11.isAbsolute(binaryPath) || isScriptBinary(binaryPath) || !looksLikeMachOOrElf(binaryPath));
|
|
1976
1976
|
const isCmdShim = isWin && /\.(cmd|bat)$/i.test(binaryPath);
|
|
1977
|
-
const useShellWin = !!spawnConfig.shell || isCmdShim || !
|
|
1977
|
+
const useShellWin = !!spawnConfig.shell || isCmdShim || !path11.isAbsolute(binaryPath) || isScriptBinary(binaryPath);
|
|
1978
1978
|
const useShell = isWin ? useShellWin : useShellUnix;
|
|
1979
1979
|
if (useShell) {
|
|
1980
1980
|
shellCmd = isWin ? "cmd.exe" : process.env.SHELL || "/bin/zsh";
|
|
@@ -2066,7 +2066,7 @@ __export(provider_cli_adapter_exports, {
|
|
|
2066
2066
|
sanitizeCliStandardMessageContent: () => sanitizeCliStandardMessageContent,
|
|
2067
2067
|
trimLastAssistantEchoForCliMessages: () => trimLastAssistantEchoForCliMessages
|
|
2068
2068
|
});
|
|
2069
|
-
import * as
|
|
2069
|
+
import * as os11 from "os";
|
|
2070
2070
|
function normalizeComparableTranscriptText(value) {
|
|
2071
2071
|
return sanitizeTerminalText(String(value || "")).replace(/\s+/g, " ").trim();
|
|
2072
2072
|
}
|
|
@@ -2197,7 +2197,7 @@ var init_provider_cli_adapter = __esm({
|
|
|
2197
2197
|
this.transportFactory = transportFactory;
|
|
2198
2198
|
this.cliType = provider.type;
|
|
2199
2199
|
this.cliName = provider.name;
|
|
2200
|
-
this.workingDir = workingDir.startsWith("~") ? workingDir.replace(/^~/,
|
|
2200
|
+
this.workingDir = workingDir.startsWith("~") ? workingDir.replace(/^~/, os11.homedir()) : workingDir;
|
|
2201
2201
|
const resolvedConfig = resolveCliAdapterConfig(provider);
|
|
2202
2202
|
this.timeouts = resolvedConfig.timeouts;
|
|
2203
2203
|
this.approvalKeys = resolvedConfig.approvalKeys;
|
|
@@ -5120,17 +5120,17 @@ function checkPathExists(paths) {
|
|
|
5120
5120
|
return null;
|
|
5121
5121
|
}
|
|
5122
5122
|
async function detectIDEs(providerLoader) {
|
|
5123
|
-
const
|
|
5123
|
+
const os21 = platform();
|
|
5124
5124
|
const results = [];
|
|
5125
5125
|
for (const def of getMergedDefinitions()) {
|
|
5126
5126
|
const cliPath = findCliCommand(providerLoader?.getIdeCliCommand(def.id, def.cli) || def.cli);
|
|
5127
|
-
const appPath = checkPathExists(providerLoader?.getIdePathCandidates(def.id, def.paths[
|
|
5127
|
+
const appPath = checkPathExists(providerLoader?.getIdePathCandidates(def.id, def.paths[os21] || []) || []);
|
|
5128
5128
|
let resolvedCli = cliPath;
|
|
5129
|
-
if (!resolvedCli && appPath &&
|
|
5129
|
+
if (!resolvedCli && appPath && os21 === "darwin") {
|
|
5130
5130
|
const bundledCli = `${appPath}/Contents/Resources/app/bin/${def.cli}`;
|
|
5131
5131
|
if (existsSync4(bundledCli)) resolvedCli = bundledCli;
|
|
5132
5132
|
}
|
|
5133
|
-
if (!resolvedCli && appPath &&
|
|
5133
|
+
if (!resolvedCli && appPath && os21 === "win32") {
|
|
5134
5134
|
const { dirname: dirname7 } = await import("path");
|
|
5135
5135
|
const appDir = dirname7(appPath);
|
|
5136
5136
|
const candidates = [
|
|
@@ -5147,7 +5147,7 @@ async function detectIDEs(providerLoader) {
|
|
|
5147
5147
|
}
|
|
5148
5148
|
}
|
|
5149
5149
|
}
|
|
5150
|
-
const installed =
|
|
5150
|
+
const installed = os21 === "darwin" ? !!(resolvedCli || appPath) : !!resolvedCli;
|
|
5151
5151
|
const version = resolvedCli ? getIdeVersion(resolvedCli) : null;
|
|
5152
5152
|
results.push({
|
|
5153
5153
|
id: def.id,
|
|
@@ -10312,6 +10312,10 @@ function resolveLegacyProviderScript(fn, scriptName, params) {
|
|
|
10312
10312
|
|
|
10313
10313
|
// src/commands/chat-commands.ts
|
|
10314
10314
|
init_contracts();
|
|
10315
|
+
import * as fs4 from "fs";
|
|
10316
|
+
import * as os6 from "os";
|
|
10317
|
+
import * as path8 from "path";
|
|
10318
|
+
import { randomUUID as randomUUID4 } from "crypto";
|
|
10315
10319
|
|
|
10316
10320
|
// src/providers/provider-input-support.ts
|
|
10317
10321
|
var VALID_INPUT_MEDIA_TYPES = /* @__PURE__ */ new Set(["text", "image", "audio", "video", "resource"]);
|
|
@@ -11000,6 +11004,50 @@ function buildDebugBundleText(bundle) {
|
|
|
11000
11004
|
"```"
|
|
11001
11005
|
].join("\n");
|
|
11002
11006
|
}
|
|
11007
|
+
function getChatDebugBundleDir() {
|
|
11008
|
+
const override = typeof process.env.ADHDEV_DEBUG_BUNDLE_DIR === "string" ? process.env.ADHDEV_DEBUG_BUNDLE_DIR.trim() : "";
|
|
11009
|
+
return override || path8.join(os6.homedir(), ".adhdev", "debug-bundles", "chat");
|
|
11010
|
+
}
|
|
11011
|
+
function safeBundleIdSegment(value, fallback) {
|
|
11012
|
+
const normalized = String(value || fallback).trim().replace(/[^A-Za-z0-9_.-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 80);
|
|
11013
|
+
return normalized || fallback;
|
|
11014
|
+
}
|
|
11015
|
+
function createChatDebugBundleId(targetSessionId) {
|
|
11016
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[-:.]/g, "").replace("T", "T").replace("Z", "Z");
|
|
11017
|
+
const sessionSegment = safeBundleIdSegment(targetSessionId, "unknown-session");
|
|
11018
|
+
return `chat-debug-${timestamp}-${sessionSegment}-${randomUUID4().slice(0, 8)}`;
|
|
11019
|
+
}
|
|
11020
|
+
function buildChatDebugBundleSummary(bundle) {
|
|
11021
|
+
const target = bundle.target && typeof bundle.target === "object" ? bundle.target : {};
|
|
11022
|
+
const readChat = bundle.readChat && typeof bundle.readChat === "object" ? bundle.readChat : {};
|
|
11023
|
+
const cli = bundle.cli && typeof bundle.cli === "object" ? bundle.cli : null;
|
|
11024
|
+
const frontend = bundle.frontend && typeof bundle.frontend === "object" ? bundle.frontend : null;
|
|
11025
|
+
return {
|
|
11026
|
+
createdAt: bundle.createdAt,
|
|
11027
|
+
targetSessionId: target.targetSessionId,
|
|
11028
|
+
providerType: target.providerType,
|
|
11029
|
+
transport: target.transport,
|
|
11030
|
+
readChatSuccess: readChat.success,
|
|
11031
|
+
readChatStatus: readChat.status,
|
|
11032
|
+
readChatTotalMessages: readChat.totalMessages,
|
|
11033
|
+
cliStatus: cli?.status,
|
|
11034
|
+
cliMessageCount: cli?.messageCount,
|
|
11035
|
+
hasFrontendSnapshot: !!frontend
|
|
11036
|
+
};
|
|
11037
|
+
}
|
|
11038
|
+
function storeChatDebugBundleOnDaemon(bundle, targetSessionId) {
|
|
11039
|
+
const bundleId = createChatDebugBundleId(targetSessionId);
|
|
11040
|
+
const dir = getChatDebugBundleDir();
|
|
11041
|
+
fs4.mkdirSync(dir, { recursive: true });
|
|
11042
|
+
const savedPath = path8.join(dir, `${bundleId}.json`);
|
|
11043
|
+
const json = `${JSON.stringify(bundle, null, 2)}
|
|
11044
|
+
`;
|
|
11045
|
+
fs4.writeFileSync(savedPath, json, { encoding: "utf8", mode: 384 });
|
|
11046
|
+
return { bundleId, savedPath, sizeBytes: Buffer.byteLength(json, "utf8") };
|
|
11047
|
+
}
|
|
11048
|
+
function isDaemonFileDebugDelivery(args) {
|
|
11049
|
+
return args?.delivery === "daemon_file" || args?.delivery === "file";
|
|
11050
|
+
}
|
|
11003
11051
|
async function handleGetChatDebugBundle(h, args) {
|
|
11004
11052
|
const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
|
|
11005
11053
|
if (!targetSessionId && !h.currentSession) {
|
|
@@ -11111,6 +11159,20 @@ async function handleGetChatDebugBundle(h, args) {
|
|
|
11111
11159
|
recentDebugTrace: getRecentDebugTrace({ limit: 120 })
|
|
11112
11160
|
};
|
|
11113
11161
|
const bundle = sanitizeDebugBundleValue(rawBundle);
|
|
11162
|
+
if (isDaemonFileDebugDelivery(args)) {
|
|
11163
|
+
const summary = buildChatDebugBundleSummary(bundle);
|
|
11164
|
+
const stored = storeChatDebugBundleOnDaemon(bundle, targetSessionId || String(summary.targetSessionId || "unknown-session"));
|
|
11165
|
+
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 || ""}`);
|
|
11166
|
+
return {
|
|
11167
|
+
success: true,
|
|
11168
|
+
delivery: "daemon_file",
|
|
11169
|
+
bundleId: stored.bundleId,
|
|
11170
|
+
savedPath: stored.savedPath,
|
|
11171
|
+
sizeBytes: stored.sizeBytes,
|
|
11172
|
+
createdAt: bundle.createdAt,
|
|
11173
|
+
summary
|
|
11174
|
+
};
|
|
11175
|
+
}
|
|
11114
11176
|
return {
|
|
11115
11177
|
success: true,
|
|
11116
11178
|
bundle,
|
|
@@ -12092,9 +12154,9 @@ async function handleResolveAction(h, args) {
|
|
|
12092
12154
|
}
|
|
12093
12155
|
|
|
12094
12156
|
// src/commands/cdp-commands.ts
|
|
12095
|
-
import * as
|
|
12096
|
-
import * as
|
|
12097
|
-
import * as
|
|
12157
|
+
import * as fs5 from "fs";
|
|
12158
|
+
import * as path9 from "path";
|
|
12159
|
+
import * as os7 from "os";
|
|
12098
12160
|
var KEY_TO_VK = {
|
|
12099
12161
|
Backspace: 8,
|
|
12100
12162
|
Tab: 9,
|
|
@@ -12348,27 +12410,27 @@ function normalizeWindowsRequestedPath(requestedPath) {
|
|
|
12348
12410
|
function resolveSafePath(requestedPath) {
|
|
12349
12411
|
const rawPath = typeof requestedPath === "string" ? requestedPath.trim() : "";
|
|
12350
12412
|
const inputPath = rawPath || ".";
|
|
12351
|
-
const home =
|
|
12413
|
+
const home = os7.homedir();
|
|
12352
12414
|
if (inputPath.startsWith("~")) {
|
|
12353
|
-
return
|
|
12415
|
+
return path9.resolve(path9.join(home, inputPath.slice(1)));
|
|
12354
12416
|
}
|
|
12355
12417
|
if (process.platform === "win32") {
|
|
12356
12418
|
const normalized = normalizeWindowsRequestedPath(inputPath);
|
|
12357
|
-
if (
|
|
12358
|
-
return
|
|
12419
|
+
if (path9.win32.isAbsolute(normalized)) {
|
|
12420
|
+
return path9.win32.normalize(normalized);
|
|
12359
12421
|
}
|
|
12360
|
-
return
|
|
12422
|
+
return path9.win32.resolve(normalized);
|
|
12361
12423
|
}
|
|
12362
|
-
if (
|
|
12363
|
-
return
|
|
12424
|
+
if (path9.isAbsolute(inputPath)) {
|
|
12425
|
+
return path9.normalize(inputPath);
|
|
12364
12426
|
}
|
|
12365
|
-
return
|
|
12427
|
+
return path9.resolve(inputPath);
|
|
12366
12428
|
}
|
|
12367
12429
|
function listDirectoryEntriesSafe(dirPath) {
|
|
12368
|
-
const entries =
|
|
12430
|
+
const entries = fs5.readdirSync(dirPath, { withFileTypes: true });
|
|
12369
12431
|
const files = [];
|
|
12370
12432
|
for (const entry of entries) {
|
|
12371
|
-
const entryPath =
|
|
12433
|
+
const entryPath = path9.join(dirPath, entry.name);
|
|
12372
12434
|
try {
|
|
12373
12435
|
if (entry.isDirectory()) {
|
|
12374
12436
|
files.push({ name: entry.name, type: "directory" });
|
|
@@ -12377,14 +12439,14 @@ function listDirectoryEntriesSafe(dirPath) {
|
|
|
12377
12439
|
if (entry.isFile()) {
|
|
12378
12440
|
let size;
|
|
12379
12441
|
try {
|
|
12380
|
-
size =
|
|
12442
|
+
size = fs5.statSync(entryPath).size;
|
|
12381
12443
|
} catch {
|
|
12382
12444
|
size = void 0;
|
|
12383
12445
|
}
|
|
12384
12446
|
files.push({ name: entry.name, type: "file", size });
|
|
12385
12447
|
continue;
|
|
12386
12448
|
}
|
|
12387
|
-
const stat =
|
|
12449
|
+
const stat = fs5.statSync(entryPath);
|
|
12388
12450
|
files.push({
|
|
12389
12451
|
name: entry.name,
|
|
12390
12452
|
type: stat.isDirectory() ? "directory" : "file",
|
|
@@ -12402,7 +12464,7 @@ function listWindowsDriveEntries(excludePath) {
|
|
|
12402
12464
|
const letter = String.fromCharCode(code);
|
|
12403
12465
|
const root = `${letter}:\\`;
|
|
12404
12466
|
try {
|
|
12405
|
-
if (!
|
|
12467
|
+
if (!fs5.existsSync(root)) continue;
|
|
12406
12468
|
if (excluded && root.toLowerCase() === excluded) continue;
|
|
12407
12469
|
drives.push({ name: `${letter}:`, type: "directory", path: root });
|
|
12408
12470
|
} catch {
|
|
@@ -12413,7 +12475,7 @@ function listWindowsDriveEntries(excludePath) {
|
|
|
12413
12475
|
async function handleFileRead(h, args) {
|
|
12414
12476
|
try {
|
|
12415
12477
|
const filePath = resolveSafePath(args?.path);
|
|
12416
|
-
const content =
|
|
12478
|
+
const content = fs5.readFileSync(filePath, "utf-8");
|
|
12417
12479
|
return { success: true, content, path: filePath };
|
|
12418
12480
|
} catch (e) {
|
|
12419
12481
|
return { success: false, error: e.message };
|
|
@@ -12422,8 +12484,8 @@ async function handleFileRead(h, args) {
|
|
|
12422
12484
|
async function handleFileWrite(h, args) {
|
|
12423
12485
|
try {
|
|
12424
12486
|
const filePath = resolveSafePath(args?.path);
|
|
12425
|
-
|
|
12426
|
-
|
|
12487
|
+
fs5.mkdirSync(path9.dirname(filePath), { recursive: true });
|
|
12488
|
+
fs5.writeFileSync(filePath, args?.content || "", "utf-8");
|
|
12427
12489
|
return { success: true, path: filePath };
|
|
12428
12490
|
} catch (e) {
|
|
12429
12491
|
return { success: false, error: e.message };
|
|
@@ -13525,8 +13587,8 @@ var DaemonCommandHandler = class {
|
|
|
13525
13587
|
|
|
13526
13588
|
// src/commands/cli-manager.ts
|
|
13527
13589
|
init_provider_cli_adapter();
|
|
13528
|
-
import * as
|
|
13529
|
-
import * as
|
|
13590
|
+
import * as os13 from "os";
|
|
13591
|
+
import * as path13 from "path";
|
|
13530
13592
|
import * as crypto4 from "crypto";
|
|
13531
13593
|
import { existsSync as existsSync10 } from "fs";
|
|
13532
13594
|
import { execFileSync } from "child_process";
|
|
@@ -13535,10 +13597,10 @@ init_config();
|
|
|
13535
13597
|
|
|
13536
13598
|
// src/providers/cli-provider-instance.ts
|
|
13537
13599
|
init_contracts();
|
|
13538
|
-
import * as
|
|
13539
|
-
import * as
|
|
13600
|
+
import * as os12 from "os";
|
|
13601
|
+
import * as path12 from "path";
|
|
13540
13602
|
import * as crypto3 from "crypto";
|
|
13541
|
-
import * as
|
|
13603
|
+
import * as fs6 from "fs";
|
|
13542
13604
|
import { createRequire } from "module";
|
|
13543
13605
|
init_provider_cli_adapter();
|
|
13544
13606
|
init_logger();
|
|
@@ -13596,7 +13658,7 @@ function buildIncrementalHistoryAppendMessages(previousMessages, currentMessages
|
|
|
13596
13658
|
var CachedDatabaseSync = null;
|
|
13597
13659
|
function getDatabaseSync() {
|
|
13598
13660
|
if (CachedDatabaseSync) return CachedDatabaseSync;
|
|
13599
|
-
const requireFn = typeof __require === "function" ? __require : createRequire(
|
|
13661
|
+
const requireFn = typeof __require === "function" ? __require : createRequire(path12.join(process.cwd(), "__adhdev_sqlite_loader__.js"));
|
|
13600
13662
|
const sqliteModule = requireFn(`node:${"sqlite"}`);
|
|
13601
13663
|
CachedDatabaseSync = sqliteModule.DatabaseSync;
|
|
13602
13664
|
if (!CachedDatabaseSync) {
|
|
@@ -13746,10 +13808,10 @@ var CliProviderInstance = class {
|
|
|
13746
13808
|
* Replaces the previously duplicated probeOpenCode/Codex/Goose functions.
|
|
13747
13809
|
*/
|
|
13748
13810
|
probeSessionIdFromConfig(probe) {
|
|
13749
|
-
const resolvedDbPath = probe.dbPath.replace(/^~/,
|
|
13811
|
+
const resolvedDbPath = probe.dbPath.replace(/^~/, os12.homedir());
|
|
13750
13812
|
const now = Date.now();
|
|
13751
13813
|
if (this.cachedSqliteDbMissingUntil > now) return null;
|
|
13752
|
-
if (!
|
|
13814
|
+
if (!fs6.existsSync(resolvedDbPath)) {
|
|
13753
13815
|
this.cachedSqliteDbMissingUntil = now + 1e4;
|
|
13754
13816
|
return null;
|
|
13755
13817
|
}
|
|
@@ -14481,7 +14543,7 @@ ${effect.notification.body || ""}`.trim();
|
|
|
14481
14543
|
};
|
|
14482
14544
|
addDir(this.workingDir);
|
|
14483
14545
|
try {
|
|
14484
|
-
addDir(
|
|
14546
|
+
addDir(fs6.realpathSync.native(this.workingDir));
|
|
14485
14547
|
} catch {
|
|
14486
14548
|
}
|
|
14487
14549
|
return Array.from(dirs);
|
|
@@ -15685,11 +15747,11 @@ function shouldRestoreHostedRuntime(record, managerTag) {
|
|
|
15685
15747
|
// src/commands/cli-manager.ts
|
|
15686
15748
|
function isExplicitCommand(command) {
|
|
15687
15749
|
const trimmed = command.trim();
|
|
15688
|
-
return
|
|
15750
|
+
return path13.isAbsolute(trimmed) || trimmed.includes("/") || trimmed.includes("\\") || trimmed.startsWith("~");
|
|
15689
15751
|
}
|
|
15690
15752
|
function expandExecutable(command) {
|
|
15691
15753
|
const trimmed = command.trim();
|
|
15692
|
-
return trimmed.startsWith("~") ?
|
|
15754
|
+
return trimmed.startsWith("~") ? path13.join(os13.homedir(), trimmed.slice(1)) : trimmed;
|
|
15693
15755
|
}
|
|
15694
15756
|
function commandExists(command) {
|
|
15695
15757
|
const trimmed = command.trim();
|
|
@@ -15970,7 +16032,7 @@ var DaemonCliManager = class {
|
|
|
15970
16032
|
async startSession(cliType, workingDir, cliArgs, initialModel, options) {
|
|
15971
16033
|
const trimmed = (workingDir || "").trim();
|
|
15972
16034
|
if (!trimmed) throw new Error("working directory required");
|
|
15973
|
-
const resolvedDir = trimmed.startsWith("~") ? trimmed.replace(/^~/,
|
|
16035
|
+
const resolvedDir = trimmed.startsWith("~") ? trimmed.replace(/^~/, os13.homedir()) : path13.resolve(trimmed);
|
|
15974
16036
|
const normalizedType = this.providerLoader.resolveAlias(cliType);
|
|
15975
16037
|
const rawProvider = this.providerLoader.getByAlias(cliType);
|
|
15976
16038
|
const provider = rawProvider ? this.providerLoader.resolve(normalizedType) || rawProvider : void 0;
|
|
@@ -16470,13 +16532,13 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
16470
16532
|
// src/launch.ts
|
|
16471
16533
|
import { execSync as execSync4, spawn as spawn2 } from "child_process";
|
|
16472
16534
|
import * as net from "net";
|
|
16473
|
-
import * as
|
|
16474
|
-
import * as
|
|
16535
|
+
import * as os15 from "os";
|
|
16536
|
+
import * as path15 from "path";
|
|
16475
16537
|
|
|
16476
16538
|
// src/providers/provider-loader.ts
|
|
16477
|
-
import * as
|
|
16478
|
-
import * as
|
|
16479
|
-
import * as
|
|
16539
|
+
import * as fs7 from "fs";
|
|
16540
|
+
import * as path14 from "path";
|
|
16541
|
+
import * as os14 from "os";
|
|
16480
16542
|
import * as chokidar from "chokidar";
|
|
16481
16543
|
init_logger();
|
|
16482
16544
|
|
|
@@ -16738,9 +16800,9 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
16738
16800
|
static siblingStderrLogged = /* @__PURE__ */ new Set();
|
|
16739
16801
|
static looksLikeProviderRoot(candidate) {
|
|
16740
16802
|
try {
|
|
16741
|
-
if (!
|
|
16803
|
+
if (!fs7.existsSync(candidate) || !fs7.statSync(candidate).isDirectory()) return false;
|
|
16742
16804
|
return ["ide", "extension", "cli", "acp"].some(
|
|
16743
|
-
(category) =>
|
|
16805
|
+
(category) => fs7.existsSync(path14.join(candidate, category))
|
|
16744
16806
|
);
|
|
16745
16807
|
} catch {
|
|
16746
16808
|
return false;
|
|
@@ -16748,20 +16810,20 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
16748
16810
|
}
|
|
16749
16811
|
static hasProviderRootMarker(candidate) {
|
|
16750
16812
|
try {
|
|
16751
|
-
return
|
|
16813
|
+
return fs7.existsSync(path14.join(candidate, _ProviderLoader.SIBLING_MARKER_FILE));
|
|
16752
16814
|
} catch {
|
|
16753
16815
|
return false;
|
|
16754
16816
|
}
|
|
16755
16817
|
}
|
|
16756
16818
|
detectDefaultUserDir() {
|
|
16757
|
-
const fallback =
|
|
16819
|
+
const fallback = path14.join(os14.homedir(), ".adhdev", "providers");
|
|
16758
16820
|
const envOptIn = process.env[_ProviderLoader.SIBLING_ENV_VAR] === "1";
|
|
16759
16821
|
const visited = /* @__PURE__ */ new Set();
|
|
16760
16822
|
for (const start of this.probeStarts) {
|
|
16761
|
-
let current =
|
|
16823
|
+
let current = path14.resolve(start);
|
|
16762
16824
|
while (!visited.has(current)) {
|
|
16763
16825
|
visited.add(current);
|
|
16764
|
-
const siblingCandidate =
|
|
16826
|
+
const siblingCandidate = path14.join(path14.dirname(current), _ProviderLoader.REPO_PROVIDER_DIRNAME);
|
|
16765
16827
|
if (_ProviderLoader.looksLikeProviderRoot(siblingCandidate)) {
|
|
16766
16828
|
const hasMarker = _ProviderLoader.hasProviderRootMarker(siblingCandidate);
|
|
16767
16829
|
if (envOptIn || hasMarker) {
|
|
@@ -16783,7 +16845,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
16783
16845
|
return { path: siblingCandidate, source };
|
|
16784
16846
|
}
|
|
16785
16847
|
}
|
|
16786
|
-
const parent =
|
|
16848
|
+
const parent = path14.dirname(current);
|
|
16787
16849
|
if (parent === current) break;
|
|
16788
16850
|
current = parent;
|
|
16789
16851
|
}
|
|
@@ -16793,11 +16855,11 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
16793
16855
|
constructor(options) {
|
|
16794
16856
|
this.logFn = options?.logFn || LOG.forComponent("Provider").asLogFn();
|
|
16795
16857
|
this.probeStarts = options?.probeStarts ?? [process.cwd(), __dirname];
|
|
16796
|
-
this.defaultProvidersDir =
|
|
16858
|
+
this.defaultProvidersDir = path14.join(os14.homedir(), ".adhdev", "providers");
|
|
16797
16859
|
const detected = this.detectDefaultUserDir();
|
|
16798
16860
|
this.userDir = detected.path;
|
|
16799
16861
|
this.userDirSource = detected.source;
|
|
16800
|
-
this.upstreamDir =
|
|
16862
|
+
this.upstreamDir = path14.join(this.defaultProvidersDir, ".upstream");
|
|
16801
16863
|
this.disableUpstream = false;
|
|
16802
16864
|
this.applySourceConfig({
|
|
16803
16865
|
userDir: options?.userDir,
|
|
@@ -16856,7 +16918,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
16856
16918
|
this.userDir = detected.path;
|
|
16857
16919
|
this.userDirSource = detected.source;
|
|
16858
16920
|
}
|
|
16859
|
-
this.upstreamDir =
|
|
16921
|
+
this.upstreamDir = path14.join(this.defaultProvidersDir, ".upstream");
|
|
16860
16922
|
this.disableUpstream = this.sourceMode === "no-upstream";
|
|
16861
16923
|
if (this.explicitProviderDir) {
|
|
16862
16924
|
this.log(`Config 'providerDir' applied: ${this.userDir}`);
|
|
@@ -16870,7 +16932,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
16870
16932
|
* Canonical provider directory shape for a given root.
|
|
16871
16933
|
*/
|
|
16872
16934
|
getProviderDir(root, category, type) {
|
|
16873
|
-
return
|
|
16935
|
+
return path14.join(root, category, type);
|
|
16874
16936
|
}
|
|
16875
16937
|
/**
|
|
16876
16938
|
* Canonical user override directory for a provider.
|
|
@@ -16897,7 +16959,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
16897
16959
|
resolveProviderFile(type, ...segments) {
|
|
16898
16960
|
const dir = this.findProviderDirInternal(type);
|
|
16899
16961
|
if (!dir) return null;
|
|
16900
|
-
return
|
|
16962
|
+
return path14.join(dir, ...segments);
|
|
16901
16963
|
}
|
|
16902
16964
|
/**
|
|
16903
16965
|
* Load all providers (3-tier priority)
|
|
@@ -16910,7 +16972,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
16910
16972
|
this.providers.clear();
|
|
16911
16973
|
this.providerAvailability.clear();
|
|
16912
16974
|
let upstreamCount = 0;
|
|
16913
|
-
if (!this.disableUpstream &&
|
|
16975
|
+
if (!this.disableUpstream && fs7.existsSync(this.upstreamDir)) {
|
|
16914
16976
|
upstreamCount = this.loadDir(this.upstreamDir);
|
|
16915
16977
|
if (upstreamCount > 0) {
|
|
16916
16978
|
this.log(`Loaded ${upstreamCount} upstream providers (auto-updated)`);
|
|
@@ -16918,7 +16980,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
16918
16980
|
} else if (this.disableUpstream) {
|
|
16919
16981
|
this.log("Upstream loading disabled (sourceMode=no-upstream)");
|
|
16920
16982
|
}
|
|
16921
|
-
if (
|
|
16983
|
+
if (fs7.existsSync(this.userDir)) {
|
|
16922
16984
|
const userCount = this.loadDir(this.userDir, [".upstream"]);
|
|
16923
16985
|
if (userCount > 0) {
|
|
16924
16986
|
this.log(`Loaded ${userCount} user custom providers (never auto-updated)`);
|
|
@@ -16933,10 +16995,10 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
16933
16995
|
* Check if upstream directory exists and has providers.
|
|
16934
16996
|
*/
|
|
16935
16997
|
hasUpstream() {
|
|
16936
|
-
if (!
|
|
16998
|
+
if (!fs7.existsSync(this.upstreamDir)) return false;
|
|
16937
16999
|
try {
|
|
16938
|
-
return
|
|
16939
|
-
(d) =>
|
|
17000
|
+
return fs7.readdirSync(this.upstreamDir).some(
|
|
17001
|
+
(d) => fs7.statSync(path14.join(this.upstreamDir, d)).isDirectory()
|
|
16940
17002
|
);
|
|
16941
17003
|
} catch {
|
|
16942
17004
|
return false;
|
|
@@ -17433,8 +17495,8 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17433
17495
|
resolved._resolvedScriptDir = entry.scriptDir;
|
|
17434
17496
|
resolved._resolvedScriptsSource = `compatibility:${entry.ideVersion}`;
|
|
17435
17497
|
if (providerDir) {
|
|
17436
|
-
const fullDir =
|
|
17437
|
-
resolved._resolvedScriptsPath =
|
|
17498
|
+
const fullDir = path14.join(providerDir, entry.scriptDir);
|
|
17499
|
+
resolved._resolvedScriptsPath = fs7.existsSync(path14.join(fullDir, "scripts.js")) ? path14.join(fullDir, "scripts.js") : fullDir;
|
|
17438
17500
|
}
|
|
17439
17501
|
matched = true;
|
|
17440
17502
|
}
|
|
@@ -17449,8 +17511,8 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17449
17511
|
resolved._resolvedScriptDir = base.defaultScriptDir;
|
|
17450
17512
|
resolved._resolvedScriptsSource = "defaultScriptDir:version_miss";
|
|
17451
17513
|
if (providerDir) {
|
|
17452
|
-
const fullDir =
|
|
17453
|
-
resolved._resolvedScriptsPath =
|
|
17514
|
+
const fullDir = path14.join(providerDir, base.defaultScriptDir);
|
|
17515
|
+
resolved._resolvedScriptsPath = fs7.existsSync(path14.join(fullDir, "scripts.js")) ? path14.join(fullDir, "scripts.js") : fullDir;
|
|
17454
17516
|
}
|
|
17455
17517
|
}
|
|
17456
17518
|
resolved._versionWarning = `Version ${currentVersion} not in compatibility matrix. Using default scripts.`;
|
|
@@ -17467,8 +17529,8 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17467
17529
|
resolved._resolvedScriptDir = dirOverride;
|
|
17468
17530
|
resolved._resolvedScriptsSource = `versions:${range}`;
|
|
17469
17531
|
if (providerDir) {
|
|
17470
|
-
const fullDir =
|
|
17471
|
-
resolved._resolvedScriptsPath =
|
|
17532
|
+
const fullDir = path14.join(providerDir, dirOverride);
|
|
17533
|
+
resolved._resolvedScriptsPath = fs7.existsSync(path14.join(fullDir, "scripts.js")) ? path14.join(fullDir, "scripts.js") : fullDir;
|
|
17472
17534
|
}
|
|
17473
17535
|
}
|
|
17474
17536
|
} else if (override.scripts) {
|
|
@@ -17484,8 +17546,8 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17484
17546
|
resolved._resolvedScriptDir = base.defaultScriptDir;
|
|
17485
17547
|
resolved._resolvedScriptsSource = "defaultScriptDir:no_version";
|
|
17486
17548
|
if (providerDir) {
|
|
17487
|
-
const fullDir =
|
|
17488
|
-
resolved._resolvedScriptsPath =
|
|
17549
|
+
const fullDir = path14.join(providerDir, base.defaultScriptDir);
|
|
17550
|
+
resolved._resolvedScriptsPath = fs7.existsSync(path14.join(fullDir, "scripts.js")) ? path14.join(fullDir, "scripts.js") : fullDir;
|
|
17489
17551
|
}
|
|
17490
17552
|
}
|
|
17491
17553
|
}
|
|
@@ -17517,15 +17579,15 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17517
17579
|
this.log(` [loadScriptsFromDir] ${type}: providerDir not found`);
|
|
17518
17580
|
return null;
|
|
17519
17581
|
}
|
|
17520
|
-
const dir =
|
|
17521
|
-
if (!
|
|
17582
|
+
const dir = path14.join(providerDir, scriptDir);
|
|
17583
|
+
if (!fs7.existsSync(dir)) {
|
|
17522
17584
|
this.log(` [loadScriptsFromDir] ${type}: dir not found: ${dir}`);
|
|
17523
17585
|
return null;
|
|
17524
17586
|
}
|
|
17525
17587
|
const cached = this.scriptsCache.get(dir);
|
|
17526
17588
|
if (cached) return cached;
|
|
17527
|
-
const scriptsJs =
|
|
17528
|
-
if (
|
|
17589
|
+
const scriptsJs = path14.join(dir, "scripts.js");
|
|
17590
|
+
if (fs7.existsSync(scriptsJs)) {
|
|
17529
17591
|
try {
|
|
17530
17592
|
delete __require.cache[__require.resolve(scriptsJs)];
|
|
17531
17593
|
const loaded = __require(scriptsJs);
|
|
@@ -17546,9 +17608,9 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17546
17608
|
watch() {
|
|
17547
17609
|
this.stopWatch();
|
|
17548
17610
|
const watchDir = (dir) => {
|
|
17549
|
-
if (!
|
|
17611
|
+
if (!fs7.existsSync(dir)) {
|
|
17550
17612
|
try {
|
|
17551
|
-
|
|
17613
|
+
fs7.mkdirSync(dir, { recursive: true });
|
|
17552
17614
|
} catch {
|
|
17553
17615
|
return;
|
|
17554
17616
|
}
|
|
@@ -17566,7 +17628,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17566
17628
|
return;
|
|
17567
17629
|
}
|
|
17568
17630
|
if (filePath.endsWith(".js") || filePath.endsWith(".json")) {
|
|
17569
|
-
this.log(`File changed: ${
|
|
17631
|
+
this.log(`File changed: ${path14.basename(filePath)}, reloading...`);
|
|
17570
17632
|
this.reload();
|
|
17571
17633
|
}
|
|
17572
17634
|
};
|
|
@@ -17621,12 +17683,12 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17621
17683
|
}
|
|
17622
17684
|
const https = __require("https");
|
|
17623
17685
|
const { execSync: execSync7 } = __require("child_process");
|
|
17624
|
-
const metaPath =
|
|
17686
|
+
const metaPath = path14.join(this.upstreamDir, _ProviderLoader.META_FILE);
|
|
17625
17687
|
let prevEtag = "";
|
|
17626
17688
|
let prevTimestamp = 0;
|
|
17627
17689
|
try {
|
|
17628
|
-
if (
|
|
17629
|
-
const meta = JSON.parse(
|
|
17690
|
+
if (fs7.existsSync(metaPath)) {
|
|
17691
|
+
const meta = JSON.parse(fs7.readFileSync(metaPath, "utf-8"));
|
|
17630
17692
|
prevEtag = meta.etag || "";
|
|
17631
17693
|
prevTimestamp = meta.timestamp || 0;
|
|
17632
17694
|
}
|
|
@@ -17681,39 +17743,39 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17681
17743
|
return { updated: false };
|
|
17682
17744
|
}
|
|
17683
17745
|
this.log("Downloading latest providers from GitHub...");
|
|
17684
|
-
const tmpTar =
|
|
17685
|
-
const tmpExtract =
|
|
17746
|
+
const tmpTar = path14.join(os14.tmpdir(), `adhdev-providers-${Date.now()}.tar.gz`);
|
|
17747
|
+
const tmpExtract = path14.join(os14.tmpdir(), `adhdev-providers-extract-${Date.now()}`);
|
|
17686
17748
|
await this.downloadFile(_ProviderLoader.GITHUB_TARBALL_URL, tmpTar);
|
|
17687
|
-
|
|
17749
|
+
fs7.mkdirSync(tmpExtract, { recursive: true });
|
|
17688
17750
|
execSync7(`tar -xzf "${tmpTar}" -C "${tmpExtract}"`, { timeout: 3e4 });
|
|
17689
|
-
const extracted =
|
|
17751
|
+
const extracted = fs7.readdirSync(tmpExtract);
|
|
17690
17752
|
const rootDir = extracted.find(
|
|
17691
|
-
(d) =>
|
|
17753
|
+
(d) => fs7.statSync(path14.join(tmpExtract, d)).isDirectory() && d.startsWith("adhdev-providers")
|
|
17692
17754
|
);
|
|
17693
17755
|
if (!rootDir) throw new Error("Unexpected tarball structure");
|
|
17694
|
-
const sourceDir =
|
|
17756
|
+
const sourceDir = path14.join(tmpExtract, rootDir);
|
|
17695
17757
|
const backupDir = this.upstreamDir + ".bak";
|
|
17696
|
-
if (
|
|
17697
|
-
if (
|
|
17698
|
-
|
|
17758
|
+
if (fs7.existsSync(this.upstreamDir)) {
|
|
17759
|
+
if (fs7.existsSync(backupDir)) fs7.rmSync(backupDir, { recursive: true, force: true });
|
|
17760
|
+
fs7.renameSync(this.upstreamDir, backupDir);
|
|
17699
17761
|
}
|
|
17700
17762
|
try {
|
|
17701
17763
|
this.copyDirRecursive(sourceDir, this.upstreamDir);
|
|
17702
17764
|
this.writeMeta(metaPath, etag || `ts-${Date.now()}`, Date.now());
|
|
17703
|
-
if (
|
|
17765
|
+
if (fs7.existsSync(backupDir)) fs7.rmSync(backupDir, { recursive: true, force: true });
|
|
17704
17766
|
} catch (e) {
|
|
17705
|
-
if (
|
|
17706
|
-
if (
|
|
17707
|
-
|
|
17767
|
+
if (fs7.existsSync(backupDir)) {
|
|
17768
|
+
if (fs7.existsSync(this.upstreamDir)) fs7.rmSync(this.upstreamDir, { recursive: true, force: true });
|
|
17769
|
+
fs7.renameSync(backupDir, this.upstreamDir);
|
|
17708
17770
|
}
|
|
17709
17771
|
throw e;
|
|
17710
17772
|
}
|
|
17711
17773
|
try {
|
|
17712
|
-
|
|
17774
|
+
fs7.rmSync(tmpTar, { force: true });
|
|
17713
17775
|
} catch {
|
|
17714
17776
|
}
|
|
17715
17777
|
try {
|
|
17716
|
-
|
|
17778
|
+
fs7.rmSync(tmpExtract, { recursive: true, force: true });
|
|
17717
17779
|
} catch {
|
|
17718
17780
|
}
|
|
17719
17781
|
const upstreamCount = this.countProviders(this.upstreamDir);
|
|
@@ -17745,7 +17807,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17745
17807
|
reject(new Error(`HTTP ${res.statusCode}`));
|
|
17746
17808
|
return;
|
|
17747
17809
|
}
|
|
17748
|
-
const ws =
|
|
17810
|
+
const ws = fs7.createWriteStream(destPath);
|
|
17749
17811
|
res.pipe(ws);
|
|
17750
17812
|
ws.on("finish", () => {
|
|
17751
17813
|
ws.close();
|
|
@@ -17764,22 +17826,22 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17764
17826
|
}
|
|
17765
17827
|
/** Recursive directory copy */
|
|
17766
17828
|
copyDirRecursive(src, dest) {
|
|
17767
|
-
|
|
17768
|
-
for (const entry of
|
|
17769
|
-
const srcPath =
|
|
17770
|
-
const destPath =
|
|
17829
|
+
fs7.mkdirSync(dest, { recursive: true });
|
|
17830
|
+
for (const entry of fs7.readdirSync(src, { withFileTypes: true })) {
|
|
17831
|
+
const srcPath = path14.join(src, entry.name);
|
|
17832
|
+
const destPath = path14.join(dest, entry.name);
|
|
17771
17833
|
if (entry.isDirectory()) {
|
|
17772
17834
|
this.copyDirRecursive(srcPath, destPath);
|
|
17773
17835
|
} else {
|
|
17774
|
-
|
|
17836
|
+
fs7.copyFileSync(srcPath, destPath);
|
|
17775
17837
|
}
|
|
17776
17838
|
}
|
|
17777
17839
|
}
|
|
17778
17840
|
/** .meta.json save */
|
|
17779
17841
|
writeMeta(metaPath, etag, timestamp) {
|
|
17780
17842
|
try {
|
|
17781
|
-
|
|
17782
|
-
|
|
17843
|
+
fs7.mkdirSync(path14.dirname(metaPath), { recursive: true });
|
|
17844
|
+
fs7.writeFileSync(metaPath, JSON.stringify({
|
|
17783
17845
|
etag,
|
|
17784
17846
|
timestamp,
|
|
17785
17847
|
lastCheck: new Date(timestamp).toISOString(),
|
|
@@ -17790,12 +17852,12 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17790
17852
|
}
|
|
17791
17853
|
/** Count provider files (provider.js or provider.json) */
|
|
17792
17854
|
countProviders(dir) {
|
|
17793
|
-
if (!
|
|
17855
|
+
if (!fs7.existsSync(dir)) return 0;
|
|
17794
17856
|
let count = 0;
|
|
17795
17857
|
const scan = (d) => {
|
|
17796
17858
|
try {
|
|
17797
|
-
for (const entry of
|
|
17798
|
-
if (entry.isDirectory()) scan(
|
|
17859
|
+
for (const entry of fs7.readdirSync(d, { withFileTypes: true })) {
|
|
17860
|
+
if (entry.isDirectory()) scan(path14.join(d, entry.name));
|
|
17799
17861
|
else if (entry.name === "provider.json") count++;
|
|
17800
17862
|
}
|
|
17801
17863
|
} catch {
|
|
@@ -18021,19 +18083,19 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
18021
18083
|
const cat = provider.category;
|
|
18022
18084
|
const searchRoots = this.getProviderRoots();
|
|
18023
18085
|
for (const root of searchRoots) {
|
|
18024
|
-
if (!
|
|
18086
|
+
if (!fs7.existsSync(root)) continue;
|
|
18025
18087
|
const candidate = this.getProviderDir(root, cat, type);
|
|
18026
|
-
if (
|
|
18027
|
-
const catDir =
|
|
18028
|
-
if (
|
|
18088
|
+
if (fs7.existsSync(path14.join(candidate, "provider.json"))) return candidate;
|
|
18089
|
+
const catDir = path14.join(root, cat);
|
|
18090
|
+
if (fs7.existsSync(catDir)) {
|
|
18029
18091
|
try {
|
|
18030
|
-
for (const entry of
|
|
18092
|
+
for (const entry of fs7.readdirSync(catDir, { withFileTypes: true })) {
|
|
18031
18093
|
if (!entry.isDirectory()) continue;
|
|
18032
|
-
const jsonPath =
|
|
18033
|
-
if (
|
|
18094
|
+
const jsonPath = path14.join(catDir, entry.name, "provider.json");
|
|
18095
|
+
if (fs7.existsSync(jsonPath)) {
|
|
18034
18096
|
try {
|
|
18035
|
-
const data = JSON.parse(
|
|
18036
|
-
if (data.type === type) return
|
|
18097
|
+
const data = JSON.parse(fs7.readFileSync(jsonPath, "utf-8"));
|
|
18098
|
+
if (data.type === type) return path14.join(catDir, entry.name);
|
|
18037
18099
|
} catch {
|
|
18038
18100
|
}
|
|
18039
18101
|
}
|
|
@@ -18050,8 +18112,8 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
18050
18112
|
* (template substitution is NOT applied here — scripts.js handles that)
|
|
18051
18113
|
*/
|
|
18052
18114
|
buildScriptWrappersFromDir(dir) {
|
|
18053
|
-
const scriptsJs =
|
|
18054
|
-
if (
|
|
18115
|
+
const scriptsJs = path14.join(dir, "scripts.js");
|
|
18116
|
+
if (fs7.existsSync(scriptsJs)) {
|
|
18055
18117
|
try {
|
|
18056
18118
|
delete __require.cache[__require.resolve(scriptsJs)];
|
|
18057
18119
|
return __require(scriptsJs);
|
|
@@ -18061,13 +18123,13 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
18061
18123
|
const toCamel = (name) => name.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
|
|
18062
18124
|
const result = {};
|
|
18063
18125
|
try {
|
|
18064
|
-
for (const file of
|
|
18126
|
+
for (const file of fs7.readdirSync(dir)) {
|
|
18065
18127
|
if (!file.endsWith(".js")) continue;
|
|
18066
18128
|
const scriptName = toCamel(file.replace(".js", ""));
|
|
18067
|
-
const filePath =
|
|
18129
|
+
const filePath = path14.join(dir, file);
|
|
18068
18130
|
result[scriptName] = (...args) => {
|
|
18069
18131
|
try {
|
|
18070
|
-
let content =
|
|
18132
|
+
let content = fs7.readFileSync(filePath, "utf-8");
|
|
18071
18133
|
if (args[0] && typeof args[0] === "object") {
|
|
18072
18134
|
for (const [key, val] of Object.entries(args[0])) {
|
|
18073
18135
|
let v = val;
|
|
@@ -18113,20 +18175,20 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
18113
18175
|
* Structure: dir/category/agent-name/provider.{json,js}
|
|
18114
18176
|
*/
|
|
18115
18177
|
loadDir(dir, excludeDirs) {
|
|
18116
|
-
if (!
|
|
18178
|
+
if (!fs7.existsSync(dir)) return 0;
|
|
18117
18179
|
let count = 0;
|
|
18118
18180
|
const scan = (d) => {
|
|
18119
18181
|
let entries;
|
|
18120
18182
|
try {
|
|
18121
|
-
entries =
|
|
18183
|
+
entries = fs7.readdirSync(d, { withFileTypes: true });
|
|
18122
18184
|
} catch {
|
|
18123
18185
|
return;
|
|
18124
18186
|
}
|
|
18125
18187
|
const hasJson = entries.some((e) => e.name === "provider.json");
|
|
18126
18188
|
if (hasJson) {
|
|
18127
|
-
const jsonPath =
|
|
18189
|
+
const jsonPath = path14.join(d, "provider.json");
|
|
18128
18190
|
try {
|
|
18129
|
-
const raw =
|
|
18191
|
+
const raw = fs7.readFileSync(jsonPath, "utf-8");
|
|
18130
18192
|
const mod = JSON.parse(raw);
|
|
18131
18193
|
if (typeof mod.extensionIdPattern === "string") {
|
|
18132
18194
|
const flags = mod.extensionIdPattern_flags || "";
|
|
@@ -18145,8 +18207,8 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
18145
18207
|
this.log(`\u26A0 Invalid provider at ${jsonPath}: ${validation.errors.join("; ")}`);
|
|
18146
18208
|
} else {
|
|
18147
18209
|
const hasCompatibility = Array.isArray(normalizedProvider.compatibility);
|
|
18148
|
-
const scriptsPath =
|
|
18149
|
-
if (!hasCompatibility &&
|
|
18210
|
+
const scriptsPath = path14.join(d, "scripts.js");
|
|
18211
|
+
if (!hasCompatibility && fs7.existsSync(scriptsPath)) {
|
|
18150
18212
|
try {
|
|
18151
18213
|
delete __require.cache[__require.resolve(scriptsPath)];
|
|
18152
18214
|
const scripts = __require(scriptsPath);
|
|
@@ -18171,7 +18233,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
18171
18233
|
if (!entry.isDirectory()) continue;
|
|
18172
18234
|
if (entry.name.startsWith("_") || entry.name.startsWith(".")) continue;
|
|
18173
18235
|
if (excludeDirs && d === dir && excludeDirs.includes(entry.name)) continue;
|
|
18174
|
-
scan(
|
|
18236
|
+
scan(path14.join(d, entry.name));
|
|
18175
18237
|
}
|
|
18176
18238
|
}
|
|
18177
18239
|
};
|
|
@@ -18361,7 +18423,7 @@ async function isCdpActive(port) {
|
|
|
18361
18423
|
});
|
|
18362
18424
|
}
|
|
18363
18425
|
async function killIdeProcess(ideId) {
|
|
18364
|
-
const plat =
|
|
18426
|
+
const plat = os15.platform();
|
|
18365
18427
|
const appName = getMacAppIdentifiers()[ideId];
|
|
18366
18428
|
const winProcesses = getWinProcessNames()[ideId];
|
|
18367
18429
|
try {
|
|
@@ -18422,7 +18484,7 @@ async function killIdeProcess(ideId) {
|
|
|
18422
18484
|
}
|
|
18423
18485
|
}
|
|
18424
18486
|
function isIdeRunning(ideId) {
|
|
18425
|
-
const plat =
|
|
18487
|
+
const plat = os15.platform();
|
|
18426
18488
|
try {
|
|
18427
18489
|
if (plat === "darwin") {
|
|
18428
18490
|
const appName = getMacAppIdentifiers()[ideId];
|
|
@@ -18477,7 +18539,7 @@ function isIdeRunning(ideId) {
|
|
|
18477
18539
|
}
|
|
18478
18540
|
}
|
|
18479
18541
|
function detectCurrentWorkspace(ideId) {
|
|
18480
|
-
const plat =
|
|
18542
|
+
const plat = os15.platform();
|
|
18481
18543
|
if (plat === "darwin") {
|
|
18482
18544
|
try {
|
|
18483
18545
|
const appName = getMacAppIdentifiers()[ideId];
|
|
@@ -18492,17 +18554,17 @@ function detectCurrentWorkspace(ideId) {
|
|
|
18492
18554
|
}
|
|
18493
18555
|
} else if (plat === "win32") {
|
|
18494
18556
|
try {
|
|
18495
|
-
const
|
|
18557
|
+
const fs16 = __require("fs");
|
|
18496
18558
|
const appNameMap = getMacAppIdentifiers();
|
|
18497
18559
|
const appName = appNameMap[ideId];
|
|
18498
18560
|
if (appName) {
|
|
18499
|
-
const storagePath =
|
|
18500
|
-
process.env.APPDATA ||
|
|
18561
|
+
const storagePath = path15.join(
|
|
18562
|
+
process.env.APPDATA || path15.join(os15.homedir(), "AppData", "Roaming"),
|
|
18501
18563
|
appName,
|
|
18502
18564
|
"storage.json"
|
|
18503
18565
|
);
|
|
18504
|
-
if (
|
|
18505
|
-
const data = JSON.parse(
|
|
18566
|
+
if (fs16.existsSync(storagePath)) {
|
|
18567
|
+
const data = JSON.parse(fs16.readFileSync(storagePath, "utf-8"));
|
|
18506
18568
|
const workspaces = data?.openedPathsList?.workspaces3 || data?.openedPathsList?.entries || [];
|
|
18507
18569
|
if (workspaces.length > 0) {
|
|
18508
18570
|
const recent = workspaces[0];
|
|
@@ -18519,7 +18581,7 @@ function detectCurrentWorkspace(ideId) {
|
|
|
18519
18581
|
return void 0;
|
|
18520
18582
|
}
|
|
18521
18583
|
async function launchWithCdp(options = {}) {
|
|
18522
|
-
const platform10 =
|
|
18584
|
+
const platform10 = os15.platform();
|
|
18523
18585
|
let targetIde;
|
|
18524
18586
|
const ides = await detectIDEs(getProviderLoader());
|
|
18525
18587
|
if (options.ideId) {
|
|
@@ -18674,14 +18736,14 @@ init_config();
|
|
|
18674
18736
|
init_logger();
|
|
18675
18737
|
|
|
18676
18738
|
// src/logging/command-log.ts
|
|
18677
|
-
import * as
|
|
18678
|
-
import * as
|
|
18679
|
-
import * as
|
|
18680
|
-
var LOG_DIR2 = process.platform === "win32" ?
|
|
18739
|
+
import * as fs8 from "fs";
|
|
18740
|
+
import * as path16 from "path";
|
|
18741
|
+
import * as os16 from "os";
|
|
18742
|
+
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");
|
|
18681
18743
|
var MAX_FILE_SIZE = 5 * 1024 * 1024;
|
|
18682
18744
|
var MAX_DAYS = 7;
|
|
18683
18745
|
try {
|
|
18684
|
-
|
|
18746
|
+
fs8.mkdirSync(LOG_DIR2, { recursive: true });
|
|
18685
18747
|
} catch {
|
|
18686
18748
|
}
|
|
18687
18749
|
var SENSITIVE_KEYS = /* @__PURE__ */ new Set([
|
|
@@ -18715,19 +18777,19 @@ function getDateStr2() {
|
|
|
18715
18777
|
return (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
18716
18778
|
}
|
|
18717
18779
|
var currentDate2 = getDateStr2();
|
|
18718
|
-
var currentFile =
|
|
18780
|
+
var currentFile = path16.join(LOG_DIR2, `commands-${currentDate2}.jsonl`);
|
|
18719
18781
|
var writeCount2 = 0;
|
|
18720
18782
|
function checkRotation() {
|
|
18721
18783
|
const today = getDateStr2();
|
|
18722
18784
|
if (today !== currentDate2) {
|
|
18723
18785
|
currentDate2 = today;
|
|
18724
|
-
currentFile =
|
|
18786
|
+
currentFile = path16.join(LOG_DIR2, `commands-${currentDate2}.jsonl`);
|
|
18725
18787
|
cleanOldFiles();
|
|
18726
18788
|
}
|
|
18727
18789
|
}
|
|
18728
18790
|
function cleanOldFiles() {
|
|
18729
18791
|
try {
|
|
18730
|
-
const files =
|
|
18792
|
+
const files = fs8.readdirSync(LOG_DIR2).filter((f) => f.startsWith("commands-") && f.endsWith(".jsonl"));
|
|
18731
18793
|
const cutoff = /* @__PURE__ */ new Date();
|
|
18732
18794
|
cutoff.setDate(cutoff.getDate() - MAX_DAYS);
|
|
18733
18795
|
const cutoffStr = cutoff.toISOString().slice(0, 10);
|
|
@@ -18735,7 +18797,7 @@ function cleanOldFiles() {
|
|
|
18735
18797
|
const dateMatch = file.match(/commands-(\d{4}-\d{2}-\d{2})/);
|
|
18736
18798
|
if (dateMatch && dateMatch[1] < cutoffStr) {
|
|
18737
18799
|
try {
|
|
18738
|
-
|
|
18800
|
+
fs8.unlinkSync(path16.join(LOG_DIR2, file));
|
|
18739
18801
|
} catch {
|
|
18740
18802
|
}
|
|
18741
18803
|
}
|
|
@@ -18745,14 +18807,14 @@ function cleanOldFiles() {
|
|
|
18745
18807
|
}
|
|
18746
18808
|
function checkSize() {
|
|
18747
18809
|
try {
|
|
18748
|
-
const stat =
|
|
18810
|
+
const stat = fs8.statSync(currentFile);
|
|
18749
18811
|
if (stat.size > MAX_FILE_SIZE) {
|
|
18750
18812
|
const backup = currentFile.replace(".jsonl", ".1.jsonl");
|
|
18751
18813
|
try {
|
|
18752
|
-
|
|
18814
|
+
fs8.unlinkSync(backup);
|
|
18753
18815
|
} catch {
|
|
18754
18816
|
}
|
|
18755
|
-
|
|
18817
|
+
fs8.renameSync(currentFile, backup);
|
|
18756
18818
|
}
|
|
18757
18819
|
} catch {
|
|
18758
18820
|
}
|
|
@@ -18785,14 +18847,14 @@ function logCommand(entry) {
|
|
|
18785
18847
|
...entry.error ? { err: entry.error } : {},
|
|
18786
18848
|
...entry.durationMs !== void 0 ? { ms: entry.durationMs } : {}
|
|
18787
18849
|
});
|
|
18788
|
-
|
|
18850
|
+
fs8.appendFileSync(currentFile, line + "\n");
|
|
18789
18851
|
} catch {
|
|
18790
18852
|
}
|
|
18791
18853
|
}
|
|
18792
18854
|
function getRecentCommands(count = 50) {
|
|
18793
18855
|
try {
|
|
18794
|
-
if (!
|
|
18795
|
-
const content =
|
|
18856
|
+
if (!fs8.existsSync(currentFile)) return [];
|
|
18857
|
+
const content = fs8.readFileSync(currentFile, "utf-8");
|
|
18796
18858
|
const lines = content.trim().split("\n").filter(Boolean);
|
|
18797
18859
|
return lines.slice(-count).map((line) => {
|
|
18798
18860
|
try {
|
|
@@ -18822,7 +18884,7 @@ init_logger();
|
|
|
18822
18884
|
|
|
18823
18885
|
// src/status/snapshot.ts
|
|
18824
18886
|
init_config();
|
|
18825
|
-
import * as
|
|
18887
|
+
import * as os17 from "os";
|
|
18826
18888
|
init_terminal_screen();
|
|
18827
18889
|
init_logger();
|
|
18828
18890
|
var READ_DEBUG_ENABLED = process.argv.includes("--dev") || process.env.ADHDEV_READ_DEBUG === "1";
|
|
@@ -18876,8 +18938,8 @@ function buildAvailableProviders(providerLoader) {
|
|
|
18876
18938
|
}
|
|
18877
18939
|
function buildMachineInfo(profile = "full") {
|
|
18878
18940
|
const base = {
|
|
18879
|
-
hostname:
|
|
18880
|
-
platform:
|
|
18941
|
+
hostname: os17.hostname(),
|
|
18942
|
+
platform: os17.platform()
|
|
18881
18943
|
};
|
|
18882
18944
|
if (profile === "live") {
|
|
18883
18945
|
return base;
|
|
@@ -18886,23 +18948,23 @@ function buildMachineInfo(profile = "full") {
|
|
|
18886
18948
|
const memSnap2 = getHostMemorySnapshot();
|
|
18887
18949
|
return {
|
|
18888
18950
|
...base,
|
|
18889
|
-
arch:
|
|
18890
|
-
cpus:
|
|
18951
|
+
arch: os17.arch(),
|
|
18952
|
+
cpus: os17.cpus().length,
|
|
18891
18953
|
totalMem: memSnap2.totalMem,
|
|
18892
|
-
release:
|
|
18954
|
+
release: os17.release()
|
|
18893
18955
|
};
|
|
18894
18956
|
}
|
|
18895
18957
|
const memSnap = getHostMemorySnapshot();
|
|
18896
18958
|
return {
|
|
18897
18959
|
...base,
|
|
18898
|
-
arch:
|
|
18899
|
-
cpus:
|
|
18960
|
+
arch: os17.arch(),
|
|
18961
|
+
cpus: os17.cpus().length,
|
|
18900
18962
|
totalMem: memSnap.totalMem,
|
|
18901
18963
|
freeMem: memSnap.freeMem,
|
|
18902
18964
|
availableMem: memSnap.availableMem,
|
|
18903
|
-
loadavg:
|
|
18904
|
-
uptime:
|
|
18905
|
-
release:
|
|
18965
|
+
loadavg: os17.loadavg(),
|
|
18966
|
+
uptime: os17.uptime(),
|
|
18967
|
+
release: os17.release()
|
|
18906
18968
|
};
|
|
18907
18969
|
}
|
|
18908
18970
|
function parseMessageTime(value) {
|
|
@@ -19129,42 +19191,42 @@ function buildStatusSnapshot(options) {
|
|
|
19129
19191
|
// src/commands/upgrade-helper.ts
|
|
19130
19192
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
19131
19193
|
import { spawn as spawn3 } from "child_process";
|
|
19132
|
-
import * as
|
|
19133
|
-
import * as
|
|
19134
|
-
import * as
|
|
19194
|
+
import * as fs9 from "fs";
|
|
19195
|
+
import * as os18 from "os";
|
|
19196
|
+
import * as path17 from "path";
|
|
19135
19197
|
var UPGRADE_HELPER_ENV = "ADHDEV_DAEMON_UPGRADE_HELPER";
|
|
19136
19198
|
function getUpgradeLogPath() {
|
|
19137
|
-
const home =
|
|
19138
|
-
const dir =
|
|
19139
|
-
|
|
19140
|
-
return
|
|
19199
|
+
const home = os18.homedir();
|
|
19200
|
+
const dir = path17.join(home, ".adhdev");
|
|
19201
|
+
fs9.mkdirSync(dir, { recursive: true });
|
|
19202
|
+
return path17.join(dir, "daemon-upgrade.log");
|
|
19141
19203
|
}
|
|
19142
19204
|
function appendUpgradeLog(message) {
|
|
19143
19205
|
const line = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${message}
|
|
19144
19206
|
`;
|
|
19145
19207
|
try {
|
|
19146
|
-
|
|
19208
|
+
fs9.appendFileSync(getUpgradeLogPath(), line, "utf8");
|
|
19147
19209
|
} catch {
|
|
19148
19210
|
}
|
|
19149
19211
|
}
|
|
19150
19212
|
function resolveSiblingNpmInvocation(nodeExecutable, platform10 = process.platform) {
|
|
19151
|
-
const binDir =
|
|
19213
|
+
const binDir = path17.dirname(nodeExecutable);
|
|
19152
19214
|
if (platform10 === "win32") {
|
|
19153
|
-
const npmCliPath =
|
|
19154
|
-
if (
|
|
19215
|
+
const npmCliPath = path17.join(binDir, "node_modules", "npm", "bin", "npm-cli.js");
|
|
19216
|
+
if (fs9.existsSync(npmCliPath)) {
|
|
19155
19217
|
return { executable: nodeExecutable, argsPrefix: [npmCliPath], execOptions: getNpmExecOptions(platform10) };
|
|
19156
19218
|
}
|
|
19157
19219
|
for (const candidate of ["npm.exe", "npm"]) {
|
|
19158
|
-
const candidatePath =
|
|
19159
|
-
if (
|
|
19220
|
+
const candidatePath = path17.join(binDir, candidate);
|
|
19221
|
+
if (fs9.existsSync(candidatePath)) {
|
|
19160
19222
|
return { executable: candidatePath, argsPrefix: [], execOptions: getNpmExecOptions(platform10) };
|
|
19161
19223
|
}
|
|
19162
19224
|
}
|
|
19163
19225
|
return { executable: nodeExecutable, argsPrefix: [npmCliPath], execOptions: getNpmExecOptions(platform10) };
|
|
19164
19226
|
}
|
|
19165
19227
|
for (const candidate of ["npm"]) {
|
|
19166
|
-
const candidatePath =
|
|
19167
|
-
if (
|
|
19228
|
+
const candidatePath = path17.join(binDir, candidate);
|
|
19229
|
+
if (fs9.existsSync(candidatePath)) {
|
|
19168
19230
|
return { executable: candidatePath, argsPrefix: [], execOptions: getNpmExecOptions(platform10) };
|
|
19169
19231
|
}
|
|
19170
19232
|
}
|
|
@@ -19174,22 +19236,22 @@ function findCurrentPackageRoot(currentCliPath, packageName) {
|
|
|
19174
19236
|
if (!currentCliPath) return null;
|
|
19175
19237
|
let resolvedPath = currentCliPath;
|
|
19176
19238
|
try {
|
|
19177
|
-
resolvedPath =
|
|
19239
|
+
resolvedPath = fs9.realpathSync.native(currentCliPath);
|
|
19178
19240
|
} catch {
|
|
19179
19241
|
}
|
|
19180
19242
|
let currentDir = resolvedPath;
|
|
19181
19243
|
try {
|
|
19182
|
-
if (
|
|
19183
|
-
currentDir =
|
|
19244
|
+
if (fs9.statSync(resolvedPath).isFile()) {
|
|
19245
|
+
currentDir = path17.dirname(resolvedPath);
|
|
19184
19246
|
}
|
|
19185
19247
|
} catch {
|
|
19186
|
-
currentDir =
|
|
19248
|
+
currentDir = path17.dirname(resolvedPath);
|
|
19187
19249
|
}
|
|
19188
19250
|
while (true) {
|
|
19189
|
-
const packageJsonPath =
|
|
19251
|
+
const packageJsonPath = path17.join(currentDir, "package.json");
|
|
19190
19252
|
try {
|
|
19191
|
-
if (
|
|
19192
|
-
const parsed = JSON.parse(
|
|
19253
|
+
if (fs9.existsSync(packageJsonPath)) {
|
|
19254
|
+
const parsed = JSON.parse(fs9.readFileSync(packageJsonPath, "utf8"));
|
|
19193
19255
|
if (parsed?.name === packageName) {
|
|
19194
19256
|
const normalized = currentDir.replace(/\\/g, "/");
|
|
19195
19257
|
return normalized.includes("/node_modules/") ? currentDir : null;
|
|
@@ -19197,7 +19259,7 @@ function findCurrentPackageRoot(currentCliPath, packageName) {
|
|
|
19197
19259
|
}
|
|
19198
19260
|
} catch {
|
|
19199
19261
|
}
|
|
19200
|
-
const parentDir =
|
|
19262
|
+
const parentDir = path17.dirname(currentDir);
|
|
19201
19263
|
if (parentDir === currentDir) {
|
|
19202
19264
|
return null;
|
|
19203
19265
|
}
|
|
@@ -19205,13 +19267,13 @@ function findCurrentPackageRoot(currentCliPath, packageName) {
|
|
|
19205
19267
|
}
|
|
19206
19268
|
}
|
|
19207
19269
|
function resolveInstallPrefixFromPackageRoot(packageRoot, packageName) {
|
|
19208
|
-
const nodeModulesDir = packageName.startsWith("@") ?
|
|
19209
|
-
if (
|
|
19270
|
+
const nodeModulesDir = packageName.startsWith("@") ? path17.dirname(path17.dirname(packageRoot)) : path17.dirname(packageRoot);
|
|
19271
|
+
if (path17.basename(nodeModulesDir) !== "node_modules") {
|
|
19210
19272
|
return null;
|
|
19211
19273
|
}
|
|
19212
|
-
const maybeLibDir =
|
|
19213
|
-
if (
|
|
19214
|
-
return
|
|
19274
|
+
const maybeLibDir = path17.dirname(nodeModulesDir);
|
|
19275
|
+
if (path17.basename(maybeLibDir) === "lib") {
|
|
19276
|
+
return path17.dirname(maybeLibDir);
|
|
19215
19277
|
}
|
|
19216
19278
|
return maybeLibDir;
|
|
19217
19279
|
}
|
|
@@ -19326,10 +19388,10 @@ async function waitForPidExit(pid, timeoutMs) {
|
|
|
19326
19388
|
}
|
|
19327
19389
|
}
|
|
19328
19390
|
function stopSessionHostProcesses(appName) {
|
|
19329
|
-
const pidFile =
|
|
19391
|
+
const pidFile = path17.join(os18.homedir(), ".adhdev", `${appName}-session-host.pid`);
|
|
19330
19392
|
try {
|
|
19331
|
-
if (
|
|
19332
|
-
const pid = Number.parseInt(
|
|
19393
|
+
if (fs9.existsSync(pidFile)) {
|
|
19394
|
+
const pid = Number.parseInt(fs9.readFileSync(pidFile, "utf8").trim(), 10);
|
|
19333
19395
|
if (Number.isFinite(pid) && pid !== process.pid && isManagedSessionHostPid(pid)) {
|
|
19334
19396
|
killPid(pid);
|
|
19335
19397
|
}
|
|
@@ -19337,15 +19399,15 @@ function stopSessionHostProcesses(appName) {
|
|
|
19337
19399
|
} catch {
|
|
19338
19400
|
} finally {
|
|
19339
19401
|
try {
|
|
19340
|
-
|
|
19402
|
+
fs9.unlinkSync(pidFile);
|
|
19341
19403
|
} catch {
|
|
19342
19404
|
}
|
|
19343
19405
|
}
|
|
19344
19406
|
}
|
|
19345
19407
|
function removeDaemonPidFile() {
|
|
19346
|
-
const pidFile =
|
|
19408
|
+
const pidFile = path17.join(os18.homedir(), ".adhdev", "daemon.pid");
|
|
19347
19409
|
try {
|
|
19348
|
-
|
|
19410
|
+
fs9.unlinkSync(pidFile);
|
|
19349
19411
|
} catch {
|
|
19350
19412
|
}
|
|
19351
19413
|
}
|
|
@@ -19354,7 +19416,7 @@ function cleanupStaleGlobalInstallDirs(pkgName, surface) {
|
|
|
19354
19416
|
const npmRoot = String(execNpmCommandSync(["root", "-g", ...prefixArgs], { encoding: "utf8" }, surface)).trim();
|
|
19355
19417
|
if (!npmRoot) return;
|
|
19356
19418
|
const npmPrefix = surface.installPrefix || String(execNpmCommandSync(["prefix", "-g", ...prefixArgs], { encoding: "utf8" }, surface)).trim();
|
|
19357
|
-
const binDir = process.platform === "win32" ? npmPrefix :
|
|
19419
|
+
const binDir = process.platform === "win32" ? npmPrefix : path17.join(npmPrefix, "bin");
|
|
19358
19420
|
const packageBaseName = pkgName.startsWith("@") ? pkgName.split("/")[1] : pkgName;
|
|
19359
19421
|
const binNames = /* @__PURE__ */ new Set([packageBaseName]);
|
|
19360
19422
|
if (pkgName === "@adhdev/daemon-standalone") {
|
|
@@ -19362,25 +19424,25 @@ function cleanupStaleGlobalInstallDirs(pkgName, surface) {
|
|
|
19362
19424
|
}
|
|
19363
19425
|
if (pkgName.startsWith("@")) {
|
|
19364
19426
|
const [scope, name] = pkgName.split("/");
|
|
19365
|
-
const scopeDir =
|
|
19366
|
-
if (!
|
|
19367
|
-
for (const entry of
|
|
19427
|
+
const scopeDir = path17.join(npmRoot, scope);
|
|
19428
|
+
if (!fs9.existsSync(scopeDir)) return;
|
|
19429
|
+
for (const entry of fs9.readdirSync(scopeDir)) {
|
|
19368
19430
|
if (!entry.startsWith(`.${name}-`)) continue;
|
|
19369
|
-
|
|
19370
|
-
appendUpgradeLog(`Removed stale scoped staging dir: ${
|
|
19431
|
+
fs9.rmSync(path17.join(scopeDir, entry), { recursive: true, force: true });
|
|
19432
|
+
appendUpgradeLog(`Removed stale scoped staging dir: ${path17.join(scopeDir, entry)}`);
|
|
19371
19433
|
}
|
|
19372
19434
|
} else {
|
|
19373
|
-
for (const entry of
|
|
19435
|
+
for (const entry of fs9.readdirSync(npmRoot)) {
|
|
19374
19436
|
if (!entry.startsWith(`.${pkgName}-`)) continue;
|
|
19375
|
-
|
|
19376
|
-
appendUpgradeLog(`Removed stale staging dir: ${
|
|
19437
|
+
fs9.rmSync(path17.join(npmRoot, entry), { recursive: true, force: true });
|
|
19438
|
+
appendUpgradeLog(`Removed stale staging dir: ${path17.join(npmRoot, entry)}`);
|
|
19377
19439
|
}
|
|
19378
19440
|
}
|
|
19379
|
-
if (
|
|
19380
|
-
for (const entry of
|
|
19441
|
+
if (fs9.existsSync(binDir)) {
|
|
19442
|
+
for (const entry of fs9.readdirSync(binDir)) {
|
|
19381
19443
|
if (!Array.from(binNames).some((name) => entry.startsWith(`.${name}-`))) continue;
|
|
19382
|
-
|
|
19383
|
-
appendUpgradeLog(`Removed stale bin staging entry: ${
|
|
19444
|
+
fs9.rmSync(path17.join(binDir, entry), { recursive: true, force: true });
|
|
19445
|
+
appendUpgradeLog(`Removed stale bin staging entry: ${path17.join(binDir, entry)}`);
|
|
19384
19446
|
}
|
|
19385
19447
|
}
|
|
19386
19448
|
}
|
|
@@ -19465,7 +19527,7 @@ async function maybeRunDaemonUpgradeHelperFromEnv() {
|
|
|
19465
19527
|
}
|
|
19466
19528
|
|
|
19467
19529
|
// src/commands/router.ts
|
|
19468
|
-
import * as
|
|
19530
|
+
import * as fs10 from "fs";
|
|
19469
19531
|
var CHAT_COMMANDS = [
|
|
19470
19532
|
"send_chat",
|
|
19471
19533
|
"new_chat",
|
|
@@ -19701,8 +19763,8 @@ var DaemonCommandRouter = class {
|
|
|
19701
19763
|
if (sinceTs > 0) {
|
|
19702
19764
|
return { success: true, logs: [], totalBuffered: 0 };
|
|
19703
19765
|
}
|
|
19704
|
-
if (
|
|
19705
|
-
const content =
|
|
19766
|
+
if (fs10.existsSync(LOG_PATH)) {
|
|
19767
|
+
const content = fs10.readFileSync(LOG_PATH, "utf-8");
|
|
19706
19768
|
const allLines = content.split("\n");
|
|
19707
19769
|
const recent = allLines.slice(-count).join("\n");
|
|
19708
19770
|
return { success: true, logs: recent, totalLines: allLines.length };
|
|
@@ -21857,12 +21919,12 @@ init_io_contracts();
|
|
|
21857
21919
|
init_chat_message_normalization();
|
|
21858
21920
|
|
|
21859
21921
|
// src/providers/version-archive.ts
|
|
21860
|
-
import * as
|
|
21861
|
-
import * as
|
|
21862
|
-
import * as
|
|
21922
|
+
import * as fs11 from "fs";
|
|
21923
|
+
import * as path18 from "path";
|
|
21924
|
+
import * as os19 from "os";
|
|
21863
21925
|
import { execSync as execSync5 } from "child_process";
|
|
21864
21926
|
import { platform as platform8 } from "os";
|
|
21865
|
-
var ARCHIVE_PATH =
|
|
21927
|
+
var ARCHIVE_PATH = path18.join(os19.homedir(), ".adhdev", "version-history.json");
|
|
21866
21928
|
var MAX_ENTRIES_PER_PROVIDER = 20;
|
|
21867
21929
|
var VersionArchive = class {
|
|
21868
21930
|
history = {};
|
|
@@ -21871,8 +21933,8 @@ var VersionArchive = class {
|
|
|
21871
21933
|
}
|
|
21872
21934
|
load() {
|
|
21873
21935
|
try {
|
|
21874
|
-
if (
|
|
21875
|
-
this.history = JSON.parse(
|
|
21936
|
+
if (fs11.existsSync(ARCHIVE_PATH)) {
|
|
21937
|
+
this.history = JSON.parse(fs11.readFileSync(ARCHIVE_PATH, "utf-8"));
|
|
21876
21938
|
}
|
|
21877
21939
|
} catch {
|
|
21878
21940
|
this.history = {};
|
|
@@ -21909,8 +21971,8 @@ var VersionArchive = class {
|
|
|
21909
21971
|
}
|
|
21910
21972
|
save() {
|
|
21911
21973
|
try {
|
|
21912
|
-
|
|
21913
|
-
|
|
21974
|
+
fs11.mkdirSync(path18.dirname(ARCHIVE_PATH), { recursive: true });
|
|
21975
|
+
fs11.writeFileSync(ARCHIVE_PATH, JSON.stringify(this.history, null, 2));
|
|
21914
21976
|
} catch {
|
|
21915
21977
|
}
|
|
21916
21978
|
}
|
|
@@ -21965,19 +22027,19 @@ function getVersion(binary, versionCommand) {
|
|
|
21965
22027
|
function checkPathExists2(paths) {
|
|
21966
22028
|
for (const p of paths) {
|
|
21967
22029
|
if (p.includes("*")) {
|
|
21968
|
-
const home =
|
|
21969
|
-
const resolved = p.replace(/\*/g, home.split(
|
|
21970
|
-
if (
|
|
22030
|
+
const home = os19.homedir();
|
|
22031
|
+
const resolved = p.replace(/\*/g, home.split(path18.sep).pop() || "");
|
|
22032
|
+
if (fs11.existsSync(resolved)) return resolved;
|
|
21971
22033
|
} else {
|
|
21972
|
-
if (
|
|
22034
|
+
if (fs11.existsSync(p)) return p;
|
|
21973
22035
|
}
|
|
21974
22036
|
}
|
|
21975
22037
|
return null;
|
|
21976
22038
|
}
|
|
21977
22039
|
function getMacAppVersion(appPath) {
|
|
21978
22040
|
if (platform8() !== "darwin" || !appPath.endsWith(".app")) return null;
|
|
21979
|
-
const plistPath =
|
|
21980
|
-
if (!
|
|
22041
|
+
const plistPath = path18.join(appPath, "Contents", "Info.plist");
|
|
22042
|
+
if (!fs11.existsSync(plistPath)) return null;
|
|
21981
22043
|
const raw = runCommand(`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${plistPath}"`);
|
|
21982
22044
|
return raw || null;
|
|
21983
22045
|
}
|
|
@@ -22002,8 +22064,8 @@ async function detectAllVersions(loader, archive) {
|
|
|
22002
22064
|
const cliBin = provider.cli ? findBinary2(provider.cli) : null;
|
|
22003
22065
|
let resolvedBin = cliBin;
|
|
22004
22066
|
if (!resolvedBin && appPath && currentOs === "darwin") {
|
|
22005
|
-
const bundled =
|
|
22006
|
-
if (provider.cli &&
|
|
22067
|
+
const bundled = path18.join(appPath, "Contents", "Resources", "app", "bin", provider.cli || "");
|
|
22068
|
+
if (provider.cli && fs11.existsSync(bundled)) resolvedBin = bundled;
|
|
22007
22069
|
}
|
|
22008
22070
|
info.installed = !!(appPath || resolvedBin);
|
|
22009
22071
|
info.path = appPath || null;
|
|
@@ -22042,8 +22104,8 @@ async function detectAllVersions(loader, archive) {
|
|
|
22042
22104
|
|
|
22043
22105
|
// src/daemon/dev-server.ts
|
|
22044
22106
|
import * as http2 from "http";
|
|
22045
|
-
import * as
|
|
22046
|
-
import * as
|
|
22107
|
+
import * as fs15 from "fs";
|
|
22108
|
+
import * as path22 from "path";
|
|
22047
22109
|
init_config();
|
|
22048
22110
|
|
|
22049
22111
|
// src/daemon/scaffold-template.ts
|
|
@@ -22394,8 +22456,8 @@ init_logger();
|
|
|
22394
22456
|
|
|
22395
22457
|
// src/daemon/dev-cdp-handlers.ts
|
|
22396
22458
|
init_logger();
|
|
22397
|
-
import * as
|
|
22398
|
-
import * as
|
|
22459
|
+
import * as fs12 from "fs";
|
|
22460
|
+
import * as path19 from "path";
|
|
22399
22461
|
async function handleCdpEvaluate(ctx, req, res) {
|
|
22400
22462
|
const body = await ctx.readBody(req);
|
|
22401
22463
|
const { expression, timeout, ideType } = body;
|
|
@@ -22573,18 +22635,18 @@ async function handleScriptHints(ctx, type, _req, res) {
|
|
|
22573
22635
|
return;
|
|
22574
22636
|
}
|
|
22575
22637
|
let scriptsPath = "";
|
|
22576
|
-
const directScripts =
|
|
22577
|
-
if (
|
|
22638
|
+
const directScripts = path19.join(dir, "scripts.js");
|
|
22639
|
+
if (fs12.existsSync(directScripts)) {
|
|
22578
22640
|
scriptsPath = directScripts;
|
|
22579
22641
|
} else {
|
|
22580
|
-
const scriptsDir =
|
|
22581
|
-
if (
|
|
22582
|
-
const versions =
|
|
22583
|
-
return
|
|
22642
|
+
const scriptsDir = path19.join(dir, "scripts");
|
|
22643
|
+
if (fs12.existsSync(scriptsDir)) {
|
|
22644
|
+
const versions = fs12.readdirSync(scriptsDir).filter((d) => {
|
|
22645
|
+
return fs12.statSync(path19.join(scriptsDir, d)).isDirectory();
|
|
22584
22646
|
}).sort().reverse();
|
|
22585
22647
|
for (const ver of versions) {
|
|
22586
|
-
const p =
|
|
22587
|
-
if (
|
|
22648
|
+
const p = path19.join(scriptsDir, ver, "scripts.js");
|
|
22649
|
+
if (fs12.existsSync(p)) {
|
|
22588
22650
|
scriptsPath = p;
|
|
22589
22651
|
break;
|
|
22590
22652
|
}
|
|
@@ -22596,7 +22658,7 @@ async function handleScriptHints(ctx, type, _req, res) {
|
|
|
22596
22658
|
return;
|
|
22597
22659
|
}
|
|
22598
22660
|
try {
|
|
22599
|
-
const source =
|
|
22661
|
+
const source = fs12.readFileSync(scriptsPath, "utf-8");
|
|
22600
22662
|
const hints = {};
|
|
22601
22663
|
const funcRegex = /module\.exports\.(\w+)\s*=\s*function\s+\w+\s*\(params\)/g;
|
|
22602
22664
|
let match;
|
|
@@ -23411,8 +23473,8 @@ async function handleDomContext(ctx, type, req, res) {
|
|
|
23411
23473
|
}
|
|
23412
23474
|
|
|
23413
23475
|
// src/daemon/dev-cli-debug.ts
|
|
23414
|
-
import * as
|
|
23415
|
-
import * as
|
|
23476
|
+
import * as fs13 from "fs";
|
|
23477
|
+
import * as path20 from "path";
|
|
23416
23478
|
function slugifyFixtureName(value) {
|
|
23417
23479
|
const normalized = String(value || "").trim().toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
23418
23480
|
return normalized || `fixture-${Date.now()}`;
|
|
@@ -23422,15 +23484,15 @@ function getCliFixtureDir(ctx, type) {
|
|
|
23422
23484
|
if (!providerDir) {
|
|
23423
23485
|
throw new Error(`Provider directory not found for '${type}'`);
|
|
23424
23486
|
}
|
|
23425
|
-
return
|
|
23487
|
+
return path20.join(providerDir, "fixtures");
|
|
23426
23488
|
}
|
|
23427
23489
|
function readCliFixture(ctx, type, name) {
|
|
23428
23490
|
const fixtureDir = getCliFixtureDir(ctx, type);
|
|
23429
|
-
const filePath =
|
|
23430
|
-
if (!
|
|
23491
|
+
const filePath = path20.join(fixtureDir, `${name}.json`);
|
|
23492
|
+
if (!fs13.existsSync(filePath)) {
|
|
23431
23493
|
throw new Error(`Fixture not found: ${filePath}`);
|
|
23432
23494
|
}
|
|
23433
|
-
return JSON.parse(
|
|
23495
|
+
return JSON.parse(fs13.readFileSync(filePath, "utf-8"));
|
|
23434
23496
|
}
|
|
23435
23497
|
function getExerciseTranscriptText(result) {
|
|
23436
23498
|
const parts = [];
|
|
@@ -24166,7 +24228,7 @@ async function handleCliFixtureCapture(ctx, req, res) {
|
|
|
24166
24228
|
return;
|
|
24167
24229
|
}
|
|
24168
24230
|
const fixtureDir = getCliFixtureDir(ctx, type);
|
|
24169
|
-
|
|
24231
|
+
fs13.mkdirSync(fixtureDir, { recursive: true });
|
|
24170
24232
|
const name = slugifyFixtureName(String(body?.name || `${type}-${Date.now()}`));
|
|
24171
24233
|
const result = await runCliExerciseInternal(ctx, { ...request, type });
|
|
24172
24234
|
const fixture = {
|
|
@@ -24193,8 +24255,8 @@ async function handleCliFixtureCapture(ctx, req, res) {
|
|
|
24193
24255
|
},
|
|
24194
24256
|
notes: typeof body?.notes === "string" ? body.notes : void 0
|
|
24195
24257
|
};
|
|
24196
|
-
const filePath =
|
|
24197
|
-
|
|
24258
|
+
const filePath = path20.join(fixtureDir, `${name}.json`);
|
|
24259
|
+
fs13.writeFileSync(filePath, JSON.stringify(fixture, null, 2));
|
|
24198
24260
|
ctx.json(res, 200, {
|
|
24199
24261
|
saved: true,
|
|
24200
24262
|
name,
|
|
@@ -24212,14 +24274,14 @@ async function handleCliFixtureCapture(ctx, req, res) {
|
|
|
24212
24274
|
async function handleCliFixtureList(ctx, type, _req, res) {
|
|
24213
24275
|
try {
|
|
24214
24276
|
const fixtureDir = getCliFixtureDir(ctx, type);
|
|
24215
|
-
if (!
|
|
24277
|
+
if (!fs13.existsSync(fixtureDir)) {
|
|
24216
24278
|
ctx.json(res, 200, { fixtures: [], count: 0 });
|
|
24217
24279
|
return;
|
|
24218
24280
|
}
|
|
24219
|
-
const fixtures =
|
|
24220
|
-
const fullPath =
|
|
24281
|
+
const fixtures = fs13.readdirSync(fixtureDir).filter((file) => file.endsWith(".json")).sort((a, b) => b.localeCompare(a, void 0, { numeric: true, sensitivity: "base" })).map((file) => {
|
|
24282
|
+
const fullPath = path20.join(fixtureDir, file);
|
|
24221
24283
|
try {
|
|
24222
|
-
const raw = JSON.parse(
|
|
24284
|
+
const raw = JSON.parse(fs13.readFileSync(fullPath, "utf-8"));
|
|
24223
24285
|
return {
|
|
24224
24286
|
name: raw.name || file.replace(/\.json$/i, ""),
|
|
24225
24287
|
path: fullPath,
|
|
@@ -24352,9 +24414,9 @@ async function handleCliRaw(ctx, req, res) {
|
|
|
24352
24414
|
}
|
|
24353
24415
|
|
|
24354
24416
|
// src/daemon/dev-auto-implement.ts
|
|
24355
|
-
import * as
|
|
24356
|
-
import * as
|
|
24357
|
-
import * as
|
|
24417
|
+
import * as fs14 from "fs";
|
|
24418
|
+
import * as path21 from "path";
|
|
24419
|
+
import * as os20 from "os";
|
|
24358
24420
|
function getAutoImplPid(ctx) {
|
|
24359
24421
|
const pid = ctx.autoImplProcess?.pid;
|
|
24360
24422
|
return typeof pid === "number" && pid > 0 ? pid : null;
|
|
@@ -24400,38 +24462,38 @@ function resolveAutoImplReference(ctx, category, requestedReference, targetType)
|
|
|
24400
24462
|
return fallback?.type || null;
|
|
24401
24463
|
}
|
|
24402
24464
|
function getLatestScriptVersionDir(scriptsDir) {
|
|
24403
|
-
if (!
|
|
24404
|
-
const versions =
|
|
24465
|
+
if (!fs14.existsSync(scriptsDir)) return null;
|
|
24466
|
+
const versions = fs14.readdirSync(scriptsDir).filter((d) => {
|
|
24405
24467
|
try {
|
|
24406
|
-
return
|
|
24468
|
+
return fs14.statSync(path21.join(scriptsDir, d)).isDirectory();
|
|
24407
24469
|
} catch {
|
|
24408
24470
|
return false;
|
|
24409
24471
|
}
|
|
24410
24472
|
}).sort((a, b) => b.localeCompare(a, void 0, { numeric: true, sensitivity: "base" }));
|
|
24411
24473
|
if (versions.length === 0) return null;
|
|
24412
|
-
return
|
|
24474
|
+
return path21.join(scriptsDir, versions[0]);
|
|
24413
24475
|
}
|
|
24414
24476
|
function resolveAutoImplWritableProviderDir(ctx, category, type, requestedDir) {
|
|
24415
|
-
const canonicalUserDir =
|
|
24416
|
-
const desiredDir = requestedDir ?
|
|
24417
|
-
const upstreamRoot =
|
|
24418
|
-
if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${
|
|
24477
|
+
const canonicalUserDir = path21.resolve(ctx.providerLoader.getUserProviderDir(category, type));
|
|
24478
|
+
const desiredDir = requestedDir ? path21.resolve(requestedDir) : canonicalUserDir;
|
|
24479
|
+
const upstreamRoot = path21.resolve(ctx.providerLoader.getUpstreamDir());
|
|
24480
|
+
if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${path21.sep}`)) {
|
|
24419
24481
|
return { dir: null, reason: `Refusing to write into upstream provider directory: ${desiredDir}` };
|
|
24420
24482
|
}
|
|
24421
|
-
if (
|
|
24483
|
+
if (path21.basename(desiredDir) !== type) {
|
|
24422
24484
|
return { dir: null, reason: `Requested writable provider directory must end with '${type}': ${desiredDir}` };
|
|
24423
24485
|
}
|
|
24424
24486
|
const sourceDir = ctx.findProviderDir(type);
|
|
24425
24487
|
if (!sourceDir) {
|
|
24426
24488
|
return { dir: null, reason: `Provider source directory not found for '${type}'` };
|
|
24427
24489
|
}
|
|
24428
|
-
if (!
|
|
24429
|
-
|
|
24430
|
-
|
|
24490
|
+
if (!fs14.existsSync(desiredDir)) {
|
|
24491
|
+
fs14.mkdirSync(path21.dirname(desiredDir), { recursive: true });
|
|
24492
|
+
fs14.cpSync(sourceDir, desiredDir, { recursive: true });
|
|
24431
24493
|
ctx.log(`Auto-implement writable copy created: ${desiredDir}`);
|
|
24432
24494
|
}
|
|
24433
|
-
const providerJson =
|
|
24434
|
-
if (!
|
|
24495
|
+
const providerJson = path21.join(desiredDir, "provider.json");
|
|
24496
|
+
if (!fs14.existsSync(providerJson)) {
|
|
24435
24497
|
return { dir: null, reason: `provider.json not found in writable provider directory: ${desiredDir}` };
|
|
24436
24498
|
}
|
|
24437
24499
|
return { dir: desiredDir };
|
|
@@ -24439,15 +24501,15 @@ function resolveAutoImplWritableProviderDir(ctx, category, type, requestedDir) {
|
|
|
24439
24501
|
function loadAutoImplReferenceScripts(ctx, referenceType) {
|
|
24440
24502
|
if (!referenceType) return {};
|
|
24441
24503
|
const refDir = ctx.findProviderDir(referenceType);
|
|
24442
|
-
if (!refDir || !
|
|
24504
|
+
if (!refDir || !fs14.existsSync(refDir)) return {};
|
|
24443
24505
|
const referenceScripts = {};
|
|
24444
|
-
const scriptsDir =
|
|
24506
|
+
const scriptsDir = path21.join(refDir, "scripts");
|
|
24445
24507
|
const latestDir = getLatestScriptVersionDir(scriptsDir);
|
|
24446
24508
|
if (!latestDir) return referenceScripts;
|
|
24447
|
-
for (const file of
|
|
24509
|
+
for (const file of fs14.readdirSync(latestDir)) {
|
|
24448
24510
|
if (!file.endsWith(".js")) continue;
|
|
24449
24511
|
try {
|
|
24450
|
-
referenceScripts[file] =
|
|
24512
|
+
referenceScripts[file] = fs14.readFileSync(path21.join(latestDir, file), "utf-8");
|
|
24451
24513
|
} catch {
|
|
24452
24514
|
}
|
|
24453
24515
|
}
|
|
@@ -24555,16 +24617,16 @@ async function handleAutoImplement(ctx, type, req, res) {
|
|
|
24555
24617
|
});
|
|
24556
24618
|
const referenceScripts = loadAutoImplReferenceScripts(ctx, resolvedReference);
|
|
24557
24619
|
const prompt = buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domContext, referenceScripts, comment, resolvedReference, verification);
|
|
24558
|
-
const tmpDir =
|
|
24559
|
-
if (!
|
|
24560
|
-
const promptFile =
|
|
24561
|
-
|
|
24620
|
+
const tmpDir = path21.join(os20.tmpdir(), "adhdev-autoimpl");
|
|
24621
|
+
if (!fs14.existsSync(tmpDir)) fs14.mkdirSync(tmpDir, { recursive: true });
|
|
24622
|
+
const promptFile = path21.join(tmpDir, `prompt-${type}-${Date.now()}.md`);
|
|
24623
|
+
fs14.writeFileSync(promptFile, prompt, "utf-8");
|
|
24562
24624
|
ctx.log(`Auto-implement prompt written to ${promptFile} (${prompt.length} chars)`);
|
|
24563
24625
|
const agentProvider = ctx.providerLoader.resolve(agent) || ctx.providerLoader.getMeta(agent);
|
|
24564
24626
|
const spawn4 = agentProvider?.spawn;
|
|
24565
24627
|
if (!spawn4?.command) {
|
|
24566
24628
|
try {
|
|
24567
|
-
|
|
24629
|
+
fs14.unlinkSync(promptFile);
|
|
24568
24630
|
} catch {
|
|
24569
24631
|
}
|
|
24570
24632
|
ctx.json(res, 400, { error: `Agent '${agent}' has no spawn config. Select a CLI provider with a spawn configuration.` });
|
|
@@ -24666,7 +24728,7 @@ async function handleAutoImplement(ctx, type, req, res) {
|
|
|
24666
24728
|
} catch {
|
|
24667
24729
|
}
|
|
24668
24730
|
try {
|
|
24669
|
-
|
|
24731
|
+
fs14.unlinkSync(promptFile);
|
|
24670
24732
|
} catch {
|
|
24671
24733
|
}
|
|
24672
24734
|
ctx.log(`Auto-implement (ACP) ${success ? "completed" : "failed"}: ${type} (exit: ${code})`);
|
|
@@ -24710,7 +24772,7 @@ async function handleAutoImplement(ctx, type, req, res) {
|
|
|
24710
24772
|
const interactiveFlags = ["--yolo", "--interactive", "-i"];
|
|
24711
24773
|
const baseArgs = [...spawn4.args || []].filter((a) => !interactiveFlags.includes(a));
|
|
24712
24774
|
let shellCmd;
|
|
24713
|
-
const isWin =
|
|
24775
|
+
const isWin = os20.platform() === "win32";
|
|
24714
24776
|
const escapeArg = (a) => isWin ? `"${a.replace(/"/g, '""')}"` : `'${a.replace(/'/g, "'\\''")}'`;
|
|
24715
24777
|
const promptMode = autoImpl?.promptMode ?? "stdin";
|
|
24716
24778
|
const extraArgs = autoImpl?.extraArgs ?? [];
|
|
@@ -24749,7 +24811,7 @@ async function handleAutoImplement(ctx, type, req, res) {
|
|
|
24749
24811
|
try {
|
|
24750
24812
|
const pty = __require("node-pty");
|
|
24751
24813
|
ctx.log(`Auto-implement spawn (PTY): ${shellCmd}`);
|
|
24752
|
-
const isWin2 =
|
|
24814
|
+
const isWin2 = os20.platform() === "win32";
|
|
24753
24815
|
child = pty.spawn(isWin2 ? "cmd.exe" : process.env.SHELL || "/bin/zsh", [isWin2 ? "/c" : "-c", shellCmd], {
|
|
24754
24816
|
name: "xterm-256color",
|
|
24755
24817
|
cols: 120,
|
|
@@ -24892,7 +24954,7 @@ async function handleAutoImplement(ctx, type, req, res) {
|
|
|
24892
24954
|
}
|
|
24893
24955
|
});
|
|
24894
24956
|
try {
|
|
24895
|
-
|
|
24957
|
+
fs14.unlinkSync(promptFile);
|
|
24896
24958
|
} catch {
|
|
24897
24959
|
}
|
|
24898
24960
|
ctx.log(`Auto-implement ${success ? "completed" : "failed"}: ${type} (exit: ${code})${verificationSummary ? ` verify=${verificationSummary.pass ? "pass" : "fail"}` : ""}`);
|
|
@@ -24989,7 +25051,7 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
|
|
|
24989
25051
|
setMode: "set_mode.js"
|
|
24990
25052
|
};
|
|
24991
25053
|
const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
|
|
24992
|
-
const scriptsDir =
|
|
25054
|
+
const scriptsDir = path21.join(providerDir, "scripts");
|
|
24993
25055
|
const latestScriptsDir = getLatestScriptVersionDir(scriptsDir);
|
|
24994
25056
|
if (latestScriptsDir) {
|
|
24995
25057
|
lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
|
|
@@ -24997,10 +25059,10 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
|
|
|
24997
25059
|
lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
|
|
24998
25060
|
lines.push("These are the ONLY files you are allowed to modify. Replace the TODO stubs with working implementations.");
|
|
24999
25061
|
lines.push("");
|
|
25000
|
-
for (const file of
|
|
25062
|
+
for (const file of fs14.readdirSync(latestScriptsDir)) {
|
|
25001
25063
|
if (file.endsWith(".js") && targetFileNames.has(file)) {
|
|
25002
25064
|
try {
|
|
25003
|
-
const content =
|
|
25065
|
+
const content = fs14.readFileSync(path21.join(latestScriptsDir, file), "utf-8");
|
|
25004
25066
|
lines.push(`### \`${file}\` \u270F\uFE0F EDIT`);
|
|
25005
25067
|
lines.push("```javascript");
|
|
25006
25068
|
lines.push(content);
|
|
@@ -25010,14 +25072,14 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
|
|
|
25010
25072
|
}
|
|
25011
25073
|
}
|
|
25012
25074
|
}
|
|
25013
|
-
const refFiles =
|
|
25075
|
+
const refFiles = fs14.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
|
|
25014
25076
|
if (refFiles.length > 0) {
|
|
25015
25077
|
lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
|
|
25016
25078
|
lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
|
|
25017
25079
|
lines.push("");
|
|
25018
25080
|
for (const file of refFiles) {
|
|
25019
25081
|
try {
|
|
25020
|
-
const content =
|
|
25082
|
+
const content = fs14.readFileSync(path21.join(latestScriptsDir, file), "utf-8");
|
|
25021
25083
|
lines.push(`### \`${file}\` \u{1F512}`);
|
|
25022
25084
|
lines.push("```javascript");
|
|
25023
25085
|
lines.push(content);
|
|
@@ -25058,11 +25120,11 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
|
|
|
25058
25120
|
lines.push("");
|
|
25059
25121
|
}
|
|
25060
25122
|
}
|
|
25061
|
-
const docsDir =
|
|
25123
|
+
const docsDir = path21.join(providerDir, "../../docs");
|
|
25062
25124
|
const loadGuide = (name) => {
|
|
25063
25125
|
try {
|
|
25064
|
-
const p =
|
|
25065
|
-
if (
|
|
25126
|
+
const p = path21.join(docsDir, name);
|
|
25127
|
+
if (fs14.existsSync(p)) return fs14.readFileSync(p, "utf-8");
|
|
25066
25128
|
} catch {
|
|
25067
25129
|
}
|
|
25068
25130
|
return null;
|
|
@@ -25298,7 +25360,7 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
|
|
|
25298
25360
|
parseApproval: "parse_approval.js"
|
|
25299
25361
|
};
|
|
25300
25362
|
const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
|
|
25301
|
-
const scriptsDir =
|
|
25363
|
+
const scriptsDir = path21.join(providerDir, "scripts");
|
|
25302
25364
|
const latestScriptsDir = getLatestScriptVersionDir(scriptsDir);
|
|
25303
25365
|
if (latestScriptsDir) {
|
|
25304
25366
|
lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
|
|
@@ -25306,11 +25368,11 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
|
|
|
25306
25368
|
lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
|
|
25307
25369
|
lines.push("These are the ONLY files you are allowed to modify. Replace TODO or heuristic-only logic with working PTY-aware implementations.");
|
|
25308
25370
|
lines.push("");
|
|
25309
|
-
for (const file of
|
|
25371
|
+
for (const file of fs14.readdirSync(latestScriptsDir)) {
|
|
25310
25372
|
if (!file.endsWith(".js")) continue;
|
|
25311
25373
|
if (!targetFileNames.has(file)) continue;
|
|
25312
25374
|
try {
|
|
25313
|
-
const content =
|
|
25375
|
+
const content = fs14.readFileSync(path21.join(latestScriptsDir, file), "utf-8");
|
|
25314
25376
|
lines.push(`### \`${file}\` \u270F\uFE0F EDIT`);
|
|
25315
25377
|
lines.push("```javascript");
|
|
25316
25378
|
lines.push(content);
|
|
@@ -25319,14 +25381,14 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
|
|
|
25319
25381
|
} catch {
|
|
25320
25382
|
}
|
|
25321
25383
|
}
|
|
25322
|
-
const refFiles =
|
|
25384
|
+
const refFiles = fs14.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
|
|
25323
25385
|
if (refFiles.length > 0) {
|
|
25324
25386
|
lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
|
|
25325
25387
|
lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
|
|
25326
25388
|
lines.push("");
|
|
25327
25389
|
for (const file of refFiles) {
|
|
25328
25390
|
try {
|
|
25329
|
-
const content =
|
|
25391
|
+
const content = fs14.readFileSync(path21.join(latestScriptsDir, file), "utf-8");
|
|
25330
25392
|
lines.push(`### \`${file}\` \u{1F512}`);
|
|
25331
25393
|
lines.push("```javascript");
|
|
25332
25394
|
lines.push(content);
|
|
@@ -25359,11 +25421,11 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
|
|
|
25359
25421
|
lines.push("");
|
|
25360
25422
|
}
|
|
25361
25423
|
}
|
|
25362
|
-
const docsDir =
|
|
25424
|
+
const docsDir = path21.join(providerDir, "../../docs");
|
|
25363
25425
|
const loadGuide = (name) => {
|
|
25364
25426
|
try {
|
|
25365
|
-
const p =
|
|
25366
|
-
if (
|
|
25427
|
+
const p = path21.join(docsDir, name);
|
|
25428
|
+
if (fs14.existsSync(p)) return fs14.readFileSync(p, "utf-8");
|
|
25367
25429
|
} catch {
|
|
25368
25430
|
}
|
|
25369
25431
|
return null;
|
|
@@ -25809,8 +25871,8 @@ var DevServer = class _DevServer {
|
|
|
25809
25871
|
}
|
|
25810
25872
|
getEndpointList() {
|
|
25811
25873
|
return this.routes.map((r) => {
|
|
25812
|
-
const
|
|
25813
|
-
return `${r.method.padEnd(5)} ${
|
|
25874
|
+
const path23 = typeof r.pattern === "string" ? r.pattern : r.pattern.source.replace(/\\\//g, "/").replace(/\(\[.*?\]\+\)/g, ":type").replace(/[\^$]/g, "");
|
|
25875
|
+
return `${r.method.padEnd(5)} ${path23}`;
|
|
25814
25876
|
});
|
|
25815
25877
|
}
|
|
25816
25878
|
async start(port = DEV_SERVER_PORT) {
|
|
@@ -26098,12 +26160,12 @@ var DevServer = class _DevServer {
|
|
|
26098
26160
|
// ─── DevConsole SPA ───
|
|
26099
26161
|
getConsoleDistDir() {
|
|
26100
26162
|
const candidates = [
|
|
26101
|
-
|
|
26102
|
-
|
|
26103
|
-
|
|
26163
|
+
path22.resolve(__dirname, "../../web-devconsole/dist"),
|
|
26164
|
+
path22.resolve(__dirname, "../../../web-devconsole/dist"),
|
|
26165
|
+
path22.join(process.cwd(), "packages/web-devconsole/dist")
|
|
26104
26166
|
];
|
|
26105
26167
|
for (const dir of candidates) {
|
|
26106
|
-
if (
|
|
26168
|
+
if (fs15.existsSync(path22.join(dir, "index.html"))) return dir;
|
|
26107
26169
|
}
|
|
26108
26170
|
return null;
|
|
26109
26171
|
}
|
|
@@ -26113,9 +26175,9 @@ var DevServer = class _DevServer {
|
|
|
26113
26175
|
this.json(res, 500, { error: "DevConsole not found. Run: npm run build -w packages/web-devconsole" });
|
|
26114
26176
|
return;
|
|
26115
26177
|
}
|
|
26116
|
-
const htmlPath =
|
|
26178
|
+
const htmlPath = path22.join(distDir, "index.html");
|
|
26117
26179
|
try {
|
|
26118
|
-
const html =
|
|
26180
|
+
const html = fs15.readFileSync(htmlPath, "utf-8");
|
|
26119
26181
|
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
26120
26182
|
res.end(html);
|
|
26121
26183
|
} catch (e) {
|
|
@@ -26138,15 +26200,15 @@ var DevServer = class _DevServer {
|
|
|
26138
26200
|
this.json(res, 404, { error: "Not found" });
|
|
26139
26201
|
return;
|
|
26140
26202
|
}
|
|
26141
|
-
const safePath =
|
|
26142
|
-
const filePath =
|
|
26203
|
+
const safePath = path22.normalize(pathname).replace(/^\.\.\//, "");
|
|
26204
|
+
const filePath = path22.join(distDir, safePath);
|
|
26143
26205
|
if (!filePath.startsWith(distDir)) {
|
|
26144
26206
|
this.json(res, 403, { error: "Forbidden" });
|
|
26145
26207
|
return;
|
|
26146
26208
|
}
|
|
26147
26209
|
try {
|
|
26148
|
-
const content =
|
|
26149
|
-
const ext =
|
|
26210
|
+
const content = fs15.readFileSync(filePath);
|
|
26211
|
+
const ext = path22.extname(filePath);
|
|
26150
26212
|
const contentType = _DevServer.MIME_MAP[ext] || "application/octet-stream";
|
|
26151
26213
|
res.writeHead(200, { "Content-Type": contentType, "Cache-Control": "public, max-age=31536000, immutable" });
|
|
26152
26214
|
res.end(content);
|
|
@@ -26254,14 +26316,14 @@ var DevServer = class _DevServer {
|
|
|
26254
26316
|
const files = [];
|
|
26255
26317
|
const scan = (d, prefix) => {
|
|
26256
26318
|
try {
|
|
26257
|
-
for (const entry of
|
|
26319
|
+
for (const entry of fs15.readdirSync(d, { withFileTypes: true })) {
|
|
26258
26320
|
if (entry.name.startsWith(".") || entry.name.endsWith(".bak")) continue;
|
|
26259
26321
|
const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
26260
26322
|
if (entry.isDirectory()) {
|
|
26261
26323
|
files.push({ path: rel, size: 0, type: "dir" });
|
|
26262
|
-
scan(
|
|
26324
|
+
scan(path22.join(d, entry.name), rel);
|
|
26263
26325
|
} else {
|
|
26264
|
-
const stat =
|
|
26326
|
+
const stat = fs15.statSync(path22.join(d, entry.name));
|
|
26265
26327
|
files.push({ path: rel, size: stat.size, type: "file" });
|
|
26266
26328
|
}
|
|
26267
26329
|
}
|
|
@@ -26284,16 +26346,16 @@ var DevServer = class _DevServer {
|
|
|
26284
26346
|
this.json(res, 404, { error: `Provider directory not found: ${type}` });
|
|
26285
26347
|
return;
|
|
26286
26348
|
}
|
|
26287
|
-
const fullPath =
|
|
26349
|
+
const fullPath = path22.resolve(dir, path22.normalize(filePath));
|
|
26288
26350
|
if (!fullPath.startsWith(dir)) {
|
|
26289
26351
|
this.json(res, 403, { error: "Forbidden" });
|
|
26290
26352
|
return;
|
|
26291
26353
|
}
|
|
26292
|
-
if (!
|
|
26354
|
+
if (!fs15.existsSync(fullPath) || fs15.statSync(fullPath).isDirectory()) {
|
|
26293
26355
|
this.json(res, 404, { error: `File not found: ${filePath}` });
|
|
26294
26356
|
return;
|
|
26295
26357
|
}
|
|
26296
|
-
const content =
|
|
26358
|
+
const content = fs15.readFileSync(fullPath, "utf-8");
|
|
26297
26359
|
this.json(res, 200, { type, path: filePath, content, lines: content.split("\n").length });
|
|
26298
26360
|
}
|
|
26299
26361
|
/** POST /api/providers/:type/file — write a file { path, content } */
|
|
@@ -26309,15 +26371,15 @@ var DevServer = class _DevServer {
|
|
|
26309
26371
|
this.json(res, 404, { error: `Provider directory not found: ${type}` });
|
|
26310
26372
|
return;
|
|
26311
26373
|
}
|
|
26312
|
-
const fullPath =
|
|
26374
|
+
const fullPath = path22.resolve(dir, path22.normalize(filePath));
|
|
26313
26375
|
if (!fullPath.startsWith(dir)) {
|
|
26314
26376
|
this.json(res, 403, { error: "Forbidden" });
|
|
26315
26377
|
return;
|
|
26316
26378
|
}
|
|
26317
26379
|
try {
|
|
26318
|
-
if (
|
|
26319
|
-
|
|
26320
|
-
|
|
26380
|
+
if (fs15.existsSync(fullPath)) fs15.copyFileSync(fullPath, fullPath + ".bak");
|
|
26381
|
+
fs15.mkdirSync(path22.dirname(fullPath), { recursive: true });
|
|
26382
|
+
fs15.writeFileSync(fullPath, content, "utf-8");
|
|
26321
26383
|
this.log(`File saved: ${fullPath} (${content.length} chars)`);
|
|
26322
26384
|
this.providerLoader.reload();
|
|
26323
26385
|
this.json(res, 200, { saved: true, path: filePath, chars: content.length });
|
|
@@ -26333,9 +26395,9 @@ var DevServer = class _DevServer {
|
|
|
26333
26395
|
return;
|
|
26334
26396
|
}
|
|
26335
26397
|
for (const name of ["scripts.js", "provider.json"]) {
|
|
26336
|
-
const p =
|
|
26337
|
-
if (
|
|
26338
|
-
const source =
|
|
26398
|
+
const p = path22.join(dir, name);
|
|
26399
|
+
if (fs15.existsSync(p)) {
|
|
26400
|
+
const source = fs15.readFileSync(p, "utf-8");
|
|
26339
26401
|
this.json(res, 200, { type, path: p, source, lines: source.split("\n").length });
|
|
26340
26402
|
return;
|
|
26341
26403
|
}
|
|
@@ -26354,11 +26416,11 @@ var DevServer = class _DevServer {
|
|
|
26354
26416
|
this.json(res, 404, { error: `Provider not found: ${type}` });
|
|
26355
26417
|
return;
|
|
26356
26418
|
}
|
|
26357
|
-
const target =
|
|
26358
|
-
const targetPath =
|
|
26419
|
+
const target = fs15.existsSync(path22.join(dir, "scripts.js")) ? "scripts.js" : "provider.json";
|
|
26420
|
+
const targetPath = path22.join(dir, target);
|
|
26359
26421
|
try {
|
|
26360
|
-
if (
|
|
26361
|
-
|
|
26422
|
+
if (fs15.existsSync(targetPath)) fs15.copyFileSync(targetPath, targetPath + ".bak");
|
|
26423
|
+
fs15.writeFileSync(targetPath, source, "utf-8");
|
|
26362
26424
|
this.log(`Saved provider: ${targetPath} (${source.length} chars)`);
|
|
26363
26425
|
this.providerLoader.reload();
|
|
26364
26426
|
this.json(res, 200, { saved: true, path: targetPath, chars: source.length });
|
|
@@ -26502,21 +26564,21 @@ var DevServer = class _DevServer {
|
|
|
26502
26564
|
}
|
|
26503
26565
|
let targetDir;
|
|
26504
26566
|
targetDir = this.providerLoader.getUserProviderDir(category, type);
|
|
26505
|
-
const jsonPath =
|
|
26506
|
-
if (
|
|
26567
|
+
const jsonPath = path22.join(targetDir, "provider.json");
|
|
26568
|
+
if (fs15.existsSync(jsonPath)) {
|
|
26507
26569
|
this.json(res, 409, { error: `Provider already exists at ${targetDir}`, path: targetDir });
|
|
26508
26570
|
return;
|
|
26509
26571
|
}
|
|
26510
26572
|
try {
|
|
26511
26573
|
const result = generateFiles(type, name, category, { cdpPorts, cli, processName, installPath, binary, extensionId, version, osPaths, processNames });
|
|
26512
|
-
|
|
26513
|
-
|
|
26574
|
+
fs15.mkdirSync(targetDir, { recursive: true });
|
|
26575
|
+
fs15.writeFileSync(jsonPath, result["provider.json"], "utf-8");
|
|
26514
26576
|
const createdFiles = ["provider.json"];
|
|
26515
26577
|
if (result.files) {
|
|
26516
26578
|
for (const [relPath, content] of Object.entries(result.files)) {
|
|
26517
|
-
const fullPath =
|
|
26518
|
-
|
|
26519
|
-
|
|
26579
|
+
const fullPath = path22.join(targetDir, relPath);
|
|
26580
|
+
fs15.mkdirSync(path22.dirname(fullPath), { recursive: true });
|
|
26581
|
+
fs15.writeFileSync(fullPath, content, "utf-8");
|
|
26520
26582
|
createdFiles.push(relPath);
|
|
26521
26583
|
}
|
|
26522
26584
|
}
|
|
@@ -26565,38 +26627,38 @@ var DevServer = class _DevServer {
|
|
|
26565
26627
|
}
|
|
26566
26628
|
// ─── Phase 2: Auto-Implement Backend ───
|
|
26567
26629
|
getLatestScriptVersionDir(scriptsDir) {
|
|
26568
|
-
if (!
|
|
26569
|
-
const versions =
|
|
26630
|
+
if (!fs15.existsSync(scriptsDir)) return null;
|
|
26631
|
+
const versions = fs15.readdirSync(scriptsDir).filter((d) => {
|
|
26570
26632
|
try {
|
|
26571
|
-
return
|
|
26633
|
+
return fs15.statSync(path22.join(scriptsDir, d)).isDirectory();
|
|
26572
26634
|
} catch {
|
|
26573
26635
|
return false;
|
|
26574
26636
|
}
|
|
26575
26637
|
}).sort((a, b) => b.localeCompare(a, void 0, { numeric: true, sensitivity: "base" }));
|
|
26576
26638
|
if (versions.length === 0) return null;
|
|
26577
|
-
return
|
|
26639
|
+
return path22.join(scriptsDir, versions[0]);
|
|
26578
26640
|
}
|
|
26579
26641
|
resolveAutoImplWritableProviderDir(category, type, requestedDir) {
|
|
26580
|
-
const canonicalUserDir =
|
|
26581
|
-
const desiredDir = requestedDir ?
|
|
26582
|
-
const upstreamRoot =
|
|
26583
|
-
if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${
|
|
26642
|
+
const canonicalUserDir = path22.resolve(this.providerLoader.getUserProviderDir(category, type));
|
|
26643
|
+
const desiredDir = requestedDir ? path22.resolve(requestedDir) : canonicalUserDir;
|
|
26644
|
+
const upstreamRoot = path22.resolve(this.providerLoader.getUpstreamDir());
|
|
26645
|
+
if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${path22.sep}`)) {
|
|
26584
26646
|
return { dir: null, reason: `Refusing to write into upstream provider directory: ${desiredDir}` };
|
|
26585
26647
|
}
|
|
26586
|
-
if (
|
|
26648
|
+
if (path22.basename(desiredDir) !== type) {
|
|
26587
26649
|
return { dir: null, reason: `Requested writable provider directory must end with '${type}': ${desiredDir}` };
|
|
26588
26650
|
}
|
|
26589
26651
|
const sourceDir = this.findProviderDir(type);
|
|
26590
26652
|
if (!sourceDir) {
|
|
26591
26653
|
return { dir: null, reason: `Provider source directory not found for '${type}'` };
|
|
26592
26654
|
}
|
|
26593
|
-
if (!
|
|
26594
|
-
|
|
26595
|
-
|
|
26655
|
+
if (!fs15.existsSync(desiredDir)) {
|
|
26656
|
+
fs15.mkdirSync(path22.dirname(desiredDir), { recursive: true });
|
|
26657
|
+
fs15.cpSync(sourceDir, desiredDir, { recursive: true });
|
|
26596
26658
|
this.log(`Auto-implement writable copy created: ${desiredDir}`);
|
|
26597
26659
|
}
|
|
26598
|
-
const providerJson =
|
|
26599
|
-
if (!
|
|
26660
|
+
const providerJson = path22.join(desiredDir, "provider.json");
|
|
26661
|
+
if (!fs15.existsSync(providerJson)) {
|
|
26600
26662
|
return { dir: null, reason: `provider.json not found in writable provider directory: ${desiredDir}` };
|
|
26601
26663
|
}
|
|
26602
26664
|
return { dir: desiredDir };
|
|
@@ -26631,7 +26693,7 @@ var DevServer = class _DevServer {
|
|
|
26631
26693
|
setMode: "set_mode.js"
|
|
26632
26694
|
};
|
|
26633
26695
|
const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
|
|
26634
|
-
const scriptsDir =
|
|
26696
|
+
const scriptsDir = path22.join(providerDir, "scripts");
|
|
26635
26697
|
const latestScriptsDir = this.getLatestScriptVersionDir(scriptsDir);
|
|
26636
26698
|
if (latestScriptsDir) {
|
|
26637
26699
|
lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
|
|
@@ -26639,10 +26701,10 @@ var DevServer = class _DevServer {
|
|
|
26639
26701
|
lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
|
|
26640
26702
|
lines.push("These are the ONLY files you are allowed to modify. Replace the TODO stubs with working implementations.");
|
|
26641
26703
|
lines.push("");
|
|
26642
|
-
for (const file of
|
|
26704
|
+
for (const file of fs15.readdirSync(latestScriptsDir)) {
|
|
26643
26705
|
if (file.endsWith(".js") && targetFileNames.has(file)) {
|
|
26644
26706
|
try {
|
|
26645
|
-
const content =
|
|
26707
|
+
const content = fs15.readFileSync(path22.join(latestScriptsDir, file), "utf-8");
|
|
26646
26708
|
lines.push(`### \`${file}\` \u270F\uFE0F EDIT`);
|
|
26647
26709
|
lines.push("```javascript");
|
|
26648
26710
|
lines.push(content);
|
|
@@ -26652,14 +26714,14 @@ var DevServer = class _DevServer {
|
|
|
26652
26714
|
}
|
|
26653
26715
|
}
|
|
26654
26716
|
}
|
|
26655
|
-
const refFiles =
|
|
26717
|
+
const refFiles = fs15.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
|
|
26656
26718
|
if (refFiles.length > 0) {
|
|
26657
26719
|
lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
|
|
26658
26720
|
lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
|
|
26659
26721
|
lines.push("");
|
|
26660
26722
|
for (const file of refFiles) {
|
|
26661
26723
|
try {
|
|
26662
|
-
const content =
|
|
26724
|
+
const content = fs15.readFileSync(path22.join(latestScriptsDir, file), "utf-8");
|
|
26663
26725
|
lines.push(`### \`${file}\` \u{1F512}`);
|
|
26664
26726
|
lines.push("```javascript");
|
|
26665
26727
|
lines.push(content);
|
|
@@ -26700,11 +26762,11 @@ var DevServer = class _DevServer {
|
|
|
26700
26762
|
lines.push("");
|
|
26701
26763
|
}
|
|
26702
26764
|
}
|
|
26703
|
-
const docsDir =
|
|
26765
|
+
const docsDir = path22.join(providerDir, "../../docs");
|
|
26704
26766
|
const loadGuide = (name) => {
|
|
26705
26767
|
try {
|
|
26706
|
-
const p =
|
|
26707
|
-
if (
|
|
26768
|
+
const p = path22.join(docsDir, name);
|
|
26769
|
+
if (fs15.existsSync(p)) return fs15.readFileSync(p, "utf-8");
|
|
26708
26770
|
} catch {
|
|
26709
26771
|
}
|
|
26710
26772
|
return null;
|
|
@@ -26877,7 +26939,7 @@ var DevServer = class _DevServer {
|
|
|
26877
26939
|
parseApproval: "parse_approval.js"
|
|
26878
26940
|
};
|
|
26879
26941
|
const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
|
|
26880
|
-
const scriptsDir =
|
|
26942
|
+
const scriptsDir = path22.join(providerDir, "scripts");
|
|
26881
26943
|
const latestScriptsDir = this.getLatestScriptVersionDir(scriptsDir);
|
|
26882
26944
|
if (latestScriptsDir) {
|
|
26883
26945
|
lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
|
|
@@ -26885,11 +26947,11 @@ var DevServer = class _DevServer {
|
|
|
26885
26947
|
lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
|
|
26886
26948
|
lines.push("These are the ONLY files you are allowed to modify. Replace TODO or heuristic-only logic with working PTY-aware implementations.");
|
|
26887
26949
|
lines.push("");
|
|
26888
|
-
for (const file of
|
|
26950
|
+
for (const file of fs15.readdirSync(latestScriptsDir)) {
|
|
26889
26951
|
if (!file.endsWith(".js")) continue;
|
|
26890
26952
|
if (!targetFileNames.has(file)) continue;
|
|
26891
26953
|
try {
|
|
26892
|
-
const content =
|
|
26954
|
+
const content = fs15.readFileSync(path22.join(latestScriptsDir, file), "utf-8");
|
|
26893
26955
|
lines.push(`### \`${file}\` \u270F\uFE0F EDIT`);
|
|
26894
26956
|
lines.push("```javascript");
|
|
26895
26957
|
lines.push(content);
|
|
@@ -26898,14 +26960,14 @@ var DevServer = class _DevServer {
|
|
|
26898
26960
|
} catch {
|
|
26899
26961
|
}
|
|
26900
26962
|
}
|
|
26901
|
-
const refFiles =
|
|
26963
|
+
const refFiles = fs15.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
|
|
26902
26964
|
if (refFiles.length > 0) {
|
|
26903
26965
|
lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
|
|
26904
26966
|
lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
|
|
26905
26967
|
lines.push("");
|
|
26906
26968
|
for (const file of refFiles) {
|
|
26907
26969
|
try {
|
|
26908
|
-
const content =
|
|
26970
|
+
const content = fs15.readFileSync(path22.join(latestScriptsDir, file), "utf-8");
|
|
26909
26971
|
lines.push(`### \`${file}\` \u{1F512}`);
|
|
26910
26972
|
lines.push("```javascript");
|
|
26911
26973
|
lines.push(content);
|
|
@@ -26938,11 +27000,11 @@ var DevServer = class _DevServer {
|
|
|
26938
27000
|
lines.push("");
|
|
26939
27001
|
}
|
|
26940
27002
|
}
|
|
26941
|
-
const docsDir =
|
|
27003
|
+
const docsDir = path22.join(providerDir, "../../docs");
|
|
26942
27004
|
const loadGuide = (name) => {
|
|
26943
27005
|
try {
|
|
26944
|
-
const p =
|
|
26945
|
-
if (
|
|
27006
|
+
const p = path22.join(docsDir, name);
|
|
27007
|
+
if (fs15.existsSync(p)) return fs15.readFileSync(p, "utf-8");
|
|
26946
27008
|
} catch {
|
|
26947
27009
|
}
|
|
26948
27010
|
return null;
|
|
@@ -27822,8 +27884,8 @@ async function installExtension(ide, extension) {
|
|
|
27822
27884
|
const res = await fetch(extension.vsixUrl);
|
|
27823
27885
|
if (res.ok) {
|
|
27824
27886
|
const buffer = Buffer.from(await res.arrayBuffer());
|
|
27825
|
-
const
|
|
27826
|
-
|
|
27887
|
+
const fs16 = await import("fs");
|
|
27888
|
+
fs16.writeFileSync(vsixPath, buffer);
|
|
27827
27889
|
return new Promise((resolve12) => {
|
|
27828
27890
|
const cmd = `"${ide.cliCommand}" --install-extension "${vsixPath}" --force`;
|
|
27829
27891
|
exec2(cmd, { timeout: 6e4 }, (error, _stdout, stderr) => {
|