evolcore 0.0.48 → 0.0.50
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 +97 -0
- package/bin/ecmsg.js +9 -4
- package/dist/ability/caller/authorization.js +21 -0
- package/dist/ability/caller/command.js +164 -0
- package/dist/ability/caller/contract.js +102 -0
- package/dist/ability/caller/daemon.js +158 -0
- package/dist/ability/caller/service.js +380 -0
- package/dist/ability/command-contract.js +5 -0
- package/dist/ability/daemon.js +5 -1
- package/dist/ability/interop-v1.js +10 -3
- package/dist/ability/management.js +1 -0
- package/dist/agent-template/jobs.js +173 -1
- package/dist/agent-template/runtime.js +285 -8
- package/dist/agent-template/service.js +1159 -40
- package/dist/agent-template/types.js +2 -1
- package/dist/agents/baseagent-availability.js +27 -3
- package/dist/agents/baseagent-capability-adapter.js +102 -0
- package/dist/agents/baseagent-plugin-descriptor.js +274 -0
- package/dist/agents/baseagent-plugin-loader.js +145 -0
- package/dist/agents/baseagent.js +68 -2
- package/dist/agents/claude-gateway/agent-registration.js +389 -0
- package/dist/agents/claude-gateway/binding.js +96 -0
- package/dist/agents/claude-gateway/inbox.js +138 -0
- package/dist/agents/claude-gateway/index.js +125 -0
- package/dist/agents/claude-gateway/listing.js +330 -0
- package/dist/agents/claude-gateway/router.js +328 -0
- package/dist/agents/claude-gateway/sessions.js +128 -0
- package/dist/agents/claude-gateway/terminal.js +250 -0
- package/dist/agents/claude-gateway/transcript.js +272 -0
- package/dist/agents/claude-gateway/types.js +14 -0
- package/dist/agents/claude-runner.js +6 -10
- package/dist/agents/codex-runner.js +9 -2
- package/dist/agents/{gemini-runner.js → gemini/gemini-runner.js} +17 -17
- package/dist/{core/session/adapters → agents/gemini}/gemini-session-file-adapter.js +2 -2
- package/dist/agents/gemini/index.js +51 -0
- package/dist/aun/aid/control-aid.js +52 -32
- package/dist/aun/group/invite-service.js +6 -36
- package/dist/aun/group/operations.js +6 -0
- package/dist/aun/msg/mention-schema.js +1 -1
- package/dist/aun/msg/p2p.js +31 -2
- package/dist/aun/msg/upload.js +126 -3
- package/dist/build-identity.json +1 -1
- package/dist/channels/aun.js +1175 -457
- package/dist/cli/ability-command.js +42 -0
- package/dist/cli/agent-command.js +20 -1
- package/dist/cli/agent-create.js +78 -18
- package/dist/cli/agent-template.js +5 -3
- package/dist/cli/agent.js +91 -0
- package/dist/cli/aun-commands.js +92 -34
- package/dist/cli/bench.js +5 -2
- package/dist/cli/config.js +22 -6
- package/dist/cli/daemon-commands.js +245 -101
- package/dist/cli/directory.js +6 -1
- package/dist/cli/ecmsg-gateway.js +11 -9
- package/dist/cli/index.js +30 -5
- package/dist/cli/init.js +39 -63
- package/dist/cli/managed-command-guard.js +3 -0
- package/dist/cli/menu-client.js +32 -7
- package/dist/cli/model.js +20 -5
- package/dist/cli/pay-command.js +30 -0
- package/dist/cli/provider-command.js +6 -2
- package/dist/cli/quota.js +89 -0
- package/dist/cli/restart-monitor.js +2 -2
- package/dist/cli/role.js +1 -0
- package/dist/cli/services-command.js +12 -9
- package/dist/cli/team-workspace-command.js +56 -2
- package/dist/cli/thread-command.js +78 -12
- package/dist/config/access-policy.js +16 -3
- package/dist/config/config-field-policy.js +88 -9
- package/dist/config/config-manager.js +97 -47
- package/dist/config/config-operation-service.js +22 -1
- package/dist/config/gateway-config.js +9 -8
- package/dist/config/owner-config.js +0 -16
- package/dist/config/peer-role-resolver.js +1 -7
- package/dist/config/providers-config.js +107 -20
- package/dist/config/providers-management.js +45 -21
- package/dist/config/resolved-config-op.js +4 -44
- package/dist/config/schema-migration.js +78 -5
- package/dist/config/schema-registry.js +52 -7
- package/dist/config-store.js +1309 -17
- package/dist/core/agent-application-service.js +220 -1
- package/dist/core/agent-ipc-registration.js +19 -2
- package/dist/core/agent-reload-coordinator.js +5 -0
- package/dist/core/agent-runtime.js +198 -54
- package/dist/core/auth/agent-delegation.js +14 -0
- package/dist/core/auth/delegation-authorization.js +33 -26
- package/dist/core/auth/operation-authorizer.js +16 -1
- package/dist/core/auth/operation-catalog.js +59 -7
- package/dist/core/baseagent-loader.js +30 -3
- package/dist/core/capability/capability-manager.js +16 -7
- package/dist/core/channel-runtime.js +4 -2
- package/dist/core/command/agent-control.js +20 -2
- package/dist/core/command/agent-template-menu.js +4 -3
- package/dist/core/command/cli-intent-parser.js +28 -0
- package/dist/core/command/command-handler.js +45 -2
- package/dist/core/command/menu-catalog.js +20 -4
- package/dist/core/command/menu-file-path.js +70 -0
- package/dist/core/command/menu-handler.js +97 -73
- package/dist/core/command/menu-protocol.js +29 -0
- package/dist/core/command/menu-query-batch.js +2 -2
- package/dist/core/command/private-mention-menu.js +71 -0
- package/dist/core/command/remote-shell.js +565 -0
- package/dist/core/command/slash-handler.js +17 -26
- package/dist/core/command/team-workspace-bootstrap.js +2 -1
- package/dist/core/command/topic-slash.js +7 -1
- package/dist/core/daemon-bootstrap.js +0 -4
- package/dist/core/daemon-control.js +58 -1
- package/dist/core/daemon-lifecycle.js +29 -7
- package/dist/core/evolagent-registry.js +18 -9
- package/dist/core/handoff/runtime.js +1 -1
- package/dist/core/host-snapshot.js +8 -3
- package/dist/core/initialization/service.js +3 -0
- package/dist/core/interaction-router.js +130 -0
- package/dist/core/ipc-registration.js +5 -0
- package/dist/core/memory/consolidation-context.js +2 -1
- package/dist/core/memory/consolidation.js +35 -64
- package/dist/core/message/aun-ipc-sender.js +213 -74
- package/dist/core/message/aun-request-registry.js +31 -0
- package/dist/core/message/contact-admission.js +91 -6
- package/dist/core/message/contact-pending-inbound.js +113 -0
- package/dist/core/message/contact-thread-approval.js +212 -0
- package/dist/core/message/im-renderer.js +40 -1
- package/dist/core/message/message-admission.js +5 -39
- package/dist/core/message/message-bridge.js +197 -45
- package/dist/core/message/message-log.js +32 -0
- package/dist/core/message/message-queue.js +102 -18
- package/dist/core/message/peer-mode.js +15 -4
- package/dist/core/message/response-engine.js +174 -26
- package/dist/core/message/send-options.js +37 -3
- package/dist/core/message/send-routing.js +11 -7
- package/dist/core/model/config-scope.js +6 -14
- package/dist/core/model/model-catalog.js +5 -5
- package/dist/core/model/model-diagnostics.js +19 -0
- package/dist/core/model/model-fallback.js +13 -2
- package/dist/core/ownership/owner-resolver.js +12 -86
- package/dist/core/pack-auth.js +7 -0
- package/dist/core/pack-install.js +1 -1
- package/dist/core/permission/ec-command-parser.js +288 -77
- package/dist/core/permission/protected-paths.js +64 -9
- package/dist/core/permission/services-path-acl.js +458 -0
- package/dist/core/permission/tool-policy.js +26 -10
- package/dist/core/relation/peer-identity.js +13 -0
- package/dist/core/session/adapters/claude-session-file-adapter.js +6 -2
- package/dist/core/session/adapters/codex-session-file-adapter.js +4 -0
- package/dist/core/session/session-manager.js +47 -10
- package/dist/core/session/session-mapper.js +16 -0
- package/dist/core/skill/index-generator.js +2 -3
- package/dist/core/skill/switch-resolver.js +3 -0
- package/dist/core/task/task-recovery-service.js +1 -0
- package/dist/core/thread/command-parser.js +4 -1
- package/dist/core/thread/ipc-operation.js +4 -2
- package/dist/core/thread/thread-operation.js +25 -10
- package/dist/core/thread/thread-service.js +294 -55
- package/dist/core/thread/topic-id.js +67 -2
- package/dist/core/thread/types.js +15 -1
- package/dist/directory/owner-directory-admission.js +11 -8
- package/dist/directory/owner-directory-cache.js +19 -0
- package/dist/directory/owner-directory-markdown.js +1 -1
- package/dist/directory/owner-directory-policy.js +5 -30
- package/dist/directory/owner-directory-request-operation.js +5 -2
- package/dist/eck/kit-renderer.js +3 -2
- package/dist/eck/message-renderer.js +28 -5
- package/dist/ecweb/basic-settings-service.js +5 -9
- package/dist/ecweb/providers-service.js +4 -2
- package/dist/ecweb/runtime/supervisor.js +36 -8
- package/dist/event-center/center-config.js +9 -5
- package/dist/event-center/dispatcher.js +10 -1
- package/dist/event-center/ipc-operation.js +19 -0
- package/dist/event-center/registry.js +20 -5
- package/dist/event-center/runtime.js +10 -7
- package/dist/index.js +120 -41
- package/dist/ipc.js +83 -3
- package/dist/outputs/authorization.js +16 -0
- package/dist/outputs/cards.js +336 -0
- package/dist/outputs/events.js +3 -2
- package/dist/outputs/protocol.js +1 -0
- package/dist/outputs/service.js +2 -15
- package/dist/paths.js +48 -1
- package/dist/pay/command.js +38 -0
- package/dist/pay/protocol.js +136 -0
- package/dist/pay/runtime.js +188 -0
- package/dist/pay/service.js +384 -0
- package/dist/pay/store.js +81 -0
- package/dist/response-system/engines/v1/proactive-flow.js +29 -2
- package/dist/services/dispatcher.js +23 -5
- package/dist/services/host/main.js +388 -0
- package/dist/services/host/protocol.js +118 -0
- package/dist/services/host/resident.js +310 -0
- package/dist/services/host-client.js +386 -0
- package/dist/services/host-deploy.js +180 -0
- package/dist/services/host-launch.js +117 -0
- package/dist/services/host-recycle.js +203 -0
- package/dist/services/host-runtime.js +802 -0
- package/dist/services/idempotency.js +44 -86
- package/dist/services/index-generator.js +4 -3
- package/dist/services/index.js +204 -22
- package/dist/services/ipc-operation.js +288 -44
- package/dist/services/pack-manager.js +1 -0
- package/dist/services/script-runner.js +515 -83
- package/dist/services/service-payload.js +13 -7
- package/dist/services/validation.js +109 -4
- package/dist/stats/budget.js +1 -1
- package/dist/stats/model-resolver.js +2 -2
- package/dist/stats/quota-query.js +95 -0
- package/dist/trigger/application-service.js +6 -4
- package/dist/trigger/local-files.js +19 -9
- package/dist/trigger/scheduler.js +22 -12
- package/dist/trigger/script-sandbox.js +51 -8
- package/dist/utils/aid-bind.js +3 -0
- package/dist/utils/atomic-write.js +22 -8
- package/dist/utils/evolcore-version.js +2 -2
- package/dist/utils/host-info.js +173 -1
- package/dist/utils/logger.js +2 -2
- package/dist/utils/media-cache.js +190 -43
- package/dist/utils/npm-ops.js +43 -8
- package/dist/utils/restart-safety.js +14 -1
- package/dist/utils/system-memory.js +113 -25
- package/dist/utils/systemd-lifecycle.js +154 -0
- package/dist/utils/windows-shell-trust.js +7 -3
- package/dist/workbench/service.js +1 -1
- package/kits/docs/INDEX.md +3 -2
- package/kits/docs/aun/AUN/346/266/210/346/201/257/347/261/273/345/236/213/344/270/216/345/261/236/346/200/247.md +1 -0
- package/kits/docs/channels/aun.md +1 -1
- package/kits/docs/evolcore/INDEX.md +9 -6
- package/kits/docs/evolcore/agent.md +36 -1
- package/kits/docs/evolcore/aid.md +45 -3
- package/kits/docs/evolcore/config.md +5 -2
- package/kits/docs/evolcore/directory.md +8 -9
- package/kits/docs/evolcore/group.md +2 -1
- package/kits/docs/evolcore/memory-tags.md +2 -0
- package/kits/docs/evolcore/menu-client.md +3 -3
- package/kits/docs/evolcore/menu-protocol.md +7 -0
- package/kits/docs/evolcore/model.md +3 -0
- package/kits/docs/evolcore/msg.md +77 -10
- package/kits/docs/evolcore/pay.md +34 -0
- package/kits/docs/evolcore/provider.md +22 -1
- package/kits/docs/evolcore/quota.md +54 -0
- package/kits/docs/evolcore/role.md +3 -0
- package/kits/docs/evolcore/services.md +46 -18
- package/kits/docs/evolcore/stats.md +2 -0
- package/kits/docs/evolcore/thread-chain.md +2 -0
- package/kits/docs/evolcore/tool-authorization.md +10 -0
- package/kits/docs/evolcore/trigger.md +2 -0
- package/kits/rules/01-overview.md +11 -32
- package/kits/rules/02-navigation.md +7 -0
- package/kits/rules/06-channel.md +3 -3
- package/kits/schemas/_meta.json +38 -5
- package/kits/schemas/agent-config.schema.20.json +24 -0
- package/kits/schemas/agent-config.schema.21.json +974 -0
- package/kits/schemas/agent-config.schema.22.json +977 -0
- package/kits/schemas/agent-config.schema.23.json +958 -0
- package/kits/schemas/daemon.schema.10.json +373 -0
- package/kits/schemas/daemon.schema.9.json +12 -0
- package/kits/schemas/defaults.schema.7.json +472 -0
- package/kits/schemas/providers.schema.3.json +18 -2
- package/kits/schemas/relation-config.schema.13.json +289 -0
- package/kits/skills/.switches.json +17 -1
- package/kits/skills/ability/SKILL.md +229 -34
- package/kits/skills/ability/STRUCTURE.md +333 -0
- package/kits/skills/ability/references/cli.md +208 -0
- package/kits/skills/ability/references/development.md +107 -37
- package/kits/skills/ability/references/management.md +106 -46
- package/kits/skills/ability/references/runtime-protocol.md +65 -63
- package/kits/skills/agent-output-cards/SKILL.md +64 -0
- package/kits/skills/ec-group/SKILL.md +8 -6
- package/kits/skills/ec-group/TASK.md +186 -0
- package/kits/skills/ec-group/WORKLOG.md +180 -0
- package/kits/skills/ec-group-collaboration/SKILL.md +3 -3
- package/kits/skills/ec-pay/SKILL.md +101 -0
- package/kits/skills/ec-pay/references/pay-cli.md +110 -0
- package/kits/skills/ec-provider/SKILL.md +58 -9
- package/kits/skills/{ec-service-proxy → ec-proxy}/SKILL.md +8 -5
- package/kits/skills/ec-service-call/SKILL.md +135 -0
- package/kits/skills/ec-service-pack/SKILL.md +277 -0
- package/kits/skills/ec-trigger/SKILL.md +1 -1
- package/kits/templates/memory-consolidation/notes.md +2 -2
- package/kits/templates/memory-consolidation/workflow.md +46 -0
- package/kits/templates/roles/visitor.json +1 -0
- package/kits/templates/system-fragments/channel.md +13 -4
- package/kits/templates/system-fragments/commands.md +5 -3
- package/kits/templates/system-fragments/directory-contacts.md +3 -4
- package/kits/templates/system-fragments/reply.md +1 -0
- package/kits/templates/system-fragments/session.md +1 -1
- package/kits/templates/system-fragments/thread.md +27 -128
- package/kits/templates/system-fragments/venue.md +27 -0
- package/package.json +4 -5
- package/scripts/agent-template/inspect.mjs +79 -29
- package/scripts/agent-template/overlay.mjs +20 -2
- package/scripts/agent-template/shared/common.mjs +24 -6
- package/scripts/agent-template/shared/team-schema.json +23 -5
- package/scripts/agent-template/shared/template-contract.mjs +107 -17
- package/scripts/agent-template/shared/template-package.mjs +254 -29
- package/scripts/agent-template/shared/template-runtime.mjs +145 -2
- package/scripts/agent-template/shared/template.mjs +67 -9
- package/scripts/agent-template/team-pack.mjs +132 -41
- package/scripts/agent-template/team-preview.mjs +249 -5
- package/kits/docs/aun/ABILITY_CALLING.md +0 -280
- package/kits/docs/evolcore/ability.md +0 -185
- package/kits/skills/ability/references/calling.md +0 -56
- package/kits/skills/ability/references/contract-checklist.md +0 -37
- package/kits/skills/ability/references/recovery.md +0 -27
- /package/dist/{core/capability/providers → agents/gemini}/gemini-capability-provider.js +0 -0
|
@@ -23,6 +23,16 @@ import { getAunRequestRegistry } from '../core/message/aun-request-registry.js';
|
|
|
23
23
|
import { ServiceError, errorMessage } from './types.js';
|
|
24
24
|
import { authorizePackTarget, packOperation } from '../core/pack-auth.js';
|
|
25
25
|
import { installPack, listPackDirs, removePack, setPackEnabled } from '../core/pack-install.js';
|
|
26
|
+
import { hardenServicesAcl, planServicesAclRepair, readServicesAcl } from '../core/permission/services-path-acl.js';
|
|
27
|
+
/**
|
|
28
|
+
* 服务调用的默认等待时长,也是请求消息的 TTL。
|
|
29
|
+
*
|
|
30
|
+
* 两者必须是同一个数:TTL 决定这条消息在网关存在多久,等待时长决定调用方愿意
|
|
31
|
+
* 等多久。TTL 更长就意味着"调用方已经放弃、消息还活着",重建了这套设计要去掉
|
|
32
|
+
* 的补投语义;TTL 更短则调用方还在等、消息已经没了。
|
|
33
|
+
*/
|
|
34
|
+
export const SERVICE_CALL_TIMEOUT_MS = 12_000;
|
|
35
|
+
export const SERVICE_CALL_TTL_SECONDS = Math.ceil(SERVICE_CALL_TIMEOUT_MS / 1_000);
|
|
26
36
|
const HELP = `ec services — 服务路由运维
|
|
27
37
|
|
|
28
38
|
用法:
|
|
@@ -31,8 +41,10 @@ const HELP = `ec services — 服务路由运维
|
|
|
31
41
|
ec services ledger <包名> [--tail N] [--aid <aid>] 台账
|
|
32
42
|
ec services tail <包名> [--tail N] [--aid <aid>] 服务消息日志
|
|
33
43
|
ec services doctor [<包名>] [--aid <aid>] 诊断
|
|
44
|
+
ec services repair-acl [--aid <aid>] 收紧 services/ 的 NTFS ACL(幂等,仅 Windows)
|
|
34
45
|
ec services reload [--aid <aid>] 重载(全部包)
|
|
35
46
|
ec services enable / disable [--aid <aid>] 总闸
|
|
47
|
+
ec services host enable / disable [--aid <aid>] 宿主模式(常驻执行形态)
|
|
36
48
|
ec services rules show [<type>] [--aid <aid>] 调用准入规则
|
|
37
49
|
ec services rules add <type> <aid...> [--deny] [--aid <aid>]
|
|
38
50
|
ec services rules remove <type> <aid...> [--deny] [--aid <aid>]
|
|
@@ -46,10 +58,10 @@ const HELP = `ec services — 服务路由运维
|
|
|
46
58
|
remove 默认把日志与台账归档到 <包>/logs/archive-<时间戳>/;--purge 连归档一起删。
|
|
47
59
|
ec services pack list [--aid <aid>]
|
|
48
60
|
|
|
49
|
-
|
|
50
|
-
ec services describe
|
|
51
|
-
ec services schema
|
|
52
|
-
ec services call
|
|
61
|
+
对端(--aid 是**被调用方**;发送身份托管会话自动补齐,宿主终端用 --as):
|
|
62
|
+
ec services describe --aid <对端aid> [--type <type>]
|
|
63
|
+
ec services schema --aid <对端aid> --type <type>
|
|
64
|
+
ec services call --aid <对端aid> --type <type> --data '<json>' [--as <发送身份>] [--timeout 12] [--encrypted]`;
|
|
53
65
|
export function parseServicesArgv(argv) {
|
|
54
66
|
const args = [...argv];
|
|
55
67
|
if (args.length === 0 || args[0] === 'help' || args[0] === '--help')
|
|
@@ -89,8 +101,8 @@ export function parseServicesArgv(argv) {
|
|
|
89
101
|
const timeoutRaw = consumeValue('--timeout');
|
|
90
102
|
if (timeoutRaw !== undefined) {
|
|
91
103
|
const timeoutMs = parseTimeoutMs(timeoutRaw);
|
|
92
|
-
if (timeoutMs === undefined)
|
|
93
|
-
return { error: `--timeout must be a positive duration (seconds or 30s/2m): ${timeoutRaw}` };
|
|
104
|
+
if (timeoutMs === undefined || timeoutMs > 300_000)
|
|
105
|
+
return { error: `--timeout must be a positive duration up to 5m (seconds or 30s/2m): ${timeoutRaw}` };
|
|
94
106
|
parsed.timeoutMs = timeoutMs;
|
|
95
107
|
}
|
|
96
108
|
const dataRaw = consumeValue('--data');
|
|
@@ -106,21 +118,22 @@ export function parseServicesArgv(argv) {
|
|
|
106
118
|
return { error: `--data is not valid JSON: ${error instanceof Error ? error.message : String(error)}` };
|
|
107
119
|
}
|
|
108
120
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
121
|
+
// `--type <type>` 是主名字;`--service` 作为历史别名保留(老脚本/文档在用)。
|
|
122
|
+
const typeFlag = consumeValue('--type');
|
|
123
|
+
if (typeFlag !== undefined)
|
|
124
|
+
parsed.type = typeFlag;
|
|
113
125
|
const serviceFlag = consumeValue('--service');
|
|
114
126
|
if (serviceFlag !== undefined)
|
|
115
127
|
parsed.type = serviceFlag;
|
|
128
|
+
// 对端调用的发送身份。与 `--aid`(被调用方)分开:同一个 flag 不能在不同子命令里
|
|
129
|
+
// 换含义,那会让"我到底在指谁"只能靠记忆。
|
|
130
|
+
const asFlag = consumeValue('--as');
|
|
131
|
+
if (asFlag !== undefined)
|
|
132
|
+
parsed.as = asFlag;
|
|
116
133
|
if (args.includes('--encrypted')) {
|
|
117
134
|
parsed.encrypted = true;
|
|
118
135
|
args.splice(args.indexOf('--encrypted'), 1);
|
|
119
136
|
}
|
|
120
|
-
if (args.includes('--no-wait')) {
|
|
121
|
-
parsed.noWait = true;
|
|
122
|
-
args.splice(args.indexOf('--no-wait'), 1);
|
|
123
|
-
}
|
|
124
137
|
parsed.from = consumeValue('--from');
|
|
125
138
|
if (args.includes('--purge')) {
|
|
126
139
|
parsed.purge = true;
|
|
@@ -145,16 +158,46 @@ export function parseServicesArgv(argv) {
|
|
|
145
158
|
parsed.type = positional[1];
|
|
146
159
|
parsed.aids = positional.slice(2);
|
|
147
160
|
}
|
|
161
|
+
else if (command === 'host') {
|
|
162
|
+
// `host enable` / `host disable`。子动作名与总闸同名但作用的是 `host.enabled`,
|
|
163
|
+
// 不在这里分流就会落进下面的默认分支,被当成包名去查。
|
|
164
|
+
const action = positional[0] ?? '';
|
|
165
|
+
if (action !== 'enable' && action !== 'disable') {
|
|
166
|
+
return { error: `host requires an action: enable | disable (got ${action || '(none)'})` };
|
|
167
|
+
}
|
|
168
|
+
parsed.command = `host:${action}`;
|
|
169
|
+
}
|
|
170
|
+
else if (command === 'call' || command === 'describe' || command === 'schema') {
|
|
171
|
+
// 对端调用**只接受显式参数**:被调用方是 `--aid`,type 是 `--type`。
|
|
172
|
+
//
|
|
173
|
+
// 位置参数在这里曾同时承担"目标 AID"和"type",而 `--aid` 又指的是发送身份——
|
|
174
|
+
// 三个身份混在两处,读命令的人无法自证谁是谁。现在统一:`--aid` 永远是
|
|
175
|
+
// 被调用方(与 status / pack / enable 一致),发送身份走 `--as`。
|
|
176
|
+
if (positional.length > 0) {
|
|
177
|
+
return {
|
|
178
|
+
error: `${command} takes no positional arguments; use --aid <target-aid> --type <services.type> `
|
|
179
|
+
+ `(and --as <sender-aid> only when no session identity is available). Got: ${positional.join(' ')}`,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
}
|
|
148
183
|
else {
|
|
149
184
|
parsed.pack = positional[0];
|
|
150
185
|
}
|
|
151
|
-
//
|
|
152
|
-
if (parsed.type === undefined)
|
|
186
|
+
// 包名类命令(status / ledger / tail / doctor)仍用位置参数指包。
|
|
187
|
+
if (parsed.type === undefined && !['call', 'describe', 'schema'].includes(command)) {
|
|
153
188
|
parsed.type = positional[1];
|
|
189
|
+
}
|
|
154
190
|
return parsed;
|
|
155
191
|
}
|
|
156
192
|
/** `--timeout 30` / `30s` / `2m` / `500ms` → 毫秒。 */
|
|
157
193
|
/** 只用于比较两个 AID 是否同一主体:去 `@` 前缀并忽略大小写。 */
|
|
194
|
+
/** 去掉展示用的 `@` 前缀与首尾空白;AID 本身不带 `@`。 */
|
|
195
|
+
function stripAidPrefix(value) {
|
|
196
|
+
const aid = String(value ?? '').trim();
|
|
197
|
+
if (!aid)
|
|
198
|
+
return undefined;
|
|
199
|
+
return aid.startsWith('@') ? aid.slice(1) : aid;
|
|
200
|
+
}
|
|
158
201
|
function normalizeAid(value) {
|
|
159
202
|
const aid = String(value ?? '').trim();
|
|
160
203
|
return (aid.startsWith('@') ? aid.slice(1) : aid).toLowerCase();
|
|
@@ -241,6 +284,32 @@ async function execute(deps, parsed) {
|
|
|
241
284
|
const { command } = parsed;
|
|
242
285
|
if (command === 'help')
|
|
243
286
|
return { ok: true, result: { help: HELP } };
|
|
287
|
+
// 对端调用单独走:目标是**远端**,本机不为它解析 router。
|
|
288
|
+
// 发送身份 = `--as` > 托管会话身份 > 缺省 AID。
|
|
289
|
+
if (command === 'call' || command === 'describe' || command === 'schema') {
|
|
290
|
+
const targetAid = parsed.aid;
|
|
291
|
+
if (!targetAid) {
|
|
292
|
+
return { ok: false, code: 'INVALID_ARGV', error: `${command} requires --aid <target-aid>` };
|
|
293
|
+
}
|
|
294
|
+
const sender = stripAidPrefix(parsed.as ?? parsed.caller?.selfAid ?? deps.defaultAid?.());
|
|
295
|
+
if (!sender) {
|
|
296
|
+
return {
|
|
297
|
+
ok: false,
|
|
298
|
+
code: 'SENDER_REQUIRED',
|
|
299
|
+
error: `${command} needs a sender identity: pass --as <aid> (a managed session supplies it automatically)`,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
const callParsed = { ...parsed, pack: targetAid };
|
|
303
|
+
const auth = authorizePackTarget({
|
|
304
|
+
caller: parsed.caller ?? { kind: 'local-control' },
|
|
305
|
+
targetAid,
|
|
306
|
+
...(deps.daemonAid?.() ? { daemonAid: deps.daemonAid() } : {}),
|
|
307
|
+
operation: packOperation('services', command, parsed.action),
|
|
308
|
+
});
|
|
309
|
+
if (!auth.allowed)
|
|
310
|
+
return { ok: false, code: auth.code, error: auth.error };
|
|
311
|
+
return await runCall(deps, sender, callParsed);
|
|
312
|
+
}
|
|
244
313
|
const target = resolveAid(deps, parsed);
|
|
245
314
|
if (target.error)
|
|
246
315
|
return target.error;
|
|
@@ -260,10 +329,6 @@ async function execute(deps, parsed) {
|
|
|
260
329
|
const snapshot = router.snapshot();
|
|
261
330
|
const servicesDir = agentServicesDir(aid);
|
|
262
331
|
switch (command) {
|
|
263
|
-
case 'call':
|
|
264
|
-
case 'describe':
|
|
265
|
-
case 'schema':
|
|
266
|
-
return await runCall(deps, aid, parsed);
|
|
267
332
|
case 'rules:show': {
|
|
268
333
|
const config = new ServiceRulesStore(servicesDir).read();
|
|
269
334
|
const entries = parsed.type
|
|
@@ -323,6 +388,8 @@ async function execute(deps, parsed) {
|
|
|
323
388
|
enabled: snapshot.enabled,
|
|
324
389
|
identity: snapshot.identity,
|
|
325
390
|
routerErrors: snapshot.routerErrors,
|
|
391
|
+
// 宿主运行时:`enabled:false` = 总闸关着;`enabled:true,running:false` = 尚未被调用。
|
|
392
|
+
host: peekServiceRouter(aid)?.hostStatus() ?? { enabled: false },
|
|
326
393
|
packs: snapshot.packs.activePacks.map(pack => statusForPack(snapshot, pack.id)),
|
|
327
394
|
skipped: snapshot.packs.skippedPacks,
|
|
328
395
|
disabled: snapshot.packs.disabledPacks,
|
|
@@ -355,6 +422,23 @@ async function execute(deps, parsed) {
|
|
|
355
422
|
}
|
|
356
423
|
case 'doctor':
|
|
357
424
|
return { ok: true, result: { aid, findings: doctor(aid, router, parsed.pack) } };
|
|
425
|
+
case 'repair-acl': {
|
|
426
|
+
// 幂等收口:历史包(装包时还没有加固逻辑)靠这条命令补齐。
|
|
427
|
+
// 加固只改 ACL、不碰文件内容,失败也只报告不抛出。
|
|
428
|
+
const result = hardenServicesAcl(servicesDir);
|
|
429
|
+
return {
|
|
430
|
+
ok: result.errors.length === 0,
|
|
431
|
+
...(result.errors.length > 0 ? { code: 'ACL_HARDEN_FAILED', error: result.errors.join('; ') } : {}),
|
|
432
|
+
result: {
|
|
433
|
+
aid,
|
|
434
|
+
servicesDir,
|
|
435
|
+
changed: result.changed,
|
|
436
|
+
plans: result.plans
|
|
437
|
+
.filter(item => item.plan.removeSids.length > 0 || item.plan.needsDenyWrite)
|
|
438
|
+
.map(item => ({ path: item.path, removeSids: item.plan.removeSids, addDenyWrite: item.plan.needsDenyWrite })),
|
|
439
|
+
},
|
|
440
|
+
};
|
|
441
|
+
}
|
|
358
442
|
case 'reload': {
|
|
359
443
|
// 不支持单包重载:`reload()` 全量重扫。曾把位置参数原样回显成
|
|
360
444
|
// `reloaded: <包名>`,等于向调用方谎报"只重载了一个包"。
|
|
@@ -371,6 +455,9 @@ async function execute(deps, parsed) {
|
|
|
371
455
|
case 'enable':
|
|
372
456
|
case 'disable':
|
|
373
457
|
return setRouterEnabled(aid, command === 'enable');
|
|
458
|
+
case 'host:enable':
|
|
459
|
+
case 'host:disable':
|
|
460
|
+
return setHostEnabled(aid, command === 'host:enable');
|
|
374
461
|
case 'pack': {
|
|
375
462
|
const servicesDirForPack = agentServicesDir(aid);
|
|
376
463
|
if (parsed.action === 'list') {
|
|
@@ -408,12 +495,19 @@ async function execute(deps, parsed) {
|
|
|
408
495
|
// 配置存在但坏了:装包成功、总闸却回落到 enabled=false,业务消息全被静默丢弃。
|
|
409
496
|
// 不替用户改文件,但必须把原因带回去。
|
|
410
497
|
const configErrors = createdRouter ? [] : loadRouterConfig(servicesDirForPack).errors;
|
|
498
|
+
// ACL 加固:新包目录与 services 根都要收口。失败不阻断安装——包已经 rename
|
|
499
|
+
// 到位,加固只是加一层兜底;把原因带回去,`doctor` 也会持续报。
|
|
500
|
+
const acl = hardenServicesAcl(servicesDirForPack);
|
|
501
|
+
if (acl.errors.length > 0) {
|
|
502
|
+
logger.warn(`[Services] services ACL hardening failed for aid=${aid}: ${acl.errors.join('; ')}`);
|
|
503
|
+
}
|
|
411
504
|
return {
|
|
412
505
|
ok: true,
|
|
413
506
|
result: {
|
|
414
507
|
aid, ...installed,
|
|
415
508
|
...(createdRouter ? { createdRouter: true } : {}),
|
|
416
509
|
...(configErrors.length > 0 ? { configErrors } : {}),
|
|
510
|
+
...(acl.errors.length > 0 ? { aclErrors: acl.errors } : {}),
|
|
417
511
|
},
|
|
418
512
|
};
|
|
419
513
|
}
|
|
@@ -462,16 +556,11 @@ ${HELP}` };
|
|
|
462
556
|
* 因此 CLI 中途被杀也不丢结果。
|
|
463
557
|
*/
|
|
464
558
|
async function runCall(deps, selfAid, parsed) {
|
|
465
|
-
//
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
if (!record)
|
|
469
|
-
return { ok: false, code: 'REQUEST_NOT_FOUND', error: `no request ${parsed.requestId}` };
|
|
470
|
-
return { ok: true, result: summarizeRecord(record) };
|
|
471
|
-
}
|
|
472
|
-
const targetAid = parsed.pack;
|
|
559
|
+
// `@` 前缀只是展示习惯(名片里那样写),AID 本身不带。不在这里剥掉就会原样
|
|
560
|
+
// 交给消息层,被 AID 校验拒成 "must be 4-64 characters"。
|
|
561
|
+
const targetAid = stripAidPrefix(parsed.pack);
|
|
473
562
|
if (!targetAid)
|
|
474
|
-
return { ok: false, code: 'INVALID_ARGV', error: `${parsed.command} requires <aid>` };
|
|
563
|
+
return { ok: false, code: 'INVALID_ARGV', error: `${parsed.command} requires --aid <target-aid>` };
|
|
475
564
|
// 调自己:消息会发出去,但入站侧没有任何分支会应答它,只能干等满超时(默认 30s)
|
|
476
565
|
// 然后报一个看起来像对端故障的 NO_RESULT。前置拒绝,别让人等。
|
|
477
566
|
if (normalizeAid(targetAid) === normalizeAid(selfAid)) {
|
|
@@ -496,14 +585,17 @@ async function runCall(deps, selfAid, parsed) {
|
|
|
496
585
|
: parsed.type
|
|
497
586
|
? { service: parsed.type }
|
|
498
587
|
: {};
|
|
499
|
-
const timeoutMs = parsed.timeoutMs ??
|
|
588
|
+
const timeoutMs = parsed.timeoutMs ?? SERVICE_CALL_TIMEOUT_MS;
|
|
589
|
+
// TTL 必须由本次等待时长推导:消息在网关活多久,调用方就等多久。多一秒都是
|
|
590
|
+
// 给"对端稍后上线还能捡到这条请求"留口子,那正是这套设计要去掉的补投语义。
|
|
591
|
+
const ttl = Math.max(1, Math.ceil(timeoutMs / 1_000));
|
|
500
592
|
const registry = getAunRequestRegistry();
|
|
501
593
|
let prepared;
|
|
502
594
|
try {
|
|
503
595
|
prepared = registry.prepare({
|
|
504
596
|
selfAid,
|
|
505
597
|
targetAid,
|
|
506
|
-
payload: { type: requestType, ...data },
|
|
598
|
+
payload: { type: requestType, ...data, service_deadline_at_ms: Date.now() + timeoutMs },
|
|
507
599
|
timeoutMs,
|
|
508
600
|
});
|
|
509
601
|
}
|
|
@@ -514,6 +606,9 @@ async function runCall(deps, selfAid, parsed) {
|
|
|
514
606
|
const sent = await channel.sendDaemonMsg({
|
|
515
607
|
to: targetAid,
|
|
516
608
|
payload: prepared.payload,
|
|
609
|
+
// volatile:只存在消息服务内存里,不落库、不分配持久 seq。对端离线时这条
|
|
610
|
+
// 请求在 TTL 到期后消失,重连也拉不到——服务调用是 RPC,不是离线信箱。
|
|
611
|
+
ttl,
|
|
517
612
|
...(parsed.encrypted !== undefined ? { encrypt: parsed.encrypted } : {}),
|
|
518
613
|
service: { type: requestType, requestId: prepared.requestId },
|
|
519
614
|
});
|
|
@@ -528,25 +623,25 @@ async function runCall(deps, selfAid, parsed) {
|
|
|
528
623
|
}
|
|
529
624
|
if (sent.message_id)
|
|
530
625
|
registry.markTransportAccepted(selfAid, prepared.requestId, sent.message_id, sent.status);
|
|
531
|
-
if (parsed.noWait) {
|
|
532
|
-
return { ok: true, result: { request_id: prepared.requestId, message_id: sent.message_id, state: 'pending' } };
|
|
533
|
-
}
|
|
534
626
|
const record = await registry.wait(selfAid, prepared.requestId, timeoutMs);
|
|
535
627
|
if (!record) {
|
|
536
628
|
return { ok: false, code: 'NO_RESULT', error: 'request record disappeared', result: { request_id: prepared.requestId } };
|
|
537
629
|
}
|
|
538
|
-
const summary = summarizeRecord(record);
|
|
539
630
|
if (record.state === 'completed' && record.responsePayload) {
|
|
540
|
-
return { ok: true, result: { ...
|
|
631
|
+
return { ok: true, result: { ...summarizeRecord(record), response: record.responsePayload } };
|
|
541
632
|
}
|
|
542
633
|
if (record.state === 'failed') {
|
|
543
|
-
return { ok: false, code: 'REQUEST_FAILED', error: `request ${prepared.requestId} failed`, result:
|
|
634
|
+
return { ok: false, code: 'REQUEST_FAILED', error: `request ${prepared.requestId} failed`, result: summarizeRecord(record) };
|
|
544
635
|
}
|
|
636
|
+
// 等到超时:把记录钉成终态,迟到的应答再也改不动它(resolveIncoming 只接受
|
|
637
|
+
// 非终态记录)。`wait()` 自己只会落到 pending —— 那是 `ec msg send` 需要的
|
|
638
|
+
// "稍后还能补上"的语义,服务调用不需要。
|
|
639
|
+
const expired = registry.markFailed(selfAid, prepared.requestId, 'no response before deadline') ?? record;
|
|
545
640
|
return {
|
|
546
641
|
ok: false,
|
|
547
642
|
code: 'NO_RESULT',
|
|
548
|
-
error: `no
|
|
549
|
-
result:
|
|
643
|
+
error: `no response within ${Math.round(timeoutMs / 1_000)}s; the request expires with it (request_id=${prepared.requestId})`,
|
|
644
|
+
result: summarizeRecord(expired),
|
|
550
645
|
};
|
|
551
646
|
}
|
|
552
647
|
function summarizeRecord(record) {
|
|
@@ -566,6 +661,18 @@ function statusForPack(snapshot, packId) {
|
|
|
566
661
|
name: pack.name,
|
|
567
662
|
status: 'active',
|
|
568
663
|
listens: pack.listen.map(entry => entry.type),
|
|
664
|
+
/**
|
|
665
|
+
* 每个 type 的执行形态。
|
|
666
|
+
*
|
|
667
|
+
* 单独列出来是因为「声明了 resident」和「实际跑在 resident」是两件事:
|
|
668
|
+
* `host.enabled=false` 时前者为真、后者为假。没有这个字段,运维只能靠
|
|
669
|
+
* 全局 host 段去推,而那是 agent 级、不是 handler 级。
|
|
670
|
+
*/
|
|
671
|
+
handlers: pack.listen.map(entry => ({
|
|
672
|
+
type: entry.type,
|
|
673
|
+
mode: entry.handler.mode ?? 'spawn',
|
|
674
|
+
...(entry.handler.resident ? { resident: entry.handler.resident } : {}),
|
|
675
|
+
})),
|
|
569
676
|
unmatched: pack.unmatched,
|
|
570
677
|
replyAllowed: pack.reply.allowed,
|
|
571
678
|
revision: pack.revision,
|
|
@@ -597,6 +704,8 @@ function doctor(aid, router, only) {
|
|
|
597
704
|
const packs = only
|
|
598
705
|
? snapshot.packs.activePacks.filter(pack => pack.id === only)
|
|
599
706
|
: snapshot.packs.activePacks;
|
|
707
|
+
// 宿主总闸:`mode:"resident"` 只有它开着才有稳态收益,否则退化成每调用一进程。
|
|
708
|
+
const hostEnabled = snapshot.config.host?.enabled === true;
|
|
600
709
|
for (const pack of packs) {
|
|
601
710
|
// 1. requires 与名片不符(对被过滤掉的包在 skipped 里单独报)。
|
|
602
711
|
findings.push({ level: 'ok', check: `${pack.id}.requires`, detail: `satisfied by ${snapshot.identity.type}/${snapshot.identity.exttype || '-'}` });
|
|
@@ -610,6 +719,17 @@ function doctor(aid, router, only) {
|
|
|
610
719
|
});
|
|
611
720
|
}
|
|
612
721
|
}
|
|
722
|
+
// 3. 常驻形态但宿主没开:**不是错误**(会降级成每调用一进程),但必须让人知道
|
|
723
|
+
// 这条路径付的是每次启动的价钱,拿不到常驻的稳态收益。
|
|
724
|
+
const residentHandlers = pack.listen.filter(entry => entry.handler.mode === 'resident');
|
|
725
|
+
if (residentHandlers.length > 0 && !hostEnabled) {
|
|
726
|
+
findings.push({
|
|
727
|
+
level: 'warn',
|
|
728
|
+
check: `${pack.id}.handler.mode`,
|
|
729
|
+
detail: `${residentHandlers.length} handler(s) declare mode=resident but services-config.json host.enabled is not true; `
|
|
730
|
+
+ 'they run one process per call (same cost as mode=spawn)',
|
|
731
|
+
});
|
|
732
|
+
}
|
|
613
733
|
}
|
|
614
734
|
// 5. type=services 但无激活包。
|
|
615
735
|
//
|
|
@@ -642,8 +762,66 @@ function doctor(aid, router, only) {
|
|
|
642
762
|
}
|
|
643
763
|
// 6. services/ 未进 L_CLASS(由 protected-paths 的运行时常量核对)。
|
|
644
764
|
findings.push(lClassFinding());
|
|
765
|
+
// 7. ACL 兜底层:沙箱组不得对包代码与声明持有写权限。
|
|
766
|
+
findings.push(servicesAclFinding(aid, only));
|
|
645
767
|
return findings;
|
|
646
768
|
}
|
|
769
|
+
/**
|
|
770
|
+
* `services/` 的 ACL 兜底层是否生效。
|
|
771
|
+
*
|
|
772
|
+
* policy 层的写拒绝来自「没有 write 授权」,只有这一层时任何一个策略放宽都会直接
|
|
773
|
+
* 让包脚本能自改代码。这里报告的是**ACL 层有没有第二道门**:
|
|
774
|
+
* - 存在非继承的写授权(沙箱组 / 外来机器 SID)→ `warn`,给出修复命令;
|
|
775
|
+
* - 缺少 DENY(写) 兜底 → `warn`;
|
|
776
|
+
* - 非 Windows 或本机没有沙箱组 → `ok` + 说明(没有可加固对象)。
|
|
777
|
+
*/
|
|
778
|
+
function servicesAclFinding(aid, only) {
|
|
779
|
+
if (process.platform !== 'win32') {
|
|
780
|
+
return { level: 'ok', check: 'acl', detail: 'not applicable on this platform (Windows-only hardening)' };
|
|
781
|
+
}
|
|
782
|
+
const servicesDir = agentServicesDir(aid);
|
|
783
|
+
let snapshot;
|
|
784
|
+
try {
|
|
785
|
+
snapshot = readServicesAcl(servicesDir);
|
|
786
|
+
}
|
|
787
|
+
catch (error) {
|
|
788
|
+
return { level: 'warn', check: 'acl', detail: `cannot read ACL: ${errorMessage(error)}` };
|
|
789
|
+
}
|
|
790
|
+
if (!snapshot.sandboxSid) {
|
|
791
|
+
return { level: 'ok', check: 'acl', detail: 'CodexSandboxUsers group not present; sandbox scripts cannot run as a sandbox identity' };
|
|
792
|
+
}
|
|
793
|
+
const rows = snapshot.entries
|
|
794
|
+
.filter(entry => !only || sameAsPackDir(entry.path, servicesDir, only))
|
|
795
|
+
.map(entry => ({ path: entry.path, plan: planServicesAclRepair(entry.aces, snapshot) }));
|
|
796
|
+
const violations = rows.flatMap(row => row.plan.violations.map(detail => `${relativeTo(servicesDir, row.path)}: ${detail}`));
|
|
797
|
+
const missingDeny = rows.filter(row => row.plan.needsDenyWrite && samePathWith(row.path, servicesDir));
|
|
798
|
+
if (violations.length === 0 && missingDeny.length === 0) {
|
|
799
|
+
return { level: 'ok', check: 'acl', detail: 'no explicit write grant for the sandbox group; DENY(write) in place' };
|
|
800
|
+
}
|
|
801
|
+
const parts = [];
|
|
802
|
+
if (violations.length > 0)
|
|
803
|
+
parts.push(`explicit write grants: ${violations.slice(0, 5).join('; ')}${violations.length > 5 ? ` (+${violations.length - 5} more)` : ''}`);
|
|
804
|
+
if (missingDeny.length > 0)
|
|
805
|
+
parts.push('services root lacks an inheritable DENY(write) for the sandbox group');
|
|
806
|
+
return {
|
|
807
|
+
level: 'warn',
|
|
808
|
+
check: 'acl',
|
|
809
|
+
detail: `${parts.join(' / ')}. Run "ec services repair-acl${only ? '' : ` --aid ${aid}`}" to harden.`,
|
|
810
|
+
};
|
|
811
|
+
}
|
|
812
|
+
/** `packDir` 是否是 `servicesDir/<only>` 自身或其子路径。 */
|
|
813
|
+
function sameAsPackDir(candidate, servicesDir, pack) {
|
|
814
|
+
const base = path.join(servicesDir, pack).toLowerCase();
|
|
815
|
+
const value = path.resolve(candidate).toLowerCase();
|
|
816
|
+
return value === base || value.startsWith(`${base}${path.sep}`);
|
|
817
|
+
}
|
|
818
|
+
function samePathWith(left, right) {
|
|
819
|
+
return path.resolve(left).toLowerCase() === path.resolve(right).toLowerCase();
|
|
820
|
+
}
|
|
821
|
+
function relativeTo(base, target) {
|
|
822
|
+
const relative = path.relative(path.resolve(base), path.resolve(target));
|
|
823
|
+
return relative || '.';
|
|
824
|
+
}
|
|
647
825
|
/** 运行期核对 L_CLASS 是否覆盖每个 agent 的 services 目录。 */
|
|
648
826
|
function lClassFinding() {
|
|
649
827
|
try {
|
|
@@ -657,16 +835,39 @@ function lClassFinding() {
|
|
|
657
835
|
return { level: 'warn', check: 'l-class', detail: `cannot verify: ${errorMessage(error)}` };
|
|
658
836
|
}
|
|
659
837
|
}
|
|
660
|
-
/**
|
|
661
|
-
|
|
662
|
-
|
|
838
|
+
/**
|
|
839
|
+
* 读 services-config.json 原始对象作为改写底稿。
|
|
840
|
+
*
|
|
841
|
+
* 不能用 `loadRouterConfig().config` 写回:那是校验后的规范形态,会丢掉未知字段、
|
|
842
|
+
* 把缺省值具体化。用户手写的文件要按原样保留,只动目标字段。
|
|
843
|
+
*/
|
|
844
|
+
function readConfigForWrite(servicesDir) {
|
|
663
845
|
const filePath = path.join(servicesDir, SERVICES_CONFIG_JSON);
|
|
664
846
|
const loaded = loadRouterConfig(servicesDir);
|
|
665
|
-
|
|
666
|
-
|
|
847
|
+
let parsed;
|
|
848
|
+
if (loaded.exists) {
|
|
849
|
+
try {
|
|
850
|
+
parsed = JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
851
|
+
}
|
|
852
|
+
catch (error) {
|
|
853
|
+
// 文件在但读不懂:拒绝改写。覆盖掉等于替用户销毁他手写的内容。
|
|
854
|
+
return { failure: { ok: false, code: 'ROUTER_INVALID', error: `cannot rewrite unreadable ${SERVICES_CONFIG_JSON}: ${errorMessage(error)}` } };
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
const base = parsed && typeof parsed === 'object' && !Array.isArray(parsed)
|
|
858
|
+
? parsed
|
|
667
859
|
: { v: 1, rateLimit: { builtin: { perMinute: 20, perHour: 200 }, service: { perMinute: 50, perHour: 1000 } } };
|
|
668
860
|
if (base.v !== 1)
|
|
669
861
|
base.v = 1;
|
|
862
|
+
return { base, filePath };
|
|
863
|
+
}
|
|
864
|
+
/** enable / disable 只改 services-config.json 的 enabled 字段;v 与其他字段原样保留。 */
|
|
865
|
+
function setRouterEnabled(aid, enabled) {
|
|
866
|
+
const servicesDir = agentServicesDir(aid);
|
|
867
|
+
const read = readConfigForWrite(servicesDir);
|
|
868
|
+
if ('failure' in read)
|
|
869
|
+
return read.failure;
|
|
870
|
+
const { base, filePath } = read;
|
|
670
871
|
base.enabled = enabled;
|
|
671
872
|
try {
|
|
672
873
|
fs.mkdirSync(servicesDir, { recursive: true });
|
|
@@ -680,4 +881,47 @@ function setRouterEnabled(aid, enabled) {
|
|
|
680
881
|
live.reload();
|
|
681
882
|
return { ok: true, result: { aid, enabled, path: filePath } };
|
|
682
883
|
}
|
|
884
|
+
/**
|
|
885
|
+
* `host enable` / `host disable`:改写 `services-config.json` 的 `host.enabled`。
|
|
886
|
+
*
|
|
887
|
+
* 与 `setRouterEnabled` 分开是因为两者作用域不同:`enabled` 是整条服务路由的总闸
|
|
888
|
+
* (关了对外不接活),`host.enabled` 只决定脚本以什么形态执行(常驻宿主 vs 一次性
|
|
889
|
+
* spawn)。混成一个命令会让"我只想退回一次性路径"变成"我的服务全停"。
|
|
890
|
+
*
|
|
891
|
+
* 写入后必须 `reload()`:`ServiceRouter.reload()` 里的 `syncHostRuntime()` 才是
|
|
892
|
+
* 挂载/摘除宿主的唯一入口,光写文件不重读不会生效。
|
|
893
|
+
*/
|
|
894
|
+
function setHostEnabled(aid, enabled) {
|
|
895
|
+
const servicesDir = agentServicesDir(aid);
|
|
896
|
+
const applied = applyHostEnabled(servicesDir, enabled);
|
|
897
|
+
if ('failure' in applied)
|
|
898
|
+
return applied.failure;
|
|
899
|
+
const live = peekServiceRouter(aid);
|
|
900
|
+
if (live)
|
|
901
|
+
live.reload();
|
|
902
|
+
return { ok: true, result: { aid, host: { enabled }, path: applied.written } };
|
|
903
|
+
}
|
|
904
|
+
/**
|
|
905
|
+
* 只写文件、不 reload。导出是为了让测试直接打靶:`setHostEnabled` 走
|
|
906
|
+
* `agentServicesDir()`,测试里没法把路径指到临时目录。
|
|
907
|
+
*/
|
|
908
|
+
export function applyHostEnabled(servicesDir, enabled) {
|
|
909
|
+
const read = readConfigForWrite(servicesDir);
|
|
910
|
+
if ('failure' in read)
|
|
911
|
+
return { failure: read.failure };
|
|
912
|
+
const { base, filePath } = read;
|
|
913
|
+
const rawHost = base.host;
|
|
914
|
+
const current = rawHost && typeof rawHost === 'object' && !Array.isArray(rawHost)
|
|
915
|
+
? rawHost
|
|
916
|
+
: {};
|
|
917
|
+
base.host = { ...current, enabled };
|
|
918
|
+
try {
|
|
919
|
+
fs.mkdirSync(servicesDir, { recursive: true });
|
|
920
|
+
fs.writeFileSync(filePath, `${JSON.stringify(base, null, 2)}\n`, 'utf8');
|
|
921
|
+
}
|
|
922
|
+
catch (error) {
|
|
923
|
+
return { failure: { ok: false, code: 'ROUTER_WRITE_FAILED', error: errorMessage(error) } };
|
|
924
|
+
}
|
|
925
|
+
return { written: filePath };
|
|
926
|
+
}
|
|
683
927
|
export { HELP as SERVICES_HELP };
|
|
@@ -161,6 +161,7 @@ export function buildPackState(packs, invalidPacks, identity) {
|
|
|
161
161
|
for (const pack of candidates) {
|
|
162
162
|
const reserved = pack.listen.filter(entry => entry.type === 'services.outputs.snapshot' || entry.type === 'services.outputs.list'
|
|
163
163
|
|| entry.type === 'services.outputs.detail' || entry.type === 'services.outputs.changes'
|
|
164
|
+
|| entry.type.startsWith('services.outputs.cards.')
|
|
164
165
|
|| entry.type === 'services.outputs.*' || entry.type.startsWith('services.workbench.'));
|
|
165
166
|
if (reserved.length) {
|
|
166
167
|
reservedOutputInvalid.push({
|