@adhdev/daemon-core 0.9.82-rc.440 → 0.9.82-rc.442

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
@@ -404,10 +404,10 @@ function readInjected(value) {
404
404
  }
405
405
  function getDaemonBuildInfo() {
406
406
  if (cached) return cached;
407
- const commit = readInjected(true ? "c3062ac83f65cfbd83e0bc4236972b64a80435cc" : void 0) ?? "unknown";
408
- const commitShort = readInjected(true ? "c3062ac8" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
409
- const version = readInjected(true ? "0.9.82-rc.440" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
410
- const builtAt = readInjected(true ? "2026-07-01T05:56:51.525Z" : void 0);
407
+ const commit = readInjected(true ? "37211cd9f2109403d5da1bf739407ae80c440a60" : void 0) ?? "unknown";
408
+ const commitShort = readInjected(true ? "37211cd9" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
409
+ const version = readInjected(true ? "0.9.82-rc.442" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
410
+ const builtAt = readInjected(true ? "2026-07-01T08:08:15.319Z" : void 0);
411
411
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
412
412
  return cached;
413
413
  }
@@ -30701,6 +30701,19 @@ var CHAT_SOURCE_REGISTRY = new ChatSourceRegistry();
30701
30701
  init_chat_message_normalization();
30702
30702
  var HOT_TAIL_MIN_LIMIT = 60;
30703
30703
  var CLI_NATIVE_TRANSCRIPT_PROVIDERS = /* @__PURE__ */ new Set(["codex-cli", "claude-cli", "hermes-cli", "antigravity-cli"]);
30704
+ var lastBoundProviderSessionIdByMeshSession = /* @__PURE__ */ new Map();
30705
+ function recordBoundProviderSessionId(meshSessionId, providerSessionId) {
30706
+ const key2 = typeof meshSessionId === "string" ? meshSessionId.trim() : "";
30707
+ const value = typeof providerSessionId === "string" ? providerSessionId.trim() : "";
30708
+ if (!key2 || !value) return;
30709
+ lastBoundProviderSessionIdByMeshSession.set(key2, value);
30710
+ }
30711
+ function getBoundProviderSessionIdPin(meshSessionId) {
30712
+ const key2 = typeof meshSessionId === "string" ? meshSessionId.trim() : "";
30713
+ if (!key2) return void 0;
30714
+ const pinned = lastBoundProviderSessionIdByMeshSession.get(key2);
30715
+ return pinned && pinned.trim() ? pinned.trim() : void 0;
30716
+ }
30704
30717
  var warnedLegacyNativeAllowlistHits = /* @__PURE__ */ new Set();
30705
30718
  function warnLegacyNativeAllowlistHit(providerType) {
30706
30719
  if (warnedLegacyNativeAllowlistHits.has(providerType)) return;
@@ -31275,7 +31288,10 @@ function sessionSpawnEnvFromAdapter(h, targetSessionId) {
31275
31288
  }
31276
31289
  function readCliProviderNativeHistory(agentStr, args) {
31277
31290
  const canBindFromLiveSession = !args.historySessionId && typeof args.sessionStartedAtMs === "number" && args.sessionStartedAtMs > 0 && typeof args.workspace === "string" && args.workspace.trim().length > 0;
31278
- if (!args.historySessionId && !canBindFromLiveSession) {
31291
+ const pinnedProviderSessionId = typeof args.pinnedProviderSessionId === "string" ? args.pinnedProviderSessionId.trim() : "";
31292
+ const effectiveHistorySessionId = args.historySessionId || (!canBindFromLiveSession ? pinnedProviderSessionId : "");
31293
+ const workspaceLatestFallback = !effectiveHistorySessionId && !canBindFromLiveSession && !pinnedProviderSessionId && args.allowWorkspaceLatestFallback === true && typeof args.workspace === "string" && args.workspace.trim().length > 0;
31294
+ if (!effectiveHistorySessionId && !canBindFromLiveSession && !workspaceLatestFallback) {
31279
31295
  return {
31280
31296
  messages: [],
31281
31297
  hasMore: false,
@@ -31286,7 +31302,7 @@ function readCliProviderNativeHistory(agentStr, args) {
31286
31302
  }
31287
31303
  const sessionHistory = readProviderChatHistory(agentStr, {
31288
31304
  canonicalHistory: args.canonicalHistory,
31289
- historySessionId: args.historySessionId,
31305
+ historySessionId: effectiveHistorySessionId || void 0,
31290
31306
  workspace: args.workspace,
31291
31307
  offset: args.offset,
31292
31308
  limit: args.limit,
@@ -31300,7 +31316,7 @@ function readCliProviderNativeHistory(agentStr, args) {
31300
31316
  const boundProviderSessionId = typeof sessionHistory?.providerSessionId === "string" ? sessionHistory.providerSessionId.trim() : "";
31301
31317
  return {
31302
31318
  ...sessionHistory,
31303
- lookup: args.historySessionId || canBindFromLiveSession && boundProviderSessionId ? "session" : "workspace"
31319
+ lookup: effectiveHistorySessionId || canBindFromLiveSession && boundProviderSessionId ? "session" : "workspace"
31304
31320
  };
31305
31321
  }
31306
31322
  function readLiveCodexWorkspaceNativeHistory(agentStr, args) {
@@ -31553,7 +31569,8 @@ async function handleChatHistory(h, args) {
31553
31569
  historyBehavior: provider?.historyBehavior,
31554
31570
  scripts: provider?.scripts,
31555
31571
  sessionStartedAtMs: sessionStartedAtMsFromRegistry(h, args?.targetSessionId),
31556
- envOverrides: sessionSpawnEnvFromAdapter(h, args?.targetSessionId)
31572
+ envOverrides: sessionSpawnEnvFromAdapter(h, args?.targetSessionId),
31573
+ pinnedProviderSessionId: getBoundProviderSessionIdPin(args?.targetSessionId)
31557
31574
  }) : readProviderChatHistory(agentStr, {
31558
31575
  canonicalHistory: provider?.nativeHistory,
31559
31576
  historySessionId,
@@ -31568,6 +31585,9 @@ async function handleChatHistory(h, args) {
31568
31585
  const lookup = result.lookup === "workspace" ? "workspace" : "session";
31569
31586
  const messages = Array.isArray(result.messages) ? normalizeAndFilterNativeHistory(h, agentStr, args, result.messages, result?.providerSessionId) : [];
31570
31587
  const historyProviderSessionId = typeof result?.providerSessionId === "string" ? result.providerSessionId : readHistorySessionIdFromMessages(messages) || historySessionId;
31588
+ if (typeof result?.providerSessionId === "string" && result.providerSessionId.trim()) {
31589
+ recordBoundProviderSessionId(args?.targetSessionId, result.providerSessionId.trim());
31590
+ }
31571
31591
  const safeMapping = hasSafeNativeHistoryMapping({
31572
31592
  historySessionId: lookup === "workspace" ? void 0 : historySessionId,
31573
31593
  providerSessionId: lookup === "workspace" ? void 0 : historyProviderSessionId,
@@ -31702,8 +31722,17 @@ async function handleReadChat(h, args) {
31702
31722
  scripts: provider?.scripts,
31703
31723
  excludeInProgressTurn: returnedStatus === "waiting_approval",
31704
31724
  sessionStartedAtMs: sessionStartedAtMsFromRegistry(h, args?.targetSessionId),
31705
- envOverrides: sessionSpawnEnvFromAdapter(h, args?.targetSessionId)
31725
+ envOverrides: sessionSpawnEnvFromAdapter(h, args?.targetSessionId),
31726
+ pinnedProviderSessionId: getBoundProviderSessionIdPin(targetSessionId),
31727
+ // Last-resort only when no pin was ever recorded for this
31728
+ // session; the downstream workspace-overlap safety gate
31729
+ // still filters an aliased session out.
31730
+ allowWorkspaceLatestFallback: !getBoundProviderSessionIdPin(targetSessionId)
31706
31731
  });
31732
+ const resolvedProviderSessionId = typeof nativeHistory?.providerSessionId === "string" ? nativeHistory.providerSessionId.trim() : "";
31733
+ if (resolvedProviderSessionId) {
31734
+ recordBoundProviderSessionId(targetSessionId, resolvedProviderSessionId);
31735
+ }
31707
31736
  } catch (error) {
31708
31737
  nativeHistoryError = error;
31709
31738
  nativeHistory = null;
@@ -31949,9 +31978,14 @@ async function handleReadChat(h, args) {
31949
31978
  const workspace = targetSid ? typeof registrySessionWorkspace === "string" ? registrySessionWorkspace : argsWorkspace ?? currentSessionWorkspace : typeof currentSessionWorkspace === "string" ? currentSessionWorkspace : void 0;
31950
31979
  const intendedWorkspace = argsWorkspace;
31951
31980
  const supportsNative = supportsCliNativeTranscript(agentStr, provider) && isNativeSourceCanonicalHistory(provider?.nativeHistory);
31981
+ const pinnedProviderSessionIdForHistory = getBoundProviderSessionIdPin(targetSid);
31982
+ const historySessionIdIsRuntimeFallback = Boolean(
31983
+ targetSid && historySessionId === targetSid && !getExplicitHistorySessionId(args)
31984
+ );
31985
+ const effectiveHistorySessionIdForRead = historySessionIdIsRuntimeFallback ? pinnedProviderSessionIdForHistory || void 0 : historySessionId;
31952
31986
  const history = supportsNative ? readCliProviderNativeHistory(agentStr, {
31953
31987
  canonicalHistory: provider?.nativeHistory,
31954
- historySessionId,
31988
+ historySessionId: effectiveHistorySessionIdForRead,
31955
31989
  workspace,
31956
31990
  offset: 0,
31957
31991
  limit: historyLimit,
@@ -31959,7 +31993,11 @@ async function handleReadChat(h, args) {
31959
31993
  historyBehavior: provider?.historyBehavior,
31960
31994
  scripts: provider?.scripts,
31961
31995
  sessionStartedAtMs: sessionStartedAtMsFromRegistry(h, args?.targetSessionId),
31962
- envOverrides: sessionSpawnEnvFromAdapter(h, args?.targetSessionId)
31996
+ envOverrides: sessionSpawnEnvFromAdapter(h, args?.targetSessionId),
31997
+ pinnedProviderSessionId: pinnedProviderSessionIdForHistory,
31998
+ // Last-resort only when no pin was ever recorded AND the
31999
+ // runtime fallback did not resolve a real provider session.
32000
+ allowWorkspaceLatestFallback: !pinnedProviderSessionIdForHistory && historySessionIdIsRuntimeFallback
31963
32001
  }) : readProviderChatHistory(agentStr, {
31964
32002
  canonicalHistory: provider?.nativeHistory,
31965
32003
  historySessionId,
@@ -31972,14 +32010,18 @@ async function handleReadChat(h, args) {
31972
32010
  });
31973
32011
  const lookup = history?.lookup === "workspace" ? "workspace" : "session";
31974
32012
  const historyMessages = Array.isArray(history?.messages) ? normalizeAndFilterNativeHistory(h, agentStr, args, history.messages, history?.providerSessionId) : [];
31975
- const historyProviderSessionId = typeof history?.providerSessionId === "string" ? history.providerSessionId : readHistorySessionIdFromMessages(historyMessages) || historySessionId;
32013
+ const historyProviderSessionId = typeof history?.providerSessionId === "string" ? history.providerSessionId : readHistorySessionIdFromMessages(historyMessages) || effectiveHistorySessionIdForRead;
32014
+ if (typeof history?.providerSessionId === "string" && history.providerSessionId.trim()) {
32015
+ recordBoundProviderSessionId(targetSid, history.providerSessionId.trim());
32016
+ }
32017
+ const mappingSessionId = effectiveHistorySessionIdForRead;
31976
32018
  const safeMapping = supportsNative ? hasSafeNativeHistoryMapping({
31977
- historySessionId: lookup === "workspace" ? void 0 : historySessionId,
32019
+ historySessionId: lookup === "workspace" ? void 0 : mappingSessionId,
31978
32020
  providerSessionId: lookup === "workspace" ? void 0 : historyProviderSessionId,
31979
32021
  workspace,
31980
32022
  nativeMessages: historyMessages
31981
32023
  }) : false;
31982
- const trustedExactNativeIdentity = lookup !== "workspace" && Boolean(historySessionId) && Boolean(historyProviderSessionId) && historySessionId === historyProviderSessionId;
32024
+ const trustedExactNativeIdentity = lookup !== "workspace" && Boolean(mappingSessionId) && Boolean(historyProviderSessionId) && mappingSessionId === historyProviderSessionId;
31983
32025
  const machineSessionKey = String(
31984
32026
  args?.targetSessionId || historyProviderSessionId || historySessionId || h.currentSession?.sessionId || ""
31985
32027
  );
@@ -38689,10 +38731,17 @@ function executeSqlite(src, input) {
38689
38731
  }
38690
38732
  try {
38691
38733
  const requested = input.providerSessionId || "";
38692
- let sessionId;
38693
- if (requested) {
38694
- sessionId = requested;
38695
- } else {
38734
+ const resolveMessagesFor = (sessionId2) => {
38735
+ if (!sessionId2) return null;
38736
+ let rows;
38737
+ try {
38738
+ rows = db.prepare(src.message_query).all(sessionId2);
38739
+ } catch {
38740
+ return null;
38741
+ }
38742
+ return rows && rows.length > 0 ? rows : null;
38743
+ };
38744
+ const resolveNewestSessionId = () => {
38696
38745
  let sessionRow;
38697
38746
  try {
38698
38747
  const sessionFloorSeconds = typeof input.sessionStartedAtMs === "number" ? Math.floor(input.sessionStartedAtMs / 1e3) : 0;
@@ -38703,14 +38752,27 @@ function executeSqlite(src, input) {
38703
38752
  sessionRow = stmt.get();
38704
38753
  }
38705
38754
  } catch {
38706
- return null;
38755
+ return "";
38707
38756
  }
38708
- if (!sessionRow) return null;
38757
+ if (!sessionRow) return "";
38709
38758
  const sessionIdRaw = Object.values(sessionRow)[0];
38710
- sessionId = sessionIdRaw == null ? "" : String(sessionIdRaw);
38759
+ return sessionIdRaw == null ? "" : String(sessionIdRaw);
38760
+ };
38761
+ let sessionId;
38762
+ let messageRows;
38763
+ if (requested) {
38764
+ messageRows = resolveMessagesFor(requested);
38765
+ if (messageRows) {
38766
+ sessionId = requested;
38767
+ } else {
38768
+ sessionId = resolveNewestSessionId();
38769
+ messageRows = resolveMessagesFor(sessionId);
38770
+ }
38771
+ } else {
38772
+ sessionId = resolveNewestSessionId();
38773
+ messageRows = resolveMessagesFor(sessionId);
38711
38774
  }
38712
38775
  if (!sessionId) return null;
38713
- const messageRows = db.prepare(src.message_query).all(sessionId);
38714
38776
  if (!messageRows || messageRows.length === 0) return null;
38715
38777
  const mtime = safeMtimeMs(resolved);
38716
38778
  const messages = [];