@adhdev/daemon-core 0.9.48 → 0.9.50

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,248 @@ 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 targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
11160
+ if (!targetSessionId && !h.currentSession) {
11161
+ return { success: false, error: "No targetSessionId specified \u2014 cannot route command" };
11162
+ }
11163
+ const provider = h.getProvider(args?.agentType);
11164
+ const transport = getTargetTransport(h, provider);
11165
+ const providerType = provider?.type || getCurrentProviderType(h, args?.agentType || "");
11166
+ const adapter = isCliLikeTransport(transport) ? getTargetedCliAdapter(h, args, provider?.type) : null;
11167
+ const targetInstance = getTargetInstance(h, args);
11168
+ let adapterStatus = null;
11169
+ let parsedStatus = null;
11170
+ let adapterDebugSnapshot = null;
11171
+ let partialResponse = "";
11172
+ if (adapter) {
11173
+ try {
11174
+ adapterStatus = adapter.getStatus?.();
11175
+ } catch (error) {
11176
+ adapterStatus = { error: error?.message || String(error) };
11177
+ }
11178
+ try {
11179
+ parsedStatus = typeof adapter.getScriptParsedStatus === "function" ? parseMaybeJson(adapter.getScriptParsedStatus()) : null;
11180
+ } catch (error) {
11181
+ parsedStatus = { error: error?.message || String(error) };
11182
+ }
11183
+ try {
11184
+ adapterDebugSnapshot = typeof adapter.getDebugSnapshot === "function" ? adapter.getDebugSnapshot() : null;
11185
+ } catch (error) {
11186
+ adapterDebugSnapshot = { error: error?.message || String(error) };
11187
+ }
11188
+ try {
11189
+ partialResponse = adapter.getPartialResponse?.() || "";
11190
+ } catch {
11191
+ partialResponse = "";
11192
+ }
11193
+ }
11194
+ let instanceState = null;
11195
+ if (targetInstance?.getState) {
11196
+ try {
11197
+ instanceState = summarizeStateForDebug(targetInstance.getState());
11198
+ } catch (error) {
11199
+ instanceState = { error: error?.message || String(error) };
11200
+ }
11201
+ }
11202
+ let readChat = null;
11203
+ try {
11204
+ const readResult = await handleReadChat(h, { ...args, tailLimit: Math.max(1, Math.min(40, Number(args?.tailLimit || 40))) });
11205
+ readChat = readResult.success ? {
11206
+ success: true,
11207
+ status: readResult.status,
11208
+ title: readResult.title,
11209
+ totalMessages: readResult.totalMessages,
11210
+ returnedMessages: Array.isArray(readResult.messages) ? readResult.messages.length : void 0,
11211
+ syncMode: readResult.syncMode,
11212
+ replaceFrom: readResult.replaceFrom,
11213
+ lastMessageSignature: readResult.lastMessageSignature,
11214
+ providerSessionId: readResult.providerSessionId,
11215
+ transcriptAuthority: readResult.transcriptAuthority,
11216
+ coverage: readResult.coverage,
11217
+ activeModal: readResult.activeModal,
11218
+ messagesTail: Array.isArray(readResult.messages) ? readResult.messages.slice(-20) : [],
11219
+ debugReadChat: readResult.debugReadChat
11220
+ } : { success: false, error: readResult.error };
11221
+ } catch (error) {
11222
+ readChat = { success: false, error: error?.message || String(error) };
11223
+ }
11224
+ const cdp = h.getCdp();
11225
+ const rawBundle = {
11226
+ version: 1,
11227
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
11228
+ target: {
11229
+ targetSessionId,
11230
+ providerType,
11231
+ transport,
11232
+ routeManagerKey: h.currentManagerKey,
11233
+ currentIdeType: h.currentIdeType
11234
+ },
11235
+ session: summarizeSessionForDebug(h.currentSession),
11236
+ provider: summarizeProviderForDebug(provider),
11237
+ daemon: {
11238
+ pid: process.pid,
11239
+ platform: process.platform,
11240
+ nodeVersion: process.version,
11241
+ cwd: process.cwd()
11242
+ },
11243
+ cdp: {
11244
+ requested: !!cdp,
11245
+ connected: !!cdp?.isConnected,
11246
+ managerKey: getCurrentManagerKey(h)
11247
+ },
11248
+ instanceState,
11249
+ cli: adapter ? {
11250
+ cliType: adapter.cliType,
11251
+ cliName: adapter.cliName,
11252
+ workingDir: adapter.workingDir,
11253
+ status: adapterStatus?.status,
11254
+ activeModal: adapterStatus?.activeModal,
11255
+ messageCount: Array.isArray(adapterStatus?.messages) ? adapterStatus.messages.length : void 0,
11256
+ messagesTail: Array.isArray(adapterStatus?.messages) ? adapterStatus.messages.slice(-20) : void 0,
11257
+ parsedStatus,
11258
+ partialResponse,
11259
+ ready: typeof adapter.isReady === "function" ? adapter.isReady() : void 0,
11260
+ processing: typeof adapter.isProcessing === "function" ? adapter.isProcessing() : void 0,
11261
+ debugSnapshot: adapterDebugSnapshot
11262
+ } : null,
11263
+ readChat,
11264
+ frontend: args?.frontendSnapshot && typeof args.frontendSnapshot === "object" ? args.frontendSnapshot : null,
11265
+ recentLogs: getRecentLogs(80, "debug"),
11266
+ recentDebugTrace: getRecentDebugTrace({ limit: 120 })
11267
+ };
11268
+ const bundle = sanitizeDebugBundleValue(rawBundle);
11269
+ return {
11270
+ success: true,
11271
+ bundle,
11272
+ text: buildDebugBundleText(bundle)
11273
+ };
11274
+ }
10945
11275
  function didProviderConfirmSend(result) {
10946
11276
  const parsed = parseMaybeJson(result);
10947
11277
  if (parsed === true) return true;
@@ -13091,6 +13421,7 @@ var DaemonCommandHandler = class {
13091
13421
  this.logCommandStart(cmd, args);
13092
13422
  const sessionScopedCommands = /* @__PURE__ */ new Set([
13093
13423
  "read_chat",
13424
+ "get_chat_debug_bundle",
13094
13425
  "send_chat",
13095
13426
  "list_chats",
13096
13427
  "new_chat",
@@ -13138,6 +13469,8 @@ var DaemonCommandHandler = class {
13138
13469
  // ─── Chat commands (chat-commands.ts) ───────────────
13139
13470
  case "read_chat":
13140
13471
  return handleReadChat(this, args);
13472
+ case "get_chat_debug_bundle":
13473
+ return handleGetChatDebugBundle(this, args);
13141
13474
  case "chat_history":
13142
13475
  return handleChatHistory(this, args);
13143
13476
  case "send_chat":
@@ -14818,7 +15151,8 @@ var AcpProviderInstance = class {
14818
15151
  cwd: this.workingDir,
14819
15152
  env,
14820
15153
  stdio: ["pipe", "pipe", "pipe"],
14821
- shell: spawnConfig.shell || false
15154
+ shell: spawnConfig.shell || false,
15155
+ ...process.platform === "win32" ? { windowsHide: true } : {}
14822
15156
  });
14823
15157
  const AUTH_ERROR_PATTERNS = [
14824
15158
  /unauthorized|unauthenticated/i,
@@ -15514,7 +15848,10 @@ function commandExists(command) {
15514
15848
  return (0, import_fs5.existsSync)(expandExecutable(trimmed));
15515
15849
  }
15516
15850
  try {
15517
- (0, import_child_process6.execFileSync)(process.platform === "win32" ? "where" : "which", [trimmed], { stdio: "ignore" });
15851
+ (0, import_child_process6.execFileSync)(process.platform === "win32" ? "where" : "which", [trimmed], {
15852
+ stdio: "ignore",
15853
+ ...process.platform === "win32" ? { windowsHide: true } : {}
15854
+ });
15518
15855
  return true;
15519
15856
  } catch {
15520
15857
  return false;
@@ -18447,7 +18784,7 @@ async function launchMacOS(ide, port, workspace, newWindow) {
18447
18784
  const canUseAppLauncher = !!appName;
18448
18785
  const useAppLauncher = preferredMethod === "app" ? canUseAppLauncher : preferredMethod === "cli" ? false : !canUseCli && canUseAppLauncher;
18449
18786
  if (!useAppLauncher && ide.cliCommand) {
18450
- (0, import_child_process7.spawn)(ide.cliCommand, args, { detached: true, stdio: "ignore" }).unref();
18787
+ (0, import_child_process7.spawn)(ide.cliCommand, args, { detached: true, stdio: "ignore", windowsHide: true }).unref();
18451
18788
  } else if (appName) {
18452
18789
  const openArgs = ["-a", appName, "--args", ...args];
18453
18790
  (0, import_child_process7.spawn)("open", openArgs, { detached: true, stdio: "ignore" }).unref();
@@ -18476,7 +18813,7 @@ async function launchLinux(ide, port, workspace, newWindow) {
18476
18813
  const args = ["--remote-debugging-port=" + port];
18477
18814
  if (newWindow) args.push("--new-window");
18478
18815
  if (workspace) args.push(workspace);
18479
- (0, import_child_process7.spawn)(cli, args, { detached: true, stdio: "ignore" }).unref();
18816
+ (0, import_child_process7.spawn)(cli, args, { detached: true, stdio: "ignore", windowsHide: true }).unref();
18480
18817
  }
18481
18818
  function getAvailableIdeIds() {
18482
18819
  return getProviderLoader().getAvailableIdeTypes();
@@ -18965,23 +19302,23 @@ function resolveSiblingNpmInvocation(nodeExecutable, platform10 = process.platfo
18965
19302
  if (platform10 === "win32") {
18966
19303
  const npmCliPath = path16.join(binDir, "node_modules", "npm", "bin", "npm-cli.js");
18967
19304
  if (fs8.existsSync(npmCliPath)) {
18968
- return { executable: nodeExecutable, argsPrefix: [npmCliPath], execOptions: { shell: false } };
19305
+ return { executable: nodeExecutable, argsPrefix: [npmCliPath], execOptions: getNpmExecOptions(platform10) };
18969
19306
  }
18970
19307
  for (const candidate of ["npm.exe", "npm"]) {
18971
19308
  const candidatePath = path16.join(binDir, candidate);
18972
19309
  if (fs8.existsSync(candidatePath)) {
18973
- return { executable: candidatePath, argsPrefix: [], execOptions: { shell: false } };
19310
+ return { executable: candidatePath, argsPrefix: [], execOptions: getNpmExecOptions(platform10) };
18974
19311
  }
18975
19312
  }
18976
- return { executable: nodeExecutable, argsPrefix: [npmCliPath], execOptions: { shell: false } };
19313
+ return { executable: nodeExecutable, argsPrefix: [npmCliPath], execOptions: getNpmExecOptions(platform10) };
18977
19314
  }
18978
19315
  for (const candidate of ["npm"]) {
18979
19316
  const candidatePath = path16.join(binDir, candidate);
18980
19317
  if (fs8.existsSync(candidatePath)) {
18981
- return { executable: candidatePath, argsPrefix: [], execOptions: { shell: false } };
19318
+ return { executable: candidatePath, argsPrefix: [], execOptions: getNpmExecOptions(platform10) };
18982
19319
  }
18983
19320
  }
18984
- return { executable: "npm", argsPrefix: [], execOptions: { shell: false } };
19321
+ return { executable: "npm", argsPrefix: [], execOptions: getNpmExecOptions(platform10) };
18985
19322
  }
18986
19323
  function findCurrentPackageRoot(currentCliPath, packageName) {
18987
19324
  if (!currentCliPath) return null;
@@ -19052,13 +19389,28 @@ function buildPinnedGlobalInstallCommand(options) {
19052
19389
  execOptions: surface.execOptions || getNpmExecOptions(options.platform)
19053
19390
  };
19054
19391
  }
19055
- function getNpmExecOptions(_platform = process.platform) {
19392
+ function getNpmExecOptions(platform10 = process.platform) {
19393
+ if (platform10 === "win32") {
19394
+ return { shell: false, windowsHide: true };
19395
+ }
19056
19396
  return { shell: false };
19057
19397
  }
19398
+ function execNpmCommandSync(args, options = {}, surface) {
19399
+ const execOptions = surface?.execOptions || getNpmExecOptions();
19400
+ return (0, import_child_process8.execFileSync)(
19401
+ surface?.npmExecutable || "npm",
19402
+ [...surface?.npmArgsPrefix || [], ...args],
19403
+ {
19404
+ ...options,
19405
+ ...execOptions,
19406
+ ...process.platform === "win32" ? { windowsHide: true } : {}
19407
+ }
19408
+ );
19409
+ }
19058
19410
  function killPid(pid) {
19059
19411
  try {
19060
19412
  if (process.platform === "win32") {
19061
- (0, import_child_process8.execFileSync)("taskkill", ["/PID", String(pid), "/T", "/F"], { stdio: "ignore" });
19413
+ (0, import_child_process8.execFileSync)("taskkill", ["/PID", String(pid), "/T", "/F"], { stdio: "ignore", windowsHide: true });
19062
19414
  } else {
19063
19415
  process.kill(pid, "SIGTERM");
19064
19416
  }
@@ -19077,7 +19429,7 @@ function getWindowsProcessCommandLine(pid) {
19077
19429
  "Bypass",
19078
19430
  "-Command",
19079
19431
  `(Get-CimInstance Win32_Process -Filter "${pidFilter}").CommandLine`
19080
- ], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"] }).trim();
19432
+ ], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"], windowsHide: true }).trim();
19081
19433
  if (psOut) return psOut;
19082
19434
  } catch {
19083
19435
  }
@@ -19088,7 +19440,7 @@ function getWindowsProcessCommandLine(pid) {
19088
19440
  pidFilter,
19089
19441
  "get",
19090
19442
  "CommandLine"
19091
- ], { encoding: "utf8", timeout: 3e3, stdio: ["ignore", "pipe", "ignore"] }).trim();
19443
+ ], { encoding: "utf8", timeout: 3e3, stdio: ["ignore", "pipe", "ignore"], windowsHide: true }).trim();
19092
19444
  if (wmicOut) return wmicOut;
19093
19445
  } catch {
19094
19446
  }
@@ -19149,9 +19501,9 @@ function removeDaemonPidFile() {
19149
19501
  }
19150
19502
  function cleanupStaleGlobalInstallDirs(pkgName, surface) {
19151
19503
  const prefixArgs = surface.installPrefix ? ["--prefix", surface.installPrefix] : [];
19152
- const npmRoot = (0, import_child_process8.execFileSync)(surface.npmExecutable, [...surface.npmArgsPrefix || [], "root", "-g", ...prefixArgs], { encoding: "utf8", ...surface.execOptions }).trim();
19504
+ const npmRoot = String(execNpmCommandSync(["root", "-g", ...prefixArgs], { encoding: "utf8" }, surface)).trim();
19153
19505
  if (!npmRoot) return;
19154
- const npmPrefix = surface.installPrefix || (0, import_child_process8.execFileSync)(surface.npmExecutable, [...surface.npmArgsPrefix || [], "prefix", "-g", ...prefixArgs], { encoding: "utf8", ...surface.execOptions }).trim();
19506
+ const npmPrefix = surface.installPrefix || String(execNpmCommandSync(["prefix", "-g", ...prefixArgs], { encoding: "utf8" }, surface)).trim();
19155
19507
  const binDir = process.platform === "win32" ? npmPrefix : path16.join(npmPrefix, "bin");
19156
19508
  const packageBaseName = pkgName.startsWith("@") ? pkgName.split("/")[1] : pkgName;
19157
19509
  const binNames = /* @__PURE__ */ new Set([packageBaseName]);
@@ -19642,6 +19994,8 @@ var DaemonCommandRouter = class {
19642
19994
  const wantsAll = args?.all === true;
19643
19995
  const offset = wantsAll ? 0 : Math.max(0, Number(args?.offset) || 0);
19644
19996
  const limit = wantsAll ? Number.MAX_SAFE_INTEGER : Math.max(1, Math.min(100, Number(args?.limit) || 30));
19997
+ const requestedWorkspace = typeof args?.workspace === "string" ? args.workspace.trim() : "";
19998
+ const requestedProviderSessionId = typeof args?.providerSessionId === "string" ? args.providerSessionId.trim() : typeof args?.activeProviderSessionId === "string" ? args.activeProviderSessionId.trim() : "";
19645
19999
  const providerMeta = this.deps.providerLoader.resolve?.(providerType) || this.deps.providerLoader.getMeta(providerType);
19646
20000
  const { sessions: historySessions, hasMore, source } = listProviderHistorySessions(providerType, {
19647
20001
  canonicalHistory: providerMeta?.canonicalHistory,
@@ -19661,6 +20015,7 @@ var DaemonCommandRouter = class {
19661
20015
  sessions: historySessions.map((session) => {
19662
20016
  const saved = savedSessionById.get(session.historySessionId);
19663
20017
  const recent = recentSessionById.get(session.historySessionId);
20018
+ const workspace = saved?.workspace || recent?.workspace || session.workspace || (requestedWorkspace && requestedProviderSessionId === session.historySessionId ? requestedWorkspace : void 0);
19664
20019
  return {
19665
20020
  id: session.historySessionId,
19666
20021
  providerSessionId: session.historySessionId,
@@ -19668,13 +20023,13 @@ var DaemonCommandRouter = class {
19668
20023
  providerName: saved?.providerName || recent?.providerName || providerType,
19669
20024
  kind: saved?.kind || recent?.kind || kind,
19670
20025
  title: saved?.title || recent?.title || session.sessionTitle || session.preview || providerType,
19671
- workspace: saved?.workspace || recent?.workspace || session.workspace,
20026
+ workspace,
19672
20027
  summaryMetadata: saved?.summaryMetadata || recent?.summaryMetadata,
19673
20028
  preview: session.preview,
19674
20029
  messageCount: session.messageCount,
19675
20030
  firstMessageAt: session.firstMessageAt,
19676
20031
  lastMessageAt: session.lastMessageAt,
19677
- canResume: !!(saved?.workspace || recent?.workspace || session.workspace) && canResumeById,
20032
+ canResume: !!workspace && canResumeById,
19678
20033
  historySource: session.source,
19679
20034
  sourcePath: session.sourcePath,
19680
20035
  sourceMtimeMs: session.sourceMtimeMs
@@ -19936,18 +20291,18 @@ var DaemonCommandRouter = class {
19936
20291
  case "daemon_upgrade": {
19937
20292
  LOG.info("Upgrade", "Remote upgrade requested from dashboard");
19938
20293
  try {
19939
- const { execSync: execSync7 } = await import("child_process");
19940
20294
  const isStandalone = this.deps.packageName === "@adhdev/daemon-standalone" || process.argv[1]?.includes("daemon-standalone");
19941
20295
  const pkgName = isStandalone ? "@adhdev/daemon-standalone" : "adhdev";
19942
- const latest = execSync7(`npm view ${pkgName} version`, { encoding: "utf-8", timeout: 1e4 }).trim();
20296
+ const npmSurface = resolveCurrentGlobalInstallSurface({ packageName: pkgName });
20297
+ const latest = String(execNpmCommandSync(["view", pkgName, "version"], { encoding: "utf-8", timeout: 1e4 }, npmSurface)).trim();
19943
20298
  LOG.info("Upgrade", `Latest ${pkgName}: v${latest}`);
19944
20299
  let currentInstalled = null;
19945
20300
  try {
19946
- const currentJson = execSync7(`npm ls -g ${pkgName} --depth=0 --json`, {
20301
+ const currentJson = String(execNpmCommandSync(["ls", "-g", pkgName, "--depth=0", "--json"], {
19947
20302
  encoding: "utf-8",
19948
20303
  timeout: 1e4,
19949
20304
  stdio: ["pipe", "pipe", "pipe"]
19950
- }).trim();
20305
+ }, npmSurface)).trim();
19951
20306
  const parsed = JSON.parse(currentJson);
19952
20307
  currentInstalled = parsed?.dependencies?.[pkgName]?.version || null;
19953
20308
  } catch {
@@ -28027,6 +28382,7 @@ async function shutdownDaemonComponents(components) {
28027
28382
  detectCLIs,
28028
28383
  detectIDEs,
28029
28384
  ensureSessionHostReady,
28385
+ execNpmCommandSync,
28030
28386
  findCdpManager,
28031
28387
  flattenMessageParts,
28032
28388
  forwardAgentStreamsToIdeInstance,
@@ -28037,6 +28393,7 @@ async function shutdownDaemonComponents(components) {
28037
28393
  getDebugRuntimeConfig,
28038
28394
  getHostMemorySnapshot,
28039
28395
  getLogLevel,
28396
+ getNpmExecOptions,
28040
28397
  getRecentActivity,
28041
28398
  getRecentCommands,
28042
28399
  getRecentDebugTrace,