evolcore 0.0.43-test.5 → 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 +47 -0
- package/bin/ecmsg.js +126 -43
- 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 +6 -6
- package/dist/aun/group/invite-service.js +3 -2
- package/dist/aun/service-proxy.js +18 -6
- package/dist/channels/aun.js +73 -10
- package/dist/cli/agent-create.js +16 -6
- package/dist/cli/aun-commands.js +9 -1
- package/dist/cli/daemon-commands.js +30 -1
- package/dist/cli/ecmsg-gateway.js +3 -1
- package/dist/cli/init.js +75 -0
- package/dist/cli/provider-command.js +1 -1
- package/dist/cli/restart-monitor.js +24 -5
- package/dist/cli/task-context.js +38 -1
- package/dist/cli/watch-logs.js +6 -4
- package/dist/config/boot-log.js +6 -4
- package/dist/config/builtin-roles.js +2 -2
- package/dist/config/config-manager.js +1 -1
- 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 +80 -87
- package/dist/config/snapshot.js +70 -41
- package/dist/core/agent-runtime.js +44 -7
- 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/command-handler.js +5 -5
- package/dist/core/command/menu-handler.js +8 -3
- package/dist/core/command/menu-protocol.js +82 -11
- package/dist/core/command/role-menu.js +27 -15
- 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 +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/ipc-registration.js +5 -4
- package/dist/core/lifecycle-notice.js +10 -4
- package/dist/core/message/aun-ipc-sender.js +2 -2
- 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 +10 -2
- package/dist/core/message/send-routing.js +12 -2
- package/dist/core/ownership/owner-resolver.js +1 -0
- package/dist/core/permission/ec-command-parser.js +11 -1
- 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 +9 -1
- package/dist/core/session/session-manager.js +36 -2
- package/dist/directory/owner-directory-admission.js +26 -1
- package/dist/directory/owner-directory-cache.js +57 -16
- package/dist/directory/owner-directory-query-operation.js +4 -1
- package/dist/ecweb/runtime/lifecycle.js +9 -7
- package/dist/ecweb/runtime/supervisor.js +44 -27
- package/dist/index.js +548 -251
- package/dist/proxy/manager.js +38 -17
- package/dist/proxy/service-supervisor.js +65 -31
- package/dist/trigger/application-service.js +3 -1
- package/dist/trigger/audit.js +19 -4
- package/dist/trigger/authorization.js +14 -5
- package/dist/trigger/history.js +176 -7
- package/dist/trigger/manager.js +1 -3
- package/dist/trigger/scheduler.js +78 -5
- package/dist/utils/cross-platform.js +152 -4
- 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/startup-trace.js +160 -19
- package/kits/docs/aun/ABILITY_CALLING.md +3 -3
- package/kits/docs/evolcore/INDEX.md +3 -2
- package/kits/docs/evolcore/ctl.md +2 -1
- package/kits/docs/evolcore/group.md +2 -2
- package/kits/docs/evolcore/menu-exec-schema-commands.md +1 -1
- package/kits/docs/evolcore/msg.md +13 -6
- package/kits/docs/evolcore/provider.md +21 -3
- package/kits/docs/evolcore/response.md +1 -1
- package/kits/eck_manifest.json +19 -7
- package/kits/eck_message_manifest.json +3 -3
- package/kits/rules/06-channel.md +5 -6
- 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/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-group/SKILL.md +8 -5
- package/kits/skills/ec-group-collaboration/SKILL.md +7 -7
- package/kits/skills/ec-trigger/SKILL.md +4 -4
- package/kits/skills/thread-ops/SKILL.md +10 -10
- package/kits/templates/system-fragments/commands.md +5 -5
- package/kits/templates/system-fragments/reply.md +2 -1
- package/kits/templates/system-fragments/session.md +1 -1
- package/kits/templates/system-fragments/thread.md +1 -1
- package/package.json +4 -3
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')
|
|
@@ -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;
|
|
@@ -43,6 +43,13 @@ export function showActivitiesPolicy(mode, chatType, _identity) {
|
|
|
43
43
|
export class ChannelLoader {
|
|
44
44
|
processDebug;
|
|
45
45
|
aunDefaultEncrypt;
|
|
46
|
+
connectionAdmission;
|
|
47
|
+
setConnectionAdmission(admit) {
|
|
48
|
+
this.connectionAdmission = admit;
|
|
49
|
+
}
|
|
50
|
+
connectInstance(instance) {
|
|
51
|
+
return this.connectionAdmission ? this.connectionAdmission(instance) : instance.connect();
|
|
52
|
+
}
|
|
46
53
|
plugins = new Map();
|
|
47
54
|
providerStatuses = new Map();
|
|
48
55
|
instanceStatuses = new Map();
|
|
@@ -141,15 +148,12 @@ export class ChannelLoader {
|
|
|
141
148
|
* AUN is always created implicitly from agent.aid (no explicit entry required).
|
|
142
149
|
*/
|
|
143
150
|
async createForAgent(agent) {
|
|
151
|
+
const aun = await this.createAunForAgent(agent);
|
|
152
|
+
const external = await this.createExternalForAgent(agent);
|
|
153
|
+
return [...aun, ...external];
|
|
154
|
+
}
|
|
155
|
+
async createAunForAgent(agent) {
|
|
144
156
|
assertAgentAidAvailable(agent.aid);
|
|
145
|
-
const ctx = {
|
|
146
|
-
agentName: agent.aid,
|
|
147
|
-
defaultProjectPath: agent.config.projects?.defaultPath ?? process.cwd(),
|
|
148
|
-
debug: this.processDebug,
|
|
149
|
-
aunDefaultEncrypt: this.aunDefaultEncrypt,
|
|
150
|
-
};
|
|
151
|
-
// Build the full list of config instances to create.
|
|
152
|
-
// AUN is synthesised from agent.aid; any explicit aun entry in channels[] is skipped.
|
|
153
157
|
const aunEffName = agent.effectiveChannelName('aun', 'main');
|
|
154
158
|
const aunInst = {
|
|
155
159
|
type: 'aun',
|
|
@@ -158,14 +162,26 @@ export class ChannelLoader {
|
|
|
158
162
|
enabled: true,
|
|
159
163
|
keystorePath: agent.config.aun?.keystorePath,
|
|
160
164
|
};
|
|
161
|
-
|
|
165
|
+
return this._buildInstances([aunInst], this.buildContext(agent));
|
|
166
|
+
}
|
|
167
|
+
async createExternalForAgent(agent) {
|
|
168
|
+
assertAgentAidAvailable(agent.aid);
|
|
169
|
+
const configInsts = [];
|
|
162
170
|
for (const inst of agent.config.channels) {
|
|
163
171
|
if (inst.type === 'aun')
|
|
164
172
|
continue;
|
|
165
173
|
const effName = agent.effectiveChannelName(inst.type, inst.name);
|
|
166
174
|
configInsts.push({ ...inst, name: effName });
|
|
167
175
|
}
|
|
168
|
-
return this._buildInstances(configInsts,
|
|
176
|
+
return this._buildInstances(configInsts, this.buildContext(agent));
|
|
177
|
+
}
|
|
178
|
+
buildContext(agent) {
|
|
179
|
+
return {
|
|
180
|
+
agentName: agent.aid,
|
|
181
|
+
defaultProjectPath: agent.config.projects?.defaultPath ?? process.cwd(),
|
|
182
|
+
debug: this.processDebug,
|
|
183
|
+
aunDefaultEncrypt: this.aunDefaultEncrypt,
|
|
184
|
+
};
|
|
169
185
|
}
|
|
170
186
|
/** Build runtime instances for a list of config instances + context. */
|
|
171
187
|
async _buildInstances(configInsts, ctx) {
|
|
@@ -278,7 +294,7 @@ export class ChannelLoader {
|
|
|
278
294
|
throw error;
|
|
279
295
|
}
|
|
280
296
|
}
|
|
281
|
-
async connectAll(instances, { concurrency = 3, intervalMs = 50, beforeConnect, shouldConnect, onConnected, onFailed } = {}) {
|
|
297
|
+
async connectAll(instances, { concurrency = 3, intervalMs = 50, beforeConnect, shouldConnect, onConnected, onFailed, connect } = {}) {
|
|
282
298
|
const connected = [];
|
|
283
299
|
const failed = [];
|
|
284
300
|
const inflight = new Set();
|
|
@@ -294,7 +310,9 @@ export class ChannelLoader {
|
|
|
294
310
|
const startConnection = (inst) => {
|
|
295
311
|
const task = (async () => {
|
|
296
312
|
try {
|
|
297
|
-
await inst.
|
|
313
|
+
const started = await (connect ? connect(inst) : this.connectInstance(inst));
|
|
314
|
+
if (started === false || inst.lifecycle?.signal.aborted || shouldConnect?.(inst) === false)
|
|
315
|
+
return;
|
|
298
316
|
connected.push(inst.adapter.channelName);
|
|
299
317
|
if (onConnected) {
|
|
300
318
|
void Promise.resolve().then(() => onConnected(inst)).catch(callbackErr => {
|
|
@@ -538,7 +556,12 @@ export function buildReloadHooks(deps) {
|
|
|
538
556
|
try {
|
|
539
557
|
registerChannelInstance(newInst);
|
|
540
558
|
onChannelStarted?.(newInst);
|
|
541
|
-
await
|
|
559
|
+
const started = await channelLoader.connectInstance(newInst);
|
|
560
|
+
if (started === false) {
|
|
561
|
+
await newInst.disconnect();
|
|
562
|
+
unregisterChannelInstance?.(channelName);
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
542
565
|
channelInstances.push(newInst);
|
|
543
566
|
await onChannelConnected?.(newInst);
|
|
544
567
|
logger.info(`[Reload] Started channel: ${channelName}`);
|