evolcore 0.0.40 → 0.0.41-test.1
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 +94 -1
- package/bin/codex-managed-hook.mjs +11 -0
- package/bin/ec-safe-output.js +11 -1
- package/dist/agents/baseagent-availability.js +1 -1
- package/dist/agents/baseagent.js +20 -43
- package/dist/agents/claude-runner.js +197 -197
- package/dist/agents/codex-runner.js +535 -259
- package/dist/agents/ecagent-runner.js +31 -12
- package/dist/agents/gemini-runner.js +27 -7
- 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/fs-download.js +39 -0
- package/dist/aun/group/identity.js +36 -13
- package/dist/aun/group/operations.js +5 -0
- package/dist/aun/msg/managed-operation.js +72 -11
- package/dist/aun/msg/p2p.js +32 -7
- package/dist/aun/service-proxy.js +36 -12
- package/dist/aun/storage/download.js +30 -0
- package/dist/aun/storage/index.js +14 -6
- package/dist/channels/aun.js +367 -24
- package/dist/channels/daemon.js +39 -5
- 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 +85 -41
- package/dist/cli/daemon-commands.js +678 -688
- package/dist/cli/fs-command.js +64 -2
- package/dist/cli/index.js +48 -4
- package/dist/cli/managed-command-guard.js +4 -0
- package/dist/cli/model.js +40 -40
- package/dist/cli/proxy-command.js +92 -0
- package/dist/cli/restart-monitor.js +17 -0
- package/dist/cli/role.js +85 -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 +8 -1
- package/dist/config/boot-log.js +38 -1
- package/dist/config/config-field-policy.js +5 -32
- package/dist/config/config-manager.js +46 -39
- package/dist/config/config-operation-service.js +8 -11
- package/dist/config/contact-book-store.js +47 -21
- package/dist/config/contact-book.js +18 -12
- package/dist/config/contact-operation-service.js +3 -4
- package/dist/config/contact-request-service.js +11 -0
- package/dist/config/daemon-services.js +11 -0
- package/dist/config/gateway-config.js +89 -595
- package/dist/config/peer-role-resolver.js +15 -11
- package/dist/config/providers-config.js +12 -7
- package/dist/config/providers-import.js +3 -21
- package/dist/config/resolved-config-op.js +3 -0
- package/dist/config/role-command-service.js +166 -0
- package/dist/config/role-request-service.js +193 -0
- package/dist/config/schema-migration.js +686 -25
- package/dist/config-store.js +79 -3
- package/dist/contracts/ecweb-instance.js +41 -0
- package/dist/contracts/ecweb-service-protocol.js +3 -1
- package/dist/core/agent-application-service.js +11 -1
- package/dist/core/agent-ipc-registration.js +4 -0
- package/dist/core/agent-runtime.js +1 -1
- package/dist/core/auth/agent-delegation.js +82 -6
- package/dist/core/auth/auth-gateway.js +1 -1
- package/dist/core/auth/authorization-audit.js +37 -9
- package/dist/core/auth/delegation-authorization.js +3 -1
- package/dist/core/auth/operation-authorizer.js +15 -0
- package/dist/core/auth/operation-catalog.js +39 -6
- package/dist/core/command/agent-control.js +94 -19
- package/dist/core/command/agent-storage-menu.js +5 -3
- package/dist/core/command/cli-intent-parser.js +2 -1
- package/dist/core/command/command-handler.js +105 -145
- package/dist/core/command/connect-menu.js +31 -2
- package/dist/core/command/data-root-resolver.js +5 -4
- package/dist/core/command/memory-slash.js +16 -8
- package/dist/core/command/menu-catalog.js +6 -6
- package/dist/core/command/menu-handler.js +87 -163
- package/dist/core/command/menu-protocol.js +9 -2
- package/dist/core/command/role-menu.js +148 -30
- package/dist/core/command/slash-gate.js +13 -10
- package/dist/core/command/slash-handler.js +157 -352
- package/dist/core/daemon-control.js +8 -14
- package/dist/core/event-catalog.js +15 -0
- package/dist/core/evolagent-registry.js +4 -4
- package/dist/core/evolagent.js +2 -2
- package/dist/core/inference/text-inference.js +31 -40
- package/dist/core/ipc-registration.js +24 -3
- package/dist/core/memory/consolidation-context.js +51 -5
- package/dist/core/memory/consolidation-ops-records.js +1 -1
- package/dist/core/memory/consolidation-trigger.js +190 -190
- package/dist/core/memory/consolidation.js +316 -29
- package/dist/core/memory/forget-log.js +96 -0
- package/dist/core/memory/index-manager.js +27 -5
- package/dist/core/memory/memory-admin.js +45 -5
- package/dist/core/memory/memory-writer.js +163 -18
- package/dist/core/memory/relation-idle-monitor.js +119 -58
- package/dist/core/memory/relation-sweep.js +44 -39
- package/dist/core/message/aun-ipc-sender.js +34 -7
- package/dist/core/message/aun-request-registry.js +97 -3
- package/dist/core/message/im-renderer.js +11 -4
- package/dist/core/message/message-admission.js +97 -8
- package/dist/core/message/message-bridge.js +71 -24
- 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 +387 -144
- package/dist/core/model/catalog-service.js +4 -2
- package/dist/core/model/config-scope.js +24 -64
- package/dist/core/model/field-scope.js +1 -1
- package/dist/core/model/model-catalog.js +37 -47
- package/dist/core/model/model-diagnostics.js +4 -3
- package/dist/core/model/model-fallback.js +10 -7
- package/dist/core/model/model-permission.js +3 -2
- package/dist/core/ownership/owner-resolver.js +25 -23
- package/dist/core/permission/ec-command-parser.js +138 -5
- package/dist/core/permission/sandbox-runtime.js +18 -1
- package/dist/core/permission/tool-policy.js +42 -10
- package/dist/core/relation/peer-identity.js +64 -1
- package/dist/core/role/runtime-policy.js +72 -13
- package/dist/core/session/session-capsule.js +197 -0
- package/dist/core/session/session-idle-monitor.js +1 -1
- package/dist/core/session/session-manager.js +168 -14
- package/dist/core/session/session-mapper.js +2 -0
- package/dist/core/session/session-renew.js +3 -3
- package/dist/core/skill/index-generator.js +15 -5
- package/dist/core/system-session/memory.js +6 -1
- package/dist/core/thread/thread-service.js +19 -6
- package/dist/directory/owner-directory-admission.js +95 -0
- package/dist/directory/owner-directory-authorization.js +309 -0
- package/dist/directory/owner-directory-cache.js +635 -0
- package/dist/eck/kit-renderer.js +2 -2
- package/dist/ecweb/basic-settings-service.js +33 -40
- package/dist/ecweb/message-context-service.js +110 -0
- package/dist/index.js +79 -17
- package/dist/ipc.js +189 -17
- package/dist/paths.js +4 -0
- package/dist/proxy/command.js +122 -0
- package/dist/proxy/ipc-service.js +68 -0
- package/dist/proxy/manager.js +485 -0
- package/dist/proxy/service-supervisor.js +603 -0
- package/dist/response-system/engines/v1/proactive-flow.js +16 -6
- 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/cross-platform.js +14 -0
- package/dist/utils/ecweb-supervisor.js +258 -83
- package/dist/utils/error-utils.js +16 -2
- package/dist/utils/logger.js +24 -5
- package/dist/utils/npm-ops.js +2 -1
- package/dist/utils/package-version-info.js +5 -3
- 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/channels/aun.md +9 -0
- 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 +18 -7
- package/kits/docs/evolcore/contact.md +3 -0
- package/kits/docs/evolcore/event.md +1 -0
- package/kits/docs/evolcore/fs.md +16 -0
- package/kits/docs/evolcore/memory-architecture.md +2 -2
- package/kits/docs/evolcore/memory-consolidation.md +32 -8
- package/kits/docs/evolcore/memory.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +36 -0
- package/kits/docs/evolcore/model.md +23 -20
- package/kits/docs/evolcore/msg.md +21 -8
- package/kits/docs/evolcore/session.md +14 -0
- package/kits/migrations/migrate-contact-book-v2.mjs +30 -11
- package/kits/schemas/_meta.json +37 -4
- package/kits/schemas/agent-config.schema.13.json +23 -3
- package/kits/schemas/agent-config.schema.16.json +891 -0
- package/kits/schemas/daemon.schema.9.json +366 -0
- package/kits/schemas/defaults.schema.5.json +406 -127
- package/kits/schemas/relation-config.schema.11.json +260 -0
- package/kits/schemas/role-config.schema.1.json +7 -7
- package/kits/skills/.switches.json +3 -7
- package/kits/skills/aid-ability/SKILL.md +35 -6
- package/kits/skills/ec-service-proxy/SKILL.md +118 -0
- package/kits/skills/ec-trigger/SKILL.md +13 -5
- package/kits/skills/personal-assistant/SKILL.md +176 -0
- package/kits/skills/personal-assistant/references/01-workspace-spec.md +333 -0
- package/kits/skills/personal-assistant/references/02-bootstrap.md +205 -0
- package/kits/skills/personal-assistant/references/03-data-flow-and-gaps.md +177 -0
- package/kits/skills/personal-assistant/references/04-frontend-contract.md +439 -0
- package/kits/skills/personal-assistant/references/05-directory-reference.md +292 -0
- package/kits/skills/personal-assistant/references/06-render-config.md +350 -0
- package/kits/skills/personal-assistant/schema/workspace.schema.json +85 -0
- package/kits/skills/personal-assistant/schema/workspace.v1.json +66 -0
- package/kits/skills/personal-assistant/scripts/archive.mjs +154 -0
- package/kits/skills/personal-assistant/scripts/check.mjs +114 -0
- package/kits/skills/personal-assistant/scripts/index-rebuild.mjs +252 -0
- package/kits/skills/personal-assistant/scripts/ingest.mjs +344 -0
- package/kits/skills/personal-assistant/scripts/init.mjs +270 -0
- package/kits/skills/personal-assistant/scripts/lib/apply.mjs +92 -0
- package/kits/skills/personal-assistant/scripts/lib/schema.mjs +96 -0
- package/kits/skills/personal-assistant/scripts/lib/time.mjs +28 -0
- package/kits/skills/personal-assistant/scripts/migrate.mjs +172 -0
- package/kits/skills/personal-assistant/scripts/search.mjs +172 -0
- package/kits/skills/personal-assistant/scripts/verify.mjs +196 -0
- package/kits/skills/personal-assistant/templates/INDEX.md.tpl +24 -0
- package/kits/skills/personal-assistant/templates/README.md.tpl +108 -0
- package/kits/skills/personal-assistant/triggers/ingest-daily.json +23 -0
- package/kits/skills/personal-assistant/triggers/memory-consolidate.json +23 -0
- package/kits/skills/personal-assistant/triggers/report-daily.json +23 -0
- package/kits/skills/personal-assistant/triggers/report-weekly.json +23 -0
- package/kits/templates/memory-consolidation/forget.md +19 -6
- package/kits/templates/memory-consolidation/notes.md +1 -1
- package/kits/templates/memory-consolidation/profile.md +2 -2
- package/kits/templates/memory-consolidation/promote.md +20 -3
- package/kits/templates/roles/member.json +8 -1
- 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 +2 -2
- 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 +4 -4
- package/package.json +7 -3
- package/dist/stats/billing.js +0 -215
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import { resolvePaths, resolveRoot } from '../paths.js';
|
|
4
|
+
import { authorizeLocalCommand } from './task-context.js';
|
|
5
|
+
import { findSessionCapsule, materializeSessionCapsules } from '../core/session/session-capsule.js';
|
|
4
6
|
import { scanChatDirs, readLastJsonlLine, } from '../core/session/session-fs-store.js';
|
|
5
7
|
const HELP_TEXT = `
|
|
6
8
|
ec session <command> [options]
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
本地会话文件查询(读取 $EVOLCORE_HOME/agents/ 下的存档;托管任务先经 daemon 鉴权)。
|
|
9
11
|
|
|
10
12
|
命令:
|
|
11
13
|
find <sessionId> 按 ec 会话 id(meta_YYYYMMDD_<ts>)定位 session 文件,
|
|
12
14
|
输出 agentSessionId 与所在位置等元数据
|
|
15
|
+
source <sessionId> 查询直接来源 EC 会话(根会话无来源)
|
|
16
|
+
capsule list <sessionId> 列出该 EC 会话使用的恢复/renew 胶囊
|
|
17
|
+
capsule show <capsuleId> 查看胶囊正文和底层会话轮换关系
|
|
13
18
|
help 显示本帮助
|
|
14
19
|
|
|
15
20
|
选项:
|
|
@@ -58,7 +63,52 @@ function findMetaInTrash(chatDir, metaFileName) {
|
|
|
58
63
|
catch { /* 目录不存在,跳过 */ }
|
|
59
64
|
return hits;
|
|
60
65
|
}
|
|
61
|
-
async function
|
|
66
|
+
async function authorizedChatDirs(args) {
|
|
67
|
+
let scope;
|
|
68
|
+
if (process.env.EVOLCORE_SESSION_ID) {
|
|
69
|
+
scope = await authorizeLocalCommand(['session', ...args]);
|
|
70
|
+
if (!scope.selfAid || !scope.peerRole || scope.peerRole === 'none')
|
|
71
|
+
throw new Error('当前任务身份不可用');
|
|
72
|
+
}
|
|
73
|
+
return scanChatDirs(resolvePaths().sessionsDir).filter(chat => {
|
|
74
|
+
if (!scope)
|
|
75
|
+
return true;
|
|
76
|
+
if (chat.selfAID !== scope.selfAid)
|
|
77
|
+
return false;
|
|
78
|
+
if (scope.peerRole === 'owner' || scope.peerRole === 'admin')
|
|
79
|
+
return true;
|
|
80
|
+
return !!scope.channel && !!scope.channelId
|
|
81
|
+
&& chat.channelType === scope.channel && chat.channelId === scope.channelId;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
function findRecords(chats, sessionId) {
|
|
85
|
+
if (!/^meta_[A-Za-z0-9_-]+$/u.test(sessionId))
|
|
86
|
+
throw new Error('无效的 EC 会话 ID');
|
|
87
|
+
return chats.flatMap(chat => {
|
|
88
|
+
const locations = [...findMetaInChatDir(chat.dirPath, `${sessionId}.jsonl`), ...findMetaInTrash(chat.dirPath, `${sessionId}.jsonl`)];
|
|
89
|
+
const records = locations.flatMap(file => {
|
|
90
|
+
const meta = readLastJsonlLine(file);
|
|
91
|
+
return meta?.id === sessionId ? [{ chat, file, meta }] : [];
|
|
92
|
+
});
|
|
93
|
+
if (records.length)
|
|
94
|
+
return records;
|
|
95
|
+
const file = path.join(chat.dirPath, 'active.json');
|
|
96
|
+
const meta = readJsonFileSafe(file);
|
|
97
|
+
return meta?.id === sessionId ? [{ chat, file, meta }] : [];
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
function printCapsule(capsule) {
|
|
101
|
+
console.log(`胶囊: ${capsule.capsuleId}`);
|
|
102
|
+
console.log(` EC 会话: ${capsule.sessionId}`);
|
|
103
|
+
if (capsule.sourceSessionId)
|
|
104
|
+
console.log(` 来源 EC 会话: ${capsule.sourceSessionId}`);
|
|
105
|
+
console.log(` cause: ${capsule.cause}`);
|
|
106
|
+
console.log(` sourceAgentSessionId: ${capsule.sourceAgentSessionId ?? '(无)'}`);
|
|
107
|
+
console.log(` agentSessionId: ${capsule.agentSessionId ?? '(尚未绑定)'}`);
|
|
108
|
+
console.log(` 创建: ${new Date(capsule.createdAt).toISOString()}`);
|
|
109
|
+
console.log(` 消费: ${capsule.consumedAt === undefined ? '(待接收)' : new Date(capsule.consumedAt).toISOString()}`);
|
|
110
|
+
}
|
|
111
|
+
async function cmdFind(args, chatDirs) {
|
|
62
112
|
const jsonFormat = hasFlag(args, '--format') && argValue(args, '--format') === 'json'
|
|
63
113
|
|| hasFlag(args, '--json');
|
|
64
114
|
// 位置参数已在调用处剥掉子命令,第一个非 flag 参数即 sessionId
|
|
@@ -70,14 +120,12 @@ async function cmdFind(args) {
|
|
|
70
120
|
}
|
|
71
121
|
// 允许传入带或不带 .jsonl 后缀的 id
|
|
72
122
|
const sessionId = rawId.endsWith('.jsonl') ? rawId.slice(0, -'.jsonl'.length) : rawId;
|
|
73
|
-
if (
|
|
123
|
+
if (!/^meta_[A-Za-z0-9_-]+$/u.test(sessionId)) {
|
|
74
124
|
console.error(`✗ ec 会话 id 应以 meta_ 开头(如 meta_20261012_1791789158257),收到: ${rawId}`);
|
|
75
125
|
process.exitCode = 1;
|
|
76
126
|
return;
|
|
77
127
|
}
|
|
78
128
|
const metaFileName = `${sessionId}.jsonl`;
|
|
79
|
-
const p = resolvePaths();
|
|
80
|
-
const chatDirs = scanChatDirs(p.sessionsDir);
|
|
81
129
|
const found = [];
|
|
82
130
|
for (const chat of chatDirs) {
|
|
83
131
|
const locations = [
|
|
@@ -90,6 +138,7 @@ async function cmdFind(args) {
|
|
|
90
138
|
continue;
|
|
91
139
|
found.push({
|
|
92
140
|
sessionId: meta.id || sessionId,
|
|
141
|
+
sourceSessionId: meta.sourceSessionId ?? null,
|
|
93
142
|
metaFile,
|
|
94
143
|
sessionKey: meta.sessionKey,
|
|
95
144
|
agentSessionId: meta.agentSessionId ?? null,
|
|
@@ -114,6 +163,7 @@ async function cmdFind(args) {
|
|
|
114
163
|
if (active && active.id === sessionId) {
|
|
115
164
|
found.push({
|
|
116
165
|
sessionId,
|
|
166
|
+
sourceSessionId: active.sourceSessionId ?? null,
|
|
117
167
|
metaFile: activeFile,
|
|
118
168
|
sessionKey: active.sessionKey,
|
|
119
169
|
agentSessionId: active.agentSessionId ?? null,
|
|
@@ -147,6 +197,8 @@ async function cmdFind(args) {
|
|
|
147
197
|
}
|
|
148
198
|
for (const f of found) {
|
|
149
199
|
console.log(`ec 会话 id: ${f.sessionId}`);
|
|
200
|
+
if (f.sourceSessionId)
|
|
201
|
+
console.log(` sourceSessionId: ${f.sourceSessionId}`);
|
|
150
202
|
console.log(` agentSessionId: ${f.agentSessionId ?? '(空)'}`);
|
|
151
203
|
console.log(` baseagent: ${f.baseagent ?? '(未知)'}`);
|
|
152
204
|
console.log(` threadId: ${f.threadId || '(主会话)'}`);
|
|
@@ -182,13 +234,76 @@ export async function runSessionCommand(args) {
|
|
|
182
234
|
console.log(HELP_TEXT);
|
|
183
235
|
return;
|
|
184
236
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
237
|
+
try {
|
|
238
|
+
const chats = await authorizedChatDirs(args);
|
|
239
|
+
const json = argValue(args, '--format') === 'json' || hasFlag(args, '--json');
|
|
240
|
+
switch (sub) {
|
|
241
|
+
case 'find':
|
|
242
|
+
await cmdFind(args.slice(1), chats);
|
|
243
|
+
break;
|
|
244
|
+
case 'source': {
|
|
245
|
+
const id = args[1];
|
|
246
|
+
if (!id || id.startsWith('-'))
|
|
247
|
+
throw new Error('用法: ec session source <sessionId>');
|
|
248
|
+
const found = findRecords(chats, id);
|
|
249
|
+
if (!found.length)
|
|
250
|
+
throw new Error(`未找到会话 ${id}`);
|
|
251
|
+
const sources = found.map(({ meta }) => ({ sessionId: meta.id, sourceSessionId: meta.sourceSessionId ?? null }));
|
|
252
|
+
if (json)
|
|
253
|
+
console.log(JSON.stringify({ ok: true, found: sources }, null, 2));
|
|
254
|
+
else
|
|
255
|
+
for (const source of sources)
|
|
256
|
+
console.log(source.sourceSessionId ?? '(根会话,无来源)');
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
case 'capsule': {
|
|
260
|
+
const operation = args[1];
|
|
261
|
+
const id = args[2];
|
|
262
|
+
if (!id || id.startsWith('-'))
|
|
263
|
+
throw new Error('用法: ec session capsule list <sessionId> | show <capsuleId>');
|
|
264
|
+
if (operation === 'list') {
|
|
265
|
+
const found = findRecords(chats, id);
|
|
266
|
+
if (!found.length)
|
|
267
|
+
throw new Error(`未找到会话 ${id}`);
|
|
268
|
+
const capsules = [...new Set(found.map(record => record.chat.dirPath))]
|
|
269
|
+
.flatMap(chat => materializeSessionCapsules(chat).filter(capsule => capsule.sessionId === id));
|
|
270
|
+
if (json)
|
|
271
|
+
console.log(JSON.stringify({ ok: true, sessionId: id, capsules }, null, 2));
|
|
272
|
+
else if (!capsules.length)
|
|
273
|
+
console.log('(无胶囊)');
|
|
274
|
+
else
|
|
275
|
+
for (const capsule of capsules)
|
|
276
|
+
printCapsule(capsule);
|
|
277
|
+
}
|
|
278
|
+
else if (operation === 'show') {
|
|
279
|
+
if (!/^cap_[A-Za-z0-9_-]+$/u.test(id))
|
|
280
|
+
throw new Error('无效的胶囊 ID');
|
|
281
|
+
const capsules = chats.flatMap(chat => {
|
|
282
|
+
const capsule = findSessionCapsule(chat.dirPath, id);
|
|
283
|
+
return capsule ? [capsule] : [];
|
|
284
|
+
});
|
|
285
|
+
if (!capsules.length)
|
|
286
|
+
throw new Error(`未找到胶囊 ${id}`);
|
|
287
|
+
if (json)
|
|
288
|
+
console.log(JSON.stringify({ ok: true, capsules }, null, 2));
|
|
289
|
+
else
|
|
290
|
+
for (const capsule of capsules) {
|
|
291
|
+
printCapsule(capsule);
|
|
292
|
+
console.log(`\n${capsule.content}\n`);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
else
|
|
296
|
+
throw new Error('用法: ec session capsule list <sessionId> | show <capsuleId>');
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
default:
|
|
300
|
+
console.error(`✗ 未知子命令: ${sub}`);
|
|
301
|
+
console.log(HELP_TEXT);
|
|
302
|
+
process.exitCode = 1;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
catch (error) {
|
|
306
|
+
console.error(`✗ ${error instanceof Error ? error.message : String(error)}`);
|
|
307
|
+
process.exitCode = 1;
|
|
193
308
|
}
|
|
194
309
|
}
|
package/dist/cli/stats.js
CHANGED
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
import { resolveRoot } from '../paths.js';
|
|
5
5
|
import { wantsHelp } from './help.js';
|
|
6
6
|
import { authorizeLocalCommand } from './task-context.js';
|
|
7
|
-
import { queryAggregated, querySessionTurns, queryContextBreakdown, queryTopPeers, queryTopModels, queryMessageAggregated, queryPeerList, querySummary, queryPeerDaily, queryTaskModelCalls, querySessionModelCalls } from '../stats/query.js';
|
|
7
|
+
import { queryAggregated, querySessionTurns, queryContextBreakdown, queryTopPeers, queryTopModels, queryMessageAggregated, queryPeerList, querySummary, queryPeerDaily, queryTaskModelCalls, querySessionModelCalls, queryTaskSummary } from '../stats/query.js';
|
|
8
8
|
import { getBudgetStatus } from '../stats/budget.js';
|
|
9
|
+
import { normalizeUsage } from '../stats/normalizer.js';
|
|
9
10
|
const HELP = `ec stats — Token 用量与费用统计
|
|
10
11
|
|
|
11
12
|
Usage: ec stats [options]
|
|
@@ -266,6 +267,48 @@ export async function handleStats(args) {
|
|
|
266
267
|
}
|
|
267
268
|
}
|
|
268
269
|
console.log(`${GREEN}✓ 回填完成:${updated} 条事件${RESET}`);
|
|
270
|
+
// 步骤1b:回填 model_calls 的 cost 字段(逐次调用明细,同样只处理金额为 NULL 的行)
|
|
271
|
+
// 明细行与 usage_events 走同一套价目,回填后 task 级金额可直接 SUM 对账。
|
|
272
|
+
let callsUpdated = 0;
|
|
273
|
+
try {
|
|
274
|
+
const pendingCalls = db.prepare(`
|
|
275
|
+
SELECT id, ts, agent_aid, peer_key, session_id, model,
|
|
276
|
+
input_tokens, output_tokens, cache_creation_tokens, cache_read_tokens
|
|
277
|
+
FROM model_calls WHERE cost_official_usd IS NULL
|
|
278
|
+
`).all();
|
|
279
|
+
for (let i = 0; i < pendingCalls.length; i += batchSize) {
|
|
280
|
+
db.exec('BEGIN');
|
|
281
|
+
const batch = pendingCalls.slice(i, i + batchSize);
|
|
282
|
+
for (const call of batch) {
|
|
283
|
+
const event = normalizeUsage({
|
|
284
|
+
input_tokens: call.input_tokens ?? 0,
|
|
285
|
+
output_tokens: call.output_tokens ?? 0,
|
|
286
|
+
cache_creation_input_tokens: call.cache_creation_tokens ?? 0,
|
|
287
|
+
cache_read_input_tokens: call.cache_read_tokens ?? 0,
|
|
288
|
+
}, {
|
|
289
|
+
ts: call.ts,
|
|
290
|
+
agent_aid: call.agent_aid ?? '',
|
|
291
|
+
peer_key: call.peer_key ?? '',
|
|
292
|
+
session_id: call.session_id ?? undefined,
|
|
293
|
+
model: call.model || 'unknown',
|
|
294
|
+
turns: 1,
|
|
295
|
+
});
|
|
296
|
+
const prices = resolvePrices(home, event);
|
|
297
|
+
db.prepare(`
|
|
298
|
+
UPDATE model_calls
|
|
299
|
+
SET cost_official_usd = ?, cost_official_cny = ?,
|
|
300
|
+
cost_gateway_usd = ?, cost_gateway_cny = ?
|
|
301
|
+
WHERE id = ?
|
|
302
|
+
`).run(prices.official?.usd ?? null, prices.official?.cny ?? null, prices.gateway?.usd ?? null, prices.gateway?.cny ?? null, call.id);
|
|
303
|
+
callsUpdated++;
|
|
304
|
+
}
|
|
305
|
+
db.exec('COMMIT');
|
|
306
|
+
}
|
|
307
|
+
console.log(`${GREEN}✓ 模型调用明细回填完成:${callsUpdated} 条${RESET}`);
|
|
308
|
+
}
|
|
309
|
+
catch (e) {
|
|
310
|
+
console.log(`${YELLOW}⚠ 模型调用明细回填跳过:${e?.message || e}${RESET}`);
|
|
311
|
+
}
|
|
269
312
|
// 步骤2:重建 usage_daily(会自动聚合 cost 字段)
|
|
270
313
|
console.log(`${CYAN}正在重建日聚合表...${RESET}`);
|
|
271
314
|
const n = rebuildDailyRollup(home);
|
|
@@ -432,17 +475,30 @@ export async function handleStats(args) {
|
|
|
432
475
|
return;
|
|
433
476
|
}
|
|
434
477
|
console.log(`\n${BOLD}📊 模型用量明细 — ${key}${RESET}\n`);
|
|
435
|
-
const headers = ['#', 'Model', 'Source', 'Input', 'Output', 'CacheR', 'CacheW', '
|
|
478
|
+
const headers = ['#', 'Model', 'Source', 'Input', 'Output', 'CacheR', 'CacheW', 'Official', 'Gateway', 'Provider Thread', 'Deg'];
|
|
436
479
|
const tableRows = rows.map(r => [
|
|
437
480
|
String(r.call_index),
|
|
438
481
|
r.model.split('-').slice(0, 3).join('-'),
|
|
439
482
|
r.source,
|
|
440
483
|
fmtTokens(r.input_tokens), fmtTokens(r.output_tokens),
|
|
441
484
|
fmtTokens(r.cache_read_tokens), fmtTokens(r.cache_creation_tokens),
|
|
485
|
+
r.cost_official_usd != null && r.cost_official_usd > 0 ? '$' + r.cost_official_usd.toFixed(4) : '—',
|
|
486
|
+
r.cost_gateway_usd != null && r.cost_gateway_usd > 0 ? '$' + r.cost_gateway_usd.toFixed(4) : '—',
|
|
442
487
|
r.provider_thread_id ?? '',
|
|
443
|
-
r.
|
|
488
|
+
r.degraded ? 'Y' : '',
|
|
444
489
|
]);
|
|
445
490
|
printTable(headers, tableRows);
|
|
491
|
+
// 汇总行
|
|
492
|
+
if (byTask) {
|
|
493
|
+
const sum = queryTaskSummary(home, key);
|
|
494
|
+
console.log(`\n Tokens: input ${fmtTokens(sum.input_tokens)} output ${fmtTokens(sum.output_tokens)} cache_read ${fmtTokens(sum.cache_read_tokens)} cache_write ${fmtTokens(sum.cache_creation_tokens)}`);
|
|
495
|
+
if (sum.cost_official_usd > 0 || sum.cost_official_cny > 0) {
|
|
496
|
+
console.log(` Official: ${GREEN}$${sum.cost_official_usd.toFixed(4)}${RESET} ¥${sum.cost_official_cny.toFixed(4)}`);
|
|
497
|
+
}
|
|
498
|
+
if (sum.cost_gateway_usd > 0 || sum.cost_gateway_cny > 0) {
|
|
499
|
+
console.log(` Gateway: ${GREEN}$${sum.cost_gateway_usd.toFixed(4)}${RESET} ¥${sum.cost_gateway_cny.toFixed(4)}`);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
446
502
|
console.log();
|
|
447
503
|
return;
|
|
448
504
|
}
|
|
@@ -610,7 +666,7 @@ export async function handleStats(args) {
|
|
|
610
666
|
const totCacheAll = totIn + totCacheRead;
|
|
611
667
|
const sessionCacheHitRate = totCacheAll > 0 ? totCacheRead / totCacheAll : 0;
|
|
612
668
|
// model_spec
|
|
613
|
-
const { resolveModelSpec } = await import('../stats/
|
|
669
|
+
const { resolveModelSpec } = await import('../stats/price-resolver.js');
|
|
614
670
|
const spec = resolveModelSpec(home, last.model);
|
|
615
671
|
const result = {
|
|
616
672
|
turn: {
|
|
@@ -365,7 +365,7 @@ export async function buildTriggerCreateRequest(args, fileScope, defaultAgentAid
|
|
|
365
365
|
...(parsed.targetSession === 'thread' ? { threadId: parsed.targetThreadId } : {}),
|
|
366
366
|
},
|
|
367
367
|
},
|
|
368
|
-
reliability: { concurrency: 'forbid', missedPolicy: 'run_once', retry: { maxAttempts:
|
|
368
|
+
reliability: { concurrency: 'forbid', missedPolicy: 'run_once', retry: { maxAttempts: 1, backoffMs: 30_000 } },
|
|
369
369
|
limits: limitsFromParsed(parsed),
|
|
370
370
|
};
|
|
371
371
|
const files = script ? [{
|
|
@@ -654,7 +654,7 @@ function loadDefinitionWithFiles(inputPath, fileScope) {
|
|
|
654
654
|
const stat = fs.statSync(inputPath);
|
|
655
655
|
const baseDir = stat.isDirectory() ? inputPath : path.dirname(inputPath);
|
|
656
656
|
const jsonPath = stat.isDirectory() ? path.join(inputPath, 'trigger.json') : inputPath;
|
|
657
|
-
const definition = normalizeTriggerDefinition(JSON.parse(readTriggerLocalFile(jsonPath, fileScope).toString('utf8')));
|
|
657
|
+
const definition = normalizeTriggerDefinition(JSON.parse(readTriggerLocalFile(jsonPath, fileScope).toString('utf8')), { allowLegacyZeroRetryAttempts: true });
|
|
658
658
|
if (fileScope && definition.agentAid !== fileScope.selfAid)
|
|
659
659
|
throw new Error('imported Trigger must belong to the authorized Agent');
|
|
660
660
|
const files = [];
|
|
@@ -12,13 +12,16 @@ export class AccessPolicyError extends Error {
|
|
|
12
12
|
}
|
|
13
13
|
export const DEFAULT_ACCESS_POLICY = Object.freeze({
|
|
14
14
|
policyMode: 'open',
|
|
15
|
+
allowOwnerDirectoryContacts: true,
|
|
16
|
+
allowOwnerAgentDirectory: true,
|
|
17
|
+
allowExternalContacts: false,
|
|
15
18
|
requestLimit: Object.freeze({ maxTimes: 600, coolDown: 60 * 60 }),
|
|
16
19
|
});
|
|
17
20
|
export function listAgentOwners(selfAid) {
|
|
18
21
|
const agent = read(ConfigTarget.Agent, { self: selfAid }, { cache: true });
|
|
19
22
|
return validAgentOwnerIds(agent);
|
|
20
23
|
}
|
|
21
|
-
/** Missing AgentConfig.access
|
|
24
|
+
/** Missing AgentConfig.access disables ordinary external contacts; explicit policies are preserved. */
|
|
22
25
|
export function readAccessPolicy(selfAid) {
|
|
23
26
|
return readAccessPolicySnapshot(selfAid).policy;
|
|
24
27
|
}
|
|
@@ -91,6 +94,10 @@ function assertAccessPolicyWrite(input, agent, policy) {
|
|
|
91
94
|
function clonePolicy(policy) {
|
|
92
95
|
return {
|
|
93
96
|
policyMode: policy.policyMode,
|
|
97
|
+
allowOwnerDirectoryContacts: policy.allowOwnerDirectoryContacts ?? true,
|
|
98
|
+
allowOwnerAgentDirectory: policy.allowOwnerAgentDirectory ?? true,
|
|
99
|
+
allowExternalContacts: policy.allowExternalContacts ?? false,
|
|
100
|
+
allowedAids: [...(policy.allowedAids ?? [])],
|
|
94
101
|
requestLimit: { ...policy.requestLimit },
|
|
95
102
|
};
|
|
96
103
|
}
|
package/dist/config/boot-log.js
CHANGED
|
@@ -15,7 +15,7 @@ import { logger } from '../utils/logger.js';
|
|
|
15
15
|
import { autoMigrateIfNeeded } from '../config-store.js';
|
|
16
16
|
import { ConfigTarget, initConfigManager, notifyConfigWrite } from './config-manager.js';
|
|
17
17
|
import { ensureRoleConfigV4OnStartup, ensureRoleConfigV5OnStartup } from './role-migration-startup.js';
|
|
18
|
-
import { ensureAuxiliaryModelMigrationOnStartup } from './schema-migration.js';
|
|
18
|
+
import { ensureAgentModelProviderMigrationOnStartup, ensureAgentOnlyModelMigrationOnStartup, ensureAuxiliaryModelMigrationOnStartup, ensureProviderServiceTypeMigrationOnStartup, ensureRelationConfigVersionMigrationOnStartup } from './schema-migration.js';
|
|
19
19
|
import { ensureContactBookV2OnStartup } from './contact-book-v2-startup.js';
|
|
20
20
|
import { synchronizeAllManagementContactsSync } from './contact-book-store.js';
|
|
21
21
|
import { readInstalledEvolcoreVersion, readFastaunVersion } from '../utils/evolcore-version.js';
|
|
@@ -34,6 +34,43 @@ export async function prepareStartupConfig(recoverRoleMutations) {
|
|
|
34
34
|
logger.info(message);
|
|
35
35
|
console.error(message);
|
|
36
36
|
}
|
|
37
|
+
const agentOnlyModelMigration = await ensureAgentOnlyModelMigrationOnStartup();
|
|
38
|
+
if (agentOnlyModelMigration) {
|
|
39
|
+
const message = `✓ Agent-only model migration applied automatically: removed relation/defaults model parameters from ${agentOnlyModelMigration.changedFiles} file(s)`
|
|
40
|
+
+ (agentOnlyModelMigration.backup ? `; backup: ${agentOnlyModelMigration.backup}` : '');
|
|
41
|
+
logger.info(message);
|
|
42
|
+
console.error(message);
|
|
43
|
+
for (const detail of agentOnlyModelMigration.details) {
|
|
44
|
+
logger.info(`[config] ${detail.file}: removed ${detail.removed.join(', ')}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const modelProviderMigration = await ensureAgentModelProviderMigrationOnStartup();
|
|
48
|
+
if (modelProviderMigration) {
|
|
49
|
+
const message = `✓ Agent model provider migration applied automatically: gateway information moved into providers.json, ${modelProviderMigration.changedFiles} file(s) updated`
|
|
50
|
+
+ (modelProviderMigration.backup ? `; backup: ${modelProviderMigration.backup}` : '');
|
|
51
|
+
logger.info(message);
|
|
52
|
+
console.error(message);
|
|
53
|
+
for (const detail of modelProviderMigration.details) {
|
|
54
|
+
logger.info(`[config] ${detail.file}${detail.removed.length ? `: removed ${detail.removed.join(', ')}` : ''}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const providerServiceTypeMigration = await ensureProviderServiceTypeMigrationOnStartup();
|
|
58
|
+
if (providerServiceTypeMigration) {
|
|
59
|
+
const message = `✓ Agent provider service type migration applied automatically: removed from ${providerServiceTypeMigration.changedFiles} config file(s)`
|
|
60
|
+
+ (providerServiceTypeMigration.backup ? `; backup: ${providerServiceTypeMigration.backup}` : '');
|
|
61
|
+
logger.info(message);
|
|
62
|
+
console.error(message);
|
|
63
|
+
for (const detail of providerServiceTypeMigration.details) {
|
|
64
|
+
logger.info(`[config] ${detail.file}: removed ${detail.removed.join(', ')}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const relationVersionMigration = await ensureRelationConfigVersionMigrationOnStartup();
|
|
68
|
+
if (relationVersionMigration) {
|
|
69
|
+
const message = `✓ Relation config version migration applied automatically: ${relationVersionMigration.changedFiles} file(s) restamped`
|
|
70
|
+
+ (relationVersionMigration.backup ? `; backup: ${relationVersionMigration.backup}` : '');
|
|
71
|
+
logger.info(message);
|
|
72
|
+
console.error(message);
|
|
73
|
+
}
|
|
37
74
|
const migration = await ensureRoleConfigV4OnStartup();
|
|
38
75
|
if (migration) {
|
|
39
76
|
const message = `✓ Role config v4 migration applied automatically: ${migration.changedFiles} file(s)`
|
|
@@ -21,15 +21,10 @@ const BEHAVIOR_TOP_FIELDS = new Set([
|
|
|
21
21
|
const BASEAGENT_BEHAVIOR_FIELDS = new Set([
|
|
22
22
|
'model',
|
|
23
23
|
'effort',
|
|
24
|
-
'auxiliaryModel',
|
|
25
|
-
'auxiliaryEffort',
|
|
26
24
|
'reasoning',
|
|
27
25
|
'agentProgressSummaries',
|
|
28
26
|
'excludeDynamicSections',
|
|
29
27
|
'enableRequestUserInput',
|
|
30
|
-
'approvalsReviewer',
|
|
31
|
-
'mode',
|
|
32
|
-
'useVertex',
|
|
33
28
|
]);
|
|
34
29
|
const SUPPORTED_BASEAGENTS = new Set(['claude', 'codex', 'gemini', 'ecagent']);
|
|
35
30
|
/** Public behavior fields for a runner this version does not implement. */
|
|
@@ -52,10 +47,10 @@ const SENSITIVE_TOP_FIELDS = new Set([
|
|
|
52
47
|
'owners',
|
|
53
48
|
'access',
|
|
54
49
|
'fullaccess',
|
|
50
|
+
'sessionFullAccess',
|
|
55
51
|
'admins',
|
|
56
52
|
'channels',
|
|
57
53
|
'aun',
|
|
58
|
-
'models',
|
|
59
54
|
'projects',
|
|
60
55
|
'capabilities',
|
|
61
56
|
'debug',
|
|
@@ -63,7 +58,6 @@ const SENSITIVE_TOP_FIELDS = new Set([
|
|
|
63
58
|
'roles',
|
|
64
59
|
'role',
|
|
65
60
|
'extra_backup',
|
|
66
|
-
'decision_model',
|
|
67
61
|
]);
|
|
68
62
|
const CRITICAL_AGENT_FIELDS = new Set(['owner', 'owners', 'admins', 'roles', 'access']);
|
|
69
63
|
const EFFORTS = new Set(['low', 'medium', 'high', 'xhigh', 'max']);
|
|
@@ -99,19 +93,13 @@ export function resolveConfigFieldRule(fieldPath, scope) {
|
|
|
99
93
|
const [, baseagent, leaf] = parts;
|
|
100
94
|
if (!SUPPORTED_BASEAGENTS.has(baseagent))
|
|
101
95
|
return { class: 'unknown' };
|
|
102
|
-
const normalizedLeaf = leaf === 'reasoning'
|
|
103
|
-
? 'effort'
|
|
104
|
-
: leaf === 'auxiliaryModel'
|
|
105
|
-
? 'model'
|
|
106
|
-
: leaf === 'auxiliaryEffort'
|
|
107
|
-
? 'effort'
|
|
108
|
-
: leaf;
|
|
96
|
+
const normalizedLeaf = leaf === 'reasoning' ? 'effort' : leaf;
|
|
109
97
|
const permissionKey = `baseagents.${baseagent}.${normalizedLeaf}`;
|
|
110
98
|
if (leaf === 'provider' && parts.length === 3)
|
|
111
99
|
return scalar(permissionKey, 'string', 'owner-only');
|
|
112
|
-
if (
|
|
100
|
+
if (leaf === 'model' && parts.length === 3)
|
|
113
101
|
return scalar(permissionKey, 'string');
|
|
114
|
-
if ((leaf === 'effort' || leaf === 'reasoning'
|
|
102
|
+
if ((leaf === 'effort' || leaf === 'reasoning') && parts.length === 3)
|
|
115
103
|
return scalar(permissionKey, 'effort');
|
|
116
104
|
if (baseagent === 'claude' && (leaf === 'agentProgressSummaries' || leaf === 'excludeDynamicSections') && parts.length === 3) {
|
|
117
105
|
return scalar(permissionKey, 'boolean');
|
|
@@ -119,13 +107,6 @@ export function resolveConfigFieldRule(fieldPath, scope) {
|
|
|
119
107
|
if (baseagent === 'codex' && leaf === 'enableRequestUserInput' && parts.length === 3) {
|
|
120
108
|
return scalar(permissionKey, 'boolean');
|
|
121
109
|
}
|
|
122
|
-
if (baseagent === 'codex' && leaf === 'approvalsReviewer' && parts.length === 3) {
|
|
123
|
-
return scalar(permissionKey, 'approvals-reviewer');
|
|
124
|
-
}
|
|
125
|
-
if (baseagent === 'gemini' && leaf === 'mode' && parts.length === 3)
|
|
126
|
-
return scalar(permissionKey, 'gemini-mode');
|
|
127
|
-
if (baseagent === 'gemini' && leaf === 'useVertex' && parts.length === 3)
|
|
128
|
-
return scalar(permissionKey, 'boolean');
|
|
129
110
|
return { class: 'sensitive' };
|
|
130
111
|
}
|
|
131
112
|
if (field === 'active_baseagent')
|
|
@@ -228,8 +209,8 @@ export function resolveConfigFieldRule(fieldPath, scope) {
|
|
|
228
209
|
// 数值参数:整理节奏与容量上限,均 owner-only
|
|
229
210
|
if (field === 'memory.idleHours'
|
|
230
211
|
|| field === 'memory.maxUnconsolidatedHours'
|
|
212
|
+
|| field === 'memory.minBatchItems'
|
|
231
213
|
|| field === 'memory.checkIntervalHours'
|
|
232
|
-
|| field === 'memory.backlogHours'
|
|
233
214
|
|| field === 'memory.indexMaxBytes'
|
|
234
215
|
|| field === 'memory.forgetAfterDays'
|
|
235
216
|
|| field === 'memory.profileRegenDays') {
|
|
@@ -339,14 +320,6 @@ export function parseConfigFieldValue(fieldPath, rawValue) {
|
|
|
339
320
|
return raw === 'all' || raw === 'text' || raw === 'none'
|
|
340
321
|
? { ok: true, value: raw }
|
|
341
322
|
: { ok: false, reason: `Config field ${fieldPath} must be all, text, or none` };
|
|
342
|
-
case 'approvals-reviewer':
|
|
343
|
-
return ['user', 'auto_review', 'guardian_subagent'].includes(raw)
|
|
344
|
-
? { ok: true, value: raw }
|
|
345
|
-
: { ok: false, reason: `Config field ${fieldPath} has an invalid approvals reviewer` };
|
|
346
|
-
case 'gemini-mode':
|
|
347
|
-
return raw === 'cli' || raw === 'sdk'
|
|
348
|
-
? { ok: true, value: raw }
|
|
349
|
-
: { ok: false, reason: `Config field ${fieldPath} must be cli or sdk` };
|
|
350
323
|
case 'manifest-file':
|
|
351
324
|
return /^[A-Za-z0-9_-]+\.json$/.test(raw)
|
|
352
325
|
? { ok: true, value: raw }
|