evolcore 0.0.43-test.6 → 0.0.43-test.7
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 +48 -0
- package/bin/ecmsg.js +171 -54
- package/dist/agents/baseagent-availability.js +1 -1
- package/dist/agents/codex/app-server-client.js +22 -0
- package/dist/agents/codex-runner.js +69 -2
- package/dist/aun/msg/p2p.js +6 -1
- package/dist/channels/aun.js +234 -21
- package/dist/cli/agent-create.js +2 -2
- package/dist/cli/daemon-commands.js +6 -66
- package/dist/cli/daemon-lifecycle-client.js +61 -0
- package/dist/cli/ecmsg-gateway.js +35 -2
- package/dist/cli/events-command.js +73 -0
- package/dist/cli/index.js +31 -14
- package/dist/cli/invoke-command.js +182 -0
- package/dist/cli/managed-command-guard.js +6 -1
- package/dist/cli/restart-monitor.js +45 -47
- package/dist/cli/services-command.js +111 -0
- package/dist/cli/team-workspace-command.js +134 -0
- package/dist/cli/thread-command.js +6 -2
- package/dist/cli/watch-msg.js +1 -1
- package/dist/config/config-field-policy.js +2 -2
- package/dist/config/config-manager.js +0 -7
- package/dist/config/invoke-ipc-service.js +118 -0
- package/dist/config/schema-migration.js +6 -1
- package/dist/config-store.js +2 -1
- package/dist/core/agent-reload-coordinator.js +6 -4
- package/dist/core/agent-runtime.js +104 -10
- package/dist/core/auth/delegation-authorization.js +66 -0
- package/dist/core/auth/operation-catalog.js +20 -0
- package/dist/core/baseagent-loader.js +60 -130
- package/dist/core/channel-loader.js +10 -1
- package/dist/core/channel-runtime.js +4 -3
- package/dist/core/command/agent-control.js +1 -1
- package/dist/core/command/agent-storage-menu.js +1 -1
- package/dist/core/command/chatmode-config.js +2 -36
- package/dist/core/command/command-handler.js +53 -11
- package/dist/core/command/data-root-resolver.js +32 -23
- package/dist/core/command/eventcenter-menu.js +338 -0
- package/dist/core/command/menu-catalog.js +8 -0
- package/dist/core/command/menu-handler.js +198 -84
- package/dist/core/command/menu-protocol.js +60 -11
- package/dist/core/command/menu-query-batch.js +194 -0
- package/dist/core/command/slash-gate.js +1 -1
- package/dist/core/command/slash-handler.js +34 -42
- package/dist/core/command/team-workspace-bootstrap.js +350 -0
- package/dist/core/command/{pa-workspace-calendar.js → team-workspace-calendar.js} +7 -7
- package/dist/core/command/team-workspace-initializer.js +2 -0
- package/dist/core/command/{pa-workspace-items.js → team-workspace-items.js} +83 -68
- package/dist/core/command/team-workspace-job-store.js +88 -0
- package/dist/core/command/team-workspace-management-service.js +2 -0
- package/dist/core/command/team-workspace-management-store.js +96 -0
- package/dist/core/command/team-workspace-management.js +265 -0
- package/dist/core/command/team-workspace-members-menu.js +88 -0
- package/dist/core/command/team-workspace-store.js +612 -0
- package/dist/core/command/team-workspace-team.js +193 -0
- package/dist/core/daemon-control.js +8 -5
- package/dist/core/daemon-lifecycle.js +132 -73
- package/dist/core/handoff/runtime.js +3 -3
- package/dist/core/invoke/executors/index.js +13 -0
- package/dist/core/invoke/executors/media.js +283 -0
- package/dist/core/invoke/executors/text.js +198 -0
- package/dist/core/invoke/invoke-service.js +157 -0
- package/dist/core/invoke/style-router.js +48 -0
- package/dist/core/invoke/types.js +19 -0
- package/dist/core/ipc-registration.js +46 -7
- package/dist/core/memory/consolidation.js +7 -5
- package/dist/core/message/aun-ipc-sender.js +147 -17
- package/dist/core/message/im-renderer.js +28 -84
- package/dist/core/message/message-bridge.js +4 -0
- package/dist/core/message/message-utils.js +10 -2
- package/dist/core/message/peer-mode.js +7 -34
- package/dist/core/message/response-engine.js +157 -54
- package/dist/core/message/send-options.js +7 -4
- package/dist/core/message/send-routing.js +43 -5
- package/dist/core/ownership/owner-resolver.js +7 -0
- package/dist/core/permission/ec-command-parser.js +3 -2
- package/dist/core/permission/protected-paths.js +12 -2
- package/dist/core/permission/shell-environment.js +9 -0
- package/dist/core/session/session-file-health.js +243 -0
- package/dist/core/session/session-fs-store.js +2 -3
- package/dist/core/task/task-recovery-service.js +13 -2
- package/dist/core/thread/command-parser.js +9 -2
- package/dist/core/thread/thread-operation.js +21 -2
- package/dist/core/thread/thread-route.js +13 -2
- package/dist/directory/owner-directory-admission.js +40 -53
- package/dist/directory/owner-directory-cache.js +89 -113
- package/dist/directory/owner-directory-query-operation.js +8 -10
- package/dist/eck/kit-renderer.js +7 -5
- package/dist/ecweb/basic-settings-service.js +1 -1
- package/dist/ecweb/message-context-service.js +0 -4
- package/dist/ecweb/runtime/lifecycle.js +6 -2
- package/dist/ecweb/runtime/supervisor.js +19 -4
- package/dist/event-center/admission-materializer.js +114 -0
- package/dist/event-center/bus-gate.js +136 -0
- package/dist/event-center/bus-host.js +290 -0
- package/dist/event-center/bus-resolver.js +120 -0
- package/dist/event-center/center-config.js +100 -0
- package/dist/event-center/client-factory.js +50 -0
- package/dist/event-center/daemon.js +45 -0
- package/dist/event-center/directory-source.js +53 -0
- package/dist/event-center/dispatcher.js +157 -0
- package/dist/event-center/event-log.js +110 -0
- package/dist/event-center/index-generator.js +63 -0
- package/dist/event-center/ipc-operation.js +308 -0
- package/dist/event-center/ledger.js +52 -0
- package/dist/event-center/pack-loader.js +202 -0
- package/dist/event-center/pack-manager.js +85 -0
- package/dist/event-center/registry.js +238 -0
- package/dist/event-center/runtime.js +641 -0
- package/dist/event-center/script-runner.js +356 -0
- package/dist/event-center/types.js +35 -0
- package/dist/event-center/validation.js +413 -0
- package/dist/index.js +285 -99
- package/dist/ipc.js +66 -12
- package/dist/paths.js +20 -0
- package/dist/product.js +14 -0
- package/dist/proxy/manager.js +5 -1
- package/dist/proxy/service-supervisor.js +13 -4
- package/dist/response-system/engines/v1/index.js +0 -1
- package/dist/response-system/modes/single-session/index.js +1 -1
- package/dist/services/dispatcher.js +100 -0
- package/dist/services/idempotency.js +90 -0
- package/dist/services/identity.js +52 -0
- package/dist/services/index-generator.js +70 -0
- package/dist/services/index.js +449 -0
- package/dist/services/ipc-operation.js +458 -0
- package/dist/services/ledger.js +52 -0
- package/dist/services/message-log.js +112 -0
- package/dist/services/pack-manager.js +204 -0
- package/dist/services/reply.js +55 -0
- package/dist/services/router.js +95 -0
- package/dist/services/script-runner.js +422 -0
- package/dist/services/service-payload.js +70 -0
- package/dist/services/types.js +18 -0
- package/dist/services/validation.js +297 -0
- package/dist/trigger/application-service.js +18 -0
- package/dist/trigger/event-source.js +1 -1
- package/dist/trigger/ipc-service.js +3 -1
- package/dist/trigger/script-sandbox.js +118 -22
- package/dist/utils/cross-platform.js +24 -10
- package/dist/utils/evolcore-version.js +69 -27
- package/dist/utils/instance-registry.js +19 -13
- package/dist/utils/process-introspect.js +45 -9
- package/dist/utils/startup-trace.js +74 -37
- package/dist/utils/windows-shell-trust.js +80 -6
- package/kits/docs/INDEX.md +2 -2
- package/kits/docs/aun/ABILITY_CALLING.md +7 -14
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +2 -0
- package/kits/docs/evolcore/ability.md +4 -0
- package/kits/docs/evolcore/aid.md +1 -1
- package/kits/docs/evolcore/event-center.md +207 -0
- package/kits/docs/evolcore/file-navigation.md +10 -264
- package/kits/docs/evolcore/fs.md +3 -2
- package/kits/docs/evolcore/group.md +1 -1
- package/kits/docs/evolcore/memory-architecture.md +2 -0
- package/kits/docs/evolcore/menu-protocol.md +21 -0
- package/kits/docs/evolcore/msg.md +15 -3
- package/kits/docs/evolcore/provider.md +3 -1
- package/kits/docs/evolcore/response.md +5 -5
- package/kits/docs/evolcore/services.md +277 -0
- package/kits/docs/evolcore/task.md +2 -0
- package/kits/docs/evolcore/team-workspace.md +41 -0
- package/kits/eck_manifest.json +26 -0
- package/kits/rules/02-navigation.md +10 -1
- package/kits/schemas/_meta.json +17 -6
- package/kits/schemas/agent-config.schema.19.json +5 -7
- package/kits/schemas/agent-config.schema.20.json +936 -0
- package/kits/schemas/relation-config.schema.12.json +2 -3
- package/kits/schemas/role-config.schema.2.json +4 -4
- package/kits/skills/.switches.json +1 -5
- package/kits/skills/ability/SKILL.md +56 -0
- package/kits/skills/ability/references/calling.md +56 -0
- package/kits/skills/{ec-ability → ability}/references/contract-checklist.md +1 -1
- package/kits/skills/{ec-ability → ability}/references/development.md +9 -33
- package/kits/skills/{ec-ability → ability}/references/management.md +2 -2
- package/kits/skills/{ec-ability → ability}/references/recovery.md +1 -1
- package/kits/skills/{ec-ability → ability}/references/runtime-protocol.md +2 -0
- package/kits/skills/ec-agent-create/SKILL.md +0 -1
- package/kits/skills/ec-service-proxy/SKILL.md +34 -5
- package/kits/skills/personal-assistant/SKILL.md +6 -6
- package/kits/skills/personal-assistant/references/02-bootstrap.md +4 -4
- package/kits/skills/personal-assistant/scripts/clean.mjs +4 -4
- package/kits/skills/personal-assistant/scripts/init.mjs +2 -2
- package/kits/skills/personal-assistant/scripts/pa.mjs +4 -4
- package/kits/templates/system-fragments/channel.md +3 -3
- package/kits/templates/system-fragments/commands.md +5 -3
- package/kits/templates/system-fragments/reply.md +0 -5
- package/kits/templates/system-fragments/thread.md +10 -8
- package/package.json +3 -5
- package/dist/cli/pa-workspace-command.js +0 -225
- package/dist/core/command/pa-workspace-store.js +0 -468
- package/dist/core/relation/pa-team.js +0 -132
- package/kits/docs/evolcore/pa-workspace.md +0 -51
- package/kits/skills/aid-ability/SKILL.md +0 -244
- package/kits/skills/ec-ability/SKILL.md +0 -67
- package/kits/skills/ec-ability/references/workflows.md +0 -15
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 生成 `$AGENT_DIR/events/.index.md`:本机已启用事件包的订阅/发布清单。
|
|
3
|
+
*
|
|
4
|
+
* 只列 enabled 且无冲突的包(PackState.enabledPacks)。空集时删除文件而不是写空文件——
|
|
5
|
+
* 让 manifest 的 `optional` 判定与文件存在性始终一致。
|
|
6
|
+
*
|
|
7
|
+
* 格式见 docs/eck/services-and-events-manifest.md §五。
|
|
8
|
+
*/
|
|
9
|
+
import fs from 'node:fs';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import { logger } from '../utils/logger.js';
|
|
12
|
+
export const EVENTS_INDEX_FILE = '.index.md';
|
|
13
|
+
/**
|
|
14
|
+
* @param eventsDir `$AGENT_DIR/events`
|
|
15
|
+
* @param enabledPacks 已启用且无冲突的包
|
|
16
|
+
* @param resolutions 包 → (bus 引用 → 解析后的 AID);用于把 `$owner` 等占位符渲染成真实值
|
|
17
|
+
*/
|
|
18
|
+
export function writeEventsIndex(eventsDir, enabledPacks, resolutions) {
|
|
19
|
+
const filePath = path.join(eventsDir, EVENTS_INDEX_FILE);
|
|
20
|
+
if (enabledPacks.length === 0) {
|
|
21
|
+
try {
|
|
22
|
+
if (fs.existsSync(filePath)) {
|
|
23
|
+
fs.unlinkSync(filePath);
|
|
24
|
+
logger.debug(`[events-index] ${EVENTS_INDEX_FILE} 已删除(无启用事件包)`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
logger.warn(`[events-index] cannot remove stale index: ${error instanceof Error ? error.message : String(error)}`);
|
|
29
|
+
}
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const lines = [];
|
|
33
|
+
lines.push(`[events] 本 Agent 已启用 ${enabledPacks.length} 个事件包,订阅以下事件。`);
|
|
34
|
+
lines.push('');
|
|
35
|
+
lines.push('事件是 TTL 内的在线通知,可能丢失;需要不丢的语义用普通消息。');
|
|
36
|
+
lines.push('');
|
|
37
|
+
for (const pack of enabledPacks) {
|
|
38
|
+
lines.push(`- ${pack.id}(${pack.name})`);
|
|
39
|
+
const resolution = resolutions?.get(pack.id);
|
|
40
|
+
for (const entry of pack.subscribe) {
|
|
41
|
+
const bus = resolution?.get(entry.bus) ?? entry.busResolved ?? entry.bus;
|
|
42
|
+
lines.push(` 订阅: ${bus} 的 ${entry.event} → ${entry.handler.script}`);
|
|
43
|
+
}
|
|
44
|
+
for (const entry of pack.publish) {
|
|
45
|
+
const bus = resolution?.get(entry.bus) ?? entry.busResolved ?? entry.bus;
|
|
46
|
+
lines.push(` 发布: ${bus} 的 ${entry.event}(本机可发)`);
|
|
47
|
+
}
|
|
48
|
+
if (pack.subscribe.length === 0 && pack.publish.length === 0) {
|
|
49
|
+
lines.push(' (仅登记事件目录,无订阅或发布)');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
lines.push('');
|
|
53
|
+
lines.push('本机管理: ec events status / ledger / tail');
|
|
54
|
+
lines.push('');
|
|
55
|
+
try {
|
|
56
|
+
fs.mkdirSync(eventsDir, { recursive: true });
|
|
57
|
+
fs.writeFileSync(filePath, lines.join('\n'), 'utf8');
|
|
58
|
+
logger.debug(`[events-index] ${EVENTS_INDEX_FILE} 已生成(${enabledPacks.length} 个包)`);
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
logger.warn(`[events-index] cannot write index: ${error instanceof Error ? error.message : String(error)}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ec events` 的 daemon 侧 IPC 操作(events.op)。
|
|
3
|
+
* daemon-control 风格(不走 delegation argv 哈希);CLI 透传 argv,daemon 解析执行。
|
|
4
|
+
*/
|
|
5
|
+
import { logger } from '../utils/logger.js';
|
|
6
|
+
import { Ledger } from './ledger.js';
|
|
7
|
+
import { EventLog } from './event-log.js';
|
|
8
|
+
import { loadPackDir } from './pack-loader.js';
|
|
9
|
+
import { toSdkCatalog } from './pack-manager.js';
|
|
10
|
+
import { materializeAllowlist } from './admission-materializer.js';
|
|
11
|
+
import { EventCenterError, errorMessage } from './types.js';
|
|
12
|
+
const HELP = `ec events — 事件中心运维
|
|
13
|
+
|
|
14
|
+
用法:
|
|
15
|
+
ec events status [<包名>] [--aid <aid>] 每包状态
|
|
16
|
+
ec events ledger <包名> [--tail N] 台账
|
|
17
|
+
ec events tail <包名> [--tail N] 事件日志
|
|
18
|
+
ec events doctor <包名> 诊断
|
|
19
|
+
ec events reload [<包名>] 重载(重新扫描目录并重建订阅)
|
|
20
|
+
ec events allowlist add <事件> --publish <aid> [--subscribe <aid>]
|
|
21
|
+
ec events allowlist remove <事件> --publish <aid> [--subscribe <aid>]
|
|
22
|
+
ec events allowlist show [--event <事件>]
|
|
23
|
+
ec events publish <包名> <事件> --data '<json>' [--ttl <秒>]`;
|
|
24
|
+
export function parseEventsArgv(argv) {
|
|
25
|
+
const args = [...argv];
|
|
26
|
+
if (args.length === 0 || args[0] === 'help' || args[0] === '--help')
|
|
27
|
+
return { command: 'help', aids: {} };
|
|
28
|
+
const command = args.shift();
|
|
29
|
+
const parsed = { command, aids: {} };
|
|
30
|
+
const consumeValue = (flag) => {
|
|
31
|
+
const index = args.indexOf(flag);
|
|
32
|
+
if (index < 0)
|
|
33
|
+
return undefined;
|
|
34
|
+
const value = args[index + 1];
|
|
35
|
+
if (value === undefined)
|
|
36
|
+
return undefined;
|
|
37
|
+
args.splice(index, 2);
|
|
38
|
+
return value;
|
|
39
|
+
};
|
|
40
|
+
const consumeList = (flag) => {
|
|
41
|
+
const values = [];
|
|
42
|
+
for (;;) {
|
|
43
|
+
const value = consumeValue(flag);
|
|
44
|
+
if (value === undefined)
|
|
45
|
+
break;
|
|
46
|
+
values.push(value);
|
|
47
|
+
}
|
|
48
|
+
return values.length ? values : undefined;
|
|
49
|
+
};
|
|
50
|
+
parsed.aid = consumeValue('--aid');
|
|
51
|
+
const tailRaw = consumeValue('--tail');
|
|
52
|
+
if (tailRaw !== undefined) {
|
|
53
|
+
const tail = Number(tailRaw);
|
|
54
|
+
if (!Number.isInteger(tail) || tail < 1 || tail > 10_000)
|
|
55
|
+
return { error: '--tail must be a positive integer' };
|
|
56
|
+
parsed.tail = tail;
|
|
57
|
+
}
|
|
58
|
+
const ttlRaw = consumeValue('--ttl');
|
|
59
|
+
if (ttlRaw !== undefined) {
|
|
60
|
+
const ttl = Number(ttlRaw);
|
|
61
|
+
if (!Number.isInteger(ttl) || ttl < 1 || ttl > 3600)
|
|
62
|
+
return { error: '--ttl must be an integer in [1, 3600]' };
|
|
63
|
+
parsed.ttl = ttl;
|
|
64
|
+
}
|
|
65
|
+
const dataRaw = consumeValue('--data');
|
|
66
|
+
if (dataRaw !== undefined) {
|
|
67
|
+
try {
|
|
68
|
+
parsed.data = JSON.parse(dataRaw);
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return { error: `--data is not valid JSON: ${dataRaw.slice(0, 80)}` };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const denyIndex = args.indexOf('--deny');
|
|
75
|
+
if (denyIndex >= 0) {
|
|
76
|
+
parsed.rule = 'deny';
|
|
77
|
+
args.splice(denyIndex, 1);
|
|
78
|
+
}
|
|
79
|
+
parsed.event = consumeValue('--event');
|
|
80
|
+
const publish = consumeList('--publish');
|
|
81
|
+
if (publish)
|
|
82
|
+
parsed.aids.publish = publish;
|
|
83
|
+
const subscribe = consumeList('--subscribe');
|
|
84
|
+
if (subscribe)
|
|
85
|
+
parsed.aids.subscribe = subscribe;
|
|
86
|
+
const positional = args.filter(item => !item.startsWith('-'));
|
|
87
|
+
if (command === 'status' || command === 'ledger' || command === 'tail' || command === 'doctor'
|
|
88
|
+
|| command === 'reload' || command === 'publish') {
|
|
89
|
+
parsed.pack = positional[0];
|
|
90
|
+
if (command === 'publish')
|
|
91
|
+
parsed.event = parsed.event ?? positional[1];
|
|
92
|
+
}
|
|
93
|
+
else if (command === 'allowlist') {
|
|
94
|
+
parsed.command = `allowlist:${positional[0] ?? ''}`;
|
|
95
|
+
parsed.event = parsed.event ?? positional[1];
|
|
96
|
+
}
|
|
97
|
+
return parsed;
|
|
98
|
+
}
|
|
99
|
+
function resolveAid(deps, parsed) {
|
|
100
|
+
if (parsed.aid)
|
|
101
|
+
return { aid: parsed.aid };
|
|
102
|
+
const units = [...deps.registry.values()];
|
|
103
|
+
if (units.length === 1)
|
|
104
|
+
return { aid: units[0].aid };
|
|
105
|
+
const fallback = deps.defaultAid?.();
|
|
106
|
+
if (fallback && units.some(unit => unit.aid === fallback))
|
|
107
|
+
return { aid: fallback };
|
|
108
|
+
if (units.length === 0) {
|
|
109
|
+
return { error: { ok: false, code: 'NO_AGENT', error: 'no event center units started; pass --aid <aid>' } };
|
|
110
|
+
}
|
|
111
|
+
return { error: { ok: false, code: 'AGENT_REQUIRED', error: `multiple agents: ${units.map(unit => unit.aid).join(', ')}; pass --aid <aid>` } };
|
|
112
|
+
}
|
|
113
|
+
export function createEventsOperationExecutor(deps) {
|
|
114
|
+
return async (request) => {
|
|
115
|
+
let parsed;
|
|
116
|
+
try {
|
|
117
|
+
parsed = parseEventsArgv(request.argv ?? []);
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
return { ok: false, code: 'INVALID_ARGV', error: errorMessage(error) };
|
|
121
|
+
}
|
|
122
|
+
if ('error' in parsed)
|
|
123
|
+
return { ok: false, code: 'INVALID_ARGV', error: parsed.error };
|
|
124
|
+
try {
|
|
125
|
+
return await execute(deps, parsed);
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
if (error instanceof EventCenterError) {
|
|
129
|
+
return { ok: false, code: error.code, error: error.message };
|
|
130
|
+
}
|
|
131
|
+
const message = errorMessage(error);
|
|
132
|
+
const code = /\b([A-Z][A-Z0-9_]{3,})\b/.exec(message)?.[1] ?? 'INTERNAL_ERROR';
|
|
133
|
+
logger.warn(`[EventCenter] events.op failed: ${code}: ${message}`);
|
|
134
|
+
return { ok: false, code, error: message };
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
async function execute(deps, parsed) {
|
|
139
|
+
const { command } = parsed;
|
|
140
|
+
if (command === 'help')
|
|
141
|
+
return { ok: true, result: { help: HELP } };
|
|
142
|
+
if (command === 'reload') {
|
|
143
|
+
const target = resolveAid(deps, parsed);
|
|
144
|
+
if (target.error)
|
|
145
|
+
return target.error;
|
|
146
|
+
await deps.registry.reload(target.aid);
|
|
147
|
+
const unit = deps.registry.get(target.aid);
|
|
148
|
+
return { ok: true, result: { aid: target.aid, packs: unit?.state.enabledPacks.map(pack => pack.id) ?? [] } };
|
|
149
|
+
}
|
|
150
|
+
const target = resolveAid(deps, parsed);
|
|
151
|
+
if (target.error)
|
|
152
|
+
return target.error;
|
|
153
|
+
const aid = target.aid;
|
|
154
|
+
const unit = deps.registry.get(aid);
|
|
155
|
+
if (!unit)
|
|
156
|
+
return { ok: false, code: 'AGENT_NOT_STARTED', error: `event center not started for ${aid}` };
|
|
157
|
+
switch (command) {
|
|
158
|
+
case 'status': {
|
|
159
|
+
if (parsed.pack) {
|
|
160
|
+
const pack = unit.state.enabledPacks.find(candidate => candidate.id === parsed.pack);
|
|
161
|
+
if (!pack)
|
|
162
|
+
return { ok: false, code: 'PACK_NOT_FOUND', error: `pack not found or invalid: ${parsed.pack}` };
|
|
163
|
+
return { ok: true, result: { aid, pack: packStatus(unit, pack.id) } };
|
|
164
|
+
}
|
|
165
|
+
const runtimeStatus = unit.runtime.status();
|
|
166
|
+
return {
|
|
167
|
+
ok: true,
|
|
168
|
+
result: {
|
|
169
|
+
aid,
|
|
170
|
+
bus: runtimeStatus.bus,
|
|
171
|
+
subscriptions: runtimeStatus.subscriptions,
|
|
172
|
+
publishers: runtimeStatus.publishers,
|
|
173
|
+
packs: [
|
|
174
|
+
...unit.state.enabledPacks.map(pack => packStatus(unit, pack.id)),
|
|
175
|
+
...unit.state.disabledPacks.map(id => ({ id, status: 'disabled' })),
|
|
176
|
+
...unit.state.invalidPacks.map(item => ({ id: item.id, status: 'invalid', errors: item.errors })),
|
|
177
|
+
],
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
case 'ledger': {
|
|
182
|
+
const pack = requirePack(unit, parsed.pack);
|
|
183
|
+
if ('ok' in pack)
|
|
184
|
+
return pack;
|
|
185
|
+
const lines = new Ledger(pack.paths.ledger).tail(parsed.tail ?? 20);
|
|
186
|
+
return { ok: true, result: { aid, pack: pack.id, lines } };
|
|
187
|
+
}
|
|
188
|
+
case 'tail': {
|
|
189
|
+
const pack = requirePack(unit, parsed.pack);
|
|
190
|
+
if ('ok' in pack)
|
|
191
|
+
return pack;
|
|
192
|
+
const lines = EventLog.forPack(pack).tail(parsed.tail ?? 20);
|
|
193
|
+
return { ok: true, result: { aid, pack: pack.id, lines } };
|
|
194
|
+
}
|
|
195
|
+
case 'doctor': {
|
|
196
|
+
const pack = requirePack(unit, parsed.pack);
|
|
197
|
+
if ('ok' in pack)
|
|
198
|
+
return pack;
|
|
199
|
+
const findings = await doctor(unit, pack.id);
|
|
200
|
+
return { ok: true, result: { aid, pack: pack.id, findings } };
|
|
201
|
+
}
|
|
202
|
+
case 'allowlist:show': {
|
|
203
|
+
const { config } = unit.centerStore.read();
|
|
204
|
+
const entries = parsed.event
|
|
205
|
+
? { [parsed.event]: config.allowlist[parsed.event] ?? { allow: { publish: [], subscribe: [] }, deny: { publish: [], subscribe: [] } } }
|
|
206
|
+
: config.allowlist;
|
|
207
|
+
return { ok: true, result: { aid, enabled: config.enabled, authMode: config.authMode, allowlist: entries } };
|
|
208
|
+
}
|
|
209
|
+
case 'allowlist:add':
|
|
210
|
+
case 'allowlist:remove': {
|
|
211
|
+
if (!parsed.event)
|
|
212
|
+
return { ok: false, code: 'INVALID_ARGV', error: 'allowlist add/remove requires <event>' };
|
|
213
|
+
if (!unit.state.catalog.some(entry => entry.event === parsed.event))
|
|
214
|
+
return { ok: false, code: 'EVENT_NOT_FOUND', error: `event is not registered: ${parsed.event}` };
|
|
215
|
+
if (!parsed.aids.publish && !parsed.aids.subscribe) {
|
|
216
|
+
return { ok: false, code: 'INVALID_ARGV', error: 'allowlist add/remove requires --publish <aid> and/or --subscribe <aid>' };
|
|
217
|
+
}
|
|
218
|
+
const action = command === 'allowlist:add' ? 'add' : 'remove';
|
|
219
|
+
const applied = {};
|
|
220
|
+
for (const role of ['publish', 'subscribe']) {
|
|
221
|
+
const aids = parsed.aids[role];
|
|
222
|
+
if (!aids)
|
|
223
|
+
continue;
|
|
224
|
+
const result = unit.centerStore.mutateAllowlist({ event: parsed.event, action, role, rule: parsed.rule, aids });
|
|
225
|
+
applied[role] = { added: result.added, removed: result.removed };
|
|
226
|
+
// 联动 Bus:白名单变更立即生效(updateConfig)。
|
|
227
|
+
const materialized = materializeAllowlist(result.config, unit.agentDir, unit.aid);
|
|
228
|
+
if (result.config.enabled && unit.state.catalog.length > 0 && !materialized.degraded) {
|
|
229
|
+
await unit.runtime.busHost.apply({
|
|
230
|
+
catalog: toSdkCatalog(unit.state.catalog),
|
|
231
|
+
allowlist: materialized.allowlist,
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return { ok: true, result: { aid, event: parsed.event, applied } };
|
|
236
|
+
}
|
|
237
|
+
case 'publish': {
|
|
238
|
+
if (!parsed.pack || !parsed.event)
|
|
239
|
+
return { ok: false, code: 'INVALID_ARGV', error: 'publish requires <pack> <event>' };
|
|
240
|
+
if (parsed.data === undefined)
|
|
241
|
+
return { ok: false, code: 'INVALID_ARGV', error: 'publish requires --data <json>' };
|
|
242
|
+
if (typeof parsed.data !== 'object' || parsed.data === null || Array.isArray(parsed.data)) {
|
|
243
|
+
return { ok: false, code: 'INVALID_ARGV', error: '--data must be a JSON object' };
|
|
244
|
+
}
|
|
245
|
+
const eventId = await unit.runtime.publish(parsed.pack, parsed.event, parsed.data, parsed.ttl);
|
|
246
|
+
return { ok: true, result: { aid, pack: parsed.pack, event: parsed.event, eventId } };
|
|
247
|
+
}
|
|
248
|
+
default:
|
|
249
|
+
return { ok: false, code: 'UNKNOWN_COMMAND', error: `unknown events command: ${command}\n${HELP}` };
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
function packStatus(unit, packId) {
|
|
253
|
+
const pack = unit.state.enabledPacks.find(candidate => candidate.id === packId);
|
|
254
|
+
if (!pack)
|
|
255
|
+
return { id: packId, status: 'invalid' };
|
|
256
|
+
const resolution = unit.runtime.resolutions.get(packId);
|
|
257
|
+
return {
|
|
258
|
+
id: pack.id,
|
|
259
|
+
name: pack.name,
|
|
260
|
+
status: 'active',
|
|
261
|
+
registers: pack.register.map(entry => entry.event),
|
|
262
|
+
publishes: pack.publish.map(entry => ({ bus: entry.bus, resolved: resolution?.get(entry.bus) ?? entry.busResolved, event: entry.event })),
|
|
263
|
+
subscribes: pack.subscribe.map(entry => ({ bus: entry.bus, resolved: resolution?.get(entry.bus) ?? entry.busResolved, event: entry.event })),
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
function requirePack(unit, packId) {
|
|
267
|
+
if (!packId)
|
|
268
|
+
return { ok: false, code: 'INVALID_ARGV', error: 'command requires <pack>' };
|
|
269
|
+
const pack = unit.state.enabledPacks.find(candidate => candidate.id === packId);
|
|
270
|
+
if (!pack)
|
|
271
|
+
return { ok: false, code: 'PACK_NOT_FOUND', error: `pack not found or invalid: ${packId}` };
|
|
272
|
+
return pack;
|
|
273
|
+
}
|
|
274
|
+
/** 诊断:重新加载包目录 + 检查脚本/解析/白名单。 */
|
|
275
|
+
async function doctor(unit, packId) {
|
|
276
|
+
const findings = [];
|
|
277
|
+
const pack = unit.state.enabledPacks.find(candidate => candidate.id === packId);
|
|
278
|
+
if (!pack) {
|
|
279
|
+
const invalid = unit.state.invalidPacks.find(item => item.id === packId);
|
|
280
|
+
return invalid
|
|
281
|
+
? [{ level: 'error', check: 'pack.json', detail: invalid.errors.join('; ') }]
|
|
282
|
+
: [{ level: 'error', check: 'pack', detail: 'pack not found' }];
|
|
283
|
+
}
|
|
284
|
+
findings.push({ level: 'ok', check: 'pack.json', detail: 'valid' });
|
|
285
|
+
// 重新加载做文件系统复查(脚本存在性 / realpath 越界)。
|
|
286
|
+
const errors = [];
|
|
287
|
+
loadPackDir(pack.dir, errors);
|
|
288
|
+
findings.push(errors.length
|
|
289
|
+
? { level: 'error', check: 'scripts', detail: errors.join('; ') }
|
|
290
|
+
: { level: 'ok', check: 'scripts', detail: 'all scripts present' });
|
|
291
|
+
const resolution = unit.runtime.resolutions.get(packId);
|
|
292
|
+
const unresolved = [...pack.subscribe, ...pack.publish]
|
|
293
|
+
.filter(entry => !(resolution?.get(entry.bus) ?? entry.busResolved))
|
|
294
|
+
.map(entry => entry.bus);
|
|
295
|
+
findings.push(unresolved.length
|
|
296
|
+
? { level: 'error', check: 'bus-resolve', detail: `unresolved: ${unresolved.join(', ')}` }
|
|
297
|
+
: { level: 'ok', check: 'bus-resolve', detail: 'all buses resolved' });
|
|
298
|
+
const { config } = unit.centerStore.read();
|
|
299
|
+
if (pack.register.length > 0 && !config.enabled) {
|
|
300
|
+
findings.push({ level: 'warn', check: 'center', detail: 'register entries exist but center.json enabled=false; bus not started' });
|
|
301
|
+
}
|
|
302
|
+
for (const entry of pack.register) {
|
|
303
|
+
if (!config.allowlist[entry.event]) {
|
|
304
|
+
findings.push({ level: 'warn', check: 'allowlist', detail: `no allowlist entry for ${entry.event}; nobody may publish/subscribe` });
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return findings;
|
|
308
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 台账(ledger.jsonl / .center-ledger.jsonl):append-only,只记生命周期,不记事件正文。
|
|
3
|
+
* 行结构按 docs/event-center/schema/ledger.schema.json(additionalProperties: false)。
|
|
4
|
+
*/
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
export class Ledger {
|
|
8
|
+
filePath;
|
|
9
|
+
constructor(filePath) {
|
|
10
|
+
this.filePath = filePath;
|
|
11
|
+
}
|
|
12
|
+
/** 追加一行;IO 失败吞掉(台账不应中断运行时)。 */
|
|
13
|
+
append(line) {
|
|
14
|
+
const { ts, action, ...rest } = line;
|
|
15
|
+
const full = { ts: ts ?? Date.now(), action, ...rest };
|
|
16
|
+
try {
|
|
17
|
+
fs.mkdirSync(path.dirname(this.filePath), { recursive: true });
|
|
18
|
+
fs.appendFileSync(this.filePath, `${JSON.stringify(full)}\n`, 'utf8');
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
// 台账写失败不致命:运行继续,`ec events ledger` 读不到时再排查磁盘。
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** 读最后 N 行(CLI tail 用)。 */
|
|
25
|
+
tail(count) {
|
|
26
|
+
let text;
|
|
27
|
+
try {
|
|
28
|
+
text = fs.readFileSync(this.filePath, 'utf8');
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
const lines = text.split('\n').filter(Boolean).slice(-count);
|
|
34
|
+
const out = [];
|
|
35
|
+
for (const line of lines) {
|
|
36
|
+
try {
|
|
37
|
+
out.push(JSON.parse(line));
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// 跳过坏行
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export function packLedger(pack) {
|
|
47
|
+
return new Ledger(pack.paths.ledger);
|
|
48
|
+
}
|
|
49
|
+
/** center 级动作(bus.start / bus.stop / allowlist.update)的台账,放 events/ 根。 */
|
|
50
|
+
export function centerLedger(eventsDir) {
|
|
51
|
+
return new Ledger(path.join(eventsDir, '.center-ledger.jsonl'));
|
|
52
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 事件包目录扫描与加载:events/<pack>/pack.json (+中文别名) 与 events/center.json。
|
|
3
|
+
* 规范名优先、别名 fallback、两者并存判校验失败(design.md §14.3)。
|
|
4
|
+
* 脚本路径做 realpath 全级校验,防符号链接逃逸出包目录。
|
|
5
|
+
*/
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { sha256 } from '../trigger/validation.js';
|
|
9
|
+
import { validateCenterConfig, validatePackJson } from './validation.js';
|
|
10
|
+
export const PACK_JSON = 'pack.json';
|
|
11
|
+
export const PACK_JSON_ALIASES = ['关注的事件.json', '会议关注的事件.json'];
|
|
12
|
+
export const LEDGER_FILE = 'ledger.jsonl';
|
|
13
|
+
export const LEDGER_FILE_ALIASES = ['已注册的标记文件.jsonl'];
|
|
14
|
+
export const SCRIPTS_DIR = 'scripts';
|
|
15
|
+
export const SCRIPTS_DIR_ALIAS = '事件处理脚本';
|
|
16
|
+
export const LOGS_DIR = 'logs';
|
|
17
|
+
export const LOGS_DIR_ALIAS = '日志';
|
|
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
|
+
}
|
|
36
|
+
/** realpath 全级校验:目标真实路径必须仍在包目录内(防中间目录符号链接逃逸)。 */
|
|
37
|
+
function assertInsidePackDir(packDir, target, errors, field) {
|
|
38
|
+
let realTarget;
|
|
39
|
+
try {
|
|
40
|
+
realTarget = fs.realpathSync(target);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
errors.push(`${field} not found: ${path.relative(packDir, target)}`);
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
const realPackDir = fs.realpathSync(packDir);
|
|
47
|
+
if (realTarget !== realPackDir && !realTarget.startsWith(realPackDir + path.sep)) {
|
|
48
|
+
errors.push(`${field} escapes pack directory via symlink`);
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
/** 加载单个包目录。返回 null 表示该包 invalid(errors 已填)。 */
|
|
54
|
+
export function loadPackDir(packDir, errors) {
|
|
55
|
+
const packId = path.basename(packDir);
|
|
56
|
+
const packJsonPath = resolveCanonicalPath(packDir, PACK_JSON, PACK_JSON_ALIASES, errors);
|
|
57
|
+
if (!packJsonPath)
|
|
58
|
+
return null;
|
|
59
|
+
let rawText;
|
|
60
|
+
try {
|
|
61
|
+
rawText = fs.readFileSync(packJsonPath, 'utf8');
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
errors.push(`cannot read ${path.basename(packJsonPath)}: ${error instanceof Error ? error.message : String(error)}`);
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
let raw;
|
|
68
|
+
try {
|
|
69
|
+
raw = JSON.parse(rawText);
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
errors.push(`${path.basename(packJsonPath)} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
const validated = validatePackJson(raw);
|
|
76
|
+
if (!validated.ok) {
|
|
77
|
+
errors.push(...validated.errors);
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
// 脚本目录:规范名/别名二选一;都没有时若包声明了 subscribe 里的脚本则报缺失。
|
|
81
|
+
let scriptsDir;
|
|
82
|
+
const canonicalScripts = path.join(packDir, SCRIPTS_DIR);
|
|
83
|
+
const aliasScripts = path.join(packDir, SCRIPTS_DIR_ALIAS);
|
|
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)
|
|
91
|
+
scriptsDir = canonicalScripts;
|
|
92
|
+
else if (hasAlias)
|
|
93
|
+
scriptsDir = aliasScripts;
|
|
94
|
+
else if (validated.value.subscribe.length > 0) {
|
|
95
|
+
errors.push(`scripts directory not found: expected ${SCRIPTS_DIR}/ (or ${SCRIPTS_DIR_ALIAS}/)`);
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
// 脚本存在性 + realpath 越界校验(realpath 覆盖全路径各级目录的符号链接)。
|
|
99
|
+
for (const entry of validated.value.subscribe) {
|
|
100
|
+
const relativeUnderScripts = entry.handler.script.slice(SCRIPTS_DIR.length + 1);
|
|
101
|
+
const scriptPath = path.join(scriptsDir ?? canonicalScripts, relativeUnderScripts);
|
|
102
|
+
if (!assertInsidePackDir(packDir, scriptPath, errors, `handler.script "${entry.handler.script}"`))
|
|
103
|
+
continue;
|
|
104
|
+
const stat = fs.lstatSync(fs.realpathSync(scriptPath));
|
|
105
|
+
if (!stat.isFile()) {
|
|
106
|
+
errors.push(`handler.script "${entry.handler.script}" is not a regular file`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const ledgerPath = resolveCanonicalPath(packDir, LEDGER_FILE, LEDGER_FILE_ALIASES, errors) ?? path.join(packDir, LEDGER_FILE);
|
|
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
|
+
})();
|
|
121
|
+
if (!fs.existsSync(logsDir)) {
|
|
122
|
+
try {
|
|
123
|
+
fs.mkdirSync(logsDir, { recursive: true });
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
errors.push(`cannot create logs directory: ${logsDir}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (errors.length)
|
|
130
|
+
return null;
|
|
131
|
+
const paths = {
|
|
132
|
+
packJson: packJsonPath,
|
|
133
|
+
scriptsDir: scriptsDir ?? canonicalScripts,
|
|
134
|
+
ledger: ledgerPath,
|
|
135
|
+
logsDir,
|
|
136
|
+
};
|
|
137
|
+
return {
|
|
138
|
+
id: packId,
|
|
139
|
+
dir: packDir,
|
|
140
|
+
name: validated.value.name,
|
|
141
|
+
enabled: validated.value.enabled,
|
|
142
|
+
busResolve: validated.value.busResolve,
|
|
143
|
+
register: validated.value.register,
|
|
144
|
+
publish: validated.value.publish,
|
|
145
|
+
subscribe: validated.value.subscribe,
|
|
146
|
+
revision: sha256(rawText),
|
|
147
|
+
paths,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
/** 扫描 events/ 下全部包目录。单包失败只废该包。 */
|
|
151
|
+
export function loadPacks(eventsDir) {
|
|
152
|
+
const valid = [];
|
|
153
|
+
const invalid = [];
|
|
154
|
+
let entries;
|
|
155
|
+
try {
|
|
156
|
+
entries = fs.readdirSync(eventsDir, { withFileTypes: true });
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
return { valid: [], invalid: [] };
|
|
160
|
+
}
|
|
161
|
+
for (const entry of entries) {
|
|
162
|
+
if (!entry.isDirectory())
|
|
163
|
+
continue;
|
|
164
|
+
if (entry.name.startsWith('.') || entry.name.startsWith('_'))
|
|
165
|
+
continue;
|
|
166
|
+
const packDir = path.join(eventsDir, entry.name);
|
|
167
|
+
const errors = [];
|
|
168
|
+
const pack = loadPackDir(packDir, errors);
|
|
169
|
+
if (pack)
|
|
170
|
+
valid.push(pack);
|
|
171
|
+
else
|
|
172
|
+
invalid.push({ dir: packDir, packId: entry.name, errors });
|
|
173
|
+
}
|
|
174
|
+
return { valid, invalid };
|
|
175
|
+
}
|
|
176
|
+
/** 读取 events/center.json;不存在返回缺省(enabled=false)。 */
|
|
177
|
+
export function loadCenterConfig(eventsDir) {
|
|
178
|
+
const filePath = path.join(eventsDir, CENTER_JSON);
|
|
179
|
+
let rawText;
|
|
180
|
+
try {
|
|
181
|
+
rawText = fs.readFileSync(filePath, 'utf8');
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
return { config: { enabled: false, authMode: 'allowlist', admission: { coupling: 'on', rematerializeMs: 300_000 }, allowlist: {} }, exists: false, errors: [] };
|
|
185
|
+
}
|
|
186
|
+
let raw;
|
|
187
|
+
try {
|
|
188
|
+
raw = JSON.parse(rawText);
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
return {
|
|
192
|
+
config: { enabled: false, authMode: 'allowlist', admission: { coupling: 'on', rematerializeMs: 300_000 }, allowlist: {} },
|
|
193
|
+
exists: true,
|
|
194
|
+
errors: [`${CENTER_JSON} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`],
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
const validated = validateCenterConfig(raw);
|
|
198
|
+
if (!validated.ok) {
|
|
199
|
+
return { config: { enabled: false, authMode: 'allowlist', admission: { coupling: 'on', rematerializeMs: 300_000 }, allowlist: {} }, exists: true, errors: validated.errors };
|
|
200
|
+
}
|
|
201
|
+
return { config: validated.value, exists: true, errors: [] };
|
|
202
|
+
}
|