evolcore 0.0.43-test.4 → 0.0.43-test.5
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 +46 -0
- package/bin/ecmsg.js +354 -91
- package/dist/agents/codex-runner.js +12 -17
- package/dist/aun/aid/agentmd.js +25 -0
- package/dist/aun/aid/control-aid.js +15 -0
- package/dist/aun/aid/identity.js +8 -0
- package/dist/aun/aid/ownership-operation.js +12 -3
- package/dist/channels/aun.js +30 -17
- package/dist/channels/daemon.js +2 -2
- package/dist/cli/agent-create.js +4 -2
- package/dist/cli/aid-bind-command.js +3 -0
- package/dist/cli/aun-commands.js +10 -3
- package/dist/cli/code-stats.js +451 -213
- package/dist/cli/ctl-command.js +1 -3
- package/dist/cli/daemon-commands.js +12 -3
- package/dist/cli/directory.js +3 -1
- package/dist/cli/ecmsg-gateway.js +204 -0
- package/dist/cli/index.js +6 -0
- package/dist/cli/init.js +45 -13
- package/dist/cli/provider-command.js +82 -5
- package/dist/cli/restart-monitor.js +11 -19
- package/dist/cli/stats.js +8 -1
- package/dist/cli/task-context.js +3 -0
- package/dist/config/boot-log.js +12 -1
- package/dist/config/config-manager.js +4 -13
- package/dist/config/daemon-services.js +1 -0
- package/dist/config/peer-role-resolver.js +5 -5
- package/dist/config/provider-identity-migration.js +202 -0
- package/dist/config/provider-identity.js +37 -0
- package/dist/config/provider-ipc-service.js +40 -3
- package/dist/config/provider-local-sync.js +153 -0
- package/dist/config/providers-config.js +32 -4
- package/dist/config/providers-management.js +144 -68
- package/dist/config/providers.js +4 -1
- package/dist/config/schema-migration.js +67 -3
- package/dist/core/agent-runtime.js +4 -2
- package/dist/core/auth/auth-gateway.js +5 -3
- package/dist/core/auth/delegation-diagnostics.js +6 -2
- package/dist/core/auth/operation-authorizer.js +3 -1
- package/dist/core/auth/operation-catalog.js +6 -4
- package/dist/core/command/cli-intent-parser.js +2 -1
- package/dist/core/command/command-handler.js +11 -6
- package/dist/core/command/menu-protocol.js +4 -2
- package/dist/core/command/provider-menu.js +4 -2
- package/dist/core/command/role-menu.js +2 -2
- package/dist/core/command/slash-handler.js +52 -16
- package/dist/core/handoff/runtime.js +9 -3
- package/dist/core/initialization/service.js +4 -3
- package/dist/core/message/aun-ipc-sender.js +81 -3
- package/dist/core/message/message-admission.js +2 -0
- package/dist/core/message/response-engine.js +23 -23
- package/dist/core/message/send-options.js +40 -0
- package/dist/core/message/send-routing.js +310 -0
- package/dist/core/ownership/owner-resolver.js +111 -8
- package/dist/core/permission/ec-command-parser.js +148 -15
- package/dist/core/permission/readonly-shell-query.js +66 -7
- package/dist/core/permission/tool-error-code.js +13 -1
- package/dist/core/permission/tool-policy.js +74 -20
- package/dist/core/relation/same-owner-proof.js +131 -0
- package/dist/core/session/session-idle-monitor.js +94 -16
- package/dist/core/session/session-manager.js +69 -16
- package/dist/core/thread/thread-route.js +5 -2
- package/dist/directory/owner-directory-cache.js +686 -97
- package/dist/directory/owner-directory-markdown.js +146 -36
- package/dist/directory/owner-directory-query-operation.js +2 -2
- package/dist/directory/owner-directory-scope.js +12 -0
- package/dist/directory/owner-directory-search.js +5 -1
- package/dist/directory/owner-directory-store.js +28 -0
- package/dist/ecweb/basic-settings-service.js +15 -1
- package/dist/ecweb/message-context-service.js +2 -2
- package/dist/ecweb/providers-service.js +3 -1
- package/dist/ecweb/runtime/lifecycle.js +18 -9
- package/dist/ecweb/runtime/supervisor.js +76 -24
- package/dist/index.js +4 -0
- package/dist/paths.js +2 -1
- package/dist/proxy/manager.js +2 -0
- package/dist/proxy/service-supervisor.js +2 -2
- package/dist/response-system/engines/v1/proactive-flow.js +4 -0
- package/dist/trigger/application-service.js +1 -0
- package/dist/trigger/event-source.js +4 -0
- package/dist/trigger/feedback.js +26 -2
- package/dist/trigger/scheduler.js +3 -3
- package/dist/trigger/system-definitions.js +2 -2
- package/dist/trigger/validation.js +4 -0
- package/dist/utils/autostart.js +2 -2
- package/dist/utils/cross-platform.js +36 -8
- package/dist/utils/public-suffix.js +5811 -0
- package/dist/utils/windows-autostart.js +41 -7
- package/ecagent/dist/harness/env/nodejs.js +46 -2
- package/kits/docs/aun/ABILITY_CALLING.md +3 -3
- package/kits/docs/channels/aun.md +1 -1
- package/kits/docs/channels/feishu.md +2 -2
- package/kits/docs/context-assembly.md +20 -4
- package/kits/docs/evolcore/INDEX.md +2 -1
- package/kits/docs/evolcore/agent.md +2 -2
- package/kits/docs/evolcore/aid.md +8 -2
- package/kits/docs/evolcore/ctl.md +13 -4
- package/kits/docs/evolcore/directory.md +48 -15
- package/kits/docs/evolcore/group.md +6 -6
- package/kits/docs/evolcore/memory-consolidation.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +32 -3
- package/kits/docs/evolcore/msg.md +28 -27
- package/kits/docs/evolcore/provider.md +39 -5
- package/kits/docs/evolcore/response.md +1 -1
- package/kits/docs/evolcore/thread-chain.md +11 -13
- package/kits/docs/evolcore/tool-authorization.md +17 -0
- package/kits/docs/evolcore/trigger.md +2 -2
- package/kits/docs/identity/ROLE_DETAIL.md +1 -1
- package/kits/docs/prompt-loading-architecture.md +30 -20
- package/kits/eck_manifest.auxiliary.json +5 -5
- package/kits/eck_manifest.json +28 -28
- package/kits/eck_manifest.memory.json +18 -18
- package/kits/rules/01-overview.md +1 -1
- package/kits/rules/06-channel.md +3 -3
- package/kits/schemas/_meta.json +7 -1
- package/kits/schemas/providers.schema.2.json +74 -0
- package/kits/schemas/role-registry.schema.1.json +1 -1
- package/kits/skills/ec-agent-create/SKILL.md +1 -0
- package/kits/skills/ec-service-proxy/SKILL.md +3 -10
- package/kits/skills/ec-trigger/SKILL.md +5 -5
- package/kits/skills/ec-trigger/references/examples.md +1 -1
- package/kits/templates/system-fragments/channel.md +5 -5
- package/kits/templates/system-fragments/commands.md +3 -2
- package/kits/templates/system-fragments/directory-contacts.md +10 -3
- package/kits/templates/system-fragments/personal-assistant.md +22 -3
- package/kits/templates/system-fragments/reply.md +47 -28
- package/kits/templates/system-fragments/session.md +2 -9
- package/kits/templates/system-fragments/thread.md +5 -5
- package/package.json +2 -3
package/dist/cli/ctl-command.js
CHANGED
|
@@ -14,8 +14,7 @@ const CTL_HELP = `用法: ec ctl <command> [args...]
|
|
|
14
14
|
会话:
|
|
15
15
|
name <名称> 重命名当前会话
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
send <消息内容> 主动发送文本消息(proactive 模式)
|
|
17
|
+
文件:
|
|
19
18
|
file [channel] <path> 发送项目内文件
|
|
20
19
|
queue [--after <time>] [--before <time>] 查看/管理会话消息队列
|
|
21
20
|
|
|
@@ -23,7 +22,6 @@ const CTL_HELP = `用法: ec ctl <command> [args...]
|
|
|
23
22
|
ec ctl status
|
|
24
23
|
ec ctl status --format json
|
|
25
24
|
ec ctl name "新会话名称"
|
|
26
|
-
ec ctl send "任务已完成"
|
|
27
25
|
ec ctl file report.md
|
|
28
26
|
ec ctl queue --full
|
|
29
27
|
ec ctl path list
|
|
@@ -694,12 +694,19 @@ export async function cmdStart(opts = {}) {
|
|
|
694
694
|
console.error('⚠ 控制 AID 未配置,请先运行 ec init;未启动 EvolCore。');
|
|
695
695
|
return;
|
|
696
696
|
}
|
|
697
|
+
if (opts.webInit) {
|
|
698
|
+
const { hasLocalControlIdentity, missingControlIdentityMessage } = await import('../aun/aid/control-aid.js');
|
|
699
|
+
if (!hasLocalControlIdentity(daemonCfgStart.aid)) {
|
|
700
|
+
trace.finish(false);
|
|
701
|
+
throw new Error(missingControlIdentityMessage(daemonCfgStart.aid));
|
|
702
|
+
}
|
|
703
|
+
}
|
|
697
704
|
trace.mark('cli.codexHookCheck');
|
|
698
705
|
if (!await ensureCodexHookBeforeLifecycle()) {
|
|
699
706
|
trace.finish(false);
|
|
700
707
|
return;
|
|
701
708
|
}
|
|
702
|
-
if (process.stdin.isTTY) {
|
|
709
|
+
if (!opts.webInit && process.stdin.isTTY) {
|
|
703
710
|
// 证书缺失时在 CLI 侧提示,daemon 是后台进程无终端不做交互
|
|
704
711
|
const certKey = path.join(resolvePaths().root, 'AIDs', daemonCfgStart.aid, 'private', 'key.json');
|
|
705
712
|
if (!fs.existsSync(certKey)) {
|
|
@@ -986,8 +993,10 @@ export async function cmdStart(opts = {}) {
|
|
|
986
993
|
}
|
|
987
994
|
}
|
|
988
995
|
console.log('');
|
|
989
|
-
//
|
|
990
|
-
|
|
996
|
+
// 代码统计仅在开发仓(link 模式)显示。判据与「安装类型」一行保持一致:
|
|
997
|
+
// 看包路径是否含 node_modules,而不是比较 EVOLCORE_HOME 与包目录——
|
|
998
|
+
// 运行时 home 默认是 ~/.evolcore,那个比较永远不会成立。
|
|
999
|
+
if (packageIsDevMode()) {
|
|
991
1000
|
printCodeStats(getPackageRoot(), p.logs);
|
|
992
1001
|
}
|
|
993
1002
|
console.log(`⏱ done in ${((Date.now() - cmdStartedAt) / 1000).toFixed(1)}s`);
|
package/dist/cli/directory.js
CHANGED
|
@@ -176,7 +176,7 @@ async function runManaged(argv, json) {
|
|
|
176
176
|
}
|
|
177
177
|
function printHelp() {
|
|
178
178
|
console.log(`用法:
|
|
179
|
-
ec directory list [<关键词>] [--filter '<kw1,kw2>']... [--type <type>] [--scope internal|external|all] [--owner <aid|unbound>] [--limit <n>] [--page <n>]
|
|
179
|
+
ec directory list [<关键词>] [--filter '<kw1,kw2>']... [--type <type>] [--scope internal|external|pa-team|all] [--owner <aid|unbound>] [--limit <n>] [--page <n>]
|
|
180
180
|
ec directory info <contact-aid|名字> [--limit <n>]
|
|
181
181
|
ec directory refresh
|
|
182
182
|
ec directory blocked
|
|
@@ -191,6 +191,8 @@ list:
|
|
|
191
191
|
位置参数按“多个词同时命中”处理。
|
|
192
192
|
默认每页 20 条,--page / --limit 可翻页;输出包含 type、exttype、描述、备注、
|
|
193
193
|
Owner 绑定关系与 Ownership 核验状态。本地备注正文不在 list 展示。
|
|
194
|
+
--scope internal|external|pa-team|all(默认 all):pa-team 只列 open_pa_context
|
|
195
|
+
里且 ownership_status=owned 的成员。
|
|
194
196
|
|
|
195
197
|
info:
|
|
196
198
|
接受 AID 或名字。AID 大小写不敏感、可带 @ 前缀;名字先做归一后的精确匹配
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ecmsg` 网关的可测部分:参数解析与下游 argv 构造。
|
|
3
|
+
*
|
|
4
|
+
* 与 `bin/ecmsg.js` 的分工:
|
|
5
|
+
* - 本模块:纯函数,无 IO,可单测
|
|
6
|
+
* - `bin/ecmsg.js`:读环境、加载模块、IPC、渲染回执
|
|
7
|
+
*
|
|
8
|
+
* 为什么单独拆出来:网关最容易出错的两处(选项归类、跨话题参数注入)都是纯逻辑,
|
|
9
|
+
* 混在带 IO 的入口脚本里就无法回归验证。
|
|
10
|
+
*/
|
|
11
|
+
import { isThreadTopicId, parseDurationToMs } from '../core/message/send-routing.js';
|
|
12
|
+
import { GATEWAY_FLAG_ALIASES, GATEWAY_ROUTE_VALUE_FLAGS, MANAGED_SEND_BOOLEAN_FLAGS, MANAGED_SEND_VALUE_FLAGS, } from '../core/message/send-options.js';
|
|
13
|
+
/**
|
|
14
|
+
* 选项表来自 `send-options.ts`(唯一事实源),网关**不再维护第二份**。
|
|
15
|
+
*
|
|
16
|
+
* 网关消费的:路由选项 + 三态 `--encrypt`;其余一律原样透传给下游通道,
|
|
17
|
+
* 因此 `--file` / `--link` / `--payload` / `--trigger-prompt` 等能力与
|
|
18
|
+
* `ec msg send` 天然一致,不存在"两边各实现一套"的漂移。
|
|
19
|
+
*/
|
|
20
|
+
const ROUTE_VALUE_FLAGS = new Set(GATEWAY_ROUTE_VALUE_FLAGS);
|
|
21
|
+
/** 原样透传给底层发送通道的选项(取一个值)。 */
|
|
22
|
+
const PASSTHROUGH_VALUE_FLAGS = new Set(MANAGED_SEND_VALUE_FLAGS.filter(flag => !ROUTE_VALUE_FLAGS.has(flag)));
|
|
23
|
+
/** 原样透传的布尔选项(`--encrypt`/`--no-encrypt` 由网关单独处理)。 */
|
|
24
|
+
const PASSTHROUGH_BOOLEAN_FLAGS = new Set(MANAGED_SEND_BOOLEAN_FLAGS.filter(flag => flag === '--mention-all'));
|
|
25
|
+
/** 正文来源类选项:出现即表示有正文,不再要求位置参数。 */
|
|
26
|
+
export const BODY_FLAGS = new Set([
|
|
27
|
+
'--text-from-file', '--file', '--link', '--payload', '--payload-file',
|
|
28
|
+
]);
|
|
29
|
+
/**
|
|
30
|
+
* 把 argv 切成「路由选项」「正文」「透传选项」三部分。
|
|
31
|
+
*
|
|
32
|
+
* 正文与透传选项原样交给底层通道,保证 `--file` / `--link` / `--payload` 等
|
|
33
|
+
* 能力与 `ec msg send` 完全一致——网关不重新实现任何正文形态。
|
|
34
|
+
*/
|
|
35
|
+
export function parseGatewayArgs(args) {
|
|
36
|
+
const route = {};
|
|
37
|
+
const passthrough = [];
|
|
38
|
+
const text = [];
|
|
39
|
+
let endOfOptions = false;
|
|
40
|
+
for (let index = 0; index < args.length; index++) {
|
|
41
|
+
const token = args[index];
|
|
42
|
+
if (endOfOptions) {
|
|
43
|
+
text.push(token);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (token === '--') {
|
|
47
|
+
endOfOptions = true;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (token === '--help' || token === '-h') {
|
|
51
|
+
route.help = true;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (token === '--no-encrypt') {
|
|
55
|
+
route.noEncrypt = true;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (PASSTHROUGH_BOOLEAN_FLAGS.has(token)) {
|
|
59
|
+
passthrough.push(token);
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
// `--self` 是 `--from` 的别名:托管发送里本端恒为会话本端,两者同义。
|
|
63
|
+
const flag = GATEWAY_FLAG_ALIASES[token] ?? token;
|
|
64
|
+
if (ROUTE_VALUE_FLAGS.has(flag)) {
|
|
65
|
+
const value = args[++index];
|
|
66
|
+
if (value === undefined)
|
|
67
|
+
return { ok: false, error: `${token} 需要一个值` };
|
|
68
|
+
if (flag === '--format') {
|
|
69
|
+
if (value !== 'json')
|
|
70
|
+
return { ok: false, error: '--format 只支持 json' };
|
|
71
|
+
route.format = 'json';
|
|
72
|
+
}
|
|
73
|
+
else if (flag === '--thread')
|
|
74
|
+
route.thread = value;
|
|
75
|
+
else if (flag === '--to')
|
|
76
|
+
route.to = value;
|
|
77
|
+
else if (flag === '--from')
|
|
78
|
+
route.from = value;
|
|
79
|
+
else if (flag === '--check-every')
|
|
80
|
+
route.checkEvery = value;
|
|
81
|
+
else if (flag === '--encrypt')
|
|
82
|
+
route.encrypt = value;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (PASSTHROUGH_VALUE_FLAGS.has(flag)) {
|
|
86
|
+
const value = args[++index];
|
|
87
|
+
if (value === undefined)
|
|
88
|
+
return { ok: false, error: `${token} 需要一个值` };
|
|
89
|
+
passthrough.push(flag, value);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (token.startsWith('--')) {
|
|
93
|
+
return { ok: false, error: `未知选项 ${token}(用 --help 查看用法)` };
|
|
94
|
+
}
|
|
95
|
+
text.push(token);
|
|
96
|
+
}
|
|
97
|
+
return { ok: true, route, passthrough, text };
|
|
98
|
+
}
|
|
99
|
+
/** 毫秒 → `20m` / `90s` / `2h` / `1d`,供下游 `--check-every` 使用。 */
|
|
100
|
+
export function formatDuration(ms) {
|
|
101
|
+
if (!ms || ms <= 0)
|
|
102
|
+
return '-';
|
|
103
|
+
if (ms % 86_400_000 === 0)
|
|
104
|
+
return `${ms / 86_400_000}d`;
|
|
105
|
+
if (ms % 3_600_000 === 0)
|
|
106
|
+
return `${ms / 3_600_000}h`;
|
|
107
|
+
if (ms % 60_000 === 0)
|
|
108
|
+
return `${ms / 60_000}m`;
|
|
109
|
+
return `${Math.round(ms / 1000)}s`;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* 由路由结果构造下游发送通道的 argv。
|
|
113
|
+
*
|
|
114
|
+
* 关键设计:
|
|
115
|
+
* - **同话题绝不注入 `--thread` / `--check-every`**。目标本来就是当前会话,
|
|
116
|
+
* 剥掉这两个参数后语义完全等价,且天然不会创建复查 Trigger,也避开了底层
|
|
117
|
+
* "跨话题参数必须成对"的校验。
|
|
118
|
+
* - **跨话题必须成对注入**。`--check-every` 由网关按判定结果给出(缺省 20m),
|
|
119
|
+
* 不依赖调用方是否传了它。
|
|
120
|
+
* - **加密显式下发二态**,不依赖 daemon 默认值:`--encrypt` 或 `--no-encrypt`。
|
|
121
|
+
*/
|
|
122
|
+
/**
|
|
123
|
+
* 目标 ID 是否是 AID 形态。
|
|
124
|
+
*
|
|
125
|
+
* 与 `ec-command-parser` 的 `looksLikeAid` 同口径(至少三级、只含域名安全字符)。
|
|
126
|
+
* 非 AUN 渠道的原生 ID(`ou_xxx`、`wxid_xxx`)不是 AID,因此**不能**作为位置
|
|
127
|
+
* 参数传给下游——那会被当成正文,目标改由 `--thread` 推导。
|
|
128
|
+
*/
|
|
129
|
+
function looksLikeAid(value) {
|
|
130
|
+
const labels = value.split('.');
|
|
131
|
+
return labels.length >= 3
|
|
132
|
+
&& labels.every(label => /^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?$/.test(label));
|
|
133
|
+
}
|
|
134
|
+
export function buildDownstreamArgv(route, text, passthrough) {
|
|
135
|
+
const scope = route.peer.peerKind === 'group' ? 'group' : 'msg';
|
|
136
|
+
// 目标为原生 ID 时必须靠 --thread 推导,写成位置参数会变成正文的一部分。
|
|
137
|
+
const targetAsPositional = looksLikeAid(route.peer.id)
|
|
138
|
+
|| (route.peer.peerKind === 'group' && !route.crossTopic);
|
|
139
|
+
const argv = targetAsPositional
|
|
140
|
+
? [scope, 'send', route.self, route.peer.id, ...text, ...passthrough]
|
|
141
|
+
: [scope, 'send', route.self, ...text, ...passthrough];
|
|
142
|
+
if (route.crossTopic && route.threadId) {
|
|
143
|
+
argv.push('--thread', route.threadId);
|
|
144
|
+
if (route.checkEveryMs)
|
|
145
|
+
argv.push('--check-every', formatDuration(route.checkEveryMs));
|
|
146
|
+
}
|
|
147
|
+
argv.push(route.encryptResolved ? '--encrypt' : '--no-encrypt');
|
|
148
|
+
return argv;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* 校验 `--thread` 是否需要在本地索引里查表。
|
|
152
|
+
*
|
|
153
|
+
* 主话题 id(`main:a:b`)自带两端,不需要索引;独立话题(`thread-…`)需要。
|
|
154
|
+
* 其他形态由 `resolveSendRoute` 直接拒绝,这里返回 false 以免做无谓的 IO。
|
|
155
|
+
*/
|
|
156
|
+
export function needsThreadIndexLookup(thread) {
|
|
157
|
+
return typeof thread === 'string' && isThreadTopicId(thread);
|
|
158
|
+
}
|
|
159
|
+
/** 跨话题时下游必须拿到合法时长;返回 undefined 表示无需复查。 */
|
|
160
|
+
export function downstreamCheckEveryMs(route) {
|
|
161
|
+
if (!route.crossTopic)
|
|
162
|
+
return undefined;
|
|
163
|
+
if (route.checkEveryMs === undefined)
|
|
164
|
+
return undefined;
|
|
165
|
+
// 兜底:解析结果来自网关自己补的默认值或调用方输入,两者都已是毫秒
|
|
166
|
+
return parseDurationToMs(formatDuration(route.checkEveryMs)) ?? route.checkEveryMs;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* 决定这次发送走哪条内部通道。
|
|
170
|
+
*
|
|
171
|
+
* 判据是**当前会话所在渠道**,不是目标对端的渠道:
|
|
172
|
+
* - 当前会话在 AUN 上 → 走 `aun-msg-send`。它同时覆盖同话题与跨话题;
|
|
173
|
+
* 跨话题的投递由 handoff 负责,目标会话属于哪个渠道由目标会话自己决定。
|
|
174
|
+
* - 当前会话在其它渠道上 → 只有"会话级发送"(发往该会话自己的 `channelId`),
|
|
175
|
+
* 因此只能同话题。跨话题需要别的入口,本端尚未提供。
|
|
176
|
+
*
|
|
177
|
+
* 换句话说:跨话题从来不是某个渠道的特性,而是"当前会话能不能把消息投到
|
|
178
|
+
* 另一条会话"。AUN 会话能,靠 handoff;其它渠道的会话暂时不能。
|
|
179
|
+
*/
|
|
180
|
+
export function decideDispatch(route, text, passthrough, currentChannelType) {
|
|
181
|
+
if (currentChannelType === 'aun') {
|
|
182
|
+
return { kind: 'aun', argv: buildDownstreamArgv(route, text, passthrough) };
|
|
183
|
+
}
|
|
184
|
+
if (route.crossTopic) {
|
|
185
|
+
return {
|
|
186
|
+
kind: 'reject',
|
|
187
|
+
code: 'CROSS_TOPIC_REQUIRES_AUN_SESSION',
|
|
188
|
+
message: `跨话题发送需要从 AUN 会话发起;当前会话在 ${currentChannelType} 渠道上`,
|
|
189
|
+
hint: '该渠道的会话目前只能回复本会话对端',
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
if (passthrough.length > 0) {
|
|
193
|
+
return {
|
|
194
|
+
kind: 'reject',
|
|
195
|
+
code: 'UNSUPPORTED_OPTION',
|
|
196
|
+
message: `${currentChannelType} 渠道的会话发送目前只支持纯文本,不支持的选项:${passthrough.join(' ')}`,
|
|
197
|
+
hint: "改用纯文本:ecmsg send '<正文>'",
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
if (!text.join(' ').trim()) {
|
|
201
|
+
return { kind: 'reject', code: 'INVALID_ARGUMENT', message: '缺少正文' };
|
|
202
|
+
}
|
|
203
|
+
return { kind: 'session' };
|
|
204
|
+
}
|
package/dist/cli/index.js
CHANGED
|
@@ -50,6 +50,12 @@ AUN:
|
|
|
50
50
|
aid 管理 AID 身份与 agent.md
|
|
51
51
|
msg 私聊消息收发、撤回、在线状态与历史
|
|
52
52
|
group 群消息与群管理
|
|
53
|
+
|
|
54
|
+
发送消息请用独立入口 ecmsg(统一入口):
|
|
55
|
+
ecmsg send '<正文>' 回复当前会话
|
|
56
|
+
ecmsg send '<正文>' --thread <话题id> 指定话题(跨话题)
|
|
57
|
+
ecmsg send '<正文>' --to <对端AID> 指定对端
|
|
58
|
+
详见 ecmsg --help。
|
|
53
59
|
fs AUN 文件系统
|
|
54
60
|
storage 底层对象存储命令
|
|
55
61
|
rpc 调用底层 AUN RPC
|
package/dist/cli/init.js
CHANGED
|
@@ -7,7 +7,7 @@ import { commandExists } from '../utils/cross-platform.js';
|
|
|
7
7
|
import { scanInstances } from '../utils/instance-registry.js';
|
|
8
8
|
import { saveDefaultsSafe, loadDaemonConfig, saveDaemonConfig } from '../config-store.js';
|
|
9
9
|
import { DEFAULT_ECWEB_PORT, ecwebService, setEcwebEnabled } from '../config/daemon-services.js';
|
|
10
|
-
import { ensureControlAgentMd, generateControlAid, resolveControlAidDomain, submitControlAidRegistration, } from '../aun/aid/control-aid.js';
|
|
10
|
+
import { ensureControlAgentMd, generateControlAid, hasLocalControlIdentity, missingControlIdentityMessage, resolveControlAidDomain, submitControlAidRegistration, } from '../aun/aid/control-aid.js';
|
|
11
11
|
import { isValidAid } from '../aun/aid/validation.js';
|
|
12
12
|
/**
|
|
13
13
|
* `agents/codex-runner.js` 是 CLI 里最重的单个模块(整包冷加载约 380ms,因为
|
|
@@ -122,8 +122,25 @@ function isAutostartOnlyRequest(options) {
|
|
|
122
122
|
&& options.ecweb === undefined
|
|
123
123
|
&& options.format === undefined;
|
|
124
124
|
}
|
|
125
|
-
function
|
|
125
|
+
export async function configureAutostartForInit(enabled, runtimeRoot, interactive = true) {
|
|
126
126
|
const result = configureAutostart(enabled, runtimeRoot);
|
|
127
|
+
if (!result.repairTask || !interactive || !process.stdin.isTTY || !process.stdout.isTTY)
|
|
128
|
+
return result;
|
|
129
|
+
console.log(`检测到失效的 \\EvolCore 登录任务:启动命令匹配当前运行目录,但启动脚本与归属记录均缺失。`);
|
|
130
|
+
console.log(`重建将覆盖该任务并生成启动脚本:${result.repairTask.wrapperPath};不修改 AIDs、配置或数据。`);
|
|
131
|
+
const prompt = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
132
|
+
try {
|
|
133
|
+
const answer = (await ask(prompt, '是否重建此登录自启动任务?[y/N] ')).trim().toLowerCase();
|
|
134
|
+
if (answer !== 'y' && answer !== 'yes')
|
|
135
|
+
return result;
|
|
136
|
+
return configureAutostart(enabled, runtimeRoot, { confirmedTaskXml: result.repairTask.xml });
|
|
137
|
+
}
|
|
138
|
+
finally {
|
|
139
|
+
prompt.close();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
async function applyExplicitAutostart(enabled, runtimeRoot, interactive) {
|
|
143
|
+
const result = await configureAutostartForInit(enabled, runtimeRoot, interactive);
|
|
127
144
|
if (!result.ok) {
|
|
128
145
|
if (result.nonFatal) {
|
|
129
146
|
console.log(`⚠ ${autostartPlatformLabel() || '登录自启'}未配置:${result.error || '检测到外部配置占用,未覆盖。'}`);
|
|
@@ -179,6 +196,12 @@ export async function ensureEcwebInstalledForInit(options = {}) {
|
|
|
179
196
|
}
|
|
180
197
|
export async function cmdInitWeb(dependencies = {}) {
|
|
181
198
|
const p = resolvePaths();
|
|
199
|
+
const hasIdentity = dependencies.hasLocalIdentity ?? hasLocalControlIdentity;
|
|
200
|
+
const existingConfig = (dependencies.loadConfig ?? loadDaemonConfig)();
|
|
201
|
+
if (existingConfig.aid && !hasIdentity(existingConfig.aid)) {
|
|
202
|
+
console.error(`❌ ${missingControlIdentityMessage(existingConfig.aid)}`);
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
182
205
|
ensureDataDirs();
|
|
183
206
|
const daemonRunning = dependencies.isDaemonRunning?.()
|
|
184
207
|
?? scanInstances().mains.some(instance => instance.alive);
|
|
@@ -208,6 +231,10 @@ export async function cmdInitWeb(dependencies = {}) {
|
|
|
208
231
|
console.error("❌ 主机控制 AID 未配置。");
|
|
209
232
|
return false;
|
|
210
233
|
}
|
|
234
|
+
if (!hasIdentity(controlAid)) {
|
|
235
|
+
console.error(`❌ ${missingControlIdentityMessage(controlAid)}`);
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
211
238
|
if (config.owner) {
|
|
212
239
|
try {
|
|
213
240
|
await submitControlAidRegistration(controlAid, config.owner);
|
|
@@ -216,11 +243,16 @@ export async function cmdInitWeb(dependencies = {}) {
|
|
|
216
243
|
console.warn(`⚠️ 主机控制 AID Owner 绑定暂未提交,将由 daemon 后续重试: ${installErrorMessage(error)}`);
|
|
217
244
|
}
|
|
218
245
|
}
|
|
219
|
-
|
|
220
|
-
|
|
246
|
+
if (config.owner) {
|
|
247
|
+
try {
|
|
248
|
+
await (dependencies.ensureAgentMd ?? ensureControlAgentMd)(controlAid, { ownerAid: config.owner });
|
|
249
|
+
}
|
|
250
|
+
catch (error) {
|
|
251
|
+
console.warn(`⚠️ 主机控制 AID 名片暂未发布,将由 daemon 后续重试: ${installErrorMessage(error)}`);
|
|
252
|
+
}
|
|
221
253
|
}
|
|
222
|
-
|
|
223
|
-
console.
|
|
254
|
+
else {
|
|
255
|
+
console.log('ℹ 主机名片将在 Web 初始化完成 Owner 绑定后发布。');
|
|
224
256
|
}
|
|
225
257
|
if (ecwebService(config.services)?.enabled !== true) {
|
|
226
258
|
config = { ...config, services: setEcwebEnabled(config.services, true) };
|
|
@@ -284,7 +316,7 @@ export async function cmdInit(options) {
|
|
|
284
316
|
// A bound installation may toggle login autostart independently of the
|
|
285
317
|
// Baseagent setup wizard. This is also the path used by public installers.
|
|
286
318
|
if (isAutostartOnlyRequest(options) && hasCompletedInitConfig()) {
|
|
287
|
-
return applyExplicitAutostart(options.autoStart, p.root);
|
|
319
|
+
return applyExplicitAutostart(options.autoStart, p.root, !options?.nonInteractive);
|
|
288
320
|
}
|
|
289
321
|
// ── 1. 单进程互斥 ──
|
|
290
322
|
const aliveMains = scanInstances().mains.filter(m => m.alive);
|
|
@@ -292,7 +324,7 @@ export async function cmdInit(options) {
|
|
|
292
324
|
// Explicit autostart flags only change the login task; they do not need
|
|
293
325
|
// to rewrite init configuration or stop an already running daemon.
|
|
294
326
|
if (isAutostartOnlyRequest(options)) {
|
|
295
|
-
return applyExplicitAutostart(options.autoStart, p.root);
|
|
327
|
+
return applyExplicitAutostart(options.autoStart, p.root, !options?.nonInteractive);
|
|
296
328
|
}
|
|
297
329
|
const pids = aliveMains.map(m => m.record.pid).join(', ');
|
|
298
330
|
console.log(`❌ EvolCore 正在运行 (PID: ${pids}),请先执行 ec stop`);
|
|
@@ -546,7 +578,7 @@ export async function initTail(options = {}) {
|
|
|
546
578
|
return false;
|
|
547
579
|
}
|
|
548
580
|
if (options.autoStart !== undefined) {
|
|
549
|
-
autoStartReady = applyAutostart(options.autoStart);
|
|
581
|
+
autoStartReady = await applyAutostart(options.autoStart);
|
|
550
582
|
}
|
|
551
583
|
}
|
|
552
584
|
const configuredOwner = loadDaemonConfig().owner;
|
|
@@ -564,7 +596,7 @@ export async function initTail(options = {}) {
|
|
|
564
596
|
}
|
|
565
597
|
async function handleAutostartPrompt() {
|
|
566
598
|
if (options.autoStart !== undefined) {
|
|
567
|
-
autoStartReady = applyAutostart(options.autoStart);
|
|
599
|
+
autoStartReady = await applyAutostart(options.autoStart);
|
|
568
600
|
return;
|
|
569
601
|
}
|
|
570
602
|
if (!autostartPlatformLabel())
|
|
@@ -573,10 +605,10 @@ export async function initTail(options = {}) {
|
|
|
573
605
|
console.log(`✓ ${autostartPlatformLabel()} 登录自启已启用`);
|
|
574
606
|
return;
|
|
575
607
|
}
|
|
576
|
-
autoStartReady = applyAutostart(true);
|
|
608
|
+
autoStartReady = await applyAutostart(true);
|
|
577
609
|
}
|
|
578
|
-
function applyAutostart(enabled) {
|
|
579
|
-
const result =
|
|
610
|
+
async function applyAutostart(enabled) {
|
|
611
|
+
const result = await configureAutostartForInit(enabled, resolvePaths().root, !options?.nonInteractive);
|
|
580
612
|
if (!result.ok) {
|
|
581
613
|
if (result.nonFatal) {
|
|
582
614
|
console.log(` ⚠ ${autostartPlatformLabel() || '登录自启'}未配置:${result.error || '检测到外部配置占用,未覆盖。'}`);
|
|
@@ -4,12 +4,84 @@ import { resolvePaths } from '../paths.js';
|
|
|
4
4
|
import { readDelegationCredential, hashCurrentDelegatedCommand } from '../core/auth/agent-delegation.js';
|
|
5
5
|
import { parseProviderCommand } from '../config/provider-ipc-service.js';
|
|
6
6
|
import { queryDaemon, daemonUnavailableMessage, wantsHelp } from './help.js';
|
|
7
|
+
function providerText(command, data) {
|
|
8
|
+
const lines = [];
|
|
9
|
+
const label = (value) => String(value ?? '未设置').replace(/[\x00-\x1f\x7f-\x9f]/gu, ' ');
|
|
10
|
+
const aliases = () => {
|
|
11
|
+
for (const [alias, target] of Object.entries(data.aliases ?? {}))
|
|
12
|
+
lines.push(` ${label(alias)} → ${label(target)}`);
|
|
13
|
+
};
|
|
14
|
+
if (command.operation === 'sync') {
|
|
15
|
+
lines.push('✓ Provider 同步完成', `地址固化:${data.materializedBaseUrls ?? 0} 项`, `配置变更:${data.changedFiles ?? 0} 个文件,更新 ${data.referencesUpdated ?? 0} 处引用`);
|
|
16
|
+
if (data.imports?.length) {
|
|
17
|
+
lines.push('本机导入:');
|
|
18
|
+
for (const item of data.imports)
|
|
19
|
+
lines.push(` ${label(item.baseagent)} → ${label(item.providerId)}(${item.merged ? '已合并' : '已新增'})`);
|
|
20
|
+
}
|
|
21
|
+
else
|
|
22
|
+
lines.push('本机导入:无');
|
|
23
|
+
if (Object.keys(data.aliases ?? {}).length) {
|
|
24
|
+
lines.push('兼容别名:');
|
|
25
|
+
aliases();
|
|
26
|
+
}
|
|
27
|
+
lines.push(`全局默认基座:${label(data.activeBaseagent)}`);
|
|
28
|
+
lines.push(data.selection ? `本次默认选择:${label(data.selection.provider)} / ${label(data.selection.model)}` : '本次默认选择:未重新选择');
|
|
29
|
+
lines.push(`待处理:${data.pending?.length ? data.pending.map(label).join('、') : '无'}`, `告警:${data.warnings?.length ? data.warnings.map(label).join('、') : '无'}`, `备份:${data.backup ? label(data.backup) : '无(未产生变更)'}`);
|
|
30
|
+
}
|
|
31
|
+
else if (command.operation === 'list') {
|
|
32
|
+
const entries = Object.entries(data.providers ?? {});
|
|
33
|
+
lines.push(`Provider 列表(${entries.length} 项)`);
|
|
34
|
+
for (const [id, provider] of entries) {
|
|
35
|
+
lines.push(`${label(id)} ${label(provider.name || '未命名')}`, ` 域名:${label(provider.domain || '待迁移')} 服务:${Object.keys(provider.services ?? {}).map(label).join('、') || '无'}`);
|
|
36
|
+
}
|
|
37
|
+
if (Object.keys(data.aliases ?? {}).length) {
|
|
38
|
+
lines.push('兼容别名:');
|
|
39
|
+
aliases();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else if (command.operation === 'show') {
|
|
43
|
+
lines.push(`Provider 详情:${label(data.providerId)}`);
|
|
44
|
+
const visit = (value, indent, field) => {
|
|
45
|
+
if (value && typeof value === 'object') {
|
|
46
|
+
const entries = Object.entries(value);
|
|
47
|
+
lines.push(`${indent}${label(field)}:${entries.length ? '' : '(空)'}`);
|
|
48
|
+
for (const [key, child] of entries)
|
|
49
|
+
visit(child, indent + ' ', key);
|
|
50
|
+
}
|
|
51
|
+
else
|
|
52
|
+
lines.push(`${indent}${label(field)}:${label(value)}`);
|
|
53
|
+
};
|
|
54
|
+
const provider = structuredClone(data.provider ?? {});
|
|
55
|
+
if (provider.common) {
|
|
56
|
+
const key = provider.common.apiKey;
|
|
57
|
+
if (key && !/^\$(?:[A-Za-z_][A-Za-z0-9_]*|\{[A-Za-z_][A-Za-z0-9_]*\})$/u.test(key))
|
|
58
|
+
provider.common.apiKey = '<redacted>';
|
|
59
|
+
for (const field of ['headers', 'queryParams']) {
|
|
60
|
+
if (provider.common[field])
|
|
61
|
+
for (const key of Object.keys(provider.common[field]))
|
|
62
|
+
provider.common[field][key] = '<redacted>';
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
for (const [field, value] of Object.entries(provider))
|
|
66
|
+
visit(value, ' ', field);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
const verbs = { create: '创建', import: '导入', update: '更新', delete: '删除' };
|
|
70
|
+
lines.push(`✓ Provider ${verbs[command.operation]}成功:${label(data.providerId ?? command.providerId)}`);
|
|
71
|
+
}
|
|
72
|
+
if (data.revision)
|
|
73
|
+
lines.push(`配置版本:${label(data.revision)}`);
|
|
74
|
+
return lines.join('\n');
|
|
75
|
+
}
|
|
7
76
|
export async function cmdProvider(args) {
|
|
8
77
|
if (!args.length || wantsHelp(args)) {
|
|
9
78
|
console.log('用法: ec provider <命令> [--format json]\n\n'
|
|
10
79
|
+ ' list\n show <provider-id>\n create --file <path>\n import --file <path>\n'
|
|
11
|
-
+ ' update <provider-id> --file <path>\n delete <provider-id>\n\n'
|
|
12
|
-
+ '
|
|
80
|
+
+ ' update <provider-id> --file <path>\n delete <provider-id>\n sync\n\n'
|
|
81
|
+
+ 'sync 扫描导入本机 Provider、固化环境变量地址、迁移 ID 与配置引用,并切换全局默认到 ecagent;不覆盖 Agent 显式基座选择。\n'
|
|
82
|
+
+ '默认输出可读文本;--format json 输出完整结构化响应,适合脚本处理。\n'
|
|
83
|
+
+ '宿主控制终端或 daemon 验证的 trusted fullaccess 任务可管理 process 级 Provider。\n'
|
|
84
|
+
+ '经 daemon 验证的 DaemonOwner 托管任务无需 fullaccess 即可 list/show。文件必须为 UTF-8,最大 1 MiB。\n'
|
|
13
85
|
+ 'import 接受单 Provider 对象、单项映射或 providers 包装,始终创建新 ID。\n'
|
|
14
86
|
+ 'update 替换完整对象;<redacted> 保留原密钥。输出始终脱敏。');
|
|
15
87
|
return;
|
|
@@ -35,15 +107,20 @@ export async function cmdProvider(args) {
|
|
|
35
107
|
const { response, transportError } = await queryDaemon(resolvePaths().socket, {
|
|
36
108
|
type: 'provider.op', argv,
|
|
37
109
|
...(sessionId || delegationToken ? { sessionId, delegationToken, delegationCommandHash: hashCurrentDelegatedCommand() } : { controlToken }),
|
|
38
|
-
}, 30_000);
|
|
110
|
+
}, parsed.operation === 'sync' ? 120_000 : 30_000);
|
|
39
111
|
if (!response)
|
|
40
112
|
throw Object.assign(new Error(daemonUnavailableMessage(transportError, '无法连接 EvolCore daemon')), { code: 'DAEMON_UNAVAILABLE' });
|
|
41
113
|
if (json)
|
|
42
114
|
console.log(JSON.stringify(response, null, 2));
|
|
43
|
-
else if (response.ok === false)
|
|
115
|
+
else if (response.ok === false) {
|
|
44
116
|
console.error(response.error + ' (' + response.code + ')');
|
|
117
|
+
if (response.data?.kind === 'provider_referenced' && Array.isArray(response.data.references)) {
|
|
118
|
+
for (const reference of response.data.references)
|
|
119
|
+
console.error(` ${reference.file}: ${reference.path}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
45
122
|
else
|
|
46
|
-
console.log(
|
|
123
|
+
console.log(providerText(parsed, response.data));
|
|
47
124
|
if (response.ok === false)
|
|
48
125
|
process.exitCode = 1;
|
|
49
126
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
|
-
import { ipcHostQuery } from '../ipc.js';
|
|
2
|
+
import { ipcHostQuery, ipcQuery } from '../ipc.js';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { spawn, execFile } from 'child_process';
|
|
5
5
|
import { promisify } from 'util';
|
|
@@ -19,9 +19,7 @@ import { applyDataMigration, finalizeDataMigration, planDataMigration, verifyDat
|
|
|
19
19
|
import { DAEMON_SHUTDOWN_TIMEOUT_MS, requestDaemonShutdown, stopCodexAppServerOrphans } from './daemon-commands.js';
|
|
20
20
|
import { getProcessStartTime, invalidateProcessSnapshot, startTimeMatches } from '../utils/process-introspect.js';
|
|
21
21
|
import { DEFAULT_ECWEB_PORT, ecwebService, serviceRuntimeMode } from '../config/daemon-services.js';
|
|
22
|
-
import {
|
|
23
|
-
import { resolveGlobalPkg } from '../utils/npm-ops.js';
|
|
24
|
-
import { WEB_PACKAGE_NAME } from '../product.js';
|
|
22
|
+
import { stopEcwebForRestart } from '../ecweb/runtime/lifecycle.js';
|
|
25
23
|
const execFileAsync = promisify(execFile);
|
|
26
24
|
/** Read-only check performed before stopping the current daemon. */
|
|
27
25
|
function preflightDataMigration(root, log) {
|
|
@@ -206,9 +204,7 @@ export async function cmdRestartMonitor() {
|
|
|
206
204
|
const s = scanInstances();
|
|
207
205
|
if (!s.mains.some(m => m.alive))
|
|
208
206
|
return false;
|
|
209
|
-
|
|
210
|
-
return service?.enabled !== true || serviceRuntimeMode(service) !== 'managed'
|
|
211
|
-
|| await probeEcwebRestartReadiness(p, service.port ?? DEFAULT_ECWEB_PORT, resolveGlobalPkg(WEB_PACKAGE_NAME)?.version);
|
|
207
|
+
return true;
|
|
212
208
|
};
|
|
213
209
|
const markRequestReady = () => {
|
|
214
210
|
if (!hasCorrelatedRequest)
|
|
@@ -1104,9 +1100,6 @@ async function spawnAndWaitReady(p, log, timeout) {
|
|
|
1104
1100
|
const ecweb = ecwebService(loadDaemonConfig().services);
|
|
1105
1101
|
const requireEcweb = ecweb?.enabled === true && serviceRuntimeMode(ecweb) === 'managed';
|
|
1106
1102
|
const ecwebPort = ecweb?.port ?? DEFAULT_ECWEB_PORT;
|
|
1107
|
-
const ecwebVersion = requireEcweb ? resolveGlobalPkg(WEB_PACKAGE_NAME)?.version : undefined;
|
|
1108
|
-
if (requireEcweb)
|
|
1109
|
-
await stopEcwebForRestart(p, ecwebPort, log);
|
|
1110
1103
|
// 删除旧的 ready signal
|
|
1111
1104
|
try {
|
|
1112
1105
|
fs.unlinkSync(p.readySignal);
|
|
@@ -1154,7 +1147,6 @@ async function spawnAndWaitReady(p, log, timeout) {
|
|
|
1154
1147
|
fs.closeSync(out);
|
|
1155
1148
|
fs.closeSync(err);
|
|
1156
1149
|
log(`Spawned new process PID: ${childPid}, waiting for ready signal...`);
|
|
1157
|
-
let waitingForEcweb = false;
|
|
1158
1150
|
// 轮询等待 ready.signal 出现
|
|
1159
1151
|
const start = Date.now();
|
|
1160
1152
|
while (Date.now() - start < timeout) {
|
|
@@ -1167,16 +1159,16 @@ async function spawnAndWaitReady(p, log, timeout) {
|
|
|
1167
1159
|
return false;
|
|
1168
1160
|
}
|
|
1169
1161
|
if (fs.existsSync(p.readySignal)) {
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
return true;
|
|
1173
|
-
}
|
|
1174
|
-
if (!waitingForEcweb)
|
|
1175
|
-
log(`Daemon ready; waiting for identified ECWeb readiness on port ${ecwebPort}`);
|
|
1176
|
-
waitingForEcweb = true;
|
|
1162
|
+
log('Daemon ready; managed services are supervised independently');
|
|
1163
|
+
return true;
|
|
1177
1164
|
}
|
|
1178
1165
|
}
|
|
1179
|
-
|
|
1166
|
+
const ping = await ipcQuery(p.socket, { type: 'ping' }, platform.isWindows ? 5_000 : 1_000);
|
|
1167
|
+
if (ping?.pong === true && ping.pid === childPid && platform.isProcessRunning(childPid)) {
|
|
1168
|
+
log(`Daemon IPC is ready (PID: ${childPid}); startup finalization and managed services continue in background`);
|
|
1169
|
+
return true;
|
|
1170
|
+
}
|
|
1171
|
+
log(`Daemon ready signal not received within ${timeout / 1000}s and identified IPC is unavailable`);
|
|
1180
1172
|
// A timeout is still a live-process race: do not let self-heal spawn a
|
|
1181
1173
|
// replacement while the timed-out daemon owns the IPC endpoint or a port.
|
|
1182
1174
|
if (platform.isProcessRunning(childPid)) {
|
package/dist/cli/stats.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ec stats — Token 用量统计 CLI 命令。
|
|
3
3
|
*/
|
|
4
|
-
import { resolveRoot } from '../paths.js';
|
|
4
|
+
import { resolveRoot, resolvePaths } from '../paths.js';
|
|
5
5
|
import { wantsHelp } from './help.js';
|
|
6
6
|
import { authorizeLocalCommand } from './task-context.js';
|
|
7
7
|
import { queryAggregated, querySessionTurns, queryContextBreakdown, queryTopPeers, queryTopModels, queryMessageAggregated, queryPeerList, querySummary, queryPeerDaily, queryTaskModelCalls, querySessionModelCalls, queryTaskSummary } from '../stats/query.js';
|
|
@@ -44,6 +44,7 @@ ec stats — Token 用量与费用统计
|
|
|
44
44
|
--peer-detail <id> 指定对端 AID 或 peer_key,按天返回消耗明细
|
|
45
45
|
--task-calls <taskId> 一个 task 的模型用量明细(Codex 为回合/子 agent 汇总)
|
|
46
46
|
--session-calls <id> 一个会话的模型用量明细(Codex 为回合/子 agent 汇总)
|
|
47
|
+
--code 代码量历史(读 ec start 写下的 code-stats.json,不重扫)
|
|
47
48
|
|
|
48
49
|
输出格式:
|
|
49
50
|
--format json JSON 输出
|
|
@@ -242,6 +243,12 @@ export async function handleStats(args) {
|
|
|
242
243
|
const managedScope = await resolveManagedStatsScope(flags, isJson, ['stats', ...args]);
|
|
243
244
|
if (managedScope)
|
|
244
245
|
enforceManagedSelector(managedScope, flags, isJson);
|
|
246
|
+
// 代码量历史:只读 ec start 写下的 code-stats.json,不重新扫描源码。
|
|
247
|
+
if (flags.code) {
|
|
248
|
+
const { showCodeStatsHistory } = await import('./code-stats.js');
|
|
249
|
+
showCodeStatsHistory(resolvePaths().logs);
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
245
252
|
// 全量重建日聚合表(运维兜底/排查),不依赖时间范围。
|
|
246
253
|
if (flags.rebuild) {
|
|
247
254
|
const { rebuildDailyRollup, getDb } = await import('../stats/db.js');
|
package/dist/cli/task-context.js
CHANGED
|
@@ -51,6 +51,9 @@ function normalizeTaskRuntimeContext(value) {
|
|
|
51
51
|
|| value.executionSource === 'session-policy'
|
|
52
52
|
? value.executionSource : undefined,
|
|
53
53
|
daemonRuntimeEpoch: optionalString(value.daemonRuntimeEpoch),
|
|
54
|
+
// 仅观测字段,但必须留在白名单里:丢掉它,ecmsg 的 --encrypt auto 就永远
|
|
55
|
+
// 判定为"非入站触发",密文会话里的回复会退化成明文。
|
|
56
|
+
inboundEncrypted: typeof value.inboundEncrypted === 'boolean' ? value.inboundEncrypted : undefined,
|
|
54
57
|
threadId: optionalString(value.threadId),
|
|
55
58
|
sessionRuntimeDir: optionalAbsolutePath(value.sessionRuntimeDir),
|
|
56
59
|
runtimeLockDir: optionalAbsolutePath(value.runtimeLockDir),
|