@adhdev/daemon-standalone 0.9.82-rc.91 → 0.9.82-rc.92

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
@@ -38029,6 +38029,13 @@ ${effect.notification.body || ""}`.trim();
38029
38029
  function getTargetedCliAdapter(h, args, providerType) {
38030
38030
  return h.getCliAdapter(args?.targetSessionId || providerType || h.currentSession?.providerType || h.currentManagerKey);
38031
38031
  }
38032
+ function getExplicitHistorySessionId(args) {
38033
+ const explicit = typeof args?.historySessionId === "string" ? args.historySessionId.trim() : "";
38034
+ if (explicit) return explicit;
38035
+ const explicitProviderSessionId = typeof args?.providerSessionId === "string" ? args.providerSessionId.trim() : "";
38036
+ if (explicitProviderSessionId) return explicitProviderSessionId;
38037
+ return void 0;
38038
+ }
38032
38039
  function getTargetInstance(h, args) {
38033
38040
  const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
38034
38041
  const sessionId = targetSessionId || h.currentSession?.sessionId || "";
@@ -38097,13 +38104,14 @@ ${effect.notification.body || ""}`.trim();
38097
38104
  await sleep(HERMES_CLI_STARTING_SEND_SETTLE_MS);
38098
38105
  }
38099
38106
  function getHistorySessionId(h, args) {
38100
- const explicit = typeof args?.historySessionId === "string" ? args.historySessionId.trim() : "";
38107
+ const explicit = getExplicitHistorySessionId(args);
38101
38108
  if (explicit) return explicit;
38102
- const explicitProviderSessionId = typeof args?.providerSessionId === "string" ? args.providerSessionId.trim() : "";
38103
- if (explicitProviderSessionId) return explicitProviderSessionId;
38104
38109
  const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
38105
38110
  if (!targetSessionId) return void 0;
38106
- const instance = h.ctx.instanceManager?.getInstance(targetSessionId);
38111
+ const session = h.ctx.sessionRegistry?.get(targetSessionId);
38112
+ const registeredProviderSessionId = typeof session?.providerSessionId === "string" ? session.providerSessionId.trim() : "";
38113
+ if (registeredProviderSessionId) return registeredProviderSessionId;
38114
+ const instance = getTargetInstance(h, args);
38107
38115
  const state = instance?.getState?.();
38108
38116
  const providerSessionId = typeof state?.providerSessionId === "string" ? state.providerSessionId.trim() : "";
38109
38117
  if (providerSessionId) return providerSessionId;
@@ -38114,6 +38122,15 @@ ${effect.notification.body || ""}`.trim();
38114
38122
  }
38115
38123
  return targetSessionId;
38116
38124
  }
38125
+ function resolveCliNativeHistorySessionId(args, currentHistorySessionId, parsedProviderSessionId) {
38126
+ const explicit = getExplicitHistorySessionId(args);
38127
+ if (explicit) return explicit;
38128
+ const parsed = typeof parsedProviderSessionId === "string" ? parsedProviderSessionId.trim() : "";
38129
+ const current = typeof currentHistorySessionId === "string" ? currentHistorySessionId.trim() : "";
38130
+ const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
38131
+ if (parsed && (!current || current === targetSessionId)) return parsed;
38132
+ return current || parsed || void 0;
38133
+ }
38117
38134
  function getInteractionId(args) {
38118
38135
  return typeof args?._interactionId === "string" && args._interactionId.trim() ? args._interactionId.trim() : void 0;
38119
38136
  }
@@ -38258,6 +38275,29 @@ ${effect.notification.body || ""}`.trim();
38258
38275
  if (CLI_NATIVE_TRANSCRIPT_PROVIDERS.has(providerType)) return true;
38259
38276
  return provider?.category === "cli" && isNativeSourceCanonicalHistory(provider?.canonicalHistory);
38260
38277
  }
38278
+ function getComparableVisibleText(message) {
38279
+ if (!message) return "";
38280
+ const role = String(message.role || "").trim().toLowerCase();
38281
+ if (role !== "user" && role !== "assistant") return "";
38282
+ const kind = String(message.kind || "standard").trim().toLowerCase();
38283
+ if (kind && kind !== "standard") return "";
38284
+ const content = flattenContent(message.content).replace(/\s+/g, " ").trim();
38285
+ return content;
38286
+ }
38287
+ function hasOverlappingVisibleConversationText(nativeMessages, ptyMessages) {
38288
+ const nativeTexts = nativeMessages.map(getComparableVisibleText).filter(Boolean);
38289
+ const ptyTexts = ptyMessages.map(getComparableVisibleText).filter(Boolean);
38290
+ if (nativeTexts.length === 0 || ptyTexts.length === 0) return false;
38291
+ for (const nativeText of nativeTexts) {
38292
+ for (const ptyText of ptyTexts) {
38293
+ if (nativeText === ptyText) return true;
38294
+ const shorter = nativeText.length <= ptyText.length ? nativeText : ptyText;
38295
+ const longer = nativeText.length <= ptyText.length ? ptyText : nativeText;
38296
+ if (shorter.length >= 32 && longer.includes(shorter)) return true;
38297
+ }
38298
+ }
38299
+ return false;
38300
+ }
38261
38301
  function hasSafeNativeHistoryMapping(args) {
38262
38302
  const explicitSessionId = String(args.historySessionId || args.providerSessionId || "").trim();
38263
38303
  if (explicitSessionId) {
@@ -38267,7 +38307,10 @@ ${effect.notification.body || ""}`.trim();
38267
38307
  }
38268
38308
  const workspace = String(args.workspace || "").trim();
38269
38309
  if (!workspace) return false;
38270
- return args.nativeMessages.some((message) => String(message?.workspace || "").trim() === workspace);
38310
+ const workspaceMatches = args.nativeMessages.some((message) => String(message?.workspace || "").trim() === workspace);
38311
+ if (!workspaceMatches) return false;
38312
+ if (!args.requireWorkspaceContentOverlap) return true;
38313
+ return hasOverlappingVisibleConversationText(args.nativeMessages, args.ptyMessages || []);
38271
38314
  }
38272
38315
  function readCliProviderNativeHistory(agentStr, args) {
38273
38316
  const sessionHistory = readProviderChatHistory(agentStr, {
@@ -38306,6 +38349,19 @@ ${effect.notification.body || ""}`.trim();
38306
38349
  function shouldPreserveReadChatPayloadField(key) {
38307
38350
  return key === "messageSource" || key === "transcriptProvenance";
38308
38351
  }
38352
+ function updateMessageSourceReturnedCount(value, returnedMessageCount) {
38353
+ if (!value || typeof value !== "object" || Array.isArray(value)) return value;
38354
+ const record2 = value;
38355
+ const coverage = record2.coverage && typeof record2.coverage === "object" && !Array.isArray(record2.coverage) ? record2.coverage : void 0;
38356
+ if (!coverage) return value;
38357
+ return {
38358
+ ...record2,
38359
+ coverage: {
38360
+ ...coverage,
38361
+ returnedMessageCount
38362
+ }
38363
+ };
38364
+ }
38309
38365
  function deriveHistoryDedupKey(message) {
38310
38366
  const unitKey = typeof message._unitKey === "string" ? message._unitKey.trim() : "";
38311
38367
  if (unitKey) return `read_chat:${unitKey}`;
@@ -38417,6 +38473,13 @@ ${effect.notification.body || ""}`.trim();
38417
38473
  const visibleMessages = filterUserFacingChatMessages(messages);
38418
38474
  const sync = buildFullTail(visibleMessages, normalizeReadChatTailLimit(args));
38419
38475
  const hiddenMsgCount = Math.max(0, messages.length - visibleMessages.length);
38476
+ const preservedPayloadFields = Object.fromEntries(Object.entries(payload).filter(([key]) => shouldPreserveReadChatPayloadField(key)));
38477
+ if (preservedPayloadFields.messageSource) {
38478
+ preservedPayloadFields.messageSource = updateMessageSourceReturnedCount(preservedPayloadFields.messageSource, sync.messages.length);
38479
+ }
38480
+ if (preservedPayloadFields.transcriptProvenance) {
38481
+ preservedPayloadFields.transcriptProvenance = updateMessageSourceReturnedCount(preservedPayloadFields.transcriptProvenance, sync.messages.length);
38482
+ }
38420
38483
  const returnedDebugReadChat = debugReadChat ? {
38421
38484
  ...debugReadChat,
38422
38485
  fullMsgCount: typeof debugReadChat.fullMsgCount === "number" ? debugReadChat.fullMsgCount : messages.length,
@@ -38427,7 +38490,7 @@ ${effect.notification.body || ""}`.trim();
38427
38490
  return {
38428
38491
  success: true,
38429
38492
  ...validatedPayload,
38430
- ...Object.fromEntries(Object.entries(payload).filter(([key]) => shouldPreserveReadChatPayloadField(key))),
38493
+ ...preservedPayloadFields,
38431
38494
  messages: sync.messages,
38432
38495
  totalMessages: sync.totalMessages,
38433
38496
  ...returnedDebugReadChat ? { debugReadChat: returnedDebugReadChat } : {}
@@ -38902,14 +38965,16 @@ ${effect.notification.body || ""}`.trim();
38902
38965
  returnedMessages.length,
38903
38966
  200
38904
38967
  );
38968
+ const nativeHistorySessionId = resolveCliNativeHistorySessionId(args, historySessionId, providerSessionId);
38969
+ const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
38905
38970
  const exactNativeHistoryScope = Boolean(
38906
- typeof args?.historySessionId === "string" && args.historySessionId.trim() || typeof args?.providerSessionId === "string" && args.providerSessionId.trim() || providerSessionId || h.currentSession?.sessionId === args?.targetSessionId && typeof h.currentSession?.providerSessionId === "string" && h.currentSession.providerSessionId.trim()
38971
+ typeof args?.historySessionId === "string" && args.historySessionId.trim() || typeof args?.providerSessionId === "string" && args.providerSessionId.trim() || providerSessionId || nativeHistorySessionId && nativeHistorySessionId !== targetSessionId || h.currentSession?.sessionId === args?.targetSessionId && typeof h.currentSession?.providerSessionId === "string" && h.currentSession.providerSessionId.trim()
38907
38972
  );
38908
38973
  let nativeHistory = null;
38909
38974
  try {
38910
38975
  nativeHistory = readCliProviderNativeHistory(agentStr, {
38911
38976
  canonicalHistory: provider?.canonicalHistory,
38912
- historySessionId,
38977
+ historySessionId: nativeHistorySessionId,
38913
38978
  workspace,
38914
38979
  offset: 0,
38915
38980
  limit: nativeHistoryLimit,
@@ -38932,13 +38997,15 @@ ${effect.notification.body || ""}`.trim();
38932
38997
  }
38933
38998
  if (nativeHistory) {
38934
38999
  const nativeMessages = Array.isArray(nativeHistory.messages) ? normalizeNativeHistoryMessages(agentStr, nativeHistory.messages) : [];
38935
- const historyProviderSessionId = typeof nativeHistory?.providerSessionId === "string" ? nativeHistory.providerSessionId : readHistorySessionIdFromMessages(nativeMessages) || historySessionId;
39000
+ const historyProviderSessionId = typeof nativeHistory?.providerSessionId === "string" ? nativeHistory.providerSessionId : readHistorySessionIdFromMessages(nativeMessages) || nativeHistorySessionId || historySessionId;
38936
39001
  const lookup = nativeHistory.lookup === "workspace" ? "workspace" : "session";
38937
39002
  const safeMapping = hasSafeNativeHistoryMapping({
38938
- historySessionId: lookup === "workspace" ? void 0 : historySessionId,
38939
- providerSessionId: lookup === "workspace" ? void 0 : providerSessionId,
39003
+ historySessionId: lookup === "workspace" ? void 0 : nativeHistorySessionId,
39004
+ providerSessionId: lookup === "workspace" ? void 0 : historyProviderSessionId || providerSessionId,
38940
39005
  workspace,
38941
- nativeMessages
39006
+ nativeMessages,
39007
+ ptyMessages: returnedMessages,
39008
+ requireWorkspaceContentOverlap: lookup === "workspace" && !exactNativeHistoryScope
38942
39009
  });
38943
39010
  const freshEnough = isNativeHistoryFreshEnough({
38944
39011
  sourceMtimeMs: nativeHistory.sourceMtimeMs,
@@ -38953,7 +39020,7 @@ ${effect.notification.body || ""}`.trim();
38953
39020
  messageSource = buildCliMessageSourceProvenance({
38954
39021
  selected: "native-history",
38955
39022
  provider: adapter.cliType,
38956
- nativeHandle: selectedProviderSessionId || historySessionId,
39023
+ nativeHandle: selectedProviderSessionId || nativeHistorySessionId || historySessionId,
38957
39024
  nativeSource: nativeHistory.source,
38958
39025
  sourcePath: nativeHistory.sourcePath,
38959
39026
  sourceMtimeMs: nativeHistory.sourceMtimeMs,
@@ -38976,7 +39043,7 @@ ${effect.notification.body || ""}`.trim();
38976
39043
  messageSource = buildCliMessageSourceProvenance({
38977
39044
  selected: "pty-parser",
38978
39045
  provider: adapter.cliType,
38979
- nativeHandle: historyProviderSessionId || historySessionId,
39046
+ nativeHandle: historyProviderSessionId || nativeHistorySessionId || historySessionId,
38980
39047
  fallbackReason,
38981
39048
  nativeSource: nativeHistory.source,
38982
39049
  sourcePath: nativeHistory.sourcePath,