evolcore 0.0.41-test.0 → 0.0.41-test.2

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 (235) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/dist/agents/baseagent-availability.js +1 -1
  3. package/dist/agents/baseagent.js +88 -49
  4. package/dist/agents/claude-runner.js +177 -92
  5. package/dist/agents/codex-runner.js +146 -71
  6. package/dist/agents/ecagent-runner.js +1 -1
  7. package/dist/agents/gemini-runner.js +1 -1
  8. package/dist/aun/aid/agentmd.js +98 -11
  9. package/dist/aun/aid/client.js +1 -1
  10. package/dist/aun/aid/control-aid.js +26 -2
  11. package/dist/aun/aid/identity.js +91 -0
  12. package/dist/aun/aid/index.js +1 -1
  13. package/dist/aun/aid/managed-operation.js +1 -1
  14. package/dist/aun/aid/ownership-operation.js +23 -22
  15. package/dist/aun/group/fs-download.js +39 -0
  16. package/dist/aun/group/identity.js +36 -21
  17. package/dist/aun/group/operations.js +5 -0
  18. package/dist/aun/menu/client.js +27 -0
  19. package/dist/aun/msg/managed-operation.js +68 -7
  20. package/dist/aun/msg/p2p.js +8 -8
  21. package/dist/aun/service-proxy.js +53 -12
  22. package/dist/channels/aun.js +633 -32
  23. package/dist/channels/daemon.js +15 -1
  24. package/dist/cli/agent-command.js +5 -2
  25. package/dist/cli/agent-create.js +991 -233
  26. package/dist/cli/agent.js +49 -10
  27. package/dist/cli/aid-bind-command.js +48 -19
  28. package/dist/cli/aun-commands.js +48 -36
  29. package/dist/cli/daemon-commands.js +679 -697
  30. package/dist/cli/fs-command.js +64 -2
  31. package/dist/cli/index.js +72 -5
  32. package/dist/cli/init-channel.js +1 -1
  33. package/dist/cli/init.js +75 -1
  34. package/dist/cli/managed-command-guard.js +17 -1
  35. package/dist/cli/model.js +40 -40
  36. package/dist/cli/provider-command.js +57 -0
  37. package/dist/cli/proxy-command.js +92 -0
  38. package/dist/cli/restart-monitor.js +4 -2
  39. package/dist/cli/role.js +85 -0
  40. package/dist/cli/stats.js +10 -3
  41. package/dist/cli/task-context.js +19 -0
  42. package/dist/config/access-policy.js +7 -2
  43. package/dist/config/boot-log.js +39 -1
  44. package/dist/config/config-field-policy.js +17 -39
  45. package/dist/config/config-manager.js +183 -44
  46. package/dist/config/config-operation-service.js +5 -19
  47. package/dist/config/contact-book-store.js +47 -21
  48. package/dist/config/contact-book.js +18 -12
  49. package/dist/config/contact-operation-service.js +3 -4
  50. package/dist/config/contact-request-service.js +11 -0
  51. package/dist/config/daemon-services.js +11 -0
  52. package/dist/config/gateway-config.js +88 -594
  53. package/dist/config/owner-config.js +2 -2
  54. package/dist/config/peer-role-resolver.js +15 -12
  55. package/dist/config/provider-ipc-service.js +132 -0
  56. package/dist/config/provider-menu-request.js +58 -0
  57. package/dist/config/providers-config.js +12 -7
  58. package/dist/config/providers-import.js +3 -21
  59. package/dist/config/providers-management.js +78 -5
  60. package/dist/config/resolved-config-op.js +11 -1
  61. package/dist/config/role-command-service.js +166 -0
  62. package/dist/config/role-request-service.js +193 -0
  63. package/dist/config/schema-migration.js +1000 -25
  64. package/dist/config-store.js +89 -4
  65. package/dist/contracts/ecweb-instance.js +41 -0
  66. package/dist/contracts/ecweb-service-protocol.js +4 -1
  67. package/dist/core/agent-application-service.js +60 -11
  68. package/dist/core/agent-create-status.js +203 -0
  69. package/dist/core/agent-creation-claim.js +177 -0
  70. package/dist/core/agent-ipc-registration.js +39 -18
  71. package/dist/core/agent-runtime.js +194 -24
  72. package/dist/core/auth/agent-delegation.js +6 -3
  73. package/dist/core/auth/auth-gateway.js +67 -2
  74. package/dist/core/auth/authorization-audit.js +58 -11
  75. package/dist/core/auth/delegation-authorization.js +5 -2
  76. package/dist/core/auth/operation-authorizer.js +43 -6
  77. package/dist/core/auth/operation-catalog.js +45 -7
  78. package/dist/core/channel-loader.js +2 -0
  79. package/dist/core/command/agent-control.js +260 -21
  80. package/dist/core/command/agent-storage-menu.js +5 -3
  81. package/dist/core/command/cli-intent-parser.js +8 -3
  82. package/dist/core/command/command-handler.js +112 -154
  83. package/dist/core/command/connect-menu.js +11 -3
  84. package/dist/core/command/data-root-resolver.js +5 -4
  85. package/dist/core/command/memory-slash.js +16 -8
  86. package/dist/core/command/menu-catalog.js +10 -6
  87. package/dist/core/command/menu-handler.js +106 -73
  88. package/dist/core/command/menu-protocol.js +15 -1
  89. package/dist/core/command/provider-menu.js +46 -0
  90. package/dist/core/command/role-menu.js +147 -30
  91. package/dist/core/command/slash-handler.js +125 -255
  92. package/dist/core/daemon-control.js +26 -27
  93. package/dist/core/event-catalog.js +10 -0
  94. package/dist/core/evolagent-registry.js +7 -5
  95. package/dist/core/evolagent.js +10 -8
  96. package/dist/core/file-integrity/store.js +11 -0
  97. package/dist/core/handoff/ipc-registration.js +3 -0
  98. package/dist/core/inference/text-inference.js +31 -40
  99. package/dist/core/initialization/service.js +491 -0
  100. package/dist/core/ipc-registration.js +40 -24
  101. package/dist/core/memory/consolidation-context.js +51 -5
  102. package/dist/core/memory/consolidation-ops-records.js +96 -1
  103. package/dist/core/memory/consolidation-trigger.js +208 -191
  104. package/dist/core/memory/consolidation.js +333 -35
  105. package/dist/core/memory/index-manager.js +27 -5
  106. package/dist/core/memory/memory-admin.js +45 -5
  107. package/dist/core/memory/memory-writer.js +163 -18
  108. package/dist/core/memory/relation-idle-monitor.js +119 -58
  109. package/dist/core/memory/relation-sweep.js +55 -45
  110. package/dist/core/message/aun-ipc-sender.js +81 -69
  111. package/dist/core/message/im-renderer.js +25 -4
  112. package/dist/core/message/message-admission.js +89 -4
  113. package/dist/core/message/message-bridge.js +66 -21
  114. package/dist/core/message/response-engine.js +108 -35
  115. package/dist/core/model/catalog-service.js +5 -3
  116. package/dist/core/model/config-scope.js +29 -71
  117. package/dist/core/model/field-scope.js +1 -1
  118. package/dist/core/model/model-catalog.js +30 -41
  119. package/dist/core/model/model-diagnostics.js +4 -3
  120. package/dist/core/model/model-fallback.js +10 -7
  121. package/dist/core/model/model-permission.js +3 -2
  122. package/dist/core/ownership/owner-resolver.js +772 -158
  123. package/dist/core/permission/approval-gateway.js +103 -403
  124. package/dist/core/permission/ec-command-parser.js +62 -6
  125. package/dist/core/permission/index.js +1 -0
  126. package/dist/core/permission/permission-result.js +78 -0
  127. package/dist/core/permission/sandbox-runtime.js +18 -1
  128. package/dist/core/permission/tool-policy.js +21 -46
  129. package/dist/core/relation/peer-identity.js +64 -1
  130. package/dist/core/role/runtime-policy.js +72 -13
  131. package/dist/core/session/session-capsule.js +1 -1
  132. package/dist/core/session/session-idle-monitor.js +1 -1
  133. package/dist/core/session/session-manager.js +20 -0
  134. package/dist/core/session/session-renew.js +3 -3
  135. package/dist/core/skill/index-generator.js +15 -5
  136. package/dist/core/system-session/memory.js +43 -8
  137. package/dist/core/thread/thread-service.js +19 -6
  138. package/dist/directory/owner-directory-admission.js +95 -0
  139. package/dist/directory/owner-directory-authorization.js +309 -0
  140. package/dist/directory/owner-directory-cache.js +635 -0
  141. package/dist/eck/kit-renderer.js +2 -2
  142. package/dist/ecweb/basic-settings-service.js +33 -40
  143. package/dist/ecweb/init-menu.js +32 -0
  144. package/dist/ecweb/message-context-service.js +110 -0
  145. package/dist/index.js +93 -19
  146. package/dist/ipc.js +247 -29
  147. package/dist/paths.js +7 -0
  148. package/dist/proxy/command.js +122 -0
  149. package/dist/proxy/ipc-service.js +68 -0
  150. package/dist/proxy/manager.js +484 -0
  151. package/dist/proxy/service-supervisor.js +603 -0
  152. package/dist/response-system/engines/v1/proactive-flow.js +16 -6
  153. package/dist/trigger/authorization.js +27 -17
  154. package/dist/trigger/feedback.js +2 -3
  155. package/dist/trigger/ipc-service.js +105 -78
  156. package/dist/trigger/local-files.js +2 -1
  157. package/dist/trigger/manager.js +5 -3
  158. package/dist/trigger/scheduler.js +88 -6
  159. package/dist/utils/atomic-write.js +28 -0
  160. package/dist/utils/cross-platform.js +14 -0
  161. package/dist/utils/ecweb-supervisor.js +258 -83
  162. package/dist/utils/error-utils.js +26 -2
  163. package/dist/utils/logger.js +92 -6
  164. package/dist/utils/package-version-info.js +4 -2
  165. package/dist/utils/welcome.js +1 -1
  166. package/kits/docs/INDEX.md +1 -0
  167. package/kits/docs/aun/SDK.md +4 -1
  168. package/kits/docs/channels/aun.md +9 -0
  169. package/kits/docs/evolcore/INDEX.md +1 -0
  170. package/kits/docs/evolcore/agent.md +8 -1
  171. package/kits/docs/evolcore/aid.md +67 -17
  172. package/kits/docs/evolcore/config.md +28 -7
  173. package/kits/docs/evolcore/contact.md +3 -0
  174. package/kits/docs/evolcore/fs.md +11 -0
  175. package/kits/docs/evolcore/group.md +1 -1
  176. package/kits/docs/evolcore/memory-architecture.md +2 -2
  177. package/kits/docs/evolcore/memory-consolidation.md +32 -8
  178. package/kits/docs/evolcore/memory.md +1 -1
  179. package/kits/docs/evolcore/menu-protocol.md +4 -0
  180. package/kits/docs/evolcore/model.md +23 -20
  181. package/kits/docs/evolcore/msg.md +4 -7
  182. package/kits/docs/evolcore/provider.md +50 -0
  183. package/kits/docs/identity/AID_PROFILE_SPEC.md +52 -17
  184. package/kits/migrations/migrate-contact-book-v2.mjs +30 -11
  185. package/kits/rules/01-overview.md +3 -0
  186. package/kits/rules/04-relation.md +1 -1
  187. package/kits/schemas/_meta.json +37 -4
  188. package/kits/schemas/agent-config.schema.13.json +8 -3
  189. package/kits/schemas/agent-config.schema.16.json +891 -0
  190. package/kits/schemas/daemon.schema.9.json +366 -0
  191. package/kits/schemas/defaults.schema.5.json +406 -127
  192. package/kits/schemas/relation-config.schema.11.json +277 -0
  193. package/kits/schemas/role-config.schema.1.json +7 -7
  194. package/kits/skills/.switches.json +4 -0
  195. package/kits/skills/ec-agent-create/SKILL.md +3 -0
  196. package/kits/skills/ec-identity/SKILL.md +2 -2
  197. package/kits/skills/ec-service-proxy/SKILL.md +118 -0
  198. package/kits/skills/ec-skill/scripts/skill.mjs +6 -0
  199. package/kits/skills/personal-assistant/SKILL.md +176 -0
  200. package/kits/skills/personal-assistant/references/01-workspace-spec.md +333 -0
  201. package/kits/skills/personal-assistant/references/02-bootstrap.md +205 -0
  202. package/kits/skills/personal-assistant/references/03-data-flow-and-gaps.md +177 -0
  203. package/kits/skills/personal-assistant/references/04-frontend-contract.md +439 -0
  204. package/kits/skills/personal-assistant/references/05-directory-reference.md +292 -0
  205. package/kits/skills/personal-assistant/references/06-render-config.md +350 -0
  206. package/kits/skills/personal-assistant/schema/workspace.schema.json +85 -0
  207. package/kits/skills/personal-assistant/schema/workspace.v1.json +66 -0
  208. package/kits/skills/personal-assistant/scripts/archive.mjs +154 -0
  209. package/kits/skills/personal-assistant/scripts/check.mjs +114 -0
  210. package/kits/skills/personal-assistant/scripts/index-rebuild.mjs +252 -0
  211. package/kits/skills/personal-assistant/scripts/ingest.mjs +344 -0
  212. package/kits/skills/personal-assistant/scripts/init.mjs +270 -0
  213. package/kits/skills/personal-assistant/scripts/lib/apply.mjs +92 -0
  214. package/kits/skills/personal-assistant/scripts/lib/schema.mjs +96 -0
  215. package/kits/skills/personal-assistant/scripts/lib/time.mjs +28 -0
  216. package/kits/skills/personal-assistant/scripts/migrate.mjs +172 -0
  217. package/kits/skills/personal-assistant/scripts/search.mjs +172 -0
  218. package/kits/skills/personal-assistant/scripts/verify.mjs +196 -0
  219. package/kits/skills/personal-assistant/templates/INDEX.md.tpl +24 -0
  220. package/kits/skills/personal-assistant/templates/README.md.tpl +108 -0
  221. package/kits/skills/personal-assistant/triggers/ingest-daily.json +23 -0
  222. package/kits/skills/personal-assistant/triggers/memory-consolidate.json +23 -0
  223. package/kits/skills/personal-assistant/triggers/report-daily.json +23 -0
  224. package/kits/skills/personal-assistant/triggers/report-weekly.json +23 -0
  225. package/kits/skills/thread-ops/SKILL.md +5 -0
  226. package/kits/templates/memory-consolidation/forget.md +19 -6
  227. package/kits/templates/memory-consolidation/notes.md +1 -1
  228. package/kits/templates/memory-consolidation/profile.md +2 -2
  229. package/kits/templates/memory-consolidation/promote.md +20 -3
  230. package/kits/templates/roles/member.json +8 -1
  231. package/kits/templates/system-fragments/baseagent.md +2 -2
  232. package/kits/templates/system-fragments/memory.md +4 -4
  233. package/kits/templates/system-fragments/venue.md +1 -1
  234. package/package.json +7 -3
  235. package/dist/core/message/create-status.js +0 -96
@@ -1,20 +1,163 @@
1
1
  import fs from 'node:fs';
2
2
  import { ownerResolver } from '../ownership/owner-resolver.js';
3
3
  import { agentFullAccessStatus, agentFullAccessWriteError } from '../role/runtime-policy.js';
4
- import { initializationSummary, validateInitializationModelArgs } from '../../cli/agent-create.js';
4
+ import { hasOrphanedInitializationMarker, initializationSummary, readInitialization, validateInitializationModelArgs } from '../../cli/agent-create.js';
5
5
  import { agentDelete, agentEnable, agentDisable, agentList, agentShow, agentSet, agentReload, } from '../../cli/agent.js';
6
6
  import { agentCreateNonInteractive } from '../../cli/agent-create.js';
7
7
  import { logger } from '../../utils/logger.js';
8
8
  import { resolvePaths, resolveRoot } from '../../paths.js';
9
9
  import path from 'path';
10
- import { ConfigTarget, ensureFile as cfgEnsure, read as cfgRead, write as cfgWrite, } from '../../config/config-manager.js';
11
- import { CreateStatusWriter, readCreateStatus } from '../message/create-status.js';
10
+ import { ConfigTarget, assertAgentAidAvailable, ensureFile as cfgEnsure, read as cfgRead, write as cfgWrite, } from '../../config/config-manager.js';
11
+ import { CreateStatusWriter, initializationCreateProgress, initializationOwnership, readCreateStatus } from '../agent-create-status.js';
12
12
  import { agentProjectRootFromDefaults, deriveAgentProjectPath } from '../../utils/project-path.js';
13
13
  import { uploadAvatar, uploadAvatarUrl } from '../../utils/avatar-upload.js';
14
14
  import { agentmdGet, agentmdPut, updateAgentMdFrontmatterName } from '../../aun/aid/agentmd.js';
15
15
  import { isValidAid } from '../../aun/aid/validation.js';
16
16
  import { isSupportedBaseagent } from '../../agents/baseagent.js';
17
17
  import { resolveProviderServiceForBaseagent } from '../../config/providers.js';
18
+ import { claimAgentCreationAsync, removeAgentCreationClaim } from '../agent-creation-claim.js';
19
+ /** Enabled by default; an explicit 0 retains the host-scoped rollback switch. */
20
+ export function appOneShotCreateEnabled(env = process.env) {
21
+ return env.EVOLCORE_APP_ONE_SHOT_CREATE !== '0';
22
+ }
23
+ export function agentCreateCapabilities(env = process.env) {
24
+ return {
25
+ legacy: true, oneShot: appOneShotCreateEnabled(env), protocolVersion: 1,
26
+ resume: true, cancel: true, exactOwnershipBinding: true, activeReadyProjection: true,
27
+ };
28
+ }
29
+ const UUID_V4 = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
30
+ function initializationError(error) {
31
+ return { error: error instanceof Error ? error.message : String(error), code: error?.code || 'INITIALIZE_FAILED' };
32
+ }
33
+ /** Compatibility receipt and query fields are always projected from the journal. */
34
+ export function oneShotCreationView(aid, lifecycle, state) {
35
+ const record = readInitialization(aid);
36
+ if (record?.mode !== 'one_shot')
37
+ return undefined;
38
+ const config = cfgRead(ConfigTarget.Agent, { self: aid });
39
+ const progress = initializationCreateProgress(record, lifecycle, config?.initialization?.operationId);
40
+ const summary = initializationSummary(aid);
41
+ const complete = progress?.status === 'ready';
42
+ return {
43
+ mode: 'one_shot', creationId: record.creationId, operationId: record.operationId,
44
+ clientRequestId: record.clientRequestId, lifecycle: lifecycle ?? null,
45
+ initialization: { ...summary, complete, ownerAid: record.plan.ownerAid,
46
+ retryable: progress?.retryable ?? false, nextStep: progress?.nextStep ?? null },
47
+ createProgress: progress, ownership: initializationOwnership(record),
48
+ usable: complete && state?.usable === true,
49
+ ...(record.plan.avatarUrl || record.plan.avatarFile ? { avatarAccepted: true } : {}),
50
+ ...(progress?.code ? { code: progress.code } : {}),
51
+ ...(progress?.error ? { error: progress.error } : {}),
52
+ };
53
+ }
54
+ async function execOneShotCreate(a, peerId, service, subject) {
55
+ if (!service?.initialization)
56
+ return { error: '初始化服务不可用', code: 'NOT_CONFIGURED' };
57
+ if (!peerId || !isValidAid(peerId))
58
+ return { error: '缺少有效发起者 AID', code: 'INVALID_ARGS' };
59
+ if (subject && !subject.isDaemonOwner && subject.processRole !== 'daemon-service') {
60
+ return { error: '一步创建需要 DaemonOwner', code: 'NOT_ALLOWED' };
61
+ }
62
+ if (a.protocolVersion !== 1)
63
+ return { error: '不支持的一步创建协议版本', code: 'INITIALIZE_PROTOCOL_UNSUPPORTED' };
64
+ if (a.dryRun !== undefined)
65
+ return { error: '一步创建兼容入口不接受 dryRun', code: 'INVALID_ARGS' };
66
+ if (typeof a.aid !== 'string' || !isValidAid(a.aid))
67
+ return { error: '无效 Agent AID', code: 'INVALID_ARGS' };
68
+ for (const field of ['resume', 'cancel']) {
69
+ if (a[field] !== undefined && typeof a[field] !== 'boolean')
70
+ return { error: `${field} 必须是布尔值`, code: 'INVALID_ARGS' };
71
+ }
72
+ if (a.resume === true && a.cancel === true)
73
+ return { error: 'resume 与 cancel 不能同时指定', code: 'INVALID_ARGS' };
74
+ const control = a.resume === true || a.cancel === true;
75
+ if (a.clientRequestId !== undefined
76
+ && (typeof a.clientRequestId !== 'string' || !UUID_V4.test(a.clientRequestId))) {
77
+ return { error: 'clientRequestId 必须是 UUID-v4', code: 'INVALID_ARGS' };
78
+ }
79
+ if (!control && a.clientRequestId === undefined) {
80
+ return { error: 'clientRequestId 必须是 UUID-v4', code: 'INVALID_ARGS' };
81
+ }
82
+ try {
83
+ const existing = readInitialization(a.aid);
84
+ if (control) {
85
+ if (Object.keys(a).some(key => !['aid', 'initialize', 'protocolVersion', 'clientRequestId', 'resume', 'cancel', 'context'].includes(key))) {
86
+ return { error: '恢复或取消不能携带新的初始化计划', code: 'INVALID_ARGS' };
87
+ }
88
+ if (a.clientRequestId === undefined) {
89
+ return { error: '恢复或取消需要原 clientRequestId', code: 'INITIALIZE_REQUEST_ID_REQUIRED' };
90
+ }
91
+ if (!existing)
92
+ return { error: '未找到初始化操作', code: 'NOT_FOUND' };
93
+ if (existing.mode !== 'one_shot' || existing.actor !== peerId
94
+ || existing.clientRequestId !== a.clientRequestId) {
95
+ return { error: '初始化操作与本次请求不匹配', code: 'INITIALIZE_PLAN_CONFLICT' };
96
+ }
97
+ if (a.cancel === true)
98
+ await service.initialization.cancel(a.aid, peerId);
99
+ else
100
+ service.initialization.resume(a.aid, peerId, a.clientRequestId);
101
+ }
102
+ else {
103
+ // The kill switch blocks new attempts, never recovery of accepted attempts.
104
+ if (!existing && !appOneShotCreateEnabled())
105
+ return { error: '主机尚未启用一步创建', code: 'INITIALIZE_DISABLED' };
106
+ for (const field of ['name', 'baseagent', 'project', 'owner', 'description', 'provider', 'model', 'effort', 'persona', 'avatarUrl']) {
107
+ if (a[field] !== undefined && typeof a[field] !== 'string')
108
+ return { error: `${field} 必须是字符串`, code: 'INVALID_ARGS' };
109
+ }
110
+ if (a.tags !== undefined && (!Array.isArray(a.tags) || a.tags.some((tag) => typeof tag !== 'string'))) {
111
+ return { error: 'tags 必须是字符串数组', code: 'INVALID_ARGS' };
112
+ }
113
+ if (a.type !== undefined && a.type !== 'agent')
114
+ return { error: 'type 必须为 agent', code: 'INVALID_ARGS' };
115
+ if (a.plan !== undefined || a.owners !== undefined || a.ownerAid !== undefined || a.avatarFile !== undefined || a.force !== undefined) {
116
+ return { error: '一步创建兼容入口不接受 plan/owners/ownerAid/avatarFile/force', code: 'INVALID_ARGS' };
117
+ }
118
+ if (a.chatmode !== undefined && (!a.chatmode || typeof a.chatmode !== 'object' || Array.isArray(a.chatmode)
119
+ || Object.entries(a.chatmode).some(([key, value]) => !['private', 'group', 'nothuman'].includes(key) || !['interactive', 'proactive'].includes(value)))) {
120
+ return { error: 'chatmode 必须包含有效的 private/group/nothuman 模式', code: 'INVALID_ARGS' };
121
+ }
122
+ let avatarUrl;
123
+ if (a.avatarUrl !== undefined) {
124
+ try {
125
+ const url = new URL(a.avatarUrl.trim());
126
+ if (url.protocol !== 'https:' || url.username || url.password || (url.port && url.port !== '443'))
127
+ throw new Error();
128
+ avatarUrl = url.toString();
129
+ }
130
+ catch {
131
+ return { error: 'avatarUrl 必须是不含认证信息的 HTTPS URL', code: 'INVALID_ARGS' };
132
+ }
133
+ }
134
+ const effort = a.effort?.trim();
135
+ const plan = {
136
+ aid: a.aid, project: a.project ?? '', baseagent: a.baseagent?.trim() ?? '',
137
+ ownerAid: a.owner?.trim() || peerId.trim(), name: a.name?.trim() ?? '',
138
+ description: a.description?.trim() || 'EvolCore AI agent.', tags: a.tags ?? [], type: 'agent',
139
+ ...(a.provider?.trim() ? { provider: a.provider.trim() } : {}),
140
+ ...(a.model?.trim() ? { model: a.model.trim() } : {}),
141
+ ...(effort && effort !== 'auto' ? { effort } : {}),
142
+ ...(a.chatmode !== undefined ? { chatmode: a.chatmode } : {}),
143
+ ...(a.persona !== undefined ? { persona: a.persona } : {}),
144
+ ...(avatarUrl ? { avatarUrl } : {}),
145
+ };
146
+ if (!existing) {
147
+ const modelError = await validateInitializationModelArgs(plan);
148
+ if (modelError)
149
+ return modelError;
150
+ }
151
+ service.initialization.startOneShot(plan, peerId, a.clientRequestId);
152
+ }
153
+ const state = service.initialization.status(a.aid);
154
+ const lifecycle = state.lifecycle ?? service.readConfig(a.aid)?.lifecycle;
155
+ return { data: { ...state, ...oneShotCreationView(a.aid, lifecycle, state), accepted: true, aid: a.aid } };
156
+ }
157
+ catch (error) {
158
+ return initializationError(error);
159
+ }
160
+ }
18
161
  const SUPPORTED_AGENT_PATCH_FIELDS = new Set(['aid', 'name', 'avatar', 'active_baseagent', 'baseagents', 'projects', 'owner', 'owners', 'fullaccess', 'chatmode', 'channels', 'channelOwners']);
19
162
  const HIDDEN_VALUE = '[hidden]';
20
163
  const SENSITIVE_CONFIG_KEYS = new Set([
@@ -90,6 +233,12 @@ export async function execAidAvatar(args) {
90
233
  };
91
234
  }
92
235
  async function updateAgentMdName(aid, value) {
236
+ try {
237
+ assertAgentAidAvailable(aid);
238
+ }
239
+ catch (error) {
240
+ return { ok: false, code: 'CONTROL_AID_RESERVED', error: error.message };
241
+ }
93
242
  const name = typeof value === 'string' ? value.trim() : '';
94
243
  if (!name)
95
244
  return { ok: false, error: 'name 不能为空', code: 'INVALID_ARGS' };
@@ -356,6 +505,9 @@ function buildCreateProgressOnlyAgent(aid, progress) {
356
505
  };
357
506
  }
358
507
  function failedCreateRetryAllowed(aid, agentDir, service) {
508
+ if (hasOrphanedInitializationMarker(aid)) {
509
+ return { allowed: false, force: false, error: '初始化状态无效,拒绝覆盖', code: 'INITIALIZE_STATE_INVALID' };
510
+ }
359
511
  const progress = readCreateStatus(agentDir);
360
512
  if ((!progress && fs.existsSync(path.join(agentDir, 'create-status.json')))
361
513
  || (progress && (!Array.isArray(progress.steps)
@@ -430,6 +582,7 @@ async function runCreateInBackground(opts, w, service) {
430
582
  // onPhase 把 agentCreateNonInteractive 内部环节(0-3、5)映射到进度文件
431
583
  const createOptions = {
432
584
  aid: opts.aid, name: opts.name, baseagent: opts.baseagent,
585
+ creationId: opts.creationId,
433
586
  project: opts.project, owner: opts.owner,
434
587
  description: opts.description,
435
588
  tags: opts.tags,
@@ -447,7 +600,7 @@ async function runCreateInBackground(opts, w, service) {
447
600
  else if (state === 'warn')
448
601
  w.warn(phase, detail);
449
602
  else if (state === 'failed')
450
- w.finishFailed(phase, detail ?? 'failed');
603
+ curPhase = phase;
451
604
  },
452
605
  };
453
606
  const res = service
@@ -456,14 +609,14 @@ async function runCreateInBackground(opts, w, service) {
456
609
  if (!('ok' in res) || res.ok !== true) {
457
610
  // Service adapters may return a failure without emitting an onPhase callback.
458
611
  const err = String(res.error || 'Agent creation failed');
459
- w.finishFailed(curPhase, err);
612
+ await w.finishFailed(curPhase, err);
460
613
  logger.warn(`[agent-control] create ${opts.aid} failed: ${err}`);
461
614
  return;
462
615
  }
463
616
  if (res.aidCreated && res.ownershipBinding)
464
617
  w.setOwnershipBinding(res.ownershipBinding);
465
618
  // 环节 4:applying_config(provider/model/effort/chatmode,agentCreateNonInteractive 之外)
466
- if (opts.provider || opts.providerServiceType || opts.model || opts.effort || opts.chatmode) {
619
+ if (opts.provider || opts.model || opts.effort || opts.chatmode) {
467
620
  curPhase = 'applying_config';
468
621
  w.begin('applying_config');
469
622
  let warned;
@@ -478,7 +631,6 @@ async function runCreateInBackground(opts, w, service) {
478
631
  baseagents[opts.baseagent] = {
479
632
  ...current,
480
633
  provider: opts.provider,
481
- ...(opts.providerServiceType ? { providerServiceType: opts.providerServiceType } : {}),
482
634
  ...(opts.model ? { model: opts.model } : {}),
483
635
  ...(opts.effort ? { effort: opts.effort } : {}),
484
636
  };
@@ -519,7 +671,7 @@ async function runCreateInBackground(opts, w, service) {
519
671
  else
520
672
  w.done('applying_config');
521
673
  }
522
- w.finishReady();
674
+ await w.finishReady();
523
675
  opts.eventBus?.publish({
524
676
  type: 'agent:created',
525
677
  aid: opts.aid,
@@ -534,7 +686,7 @@ async function runCreateInBackground(opts, w, service) {
534
686
  catch (e) {
535
687
  const msg = e?.message || String(e);
536
688
  logger.warn(`[agent-control] create ${opts.aid} threw at ${curPhase}: ${msg}`);
537
- w.finishFailed(curPhase, msg); // 兜底终态,标注真实失败环节
689
+ await w.finishFailed(curPhase, msg); // 兜底终态,标注真实失败环节
538
690
  opts.eventBus?.publish({ type: 'agent:error', aid: opts.aid, action: 'create', error: msg, timestamp: Date.now() });
539
691
  }
540
692
  }
@@ -543,6 +695,15 @@ async function runCreateInBackground(opts, w, service) {
543
695
  * 调用方负责传入已兜底的 args.project(见 command-handler 装配)。 */
544
696
  export async function execAgentAction(action, args, peerId, eventBus, service, subject) {
545
697
  const a = args ?? {};
698
+ if (action === 'create') {
699
+ if (a.initialize !== undefined && typeof a.initialize !== 'boolean')
700
+ return { error: 'initialize 必须是布尔值', code: 'INVALID_ARGS' };
701
+ if (a.initialize === true)
702
+ return execOneShotCreate(a, peerId, service, subject);
703
+ if (['protocolVersion', 'clientRequestId', 'resume', 'cancel'].some(key => a[key] !== undefined)) {
704
+ return { error: '一步创建字段必须同时指定 initialize:true', code: 'INVALID_ARGS' };
705
+ }
706
+ }
546
707
  if (action === 'initialize') {
547
708
  if (!service?.initialization)
548
709
  return { error: '初始化服务不可用', code: 'NOT_CONFIGURED' };
@@ -555,11 +716,13 @@ export async function execAgentAction(action, args, peerId, eventBus, service, s
555
716
  const aid = typeof a.aid === 'string' ? a.aid.trim() : '';
556
717
  if (!aid || !isValidAid(aid))
557
718
  return { error: 'resume 需要有效的 aid', code: 'INVALID_ARGS' };
558
- if (Object.keys(a).some(key => !['aid', 'resume', 'context'].includes(key))) {
719
+ if (Object.keys(a).some(key => !['aid', 'resume', 'clientRequestId', 'context'].includes(key))) {
559
720
  return { error: '恢复请求不能携带新的初始化计划', code: 'INVALID_ARGS' };
560
721
  }
561
722
  try {
562
- return { data: service.initialization.resume(aid, peerId) };
723
+ return { data: a.clientRequestId === undefined
724
+ ? service.initialization.resume(aid, peerId)
725
+ : service.initialization.resume(aid, peerId, a.clientRequestId) };
563
726
  }
564
727
  catch (error) {
565
728
  return { error: error instanceof Error ? error.message : String(error), code: error.code || 'INITIALIZE_FAILED' };
@@ -632,6 +795,21 @@ export async function execAgentAction(action, args, peerId, eventBus, service, s
632
795
  }
633
796
  if (typeof a.aid !== 'string' || !isValidAid(a.aid))
634
797
  return { error: '无效 Agent AID', code: 'INVALID_ARGS' };
798
+ try {
799
+ assertAgentAidAvailable(a.aid);
800
+ }
801
+ catch (error) {
802
+ return { code: 'CONTROL_AID_RESERVED', error: error.message };
803
+ }
804
+ try {
805
+ if (readInitialization(a.aid))
806
+ return { error: '已有初始化记录,请恢复原操作', code: 'INITIALIZE_PLAN_CONFLICT' };
807
+ }
808
+ catch (error) {
809
+ return initializationError(error);
810
+ }
811
+ if (hasOrphanedInitializationMarker(a.aid))
812
+ return { error: '初始化状态无效,拒绝覆盖', code: 'INITIALIZE_STATE_INVALID' };
635
813
  const owner = typeof a.owner === 'string' && a.owner.trim() ? a.owner.trim() : peerId.trim();
636
814
  if (!owner)
637
815
  return { error: '缺少 owner AID', code: 'INVALID_ARGS' };
@@ -644,12 +822,9 @@ export async function execAgentAction(action, args, peerId, eventBus, service, s
644
822
  if (a.provider !== undefined && typeof a.provider !== 'string')
645
823
  return { error: 'provider 必须是字符串', code: 'INVALID_ARGS' };
646
824
  const provider = typeof a.provider === 'string' && a.provider.trim() ? a.provider.trim() : undefined;
647
- if (a.providerServiceType !== undefined && typeof a.providerServiceType !== 'string')
648
- return { error: 'providerServiceType 必须是字符串', code: 'INVALID_ARGS' };
649
- const providerServiceType = typeof a.providerServiceType === 'string' && a.providerServiceType.trim() ? a.providerServiceType.trim() : undefined;
650
825
  if (provider) {
651
826
  try {
652
- const resolved = resolveProviderServiceForBaseagent(provider, a.baseagent, providerServiceType);
827
+ const resolved = resolveProviderServiceForBaseagent(provider, a.baseagent);
653
828
  if (model && resolved.modelOverrides[model]?.enabled === false)
654
829
  throw new Error(`Model ${model} is disabled for provider ${provider}`);
655
830
  }
@@ -681,20 +856,43 @@ export async function execAgentAction(action, args, peerId, eventBus, service, s
681
856
  const agentDir = path.join(resolvePaths().agentsDir, a.aid);
682
857
  const retry = failedCreateRetryAllowed(a.aid, agentDir, service);
683
858
  if (!retry.allowed)
684
- return { error: retry.error || 'Agent 已存在', code: 'CONFLICT' };
859
+ return { error: retry.error || 'Agent 已存在', code: retry.code || 'CONFLICT' };
860
+ // Claim the AID in the shared admission sidecar immediately before the
861
+ // legacy progress marker is created. The one-shot initializer uses the
862
+ // same gate, so its journal cannot race this older path between check and
863
+ // marker publication.
864
+ let claim;
865
+ try {
866
+ const existingProgress = readCreateStatus(agentDir);
867
+ claim = await claimAgentCreationAsync({
868
+ aid: a.aid,
869
+ mode: 'legacy',
870
+ creationId: existingProgress?.creationId,
871
+ requesterAid: peerId,
872
+ ownerAid: owner,
873
+ }, { recoverOrphanedLegacy: true });
874
+ }
875
+ catch (error) {
876
+ return initializationError(error);
877
+ }
878
+ if (!claim.claimed) {
879
+ return { error: '该 Agent 正在创建或已有其他创建操作', code: 'INITIALIZE_PLAN_CONFLICT' };
880
+ }
685
881
  // D3: accepted=true 必须意味着后续 query 能查到该 AID 的创建状态。
686
882
  let progressWriter;
687
883
  try {
688
- progressWriter = new CreateStatusWriter(agentDir, a.aid, { requesterAid: peerId, ownerAid: owner });
884
+ progressWriter = new CreateStatusWriter(agentDir, a.aid, { requesterAid: peerId, ownerAid: owner, creationId: claim.claim.creationId });
689
885
  }
690
886
  catch (e) {
887
+ if (claim.claimed)
888
+ await removeAgentCreationClaim(a.aid, claim.claim.creationId);
691
889
  return { error: `创建进度状态初始化失败: ${e?.message || e}`, code: 'INTERNAL' };
692
890
  }
693
891
  // 重副作用转后台,后台内部有 try/catch;这里 catch 只兜底未预期拒绝。
694
892
  void runCreateInBackground({
695
- aid: a.aid, name: a.name, baseagent: a.baseagent,
893
+ aid: a.aid, name: a.name, baseagent: a.baseagent, creationId: claim.claim.creationId,
696
894
  project: a.project, owner,
697
- provider, providerServiceType, model, effort, description, tags, chatmode: a.chatmode, avatarUrl,
895
+ provider, model, effort, description, tags, chatmode: a.chatmode, avatarUrl,
698
896
  retryFailedCreate: retry.force,
699
897
  eventBus,
700
898
  }, progressWriter, service).catch(e => logger.error(`[agent-control] runCreateInBackground unhandled ${a.aid}: ${e?.message || e}`));
@@ -922,15 +1120,37 @@ export async function execAgentQuery(args, service, subject) {
922
1120
  const aid = args?.aid;
923
1121
  if (!aid)
924
1122
  return { error: '缺少 aid', code: 'INVALID_ARGS' };
1123
+ if (typeof aid !== 'string' || !isValidAid(aid))
1124
+ return { error: '无效 Agent AID', code: 'INVALID_ARGS' };
925
1125
  const agentDir = path.join(resolvePaths().agentsDir, aid);
926
- const progress = readCreateStatus(agentDir);
927
1126
  const initialization = initializationSummary(aid);
1127
+ if (initialization?.code === 'INITIALIZE_STATE_INVALID') {
1128
+ return { data: {
1129
+ aid, lifecycle: service?.readConfig(aid)?.lifecycle ?? null,
1130
+ usable: false, initialization,
1131
+ } };
1132
+ }
1133
+ let oneShot;
1134
+ try {
1135
+ const record = readInitialization(aid);
1136
+ if (args?.clientRequestId !== undefined && (!record || record.clientRequestId !== args.clientRequestId
1137
+ || (subject?.actorId && record.actor !== subject.actorId))) {
1138
+ return { error: '未找到本次初始化操作', code: 'NOT_FOUND' };
1139
+ }
1140
+ oneShot = oneShotCreationView(aid, service?.readConfig(aid)?.lifecycle);
1141
+ }
1142
+ catch (error) {
1143
+ return initializationError(error);
1144
+ }
1145
+ const progress = oneShot?.createProgress ?? readCreateStatus(agentDir);
928
1146
  let usable;
929
1147
  if (initialization && service?.initialization) {
930
1148
  try {
931
1149
  const state = service.initialization.status(aid);
932
1150
  if (typeof state.usable === 'boolean')
933
1151
  usable = state.usable;
1152
+ if (oneShot)
1153
+ oneShot = oneShotCreationView(aid, state.lifecycle, state);
934
1154
  }
935
1155
  catch {
936
1156
  usable = false;
@@ -948,6 +1168,7 @@ export async function execAgentQuery(args, service, subject) {
948
1168
  lifecycle: service?.readConfig(aid)?.lifecycle ?? null,
949
1169
  initialization,
950
1170
  ...(usable === undefined ? {} : { usable }),
1171
+ ...(oneShot ?? {}),
951
1172
  },
952
1173
  };
953
1174
  if (code === 'NOT_FOUND' && progress)
@@ -982,6 +1203,7 @@ export async function execAgentQuery(args, service, subject) {
982
1203
  ...fullaccessStatus,
983
1204
  canConfigure: agentFullAccessWriteError(aid, subject) === undefined,
984
1205
  },
1206
+ ...(oneShot ? oneShotCreationView(aid, res.lifecycle ?? config?.lifecycle, { usable: usable === true }) : {}),
985
1207
  };
986
1208
  // 叠加构建进度(create 受理后、ready 前可见;ready 后文件仍在,可反映软失败 warn)
987
1209
  return { data: progress ? { ...data, createProgress: progress } : data };
@@ -1005,8 +1227,25 @@ export async function execAgentOptions(args, service) {
1005
1227
  : await agentList();
1006
1228
  if (!('ok' in res) || res.ok !== true)
1007
1229
  return { error: res.error, code: classifyError(res.error) };
1008
- const agents = scope === 'all'
1230
+ const listed = scope === 'all'
1009
1231
  ? res.agents
1010
1232
  : res.agents.filter((x) => x.status !== 'disabled');
1233
+ let agents;
1234
+ try {
1235
+ agents = listed.map((agent) => {
1236
+ const initialization = oneShotCreationView(agent.aid, agent.lifecycle);
1237
+ return initialization ? {
1238
+ ...agent,
1239
+ mode: initialization.mode,
1240
+ lifecycle: initialization.lifecycle,
1241
+ initialization: initialization.initialization,
1242
+ createProgress: initialization.createProgress,
1243
+ ownership: initialization.ownership,
1244
+ } : agent;
1245
+ });
1246
+ }
1247
+ catch (error) {
1248
+ return initializationError(error);
1249
+ }
1011
1250
  return { data: { agents, scope } };
1012
1251
  }
@@ -1,6 +1,6 @@
1
1
  import crypto from 'node:crypto';
2
2
  import { isValidAid } from '../../aun/aid/validation.js';
3
- import { isExplicitGroupId } from '../../aun/group/index.js';
3
+ import { readAunPeerKind } from '../relation/peer-identity.js';
4
4
  import { listStaticAgentOwners } from '../../config/peer-role-resolver.js';
5
5
  import { authorizeOperation } from '../auth/auth-gateway.js';
6
6
  import { auditCommandAuthorization } from '../auth/authorization-audit.js';
@@ -93,8 +93,10 @@ export class AgentStorageMenuService {
93
93
  }
94
94
  if (!subject.menuEncrypted)
95
95
  fail('MENU_TOKEN_ENCRYPTION_REQUIRED', 'Agent storage Menu requests require E2EE');
96
- if (!isValidAid(targetAid) || isExplicitGroupId(targetAid)
97
- || !isValidAid(subject.principalId ?? '') || isExplicitGroupId(subject.principalId ?? '')
96
+ if (!isValidAid(targetAid)
97
+ || !isValidAid(subject.principalId ?? '')
98
+ || readAunPeerKind(targetAid, subject.principalId, { routeKind: 'private' }).kind !== 'private'
99
+ || readAunPeerKind(targetAid, targetAid, { routeKind: 'private' }).kind !== 'private'
98
100
  || subject.role !== 'owner' || !this.isOwner(targetAid, subject.principalId)) {
99
101
  fail('ROOT_FORBIDDEN', 'Agent cloud storage requires the static Agent owner');
100
102
  }
@@ -3,7 +3,8 @@ import { parseOwnershipCommand } from '../../aun/aid/ownership-operation.js';
3
3
  import { normalizeCliArgv } from '../../cli/cli-argv.js';
4
4
  import { resolveConfigCommand, } from '../../config/resolved-config-op.js';
5
5
  export { normalizeCliArgv, parseLegacyCliCommand, validateCliArgv } from '../../cli/cli-argv.js';
6
- const MODEL_RELATION_DEFAULT_SUBCOMMANDS = new Set(['list', 'current', 'info', 'use', 'effort', 'reset']);
6
+ // 只读 model 子命令默认补 --peer(按对端关系查模型生效值);写操作(use/effort/reset)只在 Agent 级,不补 --peer。
7
+ const MODEL_RELATION_DEFAULT_SUBCOMMANDS = new Set(['list', 'current', 'info', 'check']);
7
8
  export function withDefaultRelationContext(inputArgv, defaults) {
8
9
  const argv = normalizeCliArgv(inputArgv);
9
10
  const isModelCommand = argv[0] === 'model' && MODEL_RELATION_DEFAULT_SUBCOMMANDS.has(argv[1] || '');
@@ -239,15 +240,19 @@ function parseAgentCommand(argv, source) {
239
240
  }
240
241
  function parseAidCommand(argv, source, defaultSelfAid) {
241
242
  const subcmd = argv[1];
242
- if (subcmd === 'bind') {
243
+ if (subcmd === 'bind' || subcmd === 'transfer') {
243
244
  try {
244
245
  const command = parseOwnershipCommand(argv.slice(1));
245
246
  const subjectAid = command.subjectAid ?? defaultSelfAid;
246
247
  const isMutation = command.action !== 'status';
247
- return recognized(isMutation ? 'ec.aid.bind' : 'ec.aid.bind.status', 'agent', source, {
248
+ const operation = command.action === 'transfer' ? 'ec.aid.transfer'
249
+ : isMutation ? 'ec.aid.bind' : 'ec.aid.bind.status';
250
+ return recognized(operation, 'agent', source, {
248
251
  ...(subjectAid ? { self: subjectAid } : {}),
249
252
  ...(command.subjectAid ? { subjectAid: command.subjectAid } : {}),
253
+ ...(command.action === 'status' && command.refresh ? { refresh: true } : {}),
250
254
  ...(command.action === 'bind' ? { ownerAid: command.ownerAid } : {}),
255
+ ...(command.action === 'transfer' ? { subAid: command.subAid, newOwnerAid: command.newOwnerAid } : {}),
251
256
  ...(command.action === 'accept' || command.action === 'reject'
252
257
  ? { decision: command.action, operationId: command.operationId } : {}),
253
258
  }, argv, isMutation);