@adhdev/daemon-core 0.9.36 → 0.9.37

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
@@ -1688,27 +1688,86 @@ function sliceFromOffset(text, start) {
1688
1688
  function hydrateCliParsedMessages(parsedMessages, options) {
1689
1689
  const { committedMessages, scope, lastOutputAt } = options;
1690
1690
  const referenceMessages = [...committedMessages];
1691
- const referenceComparables = referenceMessages.map((message) => normalizeComparableMessageContent(message?.content || ""));
1691
+ const referenceComparables = new Array(referenceMessages.length);
1692
1692
  const usedReferenceIndexes = /* @__PURE__ */ new Set();
1693
1693
  const now = options.now ?? Date.now();
1694
- const findReferenceTimestamp = (role, content, parsedIndex) => {
1694
+ let exactReferenceIndexesByKey = null;
1695
+ const exactReferenceCursorByKey = /* @__PURE__ */ new Map();
1696
+ const hasFiniteTimestamp = (message) => typeof message?.timestamp === "number" && Number.isFinite(message.timestamp);
1697
+ const getReferenceComparable = (index) => {
1698
+ if (typeof referenceComparables[index] === "string") return referenceComparables[index] || "";
1699
+ const comparable = normalizeComparableMessageContent(referenceMessages[index]?.content || "");
1700
+ referenceComparables[index] = comparable;
1701
+ return comparable;
1702
+ };
1703
+ const messagesShareStableIdentity = (parsed, reference) => {
1704
+ if (!parsed || !reference) return false;
1705
+ const parsedId = typeof parsed.id === "string" ? parsed.id.trim() : "";
1706
+ const referenceId = typeof reference.id === "string" ? reference.id.trim() : "";
1707
+ if (parsedId && referenceId && parsedId === referenceId) return true;
1708
+ return typeof parsed.index === "number" && Number.isFinite(parsed.index) && typeof reference.index === "number" && Number.isFinite(reference.index) && parsed.index === reference.index;
1709
+ };
1710
+ const exactReferenceKey = (role, comparable) => `${role}\0${comparable}`;
1711
+ const ensureExactReferenceIndex = () => {
1712
+ if (exactReferenceIndexesByKey) return exactReferenceIndexesByKey;
1713
+ const byKey = /* @__PURE__ */ new Map();
1714
+ for (let i = 0; i < referenceMessages.length; i++) {
1715
+ const candidate = referenceMessages[i];
1716
+ if (!candidate || candidate.role !== "user" && candidate.role !== "assistant" || !hasFiniteTimestamp(candidate)) continue;
1717
+ const comparable = getReferenceComparable(i);
1718
+ if (!comparable) continue;
1719
+ const key = exactReferenceKey(candidate.role, comparable);
1720
+ const indexes = byKey.get(key);
1721
+ if (indexes) {
1722
+ indexes.push(i);
1723
+ } else {
1724
+ byKey.set(key, [i]);
1725
+ }
1726
+ }
1727
+ exactReferenceIndexesByKey = byKey;
1728
+ return byKey;
1729
+ };
1730
+ const takeExactReferenceTimestamp = (role, normalizedContent) => {
1731
+ const key = exactReferenceKey(role, normalizedContent);
1732
+ const indexes = ensureExactReferenceIndex().get(key);
1733
+ if (!indexes) return void 0;
1734
+ let cursor = exactReferenceCursorByKey.get(key) || 0;
1735
+ while (cursor < indexes.length) {
1736
+ const candidateIndex = indexes[cursor];
1737
+ cursor += 1;
1738
+ if (usedReferenceIndexes.has(candidateIndex)) continue;
1739
+ const candidate = referenceMessages[candidateIndex];
1740
+ if (!candidate || candidate.role !== role || !hasFiniteTimestamp(candidate)) continue;
1741
+ usedReferenceIndexes.add(candidateIndex);
1742
+ exactReferenceCursorByKey.set(key, cursor);
1743
+ return candidate.timestamp;
1744
+ }
1745
+ exactReferenceCursorByKey.set(key, cursor);
1746
+ return void 0;
1747
+ };
1748
+ const findReferenceTimestamp = (message, role, content, parsedIndex) => {
1749
+ const sameIndex = referenceMessages[parsedIndex];
1750
+ if (sameIndex && !usedReferenceIndexes.has(parsedIndex) && sameIndex.role === role && hasFiniteTimestamp(sameIndex) && messagesShareStableIdentity(message, sameIndex)) {
1751
+ usedReferenceIndexes.add(parsedIndex);
1752
+ return sameIndex.timestamp;
1753
+ }
1695
1754
  const normalizedContent = normalizeComparableMessageContent(content);
1696
1755
  if (!normalizedContent) return void 0;
1697
- const sameIndex = referenceMessages[parsedIndex];
1698
- if (sameIndex && !usedReferenceIndexes.has(parsedIndex) && sameIndex.role === role && referenceComparables[parsedIndex] === normalizedContent && typeof sameIndex.timestamp === "number" && Number.isFinite(sameIndex.timestamp)) {
1756
+ if (sameIndex && !usedReferenceIndexes.has(parsedIndex) && sameIndex.role === role && getReferenceComparable(parsedIndex) === normalizedContent && hasFiniteTimestamp(sameIndex)) {
1699
1757
  usedReferenceIndexes.add(parsedIndex);
1700
1758
  return sameIndex.timestamp;
1701
1759
  }
1760
+ const exactTimestamp = takeExactReferenceTimestamp(role, normalizedContent);
1761
+ if (typeof exactTimestamp === "number") return exactTimestamp;
1702
1762
  for (let i = 0; i < referenceMessages.length; i++) {
1703
1763
  if (usedReferenceIndexes.has(i)) continue;
1704
1764
  const candidate = referenceMessages[i];
1705
1765
  if (!candidate || candidate.role !== role) continue;
1706
- const candidateContent = referenceComparables[i];
1766
+ const candidateContent = getReferenceComparable(i);
1707
1767
  if (!candidateContent) continue;
1708
- const exactMatch = candidateContent === normalizedContent;
1709
1768
  const fuzzyMatch = candidateContent.includes(normalizedContent) || normalizedContent.includes(candidateContent);
1710
- if (!exactMatch && !fuzzyMatch) continue;
1711
- if (typeof candidate.timestamp === "number" && Number.isFinite(candidate.timestamp)) {
1769
+ if (!fuzzyMatch) continue;
1770
+ if (hasFiniteTimestamp(candidate)) {
1712
1771
  usedReferenceIndexes.add(i);
1713
1772
  return candidate.timestamp;
1714
1773
  }
@@ -1719,7 +1778,7 @@ function hydrateCliParsedMessages(parsedMessages, options) {
1719
1778
  const role = message.role;
1720
1779
  const content = typeof message.content === "string" ? message.content : String(message.content || "");
1721
1780
  const parsedTimestamp = typeof message.timestamp === "number" && Number.isFinite(message.timestamp) ? message.timestamp : void 0;
1722
- const referenceTimestamp = parsedTimestamp ?? findReferenceTimestamp(role, content, index);
1781
+ const referenceTimestamp = parsedTimestamp ?? findReferenceTimestamp(message, role, content, index);
1723
1782
  const fallbackTimestamp = role === "user" ? scope?.startedAt || now : lastOutputAt || scope?.startedAt || now;
1724
1783
  const timestamp = referenceTimestamp ?? fallbackTimestamp;
1725
1784
  return {
@@ -3338,11 +3397,12 @@ var init_provider_cli_adapter = __esm({
3338
3397
  };
3339
3398
  }
3340
3399
  // ─── Public API (CliAdapter) ───────────────────
3341
- getStatus() {
3342
- const startupModal = this.startupParseGate ? this.runParseApproval(this.recentOutputBuffer) : null;
3400
+ getStatus(options = {}) {
3401
+ const allowParse = options.allowParse !== false;
3402
+ const startupModal = allowParse && this.startupParseGate ? this.runParseApproval(this.recentOutputBuffer) : null;
3343
3403
  let effectiveStatus = this.projectEffectiveStatus(startupModal);
3344
3404
  let effectiveModal = startupModal || this.activeModal;
3345
- if (!startupModal && !effectiveModal && typeof this.cliScripts?.parseOutput === "function") {
3405
+ if (allowParse && !startupModal && !effectiveModal && typeof this.cliScripts?.parseOutput === "function") {
3346
3406
  let parsed = this.getFreshParsedStatusCache();
3347
3407
  if (!parsed && effectiveStatus !== "idle") {
3348
3408
  const now = Date.now();
@@ -13398,7 +13458,7 @@ var CliProviderInstance = class {
13398
13458
  return this.presentationMode;
13399
13459
  }
13400
13460
  getHotChatSessionState() {
13401
- const adapterStatus = this.adapter.getStatus();
13461
+ const adapterStatus = this.adapter.getStatus({ allowParse: false });
13402
13462
  const autoApproveActive = adapterStatus.status === "waiting_approval" && this.shouldAutoApprove();
13403
13463
  const visibleStatus = autoApproveActive ? "generating" : adapterStatus.status;
13404
13464
  const runtime = this.adapter.getRuntimeMetadata();