@adhdev/daemon-core 0.9.82-rc.175 → 0.9.82-rc.177
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/config/chat-history.d.ts +1 -0
- package/dist/index.js +67 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +67 -8
- package/dist/index.mjs.map +1 -1
- package/dist/providers/cli-provider-instance.d.ts +3 -0
- package/dist/providers/native-history/dispatcher.d.ts +1 -0
- package/package.json +1 -1
- package/src/config/chat-history.ts +7 -3
- package/src/providers/cli-provider-instance.ts +65 -1
- package/src/providers/native-history/dispatcher.ts +4 -0
package/dist/index.mjs
CHANGED
|
@@ -12715,6 +12715,12 @@ function createNativeHistoryDispatcher(reader) {
|
|
|
12715
12715
|
const requestedProviderSid = input.providerSessionId || "";
|
|
12716
12716
|
const sourcePath = resolveSourcePath(reader, workspace, sessionId);
|
|
12717
12717
|
if (!sourcePath) return null;
|
|
12718
|
+
if (input.forceRefresh === true || input.args?.forceRefresh === true) {
|
|
12719
|
+
try {
|
|
12720
|
+
fs18.statSync(sourcePath);
|
|
12721
|
+
} catch {
|
|
12722
|
+
}
|
|
12723
|
+
}
|
|
12718
12724
|
const session = readByReader(reader, sourcePath, sessionId, workspace);
|
|
12719
12725
|
if (!session) return null;
|
|
12720
12726
|
if (requestedProviderSid && session.providerSessionId && session.providerSessionId !== requestedProviderSid) {
|
|
@@ -19363,7 +19369,7 @@ function normalizeProviderNativeHistoryRecords(agentType, historySessionId, reco
|
|
|
19363
19369
|
return sanitizeHistoryMessage(agentType, base);
|
|
19364
19370
|
}).filter(Boolean);
|
|
19365
19371
|
}
|
|
19366
|
-
function callProviderNativeHistoryRead(agentType, canonicalHistory, scripts, historySessionId, workspace, excludeInProgressTurn, sessionStartedAtMs, envOverrides) {
|
|
19372
|
+
function callProviderNativeHistoryRead(agentType, canonicalHistory, scripts, historySessionId, workspace, excludeInProgressTurn, sessionStartedAtMs, envOverrides, forceRefresh) {
|
|
19367
19373
|
const fn = getProviderNativeHistoryScript(scripts, canonicalHistory, "readSession");
|
|
19368
19374
|
if (!fn) return null;
|
|
19369
19375
|
const normalizedSessionId = normalizeSavedHistorySessionId(historySessionId || "");
|
|
@@ -19377,7 +19383,8 @@ function callProviderNativeHistoryRead(agentType, canonicalHistory, scripts, his
|
|
|
19377
19383
|
excludeInProgressTurn: excludeInProgressTurn === true,
|
|
19378
19384
|
sessionStartedAtMs,
|
|
19379
19385
|
envOverrides,
|
|
19380
|
-
|
|
19386
|
+
forceRefresh: forceRefresh === true,
|
|
19387
|
+
args: { sessionId: normalizedSessionId, historySessionId: normalizedSessionId, workspace, excludeInProgressTurn: excludeInProgressTurn === true, sessionStartedAtMs, envOverrides, forceRefresh: forceRefresh === true }
|
|
19381
19388
|
});
|
|
19382
19389
|
if (!result || typeof result !== "object") return null;
|
|
19383
19390
|
const records = normalizeProviderNativeHistoryRecords(agentType, normalizedSessionId, result.messages || result.records);
|
|
@@ -19392,11 +19399,11 @@ function callProviderNativeHistoryRead(agentType, canonicalHistory, scripts, his
|
|
|
19392
19399
|
unavailableReason: typeof result.unavailableReason === "string" ? result.unavailableReason.trim() : void 0
|
|
19393
19400
|
};
|
|
19394
19401
|
}
|
|
19395
|
-
function buildNativeHistoryReadResult(agentType, canonicalHistory, scripts, historySessionId, workspace, excludeInProgressTurn, sessionStartedAtMs, envOverrides) {
|
|
19402
|
+
function buildNativeHistoryReadResult(agentType, canonicalHistory, scripts, historySessionId, workspace, excludeInProgressTurn, sessionStartedAtMs, envOverrides, forceRefresh) {
|
|
19396
19403
|
const normalizedSessionId = normalizeSavedHistorySessionId(historySessionId || "");
|
|
19397
19404
|
const normalizedWorkspace = typeof workspace === "string" ? workspace.trim() : "";
|
|
19398
19405
|
if (!canonicalHistory || !normalizedSessionId && !normalizedWorkspace || !isNativeSourceCanonicalHistory(canonicalHistory)) return null;
|
|
19399
|
-
return callProviderNativeHistoryRead(agentType, canonicalHistory, scripts, normalizedSessionId, workspace, excludeInProgressTurn, sessionStartedAtMs, envOverrides);
|
|
19406
|
+
return callProviderNativeHistoryRead(agentType, canonicalHistory, scripts, normalizedSessionId, workspace, excludeInProgressTurn, sessionStartedAtMs, envOverrides, forceRefresh);
|
|
19400
19407
|
}
|
|
19401
19408
|
function materializeNativeHistoryToMirror(agentType, canonicalHistory, historySessionId, workspace, scripts) {
|
|
19402
19409
|
const normalizedSessionId = normalizeSavedHistorySessionId(historySessionId);
|
|
@@ -19425,7 +19432,7 @@ function isNativeSourceCanonicalHistory(canonicalHistory) {
|
|
|
19425
19432
|
}
|
|
19426
19433
|
function readProviderChatHistory(agentType, options = {}) {
|
|
19427
19434
|
if (isNativeSourceCanonicalHistory(options.canonicalHistory) && (options.historySessionId || options.workspace)) {
|
|
19428
|
-
const nativeResult = buildNativeHistoryReadResult(agentType, options.canonicalHistory, options.scripts, options.historySessionId, options.workspace, options.excludeInProgressTurn, options.sessionStartedAtMs, options.envOverrides);
|
|
19435
|
+
const nativeResult = buildNativeHistoryReadResult(agentType, options.canonicalHistory, options.scripts, options.historySessionId, options.workspace, options.excludeInProgressTurn, options.sessionStartedAtMs, options.envOverrides, options.forceRefresh);
|
|
19429
19436
|
if (!nativeResult) return { messages: [], hasMore: false, source: "native-unavailable" };
|
|
19430
19437
|
return {
|
|
19431
19438
|
...pageHistoryRecords(agentType, nativeResult.records, options.offset || 0, options.limit || 30, options.excludeRecentCount || 0, options.historyBehavior),
|
|
@@ -28758,6 +28765,7 @@ var CliProviderInstance = class {
|
|
|
28758
28765
|
}
|
|
28759
28766
|
completedDebounceTimer = null;
|
|
28760
28767
|
completedDebouncePending = null;
|
|
28768
|
+
lastExternalCompletionProbe = null;
|
|
28761
28769
|
async enforceFreshSessionLaunchIfNeeded() {
|
|
28762
28770
|
const scriptName = getForcedNewSessionScriptName(this.provider, this.launchMode);
|
|
28763
28771
|
if (!scriptName) return;
|
|
@@ -28790,11 +28798,44 @@ var CliProviderInstance = class {
|
|
|
28790
28798
|
if (looksLikeActiveApprovalPromptText(content)) return false;
|
|
28791
28799
|
return true;
|
|
28792
28800
|
}
|
|
28801
|
+
buildExternalTranscriptProbe(messages, sourcePath, sourceMtimeMs) {
|
|
28802
|
+
const visibleMessages = messages.filter((message) => isUserFacingChatMessage(message));
|
|
28803
|
+
const lastVisible = visibleMessages[visibleMessages.length - 1];
|
|
28804
|
+
const readAt = Date.now();
|
|
28805
|
+
const mtimeMs = Number(sourceMtimeMs) || 0;
|
|
28806
|
+
return {
|
|
28807
|
+
readAt,
|
|
28808
|
+
msgCount: messages.length,
|
|
28809
|
+
lastRole: typeof lastVisible?.role === "string" ? lastVisible.role.trim().toLowerCase() : null,
|
|
28810
|
+
lastKind: typeof lastVisible?.kind === "string" ? lastVisible.kind : null,
|
|
28811
|
+
contentLen: lastVisible ? flattenContent(lastVisible.content).trim().length : 0,
|
|
28812
|
+
sourcePath: typeof sourcePath === "string" && sourcePath ? sourcePath : null,
|
|
28813
|
+
sourceMtimeMs: mtimeMs || null,
|
|
28814
|
+
mtimeAgeMs: mtimeMs ? Math.max(0, readAt - mtimeMs) : null
|
|
28815
|
+
};
|
|
28816
|
+
}
|
|
28817
|
+
recordPendingTranscriptProbe(pending) {
|
|
28818
|
+
const probe = this.lastExternalCompletionProbe;
|
|
28819
|
+
if (!probe) return null;
|
|
28820
|
+
const history = pending.transcriptProbeHistory || [];
|
|
28821
|
+
const last = history[history.length - 1];
|
|
28822
|
+
if (!last || last.readAt !== probe.readAt || last.msgCount !== probe.msgCount || last.lastRole !== probe.lastRole || last.contentLen !== probe.contentLen) {
|
|
28823
|
+
history.push(probe);
|
|
28824
|
+
pending.transcriptProbeHistory = history.slice(-5);
|
|
28825
|
+
}
|
|
28826
|
+
return probe;
|
|
28827
|
+
}
|
|
28793
28828
|
readExternalCompletionMessages() {
|
|
28794
28829
|
const adapterOwnsMessagesElsewhere = this.adapter?.chatMessagesOwnedExternally === true;
|
|
28795
28830
|
if (!adapterOwnsMessagesElsewhere) return null;
|
|
28796
28831
|
if (!this.providerSessionId) return null;
|
|
28797
28832
|
if (!isNativeSourceCanonicalHistory(this.provider.nativeHistory)) return null;
|
|
28833
|
+
if (this.lastExternalCompletionProbe?.sourcePath) {
|
|
28834
|
+
try {
|
|
28835
|
+
fs12.statSync(this.lastExternalCompletionProbe.sourcePath);
|
|
28836
|
+
} catch {
|
|
28837
|
+
}
|
|
28838
|
+
}
|
|
28798
28839
|
const restoredHistory = readProviderChatHistory(this.type, {
|
|
28799
28840
|
canonicalHistory: this.provider.nativeHistory,
|
|
28800
28841
|
historySessionId: this.providerSessionId,
|
|
@@ -28803,9 +28844,18 @@ var CliProviderInstance = class {
|
|
|
28803
28844
|
limit: Number.MAX_SAFE_INTEGER,
|
|
28804
28845
|
historyBehavior: this.provider.historyBehavior,
|
|
28805
28846
|
scripts: this.provider.scripts,
|
|
28806
|
-
sessionStartedAtMs: this.startedAt
|
|
28847
|
+
sessionStartedAtMs: this.startedAt,
|
|
28848
|
+
forceRefresh: true
|
|
28807
28849
|
});
|
|
28808
|
-
if (restoredHistory.source !== "provider-native")
|
|
28850
|
+
if (restoredHistory.source !== "provider-native") {
|
|
28851
|
+
this.lastExternalCompletionProbe = null;
|
|
28852
|
+
return null;
|
|
28853
|
+
}
|
|
28854
|
+
this.lastExternalCompletionProbe = this.buildExternalTranscriptProbe(
|
|
28855
|
+
restoredHistory.messages,
|
|
28856
|
+
restoredHistory.sourcePath,
|
|
28857
|
+
restoredHistory.sourceMtimeMs
|
|
28858
|
+
);
|
|
28809
28859
|
return restoredHistory.messages;
|
|
28810
28860
|
}
|
|
28811
28861
|
completionFinalAssistantEvidence(parsedMessages) {
|
|
@@ -28843,6 +28893,9 @@ var CliProviderInstance = class {
|
|
|
28843
28893
|
parseError = error?.message || String(error);
|
|
28844
28894
|
}
|
|
28845
28895
|
const evidence = this.completionFinalAssistantEvidence(parsed?.messages);
|
|
28896
|
+
if (evidence.source === "external-native") {
|
|
28897
|
+
this.recordPendingTranscriptProbe(args.pending);
|
|
28898
|
+
}
|
|
28846
28899
|
const visibleMessages = (Array.isArray(evidence.messages) ? evidence.messages : []).filter((message) => isUserFacingChatMessage(message));
|
|
28847
28900
|
const lastVisible = visibleMessages[visibleMessages.length - 1];
|
|
28848
28901
|
const lastVisibleRole = typeof lastVisible?.role === "string" ? lastVisible.role.trim().toLowerCase() : null;
|
|
@@ -28871,7 +28924,8 @@ var CliProviderInstance = class {
|
|
|
28871
28924
|
pendingFirstObservedAt: args.pending.firstObservedAt,
|
|
28872
28925
|
pendingTimestamp: args.pending.timestamp,
|
|
28873
28926
|
pendingDurationSec: args.pending.duration,
|
|
28874
|
-
previousBlockReason: args.pending.loggedBlockReason || null
|
|
28927
|
+
previousBlockReason: args.pending.loggedBlockReason || null,
|
|
28928
|
+
transcriptProbeHistory: args.pending.transcriptProbeHistory || []
|
|
28875
28929
|
};
|
|
28876
28930
|
}
|
|
28877
28931
|
hasAdapterPendingResponse() {
|
|
@@ -28929,6 +28983,11 @@ var CliProviderInstance = class {
|
|
|
28929
28983
|
if (!finalAssistantEvidence.present) {
|
|
28930
28984
|
if (adapterOwnsMessagesElsewhere) {
|
|
28931
28985
|
if (finalAssistantEvidence.source === "external-native") {
|
|
28986
|
+
const probe = this.recordPendingTranscriptProbe(pending);
|
|
28987
|
+
if (probe && !pending.loggedTranscriptProbe) {
|
|
28988
|
+
LOG.info("CLI", `[${this.type}] external transcript probe: msgCount=${probe.msgCount} lastRole=${probe.lastRole || "none"} lastKind=${probe.lastKind || "none"} contentLen=${probe.contentLen} sourceMtime=${probe.sourceMtimeMs ?? "unknown"} mtimeAge=${probe.mtimeAgeMs ?? "unknown"}ms`);
|
|
28989
|
+
pending.loggedTranscriptProbe = true;
|
|
28990
|
+
}
|
|
28932
28991
|
return { reason: "missing_final_assistant", terminal: true };
|
|
28933
28992
|
}
|
|
28934
28993
|
if (this.provider.requiresFinalAssistantBeforeIdle === true) {
|