evolcore 0.0.40 → 0.0.41-test.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) hide show
  1. package/CHANGELOG.md +94 -1
  2. package/bin/codex-managed-hook.mjs +11 -0
  3. package/bin/ec-safe-output.js +11 -1
  4. package/dist/agents/baseagent-availability.js +1 -1
  5. package/dist/agents/baseagent.js +20 -43
  6. package/dist/agents/claude-runner.js +197 -197
  7. package/dist/agents/codex-runner.js +535 -259
  8. package/dist/agents/ecagent-runner.js +31 -12
  9. package/dist/agents/gemini-runner.js +27 -7
  10. package/dist/agents/runner-types.js +11 -3
  11. package/dist/aun/ability-device-routing.js +26 -0
  12. package/dist/aun/aid/client.js +1 -1
  13. package/dist/aun/group/fs-download.js +39 -0
  14. package/dist/aun/group/identity.js +36 -13
  15. package/dist/aun/group/operations.js +5 -0
  16. package/dist/aun/msg/managed-operation.js +72 -11
  17. package/dist/aun/msg/p2p.js +32 -7
  18. package/dist/aun/service-proxy.js +36 -12
  19. package/dist/aun/storage/download.js +30 -0
  20. package/dist/aun/storage/index.js +14 -6
  21. package/dist/channels/aun.js +367 -24
  22. package/dist/channels/daemon.js +39 -5
  23. package/dist/cli/agent-command.js +2 -0
  24. package/dist/cli/agent-create.js +98 -19
  25. package/dist/cli/agent.js +10 -3
  26. package/dist/cli/aun-commands.js +85 -41
  27. package/dist/cli/daemon-commands.js +678 -688
  28. package/dist/cli/fs-command.js +64 -2
  29. package/dist/cli/index.js +48 -4
  30. package/dist/cli/managed-command-guard.js +4 -0
  31. package/dist/cli/model.js +40 -40
  32. package/dist/cli/proxy-command.js +92 -0
  33. package/dist/cli/restart-monitor.js +17 -0
  34. package/dist/cli/role.js +85 -0
  35. package/dist/cli/session-command.js +128 -13
  36. package/dist/cli/stats.js +60 -4
  37. package/dist/cli/trigger-command.js +2 -2
  38. package/dist/config/access-policy.js +8 -1
  39. package/dist/config/boot-log.js +38 -1
  40. package/dist/config/config-field-policy.js +5 -32
  41. package/dist/config/config-manager.js +46 -39
  42. package/dist/config/config-operation-service.js +8 -11
  43. package/dist/config/contact-book-store.js +47 -21
  44. package/dist/config/contact-book.js +18 -12
  45. package/dist/config/contact-operation-service.js +3 -4
  46. package/dist/config/contact-request-service.js +11 -0
  47. package/dist/config/daemon-services.js +11 -0
  48. package/dist/config/gateway-config.js +89 -595
  49. package/dist/config/peer-role-resolver.js +15 -11
  50. package/dist/config/providers-config.js +12 -7
  51. package/dist/config/providers-import.js +3 -21
  52. package/dist/config/resolved-config-op.js +3 -0
  53. package/dist/config/role-command-service.js +166 -0
  54. package/dist/config/role-request-service.js +193 -0
  55. package/dist/config/schema-migration.js +686 -25
  56. package/dist/config-store.js +79 -3
  57. package/dist/contracts/ecweb-instance.js +41 -0
  58. package/dist/contracts/ecweb-service-protocol.js +3 -1
  59. package/dist/core/agent-application-service.js +11 -1
  60. package/dist/core/agent-ipc-registration.js +4 -0
  61. package/dist/core/agent-runtime.js +1 -1
  62. package/dist/core/auth/agent-delegation.js +82 -6
  63. package/dist/core/auth/auth-gateway.js +1 -1
  64. package/dist/core/auth/authorization-audit.js +37 -9
  65. package/dist/core/auth/delegation-authorization.js +3 -1
  66. package/dist/core/auth/operation-authorizer.js +15 -0
  67. package/dist/core/auth/operation-catalog.js +39 -6
  68. package/dist/core/command/agent-control.js +94 -19
  69. package/dist/core/command/agent-storage-menu.js +5 -3
  70. package/dist/core/command/cli-intent-parser.js +2 -1
  71. package/dist/core/command/command-handler.js +105 -145
  72. package/dist/core/command/connect-menu.js +31 -2
  73. package/dist/core/command/data-root-resolver.js +5 -4
  74. package/dist/core/command/memory-slash.js +16 -8
  75. package/dist/core/command/menu-catalog.js +6 -6
  76. package/dist/core/command/menu-handler.js +87 -163
  77. package/dist/core/command/menu-protocol.js +9 -2
  78. package/dist/core/command/role-menu.js +148 -30
  79. package/dist/core/command/slash-gate.js +13 -10
  80. package/dist/core/command/slash-handler.js +157 -352
  81. package/dist/core/daemon-control.js +8 -14
  82. package/dist/core/event-catalog.js +15 -0
  83. package/dist/core/evolagent-registry.js +4 -4
  84. package/dist/core/evolagent.js +2 -2
  85. package/dist/core/inference/text-inference.js +31 -40
  86. package/dist/core/ipc-registration.js +24 -3
  87. package/dist/core/memory/consolidation-context.js +51 -5
  88. package/dist/core/memory/consolidation-ops-records.js +1 -1
  89. package/dist/core/memory/consolidation-trigger.js +190 -190
  90. package/dist/core/memory/consolidation.js +316 -29
  91. package/dist/core/memory/forget-log.js +96 -0
  92. package/dist/core/memory/index-manager.js +27 -5
  93. package/dist/core/memory/memory-admin.js +45 -5
  94. package/dist/core/memory/memory-writer.js +163 -18
  95. package/dist/core/memory/relation-idle-monitor.js +119 -58
  96. package/dist/core/memory/relation-sweep.js +44 -39
  97. package/dist/core/message/aun-ipc-sender.js +34 -7
  98. package/dist/core/message/aun-request-registry.js +97 -3
  99. package/dist/core/message/im-renderer.js +11 -4
  100. package/dist/core/message/message-admission.js +97 -8
  101. package/dist/core/message/message-bridge.js +71 -24
  102. package/dist/core/message/message-log.js +55 -0
  103. package/dist/core/message/message-queue.js +5 -5
  104. package/dist/core/message/response-engine.js +387 -144
  105. package/dist/core/model/catalog-service.js +4 -2
  106. package/dist/core/model/config-scope.js +24 -64
  107. package/dist/core/model/field-scope.js +1 -1
  108. package/dist/core/model/model-catalog.js +37 -47
  109. package/dist/core/model/model-diagnostics.js +4 -3
  110. package/dist/core/model/model-fallback.js +10 -7
  111. package/dist/core/model/model-permission.js +3 -2
  112. package/dist/core/ownership/owner-resolver.js +25 -23
  113. package/dist/core/permission/ec-command-parser.js +138 -5
  114. package/dist/core/permission/sandbox-runtime.js +18 -1
  115. package/dist/core/permission/tool-policy.js +42 -10
  116. package/dist/core/relation/peer-identity.js +64 -1
  117. package/dist/core/role/runtime-policy.js +72 -13
  118. package/dist/core/session/session-capsule.js +197 -0
  119. package/dist/core/session/session-idle-monitor.js +1 -1
  120. package/dist/core/session/session-manager.js +168 -14
  121. package/dist/core/session/session-mapper.js +2 -0
  122. package/dist/core/session/session-renew.js +3 -3
  123. package/dist/core/skill/index-generator.js +15 -5
  124. package/dist/core/system-session/memory.js +6 -1
  125. package/dist/core/thread/thread-service.js +19 -6
  126. package/dist/directory/owner-directory-admission.js +95 -0
  127. package/dist/directory/owner-directory-authorization.js +309 -0
  128. package/dist/directory/owner-directory-cache.js +635 -0
  129. package/dist/eck/kit-renderer.js +2 -2
  130. package/dist/ecweb/basic-settings-service.js +33 -40
  131. package/dist/ecweb/message-context-service.js +110 -0
  132. package/dist/index.js +79 -17
  133. package/dist/ipc.js +189 -17
  134. package/dist/paths.js +4 -0
  135. package/dist/proxy/command.js +122 -0
  136. package/dist/proxy/ipc-service.js +68 -0
  137. package/dist/proxy/manager.js +485 -0
  138. package/dist/proxy/service-supervisor.js +603 -0
  139. package/dist/response-system/engines/v1/proactive-flow.js +16 -6
  140. package/dist/stats/budget.js +1 -1
  141. package/dist/stats/db.js +15 -0
  142. package/dist/stats/index.js +2 -2
  143. package/dist/stats/price-resolver.js +304 -5
  144. package/dist/stats/query.js +82 -3
  145. package/dist/stats/writer.js +38 -5
  146. package/dist/trigger/feedback.js +18 -7
  147. package/dist/trigger/manager.js +20 -3
  148. package/dist/trigger/parser.js +6 -3
  149. package/dist/trigger/patch.js +1 -1
  150. package/dist/trigger/system-definitions.js +43 -7
  151. package/dist/trigger/validation.js +13 -5
  152. package/dist/utils/cross-platform.js +14 -0
  153. package/dist/utils/ecweb-supervisor.js +258 -83
  154. package/dist/utils/error-utils.js +16 -2
  155. package/dist/utils/logger.js +24 -5
  156. package/dist/utils/npm-ops.js +2 -1
  157. package/dist/utils/package-version-info.js +5 -3
  158. package/dist/utils/upgrade-jobs.js +45 -5
  159. package/kits/docs/INDEX.md +1 -1
  160. package/kits/docs/aun/ABILITY_CALLING.md +20 -2
  161. package/kits/docs/channels/aun.md +9 -0
  162. package/kits/docs/evolcore/INDEX.md +2 -1
  163. package/kits/docs/evolcore/agent-create.md +3 -2
  164. package/kits/docs/evolcore/agent.md +1 -1
  165. package/kits/docs/evolcore/config.md +18 -7
  166. package/kits/docs/evolcore/contact.md +3 -0
  167. package/kits/docs/evolcore/event.md +1 -0
  168. package/kits/docs/evolcore/fs.md +16 -0
  169. package/kits/docs/evolcore/memory-architecture.md +2 -2
  170. package/kits/docs/evolcore/memory-consolidation.md +32 -8
  171. package/kits/docs/evolcore/memory.md +1 -1
  172. package/kits/docs/evolcore/menu-protocol.md +36 -0
  173. package/kits/docs/evolcore/model.md +23 -20
  174. package/kits/docs/evolcore/msg.md +21 -8
  175. package/kits/docs/evolcore/session.md +14 -0
  176. package/kits/migrations/migrate-contact-book-v2.mjs +30 -11
  177. package/kits/schemas/_meta.json +37 -4
  178. package/kits/schemas/agent-config.schema.13.json +23 -3
  179. package/kits/schemas/agent-config.schema.16.json +891 -0
  180. package/kits/schemas/daemon.schema.9.json +366 -0
  181. package/kits/schemas/defaults.schema.5.json +406 -127
  182. package/kits/schemas/relation-config.schema.11.json +260 -0
  183. package/kits/schemas/role-config.schema.1.json +7 -7
  184. package/kits/skills/.switches.json +3 -7
  185. package/kits/skills/aid-ability/SKILL.md +35 -6
  186. package/kits/skills/ec-service-proxy/SKILL.md +118 -0
  187. package/kits/skills/ec-trigger/SKILL.md +13 -5
  188. package/kits/skills/personal-assistant/SKILL.md +176 -0
  189. package/kits/skills/personal-assistant/references/01-workspace-spec.md +333 -0
  190. package/kits/skills/personal-assistant/references/02-bootstrap.md +205 -0
  191. package/kits/skills/personal-assistant/references/03-data-flow-and-gaps.md +177 -0
  192. package/kits/skills/personal-assistant/references/04-frontend-contract.md +439 -0
  193. package/kits/skills/personal-assistant/references/05-directory-reference.md +292 -0
  194. package/kits/skills/personal-assistant/references/06-render-config.md +350 -0
  195. package/kits/skills/personal-assistant/schema/workspace.schema.json +85 -0
  196. package/kits/skills/personal-assistant/schema/workspace.v1.json +66 -0
  197. package/kits/skills/personal-assistant/scripts/archive.mjs +154 -0
  198. package/kits/skills/personal-assistant/scripts/check.mjs +114 -0
  199. package/kits/skills/personal-assistant/scripts/index-rebuild.mjs +252 -0
  200. package/kits/skills/personal-assistant/scripts/ingest.mjs +344 -0
  201. package/kits/skills/personal-assistant/scripts/init.mjs +270 -0
  202. package/kits/skills/personal-assistant/scripts/lib/apply.mjs +92 -0
  203. package/kits/skills/personal-assistant/scripts/lib/schema.mjs +96 -0
  204. package/kits/skills/personal-assistant/scripts/lib/time.mjs +28 -0
  205. package/kits/skills/personal-assistant/scripts/migrate.mjs +172 -0
  206. package/kits/skills/personal-assistant/scripts/search.mjs +172 -0
  207. package/kits/skills/personal-assistant/scripts/verify.mjs +196 -0
  208. package/kits/skills/personal-assistant/templates/INDEX.md.tpl +24 -0
  209. package/kits/skills/personal-assistant/templates/README.md.tpl +108 -0
  210. package/kits/skills/personal-assistant/triggers/ingest-daily.json +23 -0
  211. package/kits/skills/personal-assistant/triggers/memory-consolidate.json +23 -0
  212. package/kits/skills/personal-assistant/triggers/report-daily.json +23 -0
  213. package/kits/skills/personal-assistant/triggers/report-weekly.json +23 -0
  214. package/kits/templates/memory-consolidation/forget.md +19 -6
  215. package/kits/templates/memory-consolidation/notes.md +1 -1
  216. package/kits/templates/memory-consolidation/profile.md +2 -2
  217. package/kits/templates/memory-consolidation/promote.md +20 -3
  218. package/kits/templates/roles/member.json +8 -1
  219. package/kits/templates/session-capsule/recovery.md +5 -0
  220. package/kits/templates/session-capsule/renew.md +5 -0
  221. package/kits/templates/system-fragments/baseagent.md +2 -2
  222. package/kits/templates/system-fragments/bootstrap.md +6 -6
  223. package/kits/templates/system-fragments/channel.md +1 -1
  224. package/kits/templates/system-fragments/memory.md +4 -4
  225. package/package.json +7 -3
  226. package/dist/stats/billing.js +0 -215
@@ -6,7 +6,7 @@ import { agentmdGet, getAidStore, isValidAid, loadClient, SLOT } from '../aun/ai
6
6
  import { daemonUnavailableMessage, queryDaemon } from './help.js';
7
7
  import { resolvePaths } from '../paths.js';
8
8
  import { AGENT_DELEGATION_TOKEN_ENV, readDelegationCredential } from '../core/auth/agent-delegation.js';
9
- import { DEFAULT_FS_CAT_BYTES, MAX_FS_CAT_BYTES, FsReadBudgetError, downloadGroupFsBytes, readPersonalFsBytesWithinBudget, } from '../aun/group/fs-download.js';
9
+ import { DEFAULT_FS_CAT_BYTES, MAX_FS_CAT_BYTES, FsReadBudgetError, downloadGroupFsBytes, readPersonalFsBytesWithinBudget, readAuthoritativePersonalFsObject, } from '../aun/group/fs-download.js';
10
10
  class FsCliError extends Error {
11
11
  code;
12
12
  suggestion;
@@ -39,6 +39,7 @@ Commands:
39
39
  token issue|revoke|ls <path> 管理访问 token(personal storage)
40
40
  find <AID>:<path> [filters] 查找节点
41
41
  df <AID>: 查看容量/配额
42
+ link <AID>:<path> [--expires T] 生成下载直链(personal storage;T 如 24h/7d/0,0 为不过期)
42
43
  mount <target> --volume <id> 挂载实体卷
43
44
  mount <target> --source <src> 挂载远程子树
44
45
  approve <AID>:<path> 批准待审挂载(personal storage)
@@ -73,6 +74,7 @@ Options:
73
74
  --mtime <expr> find 修改时间过滤
74
75
  --head-bytes <n> cat 二进制头部字节数,默认 256
75
76
  --max-bytes <n> cat 读取预算,默认及最高 131072;超限终止读取
77
+ --authoritative cat 个人空间私有 ACL 完整对象;不使用 HTTP 下载票据
76
78
  --aun-path <path> 指定 AUN keystore 根
77
79
  --app <name> 指定 AUN app slot
78
80
 
@@ -126,6 +128,8 @@ export async function cmdFs(args) {
126
128
  let opts;
127
129
  try {
128
130
  opts = parseCommonOptions(args);
131
+ if (opts.authoritative && sub !== 'cat')
132
+ throw new FsCliError('INVALID_ARGUMENT', '--authoritative 只用于 cat');
129
133
  }
130
134
  catch (e) {
131
135
  outputError(e, formatJson);
@@ -186,6 +190,9 @@ export async function cmdFs(args) {
186
190
  case 'df':
187
191
  await fsDf(args.slice(1), opts);
188
192
  return;
193
+ case 'link':
194
+ await fsLink(args.slice(1), opts);
195
+ return;
189
196
  case 'mount':
190
197
  await fsMount(args.slice(1), opts);
191
198
  return;
@@ -275,6 +282,11 @@ async function runManagedFs(args, formatJson) {
275
282
  case 'remove':
276
283
  console.log(`✓ 已删除: ${result.path}`);
277
284
  return;
285
+ case 'link':
286
+ console.log(`🔗 ${String(result.url ?? '')}`);
287
+ if (result.expireAt)
288
+ console.log(`有效期至: ${new Date(Number(result.expireAt)).toISOString()}`);
289
+ return;
278
290
  case 'getfacl':
279
291
  console.log(JSON.stringify(result.result ?? {}, null, 2));
280
292
  return;
@@ -305,6 +317,7 @@ function parseCommonOptions(args) {
305
317
  contentType: getArgValue(args, '--content-type'),
306
318
  maxCatBytes,
307
319
  headBytes,
320
+ authoritative: args.includes('--authoritative'),
308
321
  };
309
322
  }
310
323
  function requireActor(opts) {
@@ -405,7 +418,15 @@ async function fsCat(args, opts) {
405
418
  const route = await resolveRoute(target.aid, store);
406
419
  let statInfo;
407
420
  let bytes;
408
- if (route.backend === 'group') {
421
+ if (opts.authoritative) {
422
+ if (route.backend !== 'personal' || opts.token) {
423
+ throw new FsCliError('INVALID_ARGUMENT', '--authoritative 仅支持按 AID 认证的个人空间对象');
424
+ }
425
+ const object = await readAuthoritativePersonalFsObject(client, target.path, target.aid, opts.maxCatBytes);
426
+ bytes = object.bytes;
427
+ statInfo = object.metadata;
428
+ }
429
+ else if (route.backend === 'group') {
409
430
  statInfo = await client.group.fs.stat(remoteRef(target));
410
431
  const size = numberFrom(statInfo, ['size', 'size_bytes', 'bytes']);
411
432
  if (size !== undefined && size > opts.maxCatBytes)
@@ -997,6 +1018,47 @@ async function fsDf(args, opts) {
997
1018
  }
998
1019
  });
999
1020
  }
1021
+ async function fsLink(args, opts) {
1022
+ const target = parseRemoteRequired(firstPositional(args), { command: 'link' });
1023
+ const expiresRaw = getArgValue(args, '--expires');
1024
+ let expiresSeconds;
1025
+ if (expiresRaw !== undefined) {
1026
+ const match = /^(\d+)([smhd])?$/i.exec(expiresRaw.trim());
1027
+ const unit = match?.[2]?.toLowerCase();
1028
+ const scale = unit === 'm' ? 60 : unit === 'h' ? 3600 : unit === 'd' ? 86400 : 1;
1029
+ const seconds = match ? Number(match[1]) * scale : Number.NaN;
1030
+ if (!match || !Number.isSafeInteger(seconds) || seconds > 7 * 24 * 3600) {
1031
+ throw new FsCliError('INVALID_ARGUMENT', '--expires 支持纯秒数或 30m / 12h / 7d,最长 7 天,0 表示不过期');
1032
+ }
1033
+ expiresSeconds = seconds;
1034
+ }
1035
+ await withClient(opts, async ({ client, store }) => {
1036
+ const route = await resolveRoute(target.aid, store);
1037
+ if (route.backend === 'group') {
1038
+ throw new FsCliError('NOT_ALLOWED', 'link 仅支持 personal storage');
1039
+ }
1040
+ const ticket = await client.call('storage.create_download_ticket', {
1041
+ owner_aid: target.aid,
1042
+ bucket: 'default',
1043
+ object_key: target.path.replace(/^\/+/, ''),
1044
+ ...(expiresSeconds !== undefined ? { expire_in_seconds: expiresSeconds } : {}),
1045
+ });
1046
+ const url = typeof ticket?.download_url === 'string' && ticket.download_url
1047
+ ? ticket.download_url
1048
+ : typeof ticket?.url === 'string' ? ticket.url : '';
1049
+ if (!url)
1050
+ throw new FsCliError('DEPENDENCY_UNAVAILABLE', 'storage 未返回下载链接');
1051
+ outputSuccess(opts, {
1052
+ command: 'link', backend: route.backend, route, path: remoteRef(target),
1053
+ url, expireAt: ticket.expire_at ?? null,
1054
+ }, () => {
1055
+ console.log(`🔗 ${url}`);
1056
+ if (expiresSeconds !== undefined) {
1057
+ console.log(expiresSeconds === 0 ? '有效期: 不过期' : `有效期: ${expiresSeconds} 秒`);
1058
+ }
1059
+ });
1060
+ });
1061
+ }
1000
1062
  async function fsMount(args, opts) {
1001
1063
  const positional = collectPositionals(args);
1002
1064
  const volumeId = getArgValue(args, '--volume');
package/dist/cli/index.js CHANGED
@@ -40,6 +40,7 @@ Agent 与会话:
40
40
  getmeta 按会话 id / threadId / agentSessionId 查询会话元数据
41
41
  task 恢复暂停或异常中断的会话任务
42
42
  trigger 管理定时与事件触发器
43
+ proxy 查询和管理 daemon 服务代理
43
44
  handoff 查询和完成跨会话回流
44
45
  model 查看或设置模型与推理强度
45
46
  response 查看或设置响应模式
@@ -280,11 +281,27 @@ export async function main(args) {
280
281
  if (process.env.EVOLCORE_SESSION_ID) {
281
282
  const sessionId = process.env.EVOLCORE_SESSION_ID;
282
283
  const delegationToken = readDelegationCredential();
283
- const result = await ipcQuery(resolvePaths().socket, {
284
- type: 'status.auth', sessionId, delegationToken,
285
- });
284
+ let result;
285
+ try {
286
+ // Status includes a process-scope authorization round trip. Give a
287
+ // busy daemon enough time to answer and preserve transport failures
288
+ // instead of turning them into a misleading permission denial.
289
+ result = await ipcQuery(resolvePaths().socket, {
290
+ type: 'status.auth', sessionId, delegationToken, argv: ['status', ...statusArgs],
291
+ }, 10_000, { throwOnError: true });
292
+ }
293
+ catch (error) {
294
+ console.error(`❌ status 查询失败:${error instanceof Error ? error.message : String(error)}`);
295
+ process.exitCode = 1;
296
+ break;
297
+ }
298
+ if (result === null) {
299
+ console.error('❌ status 查询失败:daemon 未返回授权结果');
300
+ process.exitCode = 1;
301
+ break;
302
+ }
286
303
  if (!result?.ok) {
287
- console.error(`❌ ${result?.error || 'status is not allowed in this task'}`);
304
+ console.error(`❌ ${result?.error || 'status 权限校验失败'}`);
288
305
  process.exitCode = 1;
289
306
  break;
290
307
  }
@@ -380,6 +397,28 @@ export async function main(args) {
380
397
  await cmdTrigger(strippedArgs.slice(1));
381
398
  }
382
399
  break;
400
+ case 'proxy': {
401
+ const { cmdProxy } = await import('./proxy-command.js');
402
+ try {
403
+ await cmdProxy(strippedArgs.slice(1));
404
+ }
405
+ catch (error) {
406
+ const result = {
407
+ ok: false,
408
+ code: typeof error?.code === 'string' ? error.code : 'PROXY_FAILED',
409
+ error: error?.message ?? String(error),
410
+ };
411
+ const formatIndex = strippedArgs.indexOf('--format');
412
+ if ((formatIndex >= 0 && strippedArgs[formatIndex + 1] === 'json') || strippedArgs.includes('--json')) {
413
+ console.log(JSON.stringify(result));
414
+ }
415
+ else {
416
+ console.error(result.error + ' (' + result.code + ')');
417
+ }
418
+ process.exitCode = 1;
419
+ }
420
+ break;
421
+ }
383
422
  case 'agent': {
384
423
  const { suppressSdkLogs } = await import('../aun/aid/index.js');
385
424
  suppressSdkLogs();
@@ -492,6 +531,11 @@ export async function main(args) {
492
531
  await cmdContact(strippedArgs.slice(1));
493
532
  break;
494
533
  }
534
+ case 'role': {
535
+ const { cmdRole } = await import('./role.js');
536
+ await cmdRole(strippedArgs.slice(1));
537
+ break;
538
+ }
495
539
  case 'stats': {
496
540
  const { handleStats } = await import('./stats.js');
497
541
  await handleStats(strippedArgs.slice(1));
@@ -16,8 +16,12 @@ const MANAGED_TASK_COMMANDS = new Set([
16
16
  'memory',
17
17
  'model',
18
18
  'msg',
19
+ 'proxy',
19
20
  'queue',
20
21
  'response',
22
+ // `role` 提交/审批关系角色提升申请,通过 role.op IPC 鉴权;
23
+ // 申请本身不改变权限,审批只接受本 Agent 的 owner。
24
+ 'role',
21
25
  // `session` 按 ec 会话 id 只读查询本地 session 存档(meta 文件尾行的
22
26
  // agentSessionId 等),不触碰 daemon 与进程生命周期。
23
27
  'session',
package/dist/cli/model.js CHANGED
@@ -1,17 +1,17 @@
1
1
  /**
2
2
  * `ec model` —— 面向 agent 的模型管理命令集。
3
3
  *
4
- * 可写作用域由参数决定:
5
- * --self → agent config.json
6
- * --self --peer → 关系 relations/<peerKey>/config.json
4
+ * 模型参数只在 Agent 级配置:
5
+ * --self → agents/<aid>/config.json 的 baseagents.<ba>.{model,effort}
6
+ * --peer 保留只读:可用于查看按关系角色约束生效的模型(model current/list/check)。
7
7
  * 角色模型策略由角色策略编辑器管理;--role 仅用于过滤和预览有效模型。
8
8
  *
9
- * 改某作用域后,对应范围所有会话的下一条消息即时生效(运行时按 关系>角色>agent>defaults 解析)。
9
+ * 改 Agent 级后,该 Agent 所有会话的下一条消息即时生效(运行时不缓存,每条消息解析)。
10
10
  * 与对话内 slash(/model /effort /baseagent)互不影响。
11
11
  * 设计见 docs/model-command-design.md。
12
12
  */
13
13
  import { isHelpFlag, wantsHelp, getArgValue } from './help.js';
14
- import { ModelScopeError, normalizePeer, determineScope, activeBaseagent, writeScope, clearScope, } from '../core/model/config-scope.js';
14
+ import { ModelScopeError, normalizePeer, determineScope, activeBaseagent, writeAgentModelConfig, clearAgentModelConfig, } from '../core/model/config-scope.js';
15
15
  import { resolveEffectiveFieldWithSource } from '../config/config-manager.js';
16
16
  import { getCatalog, getModelInfo, catalogEfforts, resolveCatalogModel, assertCatalogSelectable } from '../core/model/model-catalog.js';
17
17
  import { constrainResolvedModelForRole, filterModelsForRole, validateModelSelectionForRole, } from '../core/model/model-permission.js';
@@ -119,14 +119,16 @@ function explicitOrDerivedRole(args, sel) {
119
119
  }
120
120
  }
121
121
  function determineWriteScope(sel, formatJson) {
122
+ if (!sel.self)
123
+ fail(formatJson, 'AGENT_REQUIRED', '模型参数只在 Agent 级配置,请指定 --self <aid>');
124
+ if (sel.peerKey)
125
+ fail(formatJson, 'MODEL_AGENT_ONLY', '模型参数不支持 --peer:写入只在 Agent 级,不在关系级');
122
126
  const scope = determineScope(sel);
123
- if (scope === 'global') {
127
+ if (scope === 'global')
124
128
  fail(formatJson, 'NO_GLOBAL_SCOPE', '全局 model 作用域已退役;请用 --self 选择 agent');
125
- }
126
- if (scope === 'role') {
129
+ if (scope === 'role')
127
130
  fail(formatJson, 'ROLE_POLICY_MANAGED', '角色策略只能通过角色策略编辑器修改');
128
- }
129
- return scope;
131
+ return 'agent';
130
132
  }
131
133
  function selectorWithRole(sel, role) {
132
134
  return role ? { ...sel, role } : sel;
@@ -158,7 +160,8 @@ function resolveModelConfig(sel, baseagent) {
158
160
  const effectiveModel = modelDecision.model;
159
161
  const modelSource = modelDecision.constrained ? 'role' : modelScopeFromSource(model.source);
160
162
  const source = effectiveModel !== undefined ? modelSource : modelScopeFromSource(effort.source);
161
- const scopes = ['relation', 'role', 'agent', 'global'];
163
+ // 模型只在 Agent 级配置,角色策略只做约束。
164
+ const scopes = ['role', 'agent'];
162
165
  return {
163
166
  model: effectiveModel,
164
167
  effort: effort.value,
@@ -173,27 +176,28 @@ function resolveModelConfig(sel, baseagent) {
173
176
  const HELP = `用法: ec model <command> [options]
174
177
 
175
178
  Commands:
176
- list 列出可用模型,标注各作用域命中
177
- current 显示按优先级解析后实际生效的模型 + 来源
179
+ list 列出可用模型,标注当前 Agent 级模型
180
+ current 显示 Agent 级模型(经角色约束)+ 来源
178
181
  info <model-id> 查看单个模型详情(厂商/上下文/价格/模态/effort/状态)
179
- use <model-id> 设置模型(作用域由 --self/--peer 决定)
180
- reset 清除指定作用域的设置,回落上一级
181
- effort <level> 设置推理强度(low|medium|high|xhigh|max|auto)
182
+ use <model-id> 设置 Agent 级模型(需 --self)
183
+ reset 清除 Agent 级模型与推理强度;清除后该 Agent 无模型可用
184
+ effort <level> 设置 Agent 级推理强度(low|medium|high|xhigh|max|auto)
182
185
  check 诊断网关连通性与模型可用性(分阶段输出进度)
183
186
 
184
- 作用域(越具体越优先:关系 > 角色 > agent > defaults):
185
- (无参数) 本机 CLI 只读 catalog/defaults,不允许写入
186
- --self <aid> agent级 → config.json
187
- --self <aid> --role <role> 角色策略预览(只读)
188
- --self <aid> --peer <X> 关系级 → relations/<peerKey>/config.json
187
+ 模型参数只在 Agent 级配置(agents/<aid>/config.json 的 baseagents.<ba>.{model,effort})。
188
+ 关系级与 defaults 都不承载模型;Agent 级未设置模型即无模型可用。
189
+ (无参数) 本机 CLI 只读 catalog,不允许写入
190
+ --self <aid> Agent 级(读写)
191
+ --self <aid> --role <role> 按角色策略预览有效模型(只读)
192
+ --self <aid> --peer <X> 按该对端的关系角色预览有效模型(只读,不可写)
189
193
 
190
- 修改 agent/关系作用域后,对应范围所有会话的下一条消息即时生效。
194
+ 修改 Agent 级后,该 Agent 所有会话的下一条消息即时生效。
191
195
  角色策略请通过角色策略编辑器修改。
192
- 托管会话内省略 --self/--peer/--role 时,命令作用于当前会话。
196
+ 托管会话内省略 --self/--peer/--role 时,命令作用于当前会话;写操作仅当前 Agent 的 owner/admin 可用。
193
197
 
194
198
  Options:
195
199
  --self <aid> 本端 AID
196
- --peer <X> 对端:channelType#channelId 或裸 aid(裸 aid 视为 aun#<aid>)
200
+ --peer <X> 对端:channelType#channelId 或裸 aid(裸 aid 视为 aun#<aid>),只读
197
201
  --role <role> 按角色过滤列表或预览有效模型(只读)
198
202
  --effort <level> (use 专用)同时设置推理强度
199
203
  --format json 输出 JSON
@@ -204,9 +208,8 @@ Options:
204
208
  ec model current --self bot.agentid.pub --peer aun#alice.agentid.pub
205
209
  ec model info deepseek-v4-pro
206
210
  ec model use opus --self bot.agentid.pub
207
- ec model use deepseek-v4-pro --self bot.agentid.pub --peer alice.agentid.pub
208
211
  ec model effort high --self bot.agentid.pub
209
- ec model reset --self bot.agentid.pub --peer alice.agentid.pub
212
+ ec model reset --self bot.agentid.pub
210
213
  ec model check --self bot.agentid.pub`;
211
214
  async function dispatch(sub, args, formatJson) {
212
215
  switch (sub) {
@@ -251,7 +254,7 @@ async function cmdList(args, formatJson) {
251
254
  models,
252
255
  }, () => {
253
256
  const lines = [];
254
- lines.push(`当前生效: ${resolved.model ?? '(未设置,回落 SDK 默认)'}` +
257
+ lines.push(`当前生效: ${resolved.model ?? '(未配置,Agent 级未设置模型,无模型可用)'}` +
255
258
  (resolved.source ? ` (来源: ${SCOPE_LABEL[resolved.source]})` : ''));
256
259
  lines.push('');
257
260
  if (resolved.model && !cat.models.some(m => m.id === resolved.model))
@@ -286,7 +289,7 @@ async function cmdCurrent(args, formatJson) {
286
289
  chain: resolved.chain.map((c) => ({ scope: c.scope, model: c.model ?? null, hit: c.hit })),
287
290
  }, () => {
288
291
  const lines = [];
289
- lines.push(`当前生效模型: ${resolved.model ?? '(未设置,回落 SDK 默认)'}`);
292
+ lines.push(`当前生效模型: ${resolved.model ?? '(未配置,Agent 级未设置模型,无模型可用)'}`);
290
293
  lines.push(`推理强度: ${resolved.effort ?? 'auto'}`);
291
294
  lines.push(`来源: ${resolved.source ? SCOPE_LABEL[resolved.source] : '无'}`);
292
295
  const chain = resolved.chain.map((c) => `${SCOPE_LABEL[c.scope]}${c.hit ? ' ✓' : ''}${c.model ? `(${c.model})` : ''}`).join(' > ');
@@ -328,17 +331,15 @@ function describeWrite(scope, sel, model, effort, formatJson) {
328
331
  ok: true,
329
332
  scope,
330
333
  self: sel.self ?? null,
331
- peerKey: sel.peerKey ?? null,
332
334
  model: model ?? undefined,
333
335
  effort: effort ?? undefined,
334
336
  }, () => {
335
- const lines = ['✓ 已设置', ` 作用域: ${SCOPE_LABEL[scope]}` +
336
- (sel.peerKey ? ` (${sel.peerKey})` : '') + (sel.self ? ` [self=${sel.self}]` : '')];
337
+ const lines = ['✓ 已设置', ` 作用域: ${SCOPE_LABEL[scope]} [self=${sel.self ?? '?'}]`];
337
338
  if (model !== null)
338
339
  lines.push(` 模型: ${model}`);
339
340
  if (effort !== null)
340
341
  lines.push(` 推理强度: ${effort}`);
341
- lines.push(' 生效: 该范围所有会话的下一条消息起生效。');
342
+ lines.push(' 生效: 该 Agent 所有会话的下一条消息起生效。');
342
343
  return lines.join('\n');
343
344
  });
344
345
  }
@@ -378,14 +379,14 @@ async function cmdUse(args, formatJson) {
378
379
  }
379
380
  const effortVal = effort === 'auto' ? null : (effort ?? undefined);
380
381
  try {
381
- writeScope(scope, sel, ba, { model: modelId, effort: effortVal });
382
+ writeAgentModelConfig(sel.self, ba, { model: modelId, effort: effortVal });
382
383
  }
383
384
  catch (e) {
384
385
  if (e instanceof ModelScopeError)
385
386
  fail(formatJson, e.code, e.message);
386
387
  throw e;
387
388
  }
388
- describeWrite(scope, sel, modelId, effort ?? null, formatJson);
389
+ describeWrite('agent', sel, modelId, effort ?? null, formatJson);
389
390
  }
390
391
  async function cmdEffort(args, formatJson) {
391
392
  if (wantsHelp(args)) {
@@ -410,14 +411,14 @@ async function cmdEffort(args, formatJson) {
410
411
  fail(formatJson, 'INVALID_EFFORT', `当前模型目录未声明支持推理强度: ${val}`);
411
412
  }
412
413
  try {
413
- writeScope(scope, sel, ba, { effort: val });
414
+ writeAgentModelConfig(sel.self, ba, { effort: val });
414
415
  }
415
416
  catch (e) {
416
417
  if (e instanceof ModelScopeError)
417
418
  fail(formatJson, e.code, e.message);
418
419
  throw e;
419
420
  }
420
- describeWrite(scope, sel, null, level, formatJson);
421
+ describeWrite('agent', sel, null, level, formatJson);
421
422
  }
422
423
  async function cmdReset(args, formatJson) {
423
424
  if (wantsHelp(args)) {
@@ -428,7 +429,7 @@ async function cmdReset(args, formatJson) {
428
429
  const scope = determineWriteScope(sel, formatJson);
429
430
  const ba = activeBaseagent(sel.self);
430
431
  try {
431
- clearScope(scope, sel, ba);
432
+ clearAgentModelConfig(sel.self, ba);
432
433
  }
433
434
  catch (e) {
434
435
  if (e instanceof ModelScopeError)
@@ -436,9 +437,9 @@ async function cmdReset(args, formatJson) {
436
437
  throw e;
437
438
  }
438
439
  emit(formatJson, {
439
- ok: true, scope, self: sel.self ?? null, peerKey: sel.peerKey ?? null,
440
+ ok: true, scope: 'agent', self: sel.self ?? null, peerKey: sel.peerKey ?? null,
440
441
  }, () => {
441
- return `✓ 已清除 ${SCOPE_LABEL[scope]} 设置,回落上一级(该范围所有会话下条消息生效)`;
442
+ return `✓ 已清除 Agent 级模型设置(该 Agent 所有会话下条消息生效,无模型可用直到重新设置)`;
442
443
  });
443
444
  }
444
445
  async function cmdCheck(args, formatJson) {
@@ -452,7 +453,6 @@ async function cmdCheck(args, formatJson) {
452
453
  const steps = [];
453
454
  const result = await runModelCheck({
454
455
  self: sel.self,
455
- peerKey: sel.peerKey,
456
456
  role,
457
457
  baseagent: ba,
458
458
  onStep: step => steps.push(step),
@@ -0,0 +1,92 @@
1
+ import fs from 'node:fs';
2
+ import { resolvePaths } from '../paths.js';
3
+ import { queryDaemon, daemonUnavailableMessage } from './help.js';
4
+ import { readDelegationCredential, hashCurrentDelegatedCommand } from '../core/auth/agent-delegation.js';
5
+ function printJson(value) {
6
+ console.log(JSON.stringify(value, null, 2));
7
+ }
8
+ function help() {
9
+ console.log([
10
+ '用法: ec proxy <命令> [选项]',
11
+ '',
12
+ '只管理当前 daemon 中声明的 ServiceProxy 服务。',
13
+ '',
14
+ '命令:',
15
+ ' list [--format json]',
16
+ ' show <name> [--format json]',
17
+ ' status <name> [--format json]',
18
+ ' access <name> [--format json]',
19
+ ' options [--format json]',
20
+ " build --file <service.json>|--json '<service-json>' --if-rev absent --operation-id <id>",
21
+ " update <name> --file <patch.json>|--json '<patch-json>' --if-rev <revision> --operation-id <id>",
22
+ ' apply [--all] --operation-id <id>',
23
+ ' publish|unpublish|remove|start|stop|restart|reload|reset-failure <name> --if-rev <revision> --operation-id <id>',
24
+ ' job <operation-id> [--format json]',
25
+ '',
26
+ '通用:',
27
+ ' --dry-run 校验并显示计划,不写入或执行',
28
+ ' --format json 输出结构化结果',
29
+ '',
30
+ '新服务以 --if-rev absent 创建。变更前先查询 show/status 获取 configRev。',
31
+ ].join('\n'));
32
+ }
33
+ export async function cmdProxy(args) {
34
+ if (!args.length || args[0] === '--help' || args[0] === '-h' || args[0] === 'help') {
35
+ help();
36
+ return;
37
+ }
38
+ const sessionId = process.env.EVOLCORE_SESSION_ID;
39
+ const delegationToken = readDelegationCredential();
40
+ let controlToken;
41
+ if (!sessionId) {
42
+ try {
43
+ controlToken = fs.readFileSync(resolvePaths().controlToken, 'utf8').trim() || undefined;
44
+ }
45
+ catch { }
46
+ }
47
+ const { response, transportError } = await queryDaemon(resolvePaths().socket, {
48
+ type: 'proxy.op',
49
+ argv: ['proxy', ...args],
50
+ ...(sessionId ? {
51
+ sessionId,
52
+ delegationToken,
53
+ delegationCommandHash: hashCurrentDelegatedCommand(),
54
+ } : controlToken ? { controlToken } : {}),
55
+ }, 120_000);
56
+ if (!response) {
57
+ throw Object.assign(new Error(daemonUnavailableMessage(transportError, '无法连接 EvolCore daemon')), { code: 'DAEMON_UNAVAILABLE' });
58
+ }
59
+ const formatIndex = args.indexOf('--format');
60
+ const isJson = (formatIndex >= 0 && args[formatIndex + 1] === 'json') || args.includes('--json');
61
+ if (response.ok === false) {
62
+ if (isJson)
63
+ printJson(response);
64
+ else
65
+ process.stderr.write((response.error ?? 'ServiceProxy 操作失败') + ' (' + (response.code ?? 'FAILED') + ')\n');
66
+ process.exitCode = 1;
67
+ return;
68
+ }
69
+ if (isJson) {
70
+ printJson(response);
71
+ return;
72
+ }
73
+ const result = response;
74
+ if (result.services) {
75
+ if (result.services.length === 0)
76
+ console.log('(无 ServiceProxy 服务)');
77
+ for (const service of result.services) {
78
+ console.log(service.name + ' enabled=' + service.enabled
79
+ + ' proxy=' + service.proxy?.enabled + ' runtime=' + service.runtime?.state
80
+ + ' configRev=' + service.configRev);
81
+ }
82
+ return;
83
+ }
84
+ if (result.service) {
85
+ console.log(JSON.stringify(result.service, null, 2));
86
+ return;
87
+ }
88
+ if (result.jobId)
89
+ console.log('✓ ' + (result.state ?? 'completed') + ' operationId=' + result.operationId + ' jobId=' + result.jobId);
90
+ else
91
+ console.log(JSON.stringify(result, null, 2));
92
+ }
@@ -234,6 +234,23 @@ export async function cmdRestartMonitor() {
234
234
  process.exitCode = 2;
235
235
  return;
236
236
  }
237
+ if (upgradeJob?.distTag === 'stable') {
238
+ let enabled = false;
239
+ try {
240
+ enabled = loadDaemonConfig().upgrade?.autoOnStart !== false;
241
+ }
242
+ catch { }
243
+ if (!enabled) {
244
+ log('Automatic stable upgrade disabled before restart; leaving the daemon running');
245
+ updateUpgradeJob(upgradeJob.jobId, {
246
+ status: 'failed', success: false, released: true, code: 'AUTO_UPGRADE_DISABLED',
247
+ reason: 'Automatic stable upgrades disabled by autoOnStart',
248
+ }, '自动更新已关闭,未执行重启');
249
+ cleanupPendingFile(pendingFile, log, hasCorrelatedRequest ? requestId : undefined);
250
+ process.exitCode = 2;
251
+ return;
252
+ }
253
+ }
237
254
  if (hasCorrelatedRequest) {
238
255
  if (upgradeJob && (readUpgradeJob(upgradeJob.jobId)?.status !== 'running' || upgradeJob.deadline <= Date.now())) {
239
256
  cleanupPendingFile(pendingFile, log, requestId);
@@ -0,0 +1,85 @@
1
+ import { resolvePaths } from '../paths.js';
2
+ import { executeResolvedRoleCommand, resolveRoleCommand, } from '../config/role-command-service.js';
3
+ import { applyApprovedRoleAssignment } from '../core/command/role-menu.js';
4
+ import { listStaticAgentOwners } from '../config/peer-role-resolver.js';
5
+ import { daemonUnavailableMessage, queryDaemon } from './help.js';
6
+ import { AGENT_DELEGATION_TOKEN_ENV, readDelegationCredential } from '../core/auth/agent-delegation.js';
7
+ import { getArgValue, isHelpFlag, wantsHelp } from './help.js';
8
+ export async function cmdRole(args) {
9
+ if (args.length === 0 || isHelpFlag(args[0]) || wantsHelp(args)) {
10
+ printHelp();
11
+ return;
12
+ }
13
+ const json = getArgValue(args, '--format') === 'json';
14
+ if (process.env.EVOLCORE_SESSION_ID) {
15
+ try {
16
+ const result = await runManaged(args, json);
17
+ output(result, json);
18
+ }
19
+ catch (err) {
20
+ console.error(`❌ ${err.message ?? String(err)}`);
21
+ process.exitCode = 1;
22
+ }
23
+ return;
24
+ }
25
+ const resolved = resolveRoleCommand(args);
26
+ if (!resolved.ok)
27
+ fail(resolved.reason, resolved.code);
28
+ const selfAid = resolved.command.selfAid;
29
+ const actorAid = listStaticAgentOwners(selfAid)[0] ?? selfAid;
30
+ const result = await executeResolvedRoleCommand(resolved.command, actorAid, applyApprovedRoleAssignment);
31
+ if (!result.ok)
32
+ fail(result.error, result.code, result.data);
33
+ output(result, json);
34
+ }
35
+ function output(value, json) {
36
+ if (json)
37
+ console.log(JSON.stringify(value));
38
+ else
39
+ console.log(JSON.stringify(value, null, 2));
40
+ }
41
+ async function runManaged(args, json) {
42
+ const sessionId = process.env.EVOLCORE_SESSION_ID;
43
+ const delegationToken = readDelegationCredential();
44
+ if (!delegationToken)
45
+ fail(`${AGENT_DELEGATION_TOKEN_ENV} is not set for the active task`, 'DELEGATION_REQUIRED');
46
+ const { response, transportError } = await queryDaemon(resolvePaths().socket, {
47
+ type: 'role.op',
48
+ argv: ['role', ...args],
49
+ sessionId,
50
+ delegationToken,
51
+ }, 10_000);
52
+ if (!response) {
53
+ fail(daemonUnavailableMessage(transportError, 'Unable to connect to the evolcore daemon'), 'DAEMON_UNAVAILABLE');
54
+ }
55
+ if (!response.ok || !response.result) {
56
+ fail(response.error || 'role operation failed', response.code || 'ROLE_AUTH_FAILED', response.data);
57
+ }
58
+ return response.result;
59
+ }
60
+ function fail(message, code = 'INVALID_ARGUMENT', data) {
61
+ const error = new Error(message);
62
+ error.code = code;
63
+ if (data !== undefined)
64
+ error.data = data;
65
+ throw error;
66
+ }
67
+ function printHelp() {
68
+ console.log(`Usage:
69
+ ec role request <peer-aid> --role <role-id> [--reason '<text>'] [--self <agent-aid>]
70
+ ec role list [--status pending|approved|rejected|expired] [--self <agent-aid>]
71
+ ec role approve <request-id> [--reason '<text>'] [--self <agent-aid>]
72
+ ec role reject <request-id> [--reason '<text>'] [--self <agent-aid>]
73
+
74
+ 说明:
75
+ 申请不会立即改变权限,只记录一条待审批请求,交由本 Agent 的 owner 审批。
76
+ approve / reject 只能由本 Agent 的 owner 执行;审批通过后才写入关系角色。
77
+
78
+ Options:
79
+ --self <agent-aid> 本端 agent AID;省略时从当前运行环境推断
80
+ --role <role-id> 申请提升到的角色(不能是 owner)
81
+ --status <status> 过滤请求状态
82
+ --reason <text> 申请或审批理由
83
+ --format json 输出 JSON
84
+ --help, -h 显示帮助`);
85
+ }