evolcore 0.0.43-test.5 → 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 +95 -0
- package/bin/ecmsg.js +281 -81
- package/dist/agents/baseagent-availability.js +20 -5
- package/dist/agents/baseagent.js +2 -2
- package/dist/agents/claude-runner.js +19 -4
- package/dist/agents/codex/app-server-client.js +36 -3
- package/dist/agents/codex-runner.js +75 -8
- package/dist/aun/group/invite-service.js +3 -2
- package/dist/aun/msg/p2p.js +6 -1
- package/dist/aun/service-proxy.js +18 -6
- package/dist/channels/aun.js +306 -30
- package/dist/cli/agent-create.js +18 -8
- package/dist/cli/aun-commands.js +9 -1
- package/dist/cli/daemon-commands.js +34 -65
- package/dist/cli/daemon-lifecycle-client.js +61 -0
- package/dist/cli/ecmsg-gateway.js +38 -3
- package/dist/cli/events-command.js +73 -0
- package/dist/cli/index.js +31 -14
- package/dist/cli/init.js +75 -0
- package/dist/cli/invoke-command.js +182 -0
- package/dist/cli/managed-command-guard.js +6 -1
- package/dist/cli/provider-command.js +1 -1
- package/dist/cli/restart-monitor.js +67 -50
- package/dist/cli/services-command.js +111 -0
- package/dist/cli/task-context.js +38 -1
- package/dist/cli/team-workspace-command.js +134 -0
- package/dist/cli/thread-command.js +6 -2
- package/dist/cli/watch-logs.js +6 -4
- package/dist/cli/watch-msg.js +1 -1
- package/dist/config/boot-log.js +6 -4
- package/dist/config/builtin-roles.js +2 -2
- package/dist/config/config-field-policy.js +2 -2
- package/dist/config/config-manager.js +1 -8
- package/dist/config/invoke-ipc-service.js +118 -0
- package/dist/config/peer-role-resolver.js +1 -1
- package/dist/config/provider-identity-migration.js +92 -17
- package/dist/config/provider-local-sync.js +2 -0
- package/dist/config/providers-config.js +13 -0
- package/dist/config/providers-management.js +100 -10
- package/dist/config/role-service.js +8 -8
- package/dist/config/role-store.js +22 -22
- package/dist/config/schema-migration.js +86 -88
- package/dist/config/snapshot.js +70 -41
- package/dist/config-store.js +2 -1
- package/dist/core/agent-reload-coordinator.js +6 -4
- package/dist/core/agent-runtime.js +146 -15
- package/dist/core/auth/delegation-authorization.js +66 -0
- package/dist/core/auth/operation-catalog.js +20 -0
- package/dist/core/baseagent-loader.js +75 -42
- package/dist/core/channel-loader.js +45 -13
- package/dist/core/channel-runtime.js +116 -45
- 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 +58 -16
- 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 +206 -87
- package/dist/core/command/menu-protocol.js +142 -22
- package/dist/core/command/menu-query-batch.js +194 -0
- package/dist/core/command/role-menu.js +27 -15
- 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 +45 -15
- package/dist/core/daemon-lifecycle.js +478 -75
- package/dist/core/handoff/dispatcher.js +9 -3
- package/dist/core/handoff/runtime.js +130 -42
- package/dist/core/handoff/store.js +190 -2
- package/dist/core/handoff/types.js +5 -0
- package/dist/core/initialization/service.js +4 -4
- 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 +51 -11
- package/dist/core/lifecycle-notice.js +10 -4
- package/dist/core/memory/consolidation.js +7 -5
- package/dist/core/message/aun-ipc-sender.js +149 -19
- package/dist/core/message/im-renderer.js +28 -84
- package/dist/core/message/message-bridge.js +57 -4
- package/dist/core/message/message-queue.js +46 -4
- package/dist/core/message/message-utils.js +10 -2
- package/dist/core/message/peer-mode.js +7 -34
- package/dist/core/message/pending-hints.js +4 -10
- package/dist/core/message/response-engine.js +163 -52
- package/dist/core/message/send-options.js +7 -4
- package/dist/core/message/send-routing.js +55 -7
- package/dist/core/ownership/owner-resolver.js +8 -0
- package/dist/core/permission/ec-command-parser.js +14 -3
- package/dist/core/permission/protected-paths.js +12 -2
- package/dist/core/permission/shell-environment.js +9 -0
- package/dist/core/session/adapters/claude-session-file-adapter.js +24 -0
- package/dist/core/session/adapters/codex-session-file-adapter.js +80 -0
- package/dist/core/session/adapters/ecagent-session-file-adapter.js +22 -0
- package/dist/core/session/adapters/gemini-session-file-adapter.js +39 -0
- package/dist/core/session/session-file-health.js +243 -0
- package/dist/core/session/session-fs-store.js +163 -3
- package/dist/core/session/session-idle-monitor.js +9 -1
- package/dist/core/session/session-manager.js +36 -2
- 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 +42 -30
- package/dist/directory/owner-directory-cache.js +143 -126
- package/dist/directory/owner-directory-query-operation.js +9 -8
- 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 +14 -8
- package/dist/ecweb/runtime/supervisor.js +62 -30
- 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 +751 -268
- package/dist/ipc.js +66 -12
- package/dist/paths.js +20 -0
- package/dist/product.js +14 -0
- package/dist/proxy/manager.js +43 -18
- package/dist/proxy/service-supervisor.js +78 -35
- 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 +21 -1
- package/dist/trigger/audit.js +19 -4
- package/dist/trigger/authorization.js +14 -5
- package/dist/trigger/event-source.js +1 -1
- package/dist/trigger/history.js +176 -7
- package/dist/trigger/ipc-service.js +3 -1
- package/dist/trigger/manager.js +1 -3
- package/dist/trigger/scheduler.js +78 -5
- package/dist/trigger/script-sandbox.js +118 -22
- package/dist/utils/cross-platform.js +175 -13
- package/dist/utils/evolcore-version.js +69 -27
- package/dist/utils/host-info.js +11 -8
- package/dist/utils/instance-registry.js +19 -13
- package/dist/utils/npm-ops.js +48 -0
- package/dist/utils/process-introspect.js +109 -10
- package/dist/utils/startup-trace.js +222 -44
- package/dist/utils/windows-shell-trust.js +80 -6
- package/kits/docs/INDEX.md +2 -2
- package/kits/docs/aun/ABILITY_CALLING.md +10 -17
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +5 -2
- package/kits/docs/evolcore/ability.md +4 -0
- package/kits/docs/evolcore/aid.md +1 -1
- package/kits/docs/evolcore/ctl.md +2 -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 +2 -2
- package/kits/docs/evolcore/memory-architecture.md +2 -0
- package/kits/docs/evolcore/menu-exec-schema-commands.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +21 -0
- package/kits/docs/evolcore/msg.md +27 -8
- package/kits/docs/evolcore/provider.md +23 -3
- 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 +45 -7
- package/kits/eck_message_manifest.json +3 -3
- package/kits/rules/02-navigation.md +10 -1
- package/kits/rules/06-channel.md +5 -6
- 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/daemon.schema.1.json +5 -0
- package/kits/schemas/daemon.schema.2.json +5 -0
- package/kits/schemas/daemon.schema.3.json +2 -1
- package/kits/schemas/daemon.schema.4.json +2 -1
- package/kits/schemas/daemon.schema.5.json +2 -1
- package/kits/schemas/daemon.schema.6.json +1 -1
- package/kits/schemas/daemon.schema.7.json +1 -1
- package/kits/schemas/daemon.schema.8.json +2 -1
- package/kits/schemas/daemon.schema.9.json +2 -1
- package/kits/schemas/relation-config.schema.12.json +2 -3
- package/kits/schemas/role-config.schema.2.json +4 -4
- package/kits/schemas/role-registry.schema.1.json +2 -2
- package/kits/schemas/single-session.schema.1.json +1 -1
- package/kits/schemas/single-session.schema.2.json +1 -1
- package/kits/schemas/single-session.schema.3.json +1 -1
- 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-group/SKILL.md +8 -5
- package/kits/skills/ec-group-collaboration/SKILL.md +7 -7
- package/kits/skills/ec-service-proxy/SKILL.md +34 -5
- package/kits/skills/ec-trigger/SKILL.md +4 -4
- 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/skills/thread-ops/SKILL.md +10 -10
- package/kits/templates/system-fragments/channel.md +3 -3
- package/kits/templates/system-fragments/commands.md +9 -7
- package/kits/templates/system-fragments/reply.md +2 -6
- package/kits/templates/system-fragments/session.md +1 -1
- package/kits/templates/system-fragments/thread.md +11 -9
- package/package.json +5 -6
- 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
package/dist/config/snapshot.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* snapshot —— 配置快照与回滚。
|
|
3
3
|
*
|
|
4
4
|
* v3 设计快照范围:daemon.json + providers.json + agents/defaults.json + 每 agent 的 config.json
|
|
5
|
-
* + 每关系的 config.json + extra_backup 声明文件。**不含 .env**。
|
|
5
|
+
* + 每关系的 config.json + 初始化/ECWeb 创建状态 + extra_backup 声明文件。**不含 .env**。
|
|
6
6
|
*
|
|
7
7
|
* 版本号:全量百位递增(v100/v200…),增量嵌套其下(v101…v199,每全量 ≤99 个增量)。
|
|
8
8
|
* 目录:{root}/backups/config/v100/{meta.json, snapshot/...} + v101/{meta.json, delta/...}
|
|
@@ -20,7 +20,11 @@ import { ConfigTarget, notifyConfigWrite, read } from './config-manager.js';
|
|
|
20
20
|
const RETAIN_FULL = 10;
|
|
21
21
|
const RETAIN_DELTA = 20;
|
|
22
22
|
/** Process-level master switch. Missing config remains enabled for compatibility. */
|
|
23
|
-
export function isConfigSnapshotsEnabled() {
|
|
23
|
+
export function isConfigSnapshotsEnabled(root = resolvePaths().root) {
|
|
24
|
+
if (path.resolve(root) !== path.resolve(resolvePaths().root)) {
|
|
25
|
+
const file = path.join(root, 'daemon.json');
|
|
26
|
+
return !fs.existsSync(file) || JSON.parse(fs.readFileSync(file, 'utf8').replace(/^\uFEFF/u, '')).configSnapshots !== false;
|
|
27
|
+
}
|
|
24
28
|
const config = read(ConfigTarget.Process, {}, { cache: true });
|
|
25
29
|
return config?.configSnapshots !== false;
|
|
26
30
|
}
|
|
@@ -57,6 +61,15 @@ export function collectConfigFiles(root) {
|
|
|
57
61
|
out.push(rel(abs)); };
|
|
58
62
|
pushIf(path.join(root, 'daemon.json'));
|
|
59
63
|
pushIf(path.join(root, 'providers.json'));
|
|
64
|
+
const ecweb = path.join(root, 'data', 'ecweb');
|
|
65
|
+
pushIf(path.join(ecweb, 'init-state.json'));
|
|
66
|
+
const creations = path.join(ecweb, 'agent-creations');
|
|
67
|
+
if (fs.existsSync(creations)) {
|
|
68
|
+
for (const entry of fs.readdirSync(creations, { withFileTypes: true })) {
|
|
69
|
+
if (entry.isFile() && entry.name.endsWith('.json'))
|
|
70
|
+
pushIf(path.join(creations, entry.name));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
60
73
|
const agentsRoot = path.join(root, 'agents');
|
|
61
74
|
pushIf(path.join(agentsRoot, 'defaults.json'));
|
|
62
75
|
if (fs.existsSync(agentsRoot)) {
|
|
@@ -65,6 +78,7 @@ export function collectConfigFiles(root) {
|
|
|
65
78
|
continue;
|
|
66
79
|
const adir = path.join(agentsRoot, entry.name);
|
|
67
80
|
pushIf(path.join(adir, 'config.json'));
|
|
81
|
+
pushIf(path.join(adir, 'data', 'initialization.json'));
|
|
68
82
|
const rolesDir = path.join(adir, 'roles');
|
|
69
83
|
if (fs.existsSync(rolesDir)) {
|
|
70
84
|
for (const roleEntry of fs.readdirSync(rolesDir, { withFileTypes: true })) {
|
|
@@ -127,8 +141,8 @@ function matchGlob(name, pattern) {
|
|
|
127
141
|
return re.test(name);
|
|
128
142
|
}
|
|
129
143
|
// ── current.json 指针 ────────────────────────────────────────────────────────
|
|
130
|
-
export function readCurrent() {
|
|
131
|
-
const p =
|
|
144
|
+
export function readCurrent(root = resolvePaths().root) {
|
|
145
|
+
const p = path.join(backupsDir(root), 'current.json');
|
|
132
146
|
try {
|
|
133
147
|
return JSON.parse(fs.readFileSync(p, 'utf-8'));
|
|
134
148
|
}
|
|
@@ -136,14 +150,14 @@ export function readCurrent() {
|
|
|
136
150
|
return null;
|
|
137
151
|
}
|
|
138
152
|
}
|
|
139
|
-
export function writeCurrent(ptr) {
|
|
140
|
-
const p =
|
|
153
|
+
export function writeCurrent(ptr, root = resolvePaths().root) {
|
|
154
|
+
const p = path.join(backupsDir(root), 'current.json');
|
|
141
155
|
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
142
156
|
fs.writeFileSync(p, JSON.stringify(ptr, null, 2) + '\n', 'utf-8');
|
|
143
157
|
}
|
|
144
158
|
// ── w-version.json(W 的版本标记)─────────────────────────────────────────────
|
|
145
|
-
export function readWVersion() {
|
|
146
|
-
const p =
|
|
159
|
+
export function readWVersion(root = resolvePaths().root) {
|
|
160
|
+
const p = path.join(backupsDir(root), 'w-version.json');
|
|
147
161
|
try {
|
|
148
162
|
return JSON.parse(fs.readFileSync(p, 'utf-8'));
|
|
149
163
|
}
|
|
@@ -151,16 +165,16 @@ export function readWVersion() {
|
|
|
151
165
|
return null;
|
|
152
166
|
}
|
|
153
167
|
}
|
|
154
|
-
export function writeWVersion(ptr) {
|
|
155
|
-
const p =
|
|
168
|
+
export function writeWVersion(ptr, root = resolvePaths().root) {
|
|
169
|
+
const p = path.join(backupsDir(root), 'w-version.json');
|
|
156
170
|
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
157
171
|
fs.writeFileSync(p, JSON.stringify(ptr, null, 2) + '\n', 'utf-8');
|
|
158
172
|
}
|
|
159
173
|
// ── 版本目录 ──────────────────────────────────────────────────────────────────
|
|
160
|
-
function backupsDir() { return
|
|
174
|
+
function backupsDir(root = resolvePaths().root) { return path.join(root, 'backups', 'config'); }
|
|
161
175
|
/** 列出所有全量版本号(v100/v200…),升序。 */
|
|
162
|
-
function listFulls() {
|
|
163
|
-
const dir = backupsDir();
|
|
176
|
+
function listFulls(root = resolvePaths().root) {
|
|
177
|
+
const dir = backupsDir(root);
|
|
164
178
|
if (!fs.existsSync(dir))
|
|
165
179
|
return [];
|
|
166
180
|
return fs.readdirSync(dir, { withFileTypes: true })
|
|
@@ -169,8 +183,8 @@ function listFulls() {
|
|
|
169
183
|
.sort(cmpVersion);
|
|
170
184
|
}
|
|
171
185
|
/** 列出某全量目录下的增量版本号(v101…),升序。 */
|
|
172
|
-
function listDeltas(full) {
|
|
173
|
-
const dir = path.join(backupsDir(), full);
|
|
186
|
+
function listDeltas(full, root = resolvePaths().root) {
|
|
187
|
+
const dir = path.join(backupsDir(root), full);
|
|
174
188
|
if (!fs.existsSync(dir))
|
|
175
189
|
return [];
|
|
176
190
|
return fs.readdirSync(dir, { withFileTypes: true })
|
|
@@ -218,15 +232,15 @@ export function incrementSuccessCount(version) {
|
|
|
218
232
|
meta.successCount = (meta.successCount || 0) + 1;
|
|
219
233
|
writeMeta(loc.full, loc.delta, meta);
|
|
220
234
|
}
|
|
221
|
-
function nextFullVersion() {
|
|
222
|
-
const fulls = listFulls();
|
|
235
|
+
function nextFullVersion(root) {
|
|
236
|
+
const fulls = listFulls(root);
|
|
223
237
|
if (fulls.length === 0)
|
|
224
238
|
return 'v100';
|
|
225
239
|
const last = parseInt(fulls[fulls.length - 1].slice(1));
|
|
226
240
|
return 'v' + (Math.floor(last / 100) * 100 + 100);
|
|
227
241
|
}
|
|
228
|
-
function nextDeltaVersion(full) {
|
|
229
|
-
const deltas = listDeltas(full);
|
|
242
|
+
function nextDeltaVersion(full, root) {
|
|
243
|
+
const deltas = listDeltas(full, root);
|
|
230
244
|
const base = parseInt(full.slice(1));
|
|
231
245
|
if (deltas.length === 0)
|
|
232
246
|
return 'v' + (base + 1);
|
|
@@ -243,14 +257,14 @@ function readWorkFile(root, relPath) {
|
|
|
243
257
|
}
|
|
244
258
|
}
|
|
245
259
|
/** 展开某版本到一份内容 map(相对路径 → 内容)。增量基于父全量叠加。 */
|
|
246
|
-
export function materializeVersion(full, delta) {
|
|
260
|
+
export function materializeVersion(full, delta, root = resolvePaths().root) {
|
|
247
261
|
const map = new Map();
|
|
248
|
-
const snapDir = path.join(backupsDir(), full, 'snapshot');
|
|
262
|
+
const snapDir = path.join(backupsDir(root), full, 'snapshot');
|
|
249
263
|
if (fs.existsSync(snapDir))
|
|
250
264
|
walkInto(snapDir, snapDir, map);
|
|
251
265
|
if (delta !== full) {
|
|
252
|
-
const changesPath = path.join(backupsDir(), full, delta, 'delta', 'changes.jsonl');
|
|
253
|
-
const filesDir = path.join(backupsDir(), full, delta, 'delta', 'files');
|
|
266
|
+
const changesPath = path.join(backupsDir(root), full, delta, 'delta', 'changes.jsonl');
|
|
267
|
+
const filesDir = path.join(backupsDir(root), full, delta, 'delta', 'files');
|
|
254
268
|
if (fs.existsSync(changesPath)) {
|
|
255
269
|
for (const line of fs.readFileSync(changesPath, 'utf-8').split('\n')) {
|
|
256
270
|
if (!line.trim())
|
|
@@ -306,32 +320,36 @@ function diffMaps(oldM, newM) {
|
|
|
306
320
|
}
|
|
307
321
|
// ── snapshot:建版本 ──────────────────────────────────────────────────────────
|
|
308
322
|
export function snapshot(trigger, opts = {}) {
|
|
309
|
-
|
|
323
|
+
const root = path.resolve(opts.root ?? resolvePaths().root);
|
|
324
|
+
if (!isConfigSnapshotsEnabled(root))
|
|
310
325
|
return { created: false, reason: 'disabled' };
|
|
311
|
-
const root = resolvePaths().root;
|
|
312
326
|
const work = materializeWorkdir(root);
|
|
313
|
-
const
|
|
327
|
+
for (const [file, before] of opts.expectedFiles ?? []) {
|
|
328
|
+
if ((work.get(file) ?? null) !== before)
|
|
329
|
+
throw new Error(`Configuration snapshot does not match migration input: ${file}`);
|
|
330
|
+
}
|
|
331
|
+
const cur = readCurrent(root);
|
|
314
332
|
// 决策一:要不要建版本(与 current 版本比;schema-migration 无条件)
|
|
315
333
|
if (trigger !== 'schema-migration' && cur) {
|
|
316
|
-
const curMap = materializeVersion(cur.full, cur.delta);
|
|
334
|
+
const curMap = materializeVersion(cur.full, cur.delta, root);
|
|
317
335
|
const d = diffMaps(curMap, work);
|
|
318
336
|
if (d.add.length === 0 && d.modify.length === 0 && d.del.length === 0) {
|
|
319
337
|
return { created: false, reason: 'no-change' };
|
|
320
338
|
}
|
|
321
339
|
}
|
|
322
340
|
// 决策二:增量 vs 全量(与所属全量比)
|
|
323
|
-
const fulls = listFulls();
|
|
341
|
+
const fulls = listFulls(root);
|
|
324
342
|
const baseFull = cur?.full && fulls.includes(cur.full) ? cur.full : (fulls[fulls.length - 1] || null);
|
|
325
343
|
let makeFull = opts.full || !baseFull;
|
|
326
344
|
let baseMap = null;
|
|
327
345
|
if (!makeFull && baseFull) {
|
|
328
|
-
baseMap = materializeVersion(baseFull, baseFull);
|
|
346
|
+
baseMap = materializeVersion(baseFull, baseFull, root);
|
|
329
347
|
const d = diffMaps(baseMap, work);
|
|
330
348
|
const fullFileCount = Math.max(baseMap.size, 1);
|
|
331
349
|
const changeCount = d.add.length + d.modify.length + d.del.length;
|
|
332
350
|
if (changeCount * 2 > fullFileCount)
|
|
333
351
|
makeFull = true; // 差异 > 半数
|
|
334
|
-
if (listDeltas(baseFull).length >= 99)
|
|
352
|
+
if (listDeltas(baseFull, root).length >= 99)
|
|
335
353
|
makeFull = true; // 增量达 99
|
|
336
354
|
}
|
|
337
355
|
if (makeFull)
|
|
@@ -339,26 +357,28 @@ export function snapshot(trigger, opts = {}) {
|
|
|
339
357
|
return createDelta(root, work, baseFull, baseMap, trigger, opts.description);
|
|
340
358
|
}
|
|
341
359
|
function createFull(root, work, trigger, description) {
|
|
342
|
-
const version = nextFullVersion();
|
|
343
|
-
const verDir = path.join(backupsDir(), version);
|
|
360
|
+
const version = nextFullVersion(root);
|
|
361
|
+
const verDir = path.join(backupsDir(root), version);
|
|
362
|
+
fs.mkdirSync(verDir, { recursive: true });
|
|
344
363
|
const snapDir = path.join(verDir, 'snapshot');
|
|
345
364
|
for (const [rel, content] of work) {
|
|
346
365
|
writeSnapshotConfigFile(snapDir, rel, content);
|
|
347
366
|
}
|
|
348
367
|
const meta = {
|
|
368
|
+
scopeVersion: 2,
|
|
349
369
|
version, type: 'full', createdAt: nowIso(), trigger, description,
|
|
350
370
|
changedFiles: [...work.keys()], deletedFiles: [],
|
|
351
371
|
successCount: 0,
|
|
352
372
|
};
|
|
353
373
|
fs.writeFileSync(path.join(verDir, 'meta.json'), JSON.stringify(meta, null, 2) + '\n', 'utf-8');
|
|
354
|
-
writeCurrent({ full: version, delta: version });
|
|
355
|
-
writeWVersion({ full: version, delta: version });
|
|
374
|
+
writeCurrent({ full: version, delta: version }, root);
|
|
375
|
+
writeWVersion({ full: version, delta: version }, root);
|
|
356
376
|
logger.info(`[snapshot] created full ${version} (trigger=${trigger}, ${work.size} files)`);
|
|
357
377
|
return { created: true, version, type: 'full' };
|
|
358
378
|
}
|
|
359
379
|
function createDelta(root, work, baseFull, baseMap, trigger, description) {
|
|
360
|
-
const version = nextDeltaVersion(baseFull);
|
|
361
|
-
const verDir = path.join(backupsDir(), baseFull, version);
|
|
380
|
+
const version = nextDeltaVersion(baseFull, root);
|
|
381
|
+
const verDir = path.join(backupsDir(root), baseFull, version);
|
|
362
382
|
const deltaDir = path.join(verDir, 'delta');
|
|
363
383
|
const filesDir = path.join(deltaDir, 'files');
|
|
364
384
|
const d = diffMaps(baseMap, work);
|
|
@@ -376,22 +396,30 @@ function createDelta(root, work, baseFull, baseMap, trigger, description) {
|
|
|
376
396
|
fs.mkdirSync(deltaDir, { recursive: true });
|
|
377
397
|
fs.writeFileSync(path.join(deltaDir, 'changes.jsonl'), lines.join('\n') + (lines.length ? '\n' : ''), 'utf-8');
|
|
378
398
|
const meta = {
|
|
399
|
+
scopeVersion: 2,
|
|
379
400
|
version, type: 'delta', baseVersion: baseFull, createdAt: nowIso(), trigger, description,
|
|
380
401
|
changedFiles: [...d.add, ...d.modify], deletedFiles: d.del,
|
|
381
402
|
successCount: 0,
|
|
382
403
|
};
|
|
383
404
|
fs.writeFileSync(path.join(verDir, 'meta.json'), JSON.stringify(meta, null, 2) + '\n', 'utf-8');
|
|
384
|
-
writeCurrent({ full: baseFull, delta: version });
|
|
385
|
-
writeWVersion({ full: baseFull, delta: version });
|
|
405
|
+
writeCurrent({ full: baseFull, delta: version }, root);
|
|
406
|
+
writeWVersion({ full: baseFull, delta: version }, root);
|
|
386
407
|
logger.info(`[snapshot] created delta ${version} on ${baseFull} (trigger=${trigger}, +${d.add.length} ~${d.modify.length} -${d.del.length})`);
|
|
387
408
|
return { created: true, version, type: 'delta' };
|
|
388
409
|
}
|
|
389
410
|
function writeDeltaFile(filesDir, rel, content) {
|
|
390
411
|
writeSnapshotConfigFile(filesDir, rel, content);
|
|
391
412
|
}
|
|
413
|
+
function isInitializationState(rel) {
|
|
414
|
+
return rel.endsWith('/data/initialization.json') || rel === 'data/ecweb/init-state.json'
|
|
415
|
+
|| rel.startsWith('data/ecweb/agent-creations/');
|
|
416
|
+
}
|
|
417
|
+
export function snapshotManagesFile(meta, rel) {
|
|
418
|
+
return meta.scopeVersion === 2 || !isInitializationState(rel) || meta.deletedFiles.includes(rel);
|
|
419
|
+
}
|
|
392
420
|
export function writeSnapshotConfigFile(root, rel, content) {
|
|
393
421
|
const dest = path.join(root, rel);
|
|
394
|
-
const protectedProvider = rel === 'providers.json';
|
|
422
|
+
const protectedProvider = rel === 'providers.json' || isInitializationState(rel);
|
|
395
423
|
fs.mkdirSync(path.dirname(dest), { recursive: true, ...(protectedProvider ? { mode: 0o700 } : {}) });
|
|
396
424
|
fs.writeFileSync(dest, content, { encoding: 'utf8', ...(protectedProvider ? { mode: 0o600 } : {}) });
|
|
397
425
|
if (protectedProvider && process.platform !== 'win32')
|
|
@@ -399,7 +427,7 @@ export function writeSnapshotConfigFile(root, rel, content) {
|
|
|
399
427
|
}
|
|
400
428
|
export function removeSnapshotConfigFile(root, rel) {
|
|
401
429
|
const dest = path.join(root, rel);
|
|
402
|
-
const files = rel === 'providers.json' ? [dest, `${dest}_`, `${dest}__`] : [dest];
|
|
430
|
+
const files = rel === 'providers.json' || isInitializationState(rel) ? [dest, `${dest}_`, `${dest}__`] : [dest];
|
|
403
431
|
for (const file of files) {
|
|
404
432
|
try {
|
|
405
433
|
fs.unlinkSync(file);
|
|
@@ -434,9 +462,10 @@ export function restore(version) {
|
|
|
434
462
|
const root = resolvePaths().root;
|
|
435
463
|
const target = materializeVersion(loc.full, loc.delta);
|
|
436
464
|
const current = materializeWorkdir(root);
|
|
465
|
+
const metadata = readMeta(loc.full, loc.delta);
|
|
437
466
|
// 删除工作目录中目标版本没有的配置文件
|
|
438
467
|
for (const rel of current.keys()) {
|
|
439
|
-
if (!target.has(rel)) {
|
|
468
|
+
if (!target.has(rel) && snapshotManagesFile(metadata, rel)) {
|
|
440
469
|
removeSnapshotConfigFile(root, rel);
|
|
441
470
|
}
|
|
442
471
|
}
|
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,11 +51,126 @@ 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';
|
|
127
|
+
const published = new Set();
|
|
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
|
+
}
|
|
138
|
+
const publish = (instances) => {
|
|
139
|
+
const fresh = instances.filter(instance => !published.has(instance));
|
|
140
|
+
if (!fresh.length)
|
|
141
|
+
return;
|
|
142
|
+
configureInstances?.(fresh);
|
|
143
|
+
for (const instance of fresh) {
|
|
144
|
+
published.add(instance);
|
|
145
|
+
agentInstances.push(instance);
|
|
146
|
+
agentMap.set(`${instance.evolagentName}::${instance.baseagent}`, instance.agent);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
const activeReady = async (agent, instances, timing) => {
|
|
150
|
+
if (activeSettled.has(agent.aid))
|
|
151
|
+
return;
|
|
152
|
+
if (isCancelled?.()) {
|
|
153
|
+
await disposeAgentInstances(instances);
|
|
154
|
+
activeSettled.add(agent.aid);
|
|
155
|
+
await onAgentReady?.(agent, [], timing);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
try {
|
|
159
|
+
publish(instances);
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
await disposeAgentInstances(instances);
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
activeSettled.add(agent.aid);
|
|
166
|
+
if (!instances.some(instance => instance.baseagent === agent.baseagent)) {
|
|
167
|
+
agent.status = 'error';
|
|
168
|
+
agent.error = creationErrors.filter(error => error.evolagentName === agent.name)
|
|
169
|
+
.map(({ baseagent, message }) => `${baseagent}: ${message}`).join('; ')
|
|
170
|
+
|| `No agent runner created for ${agent.aid}::${agent.baseagent}`;
|
|
171
|
+
}
|
|
172
|
+
await onAgentReady?.(agent, instances, timing);
|
|
173
|
+
};
|
|
58
174
|
const createdInstances = await agentLoader.createAll(agentRegistry, {
|
|
59
175
|
onSessionIdUpdate: async (sessionId, agentSessionId, context) => (await sessionManager.updateAgentSessionIdBySessionId(sessionId, agentSessionId, context?.turn)),
|
|
60
176
|
}, creationErrors, async (agent, instances, timing) => {
|
|
@@ -64,16 +180,13 @@ export async function createStartupAgentRunners({ agentRegistry, agentLoader, se
|
|
|
64
180
|
return;
|
|
65
181
|
}
|
|
66
182
|
try {
|
|
67
|
-
|
|
183
|
+
publish(instances);
|
|
68
184
|
}
|
|
69
185
|
catch (error) {
|
|
70
186
|
await disposeAgentInstances(instances);
|
|
71
187
|
throw error;
|
|
72
188
|
}
|
|
73
|
-
|
|
74
|
-
for (const instance of instances) {
|
|
75
|
-
agentMap.set(`${instance.evolagentName}::${instance.baseagent}`, instance.agent);
|
|
76
|
-
}
|
|
189
|
+
await activeReady(agent, instances, timing);
|
|
77
190
|
if (primaryAgent?.aid === agent.aid
|
|
78
191
|
? !instances.some(instance => instance.baseagent === primaryBaseagent)
|
|
79
192
|
: !instances.some(instance => instance.baseagent === agent.baseagent)) {
|
|
@@ -84,14 +197,20 @@ export async function createStartupAgentRunners({ agentRegistry, agentLoader, se
|
|
|
84
197
|
: `No agent runner created for ${agent.aid}::${primaryAgent?.aid === agent.aid ? primaryBaseagent : agent.baseagent}`;
|
|
85
198
|
}
|
|
86
199
|
await onAgentCreated?.(agent, instances, timing);
|
|
87
|
-
}, () => !isCancelled?.())
|
|
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);
|
|
88
207
|
if (!isCancelled?.()) {
|
|
89
208
|
agentInstances.splice(0, agentInstances.length, ...createdInstances);
|
|
90
209
|
}
|
|
91
210
|
const primaryRunnerKey = primaryAgent ? `${primaryAgent.aid}::${primaryBaseagent}` : '<empty>::claude';
|
|
92
211
|
const agentRunner = primaryAgent ? agentMap.get(primaryRunnerKey) : agentInstances[0]?.agent;
|
|
93
212
|
let runtimeError;
|
|
94
|
-
if (primaryAgent && !agentRunner) {
|
|
213
|
+
if (primaryAgent && !agentRunner && !deferredAgents.has(primaryAgent.aid)) {
|
|
95
214
|
const primaryCreationErrors = creationErrors.filter(error => error.evolagentName === primaryAgent.name);
|
|
96
215
|
const creationDetail = primaryCreationErrors.length > 0
|
|
97
216
|
? primaryCreationErrors.map(({ baseagent, message }) => `${baseagent}: ${message}`).join('; ')
|
|
@@ -107,7 +226,7 @@ export async function createStartupAgentRunners({ agentRegistry, agentLoader, se
|
|
|
107
226
|
logger.info('✓ Agent Runtime empty; no runners created');
|
|
108
227
|
}
|
|
109
228
|
else {
|
|
110
|
-
logger.info(`✓
|
|
229
|
+
logger.info(`✓ Runner startup complete (loaded: ${agentMap.size}, on demand: ${deferredAgents.size}, primary key: ${primaryRunnerKey})`);
|
|
111
230
|
}
|
|
112
231
|
return { agentInstances, agentMap, primaryBaseagent, primaryRunnerKey, runtimeError };
|
|
113
232
|
}
|
|
@@ -167,11 +286,14 @@ export function createAgentReloadRuntime({ agentRegistry, agentLoader, sessionMa
|
|
|
167
286
|
handoffRuntime,
|
|
168
287
|
stageAgentRunners: async (candidate) => {
|
|
169
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))]);
|
|
170
292
|
const staged = candidate.config.enabled === false
|
|
171
293
|
? []
|
|
172
294
|
: await agentLoader.createForAgent(candidate, {
|
|
173
295
|
onSessionIdUpdate: async (sessionId, agentSessionId, context) => (await sessionManager.updateAgentSessionIdBySessionId(sessionId, agentSessionId, context?.turn)),
|
|
174
|
-
}, creationErrors);
|
|
296
|
+
}, creationErrors, backend => needed.has(backend));
|
|
175
297
|
const onDisposeError = (instance, error) => {
|
|
176
298
|
logger.warn(`[Reload] Failed to dispose runner ${instance.evolagentName}::${instance.baseagent}: ${error instanceof Error ? error.message : String(error)}`);
|
|
177
299
|
};
|
|
@@ -179,12 +301,19 @@ export function createAgentReloadRuntime({ agentRegistry, agentLoader, sessionMa
|
|
|
179
301
|
await disposeAgentInstances(staged, onDisposeError);
|
|
180
302
|
throw new Error(creationErrors.map(error => `${error.baseagent}: ${error.message}`).join('; '));
|
|
181
303
|
}
|
|
182
|
-
if (candidate.config.enabled !== false && staged.
|
|
304
|
+
if (candidate.config.enabled !== false && !staged.some(instance => instance.baseagent === candidate.baseagent)) {
|
|
305
|
+
await disposeAgentInstances(staged, onDisposeError);
|
|
183
306
|
throw new Error(`No runner could be created for ${candidate.aid}::${candidate.config.active_baseagent}`);
|
|
184
307
|
}
|
|
185
|
-
|
|
186
|
-
instance
|
|
187
|
-
|
|
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;
|
|
188
317
|
}
|
|
189
318
|
return createRunnerReloadTransaction({ aid: candidate.aid, agentMap, staged, onDisposeError });
|
|
190
319
|
},
|
|
@@ -388,7 +517,7 @@ export function createAgentRuntimeOperations({ agentRegistry, agentLoader, sessi
|
|
|
388
517
|
const creationErrors = [];
|
|
389
518
|
const newAgentInstances = await agentLoader.createForAgent(agent, {
|
|
390
519
|
onSessionIdUpdate: async (sessionId, agentSessionId, context) => (await sessionManager.updateAgentSessionIdBySessionId(sessionId, agentSessionId, context?.turn)),
|
|
391
|
-
}, creationErrors);
|
|
520
|
+
}, creationErrors, backend => backend === agent.baseagent);
|
|
392
521
|
for (const instance of newAgentInstances) {
|
|
393
522
|
agentMap.set(`${instance.evolagentName}::${instance.baseagent}`, instance.agent);
|
|
394
523
|
instance.agent.setPermissionGateway?.(permissionGateway);
|
|
@@ -553,6 +682,8 @@ const AUDITED_WORKFLOW_SHA256 = {
|
|
|
553
682
|
'0.5.30': '4f63c8116035ec509ffea67dd0a8fc3f0300a78ba89eefdd8c65af6d9da91517',
|
|
554
683
|
'0.5.31': 'c37811b6b589166b3fc90d51707572ca09d0253db593832add489dec0026a0e3',
|
|
555
684
|
'0.5.32': '7333bede3bb0a5dc5cd7e500dc2c91d23c5c772590659540c640d5f6eabc2f1d',
|
|
685
|
+
// 0.5.33 adds batch_id propagation; audited start/read/write/notify ordering is unchanged.
|
|
686
|
+
'0.5.33': '55b6d41331b4dfc6b377be9f4ff28d322af5e06fc4539c5d0120cb15419623f6',
|
|
556
687
|
};
|
|
557
688
|
export function initializationBindPreflightFailure(error) {
|
|
558
689
|
if (!(error instanceof Error) || error.code !== 'ECONNRESET')
|
|
@@ -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
|