@adhdev/daemon-standalone 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
@@ -29342,7 +29342,12 @@ var require_dist2 = __commonJS({
29342
29342
  const isWin = os8.platform() === "win32";
29343
29343
  try {
29344
29344
  const cmd = isWin ? `where ${trimmed}` : `which ${trimmed}`;
29345
- return (0, import_child_process4.execSync)(cmd, { encoding: "utf-8", timeout: 5e3, stdio: ["pipe", "pipe", "pipe"] }).trim().split("\n")[0].trim();
29345
+ return (0, import_child_process4.execSync)(cmd, {
29346
+ encoding: "utf-8",
29347
+ timeout: 5e3,
29348
+ stdio: ["pipe", "pipe", "pipe"],
29349
+ ...isWin ? { windowsHide: true } : {}
29350
+ }).trim().split("\n")[0].trim();
29346
29351
  } catch {
29347
29352
  return isWin ? `${trimmed}.cmd` : trimmed;
29348
29353
  }
@@ -32027,6 +32032,83 @@ var require_dist2 = __commonJS({
32027
32032
  if (!this.isWaitingForResponse) return "";
32028
32033
  return this.responseBuffer;
32029
32034
  }
32035
+ getDebugSnapshot() {
32036
+ const screenText = this.readTerminalScreenText();
32037
+ const parsedResult = this.parsedStatusCache?.result && typeof this.parsedStatusCache.result === "object" ? this.parsedStatusCache.result : null;
32038
+ return {
32039
+ cliType: this.cliType,
32040
+ cliName: this.cliName,
32041
+ workingDir: this.workingDir,
32042
+ currentStatus: this.currentStatus,
32043
+ ready: this.ready,
32044
+ isWaitingForResponse: this.isWaitingForResponse,
32045
+ activeModal: this.activeModal,
32046
+ parseErrorMessage: this.parseErrorMessage,
32047
+ messageCounts: {
32048
+ committed: this.committedMessages.length,
32049
+ structured: this.structuredMessages.length,
32050
+ visible: this.messages.length,
32051
+ parsedCache: Array.isArray(parsedResult?.messages) ? parsedResult.messages.length : void 0
32052
+ },
32053
+ buffers: {
32054
+ accumulatedLength: this.accumulatedBuffer.length,
32055
+ accumulatedRawLength: this.accumulatedRawBuffer.length,
32056
+ recentOutputLength: this.recentOutputBuffer.length,
32057
+ responseLength: this.responseBuffer.length,
32058
+ startupLength: this.startupBuffer.length,
32059
+ accumulatedTail: this.accumulatedBuffer.slice(-24e3),
32060
+ accumulatedRawTail: this.accumulatedRawBuffer.slice(-24e3),
32061
+ recentOutputTail: this.recentOutputBuffer.slice(-12e3),
32062
+ responseTail: this.responseBuffer.slice(-12e3)
32063
+ },
32064
+ terminal: {
32065
+ screenText,
32066
+ lastScreenSnapshot: this.lastScreenSnapshot,
32067
+ lastScreenText: this.lastScreenText,
32068
+ lastOutputAt: this.lastOutputAt,
32069
+ lastNonEmptyOutputAt: this.lastNonEmptyOutputAt,
32070
+ lastScreenChangeAt: this.lastScreenChangeAt,
32071
+ lastScreenSnapshotReadAt: this.lastScreenSnapshotReadAt
32072
+ },
32073
+ parser: {
32074
+ scriptNames: listCliScriptNames(this.cliScripts),
32075
+ traceSessionId: this.traceSessionId,
32076
+ traceSeq: this.traceSeq,
32077
+ currentTurnScope: this.currentTurnScope,
32078
+ parsedStatusCache: parsedResult ? {
32079
+ id: parsedResult.id,
32080
+ status: parsedResult.status,
32081
+ title: parsedResult.title,
32082
+ providerSessionId: parsedResult.providerSessionId,
32083
+ transcriptAuthority: parsedResult.transcriptAuthority,
32084
+ coverage: parsedResult.coverage,
32085
+ messageCount: Array.isArray(parsedResult.messages) ? parsedResult.messages.length : void 0,
32086
+ activeModal: parsedResult.activeModal
32087
+ } : null,
32088
+ pendingScriptStatus: this.pendingScriptStatus,
32089
+ pendingScriptStatusSince: this.pendingScriptStatusSince
32090
+ },
32091
+ runtimeMetadata: this.getRuntimeMetadata(),
32092
+ statusHistory: this.statusHistory.slice(-80),
32093
+ traceEntries: this.traceEntries.slice(-120),
32094
+ timing: {
32095
+ spawnAt: this.spawnAt,
32096
+ startupFirstOutputAt: this.startupFirstOutputAt,
32097
+ submitPendingUntil: this.submitPendingUntil,
32098
+ responseSettleIgnoreUntil: this.responseSettleIgnoreUntil,
32099
+ responseEpoch: this.responseEpoch,
32100
+ resizeSuppressUntil: this.resizeSuppressUntil,
32101
+ lastApprovalResolvedAt: this.lastApprovalResolvedAt,
32102
+ committedMessagesChangedAt: this.committedMessagesChangedAt
32103
+ },
32104
+ finish: {
32105
+ idleFinishCandidate: this.idleFinishCandidate,
32106
+ finishRetryCount: this.finishRetryCount,
32107
+ submitRetryUsed: this.submitRetryUsed,
32108
+ submitRetryPromptSnippet: this.submitRetryPromptSnippet
32109
+ }
32110
+ };
32111
+ }
32030
32112
  getRuntimeMetadata() {
32031
32113
  if (!this.ptyProcess || typeof this.ptyProcess.getMetadata !== "function") return null;
32032
32114
  return this.ptyProcess.getMetadata();
@@ -32382,6 +32464,7 @@ var require_dist2 = __commonJS({
32382
32464
  detectCLIs: () => detectCLIs,
32383
32465
  detectIDEs: () => detectIDEs,
32384
32466
  ensureSessionHostReady: () => ensureSessionHostReady2,
32467
+ execNpmCommandSync: () => execNpmCommandSync,
32385
32468
  findCdpManager: () => findCdpManager,
32386
32469
  flattenMessageParts: () => flattenMessageParts,
32387
32470
  forwardAgentStreamsToIdeInstance: () => forwardAgentStreamsToIdeInstance2,
@@ -32392,6 +32475,7 @@ var require_dist2 = __commonJS({
32392
32475
  getDebugRuntimeConfig: () => getDebugRuntimeConfig,
32393
32476
  getHostMemorySnapshot: () => getHostMemorySnapshot,
32394
32477
  getLogLevel: () => getLogLevel,
32478
+ getNpmExecOptions: () => getNpmExecOptions,
32395
32479
  getRecentActivity: () => getRecentActivity,
32396
32480
  getRecentCommands: () => getRecentCommands,
32397
32481
  getRecentDebugTrace: () => getRecentDebugTrace,
@@ -33120,7 +33204,11 @@ var require_dist2 = __commonJS({
33120
33204
  }
33121
33205
  function execAsync(cmd, timeoutMs = 5e3) {
33122
33206
  return new Promise((resolve12) => {
33123
- const child = (0, import_child_process2.exec)(cmd, { encoding: "utf-8", timeout: timeoutMs }, (err, stdout) => {
33207
+ const child = (0, import_child_process2.exec)(cmd, {
33208
+ encoding: "utf-8",
33209
+ timeout: timeoutMs,
33210
+ ...process.platform === "win32" ? { windowsHide: true } : {}
33211
+ }, (err, stdout) => {
33124
33212
  if (err || !stdout?.trim()) {
33125
33213
  resolve12(null);
33126
33214
  } else {
@@ -38728,6 +38816,248 @@ ${effect.notification.body || ""}`.trim();
38728
38816
  ...debugReadChat ? { debugReadChat } : {}
38729
38817
  };
38730
38818
  }
38819
+ var DEFAULT_DEBUG_SANITIZE_OPTIONS = {
38820
+ maxDepth: 8,
38821
+ maxArrayLength: 80,
38822
+ maxObjectKeys: 120,
38823
+ maxStringLength: 16e3
38824
+ };
38825
+ var SECRET_KEY_PATTERN = /(?:token|secret|password|passwd|authorization|cookie|api[_-]?key|access[_-]?key|refresh[_-]?token|client[_-]?secret|private[_-]?key)/i;
38826
+ function truncateDebugString(value, maxLength) {
38827
+ if (value.length <= maxLength) return value;
38828
+ return `${value.slice(0, maxLength)}\u2026[truncated ${value.length - maxLength} chars]`;
38829
+ }
38830
+ function redactDebugSecrets(value) {
38831
+ 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]");
38832
+ }
38833
+ function sanitizeDebugBundleValue(value, options = {}, depth = 0, keyHint = "") {
38834
+ const normalizedOptions = { ...DEFAULT_DEBUG_SANITIZE_OPTIONS, ...options };
38835
+ if (value === null || value === void 0) return value;
38836
+ if (typeof value === "number" || typeof value === "boolean") return value;
38837
+ if (typeof value === "bigint") return String(value);
38838
+ if (typeof value === "string") {
38839
+ if (SECRET_KEY_PATTERN.test(keyHint) && value.trim()) return "[REDACTED:secret-field]";
38840
+ return truncateDebugString(redactDebugSecrets(value), normalizedOptions.maxStringLength);
38841
+ }
38842
+ if (typeof value === "function") return `[Function ${value.name || "anonymous"}]`;
38843
+ if (typeof value !== "object") return String(value);
38844
+ if (depth >= normalizedOptions.maxDepth) return "[MaxDepth]";
38845
+ if (Array.isArray(value)) {
38846
+ const items = value.slice(0, normalizedOptions.maxArrayLength).map((item) => sanitizeDebugBundleValue(item, normalizedOptions, depth + 1, keyHint));
38847
+ if (value.length > normalizedOptions.maxArrayLength) {
38848
+ items.push(`[truncated ${value.length - normalizedOptions.maxArrayLength} items]`);
38849
+ }
38850
+ return items;
38851
+ }
38852
+ const record2 = value;
38853
+ const result = {};
38854
+ const entries = Object.entries(record2).slice(0, normalizedOptions.maxObjectKeys);
38855
+ for (const [key, item] of entries) {
38856
+ result[key] = sanitizeDebugBundleValue(item, normalizedOptions, depth + 1, key);
38857
+ }
38858
+ const remaining = Object.keys(record2).length - entries.length;
38859
+ if (remaining > 0) result.__truncatedKeys = remaining;
38860
+ return result;
38861
+ }
38862
+ function summarizeProviderForDebug(provider) {
38863
+ if (!provider) return null;
38864
+ const scripts = provider.scripts && typeof provider.scripts === "object" ? Object.keys(provider.scripts) : [];
38865
+ const controls = Array.isArray(provider.controls) ? provider.controls.map((control) => ({
38866
+ id: control?.id,
38867
+ label: control?.label,
38868
+ type: control?.type,
38869
+ settingKey: control?.settingKey,
38870
+ invokeScript: control?.invokeScript,
38871
+ listScript: control?.listScript,
38872
+ location: control?.location
38873
+ })) : [];
38874
+ return {
38875
+ type: provider.type,
38876
+ name: provider.name,
38877
+ category: provider.category,
38878
+ version: provider.version,
38879
+ canonicalHistory: provider.canonicalHistory,
38880
+ historyBehavior: provider.historyBehavior,
38881
+ webviewMatchText: provider.webviewMatchText,
38882
+ scriptNames: scripts,
38883
+ controls,
38884
+ resume: provider.resume
38885
+ };
38886
+ }
38887
+ function summarizeSessionForDebug(session) {
38888
+ if (!session || typeof session !== "object") return null;
38889
+ return {
38890
+ sessionId: session.sessionId,
38891
+ instanceKey: session.instanceKey,
38892
+ adapterKey: session.adapterKey,
38893
+ providerType: session.providerType,
38894
+ providerName: session.providerName,
38895
+ transport: session.transport,
38896
+ kind: session.kind,
38897
+ cdpManagerKey: session.cdpManagerKey,
38898
+ parentSessionId: session.parentSessionId,
38899
+ providerSessionId: session.providerSessionId,
38900
+ workspace: session.workspace,
38901
+ title: session.title,
38902
+ status: session.status,
38903
+ mode: session.mode,
38904
+ capabilities: session.capabilities
38905
+ };
38906
+ }
38907
+ function summarizeStateForDebug(state) {
38908
+ if (!state || typeof state !== "object") return null;
38909
+ const activeChat = state.activeChat && typeof state.activeChat === "object" ? state.activeChat : null;
38910
+ return {
38911
+ type: state.type,
38912
+ name: state.name,
38913
+ category: state.category,
38914
+ status: state.status,
38915
+ instanceId: state.instanceId,
38916
+ providerSessionId: state.providerSessionId,
38917
+ title: state.title,
38918
+ transport: state.transport,
38919
+ mode: state.mode,
38920
+ workspace: state.workspace,
38921
+ runtime: state.runtime,
38922
+ errorMessage: state.errorMessage,
38923
+ errorReason: state.errorReason,
38924
+ activeChat: activeChat ? {
38925
+ status: activeChat.status,
38926
+ title: activeChat.title,
38927
+ messageCount: Array.isArray(activeChat.messages) ? activeChat.messages.length : void 0,
38928
+ activeModal: activeChat.activeModal,
38929
+ messagesTail: Array.isArray(activeChat.messages) ? activeChat.messages.slice(-10) : void 0
38930
+ } : null,
38931
+ controlValues: state.controlValues,
38932
+ summaryMetadata: state.summaryMetadata
38933
+ };
38934
+ }
38935
+ function buildDebugBundleText(bundle) {
38936
+ return [
38937
+ "# ADHDev Chat Debug Bundle",
38938
+ "",
38939
+ "```json",
38940
+ JSON.stringify(bundle, null, 2),
38941
+ "```"
38942
+ ].join("\n");
38943
+ }
38944
+ async function handleGetChatDebugBundle(h, args) {
38945
+ const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
38946
+ if (!targetSessionId && !h.currentSession) {
38947
+ return { success: false, error: "No targetSessionId specified \u2014 cannot route command" };
38948
+ }
38949
+ const provider = h.getProvider(args?.agentType);
38950
+ const transport = getTargetTransport(h, provider);
38951
+ const providerType = provider?.type || getCurrentProviderType(h, args?.agentType || "");
38952
+ const adapter = isCliLikeTransport(transport) ? getTargetedCliAdapter(h, args, provider?.type) : null;
38953
+ const targetInstance = getTargetInstance(h, args);
38954
+ let adapterStatus = null;
38955
+ let parsedStatus = null;
38956
+ let adapterDebugSnapshot = null;
38957
+ let partialResponse = "";
38958
+ if (adapter) {
38959
+ try {
38960
+ adapterStatus = adapter.getStatus?.();
38961
+ } catch (error48) {
38962
+ adapterStatus = { error: error48?.message || String(error48) };
38963
+ }
38964
+ try {
38965
+ parsedStatus = typeof adapter.getScriptParsedStatus === "function" ? parseMaybeJson(adapter.getScriptParsedStatus()) : null;
38966
+ } catch (error48) {
38967
+ parsedStatus = { error: error48?.message || String(error48) };
38968
+ }
38969
+ try {
38970
+ adapterDebugSnapshot = typeof adapter.getDebugSnapshot === "function" ? adapter.getDebugSnapshot() : null;
38971
+ } catch (error48) {
38972
+ adapterDebugSnapshot = { error: error48?.message || String(error48) };
38973
+ }
38974
+ try {
38975
+ partialResponse = adapter.getPartialResponse?.() || "";
38976
+ } catch {
38977
+ partialResponse = "";
38978
+ }
38979
+ }
38980
+ let instanceState = null;
38981
+ if (targetInstance?.getState) {
38982
+ try {
38983
+ instanceState = summarizeStateForDebug(targetInstance.getState());
38984
+ } catch (error48) {
38985
+ instanceState = { error: error48?.message || String(error48) };
38986
+ }
38987
+ }
38988
+ let readChat = null;
38989
+ try {
38990
+ const readResult = await handleReadChat(h, { ...args, tailLimit: Math.max(1, Math.min(40, Number(args?.tailLimit || 40))) });
38991
+ readChat = readResult.success ? {
38992
+ success: true,
38993
+ status: readResult.status,
38994
+ title: readResult.title,
38995
+ totalMessages: readResult.totalMessages,
38996
+ returnedMessages: Array.isArray(readResult.messages) ? readResult.messages.length : void 0,
38997
+ syncMode: readResult.syncMode,
38998
+ replaceFrom: readResult.replaceFrom,
38999
+ lastMessageSignature: readResult.lastMessageSignature,
39000
+ providerSessionId: readResult.providerSessionId,
39001
+ transcriptAuthority: readResult.transcriptAuthority,
39002
+ coverage: readResult.coverage,
39003
+ activeModal: readResult.activeModal,
39004
+ messagesTail: Array.isArray(readResult.messages) ? readResult.messages.slice(-20) : [],
39005
+ debugReadChat: readResult.debugReadChat
39006
+ } : { success: false, error: readResult.error };
39007
+ } catch (error48) {
39008
+ readChat = { success: false, error: error48?.message || String(error48) };
39009
+ }
39010
+ const cdp = h.getCdp();
39011
+ const rawBundle = {
39012
+ version: 1,
39013
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
39014
+ target: {
39015
+ targetSessionId,
39016
+ providerType,
39017
+ transport,
39018
+ routeManagerKey: h.currentManagerKey,
39019
+ currentIdeType: h.currentIdeType
39020
+ },
39021
+ session: summarizeSessionForDebug(h.currentSession),
39022
+ provider: summarizeProviderForDebug(provider),
39023
+ daemon: {
39024
+ pid: process.pid,
39025
+ platform: process.platform,
39026
+ nodeVersion: process.version,
39027
+ cwd: process.cwd()
39028
+ },
39029
+ cdp: {
39030
+ requested: !!cdp,
39031
+ connected: !!cdp?.isConnected,
39032
+ managerKey: getCurrentManagerKey(h)
39033
+ },
39034
+ instanceState,
39035
+ cli: adapter ? {
39036
+ cliType: adapter.cliType,
39037
+ cliName: adapter.cliName,
39038
+ workingDir: adapter.workingDir,
39039
+ status: adapterStatus?.status,
39040
+ activeModal: adapterStatus?.activeModal,
39041
+ messageCount: Array.isArray(adapterStatus?.messages) ? adapterStatus.messages.length : void 0,
39042
+ messagesTail: Array.isArray(adapterStatus?.messages) ? adapterStatus.messages.slice(-20) : void 0,
39043
+ parsedStatus,
39044
+ partialResponse,
39045
+ ready: typeof adapter.isReady === "function" ? adapter.isReady() : void 0,
39046
+ processing: typeof adapter.isProcessing === "function" ? adapter.isProcessing() : void 0,
39047
+ debugSnapshot: adapterDebugSnapshot
39048
+ } : null,
39049
+ readChat,
39050
+ frontend: args?.frontendSnapshot && typeof args.frontendSnapshot === "object" ? args.frontendSnapshot : null,
39051
+ recentLogs: getRecentLogs(80, "debug"),
39052
+ recentDebugTrace: getRecentDebugTrace({ limit: 120 })
39053
+ };
39054
+ const bundle = sanitizeDebugBundleValue(rawBundle);
39055
+ return {
39056
+ success: true,
39057
+ bundle,
39058
+ text: buildDebugBundleText(bundle)
39059
+ };
39060
+ }
38731
39061
  function didProviderConfirmSend(result) {
38732
39062
  const parsed = parseMaybeJson(result);
38733
39063
  if (parsed === true) return true;
@@ -40863,6 +41193,7 @@ ${effect.notification.body || ""}`.trim();
40863
41193
  this.logCommandStart(cmd, args);
40864
41194
  const sessionScopedCommands = /* @__PURE__ */ new Set([
40865
41195
  "read_chat",
41196
+ "get_chat_debug_bundle",
40866
41197
  "send_chat",
40867
41198
  "list_chats",
40868
41199
  "new_chat",
@@ -40910,6 +41241,8 @@ ${effect.notification.body || ""}`.trim();
40910
41241
  // ─── Chat commands (chat-commands.ts) ───────────────
40911
41242
  case "read_chat":
40912
41243
  return handleReadChat(this, args);
41244
+ case "get_chat_debug_bundle":
41245
+ return handleGetChatDebugBundle(this, args);
40913
41246
  case "chat_history":
40914
41247
  return handleChatHistory(this, args);
40915
41248
  case "send_chat":
@@ -42580,7 +42913,8 @@ ${effect.notification.body || ""}`.trim();
42580
42913
  cwd: this.workingDir,
42581
42914
  env,
42582
42915
  stdio: ["pipe", "pipe", "pipe"],
42583
- shell: spawnConfig.shell || false
42916
+ shell: spawnConfig.shell || false,
42917
+ ...process.platform === "win32" ? { windowsHide: true } : {}
42584
42918
  });
42585
42919
  const AUTH_ERROR_PATTERNS = [
42586
42920
  /unauthorized|unauthenticated/i,
@@ -43270,7 +43604,10 @@ ${rawInput}` : rawInput;
43270
43604
  return (0, import_fs5.existsSync)(expandExecutable(trimmed));
43271
43605
  }
43272
43606
  try {
43273
- (0, import_child_process6.execFileSync)(process.platform === "win32" ? "where" : "which", [trimmed], { stdio: "ignore" });
43607
+ (0, import_child_process6.execFileSync)(process.platform === "win32" ? "where" : "which", [trimmed], {
43608
+ stdio: "ignore",
43609
+ ...process.platform === "win32" ? { windowsHide: true } : {}
43610
+ });
43274
43611
  return true;
43275
43612
  } catch {
43276
43613
  return false;
@@ -46191,7 +46528,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
46191
46528
  const canUseAppLauncher = !!appName;
46192
46529
  const useAppLauncher = preferredMethod === "app" ? canUseAppLauncher : preferredMethod === "cli" ? false : !canUseCli && canUseAppLauncher;
46193
46530
  if (!useAppLauncher && ide.cliCommand) {
46194
- (0, import_child_process7.spawn)(ide.cliCommand, args, { detached: true, stdio: "ignore" }).unref();
46531
+ (0, import_child_process7.spawn)(ide.cliCommand, args, { detached: true, stdio: "ignore", windowsHide: true }).unref();
46195
46532
  } else if (appName) {
46196
46533
  const openArgs = ["-a", appName, "--args", ...args];
46197
46534
  (0, import_child_process7.spawn)("open", openArgs, { detached: true, stdio: "ignore" }).unref();
@@ -46220,7 +46557,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
46220
46557
  const args = ["--remote-debugging-port=" + port];
46221
46558
  if (newWindow) args.push("--new-window");
46222
46559
  if (workspace) args.push(workspace);
46223
- (0, import_child_process7.spawn)(cli, args, { detached: true, stdio: "ignore" }).unref();
46560
+ (0, import_child_process7.spawn)(cli, args, { detached: true, stdio: "ignore", windowsHide: true }).unref();
46224
46561
  }
46225
46562
  function getAvailableIdeIds() {
46226
46563
  return getProviderLoader().getAvailableIdeTypes();
@@ -46699,23 +47036,23 @@ Run 'adhdev doctor' for detailed diagnostics.`
46699
47036
  if (platform10 === "win32") {
46700
47037
  const npmCliPath = path16.join(binDir, "node_modules", "npm", "bin", "npm-cli.js");
46701
47038
  if (fs8.existsSync(npmCliPath)) {
46702
- return { executable: nodeExecutable, argsPrefix: [npmCliPath], execOptions: { shell: false } };
47039
+ return { executable: nodeExecutable, argsPrefix: [npmCliPath], execOptions: getNpmExecOptions(platform10) };
46703
47040
  }
46704
47041
  for (const candidate of ["npm.exe", "npm"]) {
46705
47042
  const candidatePath = path16.join(binDir, candidate);
46706
47043
  if (fs8.existsSync(candidatePath)) {
46707
- return { executable: candidatePath, argsPrefix: [], execOptions: { shell: false } };
47044
+ return { executable: candidatePath, argsPrefix: [], execOptions: getNpmExecOptions(platform10) };
46708
47045
  }
46709
47046
  }
46710
- return { executable: nodeExecutable, argsPrefix: [npmCliPath], execOptions: { shell: false } };
47047
+ return { executable: nodeExecutable, argsPrefix: [npmCliPath], execOptions: getNpmExecOptions(platform10) };
46711
47048
  }
46712
47049
  for (const candidate of ["npm"]) {
46713
47050
  const candidatePath = path16.join(binDir, candidate);
46714
47051
  if (fs8.existsSync(candidatePath)) {
46715
- return { executable: candidatePath, argsPrefix: [], execOptions: { shell: false } };
47052
+ return { executable: candidatePath, argsPrefix: [], execOptions: getNpmExecOptions(platform10) };
46716
47053
  }
46717
47054
  }
46718
- return { executable: "npm", argsPrefix: [], execOptions: { shell: false } };
47055
+ return { executable: "npm", argsPrefix: [], execOptions: getNpmExecOptions(platform10) };
46719
47056
  }
46720
47057
  function findCurrentPackageRoot(currentCliPath, packageName) {
46721
47058
  if (!currentCliPath) return null;
@@ -46786,13 +47123,28 @@ Run 'adhdev doctor' for detailed diagnostics.`
46786
47123
  execOptions: surface.execOptions || getNpmExecOptions(options.platform)
46787
47124
  };
46788
47125
  }
46789
- function getNpmExecOptions(_platform = process.platform) {
47126
+ function getNpmExecOptions(platform10 = process.platform) {
47127
+ if (platform10 === "win32") {
47128
+ return { shell: false, windowsHide: true };
47129
+ }
46790
47130
  return { shell: false };
46791
47131
  }
47132
+ function execNpmCommandSync(args, options = {}, surface) {
47133
+ const execOptions = surface?.execOptions || getNpmExecOptions();
47134
+ return (0, import_child_process8.execFileSync)(
47135
+ surface?.npmExecutable || "npm",
47136
+ [...surface?.npmArgsPrefix || [], ...args],
47137
+ {
47138
+ ...options,
47139
+ ...execOptions,
47140
+ ...process.platform === "win32" ? { windowsHide: true } : {}
47141
+ }
47142
+ );
47143
+ }
46792
47144
  function killPid2(pid) {
46793
47145
  try {
46794
47146
  if (process.platform === "win32") {
46795
- (0, import_child_process8.execFileSync)("taskkill", ["/PID", String(pid), "/T", "/F"], { stdio: "ignore" });
47147
+ (0, import_child_process8.execFileSync)("taskkill", ["/PID", String(pid), "/T", "/F"], { stdio: "ignore", windowsHide: true });
46796
47148
  } else {
46797
47149
  process.kill(pid, "SIGTERM");
46798
47150
  }
@@ -46811,7 +47163,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
46811
47163
  "Bypass",
46812
47164
  "-Command",
46813
47165
  `(Get-CimInstance Win32_Process -Filter "${pidFilter}").CommandLine`
46814
- ], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"] }).trim();
47166
+ ], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"], windowsHide: true }).trim();
46815
47167
  if (psOut) return psOut;
46816
47168
  } catch {
46817
47169
  }
@@ -46822,7 +47174,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
46822
47174
  pidFilter,
46823
47175
  "get",
46824
47176
  "CommandLine"
46825
- ], { encoding: "utf8", timeout: 3e3, stdio: ["ignore", "pipe", "ignore"] }).trim();
47177
+ ], { encoding: "utf8", timeout: 3e3, stdio: ["ignore", "pipe", "ignore"], windowsHide: true }).trim();
46826
47178
  if (wmicOut) return wmicOut;
46827
47179
  } catch {
46828
47180
  }
@@ -46883,9 +47235,9 @@ Run 'adhdev doctor' for detailed diagnostics.`
46883
47235
  }
46884
47236
  function cleanupStaleGlobalInstallDirs(pkgName, surface) {
46885
47237
  const prefixArgs = surface.installPrefix ? ["--prefix", surface.installPrefix] : [];
46886
- const npmRoot = (0, import_child_process8.execFileSync)(surface.npmExecutable, [...surface.npmArgsPrefix || [], "root", "-g", ...prefixArgs], { encoding: "utf8", ...surface.execOptions }).trim();
47238
+ const npmRoot = String(execNpmCommandSync(["root", "-g", ...prefixArgs], { encoding: "utf8" }, surface)).trim();
46887
47239
  if (!npmRoot) return;
46888
- const npmPrefix = surface.installPrefix || (0, import_child_process8.execFileSync)(surface.npmExecutable, [...surface.npmArgsPrefix || [], "prefix", "-g", ...prefixArgs], { encoding: "utf8", ...surface.execOptions }).trim();
47240
+ const npmPrefix = surface.installPrefix || String(execNpmCommandSync(["prefix", "-g", ...prefixArgs], { encoding: "utf8" }, surface)).trim();
46889
47241
  const binDir = process.platform === "win32" ? npmPrefix : path16.join(npmPrefix, "bin");
46890
47242
  const packageBaseName = pkgName.startsWith("@") ? pkgName.split("/")[1] : pkgName;
46891
47243
  const binNames = /* @__PURE__ */ new Set([packageBaseName]);
@@ -47374,6 +47726,8 @@ Run 'adhdev doctor' for detailed diagnostics.`
47374
47726
  const wantsAll = args?.all === true;
47375
47727
  const offset = wantsAll ? 0 : Math.max(0, Number(args?.offset) || 0);
47376
47728
  const limit = wantsAll ? Number.MAX_SAFE_INTEGER : Math.max(1, Math.min(100, Number(args?.limit) || 30));
47729
+ const requestedWorkspace = typeof args?.workspace === "string" ? args.workspace.trim() : "";
47730
+ const requestedProviderSessionId = typeof args?.providerSessionId === "string" ? args.providerSessionId.trim() : typeof args?.activeProviderSessionId === "string" ? args.activeProviderSessionId.trim() : "";
47377
47731
  const providerMeta = this.deps.providerLoader.resolve?.(providerType) || this.deps.providerLoader.getMeta(providerType);
47378
47732
  const { sessions: historySessions, hasMore, source } = listProviderHistorySessions(providerType, {
47379
47733
  canonicalHistory: providerMeta?.canonicalHistory,
@@ -47393,6 +47747,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
47393
47747
  sessions: historySessions.map((session) => {
47394
47748
  const saved = savedSessionById.get(session.historySessionId);
47395
47749
  const recent = recentSessionById.get(session.historySessionId);
47750
+ const workspace = saved?.workspace || recent?.workspace || session.workspace || (requestedWorkspace && requestedProviderSessionId === session.historySessionId ? requestedWorkspace : void 0);
47396
47751
  return {
47397
47752
  id: session.historySessionId,
47398
47753
  providerSessionId: session.historySessionId,
@@ -47400,13 +47755,13 @@ Run 'adhdev doctor' for detailed diagnostics.`
47400
47755
  providerName: saved?.providerName || recent?.providerName || providerType,
47401
47756
  kind: saved?.kind || recent?.kind || kind,
47402
47757
  title: saved?.title || recent?.title || session.sessionTitle || session.preview || providerType,
47403
- workspace: saved?.workspace || recent?.workspace || session.workspace,
47758
+ workspace,
47404
47759
  summaryMetadata: saved?.summaryMetadata || recent?.summaryMetadata,
47405
47760
  preview: session.preview,
47406
47761
  messageCount: session.messageCount,
47407
47762
  firstMessageAt: session.firstMessageAt,
47408
47763
  lastMessageAt: session.lastMessageAt,
47409
- canResume: !!(saved?.workspace || recent?.workspace || session.workspace) && canResumeById,
47764
+ canResume: !!workspace && canResumeById,
47410
47765
  historySource: session.source,
47411
47766
  sourcePath: session.sourcePath,
47412
47767
  sourceMtimeMs: session.sourceMtimeMs
@@ -47668,18 +48023,18 @@ Run 'adhdev doctor' for detailed diagnostics.`
47668
48023
  case "daemon_upgrade": {
47669
48024
  LOG2.info("Upgrade", "Remote upgrade requested from dashboard");
47670
48025
  try {
47671
- const { execSync: execSync7 } = await import("child_process");
47672
48026
  const isStandalone = this.deps.packageName === "@adhdev/daemon-standalone" || process.argv[1]?.includes("daemon-standalone");
47673
48027
  const pkgName = isStandalone ? "@adhdev/daemon-standalone" : "adhdev";
47674
- const latest = execSync7(`npm view ${pkgName} version`, { encoding: "utf-8", timeout: 1e4 }).trim();
48028
+ const npmSurface = resolveCurrentGlobalInstallSurface({ packageName: pkgName });
48029
+ const latest = String(execNpmCommandSync(["view", pkgName, "version"], { encoding: "utf-8", timeout: 1e4 }, npmSurface)).trim();
47675
48030
  LOG2.info("Upgrade", `Latest ${pkgName}: v${latest}`);
47676
48031
  let currentInstalled = null;
47677
48032
  try {
47678
- const currentJson = execSync7(`npm ls -g ${pkgName} --depth=0 --json`, {
48033
+ const currentJson = String(execNpmCommandSync(["ls", "-g", pkgName, "--depth=0", "--json"], {
47679
48034
  encoding: "utf-8",
47680
48035
  timeout: 1e4,
47681
48036
  stdio: ["pipe", "pipe", "pipe"]
47682
- }).trim();
48037
+ }, npmSurface)).trim();
47683
48038
  const parsed = JSON.parse(currentJson);
47684
48039
  currentInstalled = parsed?.dependencies?.[pkgName]?.version || null;
47685
48040
  } catch {