evolcore 0.0.39 → 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 +93 -0
- package/README.md +31 -20
- package/bin/codex-managed-hook.mjs +11 -0
- package/bin/ec-safe-output.js +25 -3
- package/dist/agents/baseagent-availability.js +1 -0
- package/dist/agents/claude-runner.js +53 -152
- package/dist/agents/codex-runner.js +485 -241
- package/dist/agents/ecagent-runner.js +48 -18
- package/dist/agents/gemini-runner.js +27 -8
- package/dist/agents/runner-types.js +39 -9
- package/dist/aun/ability-device-routing.js +26 -0
- package/dist/aun/aid/client.js +1 -1
- package/dist/aun/aid/control-aid.js +23 -98
- package/dist/aun/aid/ownership-operation.js +1 -3
- package/dist/aun/group/identity.js +8 -0
- package/dist/aun/group/invite-service.js +6 -0
- package/dist/aun/msg/managed-operation.js +4 -4
- package/dist/aun/msg/p2p.js +28 -12
- package/dist/aun/storage/download.js +30 -0
- package/dist/aun/storage/index.js +14 -6
- package/dist/channels/aun.js +99 -52
- package/dist/channels/daemon.js +24 -4
- package/dist/channels/dingtalk.js +8 -2
- package/dist/channels/feishu.js +6 -1
- package/dist/channels/wecom.js +7 -3
- package/dist/cli/agent-command.js +2 -0
- package/dist/cli/agent-create.js +121 -23
- package/dist/cli/agent.js +10 -3
- package/dist/cli/aid-bind-command.js +4 -1
- package/dist/cli/aun-commands.js +82 -22
- package/dist/cli/daemon-commands.js +260 -26
- package/dist/cli/index.js +25 -13
- package/dist/cli/memory-command.js +33 -14
- package/dist/cli/restart-monitor.js +52 -13
- package/dist/cli/session-command.js +128 -13
- package/dist/cli/stats.js +60 -4
- package/dist/cli/task-context.js +1 -0
- package/dist/cli/trigger-command.js +2 -2
- package/dist/config/access-policy.js +2 -0
- package/dist/config/config-field-policy.js +1 -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/contracts/ecweb-service-protocol.js +44 -0
- package/dist/core/agent-application-service.js +11 -1
- package/dist/core/agent-ipc-registration.js +4 -0
- package/dist/core/agent-runtime.js +6 -0
- package/dist/core/auth/agent-delegation.js +87 -9
- package/dist/core/auth/auth-gateway.js +3 -1
- package/dist/core/auth/authorization-audit.js +25 -4
- package/dist/core/auth/debug-context.js +5 -1
- package/dist/core/auth/operation-catalog.js +24 -0
- package/dist/core/command/agent-control.js +91 -12
- package/dist/core/command/command-handler.js +64 -47
- package/dist/core/command/connect-menu.js +23 -2
- package/dist/core/command/menu-catalog.js +49 -12
- package/dist/core/command/menu-handler.js +110 -105
- package/dist/core/command/menu-protocol.js +29 -3
- package/dist/core/command/role-menu.js +7 -6
- package/dist/core/command/slash-gate.js +22 -5
- package/dist/core/command/slash-handler.js +121 -102
- package/dist/core/event-catalog.js +17 -0
- package/dist/core/interaction-router.js +2 -1
- package/dist/core/ipc-registration.js +44 -8
- package/dist/core/memory/batch-meta.js +2 -0
- package/dist/core/memory/consolidation-context.js +42 -51
- package/dist/core/memory/consolidation-ops-records.js +39 -7
- package/dist/core/memory/consolidation-trigger.js +72 -65
- package/dist/core/memory/consolidation.js +226 -20
- package/dist/core/memory/memory-writer.js +160 -34
- package/dist/core/memory/relation-idle-monitor.js +287 -0
- package/dist/core/memory/relation-sweep.js +206 -0
- package/dist/core/message/aun-ipc-sender.js +31 -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 +96 -53
- package/dist/core/message/message-log.js +72 -0
- package/dist/core/message/message-queue.js +11 -5
- package/dist/core/message/outbound.js +70 -0
- package/dist/core/message/peer-mode.js +7 -2
- package/dist/core/message/response-engine.js +633 -191
- package/dist/core/model/model-catalog.js +7 -6
- package/dist/core/ownership/owner-resolver.js +384 -178
- package/dist/core/permission/ec-command-parser.js +129 -8
- package/dist/core/permission/tool-policy.js +35 -14
- package/dist/core/role/runtime-policy.js +64 -0
- package/dist/core/session/session-capsule.js +197 -0
- package/dist/core/session/session-manager.js +172 -18
- package/dist/core/session/session-mapper.js +2 -0
- package/dist/core/system-session/memory.js +3 -18
- package/dist/ecweb/basic-settings-service.js +709 -0
- package/dist/ecweb/providers-service.js +172 -0
- package/dist/index.js +95 -7
- package/dist/ipc.js +100 -19
- package/dist/stats/budget.js +1 -1
- package/dist/stats/db.js +48 -0
- package/dist/stats/index.js +3 -3
- package/dist/stats/price-resolver.js +304 -5
- package/dist/stats/query.js +328 -3
- package/dist/stats/writer.js +79 -6
- package/dist/trigger/application-service.js +12 -0
- package/dist/trigger/authorization.js +2 -2
- package/dist/trigger/feedback.js +18 -7
- package/dist/trigger/history.js +36 -0
- package/dist/trigger/manager.js +20 -3
- package/dist/trigger/parser.js +6 -3
- package/dist/trigger/patch.js +1 -1
- package/dist/trigger/scheduler.js +3 -0
- package/dist/trigger/system-definitions.js +43 -7
- package/dist/trigger/validation.js +13 -5
- package/dist/utils/ecweb-supervisor.js +31 -10
- package/dist/utils/error-utils.js +22 -4
- package/dist/utils/evolcore-version.js +3 -2
- package/dist/utils/host-info.js +52 -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/ecagent/dist/harness/agent-harness.js +4 -1
- package/kits/docs/INDEX.md +1 -1
- package/kits/docs/aun/ABILITY_CALLING.md +20 -2
- package/kits/docs/evolcore/INDEX.md +3 -2
- package/kits/docs/evolcore/agent-create.md +3 -2
- package/kits/docs/evolcore/agent.md +1 -1
- package/kits/docs/evolcore/aid.md +29 -12
- package/kits/docs/evolcore/config.md +9 -7
- package/kits/docs/evolcore/event.md +1 -0
- package/kits/docs/evolcore/fs.md +5 -0
- package/kits/docs/evolcore/memory-architecture.md +3 -4
- package/kits/docs/evolcore/memory-consolidation.md +28 -7
- package/kits/docs/evolcore/memory-tags.md +1 -1
- package/kits/docs/evolcore/memory.md +1 -1
- package/kits/docs/evolcore/menu-client.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +38 -0
- package/kits/docs/evolcore/msg.md +18 -2
- package/kits/docs/evolcore/session.md +14 -0
- package/kits/eck_manifest.json +3 -3
- package/kits/rules/04-relation.md +3 -2
- package/kits/schemas/agent-config.schema.13.json +20 -1
- package/kits/skills/aid-ability/SKILL.md +35 -6
- package/kits/templates/memory-consolidation/generalize.md +32 -4
- package/kits/templates/memory-consolidation/notes.md +2 -2
- package/kits/templates/memory-consolidation/promote.md +10 -2
- package/kits/templates/session-capsule/recovery.md +5 -0
- package/kits/templates/session-capsule/renew.md +5 -0
- package/kits/templates/system-fragments/baseagent.md +5 -0
- package/kits/templates/system-fragments/bootstrap.md +6 -6
- package/kits/templates/system-fragments/channel.md +1 -1
- package/kits/templates/system-fragments/memory.md +12 -3
- package/kits/templates/system-fragments/session.md +1 -1
- package/kits/{rules/07-memory-and-thread.md → templates/system-fragments/thread.md} +17 -80
- package/package.json +3 -3
- package/dist/stats/billing.js +0 -215
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';
|
|
@@ -25,6 +25,7 @@ import { RUNTIME_ENVIRONMENT_NAMES, setRuntimeEnvironmentOverride } from './conf
|
|
|
25
25
|
import { MAIN_CLI_BIN } from './product.js';
|
|
26
26
|
import { ownerResolver } from './core/ownership/owner-resolver.js';
|
|
27
27
|
import { parseOwnershipCommand, executeOwnershipCommand, ownershipFailure } from './aun/aid/ownership-operation.js';
|
|
28
|
+
import { ECWEB_SERVICE_PROTOCOL, validateEcwebClientProtocolRequirements, } from './contracts/ecweb-service-protocol.js';
|
|
28
29
|
import { delegationDiagnosticMessage, withDelegationDiagnosticContext, } from './core/auth/delegation-diagnostics.js';
|
|
29
30
|
const isWindows = process.platform === 'win32';
|
|
30
31
|
const isNamedPipe = (p) => isWindows && p.toLowerCase().startsWith('\\\\.\\pipe\\');
|
|
@@ -53,6 +54,7 @@ function parseRuntimeEnvironmentInput(value) {
|
|
|
53
54
|
return { ok: true, values };
|
|
54
55
|
}
|
|
55
56
|
const LOCAL_CONTROL_COMMANDS = new Set([
|
|
57
|
+
'service.handshake',
|
|
56
58
|
'bind.begin',
|
|
57
59
|
'bind.status',
|
|
58
60
|
'bind.cancel',
|
|
@@ -70,7 +72,10 @@ const LOCAL_CONTROL_COMMANDS = new Set([
|
|
|
70
72
|
'evolagent.load',
|
|
71
73
|
'evolagent.resync',
|
|
72
74
|
'menu.exec',
|
|
75
|
+
'ecweb.providers',
|
|
76
|
+
'ecweb.basic-settings',
|
|
73
77
|
'model.catalog',
|
|
78
|
+
'baseagent.snapshot',
|
|
74
79
|
'monitor-snapshot',
|
|
75
80
|
'monitor-subscribe',
|
|
76
81
|
'monitor-unsubscribe',
|
|
@@ -87,7 +92,7 @@ const MEMORY_COMMAND_ENDPOINTS = new Set([
|
|
|
87
92
|
const DELEGATED_ARGV_ENDPOINTS = new Set([
|
|
88
93
|
'agent.op', 'config.op', 'contact.op', 'aid.op', 'aid.ownership', 'group.op', 'msg.op', 'fs.op',
|
|
89
94
|
'ctl', 'diag', 'menu-client.request', 'task.resume', 'queue.op', 'storage.auth', 'storage.upload',
|
|
90
|
-
'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,
|
|
91
96
|
'handoff-return', 'handoff-recover-return', 'handoff-status', 'handoff-list', 'handoff-trace',
|
|
92
97
|
]);
|
|
93
98
|
let ipcQuerySequence = 0;
|
|
@@ -1004,15 +1009,23 @@ export class IpcServer {
|
|
|
1004
1009
|
return this.diagnosticRejection('daemon_restarted', cmd);
|
|
1005
1010
|
}
|
|
1006
1011
|
if (typeof cmd.delegationToken === 'string'
|
|
1007
|
-
&& (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))) {
|
|
1008
1014
|
if (!Array.isArray(cmd.argv) || cmd.argv.some(value => typeof value !== 'string')) {
|
|
1009
1015
|
return { ok: false, code: 'INVALID_REQUEST', error: 'Invalid command argv' };
|
|
1010
1016
|
}
|
|
1011
|
-
const
|
|
1017
|
+
const expectedArgv = [
|
|
1012
1018
|
MAIN_CLI_BIN,
|
|
1013
1019
|
...(cmd.type === 'menu-client.request' ? ['menu-client'] : []),
|
|
1014
1020
|
...cmd.argv,
|
|
1015
|
-
]
|
|
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);
|
|
1016
1029
|
if (!expectedHash || cmd.delegationCommandHash !== expectedHash) {
|
|
1017
1030
|
return this.diagnosticRejection('command_hash_mismatch', cmd);
|
|
1018
1031
|
}
|
|
@@ -1094,6 +1107,14 @@ export class IpcServer {
|
|
|
1094
1107
|
return this.diagExecutor ? this.diagExecutor(cmd) : { ok: false, code: 'NOT_CONFIGURED', message: '诊断入口未配置' };
|
|
1095
1108
|
case 'menu-client.request':
|
|
1096
1109
|
return this.menuClientExecutor ? this.menuClientExecutor(cmd) : { ok: false, code: 'NOT_CONFIGURED', error: 'Managed Menu client is not configured' };
|
|
1110
|
+
case 'ecweb.providers': {
|
|
1111
|
+
const { handleProvidersService } = await import('./ecweb/providers-service.js');
|
|
1112
|
+
return handleProvidersService(cmd.request);
|
|
1113
|
+
}
|
|
1114
|
+
case 'ecweb.basic-settings': {
|
|
1115
|
+
const { handleBasicSettingsService } = await import('./ecweb/basic-settings-service.js');
|
|
1116
|
+
return handleBasicSettingsService(cmd.request);
|
|
1117
|
+
}
|
|
1097
1118
|
case 'model.catalog': {
|
|
1098
1119
|
if ((cmd.self !== undefined && typeof cmd.self !== 'string')
|
|
1099
1120
|
|| (cmd.baseagent !== undefined && !['claude', 'codex', 'ecagent', 'gemini'].includes(cmd.baseagent))) {
|
|
@@ -1113,6 +1134,25 @@ export class IpcServer {
|
|
|
1113
1134
|
return { ok: false, error: 'Unable to resolve model catalog configuration' };
|
|
1114
1135
|
}
|
|
1115
1136
|
}
|
|
1137
|
+
case 'baseagent.snapshot': {
|
|
1138
|
+
if (cmd.probe !== undefined && typeof cmd.probe !== 'boolean') {
|
|
1139
|
+
return { ok: false, code: 'INVALID_REQUEST', error: 'probe must be a boolean' };
|
|
1140
|
+
}
|
|
1141
|
+
try {
|
|
1142
|
+
const { getBaseagentSnapshot } = await import('./agents/baseagent-availability.js');
|
|
1143
|
+
return {
|
|
1144
|
+
ok: true,
|
|
1145
|
+
snapshot: await getBaseagentSnapshot({ probe: cmd.probe !== false }),
|
|
1146
|
+
};
|
|
1147
|
+
}
|
|
1148
|
+
catch (error) {
|
|
1149
|
+
return {
|
|
1150
|
+
ok: false,
|
|
1151
|
+
code: 'BASEAGENT_SNAPSHOT_UNAVAILABLE',
|
|
1152
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1153
|
+
};
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1116
1156
|
case 'status':
|
|
1117
1157
|
return this.getStatus();
|
|
1118
1158
|
case 'codex-pre-tool-use': {
|
|
@@ -1152,6 +1192,34 @@ export class IpcServer {
|
|
|
1152
1192
|
protocolVersion: 1,
|
|
1153
1193
|
uptime: Math.round(process.uptime() * 1000),
|
|
1154
1194
|
};
|
|
1195
|
+
case 'service.handshake': {
|
|
1196
|
+
const protocol = {
|
|
1197
|
+
major: ECWEB_SERVICE_PROTOCOL.major,
|
|
1198
|
+
minor: ECWEB_SERVICE_PROTOCOL.minor,
|
|
1199
|
+
};
|
|
1200
|
+
const requirementsError = validateEcwebClientProtocolRequirements(cmd.requirements);
|
|
1201
|
+
const error = cmd.service !== ECWEB_SERVICE_PROTOCOL.name
|
|
1202
|
+
? `Unsupported service: ${String(cmd.service ?? 'missing')}`
|
|
1203
|
+
: requirementsError;
|
|
1204
|
+
if (error) {
|
|
1205
|
+
return {
|
|
1206
|
+
ok: false,
|
|
1207
|
+
code: 'SERVICE_PROTOCOL_MISMATCH',
|
|
1208
|
+
service: ECWEB_SERVICE_PROTOCOL.name,
|
|
1209
|
+
protocol,
|
|
1210
|
+
capabilities: ECWEB_SERVICE_PROTOCOL.capabilities,
|
|
1211
|
+
compatible: false,
|
|
1212
|
+
error,
|
|
1213
|
+
};
|
|
1214
|
+
}
|
|
1215
|
+
return {
|
|
1216
|
+
ok: true,
|
|
1217
|
+
service: ECWEB_SERVICE_PROTOCOL.name,
|
|
1218
|
+
protocol,
|
|
1219
|
+
capabilities: ECWEB_SERVICE_PROTOCOL.capabilities,
|
|
1220
|
+
compatible: true,
|
|
1221
|
+
};
|
|
1222
|
+
}
|
|
1155
1223
|
case 'shutdown': {
|
|
1156
1224
|
if (!this.shutdownExecutor)
|
|
1157
1225
|
return { ok: false, error: 'shutdown executor not configured' };
|
|
@@ -1367,6 +1435,7 @@ export class IpcServer {
|
|
|
1367
1435
|
sessionId: cmd.sessionId,
|
|
1368
1436
|
delegationToken: typeof cmd.delegationToken === 'string' ? cmd.delegationToken : undefined,
|
|
1369
1437
|
delegationCommandHash: typeof cmd.delegationCommandHash === 'string' ? cmd.delegationCommandHash : undefined,
|
|
1438
|
+
argv: Array.isArray(cmd.argv) ? cmd.argv : undefined,
|
|
1370
1439
|
});
|
|
1371
1440
|
}
|
|
1372
1441
|
case 'storage.auth': {
|
|
@@ -1375,7 +1444,7 @@ export class IpcServer {
|
|
|
1375
1444
|
if (typeof cmd.sessionId !== 'string' || !cmd.sessionId || typeof cmd.aid !== 'string' || !cmd.aid || typeof cmd.operation !== 'string') {
|
|
1376
1445
|
return { ok: false, code: 'INVALID_REQUEST', error: 'missing sessionId, aid, or operation' };
|
|
1377
1446
|
}
|
|
1378
|
-
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)) {
|
|
1379
1448
|
return { ok: false, code: 'INVALID_REQUEST', error: 'invalid storage operation' };
|
|
1380
1449
|
}
|
|
1381
1450
|
return await this.storageAuthorizationExecutor({
|
|
@@ -1454,7 +1523,7 @@ export class IpcServer {
|
|
|
1454
1523
|
}
|
|
1455
1524
|
case 'local-command-context': {
|
|
1456
1525
|
if (!Array.isArray(cmd.argv) || cmd.argv.some((value) => typeof value !== 'string')
|
|
1457
|
-
|| !['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
|
|
1458
1527
|
|| typeof cmd.delegationToken !== 'string' || !cmd.delegationToken) {
|
|
1459
1528
|
return { ok: false, code: 'INVALID_REQUEST', error: 'Local command requires argv and task credentials' };
|
|
1460
1529
|
}
|
|
@@ -1586,6 +1655,7 @@ export class IpcServer {
|
|
|
1586
1655
|
aid: cmd.aid,
|
|
1587
1656
|
to: cmd.to,
|
|
1588
1657
|
scope: cmd.scope === 'group' ? 'group' : 'msg',
|
|
1658
|
+
deviceId: cmd.deviceId,
|
|
1589
1659
|
payload: normalizedPayload,
|
|
1590
1660
|
rawPayload: cmd.rawPayload === true,
|
|
1591
1661
|
file,
|
|
@@ -1849,7 +1919,7 @@ export class IpcServer {
|
|
|
1849
1919
|
}
|
|
1850
1920
|
}
|
|
1851
1921
|
case 'memory.create': {
|
|
1852
|
-
const { sessionId, scope, slug, description, content, tags, keywords, replaces, targetPeerKey, generalizedFrom, promotedFrom } = cmd;
|
|
1922
|
+
const { sessionId, scope, slug, description, content, tags, keywords, replaces, targetPeerKey, generalizedFrom, promotedFrom, reason } = cmd;
|
|
1853
1923
|
if (!sessionId)
|
|
1854
1924
|
return { ok: false, code: 'INVALID_REQUEST', error: 'missing sessionId' };
|
|
1855
1925
|
try {
|
|
@@ -1876,12 +1946,12 @@ export class IpcServer {
|
|
|
1876
1946
|
catch (e) {
|
|
1877
1947
|
const batchDir = guard.taskCtx.consolidationBatchDir;
|
|
1878
1948
|
if (batchDir)
|
|
1879
|
-
appendOpsRecord(batchDir, { ts: new Date().toISOString(), op: 'create', scope: scope ?? '', target: slug ?? '', ok: false, error: e?.message });
|
|
1949
|
+
appendOpsRecord(batchDir, { ts: new Date().toISOString(), op: 'create', scope: scope ?? '', target: slug ?? '', ok: false, error: e?.message, ...(reason ? { reason } : {}) });
|
|
1880
1950
|
throw e;
|
|
1881
1951
|
}
|
|
1882
1952
|
const batchDir = guard.taskCtx.consolidationBatchDir;
|
|
1883
1953
|
if (batchDir)
|
|
1884
|
-
appendOpsRecord(batchDir, { ts: new Date().toISOString(), op: 'create', scope: scope ?? '', target: slug ?? '', filePath: createResult.filePath, archivedFiles: createResult.archived.map((dest, i) => ({ source:
|
|
1954
|
+
appendOpsRecord(batchDir, { ts: new Date().toISOString(), op: 'create', scope: scope ?? '', target: slug ?? '', filePath: createResult.filePath, archivedFiles: createResult.archived.map((dest, i) => ({ source: createResult.archivedSources[i] ?? dest, archivedTo: dest })), tags: Array.isArray(tags) ? tags : [], memoryDir: createResult.scopeDirs.memoryDir, ok: true, ...(reason ? { reason } : {}) });
|
|
1885
1955
|
return { ok: true, filePath: createResult.filePath, archived: createResult.archived };
|
|
1886
1956
|
}
|
|
1887
1957
|
catch (e) {
|
|
@@ -1889,7 +1959,7 @@ export class IpcServer {
|
|
|
1889
1959
|
}
|
|
1890
1960
|
}
|
|
1891
1961
|
case 'memory.update': {
|
|
1892
|
-
const { sessionId, filePath, tags, touch } = cmd;
|
|
1962
|
+
const { sessionId, filePath, tags, touch, reason } = cmd;
|
|
1893
1963
|
if (!sessionId)
|
|
1894
1964
|
return { ok: false, code: 'INVALID_REQUEST', error: 'missing sessionId' };
|
|
1895
1965
|
try {
|
|
@@ -1912,12 +1982,14 @@ export class IpcServer {
|
|
|
1912
1982
|
catch (e) {
|
|
1913
1983
|
const batchDir = guard.taskCtx.consolidationBatchDir;
|
|
1914
1984
|
if (batchDir)
|
|
1915
|
-
appendOpsRecord(batchDir, { ts: new Date().toISOString(), op: 'update', scope: guard.writeScope, target: filePath ?? '', ok: false, error: e?.message });
|
|
1985
|
+
appendOpsRecord(batchDir, { ts: new Date().toISOString(), op: 'update', scope: guard.writeScope, target: filePath ?? '', ok: false, error: e?.message, ...(reason ? { reason } : {}) });
|
|
1916
1986
|
throw e;
|
|
1917
1987
|
}
|
|
1918
1988
|
const batchDirU = guard.taskCtx.consolidationBatchDir;
|
|
1989
|
+
// target 记解析后的绝对路径:回滚直接拿它读写文件,argv 原文(如 consolidated/x.md)
|
|
1990
|
+
// 会相对 daemon 的 cwd 解析而找不到。memoryDir 记文件实际所在层,供收尾重建索引。
|
|
1919
1991
|
if (batchDirU)
|
|
1920
|
-
appendOpsRecord(batchDirU, { ts: new Date().toISOString(), op: 'update', scope: guard.writeScope, target: filePath
|
|
1992
|
+
appendOpsRecord(batchDirU, { ts: new Date().toISOString(), op: 'update', scope: guard.writeScope, target: updateResult.filePath, tags: Array.isArray(tags) ? tags : undefined, prevTags: updateResult.prevTags, memoryDir: updateResult.targetMemoryDir, ok: true, ...(reason ? { reason } : {}) });
|
|
1921
1993
|
return { ok: true, filePath: updateResult.filePath };
|
|
1922
1994
|
}
|
|
1923
1995
|
catch (e) {
|
|
@@ -1925,14 +1997,14 @@ export class IpcServer {
|
|
|
1925
1997
|
}
|
|
1926
1998
|
}
|
|
1927
1999
|
case 'memory.archive': {
|
|
1928
|
-
const { sessionId, filePaths } = cmd;
|
|
2000
|
+
const { sessionId, filePaths, reason } = cmd;
|
|
1929
2001
|
if (!sessionId)
|
|
1930
2002
|
return { ok: false, code: 'INVALID_REQUEST', error: 'missing sessionId' };
|
|
1931
2003
|
try {
|
|
1932
2004
|
const guard = await this.assertMemoryWriteSession(sessionId, undefined, 'archive', undefined, cmd.debug === true);
|
|
1933
2005
|
if ('error' in guard)
|
|
1934
2006
|
return guard.error;
|
|
1935
|
-
const { archiveMemory } = await import('./core/memory/memory-writer.js');
|
|
2007
|
+
const { archiveMemory, sourceMemoryDirOf } = await import('./core/memory/memory-writer.js');
|
|
1936
2008
|
const { appendOpsRecord } = await import('./core/memory/consolidation-ops-records.js');
|
|
1937
2009
|
let archiveResult;
|
|
1938
2010
|
try {
|
|
@@ -1946,15 +2018,20 @@ export class IpcServer {
|
|
|
1946
2018
|
catch (e) {
|
|
1947
2019
|
const batchDir = guard.taskCtx.consolidationBatchDir;
|
|
1948
2020
|
if (batchDir)
|
|
1949
|
-
appendOpsRecord(batchDir, { ts: new Date().toISOString(), op: 'archive', scope: guard.writeScope, target: (Array.isArray(filePaths) ? filePaths : []).join(', '), ok: false, error: e?.message });
|
|
2021
|
+
appendOpsRecord(batchDir, { ts: new Date().toISOString(), op: 'archive', scope: guard.writeScope, target: (Array.isArray(filePaths) ? filePaths : []).join(', '), ok: false, error: e?.message, ...(reason ? { reason } : {}) });
|
|
1950
2022
|
throw e;
|
|
1951
2023
|
}
|
|
1952
2024
|
const batchDirA = guard.taskCtx.consolidationBatchDir;
|
|
1953
2025
|
if (batchDirA) {
|
|
1954
2026
|
for (let i = 0; i < archiveResult.archived.length; i++) {
|
|
1955
2027
|
const archivedTo = archiveResult.archived[i];
|
|
1956
|
-
|
|
1957
|
-
|
|
2028
|
+
// 用解析后的绝对路径,不用 argv 原文:回滚直接拿 sourceFile 做 renameSync,
|
|
2029
|
+
// 相对路径会相对 daemon 的 cwd 解析,跨关系回滚会落到不相干的位置。
|
|
2030
|
+
const sourceFile = archiveResult.archivedSources[i] ?? archivedTo;
|
|
2031
|
+
// memoryDir 取**源文件所属层**,不是本作用域:collectAffectedScopes 靠它
|
|
2032
|
+
// 决定收尾重建哪几层索引,写成本作用域会导致关系级索引不重建。
|
|
2033
|
+
const srcMemoryDir = sourceMemoryDirOf(sourceFile);
|
|
2034
|
+
appendOpsRecord(batchDirA, { ts: new Date().toISOString(), op: 'archive', scope: guard.writeScope, target: archivedTo, sourceFile, archivedTo, memoryDir: srcMemoryDir, ok: true, ...(reason ? { reason } : {}) });
|
|
1958
2035
|
}
|
|
1959
2036
|
}
|
|
1960
2037
|
return { ok: true, archived: archiveResult.archived };
|
|
@@ -2631,14 +2708,18 @@ function ipcQueryOnce(socketPath, cmd, timeoutMs = 3000) {
|
|
|
2631
2708
|
...authenticatedCmd.argv,
|
|
2632
2709
|
]
|
|
2633
2710
|
: undefined;
|
|
2711
|
+
const executionSpec = typeof authenticatedCmd.delegationToken === 'string'
|
|
2712
|
+
? readDelegatedExecutionSpec()
|
|
2713
|
+
: undefined;
|
|
2634
2714
|
const delegationCommandHash = typeof authenticatedCmd.delegationToken === 'string'
|
|
2635
2715
|
&& typeof authenticatedCmd.delegationCommandHash !== 'string'
|
|
2636
2716
|
? requestArgv
|
|
2637
|
-
? hashDelegatedCommandArgv(requestArgv)
|
|
2717
|
+
? hashDelegatedCommandArgv(requestArgv, executionSpec)
|
|
2638
2718
|
: hashCurrentDelegatedCommand()
|
|
2639
2719
|
: undefined;
|
|
2640
2720
|
const request = {
|
|
2641
2721
|
...(delegationCommandHash ? { ...authenticatedCmd, delegationCommandHash } : authenticatedCmd),
|
|
2722
|
+
...(executionSpec ? { executionSpec: JSON.stringify(executionSpec) } : {}),
|
|
2642
2723
|
...(process.env[DAEMON_RUNTIME_EPOCH_ENV]
|
|
2643
2724
|
&& authenticatedCmd.daemonRuntimeEpoch === undefined
|
|
2644
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
|
@@ -28,6 +28,10 @@ export function getStatsDir(evolcoreHome) {
|
|
|
28
28
|
export function getDbPath(evolcoreHome) {
|
|
29
29
|
return path.join(getStatsDir(evolcoreHome), 'usage.db');
|
|
30
30
|
}
|
|
31
|
+
const ACTIVITY_EVENT_RETENTION_MS = 48 * 60 * 60 * 1000;
|
|
32
|
+
function pruneActivityEvents(db, now = Date.now()) {
|
|
33
|
+
db.prepare('DELETE FROM activity_events WHERE ts < ?').run(now - ACTIVITY_EVENT_RETENTION_MS);
|
|
34
|
+
}
|
|
31
35
|
export function closeStatsDb() {
|
|
32
36
|
if (!_db)
|
|
33
37
|
return;
|
|
@@ -73,6 +77,12 @@ export function startDailyRollupMaintenance(evolcoreHome) {
|
|
|
73
77
|
const db = getDb(evolcoreHome);
|
|
74
78
|
if (!db)
|
|
75
79
|
return undefined;
|
|
80
|
+
try {
|
|
81
|
+
pruneActivityEvents(db);
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
logger.warn(`[Stats] activity_events 清理失败(非致命): ${error}`);
|
|
85
|
+
}
|
|
76
86
|
try {
|
|
77
87
|
const daily = db.prepare('SELECT COUNT(*) AS n FROM usage_daily').get();
|
|
78
88
|
const events = db.prepare('SELECT COUNT(*) AS n FROM usage_events').get();
|
|
@@ -85,6 +95,12 @@ export function startDailyRollupMaintenance(evolcoreHome) {
|
|
|
85
95
|
logger.warn(`[Stats] usage_daily 回填检测失败(非致命): ${error}`);
|
|
86
96
|
}
|
|
87
97
|
return setInterval(() => {
|
|
98
|
+
try {
|
|
99
|
+
pruneActivityEvents(db);
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
logger.warn(`[Stats] activity_events 清理失败(非致命): ${error}`);
|
|
103
|
+
}
|
|
88
104
|
try {
|
|
89
105
|
rebuildDailyRollup(evolcoreHome);
|
|
90
106
|
}
|
|
@@ -179,6 +195,22 @@ function _initTables(db) {
|
|
|
179
195
|
CREATE INDEX IF NOT EXISTS idx_me_agent_ts ON message_events(agent_aid, ts);
|
|
180
196
|
CREATE INDEX IF NOT EXISTS idx_me_peer_ts ON message_events(agent_aid, peer_key, ts);
|
|
181
197
|
|
|
198
|
+
-- Persisted task lifecycle counters used by status activity windows.
|
|
199
|
+
CREATE TABLE IF NOT EXISTS activity_events (
|
|
200
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
201
|
+
ts INTEGER NOT NULL,
|
|
202
|
+
agent_aid TEXT NOT NULL DEFAULT '',
|
|
203
|
+
type TEXT NOT NULL,
|
|
204
|
+
duration_ms INTEGER,
|
|
205
|
+
error_type TEXT
|
|
206
|
+
);
|
|
207
|
+
CREATE INDEX IF NOT EXISTS idx_ae_ts ON activity_events(ts);
|
|
208
|
+
CREATE INDEX IF NOT EXISTS idx_ae_agent_ts ON activity_events(agent_aid, ts);
|
|
209
|
+
CREATE TABLE IF NOT EXISTS activity_meta (
|
|
210
|
+
key TEXT PRIMARY KEY,
|
|
211
|
+
value TEXT NOT NULL
|
|
212
|
+
);
|
|
213
|
+
|
|
182
214
|
-- 按天预聚合表:grain = 天 × agent × peer × session × model × billing_fn。
|
|
183
215
|
-- 由 writer.ts 写时增量 UPSERT 维护,rebuildDailyRollup() 全量重建纠偏。
|
|
184
216
|
-- 保留 model+billing_fn 维度以便查询时仍按 calcCost 现算成本。
|
|
@@ -240,6 +272,7 @@ function _initTables(db) {
|
|
|
240
272
|
CREATE INDEX IF NOT EXISTS idx_mc_agentsession ON model_calls(agent_session_id);
|
|
241
273
|
CREATE INDEX IF NOT EXISTS idx_mc_ts ON model_calls(ts);
|
|
242
274
|
`);
|
|
275
|
+
db.prepare(`INSERT OR IGNORE INTO activity_meta (key, value) VALUES ('activity_events_started_at', ?)`).run(String(Date.now()));
|
|
243
276
|
// ── Schema Migration: 添加 cost 列 ───────────────────────────────────────
|
|
244
277
|
try {
|
|
245
278
|
const cols = db.prepare(`PRAGMA table_info(usage_events)`).all();
|
|
@@ -312,6 +345,21 @@ function _initTables(db) {
|
|
|
312
345
|
catch (e) {
|
|
313
346
|
logger.warn(`[StatsDB] model_calls context window 迁移检测失败: ${e}`);
|
|
314
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
|
+
}
|
|
315
363
|
}
|
|
316
364
|
/**
|
|
317
365
|
* 全量重建 usage_daily:从 usage_events 明细按天聚合重算。
|
package/dist/stats/index.js
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export { getDb, openReadonlyDb, getStatsDir, getDbPath, closeStatsDb, archiveOldData, listArchivePaths, rebuildDailyRollup } from './db.js';
|
|
5
5
|
export { normalizeUsage } from './normalizer.js';
|
|
6
|
-
export { initializeStatsPersistence, insertUsageEvent, insertContextBreakdown, insertMessageEvent, insertModelCalls } from './writer.js';
|
|
7
|
-
export { calcCost, resolvePriceRow, resolveCanonicalModel, registerBillingFn } from './
|
|
8
|
-
export { queryAggregated, queryTodaySummary, querySessionTurns, queryContextBreakdown, queryTopPeers, queryTopModels, queryMessageAggregated, queryMessageTodaySummary, queryPeerList, querySummary, queryPeerDaily, queryTaskModelCalls, querySessionModelCalls } from './query.js';
|
|
6
|
+
export { initializeStatsPersistence, insertUsageEvent, insertContextBreakdown, insertMessageEvent, insertActivityEvent, insertModelCalls } from './writer.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';
|