evolcore 0.0.24 → 0.0.25
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 +578 -561
- package/LICENSE +21 -21
- package/README.md +455 -455
- package/bin/codex-managed-acl.ps1 +160 -160
- package/bin/codex-managed-hook.mjs +208 -208
- package/bin/ec-safe-output.js +327 -327
- package/bin/ec.js +29 -29
- package/bin/install-codex-managed-hooks.mjs +555 -555
- package/dist/agents/claude-runner.js +4 -1
- package/dist/agents/codex-runner.js +7 -4
- package/dist/agents/ecagent-runner.js +14 -13
- package/dist/agents/gemini-runner.js +22 -2
- package/dist/aun/aid/agentmd.js +56 -4
- package/dist/aun/aid/index.js +1 -0
- package/dist/aun/aid/managed-operation.js +53 -1
- package/dist/aun/storage/client.js +4 -1
- package/dist/aun/storage/index.js +1 -1
- package/dist/cli/agent-command.js +186 -87
- package/dist/cli/agent-create.js +42 -4
- package/dist/cli/agent.js +103 -1
- package/dist/cli/aun-commands.js +360 -294
- package/dist/cli/bench.js +20 -20
- package/dist/cli/config.js +20 -20
- package/dist/cli/contact.js +10 -10
- package/dist/cli/ctl-command.js +22 -22
- package/dist/cli/daemon-commands.js +15 -15
- package/dist/cli/fs-command.js +67 -67
- package/dist/cli/handoff-command.js +7 -7
- package/dist/cli/index.js +77 -77
- package/dist/cli/link-rules.js +21 -21
- package/dist/cli/menu-client.js +11 -11
- package/dist/cli/net-check.js +22 -22
- package/dist/cli/queue-command.js +29 -29
- package/dist/cli/response.js +30 -30
- package/dist/cli/restart-monitor.js +30 -30
- package/dist/cli/stats.js +51 -51
- package/dist/cli/trigger-command.js +56 -56
- package/dist/config/builtin-roles.js +1 -0
- package/dist/config/config-manager.js +15 -0
- package/dist/config/config-operation-service.js +20 -3
- package/dist/config/resolved-config-op.js +39 -1
- package/dist/core/auth/operation-authorizer.js +62 -4
- package/dist/core/auth/operation-catalog.js +16 -0
- package/dist/core/command/agent-control.js +54 -25
- package/dist/core/command/cli-intent-parser.js +18 -0
- package/dist/core/command/command-handler.js +91 -16
- package/dist/core/command/menu-catalog.js +1 -0
- package/dist/core/command/menu-handler.js +41 -5
- package/dist/core/command/menu-protocol.js +1 -0
- package/dist/core/command/slash-handler.js +9 -9
- package/dist/core/event-catalog.js +5 -0
- package/dist/core/evolagent.js +3 -3
- package/dist/core/message/response-engine.js +12 -6
- package/dist/core/permission/tool-policy.js +45 -6
- package/dist/index.js +209 -162
- package/dist/stats/db.js +159 -159
- package/dist/stats/eck-vars.js +9 -9
- package/dist/stats/query.js +139 -139
- package/dist/stats/role-budget.js +6 -6
- package/dist/stats/writer.js +51 -51
- package/dist/utils/avatar-upload.js +282 -23
- package/dist/utils/error-dict.json +160 -160
- package/dist/utils/macos-autostart.js +22 -22
- package/dist/utils/model-prices.jsonl +23 -23
- package/dist/utils/welcome.js +22 -22
- package/ecagent/LICENSE +21 -21
- package/ecagent/NOTICE +11 -11
- package/ecagent/README.md +61 -61
- package/ecagent/dist/harness/compaction/branch-summarization.js +30 -30
- package/ecagent/dist/harness/compaction/compaction.js +83 -83
- package/ecagent/dist/harness/messages.js +7 -7
- package/kits/docs/GUIDE.md +20 -20
- package/kits/docs/INDEX.md +66 -66
- package/kits/docs/aun/CHEATSHEET.md +19 -19
- package/kits/docs/aun/SYNC_PROTOCOL.md +15 -15
- package/kits/docs/channels/aun.md +56 -56
- package/kits/docs/channels/feishu.md +56 -56
- package/kits/docs/context-assembly.md +365 -364
- package/kits/docs/eck_templates/GUIDE.template.md +22 -22
- package/kits/docs/eck_templates/INDEX.template.md +28 -28
- package/kits/docs/eck_templates/path-registry.template.md +33 -33
- package/kits/docs/eck_templates/runtime.template.md +19 -19
- package/kits/docs/evolcore/INDEX.md +71 -69
- package/kits/docs/evolcore/agent-create.md +170 -156
- package/kits/docs/evolcore/agent.md +83 -73
- package/kits/docs/evolcore/aid.md +64 -62
- package/kits/docs/evolcore/codex-windows-sandbox.md +146 -0
- package/kits/docs/evolcore/config.md +195 -195
- package/kits/docs/evolcore/contact.md +68 -68
- package/kits/docs/evolcore/ctl.md +46 -46
- package/kits/docs/evolcore/event.md +216 -216
- package/kits/docs/evolcore/fs-architecture.md +1215 -1215
- package/kits/docs/evolcore/fs.md +110 -110
- package/kits/docs/evolcore/group-collaboration.md +243 -243
- package/kits/docs/evolcore/group-fs.md +17 -17
- package/kits/docs/evolcore/group-rules.md +251 -251
- package/kits/docs/evolcore/group.md +152 -152
- package/kits/docs/evolcore/menu-client.md +34 -34
- package/kits/docs/evolcore/model.md +50 -50
- package/kits/docs/evolcore/msg.md +165 -165
- package/kits/docs/evolcore/response.md +75 -75
- package/kits/docs/evolcore/rpc.md +37 -37
- package/kits/docs/evolcore/self-summary.md +29 -29
- package/kits/docs/evolcore/stats.md +83 -83
- package/kits/docs/evolcore/storage.md +50 -50
- package/kits/docs/evolcore/trigger.md +575 -575
- package/kits/docs/identity/AID_PROFILE_SPEC.md +26 -26
- package/kits/docs/identity/PATH_OPS.md +16 -16
- package/kits/docs/identity/ROLE_DETAIL.md +25 -25
- package/kits/docs/identity/identity-tools.md +26 -26
- package/kits/docs/path-registry.md +62 -62
- package/kits/docs/prompt-loading-architecture.md +270 -269
- package/kits/docs/venues/aun-group.md +45 -45
- package/kits/docs/venues/aun-private.md +10 -10
- package/kits/docs/venues/client-desktop.md +10 -10
- package/kits/docs/venues/client-mobile.md +10 -10
- package/kits/docs/venues/feishu-group.md +13 -13
- package/kits/docs/venues/feishu-private.md +9 -9
- package/kits/docs/venues/group.md +25 -25
- package/kits/docs/venues/private.md +10 -10
- package/kits/eck_manifest.auxiliary.json +43 -43
- package/kits/eck_manifest.json +195 -183
- package/kits/eck_message_manifest.json +74 -74
- package/kits/migrations/README-role-config-v4.md +32 -32
- package/kits/migrations/migrate-contact-book-v2.mjs +748 -748
- package/kits/migrations/migrate-role-config-v4.mjs +614 -614
- package/kits/migrations/migrate-role-config-v5.mjs +365 -365
- package/kits/migrations/rename-config-file.mjs +99 -99
- package/kits/rules/01-overview.md +162 -162
- package/kits/rules/02-navigation.md +96 -96
- package/kits/rules/03-identity.md +39 -37
- package/kits/rules/04-relation.md +75 -75
- package/kits/rules/05-venue.md +60 -60
- package/kits/rules/06-channel.md +63 -63
- package/kits/schemas/_meta.json +53 -53
- package/kits/schemas/agent-config.schema.1.json +177 -177
- package/kits/schemas/agent-config.schema.10.json +395 -395
- package/kits/schemas/agent-config.schema.11.json +421 -421
- package/kits/schemas/agent-config.schema.12.json +427 -427
- package/kits/schemas/agent-config.schema.2.json +239 -239
- package/kits/schemas/agent-config.schema.3.json +119 -119
- package/kits/schemas/agent-config.schema.4.json +208 -208
- package/kits/schemas/agent-config.schema.5.json +326 -326
- package/kits/schemas/agent-config.schema.6.json +322 -322
- package/kits/schemas/agent-config.schema.7.json +303 -303
- package/kits/schemas/agent-config.schema.8.json +304 -304
- package/kits/schemas/agent-config.schema.9.json +364 -364
- package/kits/schemas/contact-book.schema.1.json +36 -36
- package/kits/schemas/contact-book.schema.2.json +43 -43
- package/kits/schemas/contact-book.schema.3.json +67 -67
- package/kits/schemas/daemon.schema.1.json +91 -91
- package/kits/schemas/daemon.schema.2.json +101 -101
- package/kits/schemas/daemon.schema.3.json +123 -123
- package/kits/schemas/daemon.schema.4.json +136 -136
- package/kits/schemas/daemon.schema.5.json +135 -135
- package/kits/schemas/daemon.schema.6.json +131 -131
- package/kits/schemas/defaults.schema.1.json +81 -81
- package/kits/schemas/defaults.schema.2.json +85 -85
- package/kits/schemas/defaults.schema.3.json +73 -73
- package/kits/schemas/defaults.schema.4.json +107 -107
- package/kits/schemas/defaults.schema.5.json +119 -119
- package/kits/schemas/menu-exec-schema-commands.md +208 -208
- package/kits/schemas/migrations/README.md +30 -30
- package/kits/schemas/relation-config.schema.1.json +158 -158
- package/kits/schemas/relation-config.schema.2.json +73 -73
- package/kits/schemas/relation-config.schema.3.json +50 -50
- package/kits/schemas/relation-config.schema.4.json +47 -47
- package/kits/schemas/relation-config.schema.5.json +47 -47
- package/kits/schemas/relation-config.schema.6.json +46 -46
- package/kits/schemas/relation-config.schema.7.json +59 -59
- package/kits/schemas/relation-config.schema.8.json +103 -103
- package/kits/schemas/role-config.schema.1.json +201 -201
- package/kits/schemas/role-registry.schema.1.json +35 -35
- package/kits/schemas/single-session.schema.1.json +31 -31
- package/kits/schemas/single-session.schema.2.json +57 -57
- package/kits/schemas/single-session.schema.3.json +32 -32
- package/kits/templates/bootstrap-welcome.md +17 -17
- package/kits/templates/message-fragments/handoff-context-to-target.md +9 -9
- package/kits/templates/message-fragments/handoff-request-to-target.md +19 -19
- package/kits/templates/message-fragments/handoff-response-to-origin.md +9 -9
- package/kits/templates/message-fragments/inject-default.md +2 -2
- package/kits/templates/message-fragments/item.md +2 -2
- package/kits/templates/roles/admin.json +96 -84
- package/kits/templates/roles/member.json +97 -96
- package/kits/templates/roles/owner.json +9 -9
- package/kits/templates/roles/visitor.json +86 -85
- package/kits/templates/system-fragments/baseagent.md +14 -14
- package/kits/templates/system-fragments/bootstrap.md +38 -29
- package/kits/templates/system-fragments/channel.md +64 -64
- package/kits/templates/system-fragments/commands.md +28 -28
- package/kits/templates/system-fragments/identity.md +13 -13
- package/kits/templates/system-fragments/relation.md +19 -19
- package/kits/templates/system-fragments/session.md +59 -59
- package/kits/templates/system-fragments/venue.md +31 -31
- package/package.json +98 -98
- package/skills/eclink/SKILL.md +0 -84
- package/skills/eclink/agents/openai.yaml +0 -4
package/dist/cli/net-check.js
CHANGED
|
@@ -635,28 +635,28 @@ export async function cmdNet(args) {
|
|
|
635
635
|
const formatJson = args.includes('--format') && args.includes('json');
|
|
636
636
|
const kickTest = args.includes('--kick-test');
|
|
637
637
|
if (isHelpFlag(sub) || wantsHelp(args)) {
|
|
638
|
-
console.log(`用法: ec net check [<aid>] [--format json] [--kick-test]
|
|
639
|
-
|
|
640
|
-
检查 AUN 网络链路连通性(11 步逐层诊断)。
|
|
641
|
-
|
|
642
|
-
步骤:
|
|
643
|
-
1. DNS (AID) AID 域名解析
|
|
644
|
-
2. Discovery .well-known/aun-gateway 获取网关地址
|
|
645
|
-
3. DNS (Gateway) 网关域名解析
|
|
646
|
-
4. TCP 网关端口连接
|
|
647
|
-
5. TLS TLS 握手 + 证书验证
|
|
648
|
-
6. WSS WebSocket 升级握手
|
|
649
|
-
7. Auth AID 认证(login1 + login2 → token)
|
|
650
|
-
8. Session 会话建立
|
|
651
|
-
9. Ping meta.ping RPC
|
|
652
|
-
10. Echo self-to-self 消息收发
|
|
653
|
-
11. KickTest 踢人测试 / extra_info 验证(可选)
|
|
654
|
-
|
|
655
|
-
参数:
|
|
656
|
-
<aid> 要检查的 AID(可选,默认取前 3 个本地 AID)
|
|
657
|
-
|
|
658
|
-
选项:
|
|
659
|
-
--format json JSON 格式输出
|
|
638
|
+
console.log(`用法: ec net check [<aid>] [--format json] [--kick-test]
|
|
639
|
+
|
|
640
|
+
检查 AUN 网络链路连通性(11 步逐层诊断)。
|
|
641
|
+
|
|
642
|
+
步骤:
|
|
643
|
+
1. DNS (AID) AID 域名解析
|
|
644
|
+
2. Discovery .well-known/aun-gateway 获取网关地址
|
|
645
|
+
3. DNS (Gateway) 网关域名解析
|
|
646
|
+
4. TCP 网关端口连接
|
|
647
|
+
5. TLS TLS 握手 + 证书验证
|
|
648
|
+
6. WSS WebSocket 升级握手
|
|
649
|
+
7. Auth AID 认证(login1 + login2 → token)
|
|
650
|
+
8. Session 会话建立
|
|
651
|
+
9. Ping meta.ping RPC
|
|
652
|
+
10. Echo self-to-self 消息收发
|
|
653
|
+
11. KickTest 踢人测试 / extra_info 验证(可选)
|
|
654
|
+
|
|
655
|
+
参数:
|
|
656
|
+
<aid> 要检查的 AID(可选,默认取前 3 个本地 AID)
|
|
657
|
+
|
|
658
|
+
选项:
|
|
659
|
+
--format json JSON 格式输出
|
|
660
660
|
--kick-test 启用踢人测试(会断开 daemon 长连接,daemon 会自动重连)`);
|
|
661
661
|
return;
|
|
662
662
|
}
|
|
@@ -4,35 +4,35 @@ import { AGENT_DELEGATION_TOKEN_ENV } from '../core/auth/agent-delegation.js';
|
|
|
4
4
|
import { getArgValue, isHelpFlag, wantsHelp } from './help.js';
|
|
5
5
|
export async function cmdQueue(args) {
|
|
6
6
|
if (args.length === 0 || isHelpFlag(args[0]) || wantsHelp(args)) {
|
|
7
|
-
console.log(`用法: ec queue --agent <aid> [选项]
|
|
8
|
-
|
|
9
|
-
查询与操作 EvolAgent 的消息队列。
|
|
10
|
-
|
|
11
|
-
查询:
|
|
12
|
-
--agent <aid> 必填,目标 agent(如 mybot.agentid.pub)
|
|
13
|
-
--after <time> 只显示 adapter 接收时间晚于该值的消息(epoch ms 或 ISO)
|
|
14
|
-
--before <time> 只显示 adapter 接收时间早于该值的消息(epoch ms 或 ISO)
|
|
15
|
-
--showid 显示 messageId
|
|
16
|
-
--full 显示完整消息内容(不截断)
|
|
17
|
-
--format json 以 JSON 格式输出
|
|
18
|
-
|
|
19
|
-
JSON 时间字段:
|
|
20
|
-
receivedAt adapter 收到消息时间(epoch ms)
|
|
21
|
-
enqueuedAt 实际进入队列时间(epoch ms)
|
|
22
|
-
queueWaitMs 排队等待时长(ms)
|
|
23
|
-
processingStartedAt 开始处理时间(epoch ms,active)
|
|
24
|
-
|
|
25
|
-
操作:
|
|
26
|
-
--clear 清空该 agent 的所有待处理消息
|
|
27
|
-
--cancel <messageId> 取消指定消息
|
|
28
|
-
--interrupt --sessionkey <key> 打断指定 session 的处理中任务
|
|
29
|
-
|
|
30
|
-
示例:
|
|
31
|
-
ec queue --agent mybot.agentid.pub
|
|
32
|
-
ec queue --agent mybot.agentid.pub --after 2026-08-19T12:00:00+08:00
|
|
33
|
-
ec queue --agent mybot.agentid.pub --showid
|
|
34
|
-
ec queue --agent mybot.agentid.pub --clear
|
|
35
|
-
ec queue --agent mybot.agentid.pub --cancel msg_d4e5f6
|
|
7
|
+
console.log(`用法: ec queue --agent <aid> [选项]
|
|
8
|
+
|
|
9
|
+
查询与操作 EvolAgent 的消息队列。
|
|
10
|
+
|
|
11
|
+
查询:
|
|
12
|
+
--agent <aid> 必填,目标 agent(如 mybot.agentid.pub)
|
|
13
|
+
--after <time> 只显示 adapter 接收时间晚于该值的消息(epoch ms 或 ISO)
|
|
14
|
+
--before <time> 只显示 adapter 接收时间早于该值的消息(epoch ms 或 ISO)
|
|
15
|
+
--showid 显示 messageId
|
|
16
|
+
--full 显示完整消息内容(不截断)
|
|
17
|
+
--format json 以 JSON 格式输出
|
|
18
|
+
|
|
19
|
+
JSON 时间字段:
|
|
20
|
+
receivedAt adapter 收到消息时间(epoch ms)
|
|
21
|
+
enqueuedAt 实际进入队列时间(epoch ms)
|
|
22
|
+
queueWaitMs 排队等待时长(ms)
|
|
23
|
+
processingStartedAt 开始处理时间(epoch ms,active)
|
|
24
|
+
|
|
25
|
+
操作:
|
|
26
|
+
--clear 清空该 agent 的所有待处理消息
|
|
27
|
+
--cancel <messageId> 取消指定消息
|
|
28
|
+
--interrupt --sessionkey <key> 打断指定 session 的处理中任务
|
|
29
|
+
|
|
30
|
+
示例:
|
|
31
|
+
ec queue --agent mybot.agentid.pub
|
|
32
|
+
ec queue --agent mybot.agentid.pub --after 2026-08-19T12:00:00+08:00
|
|
33
|
+
ec queue --agent mybot.agentid.pub --showid
|
|
34
|
+
ec queue --agent mybot.agentid.pub --clear
|
|
35
|
+
ec queue --agent mybot.agentid.pub --cancel msg_d4e5f6
|
|
36
36
|
ec queue --agent mybot.agentid.pub --interrupt --sessionkey feishu#oc_abc123#main`);
|
|
37
37
|
return;
|
|
38
38
|
}
|
package/dist/cli/response.js
CHANGED
|
@@ -191,36 +191,36 @@ function sourceLabel(target) {
|
|
|
191
191
|
default: return String(target);
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
|
-
const HELP = `用法: ec response <command> [options]
|
|
195
|
-
|
|
196
|
-
Commands:
|
|
197
|
-
list 列出所有响应模式(内置 + 元数据)
|
|
198
|
-
current 显示当前作用域生效的模式 + 参数
|
|
199
|
-
info <mode-id> 查看单个模式详情(场景/配置参数)
|
|
200
|
-
set <mode-id> 设置响应模式
|
|
201
|
-
reset 清除指定作用域的 responseMode 设置
|
|
202
|
-
config <mode-id> 查看指定模式的配置参数
|
|
203
|
-
config set <k> <v> 修改模式配置参数(--mode 指定模式)
|
|
204
|
-
|
|
205
|
-
作用域(由参数决定,越具体越优先:关系 > agent):
|
|
206
|
-
--self <aid> agent级 → config.json
|
|
207
|
-
--self <aid> --peer <X> 关系级 → relations/<peerKey>/config.json
|
|
208
|
-
|
|
209
|
-
Options:
|
|
210
|
-
--self <aid> 本端 AID
|
|
211
|
-
--peer <X> 对端:channelType#channelId 或裸 aid(裸 aid 视为 aun#<aid>)
|
|
212
|
-
--mode <id> 模式 id(config set 专用)
|
|
213
|
-
--format json 输出 JSON
|
|
214
|
-
--help, -h 各子命令均支持
|
|
215
|
-
|
|
216
|
-
示例:
|
|
217
|
-
ec response list
|
|
218
|
-
ec response current --self bot.agentid.pub
|
|
219
|
-
ec response info single-session
|
|
220
|
-
ec response set single-session --self bot.agentid.pub
|
|
221
|
-
ec response set single-session --self bot.agentid.pub --peer aun#team.group.com
|
|
222
|
-
ec response config single-session --self bot.agentid.pub
|
|
223
|
-
ec response config set tool_use_reminder false --mode single-session --self bot.agentid.pub
|
|
194
|
+
const HELP = `用法: ec response <command> [options]
|
|
195
|
+
|
|
196
|
+
Commands:
|
|
197
|
+
list 列出所有响应模式(内置 + 元数据)
|
|
198
|
+
current 显示当前作用域生效的模式 + 参数
|
|
199
|
+
info <mode-id> 查看单个模式详情(场景/配置参数)
|
|
200
|
+
set <mode-id> 设置响应模式
|
|
201
|
+
reset 清除指定作用域的 responseMode 设置
|
|
202
|
+
config <mode-id> 查看指定模式的配置参数
|
|
203
|
+
config set <k> <v> 修改模式配置参数(--mode 指定模式)
|
|
204
|
+
|
|
205
|
+
作用域(由参数决定,越具体越优先:关系 > agent):
|
|
206
|
+
--self <aid> agent级 → config.json
|
|
207
|
+
--self <aid> --peer <X> 关系级 → relations/<peerKey>/config.json
|
|
208
|
+
|
|
209
|
+
Options:
|
|
210
|
+
--self <aid> 本端 AID
|
|
211
|
+
--peer <X> 对端:channelType#channelId 或裸 aid(裸 aid 视为 aun#<aid>)
|
|
212
|
+
--mode <id> 模式 id(config set 专用)
|
|
213
|
+
--format json 输出 JSON
|
|
214
|
+
--help, -h 各子命令均支持
|
|
215
|
+
|
|
216
|
+
示例:
|
|
217
|
+
ec response list
|
|
218
|
+
ec response current --self bot.agentid.pub
|
|
219
|
+
ec response info single-session
|
|
220
|
+
ec response set single-session --self bot.agentid.pub
|
|
221
|
+
ec response set single-session --self bot.agentid.pub --peer aun#team.group.com
|
|
222
|
+
ec response config single-session --self bot.agentid.pub
|
|
223
|
+
ec response config set tool_use_reminder false --mode single-session --self bot.agentid.pub
|
|
224
224
|
ec response reset --self bot.agentid.pub --peer alice.agentid.pub`;
|
|
225
225
|
// ── list ────────────────────────────────────────────────────────────────
|
|
226
226
|
function cmdList(args, formatJson) {
|
|
@@ -851,36 +851,36 @@ async function invokeClaude(claudePath, p, attempt, maxAttempts, timeout, log) {
|
|
|
851
851
|
const selfHealLog = p.selfHealLog;
|
|
852
852
|
const stdoutLog = path.join(p.logs, 'stdout.log');
|
|
853
853
|
const selfHealExists = fs.existsSync(selfHealLog) ? '存在,请先阅读之前的修复记录' : '不存在(首次修复)';
|
|
854
|
-
const prompt = `EvolCore 服务启动失败,需要你诊断并修复。这是第 ${attempt}/${maxAttempts} 次自动修复尝试。
|
|
855
|
-
|
|
856
|
-
关键信息:
|
|
857
|
-
- 项目目录:${projectDir}
|
|
858
|
-
- EVOLCORE_HOME:${p.root}
|
|
859
|
-
- 错误日志:${stdoutLog}
|
|
860
|
-
- 主日志:${p.logs}/daemon-*.log(按小时切片,读最新的那个,包含 config 校验失败等关键错误)
|
|
861
|
-
- 修复记录:${selfHealLog}(${selfHealExists})
|
|
862
|
-
|
|
863
|
-
⚠️ 重要诊断技巧:
|
|
864
|
-
- stdout.log 可能是空的(进程秒退时 logger 输出不会到 stdout),一定要同时读 daemon-*.log 最新文件
|
|
865
|
-
- 必须实际运行进程来复现错误:\`EVOLCORE_HOME=${p.root} node dist/index.js 2>&1\`,观察输出和退出码
|
|
866
|
-
- 检查是否有旧进程仍在运行:\`ps aux | grep 'node.*dist/index.js' | grep -v grep\`,旧进程可能占用端口或锁文件
|
|
867
|
-
- 可以运行 \`EVOLCORE_HOME=${p.root} node dist/cli/index.js diagnose\` 快速检查配置和数据库
|
|
868
|
-
- 如果进程无任何输出就 exit(1),说明是 process.exit(1) 被显式调用,搜索源码中所有 process.exit(1) 位置
|
|
869
|
-
- 配置文件使用双 rename 原子写(foo.json → foo.json_ → foo.json__),崩溃时可从 foo.json_ 恢复
|
|
870
|
-
|
|
871
|
-
请执行以下步骤:
|
|
872
|
-
1. 读取 ${stdoutLog} 和 ${p.logs}/daemon-*.log(最新文件)的最后 50 行
|
|
873
|
-
2. 运行 \`EVOLCORE_HOME=${p.root} node dist/index.js 2>&1\` 复现错误(设置 10 秒超时)
|
|
874
|
-
3. 如果 ${selfHealLog} 存在,先阅读之前的修复记录,避免重复尝试已失败的方案
|
|
875
|
-
4. 根据实际复现的错误修复代码
|
|
876
|
-
5. 执行 npm run build 确认编译通过
|
|
877
|
-
6. 验证修复:启动服务确认 ready.signal 已写入,然后执行 \`EVOLCORE_HOME=${p.root} node dist/cli/index.js stop\` 优雅停止(restart-monitor 会负责最终启动)
|
|
878
|
-
7. 将本次修复内容追加到 ${selfHealLog},格式:
|
|
879
|
-
## 第 ${attempt} 次修复 - {时间}
|
|
880
|
-
- 错误原因:...
|
|
881
|
-
- 修复方案:...
|
|
882
|
-
- 修改文件:...
|
|
883
|
-
|
|
854
|
+
const prompt = `EvolCore 服务启动失败,需要你诊断并修复。这是第 ${attempt}/${maxAttempts} 次自动修复尝试。
|
|
855
|
+
|
|
856
|
+
关键信息:
|
|
857
|
+
- 项目目录:${projectDir}
|
|
858
|
+
- EVOLCORE_HOME:${p.root}
|
|
859
|
+
- 错误日志:${stdoutLog}
|
|
860
|
+
- 主日志:${p.logs}/daemon-*.log(按小时切片,读最新的那个,包含 config 校验失败等关键错误)
|
|
861
|
+
- 修复记录:${selfHealLog}(${selfHealExists})
|
|
862
|
+
|
|
863
|
+
⚠️ 重要诊断技巧:
|
|
864
|
+
- stdout.log 可能是空的(进程秒退时 logger 输出不会到 stdout),一定要同时读 daemon-*.log 最新文件
|
|
865
|
+
- 必须实际运行进程来复现错误:\`EVOLCORE_HOME=${p.root} node dist/index.js 2>&1\`,观察输出和退出码
|
|
866
|
+
- 检查是否有旧进程仍在运行:\`ps aux | grep 'node.*dist/index.js' | grep -v grep\`,旧进程可能占用端口或锁文件
|
|
867
|
+
- 可以运行 \`EVOLCORE_HOME=${p.root} node dist/cli/index.js diagnose\` 快速检查配置和数据库
|
|
868
|
+
- 如果进程无任何输出就 exit(1),说明是 process.exit(1) 被显式调用,搜索源码中所有 process.exit(1) 位置
|
|
869
|
+
- 配置文件使用双 rename 原子写(foo.json → foo.json_ → foo.json__),崩溃时可从 foo.json_ 恢复
|
|
870
|
+
|
|
871
|
+
请执行以下步骤:
|
|
872
|
+
1. 读取 ${stdoutLog} 和 ${p.logs}/daemon-*.log(最新文件)的最后 50 行
|
|
873
|
+
2. 运行 \`EVOLCORE_HOME=${p.root} node dist/index.js 2>&1\` 复现错误(设置 10 秒超时)
|
|
874
|
+
3. 如果 ${selfHealLog} 存在,先阅读之前的修复记录,避免重复尝试已失败的方案
|
|
875
|
+
4. 根据实际复现的错误修复代码
|
|
876
|
+
5. 执行 npm run build 确认编译通过
|
|
877
|
+
6. 验证修复:启动服务确认 ready.signal 已写入,然后执行 \`EVOLCORE_HOME=${p.root} node dist/cli/index.js stop\` 优雅停止(restart-monitor 会负责最终启动)
|
|
878
|
+
7. 将本次修复内容追加到 ${selfHealLog},格式:
|
|
879
|
+
## 第 ${attempt} 次修复 - {时间}
|
|
880
|
+
- 错误原因:...
|
|
881
|
+
- 修复方案:...
|
|
882
|
+
- 修改文件:...
|
|
883
|
+
|
|
884
884
|
注意:只修复导致启动失败的问题,不要做额外的重构或优化。`;
|
|
885
885
|
try {
|
|
886
886
|
log(`Invoking claude CLI (attempt ${attempt}, timeout ${timeout / 60000}min)...`);
|
package/dist/cli/stats.js
CHANGED
|
@@ -6,52 +6,52 @@ import { wantsHelp } from './help.js';
|
|
|
6
6
|
import { readBestTaskRuntimeContext } from './task-context.js';
|
|
7
7
|
import { queryAggregated, querySessionTurns, queryContextBreakdown, queryTopPeers, queryTopModels, queryMessageAggregated, queryPeerList, querySummary, queryPeerDaily, queryTaskModelCalls, querySessionModelCalls } from '../stats/query.js';
|
|
8
8
|
import { getBudgetStatus } from '../stats/budget.js';
|
|
9
|
-
const HELP = `ec stats — Token 用量与费用统计
|
|
10
|
-
|
|
11
|
-
Usage: ec stats [options]
|
|
12
|
-
|
|
13
|
-
时间范围:
|
|
14
|
-
(无参数) 今日概览
|
|
15
|
-
--today 同上
|
|
16
|
-
--hour 最近 24 小时,按小时分组
|
|
17
|
-
--week 本周
|
|
18
|
-
--month 本月
|
|
19
|
-
--from <date> --to <date> 任意区间(YYYY-MM-DD)
|
|
20
|
-
|
|
21
|
-
维度过滤(可组合):
|
|
22
|
-
--agent <aid> 指定 agent
|
|
23
|
-
--peer <X> 对端(裸 AID 自动前缀 aun#,或 channel#id 格式)
|
|
24
|
-
--model <model-id> 指定模型
|
|
25
|
-
--session <id> 指定会话
|
|
26
|
-
|
|
27
|
-
聚合粒度:
|
|
28
|
-
--by hour|day|week|month|model|peer|agent
|
|
29
|
-
|
|
30
|
-
快捷视图:
|
|
31
|
-
--session <id> 单个会话明细
|
|
32
|
-
--session <id> --last 会话最后一轮用量 + 累计(等价 status.completed)
|
|
33
|
-
--context <id> 会话 context breakdown 细目
|
|
34
|
-
--budget 预算状态
|
|
35
|
-
--top-peers [--limit N] 对端排行
|
|
36
|
-
--top-models [--limit N] 模型排行
|
|
37
|
-
--traffic 消息收发条数与字节数
|
|
38
|
-
--sql "<query>" 直接执行只读 SQL
|
|
39
|
-
--rebuild 全量重建日聚合表 usage_daily(运维兜底/排查)
|
|
40
|
-
--peers [--limit N] 私聊对端列表(带累计 token/calls/活跃日)
|
|
41
|
-
--groups [--limit N] 群聊列表(同上)
|
|
42
|
-
--summary 指定时间范围总消耗汇总(token/USD/CNY)
|
|
43
|
-
--peer-detail <id> 指定对端 AID 或 peer_key,按天返回消耗明细
|
|
44
|
-
--task-calls <taskId> 一个 task 的逐次大模型调用明细
|
|
45
|
-
--session-calls <id> 一个会话的逐次大模型调用明细
|
|
46
|
-
|
|
47
|
-
输出格式:
|
|
48
|
-
--format json JSON 输出
|
|
49
|
-
--help, -h 显示此帮助
|
|
50
|
-
|
|
51
|
-
示例:
|
|
52
|
-
ec stats
|
|
53
|
-
ec stats --month --agent bot.agentid.pub
|
|
54
|
-
ec stats --peer alice.aid.pub
|
|
9
|
+
const HELP = `ec stats — Token 用量与费用统计
|
|
10
|
+
|
|
11
|
+
Usage: ec stats [options]
|
|
12
|
+
|
|
13
|
+
时间范围:
|
|
14
|
+
(无参数) 今日概览
|
|
15
|
+
--today 同上
|
|
16
|
+
--hour 最近 24 小时,按小时分组
|
|
17
|
+
--week 本周
|
|
18
|
+
--month 本月
|
|
19
|
+
--from <date> --to <date> 任意区间(YYYY-MM-DD)
|
|
20
|
+
|
|
21
|
+
维度过滤(可组合):
|
|
22
|
+
--agent <aid> 指定 agent
|
|
23
|
+
--peer <X> 对端(裸 AID 自动前缀 aun#,或 channel#id 格式)
|
|
24
|
+
--model <model-id> 指定模型
|
|
25
|
+
--session <id> 指定会话
|
|
26
|
+
|
|
27
|
+
聚合粒度:
|
|
28
|
+
--by hour|day|week|month|model|peer|agent
|
|
29
|
+
|
|
30
|
+
快捷视图:
|
|
31
|
+
--session <id> 单个会话明细
|
|
32
|
+
--session <id> --last 会话最后一轮用量 + 累计(等价 status.completed)
|
|
33
|
+
--context <id> 会话 context breakdown 细目
|
|
34
|
+
--budget 预算状态
|
|
35
|
+
--top-peers [--limit N] 对端排行
|
|
36
|
+
--top-models [--limit N] 模型排行
|
|
37
|
+
--traffic 消息收发条数与字节数
|
|
38
|
+
--sql "<query>" 直接执行只读 SQL
|
|
39
|
+
--rebuild 全量重建日聚合表 usage_daily(运维兜底/排查)
|
|
40
|
+
--peers [--limit N] 私聊对端列表(带累计 token/calls/活跃日)
|
|
41
|
+
--groups [--limit N] 群聊列表(同上)
|
|
42
|
+
--summary 指定时间范围总消耗汇总(token/USD/CNY)
|
|
43
|
+
--peer-detail <id> 指定对端 AID 或 peer_key,按天返回消耗明细
|
|
44
|
+
--task-calls <taskId> 一个 task 的逐次大模型调用明细
|
|
45
|
+
--session-calls <id> 一个会话的逐次大模型调用明细
|
|
46
|
+
|
|
47
|
+
输出格式:
|
|
48
|
+
--format json JSON 输出
|
|
49
|
+
--help, -h 显示此帮助
|
|
50
|
+
|
|
51
|
+
示例:
|
|
52
|
+
ec stats
|
|
53
|
+
ec stats --month --agent bot.agentid.pub
|
|
54
|
+
ec stats --peer alice.aid.pub
|
|
55
55
|
ec stats --session abc123 --format json`;
|
|
56
56
|
const RESET = '\x1b[0m';
|
|
57
57
|
const BOLD = '\x1b[1m';
|
|
@@ -246,11 +246,11 @@ export async function handleStats(args) {
|
|
|
246
246
|
const batch = allEvents.slice(i, i + batchSize);
|
|
247
247
|
for (const event of batch) {
|
|
248
248
|
const prices = resolvePrices(home, event); // 不传 gatewayPricing,全走本地 JSONL
|
|
249
|
-
db.prepare(`
|
|
250
|
-
UPDATE usage_events
|
|
251
|
-
SET cost_official_usd = ?, cost_official_cny = ?,
|
|
252
|
-
cost_gateway_usd = ?, cost_gateway_cny = ?
|
|
253
|
-
WHERE id = ?
|
|
249
|
+
db.prepare(`
|
|
250
|
+
UPDATE usage_events
|
|
251
|
+
SET cost_official_usd = ?, cost_official_cny = ?,
|
|
252
|
+
cost_gateway_usd = ?, cost_gateway_cny = ?
|
|
253
|
+
WHERE id = ?
|
|
254
254
|
`).run(prices.official?.usd ?? null, prices.official?.cny ?? null, prices.gateway?.usd ?? null, prices.gateway?.cny ?? null, event.id);
|
|
255
255
|
updated++;
|
|
256
256
|
}
|
|
@@ -81,62 +81,62 @@ export async function cmdTrigger(args) {
|
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
function printHelp() {
|
|
84
|
-
console.log(`用法: ec trigger <subcommand>
|
|
85
|
-
|
|
86
|
-
命令:
|
|
87
|
-
list [--agent <aid>] [--all] [--json]
|
|
88
|
-
show [--agent <aid>] <triggerId> [--json]
|
|
89
|
-
history [--agent <aid>] [triggerId] [--limit <n>] [--json]
|
|
90
|
-
create --exec <script|trigger-session|target-session> --file <trigger.json|trigger-dir> [--enable] [--json]
|
|
91
|
-
OR
|
|
92
|
-
create [--agent <aid>] --exec <script|trigger-session|target-session> --cron <expr>|--event <pattern> (--prompt <text>|--prompt-file <path>) [--enable] [其他flag]
|
|
93
|
-
set ... (create 的兼容别名)
|
|
94
|
-
update [--agent <aid>] <triggerId> <参数...> [--if-revision <sha256:...>] [--json]
|
|
95
|
-
enable [--agent <aid>] <triggerId>
|
|
96
|
-
disable [--agent <aid>] <triggerId>
|
|
97
|
-
cancel [--agent <aid>] <triggerId> (disable 的兼容别名)
|
|
98
|
-
delete|remove|rm [--agent <aid>] <triggerId>
|
|
99
|
-
run [--agent <aid>] <triggerId> [--dry-run] [--json]
|
|
100
|
-
template list|show <name> [--json]
|
|
101
|
-
|
|
102
|
-
Create 参数模式支持:
|
|
103
|
-
--once | --delay <时长> | --at <ISO时间> | --cron <表达式> | --every <时长> | --event <事件模式>
|
|
104
|
-
--exec <script|trigger-session|target-session> (必填)
|
|
105
|
-
--prompt <文本> | --prompt-file <路径>
|
|
106
|
-
Shell 双引号内的双引号、反引号和变量形式的美元符号都需在前面加反斜杠;trigger 保存的是还原后的原文
|
|
107
|
-
--script-path <路径> --script-runtime <node|python|bash>
|
|
108
|
-
--script-args <JSON> --script-timeout <时长>
|
|
109
|
-
--feedback <target> (origin/silent 仅可通过 --file 导入)
|
|
110
|
-
--baseagent <name> (仅 --exec trigger-session)
|
|
111
|
-
--model <模型> --effort <low|medium|high|xhigh|max>
|
|
112
|
-
--max-runs <次数> --max-duration <时长: 30s|15m|2h|1d>
|
|
113
|
-
--permission <readonly|auto|request|bypass|fullaccess>(省略则继承当前身份配置;fullaccess 仅 daemon-owner 且 feature flag 开启时可用)
|
|
114
|
-
--tz <时区> (仅 cron)
|
|
115
|
-
--target-channel <channelKey> --target-channel-id <ID> (AUN 可简写为 aun)
|
|
116
|
-
--target-chat-type <private|group> (AUN 目标必填;channelId 同时作为群聊 ID)
|
|
117
|
-
--target-session <main|thread> [--target-thread-id <threadId>]
|
|
118
|
-
--trigger-thread <by-run|by-trigger> (兼容旧值 per-run)
|
|
119
|
-
--name <名称>
|
|
120
|
-
|
|
121
|
-
通用输出参数:
|
|
122
|
-
--json | --format json
|
|
123
|
-
|
|
124
|
-
Update 参数:
|
|
125
|
-
--once | --delay | --at | --cron | --every | --event [--tz]
|
|
126
|
-
--prompt <文本> | --prompt-file <路径> --script-file <路径> --name <名称>
|
|
127
|
-
--description <文本> (空字符串删除)
|
|
128
|
-
--model <模型> --effort <强度> --permission <权限模式|inherit>(inherit 清除覆盖)
|
|
129
|
-
--max-runs <次数> --max-duration <时长>
|
|
130
|
-
--concurrency <forbid|replace|allow> --missed-policy <skip|run-once|run-all>
|
|
131
|
-
--feedback <origin|target|silent>
|
|
132
|
-
--target-channel <channelKey> --target-channel-id <ID> (必须同时指定)
|
|
133
|
-
--target-chat-type <private|group> --target-session <main|thread> [--target-thread-id <threadId>]
|
|
134
|
-
--trigger-thread <by-run|by-trigger> --baseagent <name> (仅 trigger_session 之间)
|
|
135
|
-
--on-error <fail|retry> --noop-sentinel <文本>
|
|
136
|
-
--retry-attempts <次数> --retry-backoff <毫秒>
|
|
137
|
-
--script-runtime <node|python|bash> --script-args <JSON> --script-timeout <时长>
|
|
138
|
-
|
|
139
|
-
省略 --agent 时使用当前 agent AID;无会话上下文或跨身份操作时需要显式指定。
|
|
84
|
+
console.log(`用法: ec trigger <subcommand>
|
|
85
|
+
|
|
86
|
+
命令:
|
|
87
|
+
list [--agent <aid>] [--all] [--json]
|
|
88
|
+
show [--agent <aid>] <triggerId> [--json]
|
|
89
|
+
history [--agent <aid>] [triggerId] [--limit <n>] [--json]
|
|
90
|
+
create --exec <script|trigger-session|target-session> --file <trigger.json|trigger-dir> [--enable] [--json]
|
|
91
|
+
OR
|
|
92
|
+
create [--agent <aid>] --exec <script|trigger-session|target-session> --cron <expr>|--event <pattern> (--prompt <text>|--prompt-file <path>) [--enable] [其他flag]
|
|
93
|
+
set ... (create 的兼容别名)
|
|
94
|
+
update [--agent <aid>] <triggerId> <参数...> [--if-revision <sha256:...>] [--json]
|
|
95
|
+
enable [--agent <aid>] <triggerId>
|
|
96
|
+
disable [--agent <aid>] <triggerId>
|
|
97
|
+
cancel [--agent <aid>] <triggerId> (disable 的兼容别名)
|
|
98
|
+
delete|remove|rm [--agent <aid>] <triggerId>
|
|
99
|
+
run [--agent <aid>] <triggerId> [--dry-run] [--json]
|
|
100
|
+
template list|show <name> [--json]
|
|
101
|
+
|
|
102
|
+
Create 参数模式支持:
|
|
103
|
+
--once | --delay <时长> | --at <ISO时间> | --cron <表达式> | --every <时长> | --event <事件模式>
|
|
104
|
+
--exec <script|trigger-session|target-session> (必填)
|
|
105
|
+
--prompt <文本> | --prompt-file <路径>
|
|
106
|
+
Shell 双引号内的双引号、反引号和变量形式的美元符号都需在前面加反斜杠;trigger 保存的是还原后的原文
|
|
107
|
+
--script-path <路径> --script-runtime <node|python|bash>
|
|
108
|
+
--script-args <JSON> --script-timeout <时长>
|
|
109
|
+
--feedback <target> (origin/silent 仅可通过 --file 导入)
|
|
110
|
+
--baseagent <name> (仅 --exec trigger-session)
|
|
111
|
+
--model <模型> --effort <low|medium|high|xhigh|max>
|
|
112
|
+
--max-runs <次数> --max-duration <时长: 30s|15m|2h|1d>
|
|
113
|
+
--permission <readonly|auto|request|bypass|fullaccess>(省略则继承当前身份配置;fullaccess 仅 daemon-owner 且 feature flag 开启时可用)
|
|
114
|
+
--tz <时区> (仅 cron)
|
|
115
|
+
--target-channel <channelKey> --target-channel-id <ID> (AUN 可简写为 aun)
|
|
116
|
+
--target-chat-type <private|group> (AUN 目标必填;channelId 同时作为群聊 ID)
|
|
117
|
+
--target-session <main|thread> [--target-thread-id <threadId>]
|
|
118
|
+
--trigger-thread <by-run|by-trigger> (兼容旧值 per-run)
|
|
119
|
+
--name <名称>
|
|
120
|
+
|
|
121
|
+
通用输出参数:
|
|
122
|
+
--json | --format json
|
|
123
|
+
|
|
124
|
+
Update 参数:
|
|
125
|
+
--once | --delay | --at | --cron | --every | --event [--tz]
|
|
126
|
+
--prompt <文本> | --prompt-file <路径> --script-file <路径> --name <名称>
|
|
127
|
+
--description <文本> (空字符串删除)
|
|
128
|
+
--model <模型> --effort <强度> --permission <权限模式|inherit>(inherit 清除覆盖)
|
|
129
|
+
--max-runs <次数> --max-duration <时长>
|
|
130
|
+
--concurrency <forbid|replace|allow> --missed-policy <skip|run-once|run-all>
|
|
131
|
+
--feedback <origin|target|silent>
|
|
132
|
+
--target-channel <channelKey> --target-channel-id <ID> (必须同时指定)
|
|
133
|
+
--target-chat-type <private|group> --target-session <main|thread> [--target-thread-id <threadId>]
|
|
134
|
+
--trigger-thread <by-run|by-trigger> --baseagent <name> (仅 trigger_session 之间)
|
|
135
|
+
--on-error <fail|retry> --noop-sentinel <文本>
|
|
136
|
+
--retry-attempts <次数> --retry-backoff <毫秒>
|
|
137
|
+
--script-runtime <node|python|bash> --script-args <JSON> --script-timeout <时长>
|
|
138
|
+
|
|
139
|
+
省略 --agent 时使用当前 agent AID;无会话上下文或跨身份操作时需要显式指定。
|
|
140
140
|
任务会话中的跨身份操作仅允许目标 Agent 上具备 owner/admin 权限的调用者执行 list/show/history;创建、修改、启停、删除和运行仍只允许当前 Agent。`);
|
|
141
141
|
}
|
|
142
142
|
async function listTriggers(args, json) {
|
|
@@ -51,6 +51,7 @@ export function getManagementCommandPermissions(role) {
|
|
|
51
51
|
'ec.aid.lookup': { allow: true, scopes: ['agent'] },
|
|
52
52
|
'ec.aid.agentmd.get': { allow: true, scopes: ['agent'] },
|
|
53
53
|
'ec.aid.agentmd.put': { allow: true, dangerous: true, scopes: ['agent'], constraints: { targetCurrentAgentOnly: true, requireAgentAdmin: true } },
|
|
54
|
+
'ec.aid.avatar': { allow: true, dangerous: true, scopes: ['agent'], constraints: { targetCurrentAgentOnly: true, requireAgentOwner: true } },
|
|
54
55
|
'ec.fs.mkdir': { allow: true, permissionMode: 'auto', scopes: ['relation'], constraints: { groupOnly: true, currentRelationOnly: true, targetCurrentAgentOnly: true } },
|
|
55
56
|
'ec.fs.upload': { allow: true, permissionMode: 'auto', scopes: ['relation'], constraints: { groupOnly: true, currentRelationOnly: true, targetCurrentAgentOnly: true } },
|
|
56
57
|
'ec.fs.copy': { allow: true, permissionMode: 'auto', scopes: ['relation'], constraints: { groupOnly: true, currentRelationOnly: true, targetCurrentAgentOnly: true } },
|
|
@@ -679,6 +679,21 @@ function groupFor(target, sel) {
|
|
|
679
679
|
function normalizeAgentConfigForWrite(value) {
|
|
680
680
|
const mutable = normalizeBaseagentEffortCompat({ ...value });
|
|
681
681
|
normalizeShowActivitiesCompat(mutable);
|
|
682
|
+
if (Object.prototype.hasOwnProperty.call(mutable, 'owners')) {
|
|
683
|
+
if (!Array.isArray(mutable.owners)) {
|
|
684
|
+
throw new ConfigError('VALIDATION_ERROR', 'owners must be an array');
|
|
685
|
+
}
|
|
686
|
+
const owners = [];
|
|
687
|
+
for (const rawOwner of mutable.owners) {
|
|
688
|
+
if (typeof rawOwner !== 'string' || !rawOwner.trim() || !isValidAid(rawOwner.trim())) {
|
|
689
|
+
throw new ConfigError('VALIDATION_ERROR', `Invalid owner AID: ${JSON.stringify(rawOwner)}`);
|
|
690
|
+
}
|
|
691
|
+
const owner = rawOwner.trim();
|
|
692
|
+
if (!owners.includes(owner))
|
|
693
|
+
owners.push(owner);
|
|
694
|
+
}
|
|
695
|
+
mutable.owners = owners;
|
|
696
|
+
}
|
|
682
697
|
// AID 格式校验
|
|
683
698
|
if (mutable.aid && !isValidAid(mutable.aid)) {
|
|
684
699
|
throw new ConfigError('VALIDATION_ERROR', `Invalid aid "${mutable.aid}" (must be a valid multi-level domain like mybot.agentid.pub)`);
|
|
@@ -301,7 +301,15 @@ function executeSet(op, options) {
|
|
|
301
301
|
if (!op.route)
|
|
302
302
|
return { ok: false, code: 'UNKNOWN_FIELD', error: `Unknown config field: ${op.field}` };
|
|
303
303
|
const selector = selectorFor(op, options);
|
|
304
|
-
mutateConfig(op.route.target, selector, existing => {
|
|
304
|
+
const mutation = mutateConfig(op.route.target, selector, existing => {
|
|
305
|
+
if (op.field === 'owners' && op.route.target === ConfigTarget.Agent) {
|
|
306
|
+
const nextOwners = Array.isArray(op.value) ? op.value : [];
|
|
307
|
+
if (nextOwners.length === 0) {
|
|
308
|
+
throw new ConfigError('LAST_OWNER_PROTECTED', 'owners must contain at least one owner');
|
|
309
|
+
}
|
|
310
|
+
setNested(existing, op.field, nextOwners);
|
|
311
|
+
return nextOwners;
|
|
312
|
+
}
|
|
305
313
|
if (op.route.merge === 'list') {
|
|
306
314
|
const previous = getNested(existing, op.field);
|
|
307
315
|
const previousItems = Array.isArray(previous) ? previous : [];
|
|
@@ -316,16 +324,18 @@ function executeSet(op, options) {
|
|
|
316
324
|
}
|
|
317
325
|
});
|
|
318
326
|
setNested(existing, op.field, merged);
|
|
327
|
+
return merged;
|
|
319
328
|
}
|
|
320
329
|
else {
|
|
321
330
|
setNested(existing, op.field, op.value);
|
|
331
|
+
return op.value;
|
|
322
332
|
}
|
|
323
333
|
});
|
|
324
334
|
return {
|
|
325
335
|
ok: true,
|
|
326
336
|
subcommand: 'set',
|
|
327
337
|
field: op.field,
|
|
328
|
-
value:
|
|
338
|
+
value: mutation.value,
|
|
329
339
|
scope: op.configScope,
|
|
330
340
|
file: op.route.schema,
|
|
331
341
|
};
|
|
@@ -334,7 +344,14 @@ function executeUnset(op, options) {
|
|
|
334
344
|
if (!op.route)
|
|
335
345
|
return { ok: false, code: 'UNKNOWN_FIELD', error: `Unknown config field: ${op.field}` };
|
|
336
346
|
const selector = selectorFor(op, options);
|
|
337
|
-
const
|
|
347
|
+
const target = op.route.target;
|
|
348
|
+
const { value: removed } = mutateConfig(target, selector, existing => {
|
|
349
|
+
if (op.field === 'owners' && target === ConfigTarget.Agent) {
|
|
350
|
+
const current = getNested(existing, op.field);
|
|
351
|
+
if (Array.isArray(current) && current.length > 0) {
|
|
352
|
+
throw new ConfigError('LAST_OWNER_PROTECTED', 'cannot unset owners while an Agent still has owners; use owners replace with another owner');
|
|
353
|
+
}
|
|
354
|
+
}
|
|
338
355
|
const parts = op.field.split('.');
|
|
339
356
|
let current = existing;
|
|
340
357
|
for (let i = 0; i < parts.length - 1; i++) {
|
|
@@ -2,6 +2,7 @@ import { normalizeCliArgv } from '../cli/cli-argv.js';
|
|
|
2
2
|
import { parseConfigSelector } from '../cli/config-selector.js';
|
|
3
3
|
import { parseConfigFieldValue, resolveConfigFieldRule, } from './config-field-policy.js';
|
|
4
4
|
import { ConfigError, routeFieldPath } from './config-manager.js';
|
|
5
|
+
import { isValidAid } from '../aun/aid/validation.js';
|
|
5
6
|
const SELECTOR_OPTIONS = {
|
|
6
7
|
'--self': 'value',
|
|
7
8
|
'--peer': 'value',
|
|
@@ -166,7 +167,13 @@ function resolveFieldCommand(argv, subcommand, options = {}) {
|
|
|
166
167
|
const rawValue = subcommand === 'set' ? business.values[1] : undefined;
|
|
167
168
|
let value;
|
|
168
169
|
if (subcommand === 'set') {
|
|
169
|
-
if (
|
|
170
|
+
if (field === 'owners') {
|
|
171
|
+
const parsedOwners = parseOwnersValue(rawValue);
|
|
172
|
+
if (!parsedOwners.ok)
|
|
173
|
+
return parsedOwners;
|
|
174
|
+
value = parsedOwners.value;
|
|
175
|
+
}
|
|
176
|
+
else if (fieldRule.class === 'safe-scalar') {
|
|
170
177
|
const parsedValue = parseConfigFieldValue(field, rawValue);
|
|
171
178
|
if (!parsedValue.ok)
|
|
172
179
|
return { ok: false, code: 'INVALID_CONFIG_VALUE', reason: parsedValue.reason };
|
|
@@ -486,6 +493,37 @@ function coerceConfigValue(raw, route) {
|
|
|
486
493
|
return Number(raw);
|
|
487
494
|
return raw;
|
|
488
495
|
}
|
|
496
|
+
function parseOwnersValue(raw) {
|
|
497
|
+
let values;
|
|
498
|
+
const trimmed = raw.trim();
|
|
499
|
+
if (trimmed.startsWith('[')) {
|
|
500
|
+
try {
|
|
501
|
+
values = JSON.parse(trimmed);
|
|
502
|
+
}
|
|
503
|
+
catch {
|
|
504
|
+
return { ok: false, code: 'INVALID_CONFIG_VALUE', reason: 'owners must be a valid JSON array of AIDs' };
|
|
505
|
+
}
|
|
506
|
+
if (!Array.isArray(values)) {
|
|
507
|
+
return { ok: false, code: 'INVALID_CONFIG_VALUE', reason: 'owners must be a JSON array of AIDs' };
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
else {
|
|
511
|
+
values = [raw];
|
|
512
|
+
}
|
|
513
|
+
if (!Array.isArray(values) || values.length === 0) {
|
|
514
|
+
return { ok: false, code: 'INVALID_CONFIG_VALUE', reason: 'owners must contain at least one AID' };
|
|
515
|
+
}
|
|
516
|
+
const owners = [];
|
|
517
|
+
for (const value of values) {
|
|
518
|
+
if (typeof value !== 'string' || !value.trim() || !isValidAid(value.trim())) {
|
|
519
|
+
return { ok: false, code: 'INVALID_CONFIG_VALUE', reason: `Invalid owner AID: ${JSON.stringify(value)}` };
|
|
520
|
+
}
|
|
521
|
+
const owner = value.trim();
|
|
522
|
+
if (!owners.includes(owner))
|
|
523
|
+
owners.push(owner);
|
|
524
|
+
}
|
|
525
|
+
return { ok: true, value: owners };
|
|
526
|
+
}
|
|
489
527
|
function configErrorResult(error) {
|
|
490
528
|
if (error instanceof ConfigError)
|
|
491
529
|
return { ok: false, code: error.code, reason: error.message };
|