@adhdev/daemon-standalone 0.8.70 → 0.8.72

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
@@ -31419,9 +31419,12 @@ ${data.message || ""}`.trim();
31419
31419
  appendRecentActivity: () => appendRecentActivity,
31420
31420
  buildAssistantChatMessage: () => buildAssistantChatMessage,
31421
31421
  buildChatMessage: () => buildChatMessage,
31422
+ buildChatMessageSignature: () => buildChatMessageSignature,
31423
+ buildChatTailDeliverySignature: () => buildChatTailDeliverySignature,
31422
31424
  buildMachineInfo: () => buildMachineInfo2,
31423
31425
  buildRuntimeSystemChatMessage: () => buildRuntimeSystemChatMessage,
31424
31426
  buildSessionEntries: () => buildSessionEntries,
31427
+ buildSessionModalDeliverySignature: () => buildSessionModalDeliverySignature,
31425
31428
  buildStatusSnapshot: () => buildStatusSnapshot2,
31426
31429
  buildSystemChatMessage: () => buildSystemChatMessage,
31427
31430
  buildTerminalChatMessage: () => buildTerminalChatMessage,
@@ -31457,6 +31460,7 @@ ${data.message || ""}`.trim();
31457
31460
  getSessionHostSurfaceKind: () => getSessionHostSurfaceKind,
31458
31461
  getWorkspaceState: () => getWorkspaceState2,
31459
31462
  hasCdpManager: () => hasCdpManager,
31463
+ hashSignatureParts: () => hashSignatureParts,
31460
31464
  initDaemonComponents: () => initDaemonComponents2,
31461
31465
  installExtensions: () => installExtensions,
31462
31466
  installGlobalInterceptor: () => installGlobalInterceptor,
@@ -31482,12 +31486,16 @@ ${data.message || ""}`.trim();
31482
31486
  normalizeChatMessage: () => normalizeChatMessage,
31483
31487
  normalizeChatMessageKind: () => normalizeChatMessageKind,
31484
31488
  normalizeChatMessages: () => normalizeChatMessages,
31489
+ normalizeChatTailActiveModal: () => normalizeChatTailActiveModal,
31485
31490
  normalizeInputEnvelope: () => normalizeInputEnvelope,
31486
31491
  normalizeManagedStatus: () => normalizeManagedStatus,
31487
31492
  normalizeMessageParts: () => normalizeMessageParts,
31493
+ normalizeSessionModalFields: () => normalizeSessionModalFields,
31488
31494
  parseProviderSourceConfigUpdate: () => parseProviderSourceConfigUpdate,
31489
31495
  partitionSessionHostDiagnosticsSessions: () => partitionSessionHostDiagnosticsSessions,
31490
31496
  partitionSessionHostRecords: () => partitionSessionHostRecords,
31497
+ prepareSessionChatTailUpdate: () => prepareSessionChatTailUpdate2,
31498
+ prepareSessionModalUpdate: () => prepareSessionModalUpdate2,
31491
31499
  probeCdpPort: () => probeCdpPort,
31492
31500
  readChatHistory: () => readChatHistory,
31493
31501
  recordDebugTrace: () => recordDebugTrace,
@@ -31867,6 +31875,23 @@ ${data.message || ""}`.trim();
31867
31875
  var import_fs2 = require("fs");
31868
31876
  var import_path22 = require("path");
31869
31877
  init_config();
31878
+ var HERMES_SESSION_ID_RE = /^\d{8}_\d{6}_[a-z0-9]+$/i;
31879
+ function normalizeProviderSessionId(providerType, providerSessionId) {
31880
+ const normalizedProviderType = typeof providerType === "string" ? providerType.trim() : "";
31881
+ const normalizedId = typeof providerSessionId === "string" ? providerSessionId.trim() : "";
31882
+ if (!normalizedId) return "";
31883
+ const lowered = normalizedId.toLowerCase();
31884
+ if (lowered === "undefined" || lowered === "null") return "";
31885
+ if (normalizedProviderType === "hermes-cli" && !HERMES_SESSION_ID_RE.test(normalizedId)) {
31886
+ return "";
31887
+ }
31888
+ return normalizedId;
31889
+ }
31890
+ function isLegacyVolatileSessionReadKey(key) {
31891
+ const normalizedKey = typeof key === "string" ? key.trim() : "";
31892
+ if (!normalizedKey) return false;
31893
+ return normalizedKey.startsWith("provider:codex:vscode-webview://");
31894
+ }
31870
31895
  var DEFAULT_STATE = {
31871
31896
  recentActivity: [],
31872
31897
  savedProviderSessions: [],
@@ -31881,15 +31906,31 @@ ${data.message || ""}`.trim();
31881
31906
  }
31882
31907
  function normalizeState(raw) {
31883
31908
  const parsed = isPlainObject22(raw) ? raw : {};
31909
+ const recentActivity = (Array.isArray(parsed.recentActivity) ? parsed.recentActivity : []).filter((entry) => {
31910
+ if (!isPlainObject22(entry)) return false;
31911
+ const normalizedId = normalizeProviderSessionId(
31912
+ typeof entry.providerType === "string" ? entry.providerType : "",
31913
+ typeof entry.providerSessionId === "string" ? entry.providerSessionId : ""
31914
+ );
31915
+ if (typeof entry.providerSessionId === "string" && !normalizedId) return false;
31916
+ return true;
31917
+ });
31918
+ const savedProviderSessions = (Array.isArray(parsed.savedProviderSessions) ? parsed.savedProviderSessions : []).filter((entry) => {
31919
+ if (!isPlainObject22(entry)) return false;
31920
+ return !!normalizeProviderSessionId(
31921
+ typeof entry.providerType === "string" ? entry.providerType : "",
31922
+ typeof entry.providerSessionId === "string" ? entry.providerSessionId : ""
31923
+ );
31924
+ });
31884
31925
  const sessionReads = Object.fromEntries(
31885
- Object.entries(isPlainObject22(parsed.sessionReads) ? parsed.sessionReads : {}).filter(([, value]) => typeof value === "number" && Number.isFinite(value))
31926
+ Object.entries(isPlainObject22(parsed.sessionReads) ? parsed.sessionReads : {}).filter(([key, value]) => !isLegacyVolatileSessionReadKey(key) && typeof value === "number" && Number.isFinite(value))
31886
31927
  );
31887
31928
  const sessionReadMarkers = Object.fromEntries(
31888
- Object.entries(isPlainObject22(parsed.sessionReadMarkers) ? parsed.sessionReadMarkers : {}).filter(([, value]) => typeof value === "string")
31929
+ Object.entries(isPlainObject22(parsed.sessionReadMarkers) ? parsed.sessionReadMarkers : {}).filter(([key, value]) => !isLegacyVolatileSessionReadKey(key) && typeof value === "string")
31889
31930
  );
31890
31931
  return {
31891
- recentActivity: Array.isArray(parsed.recentActivity) ? parsed.recentActivity : [],
31892
- savedProviderSessions: Array.isArray(parsed.savedProviderSessions) ? parsed.savedProviderSessions : [],
31932
+ recentActivity,
31933
+ savedProviderSessions,
31893
31934
  sessionReads,
31894
31935
  sessionReadMarkers
31895
31936
  };
@@ -31914,7 +31955,7 @@ ${data.message || ""}`.trim();
31914
31955
  function resetState() {
31915
31956
  saveState({ ...DEFAULT_STATE });
31916
31957
  }
31917
- var import_child_process2 = require("child_process");
31958
+ var import_child_process = require("child_process");
31918
31959
  var import_fs3 = require("fs");
31919
31960
  var import_os22 = require("os");
31920
31961
  var path42 = __toESM2(require("path"));
@@ -31942,7 +31983,7 @@ ${data.message || ""}`.trim();
31942
31983
  return (0, import_fs3.existsSync)(resolved) ? resolved : null;
31943
31984
  }
31944
31985
  try {
31945
- const result = (0, import_child_process2.execSync)(
31986
+ const result = (0, import_child_process.execSync)(
31946
31987
  (0, import_os22.platform)() === "win32" ? `where ${trimmed}` : `which ${trimmed}`,
31947
31988
  { encoding: "utf-8", timeout: 5e3, stdio: ["pipe", "pipe", "pipe"] }
31948
31989
  ).trim();
@@ -31953,7 +31994,7 @@ ${data.message || ""}`.trim();
31953
31994
  }
31954
31995
  function getIdeVersion(cliCommand) {
31955
31996
  try {
31956
- const result = (0, import_child_process2.execSync)(`"${cliCommand}" --version`, {
31997
+ const result = (0, import_child_process.execSync)(`"${cliCommand}" --version`, {
31957
31998
  encoding: "utf-8",
31958
31999
  timeout: 1e4,
31959
32000
  stdio: ["pipe", "pipe", "pipe"]
@@ -32020,7 +32061,7 @@ ${data.message || ""}`.trim();
32020
32061
  }
32021
32062
  return results;
32022
32063
  }
32023
- var import_child_process22 = require("child_process");
32064
+ var import_child_process2 = require("child_process");
32024
32065
  var os22 = __toESM2(require("os"));
32025
32066
  var path52 = __toESM2(require("path"));
32026
32067
  var import_fs4 = require("fs");
@@ -32053,7 +32094,7 @@ ${data.message || ""}`.trim();
32053
32094
  }
32054
32095
  function execAsync(cmd, timeoutMs = 5e3) {
32055
32096
  return new Promise((resolve11) => {
32056
- const child = (0, import_child_process22.exec)(cmd, { encoding: "utf-8", timeout: timeoutMs }, (err, stdout) => {
32097
+ const child = (0, import_child_process2.exec)(cmd, { encoding: "utf-8", timeout: timeoutMs }, (err, stdout) => {
32057
32098
  if (err || !stdout?.trim()) {
32058
32099
  resolve11(null);
32059
32100
  } else {
@@ -36192,6 +36233,30 @@ ${effect.notification.body || ""}`.trim();
36192
36233
  }
36193
36234
  }
36194
36235
  init_logger();
36236
+ function resolveLegacyProviderScript(fn2, scriptName, params) {
36237
+ if (typeof fn2 !== "function") return null;
36238
+ if (params && typeof params === "object" && !Array.isArray(params) && Object.keys(params).length > 0) {
36239
+ const firstVal = Object.values(params)[0];
36240
+ if (scriptName === "sendMessage" && typeof firstVal === "string") {
36241
+ const legacyScript = fn2(firstVal);
36242
+ if (legacyScript) return legacyScript;
36243
+ }
36244
+ const script = fn2(params);
36245
+ const likelyLegacyObjectLeak = typeof script === "string" && script.includes("[object Object]") && typeof firstVal === "string";
36246
+ if (!likelyLegacyObjectLeak && script) return script;
36247
+ if (firstVal !== void 0) {
36248
+ const legacyScript = fn2(firstVal);
36249
+ if (legacyScript) return legacyScript;
36250
+ }
36251
+ if (script) return script;
36252
+ return null;
36253
+ }
36254
+ if (params !== void 0) {
36255
+ const script = fn2(params);
36256
+ if (script) return script;
36257
+ }
36258
+ return fn2() || null;
36259
+ }
36195
36260
  init_contracts();
36196
36261
  var VALID_INPUT_MEDIA_TYPES = /* @__PURE__ */ new Set(["text", "image", "audio", "video", "resource"]);
36197
36262
  function getProviderLabel(provider) {
@@ -36370,10 +36435,7 @@ ${effect.notification.body || ""}`.trim();
36370
36435
  function createInteractionId(prefix = "ix") {
36371
36436
  return `${prefix}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`;
36372
36437
  }
36373
- init_chat_message_normalization();
36374
- var RECENT_SEND_WINDOW_MS = 1200;
36375
- var recentSendByTarget = /* @__PURE__ */ new Map();
36376
- function hashSignatureParts2(parts) {
36438
+ function hashSignatureParts(parts) {
36377
36439
  let hash2 = 2166136261;
36378
36440
  for (const part of parts) {
36379
36441
  const text = String(part || "");
@@ -36386,6 +36448,56 @@ ${effect.notification.body || ""}`.trim();
36386
36448
  }
36387
36449
  return hash2.toString(16).padStart(8, "0");
36388
36450
  }
36451
+ function stringifySignatureContent(content) {
36452
+ try {
36453
+ return JSON.stringify(content ?? "");
36454
+ } catch {
36455
+ return String(content ?? "");
36456
+ }
36457
+ }
36458
+ function stringifySignatureMessages(messages) {
36459
+ try {
36460
+ return JSON.stringify(messages);
36461
+ } catch {
36462
+ return String(messages.length);
36463
+ }
36464
+ }
36465
+ function buildChatMessageSignature(message) {
36466
+ if (!message) return "";
36467
+ return hashSignatureParts([
36468
+ String(message.id || ""),
36469
+ String(message.index ?? ""),
36470
+ String(message.role || ""),
36471
+ String(message.receivedAt ?? message.timestamp ?? ""),
36472
+ stringifySignatureContent(message.content)
36473
+ ]);
36474
+ }
36475
+ function buildChatTailDeliverySignature(payload) {
36476
+ return hashSignatureParts([
36477
+ payload.sessionId,
36478
+ payload.historySessionId || "",
36479
+ payload.status,
36480
+ payload.title || "",
36481
+ payload.syncMode,
36482
+ String(payload.replaceFrom),
36483
+ String(payload.totalMessages),
36484
+ payload.lastMessageSignature,
36485
+ payload.activeModal ? `${payload.activeModal.message}|${payload.activeModal.buttons.join("")}` : "",
36486
+ stringifySignatureMessages(payload.messages)
36487
+ ]);
36488
+ }
36489
+ function buildSessionModalDeliverySignature(payload) {
36490
+ return hashSignatureParts([
36491
+ payload.sessionId,
36492
+ payload.status,
36493
+ payload.title || "",
36494
+ payload.modalMessage || "",
36495
+ Array.isArray(payload.modalButtons) ? payload.modalButtons.join("") : ""
36496
+ ]);
36497
+ }
36498
+ init_chat_message_normalization();
36499
+ var RECENT_SEND_WINDOW_MS = 1200;
36500
+ var recentSendByTarget = /* @__PURE__ */ new Map();
36389
36501
  function getCurrentProviderType(h, fallback = "") {
36390
36502
  return h.currentSession?.providerType || h.currentProviderType || fallback;
36391
36503
  }
@@ -36482,20 +36594,7 @@ ${effect.notification.body || ""}`.trim();
36482
36594
  }
36483
36595
  }
36484
36596
  function getChatMessageSignature(message) {
36485
- if (!message) return "";
36486
- let content = "";
36487
- try {
36488
- content = JSON.stringify(message.content ?? "");
36489
- } catch {
36490
- content = String(message.content ?? "");
36491
- }
36492
- return hashSignatureParts2([
36493
- String(message.id || ""),
36494
- String(message.index ?? ""),
36495
- String(message.role || ""),
36496
- String(message.receivedAt ?? message.timestamp ?? ""),
36497
- content
36498
- ]);
36597
+ return buildChatMessageSignature(message);
36499
36598
  }
36500
36599
  function normalizeReadChatCursor(args) {
36501
36600
  const knownMessageCount = Math.max(0, Number(args?.knownMessageCount || 0));
@@ -38529,27 +38628,7 @@ ${effect.notification.body || ""}`.trim();
38529
38628
  if (provider?.scripts) {
38530
38629
  const fn2 = provider.scripts[scriptName];
38531
38630
  if (typeof fn2 === "function") {
38532
- const callScript = fn2;
38533
- if (params && Object.keys(params).length > 0) {
38534
- const firstVal = Object.values(params)[0];
38535
- if (scriptName === "sendMessage" && typeof firstVal === "string") {
38536
- const legacyScript = callScript(firstVal);
38537
- if (legacyScript) return legacyScript;
38538
- }
38539
- const script = callScript(params);
38540
- if (script) {
38541
- const likelyLegacyObjectLeak = typeof script === "string" && script.includes("[object Object]") && typeof firstVal === "string";
38542
- if (!likelyLegacyObjectLeak) return script;
38543
- }
38544
- if (firstVal !== void 0) {
38545
- const legacyScript = callScript(firstVal);
38546
- if (legacyScript) return legacyScript;
38547
- }
38548
- if (script) return script;
38549
- } else {
38550
- const script = callScript();
38551
- if (script) return script;
38552
- }
38631
+ return resolveLegacyProviderScript(fn2, scriptName, params);
38553
38632
  }
38554
38633
  }
38555
38634
  return null;
@@ -39140,7 +39219,10 @@ ${effect.notification.body || ""}`.trim();
39140
39219
  const parsedStatus = this.adapter.getScriptParsedStatus?.() || null;
39141
39220
  const autoApproveActive = adapterStatus.status === "waiting_approval" && this.shouldAutoApprove();
39142
39221
  const visibleStatus = autoApproveActive ? "generating" : adapterStatus.status;
39143
- const parsedProviderSessionId = typeof parsedStatus?.providerSessionId === "string" ? parsedStatus.providerSessionId.trim() : "";
39222
+ const parsedProviderSessionId = normalizeProviderSessionId(
39223
+ this.type,
39224
+ typeof parsedStatus?.providerSessionId === "string" ? parsedStatus.providerSessionId : ""
39225
+ );
39144
39226
  if (parsedProviderSessionId) {
39145
39227
  this.promoteProviderSessionId(parsedProviderSessionId);
39146
39228
  }
@@ -39404,7 +39486,10 @@ ${effect.notification.body || ""}`.trim();
39404
39486
  }
39405
39487
  applyProviderResponse(data, options) {
39406
39488
  if (!data || typeof data !== "object") return;
39407
- const patchedProviderSessionId = typeof data.providerSessionId === "string" ? data.providerSessionId.trim() : "";
39489
+ const patchedProviderSessionId = normalizeProviderSessionId(
39490
+ this.type,
39491
+ typeof data.providerSessionId === "string" ? data.providerSessionId : ""
39492
+ );
39408
39493
  if (patchedProviderSessionId) {
39409
39494
  this.promoteProviderSessionId(patchedProviderSessionId);
39410
39495
  }
@@ -44945,6 +45030,139 @@ Run 'adhdev doctor' for detailed diagnostics.`
44945
45030
  init_logger();
44946
45031
  var DEFAULT_DAEMON_PORT = 19222;
44947
45032
  var DAEMON_WS_PATH = "/ipc";
45033
+ function normalizeSyncMode(syncMode) {
45034
+ return syncMode === "append" || syncMode === "replace_tail" || syncMode === "noop" || syncMode === "full" ? syncMode : "full";
45035
+ }
45036
+ function normalizeModalButtons(value) {
45037
+ return Array.isArray(value) ? value.filter((button) => typeof button === "string") : [];
45038
+ }
45039
+ function normalizeModalMessage(value) {
45040
+ return typeof value === "string" ? value : void 0;
45041
+ }
45042
+ function normalizeChatTailActiveModal(activeModal) {
45043
+ if (!activeModal || typeof activeModal !== "object") return null;
45044
+ const message = normalizeModalMessage(activeModal.message);
45045
+ if (!message) return null;
45046
+ const rawButtons = activeModal.buttons;
45047
+ if (!Array.isArray(rawButtons)) return null;
45048
+ return {
45049
+ message,
45050
+ buttons: normalizeModalButtons(rawButtons)
45051
+ };
45052
+ }
45053
+ function normalizeSessionModalFields(activeModal) {
45054
+ if (!activeModal || typeof activeModal !== "object") {
45055
+ return { modalButtons: [] };
45056
+ }
45057
+ return {
45058
+ modalMessage: normalizeModalMessage(activeModal.message),
45059
+ modalButtons: normalizeModalButtons(activeModal.buttons)
45060
+ };
45061
+ }
45062
+ function buildNextChatCursor(cursor, result) {
45063
+ return {
45064
+ knownMessageCount: Math.max(0, Number(result.totalMessages || cursor.knownMessageCount)),
45065
+ lastMessageSignature: typeof result.lastMessageSignature === "string" ? result.lastMessageSignature : cursor.lastMessageSignature,
45066
+ tailLimit: cursor.tailLimit
45067
+ };
45068
+ }
45069
+ function prepareSessionChatTailUpdate2(input) {
45070
+ const result = input.result;
45071
+ if (!result?.success || result.syncMode === "noop") {
45072
+ return {
45073
+ cursor: result?.success ? buildNextChatCursor(input.cursor, result) : input.cursor,
45074
+ seq: input.seq,
45075
+ lastDeliveredSignature: input.lastDeliveredSignature,
45076
+ update: null
45077
+ };
45078
+ }
45079
+ const syncMode = normalizeSyncMode(result.syncMode);
45080
+ const cursor = {
45081
+ knownMessageCount: Math.max(0, Number(result.totalMessages || 0)),
45082
+ lastMessageSignature: typeof result.lastMessageSignature === "string" ? result.lastMessageSignature : "",
45083
+ tailLimit: input.cursor.tailLimit
45084
+ };
45085
+ const title = typeof result.title === "string" ? result.title : void 0;
45086
+ const activeModal = normalizeChatTailActiveModal(result.activeModal);
45087
+ const status = typeof result.status === "string" ? result.status : "idle";
45088
+ const deliverySignature = buildChatTailDeliverySignature({
45089
+ sessionId: input.sessionId,
45090
+ ...input.historySessionId ? { historySessionId: input.historySessionId } : {},
45091
+ messages: Array.isArray(result.messages) ? result.messages : [],
45092
+ status,
45093
+ ...title ? { title } : {},
45094
+ ...activeModal ? { activeModal } : {},
45095
+ syncMode,
45096
+ replaceFrom: Number(result.replaceFrom || 0),
45097
+ totalMessages: Number(result.totalMessages || 0),
45098
+ lastMessageSignature: typeof result.lastMessageSignature === "string" ? result.lastMessageSignature : ""
45099
+ });
45100
+ const seq = input.seq + 1;
45101
+ if (deliverySignature === input.lastDeliveredSignature) {
45102
+ return {
45103
+ cursor,
45104
+ seq,
45105
+ lastDeliveredSignature: input.lastDeliveredSignature,
45106
+ update: null
45107
+ };
45108
+ }
45109
+ return {
45110
+ cursor,
45111
+ seq,
45112
+ lastDeliveredSignature: deliverySignature,
45113
+ update: {
45114
+ topic: "session.chat_tail",
45115
+ key: input.key,
45116
+ sessionId: input.sessionId,
45117
+ ...input.historySessionId ? { historySessionId: input.historySessionId } : {},
45118
+ ...input.interactionId ? { interactionId: input.interactionId } : {},
45119
+ seq,
45120
+ timestamp: input.timestamp,
45121
+ messages: Array.isArray(result.messages) ? result.messages : [],
45122
+ status,
45123
+ ...title ? { title } : {},
45124
+ ...activeModal ? { activeModal } : {},
45125
+ syncMode,
45126
+ replaceFrom: Number(result.replaceFrom || 0),
45127
+ totalMessages: Number(result.totalMessages || 0),
45128
+ lastMessageSignature: typeof result.lastMessageSignature === "string" ? result.lastMessageSignature : ""
45129
+ }
45130
+ };
45131
+ }
45132
+ function prepareSessionModalUpdate2(input) {
45133
+ const { modalMessage, modalButtons } = normalizeSessionModalFields(input.activeModal);
45134
+ const deliverySignature = buildSessionModalDeliverySignature({
45135
+ sessionId: input.sessionId,
45136
+ status: input.status,
45137
+ ...input.title ? { title: input.title } : {},
45138
+ ...modalMessage ? { modalMessage } : {},
45139
+ ...modalButtons.length > 0 ? { modalButtons } : {}
45140
+ });
45141
+ if (deliverySignature === input.lastDeliveredSignature) {
45142
+ return {
45143
+ seq: input.seq,
45144
+ lastDeliveredSignature: input.lastDeliveredSignature,
45145
+ update: null
45146
+ };
45147
+ }
45148
+ const seq = input.seq + 1;
45149
+ return {
45150
+ seq,
45151
+ lastDeliveredSignature: deliverySignature,
45152
+ update: {
45153
+ topic: "session.modal",
45154
+ key: input.key,
45155
+ sessionId: input.sessionId,
45156
+ status: input.status,
45157
+ ...input.title ? { title: input.title } : {},
45158
+ ...modalMessage ? { modalMessage } : {},
45159
+ ...modalButtons.length > 0 ? { modalButtons } : {},
45160
+ ...input.interactionId ? { interactionId: input.interactionId } : {},
45161
+ seq,
45162
+ timestamp: input.timestamp
45163
+ }
45164
+ };
45165
+ }
44948
45166
  init_read_chat_contract();
44949
45167
  init_chat_message_normalization();
44950
45168
  var ProviderStreamAdapter = class {
@@ -50112,7 +50330,8 @@ data: ${JSON.stringify(msg.data)}
50112
50330
  }
50113
50331
  async handleRunScript(type, req, res, parsedBody) {
50114
50332
  const body = parsedBody || await this.readBody(req);
50115
- const { script: scriptName, params, ideType: scriptIdeType } = body;
50333
+ const { script: scriptName, params, args, ideType: scriptIdeType } = body;
50334
+ const rawParams = args !== void 0 ? args : params;
50116
50335
  const provider = this.providerLoader.resolve(type);
50117
50336
  if (!provider) {
50118
50337
  this.json(res, 404, { error: `Provider '${type}' not found` });
@@ -50129,13 +50348,7 @@ data: ${JSON.stringify(msg.data)}
50129
50348
  return;
50130
50349
  }
50131
50350
  try {
50132
- let scriptCode = null;
50133
- if (["sendMessage", "webviewSendMessage", "switchSession", "webviewSwitchSession", "setMode", "webviewSetMode", "setModel", "webviewSetModel"].includes(scriptName)) {
50134
- const firstVal = params && typeof params === "object" && Object.keys(params).length > 0 ? Object.values(params)[0] : params;
50135
- scriptCode = firstVal !== void 0 ? fn2(firstVal) : fn2();
50136
- } else {
50137
- scriptCode = params !== void 0 ? fn2(params) : fn2();
50138
- }
50351
+ const scriptCode = resolveLegacyProviderScript(fn2, scriptName, rawParams);
50139
50352
  if (!scriptCode) {
50140
50353
  this.json(res, 500, { error: "Script function returned null" });
50141
50354
  return;
@@ -50152,6 +50365,17 @@ data: ${JSON.stringify(msg.data)}
50152
50365
  break;
50153
50366
  }
50154
50367
  }
50368
+ if (!sessionId) {
50369
+ try {
50370
+ const discovered = await cdp.discoverAgentWebviews();
50371
+ const target = discovered.find((entry) => entry.agentType === type);
50372
+ if (target) {
50373
+ sessionId = await cdp.attachToAgent(target);
50374
+ }
50375
+ } catch (error48) {
50376
+ this.log(`Extension attach fallback failed for ${type}: ${error48?.message || String(error48)}`);
50377
+ }
50378
+ }
50155
50379
  if (sessionId) {
50156
50380
  raw = await cdp.evaluateInSessionFrame(sessionId, scriptCode);
50157
50381
  } else if (cdp.evaluateInWebviewFrame) {
@@ -51714,10 +51938,19 @@ data: ${JSON.stringify(msg.data)}
51714
51938
  };
51715
51939
  var DEFAULT_SESSION_HOST_APP_NAME = "adhdev";
51716
51940
  var DEFAULT_STANDALONE_SESSION_HOST_APP_NAME = "adhdev-standalone";
51941
+ function validateStandaloneSessionHostAppName(explicit) {
51942
+ if (explicit !== DEFAULT_SESSION_HOST_APP_NAME) return;
51943
+ throw new Error(
51944
+ `Standalone session-host namespace '${DEFAULT_SESSION_HOST_APP_NAME}' is reserved for the global daemon. Use '${DEFAULT_STANDALONE_SESSION_HOST_APP_NAME}' or another non-default namespace.`
51945
+ );
51946
+ }
51717
51947
  function resolveSessionHostAppName2(options = {}) {
51718
51948
  const env = options.env || process.env;
51719
51949
  const explicit = typeof env.ADHDEV_SESSION_HOST_NAME === "string" ? env.ADHDEV_SESSION_HOST_NAME.trim() : "";
51720
- if (explicit) return explicit;
51950
+ if (explicit) {
51951
+ if (options.standalone) validateStandaloneSessionHostAppName(explicit);
51952
+ return explicit;
51953
+ }
51721
51954
  return options.standalone ? DEFAULT_STANDALONE_SESSION_HOST_APP_NAME : DEFAULT_SESSION_HOST_APP_NAME;
51722
51955
  }
51723
51956
  var import_session_host_core32 = require_dist();
@@ -52261,7 +52494,7 @@ var os5 = __toESM(require("os"));
52261
52494
  var import_daemon_core2 = __toESM(require_dist2());
52262
52495
 
52263
52496
  // src/session-host.ts
52264
- var import_child_process = require("child_process");
52497
+ var childProcess = __toESM(require("child_process"));
52265
52498
  var fs2 = __toESM(require("fs"));
52266
52499
  var os2 = __toESM(require("os"));
52267
52500
  var path = __toESM(require("path"));
@@ -52311,7 +52544,7 @@ function getSessionHostPidFile() {
52311
52544
  function killPid(pid) {
52312
52545
  try {
52313
52546
  if (process.platform === "win32") {
52314
- (0, import_child_process.execFileSync)("taskkill", ["/PID", String(pid), "/T", "/F"], { stdio: "ignore" });
52547
+ childProcess.execFileSync("taskkill", ["/PID", String(pid), "/T", "/F"], { stdio: "ignore" });
52315
52548
  } else {
52316
52549
  process.kill(pid, "SIGTERM");
52317
52550
  }
@@ -52320,13 +52553,13 @@ function killPid(pid) {
52320
52553
  return false;
52321
52554
  }
52322
52555
  }
52323
- function stopSessionHost() {
52556
+ function stopManagedSessionHostProcess() {
52324
52557
  let stopped = false;
52325
52558
  const pidFile = getSessionHostPidFile();
52326
52559
  try {
52327
52560
  if (fs2.existsSync(pidFile)) {
52328
52561
  const pid = Number.parseInt(fs2.readFileSync(pidFile, "utf8").trim(), 10);
52329
- if (Number.isFinite(pid)) {
52562
+ if (Number.isFinite(pid) && pid !== process.pid) {
52330
52563
  stopped = killPid(pid) || stopped;
52331
52564
  }
52332
52565
  }
@@ -52337,23 +52570,14 @@ function stopSessionHost() {
52337
52570
  } catch {
52338
52571
  }
52339
52572
  }
52340
- if (process.platform !== "win32") {
52341
- try {
52342
- const raw = (0, import_child_process.execFileSync)("pgrep", ["-f", "session-host-daemon"], { encoding: "utf8" }).trim();
52343
- for (const line of raw.split("\n")) {
52344
- const pid = Number.parseInt(line.trim(), 10);
52345
- if (Number.isFinite(pid)) {
52346
- stopped = killPid(pid) || stopped;
52347
- }
52348
- }
52349
- } catch {
52350
- }
52351
- }
52352
52573
  return stopped;
52353
52574
  }
52575
+ function stopSessionHost() {
52576
+ return stopManagedSessionHostProcess();
52577
+ }
52354
52578
  async function runSessionHostCli(args) {
52355
52579
  const entry = resolveSessionHostEntry();
52356
- const child = (0, import_child_process.spawn)(process.execPath, [entry, ...args], {
52580
+ const child = childProcess.spawn(process.execPath, [entry, ...args], {
52357
52581
  stdio: "inherit",
52358
52582
  env: buildSessionHostEnv(process.env)
52359
52583
  });
@@ -52365,7 +52589,7 @@ async function runSessionHostCli(args) {
52365
52589
  async function ensureSessionHostReady() {
52366
52590
  const spawnHost = () => {
52367
52591
  const entry = resolveSessionHostEntry();
52368
- const child = (0, import_child_process.spawn)(process.execPath, [entry], {
52592
+ const child = childProcess.spawn(process.execPath, [entry], {
52369
52593
  detached: true,
52370
52594
  stdio: "ignore",
52371
52595
  windowsHide: true,
@@ -52810,48 +53034,6 @@ var SESSION_TARGET_COMMANDS = /* @__PURE__ */ new Set([
52810
53034
  "restart_session",
52811
53035
  "agent_command"
52812
53036
  ]);
52813
- function hashSignatureParts(parts) {
52814
- let hash2 = 2166136261;
52815
- for (const part of parts) {
52816
- const text = String(part || "");
52817
- for (let i = 0; i < text.length; i += 1) {
52818
- hash2 ^= text.charCodeAt(i);
52819
- hash2 = Math.imul(hash2, 16777619) >>> 0;
52820
- }
52821
- hash2 ^= 255;
52822
- hash2 = Math.imul(hash2, 16777619) >>> 0;
52823
- }
52824
- return hash2.toString(16).padStart(8, "0");
52825
- }
52826
- function buildChatTailDeliverySignature(payload) {
52827
- let messages = "";
52828
- try {
52829
- messages = JSON.stringify(payload.messages);
52830
- } catch {
52831
- messages = String(payload.messages.length);
52832
- }
52833
- return hashSignatureParts([
52834
- payload.sessionId,
52835
- payload.historySessionId || "",
52836
- payload.status,
52837
- payload.title || "",
52838
- payload.syncMode,
52839
- String(payload.replaceFrom),
52840
- String(payload.totalMessages),
52841
- payload.lastMessageSignature,
52842
- payload.activeModal ? `${payload.activeModal.message}|${payload.activeModal.buttons.join("")}` : "",
52843
- messages
52844
- ]);
52845
- }
52846
- function buildSessionModalDeliverySignature(payload) {
52847
- return hashSignatureParts([
52848
- payload.sessionId,
52849
- payload.status,
52850
- payload.title || "",
52851
- payload.modalMessage || "",
52852
- Array.isArray(payload.modalButtons) ? payload.modalButtons.join("") : ""
52853
- ]);
52854
- }
52855
53037
  var StandaloneServer = class {
52856
53038
  httpServer = null;
52857
53039
  wss = null;
@@ -53537,59 +53719,20 @@ var StandaloneServer = class {
53537
53719
  lastMessageSignature: state.cursor.lastMessageSignature,
53538
53720
  ...state.cursor.tailLimit > 0 ? { tailLimit: state.cursor.tailLimit } : {}
53539
53721
  });
53540
- if (!result?.success || result.syncMode === "noop") {
53541
- if (result?.success) {
53542
- state.cursor = {
53543
- knownMessageCount: Math.max(0, Number(result.totalMessages || state.cursor.knownMessageCount)),
53544
- lastMessageSignature: typeof result.lastMessageSignature === "string" ? result.lastMessageSignature : state.cursor.lastMessageSignature,
53545
- tailLimit: state.cursor.tailLimit
53546
- };
53547
- }
53548
- return null;
53549
- }
53550
- state.seq += 1;
53551
- const syncMode = result.syncMode === "append" || result.syncMode === "replace_tail" || result.syncMode === "noop" || result.syncMode === "full" ? result.syncMode : "full";
53552
- state.cursor = {
53553
- knownMessageCount: Math.max(0, Number(result.totalMessages || 0)),
53554
- lastMessageSignature: typeof result.lastMessageSignature === "string" ? result.lastMessageSignature : "",
53555
- tailLimit: state.cursor.tailLimit
53556
- };
53557
- const activeModal = result.activeModal && typeof result.activeModal === "object" && typeof result.activeModal.message === "string" && Array.isArray(result.activeModal.buttons) ? {
53558
- message: result.activeModal.message,
53559
- buttons: result.activeModal.buttons.filter((button) => typeof button === "string")
53560
- } : null;
53561
- const deliverySignature = buildChatTailDeliverySignature({
53562
- sessionId: request.targetSessionId,
53563
- ...request.historySessionId ? { historySessionId: request.historySessionId } : {},
53564
- messages: Array.isArray(result.messages) ? result.messages : [],
53565
- status: typeof result.status === "string" ? result.status : "idle",
53566
- ...typeof result.title === "string" ? { title: result.title } : {},
53567
- ...activeModal ? { activeModal } : {},
53568
- syncMode,
53569
- replaceFrom: Number(result.replaceFrom || 0),
53570
- totalMessages: Number(result.totalMessages || 0),
53571
- lastMessageSignature: typeof result.lastMessageSignature === "string" ? result.lastMessageSignature : ""
53572
- });
53573
- if (deliverySignature === state.lastDeliveredSignature) {
53574
- return null;
53575
- }
53576
- state.lastDeliveredSignature = deliverySignature;
53577
- return {
53578
- topic: "session.chat_tail",
53722
+ const prepared = (0, import_daemon_core2.prepareSessionChatTailUpdate)({
53579
53723
  key,
53580
53724
  sessionId: request.targetSessionId,
53581
53725
  ...request.historySessionId ? { historySessionId: request.historySessionId } : {},
53582
53726
  seq: state.seq,
53583
53727
  timestamp: Date.now(),
53584
- messages: Array.isArray(result.messages) ? result.messages : [],
53585
- status: typeof result.status === "string" ? result.status : "idle",
53586
- ...typeof result.title === "string" ? { title: result.title } : {},
53587
- ...activeModal ? { activeModal } : {},
53588
- syncMode,
53589
- replaceFrom: Number(result.replaceFrom || 0),
53590
- totalMessages: Number(result.totalMessages || 0),
53591
- lastMessageSignature: typeof result.lastMessageSignature === "string" ? result.lastMessageSignature : ""
53592
- };
53728
+ cursor: state.cursor,
53729
+ lastDeliveredSignature: state.lastDeliveredSignature,
53730
+ result
53731
+ });
53732
+ state.cursor = prepared.cursor;
53733
+ state.seq = prepared.seq;
53734
+ state.lastDeliveredSignature = prepared.lastDeliveredSignature;
53735
+ return prepared.update;
53593
53736
  }
53594
53737
  getHotChatSessionIdsForWsFlush() {
53595
53738
  const snapshot = this.buildSharedSnapshot("live");
@@ -53716,35 +53859,26 @@ var StandaloneServer = class {
53716
53859
  const providerState = this.findProviderStateBySessionId(state.request.params.targetSessionId);
53717
53860
  if (!providerState) return null;
53718
53861
  const now = Date.now();
53719
- state.seq += 1;
53720
- state.lastSentAt = now;
53721
53862
  const activeModal = providerState.activeChat?.activeModal;
53722
- const modalButtons = Array.isArray(activeModal?.buttons) ? activeModal.buttons.filter((button) => typeof button === "string") : [];
53723
53863
  const status = String(providerState.activeChat?.status || providerState.status || "idle");
53724
53864
  const title = typeof providerState.activeChat?.title === "string" ? providerState.activeChat.title : void 0;
53725
- const modalMessage = typeof activeModal?.message === "string" ? activeModal.message : void 0;
53726
- const deliverySignature = buildSessionModalDeliverySignature({
53865
+ const prepared = (0, import_daemon_core2.prepareSessionModalUpdate)({
53866
+ key,
53727
53867
  sessionId: state.request.params.targetSessionId,
53728
53868
  status,
53729
- ...title ? { title } : {},
53730
- ...modalMessage ? { modalMessage } : {},
53731
- ...modalButtons.length > 0 ? { modalButtons } : {}
53869
+ title,
53870
+ activeModal,
53871
+ seq: state.seq,
53872
+ timestamp: now,
53873
+ lastDeliveredSignature: state.lastDeliveredSignature
53732
53874
  });
53733
- if (deliverySignature === state.lastDeliveredSignature) {
53875
+ state.seq = prepared.seq;
53876
+ state.lastDeliveredSignature = prepared.lastDeliveredSignature;
53877
+ if (!prepared.update) {
53734
53878
  return null;
53735
53879
  }
53736
- state.lastDeliveredSignature = deliverySignature;
53737
- return {
53738
- topic: "session.modal",
53739
- key,
53740
- sessionId: state.request.params.targetSessionId,
53741
- status,
53742
- ...title ? { title } : {},
53743
- ...modalMessage ? { modalMessage } : {},
53744
- ...modalButtons.length > 0 ? { modalButtons } : {},
53745
- seq: state.seq,
53746
- timestamp: now
53747
- };
53880
+ state.lastSentAt = now;
53881
+ return prepared.update;
53748
53882
  }
53749
53883
  async flushWsSessionModalSubscriptions(targetWs) {
53750
53884
  const targets = targetWs ? [targetWs] : Array.from(this.clients);