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/cli/index.js CHANGED
@@ -1495,7 +1495,11 @@ function resolveCommandPath(command) {
1495
1495
  }
1496
1496
  function execAsync(cmd, timeoutMs = 5e3) {
1497
1497
  return new Promise((resolve18) => {
1498
- const child = (0, import_child_process2.exec)(cmd, { encoding: "utf-8", timeout: timeoutMs }, (err, stdout) => {
1498
+ const child = (0, import_child_process2.exec)(cmd, {
1499
+ encoding: "utf-8",
1500
+ timeout: timeoutMs,
1501
+ ...process.platform === "win32" ? { windowsHide: true } : {}
1502
+ }, (err, stdout) => {
1499
1503
  if (err || !stdout?.trim()) {
1500
1504
  resolve18(null);
1501
1505
  } else {
@@ -8106,6 +8110,238 @@ function buildReadChatCommandResult(payload, args) {
8106
8110
  ...debugReadChat ? { debugReadChat } : {}
8107
8111
  };
8108
8112
  }
8113
+ function truncateDebugString(value, maxLength) {
8114
+ if (value.length <= maxLength) return value;
8115
+ return `${value.slice(0, maxLength)}\u2026[truncated ${value.length - maxLength} chars]`;
8116
+ }
8117
+ function redactDebugSecrets(value) {
8118
+ 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]");
8119
+ }
8120
+ function sanitizeDebugBundleValue(value, options = {}, depth = 0, keyHint = "") {
8121
+ const normalizedOptions = { ...DEFAULT_DEBUG_SANITIZE_OPTIONS, ...options };
8122
+ if (value === null || value === void 0) return value;
8123
+ if (typeof value === "number" || typeof value === "boolean") return value;
8124
+ if (typeof value === "bigint") return String(value);
8125
+ if (typeof value === "string") {
8126
+ if (SECRET_KEY_PATTERN.test(keyHint) && value.trim()) return "[REDACTED:secret-field]";
8127
+ return truncateDebugString(redactDebugSecrets(value), normalizedOptions.maxStringLength);
8128
+ }
8129
+ if (typeof value === "function") return `[Function ${value.name || "anonymous"}]`;
8130
+ if (typeof value !== "object") return String(value);
8131
+ if (depth >= normalizedOptions.maxDepth) return "[MaxDepth]";
8132
+ if (Array.isArray(value)) {
8133
+ const items = value.slice(0, normalizedOptions.maxArrayLength).map((item) => sanitizeDebugBundleValue(item, normalizedOptions, depth + 1, keyHint));
8134
+ if (value.length > normalizedOptions.maxArrayLength) {
8135
+ items.push(`[truncated ${value.length - normalizedOptions.maxArrayLength} items]`);
8136
+ }
8137
+ return items;
8138
+ }
8139
+ const record2 = value;
8140
+ const result = {};
8141
+ const entries = Object.entries(record2).slice(0, normalizedOptions.maxObjectKeys);
8142
+ for (const [key, item] of entries) {
8143
+ result[key] = sanitizeDebugBundleValue(item, normalizedOptions, depth + 1, key);
8144
+ }
8145
+ const remaining = Object.keys(record2).length - entries.length;
8146
+ if (remaining > 0) result.__truncatedKeys = remaining;
8147
+ return result;
8148
+ }
8149
+ function summarizeProviderForDebug(provider) {
8150
+ if (!provider) return null;
8151
+ const scripts = provider.scripts && typeof provider.scripts === "object" ? Object.keys(provider.scripts) : [];
8152
+ const controls = Array.isArray(provider.controls) ? provider.controls.map((control) => ({
8153
+ id: control?.id,
8154
+ label: control?.label,
8155
+ type: control?.type,
8156
+ settingKey: control?.settingKey,
8157
+ invokeScript: control?.invokeScript,
8158
+ listScript: control?.listScript,
8159
+ location: control?.location
8160
+ })) : [];
8161
+ return {
8162
+ type: provider.type,
8163
+ name: provider.name,
8164
+ category: provider.category,
8165
+ version: provider.version,
8166
+ canonicalHistory: provider.canonicalHistory,
8167
+ historyBehavior: provider.historyBehavior,
8168
+ webviewMatchText: provider.webviewMatchText,
8169
+ scriptNames: scripts,
8170
+ controls,
8171
+ resume: provider.resume
8172
+ };
8173
+ }
8174
+ function summarizeSessionForDebug(session) {
8175
+ if (!session || typeof session !== "object") return null;
8176
+ return {
8177
+ sessionId: session.sessionId,
8178
+ instanceKey: session.instanceKey,
8179
+ adapterKey: session.adapterKey,
8180
+ providerType: session.providerType,
8181
+ providerName: session.providerName,
8182
+ transport: session.transport,
8183
+ kind: session.kind,
8184
+ cdpManagerKey: session.cdpManagerKey,
8185
+ parentSessionId: session.parentSessionId,
8186
+ providerSessionId: session.providerSessionId,
8187
+ workspace: session.workspace,
8188
+ title: session.title,
8189
+ status: session.status,
8190
+ mode: session.mode,
8191
+ capabilities: session.capabilities
8192
+ };
8193
+ }
8194
+ function summarizeStateForDebug(state) {
8195
+ if (!state || typeof state !== "object") return null;
8196
+ const activeChat = state.activeChat && typeof state.activeChat === "object" ? state.activeChat : null;
8197
+ return {
8198
+ type: state.type,
8199
+ name: state.name,
8200
+ category: state.category,
8201
+ status: state.status,
8202
+ instanceId: state.instanceId,
8203
+ providerSessionId: state.providerSessionId,
8204
+ title: state.title,
8205
+ transport: state.transport,
8206
+ mode: state.mode,
8207
+ workspace: state.workspace,
8208
+ runtime: state.runtime,
8209
+ errorMessage: state.errorMessage,
8210
+ errorReason: state.errorReason,
8211
+ activeChat: activeChat ? {
8212
+ status: activeChat.status,
8213
+ title: activeChat.title,
8214
+ messageCount: Array.isArray(activeChat.messages) ? activeChat.messages.length : void 0,
8215
+ activeModal: activeChat.activeModal,
8216
+ messagesTail: Array.isArray(activeChat.messages) ? activeChat.messages.slice(-10) : void 0
8217
+ } : null,
8218
+ controlValues: state.controlValues,
8219
+ summaryMetadata: state.summaryMetadata
8220
+ };
8221
+ }
8222
+ function buildDebugBundleText(bundle) {
8223
+ return [
8224
+ "# ADHDev Chat Debug Bundle",
8225
+ "",
8226
+ "```json",
8227
+ JSON.stringify(bundle, null, 2),
8228
+ "```"
8229
+ ].join("\n");
8230
+ }
8231
+ async function handleGetChatDebugBundle(h, args) {
8232
+ const provider = h.getProvider(args?.agentType);
8233
+ const transport = getTargetTransport(h, provider);
8234
+ const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
8235
+ const providerType = provider?.type || getCurrentProviderType(h, args?.agentType || "");
8236
+ const adapter = isCliLikeTransport(transport) ? getTargetedCliAdapter(h, args, provider?.type) : null;
8237
+ const targetInstance = getTargetInstance(h, args);
8238
+ let adapterStatus = null;
8239
+ let parsedStatus = null;
8240
+ let adapterDebugSnapshot = null;
8241
+ let partialResponse = "";
8242
+ if (adapter) {
8243
+ try {
8244
+ adapterStatus = adapter.getStatus?.();
8245
+ } catch (error48) {
8246
+ adapterStatus = { error: error48?.message || String(error48) };
8247
+ }
8248
+ try {
8249
+ parsedStatus = typeof adapter.getScriptParsedStatus === "function" ? parseMaybeJson(adapter.getScriptParsedStatus()) : null;
8250
+ } catch (error48) {
8251
+ parsedStatus = { error: error48?.message || String(error48) };
8252
+ }
8253
+ try {
8254
+ adapterDebugSnapshot = typeof adapter.getDebugSnapshot === "function" ? adapter.getDebugSnapshot() : null;
8255
+ } catch (error48) {
8256
+ adapterDebugSnapshot = { error: error48?.message || String(error48) };
8257
+ }
8258
+ try {
8259
+ partialResponse = adapter.getPartialResponse?.() || "";
8260
+ } catch {
8261
+ partialResponse = "";
8262
+ }
8263
+ }
8264
+ let instanceState = null;
8265
+ if (targetInstance?.getState) {
8266
+ try {
8267
+ instanceState = summarizeStateForDebug(targetInstance.getState());
8268
+ } catch (error48) {
8269
+ instanceState = { error: error48?.message || String(error48) };
8270
+ }
8271
+ }
8272
+ let readChat = null;
8273
+ try {
8274
+ const readResult = await handleReadChat(h, { ...args, tailLimit: Math.max(1, Math.min(40, Number(args?.tailLimit || 40))) });
8275
+ readChat = readResult.success ? {
8276
+ success: true,
8277
+ status: readResult.status,
8278
+ title: readResult.title,
8279
+ totalMessages: readResult.totalMessages,
8280
+ returnedMessages: Array.isArray(readResult.messages) ? readResult.messages.length : void 0,
8281
+ syncMode: readResult.syncMode,
8282
+ replaceFrom: readResult.replaceFrom,
8283
+ lastMessageSignature: readResult.lastMessageSignature,
8284
+ providerSessionId: readResult.providerSessionId,
8285
+ transcriptAuthority: readResult.transcriptAuthority,
8286
+ coverage: readResult.coverage,
8287
+ activeModal: readResult.activeModal,
8288
+ messagesTail: Array.isArray(readResult.messages) ? readResult.messages.slice(-20) : [],
8289
+ debugReadChat: readResult.debugReadChat
8290
+ } : { success: false, error: readResult.error };
8291
+ } catch (error48) {
8292
+ readChat = { success: false, error: error48?.message || String(error48) };
8293
+ }
8294
+ const cdp = h.getCdp();
8295
+ const rawBundle = {
8296
+ version: 1,
8297
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
8298
+ target: {
8299
+ targetSessionId,
8300
+ providerType,
8301
+ transport,
8302
+ routeManagerKey: h.currentManagerKey,
8303
+ currentIdeType: h.currentIdeType
8304
+ },
8305
+ session: summarizeSessionForDebug(h.currentSession),
8306
+ provider: summarizeProviderForDebug(provider),
8307
+ daemon: {
8308
+ pid: process.pid,
8309
+ platform: process.platform,
8310
+ nodeVersion: process.version,
8311
+ cwd: process.cwd()
8312
+ },
8313
+ cdp: {
8314
+ requested: !!cdp,
8315
+ connected: !!cdp?.isConnected,
8316
+ managerKey: getCurrentManagerKey(h)
8317
+ },
8318
+ instanceState,
8319
+ cli: adapter ? {
8320
+ cliType: adapter.cliType,
8321
+ cliName: adapter.cliName,
8322
+ workingDir: adapter.workingDir,
8323
+ status: adapterStatus?.status,
8324
+ activeModal: adapterStatus?.activeModal,
8325
+ messageCount: Array.isArray(adapterStatus?.messages) ? adapterStatus.messages.length : void 0,
8326
+ messagesTail: Array.isArray(adapterStatus?.messages) ? adapterStatus.messages.slice(-20) : void 0,
8327
+ parsedStatus,
8328
+ partialResponse,
8329
+ ready: typeof adapter.isReady === "function" ? adapter.isReady() : void 0,
8330
+ processing: typeof adapter.isProcessing === "function" ? adapter.isProcessing() : void 0,
8331
+ debugSnapshot: adapterDebugSnapshot
8332
+ } : null,
8333
+ readChat,
8334
+ frontend: args?.frontendSnapshot && typeof args.frontendSnapshot === "object" ? args.frontendSnapshot : null,
8335
+ recentLogs: getRecentLogs(80, "debug"),
8336
+ recentDebugTrace: getRecentDebugTrace({ limit: 120 })
8337
+ };
8338
+ const bundle = sanitizeDebugBundleValue(rawBundle);
8339
+ return {
8340
+ success: true,
8341
+ bundle,
8342
+ text: buildDebugBundleText(bundle)
8343
+ };
8344
+ }
8109
8345
  function didProviderConfirmSend(result) {
8110
8346
  const parsed = parseMaybeJson(result);
8111
8347
  if (parsed === true) return true;
@@ -9079,7 +9315,7 @@ async function handleResolveAction(h, args) {
9079
9315
  }
9080
9316
  return { success: false, error: "resolveAction script not available for this provider" };
9081
9317
  }
9082
- var RECENT_SEND_WINDOW_MS, READ_CHAT_PROVIDER_EVAL_TIMEOUT_MS, recentSendByTarget;
9318
+ var RECENT_SEND_WINDOW_MS, READ_CHAT_PROVIDER_EVAL_TIMEOUT_MS, recentSendByTarget, DEFAULT_DEBUG_SANITIZE_OPTIONS, SECRET_KEY_PATTERN;
9083
9319
  var init_chat_commands = __esm({
9084
9320
  "../../oss/packages/daemon-core/src/commands/chat-commands.ts"() {
9085
9321
  "use strict";
@@ -9094,6 +9330,13 @@ var init_chat_commands = __esm({
9094
9330
  RECENT_SEND_WINDOW_MS = 1200;
9095
9331
  READ_CHAT_PROVIDER_EVAL_TIMEOUT_MS = 25e3;
9096
9332
  recentSendByTarget = /* @__PURE__ */ new Map();
9333
+ DEFAULT_DEBUG_SANITIZE_OPTIONS = {
9334
+ maxDepth: 8,
9335
+ maxArrayLength: 80,
9336
+ maxObjectKeys: 120,
9337
+ maxStringLength: 16e3
9338
+ };
9339
+ SECRET_KEY_PATTERN = /(?:token|secret|password|passwd|authorization|cookie|api[_-]?key|access[_-]?key|refresh[_-]?token|client[_-]?secret|private[_-]?key)/i;
9097
9340
  }
9098
9341
  });
9099
9342
 
@@ -9522,7 +9765,8 @@ function getCliScriptCommand(payload) {
9522
9765
  if (command.type !== "send_message" && command.type !== "pty_write") return null;
9523
9766
  const text = typeof command.text === "string" ? command.text.trim() : typeof command.message === "string" ? command.message.trim() : "";
9524
9767
  if (!text) return null;
9525
- return { type: command.type, text };
9768
+ const enterCount = Number.isInteger(command.enterCount) && command.enterCount > 0 && command.enterCount <= 5 ? command.enterCount : void 0;
9769
+ return { type: command.type, text, ...enterCount ? { enterCount } : {} };
9526
9770
  }
9527
9771
  var init_cli_script_results = __esm({
9528
9772
  "../../oss/packages/daemon-core/src/providers/cli-script-results.ts"() {
@@ -9784,7 +10028,12 @@ async function executeProviderScript(h, args, scriptName) {
9784
10028
  if (cliCommand?.type === "send_message" && cliCommand.text) {
9785
10029
  await adapter.sendMessage(cliCommand.text);
9786
10030
  } else if (cliCommand?.type === "pty_write" && cliCommand.text && adapter.writeRaw) {
10031
+ const enterCount = cliCommand.enterCount || 1;
9787
10032
  await adapter.writeRaw(cliCommand.text + "\r");
10033
+ for (let i = 1; i < enterCount; i += 1) {
10034
+ await new Promise((resolve18) => setTimeout(resolve18, 50));
10035
+ await adapter.writeRaw("\r");
10036
+ }
9788
10037
  }
9789
10038
  applyProviderPatch(h, args, parsed.payload);
9790
10039
  return {
@@ -10355,6 +10604,8 @@ var init_handler = __esm({
10355
10604
  // ─── Chat commands (chat-commands.ts) ───────────────
10356
10605
  case "read_chat":
10357
10606
  return handleReadChat(this, args);
10607
+ case "get_chat_debug_bundle":
10608
+ return handleGetChatDebugBundle(this, args);
10358
10609
  case "chat_history":
10359
10610
  return handleChatHistory(this, args);
10360
10611
  case "send_chat":
@@ -12144,7 +12395,12 @@ function findBinary(name) {
12144
12395
  const isWin = os11.platform() === "win32";
12145
12396
  try {
12146
12397
  const cmd = isWin ? `where ${trimmed}` : `which ${trimmed}`;
12147
- return (0, import_child_process4.execSync)(cmd, { encoding: "utf-8", timeout: 5e3, stdio: ["pipe", "pipe", "pipe"] }).trim().split("\n")[0].trim();
12398
+ return (0, import_child_process4.execSync)(cmd, {
12399
+ encoding: "utf-8",
12400
+ timeout: 5e3,
12401
+ stdio: ["pipe", "pipe", "pipe"],
12402
+ ...isWin ? { windowsHide: true } : {}
12403
+ }).trim().split("\n")[0].trim();
12148
12404
  } catch {
12149
12405
  return isWin ? `${trimmed}.cmd` : trimmed;
12150
12406
  }
@@ -14829,6 +15085,83 @@ var init_provider_cli_adapter = __esm({
14829
15085
  if (!this.isWaitingForResponse) return "";
14830
15086
  return this.responseBuffer;
14831
15087
  }
15088
+ getDebugSnapshot() {
15089
+ const screenText = this.readTerminalScreenText();
15090
+ const parsedResult = this.parsedStatusCache?.result && typeof this.parsedStatusCache.result === "object" ? this.parsedStatusCache.result : null;
15091
+ return {
15092
+ cliType: this.cliType,
15093
+ cliName: this.cliName,
15094
+ workingDir: this.workingDir,
15095
+ currentStatus: this.currentStatus,
15096
+ ready: this.ready,
15097
+ isWaitingForResponse: this.isWaitingForResponse,
15098
+ activeModal: this.activeModal,
15099
+ parseErrorMessage: this.parseErrorMessage,
15100
+ messageCounts: {
15101
+ committed: this.committedMessages.length,
15102
+ structured: this.structuredMessages.length,
15103
+ visible: this.messages.length,
15104
+ parsedCache: Array.isArray(parsedResult?.messages) ? parsedResult.messages.length : void 0
15105
+ },
15106
+ buffers: {
15107
+ accumulatedLength: this.accumulatedBuffer.length,
15108
+ accumulatedRawLength: this.accumulatedRawBuffer.length,
15109
+ recentOutputLength: this.recentOutputBuffer.length,
15110
+ responseLength: this.responseBuffer.length,
15111
+ startupLength: this.startupBuffer.length,
15112
+ accumulatedTail: this.accumulatedBuffer.slice(-24e3),
15113
+ accumulatedRawTail: this.accumulatedRawBuffer.slice(-24e3),
15114
+ recentOutputTail: this.recentOutputBuffer.slice(-12e3),
15115
+ responseTail: this.responseBuffer.slice(-12e3)
15116
+ },
15117
+ terminal: {
15118
+ screenText,
15119
+ lastScreenSnapshot: this.lastScreenSnapshot,
15120
+ lastScreenText: this.lastScreenText,
15121
+ lastOutputAt: this.lastOutputAt,
15122
+ lastNonEmptyOutputAt: this.lastNonEmptyOutputAt,
15123
+ lastScreenChangeAt: this.lastScreenChangeAt,
15124
+ lastScreenSnapshotReadAt: this.lastScreenSnapshotReadAt
15125
+ },
15126
+ parser: {
15127
+ scriptNames: listCliScriptNames(this.cliScripts),
15128
+ traceSessionId: this.traceSessionId,
15129
+ traceSeq: this.traceSeq,
15130
+ currentTurnScope: this.currentTurnScope,
15131
+ parsedStatusCache: parsedResult ? {
15132
+ id: parsedResult.id,
15133
+ status: parsedResult.status,
15134
+ title: parsedResult.title,
15135
+ providerSessionId: parsedResult.providerSessionId,
15136
+ transcriptAuthority: parsedResult.transcriptAuthority,
15137
+ coverage: parsedResult.coverage,
15138
+ messageCount: Array.isArray(parsedResult.messages) ? parsedResult.messages.length : void 0,
15139
+ activeModal: parsedResult.activeModal
15140
+ } : null,
15141
+ pendingScriptStatus: this.pendingScriptStatus,
15142
+ pendingScriptStatusSince: this.pendingScriptStatusSince
15143
+ },
15144
+ runtimeMetadata: this.getRuntimeMetadata(),
15145
+ statusHistory: this.statusHistory.slice(-80),
15146
+ traceEntries: this.traceEntries.slice(-120),
15147
+ timing: {
15148
+ spawnAt: this.spawnAt,
15149
+ startupFirstOutputAt: this.startupFirstOutputAt,
15150
+ submitPendingUntil: this.submitPendingUntil,
15151
+ responseSettleIgnoreUntil: this.responseSettleIgnoreUntil,
15152
+ responseEpoch: this.responseEpoch,
15153
+ resizeSuppressUntil: this.resizeSuppressUntil,
15154
+ lastApprovalResolvedAt: this.lastApprovalResolvedAt,
15155
+ committedMessagesChangedAt: this.committedMessagesChangedAt
15156
+ },
15157
+ finish: {
15158
+ idleFinishCandidate: this.idleFinishCandidate,
15159
+ finishRetryCount: this.finishRetryCount,
15160
+ submitRetryUsed: this.submitRetryUsed,
15161
+ submitRetryPromptSnippet: this.submitRetryPromptSnippet
15162
+ }
15163
+ };
15164
+ }
14832
15165
  getRuntimeMetadata() {
14833
15166
  if (!this.ptyProcess || typeof this.ptyProcess.getMetadata !== "function") return null;
14834
15167
  return this.ptyProcess.getMetadata();
@@ -15581,7 +15914,12 @@ var init_cli_provider_instance = __esm({
15581
15914
  if (cliCommand?.type === "send_message" && cliCommand.text) {
15582
15915
  await this.adapter.sendMessage(cliCommand.text);
15583
15916
  } else if (cliCommand?.type === "pty_write" && cliCommand.text) {
15917
+ const enterCount = cliCommand.enterCount || 1;
15584
15918
  await this.adapter.writeRaw(cliCommand.text + "\r");
15919
+ for (let i = 1; i < enterCount; i += 1) {
15920
+ await new Promise((resolve18) => setTimeout(resolve18, 50));
15921
+ await this.adapter.writeRaw("\r");
15922
+ }
15585
15923
  }
15586
15924
  this.applyProviderResponse(parsed.payload, { phase: "immediate" });
15587
15925
  }
@@ -32900,7 +33238,8 @@ var init_acp_provider_instance = __esm({
32900
33238
  cwd: this.workingDir,
32901
33239
  env: env3,
32902
33240
  stdio: ["pipe", "pipe", "pipe"],
32903
- shell: spawnConfig.shell || false
33241
+ shell: spawnConfig.shell || false,
33242
+ ...process.platform === "win32" ? { windowsHide: true } : {}
32904
33243
  });
32905
33244
  const AUTH_ERROR_PATTERNS = [
32906
33245
  /unauthorized|unauthenticated/i,
@@ -33599,7 +33938,10 @@ function commandExists(command) {
33599
33938
  return (0, import_fs5.existsSync)(expandExecutable(trimmed));
33600
33939
  }
33601
33940
  try {
33602
- (0, import_child_process6.execFileSync)(process.platform === "win32" ? "where" : "which", [trimmed], { stdio: "ignore" });
33941
+ (0, import_child_process6.execFileSync)(process.platform === "win32" ? "where" : "which", [trimmed], {
33942
+ stdio: "ignore",
33943
+ ...process.platform === "win32" ? { windowsHide: true } : {}
33944
+ });
33603
33945
  return true;
33604
33946
  } catch {
33605
33947
  return false;
@@ -38318,7 +38660,7 @@ async function launchMacOS(ide, port, workspace, newWindow) {
38318
38660
  const canUseAppLauncher = !!appName;
38319
38661
  const useAppLauncher = preferredMethod === "app" ? canUseAppLauncher : preferredMethod === "cli" ? false : !canUseCli && canUseAppLauncher;
38320
38662
  if (!useAppLauncher && ide.cliCommand) {
38321
- (0, import_child_process7.spawn)(ide.cliCommand, args, { detached: true, stdio: "ignore" }).unref();
38663
+ (0, import_child_process7.spawn)(ide.cliCommand, args, { detached: true, stdio: "ignore", windowsHide: true }).unref();
38322
38664
  } else if (appName) {
38323
38665
  const openArgs = ["-a", appName, "--args", ...args];
38324
38666
  (0, import_child_process7.spawn)("open", openArgs, { detached: true, stdio: "ignore" }).unref();
@@ -38347,7 +38689,7 @@ async function launchLinux(ide, port, workspace, newWindow) {
38347
38689
  const args = ["--remote-debugging-port=" + port];
38348
38690
  if (newWindow) args.push("--new-window");
38349
38691
  if (workspace) args.push(workspace);
38350
- (0, import_child_process7.spawn)(cli, args, { detached: true, stdio: "ignore" }).unref();
38692
+ (0, import_child_process7.spawn)(cli, args, { detached: true, stdio: "ignore", windowsHide: true }).unref();
38351
38693
  }
38352
38694
  function getAvailableIdeIds() {
38353
38695
  return getProviderLoader().getAvailableIdeTypes();
@@ -38851,16 +39193,28 @@ function appendUpgradeLog(message) {
38851
39193
  } catch {
38852
39194
  }
38853
39195
  }
38854
- function resolveSiblingNpmExecutable(nodeExecutable) {
39196
+ function resolveSiblingNpmInvocation(nodeExecutable, platform12 = process.platform) {
38855
39197
  const binDir = path17.dirname(nodeExecutable);
38856
- const candidates = process.platform === "win32" ? ["npm.cmd", "npm.exe", "npm"] : ["npm"];
38857
- for (const candidate of candidates) {
39198
+ if (platform12 === "win32") {
39199
+ const npmCliPath = path17.join(binDir, "node_modules", "npm", "bin", "npm-cli.js");
39200
+ if (fs8.existsSync(npmCliPath)) {
39201
+ return { executable: nodeExecutable, argsPrefix: [npmCliPath], execOptions: getNpmExecOptions(platform12) };
39202
+ }
39203
+ for (const candidate of ["npm.exe", "npm"]) {
39204
+ const candidatePath = path17.join(binDir, candidate);
39205
+ if (fs8.existsSync(candidatePath)) {
39206
+ return { executable: candidatePath, argsPrefix: [], execOptions: getNpmExecOptions(platform12) };
39207
+ }
39208
+ }
39209
+ return { executable: nodeExecutable, argsPrefix: [npmCliPath], execOptions: getNpmExecOptions(platform12) };
39210
+ }
39211
+ for (const candidate of ["npm"]) {
38858
39212
  const candidatePath = path17.join(binDir, candidate);
38859
39213
  if (fs8.existsSync(candidatePath)) {
38860
- return candidatePath;
39214
+ return { executable: candidatePath, argsPrefix: [], execOptions: getNpmExecOptions(platform12) };
38861
39215
  }
38862
39216
  }
38863
- return "npm";
39217
+ return { executable: "npm", argsPrefix: [], execOptions: getNpmExecOptions(platform12) };
38864
39218
  }
38865
39219
  function findCurrentPackageRoot(currentCliPath, packageName) {
38866
39220
  if (!currentCliPath) return null;
@@ -38909,31 +39263,50 @@ function resolveInstallPrefixFromPackageRoot(packageRoot, packageName) {
38909
39263
  }
38910
39264
  function resolveCurrentGlobalInstallSurface(options) {
38911
39265
  const packageRoot = findCurrentPackageRoot(options.currentCliPath || process.argv[1], options.packageName);
39266
+ const npmInvocation = resolveSiblingNpmInvocation(options.nodeExecutable || process.execPath, options.platform);
38912
39267
  return {
38913
- npmExecutable: resolveSiblingNpmExecutable(options.nodeExecutable || process.execPath),
39268
+ npmExecutable: npmInvocation.executable,
39269
+ npmArgsPrefix: npmInvocation.argsPrefix,
38914
39270
  packageRoot,
38915
- installPrefix: packageRoot ? resolveInstallPrefixFromPackageRoot(packageRoot, options.packageName) : null
39271
+ installPrefix: packageRoot ? resolveInstallPrefixFromPackageRoot(packageRoot, options.packageName) : null,
39272
+ execOptions: npmInvocation.execOptions
38916
39273
  };
38917
39274
  }
38918
39275
  function buildPinnedGlobalInstallCommand(options) {
38919
39276
  const surface = resolveCurrentGlobalInstallSurface(options);
38920
- const args = ["install", "-g", `${options.packageName}@${options.targetVersion || "latest"}`, "--force"];
39277
+ const args = [...surface.npmArgsPrefix || [], "install", "-g", `${options.packageName}@${options.targetVersion || "latest"}`, "--force"];
38921
39278
  if (surface.installPrefix) {
38922
39279
  args.push("--prefix", surface.installPrefix);
38923
39280
  }
38924
39281
  return {
38925
39282
  command: surface.npmExecutable,
38926
39283
  args,
38927
- surface
39284
+ surface,
39285
+ execOptions: surface.execOptions || getNpmExecOptions(options.platform)
38928
39286
  };
38929
39287
  }
38930
- function getNpmExecOptions() {
38931
- return { shell: process.platform === "win32" };
39288
+ function getNpmExecOptions(platform12 = process.platform) {
39289
+ if (platform12 === "win32") {
39290
+ return { shell: false, windowsHide: true };
39291
+ }
39292
+ return { shell: false };
39293
+ }
39294
+ function execNpmCommandSync(args, options = {}, surface) {
39295
+ const execOptions = surface?.execOptions || getNpmExecOptions();
39296
+ return (0, import_child_process8.execFileSync)(
39297
+ surface?.npmExecutable || "npm",
39298
+ [...surface?.npmArgsPrefix || [], ...args],
39299
+ {
39300
+ ...options,
39301
+ ...execOptions,
39302
+ ...process.platform === "win32" ? { windowsHide: true } : {}
39303
+ }
39304
+ );
38932
39305
  }
38933
39306
  function killPid(pid) {
38934
39307
  try {
38935
39308
  if (process.platform === "win32") {
38936
- (0, import_child_process8.execFileSync)("taskkill", ["/PID", String(pid), "/T", "/F"], { stdio: "ignore" });
39309
+ (0, import_child_process8.execFileSync)("taskkill", ["/PID", String(pid), "/T", "/F"], { stdio: "ignore", windowsHide: true });
38937
39310
  } else {
38938
39311
  process.kill(pid, "SIGTERM");
38939
39312
  }
@@ -38952,7 +39325,7 @@ function getWindowsProcessCommandLine(pid) {
38952
39325
  "Bypass",
38953
39326
  "-Command",
38954
39327
  `(Get-CimInstance Win32_Process -Filter "${pidFilter}").CommandLine`
38955
- ], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"] }).trim();
39328
+ ], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"], windowsHide: true }).trim();
38956
39329
  if (psOut) return psOut;
38957
39330
  } catch {
38958
39331
  }
@@ -38963,7 +39336,7 @@ function getWindowsProcessCommandLine(pid) {
38963
39336
  pidFilter,
38964
39337
  "get",
38965
39338
  "CommandLine"
38966
- ], { encoding: "utf8", timeout: 3e3, stdio: ["ignore", "pipe", "ignore"] }).trim();
39339
+ ], { encoding: "utf8", timeout: 3e3, stdio: ["ignore", "pipe", "ignore"], windowsHide: true }).trim();
38967
39340
  if (wmicOut) return wmicOut;
38968
39341
  } catch {
38969
39342
  }
@@ -39023,11 +39396,10 @@ function removeDaemonPidFile() {
39023
39396
  }
39024
39397
  }
39025
39398
  function cleanupStaleGlobalInstallDirs(pkgName, surface) {
39026
- const npmExecOpts = getNpmExecOptions();
39027
39399
  const prefixArgs = surface.installPrefix ? ["--prefix", surface.installPrefix] : [];
39028
- const npmRoot = (0, import_child_process8.execFileSync)(surface.npmExecutable, ["root", "-g", ...prefixArgs], { encoding: "utf8", ...npmExecOpts }).trim();
39400
+ const npmRoot = String(execNpmCommandSync(["root", "-g", ...prefixArgs], { encoding: "utf8" }, surface)).trim();
39029
39401
  if (!npmRoot) return;
39030
- const npmPrefix = surface.installPrefix || (0, import_child_process8.execFileSync)(surface.npmExecutable, ["prefix", "-g", ...prefixArgs], { encoding: "utf8", ...npmExecOpts }).trim();
39402
+ const npmPrefix = surface.installPrefix || String(execNpmCommandSync(["prefix", "-g", ...prefixArgs], { encoding: "utf8" }, surface)).trim();
39031
39403
  const binDir = process.platform === "win32" ? npmPrefix : path17.join(npmPrefix, "bin");
39032
39404
  const packageBaseName = pkgName.startsWith("@") ? pkgName.split("/")[1] : pkgName;
39033
39405
  const binNames = /* @__PURE__ */ new Set([packageBaseName]);
@@ -39097,7 +39469,7 @@ async function runDaemonUpgradeHelper(payload) {
39097
39469
  encoding: "utf8",
39098
39470
  stdio: "pipe",
39099
39471
  maxBuffer: 20 * 1024 * 1024,
39100
- ...getNpmExecOptions()
39472
+ ...installCommand.execOptions
39101
39473
  }
39102
39474
  );
39103
39475
  if (installOutput.trim()) {
@@ -39849,18 +40221,18 @@ var init_router = __esm({
39849
40221
  case "daemon_upgrade": {
39850
40222
  LOG.info("Upgrade", "Remote upgrade requested from dashboard");
39851
40223
  try {
39852
- const { execSync: execSync8 } = await import("child_process");
39853
40224
  const isStandalone = this.deps.packageName === "@adhdev/daemon-standalone" || process.argv[1]?.includes("daemon-standalone");
39854
40225
  const pkgName = isStandalone ? "@adhdev/daemon-standalone" : "adhdev";
39855
- const latest = execSync8(`npm view ${pkgName} version`, { encoding: "utf-8", timeout: 1e4 }).trim();
40226
+ const npmSurface = resolveCurrentGlobalInstallSurface({ packageName: pkgName });
40227
+ const latest = String(execNpmCommandSync(["view", pkgName, "version"], { encoding: "utf-8", timeout: 1e4 }, npmSurface)).trim();
39856
40228
  LOG.info("Upgrade", `Latest ${pkgName}: v${latest}`);
39857
40229
  let currentInstalled = null;
39858
40230
  try {
39859
- const currentJson = execSync8(`npm ls -g ${pkgName} --depth=0 --json`, {
40231
+ const currentJson = String(execNpmCommandSync(["ls", "-g", pkgName, "--depth=0", "--json"], {
39860
40232
  encoding: "utf-8",
39861
40233
  timeout: 1e4,
39862
40234
  stdio: ["pipe", "pipe", "pipe"]
39863
- }).trim();
40235
+ }, npmSurface)).trim();
39864
40236
  const parsed = JSON.parse(currentJson);
39865
40237
  currentInstalled = parsed?.dependencies?.[pkgName]?.version || null;
39866
40238
  } catch {
@@ -48109,6 +48481,7 @@ __export(src_exports, {
48109
48481
  detectCLIs: () => detectCLIs,
48110
48482
  detectIDEs: () => detectIDEs,
48111
48483
  ensureSessionHostReady: () => ensureSessionHostReady,
48484
+ execNpmCommandSync: () => execNpmCommandSync,
48112
48485
  findCdpManager: () => findCdpManager,
48113
48486
  flattenMessageParts: () => flattenMessageParts,
48114
48487
  forwardAgentStreamsToIdeInstance: () => forwardAgentStreamsToIdeInstance,
@@ -48119,6 +48492,7 @@ __export(src_exports, {
48119
48492
  getDebugRuntimeConfig: () => getDebugRuntimeConfig,
48120
48493
  getHostMemorySnapshot: () => getHostMemorySnapshot,
48121
48494
  getLogLevel: () => getLogLevel,
48495
+ getNpmExecOptions: () => getNpmExecOptions,
48122
48496
  getRecentActivity: () => getRecentActivity,
48123
48497
  getRecentCommands: () => getRecentCommands,
48124
48498
  getRecentDebugTrace: () => getRecentDebugTrace,
@@ -87844,12 +88218,15 @@ function verifyPublishedMandatoryUpdateTarget(packageName, targetVersion, deps =
87844
88218
  const validation = validateMandatoryUpdateTarget(targetVersion);
87845
88219
  if (!validation.valid) throw new Error(validation.error || "invalid mandatory update target");
87846
88220
  const run = deps.execFileSync || import_child_process14.execFileSync;
87847
- const npmExecutable = deps.npmExecutable || resolveCurrentGlobalInstallSurface({ packageName }).npmExecutable;
87848
- const published = String(run(npmExecutable, ["view", `${packageName}@${targetVersion}`, "version"], {
88221
+ const surface = resolveCurrentGlobalInstallSurface({ packageName });
88222
+ const npmExecutable = deps.npmExecutable || surface.npmExecutable;
88223
+ const npmArgsPrefix = deps.npmArgsPrefix || surface.npmArgsPrefix || [];
88224
+ const execOptions = deps.execOptions || surface.execOptions || {};
88225
+ const published = String(run(npmExecutable, [...npmArgsPrefix, "view", `${packageName}@${targetVersion}`, "version"], {
87849
88226
  encoding: "utf-8",
87850
88227
  timeout: 1e4,
87851
88228
  stdio: ["pipe", "pipe", "pipe"],
87852
- ...process.platform === "win32" ? { shell: true, windowsHide: true } : {}
88229
+ ...execOptions
87853
88230
  })).trim();
87854
88231
  if (published !== targetVersion) {
87855
88232
  throw new Error(`Published version mismatch: expected ${targetVersion}, got ${published || "unknown"}`);
@@ -88056,7 +88433,7 @@ var init_adhdev_daemon = __esm({
88056
88433
  init_version();
88057
88434
  init_src();
88058
88435
  init_runtime_defaults();
88059
- pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.47" });
88436
+ pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.49" });
88060
88437
  AdhdevDaemon = class _AdhdevDaemon {
88061
88438
  localHttpServer = null;
88062
88439
  localWss = null;
@@ -89191,10 +89568,11 @@ function hasCloudMachineAuth() {
89191
89568
  function readLatestPublishedCliVersion(execFileSyncLocal) {
89192
89569
  const surface = resolveCurrentGlobalInstallSurface({ packageName: "adhdev" });
89193
89570
  try {
89194
- return execFileSyncLocal(surface.npmExecutable, ["view", "adhdev", "version"], {
89571
+ return execFileSyncLocal(surface.npmExecutable, [...surface.npmArgsPrefix || [], "view", "adhdev", "version"], {
89195
89572
  encoding: "utf-8",
89196
89573
  timeout: 5e3,
89197
- stdio: ["pipe", "pipe", "pipe"]
89574
+ stdio: ["pipe", "pipe", "pipe"],
89575
+ ...surface.execOptions
89198
89576
  }).trim();
89199
89577
  } catch {
89200
89578
  return null;
@@ -89202,7 +89580,7 @@ function readLatestPublishedCliVersion(execFileSyncLocal) {
89202
89580
  }
89203
89581
  function readInstalledGlobalCliVersion(execFileSyncLocal) {
89204
89582
  const surface = resolveCurrentGlobalInstallSurface({ packageName: "adhdev" });
89205
- const args = ["list", "-g", "adhdev", "--json"];
89583
+ const args = [...surface.npmArgsPrefix || [], "list", "-g", "adhdev", "--json"];
89206
89584
  if (surface.installPrefix) {
89207
89585
  args.push("--prefix", surface.installPrefix);
89208
89586
  }
@@ -89210,7 +89588,8 @@ function readInstalledGlobalCliVersion(execFileSyncLocal) {
89210
89588
  const result = execFileSyncLocal(surface.npmExecutable, args, {
89211
89589
  encoding: "utf-8",
89212
89590
  timeout: 5e3,
89213
- stdio: ["pipe", "pipe", "pipe"]
89591
+ stdio: ["pipe", "pipe", "pipe"],
89592
+ ...surface.execOptions
89214
89593
  });
89215
89594
  const parsed = JSON.parse(result);
89216
89595
  return parsed.dependencies?.adhdev?.version || null;
@@ -89255,7 +89634,8 @@ async function checkForUpdate() {
89255
89634
  execFileSync6(installCommand.command, installCommand.args, {
89256
89635
  encoding: "utf-8",
89257
89636
  timeout: 6e4,
89258
- stdio: ["pipe", "pipe", "pipe"]
89637
+ stdio: ["pipe", "pipe", "pipe"],
89638
+ ...installCommand.execOptions
89259
89639
  });
89260
89640
  spinner.succeed(`Updated to v${latestVersion}`);
89261
89641
  console.log();
@@ -89541,7 +89921,8 @@ async function installCliOnly() {
89541
89921
  execFileSyncLocal(installCommand.command, installCommand.args, {
89542
89922
  encoding: "utf-8",
89543
89923
  timeout: 6e4,
89544
- stdio: ["pipe", "pipe", "pipe"]
89924
+ stdio: ["pipe", "pipe", "pipe"],
89925
+ ...installCommand.execOptions
89545
89926
  });
89546
89927
  const newVersion = readInstalledGlobalCliVersion(execFileSyncLocal) || "latest";
89547
89928
  installSpinner.succeed(`adhdev CLI ${currentVersion ? "updated" : "installed"} \u2713 (v${newVersion})`);
@@ -91932,7 +92313,9 @@ async function runDaemonUpgrade(options, pkgVersion3) {
91932
92313
  console.log(source_default.cyan("\n Checking for updates..."));
91933
92314
  let latest;
91934
92315
  try {
91935
- latest = execSync8("npm view adhdev version", { encoding: "utf-8" }).trim();
92316
+ const { execNpmCommandSync: execNpmCommandSync2, resolveCurrentGlobalInstallSurface: resolveCurrentGlobalInstallSurface2 } = await Promise.resolve().then(() => (init_src(), src_exports));
92317
+ const npmSurface = resolveCurrentGlobalInstallSurface2({ packageName: "adhdev" });
92318
+ latest = String(execNpmCommandSync2(["view", "adhdev", "version"], { encoding: "utf-8" }, npmSurface)).trim();
91936
92319
  } catch (e) {
91937
92320
  console.log(source_default.red(`
91938
92321
  \u2717 Failed to check latest version: ${e?.message}