@adhdev/daemon-core 0.9.82-rc.479 → 0.9.82-rc.480

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 ? "6d7bacdddb31d77f5aa1c900d667702ab9acb472" : void 0) ?? "unknown";
408
- const commitShort = readInjected(true ? "6d7bacdd" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
409
- const version = readInjected(true ? "0.9.82-rc.479" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
410
- const builtAt = readInjected(true ? "2026-07-06T19:58:17.279Z" : void 0);
407
+ const commit = readInjected(true ? "27de51660cbce2ce37049081744c09a168420b2f" : void 0) ?? "unknown";
408
+ const commitShort = readInjected(true ? "27de5166" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
409
+ const version = readInjected(true ? "0.9.82-rc.480" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
410
+ const builtAt = readInjected(true ? "2026-07-07T16:21:33.035Z" : void 0);
411
411
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
412
412
  return cached;
413
413
  }
@@ -24258,6 +24258,41 @@ var init_cli_state_engine = __esm({
24258
24258
  this.recordTrace("idle_candidate_reset", { reason, candidate: this.idleFinishCandidate });
24259
24259
  this.idleFinishCandidate = null;
24260
24260
  }
24261
+ /**
24262
+ * Poll-driven static-idle confirm (D4). A hosted CLI session (e.g. a fresh
24263
+ * antigravity coordinator) whose boot banner drove the FSM into 'generating'
24264
+ * can then sit at a STATIC ready prompt emitting no further PTY output. Every
24265
+ * output-driven busy→idle re-eval (handleOutput/resolveStartupState/settle)
24266
+ * is starved because there is no new output, and the startup-settle loop has
24267
+ * hard-stopped past spawnAt+10s — so currentStatus stays frozen at generating
24268
+ * and the dashboard disables Send. This is the ONE path that can release that
24269
+ * wedge from the read-only status poll.
24270
+ *
24271
+ * Safety: this must NEVER flip a real generating turn to idle. The gate is
24272
+ * done by the caller (getStatus) reusing resolveStartupState's proven
24273
+ * predicates: no recent PTY output for a grace window, runDetectStatus of the
24274
+ * current screen === 'idle', and no active/parsed modal. Here we add the
24275
+ * final structural guard: there must be NO active turn scope. A live user
24276
+ * turn always carries a currentTurnScope (set in onTurnStarted), so this only
24277
+ * releases the boot-banner wedge and the post-turn static-idle case, both of
24278
+ * which have already had their scope nulled. Returns true when it transitioned.
24279
+ */
24280
+ confirmPollStaticIdle(reason) {
24281
+ if (this.currentStatus !== "generating") return false;
24282
+ if (this.currentTurnScope || this.activeModal) return false;
24283
+ this.clearAllTimers();
24284
+ this.clearIdleFinishCandidate(reason);
24285
+ this.isWaitingForResponse = false;
24286
+ this.responseSettleIgnoreUntil = 0;
24287
+ this.submitRetryUsed = false;
24288
+ this.submitRetryPromptSnippet = "";
24289
+ this.finishRetryCount = 0;
24290
+ this.currentTurnScope = null;
24291
+ this.activeModal = null;
24292
+ this.setStatus("idle", reason);
24293
+ this.recordTrace("poll_static_idle_confirmed", { reason });
24294
+ return true;
24295
+ }
24261
24296
  hasActionableApproval(startupModal) {
24262
24297
  return !!(startupModal ?? this.activeModal);
24263
24298
  }
@@ -25697,6 +25732,18 @@ ${lastSnapshot}`;
25697
25732
  const allowParse = options.allowParse !== false;
25698
25733
  const startupModal = allowParse && this.startupParseGate ? this.runParseApproval(this.recentOutputBuffer) : null;
25699
25734
  const startupDetectedStatus = allowParse && this.startupParseGate && !startupModal ? this.runDetectStatus(this.recentOutputBuffer || this.terminalScreen.getText()) : null;
25735
+ if (allowParse && this.engine.currentStatus === "generating" && !this.engine.currentTurnScope && !this.engine.activeModal) {
25736
+ const now = Date.now();
25737
+ const quietForMs = this.lastNonEmptyOutputAt ? now - this.lastNonEmptyOutputAt : Number.MAX_SAFE_INTEGER;
25738
+ if (quietForMs >= this.getStatusActivityHoldMs()) {
25739
+ const screenText = this.terminalScreen.getText();
25740
+ const pollDetect = this.runDetectStatus(screenText || this.recentOutputBuffer);
25741
+ const pollModal = this.runParseApproval(screenText) || this.runParseApproval(this.recentOutputBuffer);
25742
+ if (pollDetect === "idle" && !pollModal) {
25743
+ this.engine.confirmPollStaticIdle("poll_static_idle");
25744
+ }
25745
+ }
25746
+ }
25700
25747
  let effectiveStatus = this.projectEffectiveStatus(startupModal);
25701
25748
  let effectiveModal = startupModal || this.engine.activeModal;
25702
25749
  if (allowParse && !effectiveModal && this.engine.isWaitingForResponse) {
@@ -28844,8 +28891,11 @@ function classifyHotChatSessionsForSubscriptionFlush(sessions, previousHotSessio
28844
28891
  );
28845
28892
  const activeStatuses = options.activeStatuses ?? DEFAULT_ACTIVE_CHAT_POLL_STATUSES;
28846
28893
  const activeSessionIds = options.activeSessionIds ?? /* @__PURE__ */ new Set();
28894
+ const deliveredCompletionTailAt = options.deliveredCompletionTailAt ?? null;
28895
+ const underDeliveredSessionIds = options.underDeliveredSessionIds ?? null;
28847
28896
  const active = /* @__PURE__ */ new Set();
28848
28897
  const excluded = /* @__PURE__ */ new Set();
28898
+ const guaranteedDelivery = /* @__PURE__ */ new Set();
28849
28899
  for (const session of sessions) {
28850
28900
  const sessionId = typeof session?.id === "string" ? session.id : "";
28851
28901
  if (!sessionId) continue;
@@ -28868,12 +28918,47 @@ function classifyHotChatSessionsForSubscriptionFlush(sessions, previousHotSessio
28868
28918
  const shouldKeepRecentTailHot = recentlyUpdated && (unread || inboxBucket === "task_complete" || inboxBucket === "needs_attention" || isLiveRuntime || activeStatuses.has(status));
28869
28919
  if (activeStatuses.has(status) || shouldKeepRecentTailHot) {
28870
28920
  active.add(sessionId);
28921
+ continue;
28922
+ }
28923
+ if (underDeliveredSessionIds && underDeliveredSessionIds.has(sessionId)) {
28924
+ active.add(sessionId);
28925
+ guaranteedDelivery.add(sessionId);
28926
+ continue;
28927
+ }
28928
+ const completedUnseen = unread || inboxBucket === "task_complete";
28929
+ if (!underDeliveredSessionIds && deliveredCompletionTailAt && completedUnseen) {
28930
+ const delivered = deliveredCompletionTailAt.get(sessionId) ?? 0;
28931
+ const alreadyDelivered = delivered > 0 && lastMessageAt > 0 && delivered >= lastMessageAt;
28932
+ if (!alreadyDelivered) {
28933
+ active.add(sessionId);
28934
+ guaranteedDelivery.add(sessionId);
28935
+ }
28871
28936
  }
28872
28937
  }
28873
28938
  const finalizing = new Set(
28874
28939
  Array.from(previousHotSessionIds).filter((sessionId) => !active.has(sessionId) && !excluded.has(sessionId))
28875
28940
  );
28876
- return { active, finalizing };
28941
+ return { active, finalizing, guaranteedDelivery };
28942
+ }
28943
+ function detectNewlySettledCompletedSessions(sessions, previousStatus, options = {}) {
28944
+ const activeStatuses = options.activeStatuses ?? DEFAULT_ACTIVE_CHAT_POLL_STATUSES;
28945
+ const settled = /* @__PURE__ */ new Set();
28946
+ const nextStatus = /* @__PURE__ */ new Map();
28947
+ for (const session of sessions) {
28948
+ const sessionId = typeof session?.id === "string" ? session.id : "";
28949
+ if (!sessionId) continue;
28950
+ const status = String(session?.status || "").toLowerCase();
28951
+ const prevStatus = previousStatus.get(sessionId);
28952
+ nextStatus.set(sessionId, status);
28953
+ const wasActive = prevStatus !== void 0 && activeStatuses.has(prevStatus);
28954
+ const isSettledNow = !activeStatuses.has(status);
28955
+ const inboxBucket = String(session?.inboxBucket || "").toLowerCase();
28956
+ const completedUnseen = session?.unread === true || inboxBucket === "task_complete";
28957
+ if (wasActive && isSettledNow && completedUnseen) {
28958
+ settled.add(sessionId);
28959
+ }
28960
+ }
28961
+ return { settled, nextStatus };
28877
28962
  }
28878
28963
 
28879
28964
  // src/cdp/manager.ts
@@ -31690,7 +31775,8 @@ function callProviderNativeHistoryRead(agentType, canonicalHistory, scripts, his
31690
31775
  workspace: typeof result.workspace === "string" ? result.workspace.trim() : void 0,
31691
31776
  nativeHistoryCoverage: typeof result.nativeHistoryCoverage === "string" ? result.nativeHistoryCoverage.trim() : void 0,
31692
31777
  partialReason: typeof result.partialReason === "string" ? result.partialReason.trim() : void 0,
31693
- unavailableReason: typeof result.unavailableReason === "string" ? result.unavailableReason.trim() : void 0
31778
+ unavailableReason: typeof result.unavailableReason === "string" ? result.unavailableReason.trim() : void 0,
31779
+ ownerConfirmed: typeof result.ownerConfirmed === "boolean" ? result.ownerConfirmed : void 0
31694
31780
  };
31695
31781
  }
31696
31782
  function buildNativeHistoryReadResult(agentType, canonicalHistory, scripts, historySessionId, workspace, excludeInProgressTurn, sessionStartedAtMs, envOverrides, forceRefresh, instanceId) {
@@ -31737,7 +31823,8 @@ function readProviderChatHistory(agentType, options = {}) {
31737
31823
  workspace: nativeResult.workspace,
31738
31824
  nativeHistoryCoverage: nativeResult.nativeHistoryCoverage,
31739
31825
  partialReason: nativeResult.partialReason,
31740
- unavailableReason: nativeResult.unavailableReason
31826
+ unavailableReason: nativeResult.unavailableReason,
31827
+ ownerConfirmed: nativeResult.ownerConfirmed
31741
31828
  };
31742
31829
  }
31743
31830
  return {
@@ -34102,6 +34189,12 @@ function getExplicitHistorySessionId(args) {
34102
34189
  if (explicitProviderSessionId) return explicitProviderSessionId;
34103
34190
  return void 0;
34104
34191
  }
34192
+ function isRuntimeFallbackHistorySessionId(candidateHistorySessionId, targetSessionId) {
34193
+ const target = typeof targetSessionId === "string" ? targetSessionId.trim() : "";
34194
+ if (!target) return false;
34195
+ const candidate = typeof candidateHistorySessionId === "string" ? candidateHistorySessionId.trim() : "";
34196
+ return candidate === target;
34197
+ }
34105
34198
  function getHistorySessionId(h, args) {
34106
34199
  const explicit = getExplicitHistorySessionId(args);
34107
34200
  if (explicit) return explicit;
@@ -34936,12 +35029,19 @@ async function handleChatHistory(h, args) {
34936
35029
  if (visibleCount > excludeRecentCount) excludeRecentCount = visibleCount;
34937
35030
  }
34938
35031
  const workspace = typeof args?.workspace === "string" ? args.workspace : typeof h.currentSession?.workspace === "string" ? h.currentSession.workspace : void 0;
35032
+ const targetSidForHistory = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
35033
+ const explicitHistorySessionIdForHistory = getExplicitHistorySessionId(args);
35034
+ const historySessionIdIsRuntimeFallback = Boolean(
35035
+ targetSidForHistory && isRuntimeFallbackHistorySessionId(historySessionId, targetSidForHistory) && (!explicitHistorySessionIdForHistory || isRuntimeFallbackHistorySessionId(explicitHistorySessionIdForHistory, targetSidForHistory))
35036
+ );
35037
+ const pinnedProviderSessionIdForHistory = getBoundProviderSessionIdPin(args?.targetSessionId);
35038
+ const effectiveHistorySessionId = historySessionIdIsRuntimeFallback ? pinnedProviderSessionIdForHistory || void 0 : historySessionId;
34939
35039
  const exactNativeHistoryScope = Boolean(
34940
- typeof args?.targetSessionId === "string" && args.targetSessionId.trim() || typeof args?.historySessionId === "string" && args.historySessionId.trim() || typeof args?.providerSessionId === "string" && args.providerSessionId.trim()
35040
+ typeof args?.targetSessionId === "string" && args.targetSessionId.trim() || typeof args?.historySessionId === "string" && args.historySessionId.trim() && !historySessionIdIsRuntimeFallback || typeof args?.providerSessionId === "string" && args.providerSessionId.trim()
34941
35041
  );
34942
35042
  const result = supportsCliNativeTranscript(agentStr, provider) && isNativeSourceCanonicalHistory(provider?.nativeHistory) ? readCliProviderNativeHistory(agentStr, {
34943
35043
  canonicalHistory: provider?.nativeHistory,
34944
- historySessionId,
35044
+ historySessionId: effectiveHistorySessionId,
34945
35045
  workspace,
34946
35046
  offset: offset || 0,
34947
35047
  limit: limit || 30,
@@ -34951,7 +35051,8 @@ async function handleChatHistory(h, args) {
34951
35051
  sessionStartedAtMs: sessionStartedAtMsFromRegistry(h, args?.targetSessionId),
34952
35052
  envOverrides: sessionSpawnEnvFromAdapter(h, args?.targetSessionId),
34953
35053
  instanceId: effectiveReadSessionId(h, args?.targetSessionId) || void 0,
34954
- pinnedProviderSessionId: getBoundProviderSessionIdPin(args?.targetSessionId)
35054
+ pinnedProviderSessionId: pinnedProviderSessionIdForHistory,
35055
+ allowWorkspaceLatestFallback: !pinnedProviderSessionIdForHistory && historySessionIdIsRuntimeFallback
34955
35056
  }) : readProviderChatHistory(agentStr, {
34956
35057
  canonicalHistory: provider?.nativeHistory,
34957
35058
  historySessionId,
@@ -34965,13 +35066,17 @@ async function handleChatHistory(h, args) {
34965
35066
  if (supportsCliNativeTranscript(agentStr, provider) && isNativeSourceCanonicalHistory(provider?.nativeHistory)) {
34966
35067
  const lookup = result.lookup === "workspace" ? "workspace" : "session";
34967
35068
  const messages = Array.isArray(result.messages) ? normalizeAndFilterNativeHistory(h, agentStr, args, result.messages, result?.providerSessionId) : [];
34968
- const historyProviderSessionId = typeof result?.providerSessionId === "string" ? result.providerSessionId : readHistorySessionIdFromMessages(messages) || historySessionId;
34969
- if (typeof result?.providerSessionId === "string" && result.providerSessionId.trim()) {
34970
- recordBoundProviderSessionId(h, effectiveReadSessionId(h, args?.targetSessionId), result.providerSessionId.trim());
35069
+ const historyProviderSessionId = typeof result?.providerSessionId === "string" ? result.providerSessionId : readHistorySessionIdFromMessages(messages) || effectiveHistorySessionId;
35070
+ const resolvedProviderSessionId = typeof result?.providerSessionId === "string" ? result.providerSessionId.trim() : "";
35071
+ const resultLookupIsWorkspace = lookup === "workspace";
35072
+ const resultOwnerConfirmed = result?.ownerConfirmed === true;
35073
+ const ownerConfirmedUuid = resultOwnerConfirmed && typeof historyProviderSessionId === "string" && historyProviderSessionId.trim() ? historyProviderSessionId.trim() : "";
35074
+ if (resolvedProviderSessionId && (!resultLookupIsWorkspace || resultOwnerConfirmed)) {
35075
+ recordBoundProviderSessionId(h, effectiveReadSessionId(h, args?.targetSessionId), resolvedProviderSessionId);
34971
35076
  }
34972
35077
  const safeMapping = hasSafeNativeHistoryMapping({
34973
- historySessionId: lookup === "workspace" ? void 0 : historySessionId,
34974
- providerSessionId: lookup === "workspace" ? void 0 : historyProviderSessionId,
35078
+ historySessionId: ownerConfirmedUuid || (lookup === "workspace" ? void 0 : effectiveHistorySessionId),
35079
+ providerSessionId: ownerConfirmedUuid || (lookup === "workspace" ? void 0 : historyProviderSessionId),
34975
35080
  workspace,
34976
35081
  nativeMessages: messages
34977
35082
  });
@@ -35092,8 +35197,9 @@ async function handleReadChat(h, args) {
35092
35197
  let nativeHistoryError;
35093
35198
  if (supportsNative) {
35094
35199
  const pinnedProviderSessionIdForRead = getBoundProviderSessionIdPin(targetSessionId);
35200
+ const explicitHistorySessionIdForRead = getExplicitHistorySessionId(args);
35095
35201
  const nativeReadSessionIdIsRuntimeFallback = Boolean(
35096
- targetSessionId && nativeHistoryReadSessionId === targetSessionId && !getExplicitHistorySessionId(args)
35202
+ targetSessionId && isRuntimeFallbackHistorySessionId(nativeHistoryReadSessionId, targetSessionId) && (!explicitHistorySessionIdForRead || isRuntimeFallbackHistorySessionId(explicitHistorySessionIdForRead, targetSessionId))
35097
35203
  );
35098
35204
  const effectiveNativeReadSessionId = nativeReadSessionIdIsRuntimeFallback ? pinnedProviderSessionIdForRead || void 0 : nativeHistoryReadSessionId;
35099
35205
  try {
@@ -35119,7 +35225,10 @@ async function handleReadChat(h, args) {
35119
35225
  allowWorkspaceLatestFallback: !pinnedProviderSessionIdForRead
35120
35226
  });
35121
35227
  const resolvedProviderSessionId = typeof nativeHistory?.providerSessionId === "string" ? nativeHistory.providerSessionId.trim() : "";
35122
- if (resolvedProviderSessionId) {
35228
+ const resolvedLookupIsWorkspace = nativeHistory?.lookup === "workspace";
35229
+ const nativeOwnerConfirmed = nativeHistory?.ownerConfirmed === true;
35230
+ const mayPinResolvedProviderSessionId = resolvedProviderSessionId && (!resolvedLookupIsWorkspace || nativeOwnerConfirmed);
35231
+ if (mayPinResolvedProviderSessionId) {
35123
35232
  recordBoundProviderSessionId(h, effectiveReadSessionId(h, targetSessionId), resolvedProviderSessionId);
35124
35233
  }
35125
35234
  } catch (error) {
@@ -35131,14 +35240,15 @@ async function handleReadChat(h, args) {
35131
35240
  const sessionStartedAtMs = sessionStartedAtMsFromRegistry(h, args?.targetSessionId);
35132
35241
  let historyProviderSessionId = typeof nativeHistory?.providerSessionId === "string" ? nativeHistory.providerSessionId : readHistorySessionIdFromMessages(nativeMessages) || nativeHistoryReadSessionId || historySessionId;
35133
35242
  let lookup = nativeHistory?.lookup === "workspace" ? "workspace" : "session";
35134
- let nativeHistorySessionForMapping = adapter.cliType === "antigravity-cli" && historyProviderSessionId && nativeHistoryReadSessionId && historyProviderSessionId !== nativeHistoryReadSessionId ? void 0 : nativeHistoryReadSessionId;
35243
+ const ownerConfirmedUuid = adapter.cliType === "antigravity-cli" && nativeHistory?.ownerConfirmed === true && typeof historyProviderSessionId === "string" && historyProviderSessionId.trim() ? historyProviderSessionId.trim() : "";
35244
+ let nativeHistorySessionForMapping = ownerConfirmedUuid ? ownerConfirmedUuid : adapter.cliType === "antigravity-cli" && historyProviderSessionId && nativeHistoryReadSessionId && historyProviderSessionId !== nativeHistoryReadSessionId ? void 0 : nativeHistoryReadSessionId;
35135
35245
  let safeMapping = supportsNative && nativeHistory ? hasSafeNativeHistoryMapping({
35136
- historySessionId: lookup === "workspace" ? void 0 : nativeHistorySessionForMapping,
35137
- providerSessionId: lookup === "workspace" ? void 0 : historyProviderSessionId || providerSessionId,
35246
+ historySessionId: ownerConfirmedUuid || (lookup === "workspace" ? void 0 : nativeHistorySessionForMapping),
35247
+ providerSessionId: ownerConfirmedUuid || (lookup === "workspace" ? void 0 : historyProviderSessionId || providerSessionId),
35138
35248
  workspace,
35139
35249
  nativeMessages,
35140
35250
  ptyMessages: returnedMessages,
35141
- requireWorkspaceContentOverlap: lookup === "workspace" && !exactNativeHistoryScope
35251
+ requireWorkspaceContentOverlap: lookup === "workspace" && !exactNativeHistoryScope && !ownerConfirmedUuid
35142
35252
  }) : false;
35143
35253
  if (skipLiveNativeHistoryWithoutProviderSession && (!safeMapping || returnedMessages.length === 0)) {
35144
35254
  nativeHistory = null;
@@ -35369,8 +35479,9 @@ async function handleReadChat(h, args) {
35369
35479
  const intendedWorkspace = argsWorkspace;
35370
35480
  const supportsNative = supportsCliNativeTranscript(agentStr, provider) && isNativeSourceCanonicalHistory(provider?.nativeHistory);
35371
35481
  const pinnedProviderSessionIdForHistory = getBoundProviderSessionIdPin(targetSid);
35482
+ const explicitHistorySessionId = getExplicitHistorySessionId(args);
35372
35483
  const historySessionIdIsRuntimeFallback = Boolean(
35373
- targetSid && historySessionId === targetSid && !getExplicitHistorySessionId(args)
35484
+ targetSid && isRuntimeFallbackHistorySessionId(historySessionId, targetSid) && (!explicitHistorySessionId || isRuntimeFallbackHistorySessionId(explicitHistorySessionId, targetSid))
35374
35485
  );
35375
35486
  const effectiveHistorySessionIdForRead = historySessionIdIsRuntimeFallback ? pinnedProviderSessionIdForHistory || void 0 : historySessionId;
35376
35487
  const history = supportsNative ? readCliProviderNativeHistory(agentStr, {
@@ -35402,17 +35513,21 @@ async function handleReadChat(h, args) {
35402
35513
  const lookup = history?.lookup === "workspace" ? "workspace" : "session";
35403
35514
  const historyMessages = Array.isArray(history?.messages) ? normalizeAndFilterNativeHistory(h, agentStr, args, history.messages, history?.providerSessionId) : [];
35404
35515
  const historyProviderSessionId = typeof history?.providerSessionId === "string" ? history.providerSessionId : readHistorySessionIdFromMessages(historyMessages) || effectiveHistorySessionIdForRead;
35405
- if (typeof history?.providerSessionId === "string" && history.providerSessionId.trim()) {
35516
+ const historyLookupIsWorkspace = lookup === "workspace";
35517
+ const historyOwnerConfirmed = agentStr === "antigravity-cli" && history?.ownerConfirmed === true;
35518
+ const historyOwnerConfirmedUuid = historyOwnerConfirmed && typeof historyProviderSessionId === "string" && historyProviderSessionId.trim() ? historyProviderSessionId.trim() : "";
35519
+ if (typeof history?.providerSessionId === "string" && history.providerSessionId.trim() && (!historyLookupIsWorkspace || !agentStr || agentStr !== "antigravity-cli" || historyOwnerConfirmed)) {
35406
35520
  recordBoundProviderSessionId(h, effectiveReadSessionId(h, targetSid), history.providerSessionId.trim());
35407
35521
  }
35408
- const mappingSessionId = effectiveHistorySessionIdForRead;
35409
- const safeMapping = supportsNative ? hasSafeNativeHistoryMapping({
35410
- historySessionId: lookup === "workspace" ? void 0 : mappingSessionId,
35411
- providerSessionId: lookup === "workspace" ? void 0 : historyProviderSessionId,
35522
+ const mappingSessionId = historyOwnerConfirmedUuid || effectiveHistorySessionIdForRead;
35523
+ const antigravityWorkspaceLatestUnconfirmed = agentStr === "antigravity-cli" && historyLookupIsWorkspace && !historyOwnerConfirmedUuid;
35524
+ const safeMapping = supportsNative && !antigravityWorkspaceLatestUnconfirmed ? hasSafeNativeHistoryMapping({
35525
+ historySessionId: historyOwnerConfirmedUuid || (lookup === "workspace" ? void 0 : mappingSessionId),
35526
+ providerSessionId: historyOwnerConfirmedUuid || (lookup === "workspace" ? void 0 : historyProviderSessionId),
35412
35527
  workspace,
35413
35528
  nativeMessages: historyMessages
35414
35529
  }) : false;
35415
- const trustedExactNativeIdentity = lookup !== "workspace" && Boolean(mappingSessionId) && Boolean(historyProviderSessionId) && mappingSessionId === historyProviderSessionId;
35530
+ const trustedExactNativeIdentity = (lookup !== "workspace" || Boolean(historyOwnerConfirmedUuid)) && Boolean(mappingSessionId) && Boolean(historyProviderSessionId) && mappingSessionId === historyProviderSessionId;
35416
35531
  const machineSessionKey = String(
35417
35532
  args?.targetSessionId || historyProviderSessionId || historySessionId || h.currentSession?.sessionId || ""
35418
35533
  );
@@ -38993,7 +39108,13 @@ function toHostedCliRuntimeDescriptor(record) {
38993
39108
  cliType,
38994
39109
  workspace,
38995
39110
  cliArgs: Array.isArray(record.meta?.cliArgs) ? record.meta.cliArgs : [],
38996
- providerSessionId: typeof record.meta?.providerSessionId === "string" ? String(record.meta.providerSessionId) : void 0
39111
+ providerSessionId: typeof record.meta?.providerSessionId === "string" ? String(record.meta.providerSessionId) : void 0,
39112
+ // Real spawn time (PAST timestamp) of the underlying runtime — startedAt is
39113
+ // stamped on markStarted; fall back to createdAt (record creation). Threaded
39114
+ // through so an attach restores the native-history session-floor to the
39115
+ // runtime's actual birth instead of collapsing spawnedAtMs to 0 (which broke
39116
+ // the antigravity per-session birth-floor for co-located MAGI runtimes).
39117
+ startedAtMs: typeof record.startedAt === "number" && record.startedAt > 0 ? record.startedAt : typeof record.createdAt === "number" && record.createdAt > 0 ? record.createdAt : void 0
38997
39118
  };
38998
39119
  }
38999
39120
  function getWriteConflictOwnerClientId(error) {
@@ -48183,6 +48304,11 @@ var DEFAULT_COORDINATOR_DELEGATED_ENV_UNSETS = [
48183
48304
  function hasCliArg(args, flag) {
48184
48305
  return args.some((arg) => arg === flag || arg.startsWith(`${flag}=`));
48185
48306
  }
48307
+ function resolveHostedSpawnedAtMs(attachExisting, attachStartedAtMs, nowMs) {
48308
+ if (!attachExisting) return nowMs;
48309
+ if (typeof attachStartedAtMs === "number" && attachStartedAtMs > 0) return attachStartedAtMs;
48310
+ return 0;
48311
+ }
48186
48312
  function hasConfigOverride(args, key2) {
48187
48313
  for (let index = 0; index < args.length; index += 1) {
48188
48314
  const arg = args[index];
@@ -48511,15 +48637,30 @@ var DaemonCliManager = class {
48511
48637
  workspace: resolvedDir,
48512
48638
  // attachExisting === true means we're restoring an already-spawned
48513
48639
  // hosted runtime after a daemon restart, not starting a fresh PTY.
48514
- // The real spawn time is in the past and we don't have it on the
48515
- // restored descriptor; pinning spawnedAtMs to Date.now() in that
48516
- // case would push the native-history session-floor cutoff past
48517
- // every existing transcript file, so the agy/hermes/claude reader
48518
- // would return null even though the transcript on disk is fresh.
48519
- // 0 disables the floor for this session — recent_window_ms in the
48520
- // spec still bounds how far back we look. Fresh launches still
48521
- // get a proper floor so prior-session leak protection holds.
48522
- spawnedAtMs: attachExisting ? 0 : Date.now()
48640
+ //
48641
+ // NEVER use Date.now() for the attach case: the real spawn time is in
48642
+ // the PAST, and pinning the floor to now would push the native-history
48643
+ // session-floor cutoff past every existing transcript file, so the
48644
+ // agy/hermes/claude reader would return null even though the transcript
48645
+ // on disk is fresh (the ANTIGRAVITY-FINAL-MESSAGE-TAIL-GAP regression).
48646
+ //
48647
+ // But collapsing to 0 for EVERY attach is also wrong: with the mesh
48648
+ // coordinator + MAGI replicas all running as hosted runtimes sharing one
48649
+ // workspace and attached with attachExisting=true, spawnedAtMs=0 disables
48650
+ // the per-session native-history birth-floor for all of them. Without a
48651
+ // floor, resolveAntigravityPath takes the floor-less newest-by-mtime
48652
+ // branch (ownerConfirmed:false) and a replica's read can claim the
48653
+ // coordinator's OWN conversation, which then reads as claimedByOther —
48654
+ // regressing the coordinator chat to the pty-parser (user-only) path.
48655
+ //
48656
+ // So when the session-host record's REAL startedAt (a PAST timestamp) is
48657
+ // recoverable, use it: the floor lands at the runtime's actual birth, the
48658
+ // transcript is still found, AND each session's floor isolates its own
48659
+ // conversation. Fall back to 0 ONLY when startedAt is unrecoverable (the
48660
+ // genuine post-restart-unknown case) — that preserves the tail-gap
48661
+ // protection. Fresh launches still get Date.now() so prior-session leak
48662
+ // protection holds.
48663
+ spawnedAtMs: resolveHostedSpawnedAtMs(attachExisting, options?.attachStartedAtMs, Date.now())
48523
48664
  });
48524
48665
  } catch (spawnErr) {
48525
48666
  LOG.error("CLI", `[${cliType}] Spawn failed: ${spawnErr?.message}`);
@@ -48882,7 +49023,13 @@ Run 'adhdev doctor' for detailed diagnostics.`
48882
49023
  true,
48883
49024
  {
48884
49025
  providerSessionId: sessionBinding.providerSessionId,
48885
- launchMode: "manual"
49026
+ launchMode: "manual",
49027
+ // Thread the runtime's REAL past spawn time so the attach restores
49028
+ // the per-session native-history birth-floor instead of collapsing
49029
+ // to spawnedAtMs:0 (which disabled the antigravity per-session floor
49030
+ // and let MAGI replicas claim the coordinator's own conversation).
49031
+ // Undefined → registerCliInstance keeps the 0 fallback.
49032
+ attachStartedAtMs: record.startedAtMs
48886
49033
  }
48887
49034
  );
48888
49035
  restoredBindings.add(bindingKey);
@@ -51013,8 +51160,10 @@ function createNativeHistoryDispatcher(reader) {
51013
51160
  const requestedProviderSid = input.providerSessionId || "";
51014
51161
  const sessionStartedAtMs = typeof input.sessionStartedAtMs === "number" ? input.sessionStartedAtMs : typeof input.args?.sessionStartedAtMs === "number" ? input.args.sessionStartedAtMs : 0;
51015
51162
  const instanceId = typeof input.instanceId === "string" ? input.instanceId : typeof input.args?.instanceId === "string" ? input.args.instanceId : "";
51016
- const sourcePath = resolveSourcePath(reader, workspace, sessionId, sessionStartedAtMs, instanceId);
51163
+ const resolved = resolveSourcePath(reader, workspace, sessionId, sessionStartedAtMs, instanceId);
51164
+ const sourcePath = resolved?.path || null;
51017
51165
  if (!sourcePath) return null;
51166
+ const ownerConfirmed = reader === "antigravity-cli" ? resolved?.ownerConfirmed === true : void 0;
51018
51167
  if (input.forceRefresh === true || input.args?.forceRefresh === true) {
51019
51168
  try {
51020
51169
  fs26.statSync(sourcePath);
@@ -51044,20 +51193,27 @@ function createNativeHistoryDispatcher(reader) {
51044
51193
  providerSessionId: resolvedProviderSessionId,
51045
51194
  sourcePath: session.sourcePath,
51046
51195
  sourceMtimeMs: session.sourceMtimeMs,
51047
- nativeHistoryCoverage: session.nativeHistoryCoverage || "full"
51196
+ nativeHistoryCoverage: session.nativeHistoryCoverage || "full",
51197
+ ownerConfirmed
51048
51198
  };
51049
51199
  };
51050
51200
  }
51051
51201
  function resolveSourcePath(reader, workspace, sessionId, sessionStartedAtMs, instanceId) {
51052
51202
  switch (reader) {
51053
- case "claude-cli":
51054
- return resolveClaudePath(workspace, sessionId);
51055
- case "codex-cli":
51056
- return resolveCodexPath(workspace, sessionId, sessionStartedAtMs);
51203
+ case "claude-cli": {
51204
+ const p = resolveClaudePath(workspace, sessionId);
51205
+ return p ? { path: p } : null;
51206
+ }
51207
+ case "codex-cli": {
51208
+ const p = resolveCodexPath(workspace, sessionId, sessionStartedAtMs);
51209
+ return p ? { path: p } : null;
51210
+ }
51057
51211
  case "antigravity-cli":
51058
51212
  return resolveAntigravityPath(workspace, sessionId, sessionStartedAtMs, instanceId);
51059
- case "hermes-cli":
51060
- return resolveHermesPath(workspace, sessionId);
51213
+ case "hermes-cli": {
51214
+ const p = resolveHermesPath(workspace, sessionId);
51215
+ return p ? { path: p } : null;
51216
+ }
51061
51217
  }
51062
51218
  }
51063
51219
  function resolveClaudePath(workspace, sessionId) {
@@ -51189,7 +51345,7 @@ function resolveAntigravityPath(workspace, sessionId, sessionStartedAtMs, instan
51189
51345
  const dbPath = path34.join(agyRoot, "conversations", `${sessionId}.db`);
51190
51346
  if (fs26.existsSync(dbPath)) {
51191
51347
  if (owner) claimAntigravityConversation(sessionId, owner);
51192
- return dbPath;
51348
+ return { path: dbPath, ownerConfirmed: true };
51193
51349
  }
51194
51350
  }
51195
51351
  const brainRoot2 = path34.join(agyRoot, "brain");
@@ -51204,6 +51360,7 @@ function resolveAntigravityPath(workspace, sessionId, sessionStartedAtMs, instan
51204
51360
  return { uuid: e.name, p, mtime: safeMtime(p), birth: safeBirthtime(p) };
51205
51361
  }).filter((e) => e.mtime >= cutoff);
51206
51362
  let ordered = [];
51363
+ const brainOwnerConfirmed = sessionStartedAtMs > 0;
51207
51364
  if (sessionStartedAtMs > 0) {
51208
51365
  const floor = sessionStartedAtMs - AGY_SPAWN_CLAIM_GRACE_MS;
51209
51366
  ordered = all.filter((e) => (e.birth > 0 ? e.birth : e.mtime) >= floor).sort((a, b) => (a.birth || a.mtime) - (b.birth || b.mtime));
@@ -51214,7 +51371,7 @@ function resolveAntigravityPath(workspace, sessionId, sessionStartedAtMs, instan
51214
51371
  const t = nonEmptyBrain(e.uuid, e.p);
51215
51372
  if (t) {
51216
51373
  if (owner) claimAntigravityConversation(e.uuid, owner);
51217
- return t;
51374
+ return { path: t, ownerConfirmed: brainOwnerConfirmed };
51218
51375
  }
51219
51376
  }
51220
51377
  }
@@ -51222,7 +51379,7 @@ function resolveAntigravityPath(workspace, sessionId, sessionStartedAtMs, instan
51222
51379
  const picked = pickUnboundConversationDb(convRoot, sessionStartedAtMs, owner);
51223
51380
  if (picked) {
51224
51381
  if (owner) claimAntigravityConversation(picked.uuid, owner);
51225
- return picked.path;
51382
+ return { path: picked.path, ownerConfirmed: picked.ownerConfirmed };
51226
51383
  }
51227
51384
  return null;
51228
51385
  }
@@ -51253,10 +51410,10 @@ function pickUnboundConversationDb(convRoot, sessionFloorMs, owner) {
51253
51410
  const own = candidates.filter((c) => (c.birth > 0 ? c.birth : c.mtime) >= floor);
51254
51411
  if (own.length === 0) return null;
51255
51412
  own.sort((a, b) => (a.birth || a.mtime) - (b.birth || b.mtime));
51256
- return { path: own[0].path, uuid: own[0].uuid };
51413
+ return { path: own[0].path, uuid: own[0].uuid, ownerConfirmed: true };
51257
51414
  }
51258
51415
  candidates.sort((a, b) => b.mtime - a.mtime);
51259
- return { path: candidates[0].path, uuid: candidates[0].uuid };
51416
+ return { path: candidates[0].path, uuid: candidates[0].uuid, ownerConfirmed: false };
51260
51417
  }
51261
51418
  function spawnAwareCutoff(sessionStartedAtMs) {
51262
51419
  const recency = Date.now() - RECENT_WINDOW_MS;
@@ -69288,6 +69445,7 @@ export {
69288
69445
  detectCLIs,
69289
69446
  detectClaudeAskUserQuestionPromptFromJson,
69290
69447
  detectIDEs,
69448
+ detectNewlySettledCompletedSessions,
69291
69449
  drainPendingMeshCoordinatorEvents,
69292
69450
  enqueueTask,
69293
69451
  ensureSessionHostReady,