@adhdev/daemon-core 0.9.82-rc.91 → 0.9.82-rc.93

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.mjs CHANGED
@@ -5876,7 +5876,7 @@ ${lastSnapshot}`;
5876
5876
  const parseScreenText = this.getParseScreenText(screenText);
5877
5877
  const cached = this.parsedStatusCache;
5878
5878
  const accumulatedRawBufferKey = this.getAccumulatedRawBufferCacheKey();
5879
- if (cached && cached.responseBuffer === this.responseBuffer && cached.currentTurnScope === this.currentTurnScope && cached.recentOutputBuffer === this.recentOutputBuffer && cached.accumulatedBuffer === this.accumulatedBuffer && cached.accumulatedRawBufferKey === accumulatedRawBufferKey && cached.screenText === parseScreenText && cached.currentStatus === this.currentStatus && cached.activeModal === this.activeModal && cached.cliName === this.cliName) {
5879
+ if (!this.providerOwnsTranscript() && cached && cached.responseBuffer === this.responseBuffer && cached.currentTurnScope === this.currentTurnScope && cached.recentOutputBuffer === this.recentOutputBuffer && cached.accumulatedBuffer === this.accumulatedBuffer && cached.accumulatedRawBufferKey === accumulatedRawBufferKey && cached.screenText === parseScreenText && cached.currentStatus === this.currentStatus && cached.activeModal === this.activeModal && cached.cliName === this.cliName) {
5880
5880
  return cached.result;
5881
5881
  }
5882
5882
  const parsed = this.runParseSession();
@@ -15740,6 +15740,13 @@ function getCurrentManagerKey(h) {
15740
15740
  function getTargetedCliAdapter(h, args, providerType) {
15741
15741
  return h.getCliAdapter(args?.targetSessionId || providerType || h.currentSession?.providerType || h.currentManagerKey);
15742
15742
  }
15743
+ function getExplicitHistorySessionId(args) {
15744
+ const explicit = typeof args?.historySessionId === "string" ? args.historySessionId.trim() : "";
15745
+ if (explicit) return explicit;
15746
+ const explicitProviderSessionId = typeof args?.providerSessionId === "string" ? args.providerSessionId.trim() : "";
15747
+ if (explicitProviderSessionId) return explicitProviderSessionId;
15748
+ return void 0;
15749
+ }
15743
15750
  function getTargetInstance(h, args) {
15744
15751
  const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
15745
15752
  const sessionId = targetSessionId || h.currentSession?.sessionId || "";
@@ -15808,13 +15815,14 @@ async function waitOnceForFreshHermesCliStart(adapter, log) {
15808
15815
  await sleep(HERMES_CLI_STARTING_SEND_SETTLE_MS);
15809
15816
  }
15810
15817
  function getHistorySessionId(h, args) {
15811
- const explicit = typeof args?.historySessionId === "string" ? args.historySessionId.trim() : "";
15818
+ const explicit = getExplicitHistorySessionId(args);
15812
15819
  if (explicit) return explicit;
15813
- const explicitProviderSessionId = typeof args?.providerSessionId === "string" ? args.providerSessionId.trim() : "";
15814
- if (explicitProviderSessionId) return explicitProviderSessionId;
15815
15820
  const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
15816
15821
  if (!targetSessionId) return void 0;
15817
- const instance = h.ctx.instanceManager?.getInstance(targetSessionId);
15822
+ const session = h.ctx.sessionRegistry?.get(targetSessionId);
15823
+ const registeredProviderSessionId = typeof session?.providerSessionId === "string" ? session.providerSessionId.trim() : "";
15824
+ if (registeredProviderSessionId) return registeredProviderSessionId;
15825
+ const instance = getTargetInstance(h, args);
15818
15826
  const state = instance?.getState?.();
15819
15827
  const providerSessionId = typeof state?.providerSessionId === "string" ? state.providerSessionId.trim() : "";
15820
15828
  if (providerSessionId) return providerSessionId;
@@ -15825,6 +15833,15 @@ function getHistorySessionId(h, args) {
15825
15833
  }
15826
15834
  return targetSessionId;
15827
15835
  }
15836
+ function resolveCliNativeHistorySessionId(args, currentHistorySessionId, parsedProviderSessionId) {
15837
+ const explicit = getExplicitHistorySessionId(args);
15838
+ if (explicit) return explicit;
15839
+ const parsed = typeof parsedProviderSessionId === "string" ? parsedProviderSessionId.trim() : "";
15840
+ const current = typeof currentHistorySessionId === "string" ? currentHistorySessionId.trim() : "";
15841
+ const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
15842
+ if (parsed && (!current || current === targetSessionId)) return parsed;
15843
+ return current || parsed || void 0;
15844
+ }
15828
15845
  function getInteractionId(args) {
15829
15846
  return typeof args?._interactionId === "string" && args._interactionId.trim() ? args._interactionId.trim() : void 0;
15830
15847
  }
@@ -15969,6 +15986,29 @@ function supportsCliNativeTranscript(providerType, provider) {
15969
15986
  if (CLI_NATIVE_TRANSCRIPT_PROVIDERS.has(providerType)) return true;
15970
15987
  return provider?.category === "cli" && isNativeSourceCanonicalHistory(provider?.canonicalHistory);
15971
15988
  }
15989
+ function getComparableVisibleText(message) {
15990
+ if (!message) return "";
15991
+ const role = String(message.role || "").trim().toLowerCase();
15992
+ if (role !== "user" && role !== "assistant") return "";
15993
+ const kind = String(message.kind || "standard").trim().toLowerCase();
15994
+ if (kind && kind !== "standard") return "";
15995
+ const content = flattenContent(message.content).replace(/\s+/g, " ").trim();
15996
+ return content;
15997
+ }
15998
+ function hasOverlappingVisibleConversationText(nativeMessages, ptyMessages) {
15999
+ const nativeTexts = nativeMessages.map(getComparableVisibleText).filter(Boolean);
16000
+ const ptyTexts = ptyMessages.map(getComparableVisibleText).filter(Boolean);
16001
+ if (nativeTexts.length === 0 || ptyTexts.length === 0) return false;
16002
+ for (const nativeText of nativeTexts) {
16003
+ for (const ptyText of ptyTexts) {
16004
+ if (nativeText === ptyText) return true;
16005
+ const shorter = nativeText.length <= ptyText.length ? nativeText : ptyText;
16006
+ const longer = nativeText.length <= ptyText.length ? ptyText : nativeText;
16007
+ if (shorter.length >= 32 && longer.includes(shorter)) return true;
16008
+ }
16009
+ }
16010
+ return false;
16011
+ }
15972
16012
  function hasSafeNativeHistoryMapping(args) {
15973
16013
  const explicitSessionId = String(args.historySessionId || args.providerSessionId || "").trim();
15974
16014
  if (explicitSessionId) {
@@ -15978,7 +16018,10 @@ function hasSafeNativeHistoryMapping(args) {
15978
16018
  }
15979
16019
  const workspace = String(args.workspace || "").trim();
15980
16020
  if (!workspace) return false;
15981
- return args.nativeMessages.some((message) => String(message?.workspace || "").trim() === workspace);
16021
+ const workspaceMatches = args.nativeMessages.some((message) => String(message?.workspace || "").trim() === workspace);
16022
+ if (!workspaceMatches) return false;
16023
+ if (!args.requireWorkspaceContentOverlap) return true;
16024
+ return hasOverlappingVisibleConversationText(args.nativeMessages, args.ptyMessages || []);
15982
16025
  }
15983
16026
  function readCliProviderNativeHistory(agentStr, args) {
15984
16027
  const sessionHistory = readProviderChatHistory(agentStr, {
@@ -16017,6 +16060,19 @@ function isNativeHistoryFreshEnough(args) {
16017
16060
  function shouldPreserveReadChatPayloadField(key) {
16018
16061
  return key === "messageSource" || key === "transcriptProvenance";
16019
16062
  }
16063
+ function updateMessageSourceReturnedCount(value, returnedMessageCount) {
16064
+ if (!value || typeof value !== "object" || Array.isArray(value)) return value;
16065
+ const record = value;
16066
+ const coverage = record.coverage && typeof record.coverage === "object" && !Array.isArray(record.coverage) ? record.coverage : void 0;
16067
+ if (!coverage) return value;
16068
+ return {
16069
+ ...record,
16070
+ coverage: {
16071
+ ...coverage,
16072
+ returnedMessageCount
16073
+ }
16074
+ };
16075
+ }
16020
16076
  function deriveHistoryDedupKey(message) {
16021
16077
  const unitKey = typeof message._unitKey === "string" ? message._unitKey.trim() : "";
16022
16078
  if (unitKey) return `read_chat:${unitKey}`;
@@ -16128,6 +16184,13 @@ function buildReadChatCommandResult(payload, args) {
16128
16184
  const visibleMessages = filterUserFacingChatMessages(messages);
16129
16185
  const sync = buildFullTail(visibleMessages, normalizeReadChatTailLimit(args));
16130
16186
  const hiddenMsgCount = Math.max(0, messages.length - visibleMessages.length);
16187
+ const preservedPayloadFields = Object.fromEntries(Object.entries(payload).filter(([key]) => shouldPreserveReadChatPayloadField(key)));
16188
+ if (preservedPayloadFields.messageSource) {
16189
+ preservedPayloadFields.messageSource = updateMessageSourceReturnedCount(preservedPayloadFields.messageSource, sync.messages.length);
16190
+ }
16191
+ if (preservedPayloadFields.transcriptProvenance) {
16192
+ preservedPayloadFields.transcriptProvenance = updateMessageSourceReturnedCount(preservedPayloadFields.transcriptProvenance, sync.messages.length);
16193
+ }
16131
16194
  const returnedDebugReadChat = debugReadChat ? {
16132
16195
  ...debugReadChat,
16133
16196
  fullMsgCount: typeof debugReadChat.fullMsgCount === "number" ? debugReadChat.fullMsgCount : messages.length,
@@ -16138,7 +16201,7 @@ function buildReadChatCommandResult(payload, args) {
16138
16201
  return {
16139
16202
  success: true,
16140
16203
  ...validatedPayload,
16141
- ...Object.fromEntries(Object.entries(payload).filter(([key]) => shouldPreserveReadChatPayloadField(key))),
16204
+ ...preservedPayloadFields,
16142
16205
  messages: sync.messages,
16143
16206
  totalMessages: sync.totalMessages,
16144
16207
  ...returnedDebugReadChat ? { debugReadChat: returnedDebugReadChat } : {}
@@ -16613,14 +16676,16 @@ async function handleReadChat(h, args) {
16613
16676
  returnedMessages.length,
16614
16677
  200
16615
16678
  );
16679
+ const nativeHistorySessionId = resolveCliNativeHistorySessionId(args, historySessionId, providerSessionId);
16680
+ const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
16616
16681
  const exactNativeHistoryScope = Boolean(
16617
- 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()
16682
+ 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()
16618
16683
  );
16619
16684
  let nativeHistory = null;
16620
16685
  try {
16621
16686
  nativeHistory = readCliProviderNativeHistory(agentStr, {
16622
16687
  canonicalHistory: provider?.canonicalHistory,
16623
- historySessionId,
16688
+ historySessionId: nativeHistorySessionId,
16624
16689
  workspace,
16625
16690
  offset: 0,
16626
16691
  limit: nativeHistoryLimit,
@@ -16643,13 +16708,15 @@ async function handleReadChat(h, args) {
16643
16708
  }
16644
16709
  if (nativeHistory) {
16645
16710
  const nativeMessages = Array.isArray(nativeHistory.messages) ? normalizeNativeHistoryMessages(agentStr, nativeHistory.messages) : [];
16646
- const historyProviderSessionId = typeof nativeHistory?.providerSessionId === "string" ? nativeHistory.providerSessionId : readHistorySessionIdFromMessages(nativeMessages) || historySessionId;
16711
+ const historyProviderSessionId = typeof nativeHistory?.providerSessionId === "string" ? nativeHistory.providerSessionId : readHistorySessionIdFromMessages(nativeMessages) || nativeHistorySessionId || historySessionId;
16647
16712
  const lookup = nativeHistory.lookup === "workspace" ? "workspace" : "session";
16648
16713
  const safeMapping = hasSafeNativeHistoryMapping({
16649
- historySessionId: lookup === "workspace" ? void 0 : historySessionId,
16650
- providerSessionId: lookup === "workspace" ? void 0 : providerSessionId,
16714
+ historySessionId: lookup === "workspace" ? void 0 : nativeHistorySessionId,
16715
+ providerSessionId: lookup === "workspace" ? void 0 : historyProviderSessionId || providerSessionId,
16651
16716
  workspace,
16652
- nativeMessages
16717
+ nativeMessages,
16718
+ ptyMessages: returnedMessages,
16719
+ requireWorkspaceContentOverlap: lookup === "workspace" && !exactNativeHistoryScope
16653
16720
  });
16654
16721
  const freshEnough = isNativeHistoryFreshEnough({
16655
16722
  sourceMtimeMs: nativeHistory.sourceMtimeMs,
@@ -16664,7 +16731,7 @@ async function handleReadChat(h, args) {
16664
16731
  messageSource = buildCliMessageSourceProvenance({
16665
16732
  selected: "native-history",
16666
16733
  provider: adapter.cliType,
16667
- nativeHandle: selectedProviderSessionId || historySessionId,
16734
+ nativeHandle: selectedProviderSessionId || nativeHistorySessionId || historySessionId,
16668
16735
  nativeSource: nativeHistory.source,
16669
16736
  sourcePath: nativeHistory.sourcePath,
16670
16737
  sourceMtimeMs: nativeHistory.sourceMtimeMs,
@@ -16687,7 +16754,7 @@ async function handleReadChat(h, args) {
16687
16754
  messageSource = buildCliMessageSourceProvenance({
16688
16755
  selected: "pty-parser",
16689
16756
  provider: adapter.cliType,
16690
- nativeHandle: historyProviderSessionId || historySessionId,
16757
+ nativeHandle: historyProviderSessionId || nativeHistorySessionId || historySessionId,
16691
16758
  fallbackReason,
16692
16759
  nativeSource: nativeHistory.source,
16693
16760
  sourcePath: nativeHistory.sourcePath,