evolcore 0.0.46 → 0.0.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +93 -0
- package/bin/ec-build.mjs +86 -0
- package/dist/agent-template/jobs.js +12 -4
- package/dist/agent-template/runtime.js +139 -39
- package/dist/agent-template/service.js +66 -13
- package/dist/agents/baseagent.js +60 -20
- package/dist/agents/claude-runner.js +43 -18
- package/dist/agents/codex/app-server-client.js +32 -23
- package/dist/agents/codex-runner.js +31 -16
- package/dist/agents/ecagent-runner.js +7 -4
- package/dist/agents/gemini-runner.js +5 -2
- package/dist/agents/runner-types.js +5 -21
- package/dist/aun/aid/agentmd.js +5 -1
- package/dist/aun/group/fs-download.js +1 -1
- package/dist/aun/service-proxy.js +4 -2
- package/dist/build-identity.json +1 -0
- package/dist/channels/aun.js +100 -32
- package/dist/channels/daemon.js +10 -26
- package/dist/cli/aun-commands.js +86 -51
- package/dist/cli/code-stats.js +19 -8
- package/dist/cli/command-log.js +1 -1
- package/dist/cli/daemon-commands.js +65 -76
- package/dist/cli/daemon-lifecycle-client.js +17 -3
- package/dist/cli/directory.js +7 -1
- package/dist/cli/ecmsg-gateway.js +5 -2
- package/dist/cli/index.js +2 -8
- package/dist/cli/init-channel.js +6 -8
- package/dist/cli/init.js +74 -46
- package/dist/cli/invoke-command.js +1 -1
- package/dist/cli/provider-command.js +74 -13
- package/dist/cli/restart-monitor.js +104 -28
- package/dist/cli/role.js +61 -17
- package/dist/cli/stats.js +3 -3
- package/dist/cli/task-context.js +83 -15
- package/dist/cli/thread-command.js +16 -51
- package/dist/cli/upgrade-command.js +4 -2
- package/dist/config/boot-log.js +3 -9
- package/dist/config/builtin-roles.js +5 -7
- package/dist/config/config-manager.js +31 -23
- package/dist/config/daemon-services.js +30 -3
- package/dist/config/gateway-config.js +2 -2
- package/dist/config/invoke-ipc-service.js +6 -4
- package/dist/config/peer-bind-code.js +3 -4
- package/dist/config/peer-book-store.js +59 -218
- package/dist/config/peer-book.js +26 -27
- package/dist/config/peer-role-resolver.js +16 -1
- package/dist/config/provider-identity-migration.js +161 -6
- package/dist/config/provider-ipc-service.js +56 -11
- package/dist/config/provider-menu-request.js +24 -5
- package/dist/config/provider-templates.js +127 -0
- package/dist/config/providers-config.js +59 -8
- package/dist/config/providers-management.js +467 -49
- package/dist/config/role-command-service.js +248 -1
- package/dist/config/schema-migration.js +228 -20
- package/dist/config/schema-registry.js +6 -2
- package/dist/core/agent-application-service.js +6 -1
- package/dist/core/agent-runtime.js +10 -5
- package/dist/core/auth/agent-delegation.js +10 -4
- package/dist/core/auth/auth-gateway.js +2 -1
- package/dist/core/auth/delegation-authorization.js +3 -0
- package/dist/core/auth/delegation-diagnostics.js +56 -15
- package/dist/core/auth/operation-authorizer.js +26 -1
- package/dist/core/auth/operation-catalog.js +28 -64
- package/dist/core/capability/providers/codex-capability-provider.js +7 -8
- package/dist/core/channel-loader.js +18 -0
- package/dist/core/command/agent-control.js +32 -0
- package/dist/core/command/command-handler.js +81 -85
- package/dist/core/command/menu-catalog.js +1 -0
- package/dist/core/command/menu-handler.js +65 -153
- package/dist/core/command/menu-protocol.js +7 -1
- package/dist/core/command/provider-menu.js +13 -3
- package/dist/core/command/role-menu.js +47 -23
- package/dist/core/command/slash-handler.js +30 -49
- package/dist/core/command/team-workspace-items.js +81 -12
- package/dist/core/command/team-workspace-team.js +9 -71
- package/dist/core/command/topic-slash.js +9 -30
- package/dist/core/daemon-bootstrap.js +19 -10
- package/dist/core/daemon-control.js +8 -10
- package/dist/core/daemon-lifecycle.js +50 -40
- package/dist/core/evolagent-registry.js +22 -3
- package/dist/core/file-integrity/store.js +2 -0
- package/dist/core/handoff/runtime.js +37 -1
- package/dist/core/host-snapshot.js +9 -4
- package/dist/core/inference/text-inference.js +3 -1
- package/dist/core/initialization/service.js +31 -8
- package/dist/core/interaction-router.js +3 -0
- package/dist/core/invoke/executors/text.js +72 -19
- package/dist/core/ipc-registration.js +6 -4
- package/dist/core/memory/consolidation.js +6 -6
- package/dist/core/message/aun-ipc-sender.js +165 -55
- package/dist/core/message/im-renderer.js +1 -1
- package/dist/core/message/message-bridge.js +51 -334
- package/dist/core/message/message-log.js +5 -0
- package/dist/core/message/message-queue.js +22 -0
- package/dist/core/message/message-utils.js +8 -0
- package/dist/core/message/response-engine.js +429 -116
- package/dist/core/message/send-routing.js +5 -1
- package/dist/core/model/catalog-service.js +31 -11
- package/dist/core/model/model-capabilities.js +22 -4
- package/dist/core/model/model-catalog.js +1 -0
- package/dist/core/ownership/owner-resolver.js +355 -60
- package/dist/core/permission/protected-paths.js +6 -6
- package/dist/core/relation/peer-identity.js +28 -2
- package/dist/core/relation/same-owner-proof.js +81 -111
- package/dist/core/session/adapters/claude-session-file-adapter.js +1 -1
- package/dist/core/session/adapters/codex-session-file-adapter.js +96 -15
- package/dist/core/session/session-file-health.js +49 -14
- package/dist/core/session/session-fs-store.js +91 -35
- package/dist/core/session/session-manager.js +68 -24
- package/dist/core/session/session-mapper.js +14 -34
- package/dist/core/session/session-transcript.js +5 -1
- package/dist/core/task/task-activity-store.js +84 -0
- package/dist/core/task/task-image-resources.js +1 -1
- package/dist/core/task/task-recovery-service.js +12 -0
- package/dist/core/thread/command-parser.js +7 -12
- package/dist/core/thread/thread-context-storage.js +3 -2
- package/dist/core/thread/thread-operation.js +2 -13
- package/dist/core/thread/thread-service.js +15 -46
- package/dist/directory/owner-directory-admission.js +1 -1
- package/dist/directory/owner-directory-cache.js +45 -28
- package/dist/directory/owner-directory-markdown.js +13 -1
- package/dist/directory/owner-directory-query-operation.js +29 -3
- package/dist/directory/owner-directory-remarks.js +11 -3
- package/dist/eck/message-renderer.js +84 -24
- package/dist/ecweb/basic-settings-service.js +3 -1
- package/dist/ecweb/message-context-service.js +1 -1
- package/dist/ecweb/pairing.js +4 -3
- package/dist/ecweb/providers-service.js +26 -1
- package/dist/ecweb/runtime/lifecycle.js +82 -23
- package/dist/ecweb/runtime/proxy-access.js +74 -0
- package/dist/ecweb/runtime/supervisor.js +6 -17
- package/dist/event-center/registry.js +13 -2
- package/dist/event-center/runtime.js +103 -11
- package/dist/event-center/script-runner.js +5 -5
- package/dist/index.js +129 -93
- package/dist/ipc.js +15 -3
- package/dist/outputs/events.js +62 -0
- package/dist/outputs/protocol.js +102 -0
- package/dist/outputs/service.js +279 -0
- package/dist/paths.js +3 -0
- package/dist/proxy/manager.js +43 -13
- package/dist/services/index.js +89 -4
- package/dist/services/ipc-operation.js +4 -15
- package/dist/services/pack-manager.js +12 -1
- package/dist/services/router.js +21 -6
- package/dist/services/script-runner.js +5 -4
- package/dist/services/validation.js +1 -1
- package/dist/stats/budget.js +1 -1
- package/dist/stats/db.js +19 -0
- package/dist/stats/index.js +1 -1
- package/dist/stats/{price-resolver.js → model-resolver.js} +305 -24
- package/dist/stats/normalizer.js +2 -0
- package/dist/stats/query.js +35 -27
- package/dist/stats/role-budget.js +5 -2
- package/dist/stats/writer.js +10 -6
- package/dist/trigger/audit.js +7 -0
- package/dist/trigger/authorization.js +105 -11
- package/dist/trigger/feedback.js +10 -0
- package/dist/trigger/history.js +37 -11
- package/dist/trigger/ipc-service.js +12 -1
- package/dist/trigger/manager.js +1 -0
- package/dist/trigger/scheduler.js +11 -5
- package/dist/trigger/script-executor.js +2 -1
- package/dist/trigger/script-sandbox.js +9 -3
- package/dist/trigger/state.js +7 -0
- package/dist/trigger/validation.js +22 -0
- package/dist/utils/aid-bind.js +155 -18
- package/dist/utils/atomic-write.js +3 -3
- package/dist/utils/cross-platform.js +97 -31
- package/dist/utils/error-dict.json +94 -4
- package/dist/utils/error-utils.js +40 -4
- package/dist/utils/evolcore-version.js +36 -65
- package/dist/utils/instance-registry.js +61 -0
- package/dist/utils/msg-diag.js +1 -0
- package/dist/utils/process-introspect.js +158 -8
- package/dist/utils/process-tree.js +50 -2
- package/dist/utils/upgrade-jobs.js +4 -4
- package/dist/utils/windows-shell-trust.js +2 -0
- package/dist/workbench/protocol.js +80 -0
- package/dist/workbench/service.js +359 -0
- package/ecagent/dist/types.d.ts +6 -2
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +2 -2
- package/kits/docs/evolcore/aid.md +3 -1
- package/kits/docs/evolcore/config.md +12 -0
- package/kits/docs/evolcore/directory.md +22 -3
- package/kits/docs/evolcore/ecweb-lifecycle.md +15 -0
- package/kits/docs/evolcore/model.md +10 -0
- package/kits/docs/evolcore/peer.md +19 -65
- package/kits/docs/evolcore/provider.md +133 -5
- package/kits/docs/evolcore/role.md +80 -0
- package/kits/docs/evolcore/services.md +6 -6
- package/kits/docs/evolcore/team-workspace.md +1 -1
- package/kits/docs/evolcore/thread-chain.md +14 -15
- package/kits/docs/evolcore/tool-authorization.md +5 -0
- package/kits/docs/evolcore/trigger.md +10 -0
- package/kits/eck_message_manifest.json +12 -0
- package/kits/provider-templates.json +1213 -0
- package/kits/rules/04-relation.md +3 -3
- package/kits/schemas/_meta.json +14 -2
- package/kits/schemas/contact-book.schema.4.json +52 -0
- package/kits/schemas/providers.schema.3.json +200 -0
- package/kits/skills/.switches.json +4 -0
- package/kits/skills/ability/references/calling.md +1 -1
- package/kits/skills/ec-group/SKILL.md +2 -2
- package/kits/skills/ec-identity/SKILL.md +19 -72
- package/kits/skills/ec-provider/SKILL.md +221 -0
- package/kits/skills/ec-provider/scripts/check-model.mjs +80 -0
- package/kits/skills/ec-trigger/SKILL.md +1 -1
- package/kits/skills/thread-ops/SKILL.md +34 -21
- package/kits/templates/message-fragments/group-batch-item.md +1 -1
- package/kits/templates/message-fragments/group-batch.md +1 -1
- package/kits/templates/message-fragments/inject-default.md +1 -1
- package/kits/templates/message-fragments/interrupt-insert.md +1 -0
- package/kits/templates/message-fragments/item-group.md +1 -1
- package/kits/templates/message-fragments/item-private.md +1 -1
- package/kits/templates/message-fragments/thread-context.md +1 -1
- package/kits/templates/message-fragments/trigger-session.md +1 -1
- package/kits/templates/message-fragments/trigger-thread-check.md +1 -1
- package/kits/templates/roles/admin.json +2 -19
- package/kits/templates/roles/member.json +0 -3
- package/kits/templates/system-fragments/baseagent.md +6 -0
- package/kits/templates/system-fragments/commands.md +3 -3
- package/kits/templates/system-fragments/managed-runtime.md +1 -1
- package/kits/templates/system-fragments/relation.md +1 -1
- package/kits/templates/system-fragments/thread.md +6 -5
- package/package.json +6 -4
- package/scripts/agent-template/inspect.mjs +4 -1
- package/scripts/agent-template/shared/common.mjs +2 -3
- package/scripts/agent-template/shared/template-contract.mjs +2 -1
- package/scripts/agent-template/shared/template-package.mjs +9 -2
- package/scripts/agent-template/shared/template-runtime.mjs +20 -5
- package/scripts/agent-template/team-pack.mjs +6 -3
- package/dist/cli/peer.js +0 -127
- package/dist/config/peer-operation-service.js +0 -132
- package/dist/config/peer-request-service.js +0 -532
- package/dist/core/command/connect-menu.js +0 -624
package/dist/index.js
CHANGED
|
@@ -15,12 +15,11 @@ import { CodexSessionFileAdapter } from './core/session/adapters/codex-session-f
|
|
|
15
15
|
import { GeminiSessionFileAdapter } from './core/session/adapters/gemini-session-file-adapter.js';
|
|
16
16
|
import { EcagentSessionFileAdapter } from './core/session/adapters/ecagent-session-file-adapter.js';
|
|
17
17
|
import { loadDefaults, loadAllAgents, migrateIdentitiesIfNeeded, loadDaemonConfig, initializeEckSnapshotsConfig } from './config-store.js';
|
|
18
|
+
import { RoleQuotaQuestions } from './config/role-command-service.js';
|
|
18
19
|
import { inspectClaudeSandboxDependencies, formatClaudeSandboxDependencies } from './core/permission/sandbox-runtime.js';
|
|
19
20
|
import { migrateRelationSharedDirectories } from './core/relation/shared-data.js';
|
|
20
21
|
import { DEFAULT_ECWEB_PORT, ecwebService, serviceRuntimeMode } from './config/daemon-services.js';
|
|
21
22
|
import { ConfigTarget, clearConfiguredOwnerAfterConsensus, onConfigWrite, } from './config/config-manager.js';
|
|
22
|
-
import { expirePendingPeerRequests } from './config/peer-request-service.js';
|
|
23
|
-
import { synchronizeOwnershipPeersSync } from './config/peer-book-store.js';
|
|
24
23
|
import { createSessionIdentityResolver } from './config/peer-role-resolver.js';
|
|
25
24
|
import { initializeStartupConfig, prepareStartupConfig, recordStartupConfig } from './config/boot-log.js';
|
|
26
25
|
import { CONFIG_SCHEMA_VERSION } from './types.js';
|
|
@@ -32,10 +31,10 @@ import { GeminiAgentPlugin } from './agents/gemini-runner.js';
|
|
|
32
31
|
// 不要静态导入 ecagent-runner:它连带整个 ecagent 运行时(typebox 占了模块图
|
|
33
32
|
// 三分之一的 resolve),而绝大多数部署并不使用 ecagent。这里用懒加载外壳。
|
|
34
33
|
import { EcagentAgentPluginLazy } from './agents/ecagent-plugin-lazy.js';
|
|
35
|
-
import { AUNChannelPlugin } from './channels/aun.js';
|
|
36
34
|
import { registerAbilityPlatform } from './ability/daemon.js';
|
|
37
35
|
import { assertAunEncryptionSeedPolicy } from './aun/aid/encryption-seed-policy.js';
|
|
38
36
|
import { BindService } from './utils/aid-bind.js';
|
|
37
|
+
import { ecwebInitializationService } from './core/initialization/service.js';
|
|
39
38
|
import { buildEnvelope } from './core/message/message-utils.js';
|
|
40
39
|
import { ResponseEngine } from './core/message/response-engine.js';
|
|
41
40
|
import { MessageQueue } from './core/message/message-queue.js';
|
|
@@ -47,6 +46,7 @@ import { HandoffRuntime } from './core/handoff/runtime.js';
|
|
|
47
46
|
import { startDaemonControlAid } from './core/daemon-control.js';
|
|
48
47
|
import { createDelegationAuthorizer } from './core/auth/delegation-authorization.js';
|
|
49
48
|
import { registerProxyIpcExecutor } from './proxy/ipc-service.js';
|
|
49
|
+
import { readServiceProxySnapshot } from './proxy/manager.js';
|
|
50
50
|
import { ownerResolver, getDaemonOwners, getPrimaryOwner } from './core/ownership/owner-resolver.js';
|
|
51
51
|
import { StartupTaskQueue, startupConnectionBudget, StartupGate, discoverStartupWork, recoverStartupObserverHints, StartupHandoffRecovery, resumePendingSessions, createDaemonShutdown, daemonConversationTotalExecutionMs, daemonConversationWatchdogMs, daemonIdleTimeoutMs, startupTaskReadiness, } from './core/daemon-lifecycle.js';
|
|
52
52
|
import { createLifecycleNoticeService } from './core/lifecycle-notice.js';
|
|
@@ -71,7 +71,7 @@ import { releaseSessionPathGrants } from './core/permission/session-path-grants.
|
|
|
71
71
|
import { InteractionRouter } from './core/interaction-router.js';
|
|
72
72
|
import { GroupInviteReviewService } from './aun/group/invite-service.js';
|
|
73
73
|
import { AgentDelegationRegistry, } from './core/auth/agent-delegation.js';
|
|
74
|
-
import { ChannelLoader } from './core/channel-loader.js';
|
|
74
|
+
import { ChannelLoader, registerBuiltinChannelPlugins } from './core/channel-loader.js';
|
|
75
75
|
import { registerChannelInstance as registerChannelRuntimeInstance, createChannelStartupNotifications, registerChannelHealthNotifications, bindStartupChannelsToAgents, createAgentStorageClientResolver, createDefaultChannelPolicy, createChannelConnectionRuntime, preloadChannelThreads, } from './core/channel-runtime.js';
|
|
76
76
|
import { createIpcStatusProvider, registerDaemonIpc } from './core/ipc-registration.js';
|
|
77
77
|
import { AgentLoader } from './core/baseagent-loader.js';
|
|
@@ -92,6 +92,8 @@ import { authenticatedTriggerActor as authenticateTriggerActor, authenticatedTri
|
|
|
92
92
|
import { TargetSessionLockRegistry } from './trigger/session-lock.js';
|
|
93
93
|
import { buildTriggerScheduler, createTriggerChannelResolver, TriggerSchedulerRegistry } from './trigger/application-service.js';
|
|
94
94
|
import { createDaemonEventCenter } from './event-center/daemon.js';
|
|
95
|
+
import { setOutputChangePublisher } from './outputs/service.js';
|
|
96
|
+
import { setWorkbenchChangePublisher, setWorkbenchRuntimeProvider, notifyWorkbenchRuntimeChanged } from './workbench/service.js';
|
|
95
97
|
import { DaemonChannel } from './channels/daemon.js';
|
|
96
98
|
import { DAEMON_RUNTIME_EPOCH_ENV, ensureProcessManagedTempDir } from './cli/task-context.js';
|
|
97
99
|
import fs from 'fs';
|
|
@@ -259,7 +261,6 @@ async function main() {
|
|
|
259
261
|
let startupCancelled = false;
|
|
260
262
|
let cancelStartupClassification = () => { };
|
|
261
263
|
let normalTaskState = 'pending';
|
|
262
|
-
let startupEcwebState = 'waiting';
|
|
263
264
|
const priorityStartupGate = new StartupGate();
|
|
264
265
|
const normalStartupGate = new StartupGate();
|
|
265
266
|
const waitForBackgroundStartup = async () => await normalStartupGate.promise !== 'cancelled' && !startupCancelled;
|
|
@@ -269,7 +270,7 @@ async function main() {
|
|
|
269
270
|
priorityStartupGate.settle('cancelled');
|
|
270
271
|
normalStartupGate.settle('cancelled');
|
|
271
272
|
});
|
|
272
|
-
//
|
|
273
|
+
// Read build-time markers after task admission; startup never hashes the tree.
|
|
273
274
|
// Keep status pending until the background release instead of competing
|
|
274
275
|
// with recovery metadata reads. Bootstrap-only daemons have no task gate.
|
|
275
276
|
void trace.track('daemon.versionReport', async (phase) => {
|
|
@@ -287,6 +288,8 @@ async function main() {
|
|
|
287
288
|
// ECWeb has one lifecycle owner: the daemon. The CLI may have started an
|
|
288
289
|
// instance just before spawning us; the supervisor adopts it when healthy,
|
|
289
290
|
// otherwise starts one and keeps it alive for the daemon's lifetime.
|
|
291
|
+
// Start independently once its configuration is loaded; Agent readiness
|
|
292
|
+
// does not gate the UI, and HTTP health does not gate task readiness.
|
|
290
293
|
trace.mark('daemon.ecwebSupervisor');
|
|
291
294
|
let ecwebSupervisor = null;
|
|
292
295
|
const ecwebConfig = ecwebService(daemonCfg.services);
|
|
@@ -302,20 +305,16 @@ async function main() {
|
|
|
302
305
|
});
|
|
303
306
|
onShutdown(() => ecwebSupervisor?.stop());
|
|
304
307
|
const removeEcwebConfigListener = onConfigWrite(({ target }) => {
|
|
305
|
-
if (target !== ConfigTarget.Process || !ecwebSupervisor)
|
|
308
|
+
if (startupCancelled || target !== ConfigTarget.Process || !ecwebSupervisor)
|
|
306
309
|
return;
|
|
307
310
|
try {
|
|
308
311
|
const service = ecwebService(loadDaemonConfig().services);
|
|
309
|
-
void
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
runtimeMode: service ? serviceRuntimeMode(service) : 'managed',
|
|
316
|
-
restart: service?.runtime?.restart,
|
|
317
|
-
health: service?.health,
|
|
318
|
-
});
|
|
312
|
+
void ecwebSupervisor.configure({
|
|
313
|
+
enabled: service?.enabled === true,
|
|
314
|
+
port: service?.port ?? DEFAULT_ECWEB_PORT,
|
|
315
|
+
runtimeMode: service ? serviceRuntimeMode(service) : 'managed',
|
|
316
|
+
restart: service?.runtime?.restart,
|
|
317
|
+
health: service?.health,
|
|
319
318
|
}).catch((error) => logger.warn(`ECWeb 配置热应用失败: ${error?.message || error}`));
|
|
320
319
|
}
|
|
321
320
|
catch (error) {
|
|
@@ -323,25 +322,19 @@ async function main() {
|
|
|
323
322
|
}
|
|
324
323
|
});
|
|
325
324
|
onShutdown(removeEcwebConfigListener);
|
|
326
|
-
void trace.track('daemon.ecwebLaunch', async (
|
|
327
|
-
phase('waiting', 'priority Ready');
|
|
328
|
-
await priorityStartupGate.promise;
|
|
325
|
+
void trace.track('daemon.ecwebLaunch', async () => {
|
|
329
326
|
if (startupCancelled)
|
|
330
327
|
return false;
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
startupEcwebState = 'starting';
|
|
334
|
-
await ecwebSupervisor.start();
|
|
335
|
-
startupEcwebState = 'ready';
|
|
336
|
-
}
|
|
337
|
-
}, undefined, { initialPhase: 'waiting' }).catch((error) => {
|
|
338
|
-
startupEcwebState = 'failed';
|
|
328
|
+
await ecwebSupervisor.start();
|
|
329
|
+
}, undefined, { initialPhase: 'running' }).catch((error) => {
|
|
339
330
|
logger.warn(`ECWeb supervisor 启动失败(不影响 daemon 主流程): ${error?.message || error}`);
|
|
340
331
|
});
|
|
341
332
|
}
|
|
342
333
|
if (bindBootstrapMode && process.env.EVOLCORE_WEB_INIT !== '1' && daemonCfg.aid && loadAllAgents().agents.length === 0) {
|
|
343
334
|
priorityStartupGate.settle('ready');
|
|
344
|
-
await runBindBootstrapDaemon(daemonCfg);
|
|
335
|
+
await runBindBootstrapDaemon(daemonCfg, ecwebSupervisor);
|
|
336
|
+
// The pairing-only daemon has no Agent task gate.
|
|
337
|
+
normalStartupGate.settle('ready');
|
|
345
338
|
return;
|
|
346
339
|
}
|
|
347
340
|
// ── EvolAgent Registry:加载 agents/<aid>/config.json ──
|
|
@@ -528,7 +521,7 @@ async function main() {
|
|
|
528
521
|
baseagent.loaded = loaded.has(baseagent.id);
|
|
529
522
|
};
|
|
530
523
|
let configureRunnerCallbacks;
|
|
531
|
-
const agentDelegationRegistry =
|
|
524
|
+
const agentDelegationRegistry = await AgentDelegationRegistry.createAsync();
|
|
532
525
|
process.env[DAEMON_RUNTIME_EPOCH_ENV] = agentDelegationRegistry.getRuntimeEpoch();
|
|
533
526
|
const startupRunnersStartedAtMs = Date.now();
|
|
534
527
|
trace.mark('daemon.agentRunnerDispatch');
|
|
@@ -675,19 +668,12 @@ async function main() {
|
|
|
675
668
|
trace.mark('daemon.channelInstances', `${channelInstances.length} 个渠道实例`);
|
|
676
669
|
logger.info(`✓ Created ${channelInstances.length} channel instance(s)`);
|
|
677
670
|
let bootstrapService;
|
|
678
|
-
const contactRequestExpiryTimer = daemonPluginLifecycle.setInterval(() => {
|
|
679
|
-
for (const agent of agentRegistry.runnableAgents()) {
|
|
680
|
-
void expirePendingPeerRequests(agent.aid).catch(error => {
|
|
681
|
-
logger.warn(`[contact-request] Pending expiry sweep failed: self=${agent.aid} error=${error instanceof Error ? error.message : String(error)}`);
|
|
682
|
-
});
|
|
683
|
-
}
|
|
684
|
-
}, 60_000);
|
|
685
|
-
contactRequestExpiryTimer.unref?.();
|
|
686
671
|
const bindService = daemonCfg.aid
|
|
687
672
|
? new BindService({
|
|
688
673
|
receiverAid: daemonCfg.aid,
|
|
689
674
|
getAvailableBaseagents: detectAvailableBaseagents,
|
|
690
675
|
getUptimeSeconds: () => Math.floor(process.uptime()),
|
|
676
|
+
handleAppBindRequest: (payload, senderAid, encrypted) => ecwebInitializationService.handleAppBindRequest(payload, senderAid, encrypted),
|
|
691
677
|
})
|
|
692
678
|
: null;
|
|
693
679
|
bindService?.startCleanup();
|
|
@@ -696,15 +682,9 @@ async function main() {
|
|
|
696
682
|
});
|
|
697
683
|
let initializationServiceForOwnerRecovery;
|
|
698
684
|
const stopOwnerNotifications = ownerResolver.onChange((subjectAid, ownerAid) => {
|
|
685
|
+
if (startupCancelled)
|
|
686
|
+
return;
|
|
699
687
|
permissionGateway.revalidatePendingApprovals(subjectAid);
|
|
700
|
-
if (agentRegistry.get(subjectAid)) {
|
|
701
|
-
try {
|
|
702
|
-
synchronizeOwnershipPeersSync(subjectAid);
|
|
703
|
-
}
|
|
704
|
-
catch (error) {
|
|
705
|
-
logOwnershipEvent('contacts.sync_failed', { subjectAid, ownerAid, errorCode: ownershipErrorCode(error) }, true);
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
688
|
if (!ownerAid)
|
|
709
689
|
return;
|
|
710
690
|
initializationServiceForOwnerRecovery?.resumeForOwner(subjectAid, ownerAid);
|
|
@@ -873,6 +853,31 @@ async function main() {
|
|
|
873
853
|
return (client ?? null);
|
|
874
854
|
},
|
|
875
855
|
});
|
|
856
|
+
setOutputChangePublisher((aid, data) => {
|
|
857
|
+
void eventCenter.publishAgentEvent(aid, 'team.outputs.changed', data).catch(() => { });
|
|
858
|
+
}, aid => eventCenter.get(aid)?.runtime.nativeOutputAvailable === true);
|
|
859
|
+
setWorkbenchChangePublisher((aid, data) => {
|
|
860
|
+
void eventCenter.publishAgentEvent(aid, 'team.workbench.changed', data).catch(() => { });
|
|
861
|
+
}, aid => eventCenter.get(aid)?.runtime.nativeOutputAvailable === true);
|
|
862
|
+
setWorkbenchRuntimeProvider(aid => {
|
|
863
|
+
const agent = agentRegistry.get(aid);
|
|
864
|
+
return agent ? { status: agent.status, tasks: responseEngine.getWorkbenchTasks(aid) } : undefined;
|
|
865
|
+
});
|
|
866
|
+
const workbenchLifecycle = (event) => {
|
|
867
|
+
if ('aid' in event && typeof event.aid === 'string')
|
|
868
|
+
notifyWorkbenchRuntimeChanged(event.aid);
|
|
869
|
+
};
|
|
870
|
+
for (const type of ['agent:started', 'agent:stopped', 'agent:enabled', 'agent:disabled', 'agent:error']) {
|
|
871
|
+
eventBus.subscribe(type, workbenchLifecycle);
|
|
872
|
+
}
|
|
873
|
+
onShutdown(() => {
|
|
874
|
+
setWorkbenchRuntimeProvider();
|
|
875
|
+
setWorkbenchChangePublisher();
|
|
876
|
+
setOutputChangePublisher(undefined);
|
|
877
|
+
for (const type of ['agent:started', 'agent:stopped', 'agent:enabled', 'agent:disabled', 'agent:error']) {
|
|
878
|
+
eventBus.unsubscribe(type, workbenchLifecycle);
|
|
879
|
+
}
|
|
880
|
+
});
|
|
876
881
|
cmdHandler.setEventCenter(eventCenter);
|
|
877
882
|
// ECK 能力清单变量:只读两个运行时的内存包集合,不扫目录。
|
|
878
883
|
responseEngine.setCapabilityIndexes(selfAid => ({
|
|
@@ -1153,6 +1158,7 @@ async function main() {
|
|
|
1153
1158
|
pendingFile,
|
|
1154
1159
|
upmsg,
|
|
1155
1160
|
});
|
|
1161
|
+
let getProxyTransport;
|
|
1156
1162
|
const startupObserverRecoveries = [];
|
|
1157
1163
|
let startupRecoveryPending = true;
|
|
1158
1164
|
const lifecycleNotices = createLifecycleNoticeService({
|
|
@@ -1197,12 +1203,11 @@ async function main() {
|
|
|
1197
1203
|
let pendingShutdownTraceId;
|
|
1198
1204
|
trace.mark('daemon.baseagentProbe');
|
|
1199
1205
|
refreshLoadedBaseagents();
|
|
1200
|
-
const getStatusSnapshot = () => {
|
|
1206
|
+
const getStatusSnapshot = (agents) => {
|
|
1201
1207
|
const now = Date.now();
|
|
1202
1208
|
const todayStart = new Date(new Date(now).getFullYear(), new Date(now).getMonth(), new Date(now).getDate()).getTime();
|
|
1203
1209
|
const lastHour = queryStatusActivity(paths.root, now - 3_600_000, now);
|
|
1204
1210
|
const today = queryStatusActivity(paths.root, todayStart, now);
|
|
1205
|
-
const agents = agentRegistry.list();
|
|
1206
1211
|
const usageByAgent = queryStatusActivityByAgent(paths.root, todayStart, now, agents.map(agent => agent.aid));
|
|
1207
1212
|
return {
|
|
1208
1213
|
activity: { lastHour, today },
|
|
@@ -1233,7 +1238,7 @@ async function main() {
|
|
|
1233
1238
|
};
|
|
1234
1239
|
};
|
|
1235
1240
|
// 主机信息唯一出口:CLI、菜单、ecweb 都读这一份,别各自探测。
|
|
1236
|
-
//
|
|
1241
|
+
// 启动时先提供缓存;版本与虚拟化探测的子进程在正常 Ready 后刷新。
|
|
1237
1242
|
const hostProvider = createHostSnapshotProvider({
|
|
1238
1243
|
messageQueue,
|
|
1239
1244
|
statsCollector,
|
|
@@ -1242,11 +1247,16 @@ async function main() {
|
|
|
1242
1247
|
runMode: devMode ? 'dev' : 'install',
|
|
1243
1248
|
getSystemCpuPercent: () => ipcServer.getSystemCpuPercent(),
|
|
1244
1249
|
getControlAidState: () => controlChannel?.getAidState(),
|
|
1250
|
+
autoProbe: false,
|
|
1245
1251
|
});
|
|
1252
|
+
void waitForBackgroundStartup().then(admitted => {
|
|
1253
|
+
if (admitted)
|
|
1254
|
+
return hostProvider.refresh();
|
|
1255
|
+
}).catch(error => logger.warn(`[HostSnapshot] background probe failed: ${error}`));
|
|
1246
1256
|
trace.mark('daemon.ipcCreate');
|
|
1247
1257
|
const ipcServer = new IpcServer(resolvePaths().socket, createIpcStatusProvider({
|
|
1248
1258
|
channelInstances,
|
|
1249
|
-
getChannelRuntimeSnapshot:
|
|
1259
|
+
getChannelRuntimeSnapshot: agents => channelLoader.getSnapshot(agents.flatMap(info => {
|
|
1250
1260
|
const agent = agentRegistry.get(info.aid);
|
|
1251
1261
|
return agent ? [agent] : [];
|
|
1252
1262
|
})),
|
|
@@ -1263,8 +1273,7 @@ async function main() {
|
|
|
1263
1273
|
: priorityStartupGate.status === 'pending' ? 'recovering' : 'loading',
|
|
1264
1274
|
priorityRelease: priorityStartupGate.status,
|
|
1265
1275
|
optionalRelease: normalStartupGate.status,
|
|
1266
|
-
ecweb:
|
|
1267
|
-
: ecwebSupervisor?.status().state ?? 'disabled',
|
|
1276
|
+
ecweb: ecwebSupervisor?.status().state ?? 'disabled',
|
|
1268
1277
|
backgroundRecovery: {
|
|
1269
1278
|
handoff: startupHandoffRecovery?.status() ?? { completed: 0, total: triggerStartupAgents.length, retrying: 0 },
|
|
1270
1279
|
sessionIdle: sessionIdleRestoreState,
|
|
@@ -1286,7 +1295,7 @@ async function main() {
|
|
|
1286
1295
|
}),
|
|
1287
1296
|
daemonAid: daemonCfg.aid,
|
|
1288
1297
|
getControlAidState: () => controlChannel?.getAidState(),
|
|
1289
|
-
getHost: () => hostProvider.
|
|
1298
|
+
getHost: () => hostProvider.getHost(),
|
|
1290
1299
|
baseagents: baseagentSnapshot,
|
|
1291
1300
|
getTriggerSummary: () => {
|
|
1292
1301
|
const now = new Date();
|
|
@@ -1294,17 +1303,7 @@ async function main() {
|
|
|
1294
1303
|
return triggerSchedulers.statusSummary(from, Date.now());
|
|
1295
1304
|
},
|
|
1296
1305
|
getStatusSnapshot,
|
|
1297
|
-
getServiceProxySnapshot: () => (
|
|
1298
|
-
source: 'daemon-config',
|
|
1299
|
-
items: (daemonCfg.services ?? []).filter(service => !!service.proxy || service.name === 'ecweb').map(service => ({
|
|
1300
|
-
name: service.name,
|
|
1301
|
-
serviceEnabled: service.enabled === true,
|
|
1302
|
-
proxyEnabled: service.proxy?.enabled === true,
|
|
1303
|
-
source: service.proxy?.source ?? null,
|
|
1304
|
-
serviceType: service.proxy?.serviceType ?? null,
|
|
1305
|
-
visibility: service.proxy?.visibility ?? null,
|
|
1306
|
-
})),
|
|
1307
|
-
}),
|
|
1306
|
+
getServiceProxySnapshot: () => readServiceProxySnapshot(getProxyTransport?.()),
|
|
1308
1307
|
}), async (argv, sessionId, delegationToken, delegationCommandHash) => {
|
|
1309
1308
|
const delegation = agentDelegationRegistry.validate(delegationToken, sessionId, delegationCommandHash);
|
|
1310
1309
|
if (!delegation.ok)
|
|
@@ -1437,6 +1436,7 @@ async function main() {
|
|
|
1437
1436
|
initializationServiceForOwnerRecovery = agentInitializationService;
|
|
1438
1437
|
agentApplicationService.setInitializationService(agentInitializationService);
|
|
1439
1438
|
cmdHandler.setAgentApplicationService(agentApplicationService);
|
|
1439
|
+
const templateRecoveryMutes = new Set();
|
|
1440
1440
|
setAgentTemplateService(createAgentTemplateRuntime({
|
|
1441
1441
|
holdHandoff: (aid, token) => handoffRuntime.holdAgent(aid, token),
|
|
1442
1442
|
initialization: agentInitializationService, application: agentApplicationService,
|
|
@@ -1448,7 +1448,9 @@ async function main() {
|
|
|
1448
1448
|
&& instance.channel.getAidState?.()?.status === 'connected');
|
|
1449
1449
|
},
|
|
1450
1450
|
registry: agentRegistry, coordinator: reloadCoordinator,
|
|
1451
|
-
reloadInsideGate: async (aid) => {
|
|
1451
|
+
reloadInsideGate: async (aid, recoveryJobId, restoreStopped) => {
|
|
1452
|
+
await agentRegistry.reload(aid, reloadHooks, { recoveryJobId, preserveStopped: true, restoreStopped });
|
|
1453
|
+
},
|
|
1452
1454
|
getControl: () => controlChannel,
|
|
1453
1455
|
waitForControl: async () => {
|
|
1454
1456
|
const deadline = Date.now() + 60_000;
|
|
@@ -1458,19 +1460,35 @@ async function main() {
|
|
|
1458
1460
|
},
|
|
1459
1461
|
getScheduler: aid => triggerSchedulers.get(aid),
|
|
1460
1462
|
recoveryComplete: (aid, succeeded) => {
|
|
1461
|
-
if (succeeded && templateStartupRecovery.pending.has(aid)) {
|
|
1463
|
+
if (succeeded && (templateStartupRecovery.pending.has(aid) || templateRecoveryMutes.has(aid))) {
|
|
1462
1464
|
const agent = agentRegistry.get(aid);
|
|
1463
|
-
if (agent)
|
|
1465
|
+
if (agent && agent.status !== 'disabled')
|
|
1464
1466
|
messageQueue.unmuteAgent(agent.name);
|
|
1467
|
+
if (agent?.error === 'Template installation requires recovery')
|
|
1468
|
+
delete agent.error;
|
|
1465
1469
|
templateStartupRecovery.pending.delete(aid);
|
|
1470
|
+
templateRecoveryMutes.delete(aid);
|
|
1466
1471
|
}
|
|
1467
1472
|
},
|
|
1468
|
-
block: aid => {
|
|
1473
|
+
block: async (aid) => {
|
|
1469
1474
|
const agent = agentRegistry.get(aid);
|
|
1470
|
-
if (agent)
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1475
|
+
if (!agent)
|
|
1476
|
+
return;
|
|
1477
|
+
agent.status = 'disabled';
|
|
1478
|
+
agent.error = 'Template installation requires recovery';
|
|
1479
|
+
if (!messageQueue.isAgentMuted(agent.name))
|
|
1480
|
+
templateRecoveryMutes.add(aid);
|
|
1481
|
+
messageQueue.muteAgent(agent.name);
|
|
1482
|
+
const { createRunnerReloadTransaction } = await import('./core/runner-reload-transaction.js');
|
|
1483
|
+
const runners = createRunnerReloadTransaction({ aid, agentMap, staged: [] });
|
|
1484
|
+
runners.commit();
|
|
1485
|
+
const settlements = await Promise.allSettled([
|
|
1486
|
+
messageQueue.interruptByAgentAndWait(agent.name), triggerSchedulers.remove(aid), runners.finalize(),
|
|
1487
|
+
...agent.channelInstanceNames().map(name => reloadHooks.disconnectChannel(name)),
|
|
1488
|
+
]);
|
|
1489
|
+
const failures = settlements.filter(result => result.status === 'rejected');
|
|
1490
|
+
if (failures.length)
|
|
1491
|
+
throw new AggregateError(failures.map(result => result.reason), 'Template runtime cleanup incomplete');
|
|
1474
1492
|
},
|
|
1475
1493
|
}));
|
|
1476
1494
|
for (const aid of templateStartupRecovery.pending) {
|
|
@@ -1576,6 +1594,7 @@ async function main() {
|
|
|
1576
1594
|
waitForServices: waitForBackgroundStartup,
|
|
1577
1595
|
connectChannel: channel => trace.track('daemon.controlChannelConnect', phase => connectionQueue.run(() => { phase('running'); return channel.connect(); }, () => !startupCancelled), undefined, { initialPhase: 'queued' }),
|
|
1578
1596
|
onServiceProxyManager: manager => {
|
|
1597
|
+
getProxyTransport = () => manager.transportSnapshot();
|
|
1579
1598
|
const authorizeManagedOperation = createDelegationAuthorizer({
|
|
1580
1599
|
agentDelegationRegistry,
|
|
1581
1600
|
sessionManager,
|
|
@@ -1588,6 +1607,36 @@ async function main() {
|
|
|
1588
1607
|
});
|
|
1589
1608
|
},
|
|
1590
1609
|
});
|
|
1610
|
+
if (controlChannel && daemonCfg.aid) {
|
|
1611
|
+
const channel = controlChannel;
|
|
1612
|
+
const daemonAid = daemonCfg.aid;
|
|
1613
|
+
const quotaQuestions = new RoleQuotaQuestions(interactionRouter);
|
|
1614
|
+
channel.interactionCallback = response => interactionRouter.handleAsync({ ...response, channelKey: 'control' });
|
|
1615
|
+
processor.setRoleQuotaNotifier(request => quotaQuestions.present({ request, daemonAid, transport: {
|
|
1616
|
+
channelKey: 'control',
|
|
1617
|
+
send: async (ownerAid, interaction) => {
|
|
1618
|
+
if (interaction.kind.kind !== 'action')
|
|
1619
|
+
return false;
|
|
1620
|
+
const card = interaction.kind;
|
|
1621
|
+
const result = await channel.sendContentPayload(ownerAid, {
|
|
1622
|
+
type: 'action_card', title: card.title, text: card.body, sensitive: true,
|
|
1623
|
+
actions: [...card.buttons.map(button => ({ label: button.label, value: button.key, behavior: 'reply' })),
|
|
1624
|
+
{ label: '输入新额度', behavior: 'compose', sensitive: true,
|
|
1625
|
+
compose_timeout_ms: Math.max(0, interaction.expiresAt - Date.now()) }],
|
|
1626
|
+
}, { contentKind: 'card', dedupeKey: interaction.id,
|
|
1627
|
+
ttl: Math.max(0, interaction.expiresAt - Date.now()),
|
|
1628
|
+
context: { delivery: { chatType: 'private' }, metadata: { encrypted: true } },
|
|
1629
|
+
postSend: { type: 'register_interaction_card', requestId: interaction.id, isCommandCard: false,
|
|
1630
|
+
initiatorAid: ownerAid, sensitive: true, expiresAt: interaction.expiresAt, delivery: { chatType: 'private' } }, });
|
|
1631
|
+
return ((result.status === undefined || result.status === 'sent') && !!result.messageId)
|
|
1632
|
+
|| ((result.status === 'retry' || result.queued === true) && !!result.outboxId);
|
|
1633
|
+
},
|
|
1634
|
+
invalidate: id => channel.invalidateInteraction(id),
|
|
1635
|
+
notice: async (ownerAid, text) => {
|
|
1636
|
+
await channel.sendStructuredOrThrow(ownerAid, { type: 'notice', text, subtype: 'role_quota' }, { delivery: { chatType: 'private' }, metadata: { encrypted: true } });
|
|
1637
|
+
},
|
|
1638
|
+
} }));
|
|
1639
|
+
}
|
|
1591
1640
|
// ── 连接所有渠道(后台首连,AUN/任意渠道故障不阻塞 daemon 主流程)──
|
|
1592
1641
|
trace.point('daemon.channelConnectDispatch');
|
|
1593
1642
|
const channelConnectTimings = new Map(channelInstances.map(instance => {
|
|
@@ -1903,7 +1952,7 @@ async function main() {
|
|
|
1903
1952
|
let taskReadinessSettled = false;
|
|
1904
1953
|
const finishPriorityStartup = trace.startTask('daemon.priorityTaskReady', undefined, { summary: true });
|
|
1905
1954
|
priorityStartupGate.releaseAfter(9_000, () => {
|
|
1906
|
-
logger.warn('[startup] Priority recovery still pending after 9s; admitting idle Agents
|
|
1955
|
+
logger.warn('[startup] Priority recovery still pending after 9s; admitting idle Agents without reporting Ready');
|
|
1907
1956
|
});
|
|
1908
1957
|
void priorityStartupGate.promise.then(outcome => {
|
|
1909
1958
|
trace.setMeta('priorityRelease', outcome);
|
|
@@ -1990,7 +2039,7 @@ async function main() {
|
|
|
1990
2039
|
fs.writeFileSync(readySignalPath, String(Date.now()));
|
|
1991
2040
|
logger.info(`✓ Ready signal written: ${readySignalPath}`);
|
|
1992
2041
|
trace.setMeta('channelInstances', String(channelInstances.length));
|
|
1993
|
-
trace.setMeta('agents', String(agentRegistry.
|
|
2042
|
+
trace.setMeta('agents', String(agentRegistry.allAgents().length));
|
|
1994
2043
|
trace.ready();
|
|
1995
2044
|
// 配置 reload 走 IPC `evolagent.reload` 触发,不再用 watchFile。
|
|
1996
2045
|
// 双 rename 原子写下 watchFile 的语义会被破坏,且新结构有 N 个 config.json 要监控;
|
|
@@ -2001,7 +2050,12 @@ async function main() {
|
|
|
2001
2050
|
beginShutdown: () => lifecycleNotices.beginShutdown(),
|
|
2002
2051
|
sendOffline: signal => lifecycleNotices.sendOffline(signal),
|
|
2003
2052
|
},
|
|
2004
|
-
stopOwnership: () =>
|
|
2053
|
+
stopOwnership: () => {
|
|
2054
|
+
// IPC shutdown does not invoke the signal-only onShutdown callbacks.
|
|
2055
|
+
// Retire contact sync before resolver teardown emits invalidations.
|
|
2056
|
+
stopOwnerNotifications();
|
|
2057
|
+
ownerResolver.stop();
|
|
2058
|
+
},
|
|
2005
2059
|
ipcServer,
|
|
2006
2060
|
readySignalPath,
|
|
2007
2061
|
bindService,
|
|
@@ -2091,21 +2145,3 @@ if (isMainScript(import.meta.url)) {
|
|
|
2091
2145
|
process.exit(1);
|
|
2092
2146
|
});
|
|
2093
2147
|
}
|
|
2094
|
-
async function registerBuiltinChannelPlugins(channelLoader) {
|
|
2095
|
-
channelLoader.register(new AUNChannelPlugin());
|
|
2096
|
-
const providers = [
|
|
2097
|
-
['feishu', async () => new (await import('./channels/feishu.js')).FeishuChannelPlugin()],
|
|
2098
|
-
['wechat', async () => new (await import('./channels/wechat.js')).WechatChannelPlugin()],
|
|
2099
|
-
['dingtalk', async () => new (await import('./channels/dingtalk.js')).DingtalkChannelPlugin()],
|
|
2100
|
-
['qqbot', async () => new (await import('./channels/qqbot.js')).QQBotChannelPlugin()],
|
|
2101
|
-
['wecom', async () => new (await import('./channels/wecom.js')).WecomChannelPlugin()],
|
|
2102
|
-
];
|
|
2103
|
-
for (const [channelType, load] of providers) {
|
|
2104
|
-
try {
|
|
2105
|
-
channelLoader.register(await load());
|
|
2106
|
-
}
|
|
2107
|
-
catch (error) {
|
|
2108
|
-
channelLoader.recordProviderFailure(channelType, error);
|
|
2109
|
-
}
|
|
2110
|
-
}
|
|
2111
|
-
}
|
package/dist/ipc.js
CHANGED
|
@@ -7,7 +7,6 @@ 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
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';
|
|
@@ -2482,8 +2481,19 @@ export class IpcServer {
|
|
|
2482
2481
|
if (!this.roleOperationExecutor)
|
|
2483
2482
|
return { ok: false, code: 'NOT_CONFIGURED', error: 'role.op not configured' };
|
|
2484
2483
|
const { argv, sessionId, delegationToken } = cmd;
|
|
2485
|
-
if (!Array.isArray(argv) || argv.some(value => typeof value !== 'string')
|
|
2486
|
-
return { ok: false, code: 'INVALID_REQUEST', error: '
|
|
2484
|
+
if (!Array.isArray(argv) || argv.some(value => typeof value !== 'string')) {
|
|
2485
|
+
return { ok: false, code: 'INVALID_REQUEST', error: 'invalid argv' };
|
|
2486
|
+
}
|
|
2487
|
+
const delegated = cmd.sessionId !== undefined || cmd.delegationToken !== undefined
|
|
2488
|
+
|| cmd.actorSessionId !== undefined;
|
|
2489
|
+
if (!delegated) {
|
|
2490
|
+
if (!this.hasValidControlToken(cmd.controlToken)) {
|
|
2491
|
+
return { ok: false, code: 'CONTROL_TOKEN_REQUIRED', error: 'Host role operations require a valid control token' };
|
|
2492
|
+
}
|
|
2493
|
+
return await this.roleOperationExecutor(argv, '', undefined, undefined, true);
|
|
2494
|
+
}
|
|
2495
|
+
if (!sessionId) {
|
|
2496
|
+
return { ok: false, code: 'INVALID_REQUEST', error: 'missing sessionId' };
|
|
2487
2497
|
}
|
|
2488
2498
|
if (delegationToken !== undefined && typeof delegationToken !== 'string') {
|
|
2489
2499
|
return { ok: false, code: 'INVALID_DELEGATION', error: 'delegationToken must be a string' };
|
|
@@ -2847,6 +2857,8 @@ export class IpcServer {
|
|
|
2847
2857
|
}
|
|
2848
2858
|
}
|
|
2849
2859
|
case 'menu.exec': {
|
|
2860
|
+
// IPC clients such as the restart monitor never execute menus.
|
|
2861
|
+
const { withMenuProcessingTime, logMenuRequestCompleted, logMenuRequestReceived } = await import('./core/command/menu-protocol.js');
|
|
2850
2862
|
const request = cmd.payload && typeof cmd.payload === 'object' && !Array.isArray(cmd.payload)
|
|
2851
2863
|
? cmd.payload
|
|
2852
2864
|
: { type: 'menu.invalid' };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { ownerResolver, OWNERSHIP_AUTHORIZATION_MAX_AGE_MS } from '../core/ownership/owner-resolver.js';
|
|
2
|
+
import { OUTPUT_EVENT } from './protocol.js';
|
|
3
|
+
import { WORKBENCH_EVENT } from '../workbench/protocol.js';
|
|
4
|
+
export const PRIVATE_PROJECTION_EVENTS = [OUTPUT_EVENT, WORKBENCH_EVENT];
|
|
5
|
+
/** Fixed event shares the configured Bus. No pack, connection or switch is created. */
|
|
6
|
+
export function registerOutputEvent(state) {
|
|
7
|
+
const conflicts = state.enabledPacks.filter(pack => pack.register.some(item => PRIVATE_PROJECTION_EVENTS.some(event => event === item.event)));
|
|
8
|
+
for (const pack of conflicts)
|
|
9
|
+
state.invalidPacks.push({ id: pack.id, errors: ['Owner-private projection events are reserved native events'] });
|
|
10
|
+
const ids = new Set(conflicts.map(pack => pack.id));
|
|
11
|
+
state.enabledPacks = state.enabledPacks.filter(pack => !ids.has(pack.id));
|
|
12
|
+
state.catalog = state.catalog.filter(item => !PRIVATE_PROJECTION_EVENTS.some(event => event === item.event) && !ids.has(item.sourcePackId));
|
|
13
|
+
for (const event of PRIVATE_PROJECTION_EVENTS)
|
|
14
|
+
state.catalog.push({ event, ttl: 30, maxTtl: 60,
|
|
15
|
+
schemaVersion: 1, sourcePackId: event === OUTPUT_EVENT ? 'builtin.outputs' : 'builtin.workbench' });
|
|
16
|
+
}
|
|
17
|
+
export function outputAllowlist(aid, result) {
|
|
18
|
+
const owner = ownerResolver.snapshot(aid);
|
|
19
|
+
const subscriber = owner.authorizationStatus === 'verified' && !owner.refreshFailure?.fallbackUsed
|
|
20
|
+
&& (owner.validUntil ?? 0) > Date.now() ? owner.ownerAid : undefined;
|
|
21
|
+
const allowlist = { ...result.allowlist };
|
|
22
|
+
// The SDK ORs wildcard ACLs with named ACLs. Expand them over the other
|
|
23
|
+
// registered events so a stale Owner cannot retain this private subscription.
|
|
24
|
+
const wildcard = allowlist['*'];
|
|
25
|
+
if (wildcard) {
|
|
26
|
+
for (const [event, raw] of Object.entries(allowlist)) {
|
|
27
|
+
if (event === '*' || PRIVATE_PROJECTION_EVENTS.some(privateEvent => privateEvent === event))
|
|
28
|
+
continue;
|
|
29
|
+
const entry = raw;
|
|
30
|
+
allowlist[event] = Object.fromEntries(['publish_aids', 'subscribe_aids'].map(key => [key,
|
|
31
|
+
[...new Set([...(Array.isArray(entry?.[key]) ? entry[key] : []),
|
|
32
|
+
...(Array.isArray(wildcard[key]) ? wildcard[key] : [])])],
|
|
33
|
+
]));
|
|
34
|
+
}
|
|
35
|
+
delete allowlist['*'];
|
|
36
|
+
}
|
|
37
|
+
for (const event of PRIVATE_PROJECTION_EVENTS)
|
|
38
|
+
allowlist[event] = { publish_aids: [aid], subscribe_aids: subscriber ? [subscriber] : [] };
|
|
39
|
+
return { ...result, allowlist };
|
|
40
|
+
}
|
|
41
|
+
export async function assertOutputEventRequest(aid, sender, request, service) {
|
|
42
|
+
const lease = request.op === 'renew' && typeof request.lease_id === 'string'
|
|
43
|
+
? service?.leases?.get(request.lease_id) : undefined;
|
|
44
|
+
const names = [request.event_name, ...(Array.isArray(request.events) ? request.events : []),
|
|
45
|
+
...(Array.isArray(request.scope) ? request.scope.map(item => item?.event_name) : []),
|
|
46
|
+
...(lease?.scope?.map(item => item.event_name) ?? [])];
|
|
47
|
+
if (!PRIVATE_PROJECTION_EVENTS.some(event => names.includes(event)))
|
|
48
|
+
return;
|
|
49
|
+
const scope = Array.isArray(request.scope) ? request.scope : lease?.scope;
|
|
50
|
+
const actions = scope?.map(item => item?.action)
|
|
51
|
+
?? request.actions;
|
|
52
|
+
const publisherOnly = Array.isArray(actions) && actions.length > 0 && actions.every(action => action === 'publish');
|
|
53
|
+
if (sender === aid && (request.op === 'publish' ||
|
|
54
|
+
(request.op === 'authorize' || request.op === 'renew') && publisherOnly))
|
|
55
|
+
return;
|
|
56
|
+
const owner = await ownerResolver.refresh(aid, { maxAgeMs: OWNERSHIP_AUTHORIZATION_MAX_AGE_MS,
|
|
57
|
+
source: 'outputs.events', allowTransient: false });
|
|
58
|
+
if (request.op !== 'publish' && owner.authorizationStatus === 'verified'
|
|
59
|
+
&& !owner.refreshFailure?.fallbackUsed && (owner.validUntil ?? 0) > Date.now() && owner.ownerAid === sender)
|
|
60
|
+
return;
|
|
61
|
+
throw Object.assign(new Error('Output events require the current protocol Owner'), { code: 'FORBIDDEN' });
|
|
62
|
+
}
|