evolcore 0.0.23 → 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.
Files changed (245) hide show
  1. package/CHANGELOG.md +583 -516
  2. package/LICENSE +21 -21
  3. package/README.md +455 -453
  4. package/bin/codex-managed-acl.ps1 +160 -155
  5. package/bin/codex-managed-hook.mjs +209 -92
  6. package/bin/ec-safe-output.js +327 -245
  7. package/bin/ec.js +29 -29
  8. package/bin/install-codex-managed-hooks.mjs +555 -544
  9. package/dist/agents/baseagent-availability.js +4 -4
  10. package/dist/agents/baseagent.js +29 -1
  11. package/dist/agents/claude-runner.js +152 -14
  12. package/dist/agents/codex/app-server-client.js +18 -8
  13. package/dist/agents/codex/catalog.js +1 -1
  14. package/dist/agents/codex/diagnostics.js +215 -0
  15. package/dist/agents/codex-runner.js +445 -63
  16. package/dist/agents/ecagent-runner.js +31 -16
  17. package/dist/agents/gemini-runner.js +82 -4
  18. package/dist/agents/runner-types.js +1 -1
  19. package/dist/aun/aid/agentmd.js +56 -4
  20. package/dist/aun/aid/index.js +1 -0
  21. package/dist/aun/aid/managed-operation.js +80 -6
  22. package/dist/aun/aid/store.js +41 -0
  23. package/dist/aun/msg/managed-operation.js +6 -1
  24. package/dist/aun/outbox.js +56 -18
  25. package/dist/aun/rpc/client.js +4 -5
  26. package/dist/aun/storage/client.js +4 -1
  27. package/dist/aun/storage/index.js +1 -1
  28. package/dist/channels/aun.js +147 -76
  29. package/dist/channels/daemon.js +7 -1
  30. package/dist/channels/dingtalk.js +1 -0
  31. package/dist/channels/feishu.js +10 -4
  32. package/dist/channels/wecom.js +2 -1
  33. package/dist/cli/agent-command.js +214 -89
  34. package/dist/cli/agent-create.js +576 -0
  35. package/dist/cli/agent.js +129 -676
  36. package/dist/cli/aun-commands.js +419 -313
  37. package/dist/cli/bench.js +20 -20
  38. package/dist/cli/config.js +20 -20
  39. package/dist/cli/contact.js +10 -10
  40. package/dist/cli/ctl-command.js +22 -20
  41. package/dist/cli/daemon-commands.js +163 -32
  42. package/dist/cli/fs-command.js +67 -67
  43. package/dist/cli/handoff-command.js +7 -7
  44. package/dist/cli/index.js +79 -79
  45. package/dist/cli/link-rules.js +21 -21
  46. package/dist/cli/managed-command-guard.js +3 -0
  47. package/dist/cli/menu-client.js +11 -11
  48. package/dist/cli/net-check.js +22 -22
  49. package/dist/cli/queue-command.js +29 -29
  50. package/dist/cli/response.js +30 -30
  51. package/dist/cli/restart-monitor.js +462 -38
  52. package/dist/cli/stats.js +161 -51
  53. package/dist/cli/trigger-command.js +56 -56
  54. package/dist/config/builtin-roles.js +3 -0
  55. package/dist/config/config-manager.js +15 -0
  56. package/dist/config/config-operation-service.js +20 -3
  57. package/dist/config/resolved-config-op.js +39 -1
  58. package/dist/core/auth/auth-gateway.js +3 -2
  59. package/dist/core/auth/authorization-audit.js +72 -19
  60. package/dist/core/auth/operation-authorizer.js +125 -7
  61. package/dist/core/auth/operation-catalog.js +26 -2
  62. package/dist/core/auth/remote-access-store.js +3 -2
  63. package/dist/core/baseagent-loader.js +4 -4
  64. package/dist/core/bootstrap-messages.js +39 -18
  65. package/dist/core/bootstrap-service.js +32 -26
  66. package/dist/core/capability/capability-manager.js +8 -4
  67. package/dist/core/capability/providers/codex-capability-provider.js +1 -1
  68. package/dist/core/command/agent-control.js +60 -26
  69. package/dist/core/command/cli-intent-parser.js +18 -0
  70. package/dist/core/command/command-handler.js +173 -36
  71. package/dist/core/command/menu-catalog.js +4 -1
  72. package/dist/core/command/menu-handler.js +315 -75
  73. package/dist/core/command/menu-protocol.js +7 -2
  74. package/dist/core/command/slash-gate.js +1 -3
  75. package/dist/core/command/slash-handler.js +166 -57
  76. package/dist/core/data-migration.js +5 -15
  77. package/dist/core/event-catalog.js +8 -0
  78. package/dist/core/evolagent.js +3 -3
  79. package/dist/core/handoff/runtime.js +3 -1
  80. package/dist/core/handoff/store.js +7 -1
  81. package/dist/core/message/im-renderer.js +13 -6
  82. package/dist/core/message/message-bridge.js +5 -36
  83. package/dist/core/message/message-utils.js +6 -3
  84. package/dist/core/message/response-engine.js +85 -27
  85. package/dist/core/model/catalog-service.js +3 -1
  86. package/dist/core/model/model-catalog.js +10 -0
  87. package/dist/core/model/model-permission.js +4 -1
  88. package/dist/core/permission/approval-gateway.js +169 -33
  89. package/dist/core/permission/tool-policy.js +56 -10
  90. package/dist/core/session/adapters/codex-session-file-adapter.js +71 -3
  91. package/dist/core/session/session-manager.js +49 -13
  92. package/dist/core/session/session-renew.js +1 -0
  93. package/dist/index.js +327 -134
  94. package/dist/ipc.js +68 -21
  95. package/dist/paths.js +23 -1
  96. package/dist/stats/billing.js +18 -4
  97. package/dist/stats/db.js +159 -159
  98. package/dist/stats/eck-vars.js +9 -9
  99. package/dist/stats/query.js +139 -139
  100. package/dist/stats/role-budget.js +6 -6
  101. package/dist/stats/writer.js +51 -51
  102. package/dist/utils/atomic-write.js +26 -2
  103. package/dist/utils/avatar-upload.js +282 -23
  104. package/dist/utils/cross-platform.js +436 -1
  105. package/dist/utils/error-dict.json +160 -160
  106. package/dist/utils/error-utils.js +11 -4
  107. package/dist/utils/macos-autostart.js +22 -22
  108. package/dist/utils/model-prices.jsonl +23 -20
  109. package/dist/utils/npm-ops.js +24 -1
  110. package/dist/utils/welcome.js +22 -22
  111. package/dist/utils/windows-autostart.js +1 -1
  112. package/ecagent/LICENSE +21 -21
  113. package/ecagent/NOTICE +11 -11
  114. package/ecagent/README.md +61 -61
  115. package/ecagent/dist/harness/compaction/branch-summarization.js +30 -30
  116. package/ecagent/dist/harness/compaction/compaction.js +83 -83
  117. package/ecagent/dist/harness/messages.js +7 -7
  118. package/kits/docs/GUIDE.md +20 -20
  119. package/kits/docs/INDEX.md +66 -66
  120. package/kits/docs/aun/CHEATSHEET.md +19 -19
  121. package/kits/docs/aun/SYNC_PROTOCOL.md +15 -15
  122. package/kits/docs/channels/aun.md +56 -56
  123. package/kits/docs/channels/feishu.md +56 -56
  124. package/kits/docs/context-assembly.md +365 -364
  125. package/kits/docs/eck_templates/GUIDE.template.md +22 -22
  126. package/kits/docs/eck_templates/INDEX.template.md +28 -28
  127. package/kits/docs/eck_templates/path-registry.template.md +33 -33
  128. package/kits/docs/eck_templates/runtime.template.md +19 -19
  129. package/kits/docs/evolcore/INDEX.md +71 -69
  130. package/kits/docs/evolcore/agent-create.md +170 -156
  131. package/kits/docs/evolcore/agent.md +83 -73
  132. package/kits/docs/evolcore/aid.md +64 -62
  133. package/kits/docs/evolcore/codex-windows-sandbox.md +146 -0
  134. package/kits/docs/evolcore/config.md +195 -195
  135. package/kits/docs/evolcore/contact.md +68 -68
  136. package/kits/docs/evolcore/ctl.md +46 -46
  137. package/kits/docs/evolcore/event.md +216 -216
  138. package/kits/docs/evolcore/fs-architecture.md +1215 -1215
  139. package/kits/docs/evolcore/fs.md +110 -110
  140. package/kits/docs/evolcore/group-collaboration.md +243 -243
  141. package/kits/docs/evolcore/group-fs.md +17 -17
  142. package/kits/docs/evolcore/group-rules.md +251 -251
  143. package/kits/docs/evolcore/group.md +152 -152
  144. package/kits/docs/evolcore/menu-client.md +34 -34
  145. package/kits/docs/evolcore/model.md +50 -50
  146. package/kits/docs/evolcore/msg.md +165 -165
  147. package/kits/docs/evolcore/response.md +75 -75
  148. package/kits/docs/evolcore/rpc.md +37 -37
  149. package/kits/docs/evolcore/self-summary.md +29 -29
  150. package/kits/docs/evolcore/stats.md +83 -83
  151. package/kits/docs/evolcore/storage.md +50 -50
  152. package/kits/docs/evolcore/trigger.md +575 -575
  153. package/kits/docs/identity/AID_PROFILE_SPEC.md +26 -26
  154. package/kits/docs/identity/PATH_OPS.md +16 -16
  155. package/kits/docs/identity/ROLE_DETAIL.md +25 -25
  156. package/kits/docs/identity/identity-tools.md +26 -26
  157. package/kits/docs/path-registry.md +62 -62
  158. package/kits/docs/prompt-loading-architecture.md +270 -269
  159. package/kits/docs/venues/aun-group.md +45 -45
  160. package/kits/docs/venues/aun-private.md +10 -10
  161. package/kits/docs/venues/client-desktop.md +10 -10
  162. package/kits/docs/venues/client-mobile.md +10 -10
  163. package/kits/docs/venues/feishu-group.md +13 -13
  164. package/kits/docs/venues/feishu-private.md +9 -9
  165. package/kits/docs/venues/group.md +25 -25
  166. package/kits/docs/venues/private.md +10 -10
  167. package/kits/eck_manifest.auxiliary.json +43 -43
  168. package/kits/eck_manifest.json +195 -183
  169. package/kits/eck_message_manifest.json +74 -74
  170. package/kits/migrations/README-role-config-v4.md +32 -32
  171. package/kits/migrations/migrate-contact-book-v2.mjs +748 -748
  172. package/kits/migrations/migrate-role-config-v4.mjs +614 -614
  173. package/kits/migrations/migrate-role-config-v5.mjs +365 -365
  174. package/kits/migrations/rename-config-file.mjs +99 -99
  175. package/kits/rules/01-overview.md +162 -162
  176. package/kits/rules/02-navigation.md +96 -96
  177. package/kits/rules/03-identity.md +39 -37
  178. package/kits/rules/04-relation.md +75 -75
  179. package/kits/rules/05-venue.md +60 -60
  180. package/kits/rules/06-channel.md +63 -63
  181. package/kits/schemas/_meta.json +53 -53
  182. package/kits/schemas/agent-config.schema.1.json +177 -177
  183. package/kits/schemas/agent-config.schema.10.json +395 -395
  184. package/kits/schemas/agent-config.schema.11.json +421 -421
  185. package/kits/schemas/agent-config.schema.12.json +427 -427
  186. package/kits/schemas/agent-config.schema.2.json +239 -239
  187. package/kits/schemas/agent-config.schema.3.json +119 -119
  188. package/kits/schemas/agent-config.schema.4.json +208 -208
  189. package/kits/schemas/agent-config.schema.5.json +326 -326
  190. package/kits/schemas/agent-config.schema.6.json +322 -322
  191. package/kits/schemas/agent-config.schema.7.json +303 -303
  192. package/kits/schemas/agent-config.schema.8.json +304 -304
  193. package/kits/schemas/agent-config.schema.9.json +364 -364
  194. package/kits/schemas/contact-book.schema.1.json +36 -36
  195. package/kits/schemas/contact-book.schema.2.json +43 -43
  196. package/kits/schemas/contact-book.schema.3.json +67 -67
  197. package/kits/schemas/daemon.schema.1.json +91 -91
  198. package/kits/schemas/daemon.schema.2.json +101 -101
  199. package/kits/schemas/daemon.schema.3.json +123 -123
  200. package/kits/schemas/daemon.schema.4.json +136 -136
  201. package/kits/schemas/daemon.schema.5.json +135 -135
  202. package/kits/schemas/daemon.schema.6.json +131 -131
  203. package/kits/schemas/defaults.schema.1.json +81 -81
  204. package/kits/schemas/defaults.schema.2.json +85 -85
  205. package/kits/schemas/defaults.schema.3.json +73 -73
  206. package/kits/schemas/defaults.schema.4.json +107 -107
  207. package/kits/schemas/defaults.schema.5.json +119 -119
  208. package/kits/schemas/menu-exec-schema-commands.md +208 -208
  209. package/kits/schemas/migrations/README.md +30 -30
  210. package/kits/schemas/relation-config.schema.1.json +158 -158
  211. package/kits/schemas/relation-config.schema.2.json +73 -73
  212. package/kits/schemas/relation-config.schema.3.json +50 -50
  213. package/kits/schemas/relation-config.schema.4.json +47 -47
  214. package/kits/schemas/relation-config.schema.5.json +47 -47
  215. package/kits/schemas/relation-config.schema.6.json +46 -46
  216. package/kits/schemas/relation-config.schema.7.json +59 -59
  217. package/kits/schemas/relation-config.schema.8.json +103 -103
  218. package/kits/schemas/role-config.schema.1.json +201 -201
  219. package/kits/schemas/role-registry.schema.1.json +35 -35
  220. package/kits/schemas/single-session.schema.1.json +31 -31
  221. package/kits/schemas/single-session.schema.2.json +57 -57
  222. package/kits/schemas/single-session.schema.3.json +32 -32
  223. package/kits/templates/bootstrap-welcome.md +17 -17
  224. package/kits/templates/message-fragments/handoff-context-to-target.md +9 -9
  225. package/kits/templates/message-fragments/handoff-request-to-target.md +19 -19
  226. package/kits/templates/message-fragments/handoff-response-to-origin.md +9 -9
  227. package/kits/templates/message-fragments/inject-default.md +2 -2
  228. package/kits/templates/message-fragments/item.md +2 -2
  229. package/kits/templates/roles/admin.json +96 -82
  230. package/kits/templates/roles/member.json +97 -96
  231. package/kits/templates/roles/owner.json +9 -9
  232. package/kits/templates/roles/visitor.json +86 -85
  233. package/kits/templates/system-fragments/baseagent.md +14 -14
  234. package/kits/templates/system-fragments/bootstrap.md +38 -29
  235. package/kits/templates/system-fragments/channel.md +64 -64
  236. package/kits/templates/system-fragments/commands.md +28 -28
  237. package/kits/templates/system-fragments/identity.md +13 -13
  238. package/kits/templates/system-fragments/relation.md +19 -19
  239. package/kits/templates/system-fragments/session.md +59 -59
  240. package/kits/templates/system-fragments/venue.md +31 -31
  241. package/package.json +98 -94
  242. package/AGENTS.md +0 -62
  243. package/dist/utils/codex-cli.js +0 -43
  244. package/skills/eclink/SKILL.md +0 -84
  245. package/skills/eclink/agents/openai.yaml +0 -4
@@ -5,6 +5,7 @@ import { isExplicitGroupId } from '../aun/group-identity.js';
5
5
  import { getArgValue, isHelpFlag, wantsHelp } from './help.js';
6
6
  import { ipcQuery } from '../ipc.js';
7
7
  import { AGENT_DELEGATION_TOKEN_ENV } from '../core/auth/agent-delegation.js';
8
+ import { isManagementRole } from '../config/builtin-roles.js';
8
9
  import { readBestTaskRuntimeContext } from './task-context.js';
9
10
  // ==================== AID ====================
10
11
  function resolveAunPath(args) {
@@ -13,24 +14,35 @@ function resolveAunPath(args) {
13
14
  return args[idx + 1];
14
15
  return process.env.AUN_HOME || undefined;
15
16
  }
17
+ function isRedactedAidShowResult(info) {
18
+ return 'redacted' in info && info.redacted === true;
19
+ }
16
20
  function renderAidShow(info, formatJson) {
17
21
  if (formatJson) {
18
22
  console.log(JSON.stringify(info, null, 2));
19
23
  return;
20
24
  }
21
25
  console.log(`AID: ${info.aid}`);
22
- console.log(` 私钥: ${info.hasPrivateKey ? '有' : '无'}`);
26
+ const redacted = isRedactedAidShowResult(info);
27
+ if (!redacted) {
28
+ console.log(` 私钥: ${info.hasPrivateKey ? '有' : '无'}`);
29
+ }
23
30
  console.log(` agent.md: ${info.hasAgentMd ? '有' : '无'}`);
24
31
  if (info.hasAgentMd) {
32
+ const signatureReason = redacted ? undefined : info.agentMdSignatureReason;
25
33
  const sigLabel = info.agentMdSignature === 'verified' ? '✓ 已验签'
26
34
  : info.agentMdSignature === 'unsigned' ? '⚠ 未签名'
27
- : info.agentMdSignature === 'invalid' ? `✗ 签名无效${info.agentMdSignatureReason ? ': ' + info.agentMdSignatureReason : ''}`
35
+ : info.agentMdSignature === 'invalid' ? `✗ 签名无效${signatureReason ? ': ' + signatureReason : ''}`
28
36
  : '? 未知';
29
37
  console.log(` 签名状态: ${sigLabel}`);
30
38
  }
31
39
  console.log(` 证书到期: ${info.certExpiresAt ?? '无证书'}${info.certExpired ? ' (已过期!)' : ''}`);
32
40
  if (info.certSubject)
33
41
  console.log(` 证书主体: ${info.certSubject}`);
42
+ if (redacted) {
43
+ console.log(' 本地密钥状态: 已脱敏');
44
+ return;
45
+ }
34
46
  if (info.keyMatchesCert === false)
35
47
  console.log(' 密钥/证书: ✗ 公钥不匹配(cert.pem 与 key.json 公钥不一致)');
36
48
  else if (info.keyMatchesCert === true)
@@ -104,7 +116,8 @@ async function runManagedAid(args, formatJson) {
104
116
  if (!parsed.ok)
105
117
  failManagedAid(formatJson, parsed.code, parsed.reason);
106
118
  const runtime = await readBestTaskRuntimeContext();
107
- if (runtime?.selfAid && parsed.command.aid !== runtime.selfAid.replace(/^@/, '')) {
119
+ const requiresSelfAid = parsed.command.kind === 'show' || parsed.command.kind === 'agentmd.put' || parsed.command.kind === 'avatar';
120
+ if (requiresSelfAid && runtime?.selfAid && parsed.command.aid !== runtime.selfAid.replace(/^@/, '')) {
108
121
  failManagedAid(formatJson, 'SCOPE_MISMATCH', `托管任务只能操作当前 self AID:${runtime.selfAid}`);
109
122
  }
110
123
  const response = await ipcQuery(resolvePaths().socket, {
@@ -142,6 +155,22 @@ async function runManagedAid(args, formatJson) {
142
155
  console.log(JSON.stringify({ ok: true, aid: response.result.aid, path: response.result.path }, null, 2));
143
156
  else
144
157
  console.log('✓ agent.md 已发布');
158
+ return;
159
+ case 'avatar':
160
+ if (formatJson)
161
+ console.log(JSON.stringify({
162
+ ok: true,
163
+ aid: response.result.aid,
164
+ avatar: response.result.avatar,
165
+ objectKey: response.result.objectKey,
166
+ sha256: response.result.sha256,
167
+ mime: response.result.mime,
168
+ width: response.result.width,
169
+ height: response.result.height,
170
+ aspectRatio: response.result.aspectRatio,
171
+ }, null, 2));
172
+ else
173
+ console.log(`✓ 头像已更新${response.result.avatar ? `: ${response.result.avatar}` : ''}${response.result.sha256 ? ` (sha256: ${response.result.sha256})` : ''}`);
145
174
  }
146
175
  }
147
176
  function failManagedGroup(formatJson, code, error) {
@@ -212,7 +241,12 @@ async function runManagedMsg(args, formatJson) {
212
241
  if (runtime && (runtime.channel !== 'aun' || runtime.chatType !== 'private')) {
213
242
  failManagedGroup(formatJson, 'SCOPE_MISMATCH', 'ec msg history/online 只能读取当前 AUN 私聊关系');
214
243
  }
215
- if (runtime?.channelId && parsed.command.target !== runtime.channelId.replace(/^@/, '')) {
244
+ // owner/admin 可以跨对端读历史(每次查询仍只针对一个对端)。这里只是快速
245
+ // 预检:角色未知时放行交给 daemon 判定,daemon 侧 handleMsgOperation 才是
246
+ // 权威关卡,member 由 currentRelationOnly 约束、visitor 直接拒绝。
247
+ const mayReadCrossPeer = parsed.command.kind === 'history'
248
+ && (runtime?.peerRole === undefined || isManagementRole(runtime.peerRole));
249
+ if (!mayReadCrossPeer && runtime?.channelId && parsed.command.target !== runtime.channelId.replace(/^@/, '')) {
216
250
  failManagedGroup(formatJson, 'SCOPE_MISMATCH', `只能读取当前 AUN 私聊对端:${runtime.channelId}`);
217
251
  }
218
252
  }
@@ -314,36 +348,37 @@ export async function cmdAid(args) {
314
348
  const formatJson = getArgValue(args, '--format') === 'json';
315
349
  const aunPath = resolveAunPath(args);
316
350
  if (!sub || isHelpFlag(sub)) {
317
- console.log(`用法: ec aid <command>
318
-
319
- Commands:
320
- list 列出本地所有 AID(实测 sign+verify)
321
- show <aid> 查看本地 AID 详情(证书、私钥、签名能力)
322
- new <aid> 创建新 AID 身份
323
- delete <aid> 删除指定本地 AID(无网络注销)
324
- delete --orphan 批量清理无私钥的外部 AID 缓存
325
- delete --no-cert 批量清理无私钥也无公钥证书的孤儿目录
326
- delete --unrecoverable 批量清理云端公钥已变更、本地不可恢复的 AID
327
- 批量删除默认 dry-run,加 --yes 执行
328
- lookup <aid> 远程探测 AID(是否存在 + 网关 + agent.md)
351
+ console.log(`用法: ec aid <command>
352
+
353
+ Commands:
354
+ list 列出本地所有 AID(实测 sign+verify)
355
+ show <aid> 查看本地 AID 详情(证书、私钥、签名能力)
356
+ new <aid> 创建新 AID 身份
357
+ delete <aid> 删除指定本地 AID(无网络注销)
358
+ delete --orphan 批量清理无私钥的外部 AID 缓存
359
+ delete --no-cert 批量清理无私钥也无公钥证书的孤儿目录
360
+ delete --unrecoverable 批量清理云端公钥已变更、本地不可恢复的 AID
361
+ 批量删除默认 dry-run,加 --yes 执行
362
+ lookup <aid> 远程探测 AID(是否存在 + 网关 + agent.md)
329
363
  agentmd put <aid> 读本地 agent.md → 签名 → 上传
330
364
  agentmd get <aid> 下载 agent.md → 验签 → 本地持久化
331
-
332
- Options:
333
- --format json 输出 JSON 格式
334
- --aun-path <path> 指定 AUN keystore 根(默认 EVOLCORE_HOME,可由 AUN_HOME 设置)
335
- --help, -h 各子命令均支持,查看详细用法
336
-
337
- 示例:
338
- ec aid list
339
- ec aid show toleiliang2.agentid.pub
340
- ec aid new reviewer.agentid.pub
341
- ec aid delete --help
342
- ec aid delete old.agentid.pub
343
- ec aid delete --orphan
344
- ec aid delete --unrecoverable --yes
345
- ec aid lookup someone.agentid.pub
346
- ec aid agentmd put mybot.agentid.pub
365
+ avatar <aid> --file <path> | --url <https-url> 上传头像并更新 agent.md
366
+
367
+ Options:
368
+ --format json 输出 JSON 格式
369
+ --aun-path <path> 指定 AUN keystore 根(默认 EVOLCORE_HOME,可由 AUN_HOME 设置)
370
+ --help, -h 各子命令均支持,查看详细用法
371
+
372
+ 示例:
373
+ ec aid list
374
+ ec aid show toleiliang2.agentid.pub
375
+ ec aid new reviewer.agentid.pub
376
+ ec aid delete --help
377
+ ec aid delete old.agentid.pub
378
+ ec aid delete --orphan
379
+ ec aid delete --unrecoverable --yes
380
+ ec aid lookup someone.agentid.pub
381
+ ec aid agentmd put mybot.agentid.pub
347
382
  ec aid agentmd get someone.agentid.pub`);
348
383
  return;
349
384
  }
@@ -354,33 +389,33 @@ Options:
354
389
  const { aidList, aidListVerified, aidCreate, aidShow, aidDelete, aidLookup, agentmdPut, agentmdGet, buildInitialAgentMd, isValidAid } = await import('../aun/aid/index.js');
355
390
  if (sub === 'list') {
356
391
  if (wantsHelp(args)) {
357
- console.log(`用法: ec aid list [筛选选项] [--no-verify] [--format json]
358
-
359
- 列出本地 AID 并跑 sign+verify 自检。
360
-
361
- 筛选选项(可组合,不指定 = 列出 mine + broken + peer-cert):
362
- --mine 仅本地可用身份(实测可签名+验签通过)
363
- --broken 仅有私钥但不可用(公钥不匹配 / 证书过期 / sign 失败)
364
- --peer-cert 仅对端 AID(无私钥,有公钥证书)
365
- --no-cert 仅无私钥无证书的目录(默认隐藏,需用 aid delete --no-cert 清理)
366
-
367
- 选项:
368
- --no-verify 跳过 sign+verify 实测,仅静态扫描(更快,mine/broken 仅按静态判定近似)
369
- --format json JSON 格式输出
370
-
371
- 输出图标:
372
- 🔑 有私钥
373
- ✅ 实测可签名/验签
374
- ❌ 不可签名(公钥不匹配 / sign 失败 / verify 失败等)
375
- ⌛ 证书过期
376
- 📜 有公钥证书
377
- 📄 有 agent.md
378
-
379
- 示例:
380
- ec aid list 列出 mine + broken + peer-cert
381
- ec aid list --mine 仅可用身份
382
- ec aid list --mine --broken 所有有私钥的 AID
383
- ec aid list --no-cert 仅无私钥无证书的孤儿目录
392
+ console.log(`用法: ec aid list [筛选选项] [--no-verify] [--format json]
393
+
394
+ 列出本地 AID 并跑 sign+verify 自检。
395
+
396
+ 筛选选项(可组合,不指定 = 列出 mine + broken + peer-cert):
397
+ --mine 仅本地可用身份(实测可签名+验签通过)
398
+ --broken 仅有私钥但不可用(公钥不匹配 / 证书过期 / sign 失败)
399
+ --peer-cert 仅对端 AID(无私钥,有公钥证书)
400
+ --no-cert 仅无私钥无证书的目录(默认隐藏,需用 aid delete --no-cert 清理)
401
+
402
+ 选项:
403
+ --no-verify 跳过 sign+verify 实测,仅静态扫描(更快,mine/broken 仅按静态判定近似)
404
+ --format json JSON 格式输出
405
+
406
+ 输出图标:
407
+ 🔑 有私钥
408
+ ✅ 实测可签名/验签
409
+ ❌ 不可签名(公钥不匹配 / sign 失败 / verify 失败等)
410
+ ⌛ 证书过期
411
+ 📜 有公钥证书
412
+ 📄 有 agent.md
413
+
414
+ 示例:
415
+ ec aid list 列出 mine + broken + peer-cert
416
+ ec aid list --mine 仅可用身份
417
+ ec aid list --mine --broken 所有有私钥的 AID
418
+ ec aid list --no-cert 仅无私钥无证书的孤儿目录
384
419
  ec aid list --no-verify 跳过实测,快速静态扫描`);
385
420
  return;
386
421
  }
@@ -432,8 +467,8 @@ Options:
432
467
  }
433
468
  if (sub === 'show') {
434
469
  if (wantsHelp(args)) {
435
- console.log(`用法: ec aid show <aid> [--format json]
436
-
470
+ console.log(`用法: ec aid show <aid> [--format json]
471
+
437
472
  查看本地 AID 详情:私钥/证书/agent.md 状态、签名能力实测。`);
438
473
  return;
439
474
  }
@@ -448,16 +483,16 @@ Options:
448
483
  }
449
484
  if (sub === 'new') {
450
485
  if (wantsHelp(args)) {
451
- console.log(`用法: ec aid new <完整AID> [--force] [--format json]
452
-
453
- 创建新 AID 身份:生成 ECDSA 密钥对、向 Issuer 申请证书、构建并上传初始 agent.md。
454
-
455
- 选项:
456
- --force 强制重新注册,覆盖已存在的身份(即使签名验证失败)
457
- --format json 输出 JSON
458
- --aun-path <path> 指定 AUN keystore 根
459
-
460
- 例: ec aid new reviewer.agentid.pub
486
+ console.log(`用法: ec aid new <完整AID> [--force] [--format json]
487
+
488
+ 创建新 AID 身份:生成 ECDSA 密钥对、向 Issuer 申请证书、构建并上传初始 agent.md。
489
+
490
+ 选项:
491
+ --force 强制重新注册,覆盖已存在的身份(即使签名验证失败)
492
+ --format json 输出 JSON
493
+ --aun-path <path> 指定 AUN keystore 根
494
+
495
+ 例: ec aid new reviewer.agentid.pub
461
496
  ec aid new reviewer.agentid.pub --force`);
462
497
  return;
463
498
  }
@@ -540,34 +575,34 @@ Options:
540
575
  }
541
576
  if (sub === 'delete') {
542
577
  if (wantsHelp(args)) {
543
- console.log(`用法: ec aid delete <子命令>
544
-
545
- 单个删除:
546
- ec aid delete <aid> 删除指定 AID 的本地数据(无网络注销)
547
-
548
- 批量删除(默认 dry-run,加 --yes 才真删):
549
- ec aid delete --orphan 删除所有"无私钥"的本地缓存(外部 AID)
550
- ec aid delete --no-cert 删除所有"无私钥也无公钥证书"的目录
551
- 条件:!hasPrivateKey && !hasCert
552
- 这些目录最多只剩 agent.md 或 SQLite 残留,
553
- 对验签和加密通信都没用,删除安全。
554
- ec aid delete --unrecoverable 删除所有不可恢复的 AID
555
- 条件:本地 sign+verify 实测失败
556
- 且 PKI 探测确认云端公钥也不等本地 key.json
557
-
558
- 选项:
559
- --yes 跳过 dry-run,立即执行
560
- --skip-pki --unrecoverable 时跳过 PKI 探测,仅依据本地 sign+verify 失败判断(危险,可能误删可恢复 AID)
561
- --format json 输出 JSON 格式
562
- --aun-path <path> 指定 AUN keystore 根
563
-
564
- 示例:
565
- ec aid delete old.agentid.pub
566
- ec aid delete --orphan 列出会被清理的孤儿
567
- ec aid delete --orphan --yes 实际清理
568
- ec aid delete --no-cert 列出无证书孤儿目录
569
- ec aid delete --no-cert --yes 实际清理
570
- ec aid delete --unrecoverable 联网探测后列出无救 AID
578
+ console.log(`用法: ec aid delete <子命令>
579
+
580
+ 单个删除:
581
+ ec aid delete <aid> 删除指定 AID 的本地数据(无网络注销)
582
+
583
+ 批量删除(默认 dry-run,加 --yes 才真删):
584
+ ec aid delete --orphan 删除所有"无私钥"的本地缓存(外部 AID)
585
+ ec aid delete --no-cert 删除所有"无私钥也无公钥证书"的目录
586
+ 条件:!hasPrivateKey && !hasCert
587
+ 这些目录最多只剩 agent.md 或 SQLite 残留,
588
+ 对验签和加密通信都没用,删除安全。
589
+ ec aid delete --unrecoverable 删除所有不可恢复的 AID
590
+ 条件:本地 sign+verify 实测失败
591
+ 且 PKI 探测确认云端公钥也不等本地 key.json
592
+
593
+ 选项:
594
+ --yes 跳过 dry-run,立即执行
595
+ --skip-pki --unrecoverable 时跳过 PKI 探测,仅依据本地 sign+verify 失败判断(危险,可能误删可恢复 AID)
596
+ --format json 输出 JSON 格式
597
+ --aun-path <path> 指定 AUN keystore 根
598
+
599
+ 示例:
600
+ ec aid delete old.agentid.pub
601
+ ec aid delete --orphan 列出会被清理的孤儿
602
+ ec aid delete --orphan --yes 实际清理
603
+ ec aid delete --no-cert 列出无证书孤儿目录
604
+ ec aid delete --no-cert --yes 实际清理
605
+ ec aid delete --unrecoverable 联网探测后列出无救 AID
571
606
  ec aid delete --unrecoverable --yes`);
572
607
  return;
573
608
  }
@@ -697,8 +732,8 @@ Options:
697
732
  }
698
733
  if (sub === 'lookup') {
699
734
  if (wantsHelp(args)) {
700
- console.log(`用法: ec aid lookup <aid> [--format json]
701
-
735
+ console.log(`用法: ec aid lookup <aid> [--format json]
736
+
702
737
  远程探测 AID:是否注册、所在网关、是否有 agent.md(不验签,仅获取)。`);
703
738
  return;
704
739
  }
@@ -719,9 +754,9 @@ Options:
719
754
  const verb = args[1];
720
755
  const aid = args[2];
721
756
  if (!verb || isHelpFlag(verb) || wantsHelp(args)) {
722
- console.log(`用法: ec aid agentmd <put|get> <aid> [--format json]
723
-
724
- put <aid> 读本地 agent.md → 用本地私钥签名 → 上传到 PKI
757
+ console.log(`用法: ec aid agentmd <put|get> <aid> [--format json]
758
+
759
+ put <aid> 读本地 agent.md → 用本地私钥签名 → 上传到 PKI
725
760
  get <aid> 从 PKI 下载 agent.md → 验签 → 持久化到本地`);
726
761
  return;
727
762
  }
@@ -777,30 +812,79 @@ Options:
777
812
  console.error(`未知子命令: aid agentmd ${verb ?? ''}\n用法: ec aid agentmd [put|get] <aid>`);
778
813
  process.exit(1);
779
814
  }
780
- console.error(`未知子命令: ${sub}\n用法: ec aid [list|show|new|delete|lookup|agentmd] <aid>`);
815
+ if (sub === 'avatar') {
816
+ const aid = args[1];
817
+ const fileIndex = args.indexOf('--file');
818
+ const urlIndex = args.indexOf('--url');
819
+ const filePath = fileIndex >= 0 ? args[fileIndex + 1] : undefined;
820
+ const url = urlIndex >= 0 ? args[urlIndex + 1] : undefined;
821
+ if (wantsHelp(args)) {
822
+ console.log('用法: ec aid avatar <aid> (--file <path> | --url <https-url>) [--format json]');
823
+ return;
824
+ }
825
+ const sourceCount = (fileIndex >= 0 ? 1 : 0) + (urlIndex >= 0 ? 1 : 0);
826
+ if (!aid || sourceCount !== 1 || (fileIndex >= 0 && (!filePath || filePath.startsWith('-')))
827
+ || (urlIndex >= 0 && (!url || url.startsWith('-'))) || (fileIndex >= 0 && fileIndex !== 2) || (urlIndex >= 0 && urlIndex !== 2)
828
+ || args.filter(value => value === '--file').length > 1 || args.filter(value => value === '--url').length > 1 || !isValidAid(aid)
829
+ || (args.includes('--format') && !formatJson) || (args.includes('--format') && args.filter(value => value === '--format').length !== 1)) {
830
+ const usage = '用法: ec aid avatar <aid> (--file <path> | --url <https-url>) [--format json]';
831
+ if (formatJson)
832
+ console.log(JSON.stringify({ ok: false, code: 'INVALID_ARGUMENT', error: usage }, null, 2));
833
+ else
834
+ console.error(usage);
835
+ process.exit(1);
836
+ }
837
+ const { uploadAvatarFile, uploadAvatarUrl } = await import('../utils/avatar-upload.js');
838
+ const result = filePath
839
+ ? await uploadAvatarFile(aid, filePath, { aunPath })
840
+ : await uploadAvatarUrl(aid, url, { aunPath });
841
+ if (!result.ok) {
842
+ if (formatJson)
843
+ console.log(JSON.stringify({ ok: false, code: result.code, error: result.error }, null, 2));
844
+ else
845
+ console.error(`❌ 头像上传失败: ${result.error}`);
846
+ process.exit(1);
847
+ }
848
+ if (formatJson)
849
+ console.log(JSON.stringify({
850
+ ok: true,
851
+ aid,
852
+ avatar: result.publicUrl,
853
+ objectKey: result.objectKey,
854
+ sha256: result.sha256,
855
+ mime: result.mime,
856
+ width: result.width,
857
+ height: result.height,
858
+ aspectRatio: result.aspectRatio,
859
+ }, null, 2));
860
+ else
861
+ console.log(`✓ 头像已更新${result.publicUrl ? `: ${result.publicUrl}` : ''}${result.sha256 ? ` (sha256: ${result.sha256})` : ''}`);
862
+ return;
863
+ }
864
+ console.error(`未知子命令: ${sub}\n用法: ec aid [list|show|new|delete|lookup|agentmd|avatar] <aid>`);
781
865
  process.exit(1);
782
866
  }
783
867
  // ==================== RPC ====================
784
868
  export async function cmdRpc(args) {
785
869
  if (args.length === 0 || wantsHelp(args)) {
786
- console.log(`用法: ec rpc --as <aid> --params <params>
787
-
788
- 通用 AUN RPC 调用。
789
-
790
- --params 自动判断输入形式:
791
- 单行 JSON (以 { 开头) → 单次调用
792
- 多行 JSONL → 逐行执行,失败即停
793
- 文件路径 (文件存在) → 读取文件内容作为 JSONL
794
-
795
- 每行 JSON 格式: {"method":"<namespace.method>","params":{...}}
796
-
797
- Options:
798
- --app <name> 指定应用 slot(独立消费通道)。仅对 message.pull / group.pull
799
- 等消费类方法有意义——隔离 seq 游标与消息过滤;默认与 daemon 共享通道。
800
- --aun-path <path> 指定 AUN keystore 根
801
-
802
- 示例:
803
- ec rpc --as alice.agentid.pub --params '{"method":"message.send","params":{"to":"bob.agentid.pub","payload":{"type":"text","text":"hello"}}}'
870
+ console.log(`用法: ec rpc --as <aid> --params <params>
871
+
872
+ 通用 AUN RPC 调用。
873
+
874
+ --params 自动判断输入形式:
875
+ 单行 JSON (以 { 开头) → 单次调用
876
+ 多行 JSONL → 逐行执行,失败即停
877
+ 文件路径 (文件存在) → 读取文件内容作为 JSONL
878
+
879
+ 每行 JSON 格式: {"method":"<namespace.method>","params":{...}}
880
+
881
+ Options:
882
+ --app <name> 指定应用 slot(独立消费通道)。仅对 message.pull / group.pull
883
+ 等消费类方法有意义——隔离 seq 游标与消息过滤;默认与 daemon 共享通道。
884
+ --aun-path <path> 指定 AUN keystore 根
885
+
886
+ 示例:
887
+ ec rpc --as alice.agentid.pub --params '{"method":"message.send","params":{"to":"bob.agentid.pub","payload":{"type":"text","text":"hello"}}}'
804
888
  ec rpc --as alice.agentid.pub --params calls.jsonl`);
805
889
  return;
806
890
  }
@@ -868,29 +952,29 @@ export async function cmdStorage(args) {
868
952
  const aunPath = resolveAunPath(args);
869
953
  const formatJson = getArgValue(args, '--format') === 'json';
870
954
  if (!sub || wantsHelp(args)) {
871
- console.log(`用法: ec storage <command> <aid> [options]
872
-
873
- Commands:
874
- upload <aid> <local-file> <remote-path> [--public] 上传文件(默认私有)
875
- download <aid> <url> [local-path] 下载文件
876
- ls <aid> [prefix] 列文件
877
- rm <aid> <remote-path> 删文件
878
- quota <aid> 查配额
879
-
880
- <url> 格式: [https://]<owner-aid>/<path>
881
-
882
- Options:
883
- --public 上传后公开可读(仅 upload)
884
- --format json 输出 JSON
885
- --aun-path <path> 指定 AUN keystore 根
886
-
887
- 示例:
888
- ec storage upload myaid.agentid.pub ./doc.txt notes/doc.txt
889
- ec storage upload myaid.agentid.pub ./pic.png images/pic.png --public
890
- ec storage download myaid.agentid.pub myaid.agentid.pub/notes/doc.txt ./doc.txt
891
- ec storage download myaid.agentid.pub bob.agentid.pub/public/file.pdf ./file.pdf
892
- ec storage ls myaid.agentid.pub notes/
893
- ec storage rm myaid.agentid.pub notes/doc.txt
955
+ console.log(`用法: ec storage <command> <aid> [options]
956
+
957
+ Commands:
958
+ upload <aid> <local-file> <remote-path> [--public] 上传文件(默认私有)
959
+ download <aid> <url> [local-path] 下载文件
960
+ ls <aid> [prefix] 列文件
961
+ rm <aid> <remote-path> 删文件
962
+ quota <aid> 查配额
963
+
964
+ <url> 格式: [https://]<owner-aid>/<path>
965
+
966
+ Options:
967
+ --public 上传后公开可读(仅 upload)
968
+ --format json 输出 JSON
969
+ --aun-path <path> 指定 AUN keystore 根
970
+
971
+ 示例:
972
+ ec storage upload myaid.agentid.pub ./doc.txt notes/doc.txt
973
+ ec storage upload myaid.agentid.pub ./pic.png images/pic.png --public
974
+ ec storage download myaid.agentid.pub myaid.agentid.pub/notes/doc.txt ./doc.txt
975
+ ec storage download myaid.agentid.pub bob.agentid.pub/public/file.pdf ./file.pdf
976
+ ec storage ls myaid.agentid.pub notes/
977
+ ec storage rm myaid.agentid.pub notes/doc.txt
894
978
  ec storage quota myaid.agentid.pub`);
895
979
  return;
896
980
  }
@@ -1045,83 +1129,83 @@ export async function cmdMsg(args) {
1045
1129
  const formatJson = getArgValue(args, '--format') === 'json';
1046
1130
  const appSlot = getArgValue(args, '--app');
1047
1131
  if (!sub || isHelpFlag(sub) || (wantsHelp(args) && sub !== 'history')) {
1048
- console.log(`用法: ec msg <command> <from-aid> [args...] [options]
1049
-
1050
- Commands:
1051
- send <from> <to> <text> --return <none|required> 发送文本(跨会话时 --return 必填)
1052
- send <from> <to> --text-from-file <path> 从文件读取文本内容
1053
- send <from> <to> --file <path> [--as <type>] 发送文件(image|video|voice|file)
1054
- send <from> <to> --link <url> [--title T] 发送链接卡片
1055
- send <from> <to> --payload <json> 发送自定义 payload
1056
- pull <from> [--after-seq N] [--limit N] 拉取收件箱
1057
- ack <from> <seq> [--app <name>] 确认已读
1058
- recall <from> <message-id> [<message-id>...] 撤回消息
1059
- online <from> <target-aid> [<target-aid>...] 查询在线状态
1060
- history <from> [<target-aid>|selector] [筛选选项] 查询本地消息历史
1061
-
1062
- Options:
1063
- --text-from-file <path> 从文件读取文本(UTF-8),用于超长消息或避免 Shell 转义
1064
- --app <name> 指定应用 slot(独立消费通道,不影响 daemon)
1065
- --aun-path <path> 指定 AUN keystore 根
1066
- --format json 输出 JSON 格式
1067
- --encrypt 强制端到端加密(未指定时使用 daemon 默认值)
1068
- --no-encrypt 强制明文发送(优先于 --encrypt)
1069
- --thread <id> 指定话题 ID(用于多话题路由)
1070
- --session <latest|all|id> 按 EvolCore 逻辑会话过滤历史(默认 latest)
1071
- --before <time> 只返回该时间之前的历史
1072
- --after <time> 只返回该时间之后的历史
1073
- --direction <value> 历史方向:in|out|all
1074
- --channel <type> 历史渠道:aun|feishu|wechat|dingtalk|qqbot|wecom
1075
- --channel-name <name> 历史渠道实例名(非 AUN 渠道必须匹配 Agent 配置)
1076
- --channel-key <key> 非 AUN 已落盘渠道的完整实例键(与 --peer-id 成对)
1077
- --peer-id <id> 非 AUN 渠道的原生对端 ID(与 --channel-key 成对)
1078
- --return <none|required> 跨会话发送必填:none=仅补充目标上下文,required=回答回流来源
1079
- --content-type <mime> 显式覆盖 MIME(仅 --file 模式)
1080
- --as <type> 附件类型:image|video|voice|file(仅 --file 模式)
1081
- --text <说明> 附件说明文字(仅 --file 模式)
1082
- --transcript <text> 语音转写(仅 --as voice)
1083
- --title <text> 链接标题(仅 --link 模式)
1084
- --description <text> 链接描述(仅 --link 模式)
1085
- -- end-of-options:其后所有参数按正文处理
1086
- (用于发送恰好等于某 flag 的文本,如 send a b -- --encrypt)
1087
-
1088
- 示例:
1089
- ec msg send alice.agentid.pub bob.agentid.pub "hello" --return none
1090
- ec msg send alice.agentid.pub bob.agentid.pub --text-from-file long-message.txt --return none
1091
- ec msg send alice.agentid.pub bob.agentid.pub "讨论项目A" --thread "project-A" --return required
1092
- ec msg send alice.agentid.pub bob.agentid.pub --file ./pic.png --return none
1093
- ec msg send alice.agentid.pub bob.agentid.pub --file ./demo.mp4 --as video --return none
1094
- ec msg send alice.agentid.pub bob.agentid.pub --link https://example.com --title "AUN" --return none
1095
- ec msg pull alice.agentid.pub --app my-bot
1096
- ec msg ack alice.agentid.pub 42 --app my-bot
1097
- ec msg recall alice.agentid.pub msg-uuid-1 msg-uuid-2
1098
- ec msg online alice.agentid.pub bob.agentid.pub carol.agentid.pub
1099
- ec msg history alice.agentid.pub bob.agentid.pub --session latest --limit 50
1132
+ console.log(`用法: ec msg <command> <from-aid> [args...] [options]
1133
+
1134
+ Commands:
1135
+ send <from> <to> <text> --return <none|required> 发送文本(跨会话时 --return 必填)
1136
+ send <from> <to> --text-from-file <path> 从文件读取文本内容
1137
+ send <from> <to> --file <path> [--as <type>] 发送文件(image|video|voice|file)
1138
+ send <from> <to> --link <url> [--title T] 发送链接卡片
1139
+ send <from> <to> --payload <json> 发送自定义 payload
1140
+ pull <from> [--after-seq N] [--limit N] --app <name> 拉取收件箱(必须使用独立 slot)
1141
+ ack <from> <seq> [--app <name>] 确认已读
1142
+ recall <from> <message-id> [<message-id>...] 撤回消息
1143
+ online <from> <target-aid> [<target-aid>...] 查询在线状态
1144
+ history <from> [<target-aid>|selector] [筛选选项] 查询本地消息历史
1145
+
1146
+ Options:
1147
+ --text-from-file <path> 从文件读取文本(UTF-8),用于超长消息或避免 Shell 转义
1148
+ --app <name> 指定应用 slot(独立消费通道,不影响 daemon)
1149
+ --aun-path <path> 指定 AUN keystore 根
1150
+ --format json 输出 JSON 格式
1151
+ --encrypt 强制端到端加密(未指定时使用 daemon 默认值)
1152
+ --no-encrypt 强制明文发送(优先于 --encrypt)
1153
+ --thread <id> 指定话题 ID(用于多话题路由)
1154
+ --session <latest|all|id> 按 EvolCore 逻辑会话过滤历史(默认 latest)
1155
+ --before <time> 只返回该时间之前的历史
1156
+ --after <time> 只返回该时间之后的历史
1157
+ --direction <value> 历史方向:in|out|all
1158
+ --channel <type> 历史渠道:aun|feishu|wechat|dingtalk|qqbot|wecom
1159
+ --channel-name <name> 历史渠道实例名(非 AUN 渠道必须匹配 Agent 配置)
1160
+ --channel-key <key> 非 AUN 已落盘渠道的完整实例键(与 --peer-id 成对)
1161
+ --peer-id <id> 非 AUN 渠道的原生对端 ID(与 --channel-key 成对)
1162
+ --return <none|required> 跨会话发送必填:none=仅补充目标上下文,required=回答回流来源
1163
+ --content-type <mime> 显式覆盖 MIME(仅 --file 模式)
1164
+ --as <type> 附件类型:image|video|voice|file(仅 --file 模式)
1165
+ --text <说明> 附件说明文字(仅 --file 模式)
1166
+ --transcript <text> 语音转写(仅 --as voice)
1167
+ --title <text> 链接标题(仅 --link 模式)
1168
+ --description <text> 链接描述(仅 --link 模式)
1169
+ -- end-of-options:其后所有参数按正文处理
1170
+ (用于发送恰好等于某 flag 的文本,如 send a b -- --encrypt)
1171
+
1172
+ 示例:
1173
+ ec msg send alice.agentid.pub bob.agentid.pub "hello" --return none
1174
+ ec msg send alice.agentid.pub bob.agentid.pub --text-from-file long-message.txt --return none
1175
+ ec msg send alice.agentid.pub bob.agentid.pub "讨论项目A" --thread "project-A" --return required
1176
+ ec msg send alice.agentid.pub bob.agentid.pub --file ./pic.png --return none
1177
+ ec msg send alice.agentid.pub bob.agentid.pub --file ./demo.mp4 --as video --return none
1178
+ ec msg send alice.agentid.pub bob.agentid.pub --link https://example.com --title "AUN" --return none
1179
+ ec msg pull alice.agentid.pub --app my-bot
1180
+ ec msg ack alice.agentid.pub 42 --app my-bot
1181
+ ec msg recall alice.agentid.pub msg-uuid-1 msg-uuid-2
1182
+ ec msg online alice.agentid.pub bob.agentid.pub carol.agentid.pub
1183
+ ec msg history alice.agentid.pub bob.agentid.pub --session latest --limit 50
1100
1184
  ec msg history alice.agentid.pub --channel-key feishu#alice.agentid.pub#main --peer-id ou_xxx --session all --format json`);
1101
1185
  return;
1102
1186
  }
1103
1187
  if (sub === 'history' && wantsHelp(args)) {
1104
- console.log(`用法: ec msg history <self-aid> [<target-aid> | --channel-key <key> --peer-id <id>] [options]
1105
-
1106
- 查询指定会话对的本地历史,不调用 message.pull,也不影响收件箱游标。非 AUN selector 按已落盘的 session metadata、完整 channelKey 与原生 peer ID 精确读取,不能传入文件路径。
1107
-
1108
- 托管会话限制:普通会话只能使用当前 self AID 和当前 AUN 私聊对端;可信 daemon Trigger 可用精确的 --channel-key/--peer-id selector 读取已落盘的非 AUN 私聊历史。托管任务不支持 --channel、--channel-name、--aun-path 或 --app。
1109
-
1110
- Options:
1111
- --session <latest|all|id> 默认 latest;all 查询全部;也可指定会话 ID
1112
- --limit <N> 返回最新 N 条(默认 50,最大 500)
1113
- --before <time> 开区间;epoch 毫秒或 ISO 时间
1114
- --after <time> 开区间;epoch 毫秒或 ISO 时间
1115
- --direction <value> in|out|all(默认 all)
1116
- --channel-key <key> 非 AUN 已落盘渠道完整键;必须与 --peer-id 同时给出
1117
- --peer-id <id> 原生私聊对端 ID;必须与 --channel-key 同时给出
1118
- --format <text|json> 输出格式(默认 text)
1119
-
1120
- 示例:
1121
- ec msg history alice.agentid.pub bob.agentid.pub
1122
- ec msg history alice.agentid.pub bob.agentid.pub --session latest
1123
- ec msg history alice.agentid.pub bob.agentid.pub --session all
1124
- ec msg history alice.agentid.pub bob.agentid.pub --session meta_20260713_1783920000000 --format json
1188
+ console.log(`用法: ec msg history <self-aid> [<target-aid> | --channel-key <key> --peer-id <id>] [options]
1189
+
1190
+ 查询指定会话对的本地历史,不调用 message.pull,也不影响收件箱游标。非 AUN selector 按已落盘的 session metadata、完整 channelKey 与原生 peer ID 精确读取,不能传入文件路径。
1191
+
1192
+ 托管会话限制:普通会话只能使用当前 self AID 和当前 AUN 私聊对端;可信 daemon Trigger 可用精确的 --channel-key/--peer-id selector 读取已落盘的非 AUN 私聊历史。托管任务不支持 --channel、--channel-name、--aun-path 或 --app。
1193
+
1194
+ Options:
1195
+ --session <latest|all|id> 默认 latest;all 查询全部;也可指定会话 ID
1196
+ --limit <N> 返回最新 N 条(默认 50,最大 500)
1197
+ --before <time> 开区间;epoch 毫秒或 ISO 时间
1198
+ --after <time> 开区间;epoch 毫秒或 ISO 时间
1199
+ --direction <value> in|out|all(默认 all)
1200
+ --channel-key <key> 非 AUN 已落盘渠道完整键;必须与 --peer-id 同时给出
1201
+ --peer-id <id> 原生私聊对端 ID;必须与 --channel-key 同时给出
1202
+ --format <text|json> 输出格式(默认 text)
1203
+
1204
+ 示例:
1205
+ ec msg history alice.agentid.pub bob.agentid.pub
1206
+ ec msg history alice.agentid.pub bob.agentid.pub --session latest
1207
+ ec msg history alice.agentid.pub bob.agentid.pub --session all
1208
+ ec msg history alice.agentid.pub bob.agentid.pub --session meta_20260713_1783920000000 --format json
1125
1209
  ec msg history alice.agentid.pub --channel-key feishu#alice.agentid.pub#main --peer-id ou_xxx --session all --format json`);
1126
1210
  return;
1127
1211
  }
@@ -1142,6 +1226,20 @@ Options:
1142
1226
  }
1143
1227
  const { msgSend, msgPull, msgAck, msgRecall, msgOnline, msgHistory } = await import('../aun/msg/index.js');
1144
1228
  const commonOpts = { aunPath, slotId: appSlot };
1229
+ const requireConsumerSlot = (operation) => {
1230
+ if (appSlot)
1231
+ return appSlot;
1232
+ const error = {
1233
+ ok: false,
1234
+ code: 'APP_SLOT_REQUIRED',
1235
+ error: `${operation} requires an explicit --app <name> isolated consumer slot; refusing to access the daemon inbox`,
1236
+ };
1237
+ if (formatJson)
1238
+ console.log(JSON.stringify(error));
1239
+ else
1240
+ console.error(`❌ ${error.error}`);
1241
+ process.exit(1);
1242
+ };
1145
1243
  if (sub === 'history') {
1146
1244
  const target = args[2] && !args[2].startsWith('--') ? args[2] : undefined;
1147
1245
  const historyValueFlags = new Set([
@@ -1389,9 +1487,7 @@ Options:
1389
1487
  return;
1390
1488
  }
1391
1489
  if (sub === 'pull') {
1392
- if (!appSlot) {
1393
- console.warn('⚠ 警告: 未传 --app,当前与 daemon 共享 evolcore 消费通道。pull 会看到/影响 daemon 的消息消费;如需独立消费请用 --app <name>');
1394
- }
1490
+ const consumerSlot = requireConsumerSlot('ec msg pull');
1395
1491
  const afterSeqStr = getArgValue(args, '--after-seq');
1396
1492
  const limitStr = getArgValue(args, '--limit');
1397
1493
  const afterSeq = afterSeqStr !== undefined ? Number(afterSeqStr) : undefined;
@@ -1404,7 +1500,7 @@ Options:
1404
1500
  console.error(`❌ --limit 必须是数字: ${limitStr}`);
1405
1501
  process.exit(1);
1406
1502
  }
1407
- const result = await msgPull({ from, afterSeq, limit, ...commonOpts });
1503
+ const result = await msgPull({ from, afterSeq, limit, aunPath, slotId: consumerSlot });
1408
1504
  if (!result.ok) {
1409
1505
  if (formatJson) {
1410
1506
  console.log(JSON.stringify(result));
@@ -1440,10 +1536,8 @@ Options:
1440
1536
  console.error(`❌ seq 必须是数字: ${seqStr}`);
1441
1537
  process.exit(1);
1442
1538
  }
1443
- if (!appSlot) {
1444
- console.warn('⚠ 警告: 未传 --app,ack 将推进与 daemon 共享的 evolcore 消费游标,可能影响 daemon 收消息;如需独立请用 --app <name>');
1445
- }
1446
- const result = await msgAck({ from, seq, ...commonOpts });
1539
+ const consumerSlot = requireConsumerSlot('ec msg ack');
1540
+ const result = await msgAck({ from, seq, aunPath, slotId: consumerSlot });
1447
1541
  if (!result.ok) {
1448
1542
  if (formatJson) {
1449
1543
  console.log(JSON.stringify(result));
@@ -1540,74 +1634,74 @@ export async function cmdGroup(args) {
1540
1634
  const appSlot = getArgValue(args, '--app');
1541
1635
  const rulesActionHelp = sub === 'rules' && isHelpFlag(args[3]);
1542
1636
  if (!sub || isHelpFlag(sub) || (wantsHelp(args) && !rulesActionHelp)) {
1543
- console.log(`用法: ec group <command> <from-aid> [args...] [options]
1544
-
1545
- 消息:
1546
- send <from> <group-id> <text> --return <none|required> 发送群文本(跨会话时 --return 必填)
1547
- send <from> <group-id> --file <path> [--as <type>] 发送群文件
1548
- send <from> <group-id> --payload <json> 发送自定义 payload
1549
- pull <from> <group-id> [--after-seq N] [--limit N] 拉取群消息
1550
- ack <from> <group-id> <seq> [--app <name>] 确认已读
1551
-
1552
- 群管理:
1553
- create <from> <name> [--visibility public|private] [--description D]
1554
- [--join-mode open|approval|invite_only|closed] 创建群
1555
- list <from> [--size N] 列出我加入的群
1556
- info <from> <group-id> 查看群详情
1557
- update <from> <group-id> [--name N] [--description D] 修改群信息
1558
- dissolve <from> <group-id> 解散群
1559
- suspend <from> <group-id> 暂停群
1560
- resume <from> <group-id> 恢复群
1561
- rules <from> <group-id> get 读取已发布群规则文件 /rules.md
1562
- rules <from> <group-id> set <file> 上传并发布群规则文件
1563
- rules <from> <group-id> publish 发布当前群空间 /rules.md
1564
- rules <from> <group-id> [--mode M] [--question Q] [--max-pending N] 查看/更新入群规则
1565
-
1566
- 成员:
1567
- join <from> <group-id> [--message M] [--answer A] 申请加入
1568
- leave <from> <group-id> 退出群
1569
- invite <from> <group-id> <member-aid> [<member-aid>...] 创建定向邀请
1570
- invites <from> [--page N] [--size N] 查看收到的邀请
1571
- accept-invite <from> <invite-id> 接受邀请
1572
- reject-invite <from> <invite-id> 拒绝邀请
1573
- revoke-invite <from> <invite-id> 撤回邀请
1574
- kick <from> <group-id> <member-aid> 踢出成员
1575
- members <from> <group-id> [--page N] [--size N] 列出群成员
1576
- online <from> <group-id> 查看在线成员
1577
- role <from> <group-id> <member-aid> <admin|member> 设置成员角色
1578
- owner <from> <group-id> <new-owner-aid> 转让群主
1579
- ban <from> <group-id> [<member-aid>] [--duration N] 封禁成员;不带 member-aid 时列出封禁
1580
- unban <from> <group-id> <member-aid> 解封成员
1581
-
1582
- Options:
1583
- --app <name> 指定应用 slot(独立消费通道,不影响 daemon)
1584
- --aun-path <path> 指定 AUN keystore 根
1585
- --format json 输出 JSON 格式
1586
- --encrypt 强制端到端加密(未指定时使用 daemon 默认值;仅 send)
1587
- --no-encrypt 强制明文发送(优先于 --encrypt;仅 send)
1588
- --thread <id> 指定话题 ID(仅 send)
1589
- --return <none|required> 跨会话发送必填(仅 send;Trigger 只能使用 none)
1590
- --mention <aid> 发送时 @ 某个成员(可多次,或用逗号分隔多个 aid)
1591
- --mention-all 发送时 @ 所有人
1592
- --content-type <mime> 显式覆盖 MIME(仅 --file 模式)
1593
- --as <type> 附件类型:image|video|voice|file(仅 --file 模式)
1594
- --text <说明> 附件说明文字(仅 --file 模式)
1595
- --transcript <text> 语音转写(仅 --as voice)
1596
- --group-id <aid> 指定自定义群 AID(仅 create)
1597
- --member-type <type> 定向邀请成员类型:human|ai(仅 invite)
1598
- -- end-of-options:其后所有参数按正文处理
1599
- (用于发送恰好等于某 flag 的文本,如 send a g -- --encrypt)
1600
-
1601
- 格式示例(.example.invalid 是保留的虚构域,以下 AID 均不是真实地址):
1602
- ec group create sender.example.invalid "Dev Team" --visibility private
1603
- ec group send sender.example.invalid 12345.example.invalid "hello team" --return none
1604
- ec group send sender.example.invalid 12345.example.invalid "@member 看下 PR" --mention member.example.invalid
1605
- ec group send sender.example.invalid 12345.example.invalid --file ./arch.png
1606
- ec group rules sender.example.invalid 12345.example.invalid set ./rules.md
1607
- ec group invite sender.example.invalid 12345.example.invalid member.example.invalid
1608
- ec group members sender.example.invalid 12345.example.invalid
1609
-
1610
- 查询真实群 AID:
1637
+ console.log(`用法: ec group <command> <from-aid> [args...] [options]
1638
+
1639
+ 消息:
1640
+ send <from> <group-id> <text> --return <none|required> 发送群文本(跨会话时 --return 必填)
1641
+ send <from> <group-id> --file <path> [--as <type>] 发送群文件
1642
+ send <from> <group-id> --payload <json> 发送自定义 payload
1643
+ pull <from> <group-id> [--after-seq N] [--limit N] --app <name> 拉取群消息(必须使用独立 slot)
1644
+ ack <from> <group-id> <seq> [--app <name>] 确认已读
1645
+
1646
+ 群管理:
1647
+ create <from> <name> [--visibility public|private] [--description D]
1648
+ [--join-mode open|approval|invite_only|closed] 创建群
1649
+ list <from> [--size N] 列出我加入的群
1650
+ info <from> <group-id> 查看群详情
1651
+ update <from> <group-id> [--name N] [--description D] 修改群信息
1652
+ dissolve <from> <group-id> 解散群
1653
+ suspend <from> <group-id> 暂停群
1654
+ resume <from> <group-id> 恢复群
1655
+ rules <from> <group-id> get 读取已发布群规则文件 /rules.md
1656
+ rules <from> <group-id> set <file> 上传并发布群规则文件
1657
+ rules <from> <group-id> publish 发布当前群空间 /rules.md
1658
+ rules <from> <group-id> [--mode M] [--question Q] [--max-pending N] 查看/更新入群规则
1659
+
1660
+ 成员:
1661
+ join <from> <group-id> [--message M] [--answer A] 申请加入
1662
+ leave <from> <group-id> 退出群
1663
+ invite <from> <group-id> <member-aid> [<member-aid>...] 创建定向邀请
1664
+ invites <from> [--page N] [--size N] 查看收到的邀请
1665
+ accept-invite <from> <invite-id> 接受邀请
1666
+ reject-invite <from> <invite-id> 拒绝邀请
1667
+ revoke-invite <from> <invite-id> 撤回邀请
1668
+ kick <from> <group-id> <member-aid> 踢出成员
1669
+ members <from> <group-id> [--page N] [--size N] 列出群成员
1670
+ online <from> <group-id> 查看在线成员
1671
+ role <from> <group-id> <member-aid> <admin|member> 设置成员角色
1672
+ owner <from> <group-id> <new-owner-aid> 转让群主
1673
+ ban <from> <group-id> [<member-aid>] [--duration N] 封禁成员;不带 member-aid 时列出封禁
1674
+ unban <from> <group-id> <member-aid> 解封成员
1675
+
1676
+ Options:
1677
+ --app <name> 指定应用 slot(独立消费通道,不影响 daemon)
1678
+ --aun-path <path> 指定 AUN keystore 根
1679
+ --format json 输出 JSON 格式
1680
+ --encrypt 强制端到端加密(未指定时使用 daemon 默认值;仅 send)
1681
+ --no-encrypt 强制明文发送(优先于 --encrypt;仅 send)
1682
+ --thread <id> 指定话题 ID(仅 send)
1683
+ --return <none|required> 跨会话发送必填(仅 send;Trigger 只能使用 none)
1684
+ --mention <aid> 发送时 @ 某个成员(可多次,或用逗号分隔多个 aid)
1685
+ --mention-all 发送时 @ 所有人
1686
+ --content-type <mime> 显式覆盖 MIME(仅 --file 模式)
1687
+ --as <type> 附件类型:image|video|voice|file(仅 --file 模式)
1688
+ --text <说明> 附件说明文字(仅 --file 模式)
1689
+ --transcript <text> 语音转写(仅 --as voice)
1690
+ --group-id <aid> 指定自定义群 AID(仅 create)
1691
+ --member-type <type> 定向邀请成员类型:human|ai(仅 invite)
1692
+ -- end-of-options:其后所有参数按正文处理
1693
+ (用于发送恰好等于某 flag 的文本,如 send a g -- --encrypt)
1694
+
1695
+ 格式示例(.example.invalid 是保留的虚构域,以下 AID 均不是真实地址):
1696
+ ec group create sender.example.invalid "Dev Team" --visibility private
1697
+ ec group send sender.example.invalid 12345.example.invalid "hello team" --return none
1698
+ ec group send sender.example.invalid 12345.example.invalid "@member 看下 PR" --mention member.example.invalid
1699
+ ec group send sender.example.invalid 12345.example.invalid --file ./arch.png
1700
+ ec group rules sender.example.invalid 12345.example.invalid set ./rules.md
1701
+ ec group invite sender.example.invalid 12345.example.invalid member.example.invalid
1702
+ ec group members sender.example.invalid 12345.example.invalid
1703
+
1704
+ 查询真实群 AID:
1611
1705
  ec group list <发送方AID>`);
1612
1706
  return;
1613
1707
  }
@@ -1877,12 +1971,18 @@ Options:
1877
1971
  }
1878
1972
  if (sub === 'pull') {
1879
1973
  const groupId = requireGroupId();
1880
- if (!appSlot) {
1881
- console.warn('⚠ 警告: 未传 --app,当前与 daemon 共享 evolcore 消费通道。pull 会看到/影响 daemon 的消息消费;如需独立消费请用 --app <name>');
1974
+ const consumerSlot = appSlot;
1975
+ if (!consumerSlot) {
1976
+ const error = 'ec group pull requires an explicit --app <name> isolated consumer slot; refusing to access the daemon inbox';
1977
+ if (formatJson)
1978
+ console.log(JSON.stringify({ ok: false, code: 'APP_SLOT_REQUIRED', error }));
1979
+ else
1980
+ console.error(`❌ ${error}`);
1981
+ process.exit(1);
1882
1982
  }
1883
1983
  const afterSeq = parseNumberFlag('--after-seq', '--after-seq');
1884
1984
  const limit = parseNumberFlag('--limit', '--limit');
1885
- const result = await groupPull({ from, groupId, afterSeq, limit, ...commonOpts });
1985
+ const result = await groupPull({ from, groupId, afterSeq, limit, aunPath, slotId: consumerSlot });
1886
1986
  outputResult(result, () => {
1887
1987
  const r = result;
1888
1988
  console.log(`✓ ${r.messages.length} 条消息,latest_seq=${r.latest_message_seq}${r.has_more ? '(还有更多)' : ''}`);
@@ -1905,10 +2005,16 @@ Options:
1905
2005
  console.error(`❌ seq 必须是数字: ${seqStr}`);
1906
2006
  process.exit(1);
1907
2007
  }
1908
- if (!appSlot) {
1909
- console.warn('⚠ 警告: 未传 --app,ack 将推进与 daemon 共享的 evolcore 消费游标,可能影响 daemon 收消息;如需独立请用 --app <name>');
2008
+ const consumerSlot = appSlot;
2009
+ if (!consumerSlot) {
2010
+ const error = 'ec group ack requires an explicit --app <name> isolated consumer slot; refusing to access the daemon inbox';
2011
+ if (formatJson)
2012
+ console.log(JSON.stringify({ ok: false, code: 'APP_SLOT_REQUIRED', error }));
2013
+ else
2014
+ console.error(`❌ ${error}`);
2015
+ process.exit(1);
1910
2016
  }
1911
- const result = await groupAck({ from, groupId, seq, ...commonOpts });
2017
+ const result = await groupAck({ from, groupId, seq, aunPath, slotId: consumerSlot });
1912
2018
  outputResult(result, () => {
1913
2019
  const r = result;
1914
2020
  console.log(`✓ ack_seq=${r.ack_seq}`);
@@ -2027,18 +2133,18 @@ Options:
2027
2133
  const groupId = requireGroupId();
2028
2134
  const action = args[3];
2029
2135
  const printRulesFileUsage = () => {
2030
- console.log(`用法:
2031
- ec group rules <from> <group-id> get
2032
- ec group rules <from> <group-id> set <file>
2033
- ec group rules <from> <group-id> publish
2034
- ec group rules <from> <group-id> [--mode open|approval|invite_only|closed] [--question Q] [--max-pending N]
2035
-
2036
- 说明:
2037
- get 读取当前已发布的群规则文件 /rules.md
2038
- set 上传本地文件到群空间 /rules.md,发布 rules.content 元数据,并发送 group.rules.updated 通知
2039
- publish 不上传文件,仅发布当前群空间 /rules.md 的元数据并发送通知
2040
-
2041
- 兼容:
2136
+ console.log(`用法:
2137
+ ec group rules <from> <group-id> get
2138
+ ec group rules <from> <group-id> set <file>
2139
+ ec group rules <from> <group-id> publish
2140
+ ec group rules <from> <group-id> [--mode open|approval|invite_only|closed] [--question Q] [--max-pending N]
2141
+
2142
+ 说明:
2143
+ get 读取当前已发布的群规则文件 /rules.md
2144
+ set 上传本地文件到群空间 /rules.md,发布 rules.content 元数据,并发送 group.rules.updated 通知
2145
+ publish 不上传文件,仅发布当前群空间 /rules.md 的元数据并发送通知
2146
+
2147
+ 兼容:
2042
2148
  不带 get/set/publish 时仍使用旧的入群规则接口。`);
2043
2149
  };
2044
2150
  const printRulesFileState = (result, verb) => {