evolcore 0.0.43-test.6 → 0.0.43-test.7

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 (197) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/bin/ecmsg.js +171 -54
  3. package/dist/agents/baseagent-availability.js +1 -1
  4. package/dist/agents/codex/app-server-client.js +22 -0
  5. package/dist/agents/codex-runner.js +69 -2
  6. package/dist/aun/msg/p2p.js +6 -1
  7. package/dist/channels/aun.js +234 -21
  8. package/dist/cli/agent-create.js +2 -2
  9. package/dist/cli/daemon-commands.js +6 -66
  10. package/dist/cli/daemon-lifecycle-client.js +61 -0
  11. package/dist/cli/ecmsg-gateway.js +35 -2
  12. package/dist/cli/events-command.js +73 -0
  13. package/dist/cli/index.js +31 -14
  14. package/dist/cli/invoke-command.js +182 -0
  15. package/dist/cli/managed-command-guard.js +6 -1
  16. package/dist/cli/restart-monitor.js +45 -47
  17. package/dist/cli/services-command.js +111 -0
  18. package/dist/cli/team-workspace-command.js +134 -0
  19. package/dist/cli/thread-command.js +6 -2
  20. package/dist/cli/watch-msg.js +1 -1
  21. package/dist/config/config-field-policy.js +2 -2
  22. package/dist/config/config-manager.js +0 -7
  23. package/dist/config/invoke-ipc-service.js +118 -0
  24. package/dist/config/schema-migration.js +6 -1
  25. package/dist/config-store.js +2 -1
  26. package/dist/core/agent-reload-coordinator.js +6 -4
  27. package/dist/core/agent-runtime.js +104 -10
  28. package/dist/core/auth/delegation-authorization.js +66 -0
  29. package/dist/core/auth/operation-catalog.js +20 -0
  30. package/dist/core/baseagent-loader.js +60 -130
  31. package/dist/core/channel-loader.js +10 -1
  32. package/dist/core/channel-runtime.js +4 -3
  33. package/dist/core/command/agent-control.js +1 -1
  34. package/dist/core/command/agent-storage-menu.js +1 -1
  35. package/dist/core/command/chatmode-config.js +2 -36
  36. package/dist/core/command/command-handler.js +53 -11
  37. package/dist/core/command/data-root-resolver.js +32 -23
  38. package/dist/core/command/eventcenter-menu.js +338 -0
  39. package/dist/core/command/menu-catalog.js +8 -0
  40. package/dist/core/command/menu-handler.js +198 -84
  41. package/dist/core/command/menu-protocol.js +60 -11
  42. package/dist/core/command/menu-query-batch.js +194 -0
  43. package/dist/core/command/slash-gate.js +1 -1
  44. package/dist/core/command/slash-handler.js +34 -42
  45. package/dist/core/command/team-workspace-bootstrap.js +350 -0
  46. package/dist/core/command/{pa-workspace-calendar.js → team-workspace-calendar.js} +7 -7
  47. package/dist/core/command/team-workspace-initializer.js +2 -0
  48. package/dist/core/command/{pa-workspace-items.js → team-workspace-items.js} +83 -68
  49. package/dist/core/command/team-workspace-job-store.js +88 -0
  50. package/dist/core/command/team-workspace-management-service.js +2 -0
  51. package/dist/core/command/team-workspace-management-store.js +96 -0
  52. package/dist/core/command/team-workspace-management.js +265 -0
  53. package/dist/core/command/team-workspace-members-menu.js +88 -0
  54. package/dist/core/command/team-workspace-store.js +612 -0
  55. package/dist/core/command/team-workspace-team.js +193 -0
  56. package/dist/core/daemon-control.js +8 -5
  57. package/dist/core/daemon-lifecycle.js +132 -73
  58. package/dist/core/handoff/runtime.js +3 -3
  59. package/dist/core/invoke/executors/index.js +13 -0
  60. package/dist/core/invoke/executors/media.js +283 -0
  61. package/dist/core/invoke/executors/text.js +198 -0
  62. package/dist/core/invoke/invoke-service.js +157 -0
  63. package/dist/core/invoke/style-router.js +48 -0
  64. package/dist/core/invoke/types.js +19 -0
  65. package/dist/core/ipc-registration.js +46 -7
  66. package/dist/core/memory/consolidation.js +7 -5
  67. package/dist/core/message/aun-ipc-sender.js +147 -17
  68. package/dist/core/message/im-renderer.js +28 -84
  69. package/dist/core/message/message-bridge.js +4 -0
  70. package/dist/core/message/message-utils.js +10 -2
  71. package/dist/core/message/peer-mode.js +7 -34
  72. package/dist/core/message/response-engine.js +157 -54
  73. package/dist/core/message/send-options.js +7 -4
  74. package/dist/core/message/send-routing.js +43 -5
  75. package/dist/core/ownership/owner-resolver.js +7 -0
  76. package/dist/core/permission/ec-command-parser.js +3 -2
  77. package/dist/core/permission/protected-paths.js +12 -2
  78. package/dist/core/permission/shell-environment.js +9 -0
  79. package/dist/core/session/session-file-health.js +243 -0
  80. package/dist/core/session/session-fs-store.js +2 -3
  81. package/dist/core/task/task-recovery-service.js +13 -2
  82. package/dist/core/thread/command-parser.js +9 -2
  83. package/dist/core/thread/thread-operation.js +21 -2
  84. package/dist/core/thread/thread-route.js +13 -2
  85. package/dist/directory/owner-directory-admission.js +40 -53
  86. package/dist/directory/owner-directory-cache.js +89 -113
  87. package/dist/directory/owner-directory-query-operation.js +8 -10
  88. package/dist/eck/kit-renderer.js +7 -5
  89. package/dist/ecweb/basic-settings-service.js +1 -1
  90. package/dist/ecweb/message-context-service.js +0 -4
  91. package/dist/ecweb/runtime/lifecycle.js +6 -2
  92. package/dist/ecweb/runtime/supervisor.js +19 -4
  93. package/dist/event-center/admission-materializer.js +114 -0
  94. package/dist/event-center/bus-gate.js +136 -0
  95. package/dist/event-center/bus-host.js +290 -0
  96. package/dist/event-center/bus-resolver.js +120 -0
  97. package/dist/event-center/center-config.js +100 -0
  98. package/dist/event-center/client-factory.js +50 -0
  99. package/dist/event-center/daemon.js +45 -0
  100. package/dist/event-center/directory-source.js +53 -0
  101. package/dist/event-center/dispatcher.js +157 -0
  102. package/dist/event-center/event-log.js +110 -0
  103. package/dist/event-center/index-generator.js +63 -0
  104. package/dist/event-center/ipc-operation.js +308 -0
  105. package/dist/event-center/ledger.js +52 -0
  106. package/dist/event-center/pack-loader.js +202 -0
  107. package/dist/event-center/pack-manager.js +85 -0
  108. package/dist/event-center/registry.js +238 -0
  109. package/dist/event-center/runtime.js +641 -0
  110. package/dist/event-center/script-runner.js +356 -0
  111. package/dist/event-center/types.js +35 -0
  112. package/dist/event-center/validation.js +413 -0
  113. package/dist/index.js +285 -99
  114. package/dist/ipc.js +66 -12
  115. package/dist/paths.js +20 -0
  116. package/dist/product.js +14 -0
  117. package/dist/proxy/manager.js +5 -1
  118. package/dist/proxy/service-supervisor.js +13 -4
  119. package/dist/response-system/engines/v1/index.js +0 -1
  120. package/dist/response-system/modes/single-session/index.js +1 -1
  121. package/dist/services/dispatcher.js +100 -0
  122. package/dist/services/idempotency.js +90 -0
  123. package/dist/services/identity.js +52 -0
  124. package/dist/services/index-generator.js +70 -0
  125. package/dist/services/index.js +449 -0
  126. package/dist/services/ipc-operation.js +458 -0
  127. package/dist/services/ledger.js +52 -0
  128. package/dist/services/message-log.js +112 -0
  129. package/dist/services/pack-manager.js +204 -0
  130. package/dist/services/reply.js +55 -0
  131. package/dist/services/router.js +95 -0
  132. package/dist/services/script-runner.js +422 -0
  133. package/dist/services/service-payload.js +70 -0
  134. package/dist/services/types.js +18 -0
  135. package/dist/services/validation.js +297 -0
  136. package/dist/trigger/application-service.js +18 -0
  137. package/dist/trigger/event-source.js +1 -1
  138. package/dist/trigger/ipc-service.js +3 -1
  139. package/dist/trigger/script-sandbox.js +118 -22
  140. package/dist/utils/cross-platform.js +24 -10
  141. package/dist/utils/evolcore-version.js +69 -27
  142. package/dist/utils/instance-registry.js +19 -13
  143. package/dist/utils/process-introspect.js +45 -9
  144. package/dist/utils/startup-trace.js +74 -37
  145. package/dist/utils/windows-shell-trust.js +80 -6
  146. package/kits/docs/INDEX.md +2 -2
  147. package/kits/docs/aun/ABILITY_CALLING.md +7 -14
  148. package/kits/docs/context-assembly.md +1 -1
  149. package/kits/docs/evolcore/INDEX.md +2 -0
  150. package/kits/docs/evolcore/ability.md +4 -0
  151. package/kits/docs/evolcore/aid.md +1 -1
  152. package/kits/docs/evolcore/event-center.md +207 -0
  153. package/kits/docs/evolcore/file-navigation.md +10 -264
  154. package/kits/docs/evolcore/fs.md +3 -2
  155. package/kits/docs/evolcore/group.md +1 -1
  156. package/kits/docs/evolcore/memory-architecture.md +2 -0
  157. package/kits/docs/evolcore/menu-protocol.md +21 -0
  158. package/kits/docs/evolcore/msg.md +15 -3
  159. package/kits/docs/evolcore/provider.md +3 -1
  160. package/kits/docs/evolcore/response.md +5 -5
  161. package/kits/docs/evolcore/services.md +277 -0
  162. package/kits/docs/evolcore/task.md +2 -0
  163. package/kits/docs/evolcore/team-workspace.md +41 -0
  164. package/kits/eck_manifest.json +26 -0
  165. package/kits/rules/02-navigation.md +10 -1
  166. package/kits/schemas/_meta.json +17 -6
  167. package/kits/schemas/agent-config.schema.19.json +5 -7
  168. package/kits/schemas/agent-config.schema.20.json +936 -0
  169. package/kits/schemas/relation-config.schema.12.json +2 -3
  170. package/kits/schemas/role-config.schema.2.json +4 -4
  171. package/kits/skills/.switches.json +1 -5
  172. package/kits/skills/ability/SKILL.md +56 -0
  173. package/kits/skills/ability/references/calling.md +56 -0
  174. package/kits/skills/{ec-ability → ability}/references/contract-checklist.md +1 -1
  175. package/kits/skills/{ec-ability → ability}/references/development.md +9 -33
  176. package/kits/skills/{ec-ability → ability}/references/management.md +2 -2
  177. package/kits/skills/{ec-ability → ability}/references/recovery.md +1 -1
  178. package/kits/skills/{ec-ability → ability}/references/runtime-protocol.md +2 -0
  179. package/kits/skills/ec-agent-create/SKILL.md +0 -1
  180. package/kits/skills/ec-service-proxy/SKILL.md +34 -5
  181. package/kits/skills/personal-assistant/SKILL.md +6 -6
  182. package/kits/skills/personal-assistant/references/02-bootstrap.md +4 -4
  183. package/kits/skills/personal-assistant/scripts/clean.mjs +4 -4
  184. package/kits/skills/personal-assistant/scripts/init.mjs +2 -2
  185. package/kits/skills/personal-assistant/scripts/pa.mjs +4 -4
  186. package/kits/templates/system-fragments/channel.md +3 -3
  187. package/kits/templates/system-fragments/commands.md +5 -3
  188. package/kits/templates/system-fragments/reply.md +0 -5
  189. package/kits/templates/system-fragments/thread.md +10 -8
  190. package/package.json +3 -5
  191. package/dist/cli/pa-workspace-command.js +0 -225
  192. package/dist/core/command/pa-workspace-store.js +0 -468
  193. package/dist/core/relation/pa-team.js +0 -132
  194. package/kits/docs/evolcore/pa-workspace.md +0 -51
  195. package/kits/skills/aid-ability/SKILL.md +0 -244
  196. package/kits/skills/ec-ability/SKILL.md +0 -67
  197. package/kits/skills/ec-ability/references/workflows.md +0 -15
@@ -83,6 +83,11 @@ export function parseGatewayArgs(args) {
83
83
  continue;
84
84
  }
85
85
  if (PASSTHROUGH_VALUE_FLAGS.has(flag)) {
86
+ // `--self` 是 `--from` 的历史别名,已从网关移除:本端只由 `--from` 表达。
87
+ // 显式拒绝而不是透传——透传会被下游当成未知选项,或更糟:被当成正文。
88
+ if (flag === '--self') {
89
+ return { ok: false, error: '--self 已不再支持;本端请用 --from <本端AID>' };
90
+ }
86
91
  const value = args[++index];
87
92
  if (value === undefined)
88
93
  return { ok: false, error: `${token} 需要一个值` };
@@ -133,11 +138,15 @@ function looksLikeAid(value) {
133
138
  }
134
139
  export function buildDownstreamArgv(route, text, passthrough) {
135
140
  const scope = route.peer.peerKind === 'group' ? 'group' : 'msg';
141
+ // 收件人:私聊自发时是本端,否则是话题对端。用 route.peer.id 会把自发消息
142
+ // 实际投给话题对端(下游按位置参数认目标,--thread 只决定落点会话)。
143
+ // 群发送恒以群 AID 为目标,自发不适用于群。
144
+ const targetId = scope === 'group' ? route.peer.id : route.recipientId;
136
145
  // 目标为原生 ID 时必须靠 --thread 推导,写成位置参数会变成正文的一部分。
137
- const targetAsPositional = looksLikeAid(route.peer.id)
146
+ const targetAsPositional = looksLikeAid(targetId)
138
147
  || (route.peer.peerKind === 'group' && !route.crossTopic);
139
148
  const argv = targetAsPositional
140
- ? [scope, 'send', route.self, route.peer.id, ...text, ...passthrough]
149
+ ? [scope, 'send', route.self, targetId, ...text, ...passthrough]
141
150
  : [scope, 'send', route.self, ...text, ...passthrough];
142
151
  // 首次联系:主话题还没被创建,带上 --thread 反而会被下游判成"话题不存在",
143
152
  // 所以按普通私聊发出,会话随这条消息建立,也就不建复查。
@@ -149,6 +158,30 @@ export function buildDownstreamArgv(route, text, passthrough) {
149
158
  argv.push(route.encryptResolved ? '--encrypt' : '--no-encrypt');
150
159
  return argv;
151
160
  }
161
+ /**
162
+ * 群 AID 的 base 简写展开(`g-18127` → `g-18127.agentid.cn`)。
163
+ *
164
+ * 网关必须在构造路由**之前**完成这一步:`--to g-18127` 若不展开,既判不出它是群
165
+ * (类型解析拿不到证据),也拼不出主话题 id,会直接 `TOPIC_REQUIRED`。
166
+ *
167
+ * 只处理裸 base:已含 issuer 的值原样返回,私聊 AID 不受影响。
168
+ * issuer 取本端 AID 的域,与 `ec group send` / 托管 group 操作的调用口径一致。
169
+ * 展开失败(非群 AID 形态)时同样原样返回,交给后续判定按私聊处理。
170
+ */
171
+ export function expandGroupBase(selfAid, value, normalizeGroupAid) {
172
+ const id = String(value ?? '').trim().replace(/^@/, '');
173
+ if (!id || id.includes('.'))
174
+ return id;
175
+ const issuer = String(selfAid ?? '').split('.').slice(1).join('.');
176
+ if (!issuer)
177
+ return id;
178
+ try {
179
+ return normalizeGroupAid?.(id, issuer) ?? id;
180
+ }
181
+ catch {
182
+ return id;
183
+ }
184
+ }
152
185
  /**
153
186
  * 校验 `--thread` 是否需要在本地索引里查表。
154
187
  *
@@ -0,0 +1,73 @@
1
+ /**
2
+ * `ec events` CLI:事件中心运维(status / ledger / tail / doctor / reload / allowlist / publish)。
3
+ * daemon-control 风格:读本地 control token,经 events.op 转发,daemon 解析执行。
4
+ */
5
+ import fs from 'node:fs';
6
+ import { ipcQuery } from '../ipc.js';
7
+ import { resolvePaths } from '../paths.js';
8
+ const HELP = `ec events — 事件中心运维
9
+
10
+ 用法:
11
+ ec events status [<包名>] [--aid <aid>] 每包状态
12
+ ec events ledger <包名> [--tail N] 台账
13
+ ec events tail <包名> [--tail N] 事件日志
14
+ ec events doctor <包名> 诊断
15
+ ec events reload [<包名>] 重载(重新扫描目录并重建订阅)
16
+ ec events allowlist add <事件> --publish <aid> [--subscribe <aid>]
17
+ ec events allowlist remove <事件> --publish <aid> [--subscribe <aid>]
18
+ ec events allowlist show [--event <事件>]
19
+ ec events publish <包名> <事件> --data '<json>' [--ttl <秒>]
20
+
21
+ 事件是 TTL 内的在线通知:不落库、不重放。详见 $KITS_DOCS/evolcore/event-center.md`;
22
+ function readControlToken() {
23
+ try {
24
+ return fs.readFileSync(resolvePaths().controlToken, 'utf8').trim() || undefined;
25
+ }
26
+ catch {
27
+ return undefined;
28
+ }
29
+ }
30
+ async function queryEvents(argv) {
31
+ const controlToken = readControlToken();
32
+ try {
33
+ const response = await ipcQuery(resolvePaths().socket, { type: 'events.op', argv, controlToken }, 20_000, { throwOnError: false });
34
+ if (!response || typeof response !== 'object')
35
+ return { transportError: 'invalid daemon response' };
36
+ return { response };
37
+ }
38
+ catch (error) {
39
+ return { transportError: error instanceof Error ? error.message : String(error) };
40
+ }
41
+ }
42
+ function printResult(result, json) {
43
+ if (json) {
44
+ console.log(JSON.stringify(result, null, 2));
45
+ return;
46
+ }
47
+ if (result && typeof result === 'object') {
48
+ console.log(JSON.stringify(result, null, 2));
49
+ return;
50
+ }
51
+ console.log(String(result));
52
+ }
53
+ export async function runEventsCommand(argv) {
54
+ const args = [...argv];
55
+ const json = args.includes('--json');
56
+ if (args.length === 0 || args[0] === 'help' || args[0] === '--help') {
57
+ console.log(HELP);
58
+ return;
59
+ }
60
+ const query = await queryEvents(args);
61
+ if ('transportError' in query) {
62
+ console.error(`daemon 不可达:${query.transportError}`);
63
+ process.exitCode = 1;
64
+ return;
65
+ }
66
+ const { response } = query;
67
+ if (!response.ok) {
68
+ console.error(`${response.code ?? 'ERROR'}: ${response.error ?? 'unknown error'}`);
69
+ process.exitCode = 1;
70
+ return;
71
+ }
72
+ printResult(response.result, json);
73
+ }
package/dist/cli/index.js CHANGED
@@ -12,7 +12,6 @@ import * as platform from '../utils/cross-platform.js';
12
12
  // 实测这些模块各自 350-590ms(aun-commands/agent-command/init 最重),
13
13
  // 静态导入会让 `ec start` 的 CLI bootstrap 多花约 300ms 而毫无收益。
14
14
  // 本文件其余分支(task/trigger/proxy/thread/...)本来就是这个写法。
15
- import { cmdStart, cmdStop, cmdRestart, cmdStatus, cmdLogs, cmdWatchCommand, cmdMv, cmdDiagnose } from './daemon-commands.js';
16
15
  import { logCliCommand } from './command-log.js';
17
16
  import { isInitCancelledError, printInitCancelHint } from './init-cancel.js';
18
17
  import { assertManagedTopLevelCommandAllowed, ManagedCommandNotAllowedError } from './managed-command-guard.js';
@@ -38,11 +37,13 @@ Agent 与会话:
38
37
  session 按 ec 会话 id 查询本地 session 存档(含 agentSessionId)
39
38
  getmeta 按会话 id / threadId / agentSessionId 查询会话元数据
40
39
  thread 话题链:对端话题的列表、历史、摘要与索引维护
40
+ events 事件中心:事件包状态、台账、白名单与发布
41
+ services 服务路由:服务包状态、台账、诊断与对端调用
41
42
  memory 记忆:写 note、整理正式记忆、触发整理会话
42
43
  task 恢复暂停或异常中断的会话任务
43
44
  trigger 管理定时与事件触发器
44
45
  proxy 查询和管理 daemon 服务代理
45
- pa-workspace 绑定 PA 工作区并维护入口导航
46
+ team 管理 Team Workspace、导航和成员
46
47
  model 查看或设置模型与推理强度
47
48
  response 查看或设置响应模式
48
49
 
@@ -69,6 +70,7 @@ AUN:
69
70
  配置与诊断:
70
71
  config 读取、修改和检查分层配置
71
72
  provider 管理 daemon 级 Provider 注册表与 JSON 导入
73
+ invoke 统一模型调用:按 provider 的 style 路由到内置执行器
72
74
  ability 按 AID 管理能力插件、运行、发布和作业
73
75
  stats Token 用量与费用统计
74
76
  skill EC 技能管理:加载、安装、启停与索引刷新
@@ -321,7 +323,7 @@ export async function main(args) {
321
323
  process.exitCode = 1;
322
324
  break;
323
325
  }
324
- await cmdStart({
326
+ await (await import('./daemon-commands.js')).cmdStart({
325
327
  diagnose: strippedArgs.includes('--diagnose') || strippedArgs.includes('-d'),
326
328
  foreground: strippedArgs.includes('--foreground'),
327
329
  debug: strippedArgs.includes('--debug'),
@@ -338,7 +340,7 @@ export async function main(args) {
338
340
  process.exitCode = 1;
339
341
  break;
340
342
  }
341
- await cmdStop();
343
+ await (await import('./daemon-commands.js')).cmdStop();
342
344
  break;
343
345
  case 'restart':
344
346
  if (wantsHelp(strippedArgs.slice(1))) {
@@ -349,7 +351,7 @@ export async function main(args) {
349
351
  process.exitCode = 1;
350
352
  break;
351
353
  }
352
- await cmdRestart({ clear: strippedArgs.includes('--clear'), diagnose: strippedArgs.includes('--diagnose') || strippedArgs.includes('-d') });
354
+ await (await import('./daemon-commands.js')).cmdRestart({ clear: strippedArgs.includes('--clear'), diagnose: strippedArgs.includes('--diagnose') || strippedArgs.includes('-d') });
353
355
  break;
354
356
  case 'upgrade':
355
357
  case 'update': {
@@ -400,10 +402,10 @@ export async function main(args) {
400
402
  process.exitCode = 1;
401
403
  break;
402
404
  }
403
- await cmdStatus({ format });
405
+ await (await import('./daemon-commands.js')).cmdStatus({ format });
404
406
  }
405
407
  else {
406
- await cmdStatus({ format });
408
+ await (await import('./daemon-commands.js')).cmdStatus({ format });
407
409
  }
408
410
  }
409
411
  break;
@@ -412,14 +414,14 @@ export async function main(args) {
412
414
  printLifecycleHelp('logs');
413
415
  break;
414
416
  }
415
- await cmdLogs(strippedArgs.slice(1));
417
+ await (await import('./daemon-commands.js')).cmdLogs(strippedArgs.slice(1));
416
418
  break;
417
419
  case 'watch':
418
420
  if (wantsHelp(strippedArgs.slice(1))) {
419
421
  printLifecycleHelp('watch');
420
422
  break;
421
423
  }
422
- await cmdWatchCommand(strippedArgs.slice(1));
424
+ await (await import('./daemon-commands.js')).cmdWatchCommand(strippedArgs.slice(1));
423
425
  break;
424
426
  case 'restart-monitor':
425
427
  if (wantsHelp(strippedArgs.slice(1))) {
@@ -448,14 +450,14 @@ export async function main(args) {
448
450
  printLifecycleHelp('mv');
449
451
  break;
450
452
  }
451
- await cmdMv(strippedArgs[1], strippedArgs[2]);
453
+ await (await import('./daemon-commands.js')).cmdMv(strippedArgs[1], strippedArgs[2]);
452
454
  break;
453
455
  case 'diagnose':
454
456
  if (wantsHelp(strippedArgs.slice(1))) {
455
457
  printLifecycleHelp('diagnose');
456
458
  break;
457
459
  }
458
- await cmdDiagnose(strippedArgs.slice(1));
460
+ await (await import('./daemon-commands.js')).cmdDiagnose(strippedArgs.slice(1));
459
461
  break;
460
462
  case 'data': {
461
463
  const { cmdData } = await import('./data-command.js');
@@ -580,6 +582,16 @@ export async function main(args) {
580
582
  await runThreadCommand(strippedArgs.slice(1));
581
583
  break;
582
584
  }
585
+ case 'events': {
586
+ const { runEventsCommand } = await import('./events-command.js');
587
+ await runEventsCommand(strippedArgs.slice(1));
588
+ break;
589
+ }
590
+ case 'services': {
591
+ const { runServicesCommand } = await import('./services-command.js');
592
+ await runServicesCommand(strippedArgs.slice(1));
593
+ break;
594
+ }
583
595
  case 'session': {
584
596
  const { runSessionCommand } = await import('./session-command.js');
585
597
  await runSessionCommand(strippedArgs.slice(1));
@@ -606,9 +618,9 @@ export async function main(args) {
606
618
  await cmdSkill(strippedArgs.slice(1));
607
619
  break;
608
620
  }
609
- case 'pa-workspace': {
610
- const { cmdPaWorkspace } = await import('./pa-workspace-command.js');
611
- await cmdPaWorkspace(strippedArgs.slice(1));
621
+ case 'team': {
622
+ const { cmdTeamWorkspace } = await import('./team-workspace-command.js');
623
+ await cmdTeamWorkspace(strippedArgs.slice(1));
612
624
  break;
613
625
  }
614
626
  case 'response': {
@@ -621,6 +633,11 @@ export async function main(args) {
621
633
  await cmdProvider(strippedArgs.slice(1));
622
634
  break;
623
635
  }
636
+ case 'invoke': {
637
+ const { cmdInvoke } = await import('./invoke-command.js');
638
+ await cmdInvoke(strippedArgs.slice(1));
639
+ break;
640
+ }
624
641
  case 'ability': {
625
642
  const { cmdAbility } = await import('./ability-command.js');
626
643
  await cmdAbility(strippedArgs.slice(1));
@@ -0,0 +1,182 @@
1
+ /**
2
+ * `ec invoke` —— 统一模型调用入口。
3
+ *
4
+ * 设计见 `docs/model-intent/invoke-design.md`。
5
+ *
6
+ * 它不经过任何 baseagent:直接读 `providers.json` 的端点打过去。
7
+ * 所以在 Claude Code 会话里可以调 Codex 端点,也可以调生图/生视频端点——
8
+ * 只要端点在 providers.json 里登记过。
9
+ */
10
+ import fs from 'node:fs';
11
+ import path from 'node:path';
12
+ import { resolvePaths } from '../paths.js';
13
+ import { readDelegationCredential, hashCurrentDelegatedCommand } from '../core/auth/agent-delegation.js';
14
+ import { daemonUnavailableMessage, queryDaemon, wantsHelp } from './help.js';
15
+ import { parseInvokeArgv } from '../config/invoke-ipc-service.js';
16
+ const HELP = `用法: ec invoke --provider <id> --service <type> (--input <json>|--input-file <path>) [选项]
17
+
18
+ 统一模型调用入口:按 providers.json 的 style 路由到内置执行器。
19
+
20
+ 必填:
21
+ --provider <id> Provider ID(支持别名)
22
+ --service <type> providers.json 的 service 类型,如 text / image / decision
23
+ --input <json> | --input-file <path> 端点特定入参(JSON)
24
+
25
+ 可选:
26
+ --model <id> 缺省取该 service 下第一个已启用模型
27
+ --out <path> 产物落盘路径(图片/音频/视频)
28
+ --timeout <duration> 单次尝试超时,缺省 60s;支持 30s / 2m / 60000
29
+ --retries <n> 传输层重试次数,缺省 3,上限 10;0 = 只打一次
30
+ 仅 5xx/超时/连接失败重试,4xx 不重试
31
+ --dry-run 只解析与路由,不触网
32
+ --format json|text 缺省 json
33
+
34
+ 示例:
35
+ ec invoke --provider provider-1 --service text --model sonnet \\
36
+ --input '{"input":"你好"}'
37
+ ec invoke --provider provider-2 --service image --model dall-e-3 \\
38
+ --input '{"prompt":"一只猫"}' --out ./cat.png
39
+
40
+ 路由表(内置):
41
+ claude / anthropic → /v1/messages
42
+ codex / openai-responses→ /v1/responses
43
+ openai-compatible → /v1/chat/completions
44
+ gemini → /v1beta/models/{model}:generateContent
45
+ systemone → POST {baseUrl}
46
+ openai-images → /v1/images/generations (service: image)
47
+ openai-audio → /v1/audio/speech (service: speech)
48
+ openai-audio → /v1/audio/transcriptions (service: transcribe)
49
+ openai-embeddings → /v1/embeddings (service: embedding)
50
+
51
+ 本命令不修改 providers.json;产物路径由调用方指定。`;
52
+ function parseDuration(raw) {
53
+ const match = /^(\d+)\s*(ms|s|m|h)?$/u.exec(raw.trim());
54
+ if (!match)
55
+ throw Object.assign(new Error(`--timeout 格式无效: ${raw}`), { code: 'INVALID_ARGUMENT' });
56
+ const value = Number(match[1]);
57
+ const unit = match[2] ?? 'ms';
58
+ const factor = unit === 'h' ? 3_600_000 : unit === 'm' ? 60_000 : unit === 's' ? 1_000 : 1;
59
+ return value * factor;
60
+ }
61
+ /** 把 `--timeout <duration>` 统一改写为 `--timeout-ms <n>`。 */
62
+ function normalizeTimeoutArgs(args) {
63
+ const out = [];
64
+ for (let index = 0; index < args.length; index++) {
65
+ const token = args[index];
66
+ if (token === '--timeout') {
67
+ const value = args[index + 1];
68
+ if (value === undefined)
69
+ throw Object.assign(new Error('--timeout requires a value'), { code: 'INVALID_ARGUMENT' });
70
+ out.push('--timeout-ms', String(parseDuration(value)));
71
+ index++;
72
+ continue;
73
+ }
74
+ if (token.startsWith('--timeout=')) {
75
+ out.push('--timeout-ms', String(parseDuration(token.slice('--timeout='.length))));
76
+ continue;
77
+ }
78
+ out.push(token);
79
+ }
80
+ return out;
81
+ }
82
+ function isSuccess(response) {
83
+ // 只有明确的 ok:true 才算成功;daemon 旧版本或异常响应只带 error 时按失败处理。
84
+ return response.ok === true;
85
+ }
86
+ function renderText(response) {
87
+ if (!isSuccess(response)) {
88
+ const code = response.code ?? 'INVOKE_FAILED';
89
+ const message = response.error ?? 'invoke failed';
90
+ return `❌ ${message} (${code})` + (response.data?.hint ? `\n 提示: ${response.data.hint}` : '');
91
+ }
92
+ const lines = [
93
+ `✓ 调用成功`,
94
+ ` provider: ${response.provider}`,
95
+ ` service : ${response.service}`,
96
+ ` model : ${response.model}`,
97
+ ` style : ${response.style}`,
98
+ ` executor: ${response.executor}`,
99
+ ` latency : ${response.result?.latencyMs ?? 0}ms`,
100
+ ];
101
+ if (response.result?.artifacts?.length) {
102
+ lines.push(' 产物:');
103
+ for (const artifact of response.result.artifacts) {
104
+ lines.push(` ${artifact.kind}${artifact.path ? ` ${artifact.path}` : ''}${artifact.url ? ` ${artifact.url}` : ''}`);
105
+ }
106
+ }
107
+ return lines.join('\n');
108
+ }
109
+ export async function cmdInvoke(args) {
110
+ if (!args.length || wantsHelp(args)) {
111
+ console.log(HELP);
112
+ return;
113
+ }
114
+ const json = args.some((value, index) => value === '--format=json' || (value === '--format' && args[index + 1] === 'json'));
115
+ const emit = (payload) => {
116
+ if (json)
117
+ console.log(JSON.stringify(payload, null, 2));
118
+ else if (!isSuccess(payload))
119
+ console.error(renderText(payload));
120
+ else
121
+ console.log(renderText(payload));
122
+ };
123
+ let parsed;
124
+ try {
125
+ // 本地把 `--timeout <duration>` 换算成毫秒,再交给统一的 argv 解析。
126
+ const normalized = normalizeTimeoutArgs(args);
127
+ parsed = parseInvokeArgv(['invoke', ...normalized]);
128
+ }
129
+ catch (error) {
130
+ emit({ ok: false, code: error.code ?? 'INVALID_ARGUMENT', error: error.message });
131
+ process.exitCode = 1;
132
+ return;
133
+ }
134
+ // 本地解析出的 input:路径相对 cwd 解析(daemon 无法知道调用方 cwd)。
135
+ const inputText = parsed.inputFile
136
+ ? fs.readFileSync(path.resolve(parsed.inputFile), 'utf8')
137
+ : parsed.input;
138
+ if (Buffer.byteLength(inputText, 'utf8') > 1024 * 1024) {
139
+ emit({ ok: false, code: 'INVALID_ARGUMENT', error: 'invoke input must be under 1 MiB' });
140
+ process.exitCode = 1;
141
+ return;
142
+ }
143
+ const timeoutMs = parsed.timeoutMs;
144
+ const retries = parsed.retries === undefined ? undefined : Number(parsed.retries);
145
+ const sessionId = process.env.EVOLCORE_SESSION_ID;
146
+ const delegationToken = readDelegationCredential();
147
+ // 托管与非托管都走 daemon:密钥解析($VAR)与 providers.json 的合理归属都在 daemon。
148
+ const argv = [
149
+ 'invoke',
150
+ '--provider', parsed.providerId,
151
+ '--service', parsed.serviceType,
152
+ ...(parsed.model ? ['--model', parsed.model] : []),
153
+ ...(parsed.out ? ['--out', path.resolve(parsed.out)] : []),
154
+ ...(timeoutMs !== undefined ? ['--timeout-ms', String(timeoutMs)] : []),
155
+ ...(retries !== undefined ? ['--retries', String(retries)] : []),
156
+ ...(parsed.dryRun ? ['--dry-run'] : []),
157
+ ];
158
+ try {
159
+ let controlToken;
160
+ if (!sessionId && !delegationToken) {
161
+ try {
162
+ controlToken = fs.readFileSync(resolvePaths().controlToken, 'utf8').trim();
163
+ }
164
+ catch { }
165
+ }
166
+ const { response, transportError } = await queryDaemon(resolvePaths().socket, {
167
+ type: 'invoke.op', argv, input: inputText,
168
+ ...(sessionId || delegationToken
169
+ ? { sessionId, delegationToken, delegationCommandHash: hashCurrentDelegatedCommand() }
170
+ : { controlToken }),
171
+ }, (timeoutMs ?? 60_000) + 30_000);
172
+ if (!response)
173
+ throw Object.assign(new Error(daemonUnavailableMessage(transportError, '无法连接 EvolCore daemon')), { code: 'DAEMON_UNAVAILABLE' });
174
+ emit(response);
175
+ if (!isSuccess(response))
176
+ process.exitCode = 1;
177
+ }
178
+ catch (error) {
179
+ emit({ ok: false, code: error.code ?? 'INVOKE_FAILED', error: error.message });
180
+ process.exitCode = 1;
181
+ }
182
+ }
@@ -20,9 +20,11 @@ const MANAGED_TASK_COMMANDS = new Set([
20
20
  'memory',
21
21
  'model',
22
22
  'msg',
23
- 'pa-workspace',
23
+ 'team',
24
24
  'proxy',
25
25
  'provider',
26
+ // `invoke` 调用已登记的端点,不改配置;具体授权由 invoke.op 的委托校验完成。
27
+ 'invoke',
26
28
  'ability',
27
29
  'queue',
28
30
  'response',
@@ -39,6 +41,9 @@ const MANAGED_TASK_COMMANDS = new Set([
39
41
  // ec-skill 技能的 SKILL.md 明确指导 agent 调用它。脚本只读写
40
42
  // `thread` 提供话题链操作,通过 thread.op IPC 鉴权
41
43
  'thread',
44
+ // `events` 事件中心运维(白名单自动维护脚本用它加白名单),通过 events.op IPC
45
+ // 且要求本地 control token,daemon 侧鉴权。
46
+ 'events',
42
47
  // $EVOLCORE_HOME/skills/ 与 kits/skills/ 下的技能文件,不触碰进程生命周期。
43
48
  // 本白名单只负责让它进到脚本;具体某一级的读写权限由 skill.mjs 的
44
49
  // assertPermission() 按会话上下文判定(群聊一律拒,Agent 级要 owner,