evolcore 0.0.43-test.4 → 0.0.43-test.6
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 +93 -0
- package/bin/ecmsg.js +437 -91
- package/dist/agents/baseagent-availability.js +19 -4
- package/dist/agents/baseagent.js +2 -2
- package/dist/agents/claude-runner.js +19 -4
- package/dist/agents/codex/app-server-client.js +14 -3
- package/dist/agents/codex-runner.js +18 -23
- package/dist/aun/aid/agentmd.js +25 -0
- package/dist/aun/aid/control-aid.js +15 -0
- package/dist/aun/aid/identity.js +8 -0
- package/dist/aun/aid/ownership-operation.js +12 -3
- package/dist/aun/group/invite-service.js +3 -2
- package/dist/aun/service-proxy.js +18 -6
- package/dist/channels/aun.js +99 -23
- package/dist/channels/daemon.js +2 -2
- package/dist/cli/agent-create.js +19 -7
- package/dist/cli/aid-bind-command.js +3 -0
- package/dist/cli/aun-commands.js +19 -4
- package/dist/cli/code-stats.js +451 -213
- package/dist/cli/ctl-command.js +1 -3
- package/dist/cli/daemon-commands.js +42 -4
- package/dist/cli/directory.js +3 -1
- package/dist/cli/ecmsg-gateway.js +206 -0
- package/dist/cli/index.js +6 -0
- package/dist/cli/init.js +120 -13
- package/dist/cli/provider-command.js +82 -5
- package/dist/cli/restart-monitor.js +35 -24
- package/dist/cli/stats.js +8 -1
- package/dist/cli/task-context.js +41 -1
- package/dist/cli/watch-logs.js +6 -4
- package/dist/config/boot-log.js +16 -3
- package/dist/config/builtin-roles.js +2 -2
- package/dist/config/config-manager.js +5 -14
- package/dist/config/daemon-services.js +1 -0
- package/dist/config/peer-role-resolver.js +6 -6
- package/dist/config/provider-identity-migration.js +277 -0
- package/dist/config/provider-identity.js +37 -0
- package/dist/config/provider-ipc-service.js +40 -3
- package/dist/config/provider-local-sync.js +155 -0
- package/dist/config/providers-config.js +45 -4
- package/dist/config/providers-management.js +242 -76
- package/dist/config/providers.js +4 -1
- package/dist/config/role-service.js +8 -8
- package/dist/config/role-store.js +22 -22
- package/dist/config/schema-migration.js +143 -86
- package/dist/config/snapshot.js +70 -41
- package/dist/core/agent-runtime.js +48 -9
- package/dist/core/auth/auth-gateway.js +5 -3
- package/dist/core/auth/delegation-diagnostics.js +6 -2
- package/dist/core/auth/operation-authorizer.js +3 -1
- package/dist/core/auth/operation-catalog.js +6 -4
- package/dist/core/baseagent-loader.js +114 -11
- package/dist/core/channel-loader.js +36 -13
- package/dist/core/channel-runtime.js +112 -42
- package/dist/core/command/cli-intent-parser.js +2 -1
- package/dist/core/command/command-handler.js +16 -11
- package/dist/core/command/menu-handler.js +8 -3
- package/dist/core/command/menu-protocol.js +80 -7
- package/dist/core/command/provider-menu.js +4 -2
- package/dist/core/command/role-menu.js +29 -17
- package/dist/core/command/slash-handler.js +52 -16
- package/dist/core/daemon-control.js +42 -15
- package/dist/core/daemon-lifecycle.js +411 -67
- package/dist/core/handoff/dispatcher.js +9 -3
- package/dist/core/handoff/runtime.js +139 -45
- package/dist/core/handoff/store.js +190 -2
- package/dist/core/handoff/types.js +5 -0
- package/dist/core/initialization/service.js +7 -6
- package/dist/core/ipc-registration.js +5 -4
- package/dist/core/lifecycle-notice.js +10 -4
- package/dist/core/message/aun-ipc-sender.js +83 -5
- package/dist/core/message/message-admission.js +2 -0
- package/dist/core/message/message-bridge.js +53 -4
- package/dist/core/message/message-queue.js +46 -4
- package/dist/core/message/pending-hints.js +4 -10
- package/dist/core/message/response-engine.js +33 -25
- package/dist/core/message/send-options.js +40 -0
- package/dist/core/message/send-routing.js +320 -0
- package/dist/core/ownership/owner-resolver.js +112 -8
- package/dist/core/permission/ec-command-parser.js +159 -16
- package/dist/core/permission/readonly-shell-query.js +66 -7
- package/dist/core/permission/tool-error-code.js +13 -1
- package/dist/core/permission/tool-policy.js +74 -20
- package/dist/core/relation/same-owner-proof.js +131 -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-fs-store.js +164 -3
- package/dist/core/session/session-idle-monitor.js +103 -17
- package/dist/core/session/session-manager.js +105 -18
- package/dist/core/thread/thread-route.js +5 -2
- package/dist/directory/owner-directory-admission.js +26 -1
- package/dist/directory/owner-directory-cache.js +739 -109
- package/dist/directory/owner-directory-markdown.js +146 -36
- package/dist/directory/owner-directory-query-operation.js +6 -3
- package/dist/directory/owner-directory-scope.js +12 -0
- package/dist/directory/owner-directory-search.js +5 -1
- package/dist/directory/owner-directory-store.js +28 -0
- package/dist/ecweb/basic-settings-service.js +15 -1
- package/dist/ecweb/message-context-service.js +2 -2
- package/dist/ecweb/providers-service.js +3 -1
- package/dist/ecweb/runtime/lifecycle.js +26 -15
- package/dist/ecweb/runtime/supervisor.js +120 -51
- package/dist/index.js +551 -250
- package/dist/paths.js +2 -1
- package/dist/proxy/manager.js +40 -17
- package/dist/proxy/service-supervisor.js +67 -33
- package/dist/response-system/engines/v1/proactive-flow.js +4 -0
- package/dist/trigger/application-service.js +4 -1
- package/dist/trigger/audit.js +19 -4
- package/dist/trigger/authorization.js +14 -5
- package/dist/trigger/event-source.js +4 -0
- package/dist/trigger/feedback.js +26 -2
- package/dist/trigger/history.js +176 -7
- package/dist/trigger/manager.js +1 -3
- package/dist/trigger/scheduler.js +81 -8
- package/dist/trigger/system-definitions.js +2 -2
- package/dist/trigger/validation.js +4 -0
- package/dist/utils/autostart.js +2 -2
- package/dist/utils/cross-platform.js +188 -12
- package/dist/utils/host-info.js +11 -8
- package/dist/utils/npm-ops.js +48 -0
- package/dist/utils/process-introspect.js +64 -1
- package/dist/utils/public-suffix.js +5811 -0
- package/dist/utils/startup-trace.js +160 -19
- package/dist/utils/windows-autostart.js +41 -7
- package/ecagent/dist/harness/env/nodejs.js +46 -2
- package/kits/docs/aun/ABILITY_CALLING.md +6 -6
- package/kits/docs/channels/aun.md +1 -1
- package/kits/docs/channels/feishu.md +2 -2
- package/kits/docs/context-assembly.md +20 -4
- package/kits/docs/evolcore/INDEX.md +5 -3
- package/kits/docs/evolcore/agent.md +2 -2
- package/kits/docs/evolcore/aid.md +8 -2
- package/kits/docs/evolcore/ctl.md +15 -5
- package/kits/docs/evolcore/directory.md +48 -15
- package/kits/docs/evolcore/group.md +8 -8
- package/kits/docs/evolcore/memory-consolidation.md +1 -1
- package/kits/docs/evolcore/menu-exec-schema-commands.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +32 -3
- package/kits/docs/evolcore/msg.md +38 -30
- package/kits/docs/evolcore/provider.md +57 -5
- package/kits/docs/evolcore/response.md +2 -2
- package/kits/docs/evolcore/thread-chain.md +11 -13
- package/kits/docs/evolcore/tool-authorization.md +17 -0
- package/kits/docs/evolcore/trigger.md +2 -2
- package/kits/docs/identity/ROLE_DETAIL.md +1 -1
- package/kits/docs/prompt-loading-architecture.md +30 -20
- package/kits/eck_manifest.auxiliary.json +5 -5
- package/kits/eck_manifest.json +44 -32
- package/kits/eck_manifest.memory.json +18 -18
- package/kits/eck_message_manifest.json +3 -3
- package/kits/rules/01-overview.md +1 -1
- package/kits/rules/06-channel.md +7 -8
- package/kits/schemas/_meta.json +7 -1
- 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/providers.schema.2.json +74 -0
- 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/aid-ability/SKILL.md +7 -7
- package/kits/skills/ec-agent-create/SKILL.md +1 -0
- 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 +3 -10
- package/kits/skills/ec-trigger/SKILL.md +9 -9
- package/kits/skills/ec-trigger/references/examples.md +1 -1
- package/kits/skills/thread-ops/SKILL.md +10 -10
- package/kits/templates/system-fragments/channel.md +5 -5
- package/kits/templates/system-fragments/commands.md +7 -6
- package/kits/templates/system-fragments/directory-contacts.md +10 -3
- package/kits/templates/system-fragments/personal-assistant.md +22 -3
- package/kits/templates/system-fragments/reply.md +48 -28
- package/kits/templates/system-fragments/session.md +3 -10
- package/kits/templates/system-fragments/thread.md +5 -5
- package/package.json +4 -4
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
|
}
|
|
@@ -50,11 +50,49 @@ export function loadStartupAgentRegistry(agentRegistry) {
|
|
|
50
50
|
}
|
|
51
51
|
return { primaryAgent, runtimeStatus };
|
|
52
52
|
}
|
|
53
|
-
export async function createStartupAgentRunners({ agentRegistry, agentLoader, sessionManager, primaryAgent, agentInstances: publishedInstances, agentMap: publishedMap, configureInstances, isCancelled, onAgentCreated, }) {
|
|
53
|
+
export async function createStartupAgentRunners({ agentRegistry, agentLoader, sessionManager, primaryAgent, agentInstances: publishedInstances, agentMap: publishedMap, configureInstances, isCancelled, onAgentCreated, onAgentReady, startupPriority, }) {
|
|
54
54
|
const creationErrors = [];
|
|
55
55
|
const agentInstances = publishedInstances ?? [];
|
|
56
56
|
const agentMap = publishedMap ?? new Map();
|
|
57
57
|
const primaryBaseagent = primaryAgent?.baseagent ?? 'claude';
|
|
58
|
+
const published = new Set();
|
|
59
|
+
const activeSettled = new Set();
|
|
60
|
+
const publish = (instances) => {
|
|
61
|
+
const fresh = instances.filter(instance => !published.has(instance));
|
|
62
|
+
if (!fresh.length)
|
|
63
|
+
return;
|
|
64
|
+
configureInstances?.(fresh);
|
|
65
|
+
for (const instance of fresh) {
|
|
66
|
+
published.add(instance);
|
|
67
|
+
agentInstances.push(instance);
|
|
68
|
+
agentMap.set(`${instance.evolagentName}::${instance.baseagent}`, instance.agent);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
const activeReady = async (agent, instances, timing) => {
|
|
72
|
+
if (activeSettled.has(agent.aid))
|
|
73
|
+
return;
|
|
74
|
+
if (isCancelled?.()) {
|
|
75
|
+
await disposeAgentInstances(instances);
|
|
76
|
+
activeSettled.add(agent.aid);
|
|
77
|
+
await onAgentReady?.(agent, [], timing);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
publish(instances);
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
await disposeAgentInstances(instances);
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
activeSettled.add(agent.aid);
|
|
88
|
+
if (!instances.some(instance => instance.baseagent === agent.baseagent)) {
|
|
89
|
+
agent.status = 'error';
|
|
90
|
+
agent.error = creationErrors.filter(error => error.evolagentName === agent.name)
|
|
91
|
+
.map(({ baseagent, message }) => `${baseagent}: ${message}`).join('; ')
|
|
92
|
+
|| `No agent runner created for ${agent.aid}::${agent.baseagent}`;
|
|
93
|
+
}
|
|
94
|
+
await onAgentReady?.(agent, instances, timing);
|
|
95
|
+
};
|
|
58
96
|
const createdInstances = await agentLoader.createAll(agentRegistry, {
|
|
59
97
|
onSessionIdUpdate: async (sessionId, agentSessionId, context) => (await sessionManager.updateAgentSessionIdBySessionId(sessionId, agentSessionId, context?.turn)),
|
|
60
98
|
}, creationErrors, async (agent, instances, timing) => {
|
|
@@ -64,16 +102,13 @@ export async function createStartupAgentRunners({ agentRegistry, agentLoader, se
|
|
|
64
102
|
return;
|
|
65
103
|
}
|
|
66
104
|
try {
|
|
67
|
-
|
|
105
|
+
publish(instances);
|
|
68
106
|
}
|
|
69
107
|
catch (error) {
|
|
70
108
|
await disposeAgentInstances(instances);
|
|
71
109
|
throw error;
|
|
72
110
|
}
|
|
73
|
-
|
|
74
|
-
for (const instance of instances) {
|
|
75
|
-
agentMap.set(`${instance.evolagentName}::${instance.baseagent}`, instance.agent);
|
|
76
|
-
}
|
|
111
|
+
await activeReady(agent, instances, timing);
|
|
77
112
|
if (primaryAgent?.aid === agent.aid
|
|
78
113
|
? !instances.some(instance => instance.baseagent === primaryBaseagent)
|
|
79
114
|
: !instances.some(instance => instance.baseagent === agent.baseagent)) {
|
|
@@ -84,7 +119,7 @@ export async function createStartupAgentRunners({ agentRegistry, agentLoader, se
|
|
|
84
119
|
: `No agent runner created for ${agent.aid}::${primaryAgent?.aid === agent.aid ? primaryBaseagent : agent.baseagent}`;
|
|
85
120
|
}
|
|
86
121
|
await onAgentCreated?.(agent, instances, timing);
|
|
87
|
-
}, () => !isCancelled?.());
|
|
122
|
+
}, () => !isCancelled?.(), activeReady, startupPriority);
|
|
88
123
|
if (!isCancelled?.()) {
|
|
89
124
|
agentInstances.splice(0, agentInstances.length, ...createdInstances);
|
|
90
125
|
}
|
|
@@ -553,6 +588,8 @@ const AUDITED_WORKFLOW_SHA256 = {
|
|
|
553
588
|
'0.5.30': '4f63c8116035ec509ffea67dd0a8fc3f0300a78ba89eefdd8c65af6d9da91517',
|
|
554
589
|
'0.5.31': 'c37811b6b589166b3fc90d51707572ca09d0253db593832add489dec0026a0e3',
|
|
555
590
|
'0.5.32': '7333bede3bb0a5dc5cd7e500dc2c91d23c5c772590659540c640d5f6eabc2f1d',
|
|
591
|
+
// 0.5.33 adds batch_id propagation; audited start/read/write/notify ordering is unchanged.
|
|
592
|
+
'0.5.33': '55b6d41331b4dfc6b377be9f4ff28d322af5e06fc4539c5d0120cb15419623f6',
|
|
556
593
|
};
|
|
557
594
|
export function initializationBindPreflightFailure(error) {
|
|
558
595
|
if (!(error instanceof Error) || error.code !== 'ECONNRESET')
|
|
@@ -588,7 +625,7 @@ async function withInitializationClient(aid, action) {
|
|
|
588
625
|
// An entered bind can have remote effects. Its adapter may only mark an
|
|
589
626
|
// audited read-only preflight as not started; all other failures stay unknown.
|
|
590
627
|
actionStarted = true;
|
|
591
|
-
return await action(client);
|
|
628
|
+
return await action(client, store);
|
|
592
629
|
}
|
|
593
630
|
catch (error) {
|
|
594
631
|
if (!actionStarted) {
|
|
@@ -614,7 +651,9 @@ async function withInitializationClient(aid, action) {
|
|
|
614
651
|
}
|
|
615
652
|
}
|
|
616
653
|
export async function bindInitializationOwner(aid, ownerAid) {
|
|
617
|
-
return withInitializationClient(aid, async (client) => {
|
|
654
|
+
return withInitializationClient(aid, async (client, store) => {
|
|
655
|
+
const { assertHumanAgentOwner } = await import('../aun/aid/agentmd.js');
|
|
656
|
+
await assertHumanAgentOwner(ownerAid, { store });
|
|
618
657
|
try {
|
|
619
658
|
return await client.bindOwneraid(ownerAid);
|
|
620
659
|
}
|
|
@@ -8,7 +8,7 @@ import { ownerResolver, refreshOwnershipForAuthorization, OWNERSHIP_CACHE_MAX_AG
|
|
|
8
8
|
import { getOperationMeta } from './operation-catalog.js';
|
|
9
9
|
import { constrainRuntimePermissionMode, resolveRuntimePermissionMode } from '../role/runtime-policy.js';
|
|
10
10
|
import { buildAuthorizationEventKey } from '../audit/event-key.js';
|
|
11
|
-
import {
|
|
11
|
+
import { prepareSameOwnerProof, sameOwnerQualification, requiresSameOwnerProof } from '../relation/same-owner-proof.js';
|
|
12
12
|
export function isCrossAgentTriggerOperationAllowed(input) {
|
|
13
13
|
return input.control || input.daemonOwner === true || input.taskAgentAid === input.targetAgentAid;
|
|
14
14
|
}
|
|
@@ -44,7 +44,7 @@ export function buildAuthSubject(input) {
|
|
|
44
44
|
}));
|
|
45
45
|
const internalContactContext = roleDetail.source === 'internal-contact-default'
|
|
46
46
|
|| (input.channelType === 'aun' && chatType === 'private' && input.selfAid && actorId
|
|
47
|
-
&& (
|
|
47
|
+
&& (sameOwnerQualification(input.selfAid, actorId) === 'matched' || requiresSameOwnerProof(input.selfAid, actorId)));
|
|
48
48
|
const suppliedRole = !internalContactContext && input.identity?.role && input.identity.role !== 'none' ? input.identity.role : undefined;
|
|
49
49
|
const role = suppliedRole ?? roleDetail.effectiveRole ?? 'none';
|
|
50
50
|
const processRole = isFullAccessRun
|
|
@@ -122,7 +122,7 @@ export async function authorizeFreshOperation(params) {
|
|
|
122
122
|
|| configCommand?.dangerous || subject.processRole === 'fullaccess-run';
|
|
123
123
|
try {
|
|
124
124
|
if (subject.channelType === 'aun' && subject.chatType === 'private') {
|
|
125
|
-
await
|
|
125
|
+
await prepareSameOwnerProof(subject.selfAid, subject.actorId);
|
|
126
126
|
}
|
|
127
127
|
await refreshOwnershipForAuthorization(subject.selfAid, {
|
|
128
128
|
force: force || forceAgentMdEditor,
|
|
@@ -153,6 +153,8 @@ export async function authorizeFreshOperation(params) {
|
|
|
153
153
|
chatType: subject.chatType, conversationId: subject.conversationId,
|
|
154
154
|
fromControlChannel: subject.fromControlChannel,
|
|
155
155
|
identity: subject.roleSource === 'internal-contact-default' || (subject.role === 'owner' && subject.principalId)
|
|
156
|
+
|| (subject.channelType === 'aun' && subject.principalId
|
|
157
|
+
&& ownerResolver.owner(subject.selfAid) === subject.principalId)
|
|
156
158
|
? undefined : subject.identity,
|
|
157
159
|
});
|
|
158
160
|
if (subject.processRole === 'fullaccess-run') {
|
|
@@ -147,8 +147,12 @@ export class DelegationDiagnostics {
|
|
|
147
147
|
return 'session_mismatch';
|
|
148
148
|
if (credential.kind === 'task')
|
|
149
149
|
return this.taskCause(credential);
|
|
150
|
-
const
|
|
151
|
-
const
|
|
150
|
+
const candidate = commandHash ? this.find('approval', tokenHash, sessionId, commandHash) : undefined;
|
|
151
|
+
const approval = candidate?.taskId === credential.taskId
|
|
152
|
+
&& candidate?.activeTokenHash === credential.activeTokenHash
|
|
153
|
+
&& candidate?.runtimeEpoch === credential.runtimeEpoch
|
|
154
|
+
? candidate : undefined;
|
|
155
|
+
const activeTokenHash = credential.activeTokenHash;
|
|
152
156
|
const task = activeTokenHash
|
|
153
157
|
? this.find('task', activeTokenHash, sessionId)
|
|
154
158
|
: undefined;
|
|
@@ -522,7 +522,9 @@ function authorizeCatalogPolicy(ctx, meta) {
|
|
|
522
522
|
if (!policy)
|
|
523
523
|
return undefined;
|
|
524
524
|
if (policy.authority === 'daemon-owner') {
|
|
525
|
-
|
|
525
|
+
const delegatedRead = policy.allowDelegatedRead === true && ctx.source === 'agent-tool'
|
|
526
|
+
&& meta.category === 'read' && !meta.dangerous;
|
|
527
|
+
return scope === policy.scope && policy.channel === 'control' && (ctx.fromControlChannel || delegatedRead)
|
|
526
528
|
&& hasDaemonOwnerRole(ctx) && ctx.processRole !== 'daemon-service'
|
|
527
529
|
? allow('daemon-owner', 'catalog-daemon-owner')
|
|
528
530
|
: deny('This operation requires DaemonOwner process control');
|
|
@@ -144,14 +144,16 @@ const QUEUE_OPERATIONS = [['read', 'Read the current Agent message queue'], ['cl
|
|
|
144
144
|
*
|
|
145
145
|
* 参照设计文档 docs/command-execution-role-permission-design.md 第 5 节
|
|
146
146
|
*/
|
|
147
|
-
const PROVIDER_OPERATIONS = ['list', 'show', 'create', 'import', 'update', 'delete'].map(action => ({
|
|
147
|
+
const PROVIDER_OPERATIONS = ['list', 'show', 'create', 'import', 'update', 'delete', 'sync'].map(action => ({
|
|
148
148
|
id: 'provider.' + action,
|
|
149
149
|
category: action === 'list' || action === 'show' ? 'read' : 'process',
|
|
150
150
|
dangerous: action !== 'list' && action !== 'show',
|
|
151
151
|
defaultScopes: ['process'],
|
|
152
152
|
description: 'Manage the daemon Provider registry: ' + action,
|
|
153
|
-
sources:
|
|
154
|
-
|
|
153
|
+
sources: action === 'sync' ? ['control']
|
|
154
|
+
: action === 'list' || action === 'show' ? ['menu', 'control', 'ecweb', 'agent-tool'] : ['menu', 'control', 'ecweb'],
|
|
155
|
+
authorizationPolicy: { authority: 'daemon-owner', scope: 'process', channel: 'control',
|
|
156
|
+
allowDelegatedRead: action === 'list' || action === 'show' },
|
|
155
157
|
}));
|
|
156
158
|
const OPERATIONS = [
|
|
157
159
|
...['read', 'result-read', 'install', 'configure', 'enable', 'disable', 'invoke', 'publish', 'upgrade', 'rollback', 'uninstall', 'grant', 'retire'].map(action => ({
|
|
@@ -1264,7 +1266,7 @@ const OPERATIONS = [
|
|
|
1264
1266
|
{
|
|
1265
1267
|
id: 'ec.aid.bind', category: 'write-agent', dangerous: true, defaultScopes: ['agent'],
|
|
1266
1268
|
minimumPermissionMode: 'request',
|
|
1267
|
-
description: 'Request or decide a protocol Owner binding
|
|
1269
|
+
description: 'Request or decide a protocol Owner binding, or reset its local automatic-invitation rejection', sources: ['agent-tool', 'menu.cli'],
|
|
1268
1270
|
},
|
|
1269
1271
|
{
|
|
1270
1272
|
id: 'ec.aid.transfer', category: 'write-agent', dangerous: true, defaultScopes: ['agent'],
|
|
@@ -44,27 +44,130 @@ export class AgentLoader {
|
|
|
44
44
|
* Iterate over all EvolAgents in the registry × all registered plugins.
|
|
45
45
|
* Each successful (agent, plugin) pair yields one runner instance.
|
|
46
46
|
*/
|
|
47
|
-
async createAll(registry, callbacks, creationErrors, onAgentCreated, shouldCreateAgent = () => true) {
|
|
47
|
+
async createAll(registry, callbacks, creationErrors, onAgentCreated, shouldCreateAgent = () => true, onActiveCreated, startupPriority) {
|
|
48
48
|
const instances = [];
|
|
49
49
|
const allAgents = registry.runnableAgents();
|
|
50
|
-
//
|
|
51
|
-
//
|
|
52
|
-
//
|
|
53
|
-
//
|
|
54
|
-
const created =
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
50
|
+
// A slow CLI consumes only its backend's slots. Keeping one bounded lane
|
|
51
|
+
// per plugin prevents four pending Codex probes from starving Claude or
|
|
52
|
+
// ecagent Agents later in registry order. Active work precedes standby
|
|
53
|
+
// work within each lane, without a barrier between different backends.
|
|
54
|
+
const created = allAgents.map(() => []);
|
|
55
|
+
const startedAt = allAgents.map(() => Date.now());
|
|
56
|
+
const activeResolvers = [];
|
|
57
|
+
const activeReady = allAgents.map(() => new Promise(resolve => activeResolvers.push(resolve)));
|
|
58
|
+
const agentsByBackend = new Map();
|
|
59
|
+
allAgents.forEach((agent, index) => {
|
|
60
|
+
const indices = agentsByBackend.get(agent.baseagent) ?? [];
|
|
61
|
+
indices.push(index);
|
|
62
|
+
agentsByBackend.set(agent.baseagent, indices);
|
|
59
63
|
});
|
|
64
|
+
const lanes = [...new Set([...this.plugins.keys(), ...agentsByBackend.keys()])];
|
|
65
|
+
const completed = allAgents.map(() => 0);
|
|
66
|
+
const completeBackend = async (index) => {
|
|
67
|
+
if (++completed[index] !== lanes.length)
|
|
68
|
+
return;
|
|
69
|
+
const agent = allAgents[index];
|
|
70
|
+
created[index].sort((left, right) => (left.baseagent === agent.baseagent ? -1 : right.baseagent === agent.baseagent ? 1
|
|
71
|
+
: lanes.indexOf(left.baseagent) - lanes.indexOf(right.baseagent)));
|
|
72
|
+
await onAgentCreated?.(agent, created[index], { startedAtMs: startedAt[index], completedAtMs: Date.now() });
|
|
73
|
+
};
|
|
74
|
+
const outcomes = await Promise.allSettled(lanes.map(async (backend) => {
|
|
75
|
+
// Priority standby work may wait for a different backend. Keep that wait
|
|
76
|
+
// outside this lane's capacity so deferred active runners can proceed
|
|
77
|
+
// after a degraded release, while sharing the same four creation slots.
|
|
78
|
+
let activeCreations = 0;
|
|
79
|
+
const waitingCreations = [];
|
|
80
|
+
const create = async (agent) => {
|
|
81
|
+
if (activeCreations < 4)
|
|
82
|
+
activeCreations++;
|
|
83
|
+
else
|
|
84
|
+
await new Promise(resolve => waitingCreations.push(resolve));
|
|
85
|
+
try {
|
|
86
|
+
return shouldCreateAgent()
|
|
87
|
+
? await this.createForAgent(agent, callbacks, creationErrors, name => name === backend) : [];
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
const next = waitingCreations.shift();
|
|
91
|
+
if (next)
|
|
92
|
+
next();
|
|
93
|
+
else
|
|
94
|
+
activeCreations--;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const standbyTasks = [];
|
|
98
|
+
try {
|
|
99
|
+
for (const priority of startupPriority ? [true, false] : [true]) {
|
|
100
|
+
// Wait outside bounded lanes: deferred Agents cannot occupy capacity
|
|
101
|
+
// needed to publish a recovering Agent's active or standby runner.
|
|
102
|
+
const groupIndices = allAgents.map((_, index) => index).filter(index => !startupPriority || startupPriority.aids.has(allAgents[index].aid) === priority);
|
|
103
|
+
if (!groupIndices.length)
|
|
104
|
+
continue;
|
|
105
|
+
if (!priority)
|
|
106
|
+
await startupPriority.waitForDeferred();
|
|
107
|
+
const activeIndices = groupIndices.filter(index => allAgents[index].baseagent === backend);
|
|
108
|
+
try {
|
|
109
|
+
await mapWithConcurrency(activeIndices, 4, async (index) => {
|
|
110
|
+
const agent = allAgents[index];
|
|
111
|
+
startedAt[index] = Date.now();
|
|
112
|
+
try {
|
|
113
|
+
const active = await create(agent);
|
|
114
|
+
created[index].push(...active);
|
|
115
|
+
await onActiveCreated?.(agent, active, { startedAtMs: startedAt[index], completedAtMs: Date.now() });
|
|
116
|
+
await completeBackend(index);
|
|
117
|
+
}
|
|
118
|
+
finally {
|
|
119
|
+
activeResolvers[index]();
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
finally {
|
|
124
|
+
// A publication callback failure must not strand another lane waiting
|
|
125
|
+
// for an Agent this lane could no longer admit.
|
|
126
|
+
for (const index of activeIndices)
|
|
127
|
+
activeResolvers[index]();
|
|
128
|
+
}
|
|
129
|
+
const standby = mapWithConcurrency(groupIndices, 4, async (index) => {
|
|
130
|
+
const agent = allAgents[index];
|
|
131
|
+
if (agent.baseagent === backend)
|
|
132
|
+
return;
|
|
133
|
+
// The same Agent's active publication configures task callbacks before
|
|
134
|
+
// standby publication; other Agents' active lanes remain independent.
|
|
135
|
+
await activeReady[index];
|
|
136
|
+
created[index].push(...await create(agent));
|
|
137
|
+
await completeBackend(index);
|
|
138
|
+
}).then(() => { });
|
|
139
|
+
standbyTasks.push(standby);
|
|
140
|
+
// Observe immediately, then propagate after every lane task settles.
|
|
141
|
+
void standby.catch(() => { });
|
|
142
|
+
if (!startupPriority)
|
|
143
|
+
await standby;
|
|
144
|
+
}
|
|
145
|
+
const standbyOutcomes = await Promise.allSettled(standbyTasks);
|
|
146
|
+
const failure = standbyOutcomes.find((outcome) => outcome.status === 'rejected');
|
|
147
|
+
if (failure)
|
|
148
|
+
throw failure.reason;
|
|
149
|
+
}
|
|
150
|
+
finally {
|
|
151
|
+
// A callback failure can retire this lane before its deferred group.
|
|
152
|
+
// Other backends must still be able to settle their standby waits.
|
|
153
|
+
for (const index of agentsByBackend.get(backend) ?? [])
|
|
154
|
+
activeResolvers[index]();
|
|
155
|
+
await Promise.allSettled(standbyTasks);
|
|
156
|
+
}
|
|
157
|
+
}));
|
|
158
|
+
const failed = outcomes.find((outcome) => outcome.status === 'rejected');
|
|
159
|
+
if (failed)
|
|
160
|
+
throw failed.reason;
|
|
60
161
|
for (const agentInstances of created)
|
|
61
162
|
instances.push(...agentInstances);
|
|
62
163
|
return instances;
|
|
63
164
|
}
|
|
64
165
|
/** Create runners for one EvolAgent, used by runtime hot-load. */
|
|
65
|
-
async createForAgent(agent, callbacks, creationErrors) {
|
|
166
|
+
async createForAgent(agent, callbacks, creationErrors, selectPlugin = () => true) {
|
|
66
167
|
const instances = [];
|
|
67
168
|
for (const [pluginName, plugin] of this.plugins) {
|
|
169
|
+
if (!selectPlugin(pluginName))
|
|
170
|
+
continue;
|
|
68
171
|
if (!plugin.isEnabled(agent)) {
|
|
69
172
|
logger.debug(`Plugin '${pluginName}' disabled for agent '${agent.name}', skipping`);
|
|
70
173
|
continue;
|