@adhdev/daemon-core 0.9.82-rc.176 → 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
|
@@ -113,6 +113,7 @@ export declare function readProviderChatHistory(agentType: string, options?: {
|
|
|
113
113
|
excludeInProgressTurn?: boolean;
|
|
114
114
|
sessionStartedAtMs?: number;
|
|
115
115
|
envOverrides?: Record<string, string>;
|
|
116
|
+
forceRefresh?: boolean;
|
|
116
117
|
}): {
|
|
117
118
|
messages: HistoryMessage[];
|
|
118
119
|
hasMore: boolean;
|
package/dist/index.js
CHANGED
|
@@ -12719,6 +12719,12 @@ function createNativeHistoryDispatcher(reader) {
|
|
|
12719
12719
|
const requestedProviderSid = input.providerSessionId || "";
|
|
12720
12720
|
const sourcePath = resolveSourcePath(reader, workspace, sessionId);
|
|
12721
12721
|
if (!sourcePath) return null;
|
|
12722
|
+
if (input.forceRefresh === true || input.args?.forceRefresh === true) {
|
|
12723
|
+
try {
|
|
12724
|
+
fs18.statSync(sourcePath);
|
|
12725
|
+
} catch {
|
|
12726
|
+
}
|
|
12727
|
+
}
|
|
12722
12728
|
const session = readByReader(reader, sourcePath, sessionId, workspace);
|
|
12723
12729
|
if (!session) return null;
|
|
12724
12730
|
if (requestedProviderSid && session.providerSessionId && session.providerSessionId !== requestedProviderSid) {
|
|
@@ -19673,7 +19679,7 @@ function normalizeProviderNativeHistoryRecords(agentType, historySessionId, reco
|
|
|
19673
19679
|
return sanitizeHistoryMessage(agentType, base);
|
|
19674
19680
|
}).filter(Boolean);
|
|
19675
19681
|
}
|
|
19676
|
-
function callProviderNativeHistoryRead(agentType, canonicalHistory, scripts, historySessionId, workspace, excludeInProgressTurn, sessionStartedAtMs, envOverrides) {
|
|
19682
|
+
function callProviderNativeHistoryRead(agentType, canonicalHistory, scripts, historySessionId, workspace, excludeInProgressTurn, sessionStartedAtMs, envOverrides, forceRefresh) {
|
|
19677
19683
|
const fn = getProviderNativeHistoryScript(scripts, canonicalHistory, "readSession");
|
|
19678
19684
|
if (!fn) return null;
|
|
19679
19685
|
const normalizedSessionId = normalizeSavedHistorySessionId(historySessionId || "");
|
|
@@ -19687,7 +19693,8 @@ function callProviderNativeHistoryRead(agentType, canonicalHistory, scripts, his
|
|
|
19687
19693
|
excludeInProgressTurn: excludeInProgressTurn === true,
|
|
19688
19694
|
sessionStartedAtMs,
|
|
19689
19695
|
envOverrides,
|
|
19690
|
-
|
|
19696
|
+
forceRefresh: forceRefresh === true,
|
|
19697
|
+
args: { sessionId: normalizedSessionId, historySessionId: normalizedSessionId, workspace, excludeInProgressTurn: excludeInProgressTurn === true, sessionStartedAtMs, envOverrides, forceRefresh: forceRefresh === true }
|
|
19691
19698
|
});
|
|
19692
19699
|
if (!result || typeof result !== "object") return null;
|
|
19693
19700
|
const records = normalizeProviderNativeHistoryRecords(agentType, normalizedSessionId, result.messages || result.records);
|
|
@@ -19702,11 +19709,11 @@ function callProviderNativeHistoryRead(agentType, canonicalHistory, scripts, his
|
|
|
19702
19709
|
unavailableReason: typeof result.unavailableReason === "string" ? result.unavailableReason.trim() : void 0
|
|
19703
19710
|
};
|
|
19704
19711
|
}
|
|
19705
|
-
function buildNativeHistoryReadResult(agentType, canonicalHistory, scripts, historySessionId, workspace, excludeInProgressTurn, sessionStartedAtMs, envOverrides) {
|
|
19712
|
+
function buildNativeHistoryReadResult(agentType, canonicalHistory, scripts, historySessionId, workspace, excludeInProgressTurn, sessionStartedAtMs, envOverrides, forceRefresh) {
|
|
19706
19713
|
const normalizedSessionId = normalizeSavedHistorySessionId(historySessionId || "");
|
|
19707
19714
|
const normalizedWorkspace = typeof workspace === "string" ? workspace.trim() : "";
|
|
19708
19715
|
if (!canonicalHistory || !normalizedSessionId && !normalizedWorkspace || !isNativeSourceCanonicalHistory(canonicalHistory)) return null;
|
|
19709
|
-
return callProviderNativeHistoryRead(agentType, canonicalHistory, scripts, normalizedSessionId, workspace, excludeInProgressTurn, sessionStartedAtMs, envOverrides);
|
|
19716
|
+
return callProviderNativeHistoryRead(agentType, canonicalHistory, scripts, normalizedSessionId, workspace, excludeInProgressTurn, sessionStartedAtMs, envOverrides, forceRefresh);
|
|
19710
19717
|
}
|
|
19711
19718
|
function materializeNativeHistoryToMirror(agentType, canonicalHistory, historySessionId, workspace, scripts) {
|
|
19712
19719
|
const normalizedSessionId = normalizeSavedHistorySessionId(historySessionId);
|
|
@@ -19735,7 +19742,7 @@ function isNativeSourceCanonicalHistory(canonicalHistory) {
|
|
|
19735
19742
|
}
|
|
19736
19743
|
function readProviderChatHistory(agentType, options = {}) {
|
|
19737
19744
|
if (isNativeSourceCanonicalHistory(options.canonicalHistory) && (options.historySessionId || options.workspace)) {
|
|
19738
|
-
const nativeResult = buildNativeHistoryReadResult(agentType, options.canonicalHistory, options.scripts, options.historySessionId, options.workspace, options.excludeInProgressTurn, options.sessionStartedAtMs, options.envOverrides);
|
|
19745
|
+
const nativeResult = buildNativeHistoryReadResult(agentType, options.canonicalHistory, options.scripts, options.historySessionId, options.workspace, options.excludeInProgressTurn, options.sessionStartedAtMs, options.envOverrides, options.forceRefresh);
|
|
19739
19746
|
if (!nativeResult) return { messages: [], hasMore: false, source: "native-unavailable" };
|
|
19740
19747
|
return {
|
|
19741
19748
|
...pageHistoryRecords(agentType, nativeResult.records, options.offset || 0, options.limit || 30, options.excludeRecentCount || 0, options.historyBehavior),
|
|
@@ -29068,6 +29075,7 @@ var CliProviderInstance = class {
|
|
|
29068
29075
|
}
|
|
29069
29076
|
completedDebounceTimer = null;
|
|
29070
29077
|
completedDebouncePending = null;
|
|
29078
|
+
lastExternalCompletionProbe = null;
|
|
29071
29079
|
async enforceFreshSessionLaunchIfNeeded() {
|
|
29072
29080
|
const scriptName = getForcedNewSessionScriptName(this.provider, this.launchMode);
|
|
29073
29081
|
if (!scriptName) return;
|
|
@@ -29100,11 +29108,44 @@ var CliProviderInstance = class {
|
|
|
29100
29108
|
if (looksLikeActiveApprovalPromptText(content)) return false;
|
|
29101
29109
|
return true;
|
|
29102
29110
|
}
|
|
29111
|
+
buildExternalTranscriptProbe(messages, sourcePath, sourceMtimeMs) {
|
|
29112
|
+
const visibleMessages = messages.filter((message) => isUserFacingChatMessage(message));
|
|
29113
|
+
const lastVisible = visibleMessages[visibleMessages.length - 1];
|
|
29114
|
+
const readAt = Date.now();
|
|
29115
|
+
const mtimeMs = Number(sourceMtimeMs) || 0;
|
|
29116
|
+
return {
|
|
29117
|
+
readAt,
|
|
29118
|
+
msgCount: messages.length,
|
|
29119
|
+
lastRole: typeof lastVisible?.role === "string" ? lastVisible.role.trim().toLowerCase() : null,
|
|
29120
|
+
lastKind: typeof lastVisible?.kind === "string" ? lastVisible.kind : null,
|
|
29121
|
+
contentLen: lastVisible ? flattenContent(lastVisible.content).trim().length : 0,
|
|
29122
|
+
sourcePath: typeof sourcePath === "string" && sourcePath ? sourcePath : null,
|
|
29123
|
+
sourceMtimeMs: mtimeMs || null,
|
|
29124
|
+
mtimeAgeMs: mtimeMs ? Math.max(0, readAt - mtimeMs) : null
|
|
29125
|
+
};
|
|
29126
|
+
}
|
|
29127
|
+
recordPendingTranscriptProbe(pending) {
|
|
29128
|
+
const probe = this.lastExternalCompletionProbe;
|
|
29129
|
+
if (!probe) return null;
|
|
29130
|
+
const history = pending.transcriptProbeHistory || [];
|
|
29131
|
+
const last = history[history.length - 1];
|
|
29132
|
+
if (!last || last.readAt !== probe.readAt || last.msgCount !== probe.msgCount || last.lastRole !== probe.lastRole || last.contentLen !== probe.contentLen) {
|
|
29133
|
+
history.push(probe);
|
|
29134
|
+
pending.transcriptProbeHistory = history.slice(-5);
|
|
29135
|
+
}
|
|
29136
|
+
return probe;
|
|
29137
|
+
}
|
|
29103
29138
|
readExternalCompletionMessages() {
|
|
29104
29139
|
const adapterOwnsMessagesElsewhere = this.adapter?.chatMessagesOwnedExternally === true;
|
|
29105
29140
|
if (!adapterOwnsMessagesElsewhere) return null;
|
|
29106
29141
|
if (!this.providerSessionId) return null;
|
|
29107
29142
|
if (!isNativeSourceCanonicalHistory(this.provider.nativeHistory)) return null;
|
|
29143
|
+
if (this.lastExternalCompletionProbe?.sourcePath) {
|
|
29144
|
+
try {
|
|
29145
|
+
fs12.statSync(this.lastExternalCompletionProbe.sourcePath);
|
|
29146
|
+
} catch {
|
|
29147
|
+
}
|
|
29148
|
+
}
|
|
29108
29149
|
const restoredHistory = readProviderChatHistory(this.type, {
|
|
29109
29150
|
canonicalHistory: this.provider.nativeHistory,
|
|
29110
29151
|
historySessionId: this.providerSessionId,
|
|
@@ -29113,9 +29154,18 @@ var CliProviderInstance = class {
|
|
|
29113
29154
|
limit: Number.MAX_SAFE_INTEGER,
|
|
29114
29155
|
historyBehavior: this.provider.historyBehavior,
|
|
29115
29156
|
scripts: this.provider.scripts,
|
|
29116
|
-
sessionStartedAtMs: this.startedAt
|
|
29157
|
+
sessionStartedAtMs: this.startedAt,
|
|
29158
|
+
forceRefresh: true
|
|
29117
29159
|
});
|
|
29118
|
-
if (restoredHistory.source !== "provider-native")
|
|
29160
|
+
if (restoredHistory.source !== "provider-native") {
|
|
29161
|
+
this.lastExternalCompletionProbe = null;
|
|
29162
|
+
return null;
|
|
29163
|
+
}
|
|
29164
|
+
this.lastExternalCompletionProbe = this.buildExternalTranscriptProbe(
|
|
29165
|
+
restoredHistory.messages,
|
|
29166
|
+
restoredHistory.sourcePath,
|
|
29167
|
+
restoredHistory.sourceMtimeMs
|
|
29168
|
+
);
|
|
29119
29169
|
return restoredHistory.messages;
|
|
29120
29170
|
}
|
|
29121
29171
|
completionFinalAssistantEvidence(parsedMessages) {
|
|
@@ -29153,6 +29203,9 @@ var CliProviderInstance = class {
|
|
|
29153
29203
|
parseError = error?.message || String(error);
|
|
29154
29204
|
}
|
|
29155
29205
|
const evidence = this.completionFinalAssistantEvidence(parsed?.messages);
|
|
29206
|
+
if (evidence.source === "external-native") {
|
|
29207
|
+
this.recordPendingTranscriptProbe(args.pending);
|
|
29208
|
+
}
|
|
29156
29209
|
const visibleMessages = (Array.isArray(evidence.messages) ? evidence.messages : []).filter((message) => isUserFacingChatMessage(message));
|
|
29157
29210
|
const lastVisible = visibleMessages[visibleMessages.length - 1];
|
|
29158
29211
|
const lastVisibleRole = typeof lastVisible?.role === "string" ? lastVisible.role.trim().toLowerCase() : null;
|
|
@@ -29181,7 +29234,8 @@ var CliProviderInstance = class {
|
|
|
29181
29234
|
pendingFirstObservedAt: args.pending.firstObservedAt,
|
|
29182
29235
|
pendingTimestamp: args.pending.timestamp,
|
|
29183
29236
|
pendingDurationSec: args.pending.duration,
|
|
29184
|
-
previousBlockReason: args.pending.loggedBlockReason || null
|
|
29237
|
+
previousBlockReason: args.pending.loggedBlockReason || null,
|
|
29238
|
+
transcriptProbeHistory: args.pending.transcriptProbeHistory || []
|
|
29185
29239
|
};
|
|
29186
29240
|
}
|
|
29187
29241
|
hasAdapterPendingResponse() {
|
|
@@ -29239,6 +29293,11 @@ var CliProviderInstance = class {
|
|
|
29239
29293
|
if (!finalAssistantEvidence.present) {
|
|
29240
29294
|
if (adapterOwnsMessagesElsewhere) {
|
|
29241
29295
|
if (finalAssistantEvidence.source === "external-native") {
|
|
29296
|
+
const probe = this.recordPendingTranscriptProbe(pending);
|
|
29297
|
+
if (probe && !pending.loggedTranscriptProbe) {
|
|
29298
|
+
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`);
|
|
29299
|
+
pending.loggedTranscriptProbe = true;
|
|
29300
|
+
}
|
|
29242
29301
|
return { reason: "missing_final_assistant", terminal: true };
|
|
29243
29302
|
}
|
|
29244
29303
|
if (this.provider.requiresFinalAssistantBeforeIdle === true) {
|