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
@@ -1,6 +1,22 @@
1
+ /**
2
+ * 主机信息归口模块。
3
+ *
4
+ * 三层职责,按代价分开,调用方不要混用:
5
+ * 1. readHostInfo() 同步、无子进程、无缓存文件,只读 os/fs 的廉价值。
6
+ * 2. probeVirtualization() / 异步子进程探测,只应由 daemon 在启动后跑一次并缓存。
7
+ * probeRuntimes()
8
+ * 3. 动态值(时间、CPU、内存已用)由调用方每次现算,别缓存。
9
+ *
10
+ * 这个模块被 daemon 启动流程引用,任何同步子进程调用都会拖慢启停并阻塞事件循环,
11
+ * 所以只允许 execFile 异步形式。
12
+ */
1
13
  import fs from 'node:fs';
2
14
  import os from 'node:os';
15
+ import path from 'node:path';
16
+ import { execFile } from 'node:child_process';
3
17
  import { readSystemMemoryUsage } from './system-memory.js';
18
+ import { getPackageRoot } from '../paths.js';
19
+ import { buildCliLaunchCommand, resolveProbePath } from './cross-platform.js';
4
20
  function readOsRelease() {
5
21
  if (process.platform !== 'linux')
6
22
  return { id: null, version: null };
@@ -18,6 +34,20 @@ function readOsRelease() {
18
34
  return { id: null, version: null };
19
35
  }
20
36
  }
37
+ function detectPlatformName(platform) {
38
+ switch (platform) {
39
+ case 'win32': return 'Windows';
40
+ case 'darwin': return 'macOS';
41
+ case 'linux': return 'Linux';
42
+ default: return 'Other';
43
+ }
44
+ }
45
+ /** Windows 的 os.release() 已是 10.0.26200 形式;Linux/macOS 的内核串没有诊断价值,返回 null。 */
46
+ function readOsReleaseVersion() {
47
+ if (process.platform === 'win32')
48
+ return os.release() || null;
49
+ return null;
50
+ }
21
51
  function networkType() {
22
52
  try {
23
53
  const names = Object.entries(os.networkInterfaces())
@@ -25,9 +55,10 @@ function networkType() {
25
55
  .map(([name]) => name.toLowerCase());
26
56
  if (names.some(name => /(?:wwan|rmnet|pdp|cell|usb.*modem)/u.test(name)))
27
57
  return 'cellular';
28
- if (names.some(name => /(?:^wl|wlan|wifi|wireless)/u.test(name)))
58
+ if (names.some(name => /(?:^wl|wlan|wifi|wireless|wi-fi)/u.test(name)))
29
59
  return 'wlan';
30
- if (names.some(name => /(?:^eth|^en[opsx]|^eno|^ens|^lan)/u.test(name)))
60
+ // 支持中文网络接口名称(Windows)和标准英文名称
61
+ if (names.some(name => /(?:^eth|^en[opsx]|^eno|^ens|^lan|以太网|ethernet)/u.test(name)))
31
62
  return 'lan';
32
63
  }
33
64
  catch {
@@ -35,18 +66,224 @@ function networkType() {
35
66
  }
36
67
  return 'unknown';
37
68
  }
38
- export function readHostInfo(evolcoreVersion) {
69
+ function getTimezone() {
70
+ try {
71
+ return Intl.DateTimeFormat().resolvedOptions().timeZone || 'UTC';
72
+ }
73
+ catch {
74
+ const offset = -new Date().getTimezoneOffset();
75
+ const hours = Math.floor(Math.abs(offset) / 60);
76
+ const minutes = Math.abs(offset) % 60;
77
+ return `UTC${offset >= 0 ? '+' : '-'}${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}`;
78
+ }
79
+ }
80
+ /** statfs 是单次系统调用(实测 0.14ms),Windows/Linux/macOS 都支持,不需要缓存也不需要子进程。 */
81
+ function readDisk(evolcoreHomePath) {
82
+ try {
83
+ const stat = fs.statfsSync(evolcoreHomePath);
84
+ const blockSize = Number(stat.bsize);
85
+ return {
86
+ evolcoreHomePath,
87
+ availableBytes: Number(stat.bavail) * blockSize,
88
+ totalBytes: Number(stat.blocks) * blockSize,
89
+ };
90
+ }
91
+ catch {
92
+ return { evolcoreHomePath, availableBytes: null, totalBytes: null };
93
+ }
94
+ }
95
+ function readCpuModel() {
96
+ try {
97
+ const model = os.cpus()[0]?.model?.trim().replace(/\s+/gu, ' ');
98
+ return model || null;
99
+ }
100
+ catch {
101
+ return null;
102
+ }
103
+ }
104
+ /**
105
+ * 同步主机信息:只含 os/fs 的廉价读取,绝无子进程。
106
+ *
107
+ * 虚拟化、运行时版本这两项要起子进程,返回占位值;daemon 侧用
108
+ * probeVirtualization() / probeRuntimes() 探测后覆盖。磁盘用量与内存已用是便宜的
109
+ * 单次系统调用,直接现算,不缓存——缓存的磁盘数字比不显示更耽误判断。
110
+ */
111
+ export function readHostInfo(evolcoreVersion, evolcoreHomePath, options = {}) {
39
112
  const release = readOsRelease();
113
+ const platform = process.platform;
114
+ const memInfo = readSystemMemoryUsage();
115
+ const homePath = evolcoreHomePath || process.env.EVOLCORE_HOME || os.homedir();
40
116
  return {
41
117
  hostname: os.hostname(),
42
118
  node: { version: process.version },
43
119
  evolcore: { version: evolcoreVersion ?? null },
44
- os: { platform: process.platform, distributionId: release.id, version: release.version },
120
+ os: {
121
+ platform,
122
+ platformName: detectPlatformName(platform),
123
+ release: readOsReleaseVersion(),
124
+ distributionId: release.id,
125
+ version: release.version,
126
+ virtualization: 'unknown',
127
+ bootTime: new Date(Date.now() - os.uptime() * 1000).toISOString(),
128
+ },
45
129
  hardware: {
46
130
  architecture: process.arch,
47
131
  cpuCount: os.cpus().length,
48
- memoryTotalBytes: readSystemMemoryUsage().memTotal,
132
+ cpuModel: readCpuModel(),
133
+ memoryTotalBytes: memInfo.memTotal,
134
+ memoryUsedBytes: memInfo.memUsed,
135
+ cpuUsagePercent: null,
49
136
  },
50
137
  network: { type: networkType() },
138
+ system: {
139
+ currentTime: new Date().toISOString(),
140
+ timezone: getTimezone(),
141
+ uptimeSeconds: Math.round(os.uptime()),
142
+ },
143
+ disk: readDisk(homePath),
144
+ runtimes: options.runtimes ?? { python: null, go: null, claudeCode: null, claudeCodeBundled: null, codex: null, ecagent: null },
145
+ };
146
+ }
147
+ /** 异步 execFile 包一层:永不 reject,超时/缺失都走 ok=false。 */
148
+ function runExec(command, args, timeoutMs, windowsVerbatimArguments = false) {
149
+ return new Promise(resolve => {
150
+ execFile(command, args, {
151
+ encoding: 'utf8', timeout: timeoutMs, windowsHide: true, maxBuffer: 256 * 1024,
152
+ windowsVerbatimArguments,
153
+ }, (error, stdout) => {
154
+ resolve({ ok: !error, stdout: typeof stdout === 'string' ? stdout : '' });
155
+ });
156
+ });
157
+ }
158
+ /**
159
+ * 按 PATH 探测一个 CLI 的版本。
160
+ *
161
+ * 不能直接 execFile('claude'):Windows 上 npm 装的是 claude.cmd,Node 25 对 .cmd
162
+ * 直接 spawn 会报 EINVAL。走 resolveProbePath + buildCliLaunchCommand,与
163
+ * baseagent 探测同一套启动规则(.cmd 经受信任的 cmd.exe 转发)。
164
+ */
165
+ async function probeCliVersion(command, args, timeoutMs) {
166
+ try {
167
+ const executable = resolveProbePath(command);
168
+ if (!executable) {
169
+ // Windows Store 版 Python 只有 WindowsApps 下的 0 字节别名,stat 判不出可执行文件,
170
+ // 但 CreateProcess 认得这个别名,直接按命令名启动仍可用。
171
+ const raw = await runExec(command, args, timeoutMs);
172
+ return raw.ok ? firstVersionLine(raw.stdout) : null;
173
+ }
174
+ const launch = buildCliLaunchCommand(executable, args);
175
+ const result = await runExec(launch.command, launch.args, timeoutMs, launch.windowsVerbatimArguments);
176
+ return result.ok ? firstVersionLine(result.stdout) : null;
177
+ }
178
+ catch {
179
+ return null;
180
+ }
181
+ }
182
+ const VIRTUAL_VENDOR_PATTERNS = [
183
+ 'qemu', 'proxmox', 'kvm', 'vmware', 'innotek', 'virtualbox', 'xen',
184
+ 'seabios', 'bochs', 'parallels', 'bhyve',
185
+ ];
186
+ /**
187
+ * 虚拟化检测。
188
+ *
189
+ * Windows 上 WMI 查询要 1~2s,注册表读取只要约 50ms 且同样能拿到 BIOSVendor /
190
+ * SystemManufacturer / SystemProductName,所以优先注册表。注意 SystemManufacturer
191
+ * 单看 "Microsoft Corporation" 不能判定——物理机也是这个值,必须命中具体厂商串。
192
+ */
193
+ export async function probeVirtualization() {
194
+ try {
195
+ if (fs.existsSync('/.dockerenv') || fs.existsSync('/run/.containerenv'))
196
+ return 'docker';
197
+ if (process.platform === 'linux') {
198
+ try {
199
+ const procVersion = fs.readFileSync('/proc/version', 'utf8').toLowerCase();
200
+ if (procVersion.includes('microsoft') || procVersion.includes('wsl'))
201
+ return 'wsl';
202
+ }
203
+ catch { }
204
+ try {
205
+ const cgroup = fs.readFileSync('/proc/1/cgroup', 'utf8');
206
+ if (cgroup.includes('docker') || cgroup.includes('lxc') || cgroup.includes('kubepods'))
207
+ return 'docker';
208
+ }
209
+ catch { }
210
+ for (const file of ['/sys/class/dmi/id/product_name', '/sys/class/dmi/id/sys_vendor', '/sys/class/dmi/id/board_vendor']) {
211
+ try {
212
+ const content = fs.readFileSync(file, 'utf8').toLowerCase();
213
+ if (VIRTUAL_VENDOR_PATTERNS.some(pattern => content.includes(pattern)))
214
+ return 'vm';
215
+ }
216
+ catch { }
217
+ }
218
+ return 'none';
219
+ }
220
+ if (process.platform === 'win32') {
221
+ const { ok, stdout } = await runExec('reg', [
222
+ 'query', 'HKLM\\HARDWARE\\DESCRIPTION\\System\\BIOS',
223
+ ], 4000);
224
+ if (!ok)
225
+ return 'unknown';
226
+ const values = stdout.toLowerCase();
227
+ if (VIRTUAL_VENDOR_PATTERNS.some(pattern => values.includes(pattern)))
228
+ return 'vm';
229
+ // Hyper-V/KVM 客户机:产品名是 "Virtual Machine",但厂商仍是 Microsoft/KVM-x 之外的值
230
+ if (/systemproductname\s+reg_sz\s+virtual machine/u.test(values))
231
+ return 'vm';
232
+ return 'none';
233
+ }
234
+ return 'none';
235
+ }
236
+ catch {
237
+ return 'unknown';
238
+ }
239
+ }
240
+ // 不要求词边界:go 输出是 "go1.27.0",数字前面紧跟字母,\b 会挡住匹配。
241
+ const SEMVER = /\d+\.\d+\.\d+(?:[-+][\w.-]+)?/u;
242
+ function firstVersionLine(output) {
243
+ return output.match(SEMVER)?.[0] ?? null;
244
+ }
245
+ /** ecagent 随主包发布,版本读包根的 ecagent/package.json(不是 PATH 上的可执行文件)。 */
246
+ function readBundledEcagentVersion() {
247
+ try {
248
+ const pkg = JSON.parse(fs.readFileSync(path.join(getPackageRoot(), 'ecagent', 'package.json'), 'utf8'));
249
+ return typeof pkg.version === 'string' ? pkg.version : null;
250
+ }
251
+ catch {
252
+ return null;
253
+ }
254
+ }
255
+ /**
256
+ * SDK 平台包里的 claude.exe 版本 —— agent 进程实际用的就是它,可能落后于 PATH 上的
257
+ * claude CLI(两者版本号彼此独立:SDK 包跟自己的发布节奏,claude-code 跟自己的)。
258
+ * 用 --version 而不是读 package.json:平台包版本是 0.3.x,与 claude.exe 的 2.1.x 不是一回事。
259
+ */
260
+ async function probeBundledClaudeVersion() {
261
+ try {
262
+ const { resolveBundledClaudeExecutable } = await import('../agents/claude-runner.js');
263
+ const executable = resolveBundledClaudeExecutable();
264
+ if (!executable)
265
+ return null;
266
+ const result = await runExec(executable, ['--version'], 8000);
267
+ return result.ok ? firstVersionLine(result.stdout) : null;
268
+ }
269
+ catch {
270
+ return null;
271
+ }
272
+ }
273
+ export async function probeRuntimes() {
274
+ const [python, go, claudeCode, claudeCodeBundled, codex] = await Promise.all([
275
+ probeCliVersion('python', ['--version'], 3000),
276
+ probeCliVersion('go', ['version'], 3000),
277
+ probeCliVersion('claude', ['--version'], 8000),
278
+ probeBundledClaudeVersion(),
279
+ probeCliVersion('codex', ['--version'], 8000),
280
+ ]);
281
+ return {
282
+ python,
283
+ go,
284
+ claudeCode,
285
+ claudeCodeBundled,
286
+ codex,
287
+ ecagent: readBundledEcagentVersion(),
51
288
  };
52
289
  }
@@ -13,7 +13,7 @@ import path from 'path';
13
13
  import { spawnSync } from 'child_process';
14
14
  import { getPackageRoot, resolvePaths, isDevMode } from '../paths.js';
15
15
  import { isProcessRunning, killProcess, isWindows, findProcessesWithCommandLine } from './cross-platform.js';
16
- import { getProcessStartTime, startTimeMatches } from './process-introspect.js';
16
+ import { getProcessSnapshot, getProcessStartTime, snapshotProcessState, startTimeMatches, } from './process-introspect.js';
17
17
  import { isConfirmedLeakedTestDaemon, runtimeHomeFromEnv } from './restart-safety.js';
18
18
  import { decodeWindowsOutput } from './windows-output.js';
19
19
  import { atomicWriteJson } from './atomic-write.js';
@@ -34,7 +34,17 @@ function safeParseJson(filePath) {
34
34
  return null;
35
35
  }
36
36
  }
37
- function isAlive(pid, recordedStartedAt) {
37
+ /**
38
+ * 判断一条实例记录是否仍在运行。
39
+ *
40
+ * 优先用进程快照:Windows 上逐个 pid 查启动时间要拉一次 PowerShell(约 0.4s),
41
+ * 而启动路径上一次扫描就有十几条记录。快照不可用(macOS、CIM 失败)时回退到
42
+ * 逐个查询——慢一些,但判定语义完全不变。
43
+ */
44
+ function isAlive(pid, recordedStartedAt, snapshot = getProcessSnapshot()) {
45
+ const verdict = snapshotProcessState(snapshot, pid, recordedStartedAt);
46
+ if (verdict !== 'unknown')
47
+ return verdict === 'alive';
38
48
  if (!isProcessRunning(pid))
39
49
  return false;
40
50
  const actual = getProcessStartTime(pid);
@@ -50,6 +60,8 @@ function mainFileName(pid) {
50
60
  export function writeMain(launchedBy) {
51
61
  const dir = instanceDir();
52
62
  fs.mkdirSync(dir, { recursive: true });
63
+ // 自身启动时间走 uptime 近似(见 getProcessStartTime),不拉 PowerShell CIM:
64
+ // 这一步在就绪关键路径上,而近似值仍在容差内。
53
65
  const startedAt = getProcessStartTime(process.pid) ?? Date.now();
54
66
  const record = {
55
67
  pid: process.pid,
@@ -206,6 +218,8 @@ export function readAidLastActivity(pid) {
206
218
  * 损坏的 JSON 文件直接删除。aid-*.jsonl 在 scan 时不解析,由调用方按需读取。
207
219
  */
208
220
  export function scanInstances() {
221
+ // 整个扫描共用一份进程快照:Windows 上每条记录单独查存活要各拉一次外部进程。
222
+ const snapshot = getProcessSnapshot();
209
223
  const status = {
210
224
  mains: [],
211
225
  restartMonitors: [],
@@ -226,7 +240,7 @@ export function scanInstances() {
226
240
  if (file.startsWith('main-') && file.endsWith('.json')) {
227
241
  const record = safeParseJson(filePath);
228
242
  if (record && record.pid && record.startedAt) {
229
- const alive = isAlive(record.pid, record.startedAt);
243
+ const alive = isAlive(record.pid, record.startedAt, snapshot);
230
244
  status.mains.push({ record, alive });
231
245
  if (alive) {
232
246
  // 合并所有活 main 的 AID 活动记录(按 ts 取最新)
@@ -248,7 +262,7 @@ export function scanInstances() {
248
262
  else if (file.startsWith('restart-monitor-') && file.endsWith('.json')) {
249
263
  const record = safeParseJson(filePath);
250
264
  if (record && record.pid && record.startedAt) {
251
- const alive = isAlive(record.pid, record.startedAt);
265
+ const alive = isAlive(record.pid, record.startedAt, snapshot);
252
266
  status.restartMonitors.push({ record, alive });
253
267
  }
254
268
  else {
@@ -406,14 +420,22 @@ export function findOrphanProcesses(status = scanInstances()) {
406
420
  // backslash-delimited `dist\\index.js` command on some PowerShell builds.
407
421
  // `index.js` 会命中所有 Node 服务(各会话拉起的 MCP server 常有十几个),
408
422
  // 所以先用快照里的命令行过滤,只对真正的 EvolCore 入口做后续探测。
409
- const candidates = findProcessesWithCommandLine('index\\.js');
423
+ // 优先用启动期已经采过的进程快照:它同样带命令行,省掉这里再拉一次全表 CIM。
424
+ // 快照不可用(非 Windows、或 CIM 查询失败)时回退到主动枚举。
425
+ const snapshot = getProcessSnapshot();
426
+ const candidates = snapshot.complete
427
+ ? [...snapshot.commandLines.entries()]
428
+ .filter(([pid]) => pid !== process.pid)
429
+ .map(([pid, commandLine]) => ({ pid, commandLine }))
430
+ : findProcessesWithCommandLine('index\\.js');
410
431
  const orphans = [];
411
432
  for (const { pid, commandLine } of candidates) {
412
433
  if (known.has(pid))
413
434
  continue;
414
435
  if (commandLine !== undefined && !isEvolCoreMainCommand(commandLine))
415
436
  continue;
416
- if (!isProcessRunning(pid))
437
+ // 快照完整时它本身就是存活进程表,不需要再逐 pid 拉 tasklist。
438
+ if (!snapshot.complete && !isProcessRunning(pid))
417
439
  continue;
418
440
  const cmdline = commandLine || readCmdline(pid);
419
441
  // 二次验证:入口必须是当前 EvolCore 包的 dist/index.js。
@@ -4,12 +4,21 @@ import { LogWriter } from './log-writer.js';
4
4
  import { normalizeToolErrorClassification } from '../core/permission/tool-error-code.js';
5
5
  import { normalizeExecutionPermissionMode } from '../core/permission/mode.js';
6
6
  import { buildToolLifecycleEventKey, normalizeToolCorrelation } from '../core/audit/event-key.js';
7
- let currentLevel = process.env.LOG_LEVEL || 'INFO';
8
- const LEVELS = { DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3 };
7
+ import { CHANNEL_LOGS_ENV } from '../product.js';
8
+ export const LOG_LEVELS = ['TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL'];
9
+ const LEVELS = Object.fromEntries(LOG_LEVELS.map((level, index) => [level, index]));
10
+ let currentLevel = normalizeLogLevel(process.env.LOG_LEVEL) ?? 'INFO';
9
11
  const config = {
10
12
  messageLog: process.env.MESSAGE_LOG === 'true',
11
- eventLog: process.env.EVENT_LOG === 'true'
13
+ eventLog: process.env.EVENT_LOG === 'true',
14
+ channelLogs: process.env[CHANNEL_LOGS_ENV] === 'true',
12
15
  };
16
+ export function normalizeLogLevel(level) {
17
+ if (typeof level !== 'string')
18
+ return undefined;
19
+ const upper = level.toUpperCase();
20
+ return LOG_LEVELS.includes(upper) ? upper : undefined;
21
+ }
13
22
  let writers = null;
14
23
  fs.mkdirSync(resolvePaths().logs, { recursive: true });
15
24
  export function installChannelSdkConsoleFilter() {
@@ -33,8 +42,8 @@ function closeWriters(current) {
33
42
  current.message?.close();
34
43
  current.event?.close();
35
44
  current.menu.close();
36
- current.channelIn.close();
37
- current.channelOut.close();
45
+ current.channelIn?.close();
46
+ current.channelOut?.close();
38
47
  }
39
48
  function getWriters() {
40
49
  const logDir = resolvePaths().logs;
@@ -52,13 +61,27 @@ function getWriters() {
52
61
  ? new LogWriter({ baseName: 'events', logDir, rotation: 'hourly', retention: { hours: 48 } })
53
62
  : null,
54
63
  menu: new LogWriter({ baseName: 'menu-protocol', logDir, rotation: 'hourly', retention: { hours: 48 } }),
55
- channelIn: new LogWriter({ baseName: 'channel-in', logDir, rotation: 'hourly', retention: { hours: 48 } }),
56
- channelOut: new LogWriter({ baseName: 'channel-out', logDir, rotation: 'hourly', retention: { hours: 48 } }),
64
+ channelIn: config.channelLogs
65
+ ? new LogWriter({ baseName: 'channel-in', logDir, rotation: 'hourly', retention: { hours: 48 } })
66
+ : null,
67
+ channelOut: config.channelLogs
68
+ ? new LogWriter({ baseName: 'channel-out', logDir, rotation: 'hourly', retention: { hours: 48 } })
69
+ : null,
57
70
  };
58
71
  return writers;
59
72
  }
73
+ export function logLevelRank(level) {
74
+ const normalized = normalizeLogLevel(level);
75
+ return normalized ? LEVELS[normalized] : undefined;
76
+ }
60
77
  function shouldLog(level) {
61
- return (LEVELS[level] ?? 1) >= (LEVELS[currentLevel] ?? 1);
78
+ return LEVELS[level] >= LEVELS[currentLevel];
79
+ }
80
+ /** Return a single-line preview suitable for operational logs. */
81
+ export function logPreview(value, maxLength = 240) {
82
+ const text = typeof value === 'string' ? value : String(value ?? '');
83
+ const singleLine = text.replace(/\s+/gu, ' ').trim();
84
+ return singleLine.length <= maxLength ? singleLine : `${singleLine.slice(0, Math.max(0, maxLength - 3)).trimEnd()}...`;
62
85
  }
63
86
  /** Keep structured log streams joinable even when a producer only knows one
64
87
  * of the lifecycle identifiers. Existing fields remain source-of-truth; this
@@ -301,19 +324,31 @@ export function logOwnershipEvent(event, fields, failed = false) {
301
324
  * 优先级:daemon.json debug.logLevel → LOG_LEVEL 环境变量 → 'INFO'
302
325
  */
303
326
  export function setLogLevel(level) {
304
- const upper = level.toUpperCase();
305
- if (upper in LEVELS) {
306
- currentLevel = upper;
307
- }
327
+ const normalized = normalizeLogLevel(level);
328
+ if (normalized)
329
+ currentLevel = normalized;
308
330
  }
309
331
  export function getLogLevel() {
310
332
  return currentLevel;
311
333
  }
334
+ /** Enable or disable channel boundary audit streams at runtime. */
335
+ export function setChannelLogsEnabled(enabled) {
336
+ const next = enabled === true;
337
+ if (config.channelLogs === next)
338
+ return;
339
+ config.channelLogs = next;
340
+ if (writers) {
341
+ closeWriters(writers);
342
+ writers = null;
343
+ }
344
+ }
312
345
  export const logger = {
313
346
  debug: (...args) => log('DEBUG', ...args),
314
347
  info: (...args) => log('INFO', ...args),
315
348
  warn: (...args) => log('WARN', ...args),
316
349
  error: (...args) => log('ERROR', ...args),
350
+ trace: (...args) => log('TRACE', ...args),
351
+ fatal: (...args) => log('FATAL', ...args),
317
352
  message: (data) => {
318
353
  const writer = getWriters().message;
319
354
  if (!writer)
@@ -332,9 +367,19 @@ export const logger = {
332
367
  getWriters().menu.write(JSON.stringify({ ts: localTimestamp(), ...data }));
333
368
  },
334
369
  channelIn: (data) => {
335
- getWriters().channelIn.write(JSON.stringify({ ts: localTimestamp(), ...normalizeStructuredLog(data) }));
370
+ if (!config.channelLogs)
371
+ return;
372
+ const writer = getWriters().channelIn;
373
+ if (!writer)
374
+ return;
375
+ writer.write(JSON.stringify({ ts: localTimestamp(), ...normalizeStructuredLog(data) }));
336
376
  },
337
377
  channelOut: (data) => {
338
- getWriters().channelOut.write(JSON.stringify({ ts: localTimestamp(), ...normalizeStructuredLog(data) }));
378
+ if (!config.channelLogs)
379
+ return;
380
+ const writer = getWriters().channelOut;
381
+ if (!writer)
382
+ return;
383
+ writer.write(JSON.stringify({ ts: localTimestamp(), ...normalizeStructuredLog(data) }));
339
384
  }
340
385
  };
@@ -0,0 +1,46 @@
1
+ /**
2
+ * 版本与 runtime 元信息的归口读取。
3
+ *
4
+ * 这里全部是同步廉价读取:只读 package.json,不起子进程、不打 npm。
5
+ * ecweb 已装版本要跑 `npm root -g`(约 350ms),由 daemon 在启动后异步解析一次,
6
+ * 通过 HostSnapshot 下发;CLI 不再自己算。
7
+ */
8
+ import fs from 'node:fs';
9
+ import path from 'node:path';
10
+ import { getPackageRoot } from '../paths.js';
11
+ import { WEB_PACKAGE_NAME } from '../product.js';
12
+ function readJsonVersion(filePath) {
13
+ try {
14
+ const pkg = JSON.parse(fs.readFileSync(filePath, 'utf8'));
15
+ return typeof pkg.version === 'string' && pkg.version ? pkg.version : null;
16
+ }
17
+ catch {
18
+ return null;
19
+ }
20
+ }
21
+ /**
22
+ * ecweb 版本按"正在跑的那份"取值:开发仓的 ecweb/ 优先于 node_modules 里的旧副本。
23
+ * 不跑 npm;全局安装布局下 ecweb 在 globalRoot/ecweb,那份由 daemon 异步补齐。
24
+ */
25
+ export function readLocalEcwebVersion() {
26
+ const pkgRoot = getPackageRoot();
27
+ return readJsonVersion(path.join(pkgRoot, 'ecweb', 'package.json'))
28
+ ?? readJsonVersion(path.join(pkgRoot, 'node_modules', ...WEB_PACKAGE_NAME.split('/'), 'package.json'));
29
+ }
30
+ export function readVersionInfo(options = {}) {
31
+ const pkgRoot = getPackageRoot();
32
+ return {
33
+ evolcore: readJsonVersion(path.join(pkgRoot, 'package.json')),
34
+ fastaun: readJsonVersion(path.join(pkgRoot, 'node_modules', '@agentunion', 'fastaun', 'package.json')),
35
+ ecweb: options.ecweb !== undefined ? options.ecweb : readLocalEcwebVersion(),
36
+ node: process.version,
37
+ };
38
+ }
39
+ export function readRuntimeInfo(runMode) {
40
+ const packagePath = getPackageRoot();
41
+ return {
42
+ packagePath,
43
+ installationType: packagePath.includes('node_modules') ? 'npm-global' : 'development-link',
44
+ runMode: runMode ?? null,
45
+ };
46
+ }