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
|
@@ -8,10 +8,10 @@ import fs from 'node:fs';
|
|
|
8
8
|
import path from 'node:path';
|
|
9
9
|
import { BusHost } from './bus-host.js';
|
|
10
10
|
import { isBusPlaceholder } from './bus-resolver.js';
|
|
11
|
-
import { packLedger } from '
|
|
11
|
+
import { eventPackLedger as packLedger } from '../core/pack-ledger.js';
|
|
12
12
|
import { toSdkAllowlist, toSdkCatalog } from './pack-manager.js';
|
|
13
13
|
import { eventListenerOff, EventCenterError, errorCode, errorMessage } from './types.js';
|
|
14
|
-
import { evaluateEventBusRequest } from './bus-gate.js';
|
|
14
|
+
import { countActiveSubscribers, evaluateEventBusRequest } from './bus-gate.js';
|
|
15
15
|
import { RateWindow } from '../core/rate-window.js';
|
|
16
16
|
/** SDK app.pubsub.v1 事件载荷 → 归一化事件。 */
|
|
17
17
|
export function toReceivedEvent(busAid, payload) {
|
|
@@ -63,8 +63,19 @@ export class EventRuntime {
|
|
|
63
63
|
pendingRetry = new Map();
|
|
64
64
|
reconcileTimer;
|
|
65
65
|
reconciling = false;
|
|
66
|
+
/**
|
|
67
|
+
* `reconfigure` 与 `reconcile` 的串行队列。
|
|
68
|
+
*
|
|
69
|
+
* 两者都读写 `registeredSubBuses` / `registeredPubBuses` / `handlerBuses`,并且在
|
|
70
|
+
* `await client.authorize(...)` 处让出。`reconciling` 只挡住 reconcile 自己重入,
|
|
71
|
+
* 挡不住 reconfigure 插进来——那样 reconcile 恢复后会拿旧的 input 覆盖新基线。
|
|
72
|
+
* 串行而不是丢弃:丢掉一次 reconfigure 会让运行时停在旧的包集合上。
|
|
73
|
+
*/
|
|
74
|
+
serial = Promise.resolve();
|
|
66
75
|
/** 发布限流:按发布方 AID 独立计数(events-config.json 的 rateLimit)。 */
|
|
67
76
|
publishLimiter = new RateWindow();
|
|
77
|
+
/** 已记录发布的 `publisher:eventId`:本地发布到自己的 Bus 时 gate 与 publish 都会看到同一次。 */
|
|
78
|
+
recordedPublications = new Set();
|
|
68
79
|
constructor(options) {
|
|
69
80
|
this.options = options;
|
|
70
81
|
this.busHost = new BusHost({
|
|
@@ -89,16 +100,21 @@ export class EventRuntime {
|
|
|
89
100
|
this.configureContactsWatcher();
|
|
90
101
|
// 1. Bus 宿主(center.enabled 且目录非空)。
|
|
91
102
|
if (input.center.enabled && input.state.catalog.length > 0) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
});
|
|
97
|
-
this.busHost.refreshGate();
|
|
98
|
-
this.reportGateStatus();
|
|
103
|
+
const allowlist = this.deployableAllowlist(input);
|
|
104
|
+
if (!allowlist) {
|
|
105
|
+
// 物化失败且没有可回落的显式规则:**不下发**。让 SDK 侧保留上一次成功的那张,
|
|
106
|
+
// 而不是用空表把所有人挡掉、也不是放宽。原因已经由 status / doctor 报出。
|
|
107
|
+
logger.warn(`[EventCenter] ${this.options.aid} bus start skipped: admission materialization failed (${input.materializeReason ?? 'unknown'})`);
|
|
99
108
|
}
|
|
100
|
-
|
|
101
|
-
|
|
109
|
+
else {
|
|
110
|
+
try {
|
|
111
|
+
await this.busHost.ensureRunning({ catalog: toSdkCatalog(input.state.catalog), allowlist });
|
|
112
|
+
this.busHost.refreshGate();
|
|
113
|
+
this.reportGateStatus();
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
logger.warn(`[EventCenter] ${this.options.aid} bus start deferred: ${errorMessage(error)} (自愈重试中)`);
|
|
117
|
+
}
|
|
102
118
|
}
|
|
103
119
|
}
|
|
104
120
|
// 2. 订阅(先回调、后鉴权、再订阅)。
|
|
@@ -106,20 +122,40 @@ export class EventRuntime {
|
|
|
106
122
|
// 3. 发布授权。
|
|
107
123
|
await this.startPublishers(input);
|
|
108
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* 本次可以下发的 allowlist;`undefined` 表示"这次没有可信的表,别下发"。
|
|
127
|
+
*
|
|
128
|
+
* 优先用扫描结果,其次用当前已生效的那张(重载失败时不回退),最后才现场物化。
|
|
129
|
+
* 现场物化失败(degraded)同样返回 `undefined`——**不要**补成空表(会把所有人挡掉),
|
|
130
|
+
* 也**不要**降级放行(比策略更宽)。
|
|
131
|
+
*/
|
|
132
|
+
deployableAllowlist(input) {
|
|
133
|
+
if (input.materializedAllowlist)
|
|
134
|
+
return input.materializedAllowlist;
|
|
135
|
+
if (this.current?.materializedAllowlist)
|
|
136
|
+
return this.current.materializedAllowlist;
|
|
137
|
+
if (!this.options.materializeAllowlist)
|
|
138
|
+
return toSdkAllowlist(input.center);
|
|
139
|
+
const materialized = this.options.materializeAllowlist(input.center, input.state.catalog.map(entry => entry.event));
|
|
140
|
+
return materialized.degraded ? undefined : materialized.allowlist;
|
|
141
|
+
}
|
|
109
142
|
async updateCenter(center, materialized) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
143
|
+
// 与 reconfigure / reconcile 同队列:三者都改写 `current` 并下发 bus 配置。
|
|
144
|
+
await this.runExclusive(async () => {
|
|
145
|
+
if (!this.current)
|
|
146
|
+
return;
|
|
147
|
+
this.current = { ...this.current, center, materializedAllowlist: materialized.allowlist };
|
|
148
|
+
if (center.enabled && this.current.state.catalog.length > 0 && !materialized.degraded) {
|
|
149
|
+
await this.busHost.apply({ catalog: toSdkCatalog(this.current.state.catalog), allowlist: materialized.allowlist });
|
|
150
|
+
}
|
|
151
|
+
else if (!center.enabled || this.current.state.catalog.length === 0) {
|
|
152
|
+
await this.busHost.apply(null);
|
|
153
|
+
}
|
|
154
|
+
this.configureRematerializeTimer();
|
|
155
|
+
this.configureContactsWatcher();
|
|
156
|
+
this.busHost.refreshGate();
|
|
157
|
+
this.reportGateStatus();
|
|
158
|
+
});
|
|
123
159
|
}
|
|
124
160
|
configureRematerializeTimer() {
|
|
125
161
|
if (this.rematerializeTimer) {
|
|
@@ -153,52 +189,64 @@ export class EventRuntime {
|
|
|
153
189
|
logger.warn(`[EventCenter] ${this.options.aid} admission rematerialization failed: ${errorMessage(error)}`);
|
|
154
190
|
}
|
|
155
191
|
}
|
|
156
|
-
/** 热更新:P0 采用整停整起(退订 → 关闭 → 重新 start)。 */
|
|
157
|
-
async restart(input) {
|
|
158
|
-
await this.stopConnections();
|
|
159
|
-
await this.start(input);
|
|
160
|
-
}
|
|
161
192
|
/**
|
|
162
193
|
* 热更新(增量):不重建任何 AUN 连接,只在现有连接上做 diff。
|
|
163
194
|
*
|
|
164
|
-
*
|
|
195
|
+
* 不要改成整停整起:Bus 是单设备租约,关掉 client 后服务端要几十秒
|
|
165
196
|
* 才释放,立刻重开必然 DEVICE_CONFLICT;而订阅侧刚建好的 sub client 也会因为
|
|
166
197
|
* 对端 Bus 不可用而 authorize 超时,之后不再重试。结果是"文件改了、Bus 挂着、
|
|
167
198
|
* 订阅丢了"。设计 §8 的热更新表本来就要求:改 handler / args / timeout 只换本地
|
|
168
199
|
* 映射不动订阅,加事件才重新 authorize + subscribe,删事件才 unsubscribe。
|
|
169
200
|
*/
|
|
170
201
|
async reconfigure(input) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
this.
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
|
|
202
|
+
await this.runExclusive(async () => {
|
|
203
|
+
const previous = this.current;
|
|
204
|
+
this.closed = false;
|
|
205
|
+
this.current = input;
|
|
206
|
+
this.configureRematerializeTimer();
|
|
207
|
+
this.configureContactsWatcher();
|
|
208
|
+
// 配置已变(新包集合/新解析结果):接入重试从头计退避,随后 diff 自会重排队列。
|
|
209
|
+
this.pendingRetry.clear();
|
|
210
|
+
this.clearReconcileTimer();
|
|
211
|
+
// 顺带清理过期的限流窗口:reload 是低频动作,够用了,不值得单开定时器。
|
|
212
|
+
this.publishLimiter.prune();
|
|
213
|
+
// ① Bus:只有 center 配置或 catalog 变了才动;运行中走 updateConfig(不重启 client)。
|
|
214
|
+
//
|
|
215
|
+
// 物化失败(`deployableAllowlist` 返回 undefined)时**不动 Bus**:保留上一次成功
|
|
216
|
+
// 下发的那张表,由 status / doctor 报出原因。用空表会把人全挡掉,放宽则比策略更宽。
|
|
217
|
+
const allowlist = input.center.enabled && input.state.catalog.length > 0
|
|
218
|
+
? this.deployableAllowlist(input)
|
|
219
|
+
: null;
|
|
220
|
+
const nextBus = allowlist ? { catalog: toSdkCatalog(input.state.catalog), allowlist } : null;
|
|
221
|
+
const materializeFailed = input.center.enabled && input.state.catalog.length > 0 && !allowlist;
|
|
222
|
+
if (materializeFailed) {
|
|
223
|
+
logger.warn(`[EventCenter] ${this.options.aid} bus config kept: admission materialization failed (${input.materializeReason ?? 'unknown'})`);
|
|
224
|
+
}
|
|
225
|
+
else if (!previous || !sameBusConfig(this.busConfigOf(previous), nextBus)) {
|
|
226
|
+
try {
|
|
227
|
+
await this.busHost.apply(nextBus);
|
|
228
|
+
this.busHost.refreshGate();
|
|
229
|
+
this.reportGateStatus();
|
|
230
|
+
}
|
|
231
|
+
catch (error) {
|
|
232
|
+
logger.warn(`[EventCenter] ${this.options.aid} bus apply failed: ${errorMessage(error)}`);
|
|
233
|
+
}
|
|
196
234
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
235
|
+
// ② 订阅:按 bus 求差集。已有 bus 只增删事件,回调与 client 都复用。
|
|
236
|
+
await this.diffSubscribers(input);
|
|
237
|
+
// ③ 发布:新增 bus 或新增事件都要整批重新 authorize(SDK 续期不自动扩 scope)。
|
|
238
|
+
await this.diffPublishers(input);
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* 把 fn 排进串行队列;返回的 Promise 在这次 fn 结束时结算(含异常)。
|
|
243
|
+
*
|
|
244
|
+
* 前一次失败不能让队列断掉,所以 `serial` 只跟踪"是否结束",不传值也不传错。
|
|
245
|
+
*/
|
|
246
|
+
runExclusive(fn) {
|
|
247
|
+
const run = this.serial.then(() => fn());
|
|
248
|
+
this.serial = run.catch(() => undefined);
|
|
249
|
+
return run;
|
|
202
250
|
}
|
|
203
251
|
/** 当前 bus 配置(未启用或无 catalog 时为 null),用于判定是否需要 apply。 */
|
|
204
252
|
busConfigOf(input) {
|
|
@@ -218,19 +266,22 @@ export class EventRuntime {
|
|
|
218
266
|
// "authorize 成功过"的会话,初次失败的洞由这里补。
|
|
219
267
|
/** 对账入口:只做差集,不重建连接、不动 Bus/定时器/watcher(与 reconfigure 的区别)。 */
|
|
220
268
|
async reconcile() {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
this.
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
this.
|
|
233
|
-
|
|
269
|
+
// 判定放进队列里:等待期间 reconfigure 可能已经改了 current 或把 closed 置了。
|
|
270
|
+
await this.runExclusive(async () => {
|
|
271
|
+
if (this.closed || !this.current || this.reconciling)
|
|
272
|
+
return;
|
|
273
|
+
this.reconciling = true;
|
|
274
|
+
try {
|
|
275
|
+
this.prunePendingKeys();
|
|
276
|
+
await this.diffSubscribers(this.current, 'daemon.reconcile');
|
|
277
|
+
await this.diffPublishers(this.current);
|
|
278
|
+
}
|
|
279
|
+
finally {
|
|
280
|
+
this.reconciling = false;
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
if (this.pendingRetry.size === 0)
|
|
284
|
+
this.clearReconcileTimer();
|
|
234
285
|
}
|
|
235
286
|
/** 丢掉已不在期望集合里的重试目标(包删了/改了 bus),否则空差集会空转重试。 */
|
|
236
287
|
prunePendingKeys() {
|
|
@@ -273,6 +324,10 @@ export class EventRuntime {
|
|
|
273
324
|
this.scheduleReconcileRetry('client');
|
|
274
325
|
return undefined;
|
|
275
326
|
}
|
|
327
|
+
// 拿到了 client,'client' 这条退避就该出队。成功路径只删 `sub:` / `pub:` 两类键,
|
|
328
|
+
// 漏了这里的话 pendingRetry 永远非空:reconcile 定时器不会停,每次
|
|
329
|
+
// `state_change: ready` 都会白跑一轮全量差集(设计承诺的是"稳态零 RPC")。
|
|
330
|
+
this.pendingRetry.delete('client');
|
|
276
331
|
if (fresh !== this.client) {
|
|
277
332
|
this.forgetClient('replaced');
|
|
278
333
|
}
|
|
@@ -609,7 +664,41 @@ export class EventRuntime {
|
|
|
609
664
|
retryAfter: decision.retryAfter ?? 60,
|
|
610
665
|
});
|
|
611
666
|
}
|
|
612
|
-
|
|
667
|
+
// `ttl` / `schemaVersion` 是 `publish[]` 里的声明值,两个字段都在 validation 里
|
|
668
|
+
// 校验过、文档也承诺生效,却一直没传给 SDK——配置写了等于没写。调用方显式给的
|
|
669
|
+
// ttl 优先,其余回落到声明值;两处都没有才交给 SDK 缺省。
|
|
670
|
+
const ttl = ttlSeconds ?? entry.ttl;
|
|
671
|
+
const options = {
|
|
672
|
+
...(ttl !== undefined ? { ttlSeconds: ttl } : {}),
|
|
673
|
+
...(entry.schemaVersion !== undefined ? { schemaVersion: entry.schemaVersion } : {}),
|
|
674
|
+
};
|
|
675
|
+
const eventId = await handle.EventService.publish(busAid, eventName, data, Object.keys(options).length > 0 ? options : undefined);
|
|
676
|
+
try {
|
|
677
|
+
// 只有目标 Bus 就是本 Agent 时才看得到订阅集合;发到别人的 Bus 时投递数未知。
|
|
678
|
+
let subscribers = null;
|
|
679
|
+
if (busAid === this.options.aid) {
|
|
680
|
+
const current = this.busHost.subscribers();
|
|
681
|
+
if (current.available) {
|
|
682
|
+
subscribers = new Set(current.subscribers
|
|
683
|
+
.filter(item => item.event === eventName && item.active)
|
|
684
|
+
.map(item => item.aid)).size;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
this.recordPublication({
|
|
688
|
+
packId,
|
|
689
|
+
ts: Date.now(),
|
|
690
|
+
event: eventName,
|
|
691
|
+
bus: busAid,
|
|
692
|
+
publisher: publisherAid ?? this.options.aid,
|
|
693
|
+
...(typeof eventId === 'string' && eventId ? { eventId } : {}),
|
|
694
|
+
subscribers,
|
|
695
|
+
source: 'local',
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
catch {
|
|
699
|
+
// 事件时间线记录失败不影响发布结果。
|
|
700
|
+
}
|
|
701
|
+
return eventId;
|
|
613
702
|
}
|
|
614
703
|
async stopConnections() {
|
|
615
704
|
if (this.rematerializeTimer) {
|
|
@@ -682,19 +771,63 @@ export class EventRuntime {
|
|
|
682
771
|
materialized = materializer(current.center, current.state.catalog.map(entry => entry.event));
|
|
683
772
|
}
|
|
684
773
|
catch (error) {
|
|
685
|
-
|
|
686
|
-
|
|
774
|
+
// 拒而不是放行:这里算不出准入结论,放行等于"比策略更宽"。
|
|
775
|
+
const decision = { allowed: false, operation: String(request.op ?? 'unknown'), reason: 'admission_unavailable' };
|
|
776
|
+
logger.warn(`[EventCenter] ${this.options.aid} L2 gate check failed, rejecting: ${errorMessage(error)}`);
|
|
777
|
+
this.rejectBusRequest(senderAid, decision);
|
|
778
|
+
throw Object.assign(new Error('admission unavailable'), { code: 'FORBIDDEN' });
|
|
687
779
|
}
|
|
688
780
|
if (materialized.degraded) {
|
|
689
|
-
|
|
690
|
-
|
|
781
|
+
const reason = materialized.reason ?? 'unknown';
|
|
782
|
+
const decision = { allowed: false, operation: String(request.op ?? 'unknown'), reason: `admission_degraded: ${reason}` };
|
|
783
|
+
logger.warn(`[EventCenter] ${this.options.aid} L2 gate unavailable (${reason}), rejecting`);
|
|
784
|
+
this.rejectBusRequest(senderAid, decision);
|
|
785
|
+
throw Object.assign(new Error(`admission degraded: ${reason}`), { code: 'FORBIDDEN' });
|
|
691
786
|
}
|
|
692
787
|
const decision = evaluateEventBusRequest(senderAid, request, materialized, service);
|
|
693
|
-
if (decision.allowed)
|
|
694
|
-
|
|
788
|
+
if (decision.allowed) {
|
|
789
|
+
// 发布记录等 SDK 受理成功后写:避免把 TTL/正文校验失败的请求记成已投递。
|
|
790
|
+
if (request.op !== 'publish' || !this.options.onPublished)
|
|
791
|
+
return undefined;
|
|
792
|
+
const event = typeof request.event_name === 'string' ? request.event_name : '';
|
|
793
|
+
if (!event)
|
|
794
|
+
return undefined;
|
|
795
|
+
const packId = current.state.catalog.find(entry => entry.event === event)?.sourcePackId;
|
|
796
|
+
if (!packId)
|
|
797
|
+
return undefined;
|
|
798
|
+
const eventId = typeof request.event_id === 'string' ? request.event_id : undefined;
|
|
799
|
+
const subscribers = countActiveSubscribers(service, event);
|
|
800
|
+
return () => {
|
|
801
|
+
this.recordPublication({
|
|
802
|
+
packId,
|
|
803
|
+
ts: Date.now(),
|
|
804
|
+
event,
|
|
805
|
+
bus: this.options.aid,
|
|
806
|
+
publisher: senderAid,
|
|
807
|
+
...(eventId ? { eventId } : {}),
|
|
808
|
+
subscribers,
|
|
809
|
+
source: 'remote',
|
|
810
|
+
});
|
|
811
|
+
};
|
|
812
|
+
}
|
|
695
813
|
this.rejectBusRequest(senderAid, decision);
|
|
696
814
|
throw Object.assign(new Error(`event request rejected: ${decision.reason ?? 'admission'}`), { code: 'FORBIDDEN' });
|
|
697
815
|
}
|
|
816
|
+
/** 同一次发布(publisher + eventId)只记一行;保留最近 512 个键,超限淘汰最旧。 */
|
|
817
|
+
recordPublication(publication) {
|
|
818
|
+
if (publication.eventId) {
|
|
819
|
+
const key = `${publication.publisher}:${publication.eventId}`;
|
|
820
|
+
if (this.recordedPublications.has(key))
|
|
821
|
+
return;
|
|
822
|
+
this.recordedPublications.add(key);
|
|
823
|
+
if (this.recordedPublications.size > 512) {
|
|
824
|
+
const oldest = this.recordedPublications.values().next().value;
|
|
825
|
+
if (oldest !== undefined)
|
|
826
|
+
this.recordedPublications.delete(oldest);
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
this.options.onPublished?.(publication);
|
|
830
|
+
}
|
|
698
831
|
rejectBusRequest(senderAid, decision) {
|
|
699
832
|
this.options.onBusRequestRejected?.({
|
|
700
833
|
aid: senderAid,
|
|
@@ -719,9 +852,14 @@ export class EventRuntime {
|
|
|
719
852
|
const contactsPath = this.options.contactsPath;
|
|
720
853
|
// 监听条件:bus 宿主活动(allowlist 重物化需要)或 已启用包用占位符($pa 等重解析需要);
|
|
721
854
|
// registry 可通过 input.contactsWatch 强制开(解析失败的包不在 enabledPacks 里,runtime 推导不到)。
|
|
855
|
+
//
|
|
856
|
+
// `contactsWatch` 只能"加"不能"减":它先前是 `??` 的右值,registry 算出 false 时
|
|
857
|
+
// 会把 busHostActive 也一起短路掉——只做 register、bus 全写 `$self` 的包因此从不
|
|
858
|
+
// 挂 contacts 监听,准入物化退化成 5 分钟定时器(与 admission-coupling.md 的
|
|
859
|
+
// "contacts.json 写盘 → 2s 去抖后物化"不符)。
|
|
722
860
|
const busHostActive = Boolean(current?.center.enabled) && (current?.state.catalog.length ?? 0) > 0;
|
|
723
861
|
const usesPlaceholders = (current?.state.enabledPacks ?? []).some(pack => [...pack.publish, ...pack.subscribe].some(entry => isBusPlaceholder(entry.bus)));
|
|
724
|
-
const shouldWatch = current?.contactsWatch ??
|
|
862
|
+
const shouldWatch = busHostActive || (current?.contactsWatch ?? false) || usesPlaceholders;
|
|
725
863
|
if (!contactsPath || !current || !shouldWatch)
|
|
726
864
|
return;
|
|
727
865
|
const contactsDir = path.dirname(contactsPath);
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { spawn } from 'node:child_process';
|
|
9
9
|
import path from 'node:path';
|
|
10
|
-
import { buildTriggerScriptLaunch } from '../trigger/script-sandbox.js';
|
|
11
|
-
import { sanitizeShellExecutionEnvironment } from '../core/permission/shell-environment.js';
|
|
10
|
+
import { buildTriggerScriptLaunch, runPrepareWithDeadline } from '../trigger/script-sandbox.js';
|
|
11
|
+
import { isCredentialEnvironmentName, sanitizeShellExecutionEnvironment } from '../core/permission/shell-environment.js';
|
|
12
12
|
import { resolveRuntimePermissionMode } from '../core/role/runtime-policy.js';
|
|
13
13
|
import { resolvePhaseOneExecutionSandbox } from '../core/permission/mode.js';
|
|
14
14
|
import { killProcessTree, resolveCommandPath } from '../utils/cross-platform.js';
|
|
@@ -76,7 +76,9 @@ export class ScriptRunner {
|
|
|
76
76
|
launch = this.buildLaunch(pack, handler, event, executable, scriptPath, scriptArgs);
|
|
77
77
|
if (launch.prepare) {
|
|
78
78
|
try {
|
|
79
|
-
|
|
79
|
+
// 探针必须设上限:沙箱 provisioning 挂住时这里会无限等待,dispatcher 的
|
|
80
|
+
// 槽位永不释放,并发打满后整个事件中心停摆。探针本身响应 abort。
|
|
81
|
+
await runPrepareWithDeadline(launch.prepare);
|
|
80
82
|
}
|
|
81
83
|
catch (error) {
|
|
82
84
|
// 沙箱不可用 → 降级:清掉这次 launch,改用无沙箱配置重跑。
|
|
@@ -88,7 +90,10 @@ export class ScriptRunner {
|
|
|
88
90
|
}
|
|
89
91
|
catch (error) {
|
|
90
92
|
const code = error.code;
|
|
91
|
-
if (code === 'RUNTIME_NOT_FOUND' || code === 'INVALID_RUNTIME') {
|
|
93
|
+
if (code === 'RUNTIME_NOT_FOUND' || code === 'INVALID_RUNTIME' || code === 'SCRIPT_SANDBOX_UNAVAILABLE') {
|
|
94
|
+
// 拒跑而不是降级:`SCRIPT_SANDBOX_UNAVAILABLE` 来自「拿不到工程目录」这类
|
|
95
|
+
// 本该 fail-closed 的情况(见 event-center/daemon.ts 的 fail-closed 注释)。
|
|
96
|
+
// 把它当沙箱缺失降级,等于把"边界不可证明"变成"无边界执行"。
|
|
92
97
|
return finish({ outcome: 'error', exitCode: 126, error: { code: String(code), message: errorMessage(error) }, stdoutPreview: '', stderrPreview: '' });
|
|
93
98
|
}
|
|
94
99
|
// 沙箱构造失败(缺 codex / 缺 bubblewrap / 平台不支持)→ 降级执行。
|
|
@@ -144,11 +149,11 @@ export class ScriptRunner {
|
|
|
144
149
|
}
|
|
145
150
|
/** 构造启动配置:fullaccess(或 bypass+owner)→ 无沙箱;否则 trigger 沙箱。 */
|
|
146
151
|
buildLaunch(pack, handler, event, executable, scriptPath, scriptArgs) {
|
|
152
|
+
const publisherRole = this.deps.resolvePeerRole?.(event.publisher) ?? undefined;
|
|
147
153
|
const effective = this.deps.permissionMode
|
|
148
154
|
? this.deps.permissionMode()
|
|
149
|
-
: resolveRuntimePermissionMode({ selfAid: this.deps.aid }).effectiveValue;
|
|
155
|
+
: resolveRuntimePermissionMode({ selfAid: this.deps.aid, role: publisherRole }).effectiveValue;
|
|
150
156
|
// 传发布方角色:只有 bypass + owner 才免沙箱(与 trigger 的 owner-bypass 同语义)。
|
|
151
|
-
const publisherRole = this.deps.resolvePeerRole?.(event.publisher) ?? undefined;
|
|
152
157
|
const sandboxDecision = resolvePhaseOneExecutionSandbox(effective, publisherRole);
|
|
153
158
|
const ecEnv = this.buildEcEnv(pack, event);
|
|
154
159
|
if (sandboxDecision.state === 'off') {
|
|
@@ -163,6 +168,7 @@ export class ScriptRunner {
|
|
|
163
168
|
allowed: true,
|
|
164
169
|
scope: 'agent',
|
|
165
170
|
permissionMode: effective,
|
|
171
|
+
role: publisherRole,
|
|
166
172
|
};
|
|
167
173
|
const trigger = this.syntheticTrigger(pack, handler, executable);
|
|
168
174
|
const launch = buildTriggerScriptLaunch({
|
|
@@ -332,6 +338,7 @@ export class ScriptRunner {
|
|
|
332
338
|
}
|
|
333
339
|
/** 脚本契约 stdin(detailed-design §六)。 */
|
|
334
340
|
buildStdin(pack, event) {
|
|
341
|
+
const projectPath = this.deps.getProjectPath();
|
|
335
342
|
return JSON.stringify({
|
|
336
343
|
v: 1,
|
|
337
344
|
pack: { name: pack.name, dir: pack.dir },
|
|
@@ -344,7 +351,9 @@ export class ScriptRunner {
|
|
|
344
351
|
...(event.schemaVersion !== undefined ? { schemaVersion: event.schemaVersion } : {}),
|
|
345
352
|
data: event.data,
|
|
346
353
|
},
|
|
347
|
-
|
|
354
|
+
// File-producing handlers use the scoped project root. Do not make them
|
|
355
|
+
// infer an Agent installation directory that may deny sandbox writes.
|
|
356
|
+
agent: { aid: this.deps.aid, ...(projectPath ? { dir: projectPath } : {}) },
|
|
348
357
|
paths: { ledger: pack.paths.ledger, logs: pack.paths.logsDir },
|
|
349
358
|
});
|
|
350
359
|
}
|
|
@@ -352,5 +361,7 @@ export class ScriptRunner {
|
|
|
352
361
|
function isExcludedEnv(key) {
|
|
353
362
|
if (ENVIRONMENT_EXCLUDES.includes(key))
|
|
354
363
|
return true;
|
|
364
|
+
if (isCredentialEnvironmentName(key))
|
|
365
|
+
return true;
|
|
355
366
|
return key.toUpperCase().startsWith('EVOLCORE_');
|
|
356
367
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 事件中心(Event Center
|
|
2
|
+
* 事件中心(Event Center)共享类型与 SDK 门面适配。
|
|
3
3
|
* 设计:docs/event-center/detailed-design.md;Schema:docs/event-center/schema/。
|
|
4
4
|
*/
|
|
5
5
|
/** 带稳定错误码的错误。 */
|
|
@@ -49,3 +49,11 @@ export function eventListenerOff(client, event, subscription, handler) {
|
|
|
49
49
|
catch { /* 已失效 */ } };
|
|
50
50
|
return () => { };
|
|
51
51
|
}
|
|
52
|
+
/** SDK 0.5.34 stores each Bus role under JSON.stringify([aid, role]). */
|
|
53
|
+
export function getSdkBusBinding(facade, busAid) {
|
|
54
|
+
const buses = facade?.buses;
|
|
55
|
+
if (!(buses instanceof Map))
|
|
56
|
+
return undefined;
|
|
57
|
+
// Prefer the Bus role when the same AID also has publisher/subscriber bindings.
|
|
58
|
+
return buses.get(JSON.stringify([busAid, 'bus'])) ?? buses.get(busAid);
|
|
59
|
+
}
|
|
@@ -14,6 +14,24 @@ export const EVENT_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
|
14
14
|
export const ROLE_NAME_PATTERN = /^[a-z0-9_-]+$/;
|
|
15
15
|
export const SCRIPT_EXTENSIONS = ['mjs', 'cjs', 'js', 'py', 'sh', 'ps1'];
|
|
16
16
|
export const RUNTIME_WHITELIST = ['node', 'python', 'bash', 'powershell'];
|
|
17
|
+
/**
|
|
18
|
+
* 扩展名 → 运行时的本地映射(已知扩展名恒有值)。
|
|
19
|
+
*
|
|
20
|
+
* 不复用 `script-runner` 的 `inferRuntime`:`validation → script-runner →
|
|
21
|
+
* pack-loader → validation` 会成环。两边本来就是同一张表,这里只保证校验期能判自洽。
|
|
22
|
+
*/
|
|
23
|
+
function runtimeForExtension(script) {
|
|
24
|
+
const ext = script.split('.').pop()?.toLowerCase();
|
|
25
|
+
if (ext === 'mjs' || ext === 'cjs' || ext === 'js')
|
|
26
|
+
return 'node';
|
|
27
|
+
if (ext === 'py')
|
|
28
|
+
return 'python';
|
|
29
|
+
if (ext === 'sh')
|
|
30
|
+
return 'bash';
|
|
31
|
+
if (ext === 'ps1')
|
|
32
|
+
return 'powershell';
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
17
35
|
const TTL_CEILING = 3600;
|
|
18
36
|
const TIMEOUT_MIN = 1000;
|
|
19
37
|
const TIMEOUT_MAX = 300_000;
|
|
@@ -170,6 +188,15 @@ function validateHandler(raw, errors) {
|
|
|
170
188
|
if (raw.runtime !== undefined && !RUNTIME_WHITELIST.includes(raw.runtime)) {
|
|
171
189
|
errors.push(`handler.runtime must be one of ${RUNTIME_WHITELIST.join('/')}`);
|
|
172
190
|
}
|
|
191
|
+
else if (script !== undefined && raw.runtime !== undefined) {
|
|
192
|
+
// runtime 与扩展名必须自洽:`runtime: "python"` 配 `.mjs` 能过枚举校验,却在
|
|
193
|
+
// 运行时才因解释器不认脚本而失败。schema 也这么写("推断不出判校验失败"),
|
|
194
|
+
// 这里提前到加载期。
|
|
195
|
+
const inferred = runtimeForExtension(script);
|
|
196
|
+
if (inferred !== undefined && inferred !== raw.runtime) {
|
|
197
|
+
errors.push(`handler.runtime "${String(raw.runtime)}" does not match the script extension (expected "${inferred}"): ${script}`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
173
200
|
if (raw.args !== undefined) {
|
|
174
201
|
if (!Array.isArray(raw.args) || raw.args.some(item => typeof item !== 'string'))
|
|
175
202
|
errors.push('handler.args must be an array of strings');
|
|
@@ -368,10 +395,12 @@ export function validateCenterConfig(raw) {
|
|
|
368
395
|
const rateExtra = Object.keys(raw.rateLimit).filter(key => !['perMinute', 'perHour'].includes(key));
|
|
369
396
|
if (rateExtra.length)
|
|
370
397
|
errors.push(`rateLimit has unknown fields: ${rateExtra.join(', ')}`);
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
398
|
+
const perMinute = intInRange(raw.rateLimit.perMinute, 'rateLimit.perMinute', 1, Number.MAX_SAFE_INTEGER, errors) ?? 60;
|
|
399
|
+
const perHour = intInRange(raw.rateLimit.perHour, 'rateLimit.perHour', 1, Number.MAX_SAFE_INTEGER, errors) ?? 600;
|
|
400
|
+
// 分钟额度大于小时额度时小时那格永远轮不到,配置读起来像是生效其实没用。
|
|
401
|
+
if (perMinute > perHour)
|
|
402
|
+
errors.push('rateLimit.perMinute must be <= rateLimit.perHour');
|
|
403
|
+
rateLimit = { perMinute, perHour };
|
|
375
404
|
}
|
|
376
405
|
}
|
|
377
406
|
const rules = {};
|