evolcore 0.0.43-test.6 → 0.0.43-test.7
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 +48 -0
- package/bin/ecmsg.js +171 -54
- package/dist/agents/baseagent-availability.js +1 -1
- package/dist/agents/codex/app-server-client.js +22 -0
- package/dist/agents/codex-runner.js +69 -2
- package/dist/aun/msg/p2p.js +6 -1
- package/dist/channels/aun.js +234 -21
- package/dist/cli/agent-create.js +2 -2
- package/dist/cli/daemon-commands.js +6 -66
- package/dist/cli/daemon-lifecycle-client.js +61 -0
- package/dist/cli/ecmsg-gateway.js +35 -2
- package/dist/cli/events-command.js +73 -0
- package/dist/cli/index.js +31 -14
- package/dist/cli/invoke-command.js +182 -0
- package/dist/cli/managed-command-guard.js +6 -1
- package/dist/cli/restart-monitor.js +45 -47
- package/dist/cli/services-command.js +111 -0
- package/dist/cli/team-workspace-command.js +134 -0
- package/dist/cli/thread-command.js +6 -2
- package/dist/cli/watch-msg.js +1 -1
- package/dist/config/config-field-policy.js +2 -2
- package/dist/config/config-manager.js +0 -7
- package/dist/config/invoke-ipc-service.js +118 -0
- package/dist/config/schema-migration.js +6 -1
- package/dist/config-store.js +2 -1
- package/dist/core/agent-reload-coordinator.js +6 -4
- package/dist/core/agent-runtime.js +104 -10
- package/dist/core/auth/delegation-authorization.js +66 -0
- package/dist/core/auth/operation-catalog.js +20 -0
- package/dist/core/baseagent-loader.js +60 -130
- package/dist/core/channel-loader.js +10 -1
- package/dist/core/channel-runtime.js +4 -3
- package/dist/core/command/agent-control.js +1 -1
- package/dist/core/command/agent-storage-menu.js +1 -1
- package/dist/core/command/chatmode-config.js +2 -36
- package/dist/core/command/command-handler.js +53 -11
- package/dist/core/command/data-root-resolver.js +32 -23
- package/dist/core/command/eventcenter-menu.js +338 -0
- package/dist/core/command/menu-catalog.js +8 -0
- package/dist/core/command/menu-handler.js +198 -84
- package/dist/core/command/menu-protocol.js +60 -11
- package/dist/core/command/menu-query-batch.js +194 -0
- package/dist/core/command/slash-gate.js +1 -1
- package/dist/core/command/slash-handler.js +34 -42
- package/dist/core/command/team-workspace-bootstrap.js +350 -0
- package/dist/core/command/{pa-workspace-calendar.js → team-workspace-calendar.js} +7 -7
- package/dist/core/command/team-workspace-initializer.js +2 -0
- package/dist/core/command/{pa-workspace-items.js → team-workspace-items.js} +83 -68
- package/dist/core/command/team-workspace-job-store.js +88 -0
- package/dist/core/command/team-workspace-management-service.js +2 -0
- package/dist/core/command/team-workspace-management-store.js +96 -0
- package/dist/core/command/team-workspace-management.js +265 -0
- package/dist/core/command/team-workspace-members-menu.js +88 -0
- package/dist/core/command/team-workspace-store.js +612 -0
- package/dist/core/command/team-workspace-team.js +193 -0
- package/dist/core/daemon-control.js +8 -5
- package/dist/core/daemon-lifecycle.js +132 -73
- package/dist/core/handoff/runtime.js +3 -3
- package/dist/core/invoke/executors/index.js +13 -0
- package/dist/core/invoke/executors/media.js +283 -0
- package/dist/core/invoke/executors/text.js +198 -0
- package/dist/core/invoke/invoke-service.js +157 -0
- package/dist/core/invoke/style-router.js +48 -0
- package/dist/core/invoke/types.js +19 -0
- package/dist/core/ipc-registration.js +46 -7
- package/dist/core/memory/consolidation.js +7 -5
- package/dist/core/message/aun-ipc-sender.js +147 -17
- package/dist/core/message/im-renderer.js +28 -84
- package/dist/core/message/message-bridge.js +4 -0
- package/dist/core/message/message-utils.js +10 -2
- package/dist/core/message/peer-mode.js +7 -34
- package/dist/core/message/response-engine.js +157 -54
- package/dist/core/message/send-options.js +7 -4
- package/dist/core/message/send-routing.js +43 -5
- package/dist/core/ownership/owner-resolver.js +7 -0
- package/dist/core/permission/ec-command-parser.js +3 -2
- package/dist/core/permission/protected-paths.js +12 -2
- package/dist/core/permission/shell-environment.js +9 -0
- package/dist/core/session/session-file-health.js +243 -0
- package/dist/core/session/session-fs-store.js +2 -3
- package/dist/core/task/task-recovery-service.js +13 -2
- package/dist/core/thread/command-parser.js +9 -2
- package/dist/core/thread/thread-operation.js +21 -2
- package/dist/core/thread/thread-route.js +13 -2
- package/dist/directory/owner-directory-admission.js +40 -53
- package/dist/directory/owner-directory-cache.js +89 -113
- package/dist/directory/owner-directory-query-operation.js +8 -10
- package/dist/eck/kit-renderer.js +7 -5
- package/dist/ecweb/basic-settings-service.js +1 -1
- package/dist/ecweb/message-context-service.js +0 -4
- package/dist/ecweb/runtime/lifecycle.js +6 -2
- package/dist/ecweb/runtime/supervisor.js +19 -4
- package/dist/event-center/admission-materializer.js +114 -0
- package/dist/event-center/bus-gate.js +136 -0
- package/dist/event-center/bus-host.js +290 -0
- package/dist/event-center/bus-resolver.js +120 -0
- package/dist/event-center/center-config.js +100 -0
- package/dist/event-center/client-factory.js +50 -0
- package/dist/event-center/daemon.js +45 -0
- package/dist/event-center/directory-source.js +53 -0
- package/dist/event-center/dispatcher.js +157 -0
- package/dist/event-center/event-log.js +110 -0
- package/dist/event-center/index-generator.js +63 -0
- package/dist/event-center/ipc-operation.js +308 -0
- package/dist/event-center/ledger.js +52 -0
- package/dist/event-center/pack-loader.js +202 -0
- package/dist/event-center/pack-manager.js +85 -0
- package/dist/event-center/registry.js +238 -0
- package/dist/event-center/runtime.js +641 -0
- package/dist/event-center/script-runner.js +356 -0
- package/dist/event-center/types.js +35 -0
- package/dist/event-center/validation.js +413 -0
- package/dist/index.js +285 -99
- package/dist/ipc.js +66 -12
- package/dist/paths.js +20 -0
- package/dist/product.js +14 -0
- package/dist/proxy/manager.js +5 -1
- package/dist/proxy/service-supervisor.js +13 -4
- package/dist/response-system/engines/v1/index.js +0 -1
- package/dist/response-system/modes/single-session/index.js +1 -1
- package/dist/services/dispatcher.js +100 -0
- package/dist/services/idempotency.js +90 -0
- package/dist/services/identity.js +52 -0
- package/dist/services/index-generator.js +70 -0
- package/dist/services/index.js +449 -0
- package/dist/services/ipc-operation.js +458 -0
- package/dist/services/ledger.js +52 -0
- package/dist/services/message-log.js +112 -0
- package/dist/services/pack-manager.js +204 -0
- package/dist/services/reply.js +55 -0
- package/dist/services/router.js +95 -0
- package/dist/services/script-runner.js +422 -0
- package/dist/services/service-payload.js +70 -0
- package/dist/services/types.js +18 -0
- package/dist/services/validation.js +297 -0
- package/dist/trigger/application-service.js +18 -0
- package/dist/trigger/event-source.js +1 -1
- package/dist/trigger/ipc-service.js +3 -1
- package/dist/trigger/script-sandbox.js +118 -22
- package/dist/utils/cross-platform.js +24 -10
- package/dist/utils/evolcore-version.js +69 -27
- package/dist/utils/instance-registry.js +19 -13
- package/dist/utils/process-introspect.js +45 -9
- package/dist/utils/startup-trace.js +74 -37
- package/dist/utils/windows-shell-trust.js +80 -6
- package/kits/docs/INDEX.md +2 -2
- package/kits/docs/aun/ABILITY_CALLING.md +7 -14
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +2 -0
- package/kits/docs/evolcore/ability.md +4 -0
- package/kits/docs/evolcore/aid.md +1 -1
- package/kits/docs/evolcore/event-center.md +207 -0
- package/kits/docs/evolcore/file-navigation.md +10 -264
- package/kits/docs/evolcore/fs.md +3 -2
- package/kits/docs/evolcore/group.md +1 -1
- package/kits/docs/evolcore/memory-architecture.md +2 -0
- package/kits/docs/evolcore/menu-protocol.md +21 -0
- package/kits/docs/evolcore/msg.md +15 -3
- package/kits/docs/evolcore/provider.md +3 -1
- package/kits/docs/evolcore/response.md +5 -5
- package/kits/docs/evolcore/services.md +277 -0
- package/kits/docs/evolcore/task.md +2 -0
- package/kits/docs/evolcore/team-workspace.md +41 -0
- package/kits/eck_manifest.json +26 -0
- package/kits/rules/02-navigation.md +10 -1
- package/kits/schemas/_meta.json +17 -6
- package/kits/schemas/agent-config.schema.19.json +5 -7
- package/kits/schemas/agent-config.schema.20.json +936 -0
- package/kits/schemas/relation-config.schema.12.json +2 -3
- package/kits/schemas/role-config.schema.2.json +4 -4
- package/kits/skills/.switches.json +1 -5
- package/kits/skills/ability/SKILL.md +56 -0
- package/kits/skills/ability/references/calling.md +56 -0
- package/kits/skills/{ec-ability → ability}/references/contract-checklist.md +1 -1
- package/kits/skills/{ec-ability → ability}/references/development.md +9 -33
- package/kits/skills/{ec-ability → ability}/references/management.md +2 -2
- package/kits/skills/{ec-ability → ability}/references/recovery.md +1 -1
- package/kits/skills/{ec-ability → ability}/references/runtime-protocol.md +2 -0
- package/kits/skills/ec-agent-create/SKILL.md +0 -1
- package/kits/skills/ec-service-proxy/SKILL.md +34 -5
- package/kits/skills/personal-assistant/SKILL.md +6 -6
- package/kits/skills/personal-assistant/references/02-bootstrap.md +4 -4
- package/kits/skills/personal-assistant/scripts/clean.mjs +4 -4
- package/kits/skills/personal-assistant/scripts/init.mjs +2 -2
- package/kits/skills/personal-assistant/scripts/pa.mjs +4 -4
- package/kits/templates/system-fragments/channel.md +3 -3
- package/kits/templates/system-fragments/commands.md +5 -3
- package/kits/templates/system-fragments/reply.md +0 -5
- package/kits/templates/system-fragments/thread.md +10 -8
- package/package.json +3 -5
- package/dist/cli/pa-workspace-command.js +0 -225
- package/dist/core/command/pa-workspace-store.js +0 -468
- package/dist/core/relation/pa-team.js +0 -132
- package/kits/docs/evolcore/pa-workspace.md +0 -51
- package/kits/skills/aid-ability/SKILL.md +0 -244
- package/kits/skills/ec-ability/SKILL.md +0 -67
- package/kits/skills/ec-ability/references/workflows.md +0 -15
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* service.json / router.json 校验。
|
|
3
|
+
* 约束 1:1 映射 docs/services/schema/{service,router}.schema.json;Schema 为权威,
|
|
4
|
+
* 两者不一致改这里并同步 Schema。手写校验器(不引 ajv),失败逐条报错。
|
|
5
|
+
*/
|
|
6
|
+
import { isListenableType } from './service-payload.js';
|
|
7
|
+
export const SCRIPT_EXTENSIONS = ['mjs', 'cjs', 'js', 'py', 'sh', 'ps1'];
|
|
8
|
+
export const RUNTIME_WHITELIST = ['node', 'python', 'bash', 'powershell'];
|
|
9
|
+
const TIMEOUT_MIN = 1000;
|
|
10
|
+
const TIMEOUT_MAX = 300_000;
|
|
11
|
+
const TIMEOUT_DEFAULT = 30_000;
|
|
12
|
+
const QUOTA_DEFAULT_BUILTIN = { perMinute: 20, perHour: 200 };
|
|
13
|
+
const QUOTA_DEFAULT_SERVICE = { perMinute: 50, perHour: 1000 };
|
|
14
|
+
function isRecord(value) {
|
|
15
|
+
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
16
|
+
}
|
|
17
|
+
function optionalString(value, field, errors, max) {
|
|
18
|
+
if (value === undefined)
|
|
19
|
+
return undefined;
|
|
20
|
+
if (typeof value !== 'string') {
|
|
21
|
+
errors.push(`${field} must be a string`);
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
if (max !== undefined && value.length > max)
|
|
25
|
+
errors.push(`${field} is too long (max ${max})`);
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
function intInRange(value, field, min, max, errors) {
|
|
29
|
+
if (typeof value !== 'number' || !Number.isInteger(value) || value < min || value > max) {
|
|
30
|
+
errors.push(`${field} must be an integer between ${min} and ${max}`);
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
/** requires 的值:单个字符串、非空字符串数组,或 "*"。 */
|
|
36
|
+
function validateScopeValue(value, field, errors) {
|
|
37
|
+
if (typeof value === 'string') {
|
|
38
|
+
if (!value)
|
|
39
|
+
errors.push(`${field} must not be empty`);
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
if (Array.isArray(value)) {
|
|
43
|
+
if (value.length === 0) {
|
|
44
|
+
errors.push(`${field} must not be an empty array`);
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
if (value.some(item => typeof item !== 'string' || !item)) {
|
|
48
|
+
errors.push(`${field} must be an array of non-empty strings`);
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
errors.push(`${field} must be a string, a string array, or "*"`);
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
function validateValueAgainst(value, scope) {
|
|
57
|
+
if (scope === '*')
|
|
58
|
+
return true;
|
|
59
|
+
if (Array.isArray(scope))
|
|
60
|
+
return scope.includes(value);
|
|
61
|
+
return scope === value;
|
|
62
|
+
}
|
|
63
|
+
/** requires 判定:本机名片 type / exttype 是否满足。 */
|
|
64
|
+
export function requiresSatisfied(requires, identity) {
|
|
65
|
+
return validateValueAgainst(identity.type, requires.type)
|
|
66
|
+
&& validateValueAgainst(identity.exttype, requires.exttype);
|
|
67
|
+
}
|
|
68
|
+
/** handler.script 结构校验(存在性/越界由 pack-manager 做文件系统校验)。 */
|
|
69
|
+
function validateScriptPath(script, errors) {
|
|
70
|
+
if (typeof script !== 'string' || !script) {
|
|
71
|
+
errors.push('handler.script is required');
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
if (script.startsWith('/') || /^[a-zA-Z]:[\\/]/.test(script)) {
|
|
75
|
+
errors.push(`handler.script must be a relative path: ${script}`);
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
if (script.includes('..')) {
|
|
79
|
+
errors.push(`handler.script must not contain '..': ${script}`);
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
if (script.includes('\\')) {
|
|
83
|
+
errors.push(`handler.script must use forward slashes: ${script}`);
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
if (!script.startsWith('scripts/')) {
|
|
87
|
+
errors.push(`handler.script must be under scripts/: ${script}`);
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
const ext = script.split('.').pop() ?? '';
|
|
91
|
+
if (!SCRIPT_EXTENSIONS.includes(ext)) {
|
|
92
|
+
errors.push(`handler.script extension must be one of ${SCRIPT_EXTENSIONS.join('/')}: ${script}`);
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
return script;
|
|
96
|
+
}
|
|
97
|
+
function validateHandler(raw, errors) {
|
|
98
|
+
if (!isRecord(raw)) {
|
|
99
|
+
errors.push('listen[].handler must be an object');
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
const extra = Object.keys(raw).filter(key => !['script', 'runtime', 'args', 'timeoutMs'].includes(key));
|
|
103
|
+
if (extra.length)
|
|
104
|
+
errors.push(`listen[].handler has unknown fields: ${extra.join(', ')}`);
|
|
105
|
+
const script = validateScriptPath(raw.script, errors);
|
|
106
|
+
if (raw.runtime !== undefined && !RUNTIME_WHITELIST.includes(raw.runtime)) {
|
|
107
|
+
errors.push(`listen[].handler.runtime must be one of ${RUNTIME_WHITELIST.join('/')}`);
|
|
108
|
+
}
|
|
109
|
+
if (raw.args !== undefined && (!Array.isArray(raw.args) || raw.args.some(item => typeof item !== 'string'))) {
|
|
110
|
+
errors.push('listen[].handler.args must be an array of strings');
|
|
111
|
+
}
|
|
112
|
+
const timeoutMs = raw.timeoutMs === undefined
|
|
113
|
+
? TIMEOUT_DEFAULT
|
|
114
|
+
: intInRange(raw.timeoutMs, 'listen[].handler.timeoutMs', TIMEOUT_MIN, TIMEOUT_MAX, errors);
|
|
115
|
+
if (script === undefined)
|
|
116
|
+
return undefined;
|
|
117
|
+
return {
|
|
118
|
+
script,
|
|
119
|
+
...(raw.runtime !== undefined ? { runtime: raw.runtime } : {}),
|
|
120
|
+
...(Array.isArray(raw.args) ? { args: raw.args } : {}),
|
|
121
|
+
timeoutMs: timeoutMs ?? TIMEOUT_DEFAULT,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function validateListenEntry(raw, errors) {
|
|
125
|
+
if (!isRecord(raw)) {
|
|
126
|
+
errors.push('listen[] entries must be objects');
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
const extra = Object.keys(raw).filter(key => !['type', 'handler', 'filter'].includes(key));
|
|
130
|
+
if (extra.length)
|
|
131
|
+
errors.push(`listen entry has unknown fields: ${extra.join(', ')}`);
|
|
132
|
+
if (typeof raw.type !== 'string' || !isListenableType(raw.type)) {
|
|
133
|
+
errors.push(`listen.type must be services[.<seg>[.<seg>]] or services[.<seg>].*, and must not end with .result: ${String(raw.type)}`);
|
|
134
|
+
}
|
|
135
|
+
if (raw.filter !== undefined && !isRecord(raw.filter))
|
|
136
|
+
errors.push('listen[].filter must be an object');
|
|
137
|
+
const handler = validateHandler(raw.handler, errors);
|
|
138
|
+
if (typeof raw.type !== 'string' || !isListenableType(raw.type) || handler === undefined)
|
|
139
|
+
return undefined;
|
|
140
|
+
return {
|
|
141
|
+
type: raw.type,
|
|
142
|
+
...(isRecord(raw.filter) ? { filter: raw.filter } : {}),
|
|
143
|
+
handler,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function validateRequires(raw, errors) {
|
|
147
|
+
if (!isRecord(raw)) {
|
|
148
|
+
errors.push('requires is required and must be an object');
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
151
|
+
const extra = Object.keys(raw).filter(key => !['type', 'exttype'].includes(key));
|
|
152
|
+
if (extra.length)
|
|
153
|
+
errors.push(`requires has unknown fields: ${extra.join(', ')}`);
|
|
154
|
+
if (raw.type === undefined)
|
|
155
|
+
errors.push('requires.type is required');
|
|
156
|
+
if (raw.exttype === undefined)
|
|
157
|
+
errors.push('requires.exttype is required');
|
|
158
|
+
const type = raw.type === undefined ? undefined : validateScopeValue(raw.type, 'requires.type', errors);
|
|
159
|
+
const exttype = raw.exttype === undefined ? undefined : validateScopeValue(raw.exttype, 'requires.exttype', errors);
|
|
160
|
+
if (type === undefined || exttype === undefined)
|
|
161
|
+
return undefined;
|
|
162
|
+
return { type, exttype };
|
|
163
|
+
}
|
|
164
|
+
function validateReplyPolicy(raw, errors) {
|
|
165
|
+
if (raw === undefined)
|
|
166
|
+
return { allowed: false, payloadTypes: ['service-result'] };
|
|
167
|
+
if (!isRecord(raw)) {
|
|
168
|
+
errors.push('reply must be an object');
|
|
169
|
+
return { allowed: false, payloadTypes: ['service-result'] };
|
|
170
|
+
}
|
|
171
|
+
const extra = Object.keys(raw).filter(key => !['allowed', 'payloadTypes'].includes(key));
|
|
172
|
+
if (extra.length)
|
|
173
|
+
errors.push(`reply has unknown fields: ${extra.join(', ')}`);
|
|
174
|
+
if (raw.allowed !== undefined && typeof raw.allowed !== 'boolean')
|
|
175
|
+
errors.push('reply.allowed must be a boolean');
|
|
176
|
+
let payloadTypes = ['service-result'];
|
|
177
|
+
if (raw.payloadTypes !== undefined) {
|
|
178
|
+
if (!Array.isArray(raw.payloadTypes))
|
|
179
|
+
errors.push('reply.payloadTypes must be an array');
|
|
180
|
+
else if (raw.payloadTypes.some(item => item !== 'service-result')) {
|
|
181
|
+
errors.push('reply.payloadTypes only accepts "service-result"');
|
|
182
|
+
}
|
|
183
|
+
else
|
|
184
|
+
payloadTypes = ['service-result'];
|
|
185
|
+
}
|
|
186
|
+
return { allowed: raw.allowed === true, payloadTypes };
|
|
187
|
+
}
|
|
188
|
+
/** 校验 service.json 原始对象(不做文件系统检查)。 */
|
|
189
|
+
export function validateServiceJson(raw) {
|
|
190
|
+
const errors = [];
|
|
191
|
+
if (!isRecord(raw))
|
|
192
|
+
return { ok: false, errors: ['service.json must be a JSON object'] };
|
|
193
|
+
const extra = Object.keys(raw).filter(key => !['v', 'name', 'description', 'enabled', 'requires', 'listen', 'unmatched', 'reply'].includes(key));
|
|
194
|
+
if (extra.length)
|
|
195
|
+
errors.push(`unknown top-level fields: ${extra.join(', ')}`);
|
|
196
|
+
if (raw.v !== 1)
|
|
197
|
+
errors.push('v must be 1');
|
|
198
|
+
if (typeof raw.name !== 'string' || !raw.name || raw.name.length > 64) {
|
|
199
|
+
errors.push('name must be a non-empty string (max 64)');
|
|
200
|
+
}
|
|
201
|
+
const description = optionalString(raw.description, 'description', errors, 200);
|
|
202
|
+
if (raw.enabled !== undefined && typeof raw.enabled !== 'boolean')
|
|
203
|
+
errors.push('enabled must be a boolean');
|
|
204
|
+
if (raw.unmatched !== undefined && raw.unmatched !== 'silent' && raw.unmatched !== 'reject') {
|
|
205
|
+
errors.push('unmatched must be "silent" or "reject"');
|
|
206
|
+
}
|
|
207
|
+
const requires = validateRequires(raw.requires, errors);
|
|
208
|
+
const listen = [];
|
|
209
|
+
if (raw.listen === undefined)
|
|
210
|
+
errors.push('listen is required');
|
|
211
|
+
else if (!Array.isArray(raw.listen))
|
|
212
|
+
errors.push('listen must be an array');
|
|
213
|
+
else if (raw.listen.length === 0)
|
|
214
|
+
errors.push('listen must have at least one entry');
|
|
215
|
+
else {
|
|
216
|
+
for (const item of raw.listen) {
|
|
217
|
+
const entry = validateListenEntry(item, errors);
|
|
218
|
+
if (entry)
|
|
219
|
+
listen.push(entry);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
// 包内 type 唯一(含通配原文,同字面重复)。
|
|
223
|
+
const seen = new Set();
|
|
224
|
+
for (const entry of listen) {
|
|
225
|
+
if (seen.has(entry.type))
|
|
226
|
+
errors.push(`duplicate listen.type: ${entry.type}`);
|
|
227
|
+
else
|
|
228
|
+
seen.add(entry.type);
|
|
229
|
+
}
|
|
230
|
+
const reply = validateReplyPolicy(raw.reply, errors);
|
|
231
|
+
if (errors.length)
|
|
232
|
+
return { ok: false, errors };
|
|
233
|
+
return {
|
|
234
|
+
ok: true,
|
|
235
|
+
errors: [],
|
|
236
|
+
value: {
|
|
237
|
+
name: raw.name,
|
|
238
|
+
...(description !== undefined ? { description } : {}),
|
|
239
|
+
enabled: raw.enabled !== false,
|
|
240
|
+
requires: requires,
|
|
241
|
+
listen,
|
|
242
|
+
unmatched: raw.unmatched ?? 'silent',
|
|
243
|
+
reply,
|
|
244
|
+
},
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
function validateQuota(raw, field, fallback, errors) {
|
|
248
|
+
if (raw === undefined)
|
|
249
|
+
return { ...fallback };
|
|
250
|
+
if (!isRecord(raw)) {
|
|
251
|
+
errors.push(`${field} must be an object`);
|
|
252
|
+
return { ...fallback };
|
|
253
|
+
}
|
|
254
|
+
const extra = Object.keys(raw).filter(key => !['perMinute', 'perHour'].includes(key));
|
|
255
|
+
if (extra.length)
|
|
256
|
+
errors.push(`${field} has unknown fields: ${extra.join(', ')}`);
|
|
257
|
+
const perMinute = intInRange(raw.perMinute, `${field}.perMinute`, 1, Number.MAX_SAFE_INTEGER, errors);
|
|
258
|
+
const perHour = intInRange(raw.perHour, `${field}.perHour`, 1, Number.MAX_SAFE_INTEGER, errors);
|
|
259
|
+
return { perMinute: perMinute ?? fallback.perMinute, perHour: perHour ?? fallback.perHour };
|
|
260
|
+
}
|
|
261
|
+
/** 校验 router.json 原始对象。 */
|
|
262
|
+
export function validateRouterConfig(raw) {
|
|
263
|
+
const errors = [];
|
|
264
|
+
if (!isRecord(raw))
|
|
265
|
+
return { ok: false, errors: ['router.json must be a JSON object'] };
|
|
266
|
+
const extra = Object.keys(raw).filter(key => !['v', 'enabled', 'rateLimit'].includes(key));
|
|
267
|
+
if (extra.length)
|
|
268
|
+
errors.push(`unknown top-level fields: ${extra.join(', ')}`);
|
|
269
|
+
if (raw.v !== 1)
|
|
270
|
+
errors.push('v must be 1');
|
|
271
|
+
if (raw.enabled !== undefined && typeof raw.enabled !== 'boolean')
|
|
272
|
+
errors.push('enabled must be a boolean');
|
|
273
|
+
let rateLimit = {
|
|
274
|
+
builtin: { ...QUOTA_DEFAULT_BUILTIN },
|
|
275
|
+
service: { ...QUOTA_DEFAULT_SERVICE },
|
|
276
|
+
};
|
|
277
|
+
if (raw.rateLimit !== undefined) {
|
|
278
|
+
if (!isRecord(raw.rateLimit))
|
|
279
|
+
errors.push('rateLimit must be an object');
|
|
280
|
+
else {
|
|
281
|
+
const rateExtra = Object.keys(raw.rateLimit).filter(key => !['builtin', 'service'].includes(key));
|
|
282
|
+
if (rateExtra.length)
|
|
283
|
+
errors.push(`rateLimit has unknown fields: ${rateExtra.join(', ')}`);
|
|
284
|
+
rateLimit = {
|
|
285
|
+
builtin: validateQuota(raw.rateLimit.builtin, 'rateLimit.builtin', QUOTA_DEFAULT_BUILTIN, errors),
|
|
286
|
+
service: validateQuota(raw.rateLimit.service, 'rateLimit.service', QUOTA_DEFAULT_SERVICE, errors),
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if (errors.length)
|
|
291
|
+
return { ok: false, errors };
|
|
292
|
+
return {
|
|
293
|
+
ok: true,
|
|
294
|
+
errors: [],
|
|
295
|
+
value: { v: 1, enabled: raw.enabled === true, rateLimit },
|
|
296
|
+
};
|
|
297
|
+
}
|
|
@@ -9,6 +9,20 @@ import { logger } from '../utils/logger.js';
|
|
|
9
9
|
export class TriggerSchedulerRegistry {
|
|
10
10
|
schedulers = new Map();
|
|
11
11
|
starts = new Map();
|
|
12
|
+
listeners = [];
|
|
13
|
+
addLifecycleListener(listener) {
|
|
14
|
+
this.listeners.push(listener);
|
|
15
|
+
}
|
|
16
|
+
async notify(action) {
|
|
17
|
+
for (const listener of this.listeners) {
|
|
18
|
+
try {
|
|
19
|
+
await action(listener);
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
logger.error(`[Trigger] lifecycle listener failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
12
26
|
get(agentAid) {
|
|
13
27
|
return this.schedulers.get(agentAid);
|
|
14
28
|
}
|
|
@@ -39,6 +53,8 @@ export class TriggerSchedulerRegistry {
|
|
|
39
53
|
// Propagate failure to admission/readiness and allow ensureStarted to retry.
|
|
40
54
|
throw error;
|
|
41
55
|
}
|
|
56
|
+
// 附属服务不阻塞调度器启动。
|
|
57
|
+
void this.notify(listener => listener.started?.(agentAid));
|
|
42
58
|
}
|
|
43
59
|
async ensureStarted(agentAid, start) {
|
|
44
60
|
const existing = this.starts.get(agentAid);
|
|
@@ -56,6 +72,7 @@ export class TriggerSchedulerRegistry {
|
|
|
56
72
|
}
|
|
57
73
|
}
|
|
58
74
|
async remove(agentAid) {
|
|
75
|
+
await this.notify(listener => listener.removed?.(agentAid));
|
|
59
76
|
await this.schedulers.get(agentAid)?.stop();
|
|
60
77
|
this.schedulers.delete(agentAid);
|
|
61
78
|
this.starts.delete(agentAid);
|
|
@@ -69,6 +86,7 @@ export class TriggerSchedulerRegistry {
|
|
|
69
86
|
await Promise.all([...this.schedulers.values()].map(scheduler => scheduler.waitForIdle(timeoutMs)));
|
|
70
87
|
}
|
|
71
88
|
async suspendForDaemonExit() {
|
|
89
|
+
await this.notify(listener => listener.suspending?.());
|
|
72
90
|
await Promise.all([...this.schedulers.values()].map(scheduler => scheduler.suspendForDaemonExit()));
|
|
73
91
|
}
|
|
74
92
|
}
|
|
@@ -99,7 +99,7 @@ function matchPattern(eventType, pattern) {
|
|
|
99
99
|
return eventType.startsWith(pattern.slice(0, -1));
|
|
100
100
|
return false;
|
|
101
101
|
}
|
|
102
|
-
function matchFilter(event, filter) {
|
|
102
|
+
export function matchFilter(event, filter) {
|
|
103
103
|
if (!filter.match)
|
|
104
104
|
return true;
|
|
105
105
|
for (const [path, expected] of Object.entries(filter.match)) {
|
|
@@ -5,12 +5,14 @@ import { assertTriggerLocalFileAuthority, daemonPrivilegedTriggerReason, isTrigg
|
|
|
5
5
|
import { decodeTriggerScriptFile } from './local-files.js';
|
|
6
6
|
import { applyTriggerPatch } from './patch.js';
|
|
7
7
|
import { definitionRevision, normalizeTriggerDefinition, splitScriptCommand } from './validation.js';
|
|
8
|
-
export function createTriggerBaseagentResolver({ daemonTriggerOwnerAid, getAgentName, getDaemonAgentName, agentMap, }) {
|
|
8
|
+
export function createTriggerBaseagentResolver({ daemonTriggerOwnerAid, getAgentName, getDaemonAgentName, agentMap, getConfiguredBaseagents, }) {
|
|
9
9
|
return agentAid => {
|
|
10
10
|
const ownerName = getAgentName(agentAid)
|
|
11
11
|
?? (agentAid === daemonTriggerOwnerAid ? getDaemonAgentName() : undefined);
|
|
12
12
|
if (!ownerName)
|
|
13
13
|
return [];
|
|
14
|
+
if (getConfiguredBaseagents)
|
|
15
|
+
return getConfiguredBaseagents(ownerName);
|
|
14
16
|
const prefix = `${ownerName}::`;
|
|
15
17
|
return [...agentMap.keys()]
|
|
16
18
|
.filter(key => key.startsWith(prefix))
|
|
@@ -24,14 +24,47 @@ const SCRIPT_ENVIRONMENT_EXCLUDES = [
|
|
|
24
24
|
'GOOGLE_API_KEY',
|
|
25
25
|
'ECAGENT_API_KEY',
|
|
26
26
|
];
|
|
27
|
+
/**
|
|
28
|
+
* 构造 Trigger / 事件 / 服务脚本的启动配置。
|
|
29
|
+
*
|
|
30
|
+
* ## 三条执行路径(只此三条,其余组合一律 fail-closed)
|
|
31
|
+
*
|
|
32
|
+
* | 路径 | 判据 | 沙箱 | 平台 | 说明 |
|
|
33
|
+
* | --- | --- | --- | --- | --- |
|
|
34
|
+
* | daemon | `authorization.scope === 'daemon'` | **无** | 全平台 | 直接 spawn,继承 `process.env`(不清洗密钥) |
|
|
35
|
+
* | 无沙箱 | `permissionMode === 'fullaccess'`,或 `bypass` + `role === 'owner'` | **无** | 全平台 | 由 `:66` 与 `resolvePhaseOneExecutionSandbox` 判定;本函数在 fullaccess 时直接抛错要求走 daemon scope |
|
|
36
|
+
* | scoped | 其余非 fullaccess 模式 | **有** | Linux / Windows | macOS 不支持,见 `:70` |
|
|
37
|
+
*
|
|
38
|
+
* ## scoped 路径的沙箱后端(当前实现)
|
|
39
|
+
*
|
|
40
|
+
* - **Linux**:系统 `bubblewrap`(`--ro-bind / /` + `--tmpfs` 遮蔽 L/H-class 路径)。
|
|
41
|
+
* 不依赖 Codex。系统包缺失时报 `bubblewrap is required for scoped Trigger script isolation`。
|
|
42
|
+
* - **Windows**:**借用 `@openai/codex` 的 Windows 沙箱**(`codex.exe sandbox`
|
|
43
|
+
* 子命令 + `codex-windows-sandbox-setup.exe` 施加的 NTFS ACL)。
|
|
44
|
+
* Codex 在这里只当「沙箱宿主」用,与 baseagent 是 claude 还是 codex **无关**,
|
|
45
|
+
* 也不碰模型/认证/会话。这是已知的硬依赖:`package.json` 并未声明它,
|
|
46
|
+
* 需要用户在机器上全局安装。
|
|
47
|
+
* - **macOS**:**不支持**(`:70`)。没有可用后端,scoped 脚本一律拒跑。
|
|
48
|
+
*
|
|
49
|
+
* 三者的失败语义一致:要么跑在有隔离的沙箱里,要么拒跑(`SCRIPT_SANDBOX_UNAVAILABLE` /
|
|
50
|
+
* 退出码 126),不存在「静默降级成无沙箱」。
|
|
51
|
+
*
|
|
52
|
+
* ## 临时绕过(沙箱不可用时)
|
|
53
|
+
*
|
|
54
|
+
* 若机器上装不了 bubblewrap / codex,或 macOS 需要临时跑通,只能显式选择
|
|
55
|
+
* **daemon scope** 或 **fullaccess / bypass+owner**——两者都**没有沙箱**。
|
|
56
|
+
* 这是有意的:绕过必须显式,不能让调用方吞掉错误后自己 spawn。
|
|
57
|
+
* 走 daemon scope 时调用方必须向用户明示「本次执行没有沙箱」。
|
|
58
|
+
*/
|
|
27
59
|
export function buildTriggerScriptLaunch(input) {
|
|
28
60
|
const authorization = input.executionAuthorization;
|
|
29
61
|
if (!authorization?.allowed || !authorization.scope)
|
|
30
62
|
throw new Error('Trigger execution authorization is missing');
|
|
31
63
|
const runtime = resolveRuntime(input.trigger.execution.script?.runtime || '');
|
|
32
64
|
if (authorization.scope === 'daemon') {
|
|
65
|
+
// daemon scope:无沙箱,全平台可用。注意 env 是原样继承,KEY/TOKEN 不清洗。
|
|
33
66
|
const launch = buildCliLaunchCommand(runtime, [input.scriptPath, ...input.scriptArgs]);
|
|
34
|
-
return { ...launch, cwd: input.projectPath, env: process.env };
|
|
67
|
+
return { ...launch, cwd: input.projectPath, env: process.env, sandboxAbsent: 'daemon-scope' };
|
|
35
68
|
}
|
|
36
69
|
if (!authorization.permissionMode || authorization.permissionMode === 'fullaccess') {
|
|
37
70
|
throw new Error('scoped Trigger execution requires an effective non-fullaccess permission mode');
|
|
@@ -39,10 +72,15 @@ export function buildTriggerScriptLaunch(input) {
|
|
|
39
72
|
const sandboxDecision = resolvePhaseOneExecutionSandbox(authorization.permissionMode, authorization.role);
|
|
40
73
|
const readonly = sandboxDecision.permissionMode === 'readonly';
|
|
41
74
|
if (process.platform !== 'linux' && process.platform !== 'win32') {
|
|
42
|
-
throw new Error(
|
|
75
|
+
throw new Error(`scoped Trigger script isolation is unavailable on platform "${process.platform}" `
|
|
76
|
+
+ '(supported: linux via bubblewrap, win32 via the Codex Windows sandbox). '
|
|
77
|
+
+ 'On macOS there is no backend yet: either run this work on Linux/Windows, '
|
|
78
|
+
+ 'or execute the script through daemon scope / fullaccess and tell the user that no sandbox is applied.');
|
|
43
79
|
}
|
|
44
80
|
if (process.platform === 'win32' && path.extname(runtime).toLowerCase() !== '.exe') {
|
|
45
|
-
throw new Error(
|
|
81
|
+
throw new Error(`scoped Windows Trigger scripts require a native executable runtime (got "${runtime}"). `
|
|
82
|
+
+ 'Use runtime "node" (resolves to node.exe) or another .exe; '
|
|
83
|
+
+ '.mjs/.js script files are fine — only the runtime must be a native executable.');
|
|
46
84
|
}
|
|
47
85
|
const projectPath = resolveRealDirectory(input.projectPath, 'Trigger project path');
|
|
48
86
|
const triggerDir = resolveRealDirectory(input.triggerDir, 'Trigger directory');
|
|
@@ -70,7 +108,10 @@ export function buildTriggerScriptLaunch(input) {
|
|
|
70
108
|
}
|
|
71
109
|
const bubblewrap = process.platform === 'linux' ? resolveBubblewrapPath() : undefined;
|
|
72
110
|
if (process.platform === 'linux' && !bubblewrap) {
|
|
73
|
-
throw new Error('bubblewrap is required for scoped Trigger script isolation'
|
|
111
|
+
throw new Error('bubblewrap is required for scoped Trigger script isolation. '
|
|
112
|
+
+ 'Install it via your package manager (Debian/Ubuntu: `apt install bubblewrap`; '
|
|
113
|
+
+ 'Fedora: `dnf install bubblewrap`; Arch: `pacman -S bubblewrap`), '
|
|
114
|
+
+ 'or execute the script through daemon scope / fullaccess and tell the user that no sandbox is applied.');
|
|
74
115
|
}
|
|
75
116
|
const runtimeRoot = ensureSessionRuntimeDir(`trigger:${input.trigger.agentAid}:${input.trigger.id}`);
|
|
76
117
|
if (!runtimeRoot)
|
|
@@ -195,20 +236,50 @@ function resolveRuntime(value) {
|
|
|
195
236
|
throw new Error(`script runtime is unavailable: ${runtime}`);
|
|
196
237
|
return fs.realpathSync.native(executable);
|
|
197
238
|
}
|
|
239
|
+
/**
|
|
240
|
+
* 解析 Windows scoped 沙箱宿主。
|
|
241
|
+
*
|
|
242
|
+
* **这里就是「EvolCore 依赖 Codex」的全部来源。** Codex 只作为 Windows 沙箱的
|
|
243
|
+
* 执行宿主(`codex.exe sandbox` + `codex-windows-sandbox-setup.exe` 施加的 ACL),
|
|
244
|
+
* 与 baseagent 无关,也不涉及模型调用。替代方案(landstrip / srt)尚未接入。
|
|
245
|
+
*
|
|
246
|
+
* 失败分三类,各自的修复动作不同,报错里会明确区分:
|
|
247
|
+
* 1. 没装 Codex → 全局安装
|
|
248
|
+
* 2. 装了但缺平台包 → 重装(npm 的 optional 依赖常因超时被静默丢弃)
|
|
249
|
+
* 3. 装了但沙箱未 provisioning → 在宿主终端跑一次 elevated setup
|
|
250
|
+
*
|
|
251
|
+
* 三类都失败时,唯一出路是改用 daemon scope / fullaccess(无沙箱)。
|
|
252
|
+
*/
|
|
198
253
|
function resolveWindowsBackend() {
|
|
254
|
+
const noSandboxHint = 'Alternatively, execute the script through daemon scope or fullaccess '
|
|
255
|
+
+ '(no sandbox is applied) and tell the user explicitly.';
|
|
199
256
|
const codexPath = resolveCodexCliPath();
|
|
200
|
-
if (!codexPath)
|
|
201
|
-
throw new Error('Codex CLI is required for scoped Windows Trigger script isolation'
|
|
257
|
+
if (!codexPath) {
|
|
258
|
+
throw new Error('Codex CLI is required for scoped Windows Trigger script isolation, but `codex` was not found on PATH. '
|
|
259
|
+
+ 'EvolCore only uses it as the Windows sandbox host — install it with `npm install -g @openai/codex`, '
|
|
260
|
+
+ 'then re-run. ' + noSandboxHint);
|
|
261
|
+
}
|
|
202
262
|
let command = codexPath;
|
|
203
263
|
if (path.extname(command).toLowerCase() !== '.exe') {
|
|
204
264
|
const packageFile = path.join(path.dirname(codexPath), 'node_modules', '@openai', 'codex', 'package.json');
|
|
205
265
|
const platformName = `@openai/codex-win32-${process.arch}`;
|
|
206
|
-
|
|
266
|
+
let platformFile;
|
|
267
|
+
try {
|
|
268
|
+
platformFile = createRequire(packageFile).resolve(`${platformName}/package.json`);
|
|
269
|
+
}
|
|
270
|
+
catch (error) {
|
|
271
|
+
throw new Error(`Codex is installed but its Windows native package "${platformName}" is missing `
|
|
272
|
+
+ `(${error?.message || String(error)}). npm silently drops optional packages on download timeout; `
|
|
273
|
+
+ 'reinstall Codex with a longer timeout, e.g. `npm install -g @openai/codex --fetch-timeout=600000`. '
|
|
274
|
+
+ noSandboxHint, { cause: error });
|
|
275
|
+
}
|
|
207
276
|
const target = process.arch === 'arm64' ? 'aarch64-pc-windows-msvc' : 'x86_64-pc-windows-msvc';
|
|
208
277
|
command = path.join(path.dirname(platformFile), 'vendor', target, 'bin', 'codex.exe');
|
|
209
278
|
}
|
|
210
|
-
if (!fs.statSync(command).isFile())
|
|
211
|
-
throw new Error(
|
|
279
|
+
if (!fs.statSync(command).isFile()) {
|
|
280
|
+
throw new Error(`Codex is installed but the native sandbox executable is missing at "${command}". `
|
|
281
|
+
+ 'Reinstall Codex (`npm install -g @openai/codex`). ' + noSandboxHint);
|
|
282
|
+
}
|
|
212
283
|
const home = resolveRealDirectory(process.env.CODEX_HOME || path.join(os.homedir(), '.codex'), 'Codex control home');
|
|
213
284
|
let marker;
|
|
214
285
|
try {
|
|
@@ -227,7 +298,14 @@ function resolveWindowsBackend() {
|
|
|
227
298
|
|| users.online?.username !== 'CodexSandboxOnline' || typeof users.online?.password !== 'string' || !users.online.password
|
|
228
299
|
|| !fs.existsSync(path.join(home, '.sandbox-bin'))
|
|
229
300
|
|| !fs.readdirSync(path.join(home, '.sandbox-bin')).some(name => /^codex-command-runner-.+\.exe$/.test(name))) {
|
|
230
|
-
throw new Error('Windows restricted-read sandbox
|
|
301
|
+
throw new Error(`Codex's Windows restricted-read sandbox is not provisioned in "${home}" `
|
|
302
|
+
+ `(expected setup_marker version ${WINDOWS_SANDBOX_SETUP_VERSION}, sandbox users `
|
|
303
|
+
+ 'CodexSandboxOffline/Online, and a codex-command-runner-*.exe in .sandbox-bin). '
|
|
304
|
+
+ 'Automatic elevation is disabled by design — run the elevated setup once in a host terminal: '
|
|
305
|
+
+ 'Codex Desktop → Windows Sandbox settings → setup/repair (elevated, accept one UAC prompt). '
|
|
306
|
+
+ 'Then verify with `codex doctor --json` (backend=elevated, provisioning=complete) and '
|
|
307
|
+
+ '`codex sandbox -- cmd /c whoami` (should show CodexSandboxOffline/Online, not your desktop user). '
|
|
308
|
+
+ 'Troubleshooting: kits/docs/evolcore/codex-windows-sandbox.md. ' + noSandboxHint);
|
|
231
309
|
}
|
|
232
310
|
return { command: fs.realpathSync.native(command), home };
|
|
233
311
|
}
|
|
@@ -340,6 +418,20 @@ function getScriptEnvironmentExcludes() {
|
|
|
340
418
|
function filesystemEntry(value, access) {
|
|
341
419
|
return { path: { type: 'path', path: path.resolve(value) }, access };
|
|
342
420
|
}
|
|
421
|
+
/**
|
|
422
|
+
* 证明 Windows 沙箱的文件策略确实被执行。
|
|
423
|
+
*
|
|
424
|
+
* 这里验证的是「**显式 deny 生效**」,不是「默认拒绝读」——Codex 的 Windows
|
|
425
|
+
* 沙箱与 Linux 的 `--ro-bind / /` 同为「默认放行 + 显式 deny」语义:策略里
|
|
426
|
+
* `{ kind: 'root' }` 给 read,其余 deny 条目在其上做减法。因此拿一个不在
|
|
427
|
+
* deny 列表里的路径去期望 EACCES 永远不成立,只会把每次脚本执行都判成失败。
|
|
428
|
+
*
|
|
429
|
+
* 三步:
|
|
430
|
+
* 1. 读 canary 且策略里显式给 `read` → 必须成功(证明「能读」,策略未被整体拒绝)
|
|
431
|
+
* 2. 同一个 canary 在策略里显式给 `deny` → 必须 EACCES/EPERM
|
|
432
|
+
* (证明 deny 真的被沙箱执行;这一步失败说明沙箱没起效,必须拒跑)
|
|
433
|
+
* 3. 在 workDir 写文件 → 必须成功(证明 scoped 路径没有把整个文件系统锁死)
|
|
434
|
+
*/
|
|
343
435
|
async function verifyWindowsReadIsolation(launch, sandboxArgs, runDir, workDir, signal) {
|
|
344
436
|
signal?.throwIfAborted();
|
|
345
437
|
const canary = path.join(runDir, 'read-isolation-canary');
|
|
@@ -350,26 +442,30 @@ async function verifyWindowsReadIsolation(launch, sandboxArgs, runDir, workDir,
|
|
|
350
442
|
'if (fs.readFileSync(process.argv[1], "utf8") !== "evolcore-read-isolation-canary") process.exit(91);',
|
|
351
443
|
'process.stdout.write("evolcore-trigger-sandbox-ready");',
|
|
352
444
|
].join('\n');
|
|
353
|
-
|
|
445
|
+
// 策略里显式 deny 的同一个文件必须读不到;能读到就说明沙箱没执行策略。
|
|
446
|
+
const denyProbe = [
|
|
354
447
|
'const fs = require("node:fs");',
|
|
355
448
|
'let denied = false;',
|
|
356
449
|
'try { fs.readFileSync(process.argv[1]); } catch (error) {',
|
|
357
|
-
'if (error.code === "EACCES" || error.code === "EPERM") denied = true; else throw error;',
|
|
450
|
+
'if (error.code === "EACCES" || error.code === "EPERM" || error.code === "ENOENT") denied = true; else throw error;',
|
|
358
451
|
'}',
|
|
359
|
-
'if (!denied) { process.stderr.write("
|
|
452
|
+
'if (!denied) { process.stderr.write("deny enforcement is not applied: denied path was readable"); process.exit(90); }',
|
|
360
453
|
'fs.writeFileSync(process.argv[2], "allowed");',
|
|
361
454
|
'process.stdout.write("evolcore-trigger-sandbox-ready");',
|
|
362
455
|
].join('\n');
|
|
363
|
-
|
|
364
|
-
const
|
|
365
|
-
const stateIndex =
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
if (
|
|
456
|
+
const withExtraEntry = (extra) => {
|
|
457
|
+
const args = [...sandboxArgs];
|
|
458
|
+
const stateIndex = args.indexOf('--sandbox-state-json') + 1;
|
|
459
|
+
const state = JSON.parse(args[stateIndex]);
|
|
460
|
+
state.permissionProfile.file_system.entries.push(extra);
|
|
461
|
+
args[stateIndex] = JSON.stringify(state);
|
|
462
|
+
if (args[stateIndex].length > 20_000)
|
|
370
463
|
throw new Error('filesystem probe policy exceeds the command-line budget');
|
|
371
|
-
|
|
372
|
-
|
|
464
|
+
return args;
|
|
465
|
+
};
|
|
466
|
+
try {
|
|
467
|
+
await runWindowsIsolationProbe(launch, withExtraEntry(filesystemEntry(canary, 'read')), readProbe, [canary], signal);
|
|
468
|
+
await runWindowsIsolationProbe(launch, withExtraEntry(filesystemEntry(canary, 'deny')), denyProbe, [canary, writableProbe], signal);
|
|
373
469
|
}
|
|
374
470
|
catch (error) {
|
|
375
471
|
throw new Error(`Windows sandbox cannot prove scoped read isolation; Trigger script execution is refused: ${error?.message || String(error)}`, { cause: error });
|