@adhdev/daemon-core 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
@@ -1472,7 +1472,12 @@ function findBinary(name) {
1472
1472
  const isWin = os8.platform() === "win32";
1473
1473
  try {
1474
1474
  const cmd = isWin ? `where ${trimmed}` : `which ${trimmed}`;
1475
- return (0, import_child_process4.execSync)(cmd, { encoding: "utf-8", timeout: 5e3, stdio: ["pipe", "pipe", "pipe"] }).trim().split("\n")[0].trim();
1475
+ return (0, import_child_process4.execSync)(cmd, {
1476
+ encoding: "utf-8",
1477
+ timeout: 5e3,
1478
+ stdio: ["pipe", "pipe", "pipe"],
1479
+ ...isWin ? { windowsHide: true } : {}
1480
+ }).trim().split("\n")[0].trim();
1476
1481
  } catch {
1477
1482
  return isWin ? `${trimmed}.cmd` : trimmed;
1478
1483
  }
@@ -4157,6 +4162,83 @@ var init_provider_cli_adapter = __esm({
4157
4162
  if (!this.isWaitingForResponse) return "";
4158
4163
  return this.responseBuffer;
4159
4164
  }
4165
+ getDebugSnapshot() {
4166
+ const screenText = this.readTerminalScreenText();
4167
+ const parsedResult = this.parsedStatusCache?.result && typeof this.parsedStatusCache.result === "object" ? this.parsedStatusCache.result : null;
4168
+ return {
4169
+ cliType: this.cliType,
4170
+ cliName: this.cliName,
4171
+ workingDir: this.workingDir,
4172
+ currentStatus: this.currentStatus,
4173
+ ready: this.ready,
4174
+ isWaitingForResponse: this.isWaitingForResponse,
4175
+ activeModal: this.activeModal,
4176
+ parseErrorMessage: this.parseErrorMessage,
4177
+ messageCounts: {
4178
+ committed: this.committedMessages.length,
4179
+ structured: this.structuredMessages.length,
4180
+ visible: this.messages.length,
4181
+ parsedCache: Array.isArray(parsedResult?.messages) ? parsedResult.messages.length : void 0
4182
+ },
4183
+ buffers: {
4184
+ accumulatedLength: this.accumulatedBuffer.length,
4185
+ accumulatedRawLength: this.accumulatedRawBuffer.length,
4186
+ recentOutputLength: this.recentOutputBuffer.length,
4187
+ responseLength: this.responseBuffer.length,
4188
+ startupLength: this.startupBuffer.length,
4189
+ accumulatedTail: this.accumulatedBuffer.slice(-24e3),
4190
+ accumulatedRawTail: this.accumulatedRawBuffer.slice(-24e3),
4191
+ recentOutputTail: this.recentOutputBuffer.slice(-12e3),
4192
+ responseTail: this.responseBuffer.slice(-12e3)
4193
+ },
4194
+ terminal: {
4195
+ screenText,
4196
+ lastScreenSnapshot: this.lastScreenSnapshot,
4197
+ lastScreenText: this.lastScreenText,
4198
+ lastOutputAt: this.lastOutputAt,
4199
+ lastNonEmptyOutputAt: this.lastNonEmptyOutputAt,
4200
+ lastScreenChangeAt: this.lastScreenChangeAt,
4201
+ lastScreenSnapshotReadAt: this.lastScreenSnapshotReadAt
4202
+ },
4203
+ parser: {
4204
+ scriptNames: listCliScriptNames(this.cliScripts),
4205
+ traceSessionId: this.traceSessionId,
4206
+ traceSeq: this.traceSeq,
4207
+ currentTurnScope: this.currentTurnScope,
4208
+ parsedStatusCache: parsedResult ? {
4209
+ id: parsedResult.id,
4210
+ status: parsedResult.status,
4211
+ title: parsedResult.title,
4212
+ providerSessionId: parsedResult.providerSessionId,
4213
+ transcriptAuthority: parsedResult.transcriptAuthority,
4214
+ coverage: parsedResult.coverage,
4215
+ messageCount: Array.isArray(parsedResult.messages) ? parsedResult.messages.length : void 0,
4216
+ activeModal: parsedResult.activeModal
4217
+ } : null,
4218
+ pendingScriptStatus: this.pendingScriptStatus,
4219
+ pendingScriptStatusSince: this.pendingScriptStatusSince
4220
+ },
4221
+ runtimeMetadata: this.getRuntimeMetadata(),
4222
+ statusHistory: this.statusHistory.slice(-80),
4223
+ traceEntries: this.traceEntries.slice(-120),
4224
+ timing: {
4225
+ spawnAt: this.spawnAt,
4226
+ startupFirstOutputAt: this.startupFirstOutputAt,
4227
+ submitPendingUntil: this.submitPendingUntil,
4228
+ responseSettleIgnoreUntil: this.responseSettleIgnoreUntil,
4229
+ responseEpoch: this.responseEpoch,
4230
+ resizeSuppressUntil: this.resizeSuppressUntil,
4231
+ lastApprovalResolvedAt: this.lastApprovalResolvedAt,
4232
+ committedMessagesChangedAt: this.committedMessagesChangedAt
4233
+ },
4234
+ finish: {
4235
+ idleFinishCandidate: this.idleFinishCandidate,
4236
+ finishRetryCount: this.finishRetryCount,
4237
+ submitRetryUsed: this.submitRetryUsed,
4238
+ submitRetryPromptSnippet: this.submitRetryPromptSnippet
4239
+ }
4240
+ };
4241
+ }
4160
4242
  getRuntimeMetadata() {
4161
4243
  if (!this.ptyProcess || typeof this.ptyProcess.getMetadata !== "function") return null;
4162
4244
  return this.ptyProcess.getMetadata();
@@ -4514,6 +4596,7 @@ __export(index_exports, {
4514
4596
  detectCLIs: () => detectCLIs,
4515
4597
  detectIDEs: () => detectIDEs,
4516
4598
  ensureSessionHostReady: () => ensureSessionHostReady,
4599
+ execNpmCommandSync: () => execNpmCommandSync,
4517
4600
  findCdpManager: () => findCdpManager,
4518
4601
  flattenMessageParts: () => flattenMessageParts,
4519
4602
  forwardAgentStreamsToIdeInstance: () => forwardAgentStreamsToIdeInstance,
@@ -4524,6 +4607,7 @@ __export(index_exports, {
4524
4607
  getDebugRuntimeConfig: () => getDebugRuntimeConfig,
4525
4608
  getHostMemorySnapshot: () => getHostMemorySnapshot,
4526
4609
  getLogLevel: () => getLogLevel,
4610
+ getNpmExecOptions: () => getNpmExecOptions,
4527
4611
  getRecentActivity: () => getRecentActivity,
4528
4612
  getRecentCommands: () => getRecentCommands,
4529
4613
  getRecentDebugTrace: () => getRecentDebugTrace,
@@ -5268,7 +5352,11 @@ function resolveCommandPath(command) {
5268
5352
  }
5269
5353
  function execAsync(cmd, timeoutMs = 5e3) {
5270
5354
  return new Promise((resolve12) => {
5271
- const child = (0, import_child_process2.exec)(cmd, { encoding: "utf-8", timeout: timeoutMs }, (err, stdout) => {
5355
+ const child = (0, import_child_process2.exec)(cmd, {
5356
+ encoding: "utf-8",
5357
+ timeout: timeoutMs,
5358
+ ...process.platform === "win32" ? { windowsHide: true } : {}
5359
+ }, (err, stdout) => {
5272
5360
  if (err || !stdout?.trim()) {
5273
5361
  resolve12(null);
5274
5362
  } else {
@@ -10942,6 +11030,245 @@ function buildReadChatCommandResult(payload, args) {
10942
11030
  ...debugReadChat ? { debugReadChat } : {}
10943
11031
  };
10944
11032
  }
11033
+ var DEFAULT_DEBUG_SANITIZE_OPTIONS = {
11034
+ maxDepth: 8,
11035
+ maxArrayLength: 80,
11036
+ maxObjectKeys: 120,
11037
+ maxStringLength: 16e3
11038
+ };
11039
+ var SECRET_KEY_PATTERN = /(?:token|secret|password|passwd|authorization|cookie|api[_-]?key|access[_-]?key|refresh[_-]?token|client[_-]?secret|private[_-]?key)/i;
11040
+ function truncateDebugString(value, maxLength) {
11041
+ if (value.length <= maxLength) return value;
11042
+ return `${value.slice(0, maxLength)}\u2026[truncated ${value.length - maxLength} chars]`;
11043
+ }
11044
+ function redactDebugSecrets(value) {
11045
+ 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]");
11046
+ }
11047
+ function sanitizeDebugBundleValue(value, options = {}, depth = 0, keyHint = "") {
11048
+ const normalizedOptions = { ...DEFAULT_DEBUG_SANITIZE_OPTIONS, ...options };
11049
+ if (value === null || value === void 0) return value;
11050
+ if (typeof value === "number" || typeof value === "boolean") return value;
11051
+ if (typeof value === "bigint") return String(value);
11052
+ if (typeof value === "string") {
11053
+ if (SECRET_KEY_PATTERN.test(keyHint) && value.trim()) return "[REDACTED:secret-field]";
11054
+ return truncateDebugString(redactDebugSecrets(value), normalizedOptions.maxStringLength);
11055
+ }
11056
+ if (typeof value === "function") return `[Function ${value.name || "anonymous"}]`;
11057
+ if (typeof value !== "object") return String(value);
11058
+ if (depth >= normalizedOptions.maxDepth) return "[MaxDepth]";
11059
+ if (Array.isArray(value)) {
11060
+ const items = value.slice(0, normalizedOptions.maxArrayLength).map((item) => sanitizeDebugBundleValue(item, normalizedOptions, depth + 1, keyHint));
11061
+ if (value.length > normalizedOptions.maxArrayLength) {
11062
+ items.push(`[truncated ${value.length - normalizedOptions.maxArrayLength} items]`);
11063
+ }
11064
+ return items;
11065
+ }
11066
+ const record = value;
11067
+ const result = {};
11068
+ const entries = Object.entries(record).slice(0, normalizedOptions.maxObjectKeys);
11069
+ for (const [key, item] of entries) {
11070
+ result[key] = sanitizeDebugBundleValue(item, normalizedOptions, depth + 1, key);
11071
+ }
11072
+ const remaining = Object.keys(record).length - entries.length;
11073
+ if (remaining > 0) result.__truncatedKeys = remaining;
11074
+ return result;
11075
+ }
11076
+ function summarizeProviderForDebug(provider) {
11077
+ if (!provider) return null;
11078
+ const scripts = provider.scripts && typeof provider.scripts === "object" ? Object.keys(provider.scripts) : [];
11079
+ const controls = Array.isArray(provider.controls) ? provider.controls.map((control) => ({
11080
+ id: control?.id,
11081
+ label: control?.label,
11082
+ type: control?.type,
11083
+ settingKey: control?.settingKey,
11084
+ invokeScript: control?.invokeScript,
11085
+ listScript: control?.listScript,
11086
+ location: control?.location
11087
+ })) : [];
11088
+ return {
11089
+ type: provider.type,
11090
+ name: provider.name,
11091
+ category: provider.category,
11092
+ version: provider.version,
11093
+ canonicalHistory: provider.canonicalHistory,
11094
+ historyBehavior: provider.historyBehavior,
11095
+ webviewMatchText: provider.webviewMatchText,
11096
+ scriptNames: scripts,
11097
+ controls,
11098
+ resume: provider.resume
11099
+ };
11100
+ }
11101
+ function summarizeSessionForDebug(session) {
11102
+ if (!session || typeof session !== "object") return null;
11103
+ return {
11104
+ sessionId: session.sessionId,
11105
+ instanceKey: session.instanceKey,
11106
+ adapterKey: session.adapterKey,
11107
+ providerType: session.providerType,
11108
+ providerName: session.providerName,
11109
+ transport: session.transport,
11110
+ kind: session.kind,
11111
+ cdpManagerKey: session.cdpManagerKey,
11112
+ parentSessionId: session.parentSessionId,
11113
+ providerSessionId: session.providerSessionId,
11114
+ workspace: session.workspace,
11115
+ title: session.title,
11116
+ status: session.status,
11117
+ mode: session.mode,
11118
+ capabilities: session.capabilities
11119
+ };
11120
+ }
11121
+ function summarizeStateForDebug(state) {
11122
+ if (!state || typeof state !== "object") return null;
11123
+ const activeChat = state.activeChat && typeof state.activeChat === "object" ? state.activeChat : null;
11124
+ return {
11125
+ type: state.type,
11126
+ name: state.name,
11127
+ category: state.category,
11128
+ status: state.status,
11129
+ instanceId: state.instanceId,
11130
+ providerSessionId: state.providerSessionId,
11131
+ title: state.title,
11132
+ transport: state.transport,
11133
+ mode: state.mode,
11134
+ workspace: state.workspace,
11135
+ runtime: state.runtime,
11136
+ errorMessage: state.errorMessage,
11137
+ errorReason: state.errorReason,
11138
+ activeChat: activeChat ? {
11139
+ status: activeChat.status,
11140
+ title: activeChat.title,
11141
+ messageCount: Array.isArray(activeChat.messages) ? activeChat.messages.length : void 0,
11142
+ activeModal: activeChat.activeModal,
11143
+ messagesTail: Array.isArray(activeChat.messages) ? activeChat.messages.slice(-10) : void 0
11144
+ } : null,
11145
+ controlValues: state.controlValues,
11146
+ summaryMetadata: state.summaryMetadata
11147
+ };
11148
+ }
11149
+ function buildDebugBundleText(bundle) {
11150
+ return [
11151
+ "# ADHDev Chat Debug Bundle",
11152
+ "",
11153
+ "```json",
11154
+ JSON.stringify(bundle, null, 2),
11155
+ "```"
11156
+ ].join("\n");
11157
+ }
11158
+ async function handleGetChatDebugBundle(h, args) {
11159
+ const provider = h.getProvider(args?.agentType);
11160
+ const transport = getTargetTransport(h, provider);
11161
+ const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
11162
+ const providerType = provider?.type || getCurrentProviderType(h, args?.agentType || "");
11163
+ const adapter = isCliLikeTransport(transport) ? getTargetedCliAdapter(h, args, provider?.type) : null;
11164
+ const targetInstance = getTargetInstance(h, args);
11165
+ let adapterStatus = null;
11166
+ let parsedStatus = null;
11167
+ let adapterDebugSnapshot = null;
11168
+ let partialResponse = "";
11169
+ if (adapter) {
11170
+ try {
11171
+ adapterStatus = adapter.getStatus?.();
11172
+ } catch (error) {
11173
+ adapterStatus = { error: error?.message || String(error) };
11174
+ }
11175
+ try {
11176
+ parsedStatus = typeof adapter.getScriptParsedStatus === "function" ? parseMaybeJson(adapter.getScriptParsedStatus()) : null;
11177
+ } catch (error) {
11178
+ parsedStatus = { error: error?.message || String(error) };
11179
+ }
11180
+ try {
11181
+ adapterDebugSnapshot = typeof adapter.getDebugSnapshot === "function" ? adapter.getDebugSnapshot() : null;
11182
+ } catch (error) {
11183
+ adapterDebugSnapshot = { error: error?.message || String(error) };
11184
+ }
11185
+ try {
11186
+ partialResponse = adapter.getPartialResponse?.() || "";
11187
+ } catch {
11188
+ partialResponse = "";
11189
+ }
11190
+ }
11191
+ let instanceState = null;
11192
+ if (targetInstance?.getState) {
11193
+ try {
11194
+ instanceState = summarizeStateForDebug(targetInstance.getState());
11195
+ } catch (error) {
11196
+ instanceState = { error: error?.message || String(error) };
11197
+ }
11198
+ }
11199
+ let readChat = null;
11200
+ try {
11201
+ const readResult = await handleReadChat(h, { ...args, tailLimit: Math.max(1, Math.min(40, Number(args?.tailLimit || 40))) });
11202
+ readChat = readResult.success ? {
11203
+ success: true,
11204
+ status: readResult.status,
11205
+ title: readResult.title,
11206
+ totalMessages: readResult.totalMessages,
11207
+ returnedMessages: Array.isArray(readResult.messages) ? readResult.messages.length : void 0,
11208
+ syncMode: readResult.syncMode,
11209
+ replaceFrom: readResult.replaceFrom,
11210
+ lastMessageSignature: readResult.lastMessageSignature,
11211
+ providerSessionId: readResult.providerSessionId,
11212
+ transcriptAuthority: readResult.transcriptAuthority,
11213
+ coverage: readResult.coverage,
11214
+ activeModal: readResult.activeModal,
11215
+ messagesTail: Array.isArray(readResult.messages) ? readResult.messages.slice(-20) : [],
11216
+ debugReadChat: readResult.debugReadChat
11217
+ } : { success: false, error: readResult.error };
11218
+ } catch (error) {
11219
+ readChat = { success: false, error: error?.message || String(error) };
11220
+ }
11221
+ const cdp = h.getCdp();
11222
+ const rawBundle = {
11223
+ version: 1,
11224
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
11225
+ target: {
11226
+ targetSessionId,
11227
+ providerType,
11228
+ transport,
11229
+ routeManagerKey: h.currentManagerKey,
11230
+ currentIdeType: h.currentIdeType
11231
+ },
11232
+ session: summarizeSessionForDebug(h.currentSession),
11233
+ provider: summarizeProviderForDebug(provider),
11234
+ daemon: {
11235
+ pid: process.pid,
11236
+ platform: process.platform,
11237
+ nodeVersion: process.version,
11238
+ cwd: process.cwd()
11239
+ },
11240
+ cdp: {
11241
+ requested: !!cdp,
11242
+ connected: !!cdp?.isConnected,
11243
+ managerKey: getCurrentManagerKey(h)
11244
+ },
11245
+ instanceState,
11246
+ cli: adapter ? {
11247
+ cliType: adapter.cliType,
11248
+ cliName: adapter.cliName,
11249
+ workingDir: adapter.workingDir,
11250
+ status: adapterStatus?.status,
11251
+ activeModal: adapterStatus?.activeModal,
11252
+ messageCount: Array.isArray(adapterStatus?.messages) ? adapterStatus.messages.length : void 0,
11253
+ messagesTail: Array.isArray(adapterStatus?.messages) ? adapterStatus.messages.slice(-20) : void 0,
11254
+ parsedStatus,
11255
+ partialResponse,
11256
+ ready: typeof adapter.isReady === "function" ? adapter.isReady() : void 0,
11257
+ processing: typeof adapter.isProcessing === "function" ? adapter.isProcessing() : void 0,
11258
+ debugSnapshot: adapterDebugSnapshot
11259
+ } : null,
11260
+ readChat,
11261
+ frontend: args?.frontendSnapshot && typeof args.frontendSnapshot === "object" ? args.frontendSnapshot : null,
11262
+ recentLogs: getRecentLogs(80, "debug"),
11263
+ recentDebugTrace: getRecentDebugTrace({ limit: 120 })
11264
+ };
11265
+ const bundle = sanitizeDebugBundleValue(rawBundle);
11266
+ return {
11267
+ success: true,
11268
+ bundle,
11269
+ text: buildDebugBundleText(bundle)
11270
+ };
11271
+ }
10945
11272
  function didProviderConfirmSend(result) {
10946
11273
  const parsed = parseMaybeJson(result);
10947
11274
  if (parsed === true) return true;
@@ -12333,7 +12660,8 @@ function getCliScriptCommand(payload) {
12333
12660
  if (command.type !== "send_message" && command.type !== "pty_write") return null;
12334
12661
  const text = typeof command.text === "string" ? command.text.trim() : typeof command.message === "string" ? command.message.trim() : "";
12335
12662
  if (!text) return null;
12336
- return { type: command.type, text };
12663
+ const enterCount = Number.isInteger(command.enterCount) && command.enterCount > 0 && command.enterCount <= 5 ? command.enterCount : void 0;
12664
+ return { type: command.type, text, ...enterCount ? { enterCount } : {} };
12337
12665
  }
12338
12666
 
12339
12667
  // src/commands/stream-commands.ts
@@ -12591,7 +12919,12 @@ async function executeProviderScript(h, args, scriptName) {
12591
12919
  if (cliCommand?.type === "send_message" && cliCommand.text) {
12592
12920
  await adapter.sendMessage(cliCommand.text);
12593
12921
  } else if (cliCommand?.type === "pty_write" && cliCommand.text && adapter.writeRaw) {
12922
+ const enterCount = cliCommand.enterCount || 1;
12594
12923
  await adapter.writeRaw(cliCommand.text + "\r");
12924
+ for (let i = 1; i < enterCount; i += 1) {
12925
+ await new Promise((resolve12) => setTimeout(resolve12, 50));
12926
+ await adapter.writeRaw("\r");
12927
+ }
12595
12928
  }
12596
12929
  applyProviderPatch(h, args, parsed.payload);
12597
12930
  return {
@@ -13132,6 +13465,8 @@ var DaemonCommandHandler = class {
13132
13465
  // ─── Chat commands (chat-commands.ts) ───────────────
13133
13466
  case "read_chat":
13134
13467
  return handleReadChat(this, args);
13468
+ case "get_chat_debug_bundle":
13469
+ return handleGetChatDebugBundle(this, args);
13135
13470
  case "chat_history":
13136
13471
  return handleChatHistory(this, args);
13137
13472
  case "send_chat":
@@ -13798,7 +14133,12 @@ var CliProviderInstance = class {
13798
14133
  if (cliCommand?.type === "send_message" && cliCommand.text) {
13799
14134
  await this.adapter.sendMessage(cliCommand.text);
13800
14135
  } else if (cliCommand?.type === "pty_write" && cliCommand.text) {
14136
+ const enterCount = cliCommand.enterCount || 1;
13801
14137
  await this.adapter.writeRaw(cliCommand.text + "\r");
14138
+ for (let i = 1; i < enterCount; i += 1) {
14139
+ await new Promise((resolve12) => setTimeout(resolve12, 50));
14140
+ await this.adapter.writeRaw("\r");
14141
+ }
13802
14142
  }
13803
14143
  this.applyProviderResponse(parsed.payload, { phase: "immediate" });
13804
14144
  }
@@ -14807,7 +15147,8 @@ var AcpProviderInstance = class {
14807
15147
  cwd: this.workingDir,
14808
15148
  env,
14809
15149
  stdio: ["pipe", "pipe", "pipe"],
14810
- shell: spawnConfig.shell || false
15150
+ shell: spawnConfig.shell || false,
15151
+ ...process.platform === "win32" ? { windowsHide: true } : {}
14811
15152
  });
14812
15153
  const AUTH_ERROR_PATTERNS = [
14813
15154
  /unauthorized|unauthenticated/i,
@@ -15503,7 +15844,10 @@ function commandExists(command) {
15503
15844
  return (0, import_fs5.existsSync)(expandExecutable(trimmed));
15504
15845
  }
15505
15846
  try {
15506
- (0, import_child_process6.execFileSync)(process.platform === "win32" ? "where" : "which", [trimmed], { stdio: "ignore" });
15847
+ (0, import_child_process6.execFileSync)(process.platform === "win32" ? "where" : "which", [trimmed], {
15848
+ stdio: "ignore",
15849
+ ...process.platform === "win32" ? { windowsHide: true } : {}
15850
+ });
15507
15851
  return true;
15508
15852
  } catch {
15509
15853
  return false;
@@ -18436,7 +18780,7 @@ async function launchMacOS(ide, port, workspace, newWindow) {
18436
18780
  const canUseAppLauncher = !!appName;
18437
18781
  const useAppLauncher = preferredMethod === "app" ? canUseAppLauncher : preferredMethod === "cli" ? false : !canUseCli && canUseAppLauncher;
18438
18782
  if (!useAppLauncher && ide.cliCommand) {
18439
- (0, import_child_process7.spawn)(ide.cliCommand, args, { detached: true, stdio: "ignore" }).unref();
18783
+ (0, import_child_process7.spawn)(ide.cliCommand, args, { detached: true, stdio: "ignore", windowsHide: true }).unref();
18440
18784
  } else if (appName) {
18441
18785
  const openArgs = ["-a", appName, "--args", ...args];
18442
18786
  (0, import_child_process7.spawn)("open", openArgs, { detached: true, stdio: "ignore" }).unref();
@@ -18465,7 +18809,7 @@ async function launchLinux(ide, port, workspace, newWindow) {
18465
18809
  const args = ["--remote-debugging-port=" + port];
18466
18810
  if (newWindow) args.push("--new-window");
18467
18811
  if (workspace) args.push(workspace);
18468
- (0, import_child_process7.spawn)(cli, args, { detached: true, stdio: "ignore" }).unref();
18812
+ (0, import_child_process7.spawn)(cli, args, { detached: true, stdio: "ignore", windowsHide: true }).unref();
18469
18813
  }
18470
18814
  function getAvailableIdeIds() {
18471
18815
  return getProviderLoader().getAvailableIdeTypes();
@@ -18949,16 +19293,28 @@ function appendUpgradeLog(message) {
18949
19293
  } catch {
18950
19294
  }
18951
19295
  }
18952
- function resolveSiblingNpmExecutable(nodeExecutable) {
19296
+ function resolveSiblingNpmInvocation(nodeExecutable, platform10 = process.platform) {
18953
19297
  const binDir = path16.dirname(nodeExecutable);
18954
- const candidates = process.platform === "win32" ? ["npm.cmd", "npm.exe", "npm"] : ["npm"];
18955
- for (const candidate of candidates) {
19298
+ if (platform10 === "win32") {
19299
+ const npmCliPath = path16.join(binDir, "node_modules", "npm", "bin", "npm-cli.js");
19300
+ if (fs8.existsSync(npmCliPath)) {
19301
+ return { executable: nodeExecutable, argsPrefix: [npmCliPath], execOptions: getNpmExecOptions(platform10) };
19302
+ }
19303
+ for (const candidate of ["npm.exe", "npm"]) {
19304
+ const candidatePath = path16.join(binDir, candidate);
19305
+ if (fs8.existsSync(candidatePath)) {
19306
+ return { executable: candidatePath, argsPrefix: [], execOptions: getNpmExecOptions(platform10) };
19307
+ }
19308
+ }
19309
+ return { executable: nodeExecutable, argsPrefix: [npmCliPath], execOptions: getNpmExecOptions(platform10) };
19310
+ }
19311
+ for (const candidate of ["npm"]) {
18956
19312
  const candidatePath = path16.join(binDir, candidate);
18957
19313
  if (fs8.existsSync(candidatePath)) {
18958
- return candidatePath;
19314
+ return { executable: candidatePath, argsPrefix: [], execOptions: getNpmExecOptions(platform10) };
18959
19315
  }
18960
19316
  }
18961
- return "npm";
19317
+ return { executable: "npm", argsPrefix: [], execOptions: getNpmExecOptions(platform10) };
18962
19318
  }
18963
19319
  function findCurrentPackageRoot(currentCliPath, packageName) {
18964
19320
  if (!currentCliPath) return null;
@@ -19007,31 +19363,50 @@ function resolveInstallPrefixFromPackageRoot(packageRoot, packageName) {
19007
19363
  }
19008
19364
  function resolveCurrentGlobalInstallSurface(options) {
19009
19365
  const packageRoot = findCurrentPackageRoot(options.currentCliPath || process.argv[1], options.packageName);
19366
+ const npmInvocation = resolveSiblingNpmInvocation(options.nodeExecutable || process.execPath, options.platform);
19010
19367
  return {
19011
- npmExecutable: resolveSiblingNpmExecutable(options.nodeExecutable || process.execPath),
19368
+ npmExecutable: npmInvocation.executable,
19369
+ npmArgsPrefix: npmInvocation.argsPrefix,
19012
19370
  packageRoot,
19013
- installPrefix: packageRoot ? resolveInstallPrefixFromPackageRoot(packageRoot, options.packageName) : null
19371
+ installPrefix: packageRoot ? resolveInstallPrefixFromPackageRoot(packageRoot, options.packageName) : null,
19372
+ execOptions: npmInvocation.execOptions
19014
19373
  };
19015
19374
  }
19016
19375
  function buildPinnedGlobalInstallCommand(options) {
19017
19376
  const surface = resolveCurrentGlobalInstallSurface(options);
19018
- const args = ["install", "-g", `${options.packageName}@${options.targetVersion || "latest"}`, "--force"];
19377
+ const args = [...surface.npmArgsPrefix || [], "install", "-g", `${options.packageName}@${options.targetVersion || "latest"}`, "--force"];
19019
19378
  if (surface.installPrefix) {
19020
19379
  args.push("--prefix", surface.installPrefix);
19021
19380
  }
19022
19381
  return {
19023
19382
  command: surface.npmExecutable,
19024
19383
  args,
19025
- surface
19384
+ surface,
19385
+ execOptions: surface.execOptions || getNpmExecOptions(options.platform)
19026
19386
  };
19027
19387
  }
19028
- function getNpmExecOptions() {
19029
- return { shell: process.platform === "win32" };
19388
+ function getNpmExecOptions(platform10 = process.platform) {
19389
+ if (platform10 === "win32") {
19390
+ return { shell: false, windowsHide: true };
19391
+ }
19392
+ return { shell: false };
19393
+ }
19394
+ function execNpmCommandSync(args, options = {}, surface) {
19395
+ const execOptions = surface?.execOptions || getNpmExecOptions();
19396
+ return (0, import_child_process8.execFileSync)(
19397
+ surface?.npmExecutable || "npm",
19398
+ [...surface?.npmArgsPrefix || [], ...args],
19399
+ {
19400
+ ...options,
19401
+ ...execOptions,
19402
+ ...process.platform === "win32" ? { windowsHide: true } : {}
19403
+ }
19404
+ );
19030
19405
  }
19031
19406
  function killPid(pid) {
19032
19407
  try {
19033
19408
  if (process.platform === "win32") {
19034
- (0, import_child_process8.execFileSync)("taskkill", ["/PID", String(pid), "/T", "/F"], { stdio: "ignore" });
19409
+ (0, import_child_process8.execFileSync)("taskkill", ["/PID", String(pid), "/T", "/F"], { stdio: "ignore", windowsHide: true });
19035
19410
  } else {
19036
19411
  process.kill(pid, "SIGTERM");
19037
19412
  }
@@ -19050,7 +19425,7 @@ function getWindowsProcessCommandLine(pid) {
19050
19425
  "Bypass",
19051
19426
  "-Command",
19052
19427
  `(Get-CimInstance Win32_Process -Filter "${pidFilter}").CommandLine`
19053
- ], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"] }).trim();
19428
+ ], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"], windowsHide: true }).trim();
19054
19429
  if (psOut) return psOut;
19055
19430
  } catch {
19056
19431
  }
@@ -19061,7 +19436,7 @@ function getWindowsProcessCommandLine(pid) {
19061
19436
  pidFilter,
19062
19437
  "get",
19063
19438
  "CommandLine"
19064
- ], { encoding: "utf8", timeout: 3e3, stdio: ["ignore", "pipe", "ignore"] }).trim();
19439
+ ], { encoding: "utf8", timeout: 3e3, stdio: ["ignore", "pipe", "ignore"], windowsHide: true }).trim();
19065
19440
  if (wmicOut) return wmicOut;
19066
19441
  } catch {
19067
19442
  }
@@ -19121,11 +19496,10 @@ function removeDaemonPidFile() {
19121
19496
  }
19122
19497
  }
19123
19498
  function cleanupStaleGlobalInstallDirs(pkgName, surface) {
19124
- const npmExecOpts = getNpmExecOptions();
19125
19499
  const prefixArgs = surface.installPrefix ? ["--prefix", surface.installPrefix] : [];
19126
- const npmRoot = (0, import_child_process8.execFileSync)(surface.npmExecutable, ["root", "-g", ...prefixArgs], { encoding: "utf8", ...npmExecOpts }).trim();
19500
+ const npmRoot = String(execNpmCommandSync(["root", "-g", ...prefixArgs], { encoding: "utf8" }, surface)).trim();
19127
19501
  if (!npmRoot) return;
19128
- const npmPrefix = surface.installPrefix || (0, import_child_process8.execFileSync)(surface.npmExecutable, ["prefix", "-g", ...prefixArgs], { encoding: "utf8", ...npmExecOpts }).trim();
19502
+ const npmPrefix = surface.installPrefix || String(execNpmCommandSync(["prefix", "-g", ...prefixArgs], { encoding: "utf8" }, surface)).trim();
19129
19503
  const binDir = process.platform === "win32" ? npmPrefix : path16.join(npmPrefix, "bin");
19130
19504
  const packageBaseName = pkgName.startsWith("@") ? pkgName.split("/")[1] : pkgName;
19131
19505
  const binNames = /* @__PURE__ */ new Set([packageBaseName]);
@@ -19195,7 +19569,7 @@ async function runDaemonUpgradeHelper(payload) {
19195
19569
  encoding: "utf8",
19196
19570
  stdio: "pipe",
19197
19571
  maxBuffer: 20 * 1024 * 1024,
19198
- ...getNpmExecOptions()
19572
+ ...installCommand.execOptions
19199
19573
  }
19200
19574
  );
19201
19575
  if (installOutput.trim()) {
@@ -19910,18 +20284,18 @@ var DaemonCommandRouter = class {
19910
20284
  case "daemon_upgrade": {
19911
20285
  LOG.info("Upgrade", "Remote upgrade requested from dashboard");
19912
20286
  try {
19913
- const { execSync: execSync7 } = await import("child_process");
19914
20287
  const isStandalone = this.deps.packageName === "@adhdev/daemon-standalone" || process.argv[1]?.includes("daemon-standalone");
19915
20288
  const pkgName = isStandalone ? "@adhdev/daemon-standalone" : "adhdev";
19916
- const latest = execSync7(`npm view ${pkgName} version`, { encoding: "utf-8", timeout: 1e4 }).trim();
20289
+ const npmSurface = resolveCurrentGlobalInstallSurface({ packageName: pkgName });
20290
+ const latest = String(execNpmCommandSync(["view", pkgName, "version"], { encoding: "utf-8", timeout: 1e4 }, npmSurface)).trim();
19917
20291
  LOG.info("Upgrade", `Latest ${pkgName}: v${latest}`);
19918
20292
  let currentInstalled = null;
19919
20293
  try {
19920
- const currentJson = execSync7(`npm ls -g ${pkgName} --depth=0 --json`, {
20294
+ const currentJson = String(execNpmCommandSync(["ls", "-g", pkgName, "--depth=0", "--json"], {
19921
20295
  encoding: "utf-8",
19922
20296
  timeout: 1e4,
19923
20297
  stdio: ["pipe", "pipe", "pipe"]
19924
- }).trim();
20298
+ }, npmSurface)).trim();
19925
20299
  const parsed = JSON.parse(currentJson);
19926
20300
  currentInstalled = parsed?.dependencies?.[pkgName]?.version || null;
19927
20301
  } catch {
@@ -28001,6 +28375,7 @@ async function shutdownDaemonComponents(components) {
28001
28375
  detectCLIs,
28002
28376
  detectIDEs,
28003
28377
  ensureSessionHostReady,
28378
+ execNpmCommandSync,
28004
28379
  findCdpManager,
28005
28380
  flattenMessageParts,
28006
28381
  forwardAgentStreamsToIdeInstance,
@@ -28011,6 +28386,7 @@ async function shutdownDaemonComponents(components) {
28011
28386
  getDebugRuntimeConfig,
28012
28387
  getHostMemorySnapshot,
28013
28388
  getLogLevel,
28389
+ getNpmExecOptions,
28014
28390
  getRecentActivity,
28015
28391
  getRecentCommands,
28016
28392
  getRecentDebugTrace,