evolcore 0.0.49 → 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 +64 -1
- 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 +280 -6
- 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 +4 -1
- 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 +29 -1
- package/dist/aun/msg/upload.js +126 -3
- package/dist/build-identity.json +1 -1
- package/dist/channels/aun.js +537 -189
- 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/ecmsg-gateway.js +11 -9
- package/dist/cli/index.js +23 -4
- package/dist/cli/init.js +39 -63
- package/dist/cli/managed-command-guard.js +1 -0
- package/dist/cli/menu-client.js +32 -7
- package/dist/cli/pay-command.js +30 -0
- package/dist/cli/provider-command.js +6 -2
- package/dist/cli/restart-monitor.js +2 -2
- package/dist/cli/services-command.js +11 -9
- package/dist/cli/thread-command.js +78 -12
- package/dist/config/access-policy.js +16 -3
- package/dist/config/config-field-policy.js +17 -8
- package/dist/config/config-manager.js +86 -46
- 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 +99 -16
- package/dist/config/providers-management.js +35 -19
- package/dist/config/resolved-config-op.js +1 -42
- 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/operation-authorizer.js +16 -1
- package/dist/core/auth/operation-catalog.js +50 -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 +15 -0
- 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 +91 -72
- package/dist/core/command/menu-protocol.js +5 -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/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 +2 -1
- package/dist/core/daemon-lifecycle.js +13 -5
- package/dist/core/evolagent-registry.js +12 -7
- 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 +4 -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 +98 -21
- package/dist/core/message/aun-request-registry.js +31 -0
- package/dist/core/message/message-bridge.js +105 -6
- package/dist/core/message/message-log.js +8 -0
- package/dist/core/message/message-queue.js +5 -3
- package/dist/core/message/peer-mode.js +15 -4
- package/dist/core/message/response-engine.js +23 -8
- package/dist/core/message/send-options.js +37 -3
- package/dist/core/message/send-routing.js +11 -7
- package/dist/core/model/model-catalog.js +5 -5
- package/dist/core/ownership/owner-resolver.js +12 -86
- package/dist/core/pack-auth.js +4 -0
- package/dist/core/permission/ec-command-parser.js +182 -58
- package/dist/core/permission/protected-paths.js +64 -9
- package/dist/core/permission/services-path-acl.js +9 -2
- package/dist/core/permission/tool-policy.js +21 -9
- 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/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 +52 -2
- package/dist/core/thread/types.js +15 -1
- package/dist/eck/kit-renderer.js +2 -1
- package/dist/ecweb/basic-settings-service.js +5 -9
- package/dist/ecweb/providers-service.js +4 -2
- package/dist/index.js +116 -41
- package/dist/ipc.js +58 -2
- 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 +176 -18
- package/dist/services/ipc-operation.js +204 -44
- package/dist/services/script-runner.js +515 -83
- package/dist/services/validation.js +109 -4
- 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 -20
- package/dist/utils/aid-bind.js +3 -0
- package/dist/utils/evolcore-version.js +2 -2
- package/dist/utils/host-info.js +73 -0
- package/dist/utils/logger.js +2 -2
- package/dist/utils/media-cache.js +190 -43
- 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/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 +7 -6
- package/kits/docs/evolcore/agent.md +36 -1
- package/kits/docs/evolcore/aid.md +20 -3
- package/kits/docs/evolcore/config.md +1 -1
- 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 +68 -10
- package/kits/docs/evolcore/pay.md +34 -0
- package/kits/docs/evolcore/provider.md +21 -0
- package/kits/docs/evolcore/services.md +46 -18
- package/kits/docs/evolcore/thread-chain.md +2 -0
- package/kits/docs/evolcore/tool-authorization.md +10 -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.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 +13 -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 +12 -5
- 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 +1 -1
- 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/system-fragments/channel.md +13 -4
- package/kits/templates/system-fragments/commands.md +4 -3
- 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 -129
- package/kits/templates/system-fragments/venue.md +16 -0
- package/package.json +4 -5
- package/scripts/agent-template/inspect.mjs +37 -23
- package/scripts/agent-template/overlay.mjs +20 -2
- package/scripts/agent-template/shared/common.mjs +16 -4
- package/scripts/agent-template/shared/team-schema.json +20 -4
- package/scripts/agent-template/shared/template-contract.mjs +53 -13
- package/scripts/agent-template/shared/template-package.mjs +90 -26
- package/scripts/agent-template/shared/template-runtime.mjs +111 -1
- package/scripts/agent-template/shared/template.mjs +65 -7
- package/scripts/agent-template/team-pack.mjs +89 -33
- 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
|
@@ -24,6 +24,15 @@ 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
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);
|
|
27
36
|
const HELP = `ec services — 服务路由运维
|
|
28
37
|
|
|
29
38
|
用法:
|
|
@@ -35,6 +44,7 @@ const HELP = `ec services — 服务路由运维
|
|
|
35
44
|
ec services repair-acl [--aid <aid>] 收紧 services/ 的 NTFS ACL(幂等,仅 Windows)
|
|
36
45
|
ec services reload [--aid <aid>] 重载(全部包)
|
|
37
46
|
ec services enable / disable [--aid <aid>] 总闸
|
|
47
|
+
ec services host enable / disable [--aid <aid>] 宿主模式(常驻执行形态)
|
|
38
48
|
ec services rules show [<type>] [--aid <aid>] 调用准入规则
|
|
39
49
|
ec services rules add <type> <aid...> [--deny] [--aid <aid>]
|
|
40
50
|
ec services rules remove <type> <aid...> [--deny] [--aid <aid>]
|
|
@@ -48,10 +58,10 @@ const HELP = `ec services — 服务路由运维
|
|
|
48
58
|
remove 默认把日志与台账归档到 <包>/logs/archive-<时间戳>/;--purge 连归档一起删。
|
|
49
59
|
ec services pack list [--aid <aid>]
|
|
50
60
|
|
|
51
|
-
|
|
52
|
-
ec services describe
|
|
53
|
-
ec services schema
|
|
54
|
-
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]`;
|
|
55
65
|
export function parseServicesArgv(argv) {
|
|
56
66
|
const args = [...argv];
|
|
57
67
|
if (args.length === 0 || args[0] === 'help' || args[0] === '--help')
|
|
@@ -91,8 +101,8 @@ export function parseServicesArgv(argv) {
|
|
|
91
101
|
const timeoutRaw = consumeValue('--timeout');
|
|
92
102
|
if (timeoutRaw !== undefined) {
|
|
93
103
|
const timeoutMs = parseTimeoutMs(timeoutRaw);
|
|
94
|
-
if (timeoutMs === undefined)
|
|
95
|
-
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}` };
|
|
96
106
|
parsed.timeoutMs = timeoutMs;
|
|
97
107
|
}
|
|
98
108
|
const dataRaw = consumeValue('--data');
|
|
@@ -108,21 +118,22 @@ export function parseServicesArgv(argv) {
|
|
|
108
118
|
return { error: `--data is not valid JSON: ${error instanceof Error ? error.message : String(error)}` };
|
|
109
119
|
}
|
|
110
120
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
121
|
+
// `--type <type>` 是主名字;`--service` 作为历史别名保留(老脚本/文档在用)。
|
|
122
|
+
const typeFlag = consumeValue('--type');
|
|
123
|
+
if (typeFlag !== undefined)
|
|
124
|
+
parsed.type = typeFlag;
|
|
115
125
|
const serviceFlag = consumeValue('--service');
|
|
116
126
|
if (serviceFlag !== undefined)
|
|
117
127
|
parsed.type = serviceFlag;
|
|
128
|
+
// 对端调用的发送身份。与 `--aid`(被调用方)分开:同一个 flag 不能在不同子命令里
|
|
129
|
+
// 换含义,那会让"我到底在指谁"只能靠记忆。
|
|
130
|
+
const asFlag = consumeValue('--as');
|
|
131
|
+
if (asFlag !== undefined)
|
|
132
|
+
parsed.as = asFlag;
|
|
118
133
|
if (args.includes('--encrypted')) {
|
|
119
134
|
parsed.encrypted = true;
|
|
120
135
|
args.splice(args.indexOf('--encrypted'), 1);
|
|
121
136
|
}
|
|
122
|
-
if (args.includes('--no-wait')) {
|
|
123
|
-
parsed.noWait = true;
|
|
124
|
-
args.splice(args.indexOf('--no-wait'), 1);
|
|
125
|
-
}
|
|
126
137
|
parsed.from = consumeValue('--from');
|
|
127
138
|
if (args.includes('--purge')) {
|
|
128
139
|
parsed.purge = true;
|
|
@@ -147,16 +158,46 @@ export function parseServicesArgv(argv) {
|
|
|
147
158
|
parsed.type = positional[1];
|
|
148
159
|
parsed.aids = positional.slice(2);
|
|
149
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
|
+
}
|
|
150
183
|
else {
|
|
151
184
|
parsed.pack = positional[0];
|
|
152
185
|
}
|
|
153
|
-
//
|
|
154
|
-
if (parsed.type === undefined)
|
|
186
|
+
// 包名类命令(status / ledger / tail / doctor)仍用位置参数指包。
|
|
187
|
+
if (parsed.type === undefined && !['call', 'describe', 'schema'].includes(command)) {
|
|
155
188
|
parsed.type = positional[1];
|
|
189
|
+
}
|
|
156
190
|
return parsed;
|
|
157
191
|
}
|
|
158
192
|
/** `--timeout 30` / `30s` / `2m` / `500ms` → 毫秒。 */
|
|
159
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
|
+
}
|
|
160
201
|
function normalizeAid(value) {
|
|
161
202
|
const aid = String(value ?? '').trim();
|
|
162
203
|
return (aid.startsWith('@') ? aid.slice(1) : aid).toLowerCase();
|
|
@@ -243,6 +284,32 @@ async function execute(deps, parsed) {
|
|
|
243
284
|
const { command } = parsed;
|
|
244
285
|
if (command === 'help')
|
|
245
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
|
+
}
|
|
246
313
|
const target = resolveAid(deps, parsed);
|
|
247
314
|
if (target.error)
|
|
248
315
|
return target.error;
|
|
@@ -262,10 +329,6 @@ async function execute(deps, parsed) {
|
|
|
262
329
|
const snapshot = router.snapshot();
|
|
263
330
|
const servicesDir = agentServicesDir(aid);
|
|
264
331
|
switch (command) {
|
|
265
|
-
case 'call':
|
|
266
|
-
case 'describe':
|
|
267
|
-
case 'schema':
|
|
268
|
-
return await runCall(deps, aid, parsed);
|
|
269
332
|
case 'rules:show': {
|
|
270
333
|
const config = new ServiceRulesStore(servicesDir).read();
|
|
271
334
|
const entries = parsed.type
|
|
@@ -325,6 +388,8 @@ async function execute(deps, parsed) {
|
|
|
325
388
|
enabled: snapshot.enabled,
|
|
326
389
|
identity: snapshot.identity,
|
|
327
390
|
routerErrors: snapshot.routerErrors,
|
|
391
|
+
// 宿主运行时:`enabled:false` = 总闸关着;`enabled:true,running:false` = 尚未被调用。
|
|
392
|
+
host: peekServiceRouter(aid)?.hostStatus() ?? { enabled: false },
|
|
328
393
|
packs: snapshot.packs.activePacks.map(pack => statusForPack(snapshot, pack.id)),
|
|
329
394
|
skipped: snapshot.packs.skippedPacks,
|
|
330
395
|
disabled: snapshot.packs.disabledPacks,
|
|
@@ -390,6 +455,9 @@ async function execute(deps, parsed) {
|
|
|
390
455
|
case 'enable':
|
|
391
456
|
case 'disable':
|
|
392
457
|
return setRouterEnabled(aid, command === 'enable');
|
|
458
|
+
case 'host:enable':
|
|
459
|
+
case 'host:disable':
|
|
460
|
+
return setHostEnabled(aid, command === 'host:enable');
|
|
393
461
|
case 'pack': {
|
|
394
462
|
const servicesDirForPack = agentServicesDir(aid);
|
|
395
463
|
if (parsed.action === 'list') {
|
|
@@ -488,16 +556,11 @@ ${HELP}` };
|
|
|
488
556
|
* 因此 CLI 中途被杀也不丢结果。
|
|
489
557
|
*/
|
|
490
558
|
async function runCall(deps, selfAid, parsed) {
|
|
491
|
-
//
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
if (!record)
|
|
495
|
-
return { ok: false, code: 'REQUEST_NOT_FOUND', error: `no request ${parsed.requestId}` };
|
|
496
|
-
return { ok: true, result: summarizeRecord(record) };
|
|
497
|
-
}
|
|
498
|
-
const targetAid = parsed.pack;
|
|
559
|
+
// `@` 前缀只是展示习惯(名片里那样写),AID 本身不带。不在这里剥掉就会原样
|
|
560
|
+
// 交给消息层,被 AID 校验拒成 "must be 4-64 characters"。
|
|
561
|
+
const targetAid = stripAidPrefix(parsed.pack);
|
|
499
562
|
if (!targetAid)
|
|
500
|
-
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>` };
|
|
501
564
|
// 调自己:消息会发出去,但入站侧没有任何分支会应答它,只能干等满超时(默认 30s)
|
|
502
565
|
// 然后报一个看起来像对端故障的 NO_RESULT。前置拒绝,别让人等。
|
|
503
566
|
if (normalizeAid(targetAid) === normalizeAid(selfAid)) {
|
|
@@ -522,14 +585,17 @@ async function runCall(deps, selfAid, parsed) {
|
|
|
522
585
|
: parsed.type
|
|
523
586
|
? { service: parsed.type }
|
|
524
587
|
: {};
|
|
525
|
-
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));
|
|
526
592
|
const registry = getAunRequestRegistry();
|
|
527
593
|
let prepared;
|
|
528
594
|
try {
|
|
529
595
|
prepared = registry.prepare({
|
|
530
596
|
selfAid,
|
|
531
597
|
targetAid,
|
|
532
|
-
payload: { type: requestType, ...data },
|
|
598
|
+
payload: { type: requestType, ...data, service_deadline_at_ms: Date.now() + timeoutMs },
|
|
533
599
|
timeoutMs,
|
|
534
600
|
});
|
|
535
601
|
}
|
|
@@ -540,6 +606,9 @@ async function runCall(deps, selfAid, parsed) {
|
|
|
540
606
|
const sent = await channel.sendDaemonMsg({
|
|
541
607
|
to: targetAid,
|
|
542
608
|
payload: prepared.payload,
|
|
609
|
+
// volatile:只存在消息服务内存里,不落库、不分配持久 seq。对端离线时这条
|
|
610
|
+
// 请求在 TTL 到期后消失,重连也拉不到——服务调用是 RPC,不是离线信箱。
|
|
611
|
+
ttl,
|
|
543
612
|
...(parsed.encrypted !== undefined ? { encrypt: parsed.encrypted } : {}),
|
|
544
613
|
service: { type: requestType, requestId: prepared.requestId },
|
|
545
614
|
});
|
|
@@ -554,25 +623,25 @@ async function runCall(deps, selfAid, parsed) {
|
|
|
554
623
|
}
|
|
555
624
|
if (sent.message_id)
|
|
556
625
|
registry.markTransportAccepted(selfAid, prepared.requestId, sent.message_id, sent.status);
|
|
557
|
-
if (parsed.noWait) {
|
|
558
|
-
return { ok: true, result: { request_id: prepared.requestId, message_id: sent.message_id, state: 'pending' } };
|
|
559
|
-
}
|
|
560
626
|
const record = await registry.wait(selfAid, prepared.requestId, timeoutMs);
|
|
561
627
|
if (!record) {
|
|
562
628
|
return { ok: false, code: 'NO_RESULT', error: 'request record disappeared', result: { request_id: prepared.requestId } };
|
|
563
629
|
}
|
|
564
|
-
const summary = summarizeRecord(record);
|
|
565
630
|
if (record.state === 'completed' && record.responsePayload) {
|
|
566
|
-
return { ok: true, result: { ...
|
|
631
|
+
return { ok: true, result: { ...summarizeRecord(record), response: record.responsePayload } };
|
|
567
632
|
}
|
|
568
633
|
if (record.state === 'failed') {
|
|
569
|
-
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) };
|
|
570
635
|
}
|
|
636
|
+
// 等到超时:把记录钉成终态,迟到的应答再也改不动它(resolveIncoming 只接受
|
|
637
|
+
// 非终态记录)。`wait()` 自己只会落到 pending —— 那是 `ec msg send` 需要的
|
|
638
|
+
// "稍后还能补上"的语义,服务调用不需要。
|
|
639
|
+
const expired = registry.markFailed(selfAid, prepared.requestId, 'no response before deadline') ?? record;
|
|
571
640
|
return {
|
|
572
641
|
ok: false,
|
|
573
642
|
code: 'NO_RESULT',
|
|
574
|
-
error: `no
|
|
575
|
-
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),
|
|
576
645
|
};
|
|
577
646
|
}
|
|
578
647
|
function summarizeRecord(record) {
|
|
@@ -592,6 +661,18 @@ function statusForPack(snapshot, packId) {
|
|
|
592
661
|
name: pack.name,
|
|
593
662
|
status: 'active',
|
|
594
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
|
+
})),
|
|
595
676
|
unmatched: pack.unmatched,
|
|
596
677
|
replyAllowed: pack.reply.allowed,
|
|
597
678
|
revision: pack.revision,
|
|
@@ -623,6 +704,8 @@ function doctor(aid, router, only) {
|
|
|
623
704
|
const packs = only
|
|
624
705
|
? snapshot.packs.activePacks.filter(pack => pack.id === only)
|
|
625
706
|
: snapshot.packs.activePacks;
|
|
707
|
+
// 宿主总闸:`mode:"resident"` 只有它开着才有稳态收益,否则退化成每调用一进程。
|
|
708
|
+
const hostEnabled = snapshot.config.host?.enabled === true;
|
|
626
709
|
for (const pack of packs) {
|
|
627
710
|
// 1. requires 与名片不符(对被过滤掉的包在 skipped 里单独报)。
|
|
628
711
|
findings.push({ level: 'ok', check: `${pack.id}.requires`, detail: `satisfied by ${snapshot.identity.type}/${snapshot.identity.exttype || '-'}` });
|
|
@@ -636,6 +719,17 @@ function doctor(aid, router, only) {
|
|
|
636
719
|
});
|
|
637
720
|
}
|
|
638
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
|
+
}
|
|
639
733
|
}
|
|
640
734
|
// 5. type=services 但无激活包。
|
|
641
735
|
//
|
|
@@ -741,16 +835,39 @@ function lClassFinding() {
|
|
|
741
835
|
return { level: 'warn', check: 'l-class', detail: `cannot verify: ${errorMessage(error)}` };
|
|
742
836
|
}
|
|
743
837
|
}
|
|
744
|
-
/**
|
|
745
|
-
|
|
746
|
-
|
|
838
|
+
/**
|
|
839
|
+
* 读 services-config.json 原始对象作为改写底稿。
|
|
840
|
+
*
|
|
841
|
+
* 不能用 `loadRouterConfig().config` 写回:那是校验后的规范形态,会丢掉未知字段、
|
|
842
|
+
* 把缺省值具体化。用户手写的文件要按原样保留,只动目标字段。
|
|
843
|
+
*/
|
|
844
|
+
function readConfigForWrite(servicesDir) {
|
|
747
845
|
const filePath = path.join(servicesDir, SERVICES_CONFIG_JSON);
|
|
748
846
|
const loaded = loadRouterConfig(servicesDir);
|
|
749
|
-
|
|
750
|
-
|
|
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
|
|
751
859
|
: { v: 1, rateLimit: { builtin: { perMinute: 20, perHour: 200 }, service: { perMinute: 50, perHour: 1000 } } };
|
|
752
860
|
if (base.v !== 1)
|
|
753
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;
|
|
754
871
|
base.enabled = enabled;
|
|
755
872
|
try {
|
|
756
873
|
fs.mkdirSync(servicesDir, { recursive: true });
|
|
@@ -764,4 +881,47 @@ function setRouterEnabled(aid, enabled) {
|
|
|
764
881
|
live.reload();
|
|
765
882
|
return { ok: true, result: { aid, enabled, path: filePath } };
|
|
766
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
|
+
}
|
|
767
927
|
export { HELP as SERVICES_HELP };
|