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,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ec invoke` 的 argv 解析与 daemon 侧执行。
|
|
3
|
+
*
|
|
4
|
+
* 鉴权与 `provider.op` 同一条链:本地控制令牌或任务委托令牌。
|
|
5
|
+
* 与 provider.op 的差别在于 invoke **不做配置变更**,也不受 fullaccess 限制——
|
|
6
|
+
* 调用一个已登记的端点不改变任何状态。
|
|
7
|
+
*/
|
|
8
|
+
import { executeInvoke } from '../core/invoke/invoke-service.js';
|
|
9
|
+
function argumentError(message) {
|
|
10
|
+
throw Object.assign(new Error(message), { code: 'INVALID_ARGUMENT' });
|
|
11
|
+
}
|
|
12
|
+
const SAFE_ID = /^[A-Za-z0-9_-]+$/u;
|
|
13
|
+
const PROHIBITED = new Set(['__proto__', 'constructor', 'prototype']);
|
|
14
|
+
/** 解析 `ec invoke` 的 argv(含首个 'invoke')。 */
|
|
15
|
+
export function parseInvokeArgv(argv) {
|
|
16
|
+
if (!Array.isArray(argv) || argv.some(value => typeof value !== 'string') || argv[0] !== 'invoke') {
|
|
17
|
+
argumentError('invoke.op requires invoke argv');
|
|
18
|
+
}
|
|
19
|
+
const options = new Map();
|
|
20
|
+
const flags = new Set();
|
|
21
|
+
const valueFlags = new Set(['--provider', '--service', '--model', '--out', '--timeout', '--timeout-ms', '--retries', '--input', '--input-file', '--format']);
|
|
22
|
+
const boolFlags = new Set(['--dry-run']);
|
|
23
|
+
for (let index = 1; index < argv.length; index++) {
|
|
24
|
+
const token = argv[index];
|
|
25
|
+
if (!token.startsWith('-'))
|
|
26
|
+
argumentError(`unexpected argument: ${token}`);
|
|
27
|
+
const separator = token.indexOf('=');
|
|
28
|
+
const name = separator < 0 ? token : token.slice(0, separator);
|
|
29
|
+
if (boolFlags.has(name)) {
|
|
30
|
+
if (separator >= 0)
|
|
31
|
+
argumentError(`${name} does not take a value`);
|
|
32
|
+
flags.add(name);
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (!valueFlags.has(name))
|
|
36
|
+
argumentError(`unknown or duplicate option: ${name}`);
|
|
37
|
+
if (options.has(name))
|
|
38
|
+
argumentError(`unknown or duplicate option: ${name}`);
|
|
39
|
+
const value = separator < 0 ? argv[++index] : token.slice(separator + 1);
|
|
40
|
+
if (typeof value !== 'string' || !value || value.startsWith('--'))
|
|
41
|
+
argumentError(`${name} requires a value`);
|
|
42
|
+
options.set(name, value);
|
|
43
|
+
}
|
|
44
|
+
if (options.has('--format') && options.get('--format') !== 'json' && options.get('--format') !== 'text') {
|
|
45
|
+
argumentError('--format must be json or text');
|
|
46
|
+
}
|
|
47
|
+
const providerId = options.get('--provider');
|
|
48
|
+
const serviceType = options.get('--service');
|
|
49
|
+
if (!providerId)
|
|
50
|
+
argumentError('--provider is required');
|
|
51
|
+
if (!serviceType)
|
|
52
|
+
argumentError('--service is required');
|
|
53
|
+
if (!SAFE_ID.test(providerId) || PROHIBITED.has(providerId))
|
|
54
|
+
argumentError('invalid provider id');
|
|
55
|
+
if (!SAFE_ID.test(serviceType) || PROHIBITED.has(serviceType))
|
|
56
|
+
argumentError('invalid service type');
|
|
57
|
+
// 输入可以走 argv(--input / --input-file),也可以由 IPC 单独携带(cmd.input)。
|
|
58
|
+
// 这里只做结构校验,「恰好一种」由 executeInvokeOperation 结合 cmd.input 判定。
|
|
59
|
+
const hasInput = options.has('--input');
|
|
60
|
+
const hasInputFile = options.has('--input-file');
|
|
61
|
+
if (hasInput && hasInputFile)
|
|
62
|
+
argumentError('--input and --input-file are mutually exclusive');
|
|
63
|
+
const retriesRaw = options.get('--retries');
|
|
64
|
+
if (retriesRaw !== undefined && !/^\d+$/u.test(retriesRaw))
|
|
65
|
+
argumentError('--retries must be a non-negative integer');
|
|
66
|
+
// daemon 侧统一收毫秒:`--timeout-ms` 是 CLI 换算后的形态;`--timeout` 也按毫秒接受。
|
|
67
|
+
const timeoutRaw = options.get('--timeout-ms') ?? options.get('--timeout');
|
|
68
|
+
if (timeoutRaw !== undefined && !/^\d+$/u.test(timeoutRaw))
|
|
69
|
+
argumentError('timeout must be a positive integer (ms)');
|
|
70
|
+
return {
|
|
71
|
+
providerId,
|
|
72
|
+
serviceType,
|
|
73
|
+
model: options.get('--model'),
|
|
74
|
+
out: options.get('--out'),
|
|
75
|
+
timeoutMs: timeoutRaw === undefined ? undefined : Number(timeoutRaw),
|
|
76
|
+
retries: retriesRaw === undefined ? undefined : Number(retriesRaw),
|
|
77
|
+
dryRun: flags.has('--dry-run'),
|
|
78
|
+
input: hasInput ? options.get('--input') : undefined,
|
|
79
|
+
inputFile: hasInputFile ? options.get('--input-file') : undefined,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function parseInput(text) {
|
|
83
|
+
if (text === undefined)
|
|
84
|
+
return undefined;
|
|
85
|
+
try {
|
|
86
|
+
return JSON.parse(text.replace(/^/u, ''));
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
argumentError('invoke input must be valid JSON');
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/** Standalone IPC callers have already presented the local control token. */
|
|
93
|
+
export async function executeInvokeOperation(command) {
|
|
94
|
+
try {
|
|
95
|
+
const parsed = parseInvokeArgv(command.argv);
|
|
96
|
+
// CLI 已在本地读好 --input / --input-file,通过 cmd.input 传文本;
|
|
97
|
+
// 直接在 argv 里带 --input 的调用方也支持。
|
|
98
|
+
const inputText = command.input !== undefined ? String(command.input) : parsed.input;
|
|
99
|
+
if (inputText === undefined)
|
|
100
|
+
argumentError('exactly one of --input or --input-file is required');
|
|
101
|
+
const input = parseInput(inputText);
|
|
102
|
+
const request = {
|
|
103
|
+
providerId: parsed.providerId,
|
|
104
|
+
serviceType: parsed.serviceType,
|
|
105
|
+
model: parsed.model,
|
|
106
|
+
input,
|
|
107
|
+
outPath: parsed.out,
|
|
108
|
+
timeoutMs: parsed.timeoutMs,
|
|
109
|
+
retries: parsed.retries,
|
|
110
|
+
dryRun: parsed.dryRun,
|
|
111
|
+
};
|
|
112
|
+
return await executeInvoke(request);
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
const failure = error;
|
|
116
|
+
return { ok: false, code: failure.code ?? 'INVALID_ARGUMENT', error: failure.message ?? 'Invoke failed' };
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -5,7 +5,7 @@ import path from 'path';
|
|
|
5
5
|
import { resolvePaths } from '../paths.js';
|
|
6
6
|
import { acquireConfigMutationLock, ConfigError } from './config-manager.js';
|
|
7
7
|
import { firstConfiguredOwner } from './owner-config.js';
|
|
8
|
-
import { loadSchema } from './schema-registry.js';
|
|
8
|
+
import { currentVersion, loadSchema } from './schema-registry.js';
|
|
9
9
|
import { planProviderIdentityMigration } from './provider-identity-migration.js';
|
|
10
10
|
import { providerIdentity } from './provider-identity.js';
|
|
11
11
|
import { snapshot } from './snapshot.js';
|
|
@@ -1615,6 +1615,11 @@ const PUBLISHED_SCHEMA_CONSOLIDATIONS = [
|
|
|
1615
1615
|
function restampPublishedSchemaConsolidation(value, file, consolidation) {
|
|
1616
1616
|
if (value.$schema_version !== consolidation.from)
|
|
1617
1617
|
return null;
|
|
1618
|
+
// A consolidation only applies while the source version is unpublished.
|
|
1619
|
+
// Once that version is current, its fields (for example agent-config.team)
|
|
1620
|
+
// must be retained instead of being validated against the older schema.
|
|
1621
|
+
if (currentVersion(consolidation.logicalName) >= consolidation.from)
|
|
1622
|
+
return null;
|
|
1618
1623
|
const next = { ...value, $schema_version: consolidation.to };
|
|
1619
1624
|
const schema = loadSchema(consolidation.logicalName, consolidation.to);
|
|
1620
1625
|
if (!schema.validate(next)) {
|
package/dist/config-store.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import fs from 'fs';
|
|
19
19
|
import path from 'path';
|
|
20
|
-
import { resolvePaths, agentDir, agentPersonalDir, kitsTemplatesDir, SOUL_PERSONA_FILE, } from './paths.js';
|
|
20
|
+
import { resolvePaths, agentDir, agentOutputDir, agentPersonalDir, kitsTemplatesDir, SOUL_PERSONA_FILE, } from './paths.js';
|
|
21
21
|
import { atomicReadJson, atomicWriteJson } from './utils/atomic-write.js';
|
|
22
22
|
import { registerFile as registerFileIntegrity } from './core/file-integrity/store.js';
|
|
23
23
|
import { checkAgentDir, isValidAid } from './aun/aid/validation.js';
|
|
@@ -675,6 +675,7 @@ export function ensureAgentDirSkeleton(aid) {
|
|
|
675
675
|
for (const sub of subs) {
|
|
676
676
|
fs.mkdirSync(path.join(root, sub), { recursive: true });
|
|
677
677
|
}
|
|
678
|
+
fs.mkdirSync(agentOutputDir(aid), { recursive: true });
|
|
678
679
|
ensureSoulDir(aid);
|
|
679
680
|
}
|
|
680
681
|
/** soul 目录骨架:模板位于 `kits/templates/soul/`,文件名与目标完全一致。 */
|
|
@@ -19,10 +19,7 @@ export class AgentReloadCoordinator {
|
|
|
19
19
|
return Math.max(0, this.deps.getBusyCount(aid));
|
|
20
20
|
}
|
|
21
21
|
runExclusive(aid, operation, options = {}) {
|
|
22
|
-
|
|
23
|
-
const pending = previous
|
|
24
|
-
.catch(() => undefined)
|
|
25
|
-
.then(async () => {
|
|
22
|
+
return this.runRunnerOperation(aid, async () => {
|
|
26
23
|
const releaseWorkGate = await this.deps.acquireWorkGate?.(aid);
|
|
27
24
|
try {
|
|
28
25
|
const busyCount = this.busyCount(aid);
|
|
@@ -36,6 +33,11 @@ export class AgentReloadCoordinator {
|
|
|
36
33
|
await releaseWorkGate?.();
|
|
37
34
|
}
|
|
38
35
|
});
|
|
36
|
+
}
|
|
37
|
+
/** Serialize runner creation with mutations, without rejecting the task that requested it as busy. */
|
|
38
|
+
runRunnerOperation(aid, operation) {
|
|
39
|
+
const previous = this.inFlight.get(aid) ?? Promise.resolve();
|
|
40
|
+
const pending = previous.catch(() => undefined).then(operation);
|
|
39
41
|
this.inFlight.set(aid, pending);
|
|
40
42
|
return pending.finally(() => {
|
|
41
43
|
if (this.inFlight.get(aid) === pending)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
2
|
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { BaseagentRunnerUnavailableError } from '../agents/runner-types.js';
|
|
3
4
|
import { buildReloadHooks } from './channel-loader.js';
|
|
4
5
|
import { AgentReloadBusyError, AgentReloadCoordinator } from './agent-reload-coordinator.js';
|
|
5
6
|
import { detectDuplicates } from './evolagent-registry.js';
|
|
@@ -50,13 +51,90 @@ export function loadStartupAgentRegistry(agentRegistry) {
|
|
|
50
51
|
}
|
|
51
52
|
return { primaryAgent, runtimeStatus };
|
|
52
53
|
}
|
|
53
|
-
|
|
54
|
+
/** The map is the cache; only simultaneous requests share an in-flight promise. */
|
|
55
|
+
export function createOnDemandAgentRunners(deps) {
|
|
56
|
+
const pending = new Map();
|
|
57
|
+
const assertRunning = () => {
|
|
58
|
+
if (deps.isCancelled())
|
|
59
|
+
throw new Error('Daemon is shutting down');
|
|
60
|
+
};
|
|
61
|
+
const ensure = (aid, baseagent) => {
|
|
62
|
+
const key = `${aid}::${baseagent}`;
|
|
63
|
+
if (deps.isCancelled())
|
|
64
|
+
return Promise.reject(new Error('Daemon is shutting down'));
|
|
65
|
+
if (pending.has(key))
|
|
66
|
+
return pending.get(key);
|
|
67
|
+
// Admission waits outside the mutation lock: startup never needs a lock
|
|
68
|
+
// held by a caller waiting for the same Agent's initial publication.
|
|
69
|
+
const operation = (async () => {
|
|
70
|
+
await deps.waitForStartup(aid);
|
|
71
|
+
assertRunning();
|
|
72
|
+
await deps.coordinator.runRunnerOperation(aid, async () => {
|
|
73
|
+
assertRunning();
|
|
74
|
+
const agent = deps.agentRegistry.get(aid);
|
|
75
|
+
const available = agent && agent.config.enabled !== false && agent.status !== 'disabled' && agent.status !== 'stopped'
|
|
76
|
+
? deps.agentLoader.enabledBaseagents(agent) : [];
|
|
77
|
+
if (!agent || !available.includes(baseagent)) {
|
|
78
|
+
throw new BaseagentRunnerUnavailableError(aid, baseagent, available);
|
|
79
|
+
}
|
|
80
|
+
if (deps.agentMap.has(key))
|
|
81
|
+
return;
|
|
82
|
+
const errors = [];
|
|
83
|
+
const startedAt = Date.now();
|
|
84
|
+
const instances = await deps.agentLoader.createForAgent(agent, deps.callbacks, errors, backend => backend === baseagent, assertRunning);
|
|
85
|
+
try {
|
|
86
|
+
assertRunning();
|
|
87
|
+
if (deps.agentRegistry.get(aid) !== agent)
|
|
88
|
+
throw new Error(`Agent changed while loading ${key}`);
|
|
89
|
+
const instance = instances.find(candidate => candidate.baseagent === baseagent);
|
|
90
|
+
if (!instance) {
|
|
91
|
+
const loaded = [...deps.agentMap.keys()].filter(key => key.startsWith(`${aid}::`))
|
|
92
|
+
.map(key => key.slice(aid.length + 2));
|
|
93
|
+
const error = new BaseagentRunnerUnavailableError(aid, baseagent, loaded);
|
|
94
|
+
if (errors.length)
|
|
95
|
+
error.cause = new Error(errors.map(item => item.message).join('; '));
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
deps.configure(instances);
|
|
99
|
+
deps.agentMap.set(key, instance.agent);
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
await disposeAgentInstances(instances);
|
|
103
|
+
throw error;
|
|
104
|
+
}
|
|
105
|
+
deps.onLoaded?.();
|
|
106
|
+
logger.info(`[Runner] Loaded on demand: ${key} duration=${Date.now() - startedAt}ms`);
|
|
107
|
+
});
|
|
108
|
+
})();
|
|
109
|
+
const result = operation.finally(() => { if (pending.get(key) === result)
|
|
110
|
+
pending.delete(key); });
|
|
111
|
+
pending.set(key, result);
|
|
112
|
+
return result;
|
|
113
|
+
};
|
|
114
|
+
return {
|
|
115
|
+
ensure,
|
|
116
|
+
isLoading: (aid, baseagent) => pending.has(`${aid}::${baseagent}`),
|
|
117
|
+
// Called after cancellation; late creations dispose themselves instead of
|
|
118
|
+
// publishing into the map after shutdown has taken its disposal snapshot.
|
|
119
|
+
waitForIdle: async () => { await Promise.allSettled([...pending.values()]); },
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
export async function createStartupAgentRunners({ agentRegistry, agentLoader, sessionManager, primaryAgent, agentInstances: publishedInstances, agentMap: publishedMap, configureInstances, isCancelled, onAgentCreated, onAgentReady, startupPriority, onAgentStarting, preloadAids, onAgentDeferred, waitForClassification, }) {
|
|
54
123
|
const creationErrors = [];
|
|
55
124
|
const agentInstances = publishedInstances ?? [];
|
|
56
125
|
const agentMap = publishedMap ?? new Map();
|
|
57
126
|
const primaryBaseagent = primaryAgent?.baseagent ?? 'claude';
|
|
58
127
|
const published = new Set();
|
|
59
128
|
const activeSettled = new Set();
|
|
129
|
+
const deferredAgents = new Set();
|
|
130
|
+
if (preloadAids) {
|
|
131
|
+
for (const agent of agentRegistry.runnableAgents()) {
|
|
132
|
+
if (preloadAids.has(agent.aid))
|
|
133
|
+
continue;
|
|
134
|
+
deferredAgents.add(agent.aid);
|
|
135
|
+
await onAgentDeferred?.(agent);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
60
138
|
const publish = (instances) => {
|
|
61
139
|
const fresh = instances.filter(instance => !published.has(instance));
|
|
62
140
|
if (!fresh.length)
|
|
@@ -119,14 +197,20 @@ export async function createStartupAgentRunners({ agentRegistry, agentLoader, se
|
|
|
119
197
|
: `No agent runner created for ${agent.aid}::${primaryAgent?.aid === agent.aid ? primaryBaseagent : agent.baseagent}`;
|
|
120
198
|
}
|
|
121
199
|
await onAgentCreated?.(agent, instances, timing);
|
|
122
|
-
}, () => !isCancelled?.(), activeReady, startupPriority)
|
|
200
|
+
}, () => !isCancelled?.(), activeReady, startupPriority, onAgentStarting, preloadAids, waitForClassification ? async (agent) => {
|
|
201
|
+
if (await waitForClassification(agent.aid))
|
|
202
|
+
return true;
|
|
203
|
+
deferredAgents.add(agent.aid);
|
|
204
|
+
await onAgentDeferred?.(agent);
|
|
205
|
+
return false;
|
|
206
|
+
} : undefined);
|
|
123
207
|
if (!isCancelled?.()) {
|
|
124
208
|
agentInstances.splice(0, agentInstances.length, ...createdInstances);
|
|
125
209
|
}
|
|
126
210
|
const primaryRunnerKey = primaryAgent ? `${primaryAgent.aid}::${primaryBaseagent}` : '<empty>::claude';
|
|
127
211
|
const agentRunner = primaryAgent ? agentMap.get(primaryRunnerKey) : agentInstances[0]?.agent;
|
|
128
212
|
let runtimeError;
|
|
129
|
-
if (primaryAgent && !agentRunner) {
|
|
213
|
+
if (primaryAgent && !agentRunner && !deferredAgents.has(primaryAgent.aid)) {
|
|
130
214
|
const primaryCreationErrors = creationErrors.filter(error => error.evolagentName === primaryAgent.name);
|
|
131
215
|
const creationDetail = primaryCreationErrors.length > 0
|
|
132
216
|
? primaryCreationErrors.map(({ baseagent, message }) => `${baseagent}: ${message}`).join('; ')
|
|
@@ -142,7 +226,7 @@ export async function createStartupAgentRunners({ agentRegistry, agentLoader, se
|
|
|
142
226
|
logger.info('✓ Agent Runtime empty; no runners created');
|
|
143
227
|
}
|
|
144
228
|
else {
|
|
145
|
-
logger.info(`✓
|
|
229
|
+
logger.info(`✓ Runner startup complete (loaded: ${agentMap.size}, on demand: ${deferredAgents.size}, primary key: ${primaryRunnerKey})`);
|
|
146
230
|
}
|
|
147
231
|
return { agentInstances, agentMap, primaryBaseagent, primaryRunnerKey, runtimeError };
|
|
148
232
|
}
|
|
@@ -202,11 +286,14 @@ export function createAgentReloadRuntime({ agentRegistry, agentLoader, sessionMa
|
|
|
202
286
|
handoffRuntime,
|
|
203
287
|
stageAgentRunners: async (candidate) => {
|
|
204
288
|
const creationErrors = [];
|
|
289
|
+
// Preserve backends already in use, without loading unused configuration.
|
|
290
|
+
const needed = new Set([...(candidate.config.enabled === false ? [] : [candidate.baseagent]), ...[...agentMap.keys()]
|
|
291
|
+
.filter(key => key.startsWith(`${candidate.aid}::`)).map(key => key.slice(candidate.aid.length + 2))]);
|
|
205
292
|
const staged = candidate.config.enabled === false
|
|
206
293
|
? []
|
|
207
294
|
: await agentLoader.createForAgent(candidate, {
|
|
208
295
|
onSessionIdUpdate: async (sessionId, agentSessionId, context) => (await sessionManager.updateAgentSessionIdBySessionId(sessionId, agentSessionId, context?.turn)),
|
|
209
|
-
}, creationErrors);
|
|
296
|
+
}, creationErrors, backend => needed.has(backend));
|
|
210
297
|
const onDisposeError = (instance, error) => {
|
|
211
298
|
logger.warn(`[Reload] Failed to dispose runner ${instance.evolagentName}::${instance.baseagent}: ${error instanceof Error ? error.message : String(error)}`);
|
|
212
299
|
};
|
|
@@ -214,12 +301,19 @@ export function createAgentReloadRuntime({ agentRegistry, agentLoader, sessionMa
|
|
|
214
301
|
await disposeAgentInstances(staged, onDisposeError);
|
|
215
302
|
throw new Error(creationErrors.map(error => `${error.baseagent}: ${error.message}`).join('; '));
|
|
216
303
|
}
|
|
217
|
-
if (candidate.config.enabled !== false && staged.
|
|
304
|
+
if (candidate.config.enabled !== false && !staged.some(instance => instance.baseagent === candidate.baseagent)) {
|
|
305
|
+
await disposeAgentInstances(staged, onDisposeError);
|
|
218
306
|
throw new Error(`No runner could be created for ${candidate.aid}::${candidate.config.active_baseagent}`);
|
|
219
307
|
}
|
|
220
|
-
|
|
221
|
-
instance
|
|
222
|
-
|
|
308
|
+
try {
|
|
309
|
+
for (const instance of staged) {
|
|
310
|
+
instance.agent.setPermissionGateway?.(permissionGateway);
|
|
311
|
+
instance.agent.setCompactStartCallback?.((sessionId) => processor.handleCompactStart(sessionId));
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
catch (error) {
|
|
315
|
+
await disposeAgentInstances(staged, onDisposeError);
|
|
316
|
+
throw error;
|
|
223
317
|
}
|
|
224
318
|
return createRunnerReloadTransaction({ aid: candidate.aid, agentMap, staged, onDisposeError });
|
|
225
319
|
},
|
|
@@ -423,7 +517,7 @@ export function createAgentRuntimeOperations({ agentRegistry, agentLoader, sessi
|
|
|
423
517
|
const creationErrors = [];
|
|
424
518
|
const newAgentInstances = await agentLoader.createForAgent(agent, {
|
|
425
519
|
onSessionIdUpdate: async (sessionId, agentSessionId, context) => (await sessionManager.updateAgentSessionIdBySessionId(sessionId, agentSessionId, context?.turn)),
|
|
426
|
-
}, creationErrors);
|
|
520
|
+
}, creationErrors, backend => backend === agent.baseagent);
|
|
427
521
|
for (const instance of newAgentInstances) {
|
|
428
522
|
agentMap.set(`${instance.evolagentName}::${instance.baseagent}`, instance.agent);
|
|
429
523
|
instance.agent.setPermissionGateway?.(permissionGateway);
|
|
@@ -5,6 +5,7 @@ import { hashDelegatedCommandArgv, hasTrustedFullAccessDelegation, trustedExecut
|
|
|
5
5
|
import { isManagementRole } from '../../config/builtin-roles.js';
|
|
6
6
|
import { parsePeerKey } from '../relation/peer-identity.js';
|
|
7
7
|
import { executeParsedProviderOperation, parseProviderCommand } from '../../config/provider-ipc-service.js';
|
|
8
|
+
import { executeInvokeOperation, parseInvokeArgv } from '../../config/invoke-ipc-service.js';
|
|
8
9
|
import { MAIN_CLI_BIN } from '../../product.js';
|
|
9
10
|
import { executeUpgradeOperation, parseUpgradeCommand } from '../../cli/upgrade-command.js';
|
|
10
11
|
export function createDelegatedUpgradeOperationExecutor({ agentDelegationRegistry, sessionManager, getProcessOwners, }) {
|
|
@@ -130,6 +131,71 @@ export function createDelegatedProviderOperationExecutor({ agentDelegationRegist
|
|
|
130
131
|
function hashProviderArgv(argv) {
|
|
131
132
|
return hashDelegatedCommandArgv([MAIN_CLI_BIN, ...argv]);
|
|
132
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* 托管会话内的 `ec invoke`。
|
|
136
|
+
*
|
|
137
|
+
* 调用一个已登记的端点不改变任何状态,所以不走 provider 那样的写操作审批;
|
|
138
|
+
* 但仍要求真实的委托令牌,且只允许当前 Agent 自己发起。
|
|
139
|
+
*/
|
|
140
|
+
export function createDelegatedInvokeOperationExecutor({ agentDelegationRegistry, sessionManager, getProcessOwners, }) {
|
|
141
|
+
return async function executeDelegatedInvokeOperation(params) {
|
|
142
|
+
const validation = agentDelegationRegistry.validate(params.delegationToken, params.sessionId, params.delegationCommandHash);
|
|
143
|
+
if (!validation.ok)
|
|
144
|
+
return { ok: false, code: validation.code, error: validation.reason };
|
|
145
|
+
const grant = validation.grant;
|
|
146
|
+
const session = await sessionManager.getSessionById(params.sessionId);
|
|
147
|
+
if (!session || session.selfAID !== grant.selfAid) {
|
|
148
|
+
return { ok: false, code: 'INVALID_DELEGATION', error: 'delegation does not match the current session' };
|
|
149
|
+
}
|
|
150
|
+
let parsed;
|
|
151
|
+
try {
|
|
152
|
+
parsed = parseInvokeArgv(params.argv);
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
return { ok: false, code: 'INVALID_ARGUMENT', error: error instanceof Error ? error.message : String(error) };
|
|
156
|
+
}
|
|
157
|
+
let conversationId;
|
|
158
|
+
try {
|
|
159
|
+
conversationId = parsePeerKey(grant.peerKey).channelId;
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
return { ok: false, code: 'INVALID_DELEGATION', error: 'delegation contains an invalid relation key' };
|
|
163
|
+
}
|
|
164
|
+
const subject = buildAuthSubject({
|
|
165
|
+
selfAid: grant.selfAid,
|
|
166
|
+
sessionId: params.sessionId,
|
|
167
|
+
requestId: params.requestId,
|
|
168
|
+
actorId: grant.actorId,
|
|
169
|
+
channel: grant.channel,
|
|
170
|
+
channelType: grant.channelType,
|
|
171
|
+
channelId: conversationId,
|
|
172
|
+
chatType: grant.chatType,
|
|
173
|
+
conversationId,
|
|
174
|
+
processOwners: getProcessOwners(),
|
|
175
|
+
...trustedExecutionIdentityInput(grant),
|
|
176
|
+
});
|
|
177
|
+
return executeAuditedOperation({
|
|
178
|
+
source: 'agent-tool',
|
|
179
|
+
subject,
|
|
180
|
+
intent: {
|
|
181
|
+
operation: 'invoke.execute',
|
|
182
|
+
scope: 'process',
|
|
183
|
+
source: 'agent-tool',
|
|
184
|
+
args: { providerId: parsed.providerId, service: parsed.serviceType },
|
|
185
|
+
},
|
|
186
|
+
auditMetadata: {
|
|
187
|
+
argvHash: hashDelegatedCommandArgv([MAIN_CLI_BIN, ...params.argv]),
|
|
188
|
+
taskId: grant.taskId,
|
|
189
|
+
messageId: grant.messageId,
|
|
190
|
+
sessionId: params.sessionId,
|
|
191
|
+
agentAid: grant.selfAid,
|
|
192
|
+
},
|
|
193
|
+
}, async (onExecutionStarted) => {
|
|
194
|
+
onExecutionStarted();
|
|
195
|
+
return executeInvokeOperation({ argv: params.argv, input: params.input });
|
|
196
|
+
});
|
|
197
|
+
};
|
|
198
|
+
}
|
|
133
199
|
export function createDelegationAuthorizer({ agentDelegationRegistry, sessionManager, getProcessOwners, }) {
|
|
134
200
|
return async function authorizeManagedAgentOperation(params, operation) {
|
|
135
201
|
const delegation = params.delegationGrant
|
|
@@ -156,6 +156,26 @@ const PROVIDER_OPERATIONS = ['list', 'show', 'create', 'import', 'update', 'dele
|
|
|
156
156
|
allowDelegatedRead: action === 'list' || action === 'show' },
|
|
157
157
|
}));
|
|
158
158
|
const OPERATIONS = [
|
|
159
|
+
...[
|
|
160
|
+
['event.center.current', 'Read event center status'],
|
|
161
|
+
['event.center.update', 'Update event center status'],
|
|
162
|
+
['event.allowlist.current', 'Read event allowlist'],
|
|
163
|
+
['event.allowlist.update', 'Update event allowlist'],
|
|
164
|
+
['event.packs.list', 'List event packs'],
|
|
165
|
+
['event.register.list', 'List registered events'],
|
|
166
|
+
['event.register.update', 'Update registered events'],
|
|
167
|
+
['event.subscribers.list', 'List event subscribers'],
|
|
168
|
+
['event.stats.current', 'Read event publication statistics'],
|
|
169
|
+
].map(([id, description]) => ({
|
|
170
|
+
id,
|
|
171
|
+
category: id.endsWith('.current') || id.endsWith('.list') ? 'read' : 'write-agent',
|
|
172
|
+
dangerous: !id.endsWith('.current') && !id.endsWith('.list'),
|
|
173
|
+
defaultScopes: ['agent'],
|
|
174
|
+
description,
|
|
175
|
+
sources: ['menu'],
|
|
176
|
+
authorizationTarget: 'current-agent',
|
|
177
|
+
minimumAgentRole: 'owner',
|
|
178
|
+
})),
|
|
159
179
|
...['read', 'result-read', 'install', 'configure', 'enable', 'disable', 'invoke', 'publish', 'upgrade', 'rollback', 'uninstall', 'grant', 'retire'].map(action => ({
|
|
160
180
|
id: 'ability.' + action, category: action === 'read' ? 'read' : 'write-agent',
|
|
161
181
|
dangerous: action !== 'read', defaultScopes: ['agent'], description: 'Manage AID ability plugins: ' + action,
|