@adhdev/daemon-core 0.9.82-rc.474 → 0.9.82-rc.476

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 ? "cfb46b13fb8f556e4cb7179c4503ac3c86923d92" : void 0) ?? "unknown";
408
- const commitShort = readInjected(true ? "cfb46b13" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
409
- const version = readInjected(true ? "0.9.82-rc.474" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
410
- const builtAt = readInjected(true ? "2026-07-06T03:34:46.223Z" : void 0);
407
+ const commit = readInjected(true ? "f3bc279bf108da3a23da4e0e33ebdc41d851930c" : void 0) ?? "unknown";
408
+ const commitShort = readInjected(true ? "f3bc279b" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
409
+ const version = readInjected(true ? "0.9.82-rc.476" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
410
+ const builtAt = readInjected(true ? "2026-07-06T08:19:57.539Z" : void 0);
411
411
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
412
412
  return cached;
413
413
  }
@@ -16698,13 +16698,17 @@ function normalizeState(raw) {
16698
16698
  const sessionNotificationUnreadOverrides = Object.fromEntries(
16699
16699
  Object.entries(isPlainObject2(parsed.sessionNotificationUnreadOverrides) ? parsed.sessionNotificationUnreadOverrides : {}).filter(([, value]) => typeof value === "string" && value.length > 0)
16700
16700
  );
16701
+ const sessionProviderSessionPins = Object.fromEntries(
16702
+ Object.entries(isPlainObject2(parsed.sessionProviderSessionPins) ? parsed.sessionProviderSessionPins : {}).filter(([key2, value]) => typeof key2 === "string" && key2.length > 0 && typeof value === "string" && value.length > 0)
16703
+ );
16701
16704
  return {
16702
16705
  recentActivity,
16703
16706
  savedProviderSessions,
16704
16707
  sessionReads,
16705
16708
  sessionReadMarkers,
16706
16709
  sessionNotificationDismissals,
16707
- sessionNotificationUnreadOverrides
16710
+ sessionNotificationUnreadOverrides,
16711
+ sessionProviderSessionPins
16708
16712
  };
16709
16713
  }
16710
16714
  function loadState() {
@@ -16727,6 +16731,20 @@ function saveState(state) {
16727
16731
  function resetState() {
16728
16732
  saveState({ ...DEFAULT_STATE });
16729
16733
  }
16734
+ function loadPersistedProviderSessionPins() {
16735
+ return { ...loadState().sessionProviderSessionPins };
16736
+ }
16737
+ function recordPersistedProviderSessionPin(sessionId, providerSessionId) {
16738
+ const key2 = typeof sessionId === "string" ? sessionId.trim() : "";
16739
+ const value = typeof providerSessionId === "string" ? providerSessionId.trim() : "";
16740
+ if (!key2 || !value) return;
16741
+ const state = loadState();
16742
+ if (state.sessionProviderSessionPins[key2] === value) return;
16743
+ saveState({
16744
+ ...state,
16745
+ sessionProviderSessionPins: { ...state.sessionProviderSessionPins, [key2]: value }
16746
+ });
16747
+ }
16730
16748
  var DEFAULT_STATE;
16731
16749
  var init_state_store = __esm({
16732
16750
  "src/config/state-store.ts"() {
@@ -16738,7 +16756,8 @@ var init_state_store = __esm({
16738
16756
  sessionReads: {},
16739
16757
  sessionReadMarkers: {},
16740
16758
  sessionNotificationDismissals: {},
16741
- sessionNotificationUnreadOverrides: {}
16759
+ sessionNotificationUnreadOverrides: {},
16760
+ sessionProviderSessionPins: {}
16742
16761
  };
16743
16762
  }
16744
16763
  });
@@ -31611,10 +31630,11 @@ function normalizeProviderNativeHistoryRecords(agentType, historySessionId, reco
31611
31630
  return sanitizeHistoryMessage(agentType, base);
31612
31631
  }).filter(Boolean);
31613
31632
  }
31614
- function callProviderNativeHistoryRead(agentType, canonicalHistory, scripts, historySessionId, workspace, excludeInProgressTurn, sessionStartedAtMs, envOverrides, forceRefresh) {
31633
+ function callProviderNativeHistoryRead(agentType, canonicalHistory, scripts, historySessionId, workspace, excludeInProgressTurn, sessionStartedAtMs, envOverrides, forceRefresh, instanceId) {
31615
31634
  const fn = getProviderNativeHistoryScript(scripts, canonicalHistory, "readSession");
31616
31635
  if (!fn) return null;
31617
31636
  const normalizedSessionId = normalizeSavedHistorySessionId(historySessionId || "");
31637
+ const normalizedInstanceId = typeof instanceId === "string" ? instanceId.trim() : "";
31618
31638
  const result = fn({
31619
31639
  agentType,
31620
31640
  sessionId: normalizedSessionId,
@@ -31629,6 +31649,12 @@ function callProviderNativeHistoryRead(agentType, canonicalHistory, scripts, his
31629
31649
  // which leaves the guard disarmed so discovery still works.
31630
31650
  providerSessionId: normalizedSessionId,
31631
31651
  historySessionId: normalizedSessionId,
31652
+ // Stable per-session owner key for the antigravity conversation-claim
31653
+ // registry (see dispatcher.resolveAntigravityPath / antigravityOwnerToken).
31654
+ // Equals the session registry's sessionId and the provider instance's
31655
+ // instanceId, so read side and instance side derive the identical claim
31656
+ // owner token and two concurrent antigravity sessions never cross-bind.
31657
+ instanceId: normalizedInstanceId || void 0,
31632
31658
  workspace,
31633
31659
  format: canonicalHistory?.format,
31634
31660
  watchPath: canonicalHistory?.watchPath,
@@ -31636,7 +31662,7 @@ function callProviderNativeHistoryRead(agentType, canonicalHistory, scripts, his
31636
31662
  sessionStartedAtMs,
31637
31663
  envOverrides,
31638
31664
  forceRefresh: forceRefresh === true,
31639
- args: { sessionId: normalizedSessionId, historySessionId: normalizedSessionId, workspace, excludeInProgressTurn: excludeInProgressTurn === true, sessionStartedAtMs, envOverrides, forceRefresh: forceRefresh === true }
31665
+ args: { sessionId: normalizedSessionId, historySessionId: normalizedSessionId, instanceId: normalizedInstanceId || void 0, workspace, excludeInProgressTurn: excludeInProgressTurn === true, sessionStartedAtMs, envOverrides, forceRefresh: forceRefresh === true }
31640
31666
  });
31641
31667
  if (!result || typeof result !== "object") return null;
31642
31668
  const records = normalizeProviderNativeHistoryRecords(agentType, normalizedSessionId, result.messages || result.records);
@@ -31652,11 +31678,11 @@ function callProviderNativeHistoryRead(agentType, canonicalHistory, scripts, his
31652
31678
  unavailableReason: typeof result.unavailableReason === "string" ? result.unavailableReason.trim() : void 0
31653
31679
  };
31654
31680
  }
31655
- function buildNativeHistoryReadResult(agentType, canonicalHistory, scripts, historySessionId, workspace, excludeInProgressTurn, sessionStartedAtMs, envOverrides, forceRefresh) {
31681
+ function buildNativeHistoryReadResult(agentType, canonicalHistory, scripts, historySessionId, workspace, excludeInProgressTurn, sessionStartedAtMs, envOverrides, forceRefresh, instanceId) {
31656
31682
  const normalizedSessionId = normalizeSavedHistorySessionId(historySessionId || "");
31657
31683
  const normalizedWorkspace = typeof workspace === "string" ? workspace.trim() : "";
31658
31684
  if (!canonicalHistory || !normalizedSessionId && !normalizedWorkspace || !isNativeSourceCanonicalHistory(canonicalHistory)) return null;
31659
- return callProviderNativeHistoryRead(agentType, canonicalHistory, scripts, normalizedSessionId, workspace, excludeInProgressTurn, sessionStartedAtMs, envOverrides, forceRefresh);
31685
+ return callProviderNativeHistoryRead(agentType, canonicalHistory, scripts, normalizedSessionId, workspace, excludeInProgressTurn, sessionStartedAtMs, envOverrides, forceRefresh, instanceId);
31660
31686
  }
31661
31687
  function materializeNativeHistoryToMirror(agentType, canonicalHistory, historySessionId, workspace, scripts) {
31662
31688
  const normalizedSessionId = normalizeSavedHistorySessionId(historySessionId);
@@ -31685,7 +31711,7 @@ function isNativeSourceCanonicalHistory(canonicalHistory) {
31685
31711
  }
31686
31712
  function readProviderChatHistory(agentType, options = {}) {
31687
31713
  if (isNativeSourceCanonicalHistory(options.canonicalHistory) && (options.historySessionId || options.workspace)) {
31688
- const nativeResult = buildNativeHistoryReadResult(agentType, options.canonicalHistory, options.scripts, options.historySessionId, options.workspace, options.excludeInProgressTurn, options.sessionStartedAtMs, options.envOverrides, options.forceRefresh);
31714
+ const nativeResult = buildNativeHistoryReadResult(agentType, options.canonicalHistory, options.scripts, options.historySessionId, options.workspace, options.excludeInProgressTurn, options.sessionStartedAtMs, options.envOverrides, options.forceRefresh, options.instanceId);
31689
31715
  if (!nativeResult) return { messages: [], hasMore: false, source: "native-unavailable" };
31690
31716
  return {
31691
31717
  ...pageHistoryRecords(agentType, nativeResult.records, options.offset || 0, options.limit || 30, options.excludeRecentCount || 0, options.historyBehavior),
@@ -33656,6 +33682,7 @@ import { randomUUID as randomUUID11 } from "crypto";
33656
33682
  // src/commands/chat-commands-read.ts
33657
33683
  init_contracts2();
33658
33684
  import * as path16 from "path";
33685
+ init_state_store();
33659
33686
  init_coordinator_registry();
33660
33687
  init_logger();
33661
33688
  init_debug_trace();
@@ -34011,15 +34038,33 @@ init_chat_message_normalization();
34011
34038
  var HOT_TAIL_MIN_LIMIT = 60;
34012
34039
  var CLI_NATIVE_TRANSCRIPT_PROVIDERS = /* @__PURE__ */ new Set(["codex-cli", "claude-cli", "hermes-cli", "antigravity-cli"]);
34013
34040
  var lastBoundProviderSessionIdByMeshSession = /* @__PURE__ */ new Map();
34041
+ var persistedProviderSessionPinsHydrated = false;
34042
+ function hydratePersistedProviderSessionPinsOnce() {
34043
+ if (persistedProviderSessionPinsHydrated) return;
34044
+ persistedProviderSessionPinsHydrated = true;
34045
+ try {
34046
+ for (const [key2, value] of Object.entries(loadPersistedProviderSessionPins())) {
34047
+ if (!lastBoundProviderSessionIdByMeshSession.has(key2)) {
34048
+ lastBoundProviderSessionIdByMeshSession.set(key2, value);
34049
+ }
34050
+ }
34051
+ } catch {
34052
+ }
34053
+ }
34014
34054
  function recordBoundProviderSessionId(meshSessionId, providerSessionId) {
34015
34055
  const key2 = typeof meshSessionId === "string" ? meshSessionId.trim() : "";
34016
34056
  const value = typeof providerSessionId === "string" ? providerSessionId.trim() : "";
34017
34057
  if (!key2 || !value) return;
34018
34058
  lastBoundProviderSessionIdByMeshSession.set(key2, value);
34059
+ try {
34060
+ recordPersistedProviderSessionPin(key2, value);
34061
+ } catch {
34062
+ }
34019
34063
  }
34020
34064
  function getBoundProviderSessionIdPin(meshSessionId) {
34021
34065
  const key2 = typeof meshSessionId === "string" ? meshSessionId.trim() : "";
34022
34066
  if (!key2) return void 0;
34067
+ hydratePersistedProviderSessionPinsOnce();
34023
34068
  const pinned = lastBoundProviderSessionIdByMeshSession.get(key2);
34024
34069
  return pinned && pinned.trim() ? pinned.trim() : void 0;
34025
34070
  }
@@ -34620,7 +34665,8 @@ function readCliProviderNativeHistory(agentStr, args) {
34620
34665
  scripts: args.scripts,
34621
34666
  excludeInProgressTurn: args.excludeInProgressTurn,
34622
34667
  sessionStartedAtMs: args.sessionStartedAtMs,
34623
- envOverrides: args.envOverrides
34668
+ envOverrides: args.envOverrides,
34669
+ instanceId: args.instanceId
34624
34670
  });
34625
34671
  const boundProviderSessionId = typeof sessionHistory?.providerSessionId === "string" ? sessionHistory.providerSessionId.trim() : "";
34626
34672
  return {
@@ -34879,6 +34925,7 @@ async function handleChatHistory(h, args) {
34879
34925
  scripts: provider?.scripts,
34880
34926
  sessionStartedAtMs: sessionStartedAtMsFromRegistry(h, args?.targetSessionId),
34881
34927
  envOverrides: sessionSpawnEnvFromAdapter(h, args?.targetSessionId),
34928
+ instanceId: typeof args?.targetSessionId === "string" ? args.targetSessionId : void 0,
34882
34929
  pinnedProviderSessionId: getBoundProviderSessionIdPin(args?.targetSessionId)
34883
34930
  }) : readProviderChatHistory(agentStr, {
34884
34931
  canonicalHistory: provider?.nativeHistory,
@@ -35019,10 +35066,15 @@ async function handleReadChat(h, args) {
35019
35066
  let nativeHistory = null;
35020
35067
  let nativeHistoryError;
35021
35068
  if (supportsNative) {
35069
+ const pinnedProviderSessionIdForRead = getBoundProviderSessionIdPin(targetSessionId);
35070
+ const nativeReadSessionIdIsRuntimeFallback = Boolean(
35071
+ targetSessionId && nativeHistoryReadSessionId === targetSessionId && !getExplicitHistorySessionId(args)
35072
+ );
35073
+ const effectiveNativeReadSessionId = nativeReadSessionIdIsRuntimeFallback ? pinnedProviderSessionIdForRead || void 0 : nativeHistoryReadSessionId;
35022
35074
  try {
35023
35075
  nativeHistory = readCliProviderNativeHistory(agentStr, {
35024
35076
  canonicalHistory: provider?.nativeHistory,
35025
- historySessionId: nativeHistoryReadSessionId,
35077
+ historySessionId: effectiveNativeReadSessionId,
35026
35078
  workspace,
35027
35079
  offset: 0,
35028
35080
  limit: nativeHistoryLimit,
@@ -35032,11 +35084,14 @@ async function handleReadChat(h, args) {
35032
35084
  excludeInProgressTurn: returnedStatus === "waiting_approval",
35033
35085
  sessionStartedAtMs: sessionStartedAtMsFromRegistry(h, args?.targetSessionId),
35034
35086
  envOverrides: sessionSpawnEnvFromAdapter(h, args?.targetSessionId),
35035
- pinnedProviderSessionId: getBoundProviderSessionIdPin(targetSessionId),
35087
+ // Stable per-session identity for antigravity's conversation-claim
35088
+ // owner token (== session registry sessionId == instance instanceId).
35089
+ instanceId: typeof args?.targetSessionId === "string" ? args.targetSessionId : void 0,
35090
+ pinnedProviderSessionId: pinnedProviderSessionIdForRead,
35036
35091
  // Last-resort only when no pin was ever recorded for this
35037
35092
  // session; the downstream workspace-overlap safety gate
35038
35093
  // still filters an aliased session out.
35039
- allowWorkspaceLatestFallback: !getBoundProviderSessionIdPin(targetSessionId)
35094
+ allowWorkspaceLatestFallback: !pinnedProviderSessionIdForRead
35040
35095
  });
35041
35096
  const resolvedProviderSessionId = typeof nativeHistory?.providerSessionId === "string" ? nativeHistory.providerSessionId.trim() : "";
35042
35097
  if (resolvedProviderSessionId) {
@@ -35081,7 +35136,8 @@ async function handleReadChat(h, args) {
35081
35136
  scripts: provider?.scripts,
35082
35137
  excludeInProgressTurn: returnedStatus === "waiting_approval",
35083
35138
  sessionStartedAtMs,
35084
- envOverrides: sessionSpawnEnvFromAdapter(h, args?.targetSessionId)
35139
+ envOverrides: sessionSpawnEnvFromAdapter(h, args?.targetSessionId),
35140
+ instanceId: typeof args?.targetSessionId === "string" ? args.targetSessionId : void 0
35085
35141
  });
35086
35142
  nativeHistoryError = void 0;
35087
35143
  nativeMessages = nativeHistory && Array.isArray(nativeHistory.messages) ? normalizeAndFilterNativeHistory(h, agentStr, args, nativeHistory.messages, nativeHistory.providerSessionId) : [];
@@ -35303,6 +35359,7 @@ async function handleReadChat(h, args) {
35303
35359
  scripts: provider?.scripts,
35304
35360
  sessionStartedAtMs: sessionStartedAtMsFromRegistry(h, args?.targetSessionId),
35305
35361
  envOverrides: sessionSpawnEnvFromAdapter(h, args?.targetSessionId),
35362
+ instanceId: typeof args?.targetSessionId === "string" ? args.targetSessionId : void 0,
35306
35363
  pinnedProviderSessionId: pinnedProviderSessionIdForHistory,
35307
35364
  // Last-resort only when no pin was ever recorded AND the
35308
35365
  // runtime fallback did not resolve a real provider session.
@@ -44973,12 +45030,24 @@ var CliProviderInstance = class _CliProviderInstance {
44973
45030
  }
44974
45031
  /**
44975
45032
  * Owner token for this session in the antigravity conversation-claim
44976
- * registry. Derived identically to the dispatcher's read-side token
44977
- * (workspace + spawn time) so the claims the dispatcher records under this
44978
- * session are the ones dispose() releases.
45033
+ * registry. Keyed on the daemon instance id — the SAME value the session
45034
+ * registry stores as this session's `sessionId` (see cli-manager
45035
+ * `sessionRegistry.register({ sessionId: cliInstance.instanceId })`) and the
45036
+ * read side hands the dispatcher as `instanceId`. Both sides therefore
45037
+ * derive the identical `iid:<instanceId>` token, so the claims the
45038
+ * dispatcher records under this session are exactly the ones dispose()
45039
+ * releases.
45040
+ *
45041
+ * This must NOT be derived from a spawn timestamp: the instance's
45042
+ * `startedAt`, the adapter's `spawnedAtMs`, and the session registry's
45043
+ * `spawnedAtMs` are three INDEPENDENT `Date.now()` samples for the one
45044
+ * session, so a workspace+spawn-time token computed here would never equal
45045
+ * the read side's — the claim isolation then silently collapses and two
45046
+ * concurrent antigravity sessions cross-bind each other's conversation .db
45047
+ * (coordinator+worker chat crosswire).
44979
45048
  */
44980
45049
  antigravityClaimOwner() {
44981
- return antigravityOwnerToken(this.workingDir, this.startedAt);
45050
+ return antigravityOwnerToken(this.workingDir, this.startedAt, this.instanceId);
44982
45051
  }
44983
45052
  dispose() {
44984
45053
  if (this.type === "antigravity-cli") {
@@ -50856,6 +50925,13 @@ function createNativeHistoryDispatcher(reader) {
50856
50925
  if (requestedProviderSid && session.providerSessionId && session.providerSessionId !== requestedProviderSid) {
50857
50926
  return null;
50858
50927
  }
50928
+ let resolvedProviderSessionId = session.providerSessionId;
50929
+ if (reader === "antigravity-cli") {
50930
+ const onDiskUuid = extractAntigravityConversationUuid(session.sourcePath || sourcePath);
50931
+ if (onDiskUuid && (!resolvedProviderSessionId || resolvedProviderSessionId === sessionId)) {
50932
+ resolvedProviderSessionId = onDiskUuid;
50933
+ }
50934
+ }
50859
50935
  return {
50860
50936
  messages: session.messages.map((m) => ({
50861
50937
  role: normalizeRole2(m.role),
@@ -50864,7 +50940,7 @@ function createNativeHistoryDispatcher(reader) {
50864
50940
  kind: typeof m.kind === "string" ? m.kind : "standard",
50865
50941
  workspace: typeof m.workspace === "string" ? m.workspace : workspace || void 0
50866
50942
  })),
50867
- providerSessionId: session.providerSessionId,
50943
+ providerSessionId: resolvedProviderSessionId,
50868
50944
  sourcePath: session.sourcePath,
50869
50945
  sourceMtimeMs: session.sourceMtimeMs,
50870
50946
  nativeHistoryCoverage: session.nativeHistoryCoverage || "full"
@@ -50993,6 +51069,17 @@ function resolveRealPath(value) {
50993
51069
  return value;
50994
51070
  }
50995
51071
  }
51072
+ function extractAntigravityConversationUuid(sourcePath) {
51073
+ if (!sourcePath) return "";
51074
+ const segments = sourcePath.split(/[\\/]/);
51075
+ const base = segments[segments.length - 1] || "";
51076
+ const baseMatch = /^([0-9a-f-]+)\.(?:db|pb)$/i.exec(base);
51077
+ if (baseMatch && isUuidLikeSessionId2(baseMatch[1])) return baseMatch[1];
51078
+ for (const seg of segments) {
51079
+ if (isUuidLikeSessionId2(seg)) return seg;
51080
+ }
51081
+ return "";
51082
+ }
50996
51083
  var AGY_SPAWN_CLAIM_GRACE_MS = 2e3;
50997
51084
  function resolveAntigravityPath(workspace, sessionId, sessionStartedAtMs, instanceId) {
50998
51085
  const agyRoot = path34.join(os25.homedir(), ".gemini", "antigravity-cli");
@@ -51031,6 +51118,7 @@ function pickUnboundConversationDb(convRoot, sessionFloorMs, owner) {
51031
51118
  } catch {
51032
51119
  return null;
51033
51120
  }
51121
+ const applyRecencyCutoff = !(sessionFloorMs > 0);
51034
51122
  const recencyCutoff = Date.now() - RECENT_WINDOW_MS;
51035
51123
  const candidates = [];
51036
51124
  for (const entry of entries) {
@@ -51041,7 +51129,7 @@ function pickUnboundConversationDb(convRoot, sessionFloorMs, owner) {
51041
51129
  if (isAntigravityConversationClaimedByOther(uuid, owner)) continue;
51042
51130
  const p = path34.join(convRoot, entry.name);
51043
51131
  const mtime = safeMtime(p);
51044
- if (mtime < recencyCutoff) continue;
51132
+ if (applyRecencyCutoff && mtime < recencyCutoff) continue;
51045
51133
  candidates.push({ path: p, uuid, mtime, birth: safeBirthtime(p) });
51046
51134
  }
51047
51135
  if (candidates.length === 0) return null;