@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.js CHANGED
@@ -16104,6 +16104,54 @@ function getMessageNewestReceivedAt(messages) {
16104
16104
  }
16105
16105
  return newest;
16106
16106
  }
16107
+ function readHistorySessionIdFromMessages(messages) {
16108
+ for (const message of messages) {
16109
+ const historySessionId = typeof message?.historySessionId === "string" ? message.historySessionId.trim() : "";
16110
+ if (historySessionId) return historySessionId;
16111
+ }
16112
+ return void 0;
16113
+ }
16114
+ function normalizeNativeHistoryMessages(providerType, messages) {
16115
+ let turnIndex = 0;
16116
+ return normalizeChatMessages(messages).map((message, index) => {
16117
+ const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
16118
+ const kind = typeof message.kind === "string" && message.kind.trim() ? message.kind.trim() : role === "system" ? "system" : "standard";
16119
+ if ((role === "user" || role === "human") && index > 0) turnIndex += 1;
16120
+ const historySessionId = typeof message.historySessionId === "string" ? message.historySessionId.trim() : "";
16121
+ const contentHash = hashSignatureParts([
16122
+ providerType,
16123
+ historySessionId,
16124
+ String(message.receivedAt || message.timestamp || index),
16125
+ role,
16126
+ kind,
16127
+ flattenContent(message.content)
16128
+ ]).slice(0, 12);
16129
+ const providerUnitKey = typeof message.providerUnitKey === "string" && message.providerUnitKey.trim() ? message.providerUnitKey.trim() : `${providerType}:native:${historySessionId || "workspace"}:${index}:${role || "message"}:${kind}:${contentHash}`;
16130
+ const meta = message.meta && typeof message.meta === "object" ? message.meta : void 0;
16131
+ const isSystemSessionStart = role === "system" || kind === "system" || kind === "session_start";
16132
+ const isActivity = role === "assistant" && (kind === "tool" || kind === "terminal" || kind === "thought");
16133
+ return {
16134
+ ...message,
16135
+ role: role === "human" ? "user" : role || "assistant",
16136
+ kind: isSystemSessionStart ? "system" : kind,
16137
+ providerUnitKey,
16138
+ bubbleId: typeof message.bubbleId === "string" && message.bubbleId.trim() ? message.bubbleId.trim() : `bubble:${providerUnitKey}`,
16139
+ _turnKey: typeof message._turnKey === "string" && message._turnKey.trim() ? message._turnKey.trim() : `${providerType}:native-turn:${historySessionId || "workspace"}:${turnIndex}`,
16140
+ bubbleState: message.bubbleState || "final",
16141
+ ...isSystemSessionStart ? {
16142
+ visibility: message.visibility || "hidden",
16143
+ transcriptVisibility: message.transcriptVisibility || "hidden",
16144
+ audience: message.audience || "internal",
16145
+ source: message.source || "runtime_status"
16146
+ } : isActivity ? {
16147
+ source: message.source || (kind === "terminal" ? "terminal_command" : "tool_call"),
16148
+ meta: { ...meta, label: message.senderName || meta?.label || (kind === "terminal" ? "Terminal" : "Tool") }
16149
+ } : {
16150
+ source: message.source || (role === "assistant" ? "assistant_text" : void 0)
16151
+ }
16152
+ };
16153
+ });
16154
+ }
16107
16155
  function buildCliMessageSourceProvenance(args) {
16108
16156
  const sourceMtimeMs = Number(args.sourceMtimeMs || 0);
16109
16157
  const sourceMtimeAgeMs = sourceMtimeMs > 0 ? Math.max(0, Date.now() - sourceMtimeMs) : void 0;
@@ -16159,6 +16207,32 @@ function hasSafeNativeHistoryMapping(args) {
16159
16207
  if (!workspace) return false;
16160
16208
  return args.nativeMessages.some((message) => String(message?.workspace || "").trim() === workspace);
16161
16209
  }
16210
+ function readCliProviderNativeHistory(agentStr, args) {
16211
+ const sessionHistory = readProviderChatHistory(agentStr, {
16212
+ canonicalHistory: args.canonicalHistory,
16213
+ historySessionId: args.historySessionId,
16214
+ workspace: args.workspace,
16215
+ offset: args.offset,
16216
+ limit: args.limit,
16217
+ excludeRecentCount: args.excludeRecentCount,
16218
+ historyBehavior: args.historyBehavior,
16219
+ scripts: args.scripts
16220
+ });
16221
+ if (sessionHistory.source !== "native-unavailable" || !args.historySessionId || !args.workspace) {
16222
+ return { ...sessionHistory, lookup: "session" };
16223
+ }
16224
+ const workspaceHistory = readProviderChatHistory(agentStr, {
16225
+ canonicalHistory: args.canonicalHistory,
16226
+ historySessionId: void 0,
16227
+ workspace: args.workspace,
16228
+ offset: args.offset,
16229
+ limit: args.limit,
16230
+ excludeRecentCount: args.excludeRecentCount,
16231
+ historyBehavior: args.historyBehavior,
16232
+ scripts: args.scripts
16233
+ });
16234
+ return { ...workspaceHistory, lookup: "workspace" };
16235
+ }
16162
16236
  function isNativeHistoryFreshEnough(args) {
16163
16237
  const nativeNewest = getMessageNewestReceivedAt(args.nativeMessages);
16164
16238
  const ptyNewest = getMessageNewestReceivedAt(args.ptyMessages);
@@ -16768,7 +16842,7 @@ async function handleReadChat(h, args) {
16768
16842
  );
16769
16843
  let nativeHistory = null;
16770
16844
  try {
16771
- nativeHistory = readProviderChatHistory(agentStr, {
16845
+ nativeHistory = readCliProviderNativeHistory(agentStr, {
16772
16846
  canonicalHistory: provider?.canonicalHistory,
16773
16847
  historySessionId,
16774
16848
  workspace,
@@ -16791,11 +16865,12 @@ async function handleReadChat(h, args) {
16791
16865
  nativeHistory = null;
16792
16866
  }
16793
16867
  if (nativeHistory) {
16794
- const nativeMessages = Array.isArray(nativeHistory.messages) ? normalizeChatMessages(nativeHistory.messages) : [];
16795
- const historyProviderSessionId = typeof nativeHistory?.providerSessionId === "string" ? nativeHistory.providerSessionId : historySessionId;
16868
+ const nativeMessages = Array.isArray(nativeHistory.messages) ? normalizeNativeHistoryMessages(agentStr, nativeHistory.messages) : [];
16869
+ const historyProviderSessionId = typeof nativeHistory?.providerSessionId === "string" ? nativeHistory.providerSessionId : readHistorySessionIdFromMessages(nativeMessages) || historySessionId;
16870
+ const lookup = nativeHistory.lookup === "workspace" ? "workspace" : "session";
16796
16871
  const safeMapping = hasSafeNativeHistoryMapping({
16797
- historySessionId,
16798
- providerSessionId,
16872
+ historySessionId: lookup === "workspace" ? void 0 : historySessionId,
16873
+ providerSessionId: lookup === "workspace" ? void 0 : providerSessionId,
16799
16874
  workspace,
16800
16875
  nativeMessages
16801
16876
  });
@@ -16879,7 +16954,16 @@ async function handleReadChat(h, args) {
16879
16954
  try {
16880
16955
  const agentStr = provider?.type || args?.agentType || getCurrentProviderType(h);
16881
16956
  const workspace = typeof args?.workspace === "string" ? args.workspace : typeof h.currentSession?.workspace === "string" ? h.currentSession.workspace : void 0;
16882
- const history = readProviderChatHistory(agentStr, {
16957
+ const history = supportsCliNativeTranscript(agentStr, provider) && isNativeSourceCanonicalHistory(provider?.canonicalHistory) ? readCliProviderNativeHistory(agentStr, {
16958
+ canonicalHistory: provider?.canonicalHistory,
16959
+ historySessionId,
16960
+ workspace,
16961
+ offset: 0,
16962
+ limit: historyLimit,
16963
+ excludeRecentCount: 0,
16964
+ historyBehavior: provider?.historyBehavior,
16965
+ scripts: provider?.scripts
16966
+ }) : readProviderChatHistory(agentStr, {
16883
16967
  canonicalHistory: provider?.canonicalHistory,
16884
16968
  historySessionId,
16885
16969
  workspace,
@@ -16889,11 +16973,12 @@ async function handleReadChat(h, args) {
16889
16973
  historyBehavior: provider?.historyBehavior,
16890
16974
  scripts: provider?.scripts
16891
16975
  });
16892
- const historyProviderSessionId = typeof history?.providerSessionId === "string" ? history.providerSessionId : historySessionId;
16893
- const historyMessages = Array.isArray(history?.messages) ? normalizeChatMessages(history.messages) : [];
16976
+ const lookup = history.lookup === "workspace" ? "workspace" : "session";
16977
+ const historyMessages = Array.isArray(history?.messages) ? normalizeNativeHistoryMessages(agentStr, history.messages) : [];
16978
+ const historyProviderSessionId = typeof history?.providerSessionId === "string" ? history.providerSessionId : readHistorySessionIdFromMessages(historyMessages) || historySessionId;
16894
16979
  const safeMapping = supportsCliNativeTranscript(agentStr, provider) ? hasSafeNativeHistoryMapping({
16895
- historySessionId,
16896
- providerSessionId: historyProviderSessionId,
16980
+ historySessionId: lookup === "workspace" ? void 0 : historySessionId,
16981
+ providerSessionId: lookup === "workspace" ? void 0 : historyProviderSessionId,
16897
16982
  workspace,
16898
16983
  nativeMessages: historyMessages
16899
16984
  }) : false;