@adhdev/daemon-core 0.9.82-rc.87 → 0.9.82-rc.88
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/index.js +95 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +95 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/commands/chat-commands.ts +120 -13
package/package.json
CHANGED
|
@@ -242,6 +242,64 @@ function getMessageNewestReceivedAt(messages: Array<{ receivedAt?: unknown; time
|
|
|
242
242
|
return newest;
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
+
function readHistorySessionIdFromMessages(messages: ChatMessage[]): string | undefined {
|
|
246
|
+
for (const message of messages as Array<ChatMessage & { historySessionId?: unknown }>) {
|
|
247
|
+
const historySessionId = typeof message?.historySessionId === 'string' ? message.historySessionId.trim() : '';
|
|
248
|
+
if (historySessionId) return historySessionId;
|
|
249
|
+
}
|
|
250
|
+
return undefined;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function normalizeNativeHistoryMessages(providerType: string, messages: ChatMessage[]): ChatMessage[] {
|
|
254
|
+
let turnIndex = 0;
|
|
255
|
+
return normalizeChatMessages(messages).map((message, index) => {
|
|
256
|
+
const role = typeof message.role === 'string' ? message.role.trim().toLowerCase() : '';
|
|
257
|
+
const kind = typeof message.kind === 'string' && message.kind.trim() ? message.kind.trim() : (role === 'system' ? 'system' : 'standard');
|
|
258
|
+
if ((role === 'user' || role === 'human') && index > 0) turnIndex += 1;
|
|
259
|
+
const historySessionId = typeof (message as any).historySessionId === 'string'
|
|
260
|
+
? (message as any).historySessionId.trim()
|
|
261
|
+
: '';
|
|
262
|
+
const contentHash = hashSignatureParts([
|
|
263
|
+
providerType,
|
|
264
|
+
historySessionId,
|
|
265
|
+
String(message.receivedAt || message.timestamp || index),
|
|
266
|
+
role,
|
|
267
|
+
kind,
|
|
268
|
+
flattenContent(message.content),
|
|
269
|
+
]).slice(0, 12);
|
|
270
|
+
const providerUnitKey = typeof message.providerUnitKey === 'string' && message.providerUnitKey.trim()
|
|
271
|
+
? message.providerUnitKey.trim()
|
|
272
|
+
: `${providerType}:native:${historySessionId || 'workspace'}:${index}:${role || 'message'}:${kind}:${contentHash}`;
|
|
273
|
+
const meta = message.meta && typeof message.meta === 'object' ? message.meta as Record<string, unknown> : undefined;
|
|
274
|
+
const isSystemSessionStart = role === 'system' || kind === 'system' || kind === 'session_start';
|
|
275
|
+
const isActivity = role === 'assistant' && (kind === 'tool' || kind === 'terminal' || kind === 'thought');
|
|
276
|
+
return {
|
|
277
|
+
...message,
|
|
278
|
+
role: role === 'human' ? 'user' : (role || 'assistant'),
|
|
279
|
+
kind: isSystemSessionStart ? 'system' : kind,
|
|
280
|
+
providerUnitKey,
|
|
281
|
+
bubbleId: typeof message.bubbleId === 'string' && message.bubbleId.trim()
|
|
282
|
+
? message.bubbleId.trim()
|
|
283
|
+
: `bubble:${providerUnitKey}`,
|
|
284
|
+
_turnKey: typeof message._turnKey === 'string' && message._turnKey.trim()
|
|
285
|
+
? message._turnKey.trim()
|
|
286
|
+
: `${providerType}:native-turn:${historySessionId || 'workspace'}:${turnIndex}`,
|
|
287
|
+
bubbleState: message.bubbleState || 'final',
|
|
288
|
+
...(isSystemSessionStart ? {
|
|
289
|
+
visibility: message.visibility || 'hidden',
|
|
290
|
+
transcriptVisibility: message.transcriptVisibility || 'hidden',
|
|
291
|
+
audience: message.audience || 'internal',
|
|
292
|
+
source: message.source || 'runtime_status',
|
|
293
|
+
} : isActivity ? {
|
|
294
|
+
source: message.source || (kind === 'terminal' ? 'terminal_command' : 'tool_call'),
|
|
295
|
+
meta: { ...meta, label: message.senderName || meta?.label || (kind === 'terminal' ? 'Terminal' : 'Tool') },
|
|
296
|
+
} : {
|
|
297
|
+
source: message.source || (role === 'assistant' ? 'assistant_text' : undefined),
|
|
298
|
+
}),
|
|
299
|
+
} as ChatMessage;
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
|
|
245
303
|
function buildCliMessageSourceProvenance(args: {
|
|
246
304
|
selected: 'native-history' | 'pty-parser';
|
|
247
305
|
provider: string;
|
|
@@ -329,6 +387,42 @@ function hasSafeNativeHistoryMapping(args: {
|
|
|
329
387
|
return args.nativeMessages.some((message: any) => String(message?.workspace || '').trim() === workspace);
|
|
330
388
|
}
|
|
331
389
|
|
|
390
|
+
function readCliProviderNativeHistory(agentStr: string, args: {
|
|
391
|
+
canonicalHistory?: ProviderModule['canonicalHistory'];
|
|
392
|
+
historySessionId?: string;
|
|
393
|
+
workspace?: string;
|
|
394
|
+
offset: number;
|
|
395
|
+
limit: number;
|
|
396
|
+
excludeRecentCount: number;
|
|
397
|
+
historyBehavior?: ProviderModule['historyBehavior'];
|
|
398
|
+
scripts?: ProviderScripts;
|
|
399
|
+
}): ReturnType<typeof readProviderChatHistory> & { lookup: 'session' | 'workspace' } {
|
|
400
|
+
const sessionHistory = readProviderChatHistory(agentStr, {
|
|
401
|
+
canonicalHistory: args.canonicalHistory,
|
|
402
|
+
historySessionId: args.historySessionId,
|
|
403
|
+
workspace: args.workspace,
|
|
404
|
+
offset: args.offset,
|
|
405
|
+
limit: args.limit,
|
|
406
|
+
excludeRecentCount: args.excludeRecentCount,
|
|
407
|
+
historyBehavior: args.historyBehavior,
|
|
408
|
+
scripts: args.scripts as any,
|
|
409
|
+
});
|
|
410
|
+
if ((sessionHistory as any).source !== 'native-unavailable' || !args.historySessionId || !args.workspace) {
|
|
411
|
+
return { ...(sessionHistory as any), lookup: 'session' };
|
|
412
|
+
}
|
|
413
|
+
const workspaceHistory = readProviderChatHistory(agentStr, {
|
|
414
|
+
canonicalHistory: args.canonicalHistory,
|
|
415
|
+
historySessionId: undefined,
|
|
416
|
+
workspace: args.workspace,
|
|
417
|
+
offset: args.offset,
|
|
418
|
+
limit: args.limit,
|
|
419
|
+
excludeRecentCount: args.excludeRecentCount,
|
|
420
|
+
historyBehavior: args.historyBehavior,
|
|
421
|
+
scripts: args.scripts as any,
|
|
422
|
+
});
|
|
423
|
+
return { ...(workspaceHistory as any), lookup: 'workspace' };
|
|
424
|
+
}
|
|
425
|
+
|
|
332
426
|
function isNativeHistoryFreshEnough(args: {
|
|
333
427
|
sourceMtimeMs?: number;
|
|
334
428
|
nativeMessages: ChatMessage[];
|
|
@@ -1069,9 +1163,9 @@ export async function handleReadChat(h: CommandHelpers, args: any): Promise<Comm
|
|
|
1069
1163
|
returnedMessages.length,
|
|
1070
1164
|
200,
|
|
1071
1165
|
);
|
|
1072
|
-
let nativeHistory: ReturnType<typeof readProviderChatHistory> | null = null;
|
|
1166
|
+
let nativeHistory: (ReturnType<typeof readProviderChatHistory> & { lookup?: 'session' | 'workspace' }) | null = null;
|
|
1073
1167
|
try {
|
|
1074
|
-
nativeHistory =
|
|
1168
|
+
nativeHistory = readCliProviderNativeHistory(agentStr, {
|
|
1075
1169
|
canonicalHistory: provider?.canonicalHistory,
|
|
1076
1170
|
historySessionId,
|
|
1077
1171
|
workspace,
|
|
@@ -1096,14 +1190,15 @@ export async function handleReadChat(h: CommandHelpers, args: any): Promise<Comm
|
|
|
1096
1190
|
|
|
1097
1191
|
if (nativeHistory) {
|
|
1098
1192
|
const nativeMessages = Array.isArray((nativeHistory as any).messages)
|
|
1099
|
-
?
|
|
1193
|
+
? normalizeNativeHistoryMessages(agentStr, (nativeHistory as any).messages as ChatMessage[])
|
|
1100
1194
|
: [];
|
|
1101
1195
|
const historyProviderSessionId = typeof (nativeHistory as any)?.providerSessionId === 'string'
|
|
1102
1196
|
? (nativeHistory as any).providerSessionId
|
|
1103
|
-
: historySessionId;
|
|
1197
|
+
: readHistorySessionIdFromMessages(nativeMessages) || historySessionId;
|
|
1198
|
+
const lookup = (nativeHistory as any).lookup === 'workspace' ? 'workspace' : 'session';
|
|
1104
1199
|
const safeMapping = hasSafeNativeHistoryMapping({
|
|
1105
|
-
historySessionId,
|
|
1106
|
-
providerSessionId,
|
|
1200
|
+
historySessionId: lookup === 'workspace' ? undefined : historySessionId,
|
|
1201
|
+
providerSessionId: lookup === 'workspace' ? undefined : providerSessionId,
|
|
1107
1202
|
workspace,
|
|
1108
1203
|
nativeMessages,
|
|
1109
1204
|
});
|
|
@@ -1191,7 +1286,18 @@ export async function handleReadChat(h: CommandHelpers, args: any): Promise<Comm
|
|
|
1191
1286
|
: typeof (h.currentSession as any)?.workspace === 'string'
|
|
1192
1287
|
? (h.currentSession as any).workspace
|
|
1193
1288
|
: undefined;
|
|
1194
|
-
const history =
|
|
1289
|
+
const history = supportsCliNativeTranscript(agentStr, provider) && isNativeSourceCanonicalHistory(provider?.canonicalHistory)
|
|
1290
|
+
? readCliProviderNativeHistory(agentStr, {
|
|
1291
|
+
canonicalHistory: provider?.canonicalHistory,
|
|
1292
|
+
historySessionId,
|
|
1293
|
+
workspace,
|
|
1294
|
+
offset: 0,
|
|
1295
|
+
limit: historyLimit,
|
|
1296
|
+
excludeRecentCount: 0,
|
|
1297
|
+
historyBehavior: provider?.historyBehavior,
|
|
1298
|
+
scripts: provider?.scripts as any,
|
|
1299
|
+
})
|
|
1300
|
+
: readProviderChatHistory(agentStr, {
|
|
1195
1301
|
canonicalHistory: provider?.canonicalHistory,
|
|
1196
1302
|
historySessionId,
|
|
1197
1303
|
workspace,
|
|
@@ -1201,16 +1307,17 @@ export async function handleReadChat(h: CommandHelpers, args: any): Promise<Comm
|
|
|
1201
1307
|
historyBehavior: provider?.historyBehavior,
|
|
1202
1308
|
scripts: provider?.scripts as any,
|
|
1203
1309
|
});
|
|
1204
|
-
const
|
|
1205
|
-
? (history as any).providerSessionId
|
|
1206
|
-
: historySessionId;
|
|
1310
|
+
const lookup = (history as any).lookup === 'workspace' ? 'workspace' : 'session';
|
|
1207
1311
|
const historyMessages = Array.isArray((history as any)?.messages)
|
|
1208
|
-
?
|
|
1312
|
+
? normalizeNativeHistoryMessages(agentStr, (history as any).messages as ChatMessage[])
|
|
1209
1313
|
: [];
|
|
1314
|
+
const historyProviderSessionId = typeof (history as any)?.providerSessionId === 'string'
|
|
1315
|
+
? (history as any).providerSessionId
|
|
1316
|
+
: readHistorySessionIdFromMessages(historyMessages) || historySessionId;
|
|
1210
1317
|
const safeMapping = supportsCliNativeTranscript(agentStr, provider)
|
|
1211
1318
|
? hasSafeNativeHistoryMapping({
|
|
1212
|
-
historySessionId,
|
|
1213
|
-
providerSessionId: historyProviderSessionId,
|
|
1319
|
+
historySessionId: lookup === 'workspace' ? undefined : historySessionId,
|
|
1320
|
+
providerSessionId: lookup === 'workspace' ? undefined : historyProviderSessionId,
|
|
1214
1321
|
workspace,
|
|
1215
1322
|
nativeMessages: historyMessages,
|
|
1216
1323
|
})
|