@adhdev/daemon-standalone 0.9.82-rc.111 → 0.9.82-rc.113

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
@@ -30927,11 +30927,17 @@ ${lastSnapshot}`;
30927
30927
  }
30928
30928
  function getSessionSeenAt(state, sessionId, providerSessionId) {
30929
30929
  const providerKey = buildSessionReadStateKey(sessionId, providerSessionId);
30930
- return state.sessionReads?.[providerKey] || state.sessionReads?.[sessionId] || 0;
30930
+ return Math.max(state.sessionReads?.[providerKey] || 0, state.sessionReads?.[sessionId] || 0);
30931
30931
  }
30932
30932
  function getSessionSeenMarker(state, sessionId, providerSessionId) {
30933
30933
  const providerKey = buildSessionReadStateKey(sessionId, providerSessionId);
30934
- return state.sessionReadMarkers?.[providerKey] || state.sessionReadMarkers?.[sessionId] || "";
30934
+ const providerSeenAt = state.sessionReads?.[providerKey] || 0;
30935
+ const sessionSeenAt = state.sessionReads?.[sessionId] || 0;
30936
+ const providerMarker = state.sessionReadMarkers?.[providerKey] || "";
30937
+ const sessionMarker = state.sessionReadMarkers?.[sessionId] || "";
30938
+ if (sessionSeenAt > providerSeenAt && sessionMarker) return sessionMarker;
30939
+ if (providerSeenAt > sessionSeenAt && providerMarker) return providerMarker;
30940
+ return providerMarker || sessionMarker;
30935
30941
  }
30936
30942
  function getSessionNotificationDismissal(state, sessionId, providerSessionId) {
30937
30943
  const providerKey = buildSessionReadStateKey(sessionId, providerSessionId);
@@ -39225,7 +39231,20 @@ ${effect.notification.body || ""}`.trim();
39225
39231
  if (visibleCount > excludeRecentCount) excludeRecentCount = visibleCount;
39226
39232
  }
39227
39233
  const workspace = typeof args?.workspace === "string" ? args.workspace : typeof h.currentSession?.workspace === "string" ? h.currentSession.workspace : void 0;
39228
- const result = readProviderChatHistory(agentStr, {
39234
+ const exactNativeHistoryScope = Boolean(
39235
+ typeof args?.targetSessionId === "string" && args.targetSessionId.trim() || typeof args?.historySessionId === "string" && args.historySessionId.trim() || typeof args?.providerSessionId === "string" && args.providerSessionId.trim()
39236
+ );
39237
+ const result = supportsCliNativeTranscript(agentStr, provider) && isNativeSourceCanonicalHistory(provider?.canonicalHistory) ? readCliProviderNativeHistory(agentStr, {
39238
+ canonicalHistory: provider?.canonicalHistory,
39239
+ historySessionId,
39240
+ workspace,
39241
+ offset: offset || 0,
39242
+ limit: limit || 30,
39243
+ excludeRecentCount,
39244
+ historyBehavior: provider?.historyBehavior,
39245
+ scripts: provider?.scripts,
39246
+ exactSessionScoped: exactNativeHistoryScope
39247
+ }) : readProviderChatHistory(agentStr, {
39229
39248
  canonicalHistory: provider?.canonicalHistory,
39230
39249
  historySessionId,
39231
39250
  workspace,
@@ -39235,6 +39254,26 @@ ${effect.notification.body || ""}`.trim();
39235
39254
  historyBehavior: provider?.historyBehavior,
39236
39255
  scripts: provider?.scripts
39237
39256
  });
39257
+ if (supportsCliNativeTranscript(agentStr, provider) && isNativeSourceCanonicalHistory(provider?.canonicalHistory)) {
39258
+ const lookup = result.lookup === "workspace" ? "workspace" : "session";
39259
+ const messages = Array.isArray(result.messages) ? normalizeNativeHistoryMessages(agentStr, result.messages) : [];
39260
+ const historyProviderSessionId = typeof result?.providerSessionId === "string" ? result.providerSessionId : readHistorySessionIdFromMessages(messages) || historySessionId;
39261
+ const safeMapping = hasSafeNativeHistoryMapping({
39262
+ historySessionId: lookup === "workspace" ? void 0 : historySessionId,
39263
+ providerSessionId: lookup === "workspace" ? void 0 : historyProviderSessionId,
39264
+ workspace,
39265
+ nativeMessages: messages
39266
+ });
39267
+ if (result.source === "provider-native" && messages.length > 0 && !safeMapping) {
39268
+ return {
39269
+ success: true,
39270
+ messages: [],
39271
+ hasMore: false,
39272
+ source: "native-unavailable",
39273
+ agent: agentStr
39274
+ };
39275
+ }
39276
+ }
39238
39277
  return { success: true, ...result, agent: agentStr };
39239
39278
  } catch (e) {
39240
39279
  return { success: false, error: e.message };
@@ -41844,6 +41883,16 @@ ${effect.notification.body || ""}`.trim();
41844
41883
  }
41845
41884
  return normalizedId;
41846
41885
  }
41886
+ function isIdleStatus(value) {
41887
+ const status = typeof value === "string" ? value.trim().toLowerCase() : "";
41888
+ return !status || status === "idle" || status === "ready";
41889
+ }
41890
+ function getMessageTime(message) {
41891
+ if (!message || typeof message !== "object") return 0;
41892
+ const record2 = message;
41893
+ const value = Number(record2.receivedAt ?? record2.timestamp ?? 0);
41894
+ return Number.isFinite(value) ? value : 0;
41895
+ }
41847
41896
  var COMPLETED_FINALIZATION_RETRY_MS = 1e3;
41848
41897
  var COMPLETED_FINALIZATION_MAX_WAIT_MS = 3e4;
41849
41898
  var IMAGE_MIME_EXTENSIONS = {
@@ -42105,7 +42154,7 @@ ${effect.notification.body || ""}`.trim();
42105
42154
  await this.adapter.spawn();
42106
42155
  await this.enforceFreshSessionLaunchIfNeeded();
42107
42156
  this.maybeAppendRuntimeRecoveryMessage(this.adapter.getRuntimeMetadata());
42108
- if (this.providerSessionId) {
42157
+ if (this.providerSessionId && this.shouldHydrateExistingProviderHistory()) {
42109
42158
  this.restorePersistedHistoryFromCurrentSession();
42110
42159
  }
42111
42160
  if (this.providerSessionId && this.launchMode === "resume") {
@@ -42187,28 +42236,37 @@ ${effect.notification.body || ""}`.trim();
42187
42236
  this.provider,
42188
42237
  typeof adapterStatus?.providerSessionId === "string" ? adapterStatus.providerSessionId : ""
42189
42238
  );
42190
- if (adapterProviderSessionId) {
42191
- this.promoteProviderSessionId(adapterProviderSessionId);
42192
- }
42193
42239
  const autoApproveActive = this.maybeAutoApproveStatus(adapterStatus, Date.now());
42194
42240
  const visibleStatus = parseErrorMessage || parsedStatus?.status === "error" ? "error" : autoApproveActive ? "generating" : adapterStatus.status;
42241
+ const runtime = this.adapter.getRuntimeMetadata();
42242
+ this.maybeAppendRuntimeRecoveryMessage(runtime);
42243
+ let parsedMessages = Array.isArray(parsedStatus?.messages) ? parsedStatus.messages : [];
42195
42244
  const parsedProviderSessionId = normalizeProviderSessionId(
42196
42245
  this.provider,
42197
42246
  typeof parsedStatus?.providerSessionId === "string" ? parsedStatus.providerSessionId : ""
42198
42247
  );
42199
- if (parsedProviderSessionId) {
42248
+ const suppressFreshLaunchStartupReplay = this.shouldSuppressFreshLaunchStartupReplay(
42249
+ parsedMessages,
42250
+ parsedStatus,
42251
+ adapterStatus,
42252
+ parsedProviderSessionId
42253
+ );
42254
+ if (adapterProviderSessionId && !suppressFreshLaunchStartupReplay) {
42255
+ this.promoteProviderSessionId(adapterProviderSessionId);
42256
+ }
42257
+ if (parsedProviderSessionId && !suppressFreshLaunchStartupReplay) {
42200
42258
  this.promoteProviderSessionId(parsedProviderSessionId);
42201
42259
  }
42202
- const runtime = this.adapter.getRuntimeMetadata();
42203
- this.maybeAppendRuntimeRecoveryMessage(runtime);
42260
+ if (suppressFreshLaunchStartupReplay) {
42261
+ parsedMessages = [];
42262
+ }
42204
42263
  const activeChatId = this.providerSessionId || runtime?.runtimeId || this.instanceId;
42205
- let parsedMessages = Array.isArray(parsedStatus?.messages) ? parsedStatus.messages : [];
42206
42264
  const historyMessageCount = Number.isFinite(parsedStatus?.historyMessageCount) ? Math.max(0, Number(parsedStatus.historyMessageCount)) : null;
42207
42265
  if (historyMessageCount !== null) {
42208
42266
  parsedMessages = historyMessageCount > 0 ? parsedMessages.slice(-historyMessageCount) : [];
42209
42267
  }
42210
42268
  const mergedMessages = this.mergeConversationMessages(parsedMessages);
42211
- const canonicalBackedHistory = this.syncCanonicalSavedHistoryIfNeeded();
42269
+ const canonicalBackedHistory = this.shouldHydrateExistingProviderHistory() ? this.syncCanonicalSavedHistoryIfNeeded() : false;
42212
42270
  const statusMessages = canonicalBackedHistory && this.lastPersistedHistoryMessages.length > 0 ? this.lastPersistedHistoryMessages.map((message) => ({
42213
42271
  role: message.role,
42214
42272
  content: message.content,
@@ -42251,7 +42309,10 @@ ${effect.notification.body || ""}`.trim();
42251
42309
  this.lastPersistedHistoryMessages = normalizedMessagesToSave;
42252
42310
  }
42253
42311
  }
42254
- this.applyProviderResponse(parsedStatus, { phase: "immediate" });
42312
+ this.applyProviderResponse(
42313
+ suppressFreshLaunchStartupReplay && parsedStatus && typeof parsedStatus === "object" ? { ...parsedStatus, providerSessionId: void 0 } : parsedStatus,
42314
+ { phase: "immediate" }
42315
+ );
42255
42316
  const surface = resolveProviderStateSurface({
42256
42317
  summaryMetadata: this.summaryMetadata,
42257
42318
  controlValues: this.controlValues
@@ -43003,7 +43064,9 @@ ${effect.notification.body || ""}`.trim();
43003
43064
  this.providerSessionId = nextSessionId;
43004
43065
  this.historyWriter.promoteHistorySession(this.type, previousHistorySessionId, nextSessionId);
43005
43066
  this.historyWriter.writeSessionStart(this.type, nextSessionId, this.workingDir, this.instanceId);
43006
- this.restorePersistedHistoryFromCurrentSession();
43067
+ if (this.shouldHydrateExistingProviderHistory()) {
43068
+ this.restorePersistedHistoryFromCurrentSession();
43069
+ }
43007
43070
  this.adapter.updateRuntimeMeta({ providerSessionId: nextSessionId });
43008
43071
  this.onProviderSessionResolved?.({
43009
43072
  instanceId: this.instanceId,
@@ -43015,6 +43078,18 @@ ${effect.notification.body || ""}`.trim();
43015
43078
  });
43016
43079
  LOG2.info("CLI", `[${this.type}] discovered provider session id: ${nextSessionId}`);
43017
43080
  }
43081
+ shouldHydrateExistingProviderHistory() {
43082
+ return this.launchMode === "resume" || this.launchMode === "manual";
43083
+ }
43084
+ shouldSuppressFreshLaunchStartupReplay(parsedMessages, parsedStatus, adapterStatus, parsedProviderSessionId = "") {
43085
+ if (this.launchMode !== "new") return false;
43086
+ if (this.providerSessionId) return false;
43087
+ if (!Array.isArray(parsedMessages) || parsedMessages.length === 0) return false;
43088
+ if (!isIdleStatus(adapterStatus?.status) || !isIdleStatus(parsedStatus?.status)) return false;
43089
+ if (parsedProviderSessionId) return true;
43090
+ const newestMessageAt = parsedMessages.reduce((newest, message) => Math.max(newest, getMessageTime(message)), 0);
43091
+ return newestMessageAt === 0;
43092
+ }
43018
43093
  syncCanonicalSavedHistoryIfNeeded() {
43019
43094
  if (!this.providerSessionId) return false;
43020
43095
  const canonicalHistory = this.provider.canonicalHistory;
@@ -53554,7 +53629,8 @@ ${block2}`);
53554
53629
  update: null
53555
53630
  };
53556
53631
  }
53557
- const fullMessages = normalizeChatMessages(Array.isArray(result.messages) ? result.messages : []);
53632
+ const rawMessages = Array.isArray(result.messages) ? result.messages : Array.isArray(result.messagesTail) ? result.messagesTail : [];
53633
+ const fullMessages = normalizeChatMessages(rawMessages);
53558
53634
  const messages = fullMessages;
53559
53635
  const title = typeof result.title === "string" ? result.title : void 0;
53560
53636
  const activeModal = normalizeChatTailActiveModal(result.activeModal);