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/index.js CHANGED
@@ -633,6 +633,31 @@ var init_saved_sessions = __esm({
633
633
  }
634
634
  });
635
635
 
636
+ // ../../oss/packages/daemon-core/src/providers/provider-session-id.ts
637
+ function normalizeProviderSessionId(providerType, providerSessionId) {
638
+ const normalizedProviderType = typeof providerType === "string" ? providerType.trim() : "";
639
+ const normalizedId = typeof providerSessionId === "string" ? providerSessionId.trim() : "";
640
+ if (!normalizedId) return "";
641
+ const lowered = normalizedId.toLowerCase();
642
+ if (lowered === "undefined" || lowered === "null") return "";
643
+ if (normalizedProviderType === "hermes-cli" && !HERMES_SESSION_ID_RE.test(normalizedId)) {
644
+ return "";
645
+ }
646
+ return normalizedId;
647
+ }
648
+ function isLegacyVolatileSessionReadKey(key) {
649
+ const normalizedKey = typeof key === "string" ? key.trim() : "";
650
+ if (!normalizedKey) return false;
651
+ return normalizedKey.startsWith("provider:codex:vscode-webview://");
652
+ }
653
+ var HERMES_SESSION_ID_RE;
654
+ var init_provider_session_id = __esm({
655
+ "../../oss/packages/daemon-core/src/providers/provider-session-id.ts"() {
656
+ "use strict";
657
+ HERMES_SESSION_ID_RE = /^\d{8}_\d{6}_[a-z0-9]+$/i;
658
+ }
659
+ });
660
+
636
661
  // ../../oss/packages/daemon-core/src/config/state-store.ts
637
662
  function isPlainObject2(value) {
638
663
  return !!value && typeof value === "object" && !Array.isArray(value);
@@ -642,15 +667,31 @@ function getStatePath() {
642
667
  }
643
668
  function normalizeState(raw) {
644
669
  const parsed = isPlainObject2(raw) ? raw : {};
670
+ const recentActivity = (Array.isArray(parsed.recentActivity) ? parsed.recentActivity : []).filter((entry) => {
671
+ if (!isPlainObject2(entry)) return false;
672
+ const normalizedId = normalizeProviderSessionId(
673
+ typeof entry.providerType === "string" ? entry.providerType : "",
674
+ typeof entry.providerSessionId === "string" ? entry.providerSessionId : ""
675
+ );
676
+ if (typeof entry.providerSessionId === "string" && !normalizedId) return false;
677
+ return true;
678
+ });
679
+ const savedProviderSessions = (Array.isArray(parsed.savedProviderSessions) ? parsed.savedProviderSessions : []).filter((entry) => {
680
+ if (!isPlainObject2(entry)) return false;
681
+ return !!normalizeProviderSessionId(
682
+ typeof entry.providerType === "string" ? entry.providerType : "",
683
+ typeof entry.providerSessionId === "string" ? entry.providerSessionId : ""
684
+ );
685
+ });
645
686
  const sessionReads = Object.fromEntries(
646
- Object.entries(isPlainObject2(parsed.sessionReads) ? parsed.sessionReads : {}).filter(([, value]) => typeof value === "number" && Number.isFinite(value))
687
+ Object.entries(isPlainObject2(parsed.sessionReads) ? parsed.sessionReads : {}).filter(([key, value]) => !isLegacyVolatileSessionReadKey(key) && typeof value === "number" && Number.isFinite(value))
647
688
  );
648
689
  const sessionReadMarkers = Object.fromEntries(
649
- Object.entries(isPlainObject2(parsed.sessionReadMarkers) ? parsed.sessionReadMarkers : {}).filter(([, value]) => typeof value === "string")
690
+ Object.entries(isPlainObject2(parsed.sessionReadMarkers) ? parsed.sessionReadMarkers : {}).filter(([key, value]) => !isLegacyVolatileSessionReadKey(key) && typeof value === "string")
650
691
  );
651
692
  return {
652
- recentActivity: Array.isArray(parsed.recentActivity) ? parsed.recentActivity : [],
653
- savedProviderSessions: Array.isArray(parsed.savedProviderSessions) ? parsed.savedProviderSessions : [],
693
+ recentActivity,
694
+ savedProviderSessions,
654
695
  sessionReads,
655
696
  sessionReadMarkers
656
697
  };
@@ -682,6 +723,7 @@ var init_state_store = __esm({
682
723
  import_fs2 = require("fs");
683
724
  import_path2 = require("path");
684
725
  init_config();
726
+ init_provider_session_id();
685
727
  DEFAULT_STATE = {
686
728
  recentActivity: [],
687
729
  savedProviderSessions: [],
@@ -5862,6 +5904,37 @@ var init_reconcile = __esm({
5862
5904
  }
5863
5905
  });
5864
5906
 
5907
+ // ../../oss/packages/daemon-core/src/commands/provider-script-resolver.ts
5908
+ function resolveLegacyProviderScript(fn, scriptName, params) {
5909
+ if (typeof fn !== "function") return null;
5910
+ if (params && typeof params === "object" && !Array.isArray(params) && Object.keys(params).length > 0) {
5911
+ const firstVal = Object.values(params)[0];
5912
+ if (scriptName === "sendMessage" && typeof firstVal === "string") {
5913
+ const legacyScript = fn(firstVal);
5914
+ if (legacyScript) return legacyScript;
5915
+ }
5916
+ const script = fn(params);
5917
+ const likelyLegacyObjectLeak = typeof script === "string" && script.includes("[object Object]") && typeof firstVal === "string";
5918
+ if (!likelyLegacyObjectLeak && script) return script;
5919
+ if (firstVal !== void 0) {
5920
+ const legacyScript = fn(firstVal);
5921
+ if (legacyScript) return legacyScript;
5922
+ }
5923
+ if (script) return script;
5924
+ return null;
5925
+ }
5926
+ if (params !== void 0) {
5927
+ const script = fn(params);
5928
+ if (script) return script;
5929
+ }
5930
+ return fn() || null;
5931
+ }
5932
+ var init_provider_script_resolver = __esm({
5933
+ "../../oss/packages/daemon-core/src/commands/provider-script-resolver.ts"() {
5934
+ "use strict";
5935
+ }
5936
+ });
5937
+
5865
5938
  // ../../oss/packages/daemon-core/src/providers/provider-input-support.ts
5866
5939
  function getProviderLabel(provider) {
5867
5940
  return provider?.name || provider?.type || "This provider";
@@ -6062,7 +6135,7 @@ var init_debug_trace = __esm({
6062
6135
  }
6063
6136
  });
6064
6137
 
6065
- // ../../oss/packages/daemon-core/src/commands/chat-commands.ts
6138
+ // ../../oss/packages/daemon-core/src/chat/chat-signatures.ts
6066
6139
  function hashSignatureParts(parts) {
6067
6140
  let hash2 = 2166136261;
6068
6141
  for (const part of parts) {
@@ -6076,6 +6149,60 @@ function hashSignatureParts(parts) {
6076
6149
  }
6077
6150
  return hash2.toString(16).padStart(8, "0");
6078
6151
  }
6152
+ function stringifySignatureContent(content) {
6153
+ try {
6154
+ return JSON.stringify(content ?? "");
6155
+ } catch {
6156
+ return String(content ?? "");
6157
+ }
6158
+ }
6159
+ function stringifySignatureMessages(messages) {
6160
+ try {
6161
+ return JSON.stringify(messages);
6162
+ } catch {
6163
+ return String(messages.length);
6164
+ }
6165
+ }
6166
+ function buildChatMessageSignature(message) {
6167
+ if (!message) return "";
6168
+ return hashSignatureParts([
6169
+ String(message.id || ""),
6170
+ String(message.index ?? ""),
6171
+ String(message.role || ""),
6172
+ String(message.receivedAt ?? message.timestamp ?? ""),
6173
+ stringifySignatureContent(message.content)
6174
+ ]);
6175
+ }
6176
+ function buildChatTailDeliverySignature(payload) {
6177
+ return hashSignatureParts([
6178
+ payload.sessionId,
6179
+ payload.historySessionId || "",
6180
+ payload.status,
6181
+ payload.title || "",
6182
+ payload.syncMode,
6183
+ String(payload.replaceFrom),
6184
+ String(payload.totalMessages),
6185
+ payload.lastMessageSignature,
6186
+ payload.activeModal ? `${payload.activeModal.message}|${payload.activeModal.buttons.join("")}` : "",
6187
+ stringifySignatureMessages(payload.messages)
6188
+ ]);
6189
+ }
6190
+ function buildSessionModalDeliverySignature(payload) {
6191
+ return hashSignatureParts([
6192
+ payload.sessionId,
6193
+ payload.status,
6194
+ payload.title || "",
6195
+ payload.modalMessage || "",
6196
+ Array.isArray(payload.modalButtons) ? payload.modalButtons.join("") : ""
6197
+ ]);
6198
+ }
6199
+ var init_chat_signatures = __esm({
6200
+ "../../oss/packages/daemon-core/src/chat/chat-signatures.ts"() {
6201
+ "use strict";
6202
+ }
6203
+ });
6204
+
6205
+ // ../../oss/packages/daemon-core/src/commands/chat-commands.ts
6079
6206
  function getCurrentProviderType(h, fallback2 = "") {
6080
6207
  return h.currentSession?.providerType || h.currentProviderType || fallback2;
6081
6208
  }
@@ -6172,20 +6299,7 @@ function parseMaybeJson(value) {
6172
6299
  }
6173
6300
  }
6174
6301
  function getChatMessageSignature(message) {
6175
- if (!message) return "";
6176
- let content = "";
6177
- try {
6178
- content = JSON.stringify(message.content ?? "");
6179
- } catch {
6180
- content = String(message.content ?? "");
6181
- }
6182
- return hashSignatureParts([
6183
- String(message.id || ""),
6184
- String(message.index ?? ""),
6185
- String(message.role || ""),
6186
- String(message.receivedAt ?? message.timestamp ?? ""),
6187
- content
6188
- ]);
6302
+ return buildChatMessageSignature(message);
6189
6303
  }
6190
6304
  function normalizeReadChatCursor(args) {
6191
6305
  const knownMessageCount = Math.max(0, Number(args?.knownMessageCount || 0));
@@ -7208,6 +7322,7 @@ var init_chat_commands = __esm({
7208
7322
  init_chat_history();
7209
7323
  init_logger();
7210
7324
  init_debug_trace();
7325
+ init_chat_signatures();
7211
7326
  init_chat_message_normalization();
7212
7327
  RECENT_SEND_WINDOW_MS = 1200;
7213
7328
  recentSendByTarget = /* @__PURE__ */ new Map();
@@ -8214,6 +8329,7 @@ var init_handler = __esm({
8214
8329
  init_chat_history();
8215
8330
  init_reconcile();
8216
8331
  init_logger();
8332
+ init_provider_script_resolver();
8217
8333
  init_chat_commands();
8218
8334
  init_cdp_commands();
8219
8335
  init_stream_commands();
@@ -8289,27 +8405,7 @@ var init_handler = __esm({
8289
8405
  if (provider?.scripts) {
8290
8406
  const fn = provider.scripts[scriptName];
8291
8407
  if (typeof fn === "function") {
8292
- const callScript = fn;
8293
- if (params && Object.keys(params).length > 0) {
8294
- const firstVal = Object.values(params)[0];
8295
- if (scriptName === "sendMessage" && typeof firstVal === "string") {
8296
- const legacyScript = callScript(firstVal);
8297
- if (legacyScript) return legacyScript;
8298
- }
8299
- const script = callScript(params);
8300
- if (script) {
8301
- const likelyLegacyObjectLeak = typeof script === "string" && script.includes("[object Object]") && typeof firstVal === "string";
8302
- if (!likelyLegacyObjectLeak) return script;
8303
- }
8304
- if (firstVal !== void 0) {
8305
- const legacyScript = callScript(firstVal);
8306
- if (legacyScript) return legacyScript;
8307
- }
8308
- if (script) return script;
8309
- } else {
8310
- const script = callScript();
8311
- if (script) return script;
8312
- }
8408
+ return resolveLegacyProviderScript(fn, scriptName, params);
8313
8409
  }
8314
8410
  }
8315
8411
  return null;
@@ -12054,6 +12150,7 @@ var init_cli_provider_instance = __esm({
12054
12150
  init_approval_utils();
12055
12151
  init_cli_script_results();
12056
12152
  init_provider_patch_state();
12153
+ init_provider_session_id();
12057
12154
  init_chat_message_normalization();
12058
12155
  CachedDatabaseSync = null;
12059
12156
  CliProviderInstance = class {
@@ -12216,7 +12313,10 @@ var init_cli_provider_instance = __esm({
12216
12313
  const parsedStatus = this.adapter.getScriptParsedStatus?.() || null;
12217
12314
  const autoApproveActive = adapterStatus.status === "waiting_approval" && this.shouldAutoApprove();
12218
12315
  const visibleStatus = autoApproveActive ? "generating" : adapterStatus.status;
12219
- const parsedProviderSessionId = typeof parsedStatus?.providerSessionId === "string" ? parsedStatus.providerSessionId.trim() : "";
12316
+ const parsedProviderSessionId = normalizeProviderSessionId(
12317
+ this.type,
12318
+ typeof parsedStatus?.providerSessionId === "string" ? parsedStatus.providerSessionId : ""
12319
+ );
12220
12320
  if (parsedProviderSessionId) {
12221
12321
  this.promoteProviderSessionId(parsedProviderSessionId);
12222
12322
  }
@@ -12480,7 +12580,10 @@ var init_cli_provider_instance = __esm({
12480
12580
  }
12481
12581
  applyProviderResponse(data, options) {
12482
12582
  if (!data || typeof data !== "object") return;
12483
- const patchedProviderSessionId = typeof data.providerSessionId === "string" ? data.providerSessionId.trim() : "";
12583
+ const patchedProviderSessionId = normalizeProviderSessionId(
12584
+ this.type,
12585
+ typeof data.providerSessionId === "string" ? data.providerSessionId : ""
12586
+ );
12484
12587
  if (patchedProviderSessionId) {
12485
12588
  this.promoteProviderSessionId(patchedProviderSessionId);
12486
12589
  }
@@ -36224,6 +36327,147 @@ var init_ipc_protocol = __esm({
36224
36327
  }
36225
36328
  });
36226
36329
 
36330
+ // ../../oss/packages/daemon-core/src/chat/subscription-updates.ts
36331
+ function normalizeSyncMode(syncMode) {
36332
+ return syncMode === "append" || syncMode === "replace_tail" || syncMode === "noop" || syncMode === "full" ? syncMode : "full";
36333
+ }
36334
+ function normalizeModalButtons(value) {
36335
+ return Array.isArray(value) ? value.filter((button) => typeof button === "string") : [];
36336
+ }
36337
+ function normalizeModalMessage(value) {
36338
+ return typeof value === "string" ? value : void 0;
36339
+ }
36340
+ function normalizeChatTailActiveModal(activeModal) {
36341
+ if (!activeModal || typeof activeModal !== "object") return null;
36342
+ const message = normalizeModalMessage(activeModal.message);
36343
+ if (!message) return null;
36344
+ const rawButtons = activeModal.buttons;
36345
+ if (!Array.isArray(rawButtons)) return null;
36346
+ return {
36347
+ message,
36348
+ buttons: normalizeModalButtons(rawButtons)
36349
+ };
36350
+ }
36351
+ function normalizeSessionModalFields(activeModal) {
36352
+ if (!activeModal || typeof activeModal !== "object") {
36353
+ return { modalButtons: [] };
36354
+ }
36355
+ return {
36356
+ modalMessage: normalizeModalMessage(activeModal.message),
36357
+ modalButtons: normalizeModalButtons(activeModal.buttons)
36358
+ };
36359
+ }
36360
+ function buildNextChatCursor(cursor, result) {
36361
+ return {
36362
+ knownMessageCount: Math.max(0, Number(result.totalMessages || cursor.knownMessageCount)),
36363
+ lastMessageSignature: typeof result.lastMessageSignature === "string" ? result.lastMessageSignature : cursor.lastMessageSignature,
36364
+ tailLimit: cursor.tailLimit
36365
+ };
36366
+ }
36367
+ function prepareSessionChatTailUpdate(input) {
36368
+ const result = input.result;
36369
+ if (!result?.success || result.syncMode === "noop") {
36370
+ return {
36371
+ cursor: result?.success ? buildNextChatCursor(input.cursor, result) : input.cursor,
36372
+ seq: input.seq,
36373
+ lastDeliveredSignature: input.lastDeliveredSignature,
36374
+ update: null
36375
+ };
36376
+ }
36377
+ const syncMode = normalizeSyncMode(result.syncMode);
36378
+ const cursor = {
36379
+ knownMessageCount: Math.max(0, Number(result.totalMessages || 0)),
36380
+ lastMessageSignature: typeof result.lastMessageSignature === "string" ? result.lastMessageSignature : "",
36381
+ tailLimit: input.cursor.tailLimit
36382
+ };
36383
+ const title = typeof result.title === "string" ? result.title : void 0;
36384
+ const activeModal = normalizeChatTailActiveModal(result.activeModal);
36385
+ const status = typeof result.status === "string" ? result.status : "idle";
36386
+ const deliverySignature = buildChatTailDeliverySignature({
36387
+ sessionId: input.sessionId,
36388
+ ...input.historySessionId ? { historySessionId: input.historySessionId } : {},
36389
+ messages: Array.isArray(result.messages) ? result.messages : [],
36390
+ status,
36391
+ ...title ? { title } : {},
36392
+ ...activeModal ? { activeModal } : {},
36393
+ syncMode,
36394
+ replaceFrom: Number(result.replaceFrom || 0),
36395
+ totalMessages: Number(result.totalMessages || 0),
36396
+ lastMessageSignature: typeof result.lastMessageSignature === "string" ? result.lastMessageSignature : ""
36397
+ });
36398
+ const seq = input.seq + 1;
36399
+ if (deliverySignature === input.lastDeliveredSignature) {
36400
+ return {
36401
+ cursor,
36402
+ seq,
36403
+ lastDeliveredSignature: input.lastDeliveredSignature,
36404
+ update: null
36405
+ };
36406
+ }
36407
+ return {
36408
+ cursor,
36409
+ seq,
36410
+ lastDeliveredSignature: deliverySignature,
36411
+ update: {
36412
+ topic: "session.chat_tail",
36413
+ key: input.key,
36414
+ sessionId: input.sessionId,
36415
+ ...input.historySessionId ? { historySessionId: input.historySessionId } : {},
36416
+ ...input.interactionId ? { interactionId: input.interactionId } : {},
36417
+ seq,
36418
+ timestamp: input.timestamp,
36419
+ messages: Array.isArray(result.messages) ? result.messages : [],
36420
+ status,
36421
+ ...title ? { title } : {},
36422
+ ...activeModal ? { activeModal } : {},
36423
+ syncMode,
36424
+ replaceFrom: Number(result.replaceFrom || 0),
36425
+ totalMessages: Number(result.totalMessages || 0),
36426
+ lastMessageSignature: typeof result.lastMessageSignature === "string" ? result.lastMessageSignature : ""
36427
+ }
36428
+ };
36429
+ }
36430
+ function prepareSessionModalUpdate(input) {
36431
+ const { modalMessage, modalButtons } = normalizeSessionModalFields(input.activeModal);
36432
+ const deliverySignature = buildSessionModalDeliverySignature({
36433
+ sessionId: input.sessionId,
36434
+ status: input.status,
36435
+ ...input.title ? { title: input.title } : {},
36436
+ ...modalMessage ? { modalMessage } : {},
36437
+ ...modalButtons.length > 0 ? { modalButtons } : {}
36438
+ });
36439
+ if (deliverySignature === input.lastDeliveredSignature) {
36440
+ return {
36441
+ seq: input.seq,
36442
+ lastDeliveredSignature: input.lastDeliveredSignature,
36443
+ update: null
36444
+ };
36445
+ }
36446
+ const seq = input.seq + 1;
36447
+ return {
36448
+ seq,
36449
+ lastDeliveredSignature: deliverySignature,
36450
+ update: {
36451
+ topic: "session.modal",
36452
+ key: input.key,
36453
+ sessionId: input.sessionId,
36454
+ status: input.status,
36455
+ ...input.title ? { title: input.title } : {},
36456
+ ...modalMessage ? { modalMessage } : {},
36457
+ ...modalButtons.length > 0 ? { modalButtons } : {},
36458
+ ...input.interactionId ? { interactionId: input.interactionId } : {},
36459
+ seq,
36460
+ timestamp: input.timestamp
36461
+ }
36462
+ };
36463
+ }
36464
+ var init_subscription_updates = __esm({
36465
+ "../../oss/packages/daemon-core/src/chat/subscription-updates.ts"() {
36466
+ "use strict";
36467
+ init_chat_signatures();
36468
+ }
36469
+ });
36470
+
36227
36471
  // ../../oss/packages/daemon-core/src/agent-stream/provider-adapter.ts
36228
36472
  var ProviderStreamAdapter;
36229
36473
  var init_provider_adapter = __esm({
@@ -41243,6 +41487,7 @@ var init_dev_server = __esm({
41243
41487
  init_logger();
41244
41488
  init_builders();
41245
41489
  init_dev_cdp_handlers();
41490
+ init_provider_script_resolver();
41246
41491
  init_dev_cli_debug();
41247
41492
  init_dev_auto_implement();
41248
41493
  DEV_SERVER_PORT = 19280;
@@ -41506,7 +41751,8 @@ var init_dev_server = __esm({
41506
41751
  }
41507
41752
  async handleRunScript(type, req, res, parsedBody) {
41508
41753
  const body = parsedBody || await this.readBody(req);
41509
- const { script: scriptName, params, ideType: scriptIdeType } = body;
41754
+ const { script: scriptName, params, args, ideType: scriptIdeType } = body;
41755
+ const rawParams = args !== void 0 ? args : params;
41510
41756
  const provider = this.providerLoader.resolve(type);
41511
41757
  if (!provider) {
41512
41758
  this.json(res, 404, { error: `Provider '${type}' not found` });
@@ -41523,13 +41769,7 @@ var init_dev_server = __esm({
41523
41769
  return;
41524
41770
  }
41525
41771
  try {
41526
- let scriptCode = null;
41527
- if (["sendMessage", "webviewSendMessage", "switchSession", "webviewSwitchSession", "setMode", "webviewSetMode", "setModel", "webviewSetModel"].includes(scriptName)) {
41528
- const firstVal = params && typeof params === "object" && Object.keys(params).length > 0 ? Object.values(params)[0] : params;
41529
- scriptCode = firstVal !== void 0 ? fn(firstVal) : fn();
41530
- } else {
41531
- scriptCode = params !== void 0 ? fn(params) : fn();
41532
- }
41772
+ const scriptCode = resolveLegacyProviderScript(fn, scriptName, rawParams);
41533
41773
  if (!scriptCode) {
41534
41774
  this.json(res, 500, { error: "Script function returned null" });
41535
41775
  return;
@@ -41546,6 +41786,17 @@ var init_dev_server = __esm({
41546
41786
  break;
41547
41787
  }
41548
41788
  }
41789
+ if (!sessionId) {
41790
+ try {
41791
+ const discovered = await cdp.discoverAgentWebviews();
41792
+ const target = discovered.find((entry) => entry.agentType === type);
41793
+ if (target) {
41794
+ sessionId = await cdp.attachToAgent(target);
41795
+ }
41796
+ } catch (error48) {
41797
+ this.log(`Extension attach fallback failed for ${type}: ${error48?.message || String(error48)}`);
41798
+ }
41799
+ }
41549
41800
  if (sessionId) {
41550
41801
  raw = await cdp.evaluateInSessionFrame(sessionId, scriptCode);
41551
41802
  } else if (cdp.evaluateInWebviewFrame) {
@@ -43116,10 +43367,19 @@ var init_session_host_transport = __esm({
43116
43367
  });
43117
43368
 
43118
43369
  // ../../oss/packages/daemon-core/src/session-host/app-name.ts
43370
+ function validateStandaloneSessionHostAppName(explicit) {
43371
+ if (explicit !== DEFAULT_SESSION_HOST_APP_NAME) return;
43372
+ throw new Error(
43373
+ `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.`
43374
+ );
43375
+ }
43119
43376
  function resolveSessionHostAppName(options = {}) {
43120
43377
  const env3 = options.env || process.env;
43121
43378
  const explicit = typeof env3.ADHDEV_SESSION_HOST_NAME === "string" ? env3.ADHDEV_SESSION_HOST_NAME.trim() : "";
43122
- if (explicit) return explicit;
43379
+ if (explicit) {
43380
+ if (options.standalone) validateStandaloneSessionHostAppName(explicit);
43381
+ return explicit;
43382
+ }
43123
43383
  return options.standalone ? DEFAULT_STANDALONE_SESSION_HOST_APP_NAME : DEFAULT_SESSION_HOST_APP_NAME;
43124
43384
  }
43125
43385
  var DEFAULT_SESSION_HOST_APP_NAME, DEFAULT_STANDALONE_SESSION_HOST_APP_NAME;
@@ -43746,9 +44006,12 @@ __export(src_exports, {
43746
44006
  appendRecentActivity: () => appendRecentActivity,
43747
44007
  buildAssistantChatMessage: () => buildAssistantChatMessage,
43748
44008
  buildChatMessage: () => buildChatMessage,
44009
+ buildChatMessageSignature: () => buildChatMessageSignature,
44010
+ buildChatTailDeliverySignature: () => buildChatTailDeliverySignature,
43749
44011
  buildMachineInfo: () => buildMachineInfo,
43750
44012
  buildRuntimeSystemChatMessage: () => buildRuntimeSystemChatMessage,
43751
44013
  buildSessionEntries: () => buildSessionEntries,
44014
+ buildSessionModalDeliverySignature: () => buildSessionModalDeliverySignature,
43752
44015
  buildStatusSnapshot: () => buildStatusSnapshot,
43753
44016
  buildSystemChatMessage: () => buildSystemChatMessage,
43754
44017
  buildTerminalChatMessage: () => buildTerminalChatMessage,
@@ -43784,6 +44047,7 @@ __export(src_exports, {
43784
44047
  getSessionHostSurfaceKind: () => getSessionHostSurfaceKind,
43785
44048
  getWorkspaceState: () => getWorkspaceState,
43786
44049
  hasCdpManager: () => hasCdpManager,
44050
+ hashSignatureParts: () => hashSignatureParts,
43787
44051
  initDaemonComponents: () => initDaemonComponents,
43788
44052
  installExtensions: () => installExtensions,
43789
44053
  installGlobalInterceptor: () => installGlobalInterceptor,
@@ -43809,12 +44073,16 @@ __export(src_exports, {
43809
44073
  normalizeChatMessage: () => normalizeChatMessage,
43810
44074
  normalizeChatMessageKind: () => normalizeChatMessageKind,
43811
44075
  normalizeChatMessages: () => normalizeChatMessages,
44076
+ normalizeChatTailActiveModal: () => normalizeChatTailActiveModal,
43812
44077
  normalizeInputEnvelope: () => normalizeInputEnvelope,
43813
44078
  normalizeManagedStatus: () => normalizeManagedStatus,
43814
44079
  normalizeMessageParts: () => normalizeMessageParts,
44080
+ normalizeSessionModalFields: () => normalizeSessionModalFields,
43815
44081
  parseProviderSourceConfigUpdate: () => parseProviderSourceConfigUpdate,
43816
44082
  partitionSessionHostDiagnosticsSessions: () => partitionSessionHostDiagnosticsSessions,
43817
44083
  partitionSessionHostRecords: () => partitionSessionHostRecords,
44084
+ prepareSessionChatTailUpdate: () => prepareSessionChatTailUpdate,
44085
+ prepareSessionModalUpdate: () => prepareSessionModalUpdate,
43818
44086
  probeCdpPort: () => probeCdpPort,
43819
44087
  readChatHistory: () => readChatHistory,
43820
44088
  recordDebugTrace: () => recordDebugTrace,
@@ -43870,6 +44138,8 @@ var init_src = __esm({
43870
44138
  init_launch();
43871
44139
  init_ipc_protocol();
43872
44140
  init_chat_history();
44141
+ init_chat_signatures();
44142
+ init_subscription_updates();
43873
44143
  init_agent_stream();
43874
44144
  init_agent_stream();
43875
44145
  init_forward();
@@ -53041,48 +53311,6 @@ __export(adhdev_daemon_exports, {
53041
53311
  isDaemonRunning: () => isDaemonRunning,
53042
53312
  stopDaemon: () => stopDaemon
53043
53313
  });
53044
- function hashSignatureParts2(parts) {
53045
- let hash2 = 2166136261;
53046
- for (const part of parts) {
53047
- const text = String(part || "");
53048
- for (let i = 0; i < text.length; i += 1) {
53049
- hash2 ^= text.charCodeAt(i);
53050
- hash2 = Math.imul(hash2, 16777619) >>> 0;
53051
- }
53052
- hash2 ^= 255;
53053
- hash2 = Math.imul(hash2, 16777619) >>> 0;
53054
- }
53055
- return hash2.toString(16).padStart(8, "0");
53056
- }
53057
- function buildChatTailDeliverySignature(payload) {
53058
- let messages = "";
53059
- try {
53060
- messages = JSON.stringify(payload.messages);
53061
- } catch {
53062
- messages = String(payload.messages.length);
53063
- }
53064
- return hashSignatureParts2([
53065
- payload.sessionId,
53066
- payload.historySessionId || "",
53067
- payload.status,
53068
- payload.title || "",
53069
- payload.syncMode,
53070
- String(payload.replaceFrom),
53071
- String(payload.totalMessages),
53072
- payload.lastMessageSignature,
53073
- payload.activeModal ? `${payload.activeModal.message}|${payload.activeModal.buttons.join("")}` : "",
53074
- messages
53075
- ]);
53076
- }
53077
- function buildSessionModalDeliverySignature(payload) {
53078
- return hashSignatureParts2([
53079
- payload.sessionId,
53080
- payload.status,
53081
- payload.title || "",
53082
- payload.modalMessage || "",
53083
- Array.isArray(payload.modalButtons) ? payload.modalButtons.join("") : ""
53084
- ]);
53085
- }
53086
53314
  function resolveDaemonPort(ref = {}) {
53087
53315
  return Number.isFinite(ref.port) && Number(ref.port) > 0 ? Number(ref.port) : DEFAULT_DAEMON_PORT;
53088
53316
  }
@@ -53215,7 +53443,7 @@ var init_adhdev_daemon = __esm({
53215
53443
  init_source2();
53216
53444
  init_version();
53217
53445
  init_src();
53218
- pkgVersion = resolvePackageVersion({ injectedVersion: "0.8.70" });
53446
+ pkgVersion = resolvePackageVersion({ injectedVersion: "0.8.73" });
53219
53447
  AdhdevDaemon = class _AdhdevDaemon {
53220
53448
  localHttpServer = null;
53221
53449
  localWss = null;
@@ -53356,44 +53584,24 @@ var init_adhdev_daemon = __esm({
53356
53584
  lastMessageSignature: subscription.cursor.lastMessageSignature,
53357
53585
  ...subscription.cursor.tailLimit > 0 ? { tailLimit: subscription.cursor.tailLimit } : {}
53358
53586
  }, "p2p");
53359
- if (!result?.success || result.syncMode === "noop") {
53360
- if (result?.success) {
53361
- subscription.cursor = {
53362
- knownMessageCount: Math.max(0, Number(result.totalMessages || subscription.cursor.knownMessageCount)),
53363
- lastMessageSignature: typeof result.lastMessageSignature === "string" ? result.lastMessageSignature : subscription.cursor.lastMessageSignature,
53364
- tailLimit: subscription.cursor.tailLimit
53365
- };
53366
- }
53367
- return null;
53368
- }
53369
- subscription.seq += 1;
53370
- const syncMode = result.syncMode === "append" || result.syncMode === "replace_tail" || result.syncMode === "noop" || result.syncMode === "full" ? result.syncMode : "full";
53371
- subscription.cursor = {
53372
- knownMessageCount: Math.max(0, Number(result.totalMessages || 0)),
53373
- lastMessageSignature: typeof result.lastMessageSignature === "string" ? result.lastMessageSignature : "",
53374
- tailLimit: subscription.cursor.tailLimit
53375
- };
53376
- const activeModal = result.activeModal && typeof result.activeModal === "object" && typeof result.activeModal.message === "string" && Array.isArray(result.activeModal.buttons) ? {
53377
- message: result.activeModal.message,
53378
- buttons: result.activeModal.buttons.filter((button) => typeof button === "string")
53379
- } : null;
53380
- const deliverySignature = buildChatTailDeliverySignature({
53587
+ const interactionId = this.getSessionInteractionId(subscription.params.targetSessionId);
53588
+ const prepared = prepareSessionChatTailUpdate({
53589
+ key: subscription.key,
53381
53590
  sessionId: subscription.params.targetSessionId,
53382
53591
  ...subscription.params.historySessionId ? { historySessionId: subscription.params.historySessionId } : {},
53383
- messages: Array.isArray(result.messages) ? result.messages : [],
53384
- status: typeof result.status === "string" ? result.status : "idle",
53385
- ...typeof result.title === "string" ? { title: result.title } : {},
53386
- ...activeModal ? { activeModal } : {},
53387
- syncMode,
53388
- replaceFrom: Number(result.replaceFrom || 0),
53389
- totalMessages: Number(result.totalMessages || 0),
53390
- lastMessageSignature: typeof result.lastMessageSignature === "string" ? result.lastMessageSignature : ""
53592
+ seq: subscription.seq,
53593
+ timestamp: Date.now(),
53594
+ ...interactionId ? { interactionId } : {},
53595
+ cursor: subscription.cursor,
53596
+ lastDeliveredSignature: subscription.lastDeliveredSignature,
53597
+ result
53391
53598
  });
53392
- if (deliverySignature === subscription.lastDeliveredSignature) {
53599
+ subscription.cursor = prepared.cursor;
53600
+ subscription.seq = prepared.seq;
53601
+ subscription.lastDeliveredSignature = prepared.lastDeliveredSignature;
53602
+ if (!prepared.update) {
53393
53603
  return null;
53394
53604
  }
53395
- subscription.lastDeliveredSignature = deliverySignature;
53396
- const interactionId = this.getSessionInteractionId(subscription.params.targetSessionId);
53397
53605
  recordDebugTrace({
53398
53606
  interactionId,
53399
53607
  category: "topic",
@@ -53401,30 +53609,14 @@ var init_adhdev_daemon = __esm({
53401
53609
  level: "info",
53402
53610
  sessionId: subscription.params.targetSessionId,
53403
53611
  payload: {
53404
- syncMode,
53405
- totalMessages: Number(result.totalMessages || 0),
53406
- replaceFrom: Number(result.replaceFrom || 0),
53407
- hasModal: !!activeModal,
53408
- hasTitle: typeof result.title === "string"
53612
+ syncMode: prepared.update.syncMode,
53613
+ totalMessages: prepared.update.totalMessages,
53614
+ replaceFrom: prepared.update.replaceFrom,
53615
+ hasModal: !!prepared.update.activeModal,
53616
+ hasTitle: typeof prepared.update.title === "string"
53409
53617
  }
53410
53618
  });
53411
- return {
53412
- topic: "session.chat_tail",
53413
- key: subscription.key,
53414
- sessionId: subscription.params.targetSessionId,
53415
- ...subscription.params.historySessionId ? { historySessionId: subscription.params.historySessionId } : {},
53416
- ...interactionId ? { interactionId } : {},
53417
- seq: subscription.seq,
53418
- timestamp: Date.now(),
53419
- messages: Array.isArray(result.messages) ? result.messages : [],
53420
- status: typeof result.status === "string" ? result.status : "idle",
53421
- ...typeof result.title === "string" ? { title: result.title } : {},
53422
- ...activeModal ? { activeModal } : {},
53423
- syncMode,
53424
- replaceFrom: Number(result.replaceFrom || 0),
53425
- totalMessages: Number(result.totalMessages || 0),
53426
- lastMessageSignature: typeof result.lastMessageSignature === "string" ? result.lastMessageSignature : ""
53427
- };
53619
+ return prepared.update;
53428
53620
  }
53429
53621
  buildLiveStatusSnapshot() {
53430
53622
  return buildStatusSnapshot({
@@ -53540,24 +53732,26 @@ var init_adhdev_daemon = __esm({
53540
53732
  if (!state) return null;
53541
53733
  const now = Date.now();
53542
53734
  const activeModal = state.activeChat?.activeModal;
53543
- const modalButtons = Array.isArray(activeModal?.buttons) ? activeModal.buttons.filter((button) => typeof button === "string") : [];
53544
53735
  const status = String(state.activeChat?.status || state.status || "idle");
53545
53736
  const title = typeof state.activeChat?.title === "string" ? state.activeChat.title : void 0;
53546
- const modalMessage = typeof activeModal?.message === "string" ? activeModal.message : void 0;
53547
- const deliverySignature = buildSessionModalDeliverySignature({
53737
+ const interactionId = this.getSessionInteractionId(subscription.params.targetSessionId);
53738
+ const prepared = prepareSessionModalUpdate({
53739
+ key: subscription.key,
53548
53740
  sessionId: subscription.params.targetSessionId,
53549
53741
  status,
53550
- ...title ? { title } : {},
53551
- ...modalMessage ? { modalMessage } : {},
53552
- ...modalButtons.length > 0 ? { modalButtons } : {}
53742
+ title,
53743
+ activeModal,
53744
+ seq: subscription.seq,
53745
+ timestamp: now,
53746
+ ...interactionId ? { interactionId } : {},
53747
+ lastDeliveredSignature: subscription.lastDeliveredSignature
53553
53748
  });
53554
- if (deliverySignature === subscription.lastDeliveredSignature) {
53749
+ subscription.seq = prepared.seq;
53750
+ subscription.lastDeliveredSignature = prepared.lastDeliveredSignature;
53751
+ if (!prepared.update) {
53555
53752
  return null;
53556
53753
  }
53557
- subscription.lastDeliveredSignature = deliverySignature;
53558
- subscription.seq += 1;
53559
53754
  subscription.lastSentAt = now;
53560
- const interactionId = this.getSessionInteractionId(subscription.params.targetSessionId);
53561
53755
  recordDebugTrace({
53562
53756
  interactionId,
53563
53757
  category: "topic",
@@ -53566,23 +53760,12 @@ var init_adhdev_daemon = __esm({
53566
53760
  sessionId: subscription.params.targetSessionId,
53567
53761
  payload: {
53568
53762
  status,
53569
- hasTitle: !!title,
53570
- modalMessage: modalMessage ? modalMessage.slice(0, 140) : void 0,
53571
- modalButtonCount: modalButtons.length
53763
+ hasTitle: !!prepared.update.title,
53764
+ modalMessage: prepared.update.modalMessage ? prepared.update.modalMessage.slice(0, 140) : void 0,
53765
+ modalButtonCount: prepared.update.modalButtons?.length || 0
53572
53766
  }
53573
53767
  });
53574
- return {
53575
- topic: "session.modal",
53576
- key: subscription.key,
53577
- sessionId: subscription.params.targetSessionId,
53578
- status,
53579
- ...title ? { title } : {},
53580
- ...modalMessage ? { modalMessage } : {},
53581
- ...modalButtons.length > 0 ? { modalButtons } : {},
53582
- ...interactionId ? { interactionId } : {},
53583
- seq: subscription.seq,
53584
- timestamp: now
53585
- };
53768
+ return prepared.update;
53586
53769
  }
53587
53770
  async flushP2PSessionModalSubscriptions() {
53588
53771
  if (!this.p2p?.isConnected || !this.p2p.hasSessionModalSubscriptions()) return;