adhdev 0.9.47 → 0.9.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -975,7 +975,11 @@ function resolveCommandPath(command) {
975
975
  }
976
976
  function execAsync(cmd, timeoutMs = 5e3) {
977
977
  return new Promise((resolve16) => {
978
- const child = (0, import_child_process2.exec)(cmd, { encoding: "utf-8", timeout: timeoutMs }, (err, stdout) => {
978
+ const child = (0, import_child_process2.exec)(cmd, {
979
+ encoding: "utf-8",
980
+ timeout: timeoutMs,
981
+ ...process.platform === "win32" ? { windowsHide: true } : {}
982
+ }, (err, stdout) => {
979
983
  if (err || !stdout?.trim()) {
980
984
  resolve16(null);
981
985
  } else {
@@ -7586,6 +7590,238 @@ function buildReadChatCommandResult(payload, args) {
7586
7590
  ...debugReadChat ? { debugReadChat } : {}
7587
7591
  };
7588
7592
  }
7593
+ function truncateDebugString(value, maxLength) {
7594
+ if (value.length <= maxLength) return value;
7595
+ return `${value.slice(0, maxLength)}\u2026[truncated ${value.length - maxLength} chars]`;
7596
+ }
7597
+ function redactDebugSecrets(value) {
7598
+ return value.replace(/(Authorization\s*:\s*Bearer\s+)[^\s'"`]+/gi, "$1[REDACTED:bearer]").replace(/(Bearer\s+)[A-Za-z0-9._~+\/-]{16,}=*/gi, "$1[REDACTED:bearer]").replace(/\b(?:gh[pousr]|github_pat)_[A-Za-z0-9_]{20,}\b/g, "[REDACTED:github-token]").replace(/\bsk-[A-Za-z0-9_-]{16,}\b/g, "[REDACTED:api-key]").replace(/\bxox[baprs]-[A-Za-z0-9-]{12,}\b/g, "[REDACTED:slack-token]").replace(/\b(?:adk|adm)_[A-Za-z0-9_-]{16,}\b/g, "[REDACTED:adhdev-token]").replace(/((?:api[_-]?key|token|secret|password|passwd|client[_-]?secret)\s*[:=]\s*)[^\s,'"`}&]+/gi, "$1[REDACTED:secret]").replace(/([?&](?:api[_-]?key|token|secret|password|client_secret)=)[^&#\s]+/gi, "$1[REDACTED:secret]");
7599
+ }
7600
+ function sanitizeDebugBundleValue(value, options = {}, depth = 0, keyHint = "") {
7601
+ const normalizedOptions = { ...DEFAULT_DEBUG_SANITIZE_OPTIONS, ...options };
7602
+ if (value === null || value === void 0) return value;
7603
+ if (typeof value === "number" || typeof value === "boolean") return value;
7604
+ if (typeof value === "bigint") return String(value);
7605
+ if (typeof value === "string") {
7606
+ if (SECRET_KEY_PATTERN.test(keyHint) && value.trim()) return "[REDACTED:secret-field]";
7607
+ return truncateDebugString(redactDebugSecrets(value), normalizedOptions.maxStringLength);
7608
+ }
7609
+ if (typeof value === "function") return `[Function ${value.name || "anonymous"}]`;
7610
+ if (typeof value !== "object") return String(value);
7611
+ if (depth >= normalizedOptions.maxDepth) return "[MaxDepth]";
7612
+ if (Array.isArray(value)) {
7613
+ const items = value.slice(0, normalizedOptions.maxArrayLength).map((item) => sanitizeDebugBundleValue(item, normalizedOptions, depth + 1, keyHint));
7614
+ if (value.length > normalizedOptions.maxArrayLength) {
7615
+ items.push(`[truncated ${value.length - normalizedOptions.maxArrayLength} items]`);
7616
+ }
7617
+ return items;
7618
+ }
7619
+ const record2 = value;
7620
+ const result = {};
7621
+ const entries = Object.entries(record2).slice(0, normalizedOptions.maxObjectKeys);
7622
+ for (const [key, item] of entries) {
7623
+ result[key] = sanitizeDebugBundleValue(item, normalizedOptions, depth + 1, key);
7624
+ }
7625
+ const remaining = Object.keys(record2).length - entries.length;
7626
+ if (remaining > 0) result.__truncatedKeys = remaining;
7627
+ return result;
7628
+ }
7629
+ function summarizeProviderForDebug(provider) {
7630
+ if (!provider) return null;
7631
+ const scripts = provider.scripts && typeof provider.scripts === "object" ? Object.keys(provider.scripts) : [];
7632
+ const controls = Array.isArray(provider.controls) ? provider.controls.map((control) => ({
7633
+ id: control?.id,
7634
+ label: control?.label,
7635
+ type: control?.type,
7636
+ settingKey: control?.settingKey,
7637
+ invokeScript: control?.invokeScript,
7638
+ listScript: control?.listScript,
7639
+ location: control?.location
7640
+ })) : [];
7641
+ return {
7642
+ type: provider.type,
7643
+ name: provider.name,
7644
+ category: provider.category,
7645
+ version: provider.version,
7646
+ canonicalHistory: provider.canonicalHistory,
7647
+ historyBehavior: provider.historyBehavior,
7648
+ webviewMatchText: provider.webviewMatchText,
7649
+ scriptNames: scripts,
7650
+ controls,
7651
+ resume: provider.resume
7652
+ };
7653
+ }
7654
+ function summarizeSessionForDebug(session) {
7655
+ if (!session || typeof session !== "object") return null;
7656
+ return {
7657
+ sessionId: session.sessionId,
7658
+ instanceKey: session.instanceKey,
7659
+ adapterKey: session.adapterKey,
7660
+ providerType: session.providerType,
7661
+ providerName: session.providerName,
7662
+ transport: session.transport,
7663
+ kind: session.kind,
7664
+ cdpManagerKey: session.cdpManagerKey,
7665
+ parentSessionId: session.parentSessionId,
7666
+ providerSessionId: session.providerSessionId,
7667
+ workspace: session.workspace,
7668
+ title: session.title,
7669
+ status: session.status,
7670
+ mode: session.mode,
7671
+ capabilities: session.capabilities
7672
+ };
7673
+ }
7674
+ function summarizeStateForDebug(state) {
7675
+ if (!state || typeof state !== "object") return null;
7676
+ const activeChat = state.activeChat && typeof state.activeChat === "object" ? state.activeChat : null;
7677
+ return {
7678
+ type: state.type,
7679
+ name: state.name,
7680
+ category: state.category,
7681
+ status: state.status,
7682
+ instanceId: state.instanceId,
7683
+ providerSessionId: state.providerSessionId,
7684
+ title: state.title,
7685
+ transport: state.transport,
7686
+ mode: state.mode,
7687
+ workspace: state.workspace,
7688
+ runtime: state.runtime,
7689
+ errorMessage: state.errorMessage,
7690
+ errorReason: state.errorReason,
7691
+ activeChat: activeChat ? {
7692
+ status: activeChat.status,
7693
+ title: activeChat.title,
7694
+ messageCount: Array.isArray(activeChat.messages) ? activeChat.messages.length : void 0,
7695
+ activeModal: activeChat.activeModal,
7696
+ messagesTail: Array.isArray(activeChat.messages) ? activeChat.messages.slice(-10) : void 0
7697
+ } : null,
7698
+ controlValues: state.controlValues,
7699
+ summaryMetadata: state.summaryMetadata
7700
+ };
7701
+ }
7702
+ function buildDebugBundleText(bundle) {
7703
+ return [
7704
+ "# ADHDev Chat Debug Bundle",
7705
+ "",
7706
+ "```json",
7707
+ JSON.stringify(bundle, null, 2),
7708
+ "```"
7709
+ ].join("\n");
7710
+ }
7711
+ async function handleGetChatDebugBundle(h, args) {
7712
+ const provider = h.getProvider(args?.agentType);
7713
+ const transport = getTargetTransport(h, provider);
7714
+ const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
7715
+ const providerType = provider?.type || getCurrentProviderType(h, args?.agentType || "");
7716
+ const adapter = isCliLikeTransport(transport) ? getTargetedCliAdapter(h, args, provider?.type) : null;
7717
+ const targetInstance = getTargetInstance(h, args);
7718
+ let adapterStatus = null;
7719
+ let parsedStatus = null;
7720
+ let adapterDebugSnapshot = null;
7721
+ let partialResponse = "";
7722
+ if (adapter) {
7723
+ try {
7724
+ adapterStatus = adapter.getStatus?.();
7725
+ } catch (error48) {
7726
+ adapterStatus = { error: error48?.message || String(error48) };
7727
+ }
7728
+ try {
7729
+ parsedStatus = typeof adapter.getScriptParsedStatus === "function" ? parseMaybeJson(adapter.getScriptParsedStatus()) : null;
7730
+ } catch (error48) {
7731
+ parsedStatus = { error: error48?.message || String(error48) };
7732
+ }
7733
+ try {
7734
+ adapterDebugSnapshot = typeof adapter.getDebugSnapshot === "function" ? adapter.getDebugSnapshot() : null;
7735
+ } catch (error48) {
7736
+ adapterDebugSnapshot = { error: error48?.message || String(error48) };
7737
+ }
7738
+ try {
7739
+ partialResponse = adapter.getPartialResponse?.() || "";
7740
+ } catch {
7741
+ partialResponse = "";
7742
+ }
7743
+ }
7744
+ let instanceState = null;
7745
+ if (targetInstance?.getState) {
7746
+ try {
7747
+ instanceState = summarizeStateForDebug(targetInstance.getState());
7748
+ } catch (error48) {
7749
+ instanceState = { error: error48?.message || String(error48) };
7750
+ }
7751
+ }
7752
+ let readChat = null;
7753
+ try {
7754
+ const readResult = await handleReadChat(h, { ...args, tailLimit: Math.max(1, Math.min(40, Number(args?.tailLimit || 40))) });
7755
+ readChat = readResult.success ? {
7756
+ success: true,
7757
+ status: readResult.status,
7758
+ title: readResult.title,
7759
+ totalMessages: readResult.totalMessages,
7760
+ returnedMessages: Array.isArray(readResult.messages) ? readResult.messages.length : void 0,
7761
+ syncMode: readResult.syncMode,
7762
+ replaceFrom: readResult.replaceFrom,
7763
+ lastMessageSignature: readResult.lastMessageSignature,
7764
+ providerSessionId: readResult.providerSessionId,
7765
+ transcriptAuthority: readResult.transcriptAuthority,
7766
+ coverage: readResult.coverage,
7767
+ activeModal: readResult.activeModal,
7768
+ messagesTail: Array.isArray(readResult.messages) ? readResult.messages.slice(-20) : [],
7769
+ debugReadChat: readResult.debugReadChat
7770
+ } : { success: false, error: readResult.error };
7771
+ } catch (error48) {
7772
+ readChat = { success: false, error: error48?.message || String(error48) };
7773
+ }
7774
+ const cdp = h.getCdp();
7775
+ const rawBundle = {
7776
+ version: 1,
7777
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
7778
+ target: {
7779
+ targetSessionId,
7780
+ providerType,
7781
+ transport,
7782
+ routeManagerKey: h.currentManagerKey,
7783
+ currentIdeType: h.currentIdeType
7784
+ },
7785
+ session: summarizeSessionForDebug(h.currentSession),
7786
+ provider: summarizeProviderForDebug(provider),
7787
+ daemon: {
7788
+ pid: process.pid,
7789
+ platform: process.platform,
7790
+ nodeVersion: process.version,
7791
+ cwd: process.cwd()
7792
+ },
7793
+ cdp: {
7794
+ requested: !!cdp,
7795
+ connected: !!cdp?.isConnected,
7796
+ managerKey: getCurrentManagerKey(h)
7797
+ },
7798
+ instanceState,
7799
+ cli: adapter ? {
7800
+ cliType: adapter.cliType,
7801
+ cliName: adapter.cliName,
7802
+ workingDir: adapter.workingDir,
7803
+ status: adapterStatus?.status,
7804
+ activeModal: adapterStatus?.activeModal,
7805
+ messageCount: Array.isArray(adapterStatus?.messages) ? adapterStatus.messages.length : void 0,
7806
+ messagesTail: Array.isArray(adapterStatus?.messages) ? adapterStatus.messages.slice(-20) : void 0,
7807
+ parsedStatus,
7808
+ partialResponse,
7809
+ ready: typeof adapter.isReady === "function" ? adapter.isReady() : void 0,
7810
+ processing: typeof adapter.isProcessing === "function" ? adapter.isProcessing() : void 0,
7811
+ debugSnapshot: adapterDebugSnapshot
7812
+ } : null,
7813
+ readChat,
7814
+ frontend: args?.frontendSnapshot && typeof args.frontendSnapshot === "object" ? args.frontendSnapshot : null,
7815
+ recentLogs: getRecentLogs(80, "debug"),
7816
+ recentDebugTrace: getRecentDebugTrace({ limit: 120 })
7817
+ };
7818
+ const bundle = sanitizeDebugBundleValue(rawBundle);
7819
+ return {
7820
+ success: true,
7821
+ bundle,
7822
+ text: buildDebugBundleText(bundle)
7823
+ };
7824
+ }
7589
7825
  function didProviderConfirmSend(result) {
7590
7826
  const parsed = parseMaybeJson(result);
7591
7827
  if (parsed === true) return true;
@@ -8559,7 +8795,7 @@ async function handleResolveAction(h, args) {
8559
8795
  }
8560
8796
  return { success: false, error: "resolveAction script not available for this provider" };
8561
8797
  }
8562
- var RECENT_SEND_WINDOW_MS, READ_CHAT_PROVIDER_EVAL_TIMEOUT_MS, recentSendByTarget;
8798
+ var RECENT_SEND_WINDOW_MS, READ_CHAT_PROVIDER_EVAL_TIMEOUT_MS, recentSendByTarget, DEFAULT_DEBUG_SANITIZE_OPTIONS, SECRET_KEY_PATTERN;
8563
8799
  var init_chat_commands = __esm({
8564
8800
  "../../oss/packages/daemon-core/src/commands/chat-commands.ts"() {
8565
8801
  "use strict";
@@ -8574,6 +8810,13 @@ var init_chat_commands = __esm({
8574
8810
  RECENT_SEND_WINDOW_MS = 1200;
8575
8811
  READ_CHAT_PROVIDER_EVAL_TIMEOUT_MS = 25e3;
8576
8812
  recentSendByTarget = /* @__PURE__ */ new Map();
8813
+ DEFAULT_DEBUG_SANITIZE_OPTIONS = {
8814
+ maxDepth: 8,
8815
+ maxArrayLength: 80,
8816
+ maxObjectKeys: 120,
8817
+ maxStringLength: 16e3
8818
+ };
8819
+ SECRET_KEY_PATTERN = /(?:token|secret|password|passwd|authorization|cookie|api[_-]?key|access[_-]?key|refresh[_-]?token|client[_-]?secret|private[_-]?key)/i;
8577
8820
  }
8578
8821
  });
8579
8822
 
@@ -9002,7 +9245,8 @@ function getCliScriptCommand(payload) {
9002
9245
  if (command.type !== "send_message" && command.type !== "pty_write") return null;
9003
9246
  const text = typeof command.text === "string" ? command.text.trim() : typeof command.message === "string" ? command.message.trim() : "";
9004
9247
  if (!text) return null;
9005
- return { type: command.type, text };
9248
+ const enterCount = Number.isInteger(command.enterCount) && command.enterCount > 0 && command.enterCount <= 5 ? command.enterCount : void 0;
9249
+ return { type: command.type, text, ...enterCount ? { enterCount } : {} };
9006
9250
  }
9007
9251
  var init_cli_script_results = __esm({
9008
9252
  "../../oss/packages/daemon-core/src/providers/cli-script-results.ts"() {
@@ -9264,7 +9508,12 @@ async function executeProviderScript(h, args, scriptName) {
9264
9508
  if (cliCommand?.type === "send_message" && cliCommand.text) {
9265
9509
  await adapter.sendMessage(cliCommand.text);
9266
9510
  } else if (cliCommand?.type === "pty_write" && cliCommand.text && adapter.writeRaw) {
9511
+ const enterCount = cliCommand.enterCount || 1;
9267
9512
  await adapter.writeRaw(cliCommand.text + "\r");
9513
+ for (let i = 1; i < enterCount; i += 1) {
9514
+ await new Promise((resolve16) => setTimeout(resolve16, 50));
9515
+ await adapter.writeRaw("\r");
9516
+ }
9268
9517
  }
9269
9518
  applyProviderPatch(h, args, parsed.payload);
9270
9519
  return {
@@ -9835,6 +10084,8 @@ var init_handler = __esm({
9835
10084
  // ─── Chat commands (chat-commands.ts) ───────────────
9836
10085
  case "read_chat":
9837
10086
  return handleReadChat(this, args);
10087
+ case "get_chat_debug_bundle":
10088
+ return handleGetChatDebugBundle(this, args);
9838
10089
  case "chat_history":
9839
10090
  return handleChatHistory(this, args);
9840
10091
  case "send_chat":
@@ -11187,7 +11438,12 @@ function findBinary(name) {
11187
11438
  const isWin = os10.platform() === "win32";
11188
11439
  try {
11189
11440
  const cmd = isWin ? `where ${trimmed}` : `which ${trimmed}`;
11190
- return (0, import_child_process4.execSync)(cmd, { encoding: "utf-8", timeout: 5e3, stdio: ["pipe", "pipe", "pipe"] }).trim().split("\n")[0].trim();
11441
+ return (0, import_child_process4.execSync)(cmd, {
11442
+ encoding: "utf-8",
11443
+ timeout: 5e3,
11444
+ stdio: ["pipe", "pipe", "pipe"],
11445
+ ...isWin ? { windowsHide: true } : {}
11446
+ }).trim().split("\n")[0].trim();
11191
11447
  } catch {
11192
11448
  return isWin ? `${trimmed}.cmd` : trimmed;
11193
11449
  }
@@ -13872,6 +14128,83 @@ var init_provider_cli_adapter = __esm({
13872
14128
  if (!this.isWaitingForResponse) return "";
13873
14129
  return this.responseBuffer;
13874
14130
  }
14131
+ getDebugSnapshot() {
14132
+ const screenText = this.readTerminalScreenText();
14133
+ const parsedResult = this.parsedStatusCache?.result && typeof this.parsedStatusCache.result === "object" ? this.parsedStatusCache.result : null;
14134
+ return {
14135
+ cliType: this.cliType,
14136
+ cliName: this.cliName,
14137
+ workingDir: this.workingDir,
14138
+ currentStatus: this.currentStatus,
14139
+ ready: this.ready,
14140
+ isWaitingForResponse: this.isWaitingForResponse,
14141
+ activeModal: this.activeModal,
14142
+ parseErrorMessage: this.parseErrorMessage,
14143
+ messageCounts: {
14144
+ committed: this.committedMessages.length,
14145
+ structured: this.structuredMessages.length,
14146
+ visible: this.messages.length,
14147
+ parsedCache: Array.isArray(parsedResult?.messages) ? parsedResult.messages.length : void 0
14148
+ },
14149
+ buffers: {
14150
+ accumulatedLength: this.accumulatedBuffer.length,
14151
+ accumulatedRawLength: this.accumulatedRawBuffer.length,
14152
+ recentOutputLength: this.recentOutputBuffer.length,
14153
+ responseLength: this.responseBuffer.length,
14154
+ startupLength: this.startupBuffer.length,
14155
+ accumulatedTail: this.accumulatedBuffer.slice(-24e3),
14156
+ accumulatedRawTail: this.accumulatedRawBuffer.slice(-24e3),
14157
+ recentOutputTail: this.recentOutputBuffer.slice(-12e3),
14158
+ responseTail: this.responseBuffer.slice(-12e3)
14159
+ },
14160
+ terminal: {
14161
+ screenText,
14162
+ lastScreenSnapshot: this.lastScreenSnapshot,
14163
+ lastScreenText: this.lastScreenText,
14164
+ lastOutputAt: this.lastOutputAt,
14165
+ lastNonEmptyOutputAt: this.lastNonEmptyOutputAt,
14166
+ lastScreenChangeAt: this.lastScreenChangeAt,
14167
+ lastScreenSnapshotReadAt: this.lastScreenSnapshotReadAt
14168
+ },
14169
+ parser: {
14170
+ scriptNames: listCliScriptNames(this.cliScripts),
14171
+ traceSessionId: this.traceSessionId,
14172
+ traceSeq: this.traceSeq,
14173
+ currentTurnScope: this.currentTurnScope,
14174
+ parsedStatusCache: parsedResult ? {
14175
+ id: parsedResult.id,
14176
+ status: parsedResult.status,
14177
+ title: parsedResult.title,
14178
+ providerSessionId: parsedResult.providerSessionId,
14179
+ transcriptAuthority: parsedResult.transcriptAuthority,
14180
+ coverage: parsedResult.coverage,
14181
+ messageCount: Array.isArray(parsedResult.messages) ? parsedResult.messages.length : void 0,
14182
+ activeModal: parsedResult.activeModal
14183
+ } : null,
14184
+ pendingScriptStatus: this.pendingScriptStatus,
14185
+ pendingScriptStatusSince: this.pendingScriptStatusSince
14186
+ },
14187
+ runtimeMetadata: this.getRuntimeMetadata(),
14188
+ statusHistory: this.statusHistory.slice(-80),
14189
+ traceEntries: this.traceEntries.slice(-120),
14190
+ timing: {
14191
+ spawnAt: this.spawnAt,
14192
+ startupFirstOutputAt: this.startupFirstOutputAt,
14193
+ submitPendingUntil: this.submitPendingUntil,
14194
+ responseSettleIgnoreUntil: this.responseSettleIgnoreUntil,
14195
+ responseEpoch: this.responseEpoch,
14196
+ resizeSuppressUntil: this.resizeSuppressUntil,
14197
+ lastApprovalResolvedAt: this.lastApprovalResolvedAt,
14198
+ committedMessagesChangedAt: this.committedMessagesChangedAt
14199
+ },
14200
+ finish: {
14201
+ idleFinishCandidate: this.idleFinishCandidate,
14202
+ finishRetryCount: this.finishRetryCount,
14203
+ submitRetryUsed: this.submitRetryUsed,
14204
+ submitRetryPromptSnippet: this.submitRetryPromptSnippet
14205
+ }
14206
+ };
14207
+ }
13875
14208
  getRuntimeMetadata() {
13876
14209
  if (!this.ptyProcess || typeof this.ptyProcess.getMetadata !== "function") return null;
13877
14210
  return this.ptyProcess.getMetadata();
@@ -14624,7 +14957,12 @@ var init_cli_provider_instance = __esm({
14624
14957
  if (cliCommand?.type === "send_message" && cliCommand.text) {
14625
14958
  await this.adapter.sendMessage(cliCommand.text);
14626
14959
  } else if (cliCommand?.type === "pty_write" && cliCommand.text) {
14960
+ const enterCount = cliCommand.enterCount || 1;
14627
14961
  await this.adapter.writeRaw(cliCommand.text + "\r");
14962
+ for (let i = 1; i < enterCount; i += 1) {
14963
+ await new Promise((resolve16) => setTimeout(resolve16, 50));
14964
+ await this.adapter.writeRaw("\r");
14965
+ }
14628
14966
  }
14629
14967
  this.applyProviderResponse(parsed.payload, { phase: "immediate" });
14630
14968
  }
@@ -31943,7 +32281,8 @@ var init_acp_provider_instance = __esm({
31943
32281
  cwd: this.workingDir,
31944
32282
  env: env3,
31945
32283
  stdio: ["pipe", "pipe", "pipe"],
31946
- shell: spawnConfig.shell || false
32284
+ shell: spawnConfig.shell || false,
32285
+ ...process.platform === "win32" ? { windowsHide: true } : {}
31947
32286
  });
31948
32287
  const AUTH_ERROR_PATTERNS = [
31949
32288
  /unauthorized|unauthenticated/i,
@@ -32642,7 +32981,10 @@ function commandExists(command) {
32642
32981
  return (0, import_fs5.existsSync)(expandExecutable(trimmed));
32643
32982
  }
32644
32983
  try {
32645
- (0, import_child_process6.execFileSync)(process.platform === "win32" ? "where" : "which", [trimmed], { stdio: "ignore" });
32984
+ (0, import_child_process6.execFileSync)(process.platform === "win32" ? "where" : "which", [trimmed], {
32985
+ stdio: "ignore",
32986
+ ...process.platform === "win32" ? { windowsHide: true } : {}
32987
+ });
32646
32988
  return true;
32647
32989
  } catch {
32648
32990
  return false;
@@ -37361,7 +37703,7 @@ async function launchMacOS(ide, port, workspace, newWindow) {
37361
37703
  const canUseAppLauncher = !!appName;
37362
37704
  const useAppLauncher = preferredMethod === "app" ? canUseAppLauncher : preferredMethod === "cli" ? false : !canUseCli && canUseAppLauncher;
37363
37705
  if (!useAppLauncher && ide.cliCommand) {
37364
- (0, import_child_process7.spawn)(ide.cliCommand, args, { detached: true, stdio: "ignore" }).unref();
37706
+ (0, import_child_process7.spawn)(ide.cliCommand, args, { detached: true, stdio: "ignore", windowsHide: true }).unref();
37365
37707
  } else if (appName) {
37366
37708
  const openArgs = ["-a", appName, "--args", ...args];
37367
37709
  (0, import_child_process7.spawn)("open", openArgs, { detached: true, stdio: "ignore" }).unref();
@@ -37390,7 +37732,7 @@ async function launchLinux(ide, port, workspace, newWindow) {
37390
37732
  const args = ["--remote-debugging-port=" + port];
37391
37733
  if (newWindow) args.push("--new-window");
37392
37734
  if (workspace) args.push(workspace);
37393
- (0, import_child_process7.spawn)(cli, args, { detached: true, stdio: "ignore" }).unref();
37735
+ (0, import_child_process7.spawn)(cli, args, { detached: true, stdio: "ignore", windowsHide: true }).unref();
37394
37736
  }
37395
37737
  function getAvailableIdeIds() {
37396
37738
  return getProviderLoader().getAvailableIdeTypes();
@@ -37894,16 +38236,28 @@ function appendUpgradeLog(message) {
37894
38236
  } catch {
37895
38237
  }
37896
38238
  }
37897
- function resolveSiblingNpmExecutable(nodeExecutable) {
38239
+ function resolveSiblingNpmInvocation(nodeExecutable, platform12 = process.platform) {
37898
38240
  const binDir = path16.dirname(nodeExecutable);
37899
- const candidates = process.platform === "win32" ? ["npm.cmd", "npm.exe", "npm"] : ["npm"];
37900
- for (const candidate of candidates) {
38241
+ if (platform12 === "win32") {
38242
+ const npmCliPath = path16.join(binDir, "node_modules", "npm", "bin", "npm-cli.js");
38243
+ if (fs8.existsSync(npmCliPath)) {
38244
+ return { executable: nodeExecutable, argsPrefix: [npmCliPath], execOptions: getNpmExecOptions(platform12) };
38245
+ }
38246
+ for (const candidate of ["npm.exe", "npm"]) {
38247
+ const candidatePath = path16.join(binDir, candidate);
38248
+ if (fs8.existsSync(candidatePath)) {
38249
+ return { executable: candidatePath, argsPrefix: [], execOptions: getNpmExecOptions(platform12) };
38250
+ }
38251
+ }
38252
+ return { executable: nodeExecutable, argsPrefix: [npmCliPath], execOptions: getNpmExecOptions(platform12) };
38253
+ }
38254
+ for (const candidate of ["npm"]) {
37901
38255
  const candidatePath = path16.join(binDir, candidate);
37902
38256
  if (fs8.existsSync(candidatePath)) {
37903
- return candidatePath;
38257
+ return { executable: candidatePath, argsPrefix: [], execOptions: getNpmExecOptions(platform12) };
37904
38258
  }
37905
38259
  }
37906
- return "npm";
38260
+ return { executable: "npm", argsPrefix: [], execOptions: getNpmExecOptions(platform12) };
37907
38261
  }
37908
38262
  function findCurrentPackageRoot(currentCliPath, packageName) {
37909
38263
  if (!currentCliPath) return null;
@@ -37952,31 +38306,50 @@ function resolveInstallPrefixFromPackageRoot(packageRoot, packageName) {
37952
38306
  }
37953
38307
  function resolveCurrentGlobalInstallSurface(options) {
37954
38308
  const packageRoot = findCurrentPackageRoot(options.currentCliPath || process.argv[1], options.packageName);
38309
+ const npmInvocation = resolveSiblingNpmInvocation(options.nodeExecutable || process.execPath, options.platform);
37955
38310
  return {
37956
- npmExecutable: resolveSiblingNpmExecutable(options.nodeExecutable || process.execPath),
38311
+ npmExecutable: npmInvocation.executable,
38312
+ npmArgsPrefix: npmInvocation.argsPrefix,
37957
38313
  packageRoot,
37958
- installPrefix: packageRoot ? resolveInstallPrefixFromPackageRoot(packageRoot, options.packageName) : null
38314
+ installPrefix: packageRoot ? resolveInstallPrefixFromPackageRoot(packageRoot, options.packageName) : null,
38315
+ execOptions: npmInvocation.execOptions
37959
38316
  };
37960
38317
  }
37961
38318
  function buildPinnedGlobalInstallCommand(options) {
37962
38319
  const surface = resolveCurrentGlobalInstallSurface(options);
37963
- const args = ["install", "-g", `${options.packageName}@${options.targetVersion || "latest"}`, "--force"];
38320
+ const args = [...surface.npmArgsPrefix || [], "install", "-g", `${options.packageName}@${options.targetVersion || "latest"}`, "--force"];
37964
38321
  if (surface.installPrefix) {
37965
38322
  args.push("--prefix", surface.installPrefix);
37966
38323
  }
37967
38324
  return {
37968
38325
  command: surface.npmExecutable,
37969
38326
  args,
37970
- surface
38327
+ surface,
38328
+ execOptions: surface.execOptions || getNpmExecOptions(options.platform)
37971
38329
  };
37972
38330
  }
37973
- function getNpmExecOptions() {
37974
- return { shell: process.platform === "win32" };
38331
+ function getNpmExecOptions(platform12 = process.platform) {
38332
+ if (platform12 === "win32") {
38333
+ return { shell: false, windowsHide: true };
38334
+ }
38335
+ return { shell: false };
38336
+ }
38337
+ function execNpmCommandSync(args, options = {}, surface) {
38338
+ const execOptions = surface?.execOptions || getNpmExecOptions();
38339
+ return (0, import_child_process8.execFileSync)(
38340
+ surface?.npmExecutable || "npm",
38341
+ [...surface?.npmArgsPrefix || [], ...args],
38342
+ {
38343
+ ...options,
38344
+ ...execOptions,
38345
+ ...process.platform === "win32" ? { windowsHide: true } : {}
38346
+ }
38347
+ );
37975
38348
  }
37976
38349
  function killPid(pid) {
37977
38350
  try {
37978
38351
  if (process.platform === "win32") {
37979
- (0, import_child_process8.execFileSync)("taskkill", ["/PID", String(pid), "/T", "/F"], { stdio: "ignore" });
38352
+ (0, import_child_process8.execFileSync)("taskkill", ["/PID", String(pid), "/T", "/F"], { stdio: "ignore", windowsHide: true });
37980
38353
  } else {
37981
38354
  process.kill(pid, "SIGTERM");
37982
38355
  }
@@ -37995,7 +38368,7 @@ function getWindowsProcessCommandLine(pid) {
37995
38368
  "Bypass",
37996
38369
  "-Command",
37997
38370
  `(Get-CimInstance Win32_Process -Filter "${pidFilter}").CommandLine`
37998
- ], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"] }).trim();
38371
+ ], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"], windowsHide: true }).trim();
37999
38372
  if (psOut) return psOut;
38000
38373
  } catch {
38001
38374
  }
@@ -38006,7 +38379,7 @@ function getWindowsProcessCommandLine(pid) {
38006
38379
  pidFilter,
38007
38380
  "get",
38008
38381
  "CommandLine"
38009
- ], { encoding: "utf8", timeout: 3e3, stdio: ["ignore", "pipe", "ignore"] }).trim();
38382
+ ], { encoding: "utf8", timeout: 3e3, stdio: ["ignore", "pipe", "ignore"], windowsHide: true }).trim();
38010
38383
  if (wmicOut) return wmicOut;
38011
38384
  } catch {
38012
38385
  }
@@ -38066,11 +38439,10 @@ function removeDaemonPidFile() {
38066
38439
  }
38067
38440
  }
38068
38441
  function cleanupStaleGlobalInstallDirs(pkgName, surface) {
38069
- const npmExecOpts = getNpmExecOptions();
38070
38442
  const prefixArgs = surface.installPrefix ? ["--prefix", surface.installPrefix] : [];
38071
- const npmRoot = (0, import_child_process8.execFileSync)(surface.npmExecutable, ["root", "-g", ...prefixArgs], { encoding: "utf8", ...npmExecOpts }).trim();
38443
+ const npmRoot = String(execNpmCommandSync(["root", "-g", ...prefixArgs], { encoding: "utf8" }, surface)).trim();
38072
38444
  if (!npmRoot) return;
38073
- const npmPrefix = surface.installPrefix || (0, import_child_process8.execFileSync)(surface.npmExecutable, ["prefix", "-g", ...prefixArgs], { encoding: "utf8", ...npmExecOpts }).trim();
38445
+ const npmPrefix = surface.installPrefix || String(execNpmCommandSync(["prefix", "-g", ...prefixArgs], { encoding: "utf8" }, surface)).trim();
38074
38446
  const binDir = process.platform === "win32" ? npmPrefix : path16.join(npmPrefix, "bin");
38075
38447
  const packageBaseName = pkgName.startsWith("@") ? pkgName.split("/")[1] : pkgName;
38076
38448
  const binNames = /* @__PURE__ */ new Set([packageBaseName]);
@@ -38140,7 +38512,7 @@ async function runDaemonUpgradeHelper(payload) {
38140
38512
  encoding: "utf8",
38141
38513
  stdio: "pipe",
38142
38514
  maxBuffer: 20 * 1024 * 1024,
38143
- ...getNpmExecOptions()
38515
+ ...installCommand.execOptions
38144
38516
  }
38145
38517
  );
38146
38518
  if (installOutput.trim()) {
@@ -38892,18 +39264,18 @@ var init_router = __esm({
38892
39264
  case "daemon_upgrade": {
38893
39265
  LOG.info("Upgrade", "Remote upgrade requested from dashboard");
38894
39266
  try {
38895
- const { execSync: execSync7 } = await import("child_process");
38896
39267
  const isStandalone = this.deps.packageName === "@adhdev/daemon-standalone" || process.argv[1]?.includes("daemon-standalone");
38897
39268
  const pkgName = isStandalone ? "@adhdev/daemon-standalone" : "adhdev";
38898
- const latest = execSync7(`npm view ${pkgName} version`, { encoding: "utf-8", timeout: 1e4 }).trim();
39269
+ const npmSurface = resolveCurrentGlobalInstallSurface({ packageName: pkgName });
39270
+ const latest = String(execNpmCommandSync(["view", pkgName, "version"], { encoding: "utf-8", timeout: 1e4 }, npmSurface)).trim();
38899
39271
  LOG.info("Upgrade", `Latest ${pkgName}: v${latest}`);
38900
39272
  let currentInstalled = null;
38901
39273
  try {
38902
- const currentJson = execSync7(`npm ls -g ${pkgName} --depth=0 --json`, {
39274
+ const currentJson = String(execNpmCommandSync(["ls", "-g", pkgName, "--depth=0", "--json"], {
38903
39275
  encoding: "utf-8",
38904
39276
  timeout: 1e4,
38905
39277
  stdio: ["pipe", "pipe", "pipe"]
38906
- }).trim();
39278
+ }, npmSurface)).trim();
38907
39279
  const parsed = JSON.parse(currentJson);
38908
39280
  currentInstalled = parsed?.dependencies?.[pkgName]?.version || null;
38909
39281
  } catch {
@@ -47152,6 +47524,7 @@ __export(src_exports, {
47152
47524
  detectCLIs: () => detectCLIs,
47153
47525
  detectIDEs: () => detectIDEs,
47154
47526
  ensureSessionHostReady: () => ensureSessionHostReady,
47527
+ execNpmCommandSync: () => execNpmCommandSync,
47155
47528
  findCdpManager: () => findCdpManager,
47156
47529
  flattenMessageParts: () => flattenMessageParts,
47157
47530
  forwardAgentStreamsToIdeInstance: () => forwardAgentStreamsToIdeInstance,
@@ -47162,6 +47535,7 @@ __export(src_exports, {
47162
47535
  getDebugRuntimeConfig: () => getDebugRuntimeConfig,
47163
47536
  getHostMemorySnapshot: () => getHostMemorySnapshot,
47164
47537
  getLogLevel: () => getLogLevel,
47538
+ getNpmExecOptions: () => getNpmExecOptions,
47165
47539
  getRecentActivity: () => getRecentActivity,
47166
47540
  getRecentCommands: () => getRecentCommands,
47167
47541
  getRecentDebugTrace: () => getRecentDebugTrace,
@@ -56702,12 +57076,15 @@ function verifyPublishedMandatoryUpdateTarget(packageName, targetVersion, deps =
56702
57076
  const validation = validateMandatoryUpdateTarget(targetVersion);
56703
57077
  if (!validation.valid) throw new Error(validation.error || "invalid mandatory update target");
56704
57078
  const run = deps.execFileSync || import_child_process13.execFileSync;
56705
- const npmExecutable = deps.npmExecutable || resolveCurrentGlobalInstallSurface({ packageName }).npmExecutable;
56706
- const published = String(run(npmExecutable, ["view", `${packageName}@${targetVersion}`, "version"], {
57079
+ const surface = resolveCurrentGlobalInstallSurface({ packageName });
57080
+ const npmExecutable = deps.npmExecutable || surface.npmExecutable;
57081
+ const npmArgsPrefix = deps.npmArgsPrefix || surface.npmArgsPrefix || [];
57082
+ const execOptions = deps.execOptions || surface.execOptions || {};
57083
+ const published = String(run(npmExecutable, [...npmArgsPrefix, "view", `${packageName}@${targetVersion}`, "version"], {
56707
57084
  encoding: "utf-8",
56708
57085
  timeout: 1e4,
56709
57086
  stdio: ["pipe", "pipe", "pipe"],
56710
- ...process.platform === "win32" ? { shell: true, windowsHide: true } : {}
57087
+ ...execOptions
56711
57088
  })).trim();
56712
57089
  if (published !== targetVersion) {
56713
57090
  throw new Error(`Published version mismatch: expected ${targetVersion}, got ${published || "unknown"}`);
@@ -56914,7 +57291,7 @@ var init_adhdev_daemon = __esm({
56914
57291
  init_version();
56915
57292
  init_src();
56916
57293
  init_runtime_defaults();
56917
- pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.47" });
57294
+ pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.49" });
56918
57295
  AdhdevDaemon = class _AdhdevDaemon {
56919
57296
  localHttpServer = null;
56920
57297
  localWss = null;
@@ -88585,10 +88962,11 @@ function hasCloudMachineAuth() {
88585
88962
  function readLatestPublishedCliVersion(execFileSyncLocal) {
88586
88963
  const surface = resolveCurrentGlobalInstallSurface({ packageName: "adhdev" });
88587
88964
  try {
88588
- return execFileSyncLocal(surface.npmExecutable, ["view", "adhdev", "version"], {
88965
+ return execFileSyncLocal(surface.npmExecutable, [...surface.npmArgsPrefix || [], "view", "adhdev", "version"], {
88589
88966
  encoding: "utf-8",
88590
88967
  timeout: 5e3,
88591
- stdio: ["pipe", "pipe", "pipe"]
88968
+ stdio: ["pipe", "pipe", "pipe"],
88969
+ ...surface.execOptions
88592
88970
  }).trim();
88593
88971
  } catch {
88594
88972
  return null;
@@ -88596,7 +88974,7 @@ function readLatestPublishedCliVersion(execFileSyncLocal) {
88596
88974
  }
88597
88975
  function readInstalledGlobalCliVersion(execFileSyncLocal) {
88598
88976
  const surface = resolveCurrentGlobalInstallSurface({ packageName: "adhdev" });
88599
- const args = ["list", "-g", "adhdev", "--json"];
88977
+ const args = [...surface.npmArgsPrefix || [], "list", "-g", "adhdev", "--json"];
88600
88978
  if (surface.installPrefix) {
88601
88979
  args.push("--prefix", surface.installPrefix);
88602
88980
  }
@@ -88604,7 +88982,8 @@ function readInstalledGlobalCliVersion(execFileSyncLocal) {
88604
88982
  const result = execFileSyncLocal(surface.npmExecutable, args, {
88605
88983
  encoding: "utf-8",
88606
88984
  timeout: 5e3,
88607
- stdio: ["pipe", "pipe", "pipe"]
88985
+ stdio: ["pipe", "pipe", "pipe"],
88986
+ ...surface.execOptions
88608
88987
  });
88609
88988
  const parsed = JSON.parse(result);
88610
88989
  return parsed.dependencies?.adhdev?.version || null;
@@ -88649,7 +89028,8 @@ async function checkForUpdate() {
88649
89028
  execFileSync5(installCommand.command, installCommand.args, {
88650
89029
  encoding: "utf-8",
88651
89030
  timeout: 6e4,
88652
- stdio: ["pipe", "pipe", "pipe"]
89031
+ stdio: ["pipe", "pipe", "pipe"],
89032
+ ...installCommand.execOptions
88653
89033
  });
88654
89034
  spinner.succeed(`Updated to v${latestVersion}`);
88655
89035
  console.log();
@@ -88935,7 +89315,8 @@ async function installCliOnly() {
88935
89315
  execFileSyncLocal(installCommand.command, installCommand.args, {
88936
89316
  encoding: "utf-8",
88937
89317
  timeout: 6e4,
88938
- stdio: ["pipe", "pipe", "pipe"]
89318
+ stdio: ["pipe", "pipe", "pipe"],
89319
+ ...installCommand.execOptions
88939
89320
  });
88940
89321
  const newVersion = readInstalledGlobalCliVersion(execFileSyncLocal) || "latest";
88941
89322
  installSpinner.succeed(`adhdev CLI ${currentVersion ? "updated" : "installed"} \u2713 (v${newVersion})`);