evolcore 0.0.47 → 0.0.49
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 +90 -1
- package/bin/ec-build.mjs +86 -0
- package/dist/agent-template/jobs.js +12 -4
- package/dist/agent-template/runtime.js +143 -40
- package/dist/agent-template/service.js +66 -13
- package/dist/agents/baseagent.js +60 -20
- package/dist/agents/claude-runner.js +34 -17
- package/dist/agents/codex-runner.js +36 -17
- 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/msg/p2p.js +2 -1
- package/dist/aun/service-proxy.js +4 -2
- package/dist/build-identity.json +1 -0
- package/dist/channels/aun.js +722 -295
- package/dist/channels/daemon.js +9 -25
- 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 +44 -43
- package/dist/cli/directory.js +13 -2
- package/dist/cli/ecmsg-gateway.js +5 -2
- package/dist/cli/index.js +9 -9
- package/dist/cli/init-channel.js +4 -6
- package/dist/cli/init.js +72 -50
- package/dist/cli/invoke-command.js +1 -1
- package/dist/cli/managed-command-guard.js +2 -0
- package/dist/cli/model.js +20 -5
- package/dist/cli/provider-command.js +74 -13
- package/dist/cli/quota.js +89 -0
- package/dist/cli/role.js +62 -17
- package/dist/cli/services-command.js +1 -0
- package/dist/cli/stats.js +3 -3
- package/dist/cli/team-workspace-command.js +56 -2
- package/dist/cli/thread-command.js +16 -51
- package/dist/config/boot-log.js +3 -9
- package/dist/config/builtin-roles.js +5 -7
- package/dist/config/config-field-policy.js +71 -1
- package/dist/config/config-manager.js +13 -7
- 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 +62 -229
- package/dist/config/peer-book.js +26 -27
- package/dist/config/peer-role-resolver.js +16 -1
- package/dist/config/provider-identity-migration.js +4 -1
- 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 +67 -12
- package/dist/config/providers-management.js +477 -51
- package/dist/config/resolved-config-op.js +3 -2
- package/dist/config/role-command-service.js +248 -1
- package/dist/config/schema-migration.js +105 -4
- package/dist/core/agent-application-service.js +6 -1
- package/dist/core/agent-runtime.js +4 -0
- package/dist/core/auth/agent-delegation.js +2 -1
- package/dist/core/auth/auth-gateway.js +2 -1
- package/dist/core/auth/delegation-authorization.js +36 -26
- package/dist/core/auth/operation-authorizer.js +25 -0
- package/dist/core/auth/operation-catalog.js +37 -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/cli-intent-parser.js +13 -0
- package/dist/core/command/command-handler.js +126 -87
- package/dist/core/command/menu-catalog.js +1 -0
- package/dist/core/command/menu-handler.js +67 -150
- package/dist/core/command/menu-protocol.js +31 -1
- package/dist/core/command/provider-menu.js +13 -3
- package/dist/core/command/remote-shell.js +565 -0
- package/dist/core/command/role-menu.js +47 -23
- package/dist/core/command/slash-handler.js +26 -43
- 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 +8 -1
- package/dist/core/daemon-control.js +64 -8
- package/dist/core/daemon-lifecycle.js +16 -2
- package/dist/core/evolagent-registry.js +20 -3
- package/dist/core/file-integrity/store.js +2 -0
- package/dist/core/handoff/runtime.js +37 -1
- package/dist/core/inference/text-inference.js +3 -1
- package/dist/core/initialization/service.js +11 -6
- package/dist/core/interaction-router.js +3 -0
- package/dist/core/invoke/executors/text.js +72 -19
- package/dist/core/ipc-registration.js +3 -1
- package/dist/core/message/aun-ipc-sender.js +279 -107
- package/dist/core/message/contact-admission.js +91 -6
- package/dist/core/message/contact-pending-inbound.js +113 -0
- package/dist/core/message/contact-thread-approval.js +212 -0
- package/dist/core/message/im-renderer.js +41 -2
- package/dist/core/message/message-admission.js +5 -39
- package/dist/core/message/message-bridge.js +140 -370
- package/dist/core/message/message-log.js +29 -0
- package/dist/core/message/message-queue.js +119 -15
- package/dist/core/message/message-utils.js +8 -0
- package/dist/core/message/response-engine.js +580 -134
- package/dist/core/message/send-routing.js +5 -1
- package/dist/core/model/catalog-service.js +31 -11
- package/dist/core/model/config-scope.js +6 -14
- package/dist/core/model/model-capabilities.js +22 -4
- package/dist/core/model/model-catalog.js +1 -0
- package/dist/core/model/model-diagnostics.js +19 -0
- package/dist/core/model/model-fallback.js +13 -2
- package/dist/core/ownership/owner-resolver.js +328 -50
- package/dist/core/pack-auth.js +3 -0
- package/dist/core/pack-install.js +1 -1
- package/dist/core/permission/ec-command-parser.js +106 -19
- package/dist/core/permission/protected-paths.js +6 -6
- package/dist/core/permission/services-path-acl.js +451 -0
- package/dist/core/permission/tool-policy.js +5 -1
- package/dist/core/relation/peer-identity.js +36 -1
- package/dist/core/relation/same-owner-proof.js +81 -112
- package/dist/core/session/adapters/codex-session-file-adapter.js +96 -15
- package/dist/core/session/session-file-health.js +13 -7
- 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-recovery-service.js +13 -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/core/thread/topic-id.js +15 -0
- package/dist/directory/owner-directory-admission.js +12 -9
- package/dist/directory/owner-directory-cache.js +64 -28
- package/dist/directory/owner-directory-markdown.js +14 -2
- package/dist/directory/owner-directory-policy.js +5 -30
- package/dist/directory/owner-directory-query-operation.js +29 -3
- package/dist/directory/owner-directory-remarks.js +11 -3
- package/dist/directory/owner-directory-request-operation.js +5 -2
- package/dist/eck/kit-renderer.js +1 -1
- package/dist/eck/message-renderer.js +112 -29
- 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 +18 -8
- package/dist/ecweb/runtime/proxy-access.js +74 -0
- package/dist/ecweb/runtime/supervisor.js +36 -6
- package/dist/event-center/center-config.js +9 -5
- package/dist/event-center/dispatcher.js +10 -1
- package/dist/event-center/ipc-operation.js +19 -0
- package/dist/event-center/registry.js +29 -3
- package/dist/event-center/runtime.js +106 -11
- package/dist/event-center/script-runner.js +5 -5
- package/dist/index.js +96 -59
- package/dist/ipc.js +38 -3
- package/dist/outputs/authorization.js +16 -0
- package/dist/outputs/cards.js +336 -0
- package/dist/outputs/events.js +63 -0
- package/dist/outputs/protocol.js +103 -0
- package/dist/outputs/service.js +266 -0
- package/dist/paths.js +3 -0
- package/dist/proxy/manager.js +43 -13
- package/dist/services/index.js +114 -5
- package/dist/services/ipc-operation.js +88 -15
- package/dist/services/pack-manager.js +13 -1
- package/dist/services/router.js +21 -6
- package/dist/services/script-runner.js +5 -4
- package/dist/services/service-payload.js +13 -7
- package/dist/services/validation.js +1 -1
- package/dist/stats/budget.js +2 -2
- package/dist/stats/db.js +19 -0
- package/dist/stats/index.js +1 -1
- package/dist/stats/{price-resolver.js → model-resolver.js} +304 -23
- package/dist/stats/normalizer.js +2 -0
- package/dist/stats/query.js +35 -27
- package/dist/stats/quota-query.js +95 -0
- 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 +7 -5
- package/dist/trigger/script-executor.js +2 -1
- package/dist/trigger/script-sandbox.js +21 -3
- package/dist/trigger/validation.js +22 -0
- package/dist/utils/atomic-write.js +22 -8
- package/dist/utils/cross-platform.js +73 -26
- package/dist/utils/error-dict.json +94 -4
- package/dist/utils/error-utils.js +27 -4
- package/dist/utils/evolcore-version.js +36 -65
- package/dist/utils/host-info.js +100 -1
- package/dist/utils/msg-diag.js +1 -0
- package/dist/utils/npm-ops.js +43 -8
- package/dist/utils/process-introspect.js +12 -7
- package/dist/utils/process-tree.js +50 -2
- 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 +4 -2
- package/kits/docs/evolcore/aid.md +25 -0
- package/kits/docs/evolcore/config.md +16 -1
- package/kits/docs/evolcore/directory.md +30 -12
- package/kits/docs/evolcore/ecweb-lifecycle.md +15 -0
- package/kits/docs/evolcore/model.md +10 -0
- package/kits/docs/evolcore/msg.md +9 -0
- package/kits/docs/evolcore/peer.md +19 -65
- package/kits/docs/evolcore/provider.md +124 -4
- package/kits/docs/evolcore/quota.md +54 -0
- package/kits/docs/evolcore/role.md +83 -0
- package/kits/docs/evolcore/services.md +6 -6
- package/kits/docs/evolcore/stats.md +2 -0
- 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 +12 -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/agent-config.schema.20.json +24 -0
- package/kits/schemas/contact-book.schema.4.json +52 -0
- package/kits/schemas/providers.schema.3.json +200 -0
- package/kits/skills/.switches.json +8 -0
- package/kits/skills/ability/references/calling.md +1 -1
- package/kits/skills/agent-output-cards/SKILL.md +57 -0
- 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 +270 -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/roles/visitor.json +1 -0
- package/kits/templates/system-fragments/baseagent.md +6 -0
- package/kits/templates/system-fragments/commands.md +4 -3
- package/kits/templates/system-fragments/directory-contacts.md +3 -4
- 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 +7 -5
- package/kits/templates/system-fragments/venue.md +11 -0
- package/package.json +6 -4
- package/scripts/agent-template/inspect.mjs +50 -11
- package/scripts/agent-template/shared/common.mjs +11 -6
- package/scripts/agent-template/shared/team-schema.json +6 -4
- package/scripts/agent-template/shared/template-contract.mjs +62 -11
- package/scripts/agent-template/shared/template-package.mjs +189 -21
- package/scripts/agent-template/shared/template-runtime.mjs +54 -6
- package/scripts/agent-template/shared/template.mjs +2 -2
- package/scripts/agent-template/team-pack.mjs +52 -14
- 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
|
@@ -17,13 +17,18 @@ function resolveEntryBus(resolutions, packId, entry) {
|
|
|
17
17
|
export class EventDispatcher {
|
|
18
18
|
scriptRunner;
|
|
19
19
|
limits;
|
|
20
|
+
canDispatch;
|
|
20
21
|
queues = new Map();
|
|
21
22
|
running = 0;
|
|
22
23
|
closed = false;
|
|
23
24
|
idleResolvers = [];
|
|
24
|
-
constructor(scriptRunner, limits = DEFAULT_DISPATCHER_LIMITS) {
|
|
25
|
+
constructor(scriptRunner, limits = DEFAULT_DISPATCHER_LIMITS, canDispatch = () => true) {
|
|
25
26
|
this.scriptRunner = scriptRunner;
|
|
26
27
|
this.limits = limits;
|
|
28
|
+
this.canDispatch = canDispatch;
|
|
29
|
+
}
|
|
30
|
+
isBusy() {
|
|
31
|
+
return this.running > 0 || !this.isEmpty();
|
|
27
32
|
}
|
|
28
33
|
setLimits(limits) {
|
|
29
34
|
this.limits = { ...this.limits, ...limits };
|
|
@@ -40,6 +45,10 @@ export class EventDispatcher {
|
|
|
40
45
|
const log = EventLog.forPack(pack);
|
|
41
46
|
// 写前日志:received 一定先落盘。
|
|
42
47
|
log.writeReceived(event);
|
|
48
|
+
if (!this.canDispatch()) {
|
|
49
|
+
log.writeDropped(event, 'agent_mutation_paused');
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
43
52
|
if (entry.filter && !this.matches(entry.filter, event)) {
|
|
44
53
|
log.writeFiltered(event, 'filter_mismatch');
|
|
45
54
|
continue;
|
|
@@ -13,6 +13,7 @@ import { installPack, listPackDirs, removePack, setPackEnabled } from '../core/p
|
|
|
13
13
|
import { CenterConfigStore } from './center-config.js';
|
|
14
14
|
import { agentEventsDir } from '../paths.js';
|
|
15
15
|
import { authorizePackTarget, packOperation } from '../core/pack-auth.js';
|
|
16
|
+
import { OUTPUT_CARDS_EVENT } from '../outputs/protocol.js';
|
|
16
17
|
const HELP = `ec events — 事件中心运维
|
|
17
18
|
|
|
18
19
|
用法:
|
|
@@ -121,6 +122,9 @@ export function parseEventsArgv(argv) {
|
|
|
121
122
|
parsed.command = `rules:${positional[0] ?? ''}`;
|
|
122
123
|
parsed.event = parsed.event ?? positional[1];
|
|
123
124
|
}
|
|
125
|
+
else if (command === 'native-publish') {
|
|
126
|
+
parsed.nativeEvent = positional[0];
|
|
127
|
+
}
|
|
124
128
|
return parsed;
|
|
125
129
|
}
|
|
126
130
|
function resolveAid(deps, parsed, opts = {}) {
|
|
@@ -200,6 +204,21 @@ async function execute(deps, parsed) {
|
|
|
200
204
|
});
|
|
201
205
|
if (!auth.allowed)
|
|
202
206
|
return { ok: false, code: auth.code, error: auth.error };
|
|
207
|
+
if (command === 'native-publish') {
|
|
208
|
+
const data = parsed.data;
|
|
209
|
+
if (parsed.caller?.kind !== 'managed' || parsed.caller.selfAid !== aid
|
|
210
|
+
|| parsed.caller.peerRole !== 'owner'
|
|
211
|
+
|| parsed.nativeEvent !== OUTPUT_CARDS_EVENT || !data || typeof data !== 'object' || Array.isArray(data)
|
|
212
|
+
|| data.sourceAid !== aid || typeof data.revision !== 'string'
|
|
213
|
+
|| typeof data.cursor !== 'string') {
|
|
214
|
+
return { ok: false, code: 'NOT_ALLOWED', error: 'Native output-card notifications may only be published for the current Agent' };
|
|
215
|
+
}
|
|
216
|
+
const published = await deps.registry.publishAgentEvent(aid, OUTPUT_CARDS_EVENT, data);
|
|
217
|
+
if (!published) {
|
|
218
|
+
return { ok: false, code: 'EVENT_CENTER_NOT_RUNNING', error: `output-card notifications are unavailable for ${aid}` };
|
|
219
|
+
}
|
|
220
|
+
return { ok: true, result: { aid, event: OUTPUT_CARDS_EVENT } };
|
|
221
|
+
}
|
|
203
222
|
if (command === 'reload') {
|
|
204
223
|
await deps.registry.reload(aid);
|
|
205
224
|
const unit = deps.registry.get(aid);
|
|
@@ -19,6 +19,7 @@ import { PublicationLog } from './event-log.js';
|
|
|
19
19
|
import { ScriptRunner } from './script-runner.js';
|
|
20
20
|
import { errorMessage } from './types.js';
|
|
21
21
|
import { readBusResolverContext } from './directory-source.js';
|
|
22
|
+
import { registerOutputEvent, outputAllowlist } from '../outputs/events.js';
|
|
22
23
|
/** 旧方案残留的订阅 Trigger(labels.kind=bus-subscription),启动时一次性清理。 */
|
|
23
24
|
const LEGACY_SUBSCRIPTION_KIND = 'bus-subscription';
|
|
24
25
|
/** 解析上下文签名:只有 owner/pa/paRoles 三要素参与(fetchedAt 等时间戳字段不参与,
|
|
@@ -39,6 +40,21 @@ export class EventCenterRegistry {
|
|
|
39
40
|
scanLedgerSigs = new Map();
|
|
40
41
|
/** reload 串行队列:aid → 队尾 promise。 */
|
|
41
42
|
reloadQueues = new Map();
|
|
43
|
+
mutationPauses = new Map();
|
|
44
|
+
/** Freeze handler starts without replacing the Agent's AUN connection or Bus lease. */
|
|
45
|
+
pauseForMutation(aid, token) {
|
|
46
|
+
if (this.units.get(aid)?.dispatcher.isBusy()) {
|
|
47
|
+
throw Object.assign(new Error('Agent event handlers are busy: ' + aid), { code: 'AGENT_BUSY' });
|
|
48
|
+
}
|
|
49
|
+
const tokens = this.mutationPauses.get(aid) ?? new Set();
|
|
50
|
+
tokens.add(token);
|
|
51
|
+
this.mutationPauses.set(aid, tokens);
|
|
52
|
+
return () => {
|
|
53
|
+
tokens.delete(token);
|
|
54
|
+
if (!tokens.size && this.mutationPauses.get(aid) === tokens)
|
|
55
|
+
this.mutationPauses.delete(aid);
|
|
56
|
+
};
|
|
57
|
+
}
|
|
42
58
|
/** 签名未变则跳过 append。 */
|
|
43
59
|
ledgerOnce(aid, key, sig, append) {
|
|
44
60
|
let sigs = this.scanLedgerSigs.get(aid);
|
|
@@ -64,6 +80,15 @@ export class EventCenterRegistry {
|
|
|
64
80
|
values() {
|
|
65
81
|
return this.units.values();
|
|
66
82
|
}
|
|
83
|
+
/** Publish a fixed event from an internal read-only projection when configured. */
|
|
84
|
+
async publishAgentEvent(aid, event, data) {
|
|
85
|
+
if (event !== 'team.outputs.changed' && event !== 'team.output-cards.changed' && event !== 'team.workbench.changed')
|
|
86
|
+
return false;
|
|
87
|
+
const unit = this.units.get(aid);
|
|
88
|
+
if (!unit)
|
|
89
|
+
return false;
|
|
90
|
+
return unit.runtime.publishNativeProjection(event, data);
|
|
91
|
+
}
|
|
67
92
|
ensureStarted(aid) {
|
|
68
93
|
const existing = this.starts.get(aid);
|
|
69
94
|
if (existing)
|
|
@@ -185,6 +210,7 @@ export class EventCenterRegistry {
|
|
|
185
210
|
// ① 扫描 + 校验。
|
|
186
211
|
const loaded = loadPacks(eventsDir);
|
|
187
212
|
const state = buildPackState(loaded.valid, loaded.invalid.map(item => ({ id: item.packId, errors: item.errors })));
|
|
213
|
+
registerOutputEvent(state);
|
|
188
214
|
// ② 台账:invalid / load(签名去重)。
|
|
189
215
|
for (const item of loaded.invalid) {
|
|
190
216
|
const reason = item.errors.join('; ').slice(0, 500);
|
|
@@ -262,7 +288,7 @@ export class EventCenterRegistry {
|
|
|
262
288
|
for (const error of centerResult.errors) {
|
|
263
289
|
logger.warn(`[EventCenter] ${aid} events-config.json: ${error}`);
|
|
264
290
|
}
|
|
265
|
-
const materialized = materializeAllowlist(centerResult.config, agentDirPath, aid, runtimeState.catalog.map(entry => entry.event));
|
|
291
|
+
const materialized = outputAllowlist(aid, materializeAllowlist(centerResult.config, agentDirPath, aid, runtimeState.catalog.map(entry => entry.event)));
|
|
266
292
|
// contacts 监听需求:包里有占位符引用(含被解析淘汰的包——它们在 enabledPacks 里)
|
|
267
293
|
// 或上次解析有失败/degraded(等 contacts 到位后重解析)。
|
|
268
294
|
const usesPlaceholderRefs = loaded.valid.some(pack => [...pack.publish, ...pack.subscribe].some(entry => isBusPlaceholder(entry.bus)));
|
|
@@ -338,13 +364,13 @@ export class EventCenterRegistry {
|
|
|
338
364
|
}
|
|
339
365
|
},
|
|
340
366
|
});
|
|
341
|
-
const dispatcher = new EventDispatcher(scriptRunner);
|
|
367
|
+
const dispatcher = new EventDispatcher(scriptRunner, undefined, () => !this.mutationPauses.get(aid)?.size);
|
|
342
368
|
const runtime = new EventRuntime({
|
|
343
369
|
aid,
|
|
344
370
|
getClient: this.options.getClient,
|
|
345
371
|
contactsPath: path.join(agentDirPath, 'directory', 'contacts.json'),
|
|
346
372
|
onContactsChanged: () => this.handleContactsChanged(aid),
|
|
347
|
-
materializeAllowlist: (center, registeredEvents) => materializeAllowlist(center, agentDirPath, aid, registeredEvents),
|
|
373
|
+
materializeAllowlist: (center, registeredEvents) => outputAllowlist(aid, materializeAllowlist(center, agentDirPath, aid, registeredEvents)),
|
|
348
374
|
onBusRequestRejected: entry => centerLedger(eventsDir).append({
|
|
349
375
|
action: 'bus.request.rejected', result: 'failed', aid: entry.aid, operation: entry.operation,
|
|
350
376
|
...(entry.event ? { event: entry.event } : {}), ...(entry.action ? { direction: entry.action } : {}),
|
|
@@ -13,6 +13,9 @@ import { toSdkAllowlist, toSdkCatalog } from './pack-manager.js';
|
|
|
13
13
|
import { eventListenerOff, EventCenterError, errorCode, errorMessage } from './types.js';
|
|
14
14
|
import { countActiveSubscribers, evaluateEventBusRequest } from './bus-gate.js';
|
|
15
15
|
import { RateWindow } from '../core/rate-window.js';
|
|
16
|
+
import { assertOutputEventRequest, outputAllowlist, PRIVATE_PROJECTION_EVENTS } from '../outputs/events.js';
|
|
17
|
+
import { OUTPUT_EVENT } from '../outputs/protocol.js';
|
|
18
|
+
import { ownerResolver, OWNERSHIP_AUTHORIZATION_MAX_AGE_MS } from '../core/ownership/owner-resolver.js';
|
|
16
19
|
/** SDK app.pubsub.v1 事件载荷 → 归一化事件。 */
|
|
17
20
|
export function toReceivedEvent(busAid, payload) {
|
|
18
21
|
const eventName = typeof payload.event_name === 'string' ? payload.event_name : '';
|
|
@@ -92,10 +95,64 @@ export class EventRuntime {
|
|
|
92
95
|
get packs() { return this.current?.state.enabledPacks ?? []; }
|
|
93
96
|
get resolutions() { return this.current?.resolutions ?? new Map(); }
|
|
94
97
|
get center() { return this.current?.center; }
|
|
98
|
+
get nativeOutputAvailable() { return this.current?.center.enabled === true && this.busHost.status === 'running' && this.busHost.gateInstalled; }
|
|
99
|
+
nativeOutputPublisher;
|
|
100
|
+
nativeOutputFlight;
|
|
101
|
+
nativeOutputPending = new Map();
|
|
102
|
+
outputOwnerOff;
|
|
103
|
+
async publishNativeOutput(data) {
|
|
104
|
+
return this.publishNativeProjection(OUTPUT_EVENT, data);
|
|
105
|
+
}
|
|
106
|
+
async publishNativeProjection(event, data) {
|
|
107
|
+
if (!PRIVATE_PROJECTION_EVENTS.some(value => value === event))
|
|
108
|
+
return false;
|
|
109
|
+
if (!this.nativeOutputAvailable)
|
|
110
|
+
return false;
|
|
111
|
+
this.nativeOutputPending.set(event, data);
|
|
112
|
+
if (this.nativeOutputFlight)
|
|
113
|
+
return this.nativeOutputFlight;
|
|
114
|
+
this.nativeOutputFlight = (async () => {
|
|
115
|
+
// Bound a burst to one in-flight notification and one latest invalidation.
|
|
116
|
+
while (this.nativeOutputPending.size) {
|
|
117
|
+
if (!this.nativeOutputAvailable)
|
|
118
|
+
return false;
|
|
119
|
+
const [event, latest] = this.nativeOutputPending.entries().next().value;
|
|
120
|
+
this.nativeOutputPending.delete(event);
|
|
121
|
+
const handle = await this.ensureClient();
|
|
122
|
+
if (!handle || !this.nativeOutputAvailable)
|
|
123
|
+
return false;
|
|
124
|
+
const owner = await ownerResolver.refresh(this.options.aid, { source: 'outputs.publish',
|
|
125
|
+
maxAgeMs: OWNERSHIP_AUTHORIZATION_MAX_AGE_MS, allowTransient: false });
|
|
126
|
+
if (!await this.rematerialize())
|
|
127
|
+
return false;
|
|
128
|
+
if (owner.authorizationStatus !== 'verified' || owner.refreshFailure?.fallbackUsed
|
|
129
|
+
|| (owner.validUntil ?? 0) <= Date.now() || !this.nativeOutputAvailable)
|
|
130
|
+
return false;
|
|
131
|
+
const events = new Set([...PRIVATE_PROJECTION_EVENTS, ...(this.registeredPubBuses.get(this.options.aid) ?? [])]);
|
|
132
|
+
if (this.nativeOutputPublisher !== handle || PRIVATE_PROJECTION_EVENTS.some(value => !this.registeredPubBuses.get(this.options.aid)?.has(value))) {
|
|
133
|
+
await handle.EventService.authorize(this.options.aid, 'pub', 'allowlist', [...events]);
|
|
134
|
+
this.registeredPubBuses.set(this.options.aid, events);
|
|
135
|
+
this.nativeOutputPublisher = handle;
|
|
136
|
+
}
|
|
137
|
+
const currentOwner = ownerResolver.snapshot(this.options.aid);
|
|
138
|
+
if (currentOwner.authorizationStatus !== 'verified' || currentOwner.refreshFailure?.fallbackUsed
|
|
139
|
+
|| (currentOwner.validUntil ?? 0) <= Date.now() || currentOwner.ownerAid !== owner.ownerAid
|
|
140
|
+
|| currentOwner.revision !== owner.revision || !this.nativeOutputAvailable)
|
|
141
|
+
return false;
|
|
142
|
+
await handle.EventService.publish(this.options.aid, event, latest, { ttlSeconds: 30, schemaVersion: 1 });
|
|
143
|
+
}
|
|
144
|
+
return true;
|
|
145
|
+
})().finally(() => { this.nativeOutputFlight = undefined; this.nativeOutputPending.clear(); });
|
|
146
|
+
return this.nativeOutputFlight;
|
|
147
|
+
}
|
|
95
148
|
/** 启动:Bus(可选)→ 订阅 → 发布。任何一侧失败只记日志/台账,不影响其它侧。 */
|
|
96
149
|
async start(input) {
|
|
97
150
|
this.closed = false;
|
|
98
151
|
this.current = input;
|
|
152
|
+
this.outputOwnerOff ??= ownerResolver.onUpdate(aid => {
|
|
153
|
+
if (aid === this.options.aid && !this.closed)
|
|
154
|
+
void this.rematerialize();
|
|
155
|
+
});
|
|
99
156
|
this.configureRematerializeTimer();
|
|
100
157
|
this.configureContactsWatcher();
|
|
101
158
|
// 1. Bus 宿主(center.enabled 且目录非空)。
|
|
@@ -131,22 +188,28 @@ export class EventRuntime {
|
|
|
131
188
|
*/
|
|
132
189
|
deployableAllowlist(input) {
|
|
133
190
|
if (input.materializedAllowlist)
|
|
134
|
-
return input.materializedAllowlist;
|
|
191
|
+
return this.protectOutputAllowlist(input, input.materializedAllowlist);
|
|
135
192
|
if (this.current?.materializedAllowlist)
|
|
136
|
-
return this.current.materializedAllowlist;
|
|
193
|
+
return this.protectOutputAllowlist(input, this.current.materializedAllowlist);
|
|
137
194
|
if (!this.options.materializeAllowlist)
|
|
138
|
-
return toSdkAllowlist(input.center);
|
|
195
|
+
return this.protectOutputAllowlist(input, toSdkAllowlist(input.center));
|
|
139
196
|
const materialized = this.options.materializeAllowlist(input.center, input.state.catalog.map(entry => entry.event));
|
|
140
|
-
return materialized.degraded ? undefined : materialized.allowlist;
|
|
197
|
+
return materialized.degraded ? undefined : this.protectOutputAllowlist(input, materialized.allowlist);
|
|
198
|
+
}
|
|
199
|
+
protectOutputAllowlist(input, allowlist) {
|
|
200
|
+
return input.state.catalog.some(entry => entry.event === OUTPUT_EVENT)
|
|
201
|
+
? outputAllowlist(this.options.aid, { degraded: false, admittedAids: [], allowlist }).allowlist
|
|
202
|
+
: allowlist;
|
|
141
203
|
}
|
|
142
204
|
async updateCenter(center, materialized) {
|
|
143
205
|
// 与 reconfigure / reconcile 同队列:三者都改写 `current` 并下发 bus 配置。
|
|
144
206
|
await this.runExclusive(async () => {
|
|
145
207
|
if (!this.current)
|
|
146
208
|
return;
|
|
147
|
-
|
|
209
|
+
const allowlist = this.protectOutputAllowlist(this.current, materialized.allowlist);
|
|
210
|
+
this.current = { ...this.current, center, materializedAllowlist: allowlist };
|
|
148
211
|
if (center.enabled && this.current.state.catalog.length > 0 && !materialized.degraded) {
|
|
149
|
-
await this.busHost.apply({ catalog: toSdkCatalog(this.current.state.catalog), allowlist
|
|
212
|
+
await this.busHost.apply({ catalog: toSdkCatalog(this.current.state.catalog), allowlist });
|
|
150
213
|
}
|
|
151
214
|
else if (!center.enabled || this.current.state.catalog.length === 0) {
|
|
152
215
|
await this.busHost.apply(null);
|
|
@@ -172,21 +235,32 @@ export class EventRuntime {
|
|
|
172
235
|
const current = this.current;
|
|
173
236
|
const materializer = this.options.materializeAllowlist;
|
|
174
237
|
if (!current || !materializer || !current.center.enabled || current.state.catalog.length === 0)
|
|
175
|
-
return;
|
|
238
|
+
return false;
|
|
176
239
|
try {
|
|
177
240
|
const result = materializer(current.center, current.state.catalog.map(entry => entry.event));
|
|
178
241
|
if (result.degraded) {
|
|
179
242
|
logger.warn(`[EventCenter] ${this.options.aid} admission materialization degraded: ${result.reason ?? 'unknown'}`);
|
|
180
|
-
|
|
243
|
+
// Preserve ordinary event rules while still revoking a stale private
|
|
244
|
+
// output lease when the unrelated contacts snapshot is unavailable.
|
|
245
|
+
if (current.materializedAllowlist && current.state.catalog.some(entry => entry.event === OUTPUT_EVENT)) {
|
|
246
|
+
const protectedList = outputAllowlist(this.options.aid, { ...result, allowlist: current.materializedAllowlist }).allowlist;
|
|
247
|
+
await this.busHost.apply({ catalog: toSdkCatalog(current.state.catalog), allowlist: protectedList });
|
|
248
|
+
if (this.current === current)
|
|
249
|
+
this.current = { ...current, materializedAllowlist: protectedList };
|
|
250
|
+
}
|
|
251
|
+
return false;
|
|
181
252
|
}
|
|
182
|
-
|
|
253
|
+
const allowlist = this.protectOutputAllowlist(current, result.allowlist);
|
|
254
|
+
await this.busHost.apply({ catalog: toSdkCatalog(current.state.catalog), allowlist });
|
|
183
255
|
if (this.current === current)
|
|
184
|
-
this.current = { ...current, materializedAllowlist:
|
|
256
|
+
this.current = { ...current, materializedAllowlist: allowlist };
|
|
185
257
|
this.busHost.refreshGate();
|
|
186
258
|
this.reportGateStatus();
|
|
259
|
+
return true;
|
|
187
260
|
}
|
|
188
261
|
catch (error) {
|
|
189
262
|
logger.warn(`[EventCenter] ${this.options.aid} admission rematerialization failed: ${errorMessage(error)}`);
|
|
263
|
+
return false;
|
|
190
264
|
}
|
|
191
265
|
}
|
|
192
266
|
/**
|
|
@@ -203,6 +277,7 @@ export class EventRuntime {
|
|
|
203
277
|
const previous = this.current;
|
|
204
278
|
this.closed = false;
|
|
205
279
|
this.current = input;
|
|
280
|
+
this.nativeOutputPublisher = undefined;
|
|
206
281
|
this.configureRematerializeTimer();
|
|
207
282
|
this.configureContactsWatcher();
|
|
208
283
|
// 配置已变(新包集合/新解析结果):接入重试从头计退避,随后 diff 自会重排队列。
|
|
@@ -459,6 +534,12 @@ export class EventRuntime {
|
|
|
459
534
|
set.add(event);
|
|
460
535
|
desired.set(target.busAid, set);
|
|
461
536
|
}
|
|
537
|
+
if (this.nativeOutputAvailable && this.nativeOutputPublisher) {
|
|
538
|
+
const events = desired.get(this.options.aid) ?? new Set();
|
|
539
|
+
for (const event of PRIVATE_PROJECTION_EVENTS)
|
|
540
|
+
events.add(event);
|
|
541
|
+
desired.set(this.options.aid, events);
|
|
542
|
+
}
|
|
462
543
|
if (desired.size === 0)
|
|
463
544
|
return;
|
|
464
545
|
const handle = await this.ensureClient();
|
|
@@ -753,10 +834,24 @@ export class EventRuntime {
|
|
|
753
834
|
}
|
|
754
835
|
async close() {
|
|
755
836
|
this.closed = true;
|
|
837
|
+
this.outputOwnerOff?.();
|
|
838
|
+
this.outputOwnerOff = undefined;
|
|
839
|
+
this.nativeOutputPublisher = undefined;
|
|
840
|
+
this.nativeOutputPending.clear();
|
|
756
841
|
await this.stopConnections();
|
|
757
842
|
this.current = undefined;
|
|
758
843
|
}
|
|
759
|
-
gateRemoteRequest(senderAid, request, service) {
|
|
844
|
+
async gateRemoteRequest(senderAid, request, service) {
|
|
845
|
+
if (request.op === 'catalog' && this.current?.state.catalog.some(entry => entry.event === OUTPUT_EVENT)) {
|
|
846
|
+
// Catalog visibility is decided by the SDK's materialized ACL. Refresh
|
|
847
|
+
// it before discovery so a previous Owner cannot see the private event.
|
|
848
|
+
await ownerResolver.refresh(this.options.aid, { source: 'outputs.catalog',
|
|
849
|
+
maxAgeMs: OWNERSHIP_AUTHORIZATION_MAX_AGE_MS, allowTransient: false });
|
|
850
|
+
if (!await this.rematerialize()) {
|
|
851
|
+
throw Object.assign(new Error('Private output catalog authorization is unavailable'), { code: 'FORBIDDEN' });
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
await assertOutputEventRequest(this.options.aid, senderAid, request, service);
|
|
760
855
|
const current = this.current;
|
|
761
856
|
const materializer = this.options.materializeAllowlist;
|
|
762
857
|
if (!current || !materializer)
|
|
@@ -73,7 +73,9 @@ export class ScriptRunner {
|
|
|
73
73
|
let launch;
|
|
74
74
|
let sandboxFallbackReason;
|
|
75
75
|
try {
|
|
76
|
-
|
|
76
|
+
const built = this.buildLaunch(pack, handler, event, executable, scriptPath, scriptArgs);
|
|
77
|
+
// Unsandboxed launches have no directory preparation or new authorization gap.
|
|
78
|
+
launch = built instanceof Promise ? await built : built;
|
|
77
79
|
if (launch.prepare) {
|
|
78
80
|
try {
|
|
79
81
|
// 探针必须设上限:沙箱 provisioning 挂住时这里会无限等待,dispatcher 的
|
|
@@ -171,16 +173,14 @@ export class ScriptRunner {
|
|
|
171
173
|
role: publisherRole,
|
|
172
174
|
};
|
|
173
175
|
const trigger = this.syntheticTrigger(pack, handler, executable);
|
|
174
|
-
|
|
176
|
+
return buildTriggerScriptLaunch({
|
|
175
177
|
trigger,
|
|
176
178
|
triggerDir: pack.dir,
|
|
177
179
|
scriptPath,
|
|
178
180
|
scriptArgs,
|
|
179
181
|
projectPath,
|
|
180
182
|
executionAuthorization: authorization,
|
|
181
|
-
});
|
|
182
|
-
// 沙箱环境由 buildSandboxEnvironment 派生(密钥已剔除);这里叠加事件契约变量。
|
|
183
|
-
return { ...launch, env: { ...launch.env, ...ecEnv } };
|
|
183
|
+
}).then(launch => ({ ...launch, env: { ...launch.env, ...ecEnv } }));
|
|
184
184
|
}
|
|
185
185
|
buildEcEnv(pack, event) {
|
|
186
186
|
return {
|