@adhdev/daemon-core 0.9.82-rc.111 → 0.9.82-rc.113
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/chat/subscription-updates.d.ts +1 -0
- package/dist/index.js +91 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +91 -15
- package/dist/index.mjs.map +1 -1
- package/dist/providers/cli-provider-instance.d.ts +2 -0
- package/package.json +1 -1
- package/src/chat/subscription-updates.ts +5 -1
- package/src/commands/chat-commands.ts +49 -10
- package/src/config/recent-activity.ts +8 -2
- package/src/providers/cli-provider-instance.ts +61 -13
|
@@ -5,6 +5,7 @@ export interface ChatTailSubscriptionCursor {
|
|
|
5
5
|
export type SessionChatTailCommandResult = Partial<Omit<ReadChatSyncResult, 'activeModal'>> & {
|
|
6
6
|
success?: boolean;
|
|
7
7
|
activeModal?: unknown;
|
|
8
|
+
messagesTail?: unknown;
|
|
8
9
|
};
|
|
9
10
|
export interface PrepareSessionChatTailUpdateInput {
|
|
10
11
|
key: string;
|
package/dist/index.js
CHANGED
|
@@ -8799,11 +8799,17 @@ function buildSessionReadStateKey(sessionId, providerSessionId) {
|
|
|
8799
8799
|
}
|
|
8800
8800
|
function getSessionSeenAt(state, sessionId, providerSessionId) {
|
|
8801
8801
|
const providerKey = buildSessionReadStateKey(sessionId, providerSessionId);
|
|
8802
|
-
return state.sessionReads?.[providerKey] || state.sessionReads?.[sessionId] || 0;
|
|
8802
|
+
return Math.max(state.sessionReads?.[providerKey] || 0, state.sessionReads?.[sessionId] || 0);
|
|
8803
8803
|
}
|
|
8804
8804
|
function getSessionSeenMarker(state, sessionId, providerSessionId) {
|
|
8805
8805
|
const providerKey = buildSessionReadStateKey(sessionId, providerSessionId);
|
|
8806
|
-
|
|
8806
|
+
const providerSeenAt = state.sessionReads?.[providerKey] || 0;
|
|
8807
|
+
const sessionSeenAt = state.sessionReads?.[sessionId] || 0;
|
|
8808
|
+
const providerMarker = state.sessionReadMarkers?.[providerKey] || "";
|
|
8809
|
+
const sessionMarker = state.sessionReadMarkers?.[sessionId] || "";
|
|
8810
|
+
if (sessionSeenAt > providerSeenAt && sessionMarker) return sessionMarker;
|
|
8811
|
+
if (providerSeenAt > sessionSeenAt && providerMarker) return providerMarker;
|
|
8812
|
+
return providerMarker || sessionMarker;
|
|
8807
8813
|
}
|
|
8808
8814
|
function getSessionNotificationDismissal(state, sessionId, providerSessionId) {
|
|
8809
8815
|
const providerKey = buildSessionReadStateKey(sessionId, providerSessionId);
|
|
@@ -17195,7 +17201,20 @@ async function handleChatHistory(h, args) {
|
|
|
17195
17201
|
if (visibleCount > excludeRecentCount) excludeRecentCount = visibleCount;
|
|
17196
17202
|
}
|
|
17197
17203
|
const workspace = typeof args?.workspace === "string" ? args.workspace : typeof h.currentSession?.workspace === "string" ? h.currentSession.workspace : void 0;
|
|
17198
|
-
const
|
|
17204
|
+
const exactNativeHistoryScope = Boolean(
|
|
17205
|
+
typeof args?.targetSessionId === "string" && args.targetSessionId.trim() || typeof args?.historySessionId === "string" && args.historySessionId.trim() || typeof args?.providerSessionId === "string" && args.providerSessionId.trim()
|
|
17206
|
+
);
|
|
17207
|
+
const result = supportsCliNativeTranscript(agentStr, provider) && isNativeSourceCanonicalHistory(provider?.canonicalHistory) ? readCliProviderNativeHistory(agentStr, {
|
|
17208
|
+
canonicalHistory: provider?.canonicalHistory,
|
|
17209
|
+
historySessionId,
|
|
17210
|
+
workspace,
|
|
17211
|
+
offset: offset || 0,
|
|
17212
|
+
limit: limit || 30,
|
|
17213
|
+
excludeRecentCount,
|
|
17214
|
+
historyBehavior: provider?.historyBehavior,
|
|
17215
|
+
scripts: provider?.scripts,
|
|
17216
|
+
exactSessionScoped: exactNativeHistoryScope
|
|
17217
|
+
}) : readProviderChatHistory(agentStr, {
|
|
17199
17218
|
canonicalHistory: provider?.canonicalHistory,
|
|
17200
17219
|
historySessionId,
|
|
17201
17220
|
workspace,
|
|
@@ -17205,6 +17224,26 @@ async function handleChatHistory(h, args) {
|
|
|
17205
17224
|
historyBehavior: provider?.historyBehavior,
|
|
17206
17225
|
scripts: provider?.scripts
|
|
17207
17226
|
});
|
|
17227
|
+
if (supportsCliNativeTranscript(agentStr, provider) && isNativeSourceCanonicalHistory(provider?.canonicalHistory)) {
|
|
17228
|
+
const lookup = result.lookup === "workspace" ? "workspace" : "session";
|
|
17229
|
+
const messages = Array.isArray(result.messages) ? normalizeNativeHistoryMessages(agentStr, result.messages) : [];
|
|
17230
|
+
const historyProviderSessionId = typeof result?.providerSessionId === "string" ? result.providerSessionId : readHistorySessionIdFromMessages(messages) || historySessionId;
|
|
17231
|
+
const safeMapping = hasSafeNativeHistoryMapping({
|
|
17232
|
+
historySessionId: lookup === "workspace" ? void 0 : historySessionId,
|
|
17233
|
+
providerSessionId: lookup === "workspace" ? void 0 : historyProviderSessionId,
|
|
17234
|
+
workspace,
|
|
17235
|
+
nativeMessages: messages
|
|
17236
|
+
});
|
|
17237
|
+
if (result.source === "provider-native" && messages.length > 0 && !safeMapping) {
|
|
17238
|
+
return {
|
|
17239
|
+
success: true,
|
|
17240
|
+
messages: [],
|
|
17241
|
+
hasMore: false,
|
|
17242
|
+
source: "native-unavailable",
|
|
17243
|
+
agent: agentStr
|
|
17244
|
+
};
|
|
17245
|
+
}
|
|
17246
|
+
}
|
|
17208
17247
|
return { success: true, ...result, agent: agentStr };
|
|
17209
17248
|
} catch (e) {
|
|
17210
17249
|
return { success: false, error: e.message };
|
|
@@ -19836,6 +19875,16 @@ function normalizeProviderSessionId(provider, providerSessionId) {
|
|
|
19836
19875
|
}
|
|
19837
19876
|
|
|
19838
19877
|
// src/providers/cli-provider-instance.ts
|
|
19878
|
+
function isIdleStatus(value) {
|
|
19879
|
+
const status = typeof value === "string" ? value.trim().toLowerCase() : "";
|
|
19880
|
+
return !status || status === "idle" || status === "ready";
|
|
19881
|
+
}
|
|
19882
|
+
function getMessageTime(message) {
|
|
19883
|
+
if (!message || typeof message !== "object") return 0;
|
|
19884
|
+
const record = message;
|
|
19885
|
+
const value = Number(record.receivedAt ?? record.timestamp ?? 0);
|
|
19886
|
+
return Number.isFinite(value) ? value : 0;
|
|
19887
|
+
}
|
|
19839
19888
|
var COMPLETED_FINALIZATION_RETRY_MS = 1e3;
|
|
19840
19889
|
var COMPLETED_FINALIZATION_MAX_WAIT_MS = 3e4;
|
|
19841
19890
|
var IMAGE_MIME_EXTENSIONS = {
|
|
@@ -20097,7 +20146,7 @@ var CliProviderInstance = class {
|
|
|
20097
20146
|
await this.adapter.spawn();
|
|
20098
20147
|
await this.enforceFreshSessionLaunchIfNeeded();
|
|
20099
20148
|
this.maybeAppendRuntimeRecoveryMessage(this.adapter.getRuntimeMetadata());
|
|
20100
|
-
if (this.providerSessionId) {
|
|
20149
|
+
if (this.providerSessionId && this.shouldHydrateExistingProviderHistory()) {
|
|
20101
20150
|
this.restorePersistedHistoryFromCurrentSession();
|
|
20102
20151
|
}
|
|
20103
20152
|
if (this.providerSessionId && this.launchMode === "resume") {
|
|
@@ -20179,28 +20228,37 @@ var CliProviderInstance = class {
|
|
|
20179
20228
|
this.provider,
|
|
20180
20229
|
typeof adapterStatus?.providerSessionId === "string" ? adapterStatus.providerSessionId : ""
|
|
20181
20230
|
);
|
|
20182
|
-
if (adapterProviderSessionId) {
|
|
20183
|
-
this.promoteProviderSessionId(adapterProviderSessionId);
|
|
20184
|
-
}
|
|
20185
20231
|
const autoApproveActive = this.maybeAutoApproveStatus(adapterStatus, Date.now());
|
|
20186
20232
|
const visibleStatus = parseErrorMessage || parsedStatus?.status === "error" ? "error" : autoApproveActive ? "generating" : adapterStatus.status;
|
|
20233
|
+
const runtime = this.adapter.getRuntimeMetadata();
|
|
20234
|
+
this.maybeAppendRuntimeRecoveryMessage(runtime);
|
|
20235
|
+
let parsedMessages = Array.isArray(parsedStatus?.messages) ? parsedStatus.messages : [];
|
|
20187
20236
|
const parsedProviderSessionId = normalizeProviderSessionId(
|
|
20188
20237
|
this.provider,
|
|
20189
20238
|
typeof parsedStatus?.providerSessionId === "string" ? parsedStatus.providerSessionId : ""
|
|
20190
20239
|
);
|
|
20191
|
-
|
|
20240
|
+
const suppressFreshLaunchStartupReplay = this.shouldSuppressFreshLaunchStartupReplay(
|
|
20241
|
+
parsedMessages,
|
|
20242
|
+
parsedStatus,
|
|
20243
|
+
adapterStatus,
|
|
20244
|
+
parsedProviderSessionId
|
|
20245
|
+
);
|
|
20246
|
+
if (adapterProviderSessionId && !suppressFreshLaunchStartupReplay) {
|
|
20247
|
+
this.promoteProviderSessionId(adapterProviderSessionId);
|
|
20248
|
+
}
|
|
20249
|
+
if (parsedProviderSessionId && !suppressFreshLaunchStartupReplay) {
|
|
20192
20250
|
this.promoteProviderSessionId(parsedProviderSessionId);
|
|
20193
20251
|
}
|
|
20194
|
-
|
|
20195
|
-
|
|
20252
|
+
if (suppressFreshLaunchStartupReplay) {
|
|
20253
|
+
parsedMessages = [];
|
|
20254
|
+
}
|
|
20196
20255
|
const activeChatId = this.providerSessionId || runtime?.runtimeId || this.instanceId;
|
|
20197
|
-
let parsedMessages = Array.isArray(parsedStatus?.messages) ? parsedStatus.messages : [];
|
|
20198
20256
|
const historyMessageCount = Number.isFinite(parsedStatus?.historyMessageCount) ? Math.max(0, Number(parsedStatus.historyMessageCount)) : null;
|
|
20199
20257
|
if (historyMessageCount !== null) {
|
|
20200
20258
|
parsedMessages = historyMessageCount > 0 ? parsedMessages.slice(-historyMessageCount) : [];
|
|
20201
20259
|
}
|
|
20202
20260
|
const mergedMessages = this.mergeConversationMessages(parsedMessages);
|
|
20203
|
-
const canonicalBackedHistory = this.syncCanonicalSavedHistoryIfNeeded();
|
|
20261
|
+
const canonicalBackedHistory = this.shouldHydrateExistingProviderHistory() ? this.syncCanonicalSavedHistoryIfNeeded() : false;
|
|
20204
20262
|
const statusMessages = canonicalBackedHistory && this.lastPersistedHistoryMessages.length > 0 ? this.lastPersistedHistoryMessages.map((message) => ({
|
|
20205
20263
|
role: message.role,
|
|
20206
20264
|
content: message.content,
|
|
@@ -20243,7 +20301,10 @@ var CliProviderInstance = class {
|
|
|
20243
20301
|
this.lastPersistedHistoryMessages = normalizedMessagesToSave;
|
|
20244
20302
|
}
|
|
20245
20303
|
}
|
|
20246
|
-
this.applyProviderResponse(
|
|
20304
|
+
this.applyProviderResponse(
|
|
20305
|
+
suppressFreshLaunchStartupReplay && parsedStatus && typeof parsedStatus === "object" ? { ...parsedStatus, providerSessionId: void 0 } : parsedStatus,
|
|
20306
|
+
{ phase: "immediate" }
|
|
20307
|
+
);
|
|
20247
20308
|
const surface = resolveProviderStateSurface({
|
|
20248
20309
|
summaryMetadata: this.summaryMetadata,
|
|
20249
20310
|
controlValues: this.controlValues
|
|
@@ -20995,7 +21056,9 @@ ${effect.notification.body || ""}`.trim();
|
|
|
20995
21056
|
this.providerSessionId = nextSessionId;
|
|
20996
21057
|
this.historyWriter.promoteHistorySession(this.type, previousHistorySessionId, nextSessionId);
|
|
20997
21058
|
this.historyWriter.writeSessionStart(this.type, nextSessionId, this.workingDir, this.instanceId);
|
|
20998
|
-
this.
|
|
21059
|
+
if (this.shouldHydrateExistingProviderHistory()) {
|
|
21060
|
+
this.restorePersistedHistoryFromCurrentSession();
|
|
21061
|
+
}
|
|
20999
21062
|
this.adapter.updateRuntimeMeta({ providerSessionId: nextSessionId });
|
|
21000
21063
|
this.onProviderSessionResolved?.({
|
|
21001
21064
|
instanceId: this.instanceId,
|
|
@@ -21007,6 +21070,18 @@ ${effect.notification.body || ""}`.trim();
|
|
|
21007
21070
|
});
|
|
21008
21071
|
LOG.info("CLI", `[${this.type}] discovered provider session id: ${nextSessionId}`);
|
|
21009
21072
|
}
|
|
21073
|
+
shouldHydrateExistingProviderHistory() {
|
|
21074
|
+
return this.launchMode === "resume" || this.launchMode === "manual";
|
|
21075
|
+
}
|
|
21076
|
+
shouldSuppressFreshLaunchStartupReplay(parsedMessages, parsedStatus, adapterStatus, parsedProviderSessionId = "") {
|
|
21077
|
+
if (this.launchMode !== "new") return false;
|
|
21078
|
+
if (this.providerSessionId) return false;
|
|
21079
|
+
if (!Array.isArray(parsedMessages) || parsedMessages.length === 0) return false;
|
|
21080
|
+
if (!isIdleStatus(adapterStatus?.status) || !isIdleStatus(parsedStatus?.status)) return false;
|
|
21081
|
+
if (parsedProviderSessionId) return true;
|
|
21082
|
+
const newestMessageAt = parsedMessages.reduce((newest, message) => Math.max(newest, getMessageTime(message)), 0);
|
|
21083
|
+
return newestMessageAt === 0;
|
|
21084
|
+
}
|
|
21010
21085
|
syncCanonicalSavedHistoryIfNeeded() {
|
|
21011
21086
|
if (!this.providerSessionId) return false;
|
|
21012
21087
|
const canonicalHistory = this.provider.canonicalHistory;
|
|
@@ -31590,7 +31665,8 @@ function prepareSessionChatTailUpdate(input) {
|
|
|
31590
31665
|
update: null
|
|
31591
31666
|
};
|
|
31592
31667
|
}
|
|
31593
|
-
const
|
|
31668
|
+
const rawMessages = Array.isArray(result.messages) ? result.messages : Array.isArray(result.messagesTail) ? result.messagesTail : [];
|
|
31669
|
+
const fullMessages = normalizeChatMessages(rawMessages);
|
|
31594
31670
|
const messages = fullMessages;
|
|
31595
31671
|
const title = typeof result.title === "string" ? result.title : void 0;
|
|
31596
31672
|
const activeModal = normalizeChatTailActiveModal(result.activeModal);
|