evolcore 0.0.43-test.4 → 0.0.43-test.6
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 +93 -0
- package/bin/ecmsg.js +437 -91
- package/dist/agents/baseagent-availability.js +19 -4
- package/dist/agents/baseagent.js +2 -2
- package/dist/agents/claude-runner.js +19 -4
- package/dist/agents/codex/app-server-client.js +14 -3
- package/dist/agents/codex-runner.js +18 -23
- 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/aun/group/invite-service.js +3 -2
- package/dist/aun/service-proxy.js +18 -6
- package/dist/channels/aun.js +99 -23
- package/dist/channels/daemon.js +2 -2
- package/dist/cli/agent-create.js +19 -7
- package/dist/cli/aid-bind-command.js +3 -0
- package/dist/cli/aun-commands.js +19 -4
- package/dist/cli/code-stats.js +451 -213
- package/dist/cli/ctl-command.js +1 -3
- package/dist/cli/daemon-commands.js +42 -4
- package/dist/cli/directory.js +3 -1
- package/dist/cli/ecmsg-gateway.js +206 -0
- package/dist/cli/index.js +6 -0
- package/dist/cli/init.js +120 -13
- package/dist/cli/provider-command.js +82 -5
- package/dist/cli/restart-monitor.js +35 -24
- package/dist/cli/stats.js +8 -1
- package/dist/cli/task-context.js +41 -1
- package/dist/cli/watch-logs.js +6 -4
- package/dist/config/boot-log.js +16 -3
- package/dist/config/builtin-roles.js +2 -2
- package/dist/config/config-manager.js +5 -14
- package/dist/config/daemon-services.js +1 -0
- package/dist/config/peer-role-resolver.js +6 -6
- package/dist/config/provider-identity-migration.js +277 -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 +155 -0
- package/dist/config/providers-config.js +45 -4
- package/dist/config/providers-management.js +242 -76
- package/dist/config/providers.js +4 -1
- package/dist/config/role-service.js +8 -8
- package/dist/config/role-store.js +22 -22
- package/dist/config/schema-migration.js +143 -86
- package/dist/config/snapshot.js +70 -41
- package/dist/core/agent-runtime.js +48 -9
- 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/baseagent-loader.js +114 -11
- package/dist/core/channel-loader.js +36 -13
- package/dist/core/channel-runtime.js +112 -42
- package/dist/core/command/cli-intent-parser.js +2 -1
- package/dist/core/command/command-handler.js +16 -11
- package/dist/core/command/menu-handler.js +8 -3
- package/dist/core/command/menu-protocol.js +80 -7
- package/dist/core/command/provider-menu.js +4 -2
- package/dist/core/command/role-menu.js +29 -17
- package/dist/core/command/slash-handler.js +52 -16
- package/dist/core/daemon-control.js +42 -15
- package/dist/core/daemon-lifecycle.js +411 -67
- package/dist/core/handoff/dispatcher.js +9 -3
- package/dist/core/handoff/runtime.js +139 -45
- package/dist/core/handoff/store.js +190 -2
- package/dist/core/handoff/types.js +5 -0
- package/dist/core/initialization/service.js +7 -6
- package/dist/core/ipc-registration.js +5 -4
- package/dist/core/lifecycle-notice.js +10 -4
- package/dist/core/message/aun-ipc-sender.js +83 -5
- package/dist/core/message/message-admission.js +2 -0
- package/dist/core/message/message-bridge.js +53 -4
- package/dist/core/message/message-queue.js +46 -4
- package/dist/core/message/pending-hints.js +4 -10
- package/dist/core/message/response-engine.js +33 -25
- package/dist/core/message/send-options.js +40 -0
- package/dist/core/message/send-routing.js +320 -0
- package/dist/core/ownership/owner-resolver.js +112 -8
- package/dist/core/permission/ec-command-parser.js +159 -16
- 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/adapters/claude-session-file-adapter.js +24 -0
- package/dist/core/session/adapters/codex-session-file-adapter.js +80 -0
- package/dist/core/session/adapters/ecagent-session-file-adapter.js +22 -0
- package/dist/core/session/adapters/gemini-session-file-adapter.js +39 -0
- package/dist/core/session/session-fs-store.js +164 -3
- package/dist/core/session/session-idle-monitor.js +103 -17
- package/dist/core/session/session-manager.js +105 -18
- package/dist/core/thread/thread-route.js +5 -2
- package/dist/directory/owner-directory-admission.js +26 -1
- package/dist/directory/owner-directory-cache.js +739 -109
- package/dist/directory/owner-directory-markdown.js +146 -36
- package/dist/directory/owner-directory-query-operation.js +6 -3
- 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 +26 -15
- package/dist/ecweb/runtime/supervisor.js +120 -51
- package/dist/index.js +551 -250
- package/dist/paths.js +2 -1
- package/dist/proxy/manager.js +40 -17
- package/dist/proxy/service-supervisor.js +67 -33
- package/dist/response-system/engines/v1/proactive-flow.js +4 -0
- package/dist/trigger/application-service.js +4 -1
- package/dist/trigger/audit.js +19 -4
- package/dist/trigger/authorization.js +14 -5
- package/dist/trigger/event-source.js +4 -0
- package/dist/trigger/feedback.js +26 -2
- package/dist/trigger/history.js +176 -7
- package/dist/trigger/manager.js +1 -3
- package/dist/trigger/scheduler.js +81 -8
- 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 +188 -12
- package/dist/utils/host-info.js +11 -8
- package/dist/utils/npm-ops.js +48 -0
- package/dist/utils/process-introspect.js +64 -1
- package/dist/utils/public-suffix.js +5811 -0
- package/dist/utils/startup-trace.js +160 -19
- package/dist/utils/windows-autostart.js +41 -7
- package/ecagent/dist/harness/env/nodejs.js +46 -2
- package/kits/docs/aun/ABILITY_CALLING.md +6 -6
- 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 +5 -3
- package/kits/docs/evolcore/agent.md +2 -2
- package/kits/docs/evolcore/aid.md +8 -2
- package/kits/docs/evolcore/ctl.md +15 -5
- package/kits/docs/evolcore/directory.md +48 -15
- package/kits/docs/evolcore/group.md +8 -8
- package/kits/docs/evolcore/memory-consolidation.md +1 -1
- package/kits/docs/evolcore/menu-exec-schema-commands.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +32 -3
- package/kits/docs/evolcore/msg.md +38 -30
- package/kits/docs/evolcore/provider.md +57 -5
- package/kits/docs/evolcore/response.md +2 -2
- 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 +44 -32
- package/kits/eck_manifest.memory.json +18 -18
- package/kits/eck_message_manifest.json +3 -3
- package/kits/rules/01-overview.md +1 -1
- package/kits/rules/06-channel.md +7 -8
- package/kits/schemas/_meta.json +7 -1
- package/kits/schemas/daemon.schema.1.json +5 -0
- package/kits/schemas/daemon.schema.2.json +5 -0
- package/kits/schemas/daemon.schema.3.json +2 -1
- package/kits/schemas/daemon.schema.4.json +2 -1
- package/kits/schemas/daemon.schema.5.json +2 -1
- package/kits/schemas/daemon.schema.6.json +1 -1
- package/kits/schemas/daemon.schema.7.json +1 -1
- package/kits/schemas/daemon.schema.8.json +2 -1
- package/kits/schemas/daemon.schema.9.json +2 -1
- package/kits/schemas/providers.schema.2.json +74 -0
- package/kits/schemas/role-registry.schema.1.json +2 -2
- package/kits/schemas/single-session.schema.1.json +1 -1
- package/kits/schemas/single-session.schema.2.json +1 -1
- package/kits/schemas/single-session.schema.3.json +1 -1
- package/kits/skills/aid-ability/SKILL.md +7 -7
- package/kits/skills/ec-agent-create/SKILL.md +1 -0
- package/kits/skills/ec-group/SKILL.md +8 -5
- package/kits/skills/ec-group-collaboration/SKILL.md +7 -7
- package/kits/skills/ec-service-proxy/SKILL.md +3 -10
- package/kits/skills/ec-trigger/SKILL.md +9 -9
- package/kits/skills/ec-trigger/references/examples.md +1 -1
- package/kits/skills/thread-ops/SKILL.md +10 -10
- package/kits/templates/system-fragments/channel.md +5 -5
- package/kits/templates/system-fragments/commands.md +7 -6
- 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 +48 -28
- package/kits/templates/system-fragments/session.md +3 -10
- package/kits/templates/system-fragments/thread.md +5 -5
- package/package.json +4 -4
|
@@ -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) : data.warnings?.includes('CONFIG_SNAPSHOTS_DISABLED') ? '无(配置快照已关闭)' : '无(未产生变更)'}`);
|
|
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,8 @@ 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 {
|
|
24
|
-
import { WEB_PACKAGE_NAME } from '../product.js';
|
|
22
|
+
import { stopEcwebForRestart } from '../ecweb/runtime/lifecycle.js';
|
|
23
|
+
import { StartupTracer, STARTUP_TRACE_ID_ENV } from '../utils/startup-trace.js';
|
|
25
24
|
const execFileAsync = promisify(execFile);
|
|
26
25
|
/** Read-only check performed before stopping the current daemon. */
|
|
27
26
|
function preflightDataMigration(root, log) {
|
|
@@ -206,9 +205,7 @@ export async function cmdRestartMonitor() {
|
|
|
206
205
|
const s = scanInstances();
|
|
207
206
|
if (!s.mains.some(m => m.alive))
|
|
208
207
|
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);
|
|
208
|
+
return true;
|
|
212
209
|
};
|
|
213
210
|
const markRequestReady = () => {
|
|
214
211
|
if (!hasCorrelatedRequest)
|
|
@@ -226,6 +223,14 @@ export async function cmdRestartMonitor() {
|
|
|
226
223
|
};
|
|
227
224
|
// Keep this path available for a failed read-only preflight so a stale
|
|
228
225
|
// restart request cannot be replayed by a later daemon startup.
|
|
226
|
+
const trace = new StartupTracer('restart-monitor', {
|
|
227
|
+
traceId: process.env[STARTUP_TRACE_ID_ENV] || undefined,
|
|
228
|
+
firstPhase: 'monitor.bootstrap',
|
|
229
|
+
});
|
|
230
|
+
delete process.env[STARTUP_TRACE_ID_ENV];
|
|
231
|
+
trace.setMeta('operation', 'restart');
|
|
232
|
+
process.once('exit', () => trace.finish(false));
|
|
233
|
+
trace.mark('monitor.preflight');
|
|
229
234
|
log(`Restart monitor started (requestId=${requestId})`);
|
|
230
235
|
// 升级成功时记下版本变化,回执里要告诉 agent 实际跑的是哪个版本。
|
|
231
236
|
let upgradeVersions;
|
|
@@ -272,6 +277,7 @@ export async function cmdRestartMonitor() {
|
|
|
272
277
|
}
|
|
273
278
|
}
|
|
274
279
|
updateRestartMonitorPhase(process.pid, 'accepted');
|
|
280
|
+
trace.mark('monitor.stopDaemon');
|
|
275
281
|
log('Restart monitor accepted after migration preflight and monitor election');
|
|
276
282
|
if (upgradeJob) {
|
|
277
283
|
updateUpgradeJob(upgradeJob.jobId, { status: 'restart-started', success: true, phase: 'restart' }, '预检通过,已进入重启执行;不代表新进程已就绪');
|
|
@@ -445,6 +451,7 @@ export async function cmdRestartMonitor() {
|
|
|
445
451
|
cleanupPendingFile(pendingFile, log, hasCorrelatedRequest ? requestId : undefined);
|
|
446
452
|
process.exit(1);
|
|
447
453
|
}
|
|
454
|
+
trace.mark('monitor.packageUpgrade');
|
|
448
455
|
let upgradeBackup = null;
|
|
449
456
|
let upgrade;
|
|
450
457
|
if (applyPackageUpgrades) {
|
|
@@ -507,6 +514,7 @@ export async function cmdRestartMonitor() {
|
|
|
507
514
|
}
|
|
508
515
|
// 编译在 daemon 停止之后、拉起之前:此时没有活进程占着 dist/,
|
|
509
516
|
// 失败还能回滚到上一份可用产物,因此这一步整体是可撤销的。
|
|
517
|
+
trace.mark('monitor.sourceBuild');
|
|
510
518
|
const buildOutcome = await buildSourcesTransactionally(log);
|
|
511
519
|
if (buildOutcome.status === 'failed') {
|
|
512
520
|
const message = `服务未重启:${buildOutcome.reason ?? '构建失败'}`;
|
|
@@ -520,6 +528,7 @@ export async function cmdRestartMonitor() {
|
|
|
520
528
|
log(`↩ ${buildOutcome.reason ?? '已回滚'};继续以上一版本启动`);
|
|
521
529
|
await notifyDaemonOwners(p, `⚠️ ${buildOutcome.reason ?? '已回滚'},正在以上一版本启动服务`, log);
|
|
522
530
|
}
|
|
531
|
+
trace.mark('monitor.dataMigration');
|
|
523
532
|
const migration = applyPendingDataMigration(p.root, log);
|
|
524
533
|
if (!migration.ok) {
|
|
525
534
|
const message = `服务未重启:用户数据迁移失败(${migration.reason ?? 'unknown error'})`;
|
|
@@ -531,7 +540,7 @@ export async function cmdRestartMonitor() {
|
|
|
531
540
|
// daemon's own launcher and ECWeb's stale-instance cleanup, which could
|
|
532
541
|
// leave ServiceProxy pointed at a dead PID.
|
|
533
542
|
// 启动并检测 ready signal
|
|
534
|
-
let started = await spawnAndWaitReady(p, log, READY_TIMEOUT);
|
|
543
|
+
let started = await spawnAndWaitReady(p, log, READY_TIMEOUT, trace);
|
|
535
544
|
if (started) {
|
|
536
545
|
if (upgrade.status === 'upgraded' || upgrade.status === 'failed') {
|
|
537
546
|
await recordPackageUpgrade(MAIN_PACKAGE_NAME, {
|
|
@@ -569,7 +578,7 @@ export async function cmdRestartMonitor() {
|
|
|
569
578
|
}, log);
|
|
570
579
|
if (await restoreDistBackup(upgradeBackup, log)) {
|
|
571
580
|
await notifyDaemonOwners(p, `⚠️ 升级到 ${upgradeVersions.to} 后启动失败,正在回滚到 ${upgradeVersions.from} 重试...`, log);
|
|
572
|
-
started = await spawnAndWaitReady(p, log, READY_TIMEOUT);
|
|
581
|
+
started = await spawnAndWaitReady(p, log, READY_TIMEOUT, trace);
|
|
573
582
|
if (started) {
|
|
574
583
|
const reason = `升级到 ${upgradeVersions.to} 后启动失败,已回滚到 ${upgradeVersions.from}`;
|
|
575
584
|
await recordPackageUpgrade(MAIN_PACKAGE_NAME, {
|
|
@@ -590,7 +599,7 @@ export async function cmdRestartMonitor() {
|
|
|
590
599
|
const reverted = await revertToPreviousBuild(log);
|
|
591
600
|
if (reverted) {
|
|
592
601
|
await notifyDaemonOwners(p, '⚠️ 新编译产物启动失败,正在回滚到上一版本重试...', log);
|
|
593
|
-
started = await spawnAndWaitReady(p, log, READY_TIMEOUT);
|
|
602
|
+
started = await spawnAndWaitReady(p, log, READY_TIMEOUT, trace);
|
|
594
603
|
if (started) {
|
|
595
604
|
const reason = '新编译产物启动失败,已回滚到上一个可用版本';
|
|
596
605
|
log(`✓ ${reason}`);
|
|
@@ -668,7 +677,7 @@ export async function cmdRestartMonitor() {
|
|
|
668
677
|
continue;
|
|
669
678
|
}
|
|
670
679
|
// claude 正常完成但服务没自动启动,尝试 spawn
|
|
671
|
-
started = await spawnAndWaitReady(p, log, READY_TIMEOUT);
|
|
680
|
+
started = await spawnAndWaitReady(p, log, READY_TIMEOUT, trace);
|
|
672
681
|
if (started) {
|
|
673
682
|
log(`✓ Self-heal succeeded on attempt ${attempt}`);
|
|
674
683
|
markRequestReady();
|
|
@@ -1100,13 +1109,11 @@ function cleanupPendingFile(filePath, log, requestId) {
|
|
|
1100
1109
|
/**
|
|
1101
1110
|
* 启动新进程并等待 ready.signal
|
|
1102
1111
|
*/
|
|
1103
|
-
async function spawnAndWaitReady(p, log, timeout) {
|
|
1112
|
+
async function spawnAndWaitReady(p, log, timeout, trace) {
|
|
1113
|
+
trace.mark('monitor.spawnDaemon');
|
|
1104
1114
|
const ecweb = ecwebService(loadDaemonConfig().services);
|
|
1105
1115
|
const requireEcweb = ecweb?.enabled === true && serviceRuntimeMode(ecweb) === 'managed';
|
|
1106
1116
|
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
1117
|
// 删除旧的 ready signal
|
|
1111
1118
|
try {
|
|
1112
1119
|
fs.unlinkSync(p.readySignal);
|
|
@@ -1135,6 +1142,7 @@ async function spawnAndWaitReady(p, log, timeout) {
|
|
|
1135
1142
|
...process.env,
|
|
1136
1143
|
EVOLCORE_HOME: p.root,
|
|
1137
1144
|
EVOLCORE_LAUNCHED_BY: 'restart-monitor',
|
|
1145
|
+
[STARTUP_TRACE_ID_ENV]: trace.id,
|
|
1138
1146
|
[RESTART_REQUEST_ID_ENV]: '',
|
|
1139
1147
|
LOG_LEVEL: process.env.LOG_LEVEL || 'INFO',
|
|
1140
1148
|
MESSAGE_LOG: process.env.MESSAGE_LOG || 'true',
|
|
@@ -1143,6 +1151,8 @@ async function spawnAndWaitReady(p, log, timeout) {
|
|
|
1143
1151
|
}
|
|
1144
1152
|
});
|
|
1145
1153
|
const childPid = child.pid;
|
|
1154
|
+
trace.setMeta('daemonPid', String(childPid));
|
|
1155
|
+
trace.mark('monitor.waitReady');
|
|
1146
1156
|
if (foreground) {
|
|
1147
1157
|
foregroundDaemonExit = new Promise(resolve => {
|
|
1148
1158
|
child.once('error', () => resolve(1));
|
|
@@ -1154,7 +1164,6 @@ async function spawnAndWaitReady(p, log, timeout) {
|
|
|
1154
1164
|
fs.closeSync(out);
|
|
1155
1165
|
fs.closeSync(err);
|
|
1156
1166
|
log(`Spawned new process PID: ${childPid}, waiting for ready signal...`);
|
|
1157
|
-
let waitingForEcweb = false;
|
|
1158
1167
|
// 轮询等待 ready.signal 出现
|
|
1159
1168
|
const start = Date.now();
|
|
1160
1169
|
while (Date.now() - start < timeout) {
|
|
@@ -1167,16 +1176,18 @@ async function spawnAndWaitReady(p, log, timeout) {
|
|
|
1167
1176
|
return false;
|
|
1168
1177
|
}
|
|
1169
1178
|
if (fs.existsSync(p.readySignal)) {
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
}
|
|
1174
|
-
if (!waitingForEcweb)
|
|
1175
|
-
log(`Daemon ready; waiting for identified ECWeb readiness on port ${ecwebPort}`);
|
|
1176
|
-
waitingForEcweb = true;
|
|
1179
|
+
log('Daemon ready; managed services are supervised independently');
|
|
1180
|
+
trace.finish(true);
|
|
1181
|
+
return true;
|
|
1177
1182
|
}
|
|
1178
1183
|
}
|
|
1179
|
-
|
|
1184
|
+
const ping = await ipcQuery(p.socket, { type: 'ping' }, platform.isWindows ? 5_000 : 1_000);
|
|
1185
|
+
if (ping?.pong === true && ping.pid === childPid && platform.isProcessRunning(childPid)) {
|
|
1186
|
+
log(`Daemon IPC is ready (PID: ${childPid}); startup finalization and managed services continue in background`);
|
|
1187
|
+
trace.finish(true);
|
|
1188
|
+
return true;
|
|
1189
|
+
}
|
|
1190
|
+
log(`Daemon ready signal not received within ${timeout / 1000}s and identified IPC is unavailable`);
|
|
1180
1191
|
// A timeout is still a live-process race: do not let self-heal spawn a
|
|
1181
1192
|
// replacement while the timed-out daemon owns the IPC endpoint or a port.
|
|
1182
1193
|
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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { normalizeCausation } from '../core/causation/context.js';
|
|
2
2
|
import { RUNTIME_LOCK_DIR_ENV } from '../core/runtime-lock.js';
|
|
3
3
|
import crypto from 'node:crypto';
|
|
4
|
-
import { execFileSync } from 'node:child_process';
|
|
4
|
+
import { execFile, execFileSync } from 'node:child_process';
|
|
5
5
|
import fs from 'node:fs';
|
|
6
6
|
import os from 'node:os';
|
|
7
7
|
import path from 'node:path';
|
|
@@ -14,6 +14,7 @@ export const DAEMON_RUNTIME_EPOCH_ENV = 'EVOLCORE_DAEMON_RUNTIME_EPOCH';
|
|
|
14
14
|
export { RUNTIME_LOCK_DIR_ENV };
|
|
15
15
|
const generatedProcessManagedTempDirs = new Set();
|
|
16
16
|
const preparedWindowsSessionRuntimeDirs = new Set();
|
|
17
|
+
const pendingSessionRuntimeDirs = new Map();
|
|
17
18
|
let processTempCleanupRegistered = false;
|
|
18
19
|
function isPlainObject(value) {
|
|
19
20
|
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
@@ -51,6 +52,9 @@ function normalizeTaskRuntimeContext(value) {
|
|
|
51
52
|
|| value.executionSource === 'session-policy'
|
|
52
53
|
? value.executionSource : undefined,
|
|
53
54
|
daemonRuntimeEpoch: optionalString(value.daemonRuntimeEpoch),
|
|
55
|
+
// 仅观测字段,但必须留在白名单里:丢掉它,ecmsg 的 --encrypt auto 就永远
|
|
56
|
+
// 判定为"非入站触发",密文会话里的回复会退化成明文。
|
|
57
|
+
inboundEncrypted: typeof value.inboundEncrypted === 'boolean' ? value.inboundEncrypted : undefined,
|
|
54
58
|
threadId: optionalString(value.threadId),
|
|
55
59
|
sessionRuntimeDir: optionalAbsolutePath(value.sessionRuntimeDir),
|
|
56
60
|
runtimeLockDir: optionalAbsolutePath(value.runtimeLockDir),
|
|
@@ -310,6 +314,42 @@ export function ensureSessionRuntimeDir(sessionId) {
|
|
|
310
314
|
return undefined;
|
|
311
315
|
}
|
|
312
316
|
}
|
|
317
|
+
/** Await ACL preparation without blocking unrelated sessions or daemon I/O. */
|
|
318
|
+
export async function ensureSessionRuntimeDirAsync(sessionId) {
|
|
319
|
+
if (!sessionId)
|
|
320
|
+
return undefined;
|
|
321
|
+
const root = systemTempRoot();
|
|
322
|
+
const directory = path.join(root, sessionRuntimeName(sessionId));
|
|
323
|
+
const pending = pendingSessionRuntimeDirs.get(directory);
|
|
324
|
+
if (pending)
|
|
325
|
+
return pending;
|
|
326
|
+
const prepare = (async () => {
|
|
327
|
+
try {
|
|
328
|
+
await fs.promises.mkdir(root, { recursive: true, mode: 0o700 });
|
|
329
|
+
await fs.promises.mkdir(directory, { recursive: true, mode: 0o700 });
|
|
330
|
+
if (process.platform === 'win32' && !preparedWindowsSessionRuntimeDirs.has(directory)) {
|
|
331
|
+
const icacls = path.join(process.env.SystemRoot || process.env.WINDIR || 'C:\\Windows', 'System32', 'icacls.exe');
|
|
332
|
+
await new Promise((resolve, reject) => {
|
|
333
|
+
execFile(icacls, [directory, '/grant', '*S-1-5-32-545:(OI)(CI)M', '/Q'], { windowsHide: true, timeout: 10_000 }, error => error ? reject(error) : resolve());
|
|
334
|
+
});
|
|
335
|
+
preparedWindowsSessionRuntimeDirs.add(directory);
|
|
336
|
+
}
|
|
337
|
+
await fs.promises.mkdir(path.join(directory, 'locks'), { recursive: true, mode: 0o700 });
|
|
338
|
+
return isManagedSessionRuntimeDir(directory, root) ? directory : undefined;
|
|
339
|
+
}
|
|
340
|
+
catch {
|
|
341
|
+
return undefined;
|
|
342
|
+
}
|
|
343
|
+
})();
|
|
344
|
+
pendingSessionRuntimeDirs.set(directory, prepare);
|
|
345
|
+
try {
|
|
346
|
+
return await prepare;
|
|
347
|
+
}
|
|
348
|
+
finally {
|
|
349
|
+
if (pendingSessionRuntimeDirs.get(directory) === prepare)
|
|
350
|
+
pendingSessionRuntimeDirs.delete(directory);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
313
353
|
/** Return the lock namespace inside the session-owned runtime directory. */
|
|
314
354
|
export function ensureRuntimeLockDir(sessionRuntimeDir) {
|
|
315
355
|
if (!sessionRuntimeDir || !path.isAbsolute(sessionRuntimeDir))
|
package/dist/cli/watch-logs.js
CHANGED
|
@@ -10,7 +10,8 @@ export function shortLogName(file) {
|
|
|
10
10
|
const stem = baseName.replace(WATCH_LOG_FILE, '');
|
|
11
11
|
return stem
|
|
12
12
|
.replace(/-\d{8}(?:-\d{2})?$/, '') // -YYYYMMDD[-HH](按日/小时轮转)
|
|
13
|
-
.replace(/-\d{4}-\d{2}-\d{2}
|
|
13
|
+
.replace(/-\d{4}-\d{2}-\d{2}(?:-\d{2})?$/, '')
|
|
14
|
+
.replace(/-[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i, '');
|
|
14
15
|
}
|
|
15
16
|
/** 从支持的日志文件名列表推导去重、字母序的类型列表。 */
|
|
16
17
|
export function deriveLogTypes(files) {
|
|
@@ -26,15 +27,16 @@ export function deriveLogTypes(files) {
|
|
|
26
27
|
export function computePreChecked(types, saved) {
|
|
27
28
|
if (saved === undefined)
|
|
28
29
|
return new Set(types);
|
|
29
|
-
const savedSet = new Set(saved);
|
|
30
|
+
const savedSet = new Set(saved.map(shortLogName));
|
|
30
31
|
return new Set(types.filter(t => savedSet.has(t)));
|
|
31
32
|
}
|
|
32
33
|
/** 返回 requested 中不在 available 里的无效类型。 */
|
|
33
34
|
export function validateLogTypes(requested, available) {
|
|
34
35
|
const set = new Set(available);
|
|
35
|
-
return requested.filter(
|
|
36
|
+
return requested.filter(type => !set.has(shortLogName(type)));
|
|
36
37
|
}
|
|
37
38
|
/** 只保留类型命中 filterTypes 的文件路径。 */
|
|
38
39
|
export function filterLogFiles(files, filterTypes) {
|
|
39
|
-
|
|
40
|
+
const normalizedTypes = new Set([...filterTypes].map(shortLogName));
|
|
41
|
+
return files.filter(file => normalizedTypes.has(shortLogName(file)));
|
|
40
42
|
}
|
package/dist/config/boot-log.js
CHANGED
|
@@ -15,11 +15,11 @@ import { logger } from '../utils/logger.js';
|
|
|
15
15
|
import { autoMigrateIfNeeded } from '../config-store.js';
|
|
16
16
|
import { ConfigTarget, initConfigManager, notifyConfigWrite } from './config-manager.js';
|
|
17
17
|
import { ensureRoleConfigV4OnStartup, ensureRoleConfigV5OnStartup } from './role-migration-startup.js';
|
|
18
|
-
import { ensureAccessPolicyMigrationOnStartup, ensureAgentModelProviderMigrationOnStartup, ensureAgentOnlyModelMigrationOnStartup, ensureAuxiliaryModelMigrationOnStartup, ensurePeerFileRenameOnStartup, ensurePublishedSchemaConsolidationMigrationOnStartup, ensureProviderServiceTypeMigrationOnStartup, ensureRelationConfigVersionMigrationOnStartup, invalidateMigrationReadCache, withMigrationReadCache, } from './schema-migration.js';
|
|
18
|
+
import { ensureAccessPolicyMigrationOnStartup, ensureAgentModelProviderMigrationOnStartup, ensureAgentOnlyModelMigrationOnStartup, ensureAuxiliaryModelMigrationOnStartup, ensurePeerFileRenameOnStartup, ensurePublishedSchemaConsolidationMigrationOnStartup, ensureProviderServiceTypeMigrationOnStartup, ensureProviderIdentityMigrationOnStartup, ensureRelationConfigVersionMigrationOnStartup, invalidateMigrationReadCache, withMigrationReadCache, } from './schema-migration.js';
|
|
19
19
|
import { ensureContactBookV2OnStartup } from './peer-book-v2-startup.js';
|
|
20
20
|
import { synchronizeAllManagementPeersSync } from './peer-book-store.js';
|
|
21
21
|
import { readInstalledEvolcoreVersion, readFastaunVersion } from '../utils/evolcore-version.js';
|
|
22
|
-
import { readCurrent, readWVersion, writeWVersion, materializeVersion, listAllVersions, diffVersions, snapshot, isConfigSnapshotsEnabled, ensureStartupConfigSnapshot, incrementSuccessCount, retentionCleanup, writeSnapshotConfigFile, removeSnapshotConfigFile, } from './snapshot.js';
|
|
22
|
+
import { readCurrent, readWVersion, writeWVersion, materializeVersion, listAllVersions, diffVersions, snapshot, isConfigSnapshotsEnabled, ensureStartupConfigSnapshot, incrementSuccessCount, retentionCleanup, writeSnapshotConfigFile, removeSnapshotConfigFile, snapshotManagesFile, } from './snapshot.js';
|
|
23
23
|
const MAX_LINES = 300;
|
|
24
24
|
const KEEP_MIN = 150;
|
|
25
25
|
const FALLBACK_MAX_TRIES = 20;
|
|
@@ -95,6 +95,19 @@ export async function prepareStartupConfig(recoverRoleMutations, onStep) {
|
|
|
95
95
|
logger.info(`[config] ${detail.file}${detail.removed.length ? `: removed ${detail.removed.join(', ')}` : ''}`);
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
+
step('providerIdentity');
|
|
99
|
+
const providerIdentityMigration = await ensureProviderIdentityMigrationOnStartup();
|
|
100
|
+
if (providerIdentityMigration) {
|
|
101
|
+
const message = `Provider domain ID migration: ${providerIdentityMigration.summary.providersMigrated} provider(s), ${providerIdentityMigration.changedFiles} file(s), ${providerIdentityMigration.summary.aliasesRemoved} alias(es) removed`
|
|
102
|
+
+ (providerIdentityMigration.backup ? `; backup version: ${providerIdentityMigration.backup}` : '');
|
|
103
|
+
logger.info(message);
|
|
104
|
+
console.error(message);
|
|
105
|
+
if (providerIdentityMigration.changedFiles && !providerIdentityMigration.backup)
|
|
106
|
+
logger.warn('[config] Provider migration completed without a version backup because configSnapshots=false; transaction recovery remains enabled');
|
|
107
|
+
if (providerIdentityMigration.pending.length) {
|
|
108
|
+
logger.warn(`[config] Provider domain required for legacy entries: ${providerIdentityMigration.pending.join(', ')}`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
98
111
|
step('accessPolicy');
|
|
99
112
|
const accessPolicyMigration = await ensureAccessPolicyMigrationOnStartup();
|
|
100
113
|
if (accessPolicyMigration) {
|
|
@@ -402,7 +415,7 @@ async function expandToW(version, root) {
|
|
|
402
415
|
const { collectConfigFiles } = await import('./snapshot.js');
|
|
403
416
|
const existing = collectConfigFiles(root);
|
|
404
417
|
for (const rel of existing) {
|
|
405
|
-
if (!files.has(rel))
|
|
418
|
+
if (!files.has(rel) && snapshotManagesFile(m, rel))
|
|
406
419
|
removeSnapshotConfigFile(root, rel);
|
|
407
420
|
}
|
|
408
421
|
for (const [rel, content] of files) {
|
|
@@ -4,7 +4,7 @@ export { expectedRoleRank, ROLE_RANKS } from './role-ranks.js';
|
|
|
4
4
|
export const BUILTIN_USER_ROLES = ['member', 'visitor'];
|
|
5
5
|
export const MANAGEMENT_ROLES = ['owner', 'admin'];
|
|
6
6
|
export const DAEMON_OWNER_ROLE = 'daemon-owner';
|
|
7
|
-
export const
|
|
7
|
+
export const DEFAULT_INTERNAL_CONTACT_ROLE = 'member';
|
|
8
8
|
export function isManagementRole(role) {
|
|
9
9
|
return role === 'owner' || role === 'admin';
|
|
10
10
|
}
|
|
@@ -18,7 +18,7 @@ export function isReservedRoleName(role) {
|
|
|
18
18
|
export function getBuiltinRolesConfig() {
|
|
19
19
|
return {
|
|
20
20
|
$schema_version: 1,
|
|
21
|
-
defaultRoles: { private: null, group: null,
|
|
21
|
+
defaultRoles: { private: null, group: null, internalContact: DEFAULT_INTERNAL_CONTACT_ROLE },
|
|
22
22
|
roles: Object.fromEntries(BUILTIN_USER_ROLES.flatMap(roleId => {
|
|
23
23
|
const definition = readBuiltinRoleTemplate(roleId).definition;
|
|
24
24
|
return definition ? [[roleId, definition]] : [];
|
|
@@ -1077,7 +1077,7 @@ export function mutateConfig(target, sel, mutate) {
|
|
|
1077
1077
|
release();
|
|
1078
1078
|
}
|
|
1079
1079
|
}
|
|
1080
|
-
/**
|
|
1080
|
+
/** Retire both local compatibility fields after freshly confirmed protocol ownership. */
|
|
1081
1081
|
export function clearConfiguredOwnerAfterConsensus(subjectAid, ownerAid) {
|
|
1082
1082
|
const normalizedOwnerAid = ownerAid.trim();
|
|
1083
1083
|
if (!isValidAid(normalizedOwnerAid) || subjectAid === ownerResolver.getDaemonAid())
|
|
@@ -1092,17 +1092,8 @@ export function clearConfiguredOwnerAfterConsensus(subjectAid, ownerAid) {
|
|
|
1092
1092
|
return mutateConfig(ConfigTarget.Agent, { self: subjectAid }, config => {
|
|
1093
1093
|
if (!isConfirmed())
|
|
1094
1094
|
return;
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
if (!Array.isArray(config.owners))
|
|
1098
|
-
return;
|
|
1099
|
-
const owners = config.owners.filter((owner) => typeof owner !== 'string' || owner.trim() !== normalizedOwnerAid);
|
|
1100
|
-
if (owners.length === config.owners.length)
|
|
1101
|
-
return;
|
|
1102
|
-
if (owners.length > 0)
|
|
1103
|
-
config.owners = owners;
|
|
1104
|
-
else
|
|
1105
|
-
delete config.owners;
|
|
1095
|
+
delete config.owner;
|
|
1096
|
+
delete config.owners;
|
|
1106
1097
|
}).changed;
|
|
1107
1098
|
}
|
|
1108
1099
|
function cloneConfigValue(value) {
|
|
@@ -1120,7 +1111,7 @@ function sortConfigValue(value) {
|
|
|
1120
1111
|
.sort(([left], [right]) => left.localeCompare(right))
|
|
1121
1112
|
.map(([key, nested]) => [key, sortConfigValue(nested)]));
|
|
1122
1113
|
}
|
|
1123
|
-
function acquireConfigMutationLock(file) {
|
|
1114
|
+
export function acquireConfigMutationLock(file) {
|
|
1124
1115
|
const lockDir = resolveManagedLockPath('config', file, `${file}.mutation.lock`);
|
|
1125
1116
|
const ownerFile = path.join(lockDir, 'owner.json');
|
|
1126
1117
|
const token = crypto.randomBytes(16).toString('hex');
|
|
@@ -1489,7 +1480,7 @@ function configSkeleton(target, sel) {
|
|
|
1489
1480
|
}
|
|
1490
1481
|
const spec = props[key];
|
|
1491
1482
|
if (spec && 'default' in spec)
|
|
1492
|
-
skeleton[key] = spec.default;
|
|
1483
|
+
skeleton[key] = cloneConfigValue(spec.default);
|
|
1493
1484
|
else if (spec?.type === 'array')
|
|
1494
1485
|
skeleton[key] = [];
|
|
1495
1486
|
else if (spec?.type === 'object')
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export const SERVICE_RESTART_MAX_ATTEMPTS = 3;
|
|
2
2
|
export const SERVICE_RESTART_WINDOW_MS = 900000;
|
|
3
3
|
export const SERVICE_RESTART_BACKOFF_MS = 5000;
|
|
4
|
+
export const SERVICE_STARTUP_TIMEOUT_MS = 45000;
|
|
4
5
|
export const SERVICE_HEALTH_INTERVALS = {
|
|
5
6
|
tcp: { startup: 500, running: 10000 },
|
|
6
7
|
http: { startup: 1000, running: 15000 },
|
|
@@ -13,7 +13,7 @@ import { configuredOwnerList } from './owner-config.js';
|
|
|
13
13
|
import { tryParseChannelKey } from '../core/channel-loader.js';
|
|
14
14
|
import { isValidAid } from '../aun/aid/validation.js';
|
|
15
15
|
import { getOwners, ownerResolver } from '../core/ownership/owner-resolver.js';
|
|
16
|
-
import {
|
|
16
|
+
import { sameOwnerQualification, sameOwnerRevision, requiresSameOwnerProof } from '../core/relation/same-owner-proof.js';
|
|
17
17
|
import { readRoleStore } from './role-store.js';
|
|
18
18
|
export function isAuthenticated(userId) {
|
|
19
19
|
return isValidAid(String(userId || '').trim());
|
|
@@ -60,7 +60,7 @@ export function getFirstStaticAgentOwner(aid) {
|
|
|
60
60
|
}
|
|
61
61
|
/** Revision for security-sensitive owner/contact/relation authorization inputs. */
|
|
62
62
|
export function authorizationConfigRevision(aid) {
|
|
63
|
-
const fingerprints = [ownerResolver.revision(aid),
|
|
63
|
+
const fingerprints = [ownerResolver.revision(aid), sameOwnerRevision(aid),
|
|
64
64
|
JSON.stringify(readRoleStore(aid)), fileRevision(agentConfig(aid)), fileRevision(agentPeerConfig(aid))];
|
|
65
65
|
const relations = agentRelationsDir(aid);
|
|
66
66
|
try {
|
|
@@ -105,8 +105,8 @@ export function resolvePeerRoleDetail(ctx) {
|
|
|
105
105
|
}
|
|
106
106
|
const actorRole = resolveActorDirectRole(ctx.selfAid, actor, channelType, operatorId);
|
|
107
107
|
if (channelType === 'aun' && ctx.chatType === 'private' && hasTrustedPrincipal(actor)
|
|
108
|
-
&& (
|
|
109
|
-
||
|
|
108
|
+
&& (sameOwnerQualification(ctx.selfAid, actor.principalId) === 'matched'
|
|
109
|
+
|| requiresSameOwnerProof(ctx.selfAid, actor.principalId))) {
|
|
110
110
|
const ownerCandidate = candidates.find(candidate => candidate.role === 'owner');
|
|
111
111
|
if (ownerCandidate)
|
|
112
112
|
return resultFor('owner', 'agent-owner', actor, ctx.selfAid);
|
|
@@ -114,13 +114,13 @@ export function resolvePeerRoleDetail(ctx) {
|
|
|
114
114
|
if (relation?.role !== undefined && relation.role !== null) {
|
|
115
115
|
return resultFor(actorRole, 'relation-actor', actor, ctx.selfAid);
|
|
116
116
|
}
|
|
117
|
-
if (
|
|
117
|
+
if (sameOwnerQualification(ctx.selfAid, actor.principalId) !== 'matched') {
|
|
118
118
|
return resultFor(null, 'none', actor, ctx.selfAid);
|
|
119
119
|
}
|
|
120
120
|
const store = readRoleStore(ctx.selfAid);
|
|
121
121
|
const valid = !store.diagnostics.some(diagnostic => diagnostic.code === 'INVALID_ROLE_REGISTRY'
|
|
122
122
|
|| diagnostic.code === 'MISSING_ROLE_REGISTRY');
|
|
123
|
-
const role = valid ? normalizeDefaultRole(store.registry.defaultRoles.
|
|
123
|
+
const role = valid ? normalizeDefaultRole(store.registry.defaultRoles.internalContact ?? 'member', ctx.selfAid) : null;
|
|
124
124
|
return resultFor(role, 'internal-contact-default', actor, ctx.selfAid);
|
|
125
125
|
}
|
|
126
126
|
if (ctx.chatType === 'private') {
|