evolcore 0.0.43-test.7 → 0.0.43-test.8
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 +22 -9
- package/dist/agent-template/jobs.js +62 -0
- package/dist/agent-template/runtime.js +214 -0
- package/dist/agent-template/service.js +465 -0
- package/dist/agent-template/tool-runner.js +45 -0
- package/dist/agent-template/types.js +5 -0
- package/dist/agents/claude-runner.js +1 -1
- package/dist/aun/aid/agentmd.js +56 -1
- package/dist/aun/aid/client.js +3 -1
- package/dist/aun/menu/client.js +3 -2
- package/dist/aun/msg/p2p.js +1 -1
- package/dist/channels/aun.js +47 -32
- package/dist/cli/agent-command.js +5 -0
- package/dist/cli/agent-create.js +5 -1
- package/dist/cli/agent-template.js +124 -0
- package/dist/cli/aun-commands.js +2 -2
- package/dist/cli/ctl-command.js +2 -1
- package/dist/cli/daemon-commands.js +5 -0
- package/dist/cli/ecmsg-gateway.js +2 -2
- package/dist/cli/events-command.js +45 -9
- package/dist/cli/index.js +29 -0
- package/dist/cli/net-check.js +1 -1
- package/dist/cli/restart-monitor.js +115 -36
- package/dist/cli/services-command.js +29 -3
- package/dist/cli/thread-command.js +97 -11
- package/dist/config/boot-log.js +8 -8
- package/dist/config/schema-migration.js +41 -16
- package/dist/core/agent-ipc-registration.js +25 -4
- package/dist/core/agent-runtime.js +2 -0
- package/dist/core/auth/operation-authorizer.js +2 -0
- package/dist/core/auth/operation-catalog.js +11 -2
- package/dist/core/channel-runtime.js +16 -9
- package/dist/core/command/agent-control.js +11 -1
- package/dist/core/command/agent-template-menu.js +147 -0
- package/dist/core/command/command-handler.js +27 -6
- package/dist/core/command/eventcenter-menu.js +158 -28
- package/dist/core/command/menu-catalog.js +8 -1
- package/dist/core/command/menu-handler.js +18 -6
- package/dist/core/command/menu-protocol.js +11 -2
- package/dist/core/daemon-control.js +14 -0
- package/dist/core/daemon-lifecycle.js +262 -189
- package/dist/core/handoff/runtime.js +42 -10
- package/dist/core/ipc-registration.js +5 -1
- package/dist/core/legacy-rename.js +41 -0
- package/dist/core/message/aun-ipc-sender.js +118 -13
- package/dist/core/message/im-renderer.js +88 -1
- package/dist/core/message/message-queue.js +66 -15
- package/dist/core/message/pending-hints.js +29 -5
- package/dist/core/message/response-engine.js +37 -7
- package/dist/core/message/send-routing.js +13 -6
- package/dist/core/pack-auth.js +94 -0
- package/dist/core/pack-install.js +194 -0
- package/dist/core/permission/ec-command-parser.js +49 -16
- package/dist/core/rate-window.js +48 -0
- package/dist/core/relation/peer-identity.js +28 -0
- package/dist/core/session/session-fs-store.js +66 -26
- package/dist/core/session/session-idle-monitor.js +59 -19
- package/dist/core/session/session-manager.js +13 -4
- package/dist/core/thread/thread-route.js +2 -2
- package/dist/core/thread/thread-service.js +52 -3
- package/dist/eck/kit-renderer.js +1 -1
- package/dist/eck/message-renderer.js +2 -0
- package/dist/event-center/admission-materializer.js +22 -12
- package/dist/event-center/bus-gate.js +20 -2
- package/dist/event-center/bus-host.js +46 -29
- package/dist/event-center/bus-resolver.js +1 -1
- package/dist/event-center/center-config.js +41 -14
- package/dist/event-center/daemon.js +1 -2
- package/dist/event-center/directory-source.js +3 -1
- package/dist/event-center/index-generator.js +12 -2
- package/dist/event-center/ipc-operation.js +140 -25
- package/dist/event-center/pack-loader.js +61 -56
- package/dist/event-center/pack-manager.js +2 -2
- package/dist/event-center/registry.js +242 -17
- package/dist/event-center/runtime.js +271 -75
- package/dist/event-center/types.js +20 -4
- package/dist/event-center/validation.js +34 -12
- package/dist/index.js +147 -44
- package/dist/ipc.js +44 -4
- package/dist/paths.js +2 -2
- package/dist/response-system/engines/v1/proactive-flow.js +4 -2
- package/dist/services/index.js +3 -3
- package/dist/services/ipc-operation.js +99 -7
- package/dist/services/pack-manager.js +17 -6
- package/dist/services/router.js +8 -5
- package/dist/services/validation.js +5 -5
- package/dist/trigger/scheduler.js +38 -0
- package/dist/trigger/script-sandbox.js +52 -2
- package/dist/utils/npm-ops.js +2 -1
- package/dist/utils/package-version-info.js +6 -3
- package/kits/docs/aun/ABILITY_CALLING.md +4 -3
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +3 -3
- package/kits/docs/evolcore/agent.md +22 -1
- package/kits/docs/evolcore/event-center.md +30 -10
- package/kits/docs/evolcore/fs.md +4 -3
- package/kits/docs/evolcore/menu-protocol.md +7 -1
- package/kits/docs/evolcore/msg.md +8 -8
- package/kits/docs/evolcore/response.md +2 -2
- package/kits/docs/evolcore/services.md +27 -10
- package/kits/docs/evolcore/thread-chain.md +15 -3
- package/kits/rules/06-channel.md +1 -0
- package/kits/skills/ability/references/calling.md +2 -2
- package/kits/skills/ec-group/SKILL.md +5 -8
- 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/message-fragments/item.md +1 -1
- package/kits/templates/system-fragments/channel.md +1 -1
- package/kits/templates/system-fragments/commands.md +1 -1
- package/kits/templates/system-fragments/reply.md +1 -0
- package/kits/templates/system-fragments/thread.md +3 -2
- package/package.json +4 -3
- package/scripts/agent-template/index.mjs +40 -0
- package/scripts/agent-template/inspect.mjs +240 -0
- package/scripts/agent-template/overlay.mjs +71 -0
- package/scripts/agent-template/pack.mjs +169 -0
- package/scripts/agent-template/shared/common.mjs +235 -0
- package/scripts/agent-template/shared/evolcore.mjs +75 -0
- package/scripts/agent-template/shared/plan.mjs +129 -0
- package/scripts/agent-template/shared/team-schema.json +70 -0
- package/scripts/agent-template/shared/template-contract.mjs +154 -0
- package/scripts/agent-template/shared/template-package.mjs +265 -0
- package/scripts/agent-template/shared/template-runtime.mjs +80 -0
- package/scripts/agent-template/shared/template.mjs +142 -0
- package/dist/event-center/client-factory.js +0 -50
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* pack.json /
|
|
2
|
+
* pack.json / events-config.json 校验。
|
|
3
3
|
* 约束 1:1 映射 docs/event-center/schema/{pack,center}.schema.json;Schema 为权威,两者不一致改这里并同步 Schema。
|
|
4
4
|
* 手写校验器(不引 ajv),失败逐条报错。
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* AID 形态:`<label>(.<label>)*.<tld>`,label 以字母数字开头结尾、中间可含连字符。
|
|
8
|
+
*
|
|
9
|
+
* 比旧版 `[a-z0-9][a-z0-9.-]*\.[a-z]{2,}` 严:旧版接受 `a..b.cn`(空 label)
|
|
10
|
+
* 和 `a-.cn`(连字符结尾),这类串永远不可能是真实 AID,却能被写进白名单当噪音。
|
|
11
|
+
*/
|
|
12
|
+
export const AID_PATTERN = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)*\.[a-z]{2,}$/;
|
|
7
13
|
export const EVENT_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
8
14
|
export const ROLE_NAME_PATTERN = /^[a-z0-9_-]+$/;
|
|
9
15
|
export const SCRIPT_EXTENSIONS = ['mjs', 'cjs', 'js', 'py', 'sh', 'ps1'];
|
|
@@ -321,13 +327,13 @@ function validateAidList(value, field, errors) {
|
|
|
321
327
|
}
|
|
322
328
|
return out;
|
|
323
329
|
}
|
|
324
|
-
/** 校验
|
|
330
|
+
/** 校验 events-config.json 原始对象。 */
|
|
325
331
|
export function validateCenterConfig(raw) {
|
|
326
332
|
const errors = [];
|
|
327
333
|
if (!isRecord(raw)) {
|
|
328
|
-
return { ok: false, errors: ['
|
|
334
|
+
return { ok: false, errors: ['events-config.json must be a JSON object'] };
|
|
329
335
|
}
|
|
330
|
-
const extra = Object.keys(raw).filter(key => !['v', 'enabled', 'authMode', 'admission', '
|
|
336
|
+
const extra = Object.keys(raw).filter(key => !['v', 'enabled', 'authMode', 'admission', 'rules', 'rateLimit'].includes(key));
|
|
331
337
|
if (extra.length)
|
|
332
338
|
errors.push(`unknown top-level fields: ${extra.join(', ')}`);
|
|
333
339
|
if (raw.v !== 1)
|
|
@@ -353,12 +359,27 @@ export function validateCenterConfig(raw) {
|
|
|
353
359
|
if (parsedRematerializeMs !== undefined)
|
|
354
360
|
rematerializeMs = parsedRematerializeMs;
|
|
355
361
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
362
|
+
// 发布限流:缺省 60/分、600/时,按发布方 AID 计。
|
|
363
|
+
let rateLimit = { perMinute: 60, perHour: 600 };
|
|
364
|
+
if (raw.rateLimit !== undefined) {
|
|
365
|
+
if (!isRecord(raw.rateLimit))
|
|
366
|
+
errors.push('rateLimit must be an object');
|
|
367
|
+
else {
|
|
368
|
+
const rateExtra = Object.keys(raw.rateLimit).filter(key => !['perMinute', 'perHour'].includes(key));
|
|
369
|
+
if (rateExtra.length)
|
|
370
|
+
errors.push(`rateLimit has unknown fields: ${rateExtra.join(', ')}`);
|
|
371
|
+
rateLimit = {
|
|
372
|
+
perMinute: intInRange(raw.rateLimit.perMinute, 'rateLimit.perMinute', 1, Number.MAX_SAFE_INTEGER, errors) ?? 60,
|
|
373
|
+
perHour: intInRange(raw.rateLimit.perHour, 'rateLimit.perHour', 1, Number.MAX_SAFE_INTEGER, errors) ?? 600,
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
const rules = {};
|
|
378
|
+
if (raw.rules !== undefined) {
|
|
379
|
+
if (!isRecord(raw.rules))
|
|
380
|
+
errors.push('rules must be an object');
|
|
360
381
|
else {
|
|
361
|
-
for (const [event, entry] of Object.entries(raw.
|
|
382
|
+
for (const [event, entry] of Object.entries(raw.rules)) {
|
|
362
383
|
if (!isEventName(event)) {
|
|
363
384
|
errors.push(`allowlist key must be an event name: ${event}`);
|
|
364
385
|
continue;
|
|
@@ -393,7 +414,7 @@ export function validateCenterConfig(raw) {
|
|
|
393
414
|
if (overlap.length)
|
|
394
415
|
errors.push(`allowlist.${event}.${direction} contains the same AID in allow and deny: ${overlap.join(', ')}`);
|
|
395
416
|
}
|
|
396
|
-
|
|
417
|
+
rules[event] = { allow, deny };
|
|
397
418
|
}
|
|
398
419
|
}
|
|
399
420
|
}
|
|
@@ -407,7 +428,8 @@ export function validateCenterConfig(raw) {
|
|
|
407
428
|
enabled: raw.enabled === true,
|
|
408
429
|
authMode: 'allowlist',
|
|
409
430
|
admission: { coupling, rematerializeMs },
|
|
410
|
-
|
|
431
|
+
rules,
|
|
432
|
+
rateLimit,
|
|
411
433
|
},
|
|
412
434
|
};
|
|
413
435
|
}
|
package/dist/index.js
CHANGED
|
@@ -46,7 +46,7 @@ import { startDaemonControlAid } from './core/daemon-control.js';
|
|
|
46
46
|
import { createDelegationAuthorizer } from './core/auth/delegation-authorization.js';
|
|
47
47
|
import { registerProxyIpcExecutor } from './proxy/ipc-service.js';
|
|
48
48
|
import { ownerResolver, getDaemonOwners, getPrimaryOwner } from './core/ownership/owner-resolver.js';
|
|
49
|
-
import { StartupTaskQueue, StartupGate, discoverStartupWork,
|
|
49
|
+
import { StartupTaskQueue, StartupGate, discoverStartupWork, recoverStartupObserverHints, StartupHandoffRecovery, resumePendingSessions, createDaemonShutdown, daemonConversationTotalExecutionMs, daemonConversationWatchdogMs, daemonIdleTimeoutMs, startupTaskReadiness, } from './core/daemon-lifecycle.js';
|
|
50
50
|
import { createLifecycleNoticeService } from './core/lifecycle-notice.js';
|
|
51
51
|
import { BootstrapService, createBootstrapCompletionHandler, createBootstrapOwnerBoundHandler } from './core/bootstrap-service.js';
|
|
52
52
|
import { MessageCache } from './core/message/message-cache.js';
|
|
@@ -93,6 +93,8 @@ import { createDaemonEventCenter } from './event-center/daemon.js';
|
|
|
93
93
|
import { DaemonChannel } from './channels/daemon.js';
|
|
94
94
|
import { DAEMON_RUNTIME_EPOCH_ENV, ensureProcessManagedTempDir } from './cli/task-context.js';
|
|
95
95
|
import fs from 'fs';
|
|
96
|
+
import { createAgentTemplateRuntime, restoreTemplatesBeforeStartup } from './agent-template/runtime.js';
|
|
97
|
+
import { setAgentTemplateService } from './agent-template/service.js';
|
|
96
98
|
import crypto from 'crypto';
|
|
97
99
|
import { getBaseagentSnapshot, loadedBaseagentIds } from './agents/baseagent-availability.js';
|
|
98
100
|
import { createHostSnapshotProvider } from './core/host-snapshot.js';
|
|
@@ -333,9 +335,18 @@ async function main() {
|
|
|
333
335
|
return;
|
|
334
336
|
}
|
|
335
337
|
// ── EvolAgent Registry:加载 agents/<aid>/config.json ──
|
|
338
|
+
const templateStartupRecovery = await restoreTemplatesBeforeStartup(paths.root);
|
|
336
339
|
trace.mark('daemon.agentRegistry');
|
|
337
340
|
const agentRegistry = new EvolAgentRegistry(paths.agentsDir);
|
|
338
|
-
const {
|
|
341
|
+
const { runtimeStatus } = loadStartupAgentRegistry(agentRegistry);
|
|
342
|
+
for (const aid of new Set([...templateStartupRecovery.blocked, ...templateStartupRecovery.pending])) {
|
|
343
|
+
const agent = agentRegistry.get(aid);
|
|
344
|
+
if (agent) {
|
|
345
|
+
agent.status = 'disabled';
|
|
346
|
+
agent.error = 'Template installation requires recovery';
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
const primaryAgent = agentRegistry.runnableAgents()[0];
|
|
339
350
|
const teamWorkspaceManagementService = new TeamWorkspaceManagementService(new TeamWorkspaceBootstrapService());
|
|
340
351
|
let agentRuntimeState = runtimeStatus.state;
|
|
341
352
|
let agentRuntimeError = runtimeStatus.error;
|
|
@@ -401,6 +412,17 @@ async function main() {
|
|
|
401
412
|
primaryAid: primaryAgent?.aid, sessionsRoot: paths.sessionsDir, queuePath: daemonQueuePath(),
|
|
402
413
|
onQueueCaptured: capturedStartupQueue,
|
|
403
414
|
onScan: timing => { scanTimings.push(timing); },
|
|
415
|
+
onDiagnostics: timing => {
|
|
416
|
+
trace.setMeta('recoveryScan.eventLoop', JSON.stringify(timing));
|
|
417
|
+
logger.info(`[startup] Recovery scan event loop: active=${timing.loopActiveMs}ms idle=${timing.loopIdleMs}ms maxDelay=${timing.loopMaxMs}ms`);
|
|
418
|
+
},
|
|
419
|
+
onAgentPrioritized: (aid, reason) => {
|
|
420
|
+
if (startupCancelled)
|
|
421
|
+
return;
|
|
422
|
+
agentWorkPriority.set(aid, true);
|
|
423
|
+
agentWorkResolvers.get(aid)?.(true);
|
|
424
|
+
logger.info(`[startup] Recovery work identified: aid=${aid} source=${reason}; admitting Runner/AUN while scan continues`);
|
|
425
|
+
},
|
|
404
426
|
onAgentDiscovered: (aid, plan) => {
|
|
405
427
|
if (startupCancelled)
|
|
406
428
|
return;
|
|
@@ -409,7 +431,9 @@ async function main() {
|
|
|
409
431
|
agentWorkResolvers.get(aid)?.(priority);
|
|
410
432
|
logger.info(`[startup] Recovery scan: aid=${aid} priority=${priority} `
|
|
411
433
|
+ scanTimings.filter(timing => timing.aid === aid)
|
|
412
|
-
.map(timing => `${timing.phase}=${timing.durationMs}ms/${timing.files}`
|
|
434
|
+
.map(timing => `${timing.phase}=${timing.durationMs}ms/${timing.files}`
|
|
435
|
+
+ (timing.phase === 'sessions' ? ` [dirs=${timing.directoryMs}ms threads=${timing.threadDirectoryMs}ms`
|
|
436
|
+
+ ` metadata=${timing.metadataMs}ms readMax=${timing.readMaxMs}ms io=${JSON.stringify(timing.io)}]` : '')).join(' '));
|
|
413
437
|
},
|
|
414
438
|
}), undefined, { initialPhase: 'running' }).then(plan => {
|
|
415
439
|
discoveredStartupWork = plan;
|
|
@@ -610,10 +634,9 @@ async function main() {
|
|
|
610
634
|
trace.mark('daemon.channelCreate');
|
|
611
635
|
const channelLoader = new ChannelLoader(daemonCfg.debug, daemonCfg.aun?.defaultEncrypt);
|
|
612
636
|
await registerBuiltinChannelPlugins(channelLoader);
|
|
613
|
-
//
|
|
614
|
-
//
|
|
615
|
-
const connectionQueue = new StartupTaskQueue(2, 50
|
|
616
|
-
void priorityStartupGate.promise.then(() => connectionQueue.releaseBackground());
|
|
637
|
+
// Ready control/recovery connections take the next available slot. Idle AUN
|
|
638
|
+
// may use spare capacity without waiting for unrelated work classification.
|
|
639
|
+
const connectionQueue = new StartupTaskQueue(2, 50);
|
|
617
640
|
const schedulerQueue = new StartupTaskQueue(2, 50);
|
|
618
641
|
channelLoader.setConnectionAdmission(instance => connectionQueue.run(() => instance.connect(), () => !startupCancelled && !instance.lifecycle?.signal.aborted));
|
|
619
642
|
daemonPluginLifecycle.defer(() => { connectionQueue.stop(); schedulerQueue.stop(); }, 'startup admission');
|
|
@@ -739,6 +762,8 @@ async function main() {
|
|
|
739
762
|
processor.setInteractionRouter(interactionRouter);
|
|
740
763
|
// 创建消息队列
|
|
741
764
|
const startupHintsReady = new Set();
|
|
765
|
+
let startupHandoffRecovery;
|
|
766
|
+
let sessionIdleRestoreState = 'waiting';
|
|
742
767
|
const messageQueue = new MessageQueue(async (message) => {
|
|
743
768
|
const owner = message.selfAID || agentRegistry.resolveByChannel(message.channel)?.aid;
|
|
744
769
|
if (owner)
|
|
@@ -749,12 +774,15 @@ async function main() {
|
|
|
749
774
|
}, {
|
|
750
775
|
persistencePath: daemonQueuePath(),
|
|
751
776
|
dedupPath: daemonMessageDedupPath(),
|
|
752
|
-
blockedReason: message => {
|
|
777
|
+
blockedReason: (message, sessionId) => {
|
|
753
778
|
const aid = message.selfAID || agentRegistry.resolveByChannel(message.channel)?.aid;
|
|
754
779
|
if (!aid || !startupRunnerReady.has(aid))
|
|
755
780
|
return;
|
|
756
781
|
if (!startupHintsReady.has(aid))
|
|
757
782
|
return 'startup observer hint registration';
|
|
783
|
+
const handoffBlocked = startupHandoffRecovery?.blockedReason(aid, sessionId);
|
|
784
|
+
if (handoffBlocked)
|
|
785
|
+
return handoffBlocked;
|
|
758
786
|
const baseagent = message.baseagent || agentRegistry.get(aid)?.baseagent;
|
|
759
787
|
if (!activeRunnerSettledAgents.has(aid)
|
|
760
788
|
|| (baseagent && !agentMap.has(`${aid}::${baseagent}`) && !runnerSettledAgents.has(aid))) {
|
|
@@ -795,12 +823,27 @@ async function main() {
|
|
|
795
823
|
const handoffQueueTtlMs = daemonIdleTimeoutMs(globalSettings);
|
|
796
824
|
const taskExecutionTtlMs = daemonConversationTotalExecutionMs(globalSettings);
|
|
797
825
|
const handoffRuntime = new HandoffRuntime(sessionManager, messageQueue, createAunHandoffSender(sessionManager, channelInstances, sessionId => responseEngine.getOutboundDebug(sessionId)), undefined, { queueTtlMs: handoffQueueTtlMs });
|
|
826
|
+
startupHandoffRecovery = new StartupHandoffRecovery({
|
|
827
|
+
aids: startupAgents.map(agent => agent.aid), runtime: handoffRuntime, trace,
|
|
828
|
+
onProgress: () => messageQueue.startRestored(), isCancelled: () => startupCancelled,
|
|
829
|
+
});
|
|
798
830
|
responseEngine.setHandoffRuntime(handoffRuntime);
|
|
799
831
|
cmdHandler.setHandoffRuntime(handoffRuntime);
|
|
800
832
|
// Trigger runtime: daemon-level script + feedback scheduler.
|
|
801
833
|
const triggerSchedulers = new TriggerSchedulerRegistry();
|
|
802
834
|
// 事件中心(Event Center):文件驱动事件包,生命周期跟随 Trigger 调度器。
|
|
803
|
-
|
|
835
|
+
// 0.5.34 起复用 agent 主 AUN 连接(bus/pub/sub 同连接多角色),不再开专用 slot。
|
|
836
|
+
// 渠道重连会整个换掉 client 实例:这里必须每次动态读取、绝不缓存引用。
|
|
837
|
+
const eventCenter = createDaemonEventCenter({
|
|
838
|
+
triggerSchedulers,
|
|
839
|
+
agentRegistry,
|
|
840
|
+
getClient: aid => {
|
|
841
|
+
const instance = channelInstancesByAgent.get(aid)?.find(candidate => candidate.channelType === 'aun');
|
|
842
|
+
const channel = instance?.channel;
|
|
843
|
+
const client = typeof channel?.getClient === 'function' ? channel.getClient() : undefined;
|
|
844
|
+
return (client ?? null);
|
|
845
|
+
},
|
|
846
|
+
});
|
|
804
847
|
cmdHandler.setEventCenter(eventCenter);
|
|
805
848
|
// ECK 能力清单变量:只读两个运行时的内存包集合,不扫目录。
|
|
806
849
|
responseEngine.setCapabilityIndexes(selfAid => ({
|
|
@@ -1194,6 +1237,10 @@ async function main() {
|
|
|
1194
1237
|
optionalRelease: normalStartupGate.status,
|
|
1195
1238
|
ecweb: startupEcwebState === 'waiting' && ecwebSupervisor?.status().enabled ? 'waiting'
|
|
1196
1239
|
: startupEcwebState === 'failed' ? 'failed' : ecwebSupervisor?.status().state ?? 'disabled',
|
|
1240
|
+
backgroundRecovery: {
|
|
1241
|
+
handoff: startupHandoffRecovery?.status() ?? { completed: 0, total: triggerStartupAgents.length, retrying: 0 },
|
|
1242
|
+
sessionIdle: sessionIdleRestoreState,
|
|
1243
|
+
},
|
|
1197
1244
|
agents: startupAgents.map(agent => ({
|
|
1198
1245
|
aid: agent.aid, priority: agentWorkPriority.get(agent.aid) ?? false,
|
|
1199
1246
|
runner: agentMap.has(`${agent.aid}::${agent.baseagent}`) ? 'ready'
|
|
@@ -1360,6 +1407,38 @@ async function main() {
|
|
|
1360
1407
|
initializationServiceForOwnerRecovery = agentInitializationService;
|
|
1361
1408
|
agentApplicationService.setInitializationService(agentInitializationService);
|
|
1362
1409
|
cmdHandler.setAgentApplicationService(agentApplicationService);
|
|
1410
|
+
setAgentTemplateService(createAgentTemplateRuntime({
|
|
1411
|
+
registry: agentRegistry, coordinator: reloadCoordinator,
|
|
1412
|
+
reloadInsideGate: async (aid) => { await agentRegistry.reload(aid, reloadHooks); },
|
|
1413
|
+
getControl: () => controlChannel,
|
|
1414
|
+
waitForControl: async () => {
|
|
1415
|
+
const deadline = Date.now() + 60_000;
|
|
1416
|
+
while (!controlChannel?.isConnected() && Date.now() < deadline && !startupCancelled) {
|
|
1417
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
1418
|
+
}
|
|
1419
|
+
},
|
|
1420
|
+
getScheduler: aid => triggerSchedulers.get(aid),
|
|
1421
|
+
recoveryComplete: (aid, succeeded) => {
|
|
1422
|
+
if (succeeded && templateStartupRecovery.pending.has(aid)) {
|
|
1423
|
+
const agent = agentRegistry.get(aid);
|
|
1424
|
+
if (agent)
|
|
1425
|
+
messageQueue.unmuteAgent(agent.name);
|
|
1426
|
+
templateStartupRecovery.pending.delete(aid);
|
|
1427
|
+
}
|
|
1428
|
+
},
|
|
1429
|
+
block: aid => {
|
|
1430
|
+
const agent = agentRegistry.get(aid);
|
|
1431
|
+
if (agent) {
|
|
1432
|
+
agent.status = 'disabled';
|
|
1433
|
+
agent.error = 'Template installation requires recovery';
|
|
1434
|
+
}
|
|
1435
|
+
},
|
|
1436
|
+
}));
|
|
1437
|
+
for (const aid of templateStartupRecovery.pending) {
|
|
1438
|
+
const agent = agentRegistry.get(aid);
|
|
1439
|
+
if (agent)
|
|
1440
|
+
messageQueue.muteAgent(agent.name);
|
|
1441
|
+
}
|
|
1363
1442
|
ipcServer.setRemoteAccessOwnerProvider(() => processLevelOwners()[0]);
|
|
1364
1443
|
cmdHandler.setDaemonMonitorProvider(() => ipcServer.getMonitorSnapshot().snapshot);
|
|
1365
1444
|
cmdHandler.setDaemonHostProvider(() => hostProvider.getSnapshot());
|
|
@@ -1627,7 +1706,29 @@ async function main() {
|
|
|
1627
1706
|
sessionIdleMonitor.refreshTriggerIdentities();
|
|
1628
1707
|
});
|
|
1629
1708
|
}), undefined, { summary: true });
|
|
1630
|
-
|
|
1709
|
+
void trace.track('daemon.sessionIdleRestoreComplete', async (phase) => {
|
|
1710
|
+
let admitted = true;
|
|
1711
|
+
sessionIdleRestoreState = 'restoring';
|
|
1712
|
+
await sessionIdleMonitor.activate({
|
|
1713
|
+
waitForBackground: async () => {
|
|
1714
|
+
sessionIdleRestoreState = 'waiting';
|
|
1715
|
+
phase('waiting', 'normal Ready');
|
|
1716
|
+
admitted = await taskReadyGate.promise === 'ready' && !startupCancelled;
|
|
1717
|
+
if (admitted) {
|
|
1718
|
+
sessionIdleRestoreState = 'restoring';
|
|
1719
|
+
phase('running');
|
|
1720
|
+
}
|
|
1721
|
+
return admitted;
|
|
1722
|
+
},
|
|
1723
|
+
onRestored: (group, from, to, count) => {
|
|
1724
|
+
trace.addSpan(`daemon.sessionIdleRestore.${group}`, from, to, `sessions=${count}`, count ? 'ok' : 'skipped');
|
|
1725
|
+
trace.setMeta(`sessionIdleRestore.${group}`, String(count));
|
|
1726
|
+
},
|
|
1727
|
+
});
|
|
1728
|
+
sessionIdleRestoreState = startupCancelled || !admitted ? 'cancelled' : 'ready';
|
|
1729
|
+
if (sessionIdleRestoreState === 'cancelled')
|
|
1730
|
+
return false;
|
|
1731
|
+
}, undefined, { summary: true }).catch(error => logger.warn(`[startup] session idle restore failed: ${error}`));
|
|
1631
1732
|
relationIdleMonitor.start();
|
|
1632
1733
|
// 首轮 SDK 自动生成的会话名必须走与 `ec thread rename` 相同的出口:
|
|
1633
1734
|
// 更新话题索引、落盘并给对端发 `topic.renamed`。只调 `renameSession` 的话,
|
|
@@ -1665,41 +1766,43 @@ async function main() {
|
|
|
1665
1766
|
});
|
|
1666
1767
|
// 统一 channel:health 跨通道通知(仅 auth_error)
|
|
1667
1768
|
registerChannelHealthNotifications({ eventBus, channelInstances, agentRegistry });
|
|
1668
|
-
//
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1769
|
+
// Observer hints retain foreground precedence. Handoff history is scanned
|
|
1770
|
+
// only after actual task Ready and protects only its affected sessions.
|
|
1771
|
+
void trace.track('daemon.observerHintsComplete', () => recoverStartupObserverHints({
|
|
1772
|
+
channelInstances,
|
|
1773
|
+
recoveryAids: triggerStartupAgents.map(agent => agent.aid),
|
|
1774
|
+
agentRegistry,
|
|
1775
|
+
queuePendingObserverHints: (aid, channelKey) => queuePendingObserverHints(aid, channelKey, startupWork.hintDirectories.get(aid)),
|
|
1776
|
+
startupObserverRecoveries, trace,
|
|
1777
|
+
setStartupRecoveryPending: value => { startupRecoveryPending = value; },
|
|
1778
|
+
onAgentHintsRecovered: aid => {
|
|
1779
|
+
startupWork.hintDirectories.delete(aid);
|
|
1780
|
+
startupHintsReady.add(aid);
|
|
1781
|
+
messageQueue.startRestored();
|
|
1782
|
+
checkStartupTaskReady();
|
|
1783
|
+
},
|
|
1784
|
+
beforeAgentRecovery: async (aid) => {
|
|
1785
|
+
if (!startupWork.priorityAids.has(aid))
|
|
1786
|
+
await priorityStartupGate.promise;
|
|
1787
|
+
},
|
|
1788
|
+
isCancelled: () => startupCancelled,
|
|
1789
|
+
}), undefined, { summary: true })
|
|
1790
|
+
.catch(error => logger.error('[startup] observer hint registration failed:', error));
|
|
1791
|
+
void trace.track('daemon.handoffRecoveryComplete', async (phase) => {
|
|
1792
|
+
phase('waiting', 'normal Ready');
|
|
1793
|
+
let admitted = false;
|
|
1794
|
+
await startupHandoffRecovery.run(async () => {
|
|
1795
|
+
admitted = await taskReadyGate.promise === 'ready' && !startupCancelled;
|
|
1796
|
+
if (admitted) {
|
|
1797
|
+
phase('running');
|
|
1798
|
+
trace.point('daemon.handoffRecovery');
|
|
1799
|
+
}
|
|
1800
|
+
return admitted;
|
|
1699
1801
|
});
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1802
|
+
if (!admitted || startupCancelled)
|
|
1803
|
+
return false;
|
|
1804
|
+
}, undefined, { summary: true, initialPhase: 'waiting' })
|
|
1805
|
+
.catch(error => logger.error('[Handoff] background recovery coordinator failed:', error));
|
|
1703
1806
|
trace.point('daemon.resumeSessions');
|
|
1704
1807
|
const settleSessionRecovery = trace.startTask('daemon.resumeSessionsComplete', `sessions=${startupWork.pendingSessions.length}`, { summary: true });
|
|
1705
1808
|
if (!startupWork.pendingSessions.length)
|
package/dist/ipc.js
CHANGED
|
@@ -76,6 +76,7 @@ const LOCAL_CONTROL_COMMANDS = new Set([
|
|
|
76
76
|
'ecweb.ability',
|
|
77
77
|
'upgrade.op',
|
|
78
78
|
'provider.op',
|
|
79
|
+
'agent-template.op',
|
|
79
80
|
'invoke.op',
|
|
80
81
|
'ecweb.init',
|
|
81
82
|
'ecweb.basic-settings',
|
|
@@ -1963,8 +1964,8 @@ export class IpcServer {
|
|
|
1963
1964
|
timeoutMs: typeof cmd.timeoutMs === 'number' && Number.isFinite(cmd.timeoutMs) ? cmd.timeoutMs : undefined,
|
|
1964
1965
|
delegationToken: typeof cmd.delegationToken === 'string' ? cmd.delegationToken : undefined,
|
|
1965
1966
|
delegationCommandHash: typeof cmd.delegationCommandHash === 'string' ? cmd.delegationCommandHash : undefined,
|
|
1966
|
-
//
|
|
1967
|
-
// 用本机 controlToken
|
|
1967
|
+
// 非托管跨话题自派(`ecmsg send --from <self> --thread T --to <self>`)没有委托凭证,
|
|
1968
|
+
// 用本机 controlToken 证明「这是本机控制面调用」;只对跨话题自派生效,见 sender。
|
|
1968
1969
|
localControl: !cmd.delegationToken && this.hasValidControlToken(cmd.controlToken),
|
|
1969
1970
|
log,
|
|
1970
1971
|
});
|
|
@@ -2558,12 +2559,18 @@ export class IpcServer {
|
|
|
2558
2559
|
case 'events.op': {
|
|
2559
2560
|
if (!this.eventsOperationExecutor)
|
|
2560
2561
|
return { ok: false, code: 'NOT_CONFIGURED', error: 'events.op not configured' };
|
|
2561
|
-
return await this.eventsOperationExecutor(
|
|
2562
|
+
return await this.eventsOperationExecutor({
|
|
2563
|
+
...cmd,
|
|
2564
|
+
caller: this.packCaller(cmd),
|
|
2565
|
+
});
|
|
2562
2566
|
}
|
|
2563
2567
|
case 'services.op': {
|
|
2564
2568
|
if (!this.servicesOperationExecutor)
|
|
2565
2569
|
return { ok: false, code: 'NOT_CONFIGURED', error: 'services.op not configured' };
|
|
2566
|
-
return await this.servicesOperationExecutor(
|
|
2570
|
+
return await this.servicesOperationExecutor({
|
|
2571
|
+
...cmd,
|
|
2572
|
+
caller: this.packCaller(cmd),
|
|
2573
|
+
});
|
|
2567
2574
|
}
|
|
2568
2575
|
case 'evolagent.initialize': {
|
|
2569
2576
|
if (cmd.sessionId || cmd.delegationToken)
|
|
@@ -2584,6 +2591,19 @@ export class IpcServer {
|
|
|
2584
2591
|
}
|
|
2585
2592
|
return await this.agentOperationExecutor(argv, sessionId, delegationToken, typeof cmd.delegationCommandHash === 'string' ? cmd.delegationCommandHash : undefined);
|
|
2586
2593
|
}
|
|
2594
|
+
case 'agent-template.op': {
|
|
2595
|
+
if (cmd.sessionId !== undefined || cmd.delegationToken !== undefined)
|
|
2596
|
+
return { ok: false, code: 'NOT_ALLOWED', error: 'Managed template commands must use agent.op' };
|
|
2597
|
+
try {
|
|
2598
|
+
if (!Array.isArray(cmd.argv) || cmd.argv.some((arg) => typeof arg !== 'string'))
|
|
2599
|
+
throw new Error('argv required');
|
|
2600
|
+
const { executeHostTemplateCommand } = await import('./cli/agent-template.js');
|
|
2601
|
+
return await executeHostTemplateCommand(cmd.argv);
|
|
2602
|
+
}
|
|
2603
|
+
catch (error) {
|
|
2604
|
+
return { ok: false, code: error.code ?? 'INVALID_ARGUMENT', error: error.message };
|
|
2605
|
+
}
|
|
2606
|
+
}
|
|
2587
2607
|
case 'skill.refresh': {
|
|
2588
2608
|
if (!this.skillRefreshExecutor) {
|
|
2589
2609
|
return { ok: false, code: 'NOT_CONFIGURED', error: 'skill.refresh not configured' };
|
|
@@ -3049,6 +3069,26 @@ export class IpcServer {
|
|
|
3049
3069
|
}
|
|
3050
3070
|
catch { /* 触发失败不影响本次写入结果 */ }
|
|
3051
3071
|
}
|
|
3072
|
+
/**
|
|
3073
|
+
* 事件/服务运维命令的调用方身份。
|
|
3074
|
+
*
|
|
3075
|
+
* 主机终端(持有效 control token、无托管会话)→ local-control;
|
|
3076
|
+
* 其余按托管会话处理,角色取自该会话的 TaskRuntimeContext.peerRole。
|
|
3077
|
+
* 角色解析不出来时留空,由 `authorizePackTarget` 按最保守档拒绝管理类命令。
|
|
3078
|
+
*/
|
|
3079
|
+
packCaller(cmd) {
|
|
3080
|
+
const sessionId = typeof cmd.sessionId === 'string' && cmd.sessionId ? cmd.sessionId : undefined;
|
|
3081
|
+
const delegated = typeof cmd.delegationToken === 'string' && !!cmd.delegationToken;
|
|
3082
|
+
if (!sessionId && !delegated && this.hasValidControlToken(cmd.controlToken)) {
|
|
3083
|
+
return { kind: 'local-control' };
|
|
3084
|
+
}
|
|
3085
|
+
const context = sessionId ? this.taskRuntimeContextProvider?.({ sessionId }) : undefined;
|
|
3086
|
+
return {
|
|
3087
|
+
kind: 'managed',
|
|
3088
|
+
...(context?.selfAid ? { selfAid: context.selfAid } : {}),
|
|
3089
|
+
...(context?.peerRole ? { peerRole: context.peerRole } : {}),
|
|
3090
|
+
};
|
|
3091
|
+
}
|
|
3052
3092
|
hasValidControlToken(value) {
|
|
3053
3093
|
if (!this.controlToken || typeof value !== 'string')
|
|
3054
3094
|
return false;
|
package/dist/paths.js
CHANGED
|
@@ -260,11 +260,11 @@ export function channelStatePath(channelKey, ...parts) {
|
|
|
260
260
|
export function agentTriggersDir(aid) {
|
|
261
261
|
return path.join(agentDir(aid), 'triggers');
|
|
262
262
|
}
|
|
263
|
-
/** 事件中心目录:
|
|
263
|
+
/** 事件中心目录:events-config.json + 事件包(pack.json / ledger.jsonl / scripts/ / logs/)。 */
|
|
264
264
|
export function agentEventsDir(aid) {
|
|
265
265
|
return path.join(agentDir(aid), 'events');
|
|
266
266
|
}
|
|
267
|
-
/** 服务路由目录:
|
|
267
|
+
/** 服务路由目录:services-config.json 与服务包(pack.json / scripts/ / logs/ / ledger)。 */
|
|
268
268
|
export function agentServicesDir(aid) {
|
|
269
269
|
return path.join(agentDir(aid), 'services');
|
|
270
270
|
}
|
|
@@ -137,9 +137,11 @@ function hasSuccessfulSendReceipt(result, isError, requiresBusinessReturn = fals
|
|
|
137
137
|
return false;
|
|
138
138
|
}
|
|
139
139
|
function sendHint(state) {
|
|
140
|
+
// 提示与 `[reply]` 段、ECK 模板保持同一口径:正式回复统一写 `ecmsg send`。
|
|
141
|
+
// 私聊与群聊它会自己落到 `ec msg send` / `ec group send`,不必让模型两套写法轮换。
|
|
140
142
|
return state.chatType === 'group'
|
|
141
|
-
? { cmdHint: '
|
|
142
|
-
: { cmdHint: '
|
|
143
|
+
? { cmdHint: 'ecmsg send', target: '群里' }
|
|
144
|
+
: { cmdHint: 'ecmsg send', target: '对方' };
|
|
143
145
|
}
|
|
144
146
|
/**
|
|
145
147
|
* 结算当前轮:本轮有意图表达成功 → 清零(不再 +1);否则 +1。
|
package/dist/services/index.js
CHANGED
|
@@ -42,7 +42,7 @@ export class ServiceRouter {
|
|
|
42
42
|
this.scriptRunner = new ServiceScriptRunner(deps);
|
|
43
43
|
this.dispatcher = new ServiceDispatcher(this.scriptRunner, limits);
|
|
44
44
|
}
|
|
45
|
-
/** 首次加载:读
|
|
45
|
+
/** 首次加载:读 services-config.json + 扫描包。identity 必须已就绪。重复调用只更新 identity。 */
|
|
46
46
|
ensureStarted(identity) {
|
|
47
47
|
this.identity = identity;
|
|
48
48
|
if (this.started)
|
|
@@ -50,7 +50,7 @@ export class ServiceRouter {
|
|
|
50
50
|
this.reload();
|
|
51
51
|
this.started = true;
|
|
52
52
|
}
|
|
53
|
-
/** 重新加载
|
|
53
|
+
/** 重新加载 services-config.json 与全部包(ec services reload / 热重载用)。 */
|
|
54
54
|
reload() {
|
|
55
55
|
const router = loadRouterConfig(this.servicesDir);
|
|
56
56
|
this.config = router.config;
|
|
@@ -348,7 +348,7 @@ function readStringField(payload, key) {
|
|
|
348
348
|
/**
|
|
349
349
|
* 服务请求 payload 的 JSON Schema。
|
|
350
350
|
*
|
|
351
|
-
* 关键事实:`
|
|
351
|
+
* 关键事实:`pack.json` 不声明入参结构——参数完全由脚本自己解释,schema 无从得知。
|
|
352
352
|
* 因此这里给的是**信封**schema(type / request_id / data),`data` 保持开放对象,
|
|
353
353
|
* 并明确写出这一点,避免调用方以为有字段级约束。
|
|
354
354
|
*/
|