evolcore 0.0.45 → 0.0.46
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 +75 -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 +13 -5
- package/dist/agents/codex/app-server-client.js +2 -4
- 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/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 +656 -112
- 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 +15 -17
- package/dist/cli/daemon-lifecycle-client.js +40 -18
- 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.js +50 -20
- 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 +33 -20
- package/dist/cli/services-command.js +28 -5
- package/dist/config/config-field-policy.js +24 -0
- package/dist/config/config-manager.js +20 -2
- package/dist/config/peer-book-store.js +152 -120
- package/dist/config/peer-role-resolver.js +24 -4
- package/dist/config/provider-identity-migration.js +1 -1
- 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-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 +85 -38
- package/dist/core/auth/agent-delegation.js +5 -0
- package/dist/core/auth/operation-authorizer.js +1 -1
- 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 +35 -8
- package/dist/core/command/menu-protocol.js +8 -16
- package/dist/core/command/skill-slash.js +6 -2
- 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-control.js +3 -4
- package/dist/core/daemon-lifecycle.js +146 -110
- package/dist/core/evolagent-registry.js +42 -0
- 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/inference/text-inference.js +12 -2
- package/dist/core/invoke/invoke-service.js +24 -3
- package/dist/core/ipc-registration.js +3 -0
- 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/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/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/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 +1 -1
- package/dist/ecweb/runtime/supervisor.js +77 -35
- 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 +96 -42
- package/dist/ipc.js +33 -7
- 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 +14 -4
- package/dist/trigger/script-sandbox.js +39 -2
- package/dist/utils/cross-platform.js +35 -11
- package/dist/utils/error-utils.js +13 -1
- package/dist/utils/instance-registry.js +33 -35
- package/dist/utils/process-introspect.js +35 -20
- package/dist/utils/project-path.js +47 -3
- 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/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 +7 -3
- 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
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* 事件名冲突 → 冲突各方全部 invalid(不静默覆盖)。
|
|
4
4
|
*/
|
|
5
5
|
/** 从加载结果构建运行时状态。disabled 包不参与目录与冲突检测。 */
|
|
6
|
-
export function buildPackState(packs, invalidPacks
|
|
6
|
+
export function buildPackState(packs, invalidPacks) {
|
|
7
7
|
const enabled = packs.filter(pack => pack.enabled);
|
|
8
8
|
const disabledPacks = packs.filter(pack => !pack.enabled).map(pack => pack.id);
|
|
9
9
|
const eventOwners = new Map();
|
|
@@ -56,7 +56,7 @@ export function buildPackState(packs, invalidPacks, previousRevision = 0) {
|
|
|
56
56
|
invalidPacks: [...invalidPacks, ...conflictInvalid],
|
|
57
57
|
catalog,
|
|
58
58
|
conflicts,
|
|
59
|
-
revision:
|
|
59
|
+
revision: 1,
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
/** catalog → SDK start/updateConfig 的 catalog 参数(字段名对照旧 bus-config-store.toSdkConfig)。 */
|
|
@@ -68,7 +68,9 @@ export function toSdkCatalog(catalog) {
|
|
|
68
68
|
schema_version: entry.schemaVersion ?? 1,
|
|
69
69
|
...(entry.contentSchema !== undefined ? { content_schema: entry.contentSchema } : {}),
|
|
70
70
|
default_ttl_seconds: entry.ttl,
|
|
71
|
-
|
|
71
|
+
// 缺省同 ttl(types.ts 与 pack.schema.json 都这么写)。曾有个 300 秒地板,
|
|
72
|
+
// 那会让 `ttl: 30` 的包对外宣告「最长可存 300 秒」,与实际默认值不符。
|
|
73
|
+
max_ttl_seconds: entry.maxTtl ?? entry.ttl,
|
|
72
74
|
};
|
|
73
75
|
}
|
|
74
76
|
return out;
|
|
@@ -2,20 +2,20 @@
|
|
|
2
2
|
* per-aid 事件中心单元注册表:加载 → 解析 → 运行时,生命周期跟随 Trigger 调度器。
|
|
3
3
|
* 包级失败隔离:坏包只废自己(pack.invalid),不影响其它包与 Bus。
|
|
4
4
|
*/
|
|
5
|
-
import fs from 'node:fs';
|
|
6
5
|
import path from 'node:path';
|
|
7
6
|
import { logger } from '../utils/logger.js';
|
|
8
7
|
import { agentEventsDir } from '../paths.js';
|
|
9
8
|
import { resolvePeerRoleDetail } from '../config/peer-role-resolver.js';
|
|
10
9
|
import { BusResolveState, isBusPlaceholder, resolvePackBuses } from './bus-resolver.js';
|
|
11
|
-
import { CenterConfigStore } from './center-config.js';
|
|
10
|
+
import { CenterConfigStore, loadCenterConfig } from './center-config.js';
|
|
12
11
|
import { EventDispatcher } from './dispatcher.js';
|
|
13
12
|
import { writeEventsIndex } from './index-generator.js';
|
|
14
|
-
import { Ledger, centerLedger, packLedger } from '
|
|
13
|
+
import { Ledger, centerLedger, eventPackLedger as packLedger } from '../core/pack-ledger.js';
|
|
15
14
|
import { buildPackState } from './pack-manager.js';
|
|
16
|
-
import {
|
|
15
|
+
import { loadPacks } from './pack-loader.js';
|
|
17
16
|
import { EventRuntime } from './runtime.js';
|
|
18
|
-
import { materializeAllowlist } from './admission-materializer.js';
|
|
17
|
+
import { explicitAllowlist, materializeAllowlist } from './admission-materializer.js';
|
|
18
|
+
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';
|
|
@@ -153,6 +153,7 @@ export class EventCenterRegistry {
|
|
|
153
153
|
center: scanned.center,
|
|
154
154
|
resolutions: scanned.resolutions,
|
|
155
155
|
materializedAllowlist: scanned.materializedAllowlist,
|
|
156
|
+
materializeReason: scanned.materializeReason,
|
|
156
157
|
contactsWatch: scanned.contactsWatch,
|
|
157
158
|
});
|
|
158
159
|
}
|
|
@@ -165,7 +166,9 @@ export class EventCenterRegistry {
|
|
|
165
166
|
this.scanLedgerSigs.delete(aid);
|
|
166
167
|
if (!unit)
|
|
167
168
|
return;
|
|
168
|
-
|
|
169
|
+
// 单元没了,`.index.md` 就是过期清单。manifest 侧因 `hasEventPacks` 变 false 而
|
|
170
|
+
// 不会注入,但文件留在盘上会让"磁盘有什么"与"实际有什么"对不上;空集写回等于删文件。
|
|
171
|
+
writeEventsIndex(unit.eventsDir, []);
|
|
169
172
|
await Promise.allSettled([unit.runtime.close(), unit.dispatcher.close()]);
|
|
170
173
|
}
|
|
171
174
|
async closeAll() {
|
|
@@ -205,6 +208,14 @@ export class EventCenterRegistry {
|
|
|
205
208
|
});
|
|
206
209
|
}
|
|
207
210
|
}
|
|
211
|
+
// `enabled: false` 是合法状态:包不加载、目录与日志保留。写一条台账,
|
|
212
|
+
// 否则"这个包为什么没生效"只能靠猜——`pack.disabled` 这个 action 一直没人写。
|
|
213
|
+
// disabledPacks 只有 id,没有 PackConfig,路径按 events/<id>/ledger.jsonl 拼。
|
|
214
|
+
for (const packId of state.disabledPacks) {
|
|
215
|
+
this.ledgerOnce(aid, `${packId}#disabled`, 'disabled', () => {
|
|
216
|
+
new Ledger(path.join(eventsDir, packId, 'ledger.jsonl')).append({ action: 'pack.disabled', result: 'ok', actor: ledgerActor });
|
|
217
|
+
});
|
|
218
|
+
}
|
|
208
219
|
// ③ 占位符解析(strict 失败 → 该包退出运行;keep-last 沿用上次结果)。
|
|
209
220
|
const context = readBusResolverContext(aid, agentDirPath);
|
|
210
221
|
const resolveState = BusResolveState.forEventsDir(eventsDir);
|
|
@@ -255,14 +266,31 @@ export class EventCenterRegistry {
|
|
|
255
266
|
// contacts 监听需求:包里有占位符引用(含被解析淘汰的包——它们在 enabledPacks 里)
|
|
256
267
|
// 或上次解析有失败/degraded(等 contacts 到位后重解析)。
|
|
257
268
|
const usesPlaceholderRefs = loaded.valid.some(pack => [...pack.publish, ...pack.subscribe].some(entry => isBusPlaceholder(entry.bus)));
|
|
269
|
+
if (materialized.degraded) {
|
|
270
|
+
logger.warn(`[EventCenter] ${aid} admission degraded; keeping the last deployed allowlist: ${materialized.reason ?? 'unknown'}`);
|
|
271
|
+
// 首次启动时退回 `events-config.json` 里显式声明的规则:那是人写下的、不依赖
|
|
272
|
+
// contacts 快照的唯一权威来源。再不行就让 SDK 侧保持空表——宁可收不到,也不放宽。
|
|
273
|
+
const fallback = explicitAllowlist(centerResult.config);
|
|
274
|
+
return {
|
|
275
|
+
agentDirPath,
|
|
276
|
+
eventsDir,
|
|
277
|
+
state: runtimeState,
|
|
278
|
+
resolutions,
|
|
279
|
+
center: centerResult.config,
|
|
280
|
+
...(Object.keys(fallback).length > 0
|
|
281
|
+
? { materializedAllowlist: fallback }
|
|
282
|
+
: { materializeReason: materialized.reason ?? 'contacts snapshot unavailable' }),
|
|
283
|
+
contactsWatch: usesPlaceholderRefs || wantsResolveRefresh,
|
|
284
|
+
resolverSignature: resolverSignatureOf(context),
|
|
285
|
+
};
|
|
286
|
+
}
|
|
258
287
|
return {
|
|
259
288
|
agentDirPath,
|
|
260
289
|
eventsDir,
|
|
261
290
|
state: runtimeState,
|
|
262
291
|
resolutions,
|
|
263
292
|
center: centerResult.config,
|
|
264
|
-
|
|
265
|
-
materializedAllowlist: materialized.degraded ? {} : materialized.allowlist,
|
|
293
|
+
materializedAllowlist: materialized.allowlist,
|
|
266
294
|
contactsWatch: usesPlaceholderRefs || wantsResolveRefresh,
|
|
267
295
|
resolverSignature: resolverSignatureOf(context),
|
|
268
296
|
};
|
|
@@ -282,6 +310,8 @@ export class EventCenterRegistry {
|
|
|
282
310
|
const existingUnit = this.units.get(aid);
|
|
283
311
|
if (existingUnit) {
|
|
284
312
|
this.units.delete(aid);
|
|
313
|
+
// 必须摘掉旧的目录监听与去抖定时器(`remove()` 里有这一步,这里先前漏了)。
|
|
314
|
+
// 否则每次调度器重启都会多留一个 `fs.watch` 句柄,Windows 上很快耗尽。
|
|
285
315
|
await Promise.allSettled([existingUnit.runtime.close(), existingUnit.dispatcher.close()]);
|
|
286
316
|
}
|
|
287
317
|
this.cleanupLegacySubscriptionTriggers(aid);
|
|
@@ -320,6 +350,15 @@ export class EventCenterRegistry {
|
|
|
320
350
|
...(entry.event ? { event: entry.event } : {}), ...(entry.action ? { direction: entry.action } : {}),
|
|
321
351
|
reason: entry.reason, code: 'FORBIDDEN',
|
|
322
352
|
}),
|
|
353
|
+
// 读 unit 上的实时 state:reload 会原地替换包集合,闭包不能捕获初值。
|
|
354
|
+
onPublished: publication => {
|
|
355
|
+
const live = this.units.get(aid);
|
|
356
|
+
const pack = (live?.state ?? runtimeState).enabledPacks.find(candidate => candidate.id === publication.packId);
|
|
357
|
+
if (!pack)
|
|
358
|
+
return;
|
|
359
|
+
const { packId: _packId, ...record } = publication;
|
|
360
|
+
PublicationLog.forPack(pack).append(record);
|
|
361
|
+
},
|
|
323
362
|
onGateStatus: installed => centerLedger(eventsDir).append({
|
|
324
363
|
action: installed ? 'gate.installed' : 'gate.degraded', result: installed ? 'ok' : 'failed', actor: 'daemon',
|
|
325
364
|
...(installed ? {} : { reason: 'sdk_request_handler_unavailable' }),
|
|
@@ -366,12 +405,12 @@ export class EventCenterRegistry {
|
|
|
366
405
|
resolverSignature: scanned.resolverSignature,
|
|
367
406
|
};
|
|
368
407
|
this.units.set(aid, unit);
|
|
369
|
-
this.attachEventsWatcher(unit);
|
|
370
408
|
await runtime.start({
|
|
371
409
|
state: runtimeState,
|
|
372
410
|
center: centerConfig,
|
|
373
411
|
resolutions,
|
|
374
412
|
materializedAllowlist: scanned.materializedAllowlist,
|
|
413
|
+
materializeReason: scanned.materializeReason,
|
|
375
414
|
contactsWatch: scanned.contactsWatch,
|
|
376
415
|
});
|
|
377
416
|
}
|
|
@@ -396,49 +435,6 @@ export class EventCenterRegistry {
|
|
|
396
435
|
logger.warn(`[EventCenter] ${aid} contacts-triggered reload failed: ${errorMessage(error)}`);
|
|
397
436
|
});
|
|
398
437
|
}
|
|
399
|
-
// ── M3:events/ 目录监听(改 pack.json/center.json 自动 reload)────────
|
|
400
|
-
// 原生 recursive fs.watch(win32 单句柄;chokidar 在 Windows 有句柄爆炸教训)。
|
|
401
|
-
// 只认包清单与 center.json:.index.md 在监听目录内(reload 自己写,会自触发),
|
|
402
|
-
// ledger/logs/scripts 是运行产物,全排除。error 即降级拆除,回到手动 reload。
|
|
403
|
-
attachEventsWatcher(unit) {
|
|
404
|
-
if (unit.eventsWatcher || this.options.watchEvents === false)
|
|
405
|
-
return;
|
|
406
|
-
// 旧名文件(center.json / 关注的事件.json)首次加载时就地迁移成规范名,磁盘上不再出现,无需监听。
|
|
407
|
-
const watched = new Set([PACK_JSON, EVENTS_CONFIG_JSON]);
|
|
408
|
-
try {
|
|
409
|
-
const watcher = fs.watch(unit.eventsDir, { recursive: true }, (_kind, filename) => {
|
|
410
|
-
const base = filename ? path.basename(filename.toString()) : '';
|
|
411
|
-
if (!watched.has(base))
|
|
412
|
-
return;
|
|
413
|
-
if (unit.eventsReloadTimer)
|
|
414
|
-
clearTimeout(unit.eventsReloadTimer);
|
|
415
|
-
unit.eventsReloadTimer = setTimeout(() => {
|
|
416
|
-
unit.eventsReloadTimer = undefined;
|
|
417
|
-
this.reload(unit.aid).catch(error => {
|
|
418
|
-
logger.warn(`[EventCenter] ${unit.aid} watcher reload failed: ${errorMessage(error)}`);
|
|
419
|
-
});
|
|
420
|
-
}, 2_000);
|
|
421
|
-
unit.eventsReloadTimer.unref?.();
|
|
422
|
-
});
|
|
423
|
-
watcher.on('error', () => this.detachEventsWatcher(unit));
|
|
424
|
-
unit.eventsWatcher = watcher;
|
|
425
|
-
}
|
|
426
|
-
catch {
|
|
427
|
-
// 目录缺失或平台不支持 recursive:不监听即可,手动 reload 仍可用。
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
detachEventsWatcher(unit) {
|
|
431
|
-
if (unit.eventsReloadTimer)
|
|
432
|
-
clearTimeout(unit.eventsReloadTimer);
|
|
433
|
-
unit.eventsReloadTimer = undefined;
|
|
434
|
-
try {
|
|
435
|
-
unit.eventsWatcher?.close();
|
|
436
|
-
}
|
|
437
|
-
catch {
|
|
438
|
-
// 已失效。
|
|
439
|
-
}
|
|
440
|
-
unit.eventsWatcher = undefined;
|
|
441
|
-
}
|
|
442
438
|
/** 一次性清理旧事件总线遗留的订阅 Trigger(事件源 bus:event 已无人发布,纯残留)。 */
|
|
443
439
|
cleanupLegacySubscriptionTriggers(aid) {
|
|
444
440
|
const scheduler = this.options.getScheduler?.(aid);
|
|
@@ -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);
|