adhdev 0.8.70 → 0.8.73

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/cli/index.js CHANGED
@@ -1153,6 +1153,31 @@ var init_saved_sessions = __esm({
1153
1153
  }
1154
1154
  });
1155
1155
 
1156
+ // ../../oss/packages/daemon-core/src/providers/provider-session-id.ts
1157
+ function normalizeProviderSessionId(providerType, providerSessionId) {
1158
+ const normalizedProviderType = typeof providerType === "string" ? providerType.trim() : "";
1159
+ const normalizedId = typeof providerSessionId === "string" ? providerSessionId.trim() : "";
1160
+ if (!normalizedId) return "";
1161
+ const lowered = normalizedId.toLowerCase();
1162
+ if (lowered === "undefined" || lowered === "null") return "";
1163
+ if (normalizedProviderType === "hermes-cli" && !HERMES_SESSION_ID_RE.test(normalizedId)) {
1164
+ return "";
1165
+ }
1166
+ return normalizedId;
1167
+ }
1168
+ function isLegacyVolatileSessionReadKey(key) {
1169
+ const normalizedKey = typeof key === "string" ? key.trim() : "";
1170
+ if (!normalizedKey) return false;
1171
+ return normalizedKey.startsWith("provider:codex:vscode-webview://");
1172
+ }
1173
+ var HERMES_SESSION_ID_RE;
1174
+ var init_provider_session_id = __esm({
1175
+ "../../oss/packages/daemon-core/src/providers/provider-session-id.ts"() {
1176
+ "use strict";
1177
+ HERMES_SESSION_ID_RE = /^\d{8}_\d{6}_[a-z0-9]+$/i;
1178
+ }
1179
+ });
1180
+
1156
1181
  // ../../oss/packages/daemon-core/src/config/state-store.ts
1157
1182
  function isPlainObject2(value) {
1158
1183
  return !!value && typeof value === "object" && !Array.isArray(value);
@@ -1162,15 +1187,31 @@ function getStatePath() {
1162
1187
  }
1163
1188
  function normalizeState(raw) {
1164
1189
  const parsed = isPlainObject2(raw) ? raw : {};
1190
+ const recentActivity = (Array.isArray(parsed.recentActivity) ? parsed.recentActivity : []).filter((entry) => {
1191
+ if (!isPlainObject2(entry)) return false;
1192
+ const normalizedId = normalizeProviderSessionId(
1193
+ typeof entry.providerType === "string" ? entry.providerType : "",
1194
+ typeof entry.providerSessionId === "string" ? entry.providerSessionId : ""
1195
+ );
1196
+ if (typeof entry.providerSessionId === "string" && !normalizedId) return false;
1197
+ return true;
1198
+ });
1199
+ const savedProviderSessions = (Array.isArray(parsed.savedProviderSessions) ? parsed.savedProviderSessions : []).filter((entry) => {
1200
+ if (!isPlainObject2(entry)) return false;
1201
+ return !!normalizeProviderSessionId(
1202
+ typeof entry.providerType === "string" ? entry.providerType : "",
1203
+ typeof entry.providerSessionId === "string" ? entry.providerSessionId : ""
1204
+ );
1205
+ });
1165
1206
  const sessionReads = Object.fromEntries(
1166
- Object.entries(isPlainObject2(parsed.sessionReads) ? parsed.sessionReads : {}).filter(([, value]) => typeof value === "number" && Number.isFinite(value))
1207
+ Object.entries(isPlainObject2(parsed.sessionReads) ? parsed.sessionReads : {}).filter(([key, value]) => !isLegacyVolatileSessionReadKey(key) && typeof value === "number" && Number.isFinite(value))
1167
1208
  );
1168
1209
  const sessionReadMarkers = Object.fromEntries(
1169
- Object.entries(isPlainObject2(parsed.sessionReadMarkers) ? parsed.sessionReadMarkers : {}).filter(([, value]) => typeof value === "string")
1210
+ Object.entries(isPlainObject2(parsed.sessionReadMarkers) ? parsed.sessionReadMarkers : {}).filter(([key, value]) => !isLegacyVolatileSessionReadKey(key) && typeof value === "string")
1170
1211
  );
1171
1212
  return {
1172
- recentActivity: Array.isArray(parsed.recentActivity) ? parsed.recentActivity : [],
1173
- savedProviderSessions: Array.isArray(parsed.savedProviderSessions) ? parsed.savedProviderSessions : [],
1213
+ recentActivity,
1214
+ savedProviderSessions,
1174
1215
  sessionReads,
1175
1216
  sessionReadMarkers
1176
1217
  };
@@ -1202,6 +1243,7 @@ var init_state_store = __esm({
1202
1243
  import_fs2 = require("fs");
1203
1244
  import_path2 = require("path");
1204
1245
  init_config();
1246
+ init_provider_session_id();
1205
1247
  DEFAULT_STATE = {
1206
1248
  recentActivity: [],
1207
1249
  savedProviderSessions: [],
@@ -6382,6 +6424,37 @@ var init_reconcile = __esm({
6382
6424
  }
6383
6425
  });
6384
6426
 
6427
+ // ../../oss/packages/daemon-core/src/commands/provider-script-resolver.ts
6428
+ function resolveLegacyProviderScript(fn, scriptName, params) {
6429
+ if (typeof fn !== "function") return null;
6430
+ if (params && typeof params === "object" && !Array.isArray(params) && Object.keys(params).length > 0) {
6431
+ const firstVal = Object.values(params)[0];
6432
+ if (scriptName === "sendMessage" && typeof firstVal === "string") {
6433
+ const legacyScript = fn(firstVal);
6434
+ if (legacyScript) return legacyScript;
6435
+ }
6436
+ const script = fn(params);
6437
+ const likelyLegacyObjectLeak = typeof script === "string" && script.includes("[object Object]") && typeof firstVal === "string";
6438
+ if (!likelyLegacyObjectLeak && script) return script;
6439
+ if (firstVal !== void 0) {
6440
+ const legacyScript = fn(firstVal);
6441
+ if (legacyScript) return legacyScript;
6442
+ }
6443
+ if (script) return script;
6444
+ return null;
6445
+ }
6446
+ if (params !== void 0) {
6447
+ const script = fn(params);
6448
+ if (script) return script;
6449
+ }
6450
+ return fn() || null;
6451
+ }
6452
+ var init_provider_script_resolver = __esm({
6453
+ "../../oss/packages/daemon-core/src/commands/provider-script-resolver.ts"() {
6454
+ "use strict";
6455
+ }
6456
+ });
6457
+
6385
6458
  // ../../oss/packages/daemon-core/src/providers/provider-input-support.ts
6386
6459
  function getProviderLabel(provider) {
6387
6460
  return provider?.name || provider?.type || "This provider";
@@ -6582,7 +6655,7 @@ var init_debug_trace = __esm({
6582
6655
  }
6583
6656
  });
6584
6657
 
6585
- // ../../oss/packages/daemon-core/src/commands/chat-commands.ts
6658
+ // ../../oss/packages/daemon-core/src/chat/chat-signatures.ts
6586
6659
  function hashSignatureParts(parts) {
6587
6660
  let hash2 = 2166136261;
6588
6661
  for (const part of parts) {
@@ -6596,6 +6669,60 @@ function hashSignatureParts(parts) {
6596
6669
  }
6597
6670
  return hash2.toString(16).padStart(8, "0");
6598
6671
  }
6672
+ function stringifySignatureContent(content) {
6673
+ try {
6674
+ return JSON.stringify(content ?? "");
6675
+ } catch {
6676
+ return String(content ?? "");
6677
+ }
6678
+ }
6679
+ function stringifySignatureMessages(messages) {
6680
+ try {
6681
+ return JSON.stringify(messages);
6682
+ } catch {
6683
+ return String(messages.length);
6684
+ }
6685
+ }
6686
+ function buildChatMessageSignature(message) {
6687
+ if (!message) return "";
6688
+ return hashSignatureParts([
6689
+ String(message.id || ""),
6690
+ String(message.index ?? ""),
6691
+ String(message.role || ""),
6692
+ String(message.receivedAt ?? message.timestamp ?? ""),
6693
+ stringifySignatureContent(message.content)
6694
+ ]);
6695
+ }
6696
+ function buildChatTailDeliverySignature(payload) {
6697
+ return hashSignatureParts([
6698
+ payload.sessionId,
6699
+ payload.historySessionId || "",
6700
+ payload.status,
6701
+ payload.title || "",
6702
+ payload.syncMode,
6703
+ String(payload.replaceFrom),
6704
+ String(payload.totalMessages),
6705
+ payload.lastMessageSignature,
6706
+ payload.activeModal ? `${payload.activeModal.message}|${payload.activeModal.buttons.join("")}` : "",
6707
+ stringifySignatureMessages(payload.messages)
6708
+ ]);
6709
+ }
6710
+ function buildSessionModalDeliverySignature(payload) {
6711
+ return hashSignatureParts([
6712
+ payload.sessionId,
6713
+ payload.status,
6714
+ payload.title || "",
6715
+ payload.modalMessage || "",
6716
+ Array.isArray(payload.modalButtons) ? payload.modalButtons.join("") : ""
6717
+ ]);
6718
+ }
6719
+ var init_chat_signatures = __esm({
6720
+ "../../oss/packages/daemon-core/src/chat/chat-signatures.ts"() {
6721
+ "use strict";
6722
+ }
6723
+ });
6724
+
6725
+ // ../../oss/packages/daemon-core/src/commands/chat-commands.ts
6599
6726
  function getCurrentProviderType(h, fallback2 = "") {
6600
6727
  return h.currentSession?.providerType || h.currentProviderType || fallback2;
6601
6728
  }
@@ -6692,20 +6819,7 @@ function parseMaybeJson(value) {
6692
6819
  }
6693
6820
  }
6694
6821
  function getChatMessageSignature(message) {
6695
- if (!message) return "";
6696
- let content = "";
6697
- try {
6698
- content = JSON.stringify(message.content ?? "");
6699
- } catch {
6700
- content = String(message.content ?? "");
6701
- }
6702
- return hashSignatureParts([
6703
- String(message.id || ""),
6704
- String(message.index ?? ""),
6705
- String(message.role || ""),
6706
- String(message.receivedAt ?? message.timestamp ?? ""),
6707
- content
6708
- ]);
6822
+ return buildChatMessageSignature(message);
6709
6823
  }
6710
6824
  function normalizeReadChatCursor(args) {
6711
6825
  const knownMessageCount = Math.max(0, Number(args?.knownMessageCount || 0));
@@ -7728,6 +7842,7 @@ var init_chat_commands = __esm({
7728
7842
  init_chat_history();
7729
7843
  init_logger();
7730
7844
  init_debug_trace();
7845
+ init_chat_signatures();
7731
7846
  init_chat_message_normalization();
7732
7847
  RECENT_SEND_WINDOW_MS = 1200;
7733
7848
  recentSendByTarget = /* @__PURE__ */ new Map();
@@ -8734,6 +8849,7 @@ var init_handler = __esm({
8734
8849
  init_chat_history();
8735
8850
  init_reconcile();
8736
8851
  init_logger();
8852
+ init_provider_script_resolver();
8737
8853
  init_chat_commands();
8738
8854
  init_cdp_commands();
8739
8855
  init_stream_commands();
@@ -8809,27 +8925,7 @@ var init_handler = __esm({
8809
8925
  if (provider?.scripts) {
8810
8926
  const fn = provider.scripts[scriptName];
8811
8927
  if (typeof fn === "function") {
8812
- const callScript = fn;
8813
- if (params && Object.keys(params).length > 0) {
8814
- const firstVal = Object.values(params)[0];
8815
- if (scriptName === "sendMessage" && typeof firstVal === "string") {
8816
- const legacyScript = callScript(firstVal);
8817
- if (legacyScript) return legacyScript;
8818
- }
8819
- const script = callScript(params);
8820
- if (script) {
8821
- const likelyLegacyObjectLeak = typeof script === "string" && script.includes("[object Object]") && typeof firstVal === "string";
8822
- if (!likelyLegacyObjectLeak) return script;
8823
- }
8824
- if (firstVal !== void 0) {
8825
- const legacyScript = callScript(firstVal);
8826
- if (legacyScript) return legacyScript;
8827
- }
8828
- if (script) return script;
8829
- } else {
8830
- const script = callScript();
8831
- if (script) return script;
8832
- }
8928
+ return resolveLegacyProviderScript(fn, scriptName, params);
8833
8929
  }
8834
8930
  }
8835
8931
  return null;
@@ -12995,6 +13091,7 @@ var init_cli_provider_instance = __esm({
12995
13091
  init_approval_utils();
12996
13092
  init_cli_script_results();
12997
13093
  init_provider_patch_state();
13094
+ init_provider_session_id();
12998
13095
  init_chat_message_normalization();
12999
13096
  CachedDatabaseSync = null;
13000
13097
  CliProviderInstance = class {
@@ -13157,7 +13254,10 @@ var init_cli_provider_instance = __esm({
13157
13254
  const parsedStatus = this.adapter.getScriptParsedStatus?.() || null;
13158
13255
  const autoApproveActive = adapterStatus.status === "waiting_approval" && this.shouldAutoApprove();
13159
13256
  const visibleStatus = autoApproveActive ? "generating" : adapterStatus.status;
13160
- const parsedProviderSessionId = typeof parsedStatus?.providerSessionId === "string" ? parsedStatus.providerSessionId.trim() : "";
13257
+ const parsedProviderSessionId = normalizeProviderSessionId(
13258
+ this.type,
13259
+ typeof parsedStatus?.providerSessionId === "string" ? parsedStatus.providerSessionId : ""
13260
+ );
13161
13261
  if (parsedProviderSessionId) {
13162
13262
  this.promoteProviderSessionId(parsedProviderSessionId);
13163
13263
  }
@@ -13421,7 +13521,10 @@ var init_cli_provider_instance = __esm({
13421
13521
  }
13422
13522
  applyProviderResponse(data, options) {
13423
13523
  if (!data || typeof data !== "object") return;
13424
- const patchedProviderSessionId = typeof data.providerSessionId === "string" ? data.providerSessionId.trim() : "";
13524
+ const patchedProviderSessionId = normalizeProviderSessionId(
13525
+ this.type,
13526
+ typeof data.providerSessionId === "string" ? data.providerSessionId : ""
13527
+ );
13425
13528
  if (patchedProviderSessionId) {
13426
13529
  this.promoteProviderSessionId(patchedProviderSessionId);
13427
13530
  }
@@ -37165,6 +37268,147 @@ var init_ipc_protocol = __esm({
37165
37268
  }
37166
37269
  });
37167
37270
 
37271
+ // ../../oss/packages/daemon-core/src/chat/subscription-updates.ts
37272
+ function normalizeSyncMode(syncMode) {
37273
+ return syncMode === "append" || syncMode === "replace_tail" || syncMode === "noop" || syncMode === "full" ? syncMode : "full";
37274
+ }
37275
+ function normalizeModalButtons(value) {
37276
+ return Array.isArray(value) ? value.filter((button) => typeof button === "string") : [];
37277
+ }
37278
+ function normalizeModalMessage(value) {
37279
+ return typeof value === "string" ? value : void 0;
37280
+ }
37281
+ function normalizeChatTailActiveModal(activeModal) {
37282
+ if (!activeModal || typeof activeModal !== "object") return null;
37283
+ const message = normalizeModalMessage(activeModal.message);
37284
+ if (!message) return null;
37285
+ const rawButtons = activeModal.buttons;
37286
+ if (!Array.isArray(rawButtons)) return null;
37287
+ return {
37288
+ message,
37289
+ buttons: normalizeModalButtons(rawButtons)
37290
+ };
37291
+ }
37292
+ function normalizeSessionModalFields(activeModal) {
37293
+ if (!activeModal || typeof activeModal !== "object") {
37294
+ return { modalButtons: [] };
37295
+ }
37296
+ return {
37297
+ modalMessage: normalizeModalMessage(activeModal.message),
37298
+ modalButtons: normalizeModalButtons(activeModal.buttons)
37299
+ };
37300
+ }
37301
+ function buildNextChatCursor(cursor, result) {
37302
+ return {
37303
+ knownMessageCount: Math.max(0, Number(result.totalMessages || cursor.knownMessageCount)),
37304
+ lastMessageSignature: typeof result.lastMessageSignature === "string" ? result.lastMessageSignature : cursor.lastMessageSignature,
37305
+ tailLimit: cursor.tailLimit
37306
+ };
37307
+ }
37308
+ function prepareSessionChatTailUpdate(input) {
37309
+ const result = input.result;
37310
+ if (!result?.success || result.syncMode === "noop") {
37311
+ return {
37312
+ cursor: result?.success ? buildNextChatCursor(input.cursor, result) : input.cursor,
37313
+ seq: input.seq,
37314
+ lastDeliveredSignature: input.lastDeliveredSignature,
37315
+ update: null
37316
+ };
37317
+ }
37318
+ const syncMode = normalizeSyncMode(result.syncMode);
37319
+ const cursor = {
37320
+ knownMessageCount: Math.max(0, Number(result.totalMessages || 0)),
37321
+ lastMessageSignature: typeof result.lastMessageSignature === "string" ? result.lastMessageSignature : "",
37322
+ tailLimit: input.cursor.tailLimit
37323
+ };
37324
+ const title = typeof result.title === "string" ? result.title : void 0;
37325
+ const activeModal = normalizeChatTailActiveModal(result.activeModal);
37326
+ const status = typeof result.status === "string" ? result.status : "idle";
37327
+ const deliverySignature = buildChatTailDeliverySignature({
37328
+ sessionId: input.sessionId,
37329
+ ...input.historySessionId ? { historySessionId: input.historySessionId } : {},
37330
+ messages: Array.isArray(result.messages) ? result.messages : [],
37331
+ status,
37332
+ ...title ? { title } : {},
37333
+ ...activeModal ? { activeModal } : {},
37334
+ syncMode,
37335
+ replaceFrom: Number(result.replaceFrom || 0),
37336
+ totalMessages: Number(result.totalMessages || 0),
37337
+ lastMessageSignature: typeof result.lastMessageSignature === "string" ? result.lastMessageSignature : ""
37338
+ });
37339
+ const seq = input.seq + 1;
37340
+ if (deliverySignature === input.lastDeliveredSignature) {
37341
+ return {
37342
+ cursor,
37343
+ seq,
37344
+ lastDeliveredSignature: input.lastDeliveredSignature,
37345
+ update: null
37346
+ };
37347
+ }
37348
+ return {
37349
+ cursor,
37350
+ seq,
37351
+ lastDeliveredSignature: deliverySignature,
37352
+ update: {
37353
+ topic: "session.chat_tail",
37354
+ key: input.key,
37355
+ sessionId: input.sessionId,
37356
+ ...input.historySessionId ? { historySessionId: input.historySessionId } : {},
37357
+ ...input.interactionId ? { interactionId: input.interactionId } : {},
37358
+ seq,
37359
+ timestamp: input.timestamp,
37360
+ messages: Array.isArray(result.messages) ? result.messages : [],
37361
+ status,
37362
+ ...title ? { title } : {},
37363
+ ...activeModal ? { activeModal } : {},
37364
+ syncMode,
37365
+ replaceFrom: Number(result.replaceFrom || 0),
37366
+ totalMessages: Number(result.totalMessages || 0),
37367
+ lastMessageSignature: typeof result.lastMessageSignature === "string" ? result.lastMessageSignature : ""
37368
+ }
37369
+ };
37370
+ }
37371
+ function prepareSessionModalUpdate(input) {
37372
+ const { modalMessage, modalButtons } = normalizeSessionModalFields(input.activeModal);
37373
+ const deliverySignature = buildSessionModalDeliverySignature({
37374
+ sessionId: input.sessionId,
37375
+ status: input.status,
37376
+ ...input.title ? { title: input.title } : {},
37377
+ ...modalMessage ? { modalMessage } : {},
37378
+ ...modalButtons.length > 0 ? { modalButtons } : {}
37379
+ });
37380
+ if (deliverySignature === input.lastDeliveredSignature) {
37381
+ return {
37382
+ seq: input.seq,
37383
+ lastDeliveredSignature: input.lastDeliveredSignature,
37384
+ update: null
37385
+ };
37386
+ }
37387
+ const seq = input.seq + 1;
37388
+ return {
37389
+ seq,
37390
+ lastDeliveredSignature: deliverySignature,
37391
+ update: {
37392
+ topic: "session.modal",
37393
+ key: input.key,
37394
+ sessionId: input.sessionId,
37395
+ status: input.status,
37396
+ ...input.title ? { title: input.title } : {},
37397
+ ...modalMessage ? { modalMessage } : {},
37398
+ ...modalButtons.length > 0 ? { modalButtons } : {},
37399
+ ...input.interactionId ? { interactionId: input.interactionId } : {},
37400
+ seq,
37401
+ timestamp: input.timestamp
37402
+ }
37403
+ };
37404
+ }
37405
+ var init_subscription_updates = __esm({
37406
+ "../../oss/packages/daemon-core/src/chat/subscription-updates.ts"() {
37407
+ "use strict";
37408
+ init_chat_signatures();
37409
+ }
37410
+ });
37411
+
37168
37412
  // ../../oss/packages/daemon-core/src/agent-stream/provider-adapter.ts
37169
37413
  var ProviderStreamAdapter;
37170
37414
  var init_provider_adapter = __esm({
@@ -42184,6 +42428,7 @@ var init_dev_server = __esm({
42184
42428
  init_logger();
42185
42429
  init_builders();
42186
42430
  init_dev_cdp_handlers();
42431
+ init_provider_script_resolver();
42187
42432
  init_dev_cli_debug();
42188
42433
  init_dev_auto_implement();
42189
42434
  DEV_SERVER_PORT = 19280;
@@ -42447,7 +42692,8 @@ var init_dev_server = __esm({
42447
42692
  }
42448
42693
  async handleRunScript(type, req, res, parsedBody) {
42449
42694
  const body = parsedBody || await this.readBody(req);
42450
- const { script: scriptName, params, ideType: scriptIdeType } = body;
42695
+ const { script: scriptName, params, args, ideType: scriptIdeType } = body;
42696
+ const rawParams = args !== void 0 ? args : params;
42451
42697
  const provider = this.providerLoader.resolve(type);
42452
42698
  if (!provider) {
42453
42699
  this.json(res, 404, { error: `Provider '${type}' not found` });
@@ -42464,13 +42710,7 @@ var init_dev_server = __esm({
42464
42710
  return;
42465
42711
  }
42466
42712
  try {
42467
- let scriptCode = null;
42468
- if (["sendMessage", "webviewSendMessage", "switchSession", "webviewSwitchSession", "setMode", "webviewSetMode", "setModel", "webviewSetModel"].includes(scriptName)) {
42469
- const firstVal = params && typeof params === "object" && Object.keys(params).length > 0 ? Object.values(params)[0] : params;
42470
- scriptCode = firstVal !== void 0 ? fn(firstVal) : fn();
42471
- } else {
42472
- scriptCode = params !== void 0 ? fn(params) : fn();
42473
- }
42713
+ const scriptCode = resolveLegacyProviderScript(fn, scriptName, rawParams);
42474
42714
  if (!scriptCode) {
42475
42715
  this.json(res, 500, { error: "Script function returned null" });
42476
42716
  return;
@@ -42487,6 +42727,17 @@ var init_dev_server = __esm({
42487
42727
  break;
42488
42728
  }
42489
42729
  }
42730
+ if (!sessionId) {
42731
+ try {
42732
+ const discovered = await cdp.discoverAgentWebviews();
42733
+ const target = discovered.find((entry) => entry.agentType === type);
42734
+ if (target) {
42735
+ sessionId = await cdp.attachToAgent(target);
42736
+ }
42737
+ } catch (error48) {
42738
+ this.log(`Extension attach fallback failed for ${type}: ${error48?.message || String(error48)}`);
42739
+ }
42740
+ }
42490
42741
  if (sessionId) {
42491
42742
  raw = await cdp.evaluateInSessionFrame(sessionId, scriptCode);
42492
42743
  } else if (cdp.evaluateInWebviewFrame) {
@@ -44057,10 +44308,19 @@ var init_session_host_transport = __esm({
44057
44308
  });
44058
44309
 
44059
44310
  // ../../oss/packages/daemon-core/src/session-host/app-name.ts
44311
+ function validateStandaloneSessionHostAppName(explicit) {
44312
+ if (explicit !== DEFAULT_SESSION_HOST_APP_NAME) return;
44313
+ throw new Error(
44314
+ `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.`
44315
+ );
44316
+ }
44060
44317
  function resolveSessionHostAppName(options = {}) {
44061
44318
  const env3 = options.env || process.env;
44062
44319
  const explicit = typeof env3.ADHDEV_SESSION_HOST_NAME === "string" ? env3.ADHDEV_SESSION_HOST_NAME.trim() : "";
44063
- if (explicit) return explicit;
44320
+ if (explicit) {
44321
+ if (options.standalone) validateStandaloneSessionHostAppName(explicit);
44322
+ return explicit;
44323
+ }
44064
44324
  return options.standalone ? DEFAULT_STANDALONE_SESSION_HOST_APP_NAME : DEFAULT_SESSION_HOST_APP_NAME;
44065
44325
  }
44066
44326
  var DEFAULT_SESSION_HOST_APP_NAME, DEFAULT_STANDALONE_SESSION_HOST_APP_NAME;
@@ -44687,9 +44947,12 @@ __export(src_exports, {
44687
44947
  appendRecentActivity: () => appendRecentActivity,
44688
44948
  buildAssistantChatMessage: () => buildAssistantChatMessage,
44689
44949
  buildChatMessage: () => buildChatMessage,
44950
+ buildChatMessageSignature: () => buildChatMessageSignature,
44951
+ buildChatTailDeliverySignature: () => buildChatTailDeliverySignature,
44690
44952
  buildMachineInfo: () => buildMachineInfo,
44691
44953
  buildRuntimeSystemChatMessage: () => buildRuntimeSystemChatMessage,
44692
44954
  buildSessionEntries: () => buildSessionEntries,
44955
+ buildSessionModalDeliverySignature: () => buildSessionModalDeliverySignature,
44693
44956
  buildStatusSnapshot: () => buildStatusSnapshot,
44694
44957
  buildSystemChatMessage: () => buildSystemChatMessage,
44695
44958
  buildTerminalChatMessage: () => buildTerminalChatMessage,
@@ -44725,6 +44988,7 @@ __export(src_exports, {
44725
44988
  getSessionHostSurfaceKind: () => getSessionHostSurfaceKind2,
44726
44989
  getWorkspaceState: () => getWorkspaceState,
44727
44990
  hasCdpManager: () => hasCdpManager,
44991
+ hashSignatureParts: () => hashSignatureParts,
44728
44992
  initDaemonComponents: () => initDaemonComponents,
44729
44993
  installExtensions: () => installExtensions,
44730
44994
  installGlobalInterceptor: () => installGlobalInterceptor,
@@ -44750,12 +45014,16 @@ __export(src_exports, {
44750
45014
  normalizeChatMessage: () => normalizeChatMessage,
44751
45015
  normalizeChatMessageKind: () => normalizeChatMessageKind,
44752
45016
  normalizeChatMessages: () => normalizeChatMessages,
45017
+ normalizeChatTailActiveModal: () => normalizeChatTailActiveModal,
44753
45018
  normalizeInputEnvelope: () => normalizeInputEnvelope,
44754
45019
  normalizeManagedStatus: () => normalizeManagedStatus,
44755
45020
  normalizeMessageParts: () => normalizeMessageParts,
45021
+ normalizeSessionModalFields: () => normalizeSessionModalFields,
44756
45022
  parseProviderSourceConfigUpdate: () => parseProviderSourceConfigUpdate,
44757
45023
  partitionSessionHostDiagnosticsSessions: () => partitionSessionHostDiagnosticsSessions,
44758
45024
  partitionSessionHostRecords: () => partitionSessionHostRecords,
45025
+ prepareSessionChatTailUpdate: () => prepareSessionChatTailUpdate,
45026
+ prepareSessionModalUpdate: () => prepareSessionModalUpdate,
44759
45027
  probeCdpPort: () => probeCdpPort,
44760
45028
  readChatHistory: () => readChatHistory,
44761
45029
  recordDebugTrace: () => recordDebugTrace,
@@ -44811,6 +45079,8 @@ var init_src = __esm({
44811
45079
  init_launch();
44812
45080
  init_ipc_protocol();
44813
45081
  init_chat_history();
45082
+ init_chat_signatures();
45083
+ init_subscription_updates();
44814
45084
  init_agent_stream();
44815
45085
  init_agent_stream();
44816
45086
  init_forward();
@@ -84745,48 +85015,6 @@ __export(adhdev_daemon_exports, {
84745
85015
  isDaemonRunning: () => isDaemonRunning,
84746
85016
  stopDaemon: () => stopDaemon
84747
85017
  });
84748
- function hashSignatureParts2(parts) {
84749
- let hash2 = 2166136261;
84750
- for (const part of parts) {
84751
- const text = String(part || "");
84752
- for (let i = 0; i < text.length; i += 1) {
84753
- hash2 ^= text.charCodeAt(i);
84754
- hash2 = Math.imul(hash2, 16777619) >>> 0;
84755
- }
84756
- hash2 ^= 255;
84757
- hash2 = Math.imul(hash2, 16777619) >>> 0;
84758
- }
84759
- return hash2.toString(16).padStart(8, "0");
84760
- }
84761
- function buildChatTailDeliverySignature(payload) {
84762
- let messages = "";
84763
- try {
84764
- messages = JSON.stringify(payload.messages);
84765
- } catch {
84766
- messages = String(payload.messages.length);
84767
- }
84768
- return hashSignatureParts2([
84769
- payload.sessionId,
84770
- payload.historySessionId || "",
84771
- payload.status,
84772
- payload.title || "",
84773
- payload.syncMode,
84774
- String(payload.replaceFrom),
84775
- String(payload.totalMessages),
84776
- payload.lastMessageSignature,
84777
- payload.activeModal ? `${payload.activeModal.message}|${payload.activeModal.buttons.join("")}` : "",
84778
- messages
84779
- ]);
84780
- }
84781
- function buildSessionModalDeliverySignature(payload) {
84782
- return hashSignatureParts2([
84783
- payload.sessionId,
84784
- payload.status,
84785
- payload.title || "",
84786
- payload.modalMessage || "",
84787
- Array.isArray(payload.modalButtons) ? payload.modalButtons.join("") : ""
84788
- ]);
84789
- }
84790
85018
  function resolveDaemonPort(ref = {}) {
84791
85019
  return Number.isFinite(ref.port) && Number(ref.port) > 0 ? Number(ref.port) : DEFAULT_DAEMON_PORT;
84792
85020
  }
@@ -84919,7 +85147,7 @@ var init_adhdev_daemon = __esm({
84919
85147
  init_source();
84920
85148
  init_version();
84921
85149
  init_src();
84922
- pkgVersion = resolvePackageVersion({ injectedVersion: "0.8.70" });
85150
+ pkgVersion = resolvePackageVersion({ injectedVersion: "0.8.73" });
84923
85151
  AdhdevDaemon = class _AdhdevDaemon {
84924
85152
  localHttpServer = null;
84925
85153
  localWss = null;
@@ -85060,44 +85288,24 @@ var init_adhdev_daemon = __esm({
85060
85288
  lastMessageSignature: subscription.cursor.lastMessageSignature,
85061
85289
  ...subscription.cursor.tailLimit > 0 ? { tailLimit: subscription.cursor.tailLimit } : {}
85062
85290
  }, "p2p");
85063
- if (!result?.success || result.syncMode === "noop") {
85064
- if (result?.success) {
85065
- subscription.cursor = {
85066
- knownMessageCount: Math.max(0, Number(result.totalMessages || subscription.cursor.knownMessageCount)),
85067
- lastMessageSignature: typeof result.lastMessageSignature === "string" ? result.lastMessageSignature : subscription.cursor.lastMessageSignature,
85068
- tailLimit: subscription.cursor.tailLimit
85069
- };
85070
- }
85071
- return null;
85072
- }
85073
- subscription.seq += 1;
85074
- const syncMode = result.syncMode === "append" || result.syncMode === "replace_tail" || result.syncMode === "noop" || result.syncMode === "full" ? result.syncMode : "full";
85075
- subscription.cursor = {
85076
- knownMessageCount: Math.max(0, Number(result.totalMessages || 0)),
85077
- lastMessageSignature: typeof result.lastMessageSignature === "string" ? result.lastMessageSignature : "",
85078
- tailLimit: subscription.cursor.tailLimit
85079
- };
85080
- const activeModal = result.activeModal && typeof result.activeModal === "object" && typeof result.activeModal.message === "string" && Array.isArray(result.activeModal.buttons) ? {
85081
- message: result.activeModal.message,
85082
- buttons: result.activeModal.buttons.filter((button) => typeof button === "string")
85083
- } : null;
85084
- const deliverySignature = buildChatTailDeliverySignature({
85291
+ const interactionId = this.getSessionInteractionId(subscription.params.targetSessionId);
85292
+ const prepared = prepareSessionChatTailUpdate({
85293
+ key: subscription.key,
85085
85294
  sessionId: subscription.params.targetSessionId,
85086
85295
  ...subscription.params.historySessionId ? { historySessionId: subscription.params.historySessionId } : {},
85087
- messages: Array.isArray(result.messages) ? result.messages : [],
85088
- status: typeof result.status === "string" ? result.status : "idle",
85089
- ...typeof result.title === "string" ? { title: result.title } : {},
85090
- ...activeModal ? { activeModal } : {},
85091
- syncMode,
85092
- replaceFrom: Number(result.replaceFrom || 0),
85093
- totalMessages: Number(result.totalMessages || 0),
85094
- lastMessageSignature: typeof result.lastMessageSignature === "string" ? result.lastMessageSignature : ""
85296
+ seq: subscription.seq,
85297
+ timestamp: Date.now(),
85298
+ ...interactionId ? { interactionId } : {},
85299
+ cursor: subscription.cursor,
85300
+ lastDeliveredSignature: subscription.lastDeliveredSignature,
85301
+ result
85095
85302
  });
85096
- if (deliverySignature === subscription.lastDeliveredSignature) {
85303
+ subscription.cursor = prepared.cursor;
85304
+ subscription.seq = prepared.seq;
85305
+ subscription.lastDeliveredSignature = prepared.lastDeliveredSignature;
85306
+ if (!prepared.update) {
85097
85307
  return null;
85098
85308
  }
85099
- subscription.lastDeliveredSignature = deliverySignature;
85100
- const interactionId = this.getSessionInteractionId(subscription.params.targetSessionId);
85101
85309
  recordDebugTrace({
85102
85310
  interactionId,
85103
85311
  category: "topic",
@@ -85105,30 +85313,14 @@ var init_adhdev_daemon = __esm({
85105
85313
  level: "info",
85106
85314
  sessionId: subscription.params.targetSessionId,
85107
85315
  payload: {
85108
- syncMode,
85109
- totalMessages: Number(result.totalMessages || 0),
85110
- replaceFrom: Number(result.replaceFrom || 0),
85111
- hasModal: !!activeModal,
85112
- hasTitle: typeof result.title === "string"
85316
+ syncMode: prepared.update.syncMode,
85317
+ totalMessages: prepared.update.totalMessages,
85318
+ replaceFrom: prepared.update.replaceFrom,
85319
+ hasModal: !!prepared.update.activeModal,
85320
+ hasTitle: typeof prepared.update.title === "string"
85113
85321
  }
85114
85322
  });
85115
- return {
85116
- topic: "session.chat_tail",
85117
- key: subscription.key,
85118
- sessionId: subscription.params.targetSessionId,
85119
- ...subscription.params.historySessionId ? { historySessionId: subscription.params.historySessionId } : {},
85120
- ...interactionId ? { interactionId } : {},
85121
- seq: subscription.seq,
85122
- timestamp: Date.now(),
85123
- messages: Array.isArray(result.messages) ? result.messages : [],
85124
- status: typeof result.status === "string" ? result.status : "idle",
85125
- ...typeof result.title === "string" ? { title: result.title } : {},
85126
- ...activeModal ? { activeModal } : {},
85127
- syncMode,
85128
- replaceFrom: Number(result.replaceFrom || 0),
85129
- totalMessages: Number(result.totalMessages || 0),
85130
- lastMessageSignature: typeof result.lastMessageSignature === "string" ? result.lastMessageSignature : ""
85131
- };
85323
+ return prepared.update;
85132
85324
  }
85133
85325
  buildLiveStatusSnapshot() {
85134
85326
  return buildStatusSnapshot({
@@ -85244,24 +85436,26 @@ var init_adhdev_daemon = __esm({
85244
85436
  if (!state) return null;
85245
85437
  const now = Date.now();
85246
85438
  const activeModal = state.activeChat?.activeModal;
85247
- const modalButtons = Array.isArray(activeModal?.buttons) ? activeModal.buttons.filter((button) => typeof button === "string") : [];
85248
85439
  const status = String(state.activeChat?.status || state.status || "idle");
85249
85440
  const title = typeof state.activeChat?.title === "string" ? state.activeChat.title : void 0;
85250
- const modalMessage = typeof activeModal?.message === "string" ? activeModal.message : void 0;
85251
- const deliverySignature = buildSessionModalDeliverySignature({
85441
+ const interactionId = this.getSessionInteractionId(subscription.params.targetSessionId);
85442
+ const prepared = prepareSessionModalUpdate({
85443
+ key: subscription.key,
85252
85444
  sessionId: subscription.params.targetSessionId,
85253
85445
  status,
85254
- ...title ? { title } : {},
85255
- ...modalMessage ? { modalMessage } : {},
85256
- ...modalButtons.length > 0 ? { modalButtons } : {}
85446
+ title,
85447
+ activeModal,
85448
+ seq: subscription.seq,
85449
+ timestamp: now,
85450
+ ...interactionId ? { interactionId } : {},
85451
+ lastDeliveredSignature: subscription.lastDeliveredSignature
85257
85452
  });
85258
- if (deliverySignature === subscription.lastDeliveredSignature) {
85453
+ subscription.seq = prepared.seq;
85454
+ subscription.lastDeliveredSignature = prepared.lastDeliveredSignature;
85455
+ if (!prepared.update) {
85259
85456
  return null;
85260
85457
  }
85261
- subscription.lastDeliveredSignature = deliverySignature;
85262
- subscription.seq += 1;
85263
85458
  subscription.lastSentAt = now;
85264
- const interactionId = this.getSessionInteractionId(subscription.params.targetSessionId);
85265
85459
  recordDebugTrace({
85266
85460
  interactionId,
85267
85461
  category: "topic",
@@ -85270,23 +85464,12 @@ var init_adhdev_daemon = __esm({
85270
85464
  sessionId: subscription.params.targetSessionId,
85271
85465
  payload: {
85272
85466
  status,
85273
- hasTitle: !!title,
85274
- modalMessage: modalMessage ? modalMessage.slice(0, 140) : void 0,
85275
- modalButtonCount: modalButtons.length
85467
+ hasTitle: !!prepared.update.title,
85468
+ modalMessage: prepared.update.modalMessage ? prepared.update.modalMessage.slice(0, 140) : void 0,
85469
+ modalButtonCount: prepared.update.modalButtons?.length || 0
85276
85470
  }
85277
85471
  });
85278
- return {
85279
- topic: "session.modal",
85280
- key: subscription.key,
85281
- sessionId: subscription.params.targetSessionId,
85282
- status,
85283
- ...title ? { title } : {},
85284
- ...modalMessage ? { modalMessage } : {},
85285
- ...modalButtons.length > 0 ? { modalButtons } : {},
85286
- ...interactionId ? { interactionId } : {},
85287
- seq: subscription.seq,
85288
- timestamp: now
85289
- };
85472
+ return prepared.update;
85290
85473
  }
85291
85474
  async flushP2PSessionModalSubscriptions() {
85292
85475
  if (!this.p2p?.isConnected || !this.p2p.hasSessionModalSubscriptions()) return;
@@ -88703,7 +88886,16 @@ function registerDaemonCommands(program2, pkgVersion3) {
88703
88886
  if (options.open === false) args.push("--no-open");
88704
88887
  if (options.token) args.push("--token", options.token);
88705
88888
  if (options.dev) args.push("--dev");
88706
- const sessionHostName = resolveSessionHostAppName2({ standalone: true, env: process.env });
88889
+ let sessionHostName;
88890
+ try {
88891
+ sessionHostName = resolveSessionHostAppName2({ standalone: true, env: process.env });
88892
+ } catch (error48) {
88893
+ console.error(source_default.red(`
88894
+ \u2717 ${error48 instanceof Error ? error48.message : String(error48)}
88895
+ `));
88896
+ process.exitCode = 1;
88897
+ return;
88898
+ }
88707
88899
  const standaloneEnv = {
88708
88900
  ...process.env,
88709
88901
  ADHDEV_SESSION_HOST_NAME: process.env.ADHDEV_SESSION_HOST_NAME || sessionHostName