evolcore 0.0.45 → 0.0.47
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 +113 -0
- package/bin/ecmsg.js +33 -23
- package/dist/ability/application-service.js +1 -2
- package/dist/ability/package.js +28 -0
- package/dist/agent-template/jobs.js +158 -36
- package/dist/agent-template/runtime.js +401 -34
- package/dist/agent-template/service.js +764 -369
- package/dist/agent-template/tool-runner.js +35 -17
- package/dist/agent-template/types.js +7 -4
- package/dist/agents/baseagent.js +10 -9
- package/dist/agents/claude-runner.js +22 -6
- package/dist/agents/codex/app-server-client.js +34 -27
- package/dist/agents/codex/diagnostics.js +18 -1
- package/dist/agents/codex-runner.js +3 -1
- package/dist/agents/ecagent-runner.js +3 -1
- package/dist/agents/gemini-runner.js +2 -1
- package/dist/aun/group/fs-download.js +1 -1
- package/dist/aun/menu/client.js +142 -182
- package/dist/aun/rpc/client.js +33 -17
- package/dist/aun/service-proxy.js +6 -23
- package/dist/channels/aun.js +675 -120
- package/dist/channels/daemon.js +1 -1
- package/dist/cli/agent-create.js +37 -10
- package/dist/cli/agent-template.js +105 -84
- package/dist/cli/agent.js +31 -18
- package/dist/cli/daemon-commands.js +42 -56
- package/dist/cli/daemon-lifecycle-client.js +55 -19
- package/dist/cli/directory.js +12 -4
- package/dist/cli/ecmsg-gateway.js +5 -2
- package/dist/cli/events-command.js +2 -1
- package/dist/cli/init-channel.js +2 -2
- package/dist/cli/init.js +57 -21
- package/dist/cli/integrity-command.js +2 -0
- package/dist/cli/managed-command-guard.js +20 -1
- package/dist/cli/menu-client.js +7 -5
- package/dist/cli/restart-monitor.js +135 -46
- package/dist/cli/services-command.js +28 -5
- package/dist/cli/task-context.js +83 -15
- package/dist/cli/upgrade-command.js +4 -2
- package/dist/config/config-field-policy.js +24 -0
- package/dist/config/config-manager.js +49 -19
- package/dist/config/peer-book-store.js +167 -127
- package/dist/config/peer-role-resolver.js +24 -4
- package/dist/config/provider-identity-migration.js +158 -6
- package/dist/config/provider-identity.js +10 -4
- package/dist/config/provider-ipc-service.js +10 -2
- package/dist/config/provider-local-sync.js +2 -2
- package/dist/config/providers-config.js +95 -10
- package/dist/config/providers-import.js +4 -6
- package/dist/config/providers.js +14 -3
- package/dist/config/role-store.js +1 -1
- package/dist/config/schema-migration.js +123 -16
- package/dist/config/schema-registry.js +6 -2
- package/dist/config-store.js +9 -1
- package/dist/core/agent-application-service.js +56 -29
- package/dist/core/agent-create-status.js +3 -1
- package/dist/core/agent-creation-claim.js +1 -0
- package/dist/core/agent-ipc-registration.js +2 -2
- package/dist/core/agent-reload-coordinator.js +38 -1
- package/dist/core/agent-runtime.js +91 -43
- package/dist/core/auth/agent-delegation.js +13 -3
- package/dist/core/auth/delegation-diagnostics.js +56 -15
- package/dist/core/auth/operation-authorizer.js +2 -2
- package/dist/core/auth/operation-catalog.js +3 -3
- package/dist/core/bootstrap-service.js +3 -0
- package/dist/core/capability/capability-manager.js +3 -1
- package/dist/core/channel-loader.js +29 -3
- package/dist/core/channel-runtime.js +1 -1
- package/dist/core/command/agent-control.js +6 -5
- package/dist/core/command/agent-template-menu.js +32 -97
- package/dist/core/command/eventcenter-menu.js +61 -13
- package/dist/core/command/menu-catalog.js +11 -4
- package/dist/core/command/menu-handler.js +39 -12
- package/dist/core/command/menu-protocol.js +8 -16
- package/dist/core/command/skill-slash.js +6 -2
- package/dist/core/command/slash-handler.js +4 -6
- package/dist/core/command/team-workspace-bootstrap.js +1 -2
- package/dist/core/command/team-workspace-management-store.js +83 -0
- package/dist/core/command/team-workspace-management.js +1 -2
- package/dist/core/command/team-workspace-team.js +26 -3
- package/dist/core/daemon-bootstrap.js +11 -9
- package/dist/core/daemon-control.js +4 -7
- package/dist/core/daemon-lifecycle.js +189 -143
- package/dist/core/evolagent-registry.js +50 -2
- package/dist/core/evolagent.js +2 -1
- package/dist/core/file-integrity/read.js +9 -16
- package/dist/core/file-integrity/store.js +94 -34
- package/dist/core/handoff/dispatcher.js +33 -7
- package/dist/core/handoff/runtime.js +8 -0
- package/dist/core/host-snapshot.js +9 -4
- package/dist/core/inference/text-inference.js +12 -2
- package/dist/core/initialization/service.js +22 -4
- package/dist/core/invoke/invoke-service.js +24 -3
- package/dist/core/ipc-registration.js +7 -3
- package/dist/core/memory/consolidation.js +6 -6
- package/dist/core/message/aun-ipc-sender.js +109 -7
- package/dist/core/message/contact-admission.js +6 -2
- package/dist/core/message/message-bridge.js +13 -0
- package/dist/core/message/message-queue.js +131 -30
- package/dist/core/message/pending-hints.js +8 -0
- package/dist/core/message/response-engine.js +48 -2
- package/dist/core/message/send-routing.js +3 -12
- package/dist/core/model/catalog-service.js +13 -0
- package/dist/core/model/model-catalog.js +57 -18
- package/dist/core/ownership/owner-resolver.js +27 -10
- package/dist/core/pack-auth.js +163 -31
- package/dist/core/pack-install.js +42 -1
- package/dist/{services/ledger.js → core/pack-ledger.js} +17 -6
- package/dist/core/permission/ec-command-parser.js +3 -1
- package/dist/core/permission/shell-environment.js +23 -0
- package/dist/core/rate-window.js +6 -1
- package/dist/core/relation/peer-identity.js +5 -1
- package/dist/core/relation/same-owner-proof.js +2 -1
- package/dist/core/session/adapters/claude-session-file-adapter.js +1 -1
- package/dist/core/session/session-file-health.js +36 -7
- package/dist/core/session/session-idle-monitor.js +0 -1
- package/dist/core/session/session-manager.js +14 -0
- package/dist/core/session/session-title.js +26 -6
- package/dist/core/skill/index-generator.js +3 -4
- package/dist/core/task/task-image-resources.js +1 -1
- package/dist/core/thread/thread-service.js +0 -1
- package/dist/core/thread/topic-id.js +8 -0
- package/dist/directory/owner-directory-admission.js +17 -0
- package/dist/directory/owner-directory-cache.js +3 -1
- package/dist/directory/owner-directory-markdown.js +145 -23
- package/dist/directory/owner-directory-policy.js +23 -0
- package/dist/directory/owner-directory-query-operation.js +20 -6
- package/dist/directory/owner-directory-search.js +47 -0
- package/dist/eck/message-renderer.js +171 -32
- package/dist/ecweb/basic-settings-service.js +7 -3
- package/dist/ecweb/providers-service.js +17 -10
- package/dist/ecweb/runtime/lifecycle.js +65 -16
- package/dist/ecweb/runtime/supervisor.js +79 -50
- package/dist/event-center/admission-materializer.js +1 -1
- package/dist/event-center/bus-gate.js +48 -4
- package/dist/event-center/bus-host.js +3 -3
- package/dist/event-center/center-config.js +57 -28
- package/dist/event-center/dispatcher.js +8 -0
- package/dist/event-center/event-log.js +69 -27
- package/dist/event-center/index-generator.js +6 -1
- package/dist/event-center/ipc-operation.js +66 -25
- package/dist/event-center/pack-loader.js +12 -55
- package/dist/event-center/pack-manager.js +5 -3
- package/dist/event-center/registry.js +48 -52
- package/dist/event-center/runtime.js +219 -81
- package/dist/event-center/script-runner.js +18 -7
- package/dist/event-center/types.js +9 -1
- package/dist/event-center/validation.js +33 -4
- package/dist/index.js +132 -75
- package/dist/ipc.js +35 -8
- package/dist/product.js +1 -0
- package/dist/proxy/manager.js +52 -11
- package/dist/proxy/service-supervisor.js +265 -67
- package/dist/services/dispatcher.js +26 -3
- package/dist/services/idempotency.js +128 -0
- package/dist/services/identity.js +3 -27
- package/dist/services/index-generator.js +5 -1
- package/dist/services/index.js +244 -45
- package/dist/services/ipc-operation.js +164 -20
- package/dist/services/pack-manager.js +37 -9
- package/dist/services/router.js +100 -31
- package/dist/services/script-runner.js +15 -4
- package/dist/services/service-payload.js +50 -2
- package/dist/services/validation.js +107 -3
- package/dist/trigger/scheduler.js +18 -4
- package/dist/trigger/script-sandbox.js +39 -2
- package/dist/trigger/state.js +7 -0
- package/dist/utils/aid-bind.js +155 -18
- package/dist/utils/atomic-write.js +3 -3
- package/dist/utils/cross-platform.js +59 -16
- package/dist/utils/error-utils.js +26 -1
- package/dist/utils/instance-registry.js +94 -35
- package/dist/utils/process-introspect.js +187 -27
- package/dist/utils/project-path.js +47 -3
- package/dist/utils/upgrade-jobs.js +4 -4
- package/dist/utils/windows-shell-trust.js +174 -68
- package/kits/docs/context-assembly.md +3 -3
- package/kits/docs/evolcore/agent.md +28 -10
- package/kits/docs/evolcore/aid.md +3 -1
- package/kits/docs/evolcore/config.md +22 -0
- package/kits/docs/evolcore/directory.md +46 -12
- package/kits/docs/evolcore/event-center.md +6 -6
- package/kits/docs/evolcore/group-collaboration.md +1 -1
- package/kits/docs/evolcore/menu-client.md +7 -5
- package/kits/docs/evolcore/menu-protocol.md +5 -3
- package/kits/docs/evolcore/msg.md +10 -3
- package/kits/docs/evolcore/provider.md +17 -5
- package/kits/docs/evolcore/services.md +145 -12
- package/kits/docs/evolcore/thread-chain.md +17 -9
- package/kits/docs/prompt-loading-architecture.md +4 -4
- package/kits/eck_message_manifest.json +46 -3
- package/kits/rules/04-relation.md +10 -2
- package/kits/rules/06-channel.md +2 -1
- package/kits/schemas/providers.schema.2.json +1 -0
- package/kits/skills/ec-group/SKILL.md +4 -0
- package/kits/skills/ec-skill/scripts/cli.mjs +1 -1
- package/kits/skills/ec-skill/scripts/skill.mjs +13 -2
- package/kits/skills/thread-ops/SKILL.md +8 -5
- package/kits/templates/message-fragments/group-batch-item.md +3 -0
- package/kits/templates/message-fragments/group-batch.md +1 -0
- package/kits/templates/message-fragments/item-group.md +4 -0
- package/kits/templates/message-fragments/item-private.md +4 -0
- package/kits/templates/message-fragments/thread-context.md +1 -1
- package/kits/templates/system-fragments/commands.md +5 -5
- package/kits/templates/system-fragments/managed-runtime.md +1 -1
- package/kits/templates/system-fragments/relation.md +11 -7
- package/package.json +3 -2
- package/scripts/agent-template/index.mjs +9 -4
- package/scripts/agent-template/inspect.mjs +16 -9
- package/scripts/agent-template/shared/plan.mjs +3 -33
- package/scripts/agent-template/shared/template-contract.mjs +186 -3
- package/scripts/agent-template/shared/template-package.mjs +119 -10
- package/scripts/agent-template/shared/template-runtime.mjs +49 -6
- package/scripts/agent-template/shared/template.mjs +5 -5
- package/scripts/agent-template/team-pack.mjs +245 -0
- package/scripts/agent-template/team-preview.mjs +111 -0
- package/scripts/aid-batch/identity-batch.mjs +143 -0
- package/dist/ability/versions.js +0 -32
- package/dist/aun/model-headers.js +0 -17
- package/dist/channels/builtin-plugins.js +0 -19
- package/dist/core/command/team-workspace-initializer.js +0 -2
- package/dist/core/command/team-workspace-job-store.js +0 -88
- package/dist/core/command/team-workspace-management-service.js +0 -2
- package/dist/core/contact-bind-registry.js +0 -27
- package/dist/event-center/ledger.js +0 -52
- package/dist/services/reply.js +0 -55
- package/kits/templates/message-fragments/item.md +0 -3
- package/scripts/agent-template/pack.mjs +0 -169
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// 【重要】最先加载环境变量,确保后续模块初始化时可用
|
|
2
2
|
import dotenv from 'dotenv';
|
|
3
3
|
import path from 'path';
|
|
4
|
+
import { resolveProjectDefaultPath } from './utils/project-path.js';
|
|
4
5
|
import { ensureDataDirs, resolvePaths, eckDebugDir, daemonControlDir, daemonQueuePath, daemonMessageDedupPath, isDevMode } from './paths.js';
|
|
5
6
|
// 立即加载 .env 文件(在其他模块导入之前)
|
|
6
7
|
try {
|
|
@@ -31,13 +32,15 @@ import { GeminiAgentPlugin } from './agents/gemini-runner.js';
|
|
|
31
32
|
// 不要静态导入 ecagent-runner:它连带整个 ecagent 运行时(typebox 占了模块图
|
|
32
33
|
// 三分之一的 resolve),而绝大多数部署并不使用 ecagent。这里用懒加载外壳。
|
|
33
34
|
import { EcagentAgentPluginLazy } from './agents/ecagent-plugin-lazy.js';
|
|
34
|
-
import {
|
|
35
|
+
import { AUNChannelPlugin } from './channels/aun.js';
|
|
35
36
|
import { registerAbilityPlatform } from './ability/daemon.js';
|
|
36
37
|
import { assertAunEncryptionSeedPolicy } from './aun/aid/encryption-seed-policy.js';
|
|
37
38
|
import { BindService } from './utils/aid-bind.js';
|
|
39
|
+
import { ecwebInitializationService } from './core/initialization/service.js';
|
|
38
40
|
import { buildEnvelope } from './core/message/message-utils.js';
|
|
39
41
|
import { ResponseEngine } from './core/message/response-engine.js';
|
|
40
42
|
import { MessageQueue } from './core/message/message-queue.js';
|
|
43
|
+
import { wasInterruptHintConsumed } from './core/message/pending-hints.js';
|
|
41
44
|
import { MessageBridge } from './core/message/message-bridge.js';
|
|
42
45
|
import { readFastaunVersion, readInstalledEvolcoreVersion, createEvolcoreStartupDiagnostics, reportEvolcoreStartup, } from './utils/evolcore-version.js';
|
|
43
46
|
import { recoverAllRoleMutationsSync } from './core/command/role-menu.js';
|
|
@@ -46,7 +49,7 @@ import { startDaemonControlAid } from './core/daemon-control.js';
|
|
|
46
49
|
import { createDelegationAuthorizer } from './core/auth/delegation-authorization.js';
|
|
47
50
|
import { registerProxyIpcExecutor } from './proxy/ipc-service.js';
|
|
48
51
|
import { ownerResolver, getDaemonOwners, getPrimaryOwner } from './core/ownership/owner-resolver.js';
|
|
49
|
-
import { StartupTaskQueue, StartupGate, discoverStartupWork, recoverStartupObserverHints, StartupHandoffRecovery, resumePendingSessions, createDaemonShutdown, daemonConversationTotalExecutionMs, daemonConversationWatchdogMs, daemonIdleTimeoutMs, startupTaskReadiness, } from './core/daemon-lifecycle.js';
|
|
52
|
+
import { StartupTaskQueue, startupConnectionBudget, StartupGate, discoverStartupWork, recoverStartupObserverHints, StartupHandoffRecovery, resumePendingSessions, createDaemonShutdown, daemonConversationTotalExecutionMs, daemonConversationWatchdogMs, daemonIdleTimeoutMs, startupTaskReadiness, } from './core/daemon-lifecycle.js';
|
|
50
53
|
import { createLifecycleNoticeService } from './core/lifecycle-notice.js';
|
|
51
54
|
import { BootstrapService, createBootstrapCompletionHandler, createBootstrapOwnerBoundHandler } from './core/bootstrap-service.js';
|
|
52
55
|
import { MessageCache } from './core/message/message-cache.js';
|
|
@@ -123,10 +126,6 @@ async function main() {
|
|
|
123
126
|
// managed root before any runner or task runtime is initialized.
|
|
124
127
|
ensureProcessManagedTempDir();
|
|
125
128
|
const buildDiagnostics = createEvolcoreStartupDiagnostics(import.meta.url);
|
|
126
|
-
void trace.track('daemon.versionReport', () => reportEvolcoreStartup(import.meta.url, message => logger.info(message), buildDiagnostics), undefined, { initialPhase: 'running' }).catch(error => {
|
|
127
|
-
buildDiagnostics.state = 'unavailable';
|
|
128
|
-
logger.warn(`[Build] startup diagnostics unavailable: ${error instanceof Error ? error.message : String(error)}`);
|
|
129
|
-
});
|
|
130
129
|
trace.mark('daemon.sdkFilter');
|
|
131
130
|
installChannelSdkConsoleFilter();
|
|
132
131
|
console.error('[EvolCore] ✓ Console filter installed');
|
|
@@ -261,22 +260,35 @@ async function main() {
|
|
|
261
260
|
let startupCancelled = false;
|
|
262
261
|
let cancelStartupClassification = () => { };
|
|
263
262
|
let normalTaskState = 'pending';
|
|
264
|
-
let startupEcwebState = 'waiting';
|
|
265
263
|
const priorityStartupGate = new StartupGate();
|
|
266
264
|
const normalStartupGate = new StartupGate();
|
|
267
|
-
// Audit needs genuine task Ready; optional services can also start degraded.
|
|
268
|
-
const taskReadyGate = new StartupGate();
|
|
269
265
|
const waitForBackgroundStartup = async () => await normalStartupGate.promise !== 'cancelled' && !startupCancelled;
|
|
270
266
|
onShutdown(() => {
|
|
271
267
|
startupCancelled = true;
|
|
272
268
|
cancelStartupClassification();
|
|
273
269
|
priorityStartupGate.settle('cancelled');
|
|
274
270
|
normalStartupGate.settle('cancelled');
|
|
275
|
-
|
|
271
|
+
});
|
|
272
|
+
// Full-tree build hashing is diagnostic I/O, not a prerequisite for tasks.
|
|
273
|
+
// Keep status pending until the background release instead of competing
|
|
274
|
+
// with recovery metadata reads. Bootstrap-only daemons have no task gate.
|
|
275
|
+
void trace.track('daemon.versionReport', async (phase) => {
|
|
276
|
+
if (!bindBootstrapMode) {
|
|
277
|
+
phase('waiting', 'normal Ready');
|
|
278
|
+
if (!await waitForBackgroundStartup())
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
phase('running');
|
|
282
|
+
return reportEvolcoreStartup(import.meta.url, message => logger.info(message), buildDiagnostics);
|
|
283
|
+
}, undefined, { initialPhase: 'waiting' }).catch(error => {
|
|
284
|
+
buildDiagnostics.state = 'unavailable';
|
|
285
|
+
logger.warn(`[Build] startup diagnostics unavailable: ${error instanceof Error ? error.message : String(error)}`);
|
|
276
286
|
});
|
|
277
287
|
// ECWeb has one lifecycle owner: the daemon. The CLI may have started an
|
|
278
288
|
// instance just before spawning us; the supervisor adopts it when healthy,
|
|
279
289
|
// otherwise starts one and keeps it alive for the daemon's lifetime.
|
|
290
|
+
// Start independently once its configuration is loaded; Agent readiness
|
|
291
|
+
// does not gate the UI, and HTTP health does not gate task readiness.
|
|
280
292
|
trace.mark('daemon.ecwebSupervisor');
|
|
281
293
|
let ecwebSupervisor = null;
|
|
282
294
|
const ecwebConfig = ecwebService(daemonCfg.services);
|
|
@@ -292,20 +304,16 @@ async function main() {
|
|
|
292
304
|
});
|
|
293
305
|
onShutdown(() => ecwebSupervisor?.stop());
|
|
294
306
|
const removeEcwebConfigListener = onConfigWrite(({ target }) => {
|
|
295
|
-
if (target !== ConfigTarget.Process || !ecwebSupervisor)
|
|
307
|
+
if (startupCancelled || target !== ConfigTarget.Process || !ecwebSupervisor)
|
|
296
308
|
return;
|
|
297
309
|
try {
|
|
298
310
|
const service = ecwebService(loadDaemonConfig().services);
|
|
299
|
-
void
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
runtimeMode: service ? serviceRuntimeMode(service) : 'managed',
|
|
306
|
-
restart: service?.runtime?.restart,
|
|
307
|
-
health: service?.health,
|
|
308
|
-
});
|
|
311
|
+
void ecwebSupervisor.configure({
|
|
312
|
+
enabled: service?.enabled === true,
|
|
313
|
+
port: service?.port ?? DEFAULT_ECWEB_PORT,
|
|
314
|
+
runtimeMode: service ? serviceRuntimeMode(service) : 'managed',
|
|
315
|
+
restart: service?.runtime?.restart,
|
|
316
|
+
health: service?.health,
|
|
309
317
|
}).catch((error) => logger.warn(`ECWeb 配置热应用失败: ${error?.message || error}`));
|
|
310
318
|
}
|
|
311
319
|
catch (error) {
|
|
@@ -313,25 +321,19 @@ async function main() {
|
|
|
313
321
|
}
|
|
314
322
|
});
|
|
315
323
|
onShutdown(removeEcwebConfigListener);
|
|
316
|
-
void trace.track('daemon.ecwebLaunch', async (
|
|
317
|
-
phase('waiting', 'priority Ready');
|
|
318
|
-
await priorityStartupGate.promise;
|
|
324
|
+
void trace.track('daemon.ecwebLaunch', async () => {
|
|
319
325
|
if (startupCancelled)
|
|
320
326
|
return false;
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
startupEcwebState = 'starting';
|
|
324
|
-
await ecwebSupervisor.start();
|
|
325
|
-
startupEcwebState = 'ready';
|
|
326
|
-
}
|
|
327
|
-
}, undefined, { initialPhase: 'waiting' }).catch((error) => {
|
|
328
|
-
startupEcwebState = 'failed';
|
|
327
|
+
await ecwebSupervisor.start();
|
|
328
|
+
}, undefined, { initialPhase: 'running' }).catch((error) => {
|
|
329
329
|
logger.warn(`ECWeb supervisor 启动失败(不影响 daemon 主流程): ${error?.message || error}`);
|
|
330
330
|
});
|
|
331
331
|
}
|
|
332
332
|
if (bindBootstrapMode && process.env.EVOLCORE_WEB_INIT !== '1' && daemonCfg.aid && loadAllAgents().agents.length === 0) {
|
|
333
333
|
priorityStartupGate.settle('ready');
|
|
334
334
|
await runBindBootstrapDaemon(daemonCfg);
|
|
335
|
+
// The pairing-only daemon has no Agent task gate.
|
|
336
|
+
normalStartupGate.settle('ready');
|
|
335
337
|
return;
|
|
336
338
|
}
|
|
337
339
|
// ── EvolAgent Registry:加载 agents/<aid>/config.json ──
|
|
@@ -395,6 +397,7 @@ async function main() {
|
|
|
395
397
|
sessionManager.registerFileAdapter(new GeminiSessionFileAdapter());
|
|
396
398
|
sessionManager.registerFileAdapter(new EcagentSessionFileAdapter());
|
|
397
399
|
let capturedStartupQueue;
|
|
400
|
+
let startupQueueSnapshot;
|
|
398
401
|
const startupQueueCaptured = new Promise(resolve => { capturedStartupQueue = resolve; });
|
|
399
402
|
let discoveredStartupWork;
|
|
400
403
|
const agentWorkPriority = new Map();
|
|
@@ -410,7 +413,7 @@ async function main() {
|
|
|
410
413
|
const startupWorkPromise = trace.track('daemon.startupWorkDiscovery', () => discoverStartupWork({
|
|
411
414
|
agentAids: startupAgents.map(agent => agent.aid), daemonTriggerAid,
|
|
412
415
|
primaryAid: primaryAgent?.aid, sessionsRoot: paths.sessionsDir, queuePath: daemonQueuePath(),
|
|
413
|
-
onQueueCaptured: capturedStartupQueue,
|
|
416
|
+
onQueueCaptured: snapshot => { startupQueueSnapshot = snapshot; capturedStartupQueue(); },
|
|
414
417
|
onScan: timing => { scanTimings.push(timing); },
|
|
415
418
|
onDiagnostics: timing => {
|
|
416
419
|
trace.setMeta('recoveryScan.eventLoop', JSON.stringify(timing));
|
|
@@ -421,7 +424,7 @@ async function main() {
|
|
|
421
424
|
return;
|
|
422
425
|
agentWorkPriority.set(aid, true);
|
|
423
426
|
agentWorkResolvers.get(aid)?.(true);
|
|
424
|
-
logger.info(`[startup] Recovery work identified: aid=${aid} source=${reason}; admitting Runner
|
|
427
|
+
logger.info(`[startup] Recovery work identified: aid=${aid} source=${reason}; admitting Runner while scan continues`);
|
|
425
428
|
},
|
|
426
429
|
onAgentDiscovered: (aid, plan) => {
|
|
427
430
|
if (startupCancelled)
|
|
@@ -517,7 +520,7 @@ async function main() {
|
|
|
517
520
|
baseagent.loaded = loaded.has(baseagent.id);
|
|
518
521
|
};
|
|
519
522
|
let configureRunnerCallbacks;
|
|
520
|
-
const agentDelegationRegistry =
|
|
523
|
+
const agentDelegationRegistry = await AgentDelegationRegistry.createAsync();
|
|
521
524
|
process.env[DAEMON_RUNTIME_EPOCH_ENV] = agentDelegationRegistry.getRuntimeEpoch();
|
|
522
525
|
const startupRunnersStartedAtMs = Date.now();
|
|
523
526
|
trace.mark('daemon.agentRunnerDispatch');
|
|
@@ -636,7 +639,10 @@ async function main() {
|
|
|
636
639
|
await registerBuiltinChannelPlugins(channelLoader);
|
|
637
640
|
// Ready control/recovery connections take the next available slot. Idle AUN
|
|
638
641
|
// may use spare capacity without waiting for unrelated work classification.
|
|
639
|
-
const
|
|
642
|
+
const connectionBudget = startupConnectionBudget();
|
|
643
|
+
trace.setMeta('connectionAdmission', JSON.stringify({ ...connectionBudget, intervalMs: 50 }));
|
|
644
|
+
logger.info(`[startup] Channel connection admission: cpuParallelism=${connectionBudget.cpuParallelism} concurrency=${connectionBudget.concurrency} intervalMs=50`);
|
|
645
|
+
const connectionQueue = new StartupTaskQueue(connectionBudget.concurrency, 50);
|
|
640
646
|
const schedulerQueue = new StartupTaskQueue(2, 50);
|
|
641
647
|
channelLoader.setConnectionAdmission(instance => connectionQueue.run(() => instance.connect(), () => !startupCancelled && !instance.lifecycle?.signal.aborted));
|
|
642
648
|
daemonPluginLifecycle.defer(() => { connectionQueue.stop(); schedulerQueue.stop(); }, 'startup admission');
|
|
@@ -674,6 +680,7 @@ async function main() {
|
|
|
674
680
|
receiverAid: daemonCfg.aid,
|
|
675
681
|
getAvailableBaseagents: detectAvailableBaseagents,
|
|
676
682
|
getUptimeSeconds: () => Math.floor(process.uptime()),
|
|
683
|
+
handleAppBindRequest: (payload, senderAid, encrypted) => ecwebInitializationService.handleAppBindRequest(payload, senderAid, encrypted),
|
|
677
684
|
})
|
|
678
685
|
: null;
|
|
679
686
|
bindService?.startCleanup();
|
|
@@ -682,6 +689,8 @@ async function main() {
|
|
|
682
689
|
});
|
|
683
690
|
let initializationServiceForOwnerRecovery;
|
|
684
691
|
const stopOwnerNotifications = ownerResolver.onChange((subjectAid, ownerAid) => {
|
|
692
|
+
if (startupCancelled)
|
|
693
|
+
return;
|
|
685
694
|
permissionGateway.revalidatePendingApprovals(subjectAid);
|
|
686
695
|
if (agentRegistry.get(subjectAid)) {
|
|
687
696
|
try {
|
|
@@ -762,6 +771,7 @@ async function main() {
|
|
|
762
771
|
processor.setInteractionRouter(interactionRouter);
|
|
763
772
|
// 创建消息队列
|
|
764
773
|
const startupHintsReady = new Set();
|
|
774
|
+
const startupSessionsReady = new Set();
|
|
765
775
|
let startupHandoffRecovery;
|
|
766
776
|
let sessionIdleRestoreState = 'waiting';
|
|
767
777
|
const messageQueue = new MessageQueue(async (message) => {
|
|
@@ -774,12 +784,15 @@ async function main() {
|
|
|
774
784
|
}, {
|
|
775
785
|
persistencePath: daemonQueuePath(),
|
|
776
786
|
dedupPath: daemonMessageDedupPath(),
|
|
787
|
+
wasObserverHintConsumed: message => wasInterruptHintConsumed(paths.sessionsDir, message),
|
|
777
788
|
blockedReason: (message, sessionId) => {
|
|
778
789
|
const aid = message.selfAID || agentRegistry.resolveByChannel(message.channel)?.aid;
|
|
779
790
|
if (!aid || !startupRunnerReady.has(aid))
|
|
780
791
|
return;
|
|
781
792
|
if (!startupHintsReady.has(aid))
|
|
782
793
|
return 'startup observer hint registration';
|
|
794
|
+
if (!startupSessionsReady.has(aid))
|
|
795
|
+
return 'startup session recovery registration';
|
|
783
796
|
const handoffBlocked = startupHandoffRecovery?.blockedReason(aid, sessionId);
|
|
784
797
|
if (handoffBlocked)
|
|
785
798
|
return handoffBlocked;
|
|
@@ -813,7 +826,18 @@ async function main() {
|
|
|
813
826
|
// is deliberately dropped here and reclaimed from active.json by its scheduler.
|
|
814
827
|
// Capture queued inputs before restorePersisted rewrites their snapshot.
|
|
815
828
|
await startupQueueCaptured;
|
|
816
|
-
|
|
829
|
+
if (startupQueueSnapshot) {
|
|
830
|
+
for (const bucket of [...startupQueueSnapshot.queues, ...(startupQueueSnapshot.active ?? [])]) {
|
|
831
|
+
for (const item of bucket.items) {
|
|
832
|
+
const message = item.message;
|
|
833
|
+
const parts = bucket.queueKey.split('::');
|
|
834
|
+
const sessionId = message.boundSessionId || (parts.length >= 3 ? parts[1] : parts[0]);
|
|
835
|
+
sessionManager.registerSessionRoute(sessionId, message);
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
// An unreadable snapshot must fail restoration, never be overwritten as an empty queue.
|
|
840
|
+
messageQueue.restorePersisted(false, startupQueueSnapshot);
|
|
817
841
|
const droppedTriggerSessionIds = new Set(messageQueue.consumeDroppedTriggerSessionIds());
|
|
818
842
|
// 进程退出时立即刷盘队列状态(防止 debounce 期间的消息丢失)
|
|
819
843
|
onShutdown(() => messageQueue.persistQueuesImmediate());
|
|
@@ -1028,7 +1052,6 @@ async function main() {
|
|
|
1028
1052
|
};
|
|
1029
1053
|
const startupTriggerReady = new Set();
|
|
1030
1054
|
const startupTriggerFailed = new Set();
|
|
1031
|
-
const startupSessionsReady = new Set();
|
|
1032
1055
|
const startupTriggerPromises = new Map();
|
|
1033
1056
|
const defaultPolicy = createDefaultChannelPolicy();
|
|
1034
1057
|
processor.registerChannel(daemonChannel, defaultPolicy, { channelType: 'daemon' });
|
|
@@ -1037,7 +1060,7 @@ async function main() {
|
|
|
1037
1060
|
// ── MessageBridge:Channel ↔ Core 消息桥梁 ──
|
|
1038
1061
|
trace.mark('daemon.messageBridge');
|
|
1039
1062
|
const defaultProjectPath = primaryAgent?.projectPath
|
|
1040
|
-
?? defaults.projects?.defaultPath
|
|
1063
|
+
?? resolveProjectDefaultPath(defaults.projects?.defaultPath)
|
|
1041
1064
|
?? path.join(paths.root, 'projects', 'default');
|
|
1042
1065
|
const isContactBindChannelReady = (channelKey) => {
|
|
1043
1066
|
const inst = channelInstances.find(candidate => candidate.adapter.channelKey === channelKey);
|
|
@@ -1141,7 +1164,7 @@ async function main() {
|
|
|
1141
1164
|
sendLifecycleNoticeForChannel: instance => lifecycleNotices.online(instance),
|
|
1142
1165
|
trySendPendingRestartNotice,
|
|
1143
1166
|
sessionsDir: paths.sessionsDir,
|
|
1144
|
-
isStartupRecoveryPending:
|
|
1167
|
+
isStartupRecoveryPending: aid => startupRecoveryPending && !startupHintsReady.has(aid),
|
|
1145
1168
|
isCancelled: () => startupCancelled,
|
|
1146
1169
|
refreshAunAuthorization: async (aid) => {
|
|
1147
1170
|
const view = await ownerResolver.refresh(aid, { source: 'startup' });
|
|
@@ -1169,12 +1192,11 @@ async function main() {
|
|
|
1169
1192
|
let pendingShutdownTraceId;
|
|
1170
1193
|
trace.mark('daemon.baseagentProbe');
|
|
1171
1194
|
refreshLoadedBaseagents();
|
|
1172
|
-
const getStatusSnapshot = () => {
|
|
1195
|
+
const getStatusSnapshot = (agents) => {
|
|
1173
1196
|
const now = Date.now();
|
|
1174
1197
|
const todayStart = new Date(new Date(now).getFullYear(), new Date(now).getMonth(), new Date(now).getDate()).getTime();
|
|
1175
1198
|
const lastHour = queryStatusActivity(paths.root, now - 3_600_000, now);
|
|
1176
1199
|
const today = queryStatusActivity(paths.root, todayStart, now);
|
|
1177
|
-
const agents = agentRegistry.list();
|
|
1178
1200
|
const usageByAgent = queryStatusActivityByAgent(paths.root, todayStart, now, agents.map(agent => agent.aid));
|
|
1179
1201
|
return {
|
|
1180
1202
|
activity: { lastHour, today },
|
|
@@ -1205,7 +1227,7 @@ async function main() {
|
|
|
1205
1227
|
};
|
|
1206
1228
|
};
|
|
1207
1229
|
// 主机信息唯一出口:CLI、菜单、ecweb 都读这一份,别各自探测。
|
|
1208
|
-
//
|
|
1230
|
+
// 启动时先提供缓存;版本与虚拟化探测的子进程在正常 Ready 后刷新。
|
|
1209
1231
|
const hostProvider = createHostSnapshotProvider({
|
|
1210
1232
|
messageQueue,
|
|
1211
1233
|
statsCollector,
|
|
@@ -1214,11 +1236,16 @@ async function main() {
|
|
|
1214
1236
|
runMode: devMode ? 'dev' : 'install',
|
|
1215
1237
|
getSystemCpuPercent: () => ipcServer.getSystemCpuPercent(),
|
|
1216
1238
|
getControlAidState: () => controlChannel?.getAidState(),
|
|
1239
|
+
autoProbe: false,
|
|
1217
1240
|
});
|
|
1241
|
+
void waitForBackgroundStartup().then(admitted => {
|
|
1242
|
+
if (admitted)
|
|
1243
|
+
return hostProvider.refresh();
|
|
1244
|
+
}).catch(error => logger.warn(`[HostSnapshot] background probe failed: ${error}`));
|
|
1218
1245
|
trace.mark('daemon.ipcCreate');
|
|
1219
1246
|
const ipcServer = new IpcServer(resolvePaths().socket, createIpcStatusProvider({
|
|
1220
1247
|
channelInstances,
|
|
1221
|
-
getChannelRuntimeSnapshot:
|
|
1248
|
+
getChannelRuntimeSnapshot: agents => channelLoader.getSnapshot(agents.flatMap(info => {
|
|
1222
1249
|
const agent = agentRegistry.get(info.aid);
|
|
1223
1250
|
return agent ? [agent] : [];
|
|
1224
1251
|
})),
|
|
@@ -1235,8 +1262,7 @@ async function main() {
|
|
|
1235
1262
|
: priorityStartupGate.status === 'pending' ? 'recovering' : 'loading',
|
|
1236
1263
|
priorityRelease: priorityStartupGate.status,
|
|
1237
1264
|
optionalRelease: normalStartupGate.status,
|
|
1238
|
-
ecweb:
|
|
1239
|
-
: startupEcwebState === 'failed' ? 'failed' : ecwebSupervisor?.status().state ?? 'disabled',
|
|
1265
|
+
ecweb: ecwebSupervisor?.status().state ?? 'disabled',
|
|
1240
1266
|
backgroundRecovery: {
|
|
1241
1267
|
handoff: startupHandoffRecovery?.status() ?? { completed: 0, total: triggerStartupAgents.length, retrying: 0 },
|
|
1242
1268
|
sessionIdle: sessionIdleRestoreState,
|
|
@@ -1258,7 +1284,7 @@ async function main() {
|
|
|
1258
1284
|
}),
|
|
1259
1285
|
daemonAid: daemonCfg.aid,
|
|
1260
1286
|
getControlAidState: () => controlChannel?.getAidState(),
|
|
1261
|
-
getHost: () => hostProvider.
|
|
1287
|
+
getHost: () => hostProvider.getHost(),
|
|
1262
1288
|
baseagents: baseagentSnapshot,
|
|
1263
1289
|
getTriggerSummary: () => {
|
|
1264
1290
|
const now = new Date();
|
|
@@ -1373,6 +1399,7 @@ async function main() {
|
|
|
1373
1399
|
reload: (aid, options) => reloadCoordinator.reload(aid, options),
|
|
1374
1400
|
hooks: reloadHooks,
|
|
1375
1401
|
hotLoad: coreHotLoadAgent,
|
|
1402
|
+
unload: agentRuntimeOperations.unload,
|
|
1376
1403
|
resync: coreResyncAgents,
|
|
1377
1404
|
create: async (options) => {
|
|
1378
1405
|
const { agentCreateNonInteractive } = await import('./cli/agent-create.js');
|
|
@@ -1403,11 +1430,21 @@ async function main() {
|
|
|
1403
1430
|
channelInstances,
|
|
1404
1431
|
hotLoad: coreHotLoadAgent,
|
|
1405
1432
|
activate: completeAgentBootstrap,
|
|
1433
|
+
activatePrepared: async (aid) => bootstrapService.completeBootstrap(aid, { allowSuppliedOwnerPending: true }),
|
|
1406
1434
|
});
|
|
1407
1435
|
initializationServiceForOwnerRecovery = agentInitializationService;
|
|
1408
1436
|
agentApplicationService.setInitializationService(agentInitializationService);
|
|
1409
1437
|
cmdHandler.setAgentApplicationService(agentApplicationService);
|
|
1410
1438
|
setAgentTemplateService(createAgentTemplateRuntime({
|
|
1439
|
+
holdHandoff: (aid, token) => handoffRuntime.holdAgent(aid, token),
|
|
1440
|
+
initialization: agentInitializationService, application: agentApplicationService,
|
|
1441
|
+
usable: aid => {
|
|
1442
|
+
const agent = agentRegistry.get(aid);
|
|
1443
|
+
return !!agent && agent.config.enabled !== false && agentMap.has(`${aid}::${agent.baseagent}`)
|
|
1444
|
+
&& channelInstances.some(instance => instance.channelType === 'aun'
|
|
1445
|
+
&& instance.channel.getAidState?.()?.aid === aid
|
|
1446
|
+
&& instance.channel.getAidState?.()?.status === 'connected');
|
|
1447
|
+
},
|
|
1411
1448
|
registry: agentRegistry, coordinator: reloadCoordinator,
|
|
1412
1449
|
reloadInsideGate: async (aid) => { await agentRegistry.reload(aid, reloadHooks); },
|
|
1413
1450
|
getControl: () => controlChannel,
|
|
@@ -1558,28 +1595,17 @@ async function main() {
|
|
|
1558
1595
|
return [instance, trace.startTask('daemon.channelConnect', owner ? `aid=${owner.aid}; channel=${channel}` : channel, { initialPhase: 'waiting' })];
|
|
1559
1596
|
}));
|
|
1560
1597
|
logger.info(`🚀 EvolCore core is ready; connecting ${channelInstances.length} channel(s) in background`);
|
|
1561
|
-
const backgroundConnections = new Set();
|
|
1562
1598
|
const connectOptions = {
|
|
1563
1599
|
sharedAdmission: true,
|
|
1564
1600
|
beforeConnect: async (instance) => {
|
|
1565
1601
|
const owner = agentRegistry.resolveByChannel(instance.adapter.channelKey)
|
|
1566
1602
|
?? agentRegistry.resolveByChannel(instance.adapter.channelName);
|
|
1567
1603
|
const timing = channelConnectTimings.get(instance);
|
|
1568
|
-
if (owner && instance.channelType === 'aun') {
|
|
1569
|
-
timing?.phase('waiting', 'Agent work classification');
|
|
1570
|
-
const priority = await agentWorkReady.get(owner.aid);
|
|
1571
|
-
if (priority === undefined) {
|
|
1572
|
-
if (startupCancelled)
|
|
1573
|
-
return false;
|
|
1574
|
-
throw new Error(`Work classification unavailable for ${owner.aid}`);
|
|
1575
|
-
}
|
|
1576
|
-
if (!priority)
|
|
1577
|
-
backgroundConnections.add(instance);
|
|
1578
|
-
}
|
|
1579
1604
|
// Transport and authenticated control messages do not require a model runner.
|
|
1580
1605
|
if (startupCancelled || owner?.status === 'disabled')
|
|
1581
1606
|
return false;
|
|
1582
|
-
|
|
1607
|
+
const priority = !owner || instance.channelType !== 'aun' || agentWorkPriority.get(owner.aid) === true;
|
|
1608
|
+
timing?.phase('queued', priority ? 'priority connection admission' : 'idle connection admission');
|
|
1583
1609
|
return true;
|
|
1584
1610
|
},
|
|
1585
1611
|
shouldConnect: (instance) => {
|
|
@@ -1592,8 +1618,14 @@ async function main() {
|
|
|
1592
1618
|
onConnected: markChannelConnected,
|
|
1593
1619
|
connect: async (instance) => {
|
|
1594
1620
|
const timing = channelConnectTimings.get(instance);
|
|
1621
|
+
const owner = agentRegistry.resolveByChannel(instance.adapter.channelKey)
|
|
1622
|
+
?? agentRegistry.resolveByChannel(instance.adapter.channelName);
|
|
1595
1623
|
try {
|
|
1596
|
-
const started = await connectionQueue.run(() => {
|
|
1624
|
+
const started = await connectionQueue.run(() => {
|
|
1625
|
+
timing.phase('running');
|
|
1626
|
+
return instance.connect();
|
|
1627
|
+
}, () => !startupCancelled && channelInstances.includes(instance) && !instance.lifecycle?.signal.aborted, () => owner && instance.channelType === 'aun'
|
|
1628
|
+
? (agentWorkPriority.get(owner.aid) ? 'foreground' : 'background') : 'foreground');
|
|
1597
1629
|
timing(started ? 'ok' : 'cancelled');
|
|
1598
1630
|
return started;
|
|
1599
1631
|
}
|
|
@@ -1636,7 +1668,7 @@ async function main() {
|
|
|
1636
1668
|
const finishConnections = trace.startTask('daemon.channelConnectionsReady', `aun=${aunInstances.length}; other=${externalInstances.length}; control AUN tracked separately`, { summary: true });
|
|
1637
1669
|
const aunConnections = connectAfter(aunInstances);
|
|
1638
1670
|
void aunConnections.catch(() => { });
|
|
1639
|
-
// Agent AUN
|
|
1671
|
+
// Agent AUN transport progresses independently; classification prioritizes queued work.
|
|
1640
1672
|
// Cross-Agent channel routes and local recovery still need the complete plan.
|
|
1641
1673
|
const startupWork = await startupWorkPromise.catch(error => {
|
|
1642
1674
|
finishConnections('failed');
|
|
@@ -1712,8 +1744,8 @@ async function main() {
|
|
|
1712
1744
|
await sessionIdleMonitor.activate({
|
|
1713
1745
|
waitForBackground: async () => {
|
|
1714
1746
|
sessionIdleRestoreState = 'waiting';
|
|
1715
|
-
phase('waiting', '
|
|
1716
|
-
admitted = await
|
|
1747
|
+
phase('waiting', 'background startup');
|
|
1748
|
+
admitted = await waitForBackgroundStartup();
|
|
1717
1749
|
if (admitted) {
|
|
1718
1750
|
sessionIdleRestoreState = 'restoring';
|
|
1719
1751
|
phase('running');
|
|
@@ -1766,8 +1798,6 @@ async function main() {
|
|
|
1766
1798
|
});
|
|
1767
1799
|
// 统一 channel:health 跨通道通知(仅 auth_error)
|
|
1768
1800
|
registerChannelHealthNotifications({ eventBus, channelInstances, agentRegistry });
|
|
1769
|
-
// Observer hints retain foreground precedence. Handoff history is scanned
|
|
1770
|
-
// only after actual task Ready and protects only its affected sessions.
|
|
1771
1801
|
void trace.track('daemon.observerHintsComplete', () => recoverStartupObserverHints({
|
|
1772
1802
|
channelInstances,
|
|
1773
1803
|
recoveryAids: triggerStartupAgents.map(agent => agent.aid),
|
|
@@ -1789,10 +1819,13 @@ async function main() {
|
|
|
1789
1819
|
}), undefined, { summary: true })
|
|
1790
1820
|
.catch(error => logger.error('[startup] observer hint registration failed:', error));
|
|
1791
1821
|
void trace.track('daemon.handoffRecoveryComplete', async (phase) => {
|
|
1792
|
-
phase('waiting', '
|
|
1822
|
+
phase('waiting', 'background startup');
|
|
1793
1823
|
let admitted = false;
|
|
1794
1824
|
await startupHandoffRecovery.run(async () => {
|
|
1795
|
-
|
|
1825
|
+
// Handoff scanning is background recovery and must not depend on a
|
|
1826
|
+
// genuine task Ready. normalStartupGate carries a 30s degraded release,
|
|
1827
|
+
// so a single never-ready Agent can no longer keep the scan unstarted.
|
|
1828
|
+
admitted = await normalStartupGate.promise !== 'cancelled' && !startupCancelled;
|
|
1796
1829
|
if (admitted) {
|
|
1797
1830
|
phase('running');
|
|
1798
1831
|
trace.point('daemon.handoffRecovery');
|
|
@@ -1831,12 +1864,16 @@ async function main() {
|
|
|
1831
1864
|
if (startupCancelled)
|
|
1832
1865
|
return false;
|
|
1833
1866
|
phase('running');
|
|
1834
|
-
resumePendingSessions({ sessionManager, messageQueue, droppedTriggerSessionIds, agentRegistry, agentMap,
|
|
1867
|
+
await resumePendingSessions({ sessionManager, messageQueue, droppedTriggerSessionIds, agentRegistry, agentMap,
|
|
1835
1868
|
pendingSessions });
|
|
1836
1869
|
startupSessionsReady.add(agent.aid);
|
|
1837
1870
|
checkStartupTaskReady();
|
|
1838
1871
|
}, `aid=${agent.aid}; sessions=${pendingSessions.length}`, { initialPhase: 'waiting' });
|
|
1839
1872
|
}));
|
|
1873
|
+
if (startupWork.recoveryIndexAids.size && !startupCancelled
|
|
1874
|
+
&& !messageQueue.completeRecoveryIndex([...startupWork.recoveryIndexAids])) {
|
|
1875
|
+
logger.warn('[startup] Recovery index could not be persisted; retaining compatibility scan for the next start');
|
|
1876
|
+
}
|
|
1840
1877
|
settleSessionRecovery(startupCancelled ? 'cancelled' : 'ok');
|
|
1841
1878
|
})().catch(error => {
|
|
1842
1879
|
settleSessionRecovery('failed');
|
|
@@ -1864,7 +1901,7 @@ async function main() {
|
|
|
1864
1901
|
let taskReadinessSettled = false;
|
|
1865
1902
|
const finishPriorityStartup = trace.startTask('daemon.priorityTaskReady', undefined, { summary: true });
|
|
1866
1903
|
priorityStartupGate.releaseAfter(9_000, () => {
|
|
1867
|
-
logger.warn('[startup] Priority recovery still pending after 9s; admitting idle Agents
|
|
1904
|
+
logger.warn('[startup] Priority recovery still pending after 9s; admitting idle Agents without reporting Ready');
|
|
1868
1905
|
});
|
|
1869
1906
|
void priorityStartupGate.promise.then(outcome => {
|
|
1870
1907
|
trace.setMeta('priorityRelease', outcome);
|
|
@@ -1912,7 +1949,6 @@ async function main() {
|
|
|
1912
1949
|
return;
|
|
1913
1950
|
normalTaskState = state;
|
|
1914
1951
|
taskReadinessSettled = true;
|
|
1915
|
-
taskReadyGate.settle(state);
|
|
1916
1952
|
normalStartupGate.settle(state);
|
|
1917
1953
|
if (state === 'ready') {
|
|
1918
1954
|
trace.tasksReady();
|
|
@@ -1941,7 +1977,6 @@ async function main() {
|
|
|
1941
1977
|
normalTaskState = 'failed';
|
|
1942
1978
|
priorityStartupGate.settle('failed');
|
|
1943
1979
|
normalStartupGate.settle('failed');
|
|
1944
|
-
taskReadyGate.settle('failed');
|
|
1945
1980
|
settleStartupTaskReady('failed');
|
|
1946
1981
|
logger.error('[startup] Task runtime dispatch failed:', error);
|
|
1947
1982
|
});
|
|
@@ -1953,7 +1988,7 @@ async function main() {
|
|
|
1953
1988
|
fs.writeFileSync(readySignalPath, String(Date.now()));
|
|
1954
1989
|
logger.info(`✓ Ready signal written: ${readySignalPath}`);
|
|
1955
1990
|
trace.setMeta('channelInstances', String(channelInstances.length));
|
|
1956
|
-
trace.setMeta('agents', String(agentRegistry.
|
|
1991
|
+
trace.setMeta('agents', String(agentRegistry.allAgents().length));
|
|
1957
1992
|
trace.ready();
|
|
1958
1993
|
// 配置 reload 走 IPC `evolagent.reload` 触发,不再用 watchFile。
|
|
1959
1994
|
// 双 rename 原子写下 watchFile 的语义会被破坏,且新结构有 N 个 config.json 要监控;
|
|
@@ -1964,7 +1999,12 @@ async function main() {
|
|
|
1964
1999
|
beginShutdown: () => lifecycleNotices.beginShutdown(),
|
|
1965
2000
|
sendOffline: signal => lifecycleNotices.sendOffline(signal),
|
|
1966
2001
|
},
|
|
1967
|
-
stopOwnership: () =>
|
|
2002
|
+
stopOwnership: () => {
|
|
2003
|
+
// IPC shutdown does not invoke the signal-only onShutdown callbacks.
|
|
2004
|
+
// Retire contact sync before resolver teardown emits invalidations.
|
|
2005
|
+
stopOwnerNotifications();
|
|
2006
|
+
ownerResolver.stop();
|
|
2007
|
+
},
|
|
1968
2008
|
ipcServer,
|
|
1969
2009
|
readySignalPath,
|
|
1970
2010
|
bindService,
|
|
@@ -1987,7 +2027,6 @@ async function main() {
|
|
|
1987
2027
|
cancelStartupClassification();
|
|
1988
2028
|
priorityStartupGate.settle('cancelled');
|
|
1989
2029
|
normalStartupGate.settle('cancelled');
|
|
1990
|
-
taskReadyGate.settle('cancelled');
|
|
1991
2030
|
void startupCpuProfile?.stop('shutdown');
|
|
1992
2031
|
stopReadinessObservers();
|
|
1993
2032
|
settleStartupTaskReady('cancelled');
|
|
@@ -2055,3 +2094,21 @@ if (isMainScript(import.meta.url)) {
|
|
|
2055
2094
|
process.exit(1);
|
|
2056
2095
|
});
|
|
2057
2096
|
}
|
|
2097
|
+
async function registerBuiltinChannelPlugins(channelLoader) {
|
|
2098
|
+
channelLoader.register(new AUNChannelPlugin());
|
|
2099
|
+
const providers = [
|
|
2100
|
+
['feishu', async () => new (await import('./channels/feishu.js')).FeishuChannelPlugin()],
|
|
2101
|
+
['wechat', async () => new (await import('./channels/wechat.js')).WechatChannelPlugin()],
|
|
2102
|
+
['dingtalk', async () => new (await import('./channels/dingtalk.js')).DingtalkChannelPlugin()],
|
|
2103
|
+
['qqbot', async () => new (await import('./channels/qqbot.js')).QQBotChannelPlugin()],
|
|
2104
|
+
['wecom', async () => new (await import('./channels/wecom.js')).WecomChannelPlugin()],
|
|
2105
|
+
];
|
|
2106
|
+
for (const [channelType, load] of providers) {
|
|
2107
|
+
try {
|
|
2108
|
+
channelLoader.register(await load());
|
|
2109
|
+
}
|
|
2110
|
+
catch (error) {
|
|
2111
|
+
channelLoader.recordProviderFailure(channelType, error);
|
|
2112
|
+
}
|
|
2113
|
+
}
|
|
2114
|
+
}
|
package/dist/ipc.js
CHANGED
|
@@ -7,9 +7,8 @@ import os from 'os';
|
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import { execFile } from 'node:child_process';
|
|
9
9
|
import { logger, logOwnershipEvent } from './utils/logger.js';
|
|
10
|
-
import { withMenuProcessingTime, logMenuRequestCompleted, logMenuRequestReceived } from './core/command/menu-protocol.js';
|
|
11
10
|
import { fileCache } from './core/daemon-file-cache.js';
|
|
12
|
-
import { DAEMON_RUNTIME_EPOCH_ENV } from './cli/task-context.js';
|
|
11
|
+
import { DAEMON_RUNTIME_EPOCH_ENV, isTrustedFullAccessRuntimeContext } from './cli/task-context.js';
|
|
13
12
|
import { HANDOFF_QUERY_MAX_LIMIT, HANDOFF_STATES } from './core/handoff/types.js';
|
|
14
13
|
import { AgentReloadBusyError } from './core/agent-reload-coordinator.js';
|
|
15
14
|
import { getPackageRoot, getWindowsInstanceSocketPathCandidates, normalizeIpcEndpoint, resolvePaths } from './paths.js';
|
|
@@ -22,7 +21,8 @@ import { normalizeAunMentionEntries } from './aun/msg/mention-schema.js';
|
|
|
22
21
|
import { remoteAccessService } from './core/auth/remote-access-store.js';
|
|
23
22
|
import { setModelCatalogDaemonOwner } from './core/model/model-catalog.js';
|
|
24
23
|
import { RUNTIME_ENVIRONMENT_NAMES, setRuntimeEnvironmentOverride } from './config/runtime-env.js';
|
|
25
|
-
import { MAIN_CLI_BIN, SESSION_ID_ENV } from './product.js';
|
|
24
|
+
import { MAIN_CLI_BIN, MESSAGE_CLI_BIN, SESSION_ID_ENV } from './product.js';
|
|
25
|
+
import { canonicalizeEvolcoreCommandArgv } from './core/permission/ec-command-parser.js';
|
|
26
26
|
import { ownerResolver } from './core/ownership/owner-resolver.js';
|
|
27
27
|
import { parseOwnershipCommand, executeOwnershipCommand, ownershipFailure } from './aun/aid/ownership-operation.js';
|
|
28
28
|
import { ECWEB_SERVICE_PROTOCOL, validateEcwebClientProtocolRequirements, } from './contracts/ecweb-service-protocol.js';
|
|
@@ -69,6 +69,7 @@ const LOCAL_CONTROL_COMMANDS = new Set([
|
|
|
69
69
|
'evolagent.list',
|
|
70
70
|
'evolagent.show',
|
|
71
71
|
'evolagent.reload',
|
|
72
|
+
'evolagent.lifecycle',
|
|
72
73
|
'evolagent.load',
|
|
73
74
|
'evolagent.resync',
|
|
74
75
|
'menu.exec',
|
|
@@ -1159,11 +1160,13 @@ export class IpcServer {
|
|
|
1159
1160
|
// 否则绑定原始命令 argv。收发方等执行参数由 daemon 在授权后另行补全。
|
|
1160
1161
|
const expectedArgv = executionSpec
|
|
1161
1162
|
? [...executionSpec.argv]
|
|
1162
|
-
: [
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1163
|
+
: cmd.type === 'aun-msg-send' && cmd.argv[0] === MESSAGE_CLI_BIN
|
|
1164
|
+
? canonicalizeEvolcoreCommandArgv(cmd.argv)
|
|
1165
|
+
: [
|
|
1166
|
+
MAIN_CLI_BIN,
|
|
1167
|
+
...(cmd.type === 'menu-client.request' ? ['menu-client'] : []),
|
|
1168
|
+
...cmd.argv,
|
|
1169
|
+
];
|
|
1167
1170
|
const expectedHash = hashDelegatedCommandArgv(expectedArgv, executionSpec);
|
|
1168
1171
|
if (!expectedHash || cmd.delegationCommandHash !== expectedHash) {
|
|
1169
1172
|
return this.diagnosticRejection('command_hash_mismatch', cmd);
|
|
@@ -2734,6 +2737,22 @@ export class IpcServer {
|
|
|
2734
2737
|
return { ok: false, error: e?.message || String(e) };
|
|
2735
2738
|
}
|
|
2736
2739
|
}
|
|
2740
|
+
case 'evolagent.lifecycle': {
|
|
2741
|
+
if (cmd.sessionId !== undefined || cmd.delegationToken !== undefined) {
|
|
2742
|
+
return { ok: false, code: 'NOT_ALLOWED', error: 'Managed callers must use agent.op' };
|
|
2743
|
+
}
|
|
2744
|
+
if (!['enable', 'disable', 'delete'].includes(cmd.action) || typeof cmd.aid !== 'string') {
|
|
2745
|
+
return { ok: false, code: 'INVALID_ARGS', error: 'Invalid Agent lifecycle operation' };
|
|
2746
|
+
}
|
|
2747
|
+
if (!this.agentApplicationService) {
|
|
2748
|
+
return { ok: false, code: 'NOT_CONFIGURED', error: 'Agent application service is not configured' };
|
|
2749
|
+
}
|
|
2750
|
+
return cmd.action === 'delete'
|
|
2751
|
+
? await this.agentApplicationService.delete(cmd.aid, cmd.purge === true)
|
|
2752
|
+
: cmd.action === 'disable'
|
|
2753
|
+
? await this.agentApplicationService.disable(cmd.aid, cmd.force === true)
|
|
2754
|
+
: await this.agentApplicationService.enable(cmd.aid, cmd.force === true);
|
|
2755
|
+
}
|
|
2737
2756
|
case 'evolagent.reload': {
|
|
2738
2757
|
const name = cmd.name;
|
|
2739
2758
|
if (!name || typeof name !== 'string')
|
|
@@ -2827,6 +2846,8 @@ export class IpcServer {
|
|
|
2827
2846
|
}
|
|
2828
2847
|
}
|
|
2829
2848
|
case 'menu.exec': {
|
|
2849
|
+
// IPC clients such as the restart monitor never execute menus.
|
|
2850
|
+
const { withMenuProcessingTime, logMenuRequestCompleted, logMenuRequestReceived } = await import('./core/command/menu-protocol.js');
|
|
2830
2851
|
const request = cmd.payload && typeof cmd.payload === 'object' && !Array.isArray(cmd.payload)
|
|
2831
2852
|
? cmd.payload
|
|
2832
2853
|
: { type: 'menu.invalid' };
|
|
@@ -3083,10 +3104,16 @@ export class IpcServer {
|
|
|
3083
3104
|
return { kind: 'local-control' };
|
|
3084
3105
|
}
|
|
3085
3106
|
const context = sessionId ? this.taskRuntimeContextProvider?.({ sessionId }) : undefined;
|
|
3107
|
+
// fullaccess 必须由 daemon 校验过的 context 推出,不能取请求体里的自报值:
|
|
3108
|
+
// `isTrustedFullAccessRuntimeContext` 四个条件合判,少一个就等于放宽了别处
|
|
3109
|
+
// 正在用的安全边界(见 cli/task-context.ts)。
|
|
3110
|
+
const fullAccess = isTrustedFullAccessRuntimeContext(context);
|
|
3086
3111
|
return {
|
|
3087
3112
|
kind: 'managed',
|
|
3088
3113
|
...(context?.selfAid ? { selfAid: context.selfAid } : {}),
|
|
3089
3114
|
...(context?.peerRole ? { peerRole: context.peerRole } : {}),
|
|
3115
|
+
...(fullAccess ? { fullAccess: true } : {}),
|
|
3116
|
+
...(fullAccess && context?.authorizedBy ? { authorizedBy: context.authorizedBy } : {}),
|
|
3090
3117
|
};
|
|
3091
3118
|
}
|
|
3092
3119
|
hasValidControlToken(value) {
|
package/dist/product.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
export const PRODUCT_DISPLAY_NAME = 'EvolCore';
|
|
8
8
|
export const MAIN_PACKAGE_NAME = 'evolcore';
|
|
9
9
|
export const MAIN_CLI_BIN = 'ec';
|
|
10
|
+
export const MESSAGE_CLI_BIN = 'ecmsg';
|
|
10
11
|
export const RESTART_REQUEST_ID_ENV = 'EVOLCORE_RESTART_REQUEST_ID';
|
|
11
12
|
export const CHANNEL_LOGS_ENV = 'CHANNEL_LOGS';
|
|
12
13
|
export const WEB_PACKAGE_NAME = 'ec-web';
|