evolcore 0.0.43-test.7 → 0.0.43-test.8
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 +47 -0
- package/bin/ecmsg.js +22 -9
- package/dist/agent-template/jobs.js +62 -0
- package/dist/agent-template/runtime.js +214 -0
- package/dist/agent-template/service.js +465 -0
- package/dist/agent-template/tool-runner.js +45 -0
- package/dist/agent-template/types.js +5 -0
- package/dist/agents/claude-runner.js +1 -1
- package/dist/aun/aid/agentmd.js +56 -1
- package/dist/aun/aid/client.js +3 -1
- package/dist/aun/menu/client.js +3 -2
- package/dist/aun/msg/p2p.js +1 -1
- package/dist/channels/aun.js +47 -32
- package/dist/cli/agent-command.js +5 -0
- package/dist/cli/agent-create.js +5 -1
- package/dist/cli/agent-template.js +124 -0
- package/dist/cli/aun-commands.js +2 -2
- package/dist/cli/ctl-command.js +2 -1
- package/dist/cli/daemon-commands.js +5 -0
- package/dist/cli/ecmsg-gateway.js +2 -2
- package/dist/cli/events-command.js +45 -9
- package/dist/cli/index.js +29 -0
- package/dist/cli/net-check.js +1 -1
- package/dist/cli/restart-monitor.js +115 -36
- package/dist/cli/services-command.js +29 -3
- package/dist/cli/thread-command.js +97 -11
- package/dist/config/boot-log.js +8 -8
- package/dist/config/schema-migration.js +41 -16
- package/dist/core/agent-ipc-registration.js +25 -4
- package/dist/core/agent-runtime.js +2 -0
- package/dist/core/auth/operation-authorizer.js +2 -0
- package/dist/core/auth/operation-catalog.js +11 -2
- package/dist/core/channel-runtime.js +16 -9
- package/dist/core/command/agent-control.js +11 -1
- package/dist/core/command/agent-template-menu.js +147 -0
- package/dist/core/command/command-handler.js +27 -6
- package/dist/core/command/eventcenter-menu.js +158 -28
- package/dist/core/command/menu-catalog.js +8 -1
- package/dist/core/command/menu-handler.js +18 -6
- package/dist/core/command/menu-protocol.js +11 -2
- package/dist/core/daemon-control.js +14 -0
- package/dist/core/daemon-lifecycle.js +262 -189
- package/dist/core/handoff/runtime.js +42 -10
- package/dist/core/ipc-registration.js +5 -1
- package/dist/core/legacy-rename.js +41 -0
- package/dist/core/message/aun-ipc-sender.js +118 -13
- package/dist/core/message/im-renderer.js +88 -1
- package/dist/core/message/message-queue.js +66 -15
- package/dist/core/message/pending-hints.js +29 -5
- package/dist/core/message/response-engine.js +37 -7
- package/dist/core/message/send-routing.js +13 -6
- package/dist/core/pack-auth.js +94 -0
- package/dist/core/pack-install.js +194 -0
- package/dist/core/permission/ec-command-parser.js +49 -16
- package/dist/core/rate-window.js +48 -0
- package/dist/core/relation/peer-identity.js +28 -0
- package/dist/core/session/session-fs-store.js +66 -26
- package/dist/core/session/session-idle-monitor.js +59 -19
- package/dist/core/session/session-manager.js +13 -4
- package/dist/core/thread/thread-route.js +2 -2
- package/dist/core/thread/thread-service.js +52 -3
- package/dist/eck/kit-renderer.js +1 -1
- package/dist/eck/message-renderer.js +2 -0
- package/dist/event-center/admission-materializer.js +22 -12
- package/dist/event-center/bus-gate.js +20 -2
- package/dist/event-center/bus-host.js +46 -29
- package/dist/event-center/bus-resolver.js +1 -1
- package/dist/event-center/center-config.js +41 -14
- package/dist/event-center/daemon.js +1 -2
- package/dist/event-center/directory-source.js +3 -1
- package/dist/event-center/index-generator.js +12 -2
- package/dist/event-center/ipc-operation.js +140 -25
- package/dist/event-center/pack-loader.js +61 -56
- package/dist/event-center/pack-manager.js +2 -2
- package/dist/event-center/registry.js +242 -17
- package/dist/event-center/runtime.js +271 -75
- package/dist/event-center/types.js +20 -4
- package/dist/event-center/validation.js +34 -12
- package/dist/index.js +147 -44
- package/dist/ipc.js +44 -4
- package/dist/paths.js +2 -2
- package/dist/response-system/engines/v1/proactive-flow.js +4 -2
- package/dist/services/index.js +3 -3
- package/dist/services/ipc-operation.js +99 -7
- package/dist/services/pack-manager.js +17 -6
- package/dist/services/router.js +8 -5
- package/dist/services/validation.js +5 -5
- package/dist/trigger/scheduler.js +38 -0
- package/dist/trigger/script-sandbox.js +52 -2
- package/dist/utils/npm-ops.js +2 -1
- package/dist/utils/package-version-info.js +6 -3
- package/kits/docs/aun/ABILITY_CALLING.md +4 -3
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +3 -3
- package/kits/docs/evolcore/agent.md +22 -1
- package/kits/docs/evolcore/event-center.md +30 -10
- package/kits/docs/evolcore/fs.md +4 -3
- package/kits/docs/evolcore/menu-protocol.md +7 -1
- package/kits/docs/evolcore/msg.md +8 -8
- package/kits/docs/evolcore/response.md +2 -2
- package/kits/docs/evolcore/services.md +27 -10
- package/kits/docs/evolcore/thread-chain.md +15 -3
- package/kits/rules/06-channel.md +1 -0
- package/kits/skills/ability/references/calling.md +2 -2
- package/kits/skills/ec-group/SKILL.md +5 -8
- package/kits/skills/ec-group-collaboration/SKILL.md +7 -7
- package/kits/skills/ec-trigger/SKILL.md +4 -4
- package/kits/skills/thread-ops/SKILL.md +10 -10
- package/kits/templates/message-fragments/item.md +1 -1
- package/kits/templates/system-fragments/channel.md +1 -1
- package/kits/templates/system-fragments/commands.md +1 -1
- package/kits/templates/system-fragments/reply.md +1 -0
- package/kits/templates/system-fragments/thread.md +3 -2
- package/package.json +4 -3
- package/scripts/agent-template/index.mjs +40 -0
- package/scripts/agent-template/inspect.mjs +240 -0
- package/scripts/agent-template/overlay.mjs +71 -0
- package/scripts/agent-template/pack.mjs +169 -0
- package/scripts/agent-template/shared/common.mjs +235 -0
- package/scripts/agent-template/shared/evolcore.mjs +75 -0
- package/scripts/agent-template/shared/plan.mjs +129 -0
- package/scripts/agent-template/shared/team-schema.json +70 -0
- package/scripts/agent-template/shared/template-contract.mjs +154 -0
- package/scripts/agent-template/shared/template-package.mjs +265 -0
- package/scripts/agent-template/shared/template-runtime.mjs +80 -0
- package/scripts/agent-template/shared/template.mjs +142 -0
- package/dist/event-center/client-factory.js +0 -50
|
@@ -1,20 +1,38 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* events-config.json 管理:读、原子写、rules 增删查;变更联动 SDK updateConfig 由调用方(runtime)执行。
|
|
3
3
|
*/
|
|
4
4
|
import fs from 'node:fs';
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import { atomicWriteJson } from '../utils/atomic-write.js';
|
|
7
7
|
import { centerLedger } from './ledger.js';
|
|
8
|
-
import {
|
|
8
|
+
import { EVENTS_CONFIG_JSON } from './pack-loader.js';
|
|
9
9
|
import { EventCenterError } from './types.js';
|
|
10
|
-
import { validateCenterConfig } from './validation.js';
|
|
10
|
+
import { AID_PATTERN, validateCenterConfig } from './validation.js';
|
|
11
11
|
export class CenterConfigStore {
|
|
12
12
|
filePath;
|
|
13
13
|
ledger;
|
|
14
14
|
constructor(options) {
|
|
15
|
-
this.filePath = path.join(options.eventsDir,
|
|
15
|
+
this.filePath = path.join(options.eventsDir, EVENTS_CONFIG_JSON);
|
|
16
16
|
this.ledger = options.ledger ?? centerLedger(options.eventsDir);
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* 严格读取:只用于**会写回磁盘**的路径(rules 增删、center 开关)。
|
|
20
|
+
*
|
|
21
|
+
* 与 `read()` 的区别只在"文件存在但非法"这一种情况:此时抛错,绝不返回缺省值。
|
|
22
|
+
* 缺省值一旦被当作基准再写回去,磁盘上那份(可能只是某个 AID 写错的)配置就被
|
|
23
|
+
* 整份覆盖成 `enabled:false / rules:{}`——静默丢规则,且违背 admission-coupling.md
|
|
24
|
+
* §4.3 "配置校验失败时原配置保持不变"的承诺。
|
|
25
|
+
*
|
|
26
|
+
* 只读路径(status / doctor / 菜单展示)仍用 `read()`:那里展示缺省值是合理的,
|
|
27
|
+
* 因为紧接着会带上 errors 提示配置有问题。
|
|
28
|
+
*/
|
|
29
|
+
readStrict() {
|
|
30
|
+
const { config, exists, errors } = this.read();
|
|
31
|
+
if (exists && errors.length > 0) {
|
|
32
|
+
throw new EventCenterError('CONFIG_INVALID', `${EVENTS_CONFIG_JSON} is invalid, refusing to overwrite: ${errors.join('; ')}`);
|
|
33
|
+
}
|
|
34
|
+
return config;
|
|
35
|
+
}
|
|
18
36
|
/** 读取并校验;校验失败返回缺省并带 errors(Bus 不启动,不覆盖磁盘)。 */
|
|
19
37
|
read() {
|
|
20
38
|
let rawText;
|
|
@@ -22,7 +40,7 @@ export class CenterConfigStore {
|
|
|
22
40
|
rawText = fs.readFileSync(this.filePath, 'utf8');
|
|
23
41
|
}
|
|
24
42
|
catch {
|
|
25
|
-
return { config: { enabled: false, authMode: 'allowlist', admission: { coupling: 'on', rematerializeMs: 300_000 },
|
|
43
|
+
return { config: { enabled: false, authMode: 'allowlist', admission: { coupling: 'on', rematerializeMs: 300_000 }, rules: {}, rateLimit: { perMinute: 60, perHour: 600 } }, exists: false, errors: [] };
|
|
26
44
|
}
|
|
27
45
|
let raw;
|
|
28
46
|
try {
|
|
@@ -30,14 +48,14 @@ export class CenterConfigStore {
|
|
|
30
48
|
}
|
|
31
49
|
catch (error) {
|
|
32
50
|
return {
|
|
33
|
-
config: { enabled: false, authMode: 'allowlist', admission: { coupling: 'on', rematerializeMs: 300_000 },
|
|
51
|
+
config: { enabled: false, authMode: 'allowlist', admission: { coupling: 'on', rematerializeMs: 300_000 }, rules: {}, rateLimit: { perMinute: 60, perHour: 600 } },
|
|
34
52
|
exists: true,
|
|
35
|
-
errors: [`${
|
|
53
|
+
errors: [`${EVENTS_CONFIG_JSON} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`],
|
|
36
54
|
};
|
|
37
55
|
}
|
|
38
56
|
const validated = validateCenterConfig(raw);
|
|
39
57
|
if (!validated.ok) {
|
|
40
|
-
return { config: { enabled: false, authMode: 'allowlist', admission: { coupling: 'on', rematerializeMs: 300_000 },
|
|
58
|
+
return { config: { enabled: false, authMode: 'allowlist', admission: { coupling: 'on', rematerializeMs: 300_000 }, rules: {}, rateLimit: { perMinute: 60, perHour: 600 } }, exists: true, errors: validated.errors };
|
|
41
59
|
}
|
|
42
60
|
return { config: validated.value, exists: true, errors: [] };
|
|
43
61
|
}
|
|
@@ -48,13 +66,21 @@ export class CenterConfigStore {
|
|
|
48
66
|
enabled: config.enabled,
|
|
49
67
|
authMode: config.authMode,
|
|
50
68
|
admission: config.admission,
|
|
51
|
-
|
|
69
|
+
rules: config.rules,
|
|
70
|
+
rateLimit: config.rateLimit,
|
|
52
71
|
});
|
|
53
72
|
}
|
|
54
73
|
/** 白名单增删。返回更新后的配置;不做磁盘之外的生效动作。 */
|
|
55
74
|
mutateAllowlist(input) {
|
|
56
|
-
|
|
57
|
-
const
|
|
75
|
+
// 必须严格读:校验失败时若拿缺省值当基准写回,会把整份配置清零。
|
|
76
|
+
const config = this.readStrict();
|
|
77
|
+
for (const aid of input.aids) {
|
|
78
|
+
// 写路径同样校验 AID 格式——只在读时校验等于"先写脏数据,下次读就报错"。
|
|
79
|
+
if (!AID_PATTERN.test(aid)) {
|
|
80
|
+
throw new EventCenterError('INVALID_ARGS', `invalid AID: ${aid}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const current = config.rules[input.event];
|
|
58
84
|
const entry = current
|
|
59
85
|
? { allow: { publish: [...current.allow.publish], subscribe: [...current.allow.subscribe] }, deny: { publish: [...current.deny.publish], subscribe: [...current.deny.subscribe] } }
|
|
60
86
|
: { allow: { publish: [], subscribe: [] }, deny: { publish: [], subscribe: [] } };
|
|
@@ -83,7 +109,7 @@ export class CenterConfigStore {
|
|
|
83
109
|
}
|
|
84
110
|
}
|
|
85
111
|
}
|
|
86
|
-
config.
|
|
112
|
+
config.rules[input.event] = entry;
|
|
87
113
|
this.write(config);
|
|
88
114
|
this.ledger.append({
|
|
89
115
|
action: 'allowlist.update',
|
|
@@ -92,8 +118,9 @@ export class CenterConfigStore {
|
|
|
92
118
|
...(added.length ? { added } : {}),
|
|
93
119
|
...(removed.length ? { removed } : {}),
|
|
94
120
|
...(input.rule ? { rule: input.rule } : {}),
|
|
95
|
-
|
|
96
|
-
|
|
121
|
+
// 目前唯一的写入口是 CLI 与菜单,没有脚本侧通道;`by`/actor=script 曾是死代码。
|
|
122
|
+
// 等真出现脚本改规则的需求时再引入,避免文档承诺一个不存在的分支。
|
|
123
|
+
actor: 'menu',
|
|
97
124
|
});
|
|
98
125
|
return { config, changed: entry, added, removed };
|
|
99
126
|
}
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import fs from 'node:fs';
|
|
6
6
|
import { agentDir } from '../paths.js';
|
|
7
|
-
import { createEventClient } from './client-factory.js';
|
|
8
7
|
import { EventCenterRegistry } from './registry.js';
|
|
9
8
|
/**
|
|
10
9
|
* 解析 agent 工程目录:只接受真实存在的目录。
|
|
@@ -28,7 +27,7 @@ export function resolveAgentProjectPath(aid, candidate) {
|
|
|
28
27
|
export function createDaemonEventCenter(options) {
|
|
29
28
|
const registry = new EventCenterRegistry({
|
|
30
29
|
agentDir,
|
|
31
|
-
|
|
30
|
+
getClient: options.getClient,
|
|
32
31
|
getProjectPath: options.getProjectPath
|
|
33
32
|
?? (aid => resolveAgentProjectPath(aid, options.agentRegistry.get(aid)?.projectPath)),
|
|
34
33
|
getScheduler: aid => options.triggerSchedulers.get(aid),
|
|
@@ -22,7 +22,9 @@ export function readBusResolverContext(aid, agentDir) {
|
|
|
22
22
|
const ownerAid = identityAid(record.owner);
|
|
23
23
|
if (ownerAid)
|
|
24
24
|
context.owner = ownerAid;
|
|
25
|
-
|
|
25
|
+
// 本地快照持久化为 camelCase personalAssistant(owner-directory-cache 的写盘格式),
|
|
26
|
+
// 设计文档口径是 snake_case personal_assistant;两种都读,camelCase 优先。
|
|
27
|
+
const paAid = identityAid(record.personalAssistant) ?? identityAid(record.personal_assistant);
|
|
26
28
|
if (paAid)
|
|
27
29
|
context.pa = paAid;
|
|
28
30
|
const paRoles = parsePaRoles(record.pa_roles);
|
|
@@ -50,11 +50,21 @@ export function writeEventsIndex(eventsDir, enabledPacks, resolutions) {
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
lines.push('');
|
|
53
|
-
lines.push('本机管理: ec events status / ledger / tail');
|
|
53
|
+
lines.push('本机管理: ec events status / ledger / tail / reload');
|
|
54
54
|
lines.push('');
|
|
55
55
|
try {
|
|
56
56
|
fs.mkdirSync(eventsDir, { recursive: true });
|
|
57
|
-
|
|
57
|
+
// 内容未变则跳过写盘:reload 可能由 contacts/watcher 高频触发,.index.md 又在
|
|
58
|
+
// events/ 目录内(被 watcher 监听),重复写会既刷盘又自触发。
|
|
59
|
+
const content = lines.join('\n');
|
|
60
|
+
try {
|
|
61
|
+
if (fs.readFileSync(filePath, 'utf8') === content)
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
// 读不到(尚不存在等)按需写。
|
|
66
|
+
}
|
|
67
|
+
fs.writeFileSync(filePath, content, 'utf8');
|
|
58
68
|
logger.debug(`[events-index] ${EVENTS_INDEX_FILE} 已生成(${enabledPacks.length} 个包)`);
|
|
59
69
|
}
|
|
60
70
|
catch (error) {
|
|
@@ -3,12 +3,16 @@
|
|
|
3
3
|
* daemon-control 风格(不走 delegation argv 哈希);CLI 透传 argv,daemon 解析执行。
|
|
4
4
|
*/
|
|
5
5
|
import { logger } from '../utils/logger.js';
|
|
6
|
-
import { Ledger } from './ledger.js';
|
|
6
|
+
import { Ledger, centerLedger } from './ledger.js';
|
|
7
7
|
import { EventLog } from './event-log.js';
|
|
8
8
|
import { loadPackDir } from './pack-loader.js';
|
|
9
9
|
import { toSdkCatalog } from './pack-manager.js';
|
|
10
10
|
import { materializeAllowlist } from './admission-materializer.js';
|
|
11
11
|
import { EventCenterError, errorMessage } from './types.js';
|
|
12
|
+
import { installPack, listPackDirs, removePack } from '../core/pack-install.js';
|
|
13
|
+
import { CenterConfigStore } from './center-config.js';
|
|
14
|
+
import { agentEventsDir } from '../paths.js';
|
|
15
|
+
import { authorizePackTarget, isManagingEventsCommand } from '../core/pack-auth.js';
|
|
12
16
|
const HELP = `ec events — 事件中心运维
|
|
13
17
|
|
|
14
18
|
用法:
|
|
@@ -17,10 +21,18 @@ const HELP = `ec events — 事件中心运维
|
|
|
17
21
|
ec events tail <包名> [--tail N] 事件日志
|
|
18
22
|
ec events doctor <包名> 诊断
|
|
19
23
|
ec events reload [<包名>] 重载(重新扫描目录并重建订阅)
|
|
20
|
-
ec events
|
|
21
|
-
ec events
|
|
22
|
-
ec events
|
|
23
|
-
ec events publish <包名> <事件> --data '<json>' [--ttl <秒>]
|
|
24
|
+
ec events rules add <事件> --publish <aid> [--subscribe <aid>] [--deny]
|
|
25
|
+
ec events rules remove <事件> --publish <aid> [--subscribe <aid>] [--deny]
|
|
26
|
+
ec events rules show [--event <事件>]
|
|
27
|
+
ec events publish <包名> <事件> --data '<json>' [--ttl <秒>]
|
|
28
|
+
|
|
29
|
+
安装与卸载(L 类目录只能由 daemon 代写):
|
|
30
|
+
ec events pack add <包名> --from <源目录> [--aid <aid>]
|
|
31
|
+
ec events pack remove <包名> [--aid <aid>] [--purge]
|
|
32
|
+
ec events pack list [--aid <aid>]
|
|
33
|
+
|
|
34
|
+
add 遇到已安装的包直接报错,先 remove 再装。
|
|
35
|
+
remove 默认把日志与台账归档到 <包>/logs/archive-<时间戳>/;--purge 连归档一起删。`;
|
|
24
36
|
export function parseEventsArgv(argv) {
|
|
25
37
|
const args = [...argv];
|
|
26
38
|
if (args.length === 0 || args[0] === 'help' || args[0] === '--help')
|
|
@@ -83,22 +95,43 @@ export function parseEventsArgv(argv) {
|
|
|
83
95
|
const subscribe = consumeList('--subscribe');
|
|
84
96
|
if (subscribe)
|
|
85
97
|
parsed.aids.subscribe = subscribe;
|
|
98
|
+
parsed.from = consumeValue('--from');
|
|
99
|
+
if (args.includes('--purge')) {
|
|
100
|
+
parsed.purge = true;
|
|
101
|
+
args.splice(args.indexOf('--purge'), 1);
|
|
102
|
+
}
|
|
103
|
+
if (args.includes('--force')) {
|
|
104
|
+
// `pack add` 不再支持覆盖:重装前必须先 `pack remove`。识别出来只为给出明确提示,
|
|
105
|
+
// 而不是当成未知参数静默忽略。
|
|
106
|
+
return { error: '--force is no longer supported; run "pack remove <包名>" before reinstalling' };
|
|
107
|
+
}
|
|
86
108
|
const positional = args.filter(item => !item.startsWith('-'));
|
|
87
|
-
if (command === '
|
|
109
|
+
if (command === 'pack') {
|
|
110
|
+
parsed.action = positional[0];
|
|
111
|
+
parsed.pack = positional[1];
|
|
112
|
+
}
|
|
113
|
+
else if (command === 'status' || command === 'ledger' || command === 'tail' || command === 'doctor'
|
|
88
114
|
|| command === 'reload' || command === 'publish') {
|
|
89
115
|
parsed.pack = positional[0];
|
|
90
116
|
if (command === 'publish')
|
|
91
117
|
parsed.event = parsed.event ?? positional[1];
|
|
92
118
|
}
|
|
93
|
-
else if (command === '
|
|
94
|
-
parsed.command = `
|
|
119
|
+
else if (command === 'rules') {
|
|
120
|
+
parsed.command = `rules:${positional[0] ?? ''}`;
|
|
95
121
|
parsed.event = parsed.event ?? positional[1];
|
|
96
122
|
}
|
|
97
123
|
return parsed;
|
|
98
124
|
}
|
|
99
|
-
function resolveAid(deps, parsed) {
|
|
125
|
+
function resolveAid(deps, parsed, opts = {}) {
|
|
100
126
|
if (parsed.aid)
|
|
101
127
|
return { aid: parsed.aid };
|
|
128
|
+
// pack 安装/卸载在单元还没起时也要能用(装完才 reload),此时默认 AID 优先于
|
|
129
|
+
// "恰好只有一个已启动单元"——否则全新 agent 永远装不上第一个包。
|
|
130
|
+
if (opts.preferDefault) {
|
|
131
|
+
const preferred = deps.defaultAid?.();
|
|
132
|
+
if (preferred)
|
|
133
|
+
return { aid: preferred };
|
|
134
|
+
}
|
|
102
135
|
const units = [...deps.registry.values()];
|
|
103
136
|
if (units.length === 1)
|
|
104
137
|
return { aid: units[0].aid };
|
|
@@ -121,6 +154,8 @@ export function createEventsOperationExecutor(deps) {
|
|
|
121
154
|
}
|
|
122
155
|
if ('error' in parsed)
|
|
123
156
|
return { ok: false, code: 'INVALID_ARGV', error: parsed.error };
|
|
157
|
+
// 调用方身份随请求传入,不参与 argv 解析(argv 来自 agent,可伪造)。
|
|
158
|
+
parsed.caller = request.caller;
|
|
124
159
|
try {
|
|
125
160
|
return await execute(deps, parsed);
|
|
126
161
|
}
|
|
@@ -147,10 +182,63 @@ async function execute(deps, parsed) {
|
|
|
147
182
|
const unit = deps.registry.get(target.aid);
|
|
148
183
|
return { ok: true, result: { aid: target.aid, packs: unit?.state.enabledPacks.map(pack => pack.id) ?? [] } };
|
|
149
184
|
}
|
|
150
|
-
const target = resolveAid(deps, parsed);
|
|
185
|
+
const target = resolveAid(deps, parsed, { preferDefault: command === 'pack' });
|
|
151
186
|
if (target.error)
|
|
152
187
|
return target.error;
|
|
153
188
|
const aid = target.aid;
|
|
189
|
+
const auth = authorizePackTarget({
|
|
190
|
+
caller: parsed.caller ?? { kind: 'local-control' },
|
|
191
|
+
targetAid: aid,
|
|
192
|
+
...(deps.daemonAid?.() ? { daemonAid: deps.daemonAid() } : {}),
|
|
193
|
+
requiresManagement: isManagingEventsCommand(parsed.command.startsWith('rules:') ? 'rules' : parsed.command),
|
|
194
|
+
});
|
|
195
|
+
if (!auth.allowed)
|
|
196
|
+
return { ok: false, code: auth.code, error: auth.error };
|
|
197
|
+
// ── 包安装/卸载:不需要 unit 已启动(装完再 reload 即可生效)──
|
|
198
|
+
if (command === 'pack') {
|
|
199
|
+
const eventsDir = agentEventsDir(aid);
|
|
200
|
+
if (parsed.action === 'list') {
|
|
201
|
+
return { ok: true, result: { aid, eventsDir, packs: listPackDirs(eventsDir, 'pack.json') } };
|
|
202
|
+
}
|
|
203
|
+
if (!parsed.pack)
|
|
204
|
+
return { ok: false, code: 'INVALID_ARGV', error: `${command} ${parsed.action ?? ''} requires <包名>` };
|
|
205
|
+
if (parsed.action === 'add') {
|
|
206
|
+
if (!parsed.from)
|
|
207
|
+
return { ok: false, code: 'INVALID_ARGV', error: 'pack add requires --from <源目录>' };
|
|
208
|
+
const installed = installPack({
|
|
209
|
+
sourceDir: parsed.from,
|
|
210
|
+
targetRoot: eventsDir,
|
|
211
|
+
name: parsed.pack,
|
|
212
|
+
manifestFile: 'pack.json',
|
|
213
|
+
legacyManifestFile: '关注的事件.json',
|
|
214
|
+
});
|
|
215
|
+
// 总闸必须在 reload **之前**建好:reload 会按磁盘状态一次性重建运行时,
|
|
216
|
+
// 建完再 reload 会让 Bus/Sub/Pub 三条连接白连一次(服务端记 4009
|
|
217
|
+
// "Connection replaced by new session"),既不干净也拖慢安装。
|
|
218
|
+
// 没有 events-config.json 时 Bus 永远 stopped,包 active 却收不到事件。
|
|
219
|
+
const centerStoreBefore = new CenterConfigStore({ eventsDir });
|
|
220
|
+
let createdCenter = false;
|
|
221
|
+
if (!centerStoreBefore.read().exists) {
|
|
222
|
+
centerStoreBefore.write({
|
|
223
|
+
enabled: true,
|
|
224
|
+
authMode: 'allowlist',
|
|
225
|
+
admission: { coupling: 'on', rematerializeMs: 300_000 },
|
|
226
|
+
rules: {},
|
|
227
|
+
rateLimit: { perMinute: 60, perHour: 600 },
|
|
228
|
+
});
|
|
229
|
+
createdCenter = true;
|
|
230
|
+
}
|
|
231
|
+
await deps.registry.reload(aid);
|
|
232
|
+
return { ok: true, result: { aid, ...installed, ...(createdCenter ? { createdCenter: true } : {}) } };
|
|
233
|
+
}
|
|
234
|
+
if (parsed.action === 'remove') {
|
|
235
|
+
const removed = removePack({ pack: parsed.pack, targetRoot: eventsDir, purge: parsed.purge === true });
|
|
236
|
+
await deps.registry.reload(aid);
|
|
237
|
+
return { ok: true, result: { aid, ...removed } };
|
|
238
|
+
}
|
|
239
|
+
return { ok: false, code: 'UNKNOWN_COMMAND', error: `unknown pack action: ${parsed.action ?? '(none)'}
|
|
240
|
+
${HELP}` };
|
|
241
|
+
}
|
|
154
242
|
const unit = deps.registry.get(aid);
|
|
155
243
|
if (!unit)
|
|
156
244
|
return { ok: false, code: 'AGENT_NOT_STARTED', error: `event center not started for ${aid}` };
|
|
@@ -163,12 +251,16 @@ async function execute(deps, parsed) {
|
|
|
163
251
|
return { ok: true, result: { aid, pack: packStatus(unit, pack.id) } };
|
|
164
252
|
}
|
|
165
253
|
const runtimeStatus = unit.runtime.status();
|
|
254
|
+
// 配置非法时运行态是"按缺省值起的"(Bus 可能根本没起),这一点必须和状态一起显示。
|
|
255
|
+
const { errors: configErrors = [] } = unit.centerStore.read();
|
|
166
256
|
return {
|
|
167
257
|
ok: true,
|
|
168
258
|
result: {
|
|
169
259
|
aid,
|
|
260
|
+
...(configErrors.length > 0 ? { configErrors } : {}),
|
|
170
261
|
bus: runtimeStatus.bus,
|
|
171
262
|
subscriptions: runtimeStatus.subscriptions,
|
|
263
|
+
pendingSubscriptions: runtimeStatus.pendingSubscriptions,
|
|
172
264
|
publishers: runtimeStatus.publishers,
|
|
173
265
|
packs: [
|
|
174
266
|
...unit.state.enabledPacks.map(pack => packStatus(unit, pack.id)),
|
|
@@ -179,6 +271,12 @@ async function execute(deps, parsed) {
|
|
|
179
271
|
};
|
|
180
272
|
}
|
|
181
273
|
case 'ledger': {
|
|
274
|
+
// 不传包名 = 读中心台账(bus.start/stop、gate、allowlist.update 在这里,
|
|
275
|
+
// 包级 ledger 只有 pack.load/subscribe)。
|
|
276
|
+
if (!parsed.pack) {
|
|
277
|
+
const lines = centerLedger(unit.eventsDir).tail(parsed.tail ?? 20);
|
|
278
|
+
return { ok: true, result: { aid, scope: 'center', lines } };
|
|
279
|
+
}
|
|
182
280
|
const pack = requirePack(unit, parsed.pack);
|
|
183
281
|
if ('ok' in pack)
|
|
184
282
|
return pack;
|
|
@@ -199,23 +297,31 @@ async function execute(deps, parsed) {
|
|
|
199
297
|
const findings = await doctor(unit, pack.id);
|
|
200
298
|
return { ok: true, result: { aid, pack: pack.id, findings } };
|
|
201
299
|
}
|
|
202
|
-
case '
|
|
203
|
-
const { config } = unit.centerStore.read();
|
|
300
|
+
case 'rules:show': {
|
|
301
|
+
const { config, errors: configErrors = [] } = unit.centerStore.read();
|
|
204
302
|
const entries = parsed.event
|
|
205
|
-
? { [parsed.event]: config.
|
|
206
|
-
: config.
|
|
207
|
-
|
|
303
|
+
? { [parsed.event]: config.rules[parsed.event] ?? { allow: { publish: [], subscribe: [] }, deny: { publish: [], subscribe: [] } } }
|
|
304
|
+
: config.rules;
|
|
305
|
+
// errors 非空时 `rules` 是缺省值而不是磁盘内容——必须让调用方看得见,
|
|
306
|
+
// 否则会误以为"规则被清空了"。
|
|
307
|
+
return {
|
|
308
|
+
ok: true,
|
|
309
|
+
result: {
|
|
310
|
+
aid, enabled: config.enabled, authMode: config.authMode, rules: entries,
|
|
311
|
+
...(configErrors.length > 0 ? { configErrors } : {}),
|
|
312
|
+
},
|
|
313
|
+
};
|
|
208
314
|
}
|
|
209
|
-
case '
|
|
210
|
-
case '
|
|
315
|
+
case 'rules:add':
|
|
316
|
+
case 'rules:remove': {
|
|
211
317
|
if (!parsed.event)
|
|
212
|
-
return { ok: false, code: 'INVALID_ARGV', error: '
|
|
318
|
+
return { ok: false, code: 'INVALID_ARGV', error: 'rules add/remove requires <event>' };
|
|
213
319
|
if (!unit.state.catalog.some(entry => entry.event === parsed.event))
|
|
214
320
|
return { ok: false, code: 'EVENT_NOT_FOUND', error: `event is not registered: ${parsed.event}` };
|
|
215
321
|
if (!parsed.aids.publish && !parsed.aids.subscribe) {
|
|
216
|
-
return { ok: false, code: 'INVALID_ARGV', error: '
|
|
322
|
+
return { ok: false, code: 'INVALID_ARGV', error: 'rules add/remove requires --publish <aid> and/or --subscribe <aid>' };
|
|
217
323
|
}
|
|
218
|
-
const action = command === '
|
|
324
|
+
const action = command === 'rules:add' ? 'add' : 'remove';
|
|
219
325
|
const applied = {};
|
|
220
326
|
for (const role of ['publish', 'subscribe']) {
|
|
221
327
|
const aids = parsed.aids[role];
|
|
@@ -242,7 +348,9 @@ async function execute(deps, parsed) {
|
|
|
242
348
|
if (typeof parsed.data !== 'object' || parsed.data === null || Array.isArray(parsed.data)) {
|
|
243
349
|
return { ok: false, code: 'INVALID_ARGV', error: '--data must be a JSON object' };
|
|
244
350
|
}
|
|
245
|
-
|
|
351
|
+
// 发布方身份用于限流计数:托管会话用其 agent,主机终端用本机 AID。
|
|
352
|
+
const publisherAid = parsed.caller?.kind === 'managed' ? parsed.caller.selfAid : undefined;
|
|
353
|
+
const eventId = await unit.runtime.publish(parsed.pack, parsed.event, parsed.data, parsed.ttl, publisherAid);
|
|
246
354
|
return { ok: true, result: { aid, pack: parsed.pack, event: parsed.event, eventId } };
|
|
247
355
|
}
|
|
248
356
|
default:
|
|
@@ -295,13 +403,20 @@ async function doctor(unit, packId) {
|
|
|
295
403
|
findings.push(unresolved.length
|
|
296
404
|
? { level: 'error', check: 'bus-resolve', detail: `unresolved: ${unresolved.join(', ')}` }
|
|
297
405
|
: { level: 'ok', check: 'bus-resolve', detail: 'all buses resolved' });
|
|
298
|
-
const { config } = unit.centerStore.read();
|
|
406
|
+
const { config, errors: configErrors } = unit.centerStore.read();
|
|
407
|
+
// 配置非法时 read() 会退回缺省值;不把错误报出来,用户只会看到"规则没了"。
|
|
408
|
+
if (configErrors.length > 0) {
|
|
409
|
+
findings.push({ level: 'error', check: 'events-config.json', detail: configErrors.join('; ') });
|
|
410
|
+
}
|
|
299
411
|
if (pack.register.length > 0 && !config.enabled) {
|
|
300
|
-
findings.push({ level: 'warn', check: '
|
|
412
|
+
findings.push({ level: 'warn', check: 'config', detail: 'register entries exist but events-config.json enabled=false; bus not started' });
|
|
301
413
|
}
|
|
302
414
|
for (const entry of pack.register) {
|
|
303
|
-
|
|
304
|
-
|
|
415
|
+
const rule = config.rules[entry.event];
|
|
416
|
+
// 没有 rules 条目是**正常默认**:此时按联系人准入放行(自 AID / Owner / 联系人),
|
|
417
|
+
// 不是"没人能发"。只有当条目存在且 deny 把自 AID 也挡了才是真问题。
|
|
418
|
+
if (rule && rule.deny.publish.includes(unit.aid) && rule.deny.subscribe.includes(unit.aid)) {
|
|
419
|
+
findings.push({ level: 'warn', check: 'rules', detail: `${entry.event} denies the local AID in both directions; it cannot publish or subscribe` });
|
|
305
420
|
}
|
|
306
421
|
}
|
|
307
422
|
return findings;
|
|
@@ -1,38 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 事件包目录扫描与加载:events/<pack>/pack.json
|
|
3
|
-
*
|
|
2
|
+
* 事件包目录扫描与加载:events/<pack>/pack.json 与 events/events-config.json。
|
|
3
|
+
* 每个东西只有一个名字,不接受别名(包主要由 agent 生成,多一个写法就多一次选错的机会)。
|
|
4
4
|
* 脚本路径做 realpath 全级校验,防符号链接逃逸出包目录。
|
|
5
5
|
*/
|
|
6
6
|
import fs from 'node:fs';
|
|
7
7
|
import path from 'node:path';
|
|
8
8
|
import { sha256 } from '../trigger/validation.js';
|
|
9
9
|
import { validateCenterConfig, validatePackJson } from './validation.js';
|
|
10
|
+
import { migrateLegacyFileName } from '../core/legacy-rename.js';
|
|
11
|
+
import { PACK_ARCHIVED_MARKER as ARCHIVED_MARKER } from '../core/pack-install.js';
|
|
12
|
+
import { atomicWriteJson } from '../utils/atomic-write.js';
|
|
13
|
+
import { logger } from '../utils/logger.js';
|
|
14
|
+
/**
|
|
15
|
+
* 事件包与服务包的文件名一一对应,且**每个东西只有一个名字**(不留别名):
|
|
16
|
+
*
|
|
17
|
+
* | 位置 | 文件名 |
|
|
18
|
+
* | --- | --- |
|
|
19
|
+
* | AID 级配置 | `events-config.json` / `services-config.json` |
|
|
20
|
+
* | 包声明 | `pack.json`(两侧同名) |
|
|
21
|
+
* | 包台账 | `ledger.jsonl`(两侧同名) |
|
|
22
|
+
* | 脚本目录 | `scripts/`(两侧同名) |
|
|
23
|
+
* | 日志目录 | `logs/`(两侧同名) |
|
|
24
|
+
*
|
|
25
|
+
* 不设别名的理由:包主要由 agent 生成,多一个可接受的写法就多一次选错的机会。
|
|
26
|
+
*/
|
|
10
27
|
export const PACK_JSON = 'pack.json';
|
|
11
|
-
export const PACK_JSON_ALIASES = ['关注的事件.json', '会议关注的事件.json'];
|
|
12
28
|
export const LEDGER_FILE = 'ledger.jsonl';
|
|
13
|
-
export const LEDGER_FILE_ALIASES = ['已注册的标记文件.jsonl'];
|
|
14
29
|
export const SCRIPTS_DIR = 'scripts';
|
|
15
|
-
export const SCRIPTS_DIR_ALIAS = '事件处理脚本';
|
|
16
30
|
export const LOGS_DIR = 'logs';
|
|
17
|
-
export const
|
|
18
|
-
export const CENTER_JSON = 'center.json';
|
|
19
|
-
/** 规范名优先;规范名与任一别名同时存在 → 冲突;都缺 → undefined。 */
|
|
20
|
-
function resolveCanonicalPath(dir, canonical, aliases, errors) {
|
|
21
|
-
const canonicalPath = path.join(dir, canonical);
|
|
22
|
-
const aliasPaths = aliases.map(alias => path.join(dir, alias)).filter(candidate => fs.existsSync(candidate));
|
|
23
|
-
if (fs.existsSync(canonicalPath)) {
|
|
24
|
-
if (aliasPaths.length) {
|
|
25
|
-
errors.push(`both ${canonical} and ${aliasPaths.map(item => path.basename(item)).join(', ')} exist; keep exactly one`);
|
|
26
|
-
return undefined;
|
|
27
|
-
}
|
|
28
|
-
return canonicalPath;
|
|
29
|
-
}
|
|
30
|
-
if (aliasPaths.length > 1) {
|
|
31
|
-
errors.push(`multiple aliases exist for ${canonical}: ${aliasPaths.map(item => path.basename(item)).join(', ')}`);
|
|
32
|
-
return undefined;
|
|
33
|
-
}
|
|
34
|
-
return aliasPaths[0];
|
|
35
|
-
}
|
|
31
|
+
export const EVENTS_CONFIG_JSON = 'events-config.json';
|
|
36
32
|
/** realpath 全级校验:目标真实路径必须仍在包目录内(防中间目录符号链接逃逸)。 */
|
|
37
33
|
function assertInsidePackDir(packDir, target, errors, field) {
|
|
38
34
|
let realTarget;
|
|
@@ -53,9 +49,16 @@ function assertInsidePackDir(packDir, target, errors, field) {
|
|
|
53
49
|
/** 加载单个包目录。返回 null 表示该包 invalid(errors 已填)。 */
|
|
54
50
|
export function loadPackDir(packDir, errors) {
|
|
55
51
|
const packId = path.basename(packDir);
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
// 旧名 关注的事件.json / 会议关注的事件.json 曾作为 pack.json 的别名,
|
|
53
|
+
// 已取消别名:首次加载时一次性迁移成 pack.json,之后只认规范名。
|
|
54
|
+
for (const legacy of ['关注的事件.json', '会议关注的事件.json']) {
|
|
55
|
+
migrateLegacyFileName(packDir, legacy, PACK_JSON, `events pack ${packId}`);
|
|
56
|
+
}
|
|
57
|
+
const packJsonPath = path.join(packDir, PACK_JSON);
|
|
58
|
+
if (!fs.existsSync(packJsonPath)) {
|
|
59
|
+
errors.push(`missing ${PACK_JSON}`);
|
|
58
60
|
return null;
|
|
61
|
+
}
|
|
59
62
|
let rawText;
|
|
60
63
|
try {
|
|
61
64
|
rawText = fs.readFileSync(packJsonPath, 'utf8');
|
|
@@ -77,22 +80,13 @@ export function loadPackDir(packDir, errors) {
|
|
|
77
80
|
errors.push(...validated.errors);
|
|
78
81
|
return null;
|
|
79
82
|
}
|
|
80
|
-
//
|
|
83
|
+
// 脚本目录:只认 scripts/。声明了 subscribe 却没有该目录即 invalid。
|
|
81
84
|
let scriptsDir;
|
|
82
85
|
const canonicalScripts = path.join(packDir, SCRIPTS_DIR);
|
|
83
|
-
|
|
84
|
-
const hasCanonical = fs.existsSync(canonicalScripts);
|
|
85
|
-
const hasAlias = fs.existsSync(aliasScripts);
|
|
86
|
-
if (hasCanonical && hasAlias) {
|
|
87
|
-
errors.push(`both ${SCRIPTS_DIR}/ and ${SCRIPTS_DIR_ALIAS}/ exist; keep exactly one`);
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
if (hasCanonical)
|
|
86
|
+
if (fs.existsSync(canonicalScripts))
|
|
91
87
|
scriptsDir = canonicalScripts;
|
|
92
|
-
else if (hasAlias)
|
|
93
|
-
scriptsDir = aliasScripts;
|
|
94
88
|
else if (validated.value.subscribe.length > 0) {
|
|
95
|
-
errors.push(`scripts directory not found: expected ${SCRIPTS_DIR}
|
|
89
|
+
errors.push(`scripts directory not found: expected ${SCRIPTS_DIR}/`);
|
|
96
90
|
return null;
|
|
97
91
|
}
|
|
98
92
|
// 脚本存在性 + realpath 越界校验(realpath 覆盖全路径各级目录的符号链接)。
|
|
@@ -106,18 +100,8 @@ export function loadPackDir(packDir, errors) {
|
|
|
106
100
|
errors.push(`handler.script "${entry.handler.script}" is not a regular file`);
|
|
107
101
|
}
|
|
108
102
|
}
|
|
109
|
-
const ledgerPath =
|
|
110
|
-
const logsDir = (
|
|
111
|
-
const canonicalLogs = path.join(packDir, LOGS_DIR);
|
|
112
|
-
const aliasLogs = path.join(packDir, LOGS_DIR_ALIAS);
|
|
113
|
-
const hasCanonicalLogs = fs.existsSync(canonicalLogs);
|
|
114
|
-
const hasAliasLogs = fs.existsSync(aliasLogs);
|
|
115
|
-
if (hasCanonicalLogs && hasAliasLogs) {
|
|
116
|
-
errors.push(`both ${LOGS_DIR}/ and ${LOGS_DIR_ALIAS}/ exist; keep exactly one`);
|
|
117
|
-
return canonicalLogs;
|
|
118
|
-
}
|
|
119
|
-
return hasCanonicalLogs ? canonicalLogs : aliasLogs;
|
|
120
|
-
})();
|
|
103
|
+
const ledgerPath = path.join(packDir, LEDGER_FILE);
|
|
104
|
+
const logsDir = path.join(packDir, LOGS_DIR);
|
|
121
105
|
if (!fs.existsSync(logsDir)) {
|
|
122
106
|
try {
|
|
123
107
|
fs.mkdirSync(logsDir, { recursive: true });
|
|
@@ -164,6 +148,11 @@ export function loadPacks(eventsDir) {
|
|
|
164
148
|
if (entry.name.startsWith('.') || entry.name.startsWith('_'))
|
|
165
149
|
continue;
|
|
166
150
|
const packDir = path.join(eventsDir, entry.name);
|
|
151
|
+
// 已卸载但保留归档的目录(`pack remove` 留下 .archived):不是包,也不是坏包。
|
|
152
|
+
// 必须在这里跳过而不是靠 loadPackDir 返回 null —— 那个 null 在下面会被
|
|
153
|
+
// 记成 invalid 并往它的 ledger 里写一条 pack.invalid。
|
|
154
|
+
if (fs.existsSync(path.join(packDir, ARCHIVED_MARKER)))
|
|
155
|
+
continue;
|
|
167
156
|
const errors = [];
|
|
168
157
|
const pack = loadPackDir(packDir, errors);
|
|
169
158
|
if (pack)
|
|
@@ -173,15 +162,17 @@ export function loadPacks(eventsDir) {
|
|
|
173
162
|
}
|
|
174
163
|
return { valid, invalid };
|
|
175
164
|
}
|
|
176
|
-
/** 读取 events/
|
|
165
|
+
/** 读取 events/events-config.json;不存在返回缺省(enabled=false)。 */
|
|
177
166
|
export function loadCenterConfig(eventsDir) {
|
|
178
|
-
|
|
167
|
+
// 旧名 center.json 一次性迁移成 events-config.json(只搬运,不双读)。
|
|
168
|
+
migrateLegacyFileName(eventsDir, 'center.json', EVENTS_CONFIG_JSON, 'events config');
|
|
169
|
+
const filePath = path.join(eventsDir, EVENTS_CONFIG_JSON);
|
|
179
170
|
let rawText;
|
|
180
171
|
try {
|
|
181
172
|
rawText = fs.readFileSync(filePath, 'utf8');
|
|
182
173
|
}
|
|
183
174
|
catch {
|
|
184
|
-
return { config: { enabled: false, authMode: 'allowlist', admission: { coupling: 'on', rematerializeMs: 300_000 },
|
|
175
|
+
return { config: { enabled: false, authMode: 'allowlist', admission: { coupling: 'on', rematerializeMs: 300_000 }, rules: {}, rateLimit: { perMinute: 60, perHour: 600 } }, exists: false, errors: [] };
|
|
185
176
|
}
|
|
186
177
|
let raw;
|
|
187
178
|
try {
|
|
@@ -189,14 +180,28 @@ export function loadCenterConfig(eventsDir) {
|
|
|
189
180
|
}
|
|
190
181
|
catch (error) {
|
|
191
182
|
return {
|
|
192
|
-
config: { enabled: false, authMode: 'allowlist', admission: { coupling: 'on', rematerializeMs: 300_000 },
|
|
183
|
+
config: { enabled: false, authMode: 'allowlist', admission: { coupling: 'on', rematerializeMs: 300_000 }, rules: {}, rateLimit: { perMinute: 60, perHour: 600 } },
|
|
193
184
|
exists: true,
|
|
194
|
-
errors: [`${
|
|
185
|
+
errors: [`${EVENTS_CONFIG_JSON} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`],
|
|
195
186
|
};
|
|
196
187
|
}
|
|
188
|
+
// 旧键名 `allowlist` 一次性迁移成 `rules`(它同时装 allow 与 deny,叫 allowlist 会误导)。
|
|
189
|
+
// 只搬运、不双读:迁移后写回时只有 rules。authMode 的 'allowlist' 是协议取值,不动。
|
|
190
|
+
if (raw && typeof raw === 'object' && !Array.isArray(raw)) {
|
|
191
|
+
const record = raw;
|
|
192
|
+
if (!('rules' in record) && 'allowlist' in record) {
|
|
193
|
+
record.rules = record.allowlist;
|
|
194
|
+
delete record.allowlist;
|
|
195
|
+
try {
|
|
196
|
+
atomicWriteJson(filePath, record);
|
|
197
|
+
logger.info(`[migration] ${EVENTS_CONFIG_JSON}: allowlist → rules`);
|
|
198
|
+
}
|
|
199
|
+
catch { /* 写回失败不影响本次读取 */ }
|
|
200
|
+
}
|
|
201
|
+
}
|
|
197
202
|
const validated = validateCenterConfig(raw);
|
|
198
203
|
if (!validated.ok) {
|
|
199
|
-
return { config: { enabled: false, authMode: 'allowlist', admission: { coupling: 'on', rematerializeMs: 300_000 },
|
|
204
|
+
return { config: { enabled: false, authMode: 'allowlist', admission: { coupling: 'on', rematerializeMs: 300_000 }, rules: {}, rateLimit: { perMinute: 60, perHour: 600 } }, exists: true, errors: validated.errors };
|
|
200
205
|
}
|
|
201
206
|
return { config: validated.value, exists: true, errors: [] };
|
|
202
207
|
}
|
|
@@ -73,10 +73,10 @@ export function toSdkCatalog(catalog) {
|
|
|
73
73
|
}
|
|
74
74
|
return out;
|
|
75
75
|
}
|
|
76
|
-
/**
|
|
76
|
+
/** events-config.json 的 rules(物化后)→ SDK start/updateConfig 的 allowlist 参数。 */
|
|
77
77
|
export function toSdkAllowlist(config) {
|
|
78
78
|
const out = {};
|
|
79
|
-
for (const [event, entry] of Object.entries(config.
|
|
79
|
+
for (const [event, entry] of Object.entries(config.rules)) {
|
|
80
80
|
const publish = entry.allow.publish.filter(aid => !entry.deny.publish.includes(aid));
|
|
81
81
|
const subscribe = entry.allow.subscribe.filter(aid => !entry.deny.subscribe.includes(aid));
|
|
82
82
|
out[event] = { publish_aids: [...publish], subscribe_aids: [...subscribe] };
|