evolcore 0.0.43-test.3 → 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 +82 -0
- package/bin/ecmsg.js +492 -0
- package/bin/install-codex-managed-hooks.mjs +130 -8
- package/dist/ability/application-service.js +37 -0
- package/dist/ability/resources.js +28 -0
- package/dist/ability/runtime.js +6 -1
- package/dist/agents/claude-runner.js +7 -5
- package/dist/agents/codex/app-server-client.js +0 -12
- package/dist/agents/codex-runner.js +12 -54
- package/dist/agents/ecagent-runner.js +130 -35
- package/dist/aun/aid/agentmd.js +56 -12
- 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/aun/menu/client.js +8 -7
- package/dist/aun/menu/index.js +1 -1
- package/dist/aun/menu/transport.js +8 -5
- package/dist/aun/service-proxy.js +3 -0
- package/dist/channels/aun.js +56 -22
- package/dist/channels/daemon.js +12 -4
- package/dist/cli/agent-command.js +5 -0
- package/dist/cli/agent-create.js +32 -8
- package/dist/cli/agent.js +9 -3
- package/dist/cli/aid-bind-command.js +3 -0
- package/dist/cli/aun-commands.js +12 -5
- package/dist/cli/code-stats.js +451 -213
- package/dist/cli/ctl-command.js +1 -3
- package/dist/cli/daemon-commands.js +42 -21
- package/dist/cli/directory.js +7 -8
- package/dist/cli/ecmsg-gateway.js +204 -0
- package/dist/cli/getmeta-command.js +2 -1
- package/dist/cli/index.js +6 -0
- package/dist/cli/init.js +58 -18
- 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/cli/trigger-command.js +20 -14
- package/dist/config/boot-log.js +23 -2
- package/dist/config/config-field-policy.js +2 -0
- package/dist/config/config-manager.js +13 -17
- package/dist/config/daemon-services.js +1 -0
- package/dist/config/peer-role-resolver.js +6 -6
- 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/role-schema.js +3 -3
- package/dist/config/schema-migration.js +188 -3
- package/dist/core/agent-application-service.js +11 -0
- package/dist/core/agent-ipc-registration.js +2 -0
- package/dist/core/agent-runtime.js +45 -11
- package/dist/core/auth/auth-gateway.js +8 -6
- package/dist/core/auth/delegation-diagnostics.js +6 -2
- package/dist/core/auth/operation-authorizer.js +5 -2
- package/dist/core/auth/operation-catalog.js +6 -4
- package/dist/core/baseagent-loader.js +11 -3
- package/dist/core/bootstrap-service.js +8 -0
- package/dist/core/channel-loader.js +61 -23
- package/dist/core/command/agent-control.js +4 -1
- package/dist/core/command/chatmode-config.js +46 -0
- package/dist/core/command/cli-intent-parser.js +2 -1
- package/dist/core/command/command-handler.js +16 -20
- package/dist/core/command/daemon-diagnostics.js +2 -1
- package/dist/core/command/menu-catalog.js +1 -1
- package/dist/core/command/menu-handler.js +16 -16
- 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 +56 -42
- package/dist/core/daemon-lifecycle.js +35 -17
- package/dist/core/event-catalog.js +19 -0
- package/dist/core/evolagent-registry.js +3 -0
- package/dist/core/handoff/runtime.js +9 -3
- package/dist/core/initialization/service.js +4 -3
- package/dist/core/ipc-registration.js +6 -0
- package/dist/core/message/aun-ipc-sender.js +81 -3
- package/dist/core/message/im-renderer.js +24 -19
- package/dist/core/message/message-admission.js +13 -2
- package/dist/core/message/response-engine.js +40 -41
- package/dist/core/message/send-options.js +40 -0
- package/dist/core/message/send-routing.js +310 -0
- package/dist/core/model/model-capabilities.js +37 -0
- package/dist/core/model/model-catalog.js +6 -2
- package/dist/core/ownership/owner-resolver.js +117 -14
- package/dist/core/permission/ec-command-parser.js +195 -27
- 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/plugin-lifecycle.js +6 -2
- package/dist/core/relation/pa-team.js +7 -2
- 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 +690 -99
- package/dist/directory/owner-directory-markdown.js +146 -36
- package/dist/directory/owner-directory-query-operation.js +7 -9
- 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 +38 -5
- package/dist/ecweb/runtime/supervisor.js +157 -49
- package/dist/index.js +202 -38
- package/dist/paths.js +2 -1
- package/dist/proxy/manager.js +2 -0
- package/dist/proxy/service-supervisor.js +379 -143
- package/dist/response-system/engines/v1/proactive-flow.js +4 -0
- package/dist/trigger/application-service.js +1 -0
- package/dist/trigger/audit.js +3 -2
- package/dist/trigger/authorization.js +2 -3
- package/dist/trigger/event-source.js +4 -0
- package/dist/trigger/feedback.js +26 -2
- package/dist/trigger/history.js +4 -3
- package/dist/trigger/ipc-service.js +24 -19
- package/dist/trigger/manager.js +3 -5
- package/dist/trigger/parser.js +4 -21
- package/dist/trigger/patch.js +3 -15
- package/dist/trigger/scheduler.js +48 -13
- package/dist/trigger/system-definitions.js +2 -2
- package/dist/trigger/validation.js +4 -13
- package/dist/utils/autostart.js +2 -2
- package/dist/utils/cross-platform.js +36 -8
- package/dist/utils/error-utils.js +8 -0
- package/dist/utils/macos-autostart.js +31 -0
- package/dist/utils/model-prices.jsonl +15 -8
- package/dist/utils/process-introspect.js +21 -1
- package/dist/utils/public-suffix.js +5811 -0
- package/dist/utils/startup-trace.js +7 -1
- package/dist/utils/windows-autostart.js +42 -7
- package/ecagent/dist/harness/compaction/branch-summarization.js +1 -1
- package/ecagent/dist/harness/compaction/compaction.js +4 -4
- 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 +3 -2
- 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/file-navigation.md +63 -49
- package/kits/docs/evolcore/group.md +6 -6
- package/kits/docs/evolcore/memory-consolidation.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +33 -3
- package/kits/docs/evolcore/model.md +5 -3
- package/kits/docs/evolcore/msg.md +28 -27
- package/kits/docs/evolcore/provider.md +39 -5
- package/kits/docs/evolcore/response.md +3 -1
- package/kits/docs/evolcore/thread-chain.md +12 -14
- package/kits/docs/evolcore/tool-authorization.md +21 -1
- package/kits/docs/evolcore/trigger.md +12 -9
- 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 -49
- package/kits/eck_manifest.memory.json +18 -18
- package/kits/rules/01-overview.md +43 -45
- package/kits/rules/02-navigation.md +44 -53
- package/kits/rules/03-identity.md +21 -25
- package/kits/rules/04-relation.md +23 -33
- package/kits/rules/05-venue.md +24 -25
- package/kits/rules/06-channel.md +3 -3
- package/kits/schemas/_meta.json +20 -27
- package/kits/schemas/agent-config.schema.19.json +10 -6
- package/kits/schemas/providers.schema.2.json +74 -0
- package/kits/schemas/relation-config.schema.12.json +2 -2
- package/kits/schemas/role-config.schema.2.json +5 -5
- 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 -0
- package/kits/skills/ec-trigger/SKILL.md +4 -4
- 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/identity.md +0 -1
- 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 +17 -13
- package/kits/schemas/agent-config.schema.20.json +0 -925
- package/kits/schemas/relation-config.schema.13.json +0 -289
- package/kits/schemas/role-config.schema.3.json +0 -1038
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
|
|
@@ -626,7 +626,7 @@ function printStartupInfo(opts = {}, asMode) {
|
|
|
626
626
|
console.log(` Daemon执行: ${daemonExecution}`);
|
|
627
627
|
}
|
|
628
628
|
if (!opts.statusLayout)
|
|
629
|
-
console.log(`
|
|
629
|
+
console.log(` 代码最新修改: ${latestMtime ? formatLocalTime(latestMtime) : '?'}`);
|
|
630
630
|
}
|
|
631
631
|
export async function cmdStart(opts = {}) {
|
|
632
632
|
// Measure from process start so the reported time includes CLI bootstrap
|
|
@@ -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)) {
|
|
@@ -941,6 +948,10 @@ export async function cmdStart(opts = {}) {
|
|
|
941
948
|
// ready signal 出现(优先检查,避免 Windows 上误判进程状态)
|
|
942
949
|
if (fs.existsSync(p.readySignal)) {
|
|
943
950
|
console.log(`✓ EvolCore started successfully (PID: ${childPid})`);
|
|
951
|
+
const daemonRecord = scanInstances().mains.find(entry => entry.alive && entry.record.pid === childPid)?.record;
|
|
952
|
+
if (daemonRecord?.startedAtIso) {
|
|
953
|
+
console.log(` Daemon 启动时间: ${new Date(daemonRecord.startedAtIso).toLocaleString()}`);
|
|
954
|
+
}
|
|
944
955
|
console.log(` EVOLCORE_HOME: ${resolveRoot()}`);
|
|
945
956
|
console.log(` Logs: ${p.logs}/`);
|
|
946
957
|
// ready 已到,先闭合 waitReady —— 后面的日志解析/代码统计是启动成功之后的开销,
|
|
@@ -982,8 +993,10 @@ export async function cmdStart(opts = {}) {
|
|
|
982
993
|
}
|
|
983
994
|
}
|
|
984
995
|
console.log('');
|
|
985
|
-
//
|
|
986
|
-
|
|
996
|
+
// 代码统计仅在开发仓(link 模式)显示。判据与「安装类型」一行保持一致:
|
|
997
|
+
// 看包路径是否含 node_modules,而不是比较 EVOLCORE_HOME 与包目录——
|
|
998
|
+
// 运行时 home 默认是 ~/.evolcore,那个比较永远不会成立。
|
|
999
|
+
if (packageIsDevMode()) {
|
|
987
1000
|
printCodeStats(getPackageRoot(), p.logs);
|
|
988
1001
|
}
|
|
989
1002
|
console.log(`⏱ done in ${((Date.now() - cmdStartedAt) / 1000).toFixed(1)}s`);
|
|
@@ -1922,16 +1935,8 @@ export async function cmdLogs(args) {
|
|
|
1922
1935
|
const moduleIdx = args.indexOf('--module');
|
|
1923
1936
|
const level = levelIdx !== -1 ? args[levelIdx + 1] : undefined;
|
|
1924
1937
|
const module = moduleIdx !== -1 ? args[moduleIdx + 1] : undefined;
|
|
1938
|
+
let managedRawAuthorized = false;
|
|
1925
1939
|
if (process.env.EVOLCORE_SESSION_ID) {
|
|
1926
|
-
if (raw) {
|
|
1927
|
-
const reason = '--raw is unavailable in managed tasks; use it from the host terminal';
|
|
1928
|
-
console.error(`EVOLCORE_TOOL_ERROR_V1 ${JSON.stringify({
|
|
1929
|
-
errorCode: 'POLICY_DENIED', decisionSource: 'policy', policyCode: 'managed_logs_raw', reason,
|
|
1930
|
-
})}`);
|
|
1931
|
-
console.error(`❌ [NOT_ALLOWED] ${reason}`);
|
|
1932
|
-
process.exitCode = 1;
|
|
1933
|
-
return;
|
|
1934
|
-
}
|
|
1935
1940
|
try {
|
|
1936
1941
|
const statusArgs = ['logs', ...args];
|
|
1937
1942
|
const result = await ipcQuery(resolvePaths().socket, {
|
|
@@ -1952,13 +1957,27 @@ export async function cmdLogs(args) {
|
|
|
1952
1957
|
process.exitCode = 1;
|
|
1953
1958
|
return;
|
|
1954
1959
|
}
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1960
|
+
if (raw) {
|
|
1961
|
+
if (result.data?.rawAuthorized !== true) {
|
|
1962
|
+
const reason = 'Managed raw logs were not authorized';
|
|
1963
|
+
console.error(`EVOLCORE_TOOL_ERROR_V1 ${JSON.stringify({
|
|
1964
|
+
errorCode: 'POLICY_DENIED', decisionSource: 'policy', policyCode: 'managed_logs_raw', reason,
|
|
1965
|
+
})}`);
|
|
1966
|
+
console.error(`❌ [NOT_ALLOWED] ${reason}`);
|
|
1967
|
+
process.exitCode = 1;
|
|
1968
|
+
return;
|
|
1969
|
+
}
|
|
1970
|
+
managedRawAuthorized = true;
|
|
1971
|
+
}
|
|
1972
|
+
else {
|
|
1973
|
+
const rows = Array.isArray(result.data?.lines) ? result.data.lines : [];
|
|
1974
|
+
const managedOpts = { level, module, color: false };
|
|
1975
|
+
for (const row of rows) {
|
|
1976
|
+
const line = typeof row?.raw === 'string' ? row.raw : JSON.stringify(row);
|
|
1977
|
+
const rendered = renderLogLine(line, { color: managedOpts.color });
|
|
1978
|
+
if (rendered !== null)
|
|
1979
|
+
process.stdout.write(rendered + '\n');
|
|
1980
|
+
}
|
|
1962
1981
|
}
|
|
1963
1982
|
}
|
|
1964
1983
|
catch (error) {
|
|
@@ -1968,8 +1987,10 @@ export async function cmdLogs(args) {
|
|
|
1968
1987
|
})}`);
|
|
1969
1988
|
console.error(`❌ logs 查询失败:${reason}`);
|
|
1970
1989
|
process.exitCode = 1;
|
|
1990
|
+
return;
|
|
1971
1991
|
}
|
|
1972
|
-
|
|
1992
|
+
if (!raw || !managedRawAuthorized)
|
|
1993
|
+
return;
|
|
1973
1994
|
}
|
|
1974
1995
|
const p = resolvePaths();
|
|
1975
1996
|
const mainLog = findLatestLog(p.logs, 'daemon');
|
package/dist/cli/directory.js
CHANGED
|
@@ -3,8 +3,7 @@ import { daemonUnavailableMessage, getArgValue, isHelpFlag, queryDaemon, wantsHe
|
|
|
3
3
|
import { AGENT_DELEGATION_TOKEN_ENV, readDelegationCredential } from '../core/auth/agent-delegation.js';
|
|
4
4
|
import { DirectoryQueryError, executeDirectoryQueryCommand, resolveDirectoryQueryCommand, } from '../directory/owner-directory-query-operation.js';
|
|
5
5
|
import { executeDirectoryRequestCommand, resolveDirectoryRequestCommand, } from '../directory/owner-directory-request-operation.js';
|
|
6
|
-
|
|
7
|
-
const QUERY_ACTIONS = new Set(['list', 'info', 'refresh', 'blocked', 'find', 'show']);
|
|
6
|
+
const QUERY_ACTIONS = new Set(['list', 'info', 'refresh', 'blocked']);
|
|
8
7
|
/**
|
|
9
8
|
* `ec directory ...`
|
|
10
9
|
*
|
|
@@ -12,8 +11,7 @@ const QUERY_ACTIONS = new Set(['list', 'info', 'refresh', 'blocked', 'find', 'sh
|
|
|
12
11
|
* 直接读写自己目录下的 `<agent>/directory/remarks/<联系人AID>.md`,改完再
|
|
13
12
|
* `ec directory refresh` 让 `directory.md` 重算。
|
|
14
13
|
*
|
|
15
|
-
* 命令面与 `ec skill` 对齐:`list` 列举/过滤(含分页),`info`
|
|
16
|
-
* 旧的 `find` / `show` 保留为别名。
|
|
14
|
+
* 命令面与 `ec skill` 对齐:`list` 列举/过滤(含分页),`info` 看单条详情。
|
|
17
15
|
*/
|
|
18
16
|
export async function cmdDirectory(args) {
|
|
19
17
|
if (args.length === 0 || isHelpFlag(args[0]) || wantsHelp(args)) {
|
|
@@ -178,7 +176,7 @@ async function runManaged(argv, json) {
|
|
|
178
176
|
}
|
|
179
177
|
function printHelp() {
|
|
180
178
|
console.log(`用法:
|
|
181
|
-
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>]
|
|
182
180
|
ec directory info <contact-aid|名字> [--limit <n>]
|
|
183
181
|
ec directory refresh
|
|
184
182
|
ec directory blocked
|
|
@@ -190,15 +188,16 @@ request:向目标发送 app-v1 friend.invite.v1 加好友申请;介绍默认
|
|
|
190
188
|
list:
|
|
191
189
|
列举名录;给关键词时按 AID、名字、备注、描述、exttype 做子串匹配(不区分大小写)。
|
|
192
190
|
--filter 与 ec skill list --filter 同语义:组内逗号分隔为 OR,多个 --filter 之间为 AND;
|
|
193
|
-
|
|
191
|
+
位置参数按“多个词同时命中”处理。
|
|
194
192
|
默认每页 20 条,--page / --limit 可翻页;输出包含 type、exttype、描述、备注、
|
|
195
193
|
Owner 绑定关系与 Ownership 核验状态。本地备注正文不在 list 展示。
|
|
196
|
-
|
|
194
|
+
--scope internal|external|pa-team|all(默认 all):pa-team 只列 open_pa_context
|
|
195
|
+
里且 ownership_status=owned 的成员。
|
|
197
196
|
|
|
198
197
|
info:
|
|
199
198
|
接受 AID 或名字。AID 大小写不敏感、可带 @ 前缀;名字先做归一后的精确匹配
|
|
200
199
|
(全角/半角、空格、结尾括号称呼不影响),没命中再按名字包含匹配,结果标
|
|
201
|
-
matchKind=fuzzy
|
|
200
|
+
matchKind=fuzzy。返回完整记录(含本地备注正文)。
|
|
202
201
|
|
|
203
202
|
refresh:
|
|
204
203
|
拉一次最新名录并重算 directory.md / identity.json。拉取需要 channel 在线;
|
|
@@ -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
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import fs from 'fs';
|
|
3
|
+
import { loadAgent } from '../config-store.js';
|
|
3
4
|
import { resolvePaths, agentThreadIndexPath, agentTriggersDir } from '../paths.js';
|
|
4
5
|
import { scanChatDirs, readLastJsonlLine, } from '../core/session/session-fs-store.js';
|
|
5
6
|
import { isMainTopicId } from '../core/thread/topic-id.js';
|
|
@@ -147,7 +148,7 @@ async function cmdGetTriggerMeta(id, selfFilter, jsonFormat) {
|
|
|
147
148
|
agentAid: def.agentAid,
|
|
148
149
|
name: def.name,
|
|
149
150
|
enabled: def.enabled,
|
|
150
|
-
baseagent: def.execution.
|
|
151
|
+
baseagent: def.execution.type === 'trigger_session' ? loadAgent(def.agentAid)?.active_baseagent ?? null : null,
|
|
151
152
|
executionSessionId,
|
|
152
153
|
originChannelKey: def.origin?.channelKey ?? null,
|
|
153
154
|
originChannelId: def.origin?.channelId ?? null,
|
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,9 +122,30 @@ 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) {
|
|
145
|
+
if (result.nonFatal) {
|
|
146
|
+
console.log(`⚠ ${autostartPlatformLabel() || '登录自启'}未配置:${result.error || '检测到外部配置占用,未覆盖。'}`);
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
128
149
|
console.log(`❌ ${autostartPlatformLabel() || '登录自启'}配置失败: ${result.error || '未知错误'}`);
|
|
129
150
|
printWindowsAutostartRetryInstructions(enabled);
|
|
130
151
|
}
|
|
@@ -175,6 +196,12 @@ export async function ensureEcwebInstalledForInit(options = {}) {
|
|
|
175
196
|
}
|
|
176
197
|
export async function cmdInitWeb(dependencies = {}) {
|
|
177
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
|
+
}
|
|
178
205
|
ensureDataDirs();
|
|
179
206
|
const daemonRunning = dependencies.isDaemonRunning?.()
|
|
180
207
|
?? scanInstances().mains.some(instance => instance.alive);
|
|
@@ -204,6 +231,10 @@ export async function cmdInitWeb(dependencies = {}) {
|
|
|
204
231
|
console.error("❌ 主机控制 AID 未配置。");
|
|
205
232
|
return false;
|
|
206
233
|
}
|
|
234
|
+
if (!hasIdentity(controlAid)) {
|
|
235
|
+
console.error(`❌ ${missingControlIdentityMessage(controlAid)}`);
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
207
238
|
if (config.owner) {
|
|
208
239
|
try {
|
|
209
240
|
await submitControlAidRegistration(controlAid, config.owner);
|
|
@@ -212,11 +243,16 @@ export async function cmdInitWeb(dependencies = {}) {
|
|
|
212
243
|
console.warn(`⚠️ 主机控制 AID Owner 绑定暂未提交,将由 daemon 后续重试: ${installErrorMessage(error)}`);
|
|
213
244
|
}
|
|
214
245
|
}
|
|
215
|
-
|
|
216
|
-
|
|
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
|
+
}
|
|
217
253
|
}
|
|
218
|
-
|
|
219
|
-
console.
|
|
254
|
+
else {
|
|
255
|
+
console.log('ℹ 主机名片将在 Web 初始化完成 Owner 绑定后发布。');
|
|
220
256
|
}
|
|
221
257
|
if (ecwebService(config.services)?.enabled !== true) {
|
|
222
258
|
config = { ...config, services: setEcwebEnabled(config.services, true) };
|
|
@@ -280,7 +316,7 @@ export async function cmdInit(options) {
|
|
|
280
316
|
// A bound installation may toggle login autostart independently of the
|
|
281
317
|
// Baseagent setup wizard. This is also the path used by public installers.
|
|
282
318
|
if (isAutostartOnlyRequest(options) && hasCompletedInitConfig()) {
|
|
283
|
-
return applyExplicitAutostart(options.autoStart, p.root);
|
|
319
|
+
return applyExplicitAutostart(options.autoStart, p.root, !options?.nonInteractive);
|
|
284
320
|
}
|
|
285
321
|
// ── 1. 单进程互斥 ──
|
|
286
322
|
const aliveMains = scanInstances().mains.filter(m => m.alive);
|
|
@@ -288,7 +324,7 @@ export async function cmdInit(options) {
|
|
|
288
324
|
// Explicit autostart flags only change the login task; they do not need
|
|
289
325
|
// to rewrite init configuration or stop an already running daemon.
|
|
290
326
|
if (isAutostartOnlyRequest(options)) {
|
|
291
|
-
return applyExplicitAutostart(options.autoStart, p.root);
|
|
327
|
+
return applyExplicitAutostart(options.autoStart, p.root, !options?.nonInteractive);
|
|
292
328
|
}
|
|
293
329
|
const pids = aliveMains.map(m => m.record.pid).join(', ');
|
|
294
330
|
console.log(`❌ EvolCore 正在运行 (PID: ${pids}),请先执行 ec stop`);
|
|
@@ -504,7 +540,6 @@ export async function initTail(options = {}) {
|
|
|
504
540
|
const daemonConfig = loadDaemonConfig();
|
|
505
541
|
let controlAidReady = !!daemonConfig.aid;
|
|
506
542
|
let autoStartReady = true;
|
|
507
|
-
const autoStartExplicit = options.autoStart !== undefined;
|
|
508
543
|
if (daemonConfig.aid) {
|
|
509
544
|
console.log(`✓ 控制 AID 已存在: ${daemonConfig.aid}`);
|
|
510
545
|
}
|
|
@@ -543,7 +578,7 @@ export async function initTail(options = {}) {
|
|
|
543
578
|
return false;
|
|
544
579
|
}
|
|
545
580
|
if (options.autoStart !== undefined) {
|
|
546
|
-
autoStartReady = applyAutostart(options.autoStart);
|
|
581
|
+
autoStartReady = await applyAutostart(options.autoStart);
|
|
547
582
|
}
|
|
548
583
|
}
|
|
549
584
|
const configuredOwner = loadDaemonConfig().owner;
|
|
@@ -561,7 +596,7 @@ export async function initTail(options = {}) {
|
|
|
561
596
|
}
|
|
562
597
|
async function handleAutostartPrompt() {
|
|
563
598
|
if (options.autoStart !== undefined) {
|
|
564
|
-
autoStartReady = applyAutostart(options.autoStart);
|
|
599
|
+
autoStartReady = await applyAutostart(options.autoStart);
|
|
565
600
|
return;
|
|
566
601
|
}
|
|
567
602
|
if (!autostartPlatformLabel())
|
|
@@ -570,11 +605,15 @@ export async function initTail(options = {}) {
|
|
|
570
605
|
console.log(`✓ ${autostartPlatformLabel()} 登录自启已启用`);
|
|
571
606
|
return;
|
|
572
607
|
}
|
|
573
|
-
autoStartReady = applyAutostart(true);
|
|
608
|
+
autoStartReady = await applyAutostart(true);
|
|
574
609
|
}
|
|
575
|
-
function applyAutostart(enabled) {
|
|
576
|
-
const result =
|
|
610
|
+
async function applyAutostart(enabled) {
|
|
611
|
+
const result = await configureAutostartForInit(enabled, resolvePaths().root, !options?.nonInteractive);
|
|
577
612
|
if (!result.ok) {
|
|
613
|
+
if (result.nonFatal) {
|
|
614
|
+
console.log(` ⚠ ${autostartPlatformLabel() || '登录自启'}未配置:${result.error || '检测到外部配置占用,未覆盖。'}`);
|
|
615
|
+
return true;
|
|
616
|
+
}
|
|
578
617
|
console.log(` ❌ ${autostartPlatformLabel() || '登录自启'}配置失败: ${result.error || '未知错误'}`);
|
|
579
618
|
printWindowsAutostartRetryInstructions(enabled);
|
|
580
619
|
return false;
|
|
@@ -643,8 +682,6 @@ export async function initTail(options = {}) {
|
|
|
643
682
|
return false;
|
|
644
683
|
}
|
|
645
684
|
if (!autoStartReady) {
|
|
646
|
-
if (autoStartExplicit)
|
|
647
|
-
return false;
|
|
648
685
|
console.log(' ⚠️ 登录自启配置未完成,可稍后运行 ec init --auto-start 重试');
|
|
649
686
|
}
|
|
650
687
|
// 初始化完成总结
|
|
@@ -861,14 +898,17 @@ export async function cmdInitNonInteractive(opts, dependencies = {}) {
|
|
|
861
898
|
if (opts.autoStart !== undefined) {
|
|
862
899
|
const autostart = configureAutostart(opts.autoStart, p.root);
|
|
863
900
|
if (!autostart.ok) {
|
|
864
|
-
|
|
901
|
+
if (!autostart.nonFatal) {
|
|
902
|
+
fail('AUTOSTART_CONFIG_FAILED', autostart.error || 'failed to configure login autostart', EXIT_RUNTIME, format);
|
|
903
|
+
}
|
|
904
|
+
autostartWarning = autostart.error || 'login autostart was not changed because an external configuration owns the same name';
|
|
865
905
|
}
|
|
866
906
|
if (opts.autoStart === true && autostart.backend) {
|
|
867
907
|
// Keep the selected Windows backend visible to automation callers as
|
|
868
908
|
// well as in data/autostart-state.json.
|
|
869
909
|
autostartBackend = autostart.backend;
|
|
870
910
|
}
|
|
871
|
-
autostartWarning = autostart.warning;
|
|
911
|
+
autostartWarning = autostart.warning || (autostart.nonFatal ? autostart.error : undefined);
|
|
872
912
|
}
|
|
873
913
|
// ── 10. 复用 Agent 创建流程的显式 Owner 绑定;不等待人工审批 ──
|
|
874
914
|
let binding;
|