evolcore 0.0.40 → 0.0.41-test.0
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/CHANGELOG.md +45 -1
- package/bin/codex-managed-hook.mjs +11 -0
- package/bin/ec-safe-output.js +11 -1
- package/dist/agents/claude-runner.js +21 -106
- package/dist/agents/codex-runner.js +451 -231
- package/dist/agents/ecagent-runner.js +30 -11
- package/dist/agents/gemini-runner.js +26 -6
- package/dist/agents/runner-types.js +11 -3
- package/dist/aun/ability-device-routing.js +26 -0
- package/dist/aun/aid/client.js +1 -1
- package/dist/aun/group/identity.js +8 -0
- package/dist/aun/msg/managed-operation.js +4 -4
- package/dist/aun/msg/p2p.js +27 -7
- package/dist/aun/storage/download.js +30 -0
- package/dist/aun/storage/index.js +14 -6
- package/dist/channels/aun.js +33 -4
- package/dist/channels/daemon.js +24 -4
- package/dist/cli/agent-command.js +2 -0
- package/dist/cli/agent-create.js +98 -19
- package/dist/cli/agent.js +10 -3
- package/dist/cli/aun-commands.js +82 -22
- package/dist/cli/daemon-commands.js +19 -10
- package/dist/cli/index.js +1 -1
- package/dist/cli/restart-monitor.js +17 -0
- package/dist/cli/session-command.js +128 -13
- package/dist/cli/stats.js +60 -4
- package/dist/cli/trigger-command.js +2 -2
- package/dist/config/access-policy.js +2 -0
- package/dist/config/config-operation-service.js +17 -6
- package/dist/config/gateway-config.js +1 -1
- package/dist/config/peer-role-resolver.js +10 -8
- package/dist/core/agent-application-service.js +11 -1
- package/dist/core/agent-ipc-registration.js +4 -0
- package/dist/core/auth/agent-delegation.js +80 -5
- package/dist/core/auth/authorization-audit.js +20 -3
- package/dist/core/auth/operation-catalog.js +8 -0
- package/dist/core/command/agent-control.js +91 -12
- package/dist/core/command/command-handler.js +57 -46
- package/dist/core/command/connect-menu.js +23 -2
- package/dist/core/command/menu-catalog.js +1 -0
- package/dist/core/command/menu-handler.js +38 -101
- package/dist/core/command/menu-protocol.js +9 -2
- package/dist/core/command/role-menu.js +7 -6
- package/dist/core/command/slash-gate.js +13 -10
- package/dist/core/command/slash-handler.js +34 -98
- package/dist/core/event-catalog.js +15 -0
- package/dist/core/ipc-registration.js +18 -1
- package/dist/core/memory/consolidation-trigger.js +1 -1
- package/dist/core/message/aun-ipc-sender.js +26 -5
- package/dist/core/message/aun-request-registry.js +97 -3
- package/dist/core/message/im-renderer.js +4 -0
- package/dist/core/message/message-admission.js +8 -4
- package/dist/core/message/message-bridge.js +40 -6
- package/dist/core/message/message-log.js +55 -0
- package/dist/core/message/message-queue.js +5 -5
- package/dist/core/message/response-engine.js +310 -136
- package/dist/core/model/model-catalog.js +7 -6
- package/dist/core/ownership/owner-resolver.js +2 -2
- package/dist/core/permission/ec-command-parser.js +110 -5
- package/dist/core/permission/tool-policy.js +28 -7
- package/dist/core/session/session-capsule.js +197 -0
- package/dist/core/session/session-manager.js +148 -14
- package/dist/core/session/session-mapper.js +2 -0
- package/dist/index.js +3 -3
- package/dist/ipc.js +22 -8
- package/dist/stats/budget.js +1 -1
- package/dist/stats/db.js +15 -0
- package/dist/stats/index.js +2 -2
- package/dist/stats/price-resolver.js +304 -5
- package/dist/stats/query.js +82 -3
- package/dist/stats/writer.js +38 -5
- package/dist/trigger/feedback.js +18 -7
- package/dist/trigger/manager.js +20 -3
- package/dist/trigger/parser.js +6 -3
- package/dist/trigger/patch.js +1 -1
- package/dist/trigger/system-definitions.js +43 -7
- package/dist/trigger/validation.js +13 -5
- package/dist/utils/error-utils.js +14 -0
- package/dist/utils/npm-ops.js +2 -1
- package/dist/utils/package-version-info.js +1 -1
- package/dist/utils/upgrade-jobs.js +45 -5
- package/kits/docs/INDEX.md +1 -1
- package/kits/docs/aun/ABILITY_CALLING.md +20 -2
- package/kits/docs/evolcore/INDEX.md +2 -1
- package/kits/docs/evolcore/agent-create.md +3 -2
- package/kits/docs/evolcore/agent.md +1 -1
- package/kits/docs/evolcore/config.md +1 -1
- package/kits/docs/evolcore/event.md +1 -0
- package/kits/docs/evolcore/fs.md +5 -0
- package/kits/docs/evolcore/menu-protocol.md +32 -0
- package/kits/docs/evolcore/msg.md +17 -1
- package/kits/docs/evolcore/session.md +14 -0
- package/kits/schemas/agent-config.schema.13.json +15 -0
- package/kits/skills/aid-ability/SKILL.md +35 -6
- package/kits/templates/session-capsule/recovery.md +5 -0
- package/kits/templates/session-capsule/renew.md +5 -0
- package/kits/templates/system-fragments/bootstrap.md +6 -6
- package/kits/templates/system-fragments/channel.md +1 -1
- package/package.json +3 -3
- package/dist/stats/billing.js +0 -215
|
@@ -14,6 +14,8 @@ import path from 'path';
|
|
|
14
14
|
import fs from 'fs';
|
|
15
15
|
import os from 'os';
|
|
16
16
|
import { createHash } from 'node:crypto';
|
|
17
|
+
import { appendSessionCapsuleEvent, capsuleHistory, fallbackCapsuleContent, findSessionCapsule, generateCapsuleContent, generateCapsuleId, renderCapsuleInput, withoutBackendSessionId } from './session-capsule.js';
|
|
18
|
+
import { associateMessageCapsule } from '../message/message-log.js';
|
|
17
19
|
function forkHistoryRecord(value) {
|
|
18
20
|
return value && typeof value === 'object' && !Array.isArray(value)
|
|
19
21
|
? value
|
|
@@ -227,8 +229,8 @@ export function pageForkHistory(snapshot, before = snapshot.items.length, limit
|
|
|
227
229
|
};
|
|
228
230
|
}
|
|
229
231
|
/** Metadata keys owned by ordinary topic/session routing writers. */
|
|
230
|
-
const TOPIC_METADATA_PROTECTED_KEYS = new Set(['turnState', 'resumeAt', 'agentSessions', 'sessionLoop', 'sessionFullAccess']);
|
|
231
|
-
const TOPIC_BACKEND_SCOPED_KEYS = ['resumeAt', 'agentSessions'];
|
|
232
|
+
const TOPIC_METADATA_PROTECTED_KEYS = new Set(['turnState', 'resumeAt', 'agentSessions', 'sessionLoop', 'sessionFullAccess', 'capsuleId']);
|
|
233
|
+
const TOPIC_BACKEND_SCOPED_KEYS = ['resumeAt', 'agentSessions', 'capsuleId'];
|
|
232
234
|
function topicMetadataOwnershipError(key) {
|
|
233
235
|
const error = new Error(`topic metadata field is owned by a dedicated updater: ${key}`);
|
|
234
236
|
error.code = 'TOPIC_METADATA_OWNERSHIP';
|
|
@@ -254,6 +256,13 @@ function newSessionStableMetadata(chatType, ...sources) {
|
|
|
254
256
|
}
|
|
255
257
|
return metadata;
|
|
256
258
|
}
|
|
259
|
+
function matchesActiveTurn(session, lease) {
|
|
260
|
+
const active = session.metadata?.turnState?.active;
|
|
261
|
+
return session.id === lease.sessionId && !!active
|
|
262
|
+
&& session.metadata?.turnState?.generation === lease.generation
|
|
263
|
+
&& active.generation === lease.generation && active.taskId === lease.taskId
|
|
264
|
+
&& active.turnId === lease.turnId && active.inputId === lease.inputId;
|
|
265
|
+
}
|
|
257
266
|
/** 判定用户是否为指定渠道的 admin */
|
|
258
267
|
/** 判定用户是否为指定渠道的 member */
|
|
259
268
|
export class SessionManager {
|
|
@@ -265,6 +274,7 @@ export class SessionManager {
|
|
|
265
274
|
/** findSessionFileById 的查找缓存:命中前一律 stat 校验,不作为真相源。 */
|
|
266
275
|
sessionFileIndex = new Map();
|
|
267
276
|
knownChatDirs = null;
|
|
277
|
+
capsuleTranscriptReader;
|
|
268
278
|
constructor(sessionsDir, eventBus, identityResolver) {
|
|
269
279
|
ensureDir(sessionsDir);
|
|
270
280
|
this.sessionsDir = sessionsDir;
|
|
@@ -278,6 +288,90 @@ export class SessionManager {
|
|
|
278
288
|
this.fileAdapters.set(adapter.baseagent, adapter);
|
|
279
289
|
logger.debug(`[SessionManager] Registered file adapter: ${adapter.baseagent}`);
|
|
280
290
|
}
|
|
291
|
+
setCapsuleTranscriptReader(reader) {
|
|
292
|
+
this.capsuleTranscriptReader = reader;
|
|
293
|
+
}
|
|
294
|
+
getPendingCapsule(session) {
|
|
295
|
+
const id = session.metadata?.capsuleId;
|
|
296
|
+
if (!id)
|
|
297
|
+
return undefined;
|
|
298
|
+
const capsule = findSessionCapsule(this.getChatDir(session), id);
|
|
299
|
+
if (!capsule || capsule.sessionId !== session.id)
|
|
300
|
+
throw new Error('Session capsule is unavailable');
|
|
301
|
+
return capsule.consumedAt === undefined ? capsule : undefined;
|
|
302
|
+
}
|
|
303
|
+
createCapsule(source, targetSessionId, cause, content) {
|
|
304
|
+
const capsule = {
|
|
305
|
+
capsuleId: generateCapsuleId(), sessionId: targetSessionId,
|
|
306
|
+
...(source.id !== targetSessionId ? { sourceSessionId: source.id } : {}),
|
|
307
|
+
cause, sourceAgentSessionId: source.agentSessionId, content, createdAt: Date.now(),
|
|
308
|
+
};
|
|
309
|
+
appendSessionCapsuleEvent(this.getChatDir(source), { ...capsule, kind: 'created' });
|
|
310
|
+
return capsule;
|
|
311
|
+
}
|
|
312
|
+
stageBackendRecovery(session, content) {
|
|
313
|
+
if (!session.agentSessionId)
|
|
314
|
+
return this.getPendingCapsule(session);
|
|
315
|
+
const existing = this.getPendingCapsule(session);
|
|
316
|
+
if (existing?.sourceAgentSessionId === session.agentSessionId && !existing.agentSessionId)
|
|
317
|
+
return existing;
|
|
318
|
+
const capsule = this.createCapsule(session, session.id, 'backend-recovery', content ?? fallbackCapsuleContent(capsuleHistory(this.getChatDir(session), session), 'backend-recovery'));
|
|
319
|
+
session.metadata = { ...session.metadata, capsuleId: capsule.capsuleId };
|
|
320
|
+
return capsule;
|
|
321
|
+
}
|
|
322
|
+
/** Called before the first model input; pending context is never added to system instructions. */
|
|
323
|
+
prepareCapsuleInput(sessionId, prompt) {
|
|
324
|
+
const loaded = this.loadSessionForUpdate(sessionId);
|
|
325
|
+
if (!loaded)
|
|
326
|
+
return { prompt };
|
|
327
|
+
const capsule = this.getPendingCapsule(loaded.current);
|
|
328
|
+
if (!capsule)
|
|
329
|
+
return { prompt };
|
|
330
|
+
return { prompt: renderCapsuleInput(capsule, prompt), capsuleId: capsule.capsuleId };
|
|
331
|
+
}
|
|
332
|
+
/** Main-session runners may discover an unavailable transcript after generic admission. */
|
|
333
|
+
async prepareBackendRecovery(sessionId, expectedAgentSessionId, prompt, systemPrompt, lease) {
|
|
334
|
+
const cleared = await this.clearMainSessionBackendIfMatches(sessionId, expectedAgentSessionId, [], lease);
|
|
335
|
+
if (cleared !== 'cleared' && cleared !== 'already_clear') {
|
|
336
|
+
throw new Error(`Backend recovery rejected: ${cleared}`);
|
|
337
|
+
}
|
|
338
|
+
const prepared = this.prepareCapsuleInput(sessionId, prompt);
|
|
339
|
+
return { ...prepared, systemPrompt: withoutBackendSessionId(systemPrompt) };
|
|
340
|
+
}
|
|
341
|
+
recordCapsuleBinding(session, agentSessionId) {
|
|
342
|
+
const capsule = this.getPendingCapsule(session);
|
|
343
|
+
if (!capsule || capsule.agentSessionId === agentSessionId)
|
|
344
|
+
return;
|
|
345
|
+
if (capsule.agentSessionId)
|
|
346
|
+
throw new Error('Capsule is already bound to a different backend');
|
|
347
|
+
appendSessionCapsuleEvent(this.getChatDir(session), { ...capsule, content: undefined,
|
|
348
|
+
kind: 'bound', agentSessionId });
|
|
349
|
+
}
|
|
350
|
+
/** Requires both durable backend binding and current-turn input acceptance. */
|
|
351
|
+
consumeSessionCapsule(sessionId, capsuleId, input) {
|
|
352
|
+
const loaded = this.loadSessionForUpdate(sessionId);
|
|
353
|
+
if (!loaded || loaded.current.agentSessionId !== input.agentSessionId)
|
|
354
|
+
return undefined;
|
|
355
|
+
const session = loaded.current;
|
|
356
|
+
if (input.lease && !matchesActiveTurn(session, input.lease))
|
|
357
|
+
return undefined;
|
|
358
|
+
const capsule = this.getPendingCapsule(session);
|
|
359
|
+
if (!capsule || capsule.capsuleId !== capsuleId || capsule.agentSessionId !== input.agentSessionId)
|
|
360
|
+
return undefined;
|
|
361
|
+
const consumedAt = Date.now();
|
|
362
|
+
appendSessionCapsuleEvent(this.getChatDir(session), { ...capsule, content: undefined,
|
|
363
|
+
kind: 'consumed', consumedAt, messageId: input.messageId });
|
|
364
|
+
// Input was accepted even when an auxiliary message-log annotation fails.
|
|
365
|
+
// Keep the durable receipt so a retry cannot submit this context twice.
|
|
366
|
+
associateMessageCapsule(this.getChatDir(session), session.id, capsuleId, input.messageId, input.timestamp);
|
|
367
|
+
if (capsule.cause === 'backend-recovery') {
|
|
368
|
+
this.eventBus.publish({ type: 'session:backend-recovery', sessionId,
|
|
369
|
+
agentAid: session.selfAID, baseagent: session.baseagent,
|
|
370
|
+
sourceAgentSessionId: capsule.sourceAgentSessionId, agentSessionId: input.agentSessionId,
|
|
371
|
+
capsuleId, timestamp: consumedAt });
|
|
372
|
+
}
|
|
373
|
+
return { ...capsule, consumedAt, messageId: input.messageId };
|
|
374
|
+
}
|
|
281
375
|
getFileAdapter(baseagent) {
|
|
282
376
|
return this.fileAdapters.get(baseagent);
|
|
283
377
|
}
|
|
@@ -803,6 +897,7 @@ export class SessionManager {
|
|
|
803
897
|
return agentSessionId;
|
|
804
898
|
}
|
|
805
899
|
logger.warn(`Session file not found for ${session.baseagent}: ${agentSessionId}, clearing session ID`);
|
|
900
|
+
this.stageBackendRecovery(session);
|
|
806
901
|
session.agentSessionId = undefined;
|
|
807
902
|
this.persistSession(session, 'sync');
|
|
808
903
|
return undefined;
|
|
@@ -1049,6 +1144,10 @@ export class SessionManager {
|
|
|
1049
1144
|
async rotateTopicBackend(input) {
|
|
1050
1145
|
if (!input.expectedThreadId.trim())
|
|
1051
1146
|
throw new Error('backend rotation requires a non-empty threadId');
|
|
1147
|
+
const before = this.latestSessionForBoundary(input.sessionId).session;
|
|
1148
|
+
const capsuleContent = before?.agentSessionId
|
|
1149
|
+
? await generateCapsuleContent(this.getChatDir(before), before, 'topic-renew', this.capsuleTranscriptReader)
|
|
1150
|
+
: undefined;
|
|
1052
1151
|
return this.mutateLatestTopicSession(input.sessionId, (current, found) => {
|
|
1053
1152
|
if (sessionTopicThreadId(current) !== input.expectedThreadId) {
|
|
1054
1153
|
const error = new Error('backend rotation threadId mismatch');
|
|
@@ -1056,21 +1155,18 @@ export class SessionManager {
|
|
|
1056
1155
|
throw error;
|
|
1057
1156
|
}
|
|
1058
1157
|
const wasBound = !!normalizeBackendSessionId(current.agentSessionId);
|
|
1158
|
+
if (before?.agentSessionId !== current.agentSessionId)
|
|
1159
|
+
throw new Error('Backend changed while preparing renew context');
|
|
1059
1160
|
const next = JSON.parse(JSON.stringify(current));
|
|
1060
1161
|
const previousBaseagent = next.baseagent;
|
|
1061
|
-
if (input.baseagent !== undefined) {
|
|
1062
|
-
const requested = input.baseagent.trim();
|
|
1063
|
-
if (!requested) {
|
|
1064
|
-
const error = new Error('backend rotation baseagent must be non-empty');
|
|
1065
|
-
error.code = 'BASEAGENT_REQUIRED';
|
|
1066
|
-
throw error;
|
|
1067
|
-
}
|
|
1068
|
-
next.baseagent = requested;
|
|
1069
|
-
}
|
|
1070
1162
|
next.agentSessionId = undefined;
|
|
1071
1163
|
const nextMetadata = { ...(next.metadata ?? {}) };
|
|
1072
1164
|
delete nextMetadata.resumeAt;
|
|
1073
1165
|
delete nextMetadata.agentSessions;
|
|
1166
|
+
if (capsuleContent !== undefined) {
|
|
1167
|
+
const capsule = this.createCapsule(current, current.id, 'topic-renew', capsuleContent);
|
|
1168
|
+
nextMetadata.capsuleId = capsule.capsuleId;
|
|
1169
|
+
}
|
|
1074
1170
|
next.metadata = nextMetadata;
|
|
1075
1171
|
this.persistConfirmedTopicBoundary(current, found, next);
|
|
1076
1172
|
return {
|
|
@@ -1110,13 +1206,16 @@ export class SessionManager {
|
|
|
1110
1206
|
|| current.metadata?.turnState?.generation !== input.lease.generation)
|
|
1111
1207
|
return 'stale';
|
|
1112
1208
|
const currentId = normalizeBackendSessionId(current.agentSessionId);
|
|
1113
|
-
if (currentId === agentSessionId)
|
|
1209
|
+
if (currentId === agentSessionId) {
|
|
1210
|
+
this.recordCapsuleBinding(current, agentSessionId);
|
|
1114
1211
|
return 'already_active';
|
|
1212
|
+
}
|
|
1115
1213
|
if (currentId && currentId !== agentSessionId)
|
|
1116
1214
|
return 'conflict';
|
|
1117
1215
|
const next = JSON.parse(JSON.stringify(current));
|
|
1118
1216
|
next.agentSessionId = agentSessionId;
|
|
1119
1217
|
this.persistConfirmedTopicBoundary(current, found, next);
|
|
1218
|
+
this.recordCapsuleBinding(next, agentSessionId);
|
|
1120
1219
|
return 'activated';
|
|
1121
1220
|
});
|
|
1122
1221
|
}
|
|
@@ -1717,6 +1816,8 @@ export class SessionManager {
|
|
|
1717
1816
|
}
|
|
1718
1817
|
active.agentSessionId = agentSessionId;
|
|
1719
1818
|
this.persistSession(active, 'sync');
|
|
1819
|
+
if (agentSessionId)
|
|
1820
|
+
this.recordCapsuleBinding(active, agentSessionId);
|
|
1720
1821
|
}
|
|
1721
1822
|
async updateAgentSessionIdBySessionId(sessionId, agentSessionId, turnLease) {
|
|
1722
1823
|
const loaded = this.loadSessionForUpdate(sessionId);
|
|
@@ -1733,8 +1834,12 @@ export class SessionManager {
|
|
|
1733
1834
|
logger.warn(`[SessionManager] Ignoring topic agentSessionId update without an active turn lease: sessionId=${sessionId}`);
|
|
1734
1835
|
return 'stale';
|
|
1735
1836
|
}
|
|
1837
|
+
if (turnLease && !matchesActiveTurn(current, turnLease))
|
|
1838
|
+
return 'stale';
|
|
1736
1839
|
current.agentSessionId = agentSessionId;
|
|
1737
1840
|
const wrote = this.persistSession(current, 'sync');
|
|
1841
|
+
if (agentSessionId)
|
|
1842
|
+
this.recordCapsuleBinding(current, agentSessionId);
|
|
1738
1843
|
if (wrote) {
|
|
1739
1844
|
logger.info(`[SessionManager] Updating agent_session_id: sessionId=${sessionId}, agentSessionId=${agentSessionId}`);
|
|
1740
1845
|
}
|
|
@@ -1745,18 +1850,37 @@ export class SessionManager {
|
|
|
1745
1850
|
* points at the caller's expected ID. This is the recovery counterpart to
|
|
1746
1851
|
* provider-side "session not found" errors and must never rotate a topic.
|
|
1747
1852
|
*/
|
|
1748
|
-
async clearMainSessionBackendIfMatches(sessionId, expectedAgentSessionId, metadataKeys = []) {
|
|
1853
|
+
async clearMainSessionBackendIfMatches(sessionId, expectedAgentSessionId, metadataKeys = [], lease) {
|
|
1749
1854
|
const loaded = this.loadSessionForUpdate(sessionId);
|
|
1750
1855
|
if (!loaded)
|
|
1751
1856
|
return 'missing';
|
|
1752
|
-
|
|
1857
|
+
let { current } = loaded;
|
|
1753
1858
|
if (isTopicSession(current))
|
|
1754
1859
|
return 'topic';
|
|
1860
|
+
if (lease && !matchesActiveTurn(current, lease))
|
|
1861
|
+
return 'mismatch';
|
|
1755
1862
|
const currentId = normalizeBackendSessionId(current.agentSessionId);
|
|
1756
1863
|
if (!currentId)
|
|
1757
1864
|
return 'already_clear';
|
|
1758
1865
|
if (currentId !== normalizeBackendSessionId(expectedAgentSessionId))
|
|
1759
1866
|
return 'mismatch';
|
|
1867
|
+
const content = await generateCapsuleContent(this.getChatDir(current), current, 'backend-recovery', this.capsuleTranscriptReader);
|
|
1868
|
+
// Summary generation is outside the short snapshot mutation. Re-check the
|
|
1869
|
+
// durable binding so a late recovery cannot clear a newer backend.
|
|
1870
|
+
const latest = this.loadSessionForUpdate(sessionId);
|
|
1871
|
+
if (!latest)
|
|
1872
|
+
return 'missing';
|
|
1873
|
+
current = latest.current;
|
|
1874
|
+
if (isTopicSession(current))
|
|
1875
|
+
return 'topic';
|
|
1876
|
+
if (lease && !matchesActiveTurn(current, lease))
|
|
1877
|
+
return 'mismatch';
|
|
1878
|
+
const latestId = normalizeBackendSessionId(current.agentSessionId);
|
|
1879
|
+
if (!latestId)
|
|
1880
|
+
return 'already_clear';
|
|
1881
|
+
if (latestId !== normalizeBackendSessionId(expectedAgentSessionId))
|
|
1882
|
+
return 'mismatch';
|
|
1883
|
+
this.stageBackendRecovery(current, content);
|
|
1760
1884
|
current.agentSessionId = undefined;
|
|
1761
1885
|
if (metadataKeys.length > 0 && current.metadata) {
|
|
1762
1886
|
const metadata = { ...current.metadata };
|
|
@@ -2169,6 +2293,8 @@ export class SessionManager {
|
|
|
2169
2293
|
createdAt: Date.now(),
|
|
2170
2294
|
updatedAt: Date.now(),
|
|
2171
2295
|
};
|
|
2296
|
+
if (eventMetadata?.sourceSessionId)
|
|
2297
|
+
session.sourceSessionId = eventMetadata.sourceSessionId;
|
|
2172
2298
|
this.persistSession(session, 'set');
|
|
2173
2299
|
this.eventBus.publish({
|
|
2174
2300
|
type: 'session:created',
|
|
@@ -2203,6 +2329,7 @@ export class SessionManager {
|
|
|
2203
2329
|
const sourceTopicId = sessionTopicThreadId(sourceSession);
|
|
2204
2330
|
const session = {
|
|
2205
2331
|
id: generateSessionId(),
|
|
2332
|
+
sourceSessionId: sourceSession.id,
|
|
2206
2333
|
channel: sourceSession.channel,
|
|
2207
2334
|
channelType,
|
|
2208
2335
|
channelId: sourceSession.channelId,
|
|
@@ -2269,6 +2396,7 @@ export class SessionManager {
|
|
|
2269
2396
|
};
|
|
2270
2397
|
const session = {
|
|
2271
2398
|
id: generateSessionId(),
|
|
2399
|
+
sourceSessionId: sourceSession.id,
|
|
2272
2400
|
channel: sourceSession.channel,
|
|
2273
2401
|
channelType,
|
|
2274
2402
|
channelId: sourceSession.channelId,
|
|
@@ -2336,12 +2464,15 @@ export class SessionManager {
|
|
|
2336
2464
|
const metadata = { ...(sourceSession.metadata || {}) };
|
|
2337
2465
|
delete metadata.agentSessions;
|
|
2338
2466
|
delete metadata.resumeAt;
|
|
2467
|
+
delete metadata.turnState;
|
|
2468
|
+
delete metadata.capsuleId;
|
|
2339
2469
|
delete metadata.replyContext;
|
|
2340
2470
|
delete metadata.sessionLoop;
|
|
2341
2471
|
delete metadata.sessionFullAccess;
|
|
2342
2472
|
metadata.__sessionRenewedAt = Date.now();
|
|
2343
2473
|
const session = {
|
|
2344
2474
|
id: generateSessionId(),
|
|
2475
|
+
sourceSessionId: sourceSession.id,
|
|
2345
2476
|
channel: sourceSession.channel,
|
|
2346
2477
|
channelType: sourceSession.channelType || sourceSession.channel,
|
|
2347
2478
|
channelId: sourceSession.channelId,
|
|
@@ -2358,6 +2489,9 @@ export class SessionManager {
|
|
|
2358
2489
|
updatedAt: Date.now(),
|
|
2359
2490
|
};
|
|
2360
2491
|
session.identity = sourceSession.identity;
|
|
2492
|
+
const content = await generateCapsuleContent(this.getChatDir(sourceSession), sourceSession, 'session-renew', this.capsuleTranscriptReader);
|
|
2493
|
+
const capsule = this.createCapsule(sourceSession, session.id, 'session-renew', content);
|
|
2494
|
+
session.metadata = { ...session.metadata, capsuleId: capsule.capsuleId };
|
|
2361
2495
|
this.persistSession(session, 'set');
|
|
2362
2496
|
this.eventBus.publish({
|
|
2363
2497
|
type: 'session:created',
|
|
@@ -108,6 +108,7 @@ export function sessionToFile(session) {
|
|
|
108
108
|
}
|
|
109
109
|
return {
|
|
110
110
|
id: session.id,
|
|
111
|
+
...(session.sourceSessionId ? { sourceSessionId: session.sourceSessionId } : {}),
|
|
111
112
|
channel: session.channel,
|
|
112
113
|
channelType,
|
|
113
114
|
channelId: session.channelId,
|
|
@@ -166,6 +167,7 @@ export function fileToSession(file) {
|
|
|
166
167
|
const isTopic = kind.kind === 'topic';
|
|
167
168
|
return {
|
|
168
169
|
id: file.id,
|
|
170
|
+
...(file.sourceSessionId ? { sourceSessionId: file.sourceSessionId } : {}),
|
|
169
171
|
channel: file.channel,
|
|
170
172
|
channelType: file.channelType,
|
|
171
173
|
channelId: file.channelId,
|
package/dist/index.js
CHANGED
|
@@ -428,13 +428,13 @@ async function main() {
|
|
|
428
428
|
dedupPath: daemonMessageDedupPath(),
|
|
429
429
|
});
|
|
430
430
|
// 设置中断回调(精确中断正在处理的 agent)
|
|
431
|
-
messageQueue.setInterruptCallback(async (sessionKey, baseagent, evolagentName, reason = 'new_message', timeout, strict) => {
|
|
431
|
+
messageQueue.setInterruptCallback(async (sessionKey, baseagent, evolagentName, reason = 'new_message', timeout, strict, target) => {
|
|
432
432
|
void baseagent;
|
|
433
433
|
void evolagentName;
|
|
434
434
|
if (timeout)
|
|
435
|
-
await responseEngine.timeoutSession(sessionKey, timeout);
|
|
435
|
+
await responseEngine.timeoutSession(sessionKey, timeout, target);
|
|
436
436
|
else
|
|
437
|
-
await responseEngine.interruptSession(sessionKey, reason, strict);
|
|
437
|
+
await responseEngine.interruptSession(sessionKey, reason, strict, undefined, target);
|
|
438
438
|
});
|
|
439
439
|
messageQueue.setEventBus(eventBus);
|
|
440
440
|
// Restore persisted input before Trigger schedulers start. Trigger-owned work
|
package/dist/ipc.js
CHANGED
|
@@ -16,7 +16,7 @@ import { getPackageRoot, getWindowsInstanceSocketPathCandidates, normalizeIpcEnd
|
|
|
16
16
|
import { getProcessStartTime, isSameOrOlderProcess } from './utils/process-introspect.js';
|
|
17
17
|
import { classifyProcessTree, ProcessTreeSampler, readProcessMetrics } from './utils/process-tree-stats.js';
|
|
18
18
|
import { readSystemMemoryUsage } from './utils/system-memory.js';
|
|
19
|
-
import { hashCurrentDelegatedCommand, hashDelegatedCommandArgv } from './core/auth/agent-delegation.js';
|
|
19
|
+
import { hashCurrentDelegatedCommand, hashDelegatedCommandArgv, parseDelegatedExecutionSpec, readDelegatedExecutionSpec } from './core/auth/agent-delegation.js';
|
|
20
20
|
import { resolveSkillRefreshArgv } from './core/skill/command-parser.js';
|
|
21
21
|
import { normalizeAunMentionEntries } from './aun/msg/mention-schema.js';
|
|
22
22
|
import { remoteAccessService } from './core/auth/remote-access-store.js';
|
|
@@ -92,7 +92,7 @@ const MEMORY_COMMAND_ENDPOINTS = new Set([
|
|
|
92
92
|
const DELEGATED_ARGV_ENDPOINTS = new Set([
|
|
93
93
|
'agent.op', 'config.op', 'contact.op', 'aid.op', 'aid.ownership', 'group.op', 'msg.op', 'fs.op',
|
|
94
94
|
'ctl', 'diag', 'menu-client.request', 'task.resume', 'queue.op', 'storage.auth', 'storage.upload',
|
|
95
|
-
'trigger.op', 'skill.refresh', 'thread.op', 'local-command-context', 'evolagent.bootstrapComplete', ...MEMORY_COMMAND_ENDPOINTS,
|
|
95
|
+
'trigger.op', 'skill.refresh', 'thread.op', 'local-command-context', 'evolagent.bootstrapComplete', 'status.auth', ...MEMORY_COMMAND_ENDPOINTS,
|
|
96
96
|
'handoff-return', 'handoff-recover-return', 'handoff-status', 'handoff-list', 'handoff-trace',
|
|
97
97
|
]);
|
|
98
98
|
let ipcQuerySequence = 0;
|
|
@@ -1009,15 +1009,23 @@ export class IpcServer {
|
|
|
1009
1009
|
return this.diagnosticRejection('daemon_restarted', cmd);
|
|
1010
1010
|
}
|
|
1011
1011
|
if (typeof cmd.delegationToken === 'string'
|
|
1012
|
-
&& (DELEGATED_ARGV_ENDPOINTS.has(cmd.type)
|
|
1012
|
+
&& ((DELEGATED_ARGV_ENDPOINTS.has(cmd.type) && (cmd.type !== 'status.auth' || cmd.argv !== undefined))
|
|
1013
|
+
|| (cmd.type === 'aun-msg-send' && cmd.argv !== undefined))) {
|
|
1013
1014
|
if (!Array.isArray(cmd.argv) || cmd.argv.some(value => typeof value !== 'string')) {
|
|
1014
1015
|
return { ok: false, code: 'INVALID_REQUEST', error: 'Invalid command argv' };
|
|
1015
1016
|
}
|
|
1016
|
-
const
|
|
1017
|
+
const expectedArgv = [
|
|
1017
1018
|
MAIN_CLI_BIN,
|
|
1018
1019
|
...(cmd.type === 'menu-client.request' ? ['menu-client'] : []),
|
|
1019
1020
|
...cmd.argv,
|
|
1020
|
-
]
|
|
1021
|
+
];
|
|
1022
|
+
const executionSpec = cmd.executionSpec === undefined
|
|
1023
|
+
? undefined
|
|
1024
|
+
: parseDelegatedExecutionSpec(cmd.executionSpec);
|
|
1025
|
+
if (cmd.executionSpec !== undefined && !executionSpec) {
|
|
1026
|
+
return { ok: false, code: 'INVALID_REQUEST', error: 'Invalid delegated execution spec' };
|
|
1027
|
+
}
|
|
1028
|
+
const expectedHash = hashDelegatedCommandArgv(expectedArgv, executionSpec);
|
|
1021
1029
|
if (!expectedHash || cmd.delegationCommandHash !== expectedHash) {
|
|
1022
1030
|
return this.diagnosticRejection('command_hash_mismatch', cmd);
|
|
1023
1031
|
}
|
|
@@ -1427,6 +1435,7 @@ export class IpcServer {
|
|
|
1427
1435
|
sessionId: cmd.sessionId,
|
|
1428
1436
|
delegationToken: typeof cmd.delegationToken === 'string' ? cmd.delegationToken : undefined,
|
|
1429
1437
|
delegationCommandHash: typeof cmd.delegationCommandHash === 'string' ? cmd.delegationCommandHash : undefined,
|
|
1438
|
+
argv: Array.isArray(cmd.argv) ? cmd.argv : undefined,
|
|
1430
1439
|
});
|
|
1431
1440
|
}
|
|
1432
1441
|
case 'storage.auth': {
|
|
@@ -1435,7 +1444,7 @@ export class IpcServer {
|
|
|
1435
1444
|
if (typeof cmd.sessionId !== 'string' || !cmd.sessionId || typeof cmd.aid !== 'string' || !cmd.aid || typeof cmd.operation !== 'string') {
|
|
1436
1445
|
return { ok: false, code: 'INVALID_REQUEST', error: 'missing sessionId, aid, or operation' };
|
|
1437
1446
|
}
|
|
1438
|
-
if (!['storage.list', 'storage.quota', 'storage.upload', 'storage.download', 'storage.delete'].includes(cmd.operation)) {
|
|
1447
|
+
if (!['storage.list', 'storage.quota', 'storage.upload', 'storage.download', 'storage.delete', 'storage.get_by_share'].includes(cmd.operation)) {
|
|
1439
1448
|
return { ok: false, code: 'INVALID_REQUEST', error: 'invalid storage operation' };
|
|
1440
1449
|
}
|
|
1441
1450
|
return await this.storageAuthorizationExecutor({
|
|
@@ -1514,7 +1523,7 @@ export class IpcServer {
|
|
|
1514
1523
|
}
|
|
1515
1524
|
case 'local-command-context': {
|
|
1516
1525
|
if (!Array.isArray(cmd.argv) || cmd.argv.some((value) => typeof value !== 'string')
|
|
1517
|
-
|| !['skill', 'stats'].includes(cmd.argv[0]) || typeof cmd.sessionId !== 'string' || !cmd.sessionId
|
|
1526
|
+
|| !['skill', 'stats', 'session'].includes(cmd.argv[0]) || typeof cmd.sessionId !== 'string' || !cmd.sessionId
|
|
1518
1527
|
|| typeof cmd.delegationToken !== 'string' || !cmd.delegationToken) {
|
|
1519
1528
|
return { ok: false, code: 'INVALID_REQUEST', error: 'Local command requires argv and task credentials' };
|
|
1520
1529
|
}
|
|
@@ -1646,6 +1655,7 @@ export class IpcServer {
|
|
|
1646
1655
|
aid: cmd.aid,
|
|
1647
1656
|
to: cmd.to,
|
|
1648
1657
|
scope: cmd.scope === 'group' ? 'group' : 'msg',
|
|
1658
|
+
deviceId: cmd.deviceId,
|
|
1649
1659
|
payload: normalizedPayload,
|
|
1650
1660
|
rawPayload: cmd.rawPayload === true,
|
|
1651
1661
|
file,
|
|
@@ -2698,14 +2708,18 @@ function ipcQueryOnce(socketPath, cmd, timeoutMs = 3000) {
|
|
|
2698
2708
|
...authenticatedCmd.argv,
|
|
2699
2709
|
]
|
|
2700
2710
|
: undefined;
|
|
2711
|
+
const executionSpec = typeof authenticatedCmd.delegationToken === 'string'
|
|
2712
|
+
? readDelegatedExecutionSpec()
|
|
2713
|
+
: undefined;
|
|
2701
2714
|
const delegationCommandHash = typeof authenticatedCmd.delegationToken === 'string'
|
|
2702
2715
|
&& typeof authenticatedCmd.delegationCommandHash !== 'string'
|
|
2703
2716
|
? requestArgv
|
|
2704
|
-
? hashDelegatedCommandArgv(requestArgv)
|
|
2717
|
+
? hashDelegatedCommandArgv(requestArgv, executionSpec)
|
|
2705
2718
|
: hashCurrentDelegatedCommand()
|
|
2706
2719
|
: undefined;
|
|
2707
2720
|
const request = {
|
|
2708
2721
|
...(delegationCommandHash ? { ...authenticatedCmd, delegationCommandHash } : authenticatedCmd),
|
|
2722
|
+
...(executionSpec ? { executionSpec: JSON.stringify(executionSpec) } : {}),
|
|
2709
2723
|
...(process.env[DAEMON_RUNTIME_EPOCH_ENV]
|
|
2710
2724
|
&& authenticatedCmd.daemonRuntimeEpoch === undefined
|
|
2711
2725
|
&& typeof authenticatedCmd.delegationToken === 'string'
|
package/dist/stats/budget.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import fs from 'fs';
|
|
5
5
|
import path from 'path';
|
|
6
|
-
import { calcCost } from './
|
|
6
|
+
import { calcCost } from './price-resolver.js';
|
|
7
7
|
import { openReadonlyDb, getDbPath } from './db.js';
|
|
8
8
|
function loadBudgets(evolcoreHome) {
|
|
9
9
|
const file = path.join(evolcoreHome, 'data', 'stats', 'budgets.json');
|
package/dist/stats/db.js
CHANGED
|
@@ -345,6 +345,21 @@ function _initTables(db) {
|
|
|
345
345
|
catch (e) {
|
|
346
346
|
logger.warn(`[StatsDB] model_calls context window 迁移检测失败: ${e}`);
|
|
347
347
|
}
|
|
348
|
+
// 轻量迁移:model_calls 添加 cost 列(官方价 + 网关价)
|
|
349
|
+
try {
|
|
350
|
+
const cols = db.prepare(`PRAGMA table_info(model_calls)`).all();
|
|
351
|
+
if (!cols.some(c => c.name === 'cost_official_usd')) {
|
|
352
|
+
db.exec(`
|
|
353
|
+
ALTER TABLE model_calls ADD COLUMN cost_official_usd REAL;
|
|
354
|
+
ALTER TABLE model_calls ADD COLUMN cost_official_cny REAL;
|
|
355
|
+
ALTER TABLE model_calls ADD COLUMN cost_gateway_usd REAL;
|
|
356
|
+
ALTER TABLE model_calls ADD COLUMN cost_gateway_cny REAL;
|
|
357
|
+
`);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
catch (e) {
|
|
361
|
+
logger.warn(`[StatsDB] model_calls cost 列迁移检测失败: ${e}`);
|
|
362
|
+
}
|
|
348
363
|
}
|
|
349
364
|
/**
|
|
350
365
|
* 全量重建 usage_daily:从 usage_events 明细按天聚合重算。
|
package/dist/stats/index.js
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
export { getDb, openReadonlyDb, getStatsDir, getDbPath, closeStatsDb, archiveOldData, listArchivePaths, rebuildDailyRollup } from './db.js';
|
|
5
5
|
export { normalizeUsage } from './normalizer.js';
|
|
6
6
|
export { initializeStatsPersistence, insertUsageEvent, insertContextBreakdown, insertMessageEvent, insertActivityEvent, insertModelCalls } from './writer.js';
|
|
7
|
-
export { calcCost, resolvePriceRow, resolveCanonicalModel, registerBillingFn } from './
|
|
8
|
-
export { queryAggregated, queryTodaySummary, queryStatusActivity, queryStatusActivityByAgent, querySessionTurns, queryContextBreakdown, queryTopPeers, queryTopModels, queryMessageAggregated, queryMessageTodaySummary, queryPeerList, querySummary, queryPeerDaily, queryTaskModelCalls, querySessionModelCalls } from './query.js';
|
|
7
|
+
export { calcCost, resolvePriceRow, resolveCanonicalModel, registerBillingFn } from './price-resolver.js';
|
|
8
|
+
export { queryAggregated, queryTodaySummary, queryStatusActivity, queryStatusActivityByAgent, querySessionTurns, queryContextBreakdown, queryTopPeers, queryTopModels, queryMessageAggregated, queryMessageTodaySummary, queryPeerList, querySummary, queryPeerDaily, queryTaskModelCalls, querySessionModelCalls, queryTaskSummary } from './query.js';
|
|
9
9
|
export { getBudgetStatus } from './budget.js';
|
|
10
10
|
export { getRoleBudgetStatus, formatUsageSubjectKey } from './role-budget.js';
|
|
11
11
|
export { buildSystemVars, buildTurnVars } from './eck-vars.js';
|