adhdev 0.8.8 → 0.8.10

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 CHANGED
@@ -581,8 +581,8 @@ async function detectIDEs() {
581
581
  if ((0, import_fs2.existsSync)(bundledCli)) resolvedCli = bundledCli;
582
582
  }
583
583
  if (!resolvedCli && appPath && os22 === "win32") {
584
- const { dirname: dirname10 } = await import("path");
585
- const appDir = dirname10(appPath);
584
+ const { dirname: dirname9 } = await import("path");
585
+ const appDir = dirname9(appPath);
586
586
  const candidates = [
587
587
  `${appDir}\\\\bin\\\\${def.cli}.cmd`,
588
588
  `${appDir}\\\\bin\\\\${def.cli}`,
@@ -748,6 +748,12 @@ function getLogLevel() {
748
748
  function getDateStr() {
749
749
  return (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
750
750
  }
751
+ function getDaemonLogDir() {
752
+ return LOG_DIR;
753
+ }
754
+ function getCurrentDaemonLogPath(date5 = /* @__PURE__ */ new Date()) {
755
+ return path4.join(LOG_DIR, `daemon-${date5.toISOString().slice(0, 10)}.log`);
756
+ }
751
757
  function checkDateRotation() {
752
758
  const today = getDateStr();
753
759
  if (today !== currentDate) {
@@ -26981,9 +26987,9 @@ var init_handler2 = __esm({
26981
26987
  if (this.fsw.closed) {
26982
26988
  return;
26983
26989
  }
26984
- const dirname10 = sp.dirname(file2);
26990
+ const dirname9 = sp.dirname(file2);
26985
26991
  const basename7 = sp.basename(file2);
26986
- const parent = this.fsw._getWatchedDir(dirname10);
26992
+ const parent = this.fsw._getWatchedDir(dirname9);
26987
26993
  let prevStats = stats;
26988
26994
  if (parent.has(basename7))
26989
26995
  return;
@@ -27010,7 +27016,7 @@ var init_handler2 = __esm({
27010
27016
  prevStats = newStats2;
27011
27017
  }
27012
27018
  } catch (error48) {
27013
- this.fsw._remove(dirname10, basename7);
27019
+ this.fsw._remove(dirname9, basename7);
27014
27020
  }
27015
27021
  } else if (parent.has(basename7)) {
27016
27022
  const at = newStats.atimeMs;
@@ -37677,6 +37683,8 @@ __export(src_exports, {
37677
37683
  forwardAgentStreamsToIdeInstance: () => forwardAgentStreamsToIdeInstance,
37678
37684
  getAIExtensions: () => getAIExtensions,
37679
37685
  getAvailableIdeIds: () => getAvailableIdeIds,
37686
+ getCurrentDaemonLogPath: () => getCurrentDaemonLogPath,
37687
+ getDaemonLogDir: () => getDaemonLogDir,
37680
37688
  getHostMemorySnapshot: () => getHostMemorySnapshot,
37681
37689
  getLogLevel: () => getLogLevel,
37682
37690
  getRecentActivity: () => getRecentActivity,
@@ -37763,6 +37771,136 @@ var init_src = __esm({
37763
37771
  }
37764
37772
  });
37765
37773
 
37774
+ // src/cli/cdp-utils.ts
37775
+ var cdp_utils_exports = {};
37776
+ __export(cdp_utils_exports, {
37777
+ directCdpEval: () => directCdpEval,
37778
+ sendDaemonCommand: () => sendDaemonCommand
37779
+ });
37780
+ async function sendDaemonCommand(cmd, args = {}, port = 19222) {
37781
+ const WebSocket4 = (await import("ws")).default;
37782
+ const { DAEMON_WS_PATH: DAEMON_WS_PATH2 } = await Promise.resolve().then(() => (init_src(), src_exports));
37783
+ return new Promise((resolve13, reject) => {
37784
+ const wsUrl = `ws://127.0.0.1:${port}${DAEMON_WS_PATH2 || "/daemon"}`;
37785
+ const ws = new WebSocket4(wsUrl);
37786
+ const requestId = `cli-${Date.now()}`;
37787
+ let commandSent = false;
37788
+ const timeout = setTimeout(() => {
37789
+ ws.close();
37790
+ reject(new Error("Timeout: no response from daemon after 15s"));
37791
+ }, 15e3);
37792
+ const sendCommand = () => {
37793
+ if (commandSent) return;
37794
+ commandSent = true;
37795
+ ws.send(JSON.stringify({
37796
+ type: "ext:command",
37797
+ payload: { command: cmd, args, requestId }
37798
+ }));
37799
+ };
37800
+ ws.on("open", () => {
37801
+ ws.send(JSON.stringify({
37802
+ type: "ext:register",
37803
+ payload: {
37804
+ ideType: "cli-debug",
37805
+ ideVersion: "1.0.0",
37806
+ extensionVersion: "1.0.0",
37807
+ instanceId: `cli-debug-${Date.now()}`,
37808
+ machineId: "cli",
37809
+ workspaceFolders: []
37810
+ }
37811
+ }));
37812
+ setTimeout(() => sendCommand(), 200);
37813
+ });
37814
+ ws.on("message", (data) => {
37815
+ try {
37816
+ const msg = JSON.parse(data.toString());
37817
+ if (msg.type === "daemon:welcome") {
37818
+ sendCommand();
37819
+ return;
37820
+ }
37821
+ if (msg.type === "ext:command_result" && msg.payload?.requestId === requestId || msg.type === "daemon:command_result" || msg.type === "command_result") {
37822
+ clearTimeout(timeout);
37823
+ ws.close();
37824
+ resolve13(msg.payload?.result || msg.payload || msg);
37825
+ }
37826
+ } catch {
37827
+ }
37828
+ });
37829
+ ws.on("error", (e) => {
37830
+ clearTimeout(timeout);
37831
+ reject(new Error(
37832
+ `Cannot connect to local daemon IPC at port ${port}: ${e.message}
37833
+ This command needs a running local daemon with IPC enabled. Start with: adhdev daemon`
37834
+ ));
37835
+ });
37836
+ ws.on("close", () => {
37837
+ clearTimeout(timeout);
37838
+ });
37839
+ });
37840
+ }
37841
+ async function directCdpEval(expression, port = 9222) {
37842
+ const http3 = await import("http");
37843
+ const targets = await new Promise((resolve13, reject) => {
37844
+ http3.get(`http://127.0.0.1:${port}/json`, (res) => {
37845
+ let data = "";
37846
+ res.on("data", (c) => data += c);
37847
+ res.on("end", () => {
37848
+ try {
37849
+ resolve13(JSON.parse(data));
37850
+ } catch {
37851
+ reject(new Error("Invalid JSON"));
37852
+ }
37853
+ });
37854
+ }).on("error", (e) => reject(new Error(`Cannot reach CDP at port ${port}: ${e.message}`)));
37855
+ });
37856
+ const isNonMain = (title) => !title || /extension-output|ADHDev CDP|Debug Console|Output\s*$|Launchpad/i.test(title);
37857
+ const pages = targets.filter((t) => (t.type === "page" || t.type === "Page") && t.webSocketDebuggerUrl);
37858
+ const mainPages = pages.filter((t) => !isNonMain(t.title || ""));
37859
+ const target = (mainPages.length > 0 ? mainPages[0] : pages[0]) || targets[0];
37860
+ if (!target?.webSocketDebuggerUrl) throw new Error("No CDP target found");
37861
+ const WebSocket4 = (await import("ws")).default;
37862
+ return new Promise((resolve13, reject) => {
37863
+ const ws = new WebSocket4(target.webSocketDebuggerUrl);
37864
+ const timeout = setTimeout(() => {
37865
+ ws.close();
37866
+ reject(new Error("CDP timeout"));
37867
+ }, 15e3);
37868
+ let id = 1;
37869
+ ws.on("open", () => {
37870
+ const stripped = expression.replace(/\/\*[\s\S]*?\*\//g, "").trimStart();
37871
+ const isAsync = stripped.startsWith("(async");
37872
+ ws.send(JSON.stringify({
37873
+ id: id++,
37874
+ method: "Runtime.evaluate",
37875
+ params: { expression, returnByValue: true, awaitPromise: isAsync }
37876
+ }));
37877
+ });
37878
+ ws.on("message", (data) => {
37879
+ const msg = JSON.parse(data.toString());
37880
+ if (msg.id) {
37881
+ clearTimeout(timeout);
37882
+ ws.close();
37883
+ if (msg.result?.result?.value !== void 0) {
37884
+ resolve13(msg.result.result.value);
37885
+ } else if (msg.result?.exceptionDetails) {
37886
+ reject(new Error(msg.result.exceptionDetails.text));
37887
+ } else {
37888
+ resolve13(msg.result);
37889
+ }
37890
+ }
37891
+ });
37892
+ ws.on("error", (e) => {
37893
+ clearTimeout(timeout);
37894
+ reject(new Error(`CDP connection failed: ${e.message}`));
37895
+ });
37896
+ });
37897
+ }
37898
+ var init_cdp_utils = __esm({
37899
+ "src/cli/cdp-utils.ts"() {
37900
+ "use strict";
37901
+ }
37902
+ });
37903
+
37766
37904
  // src/server-connection.ts
37767
37905
  var import_ws2, ServerConnection;
37768
37906
  var init_server_connection = __esm({
@@ -39048,7 +39186,10 @@ var init_screenshot_controller = __esm({
39048
39186
  var session_host_exports = {};
39049
39187
  __export(session_host_exports, {
39050
39188
  ensureSessionHostReady: () => ensureSessionHostReady2,
39189
+ getSessionHostPid: () => getSessionHostPid,
39190
+ getSessionHostStatusPaths: () => getSessionHostStatusPaths,
39051
39191
  listHostedCliRuntimes: () => listHostedCliRuntimes2,
39192
+ probeSessionHostStatus: () => probeSessionHostStatus,
39052
39193
  stopSessionHost: () => stopSessionHost
39053
39194
  });
39054
39195
  function buildSessionHostEnv(baseEnv) {
@@ -39080,6 +39221,22 @@ function resolveSessionHostEntry() {
39080
39221
  function getSessionHostPidFile() {
39081
39222
  return path20.join(os20.homedir(), ".adhdev", `${SESSION_HOST_APP_NAME}-session-host.pid`);
39082
39223
  }
39224
+ function getSessionHostStatusPaths() {
39225
+ return {
39226
+ pidFile: getSessionHostPidFile(),
39227
+ endpoint: getDefaultSessionHostEndpoint(SESSION_HOST_APP_NAME)
39228
+ };
39229
+ }
39230
+ function getSessionHostPid() {
39231
+ try {
39232
+ const pidFile = getSessionHostPidFile();
39233
+ if (!fs16.existsSync(pidFile)) return null;
39234
+ const pid = Number.parseInt(fs16.readFileSync(pidFile, "utf8").trim(), 10);
39235
+ return Number.isFinite(pid) ? pid : null;
39236
+ } catch {
39237
+ return null;
39238
+ }
39239
+ }
39083
39240
  function killPid2(pid) {
39084
39241
  try {
39085
39242
  if (process.platform === "win32") {
@@ -39156,6 +39313,33 @@ async function ensureSessionHostReady2() {
39156
39313
  async function listHostedCliRuntimes2(endpoint) {
39157
39314
  return listHostedCliRuntimes(endpoint);
39158
39315
  }
39316
+ async function probeSessionHostStatus() {
39317
+ const { pidFile, endpoint } = getSessionHostStatusPaths();
39318
+ const pid = getSessionHostPid();
39319
+ const client = new SessionHostClient({ endpoint });
39320
+ try {
39321
+ await client.connect();
39322
+ await client.close();
39323
+ const runtimes = await listHostedCliRuntimes(endpoint);
39324
+ return {
39325
+ pid,
39326
+ pidFile,
39327
+ endpoint,
39328
+ reachable: true,
39329
+ runtimeCount: runtimes.length
39330
+ };
39331
+ } catch {
39332
+ await client.close().catch(() => {
39333
+ });
39334
+ return {
39335
+ pid,
39336
+ pidFile,
39337
+ endpoint,
39338
+ reachable: false,
39339
+ runtimeCount: 0
39340
+ };
39341
+ }
39342
+ }
39159
39343
  var import_child_process11, fs16, os20, path20, SESSION_HOST_APP_NAME, SESSION_HOST_START_TIMEOUT_MS;
39160
39344
  var init_session_host = __esm({
39161
39345
  "src/session-host.ts"() {
@@ -39165,15 +39349,44 @@ var init_session_host = __esm({
39165
39349
  os20 = __toESM(require("os"));
39166
39350
  path20 = __toESM(require("path"));
39167
39351
  init_src();
39352
+ init_dist();
39168
39353
  SESSION_HOST_APP_NAME = process.env.ADHDEV_SESSION_HOST_NAME || "adhdev";
39169
39354
  SESSION_HOST_START_TIMEOUT_MS = 15e3;
39170
39355
  }
39171
39356
  });
39172
39357
 
39358
+ // src/version.ts
39359
+ function resolvePackageVersion(options) {
39360
+ const injectedVersion = options?.injectedVersion || "unknown";
39361
+ const dir = options?.dirname || __dirname;
39362
+ const possiblePaths = [
39363
+ (0, import_path2.join)(dir, "..", "..", "package.json"),
39364
+ (0, import_path2.join)(dir, "..", "package.json"),
39365
+ (0, import_path2.join)(dir, "package.json")
39366
+ ];
39367
+ for (const p of possiblePaths) {
39368
+ try {
39369
+ const data = JSON.parse((0, import_fs3.readFileSync)(p, "utf-8"));
39370
+ if (data.version) return data.version;
39371
+ } catch {
39372
+ }
39373
+ }
39374
+ return injectedVersion;
39375
+ }
39376
+ var import_fs3, import_path2;
39377
+ var init_version = __esm({
39378
+ "src/version.ts"() {
39379
+ "use strict";
39380
+ import_fs3 = require("fs");
39381
+ import_path2 = require("path");
39382
+ }
39383
+ });
39384
+
39173
39385
  // src/adhdev-daemon.ts
39174
39386
  var adhdev_daemon_exports = {};
39175
39387
  __export(adhdev_daemon_exports, {
39176
39388
  AdhdevDaemon: () => AdhdevDaemon,
39389
+ getDaemonPid: () => getDaemonPid,
39177
39390
  isDaemonRunning: () => isDaemonRunning,
39178
39391
  stopDaemon: () => stopDaemon
39179
39392
  });
@@ -39203,6 +39416,16 @@ function isDaemonRunning() {
39203
39416
  return false;
39204
39417
  }
39205
39418
  }
39419
+ function getDaemonPid() {
39420
+ const pidFile = getDaemonPidFile();
39421
+ try {
39422
+ if (!fs17.existsSync(pidFile)) return null;
39423
+ const pid = parseInt(fs17.readFileSync(pidFile, "utf-8").trim(), 10);
39424
+ return Number.isFinite(pid) ? pid : null;
39425
+ } catch {
39426
+ return null;
39427
+ }
39428
+ }
39206
39429
  function stopDaemon() {
39207
39430
  const pidFile = getDaemonPidFile();
39208
39431
  try {
@@ -39216,7 +39439,7 @@ function stopDaemon() {
39216
39439
  return false;
39217
39440
  }
39218
39441
  }
39219
- var os21, fs17, path21, import_chalk2, pkgVersion, DANGEROUS_PATTERNS, AdhdevDaemon;
39442
+ var os21, fs17, path21, import_http, import_ws3, import_chalk2, pkgVersion, DANGEROUS_PATTERNS, AdhdevDaemon;
39220
39443
  var init_adhdev_daemon = __esm({
39221
39444
  "src/adhdev-daemon.ts"() {
39222
39445
  "use strict";
@@ -39229,27 +39452,11 @@ var init_adhdev_daemon = __esm({
39229
39452
  os21 = __toESM(require("os"));
39230
39453
  fs17 = __toESM(require("fs"));
39231
39454
  path21 = __toESM(require("path"));
39455
+ import_http = require("http");
39456
+ import_ws3 = require("ws");
39232
39457
  import_chalk2 = __toESM(require("chalk"));
39233
- pkgVersion = "0.8.8";
39234
- if (pkgVersion === "unknown") {
39235
- try {
39236
- const possiblePaths = [
39237
- path21.join(__dirname, "..", "package.json"),
39238
- path21.join(__dirname, "package.json")
39239
- ];
39240
- for (const p of possiblePaths) {
39241
- try {
39242
- const data = JSON.parse(fs17.readFileSync(p, "utf-8"));
39243
- if (data.version) {
39244
- pkgVersion = data.version;
39245
- break;
39246
- }
39247
- } catch {
39248
- }
39249
- }
39250
- } catch {
39251
- }
39252
- }
39458
+ init_version();
39459
+ pkgVersion = resolvePackageVersion({ injectedVersion: "0.8.10" });
39253
39460
  DANGEROUS_PATTERNS = [
39254
39461
  /\brm\s+(-[a-z]*f|-[a-z]*r|--force|--recursive)/i,
39255
39462
  /\bsudo\b/i,
@@ -39263,6 +39470,9 @@ var init_adhdev_daemon = __esm({
39263
39470
  /\b:\/\)\s*\{/
39264
39471
  ];
39265
39472
  AdhdevDaemon = class {
39473
+ localHttpServer = null;
39474
+ localWss = null;
39475
+ localClients = /* @__PURE__ */ new Set();
39266
39476
  serverConn = null;
39267
39477
  p2p = null;
39268
39478
  screenshotController = null;
@@ -39290,11 +39500,7 @@ var init_adhdev_daemon = __esm({
39290
39500
  return mode === "chat" || mode === "terminal";
39291
39501
  }
39292
39502
  async start(options = {}) {
39293
- try {
39294
- const { installGlobalInterceptor: installGlobalInterceptor2 } = require("./logging/logger");
39295
- installGlobalInterceptor2();
39296
- } catch {
39297
- }
39503
+ installGlobalInterceptor();
39298
39504
  process.on("uncaughtException", (err) => {
39299
39505
  LOG.error("Daemon", `Uncaught exception: ${err?.message}
39300
39506
  ${err?.stack || ""}`);
@@ -39370,6 +39576,7 @@ ${err?.stack || ""}`);
39370
39576
  }
39371
39577
  });
39372
39578
  await this.components.cliManager.restoreHostedSessions();
39579
+ await this.startLocalIpcServer();
39373
39580
  this.components.providerLoader.fetchLatest().then(({ updated }) => {
39374
39581
  if (updated) {
39375
39582
  this.components.providerLoader.reload();
@@ -39526,6 +39733,7 @@ ${err?.stack || ""}`);
39526
39733
  const cdpManagers = this.components?.cdpManagers;
39527
39734
  const cdpStatus = cdpManagers && cdpManagers.size > 0 ? `\u2705 ${[...cdpManagers.entries()].map(([k, m]) => `${k}:${m.getPort()}`).join(", ")}` : "\u274C not connected";
39528
39735
  console.log(` ${import_chalk2.default.bold("CDP:")} ${cdpStatus}`);
39736
+ console.log(` ${import_chalk2.default.bold("IPC:")} ${import_chalk2.default.cyan(`ws://127.0.0.1:${this.localPort}${DAEMON_WS_PATH}`)}`);
39529
39737
  console.log(` ${import_chalk2.default.bold("P2P:")} ${this.p2p?.isAvailable ? "\u2705 available" : "\u274C unavailable"}`);
39530
39738
  const providerCount = this.components?.providerLoader.getAll().length ?? 0;
39531
39739
  console.log(` ${import_chalk2.default.bold("Providers:")} ${providerCount > 0 ? `\u2705 ${providerCount} loaded` : "\u274C not loaded"}`);
@@ -39642,6 +39850,135 @@ ${err?.stack || ""}`);
39642
39850
  return { success: false, error: e.message };
39643
39851
  }
39644
39852
  }
39853
+ async startLocalIpcServer() {
39854
+ if (this.localHttpServer || this.localWss) return;
39855
+ this.localHttpServer = (0, import_http.createServer)((req, res) => {
39856
+ const url2 = req.url || "/";
39857
+ if (req.method === "GET" && url2 === "/health") {
39858
+ res.writeHead(200, { "Content-Type": "application/json" });
39859
+ res.end(JSON.stringify({
39860
+ ok: true,
39861
+ pid: process.pid,
39862
+ wsPath: DAEMON_WS_PATH,
39863
+ port: this.localPort
39864
+ }));
39865
+ return;
39866
+ }
39867
+ res.writeHead(404, { "Content-Type": "application/json" });
39868
+ res.end(JSON.stringify({ error: "Not found" }));
39869
+ });
39870
+ this.localWss = new import_ws3.WebSocketServer({ noServer: true });
39871
+ this.localWss.on("connection", (ws) => this.handleLocalIpcConnection(ws));
39872
+ this.localHttpServer.on("upgrade", (req, socket, head) => {
39873
+ const wsUrl = new URL(req.url || "/", `http://${req.headers.host || "127.0.0.1"}`);
39874
+ if (wsUrl.pathname !== DAEMON_WS_PATH) {
39875
+ socket.write("HTTP/1.1 404 Not Found\r\n\r\n");
39876
+ socket.destroy();
39877
+ return;
39878
+ }
39879
+ this.localWss.handleUpgrade(req, socket, head, (ws) => {
39880
+ this.localWss.emit("connection", ws, req);
39881
+ });
39882
+ });
39883
+ await new Promise((resolve13, reject) => {
39884
+ const cleanup = () => {
39885
+ this.localHttpServer?.off("error", onError);
39886
+ this.localHttpServer?.off("listening", onListening);
39887
+ };
39888
+ const onError = (error48) => {
39889
+ cleanup();
39890
+ reject(error48);
39891
+ };
39892
+ const onListening = () => {
39893
+ cleanup();
39894
+ resolve13();
39895
+ };
39896
+ this.localHttpServer.once("error", onError);
39897
+ this.localHttpServer.once("listening", onListening);
39898
+ this.localHttpServer.listen(this.localPort, "127.0.0.1");
39899
+ });
39900
+ LOG.info("IPC", `Local IPC listening on ws://127.0.0.1:${this.localPort}${DAEMON_WS_PATH}`);
39901
+ }
39902
+ handleLocalIpcConnection(ws) {
39903
+ this.localClients.add(ws);
39904
+ this.sendLocalIpcWelcome(ws);
39905
+ ws.on("message", (raw) => {
39906
+ void this.handleLocalIpcMessage(ws, raw.toString());
39907
+ });
39908
+ ws.on("close", () => {
39909
+ this.localClients.delete(ws);
39910
+ });
39911
+ ws.on("error", () => {
39912
+ this.localClients.delete(ws);
39913
+ });
39914
+ }
39915
+ sendLocalIpcWelcome(ws) {
39916
+ try {
39917
+ const cliAgents = this.components ? this.components.instanceManager.collectAllStates().filter((state) => state?.category === "cli").map((state) => String(state?.instanceId || "")).filter(Boolean) : [];
39918
+ ws.send(JSON.stringify({
39919
+ type: "daemon:welcome",
39920
+ payload: {
39921
+ daemonVersion: pkgVersion,
39922
+ serverConnected: this.serverConn?.isConnected() ?? false,
39923
+ cdpConnected: (this.components?.cdpManagers.size || 0) > 0,
39924
+ localPort: this.localPort,
39925
+ cliAgents
39926
+ }
39927
+ }));
39928
+ } catch (error48) {
39929
+ LOG.warn("IPC", `Failed to send welcome: ${error48?.message || error48}`);
39930
+ }
39931
+ }
39932
+ async handleLocalIpcMessage(ws, raw) {
39933
+ let msg;
39934
+ try {
39935
+ msg = JSON.parse(raw);
39936
+ } catch {
39937
+ return;
39938
+ }
39939
+ if (!msg || typeof msg !== "object") return;
39940
+ if (msg.type === "ext:register") {
39941
+ this.sendLocalIpcWelcome(ws);
39942
+ return;
39943
+ }
39944
+ if (msg.type !== "ext:command") return;
39945
+ const payload = msg.payload && typeof msg.payload === "object" ? msg.payload : {};
39946
+ const command = typeof payload.command === "string" ? payload.command : "";
39947
+ const args = payload.args && typeof payload.args === "object" ? payload.args : {};
39948
+ const requestId = typeof payload.requestId === "string" ? payload.requestId : typeof payload.messageId === "string" ? payload.messageId : `ipc-${Date.now()}`;
39949
+ if (!command) {
39950
+ ws.send(JSON.stringify({
39951
+ type: "ext:command_result",
39952
+ payload: {
39953
+ requestId,
39954
+ success: false,
39955
+ error: "command required"
39956
+ }
39957
+ }));
39958
+ return;
39959
+ }
39960
+ try {
39961
+ const result = await this.components.router.execute(command, args, "ipc");
39962
+ ws.send(JSON.stringify({
39963
+ type: "ext:command_result",
39964
+ payload: {
39965
+ requestId,
39966
+ success: !!result?.success,
39967
+ result,
39968
+ error: result?.success ? void 0 : result?.error
39969
+ }
39970
+ }));
39971
+ } catch (error48) {
39972
+ ws.send(JSON.stringify({
39973
+ type: "ext:command_result",
39974
+ payload: {
39975
+ requestId,
39976
+ success: false,
39977
+ error: error48?.message || String(error48)
39978
+ }
39979
+ }));
39980
+ }
39981
+ }
39645
39982
  // ─── executeDaemonCommand / stopIde: Removed — now in DaemonCommandRouter ───
39646
39983
  sendResult(msg, success2, extra) {
39647
39984
  if (!msg.id) return;
@@ -39682,6 +40019,23 @@ ${err?.stack || ""}`);
39682
40019
  this.serverConn?.disconnect();
39683
40020
  } catch {
39684
40021
  }
40022
+ try {
40023
+ for (const client of this.localClients) {
40024
+ client.close();
40025
+ }
40026
+ this.localClients.clear();
40027
+ this.localWss?.close();
40028
+ this.localWss = null;
40029
+ await new Promise((resolve13) => {
40030
+ if (!this.localHttpServer) {
40031
+ resolve13();
40032
+ return;
40033
+ }
40034
+ this.localHttpServer.close(() => resolve13());
40035
+ this.localHttpServer = null;
40036
+ });
40037
+ } catch {
40038
+ }
39685
40039
  removeDaemonPid();
39686
40040
  console.log(import_chalk2.default.green(" \u2713 ADHDev Daemon stopped.\n"));
39687
40041
  if (exitProcess) {
@@ -39821,11 +40175,12 @@ async function quickSetup() {
39821
40175
  console.log(` ${import_chalk3.default.bold("Status:")} ${loginResult ? import_chalk3.default.green("Ready to connect") : import_chalk3.default.yellow("Login required")}`);
39822
40176
  console.log();
39823
40177
  console.log(import_chalk3.default.gray(" Next steps:"));
39824
- console.log(import_chalk3.default.gray(` ${loginResult ? "adhdev daemon \u2014 Start the main daemon (required for all features)" : "adhdev setup \u2014 Sign in to finish setup and enable the daemon"}`));
40178
+ console.log(import_chalk3.default.gray(` ${loginResult ? "adhdev daemon \u2014 Start the main daemon (IDE / remote features)" : "adhdev setup \u2014 Sign in to finish setup and enable the daemon"}`));
39825
40179
  console.log(import_chalk3.default.gray(" adhdev launch cursor \u2014 Launch Cursor IDE with remote control"));
39826
40180
  console.log(import_chalk3.default.gray(" adhdev launch windsurf \u2014 Launch Windsurf IDE with remote control"));
39827
- console.log(import_chalk3.default.gray(" adhdev launch gemini \u2014 Start Gemini CLI agent via daemon"));
39828
- console.log(import_chalk3.default.gray(" adhdev launch claude \u2014 Start Claude Code agent via daemon"));
40181
+ console.log(import_chalk3.default.gray(" adhdev daemon \u2014 Keep the daemon running for CLI agent launch"));
40182
+ console.log(import_chalk3.default.gray(" adhdev launch gemini \u2014 Start Gemini CLI agent"));
40183
+ console.log(import_chalk3.default.gray(" adhdev launch claude \u2014 Start Claude Code agent"));
39829
40184
  console.log(import_chalk3.default.gray(" adhdev status \u2014 Check setup status"));
39830
40185
  console.log();
39831
40186
  console.log(import_chalk3.default.cyan(" Dashboard: https://adhf.dev/dashboard"));
@@ -39956,19 +40311,19 @@ async function startDaemonFlow() {
39956
40311
  const { AdhdevDaemon: AdhdevDaemon2 } = await Promise.resolve().then(() => (init_adhdev_daemon(), adhdev_daemon_exports));
39957
40312
  const daemon = new AdhdevDaemon2();
39958
40313
  const { execSync: execSync7 } = await import("child_process");
40314
+ const { getCurrentDaemonLogPath: getCurrentDaemonLogPath2 } = await Promise.resolve().then(() => (init_src(), src_exports));
40315
+ const logPath = getCurrentDaemonLogPath2();
39959
40316
  const os22 = await import("os");
39960
- const path23 = await import("path");
39961
- const logPath = path23.join(os22.homedir(), ".adhdev", "daemon.log");
39962
40317
  const platform11 = os22.platform();
39963
40318
  try {
39964
40319
  if (platform11 === "win32") {
39965
- execSync7(`start /B adhdev daemon > "${logPath}" 2>&1`, {
40320
+ execSync7("start /B adhdev daemon >NUL 2>&1", {
39966
40321
  timeout: 3e3,
39967
40322
  stdio: "ignore",
39968
40323
  shell: "cmd.exe"
39969
40324
  });
39970
40325
  } else {
39971
- execSync7(`nohup adhdev daemon > "${logPath}" 2>&1 &`, {
40326
+ execSync7("nohup adhdev daemon >/dev/null 2>&1 &", {
39972
40327
  timeout: 3e3,
39973
40328
  stdio: "ignore"
39974
40329
  });
@@ -40016,7 +40371,7 @@ async function installCliOnly() {
40016
40371
  console.log(import_chalk3.default.gray(" The `adhdev` command lets you:"));
40017
40372
  console.log(import_chalk3.default.gray(" \u2022 Start the main daemon (adhdev daemon)"));
40018
40373
  console.log(import_chalk3.default.gray(" \u2022 Launch IDE with CDP (adhdev launch <ide>)"));
40019
- console.log(import_chalk3.default.gray(" \u2022 Start CLI agents (adhdev launch <agent>)"));
40374
+ console.log(import_chalk3.default.gray(" \u2022 Start CLI agents (adhdev daemon && adhdev launch <agent>)"));
40020
40375
  console.log(import_chalk3.default.gray(" \u2022 Check setup status (adhdev status)"));
40021
40376
  console.log();
40022
40377
  if (currentVersion) {
@@ -40112,124 +40467,6 @@ ${import_chalk3.default.cyan("\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u
40112
40467
  }
40113
40468
  });
40114
40469
 
40115
- // src/cli/cdp-utils.ts
40116
- var cdp_utils_exports = {};
40117
- __export(cdp_utils_exports, {
40118
- directCdpEval: () => directCdpEval,
40119
- sendDaemonCommand: () => sendDaemonCommand
40120
- });
40121
- async function sendDaemonCommand(cmd, args = {}, port = 19222) {
40122
- const WebSocket3 = (await import("ws")).default;
40123
- const { DAEMON_WS_PATH: DAEMON_WS_PATH2 } = await Promise.resolve().then(() => (init_src(), src_exports));
40124
- return new Promise((resolve13, reject) => {
40125
- const wsUrl = `ws://127.0.0.1:${port}${DAEMON_WS_PATH2 || "/daemon"}`;
40126
- const ws = new WebSocket3(wsUrl);
40127
- const timeout = setTimeout(() => {
40128
- ws.close();
40129
- reject(new Error("Timeout: no response from daemon after 15s"));
40130
- }, 15e3);
40131
- ws.on("open", () => {
40132
- ws.send(JSON.stringify({
40133
- type: "ext:register",
40134
- payload: {
40135
- ideType: "cli-debug",
40136
- ideVersion: "1.0.0",
40137
- extensionVersion: "1.0.0",
40138
- instanceId: `cli-debug-${Date.now()}`,
40139
- machineId: "cli"
40140
- }
40141
- }));
40142
- setTimeout(() => {
40143
- ws.send(JSON.stringify({
40144
- type: "ext:command",
40145
- payload: { command: cmd, args, messageId: `cli-${Date.now()}` }
40146
- }));
40147
- }, 200);
40148
- });
40149
- ws.on("message", (data) => {
40150
- try {
40151
- const msg = JSON.parse(data.toString());
40152
- if (msg.type === "daemon:command_result" || msg.type === "command_result") {
40153
- clearTimeout(timeout);
40154
- ws.close();
40155
- resolve13(msg.payload?.result || msg.payload || msg);
40156
- }
40157
- } catch {
40158
- }
40159
- });
40160
- ws.on("error", (e) => {
40161
- clearTimeout(timeout);
40162
- reject(new Error(`Cannot connect to daemon at port ${port}: ${e.message}
40163
- Is 'adhdev daemon' running?`));
40164
- });
40165
- ws.on("close", () => {
40166
- clearTimeout(timeout);
40167
- });
40168
- });
40169
- }
40170
- async function directCdpEval(expression, port = 9222) {
40171
- const http3 = await import("http");
40172
- const targets = await new Promise((resolve13, reject) => {
40173
- http3.get(`http://127.0.0.1:${port}/json`, (res) => {
40174
- let data = "";
40175
- res.on("data", (c) => data += c);
40176
- res.on("end", () => {
40177
- try {
40178
- resolve13(JSON.parse(data));
40179
- } catch {
40180
- reject(new Error("Invalid JSON"));
40181
- }
40182
- });
40183
- }).on("error", (e) => reject(new Error(`Cannot reach CDP at port ${port}: ${e.message}`)));
40184
- });
40185
- const isNonMain = (title) => !title || /extension-output|ADHDev CDP|Debug Console|Output\s*$|Launchpad/i.test(title);
40186
- const pages = targets.filter((t) => (t.type === "page" || t.type === "Page") && t.webSocketDebuggerUrl);
40187
- const mainPages = pages.filter((t) => !isNonMain(t.title || ""));
40188
- const target = (mainPages.length > 0 ? mainPages[0] : pages[0]) || targets[0];
40189
- if (!target?.webSocketDebuggerUrl) throw new Error("No CDP target found");
40190
- const WebSocket3 = (await import("ws")).default;
40191
- return new Promise((resolve13, reject) => {
40192
- const ws = new WebSocket3(target.webSocketDebuggerUrl);
40193
- const timeout = setTimeout(() => {
40194
- ws.close();
40195
- reject(new Error("CDP timeout"));
40196
- }, 15e3);
40197
- let id = 1;
40198
- ws.on("open", () => {
40199
- const stripped = expression.replace(/\/\*[\s\S]*?\*\//g, "").trimStart();
40200
- const isAsync = stripped.startsWith("(async");
40201
- ws.send(JSON.stringify({
40202
- id: id++,
40203
- method: "Runtime.evaluate",
40204
- params: { expression, returnByValue: true, awaitPromise: isAsync }
40205
- }));
40206
- });
40207
- ws.on("message", (data) => {
40208
- const msg = JSON.parse(data.toString());
40209
- if (msg.id) {
40210
- clearTimeout(timeout);
40211
- ws.close();
40212
- if (msg.result?.result?.value !== void 0) {
40213
- resolve13(msg.result.result.value);
40214
- } else if (msg.result?.exceptionDetails) {
40215
- reject(new Error(msg.result.exceptionDetails.text));
40216
- } else {
40217
- resolve13(msg.result);
40218
- }
40219
- }
40220
- });
40221
- ws.on("error", (e) => {
40222
- clearTimeout(timeout);
40223
- reject(new Error(`CDP connection failed: ${e.message}`));
40224
- });
40225
- });
40226
- }
40227
- var init_cdp_utils = __esm({
40228
- "src/cli/cdp-utils.ts"() {
40229
- "use strict";
40230
- }
40231
- });
40232
-
40233
40470
  // ../../oss/packages/web-core/src/constants/supported.ts
40234
40471
  var supported_exports = {};
40235
40472
  __export(supported_exports, {
@@ -40275,18 +40512,17 @@ var init_supported = __esm({
40275
40512
  // src/cli/index.ts
40276
40513
  var import_commander = require("commander");
40277
40514
  var import_chalk7 = __toESM(require("chalk"));
40278
- var import_fs3 = require("fs");
40279
- var import_path2 = require("path");
40280
40515
  init_src();
40281
40516
 
40282
40517
  // src/cli/setup-commands.ts
40283
40518
  var import_chalk4 = __toESM(require("chalk"));
40519
+ init_cdp_utils();
40284
40520
  function registerSetupCommands(program2, providerLoader) {
40285
40521
  program2.command("setup").description("Run the interactive setup wizard (detect IDEs, login)").option("-f, --force", "Force re-run setup even if already configured").action(async (options) => {
40286
40522
  const { runWizard: runWizard2 } = await Promise.resolve().then(() => (init_wizard(), wizard_exports));
40287
40523
  await runWizard2({ force: options.force });
40288
40524
  });
40289
- program2.command("launch [target]").description("Launch IDE with CDP or start CLI agent (e.g. cursor, gemini, claude)").option("-w, --workspace <path>", "Workspace directory to open").option("-n, --new-window", "Open in a new window").option("-d, --dir <path>", "Working directory for CLI agent", process.cwd()).action(async (targetArg, options) => {
40525
+ program2.command("launch [target]").description("Launch IDE with CDP or start CLI agent").option("-w, --workspace <path>", "Workspace directory to open").option("-n, --new-window", "Open in a new window").option("-d, --dir <path>", "Working directory for CLI agent", process.cwd()).action(async (targetArg, options) => {
40290
40526
  const {
40291
40527
  detectIDEs: detectIDEs2,
40292
40528
  detectCLIs: detectCLIs2,
@@ -40301,35 +40537,7 @@ function registerSetupCommands(program2, providerLoader) {
40301
40537
  const spinner2 = ora3.default(`Launching ${targetArg}...`).start();
40302
40538
  try {
40303
40539
  const { isDaemonRunning: isDaemonRunning2 } = await Promise.resolve().then(() => (init_adhdev_daemon(), adhdev_daemon_exports));
40304
- if (isDaemonRunning2()) {
40305
- const devServerPort = 19280;
40306
- const body = JSON.stringify({
40307
- type: cliType,
40308
- workingDir: require("path").resolve(workingDir)
40309
- });
40310
- const res = await fetch(`http://127.0.0.1:${devServerPort}/api/cli/launch`, {
40311
- method: "POST",
40312
- headers: { "Content-Type": "application/json" },
40313
- body
40314
- });
40315
- const result = await res.json();
40316
- spinner2.stop();
40317
- if (!result?.launched) {
40318
- console.log(import_chalk4.default.red(`
40319
- \u2717 ${result?.error || "Launch failed"}
40320
- `));
40321
- process.exit(1);
40322
- }
40323
- console.log();
40324
- console.log(import_chalk4.default.bold(` \u{1F680} CLI Agent Launched
40325
- `));
40326
- console.log(` ${import_chalk4.default.bold("Agent:")} ${targetArg} (${cliType})`);
40327
- console.log(` ${import_chalk4.default.bold("Dir:")} ${workingDir}`);
40328
- console.log(` ${import_chalk4.default.bold("Mode:")} via running daemon`);
40329
- console.log();
40330
- console.log(import_chalk4.default.gray(" Open dashboard: https://adhf.dev/dashboard"));
40331
- console.log();
40332
- } else {
40540
+ if (!isDaemonRunning2()) {
40333
40541
  spinner2.stop();
40334
40542
  console.log(import_chalk4.default.yellow(`
40335
40543
  \u26A0 Daemon not running. Start with 'adhdev daemon' first.
@@ -40337,14 +40545,35 @@ function registerSetupCommands(program2, providerLoader) {
40337
40545
  console.log(import_chalk4.default.gray(" Then run: adhdev launch " + targetArg));
40338
40546
  process.exit(1);
40339
40547
  }
40548
+ const resolvedDir = require("path").resolve(workingDir);
40549
+ const result = await sendDaemonCommand("launch_cli", {
40550
+ cliType,
40551
+ dir: resolvedDir
40552
+ });
40553
+ spinner2.stop();
40554
+ if (!result?.success) {
40555
+ console.log(import_chalk4.default.red(`
40556
+ \u2717 ${result?.error || "Launch failed"}
40557
+ `));
40558
+ process.exit(1);
40559
+ }
40560
+ console.log();
40561
+ console.log(import_chalk4.default.bold(` \u{1F680} CLI Agent Launched
40562
+ `));
40563
+ console.log(` ${import_chalk4.default.bold("Agent:")} ${targetArg} (${cliType})`);
40564
+ console.log(` ${import_chalk4.default.bold("Dir:")} ${result?.dir || resolvedDir}`);
40565
+ console.log(` ${import_chalk4.default.bold("Mode:")} via running daemon`);
40566
+ if (result?.sessionId) {
40567
+ console.log(` ${import_chalk4.default.bold("Session:")} ${result.sessionId}`);
40568
+ }
40569
+ console.log();
40570
+ console.log(import_chalk4.default.gray(" Open dashboard: https://adhf.dev/dashboard"));
40571
+ console.log();
40340
40572
  } catch (e) {
40341
40573
  spinner2.stop();
40342
40574
  console.log(import_chalk4.default.red(`
40343
40575
  \u2717 Launch failed: ${e?.message || e}
40344
40576
  `));
40345
- if (e?.cause?.code === "ECONNREFUSED") {
40346
- console.log(import_chalk4.default.gray(" Is the daemon running with --dev? (adhdev daemon --dev)"));
40347
- }
40348
40577
  process.exit(1);
40349
40578
  }
40350
40579
  return;
@@ -40436,6 +40665,8 @@ function registerSetupCommands(program2, providerLoader) {
40436
40665
  });
40437
40666
  program2.command("status").description("Show current ADHDev setup status").action(async () => {
40438
40667
  const { loadConfig: loadConfig2, detectIDEs: detectIDEs2, detectCLIs: detectCLIs2 } = await Promise.resolve().then(() => (init_src(), src_exports));
40668
+ const { isDaemonRunning: isDaemonRunning2, getDaemonPid: getDaemonPid2 } = await Promise.resolve().then(() => (init_adhdev_daemon(), adhdev_daemon_exports));
40669
+ const { probeSessionHostStatus: probeSessionHostStatus2 } = await Promise.resolve().then(() => (init_session_host(), session_host_exports));
40439
40670
  const config2 = loadConfig2();
40440
40671
  const hasMachineSecret = Boolean(config2.machineSecret && config2.machineSecret.trim());
40441
40672
  console.log(import_chalk4.default.bold("\n\u{1F9A6} ADHDev Status\n"));
@@ -40451,11 +40682,12 @@ function registerSetupCommands(program2, providerLoader) {
40451
40682
  return;
40452
40683
  }
40453
40684
  const ideList = config2.configuredIdes?.length ? config2.configuredIdes : config2.selectedIde ? [config2.selectedIde] : [];
40685
+ const visibleIdeList = ideList.filter((ideId) => ideId !== "daemon");
40454
40686
  console.log(` ${import_chalk4.default.bold("Status:")} ${import_chalk4.default.green("\u2713 Configured")}`);
40455
- if (ideList.length > 0) {
40687
+ if (visibleIdeList.length > 0) {
40456
40688
  const ides = await detectIDEs2();
40457
40689
  console.log(` ${import_chalk4.default.bold("IDEs:")}`);
40458
- for (const ideId of ideList) {
40690
+ for (const ideId of visibleIdeList) {
40459
40691
  const ide = ides.find((i) => i.id === ideId);
40460
40692
  if (ide?.installed) {
40461
40693
  const ver = ide.version ? import_chalk4.default.gray(` v${ide.version}`) : "";
@@ -40464,6 +40696,8 @@ function registerSetupCommands(program2, providerLoader) {
40464
40696
  console.log(` ${import_chalk4.default.yellow("?")} ${ideId}`);
40465
40697
  }
40466
40698
  }
40699
+ } else {
40700
+ console.log(` ${import_chalk4.default.bold("IDEs:")} ${import_chalk4.default.gray("auto-detect at runtime")}`);
40467
40701
  }
40468
40702
  const clis = await detectCLIs2(providerLoader);
40469
40703
  const installedClis = clis.filter((c) => c.installed);
@@ -40478,6 +40712,32 @@ function registerSetupCommands(program2, providerLoader) {
40478
40712
  config2.installedExtensions.forEach((ext) => {
40479
40713
  console.log(import_chalk4.default.gray(` \u2022 ${ext}`));
40480
40714
  });
40715
+ const daemonRunning = isDaemonRunning2();
40716
+ console.log(` ${import_chalk4.default.bold("Daemon:")} ${daemonRunning ? import_chalk4.default.green(`running (PID ${getDaemonPid2() ?? "unknown"})`) : import_chalk4.default.gray("not running")}`);
40717
+ if (daemonRunning) {
40718
+ try {
40719
+ const controller = new AbortController();
40720
+ const timer = setTimeout(() => controller.abort(), 1500);
40721
+ const res = await fetch("http://127.0.0.1:19222/health", { signal: controller.signal });
40722
+ clearTimeout(timer);
40723
+ if (res.ok) {
40724
+ const data = await res.json();
40725
+ console.log(import_chalk4.default.gray(` Local IPC ${data.port}${data.wsPath}`));
40726
+ } else {
40727
+ console.log(import_chalk4.default.gray(" Local IPC unavailable"));
40728
+ }
40729
+ } catch {
40730
+ console.log(import_chalk4.default.gray(" Local IPC unavailable"));
40731
+ }
40732
+ }
40733
+ try {
40734
+ const sessionHost = await probeSessionHostStatus2();
40735
+ const sessionHostLabel = sessionHost.reachable ? `reachable (${sessionHost.runtimeCount} active runtime${sessionHost.runtimeCount === 1 ? "" : "s"})` : "not reachable";
40736
+ console.log(` ${import_chalk4.default.bold("Session Host:")} ${sessionHostLabel}`);
40737
+ console.log(import_chalk4.default.gray(` PID ${sessionHost.pid ?? "unknown"} \u2022 ${sessionHost.endpoint.path}`));
40738
+ } catch {
40739
+ console.log(` ${import_chalk4.default.bold("Session Host:")} ${import_chalk4.default.gray("status unavailable")}`);
40740
+ }
40481
40741
  console.log(` ${import_chalk4.default.bold("User:")} ${config2.userEmail || import_chalk4.default.gray("not logged in")}`);
40482
40742
  console.log(` ${import_chalk4.default.bold("Server:")} ${config2.serverUrl}`);
40483
40743
  console.log(` ${import_chalk4.default.bold("Setup date:")} ${config2.setupDate || "unknown"}`);
@@ -40630,11 +40890,56 @@ function registerDaemonCommands(program2, pkgVersion3) {
40630
40890
  });
40631
40891
  });
40632
40892
  hideCommand(program2.command("daemon:status").description("Check ADHDev Daemon status").action(async () => {
40633
- const { isDaemonRunning: isDaemonRunning2 } = await Promise.resolve().then(() => (init_adhdev_daemon(), adhdev_daemon_exports));
40893
+ const { isDaemonRunning: isDaemonRunning2, getDaemonPid: getDaemonPid2 } = await Promise.resolve().then(() => (init_adhdev_daemon(), adhdev_daemon_exports));
40894
+ const { getCurrentDaemonLogPath: getCurrentDaemonLogPath2 } = await Promise.resolve().then(() => (init_src(), src_exports));
40895
+ const { probeSessionHostStatus: probeSessionHostStatus2 } = await Promise.resolve().then(() => (init_session_host(), session_host_exports));
40634
40896
  if (isDaemonRunning2()) {
40635
40897
  console.log(import_chalk5.default.green(`
40636
40898
  \u2713 ADHDev Daemon is running.
40637
40899
  `));
40900
+ console.log(import_chalk5.default.gray(` PID: ${getDaemonPid2() ?? "unknown"}`));
40901
+ console.log(import_chalk5.default.gray(` Logs: ${getCurrentDaemonLogPath2()}`));
40902
+ try {
40903
+ const controller = new AbortController();
40904
+ const timer = setTimeout(() => controller.abort(), 1500);
40905
+ const res = await fetch("http://127.0.0.1:19222/health", { signal: controller.signal });
40906
+ clearTimeout(timer);
40907
+ if (res.ok) {
40908
+ const data = await res.json();
40909
+ console.log(import_chalk5.default.gray(` Local IPC: reachable (ws://127.0.0.1:${data.port}${data.wsPath})`));
40910
+ } else {
40911
+ console.log(import_chalk5.default.gray(" Local IPC: not reachable"));
40912
+ }
40913
+ } catch {
40914
+ console.log(import_chalk5.default.gray(" Local IPC: not reachable"));
40915
+ }
40916
+ try {
40917
+ const sessionHost = await probeSessionHostStatus2();
40918
+ console.log(import_chalk5.default.gray(
40919
+ ` SessionHost: ${sessionHost.reachable ? `reachable (${sessionHost.runtimeCount} active runtime${sessionHost.runtimeCount === 1 ? "" : "s"})` : "not reachable"}`
40920
+ ));
40921
+ console.log(import_chalk5.default.gray(` Session IPC: ${sessionHost.endpoint.path}`));
40922
+ console.log(import_chalk5.default.gray(` Session PID: ${sessionHost.pid ?? "unknown"}`));
40923
+ } catch {
40924
+ console.log(import_chalk5.default.gray(" SessionHost: status unavailable"));
40925
+ }
40926
+ try {
40927
+ const controller = new AbortController();
40928
+ const timer = setTimeout(() => controller.abort(), 1500);
40929
+ const res = await fetch("http://127.0.0.1:19280/api/status", { signal: controller.signal });
40930
+ clearTimeout(timer);
40931
+ if (res.ok) {
40932
+ const data = await res.json();
40933
+ const cdpCount = data?.cdp ? Object.keys(data.cdp).length : 0;
40934
+ const providerCount = Array.isArray(data?.providers) ? data.providers.length : 0;
40935
+ console.log(import_chalk5.default.gray(` DevServer: reachable (${cdpCount} CDP, ${providerCount} providers)`));
40936
+ } else {
40937
+ console.log(import_chalk5.default.gray(" DevServer: not reachable"));
40938
+ }
40939
+ } catch {
40940
+ console.log(import_chalk5.default.gray(" DevServer: not reachable (run `adhdev daemon --dev` for local debug APIs)"));
40941
+ }
40942
+ console.log();
40638
40943
  } else {
40639
40944
  console.log(import_chalk5.default.gray(`
40640
40945
  \u2717 ADHDev Daemon is not running.`));
@@ -40680,7 +40985,8 @@ function registerDaemonCommands(program2, pkgVersion3) {
40680
40985
  console.log(import_chalk5.default.green(` \u2713 ADHDev Daemon restarted (PID: ${child.pid})
40681
40986
  `));
40682
40987
  } else {
40683
- console.log(import_chalk5.default.red(` \u2717 Daemon failed to start. Check logs: ~/.adhdev/daemon.log
40988
+ const { getCurrentDaemonLogPath: getCurrentDaemonLogPath2 } = await Promise.resolve().then(() => (init_src(), src_exports));
40989
+ console.log(import_chalk5.default.red(` \u2717 Daemon failed to start. Check logs: ${getCurrentDaemonLogPath2()}
40684
40990
  `));
40685
40991
  process.exit(1);
40686
40992
  }
@@ -40945,7 +41251,7 @@ function registerProviderCommands(program2) {
40945
41251
  }
40946
41252
  });
40947
41253
  });
40948
- req.on("error", () => reject(new Error("Daemon not reachable. Is adhdev daemon running?")));
41254
+ req.on("error", () => reject(new Error("Provider reload failed: neither daemon IPC nor DevServer is reachable. Start with `adhdev daemon` (or `adhdev daemon --dev` for provider dev APIs).")));
40949
41255
  req.write("{}");
40950
41256
  req.end();
40951
41257
  });
@@ -41810,8 +42116,8 @@ function registerCdpCommands(program2) {
41810
42116
  const mainPages = pages.filter((t) => !isNonMain(t.title || ""));
41811
42117
  const target = (mainPages.length > 0 ? mainPages[0] : pages[0]) || targets[0];
41812
42118
  if (!target?.webSocketDebuggerUrl) throw new Error("No CDP target");
41813
- const WebSocket3 = (await import("ws")).default;
41814
- const ws = new WebSocket3(target.webSocketDebuggerUrl);
42119
+ const WebSocket4 = (await import("ws")).default;
42120
+ const ws = new WebSocket4(target.webSocketDebuggerUrl);
41815
42121
  await new Promise((resolve13, reject) => {
41816
42122
  ws.on("open", () => {
41817
42123
  ws.send(JSON.stringify({ id: 1, method: "Page.captureScreenshot", params: { format: "jpeg", quality: 50 } }));
@@ -41840,25 +42146,8 @@ function registerCdpCommands(program2) {
41840
42146
  }
41841
42147
 
41842
42148
  // src/cli/index.ts
41843
- var pkgVersion2 = "unknown";
41844
- try {
41845
- const possiblePaths = [
41846
- (0, import_path2.join)(__dirname, "..", "..", "package.json"),
41847
- (0, import_path2.join)(__dirname, "..", "package.json"),
41848
- (0, import_path2.join)(__dirname, "package.json")
41849
- ];
41850
- for (const p of possiblePaths) {
41851
- try {
41852
- const data = JSON.parse((0, import_fs3.readFileSync)(p, "utf-8"));
41853
- if (data.version) {
41854
- pkgVersion2 = data.version;
41855
- break;
41856
- }
41857
- } catch {
41858
- }
41859
- }
41860
- } catch {
41861
- }
42149
+ init_version();
42150
+ var pkgVersion2 = resolvePackageVersion();
41862
42151
  var _cliProviderLoader = new ProviderLoader({ logFn: () => {
41863
42152
  } });
41864
42153
  _cliProviderLoader.loadAll();
@@ -41882,7 +42171,7 @@ void (async () => {
41882
42171
  console.log(import_chalk7.default.gray(" adhdev daemon \u2014 Start unified daemon (Required)"));
41883
42172
  console.log(import_chalk7.default.gray(" adhdev standalone \u2014 Start standalone local dashboard & daemon"));
41884
42173
  console.log(import_chalk7.default.gray(" adhdev launch cursor \u2014 Launch IDE with CDP (e.g. cursor, windsurf)"));
41885
- console.log(import_chalk7.default.gray(" adhdev launch claude \u2014 Launch CLI agent (e.g. gemini, claude)"));
42174
+ console.log(import_chalk7.default.gray(" adhdev launch claude \u2014 Launch CLI agent via the running daemon"));
41886
42175
  console.log(import_chalk7.default.gray(" adhdev status \u2014 Check current setup"));
41887
42176
  console.log(import_chalk7.default.gray(" adhdev update \u2014 Upgrade to latest version"));
41888
42177
  console.log();