@adhdev/daemon-standalone 0.8.73 → 0.8.74

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
@@ -30851,6 +30851,8 @@ ${data.message || ""}`.trim();
30851
30851
  }
30852
30852
  async sendMessage(text) {
30853
30853
  if (!this.ptyProcess) throw new Error(`${this.cliName} is not running`);
30854
+ const allowInputDuringGeneration = this.provider.allowInputDuringGeneration === true;
30855
+ const allowInterventionPrompt = allowInputDuringGeneration && this.isWaitingForResponse && this.currentStatus !== "waiting_approval";
30854
30856
  if (this.startupParseGate) {
30855
30857
  const deadline = Date.now() + 1e4;
30856
30858
  while (this.startupParseGate && Date.now() < deadline) {
@@ -30858,7 +30860,9 @@ ${data.message || ""}`.trim();
30858
30860
  await new Promise((resolve11) => setTimeout(resolve11, 50));
30859
30861
  }
30860
30862
  }
30861
- await this.waitForInteractivePrompt();
30863
+ if (!allowInterventionPrompt) {
30864
+ await this.waitForInteractivePrompt();
30865
+ }
30862
30866
  if (!this.ready) {
30863
30867
  this.resolveStartupState("send_precheck");
30864
30868
  const screenText = this.terminalScreen.getText() || "";
@@ -30870,7 +30874,7 @@ ${data.message || ""}`.trim();
30870
30874
  }
30871
30875
  }
30872
30876
  if (!this.ready) throw new Error(`${this.cliName} not ready (status: ${this.currentStatus})`);
30873
- if (this.isWaitingForResponse) {
30877
+ if (this.isWaitingForResponse && !allowInputDuringGeneration) {
30874
30878
  throw new Error(`${this.cliName} is still processing the previous prompt`);
30875
30879
  }
30876
30880
  const blockingModal = this.activeModal || this.getStartupConfirmationModal(this.terminalScreen.getText() || "");
@@ -33863,6 +33867,7 @@ ${cleanBody}`;
33863
33867
  init_chat_message_normalization();
33864
33868
  var HISTORY_DIR = path7.join(os52.homedir(), ".adhdev", "history");
33865
33869
  var RETAIN_DAYS = 30;
33870
+ var savedHistorySessionCache = /* @__PURE__ */ new Map();
33866
33871
  var CODEX_STARTER_PROMPT_RE = /^(?:[›❯]\s*)?(?:Find and fix a bug in @filename|Improve documentation in @filename|Write tests for @filename|Explain this codebase|Summarize recent commits|Implement \{feature\}|Use \/skills(?: to list available skills)?|Run \/review on my current changes)$/i;
33867
33872
  function normalizeHistoryComparable(text) {
33868
33873
  return String(text || "").replace(/\s+/g, " ").trim();
@@ -33920,6 +33925,85 @@ ${cleanBody}`;
33920
33925
  content
33921
33926
  };
33922
33927
  }
33928
+ function sanitizeHistoryFileSegment(value) {
33929
+ return String(value || "").replace(/[^a-zA-Z0-9_-]/g, "_");
33930
+ }
33931
+ function listHistoryFiles(dir, historySessionId) {
33932
+ const sanitizedSessionId = historySessionId ? sanitizeHistoryFileSegment(historySessionId) : "";
33933
+ return fs32.readdirSync(dir).filter((file2) => {
33934
+ if (!file2.endsWith(".jsonl")) return false;
33935
+ if (sanitizedSessionId) {
33936
+ return file2.startsWith(`${sanitizedSessionId}_`);
33937
+ }
33938
+ return true;
33939
+ }).sort().reverse();
33940
+ }
33941
+ function buildSavedHistoryCacheSignature(dir, files) {
33942
+ return files.map((file2) => {
33943
+ try {
33944
+ const stat4 = fs32.statSync(path7.join(dir, file2));
33945
+ return `${file2}:${stat4.size}:${Math.trunc(stat4.mtimeMs)}`;
33946
+ } catch {
33947
+ return `${file2}:missing`;
33948
+ }
33949
+ }).join("|");
33950
+ }
33951
+ function computeSavedHistorySessionSummaries(agentType, dir, files) {
33952
+ const groupedFiles = /* @__PURE__ */ new Map();
33953
+ const filePattern = /^([A-Za-z0-9_-]+)_\d{4}-\d{2}-\d{2}\.jsonl$/;
33954
+ for (const file2 of files) {
33955
+ const match = file2.match(filePattern);
33956
+ if (!match?.[1]) continue;
33957
+ const historySessionId = match[1];
33958
+ const grouped = groupedFiles.get(historySessionId) || [];
33959
+ grouped.push(file2);
33960
+ groupedFiles.set(historySessionId, grouped);
33961
+ }
33962
+ const summaries = [];
33963
+ for (const [historySessionId, grouped] of groupedFiles.entries()) {
33964
+ let messageCount = 0;
33965
+ let firstMessageAt = 0;
33966
+ let lastMessageAt = 0;
33967
+ let sessionTitle = "";
33968
+ let preview = "";
33969
+ let workspace = "";
33970
+ for (const file2 of grouped.sort()) {
33971
+ const filePath = path7.join(dir, file2);
33972
+ const content = fs32.readFileSync(filePath, "utf-8");
33973
+ const lines = content.split("\n").filter(Boolean);
33974
+ for (const line of lines) {
33975
+ let parsed = null;
33976
+ try {
33977
+ parsed = JSON.parse(line);
33978
+ } catch {
33979
+ parsed = null;
33980
+ }
33981
+ if (!parsed || parsed.historySessionId !== historySessionId) continue;
33982
+ if (parsed.kind === "session_start") {
33983
+ if (!workspace && parsed.workspace) workspace = parsed.workspace;
33984
+ continue;
33985
+ }
33986
+ messageCount += 1;
33987
+ if (!firstMessageAt || parsed.receivedAt < firstMessageAt) firstMessageAt = parsed.receivedAt;
33988
+ if (!lastMessageAt || parsed.receivedAt > lastMessageAt) lastMessageAt = parsed.receivedAt;
33989
+ if (parsed.sessionTitle) sessionTitle = parsed.sessionTitle;
33990
+ if (parsed.role !== "system" && parsed.content.trim()) preview = parsed.content.trim();
33991
+ }
33992
+ }
33993
+ if (messageCount === 0 || !lastMessageAt) continue;
33994
+ summaries.push({
33995
+ historySessionId,
33996
+ sessionTitle: sessionTitle || void 0,
33997
+ messageCount,
33998
+ firstMessageAt,
33999
+ lastMessageAt,
34000
+ preview: preview || void 0,
34001
+ workspace: workspace || void 0
34002
+ });
34003
+ }
34004
+ summaries.sort((a, b2) => b2.lastMessageAt - a.lastMessageAt);
34005
+ return summaries;
34006
+ }
33923
34007
  var ChatHistoryWriter = class {
33924
34008
  /** Last seen message count per agent (deduplication) */
33925
34009
  lastSeenCounts = /* @__PURE__ */ new Map();
@@ -34248,19 +34332,12 @@ ${cleanBody}`;
34248
34332
  return name.replace(/[^a-zA-Z0-9_-]/g, "_");
34249
34333
  }
34250
34334
  };
34251
- function readChatHistory(agentType, offset = 0, limit = 30, historySessionId) {
34335
+ function readChatHistory(agentType, offset = 0, limit = 30, historySessionId, excludeRecentCount = 0) {
34252
34336
  try {
34253
34337
  const sanitized = agentType.replace(/[^a-zA-Z0-9_-]/g, "_");
34254
34338
  const dir = path7.join(HISTORY_DIR, sanitized);
34255
34339
  if (!fs32.existsSync(dir)) return { messages: [], hasMore: false };
34256
- const sanitizedInstance = historySessionId?.replace(/[^a-zA-Z0-9_-]/g, "_");
34257
- const files = fs32.readdirSync(dir).filter((f) => {
34258
- if (!f.endsWith(".jsonl")) return false;
34259
- if (sanitizedInstance) {
34260
- return f.startsWith(`${sanitizedInstance}_`);
34261
- }
34262
- return true;
34263
- }).sort().reverse();
34340
+ const files = listHistoryFiles(dir, historySessionId);
34264
34341
  const allMessages = [];
34265
34342
  const seen = /* @__PURE__ */ new Set();
34266
34343
  for (const file2 of files) {
@@ -34291,8 +34368,13 @@ ${cleanBody}`;
34291
34368
  if (message.role !== "system") lastTurn = message;
34292
34369
  }
34293
34370
  const collapsed = collapseReplayAssistantTurns(agentType, chronological);
34294
- const sliced = collapsed.slice(offset, offset + limit);
34295
- const hasMore = collapsed.length > offset + limit;
34371
+ const boundedLimit = Math.max(1, limit);
34372
+ const boundedOffset = Math.max(0, offset);
34373
+ const boundedExclude = Math.max(0, Math.min(excludeRecentCount, collapsed.length));
34374
+ const endExclusive = Math.max(0, collapsed.length - boundedExclude - boundedOffset);
34375
+ const startInclusive = Math.max(0, endExclusive - boundedLimit);
34376
+ const sliced = collapsed.slice(startInclusive, endExclusive);
34377
+ const hasMore = startInclusive > 0;
34296
34378
  return { messages: sliced, hasMore };
34297
34379
  } catch {
34298
34380
  return { messages: [], hasMore: false };
@@ -34302,61 +34384,20 @@ ${cleanBody}`;
34302
34384
  try {
34303
34385
  const sanitized = agentType.replace(/[^a-zA-Z0-9_-]/g, "_");
34304
34386
  const dir = path7.join(HISTORY_DIR, sanitized);
34305
- if (!fs32.existsSync(dir)) return { sessions: [], hasMore: false };
34306
- const groupedFiles = /* @__PURE__ */ new Map();
34307
- const filePattern = /^([A-Za-z0-9_-]+)_\d{4}-\d{2}-\d{2}\.jsonl$/;
34308
- for (const file2 of fs32.readdirSync(dir)) {
34309
- if (!file2.endsWith(".jsonl")) continue;
34310
- const match = file2.match(filePattern);
34311
- if (!match?.[1]) continue;
34312
- const historySessionId = match[1];
34313
- const files = groupedFiles.get(historySessionId) || [];
34314
- files.push(file2);
34315
- groupedFiles.set(historySessionId, files);
34316
- }
34317
- const summaries = [];
34318
- for (const [historySessionId, files] of groupedFiles.entries()) {
34319
- let messageCount = 0;
34320
- let firstMessageAt = 0;
34321
- let lastMessageAt = 0;
34322
- let sessionTitle = "";
34323
- let preview = "";
34324
- let workspace = "";
34325
- for (const file2 of files.sort()) {
34326
- const filePath = path7.join(dir, file2);
34327
- const content = fs32.readFileSync(filePath, "utf-8");
34328
- const lines = content.split("\n").filter(Boolean);
34329
- for (const line of lines) {
34330
- let parsed = null;
34331
- try {
34332
- parsed = JSON.parse(line);
34333
- } catch {
34334
- parsed = null;
34335
- }
34336
- if (!parsed || parsed.historySessionId !== historySessionId) continue;
34337
- if (parsed.kind === "session_start") {
34338
- if (!workspace && parsed.workspace) workspace = parsed.workspace;
34339
- continue;
34340
- }
34341
- messageCount += 1;
34342
- if (!firstMessageAt || parsed.receivedAt < firstMessageAt) firstMessageAt = parsed.receivedAt;
34343
- if (!lastMessageAt || parsed.receivedAt > lastMessageAt) lastMessageAt = parsed.receivedAt;
34344
- if (parsed.sessionTitle) sessionTitle = parsed.sessionTitle;
34345
- if (parsed.role !== "system" && parsed.content.trim()) preview = parsed.content.trim();
34346
- }
34347
- }
34348
- if (messageCount === 0 || !lastMessageAt) continue;
34349
- summaries.push({
34350
- historySessionId,
34351
- sessionTitle: sessionTitle || void 0,
34352
- messageCount,
34353
- firstMessageAt,
34354
- lastMessageAt,
34355
- preview: preview || void 0,
34356
- workspace: workspace || void 0
34387
+ if (!fs32.existsSync(dir)) {
34388
+ savedHistorySessionCache.delete(sanitized);
34389
+ return { sessions: [], hasMore: false };
34390
+ }
34391
+ const files = listHistoryFiles(dir);
34392
+ const signature = buildSavedHistoryCacheSignature(dir, files);
34393
+ const cached2 = savedHistorySessionCache.get(sanitized);
34394
+ const summaries = cached2?.signature === signature ? cached2.summaries : computeSavedHistorySessionSummaries(agentType, dir, files);
34395
+ if (!cached2 || cached2.signature !== signature) {
34396
+ savedHistorySessionCache.set(sanitized, {
34397
+ signature,
34398
+ summaries
34357
34399
  });
34358
34400
  }
34359
- summaries.sort((a, b2) => b2.lastMessageAt - a.lastMessageAt);
34360
34401
  const offset = Math.max(0, options.offset || 0);
34361
34402
  const limit = Math.max(1, options.limit || 30);
34362
34403
  const sliced = summaries.slice(offset, offset + limit);
@@ -34845,22 +34886,22 @@ ${effect.notification.body || ""}`.trim();
34845
34886
  init_logger();
34846
34887
  init_read_chat_contract();
34847
34888
  var DEFAULT_APPROVAL_POSITIVE_HINTS = [
34848
- "run",
34889
+ "yes",
34890
+ "allow once",
34849
34891
  "approve",
34850
34892
  "accept",
34851
- "allow once",
34852
- "always allow",
34853
- "allow",
34854
- "yes",
34855
- "proceed",
34856
34893
  "continue",
34894
+ "run",
34895
+ "proceed",
34857
34896
  "confirm",
34858
34897
  "save",
34859
34898
  "ok",
34860
- "trust"
34899
+ "trust",
34900
+ "allow",
34901
+ "always allow"
34861
34902
  ];
34862
34903
  function normalizeApprovalLabel(value) {
34863
- return String(value || "").toLowerCase().replace(/[^\p{L}\p{N}]+/gu, " ").trim();
34904
+ return String(value || "").toLowerCase().replace(/^[\s\[(<{]*\d+(?:\s*[.)\]}>:-]|\s)+/, "").replace(/[^\p{L}\p{N}]+/gu, " ").trim();
34864
34905
  }
34865
34906
  function getApprovalPositiveHints(provider) {
34866
34907
  const customHints = Array.isArray(provider?.approvalPositiveHints) ? provider.approvalPositiveHints.map((hint) => normalizeApprovalLabel(String(hint || ""))).filter(Boolean) : [];
@@ -36606,6 +36647,41 @@ ${effect.notification.body || ""}`.trim();
36606
36647
  const messages = Array.isArray(payload.messages) ? payload.messages : [];
36607
36648
  return normalizeChatMessages(messages);
36608
36649
  }
36650
+ function buildReadChatReplayCollapseSignature(message) {
36651
+ if (!message) return "";
36652
+ const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
36653
+ const kind = typeof message.kind === "string" ? message.kind.trim().toLowerCase() : "standard";
36654
+ const senderName = typeof message.senderName === "string" ? message.senderName.trim().toLowerCase() : "";
36655
+ const content = flattenContent(message.content || "").replace(/\s+/g, " ").trim();
36656
+ return `${role}:${kind}:${senderName}:${content}`;
36657
+ }
36658
+ function shouldCollapseReadChatReplayDuplicate(message) {
36659
+ if (!message) return false;
36660
+ const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
36661
+ if (role !== "assistant" && role !== "system") return false;
36662
+ const kind = typeof message.kind === "string" ? message.kind.trim().toLowerCase() : "standard";
36663
+ return kind === "tool" || kind === "terminal" || kind === "thought" || kind === "system";
36664
+ }
36665
+ function collapseReplayDuplicatesFromReadChat(messages) {
36666
+ const collapsed = [];
36667
+ let lastReplayTurnSignature = "";
36668
+ for (const message of messages) {
36669
+ const signature = buildReadChatReplayCollapseSignature(message);
36670
+ const previous = collapsed[collapsed.length - 1];
36671
+ const previousSignature = buildReadChatReplayCollapseSignature(previous);
36672
+ if (shouldCollapseReadChatReplayDuplicate(message) && signature) {
36673
+ if (previousSignature === signature) continue;
36674
+ if (lastReplayTurnSignature === signature) continue;
36675
+ }
36676
+ collapsed.push(message);
36677
+ if (shouldCollapseReadChatReplayDuplicate(message) && signature) {
36678
+ lastReplayTurnSignature = signature;
36679
+ } else if ((message.role || "").toLowerCase() === "user") {
36680
+ lastReplayTurnSignature = "";
36681
+ }
36682
+ }
36683
+ return collapsed;
36684
+ }
36609
36685
  function deriveHistoryDedupKey(message) {
36610
36686
  const unitKey = typeof message._unitKey === "string" ? message._unitKey.trim() : "";
36611
36687
  if (unitKey) return `read_chat:${unitKey}`;
@@ -36681,14 +36757,38 @@ ${effect.notification.body || ""}`.trim();
36681
36757
  lastMessageSignature
36682
36758
  };
36683
36759
  }
36760
+ function hasNonEmptyModalButtons(activeModal) {
36761
+ if (!activeModal || typeof activeModal !== "object") return false;
36762
+ const buttons = activeModal.buttons;
36763
+ return Array.isArray(buttons) && buttons.some((button) => typeof button === "string" && button.trim().length > 0);
36764
+ }
36765
+ function normalizeReadChatCommandStatus(status, activeModal) {
36766
+ const raw = typeof status === "string" ? status.trim() : "";
36767
+ if (!raw) {
36768
+ return hasNonEmptyModalButtons(activeModal) ? "waiting_approval" : "idle";
36769
+ }
36770
+ switch (raw) {
36771
+ case "starting":
36772
+ return hasNonEmptyModalButtons(activeModal) ? "waiting_approval" : "generating";
36773
+ case "stopped":
36774
+ case "disconnected":
36775
+ case "not_monitored":
36776
+ return "error";
36777
+ default:
36778
+ return raw;
36779
+ }
36780
+ }
36684
36781
  function buildReadChatCommandResult(payload, args) {
36685
36782
  let validatedPayload;
36686
36783
  try {
36687
- validatedPayload = validateReadChatResultPayload(payload, "read_chat command result");
36784
+ validatedPayload = validateReadChatResultPayload({
36785
+ ...payload,
36786
+ status: normalizeReadChatCommandStatus(payload?.status, payload?.activeModal)
36787
+ }, "read_chat command result");
36688
36788
  } catch (error48) {
36689
36789
  return { success: false, error: error48?.message || String(error48) };
36690
36790
  }
36691
- const messages = normalizeReadChatMessages(validatedPayload);
36791
+ const messages = collapseReplayDuplicatesFromReadChat(normalizeReadChatMessages(validatedPayload));
36692
36792
  const cursor = normalizeReadChatCursor(args);
36693
36793
  if (!cursor.knownMessageCount && !cursor.lastMessageSignature && cursor.tailLimit > 0 && messages.length > cursor.tailLimit) {
36694
36794
  const tailMessages = messages.slice(-cursor.tailLimit);
@@ -36770,7 +36870,15 @@ ${effect.notification.body || ""}`.trim();
36770
36870
  try {
36771
36871
  const provider = h.getProvider(agentType);
36772
36872
  const agentStr = provider?.type || agentType || getCurrentProviderType(h);
36773
- const result = readChatHistory(agentStr, offset || 0, limit || 30, historySessionId);
36873
+ const transport = getTargetTransport(h, provider);
36874
+ let excludeRecentCount = Math.max(0, Number(args?.excludeRecentCount || 0));
36875
+ if (isCliLikeTransport(transport)) {
36876
+ const adapter = getTargetedCliAdapter(h, args, provider?.type);
36877
+ const status = adapter?.getStatus?.();
36878
+ const visibleCount = Array.isArray(status?.messages) ? status.messages.length : 0;
36879
+ if (visibleCount > excludeRecentCount) excludeRecentCount = visibleCount;
36880
+ }
36881
+ const result = readChatHistory(agentStr, offset || 0, limit || 30, historySessionId, excludeRecentCount);
36774
36882
  return { success: true, ...result, agent: agentStr };
36775
36883
  } catch (e) {
36776
36884
  return { success: false, error: e.message };
@@ -38020,13 +38128,6 @@ ${effect.notification.body || ""}`.trim();
38020
38128
  return { type: command.type, text };
38021
38129
  }
38022
38130
  init_logger();
38023
- function getCliPresentationMode(h, targetSessionId) {
38024
- if (!targetSessionId) return null;
38025
- const instance = h.ctx.instanceManager?.getInstance(targetSessionId);
38026
- if (instance?.category !== "cli") return null;
38027
- const mode = instance.getPresentationMode?.();
38028
- return mode === "chat" || mode === "terminal" ? mode : null;
38029
- }
38030
38131
  function normalizeOpenPanelCommandResult(result) {
38031
38132
  const payload = Object.prototype.hasOwnProperty.call(result, "result") ? result.result : result;
38032
38133
  if (payload === true) return { opened: true, visible: true, focused: false };
@@ -38099,9 +38200,6 @@ ${effect.notification.body || ""}`.trim();
38099
38200
  function handlePtyInput(h, args) {
38100
38201
  const { cliType, data, targetSessionId } = args || {};
38101
38202
  if (!data) return { success: false, error: "data required" };
38102
- if (getCliPresentationMode(h, targetSessionId) === "chat") {
38103
- return { success: false, error: "CLI session is in chat mode", code: "CLI_VIEW_MODE_NOT_TERMINAL" };
38104
- }
38105
38203
  const adapter = h.getCliAdapter(targetSessionId || cliType);
38106
38204
  if (!adapter || typeof adapter.writeRaw !== "function") {
38107
38205
  return { success: false, error: `CLI adapter not found: ${targetSessionId || cliType || "unknown"}` };
@@ -38109,24 +38207,10 @@ ${effect.notification.body || ""}`.trim();
38109
38207
  adapter.writeRaw(data);
38110
38208
  return { success: true };
38111
38209
  }
38112
- function handlePtyResize(h, args) {
38113
- const { cliType, cols, rows, force, targetSessionId } = args || {};
38210
+ function handlePtyResize(_h, args) {
38211
+ const { cols, rows } = args || {};
38114
38212
  if (!cols || !rows) return { success: false, error: "cols and rows required" };
38115
- if (getCliPresentationMode(h, targetSessionId) === "chat") {
38116
- return { success: false, error: "CLI session is in chat mode", code: "CLI_VIEW_MODE_NOT_TERMINAL" };
38117
- }
38118
- const adapter = h.getCliAdapter(targetSessionId || cliType);
38119
- if (!adapter || typeof adapter.resize !== "function") {
38120
- return { success: false, error: `CLI adapter not found: ${targetSessionId || cliType || "unknown"}` };
38121
- }
38122
- const resize = adapter.resize;
38123
- if (force) {
38124
- resize(cols - 1, rows);
38125
- setTimeout(() => resize(cols, rows), 50);
38126
- } else {
38127
- resize(cols, rows);
38128
- }
38129
- return { success: true };
38213
+ return { success: false, error: "PTY resize temporarily disabled", code: "PTY_RESIZE_DISABLED" };
38130
38214
  }
38131
38215
  function handleGetProviderSettings(h, args) {
38132
38216
  const loader = h.ctx.providerLoader;
@@ -38213,15 +38297,45 @@ ${effect.notification.body || ""}`.trim();
38213
38297
  }
38214
38298
  function buildControlScriptResult(scriptName, payload) {
38215
38299
  if (!payload || typeof payload !== "object") return {};
38216
- if (Array.isArray(payload.options)) {
38217
- return { controlResult: normalizeControlListResult(payload) };
38300
+ const legacyListPayload = (() => {
38301
+ if (Array.isArray(payload.options)) return payload;
38302
+ if (/^listmodels$/i.test(scriptName) && Array.isArray(payload.models)) {
38303
+ return {
38304
+ options: payload.models,
38305
+ currentValue: payload.currentValue ?? payload.current ?? payload.currentModel,
38306
+ ...typeof payload.error === "string" ? { error: payload.error } : {}
38307
+ };
38308
+ }
38309
+ if (/^listmodes$/i.test(scriptName) && Array.isArray(payload.modes)) {
38310
+ return {
38311
+ options: payload.modes,
38312
+ currentValue: payload.currentValue ?? payload.current ?? payload.currentMode ?? payload.mode,
38313
+ ...typeof payload.error === "string" ? { error: payload.error } : {}
38314
+ };
38315
+ }
38316
+ return null;
38317
+ })();
38318
+ if (legacyListPayload) {
38319
+ return { controlResult: normalizeControlListResult(legacyListPayload) };
38218
38320
  }
38219
- const looksLikeValueMutation = /^set|^change/i.test(scriptName) || payload.currentValue !== void 0 || payload.value !== void 0;
38321
+ const legacyMutationPayload = (() => {
38322
+ if (typeof payload.ok === "boolean") return payload;
38323
+ if (typeof payload.success === "boolean") {
38324
+ return {
38325
+ ok: payload.success,
38326
+ currentValue: payload.currentValue ?? payload.value ?? payload.model ?? payload.mode ?? payload.selectedModel ?? payload.selectedMode,
38327
+ ...Array.isArray(payload.effects) ? { effects: payload.effects } : {},
38328
+ ...typeof payload.error === "string" ? { error: payload.error } : {}
38329
+ };
38330
+ }
38331
+ return null;
38332
+ })();
38333
+ const looksLikeValueMutation = /^set|^change/i.test(scriptName) || payload.currentValue !== void 0 || payload.value !== void 0 || payload.success !== void 0;
38220
38334
  if (looksLikeValueMutation) {
38221
- return { controlResult: normalizeControlSetResult(payload) };
38335
+ return { controlResult: normalizeControlSetResult(legacyMutationPayload || payload) };
38222
38336
  }
38223
38337
  if (payload.ok !== void 0 || Array.isArray(payload.effects) || typeof payload.error === "string") {
38224
- return { controlResult: normalizeControlInvokeResult(payload) };
38338
+ return { controlResult: normalizeControlInvokeResult(legacyMutationPayload || payload) };
38225
38339
  }
38226
38340
  return {};
38227
38341
  }
@@ -38296,7 +38410,7 @@ ${effect.notification.body || ""}`.trim();
38296
38410
  }
38297
38411
  const managed = runtimeSessionId ? h.agentStream?.getManagedSession(runtimeSessionId) : null;
38298
38412
  const targetSessionId = managed?.cdpSessionId || null;
38299
- const IDE_LEVEL_SCRIPTS = provider.type === "claude-code-vscode" ? ["listModes", "setMode"] : ["listModes", "setMode", "listModels", "setModel"];
38413
+ const IDE_LEVEL_SCRIPTS = provider.type === "claude-code-vscode" ? ["listModes", "setMode", "listModels", "setModel", "setModelGui"] : ["listModes", "setMode", "listModels", "setModel"];
38300
38414
  if (IDE_LEVEL_SCRIPTS.includes(scriptName)) {
38301
38415
  if (targetSessionId) {
38302
38416
  try {
@@ -50440,6 +50554,20 @@ data: ${JSON.stringify(msg.data)}
50440
50554
  async handleReload(_req, res) {
50441
50555
  try {
50442
50556
  this.providerLoader.reload();
50557
+ let refreshedInstances = 0;
50558
+ if (this.instanceManager) {
50559
+ for (const id of this.instanceManager.listInstanceIds()) {
50560
+ const instance = this.instanceManager.getInstance(id);
50561
+ const providerType = typeof instance?.type === "string" ? instance.type : "";
50562
+ if (!providerType) continue;
50563
+ const resolved = this.providerLoader.resolve(providerType);
50564
+ if (!resolved) continue;
50565
+ if (instance && typeof instance === "object" && "provider" in instance) {
50566
+ instance.provider = resolved;
50567
+ refreshedInstances += 1;
50568
+ }
50569
+ }
50570
+ }
50443
50571
  const providers = this.providerLoader.getAll().map((p) => ({
50444
50572
  type: p.type,
50445
50573
  name: p.name,
@@ -50450,7 +50578,7 @@ data: ${JSON.stringify(msg.data)}
50450
50578
  cdp.clearTargetId();
50451
50579
  }
50452
50580
  }
50453
- this.json(res, 200, { reloaded: true, providers });
50581
+ this.json(res, 200, { reloaded: true, refreshedInstances, providers });
50454
50582
  } catch (e) {
50455
50583
  this.json(res, 500, { error: e.message });
50456
50584
  }