adhdev 0.8.12 → 0.8.13
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/cli/index.js +558 -329
- package/dist/cli/index.js.map +1 -1
- package/dist/index.js +502 -320
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/vendor/session-host-daemon/index.js +38 -62
- package/vendor/session-host-daemon/index.js.map +1 -1
- package/vendor/session-host-daemon/index.mjs +25 -49
- package/vendor/session-host-daemon/index.mjs.map +1 -1
- package/vendor/session-host-daemon/node_modules/@adhdev/session-host-core/index.d.mts +30 -1
- package/vendor/session-host-daemon/node_modules/@adhdev/session-host-core/index.d.ts +30 -1
- package/vendor/session-host-daemon/node_modules/@adhdev/session-host-core/index.js +73 -6
- package/vendor/session-host-daemon/node_modules/@adhdev/session-host-core/index.js.map +1 -1
- package/vendor/session-host-daemon/node_modules/@adhdev/session-host-core/index.mjs +77 -6
- package/vendor/session-host-daemon/node_modules/@adhdev/session-host-core/index.mjs.map +1 -1
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
|
9
9
|
var __esm = (fn, res) => function __init() {
|
|
10
10
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
11
11
|
};
|
|
12
|
-
var __commonJS = (cb, mod) => function
|
|
12
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
13
13
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
14
14
|
};
|
|
15
15
|
var __export = (target, all) => {
|
|
@@ -572,18 +572,18 @@ function checkPathExists(paths) {
|
|
|
572
572
|
return null;
|
|
573
573
|
}
|
|
574
574
|
async function detectIDEs() {
|
|
575
|
-
const
|
|
575
|
+
const os23 = (0, import_os2.platform)();
|
|
576
576
|
const results = [];
|
|
577
577
|
for (const def of getMergedDefinitions()) {
|
|
578
578
|
const cliPath = findCliCommand(def.cli);
|
|
579
|
-
const appPath = checkPathExists(def.paths[
|
|
579
|
+
const appPath = checkPathExists(def.paths[os23] || []);
|
|
580
580
|
const installed = !!(cliPath || appPath);
|
|
581
581
|
let resolvedCli = cliPath;
|
|
582
|
-
if (!resolvedCli && appPath &&
|
|
582
|
+
if (!resolvedCli && appPath && os23 === "darwin") {
|
|
583
583
|
const bundledCli = `${appPath}/Contents/Resources/app/bin/${def.cli}`;
|
|
584
584
|
if ((0, import_fs2.existsSync)(bundledCli)) resolvedCli = bundledCli;
|
|
585
585
|
}
|
|
586
|
-
if (!resolvedCli && appPath &&
|
|
586
|
+
if (!resolvedCli && appPath && os23 === "win32") {
|
|
587
587
|
const { dirname: dirname9 } = await import("path");
|
|
588
588
|
const appDir = dirname9(appPath);
|
|
589
589
|
const candidates = [
|
|
@@ -644,8 +644,8 @@ function execAsync(cmd, timeoutMs = 5e3) {
|
|
|
644
644
|
});
|
|
645
645
|
}
|
|
646
646
|
async function detectCLIs(providerLoader) {
|
|
647
|
-
const
|
|
648
|
-
const whichCmd =
|
|
647
|
+
const platform11 = os2.platform();
|
|
648
|
+
const whichCmd = platform11 === "win32" ? "where" : "which";
|
|
649
649
|
const cliList = providerLoader ? providerLoader.getCliDetectionList() : [];
|
|
650
650
|
const results = await Promise.all(
|
|
651
651
|
cliList.map(async (cli) => {
|
|
@@ -680,6 +680,39 @@ async function detectCLIs(providerLoader) {
|
|
|
680
680
|
}
|
|
681
681
|
async function detectCLI(cliId, providerLoader) {
|
|
682
682
|
const resolvedId = providerLoader ? providerLoader.resolveAlias(cliId) : cliId;
|
|
683
|
+
if (providerLoader) {
|
|
684
|
+
const cliList = providerLoader.getCliDetectionList();
|
|
685
|
+
const target = cliList.find((c) => c.id === resolvedId);
|
|
686
|
+
if (target) {
|
|
687
|
+
const platform11 = os2.platform();
|
|
688
|
+
const whichCmd = platform11 === "win32" ? "where" : "which";
|
|
689
|
+
try {
|
|
690
|
+
const pathResult = await execAsync(`${whichCmd} ${target.command}`);
|
|
691
|
+
if (!pathResult) return null;
|
|
692
|
+
const firstPath = pathResult.split("\n")[0];
|
|
693
|
+
let version2;
|
|
694
|
+
try {
|
|
695
|
+
const versionCommands = [
|
|
696
|
+
target.versionCommand,
|
|
697
|
+
`${target.command} --version`,
|
|
698
|
+
`${target.command} -V`,
|
|
699
|
+
`${target.command} -v`
|
|
700
|
+
].filter((v) => !!v);
|
|
701
|
+
for (const versionCommand of versionCommands) {
|
|
702
|
+
const versionResult = await execAsync(versionCommand, 3e3);
|
|
703
|
+
if (versionResult) {
|
|
704
|
+
version2 = parseVersion(versionResult);
|
|
705
|
+
break;
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
} catch {
|
|
709
|
+
}
|
|
710
|
+
return { ...target, installed: true, version: version2, path: firstPath };
|
|
711
|
+
} catch {
|
|
712
|
+
return null;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
}
|
|
683
716
|
const all = await detectCLIs(providerLoader);
|
|
684
717
|
return all.find((c) => c.id === resolvedId && c.installed) || null;
|
|
685
718
|
}
|
|
@@ -6196,6 +6229,13 @@ function logTerminalBackendSelection(preference, ghosttyAvailable, backendKind)
|
|
|
6196
6229
|
const key = `${preference}:${ghosttyAvailable}:${backendKind}`;
|
|
6197
6230
|
if (loggedTerminalBackends.has(key)) return;
|
|
6198
6231
|
loggedTerminalBackends.add(key);
|
|
6232
|
+
if (backendKind === "xterm" && preference !== "xterm" && !ghosttyAvailable) {
|
|
6233
|
+
LOG.warn(
|
|
6234
|
+
"Terminal",
|
|
6235
|
+
`[terminal-screen] ghostty-vt unavailable; using xterm fallback (preference=${preference})`
|
|
6236
|
+
);
|
|
6237
|
+
return;
|
|
6238
|
+
}
|
|
6199
6239
|
LOG.info(
|
|
6200
6240
|
"Terminal",
|
|
6201
6241
|
`[terminal-screen] backend=${backendKind} preference=${preference} ghosttyAvailable=${ghosttyAvailable}`
|
|
@@ -6258,10 +6298,11 @@ var init_terminal_screen = __esm({
|
|
|
6258
6298
|
});
|
|
6259
6299
|
|
|
6260
6300
|
// ../../oss/packages/daemon-core/src/cli-adapters/pty-transport.ts
|
|
6261
|
-
var pty, NodePtyRuntimeTransport, NodePtyTransportFactory;
|
|
6301
|
+
var os7, pty, NodePtyRuntimeTransport, NodePtyTransportFactory;
|
|
6262
6302
|
var init_pty_transport = __esm({
|
|
6263
6303
|
"../../oss/packages/daemon-core/src/cli-adapters/pty-transport.ts"() {
|
|
6264
6304
|
"use strict";
|
|
6305
|
+
os7 = __toESM(require("os"));
|
|
6265
6306
|
try {
|
|
6266
6307
|
pty = require("node-pty");
|
|
6267
6308
|
} catch {
|
|
@@ -6298,11 +6339,21 @@ var init_pty_transport = __esm({
|
|
|
6298
6339
|
NodePtyTransportFactory = class {
|
|
6299
6340
|
spawn(command, args, options) {
|
|
6300
6341
|
if (!pty) throw new Error("node-pty is not installed");
|
|
6342
|
+
let cwd = options.cwd;
|
|
6343
|
+
if (cwd) {
|
|
6344
|
+
try {
|
|
6345
|
+
const fs18 = require("fs");
|
|
6346
|
+
const stat4 = fs18.statSync(cwd);
|
|
6347
|
+
if (!stat4.isDirectory()) cwd = os7.homedir();
|
|
6348
|
+
} catch {
|
|
6349
|
+
cwd = os7.homedir();
|
|
6350
|
+
}
|
|
6351
|
+
}
|
|
6301
6352
|
const handle = pty.spawn(command, args, {
|
|
6302
6353
|
name: "xterm-256color",
|
|
6303
6354
|
cols: options.cols,
|
|
6304
6355
|
rows: options.rows,
|
|
6305
|
-
cwd
|
|
6356
|
+
cwd,
|
|
6306
6357
|
env: options.env
|
|
6307
6358
|
});
|
|
6308
6359
|
return new NodePtyRuntimeTransport(handle);
|
|
@@ -6311,33 +6362,39 @@ var init_pty_transport = __esm({
|
|
|
6311
6362
|
}
|
|
6312
6363
|
});
|
|
6313
6364
|
|
|
6314
|
-
// ../../oss/packages/
|
|
6315
|
-
|
|
6316
|
-
__export(provider_cli_adapter_exports, {
|
|
6317
|
-
ProviderCliAdapter: () => ProviderCliAdapter,
|
|
6318
|
-
normalizeCliProviderForRuntime: () => normalizeCliProviderForRuntime
|
|
6319
|
-
});
|
|
6320
|
-
function stripAnsi(str) {
|
|
6321
|
-
return str.replace(/\x1B\][^\x07]*\x07/g, "").replace(/\x1B\][\s\S]*?\x1B\\/g, "").replace(/\x1B[P^_X][\s\S]*?(?:\x07|\x1B\\)/g, "").replace(/\x1B\[\d*[A-HJKSTfG]/g, " ").replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g, "").replace(/ +/g, " ");
|
|
6322
|
-
}
|
|
6323
|
-
function stripTerminalNoise(str) {
|
|
6324
|
-
return String(str || "").replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x9F]/g, "").replace(/(^|[\s([])(?:\??\d{1,4}(?:;\d{1,4})*[A-Za-z])(?=$|[\s)\]])/g, "$1").replace(/(^|[\s([])(?:\[\??\d{1,4}(?:;\d{1,4})*[A-Za-z])(?=$|[\s)\]])/g, "$1").replace(/(^|[\s([])(?:\d{1,4};\?)(?=$|[\s)\]])/g, "$1").replace(/(^|[\s([])(?:\d+\$r[0-9;\" ]*[A-Za-z]?)(?=$|[\s)\]])/g, "$1").replace(/(^|[\s([])(?:>\|[A-Za-z0-9_.:-]+(?:\([^)]*\))?)(?=$|[\s)\]])/g, "$1").replace(/(^|[\s([])(?:[A-Z]\d(?:\s+[A-Z]\d)+)(?=$|[\s)\]])/g, "$1").replace(/(^|[\s([])(?:\d+;[^\s)\]]+)(?=$|[\s)\]])/g, "$1").replace(/\r+/g, "\n").replace(/[ \t]+\n/g, "\n").replace(/\n{3,}/g, "\n\n").replace(/ {2,}/g, " ");
|
|
6325
|
-
}
|
|
6326
|
-
function sanitizeTerminalText(str) {
|
|
6327
|
-
return stripTerminalNoise(stripAnsi(str));
|
|
6328
|
-
}
|
|
6329
|
-
function applyPreferredTerminalColorEnv(env) {
|
|
6330
|
-
if (env.NO_COLOR) return;
|
|
6331
|
-
if (!env.TERM || env.TERM === "xterm-color") {
|
|
6332
|
-
env.TERM = "xterm-256color";
|
|
6333
|
-
}
|
|
6334
|
-
if (!env.COLORTERM) env.COLORTERM = "truecolor";
|
|
6365
|
+
// ../../oss/packages/session-host-core/dist/index.mjs
|
|
6366
|
+
function getDefaultSessionHostEndpoint(appName = "adhdev") {
|
|
6335
6367
|
if (process.platform === "win32") {
|
|
6336
|
-
|
|
6337
|
-
|
|
6368
|
+
return {
|
|
6369
|
+
kind: "pipe",
|
|
6370
|
+
path: `\\\\.\\pipe\\${appName}-session-host`
|
|
6371
|
+
};
|
|
6338
6372
|
}
|
|
6373
|
+
return {
|
|
6374
|
+
kind: "unix",
|
|
6375
|
+
path: path22.join(os8.tmpdir(), `${appName}-session-host.sock`)
|
|
6376
|
+
};
|
|
6377
|
+
}
|
|
6378
|
+
function serializeEnvelope(envelope) {
|
|
6379
|
+
return `${JSON.stringify(envelope)}
|
|
6380
|
+
`;
|
|
6339
6381
|
}
|
|
6340
|
-
function
|
|
6382
|
+
function createLineParser(onEnvelope) {
|
|
6383
|
+
let buffer = "";
|
|
6384
|
+
return (chunk) => {
|
|
6385
|
+
buffer += chunk.toString();
|
|
6386
|
+
let newlineIndex = buffer.indexOf("\n");
|
|
6387
|
+
while (newlineIndex >= 0) {
|
|
6388
|
+
const rawLine = buffer.slice(0, newlineIndex).trim();
|
|
6389
|
+
buffer = buffer.slice(newlineIndex + 1);
|
|
6390
|
+
if (rawLine) {
|
|
6391
|
+
onEnvelope(JSON.parse(rawLine));
|
|
6392
|
+
}
|
|
6393
|
+
newlineIndex = buffer.indexOf("\n");
|
|
6394
|
+
}
|
|
6395
|
+
};
|
|
6396
|
+
}
|
|
6397
|
+
function sanitizeSpawnEnv(baseEnv, overrides) {
|
|
6341
6398
|
const env = {};
|
|
6342
6399
|
const source = { ...baseEnv, ...overrides || {} };
|
|
6343
6400
|
for (const [key, value] of Object.entries(source)) {
|
|
@@ -6349,9 +6406,185 @@ function buildCliSpawnEnv(baseEnv, overrides) {
|
|
|
6349
6406
|
delete env[key];
|
|
6350
6407
|
}
|
|
6351
6408
|
}
|
|
6352
|
-
|
|
6409
|
+
applyTerminalColorEnv(env);
|
|
6353
6410
|
return env;
|
|
6354
6411
|
}
|
|
6412
|
+
function applyTerminalColorEnv(env) {
|
|
6413
|
+
if (env.NO_COLOR) return;
|
|
6414
|
+
if (!env.TERM || env.TERM === "xterm-color") {
|
|
6415
|
+
env.TERM = "xterm-256color";
|
|
6416
|
+
}
|
|
6417
|
+
if (!env.COLORTERM) env.COLORTERM = "truecolor";
|
|
6418
|
+
if (process.platform === "win32") {
|
|
6419
|
+
if (!env.FORCE_COLOR) env.FORCE_COLOR = "1";
|
|
6420
|
+
if (!env.CLICOLOR) env.CLICOLOR = "1";
|
|
6421
|
+
}
|
|
6422
|
+
}
|
|
6423
|
+
function ensureNodePtySpawnHelperPermissions(logFn) {
|
|
6424
|
+
if (os22.platform() === "win32") return;
|
|
6425
|
+
try {
|
|
6426
|
+
const fs18 = __require("fs");
|
|
6427
|
+
const ptyDir = path32.resolve(path32.dirname(__require.resolve("node-pty")), "..");
|
|
6428
|
+
const platformArch = `${os22.platform()}-${os22.arch()}`;
|
|
6429
|
+
const helper = path32.join(ptyDir, "prebuilds", platformArch, "spawn-helper");
|
|
6430
|
+
if (fs18.existsSync(helper)) {
|
|
6431
|
+
const stat4 = fs18.statSync(helper);
|
|
6432
|
+
if (!(stat4.mode & 73)) {
|
|
6433
|
+
fs18.chmodSync(helper, stat4.mode | 493);
|
|
6434
|
+
logFn?.(`Fixed spawn-helper permissions: ${helper}`);
|
|
6435
|
+
}
|
|
6436
|
+
}
|
|
6437
|
+
} catch {
|
|
6438
|
+
}
|
|
6439
|
+
}
|
|
6440
|
+
var os8, path22, net, import_crypto3, os22, path32, __require, SessionHostClient;
|
|
6441
|
+
var init_dist = __esm({
|
|
6442
|
+
"../../oss/packages/session-host-core/dist/index.mjs"() {
|
|
6443
|
+
"use strict";
|
|
6444
|
+
os8 = __toESM(require("os"), 1);
|
|
6445
|
+
path22 = __toESM(require("path"), 1);
|
|
6446
|
+
net = __toESM(require("net"), 1);
|
|
6447
|
+
import_crypto3 = require("crypto");
|
|
6448
|
+
os22 = __toESM(require("os"), 1);
|
|
6449
|
+
path32 = __toESM(require("path"), 1);
|
|
6450
|
+
__require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
6451
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
6452
|
+
}) : x)(function(x) {
|
|
6453
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
6454
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6455
|
+
});
|
|
6456
|
+
SessionHostClient = class {
|
|
6457
|
+
endpoint;
|
|
6458
|
+
socket = null;
|
|
6459
|
+
requestWaiters = /* @__PURE__ */ new Map();
|
|
6460
|
+
eventListeners = /* @__PURE__ */ new Set();
|
|
6461
|
+
constructor(options = {}) {
|
|
6462
|
+
this.endpoint = options.endpoint || getDefaultSessionHostEndpoint(options.appName || "adhdev");
|
|
6463
|
+
}
|
|
6464
|
+
async connect() {
|
|
6465
|
+
if (this.socket && !this.socket.destroyed) return;
|
|
6466
|
+
if (this.socket) {
|
|
6467
|
+
try {
|
|
6468
|
+
this.socket.destroy();
|
|
6469
|
+
} catch {
|
|
6470
|
+
}
|
|
6471
|
+
this.socket = null;
|
|
6472
|
+
}
|
|
6473
|
+
const socket = net.createConnection(this.endpoint.path);
|
|
6474
|
+
this.socket = socket;
|
|
6475
|
+
socket.on("data", createLineParser((envelope) => {
|
|
6476
|
+
if (envelope.kind === "response") {
|
|
6477
|
+
const waiter = this.requestWaiters.get(envelope.requestId);
|
|
6478
|
+
if (waiter) {
|
|
6479
|
+
this.requestWaiters.delete(envelope.requestId);
|
|
6480
|
+
waiter.resolve(envelope.response);
|
|
6481
|
+
}
|
|
6482
|
+
return;
|
|
6483
|
+
}
|
|
6484
|
+
if (envelope.kind === "event") {
|
|
6485
|
+
for (const listener of this.eventListeners) listener(envelope.event);
|
|
6486
|
+
}
|
|
6487
|
+
}));
|
|
6488
|
+
socket.on("error", (error48) => {
|
|
6489
|
+
for (const waiter of this.requestWaiters.values()) {
|
|
6490
|
+
waiter.reject(error48);
|
|
6491
|
+
}
|
|
6492
|
+
this.requestWaiters.clear();
|
|
6493
|
+
if (this.socket === socket) {
|
|
6494
|
+
this.socket = null;
|
|
6495
|
+
}
|
|
6496
|
+
try {
|
|
6497
|
+
socket.destroy();
|
|
6498
|
+
} catch {
|
|
6499
|
+
}
|
|
6500
|
+
});
|
|
6501
|
+
await new Promise((resolve22, reject) => {
|
|
6502
|
+
socket.once("connect", () => resolve22());
|
|
6503
|
+
socket.once("error", reject);
|
|
6504
|
+
});
|
|
6505
|
+
}
|
|
6506
|
+
onEvent(listener) {
|
|
6507
|
+
this.eventListeners.add(listener);
|
|
6508
|
+
return () => {
|
|
6509
|
+
this.eventListeners.delete(listener);
|
|
6510
|
+
};
|
|
6511
|
+
}
|
|
6512
|
+
async request(request) {
|
|
6513
|
+
await this.connect();
|
|
6514
|
+
if (!this.socket) throw new Error("Session host socket unavailable");
|
|
6515
|
+
const requestId = (0, import_crypto3.randomUUID)();
|
|
6516
|
+
const envelope = {
|
|
6517
|
+
kind: "request",
|
|
6518
|
+
requestId,
|
|
6519
|
+
request
|
|
6520
|
+
};
|
|
6521
|
+
const response = await new Promise((resolve22, reject) => {
|
|
6522
|
+
const timeout = setTimeout(() => {
|
|
6523
|
+
this.requestWaiters.delete(requestId);
|
|
6524
|
+
reject(new Error(`Session host request timed out after 30s (${request.type})`));
|
|
6525
|
+
}, 3e4);
|
|
6526
|
+
this.requestWaiters.set(requestId, {
|
|
6527
|
+
resolve: (value) => {
|
|
6528
|
+
clearTimeout(timeout);
|
|
6529
|
+
resolve22(value);
|
|
6530
|
+
},
|
|
6531
|
+
reject: (error48) => {
|
|
6532
|
+
clearTimeout(timeout);
|
|
6533
|
+
reject(error48);
|
|
6534
|
+
}
|
|
6535
|
+
});
|
|
6536
|
+
this.socket?.write(serializeEnvelope(envelope));
|
|
6537
|
+
});
|
|
6538
|
+
return response;
|
|
6539
|
+
}
|
|
6540
|
+
async close() {
|
|
6541
|
+
if (!this.socket) return;
|
|
6542
|
+
const socket = this.socket;
|
|
6543
|
+
this.socket = null;
|
|
6544
|
+
for (const waiter of this.requestWaiters.values()) {
|
|
6545
|
+
waiter.reject(new Error("Session host client closed"));
|
|
6546
|
+
}
|
|
6547
|
+
this.requestWaiters.clear();
|
|
6548
|
+
await new Promise((resolve22) => {
|
|
6549
|
+
let settled = false;
|
|
6550
|
+
const done = () => {
|
|
6551
|
+
if (settled) return;
|
|
6552
|
+
settled = true;
|
|
6553
|
+
resolve22();
|
|
6554
|
+
};
|
|
6555
|
+
socket.once("close", done);
|
|
6556
|
+
socket.end();
|
|
6557
|
+
socket.destroy();
|
|
6558
|
+
setTimeout(done, 50);
|
|
6559
|
+
});
|
|
6560
|
+
}
|
|
6561
|
+
};
|
|
6562
|
+
}
|
|
6563
|
+
});
|
|
6564
|
+
|
|
6565
|
+
// ../../oss/packages/daemon-core/src/cli-adapters/spawn-env.ts
|
|
6566
|
+
var init_spawn_env = __esm({
|
|
6567
|
+
"../../oss/packages/daemon-core/src/cli-adapters/spawn-env.ts"() {
|
|
6568
|
+
"use strict";
|
|
6569
|
+
init_dist();
|
|
6570
|
+
}
|
|
6571
|
+
});
|
|
6572
|
+
|
|
6573
|
+
// ../../oss/packages/daemon-core/src/cli-adapters/provider-cli-adapter.ts
|
|
6574
|
+
var provider_cli_adapter_exports = {};
|
|
6575
|
+
__export(provider_cli_adapter_exports, {
|
|
6576
|
+
ProviderCliAdapter: () => ProviderCliAdapter,
|
|
6577
|
+
normalizeCliProviderForRuntime: () => normalizeCliProviderForRuntime
|
|
6578
|
+
});
|
|
6579
|
+
function stripAnsi(str) {
|
|
6580
|
+
return str.replace(/\x1B\][^\x07]*\x07/g, "").replace(/\x1B\][\s\S]*?\x1B\\/g, "").replace(/\x1B[P^_X][\s\S]*?(?:\x07|\x1B\\)/g, "").replace(/\x1B\[\d*[A-HJKSTfG]/g, " ").replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g, "").replace(/ +/g, " ");
|
|
6581
|
+
}
|
|
6582
|
+
function stripTerminalNoise(str) {
|
|
6583
|
+
return String(str || "").replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x9F]/g, "").replace(/(^|[\s([])(?:\??\d{1,4}(?:;\d{1,4})*[A-Za-z])(?=$|[\s)\]])/g, "$1").replace(/(^|[\s([])(?:\[\??\d{1,4}(?:;\d{1,4})*[A-Za-z])(?=$|[\s)\]])/g, "$1").replace(/(^|[\s([])(?:\d{1,4};\?)(?=$|[\s)\]])/g, "$1").replace(/(^|[\s([])(?:\d+\$r[0-9;\" ]*[A-Za-z]?)(?=$|[\s)\]])/g, "$1").replace(/(^|[\s([])(?:>\|[A-Za-z0-9_.:-]+(?:\([^)]*\))?)(?=$|[\s)\]])/g, "$1").replace(/(^|[\s([])(?:[A-Z]\d(?:\s+[A-Z]\d)+)(?=$|[\s)\]])/g, "$1").replace(/(^|[\s([])(?:\d+;[^\s)\]]+)(?=$|[\s)\]])/g, "$1").replace(/\r+/g, "\n").replace(/[ \t]+\n/g, "\n").replace(/\n{3,}/g, "\n\n").replace(/ {2,}/g, " ");
|
|
6584
|
+
}
|
|
6585
|
+
function sanitizeTerminalText(str) {
|
|
6586
|
+
return stripTerminalNoise(stripAnsi(str));
|
|
6587
|
+
}
|
|
6355
6588
|
function computeTerminalQueryTail(buffer) {
|
|
6356
6589
|
const prefixes = ["\x1B[6n", "\x1B[?6n"];
|
|
6357
6590
|
const maxLength = prefixes.reduce((n, value) => Math.max(n, value.length), 0) - 1;
|
|
@@ -6365,7 +6598,7 @@ function computeTerminalQueryTail(buffer) {
|
|
|
6365
6598
|
return "";
|
|
6366
6599
|
}
|
|
6367
6600
|
function findBinary(name) {
|
|
6368
|
-
const isWin =
|
|
6601
|
+
const isWin = os9.platform() === "win32";
|
|
6369
6602
|
try {
|
|
6370
6603
|
const cmd = isWin ? `where ${name}` : `which ${name}`;
|
|
6371
6604
|
return (0, import_child_process4.execSync)(cmd, { encoding: "utf-8", timeout: 5e3, stdio: ["pipe", "pipe", "pipe"] }).trim().split("\n")[0].trim();
|
|
@@ -6413,7 +6646,7 @@ function looksLikeMachOOrElf(filePath) {
|
|
|
6413
6646
|
}
|
|
6414
6647
|
function shSingleQuote(arg) {
|
|
6415
6648
|
if (/^[a-zA-Z0-9@%_+=:,./-]+$/.test(arg)) return arg;
|
|
6416
|
-
if (
|
|
6649
|
+
if (os9.platform() === "win32") {
|
|
6417
6650
|
return `"${arg.replace(/"/g, '""')}"`;
|
|
6418
6651
|
}
|
|
6419
6652
|
return `'${arg.replace(/'/g, `'\\''`)}'`;
|
|
@@ -6480,37 +6713,24 @@ function normalizeCliProviderForRuntime(raw) {
|
|
|
6480
6713
|
}
|
|
6481
6714
|
};
|
|
6482
6715
|
}
|
|
6483
|
-
var
|
|
6716
|
+
var os9, path7, import_child_process4, pty2, buildCliSpawnEnv, ProviderCliAdapter;
|
|
6484
6717
|
var init_provider_cli_adapter = __esm({
|
|
6485
6718
|
"../../oss/packages/daemon-core/src/cli-adapters/provider-cli-adapter.ts"() {
|
|
6486
6719
|
"use strict";
|
|
6487
|
-
|
|
6720
|
+
os9 = __toESM(require("os"));
|
|
6488
6721
|
path7 = __toESM(require("path"));
|
|
6489
6722
|
import_child_process4 = require("child_process");
|
|
6490
6723
|
init_logger();
|
|
6491
6724
|
init_terminal_screen();
|
|
6492
6725
|
init_pty_transport();
|
|
6726
|
+
init_spawn_env();
|
|
6493
6727
|
try {
|
|
6494
6728
|
pty2 = require("node-pty");
|
|
6495
|
-
|
|
6496
|
-
try {
|
|
6497
|
-
const fs18 = require("fs");
|
|
6498
|
-
const ptyDir = path7.resolve(path7.dirname(require.resolve("node-pty")), "..");
|
|
6499
|
-
const platformArch = `${os7.platform()}-${os7.arch()}`;
|
|
6500
|
-
const helper = path7.join(ptyDir, "prebuilds", platformArch, "spawn-helper");
|
|
6501
|
-
if (fs18.existsSync(helper)) {
|
|
6502
|
-
const stat4 = fs18.statSync(helper);
|
|
6503
|
-
if (!(stat4.mode & 73)) {
|
|
6504
|
-
fs18.chmodSync(helper, stat4.mode | 493);
|
|
6505
|
-
LOG.info("CLI", "[node-pty] Fixed spawn-helper permissions");
|
|
6506
|
-
}
|
|
6507
|
-
}
|
|
6508
|
-
} catch {
|
|
6509
|
-
}
|
|
6510
|
-
}
|
|
6729
|
+
ensureNodePtySpawnHelperPermissions((msg) => LOG.info("CLI", msg));
|
|
6511
6730
|
} catch {
|
|
6512
6731
|
LOG.error("CLI", "[ProviderCliAdapter] node-pty not found. Terminal features disabled.");
|
|
6513
6732
|
}
|
|
6733
|
+
buildCliSpawnEnv = sanitizeSpawnEnv;
|
|
6514
6734
|
ProviderCliAdapter = class _ProviderCliAdapter {
|
|
6515
6735
|
constructor(provider, workingDir, extraArgs = [], transportFactory = new NodePtyTransportFactory()) {
|
|
6516
6736
|
this.extraArgs = extraArgs;
|
|
@@ -6518,7 +6738,7 @@ var init_provider_cli_adapter = __esm({
|
|
|
6518
6738
|
this.transportFactory = transportFactory;
|
|
6519
6739
|
this.cliType = provider.type;
|
|
6520
6740
|
this.cliName = provider.name;
|
|
6521
|
-
this.workingDir = workingDir.startsWith("~") ? workingDir.replace(/^~/,
|
|
6741
|
+
this.workingDir = workingDir.startsWith("~") ? workingDir.replace(/^~/, os9.homedir()) : workingDir;
|
|
6522
6742
|
const t = provider.timeouts || {};
|
|
6523
6743
|
this.timeouts = {
|
|
6524
6744
|
ptyFlush: t.ptyFlush ?? 50,
|
|
@@ -6825,7 +7045,7 @@ var init_provider_cli_adapter = __esm({
|
|
|
6825
7045
|
if (this.ptyProcess) return;
|
|
6826
7046
|
const { spawn: spawnConfig } = this.provider;
|
|
6827
7047
|
const binaryPath = findBinary(spawnConfig.command);
|
|
6828
|
-
const isWin =
|
|
7048
|
+
const isWin = os9.platform() === "win32";
|
|
6829
7049
|
const allArgs = [...spawnConfig.args, ...this.extraArgs];
|
|
6830
7050
|
LOG.info("CLI", `[${this.cliType}] Spawning in ${this.workingDir}`);
|
|
6831
7051
|
this.resetTraceSession();
|
|
@@ -6877,6 +7097,12 @@ var init_provider_cli_adapter = __esm({
|
|
|
6877
7097
|
shellArgs = ["-l", "-c", fullCmd];
|
|
6878
7098
|
this.ptyProcess = this.transportFactory.spawn(shellCmd, shellArgs, ptyOpts);
|
|
6879
7099
|
} else {
|
|
7100
|
+
if (isWin) {
|
|
7101
|
+
const hint = /error code 267|ERROR_DIRECTORY/i.test(msg) ? " (working directory does not exist or is not a directory)" : /error code 740|elevation/i.test(msg) ? " (requires administrator privileges)" : /error code 2|ENOENT|not found/i.test(msg) ? ` (executable not found: ${shellCmd})` : "";
|
|
7102
|
+
if (hint) {
|
|
7103
|
+
throw new Error(`Failed to spawn CLI${hint}: ${msg}`);
|
|
7104
|
+
}
|
|
7105
|
+
}
|
|
6880
7106
|
throw err;
|
|
6881
7107
|
}
|
|
6882
7108
|
}
|
|
@@ -7629,7 +7855,8 @@ ${data.message || ""}`.trim();
|
|
|
7629
7855
|
const payload = stopCommand.endsWith("\r") || stopCommand.endsWith("\n") ? stopCommand : `${stopCommand}${this.sendKey}`;
|
|
7630
7856
|
this.ptyProcess.write(payload);
|
|
7631
7857
|
};
|
|
7632
|
-
|
|
7858
|
+
const interruptGraceMs = typeof resume.interruptGraceMs === "number" ? Math.max(100, resume.interruptGraceMs) : 500;
|
|
7859
|
+
if (wasProcessing) setTimeout(writeCommand, interruptGraceMs);
|
|
7633
7860
|
else writeCommand();
|
|
7634
7861
|
} else {
|
|
7635
7862
|
this.ptyProcess.write("");
|
|
@@ -7674,6 +7901,18 @@ ${data.message || ""}`.trim();
|
|
|
7674
7901
|
clearTimeout(this.submitRetryTimer);
|
|
7675
7902
|
this.submitRetryTimer = null;
|
|
7676
7903
|
}
|
|
7904
|
+
if (this.responseTimeout) {
|
|
7905
|
+
clearTimeout(this.responseTimeout);
|
|
7906
|
+
this.responseTimeout = null;
|
|
7907
|
+
}
|
|
7908
|
+
if (this.idleTimeout) {
|
|
7909
|
+
clearTimeout(this.idleTimeout);
|
|
7910
|
+
this.idleTimeout = null;
|
|
7911
|
+
}
|
|
7912
|
+
if (this.pendingScriptStatusTimer) {
|
|
7913
|
+
clearTimeout(this.pendingScriptStatusTimer);
|
|
7914
|
+
this.pendingScriptStatusTimer = null;
|
|
7915
|
+
}
|
|
7677
7916
|
if (this.pendingOutputParseTimer) {
|
|
7678
7917
|
clearTimeout(this.pendingOutputParseTimer);
|
|
7679
7918
|
this.pendingOutputParseTimer = null;
|
|
@@ -7715,6 +7954,18 @@ ${data.message || ""}`.trim();
|
|
|
7715
7954
|
clearTimeout(this.submitRetryTimer);
|
|
7716
7955
|
this.submitRetryTimer = null;
|
|
7717
7956
|
}
|
|
7957
|
+
if (this.responseTimeout) {
|
|
7958
|
+
clearTimeout(this.responseTimeout);
|
|
7959
|
+
this.responseTimeout = null;
|
|
7960
|
+
}
|
|
7961
|
+
if (this.idleTimeout) {
|
|
7962
|
+
clearTimeout(this.idleTimeout);
|
|
7963
|
+
this.idleTimeout = null;
|
|
7964
|
+
}
|
|
7965
|
+
if (this.pendingScriptStatusTimer) {
|
|
7966
|
+
clearTimeout(this.pendingScriptStatusTimer);
|
|
7967
|
+
this.pendingScriptStatusTimer = null;
|
|
7968
|
+
}
|
|
7718
7969
|
if (this.pendingOutputParseTimer) {
|
|
7719
7970
|
clearTimeout(this.pendingOutputParseTimer);
|
|
7720
7971
|
this.pendingOutputParseTimer = null;
|
|
@@ -7909,11 +8160,11 @@ function getDatabaseSync() {
|
|
|
7909
8160
|
}
|
|
7910
8161
|
return CachedDatabaseSync;
|
|
7911
8162
|
}
|
|
7912
|
-
var
|
|
8163
|
+
var os10, path8, crypto3, fs5, import_node_module, CachedDatabaseSync, CliProviderInstance;
|
|
7913
8164
|
var init_cli_provider_instance = __esm({
|
|
7914
8165
|
"../../oss/packages/daemon-core/src/providers/cli-provider-instance.ts"() {
|
|
7915
8166
|
"use strict";
|
|
7916
|
-
|
|
8167
|
+
os10 = __toESM(require("os"));
|
|
7917
8168
|
path8 = __toESM(require("path"));
|
|
7918
8169
|
crypto3 = __toESM(require("crypto"));
|
|
7919
8170
|
fs5 = __toESM(require("fs"));
|
|
@@ -7994,17 +8245,60 @@ var init_cli_provider_instance = __esm({
|
|
|
7994
8245
|
async onTick() {
|
|
7995
8246
|
if (this.providerSessionId) return;
|
|
7996
8247
|
let probedSessionId = null;
|
|
7997
|
-
|
|
7998
|
-
|
|
7999
|
-
|
|
8000
|
-
|
|
8001
|
-
|
|
8002
|
-
|
|
8248
|
+
const probeConfig = this.provider.sessionProbe;
|
|
8249
|
+
if (probeConfig) {
|
|
8250
|
+
probedSessionId = this.probeSessionIdFromConfig(probeConfig);
|
|
8251
|
+
} else {
|
|
8252
|
+
if (this.type === "opencode-cli") {
|
|
8253
|
+
probedSessionId = this.probeSessionIdFromConfig({
|
|
8254
|
+
dbPath: "~/.local/share/opencode/opencode.db",
|
|
8255
|
+
query: "select id from session where directory in ({dirs}) and time_created >= ? and time_archived is null order by time_updated desc limit 1",
|
|
8256
|
+
timestampFormat: "unix_ms"
|
|
8257
|
+
});
|
|
8258
|
+
} else if (this.type === "codex-cli") {
|
|
8259
|
+
probedSessionId = this.probeSessionIdFromConfig({
|
|
8260
|
+
dbPath: "~/.codex/state_5.sqlite",
|
|
8261
|
+
query: "select id from threads where cwd in ({dirs}) and created_at >= ? and archived = 0 order by created_at desc limit 1",
|
|
8262
|
+
timestampFormat: "unix_s"
|
|
8263
|
+
});
|
|
8264
|
+
} else if (this.type === "goose-cli") {
|
|
8265
|
+
probedSessionId = this.probeSessionIdFromConfig({
|
|
8266
|
+
dbPath: "~/.local/share/goose/sessions/sessions.db",
|
|
8267
|
+
query: "select id from sessions where working_dir in ({dirs}) and created_at >= ? order by updated_at desc limit 1",
|
|
8268
|
+
timestampFormat: "iso"
|
|
8269
|
+
});
|
|
8270
|
+
}
|
|
8003
8271
|
}
|
|
8004
8272
|
if (probedSessionId) {
|
|
8005
8273
|
this.promoteProviderSessionId(probedSessionId);
|
|
8006
8274
|
}
|
|
8007
8275
|
}
|
|
8276
|
+
/**
|
|
8277
|
+
* Generic session ID probe using declarative ProviderSessionProbe config.
|
|
8278
|
+
* Replaces the previously duplicated probeOpenCode/Codex/Goose functions.
|
|
8279
|
+
*/
|
|
8280
|
+
probeSessionIdFromConfig(probe) {
|
|
8281
|
+
const resolvedDbPath = probe.dbPath.replace(/^~/, os10.homedir());
|
|
8282
|
+
if (!fs5.existsSync(resolvedDbPath)) return null;
|
|
8283
|
+
const directories = this.getProbeDirectories();
|
|
8284
|
+
const minCreatedAt = Math.max(0, this.startedAt - 6e4);
|
|
8285
|
+
const tsFormat = probe.timestampFormat || "unix_ms";
|
|
8286
|
+
let timestampParam;
|
|
8287
|
+
if (tsFormat === "unix_s") {
|
|
8288
|
+
timestampParam = Math.floor(minCreatedAt / 1e3);
|
|
8289
|
+
} else if (tsFormat === "iso") {
|
|
8290
|
+
timestampParam = new Date(minCreatedAt).toISOString().slice(0, 19).replace("T", " ");
|
|
8291
|
+
} else {
|
|
8292
|
+
timestampParam = minCreatedAt;
|
|
8293
|
+
}
|
|
8294
|
+
const placeholders = this.buildSqlPlaceholderList(directories.length);
|
|
8295
|
+
const query = probe.query.replace("{dirs}", placeholders);
|
|
8296
|
+
try {
|
|
8297
|
+
return this.querySqliteText(resolvedDbPath, query, [...directories, timestampParam]);
|
|
8298
|
+
} catch {
|
|
8299
|
+
return null;
|
|
8300
|
+
}
|
|
8301
|
+
}
|
|
8008
8302
|
getState() {
|
|
8009
8303
|
const adapterStatus = this.adapter.getStatus();
|
|
8010
8304
|
const parsedStatus = this.adapter.getScriptParsedStatus?.() || null;
|
|
@@ -8302,34 +8596,6 @@ var init_cli_provider_instance = __esm({
|
|
|
8302
8596
|
});
|
|
8303
8597
|
LOG.info("CLI", `[${this.type}] discovered provider session id: ${nextSessionId}`);
|
|
8304
8598
|
}
|
|
8305
|
-
probeOpenCodeSessionId() {
|
|
8306
|
-
const dbPath = path8.join(os8.homedir(), ".local", "share", "opencode", "opencode.db");
|
|
8307
|
-
if (!fs5.existsSync(dbPath)) return null;
|
|
8308
|
-
const minCreatedAt = Math.max(0, this.startedAt - 6e4);
|
|
8309
|
-
const directories = this.getProbeDirectories();
|
|
8310
|
-
const query = `select id from session where directory in (${this.buildSqlPlaceholderList(directories.length)}) and time_created >= ? and time_archived is null order by time_updated desc limit 1;`;
|
|
8311
|
-
return this.querySqliteText(dbPath, query, [...directories, minCreatedAt]);
|
|
8312
|
-
}
|
|
8313
|
-
probeCodexSessionId() {
|
|
8314
|
-
const dbPath = path8.join(os8.homedir(), ".codex", "state_5.sqlite");
|
|
8315
|
-
if (!fs5.existsSync(dbPath)) return null;
|
|
8316
|
-
const minCreatedAt = Math.max(0, Math.floor((this.startedAt - 6e4) / 1e3));
|
|
8317
|
-
const directories = this.getProbeDirectories();
|
|
8318
|
-
const query = `select id from threads where cwd in (${this.buildSqlPlaceholderList(directories.length)}) and created_at >= ? and archived = 0 order by created_at desc limit 1;`;
|
|
8319
|
-
return this.querySqliteText(dbPath, query, [...directories, minCreatedAt]);
|
|
8320
|
-
}
|
|
8321
|
-
probeGooseSessionId() {
|
|
8322
|
-
const dbPath = path8.join(os8.homedir(), ".local", "share", "goose", "sessions", "sessions.db");
|
|
8323
|
-
if (!fs5.existsSync(dbPath)) return null;
|
|
8324
|
-
const minCreatedAtIso = new Date(Math.max(0, this.startedAt - 6e4)).toISOString().slice(0, 19).replace("T", " ");
|
|
8325
|
-
const directories = this.getProbeDirectories();
|
|
8326
|
-
const query = `select id from sessions where working_dir in (${this.buildSqlPlaceholderList(directories.length)}) and created_at >= ? order by updated_at desc limit 1;`;
|
|
8327
|
-
try {
|
|
8328
|
-
return this.querySqliteText(dbPath, query, [...directories, minCreatedAtIso]);
|
|
8329
|
-
} catch {
|
|
8330
|
-
return null;
|
|
8331
|
-
}
|
|
8332
|
-
}
|
|
8333
8599
|
getProbeDirectories() {
|
|
8334
8600
|
const dirs = /* @__PURE__ */ new Set();
|
|
8335
8601
|
const addDir = (value) => {
|
|
@@ -25688,11 +25954,11 @@ function resolveCliSessionBinding(provider, normalizedType, cliArgs, requestedRe
|
|
|
25688
25954
|
launchMode: "new"
|
|
25689
25955
|
};
|
|
25690
25956
|
}
|
|
25691
|
-
var
|
|
25957
|
+
var os11, path9, crypto4, import_chalk, chalkApi, DaemonCliManager;
|
|
25692
25958
|
var init_cli_manager = __esm({
|
|
25693
25959
|
"../../oss/packages/daemon-core/src/commands/cli-manager.ts"() {
|
|
25694
25960
|
"use strict";
|
|
25695
|
-
|
|
25961
|
+
os11 = __toESM(require("os"));
|
|
25696
25962
|
path9 = __toESM(require("path"));
|
|
25697
25963
|
crypto4 = __toESM(require("crypto"));
|
|
25698
25964
|
import_chalk = __toESM(require("chalk"));
|
|
@@ -25844,7 +26110,7 @@ var init_cli_manager = __esm({
|
|
|
25844
26110
|
async startSession(cliType, workingDir, cliArgs, initialModel, options) {
|
|
25845
26111
|
const trimmed = (workingDir || "").trim();
|
|
25846
26112
|
if (!trimmed) throw new Error("working directory required");
|
|
25847
|
-
const resolvedDir = trimmed.startsWith("~") ? trimmed.replace(/^~/,
|
|
26113
|
+
const resolvedDir = trimmed.startsWith("~") ? trimmed.replace(/^~/, os11.homedir()) : path9.resolve(trimmed);
|
|
25848
26114
|
const normalizedType = this.providerLoader.resolveAlias(cliType);
|
|
25849
26115
|
const provider = this.providerLoader.getByAlias(cliType);
|
|
25850
26116
|
const key = crypto4.randomUUID();
|
|
@@ -25928,7 +26194,19 @@ ${installInfo}`
|
|
|
25928
26194
|
return { runtimeSessionId: sessionId };
|
|
25929
26195
|
}
|
|
25930
26196
|
const cliInfo = await detectCLI(cliType, this.providerLoader);
|
|
25931
|
-
if (!cliInfo)
|
|
26197
|
+
if (!cliInfo) {
|
|
26198
|
+
const installHint = provider?.install || "";
|
|
26199
|
+
const displayName = provider?.displayName || provider?.name || cliType;
|
|
26200
|
+
const spawnCmd = provider?.spawn?.command || cliType;
|
|
26201
|
+
throw new Error(
|
|
26202
|
+
`${displayName} is not installed.
|
|
26203
|
+
Command '${spawnCmd}' not found on PATH.
|
|
26204
|
+
` + (installHint ? `
|
|
26205
|
+
${installHint}
|
|
26206
|
+
` : "") + `
|
|
26207
|
+
Run 'adhdev doctor' for detailed diagnostics.`
|
|
26208
|
+
);
|
|
26209
|
+
}
|
|
25932
26210
|
console.log(colorize("yellow", ` \u26A1 Starting CLI ${cliType} in ${resolvedDir}...`));
|
|
25933
26211
|
if (provider) {
|
|
25934
26212
|
console.log(colorize("cyan", ` \u{1F4E6} Using provider: ${provider.name} (${provider.type})`));
|
|
@@ -26244,8 +26522,9 @@ ${installInfo}`
|
|
|
26244
26522
|
const dir = rdir.path;
|
|
26245
26523
|
if (!cliType) throw new Error("cliType required");
|
|
26246
26524
|
const found = this.findAdapter(cliType, { instanceKey: args?.targetSessionId, dir });
|
|
26525
|
+
const prevCliArgs = found ? found.adapter.extraArgs : void 0;
|
|
26247
26526
|
if (found) await this.stopSession(found.key);
|
|
26248
|
-
await this.startSession(cliType, dir);
|
|
26527
|
+
await this.startSession(cliType, dir, args?.cliArgs || prevCliArgs, args?.initialModel);
|
|
26249
26528
|
return { success: true, restarted: true };
|
|
26250
26529
|
}
|
|
26251
26530
|
case "agent_command": {
|
|
@@ -28029,13 +28308,13 @@ var init_chokidar = __esm({
|
|
|
28029
28308
|
});
|
|
28030
28309
|
|
|
28031
28310
|
// ../../oss/packages/daemon-core/src/providers/provider-loader.ts
|
|
28032
|
-
var fs6, path10,
|
|
28311
|
+
var fs6, path10, os12, ProviderLoader;
|
|
28033
28312
|
var init_provider_loader = __esm({
|
|
28034
28313
|
"../../oss/packages/daemon-core/src/providers/provider-loader.ts"() {
|
|
28035
28314
|
"use strict";
|
|
28036
28315
|
fs6 = __toESM(require("fs"));
|
|
28037
28316
|
path10 = __toESM(require("path"));
|
|
28038
|
-
|
|
28317
|
+
os12 = __toESM(require("os"));
|
|
28039
28318
|
init_chokidar();
|
|
28040
28319
|
init_ide_detector();
|
|
28041
28320
|
init_logger();
|
|
@@ -28056,7 +28335,7 @@ var init_provider_loader = __esm({
|
|
|
28056
28335
|
static META_FILE = ".meta.json";
|
|
28057
28336
|
constructor(options) {
|
|
28058
28337
|
this.logFn = options?.logFn || LOG.forComponent("Provider").asLogFn();
|
|
28059
|
-
const defaultProvidersDir = path10.join(
|
|
28338
|
+
const defaultProvidersDir = path10.join(os12.homedir(), ".adhdev", "providers");
|
|
28060
28339
|
if (options?.userDir) {
|
|
28061
28340
|
this.userDir = options.userDir;
|
|
28062
28341
|
this.log(`Config 'providerDir' applied: ${this.userDir}`);
|
|
@@ -28656,8 +28935,8 @@ var init_provider_loader = __esm({
|
|
|
28656
28935
|
return { updated: false };
|
|
28657
28936
|
}
|
|
28658
28937
|
this.log("Downloading latest providers from GitHub...");
|
|
28659
|
-
const tmpTar = path10.join(
|
|
28660
|
-
const tmpExtract = path10.join(
|
|
28938
|
+
const tmpTar = path10.join(os12.tmpdir(), `adhdev-providers-${Date.now()}.tar.gz`);
|
|
28939
|
+
const tmpExtract = path10.join(os12.tmpdir(), `adhdev-providers-extract-${Date.now()}`);
|
|
28661
28940
|
await this.downloadFile(_ProviderLoader.GITHUB_TARBALL_URL, tmpTar);
|
|
28662
28941
|
fs6.mkdirSync(tmpExtract, { recursive: true });
|
|
28663
28942
|
execSync7(`tar -xzf "${tmpTar}" -C "${tmpExtract}"`, { timeout: 3e4 });
|
|
@@ -29091,7 +29370,7 @@ async function findFreePort(ports) {
|
|
|
29091
29370
|
}
|
|
29092
29371
|
function checkPortFree(port) {
|
|
29093
29372
|
return new Promise((resolve13) => {
|
|
29094
|
-
const server =
|
|
29373
|
+
const server = net2.createServer();
|
|
29095
29374
|
server.unref();
|
|
29096
29375
|
server.on("error", () => resolve13(false));
|
|
29097
29376
|
server.listen(port, "127.0.0.1", () => {
|
|
@@ -29123,7 +29402,7 @@ async function isCdpActive(port) {
|
|
|
29123
29402
|
});
|
|
29124
29403
|
}
|
|
29125
29404
|
async function killIdeProcess(ideId) {
|
|
29126
|
-
const plat =
|
|
29405
|
+
const plat = os13.platform();
|
|
29127
29406
|
const appName = getMacAppIdentifiers()[ideId];
|
|
29128
29407
|
const winProcesses = getWinProcessNames()[ideId];
|
|
29129
29408
|
try {
|
|
@@ -29182,7 +29461,7 @@ async function killIdeProcess(ideId) {
|
|
|
29182
29461
|
}
|
|
29183
29462
|
}
|
|
29184
29463
|
function isIdeRunning(ideId) {
|
|
29185
|
-
const plat =
|
|
29464
|
+
const plat = os13.platform();
|
|
29186
29465
|
try {
|
|
29187
29466
|
if (plat === "darwin") {
|
|
29188
29467
|
const appName = getMacAppIdentifiers()[ideId];
|
|
@@ -29218,7 +29497,7 @@ function isIdeRunning(ideId) {
|
|
|
29218
29497
|
}
|
|
29219
29498
|
}
|
|
29220
29499
|
function detectCurrentWorkspace(ideId) {
|
|
29221
|
-
const plat =
|
|
29500
|
+
const plat = os13.platform();
|
|
29222
29501
|
if (plat === "darwin") {
|
|
29223
29502
|
try {
|
|
29224
29503
|
const appName = getMacAppIdentifiers()[ideId];
|
|
@@ -29238,7 +29517,7 @@ function detectCurrentWorkspace(ideId) {
|
|
|
29238
29517
|
const appName = appNameMap[ideId];
|
|
29239
29518
|
if (appName) {
|
|
29240
29519
|
const storagePath = path11.join(
|
|
29241
|
-
process.env.APPDATA || path11.join(
|
|
29520
|
+
process.env.APPDATA || path11.join(os13.homedir(), "AppData", "Roaming"),
|
|
29242
29521
|
appName,
|
|
29243
29522
|
"storage.json"
|
|
29244
29523
|
);
|
|
@@ -29260,7 +29539,7 @@ function detectCurrentWorkspace(ideId) {
|
|
|
29260
29539
|
return void 0;
|
|
29261
29540
|
}
|
|
29262
29541
|
async function launchWithCdp(options = {}) {
|
|
29263
|
-
const
|
|
29542
|
+
const platform11 = os13.platform();
|
|
29264
29543
|
let targetIde;
|
|
29265
29544
|
const ides = await detectIDEs();
|
|
29266
29545
|
if (options.ideId) {
|
|
@@ -29329,9 +29608,9 @@ async function launchWithCdp(options = {}) {
|
|
|
29329
29608
|
}
|
|
29330
29609
|
const port = await findFreePort(portPair);
|
|
29331
29610
|
try {
|
|
29332
|
-
if (
|
|
29611
|
+
if (platform11 === "darwin") {
|
|
29333
29612
|
await launchMacOS(targetIde, port, workspace, options.newWindow);
|
|
29334
|
-
} else if (
|
|
29613
|
+
} else if (platform11 === "win32") {
|
|
29335
29614
|
await launchWindows(targetIde, port, workspace, options.newWindow);
|
|
29336
29615
|
} else {
|
|
29337
29616
|
await launchLinux(targetIde, port, workspace, options.newWindow);
|
|
@@ -29404,13 +29683,13 @@ async function launchLinux(ide, port, workspace, newWindow) {
|
|
|
29404
29683
|
function getAvailableIdeIds() {
|
|
29405
29684
|
return getProviderLoader().getAvailableIdeTypes();
|
|
29406
29685
|
}
|
|
29407
|
-
var import_child_process6,
|
|
29686
|
+
var import_child_process6, net2, os13, path11, _providerLoader;
|
|
29408
29687
|
var init_launch = __esm({
|
|
29409
29688
|
"../../oss/packages/daemon-core/src/launch.ts"() {
|
|
29410
29689
|
"use strict";
|
|
29411
29690
|
import_child_process6 = require("child_process");
|
|
29412
|
-
|
|
29413
|
-
|
|
29691
|
+
net2 = __toESM(require("net"));
|
|
29692
|
+
os13 = __toESM(require("os"));
|
|
29414
29693
|
path11 = __toESM(require("path"));
|
|
29415
29694
|
init_ide_detector();
|
|
29416
29695
|
init_provider_loader();
|
|
@@ -29523,14 +29802,14 @@ function getRecentCommands(count = 50) {
|
|
|
29523
29802
|
return [];
|
|
29524
29803
|
}
|
|
29525
29804
|
}
|
|
29526
|
-
var fs7, path12,
|
|
29805
|
+
var fs7, path12, os14, LOG_DIR2, MAX_FILE_SIZE, MAX_DAYS, SENSITIVE_KEYS, currentDate2, currentFile, writeCount2, SKIP_COMMANDS;
|
|
29527
29806
|
var init_command_log = __esm({
|
|
29528
29807
|
"../../oss/packages/daemon-core/src/logging/command-log.ts"() {
|
|
29529
29808
|
"use strict";
|
|
29530
29809
|
fs7 = __toESM(require("fs"));
|
|
29531
29810
|
path12 = __toESM(require("path"));
|
|
29532
|
-
|
|
29533
|
-
LOG_DIR2 = process.platform === "win32" ? path12.join(process.env.LOCALAPPDATA || process.env.APPDATA || path12.join(
|
|
29811
|
+
os14 = __toESM(require("os"));
|
|
29812
|
+
LOG_DIR2 = process.platform === "win32" ? path12.join(process.env.LOCALAPPDATA || process.env.APPDATA || path12.join(os14.homedir(), "AppData", "Local"), "adhdev", "logs") : process.platform === "darwin" ? path12.join(os14.homedir(), "Library", "Logs", "adhdev") : path12.join(os14.homedir(), ".local", "share", "adhdev", "logs");
|
|
29534
29813
|
MAX_FILE_SIZE = 5 * 1024 * 1024;
|
|
29535
29814
|
MAX_DAYS = 7;
|
|
29536
29815
|
try {
|
|
@@ -29671,16 +29950,16 @@ function buildStatusSnapshot(options) {
|
|
|
29671
29950
|
version: options.version,
|
|
29672
29951
|
daemonMode: options.daemonMode,
|
|
29673
29952
|
machine: {
|
|
29674
|
-
hostname:
|
|
29675
|
-
platform:
|
|
29676
|
-
arch:
|
|
29677
|
-
cpus:
|
|
29953
|
+
hostname: os15.hostname(),
|
|
29954
|
+
platform: os15.platform(),
|
|
29955
|
+
arch: os15.arch(),
|
|
29956
|
+
cpus: os15.cpus().length,
|
|
29678
29957
|
totalMem: memSnap.totalMem,
|
|
29679
29958
|
freeMem: memSnap.freeMem,
|
|
29680
29959
|
availableMem: memSnap.availableMem,
|
|
29681
|
-
loadavg:
|
|
29682
|
-
uptime:
|
|
29683
|
-
release:
|
|
29960
|
+
loadavg: os15.loadavg(),
|
|
29961
|
+
uptime: os15.uptime(),
|
|
29962
|
+
release: os15.release()
|
|
29684
29963
|
},
|
|
29685
29964
|
machineNickname: options.machineNickname ?? cfg.machineNickname ?? null,
|
|
29686
29965
|
timestamp: options.timestamp ?? Date.now(),
|
|
@@ -29695,11 +29974,11 @@ function buildStatusSnapshot(options) {
|
|
|
29695
29974
|
availableProviders: buildAvailableProviders(options.providerLoader)
|
|
29696
29975
|
};
|
|
29697
29976
|
}
|
|
29698
|
-
var
|
|
29977
|
+
var os15, READ_DEBUG_ENABLED;
|
|
29699
29978
|
var init_snapshot = __esm({
|
|
29700
29979
|
"../../oss/packages/daemon-core/src/status/snapshot.ts"() {
|
|
29701
29980
|
"use strict";
|
|
29702
|
-
|
|
29981
|
+
os15 = __toESM(require("os"));
|
|
29703
29982
|
init_config();
|
|
29704
29983
|
init_recent_activity();
|
|
29705
29984
|
init_workspaces();
|
|
@@ -29713,7 +29992,7 @@ var init_snapshot = __esm({
|
|
|
29713
29992
|
|
|
29714
29993
|
// ../../oss/packages/daemon-core/src/commands/upgrade-helper.ts
|
|
29715
29994
|
function getUpgradeLogPath() {
|
|
29716
|
-
const home =
|
|
29995
|
+
const home = os16.homedir();
|
|
29717
29996
|
const dir = path13.join(home, ".adhdev");
|
|
29718
29997
|
fs8.mkdirSync(dir, { recursive: true });
|
|
29719
29998
|
return path13.join(dir, "daemon-upgrade.log");
|
|
@@ -29753,7 +30032,7 @@ async function waitForPidExit(pid, timeoutMs) {
|
|
|
29753
30032
|
}
|
|
29754
30033
|
}
|
|
29755
30034
|
function stopSessionHostProcesses(appName) {
|
|
29756
|
-
const pidFile = path13.join(
|
|
30035
|
+
const pidFile = path13.join(os16.homedir(), ".adhdev", `${appName}-session-host.pid`);
|
|
29757
30036
|
try {
|
|
29758
30037
|
if (fs8.existsSync(pidFile)) {
|
|
29759
30038
|
const pid = Number.parseInt(fs8.readFileSync(pidFile, "utf8").trim(), 10);
|
|
@@ -29782,7 +30061,7 @@ function stopSessionHostProcesses(appName) {
|
|
|
29782
30061
|
}
|
|
29783
30062
|
}
|
|
29784
30063
|
function removeDaemonPidFile() {
|
|
29785
|
-
const pidFile = path13.join(
|
|
30064
|
+
const pidFile = path13.join(os16.homedir(), ".adhdev", "daemon.pid");
|
|
29786
30065
|
try {
|
|
29787
30066
|
fs8.unlinkSync(pidFile);
|
|
29788
30067
|
} catch {
|
|
@@ -29887,14 +30166,14 @@ async function maybeRunDaemonUpgradeHelperFromEnv() {
|
|
|
29887
30166
|
process.exit(1);
|
|
29888
30167
|
}
|
|
29889
30168
|
}
|
|
29890
|
-
var import_child_process7, import_child_process8, fs8,
|
|
30169
|
+
var import_child_process7, import_child_process8, fs8, os16, path13, UPGRADE_HELPER_ENV;
|
|
29891
30170
|
var init_upgrade_helper = __esm({
|
|
29892
30171
|
"../../oss/packages/daemon-core/src/commands/upgrade-helper.ts"() {
|
|
29893
30172
|
"use strict";
|
|
29894
30173
|
import_child_process7 = require("child_process");
|
|
29895
30174
|
import_child_process8 = require("child_process");
|
|
29896
30175
|
fs8 = __toESM(require("fs"));
|
|
29897
|
-
|
|
30176
|
+
os16 = __toESM(require("os"));
|
|
29898
30177
|
path13 = __toESM(require("path"));
|
|
29899
30178
|
UPGRADE_HELPER_ENV = "ADHDEV_DAEMON_UPGRADE_HELPER";
|
|
29900
30179
|
}
|
|
@@ -31418,7 +31697,7 @@ function getVersion(binary, versionCommand) {
|
|
|
31418
31697
|
function checkPathExists2(paths) {
|
|
31419
31698
|
for (const p of paths) {
|
|
31420
31699
|
if (p.includes("*")) {
|
|
31421
|
-
const home =
|
|
31700
|
+
const home = os17.homedir();
|
|
31422
31701
|
const resolved = p.replace(/\*/g, home.split(path14.sep).pop() || "");
|
|
31423
31702
|
if (fs10.existsSync(resolved)) return resolved;
|
|
31424
31703
|
} else {
|
|
@@ -31493,16 +31772,16 @@ async function detectAllVersions(loader, archive) {
|
|
|
31493
31772
|
}
|
|
31494
31773
|
return results;
|
|
31495
31774
|
}
|
|
31496
|
-
var fs10, path14,
|
|
31775
|
+
var fs10, path14, os17, import_child_process9, import_os3, ARCHIVE_PATH, MAX_ENTRIES_PER_PROVIDER, VersionArchive;
|
|
31497
31776
|
var init_version_archive = __esm({
|
|
31498
31777
|
"../../oss/packages/daemon-core/src/providers/version-archive.ts"() {
|
|
31499
31778
|
"use strict";
|
|
31500
31779
|
fs10 = __toESM(require("fs"));
|
|
31501
31780
|
path14 = __toESM(require("path"));
|
|
31502
|
-
|
|
31781
|
+
os17 = __toESM(require("os"));
|
|
31503
31782
|
import_child_process9 = require("child_process");
|
|
31504
31783
|
import_os3 = require("os");
|
|
31505
|
-
ARCHIVE_PATH = path14.join(
|
|
31784
|
+
ARCHIVE_PATH = path14.join(os17.homedir(), ".adhdev", "version-history.json");
|
|
31506
31785
|
MAX_ENTRIES_PER_PROVIDER = 20;
|
|
31507
31786
|
VersionArchive = class {
|
|
31508
31787
|
history = {};
|
|
@@ -34019,7 +34298,7 @@ async function handleAutoImplement(ctx, type, req, res) {
|
|
|
34019
34298
|
});
|
|
34020
34299
|
const referenceScripts = loadAutoImplReferenceScripts(ctx, resolvedReference);
|
|
34021
34300
|
const prompt = buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domContext, referenceScripts, comment, resolvedReference, verification);
|
|
34022
|
-
const tmpDir = path17.join(
|
|
34301
|
+
const tmpDir = path17.join(os18.tmpdir(), "adhdev-autoimpl");
|
|
34023
34302
|
if (!fs13.existsSync(tmpDir)) fs13.mkdirSync(tmpDir, { recursive: true });
|
|
34024
34303
|
const promptFile = path17.join(tmpDir, `prompt-${type}-${Date.now()}.md`);
|
|
34025
34304
|
fs13.writeFileSync(promptFile, prompt, "utf-8");
|
|
@@ -34173,7 +34452,7 @@ async function handleAutoImplement(ctx, type, req, res) {
|
|
|
34173
34452
|
const interactiveFlags = ["--yolo", "--interactive", "-i"];
|
|
34174
34453
|
const baseArgs = [...spawn5.args || []].filter((a) => !interactiveFlags.includes(a));
|
|
34175
34454
|
let shellCmd;
|
|
34176
|
-
const isWin =
|
|
34455
|
+
const isWin = os18.platform() === "win32";
|
|
34177
34456
|
const escapeArg = (a) => isWin ? `"${a.replace(/"/g, '""')}"` : `'${a.replace(/'/g, "'\\''")}'`;
|
|
34178
34457
|
if (command === "claude") {
|
|
34179
34458
|
const args = [...baseArgs, "--dangerously-skip-permissions"];
|
|
@@ -34217,7 +34496,7 @@ async function handleAutoImplement(ctx, type, req, res) {
|
|
|
34217
34496
|
try {
|
|
34218
34497
|
const pty3 = require("node-pty");
|
|
34219
34498
|
ctx.log(`Auto-implement spawn (PTY): ${shellCmd}`);
|
|
34220
|
-
const isWin2 =
|
|
34499
|
+
const isWin2 = os18.platform() === "win32";
|
|
34221
34500
|
child = pty3.spawn(isWin2 ? "cmd.exe" : process.env.SHELL || "/bin/zsh", [isWin2 ? "/c" : "-c", shellCmd], {
|
|
34222
34501
|
name: "xterm-256color",
|
|
34223
34502
|
cols: 120,
|
|
@@ -35124,13 +35403,13 @@ data: ${JSON.stringify(msg.data)}
|
|
|
35124
35403
|
}
|
|
35125
35404
|
}
|
|
35126
35405
|
}
|
|
35127
|
-
var fs13, path17,
|
|
35406
|
+
var fs13, path17, os18;
|
|
35128
35407
|
var init_dev_auto_implement = __esm({
|
|
35129
35408
|
"../../oss/packages/daemon-core/src/daemon/dev-auto-implement.ts"() {
|
|
35130
35409
|
"use strict";
|
|
35131
35410
|
fs13 = __toESM(require("fs"));
|
|
35132
35411
|
path17 = __toESM(require("path"));
|
|
35133
|
-
|
|
35412
|
+
os18 = __toESM(require("os"));
|
|
35134
35413
|
init_dev_server();
|
|
35135
35414
|
init_dev_cli_debug();
|
|
35136
35415
|
}
|
|
@@ -36651,141 +36930,6 @@ data: ${JSON.stringify(msg.data)}
|
|
|
36651
36930
|
}
|
|
36652
36931
|
});
|
|
36653
36932
|
|
|
36654
|
-
// ../../oss/packages/session-host-core/dist/index.mjs
|
|
36655
|
-
function getDefaultSessionHostEndpoint(appName = "adhdev") {
|
|
36656
|
-
if (process.platform === "win32") {
|
|
36657
|
-
return {
|
|
36658
|
-
kind: "pipe",
|
|
36659
|
-
path: `\\\\.\\pipe\\${appName}-session-host`
|
|
36660
|
-
};
|
|
36661
|
-
}
|
|
36662
|
-
return {
|
|
36663
|
-
kind: "unix",
|
|
36664
|
-
path: path22.join(os17.tmpdir(), `${appName}-session-host.sock`)
|
|
36665
|
-
};
|
|
36666
|
-
}
|
|
36667
|
-
function serializeEnvelope(envelope) {
|
|
36668
|
-
return `${JSON.stringify(envelope)}
|
|
36669
|
-
`;
|
|
36670
|
-
}
|
|
36671
|
-
function createLineParser(onEnvelope) {
|
|
36672
|
-
let buffer = "";
|
|
36673
|
-
return (chunk) => {
|
|
36674
|
-
buffer += chunk.toString();
|
|
36675
|
-
let newlineIndex = buffer.indexOf("\n");
|
|
36676
|
-
while (newlineIndex >= 0) {
|
|
36677
|
-
const rawLine = buffer.slice(0, newlineIndex).trim();
|
|
36678
|
-
buffer = buffer.slice(newlineIndex + 1);
|
|
36679
|
-
if (rawLine) {
|
|
36680
|
-
onEnvelope(JSON.parse(rawLine));
|
|
36681
|
-
}
|
|
36682
|
-
newlineIndex = buffer.indexOf("\n");
|
|
36683
|
-
}
|
|
36684
|
-
};
|
|
36685
|
-
}
|
|
36686
|
-
var os17, path22, net2, import_crypto3, SessionHostClient;
|
|
36687
|
-
var init_dist = __esm({
|
|
36688
|
-
"../../oss/packages/session-host-core/dist/index.mjs"() {
|
|
36689
|
-
"use strict";
|
|
36690
|
-
os17 = __toESM(require("os"), 1);
|
|
36691
|
-
path22 = __toESM(require("path"), 1);
|
|
36692
|
-
net2 = __toESM(require("net"), 1);
|
|
36693
|
-
import_crypto3 = require("crypto");
|
|
36694
|
-
SessionHostClient = class {
|
|
36695
|
-
endpoint;
|
|
36696
|
-
socket = null;
|
|
36697
|
-
requestWaiters = /* @__PURE__ */ new Map();
|
|
36698
|
-
eventListeners = /* @__PURE__ */ new Set();
|
|
36699
|
-
constructor(options = {}) {
|
|
36700
|
-
this.endpoint = options.endpoint || getDefaultSessionHostEndpoint(options.appName || "adhdev");
|
|
36701
|
-
}
|
|
36702
|
-
async connect() {
|
|
36703
|
-
if (this.socket && !this.socket.destroyed) return;
|
|
36704
|
-
const socket = net2.createConnection(this.endpoint.path);
|
|
36705
|
-
this.socket = socket;
|
|
36706
|
-
socket.on("data", createLineParser((envelope) => {
|
|
36707
|
-
if (envelope.kind === "response") {
|
|
36708
|
-
const waiter = this.requestWaiters.get(envelope.requestId);
|
|
36709
|
-
if (waiter) {
|
|
36710
|
-
this.requestWaiters.delete(envelope.requestId);
|
|
36711
|
-
waiter.resolve(envelope.response);
|
|
36712
|
-
}
|
|
36713
|
-
return;
|
|
36714
|
-
}
|
|
36715
|
-
if (envelope.kind === "event") {
|
|
36716
|
-
for (const listener of this.eventListeners) listener(envelope.event);
|
|
36717
|
-
}
|
|
36718
|
-
}));
|
|
36719
|
-
socket.on("error", (error48) => {
|
|
36720
|
-
for (const waiter of this.requestWaiters.values()) {
|
|
36721
|
-
waiter.reject(error48);
|
|
36722
|
-
}
|
|
36723
|
-
this.requestWaiters.clear();
|
|
36724
|
-
});
|
|
36725
|
-
await new Promise((resolve13, reject) => {
|
|
36726
|
-
socket.once("connect", () => resolve13());
|
|
36727
|
-
socket.once("error", reject);
|
|
36728
|
-
});
|
|
36729
|
-
}
|
|
36730
|
-
onEvent(listener) {
|
|
36731
|
-
this.eventListeners.add(listener);
|
|
36732
|
-
return () => {
|
|
36733
|
-
this.eventListeners.delete(listener);
|
|
36734
|
-
};
|
|
36735
|
-
}
|
|
36736
|
-
async request(request) {
|
|
36737
|
-
await this.connect();
|
|
36738
|
-
if (!this.socket) throw new Error("Session host socket unavailable");
|
|
36739
|
-
const requestId = (0, import_crypto3.randomUUID)();
|
|
36740
|
-
const envelope = {
|
|
36741
|
-
kind: "request",
|
|
36742
|
-
requestId,
|
|
36743
|
-
request
|
|
36744
|
-
};
|
|
36745
|
-
const response = await new Promise((resolve13, reject) => {
|
|
36746
|
-
const timeout = setTimeout(() => {
|
|
36747
|
-
this.requestWaiters.delete(requestId);
|
|
36748
|
-
reject(new Error(`Session host request timed out after 30s (${request.type})`));
|
|
36749
|
-
}, 3e4);
|
|
36750
|
-
this.requestWaiters.set(requestId, {
|
|
36751
|
-
resolve: (value) => {
|
|
36752
|
-
clearTimeout(timeout);
|
|
36753
|
-
resolve13(value);
|
|
36754
|
-
},
|
|
36755
|
-
reject: (error48) => {
|
|
36756
|
-
clearTimeout(timeout);
|
|
36757
|
-
reject(error48);
|
|
36758
|
-
}
|
|
36759
|
-
});
|
|
36760
|
-
this.socket?.write(serializeEnvelope(envelope));
|
|
36761
|
-
});
|
|
36762
|
-
return response;
|
|
36763
|
-
}
|
|
36764
|
-
async close() {
|
|
36765
|
-
if (!this.socket) return;
|
|
36766
|
-
const socket = this.socket;
|
|
36767
|
-
this.socket = null;
|
|
36768
|
-
for (const waiter of this.requestWaiters.values()) {
|
|
36769
|
-
waiter.reject(new Error("Session host client closed"));
|
|
36770
|
-
}
|
|
36771
|
-
this.requestWaiters.clear();
|
|
36772
|
-
await new Promise((resolve13) => {
|
|
36773
|
-
let settled = false;
|
|
36774
|
-
const done = () => {
|
|
36775
|
-
if (settled) return;
|
|
36776
|
-
settled = true;
|
|
36777
|
-
resolve13();
|
|
36778
|
-
};
|
|
36779
|
-
socket.once("close", done);
|
|
36780
|
-
socket.end();
|
|
36781
|
-
socket.destroy();
|
|
36782
|
-
setTimeout(done, 50);
|
|
36783
|
-
});
|
|
36784
|
-
}
|
|
36785
|
-
};
|
|
36786
|
-
}
|
|
36787
|
-
});
|
|
36788
|
-
|
|
36789
36933
|
// ../../oss/packages/daemon-core/src/cli-adapters/session-host-transport.ts
|
|
36790
36934
|
var SessionHostRuntimeTransport, SessionHostPtyTransportFactory;
|
|
36791
36935
|
var init_session_host_transport = __esm({
|
|
@@ -38112,17 +38256,17 @@ function canPeerUsePrivilegedShareCommand(commandType, permission) {
|
|
|
38112
38256
|
return false;
|
|
38113
38257
|
}
|
|
38114
38258
|
}
|
|
38115
|
-
var fs15, path19,
|
|
38259
|
+
var fs15, path19, os19, import_node_module2, esmRequire, logFile, log, logDebug, DaemonP2PSender;
|
|
38116
38260
|
var init_daemon_p2p = __esm({
|
|
38117
38261
|
"src/daemon-p2p.ts"() {
|
|
38118
38262
|
"use strict";
|
|
38119
38263
|
fs15 = __toESM(require("fs"));
|
|
38120
38264
|
init_src();
|
|
38121
38265
|
path19 = __toESM(require("path"));
|
|
38122
|
-
|
|
38266
|
+
os19 = __toESM(require("os"));
|
|
38123
38267
|
import_node_module2 = require("module");
|
|
38124
38268
|
esmRequire = (0, import_node_module2.createRequire)(__filename);
|
|
38125
|
-
logFile = path19.join(
|
|
38269
|
+
logFile = path19.join(os19.tmpdir(), "adhdev_daemon_p2p.log");
|
|
38126
38270
|
log = (msg) => {
|
|
38127
38271
|
LOG.info("P2P", `[${(/* @__PURE__ */ new Date()).toISOString()}] [P2P] ${msg}`);
|
|
38128
38272
|
};
|
|
@@ -38185,9 +38329,9 @@ var init_daemon_p2p = __esm({
|
|
|
38185
38329
|
log(`node-datachannel not found: ${e?.message}
|
|
38186
38330
|
${e?.stack || ""}`);
|
|
38187
38331
|
}
|
|
38188
|
-
const
|
|
38332
|
+
const platform11 = process.platform;
|
|
38189
38333
|
const arch3 = process.arch;
|
|
38190
|
-
const prebuildKey = `${
|
|
38334
|
+
const prebuildKey = `${platform11}-${arch3}`;
|
|
38191
38335
|
try {
|
|
38192
38336
|
const candidates = [
|
|
38193
38337
|
path19.join(__dirname, "node_modules", "node-datachannel"),
|
|
@@ -40910,7 +41054,7 @@ var require_sharp = __commonJS({
|
|
|
40910
41054
|
if (sharp) {
|
|
40911
41055
|
module2.exports = sharp;
|
|
40912
41056
|
} else {
|
|
40913
|
-
const [isLinux2, isMacOs, isWindows2] = ["linux", "darwin", "win32"].map((
|
|
41057
|
+
const [isLinux2, isMacOs, isWindows2] = ["linux", "darwin", "win32"].map((os23) => runtimePlatform.startsWith(os23));
|
|
40914
41058
|
const help = [`Could not load the "sharp" module using the ${runtimePlatform} runtime`];
|
|
40915
41059
|
errors.forEach((err) => {
|
|
40916
41060
|
if (err.code !== "MODULE_NOT_FOUND") {
|
|
@@ -40927,15 +41071,15 @@ var require_sharp = __commonJS({
|
|
|
40927
41071
|
` Requires ${expected}`
|
|
40928
41072
|
);
|
|
40929
41073
|
} else if (prebuiltPlatforms.includes(runtimePlatform)) {
|
|
40930
|
-
const [
|
|
40931
|
-
const libc =
|
|
41074
|
+
const [os23, cpu] = runtimePlatform.split("-");
|
|
41075
|
+
const libc = os23.endsWith("musl") ? " --libc=musl" : "";
|
|
40932
41076
|
help.push(
|
|
40933
41077
|
"- Ensure optional dependencies can be installed:",
|
|
40934
41078
|
" npm install --include=optional sharp",
|
|
40935
41079
|
"- Ensure your package manager supports multi-platform installation:",
|
|
40936
41080
|
" See https://sharp.pixelplumbing.com/install#cross-platform",
|
|
40937
41081
|
"- Add platform-specific dependencies:",
|
|
40938
|
-
` npm install --os=${
|
|
41082
|
+
` npm install --os=${os23.replace("musl", "")}${libc} --cpu=${cpu} sharp`
|
|
40939
41083
|
);
|
|
40940
41084
|
} else {
|
|
40941
41085
|
help.push(
|
|
@@ -45667,24 +45811,7 @@ var init_screenshot_controller = __esm({
|
|
|
45667
45811
|
|
|
45668
45812
|
// src/session-host.ts
|
|
45669
45813
|
function buildSessionHostEnv(baseEnv) {
|
|
45670
|
-
const env =
|
|
45671
|
-
for (const [key, value] of Object.entries(baseEnv)) {
|
|
45672
|
-
if (typeof value !== "string") continue;
|
|
45673
|
-
env[key] = value;
|
|
45674
|
-
}
|
|
45675
|
-
for (const key of Object.keys(env)) {
|
|
45676
|
-
if (key === "INIT_CWD" || key === "npm_command" || key === "npm_execpath" || key === "npm_node_execpath" || key.startsWith("npm_") || key.startsWith("npm_config_") || key.startsWith("npm_package_") || key.startsWith("npm_lifecycle_") || key.startsWith("PNPM_") || key.startsWith("YARN_") || key.startsWith("BUN_")) {
|
|
45677
|
-
delete env[key];
|
|
45678
|
-
}
|
|
45679
|
-
}
|
|
45680
|
-
if (!env.NO_COLOR) {
|
|
45681
|
-
if (!env.TERM || env.TERM === "xterm-color") env.TERM = "xterm-256color";
|
|
45682
|
-
if (!env.COLORTERM) env.COLORTERM = "truecolor";
|
|
45683
|
-
if (process.platform === "win32") {
|
|
45684
|
-
if (!env.FORCE_COLOR) env.FORCE_COLOR = "1";
|
|
45685
|
-
if (!env.CLICOLOR) env.CLICOLOR = "1";
|
|
45686
|
-
}
|
|
45687
|
-
}
|
|
45814
|
+
const env = sanitizeSpawnEnv(baseEnv);
|
|
45688
45815
|
env.ADHDEV_SESSION_HOST_NAME = SESSION_HOST_APP_NAME;
|
|
45689
45816
|
return env;
|
|
45690
45817
|
}
|
|
@@ -45701,7 +45828,7 @@ function resolveSessionHostEntry() {
|
|
|
45701
45828
|
return require.resolve("@adhdev/session-host-daemon");
|
|
45702
45829
|
}
|
|
45703
45830
|
function getSessionHostPidFile() {
|
|
45704
|
-
return path20.join(
|
|
45831
|
+
return path20.join(os20.homedir(), ".adhdev", `${SESSION_HOST_APP_NAME}-session-host.pid`);
|
|
45705
45832
|
}
|
|
45706
45833
|
function killPid2(pid) {
|
|
45707
45834
|
try {
|
|
@@ -45715,6 +45842,35 @@ function killPid2(pid) {
|
|
|
45715
45842
|
return false;
|
|
45716
45843
|
}
|
|
45717
45844
|
}
|
|
45845
|
+
function getWindowsProcessCommandLine(pid) {
|
|
45846
|
+
const pidFilter = `ProcessId=${pid}`;
|
|
45847
|
+
try {
|
|
45848
|
+
const wmicOut = (0, import_child_process11.execFileSync)("wmic", [
|
|
45849
|
+
"process",
|
|
45850
|
+
"where",
|
|
45851
|
+
pidFilter,
|
|
45852
|
+
"get",
|
|
45853
|
+
"CommandLine"
|
|
45854
|
+
], { encoding: "utf8", timeout: 3e3, stdio: ["ignore", "pipe", "ignore"] });
|
|
45855
|
+
const text = wmicOut.trim();
|
|
45856
|
+
if (text) return text;
|
|
45857
|
+
} catch {
|
|
45858
|
+
}
|
|
45859
|
+
try {
|
|
45860
|
+
const psOut = (0, import_child_process11.execFileSync)("powershell.exe", [
|
|
45861
|
+
"-NoProfile",
|
|
45862
|
+
"-NonInteractive",
|
|
45863
|
+
"-ExecutionPolicy",
|
|
45864
|
+
"Bypass",
|
|
45865
|
+
"-Command",
|
|
45866
|
+
`(Get-CimInstance Win32_Process -Filter "${pidFilter}").CommandLine`
|
|
45867
|
+
], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"] });
|
|
45868
|
+
const text = psOut.trim();
|
|
45869
|
+
if (text) return text;
|
|
45870
|
+
} catch {
|
|
45871
|
+
}
|
|
45872
|
+
return null;
|
|
45873
|
+
}
|
|
45718
45874
|
function stopSessionHost() {
|
|
45719
45875
|
let stopped = false;
|
|
45720
45876
|
const pidFile = getSessionHostPidFile();
|
|
@@ -45732,7 +45888,26 @@ function stopSessionHost() {
|
|
|
45732
45888
|
} catch {
|
|
45733
45889
|
}
|
|
45734
45890
|
}
|
|
45735
|
-
if (process.platform
|
|
45891
|
+
if (process.platform === "win32") {
|
|
45892
|
+
try {
|
|
45893
|
+
const raw = (0, import_child_process11.execFileSync)("tasklist", ["/FO", "CSV", "/NH", "/FI", "IMAGENAME eq node.exe"], {
|
|
45894
|
+
encoding: "utf8",
|
|
45895
|
+
timeout: 5e3,
|
|
45896
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
45897
|
+
}).trim();
|
|
45898
|
+
for (const line of raw.split(/\r?\n/)) {
|
|
45899
|
+
const match = line.match(/^"node\.exe","(\d+)"/i);
|
|
45900
|
+
if (!match) continue;
|
|
45901
|
+
const candidatePid = Number.parseInt(match[1], 10);
|
|
45902
|
+
if (!Number.isFinite(candidatePid) || candidatePid === process.pid) continue;
|
|
45903
|
+
const commandLine = getWindowsProcessCommandLine(candidatePid);
|
|
45904
|
+
if (commandLine?.includes("session-host-daemon")) {
|
|
45905
|
+
stopped = killPid2(candidatePid) || stopped;
|
|
45906
|
+
}
|
|
45907
|
+
}
|
|
45908
|
+
} catch {
|
|
45909
|
+
}
|
|
45910
|
+
} else {
|
|
45736
45911
|
try {
|
|
45737
45912
|
const raw = (0, import_child_process11.execFileSync)("pgrep", ["-f", "session-host-daemon"], { encoding: "utf8" }).trim();
|
|
45738
45913
|
for (const line of raw.split("\n")) {
|
|
@@ -45749,13 +45924,20 @@ function stopSessionHost() {
|
|
|
45749
45924
|
async function ensureSessionHostReady2() {
|
|
45750
45925
|
const spawnHost = () => {
|
|
45751
45926
|
const entry = resolveSessionHostEntry();
|
|
45927
|
+
const logDir = path20.join(os20.homedir(), ".adhdev", "logs");
|
|
45928
|
+
fs16.mkdirSync(logDir, { recursive: true });
|
|
45929
|
+
const logFd = fs16.openSync(path20.join(logDir, "session-host.log"), "a");
|
|
45752
45930
|
const child = (0, import_child_process11.spawn)(process.execPath, [entry], {
|
|
45753
45931
|
detached: true,
|
|
45754
|
-
stdio: "ignore",
|
|
45932
|
+
stdio: ["ignore", logFd, logFd],
|
|
45755
45933
|
windowsHide: true,
|
|
45756
45934
|
env: buildSessionHostEnv(process.env)
|
|
45757
45935
|
});
|
|
45758
45936
|
child.unref();
|
|
45937
|
+
try {
|
|
45938
|
+
fs16.closeSync(logFd);
|
|
45939
|
+
} catch {
|
|
45940
|
+
}
|
|
45759
45941
|
};
|
|
45760
45942
|
try {
|
|
45761
45943
|
return await ensureSessionHostReady({
|
|
@@ -45779,13 +45961,13 @@ async function ensureSessionHostReady2() {
|
|
|
45779
45961
|
async function listHostedCliRuntimes2(endpoint) {
|
|
45780
45962
|
return listHostedCliRuntimes(endpoint);
|
|
45781
45963
|
}
|
|
45782
|
-
var import_child_process11, fs16,
|
|
45964
|
+
var import_child_process11, fs16, os20, path20, SESSION_HOST_APP_NAME, SESSION_HOST_START_TIMEOUT_MS;
|
|
45783
45965
|
var init_session_host = __esm({
|
|
45784
45966
|
"src/session-host.ts"() {
|
|
45785
45967
|
"use strict";
|
|
45786
45968
|
import_child_process11 = require("child_process");
|
|
45787
45969
|
fs16 = __toESM(require("fs"));
|
|
45788
|
-
|
|
45970
|
+
os20 = __toESM(require("os"));
|
|
45789
45971
|
path20 = __toESM(require("path"));
|
|
45790
45972
|
init_src();
|
|
45791
45973
|
init_dist();
|
|
@@ -45830,7 +46012,7 @@ __export(adhdev_daemon_exports, {
|
|
|
45830
46012
|
stopDaemon: () => stopDaemon
|
|
45831
46013
|
});
|
|
45832
46014
|
function getDaemonPidFile() {
|
|
45833
|
-
const dir = path21.join(
|
|
46015
|
+
const dir = path21.join(os21.homedir(), ".adhdev");
|
|
45834
46016
|
if (!fs17.existsSync(dir)) fs17.mkdirSync(dir, { recursive: true });
|
|
45835
46017
|
return path21.join(dir, "daemon.pid");
|
|
45836
46018
|
}
|
|
@@ -45878,7 +46060,7 @@ function stopDaemon() {
|
|
|
45878
46060
|
return false;
|
|
45879
46061
|
}
|
|
45880
46062
|
}
|
|
45881
|
-
var
|
|
46063
|
+
var os21, fs17, path21, import_http, import_ws3, import_chalk2, pkgVersion, DANGEROUS_PATTERNS, AdhdevDaemon;
|
|
45882
46064
|
var init_adhdev_daemon = __esm({
|
|
45883
46065
|
"src/adhdev-daemon.ts"() {
|
|
45884
46066
|
"use strict";
|
|
@@ -45888,14 +46070,14 @@ var init_adhdev_daemon = __esm({
|
|
|
45888
46070
|
init_screenshot_controller();
|
|
45889
46071
|
init_session_host();
|
|
45890
46072
|
init_dist();
|
|
45891
|
-
|
|
46073
|
+
os21 = __toESM(require("os"));
|
|
45892
46074
|
fs17 = __toESM(require("fs"));
|
|
45893
46075
|
path21 = __toESM(require("path"));
|
|
45894
46076
|
import_http = require("http");
|
|
45895
46077
|
import_ws3 = require("ws");
|
|
45896
46078
|
import_chalk2 = __toESM(require("chalk"));
|
|
45897
46079
|
init_version();
|
|
45898
|
-
pkgVersion = resolvePackageVersion({ injectedVersion: "0.8.
|
|
46080
|
+
pkgVersion = resolvePackageVersion({ injectedVersion: "0.8.13" });
|
|
45899
46081
|
DANGEROUS_PATTERNS = [
|
|
45900
46082
|
/\brm\s+(-[a-z]*f|-[a-z]*r|--force|--recursive)/i,
|
|
45901
46083
|
/\bsudo\b/i,
|
|
@@ -46032,8 +46214,8 @@ ${err?.stack || ""}`);
|
|
|
46032
46214
|
cliInfo: {
|
|
46033
46215
|
type: "adhdev-daemon",
|
|
46034
46216
|
version: pkgVersion,
|
|
46035
|
-
platform:
|
|
46036
|
-
hostname:
|
|
46217
|
+
platform: os21.platform(),
|
|
46218
|
+
hostname: os21.hostname(),
|
|
46037
46219
|
machineId: config2.machineId,
|
|
46038
46220
|
instanceId
|
|
46039
46221
|
}
|
|
@@ -46667,16 +46849,16 @@ async function loginFlow() {
|
|
|
46667
46849
|
let verificationUrl;
|
|
46668
46850
|
try {
|
|
46669
46851
|
const config2 = loadConfig();
|
|
46670
|
-
const
|
|
46852
|
+
const os23 = await import("os");
|
|
46671
46853
|
const res = await fetch(`${SERVER_URL}/auth/cli/init`, {
|
|
46672
46854
|
method: "POST",
|
|
46673
46855
|
headers: { "Content-Type": "application/json" },
|
|
46674
46856
|
body: JSON.stringify({
|
|
46675
46857
|
clientMachineId: config2.machineId,
|
|
46676
46858
|
registeredMachineId: config2.registeredMachineId,
|
|
46677
|
-
hostname:
|
|
46678
|
-
platform:
|
|
46679
|
-
arch:
|
|
46859
|
+
hostname: os23.hostname(),
|
|
46860
|
+
platform: os23.platform(),
|
|
46861
|
+
arch: os23.arch()
|
|
46680
46862
|
})
|
|
46681
46863
|
});
|
|
46682
46864
|
if (!res.ok) {
|
|
@@ -46777,10 +46959,10 @@ async function startDaemonFlow() {
|
|
|
46777
46959
|
const { execSync: execSync7 } = await import("child_process");
|
|
46778
46960
|
const { getCurrentDaemonLogPath: getCurrentDaemonLogPath2 } = await Promise.resolve().then(() => (init_src(), src_exports));
|
|
46779
46961
|
const logPath = getCurrentDaemonLogPath2();
|
|
46780
|
-
const
|
|
46781
|
-
const
|
|
46962
|
+
const os23 = await import("os");
|
|
46963
|
+
const platform11 = os23.platform();
|
|
46782
46964
|
try {
|
|
46783
|
-
if (
|
|
46965
|
+
if (platform11 === "win32") {
|
|
46784
46966
|
execSync7("start /B adhdev daemon >NUL 2>&1", {
|
|
46785
46967
|
timeout: 3e3,
|
|
46786
46968
|
stdio: "ignore",
|