evolcore 0.0.40 → 0.0.41-test.1
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 +94 -1
- package/bin/codex-managed-hook.mjs +11 -0
- package/bin/ec-safe-output.js +11 -1
- package/dist/agents/baseagent-availability.js +1 -1
- package/dist/agents/baseagent.js +20 -43
- package/dist/agents/claude-runner.js +197 -197
- package/dist/agents/codex-runner.js +535 -259
- package/dist/agents/ecagent-runner.js +31 -12
- package/dist/agents/gemini-runner.js +27 -7
- package/dist/agents/runner-types.js +11 -3
- package/dist/aun/ability-device-routing.js +26 -0
- package/dist/aun/aid/client.js +1 -1
- package/dist/aun/group/fs-download.js +39 -0
- package/dist/aun/group/identity.js +36 -13
- package/dist/aun/group/operations.js +5 -0
- package/dist/aun/msg/managed-operation.js +72 -11
- package/dist/aun/msg/p2p.js +32 -7
- package/dist/aun/service-proxy.js +36 -12
- package/dist/aun/storage/download.js +30 -0
- package/dist/aun/storage/index.js +14 -6
- package/dist/channels/aun.js +367 -24
- package/dist/channels/daemon.js +39 -5
- package/dist/cli/agent-command.js +2 -0
- package/dist/cli/agent-create.js +98 -19
- package/dist/cli/agent.js +10 -3
- package/dist/cli/aun-commands.js +85 -41
- package/dist/cli/daemon-commands.js +678 -688
- package/dist/cli/fs-command.js +64 -2
- package/dist/cli/index.js +48 -4
- package/dist/cli/managed-command-guard.js +4 -0
- package/dist/cli/model.js +40 -40
- package/dist/cli/proxy-command.js +92 -0
- package/dist/cli/restart-monitor.js +17 -0
- package/dist/cli/role.js +85 -0
- package/dist/cli/session-command.js +128 -13
- package/dist/cli/stats.js +60 -4
- package/dist/cli/trigger-command.js +2 -2
- package/dist/config/access-policy.js +8 -1
- package/dist/config/boot-log.js +38 -1
- package/dist/config/config-field-policy.js +5 -32
- package/dist/config/config-manager.js +46 -39
- package/dist/config/config-operation-service.js +8 -11
- package/dist/config/contact-book-store.js +47 -21
- package/dist/config/contact-book.js +18 -12
- package/dist/config/contact-operation-service.js +3 -4
- package/dist/config/contact-request-service.js +11 -0
- package/dist/config/daemon-services.js +11 -0
- package/dist/config/gateway-config.js +89 -595
- package/dist/config/peer-role-resolver.js +15 -11
- package/dist/config/providers-config.js +12 -7
- package/dist/config/providers-import.js +3 -21
- package/dist/config/resolved-config-op.js +3 -0
- package/dist/config/role-command-service.js +166 -0
- package/dist/config/role-request-service.js +193 -0
- package/dist/config/schema-migration.js +686 -25
- package/dist/config-store.js +79 -3
- package/dist/contracts/ecweb-instance.js +41 -0
- package/dist/contracts/ecweb-service-protocol.js +3 -1
- package/dist/core/agent-application-service.js +11 -1
- package/dist/core/agent-ipc-registration.js +4 -0
- package/dist/core/agent-runtime.js +1 -1
- package/dist/core/auth/agent-delegation.js +82 -6
- package/dist/core/auth/auth-gateway.js +1 -1
- package/dist/core/auth/authorization-audit.js +37 -9
- package/dist/core/auth/delegation-authorization.js +3 -1
- package/dist/core/auth/operation-authorizer.js +15 -0
- package/dist/core/auth/operation-catalog.js +39 -6
- package/dist/core/command/agent-control.js +94 -19
- package/dist/core/command/agent-storage-menu.js +5 -3
- package/dist/core/command/cli-intent-parser.js +2 -1
- package/dist/core/command/command-handler.js +105 -145
- package/dist/core/command/connect-menu.js +31 -2
- package/dist/core/command/data-root-resolver.js +5 -4
- package/dist/core/command/memory-slash.js +16 -8
- package/dist/core/command/menu-catalog.js +6 -6
- package/dist/core/command/menu-handler.js +87 -163
- package/dist/core/command/menu-protocol.js +9 -2
- package/dist/core/command/role-menu.js +148 -30
- package/dist/core/command/slash-gate.js +13 -10
- package/dist/core/command/slash-handler.js +157 -352
- package/dist/core/daemon-control.js +8 -14
- package/dist/core/event-catalog.js +15 -0
- package/dist/core/evolagent-registry.js +4 -4
- package/dist/core/evolagent.js +2 -2
- package/dist/core/inference/text-inference.js +31 -40
- package/dist/core/ipc-registration.js +24 -3
- package/dist/core/memory/consolidation-context.js +51 -5
- package/dist/core/memory/consolidation-ops-records.js +1 -1
- package/dist/core/memory/consolidation-trigger.js +190 -190
- package/dist/core/memory/consolidation.js +316 -29
- package/dist/core/memory/forget-log.js +96 -0
- package/dist/core/memory/index-manager.js +27 -5
- package/dist/core/memory/memory-admin.js +45 -5
- package/dist/core/memory/memory-writer.js +163 -18
- package/dist/core/memory/relation-idle-monitor.js +119 -58
- package/dist/core/memory/relation-sweep.js +44 -39
- package/dist/core/message/aun-ipc-sender.js +34 -7
- package/dist/core/message/aun-request-registry.js +97 -3
- package/dist/core/message/im-renderer.js +11 -4
- package/dist/core/message/message-admission.js +97 -8
- package/dist/core/message/message-bridge.js +71 -24
- package/dist/core/message/message-log.js +55 -0
- package/dist/core/message/message-queue.js +5 -5
- package/dist/core/message/response-engine.js +387 -144
- package/dist/core/model/catalog-service.js +4 -2
- package/dist/core/model/config-scope.js +24 -64
- package/dist/core/model/field-scope.js +1 -1
- package/dist/core/model/model-catalog.js +37 -47
- package/dist/core/model/model-diagnostics.js +4 -3
- package/dist/core/model/model-fallback.js +10 -7
- package/dist/core/model/model-permission.js +3 -2
- package/dist/core/ownership/owner-resolver.js +25 -23
- package/dist/core/permission/ec-command-parser.js +138 -5
- package/dist/core/permission/sandbox-runtime.js +18 -1
- package/dist/core/permission/tool-policy.js +42 -10
- package/dist/core/relation/peer-identity.js +64 -1
- package/dist/core/role/runtime-policy.js +72 -13
- package/dist/core/session/session-capsule.js +197 -0
- package/dist/core/session/session-idle-monitor.js +1 -1
- package/dist/core/session/session-manager.js +168 -14
- package/dist/core/session/session-mapper.js +2 -0
- package/dist/core/session/session-renew.js +3 -3
- package/dist/core/skill/index-generator.js +15 -5
- package/dist/core/system-session/memory.js +6 -1
- package/dist/core/thread/thread-service.js +19 -6
- package/dist/directory/owner-directory-admission.js +95 -0
- package/dist/directory/owner-directory-authorization.js +309 -0
- package/dist/directory/owner-directory-cache.js +635 -0
- package/dist/eck/kit-renderer.js +2 -2
- package/dist/ecweb/basic-settings-service.js +33 -40
- package/dist/ecweb/message-context-service.js +110 -0
- package/dist/index.js +79 -17
- package/dist/ipc.js +189 -17
- package/dist/paths.js +4 -0
- package/dist/proxy/command.js +122 -0
- package/dist/proxy/ipc-service.js +68 -0
- package/dist/proxy/manager.js +485 -0
- package/dist/proxy/service-supervisor.js +603 -0
- package/dist/response-system/engines/v1/proactive-flow.js +16 -6
- package/dist/stats/budget.js +1 -1
- package/dist/stats/db.js +15 -0
- package/dist/stats/index.js +2 -2
- package/dist/stats/price-resolver.js +304 -5
- package/dist/stats/query.js +82 -3
- package/dist/stats/writer.js +38 -5
- package/dist/trigger/feedback.js +18 -7
- package/dist/trigger/manager.js +20 -3
- package/dist/trigger/parser.js +6 -3
- package/dist/trigger/patch.js +1 -1
- package/dist/trigger/system-definitions.js +43 -7
- package/dist/trigger/validation.js +13 -5
- package/dist/utils/cross-platform.js +14 -0
- package/dist/utils/ecweb-supervisor.js +258 -83
- package/dist/utils/error-utils.js +16 -2
- package/dist/utils/logger.js +24 -5
- package/dist/utils/npm-ops.js +2 -1
- package/dist/utils/package-version-info.js +5 -3
- package/dist/utils/upgrade-jobs.js +45 -5
- package/kits/docs/INDEX.md +1 -1
- package/kits/docs/aun/ABILITY_CALLING.md +20 -2
- package/kits/docs/channels/aun.md +9 -0
- package/kits/docs/evolcore/INDEX.md +2 -1
- package/kits/docs/evolcore/agent-create.md +3 -2
- package/kits/docs/evolcore/agent.md +1 -1
- package/kits/docs/evolcore/config.md +18 -7
- package/kits/docs/evolcore/contact.md +3 -0
- package/kits/docs/evolcore/event.md +1 -0
- package/kits/docs/evolcore/fs.md +16 -0
- package/kits/docs/evolcore/memory-architecture.md +2 -2
- package/kits/docs/evolcore/memory-consolidation.md +32 -8
- package/kits/docs/evolcore/memory.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +36 -0
- package/kits/docs/evolcore/model.md +23 -20
- package/kits/docs/evolcore/msg.md +21 -8
- package/kits/docs/evolcore/session.md +14 -0
- package/kits/migrations/migrate-contact-book-v2.mjs +30 -11
- package/kits/schemas/_meta.json +37 -4
- package/kits/schemas/agent-config.schema.13.json +23 -3
- package/kits/schemas/agent-config.schema.16.json +891 -0
- package/kits/schemas/daemon.schema.9.json +366 -0
- package/kits/schemas/defaults.schema.5.json +406 -127
- package/kits/schemas/relation-config.schema.11.json +260 -0
- package/kits/schemas/role-config.schema.1.json +7 -7
- package/kits/skills/.switches.json +3 -7
- package/kits/skills/aid-ability/SKILL.md +35 -6
- package/kits/skills/ec-service-proxy/SKILL.md +118 -0
- package/kits/skills/ec-trigger/SKILL.md +13 -5
- package/kits/skills/personal-assistant/SKILL.md +176 -0
- package/kits/skills/personal-assistant/references/01-workspace-spec.md +333 -0
- package/kits/skills/personal-assistant/references/02-bootstrap.md +205 -0
- package/kits/skills/personal-assistant/references/03-data-flow-and-gaps.md +177 -0
- package/kits/skills/personal-assistant/references/04-frontend-contract.md +439 -0
- package/kits/skills/personal-assistant/references/05-directory-reference.md +292 -0
- package/kits/skills/personal-assistant/references/06-render-config.md +350 -0
- package/kits/skills/personal-assistant/schema/workspace.schema.json +85 -0
- package/kits/skills/personal-assistant/schema/workspace.v1.json +66 -0
- package/kits/skills/personal-assistant/scripts/archive.mjs +154 -0
- package/kits/skills/personal-assistant/scripts/check.mjs +114 -0
- package/kits/skills/personal-assistant/scripts/index-rebuild.mjs +252 -0
- package/kits/skills/personal-assistant/scripts/ingest.mjs +344 -0
- package/kits/skills/personal-assistant/scripts/init.mjs +270 -0
- package/kits/skills/personal-assistant/scripts/lib/apply.mjs +92 -0
- package/kits/skills/personal-assistant/scripts/lib/schema.mjs +96 -0
- package/kits/skills/personal-assistant/scripts/lib/time.mjs +28 -0
- package/kits/skills/personal-assistant/scripts/migrate.mjs +172 -0
- package/kits/skills/personal-assistant/scripts/search.mjs +172 -0
- package/kits/skills/personal-assistant/scripts/verify.mjs +196 -0
- package/kits/skills/personal-assistant/templates/INDEX.md.tpl +24 -0
- package/kits/skills/personal-assistant/templates/README.md.tpl +108 -0
- package/kits/skills/personal-assistant/triggers/ingest-daily.json +23 -0
- package/kits/skills/personal-assistant/triggers/memory-consolidate.json +23 -0
- package/kits/skills/personal-assistant/triggers/report-daily.json +23 -0
- package/kits/skills/personal-assistant/triggers/report-weekly.json +23 -0
- package/kits/templates/memory-consolidation/forget.md +19 -6
- package/kits/templates/memory-consolidation/notes.md +1 -1
- package/kits/templates/memory-consolidation/profile.md +2 -2
- package/kits/templates/memory-consolidation/promote.md +20 -3
- package/kits/templates/roles/member.json +8 -1
- package/kits/templates/session-capsule/recovery.md +5 -0
- package/kits/templates/session-capsule/renew.md +5 -0
- package/kits/templates/system-fragments/baseagent.md +2 -2
- package/kits/templates/system-fragments/bootstrap.md +6 -6
- package/kits/templates/system-fragments/channel.md +1 -1
- package/kits/templates/system-fragments/memory.md +4 -4
- package/package.json +7 -3
- package/dist/stats/billing.js +0 -215
package/dist/config-store.js
CHANGED
|
@@ -112,6 +112,81 @@ export function saveDaemonConfig(value) {
|
|
|
112
112
|
}
|
|
113
113
|
catch { /* best-effort */ }
|
|
114
114
|
}
|
|
115
|
+
function validateServiceManagementFields(service, index) {
|
|
116
|
+
const prefix = `daemon.json.services[${service.name ?? index}]`;
|
|
117
|
+
const runtime = service.runtime;
|
|
118
|
+
if (runtime !== undefined) {
|
|
119
|
+
if (!runtime || typeof runtime !== 'object' || Array.isArray(runtime))
|
|
120
|
+
throw new Error(`${prefix}.runtime must be an object`);
|
|
121
|
+
const unknown = Object.keys(runtime).filter(key => !['mode', 'command', 'stopTimeoutMs', 'restart'].includes(key));
|
|
122
|
+
if (unknown.length)
|
|
123
|
+
throw new Error(`${prefix}.runtime contains unsupported fields: ${unknown.join(', ')}`);
|
|
124
|
+
if (runtime.mode !== undefined && !['managed', 'external'].includes(runtime.mode)) {
|
|
125
|
+
throw new Error(`${prefix}.runtime.mode must be managed or external`);
|
|
126
|
+
}
|
|
127
|
+
if (service.name === 'ecweb' && runtime.command !== undefined) {
|
|
128
|
+
throw new Error('daemon.json.services[ecweb].runtime.command is managed by the internal ECWeb adapter');
|
|
129
|
+
}
|
|
130
|
+
if (runtime.command !== undefined) {
|
|
131
|
+
const command = runtime.command;
|
|
132
|
+
if (!command || typeof command !== 'object' || Array.isArray(command)
|
|
133
|
+
|| Object.keys(command).some(key => !['file', 'args', 'cwd'].includes(key))) {
|
|
134
|
+
throw new Error(`${prefix}.runtime.command must contain only file, args, and cwd`);
|
|
135
|
+
}
|
|
136
|
+
if (typeof command.file !== 'string' || !path.isAbsolute(command.file) || command.file.length > 2048) {
|
|
137
|
+
throw new Error(`${prefix}.runtime.command.file must be an absolute executable path`);
|
|
138
|
+
}
|
|
139
|
+
if (command.cwd !== undefined && (typeof command.cwd !== 'string' || !path.isAbsolute(command.cwd) || command.cwd.length > 2048)) {
|
|
140
|
+
throw new Error(`${prefix}.runtime.command.cwd must be an absolute path`);
|
|
141
|
+
}
|
|
142
|
+
if (command.args !== undefined && (!Array.isArray(command.args) || command.args.length > 128
|
|
143
|
+
|| command.args.some((arg) => typeof arg !== 'string' || arg.length > 8192))) {
|
|
144
|
+
throw new Error(`${prefix}.runtime.command.args must be at most 128 strings`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (runtime.mode === 'managed' && service.name !== 'ecweb' && !runtime.command) {
|
|
148
|
+
throw new Error(`${prefix}.runtime.command is required for managed services`);
|
|
149
|
+
}
|
|
150
|
+
if (runtime.stopTimeoutMs !== undefined
|
|
151
|
+
&& (!Number.isInteger(runtime.stopTimeoutMs) || runtime.stopTimeoutMs < 100 || runtime.stopTimeoutMs > 120000)) {
|
|
152
|
+
throw new Error(`${prefix}.runtime.stopTimeoutMs must be 100-120000`);
|
|
153
|
+
}
|
|
154
|
+
if (runtime.restart !== undefined) {
|
|
155
|
+
const restart = runtime.restart;
|
|
156
|
+
const restartFields = ['enabled', 'backoffMs'];
|
|
157
|
+
if (!restart || typeof restart !== 'object' || Array.isArray(restart)
|
|
158
|
+
|| Object.keys(restart).some(key => !restartFields.includes(key))) {
|
|
159
|
+
throw new Error(`${prefix}.runtime.restart contains unsupported fields`);
|
|
160
|
+
}
|
|
161
|
+
if (restart.enabled !== undefined && typeof restart.enabled !== 'boolean') {
|
|
162
|
+
throw new Error(`${prefix}.runtime.restart.enabled must be a boolean`);
|
|
163
|
+
}
|
|
164
|
+
if (restart.backoffMs !== undefined
|
|
165
|
+
&& (!Number.isInteger(restart.backoffMs) || restart.backoffMs < 1 || restart.backoffMs > 3600000)) {
|
|
166
|
+
throw new Error(`${prefix}.runtime.restart.backoffMs must be 1-3600000`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const health = service.health;
|
|
171
|
+
if (health !== undefined) {
|
|
172
|
+
const fields = ['type', 'path', 'timeoutMs', 'failureThreshold', 'startupTimeoutMs'];
|
|
173
|
+
if (!health || typeof health !== 'object' || Array.isArray(health)
|
|
174
|
+
|| Object.keys(health).some(key => !fields.includes(key)))
|
|
175
|
+
throw new Error(`${prefix}.health contains unsupported fields`);
|
|
176
|
+
if (health.type !== undefined && !['http', 'tcp'].includes(health.type))
|
|
177
|
+
throw new Error(`${prefix}.health.type is invalid`);
|
|
178
|
+
if (health.path !== undefined && (typeof health.path !== 'string' || !health.path.startsWith('/') || health.path.length > 1024)) {
|
|
179
|
+
throw new Error(`${prefix}.health.path must be an absolute URL path`);
|
|
180
|
+
}
|
|
181
|
+
for (const field of ['timeoutMs', 'failureThreshold', 'startupTimeoutMs']) {
|
|
182
|
+
const number = health[field];
|
|
183
|
+
const max = field === 'failureThreshold' ? 100 : 300000;
|
|
184
|
+
if (number !== undefined && (!Number.isInteger(number) || number < 1 || number > max)) {
|
|
185
|
+
throw new Error(`${prefix}.health.${field} must be 1-${max}`);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
115
190
|
function validateDaemonConfig(value, validateAidDomain) {
|
|
116
191
|
assertOwnerConfigRecord(value, 'daemon.json', isValidAid);
|
|
117
192
|
if (value.upgrade !== undefined) {
|
|
@@ -180,7 +255,7 @@ function validateDaemonConfig(value, validateAidDomain) {
|
|
|
180
255
|
throw new Error(`daemon.json.services[${index}] must be an object`);
|
|
181
256
|
}
|
|
182
257
|
const service = rawService;
|
|
183
|
-
const unknownServiceFields = Object.keys(service).filter((key) => !['name', 'enabled', 'port', 'proxy'].includes(key));
|
|
258
|
+
const unknownServiceFields = Object.keys(service).filter((key) => !['name', 'enabled', 'port', 'runtime', 'health', 'proxy'].includes(key));
|
|
184
259
|
if (unknownServiceFields.length > 0) {
|
|
185
260
|
throw new Error(`daemon.json.services[${index}] contains unsupported fields: ${unknownServiceFields.join(', ')}`);
|
|
186
261
|
}
|
|
@@ -197,6 +272,7 @@ function validateDaemonConfig(value, validateAidDomain) {
|
|
|
197
272
|
if (service.port !== undefined && (!Number.isInteger(service.port) || service.port < 1 || service.port > 65535)) {
|
|
198
273
|
throw new Error(`daemon.json.services[${service.name}].port must be an integer from 1 to 65535`);
|
|
199
274
|
}
|
|
275
|
+
validateServiceManagementFields(service, index);
|
|
200
276
|
if (service.proxy !== undefined) {
|
|
201
277
|
if (!service.proxy || typeof service.proxy !== 'object' || Array.isArray(service.proxy)) {
|
|
202
278
|
throw new Error(`daemon.json.services[${service.name}].proxy must be an object`);
|
|
@@ -373,12 +449,12 @@ export function autoMigrateIfNeeded() {
|
|
|
373
449
|
: `[migrate] daemon.json schema version -> ${daemonSchemaVersion}`);
|
|
374
450
|
}
|
|
375
451
|
/**
|
|
376
|
-
* @deprecated Use ConfigManager.read(ConfigTarget.Agent, { self: aid }, {
|
|
452
|
+
* @deprecated Use ConfigManager.read(ConfigTarget.Agent, { self: aid }, { cache: true }) instead.
|
|
377
453
|
* This wrapper exists for backward compatibility. All logic (aid validation, path cleaning, env expansion)
|
|
378
454
|
* is now handled by ConfigManager.
|
|
379
455
|
*/
|
|
380
456
|
export function loadAgent(aid) {
|
|
381
|
-
return cfgRead(ConfigTarget.Agent, { self: aid }, {
|
|
457
|
+
return cfgRead(ConfigTarget.Agent, { self: aid }, { cache: true });
|
|
382
458
|
}
|
|
383
459
|
/**
|
|
384
460
|
* @deprecated Use ConfigManager.write(ConfigTarget.Agent, value, { self: value.aid }) instead.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
export function ecwebHomeId(root) {
|
|
4
|
+
const resolved = path.resolve(root);
|
|
5
|
+
const canonical = process.platform === 'win32' ? resolved.toLowerCase() : resolved;
|
|
6
|
+
return crypto.createHash('sha256').update(canonical).digest('hex');
|
|
7
|
+
}
|
|
8
|
+
export function parseEcwebInstanceRecord(value, root, file) {
|
|
9
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
10
|
+
return null;
|
|
11
|
+
const record = value;
|
|
12
|
+
if (!Number.isSafeInteger(record.pid) || record.pid <= 0)
|
|
13
|
+
return null;
|
|
14
|
+
const port = record.port === undefined ? 42705 : record.port;
|
|
15
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535)
|
|
16
|
+
return null;
|
|
17
|
+
if (file && !new RegExp(`^(?:ecweb|watch-web)-${record.pid}\\.json$`).test(path.basename(file)))
|
|
18
|
+
return null;
|
|
19
|
+
if (record.startedAt !== undefined && (typeof record.startedAt !== 'number' || !Number.isFinite(record.startedAt) || record.startedAt <= 0))
|
|
20
|
+
return null;
|
|
21
|
+
if (record.schemaVersion !== undefined) {
|
|
22
|
+
if (record.schemaVersion !== 1 || record.service !== 'ecweb' || record.homeId !== ecwebHomeId(root)
|
|
23
|
+
|| record.port === undefined || record.startedAt === undefined
|
|
24
|
+
|| typeof record.instanceId !== 'string' || !/^[A-Za-z0-9-]{1,128}$/.test(record.instanceId))
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
return { ...record, pid: record.pid, port: port };
|
|
28
|
+
}
|
|
29
|
+
export function matchesEcwebInstanceHealth(value, record) {
|
|
30
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
31
|
+
return false;
|
|
32
|
+
const health = value;
|
|
33
|
+
if (health.ok !== true || health.service !== 'ecweb' || health.processAlive === false)
|
|
34
|
+
return false;
|
|
35
|
+
if (!record)
|
|
36
|
+
return true;
|
|
37
|
+
if (health.pid !== undefined && health.pid !== record.pid)
|
|
38
|
+
return false;
|
|
39
|
+
return record.schemaVersion === undefined
|
|
40
|
+
|| (health.processAlive === true && health.pid === record.pid && health.instanceId === record.instanceId && health.homeId === record.homeId);
|
|
41
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export const ECWEB_SERVICE_PROTOCOL = Object.freeze({
|
|
2
2
|
name: 'evolcore.ecweb',
|
|
3
3
|
major: 1,
|
|
4
|
-
minor:
|
|
4
|
+
minor: 3,
|
|
5
5
|
capabilities: Object.freeze([
|
|
6
6
|
'daemon.status',
|
|
7
7
|
'agent.directory',
|
|
@@ -15,6 +15,8 @@ export const ECWEB_SERVICE_PROTOCOL = Object.freeze({
|
|
|
15
15
|
'monitor.subscription',
|
|
16
16
|
'remote-auth',
|
|
17
17
|
'trigger.history',
|
|
18
|
+
'message.context',
|
|
19
|
+
'session.runnerTasks',
|
|
18
20
|
]),
|
|
19
21
|
});
|
|
20
22
|
export function validateEcwebClientProtocolRequirements(value) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { initializationSummary } from '../cli/agent-create.js';
|
|
1
2
|
import fs from 'node:fs';
|
|
2
3
|
import path from 'node:path';
|
|
3
4
|
import { agentMdPath, resolvePaths, } from '../paths.js';
|
|
@@ -90,11 +91,14 @@ export class AgentApplicationService {
|
|
|
90
91
|
const config = (loadAgent(aid) ?? agent.config);
|
|
91
92
|
const identity = readAgentMdIdentity(aid);
|
|
92
93
|
const paths = resolvePaths();
|
|
94
|
+
const lifecycle = config?.lifecycle ?? null;
|
|
95
|
+
const initialization = initializationSummary(aid);
|
|
96
|
+
const initializationState = initialization && this.initialization?.status(aid);
|
|
93
97
|
return {
|
|
94
98
|
ok: true,
|
|
95
99
|
aid,
|
|
96
100
|
status: info.status || 'stopped',
|
|
97
|
-
lifecycle
|
|
101
|
+
lifecycle,
|
|
98
102
|
identity,
|
|
99
103
|
config: {
|
|
100
104
|
baseagent: info.baseagent || null,
|
|
@@ -104,6 +108,12 @@ export class AgentApplicationService {
|
|
|
104
108
|
channels: info.channels ?? [],
|
|
105
109
|
},
|
|
106
110
|
connection,
|
|
111
|
+
...(initialization ? {
|
|
112
|
+
initialization,
|
|
113
|
+
usable: typeof initializationState?.usable === 'boolean'
|
|
114
|
+
? initializationState.usable
|
|
115
|
+
: initialization.complete === true && lifecycle === 'active' && connection?.status === 'connected',
|
|
116
|
+
} : {}),
|
|
107
117
|
sessions: {
|
|
108
118
|
active: info.activeSessions ?? 0,
|
|
109
119
|
last_activity: info.lastActivity ? new Date(info.lastActivity).toISOString() : null,
|
|
@@ -274,6 +274,10 @@ export function registerAgentOperationExecutor({ ipcServer, sessionManager, agen
|
|
|
274
274
|
const plan = resolveInitializationPlan(argv.slice(1), {
|
|
275
275
|
projectCwd: taskSession.projectPath, tempDir: delegation.grant.sessionRuntimeDir,
|
|
276
276
|
});
|
|
277
|
+
const { validateInitializationModelArgs } = await import('../cli/agent-create.js');
|
|
278
|
+
const modelError = await validateInitializationModelArgs(plan);
|
|
279
|
+
if (modelError)
|
|
280
|
+
return fail(modelError.code, modelError.error);
|
|
277
281
|
if (plan.avatarFile?.startsWith('attachment:')) {
|
|
278
282
|
const { readRelationAttachment } = await import('../utils/media-cache.js');
|
|
279
283
|
plan.avatarFile = readRelationAttachment(taskAid, delegation.grant.peerKey, plan.avatarFile.slice('attachment:'.length)).attachment.filePath;
|
|
@@ -357,7 +357,7 @@ export function createAgentRuntimeOperations({ agentRegistry, agentLoader, sessi
|
|
|
357
357
|
if (!diskCfg || diskCfg.enabled === false) {
|
|
358
358
|
try {
|
|
359
359
|
const offlined = await reloadCoordinator.runExclusive(aid, async () => {
|
|
360
|
-
const latestDiskCfg = readConfig(ConfigTarget.Agent, { self: aid }, { cache: false
|
|
360
|
+
const latestDiskCfg = readConfig(ConfigTarget.Agent, { self: aid }, { cache: false });
|
|
361
361
|
if (latestDiskCfg && latestDiskCfg.enabled !== false)
|
|
362
362
|
return false;
|
|
363
363
|
const runtimeAgent = agentRegistry.get(aid);
|
|
@@ -10,6 +10,7 @@ import { DebugDelegationRegistry, DEBUG_TOKEN_PREFIX } from './debug-context.js'
|
|
|
10
10
|
import { DelegationDiagnostics, } from './delegation-diagnostics.js';
|
|
11
11
|
export const AGENT_DELEGATION_TOKEN_ENV = 'EVOLCORE_DELEGATION_TOKEN';
|
|
12
12
|
export const CODEX_SESSION_TOKEN_ENV = 'EVOLCORE_CODEX_SESSION_TOKEN';
|
|
13
|
+
export const DELEGATED_EXECUTION_SPEC_ENV = 'EVOLCORE_DELEGATED_EXECUTION_SPEC';
|
|
13
14
|
export const AGENT_DELEGATION_COMMAND_TTL_MS = 5 * 60_000;
|
|
14
15
|
const INTERNAL_DELEGATION_TTL_MS = 30_000;
|
|
15
16
|
/**
|
|
@@ -169,6 +170,7 @@ export class AgentDelegationRegistry {
|
|
|
169
170
|
return false;
|
|
170
171
|
const sessionToken = input.sessionToken ?? input.carrierToken;
|
|
171
172
|
if (!sessionToken || !isDelegationCommandHash(input.commandHash)
|
|
173
|
+
|| (input.specHash !== undefined && !isDelegationCommandHash(input.specHash))
|
|
172
174
|
|| !input.approvalId || input.approvalId.length > 512 || input.approvalId.includes('\0'))
|
|
173
175
|
return false;
|
|
174
176
|
this.deleteExpiredApprovedCommands();
|
|
@@ -186,7 +188,7 @@ export class AgentDelegationRegistry {
|
|
|
186
188
|
this.approvedCommandBindings.delete(bindingKey);
|
|
187
189
|
}
|
|
188
190
|
else {
|
|
189
|
-
return existingBinding.commandHash === input.commandHash;
|
|
191
|
+
return existingBinding.commandHash === input.commandHash && existingBinding.specHash === input.specHash;
|
|
190
192
|
}
|
|
191
193
|
}
|
|
192
194
|
const key = approvedCommandKey(sessionTokenHash, input.sessionId, input.commandHash);
|
|
@@ -213,6 +215,7 @@ export class AgentDelegationRegistry {
|
|
|
213
215
|
approvalId: input.approvalId,
|
|
214
216
|
activeTokenHash,
|
|
215
217
|
commandHash: input.commandHash,
|
|
218
|
+
specHash: input.specHash,
|
|
216
219
|
expiresAt,
|
|
217
220
|
consumed: false,
|
|
218
221
|
});
|
|
@@ -490,10 +493,11 @@ export async function authorizeDelegatedAunMsgSend(registry, input) {
|
|
|
490
493
|
export function trustedExecutionIdentityInput(grant) {
|
|
491
494
|
return grant.executionIdentity && isValidFullAccessExecutionIdentity(grant.executionIdentity)
|
|
492
495
|
? {
|
|
496
|
+
sessionId: grant.sessionId,
|
|
493
497
|
trustedProcessRole: 'fullaccess-run',
|
|
494
498
|
trustedFullAccessAuthorization: grant.executionIdentity,
|
|
495
499
|
}
|
|
496
|
-
: {};
|
|
500
|
+
: { sessionId: grant.sessionId };
|
|
497
501
|
}
|
|
498
502
|
export function hasTrustedFullAccessDelegation(grant) {
|
|
499
503
|
return !!grant.executionIdentity && isValidFullAccessExecutionIdentity(grant.executionIdentity);
|
|
@@ -544,17 +548,89 @@ function delegationFailureDetailCode(cause) {
|
|
|
544
548
|
return 'APPROVED_COMMAND_UNAVAILABLE';
|
|
545
549
|
}
|
|
546
550
|
}
|
|
547
|
-
export function hashDelegatedCommandArgv(argv) {
|
|
551
|
+
export function hashDelegatedCommandArgv(argv, executionSpec) {
|
|
548
552
|
if (argv.length === 0 || argv.some(value => typeof value !== 'string' || value.includes('\0')))
|
|
549
553
|
return undefined;
|
|
554
|
+
if (executionSpec !== undefined && (hashDelegatedCommandSpec(executionSpec) === undefined
|
|
555
|
+
|| JSON.stringify(executionSpec.argv) !== JSON.stringify(argv)))
|
|
556
|
+
return undefined;
|
|
557
|
+
return crypto.createHash('sha256')
|
|
558
|
+
.update(executionSpec ? 'evolcore-agent-delegation-command-v2\0' : 'evolcore-agent-delegation-command-v1\0')
|
|
559
|
+
.update(JSON.stringify(executionSpec ? { argv, executionSpec } : argv))
|
|
560
|
+
.digest('hex');
|
|
561
|
+
}
|
|
562
|
+
export function readDelegatedExecutionSpec(env = process.env) {
|
|
563
|
+
const raw = env[DELEGATED_EXECUTION_SPEC_ENV]?.trim();
|
|
564
|
+
if (!raw || raw.length > 16 * 1024)
|
|
565
|
+
return undefined;
|
|
566
|
+
try {
|
|
567
|
+
const spec = parseDelegatedExecutionSpec(raw);
|
|
568
|
+
const currentArgv = currentDelegatedCommandArgv();
|
|
569
|
+
return spec && currentArgv
|
|
570
|
+
&& JSON.stringify(spec.argv) === JSON.stringify([MAIN_CLI_BIN, ...currentArgv])
|
|
571
|
+
? spec
|
|
572
|
+
: undefined;
|
|
573
|
+
}
|
|
574
|
+
catch {
|
|
575
|
+
return undefined;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
export function parseDelegatedExecutionSpec(raw) {
|
|
579
|
+
if (typeof raw !== 'string' || !raw || raw.length > 16 * 1024)
|
|
580
|
+
return undefined;
|
|
581
|
+
let value;
|
|
582
|
+
try {
|
|
583
|
+
value = JSON.parse(raw);
|
|
584
|
+
}
|
|
585
|
+
catch {
|
|
586
|
+
return undefined;
|
|
587
|
+
}
|
|
588
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
589
|
+
return undefined;
|
|
590
|
+
const spec = value;
|
|
591
|
+
if (spec.version !== 1 || !['posix', 'powershell', 'cmd'].includes(String(spec.dialect))
|
|
592
|
+
|| !['bounded-output', 'cd-prefixed'].includes(String(spec.wrapper))
|
|
593
|
+
|| !Array.isArray(spec.argv) || spec.argv.some(arg => typeof arg !== 'string' || arg.includes('\0'))
|
|
594
|
+
|| spec.argv[0] !== MAIN_CLI_BIN)
|
|
595
|
+
return undefined;
|
|
596
|
+
if (spec.cwd !== undefined && (typeof spec.cwd !== 'string' || spec.cwd.includes('\0')))
|
|
597
|
+
return undefined;
|
|
598
|
+
if (spec.outputPath !== undefined && (typeof spec.outputPath !== 'string' || spec.outputPath.includes('\0')))
|
|
599
|
+
return undefined;
|
|
600
|
+
if (spec.mergeStderr !== undefined && typeof spec.mergeStderr !== 'boolean')
|
|
601
|
+
return undefined;
|
|
602
|
+
if (spec.suffixArgv !== undefined && (!Array.isArray(spec.suffixArgv)
|
|
603
|
+
|| spec.suffixArgv.some(arg => typeof arg !== 'string' || arg.includes('\0'))))
|
|
604
|
+
return undefined;
|
|
605
|
+
if (spec.filterChain !== undefined && (!Array.isArray(spec.filterChain)
|
|
606
|
+
|| spec.filterChain.some(stage => !Array.isArray(stage)
|
|
607
|
+
|| stage.some(arg => typeof arg !== 'string' || arg.includes('\0')))))
|
|
608
|
+
return undefined;
|
|
609
|
+
return spec;
|
|
610
|
+
}
|
|
611
|
+
/** Bind an approval to the complete shell-independent execution shape. */
|
|
612
|
+
export function hashDelegatedCommandSpec(spec) {
|
|
613
|
+
const values = [
|
|
614
|
+
...spec.argv,
|
|
615
|
+
spec.dialect,
|
|
616
|
+
spec.wrapper,
|
|
617
|
+
spec.cwd,
|
|
618
|
+
spec.outputPath,
|
|
619
|
+
...(spec.filterChain ?? []).flat(),
|
|
620
|
+
...(spec.suffixArgv ?? []),
|
|
621
|
+
];
|
|
622
|
+
if (spec.version !== 1 || values.some(value => value !== undefined && (typeof value !== 'string' || value.includes('\0')))) {
|
|
623
|
+
return undefined;
|
|
624
|
+
}
|
|
550
625
|
return crypto.createHash('sha256')
|
|
551
|
-
.update('evolcore-agent-delegation-
|
|
552
|
-
.update(JSON.stringify(
|
|
626
|
+
.update('evolcore-agent-delegation-spec-v1\0')
|
|
627
|
+
.update(JSON.stringify(spec))
|
|
553
628
|
.digest('hex');
|
|
554
629
|
}
|
|
555
630
|
export function hashCurrentDelegatedCommand(processArgv = process.argv) {
|
|
556
631
|
const argv = currentDelegatedCommandArgv(processArgv);
|
|
557
|
-
|
|
632
|
+
const spec = readDelegatedExecutionSpec();
|
|
633
|
+
return argv ? hashDelegatedCommandArgv([MAIN_CLI_BIN, ...argv], spec) : undefined;
|
|
558
634
|
}
|
|
559
635
|
/**
|
|
560
636
|
* Return the command arguments used by a delegated CLI invocation.
|
|
@@ -107,7 +107,7 @@ export async function authorizeFreshOperation(params) {
|
|
|
107
107
|
const configCommand = params.resolvedConfigCommand;
|
|
108
108
|
const changesOwner = configCommand?.kind === 'field' && configCommand.subcommand !== 'get'
|
|
109
109
|
&& ['owner', 'owners'].includes(configCommand.field.split('.')[0]);
|
|
110
|
-
const force = changesOwner || ['ec.aid.bind', 'ec.aid.
|
|
110
|
+
const force = changesOwner || ['ec.aid.bind', 'ec.aid.unbind', 'ec.aid.transfer']
|
|
111
111
|
.includes(params.intent.operation) || params.intent.operation === 'config.restore';
|
|
112
112
|
const operation = getOperationMeta(params.intent.operation);
|
|
113
113
|
const sensitive = force || params.intent.dangerous || operation?.dangerous || operation?.category !== 'read'
|
|
@@ -12,7 +12,7 @@ export function auditCommandAuthorization(event) {
|
|
|
12
12
|
(event.source === 'agent-tool' && event.operation.startsWith('config.')) ||
|
|
13
13
|
event.operation === 'codex.approval' ||
|
|
14
14
|
event.operation === 'permission.approval' ||
|
|
15
|
-
event.operation
|
|
15
|
+
event.operation.startsWith('permission.runtime') ||
|
|
16
16
|
event.operation.startsWith('fullaccess.') ||
|
|
17
17
|
event.operation.startsWith('role.') ||
|
|
18
18
|
event.operation === 'file.root.storage' ||
|
|
@@ -280,14 +280,14 @@ export function auditToolInfrastructureFailure(input) {
|
|
|
280
280
|
eventKey: buildToolLifecycleEventKey(input),
|
|
281
281
|
eventPhase: 'final',
|
|
282
282
|
source: 'agent-tool',
|
|
283
|
-
operation: 'tool.execution.blocked',
|
|
283
|
+
operation: input.fallback ? 'permission.runtime.sandbox_fallback' : 'tool.execution.blocked',
|
|
284
284
|
scope: 'filesystem',
|
|
285
285
|
dangerous: false,
|
|
286
|
-
decision: 'deny',
|
|
286
|
+
decision: input.fallback ? 'allow' : 'deny',
|
|
287
287
|
decisionSource: 'infrastructure',
|
|
288
288
|
errorCode: infrastructureErrorCode(input.policyCode),
|
|
289
289
|
executed: false,
|
|
290
|
-
executionState: 'blocked',
|
|
290
|
+
executionState: input.fallback ? 'authorized' : 'blocked',
|
|
291
291
|
...normalizeToolCorrelation(input),
|
|
292
292
|
sessionId: input.sessionId ?? 'unknown',
|
|
293
293
|
agentAid: input.agentAid ?? 'unknown',
|
|
@@ -301,6 +301,7 @@ export function auditToolInfrastructureFailure(input) {
|
|
|
301
301
|
argsSummary: input.occurrences || input.sandboxFailure
|
|
302
302
|
? {
|
|
303
303
|
...(input.occurrences ? { occurrences: input.occurrences } : {}),
|
|
304
|
+
...(input.fallback ? { sandboxFallback: true } : {}),
|
|
304
305
|
// Flat primitive fields survive the audit argument redactor and can
|
|
305
306
|
// be aggregated without reparsing (possibly truncated) stderr.
|
|
306
307
|
...(input.sandboxFailure ? {
|
|
@@ -367,8 +368,9 @@ function buildAuditRecord(event) {
|
|
|
367
368
|
: undefined;
|
|
368
369
|
const errorCode = classification?.errorCode;
|
|
369
370
|
const ecwebRequestId = event.source === 'ecweb' ? event.ecwebRequestId : undefined;
|
|
370
|
-
const
|
|
371
|
-
const
|
|
371
|
+
const sourceRequestId = event.requestId ?? ecwebRequestId;
|
|
372
|
+
const requestId = namespaceAuditRequestId(event.source, event.sessionId, sourceRequestId);
|
|
373
|
+
const correlationId = event.correlationId ?? event.callId ?? sourceRequestId;
|
|
372
374
|
return {
|
|
373
375
|
type: 'authorization:audit',
|
|
374
376
|
ts: event.ts,
|
|
@@ -380,17 +382,20 @@ function buildAuditRecord(event) {
|
|
|
380
382
|
sessionId: event.sessionId,
|
|
381
383
|
callId: event.callId,
|
|
382
384
|
correlationId,
|
|
383
|
-
requestId,
|
|
385
|
+
requestId: sourceRequestId,
|
|
384
386
|
operation: event.operation,
|
|
385
387
|
})),
|
|
386
388
|
eventPhase: event.eventPhase,
|
|
387
389
|
callId: event.callId,
|
|
388
390
|
correlationId,
|
|
389
391
|
requestId,
|
|
392
|
+
sourceRequestId,
|
|
390
393
|
sessionId: event.sessionId,
|
|
391
|
-
...(
|
|
394
|
+
...(!event.sessionId ? {
|
|
395
|
+
sessionScope: event.source === 'ecweb' ? 'not_applicable' : 'unknown',
|
|
396
|
+
} : {}),
|
|
392
397
|
agentAid: redactIdentifier(event.agentAid ?? event.selfAid),
|
|
393
|
-
agentName: resolveAgentName(event),
|
|
398
|
+
agentName: resolveAgentName(event) ?? 'unknown',
|
|
394
399
|
permissionMode: normalizeAuditPermissionMode(event.permissionMode),
|
|
395
400
|
toolName: event.toolName,
|
|
396
401
|
approvalMethod: event.approvalMethod,
|
|
@@ -438,6 +443,15 @@ function buildAuditRecord(event) {
|
|
|
438
443
|
exitCode: event.exitCode,
|
|
439
444
|
};
|
|
440
445
|
}
|
|
446
|
+
function namespaceAuditRequestId(source, sessionId, sourceRequestId) {
|
|
447
|
+
if (sourceRequestId === undefined)
|
|
448
|
+
return undefined;
|
|
449
|
+
const namespace = source === 'ecweb' && !sessionId ? [source] : [source, sessionId ?? 'unknown'];
|
|
450
|
+
// JSON escaping also preserves unpaired UTF-16 surrogates from source IDs;
|
|
451
|
+
// encodeURIComponent alone would throw and interrupt authorization auditing.
|
|
452
|
+
const parts = [...namespace, sourceRequestId].map(part => encodeURIComponent(JSON.stringify(part).slice(1, -1)));
|
|
453
|
+
return `audit:v1:${parts.join(':')}`;
|
|
454
|
+
}
|
|
441
455
|
function resolveAgentName(event) {
|
|
442
456
|
const displayName = typeof event.agentName === 'string' ? event.agentName.trim() : '';
|
|
443
457
|
if (displayName && !isUnknownAgentLabel(displayName))
|
|
@@ -448,6 +462,14 @@ function resolveAgentName(event) {
|
|
|
448
462
|
const selfAid = typeof event.selfAid === 'string' ? event.selfAid.trim() : '';
|
|
449
463
|
if (selfAid && selfAid !== 'unknown')
|
|
450
464
|
return selfAid;
|
|
465
|
+
const targetAgentAid = event.source === 'ecweb' && typeof event.targetAgentAid === 'string'
|
|
466
|
+
? event.targetAgentAid.trim() : '';
|
|
467
|
+
if (targetAgentAid && targetAgentAid !== 'unknown')
|
|
468
|
+
return targetAgentAid;
|
|
469
|
+
const actorId = event.source === 'ecweb' && typeof event.actorId === 'string'
|
|
470
|
+
? event.actorId.trim() : '';
|
|
471
|
+
if (actorId && !isUnknownAgentLabel(actorId))
|
|
472
|
+
return actorId;
|
|
451
473
|
return aid === 'unknown' || selfAid === 'unknown' ? 'unknown' : undefined;
|
|
452
474
|
}
|
|
453
475
|
function isUnknownAgentLabel(value) {
|
|
@@ -493,6 +515,7 @@ function logAuditEvent(record) {
|
|
|
493
515
|
record.taskId ? `task=${record.taskId}` : null,
|
|
494
516
|
record.messageId ? `message=${record.messageId}` : null,
|
|
495
517
|
record.requestId ? `request=${record.requestId}` : null,
|
|
518
|
+
record.sourceRequestId ? `sourceRequest=${JSON.stringify(record.sourceRequestId)}` : null,
|
|
496
519
|
record.callId ? `call=${record.callId}` : null,
|
|
497
520
|
record.correlationId ? `correlation=${record.correlationId}` : null,
|
|
498
521
|
record.eventKey ? `eventKey=${record.eventKey}` : null,
|
|
@@ -601,6 +624,11 @@ function summarizeAuthorizationArgs(operation, args) {
|
|
|
601
624
|
? Math.max(0, Math.floor(diagnostic.inputLength)) : undefined;
|
|
602
625
|
if (issue && offset !== undefined && tokenIndex !== undefined && dialect && inputLength !== undefined) {
|
|
603
626
|
summary.parseFailure = { issue, offset, tokenIndex, dialect, inputLength };
|
|
627
|
+
for (const field of ['canonicalizationStage', 'wrapper', 'redirectDetected', 'managedTempPath', 'managedTempResolved']) {
|
|
628
|
+
if (typeof diagnostic[field] === 'string' || typeof diagnostic[field] === 'boolean') {
|
|
629
|
+
summary.parseFailure[field] = diagnostic[field];
|
|
630
|
+
}
|
|
631
|
+
}
|
|
604
632
|
}
|
|
605
633
|
continue;
|
|
606
634
|
}
|
|
@@ -40,7 +40,9 @@ export function createDelegationAuthorizer({ agentDelegationRegistry, sessionMan
|
|
|
40
40
|
subject,
|
|
41
41
|
intent: {
|
|
42
42
|
operation,
|
|
43
|
-
scope: operation === 'system.status'
|
|
43
|
+
scope: operation === 'system.status' || operation === 'proxy.configure' || operation === 'proxy.lifecycle'
|
|
44
|
+
? 'process'
|
|
45
|
+
: 'agent',
|
|
44
46
|
source: 'agent-tool',
|
|
45
47
|
args: { self: delegation.grant.selfAid, aid: params.targetAid ?? delegation.grant.selfAid },
|
|
46
48
|
},
|
|
@@ -45,6 +45,11 @@ const DAEMON_OWNER_MODEL_OPTION_READ_OPERATIONS = new Set([
|
|
|
45
45
|
'model.list',
|
|
46
46
|
'model.effort.current',
|
|
47
47
|
]);
|
|
48
|
+
const MODEL_WRITE_OPERATIONS = new Set([
|
|
49
|
+
'model.use',
|
|
50
|
+
'model.effort',
|
|
51
|
+
'model.reset',
|
|
52
|
+
]);
|
|
48
53
|
export function authorizeCommand(ctx) {
|
|
49
54
|
return authorizeCommandInternal(ctx);
|
|
50
55
|
}
|
|
@@ -212,6 +217,16 @@ function authorizeCommandInternal(ctx, resolvedConfigCommand) {
|
|
|
212
217
|
matchedRule: 'daemon-owner-model-options-read',
|
|
213
218
|
};
|
|
214
219
|
}
|
|
220
|
+
// 模型参数只在 Agent 级:写操作只能落 agent scope,且只有该 Agent 的 owner/admin
|
|
221
|
+
// (或 DaemonOwner)能改。这是代码级上限,角色文件授予 model.* 也不能越过。
|
|
222
|
+
if (MODEL_WRITE_OPERATIONS.has(operation)) {
|
|
223
|
+
if (intent.scope !== 'agent') {
|
|
224
|
+
return denyDecision(ctx, 'SCOPE_MISMATCH', '模型参数只能在 Agent 级配置,不支持关系级设置', operation, intent.scope, opMeta.dangerous);
|
|
225
|
+
}
|
|
226
|
+
if (!hasDaemonOwnerRole(ctx) && !(isManagementRole(role) && isCurrentAgentTarget(ctx))) {
|
|
227
|
+
return denyDecision(ctx, 'NOT_ALLOWED', '只有当前 Agent 的 owner/admin 可以修改模型', operation, intent.scope, opMeta.dangerous);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
215
230
|
if (requiresDaemonOwner(ctx, resolvedConfigCommand)) {
|
|
216
231
|
if (!hasDaemonOwnerRole(ctx)) {
|
|
217
232
|
const reasonCode = daemonOwnerDenialReasonCode(ctx);
|
|
@@ -129,6 +129,30 @@ const QUEUE_OPERATIONS = [['read', 'Read the current Agent message queue'], ['cl
|
|
|
129
129
|
* 参照设计文档 docs/command-execution-role-permission-design.md 第 5 节
|
|
130
130
|
*/
|
|
131
131
|
const OPERATIONS = [
|
|
132
|
+
{
|
|
133
|
+
id: 'proxy.read',
|
|
134
|
+
category: 'read',
|
|
135
|
+
dangerous: false,
|
|
136
|
+
defaultScopes: ['agent'],
|
|
137
|
+
description: '查看当前 daemon 的本地服务与 ServiceProxy 状态',
|
|
138
|
+
sources: ['agent-tool'],
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
id: 'proxy.configure',
|
|
142
|
+
category: 'process',
|
|
143
|
+
dangerous: true,
|
|
144
|
+
defaultScopes: ['process'],
|
|
145
|
+
description: '创建、修改、发布或删除本地服务代理配置',
|
|
146
|
+
sources: ['agent-tool'],
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
id: 'proxy.lifecycle',
|
|
150
|
+
category: 'process',
|
|
151
|
+
dangerous: true,
|
|
152
|
+
defaultScopes: ['process'],
|
|
153
|
+
description: '启动、停止、重载或守护本地服务',
|
|
154
|
+
sources: ['agent-tool'],
|
|
155
|
+
},
|
|
132
156
|
// ── Model Operations ──
|
|
133
157
|
{
|
|
134
158
|
id: 'baseagent.models.list',
|
|
@@ -178,28 +202,29 @@ const OPERATIONS = [
|
|
|
178
202
|
description: '检查模型可用性(可能触发网关探测)',
|
|
179
203
|
sources: ['slash', 'menu.cli', 'agent-tool'],
|
|
180
204
|
},
|
|
205
|
+
// 模型参数只在 Agent 级配置,仅 owner/admin 可写(operation-authorizer 另有代码级上限)。
|
|
181
206
|
{
|
|
182
207
|
id: 'model.use',
|
|
183
208
|
category: 'write-own',
|
|
184
209
|
dangerous: false,
|
|
185
|
-
defaultScopes: ['
|
|
186
|
-
description: '
|
|
210
|
+
defaultScopes: ['agent'],
|
|
211
|
+
description: '设置 Agent 使用的模型',
|
|
187
212
|
sources: ['slash', 'menu', 'menu.cli', 'agent-tool'],
|
|
188
213
|
},
|
|
189
214
|
{
|
|
190
215
|
id: 'model.effort',
|
|
191
216
|
category: 'write-own',
|
|
192
217
|
dangerous: false,
|
|
193
|
-
defaultScopes: ['
|
|
194
|
-
description: '
|
|
218
|
+
defaultScopes: ['agent'],
|
|
219
|
+
description: '设置 Agent 的推理强度',
|
|
195
220
|
sources: ['slash', 'menu', 'menu.cli', 'agent-tool'],
|
|
196
221
|
},
|
|
197
222
|
{
|
|
198
223
|
id: 'model.reset',
|
|
199
224
|
category: 'write-own',
|
|
200
225
|
dangerous: false,
|
|
201
|
-
defaultScopes: ['
|
|
202
|
-
description: '
|
|
226
|
+
defaultScopes: ['agent'],
|
|
227
|
+
description: '清除 Agent 的模型与推理强度设置',
|
|
203
228
|
sources: ['slash', 'menu.cli', 'agent-tool'],
|
|
204
229
|
},
|
|
205
230
|
// ── Session Operations ──
|
|
@@ -1046,6 +1071,14 @@ const OPERATIONS = [
|
|
|
1046
1071
|
description: '删除云存储对象',
|
|
1047
1072
|
sources: ['menu.cli', 'agent-tool', 'control'],
|
|
1048
1073
|
},
|
|
1074
|
+
{
|
|
1075
|
+
id: 'storage.get_by_share',
|
|
1076
|
+
category: 'write-agent',
|
|
1077
|
+
dangerous: true,
|
|
1078
|
+
defaultScopes: ['agent', 'control'],
|
|
1079
|
+
description: '通过分享短码从云存储下载文件',
|
|
1080
|
+
sources: ['menu.cli', 'agent-tool', 'control'],
|
|
1081
|
+
},
|
|
1049
1082
|
// ── Gateway & Config Operations ──
|
|
1050
1083
|
{
|
|
1051
1084
|
id: 'gateway.read',
|