evolcore 0.0.49 → 0.0.50
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.
- package/CHANGELOG.md +64 -1
- package/bin/ecmsg.js +9 -4
- package/dist/ability/caller/authorization.js +21 -0
- package/dist/ability/caller/command.js +164 -0
- package/dist/ability/caller/contract.js +102 -0
- package/dist/ability/caller/daemon.js +158 -0
- package/dist/ability/caller/service.js +380 -0
- package/dist/ability/command-contract.js +5 -0
- package/dist/ability/daemon.js +5 -1
- package/dist/ability/interop-v1.js +10 -3
- package/dist/ability/management.js +1 -0
- package/dist/agent-template/jobs.js +173 -1
- package/dist/agent-template/runtime.js +280 -6
- package/dist/agent-template/service.js +1159 -40
- package/dist/agent-template/types.js +2 -1
- package/dist/agents/baseagent-availability.js +27 -3
- package/dist/agents/baseagent-capability-adapter.js +102 -0
- package/dist/agents/baseagent-plugin-descriptor.js +274 -0
- package/dist/agents/baseagent-plugin-loader.js +145 -0
- package/dist/agents/baseagent.js +68 -2
- package/dist/agents/claude-gateway/agent-registration.js +389 -0
- package/dist/agents/claude-gateway/binding.js +96 -0
- package/dist/agents/claude-gateway/inbox.js +138 -0
- package/dist/agents/claude-gateway/index.js +125 -0
- package/dist/agents/claude-gateway/listing.js +330 -0
- package/dist/agents/claude-gateway/router.js +328 -0
- package/dist/agents/claude-gateway/sessions.js +128 -0
- package/dist/agents/claude-gateway/terminal.js +250 -0
- package/dist/agents/claude-gateway/transcript.js +272 -0
- package/dist/agents/claude-gateway/types.js +14 -0
- package/dist/agents/claude-runner.js +6 -10
- package/dist/agents/codex-runner.js +4 -1
- package/dist/agents/{gemini-runner.js → gemini/gemini-runner.js} +17 -17
- package/dist/{core/session/adapters → agents/gemini}/gemini-session-file-adapter.js +2 -2
- package/dist/agents/gemini/index.js +51 -0
- package/dist/aun/aid/control-aid.js +52 -32
- package/dist/aun/group/invite-service.js +6 -36
- package/dist/aun/group/operations.js +6 -0
- package/dist/aun/msg/mention-schema.js +1 -1
- package/dist/aun/msg/p2p.js +29 -1
- package/dist/aun/msg/upload.js +126 -3
- package/dist/build-identity.json +1 -1
- package/dist/channels/aun.js +537 -189
- package/dist/cli/ability-command.js +42 -0
- package/dist/cli/agent-command.js +20 -1
- package/dist/cli/agent-create.js +78 -18
- package/dist/cli/agent-template.js +5 -3
- package/dist/cli/agent.js +91 -0
- package/dist/cli/aun-commands.js +92 -34
- package/dist/cli/bench.js +5 -2
- package/dist/cli/config.js +22 -6
- package/dist/cli/daemon-commands.js +245 -101
- package/dist/cli/ecmsg-gateway.js +11 -9
- package/dist/cli/index.js +23 -4
- package/dist/cli/init.js +39 -63
- package/dist/cli/managed-command-guard.js +1 -0
- package/dist/cli/menu-client.js +32 -7
- package/dist/cli/pay-command.js +30 -0
- package/dist/cli/provider-command.js +6 -2
- package/dist/cli/restart-monitor.js +2 -2
- package/dist/cli/services-command.js +11 -9
- package/dist/cli/thread-command.js +78 -12
- package/dist/config/access-policy.js +16 -3
- package/dist/config/config-field-policy.js +17 -8
- package/dist/config/config-manager.js +86 -46
- package/dist/config/config-operation-service.js +22 -1
- package/dist/config/gateway-config.js +9 -8
- package/dist/config/owner-config.js +0 -16
- package/dist/config/peer-role-resolver.js +1 -7
- package/dist/config/providers-config.js +99 -16
- package/dist/config/providers-management.js +35 -19
- package/dist/config/resolved-config-op.js +1 -42
- package/dist/config/schema-migration.js +78 -5
- package/dist/config/schema-registry.js +52 -7
- package/dist/config-store.js +1309 -17
- package/dist/core/agent-application-service.js +220 -1
- package/dist/core/agent-ipc-registration.js +19 -2
- package/dist/core/agent-reload-coordinator.js +5 -0
- package/dist/core/agent-runtime.js +198 -54
- package/dist/core/auth/agent-delegation.js +14 -0
- package/dist/core/auth/operation-authorizer.js +16 -1
- package/dist/core/auth/operation-catalog.js +50 -7
- package/dist/core/baseagent-loader.js +30 -3
- package/dist/core/capability/capability-manager.js +16 -7
- package/dist/core/channel-runtime.js +4 -2
- package/dist/core/command/agent-control.js +20 -2
- package/dist/core/command/agent-template-menu.js +4 -3
- package/dist/core/command/cli-intent-parser.js +15 -0
- package/dist/core/command/menu-catalog.js +20 -4
- package/dist/core/command/menu-file-path.js +70 -0
- package/dist/core/command/menu-handler.js +91 -72
- package/dist/core/command/menu-protocol.js +5 -0
- package/dist/core/command/menu-query-batch.js +2 -2
- package/dist/core/command/private-mention-menu.js +71 -0
- package/dist/core/command/slash-handler.js +17 -26
- package/dist/core/command/team-workspace-bootstrap.js +2 -1
- package/dist/core/command/topic-slash.js +7 -1
- package/dist/core/daemon-bootstrap.js +0 -4
- package/dist/core/daemon-control.js +2 -1
- package/dist/core/daemon-lifecycle.js +13 -5
- package/dist/core/evolagent-registry.js +12 -7
- package/dist/core/handoff/runtime.js +1 -1
- package/dist/core/host-snapshot.js +8 -3
- package/dist/core/initialization/service.js +3 -0
- package/dist/core/interaction-router.js +130 -0
- package/dist/core/ipc-registration.js +4 -0
- package/dist/core/memory/consolidation-context.js +2 -1
- package/dist/core/memory/consolidation.js +35 -64
- package/dist/core/message/aun-ipc-sender.js +98 -21
- package/dist/core/message/aun-request-registry.js +31 -0
- package/dist/core/message/message-bridge.js +105 -6
- package/dist/core/message/message-log.js +8 -0
- package/dist/core/message/message-queue.js +5 -3
- package/dist/core/message/peer-mode.js +15 -4
- package/dist/core/message/response-engine.js +23 -8
- package/dist/core/message/send-options.js +37 -3
- package/dist/core/message/send-routing.js +11 -7
- package/dist/core/model/model-catalog.js +5 -5
- package/dist/core/ownership/owner-resolver.js +12 -86
- package/dist/core/pack-auth.js +4 -0
- package/dist/core/permission/ec-command-parser.js +182 -58
- package/dist/core/permission/protected-paths.js +64 -9
- package/dist/core/permission/services-path-acl.js +9 -2
- package/dist/core/permission/tool-policy.js +21 -9
- package/dist/core/session/adapters/claude-session-file-adapter.js +6 -2
- package/dist/core/session/adapters/codex-session-file-adapter.js +4 -0
- package/dist/core/session/session-manager.js +47 -10
- package/dist/core/session/session-mapper.js +16 -0
- package/dist/core/skill/index-generator.js +2 -3
- package/dist/core/skill/switch-resolver.js +3 -0
- package/dist/core/thread/command-parser.js +4 -1
- package/dist/core/thread/ipc-operation.js +4 -2
- package/dist/core/thread/thread-operation.js +25 -10
- package/dist/core/thread/thread-service.js +294 -55
- package/dist/core/thread/topic-id.js +52 -2
- package/dist/core/thread/types.js +15 -1
- package/dist/eck/kit-renderer.js +2 -1
- package/dist/ecweb/basic-settings-service.js +5 -9
- package/dist/ecweb/providers-service.js +4 -2
- package/dist/index.js +116 -41
- package/dist/ipc.js +58 -2
- package/dist/paths.js +48 -1
- package/dist/pay/command.js +38 -0
- package/dist/pay/protocol.js +136 -0
- package/dist/pay/runtime.js +188 -0
- package/dist/pay/service.js +384 -0
- package/dist/pay/store.js +81 -0
- package/dist/response-system/engines/v1/proactive-flow.js +29 -2
- package/dist/services/dispatcher.js +23 -5
- package/dist/services/host/main.js +388 -0
- package/dist/services/host/protocol.js +118 -0
- package/dist/services/host/resident.js +310 -0
- package/dist/services/host-client.js +386 -0
- package/dist/services/host-deploy.js +180 -0
- package/dist/services/host-launch.js +117 -0
- package/dist/services/host-recycle.js +203 -0
- package/dist/services/host-runtime.js +802 -0
- package/dist/services/idempotency.js +44 -86
- package/dist/services/index-generator.js +4 -3
- package/dist/services/index.js +176 -18
- package/dist/services/ipc-operation.js +204 -44
- package/dist/services/script-runner.js +515 -83
- package/dist/services/validation.js +109 -4
- package/dist/trigger/application-service.js +6 -4
- package/dist/trigger/local-files.js +19 -9
- package/dist/trigger/scheduler.js +22 -12
- package/dist/trigger/script-sandbox.js +51 -20
- package/dist/utils/aid-bind.js +3 -0
- package/dist/utils/evolcore-version.js +2 -2
- package/dist/utils/host-info.js +73 -0
- package/dist/utils/logger.js +2 -2
- package/dist/utils/media-cache.js +190 -43
- package/dist/utils/restart-safety.js +14 -1
- package/dist/utils/system-memory.js +113 -25
- package/dist/utils/systemd-lifecycle.js +154 -0
- package/dist/utils/windows-shell-trust.js +7 -3
- package/kits/docs/INDEX.md +3 -2
- 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 +1 -0
- package/kits/docs/channels/aun.md +1 -1
- package/kits/docs/evolcore/INDEX.md +7 -6
- package/kits/docs/evolcore/agent.md +36 -1
- package/kits/docs/evolcore/aid.md +20 -3
- package/kits/docs/evolcore/config.md +1 -1
- package/kits/docs/evolcore/group.md +2 -1
- package/kits/docs/evolcore/memory-tags.md +2 -0
- package/kits/docs/evolcore/menu-client.md +3 -3
- package/kits/docs/evolcore/menu-protocol.md +7 -0
- package/kits/docs/evolcore/model.md +3 -0
- package/kits/docs/evolcore/msg.md +68 -10
- package/kits/docs/evolcore/pay.md +34 -0
- package/kits/docs/evolcore/provider.md +21 -0
- package/kits/docs/evolcore/services.md +46 -18
- package/kits/docs/evolcore/thread-chain.md +2 -0
- package/kits/docs/evolcore/tool-authorization.md +10 -0
- package/kits/rules/01-overview.md +11 -32
- package/kits/rules/02-navigation.md +7 -0
- package/kits/rules/06-channel.md +3 -3
- package/kits/schemas/_meta.json +38 -5
- package/kits/schemas/agent-config.schema.21.json +974 -0
- package/kits/schemas/agent-config.schema.22.json +977 -0
- package/kits/schemas/agent-config.schema.23.json +958 -0
- package/kits/schemas/daemon.schema.10.json +373 -0
- package/kits/schemas/daemon.schema.9.json +12 -0
- package/kits/schemas/defaults.schema.7.json +472 -0
- package/kits/schemas/providers.schema.3.json +18 -2
- package/kits/schemas/relation-config.schema.13.json +289 -0
- package/kits/skills/.switches.json +13 -1
- package/kits/skills/ability/SKILL.md +229 -34
- package/kits/skills/ability/STRUCTURE.md +333 -0
- package/kits/skills/ability/references/cli.md +208 -0
- package/kits/skills/ability/references/development.md +107 -37
- package/kits/skills/ability/references/management.md +106 -46
- package/kits/skills/ability/references/runtime-protocol.md +65 -63
- package/kits/skills/agent-output-cards/SKILL.md +12 -5
- package/kits/skills/ec-group/SKILL.md +8 -6
- package/kits/skills/ec-group/TASK.md +186 -0
- package/kits/skills/ec-group/WORKLOG.md +180 -0
- package/kits/skills/ec-group-collaboration/SKILL.md +3 -3
- package/kits/skills/ec-pay/SKILL.md +101 -0
- package/kits/skills/ec-pay/references/pay-cli.md +110 -0
- package/kits/skills/ec-provider/SKILL.md +1 -1
- package/kits/skills/{ec-service-proxy → ec-proxy}/SKILL.md +8 -5
- package/kits/skills/ec-service-call/SKILL.md +135 -0
- package/kits/skills/ec-service-pack/SKILL.md +277 -0
- package/kits/skills/ec-trigger/SKILL.md +1 -1
- package/kits/templates/memory-consolidation/notes.md +2 -2
- package/kits/templates/memory-consolidation/workflow.md +46 -0
- package/kits/templates/system-fragments/channel.md +13 -4
- package/kits/templates/system-fragments/commands.md +4 -3
- package/kits/templates/system-fragments/reply.md +1 -0
- package/kits/templates/system-fragments/session.md +1 -1
- package/kits/templates/system-fragments/thread.md +27 -129
- package/kits/templates/system-fragments/venue.md +16 -0
- package/package.json +4 -5
- package/scripts/agent-template/inspect.mjs +37 -23
- package/scripts/agent-template/overlay.mjs +20 -2
- package/scripts/agent-template/shared/common.mjs +16 -4
- package/scripts/agent-template/shared/team-schema.json +20 -4
- package/scripts/agent-template/shared/template-contract.mjs +53 -13
- package/scripts/agent-template/shared/template-package.mjs +90 -26
- package/scripts/agent-template/shared/template-runtime.mjs +111 -1
- package/scripts/agent-template/shared/template.mjs +65 -7
- package/scripts/agent-template/team-pack.mjs +89 -33
- package/scripts/agent-template/team-preview.mjs +249 -5
- package/kits/docs/aun/ABILITY_CALLING.md +0 -280
- package/kits/docs/evolcore/ability.md +0 -185
- package/kits/skills/ability/references/calling.md +0 -56
- package/kits/skills/ability/references/contract-checklist.md +0 -37
- package/kits/skills/ability/references/recovery.md +0 -27
- /package/dist/{core/capability/providers → agents/gemini}/gemini-capability-provider.js +0 -0
|
@@ -27,7 +27,22 @@ function runtimeForExtension(script) {
|
|
|
27
27
|
}
|
|
28
28
|
const TIMEOUT_MIN = 1000;
|
|
29
29
|
const TIMEOUT_MAX = 300_000;
|
|
30
|
-
|
|
30
|
+
/**
|
|
31
|
+
* handler.name / handler.description 的长度上限。
|
|
32
|
+
*
|
|
33
|
+
* 比包级 `description`(200)更严:这两个字段会进 `services.skill` 的渲染文本,
|
|
34
|
+
* 而 skill 是给**另一个 Agent 读的**。一个包有 10 个 type 时,每个 200 字就是
|
|
35
|
+
* 2000 字噪音。收紧到 24 / 120,并配合 skill 渲染时的单行截断。
|
|
36
|
+
*/
|
|
37
|
+
export const HANDLER_NAME_MAX = 24;
|
|
38
|
+
export const HANDLER_DESCRIPTION_MAX = 120;
|
|
39
|
+
/**
|
|
40
|
+
* 脚本默认超时。必须**短于**调用方的等待期(`SERVICE_CALL_TIMEOUT_MS`,12 秒),
|
|
41
|
+
* 否则脚本的默认执行窗口比调用方愿意等的时间还长:每次都必然白跑,
|
|
42
|
+
* 调用方只看到 NO_RESULT 而服务端还在跑。
|
|
43
|
+
*/
|
|
44
|
+
export const DEFAULT_HANDLER_TIMEOUT_MS = 10_000;
|
|
45
|
+
const TIMEOUT_DEFAULT = DEFAULT_HANDLER_TIMEOUT_MS;
|
|
31
46
|
const QUOTA_DEFAULT_BUILTIN = { perMinute: 20, perHour: 200 };
|
|
32
47
|
const QUOTA_DEFAULT_SERVICE = { perMinute: 50, perHour: 1000 };
|
|
33
48
|
function isRecord(value) {
|
|
@@ -44,6 +59,20 @@ function optionalString(value, field, errors, max) {
|
|
|
44
59
|
errors.push(`${field} is too long (max ${max})`);
|
|
45
60
|
return value;
|
|
46
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* handler 的展示性文本(`name` / `description`)。
|
|
64
|
+
*
|
|
65
|
+
* 与 `optionalString` 的差别只有一点:**纯空白视为未声明**。这两个字段只用于展示,
|
|
66
|
+
* 写一个空串和没写没有任何区别;保留空串反而会让 `describe` 输出里出现
|
|
67
|
+
* `"name": ""`,调用方无法区分「有标题但为空」和「没标题」。
|
|
68
|
+
*/
|
|
69
|
+
function optionalLabel(value, field, max, errors) {
|
|
70
|
+
const text = optionalString(value, field, errors, max);
|
|
71
|
+
if (text === undefined)
|
|
72
|
+
return undefined;
|
|
73
|
+
const trimmed = text.trim();
|
|
74
|
+
return trimmed ? trimmed : undefined;
|
|
75
|
+
}
|
|
47
76
|
function intInRange(value, field, min, max, errors) {
|
|
48
77
|
if (typeof value !== 'number' || !Number.isInteger(value) || value < min || value > max) {
|
|
49
78
|
errors.push(`${field} must be an integer between ${min} and ${max}`);
|
|
@@ -118,10 +147,12 @@ function validateHandler(raw, errors) {
|
|
|
118
147
|
errors.push('listen[].handler must be an object');
|
|
119
148
|
return undefined;
|
|
120
149
|
}
|
|
121
|
-
const extra = Object.keys(raw).filter(key => !['script', 'runtime', 'args', 'timeoutMs'].includes(key));
|
|
150
|
+
const extra = Object.keys(raw).filter(key => !['script', 'runtime', 'args', 'timeoutMs', 'name', 'description', 'mode', 'resident'].includes(key));
|
|
122
151
|
if (extra.length)
|
|
123
152
|
errors.push(`listen[].handler has unknown fields: ${extra.join(', ')}`);
|
|
124
153
|
const script = validateScriptPath(raw.script, errors);
|
|
154
|
+
const name = optionalLabel(raw.name, 'listen[].handler.name', HANDLER_NAME_MAX, errors);
|
|
155
|
+
const description = optionalLabel(raw.description, 'listen[].handler.description', HANDLER_DESCRIPTION_MAX, errors);
|
|
125
156
|
if (raw.runtime !== undefined && !RUNTIME_WHITELIST.includes(raw.runtime)) {
|
|
126
157
|
errors.push(`listen[].handler.runtime must be one of ${RUNTIME_WHITELIST.join('/')}`);
|
|
127
158
|
}
|
|
@@ -140,6 +171,7 @@ function validateHandler(raw, errors) {
|
|
|
140
171
|
const timeoutMs = raw.timeoutMs === undefined
|
|
141
172
|
? TIMEOUT_DEFAULT
|
|
142
173
|
: intInRange(raw.timeoutMs, 'listen[].handler.timeoutMs', TIMEOUT_MIN, TIMEOUT_MAX, errors);
|
|
174
|
+
const mode = validateHandlerMode(raw.mode, raw.resident, errors);
|
|
143
175
|
if (script === undefined)
|
|
144
176
|
return undefined;
|
|
145
177
|
return {
|
|
@@ -147,6 +179,60 @@ function validateHandler(raw, errors) {
|
|
|
147
179
|
...(raw.runtime !== undefined ? { runtime: raw.runtime } : {}),
|
|
148
180
|
...(Array.isArray(raw.args) ? { args: raw.args } : {}),
|
|
149
181
|
timeoutMs: timeoutMs ?? TIMEOUT_DEFAULT,
|
|
182
|
+
...(name !== undefined ? { name } : {}),
|
|
183
|
+
...(description !== undefined ? { description } : {}),
|
|
184
|
+
...(mode !== undefined ? { mode: mode.mode } : {}),
|
|
185
|
+
...(mode?.resident ? { resident: mode.resident } : {}),
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* `handler.mode` / `handler.resident` 校验。
|
|
190
|
+
*
|
|
191
|
+
* `resident` 子对象只在 `mode:"resident"` 时有意义——其他形态下出现就报错,
|
|
192
|
+
* 因为静默忽略会让作者以为调参生效了,而实际写的是个死配置。
|
|
193
|
+
*/
|
|
194
|
+
function validateHandlerMode(rawMode, rawResident, errors) {
|
|
195
|
+
if (rawMode !== undefined && rawMode !== 'spawn' && rawMode !== 'resident') {
|
|
196
|
+
errors.push('listen[].handler.mode must be "spawn" or "resident"');
|
|
197
|
+
return undefined;
|
|
198
|
+
}
|
|
199
|
+
// 未声明时**不落默认值**:让"没写"与"显式写 spawn"在输出里可区分——
|
|
200
|
+
// 否则 describe/status 会显示一个用户从未写过的 mode,排查时容易误判。
|
|
201
|
+
const declared = rawMode === 'spawn' || rawMode === 'resident' ? rawMode : undefined;
|
|
202
|
+
const mode = declared ?? 'spawn';
|
|
203
|
+
if (rawResident === undefined)
|
|
204
|
+
return declared ? { mode: declared } : undefined;
|
|
205
|
+
if (mode !== 'resident') {
|
|
206
|
+
errors.push('listen[].handler.resident is only meaningful when handler.mode is "resident"');
|
|
207
|
+
return declared ? { mode: declared } : undefined;
|
|
208
|
+
}
|
|
209
|
+
if (!isRecord(rawResident)) {
|
|
210
|
+
errors.push('listen[].handler.resident must be an object');
|
|
211
|
+
return { mode: declared };
|
|
212
|
+
}
|
|
213
|
+
const extra = Object.keys(rawResident).filter(key => !['startTimeoutMs', 'softTimeoutMs', 'hardTimeoutAfter'].includes(key));
|
|
214
|
+
if (extra.length)
|
|
215
|
+
errors.push(`listen[].handler.resident has unknown fields: ${extra.join(', ')}`);
|
|
216
|
+
const startTimeoutMs = rawResident.startTimeoutMs === undefined
|
|
217
|
+
? undefined
|
|
218
|
+
: intInRange(rawResident.startTimeoutMs, 'listen[].handler.resident.startTimeoutMs', TIMEOUT_MIN, 120_000, errors);
|
|
219
|
+
const softTimeoutMs = rawResident.softTimeoutMs === undefined
|
|
220
|
+
? undefined
|
|
221
|
+
: intInRange(rawResident.softTimeoutMs, 'listen[].handler.resident.softTimeoutMs', TIMEOUT_MIN, TIMEOUT_MAX, errors);
|
|
222
|
+
const hardTimeoutAfter = rawResident.hardTimeoutAfter === undefined
|
|
223
|
+
? undefined
|
|
224
|
+
: intInRange(rawResident.hardTimeoutAfter, 'listen[].handler.resident.hardTimeoutAfter', 1, 100, errors);
|
|
225
|
+
return {
|
|
226
|
+
...(declared ? { mode: declared } : {}),
|
|
227
|
+
...((startTimeoutMs ?? softTimeoutMs ?? hardTimeoutAfter) !== undefined
|
|
228
|
+
? {
|
|
229
|
+
resident: {
|
|
230
|
+
...(startTimeoutMs !== undefined ? { startTimeoutMs } : {}),
|
|
231
|
+
...(softTimeoutMs !== undefined ? { softTimeoutMs } : {}),
|
|
232
|
+
...(hardTimeoutAfter !== undefined ? { hardTimeoutAfter } : {}),
|
|
233
|
+
},
|
|
234
|
+
}
|
|
235
|
+
: {}),
|
|
150
236
|
};
|
|
151
237
|
}
|
|
152
238
|
function validateListenEntry(raw, errors) {
|
|
@@ -366,7 +452,7 @@ export function validateRouterConfig(raw) {
|
|
|
366
452
|
const errors = [];
|
|
367
453
|
if (!isRecord(raw))
|
|
368
454
|
return { ok: false, errors: ['services-config.json must be a JSON object'] };
|
|
369
|
-
const extra = Object.keys(raw).filter(key => !['v', 'enabled', 'rateLimit', 'rules'].includes(key));
|
|
455
|
+
const extra = Object.keys(raw).filter(key => !['v', 'enabled', 'rateLimit', 'rules', 'host'].includes(key));
|
|
370
456
|
if (extra.length)
|
|
371
457
|
errors.push(`unknown top-level fields: ${extra.join(', ')}`);
|
|
372
458
|
if (raw.v !== 1)
|
|
@@ -391,11 +477,30 @@ export function validateRouterConfig(raw) {
|
|
|
391
477
|
}
|
|
392
478
|
}
|
|
393
479
|
const rules = validateRules(raw.rules, errors);
|
|
480
|
+
const host = validateHostConfig(raw.host, errors);
|
|
394
481
|
if (errors.length)
|
|
395
482
|
return { ok: false, errors };
|
|
396
483
|
return {
|
|
397
484
|
ok: true,
|
|
398
485
|
errors: [],
|
|
399
|
-
value: { v: 1, enabled: raw.enabled !== false, rateLimit, rules },
|
|
486
|
+
value: { v: 1, enabled: raw.enabled !== false, rateLimit, rules, ...(host ? { host } : {}) },
|
|
400
487
|
};
|
|
401
488
|
}
|
|
489
|
+
/**
|
|
490
|
+
* `host` 段。当前只认 `enabled`;P3 的自管理参数(空闲窗口、间隔分级)上线时在这里扩,
|
|
491
|
+
* **未知字段一律报错**——静默忽略会让用户以为开关生效了。
|
|
492
|
+
*/
|
|
493
|
+
function validateHostConfig(raw, errors) {
|
|
494
|
+
if (raw === undefined)
|
|
495
|
+
return undefined;
|
|
496
|
+
if (!isRecord(raw)) {
|
|
497
|
+
errors.push('host must be an object');
|
|
498
|
+
return undefined;
|
|
499
|
+
}
|
|
500
|
+
const extra = Object.keys(raw).filter(key => key !== 'enabled');
|
|
501
|
+
if (extra.length)
|
|
502
|
+
errors.push(`host has unknown fields: ${extra.join(', ')}`);
|
|
503
|
+
if (raw.enabled !== undefined && typeof raw.enabled !== 'boolean')
|
|
504
|
+
errors.push('host.enabled must be a boolean');
|
|
505
|
+
return { ...(raw.enabled !== undefined ? { enabled: raw.enabled } : {}) };
|
|
506
|
+
}
|
|
@@ -41,12 +41,12 @@ export class TriggerSchedulerRegistry {
|
|
|
41
41
|
}
|
|
42
42
|
return { enabled, today: { calls, failures } };
|
|
43
43
|
}
|
|
44
|
-
async replace(agentAid, createScheduler) {
|
|
44
|
+
async replace(agentAid, createScheduler, admit) {
|
|
45
45
|
await this.schedulers.get(agentAid)?.stop();
|
|
46
46
|
const scheduler = createScheduler();
|
|
47
47
|
this.schedulers.set(agentAid, scheduler);
|
|
48
48
|
try {
|
|
49
|
-
await scheduler.init();
|
|
49
|
+
await scheduler.init(admit);
|
|
50
50
|
}
|
|
51
51
|
catch (error) {
|
|
52
52
|
logger.error(`[Trigger] Scheduler init failed for ${agentAid}: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -86,8 +86,10 @@ export class TriggerSchedulerRegistry {
|
|
|
86
86
|
await Promise.all([...this.schedulers.values()].map(scheduler => scheduler.waitForIdle(timeoutMs)));
|
|
87
87
|
}
|
|
88
88
|
async suspendForDaemonExit() {
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
// Mark all resumable runs suspended before yielding: daemon queue interruption
|
|
90
|
+
// starts as soon as this method returns its promise. Listeners may be async.
|
|
91
|
+
const suspending = [...this.schedulers.values()].map(scheduler => scheduler.suspendForDaemonExit());
|
|
92
|
+
await Promise.all([...suspending, this.notify(listener => listener.suspending?.())]);
|
|
91
93
|
}
|
|
92
94
|
}
|
|
93
95
|
export function createTriggerChannelResolver({ agentRegistry, channelInstances, daemonChannel, daemonTriggerOwner, }) {
|
|
@@ -114,6 +114,12 @@ function assertSessionRuntimeScope(candidate, runtime, errorMessage) {
|
|
|
114
114
|
throw new Error(errorMessage);
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
|
+
function sameFileIdentity(left, right) {
|
|
118
|
+
return left.dev === right.dev && left.ino === right.ino;
|
|
119
|
+
}
|
|
120
|
+
function sameFileMetadata(left, right) {
|
|
121
|
+
return left.size === right.size && left.mtimeMs === right.mtimeMs && left.ctimeMs === right.ctimeMs;
|
|
122
|
+
}
|
|
117
123
|
export function readManagedLocalFile(input, scope, kind) {
|
|
118
124
|
const sourceLabel = kind === 'trigger' ? 'Trigger input' : 'Attachment source';
|
|
119
125
|
const resolved = resolveManagedLocalPath(input, scope, kind);
|
|
@@ -126,16 +132,21 @@ export function readManagedLocalFile(input, scope, kind) {
|
|
|
126
132
|
const descriptor = fs.openSync(resolved, fs.constants.O_RDONLY | noFollow);
|
|
127
133
|
try {
|
|
128
134
|
const opened = fs.fstatSync(descriptor);
|
|
129
|
-
|
|
130
|
-
|
|
135
|
+
const openedPath = fs.lstatSync(resolved);
|
|
136
|
+
// Windows path and handle stats can report different dev/ino values for the
|
|
137
|
+
// same file. Compare identities within each API and metadata across APIs;
|
|
138
|
+
// retain the additional path-to-handle identity check on POSIX.
|
|
139
|
+
if (!opened.isFile() || !openedPath.isFile() || openedPath.isSymbolicLink()
|
|
140
|
+
|| !sameFileIdentity(openedPath, expected) || !sameFileMetadata(openedPath, expected)
|
|
141
|
+
|| (process.platform !== 'win32' && !sameFileIdentity(opened, expected))
|
|
142
|
+
|| !sameFileMetadata(opened, expected)
|
|
143
|
+
|| (scope && (opened.nlink !== 1 || openedPath.nlink !== 1))
|
|
131
144
|
|| resolveManagedLocalPath(input, scope, kind) !== resolved) {
|
|
132
145
|
throw new Error(`${sourceLabel} changed during validation`);
|
|
133
146
|
}
|
|
134
147
|
if (opened.size > TRIGGER_LOCAL_FILE_LIMIT) {
|
|
135
148
|
throw new Error(`${sourceLabel} exceeds the 4 MiB limit`);
|
|
136
149
|
}
|
|
137
|
-
const openedMtime = opened.mtimeMs;
|
|
138
|
-
const openedCtime = opened.ctimeMs;
|
|
139
150
|
const buffer = Buffer.alloc(Math.min(opened.size + 1, TRIGGER_LOCAL_FILE_LIMIT + 1));
|
|
140
151
|
let length = 0;
|
|
141
152
|
while (length < buffer.length) {
|
|
@@ -146,11 +157,10 @@ export function readManagedLocalFile(input, scope, kind) {
|
|
|
146
157
|
}
|
|
147
158
|
const afterRead = fs.fstatSync(descriptor);
|
|
148
159
|
const afterPath = fs.lstatSync(resolved);
|
|
149
|
-
if (length !== opened.size || afterRead.
|
|
150
|
-
|| afterRead
|
|
151
|
-
|| afterPath
|
|
152
|
-
|| !afterPath.isFile() || afterPath.isSymbolicLink()
|
|
153
|
-
|| afterPath.size !== opened.size || afterPath.mtimeMs !== openedMtime || afterPath.ctimeMs !== openedCtime
|
|
160
|
+
if (length !== opened.size || !afterRead.isFile()
|
|
161
|
+
|| !sameFileIdentity(afterRead, opened) || !sameFileMetadata(afterRead, opened)
|
|
162
|
+
|| !sameFileIdentity(afterPath, expected)
|
|
163
|
+
|| !afterPath.isFile() || afterPath.isSymbolicLink() || !sameFileMetadata(afterPath, opened)
|
|
154
164
|
|| (scope && (afterRead.nlink !== 1 || afterPath.nlink !== 1))
|
|
155
165
|
|| resolveManagedLocalPath(input, scope, kind) !== resolved) {
|
|
156
166
|
throw new Error(`${sourceLabel} changed during reading`);
|
|
@@ -84,7 +84,7 @@ export class TriggerRuntimeScheduler {
|
|
|
84
84
|
});
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
|
-
async init() {
|
|
87
|
+
async init(admit) {
|
|
88
88
|
const stopped = this.stop();
|
|
89
89
|
const generation = this.lifecycleGeneration;
|
|
90
90
|
await stopped;
|
|
@@ -95,17 +95,27 @@ export class TriggerRuntimeScheduler {
|
|
|
95
95
|
await this.audit.initializeHistory?.();
|
|
96
96
|
if (this.stopping || generation !== this.lifecycleGeneration)
|
|
97
97
|
return;
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
this.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
98
|
+
// Shared history imports must register before bounded startup admission;
|
|
99
|
+
// otherwise each queue wave scans the same global audit files again.
|
|
100
|
+
const initialize = async () => {
|
|
101
|
+
if (this.stopping || generation !== this.lifecycleGeneration)
|
|
102
|
+
return;
|
|
103
|
+
await this.recoverOpenRuns();
|
|
104
|
+
if (this.stopping || generation !== this.lifecycleGeneration)
|
|
105
|
+
return;
|
|
106
|
+
for (const definition of this.manager.list()) {
|
|
107
|
+
if (this.recoveredOneShotIds.has(definition.id))
|
|
108
|
+
continue;
|
|
109
|
+
this.schedule(definition);
|
|
110
|
+
}
|
|
111
|
+
this.recoveredOneShotIds.clear();
|
|
112
|
+
this.initialized = true;
|
|
113
|
+
logger.info(`[Trigger] scheduler initialized for ${this.manager.agentAid}`);
|
|
114
|
+
};
|
|
115
|
+
if (admit)
|
|
116
|
+
await admit(initialize);
|
|
117
|
+
else
|
|
118
|
+
await initialize();
|
|
109
119
|
}
|
|
110
120
|
async stop() {
|
|
111
121
|
this.lifecycleGeneration++;
|
|
@@ -193,6 +193,8 @@ export async function buildTriggerScriptLaunch(input) {
|
|
|
193
193
|
process.execPath,
|
|
194
194
|
path.dirname(process.execPath),
|
|
195
195
|
snapshotDir,
|
|
196
|
+
// 服务常驻宿主:包脚本快照根(只读)。不传时这里是空数组,行为不变。
|
|
197
|
+
...(input.extraReadRoots ?? []),
|
|
196
198
|
].filter(value => fs.existsSync(value));
|
|
197
199
|
const entries = [
|
|
198
200
|
{ path: { type: 'special', value: { kind: 'root' } },
|
|
@@ -201,19 +203,16 @@ export async function buildTriggerScriptLaunch(input) {
|
|
|
201
203
|
filesystemEntry(projectPath, readonly ? 'read' : 'write'),
|
|
202
204
|
filesystemEntry(snapshotDir, 'read'),
|
|
203
205
|
filesystemEntry(workDir, 'write'),
|
|
206
|
+
// 额外可写根(服务宿主的工作目录)。不存在时 `filesystemEntry` 仍是合法条目,
|
|
207
|
+
// 但策略里指向不存在的路径不会生效,所以调用方必须先建好目录。
|
|
208
|
+
...(input.extraWriteRoots ?? []).map(value => filesystemEntry(value, 'write')),
|
|
204
209
|
filesystemEntry(windowsBackend.home, 'deny'),
|
|
205
|
-
//
|
|
206
|
-
//
|
|
207
|
-
//
|
|
208
|
-
//
|
|
209
|
-
//
|
|
210
|
-
//
|
|
211
|
-
// **不能写 `deny`**:Codex 的 deny 连读一起拒,而服务脚本要读自己的
|
|
212
|
-
// pack.json。真需要拦写也拦不住显式子级 Allow——那由 ACL 层负责
|
|
213
|
-
// (见 src/core/permission/services-path-acl.ts)。
|
|
214
|
-
...(input.trigger.labels?.kind === 'services'
|
|
215
|
-
? [filesystemEntry(path.join(root, 'agents', input.trigger.agentAid, 'services'), 'read')]
|
|
216
|
-
: []),
|
|
210
|
+
// 这里不再为 `services` 单独追加条目。`services` 已由
|
|
211
|
+
// `getExistingLClassReadOnlyTargets` 纳入 L 类只读目标,win32 下写保护由
|
|
212
|
+
// 「没有任何条目授 write」+ ACL 的 DENY(写) 共同承担(见
|
|
213
|
+
// src/core/permission/services-path-acl.ts)。原先那条按
|
|
214
|
+
// `trigger.labels.kind === 'services'` 分流的 read 条目是空操作:实测有它无它,
|
|
215
|
+
// 服务脚本对 services 树的 list / read / write 结果完全相同。
|
|
217
216
|
...Object.entries(filesystem).flatMap(([value, access]) => typeof access === 'number' ? [] : [{
|
|
218
217
|
path: /[*?[\]]/.test(value)
|
|
219
218
|
? { type: 'glob_pattern', pattern: value }
|
|
@@ -248,7 +247,7 @@ export async function buildTriggerScriptLaunch(input) {
|
|
|
248
247
|
env: { ...env, CODEX_HOME: windowsBackend.home },
|
|
249
248
|
cleanup,
|
|
250
249
|
};
|
|
251
|
-
launch.prepare = signal => verifyWindowsReadIsolation(launch, sandboxArgs, runDir, workDir, signal);
|
|
250
|
+
launch.prepare = signal => verifyWindowsReadIsolation(launch, sandboxArgs, runDir, workDir, signal, input.verifyGrandchild === true);
|
|
252
251
|
return launch;
|
|
253
252
|
}
|
|
254
253
|
const launch = sandboxDecision.state === 'off'
|
|
@@ -266,7 +265,14 @@ export async function buildTriggerScriptLaunch(input) {
|
|
|
266
265
|
const separator = launch.args.indexOf('--');
|
|
267
266
|
if (separator < 0)
|
|
268
267
|
throw new Error('bubblewrap launch is missing its command separator');
|
|
269
|
-
const runMountArgs = [
|
|
268
|
+
const runMountArgs = [
|
|
269
|
+
'--ro-bind', runDir, runDir,
|
|
270
|
+
'--bind', workDir, workDir,
|
|
271
|
+
...(input.extraWriteRoots ?? []).flatMap(root => ['--bind', root, root]),
|
|
272
|
+
// 额外只读根(服务宿主的包脚本快照根)。bwrap 里**没有挂载就等于不存在**,
|
|
273
|
+
// 与 Windows 侧的 read 策略条目是同一件事的两平台写法,必须成对出现。
|
|
274
|
+
...(input.extraReadRoots ?? []).flatMap(root => ['--ro-bind', root, root]),
|
|
275
|
+
];
|
|
270
276
|
if (!launch.args.slice(0, separator).includes('--chdir'))
|
|
271
277
|
runMountArgs.push('--chdir', projectPath);
|
|
272
278
|
launch.args.splice(separator, 0, ...runMountArgs);
|
|
@@ -375,7 +381,7 @@ function assertRealDirectory(value, label) {
|
|
|
375
381
|
function samePath(left, right) {
|
|
376
382
|
return isSameOrDescendant(left, right) && isSameOrDescendant(right, left);
|
|
377
383
|
}
|
|
378
|
-
function readScriptSnapshot(value, triggerDir) {
|
|
384
|
+
export function readScriptSnapshot(value, triggerDir) {
|
|
379
385
|
const scriptPath = path.resolve(value);
|
|
380
386
|
const validate = () => {
|
|
381
387
|
if (!isSameOrDescendant(scriptPath, triggerDir))
|
|
@@ -439,7 +445,7 @@ const SCRIPT_STAGING_FILE_COUNT = 2_000;
|
|
|
439
445
|
* `preserveNodeModuleType` 统一合成,避免 `wx` 冲突)。每个文件走与入口相同的
|
|
440
446
|
* lstat/fd 校验(防 TOCTOU/软链),越界文件直接抛错走沙箱不可用降级。
|
|
441
447
|
*/
|
|
442
|
-
function stageScriptSnapshot(scriptSource, triggerDir, scriptBytes, snapshotDir) {
|
|
448
|
+
export function stageScriptSnapshot(scriptSource, triggerDir, scriptBytes, snapshotDir) {
|
|
443
449
|
const scriptName = path.basename(scriptSource);
|
|
444
450
|
const scriptPath = path.join(snapshotDir, scriptName);
|
|
445
451
|
fs.writeFileSync(scriptPath, scriptBytes, { flag: 'wx', mode: 0o400 });
|
|
@@ -477,7 +483,7 @@ function stageScriptSnapshot(scriptSource, triggerDir, scriptBytes, snapshotDir)
|
|
|
477
483
|
stage(scriptDir, '');
|
|
478
484
|
return scriptPath;
|
|
479
485
|
}
|
|
480
|
-
function preserveNodeModuleType(runtime, scriptPath, snapshotDir) {
|
|
486
|
+
export function preserveNodeModuleType(runtime, scriptPath, snapshotDir) {
|
|
481
487
|
if (!/^node(?:\.exe)?$/i.test(path.basename(runtime)) || path.extname(scriptPath) !== '.js')
|
|
482
488
|
return;
|
|
483
489
|
let current = path.dirname(scriptPath);
|
|
@@ -537,7 +543,7 @@ function filesystemEntry(value, access) {
|
|
|
537
543
|
* (证明 deny 真的被沙箱执行;这一步失败说明沙箱没起效,必须拒跑)
|
|
538
544
|
* 3. 在 workDir 写文件 → 必须成功(证明 scoped 路径没有把整个文件系统锁死)
|
|
539
545
|
*/
|
|
540
|
-
async function verifyWindowsReadIsolation(launch, sandboxArgs, runDir, workDir, signal) {
|
|
546
|
+
async function verifyWindowsReadIsolation(launch, sandboxArgs, runDir, workDir, signal, verifyGrandchild = false) {
|
|
541
547
|
signal?.throwIfAborted();
|
|
542
548
|
const canary = path.join(runDir, 'read-isolation-canary');
|
|
543
549
|
const writableProbe = path.join(workDir, 'write-isolation-probe');
|
|
@@ -558,6 +564,30 @@ async function verifyWindowsReadIsolation(launch, sandboxArgs, runDir, workDir,
|
|
|
558
564
|
'fs.writeFileSync(process.argv[2], "allowed");',
|
|
559
565
|
'process.stdout.write("evolcore-trigger-sandbox-ready");',
|
|
560
566
|
].join('\n');
|
|
567
|
+
// 孙进程版:沙箱内的这个 node 再 spawn 一个 node,由**后者**去读 deny 路径。
|
|
568
|
+
// 服务宿主正是这个形状(宿主 → 脚本次进程),直接子进程被拦不能证明孙进程也被拦。
|
|
569
|
+
const grandchildDenyProbe = [
|
|
570
|
+
'const { spawn } = require("node:child_process");',
|
|
571
|
+
'const inner = [',
|
|
572
|
+
' "const fs = require(\\"node:fs\\");",',
|
|
573
|
+
' "let denied = false;",',
|
|
574
|
+
' "try { fs.readFileSync(process.argv[1]); } catch (e) {",',
|
|
575
|
+
' "if (e.code === \\"EACCES\\" || e.code === \\"EPERM\\" || e.code === \\"ENOENT\\") denied = true; else throw e;",',
|
|
576
|
+
' "}",',
|
|
577
|
+
' "process.stdout.write(denied ? \\"denied\\" : \\"readable\\");",',
|
|
578
|
+
'].join("\\n");',
|
|
579
|
+
'const child = spawn(process.execPath, ["-e", inner, process.argv[1]], { stdio: ["ignore", "pipe", "inherit"] });',
|
|
580
|
+
'let out = "";',
|
|
581
|
+
'child.stdout.on("data", b => { out += b.toString(); });',
|
|
582
|
+
'child.on("close", code => {',
|
|
583
|
+
' if (code !== 0) { process.stderr.write("grandchild probe exited " + code); process.exit(92); }',
|
|
584
|
+
' if (out.trim() !== "denied") {',
|
|
585
|
+
' process.stderr.write("grandchild escaped the sandbox: denied path was readable from a grandchild process");',
|
|
586
|
+
' process.exit(90);',
|
|
587
|
+
' }',
|
|
588
|
+
' process.stdout.write("evolcore-trigger-sandbox-ready");',
|
|
589
|
+
'});',
|
|
590
|
+
].join('\n');
|
|
561
591
|
const withExtraEntry = (extra) => {
|
|
562
592
|
const args = [...sandboxArgs];
|
|
563
593
|
const stateIndex = args.indexOf('--sandbox-state-json') + 1;
|
|
@@ -570,10 +600,11 @@ async function verifyWindowsReadIsolation(launch, sandboxArgs, runDir, workDir,
|
|
|
570
600
|
};
|
|
571
601
|
try {
|
|
572
602
|
await runWindowsIsolationProbe(launch, withExtraEntry(filesystemEntry(canary, 'read')), readProbe, [canary], signal);
|
|
573
|
-
await runWindowsIsolationProbe(launch, withExtraEntry(filesystemEntry(canary, 'deny')), denyProbe, [canary, writableProbe], signal);
|
|
603
|
+
await runWindowsIsolationProbe(launch, withExtraEntry(filesystemEntry(canary, 'deny')), verifyGrandchild ? grandchildDenyProbe : denyProbe, verifyGrandchild ? [canary] : [canary, writableProbe], signal);
|
|
574
604
|
}
|
|
575
605
|
catch (error) {
|
|
576
|
-
throw new Error(`Windows sandbox cannot prove scoped read isolation
|
|
606
|
+
throw new Error(`Windows sandbox cannot prove scoped read isolation${verifyGrandchild ? ' (including grandchild processes)' : ''}; `
|
|
607
|
+
+ `scoped execution is refused: ${error?.message || String(error)}`, { cause: error });
|
|
577
608
|
}
|
|
578
609
|
finally {
|
|
579
610
|
try {
|
package/dist/utils/aid-bind.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { randomBytes, randomUUID, timingSafeEqual, createHash } from 'crypto';
|
|
2
|
+
import os from 'node:os';
|
|
2
3
|
import { loadAgent } from '../config-store.js';
|
|
3
4
|
import { isValidAid } from '../aun/aid/validation.js';
|
|
4
5
|
import { ownerResolver } from '../core/ownership/owner-resolver.js';
|
|
@@ -42,6 +43,8 @@ export class BindService {
|
|
|
42
43
|
return { ok: true, taskId: session.id, expiresAt: session.expiresAt, qrData: {
|
|
43
44
|
type: 'evolcore.bind', version: readInstalledEvolcoreVersion(),
|
|
44
45
|
platform: process.platform === 'win32' ? 'windows' : process.platform,
|
|
46
|
+
// 机器名随二维码带给 App:主机列表的默认显示名要用它,而不是 agent 的名字。
|
|
47
|
+
hostName: os.hostname(),
|
|
45
48
|
bindType: session.bindType, subjectAid, receiverAid: this.options.receiverAid,
|
|
46
49
|
token: session.token, expiresAt: session.expiresAt,
|
|
47
50
|
} };
|
|
@@ -5,8 +5,8 @@ import { fileURLToPath } from 'url';
|
|
|
5
5
|
import { getPackageRoot } from '../paths.js';
|
|
6
6
|
// Embedded by bin/ec-build.mjs; loaded processes retain these values across rebuilds.
|
|
7
7
|
// @evolcore-build-identity:start
|
|
8
|
-
export const RUNTIME_BUILD_ID = "sha256:
|
|
9
|
-
export const RUNTIME_BUILD_TIME = "2026-11-
|
|
8
|
+
export const RUNTIME_BUILD_ID = "sha256:3561d8e3c0e3ce13b94f99d2";
|
|
9
|
+
export const RUNTIME_BUILD_TIME = "2026-11-17T15:02:32.541Z";
|
|
10
10
|
// @evolcore-build-identity:end
|
|
11
11
|
let cachedVersion;
|
|
12
12
|
let cachedFlavor;
|
package/dist/utils/host-info.js
CHANGED
|
@@ -255,6 +255,7 @@ export function readHostInfo(evolcoreVersion, evolcoreHomePath, options = {}) {
|
|
|
255
255
|
os: {
|
|
256
256
|
platform,
|
|
257
257
|
platformName: detectPlatformName(platform),
|
|
258
|
+
productName: null,
|
|
258
259
|
release: readOsReleaseVersion(),
|
|
259
260
|
distributionId: release.id,
|
|
260
261
|
version: release.version,
|
|
@@ -373,6 +374,78 @@ export async function probeVirtualization() {
|
|
|
373
374
|
return 'unknown';
|
|
374
375
|
}
|
|
375
376
|
}
|
|
377
|
+
/** Windows 11 的 build 分界:22000 是 21H2 首发 build,Windows 10 最高到 19045。 */
|
|
378
|
+
const WINDOWS_11_MIN_BUILD = 22000;
|
|
379
|
+
/**
|
|
380
|
+
* 完整 OS 产品名。只能异步:Windows 走注册表(约 50ms 子进程),Linux 读
|
|
381
|
+
* os-release 的 PRETTY_NAME。macOS 没有等价的廉价来源,返回 null 由界面回落
|
|
382
|
+
* 到 platformName + release。
|
|
383
|
+
*
|
|
384
|
+
* Windows 不能直接用 ProductName:微软为兼容性在 Windows 11 上仍把它写成
|
|
385
|
+
* "Windows 10 Pro"(本机实测 ProductName=Windows 10 Pro,CurrentBuild=26200,
|
|
386
|
+
* 而 Caption 报的是 Windows 11 专业版)。所以产品名里的主版本必须按 build 号纠正,
|
|
387
|
+
* 不能用 `os.release()` 的 "10.0.x"——Win10 和 Win11 的主版本号都是 10.0。
|
|
388
|
+
*/
|
|
389
|
+
export async function probeOsProductName() {
|
|
390
|
+
try {
|
|
391
|
+
if (process.platform === 'win32') {
|
|
392
|
+
const { ok, stdout } = await runExec('reg', [
|
|
393
|
+
'query', 'HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion',
|
|
394
|
+
], 4000);
|
|
395
|
+
if (!ok)
|
|
396
|
+
return null;
|
|
397
|
+
return readWindowsProductName(stdout);
|
|
398
|
+
}
|
|
399
|
+
if (process.platform === 'linux') {
|
|
400
|
+
const pretty = readOsReleasePrettyName();
|
|
401
|
+
if (pretty)
|
|
402
|
+
return pretty;
|
|
403
|
+
const release = readOsRelease();
|
|
404
|
+
return release.version ? `${release.id ?? 'Linux'} ${release.version}` : null;
|
|
405
|
+
}
|
|
406
|
+
return null;
|
|
407
|
+
}
|
|
408
|
+
catch {
|
|
409
|
+
return null;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* 从 `reg query ...\CurrentVersion` 的输出里拼出可信的 Windows 产品名。
|
|
414
|
+
*
|
|
415
|
+
* 注册表值本身在 Win11 上是错的,唯一可靠的版本判据是 CurrentBuild。产品名可能有
|
|
416
|
+
* 本地化后缀("专业版"/"Pro"),所以只替换 "Windows <主版本>" 这一小段,其余原样
|
|
417
|
+
* 保留。build 就读不到时宁可返回原值,也不猜版本。
|
|
418
|
+
*/
|
|
419
|
+
export function readWindowsProductName(registryOutput) {
|
|
420
|
+
const values = new Map();
|
|
421
|
+
for (const line of registryOutput.split(/\r?\n/u)) {
|
|
422
|
+
// 每行形如 " ProductName REG_SZ Windows 10 Pro"
|
|
423
|
+
const match = line.match(/^\s{2,}(\S+)\s+REG_(?:SZ|EXPAND_SZ)\s+(.+)$/u);
|
|
424
|
+
if (match)
|
|
425
|
+
values.set(match[1], match[2].trim());
|
|
426
|
+
}
|
|
427
|
+
const productName = values.get('ProductName');
|
|
428
|
+
if (!productName)
|
|
429
|
+
return null;
|
|
430
|
+
const build = Number(values.get('CurrentBuild') ?? values.get('CurrentBuildNumber') ?? '');
|
|
431
|
+
if (!Number.isSafeInteger(build) || build <= 0)
|
|
432
|
+
return productName;
|
|
433
|
+
const expectedMajor = build >= WINDOWS_11_MIN_BUILD ? 11 : 10;
|
|
434
|
+
// ProductName 的写法固定是 "Windows <主版本> <edition>";只认这个前缀,避免误改其它片段。
|
|
435
|
+
return productName.replace(/^Windows\s+(\d+)/u, (_all, major) => (Number(major) === expectedMajor ? `Windows ${major}` : `Windows ${expectedMajor}`));
|
|
436
|
+
}
|
|
437
|
+
/** Linux 发行版的 PRETTY_NAME,已含版本号,是最接近 Windows ProductName 的字段。 */
|
|
438
|
+
function readOsReleasePrettyName() {
|
|
439
|
+
try {
|
|
440
|
+
for (const line of fs.readFileSync('/etc/os-release', 'utf8').split(/\r?\n/u)) {
|
|
441
|
+
const match = line.match(/^PRETTY_NAME=(.*)$/u);
|
|
442
|
+
if (match)
|
|
443
|
+
return match[1].replace(/^"|"$/gu, '').trim() || null;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
catch { }
|
|
447
|
+
return null;
|
|
448
|
+
}
|
|
376
449
|
// 不要求词边界:go 输出是 "go1.27.0",数字前面紧跟字母,\b 会挡住匹配。
|
|
377
450
|
const SEMVER = /\d+\.\d+\.\d+(?:[-+][\w.-]+)?/u;
|
|
378
451
|
function firstVersionLine(output) {
|
package/dist/utils/logger.js
CHANGED
|
@@ -271,7 +271,7 @@ export function ownershipErrorCode(error, fallback = 'OWNERSHIP_OPERATION_FAILED
|
|
|
271
271
|
}
|
|
272
272
|
export function logOwnershipEvent(event, fields, failed = false) {
|
|
273
273
|
const record = { schema: 'ec.ownership.v1', event };
|
|
274
|
-
for (const key of ['subjectAid', 'ownerAid', 'actorAid', 'localAid'
|
|
274
|
+
for (const key of ['subjectAid', 'ownerAid', 'actorAid', 'localAid']) {
|
|
275
275
|
const value = fields[key];
|
|
276
276
|
if (typeof value === 'string' && value.length <= 253
|
|
277
277
|
&& /^[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?){2,}$/.test(value)) {
|
|
@@ -308,7 +308,7 @@ export function logOwnershipEvent(event, fields, failed = false) {
|
|
|
308
308
|
if (typeof fields.relationVersion === 'number' && Number.isSafeInteger(fields.relationVersion)
|
|
309
309
|
&& fields.relationVersion >= 0)
|
|
310
310
|
record.relationVersion = fields.relationVersion;
|
|
311
|
-
for (const key of ['attemptId', 'processId', 'durationMs', 'maxAgeMs', 'timeoutMs'
|
|
311
|
+
for (const key of ['attemptId', 'processId', 'durationMs', 'maxAgeMs', 'timeoutMs']) {
|
|
312
312
|
const value = fields[key];
|
|
313
313
|
if (typeof value === 'number' && Number.isSafeInteger(value) && value >= 0)
|
|
314
314
|
record[key] = value;
|