@adhdev/daemon-core 0.9.31 → 0.9.33
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 +4 -0
- package/dist/index.js +113 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +113 -11
- package/dist/index.mjs.map +1 -1
- package/dist/providers/provider-loader.d.ts +2 -0
- package/dist/status/chat-tail-hot-sessions.d.ts +1 -0
- package/node_modules/@adhdev/session-host-core/package.json +1 -1
- package/package.json +1 -1
- package/src/cli-adapters/provider-cli-adapter.ts +54 -3
- package/src/commands/chat-commands.ts +54 -0
- package/src/logging/logger.ts +5 -6
- package/src/providers/provider-loader.ts +25 -5
- package/src/status/chat-tail-hot-sessions.ts +6 -0
package/dist/index.mjs
CHANGED
|
@@ -348,14 +348,13 @@ function daemonLog(category, msg, level = "info") {
|
|
|
348
348
|
const shouldOutput = LEVEL_NUM[level] >= LEVEL_NUM[currentLevel];
|
|
349
349
|
const label = LEVEL_LABEL[level];
|
|
350
350
|
const line = `[${ts()}] [${label}] [${category}] ${msg}`;
|
|
351
|
+
if (!shouldOutput) return;
|
|
351
352
|
writeToFile(line);
|
|
352
353
|
ringBuffer.push({ ts: Date.now(), level, category, message: msg });
|
|
353
354
|
if (ringBuffer.length > RING_BUFFER_SIZE) {
|
|
354
355
|
ringBuffer.splice(0, ringBuffer.length - RING_BUFFER_SIZE);
|
|
355
356
|
}
|
|
356
|
-
|
|
357
|
-
origConsoleLog(line);
|
|
358
|
-
}
|
|
357
|
+
origConsoleLog(line);
|
|
359
358
|
}
|
|
360
359
|
function installGlobalInterceptor() {
|
|
361
360
|
if (interceptorInstalled) return;
|
|
@@ -2161,6 +2160,7 @@ var init_provider_cli_adapter = __esm({
|
|
|
2161
2160
|
static STATUS_HOT_PATH_PARSE_MIN_INTERVAL_MS = 1e3;
|
|
2162
2161
|
static SCREEN_SNAPSHOT_MIN_INTERVAL_MS = 250;
|
|
2163
2162
|
static MAX_TRACE_ENTRIES = 250;
|
|
2163
|
+
static PARSE_MESSAGE_TAIL_LIMIT = 100;
|
|
2164
2164
|
providerResolutionMeta;
|
|
2165
2165
|
static FINISH_RETRY_DELAY_MS = 300;
|
|
2166
2166
|
static MAX_FINISH_RETRIES = 2;
|
|
@@ -2192,6 +2192,32 @@ var init_provider_cli_adapter = __esm({
|
|
|
2192
2192
|
}
|
|
2193
2193
|
return null;
|
|
2194
2194
|
}
|
|
2195
|
+
selectParseBaseMessages(baseMessages) {
|
|
2196
|
+
if (baseMessages.length <= _ProviderCliAdapter.PARSE_MESSAGE_TAIL_LIMIT) return baseMessages;
|
|
2197
|
+
return baseMessages.slice(-_ProviderCliAdapter.PARSE_MESSAGE_TAIL_LIMIT);
|
|
2198
|
+
}
|
|
2199
|
+
messagesComparable(left, right) {
|
|
2200
|
+
if (!left || !right) return false;
|
|
2201
|
+
if ((left.role || "") !== (right.role || "")) return false;
|
|
2202
|
+
const leftText = normalizeComparableTranscriptText(left.content);
|
|
2203
|
+
const rightText = normalizeComparableTranscriptText(right.content);
|
|
2204
|
+
return !!leftText && leftText === rightText;
|
|
2205
|
+
}
|
|
2206
|
+
stitchParsedMessagesWithCommittedBase(parsedMessages, fullBaseMessages, parseBaseMessages) {
|
|
2207
|
+
if (!Array.isArray(parsedMessages) || parsedMessages.length === 0) return parsedMessages;
|
|
2208
|
+
if (fullBaseMessages.length <= parseBaseMessages.length) return parsedMessages;
|
|
2209
|
+
const parsedFirst = parsedMessages[0];
|
|
2210
|
+
const fullFirst = fullBaseMessages[0];
|
|
2211
|
+
if (parsedMessages.length >= fullBaseMessages.length && this.messagesComparable(parsedFirst, fullFirst)) {
|
|
2212
|
+
return parsedMessages;
|
|
2213
|
+
}
|
|
2214
|
+
const tailFirst = parseBaseMessages[0];
|
|
2215
|
+
if (tailFirst && this.messagesComparable(parsedFirst, tailFirst)) {
|
|
2216
|
+
const prefixLength = fullBaseMessages.length - parseBaseMessages.length;
|
|
2217
|
+
return [...fullBaseMessages.slice(0, prefixLength), ...parsedMessages];
|
|
2218
|
+
}
|
|
2219
|
+
return [...fullBaseMessages, ...parsedMessages];
|
|
2220
|
+
}
|
|
2195
2221
|
getIdleFinishConfirmMs() {
|
|
2196
2222
|
return this.timeouts.idleFinishConfirm;
|
|
2197
2223
|
}
|
|
@@ -2777,7 +2803,7 @@ var init_provider_cli_adapter = __esm({
|
|
|
2777
2803
|
const ctx = { now, modal, status, parsedMessages, lastParsedAssistant, parsedStatus: parsedStatus || null, prevStatus };
|
|
2778
2804
|
if (!this.applyPendingScriptStatusDebounce(ctx)) return;
|
|
2779
2805
|
const recentInteractiveActivity = this.hasRecentInteractiveActivity(now);
|
|
2780
|
-
LOG.
|
|
2806
|
+
LOG.debug(
|
|
2781
2807
|
"CLI",
|
|
2782
2808
|
`[${this.cliType}] settled diagnostics prompt=${JSON.stringify(this.currentTurnScope?.prompt || "").slice(0, 140)} status=${String(status || "")} parsedStatus=${String(parsedStatus || "")} parsedMsgCount=${parsedMessages.length} lastParsedAssistant=${JSON.stringify(summarizeCliTraceText(lastParsedAssistant?.content || "", 120)).slice(0, 160)} responseBuffer=${JSON.stringify(summarizeCliTraceText(this.responseBuffer, 160)).slice(0, 220)} screen=${JSON.stringify(summarizeCliTraceText(screenText, 160)).slice(0, 220)}`
|
|
2783
2809
|
);
|
|
@@ -3144,18 +3170,26 @@ var init_provider_cli_adapter = __esm({
|
|
|
3144
3170
|
try {
|
|
3145
3171
|
const screenText = this.terminalScreen.getText();
|
|
3146
3172
|
const tail = this.recentOutputBuffer.slice(-500);
|
|
3173
|
+
const parseBaseMessages = this.selectParseBaseMessages(this.committedMessages);
|
|
3147
3174
|
const input = buildCliParseInput({
|
|
3148
3175
|
accumulatedBuffer: this.accumulatedBuffer,
|
|
3149
3176
|
accumulatedRawBuffer: this.accumulatedRawBuffer,
|
|
3150
3177
|
recentOutputBuffer: this.recentOutputBuffer,
|
|
3151
3178
|
terminalScreenText: screenText,
|
|
3152
|
-
baseMessages:
|
|
3179
|
+
baseMessages: parseBaseMessages,
|
|
3153
3180
|
partialResponse: this.responseBuffer,
|
|
3154
3181
|
isWaitingForResponse: this.isWaitingForResponse,
|
|
3155
3182
|
scope: this.currentTurnScope,
|
|
3156
3183
|
runtimeSettings: this.runtimeSettings
|
|
3157
3184
|
});
|
|
3158
3185
|
const session = this.cliScripts.parseSession({ ...input, tail, tailScreen: buildCliScreenSnapshot(tail) });
|
|
3186
|
+
if (session && typeof session === "object" && Array.isArray(session.messages)) {
|
|
3187
|
+
session.messages = this.stitchParsedMessagesWithCommittedBase(
|
|
3188
|
+
session.messages,
|
|
3189
|
+
this.committedMessages,
|
|
3190
|
+
parseBaseMessages
|
|
3191
|
+
);
|
|
3192
|
+
}
|
|
3159
3193
|
this.parseErrorMessage = null;
|
|
3160
3194
|
return session && typeof session === "object" ? session : null;
|
|
3161
3195
|
} catch (e) {
|
|
@@ -3476,12 +3510,13 @@ var init_provider_cli_adapter = __esm({
|
|
|
3476
3510
|
}
|
|
3477
3511
|
try {
|
|
3478
3512
|
const screenText = typeof screenTextOverride === "string" ? screenTextOverride : this.terminalScreen.getText();
|
|
3513
|
+
const parseBaseMessages = this.selectParseBaseMessages(baseMessages);
|
|
3479
3514
|
const input = buildCliParseInput({
|
|
3480
3515
|
accumulatedBuffer: this.accumulatedBuffer,
|
|
3481
3516
|
accumulatedRawBuffer: this.accumulatedRawBuffer,
|
|
3482
3517
|
recentOutputBuffer: this.recentOutputBuffer,
|
|
3483
3518
|
terminalScreenText: screenText,
|
|
3484
|
-
baseMessages,
|
|
3519
|
+
baseMessages: parseBaseMessages,
|
|
3485
3520
|
partialResponse,
|
|
3486
3521
|
isWaitingForResponse: this.isWaitingForResponse,
|
|
3487
3522
|
scope,
|
|
@@ -3493,6 +3528,11 @@ var init_provider_cli_adapter = __esm({
|
|
|
3493
3528
|
}
|
|
3494
3529
|
const normalizedParsed = this.suppressStaleParsedApproval(parsed, input.recentBuffer, input.screenText);
|
|
3495
3530
|
if (normalizedParsed && Array.isArray(normalizedParsed.messages)) {
|
|
3531
|
+
normalizedParsed.messages = this.stitchParsedMessagesWithCommittedBase(
|
|
3532
|
+
normalizedParsed.messages,
|
|
3533
|
+
baseMessages,
|
|
3534
|
+
parseBaseMessages
|
|
3535
|
+
);
|
|
3496
3536
|
this.trimLastAssistantEcho(normalizedParsed.messages, scope?.prompt || getLastUserPromptText(baseMessages));
|
|
3497
3537
|
}
|
|
3498
3538
|
this.parseErrorMessage = null;
|
|
@@ -4993,6 +5033,7 @@ function classifyHotChatSessionsForSubscriptionFlush(sessions, previousHotSessio
|
|
|
4993
5033
|
Number.isFinite(options.recentMessageGraceMs) ? Number(options.recentMessageGraceMs) : DEFAULT_CHAT_TAIL_RECENT_MESSAGE_GRACE_MS
|
|
4994
5034
|
);
|
|
4995
5035
|
const activeStatuses = options.activeStatuses ?? DEFAULT_ACTIVE_CHAT_POLL_STATUSES;
|
|
5036
|
+
const activeSessionIds = options.activeSessionIds ?? /* @__PURE__ */ new Set();
|
|
4996
5037
|
const active = /* @__PURE__ */ new Set();
|
|
4997
5038
|
const excluded = /* @__PURE__ */ new Set();
|
|
4998
5039
|
for (const session of sessions) {
|
|
@@ -5002,6 +5043,10 @@ function classifyHotChatSessionsForSubscriptionFlush(sessions, previousHotSessio
|
|
|
5002
5043
|
excluded.add(sessionId);
|
|
5003
5044
|
continue;
|
|
5004
5045
|
}
|
|
5046
|
+
if (activeSessionIds.has(sessionId)) {
|
|
5047
|
+
active.add(sessionId);
|
|
5048
|
+
continue;
|
|
5049
|
+
}
|
|
5005
5050
|
const status = String(session?.status || "").toLowerCase();
|
|
5006
5051
|
const unread = session?.unread === true;
|
|
5007
5052
|
const inboxBucket = String(session?.inboxBucket || "").toLowerCase();
|
|
@@ -10311,6 +10356,26 @@ function toHistoryPersistedMessages(messages) {
|
|
|
10311
10356
|
historyDedupKey: deriveHistoryDedupKey(message)
|
|
10312
10357
|
}));
|
|
10313
10358
|
}
|
|
10359
|
+
function findLastMessageIndexBySignature(messages, signature) {
|
|
10360
|
+
if (!signature) return -1;
|
|
10361
|
+
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
10362
|
+
if (getChatMessageSignature(messages[index]) === signature) {
|
|
10363
|
+
return index;
|
|
10364
|
+
}
|
|
10365
|
+
}
|
|
10366
|
+
return -1;
|
|
10367
|
+
}
|
|
10368
|
+
function buildBoundedTailSync(messages, cursor) {
|
|
10369
|
+
const totalMessages = messages.length;
|
|
10370
|
+
const tailMessages = cursor.tailLimit > 0 && totalMessages > cursor.tailLimit ? messages.slice(-cursor.tailLimit) : messages;
|
|
10371
|
+
return {
|
|
10372
|
+
syncMode: "full",
|
|
10373
|
+
replaceFrom: 0,
|
|
10374
|
+
messages: tailMessages,
|
|
10375
|
+
totalMessages,
|
|
10376
|
+
lastMessageSignature: getChatMessageSignature(messages[totalMessages - 1])
|
|
10377
|
+
};
|
|
10378
|
+
}
|
|
10314
10379
|
function computeReadChatSync(messages, cursor) {
|
|
10315
10380
|
const totalMessages = messages.length;
|
|
10316
10381
|
const lastMessageSignature = getChatMessageSignature(messages[totalMessages - 1]);
|
|
@@ -10342,6 +10407,15 @@ function computeReadChatSync(messages, cursor) {
|
|
|
10342
10407
|
lastMessageSignature
|
|
10343
10408
|
};
|
|
10344
10409
|
}
|
|
10410
|
+
if (cursor.tailLimit > 0 && knownSignature === lastMessageSignature) {
|
|
10411
|
+
return {
|
|
10412
|
+
syncMode: "noop",
|
|
10413
|
+
replaceFrom: totalMessages,
|
|
10414
|
+
messages: [],
|
|
10415
|
+
totalMessages,
|
|
10416
|
+
lastMessageSignature
|
|
10417
|
+
};
|
|
10418
|
+
}
|
|
10345
10419
|
if (knownMessageCount < totalMessages) {
|
|
10346
10420
|
const anchorSignature = getChatMessageSignature(messages[knownMessageCount - 1]);
|
|
10347
10421
|
if (anchorSignature === knownSignature) {
|
|
@@ -10353,6 +10427,19 @@ function computeReadChatSync(messages, cursor) {
|
|
|
10353
10427
|
lastMessageSignature
|
|
10354
10428
|
};
|
|
10355
10429
|
}
|
|
10430
|
+
if (cursor.tailLimit > 0) {
|
|
10431
|
+
const signatureIndex = findLastMessageIndexBySignature(messages, knownSignature);
|
|
10432
|
+
if (signatureIndex >= 0) {
|
|
10433
|
+
return {
|
|
10434
|
+
syncMode: "append",
|
|
10435
|
+
replaceFrom: knownMessageCount,
|
|
10436
|
+
messages: messages.slice(signatureIndex + 1),
|
|
10437
|
+
totalMessages,
|
|
10438
|
+
lastMessageSignature
|
|
10439
|
+
};
|
|
10440
|
+
}
|
|
10441
|
+
return buildBoundedTailSync(messages, cursor);
|
|
10442
|
+
}
|
|
10356
10443
|
}
|
|
10357
10444
|
const replaceFrom = Math.max(0, Math.min(knownMessageCount - 1, totalMessages));
|
|
10358
10445
|
return {
|
|
@@ -15966,6 +16053,9 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
15966
16053
|
log(msg) {
|
|
15967
16054
|
this.logFn(`[ProviderLoader] ${msg}`);
|
|
15968
16055
|
}
|
|
16056
|
+
debugLog(msg) {
|
|
16057
|
+
LOG.debug("Provider", `[ProviderLoader] ${msg}`);
|
|
16058
|
+
}
|
|
15969
16059
|
// ─── Public API ────────────────────────────────
|
|
15970
16060
|
/**
|
|
15971
16061
|
* User override root (~/.adhdev/providers by default).
|
|
@@ -16355,10 +16445,22 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
16355
16445
|
setMachineProviderEnabled(type, enabled) {
|
|
16356
16446
|
return this.setMachineProviderConfig(type, { enabled });
|
|
16357
16447
|
}
|
|
16448
|
+
getEffectiveProviderAvailability(type) {
|
|
16449
|
+
const providerType = this.resolveAlias(type);
|
|
16450
|
+
const availability = this.providerAvailability.get(providerType);
|
|
16451
|
+
if (availability) return availability;
|
|
16452
|
+
const machineConfig = this.getMachineProviderConfig(providerType);
|
|
16453
|
+
const lastDetection = machineConfig.lastDetection;
|
|
16454
|
+
if (!lastDetection) return void 0;
|
|
16455
|
+
return {
|
|
16456
|
+
installed: lastDetection.ok === true,
|
|
16457
|
+
detectedPath: typeof lastDetection.path === "string" && lastDetection.path.trim() ? lastDetection.path.trim() : null
|
|
16458
|
+
};
|
|
16459
|
+
}
|
|
16358
16460
|
getMachineProviderStatus(type) {
|
|
16359
16461
|
const providerType = this.resolveAlias(type);
|
|
16360
16462
|
if (!this.isMachineProviderEnabled(providerType)) return "disabled";
|
|
16361
|
-
const availability = this.
|
|
16463
|
+
const availability = this.getEffectiveProviderAvailability(providerType);
|
|
16362
16464
|
if (!availability) return "enabled_unchecked";
|
|
16363
16465
|
return availability.installed ? "detected" : "not_detected";
|
|
16364
16466
|
}
|
|
@@ -16486,7 +16588,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
16486
16588
|
}
|
|
16487
16589
|
getAvailableProviderInfos() {
|
|
16488
16590
|
return this.getAll().map((provider) => {
|
|
16489
|
-
const availability = this.
|
|
16591
|
+
const availability = this.getEffectiveProviderAvailability(provider.type);
|
|
16490
16592
|
const enabled = this.isMachineProviderEnabled(provider.type);
|
|
16491
16593
|
const machineConfig = this.getMachineProviderConfig(provider.type);
|
|
16492
16594
|
return {
|
|
@@ -16572,7 +16674,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
16572
16674
|
const loaded = this.loadScriptsFromDir(type, entry.scriptDir);
|
|
16573
16675
|
if (loaded) {
|
|
16574
16676
|
resolved.scripts = loaded;
|
|
16575
|
-
this.
|
|
16677
|
+
this.debugLog(` [compatibility] ${type} v${currentVersion} \u2192 ${entry.scriptDir}`);
|
|
16576
16678
|
resolved._resolvedScriptDir = entry.scriptDir;
|
|
16577
16679
|
resolved._resolvedScriptsSource = `compatibility:${entry.ideVersion}`;
|
|
16578
16680
|
if (providerDir) {
|
|
@@ -16588,7 +16690,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
16588
16690
|
const loaded = this.loadScriptsFromDir(type, base.defaultScriptDir);
|
|
16589
16691
|
if (loaded) {
|
|
16590
16692
|
resolved.scripts = loaded;
|
|
16591
|
-
this.
|
|
16693
|
+
this.debugLog(` [compatibility] ${type} v${currentVersion} \u2192 default: ${base.defaultScriptDir}`);
|
|
16592
16694
|
resolved._resolvedScriptDir = base.defaultScriptDir;
|
|
16593
16695
|
resolved._resolvedScriptsSource = "defaultScriptDir:version_miss";
|
|
16594
16696
|
if (providerDir) {
|
|
@@ -16623,7 +16725,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
16623
16725
|
const loaded = this.loadScriptsFromDir(type, base.defaultScriptDir);
|
|
16624
16726
|
if (loaded) {
|
|
16625
16727
|
resolved.scripts = loaded;
|
|
16626
|
-
this.
|
|
16728
|
+
this.debugLog(` [compatibility] ${type} no version detected \u2192 default: ${base.defaultScriptDir}`);
|
|
16627
16729
|
resolved._resolvedScriptDir = base.defaultScriptDir;
|
|
16628
16730
|
resolved._resolvedScriptsSource = "defaultScriptDir:no_version";
|
|
16629
16731
|
if (providerDir) {
|