evolcore 0.0.48 → 0.0.50

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 (302) hide show
  1. package/CHANGELOG.md +97 -0
  2. package/bin/ecmsg.js +9 -4
  3. package/dist/ability/caller/authorization.js +21 -0
  4. package/dist/ability/caller/command.js +164 -0
  5. package/dist/ability/caller/contract.js +102 -0
  6. package/dist/ability/caller/daemon.js +158 -0
  7. package/dist/ability/caller/service.js +380 -0
  8. package/dist/ability/command-contract.js +5 -0
  9. package/dist/ability/daemon.js +5 -1
  10. package/dist/ability/interop-v1.js +10 -3
  11. package/dist/ability/management.js +1 -0
  12. package/dist/agent-template/jobs.js +173 -1
  13. package/dist/agent-template/runtime.js +285 -8
  14. package/dist/agent-template/service.js +1159 -40
  15. package/dist/agent-template/types.js +2 -1
  16. package/dist/agents/baseagent-availability.js +27 -3
  17. package/dist/agents/baseagent-capability-adapter.js +102 -0
  18. package/dist/agents/baseagent-plugin-descriptor.js +274 -0
  19. package/dist/agents/baseagent-plugin-loader.js +145 -0
  20. package/dist/agents/baseagent.js +68 -2
  21. package/dist/agents/claude-gateway/agent-registration.js +389 -0
  22. package/dist/agents/claude-gateway/binding.js +96 -0
  23. package/dist/agents/claude-gateway/inbox.js +138 -0
  24. package/dist/agents/claude-gateway/index.js +125 -0
  25. package/dist/agents/claude-gateway/listing.js +330 -0
  26. package/dist/agents/claude-gateway/router.js +328 -0
  27. package/dist/agents/claude-gateway/sessions.js +128 -0
  28. package/dist/agents/claude-gateway/terminal.js +250 -0
  29. package/dist/agents/claude-gateway/transcript.js +272 -0
  30. package/dist/agents/claude-gateway/types.js +14 -0
  31. package/dist/agents/claude-runner.js +6 -10
  32. package/dist/agents/codex-runner.js +9 -2
  33. package/dist/agents/{gemini-runner.js → gemini/gemini-runner.js} +17 -17
  34. package/dist/{core/session/adapters → agents/gemini}/gemini-session-file-adapter.js +2 -2
  35. package/dist/agents/gemini/index.js +51 -0
  36. package/dist/aun/aid/control-aid.js +52 -32
  37. package/dist/aun/group/invite-service.js +6 -36
  38. package/dist/aun/group/operations.js +6 -0
  39. package/dist/aun/msg/mention-schema.js +1 -1
  40. package/dist/aun/msg/p2p.js +31 -2
  41. package/dist/aun/msg/upload.js +126 -3
  42. package/dist/build-identity.json +1 -1
  43. package/dist/channels/aun.js +1175 -457
  44. package/dist/cli/ability-command.js +42 -0
  45. package/dist/cli/agent-command.js +20 -1
  46. package/dist/cli/agent-create.js +78 -18
  47. package/dist/cli/agent-template.js +5 -3
  48. package/dist/cli/agent.js +91 -0
  49. package/dist/cli/aun-commands.js +92 -34
  50. package/dist/cli/bench.js +5 -2
  51. package/dist/cli/config.js +22 -6
  52. package/dist/cli/daemon-commands.js +245 -101
  53. package/dist/cli/directory.js +6 -1
  54. package/dist/cli/ecmsg-gateway.js +11 -9
  55. package/dist/cli/index.js +30 -5
  56. package/dist/cli/init.js +39 -63
  57. package/dist/cli/managed-command-guard.js +3 -0
  58. package/dist/cli/menu-client.js +32 -7
  59. package/dist/cli/model.js +20 -5
  60. package/dist/cli/pay-command.js +30 -0
  61. package/dist/cli/provider-command.js +6 -2
  62. package/dist/cli/quota.js +89 -0
  63. package/dist/cli/restart-monitor.js +2 -2
  64. package/dist/cli/role.js +1 -0
  65. package/dist/cli/services-command.js +12 -9
  66. package/dist/cli/team-workspace-command.js +56 -2
  67. package/dist/cli/thread-command.js +78 -12
  68. package/dist/config/access-policy.js +16 -3
  69. package/dist/config/config-field-policy.js +88 -9
  70. package/dist/config/config-manager.js +97 -47
  71. package/dist/config/config-operation-service.js +22 -1
  72. package/dist/config/gateway-config.js +9 -8
  73. package/dist/config/owner-config.js +0 -16
  74. package/dist/config/peer-role-resolver.js +1 -7
  75. package/dist/config/providers-config.js +107 -20
  76. package/dist/config/providers-management.js +45 -21
  77. package/dist/config/resolved-config-op.js +4 -44
  78. package/dist/config/schema-migration.js +78 -5
  79. package/dist/config/schema-registry.js +52 -7
  80. package/dist/config-store.js +1309 -17
  81. package/dist/core/agent-application-service.js +220 -1
  82. package/dist/core/agent-ipc-registration.js +19 -2
  83. package/dist/core/agent-reload-coordinator.js +5 -0
  84. package/dist/core/agent-runtime.js +198 -54
  85. package/dist/core/auth/agent-delegation.js +14 -0
  86. package/dist/core/auth/delegation-authorization.js +33 -26
  87. package/dist/core/auth/operation-authorizer.js +16 -1
  88. package/dist/core/auth/operation-catalog.js +59 -7
  89. package/dist/core/baseagent-loader.js +30 -3
  90. package/dist/core/capability/capability-manager.js +16 -7
  91. package/dist/core/channel-runtime.js +4 -2
  92. package/dist/core/command/agent-control.js +20 -2
  93. package/dist/core/command/agent-template-menu.js +4 -3
  94. package/dist/core/command/cli-intent-parser.js +28 -0
  95. package/dist/core/command/command-handler.js +45 -2
  96. package/dist/core/command/menu-catalog.js +20 -4
  97. package/dist/core/command/menu-file-path.js +70 -0
  98. package/dist/core/command/menu-handler.js +97 -73
  99. package/dist/core/command/menu-protocol.js +29 -0
  100. package/dist/core/command/menu-query-batch.js +2 -2
  101. package/dist/core/command/private-mention-menu.js +71 -0
  102. package/dist/core/command/remote-shell.js +565 -0
  103. package/dist/core/command/slash-handler.js +17 -26
  104. package/dist/core/command/team-workspace-bootstrap.js +2 -1
  105. package/dist/core/command/topic-slash.js +7 -1
  106. package/dist/core/daemon-bootstrap.js +0 -4
  107. package/dist/core/daemon-control.js +58 -1
  108. package/dist/core/daemon-lifecycle.js +29 -7
  109. package/dist/core/evolagent-registry.js +18 -9
  110. package/dist/core/handoff/runtime.js +1 -1
  111. package/dist/core/host-snapshot.js +8 -3
  112. package/dist/core/initialization/service.js +3 -0
  113. package/dist/core/interaction-router.js +130 -0
  114. package/dist/core/ipc-registration.js +5 -0
  115. package/dist/core/memory/consolidation-context.js +2 -1
  116. package/dist/core/memory/consolidation.js +35 -64
  117. package/dist/core/message/aun-ipc-sender.js +213 -74
  118. package/dist/core/message/aun-request-registry.js +31 -0
  119. package/dist/core/message/contact-admission.js +91 -6
  120. package/dist/core/message/contact-pending-inbound.js +113 -0
  121. package/dist/core/message/contact-thread-approval.js +212 -0
  122. package/dist/core/message/im-renderer.js +40 -1
  123. package/dist/core/message/message-admission.js +5 -39
  124. package/dist/core/message/message-bridge.js +197 -45
  125. package/dist/core/message/message-log.js +32 -0
  126. package/dist/core/message/message-queue.js +102 -18
  127. package/dist/core/message/peer-mode.js +15 -4
  128. package/dist/core/message/response-engine.js +174 -26
  129. package/dist/core/message/send-options.js +37 -3
  130. package/dist/core/message/send-routing.js +11 -7
  131. package/dist/core/model/config-scope.js +6 -14
  132. package/dist/core/model/model-catalog.js +5 -5
  133. package/dist/core/model/model-diagnostics.js +19 -0
  134. package/dist/core/model/model-fallback.js +13 -2
  135. package/dist/core/ownership/owner-resolver.js +12 -86
  136. package/dist/core/pack-auth.js +7 -0
  137. package/dist/core/pack-install.js +1 -1
  138. package/dist/core/permission/ec-command-parser.js +288 -77
  139. package/dist/core/permission/protected-paths.js +64 -9
  140. package/dist/core/permission/services-path-acl.js +458 -0
  141. package/dist/core/permission/tool-policy.js +26 -10
  142. package/dist/core/relation/peer-identity.js +13 -0
  143. package/dist/core/session/adapters/claude-session-file-adapter.js +6 -2
  144. package/dist/core/session/adapters/codex-session-file-adapter.js +4 -0
  145. package/dist/core/session/session-manager.js +47 -10
  146. package/dist/core/session/session-mapper.js +16 -0
  147. package/dist/core/skill/index-generator.js +2 -3
  148. package/dist/core/skill/switch-resolver.js +3 -0
  149. package/dist/core/task/task-recovery-service.js +1 -0
  150. package/dist/core/thread/command-parser.js +4 -1
  151. package/dist/core/thread/ipc-operation.js +4 -2
  152. package/dist/core/thread/thread-operation.js +25 -10
  153. package/dist/core/thread/thread-service.js +294 -55
  154. package/dist/core/thread/topic-id.js +67 -2
  155. package/dist/core/thread/types.js +15 -1
  156. package/dist/directory/owner-directory-admission.js +11 -8
  157. package/dist/directory/owner-directory-cache.js +19 -0
  158. package/dist/directory/owner-directory-markdown.js +1 -1
  159. package/dist/directory/owner-directory-policy.js +5 -30
  160. package/dist/directory/owner-directory-request-operation.js +5 -2
  161. package/dist/eck/kit-renderer.js +3 -2
  162. package/dist/eck/message-renderer.js +28 -5
  163. package/dist/ecweb/basic-settings-service.js +5 -9
  164. package/dist/ecweb/providers-service.js +4 -2
  165. package/dist/ecweb/runtime/supervisor.js +36 -8
  166. package/dist/event-center/center-config.js +9 -5
  167. package/dist/event-center/dispatcher.js +10 -1
  168. package/dist/event-center/ipc-operation.js +19 -0
  169. package/dist/event-center/registry.js +20 -5
  170. package/dist/event-center/runtime.js +10 -7
  171. package/dist/index.js +120 -41
  172. package/dist/ipc.js +83 -3
  173. package/dist/outputs/authorization.js +16 -0
  174. package/dist/outputs/cards.js +336 -0
  175. package/dist/outputs/events.js +3 -2
  176. package/dist/outputs/protocol.js +1 -0
  177. package/dist/outputs/service.js +2 -15
  178. package/dist/paths.js +48 -1
  179. package/dist/pay/command.js +38 -0
  180. package/dist/pay/protocol.js +136 -0
  181. package/dist/pay/runtime.js +188 -0
  182. package/dist/pay/service.js +384 -0
  183. package/dist/pay/store.js +81 -0
  184. package/dist/response-system/engines/v1/proactive-flow.js +29 -2
  185. package/dist/services/dispatcher.js +23 -5
  186. package/dist/services/host/main.js +388 -0
  187. package/dist/services/host/protocol.js +118 -0
  188. package/dist/services/host/resident.js +310 -0
  189. package/dist/services/host-client.js +386 -0
  190. package/dist/services/host-deploy.js +180 -0
  191. package/dist/services/host-launch.js +117 -0
  192. package/dist/services/host-recycle.js +203 -0
  193. package/dist/services/host-runtime.js +802 -0
  194. package/dist/services/idempotency.js +44 -86
  195. package/dist/services/index-generator.js +4 -3
  196. package/dist/services/index.js +204 -22
  197. package/dist/services/ipc-operation.js +288 -44
  198. package/dist/services/pack-manager.js +1 -0
  199. package/dist/services/script-runner.js +515 -83
  200. package/dist/services/service-payload.js +13 -7
  201. package/dist/services/validation.js +109 -4
  202. package/dist/stats/budget.js +1 -1
  203. package/dist/stats/model-resolver.js +2 -2
  204. package/dist/stats/quota-query.js +95 -0
  205. package/dist/trigger/application-service.js +6 -4
  206. package/dist/trigger/local-files.js +19 -9
  207. package/dist/trigger/scheduler.js +22 -12
  208. package/dist/trigger/script-sandbox.js +51 -8
  209. package/dist/utils/aid-bind.js +3 -0
  210. package/dist/utils/atomic-write.js +22 -8
  211. package/dist/utils/evolcore-version.js +2 -2
  212. package/dist/utils/host-info.js +173 -1
  213. package/dist/utils/logger.js +2 -2
  214. package/dist/utils/media-cache.js +190 -43
  215. package/dist/utils/npm-ops.js +43 -8
  216. package/dist/utils/restart-safety.js +14 -1
  217. package/dist/utils/system-memory.js +113 -25
  218. package/dist/utils/systemd-lifecycle.js +154 -0
  219. package/dist/utils/windows-shell-trust.js +7 -3
  220. package/dist/workbench/service.js +1 -1
  221. package/kits/docs/INDEX.md +3 -2
  222. package/kits/docs/aun/AUN/346/266/210/346/201/257/347/261/273/345/236/213/344/270/216/345/261/236/346/200/247.md +1 -0
  223. package/kits/docs/channels/aun.md +1 -1
  224. package/kits/docs/evolcore/INDEX.md +9 -6
  225. package/kits/docs/evolcore/agent.md +36 -1
  226. package/kits/docs/evolcore/aid.md +45 -3
  227. package/kits/docs/evolcore/config.md +5 -2
  228. package/kits/docs/evolcore/directory.md +8 -9
  229. package/kits/docs/evolcore/group.md +2 -1
  230. package/kits/docs/evolcore/memory-tags.md +2 -0
  231. package/kits/docs/evolcore/menu-client.md +3 -3
  232. package/kits/docs/evolcore/menu-protocol.md +7 -0
  233. package/kits/docs/evolcore/model.md +3 -0
  234. package/kits/docs/evolcore/msg.md +77 -10
  235. package/kits/docs/evolcore/pay.md +34 -0
  236. package/kits/docs/evolcore/provider.md +22 -1
  237. package/kits/docs/evolcore/quota.md +54 -0
  238. package/kits/docs/evolcore/role.md +3 -0
  239. package/kits/docs/evolcore/services.md +46 -18
  240. package/kits/docs/evolcore/stats.md +2 -0
  241. package/kits/docs/evolcore/thread-chain.md +2 -0
  242. package/kits/docs/evolcore/tool-authorization.md +10 -0
  243. package/kits/docs/evolcore/trigger.md +2 -0
  244. package/kits/rules/01-overview.md +11 -32
  245. package/kits/rules/02-navigation.md +7 -0
  246. package/kits/rules/06-channel.md +3 -3
  247. package/kits/schemas/_meta.json +38 -5
  248. package/kits/schemas/agent-config.schema.20.json +24 -0
  249. package/kits/schemas/agent-config.schema.21.json +974 -0
  250. package/kits/schemas/agent-config.schema.22.json +977 -0
  251. package/kits/schemas/agent-config.schema.23.json +958 -0
  252. package/kits/schemas/daemon.schema.10.json +373 -0
  253. package/kits/schemas/daemon.schema.9.json +12 -0
  254. package/kits/schemas/defaults.schema.7.json +472 -0
  255. package/kits/schemas/providers.schema.3.json +18 -2
  256. package/kits/schemas/relation-config.schema.13.json +289 -0
  257. package/kits/skills/.switches.json +17 -1
  258. package/kits/skills/ability/SKILL.md +229 -34
  259. package/kits/skills/ability/STRUCTURE.md +333 -0
  260. package/kits/skills/ability/references/cli.md +208 -0
  261. package/kits/skills/ability/references/development.md +107 -37
  262. package/kits/skills/ability/references/management.md +106 -46
  263. package/kits/skills/ability/references/runtime-protocol.md +65 -63
  264. package/kits/skills/agent-output-cards/SKILL.md +64 -0
  265. package/kits/skills/ec-group/SKILL.md +8 -6
  266. package/kits/skills/ec-group/TASK.md +186 -0
  267. package/kits/skills/ec-group/WORKLOG.md +180 -0
  268. package/kits/skills/ec-group-collaboration/SKILL.md +3 -3
  269. package/kits/skills/ec-pay/SKILL.md +101 -0
  270. package/kits/skills/ec-pay/references/pay-cli.md +110 -0
  271. package/kits/skills/ec-provider/SKILL.md +58 -9
  272. package/kits/skills/{ec-service-proxy → ec-proxy}/SKILL.md +8 -5
  273. package/kits/skills/ec-service-call/SKILL.md +135 -0
  274. package/kits/skills/ec-service-pack/SKILL.md +277 -0
  275. package/kits/skills/ec-trigger/SKILL.md +1 -1
  276. package/kits/templates/memory-consolidation/notes.md +2 -2
  277. package/kits/templates/memory-consolidation/workflow.md +46 -0
  278. package/kits/templates/roles/visitor.json +1 -0
  279. package/kits/templates/system-fragments/channel.md +13 -4
  280. package/kits/templates/system-fragments/commands.md +5 -3
  281. package/kits/templates/system-fragments/directory-contacts.md +3 -4
  282. package/kits/templates/system-fragments/reply.md +1 -0
  283. package/kits/templates/system-fragments/session.md +1 -1
  284. package/kits/templates/system-fragments/thread.md +27 -128
  285. package/kits/templates/system-fragments/venue.md +27 -0
  286. package/package.json +4 -5
  287. package/scripts/agent-template/inspect.mjs +79 -29
  288. package/scripts/agent-template/overlay.mjs +20 -2
  289. package/scripts/agent-template/shared/common.mjs +24 -6
  290. package/scripts/agent-template/shared/team-schema.json +23 -5
  291. package/scripts/agent-template/shared/template-contract.mjs +107 -17
  292. package/scripts/agent-template/shared/template-package.mjs +254 -29
  293. package/scripts/agent-template/shared/template-runtime.mjs +145 -2
  294. package/scripts/agent-template/shared/template.mjs +67 -9
  295. package/scripts/agent-template/team-pack.mjs +132 -41
  296. package/scripts/agent-template/team-preview.mjs +249 -5
  297. package/kits/docs/aun/ABILITY_CALLING.md +0 -280
  298. package/kits/docs/evolcore/ability.md +0 -185
  299. package/kits/skills/ability/references/calling.md +0 -56
  300. package/kits/skills/ability/references/contract-checklist.md +0 -37
  301. package/kits/skills/ability/references/recovery.md +0 -27
  302. /package/dist/{core/capability/providers → agents/gemini}/gemini-capability-provider.js +0 -0
@@ -0,0 +1,89 @@
1
+ import fs from 'node:fs';
2
+ import { resolvePaths } from '../paths.js';
3
+ import { readDelegationCredential } from '../core/auth/agent-delegation.js';
4
+ import { parseQuotaCommand } from '../stats/quota-query.js';
5
+ import { daemonUnavailableMessage, queryDaemon, wantsHelp } from './help.js';
6
+ const HELP = `用法: ec quota status [--self <agent-aid>] [--peer <aid|channel#id>] [--format text|json]
7
+
8
+ 查询 Agent 预算及对端的角色费用配额(上限、已用、剩余、周期、独立/共享、是否受限)。
9
+ 查看或修改角色额度规则使用 ec role quota show|set|disable|inherit。
10
+ 托管会话默认当前 Agent 和当前对端;宿主终端必须指定 --self,省略 --peer 时只查 Agent。
11
+ Owner/Admin 可查询指定对端;普通对端只可查询当前关系,不返回 Agent 总用量。
12
+ 群聊默认查询当前发言人在本群生效的角色额度。
13
+ 角色额度与一般预算分别返回,币种与计费口径不混算;-1 表示不限额。
14
+
15
+ ec quota status
16
+ ec quota status --peer alice.agentid.cn --format json
17
+ ec quota status --self bot.agentid.cn --format json`;
18
+ export async function cmdQuota(args) {
19
+ if (!args.length || wantsHelp(args)) {
20
+ console.log(HELP);
21
+ return;
22
+ }
23
+ const json = args.some((arg, index) => arg === '--format=json' || arg === '--format' && args[index + 1] === 'json');
24
+ try {
25
+ parseQuotaCommand(args);
26
+ const sessionId = process.env.EVOLCORE_SESSION_ID;
27
+ const delegationToken = readDelegationCredential();
28
+ const managed = sessionId !== undefined || delegationToken !== undefined;
29
+ if (managed && (!sessionId || !delegationToken))
30
+ throw Object.assign(new Error('Current task delegation is required'), { code: 'DELEGATION_REQUIRED' });
31
+ let controlToken;
32
+ if (!managed) {
33
+ try {
34
+ controlToken = fs.readFileSync(resolvePaths().controlToken, 'utf8').trim();
35
+ }
36
+ catch { }
37
+ }
38
+ const { response, transportError } = await queryDaemon(resolvePaths().socket, {
39
+ type: 'quota.op', argv: ['quota', ...args],
40
+ ...(managed ? { sessionId, delegationToken } : { controlToken }),
41
+ }, 30_000);
42
+ if (!response)
43
+ throw Object.assign(new Error(daemonUnavailableMessage(transportError, 'Unable to connect to the evolcore daemon')), { code: 'DAEMON_UNAVAILABLE' });
44
+ if (!response.ok || !response.result)
45
+ throw Object.assign(new Error(response.error ?? 'Quota query failed'), { code: response.code ?? 'QUOTA_QUERY_FAILED' });
46
+ if (json)
47
+ console.log(JSON.stringify(response.result, null, 2));
48
+ else
49
+ console.log(formatQuota(response.result));
50
+ }
51
+ catch (error) {
52
+ const failure = { ok: false, code: error.code ?? 'QUOTA_QUERY_FAILED', error: error.message ?? String(error) };
53
+ if (json)
54
+ console.log(JSON.stringify(failure));
55
+ else
56
+ console.error(`❌ [${failure.code}] ${failure.error}`);
57
+ process.exitCode = 1;
58
+ }
59
+ }
60
+ export function formatQuota(result) {
61
+ const lines = [`Agent: ${result.selfAid}`];
62
+ const amount = (value, currency) => value < 0 ? '不限额' : `${value.toFixed(4)} ${currency}`;
63
+ const budget = (status) => {
64
+ for (const [label, limit, used, remaining] of [
65
+ ['日预算', status.daily_limit_usd, status.daily_used_usd, status.daily_remaining_usd],
66
+ ['月预算', status.monthly_limit_usd, status.monthly_used_usd, status.monthly_remaining_usd],
67
+ ])
68
+ lines.push(` ${label}: 上限 ${amount(limit, 'USD')} / 已用 ${amount(used, 'USD')} / 剩余 ${amount(remaining, 'USD')}`);
69
+ };
70
+ if (result.agent.budget)
71
+ budget(result.agent.budget);
72
+ else
73
+ lines.push(' Agent 总预算用量: 仅 Owner/Admin 可见');
74
+ if (result.relation) {
75
+ const relation = result.relation;
76
+ const quota = relation.roleQuota;
77
+ lines.push(`对端: ${relation.peerKey}${relation.chatType === 'group' ? ` / 发言人 ${relation.actorId}` : ''}`);
78
+ lines.push(` 角色: ${quota.role} / ${quota.scope === 'role' ? '同角色共享额度' : '每个对端独立额度'}`);
79
+ lines.push(` 角色限额: ${quota.enabled ? '启用' : '不限制'}${quota.reason ? ` (${quota.reason})` : ''}`);
80
+ lines.push(` 上限 ${amount(quota.limit_amount, quota.currency)} / 已用 ${amount(quota.used_amount, quota.currency)} / 剩余 ${amount(quota.remaining_amount, quota.currency)}`);
81
+ lines.push(` 重置周期: ${quota.reset_mode} / 计费: ${quota.cost_basis}`);
82
+ if (relation.budget) {
83
+ lines.push(' 对端生效的一般预算(按 Agent 总用量计算):');
84
+ budget(relation.budget);
85
+ }
86
+ }
87
+ lines.push(`当前是否被额度阻止: ${result.hard_blocked ? '是' : '否'}`);
88
+ return lines.join('\n');
89
+ }
@@ -22,7 +22,7 @@ import { stopEcwebForRestart } from '../ecweb/runtime/lifecycle.js';
22
22
  import { StartupTracer, STARTUP_TRACE_ID_ENV } from '../utils/startup-trace.js';
23
23
  const execFileAsync = promisify(execFile);
24
24
  /** Read-only check performed before stopping the current daemon. */
25
- function preflightDataMigration(root, log) {
25
+ export function preflightDataMigration(root, log) {
26
26
  try {
27
27
  const plan = planDataMigration(root);
28
28
  const operations = plan.operations.filter(operation => operation.status !== 'acknowledged').length;
@@ -148,7 +148,7 @@ export async function cmdRestartMonitor() {
148
148
  const pendingFile = path.join(daemonControlDir(), 'restart-pending.json');
149
149
  const requestId = process.env[RESTART_REQUEST_ID_ENV] || 'unknown';
150
150
  const MAX_HEAL_ATTEMPTS = 3;
151
- const READY_TIMEOUT = 30000; // 30s(AUN sidecar + 外部渠道连接预留)
151
+ const READY_TIMEOUT = 36000; // 36s(AUN sidecar + 外部渠道连接预留;与 daemon-commands 的 READY_WAIT_TIMEOUT_MS 对齐)
152
152
  const HEAL_TIMEOUT = 30 * 60 * 1000; // 30 分钟,让 claude 自然结束
153
153
  const eventBus = new EventBus();
154
154
  const log = (msg) => {
package/dist/cli/role.js CHANGED
@@ -112,6 +112,7 @@ function printHelp() {
112
112
  申请不会立即改变权限,只记录一条待审批请求,交由本 Agent 的 owner 审批。
113
113
  approve / reject 只能由本 Agent 的 owner 执行;审批通过后才写入关系角色。
114
114
  quota 管理角色定义 usageLimits,不是消息准入频率 access.requestLimit。
115
+ quota show 查看角色额度规则及继承结果;查询具体对端已用和剩余使用 ec quota status。
115
116
  quota set 不自动启用限制;需要时明确传 --enabled true。disable 保留金额等设置。
116
117
  inherit 删除角色自己的额度覆盖,恢复使用 member 额度;set 会将当前继承值物化为本角色配置。
117
118
  owner/admin 不受角色配额限制;自定义角色没有显式额度时继承 member。
@@ -9,6 +9,7 @@ import path from 'node:path';
9
9
  import { ipcQuery } from '../ipc.js';
10
10
  import { readDelegationCredential, hashCurrentDelegatedCommand } from '../core/auth/agent-delegation.js';
11
11
  import { resolvePaths } from '../paths.js';
12
+ import { SERVICE_CALL_TIMEOUT_MS } from '../services/ipc-operation.js';
12
13
  const HELP = `ec services — 服务路由运维
13
14
 
14
15
  本机:
@@ -17,8 +18,10 @@ const HELP = `ec services — 服务路由运维
17
18
  ec services ledger <包名> [--tail N] [--aid <aid>] 台账
18
19
  ec services tail <包名> [--tail N] [--aid <aid>] 服务消息日志
19
20
  ec services doctor [<包名>] [--aid <aid>] 诊断
21
+ ec services repair-acl [--aid <aid>] 收紧 services/ 的 NTFS ACL(幂等,仅 Windows)
20
22
  ec services reload [--aid <aid>] 重载(全部包)
21
23
  ec services enable / disable [--aid <aid>] 总闸
24
+ ec services host enable / disable [--aid <aid>] 宿主模式(常驻执行形态)
22
25
  ec services rules show [<type>] [--aid <aid>] 调用准入规则
23
26
  ec services rules add <type> <aid...> [--deny] [--aid <aid>]
24
27
  ec services rules remove <type> <aid...> [--deny] [--aid <aid>]
@@ -32,11 +35,11 @@ const HELP = `ec services — 服务路由运维
32
35
  remove 默认把日志与台账归档到 <包>/logs/archive-<时间戳>/;--purge 连归档一起删。
33
36
  ec services pack list [--aid <aid>]
34
37
 
35
- 对端:
36
- ec services describe <aid> [--service <type>] 查对端可用服务
37
- ec services schema <aid> <type> 查某个服务的请求 schema
38
- ec services call <aid> <type> --data '<json>' [--timeout 30] [--encrypted] [--no-wait]
39
- ec services call --request-id <id> --wait 查已发出的调用(--aid 指定本端)
38
+ 对端(--aid 是被调用方;发送身份托管会话自动补齐,宿主终端用 --as):
39
+ ec services describe --aid <对端aid> [--type <type>] 查对端可用服务
40
+ ec services schema --aid <对端aid> --type <type> 查某个服务的请求 schema
41
+ ec services call --aid <对端aid> --type <type> --data '<json>'
42
+ [--as <发送身份>] [--timeout 12] [--encrypted]
40
43
 
41
44
  服务调用是点对点、要结果、不丢的消息:结果由 daemon 落盘,CLI 被杀也不丢。`;
42
45
  /** 这三个子命令的回包是「对端应答」,CLI 只打印正文。 */
@@ -122,7 +125,7 @@ export async function runServicesCommand(argv) {
122
125
  process.exitCode = response.code === 'NO_RESULT' ? 2 : 1;
123
126
  return;
124
127
  }
125
- // 对端调用的成功输出是应答正文;--no-wait 时没有 response,回落到 request_id。
128
+ // 对端调用的成功输出是应答正文。
126
129
  const result = response.result;
127
130
  if (RELAY_COMMANDS.has(args[0] ?? '') && result && 'response' in result) {
128
131
  const body = result.response;
@@ -137,12 +140,12 @@ export async function runServicesCommand(argv) {
137
140
  }
138
141
  printResult(result, json);
139
142
  }
140
- /** `--timeout` 预算 + 5s 余量,作为 IPC 等待上限。 */
143
+ /** `--timeout` 预算 + 5s 余量,作为 IPC 等待上限。缺省与 daemon 侧同源(12s)。 */
141
144
  function readCallBudget(args) {
142
145
  const index = args.indexOf('--timeout');
143
146
  const raw = index >= 0 ? args[index + 1] : undefined;
144
- const parsed = raw === undefined ? 30_000 : parseTimeoutMs(raw);
145
- return (parsed ?? 30_000) + 5_000;
147
+ const parsed = raw === undefined ? SERVICE_CALL_TIMEOUT_MS : parseTimeoutMs(raw);
148
+ return (parsed ?? SERVICE_CALL_TIMEOUT_MS) + 5_000;
146
149
  }
147
150
  function parseTimeoutMs(value) {
148
151
  const trimmed = value.trim().toLowerCase();
@@ -1,6 +1,11 @@
1
1
  import path from 'node:path';
2
+ import fs from 'node:fs';
3
+ import crypto from 'node:crypto';
2
4
  import { authorizeLocalCommand } from './task-context.js';
3
- import { agentWorkspaceDir } from '../paths.js';
5
+ import { agentOutputDir, agentWorkspaceDir, resolvePaths } from '../paths.js';
6
+ import { ipcQuery } from '../ipc.js';
7
+ import { readDelegationCredential, hashCurrentDelegatedCommand } from '../core/auth/agent-delegation.js';
8
+ import { publishOutputCard, removeOutputCard } from '../outputs/cards.js';
4
9
  import { readTeamWorkspaceNavigation, upsertTeamWorkspaceNavigation, removeTeamWorkspaceNavigation, updateTeamWorkspaceNavigation, } from '../core/command/team-workspace-store.js';
5
10
  import { readTeamMembers, updateTeamMembers } from '../core/command/team-workspace-team.js';
6
11
  import { TeamWorkspaceBootstrapService, TeamWorkspaceInitializer } from '../core/command/team-workspace-bootstrap.js';
@@ -11,8 +16,10 @@ const USAGE = `用法: ec team workspace init [--workspace <绝对路径>]
11
16
  ec team navigation update --replace-json <entries-json> [--expected-revision <n>]
12
17
  ec team members show
13
18
  ec team members update --members-json <aids-json>
19
+ ec team cards publish --file <card.json>
20
+ ec team cards remove --id <card-id>
14
21
 
15
- 所有命令只输出 JSON;只允许当前 Agent Owner 的 AUN 私聊托管会话。`;
22
+ 所有命令只输出 JSON;cards 命令只允许当前 Agent Owner 的 AUN 私聊托管会话。`;
16
23
  class TeamWorkspaceCommandError extends Error {
17
24
  code;
18
25
  constructor(code, message) {
@@ -55,6 +62,23 @@ function expectedRevision(args, current) {
55
62
  return revision;
56
63
  }
57
64
  function output(value) { process.stdout.write(`${JSON.stringify(value, null, 2)}\n`); }
65
+ async function publishCardChanged(aid, id, revision) {
66
+ const sessionId = process.env.EVOLCORE_SESSION_ID;
67
+ const delegationToken = sessionId ? readDelegationCredential() : undefined;
68
+ if (sessionId && !delegationToken)
69
+ return false;
70
+ try {
71
+ const response = await ipcQuery(resolvePaths().socket, {
72
+ type: 'events.op', argv: ['native-publish', 'team.output-cards.changed', '--aid', aid,
73
+ '--data', JSON.stringify({ sourceAid: aid, revision, cursor: `${revision}.1`, id })],
74
+ ...(sessionId && delegationToken ? { sessionId, delegationToken, delegationCommandHash: hashCurrentDelegatedCommand() } : {}),
75
+ }, 5_000, { throwOnError: false });
76
+ return response?.ok === true;
77
+ }
78
+ catch {
79
+ return false;
80
+ }
81
+ }
58
82
  function assertOwnerContext(context) {
59
83
  if (context.channel !== 'aun' || context.chatType !== 'private' || context.peerRole !== 'owner' || !context.selfAid || !context.peerId) {
60
84
  throw new TeamWorkspaceCommandError('NOT_ALLOWED', 'Team workspace commands require the current Agent Owner in an AUN private chat');
@@ -74,6 +98,36 @@ export async function cmdTeamWorkspace(rawArgs) {
74
98
  try {
75
99
  const context = await authorizeLocalCommand(['team', ...rawArgs]);
76
100
  assertOwnerContext(context);
101
+ if (rawArgs[0] === 'cards' && rawArgs[1] === 'publish') {
102
+ assertFlags(rawArgs.slice(2), ['--file']);
103
+ const fileIndex = rawArgs.indexOf('--file');
104
+ if (rawArgs.length !== 4 || fileIndex < 0)
105
+ throw new TeamWorkspaceCommandError('INVALID_ARGUMENT', USAGE);
106
+ const source = path.resolve(rawArgs[fileIndex + 1]);
107
+ let manifest;
108
+ try {
109
+ manifest = JSON.parse(fs.readFileSync(source, 'utf8'));
110
+ }
111
+ catch {
112
+ throw new TeamWorkspaceCommandError('INVALID_CARD', `Cannot read a valid card JSON file: ${source}`);
113
+ }
114
+ const card = publishOutputCard(context.selfAid, manifest, agentOutputDir);
115
+ const notified = await publishCardChanged(context.selfAid, card.id, card.version);
116
+ output({ ok: true, id: card.id, version: card.version, path: path.relative(agentOutputDir(context.selfAid), path.join(agentOutputDir(context.selfAid), '.cards', `${card.id}.json`)).split(path.sep).join('/'), notified });
117
+ return;
118
+ }
119
+ if (rawArgs[0] === 'cards' && rawArgs[1] === 'remove') {
120
+ assertFlags(rawArgs.slice(2), ['--id']);
121
+ const idIndex = rawArgs.indexOf('--id');
122
+ if (rawArgs.length !== 4 || idIndex < 0)
123
+ throw new TeamWorkspaceCommandError('INVALID_ARGUMENT', USAGE);
124
+ const id = rawArgs[idIndex + 1];
125
+ const removed = removeOutputCard(context.selfAid, id, agentOutputDir);
126
+ const revision = crypto.createHash('sha256').update(`${context.selfAid}:${id}:${Date.now()}`).digest('hex').slice(0, 24);
127
+ const notified = removed && await publishCardChanged(context.selfAid, id, revision);
128
+ output({ ok: true, id, removed, notified: notified || false });
129
+ return;
130
+ }
77
131
  if (rawArgs[0] === 'workspace' && rawArgs[1] === 'init') {
78
132
  const pathIndex = rawArgs.indexOf('--workspace');
79
133
  const workspace = pathIndex >= 0 ? rawArgs[pathIndex + 1] : undefined;
@@ -16,6 +16,7 @@ const HELP_TEXT = `
16
16
  show <ref> 查看单个话题的元数据
17
17
  history <ref> 读取话题历史消息
18
18
  create <peer> --name 新建话题(对端类型按关系证据自动识别,--group/--private 可覆盖)
19
+ 对端不能是本端自己;跨话题自派请先用真实对端建话题
19
20
  rename <ref> <名称> 修改话题名称(仅本端)
20
21
  status <ref> <状态> 更新话题状态(active|closed|archived)
21
22
  delete <ref> 删除话题(session 文件移入 _trash)
@@ -26,6 +27,7 @@ const HELP_TEXT = `
26
27
  rebuild-index 重建话题索引(丢失/损坏时使用)
27
28
  rebuild-index --check 检查索引健康状态(只报告不写盘,区分严重/轻微)
28
29
  check-index 同 rebuild-index --check
30
+ reconcile-status 对账索引与会话文件的状态漂移(默认只报告,--write 写回)
29
31
 
30
32
  典型工作流:
31
33
  1. ec thread peers # 查看有话题记录的所有对端
@@ -43,6 +45,10 @@ list 选项:
43
45
  --page <n> 页码
44
46
  --limit <n> 每页条数
45
47
 
48
+ reconcile-status 选项:
49
+ --write 按版本判定写回索引(仅「会话文件较新」的条目)
50
+ --agent <aid> 指定 Agent(宿主终端)
51
+
46
52
  history 选项:
47
53
  --limit <n> 消息条数上限(默认 50)
48
54
  --before <time> 截止时间
@@ -178,6 +184,21 @@ function printItem(item, opts) {
178
184
  return;
179
185
  }
180
186
  const obj = item;
187
+ // CreateThreadResult — 必须在 ThreadIndexEntry 之前检查:两者都含 threadId + sessionId,
188
+ // 而创建结果没有 lastActiveAt/nameUpdatedAt 这类索引字段。顺序写反会让创建成功
189
+ // 时走成条目渲染,peerUnverified 提示永远不出现。
190
+ if ('createdAt' in obj && 'sessionId' in obj && !('lastActiveAt' in obj)) {
191
+ console.log(`✓ 话题创建成功: ${obj.threadId}`);
192
+ console.log(` 名称: ${obj.name}`);
193
+ console.log(` 对端: ${obj.peer}`);
194
+ // 本地名片缓存缺失不影响创建(建话题不发消息,离线也必须可建),
195
+ // 但要让用户知道"这个对端本端还没见过",并给出补充路径。
196
+ if (obj.peerUnverified === true) {
197
+ console.warn(`⚠ 对端 ${obj.peer} 本地无名片缓存,消息可能无法投递`);
198
+ console.warn(` 先执行 ec aid agentmd get ${obj.peer} 拉取名片,再重试发送`);
199
+ }
200
+ return;
201
+ }
181
202
  // ThreadHistoryResult — 必须在 ThreadIndexEntry 之前检查,两者都含 threadId
182
203
  if ('messages' in obj && Array.isArray(obj.messages)) {
183
204
  const result = obj;
@@ -232,13 +253,6 @@ function printItem(item, opts) {
232
253
  console.log(`[${obj.time}] ${dir} ${obj.from}: ${String(obj.content).slice(0, 120)}`);
233
254
  return;
234
255
  }
235
- // CreateThreadResult
236
- if ('createdAt' in obj && 'sessionId' in obj) {
237
- console.log(`✓ 话题创建成功: ${obj.threadId}`);
238
- console.log(` 名称: ${obj.name}`);
239
- console.log(` 对端: ${obj.peer}`);
240
- return;
241
- }
242
256
  // RenameThreadResult
243
257
  if ('changed' in obj) {
244
258
  console.log(obj.changed ? `✓ 改名成功: ${obj.name}` : '✓ 名称未变更');
@@ -546,11 +560,12 @@ export async function runThreadCommand(args) {
546
560
  }
547
561
  const r = resp.result;
548
562
  if (dryRun) {
549
- // 两个计数都可能缺省(接口只回传有问题的维度),缺省按 0 处理,
563
+ // 三个计数都可能缺省(接口只回传有问题的维度),缺省按 0 处理,
550
564
  // 否则健康状态也会落进「建议 rebuild」分支。
551
565
  const missing = r.missing ?? 0;
552
566
  const stale = r.stale ?? 0;
553
- if (missing === 0 && stale === 0) {
567
+ const selfPeer = r.selfPeer ?? 0;
568
+ if (missing === 0 && stale === 0 && selfPeer === 0) {
554
569
  console.log(`✓ 索引健康:共 ${r.rebuilt ?? r.total} 条话题,session 文件完整`);
555
570
  }
556
571
  else {
@@ -560,7 +575,14 @@ export async function runThreadCommand(args) {
560
575
  if (stale > 0) {
561
576
  console.warn(`⚠ [轻微] ${stale} 条话题属性与 session 文件最后一行不一致(写盘时序),rebuild-index 可修复`);
562
577
  }
563
- console.warn(` 建议执行 ec thread rebuild-index 修复`);
578
+ if (selfPeer > 0) {
579
+ console.warn(`⚠ [严重] ${selfPeer} 条话题的对端是本端自己——结构残缺,rebuild 修不好,需逐条删除:`);
580
+ for (const id of (r.selfPeerIds ?? [])) {
581
+ console.warn(` ec thread delete ${aid}/${id}`);
582
+ }
583
+ }
584
+ if (missing > 0 || stale > 0)
585
+ console.warn(` 建议执行 ec thread rebuild-index 修复`);
564
586
  if (jsonFormat)
565
587
  console.log(JSON.stringify(r, null, 2));
566
588
  }
@@ -572,6 +594,42 @@ export async function runThreadCommand(args) {
572
594
  console.warn(`⚠ ${resp.indexWarning}`);
573
595
  break;
574
596
  }
597
+ case 'reconcile-status': {
598
+ const aid = argValue(args, '--agent') ?? selfAid;
599
+ const apply = hasFlag(args, '--write');
600
+ const resp = await sendOp({ op: 'reconcile-status', selfAid: aid, apply });
601
+ if (!resp.ok) {
602
+ console.error(`✗ ${resp.error}`);
603
+ process.exitCode = 1;
604
+ return;
605
+ }
606
+ const r = resp.result;
607
+ const drift = Array.isArray(r?.drift) ? r.drift : [];
608
+ if (jsonFormat) {
609
+ console.log(JSON.stringify(r, null, 2));
610
+ break;
611
+ }
612
+ if (drift.length === 0) {
613
+ console.log(`✓ 索引与会话文件状态一致,无需对账`);
614
+ break;
615
+ }
616
+ // 逐条列出冲突与判定:只有明确「文件较新」的才可自动修,
617
+ // ambiguous 表示两侧都没有版本号,必须人工确认。
618
+ for (const d of drift) {
619
+ const reason = d.winner === 'file' ? '以会话文件为准'
620
+ : d.winner === 'index' ? '以索引为准' : '无版本依据,需人工确认';
621
+ console.log(`${d.threadId} 索引=${d.indexStatus} 文件=${d.fileStatus} ${reason}`);
622
+ if (d.kind === 'name' || d.kind === 'both')
623
+ console.log(` 名称也有差异,本命令只处理状态`);
624
+ }
625
+ if (apply) {
626
+ console.log(`\n✓ 已按判定写回 ${r.applied ?? 0} 条;其余需人工确认`);
627
+ }
628
+ else {
629
+ console.log(`\n共 ${drift.length} 条可对账;加 --write 按判定写回(仅「文件较新」的条目)`);
630
+ }
631
+ break;
632
+ }
575
633
  case 'check-index': {
576
634
  const aid = argValue(args, '--agent') ?? selfAid;
577
635
  const resp = await sendOp({ op: 'check-index', selfAid: aid });
@@ -583,7 +641,8 @@ export async function runThreadCommand(args) {
583
641
  const r = resp.result;
584
642
  const missing = r.missing ?? 0;
585
643
  const stale = r.stale ?? 0;
586
- if (missing === 0 && stale === 0) {
644
+ const selfPeer = r.selfPeer ?? 0;
645
+ if (missing === 0 && stale === 0 && selfPeer === 0) {
587
646
  console.log(`✓ 索引健康:共 ${r.total} 条话题,session 文件完整`);
588
647
  }
589
648
  else {
@@ -593,7 +652,14 @@ export async function runThreadCommand(args) {
593
652
  if (stale > 0) {
594
653
  console.warn(`⚠ [轻微] ${stale} 条话题属性与 session 文件最后一行不一致(写盘时序),rebuild-index 可修复`);
595
654
  }
596
- console.warn(` 建议执行 ec thread rebuild-index 修复`);
655
+ if (selfPeer > 0) {
656
+ console.warn(`⚠ [严重] ${selfPeer} 条话题的对端是本端自己——结构残缺,rebuild 修不好,需逐条删除:`);
657
+ for (const id of (r.selfPeerIds ?? [])) {
658
+ console.warn(` ec thread delete ${aid}/${id}`);
659
+ }
660
+ }
661
+ if (missing > 0 || stale > 0)
662
+ console.warn(` 建议执行 ec thread rebuild-index 修复`);
597
663
  if (jsonFormat)
598
664
  console.log(JSON.stringify(r, null, 2));
599
665
  }
@@ -14,10 +14,13 @@ export class AccessPolicyError extends Error {
14
14
  * 缺失 `access` 时按"只收内部联系人"执行:同 Owner 名录成员可进,外部与陌生人不进。
15
15
  *
16
16
  * `allowAllContacts` 是压过三档的总开关,默认关。
17
+ *
18
+ * `allowExternalContacts` **不在这里**:它没有 schema 默认值,因为"未配置"要由个人助理
19
+ * 身份判定接管(PA 默认接收外部联系人)。补 `false` 会把"未配置"永久写成"显式关闭",
20
+ * 见 docs/config/11-default-value-levels.md。
17
21
  */
18
22
  export const DEFAULT_ACCESS_POLICY = Object.freeze({
19
23
  allowInternalContacts: true,
20
- allowExternalContacts: false,
21
24
  allowAllContacts: false,
22
25
  allowedAids: Object.freeze([]),
23
26
  deniedAids: Object.freeze([]),
@@ -111,13 +114,23 @@ function assertAccessPolicyWrite(input, agent, policy) {
111
114
  }
112
115
  }
113
116
  function clonePolicy(policy) {
117
+ // requestLimit 的每个子字段单独回落:配置里只写了 maxTimes 时 coolDown 仍是数,
118
+ // 浅展开会留下 undefined,频控窗口算成 NaN。
119
+ const maxTimes = policy.requestLimit?.maxTimes ?? DEFAULT_ACCESS_POLICY.requestLimit.maxTimes;
120
+ const coolDown = policy.requestLimit?.coolDown ?? DEFAULT_ACCESS_POLICY.requestLimit.coolDown;
114
121
  return {
122
+ ...(policy.contactAdmission !== undefined ? { contactAdmission: policy.contactAdmission } : {}),
115
123
  allowInternalContacts: policy.allowInternalContacts ?? true,
116
- allowExternalContacts: policy.allowExternalContacts ?? false,
124
+ // allowExternalContacts 没有 schema 默认值:未配置就保持缺席,由个人助理身份判定接管。
125
+ // 这里不补 false —— 补了就和 `ec config get access` 的读数不一致,
126
+ // 也会让"未配置"这一信息在 view=access 里丢失。
127
+ ...(policy.allowExternalContacts !== undefined
128
+ ? { allowExternalContacts: policy.allowExternalContacts }
129
+ : {}),
117
130
  allowAllContacts: policy.allowAllContacts ?? false,
118
131
  allowedAids: [...(policy.allowedAids ?? [])],
119
132
  deniedAids: [...(policy.deniedAids ?? [])],
120
- requestLimit: { ...policy.requestLimit },
133
+ requestLimit: { maxTimes, coolDown },
121
134
  };
122
135
  }
123
136
  function accessPolicyRevision(policy) {