evolcore 0.0.41 → 0.0.42

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 (190) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/bin/codex-managed-hook.mjs +9 -5
  3. package/dist/agents/baseagent.js +156 -16
  4. package/dist/agents/claude-runner.js +10 -3
  5. package/dist/agents/codex/catalog.js +8 -4
  6. package/dist/agents/codex-runner.js +236 -59
  7. package/dist/agents/ecagent-runner.js +82 -13
  8. package/dist/aun/aid/agentmd.js +106 -27
  9. package/dist/aun/aid/client.js +1 -1
  10. package/dist/aun/aid/control-aid.js +65 -13
  11. package/dist/aun/aid/identity.js +70 -4
  12. package/dist/aun/aid/index.js +2 -2
  13. package/dist/aun/service-proxy.js +25 -1
  14. package/dist/channels/aun.js +242 -209
  15. package/dist/channels/dingtalk.js +1 -1
  16. package/dist/channels/feishu.js +1 -1
  17. package/dist/channels/qqbot.js +1 -1
  18. package/dist/channels/wechat.js +1 -1
  19. package/dist/channels/wecom.js +1 -1
  20. package/dist/cli/agent-command.js +183 -3
  21. package/dist/cli/agent-create.js +92 -86
  22. package/dist/cli/agent.js +136 -1
  23. package/dist/cli/aun-commands.js +137 -35
  24. package/dist/cli/bench.js +8 -2
  25. package/dist/cli/command-log.js +1 -1
  26. package/dist/cli/daemon-commands.js +235 -51
  27. package/dist/cli/debug-mode.js +1 -1
  28. package/dist/cli/directory.js +170 -0
  29. package/dist/cli/index.js +40 -30
  30. package/dist/cli/init-channel.js +4 -4
  31. package/dist/cli/init.js +47 -32
  32. package/dist/cli/managed-command-guard.js +4 -1
  33. package/dist/cli/model.js +27 -18
  34. package/dist/cli/pa-workspace-command.js +191 -0
  35. package/dist/cli/{contact.js → peer.js} +19 -25
  36. package/dist/cli/restart-monitor.js +11 -4
  37. package/dist/cli/thread-command.js +47 -18
  38. package/dist/cli/version.js +18 -18
  39. package/dist/config/access-policy.js +29 -12
  40. package/dist/config/boot-log.js +65 -10
  41. package/dist/config/builtin-roles.js +2 -4
  42. package/dist/config/config-field-policy.js +3 -0
  43. package/dist/config/config-manager.js +28 -20
  44. package/dist/config/{contact-bind-code.js → peer-bind-code.js} +6 -6
  45. package/dist/config/{contact-book-store.js → peer-book-store.js} +75 -75
  46. package/dist/config/{contact-book-v2-startup.js → peer-book-v2-startup.js} +2 -2
  47. package/dist/config/{contact-book.js → peer-book.js} +47 -47
  48. package/dist/config/peer-operation-service.js +132 -0
  49. package/dist/config/{contact-request-service.js → peer-request-service.js} +90 -90
  50. package/dist/config/peer-role-resolver.js +3 -3
  51. package/dist/config/providers-config.js +17 -8
  52. package/dist/config/providers.js +1 -1
  53. package/dist/config/schema-migration.js +336 -39
  54. package/dist/core/agent-application-service.js +8 -2
  55. package/dist/core/agent-create-status.js +4 -5
  56. package/dist/core/agent-ipc-registration.js +5 -4
  57. package/dist/core/agent-runtime.js +30 -17
  58. package/dist/core/auth/operation-authorizer.js +0 -24
  59. package/dist/core/auth/operation-catalog.js +4 -20
  60. package/dist/core/baseagent-loader.js +27 -3
  61. package/dist/core/bootstrap-service.js +5 -22
  62. package/dist/core/capability/capability-manager.js +52 -35
  63. package/dist/core/channel-loader.js +43 -2
  64. package/dist/core/channel-runtime.js +2 -2
  65. package/dist/core/command/agent-control.js +54 -18
  66. package/dist/core/command/command-handler.js +92 -72
  67. package/dist/core/command/connect-menu.js +35 -42
  68. package/dist/core/command/daemon-diagnostics.js +41 -5
  69. package/dist/core/command/data-root-error.js +10 -0
  70. package/dist/core/command/data-root-resolver.js +53 -13
  71. package/dist/core/command/menu-catalog.js +1 -0
  72. package/dist/core/command/menu-handler.js +163 -65
  73. package/dist/core/command/menu-protocol.js +52 -0
  74. package/dist/core/command/pa-workspace-calendar.js +223 -0
  75. package/dist/core/command/pa-workspace-store.js +459 -0
  76. package/dist/core/command/role-menu.js +2 -2
  77. package/dist/core/command/slash-gate.js +1 -1
  78. package/dist/core/command/slash-handler.js +57 -41
  79. package/dist/core/daemon-lifecycle.js +90 -31
  80. package/dist/core/evolagent.js +6 -10
  81. package/dist/core/handoff/runtime.js +11 -4
  82. package/dist/core/host-snapshot.js +208 -0
  83. package/dist/core/initialization/service.js +152 -20
  84. package/dist/core/ipc-registration.js +33 -4
  85. package/dist/core/memory/batch-meta.js +27 -0
  86. package/dist/core/memory/consolidation-ops-records.js +44 -1
  87. package/dist/core/memory/consolidation.js +169 -27
  88. package/dist/core/message/aun-ipc-sender.js +2 -8
  89. package/dist/core/message/im-renderer.js +56 -3
  90. package/dist/core/message/message-admission.js +121 -124
  91. package/dist/core/message/message-bridge.js +38 -54
  92. package/dist/core/message/message-queue.js +7 -0
  93. package/dist/core/message/outbound.js +34 -9
  94. package/dist/core/message/response-engine.js +154 -73
  95. package/dist/core/model/catalog-service.js +1 -1
  96. package/dist/core/model/config-scope.js +2 -2
  97. package/dist/core/model/model-catalog.js +5 -4
  98. package/dist/core/model/model-diagnostics.js +6 -5
  99. package/dist/core/model/model-fallback.js +3 -6
  100. package/dist/core/model/model-permission.js +1 -1
  101. package/dist/core/ownership/owner-resolver.js +9 -9
  102. package/dist/core/permission/approval-gateway.js +1 -1
  103. package/dist/core/permission/ec-command-parser.js +2 -2
  104. package/dist/core/permission/tool-canonical.js +96 -46
  105. package/dist/core/permission/tool-error-code.js +41 -0
  106. package/dist/core/permission/tool-policy.js +71 -47
  107. package/dist/core/role/runtime-policy.js +1 -1
  108. package/dist/core/session/session-idle-monitor.js +10 -0
  109. package/dist/core/session/session-manager.js +2 -4
  110. package/dist/core/session/session-title.js +36 -8
  111. package/dist/core/system-session/memory.js +2 -7
  112. package/dist/core/thread/command-parser.js +6 -2
  113. package/dist/core/thread/ipc-operation.js +51 -36
  114. package/dist/core/thread/thread-operation.js +29 -61
  115. package/dist/core/thread/thread-service.js +57 -13
  116. package/dist/directory/canonical-digest.js +54 -0
  117. package/dist/directory/owner-directory-admission.js +114 -43
  118. package/dist/directory/owner-directory-agentmd-sync.js +89 -0
  119. package/dist/directory/owner-directory-cache.js +847 -459
  120. package/dist/directory/owner-directory-markdown.js +272 -0
  121. package/dist/directory/owner-directory-query-operation.js +195 -0
  122. package/dist/directory/owner-directory-remark-operation.js +147 -0
  123. package/dist/directory/owner-directory-remarks.js +145 -0
  124. package/dist/directory/owner-directory-scope.js +55 -0
  125. package/dist/directory/owner-directory-search.js +148 -0
  126. package/dist/directory/owner-directory-store.js +227 -0
  127. package/dist/eck/kit-renderer.js +1 -0
  128. package/dist/ecweb/basic-settings-service.js +4 -1
  129. package/dist/ecweb/message-context-service.js +13 -9
  130. package/dist/index.js +195 -37
  131. package/dist/ipc.js +86 -22
  132. package/dist/paths.js +11 -8
  133. package/dist/product.js +2 -0
  134. package/dist/proxy/manager.js +13 -2
  135. package/dist/proxy/service-supervisor.js +8 -1
  136. package/dist/trigger/history.js +23 -0
  137. package/dist/trigger/scheduler.js +3 -0
  138. package/dist/utils/atomic-write.js +21 -0
  139. package/dist/utils/cross-platform.js +35 -0
  140. package/dist/utils/ecweb-supervisor.js +42 -0
  141. package/dist/utils/error-utils.js +2 -1
  142. package/dist/utils/evolcore-version.js +19 -0
  143. package/dist/utils/host-info.js +242 -5
  144. package/dist/utils/instance-registry.js +28 -6
  145. package/dist/utils/logger.js +59 -14
  146. package/dist/utils/machine-info.js +46 -0
  147. package/dist/utils/process-introspect.js +166 -2
  148. package/dist/utils/startup-trace.js +245 -0
  149. package/ecagent/dist/agent-loop.js +27 -13
  150. package/ecagent/dist/harness/agent-harness.js +3 -3
  151. package/ecagent/dist/harness/types.d.ts +1 -0
  152. package/ecagent/dist/types.d.ts +1 -0
  153. package/kits/docs/INDEX.md +1 -1
  154. package/kits/docs/aun/AUN/346/266/210/346/201/257/347/261/273/345/236/213/344/270/216/345/261/236/346/200/247.md +72 -0
  155. package/kits/docs/evolcore/INDEX.md +3 -2
  156. package/kits/docs/evolcore/agent-create.md +17 -27
  157. package/kits/docs/evolcore/agent.md +4 -1
  158. package/kits/docs/evolcore/aid.md +3 -1
  159. package/kits/docs/evolcore/config.md +16 -5
  160. package/kits/docs/evolcore/ctl.md +9 -0
  161. package/kits/docs/evolcore/ec-capabilities.md +19 -0
  162. package/kits/docs/evolcore/memory-consolidation-batches.md +79 -5
  163. package/kits/docs/evolcore/menu-exec-schema-commands.md +2 -1
  164. package/kits/docs/evolcore/menu-protocol.md +1 -0
  165. package/kits/docs/evolcore/model.md +13 -4
  166. package/kits/docs/evolcore/msg.md +1 -1
  167. package/kits/docs/evolcore/pa-workspace.md +51 -0
  168. package/kits/docs/evolcore/peer.md +73 -0
  169. package/kits/docs/evolcore/thread-chain.md +4 -1
  170. package/kits/eck_manifest.json +21 -0
  171. package/kits/rules/06-channel.md +1 -1
  172. package/kits/schemas/_meta.json +12 -1
  173. package/kits/schemas/agent-config.schema.16.json +6 -0
  174. package/kits/schemas/agent-config.schema.17.json +897 -0
  175. package/kits/schemas/daemon.schema.9.json +8 -1
  176. package/kits/skills/ec-agent-create/SKILL.md +2 -2
  177. package/kits/skills/ec-identity/SKILL.md +45 -27
  178. package/kits/skills/ec-service-proxy/SKILL.md +7 -2
  179. package/kits/skills/personal-assistant/references/03-data-flow-and-gaps.md +4 -5
  180. package/kits/skills/thread-ops/SKILL.md +11 -11
  181. package/kits/templates/bootstrap-welcome.md +3 -15
  182. package/kits/templates/message-fragments/item.md +1 -1
  183. package/kits/templates/system-fragments/bootstrap.md +24 -23
  184. package/kits/templates/system-fragments/commands.md +12 -5
  185. package/kits/templates/system-fragments/thread.md +18 -3
  186. package/package.json +6 -4
  187. package/dist/config/contact-operation-service.js +0 -235
  188. package/dist/directory/owner-directory-authorization.js +0 -309
  189. package/kits/docs/evolcore/contact.md +0 -78
  190. /package/dist/config/{contact-alias.js → peer-alias.js} +0 -0
@@ -8,7 +8,7 @@ import { formatItemsAsText } from '../core/message/items-formatter.js';
8
8
  import { createSendFileMarkerPattern } from '../core/message/file-markers.js';
9
9
  import { sentReceipt, suppressedReceipt } from '../core/message/send-receipt.js';
10
10
  import { initWelcomeManager, sendWelcomeIfNeeded } from '../utils/welcome.js';
11
- import { CONTACT_BIND_CODE_TTL_MS, CONTACT_BIND_MAX_FAILED_ATTEMPTS, ContactBindCodeRegistry, handleExplicitContactBindCommand, } from '../config/contact-bind-code.js';
11
+ import { CONTACT_BIND_CODE_TTL_MS, CONTACT_BIND_MAX_FAILED_ATTEMPTS, ContactBindCodeRegistry, handleExplicitContactBindCommand, } from '../config/peer-bind-code.js';
12
12
  import { channelStatePath } from '../paths.js';
13
13
  const DINGTALK_QUEUED_EMOTION = 'Pin';
14
14
  const DINGTALK_THINKING_EMOTION = 'BusinessTrip';
@@ -8,7 +8,7 @@ import { createSendFileMarkerPattern } from '../core/message/file-markers.js';
8
8
  import { initWelcomeManager, sendWelcomeIfNeeded } from '../utils/welcome.js';
9
9
  import { channelStatePath } from '../paths.js';
10
10
  import { sentReceipt, suppressedReceipt } from '../core/message/send-receipt.js';
11
- import { ContactBindCodeRegistry, handleExplicitContactBindCommand, } from '../config/contact-bind-code.js';
11
+ import { ContactBindCodeRegistry, handleExplicitContactBindCommand, } from '../config/peer-bind-code.js';
12
12
  const feishuContactBinds = new ContactBindCodeRegistry({
13
13
  channelType: 'feishu',
14
14
  displayName: '飞书',
@@ -5,7 +5,7 @@ import { middleOutputModePolicy, resolveShowActivities, showActivitiesPolicy } f
5
5
  import { formatItemsAsText } from '../core/message/items-formatter.js';
6
6
  import { createSendFileMarkerPattern } from '../core/message/file-markers.js';
7
7
  import { initWelcomeManager, sendWelcomeIfNeeded } from '../utils/welcome.js';
8
- import { ContactBindCodeRegistry, handleExplicitContactBindCommand, } from '../config/contact-bind-code.js';
8
+ import { ContactBindCodeRegistry, handleExplicitContactBindCommand, } from '../config/peer-bind-code.js';
9
9
  const qqbotContactBinds = new ContactBindCodeRegistry({
10
10
  channelType: 'qqbot',
11
11
  displayName: 'QQ',
@@ -9,7 +9,7 @@ import { DEFAULT_FLUSH_DELAY_SECONDS } from '../types.js';
9
9
  import { formatItemsAsText } from '../core/message/items-formatter.js';
10
10
  import { createSendFileMarkerPattern } from '../core/message/file-markers.js';
11
11
  import { initWelcomeManager, sendWelcomeIfNeeded } from '../utils/welcome.js';
12
- import { ContactBindCodeRegistry, handleExplicitContactBindCommand, } from '../config/contact-bind-code.js';
12
+ import { ContactBindCodeRegistry, handleExplicitContactBindCommand, } from '../config/peer-bind-code.js';
13
13
  const wechatContactBinds = new ContactBindCodeRegistry({
14
14
  channelType: 'wechat',
15
15
  displayName: '微信',
@@ -10,7 +10,7 @@ import { initWelcomeManager, sendWelcomeIfNeeded } from '../utils/welcome.js';
10
10
  import { bufferToInboundImage, sanitizeFileName, saveToUploads, validateUrl } from '../utils/media-cache.js';
11
11
  import { channelStatePath } from '../paths.js';
12
12
  import { atomicReadJson, atomicWriteJson } from '../utils/atomic-write.js';
13
- import { ContactBindCodeRegistry, handleExplicitContactBindCommand, } from '../config/contact-bind-code.js';
13
+ import { ContactBindCodeRegistry, handleExplicitContactBindCommand, } from '../config/peer-bind-code.js';
14
14
  function wecomErrorCode(error) {
15
15
  if (!error || typeof error !== 'object')
16
16
  return undefined;
@@ -87,7 +87,7 @@ function printAgentNewHelp() {
87
87
  --owner <aid> 必填;初始协议 Owner 绑定意图
88
88
  --name <display-name> 初始化必填;Bootstrap 默认取项目名称
89
89
  --description <text> 初始化必填;Bootstrap 默认取项目描述
90
- --tags <json-array> 初始化必填;3 到 6 个标签
90
+ --tags <json-array> 初始化必填;标签 JSON 数组
91
91
  --type <type> 主体类型,默认 agent
92
92
  --avatar-file <path> 头像图片文件(或 attachment:<id>)
93
93
  --avatar-url <https-url> 头像 HTTPS 地址;与 --avatar-file 互斥
@@ -112,7 +112,7 @@ export async function cmdAgent(args) {
112
112
  assertEcSingleLine(args[nameIndex + 1], '--name');
113
113
  }
114
114
  const formatJson = getArgValue(args, '--format') === 'json';
115
- const commands = new Set(['list', 'show', 'new', 'initialize', 'enable', 'disable', 'get', 'set', 'persona', 'welcome', 'rename', 'ready', 'reload', 'delete']);
115
+ const commands = new Set(['list', 'show', 'new', 'initialize', 'enable', 'disable', 'get', 'set', 'persona', 'welcome', 'rename', 'ready', 'reload', 'delete', 'host']);
116
116
  if (sub === 'create') {
117
117
  const error = { ok: false, code: 'INVALID_COMMAND', error: '`ec agent create` is not a command; use `ec agent new`.' };
118
118
  if (formatJson)
@@ -128,6 +128,7 @@ export async function cmdAgent(args) {
128
128
  Commands:
129
129
  list 列出所有 agent
130
130
  show <aid> 查看 agent 详情(身份 + 配置 + 连接 + 会话 + 路径)
131
+ host <aid> 查看 agent 所在主机信息(位置、daemon、硬件、版本)
131
132
  new <aid> ... 创建并激活(默认 --initialize,隐含非交互)
132
133
  new <aid> --bootstrap ... 创建后进入 Bootstrap(隐含非交互)
133
134
  initialize <aid> --resume 恢复一次性初始化
@@ -212,7 +213,8 @@ Options:
212
213
  }
213
214
  const { agentList, agentShow, agentCreateNonInteractive, agentReload, agentEnable, agentDisable, agentGet, agentSet, agentPersona, agentWelcome, agentRename, agentDelete, agentReady, runManagedAgentOperation, } = await import('./agent.js');
214
215
  const { parseAgentOwnerArgs, parseAgentTags, resolveAgentCreatePlan, validateAgentCreatePlan } = await import('./agent-create.js');
215
- if (process.env.EVOLCORE_SESSION_ID && !wantsHelp(args) && !new Set(['get', 'set', 'persona', 'welcome', 'ready']).has(sub)) {
216
+ // host 走 status.auth 授权(与 ec status 同门),不经过 agent.op 的子命令映射。
217
+ if (process.env.EVOLCORE_SESSION_ID && !wantsHelp(args) && !new Set(['get', 'set', 'persona', 'welcome', 'ready', 'host']).has(sub)) {
216
218
  const result = await runManagedAgentOperation(args);
217
219
  if (!result.ok) {
218
220
  if (formatJson)
@@ -887,6 +889,47 @@ Options:
887
889
  printAgentShowHuman(result);
888
890
  return;
889
891
  }
892
+ // --- host ---
893
+ if (sub === 'host') {
894
+ if (wantsHelp(args)) {
895
+ console.log(`用法: ec agent host <aid> [--format json]
896
+
897
+ 查看指定 agent 所在主机的信息,数据全部来自 daemon(唯一出口,CLI 不重复探测):
898
+ - Daemon:AID、PID、启动时间、运行时长、控制 AID 连接状态、Owner 元信息与最近签名时间
899
+ - 队列:运行中 agent 数、待处理/处理中、近一小时收到/完成/错误/平均耗时、各 agent 队列
900
+ - 主机:hostname、OS 版本、物理机/虚拟机/容器、CPU 型号与占用、内存、网络类型
901
+ - 磁盘、各组件版本(含 PATH 与 bundled 两个 Claude Code 版本)、runtime 元信息
902
+
903
+ 输出末尾附命令总耗时。当前只支持本机 agent。`);
904
+ return;
905
+ }
906
+ const aid = args[1];
907
+ if (!aid) {
908
+ console.error('用法: ec agent host <aid>');
909
+ process.exit(1);
910
+ }
911
+ // performance.now() 的原点是进程启动,所以直接读它就能拿到含启动+模块加载的总耗时。
912
+ const branchStart = performance.now();
913
+ const { agentHost } = await import('./agent.js');
914
+ const result = await agentHost(aid, args.slice(1));
915
+ const durationMs = Math.round(performance.now() - branchStart);
916
+ const totalMs = Math.round(performance.now());
917
+ if (!result.ok) {
918
+ if (formatJson) {
919
+ console.log(JSON.stringify({ ...result, durationMs, totalMs }));
920
+ }
921
+ else {
922
+ console.error(`❌ ${describeHostFailure(result)} (host ${durationMs}ms / 总 ${totalMs}ms)`);
923
+ }
924
+ process.exit(1);
925
+ }
926
+ if (formatJson) {
927
+ console.log(JSON.stringify({ ...result, durationMs, totalMs }, null, 2));
928
+ return;
929
+ }
930
+ printAgentHostHuman(result, durationMs, totalMs);
931
+ return;
932
+ }
890
933
  // --- rename ---
891
934
  if (sub === 'rename') {
892
935
  if (wantsHelp(args)) {
@@ -1001,3 +1044,140 @@ function formatDurationMs(ms) {
1001
1044
  const day = Math.floor(hour / 24);
1002
1045
  return `${day}d${hour % 24}h${String(m).padStart(2, '0')}m`;
1003
1046
  }
1047
+ /** PKI 注册门禁结论的一行说明;`unknown` 必须说清是"没验到"而不是"不存在"。 */
1048
+ function formatAidRegistration(registration) {
1049
+ if (!registration || typeof registration !== 'object')
1050
+ return null;
1051
+ switch (registration.status) {
1052
+ case 'registered': return `已注册 · ${registration.elapsedMs}ms`;
1053
+ case 'absent': return '未注册(网关确认不存在)';
1054
+ case 'unknown': return `未确认(${registration.reason || '网关不可达'})`;
1055
+ default: return null;
1056
+ }
1057
+ }
1058
+ /**
1059
+ * `ec agent host` 失败时说明是哪道门禁挡下的:
1060
+ * - 网络门禁判 absent → AID 根本没在 PKI 注册,不必再找本机
1061
+ * - 网络无结论 + 本机没有 → 本机未托管;若同时 unknown,要提示这不是"不存在"的证据
1062
+ */
1063
+ function describeHostFailure(result) {
1064
+ const base = result.error;
1065
+ const registration = result.registration;
1066
+ if (registration?.status === 'absent') {
1067
+ return `${base} (PKI 未注册:网关确认该 AID 不存在)`;
1068
+ }
1069
+ if (registration?.status === 'unknown') {
1070
+ return `${base} (本机未托管;PKI 状态未确认:${registration.reason || '网关不可达'})`;
1071
+ }
1072
+ if (registration?.status === 'registered') {
1073
+ return `${base} (PKI 已注册,但本机未托管该 agent)`;
1074
+ }
1075
+ return base;
1076
+ }
1077
+ function printAgentHostHuman(result, durationMs, totalMs) {
1078
+ const h = result.host;
1079
+ const d = result.daemon;
1080
+ console.log(`${result.aid} (sampled ${result.sampledAt})
1081
+ `);
1082
+ console.log(' Daemon');
1083
+ console.log(` AID: ${d.aid || '—'}`);
1084
+ console.log(` PID: ${d.pid ?? '—'}`);
1085
+ console.log(` Running: ${d.running ? 'yes' : 'no'}`);
1086
+ if (d.startTime)
1087
+ console.log(` Started: ${d.startTime}`);
1088
+ if (d.uptimeMs !== null && d.uptimeMs !== undefined)
1089
+ console.log(` Uptime: ${formatDurationMs(d.uptimeMs)}`);
1090
+ console.log(` Control AID: ${d.controlAid || '—'}`);
1091
+ if (d.owner) {
1092
+ console.log(` Owner AID: ${d.owner.aid}`);
1093
+ console.log(` Owner Name: ${d.owner.name || '—'}`);
1094
+ console.log(` Owner Type: ${d.owner.type || '—'}`);
1095
+ if (d.owner.exttype)
1096
+ console.log(` Owner Exttype: ${d.owner.exttype}`);
1097
+ if (d.owner.lastSignedAt) {
1098
+ const note = d.owner.signedAtSource === 'ownership-declared-at' ? ' (绑定声明时间,非名片签名)' : '';
1099
+ console.log(` Last Signed: ${d.owner.lastSignedAt}${note}`);
1100
+ }
1101
+ else {
1102
+ console.log(' Last Signed: —(agent.md 无签名块)');
1103
+ }
1104
+ }
1105
+ console.log('');
1106
+ if (result.queue) {
1107
+ const q = result.queue;
1108
+ console.log(' Queue & Activity');
1109
+ console.log(` Running Agents: ${q.activeAgents}`);
1110
+ console.log(` Pending: ${q.totalPending}`);
1111
+ console.log(` Processing: ${q.totalProcessing}`);
1112
+ console.log(' Last Hour:');
1113
+ console.log(` Received: ${q.lastHour.received ?? '—'}`);
1114
+ console.log(` Completed: ${q.lastHour.completed ?? '—'}`);
1115
+ console.log(` Errors: ${q.lastHour.errors ?? '—'}`);
1116
+ console.log(` Avg Time: ${q.lastHour.avgResponseMs !== null ? `${(q.lastHour.avgResponseMs / 1000).toFixed(1)}s` : '—'}`);
1117
+ console.log('');
1118
+ }
1119
+ if (Array.isArray(result.agents) && result.agents.length > 0) {
1120
+ console.log(' Agents');
1121
+ for (const agent of result.agents) {
1122
+ const busy = agent.pending || agent.processing ? ` pending=${agent.pending} processing=${agent.processing}` : '';
1123
+ console.log(` ${(agent.name || agent.aid).padEnd(28)} ${String(agent.status).padEnd(10)}${busy}`);
1124
+ }
1125
+ console.log('');
1126
+ }
1127
+ console.log(' System');
1128
+ console.log(` Current Time: ${h.system.currentTime}`);
1129
+ console.log(` Timezone: ${h.system.timezone}`);
1130
+ console.log(` Boot Time: ${h.os.bootTime}`);
1131
+ console.log(` Uptime: ${formatDurationMs(h.system.uptimeSeconds * 1000)}`);
1132
+ console.log('');
1133
+ const virtMap = {
1134
+ vm: '虚拟机', docker: 'Docker 容器', wsl: 'WSL', none: '物理机', unknown: '未知(探测未完成)',
1135
+ };
1136
+ console.log(' Host');
1137
+ console.log(` Hostname: ${h.hostname}`);
1138
+ console.log(` OS: ${h.os.platformName}${h.os.release ? ` (${h.os.release})` : ''}${h.os.version ? ` · ${h.os.version}` : ''}`);
1139
+ if (h.os.distributionId)
1140
+ console.log(` Distribution: ${h.os.distributionId}`);
1141
+ console.log(` Environment: ${virtMap[h.os.virtualization] || h.os.virtualization}`);
1142
+ console.log(` Architecture: ${h.hardware.architecture}`);
1143
+ console.log(` CPU: ${h.hardware.cpuCount} cores${h.hardware.cpuModel ? ` · ${h.hardware.cpuModel}` : ''}`);
1144
+ console.log(` CPU Usage: ${h.hardware.cpuUsagePercent !== null ? `${h.hardware.cpuUsagePercent}%` : '—(需 daemon 采样)'}`);
1145
+ console.log(` Memory: ${formatBytes(h.hardware.memoryUsedBytes)} / ${formatBytes(h.hardware.memoryTotalBytes)}`);
1146
+ console.log(` Network: ${h.network.type}`);
1147
+ console.log('');
1148
+ console.log(' Disk');
1149
+ console.log(` Home Path: ${h.disk.evolcoreHomePath}`);
1150
+ if (h.disk.availableBytes !== null && h.disk.totalBytes) {
1151
+ const used = h.disk.totalBytes - h.disk.availableBytes;
1152
+ console.log(` Total: ${formatBytes(h.disk.totalBytes)}`);
1153
+ console.log(` Available: ${formatBytes(h.disk.availableBytes)}`);
1154
+ console.log(` Used: ${formatBytes(used)} (${((used / h.disk.totalBytes) * 100).toFixed(1)}%)`);
1155
+ }
1156
+ else {
1157
+ console.log(' Space: 未能检测');
1158
+ }
1159
+ console.log('');
1160
+ console.log(' Versions');
1161
+ console.log(` EvolCore: ${result.versions.evolcore || '—'}`);
1162
+ console.log(` FastAUN: ${result.versions.fastaun || '—'}`);
1163
+ console.log(` ECWeb: ${result.versions.ecweb || '—'}`);
1164
+ console.log(` Node: ${result.versions.node}`);
1165
+ const rt = h.runtimes || {};
1166
+ for (const [label, value] of [['Python', rt.python], ['Go', rt.go], ['Claude Code', rt.claudeCode], ['Codex', rt.codex], ['ecagent', rt.ecagent]]) {
1167
+ console.log(` ${(label + ':').padEnd(14)}${value || '—'}`);
1168
+ }
1169
+ // agent 实际跑的是 SDK 平台包里的 claude.exe,与 PATH 上的 claude CLI 版本可能不一致
1170
+ const bundled = rt.claudeCodeBundled;
1171
+ const bundledMismatch = bundled && rt.claudeCode && bundled !== rt.claudeCode;
1172
+ console.log(` ${'Claude(bundle):'.padEnd(14)}${bundled || '—'}${bundledMismatch ? ` ← 与 PATH 上的 ${rt.claudeCode} 不一致` : ''}`);
1173
+ console.log('');
1174
+ console.log(' Runtime');
1175
+ console.log(` Package: ${result.runtime.packagePath}`);
1176
+ console.log(` Type: ${result.runtime.installationType === 'npm-global' ? 'npm 全局安装' : '开发链接'}`);
1177
+ console.log(` Mode: ${result.runtime.runMode === 'dev' ? '开发模式' : result.runtime.runMode === 'install' ? '安装模式' : '未知'}`);
1178
+ const registrationLine = formatAidRegistration(result.registration);
1179
+ if (registrationLine)
1180
+ console.log(` PKI: ${registrationLine}`);
1181
+ console.log('');
1182
+ console.log(` 耗时: 总 ${totalMs}ms(其中进程启动+模块加载 ${totalMs - durationMs}ms,host 取数 ${durationMs}ms)`);
1183
+ }
@@ -7,7 +7,7 @@ import { resolvePaths, aunPath as defaultAunPath, agentConfig, agentDataDir, age
7
7
  import { loadDefaults, loadAgent, saveAgent, ensureAgentDirSkeleton } from '../config-store.js';
8
8
  import { ConfigTarget, assertAgentAidAvailable, write as cfgWrite, ensureFile as cfgEnsure, read as cfgRead } from '../config/config-manager.js';
9
9
  import { daemonUnavailableMessage, queryDaemon } from './help.js';
10
- import { ipcHostQuery, ipcQuery } from '../ipc.js';
10
+ import { ipcQuery } from '../ipc.js';
11
11
  import { CONFIG_SCHEMA_VERSION } from '../types.js';
12
12
  import { ensureInitialRoleRegistry } from '../config/role-service.js';
13
13
  import { getCodexAppServerAvailability } from '../agents/codex-runner.js';
@@ -23,7 +23,7 @@ import { readTaskRuntimeContextFromEnv } from './task-context.js';
23
23
  import { logger } from '../utils/logger.js';
24
24
  import { creationOwnershipBinding } from '../core/ownership/owner-resolver.js';
25
25
  import { getCatalog, getProviderCatalog, resolveCatalogModel, catalogEfforts, assertCatalogSelectable } from '../core/model/model-catalog.js';
26
- import { providerServiceTypeForBaseagent, resolveProviderServiceForBaseagent } from '../config/providers.js';
26
+ import { resolveProviderServiceForBaseagent } from '../config/providers.js';
27
27
  import { claimAgentCreation, claimAgentCreationAsync, readAgentCreationClaim, updateAgentCreationClaim } from '../core/agent-creation-claim.js';
28
28
  /** Select the creation lifecycle independently of --non-interactive. */
29
29
  export function resolveAgentCreateMode(args) {
@@ -81,8 +81,8 @@ export function parseAgentTags(raw) {
81
81
  const tagErrors = validateAgentTags(tags);
82
82
  if (tagErrors.length > 0)
83
83
  throw new Error(`--tags ${tagErrors.join('; ')}`);
84
- // Duplicate labels are harmless at the wire level, but should not consume
85
- // the advertised 3-6 tag budget or produce duplicate frontmatter entries.
84
+ // Duplicate labels are harmless at the wire level, but should not produce
85
+ // duplicate frontmatter entries.
86
86
  return [...new Set(tags)];
87
87
  }
88
88
  export function validateAgentOwnerOptions(options) {
@@ -107,7 +107,7 @@ export function parseAgentOwnerArgs(argv) {
107
107
  };
108
108
  const options = {};
109
109
  if (hasOwner)
110
- options.owner = value('--owner');
110
+ options.owner = value('--owner').trim().toLowerCase();
111
111
  const error = validateAgentOwnerOptions(options);
112
112
  if (error)
113
113
  throw new Error(error);
@@ -250,7 +250,7 @@ export async function agentCreateInteractive(opts = {}) {
250
250
  const rl = opts.rl ?? readline.createInterface({ input: opts.stdin || process.stdin, output: opts.stdout || process.stdout });
251
251
  const ask = (q) => new Promise(r => rl.question(q, r));
252
252
  try {
253
- const { aidCreate, buildInitialAgentMd, agentmdPut } = await import('../aun/aid/index.js');
253
+ const { aidCreateIdentityOnly, buildInitialAgentMd, agentmdPutInitializationProfile } = await import('../aun/aid/index.js');
254
254
  const aidPrompt = opts.suggestedName ? `AID [${opts.suggestedName}]: ` : 'AID (e.g. mybot.agentid.cn): ';
255
255
  let aid = '';
256
256
  while (!aid) {
@@ -343,7 +343,7 @@ export async function agentCreateInteractive(opts = {}) {
343
343
  console.log(` ⚠ Invalid Owner AID "${ownerInput}"`);
344
344
  continue;
345
345
  }
346
- owner = ownerInput;
346
+ owner = ownerInput.toLowerCase();
347
347
  break;
348
348
  }
349
349
  const defaultName = aid.split('.')[0];
@@ -361,11 +361,9 @@ export async function agentCreateInteractive(opts = {}) {
361
361
  if (!creationClaim.claimed)
362
362
  return { ok: false, error: 'Agent creation is already in progress or has an existing creation record' };
363
363
  let aidCreated = false;
364
+ let ownerBindRequestedAid;
364
365
  try {
365
- // Keep the registration connection independent from Ownership. Its
366
- // authentication can be short-lived, so only submit binding after the
367
- // complete agent.md has been published and the daemon has hot-loaded it.
368
- const result = await aidCreate(aid, { type: 'agent' });
366
+ const result = await aidCreateIdentityOnly(aid, { type: 'agent' });
369
367
  try {
370
368
  if (result.alreadyExisted)
371
369
  await assertAgentIdentityReusable(aid, { store: result.store });
@@ -389,6 +387,18 @@ export async function agentCreateInteractive(opts = {}) {
389
387
  ensureInitialRoleRegistry(aid);
390
388
  saveInitialBehavior(aid, baseagent);
391
389
  ensureAgentDirSkeleton(aid);
390
+ let ownerBindInterrupted = false;
391
+ let ownershipBinding;
392
+ try {
393
+ const { bindAgentCreationOwner } = await import('../core/agent-runtime.js');
394
+ const task = await bindAgentCreationOwner(aid, owner);
395
+ ownerBindRequestedAid = owner;
396
+ ownershipBinding = aidCreated ? creationOwnershipBinding(task, aid, owner) : undefined;
397
+ }
398
+ catch (error) {
399
+ ownerBindInterrupted = true;
400
+ logger.warn(`[agent-create] Ownership bind interrupted for ${aid}: ${error instanceof Error ? error.message : String(error)}`);
401
+ }
392
402
  let agentmdUploaded = false;
393
403
  try {
394
404
  const content = buildInitialAgentMd({ aid, name: agentName, description: agentDescription, tags: agentTags });
@@ -398,7 +408,9 @@ export async function agentCreateInteractive(opts = {}) {
398
408
  try {
399
409
  if (attempt > 1)
400
410
  await new Promise(r => setTimeout(r, 2000));
401
- await agentmdPut(content, { aid, aunPath });
411
+ if (!ownerBindRequestedAid)
412
+ throw new Error('Owner binding is not confirmed; profile publication was skipped');
413
+ await agentmdPutInitializationProfile(content, { aid, ownerAid: owner, aunPath });
402
414
  agentmdUploaded = true;
403
415
  break;
404
416
  }
@@ -430,28 +442,7 @@ export async function agentCreateInteractive(opts = {}) {
430
442
  hotLoadError = ipcResult.error;
431
443
  }
432
444
  catch { /* daemon not running */ }
433
- let ownerBindRequestedAid;
434
- let ownerBindSkipped = false;
435
- let ownerBindInterrupted = false;
436
- if (owner && agentmdUploaded && hotLoaded) {
437
- try {
438
- const bindResult = await ipcHostQuery(p.socket, {
439
- type: 'aid.ownership',
440
- authMode: 'local-control',
441
- argv: ['aid', 'bind', owner, '--subject', aid],
442
- }, 30_000);
443
- if (!bindResult?.ok)
444
- throw new Error(bindResult?.error || 'Ownership bind failed');
445
- ownerBindRequestedAid = owner;
446
- }
447
- catch (error) {
448
- ownerBindInterrupted = true;
449
- logger.warn(`[agent-create] Ownership bind interrupted for ${aid}: ${error instanceof Error ? error.message : String(error)}`);
450
- }
451
- }
452
- else if (owner && agentmdUploaded) {
453
- ownerBindSkipped = true;
454
- }
445
+ const ownerBindSkipped = !!owner && !!agentmdUploaded && !ownerBindRequestedAid;
455
446
  await updateAgentCreationClaim(aid, creationClaim.claim.creationId, { status: 'ready' });
456
447
  return {
457
448
  ok: true,
@@ -465,6 +456,7 @@ export async function agentCreateInteractive(opts = {}) {
465
456
  ownerBindRequestedAid,
466
457
  ownerBindSkipped,
467
458
  ownerBindInterrupted,
459
+ ...(ownershipBinding ? { ownershipBinding } : {}),
468
460
  };
469
461
  }
470
462
  finally {
@@ -481,16 +473,21 @@ export async function agentCreateInteractive(opts = {}) {
481
473
  }
482
474
  export async function agentCreateNonInteractive(opts, runtime = {}) {
483
475
  const p = resolvePaths();
484
- const { aidCreate, buildInitialAgentMd, agentmdPut } = await import('../aun/aid/index.js');
476
+ const { aidCreateIdentityOnly, buildInitialAgentMd, agentmdPut, agentmdPutInitializationProfile } = await import('../aun/aid/index.js');
485
477
  opts.onPhase?.('validating', 'begin');
486
478
  const failValidating = (error) => { opts.onPhase?.('validating', 'failed', error); return { ok: false, error }; };
487
479
  const ownerError = validateAgentOwnerOptions(opts);
488
480
  if (ownerError)
489
481
  return failValidating(ownerError);
490
- const ownerAid = opts.owner?.trim();
482
+ const ownerAid = opts.owner?.trim().toLowerCase();
491
483
  const agentType = normalizeAgentType(opts.type ?? DEFAULT_AGENT_TYPE) ?? opts.type ?? DEFAULT_AGENT_TYPE;
492
- if (agentType === 'agent' && !ownerAid)
493
- return failValidating('An owner AID is required when creating an agent');
484
+ if (agentType === 'group' || agentType === 'org') {
485
+ return failValidating(`${agentType} AIDs require their dedicated creation flow`);
486
+ }
487
+ if (agentType !== 'human' && !ownerAid)
488
+ return failValidating(`An owner AID is required when creating a ${agentType}`);
489
+ if (agentType === 'human' && ownerAid)
490
+ return failValidating('Human AIDs cannot specify an owner');
494
491
  if (opts.tags !== undefined) {
495
492
  const tagErrors = validateAgentTags(opts.tags);
496
493
  if (tagErrors.length > 0)
@@ -565,13 +562,10 @@ export async function agentCreateNonInteractive(opts, runtime = {}) {
565
562
  opts.onPhase?.('validating', 'done');
566
563
  opts.onPhase?.('registering_aid', 'begin');
567
564
  let aidCreated = false;
568
- // Do not persist a pending registration ownership intent here. Avatar
569
- // publication uses an AUN short connection, and the SDK may resume that
570
- // intent as soon as the short connection is authenticated, before the final
571
- // agent.md (including avatar) has been published. Submit the bind only after
572
- // the final card is in place and the Agent has a long-lived channel.
565
+ let ownerBindRequestedAid;
566
+ let ownershipBinding;
573
567
  try {
574
- const result = await aidCreate(opts.aid, { type: agentType });
568
+ const result = await aidCreateIdentityOnly(opts.aid, { type: agentType });
575
569
  try {
576
570
  if (result.alreadyExisted)
577
571
  await assertAgentIdentityReusable(opts.aid, { store: result.store });
@@ -609,6 +603,29 @@ export async function agentCreateNonInteractive(opts, runtime = {}) {
609
603
  opts.onPhase?.('uploading_agentmd', 'begin');
610
604
  let agentmdUploaded = false;
611
605
  let agentmdError;
606
+ let ownerBindInterrupted = false;
607
+ if (ownerAid) {
608
+ try {
609
+ const bindOwner = runtime.bindOwnerAgent ?? (async (aid, owner) => {
610
+ const { bindAgentCreationOwner } = await import('../core/agent-runtime.js');
611
+ return bindAgentCreationOwner(aid, owner);
612
+ });
613
+ const state = await bindOwner(opts.aid, ownerAid);
614
+ ownerBindRequestedAid = ownerAid;
615
+ const task = (state && typeof state === 'object' && 'task' in state)
616
+ ? state.task
617
+ : state;
618
+ const binding = aidCreated ? creationOwnershipBinding(task, opts.aid, ownerAid) : undefined;
619
+ if (binding) {
620
+ opts.onOwnershipBinding?.(binding);
621
+ ownershipBinding = binding;
622
+ }
623
+ }
624
+ catch (error) {
625
+ ownerBindInterrupted = true;
626
+ logger.warn(`[agent-create] Ownership bind interrupted for ${opts.aid}: ${error instanceof Error ? error.message : String(error)}`);
627
+ }
628
+ }
612
629
  try {
613
630
  const content = buildInitialAgentMd({ aid: opts.aid, name: opts.name, description: opts.description, type: agentType, tags: opts.tags });
614
631
  const aunPath = process.env.AUN_HOME || defaultAunPath();
@@ -617,7 +634,14 @@ export async function agentCreateNonInteractive(opts, runtime = {}) {
617
634
  try {
618
635
  if (attempt > 1)
619
636
  await new Promise(r => setTimeout(r, 2000));
620
- await agentmdPut(content, { aid: opts.aid, aunPath });
637
+ if (ownerAid) {
638
+ if (!ownerBindRequestedAid)
639
+ throw new Error('Owner binding is not confirmed; profile publication was skipped');
640
+ await agentmdPutInitializationProfile(content, { aid: opts.aid, ownerAid, aunPath });
641
+ }
642
+ else {
643
+ await agentmdPut(content, { aid: opts.aid, aunPath });
644
+ }
621
645
  agentmdUploaded = true;
622
646
  opts.onPhase?.('uploading_agentmd', 'done');
623
647
  break;
@@ -691,43 +715,7 @@ export async function agentCreateNonInteractive(opts, runtime = {}) {
691
715
  hotLoadError = error instanceof Error ? error.message : String(error);
692
716
  opts.onPhase?.('hot_loading', 'warn', hotLoadError);
693
717
  }
694
- let ownerBindRequestedAid;
695
- let ownerBindSkipped = false;
696
- let ownerBindInterrupted = false;
697
- let ownershipBinding;
698
- if (ownerAid && agentmdUploaded && hotLoaded) {
699
- try {
700
- let state;
701
- if (runtime.bindOwnerAgent) {
702
- state = await runtime.bindOwnerAgent(opts.aid, ownerAid);
703
- }
704
- else {
705
- const bindResult = await ipcHostQuery(p.socket, {
706
- type: 'aid.ownership',
707
- authMode: 'local-control',
708
- argv: ['aid', 'bind', ownerAid, '--subject', opts.aid],
709
- }, 30_000);
710
- if (!bindResult?.ok)
711
- throw new Error(bindResult?.error || 'Ownership bind failed');
712
- state = bindResult.state;
713
- }
714
- ownerBindRequestedAid = ownerAid;
715
- // Reusing an existing identity (including a failed-create retry) cannot
716
- // prove that an SDK-reused task originated in this creation attempt.
717
- const binding = aidCreated ? creationOwnershipBinding(state?.task, opts.aid, ownerAid) : undefined;
718
- if (binding) {
719
- opts.onOwnershipBinding?.(binding);
720
- ownershipBinding = binding;
721
- }
722
- }
723
- catch (error) {
724
- ownerBindInterrupted = true;
725
- logger.warn(`[agent-create] Ownership bind interrupted for ${opts.aid}: ${error instanceof Error ? error.message : String(error)}`);
726
- }
727
- }
728
- else if (ownerAid && agentmdUploaded) {
729
- ownerBindSkipped = true;
730
- }
718
+ const ownerBindSkipped = !!ownerAid && !!agentmdUploaded && !ownerBindRequestedAid;
731
719
  await updateAgentCreationClaim(opts.aid, creationClaim.claim.creationId, { status: 'ready' });
732
720
  return {
733
721
  ok: true,
@@ -1082,6 +1070,8 @@ function failure(code, error = code) {
1082
1070
  throw Object.assign(new Error(error), { code });
1083
1071
  }
1084
1072
  export function validateInitializationPlan(plan) {
1073
+ if (typeof plan.ownerAid === 'string')
1074
+ plan.ownerAid = plan.ownerAid.trim().toLowerCase();
1085
1075
  assertAgentAidAvailable(plan.aid);
1086
1076
  if (plan.provider !== undefined)
1087
1077
  resolveProviderServiceForBaseagent(plan.provider, plan.baseagent);
@@ -1120,7 +1110,7 @@ export function validateInitializationPlan(plan) {
1120
1110
  }
1121
1111
  if (fs.existsSync(plan.project) && !fs.statSync(plan.project).isDirectory())
1122
1112
  failure('INVALID_ARGS', 'project is not a directory');
1123
- const card = validateAgentMdFrontmatter(buildInitialAgentMd(plan), plan.aid);
1113
+ const card = validateAgentMdFrontmatter(buildInitialAgentMd(plan), plan.aid, { allowUnowned: true });
1124
1114
  if (!card.valid)
1125
1115
  failure('INVALID_ARGS', card.errors.join('; '));
1126
1116
  if (plan.persona !== undefined) {
@@ -1154,7 +1144,7 @@ export async function validateInitializationModelArgs(args) {
1154
1144
  return { error: '指定 model/effort 时必须提供 baseagent', code: 'INVALID_ARGS' };
1155
1145
  try {
1156
1146
  const catalog = typeof plan.provider === 'string'
1157
- ? await getProviderCatalog(plan.provider, providerServiceTypeForBaseagent(baseagent), false, false, baseagent)
1147
+ ? await getProviderCatalog(plan.provider, undefined, false, false, baseagent)
1158
1148
  : await getCatalog(undefined, baseagent);
1159
1149
  assertCatalogSelectable(catalog);
1160
1150
  const modelIds = catalog.models.map(entry => entry.id);
@@ -1200,6 +1190,19 @@ export class AgentInitializationService {
1200
1190
  deps;
1201
1191
  running = new Map();
1202
1192
  ownerRechecks = new Map();
1193
+ /** Keep the shared admission claim in sync with the one-shot journal. */
1194
+ async updateOneShotClaim(record, status) {
1195
+ if (recordMode(record) !== 'one_shot' || !record.creationId)
1196
+ return;
1197
+ try {
1198
+ await updateAgentCreationClaim(record.plan.aid, record.creationId, { status });
1199
+ }
1200
+ catch (error) {
1201
+ // Claim maintenance must not turn a completed initialization into a
1202
+ // failed one when the sidecar is temporarily unavailable.
1203
+ logger.warn(`[Initialization] failed to mark one-shot claim ${record.plan.aid} as ${status}: ${error instanceof Error ? error.message : String(error)}`);
1204
+ }
1205
+ }
1203
1206
  constructor(deps) {
1204
1207
  this.deps = deps;
1205
1208
  }
@@ -1456,6 +1459,7 @@ export class AgentInitializationService {
1456
1459
  r.status = 'cancelled';
1457
1460
  r.code = 'INITIALIZE_CANCELLED';
1458
1461
  saveInitialization(r);
1462
+ await this.updateOneShotClaim(r, 'failed');
1459
1463
  await this.running.get(aid);
1460
1464
  }
1461
1465
  async settle(aid) { await this.running.get(aid); }
@@ -1477,7 +1481,7 @@ export class AgentInitializationService {
1477
1481
  const aid = r.plan.aid;
1478
1482
  clearTimeout(this.ownerRechecks.get(aid));
1479
1483
  this.ownerRechecks.delete(aid);
1480
- const work = Promise.resolve().then(() => this.run(r)).catch(error => {
1484
+ const work = Promise.resolve().then(() => this.run(r)).catch(async (error) => {
1481
1485
  // Cancellation wins over a stale worker, including delete while network I/O was pending.
1482
1486
  let current;
1483
1487
  try {
@@ -1501,6 +1505,7 @@ export class AgentInitializationService {
1501
1505
  const syscall = typeof errno.syscall === 'string' && /^[a-z_]+$/i.test(errno.syscall) ? errno.syscall : 'unknown';
1502
1506
  logger.warn(`[Initialization] worker failed for ${aid}: phase=${r.phase} code=${initializationErrorCode(error, 'INITIALIZE_FAILED')} syscall=${syscall}`);
1503
1507
  saveInitialization(r);
1508
+ await this.updateOneShotClaim(r, 'failed');
1504
1509
  }).catch(() => { })
1505
1510
  .finally(() => {
1506
1511
  this.running.delete(aid);
@@ -1756,7 +1761,7 @@ export class AgentInitializationService {
1756
1761
  failure('INITIALIZE_PLAN_CONFLICT');
1757
1762
  fs.writeFileSync(file, p.persona, { encoding: 'utf8', mode: 0o600 });
1758
1763
  }
1759
- const bindBeforePublication = recordMode(r) === 'one_shot' && this.deps.ownershipBeforePublication === true;
1764
+ const bindBeforePublication = this.deps.ownershipBeforePublication === true;
1760
1765
  if (bindBeforePublication) {
1761
1766
  // The explicit SDK bind creates the first card and its real declaration.
1762
1767
  // Its receipt must be durable before publishing the requested profile.
@@ -1922,6 +1927,7 @@ export class AgentInitializationService {
1922
1927
  // Activation is durable even if a post-commit network delivery failed.
1923
1928
  r.phase = 'active';
1924
1929
  r.status = 'complete';
1930
+ await this.updateOneShotClaim(r, 'ready');
1925
1931
  saveInitialization(r);
1926
1932
  }
1927
1933
  }