@adhdev/daemon-core 0.9.82-rc.87 → 0.9.82-rc.88

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
@@ -15845,6 +15845,54 @@ function getMessageNewestReceivedAt(messages) {
15845
15845
  }
15846
15846
  return newest;
15847
15847
  }
15848
+ function readHistorySessionIdFromMessages(messages) {
15849
+ for (const message of messages) {
15850
+ const historySessionId = typeof message?.historySessionId === "string" ? message.historySessionId.trim() : "";
15851
+ if (historySessionId) return historySessionId;
15852
+ }
15853
+ return void 0;
15854
+ }
15855
+ function normalizeNativeHistoryMessages(providerType, messages) {
15856
+ let turnIndex = 0;
15857
+ return normalizeChatMessages(messages).map((message, index) => {
15858
+ const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
15859
+ const kind = typeof message.kind === "string" && message.kind.trim() ? message.kind.trim() : role === "system" ? "system" : "standard";
15860
+ if ((role === "user" || role === "human") && index > 0) turnIndex += 1;
15861
+ const historySessionId = typeof message.historySessionId === "string" ? message.historySessionId.trim() : "";
15862
+ const contentHash = hashSignatureParts([
15863
+ providerType,
15864
+ historySessionId,
15865
+ String(message.receivedAt || message.timestamp || index),
15866
+ role,
15867
+ kind,
15868
+ flattenContent(message.content)
15869
+ ]).slice(0, 12);
15870
+ const providerUnitKey = typeof message.providerUnitKey === "string" && message.providerUnitKey.trim() ? message.providerUnitKey.trim() : `${providerType}:native:${historySessionId || "workspace"}:${index}:${role || "message"}:${kind}:${contentHash}`;
15871
+ const meta = message.meta && typeof message.meta === "object" ? message.meta : void 0;
15872
+ const isSystemSessionStart = role === "system" || kind === "system" || kind === "session_start";
15873
+ const isActivity = role === "assistant" && (kind === "tool" || kind === "terminal" || kind === "thought");
15874
+ return {
15875
+ ...message,
15876
+ role: role === "human" ? "user" : role || "assistant",
15877
+ kind: isSystemSessionStart ? "system" : kind,
15878
+ providerUnitKey,
15879
+ bubbleId: typeof message.bubbleId === "string" && message.bubbleId.trim() ? message.bubbleId.trim() : `bubble:${providerUnitKey}`,
15880
+ _turnKey: typeof message._turnKey === "string" && message._turnKey.trim() ? message._turnKey.trim() : `${providerType}:native-turn:${historySessionId || "workspace"}:${turnIndex}`,
15881
+ bubbleState: message.bubbleState || "final",
15882
+ ...isSystemSessionStart ? {
15883
+ visibility: message.visibility || "hidden",
15884
+ transcriptVisibility: message.transcriptVisibility || "hidden",
15885
+ audience: message.audience || "internal",
15886
+ source: message.source || "runtime_status"
15887
+ } : isActivity ? {
15888
+ source: message.source || (kind === "terminal" ? "terminal_command" : "tool_call"),
15889
+ meta: { ...meta, label: message.senderName || meta?.label || (kind === "terminal" ? "Terminal" : "Tool") }
15890
+ } : {
15891
+ source: message.source || (role === "assistant" ? "assistant_text" : void 0)
15892
+ }
15893
+ };
15894
+ });
15895
+ }
15848
15896
  function buildCliMessageSourceProvenance(args) {
15849
15897
  const sourceMtimeMs = Number(args.sourceMtimeMs || 0);
15850
15898
  const sourceMtimeAgeMs = sourceMtimeMs > 0 ? Math.max(0, Date.now() - sourceMtimeMs) : void 0;
@@ -15900,6 +15948,32 @@ function hasSafeNativeHistoryMapping(args) {
15900
15948
  if (!workspace) return false;
15901
15949
  return args.nativeMessages.some((message) => String(message?.workspace || "").trim() === workspace);
15902
15950
  }
15951
+ function readCliProviderNativeHistory(agentStr, args) {
15952
+ const sessionHistory = readProviderChatHistory(agentStr, {
15953
+ canonicalHistory: args.canonicalHistory,
15954
+ historySessionId: args.historySessionId,
15955
+ workspace: args.workspace,
15956
+ offset: args.offset,
15957
+ limit: args.limit,
15958
+ excludeRecentCount: args.excludeRecentCount,
15959
+ historyBehavior: args.historyBehavior,
15960
+ scripts: args.scripts
15961
+ });
15962
+ if (sessionHistory.source !== "native-unavailable" || !args.historySessionId || !args.workspace) {
15963
+ return { ...sessionHistory, lookup: "session" };
15964
+ }
15965
+ const workspaceHistory = readProviderChatHistory(agentStr, {
15966
+ canonicalHistory: args.canonicalHistory,
15967
+ historySessionId: void 0,
15968
+ workspace: args.workspace,
15969
+ offset: args.offset,
15970
+ limit: args.limit,
15971
+ excludeRecentCount: args.excludeRecentCount,
15972
+ historyBehavior: args.historyBehavior,
15973
+ scripts: args.scripts
15974
+ });
15975
+ return { ...workspaceHistory, lookup: "workspace" };
15976
+ }
15903
15977
  function isNativeHistoryFreshEnough(args) {
15904
15978
  const nativeNewest = getMessageNewestReceivedAt(args.nativeMessages);
15905
15979
  const ptyNewest = getMessageNewestReceivedAt(args.ptyMessages);
@@ -16509,7 +16583,7 @@ async function handleReadChat(h, args) {
16509
16583
  );
16510
16584
  let nativeHistory = null;
16511
16585
  try {
16512
- nativeHistory = readProviderChatHistory(agentStr, {
16586
+ nativeHistory = readCliProviderNativeHistory(agentStr, {
16513
16587
  canonicalHistory: provider?.canonicalHistory,
16514
16588
  historySessionId,
16515
16589
  workspace,
@@ -16532,11 +16606,12 @@ async function handleReadChat(h, args) {
16532
16606
  nativeHistory = null;
16533
16607
  }
16534
16608
  if (nativeHistory) {
16535
- const nativeMessages = Array.isArray(nativeHistory.messages) ? normalizeChatMessages(nativeHistory.messages) : [];
16536
- const historyProviderSessionId = typeof nativeHistory?.providerSessionId === "string" ? nativeHistory.providerSessionId : historySessionId;
16609
+ const nativeMessages = Array.isArray(nativeHistory.messages) ? normalizeNativeHistoryMessages(agentStr, nativeHistory.messages) : [];
16610
+ const historyProviderSessionId = typeof nativeHistory?.providerSessionId === "string" ? nativeHistory.providerSessionId : readHistorySessionIdFromMessages(nativeMessages) || historySessionId;
16611
+ const lookup = nativeHistory.lookup === "workspace" ? "workspace" : "session";
16537
16612
  const safeMapping = hasSafeNativeHistoryMapping({
16538
- historySessionId,
16539
- providerSessionId,
16613
+ historySessionId: lookup === "workspace" ? void 0 : historySessionId,
16614
+ providerSessionId: lookup === "workspace" ? void 0 : providerSessionId,
16540
16615
  workspace,
16541
16616
  nativeMessages
16542
16617
  });
@@ -16620,7 +16695,16 @@ async function handleReadChat(h, args) {
16620
16695
  try {
16621
16696
  const agentStr = provider?.type || args?.agentType || getCurrentProviderType(h);
16622
16697
  const workspace = typeof args?.workspace === "string" ? args.workspace : typeof h.currentSession?.workspace === "string" ? h.currentSession.workspace : void 0;
16623
- const history = readProviderChatHistory(agentStr, {
16698
+ const history = supportsCliNativeTranscript(agentStr, provider) && isNativeSourceCanonicalHistory(provider?.canonicalHistory) ? readCliProviderNativeHistory(agentStr, {
16699
+ canonicalHistory: provider?.canonicalHistory,
16700
+ historySessionId,
16701
+ workspace,
16702
+ offset: 0,
16703
+ limit: historyLimit,
16704
+ excludeRecentCount: 0,
16705
+ historyBehavior: provider?.historyBehavior,
16706
+ scripts: provider?.scripts
16707
+ }) : readProviderChatHistory(agentStr, {
16624
16708
  canonicalHistory: provider?.canonicalHistory,
16625
16709
  historySessionId,
16626
16710
  workspace,
@@ -16630,11 +16714,12 @@ async function handleReadChat(h, args) {
16630
16714
  historyBehavior: provider?.historyBehavior,
16631
16715
  scripts: provider?.scripts
16632
16716
  });
16633
- const historyProviderSessionId = typeof history?.providerSessionId === "string" ? history.providerSessionId : historySessionId;
16634
- const historyMessages = Array.isArray(history?.messages) ? normalizeChatMessages(history.messages) : [];
16717
+ const lookup = history.lookup === "workspace" ? "workspace" : "session";
16718
+ const historyMessages = Array.isArray(history?.messages) ? normalizeNativeHistoryMessages(agentStr, history.messages) : [];
16719
+ const historyProviderSessionId = typeof history?.providerSessionId === "string" ? history.providerSessionId : readHistorySessionIdFromMessages(historyMessages) || historySessionId;
16635
16720
  const safeMapping = supportsCliNativeTranscript(agentStr, provider) ? hasSafeNativeHistoryMapping({
16636
- historySessionId,
16637
- providerSessionId: historyProviderSessionId,
16721
+ historySessionId: lookup === "workspace" ? void 0 : historySessionId,
16722
+ providerSessionId: lookup === "workspace" ? void 0 : historyProviderSessionId,
16638
16723
  workspace,
16639
16724
  nativeMessages: historyMessages
16640
16725
  }) : false;