evolcore 0.0.41 → 0.0.42-test.0

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
@@ -0,0 +1,208 @@
1
+ /**
2
+ * daemon 侧主机信息快照:`/system view=host`、`ec agent host`、ecweb 主机页的唯一出口。
3
+ *
4
+ * 分层:
5
+ * - 静态段(虚拟化、运行时版本、os 版本):启动时先读缓存,再异步探测刷新,
6
+ * 绝不阻塞 daemon 启动,也绝不在事件循环里跑同步子进程。
7
+ * - 动态段(时间、CPU、内存已用、磁盘、队列):每次查询现算,都很便宜。
8
+ */
9
+ import fs from 'node:fs';
10
+ import path from 'node:path';
11
+ import { parseDocument } from 'yaml';
12
+ import { resolvePaths, agentMdPath } from '../paths.js';
13
+ import { readHostInfo, probeVirtualization, probeRuntimes } from '../utils/host-info.js';
14
+ import { readVersionInfo, readRuntimeInfo } from '../utils/machine-info.js';
15
+ import { loadDaemonConfig } from '../config-store.js';
16
+ const EMPTY_RUNTIMES = { python: null, go: null, claudeCode: null, claudeCodeBundled: null, codex: null, ecagent: null };
17
+ function staticCachePath() {
18
+ return path.join(resolvePaths().root, 'data', 'host-static.json');
19
+ }
20
+ function readStaticCache() {
21
+ try {
22
+ const raw = JSON.parse(fs.readFileSync(staticCachePath(), 'utf8'));
23
+ if (!raw || typeof raw !== 'object')
24
+ return null;
25
+ return {
26
+ virtualization: (raw.virtualization ?? 'unknown'),
27
+ runtimes: { ...EMPTY_RUNTIMES, ...(raw.runtimes ?? {}) },
28
+ cachedAt: typeof raw.cachedAt === 'string' ? raw.cachedAt : new Date(0).toISOString(),
29
+ };
30
+ }
31
+ catch {
32
+ return null;
33
+ }
34
+ }
35
+ function writeStaticCache(cache) {
36
+ try {
37
+ fs.mkdirSync(path.dirname(staticCachePath()), { recursive: true });
38
+ fs.writeFileSync(staticCachePath(), JSON.stringify(cache), 'utf8');
39
+ }
40
+ catch { }
41
+ }
42
+ /** 读 frontmatter(只取第一段 `---` 块),解析失败返回空对象。 */
43
+ function readFrontmatter(content) {
44
+ const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---/u);
45
+ if (!match)
46
+ return {};
47
+ const document = parseDocument(match[1]);
48
+ if (document.errors.length > 0)
49
+ return {};
50
+ const data = document.toJS();
51
+ return data && typeof data === 'object' ? data : {};
52
+ }
53
+ /** agent.md 末尾签名块里的 unix 秒;SDK 未写入时为 null。 */
54
+ export function readAgentMdSignedAt(content) {
55
+ const match = content.match(/<!-- AUN-SIGNATURE[\s\S]*?timestamp:\s*(\d{9,11})[\s\S]*?-->/u);
56
+ if (!match)
57
+ return null;
58
+ const seconds = Number(match[1]);
59
+ return Number.isSafeInteger(seconds) ? new Date(seconds * 1000).toISOString() : null;
60
+ }
61
+ function str(value) {
62
+ return typeof value === 'string' && value.trim() ? value.trim() : null;
63
+ }
64
+ function readLocalOwnerAid(daemonAid) {
65
+ if (!daemonAid)
66
+ return null;
67
+ try {
68
+ const frontmatter = readFrontmatter(fs.readFileSync(agentMdPath(daemonAid), 'utf8'));
69
+ const owner = str(frontmatter.owner);
70
+ if (owner)
71
+ return owner;
72
+ const ownership = frontmatter.ownership;
73
+ return str(ownership?.statement?.owner_aid);
74
+ }
75
+ catch {
76
+ return null;
77
+ }
78
+ }
79
+ /**
80
+ * owner 元信息:名称/类型取自 owner 自己的 agent.md(owner 不在本机时为空),
81
+ * 签名时间取签名块 timestamp,取不到才退回 daemon agent.md 的 declared_at
82
+ * (那是绑定声明的签发时间,不是 owner 名片最近一次签名,会标注来源)。
83
+ */
84
+ function readOwnerMetadata(ownerAid, daemonAid) {
85
+ let name = null;
86
+ let type = null;
87
+ let exttype = null;
88
+ let lastSignedAt = null;
89
+ let signedAtSource = null;
90
+ try {
91
+ const content = fs.readFileSync(agentMdPath(ownerAid), 'utf8');
92
+ const frontmatter = readFrontmatter(content);
93
+ name = str(frontmatter.name);
94
+ type = str(frontmatter.type);
95
+ exttype = str(frontmatter.exttype);
96
+ lastSignedAt = readAgentMdSignedAt(content);
97
+ if (lastSignedAt)
98
+ signedAtSource = 'agent-md-signature';
99
+ }
100
+ catch { }
101
+ if (!lastSignedAt && daemonAid) {
102
+ try {
103
+ const frontmatter = readFrontmatter(fs.readFileSync(agentMdPath(daemonAid), 'utf8'));
104
+ const ownership = frontmatter.ownership;
105
+ const declaredAt = Number(ownership?.statement?.declared_at);
106
+ if (Number.isSafeInteger(declaredAt) && declaredAt > 0) {
107
+ lastSignedAt = new Date(declaredAt * 1000).toISOString();
108
+ signedAtSource = 'ownership-declared-at';
109
+ }
110
+ }
111
+ catch { }
112
+ }
113
+ return { aid: ownerAid, name, type, exttype, lastSignedAt, signedAtSource };
114
+ }
115
+ /** daemon 自己的启动时刻:MainRecord 由启动流程落盘,缺失时用进程 uptime 反推。 */
116
+ function readDaemonStartTime() {
117
+ const pid = process.pid;
118
+ try {
119
+ const record = JSON.parse(fs.readFileSync(path.join(resolvePaths().instanceDir, `main-${pid}.json`), 'utf8'));
120
+ if (typeof record.startedAtIso === 'string' && record.startedAtIso)
121
+ return record.startedAtIso;
122
+ if (typeof record.startedAt === 'number' && record.startedAt > 0)
123
+ return new Date(record.startedAt).toISOString();
124
+ }
125
+ catch { }
126
+ return new Date(Date.now() - Math.round(process.uptime() * 1000)).toISOString();
127
+ }
128
+ /**
129
+ * 创建快照提供者。构造时只做同步廉价读取;异步探测用 setImmediate 排到启动流程之后。
130
+ */
131
+ export function createHostSnapshotProvider(deps) {
132
+ const daemonAid = deps.daemonAid ?? loadDaemonConfig().aid ?? null;
133
+ const cached = readStaticCache();
134
+ const staticState = {
135
+ virtualization: cached?.virtualization ?? 'unknown',
136
+ runtimes: cached?.runtimes ?? EMPTY_RUNTIMES,
137
+ cachedAt: cached?.cachedAt ?? null,
138
+ virtualizationProbed: false,
139
+ runtimesProbed: false,
140
+ };
141
+ const versions = readVersionInfo();
142
+ const probe = async () => {
143
+ const [virtualization, runtimes] = await Promise.all([
144
+ probeVirtualization().then(value => ({ value }), () => ({ value: staticState.virtualization })),
145
+ probeRuntimes().then(value => ({ value }), () => ({ value: staticState.runtimes })),
146
+ ]);
147
+ staticState.virtualization = virtualization.value;
148
+ staticState.runtimes = runtimes.value;
149
+ staticState.virtualizationProbed = true;
150
+ staticState.runtimesProbed = true;
151
+ staticState.cachedAt = new Date().toISOString();
152
+ writeStaticCache({ virtualization: staticState.virtualization, runtimes: staticState.runtimes, cachedAt: staticState.cachedAt });
153
+ };
154
+ const getSnapshot = () => {
155
+ const host = readHostInfo(versions.evolcore, resolvePaths().root, { runtimes: staticState.runtimes });
156
+ host.os.virtualization = staticState.virtualization;
157
+ // CPU 只有 daemon 有采样值;采样未启动时宁可给 null,也不给一个骗人的数字。
158
+ host.hardware.cpuUsagePercent = deps.getSystemCpuPercent?.() ?? null;
159
+ const agents = deps.agentRegistry.list();
160
+ let totalPending = 0;
161
+ let totalProcessing = 0;
162
+ const agentRows = agents.map(agent => {
163
+ const pending = deps.messageQueue.getQueueLengthByAgent(agent.aid);
164
+ const processing = deps.messageQueue.getProcessingCountByAgent(agent.aid);
165
+ totalPending += pending;
166
+ totalProcessing += processing;
167
+ return { aid: agent.aid, name: agent.name ?? agent.aid, status: agent.status, pending, processing };
168
+ });
169
+ const stats = deps.statsCollector.getSnapshot().lastHour;
170
+ const ownerAid = readLocalOwnerAid(daemonAid);
171
+ return {
172
+ sampledAt: new Date().toISOString(),
173
+ host,
174
+ versions,
175
+ runtime: readRuntimeInfo(deps.runMode),
176
+ daemon: {
177
+ aid: daemonAid,
178
+ pid: process.pid,
179
+ running: true,
180
+ runMode: deps.runMode ?? null,
181
+ startTime: readDaemonStartTime(),
182
+ uptimeMs: Math.round(process.uptime() * 1000),
183
+ controlAid: deps.getControlAidState?.()?.status ?? null,
184
+ owner: ownerAid ? readOwnerMetadata(ownerAid, daemonAid) : null,
185
+ },
186
+ queue: {
187
+ totalPending: totalPending || deps.messageQueue.getGlobalQueueLength(),
188
+ totalProcessing: totalProcessing || deps.messageQueue.getGlobalProcessingCount(),
189
+ activeAgents: agents.filter(agent => agent.status === 'running').length,
190
+ lastHour: {
191
+ received: stats.received,
192
+ completed: stats.completed,
193
+ errors: stats.errors,
194
+ avgResponseMs: stats.avgResponseMs,
195
+ },
196
+ },
197
+ agents: agentRows,
198
+ probe: {
199
+ virtualization: staticState.virtualizationProbed,
200
+ runtimes: staticState.runtimesProbed,
201
+ cachedAt: staticState.cachedAt,
202
+ },
203
+ };
204
+ };
205
+ // 不阻塞启动:等当前微任务队列跑完再起子进程。
206
+ setImmediate(() => { void probe(); });
207
+ return { getSnapshot, refresh: probe };
208
+ }
@@ -5,15 +5,17 @@ import { createRequire } from 'node:module';
5
5
  import { resolvePaths } from '../../paths.js';
6
6
  import { atomicReadJson, atomicWriteJson } from '../../utils/atomic-write.js';
7
7
  import { loadDaemonConfig } from '../../config-store.js';
8
- import { ConfigTarget, mutateConfig } from '../../config/config-manager.js';
8
+ import { ConfigTarget, mutateConfig, read } from '../../config/config-manager.js';
9
9
  import { getBaseagentSnapshot } from '../../agents/baseagent-availability.js';
10
10
  import { isValidAid } from '../../aun/aid/validation.js';
11
11
  import { listBaseagentImportSources, providerFromBaseagent } from '../../config/providers-import.js';
12
12
  import { importOrMergeBaseagentProvider, readProvidersSnapshot } from '../../config/providers-management.js';
13
+ import { providerServiceTypesForBaseagent } from '../../config/providers.js';
13
14
  import { readInstalledEvolcoreVersion } from '../../utils/evolcore-version.js';
14
- import { defaultProjectsRoot } from '../../utils/project-path.js';
15
+ import { agentProjectRootFromDefaults, defaultProjectsRoot } from '../../utils/project-path.js';
15
16
  import { resolveControlAidDomain } from '../../aun/aid/control-aid.js';
16
17
  import { validateInitializationModelArgs } from '../../cli/agent-create.js';
18
+ import { resolveRuntimeBaseagentModelSelection } from '../../agents/baseagent.js';
17
19
  import { isHClassPath, isLClassPath } from '../permission/protected-paths.js';
18
20
  import { normalizeAvatarImage } from '../../utils/avatar-upload.js';
19
21
  const require = createRequire(import.meta.url);
@@ -25,6 +27,26 @@ function record(value) {
25
27
  function fail(code, message, statusCode = 400) {
26
28
  throw Object.assign(new Error(message), { code, statusCode });
27
29
  }
30
+ function providerSupportsBaseagent(provider, baseagent) {
31
+ return !!provider?.services && providerServiceTypesForBaseagent(baseagent).some(type => Object.hasOwn(provider.services, type));
32
+ }
33
+ async function resolveEcagentDefaultModel(providerId) {
34
+ try {
35
+ const selection = await resolveRuntimeBaseagentModelSelection('ecagent', { provider: providerId });
36
+ if (selection)
37
+ return selection.model;
38
+ }
39
+ catch { /* Report a recoverable configuration error without upstream credentials. */ }
40
+ return fail('ECAGENT_MODEL_UNAVAILABLE', 'ecagent 默认服务商中未找到可用的 deepseek[*]flash 模型,请检查服务商配置后重试', 409);
41
+ }
42
+ function baseagentDefaults() {
43
+ const defaults = read(ConfigTarget.Defaults, undefined, { cache: false });
44
+ return Object.fromEntries(Object.entries(defaults?.baseagents ?? {}).filter(([, block]) => record(block))
45
+ .map(([id, block]) => {
46
+ const value = block;
47
+ return [id, Object.fromEntries(['provider', 'model', 'effort'].flatMap(field => typeof value[field] === 'string' ? [[field, value[field]]] : []))];
48
+ }));
49
+ }
28
50
  function qrSvg(payload) {
29
51
  const QRCode = require('qrcode-terminal/vendor/QRCode');
30
52
  const qr = new QRCode(-1, 1);
@@ -45,6 +67,7 @@ function qrSvg(payload) {
45
67
  export class EcwebInitializationService {
46
68
  deps;
47
69
  agentInitializer;
70
+ ownerRecoveryAt = new Map();
48
71
  queue = Promise.resolve();
49
72
  constructor(deps = {}) {
50
73
  this.deps = deps;
@@ -57,21 +80,25 @@ export class EcwebInitializationService {
57
80
  }
58
81
  root() { return this.deps.root?.() ?? resolvePaths().root; }
59
82
  now() { return this.deps.now?.() ?? Date.now(); }
60
- file() { return path.join(this.root(), 'data', 'ecweb', 'init-state.json'); }
83
+ file(workflowId) {
84
+ return workflowId ? path.join(this.root(), 'data', 'ecweb', 'agent-creations', workflowId + '.json')
85
+ : path.join(this.root(), 'data', 'ecweb', 'init-state.json');
86
+ }
61
87
  save(state) {
62
88
  state.updatedAt = this.now();
63
- atomicWriteJson(this.file(), state);
64
- for (const file of [this.file(), `${this.file()}_`])
89
+ const stateFile = this.file(state.workflowId);
90
+ atomicWriteJson(stateFile, state);
91
+ for (const file of [stateFile, stateFile + '_'])
65
92
  if (fs.existsSync(file))
66
93
  fs.chmodSync(file, 0o600);
67
94
  }
68
- read() {
95
+ read(workflowId) {
69
96
  const aid = this.deps.controlAid ? this.deps.controlAid() : loadDaemonConfig().aid;
70
97
  if (!aid || !isValidAid(aid))
71
98
  fail('CONTROL_AID_NOT_READY', '主机身份尚未就绪,请先运行 ec init --web', 409);
72
99
  let state;
73
100
  try {
74
- state = atomicReadJson(this.file());
101
+ state = atomicReadJson(this.file(workflowId));
75
102
  }
76
103
  catch {
77
104
  return fail('INIT_STATE_INVALID', '初始化状态无法读取,请检查数据文件', 409);
@@ -82,8 +109,11 @@ export class EcwebInitializationService {
82
109
  || !['created', 'pending', 'unknown', 'bound', 'expired'].includes(state.binding.status))))) {
83
110
  fail('INIT_STATE_INVALID', '初始化状态无效,不能继续绑定', 409);
84
111
  }
112
+ if (state && state.workflowId !== workflowId)
113
+ fail('INIT_STATE_INVALID', '创建会话状态无效', 409);
85
114
  if (!state || state.controlAid !== aid)
86
- return { version: 1, controlAid: aid, step: 'welcome', updatedAt: this.now() };
115
+ return { version: 1, controlAid: aid,
116
+ ...(workflowId ? { workflowId } : {}), step: workflowId ? 'agent' : 'welcome', updatedAt: this.now() };
87
117
  if (state.binding?.status === 'created' && state.binding.expiresAt <= this.now()) {
88
118
  state.binding.status = 'expired';
89
119
  this.save(state);
@@ -119,6 +149,60 @@ export class EcwebInitializationService {
119
149
  }
120
150
  return owner;
121
151
  }
152
+ async persistDefaults(state, baseagent, inventory) {
153
+ const available = inventory.baseagents.filter(item => item.detected).map(item => item.id);
154
+ if (!available.includes(baseagent))
155
+ fail('INVALID_BASEAGENT', '请选择可用的默认 Base Agent');
156
+ const providers = readProvidersSnapshot();
157
+ const firstProvider = (id) => providerServiceTypesForBaseagent(id)
158
+ .map(type => Object.entries(providers.providers).find(([, provider]) => Object.hasOwn(provider.services ?? {}, type))?.[0])
159
+ .find(providerId => providerId !== undefined);
160
+ const ecagentProvider = available.includes('ecagent') ? firstProvider('ecagent') : undefined;
161
+ if (available.includes('ecagent') && !ecagentProvider)
162
+ fail('PROVIDER_REQUIRED', '请先导入支持 ecagent 或 text 的服务商配置,再继续初始化', 409);
163
+ const ecagentModel = ecagentProvider ? await resolveEcagentDefaultModel(ecagentProvider) : undefined;
164
+ try {
165
+ mutateConfig(ConfigTarget.Defaults, undefined, config => {
166
+ if (readProvidersSnapshot().revision !== providers.revision) {
167
+ fail('REVISION_CONFLICT', '服务商配置已变更,请刷新后重新确认', 409);
168
+ }
169
+ config.active_baseagent = baseagent;
170
+ config.baseagents = record(config.baseagents) ? config.baseagents : {};
171
+ for (const id of available) {
172
+ const previous = record(config.baseagents[id]) ? config.baseagents[id] : {};
173
+ const previousProvider = typeof previous.provider === 'string' ? previous.provider : '';
174
+ const provider = id === 'ecagent' ? ecagentProvider
175
+ : state.providerIds?.[id]
176
+ || (providerSupportsBaseagent(providers.providers[previousProvider], id) ? previousProvider : undefined)
177
+ || firstProvider(id);
178
+ if (!provider || !providerSupportsBaseagent(providers.providers[provider], id)) {
179
+ fail('PROVIDER_REQUIRED', `未找到可用于 ${id} 的服务商,请先导入对应配置后重试`, 409);
180
+ }
181
+ config.baseagents[id] = { ...previous, provider };
182
+ if (id === 'ecagent') {
183
+ config.baseagents[id].model = ecagentModel;
184
+ delete config.baseagents[id].effort;
185
+ }
186
+ }
187
+ });
188
+ }
189
+ catch (error) {
190
+ if (['REVISION_CONFLICT', 'PROVIDER_REQUIRED'].includes(error.code ?? ''))
191
+ throw error;
192
+ fail('DEFAULTS_SAVE_FAILED', '默认配置保存失败,已导入的服务商配置仍保留;请返回调整后点击“下一步”重试', 503);
193
+ }
194
+ }
195
+ requireDefaults(state, inventory) {
196
+ const defaults = baseagentDefaults();
197
+ const providers = readProvidersSnapshot();
198
+ const active = inventory.baseagents.find(item => item.id === inventory.active && item.detected);
199
+ if (!state.baseagent || !active || (inventory.baseagents.some(item => item.id === 'ecagent' && item.detected)
200
+ && !defaults.ecagent?.model?.trim()) || inventory.baseagents.some(item => item.detected
201
+ && !providerSupportsBaseagent(providers.providers[defaults[item.id]?.provider ?? ''], item.id))) {
202
+ fail('DEFAULTS_REQUIRED', '默认 Base Agent 或服务商配置未保存完整,请返回配置步骤重新保存', 409);
203
+ }
204
+ return defaults;
205
+ }
122
206
  async view(state) {
123
207
  if (state.creation && !state.agent) {
124
208
  const { aid, name, project } = state.creation.plan;
@@ -126,8 +210,25 @@ export class EcwebInitializationService {
126
210
  this.save(state);
127
211
  }
128
212
  if (state.step === 'agent' && state.agent && this.agentInitializer) {
129
- const result = this.agentInitializer.status(state.agent.aid);
213
+ let result = this.agentInitializer.status(state.agent.aid);
214
+ if (result.status === 'in_progress' && result.phase === 'ownerpending') {
215
+ const now = this.now();
216
+ const lastRecovery = this.ownerRecoveryAt.get(state.agent.aid) ?? 0;
217
+ const ownerAid = state.creation?.plan.ownerAid;
218
+ if (ownerAid && now - lastRecovery >= 5_000) {
219
+ this.ownerRecoveryAt.set(state.agent.aid, now);
220
+ try {
221
+ this.agentInitializer.resumeForOwner(state.agent.aid, ownerAid);
222
+ result = this.agentInitializer.status(state.agent.aid);
223
+ }
224
+ catch {
225
+ // Keep returning the durable status; a transient recovery failure
226
+ // must not make the ECweb state endpoint unavailable.
227
+ }
228
+ }
229
+ }
130
230
  if (result.complete === true && result.usable === true) {
231
+ this.ownerRecoveryAt.delete(state.agent.aid);
131
232
  state.step = 'ready';
132
233
  this.save(state);
133
234
  }
@@ -283,9 +384,19 @@ export class EcwebInitializationService {
283
384
  if (!record(input) || typeof input.method !== 'string' || typeof input.pathname !== 'string') {
284
385
  fail('INVALID_REQUEST', '初始化请求格式无效');
285
386
  }
286
- const pathname = input.pathname.replace(/\/+$/u, '');
387
+ let pathname = input.pathname.replace(/\/+$/u, '');
287
388
  const body = record(input.body) ? input.body : {};
288
- const state = this.read();
389
+ let workflowId;
390
+ if (pathname.startsWith('/api/init/agent-creations/')) {
391
+ const match = /^\/api\/init\/agent-creations\/([0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})\/(state|configuration|agent|agent\/resume|avatar)$/u.exec(pathname);
392
+ if (!match || !((input.method === 'GET' && ['state', 'configuration'].includes(match[2]))
393
+ || (input.method === 'POST' && ['agent', 'agent/resume', 'avatar'].includes(match[2])))) {
394
+ fail('INVALID_REQUEST', 'Agent 创建会话接口无效');
395
+ }
396
+ workflowId = match[1];
397
+ pathname = '/api/init/' + match[2];
398
+ }
399
+ const state = this.read(workflowId);
289
400
  if (input.method === 'GET' && pathname === '/api/init/state')
290
401
  return { status: 200, body: { success: true, data: await this.view(state) } };
291
402
  if (input.method === 'POST' && pathname === '/api/init/start') {
@@ -324,12 +435,17 @@ export class EcwebInitializationService {
324
435
  if (!owner)
325
436
  fail('OWNERSHIP_REQUIRED', '请先完成主机 Owner 绑定', 409);
326
437
  const providers = readProvidersSnapshot();
438
+ const inventory = await getBaseagentSnapshot();
327
439
  return { status: 200, body: { success: true, data: {
328
- baseagents: await getBaseagentSnapshot(), providers,
329
- sources: listBaseagentImportSources(),
440
+ baseagents: inventory, providers,
441
+ sources: workflowId ? [] : listBaseagentImportSources(),
330
442
  providersRevision: providers.revision,
331
- defaultProjectPath: defaultProjectsRoot(this.root()),
332
- defaultBaseagent: state.baseagent ?? null,
443
+ defaultProjectPath: workflowId
444
+ ? agentProjectRootFromDefaults(read(ConfigTarget.Defaults, undefined, { cache: false }), this.root())
445
+ : defaultProjectsRoot(this.root()),
446
+ defaultBaseagent: workflowId ? inventory.active : state.baseagent ?? null,
447
+ importedProviders: state.providerIds ?? {},
448
+ baseagentDefaults: baseagentDefaults(),
333
449
  } } };
334
450
  }
335
451
  if (input.method === 'POST' && pathname === '/api/init/configuration') {
@@ -342,7 +458,7 @@ export class EcwebInitializationService {
342
458
  if (typeof body.baseagent !== 'string' || !inventory.baseagents.some(item => item.id === body.baseagent && item.detected)) {
343
459
  fail('INVALID_BASEAGENT', '请选择可用的默认 Base Agent');
344
460
  }
345
- mutateConfig(ConfigTarget.Defaults, undefined, config => { config.active_baseagent = body.baseagent; });
461
+ await this.persistDefaults(state, body.baseagent, inventory);
346
462
  state.baseagent = body.baseagent;
347
463
  state.ownerAid = owner;
348
464
  state.step = 'agent';
@@ -370,9 +486,20 @@ export class EcwebInitializationService {
370
486
  return fail('INVALID_SOURCE', 'Provider 来源无效');
371
487
  try {
372
488
  const data = await importOrMergeBaseagentProvider({ revision: body.revision, value: provider });
489
+ if (!state.providerIds)
490
+ state.providerIds = {};
491
+ state.providerIds[body.id] = data.providerId;
492
+ try {
493
+ this.save(state);
494
+ }
495
+ catch {
496
+ fail('INIT_STATE_SAVE_FAILED', '服务商已导入,但初始化进度保存失败,请返回配置步骤重试', 503);
497
+ }
373
498
  return { status: 200, body: { success: true, data } };
374
499
  }
375
500
  catch (error) {
501
+ if (error.code === 'INIT_STATE_SAVE_FAILED')
502
+ throw error;
376
503
  if (error.statusCode === 409)
377
504
  fail('REVISION_CONFLICT', '配置已变更,请刷新预览后重新确认', 409);
378
505
  return fail('PROVIDER_IMPORT_FAILED', 'Provider 导入失败,未返回凭据详情');
@@ -389,7 +516,7 @@ export class EcwebInitializationService {
389
516
  const fingerprint = crypto.createHash('sha256').update(JSON.stringify(body)).digest('hex');
390
517
  if (state.creation) {
391
518
  if (state.creation.operationId !== body.operationId || state.creation.fingerprint !== fingerprint)
392
- fail('CREATE_CONFLICT', '已有首个 Agent 创建请求,请查询进度', 409);
519
+ fail('CREATE_CONFLICT', '已有 Agent 创建请求,请查询进度', 409);
393
520
  this.agentInitializer.start(state.creation.plan, 'local-control');
394
521
  return { status: 200, body: { success: true, data: await this.view(state) } };
395
522
  }
@@ -406,16 +533,21 @@ export class EcwebInitializationService {
406
533
  if (!inventory.baseagents.some(item => item.id === baseagent && item.detected)) {
407
534
  fail('INVALID_BASEAGENT', '请选择可用的 Base Agent');
408
535
  }
536
+ const defaults = (workflowId ? baseagentDefaults() : this.requireDefaults(state, inventory))[baseagent] ?? {};
537
+ const provider = typeof body.provider === 'string' && body.provider ? body.provider : defaults.provider;
538
+ const inherited = provider === defaults.provider ? defaults : {};
539
+ const model = typeof body.model === 'string' && body.model.trim() ? body.model.trim() : inherited.model;
540
+ const effort = typeof body.effort === 'string' && body.effort.trim() ? body.effort.trim() : inherited.effort;
409
541
  const aid = typeof body.aid === 'string' && body.aid.trim() ? body.aid.trim().toLowerCase() : this.generatedAgentAid(name, state.controlAid);
410
542
  if (!name || !project || !baseagent)
411
543
  fail('INVALID_ARGS', '昵称、项目目录和 Base Agent 不能为空');
412
544
  const plan = {
413
545
  aid, project, baseagent,
414
- ...(typeof body.model === 'string' && body.model.trim() && body.model.trim() !== 'auto' ? { model: body.model.trim() } : {}),
415
- ...(typeof body.effort === 'string' && body.effort.trim() && body.effort.trim() !== 'auto' ? { effort: body.effort.trim() } : {}),
546
+ ...(model && model !== 'auto' ? { model } : {}),
547
+ ...(effort && effort !== 'auto' ? { effort } : {}),
416
548
  ownerAid: typeof body.ownerAid === 'string' && body.ownerAid.trim() ? body.ownerAid.trim().toLowerCase() : owner,
417
549
  name, description: `${name},由 ECweb 创建的 Agent`, type: 'agent', tags: ['assistant'],
418
- ...(typeof body.provider === 'string' && body.provider ? { provider: body.provider } : {}),
550
+ ...(provider ? { provider } : {}),
419
551
  ...(state.avatar && body.avatarId === state.avatar.id ? { avatarFile: state.avatar.file } : {}),
420
552
  };
421
553
  if (body.avatarId && (!state.avatar || body.avatarId !== state.avatar.id))
@@ -26,6 +26,7 @@ import { createManagedCrossThreadReviewTrigger, createTriggerBaseagentResolver,
26
26
  import { createThreadOperationExecutor } from './thread/ipc-operation.js';
27
27
  import { isLinkedInstall } from '../utils/npm-ops.js';
28
28
  import { buildSystemSessionContext, getSystemSessionModule } from './system-session/registry.js';
29
+ import { parseManagedDaemonLogArgv, queryDiagnosticLogs } from './command/daemon-diagnostics.js';
29
30
  export function registerDaemonIpc({ ipcServer, agentRegistry, agentDelegationRegistry, sessionManager, statsCollector, aidStatsCollector, responseEngine, messageQueue, agentMap, commandHandler, channelInstances, eventBus, handoffRuntime, reloadCoordinator, agentApplicationService, agentInitializationService, enqueueConsolidation, getRelationRoute, isConsolidationPending, completeAgentBootstrap, contactBinds, bindService, diagService, getProcessOwners, getControlAidState, daemonAid, triggerControlToken, triggerSchedulers, daemonTriggerOwner, primaryAgent, triggerAuthorization, }) {
30
31
  ecwebInitializationService.setAgentInitializer(agentInitializationService);
31
32
  const authorizeManagedAgentOperation = createDelegationAuthorizer({
@@ -61,7 +62,22 @@ export function registerDaemonIpc({ ipcServer, agentRegistry, agentDelegationReg
61
62
  agentMap,
62
63
  isLinkedInstall: isLinkedInstall(),
63
64
  });
64
- ipcServer.setEcwebMessageContextProvider(createEcwebMessageContextProvider(sessionManager));
65
+ ipcServer.setEcwebMessageContextProvider(createEcwebMessageContextProvider(sessionManager, session => {
66
+ const queued = messageQueue.isProcessing(session.id) || messageQueue.getQueueLength(session.id) > 0;
67
+ try {
68
+ const runner = responseEngine.getAgent(session.metadata?.channelKey || session.channel, session.baseagent, session.selfAID);
69
+ const executionState = runner.getExecutionState?.(session.id);
70
+ if (executionState === 'interrupting')
71
+ return 'interrupting';
72
+ if (queued || executionState === 'running' || runner.hasActiveStream(session.id)
73
+ || runner.hasActiveOperation?.(session.id))
74
+ return 'processing';
75
+ return 'idle';
76
+ }
77
+ catch {
78
+ return queued ? 'processing' : undefined;
79
+ }
80
+ }));
65
81
  if (process.env.EVOLCORE_DEBUG_MODE === '1') {
66
82
  ipcServer.setDebugIssueTokenExecutor(async ({ sessionId }) => {
67
83
  try {
@@ -301,7 +317,7 @@ export function createIpcStatusProvider(dependencies) {
301
317
  pid: process.pid,
302
318
  uptime: snapshot.uptimeMs,
303
319
  ...(dependencies.runMode ? { runMode: dependencies.runMode } : {}),
304
- ...(dependencies.host ? { host: dependencies.host } : {}),
320
+ ...(dependencies.getHost ? { host: dependencies.getHost() } : {}),
305
321
  build: {
306
322
  runtimeMode: dependencies.runtimeIsDist ? 'dist' : 'source',
307
323
  runtimeId: dependencies.runtimeBuildIdentity.id,
@@ -468,7 +484,7 @@ export function registerRuntimeIpcProviders({ ipcServer, channelInstances, messa
468
484
  for (const runner of new Set(agentMap.values())) {
469
485
  if (typeof runner?.evaluatePreToolUse !== 'function')
470
486
  continue;
471
- const result = await runner.evaluatePreToolUse(params.threadId, params.toolName, params.toolInput, params.signal, params.callId, params.sessionToken);
487
+ const result = await runner.evaluatePreToolUse(params.threadId, params.toolName, params.toolInput, params.signal, params.callId, params.sessionToken, params.hookToken);
472
488
  if (result.applicable)
473
489
  return result;
474
490
  }
@@ -570,8 +586,9 @@ export function registerCommandIpcProviders({ ipcServer, agentRegistry, triggerC
570
586
  ipcServer.setWechatContactBindExecutor(contactBinds.wechat);
571
587
  ipcServer.setMenuExecutor((payload, auth) => cmdHandler.execMenuForEcweb(payload, auth));
572
588
  ipcServer.setConfigOperationExecutor((argv, sessionId, delegationToken, delegationCommandHash, requestId) => cmdHandler.handleConfigOperation(argv, sessionId, delegationToken, delegationCommandHash, requestId));
573
- ipcServer.setContactOperationExecutor((argv, sessionId, delegationToken, delegationCommandHash) => cmdHandler.handleContactOperation(argv, sessionId, delegationToken, delegationCommandHash));
589
+ ipcServer.setPeerOperationExecutor((argv, sessionId, delegationToken, delegationCommandHash) => cmdHandler.handleContactOperation(argv, sessionId, delegationToken, delegationCommandHash));
574
590
  ipcServer.setRoleOperationExecutor((argv, sessionId, delegationToken, delegationCommandHash) => cmdHandler.handleRoleOperation(argv, sessionId, delegationToken, delegationCommandHash));
591
+ ipcServer.setDirectoryOperationExecutor((argv, sessionId, delegationToken, delegationCommandHash) => cmdHandler.handleDirectoryOperation(argv, sessionId, delegationToken, delegationCommandHash));
575
592
  ipcServer.setAidOperationExecutor((argv, sessionId, delegationToken, delegationCommandHash, requestId) => cmdHandler.handleAidOperation(argv, sessionId, delegationToken, delegationCommandHash, requestId));
576
593
  ipcServer.setAidOwnershipExecutor((argv, sessionId, delegationToken, delegationCommandHash) => cmdHandler.handleOwnershipOperation(argv, sessionId, delegationToken, delegationCommandHash));
577
594
  ipcServer.setDiagExecutor(command => executeDiag(command));
@@ -668,6 +685,18 @@ export function registerOperationIpcProviders({ ipcServer, sessionManager, messa
668
685
  const authorization = await authorizeManagedAgentOperation(params, 'system.status');
669
686
  return authorization.ok ? { ok: true } : authorization;
670
687
  });
688
+ ipcServer.setLogsQueryExecutor(async (params) => {
689
+ try {
690
+ const query = parseManagedDaemonLogArgv(params.argv);
691
+ const authorization = await authorizeManagedAgentOperation(params, 'system.status');
692
+ if (!authorization.ok)
693
+ return authorization;
694
+ return { ok: true, data: queryDiagnosticLogs(query, authorization.aid) };
695
+ }
696
+ catch (error) {
697
+ return { ok: false, code: error?.code ?? 'INTERNAL_ERROR', error: error?.message ?? String(error) };
698
+ }
699
+ });
671
700
  ipcServer.setStorageAuthorizationExecutor(async (params) => {
672
701
  try {
673
702
  if (!params.argv)
@@ -76,6 +76,32 @@ export function writeBatchMeta(batchDir, meta) {
76
76
  }
77
77
  catch { /* 失败静默,不影响主流程 */ }
78
78
  }
79
+ /**
80
+ * 会话拉起后回填标识:executionSessionId / triggerId / plannedModel。
81
+ *
82
+ * 这三个值在 serializeConsolidationContext 写初始 batch.md 时还不知道——
83
+ * triggerId 在其后才生成,sessionId 要等 launch() 返回。没有它们,
84
+ * 批次目录就无法回溯到会话,模型没配这类早期失败也无从判断。
85
+ * 只合并 frontmatter,正文(含 feedback)原样保留。
86
+ */
87
+ export function patchBatchMeta(batchDir, updates) {
88
+ try {
89
+ const filePath = batchMdPath(batchDir);
90
+ if (!fs.existsSync(filePath))
91
+ return;
92
+ const raw = fs.readFileSync(filePath, 'utf-8');
93
+ const { meta, body } = parseFrontmatter(raw);
94
+ const merged = { ...meta };
95
+ for (const [key, value] of Object.entries(updates)) {
96
+ if (value === undefined)
97
+ continue;
98
+ merged[key] = value;
99
+ }
100
+ const result = serializeFrontmatter(merged) + (body ? '\n' + body : '');
101
+ fs.writeFileSync(filePath, result, 'utf-8');
102
+ }
103
+ catch { /* 失败静默,不影响主流程 */ }
104
+ }
79
105
  /**
80
106
  * 会话结束时更新 batch.md:
81
107
  * - 合并 frontmatter 字段(status / finishedAt / success / agentSessionId)
@@ -97,6 +123,7 @@ export function updateBatchMeta(batchDir, updates) {
97
123
  ...(updates.agentSessionId ? { agentSessionId: updates.agentSessionId } : {}),
98
124
  ...(updates.requestedModel ? { requestedModel: updates.requestedModel } : {}),
99
125
  ...(updates.actualModel ? { actualModel: updates.actualModel } : {}),
126
+ ...(updates.errorCode ? { errorCode: updates.errorCode } : {}),
100
127
  ...(updates.failureReason ? { failureReason: updates.failureReason } : {}),
101
128
  };
102
129
  // 更新 feedback 正文