@adhdev/daemon-core 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/cli-adapters/provider-cli-adapter.d.ts +3 -1
- package/dist/index.js +94 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +94 -25
- package/dist/index.mjs.map +1 -1
- package/node_modules/@adhdev/session-host-core/package.json +1 -1
- package/package.json +1 -1
- package/src/cli-adapters/provider-cli-adapter.ts +4 -3
- package/src/cli-adapters/provider-cli-parse.ts +89 -11
- package/src/providers/cli-provider-instance.ts +37 -16
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.
|
|
1691
|
+
const referenceComparables = new Array(referenceMessages.length);
|
|
1692
1692
|
const usedReferenceIndexes = /* @__PURE__ */ new Set();
|
|
1693
1693
|
const now = options.now ?? Date.now();
|
|
1694
|
-
|
|
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
|
-
|
|
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 =
|
|
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 (!
|
|
1711
|
-
if (
|
|
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
|
|
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();
|
|
@@ -13077,17 +13137,24 @@ function buildPersistableCliHistorySignature(message) {
|
|
|
13077
13137
|
normalizePersistableCliHistoryContent(message.content)
|
|
13078
13138
|
].join("|");
|
|
13079
13139
|
}
|
|
13140
|
+
function hasSamePersistableCliHistoryIdentity(a, b) {
|
|
13141
|
+
return String(a?.role || "") === String(b?.role || "") && String(a?.kind || "") === String(b?.kind || "") && String(a?.senderName || "") === String(b?.senderName || "") && String(a?.content || "") === String(b?.content || "");
|
|
13142
|
+
}
|
|
13080
13143
|
function buildIncrementalHistoryAppendMessages(previousMessages, currentMessages) {
|
|
13081
13144
|
if (!Array.isArray(currentMessages) || currentMessages.length === 0) return [];
|
|
13082
13145
|
if (!Array.isArray(previousMessages) || previousMessages.length === 0) return currentMessages;
|
|
13083
|
-
const
|
|
13084
|
-
const currentSignatures = currentMessages.map(buildPersistableCliHistorySignature);
|
|
13146
|
+
const comparableLength = Math.min(previousMessages.length, currentMessages.length);
|
|
13085
13147
|
let sharedPrefixLength = 0;
|
|
13086
|
-
while (sharedPrefixLength <
|
|
13148
|
+
while (sharedPrefixLength < comparableLength && hasSamePersistableCliHistoryIdentity(previousMessages[sharedPrefixLength], currentMessages[sharedPrefixLength])) {
|
|
13149
|
+
sharedPrefixLength += 1;
|
|
13150
|
+
}
|
|
13151
|
+
if (sharedPrefixLength === currentMessages.length) return [];
|
|
13152
|
+
if (sharedPrefixLength === previousMessages.length) return currentMessages.slice(sharedPrefixLength);
|
|
13153
|
+
while (sharedPrefixLength < comparableLength && buildPersistableCliHistorySignature(previousMessages[sharedPrefixLength]) === buildPersistableCliHistorySignature(currentMessages[sharedPrefixLength])) {
|
|
13087
13154
|
sharedPrefixLength += 1;
|
|
13088
13155
|
}
|
|
13089
|
-
if (sharedPrefixLength ===
|
|
13090
|
-
if (sharedPrefixLength ===
|
|
13156
|
+
if (sharedPrefixLength === currentMessages.length) return [];
|
|
13157
|
+
if (sharedPrefixLength === previousMessages.length) return currentMessages.slice(sharedPrefixLength);
|
|
13091
13158
|
return currentMessages;
|
|
13092
13159
|
}
|
|
13093
13160
|
var CachedDatabaseSync = null;
|
|
@@ -13333,13 +13400,15 @@ var CliProviderInstance = class {
|
|
|
13333
13400
|
}));
|
|
13334
13401
|
if (!canonicalBackedHistory && !shouldSkipReplayPersist && normalizedMessagesToSave.length > 0) {
|
|
13335
13402
|
const incrementalMessages = buildIncrementalHistoryAppendMessages(this.lastPersistedHistoryMessages, normalizedMessagesToSave);
|
|
13336
|
-
|
|
13337
|
-
this.
|
|
13338
|
-
|
|
13339
|
-
|
|
13340
|
-
|
|
13341
|
-
|
|
13342
|
-
|
|
13403
|
+
if (incrementalMessages.length > 0) {
|
|
13404
|
+
this.historyWriter.appendNewMessages(
|
|
13405
|
+
this.type,
|
|
13406
|
+
incrementalMessages,
|
|
13407
|
+
parsedStatus?.title || dirName,
|
|
13408
|
+
this.instanceId,
|
|
13409
|
+
this.providerSessionId
|
|
13410
|
+
);
|
|
13411
|
+
}
|
|
13343
13412
|
}
|
|
13344
13413
|
if (!canonicalBackedHistory) {
|
|
13345
13414
|
this.lastPersistedHistoryMessages = normalizedMessagesToSave;
|
|
@@ -13398,7 +13467,7 @@ var CliProviderInstance = class {
|
|
|
13398
13467
|
return this.presentationMode;
|
|
13399
13468
|
}
|
|
13400
13469
|
getHotChatSessionState() {
|
|
13401
|
-
const adapterStatus = this.adapter.getStatus();
|
|
13470
|
+
const adapterStatus = this.adapter.getStatus({ allowParse: false });
|
|
13402
13471
|
const autoApproveActive = adapterStatus.status === "waiting_approval" && this.shouldAutoApprove();
|
|
13403
13472
|
const visibleStatus = autoApproveActive ? "generating" : adapterStatus.status;
|
|
13404
13473
|
const runtime = this.adapter.getRuntimeMetadata();
|