@adhdev/daemon-core 0.9.49 → 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 +471 -402
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +467 -398
- 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 +78 -1
- package/src/commands/handler.ts +1 -0
- package/src/commands/router.ts +12 -2
package/dist/index.js
CHANGED
|
@@ -1340,11 +1340,11 @@ function loadNodePty() {
|
|
|
1340
1340
|
}
|
|
1341
1341
|
return cachedPty;
|
|
1342
1342
|
}
|
|
1343
|
-
var
|
|
1343
|
+
var os8, cachedPty, NodePtyRuntimeTransport, NodePtyTransportFactory;
|
|
1344
1344
|
var init_pty_transport = __esm({
|
|
1345
1345
|
"src/cli-adapters/pty-transport.ts"() {
|
|
1346
1346
|
"use strict";
|
|
1347
|
-
|
|
1347
|
+
os8 = __toESM(require("os"));
|
|
1348
1348
|
init_spawn_env();
|
|
1349
1349
|
NodePtyRuntimeTransport = class {
|
|
1350
1350
|
constructor(handle) {
|
|
@@ -1381,11 +1381,11 @@ var init_pty_transport = __esm({
|
|
|
1381
1381
|
let cwd = options.cwd;
|
|
1382
1382
|
if (cwd) {
|
|
1383
1383
|
try {
|
|
1384
|
-
const
|
|
1385
|
-
const stat =
|
|
1386
|
-
if (!stat.isDirectory()) cwd =
|
|
1384
|
+
const fs16 = require("fs");
|
|
1385
|
+
const stat = fs16.statSync(cwd);
|
|
1386
|
+
if (!stat.isDirectory()) cwd = os8.homedir();
|
|
1387
1387
|
} catch {
|
|
1388
|
-
cwd =
|
|
1388
|
+
cwd = os8.homedir();
|
|
1389
1389
|
}
|
|
1390
1390
|
}
|
|
1391
1391
|
const handle = pty.spawn(command, args, {
|
|
@@ -1465,11 +1465,11 @@ function buildCliScreenSnapshot(text) {
|
|
|
1465
1465
|
function findBinary(name) {
|
|
1466
1466
|
const trimmed = String(name || "").trim();
|
|
1467
1467
|
if (!trimmed) return trimmed;
|
|
1468
|
-
const expanded = trimmed.startsWith("~") ?
|
|
1469
|
-
if (
|
|
1470
|
-
return
|
|
1468
|
+
const expanded = trimmed.startsWith("~") ? path10.join(os9.homedir(), trimmed.slice(1)) : trimmed;
|
|
1469
|
+
if (path10.isAbsolute(expanded) || expanded.includes("/") || expanded.includes("\\")) {
|
|
1470
|
+
return path10.isAbsolute(expanded) ? expanded : path10.resolve(expanded);
|
|
1471
1471
|
}
|
|
1472
|
-
const isWin =
|
|
1472
|
+
const isWin = os9.platform() === "win32";
|
|
1473
1473
|
try {
|
|
1474
1474
|
const cmd = isWin ? `where ${trimmed}` : `which ${trimmed}`;
|
|
1475
1475
|
return (0, import_child_process4.execSync)(cmd, {
|
|
@@ -1483,14 +1483,14 @@ function findBinary(name) {
|
|
|
1483
1483
|
}
|
|
1484
1484
|
}
|
|
1485
1485
|
function isScriptBinary(binaryPath) {
|
|
1486
|
-
if (!
|
|
1486
|
+
if (!path10.isAbsolute(binaryPath)) return false;
|
|
1487
1487
|
try {
|
|
1488
|
-
const
|
|
1489
|
-
const resolved =
|
|
1488
|
+
const fs16 = require("fs");
|
|
1489
|
+
const resolved = fs16.realpathSync(binaryPath);
|
|
1490
1490
|
const head = Buffer.alloc(8);
|
|
1491
|
-
const fd =
|
|
1492
|
-
|
|
1493
|
-
|
|
1491
|
+
const fd = fs16.openSync(resolved, "r");
|
|
1492
|
+
fs16.readSync(fd, head, 0, 8, 0);
|
|
1493
|
+
fs16.closeSync(fd);
|
|
1494
1494
|
let i = 0;
|
|
1495
1495
|
if (head[0] === 239 && head[1] === 187 && head[2] === 191) i = 3;
|
|
1496
1496
|
return head[i] === 35 && head[i + 1] === 33;
|
|
@@ -1499,14 +1499,14 @@ function isScriptBinary(binaryPath) {
|
|
|
1499
1499
|
}
|
|
1500
1500
|
}
|
|
1501
1501
|
function looksLikeMachOOrElf(filePath) {
|
|
1502
|
-
if (!
|
|
1502
|
+
if (!path10.isAbsolute(filePath)) return false;
|
|
1503
1503
|
try {
|
|
1504
|
-
const
|
|
1505
|
-
const resolved =
|
|
1504
|
+
const fs16 = require("fs");
|
|
1505
|
+
const resolved = fs16.realpathSync(filePath);
|
|
1506
1506
|
const buf = Buffer.alloc(8);
|
|
1507
|
-
const fd =
|
|
1508
|
-
|
|
1509
|
-
|
|
1507
|
+
const fd = fs16.openSync(resolved, "r");
|
|
1508
|
+
fs16.readSync(fd, buf, 0, 8, 0);
|
|
1509
|
+
fs16.closeSync(fd);
|
|
1510
1510
|
let i = 0;
|
|
1511
1511
|
if (buf[0] === 239 && buf[1] === 187 && buf[2] === 191) i = 3;
|
|
1512
1512
|
const b = buf.subarray(i);
|
|
@@ -1522,7 +1522,7 @@ function looksLikeMachOOrElf(filePath) {
|
|
|
1522
1522
|
}
|
|
1523
1523
|
function shSingleQuote(arg) {
|
|
1524
1524
|
if (/^[a-zA-Z0-9@%_+=:,./-]+$/.test(arg)) return arg;
|
|
1525
|
-
if (
|
|
1525
|
+
if (os9.platform() === "win32") {
|
|
1526
1526
|
return `"${arg.replace(/"/g, '""')}"`;
|
|
1527
1527
|
}
|
|
1528
1528
|
return `'${arg.replace(/'/g, `'\\''`)}'`;
|
|
@@ -1649,12 +1649,12 @@ function normalizeCliProviderForRuntime(raw) {
|
|
|
1649
1649
|
}
|
|
1650
1650
|
};
|
|
1651
1651
|
}
|
|
1652
|
-
var
|
|
1652
|
+
var os9, path10, import_child_process4, buildCliSpawnEnv, COMMON_COMPARABLE_WRAP_WORDS;
|
|
1653
1653
|
var init_provider_cli_shared = __esm({
|
|
1654
1654
|
"src/cli-adapters/provider-cli-shared.ts"() {
|
|
1655
1655
|
"use strict";
|
|
1656
|
-
|
|
1657
|
-
|
|
1656
|
+
os9 = __toESM(require("os"));
|
|
1657
|
+
path10 = __toESM(require("path"));
|
|
1658
1658
|
import_child_process4 = require("child_process");
|
|
1659
1659
|
init_spawn_env();
|
|
1660
1660
|
buildCliSpawnEnv = import_session_host_core.sanitizeSpawnEnv;
|
|
@@ -1967,13 +1967,13 @@ function resolveCliSpawnPlan(options) {
|
|
|
1967
1967
|
const { spawn: spawnConfig } = provider;
|
|
1968
1968
|
const configuredCommand = typeof runtimeSettings.executablePath === "string" && runtimeSettings.executablePath.trim() ? runtimeSettings.executablePath.trim() : spawnConfig.command;
|
|
1969
1969
|
const binaryPath = findBinary(configuredCommand);
|
|
1970
|
-
const isWin =
|
|
1970
|
+
const isWin = os10.platform() === "win32";
|
|
1971
1971
|
const allArgs = [...spawnConfig.args, ...extraArgs];
|
|
1972
1972
|
let shellCmd;
|
|
1973
1973
|
let shellArgs;
|
|
1974
|
-
const useShellUnix = !isWin && (!!spawnConfig.shell || !
|
|
1974
|
+
const useShellUnix = !isWin && (!!spawnConfig.shell || !path11.isAbsolute(binaryPath) || isScriptBinary(binaryPath) || !looksLikeMachOOrElf(binaryPath));
|
|
1975
1975
|
const isCmdShim = isWin && /\.(cmd|bat)$/i.test(binaryPath);
|
|
1976
|
-
const useShellWin = !!spawnConfig.shell || isCmdShim || !
|
|
1976
|
+
const useShellWin = !!spawnConfig.shell || isCmdShim || !path11.isAbsolute(binaryPath) || isScriptBinary(binaryPath);
|
|
1977
1977
|
const useShell = isWin ? useShellWin : useShellUnix;
|
|
1978
1978
|
if (useShell) {
|
|
1979
1979
|
shellCmd = isWin ? "cmd.exe" : process.env.SHELL || "/bin/zsh";
|
|
@@ -2049,12 +2049,12 @@ function respondToCliTerminalQueries(options) {
|
|
|
2049
2049
|
}
|
|
2050
2050
|
return "";
|
|
2051
2051
|
}
|
|
2052
|
-
var
|
|
2052
|
+
var os10, path11, import_session_host_core2;
|
|
2053
2053
|
var init_provider_cli_runtime = __esm({
|
|
2054
2054
|
"src/cli-adapters/provider-cli-runtime.ts"() {
|
|
2055
2055
|
"use strict";
|
|
2056
|
-
|
|
2057
|
-
|
|
2056
|
+
os10 = __toESM(require("os"));
|
|
2057
|
+
path11 = __toESM(require("path"));
|
|
2058
2058
|
import_session_host_core2 = require("@adhdev/session-host-core");
|
|
2059
2059
|
init_provider_cli_shared();
|
|
2060
2060
|
}
|
|
@@ -2176,11 +2176,11 @@ function trimLastAssistantEchoForCliMessages(messages, prompt) {
|
|
|
2176
2176
|
return;
|
|
2177
2177
|
}
|
|
2178
2178
|
}
|
|
2179
|
-
var
|
|
2179
|
+
var os11, COMMITTED_ACTIVITY_PREFIX_BLOCK_RE, ProviderCliAdapter;
|
|
2180
2180
|
var init_provider_cli_adapter = __esm({
|
|
2181
2181
|
"src/cli-adapters/provider-cli-adapter.ts"() {
|
|
2182
2182
|
"use strict";
|
|
2183
|
-
|
|
2183
|
+
os11 = __toESM(require("os"));
|
|
2184
2184
|
init_logger();
|
|
2185
2185
|
init_debug_config();
|
|
2186
2186
|
init_terminal_screen();
|
|
@@ -2200,7 +2200,7 @@ var init_provider_cli_adapter = __esm({
|
|
|
2200
2200
|
this.transportFactory = transportFactory;
|
|
2201
2201
|
this.cliType = provider.type;
|
|
2202
2202
|
this.cliName = provider.name;
|
|
2203
|
-
this.workingDir = workingDir.startsWith("~") ? workingDir.replace(/^~/,
|
|
2203
|
+
this.workingDir = workingDir.startsWith("~") ? workingDir.replace(/^~/, os11.homedir()) : workingDir;
|
|
2204
2204
|
const resolvedConfig = resolveCliAdapterConfig(provider);
|
|
2205
2205
|
this.timeouts = resolvedConfig.timeouts;
|
|
2206
2206
|
this.approvalKeys = resolvedConfig.approvalKeys;
|
|
@@ -5275,17 +5275,17 @@ function checkPathExists(paths) {
|
|
|
5275
5275
|
return null;
|
|
5276
5276
|
}
|
|
5277
5277
|
async function detectIDEs(providerLoader) {
|
|
5278
|
-
const
|
|
5278
|
+
const os21 = (0, import_os2.platform)();
|
|
5279
5279
|
const results = [];
|
|
5280
5280
|
for (const def of getMergedDefinitions()) {
|
|
5281
5281
|
const cliPath = findCliCommand(providerLoader?.getIdeCliCommand(def.id, def.cli) || def.cli);
|
|
5282
|
-
const appPath = checkPathExists(providerLoader?.getIdePathCandidates(def.id, def.paths[
|
|
5282
|
+
const appPath = checkPathExists(providerLoader?.getIdePathCandidates(def.id, def.paths[os21] || []) || []);
|
|
5283
5283
|
let resolvedCli = cliPath;
|
|
5284
|
-
if (!resolvedCli && appPath &&
|
|
5284
|
+
if (!resolvedCli && appPath && os21 === "darwin") {
|
|
5285
5285
|
const bundledCli = `${appPath}/Contents/Resources/app/bin/${def.cli}`;
|
|
5286
5286
|
if ((0, import_fs3.existsSync)(bundledCli)) resolvedCli = bundledCli;
|
|
5287
5287
|
}
|
|
5288
|
-
if (!resolvedCli && appPath &&
|
|
5288
|
+
if (!resolvedCli && appPath && os21 === "win32") {
|
|
5289
5289
|
const { dirname: dirname7 } = await import("path");
|
|
5290
5290
|
const appDir = dirname7(appPath);
|
|
5291
5291
|
const candidates = [
|
|
@@ -5302,7 +5302,7 @@ async function detectIDEs(providerLoader) {
|
|
|
5302
5302
|
}
|
|
5303
5303
|
}
|
|
5304
5304
|
}
|
|
5305
|
-
const installed =
|
|
5305
|
+
const installed = os21 === "darwin" ? !!(resolvedCli || appPath) : !!resolvedCli;
|
|
5306
5306
|
const version = resolvedCli ? getIdeVersion(resolvedCli) : null;
|
|
5307
5307
|
results.push({
|
|
5308
5308
|
id: def.id,
|
|
@@ -10466,6 +10466,10 @@ function resolveLegacyProviderScript(fn, scriptName, params) {
|
|
|
10466
10466
|
}
|
|
10467
10467
|
|
|
10468
10468
|
// src/commands/chat-commands.ts
|
|
10469
|
+
var fs4 = __toESM(require("fs"));
|
|
10470
|
+
var os6 = __toESM(require("os"));
|
|
10471
|
+
var path8 = __toESM(require("path"));
|
|
10472
|
+
var import_node_crypto = require("crypto");
|
|
10469
10473
|
init_contracts();
|
|
10470
10474
|
|
|
10471
10475
|
// src/providers/provider-input-support.ts
|
|
@@ -11155,10 +11159,57 @@ function buildDebugBundleText(bundle) {
|
|
|
11155
11159
|
"```"
|
|
11156
11160
|
].join("\n");
|
|
11157
11161
|
}
|
|
11162
|
+
function getChatDebugBundleDir() {
|
|
11163
|
+
const override = typeof process.env.ADHDEV_DEBUG_BUNDLE_DIR === "string" ? process.env.ADHDEV_DEBUG_BUNDLE_DIR.trim() : "";
|
|
11164
|
+
return override || path8.join(os6.homedir(), ".adhdev", "debug-bundles", "chat");
|
|
11165
|
+
}
|
|
11166
|
+
function safeBundleIdSegment(value, fallback) {
|
|
11167
|
+
const normalized = String(value || fallback).trim().replace(/[^A-Za-z0-9_.-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 80);
|
|
11168
|
+
return normalized || fallback;
|
|
11169
|
+
}
|
|
11170
|
+
function createChatDebugBundleId(targetSessionId) {
|
|
11171
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[-:.]/g, "").replace("T", "T").replace("Z", "Z");
|
|
11172
|
+
const sessionSegment = safeBundleIdSegment(targetSessionId, "unknown-session");
|
|
11173
|
+
return `chat-debug-${timestamp}-${sessionSegment}-${(0, import_node_crypto.randomUUID)().slice(0, 8)}`;
|
|
11174
|
+
}
|
|
11175
|
+
function buildChatDebugBundleSummary(bundle) {
|
|
11176
|
+
const target = bundle.target && typeof bundle.target === "object" ? bundle.target : {};
|
|
11177
|
+
const readChat = bundle.readChat && typeof bundle.readChat === "object" ? bundle.readChat : {};
|
|
11178
|
+
const cli = bundle.cli && typeof bundle.cli === "object" ? bundle.cli : null;
|
|
11179
|
+
const frontend = bundle.frontend && typeof bundle.frontend === "object" ? bundle.frontend : null;
|
|
11180
|
+
return {
|
|
11181
|
+
createdAt: bundle.createdAt,
|
|
11182
|
+
targetSessionId: target.targetSessionId,
|
|
11183
|
+
providerType: target.providerType,
|
|
11184
|
+
transport: target.transport,
|
|
11185
|
+
readChatSuccess: readChat.success,
|
|
11186
|
+
readChatStatus: readChat.status,
|
|
11187
|
+
readChatTotalMessages: readChat.totalMessages,
|
|
11188
|
+
cliStatus: cli?.status,
|
|
11189
|
+
cliMessageCount: cli?.messageCount,
|
|
11190
|
+
hasFrontendSnapshot: !!frontend
|
|
11191
|
+
};
|
|
11192
|
+
}
|
|
11193
|
+
function storeChatDebugBundleOnDaemon(bundle, targetSessionId) {
|
|
11194
|
+
const bundleId = createChatDebugBundleId(targetSessionId);
|
|
11195
|
+
const dir = getChatDebugBundleDir();
|
|
11196
|
+
fs4.mkdirSync(dir, { recursive: true });
|
|
11197
|
+
const savedPath = path8.join(dir, `${bundleId}.json`);
|
|
11198
|
+
const json = `${JSON.stringify(bundle, null, 2)}
|
|
11199
|
+
`;
|
|
11200
|
+
fs4.writeFileSync(savedPath, json, { encoding: "utf8", mode: 384 });
|
|
11201
|
+
return { bundleId, savedPath, sizeBytes: Buffer.byteLength(json, "utf8") };
|
|
11202
|
+
}
|
|
11203
|
+
function isDaemonFileDebugDelivery(args) {
|
|
11204
|
+
return args?.delivery === "daemon_file" || args?.delivery === "file";
|
|
11205
|
+
}
|
|
11158
11206
|
async function handleGetChatDebugBundle(h, args) {
|
|
11207
|
+
const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
|
|
11208
|
+
if (!targetSessionId && !h.currentSession) {
|
|
11209
|
+
return { success: false, error: "No targetSessionId specified \u2014 cannot route command" };
|
|
11210
|
+
}
|
|
11159
11211
|
const provider = h.getProvider(args?.agentType);
|
|
11160
11212
|
const transport = getTargetTransport(h, provider);
|
|
11161
|
-
const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
|
|
11162
11213
|
const providerType = provider?.type || getCurrentProviderType(h, args?.agentType || "");
|
|
11163
11214
|
const adapter = isCliLikeTransport(transport) ? getTargetedCliAdapter(h, args, provider?.type) : null;
|
|
11164
11215
|
const targetInstance = getTargetInstance(h, args);
|
|
@@ -11263,6 +11314,20 @@ async function handleGetChatDebugBundle(h, args) {
|
|
|
11263
11314
|
recentDebugTrace: getRecentDebugTrace({ limit: 120 })
|
|
11264
11315
|
};
|
|
11265
11316
|
const bundle = sanitizeDebugBundleValue(rawBundle);
|
|
11317
|
+
if (isDaemonFileDebugDelivery(args)) {
|
|
11318
|
+
const summary = buildChatDebugBundleSummary(bundle);
|
|
11319
|
+
const stored = storeChatDebugBundleOnDaemon(bundle, targetSessionId || String(summary.targetSessionId || "unknown-session"));
|
|
11320
|
+
LOG.info("Command", `[get_chat_debug_bundle] saved daemon_file bundle id=${stored.bundleId} path=${stored.savedPath} sizeBytes=${stored.sizeBytes} targetSessionId=${summary.targetSessionId || ""} providerType=${summary.providerType || ""} transport=${summary.transport || ""}`);
|
|
11321
|
+
return {
|
|
11322
|
+
success: true,
|
|
11323
|
+
delivery: "daemon_file",
|
|
11324
|
+
bundleId: stored.bundleId,
|
|
11325
|
+
savedPath: stored.savedPath,
|
|
11326
|
+
sizeBytes: stored.sizeBytes,
|
|
11327
|
+
createdAt: bundle.createdAt,
|
|
11328
|
+
summary
|
|
11329
|
+
};
|
|
11330
|
+
}
|
|
11266
11331
|
return {
|
|
11267
11332
|
success: true,
|
|
11268
11333
|
bundle,
|
|
@@ -12244,9 +12309,9 @@ async function handleResolveAction(h, args) {
|
|
|
12244
12309
|
}
|
|
12245
12310
|
|
|
12246
12311
|
// src/commands/cdp-commands.ts
|
|
12247
|
-
var
|
|
12248
|
-
var
|
|
12249
|
-
var
|
|
12312
|
+
var fs5 = __toESM(require("fs"));
|
|
12313
|
+
var path9 = __toESM(require("path"));
|
|
12314
|
+
var os7 = __toESM(require("os"));
|
|
12250
12315
|
var KEY_TO_VK = {
|
|
12251
12316
|
Backspace: 8,
|
|
12252
12317
|
Tab: 9,
|
|
@@ -12500,27 +12565,27 @@ function normalizeWindowsRequestedPath(requestedPath) {
|
|
|
12500
12565
|
function resolveSafePath(requestedPath) {
|
|
12501
12566
|
const rawPath = typeof requestedPath === "string" ? requestedPath.trim() : "";
|
|
12502
12567
|
const inputPath = rawPath || ".";
|
|
12503
|
-
const home =
|
|
12568
|
+
const home = os7.homedir();
|
|
12504
12569
|
if (inputPath.startsWith("~")) {
|
|
12505
|
-
return
|
|
12570
|
+
return path9.resolve(path9.join(home, inputPath.slice(1)));
|
|
12506
12571
|
}
|
|
12507
12572
|
if (process.platform === "win32") {
|
|
12508
12573
|
const normalized = normalizeWindowsRequestedPath(inputPath);
|
|
12509
|
-
if (
|
|
12510
|
-
return
|
|
12574
|
+
if (path9.win32.isAbsolute(normalized)) {
|
|
12575
|
+
return path9.win32.normalize(normalized);
|
|
12511
12576
|
}
|
|
12512
|
-
return
|
|
12577
|
+
return path9.win32.resolve(normalized);
|
|
12513
12578
|
}
|
|
12514
|
-
if (
|
|
12515
|
-
return
|
|
12579
|
+
if (path9.isAbsolute(inputPath)) {
|
|
12580
|
+
return path9.normalize(inputPath);
|
|
12516
12581
|
}
|
|
12517
|
-
return
|
|
12582
|
+
return path9.resolve(inputPath);
|
|
12518
12583
|
}
|
|
12519
12584
|
function listDirectoryEntriesSafe(dirPath) {
|
|
12520
|
-
const entries =
|
|
12585
|
+
const entries = fs5.readdirSync(dirPath, { withFileTypes: true });
|
|
12521
12586
|
const files = [];
|
|
12522
12587
|
for (const entry of entries) {
|
|
12523
|
-
const entryPath =
|
|
12588
|
+
const entryPath = path9.join(dirPath, entry.name);
|
|
12524
12589
|
try {
|
|
12525
12590
|
if (entry.isDirectory()) {
|
|
12526
12591
|
files.push({ name: entry.name, type: "directory" });
|
|
@@ -12529,14 +12594,14 @@ function listDirectoryEntriesSafe(dirPath) {
|
|
|
12529
12594
|
if (entry.isFile()) {
|
|
12530
12595
|
let size;
|
|
12531
12596
|
try {
|
|
12532
|
-
size =
|
|
12597
|
+
size = fs5.statSync(entryPath).size;
|
|
12533
12598
|
} catch {
|
|
12534
12599
|
size = void 0;
|
|
12535
12600
|
}
|
|
12536
12601
|
files.push({ name: entry.name, type: "file", size });
|
|
12537
12602
|
continue;
|
|
12538
12603
|
}
|
|
12539
|
-
const stat =
|
|
12604
|
+
const stat = fs5.statSync(entryPath);
|
|
12540
12605
|
files.push({
|
|
12541
12606
|
name: entry.name,
|
|
12542
12607
|
type: stat.isDirectory() ? "directory" : "file",
|
|
@@ -12554,7 +12619,7 @@ function listWindowsDriveEntries(excludePath) {
|
|
|
12554
12619
|
const letter = String.fromCharCode(code);
|
|
12555
12620
|
const root = `${letter}:\\`;
|
|
12556
12621
|
try {
|
|
12557
|
-
if (!
|
|
12622
|
+
if (!fs5.existsSync(root)) continue;
|
|
12558
12623
|
if (excluded && root.toLowerCase() === excluded) continue;
|
|
12559
12624
|
drives.push({ name: `${letter}:`, type: "directory", path: root });
|
|
12560
12625
|
} catch {
|
|
@@ -12565,7 +12630,7 @@ function listWindowsDriveEntries(excludePath) {
|
|
|
12565
12630
|
async function handleFileRead(h, args) {
|
|
12566
12631
|
try {
|
|
12567
12632
|
const filePath = resolveSafePath(args?.path);
|
|
12568
|
-
const content =
|
|
12633
|
+
const content = fs5.readFileSync(filePath, "utf-8");
|
|
12569
12634
|
return { success: true, content, path: filePath };
|
|
12570
12635
|
} catch (e) {
|
|
12571
12636
|
return { success: false, error: e.message };
|
|
@@ -12574,8 +12639,8 @@ async function handleFileRead(h, args) {
|
|
|
12574
12639
|
async function handleFileWrite(h, args) {
|
|
12575
12640
|
try {
|
|
12576
12641
|
const filePath = resolveSafePath(args?.path);
|
|
12577
|
-
|
|
12578
|
-
|
|
12642
|
+
fs5.mkdirSync(path9.dirname(filePath), { recursive: true });
|
|
12643
|
+
fs5.writeFileSync(filePath, args?.content || "", "utf-8");
|
|
12579
12644
|
return { success: true, path: filePath };
|
|
12580
12645
|
} catch (e) {
|
|
12581
12646
|
return { success: false, error: e.message };
|
|
@@ -13418,6 +13483,7 @@ var DaemonCommandHandler = class {
|
|
|
13418
13483
|
this.logCommandStart(cmd, args);
|
|
13419
13484
|
const sessionScopedCommands = /* @__PURE__ */ new Set([
|
|
13420
13485
|
"read_chat",
|
|
13486
|
+
"get_chat_debug_bundle",
|
|
13421
13487
|
"send_chat",
|
|
13422
13488
|
"list_chats",
|
|
13423
13489
|
"new_chat",
|
|
@@ -13675,8 +13741,8 @@ var DaemonCommandHandler = class {
|
|
|
13675
13741
|
};
|
|
13676
13742
|
|
|
13677
13743
|
// src/commands/cli-manager.ts
|
|
13678
|
-
var
|
|
13679
|
-
var
|
|
13744
|
+
var os13 = __toESM(require("os"));
|
|
13745
|
+
var path13 = __toESM(require("path"));
|
|
13680
13746
|
var crypto4 = __toESM(require("crypto"));
|
|
13681
13747
|
var import_fs5 = require("fs");
|
|
13682
13748
|
var import_child_process6 = require("child_process");
|
|
@@ -13685,10 +13751,10 @@ init_provider_cli_adapter();
|
|
|
13685
13751
|
init_config();
|
|
13686
13752
|
|
|
13687
13753
|
// src/providers/cli-provider-instance.ts
|
|
13688
|
-
var
|
|
13689
|
-
var
|
|
13754
|
+
var os12 = __toESM(require("os"));
|
|
13755
|
+
var path12 = __toESM(require("path"));
|
|
13690
13756
|
var crypto3 = __toESM(require("crypto"));
|
|
13691
|
-
var
|
|
13757
|
+
var fs6 = __toESM(require("fs"));
|
|
13692
13758
|
var import_node_module = require("module");
|
|
13693
13759
|
init_contracts();
|
|
13694
13760
|
init_provider_cli_adapter();
|
|
@@ -13747,7 +13813,7 @@ function buildIncrementalHistoryAppendMessages(previousMessages, currentMessages
|
|
|
13747
13813
|
var CachedDatabaseSync = null;
|
|
13748
13814
|
function getDatabaseSync() {
|
|
13749
13815
|
if (CachedDatabaseSync) return CachedDatabaseSync;
|
|
13750
|
-
const requireFn = typeof require === "function" ? require : (0, import_node_module.createRequire)(
|
|
13816
|
+
const requireFn = typeof require === "function" ? require : (0, import_node_module.createRequire)(path12.join(process.cwd(), "__adhdev_sqlite_loader__.js"));
|
|
13751
13817
|
const sqliteModule = requireFn(`node:${"sqlite"}`);
|
|
13752
13818
|
CachedDatabaseSync = sqliteModule.DatabaseSync;
|
|
13753
13819
|
if (!CachedDatabaseSync) {
|
|
@@ -13897,10 +13963,10 @@ var CliProviderInstance = class {
|
|
|
13897
13963
|
* Replaces the previously duplicated probeOpenCode/Codex/Goose functions.
|
|
13898
13964
|
*/
|
|
13899
13965
|
probeSessionIdFromConfig(probe) {
|
|
13900
|
-
const resolvedDbPath = probe.dbPath.replace(/^~/,
|
|
13966
|
+
const resolvedDbPath = probe.dbPath.replace(/^~/, os12.homedir());
|
|
13901
13967
|
const now = Date.now();
|
|
13902
13968
|
if (this.cachedSqliteDbMissingUntil > now) return null;
|
|
13903
|
-
if (!
|
|
13969
|
+
if (!fs6.existsSync(resolvedDbPath)) {
|
|
13904
13970
|
this.cachedSqliteDbMissingUntil = now + 1e4;
|
|
13905
13971
|
return null;
|
|
13906
13972
|
}
|
|
@@ -14632,7 +14698,7 @@ ${effect.notification.body || ""}`.trim();
|
|
|
14632
14698
|
};
|
|
14633
14699
|
addDir(this.workingDir);
|
|
14634
14700
|
try {
|
|
14635
|
-
addDir(
|
|
14701
|
+
addDir(fs6.realpathSync.native(this.workingDir));
|
|
14636
14702
|
} catch {
|
|
14637
14703
|
}
|
|
14638
14704
|
return Array.from(dirs);
|
|
@@ -15831,11 +15897,11 @@ function shouldRestoreHostedRuntime(record, managerTag) {
|
|
|
15831
15897
|
// src/commands/cli-manager.ts
|
|
15832
15898
|
function isExplicitCommand(command) {
|
|
15833
15899
|
const trimmed = command.trim();
|
|
15834
|
-
return
|
|
15900
|
+
return path13.isAbsolute(trimmed) || trimmed.includes("/") || trimmed.includes("\\") || trimmed.startsWith("~");
|
|
15835
15901
|
}
|
|
15836
15902
|
function expandExecutable(command) {
|
|
15837
15903
|
const trimmed = command.trim();
|
|
15838
|
-
return trimmed.startsWith("~") ?
|
|
15904
|
+
return trimmed.startsWith("~") ? path13.join(os13.homedir(), trimmed.slice(1)) : trimmed;
|
|
15839
15905
|
}
|
|
15840
15906
|
function commandExists(command) {
|
|
15841
15907
|
const trimmed = command.trim();
|
|
@@ -16116,7 +16182,7 @@ var DaemonCliManager = class {
|
|
|
16116
16182
|
async startSession(cliType, workingDir, cliArgs, initialModel, options) {
|
|
16117
16183
|
const trimmed = (workingDir || "").trim();
|
|
16118
16184
|
if (!trimmed) throw new Error("working directory required");
|
|
16119
|
-
const resolvedDir = trimmed.startsWith("~") ? trimmed.replace(/^~/,
|
|
16185
|
+
const resolvedDir = trimmed.startsWith("~") ? trimmed.replace(/^~/, os13.homedir()) : path13.resolve(trimmed);
|
|
16120
16186
|
const normalizedType = this.providerLoader.resolveAlias(cliType);
|
|
16121
16187
|
const rawProvider = this.providerLoader.getByAlias(cliType);
|
|
16122
16188
|
const provider = rawProvider ? this.providerLoader.resolve(normalizedType) || rawProvider : void 0;
|
|
@@ -16616,13 +16682,13 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
16616
16682
|
// src/launch.ts
|
|
16617
16683
|
var import_child_process7 = require("child_process");
|
|
16618
16684
|
var net = __toESM(require("net"));
|
|
16619
|
-
var
|
|
16620
|
-
var
|
|
16685
|
+
var os15 = __toESM(require("os"));
|
|
16686
|
+
var path15 = __toESM(require("path"));
|
|
16621
16687
|
|
|
16622
16688
|
// src/providers/provider-loader.ts
|
|
16623
|
-
var
|
|
16624
|
-
var
|
|
16625
|
-
var
|
|
16689
|
+
var fs7 = __toESM(require("fs"));
|
|
16690
|
+
var path14 = __toESM(require("path"));
|
|
16691
|
+
var os14 = __toESM(require("os"));
|
|
16626
16692
|
var chokidar = __toESM(require("chokidar"));
|
|
16627
16693
|
init_logger();
|
|
16628
16694
|
|
|
@@ -16884,9 +16950,9 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
16884
16950
|
static siblingStderrLogged = /* @__PURE__ */ new Set();
|
|
16885
16951
|
static looksLikeProviderRoot(candidate) {
|
|
16886
16952
|
try {
|
|
16887
|
-
if (!
|
|
16953
|
+
if (!fs7.existsSync(candidate) || !fs7.statSync(candidate).isDirectory()) return false;
|
|
16888
16954
|
return ["ide", "extension", "cli", "acp"].some(
|
|
16889
|
-
(category) =>
|
|
16955
|
+
(category) => fs7.existsSync(path14.join(candidate, category))
|
|
16890
16956
|
);
|
|
16891
16957
|
} catch {
|
|
16892
16958
|
return false;
|
|
@@ -16894,20 +16960,20 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
16894
16960
|
}
|
|
16895
16961
|
static hasProviderRootMarker(candidate) {
|
|
16896
16962
|
try {
|
|
16897
|
-
return
|
|
16963
|
+
return fs7.existsSync(path14.join(candidate, _ProviderLoader.SIBLING_MARKER_FILE));
|
|
16898
16964
|
} catch {
|
|
16899
16965
|
return false;
|
|
16900
16966
|
}
|
|
16901
16967
|
}
|
|
16902
16968
|
detectDefaultUserDir() {
|
|
16903
|
-
const fallback =
|
|
16969
|
+
const fallback = path14.join(os14.homedir(), ".adhdev", "providers");
|
|
16904
16970
|
const envOptIn = process.env[_ProviderLoader.SIBLING_ENV_VAR] === "1";
|
|
16905
16971
|
const visited = /* @__PURE__ */ new Set();
|
|
16906
16972
|
for (const start of this.probeStarts) {
|
|
16907
|
-
let current =
|
|
16973
|
+
let current = path14.resolve(start);
|
|
16908
16974
|
while (!visited.has(current)) {
|
|
16909
16975
|
visited.add(current);
|
|
16910
|
-
const siblingCandidate =
|
|
16976
|
+
const siblingCandidate = path14.join(path14.dirname(current), _ProviderLoader.REPO_PROVIDER_DIRNAME);
|
|
16911
16977
|
if (_ProviderLoader.looksLikeProviderRoot(siblingCandidate)) {
|
|
16912
16978
|
const hasMarker = _ProviderLoader.hasProviderRootMarker(siblingCandidate);
|
|
16913
16979
|
if (envOptIn || hasMarker) {
|
|
@@ -16929,7 +16995,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
16929
16995
|
return { path: siblingCandidate, source };
|
|
16930
16996
|
}
|
|
16931
16997
|
}
|
|
16932
|
-
const parent =
|
|
16998
|
+
const parent = path14.dirname(current);
|
|
16933
16999
|
if (parent === current) break;
|
|
16934
17000
|
current = parent;
|
|
16935
17001
|
}
|
|
@@ -16939,11 +17005,11 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
16939
17005
|
constructor(options) {
|
|
16940
17006
|
this.logFn = options?.logFn || LOG.forComponent("Provider").asLogFn();
|
|
16941
17007
|
this.probeStarts = options?.probeStarts ?? [process.cwd(), __dirname];
|
|
16942
|
-
this.defaultProvidersDir =
|
|
17008
|
+
this.defaultProvidersDir = path14.join(os14.homedir(), ".adhdev", "providers");
|
|
16943
17009
|
const detected = this.detectDefaultUserDir();
|
|
16944
17010
|
this.userDir = detected.path;
|
|
16945
17011
|
this.userDirSource = detected.source;
|
|
16946
|
-
this.upstreamDir =
|
|
17012
|
+
this.upstreamDir = path14.join(this.defaultProvidersDir, ".upstream");
|
|
16947
17013
|
this.disableUpstream = false;
|
|
16948
17014
|
this.applySourceConfig({
|
|
16949
17015
|
userDir: options?.userDir,
|
|
@@ -17002,7 +17068,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17002
17068
|
this.userDir = detected.path;
|
|
17003
17069
|
this.userDirSource = detected.source;
|
|
17004
17070
|
}
|
|
17005
|
-
this.upstreamDir =
|
|
17071
|
+
this.upstreamDir = path14.join(this.defaultProvidersDir, ".upstream");
|
|
17006
17072
|
this.disableUpstream = this.sourceMode === "no-upstream";
|
|
17007
17073
|
if (this.explicitProviderDir) {
|
|
17008
17074
|
this.log(`Config 'providerDir' applied: ${this.userDir}`);
|
|
@@ -17016,7 +17082,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17016
17082
|
* Canonical provider directory shape for a given root.
|
|
17017
17083
|
*/
|
|
17018
17084
|
getProviderDir(root, category, type) {
|
|
17019
|
-
return
|
|
17085
|
+
return path14.join(root, category, type);
|
|
17020
17086
|
}
|
|
17021
17087
|
/**
|
|
17022
17088
|
* Canonical user override directory for a provider.
|
|
@@ -17043,7 +17109,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17043
17109
|
resolveProviderFile(type, ...segments) {
|
|
17044
17110
|
const dir = this.findProviderDirInternal(type);
|
|
17045
17111
|
if (!dir) return null;
|
|
17046
|
-
return
|
|
17112
|
+
return path14.join(dir, ...segments);
|
|
17047
17113
|
}
|
|
17048
17114
|
/**
|
|
17049
17115
|
* Load all providers (3-tier priority)
|
|
@@ -17056,7 +17122,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17056
17122
|
this.providers.clear();
|
|
17057
17123
|
this.providerAvailability.clear();
|
|
17058
17124
|
let upstreamCount = 0;
|
|
17059
|
-
if (!this.disableUpstream &&
|
|
17125
|
+
if (!this.disableUpstream && fs7.existsSync(this.upstreamDir)) {
|
|
17060
17126
|
upstreamCount = this.loadDir(this.upstreamDir);
|
|
17061
17127
|
if (upstreamCount > 0) {
|
|
17062
17128
|
this.log(`Loaded ${upstreamCount} upstream providers (auto-updated)`);
|
|
@@ -17064,7 +17130,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17064
17130
|
} else if (this.disableUpstream) {
|
|
17065
17131
|
this.log("Upstream loading disabled (sourceMode=no-upstream)");
|
|
17066
17132
|
}
|
|
17067
|
-
if (
|
|
17133
|
+
if (fs7.existsSync(this.userDir)) {
|
|
17068
17134
|
const userCount = this.loadDir(this.userDir, [".upstream"]);
|
|
17069
17135
|
if (userCount > 0) {
|
|
17070
17136
|
this.log(`Loaded ${userCount} user custom providers (never auto-updated)`);
|
|
@@ -17079,10 +17145,10 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17079
17145
|
* Check if upstream directory exists and has providers.
|
|
17080
17146
|
*/
|
|
17081
17147
|
hasUpstream() {
|
|
17082
|
-
if (!
|
|
17148
|
+
if (!fs7.existsSync(this.upstreamDir)) return false;
|
|
17083
17149
|
try {
|
|
17084
|
-
return
|
|
17085
|
-
(d) =>
|
|
17150
|
+
return fs7.readdirSync(this.upstreamDir).some(
|
|
17151
|
+
(d) => fs7.statSync(path14.join(this.upstreamDir, d)).isDirectory()
|
|
17086
17152
|
);
|
|
17087
17153
|
} catch {
|
|
17088
17154
|
return false;
|
|
@@ -17579,8 +17645,8 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17579
17645
|
resolved._resolvedScriptDir = entry.scriptDir;
|
|
17580
17646
|
resolved._resolvedScriptsSource = `compatibility:${entry.ideVersion}`;
|
|
17581
17647
|
if (providerDir) {
|
|
17582
|
-
const fullDir =
|
|
17583
|
-
resolved._resolvedScriptsPath =
|
|
17648
|
+
const fullDir = path14.join(providerDir, entry.scriptDir);
|
|
17649
|
+
resolved._resolvedScriptsPath = fs7.existsSync(path14.join(fullDir, "scripts.js")) ? path14.join(fullDir, "scripts.js") : fullDir;
|
|
17584
17650
|
}
|
|
17585
17651
|
matched = true;
|
|
17586
17652
|
}
|
|
@@ -17595,8 +17661,8 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17595
17661
|
resolved._resolvedScriptDir = base.defaultScriptDir;
|
|
17596
17662
|
resolved._resolvedScriptsSource = "defaultScriptDir:version_miss";
|
|
17597
17663
|
if (providerDir) {
|
|
17598
|
-
const fullDir =
|
|
17599
|
-
resolved._resolvedScriptsPath =
|
|
17664
|
+
const fullDir = path14.join(providerDir, base.defaultScriptDir);
|
|
17665
|
+
resolved._resolvedScriptsPath = fs7.existsSync(path14.join(fullDir, "scripts.js")) ? path14.join(fullDir, "scripts.js") : fullDir;
|
|
17600
17666
|
}
|
|
17601
17667
|
}
|
|
17602
17668
|
resolved._versionWarning = `Version ${currentVersion} not in compatibility matrix. Using default scripts.`;
|
|
@@ -17613,8 +17679,8 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17613
17679
|
resolved._resolvedScriptDir = dirOverride;
|
|
17614
17680
|
resolved._resolvedScriptsSource = `versions:${range}`;
|
|
17615
17681
|
if (providerDir) {
|
|
17616
|
-
const fullDir =
|
|
17617
|
-
resolved._resolvedScriptsPath =
|
|
17682
|
+
const fullDir = path14.join(providerDir, dirOverride);
|
|
17683
|
+
resolved._resolvedScriptsPath = fs7.existsSync(path14.join(fullDir, "scripts.js")) ? path14.join(fullDir, "scripts.js") : fullDir;
|
|
17618
17684
|
}
|
|
17619
17685
|
}
|
|
17620
17686
|
} else if (override.scripts) {
|
|
@@ -17630,8 +17696,8 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17630
17696
|
resolved._resolvedScriptDir = base.defaultScriptDir;
|
|
17631
17697
|
resolved._resolvedScriptsSource = "defaultScriptDir:no_version";
|
|
17632
17698
|
if (providerDir) {
|
|
17633
|
-
const fullDir =
|
|
17634
|
-
resolved._resolvedScriptsPath =
|
|
17699
|
+
const fullDir = path14.join(providerDir, base.defaultScriptDir);
|
|
17700
|
+
resolved._resolvedScriptsPath = fs7.existsSync(path14.join(fullDir, "scripts.js")) ? path14.join(fullDir, "scripts.js") : fullDir;
|
|
17635
17701
|
}
|
|
17636
17702
|
}
|
|
17637
17703
|
}
|
|
@@ -17663,15 +17729,15 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17663
17729
|
this.log(` [loadScriptsFromDir] ${type}: providerDir not found`);
|
|
17664
17730
|
return null;
|
|
17665
17731
|
}
|
|
17666
|
-
const dir =
|
|
17667
|
-
if (!
|
|
17732
|
+
const dir = path14.join(providerDir, scriptDir);
|
|
17733
|
+
if (!fs7.existsSync(dir)) {
|
|
17668
17734
|
this.log(` [loadScriptsFromDir] ${type}: dir not found: ${dir}`);
|
|
17669
17735
|
return null;
|
|
17670
17736
|
}
|
|
17671
17737
|
const cached = this.scriptsCache.get(dir);
|
|
17672
17738
|
if (cached) return cached;
|
|
17673
|
-
const scriptsJs =
|
|
17674
|
-
if (
|
|
17739
|
+
const scriptsJs = path14.join(dir, "scripts.js");
|
|
17740
|
+
if (fs7.existsSync(scriptsJs)) {
|
|
17675
17741
|
try {
|
|
17676
17742
|
delete require.cache[require.resolve(scriptsJs)];
|
|
17677
17743
|
const loaded = require(scriptsJs);
|
|
@@ -17692,9 +17758,9 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17692
17758
|
watch() {
|
|
17693
17759
|
this.stopWatch();
|
|
17694
17760
|
const watchDir = (dir) => {
|
|
17695
|
-
if (!
|
|
17761
|
+
if (!fs7.existsSync(dir)) {
|
|
17696
17762
|
try {
|
|
17697
|
-
|
|
17763
|
+
fs7.mkdirSync(dir, { recursive: true });
|
|
17698
17764
|
} catch {
|
|
17699
17765
|
return;
|
|
17700
17766
|
}
|
|
@@ -17712,7 +17778,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17712
17778
|
return;
|
|
17713
17779
|
}
|
|
17714
17780
|
if (filePath.endsWith(".js") || filePath.endsWith(".json")) {
|
|
17715
|
-
this.log(`File changed: ${
|
|
17781
|
+
this.log(`File changed: ${path14.basename(filePath)}, reloading...`);
|
|
17716
17782
|
this.reload();
|
|
17717
17783
|
}
|
|
17718
17784
|
};
|
|
@@ -17767,12 +17833,12 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17767
17833
|
}
|
|
17768
17834
|
const https = require("https");
|
|
17769
17835
|
const { execSync: execSync7 } = require("child_process");
|
|
17770
|
-
const metaPath =
|
|
17836
|
+
const metaPath = path14.join(this.upstreamDir, _ProviderLoader.META_FILE);
|
|
17771
17837
|
let prevEtag = "";
|
|
17772
17838
|
let prevTimestamp = 0;
|
|
17773
17839
|
try {
|
|
17774
|
-
if (
|
|
17775
|
-
const meta = JSON.parse(
|
|
17840
|
+
if (fs7.existsSync(metaPath)) {
|
|
17841
|
+
const meta = JSON.parse(fs7.readFileSync(metaPath, "utf-8"));
|
|
17776
17842
|
prevEtag = meta.etag || "";
|
|
17777
17843
|
prevTimestamp = meta.timestamp || 0;
|
|
17778
17844
|
}
|
|
@@ -17827,39 +17893,39 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17827
17893
|
return { updated: false };
|
|
17828
17894
|
}
|
|
17829
17895
|
this.log("Downloading latest providers from GitHub...");
|
|
17830
|
-
const tmpTar =
|
|
17831
|
-
const tmpExtract =
|
|
17896
|
+
const tmpTar = path14.join(os14.tmpdir(), `adhdev-providers-${Date.now()}.tar.gz`);
|
|
17897
|
+
const tmpExtract = path14.join(os14.tmpdir(), `adhdev-providers-extract-${Date.now()}`);
|
|
17832
17898
|
await this.downloadFile(_ProviderLoader.GITHUB_TARBALL_URL, tmpTar);
|
|
17833
|
-
|
|
17899
|
+
fs7.mkdirSync(tmpExtract, { recursive: true });
|
|
17834
17900
|
execSync7(`tar -xzf "${tmpTar}" -C "${tmpExtract}"`, { timeout: 3e4 });
|
|
17835
|
-
const extracted =
|
|
17901
|
+
const extracted = fs7.readdirSync(tmpExtract);
|
|
17836
17902
|
const rootDir = extracted.find(
|
|
17837
|
-
(d) =>
|
|
17903
|
+
(d) => fs7.statSync(path14.join(tmpExtract, d)).isDirectory() && d.startsWith("adhdev-providers")
|
|
17838
17904
|
);
|
|
17839
17905
|
if (!rootDir) throw new Error("Unexpected tarball structure");
|
|
17840
|
-
const sourceDir =
|
|
17906
|
+
const sourceDir = path14.join(tmpExtract, rootDir);
|
|
17841
17907
|
const backupDir = this.upstreamDir + ".bak";
|
|
17842
|
-
if (
|
|
17843
|
-
if (
|
|
17844
|
-
|
|
17908
|
+
if (fs7.existsSync(this.upstreamDir)) {
|
|
17909
|
+
if (fs7.existsSync(backupDir)) fs7.rmSync(backupDir, { recursive: true, force: true });
|
|
17910
|
+
fs7.renameSync(this.upstreamDir, backupDir);
|
|
17845
17911
|
}
|
|
17846
17912
|
try {
|
|
17847
17913
|
this.copyDirRecursive(sourceDir, this.upstreamDir);
|
|
17848
17914
|
this.writeMeta(metaPath, etag || `ts-${Date.now()}`, Date.now());
|
|
17849
|
-
if (
|
|
17915
|
+
if (fs7.existsSync(backupDir)) fs7.rmSync(backupDir, { recursive: true, force: true });
|
|
17850
17916
|
} catch (e) {
|
|
17851
|
-
if (
|
|
17852
|
-
if (
|
|
17853
|
-
|
|
17917
|
+
if (fs7.existsSync(backupDir)) {
|
|
17918
|
+
if (fs7.existsSync(this.upstreamDir)) fs7.rmSync(this.upstreamDir, { recursive: true, force: true });
|
|
17919
|
+
fs7.renameSync(backupDir, this.upstreamDir);
|
|
17854
17920
|
}
|
|
17855
17921
|
throw e;
|
|
17856
17922
|
}
|
|
17857
17923
|
try {
|
|
17858
|
-
|
|
17924
|
+
fs7.rmSync(tmpTar, { force: true });
|
|
17859
17925
|
} catch {
|
|
17860
17926
|
}
|
|
17861
17927
|
try {
|
|
17862
|
-
|
|
17928
|
+
fs7.rmSync(tmpExtract, { recursive: true, force: true });
|
|
17863
17929
|
} catch {
|
|
17864
17930
|
}
|
|
17865
17931
|
const upstreamCount = this.countProviders(this.upstreamDir);
|
|
@@ -17891,7 +17957,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17891
17957
|
reject(new Error(`HTTP ${res.statusCode}`));
|
|
17892
17958
|
return;
|
|
17893
17959
|
}
|
|
17894
|
-
const ws =
|
|
17960
|
+
const ws = fs7.createWriteStream(destPath);
|
|
17895
17961
|
res.pipe(ws);
|
|
17896
17962
|
ws.on("finish", () => {
|
|
17897
17963
|
ws.close();
|
|
@@ -17910,22 +17976,22 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17910
17976
|
}
|
|
17911
17977
|
/** Recursive directory copy */
|
|
17912
17978
|
copyDirRecursive(src, dest) {
|
|
17913
|
-
|
|
17914
|
-
for (const entry of
|
|
17915
|
-
const srcPath =
|
|
17916
|
-
const destPath =
|
|
17979
|
+
fs7.mkdirSync(dest, { recursive: true });
|
|
17980
|
+
for (const entry of fs7.readdirSync(src, { withFileTypes: true })) {
|
|
17981
|
+
const srcPath = path14.join(src, entry.name);
|
|
17982
|
+
const destPath = path14.join(dest, entry.name);
|
|
17917
17983
|
if (entry.isDirectory()) {
|
|
17918
17984
|
this.copyDirRecursive(srcPath, destPath);
|
|
17919
17985
|
} else {
|
|
17920
|
-
|
|
17986
|
+
fs7.copyFileSync(srcPath, destPath);
|
|
17921
17987
|
}
|
|
17922
17988
|
}
|
|
17923
17989
|
}
|
|
17924
17990
|
/** .meta.json save */
|
|
17925
17991
|
writeMeta(metaPath, etag, timestamp) {
|
|
17926
17992
|
try {
|
|
17927
|
-
|
|
17928
|
-
|
|
17993
|
+
fs7.mkdirSync(path14.dirname(metaPath), { recursive: true });
|
|
17994
|
+
fs7.writeFileSync(metaPath, JSON.stringify({
|
|
17929
17995
|
etag,
|
|
17930
17996
|
timestamp,
|
|
17931
17997
|
lastCheck: new Date(timestamp).toISOString(),
|
|
@@ -17936,12 +18002,12 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
17936
18002
|
}
|
|
17937
18003
|
/** Count provider files (provider.js or provider.json) */
|
|
17938
18004
|
countProviders(dir) {
|
|
17939
|
-
if (!
|
|
18005
|
+
if (!fs7.existsSync(dir)) return 0;
|
|
17940
18006
|
let count = 0;
|
|
17941
18007
|
const scan = (d) => {
|
|
17942
18008
|
try {
|
|
17943
|
-
for (const entry of
|
|
17944
|
-
if (entry.isDirectory()) scan(
|
|
18009
|
+
for (const entry of fs7.readdirSync(d, { withFileTypes: true })) {
|
|
18010
|
+
if (entry.isDirectory()) scan(path14.join(d, entry.name));
|
|
17945
18011
|
else if (entry.name === "provider.json") count++;
|
|
17946
18012
|
}
|
|
17947
18013
|
} catch {
|
|
@@ -18167,19 +18233,19 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
18167
18233
|
const cat = provider.category;
|
|
18168
18234
|
const searchRoots = this.getProviderRoots();
|
|
18169
18235
|
for (const root of searchRoots) {
|
|
18170
|
-
if (!
|
|
18236
|
+
if (!fs7.existsSync(root)) continue;
|
|
18171
18237
|
const candidate = this.getProviderDir(root, cat, type);
|
|
18172
|
-
if (
|
|
18173
|
-
const catDir =
|
|
18174
|
-
if (
|
|
18238
|
+
if (fs7.existsSync(path14.join(candidate, "provider.json"))) return candidate;
|
|
18239
|
+
const catDir = path14.join(root, cat);
|
|
18240
|
+
if (fs7.existsSync(catDir)) {
|
|
18175
18241
|
try {
|
|
18176
|
-
for (const entry of
|
|
18242
|
+
for (const entry of fs7.readdirSync(catDir, { withFileTypes: true })) {
|
|
18177
18243
|
if (!entry.isDirectory()) continue;
|
|
18178
|
-
const jsonPath =
|
|
18179
|
-
if (
|
|
18244
|
+
const jsonPath = path14.join(catDir, entry.name, "provider.json");
|
|
18245
|
+
if (fs7.existsSync(jsonPath)) {
|
|
18180
18246
|
try {
|
|
18181
|
-
const data = JSON.parse(
|
|
18182
|
-
if (data.type === type) return
|
|
18247
|
+
const data = JSON.parse(fs7.readFileSync(jsonPath, "utf-8"));
|
|
18248
|
+
if (data.type === type) return path14.join(catDir, entry.name);
|
|
18183
18249
|
} catch {
|
|
18184
18250
|
}
|
|
18185
18251
|
}
|
|
@@ -18196,8 +18262,8 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
18196
18262
|
* (template substitution is NOT applied here — scripts.js handles that)
|
|
18197
18263
|
*/
|
|
18198
18264
|
buildScriptWrappersFromDir(dir) {
|
|
18199
|
-
const scriptsJs =
|
|
18200
|
-
if (
|
|
18265
|
+
const scriptsJs = path14.join(dir, "scripts.js");
|
|
18266
|
+
if (fs7.existsSync(scriptsJs)) {
|
|
18201
18267
|
try {
|
|
18202
18268
|
delete require.cache[require.resolve(scriptsJs)];
|
|
18203
18269
|
return require(scriptsJs);
|
|
@@ -18207,13 +18273,13 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
18207
18273
|
const toCamel = (name) => name.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
|
|
18208
18274
|
const result = {};
|
|
18209
18275
|
try {
|
|
18210
|
-
for (const file of
|
|
18276
|
+
for (const file of fs7.readdirSync(dir)) {
|
|
18211
18277
|
if (!file.endsWith(".js")) continue;
|
|
18212
18278
|
const scriptName = toCamel(file.replace(".js", ""));
|
|
18213
|
-
const filePath =
|
|
18279
|
+
const filePath = path14.join(dir, file);
|
|
18214
18280
|
result[scriptName] = (...args) => {
|
|
18215
18281
|
try {
|
|
18216
|
-
let content =
|
|
18282
|
+
let content = fs7.readFileSync(filePath, "utf-8");
|
|
18217
18283
|
if (args[0] && typeof args[0] === "object") {
|
|
18218
18284
|
for (const [key, val] of Object.entries(args[0])) {
|
|
18219
18285
|
let v = val;
|
|
@@ -18259,20 +18325,20 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
18259
18325
|
* Structure: dir/category/agent-name/provider.{json,js}
|
|
18260
18326
|
*/
|
|
18261
18327
|
loadDir(dir, excludeDirs) {
|
|
18262
|
-
if (!
|
|
18328
|
+
if (!fs7.existsSync(dir)) return 0;
|
|
18263
18329
|
let count = 0;
|
|
18264
18330
|
const scan = (d) => {
|
|
18265
18331
|
let entries;
|
|
18266
18332
|
try {
|
|
18267
|
-
entries =
|
|
18333
|
+
entries = fs7.readdirSync(d, { withFileTypes: true });
|
|
18268
18334
|
} catch {
|
|
18269
18335
|
return;
|
|
18270
18336
|
}
|
|
18271
18337
|
const hasJson = entries.some((e) => e.name === "provider.json");
|
|
18272
18338
|
if (hasJson) {
|
|
18273
|
-
const jsonPath =
|
|
18339
|
+
const jsonPath = path14.join(d, "provider.json");
|
|
18274
18340
|
try {
|
|
18275
|
-
const raw =
|
|
18341
|
+
const raw = fs7.readFileSync(jsonPath, "utf-8");
|
|
18276
18342
|
const mod = JSON.parse(raw);
|
|
18277
18343
|
if (typeof mod.extensionIdPattern === "string") {
|
|
18278
18344
|
const flags = mod.extensionIdPattern_flags || "";
|
|
@@ -18291,8 +18357,8 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
18291
18357
|
this.log(`\u26A0 Invalid provider at ${jsonPath}: ${validation.errors.join("; ")}`);
|
|
18292
18358
|
} else {
|
|
18293
18359
|
const hasCompatibility = Array.isArray(normalizedProvider.compatibility);
|
|
18294
|
-
const scriptsPath =
|
|
18295
|
-
if (!hasCompatibility &&
|
|
18360
|
+
const scriptsPath = path14.join(d, "scripts.js");
|
|
18361
|
+
if (!hasCompatibility && fs7.existsSync(scriptsPath)) {
|
|
18296
18362
|
try {
|
|
18297
18363
|
delete require.cache[require.resolve(scriptsPath)];
|
|
18298
18364
|
const scripts = require(scriptsPath);
|
|
@@ -18317,7 +18383,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
18317
18383
|
if (!entry.isDirectory()) continue;
|
|
18318
18384
|
if (entry.name.startsWith("_") || entry.name.startsWith(".")) continue;
|
|
18319
18385
|
if (excludeDirs && d === dir && excludeDirs.includes(entry.name)) continue;
|
|
18320
|
-
scan(
|
|
18386
|
+
scan(path14.join(d, entry.name));
|
|
18321
18387
|
}
|
|
18322
18388
|
}
|
|
18323
18389
|
};
|
|
@@ -18507,7 +18573,7 @@ async function isCdpActive(port) {
|
|
|
18507
18573
|
});
|
|
18508
18574
|
}
|
|
18509
18575
|
async function killIdeProcess(ideId) {
|
|
18510
|
-
const plat =
|
|
18576
|
+
const plat = os15.platform();
|
|
18511
18577
|
const appName = getMacAppIdentifiers()[ideId];
|
|
18512
18578
|
const winProcesses = getWinProcessNames()[ideId];
|
|
18513
18579
|
try {
|
|
@@ -18568,7 +18634,7 @@ async function killIdeProcess(ideId) {
|
|
|
18568
18634
|
}
|
|
18569
18635
|
}
|
|
18570
18636
|
function isIdeRunning(ideId) {
|
|
18571
|
-
const plat =
|
|
18637
|
+
const plat = os15.platform();
|
|
18572
18638
|
try {
|
|
18573
18639
|
if (plat === "darwin") {
|
|
18574
18640
|
const appName = getMacAppIdentifiers()[ideId];
|
|
@@ -18623,7 +18689,7 @@ function isIdeRunning(ideId) {
|
|
|
18623
18689
|
}
|
|
18624
18690
|
}
|
|
18625
18691
|
function detectCurrentWorkspace(ideId) {
|
|
18626
|
-
const plat =
|
|
18692
|
+
const plat = os15.platform();
|
|
18627
18693
|
if (plat === "darwin") {
|
|
18628
18694
|
try {
|
|
18629
18695
|
const appName = getMacAppIdentifiers()[ideId];
|
|
@@ -18638,17 +18704,17 @@ function detectCurrentWorkspace(ideId) {
|
|
|
18638
18704
|
}
|
|
18639
18705
|
} else if (plat === "win32") {
|
|
18640
18706
|
try {
|
|
18641
|
-
const
|
|
18707
|
+
const fs16 = require("fs");
|
|
18642
18708
|
const appNameMap = getMacAppIdentifiers();
|
|
18643
18709
|
const appName = appNameMap[ideId];
|
|
18644
18710
|
if (appName) {
|
|
18645
|
-
const storagePath =
|
|
18646
|
-
process.env.APPDATA ||
|
|
18711
|
+
const storagePath = path15.join(
|
|
18712
|
+
process.env.APPDATA || path15.join(os15.homedir(), "AppData", "Roaming"),
|
|
18647
18713
|
appName,
|
|
18648
18714
|
"storage.json"
|
|
18649
18715
|
);
|
|
18650
|
-
if (
|
|
18651
|
-
const data = JSON.parse(
|
|
18716
|
+
if (fs16.existsSync(storagePath)) {
|
|
18717
|
+
const data = JSON.parse(fs16.readFileSync(storagePath, "utf-8"));
|
|
18652
18718
|
const workspaces = data?.openedPathsList?.workspaces3 || data?.openedPathsList?.entries || [];
|
|
18653
18719
|
if (workspaces.length > 0) {
|
|
18654
18720
|
const recent = workspaces[0];
|
|
@@ -18665,7 +18731,7 @@ function detectCurrentWorkspace(ideId) {
|
|
|
18665
18731
|
return void 0;
|
|
18666
18732
|
}
|
|
18667
18733
|
async function launchWithCdp(options = {}) {
|
|
18668
|
-
const platform10 =
|
|
18734
|
+
const platform10 = os15.platform();
|
|
18669
18735
|
let targetIde;
|
|
18670
18736
|
const ides = await detectIDEs(getProviderLoader());
|
|
18671
18737
|
if (options.ideId) {
|
|
@@ -18820,14 +18886,14 @@ init_config();
|
|
|
18820
18886
|
init_logger();
|
|
18821
18887
|
|
|
18822
18888
|
// src/logging/command-log.ts
|
|
18823
|
-
var
|
|
18824
|
-
var
|
|
18825
|
-
var
|
|
18826
|
-
var LOG_DIR2 = process.platform === "win32" ?
|
|
18889
|
+
var fs8 = __toESM(require("fs"));
|
|
18890
|
+
var path16 = __toESM(require("path"));
|
|
18891
|
+
var os16 = __toESM(require("os"));
|
|
18892
|
+
var LOG_DIR2 = process.platform === "win32" ? path16.join(process.env.LOCALAPPDATA || process.env.APPDATA || path16.join(os16.homedir(), "AppData", "Local"), "adhdev", "logs") : process.platform === "darwin" ? path16.join(os16.homedir(), "Library", "Logs", "adhdev") : path16.join(os16.homedir(), ".local", "share", "adhdev", "logs");
|
|
18827
18893
|
var MAX_FILE_SIZE = 5 * 1024 * 1024;
|
|
18828
18894
|
var MAX_DAYS = 7;
|
|
18829
18895
|
try {
|
|
18830
|
-
|
|
18896
|
+
fs8.mkdirSync(LOG_DIR2, { recursive: true });
|
|
18831
18897
|
} catch {
|
|
18832
18898
|
}
|
|
18833
18899
|
var SENSITIVE_KEYS = /* @__PURE__ */ new Set([
|
|
@@ -18861,19 +18927,19 @@ function getDateStr2() {
|
|
|
18861
18927
|
return (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
18862
18928
|
}
|
|
18863
18929
|
var currentDate2 = getDateStr2();
|
|
18864
|
-
var currentFile =
|
|
18930
|
+
var currentFile = path16.join(LOG_DIR2, `commands-${currentDate2}.jsonl`);
|
|
18865
18931
|
var writeCount2 = 0;
|
|
18866
18932
|
function checkRotation() {
|
|
18867
18933
|
const today = getDateStr2();
|
|
18868
18934
|
if (today !== currentDate2) {
|
|
18869
18935
|
currentDate2 = today;
|
|
18870
|
-
currentFile =
|
|
18936
|
+
currentFile = path16.join(LOG_DIR2, `commands-${currentDate2}.jsonl`);
|
|
18871
18937
|
cleanOldFiles();
|
|
18872
18938
|
}
|
|
18873
18939
|
}
|
|
18874
18940
|
function cleanOldFiles() {
|
|
18875
18941
|
try {
|
|
18876
|
-
const files =
|
|
18942
|
+
const files = fs8.readdirSync(LOG_DIR2).filter((f) => f.startsWith("commands-") && f.endsWith(".jsonl"));
|
|
18877
18943
|
const cutoff = /* @__PURE__ */ new Date();
|
|
18878
18944
|
cutoff.setDate(cutoff.getDate() - MAX_DAYS);
|
|
18879
18945
|
const cutoffStr = cutoff.toISOString().slice(0, 10);
|
|
@@ -18881,7 +18947,7 @@ function cleanOldFiles() {
|
|
|
18881
18947
|
const dateMatch = file.match(/commands-(\d{4}-\d{2}-\d{2})/);
|
|
18882
18948
|
if (dateMatch && dateMatch[1] < cutoffStr) {
|
|
18883
18949
|
try {
|
|
18884
|
-
|
|
18950
|
+
fs8.unlinkSync(path16.join(LOG_DIR2, file));
|
|
18885
18951
|
} catch {
|
|
18886
18952
|
}
|
|
18887
18953
|
}
|
|
@@ -18891,14 +18957,14 @@ function cleanOldFiles() {
|
|
|
18891
18957
|
}
|
|
18892
18958
|
function checkSize() {
|
|
18893
18959
|
try {
|
|
18894
|
-
const stat =
|
|
18960
|
+
const stat = fs8.statSync(currentFile);
|
|
18895
18961
|
if (stat.size > MAX_FILE_SIZE) {
|
|
18896
18962
|
const backup = currentFile.replace(".jsonl", ".1.jsonl");
|
|
18897
18963
|
try {
|
|
18898
|
-
|
|
18964
|
+
fs8.unlinkSync(backup);
|
|
18899
18965
|
} catch {
|
|
18900
18966
|
}
|
|
18901
|
-
|
|
18967
|
+
fs8.renameSync(currentFile, backup);
|
|
18902
18968
|
}
|
|
18903
18969
|
} catch {
|
|
18904
18970
|
}
|
|
@@ -18931,14 +18997,14 @@ function logCommand(entry) {
|
|
|
18931
18997
|
...entry.error ? { err: entry.error } : {},
|
|
18932
18998
|
...entry.durationMs !== void 0 ? { ms: entry.durationMs } : {}
|
|
18933
18999
|
});
|
|
18934
|
-
|
|
19000
|
+
fs8.appendFileSync(currentFile, line + "\n");
|
|
18935
19001
|
} catch {
|
|
18936
19002
|
}
|
|
18937
19003
|
}
|
|
18938
19004
|
function getRecentCommands(count = 50) {
|
|
18939
19005
|
try {
|
|
18940
|
-
if (!
|
|
18941
|
-
const content =
|
|
19006
|
+
if (!fs8.existsSync(currentFile)) return [];
|
|
19007
|
+
const content = fs8.readFileSync(currentFile, "utf-8");
|
|
18942
19008
|
const lines = content.trim().split("\n").filter(Boolean);
|
|
18943
19009
|
return lines.slice(-count).map((line) => {
|
|
18944
19010
|
try {
|
|
@@ -18967,7 +19033,7 @@ cleanOldFiles();
|
|
|
18967
19033
|
init_logger();
|
|
18968
19034
|
|
|
18969
19035
|
// src/status/snapshot.ts
|
|
18970
|
-
var
|
|
19036
|
+
var os17 = __toESM(require("os"));
|
|
18971
19037
|
init_config();
|
|
18972
19038
|
init_terminal_screen();
|
|
18973
19039
|
init_logger();
|
|
@@ -19022,8 +19088,8 @@ function buildAvailableProviders(providerLoader) {
|
|
|
19022
19088
|
}
|
|
19023
19089
|
function buildMachineInfo(profile = "full") {
|
|
19024
19090
|
const base = {
|
|
19025
|
-
hostname:
|
|
19026
|
-
platform:
|
|
19091
|
+
hostname: os17.hostname(),
|
|
19092
|
+
platform: os17.platform()
|
|
19027
19093
|
};
|
|
19028
19094
|
if (profile === "live") {
|
|
19029
19095
|
return base;
|
|
@@ -19032,23 +19098,23 @@ function buildMachineInfo(profile = "full") {
|
|
|
19032
19098
|
const memSnap2 = getHostMemorySnapshot();
|
|
19033
19099
|
return {
|
|
19034
19100
|
...base,
|
|
19035
|
-
arch:
|
|
19036
|
-
cpus:
|
|
19101
|
+
arch: os17.arch(),
|
|
19102
|
+
cpus: os17.cpus().length,
|
|
19037
19103
|
totalMem: memSnap2.totalMem,
|
|
19038
|
-
release:
|
|
19104
|
+
release: os17.release()
|
|
19039
19105
|
};
|
|
19040
19106
|
}
|
|
19041
19107
|
const memSnap = getHostMemorySnapshot();
|
|
19042
19108
|
return {
|
|
19043
19109
|
...base,
|
|
19044
|
-
arch:
|
|
19045
|
-
cpus:
|
|
19110
|
+
arch: os17.arch(),
|
|
19111
|
+
cpus: os17.cpus().length,
|
|
19046
19112
|
totalMem: memSnap.totalMem,
|
|
19047
19113
|
freeMem: memSnap.freeMem,
|
|
19048
19114
|
availableMem: memSnap.availableMem,
|
|
19049
|
-
loadavg:
|
|
19050
|
-
uptime:
|
|
19051
|
-
release:
|
|
19115
|
+
loadavg: os17.loadavg(),
|
|
19116
|
+
uptime: os17.uptime(),
|
|
19117
|
+
release: os17.release()
|
|
19052
19118
|
};
|
|
19053
19119
|
}
|
|
19054
19120
|
function parseMessageTime(value) {
|
|
@@ -19275,42 +19341,42 @@ function buildStatusSnapshot(options) {
|
|
|
19275
19341
|
// src/commands/upgrade-helper.ts
|
|
19276
19342
|
var import_child_process8 = require("child_process");
|
|
19277
19343
|
var import_child_process9 = require("child_process");
|
|
19278
|
-
var
|
|
19279
|
-
var
|
|
19280
|
-
var
|
|
19344
|
+
var fs9 = __toESM(require("fs"));
|
|
19345
|
+
var os18 = __toESM(require("os"));
|
|
19346
|
+
var path17 = __toESM(require("path"));
|
|
19281
19347
|
var UPGRADE_HELPER_ENV = "ADHDEV_DAEMON_UPGRADE_HELPER";
|
|
19282
19348
|
function getUpgradeLogPath() {
|
|
19283
|
-
const home =
|
|
19284
|
-
const dir =
|
|
19285
|
-
|
|
19286
|
-
return
|
|
19349
|
+
const home = os18.homedir();
|
|
19350
|
+
const dir = path17.join(home, ".adhdev");
|
|
19351
|
+
fs9.mkdirSync(dir, { recursive: true });
|
|
19352
|
+
return path17.join(dir, "daemon-upgrade.log");
|
|
19287
19353
|
}
|
|
19288
19354
|
function appendUpgradeLog(message) {
|
|
19289
19355
|
const line = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${message}
|
|
19290
19356
|
`;
|
|
19291
19357
|
try {
|
|
19292
|
-
|
|
19358
|
+
fs9.appendFileSync(getUpgradeLogPath(), line, "utf8");
|
|
19293
19359
|
} catch {
|
|
19294
19360
|
}
|
|
19295
19361
|
}
|
|
19296
19362
|
function resolveSiblingNpmInvocation(nodeExecutable, platform10 = process.platform) {
|
|
19297
|
-
const binDir =
|
|
19363
|
+
const binDir = path17.dirname(nodeExecutable);
|
|
19298
19364
|
if (platform10 === "win32") {
|
|
19299
|
-
const npmCliPath =
|
|
19300
|
-
if (
|
|
19365
|
+
const npmCliPath = path17.join(binDir, "node_modules", "npm", "bin", "npm-cli.js");
|
|
19366
|
+
if (fs9.existsSync(npmCliPath)) {
|
|
19301
19367
|
return { executable: nodeExecutable, argsPrefix: [npmCliPath], execOptions: getNpmExecOptions(platform10) };
|
|
19302
19368
|
}
|
|
19303
19369
|
for (const candidate of ["npm.exe", "npm"]) {
|
|
19304
|
-
const candidatePath =
|
|
19305
|
-
if (
|
|
19370
|
+
const candidatePath = path17.join(binDir, candidate);
|
|
19371
|
+
if (fs9.existsSync(candidatePath)) {
|
|
19306
19372
|
return { executable: candidatePath, argsPrefix: [], execOptions: getNpmExecOptions(platform10) };
|
|
19307
19373
|
}
|
|
19308
19374
|
}
|
|
19309
19375
|
return { executable: nodeExecutable, argsPrefix: [npmCliPath], execOptions: getNpmExecOptions(platform10) };
|
|
19310
19376
|
}
|
|
19311
19377
|
for (const candidate of ["npm"]) {
|
|
19312
|
-
const candidatePath =
|
|
19313
|
-
if (
|
|
19378
|
+
const candidatePath = path17.join(binDir, candidate);
|
|
19379
|
+
if (fs9.existsSync(candidatePath)) {
|
|
19314
19380
|
return { executable: candidatePath, argsPrefix: [], execOptions: getNpmExecOptions(platform10) };
|
|
19315
19381
|
}
|
|
19316
19382
|
}
|
|
@@ -19320,22 +19386,22 @@ function findCurrentPackageRoot(currentCliPath, packageName) {
|
|
|
19320
19386
|
if (!currentCliPath) return null;
|
|
19321
19387
|
let resolvedPath = currentCliPath;
|
|
19322
19388
|
try {
|
|
19323
|
-
resolvedPath =
|
|
19389
|
+
resolvedPath = fs9.realpathSync.native(currentCliPath);
|
|
19324
19390
|
} catch {
|
|
19325
19391
|
}
|
|
19326
19392
|
let currentDir = resolvedPath;
|
|
19327
19393
|
try {
|
|
19328
|
-
if (
|
|
19329
|
-
currentDir =
|
|
19394
|
+
if (fs9.statSync(resolvedPath).isFile()) {
|
|
19395
|
+
currentDir = path17.dirname(resolvedPath);
|
|
19330
19396
|
}
|
|
19331
19397
|
} catch {
|
|
19332
|
-
currentDir =
|
|
19398
|
+
currentDir = path17.dirname(resolvedPath);
|
|
19333
19399
|
}
|
|
19334
19400
|
while (true) {
|
|
19335
|
-
const packageJsonPath =
|
|
19401
|
+
const packageJsonPath = path17.join(currentDir, "package.json");
|
|
19336
19402
|
try {
|
|
19337
|
-
if (
|
|
19338
|
-
const parsed = JSON.parse(
|
|
19403
|
+
if (fs9.existsSync(packageJsonPath)) {
|
|
19404
|
+
const parsed = JSON.parse(fs9.readFileSync(packageJsonPath, "utf8"));
|
|
19339
19405
|
if (parsed?.name === packageName) {
|
|
19340
19406
|
const normalized = currentDir.replace(/\\/g, "/");
|
|
19341
19407
|
return normalized.includes("/node_modules/") ? currentDir : null;
|
|
@@ -19343,7 +19409,7 @@ function findCurrentPackageRoot(currentCliPath, packageName) {
|
|
|
19343
19409
|
}
|
|
19344
19410
|
} catch {
|
|
19345
19411
|
}
|
|
19346
|
-
const parentDir =
|
|
19412
|
+
const parentDir = path17.dirname(currentDir);
|
|
19347
19413
|
if (parentDir === currentDir) {
|
|
19348
19414
|
return null;
|
|
19349
19415
|
}
|
|
@@ -19351,13 +19417,13 @@ function findCurrentPackageRoot(currentCliPath, packageName) {
|
|
|
19351
19417
|
}
|
|
19352
19418
|
}
|
|
19353
19419
|
function resolveInstallPrefixFromPackageRoot(packageRoot, packageName) {
|
|
19354
|
-
const nodeModulesDir = packageName.startsWith("@") ?
|
|
19355
|
-
if (
|
|
19420
|
+
const nodeModulesDir = packageName.startsWith("@") ? path17.dirname(path17.dirname(packageRoot)) : path17.dirname(packageRoot);
|
|
19421
|
+
if (path17.basename(nodeModulesDir) !== "node_modules") {
|
|
19356
19422
|
return null;
|
|
19357
19423
|
}
|
|
19358
|
-
const maybeLibDir =
|
|
19359
|
-
if (
|
|
19360
|
-
return
|
|
19424
|
+
const maybeLibDir = path17.dirname(nodeModulesDir);
|
|
19425
|
+
if (path17.basename(maybeLibDir) === "lib") {
|
|
19426
|
+
return path17.dirname(maybeLibDir);
|
|
19361
19427
|
}
|
|
19362
19428
|
return maybeLibDir;
|
|
19363
19429
|
}
|
|
@@ -19472,10 +19538,10 @@ async function waitForPidExit(pid, timeoutMs) {
|
|
|
19472
19538
|
}
|
|
19473
19539
|
}
|
|
19474
19540
|
function stopSessionHostProcesses(appName) {
|
|
19475
|
-
const pidFile =
|
|
19541
|
+
const pidFile = path17.join(os18.homedir(), ".adhdev", `${appName}-session-host.pid`);
|
|
19476
19542
|
try {
|
|
19477
|
-
if (
|
|
19478
|
-
const pid = Number.parseInt(
|
|
19543
|
+
if (fs9.existsSync(pidFile)) {
|
|
19544
|
+
const pid = Number.parseInt(fs9.readFileSync(pidFile, "utf8").trim(), 10);
|
|
19479
19545
|
if (Number.isFinite(pid) && pid !== process.pid && isManagedSessionHostPid(pid)) {
|
|
19480
19546
|
killPid(pid);
|
|
19481
19547
|
}
|
|
@@ -19483,15 +19549,15 @@ function stopSessionHostProcesses(appName) {
|
|
|
19483
19549
|
} catch {
|
|
19484
19550
|
} finally {
|
|
19485
19551
|
try {
|
|
19486
|
-
|
|
19552
|
+
fs9.unlinkSync(pidFile);
|
|
19487
19553
|
} catch {
|
|
19488
19554
|
}
|
|
19489
19555
|
}
|
|
19490
19556
|
}
|
|
19491
19557
|
function removeDaemonPidFile() {
|
|
19492
|
-
const pidFile =
|
|
19558
|
+
const pidFile = path17.join(os18.homedir(), ".adhdev", "daemon.pid");
|
|
19493
19559
|
try {
|
|
19494
|
-
|
|
19560
|
+
fs9.unlinkSync(pidFile);
|
|
19495
19561
|
} catch {
|
|
19496
19562
|
}
|
|
19497
19563
|
}
|
|
@@ -19500,7 +19566,7 @@ function cleanupStaleGlobalInstallDirs(pkgName, surface) {
|
|
|
19500
19566
|
const npmRoot = String(execNpmCommandSync(["root", "-g", ...prefixArgs], { encoding: "utf8" }, surface)).trim();
|
|
19501
19567
|
if (!npmRoot) return;
|
|
19502
19568
|
const npmPrefix = surface.installPrefix || String(execNpmCommandSync(["prefix", "-g", ...prefixArgs], { encoding: "utf8" }, surface)).trim();
|
|
19503
|
-
const binDir = process.platform === "win32" ? npmPrefix :
|
|
19569
|
+
const binDir = process.platform === "win32" ? npmPrefix : path17.join(npmPrefix, "bin");
|
|
19504
19570
|
const packageBaseName = pkgName.startsWith("@") ? pkgName.split("/")[1] : pkgName;
|
|
19505
19571
|
const binNames = /* @__PURE__ */ new Set([packageBaseName]);
|
|
19506
19572
|
if (pkgName === "@adhdev/daemon-standalone") {
|
|
@@ -19508,25 +19574,25 @@ function cleanupStaleGlobalInstallDirs(pkgName, surface) {
|
|
|
19508
19574
|
}
|
|
19509
19575
|
if (pkgName.startsWith("@")) {
|
|
19510
19576
|
const [scope, name] = pkgName.split("/");
|
|
19511
|
-
const scopeDir =
|
|
19512
|
-
if (!
|
|
19513
|
-
for (const entry of
|
|
19577
|
+
const scopeDir = path17.join(npmRoot, scope);
|
|
19578
|
+
if (!fs9.existsSync(scopeDir)) return;
|
|
19579
|
+
for (const entry of fs9.readdirSync(scopeDir)) {
|
|
19514
19580
|
if (!entry.startsWith(`.${name}-`)) continue;
|
|
19515
|
-
|
|
19516
|
-
appendUpgradeLog(`Removed stale scoped staging dir: ${
|
|
19581
|
+
fs9.rmSync(path17.join(scopeDir, entry), { recursive: true, force: true });
|
|
19582
|
+
appendUpgradeLog(`Removed stale scoped staging dir: ${path17.join(scopeDir, entry)}`);
|
|
19517
19583
|
}
|
|
19518
19584
|
} else {
|
|
19519
|
-
for (const entry of
|
|
19585
|
+
for (const entry of fs9.readdirSync(npmRoot)) {
|
|
19520
19586
|
if (!entry.startsWith(`.${pkgName}-`)) continue;
|
|
19521
|
-
|
|
19522
|
-
appendUpgradeLog(`Removed stale staging dir: ${
|
|
19587
|
+
fs9.rmSync(path17.join(npmRoot, entry), { recursive: true, force: true });
|
|
19588
|
+
appendUpgradeLog(`Removed stale staging dir: ${path17.join(npmRoot, entry)}`);
|
|
19523
19589
|
}
|
|
19524
19590
|
}
|
|
19525
|
-
if (
|
|
19526
|
-
for (const entry of
|
|
19591
|
+
if (fs9.existsSync(binDir)) {
|
|
19592
|
+
for (const entry of fs9.readdirSync(binDir)) {
|
|
19527
19593
|
if (!Array.from(binNames).some((name) => entry.startsWith(`.${name}-`))) continue;
|
|
19528
|
-
|
|
19529
|
-
appendUpgradeLog(`Removed stale bin staging entry: ${
|
|
19594
|
+
fs9.rmSync(path17.join(binDir, entry), { recursive: true, force: true });
|
|
19595
|
+
appendUpgradeLog(`Removed stale bin staging entry: ${path17.join(binDir, entry)}`);
|
|
19530
19596
|
}
|
|
19531
19597
|
}
|
|
19532
19598
|
}
|
|
@@ -19611,7 +19677,7 @@ async function maybeRunDaemonUpgradeHelperFromEnv() {
|
|
|
19611
19677
|
}
|
|
19612
19678
|
|
|
19613
19679
|
// src/commands/router.ts
|
|
19614
|
-
var
|
|
19680
|
+
var fs10 = __toESM(require("fs"));
|
|
19615
19681
|
var CHAT_COMMANDS = [
|
|
19616
19682
|
"send_chat",
|
|
19617
19683
|
"new_chat",
|
|
@@ -19847,8 +19913,8 @@ var DaemonCommandRouter = class {
|
|
|
19847
19913
|
if (sinceTs > 0) {
|
|
19848
19914
|
return { success: true, logs: [], totalBuffered: 0 };
|
|
19849
19915
|
}
|
|
19850
|
-
if (
|
|
19851
|
-
const content =
|
|
19916
|
+
if (fs10.existsSync(LOG_PATH)) {
|
|
19917
|
+
const content = fs10.readFileSync(LOG_PATH, "utf-8");
|
|
19852
19918
|
const allLines = content.split("\n");
|
|
19853
19919
|
const recent = allLines.slice(-count).join("\n");
|
|
19854
19920
|
return { success: true, logs: recent, totalLines: allLines.length };
|
|
@@ -19990,6 +20056,8 @@ var DaemonCommandRouter = class {
|
|
|
19990
20056
|
const wantsAll = args?.all === true;
|
|
19991
20057
|
const offset = wantsAll ? 0 : Math.max(0, Number(args?.offset) || 0);
|
|
19992
20058
|
const limit = wantsAll ? Number.MAX_SAFE_INTEGER : Math.max(1, Math.min(100, Number(args?.limit) || 30));
|
|
20059
|
+
const requestedWorkspace = typeof args?.workspace === "string" ? args.workspace.trim() : "";
|
|
20060
|
+
const requestedProviderSessionId = typeof args?.providerSessionId === "string" ? args.providerSessionId.trim() : typeof args?.activeProviderSessionId === "string" ? args.activeProviderSessionId.trim() : "";
|
|
19993
20061
|
const providerMeta = this.deps.providerLoader.resolve?.(providerType) || this.deps.providerLoader.getMeta(providerType);
|
|
19994
20062
|
const { sessions: historySessions, hasMore, source } = listProviderHistorySessions(providerType, {
|
|
19995
20063
|
canonicalHistory: providerMeta?.canonicalHistory,
|
|
@@ -20009,6 +20077,7 @@ var DaemonCommandRouter = class {
|
|
|
20009
20077
|
sessions: historySessions.map((session) => {
|
|
20010
20078
|
const saved = savedSessionById.get(session.historySessionId);
|
|
20011
20079
|
const recent = recentSessionById.get(session.historySessionId);
|
|
20080
|
+
const workspace = saved?.workspace || recent?.workspace || session.workspace || (requestedWorkspace && requestedProviderSessionId === session.historySessionId ? requestedWorkspace : void 0);
|
|
20012
20081
|
return {
|
|
20013
20082
|
id: session.historySessionId,
|
|
20014
20083
|
providerSessionId: session.historySessionId,
|
|
@@ -20016,13 +20085,13 @@ var DaemonCommandRouter = class {
|
|
|
20016
20085
|
providerName: saved?.providerName || recent?.providerName || providerType,
|
|
20017
20086
|
kind: saved?.kind || recent?.kind || kind,
|
|
20018
20087
|
title: saved?.title || recent?.title || session.sessionTitle || session.preview || providerType,
|
|
20019
|
-
workspace
|
|
20088
|
+
workspace,
|
|
20020
20089
|
summaryMetadata: saved?.summaryMetadata || recent?.summaryMetadata,
|
|
20021
20090
|
preview: session.preview,
|
|
20022
20091
|
messageCount: session.messageCount,
|
|
20023
20092
|
firstMessageAt: session.firstMessageAt,
|
|
20024
20093
|
lastMessageAt: session.lastMessageAt,
|
|
20025
|
-
canResume: !!
|
|
20094
|
+
canResume: !!workspace && canResumeById,
|
|
20026
20095
|
historySource: session.source,
|
|
20027
20096
|
sourcePath: session.sourcePath,
|
|
20028
20097
|
sourceMtimeMs: session.sourceMtimeMs
|
|
@@ -22000,12 +22069,12 @@ init_io_contracts();
|
|
|
22000
22069
|
init_chat_message_normalization();
|
|
22001
22070
|
|
|
22002
22071
|
// src/providers/version-archive.ts
|
|
22003
|
-
var
|
|
22004
|
-
var
|
|
22005
|
-
var
|
|
22072
|
+
var fs11 = __toESM(require("fs"));
|
|
22073
|
+
var path18 = __toESM(require("path"));
|
|
22074
|
+
var os19 = __toESM(require("os"));
|
|
22006
22075
|
var import_child_process10 = require("child_process");
|
|
22007
22076
|
var import_os3 = require("os");
|
|
22008
|
-
var ARCHIVE_PATH =
|
|
22077
|
+
var ARCHIVE_PATH = path18.join(os19.homedir(), ".adhdev", "version-history.json");
|
|
22009
22078
|
var MAX_ENTRIES_PER_PROVIDER = 20;
|
|
22010
22079
|
var VersionArchive = class {
|
|
22011
22080
|
history = {};
|
|
@@ -22014,8 +22083,8 @@ var VersionArchive = class {
|
|
|
22014
22083
|
}
|
|
22015
22084
|
load() {
|
|
22016
22085
|
try {
|
|
22017
|
-
if (
|
|
22018
|
-
this.history = JSON.parse(
|
|
22086
|
+
if (fs11.existsSync(ARCHIVE_PATH)) {
|
|
22087
|
+
this.history = JSON.parse(fs11.readFileSync(ARCHIVE_PATH, "utf-8"));
|
|
22019
22088
|
}
|
|
22020
22089
|
} catch {
|
|
22021
22090
|
this.history = {};
|
|
@@ -22052,8 +22121,8 @@ var VersionArchive = class {
|
|
|
22052
22121
|
}
|
|
22053
22122
|
save() {
|
|
22054
22123
|
try {
|
|
22055
|
-
|
|
22056
|
-
|
|
22124
|
+
fs11.mkdirSync(path18.dirname(ARCHIVE_PATH), { recursive: true });
|
|
22125
|
+
fs11.writeFileSync(ARCHIVE_PATH, JSON.stringify(this.history, null, 2));
|
|
22057
22126
|
} catch {
|
|
22058
22127
|
}
|
|
22059
22128
|
}
|
|
@@ -22108,19 +22177,19 @@ function getVersion(binary, versionCommand) {
|
|
|
22108
22177
|
function checkPathExists2(paths) {
|
|
22109
22178
|
for (const p of paths) {
|
|
22110
22179
|
if (p.includes("*")) {
|
|
22111
|
-
const home =
|
|
22112
|
-
const resolved = p.replace(/\*/g, home.split(
|
|
22113
|
-
if (
|
|
22180
|
+
const home = os19.homedir();
|
|
22181
|
+
const resolved = p.replace(/\*/g, home.split(path18.sep).pop() || "");
|
|
22182
|
+
if (fs11.existsSync(resolved)) return resolved;
|
|
22114
22183
|
} else {
|
|
22115
|
-
if (
|
|
22184
|
+
if (fs11.existsSync(p)) return p;
|
|
22116
22185
|
}
|
|
22117
22186
|
}
|
|
22118
22187
|
return null;
|
|
22119
22188
|
}
|
|
22120
22189
|
function getMacAppVersion(appPath) {
|
|
22121
22190
|
if ((0, import_os3.platform)() !== "darwin" || !appPath.endsWith(".app")) return null;
|
|
22122
|
-
const plistPath =
|
|
22123
|
-
if (!
|
|
22191
|
+
const plistPath = path18.join(appPath, "Contents", "Info.plist");
|
|
22192
|
+
if (!fs11.existsSync(plistPath)) return null;
|
|
22124
22193
|
const raw = runCommand(`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${plistPath}"`);
|
|
22125
22194
|
return raw || null;
|
|
22126
22195
|
}
|
|
@@ -22145,8 +22214,8 @@ async function detectAllVersions(loader, archive) {
|
|
|
22145
22214
|
const cliBin = provider.cli ? findBinary2(provider.cli) : null;
|
|
22146
22215
|
let resolvedBin = cliBin;
|
|
22147
22216
|
if (!resolvedBin && appPath && currentOs === "darwin") {
|
|
22148
|
-
const bundled =
|
|
22149
|
-
if (provider.cli &&
|
|
22217
|
+
const bundled = path18.join(appPath, "Contents", "Resources", "app", "bin", provider.cli || "");
|
|
22218
|
+
if (provider.cli && fs11.existsSync(bundled)) resolvedBin = bundled;
|
|
22150
22219
|
}
|
|
22151
22220
|
info.installed = !!(appPath || resolvedBin);
|
|
22152
22221
|
info.path = appPath || null;
|
|
@@ -22185,8 +22254,8 @@ async function detectAllVersions(loader, archive) {
|
|
|
22185
22254
|
|
|
22186
22255
|
// src/daemon/dev-server.ts
|
|
22187
22256
|
var http2 = __toESM(require("http"));
|
|
22188
|
-
var
|
|
22189
|
-
var
|
|
22257
|
+
var fs15 = __toESM(require("fs"));
|
|
22258
|
+
var path22 = __toESM(require("path"));
|
|
22190
22259
|
init_config();
|
|
22191
22260
|
|
|
22192
22261
|
// src/daemon/scaffold-template.ts
|
|
@@ -22536,8 +22605,8 @@ async (params) => {
|
|
|
22536
22605
|
init_logger();
|
|
22537
22606
|
|
|
22538
22607
|
// src/daemon/dev-cdp-handlers.ts
|
|
22539
|
-
var
|
|
22540
|
-
var
|
|
22608
|
+
var fs12 = __toESM(require("fs"));
|
|
22609
|
+
var path19 = __toESM(require("path"));
|
|
22541
22610
|
init_logger();
|
|
22542
22611
|
async function handleCdpEvaluate(ctx, req, res) {
|
|
22543
22612
|
const body = await ctx.readBody(req);
|
|
@@ -22716,18 +22785,18 @@ async function handleScriptHints(ctx, type, _req, res) {
|
|
|
22716
22785
|
return;
|
|
22717
22786
|
}
|
|
22718
22787
|
let scriptsPath = "";
|
|
22719
|
-
const directScripts =
|
|
22720
|
-
if (
|
|
22788
|
+
const directScripts = path19.join(dir, "scripts.js");
|
|
22789
|
+
if (fs12.existsSync(directScripts)) {
|
|
22721
22790
|
scriptsPath = directScripts;
|
|
22722
22791
|
} else {
|
|
22723
|
-
const scriptsDir =
|
|
22724
|
-
if (
|
|
22725
|
-
const versions =
|
|
22726
|
-
return
|
|
22792
|
+
const scriptsDir = path19.join(dir, "scripts");
|
|
22793
|
+
if (fs12.existsSync(scriptsDir)) {
|
|
22794
|
+
const versions = fs12.readdirSync(scriptsDir).filter((d) => {
|
|
22795
|
+
return fs12.statSync(path19.join(scriptsDir, d)).isDirectory();
|
|
22727
22796
|
}).sort().reverse();
|
|
22728
22797
|
for (const ver of versions) {
|
|
22729
|
-
const p =
|
|
22730
|
-
if (
|
|
22798
|
+
const p = path19.join(scriptsDir, ver, "scripts.js");
|
|
22799
|
+
if (fs12.existsSync(p)) {
|
|
22731
22800
|
scriptsPath = p;
|
|
22732
22801
|
break;
|
|
22733
22802
|
}
|
|
@@ -22739,7 +22808,7 @@ async function handleScriptHints(ctx, type, _req, res) {
|
|
|
22739
22808
|
return;
|
|
22740
22809
|
}
|
|
22741
22810
|
try {
|
|
22742
|
-
const source =
|
|
22811
|
+
const source = fs12.readFileSync(scriptsPath, "utf-8");
|
|
22743
22812
|
const hints = {};
|
|
22744
22813
|
const funcRegex = /module\.exports\.(\w+)\s*=\s*function\s+\w+\s*\(params\)/g;
|
|
22745
22814
|
let match;
|
|
@@ -23554,8 +23623,8 @@ async function handleDomContext(ctx, type, req, res) {
|
|
|
23554
23623
|
}
|
|
23555
23624
|
|
|
23556
23625
|
// src/daemon/dev-cli-debug.ts
|
|
23557
|
-
var
|
|
23558
|
-
var
|
|
23626
|
+
var fs13 = __toESM(require("fs"));
|
|
23627
|
+
var path20 = __toESM(require("path"));
|
|
23559
23628
|
function slugifyFixtureName(value) {
|
|
23560
23629
|
const normalized = String(value || "").trim().toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
23561
23630
|
return normalized || `fixture-${Date.now()}`;
|
|
@@ -23565,15 +23634,15 @@ function getCliFixtureDir(ctx, type) {
|
|
|
23565
23634
|
if (!providerDir) {
|
|
23566
23635
|
throw new Error(`Provider directory not found for '${type}'`);
|
|
23567
23636
|
}
|
|
23568
|
-
return
|
|
23637
|
+
return path20.join(providerDir, "fixtures");
|
|
23569
23638
|
}
|
|
23570
23639
|
function readCliFixture(ctx, type, name) {
|
|
23571
23640
|
const fixtureDir = getCliFixtureDir(ctx, type);
|
|
23572
|
-
const filePath =
|
|
23573
|
-
if (!
|
|
23641
|
+
const filePath = path20.join(fixtureDir, `${name}.json`);
|
|
23642
|
+
if (!fs13.existsSync(filePath)) {
|
|
23574
23643
|
throw new Error(`Fixture not found: ${filePath}`);
|
|
23575
23644
|
}
|
|
23576
|
-
return JSON.parse(
|
|
23645
|
+
return JSON.parse(fs13.readFileSync(filePath, "utf-8"));
|
|
23577
23646
|
}
|
|
23578
23647
|
function getExerciseTranscriptText(result) {
|
|
23579
23648
|
const parts = [];
|
|
@@ -24309,7 +24378,7 @@ async function handleCliFixtureCapture(ctx, req, res) {
|
|
|
24309
24378
|
return;
|
|
24310
24379
|
}
|
|
24311
24380
|
const fixtureDir = getCliFixtureDir(ctx, type);
|
|
24312
|
-
|
|
24381
|
+
fs13.mkdirSync(fixtureDir, { recursive: true });
|
|
24313
24382
|
const name = slugifyFixtureName(String(body?.name || `${type}-${Date.now()}`));
|
|
24314
24383
|
const result = await runCliExerciseInternal(ctx, { ...request, type });
|
|
24315
24384
|
const fixture = {
|
|
@@ -24336,8 +24405,8 @@ async function handleCliFixtureCapture(ctx, req, res) {
|
|
|
24336
24405
|
},
|
|
24337
24406
|
notes: typeof body?.notes === "string" ? body.notes : void 0
|
|
24338
24407
|
};
|
|
24339
|
-
const filePath =
|
|
24340
|
-
|
|
24408
|
+
const filePath = path20.join(fixtureDir, `${name}.json`);
|
|
24409
|
+
fs13.writeFileSync(filePath, JSON.stringify(fixture, null, 2));
|
|
24341
24410
|
ctx.json(res, 200, {
|
|
24342
24411
|
saved: true,
|
|
24343
24412
|
name,
|
|
@@ -24355,14 +24424,14 @@ async function handleCliFixtureCapture(ctx, req, res) {
|
|
|
24355
24424
|
async function handleCliFixtureList(ctx, type, _req, res) {
|
|
24356
24425
|
try {
|
|
24357
24426
|
const fixtureDir = getCliFixtureDir(ctx, type);
|
|
24358
|
-
if (!
|
|
24427
|
+
if (!fs13.existsSync(fixtureDir)) {
|
|
24359
24428
|
ctx.json(res, 200, { fixtures: [], count: 0 });
|
|
24360
24429
|
return;
|
|
24361
24430
|
}
|
|
24362
|
-
const fixtures =
|
|
24363
|
-
const fullPath =
|
|
24431
|
+
const fixtures = fs13.readdirSync(fixtureDir).filter((file) => file.endsWith(".json")).sort((a, b) => b.localeCompare(a, void 0, { numeric: true, sensitivity: "base" })).map((file) => {
|
|
24432
|
+
const fullPath = path20.join(fixtureDir, file);
|
|
24364
24433
|
try {
|
|
24365
|
-
const raw = JSON.parse(
|
|
24434
|
+
const raw = JSON.parse(fs13.readFileSync(fullPath, "utf-8"));
|
|
24366
24435
|
return {
|
|
24367
24436
|
name: raw.name || file.replace(/\.json$/i, ""),
|
|
24368
24437
|
path: fullPath,
|
|
@@ -24495,9 +24564,9 @@ async function handleCliRaw(ctx, req, res) {
|
|
|
24495
24564
|
}
|
|
24496
24565
|
|
|
24497
24566
|
// src/daemon/dev-auto-implement.ts
|
|
24498
|
-
var
|
|
24499
|
-
var
|
|
24500
|
-
var
|
|
24567
|
+
var fs14 = __toESM(require("fs"));
|
|
24568
|
+
var path21 = __toESM(require("path"));
|
|
24569
|
+
var os20 = __toESM(require("os"));
|
|
24501
24570
|
function getAutoImplPid(ctx) {
|
|
24502
24571
|
const pid = ctx.autoImplProcess?.pid;
|
|
24503
24572
|
return typeof pid === "number" && pid > 0 ? pid : null;
|
|
@@ -24543,38 +24612,38 @@ function resolveAutoImplReference(ctx, category, requestedReference, targetType)
|
|
|
24543
24612
|
return fallback?.type || null;
|
|
24544
24613
|
}
|
|
24545
24614
|
function getLatestScriptVersionDir(scriptsDir) {
|
|
24546
|
-
if (!
|
|
24547
|
-
const versions =
|
|
24615
|
+
if (!fs14.existsSync(scriptsDir)) return null;
|
|
24616
|
+
const versions = fs14.readdirSync(scriptsDir).filter((d) => {
|
|
24548
24617
|
try {
|
|
24549
|
-
return
|
|
24618
|
+
return fs14.statSync(path21.join(scriptsDir, d)).isDirectory();
|
|
24550
24619
|
} catch {
|
|
24551
24620
|
return false;
|
|
24552
24621
|
}
|
|
24553
24622
|
}).sort((a, b) => b.localeCompare(a, void 0, { numeric: true, sensitivity: "base" }));
|
|
24554
24623
|
if (versions.length === 0) return null;
|
|
24555
|
-
return
|
|
24624
|
+
return path21.join(scriptsDir, versions[0]);
|
|
24556
24625
|
}
|
|
24557
24626
|
function resolveAutoImplWritableProviderDir(ctx, category, type, requestedDir) {
|
|
24558
|
-
const canonicalUserDir =
|
|
24559
|
-
const desiredDir = requestedDir ?
|
|
24560
|
-
const upstreamRoot =
|
|
24561
|
-
if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${
|
|
24627
|
+
const canonicalUserDir = path21.resolve(ctx.providerLoader.getUserProviderDir(category, type));
|
|
24628
|
+
const desiredDir = requestedDir ? path21.resolve(requestedDir) : canonicalUserDir;
|
|
24629
|
+
const upstreamRoot = path21.resolve(ctx.providerLoader.getUpstreamDir());
|
|
24630
|
+
if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${path21.sep}`)) {
|
|
24562
24631
|
return { dir: null, reason: `Refusing to write into upstream provider directory: ${desiredDir}` };
|
|
24563
24632
|
}
|
|
24564
|
-
if (
|
|
24633
|
+
if (path21.basename(desiredDir) !== type) {
|
|
24565
24634
|
return { dir: null, reason: `Requested writable provider directory must end with '${type}': ${desiredDir}` };
|
|
24566
24635
|
}
|
|
24567
24636
|
const sourceDir = ctx.findProviderDir(type);
|
|
24568
24637
|
if (!sourceDir) {
|
|
24569
24638
|
return { dir: null, reason: `Provider source directory not found for '${type}'` };
|
|
24570
24639
|
}
|
|
24571
|
-
if (!
|
|
24572
|
-
|
|
24573
|
-
|
|
24640
|
+
if (!fs14.existsSync(desiredDir)) {
|
|
24641
|
+
fs14.mkdirSync(path21.dirname(desiredDir), { recursive: true });
|
|
24642
|
+
fs14.cpSync(sourceDir, desiredDir, { recursive: true });
|
|
24574
24643
|
ctx.log(`Auto-implement writable copy created: ${desiredDir}`);
|
|
24575
24644
|
}
|
|
24576
|
-
const providerJson =
|
|
24577
|
-
if (!
|
|
24645
|
+
const providerJson = path21.join(desiredDir, "provider.json");
|
|
24646
|
+
if (!fs14.existsSync(providerJson)) {
|
|
24578
24647
|
return { dir: null, reason: `provider.json not found in writable provider directory: ${desiredDir}` };
|
|
24579
24648
|
}
|
|
24580
24649
|
return { dir: desiredDir };
|
|
@@ -24582,15 +24651,15 @@ function resolveAutoImplWritableProviderDir(ctx, category, type, requestedDir) {
|
|
|
24582
24651
|
function loadAutoImplReferenceScripts(ctx, referenceType) {
|
|
24583
24652
|
if (!referenceType) return {};
|
|
24584
24653
|
const refDir = ctx.findProviderDir(referenceType);
|
|
24585
|
-
if (!refDir || !
|
|
24654
|
+
if (!refDir || !fs14.existsSync(refDir)) return {};
|
|
24586
24655
|
const referenceScripts = {};
|
|
24587
|
-
const scriptsDir =
|
|
24656
|
+
const scriptsDir = path21.join(refDir, "scripts");
|
|
24588
24657
|
const latestDir = getLatestScriptVersionDir(scriptsDir);
|
|
24589
24658
|
if (!latestDir) return referenceScripts;
|
|
24590
|
-
for (const file of
|
|
24659
|
+
for (const file of fs14.readdirSync(latestDir)) {
|
|
24591
24660
|
if (!file.endsWith(".js")) continue;
|
|
24592
24661
|
try {
|
|
24593
|
-
referenceScripts[file] =
|
|
24662
|
+
referenceScripts[file] = fs14.readFileSync(path21.join(latestDir, file), "utf-8");
|
|
24594
24663
|
} catch {
|
|
24595
24664
|
}
|
|
24596
24665
|
}
|
|
@@ -24698,16 +24767,16 @@ async function handleAutoImplement(ctx, type, req, res) {
|
|
|
24698
24767
|
});
|
|
24699
24768
|
const referenceScripts = loadAutoImplReferenceScripts(ctx, resolvedReference);
|
|
24700
24769
|
const prompt = buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domContext, referenceScripts, comment, resolvedReference, verification);
|
|
24701
|
-
const tmpDir =
|
|
24702
|
-
if (!
|
|
24703
|
-
const promptFile =
|
|
24704
|
-
|
|
24770
|
+
const tmpDir = path21.join(os20.tmpdir(), "adhdev-autoimpl");
|
|
24771
|
+
if (!fs14.existsSync(tmpDir)) fs14.mkdirSync(tmpDir, { recursive: true });
|
|
24772
|
+
const promptFile = path21.join(tmpDir, `prompt-${type}-${Date.now()}.md`);
|
|
24773
|
+
fs14.writeFileSync(promptFile, prompt, "utf-8");
|
|
24705
24774
|
ctx.log(`Auto-implement prompt written to ${promptFile} (${prompt.length} chars)`);
|
|
24706
24775
|
const agentProvider = ctx.providerLoader.resolve(agent) || ctx.providerLoader.getMeta(agent);
|
|
24707
24776
|
const spawn4 = agentProvider?.spawn;
|
|
24708
24777
|
if (!spawn4?.command) {
|
|
24709
24778
|
try {
|
|
24710
|
-
|
|
24779
|
+
fs14.unlinkSync(promptFile);
|
|
24711
24780
|
} catch {
|
|
24712
24781
|
}
|
|
24713
24782
|
ctx.json(res, 400, { error: `Agent '${agent}' has no spawn config. Select a CLI provider with a spawn configuration.` });
|
|
@@ -24809,7 +24878,7 @@ async function handleAutoImplement(ctx, type, req, res) {
|
|
|
24809
24878
|
} catch {
|
|
24810
24879
|
}
|
|
24811
24880
|
try {
|
|
24812
|
-
|
|
24881
|
+
fs14.unlinkSync(promptFile);
|
|
24813
24882
|
} catch {
|
|
24814
24883
|
}
|
|
24815
24884
|
ctx.log(`Auto-implement (ACP) ${success ? "completed" : "failed"}: ${type} (exit: ${code})`);
|
|
@@ -24853,7 +24922,7 @@ async function handleAutoImplement(ctx, type, req, res) {
|
|
|
24853
24922
|
const interactiveFlags = ["--yolo", "--interactive", "-i"];
|
|
24854
24923
|
const baseArgs = [...spawn4.args || []].filter((a) => !interactiveFlags.includes(a));
|
|
24855
24924
|
let shellCmd;
|
|
24856
|
-
const isWin =
|
|
24925
|
+
const isWin = os20.platform() === "win32";
|
|
24857
24926
|
const escapeArg = (a) => isWin ? `"${a.replace(/"/g, '""')}"` : `'${a.replace(/'/g, "'\\''")}'`;
|
|
24858
24927
|
const promptMode = autoImpl?.promptMode ?? "stdin";
|
|
24859
24928
|
const extraArgs = autoImpl?.extraArgs ?? [];
|
|
@@ -24892,7 +24961,7 @@ async function handleAutoImplement(ctx, type, req, res) {
|
|
|
24892
24961
|
try {
|
|
24893
24962
|
const pty = require("node-pty");
|
|
24894
24963
|
ctx.log(`Auto-implement spawn (PTY): ${shellCmd}`);
|
|
24895
|
-
const isWin2 =
|
|
24964
|
+
const isWin2 = os20.platform() === "win32";
|
|
24896
24965
|
child = pty.spawn(isWin2 ? "cmd.exe" : process.env.SHELL || "/bin/zsh", [isWin2 ? "/c" : "-c", shellCmd], {
|
|
24897
24966
|
name: "xterm-256color",
|
|
24898
24967
|
cols: 120,
|
|
@@ -25035,7 +25104,7 @@ async function handleAutoImplement(ctx, type, req, res) {
|
|
|
25035
25104
|
}
|
|
25036
25105
|
});
|
|
25037
25106
|
try {
|
|
25038
|
-
|
|
25107
|
+
fs14.unlinkSync(promptFile);
|
|
25039
25108
|
} catch {
|
|
25040
25109
|
}
|
|
25041
25110
|
ctx.log(`Auto-implement ${success ? "completed" : "failed"}: ${type} (exit: ${code})${verificationSummary ? ` verify=${verificationSummary.pass ? "pass" : "fail"}` : ""}`);
|
|
@@ -25132,7 +25201,7 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
|
|
|
25132
25201
|
setMode: "set_mode.js"
|
|
25133
25202
|
};
|
|
25134
25203
|
const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
|
|
25135
|
-
const scriptsDir =
|
|
25204
|
+
const scriptsDir = path21.join(providerDir, "scripts");
|
|
25136
25205
|
const latestScriptsDir = getLatestScriptVersionDir(scriptsDir);
|
|
25137
25206
|
if (latestScriptsDir) {
|
|
25138
25207
|
lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
|
|
@@ -25140,10 +25209,10 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
|
|
|
25140
25209
|
lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
|
|
25141
25210
|
lines.push("These are the ONLY files you are allowed to modify. Replace the TODO stubs with working implementations.");
|
|
25142
25211
|
lines.push("");
|
|
25143
|
-
for (const file of
|
|
25212
|
+
for (const file of fs14.readdirSync(latestScriptsDir)) {
|
|
25144
25213
|
if (file.endsWith(".js") && targetFileNames.has(file)) {
|
|
25145
25214
|
try {
|
|
25146
|
-
const content =
|
|
25215
|
+
const content = fs14.readFileSync(path21.join(latestScriptsDir, file), "utf-8");
|
|
25147
25216
|
lines.push(`### \`${file}\` \u270F\uFE0F EDIT`);
|
|
25148
25217
|
lines.push("```javascript");
|
|
25149
25218
|
lines.push(content);
|
|
@@ -25153,14 +25222,14 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
|
|
|
25153
25222
|
}
|
|
25154
25223
|
}
|
|
25155
25224
|
}
|
|
25156
|
-
const refFiles =
|
|
25225
|
+
const refFiles = fs14.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
|
|
25157
25226
|
if (refFiles.length > 0) {
|
|
25158
25227
|
lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
|
|
25159
25228
|
lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
|
|
25160
25229
|
lines.push("");
|
|
25161
25230
|
for (const file of refFiles) {
|
|
25162
25231
|
try {
|
|
25163
|
-
const content =
|
|
25232
|
+
const content = fs14.readFileSync(path21.join(latestScriptsDir, file), "utf-8");
|
|
25164
25233
|
lines.push(`### \`${file}\` \u{1F512}`);
|
|
25165
25234
|
lines.push("```javascript");
|
|
25166
25235
|
lines.push(content);
|
|
@@ -25201,11 +25270,11 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
|
|
|
25201
25270
|
lines.push("");
|
|
25202
25271
|
}
|
|
25203
25272
|
}
|
|
25204
|
-
const docsDir =
|
|
25273
|
+
const docsDir = path21.join(providerDir, "../../docs");
|
|
25205
25274
|
const loadGuide = (name) => {
|
|
25206
25275
|
try {
|
|
25207
|
-
const p =
|
|
25208
|
-
if (
|
|
25276
|
+
const p = path21.join(docsDir, name);
|
|
25277
|
+
if (fs14.existsSync(p)) return fs14.readFileSync(p, "utf-8");
|
|
25209
25278
|
} catch {
|
|
25210
25279
|
}
|
|
25211
25280
|
return null;
|
|
@@ -25441,7 +25510,7 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
|
|
|
25441
25510
|
parseApproval: "parse_approval.js"
|
|
25442
25511
|
};
|
|
25443
25512
|
const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
|
|
25444
|
-
const scriptsDir =
|
|
25513
|
+
const scriptsDir = path21.join(providerDir, "scripts");
|
|
25445
25514
|
const latestScriptsDir = getLatestScriptVersionDir(scriptsDir);
|
|
25446
25515
|
if (latestScriptsDir) {
|
|
25447
25516
|
lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
|
|
@@ -25449,11 +25518,11 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
|
|
|
25449
25518
|
lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
|
|
25450
25519
|
lines.push("These are the ONLY files you are allowed to modify. Replace TODO or heuristic-only logic with working PTY-aware implementations.");
|
|
25451
25520
|
lines.push("");
|
|
25452
|
-
for (const file of
|
|
25521
|
+
for (const file of fs14.readdirSync(latestScriptsDir)) {
|
|
25453
25522
|
if (!file.endsWith(".js")) continue;
|
|
25454
25523
|
if (!targetFileNames.has(file)) continue;
|
|
25455
25524
|
try {
|
|
25456
|
-
const content =
|
|
25525
|
+
const content = fs14.readFileSync(path21.join(latestScriptsDir, file), "utf-8");
|
|
25457
25526
|
lines.push(`### \`${file}\` \u270F\uFE0F EDIT`);
|
|
25458
25527
|
lines.push("```javascript");
|
|
25459
25528
|
lines.push(content);
|
|
@@ -25462,14 +25531,14 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
|
|
|
25462
25531
|
} catch {
|
|
25463
25532
|
}
|
|
25464
25533
|
}
|
|
25465
|
-
const refFiles =
|
|
25534
|
+
const refFiles = fs14.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
|
|
25466
25535
|
if (refFiles.length > 0) {
|
|
25467
25536
|
lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
|
|
25468
25537
|
lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
|
|
25469
25538
|
lines.push("");
|
|
25470
25539
|
for (const file of refFiles) {
|
|
25471
25540
|
try {
|
|
25472
|
-
const content =
|
|
25541
|
+
const content = fs14.readFileSync(path21.join(latestScriptsDir, file), "utf-8");
|
|
25473
25542
|
lines.push(`### \`${file}\` \u{1F512}`);
|
|
25474
25543
|
lines.push("```javascript");
|
|
25475
25544
|
lines.push(content);
|
|
@@ -25502,11 +25571,11 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
|
|
|
25502
25571
|
lines.push("");
|
|
25503
25572
|
}
|
|
25504
25573
|
}
|
|
25505
|
-
const docsDir =
|
|
25574
|
+
const docsDir = path21.join(providerDir, "../../docs");
|
|
25506
25575
|
const loadGuide = (name) => {
|
|
25507
25576
|
try {
|
|
25508
|
-
const p =
|
|
25509
|
-
if (
|
|
25577
|
+
const p = path21.join(docsDir, name);
|
|
25578
|
+
if (fs14.existsSync(p)) return fs14.readFileSync(p, "utf-8");
|
|
25510
25579
|
} catch {
|
|
25511
25580
|
}
|
|
25512
25581
|
return null;
|
|
@@ -25952,8 +26021,8 @@ var DevServer = class _DevServer {
|
|
|
25952
26021
|
}
|
|
25953
26022
|
getEndpointList() {
|
|
25954
26023
|
return this.routes.map((r) => {
|
|
25955
|
-
const
|
|
25956
|
-
return `${r.method.padEnd(5)} ${
|
|
26024
|
+
const path23 = typeof r.pattern === "string" ? r.pattern : r.pattern.source.replace(/\\\//g, "/").replace(/\(\[.*?\]\+\)/g, ":type").replace(/[\^$]/g, "");
|
|
26025
|
+
return `${r.method.padEnd(5)} ${path23}`;
|
|
25957
26026
|
});
|
|
25958
26027
|
}
|
|
25959
26028
|
async start(port = DEV_SERVER_PORT) {
|
|
@@ -26241,12 +26310,12 @@ var DevServer = class _DevServer {
|
|
|
26241
26310
|
// ─── DevConsole SPA ───
|
|
26242
26311
|
getConsoleDistDir() {
|
|
26243
26312
|
const candidates = [
|
|
26244
|
-
|
|
26245
|
-
|
|
26246
|
-
|
|
26313
|
+
path22.resolve(__dirname, "../../web-devconsole/dist"),
|
|
26314
|
+
path22.resolve(__dirname, "../../../web-devconsole/dist"),
|
|
26315
|
+
path22.join(process.cwd(), "packages/web-devconsole/dist")
|
|
26247
26316
|
];
|
|
26248
26317
|
for (const dir of candidates) {
|
|
26249
|
-
if (
|
|
26318
|
+
if (fs15.existsSync(path22.join(dir, "index.html"))) return dir;
|
|
26250
26319
|
}
|
|
26251
26320
|
return null;
|
|
26252
26321
|
}
|
|
@@ -26256,9 +26325,9 @@ var DevServer = class _DevServer {
|
|
|
26256
26325
|
this.json(res, 500, { error: "DevConsole not found. Run: npm run build -w packages/web-devconsole" });
|
|
26257
26326
|
return;
|
|
26258
26327
|
}
|
|
26259
|
-
const htmlPath =
|
|
26328
|
+
const htmlPath = path22.join(distDir, "index.html");
|
|
26260
26329
|
try {
|
|
26261
|
-
const html =
|
|
26330
|
+
const html = fs15.readFileSync(htmlPath, "utf-8");
|
|
26262
26331
|
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
26263
26332
|
res.end(html);
|
|
26264
26333
|
} catch (e) {
|
|
@@ -26281,15 +26350,15 @@ var DevServer = class _DevServer {
|
|
|
26281
26350
|
this.json(res, 404, { error: "Not found" });
|
|
26282
26351
|
return;
|
|
26283
26352
|
}
|
|
26284
|
-
const safePath =
|
|
26285
|
-
const filePath =
|
|
26353
|
+
const safePath = path22.normalize(pathname).replace(/^\.\.\//, "");
|
|
26354
|
+
const filePath = path22.join(distDir, safePath);
|
|
26286
26355
|
if (!filePath.startsWith(distDir)) {
|
|
26287
26356
|
this.json(res, 403, { error: "Forbidden" });
|
|
26288
26357
|
return;
|
|
26289
26358
|
}
|
|
26290
26359
|
try {
|
|
26291
|
-
const content =
|
|
26292
|
-
const ext =
|
|
26360
|
+
const content = fs15.readFileSync(filePath);
|
|
26361
|
+
const ext = path22.extname(filePath);
|
|
26293
26362
|
const contentType = _DevServer.MIME_MAP[ext] || "application/octet-stream";
|
|
26294
26363
|
res.writeHead(200, { "Content-Type": contentType, "Cache-Control": "public, max-age=31536000, immutable" });
|
|
26295
26364
|
res.end(content);
|
|
@@ -26397,14 +26466,14 @@ var DevServer = class _DevServer {
|
|
|
26397
26466
|
const files = [];
|
|
26398
26467
|
const scan = (d, prefix) => {
|
|
26399
26468
|
try {
|
|
26400
|
-
for (const entry of
|
|
26469
|
+
for (const entry of fs15.readdirSync(d, { withFileTypes: true })) {
|
|
26401
26470
|
if (entry.name.startsWith(".") || entry.name.endsWith(".bak")) continue;
|
|
26402
26471
|
const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
26403
26472
|
if (entry.isDirectory()) {
|
|
26404
26473
|
files.push({ path: rel, size: 0, type: "dir" });
|
|
26405
|
-
scan(
|
|
26474
|
+
scan(path22.join(d, entry.name), rel);
|
|
26406
26475
|
} else {
|
|
26407
|
-
const stat =
|
|
26476
|
+
const stat = fs15.statSync(path22.join(d, entry.name));
|
|
26408
26477
|
files.push({ path: rel, size: stat.size, type: "file" });
|
|
26409
26478
|
}
|
|
26410
26479
|
}
|
|
@@ -26427,16 +26496,16 @@ var DevServer = class _DevServer {
|
|
|
26427
26496
|
this.json(res, 404, { error: `Provider directory not found: ${type}` });
|
|
26428
26497
|
return;
|
|
26429
26498
|
}
|
|
26430
|
-
const fullPath =
|
|
26499
|
+
const fullPath = path22.resolve(dir, path22.normalize(filePath));
|
|
26431
26500
|
if (!fullPath.startsWith(dir)) {
|
|
26432
26501
|
this.json(res, 403, { error: "Forbidden" });
|
|
26433
26502
|
return;
|
|
26434
26503
|
}
|
|
26435
|
-
if (!
|
|
26504
|
+
if (!fs15.existsSync(fullPath) || fs15.statSync(fullPath).isDirectory()) {
|
|
26436
26505
|
this.json(res, 404, { error: `File not found: ${filePath}` });
|
|
26437
26506
|
return;
|
|
26438
26507
|
}
|
|
26439
|
-
const content =
|
|
26508
|
+
const content = fs15.readFileSync(fullPath, "utf-8");
|
|
26440
26509
|
this.json(res, 200, { type, path: filePath, content, lines: content.split("\n").length });
|
|
26441
26510
|
}
|
|
26442
26511
|
/** POST /api/providers/:type/file — write a file { path, content } */
|
|
@@ -26452,15 +26521,15 @@ var DevServer = class _DevServer {
|
|
|
26452
26521
|
this.json(res, 404, { error: `Provider directory not found: ${type}` });
|
|
26453
26522
|
return;
|
|
26454
26523
|
}
|
|
26455
|
-
const fullPath =
|
|
26524
|
+
const fullPath = path22.resolve(dir, path22.normalize(filePath));
|
|
26456
26525
|
if (!fullPath.startsWith(dir)) {
|
|
26457
26526
|
this.json(res, 403, { error: "Forbidden" });
|
|
26458
26527
|
return;
|
|
26459
26528
|
}
|
|
26460
26529
|
try {
|
|
26461
|
-
if (
|
|
26462
|
-
|
|
26463
|
-
|
|
26530
|
+
if (fs15.existsSync(fullPath)) fs15.copyFileSync(fullPath, fullPath + ".bak");
|
|
26531
|
+
fs15.mkdirSync(path22.dirname(fullPath), { recursive: true });
|
|
26532
|
+
fs15.writeFileSync(fullPath, content, "utf-8");
|
|
26464
26533
|
this.log(`File saved: ${fullPath} (${content.length} chars)`);
|
|
26465
26534
|
this.providerLoader.reload();
|
|
26466
26535
|
this.json(res, 200, { saved: true, path: filePath, chars: content.length });
|
|
@@ -26476,9 +26545,9 @@ var DevServer = class _DevServer {
|
|
|
26476
26545
|
return;
|
|
26477
26546
|
}
|
|
26478
26547
|
for (const name of ["scripts.js", "provider.json"]) {
|
|
26479
|
-
const p =
|
|
26480
|
-
if (
|
|
26481
|
-
const source =
|
|
26548
|
+
const p = path22.join(dir, name);
|
|
26549
|
+
if (fs15.existsSync(p)) {
|
|
26550
|
+
const source = fs15.readFileSync(p, "utf-8");
|
|
26482
26551
|
this.json(res, 200, { type, path: p, source, lines: source.split("\n").length });
|
|
26483
26552
|
return;
|
|
26484
26553
|
}
|
|
@@ -26497,11 +26566,11 @@ var DevServer = class _DevServer {
|
|
|
26497
26566
|
this.json(res, 404, { error: `Provider not found: ${type}` });
|
|
26498
26567
|
return;
|
|
26499
26568
|
}
|
|
26500
|
-
const target =
|
|
26501
|
-
const targetPath =
|
|
26569
|
+
const target = fs15.existsSync(path22.join(dir, "scripts.js")) ? "scripts.js" : "provider.json";
|
|
26570
|
+
const targetPath = path22.join(dir, target);
|
|
26502
26571
|
try {
|
|
26503
|
-
if (
|
|
26504
|
-
|
|
26572
|
+
if (fs15.existsSync(targetPath)) fs15.copyFileSync(targetPath, targetPath + ".bak");
|
|
26573
|
+
fs15.writeFileSync(targetPath, source, "utf-8");
|
|
26505
26574
|
this.log(`Saved provider: ${targetPath} (${source.length} chars)`);
|
|
26506
26575
|
this.providerLoader.reload();
|
|
26507
26576
|
this.json(res, 200, { saved: true, path: targetPath, chars: source.length });
|
|
@@ -26645,21 +26714,21 @@ var DevServer = class _DevServer {
|
|
|
26645
26714
|
}
|
|
26646
26715
|
let targetDir;
|
|
26647
26716
|
targetDir = this.providerLoader.getUserProviderDir(category, type);
|
|
26648
|
-
const jsonPath =
|
|
26649
|
-
if (
|
|
26717
|
+
const jsonPath = path22.join(targetDir, "provider.json");
|
|
26718
|
+
if (fs15.existsSync(jsonPath)) {
|
|
26650
26719
|
this.json(res, 409, { error: `Provider already exists at ${targetDir}`, path: targetDir });
|
|
26651
26720
|
return;
|
|
26652
26721
|
}
|
|
26653
26722
|
try {
|
|
26654
26723
|
const result = generateFiles(type, name, category, { cdpPorts, cli, processName, installPath, binary, extensionId, version, osPaths, processNames });
|
|
26655
|
-
|
|
26656
|
-
|
|
26724
|
+
fs15.mkdirSync(targetDir, { recursive: true });
|
|
26725
|
+
fs15.writeFileSync(jsonPath, result["provider.json"], "utf-8");
|
|
26657
26726
|
const createdFiles = ["provider.json"];
|
|
26658
26727
|
if (result.files) {
|
|
26659
26728
|
for (const [relPath, content] of Object.entries(result.files)) {
|
|
26660
|
-
const fullPath =
|
|
26661
|
-
|
|
26662
|
-
|
|
26729
|
+
const fullPath = path22.join(targetDir, relPath);
|
|
26730
|
+
fs15.mkdirSync(path22.dirname(fullPath), { recursive: true });
|
|
26731
|
+
fs15.writeFileSync(fullPath, content, "utf-8");
|
|
26663
26732
|
createdFiles.push(relPath);
|
|
26664
26733
|
}
|
|
26665
26734
|
}
|
|
@@ -26708,38 +26777,38 @@ var DevServer = class _DevServer {
|
|
|
26708
26777
|
}
|
|
26709
26778
|
// ─── Phase 2: Auto-Implement Backend ───
|
|
26710
26779
|
getLatestScriptVersionDir(scriptsDir) {
|
|
26711
|
-
if (!
|
|
26712
|
-
const versions =
|
|
26780
|
+
if (!fs15.existsSync(scriptsDir)) return null;
|
|
26781
|
+
const versions = fs15.readdirSync(scriptsDir).filter((d) => {
|
|
26713
26782
|
try {
|
|
26714
|
-
return
|
|
26783
|
+
return fs15.statSync(path22.join(scriptsDir, d)).isDirectory();
|
|
26715
26784
|
} catch {
|
|
26716
26785
|
return false;
|
|
26717
26786
|
}
|
|
26718
26787
|
}).sort((a, b) => b.localeCompare(a, void 0, { numeric: true, sensitivity: "base" }));
|
|
26719
26788
|
if (versions.length === 0) return null;
|
|
26720
|
-
return
|
|
26789
|
+
return path22.join(scriptsDir, versions[0]);
|
|
26721
26790
|
}
|
|
26722
26791
|
resolveAutoImplWritableProviderDir(category, type, requestedDir) {
|
|
26723
|
-
const canonicalUserDir =
|
|
26724
|
-
const desiredDir = requestedDir ?
|
|
26725
|
-
const upstreamRoot =
|
|
26726
|
-
if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${
|
|
26792
|
+
const canonicalUserDir = path22.resolve(this.providerLoader.getUserProviderDir(category, type));
|
|
26793
|
+
const desiredDir = requestedDir ? path22.resolve(requestedDir) : canonicalUserDir;
|
|
26794
|
+
const upstreamRoot = path22.resolve(this.providerLoader.getUpstreamDir());
|
|
26795
|
+
if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${path22.sep}`)) {
|
|
26727
26796
|
return { dir: null, reason: `Refusing to write into upstream provider directory: ${desiredDir}` };
|
|
26728
26797
|
}
|
|
26729
|
-
if (
|
|
26798
|
+
if (path22.basename(desiredDir) !== type) {
|
|
26730
26799
|
return { dir: null, reason: `Requested writable provider directory must end with '${type}': ${desiredDir}` };
|
|
26731
26800
|
}
|
|
26732
26801
|
const sourceDir = this.findProviderDir(type);
|
|
26733
26802
|
if (!sourceDir) {
|
|
26734
26803
|
return { dir: null, reason: `Provider source directory not found for '${type}'` };
|
|
26735
26804
|
}
|
|
26736
|
-
if (!
|
|
26737
|
-
|
|
26738
|
-
|
|
26805
|
+
if (!fs15.existsSync(desiredDir)) {
|
|
26806
|
+
fs15.mkdirSync(path22.dirname(desiredDir), { recursive: true });
|
|
26807
|
+
fs15.cpSync(sourceDir, desiredDir, { recursive: true });
|
|
26739
26808
|
this.log(`Auto-implement writable copy created: ${desiredDir}`);
|
|
26740
26809
|
}
|
|
26741
|
-
const providerJson =
|
|
26742
|
-
if (!
|
|
26810
|
+
const providerJson = path22.join(desiredDir, "provider.json");
|
|
26811
|
+
if (!fs15.existsSync(providerJson)) {
|
|
26743
26812
|
return { dir: null, reason: `provider.json not found in writable provider directory: ${desiredDir}` };
|
|
26744
26813
|
}
|
|
26745
26814
|
return { dir: desiredDir };
|
|
@@ -26774,7 +26843,7 @@ var DevServer = class _DevServer {
|
|
|
26774
26843
|
setMode: "set_mode.js"
|
|
26775
26844
|
};
|
|
26776
26845
|
const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
|
|
26777
|
-
const scriptsDir =
|
|
26846
|
+
const scriptsDir = path22.join(providerDir, "scripts");
|
|
26778
26847
|
const latestScriptsDir = this.getLatestScriptVersionDir(scriptsDir);
|
|
26779
26848
|
if (latestScriptsDir) {
|
|
26780
26849
|
lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
|
|
@@ -26782,10 +26851,10 @@ var DevServer = class _DevServer {
|
|
|
26782
26851
|
lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
|
|
26783
26852
|
lines.push("These are the ONLY files you are allowed to modify. Replace the TODO stubs with working implementations.");
|
|
26784
26853
|
lines.push("");
|
|
26785
|
-
for (const file of
|
|
26854
|
+
for (const file of fs15.readdirSync(latestScriptsDir)) {
|
|
26786
26855
|
if (file.endsWith(".js") && targetFileNames.has(file)) {
|
|
26787
26856
|
try {
|
|
26788
|
-
const content =
|
|
26857
|
+
const content = fs15.readFileSync(path22.join(latestScriptsDir, file), "utf-8");
|
|
26789
26858
|
lines.push(`### \`${file}\` \u270F\uFE0F EDIT`);
|
|
26790
26859
|
lines.push("```javascript");
|
|
26791
26860
|
lines.push(content);
|
|
@@ -26795,14 +26864,14 @@ var DevServer = class _DevServer {
|
|
|
26795
26864
|
}
|
|
26796
26865
|
}
|
|
26797
26866
|
}
|
|
26798
|
-
const refFiles =
|
|
26867
|
+
const refFiles = fs15.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
|
|
26799
26868
|
if (refFiles.length > 0) {
|
|
26800
26869
|
lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
|
|
26801
26870
|
lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
|
|
26802
26871
|
lines.push("");
|
|
26803
26872
|
for (const file of refFiles) {
|
|
26804
26873
|
try {
|
|
26805
|
-
const content =
|
|
26874
|
+
const content = fs15.readFileSync(path22.join(latestScriptsDir, file), "utf-8");
|
|
26806
26875
|
lines.push(`### \`${file}\` \u{1F512}`);
|
|
26807
26876
|
lines.push("```javascript");
|
|
26808
26877
|
lines.push(content);
|
|
@@ -26843,11 +26912,11 @@ var DevServer = class _DevServer {
|
|
|
26843
26912
|
lines.push("");
|
|
26844
26913
|
}
|
|
26845
26914
|
}
|
|
26846
|
-
const docsDir =
|
|
26915
|
+
const docsDir = path22.join(providerDir, "../../docs");
|
|
26847
26916
|
const loadGuide = (name) => {
|
|
26848
26917
|
try {
|
|
26849
|
-
const p =
|
|
26850
|
-
if (
|
|
26918
|
+
const p = path22.join(docsDir, name);
|
|
26919
|
+
if (fs15.existsSync(p)) return fs15.readFileSync(p, "utf-8");
|
|
26851
26920
|
} catch {
|
|
26852
26921
|
}
|
|
26853
26922
|
return null;
|
|
@@ -27020,7 +27089,7 @@ var DevServer = class _DevServer {
|
|
|
27020
27089
|
parseApproval: "parse_approval.js"
|
|
27021
27090
|
};
|
|
27022
27091
|
const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
|
|
27023
|
-
const scriptsDir =
|
|
27092
|
+
const scriptsDir = path22.join(providerDir, "scripts");
|
|
27024
27093
|
const latestScriptsDir = this.getLatestScriptVersionDir(scriptsDir);
|
|
27025
27094
|
if (latestScriptsDir) {
|
|
27026
27095
|
lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
|
|
@@ -27028,11 +27097,11 @@ var DevServer = class _DevServer {
|
|
|
27028
27097
|
lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
|
|
27029
27098
|
lines.push("These are the ONLY files you are allowed to modify. Replace TODO or heuristic-only logic with working PTY-aware implementations.");
|
|
27030
27099
|
lines.push("");
|
|
27031
|
-
for (const file of
|
|
27100
|
+
for (const file of fs15.readdirSync(latestScriptsDir)) {
|
|
27032
27101
|
if (!file.endsWith(".js")) continue;
|
|
27033
27102
|
if (!targetFileNames.has(file)) continue;
|
|
27034
27103
|
try {
|
|
27035
|
-
const content =
|
|
27104
|
+
const content = fs15.readFileSync(path22.join(latestScriptsDir, file), "utf-8");
|
|
27036
27105
|
lines.push(`### \`${file}\` \u270F\uFE0F EDIT`);
|
|
27037
27106
|
lines.push("```javascript");
|
|
27038
27107
|
lines.push(content);
|
|
@@ -27041,14 +27110,14 @@ var DevServer = class _DevServer {
|
|
|
27041
27110
|
} catch {
|
|
27042
27111
|
}
|
|
27043
27112
|
}
|
|
27044
|
-
const refFiles =
|
|
27113
|
+
const refFiles = fs15.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
|
|
27045
27114
|
if (refFiles.length > 0) {
|
|
27046
27115
|
lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
|
|
27047
27116
|
lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
|
|
27048
27117
|
lines.push("");
|
|
27049
27118
|
for (const file of refFiles) {
|
|
27050
27119
|
try {
|
|
27051
|
-
const content =
|
|
27120
|
+
const content = fs15.readFileSync(path22.join(latestScriptsDir, file), "utf-8");
|
|
27052
27121
|
lines.push(`### \`${file}\` \u{1F512}`);
|
|
27053
27122
|
lines.push("```javascript");
|
|
27054
27123
|
lines.push(content);
|
|
@@ -27081,11 +27150,11 @@ var DevServer = class _DevServer {
|
|
|
27081
27150
|
lines.push("");
|
|
27082
27151
|
}
|
|
27083
27152
|
}
|
|
27084
|
-
const docsDir =
|
|
27153
|
+
const docsDir = path22.join(providerDir, "../../docs");
|
|
27085
27154
|
const loadGuide = (name) => {
|
|
27086
27155
|
try {
|
|
27087
|
-
const p =
|
|
27088
|
-
if (
|
|
27156
|
+
const p = path22.join(docsDir, name);
|
|
27157
|
+
if (fs15.existsSync(p)) return fs15.readFileSync(p, "utf-8");
|
|
27089
27158
|
} catch {
|
|
27090
27159
|
}
|
|
27091
27160
|
return null;
|
|
@@ -27960,8 +28029,8 @@ async function installExtension(ide, extension) {
|
|
|
27960
28029
|
const res = await fetch(extension.vsixUrl);
|
|
27961
28030
|
if (res.ok) {
|
|
27962
28031
|
const buffer = Buffer.from(await res.arrayBuffer());
|
|
27963
|
-
const
|
|
27964
|
-
|
|
28032
|
+
const fs16 = await import("fs");
|
|
28033
|
+
fs16.writeFileSync(vsixPath, buffer);
|
|
27965
28034
|
return new Promise((resolve12) => {
|
|
27966
28035
|
const cmd = `"${ide.cliCommand}" --install-extension "${vsixPath}" --force`;
|
|
27967
28036
|
(0, import_child_process11.exec)(cmd, { timeout: 6e4 }, (error, _stdout, stderr) => {
|