evolcore 0.0.45 → 0.0.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +113 -0
- package/bin/ecmsg.js +33 -23
- package/dist/ability/application-service.js +1 -2
- package/dist/ability/package.js +28 -0
- package/dist/agent-template/jobs.js +158 -36
- package/dist/agent-template/runtime.js +401 -34
- package/dist/agent-template/service.js +764 -369
- package/dist/agent-template/tool-runner.js +35 -17
- package/dist/agent-template/types.js +7 -4
- package/dist/agents/baseagent.js +10 -9
- package/dist/agents/claude-runner.js +22 -6
- package/dist/agents/codex/app-server-client.js +34 -27
- package/dist/agents/codex/diagnostics.js +18 -1
- package/dist/agents/codex-runner.js +3 -1
- package/dist/agents/ecagent-runner.js +3 -1
- package/dist/agents/gemini-runner.js +2 -1
- package/dist/aun/group/fs-download.js +1 -1
- package/dist/aun/menu/client.js +142 -182
- package/dist/aun/rpc/client.js +33 -17
- package/dist/aun/service-proxy.js +6 -23
- package/dist/channels/aun.js +675 -120
- package/dist/channels/daemon.js +1 -1
- package/dist/cli/agent-create.js +37 -10
- package/dist/cli/agent-template.js +105 -84
- package/dist/cli/agent.js +31 -18
- package/dist/cli/daemon-commands.js +42 -56
- package/dist/cli/daemon-lifecycle-client.js +55 -19
- package/dist/cli/directory.js +12 -4
- package/dist/cli/ecmsg-gateway.js +5 -2
- package/dist/cli/events-command.js +2 -1
- package/dist/cli/init-channel.js +2 -2
- package/dist/cli/init.js +57 -21
- package/dist/cli/integrity-command.js +2 -0
- package/dist/cli/managed-command-guard.js +20 -1
- package/dist/cli/menu-client.js +7 -5
- package/dist/cli/restart-monitor.js +135 -46
- package/dist/cli/services-command.js +28 -5
- package/dist/cli/task-context.js +83 -15
- package/dist/cli/upgrade-command.js +4 -2
- package/dist/config/config-field-policy.js +24 -0
- package/dist/config/config-manager.js +49 -19
- package/dist/config/peer-book-store.js +167 -127
- package/dist/config/peer-role-resolver.js +24 -4
- package/dist/config/provider-identity-migration.js +158 -6
- package/dist/config/provider-identity.js +10 -4
- package/dist/config/provider-ipc-service.js +10 -2
- package/dist/config/provider-local-sync.js +2 -2
- package/dist/config/providers-config.js +95 -10
- package/dist/config/providers-import.js +4 -6
- package/dist/config/providers.js +14 -3
- package/dist/config/role-store.js +1 -1
- package/dist/config/schema-migration.js +123 -16
- package/dist/config/schema-registry.js +6 -2
- package/dist/config-store.js +9 -1
- package/dist/core/agent-application-service.js +56 -29
- package/dist/core/agent-create-status.js +3 -1
- package/dist/core/agent-creation-claim.js +1 -0
- package/dist/core/agent-ipc-registration.js +2 -2
- package/dist/core/agent-reload-coordinator.js +38 -1
- package/dist/core/agent-runtime.js +91 -43
- package/dist/core/auth/agent-delegation.js +13 -3
- package/dist/core/auth/delegation-diagnostics.js +56 -15
- package/dist/core/auth/operation-authorizer.js +2 -2
- package/dist/core/auth/operation-catalog.js +3 -3
- package/dist/core/bootstrap-service.js +3 -0
- package/dist/core/capability/capability-manager.js +3 -1
- package/dist/core/channel-loader.js +29 -3
- package/dist/core/channel-runtime.js +1 -1
- package/dist/core/command/agent-control.js +6 -5
- package/dist/core/command/agent-template-menu.js +32 -97
- package/dist/core/command/eventcenter-menu.js +61 -13
- package/dist/core/command/menu-catalog.js +11 -4
- package/dist/core/command/menu-handler.js +39 -12
- package/dist/core/command/menu-protocol.js +8 -16
- package/dist/core/command/skill-slash.js +6 -2
- package/dist/core/command/slash-handler.js +4 -6
- package/dist/core/command/team-workspace-bootstrap.js +1 -2
- package/dist/core/command/team-workspace-management-store.js +83 -0
- package/dist/core/command/team-workspace-management.js +1 -2
- package/dist/core/command/team-workspace-team.js +26 -3
- package/dist/core/daemon-bootstrap.js +11 -9
- package/dist/core/daemon-control.js +4 -7
- package/dist/core/daemon-lifecycle.js +189 -143
- package/dist/core/evolagent-registry.js +50 -2
- package/dist/core/evolagent.js +2 -1
- package/dist/core/file-integrity/read.js +9 -16
- package/dist/core/file-integrity/store.js +94 -34
- package/dist/core/handoff/dispatcher.js +33 -7
- package/dist/core/handoff/runtime.js +8 -0
- package/dist/core/host-snapshot.js +9 -4
- package/dist/core/inference/text-inference.js +12 -2
- package/dist/core/initialization/service.js +22 -4
- package/dist/core/invoke/invoke-service.js +24 -3
- package/dist/core/ipc-registration.js +7 -3
- package/dist/core/memory/consolidation.js +6 -6
- package/dist/core/message/aun-ipc-sender.js +109 -7
- package/dist/core/message/contact-admission.js +6 -2
- package/dist/core/message/message-bridge.js +13 -0
- package/dist/core/message/message-queue.js +131 -30
- package/dist/core/message/pending-hints.js +8 -0
- package/dist/core/message/response-engine.js +48 -2
- package/dist/core/message/send-routing.js +3 -12
- package/dist/core/model/catalog-service.js +13 -0
- package/dist/core/model/model-catalog.js +57 -18
- package/dist/core/ownership/owner-resolver.js +27 -10
- package/dist/core/pack-auth.js +163 -31
- package/dist/core/pack-install.js +42 -1
- package/dist/{services/ledger.js → core/pack-ledger.js} +17 -6
- package/dist/core/permission/ec-command-parser.js +3 -1
- package/dist/core/permission/shell-environment.js +23 -0
- package/dist/core/rate-window.js +6 -1
- package/dist/core/relation/peer-identity.js +5 -1
- package/dist/core/relation/same-owner-proof.js +2 -1
- package/dist/core/session/adapters/claude-session-file-adapter.js +1 -1
- package/dist/core/session/session-file-health.js +36 -7
- package/dist/core/session/session-idle-monitor.js +0 -1
- package/dist/core/session/session-manager.js +14 -0
- package/dist/core/session/session-title.js +26 -6
- package/dist/core/skill/index-generator.js +3 -4
- package/dist/core/task/task-image-resources.js +1 -1
- package/dist/core/thread/thread-service.js +0 -1
- package/dist/core/thread/topic-id.js +8 -0
- package/dist/directory/owner-directory-admission.js +17 -0
- package/dist/directory/owner-directory-cache.js +3 -1
- package/dist/directory/owner-directory-markdown.js +145 -23
- package/dist/directory/owner-directory-policy.js +23 -0
- package/dist/directory/owner-directory-query-operation.js +20 -6
- package/dist/directory/owner-directory-search.js +47 -0
- package/dist/eck/message-renderer.js +171 -32
- package/dist/ecweb/basic-settings-service.js +7 -3
- package/dist/ecweb/providers-service.js +17 -10
- package/dist/ecweb/runtime/lifecycle.js +65 -16
- package/dist/ecweb/runtime/supervisor.js +79 -50
- package/dist/event-center/admission-materializer.js +1 -1
- package/dist/event-center/bus-gate.js +48 -4
- package/dist/event-center/bus-host.js +3 -3
- package/dist/event-center/center-config.js +57 -28
- package/dist/event-center/dispatcher.js +8 -0
- package/dist/event-center/event-log.js +69 -27
- package/dist/event-center/index-generator.js +6 -1
- package/dist/event-center/ipc-operation.js +66 -25
- package/dist/event-center/pack-loader.js +12 -55
- package/dist/event-center/pack-manager.js +5 -3
- package/dist/event-center/registry.js +48 -52
- package/dist/event-center/runtime.js +219 -81
- package/dist/event-center/script-runner.js +18 -7
- package/dist/event-center/types.js +9 -1
- package/dist/event-center/validation.js +33 -4
- package/dist/index.js +132 -75
- package/dist/ipc.js +35 -8
- package/dist/product.js +1 -0
- package/dist/proxy/manager.js +52 -11
- package/dist/proxy/service-supervisor.js +265 -67
- package/dist/services/dispatcher.js +26 -3
- package/dist/services/idempotency.js +128 -0
- package/dist/services/identity.js +3 -27
- package/dist/services/index-generator.js +5 -1
- package/dist/services/index.js +244 -45
- package/dist/services/ipc-operation.js +164 -20
- package/dist/services/pack-manager.js +37 -9
- package/dist/services/router.js +100 -31
- package/dist/services/script-runner.js +15 -4
- package/dist/services/service-payload.js +50 -2
- package/dist/services/validation.js +107 -3
- package/dist/trigger/scheduler.js +18 -4
- package/dist/trigger/script-sandbox.js +39 -2
- package/dist/trigger/state.js +7 -0
- package/dist/utils/aid-bind.js +155 -18
- package/dist/utils/atomic-write.js +3 -3
- package/dist/utils/cross-platform.js +59 -16
- package/dist/utils/error-utils.js +26 -1
- package/dist/utils/instance-registry.js +94 -35
- package/dist/utils/process-introspect.js +187 -27
- package/dist/utils/project-path.js +47 -3
- package/dist/utils/upgrade-jobs.js +4 -4
- package/dist/utils/windows-shell-trust.js +174 -68
- package/kits/docs/context-assembly.md +3 -3
- package/kits/docs/evolcore/agent.md +28 -10
- package/kits/docs/evolcore/aid.md +3 -1
- package/kits/docs/evolcore/config.md +22 -0
- package/kits/docs/evolcore/directory.md +46 -12
- package/kits/docs/evolcore/event-center.md +6 -6
- package/kits/docs/evolcore/group-collaboration.md +1 -1
- package/kits/docs/evolcore/menu-client.md +7 -5
- package/kits/docs/evolcore/menu-protocol.md +5 -3
- package/kits/docs/evolcore/msg.md +10 -3
- package/kits/docs/evolcore/provider.md +17 -5
- package/kits/docs/evolcore/services.md +145 -12
- package/kits/docs/evolcore/thread-chain.md +17 -9
- package/kits/docs/prompt-loading-architecture.md +4 -4
- package/kits/eck_message_manifest.json +46 -3
- package/kits/rules/04-relation.md +10 -2
- package/kits/rules/06-channel.md +2 -1
- package/kits/schemas/providers.schema.2.json +1 -0
- package/kits/skills/ec-group/SKILL.md +4 -0
- package/kits/skills/ec-skill/scripts/cli.mjs +1 -1
- package/kits/skills/ec-skill/scripts/skill.mjs +13 -2
- package/kits/skills/thread-ops/SKILL.md +8 -5
- package/kits/templates/message-fragments/group-batch-item.md +3 -0
- package/kits/templates/message-fragments/group-batch.md +1 -0
- package/kits/templates/message-fragments/item-group.md +4 -0
- package/kits/templates/message-fragments/item-private.md +4 -0
- package/kits/templates/message-fragments/thread-context.md +1 -1
- package/kits/templates/system-fragments/commands.md +5 -5
- package/kits/templates/system-fragments/managed-runtime.md +1 -1
- package/kits/templates/system-fragments/relation.md +11 -7
- package/package.json +3 -2
- package/scripts/agent-template/index.mjs +9 -4
- package/scripts/agent-template/inspect.mjs +16 -9
- package/scripts/agent-template/shared/plan.mjs +3 -33
- package/scripts/agent-template/shared/template-contract.mjs +186 -3
- package/scripts/agent-template/shared/template-package.mjs +119 -10
- package/scripts/agent-template/shared/template-runtime.mjs +49 -6
- package/scripts/agent-template/shared/template.mjs +5 -5
- package/scripts/agent-template/team-pack.mjs +245 -0
- package/scripts/agent-template/team-preview.mjs +111 -0
- package/scripts/aid-batch/identity-batch.mjs +143 -0
- package/dist/ability/versions.js +0 -32
- package/dist/aun/model-headers.js +0 -17
- package/dist/channels/builtin-plugins.js +0 -19
- package/dist/core/command/team-workspace-initializer.js +0 -2
- package/dist/core/command/team-workspace-job-store.js +0 -88
- package/dist/core/command/team-workspace-management-service.js +0 -2
- package/dist/core/contact-bind-registry.js +0 -27
- package/dist/event-center/ledger.js +0 -52
- package/dist/services/reply.js +0 -55
- package/kits/templates/message-fragments/item.md +0 -3
- package/scripts/agent-template/pack.mjs +0 -169
|
@@ -2,25 +2,27 @@
|
|
|
2
2
|
* `ec services` 的 daemon 侧 IPC 操作(services.op)。
|
|
3
3
|
* daemon-control 风格(不走 delegation argv 哈希);CLI 透传 argv,daemon 解析执行。
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* 本机运维:status / list / types / ledger / tail / doctor / reload / enable / disable /
|
|
6
|
+
* pack add|remove|list;对端调用(describe / schema / call)也在这里(`runCall`),
|
|
7
|
+
* 请求登记进 AunRequestRegistry,应答由 AUN 入站的 `services.*.result` 分支落盘——
|
|
8
|
+
* CLI 只等记录终态,中途被杀也不丢结果。
|
|
7
9
|
*/
|
|
8
10
|
import fs from 'node:fs';
|
|
9
11
|
import path from 'node:path';
|
|
10
12
|
import { logger } from '../utils/logger.js';
|
|
11
13
|
import { agentServicesDir, resolveRoot } from '../paths.js';
|
|
12
14
|
import { classifyProtectedPath } from '../core/permission/protected-paths.js';
|
|
13
|
-
import { ServiceLedger } from '
|
|
15
|
+
import { ServiceLedger } from '../core/pack-ledger.js';
|
|
14
16
|
import { ServiceMessageLog } from './message-log.js';
|
|
15
|
-
import { SERVICES_CONFIG_JSON, loadRouterConfig } from './router.js';
|
|
17
|
+
import { SERVICES_CONFIG_JSON, loadRouterConfig, ServiceRulesStore } from './router.js';
|
|
16
18
|
import { PACK_JSON } from './pack-manager.js';
|
|
17
19
|
import { readLocalSelfIdentity } from './identity.js';
|
|
18
20
|
import { createOfflineServiceRouter, listServiceRouterAids, peekServiceRouter, } from './index.js';
|
|
19
21
|
import { isReservedServiceType, RESERVED_TYPES } from './service-payload.js';
|
|
20
22
|
import { getAunRequestRegistry } from '../core/message/aun-request-registry.js';
|
|
21
23
|
import { ServiceError, errorMessage } from './types.js';
|
|
22
|
-
import { authorizePackTarget,
|
|
23
|
-
import { installPack, listPackDirs, removePack } from '../core/pack-install.js';
|
|
24
|
+
import { authorizePackTarget, packOperation } from '../core/pack-auth.js';
|
|
25
|
+
import { installPack, listPackDirs, removePack, setPackEnabled } from '../core/pack-install.js';
|
|
24
26
|
const HELP = `ec services — 服务路由运维
|
|
25
27
|
|
|
26
28
|
用法:
|
|
@@ -29,12 +31,16 @@ const HELP = `ec services — 服务路由运维
|
|
|
29
31
|
ec services ledger <包名> [--tail N] [--aid <aid>] 台账
|
|
30
32
|
ec services tail <包名> [--tail N] [--aid <aid>] 服务消息日志
|
|
31
33
|
ec services doctor [<包名>] [--aid <aid>] 诊断
|
|
32
|
-
ec services reload [
|
|
34
|
+
ec services reload [--aid <aid>] 重载(全部包)
|
|
33
35
|
ec services enable / disable [--aid <aid>] 总闸
|
|
36
|
+
ec services rules show [<type>] [--aid <aid>] 调用准入规则
|
|
37
|
+
ec services rules add <type> <aid...> [--deny] [--aid <aid>]
|
|
38
|
+
ec services rules remove <type> <aid...> [--deny] [--aid <aid>]
|
|
34
39
|
|
|
35
40
|
安装与卸载(L 类目录只能由 daemon 代写):
|
|
36
41
|
ec services pack add <包名> --from <源目录> [--aid <aid>]
|
|
37
42
|
ec services pack remove <包名> [--aid <aid>] [--purge]
|
|
43
|
+
ec services pack enable / disable <包名> [--aid <aid>]
|
|
38
44
|
|
|
39
45
|
add 遇到已安装的包直接报错,先 remove 再装。
|
|
40
46
|
remove 默认把日志与台账归档到 <包>/logs/archive-<时间戳>/;--purge 连归档一起删。
|
|
@@ -61,6 +67,18 @@ export function parseServicesArgv(argv) {
|
|
|
61
67
|
return value;
|
|
62
68
|
};
|
|
63
69
|
parsed.aid = consumeValue('--aid');
|
|
70
|
+
// `--format` 只影响 CLI 的打印方式,daemon 不需要它的值。但不消费掉就会落到
|
|
71
|
+
// 位置参数里被当成包名:`status --format json` 会去查一个叫 `json` 的包并报
|
|
72
|
+
// PACK_NOT_FOUND。仍要校验取值,拼错时给明确报错而不是静默按默认打印。
|
|
73
|
+
// `--wait` 是缺省行为(CLI 一直等到达终态),显式写出来只是为了可读性。
|
|
74
|
+
// 必须消费掉:不认它就会落进位置参数,被当成目标 AID 或 selfAid。
|
|
75
|
+
const waitIndex = args.indexOf('--wait');
|
|
76
|
+
if (waitIndex >= 0)
|
|
77
|
+
args.splice(waitIndex, 1);
|
|
78
|
+
const formatRaw = consumeValue('--format');
|
|
79
|
+
if (formatRaw !== undefined && formatRaw !== 'json' && formatRaw !== 'text') {
|
|
80
|
+
return { error: `--format must be "json" or "text": ${formatRaw}` };
|
|
81
|
+
}
|
|
64
82
|
const tailRaw = consumeValue('--tail');
|
|
65
83
|
if (tailRaw !== undefined) {
|
|
66
84
|
const tail = Number(tailRaw);
|
|
@@ -108,6 +126,10 @@ export function parseServicesArgv(argv) {
|
|
|
108
126
|
parsed.purge = true;
|
|
109
127
|
args.splice(args.indexOf('--purge'), 1);
|
|
110
128
|
}
|
|
129
|
+
if (args.includes('--deny')) {
|
|
130
|
+
parsed.rule = 'deny';
|
|
131
|
+
args.splice(args.indexOf('--deny'), 1);
|
|
132
|
+
}
|
|
111
133
|
if (args.includes('--force')) {
|
|
112
134
|
// 覆盖安装已取消:重装前必须先 `pack remove`。识别出来是为了给明确提示。
|
|
113
135
|
return { error: '--force is no longer supported; run "pack remove <包名>" before reinstalling' };
|
|
@@ -117,6 +139,12 @@ export function parseServicesArgv(argv) {
|
|
|
117
139
|
parsed.action = positional[0];
|
|
118
140
|
parsed.pack = positional[1];
|
|
119
141
|
}
|
|
142
|
+
else if (command === 'rules') {
|
|
143
|
+
// `rules show` / `rules add <type> <aid...>` / `rules remove <type> <aid...>`
|
|
144
|
+
parsed.command = `rules:${positional[0] ?? ''}`;
|
|
145
|
+
parsed.type = positional[1];
|
|
146
|
+
parsed.aids = positional.slice(2);
|
|
147
|
+
}
|
|
120
148
|
else {
|
|
121
149
|
parsed.pack = positional[0];
|
|
122
150
|
}
|
|
@@ -126,6 +154,11 @@ export function parseServicesArgv(argv) {
|
|
|
126
154
|
return parsed;
|
|
127
155
|
}
|
|
128
156
|
/** `--timeout 30` / `30s` / `2m` / `500ms` → 毫秒。 */
|
|
157
|
+
/** 只用于比较两个 AID 是否同一主体:去 `@` 前缀并忽略大小写。 */
|
|
158
|
+
function normalizeAid(value) {
|
|
159
|
+
const aid = String(value ?? '').trim();
|
|
160
|
+
return (aid.startsWith('@') ? aid.slice(1) : aid).toLowerCase();
|
|
161
|
+
}
|
|
129
162
|
function parseTimeoutMs(value) {
|
|
130
163
|
const trimmed = value.trim().toLowerCase();
|
|
131
164
|
const plain = Number(trimmed);
|
|
@@ -192,7 +225,13 @@ export function createServicesOperationExecutor(deps) {
|
|
|
192
225
|
if (error instanceof ServiceError)
|
|
193
226
|
return { ok: false, code: error.code, error: error.message };
|
|
194
227
|
const message = errorMessage(error);
|
|
195
|
-
|
|
228
|
+
// 先认 `error.code`(pack-install 等底层用 `Object.assign(err, { code })` 挂的
|
|
229
|
+
// 结构化错误码)。从消息文本里正则捞 `[A-Z_]{4,}` 只能兜底——文本里没有大写词汇
|
|
230
|
+
// (例如 "pack already installed")时会退化成 INTERNAL_ERROR,把可判定的冲突
|
|
231
|
+
// 说成内部故障。
|
|
232
|
+
const code = typeof error?.code === 'string'
|
|
233
|
+
? error.code
|
|
234
|
+
: /\b([A-Z][A-Z0-9_]{3,})\b/.exec(message)?.[1] ?? 'INTERNAL_ERROR';
|
|
196
235
|
logger.warn(`[Services] services.op failed: ${code}: ${message}`);
|
|
197
236
|
return { ok: false, code, error: message };
|
|
198
237
|
}
|
|
@@ -207,13 +246,14 @@ async function execute(deps, parsed) {
|
|
|
207
246
|
return target.error;
|
|
208
247
|
const aid = target.aid;
|
|
209
248
|
const router = target.router;
|
|
210
|
-
//
|
|
211
|
-
//
|
|
249
|
+
// 授权:四档操作 × 两类目标(见 core/pack-auth.ts)。
|
|
250
|
+
// 自己 AID:view 需 member+、manage 需 owner/admin、switch 需 daemonOwner+fullaccess;
|
|
251
|
+
// 其他 AID:view 需同 Owner,manage/switch 需 daemonOwner+fullaccess+同 Owner。
|
|
212
252
|
const auth = authorizePackTarget({
|
|
213
253
|
caller: parsed.caller ?? { kind: 'local-control' },
|
|
214
254
|
targetAid: aid,
|
|
215
255
|
...(deps.daemonAid?.() ? { daemonAid: deps.daemonAid() } : {}),
|
|
216
|
-
|
|
256
|
+
operation: packOperation('services', command, parsed.action),
|
|
217
257
|
});
|
|
218
258
|
if (!auth.allowed)
|
|
219
259
|
return { ok: false, code: auth.code, error: auth.error };
|
|
@@ -224,6 +264,51 @@ async function execute(deps, parsed) {
|
|
|
224
264
|
case 'describe':
|
|
225
265
|
case 'schema':
|
|
226
266
|
return await runCall(deps, aid, parsed);
|
|
267
|
+
case 'rules:show': {
|
|
268
|
+
const config = new ServiceRulesStore(servicesDir).read();
|
|
269
|
+
const entries = parsed.type
|
|
270
|
+
? { [parsed.type]: config.rules[parsed.type] ?? { allow: [], deny: [] } }
|
|
271
|
+
: config.rules;
|
|
272
|
+
return { ok: true, result: { aid, enabled: config.enabled, rules: entries } };
|
|
273
|
+
}
|
|
274
|
+
case 'rules:add':
|
|
275
|
+
case 'rules:remove': {
|
|
276
|
+
if (!parsed.type)
|
|
277
|
+
return { ok: false, code: 'INVALID_ARGV', error: `${parsed.command.replace(':', ' ')} requires <type> <aid...>` };
|
|
278
|
+
const aids = parsed.aids ?? [];
|
|
279
|
+
if (aids.length === 0) {
|
|
280
|
+
return { ok: false, code: 'INVALID_ARGV', error: `${parsed.command.replace(':', ' ')} requires at least one <aid>` };
|
|
281
|
+
}
|
|
282
|
+
const store = new ServiceRulesStore(servicesDir);
|
|
283
|
+
const applied = store.mutate({
|
|
284
|
+
type: parsed.type,
|
|
285
|
+
action: command === 'rules:add' ? 'add' : 'remove',
|
|
286
|
+
rule: parsed.rule ?? 'allow',
|
|
287
|
+
aids,
|
|
288
|
+
});
|
|
289
|
+
new ServiceLedger(path.join(servicesDir, '.router-ledger.jsonl')).append({
|
|
290
|
+
action: 'rules.update',
|
|
291
|
+
result: 'ok',
|
|
292
|
+
type: parsed.type,
|
|
293
|
+
reason: parsed.rule ?? 'allow',
|
|
294
|
+
...(applied.added.length ? { added: applied.added } : {}),
|
|
295
|
+
...(applied.removed.length ? { removed: applied.removed } : {}),
|
|
296
|
+
});
|
|
297
|
+
// rules 只影响准入判定,不需要重扫包;但 live router 持有的是配置快照,
|
|
298
|
+
// 重启一次让新规则立刻生效(与 enable/disable 同一路径)。
|
|
299
|
+
const live = peekServiceRouter(aid);
|
|
300
|
+
if (live)
|
|
301
|
+
live.reload();
|
|
302
|
+
else
|
|
303
|
+
router.reload();
|
|
304
|
+
return {
|
|
305
|
+
ok: true,
|
|
306
|
+
result: {
|
|
307
|
+
aid, type: parsed.type, rule: parsed.rule ?? 'allow',
|
|
308
|
+
added: applied.added, removed: applied.removed,
|
|
309
|
+
},
|
|
310
|
+
};
|
|
311
|
+
}
|
|
227
312
|
case 'status': {
|
|
228
313
|
if (parsed.pack) {
|
|
229
314
|
const found = statusForPack(snapshot, parsed.pack);
|
|
@@ -271,12 +356,17 @@ async function execute(deps, parsed) {
|
|
|
271
356
|
case 'doctor':
|
|
272
357
|
return { ok: true, result: { aid, findings: doctor(aid, router, parsed.pack) } };
|
|
273
358
|
case 'reload': {
|
|
359
|
+
// 不支持单包重载:`reload()` 全量重扫。曾把位置参数原样回显成
|
|
360
|
+
// `reloaded: <包名>`,等于向调用方谎报"只重载了一个包"。
|
|
361
|
+
if (parsed.pack) {
|
|
362
|
+
return { ok: false, code: 'INVALID_ARGV', error: `reload does not accept a pack name (reloads all packs): ${parsed.pack}` };
|
|
363
|
+
}
|
|
274
364
|
const live = peekServiceRouter(aid);
|
|
275
365
|
if (live)
|
|
276
366
|
live.reload();
|
|
277
367
|
else
|
|
278
368
|
router.reload();
|
|
279
|
-
return { ok: true, result: { aid, reloaded:
|
|
369
|
+
return { ok: true, result: { aid, reloaded: '*', enabled: router.enabled } };
|
|
280
370
|
}
|
|
281
371
|
case 'enable':
|
|
282
372
|
case 'disable':
|
|
@@ -298,15 +388,21 @@ async function execute(deps, parsed) {
|
|
|
298
388
|
manifestFile: PACK_JSON,
|
|
299
389
|
legacyManifestFile: 'service.json',
|
|
300
390
|
});
|
|
301
|
-
// 装包后若还没有 services-config.json
|
|
302
|
-
//
|
|
391
|
+
// 装包后若还没有 services-config.json,建一份 **enabled=false** 的总闸。
|
|
392
|
+
//
|
|
393
|
+
// 不能自动开:总闸是"这个 AID 是否对外提供服务的整机决策",需要
|
|
394
|
+
// daemonOwner + fullaccess 显式执行 `ec services enable`。装包只是把文件
|
|
395
|
+
// 放到位(owner/admin 即可),自动开机等于让装包顺带绕过那道闸。
|
|
396
|
+
//
|
|
397
|
+
// 仍然落盘而不是留空:`loadRouterConfig` 对缺失文件返回缺省 enabled=false,
|
|
398
|
+
// 行为一样,但文件存在才可发现——否则用户只会看到"服务不通"。
|
|
303
399
|
const routerPath = path.join(servicesDirForPack, SERVICES_CONFIG_JSON);
|
|
304
400
|
let createdRouter = false;
|
|
305
401
|
if (!fs.existsSync(routerPath)) {
|
|
306
402
|
fs.mkdirSync(servicesDirForPack, { recursive: true });
|
|
307
403
|
fs.writeFileSync(routerPath, `${JSON.stringify({
|
|
308
404
|
v: 1,
|
|
309
|
-
enabled:
|
|
405
|
+
enabled: false,
|
|
310
406
|
rateLimit: {
|
|
311
407
|
builtin: { perMinute: 20, perHour: 200 },
|
|
312
408
|
service: { perMinute: 50, perHour: 1000 },
|
|
@@ -320,7 +416,17 @@ async function execute(deps, parsed) {
|
|
|
320
416
|
live.reload();
|
|
321
417
|
else
|
|
322
418
|
router.reload();
|
|
323
|
-
|
|
419
|
+
// 配置存在但坏了:装包成功、总闸却回落到 enabled=false,业务消息全被静默丢弃。
|
|
420
|
+
// 不替用户改文件,但必须把原因带回去。
|
|
421
|
+
const configErrors = createdRouter ? [] : loadRouterConfig(servicesDirForPack).errors;
|
|
422
|
+
return {
|
|
423
|
+
ok: true,
|
|
424
|
+
result: {
|
|
425
|
+
aid, ...installed,
|
|
426
|
+
...(createdRouter ? { createdRouter: true } : {}),
|
|
427
|
+
...(configErrors.length > 0 ? { configErrors } : {}),
|
|
428
|
+
},
|
|
429
|
+
};
|
|
324
430
|
}
|
|
325
431
|
if (parsed.action === 'remove') {
|
|
326
432
|
const removed = removePack({ pack: parsed.pack, targetRoot: servicesDirForPack, purge: parsed.purge === true });
|
|
@@ -331,6 +437,27 @@ async function execute(deps, parsed) {
|
|
|
331
437
|
router.reload();
|
|
332
438
|
return { ok: true, result: { aid, ...removed } };
|
|
333
439
|
}
|
|
440
|
+
if (parsed.action === 'enable' || parsed.action === 'disable') {
|
|
441
|
+
const enabled = parsed.action === 'enable';
|
|
442
|
+
const toggled = setPackEnabled({
|
|
443
|
+
targetRoot: servicesDirForPack,
|
|
444
|
+
pack: parsed.pack,
|
|
445
|
+
manifestFile: PACK_JSON,
|
|
446
|
+
enabled,
|
|
447
|
+
});
|
|
448
|
+
// 台账记"有人主动改过",与加载时发现 enabled=false 的 pack.disabled 分开。
|
|
449
|
+
new ServiceLedger(path.join(toggled.dir, 'ledger.jsonl')).append({
|
|
450
|
+
action: enabled ? 'pack.enable' : 'pack.disable',
|
|
451
|
+
result: 'ok',
|
|
452
|
+
packId: parsed.pack,
|
|
453
|
+
});
|
|
454
|
+
const live = peekServiceRouter(aid);
|
|
455
|
+
if (live)
|
|
456
|
+
live.reload();
|
|
457
|
+
else
|
|
458
|
+
router.reload();
|
|
459
|
+
return { ok: true, result: { aid, ...toggled } };
|
|
460
|
+
}
|
|
334
461
|
return { ok: false, code: 'UNKNOWN_COMMAND', error: `unknown pack action: ${parsed.action ?? '(none)'}
|
|
335
462
|
${HELP}` };
|
|
336
463
|
}
|
|
@@ -356,6 +483,11 @@ async function runCall(deps, selfAid, parsed) {
|
|
|
356
483
|
const targetAid = parsed.pack;
|
|
357
484
|
if (!targetAid)
|
|
358
485
|
return { ok: false, code: 'INVALID_ARGV', error: `${parsed.command} requires <aid>` };
|
|
486
|
+
// 调自己:消息会发出去,但入站侧没有任何分支会应答它,只能干等满超时(默认 30s)
|
|
487
|
+
// 然后报一个看起来像对端故障的 NO_RESULT。前置拒绝,别让人等。
|
|
488
|
+
if (normalizeAid(targetAid) === normalizeAid(selfAid)) {
|
|
489
|
+
return { ok: false, code: 'INVALID_ARGV', error: 'cannot call self: <aid> is this daemon\'s own AID' };
|
|
490
|
+
}
|
|
359
491
|
const channel = deps.getChannel?.(selfAid);
|
|
360
492
|
if (!channel?.sendDaemonMsg) {
|
|
361
493
|
return { ok: false, code: 'NOT_CONFIGURED', error: `no AUN channel is connected for ${selfAid}` };
|
|
@@ -489,10 +621,13 @@ function doctor(aid, router, only) {
|
|
|
489
621
|
});
|
|
490
622
|
}
|
|
491
623
|
}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
624
|
+
}
|
|
625
|
+
// 5. type=services 但无激活包。
|
|
626
|
+
//
|
|
627
|
+
// 必须在循环外:`activePacks` 为空时循环一次都不进,而这正是该告警唯一会成立的
|
|
628
|
+
// 场景。写成循环体里等于永不触发。
|
|
629
|
+
if (snapshot.identity.type === 'services' && snapshot.packs.activePacks.length === 0) {
|
|
630
|
+
findings.push({ level: 'warn', check: 'identity', detail: 'agent.md type=services but no active service pack' });
|
|
496
631
|
}
|
|
497
632
|
for (const item of snapshot.packs.skippedPacks) {
|
|
498
633
|
if (only && item.id !== only)
|
|
@@ -507,6 +642,15 @@ function doctor(aid, router, only) {
|
|
|
507
642
|
for (const conflict of snapshot.packs.conflicts) {
|
|
508
643
|
findings.push({ level: 'error', check: 'listen.type', detail: `${conflict.type} declared by ${conflict.packs.join(', ')}` });
|
|
509
644
|
}
|
|
645
|
+
// 通配重叠:不是错误(路由仍确定:精确优先、其次按目录扫描顺序取首个通配),
|
|
646
|
+
// 但"哪个包接"取决于 readdir 顺序,必须让人知道。
|
|
647
|
+
for (const overlap of snapshot.packs.overlaps) {
|
|
648
|
+
findings.push({
|
|
649
|
+
level: 'warn',
|
|
650
|
+
check: 'listen.type.overlap',
|
|
651
|
+
detail: `${overlap.type} also matches ${overlap.shadowed} (${overlap.packs.join(' / ')}); routing order depends on directory scan order`,
|
|
652
|
+
});
|
|
653
|
+
}
|
|
510
654
|
// 6. services/ 未进 L_CLASS(由 protected-paths 的运行时常量核对)。
|
|
511
655
|
findings.push(lClassFinding());
|
|
512
656
|
return findings;
|
|
@@ -22,7 +22,10 @@ export const SCRIPTS_DIR = 'scripts';
|
|
|
22
22
|
export const LEDGER_FILE = 'ledger.jsonl';
|
|
23
23
|
export const LOGS_DIR = 'logs';
|
|
24
24
|
export const IDEMPOTENCY_FILE = '.idempotency.jsonl';
|
|
25
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* realpath 全级校验:目标真实路径必须仍在包目录内(防中间目录符号链接逃逸)。
|
|
27
|
+
* 通过时返回**已解析的真实路径**,调用方直接对它 stat,不必再 realpath 一次。
|
|
28
|
+
*/
|
|
26
29
|
function assertInsidePackDir(packDir, target, errors, field) {
|
|
27
30
|
let realTarget;
|
|
28
31
|
try {
|
|
@@ -30,14 +33,14 @@ function assertInsidePackDir(packDir, target, errors, field) {
|
|
|
30
33
|
}
|
|
31
34
|
catch {
|
|
32
35
|
errors.push(`${field} not found: ${path.relative(packDir, target)}`);
|
|
33
|
-
return
|
|
36
|
+
return undefined;
|
|
34
37
|
}
|
|
35
38
|
const realPackDir = fs.realpathSync(packDir);
|
|
36
39
|
if (realTarget !== realPackDir && !realTarget.startsWith(realPackDir + path.sep)) {
|
|
37
40
|
errors.push(`${field} escapes pack directory via symlink`);
|
|
38
|
-
return
|
|
41
|
+
return undefined;
|
|
39
42
|
}
|
|
40
|
-
return
|
|
43
|
+
return realTarget;
|
|
41
44
|
}
|
|
42
45
|
/** 加载单个包目录。返回 null 表示该包 invalid(errors 已填)。 */
|
|
43
46
|
export function loadPackDir(packDir, errors) {
|
|
@@ -76,10 +79,10 @@ export function loadPackDir(packDir, errors) {
|
|
|
76
79
|
for (const entry of validated.value.listen) {
|
|
77
80
|
const relativeUnderScripts = entry.handler.script.slice(SCRIPTS_DIR.length + 1);
|
|
78
81
|
const scriptPath = path.join(scriptsDir, relativeUnderScripts);
|
|
79
|
-
|
|
82
|
+
const realScript = assertInsidePackDir(packDir, scriptPath, errors, `listen[].handler.script "${entry.handler.script}"`);
|
|
83
|
+
if (!realScript)
|
|
80
84
|
continue;
|
|
81
|
-
|
|
82
|
-
if (!stat.isFile())
|
|
85
|
+
if (!fs.statSync(realScript).isFile())
|
|
83
86
|
errors.push(`listen[].handler.script "${entry.handler.script}" is not a regular file`);
|
|
84
87
|
}
|
|
85
88
|
const logsDir = path.join(packDir, LOGS_DIR);
|
|
@@ -149,7 +152,7 @@ export function loadPacks(servicesDir) {
|
|
|
149
152
|
* - requires 不满足 → skipped(不是错误);
|
|
150
153
|
* - 跨包同 listen.type 且两包都 active → 两个包都 invalid。
|
|
151
154
|
*/
|
|
152
|
-
export function buildPackState(packs, invalidPacks, identity
|
|
155
|
+
export function buildPackState(packs, invalidPacks, identity) {
|
|
153
156
|
const disabledPacks = packs.filter(pack => !pack.enabled).map(pack => pack.id);
|
|
154
157
|
const candidates = packs.filter(pack => pack.enabled);
|
|
155
158
|
const skippedPacks = [];
|
|
@@ -189,6 +192,30 @@ export function buildPackState(packs, invalidPacks, identity, previousRevision =
|
|
|
189
192
|
});
|
|
190
193
|
}
|
|
191
194
|
const activePacks = activeCandidates.filter(pack => !conflictPackIds.has(pack.id));
|
|
195
|
+
// 通配重叠:`a.x.*` 与另一个包的 `a.x.y`(或两个通配)会同时命中同一个 type。
|
|
196
|
+
// 路由是确定的(精确优先,其次按 readdir 顺序取首个通配),但"哪个包接"取决于
|
|
197
|
+
// 目录扫描顺序——这不是冲突,不该判 invalid,但必须让 doctor 报出来。
|
|
198
|
+
const overlaps = [];
|
|
199
|
+
for (const pack of activePacks) {
|
|
200
|
+
for (const entry of pack.listen) {
|
|
201
|
+
if (!entry.type.endsWith('.*'))
|
|
202
|
+
continue;
|
|
203
|
+
const prefix = entry.type.slice(0, -1);
|
|
204
|
+
for (const other of activePacks) {
|
|
205
|
+
if (other.id === pack.id)
|
|
206
|
+
continue;
|
|
207
|
+
for (const otherEntry of other.listen) {
|
|
208
|
+
// 两个通配:前缀互为前缀(同长则完全相同,已被上面的冲突检测捕获)。
|
|
209
|
+
const overlapsOther = otherEntry.type.endsWith('.*')
|
|
210
|
+
? otherEntry.type.slice(0, -1).startsWith(prefix) || prefix.startsWith(otherEntry.type.slice(0, -1))
|
|
211
|
+
: otherEntry.type.startsWith(prefix);
|
|
212
|
+
if (overlapsOther) {
|
|
213
|
+
overlaps.push({ type: entry.type, packs: [pack.id, other.id], shadowed: otherEntry.type });
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
192
219
|
const routeIndex = new Map();
|
|
193
220
|
const wildcardIndex = [];
|
|
194
221
|
for (const pack of activePacks) {
|
|
@@ -208,8 +235,9 @@ export function buildPackState(packs, invalidPacks, identity, previousRevision =
|
|
|
208
235
|
disabledPacks,
|
|
209
236
|
invalidPacks: [...invalidPacks, ...conflictInvalid],
|
|
210
237
|
conflicts,
|
|
238
|
+
overlaps,
|
|
211
239
|
routeIndex,
|
|
212
240
|
wildcardIndex,
|
|
213
|
-
revision:
|
|
241
|
+
revision: 1,
|
|
214
242
|
};
|
|
215
243
|
}
|
package/dist/services/router.js
CHANGED
|
@@ -6,8 +6,12 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import fs from 'node:fs';
|
|
8
8
|
import path from 'node:path';
|
|
9
|
+
import { ServiceError } from './types.js';
|
|
10
|
+
import { atomicWriteJson } from '../utils/atomic-write.js';
|
|
9
11
|
import { validateRouterConfig } from './validation.js';
|
|
10
12
|
import { migrateLegacyFileName } from '../core/legacy-rename.js';
|
|
13
|
+
import { RateWindow } from '../core/rate-window.js';
|
|
14
|
+
import { RESERVED_TYPES } from './service-payload.js';
|
|
11
15
|
export const SERVICES_CONFIG_JSON = 'services-config.json';
|
|
12
16
|
export const DEFAULT_ROUTER_CONFIG = {
|
|
13
17
|
v: 1,
|
|
@@ -16,6 +20,7 @@ export const DEFAULT_ROUTER_CONFIG = {
|
|
|
16
20
|
builtin: { perMinute: 20, perHour: 200 },
|
|
17
21
|
service: { perMinute: 50, perHour: 1000 },
|
|
18
22
|
},
|
|
23
|
+
rules: {},
|
|
19
24
|
};
|
|
20
25
|
/** 读取 services/services-config.json;不存在或缺 v 时返回缺省(enabled=false)。 */
|
|
21
26
|
export function loadRouterConfig(servicesDir) {
|
|
@@ -45,9 +50,14 @@ export function loadRouterConfig(servicesDir) {
|
|
|
45
50
|
return { config: DEFAULT_ROUTER_CONFIG, exists: true, errors: validated.errors };
|
|
46
51
|
return { config: validated.value, exists: true, errors: [] };
|
|
47
52
|
}
|
|
48
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* 服务侧限流:`builtin` / `service` 两套额度,按 (bucket, fromAid) 独立计数。
|
|
55
|
+
*
|
|
56
|
+
* 窗口算法复用 `src/core/rate-window.ts`——事件侧用的是同一份。这里曾经是一份完整
|
|
57
|
+
* 复制,两份各自漂移的话,限流行为不一致比没有限流更难排查。
|
|
58
|
+
*/
|
|
49
59
|
export class RateLimiter {
|
|
50
|
-
windows = new
|
|
60
|
+
windows = new RateWindow();
|
|
51
61
|
config;
|
|
52
62
|
constructor(config) {
|
|
53
63
|
this.config = config;
|
|
@@ -60,39 +70,98 @@ export class RateLimiter {
|
|
|
60
70
|
}
|
|
61
71
|
/** 记一次消费;超限时不计数并给出 retryAfter。 */
|
|
62
72
|
consume(bucket, fromAid, now = Date.now()) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
return this.windows.consume(`${bucket}\u0000${fromAid}`, this.quota(bucket), now);
|
|
74
|
+
}
|
|
75
|
+
/** 清理过期窗口,避免长期运行后按 AID 无限增长。调用点在 `ServiceRouter.reload()`。 */
|
|
76
|
+
prune(now = Date.now()) {
|
|
77
|
+
this.windows.prune(now);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/** 与 `services/validation.ts` 同一份口径。 */
|
|
81
|
+
const AID_PATTERN = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)*\.[a-z]{2,}$/;
|
|
82
|
+
export class ServiceRulesStore {
|
|
83
|
+
servicesDir;
|
|
84
|
+
constructor(servicesDir) {
|
|
85
|
+
this.servicesDir = servicesDir;
|
|
86
|
+
}
|
|
87
|
+
/** 严格读:文件存在但非法时抛错,**不**退回缺省值——否则写回会把整份配置清零。 */
|
|
88
|
+
readStrict() {
|
|
89
|
+
const loaded = loadRouterConfig(this.servicesDir);
|
|
90
|
+
if (loaded.exists && loaded.errors.length > 0) {
|
|
91
|
+
throw new ServiceError('CONFIG_INVALID', `${SERVICES_CONFIG_JSON}: ${loaded.errors.join('; ')}`);
|
|
75
92
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
93
|
+
const filePath = path.join(this.servicesDir, SERVICES_CONFIG_JSON);
|
|
94
|
+
let raw = {};
|
|
95
|
+
if (loaded.exists) {
|
|
96
|
+
try {
|
|
97
|
+
const parsed = JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
98
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed))
|
|
99
|
+
raw = parsed;
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
throw new ServiceError('CONFIG_INVALID', `${SERVICES_CONFIG_JSON} is not valid JSON`);
|
|
103
|
+
}
|
|
79
104
|
}
|
|
80
|
-
|
|
81
|
-
|
|
105
|
+
return { config: loaded.config, raw };
|
|
106
|
+
}
|
|
107
|
+
/** 原样保留其他顶层字段(v / enabled / rateLimit),只替换 rules。 */
|
|
108
|
+
write(servicesDirConfig, raw) {
|
|
109
|
+
const filePath = path.join(this.servicesDir, SERVICES_CONFIG_JSON);
|
|
110
|
+
fs.mkdirSync(this.servicesDir, { recursive: true });
|
|
111
|
+
atomicWriteJson(filePath, { ...raw, v: 1, rules: servicesDirConfig.rules });
|
|
112
|
+
}
|
|
113
|
+
read() {
|
|
114
|
+
return this.readStrict().config;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* 增删一个 AID。
|
|
118
|
+
*
|
|
119
|
+
* `allow` 与 `deny` 互斥:同一个 AID 同时出现在两边时 deny 赢,但写的人多半
|
|
120
|
+
* 以为 allow 会赢——直接报错,别让人以为规则生效了。
|
|
121
|
+
*/
|
|
122
|
+
mutate(input) {
|
|
123
|
+
// Builtin admission is fixed; reject rules that could never take effect.
|
|
124
|
+
if (RESERVED_TYPES.has(input.type)) {
|
|
125
|
+
throw new ServiceError('INVALID_ARGS', `rules must not target a builtin reserved type: ${input.type} (builtin admission is fixed)`);
|
|
82
126
|
}
|
|
83
|
-
|
|
84
|
-
|
|
127
|
+
for (const aid of input.aids) {
|
|
128
|
+
if (!AID_PATTERN.test(aid))
|
|
129
|
+
throw new ServiceError('INVALID_ARGS', `invalid AID: ${aid}`);
|
|
85
130
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
131
|
+
const { config, raw } = this.readStrict();
|
|
132
|
+
const current = config.rules[input.type];
|
|
133
|
+
const entry = current
|
|
134
|
+
? { allow: [...current.allow], deny: [...current.deny] }
|
|
135
|
+
: { allow: [], deny: [] };
|
|
136
|
+
const list = input.rule === 'deny' ? entry.deny : entry.allow;
|
|
137
|
+
const opposite = input.rule === 'deny' ? entry.allow : entry.deny;
|
|
138
|
+
const added = [];
|
|
139
|
+
const removed = [];
|
|
140
|
+
for (const aid of input.aids) {
|
|
141
|
+
if (input.action === 'add') {
|
|
142
|
+
if (opposite.includes(aid)) {
|
|
143
|
+
throw new ServiceError('INVALID_ARGS', `AID appears in both allow and deny for ${input.type}: ${aid}`);
|
|
144
|
+
}
|
|
145
|
+
if (!list.includes(aid)) {
|
|
146
|
+
list.push(aid);
|
|
147
|
+
added.push(aid);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
const index = list.indexOf(aid);
|
|
152
|
+
if (index >= 0) {
|
|
153
|
+
list.splice(index, 1);
|
|
154
|
+
removed.push(aid);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
96
157
|
}
|
|
158
|
+
// 两个列表都空时把条目删掉,而不是留一条空规则:空规则的语义是"基础集合
|
|
159
|
+
// 原样放行",与"没有规则"相同,但会让 `rules show` 里多一行噪音。
|
|
160
|
+
if (entry.allow.length === 0 && entry.deny.length === 0)
|
|
161
|
+
delete config.rules[input.type];
|
|
162
|
+
else
|
|
163
|
+
config.rules[input.type] = entry;
|
|
164
|
+
this.write(config, raw);
|
|
165
|
+
return { config, changed: entry, added, removed };
|
|
97
166
|
}
|
|
98
167
|
}
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { spawn } from 'node:child_process';
|
|
9
9
|
import path from 'node:path';
|
|
10
|
-
import { buildTriggerScriptLaunch } from '../trigger/script-sandbox.js';
|
|
11
|
-
import { sanitizeShellExecutionEnvironment } from '../core/permission/shell-environment.js';
|
|
10
|
+
import { buildTriggerScriptLaunch, runPrepareWithDeadline } from '../trigger/script-sandbox.js';
|
|
11
|
+
import { isCredentialEnvironmentName, sanitizeShellExecutionEnvironment } from '../core/permission/shell-environment.js';
|
|
12
12
|
import { resolveRuntimePermissionMode } from '../core/role/runtime-policy.js';
|
|
13
13
|
import { resolvePhaseOneExecutionSandbox } from '../core/permission/mode.js';
|
|
14
14
|
import { killProcessTree, resolveCommandPath } from '../utils/cross-platform.js';
|
|
@@ -60,8 +60,11 @@ export class ServiceScriptRunner {
|
|
|
60
60
|
async run(pack, handler, message) {
|
|
61
61
|
const startedAt = Date.now();
|
|
62
62
|
let cmd = handler.script;
|
|
63
|
+
// `cmd` 由 finish 统一带上:解释器与绝对路径在 try 里才算得出来(拿不到 runtime 时
|
|
64
|
+
// 退回相对路径),调用方不该为它传参。
|
|
63
65
|
const finish = (partial) => ({
|
|
64
66
|
...partial,
|
|
67
|
+
cmd,
|
|
65
68
|
durationMs: Date.now() - startedAt,
|
|
66
69
|
});
|
|
67
70
|
let launch;
|
|
@@ -75,7 +78,9 @@ export class ServiceScriptRunner {
|
|
|
75
78
|
launch = this.buildLaunch(pack, handler, message, executable, scriptPath, scriptArgs);
|
|
76
79
|
if (launch.prepare) {
|
|
77
80
|
try {
|
|
78
|
-
|
|
81
|
+
// 探针必须设上限:沙箱 provisioning 挂住时这里会无限等待,dispatcher 的
|
|
82
|
+
// 槽位永不释放,5 个并发打满后整个 services 停摆。探针本身响应 abort。
|
|
83
|
+
await runPrepareWithDeadline(launch.prepare);
|
|
79
84
|
}
|
|
80
85
|
catch (error) {
|
|
81
86
|
// 沙箱不可用 → 降级:清掉这次 launch,改用无沙箱配置重跑。
|
|
@@ -87,7 +92,11 @@ export class ServiceScriptRunner {
|
|
|
87
92
|
}
|
|
88
93
|
catch (error) {
|
|
89
94
|
const code = error.code;
|
|
90
|
-
if (code === 'RUNTIME_NOT_FOUND' || code === 'INVALID_RUNTIME') {
|
|
95
|
+
if (code === 'RUNTIME_NOT_FOUND' || code === 'INVALID_RUNTIME' || code === 'SCRIPT_SANDBOX_UNAVAILABLE') {
|
|
96
|
+
// 拒跑而不是降级:`SCRIPT_SANDBOX_UNAVAILABLE` 来自「拿不到工程目录」这类
|
|
97
|
+
// 本该 fail-closed 的情况(见 aun.ts 的 setDefaultProjectPath 与
|
|
98
|
+
// event-center/daemon.ts 的 fail-closed 注释)。把它当沙箱缺失降级,等于
|
|
99
|
+
// 把"边界不可证明"变成"无边界执行"。
|
|
91
100
|
return finish({ outcome: 'error', exitCode: 126, error: { code: String(code), message: errorMessage(error) }, stdoutPreview: '', stderrPreview: '' });
|
|
92
101
|
}
|
|
93
102
|
// 沙箱构造失败(缺 codex / 缺 bubblewrap / 平台不支持)→ 降级执行。
|
|
@@ -418,5 +427,7 @@ export function extractServiceData(payload) {
|
|
|
418
427
|
function isExcludedEnv(key) {
|
|
419
428
|
if (ENVIRONMENT_EXCLUDES.includes(key))
|
|
420
429
|
return true;
|
|
430
|
+
if (isCredentialEnvironmentName(key))
|
|
431
|
+
return true;
|
|
421
432
|
return key.toUpperCase().startsWith('EVOLCORE_');
|
|
422
433
|
}
|