@adhdev/daemon-standalone 0.9.36 → 0.9.38

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
@@ -29560,27 +29560,86 @@ var require_dist2 = __commonJS({
29560
29560
  function hydrateCliParsedMessages(parsedMessages, options) {
29561
29561
  const { committedMessages, scope, lastOutputAt } = options;
29562
29562
  const referenceMessages = [...committedMessages];
29563
- const referenceComparables = referenceMessages.map((message) => normalizeComparableMessageContent(message?.content || ""));
29563
+ const referenceComparables = new Array(referenceMessages.length);
29564
29564
  const usedReferenceIndexes = /* @__PURE__ */ new Set();
29565
29565
  const now = options.now ?? Date.now();
29566
- const findReferenceTimestamp = (role, content, parsedIndex) => {
29566
+ let exactReferenceIndexesByKey = null;
29567
+ const exactReferenceCursorByKey = /* @__PURE__ */ new Map();
29568
+ const hasFiniteTimestamp = (message) => typeof message?.timestamp === "number" && Number.isFinite(message.timestamp);
29569
+ const getReferenceComparable = (index) => {
29570
+ if (typeof referenceComparables[index] === "string") return referenceComparables[index] || "";
29571
+ const comparable = normalizeComparableMessageContent(referenceMessages[index]?.content || "");
29572
+ referenceComparables[index] = comparable;
29573
+ return comparable;
29574
+ };
29575
+ const messagesShareStableIdentity = (parsed, reference) => {
29576
+ if (!parsed || !reference) return false;
29577
+ const parsedId = typeof parsed.id === "string" ? parsed.id.trim() : "";
29578
+ const referenceId = typeof reference.id === "string" ? reference.id.trim() : "";
29579
+ if (parsedId && referenceId && parsedId === referenceId) return true;
29580
+ return typeof parsed.index === "number" && Number.isFinite(parsed.index) && typeof reference.index === "number" && Number.isFinite(reference.index) && parsed.index === reference.index;
29581
+ };
29582
+ const exactReferenceKey = (role, comparable) => `${role}\0${comparable}`;
29583
+ const ensureExactReferenceIndex = () => {
29584
+ if (exactReferenceIndexesByKey) return exactReferenceIndexesByKey;
29585
+ const byKey = /* @__PURE__ */ new Map();
29586
+ for (let i = 0; i < referenceMessages.length; i++) {
29587
+ const candidate = referenceMessages[i];
29588
+ if (!candidate || candidate.role !== "user" && candidate.role !== "assistant" || !hasFiniteTimestamp(candidate)) continue;
29589
+ const comparable = getReferenceComparable(i);
29590
+ if (!comparable) continue;
29591
+ const key = exactReferenceKey(candidate.role, comparable);
29592
+ const indexes = byKey.get(key);
29593
+ if (indexes) {
29594
+ indexes.push(i);
29595
+ } else {
29596
+ byKey.set(key, [i]);
29597
+ }
29598
+ }
29599
+ exactReferenceIndexesByKey = byKey;
29600
+ return byKey;
29601
+ };
29602
+ const takeExactReferenceTimestamp = (role, normalizedContent) => {
29603
+ const key = exactReferenceKey(role, normalizedContent);
29604
+ const indexes = ensureExactReferenceIndex().get(key);
29605
+ if (!indexes) return void 0;
29606
+ let cursor = exactReferenceCursorByKey.get(key) || 0;
29607
+ while (cursor < indexes.length) {
29608
+ const candidateIndex = indexes[cursor];
29609
+ cursor += 1;
29610
+ if (usedReferenceIndexes.has(candidateIndex)) continue;
29611
+ const candidate = referenceMessages[candidateIndex];
29612
+ if (!candidate || candidate.role !== role || !hasFiniteTimestamp(candidate)) continue;
29613
+ usedReferenceIndexes.add(candidateIndex);
29614
+ exactReferenceCursorByKey.set(key, cursor);
29615
+ return candidate.timestamp;
29616
+ }
29617
+ exactReferenceCursorByKey.set(key, cursor);
29618
+ return void 0;
29619
+ };
29620
+ const findReferenceTimestamp = (message, role, content, parsedIndex) => {
29621
+ const sameIndex = referenceMessages[parsedIndex];
29622
+ if (sameIndex && !usedReferenceIndexes.has(parsedIndex) && sameIndex.role === role && hasFiniteTimestamp(sameIndex) && messagesShareStableIdentity(message, sameIndex)) {
29623
+ usedReferenceIndexes.add(parsedIndex);
29624
+ return sameIndex.timestamp;
29625
+ }
29567
29626
  const normalizedContent = normalizeComparableMessageContent(content);
29568
29627
  if (!normalizedContent) return void 0;
29569
- const sameIndex = referenceMessages[parsedIndex];
29570
- if (sameIndex && !usedReferenceIndexes.has(parsedIndex) && sameIndex.role === role && referenceComparables[parsedIndex] === normalizedContent && typeof sameIndex.timestamp === "number" && Number.isFinite(sameIndex.timestamp)) {
29628
+ if (sameIndex && !usedReferenceIndexes.has(parsedIndex) && sameIndex.role === role && getReferenceComparable(parsedIndex) === normalizedContent && hasFiniteTimestamp(sameIndex)) {
29571
29629
  usedReferenceIndexes.add(parsedIndex);
29572
29630
  return sameIndex.timestamp;
29573
29631
  }
29632
+ const exactTimestamp = takeExactReferenceTimestamp(role, normalizedContent);
29633
+ if (typeof exactTimestamp === "number") return exactTimestamp;
29574
29634
  for (let i = 0; i < referenceMessages.length; i++) {
29575
29635
  if (usedReferenceIndexes.has(i)) continue;
29576
29636
  const candidate = referenceMessages[i];
29577
29637
  if (!candidate || candidate.role !== role) continue;
29578
- const candidateContent = referenceComparables[i];
29638
+ const candidateContent = getReferenceComparable(i);
29579
29639
  if (!candidateContent) continue;
29580
- const exactMatch = candidateContent === normalizedContent;
29581
29640
  const fuzzyMatch = candidateContent.includes(normalizedContent) || normalizedContent.includes(candidateContent);
29582
- if (!exactMatch && !fuzzyMatch) continue;
29583
- if (typeof candidate.timestamp === "number" && Number.isFinite(candidate.timestamp)) {
29641
+ if (!fuzzyMatch) continue;
29642
+ if (hasFiniteTimestamp(candidate)) {
29584
29643
  usedReferenceIndexes.add(i);
29585
29644
  return candidate.timestamp;
29586
29645
  }
@@ -29591,7 +29650,7 @@ var require_dist2 = __commonJS({
29591
29650
  const role = message.role;
29592
29651
  const content = typeof message.content === "string" ? message.content : String(message.content || "");
29593
29652
  const parsedTimestamp = typeof message.timestamp === "number" && Number.isFinite(message.timestamp) ? message.timestamp : void 0;
29594
- const referenceTimestamp = parsedTimestamp ?? findReferenceTimestamp(role, content, index);
29653
+ const referenceTimestamp = parsedTimestamp ?? findReferenceTimestamp(message, role, content, index);
29595
29654
  const fallbackTimestamp = role === "user" ? scope?.startedAt || now : lastOutputAt || scope?.startedAt || now;
29596
29655
  const timestamp = referenceTimestamp ?? fallbackTimestamp;
29597
29656
  return {
@@ -31208,11 +31267,12 @@ var require_dist2 = __commonJS({
31208
31267
  };
31209
31268
  }
31210
31269
  // ─── Public API (CliAdapter) ───────────────────
31211
- getStatus() {
31212
- const startupModal = this.startupParseGate ? this.runParseApproval(this.recentOutputBuffer) : null;
31270
+ getStatus(options = {}) {
31271
+ const allowParse = options.allowParse !== false;
31272
+ const startupModal = allowParse && this.startupParseGate ? this.runParseApproval(this.recentOutputBuffer) : null;
31213
31273
  let effectiveStatus = this.projectEffectiveStatus(startupModal);
31214
31274
  let effectiveModal = startupModal || this.activeModal;
31215
- if (!startupModal && !effectiveModal && typeof this.cliScripts?.parseOutput === "function") {
31275
+ if (allowParse && !startupModal && !effectiveModal && typeof this.cliScripts?.parseOutput === "function") {
31216
31276
  let parsed = this.getFreshParsedStatusCache();
31217
31277
  if (!parsed && effectiveStatus !== "idle") {
31218
31278
  const now = Date.now();
@@ -40991,17 +41051,24 @@ ${effect.notification.body || ""}`.trim();
40991
41051
  normalizePersistableCliHistoryContent(message.content)
40992
41052
  ].join("|");
40993
41053
  }
41054
+ function hasSamePersistableCliHistoryIdentity(a, b2) {
41055
+ return String(a?.role || "") === String(b2?.role || "") && String(a?.kind || "") === String(b2?.kind || "") && String(a?.senderName || "") === String(b2?.senderName || "") && String(a?.content || "") === String(b2?.content || "");
41056
+ }
40994
41057
  function buildIncrementalHistoryAppendMessages(previousMessages, currentMessages) {
40995
41058
  if (!Array.isArray(currentMessages) || currentMessages.length === 0) return [];
40996
41059
  if (!Array.isArray(previousMessages) || previousMessages.length === 0) return currentMessages;
40997
- const previousSignatures = previousMessages.map(buildPersistableCliHistorySignature);
40998
- const currentSignatures = currentMessages.map(buildPersistableCliHistorySignature);
41060
+ const comparableLength = Math.min(previousMessages.length, currentMessages.length);
40999
41061
  let sharedPrefixLength = 0;
41000
- while (sharedPrefixLength < previousSignatures.length && sharedPrefixLength < currentSignatures.length && previousSignatures[sharedPrefixLength] === currentSignatures[sharedPrefixLength]) {
41062
+ while (sharedPrefixLength < comparableLength && hasSamePersistableCliHistoryIdentity(previousMessages[sharedPrefixLength], currentMessages[sharedPrefixLength])) {
41001
41063
  sharedPrefixLength += 1;
41002
41064
  }
41003
- if (sharedPrefixLength === currentSignatures.length) return [];
41004
- if (sharedPrefixLength === previousSignatures.length) return currentMessages.slice(sharedPrefixLength);
41065
+ if (sharedPrefixLength === currentMessages.length) return [];
41066
+ if (sharedPrefixLength === previousMessages.length) return currentMessages.slice(sharedPrefixLength);
41067
+ while (sharedPrefixLength < comparableLength && buildPersistableCliHistorySignature(previousMessages[sharedPrefixLength]) === buildPersistableCliHistorySignature(currentMessages[sharedPrefixLength])) {
41068
+ sharedPrefixLength += 1;
41069
+ }
41070
+ if (sharedPrefixLength === currentMessages.length) return [];
41071
+ if (sharedPrefixLength === previousMessages.length) return currentMessages.slice(sharedPrefixLength);
41005
41072
  return currentMessages;
41006
41073
  }
41007
41074
  var CachedDatabaseSync = null;
@@ -41247,13 +41314,15 @@ ${effect.notification.body || ""}`.trim();
41247
41314
  }));
41248
41315
  if (!canonicalBackedHistory && !shouldSkipReplayPersist && normalizedMessagesToSave.length > 0) {
41249
41316
  const incrementalMessages = buildIncrementalHistoryAppendMessages(this.lastPersistedHistoryMessages, normalizedMessagesToSave);
41250
- this.historyWriter.appendNewMessages(
41251
- this.type,
41252
- incrementalMessages,
41253
- parsedStatus?.title || dirName,
41254
- this.instanceId,
41255
- this.providerSessionId
41256
- );
41317
+ if (incrementalMessages.length > 0) {
41318
+ this.historyWriter.appendNewMessages(
41319
+ this.type,
41320
+ incrementalMessages,
41321
+ parsedStatus?.title || dirName,
41322
+ this.instanceId,
41323
+ this.providerSessionId
41324
+ );
41325
+ }
41257
41326
  }
41258
41327
  if (!canonicalBackedHistory) {
41259
41328
  this.lastPersistedHistoryMessages = normalizedMessagesToSave;
@@ -41312,7 +41381,7 @@ ${effect.notification.body || ""}`.trim();
41312
41381
  return this.presentationMode;
41313
41382
  }
41314
41383
  getHotChatSessionState() {
41315
- const adapterStatus = this.adapter.getStatus();
41384
+ const adapterStatus = this.adapter.getStatus({ allowParse: false });
41316
41385
  const autoApproveActive = adapterStatus.status === "waiting_approval" && this.shouldAutoApprove();
41317
41386
  const visibleStatus = autoApproveActive ? "generating" : adapterStatus.status;
41318
41387
  const runtime = this.adapter.getRuntimeMetadata();