adhdev 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/index.js +96 -27
- package/dist/cli/index.js.map +1 -1
- package/dist/index.js +96 -27
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -12376,27 +12376,86 @@ function sliceFromOffset(text, start) {
|
|
|
12376
12376
|
function hydrateCliParsedMessages(parsedMessages, options) {
|
|
12377
12377
|
const { committedMessages, scope, lastOutputAt } = options;
|
|
12378
12378
|
const referenceMessages = [...committedMessages];
|
|
12379
|
-
const referenceComparables = referenceMessages.
|
|
12379
|
+
const referenceComparables = new Array(referenceMessages.length);
|
|
12380
12380
|
const usedReferenceIndexes = /* @__PURE__ */ new Set();
|
|
12381
12381
|
const now = options.now ?? Date.now();
|
|
12382
|
-
|
|
12382
|
+
let exactReferenceIndexesByKey = null;
|
|
12383
|
+
const exactReferenceCursorByKey = /* @__PURE__ */ new Map();
|
|
12384
|
+
const hasFiniteTimestamp = (message) => typeof message?.timestamp === "number" && Number.isFinite(message.timestamp);
|
|
12385
|
+
const getReferenceComparable = (index) => {
|
|
12386
|
+
if (typeof referenceComparables[index] === "string") return referenceComparables[index] || "";
|
|
12387
|
+
const comparable = normalizeComparableMessageContent(referenceMessages[index]?.content || "");
|
|
12388
|
+
referenceComparables[index] = comparable;
|
|
12389
|
+
return comparable;
|
|
12390
|
+
};
|
|
12391
|
+
const messagesShareStableIdentity = (parsed, reference) => {
|
|
12392
|
+
if (!parsed || !reference) return false;
|
|
12393
|
+
const parsedId = typeof parsed.id === "string" ? parsed.id.trim() : "";
|
|
12394
|
+
const referenceId = typeof reference.id === "string" ? reference.id.trim() : "";
|
|
12395
|
+
if (parsedId && referenceId && parsedId === referenceId) return true;
|
|
12396
|
+
return typeof parsed.index === "number" && Number.isFinite(parsed.index) && typeof reference.index === "number" && Number.isFinite(reference.index) && parsed.index === reference.index;
|
|
12397
|
+
};
|
|
12398
|
+
const exactReferenceKey = (role, comparable) => `${role}\0${comparable}`;
|
|
12399
|
+
const ensureExactReferenceIndex = () => {
|
|
12400
|
+
if (exactReferenceIndexesByKey) return exactReferenceIndexesByKey;
|
|
12401
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
12402
|
+
for (let i = 0; i < referenceMessages.length; i++) {
|
|
12403
|
+
const candidate = referenceMessages[i];
|
|
12404
|
+
if (!candidate || candidate.role !== "user" && candidate.role !== "assistant" || !hasFiniteTimestamp(candidate)) continue;
|
|
12405
|
+
const comparable = getReferenceComparable(i);
|
|
12406
|
+
if (!comparable) continue;
|
|
12407
|
+
const key = exactReferenceKey(candidate.role, comparable);
|
|
12408
|
+
const indexes = byKey.get(key);
|
|
12409
|
+
if (indexes) {
|
|
12410
|
+
indexes.push(i);
|
|
12411
|
+
} else {
|
|
12412
|
+
byKey.set(key, [i]);
|
|
12413
|
+
}
|
|
12414
|
+
}
|
|
12415
|
+
exactReferenceIndexesByKey = byKey;
|
|
12416
|
+
return byKey;
|
|
12417
|
+
};
|
|
12418
|
+
const takeExactReferenceTimestamp = (role, normalizedContent) => {
|
|
12419
|
+
const key = exactReferenceKey(role, normalizedContent);
|
|
12420
|
+
const indexes = ensureExactReferenceIndex().get(key);
|
|
12421
|
+
if (!indexes) return void 0;
|
|
12422
|
+
let cursor = exactReferenceCursorByKey.get(key) || 0;
|
|
12423
|
+
while (cursor < indexes.length) {
|
|
12424
|
+
const candidateIndex = indexes[cursor];
|
|
12425
|
+
cursor += 1;
|
|
12426
|
+
if (usedReferenceIndexes.has(candidateIndex)) continue;
|
|
12427
|
+
const candidate = referenceMessages[candidateIndex];
|
|
12428
|
+
if (!candidate || candidate.role !== role || !hasFiniteTimestamp(candidate)) continue;
|
|
12429
|
+
usedReferenceIndexes.add(candidateIndex);
|
|
12430
|
+
exactReferenceCursorByKey.set(key, cursor);
|
|
12431
|
+
return candidate.timestamp;
|
|
12432
|
+
}
|
|
12433
|
+
exactReferenceCursorByKey.set(key, cursor);
|
|
12434
|
+
return void 0;
|
|
12435
|
+
};
|
|
12436
|
+
const findReferenceTimestamp = (message, role, content, parsedIndex) => {
|
|
12437
|
+
const sameIndex = referenceMessages[parsedIndex];
|
|
12438
|
+
if (sameIndex && !usedReferenceIndexes.has(parsedIndex) && sameIndex.role === role && hasFiniteTimestamp(sameIndex) && messagesShareStableIdentity(message, sameIndex)) {
|
|
12439
|
+
usedReferenceIndexes.add(parsedIndex);
|
|
12440
|
+
return sameIndex.timestamp;
|
|
12441
|
+
}
|
|
12383
12442
|
const normalizedContent = normalizeComparableMessageContent(content);
|
|
12384
12443
|
if (!normalizedContent) return void 0;
|
|
12385
|
-
|
|
12386
|
-
if (sameIndex && !usedReferenceIndexes.has(parsedIndex) && sameIndex.role === role && referenceComparables[parsedIndex] === normalizedContent && typeof sameIndex.timestamp === "number" && Number.isFinite(sameIndex.timestamp)) {
|
|
12444
|
+
if (sameIndex && !usedReferenceIndexes.has(parsedIndex) && sameIndex.role === role && getReferenceComparable(parsedIndex) === normalizedContent && hasFiniteTimestamp(sameIndex)) {
|
|
12387
12445
|
usedReferenceIndexes.add(parsedIndex);
|
|
12388
12446
|
return sameIndex.timestamp;
|
|
12389
12447
|
}
|
|
12448
|
+
const exactTimestamp = takeExactReferenceTimestamp(role, normalizedContent);
|
|
12449
|
+
if (typeof exactTimestamp === "number") return exactTimestamp;
|
|
12390
12450
|
for (let i = 0; i < referenceMessages.length; i++) {
|
|
12391
12451
|
if (usedReferenceIndexes.has(i)) continue;
|
|
12392
12452
|
const candidate = referenceMessages[i];
|
|
12393
12453
|
if (!candidate || candidate.role !== role) continue;
|
|
12394
|
-
const candidateContent =
|
|
12454
|
+
const candidateContent = getReferenceComparable(i);
|
|
12395
12455
|
if (!candidateContent) continue;
|
|
12396
|
-
const exactMatch = candidateContent === normalizedContent;
|
|
12397
12456
|
const fuzzyMatch = candidateContent.includes(normalizedContent) || normalizedContent.includes(candidateContent);
|
|
12398
|
-
if (!
|
|
12399
|
-
if (
|
|
12457
|
+
if (!fuzzyMatch) continue;
|
|
12458
|
+
if (hasFiniteTimestamp(candidate)) {
|
|
12400
12459
|
usedReferenceIndexes.add(i);
|
|
12401
12460
|
return candidate.timestamp;
|
|
12402
12461
|
}
|
|
@@ -12407,7 +12466,7 @@ function hydrateCliParsedMessages(parsedMessages, options) {
|
|
|
12407
12466
|
const role = message.role;
|
|
12408
12467
|
const content = typeof message.content === "string" ? message.content : String(message.content || "");
|
|
12409
12468
|
const parsedTimestamp = typeof message.timestamp === "number" && Number.isFinite(message.timestamp) ? message.timestamp : void 0;
|
|
12410
|
-
const referenceTimestamp = parsedTimestamp ?? findReferenceTimestamp(role, content, index);
|
|
12469
|
+
const referenceTimestamp = parsedTimestamp ?? findReferenceTimestamp(message, role, content, index);
|
|
12411
12470
|
const fallbackTimestamp = role === "user" ? scope?.startedAt || now : lastOutputAt || scope?.startedAt || now;
|
|
12412
12471
|
const timestamp = referenceTimestamp ?? fallbackTimestamp;
|
|
12413
12472
|
return {
|
|
@@ -14027,11 +14086,12 @@ var init_provider_cli_adapter = __esm({
|
|
|
14027
14086
|
};
|
|
14028
14087
|
}
|
|
14029
14088
|
// ─── Public API (CliAdapter) ───────────────────
|
|
14030
|
-
getStatus() {
|
|
14031
|
-
const
|
|
14089
|
+
getStatus(options = {}) {
|
|
14090
|
+
const allowParse = options.allowParse !== false;
|
|
14091
|
+
const startupModal = allowParse && this.startupParseGate ? this.runParseApproval(this.recentOutputBuffer) : null;
|
|
14032
14092
|
let effectiveStatus = this.projectEffectiveStatus(startupModal);
|
|
14033
14093
|
let effectiveModal = startupModal || this.activeModal;
|
|
14034
|
-
if (!startupModal && !effectiveModal && typeof this.cliScripts?.parseOutput === "function") {
|
|
14094
|
+
if (allowParse && !startupModal && !effectiveModal && typeof this.cliScripts?.parseOutput === "function") {
|
|
14035
14095
|
let parsed = this.getFreshParsedStatusCache();
|
|
14036
14096
|
if (!parsed && effectiveStatus !== "idle") {
|
|
14037
14097
|
const now = Date.now();
|
|
@@ -14990,17 +15050,24 @@ function buildPersistableCliHistorySignature(message) {
|
|
|
14990
15050
|
normalizePersistableCliHistoryContent(message.content)
|
|
14991
15051
|
].join("|");
|
|
14992
15052
|
}
|
|
15053
|
+
function hasSamePersistableCliHistoryIdentity(a, b) {
|
|
15054
|
+
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 || "");
|
|
15055
|
+
}
|
|
14993
15056
|
function buildIncrementalHistoryAppendMessages(previousMessages, currentMessages) {
|
|
14994
15057
|
if (!Array.isArray(currentMessages) || currentMessages.length === 0) return [];
|
|
14995
15058
|
if (!Array.isArray(previousMessages) || previousMessages.length === 0) return currentMessages;
|
|
14996
|
-
const
|
|
14997
|
-
const currentSignatures = currentMessages.map(buildPersistableCliHistorySignature);
|
|
15059
|
+
const comparableLength = Math.min(previousMessages.length, currentMessages.length);
|
|
14998
15060
|
let sharedPrefixLength = 0;
|
|
14999
|
-
while (sharedPrefixLength <
|
|
15061
|
+
while (sharedPrefixLength < comparableLength && hasSamePersistableCliHistoryIdentity(previousMessages[sharedPrefixLength], currentMessages[sharedPrefixLength])) {
|
|
15062
|
+
sharedPrefixLength += 1;
|
|
15063
|
+
}
|
|
15064
|
+
if (sharedPrefixLength === currentMessages.length) return [];
|
|
15065
|
+
if (sharedPrefixLength === previousMessages.length) return currentMessages.slice(sharedPrefixLength);
|
|
15066
|
+
while (sharedPrefixLength < comparableLength && buildPersistableCliHistorySignature(previousMessages[sharedPrefixLength]) === buildPersistableCliHistorySignature(currentMessages[sharedPrefixLength])) {
|
|
15000
15067
|
sharedPrefixLength += 1;
|
|
15001
15068
|
}
|
|
15002
|
-
if (sharedPrefixLength ===
|
|
15003
|
-
if (sharedPrefixLength ===
|
|
15069
|
+
if (sharedPrefixLength === currentMessages.length) return [];
|
|
15070
|
+
if (sharedPrefixLength === previousMessages.length) return currentMessages.slice(sharedPrefixLength);
|
|
15004
15071
|
return currentMessages;
|
|
15005
15072
|
}
|
|
15006
15073
|
function getDatabaseSync() {
|
|
@@ -15267,13 +15334,15 @@ var init_cli_provider_instance = __esm({
|
|
|
15267
15334
|
}));
|
|
15268
15335
|
if (!canonicalBackedHistory && !shouldSkipReplayPersist && normalizedMessagesToSave.length > 0) {
|
|
15269
15336
|
const incrementalMessages = buildIncrementalHistoryAppendMessages(this.lastPersistedHistoryMessages, normalizedMessagesToSave);
|
|
15270
|
-
|
|
15271
|
-
this.
|
|
15272
|
-
|
|
15273
|
-
|
|
15274
|
-
|
|
15275
|
-
|
|
15276
|
-
|
|
15337
|
+
if (incrementalMessages.length > 0) {
|
|
15338
|
+
this.historyWriter.appendNewMessages(
|
|
15339
|
+
this.type,
|
|
15340
|
+
incrementalMessages,
|
|
15341
|
+
parsedStatus?.title || dirName,
|
|
15342
|
+
this.instanceId,
|
|
15343
|
+
this.providerSessionId
|
|
15344
|
+
);
|
|
15345
|
+
}
|
|
15277
15346
|
}
|
|
15278
15347
|
if (!canonicalBackedHistory) {
|
|
15279
15348
|
this.lastPersistedHistoryMessages = normalizedMessagesToSave;
|
|
@@ -15332,7 +15401,7 @@ var init_cli_provider_instance = __esm({
|
|
|
15332
15401
|
return this.presentationMode;
|
|
15333
15402
|
}
|
|
15334
15403
|
getHotChatSessionState() {
|
|
15335
|
-
const adapterStatus = this.adapter.getStatus();
|
|
15404
|
+
const adapterStatus = this.adapter.getStatus({ allowParse: false });
|
|
15336
15405
|
const autoApproveActive = adapterStatus.status === "waiting_approval" && this.shouldAutoApprove();
|
|
15337
15406
|
const visibleStatus = autoApproveActive ? "generating" : adapterStatus.status;
|
|
15338
15407
|
const runtime = this.adapter.getRuntimeMetadata();
|
|
@@ -88235,7 +88304,7 @@ var init_adhdev_daemon = __esm({
|
|
|
88235
88304
|
init_version();
|
|
88236
88305
|
init_src();
|
|
88237
88306
|
init_runtime_defaults();
|
|
88238
|
-
pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.
|
|
88307
|
+
pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.38" });
|
|
88239
88308
|
AdhdevDaemon = class _AdhdevDaemon {
|
|
88240
88309
|
localHttpServer = null;
|
|
88241
88310
|
localWss = null;
|
|
@@ -88252,7 +88321,7 @@ var init_adhdev_daemon = __esm({
|
|
|
88252
88321
|
p2pChatOutputActiveAt = /* @__PURE__ */ new Map();
|
|
88253
88322
|
p2pChatOutputFlushTimer = null;
|
|
88254
88323
|
hotChatSnapshotCache = null;
|
|
88255
|
-
static HOT_CHAT_SNAPSHOT_CACHE_TTL_MS =
|
|
88324
|
+
static HOT_CHAT_SNAPSHOT_CACHE_TTL_MS = 2400;
|
|
88256
88325
|
static CHAT_OUTPUT_ACTIVITY_HOT_MS = DEFAULT_CHAT_TAIL_RECENT_MESSAGE_GRACE_MS;
|
|
88257
88326
|
static CHAT_OUTPUT_FLUSH_DEBOUNCE_MS = 700;
|
|
88258
88327
|
components = null;
|