@adhdev/daemon-standalone 0.9.50 → 0.9.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +462 -400
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/public/assets/{index-BNCOpUZd.js → index-CgLuVDjL.js} +28 -27
- package/public/index.html +1 -1
package/dist/index.js
CHANGED
|
@@ -29209,14 +29209,14 @@ var require_dist2 = __commonJS({
|
|
|
29209
29209
|
}
|
|
29210
29210
|
return cachedPty;
|
|
29211
29211
|
}
|
|
29212
|
-
var
|
|
29212
|
+
var os8;
|
|
29213
29213
|
var cachedPty;
|
|
29214
29214
|
var NodePtyRuntimeTransport;
|
|
29215
29215
|
var NodePtyTransportFactory;
|
|
29216
29216
|
var init_pty_transport = __esm2({
|
|
29217
29217
|
"src/cli-adapters/pty-transport.ts"() {
|
|
29218
29218
|
"use strict";
|
|
29219
|
-
|
|
29219
|
+
os8 = __toESM2(require("os"));
|
|
29220
29220
|
init_spawn_env();
|
|
29221
29221
|
NodePtyRuntimeTransport = class {
|
|
29222
29222
|
constructor(handle) {
|
|
@@ -29253,11 +29253,11 @@ var require_dist2 = __commonJS({
|
|
|
29253
29253
|
let cwd = options.cwd;
|
|
29254
29254
|
if (cwd) {
|
|
29255
29255
|
try {
|
|
29256
|
-
const
|
|
29257
|
-
const stat4 =
|
|
29258
|
-
if (!stat4.isDirectory()) cwd =
|
|
29256
|
+
const fs16 = require("fs");
|
|
29257
|
+
const stat4 = fs16.statSync(cwd);
|
|
29258
|
+
if (!stat4.isDirectory()) cwd = os8.homedir();
|
|
29259
29259
|
} catch {
|
|
29260
|
-
cwd =
|
|
29260
|
+
cwd = os8.homedir();
|
|
29261
29261
|
}
|
|
29262
29262
|
}
|
|
29263
29263
|
const handle = pty.spawn(command, args, {
|
|
@@ -29335,11 +29335,11 @@ var require_dist2 = __commonJS({
|
|
|
29335
29335
|
function findBinary(name) {
|
|
29336
29336
|
const trimmed = String(name || "").trim();
|
|
29337
29337
|
if (!trimmed) return trimmed;
|
|
29338
|
-
const expanded = trimmed.startsWith("~") ?
|
|
29339
|
-
if (
|
|
29340
|
-
return
|
|
29338
|
+
const expanded = trimmed.startsWith("~") ? path10.join(os9.homedir(), trimmed.slice(1)) : trimmed;
|
|
29339
|
+
if (path10.isAbsolute(expanded) || expanded.includes("/") || expanded.includes("\\")) {
|
|
29340
|
+
return path10.isAbsolute(expanded) ? expanded : path10.resolve(expanded);
|
|
29341
29341
|
}
|
|
29342
|
-
const isWin =
|
|
29342
|
+
const isWin = os9.platform() === "win32";
|
|
29343
29343
|
try {
|
|
29344
29344
|
const cmd = isWin ? `where ${trimmed}` : `which ${trimmed}`;
|
|
29345
29345
|
return (0, import_child_process4.execSync)(cmd, {
|
|
@@ -29353,14 +29353,14 @@ var require_dist2 = __commonJS({
|
|
|
29353
29353
|
}
|
|
29354
29354
|
}
|
|
29355
29355
|
function isScriptBinary(binaryPath) {
|
|
29356
|
-
if (!
|
|
29356
|
+
if (!path10.isAbsolute(binaryPath)) return false;
|
|
29357
29357
|
try {
|
|
29358
|
-
const
|
|
29359
|
-
const resolved =
|
|
29358
|
+
const fs16 = require("fs");
|
|
29359
|
+
const resolved = fs16.realpathSync(binaryPath);
|
|
29360
29360
|
const head = Buffer.alloc(8);
|
|
29361
|
-
const fd =
|
|
29362
|
-
|
|
29363
|
-
|
|
29361
|
+
const fd = fs16.openSync(resolved, "r");
|
|
29362
|
+
fs16.readSync(fd, head, 0, 8, 0);
|
|
29363
|
+
fs16.closeSync(fd);
|
|
29364
29364
|
let i = 0;
|
|
29365
29365
|
if (head[0] === 239 && head[1] === 187 && head[2] === 191) i = 3;
|
|
29366
29366
|
return head[i] === 35 && head[i + 1] === 33;
|
|
@@ -29369,14 +29369,14 @@ var require_dist2 = __commonJS({
|
|
|
29369
29369
|
}
|
|
29370
29370
|
}
|
|
29371
29371
|
function looksLikeMachOOrElf(filePath) {
|
|
29372
|
-
if (!
|
|
29372
|
+
if (!path10.isAbsolute(filePath)) return false;
|
|
29373
29373
|
try {
|
|
29374
|
-
const
|
|
29375
|
-
const resolved =
|
|
29374
|
+
const fs16 = require("fs");
|
|
29375
|
+
const resolved = fs16.realpathSync(filePath);
|
|
29376
29376
|
const buf = Buffer.alloc(8);
|
|
29377
|
-
const fd =
|
|
29378
|
-
|
|
29379
|
-
|
|
29377
|
+
const fd = fs16.openSync(resolved, "r");
|
|
29378
|
+
fs16.readSync(fd, buf, 0, 8, 0);
|
|
29379
|
+
fs16.closeSync(fd);
|
|
29380
29380
|
let i = 0;
|
|
29381
29381
|
if (buf[0] === 239 && buf[1] === 187 && buf[2] === 191) i = 3;
|
|
29382
29382
|
const b2 = buf.subarray(i);
|
|
@@ -29392,7 +29392,7 @@ var require_dist2 = __commonJS({
|
|
|
29392
29392
|
}
|
|
29393
29393
|
function shSingleQuote(arg) {
|
|
29394
29394
|
if (/^[a-zA-Z0-9@%_+=:,./-]+$/.test(arg)) return arg;
|
|
29395
|
-
if (
|
|
29395
|
+
if (os9.platform() === "win32") {
|
|
29396
29396
|
return `"${arg.replace(/"/g, '""')}"`;
|
|
29397
29397
|
}
|
|
29398
29398
|
return `'${arg.replace(/'/g, `'\\''`)}'`;
|
|
@@ -29519,16 +29519,16 @@ var require_dist2 = __commonJS({
|
|
|
29519
29519
|
}
|
|
29520
29520
|
};
|
|
29521
29521
|
}
|
|
29522
|
-
var
|
|
29523
|
-
var
|
|
29522
|
+
var os9;
|
|
29523
|
+
var path10;
|
|
29524
29524
|
var import_child_process4;
|
|
29525
29525
|
var buildCliSpawnEnv;
|
|
29526
29526
|
var COMMON_COMPARABLE_WRAP_WORDS;
|
|
29527
29527
|
var init_provider_cli_shared = __esm2({
|
|
29528
29528
|
"src/cli-adapters/provider-cli-shared.ts"() {
|
|
29529
29529
|
"use strict";
|
|
29530
|
-
|
|
29531
|
-
|
|
29530
|
+
os9 = __toESM2(require("os"));
|
|
29531
|
+
path10 = __toESM2(require("path"));
|
|
29532
29532
|
import_child_process4 = require("child_process");
|
|
29533
29533
|
init_spawn_env();
|
|
29534
29534
|
buildCliSpawnEnv = import_session_host_core3.sanitizeSpawnEnv;
|
|
@@ -29835,13 +29835,13 @@ var require_dist2 = __commonJS({
|
|
|
29835
29835
|
const { spawn: spawnConfig } = provider;
|
|
29836
29836
|
const configuredCommand = typeof runtimeSettings.executablePath === "string" && runtimeSettings.executablePath.trim() ? runtimeSettings.executablePath.trim() : spawnConfig.command;
|
|
29837
29837
|
const binaryPath = findBinary(configuredCommand);
|
|
29838
|
-
const isWin =
|
|
29838
|
+
const isWin = os10.platform() === "win32";
|
|
29839
29839
|
const allArgs = [...spawnConfig.args, ...extraArgs];
|
|
29840
29840
|
let shellCmd;
|
|
29841
29841
|
let shellArgs;
|
|
29842
|
-
const useShellUnix = !isWin && (!!spawnConfig.shell || !
|
|
29842
|
+
const useShellUnix = !isWin && (!!spawnConfig.shell || !path11.isAbsolute(binaryPath) || isScriptBinary(binaryPath) || !looksLikeMachOOrElf(binaryPath));
|
|
29843
29843
|
const isCmdShim = isWin && /\.(cmd|bat)$/i.test(binaryPath);
|
|
29844
|
-
const useShellWin = !!spawnConfig.shell || isCmdShim || !
|
|
29844
|
+
const useShellWin = !!spawnConfig.shell || isCmdShim || !path11.isAbsolute(binaryPath) || isScriptBinary(binaryPath);
|
|
29845
29845
|
const useShell = isWin ? useShellWin : useShellUnix;
|
|
29846
29846
|
if (useShell) {
|
|
29847
29847
|
shellCmd = isWin ? "cmd.exe" : process.env.SHELL || "/bin/zsh";
|
|
@@ -29917,14 +29917,14 @@ var require_dist2 = __commonJS({
|
|
|
29917
29917
|
}
|
|
29918
29918
|
return "";
|
|
29919
29919
|
}
|
|
29920
|
-
var
|
|
29921
|
-
var
|
|
29920
|
+
var os10;
|
|
29921
|
+
var path11;
|
|
29922
29922
|
var import_session_host_core22;
|
|
29923
29923
|
var init_provider_cli_runtime = __esm2({
|
|
29924
29924
|
"src/cli-adapters/provider-cli-runtime.ts"() {
|
|
29925
29925
|
"use strict";
|
|
29926
|
-
|
|
29927
|
-
|
|
29926
|
+
os10 = __toESM2(require("os"));
|
|
29927
|
+
path11 = __toESM2(require("path"));
|
|
29928
29928
|
import_session_host_core22 = require_dist();
|
|
29929
29929
|
init_provider_cli_shared();
|
|
29930
29930
|
}
|
|
@@ -30044,13 +30044,13 @@ var require_dist2 = __commonJS({
|
|
|
30044
30044
|
return;
|
|
30045
30045
|
}
|
|
30046
30046
|
}
|
|
30047
|
-
var
|
|
30047
|
+
var os11;
|
|
30048
30048
|
var COMMITTED_ACTIVITY_PREFIX_BLOCK_RE;
|
|
30049
30049
|
var ProviderCliAdapter;
|
|
30050
30050
|
var init_provider_cli_adapter = __esm2({
|
|
30051
30051
|
"src/cli-adapters/provider-cli-adapter.ts"() {
|
|
30052
30052
|
"use strict";
|
|
30053
|
-
|
|
30053
|
+
os11 = __toESM2(require("os"));
|
|
30054
30054
|
init_logger();
|
|
30055
30055
|
init_debug_config();
|
|
30056
30056
|
init_terminal_screen();
|
|
@@ -30070,7 +30070,7 @@ var require_dist2 = __commonJS({
|
|
|
30070
30070
|
this.transportFactory = transportFactory;
|
|
30071
30071
|
this.cliType = provider.type;
|
|
30072
30072
|
this.cliName = provider.name;
|
|
30073
|
-
this.workingDir = workingDir.startsWith("~") ? workingDir.replace(/^~/,
|
|
30073
|
+
this.workingDir = workingDir.startsWith("~") ? workingDir.replace(/^~/, os11.homedir()) : workingDir;
|
|
30074
30074
|
const resolvedConfig = resolveCliAdapterConfig(provider);
|
|
30075
30075
|
this.timeouts = resolvedConfig.timeouts;
|
|
30076
30076
|
this.approvalKeys = resolvedConfig.approvalKeys;
|
|
@@ -33129,17 +33129,17 @@ var require_dist2 = __commonJS({
|
|
|
33129
33129
|
return null;
|
|
33130
33130
|
}
|
|
33131
33131
|
async function detectIDEs(providerLoader) {
|
|
33132
|
-
const
|
|
33132
|
+
const os21 = (0, import_os22.platform)();
|
|
33133
33133
|
const results = [];
|
|
33134
33134
|
for (const def of getMergedDefinitions()) {
|
|
33135
33135
|
const cliPath = findCliCommand(providerLoader?.getIdeCliCommand(def.id, def.cli) || def.cli);
|
|
33136
|
-
const appPath = checkPathExists(providerLoader?.getIdePathCandidates(def.id, def.paths[
|
|
33136
|
+
const appPath = checkPathExists(providerLoader?.getIdePathCandidates(def.id, def.paths[os21] || []) || []);
|
|
33137
33137
|
let resolvedCli = cliPath;
|
|
33138
|
-
if (!resolvedCli && appPath &&
|
|
33138
|
+
if (!resolvedCli && appPath && os21 === "darwin") {
|
|
33139
33139
|
const bundledCli = `${appPath}/Contents/Resources/app/bin/${def.cli}`;
|
|
33140
33140
|
if ((0, import_fs3.existsSync)(bundledCli)) resolvedCli = bundledCli;
|
|
33141
33141
|
}
|
|
33142
|
-
if (!resolvedCli && appPath &&
|
|
33142
|
+
if (!resolvedCli && appPath && os21 === "win32") {
|
|
33143
33143
|
const { dirname: dirname7 } = await import("path");
|
|
33144
33144
|
const appDir = dirname7(appPath);
|
|
33145
33145
|
const candidates = [
|
|
@@ -33156,7 +33156,7 @@ var require_dist2 = __commonJS({
|
|
|
33156
33156
|
}
|
|
33157
33157
|
}
|
|
33158
33158
|
}
|
|
33159
|
-
const installed =
|
|
33159
|
+
const installed = os21 === "darwin" ? !!(resolvedCli || appPath) : !!resolvedCli;
|
|
33160
33160
|
const version2 = resolvedCli ? getIdeVersion(resolvedCli) : null;
|
|
33161
33161
|
results.push({
|
|
33162
33162
|
id: def.id,
|
|
@@ -38262,6 +38262,10 @@ ${effect.notification.body || ""}`.trim();
|
|
|
38262
38262
|
}
|
|
38263
38263
|
return fn2() || null;
|
|
38264
38264
|
}
|
|
38265
|
+
var fs42 = __toESM2(require("fs"));
|
|
38266
|
+
var os62 = __toESM2(require("os"));
|
|
38267
|
+
var path8 = __toESM2(require("path"));
|
|
38268
|
+
var import_node_crypto = require("crypto");
|
|
38265
38269
|
init_contracts();
|
|
38266
38270
|
var VALID_INPUT_MEDIA_TYPES = /* @__PURE__ */ new Set(["text", "image", "audio", "video", "resource"]);
|
|
38267
38271
|
function getProviderLabel(provider) {
|
|
@@ -38941,6 +38945,50 @@ ${effect.notification.body || ""}`.trim();
|
|
|
38941
38945
|
"```"
|
|
38942
38946
|
].join("\n");
|
|
38943
38947
|
}
|
|
38948
|
+
function getChatDebugBundleDir() {
|
|
38949
|
+
const override = typeof process.env.ADHDEV_DEBUG_BUNDLE_DIR === "string" ? process.env.ADHDEV_DEBUG_BUNDLE_DIR.trim() : "";
|
|
38950
|
+
return override || path8.join(os62.homedir(), ".adhdev", "debug-bundles", "chat");
|
|
38951
|
+
}
|
|
38952
|
+
function safeBundleIdSegment(value, fallback) {
|
|
38953
|
+
const normalized = String(value || fallback).trim().replace(/[^A-Za-z0-9_.-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 80);
|
|
38954
|
+
return normalized || fallback;
|
|
38955
|
+
}
|
|
38956
|
+
function createChatDebugBundleId(targetSessionId) {
|
|
38957
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[-:.]/g, "").replace("T", "T").replace("Z", "Z");
|
|
38958
|
+
const sessionSegment = safeBundleIdSegment(targetSessionId, "unknown-session");
|
|
38959
|
+
return `chat-debug-${timestamp}-${sessionSegment}-${(0, import_node_crypto.randomUUID)().slice(0, 8)}`;
|
|
38960
|
+
}
|
|
38961
|
+
function buildChatDebugBundleSummary(bundle) {
|
|
38962
|
+
const target = bundle.target && typeof bundle.target === "object" ? bundle.target : {};
|
|
38963
|
+
const readChat = bundle.readChat && typeof bundle.readChat === "object" ? bundle.readChat : {};
|
|
38964
|
+
const cli = bundle.cli && typeof bundle.cli === "object" ? bundle.cli : null;
|
|
38965
|
+
const frontend = bundle.frontend && typeof bundle.frontend === "object" ? bundle.frontend : null;
|
|
38966
|
+
return {
|
|
38967
|
+
createdAt: bundle.createdAt,
|
|
38968
|
+
targetSessionId: target.targetSessionId,
|
|
38969
|
+
providerType: target.providerType,
|
|
38970
|
+
transport: target.transport,
|
|
38971
|
+
readChatSuccess: readChat.success,
|
|
38972
|
+
readChatStatus: readChat.status,
|
|
38973
|
+
readChatTotalMessages: readChat.totalMessages,
|
|
38974
|
+
cliStatus: cli?.status,
|
|
38975
|
+
cliMessageCount: cli?.messageCount,
|
|
38976
|
+
hasFrontendSnapshot: !!frontend
|
|
38977
|
+
};
|
|
38978
|
+
}
|
|
38979
|
+
function storeChatDebugBundleOnDaemon(bundle, targetSessionId) {
|
|
38980
|
+
const bundleId = createChatDebugBundleId(targetSessionId);
|
|
38981
|
+
const dir = getChatDebugBundleDir();
|
|
38982
|
+
fs42.mkdirSync(dir, { recursive: true });
|
|
38983
|
+
const savedPath = path8.join(dir, `${bundleId}.json`);
|
|
38984
|
+
const json2 = `${JSON.stringify(bundle, null, 2)}
|
|
38985
|
+
`;
|
|
38986
|
+
fs42.writeFileSync(savedPath, json2, { encoding: "utf8", mode: 384 });
|
|
38987
|
+
return { bundleId, savedPath, sizeBytes: Buffer.byteLength(json2, "utf8") };
|
|
38988
|
+
}
|
|
38989
|
+
function isDaemonFileDebugDelivery(args) {
|
|
38990
|
+
return args?.delivery === "daemon_file" || args?.delivery === "file";
|
|
38991
|
+
}
|
|
38944
38992
|
async function handleGetChatDebugBundle(h, args) {
|
|
38945
38993
|
const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
|
|
38946
38994
|
if (!targetSessionId && !h.currentSession) {
|
|
@@ -39052,6 +39100,20 @@ ${effect.notification.body || ""}`.trim();
|
|
|
39052
39100
|
recentDebugTrace: getRecentDebugTrace({ limit: 120 })
|
|
39053
39101
|
};
|
|
39054
39102
|
const bundle = sanitizeDebugBundleValue(rawBundle);
|
|
39103
|
+
if (isDaemonFileDebugDelivery(args)) {
|
|
39104
|
+
const summary = buildChatDebugBundleSummary(bundle);
|
|
39105
|
+
const stored = storeChatDebugBundleOnDaemon(bundle, targetSessionId || String(summary.targetSessionId || "unknown-session"));
|
|
39106
|
+
LOG2.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 || ""}`);
|
|
39107
|
+
return {
|
|
39108
|
+
success: true,
|
|
39109
|
+
delivery: "daemon_file",
|
|
39110
|
+
bundleId: stored.bundleId,
|
|
39111
|
+
savedPath: stored.savedPath,
|
|
39112
|
+
sizeBytes: stored.sizeBytes,
|
|
39113
|
+
createdAt: bundle.createdAt,
|
|
39114
|
+
summary
|
|
39115
|
+
};
|
|
39116
|
+
}
|
|
39055
39117
|
return {
|
|
39056
39118
|
success: true,
|
|
39057
39119
|
bundle,
|
|
@@ -40031,9 +40093,9 @@ ${effect.notification.body || ""}`.trim();
|
|
|
40031
40093
|
}
|
|
40032
40094
|
return { success: false, error: "resolveAction script not available for this provider" };
|
|
40033
40095
|
}
|
|
40034
|
-
var
|
|
40035
|
-
var
|
|
40036
|
-
var
|
|
40096
|
+
var fs52 = __toESM2(require("fs"));
|
|
40097
|
+
var path9 = __toESM2(require("path"));
|
|
40098
|
+
var os7 = __toESM2(require("os"));
|
|
40037
40099
|
var KEY_TO_VK = {
|
|
40038
40100
|
Backspace: 8,
|
|
40039
40101
|
Tab: 9,
|
|
@@ -40287,27 +40349,27 @@ ${effect.notification.body || ""}`.trim();
|
|
|
40287
40349
|
function resolveSafePath(requestedPath) {
|
|
40288
40350
|
const rawPath = typeof requestedPath === "string" ? requestedPath.trim() : "";
|
|
40289
40351
|
const inputPath = rawPath || ".";
|
|
40290
|
-
const home =
|
|
40352
|
+
const home = os7.homedir();
|
|
40291
40353
|
if (inputPath.startsWith("~")) {
|
|
40292
|
-
return
|
|
40354
|
+
return path9.resolve(path9.join(home, inputPath.slice(1)));
|
|
40293
40355
|
}
|
|
40294
40356
|
if (process.platform === "win32") {
|
|
40295
40357
|
const normalized = normalizeWindowsRequestedPath(inputPath);
|
|
40296
|
-
if (
|
|
40297
|
-
return
|
|
40358
|
+
if (path9.win32.isAbsolute(normalized)) {
|
|
40359
|
+
return path9.win32.normalize(normalized);
|
|
40298
40360
|
}
|
|
40299
|
-
return
|
|
40361
|
+
return path9.win32.resolve(normalized);
|
|
40300
40362
|
}
|
|
40301
|
-
if (
|
|
40302
|
-
return
|
|
40363
|
+
if (path9.isAbsolute(inputPath)) {
|
|
40364
|
+
return path9.normalize(inputPath);
|
|
40303
40365
|
}
|
|
40304
|
-
return
|
|
40366
|
+
return path9.resolve(inputPath);
|
|
40305
40367
|
}
|
|
40306
40368
|
function listDirectoryEntriesSafe(dirPath) {
|
|
40307
|
-
const entries =
|
|
40369
|
+
const entries = fs52.readdirSync(dirPath, { withFileTypes: true });
|
|
40308
40370
|
const files = [];
|
|
40309
40371
|
for (const entry of entries) {
|
|
40310
|
-
const entryPath =
|
|
40372
|
+
const entryPath = path9.join(dirPath, entry.name);
|
|
40311
40373
|
try {
|
|
40312
40374
|
if (entry.isDirectory()) {
|
|
40313
40375
|
files.push({ name: entry.name, type: "directory" });
|
|
@@ -40316,14 +40378,14 @@ ${effect.notification.body || ""}`.trim();
|
|
|
40316
40378
|
if (entry.isFile()) {
|
|
40317
40379
|
let size;
|
|
40318
40380
|
try {
|
|
40319
|
-
size =
|
|
40381
|
+
size = fs52.statSync(entryPath).size;
|
|
40320
40382
|
} catch {
|
|
40321
40383
|
size = void 0;
|
|
40322
40384
|
}
|
|
40323
40385
|
files.push({ name: entry.name, type: "file", size });
|
|
40324
40386
|
continue;
|
|
40325
40387
|
}
|
|
40326
|
-
const stat4 =
|
|
40388
|
+
const stat4 = fs52.statSync(entryPath);
|
|
40327
40389
|
files.push({
|
|
40328
40390
|
name: entry.name,
|
|
40329
40391
|
type: stat4.isDirectory() ? "directory" : "file",
|
|
@@ -40341,7 +40403,7 @@ ${effect.notification.body || ""}`.trim();
|
|
|
40341
40403
|
const letter = String.fromCharCode(code);
|
|
40342
40404
|
const root = `${letter}:\\`;
|
|
40343
40405
|
try {
|
|
40344
|
-
if (!
|
|
40406
|
+
if (!fs52.existsSync(root)) continue;
|
|
40345
40407
|
if (excluded && root.toLowerCase() === excluded) continue;
|
|
40346
40408
|
drives.push({ name: `${letter}:`, type: "directory", path: root });
|
|
40347
40409
|
} catch {
|
|
@@ -40352,7 +40414,7 @@ ${effect.notification.body || ""}`.trim();
|
|
|
40352
40414
|
async function handleFileRead(h, args) {
|
|
40353
40415
|
try {
|
|
40354
40416
|
const filePath = resolveSafePath(args?.path);
|
|
40355
|
-
const content =
|
|
40417
|
+
const content = fs52.readFileSync(filePath, "utf-8");
|
|
40356
40418
|
return { success: true, content, path: filePath };
|
|
40357
40419
|
} catch (e) {
|
|
40358
40420
|
return { success: false, error: e.message };
|
|
@@ -40361,8 +40423,8 @@ ${effect.notification.body || ""}`.trim();
|
|
|
40361
40423
|
async function handleFileWrite(h, args) {
|
|
40362
40424
|
try {
|
|
40363
40425
|
const filePath = resolveSafePath(args?.path);
|
|
40364
|
-
|
|
40365
|
-
|
|
40426
|
+
fs52.mkdirSync(path9.dirname(filePath), { recursive: true });
|
|
40427
|
+
fs52.writeFileSync(filePath, args?.content || "", "utf-8");
|
|
40366
40428
|
return { success: true, path: filePath };
|
|
40367
40429
|
} catch (e) {
|
|
40368
40430
|
return { success: false, error: e.message };
|
|
@@ -41449,18 +41511,18 @@ ${effect.notification.body || ""}`.trim();
|
|
|
41449
41511
|
}
|
|
41450
41512
|
}
|
|
41451
41513
|
};
|
|
41452
|
-
var
|
|
41453
|
-
var
|
|
41514
|
+
var os13 = __toESM2(require("os"));
|
|
41515
|
+
var path13 = __toESM2(require("path"));
|
|
41454
41516
|
var crypto4 = __toESM2(require("crypto"));
|
|
41455
41517
|
var import_fs5 = require("fs");
|
|
41456
41518
|
var import_child_process6 = require("child_process");
|
|
41457
41519
|
var import_chalk = __toESM2(require("chalk"));
|
|
41458
41520
|
init_provider_cli_adapter();
|
|
41459
41521
|
init_config();
|
|
41460
|
-
var
|
|
41461
|
-
var
|
|
41522
|
+
var os12 = __toESM2(require("os"));
|
|
41523
|
+
var path12 = __toESM2(require("path"));
|
|
41462
41524
|
var crypto3 = __toESM2(require("crypto"));
|
|
41463
|
-
var
|
|
41525
|
+
var fs6 = __toESM2(require("fs"));
|
|
41464
41526
|
var import_node_module = require("module");
|
|
41465
41527
|
init_contracts();
|
|
41466
41528
|
init_provider_cli_adapter();
|
|
@@ -41515,7 +41577,7 @@ ${effect.notification.body || ""}`.trim();
|
|
|
41515
41577
|
var CachedDatabaseSync = null;
|
|
41516
41578
|
function getDatabaseSync() {
|
|
41517
41579
|
if (CachedDatabaseSync) return CachedDatabaseSync;
|
|
41518
|
-
const requireFn = typeof require === "function" ? require : (0, import_node_module.createRequire)(
|
|
41580
|
+
const requireFn = typeof require === "function" ? require : (0, import_node_module.createRequire)(path12.join(process.cwd(), "__adhdev_sqlite_loader__.js"));
|
|
41519
41581
|
const sqliteModule = requireFn(`node:${"sqlite"}`);
|
|
41520
41582
|
CachedDatabaseSync = sqliteModule.DatabaseSync;
|
|
41521
41583
|
if (!CachedDatabaseSync) {
|
|
@@ -41665,10 +41727,10 @@ ${effect.notification.body || ""}`.trim();
|
|
|
41665
41727
|
* Replaces the previously duplicated probeOpenCode/Codex/Goose functions.
|
|
41666
41728
|
*/
|
|
41667
41729
|
probeSessionIdFromConfig(probe) {
|
|
41668
|
-
const resolvedDbPath = probe.dbPath.replace(/^~/,
|
|
41730
|
+
const resolvedDbPath = probe.dbPath.replace(/^~/, os12.homedir());
|
|
41669
41731
|
const now = Date.now();
|
|
41670
41732
|
if (this.cachedSqliteDbMissingUntil > now) return null;
|
|
41671
|
-
if (!
|
|
41733
|
+
if (!fs6.existsSync(resolvedDbPath)) {
|
|
41672
41734
|
this.cachedSqliteDbMissingUntil = now + 1e4;
|
|
41673
41735
|
return null;
|
|
41674
41736
|
}
|
|
@@ -42400,7 +42462,7 @@ ${effect.notification.body || ""}`.trim();
|
|
|
42400
42462
|
};
|
|
42401
42463
|
addDir(this.workingDir);
|
|
42402
42464
|
try {
|
|
42403
|
-
addDir(
|
|
42465
|
+
addDir(fs6.realpathSync.native(this.workingDir));
|
|
42404
42466
|
} catch {
|
|
42405
42467
|
}
|
|
42406
42468
|
return Array.from(dirs);
|
|
@@ -43591,11 +43653,11 @@ ${rawInput}` : rawInput;
|
|
|
43591
43653
|
}
|
|
43592
43654
|
function isExplicitCommand(command) {
|
|
43593
43655
|
const trimmed = command.trim();
|
|
43594
|
-
return
|
|
43656
|
+
return path13.isAbsolute(trimmed) || trimmed.includes("/") || trimmed.includes("\\") || trimmed.startsWith("~");
|
|
43595
43657
|
}
|
|
43596
43658
|
function expandExecutable(command) {
|
|
43597
43659
|
const trimmed = command.trim();
|
|
43598
|
-
return trimmed.startsWith("~") ?
|
|
43660
|
+
return trimmed.startsWith("~") ? path13.join(os13.homedir(), trimmed.slice(1)) : trimmed;
|
|
43599
43661
|
}
|
|
43600
43662
|
function commandExists(command) {
|
|
43601
43663
|
const trimmed = command.trim();
|
|
@@ -43876,7 +43938,7 @@ ${rawInput}` : rawInput;
|
|
|
43876
43938
|
async startSession(cliType, workingDir, cliArgs, initialModel, options) {
|
|
43877
43939
|
const trimmed = (workingDir || "").trim();
|
|
43878
43940
|
if (!trimmed) throw new Error("working directory required");
|
|
43879
|
-
const resolvedDir = trimmed.startsWith("~") ? trimmed.replace(/^~/,
|
|
43941
|
+
const resolvedDir = trimmed.startsWith("~") ? trimmed.replace(/^~/, os13.homedir()) : path13.resolve(trimmed);
|
|
43880
43942
|
const normalizedType = this.providerLoader.resolveAlias(cliType);
|
|
43881
43943
|
const rawProvider = this.providerLoader.getByAlias(cliType);
|
|
43882
43944
|
const provider = rawProvider ? this.providerLoader.resolve(normalizedType) || rawProvider : void 0;
|
|
@@ -44374,11 +44436,11 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
44374
44436
|
};
|
|
44375
44437
|
var import_child_process7 = require("child_process");
|
|
44376
44438
|
var net3 = __toESM2(require("net"));
|
|
44377
|
-
var
|
|
44439
|
+
var os15 = __toESM2(require("os"));
|
|
44440
|
+
var path15 = __toESM2(require("path"));
|
|
44441
|
+
var fs7 = __toESM2(require("fs"));
|
|
44378
44442
|
var path14 = __toESM2(require("path"));
|
|
44379
|
-
var
|
|
44380
|
-
var path13 = __toESM2(require("path"));
|
|
44381
|
-
var os13 = __toESM2(require("os"));
|
|
44443
|
+
var os14 = __toESM2(require("os"));
|
|
44382
44444
|
var chokidar = __toESM2((init_chokidar(), __toCommonJS(chokidar_exports)));
|
|
44383
44445
|
init_logger();
|
|
44384
44446
|
var VALID_CAPABILITY_MEDIA_TYPES = /* @__PURE__ */ new Set(["text", "image", "audio", "video", "resource"]);
|
|
@@ -44636,9 +44698,9 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
44636
44698
|
static siblingStderrLogged = /* @__PURE__ */ new Set();
|
|
44637
44699
|
static looksLikeProviderRoot(candidate) {
|
|
44638
44700
|
try {
|
|
44639
|
-
if (!
|
|
44701
|
+
if (!fs7.existsSync(candidate) || !fs7.statSync(candidate).isDirectory()) return false;
|
|
44640
44702
|
return ["ide", "extension", "cli", "acp"].some(
|
|
44641
|
-
(category) =>
|
|
44703
|
+
(category) => fs7.existsSync(path14.join(candidate, category))
|
|
44642
44704
|
);
|
|
44643
44705
|
} catch {
|
|
44644
44706
|
return false;
|
|
@@ -44646,20 +44708,20 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
44646
44708
|
}
|
|
44647
44709
|
static hasProviderRootMarker(candidate) {
|
|
44648
44710
|
try {
|
|
44649
|
-
return
|
|
44711
|
+
return fs7.existsSync(path14.join(candidate, _ProviderLoader.SIBLING_MARKER_FILE));
|
|
44650
44712
|
} catch {
|
|
44651
44713
|
return false;
|
|
44652
44714
|
}
|
|
44653
44715
|
}
|
|
44654
44716
|
detectDefaultUserDir() {
|
|
44655
|
-
const fallback =
|
|
44717
|
+
const fallback = path14.join(os14.homedir(), ".adhdev", "providers");
|
|
44656
44718
|
const envOptIn = process.env[_ProviderLoader.SIBLING_ENV_VAR] === "1";
|
|
44657
44719
|
const visited = /* @__PURE__ */ new Set();
|
|
44658
44720
|
for (const start of this.probeStarts) {
|
|
44659
|
-
let current =
|
|
44721
|
+
let current = path14.resolve(start);
|
|
44660
44722
|
while (!visited.has(current)) {
|
|
44661
44723
|
visited.add(current);
|
|
44662
|
-
const siblingCandidate =
|
|
44724
|
+
const siblingCandidate = path14.join(path14.dirname(current), _ProviderLoader.REPO_PROVIDER_DIRNAME);
|
|
44663
44725
|
if (_ProviderLoader.looksLikeProviderRoot(siblingCandidate)) {
|
|
44664
44726
|
const hasMarker = _ProviderLoader.hasProviderRootMarker(siblingCandidate);
|
|
44665
44727
|
if (envOptIn || hasMarker) {
|
|
@@ -44681,7 +44743,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
44681
44743
|
return { path: siblingCandidate, source };
|
|
44682
44744
|
}
|
|
44683
44745
|
}
|
|
44684
|
-
const parent =
|
|
44746
|
+
const parent = path14.dirname(current);
|
|
44685
44747
|
if (parent === current) break;
|
|
44686
44748
|
current = parent;
|
|
44687
44749
|
}
|
|
@@ -44691,11 +44753,11 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
44691
44753
|
constructor(options) {
|
|
44692
44754
|
this.logFn = options?.logFn || LOG2.forComponent("Provider").asLogFn();
|
|
44693
44755
|
this.probeStarts = options?.probeStarts ?? [process.cwd(), __dirname];
|
|
44694
|
-
this.defaultProvidersDir =
|
|
44756
|
+
this.defaultProvidersDir = path14.join(os14.homedir(), ".adhdev", "providers");
|
|
44695
44757
|
const detected = this.detectDefaultUserDir();
|
|
44696
44758
|
this.userDir = detected.path;
|
|
44697
44759
|
this.userDirSource = detected.source;
|
|
44698
|
-
this.upstreamDir =
|
|
44760
|
+
this.upstreamDir = path14.join(this.defaultProvidersDir, ".upstream");
|
|
44699
44761
|
this.disableUpstream = false;
|
|
44700
44762
|
this.applySourceConfig({
|
|
44701
44763
|
userDir: options?.userDir,
|
|
@@ -44754,7 +44816,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
44754
44816
|
this.userDir = detected.path;
|
|
44755
44817
|
this.userDirSource = detected.source;
|
|
44756
44818
|
}
|
|
44757
|
-
this.upstreamDir =
|
|
44819
|
+
this.upstreamDir = path14.join(this.defaultProvidersDir, ".upstream");
|
|
44758
44820
|
this.disableUpstream = this.sourceMode === "no-upstream";
|
|
44759
44821
|
if (this.explicitProviderDir) {
|
|
44760
44822
|
this.log(`Config 'providerDir' applied: ${this.userDir}`);
|
|
@@ -44768,7 +44830,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
44768
44830
|
* Canonical provider directory shape for a given root.
|
|
44769
44831
|
*/
|
|
44770
44832
|
getProviderDir(root, category, type) {
|
|
44771
|
-
return
|
|
44833
|
+
return path14.join(root, category, type);
|
|
44772
44834
|
}
|
|
44773
44835
|
/**
|
|
44774
44836
|
* Canonical user override directory for a provider.
|
|
@@ -44795,7 +44857,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
44795
44857
|
resolveProviderFile(type, ...segments) {
|
|
44796
44858
|
const dir = this.findProviderDirInternal(type);
|
|
44797
44859
|
if (!dir) return null;
|
|
44798
|
-
return
|
|
44860
|
+
return path14.join(dir, ...segments);
|
|
44799
44861
|
}
|
|
44800
44862
|
/**
|
|
44801
44863
|
* Load all providers (3-tier priority)
|
|
@@ -44808,7 +44870,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
44808
44870
|
this.providers.clear();
|
|
44809
44871
|
this.providerAvailability.clear();
|
|
44810
44872
|
let upstreamCount = 0;
|
|
44811
|
-
if (!this.disableUpstream &&
|
|
44873
|
+
if (!this.disableUpstream && fs7.existsSync(this.upstreamDir)) {
|
|
44812
44874
|
upstreamCount = this.loadDir(this.upstreamDir);
|
|
44813
44875
|
if (upstreamCount > 0) {
|
|
44814
44876
|
this.log(`Loaded ${upstreamCount} upstream providers (auto-updated)`);
|
|
@@ -44816,7 +44878,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
44816
44878
|
} else if (this.disableUpstream) {
|
|
44817
44879
|
this.log("Upstream loading disabled (sourceMode=no-upstream)");
|
|
44818
44880
|
}
|
|
44819
|
-
if (
|
|
44881
|
+
if (fs7.existsSync(this.userDir)) {
|
|
44820
44882
|
const userCount = this.loadDir(this.userDir, [".upstream"]);
|
|
44821
44883
|
if (userCount > 0) {
|
|
44822
44884
|
this.log(`Loaded ${userCount} user custom providers (never auto-updated)`);
|
|
@@ -44831,10 +44893,10 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
44831
44893
|
* Check if upstream directory exists and has providers.
|
|
44832
44894
|
*/
|
|
44833
44895
|
hasUpstream() {
|
|
44834
|
-
if (!
|
|
44896
|
+
if (!fs7.existsSync(this.upstreamDir)) return false;
|
|
44835
44897
|
try {
|
|
44836
|
-
return
|
|
44837
|
-
(d) =>
|
|
44898
|
+
return fs7.readdirSync(this.upstreamDir).some(
|
|
44899
|
+
(d) => fs7.statSync(path14.join(this.upstreamDir, d)).isDirectory()
|
|
44838
44900
|
);
|
|
44839
44901
|
} catch {
|
|
44840
44902
|
return false;
|
|
@@ -45331,8 +45393,8 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45331
45393
|
resolved._resolvedScriptDir = entry.scriptDir;
|
|
45332
45394
|
resolved._resolvedScriptsSource = `compatibility:${entry.ideVersion}`;
|
|
45333
45395
|
if (providerDir) {
|
|
45334
|
-
const fullDir =
|
|
45335
|
-
resolved._resolvedScriptsPath =
|
|
45396
|
+
const fullDir = path14.join(providerDir, entry.scriptDir);
|
|
45397
|
+
resolved._resolvedScriptsPath = fs7.existsSync(path14.join(fullDir, "scripts.js")) ? path14.join(fullDir, "scripts.js") : fullDir;
|
|
45336
45398
|
}
|
|
45337
45399
|
matched = true;
|
|
45338
45400
|
}
|
|
@@ -45347,8 +45409,8 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45347
45409
|
resolved._resolvedScriptDir = base.defaultScriptDir;
|
|
45348
45410
|
resolved._resolvedScriptsSource = "defaultScriptDir:version_miss";
|
|
45349
45411
|
if (providerDir) {
|
|
45350
|
-
const fullDir =
|
|
45351
|
-
resolved._resolvedScriptsPath =
|
|
45412
|
+
const fullDir = path14.join(providerDir, base.defaultScriptDir);
|
|
45413
|
+
resolved._resolvedScriptsPath = fs7.existsSync(path14.join(fullDir, "scripts.js")) ? path14.join(fullDir, "scripts.js") : fullDir;
|
|
45352
45414
|
}
|
|
45353
45415
|
}
|
|
45354
45416
|
resolved._versionWarning = `Version ${currentVersion} not in compatibility matrix. Using default scripts.`;
|
|
@@ -45365,8 +45427,8 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45365
45427
|
resolved._resolvedScriptDir = dirOverride;
|
|
45366
45428
|
resolved._resolvedScriptsSource = `versions:${range}`;
|
|
45367
45429
|
if (providerDir) {
|
|
45368
|
-
const fullDir =
|
|
45369
|
-
resolved._resolvedScriptsPath =
|
|
45430
|
+
const fullDir = path14.join(providerDir, dirOverride);
|
|
45431
|
+
resolved._resolvedScriptsPath = fs7.existsSync(path14.join(fullDir, "scripts.js")) ? path14.join(fullDir, "scripts.js") : fullDir;
|
|
45370
45432
|
}
|
|
45371
45433
|
}
|
|
45372
45434
|
} else if (override.scripts) {
|
|
@@ -45382,8 +45444,8 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45382
45444
|
resolved._resolvedScriptDir = base.defaultScriptDir;
|
|
45383
45445
|
resolved._resolvedScriptsSource = "defaultScriptDir:no_version";
|
|
45384
45446
|
if (providerDir) {
|
|
45385
|
-
const fullDir =
|
|
45386
|
-
resolved._resolvedScriptsPath =
|
|
45447
|
+
const fullDir = path14.join(providerDir, base.defaultScriptDir);
|
|
45448
|
+
resolved._resolvedScriptsPath = fs7.existsSync(path14.join(fullDir, "scripts.js")) ? path14.join(fullDir, "scripts.js") : fullDir;
|
|
45387
45449
|
}
|
|
45388
45450
|
}
|
|
45389
45451
|
}
|
|
@@ -45415,15 +45477,15 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45415
45477
|
this.log(` [loadScriptsFromDir] ${type}: providerDir not found`);
|
|
45416
45478
|
return null;
|
|
45417
45479
|
}
|
|
45418
|
-
const dir =
|
|
45419
|
-
if (!
|
|
45480
|
+
const dir = path14.join(providerDir, scriptDir);
|
|
45481
|
+
if (!fs7.existsSync(dir)) {
|
|
45420
45482
|
this.log(` [loadScriptsFromDir] ${type}: dir not found: ${dir}`);
|
|
45421
45483
|
return null;
|
|
45422
45484
|
}
|
|
45423
45485
|
const cached2 = this.scriptsCache.get(dir);
|
|
45424
45486
|
if (cached2) return cached2;
|
|
45425
|
-
const scriptsJs =
|
|
45426
|
-
if (
|
|
45487
|
+
const scriptsJs = path14.join(dir, "scripts.js");
|
|
45488
|
+
if (fs7.existsSync(scriptsJs)) {
|
|
45427
45489
|
try {
|
|
45428
45490
|
delete require.cache[require.resolve(scriptsJs)];
|
|
45429
45491
|
const loaded = require(scriptsJs);
|
|
@@ -45444,9 +45506,9 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45444
45506
|
watch() {
|
|
45445
45507
|
this.stopWatch();
|
|
45446
45508
|
const watchDir = (dir) => {
|
|
45447
|
-
if (!
|
|
45509
|
+
if (!fs7.existsSync(dir)) {
|
|
45448
45510
|
try {
|
|
45449
|
-
|
|
45511
|
+
fs7.mkdirSync(dir, { recursive: true });
|
|
45450
45512
|
} catch {
|
|
45451
45513
|
return;
|
|
45452
45514
|
}
|
|
@@ -45464,7 +45526,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45464
45526
|
return;
|
|
45465
45527
|
}
|
|
45466
45528
|
if (filePath.endsWith(".js") || filePath.endsWith(".json")) {
|
|
45467
|
-
this.log(`File changed: ${
|
|
45529
|
+
this.log(`File changed: ${path14.basename(filePath)}, reloading...`);
|
|
45468
45530
|
this.reload();
|
|
45469
45531
|
}
|
|
45470
45532
|
};
|
|
@@ -45519,12 +45581,12 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45519
45581
|
}
|
|
45520
45582
|
const https = require("https");
|
|
45521
45583
|
const { execSync: execSync7 } = require("child_process");
|
|
45522
|
-
const metaPath =
|
|
45584
|
+
const metaPath = path14.join(this.upstreamDir, _ProviderLoader.META_FILE);
|
|
45523
45585
|
let prevEtag = "";
|
|
45524
45586
|
let prevTimestamp = 0;
|
|
45525
45587
|
try {
|
|
45526
|
-
if (
|
|
45527
|
-
const meta3 = JSON.parse(
|
|
45588
|
+
if (fs7.existsSync(metaPath)) {
|
|
45589
|
+
const meta3 = JSON.parse(fs7.readFileSync(metaPath, "utf-8"));
|
|
45528
45590
|
prevEtag = meta3.etag || "";
|
|
45529
45591
|
prevTimestamp = meta3.timestamp || 0;
|
|
45530
45592
|
}
|
|
@@ -45579,39 +45641,39 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45579
45641
|
return { updated: false };
|
|
45580
45642
|
}
|
|
45581
45643
|
this.log("Downloading latest providers from GitHub...");
|
|
45582
|
-
const tmpTar =
|
|
45583
|
-
const tmpExtract =
|
|
45644
|
+
const tmpTar = path14.join(os14.tmpdir(), `adhdev-providers-${Date.now()}.tar.gz`);
|
|
45645
|
+
const tmpExtract = path14.join(os14.tmpdir(), `adhdev-providers-extract-${Date.now()}`);
|
|
45584
45646
|
await this.downloadFile(_ProviderLoader.GITHUB_TARBALL_URL, tmpTar);
|
|
45585
|
-
|
|
45647
|
+
fs7.mkdirSync(tmpExtract, { recursive: true });
|
|
45586
45648
|
execSync7(`tar -xzf "${tmpTar}" -C "${tmpExtract}"`, { timeout: 3e4 });
|
|
45587
|
-
const extracted =
|
|
45649
|
+
const extracted = fs7.readdirSync(tmpExtract);
|
|
45588
45650
|
const rootDir = extracted.find(
|
|
45589
|
-
(d) =>
|
|
45651
|
+
(d) => fs7.statSync(path14.join(tmpExtract, d)).isDirectory() && d.startsWith("adhdev-providers")
|
|
45590
45652
|
);
|
|
45591
45653
|
if (!rootDir) throw new Error("Unexpected tarball structure");
|
|
45592
|
-
const sourceDir =
|
|
45654
|
+
const sourceDir = path14.join(tmpExtract, rootDir);
|
|
45593
45655
|
const backupDir = this.upstreamDir + ".bak";
|
|
45594
|
-
if (
|
|
45595
|
-
if (
|
|
45596
|
-
|
|
45656
|
+
if (fs7.existsSync(this.upstreamDir)) {
|
|
45657
|
+
if (fs7.existsSync(backupDir)) fs7.rmSync(backupDir, { recursive: true, force: true });
|
|
45658
|
+
fs7.renameSync(this.upstreamDir, backupDir);
|
|
45597
45659
|
}
|
|
45598
45660
|
try {
|
|
45599
45661
|
this.copyDirRecursive(sourceDir, this.upstreamDir);
|
|
45600
45662
|
this.writeMeta(metaPath, etag || `ts-${Date.now()}`, Date.now());
|
|
45601
|
-
if (
|
|
45663
|
+
if (fs7.existsSync(backupDir)) fs7.rmSync(backupDir, { recursive: true, force: true });
|
|
45602
45664
|
} catch (e) {
|
|
45603
|
-
if (
|
|
45604
|
-
if (
|
|
45605
|
-
|
|
45665
|
+
if (fs7.existsSync(backupDir)) {
|
|
45666
|
+
if (fs7.existsSync(this.upstreamDir)) fs7.rmSync(this.upstreamDir, { recursive: true, force: true });
|
|
45667
|
+
fs7.renameSync(backupDir, this.upstreamDir);
|
|
45606
45668
|
}
|
|
45607
45669
|
throw e;
|
|
45608
45670
|
}
|
|
45609
45671
|
try {
|
|
45610
|
-
|
|
45672
|
+
fs7.rmSync(tmpTar, { force: true });
|
|
45611
45673
|
} catch {
|
|
45612
45674
|
}
|
|
45613
45675
|
try {
|
|
45614
|
-
|
|
45676
|
+
fs7.rmSync(tmpExtract, { recursive: true, force: true });
|
|
45615
45677
|
} catch {
|
|
45616
45678
|
}
|
|
45617
45679
|
const upstreamCount = this.countProviders(this.upstreamDir);
|
|
@@ -45643,7 +45705,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45643
45705
|
reject(new Error(`HTTP ${res.statusCode}`));
|
|
45644
45706
|
return;
|
|
45645
45707
|
}
|
|
45646
|
-
const ws2 =
|
|
45708
|
+
const ws2 = fs7.createWriteStream(destPath);
|
|
45647
45709
|
res.pipe(ws2);
|
|
45648
45710
|
ws2.on("finish", () => {
|
|
45649
45711
|
ws2.close();
|
|
@@ -45662,22 +45724,22 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45662
45724
|
}
|
|
45663
45725
|
/** Recursive directory copy */
|
|
45664
45726
|
copyDirRecursive(src, dest) {
|
|
45665
|
-
|
|
45666
|
-
for (const entry of
|
|
45667
|
-
const srcPath =
|
|
45668
|
-
const destPath =
|
|
45727
|
+
fs7.mkdirSync(dest, { recursive: true });
|
|
45728
|
+
for (const entry of fs7.readdirSync(src, { withFileTypes: true })) {
|
|
45729
|
+
const srcPath = path14.join(src, entry.name);
|
|
45730
|
+
const destPath = path14.join(dest, entry.name);
|
|
45669
45731
|
if (entry.isDirectory()) {
|
|
45670
45732
|
this.copyDirRecursive(srcPath, destPath);
|
|
45671
45733
|
} else {
|
|
45672
|
-
|
|
45734
|
+
fs7.copyFileSync(srcPath, destPath);
|
|
45673
45735
|
}
|
|
45674
45736
|
}
|
|
45675
45737
|
}
|
|
45676
45738
|
/** .meta.json save */
|
|
45677
45739
|
writeMeta(metaPath, etag, timestamp) {
|
|
45678
45740
|
try {
|
|
45679
|
-
|
|
45680
|
-
|
|
45741
|
+
fs7.mkdirSync(path14.dirname(metaPath), { recursive: true });
|
|
45742
|
+
fs7.writeFileSync(metaPath, JSON.stringify({
|
|
45681
45743
|
etag,
|
|
45682
45744
|
timestamp,
|
|
45683
45745
|
lastCheck: new Date(timestamp).toISOString(),
|
|
@@ -45688,12 +45750,12 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45688
45750
|
}
|
|
45689
45751
|
/** Count provider files (provider.js or provider.json) */
|
|
45690
45752
|
countProviders(dir) {
|
|
45691
|
-
if (!
|
|
45753
|
+
if (!fs7.existsSync(dir)) return 0;
|
|
45692
45754
|
let count = 0;
|
|
45693
45755
|
const scan = (d) => {
|
|
45694
45756
|
try {
|
|
45695
|
-
for (const entry of
|
|
45696
|
-
if (entry.isDirectory()) scan(
|
|
45757
|
+
for (const entry of fs7.readdirSync(d, { withFileTypes: true })) {
|
|
45758
|
+
if (entry.isDirectory()) scan(path14.join(d, entry.name));
|
|
45697
45759
|
else if (entry.name === "provider.json") count++;
|
|
45698
45760
|
}
|
|
45699
45761
|
} catch {
|
|
@@ -45919,19 +45981,19 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45919
45981
|
const cat = provider.category;
|
|
45920
45982
|
const searchRoots = this.getProviderRoots();
|
|
45921
45983
|
for (const root of searchRoots) {
|
|
45922
|
-
if (!
|
|
45984
|
+
if (!fs7.existsSync(root)) continue;
|
|
45923
45985
|
const candidate = this.getProviderDir(root, cat, type);
|
|
45924
|
-
if (
|
|
45925
|
-
const catDir =
|
|
45926
|
-
if (
|
|
45986
|
+
if (fs7.existsSync(path14.join(candidate, "provider.json"))) return candidate;
|
|
45987
|
+
const catDir = path14.join(root, cat);
|
|
45988
|
+
if (fs7.existsSync(catDir)) {
|
|
45927
45989
|
try {
|
|
45928
|
-
for (const entry of
|
|
45990
|
+
for (const entry of fs7.readdirSync(catDir, { withFileTypes: true })) {
|
|
45929
45991
|
if (!entry.isDirectory()) continue;
|
|
45930
|
-
const jsonPath =
|
|
45931
|
-
if (
|
|
45992
|
+
const jsonPath = path14.join(catDir, entry.name, "provider.json");
|
|
45993
|
+
if (fs7.existsSync(jsonPath)) {
|
|
45932
45994
|
try {
|
|
45933
|
-
const data = JSON.parse(
|
|
45934
|
-
if (data.type === type) return
|
|
45995
|
+
const data = JSON.parse(fs7.readFileSync(jsonPath, "utf-8"));
|
|
45996
|
+
if (data.type === type) return path14.join(catDir, entry.name);
|
|
45935
45997
|
} catch {
|
|
45936
45998
|
}
|
|
45937
45999
|
}
|
|
@@ -45948,8 +46010,8 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45948
46010
|
* (template substitution is NOT applied here — scripts.js handles that)
|
|
45949
46011
|
*/
|
|
45950
46012
|
buildScriptWrappersFromDir(dir) {
|
|
45951
|
-
const scriptsJs =
|
|
45952
|
-
if (
|
|
46013
|
+
const scriptsJs = path14.join(dir, "scripts.js");
|
|
46014
|
+
if (fs7.existsSync(scriptsJs)) {
|
|
45953
46015
|
try {
|
|
45954
46016
|
delete require.cache[require.resolve(scriptsJs)];
|
|
45955
46017
|
return require(scriptsJs);
|
|
@@ -45959,13 +46021,13 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45959
46021
|
const toCamel = (name) => name.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
|
|
45960
46022
|
const result = {};
|
|
45961
46023
|
try {
|
|
45962
|
-
for (const file2 of
|
|
46024
|
+
for (const file2 of fs7.readdirSync(dir)) {
|
|
45963
46025
|
if (!file2.endsWith(".js")) continue;
|
|
45964
46026
|
const scriptName = toCamel(file2.replace(".js", ""));
|
|
45965
|
-
const filePath =
|
|
46027
|
+
const filePath = path14.join(dir, file2);
|
|
45966
46028
|
result[scriptName] = (...args) => {
|
|
45967
46029
|
try {
|
|
45968
|
-
let content =
|
|
46030
|
+
let content = fs7.readFileSync(filePath, "utf-8");
|
|
45969
46031
|
if (args[0] && typeof args[0] === "object") {
|
|
45970
46032
|
for (const [key, val] of Object.entries(args[0])) {
|
|
45971
46033
|
let v2 = val;
|
|
@@ -46011,20 +46073,20 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
46011
46073
|
* Structure: dir/category/agent-name/provider.{json,js}
|
|
46012
46074
|
*/
|
|
46013
46075
|
loadDir(dir, excludeDirs) {
|
|
46014
|
-
if (!
|
|
46076
|
+
if (!fs7.existsSync(dir)) return 0;
|
|
46015
46077
|
let count = 0;
|
|
46016
46078
|
const scan = (d) => {
|
|
46017
46079
|
let entries;
|
|
46018
46080
|
try {
|
|
46019
|
-
entries =
|
|
46081
|
+
entries = fs7.readdirSync(d, { withFileTypes: true });
|
|
46020
46082
|
} catch {
|
|
46021
46083
|
return;
|
|
46022
46084
|
}
|
|
46023
46085
|
const hasJson = entries.some((e) => e.name === "provider.json");
|
|
46024
46086
|
if (hasJson) {
|
|
46025
|
-
const jsonPath =
|
|
46087
|
+
const jsonPath = path14.join(d, "provider.json");
|
|
46026
46088
|
try {
|
|
46027
|
-
const raw =
|
|
46089
|
+
const raw = fs7.readFileSync(jsonPath, "utf-8");
|
|
46028
46090
|
const mod = JSON.parse(raw);
|
|
46029
46091
|
if (typeof mod.extensionIdPattern === "string") {
|
|
46030
46092
|
const flags = mod.extensionIdPattern_flags || "";
|
|
@@ -46043,8 +46105,8 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
46043
46105
|
this.log(`\u26A0 Invalid provider at ${jsonPath}: ${validation.errors.join("; ")}`);
|
|
46044
46106
|
} else {
|
|
46045
46107
|
const hasCompatibility = Array.isArray(normalizedProvider.compatibility);
|
|
46046
|
-
const scriptsPath =
|
|
46047
|
-
if (!hasCompatibility &&
|
|
46108
|
+
const scriptsPath = path14.join(d, "scripts.js");
|
|
46109
|
+
if (!hasCompatibility && fs7.existsSync(scriptsPath)) {
|
|
46048
46110
|
try {
|
|
46049
46111
|
delete require.cache[require.resolve(scriptsPath)];
|
|
46050
46112
|
const scripts = require(scriptsPath);
|
|
@@ -46069,7 +46131,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
46069
46131
|
if (!entry.isDirectory()) continue;
|
|
46070
46132
|
if (entry.name.startsWith("_") || entry.name.startsWith(".")) continue;
|
|
46071
46133
|
if (excludeDirs && d === dir && excludeDirs.includes(entry.name)) continue;
|
|
46072
|
-
scan(
|
|
46134
|
+
scan(path14.join(d, entry.name));
|
|
46073
46135
|
}
|
|
46074
46136
|
}
|
|
46075
46137
|
};
|
|
@@ -46255,7 +46317,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
46255
46317
|
});
|
|
46256
46318
|
}
|
|
46257
46319
|
async function killIdeProcess(ideId) {
|
|
46258
|
-
const plat =
|
|
46320
|
+
const plat = os15.platform();
|
|
46259
46321
|
const appName = getMacAppIdentifiers()[ideId];
|
|
46260
46322
|
const winProcesses = getWinProcessNames()[ideId];
|
|
46261
46323
|
try {
|
|
@@ -46316,7 +46378,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
46316
46378
|
}
|
|
46317
46379
|
}
|
|
46318
46380
|
function isIdeRunning(ideId) {
|
|
46319
|
-
const plat =
|
|
46381
|
+
const plat = os15.platform();
|
|
46320
46382
|
try {
|
|
46321
46383
|
if (plat === "darwin") {
|
|
46322
46384
|
const appName = getMacAppIdentifiers()[ideId];
|
|
@@ -46371,7 +46433,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
46371
46433
|
}
|
|
46372
46434
|
}
|
|
46373
46435
|
function detectCurrentWorkspace(ideId) {
|
|
46374
|
-
const plat =
|
|
46436
|
+
const plat = os15.platform();
|
|
46375
46437
|
if (plat === "darwin") {
|
|
46376
46438
|
try {
|
|
46377
46439
|
const appName = getMacAppIdentifiers()[ideId];
|
|
@@ -46386,17 +46448,17 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
46386
46448
|
}
|
|
46387
46449
|
} else if (plat === "win32") {
|
|
46388
46450
|
try {
|
|
46389
|
-
const
|
|
46451
|
+
const fs16 = require("fs");
|
|
46390
46452
|
const appNameMap = getMacAppIdentifiers();
|
|
46391
46453
|
const appName = appNameMap[ideId];
|
|
46392
46454
|
if (appName) {
|
|
46393
|
-
const storagePath =
|
|
46394
|
-
process.env.APPDATA ||
|
|
46455
|
+
const storagePath = path15.join(
|
|
46456
|
+
process.env.APPDATA || path15.join(os15.homedir(), "AppData", "Roaming"),
|
|
46395
46457
|
appName,
|
|
46396
46458
|
"storage.json"
|
|
46397
46459
|
);
|
|
46398
|
-
if (
|
|
46399
|
-
const data = JSON.parse(
|
|
46460
|
+
if (fs16.existsSync(storagePath)) {
|
|
46461
|
+
const data = JSON.parse(fs16.readFileSync(storagePath, "utf-8"));
|
|
46400
46462
|
const workspaces = data?.openedPathsList?.workspaces3 || data?.openedPathsList?.entries || [];
|
|
46401
46463
|
if (workspaces.length > 0) {
|
|
46402
46464
|
const recent = workspaces[0];
|
|
@@ -46413,7 +46475,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
46413
46475
|
return void 0;
|
|
46414
46476
|
}
|
|
46415
46477
|
async function launchWithCdp(options = {}) {
|
|
46416
|
-
const platform10 =
|
|
46478
|
+
const platform10 = os15.platform();
|
|
46417
46479
|
let targetIde;
|
|
46418
46480
|
const ides = await detectIDEs(getProviderLoader());
|
|
46419
46481
|
if (options.ideId) {
|
|
@@ -46564,14 +46626,14 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
46564
46626
|
}
|
|
46565
46627
|
init_config();
|
|
46566
46628
|
init_logger();
|
|
46567
|
-
var
|
|
46568
|
-
var
|
|
46569
|
-
var
|
|
46570
|
-
var LOG_DIR2 = process.platform === "win32" ?
|
|
46629
|
+
var fs8 = __toESM2(require("fs"));
|
|
46630
|
+
var path16 = __toESM2(require("path"));
|
|
46631
|
+
var os16 = __toESM2(require("os"));
|
|
46632
|
+
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");
|
|
46571
46633
|
var MAX_FILE_SIZE = 5 * 1024 * 1024;
|
|
46572
46634
|
var MAX_DAYS = 7;
|
|
46573
46635
|
try {
|
|
46574
|
-
|
|
46636
|
+
fs8.mkdirSync(LOG_DIR2, { recursive: true });
|
|
46575
46637
|
} catch {
|
|
46576
46638
|
}
|
|
46577
46639
|
var SENSITIVE_KEYS = /* @__PURE__ */ new Set([
|
|
@@ -46605,19 +46667,19 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
46605
46667
|
return (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
46606
46668
|
}
|
|
46607
46669
|
var currentDate2 = getDateStr2();
|
|
46608
|
-
var currentFile =
|
|
46670
|
+
var currentFile = path16.join(LOG_DIR2, `commands-${currentDate2}.jsonl`);
|
|
46609
46671
|
var writeCount2 = 0;
|
|
46610
46672
|
function checkRotation() {
|
|
46611
46673
|
const today = getDateStr2();
|
|
46612
46674
|
if (today !== currentDate2) {
|
|
46613
46675
|
currentDate2 = today;
|
|
46614
|
-
currentFile =
|
|
46676
|
+
currentFile = path16.join(LOG_DIR2, `commands-${currentDate2}.jsonl`);
|
|
46615
46677
|
cleanOldFiles();
|
|
46616
46678
|
}
|
|
46617
46679
|
}
|
|
46618
46680
|
function cleanOldFiles() {
|
|
46619
46681
|
try {
|
|
46620
|
-
const files =
|
|
46682
|
+
const files = fs8.readdirSync(LOG_DIR2).filter((f) => f.startsWith("commands-") && f.endsWith(".jsonl"));
|
|
46621
46683
|
const cutoff = /* @__PURE__ */ new Date();
|
|
46622
46684
|
cutoff.setDate(cutoff.getDate() - MAX_DAYS);
|
|
46623
46685
|
const cutoffStr = cutoff.toISOString().slice(0, 10);
|
|
@@ -46625,7 +46687,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
46625
46687
|
const dateMatch = file2.match(/commands-(\d{4}-\d{2}-\d{2})/);
|
|
46626
46688
|
if (dateMatch && dateMatch[1] < cutoffStr) {
|
|
46627
46689
|
try {
|
|
46628
|
-
|
|
46690
|
+
fs8.unlinkSync(path16.join(LOG_DIR2, file2));
|
|
46629
46691
|
} catch {
|
|
46630
46692
|
}
|
|
46631
46693
|
}
|
|
@@ -46635,14 +46697,14 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
46635
46697
|
}
|
|
46636
46698
|
function checkSize() {
|
|
46637
46699
|
try {
|
|
46638
|
-
const stat4 =
|
|
46700
|
+
const stat4 = fs8.statSync(currentFile);
|
|
46639
46701
|
if (stat4.size > MAX_FILE_SIZE) {
|
|
46640
46702
|
const backup = currentFile.replace(".jsonl", ".1.jsonl");
|
|
46641
46703
|
try {
|
|
46642
|
-
|
|
46704
|
+
fs8.unlinkSync(backup);
|
|
46643
46705
|
} catch {
|
|
46644
46706
|
}
|
|
46645
|
-
|
|
46707
|
+
fs8.renameSync(currentFile, backup);
|
|
46646
46708
|
}
|
|
46647
46709
|
} catch {
|
|
46648
46710
|
}
|
|
@@ -46675,14 +46737,14 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
46675
46737
|
...entry.error ? { err: entry.error } : {},
|
|
46676
46738
|
...entry.durationMs !== void 0 ? { ms: entry.durationMs } : {}
|
|
46677
46739
|
});
|
|
46678
|
-
|
|
46740
|
+
fs8.appendFileSync(currentFile, line + "\n");
|
|
46679
46741
|
} catch {
|
|
46680
46742
|
}
|
|
46681
46743
|
}
|
|
46682
46744
|
function getRecentCommands(count = 50) {
|
|
46683
46745
|
try {
|
|
46684
|
-
if (!
|
|
46685
|
-
const content =
|
|
46746
|
+
if (!fs8.existsSync(currentFile)) return [];
|
|
46747
|
+
const content = fs8.readFileSync(currentFile, "utf-8");
|
|
46686
46748
|
const lines = content.trim().split("\n").filter(Boolean);
|
|
46687
46749
|
return lines.slice(-count).map((line) => {
|
|
46688
46750
|
try {
|
|
@@ -46707,7 +46769,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
46707
46769
|
}
|
|
46708
46770
|
cleanOldFiles();
|
|
46709
46771
|
init_logger();
|
|
46710
|
-
var
|
|
46772
|
+
var os17 = __toESM2(require("os"));
|
|
46711
46773
|
init_config();
|
|
46712
46774
|
init_terminal_screen();
|
|
46713
46775
|
init_logger();
|
|
@@ -46762,8 +46824,8 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
46762
46824
|
}
|
|
46763
46825
|
function buildMachineInfo2(profile = "full") {
|
|
46764
46826
|
const base = {
|
|
46765
|
-
hostname:
|
|
46766
|
-
platform:
|
|
46827
|
+
hostname: os17.hostname(),
|
|
46828
|
+
platform: os17.platform()
|
|
46767
46829
|
};
|
|
46768
46830
|
if (profile === "live") {
|
|
46769
46831
|
return base;
|
|
@@ -46772,23 +46834,23 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
46772
46834
|
const memSnap2 = getHostMemorySnapshot();
|
|
46773
46835
|
return {
|
|
46774
46836
|
...base,
|
|
46775
|
-
arch:
|
|
46776
|
-
cpus:
|
|
46837
|
+
arch: os17.arch(),
|
|
46838
|
+
cpus: os17.cpus().length,
|
|
46777
46839
|
totalMem: memSnap2.totalMem,
|
|
46778
|
-
release:
|
|
46840
|
+
release: os17.release()
|
|
46779
46841
|
};
|
|
46780
46842
|
}
|
|
46781
46843
|
const memSnap = getHostMemorySnapshot();
|
|
46782
46844
|
return {
|
|
46783
46845
|
...base,
|
|
46784
|
-
arch:
|
|
46785
|
-
cpus:
|
|
46846
|
+
arch: os17.arch(),
|
|
46847
|
+
cpus: os17.cpus().length,
|
|
46786
46848
|
totalMem: memSnap.totalMem,
|
|
46787
46849
|
freeMem: memSnap.freeMem,
|
|
46788
46850
|
availableMem: memSnap.availableMem,
|
|
46789
|
-
loadavg:
|
|
46790
|
-
uptime:
|
|
46791
|
-
release:
|
|
46851
|
+
loadavg: os17.loadavg(),
|
|
46852
|
+
uptime: os17.uptime(),
|
|
46853
|
+
release: os17.release()
|
|
46792
46854
|
};
|
|
46793
46855
|
}
|
|
46794
46856
|
function parseMessageTime(value) {
|
|
@@ -47013,42 +47075,42 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
47013
47075
|
}
|
|
47014
47076
|
var import_child_process8 = require("child_process");
|
|
47015
47077
|
var import_child_process9 = require("child_process");
|
|
47016
|
-
var
|
|
47017
|
-
var
|
|
47018
|
-
var
|
|
47078
|
+
var fs9 = __toESM2(require("fs"));
|
|
47079
|
+
var os18 = __toESM2(require("os"));
|
|
47080
|
+
var path17 = __toESM2(require("path"));
|
|
47019
47081
|
var UPGRADE_HELPER_ENV = "ADHDEV_DAEMON_UPGRADE_HELPER";
|
|
47020
47082
|
function getUpgradeLogPath() {
|
|
47021
|
-
const home =
|
|
47022
|
-
const dir =
|
|
47023
|
-
|
|
47024
|
-
return
|
|
47083
|
+
const home = os18.homedir();
|
|
47084
|
+
const dir = path17.join(home, ".adhdev");
|
|
47085
|
+
fs9.mkdirSync(dir, { recursive: true });
|
|
47086
|
+
return path17.join(dir, "daemon-upgrade.log");
|
|
47025
47087
|
}
|
|
47026
47088
|
function appendUpgradeLog(message) {
|
|
47027
47089
|
const line = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${message}
|
|
47028
47090
|
`;
|
|
47029
47091
|
try {
|
|
47030
|
-
|
|
47092
|
+
fs9.appendFileSync(getUpgradeLogPath(), line, "utf8");
|
|
47031
47093
|
} catch {
|
|
47032
47094
|
}
|
|
47033
47095
|
}
|
|
47034
47096
|
function resolveSiblingNpmInvocation(nodeExecutable, platform10 = process.platform) {
|
|
47035
|
-
const binDir =
|
|
47097
|
+
const binDir = path17.dirname(nodeExecutable);
|
|
47036
47098
|
if (platform10 === "win32") {
|
|
47037
|
-
const npmCliPath =
|
|
47038
|
-
if (
|
|
47099
|
+
const npmCliPath = path17.join(binDir, "node_modules", "npm", "bin", "npm-cli.js");
|
|
47100
|
+
if (fs9.existsSync(npmCliPath)) {
|
|
47039
47101
|
return { executable: nodeExecutable, argsPrefix: [npmCliPath], execOptions: getNpmExecOptions(platform10) };
|
|
47040
47102
|
}
|
|
47041
47103
|
for (const candidate of ["npm.exe", "npm"]) {
|
|
47042
|
-
const candidatePath =
|
|
47043
|
-
if (
|
|
47104
|
+
const candidatePath = path17.join(binDir, candidate);
|
|
47105
|
+
if (fs9.existsSync(candidatePath)) {
|
|
47044
47106
|
return { executable: candidatePath, argsPrefix: [], execOptions: getNpmExecOptions(platform10) };
|
|
47045
47107
|
}
|
|
47046
47108
|
}
|
|
47047
47109
|
return { executable: nodeExecutable, argsPrefix: [npmCliPath], execOptions: getNpmExecOptions(platform10) };
|
|
47048
47110
|
}
|
|
47049
47111
|
for (const candidate of ["npm"]) {
|
|
47050
|
-
const candidatePath =
|
|
47051
|
-
if (
|
|
47112
|
+
const candidatePath = path17.join(binDir, candidate);
|
|
47113
|
+
if (fs9.existsSync(candidatePath)) {
|
|
47052
47114
|
return { executable: candidatePath, argsPrefix: [], execOptions: getNpmExecOptions(platform10) };
|
|
47053
47115
|
}
|
|
47054
47116
|
}
|
|
@@ -47058,22 +47120,22 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
47058
47120
|
if (!currentCliPath) return null;
|
|
47059
47121
|
let resolvedPath = currentCliPath;
|
|
47060
47122
|
try {
|
|
47061
|
-
resolvedPath =
|
|
47123
|
+
resolvedPath = fs9.realpathSync.native(currentCliPath);
|
|
47062
47124
|
} catch {
|
|
47063
47125
|
}
|
|
47064
47126
|
let currentDir = resolvedPath;
|
|
47065
47127
|
try {
|
|
47066
|
-
if (
|
|
47067
|
-
currentDir =
|
|
47128
|
+
if (fs9.statSync(resolvedPath).isFile()) {
|
|
47129
|
+
currentDir = path17.dirname(resolvedPath);
|
|
47068
47130
|
}
|
|
47069
47131
|
} catch {
|
|
47070
|
-
currentDir =
|
|
47132
|
+
currentDir = path17.dirname(resolvedPath);
|
|
47071
47133
|
}
|
|
47072
47134
|
while (true) {
|
|
47073
|
-
const packageJsonPath =
|
|
47135
|
+
const packageJsonPath = path17.join(currentDir, "package.json");
|
|
47074
47136
|
try {
|
|
47075
|
-
if (
|
|
47076
|
-
const parsed = JSON.parse(
|
|
47137
|
+
if (fs9.existsSync(packageJsonPath)) {
|
|
47138
|
+
const parsed = JSON.parse(fs9.readFileSync(packageJsonPath, "utf8"));
|
|
47077
47139
|
if (parsed?.name === packageName) {
|
|
47078
47140
|
const normalized = currentDir.replace(/\\/g, "/");
|
|
47079
47141
|
return normalized.includes("/node_modules/") ? currentDir : null;
|
|
@@ -47081,7 +47143,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
47081
47143
|
}
|
|
47082
47144
|
} catch {
|
|
47083
47145
|
}
|
|
47084
|
-
const parentDir =
|
|
47146
|
+
const parentDir = path17.dirname(currentDir);
|
|
47085
47147
|
if (parentDir === currentDir) {
|
|
47086
47148
|
return null;
|
|
47087
47149
|
}
|
|
@@ -47089,13 +47151,13 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
47089
47151
|
}
|
|
47090
47152
|
}
|
|
47091
47153
|
function resolveInstallPrefixFromPackageRoot(packageRoot, packageName) {
|
|
47092
|
-
const nodeModulesDir = packageName.startsWith("@") ?
|
|
47093
|
-
if (
|
|
47154
|
+
const nodeModulesDir = packageName.startsWith("@") ? path17.dirname(path17.dirname(packageRoot)) : path17.dirname(packageRoot);
|
|
47155
|
+
if (path17.basename(nodeModulesDir) !== "node_modules") {
|
|
47094
47156
|
return null;
|
|
47095
47157
|
}
|
|
47096
|
-
const maybeLibDir =
|
|
47097
|
-
if (
|
|
47098
|
-
return
|
|
47158
|
+
const maybeLibDir = path17.dirname(nodeModulesDir);
|
|
47159
|
+
if (path17.basename(maybeLibDir) === "lib") {
|
|
47160
|
+
return path17.dirname(maybeLibDir);
|
|
47099
47161
|
}
|
|
47100
47162
|
return maybeLibDir;
|
|
47101
47163
|
}
|
|
@@ -47210,10 +47272,10 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
47210
47272
|
}
|
|
47211
47273
|
}
|
|
47212
47274
|
function stopSessionHostProcesses(appName) {
|
|
47213
|
-
const pidFile =
|
|
47275
|
+
const pidFile = path17.join(os18.homedir(), ".adhdev", `${appName}-session-host.pid`);
|
|
47214
47276
|
try {
|
|
47215
|
-
if (
|
|
47216
|
-
const pid = Number.parseInt(
|
|
47277
|
+
if (fs9.existsSync(pidFile)) {
|
|
47278
|
+
const pid = Number.parseInt(fs9.readFileSync(pidFile, "utf8").trim(), 10);
|
|
47217
47279
|
if (Number.isFinite(pid) && pid !== process.pid && isManagedSessionHostPid(pid)) {
|
|
47218
47280
|
killPid2(pid);
|
|
47219
47281
|
}
|
|
@@ -47221,15 +47283,15 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
47221
47283
|
} catch {
|
|
47222
47284
|
} finally {
|
|
47223
47285
|
try {
|
|
47224
|
-
|
|
47286
|
+
fs9.unlinkSync(pidFile);
|
|
47225
47287
|
} catch {
|
|
47226
47288
|
}
|
|
47227
47289
|
}
|
|
47228
47290
|
}
|
|
47229
47291
|
function removeDaemonPidFile() {
|
|
47230
|
-
const pidFile =
|
|
47292
|
+
const pidFile = path17.join(os18.homedir(), ".adhdev", "daemon.pid");
|
|
47231
47293
|
try {
|
|
47232
|
-
|
|
47294
|
+
fs9.unlinkSync(pidFile);
|
|
47233
47295
|
} catch {
|
|
47234
47296
|
}
|
|
47235
47297
|
}
|
|
@@ -47238,7 +47300,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
47238
47300
|
const npmRoot = String(execNpmCommandSync(["root", "-g", ...prefixArgs], { encoding: "utf8" }, surface)).trim();
|
|
47239
47301
|
if (!npmRoot) return;
|
|
47240
47302
|
const npmPrefix = surface.installPrefix || String(execNpmCommandSync(["prefix", "-g", ...prefixArgs], { encoding: "utf8" }, surface)).trim();
|
|
47241
|
-
const binDir = process.platform === "win32" ? npmPrefix :
|
|
47303
|
+
const binDir = process.platform === "win32" ? npmPrefix : path17.join(npmPrefix, "bin");
|
|
47242
47304
|
const packageBaseName = pkgName.startsWith("@") ? pkgName.split("/")[1] : pkgName;
|
|
47243
47305
|
const binNames = /* @__PURE__ */ new Set([packageBaseName]);
|
|
47244
47306
|
if (pkgName === "@adhdev/daemon-standalone") {
|
|
@@ -47246,25 +47308,25 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
47246
47308
|
}
|
|
47247
47309
|
if (pkgName.startsWith("@")) {
|
|
47248
47310
|
const [scope, name] = pkgName.split("/");
|
|
47249
|
-
const scopeDir =
|
|
47250
|
-
if (!
|
|
47251
|
-
for (const entry of
|
|
47311
|
+
const scopeDir = path17.join(npmRoot, scope);
|
|
47312
|
+
if (!fs9.existsSync(scopeDir)) return;
|
|
47313
|
+
for (const entry of fs9.readdirSync(scopeDir)) {
|
|
47252
47314
|
if (!entry.startsWith(`.${name}-`)) continue;
|
|
47253
|
-
|
|
47254
|
-
appendUpgradeLog(`Removed stale scoped staging dir: ${
|
|
47315
|
+
fs9.rmSync(path17.join(scopeDir, entry), { recursive: true, force: true });
|
|
47316
|
+
appendUpgradeLog(`Removed stale scoped staging dir: ${path17.join(scopeDir, entry)}`);
|
|
47255
47317
|
}
|
|
47256
47318
|
} else {
|
|
47257
|
-
for (const entry of
|
|
47319
|
+
for (const entry of fs9.readdirSync(npmRoot)) {
|
|
47258
47320
|
if (!entry.startsWith(`.${pkgName}-`)) continue;
|
|
47259
|
-
|
|
47260
|
-
appendUpgradeLog(`Removed stale staging dir: ${
|
|
47321
|
+
fs9.rmSync(path17.join(npmRoot, entry), { recursive: true, force: true });
|
|
47322
|
+
appendUpgradeLog(`Removed stale staging dir: ${path17.join(npmRoot, entry)}`);
|
|
47261
47323
|
}
|
|
47262
47324
|
}
|
|
47263
|
-
if (
|
|
47264
|
-
for (const entry of
|
|
47325
|
+
if (fs9.existsSync(binDir)) {
|
|
47326
|
+
for (const entry of fs9.readdirSync(binDir)) {
|
|
47265
47327
|
if (!Array.from(binNames).some((name) => entry.startsWith(`.${name}-`))) continue;
|
|
47266
|
-
|
|
47267
|
-
appendUpgradeLog(`Removed stale bin staging entry: ${
|
|
47328
|
+
fs9.rmSync(path17.join(binDir, entry), { recursive: true, force: true });
|
|
47329
|
+
appendUpgradeLog(`Removed stale bin staging entry: ${path17.join(binDir, entry)}`);
|
|
47268
47330
|
}
|
|
47269
47331
|
}
|
|
47270
47332
|
}
|
|
@@ -47347,7 +47409,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
47347
47409
|
process.exit(1);
|
|
47348
47410
|
}
|
|
47349
47411
|
}
|
|
47350
|
-
var
|
|
47412
|
+
var fs10 = __toESM2(require("fs"));
|
|
47351
47413
|
var CHAT_COMMANDS = [
|
|
47352
47414
|
"send_chat",
|
|
47353
47415
|
"new_chat",
|
|
@@ -47583,8 +47645,8 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
47583
47645
|
if (sinceTs > 0) {
|
|
47584
47646
|
return { success: true, logs: [], totalBuffered: 0 };
|
|
47585
47647
|
}
|
|
47586
|
-
if (
|
|
47587
|
-
const content =
|
|
47648
|
+
if (fs10.existsSync(LOG_PATH)) {
|
|
47649
|
+
const content = fs10.readFileSync(LOG_PATH, "utf-8");
|
|
47588
47650
|
const allLines = content.split("\n");
|
|
47589
47651
|
const recent = allLines.slice(-count).join("\n");
|
|
47590
47652
|
return { success: true, logs: recent, totalLines: allLines.length };
|
|
@@ -49715,12 +49777,12 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
49715
49777
|
};
|
|
49716
49778
|
init_io_contracts();
|
|
49717
49779
|
init_chat_message_normalization();
|
|
49718
|
-
var
|
|
49719
|
-
var
|
|
49720
|
-
var
|
|
49780
|
+
var fs11 = __toESM2(require("fs"));
|
|
49781
|
+
var path18 = __toESM2(require("path"));
|
|
49782
|
+
var os19 = __toESM2(require("os"));
|
|
49721
49783
|
var import_child_process10 = require("child_process");
|
|
49722
49784
|
var import_os3 = require("os");
|
|
49723
|
-
var ARCHIVE_PATH =
|
|
49785
|
+
var ARCHIVE_PATH = path18.join(os19.homedir(), ".adhdev", "version-history.json");
|
|
49724
49786
|
var MAX_ENTRIES_PER_PROVIDER = 20;
|
|
49725
49787
|
var VersionArchive = class {
|
|
49726
49788
|
history = {};
|
|
@@ -49729,8 +49791,8 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
49729
49791
|
}
|
|
49730
49792
|
load() {
|
|
49731
49793
|
try {
|
|
49732
|
-
if (
|
|
49733
|
-
this.history = JSON.parse(
|
|
49794
|
+
if (fs11.existsSync(ARCHIVE_PATH)) {
|
|
49795
|
+
this.history = JSON.parse(fs11.readFileSync(ARCHIVE_PATH, "utf-8"));
|
|
49734
49796
|
}
|
|
49735
49797
|
} catch {
|
|
49736
49798
|
this.history = {};
|
|
@@ -49767,8 +49829,8 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
49767
49829
|
}
|
|
49768
49830
|
save() {
|
|
49769
49831
|
try {
|
|
49770
|
-
|
|
49771
|
-
|
|
49832
|
+
fs11.mkdirSync(path18.dirname(ARCHIVE_PATH), { recursive: true });
|
|
49833
|
+
fs11.writeFileSync(ARCHIVE_PATH, JSON.stringify(this.history, null, 2));
|
|
49772
49834
|
} catch {
|
|
49773
49835
|
}
|
|
49774
49836
|
}
|
|
@@ -49823,19 +49885,19 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
49823
49885
|
function checkPathExists2(paths) {
|
|
49824
49886
|
for (const p of paths) {
|
|
49825
49887
|
if (p.includes("*")) {
|
|
49826
|
-
const home =
|
|
49827
|
-
const resolved = p.replace(/\*/g, home.split(
|
|
49828
|
-
if (
|
|
49888
|
+
const home = os19.homedir();
|
|
49889
|
+
const resolved = p.replace(/\*/g, home.split(path18.sep).pop() || "");
|
|
49890
|
+
if (fs11.existsSync(resolved)) return resolved;
|
|
49829
49891
|
} else {
|
|
49830
|
-
if (
|
|
49892
|
+
if (fs11.existsSync(p)) return p;
|
|
49831
49893
|
}
|
|
49832
49894
|
}
|
|
49833
49895
|
return null;
|
|
49834
49896
|
}
|
|
49835
49897
|
function getMacAppVersion(appPath) {
|
|
49836
49898
|
if ((0, import_os3.platform)() !== "darwin" || !appPath.endsWith(".app")) return null;
|
|
49837
|
-
const plistPath =
|
|
49838
|
-
if (!
|
|
49899
|
+
const plistPath = path18.join(appPath, "Contents", "Info.plist");
|
|
49900
|
+
if (!fs11.existsSync(plistPath)) return null;
|
|
49839
49901
|
const raw = runCommand(`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${plistPath}"`);
|
|
49840
49902
|
return raw || null;
|
|
49841
49903
|
}
|
|
@@ -49860,8 +49922,8 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
49860
49922
|
const cliBin = provider.cli ? findBinary2(provider.cli) : null;
|
|
49861
49923
|
let resolvedBin = cliBin;
|
|
49862
49924
|
if (!resolvedBin && appPath && currentOs === "darwin") {
|
|
49863
|
-
const bundled =
|
|
49864
|
-
if (provider.cli &&
|
|
49925
|
+
const bundled = path18.join(appPath, "Contents", "Resources", "app", "bin", provider.cli || "");
|
|
49926
|
+
if (provider.cli && fs11.existsSync(bundled)) resolvedBin = bundled;
|
|
49865
49927
|
}
|
|
49866
49928
|
info.installed = !!(appPath || resolvedBin);
|
|
49867
49929
|
info.path = appPath || null;
|
|
@@ -49898,8 +49960,8 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
49898
49960
|
return results;
|
|
49899
49961
|
}
|
|
49900
49962
|
var http2 = __toESM2(require("http"));
|
|
49901
|
-
var
|
|
49902
|
-
var
|
|
49963
|
+
var fs15 = __toESM2(require("fs"));
|
|
49964
|
+
var path222 = __toESM2(require("path"));
|
|
49903
49965
|
init_config();
|
|
49904
49966
|
function generateFiles(type, name, category, opts = {}) {
|
|
49905
49967
|
const { cdpPorts, cli, processName, installPath, binary, extensionId, version: version2 = "0.1" } = opts;
|
|
@@ -50243,8 +50305,8 @@ async (params) => {
|
|
|
50243
50305
|
};
|
|
50244
50306
|
}
|
|
50245
50307
|
init_logger();
|
|
50246
|
-
var
|
|
50247
|
-
var
|
|
50308
|
+
var fs12 = __toESM2(require("fs"));
|
|
50309
|
+
var path19 = __toESM2(require("path"));
|
|
50248
50310
|
init_logger();
|
|
50249
50311
|
async function handleCdpEvaluate(ctx, req, res) {
|
|
50250
50312
|
const body = await ctx.readBody(req);
|
|
@@ -50423,18 +50485,18 @@ async (params) => {
|
|
|
50423
50485
|
return;
|
|
50424
50486
|
}
|
|
50425
50487
|
let scriptsPath = "";
|
|
50426
|
-
const directScripts =
|
|
50427
|
-
if (
|
|
50488
|
+
const directScripts = path19.join(dir, "scripts.js");
|
|
50489
|
+
if (fs12.existsSync(directScripts)) {
|
|
50428
50490
|
scriptsPath = directScripts;
|
|
50429
50491
|
} else {
|
|
50430
|
-
const scriptsDir =
|
|
50431
|
-
if (
|
|
50432
|
-
const versions =
|
|
50433
|
-
return
|
|
50492
|
+
const scriptsDir = path19.join(dir, "scripts");
|
|
50493
|
+
if (fs12.existsSync(scriptsDir)) {
|
|
50494
|
+
const versions = fs12.readdirSync(scriptsDir).filter((d) => {
|
|
50495
|
+
return fs12.statSync(path19.join(scriptsDir, d)).isDirectory();
|
|
50434
50496
|
}).sort().reverse();
|
|
50435
50497
|
for (const ver of versions) {
|
|
50436
|
-
const p =
|
|
50437
|
-
if (
|
|
50498
|
+
const p = path19.join(scriptsDir, ver, "scripts.js");
|
|
50499
|
+
if (fs12.existsSync(p)) {
|
|
50438
50500
|
scriptsPath = p;
|
|
50439
50501
|
break;
|
|
50440
50502
|
}
|
|
@@ -50446,7 +50508,7 @@ async (params) => {
|
|
|
50446
50508
|
return;
|
|
50447
50509
|
}
|
|
50448
50510
|
try {
|
|
50449
|
-
const source =
|
|
50511
|
+
const source = fs12.readFileSync(scriptsPath, "utf-8");
|
|
50450
50512
|
const hints = {};
|
|
50451
50513
|
const funcRegex = /module\.exports\.(\w+)\s*=\s*function\s+\w+\s*\(params\)/g;
|
|
50452
50514
|
let match;
|
|
@@ -51259,8 +51321,8 @@ async (params) => {
|
|
|
51259
51321
|
ctx.json(res, 500, { error: `DOM context collection failed: ${e.message}` });
|
|
51260
51322
|
}
|
|
51261
51323
|
}
|
|
51262
|
-
var
|
|
51263
|
-
var
|
|
51324
|
+
var fs13 = __toESM2(require("fs"));
|
|
51325
|
+
var path20 = __toESM2(require("path"));
|
|
51264
51326
|
function slugifyFixtureName(value) {
|
|
51265
51327
|
const normalized = String(value || "").trim().toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
51266
51328
|
return normalized || `fixture-${Date.now()}`;
|
|
@@ -51270,15 +51332,15 @@ async (params) => {
|
|
|
51270
51332
|
if (!providerDir) {
|
|
51271
51333
|
throw new Error(`Provider directory not found for '${type}'`);
|
|
51272
51334
|
}
|
|
51273
|
-
return
|
|
51335
|
+
return path20.join(providerDir, "fixtures");
|
|
51274
51336
|
}
|
|
51275
51337
|
function readCliFixture(ctx, type, name) {
|
|
51276
51338
|
const fixtureDir = getCliFixtureDir(ctx, type);
|
|
51277
|
-
const filePath =
|
|
51278
|
-
if (!
|
|
51339
|
+
const filePath = path20.join(fixtureDir, `${name}.json`);
|
|
51340
|
+
if (!fs13.existsSync(filePath)) {
|
|
51279
51341
|
throw new Error(`Fixture not found: ${filePath}`);
|
|
51280
51342
|
}
|
|
51281
|
-
return JSON.parse(
|
|
51343
|
+
return JSON.parse(fs13.readFileSync(filePath, "utf-8"));
|
|
51282
51344
|
}
|
|
51283
51345
|
function getExerciseTranscriptText(result) {
|
|
51284
51346
|
const parts = [];
|
|
@@ -52014,7 +52076,7 @@ async (params) => {
|
|
|
52014
52076
|
return;
|
|
52015
52077
|
}
|
|
52016
52078
|
const fixtureDir = getCliFixtureDir(ctx, type);
|
|
52017
|
-
|
|
52079
|
+
fs13.mkdirSync(fixtureDir, { recursive: true });
|
|
52018
52080
|
const name = slugifyFixtureName(String(body?.name || `${type}-${Date.now()}`));
|
|
52019
52081
|
const result = await runCliExerciseInternal(ctx, { ...request, type });
|
|
52020
52082
|
const fixture = {
|
|
@@ -52041,8 +52103,8 @@ async (params) => {
|
|
|
52041
52103
|
},
|
|
52042
52104
|
notes: typeof body?.notes === "string" ? body.notes : void 0
|
|
52043
52105
|
};
|
|
52044
|
-
const filePath =
|
|
52045
|
-
|
|
52106
|
+
const filePath = path20.join(fixtureDir, `${name}.json`);
|
|
52107
|
+
fs13.writeFileSync(filePath, JSON.stringify(fixture, null, 2));
|
|
52046
52108
|
ctx.json(res, 200, {
|
|
52047
52109
|
saved: true,
|
|
52048
52110
|
name,
|
|
@@ -52060,14 +52122,14 @@ async (params) => {
|
|
|
52060
52122
|
async function handleCliFixtureList(ctx, type, _req, res) {
|
|
52061
52123
|
try {
|
|
52062
52124
|
const fixtureDir = getCliFixtureDir(ctx, type);
|
|
52063
|
-
if (!
|
|
52125
|
+
if (!fs13.existsSync(fixtureDir)) {
|
|
52064
52126
|
ctx.json(res, 200, { fixtures: [], count: 0 });
|
|
52065
52127
|
return;
|
|
52066
52128
|
}
|
|
52067
|
-
const fixtures =
|
|
52068
|
-
const fullPath =
|
|
52129
|
+
const fixtures = fs13.readdirSync(fixtureDir).filter((file2) => file2.endsWith(".json")).sort((a, b2) => b2.localeCompare(a, void 0, { numeric: true, sensitivity: "base" })).map((file2) => {
|
|
52130
|
+
const fullPath = path20.join(fixtureDir, file2);
|
|
52069
52131
|
try {
|
|
52070
|
-
const raw = JSON.parse(
|
|
52132
|
+
const raw = JSON.parse(fs13.readFileSync(fullPath, "utf-8"));
|
|
52071
52133
|
return {
|
|
52072
52134
|
name: raw.name || file2.replace(/\.json$/i, ""),
|
|
52073
52135
|
path: fullPath,
|
|
@@ -52198,9 +52260,9 @@ async (params) => {
|
|
|
52198
52260
|
ctx.json(res, 500, { error: `Raw send failed: ${e.message}` });
|
|
52199
52261
|
}
|
|
52200
52262
|
}
|
|
52201
|
-
var
|
|
52202
|
-
var
|
|
52203
|
-
var
|
|
52263
|
+
var fs14 = __toESM2(require("fs"));
|
|
52264
|
+
var path21 = __toESM2(require("path"));
|
|
52265
|
+
var os20 = __toESM2(require("os"));
|
|
52204
52266
|
function getAutoImplPid(ctx) {
|
|
52205
52267
|
const pid = ctx.autoImplProcess?.pid;
|
|
52206
52268
|
return typeof pid === "number" && pid > 0 ? pid : null;
|
|
@@ -52246,38 +52308,38 @@ async (params) => {
|
|
|
52246
52308
|
return fallback?.type || null;
|
|
52247
52309
|
}
|
|
52248
52310
|
function getLatestScriptVersionDir(scriptsDir) {
|
|
52249
|
-
if (!
|
|
52250
|
-
const versions =
|
|
52311
|
+
if (!fs14.existsSync(scriptsDir)) return null;
|
|
52312
|
+
const versions = fs14.readdirSync(scriptsDir).filter((d) => {
|
|
52251
52313
|
try {
|
|
52252
|
-
return
|
|
52314
|
+
return fs14.statSync(path21.join(scriptsDir, d)).isDirectory();
|
|
52253
52315
|
} catch {
|
|
52254
52316
|
return false;
|
|
52255
52317
|
}
|
|
52256
52318
|
}).sort((a, b2) => b2.localeCompare(a, void 0, { numeric: true, sensitivity: "base" }));
|
|
52257
52319
|
if (versions.length === 0) return null;
|
|
52258
|
-
return
|
|
52320
|
+
return path21.join(scriptsDir, versions[0]);
|
|
52259
52321
|
}
|
|
52260
52322
|
function resolveAutoImplWritableProviderDir(ctx, category, type, requestedDir) {
|
|
52261
|
-
const canonicalUserDir =
|
|
52262
|
-
const desiredDir = requestedDir ?
|
|
52263
|
-
const upstreamRoot =
|
|
52264
|
-
if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${
|
|
52323
|
+
const canonicalUserDir = path21.resolve(ctx.providerLoader.getUserProviderDir(category, type));
|
|
52324
|
+
const desiredDir = requestedDir ? path21.resolve(requestedDir) : canonicalUserDir;
|
|
52325
|
+
const upstreamRoot = path21.resolve(ctx.providerLoader.getUpstreamDir());
|
|
52326
|
+
if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${path21.sep}`)) {
|
|
52265
52327
|
return { dir: null, reason: `Refusing to write into upstream provider directory: ${desiredDir}` };
|
|
52266
52328
|
}
|
|
52267
|
-
if (
|
|
52329
|
+
if (path21.basename(desiredDir) !== type) {
|
|
52268
52330
|
return { dir: null, reason: `Requested writable provider directory must end with '${type}': ${desiredDir}` };
|
|
52269
52331
|
}
|
|
52270
52332
|
const sourceDir = ctx.findProviderDir(type);
|
|
52271
52333
|
if (!sourceDir) {
|
|
52272
52334
|
return { dir: null, reason: `Provider source directory not found for '${type}'` };
|
|
52273
52335
|
}
|
|
52274
|
-
if (!
|
|
52275
|
-
|
|
52276
|
-
|
|
52336
|
+
if (!fs14.existsSync(desiredDir)) {
|
|
52337
|
+
fs14.mkdirSync(path21.dirname(desiredDir), { recursive: true });
|
|
52338
|
+
fs14.cpSync(sourceDir, desiredDir, { recursive: true });
|
|
52277
52339
|
ctx.log(`Auto-implement writable copy created: ${desiredDir}`);
|
|
52278
52340
|
}
|
|
52279
|
-
const providerJson =
|
|
52280
|
-
if (!
|
|
52341
|
+
const providerJson = path21.join(desiredDir, "provider.json");
|
|
52342
|
+
if (!fs14.existsSync(providerJson)) {
|
|
52281
52343
|
return { dir: null, reason: `provider.json not found in writable provider directory: ${desiredDir}` };
|
|
52282
52344
|
}
|
|
52283
52345
|
return { dir: desiredDir };
|
|
@@ -52285,15 +52347,15 @@ async (params) => {
|
|
|
52285
52347
|
function loadAutoImplReferenceScripts(ctx, referenceType) {
|
|
52286
52348
|
if (!referenceType) return {};
|
|
52287
52349
|
const refDir = ctx.findProviderDir(referenceType);
|
|
52288
|
-
if (!refDir || !
|
|
52350
|
+
if (!refDir || !fs14.existsSync(refDir)) return {};
|
|
52289
52351
|
const referenceScripts = {};
|
|
52290
|
-
const scriptsDir =
|
|
52352
|
+
const scriptsDir = path21.join(refDir, "scripts");
|
|
52291
52353
|
const latestDir = getLatestScriptVersionDir(scriptsDir);
|
|
52292
52354
|
if (!latestDir) return referenceScripts;
|
|
52293
|
-
for (const file2 of
|
|
52355
|
+
for (const file2 of fs14.readdirSync(latestDir)) {
|
|
52294
52356
|
if (!file2.endsWith(".js")) continue;
|
|
52295
52357
|
try {
|
|
52296
|
-
referenceScripts[file2] =
|
|
52358
|
+
referenceScripts[file2] = fs14.readFileSync(path21.join(latestDir, file2), "utf-8");
|
|
52297
52359
|
} catch {
|
|
52298
52360
|
}
|
|
52299
52361
|
}
|
|
@@ -52401,16 +52463,16 @@ async (params) => {
|
|
|
52401
52463
|
});
|
|
52402
52464
|
const referenceScripts = loadAutoImplReferenceScripts(ctx, resolvedReference);
|
|
52403
52465
|
const prompt = buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domContext, referenceScripts, comment, resolvedReference, verification);
|
|
52404
|
-
const tmpDir =
|
|
52405
|
-
if (!
|
|
52406
|
-
const promptFile =
|
|
52407
|
-
|
|
52466
|
+
const tmpDir = path21.join(os20.tmpdir(), "adhdev-autoimpl");
|
|
52467
|
+
if (!fs14.existsSync(tmpDir)) fs14.mkdirSync(tmpDir, { recursive: true });
|
|
52468
|
+
const promptFile = path21.join(tmpDir, `prompt-${type}-${Date.now()}.md`);
|
|
52469
|
+
fs14.writeFileSync(promptFile, prompt, "utf-8");
|
|
52408
52470
|
ctx.log(`Auto-implement prompt written to ${promptFile} (${prompt.length} chars)`);
|
|
52409
52471
|
const agentProvider = ctx.providerLoader.resolve(agent) || ctx.providerLoader.getMeta(agent);
|
|
52410
52472
|
const spawn4 = agentProvider?.spawn;
|
|
52411
52473
|
if (!spawn4?.command) {
|
|
52412
52474
|
try {
|
|
52413
|
-
|
|
52475
|
+
fs14.unlinkSync(promptFile);
|
|
52414
52476
|
} catch {
|
|
52415
52477
|
}
|
|
52416
52478
|
ctx.json(res, 400, { error: `Agent '${agent}' has no spawn config. Select a CLI provider with a spawn configuration.` });
|
|
@@ -52512,7 +52574,7 @@ async (params) => {
|
|
|
52512
52574
|
} catch {
|
|
52513
52575
|
}
|
|
52514
52576
|
try {
|
|
52515
|
-
|
|
52577
|
+
fs14.unlinkSync(promptFile);
|
|
52516
52578
|
} catch {
|
|
52517
52579
|
}
|
|
52518
52580
|
ctx.log(`Auto-implement (ACP) ${success2 ? "completed" : "failed"}: ${type} (exit: ${code})`);
|
|
@@ -52556,7 +52618,7 @@ async (params) => {
|
|
|
52556
52618
|
const interactiveFlags = ["--yolo", "--interactive", "-i"];
|
|
52557
52619
|
const baseArgs = [...spawn4.args || []].filter((a) => !interactiveFlags.includes(a));
|
|
52558
52620
|
let shellCmd;
|
|
52559
|
-
const isWin =
|
|
52621
|
+
const isWin = os20.platform() === "win32";
|
|
52560
52622
|
const escapeArg = (a) => isWin ? `"${a.replace(/"/g, '""')}"` : `'${a.replace(/'/g, "'\\''")}'`;
|
|
52561
52623
|
const promptMode = autoImpl?.promptMode ?? "stdin";
|
|
52562
52624
|
const extraArgs = autoImpl?.extraArgs ?? [];
|
|
@@ -52595,7 +52657,7 @@ async (params) => {
|
|
|
52595
52657
|
try {
|
|
52596
52658
|
const pty = require("node-pty");
|
|
52597
52659
|
ctx.log(`Auto-implement spawn (PTY): ${shellCmd}`);
|
|
52598
|
-
const isWin2 =
|
|
52660
|
+
const isWin2 = os20.platform() === "win32";
|
|
52599
52661
|
child = pty.spawn(isWin2 ? "cmd.exe" : process.env.SHELL || "/bin/zsh", [isWin2 ? "/c" : "-c", shellCmd], {
|
|
52600
52662
|
name: "xterm-256color",
|
|
52601
52663
|
cols: 120,
|
|
@@ -52738,7 +52800,7 @@ async (params) => {
|
|
|
52738
52800
|
}
|
|
52739
52801
|
});
|
|
52740
52802
|
try {
|
|
52741
|
-
|
|
52803
|
+
fs14.unlinkSync(promptFile);
|
|
52742
52804
|
} catch {
|
|
52743
52805
|
}
|
|
52744
52806
|
ctx.log(`Auto-implement ${success2 ? "completed" : "failed"}: ${type} (exit: ${code})${verificationSummary ? ` verify=${verificationSummary.pass ? "pass" : "fail"}` : ""}`);
|
|
@@ -52835,7 +52897,7 @@ async (params) => {
|
|
|
52835
52897
|
setMode: "set_mode.js"
|
|
52836
52898
|
};
|
|
52837
52899
|
const targetFileNames = new Set(functions.map((fn2) => funcToFile[fn2]).filter(Boolean));
|
|
52838
|
-
const scriptsDir =
|
|
52900
|
+
const scriptsDir = path21.join(providerDir, "scripts");
|
|
52839
52901
|
const latestScriptsDir = getLatestScriptVersionDir(scriptsDir);
|
|
52840
52902
|
if (latestScriptsDir) {
|
|
52841
52903
|
lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
|
|
@@ -52843,10 +52905,10 @@ async (params) => {
|
|
|
52843
52905
|
lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
|
|
52844
52906
|
lines.push("These are the ONLY files you are allowed to modify. Replace the TODO stubs with working implementations.");
|
|
52845
52907
|
lines.push("");
|
|
52846
|
-
for (const file2 of
|
|
52908
|
+
for (const file2 of fs14.readdirSync(latestScriptsDir)) {
|
|
52847
52909
|
if (file2.endsWith(".js") && targetFileNames.has(file2)) {
|
|
52848
52910
|
try {
|
|
52849
|
-
const content =
|
|
52911
|
+
const content = fs14.readFileSync(path21.join(latestScriptsDir, file2), "utf-8");
|
|
52850
52912
|
lines.push(`### \`${file2}\` \u270F\uFE0F EDIT`);
|
|
52851
52913
|
lines.push("```javascript");
|
|
52852
52914
|
lines.push(content);
|
|
@@ -52856,14 +52918,14 @@ async (params) => {
|
|
|
52856
52918
|
}
|
|
52857
52919
|
}
|
|
52858
52920
|
}
|
|
52859
|
-
const refFiles =
|
|
52921
|
+
const refFiles = fs14.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
|
|
52860
52922
|
if (refFiles.length > 0) {
|
|
52861
52923
|
lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
|
|
52862
52924
|
lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
|
|
52863
52925
|
lines.push("");
|
|
52864
52926
|
for (const file2 of refFiles) {
|
|
52865
52927
|
try {
|
|
52866
|
-
const content =
|
|
52928
|
+
const content = fs14.readFileSync(path21.join(latestScriptsDir, file2), "utf-8");
|
|
52867
52929
|
lines.push(`### \`${file2}\` \u{1F512}`);
|
|
52868
52930
|
lines.push("```javascript");
|
|
52869
52931
|
lines.push(content);
|
|
@@ -52904,11 +52966,11 @@ async (params) => {
|
|
|
52904
52966
|
lines.push("");
|
|
52905
52967
|
}
|
|
52906
52968
|
}
|
|
52907
|
-
const docsDir =
|
|
52969
|
+
const docsDir = path21.join(providerDir, "../../docs");
|
|
52908
52970
|
const loadGuide = (name) => {
|
|
52909
52971
|
try {
|
|
52910
|
-
const p =
|
|
52911
|
-
if (
|
|
52972
|
+
const p = path21.join(docsDir, name);
|
|
52973
|
+
if (fs14.existsSync(p)) return fs14.readFileSync(p, "utf-8");
|
|
52912
52974
|
} catch {
|
|
52913
52975
|
}
|
|
52914
52976
|
return null;
|
|
@@ -53144,7 +53206,7 @@ async (params) => {
|
|
|
53144
53206
|
parseApproval: "parse_approval.js"
|
|
53145
53207
|
};
|
|
53146
53208
|
const targetFileNames = new Set(functions.map((fn2) => funcToFile[fn2]).filter(Boolean));
|
|
53147
|
-
const scriptsDir =
|
|
53209
|
+
const scriptsDir = path21.join(providerDir, "scripts");
|
|
53148
53210
|
const latestScriptsDir = getLatestScriptVersionDir(scriptsDir);
|
|
53149
53211
|
if (latestScriptsDir) {
|
|
53150
53212
|
lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
|
|
@@ -53152,11 +53214,11 @@ async (params) => {
|
|
|
53152
53214
|
lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
|
|
53153
53215
|
lines.push("These are the ONLY files you are allowed to modify. Replace TODO or heuristic-only logic with working PTY-aware implementations.");
|
|
53154
53216
|
lines.push("");
|
|
53155
|
-
for (const file2 of
|
|
53217
|
+
for (const file2 of fs14.readdirSync(latestScriptsDir)) {
|
|
53156
53218
|
if (!file2.endsWith(".js")) continue;
|
|
53157
53219
|
if (!targetFileNames.has(file2)) continue;
|
|
53158
53220
|
try {
|
|
53159
|
-
const content =
|
|
53221
|
+
const content = fs14.readFileSync(path21.join(latestScriptsDir, file2), "utf-8");
|
|
53160
53222
|
lines.push(`### \`${file2}\` \u270F\uFE0F EDIT`);
|
|
53161
53223
|
lines.push("```javascript");
|
|
53162
53224
|
lines.push(content);
|
|
@@ -53165,14 +53227,14 @@ async (params) => {
|
|
|
53165
53227
|
} catch {
|
|
53166
53228
|
}
|
|
53167
53229
|
}
|
|
53168
|
-
const refFiles =
|
|
53230
|
+
const refFiles = fs14.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
|
|
53169
53231
|
if (refFiles.length > 0) {
|
|
53170
53232
|
lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
|
|
53171
53233
|
lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
|
|
53172
53234
|
lines.push("");
|
|
53173
53235
|
for (const file2 of refFiles) {
|
|
53174
53236
|
try {
|
|
53175
|
-
const content =
|
|
53237
|
+
const content = fs14.readFileSync(path21.join(latestScriptsDir, file2), "utf-8");
|
|
53176
53238
|
lines.push(`### \`${file2}\` \u{1F512}`);
|
|
53177
53239
|
lines.push("```javascript");
|
|
53178
53240
|
lines.push(content);
|
|
@@ -53205,11 +53267,11 @@ async (params) => {
|
|
|
53205
53267
|
lines.push("");
|
|
53206
53268
|
}
|
|
53207
53269
|
}
|
|
53208
|
-
const docsDir =
|
|
53270
|
+
const docsDir = path21.join(providerDir, "../../docs");
|
|
53209
53271
|
const loadGuide = (name) => {
|
|
53210
53272
|
try {
|
|
53211
|
-
const p =
|
|
53212
|
-
if (
|
|
53273
|
+
const p = path21.join(docsDir, name);
|
|
53274
|
+
if (fs14.existsSync(p)) return fs14.readFileSync(p, "utf-8");
|
|
53213
53275
|
} catch {
|
|
53214
53276
|
}
|
|
53215
53277
|
return null;
|
|
@@ -53653,8 +53715,8 @@ data: ${JSON.stringify(msg.data)}
|
|
|
53653
53715
|
}
|
|
53654
53716
|
getEndpointList() {
|
|
53655
53717
|
return this.routes.map((r) => {
|
|
53656
|
-
const
|
|
53657
|
-
return `${r.method.padEnd(5)} ${
|
|
53718
|
+
const path232 = typeof r.pattern === "string" ? r.pattern : r.pattern.source.replace(/\\\//g, "/").replace(/\(\[.*?\]\+\)/g, ":type").replace(/[\^$]/g, "");
|
|
53719
|
+
return `${r.method.padEnd(5)} ${path232}`;
|
|
53658
53720
|
});
|
|
53659
53721
|
}
|
|
53660
53722
|
async start(port = DEV_SERVER_PORT) {
|
|
@@ -53942,12 +54004,12 @@ data: ${JSON.stringify(msg.data)}
|
|
|
53942
54004
|
// ─── DevConsole SPA ───
|
|
53943
54005
|
getConsoleDistDir() {
|
|
53944
54006
|
const candidates = [
|
|
53945
|
-
|
|
53946
|
-
|
|
53947
|
-
|
|
54007
|
+
path222.resolve(__dirname, "../../web-devconsole/dist"),
|
|
54008
|
+
path222.resolve(__dirname, "../../../web-devconsole/dist"),
|
|
54009
|
+
path222.join(process.cwd(), "packages/web-devconsole/dist")
|
|
53948
54010
|
];
|
|
53949
54011
|
for (const dir of candidates) {
|
|
53950
|
-
if (
|
|
54012
|
+
if (fs15.existsSync(path222.join(dir, "index.html"))) return dir;
|
|
53951
54013
|
}
|
|
53952
54014
|
return null;
|
|
53953
54015
|
}
|
|
@@ -53957,9 +54019,9 @@ data: ${JSON.stringify(msg.data)}
|
|
|
53957
54019
|
this.json(res, 500, { error: "DevConsole not found. Run: npm run build -w packages/web-devconsole" });
|
|
53958
54020
|
return;
|
|
53959
54021
|
}
|
|
53960
|
-
const htmlPath =
|
|
54022
|
+
const htmlPath = path222.join(distDir, "index.html");
|
|
53961
54023
|
try {
|
|
53962
|
-
const html =
|
|
54024
|
+
const html = fs15.readFileSync(htmlPath, "utf-8");
|
|
53963
54025
|
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
53964
54026
|
res.end(html);
|
|
53965
54027
|
} catch (e) {
|
|
@@ -53982,15 +54044,15 @@ data: ${JSON.stringify(msg.data)}
|
|
|
53982
54044
|
this.json(res, 404, { error: "Not found" });
|
|
53983
54045
|
return;
|
|
53984
54046
|
}
|
|
53985
|
-
const safePath =
|
|
53986
|
-
const filePath =
|
|
54047
|
+
const safePath = path222.normalize(pathname).replace(/^\.\.\//, "");
|
|
54048
|
+
const filePath = path222.join(distDir, safePath);
|
|
53987
54049
|
if (!filePath.startsWith(distDir)) {
|
|
53988
54050
|
this.json(res, 403, { error: "Forbidden" });
|
|
53989
54051
|
return;
|
|
53990
54052
|
}
|
|
53991
54053
|
try {
|
|
53992
|
-
const content =
|
|
53993
|
-
const ext =
|
|
54054
|
+
const content = fs15.readFileSync(filePath);
|
|
54055
|
+
const ext = path222.extname(filePath);
|
|
53994
54056
|
const contentType = _DevServer.MIME_MAP[ext] || "application/octet-stream";
|
|
53995
54057
|
res.writeHead(200, { "Content-Type": contentType, "Cache-Control": "public, max-age=31536000, immutable" });
|
|
53996
54058
|
res.end(content);
|
|
@@ -54098,14 +54160,14 @@ data: ${JSON.stringify(msg.data)}
|
|
|
54098
54160
|
const files = [];
|
|
54099
54161
|
const scan = (d, prefix) => {
|
|
54100
54162
|
try {
|
|
54101
|
-
for (const entry of
|
|
54163
|
+
for (const entry of fs15.readdirSync(d, { withFileTypes: true })) {
|
|
54102
54164
|
if (entry.name.startsWith(".") || entry.name.endsWith(".bak")) continue;
|
|
54103
54165
|
const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
54104
54166
|
if (entry.isDirectory()) {
|
|
54105
54167
|
files.push({ path: rel, size: 0, type: "dir" });
|
|
54106
|
-
scan(
|
|
54168
|
+
scan(path222.join(d, entry.name), rel);
|
|
54107
54169
|
} else {
|
|
54108
|
-
const stat4 =
|
|
54170
|
+
const stat4 = fs15.statSync(path222.join(d, entry.name));
|
|
54109
54171
|
files.push({ path: rel, size: stat4.size, type: "file" });
|
|
54110
54172
|
}
|
|
54111
54173
|
}
|
|
@@ -54128,16 +54190,16 @@ data: ${JSON.stringify(msg.data)}
|
|
|
54128
54190
|
this.json(res, 404, { error: `Provider directory not found: ${type}` });
|
|
54129
54191
|
return;
|
|
54130
54192
|
}
|
|
54131
|
-
const fullPath =
|
|
54193
|
+
const fullPath = path222.resolve(dir, path222.normalize(filePath));
|
|
54132
54194
|
if (!fullPath.startsWith(dir)) {
|
|
54133
54195
|
this.json(res, 403, { error: "Forbidden" });
|
|
54134
54196
|
return;
|
|
54135
54197
|
}
|
|
54136
|
-
if (!
|
|
54198
|
+
if (!fs15.existsSync(fullPath) || fs15.statSync(fullPath).isDirectory()) {
|
|
54137
54199
|
this.json(res, 404, { error: `File not found: ${filePath}` });
|
|
54138
54200
|
return;
|
|
54139
54201
|
}
|
|
54140
|
-
const content =
|
|
54202
|
+
const content = fs15.readFileSync(fullPath, "utf-8");
|
|
54141
54203
|
this.json(res, 200, { type, path: filePath, content, lines: content.split("\n").length });
|
|
54142
54204
|
}
|
|
54143
54205
|
/** POST /api/providers/:type/file — write a file { path, content } */
|
|
@@ -54153,15 +54215,15 @@ data: ${JSON.stringify(msg.data)}
|
|
|
54153
54215
|
this.json(res, 404, { error: `Provider directory not found: ${type}` });
|
|
54154
54216
|
return;
|
|
54155
54217
|
}
|
|
54156
|
-
const fullPath =
|
|
54218
|
+
const fullPath = path222.resolve(dir, path222.normalize(filePath));
|
|
54157
54219
|
if (!fullPath.startsWith(dir)) {
|
|
54158
54220
|
this.json(res, 403, { error: "Forbidden" });
|
|
54159
54221
|
return;
|
|
54160
54222
|
}
|
|
54161
54223
|
try {
|
|
54162
|
-
if (
|
|
54163
|
-
|
|
54164
|
-
|
|
54224
|
+
if (fs15.existsSync(fullPath)) fs15.copyFileSync(fullPath, fullPath + ".bak");
|
|
54225
|
+
fs15.mkdirSync(path222.dirname(fullPath), { recursive: true });
|
|
54226
|
+
fs15.writeFileSync(fullPath, content, "utf-8");
|
|
54165
54227
|
this.log(`File saved: ${fullPath} (${content.length} chars)`);
|
|
54166
54228
|
this.providerLoader.reload();
|
|
54167
54229
|
this.json(res, 200, { saved: true, path: filePath, chars: content.length });
|
|
@@ -54177,9 +54239,9 @@ data: ${JSON.stringify(msg.data)}
|
|
|
54177
54239
|
return;
|
|
54178
54240
|
}
|
|
54179
54241
|
for (const name of ["scripts.js", "provider.json"]) {
|
|
54180
|
-
const p =
|
|
54181
|
-
if (
|
|
54182
|
-
const source =
|
|
54242
|
+
const p = path222.join(dir, name);
|
|
54243
|
+
if (fs15.existsSync(p)) {
|
|
54244
|
+
const source = fs15.readFileSync(p, "utf-8");
|
|
54183
54245
|
this.json(res, 200, { type, path: p, source, lines: source.split("\n").length });
|
|
54184
54246
|
return;
|
|
54185
54247
|
}
|
|
@@ -54198,11 +54260,11 @@ data: ${JSON.stringify(msg.data)}
|
|
|
54198
54260
|
this.json(res, 404, { error: `Provider not found: ${type}` });
|
|
54199
54261
|
return;
|
|
54200
54262
|
}
|
|
54201
|
-
const target =
|
|
54202
|
-
const targetPath =
|
|
54263
|
+
const target = fs15.existsSync(path222.join(dir, "scripts.js")) ? "scripts.js" : "provider.json";
|
|
54264
|
+
const targetPath = path222.join(dir, target);
|
|
54203
54265
|
try {
|
|
54204
|
-
if (
|
|
54205
|
-
|
|
54266
|
+
if (fs15.existsSync(targetPath)) fs15.copyFileSync(targetPath, targetPath + ".bak");
|
|
54267
|
+
fs15.writeFileSync(targetPath, source, "utf-8");
|
|
54206
54268
|
this.log(`Saved provider: ${targetPath} (${source.length} chars)`);
|
|
54207
54269
|
this.providerLoader.reload();
|
|
54208
54270
|
this.json(res, 200, { saved: true, path: targetPath, chars: source.length });
|
|
@@ -54346,21 +54408,21 @@ data: ${JSON.stringify(msg.data)}
|
|
|
54346
54408
|
}
|
|
54347
54409
|
let targetDir;
|
|
54348
54410
|
targetDir = this.providerLoader.getUserProviderDir(category, type);
|
|
54349
|
-
const jsonPath =
|
|
54350
|
-
if (
|
|
54411
|
+
const jsonPath = path222.join(targetDir, "provider.json");
|
|
54412
|
+
if (fs15.existsSync(jsonPath)) {
|
|
54351
54413
|
this.json(res, 409, { error: `Provider already exists at ${targetDir}`, path: targetDir });
|
|
54352
54414
|
return;
|
|
54353
54415
|
}
|
|
54354
54416
|
try {
|
|
54355
54417
|
const result = generateFiles(type, name, category, { cdpPorts, cli, processName, installPath, binary, extensionId, version: version2, osPaths, processNames });
|
|
54356
|
-
|
|
54357
|
-
|
|
54418
|
+
fs15.mkdirSync(targetDir, { recursive: true });
|
|
54419
|
+
fs15.writeFileSync(jsonPath, result["provider.json"], "utf-8");
|
|
54358
54420
|
const createdFiles = ["provider.json"];
|
|
54359
54421
|
if (result.files) {
|
|
54360
54422
|
for (const [relPath, content] of Object.entries(result.files)) {
|
|
54361
|
-
const fullPath =
|
|
54362
|
-
|
|
54363
|
-
|
|
54423
|
+
const fullPath = path222.join(targetDir, relPath);
|
|
54424
|
+
fs15.mkdirSync(path222.dirname(fullPath), { recursive: true });
|
|
54425
|
+
fs15.writeFileSync(fullPath, content, "utf-8");
|
|
54364
54426
|
createdFiles.push(relPath);
|
|
54365
54427
|
}
|
|
54366
54428
|
}
|
|
@@ -54409,38 +54471,38 @@ data: ${JSON.stringify(msg.data)}
|
|
|
54409
54471
|
}
|
|
54410
54472
|
// ─── Phase 2: Auto-Implement Backend ───
|
|
54411
54473
|
getLatestScriptVersionDir(scriptsDir) {
|
|
54412
|
-
if (!
|
|
54413
|
-
const versions =
|
|
54474
|
+
if (!fs15.existsSync(scriptsDir)) return null;
|
|
54475
|
+
const versions = fs15.readdirSync(scriptsDir).filter((d) => {
|
|
54414
54476
|
try {
|
|
54415
|
-
return
|
|
54477
|
+
return fs15.statSync(path222.join(scriptsDir, d)).isDirectory();
|
|
54416
54478
|
} catch {
|
|
54417
54479
|
return false;
|
|
54418
54480
|
}
|
|
54419
54481
|
}).sort((a, b2) => b2.localeCompare(a, void 0, { numeric: true, sensitivity: "base" }));
|
|
54420
54482
|
if (versions.length === 0) return null;
|
|
54421
|
-
return
|
|
54483
|
+
return path222.join(scriptsDir, versions[0]);
|
|
54422
54484
|
}
|
|
54423
54485
|
resolveAutoImplWritableProviderDir(category, type, requestedDir) {
|
|
54424
|
-
const canonicalUserDir =
|
|
54425
|
-
const desiredDir = requestedDir ?
|
|
54426
|
-
const upstreamRoot =
|
|
54427
|
-
if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${
|
|
54486
|
+
const canonicalUserDir = path222.resolve(this.providerLoader.getUserProviderDir(category, type));
|
|
54487
|
+
const desiredDir = requestedDir ? path222.resolve(requestedDir) : canonicalUserDir;
|
|
54488
|
+
const upstreamRoot = path222.resolve(this.providerLoader.getUpstreamDir());
|
|
54489
|
+
if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${path222.sep}`)) {
|
|
54428
54490
|
return { dir: null, reason: `Refusing to write into upstream provider directory: ${desiredDir}` };
|
|
54429
54491
|
}
|
|
54430
|
-
if (
|
|
54492
|
+
if (path222.basename(desiredDir) !== type) {
|
|
54431
54493
|
return { dir: null, reason: `Requested writable provider directory must end with '${type}': ${desiredDir}` };
|
|
54432
54494
|
}
|
|
54433
54495
|
const sourceDir = this.findProviderDir(type);
|
|
54434
54496
|
if (!sourceDir) {
|
|
54435
54497
|
return { dir: null, reason: `Provider source directory not found for '${type}'` };
|
|
54436
54498
|
}
|
|
54437
|
-
if (!
|
|
54438
|
-
|
|
54439
|
-
|
|
54499
|
+
if (!fs15.existsSync(desiredDir)) {
|
|
54500
|
+
fs15.mkdirSync(path222.dirname(desiredDir), { recursive: true });
|
|
54501
|
+
fs15.cpSync(sourceDir, desiredDir, { recursive: true });
|
|
54440
54502
|
this.log(`Auto-implement writable copy created: ${desiredDir}`);
|
|
54441
54503
|
}
|
|
54442
|
-
const providerJson =
|
|
54443
|
-
if (!
|
|
54504
|
+
const providerJson = path222.join(desiredDir, "provider.json");
|
|
54505
|
+
if (!fs15.existsSync(providerJson)) {
|
|
54444
54506
|
return { dir: null, reason: `provider.json not found in writable provider directory: ${desiredDir}` };
|
|
54445
54507
|
}
|
|
54446
54508
|
return { dir: desiredDir };
|
|
@@ -54475,7 +54537,7 @@ data: ${JSON.stringify(msg.data)}
|
|
|
54475
54537
|
setMode: "set_mode.js"
|
|
54476
54538
|
};
|
|
54477
54539
|
const targetFileNames = new Set(functions.map((fn2) => funcToFile[fn2]).filter(Boolean));
|
|
54478
|
-
const scriptsDir =
|
|
54540
|
+
const scriptsDir = path222.join(providerDir, "scripts");
|
|
54479
54541
|
const latestScriptsDir = this.getLatestScriptVersionDir(scriptsDir);
|
|
54480
54542
|
if (latestScriptsDir) {
|
|
54481
54543
|
lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
|
|
@@ -54483,10 +54545,10 @@ data: ${JSON.stringify(msg.data)}
|
|
|
54483
54545
|
lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
|
|
54484
54546
|
lines.push("These are the ONLY files you are allowed to modify. Replace the TODO stubs with working implementations.");
|
|
54485
54547
|
lines.push("");
|
|
54486
|
-
for (const file2 of
|
|
54548
|
+
for (const file2 of fs15.readdirSync(latestScriptsDir)) {
|
|
54487
54549
|
if (file2.endsWith(".js") && targetFileNames.has(file2)) {
|
|
54488
54550
|
try {
|
|
54489
|
-
const content =
|
|
54551
|
+
const content = fs15.readFileSync(path222.join(latestScriptsDir, file2), "utf-8");
|
|
54490
54552
|
lines.push(`### \`${file2}\` \u270F\uFE0F EDIT`);
|
|
54491
54553
|
lines.push("```javascript");
|
|
54492
54554
|
lines.push(content);
|
|
@@ -54496,14 +54558,14 @@ data: ${JSON.stringify(msg.data)}
|
|
|
54496
54558
|
}
|
|
54497
54559
|
}
|
|
54498
54560
|
}
|
|
54499
|
-
const refFiles =
|
|
54561
|
+
const refFiles = fs15.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
|
|
54500
54562
|
if (refFiles.length > 0) {
|
|
54501
54563
|
lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
|
|
54502
54564
|
lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
|
|
54503
54565
|
lines.push("");
|
|
54504
54566
|
for (const file2 of refFiles) {
|
|
54505
54567
|
try {
|
|
54506
|
-
const content =
|
|
54568
|
+
const content = fs15.readFileSync(path222.join(latestScriptsDir, file2), "utf-8");
|
|
54507
54569
|
lines.push(`### \`${file2}\` \u{1F512}`);
|
|
54508
54570
|
lines.push("```javascript");
|
|
54509
54571
|
lines.push(content);
|
|
@@ -54544,11 +54606,11 @@ data: ${JSON.stringify(msg.data)}
|
|
|
54544
54606
|
lines.push("");
|
|
54545
54607
|
}
|
|
54546
54608
|
}
|
|
54547
|
-
const docsDir =
|
|
54609
|
+
const docsDir = path222.join(providerDir, "../../docs");
|
|
54548
54610
|
const loadGuide = (name) => {
|
|
54549
54611
|
try {
|
|
54550
|
-
const p =
|
|
54551
|
-
if (
|
|
54612
|
+
const p = path222.join(docsDir, name);
|
|
54613
|
+
if (fs15.existsSync(p)) return fs15.readFileSync(p, "utf-8");
|
|
54552
54614
|
} catch {
|
|
54553
54615
|
}
|
|
54554
54616
|
return null;
|
|
@@ -54721,7 +54783,7 @@ data: ${JSON.stringify(msg.data)}
|
|
|
54721
54783
|
parseApproval: "parse_approval.js"
|
|
54722
54784
|
};
|
|
54723
54785
|
const targetFileNames = new Set(functions.map((fn2) => funcToFile[fn2]).filter(Boolean));
|
|
54724
|
-
const scriptsDir =
|
|
54786
|
+
const scriptsDir = path222.join(providerDir, "scripts");
|
|
54725
54787
|
const latestScriptsDir = this.getLatestScriptVersionDir(scriptsDir);
|
|
54726
54788
|
if (latestScriptsDir) {
|
|
54727
54789
|
lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
|
|
@@ -54729,11 +54791,11 @@ data: ${JSON.stringify(msg.data)}
|
|
|
54729
54791
|
lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
|
|
54730
54792
|
lines.push("These are the ONLY files you are allowed to modify. Replace TODO or heuristic-only logic with working PTY-aware implementations.");
|
|
54731
54793
|
lines.push("");
|
|
54732
|
-
for (const file2 of
|
|
54794
|
+
for (const file2 of fs15.readdirSync(latestScriptsDir)) {
|
|
54733
54795
|
if (!file2.endsWith(".js")) continue;
|
|
54734
54796
|
if (!targetFileNames.has(file2)) continue;
|
|
54735
54797
|
try {
|
|
54736
|
-
const content =
|
|
54798
|
+
const content = fs15.readFileSync(path222.join(latestScriptsDir, file2), "utf-8");
|
|
54737
54799
|
lines.push(`### \`${file2}\` \u270F\uFE0F EDIT`);
|
|
54738
54800
|
lines.push("```javascript");
|
|
54739
54801
|
lines.push(content);
|
|
@@ -54742,14 +54804,14 @@ data: ${JSON.stringify(msg.data)}
|
|
|
54742
54804
|
} catch {
|
|
54743
54805
|
}
|
|
54744
54806
|
}
|
|
54745
|
-
const refFiles =
|
|
54807
|
+
const refFiles = fs15.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
|
|
54746
54808
|
if (refFiles.length > 0) {
|
|
54747
54809
|
lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
|
|
54748
54810
|
lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
|
|
54749
54811
|
lines.push("");
|
|
54750
54812
|
for (const file2 of refFiles) {
|
|
54751
54813
|
try {
|
|
54752
|
-
const content =
|
|
54814
|
+
const content = fs15.readFileSync(path222.join(latestScriptsDir, file2), "utf-8");
|
|
54753
54815
|
lines.push(`### \`${file2}\` \u{1F512}`);
|
|
54754
54816
|
lines.push("```javascript");
|
|
54755
54817
|
lines.push(content);
|
|
@@ -54782,11 +54844,11 @@ data: ${JSON.stringify(msg.data)}
|
|
|
54782
54844
|
lines.push("");
|
|
54783
54845
|
}
|
|
54784
54846
|
}
|
|
54785
|
-
const docsDir =
|
|
54847
|
+
const docsDir = path222.join(providerDir, "../../docs");
|
|
54786
54848
|
const loadGuide = (name) => {
|
|
54787
54849
|
try {
|
|
54788
|
-
const p =
|
|
54789
|
-
if (
|
|
54850
|
+
const p = path222.join(docsDir, name);
|
|
54851
|
+
if (fs15.existsSync(p)) return fs15.readFileSync(p, "utf-8");
|
|
54790
54852
|
} catch {
|
|
54791
54853
|
}
|
|
54792
54854
|
return null;
|
|
@@ -55649,8 +55711,8 @@ data: ${JSON.stringify(msg.data)}
|
|
|
55649
55711
|
const res = await fetch(extension.vsixUrl);
|
|
55650
55712
|
if (res.ok) {
|
|
55651
55713
|
const buffer = Buffer.from(await res.arrayBuffer());
|
|
55652
|
-
const
|
|
55653
|
-
|
|
55714
|
+
const fs16 = await import("fs");
|
|
55715
|
+
fs16.writeFileSync(vsixPath, buffer);
|
|
55654
55716
|
return new Promise((resolve12) => {
|
|
55655
55717
|
const cmd = `"${ide.cliCommand}" --install-extension "${vsixPath}" --force`;
|
|
55656
55718
|
(0, import_child_process11.exec)(cmd, { timeout: 6e4 }, (error48, _stdout, stderr) => {
|