evolcore 0.0.43-test.6 → 0.0.43-test.8
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 +95 -0
- package/bin/ecmsg.js +188 -58
- package/dist/agent-template/jobs.js +62 -0
- package/dist/agent-template/runtime.js +214 -0
- package/dist/agent-template/service.js +465 -0
- package/dist/agent-template/tool-runner.js +45 -0
- package/dist/agent-template/types.js +5 -0
- package/dist/agents/baseagent-availability.js +1 -1
- package/dist/agents/claude-runner.js +1 -1
- package/dist/agents/codex/app-server-client.js +22 -0
- package/dist/agents/codex-runner.js +69 -2
- package/dist/aun/aid/agentmd.js +56 -1
- package/dist/aun/aid/client.js +3 -1
- package/dist/aun/menu/client.js +3 -2
- package/dist/aun/msg/p2p.js +6 -1
- package/dist/channels/aun.js +277 -49
- package/dist/cli/agent-command.js +5 -0
- package/dist/cli/agent-create.js +7 -3
- package/dist/cli/agent-template.js +124 -0
- package/dist/cli/aun-commands.js +2 -2
- package/dist/cli/ctl-command.js +2 -1
- package/dist/cli/daemon-commands.js +11 -66
- package/dist/cli/daemon-lifecycle-client.js +61 -0
- package/dist/cli/ecmsg-gateway.js +35 -2
- package/dist/cli/events-command.js +109 -0
- package/dist/cli/index.js +60 -14
- package/dist/cli/invoke-command.js +182 -0
- package/dist/cli/managed-command-guard.js +6 -1
- package/dist/cli/net-check.js +1 -1
- package/dist/cli/restart-monitor.js +160 -83
- package/dist/cli/services-command.js +137 -0
- package/dist/cli/team-workspace-command.js +134 -0
- package/dist/cli/thread-command.js +103 -13
- package/dist/cli/watch-msg.js +1 -1
- package/dist/config/boot-log.js +8 -8
- package/dist/config/config-field-policy.js +2 -2
- package/dist/config/config-manager.js +0 -7
- package/dist/config/invoke-ipc-service.js +118 -0
- package/dist/config/schema-migration.js +45 -15
- package/dist/config-store.js +2 -1
- package/dist/core/agent-ipc-registration.js +25 -4
- package/dist/core/agent-reload-coordinator.js +6 -4
- package/dist/core/agent-runtime.js +106 -10
- package/dist/core/auth/delegation-authorization.js +66 -0
- package/dist/core/auth/operation-authorizer.js +2 -0
- package/dist/core/auth/operation-catalog.js +29 -0
- package/dist/core/baseagent-loader.js +60 -130
- package/dist/core/channel-loader.js +10 -1
- package/dist/core/channel-runtime.js +20 -12
- package/dist/core/command/agent-control.js +12 -2
- package/dist/core/command/agent-storage-menu.js +1 -1
- package/dist/core/command/agent-template-menu.js +147 -0
- package/dist/core/command/chatmode-config.js +2 -36
- package/dist/core/command/command-handler.js +80 -17
- package/dist/core/command/data-root-resolver.js +32 -23
- package/dist/core/command/eventcenter-menu.js +468 -0
- package/dist/core/command/menu-catalog.js +15 -0
- package/dist/core/command/menu-handler.js +216 -90
- package/dist/core/command/menu-protocol.js +71 -13
- package/dist/core/command/menu-query-batch.js +194 -0
- package/dist/core/command/slash-gate.js +1 -1
- package/dist/core/command/slash-handler.js +34 -42
- package/dist/core/command/team-workspace-bootstrap.js +350 -0
- package/dist/core/command/{pa-workspace-calendar.js → team-workspace-calendar.js} +7 -7
- package/dist/core/command/team-workspace-initializer.js +2 -0
- package/dist/core/command/{pa-workspace-items.js → team-workspace-items.js} +83 -68
- package/dist/core/command/team-workspace-job-store.js +88 -0
- package/dist/core/command/team-workspace-management-service.js +2 -0
- package/dist/core/command/team-workspace-management-store.js +96 -0
- package/dist/core/command/team-workspace-management.js +265 -0
- package/dist/core/command/team-workspace-members-menu.js +88 -0
- package/dist/core/command/team-workspace-store.js +612 -0
- package/dist/core/command/team-workspace-team.js +193 -0
- package/dist/core/daemon-control.js +22 -5
- package/dist/core/daemon-lifecycle.js +323 -191
- package/dist/core/handoff/runtime.js +45 -13
- package/dist/core/invoke/executors/index.js +13 -0
- package/dist/core/invoke/executors/media.js +283 -0
- package/dist/core/invoke/executors/text.js +198 -0
- package/dist/core/invoke/invoke-service.js +157 -0
- package/dist/core/invoke/style-router.js +48 -0
- package/dist/core/invoke/types.js +19 -0
- package/dist/core/ipc-registration.js +50 -7
- package/dist/core/legacy-rename.js +41 -0
- package/dist/core/memory/consolidation.js +7 -5
- package/dist/core/message/aun-ipc-sender.js +252 -17
- package/dist/core/message/im-renderer.js +116 -85
- package/dist/core/message/message-bridge.js +4 -0
- package/dist/core/message/message-queue.js +66 -15
- package/dist/core/message/message-utils.js +10 -2
- package/dist/core/message/peer-mode.js +7 -34
- package/dist/core/message/pending-hints.js +29 -5
- package/dist/core/message/response-engine.js +194 -61
- package/dist/core/message/send-options.js +7 -4
- package/dist/core/message/send-routing.js +50 -5
- package/dist/core/ownership/owner-resolver.js +7 -0
- package/dist/core/pack-auth.js +94 -0
- package/dist/core/pack-install.js +194 -0
- package/dist/core/permission/ec-command-parser.js +51 -17
- package/dist/core/permission/protected-paths.js +12 -2
- package/dist/core/permission/shell-environment.js +9 -0
- package/dist/core/rate-window.js +48 -0
- package/dist/core/relation/peer-identity.js +28 -0
- package/dist/core/session/session-file-health.js +243 -0
- package/dist/core/session/session-fs-store.js +67 -28
- package/dist/core/session/session-idle-monitor.js +59 -19
- package/dist/core/session/session-manager.js +13 -4
- package/dist/core/task/task-recovery-service.js +13 -2
- package/dist/core/thread/command-parser.js +9 -2
- package/dist/core/thread/thread-operation.js +21 -2
- package/dist/core/thread/thread-route.js +13 -2
- package/dist/core/thread/thread-service.js +52 -3
- package/dist/directory/owner-directory-admission.js +40 -53
- package/dist/directory/owner-directory-cache.js +89 -113
- package/dist/directory/owner-directory-query-operation.js +8 -10
- package/dist/eck/kit-renderer.js +7 -5
- package/dist/eck/message-renderer.js +2 -0
- package/dist/ecweb/basic-settings-service.js +1 -1
- package/dist/ecweb/message-context-service.js +0 -4
- package/dist/ecweb/runtime/lifecycle.js +6 -2
- package/dist/ecweb/runtime/supervisor.js +19 -4
- package/dist/event-center/admission-materializer.js +124 -0
- package/dist/event-center/bus-gate.js +154 -0
- package/dist/event-center/bus-host.js +307 -0
- package/dist/event-center/bus-resolver.js +120 -0
- package/dist/event-center/center-config.js +127 -0
- package/dist/event-center/daemon.js +44 -0
- package/dist/event-center/directory-source.js +55 -0
- package/dist/event-center/dispatcher.js +157 -0
- package/dist/event-center/event-log.js +110 -0
- package/dist/event-center/index-generator.js +73 -0
- package/dist/event-center/ipc-operation.js +423 -0
- package/dist/event-center/ledger.js +52 -0
- package/dist/event-center/pack-loader.js +207 -0
- package/dist/event-center/pack-manager.js +85 -0
- package/dist/event-center/registry.js +463 -0
- package/dist/event-center/runtime.js +837 -0
- package/dist/event-center/script-runner.js +356 -0
- package/dist/event-center/types.js +51 -0
- package/dist/event-center/validation.js +435 -0
- package/dist/index.js +424 -135
- package/dist/ipc.js +106 -12
- package/dist/paths.js +20 -0
- package/dist/product.js +14 -0
- package/dist/proxy/manager.js +5 -1
- package/dist/proxy/service-supervisor.js +13 -4
- package/dist/response-system/engines/v1/index.js +0 -1
- package/dist/response-system/engines/v1/proactive-flow.js +4 -2
- package/dist/response-system/modes/single-session/index.js +1 -1
- package/dist/services/dispatcher.js +100 -0
- package/dist/services/idempotency.js +90 -0
- package/dist/services/identity.js +52 -0
- package/dist/services/index-generator.js +70 -0
- package/dist/services/index.js +449 -0
- package/dist/services/ipc-operation.js +550 -0
- package/dist/services/ledger.js +52 -0
- package/dist/services/message-log.js +112 -0
- package/dist/services/pack-manager.js +215 -0
- package/dist/services/reply.js +55 -0
- package/dist/services/router.js +98 -0
- package/dist/services/script-runner.js +422 -0
- package/dist/services/service-payload.js +70 -0
- package/dist/services/types.js +18 -0
- package/dist/services/validation.js +297 -0
- package/dist/trigger/application-service.js +18 -0
- package/dist/trigger/event-source.js +1 -1
- package/dist/trigger/ipc-service.js +3 -1
- package/dist/trigger/scheduler.js +38 -0
- package/dist/trigger/script-sandbox.js +170 -24
- package/dist/utils/cross-platform.js +24 -10
- package/dist/utils/evolcore-version.js +69 -27
- package/dist/utils/instance-registry.js +19 -13
- package/dist/utils/npm-ops.js +2 -1
- package/dist/utils/package-version-info.js +6 -3
- package/dist/utils/process-introspect.js +45 -9
- package/dist/utils/startup-trace.js +74 -37
- package/dist/utils/windows-shell-trust.js +80 -6
- package/kits/docs/INDEX.md +2 -2
- package/kits/docs/aun/ABILITY_CALLING.md +9 -15
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +3 -1
- package/kits/docs/evolcore/ability.md +4 -0
- package/kits/docs/evolcore/agent.md +22 -1
- package/kits/docs/evolcore/aid.md +1 -1
- package/kits/docs/evolcore/event-center.md +227 -0
- package/kits/docs/evolcore/file-navigation.md +10 -264
- package/kits/docs/evolcore/fs.md +5 -3
- package/kits/docs/evolcore/group.md +1 -1
- package/kits/docs/evolcore/memory-architecture.md +2 -0
- package/kits/docs/evolcore/menu-protocol.md +28 -1
- package/kits/docs/evolcore/msg.md +21 -9
- package/kits/docs/evolcore/provider.md +3 -1
- package/kits/docs/evolcore/response.md +5 -5
- package/kits/docs/evolcore/services.md +294 -0
- package/kits/docs/evolcore/task.md +2 -0
- package/kits/docs/evolcore/team-workspace.md +41 -0
- package/kits/docs/evolcore/thread-chain.md +15 -3
- package/kits/eck_manifest.json +26 -0
- package/kits/rules/02-navigation.md +10 -1
- package/kits/rules/06-channel.md +1 -0
- package/kits/schemas/_meta.json +17 -6
- package/kits/schemas/agent-config.schema.19.json +5 -7
- package/kits/schemas/agent-config.schema.20.json +936 -0
- package/kits/schemas/relation-config.schema.12.json +2 -3
- package/kits/schemas/role-config.schema.2.json +4 -4
- package/kits/skills/.switches.json +1 -5
- package/kits/skills/ability/SKILL.md +56 -0
- package/kits/skills/ability/references/calling.md +56 -0
- package/kits/skills/{ec-ability → ability}/references/contract-checklist.md +1 -1
- package/kits/skills/{ec-ability → ability}/references/development.md +9 -33
- package/kits/skills/{ec-ability → ability}/references/management.md +2 -2
- package/kits/skills/{ec-ability → ability}/references/recovery.md +1 -1
- package/kits/skills/{ec-ability → ability}/references/runtime-protocol.md +2 -0
- package/kits/skills/ec-agent-create/SKILL.md +0 -1
- package/kits/skills/ec-group/SKILL.md +5 -8
- package/kits/skills/ec-group-collaboration/SKILL.md +7 -7
- package/kits/skills/ec-service-proxy/SKILL.md +34 -5
- package/kits/skills/ec-trigger/SKILL.md +4 -4
- package/kits/skills/personal-assistant/SKILL.md +6 -6
- package/kits/skills/personal-assistant/references/02-bootstrap.md +4 -4
- package/kits/skills/personal-assistant/scripts/clean.mjs +4 -4
- package/kits/skills/personal-assistant/scripts/init.mjs +2 -2
- package/kits/skills/personal-assistant/scripts/pa.mjs +4 -4
- package/kits/skills/thread-ops/SKILL.md +10 -10
- package/kits/templates/message-fragments/item.md +1 -1
- package/kits/templates/system-fragments/channel.md +3 -3
- package/kits/templates/system-fragments/commands.md +5 -3
- package/kits/templates/system-fragments/reply.md +1 -5
- package/kits/templates/system-fragments/thread.md +13 -10
- package/package.json +5 -6
- package/scripts/agent-template/index.mjs +40 -0
- package/scripts/agent-template/inspect.mjs +240 -0
- package/scripts/agent-template/overlay.mjs +71 -0
- package/scripts/agent-template/pack.mjs +169 -0
- package/scripts/agent-template/shared/common.mjs +235 -0
- package/scripts/agent-template/shared/evolcore.mjs +75 -0
- package/scripts/agent-template/shared/plan.mjs +129 -0
- package/scripts/agent-template/shared/team-schema.json +70 -0
- package/scripts/agent-template/shared/template-contract.mjs +154 -0
- package/scripts/agent-template/shared/template-package.mjs +265 -0
- package/scripts/agent-template/shared/template-runtime.mjs +80 -0
- package/scripts/agent-template/shared/template.mjs +142 -0
- package/dist/cli/pa-workspace-command.js +0 -225
- package/dist/core/command/pa-workspace-store.js +0 -468
- package/dist/core/relation/pa-team.js +0 -132
- package/kits/docs/evolcore/pa-workspace.md +0 -51
- package/kits/skills/aid-ability/SKILL.md +0 -244
- package/kits/skills/ec-ability/SKILL.md +0 -67
- package/kits/skills/ec-ability/references/workflows.md +0 -15
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ec invoke` 的调用编排:解析 → 路由 → 执行 → 重试 → 归一化。
|
|
3
|
+
*
|
|
4
|
+
* 设计见 `docs/model-intent/invoke-design.md`。
|
|
5
|
+
*
|
|
6
|
+
* 重试语义(唯一一处重试):
|
|
7
|
+
* - 5xx / 连接失败 / 超时 → 重试,直到 `--retries` 次,指数退避
|
|
8
|
+
* - 4xx → 不重试,直接失败
|
|
9
|
+
* - `--retries 0` → 只打一次
|
|
10
|
+
*/
|
|
11
|
+
import { resolveProviderService } from '../../config/providers.js';
|
|
12
|
+
import { InvokeError } from './types.js';
|
|
13
|
+
import { resolveStyleRoute } from './style-router.js';
|
|
14
|
+
export const DEFAULT_INVOKE_TIMEOUT_MS = 60_000;
|
|
15
|
+
export const DEFAULT_INVOKE_RETRIES = 3;
|
|
16
|
+
export const MAX_INVOKE_RETRIES = 10;
|
|
17
|
+
export const MAX_INVOKE_TIMEOUT_MS = 3_600_000;
|
|
18
|
+
/** 判定一个错误是否可重试:传输层错误才重试。 */
|
|
19
|
+
function isRetryable(error) {
|
|
20
|
+
if (error instanceof InvokeError)
|
|
21
|
+
return error.code === 'TRANSPORT_ERROR' || error.code === 'UPSTREAM_ERROR';
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
function backoffMs(attempt) {
|
|
25
|
+
// 200ms, 400ms, 800ms ... 上限 4s
|
|
26
|
+
return Math.min(200 * 2 ** (attempt - 1), 4_000);
|
|
27
|
+
}
|
|
28
|
+
function sleep(ms, signal) {
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
const timer = setTimeout(resolve, ms);
|
|
31
|
+
signal?.addEventListener('abort', () => {
|
|
32
|
+
clearTimeout(timer);
|
|
33
|
+
reject(new InvokeError('ABORTED', 'Invoke was aborted'));
|
|
34
|
+
}, { once: true });
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/** 带重试地跑一个执行器。导出供测试验证重试语义。 */
|
|
38
|
+
export async function runWithRetry(executor, context, options) {
|
|
39
|
+
const started = Date.now();
|
|
40
|
+
let lastError;
|
|
41
|
+
for (let attempt = 0; attempt <= options.retries; attempt++) {
|
|
42
|
+
options.signal?.throwIfAborted();
|
|
43
|
+
if (attempt > 0)
|
|
44
|
+
await sleep(backoffMs(attempt), options.signal);
|
|
45
|
+
try {
|
|
46
|
+
const result = await executor.invoke(context, options);
|
|
47
|
+
return { ...result, latencyMs: Date.now() - started };
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
lastError = error;
|
|
51
|
+
if (!isRetryable(error))
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
throw lastError;
|
|
56
|
+
}
|
|
57
|
+
/** 解析 `--model` 缺省值:从 catalog 取第一个已启用模型。 */
|
|
58
|
+
async function resolveDefaultModel(providerId, serviceType) {
|
|
59
|
+
const { getLocalProviderCatalog } = await import('../model/model-catalog.js');
|
|
60
|
+
const snapshot = await getLocalProviderCatalog(providerId, serviceType, false);
|
|
61
|
+
const model = snapshot.models.find(entry => !entry.aliasFor) ?? snapshot.models[0];
|
|
62
|
+
if (!model) {
|
|
63
|
+
throw new InvokeError('MODEL_REQUIRED', `No model available for provider ${providerId} service ${serviceType}; pass --model`);
|
|
64
|
+
}
|
|
65
|
+
return model.id;
|
|
66
|
+
}
|
|
67
|
+
export async function executeInvoke(request) {
|
|
68
|
+
const timeoutMs = request.timeoutMs ?? DEFAULT_INVOKE_TIMEOUT_MS;
|
|
69
|
+
const retries = request.retries ?? DEFAULT_INVOKE_RETRIES;
|
|
70
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0 || timeoutMs > MAX_INVOKE_TIMEOUT_MS) {
|
|
71
|
+
return { ok: false, code: 'INVALID_ARGUMENT', error: `--timeout must be between 1 and ${MAX_INVOKE_TIMEOUT_MS} ms` };
|
|
72
|
+
}
|
|
73
|
+
if (!Number.isInteger(retries) || retries < 0 || retries > MAX_INVOKE_RETRIES) {
|
|
74
|
+
return { ok: false, code: 'INVALID_ARGUMENT', error: `--retries must be an integer between 0 and ${MAX_INVOKE_RETRIES}` };
|
|
75
|
+
}
|
|
76
|
+
let connection;
|
|
77
|
+
try {
|
|
78
|
+
connection = resolveProviderService(request.providerId, request.serviceType);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
return { ok: false, code: 'PROVIDER_NOT_FOUND', error: error.message };
|
|
82
|
+
}
|
|
83
|
+
let model = request.model;
|
|
84
|
+
if (!model) {
|
|
85
|
+
// `--dry-run` 的契约是「不触网」。缺省模型要走目录接口(网络),
|
|
86
|
+
// 所以 dry-run 且未显式给 --model 时不解析真实模型,用占位值。
|
|
87
|
+
if (request.dryRun) {
|
|
88
|
+
model = '<dry-run>';
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
try {
|
|
92
|
+
model = await resolveDefaultModel(connection.providerId, connection.serviceType);
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
return { ok: false, code: error instanceof InvokeError ? error.code : 'MODEL_REQUIRED', error: error.message };
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
let route;
|
|
100
|
+
try {
|
|
101
|
+
route = await resolveStyleRoute({ style: connection.style, serviceType: request.serviceType });
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
return { ok: false, code: 'ROUTE_FAILED', error: error.message };
|
|
105
|
+
}
|
|
106
|
+
if (request.dryRun) {
|
|
107
|
+
return {
|
|
108
|
+
ok: true,
|
|
109
|
+
provider: connection.providerId,
|
|
110
|
+
service: request.serviceType,
|
|
111
|
+
model,
|
|
112
|
+
style: connection.style,
|
|
113
|
+
executor: route.kind === 'builtin' ? route.executor.id : route.kind,
|
|
114
|
+
result: { output: { dryRun: true, route }, latencyMs: 0 },
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
if (route.kind !== 'builtin') {
|
|
118
|
+
return {
|
|
119
|
+
ok: false,
|
|
120
|
+
code: 'STYLE_UNSUPPORTED',
|
|
121
|
+
error: `No builtin executor handles style "${connection.style}" for service "${request.serviceType}"`,
|
|
122
|
+
data: { style: connection.style, serviceType: request.serviceType, hint: 'Plugin generation lands in phase C' },
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
const context = {
|
|
126
|
+
provider: {
|
|
127
|
+
providerId: connection.providerId,
|
|
128
|
+
serviceType: connection.serviceType,
|
|
129
|
+
style: connection.style,
|
|
130
|
+
baseUrl: connection.baseUrl,
|
|
131
|
+
apiKey: connection.apiKey,
|
|
132
|
+
headers: connection.headers,
|
|
133
|
+
queryParams: connection.queryParams,
|
|
134
|
+
},
|
|
135
|
+
model,
|
|
136
|
+
input: request.input,
|
|
137
|
+
outPath: request.outPath,
|
|
138
|
+
};
|
|
139
|
+
try {
|
|
140
|
+
const result = await runWithRetry(route.executor, context, { timeoutMs, retries });
|
|
141
|
+
return {
|
|
142
|
+
ok: true,
|
|
143
|
+
provider: connection.providerId,
|
|
144
|
+
service: request.serviceType,
|
|
145
|
+
model,
|
|
146
|
+
style: connection.style,
|
|
147
|
+
executor: route.executor.id,
|
|
148
|
+
result,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
if (error instanceof InvokeError) {
|
|
153
|
+
return { ok: false, code: error.code, error: error.message, data: error.data };
|
|
154
|
+
}
|
|
155
|
+
return { ok: false, code: 'INVOKE_FAILED', error: error.message };
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* style 路由表。
|
|
3
|
+
*
|
|
4
|
+
* 设计见 `docs/model-intent/invoke-design.md` 第二节「路由表」。
|
|
5
|
+
*
|
|
6
|
+
* 路由**只按 style 判定**,不按域名、不看模型名。内置执行器优先,
|
|
7
|
+
* 未命中才考虑插件(插件机制在阶段 C 接入)。
|
|
8
|
+
*/
|
|
9
|
+
import { BUILTIN_EXECUTORS } from './executors/index.js';
|
|
10
|
+
/** style 别名归一:路由只认 canonical 形态。 */
|
|
11
|
+
const STYLE_ALIASES = {
|
|
12
|
+
anthropic: 'claude',
|
|
13
|
+
'openai-responses': 'codex',
|
|
14
|
+
};
|
|
15
|
+
export function canonicalStyle(style) {
|
|
16
|
+
const normalized = style.trim().toLowerCase();
|
|
17
|
+
return STYLE_ALIASES[normalized] ?? normalized;
|
|
18
|
+
}
|
|
19
|
+
/** 查询内置执行器;未命中返回 undefined。 */
|
|
20
|
+
export function findBuiltinExecutor(style, serviceType, executors = BUILTIN_EXECUTORS) {
|
|
21
|
+
const target = canonicalStyle(style);
|
|
22
|
+
return executors.find(executor => executor.handles.some(handle => canonicalStyle(handle) === target)
|
|
23
|
+
&& (executor.services.includes('*') || executor.services.includes(serviceType)));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 解析一次调用该走谁。
|
|
27
|
+
*
|
|
28
|
+
* @param pluginLookup 插件查找(阶段 C)。返回插件 ID 表示可路由到插件。
|
|
29
|
+
*/
|
|
30
|
+
export async function resolveStyleRoute(input) {
|
|
31
|
+
const executor = findBuiltinExecutor(input.style, input.serviceType, input.executors);
|
|
32
|
+
if (executor)
|
|
33
|
+
return { kind: 'builtin', executor };
|
|
34
|
+
if (input.pluginLookup) {
|
|
35
|
+
const pluginId = await input.pluginLookup(input.style, input.serviceType);
|
|
36
|
+
if (pluginId)
|
|
37
|
+
return { kind: 'plugin', pluginId };
|
|
38
|
+
}
|
|
39
|
+
return { kind: 'unsupported', style: input.style, serviceType: input.serviceType };
|
|
40
|
+
}
|
|
41
|
+
/** `--dry-run` 与帮助用的路由表快照。 */
|
|
42
|
+
export function describeRouteTable(executors = BUILTIN_EXECUTORS) {
|
|
43
|
+
return executors.map(executor => ({
|
|
44
|
+
executor: executor.id,
|
|
45
|
+
handles: [...executor.handles],
|
|
46
|
+
services: [...executor.services],
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 统一模型调用层(`ec invoke`)的类型契约。
|
|
3
|
+
*
|
|
4
|
+
* 设计见 `docs/model-intent/invoke-design.md`。
|
|
5
|
+
*
|
|
6
|
+
* 核心约束:本层只做「按 style 路由 + 打端点 + 归一化产物」,
|
|
7
|
+
* 不修改 `providers.json`,不决定产物落点,不做意图选择。
|
|
8
|
+
*/
|
|
9
|
+
/** 调用失败的结构化错误。 */
|
|
10
|
+
export class InvokeError extends Error {
|
|
11
|
+
code;
|
|
12
|
+
data;
|
|
13
|
+
constructor(code, message, data) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.code = code;
|
|
16
|
+
this.data = data;
|
|
17
|
+
this.name = 'InvokeError';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { createEventsOperationExecutor } from '../event-center/ipc-operation.js';
|
|
2
|
+
import { createServicesOperationExecutor } from '../services/ipc-operation.js';
|
|
1
3
|
import { ecwebInitializationService } from './initialization/service.js';
|
|
2
4
|
import { TriggerDefinitionManager } from '../trigger/manager.js';
|
|
3
5
|
import { ensureSessionRuntimeDirAsync } from '../cli/task-context.js';
|
|
@@ -26,8 +28,8 @@ import { createThreadOperationExecutor } from './thread/ipc-operation.js';
|
|
|
26
28
|
import { isLinkedInstall } from '../utils/npm-ops.js';
|
|
27
29
|
import { buildSystemSessionContext, getSystemSessionModule } from './system-session/registry.js';
|
|
28
30
|
import { parseManagedDaemonLogArgv, queryDiagnosticLogs } from './command/daemon-diagnostics.js';
|
|
29
|
-
import { createDelegationAuthorizer, createDelegatedProviderOperationExecutor, createDelegatedUpgradeOperationExecutor } from './auth/delegation-authorization.js';
|
|
30
|
-
export function registerDaemonIpc({ lifecycle, ipcServer, agentRegistry, agentDelegationRegistry, sessionManager, statsCollector, aidStatsCollector, responseEngine, messageQueue, agentMap, commandHandler, channelInstances, eventBus, handoffRuntime, reloadCoordinator, agentApplicationService, agentInitializationService, enqueueConsolidation, getRelationRoute, isConsolidationPending, completeAgentBootstrap, contactBinds, bindService, diagService, getProcessOwners, getControlAidState, daemonAid, triggerControlToken, triggerSchedulers, daemonTriggerOwner, primaryAgent, triggerAuthorization, }) {
|
|
31
|
+
import { createDelegationAuthorizer, createDelegatedProviderOperationExecutor, createDelegatedUpgradeOperationExecutor, createDelegatedInvokeOperationExecutor } from './auth/delegation-authorization.js';
|
|
32
|
+
export function registerDaemonIpc({ lifecycle, ipcServer, agentRegistry, agentDelegationRegistry, sessionManager, statsCollector, aidStatsCollector, responseEngine, messageQueue, agentMap, getConfiguredBaseagents, commandHandler, channelInstances, eventBus, handoffRuntime, reloadCoordinator, agentApplicationService, agentInitializationService, enqueueConsolidation, getRelationRoute, isConsolidationPending, completeAgentBootstrap, contactBinds, bindService, diagService, getProcessOwners, getControlAidState, daemonAid, triggerControlToken, triggerSchedulers, eventCenter, daemonTriggerOwner, primaryAgent, triggerAuthorization, }) {
|
|
31
33
|
ecwebInitializationService.setAgentInitializer(agentInitializationService);
|
|
32
34
|
const authorizeManagedAgentOperation = createDelegationAuthorizer({
|
|
33
35
|
agentDelegationRegistry,
|
|
@@ -39,6 +41,11 @@ export function registerDaemonIpc({ lifecycle, ipcServer, agentRegistry, agentDe
|
|
|
39
41
|
sessionManager,
|
|
40
42
|
getProcessOwners,
|
|
41
43
|
}));
|
|
44
|
+
ipcServer.setInvokeExecutor(createDelegatedInvokeOperationExecutor({
|
|
45
|
+
agentDelegationRegistry,
|
|
46
|
+
sessionManager,
|
|
47
|
+
getProcessOwners,
|
|
48
|
+
}));
|
|
42
49
|
ipcServer.setUpgradeExecutor(createDelegatedUpgradeOperationExecutor({
|
|
43
50
|
agentDelegationRegistry,
|
|
44
51
|
sessionManager,
|
|
@@ -269,6 +276,7 @@ export function registerDaemonIpc({ lifecycle, ipcServer, agentRegistry, agentDe
|
|
|
269
276
|
getAgentName: agentAid => agentRegistry.get(agentAid)?.name,
|
|
270
277
|
getDaemonAgentName: () => primaryAgent?.name,
|
|
271
278
|
agentMap,
|
|
279
|
+
getConfiguredBaseagents,
|
|
272
280
|
}),
|
|
273
281
|
getSessionById: sessionId => sessionManager.getSessionById(sessionId),
|
|
274
282
|
...triggerAuthorization,
|
|
@@ -280,8 +288,41 @@ export function registerDaemonIpc({ lifecycle, ipcServer, agentRegistry, agentDe
|
|
|
280
288
|
responseEngine,
|
|
281
289
|
handoffRuntime,
|
|
282
290
|
sessionManager,
|
|
291
|
+
messageQueue,
|
|
283
292
|
createCrossThreadReviewTrigger: input => createManagedCrossThreadReviewTrigger(input, triggerIpcDependencies),
|
|
284
293
|
});
|
|
294
|
+
if (eventCenter) {
|
|
295
|
+
ipcServer.setEventsOperationExecutor(createEventsOperationExecutor({
|
|
296
|
+
registry: eventCenter,
|
|
297
|
+
daemonAid: () => daemonAid,
|
|
298
|
+
}));
|
|
299
|
+
}
|
|
300
|
+
// 服务路由:已连接通道的实例会暴露其 router;启动即预热一次,让 `ec services status`
|
|
301
|
+
// 看到的是 daemon 真在用的那份状态,而不是磁盘重扫出来的临时实例。
|
|
302
|
+
for (const instance of channelInstances) {
|
|
303
|
+
const channel = instance.channel;
|
|
304
|
+
try {
|
|
305
|
+
channel?.getServiceRouter?.();
|
|
306
|
+
}
|
|
307
|
+
catch (error) {
|
|
308
|
+
logger.warn(`[Services] router prewarm failed for ${instance.adapter.channelName}: ${error instanceof Error ? error.message : String(error)}`);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
ipcServer.setServicesOperationExecutor(createServicesOperationExecutor({
|
|
312
|
+
defaultAid: () => daemonAid,
|
|
313
|
+
daemonAid: () => daemonAid,
|
|
314
|
+
getChannel: aid => channelInstances.find(candidate => {
|
|
315
|
+
if (candidate.channelType !== 'aun')
|
|
316
|
+
return false;
|
|
317
|
+
const channel = candidate.channel;
|
|
318
|
+
try {
|
|
319
|
+
return !!channel && (channel.getAidState?.()?.aid === aid || channel.getAid?.() === aid);
|
|
320
|
+
}
|
|
321
|
+
catch {
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
})?.channel,
|
|
325
|
+
}));
|
|
285
326
|
ipcServer.setAgentReloadExecutor((aid, options) => reloadCoordinator.reload(aid, options));
|
|
286
327
|
registerConsolidationCheckExecutor({ ipcServer, agentRegistry, enqueueConsolidation, getRelationRoute, isConsolidationPending });
|
|
287
328
|
ipcServer.setInitializationExecutor(async (command) => executeLocalInitializationCommand(agentInitializationService, command));
|
|
@@ -341,17 +382,19 @@ export function createIpcStatusProvider(dependencies) {
|
|
|
341
382
|
const snapshot = dependencies.statsCollector.getSnapshot();
|
|
342
383
|
const agents = dependencies.agentRegistry.list();
|
|
343
384
|
const runtimeError = dependencies.getAgentRuntimeError();
|
|
385
|
+
const build = dependencies.getBuildDiagnostics();
|
|
344
386
|
return {
|
|
345
387
|
pid: process.pid,
|
|
346
388
|
uptime: snapshot.uptimeMs,
|
|
347
389
|
...(dependencies.runMode ? { runMode: dependencies.runMode } : {}),
|
|
348
390
|
...(dependencies.getHost ? { host: dependencies.getHost() } : {}),
|
|
349
391
|
build: {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
392
|
+
state: build.state,
|
|
393
|
+
runtimeMode: build.runtimeIsDist ? 'dist' : 'source',
|
|
394
|
+
runtimeId: build.runtimeBuildIdentity.id,
|
|
395
|
+
diskDistId: build.diskDistId,
|
|
396
|
+
entry: build.runtimeBuildIdentity.entry,
|
|
397
|
+
version: build.runtimeBuildIdentity.version,
|
|
355
398
|
},
|
|
356
399
|
controlPlane: { ready: true, owned: dependencies.getProcessOwners().length > 0 },
|
|
357
400
|
...(dependencies.getStartupProgress ? { startup: dependencies.getStartupProgress() } : {}),
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 一次性文件名迁移:旧名 → 规范名。
|
|
3
|
+
*
|
|
4
|
+
* 背景:中心/服务两侧的配置文件改成「每个东西只有一个名字」(`events-config.json` /
|
|
5
|
+
* `services-config.json` / 包声明统一 `pack.json`),不留别名。留别名会让 agent 多一次
|
|
6
|
+
* 「这里该写哪个名」的判断,而这正是我们要消除的东西。
|
|
7
|
+
*
|
|
8
|
+
* 但存量机器上还有旧名。取舍:**只搬运、不双读**——启动时把旧名重命名成新名,
|
|
9
|
+
* 之后所有代码只认规范名。这样既不产生"两套名字都能用"的长期负担,也不会把
|
|
10
|
+
* 用户已配好的策略弄丢。
|
|
11
|
+
*/
|
|
12
|
+
import fs from 'node:fs';
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
import { logger } from '../utils/logger.js';
|
|
15
|
+
/**
|
|
16
|
+
* 把 `dir/legacyName` 重命名为 `dir/canonicalName`。
|
|
17
|
+
*
|
|
18
|
+
* @returns 是否发生了迁移
|
|
19
|
+
*/
|
|
20
|
+
export function migrateLegacyFileName(dir, legacyName, canonicalName, label) {
|
|
21
|
+
const legacyPath = path.join(dir, legacyName);
|
|
22
|
+
const canonicalPath = path.join(dir, canonicalName);
|
|
23
|
+
if (!fs.existsSync(legacyPath))
|
|
24
|
+
return false;
|
|
25
|
+
// 两个都在:不猜哪个是对的,保留规范名并告警,让用户自己处理旧文件。
|
|
26
|
+
if (fs.existsSync(canonicalPath)) {
|
|
27
|
+
logger.warn(`[migration] ${label}: 同时存在 ${legacyName} 与 ${canonicalName},已忽略前者;` +
|
|
28
|
+
`请删除 ${legacyPath}`);
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
fs.renameSync(legacyPath, canonicalPath);
|
|
33
|
+
logger.info(`[migration] ${label}: ${legacyName} → ${canonicalName}`);
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
logger.warn(`[migration] ${label}: 无法重命名 ${legacyPath}: ` +
|
|
38
|
+
`${error instanceof Error ? error.message : String(error)};将按缺少配置处理`);
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* `execution.memoryMode` 会经 session.metadata 透传到渲染层与 ipc 的权限校验。
|
|
10
10
|
*/
|
|
11
11
|
import fs from 'fs';
|
|
12
|
-
import {
|
|
12
|
+
import { getProtocolOwner, ownerResolver } from '../ownership/owner-resolver.js';
|
|
13
13
|
import path from 'path';
|
|
14
14
|
import { agentDir, resolveRoot } from '../../paths.js';
|
|
15
15
|
import { isSilentConsolidationTrigger, serializeConsolidationContext } from './consolidation-context.js';
|
|
@@ -665,7 +665,9 @@ export function recordConsolidationOutcome(contextFilePath, outcome) {
|
|
|
665
665
|
export async function triggerAgentPromote(params) {
|
|
666
666
|
const { selfAid } = params;
|
|
667
667
|
try {
|
|
668
|
-
const ownerAid =
|
|
668
|
+
const ownerAid = getProtocolOwner(selfAid);
|
|
669
|
+
if (params.ownerAid && params.ownerAid !== ownerAid)
|
|
670
|
+
return;
|
|
669
671
|
if (!ownerAid)
|
|
670
672
|
return;
|
|
671
673
|
const agentConsolidated = path.join(agentDir(selfAid), 'personal', 'memory', 'consolidated');
|
|
@@ -1005,7 +1007,7 @@ export function createConsolidationSessionFinalizer({ sessionManager, getAgent,
|
|
|
1005
1007
|
continue;
|
|
1006
1008
|
}
|
|
1007
1009
|
if (due > 0) {
|
|
1008
|
-
const ownerAid = memoryConfig ?
|
|
1010
|
+
const ownerAid = memoryConfig ? getProtocolOwner(selfAid) : undefined;
|
|
1009
1011
|
const taskCtx = { selfAid, peerKey: meta.peerKey, baseagent: agent?.baseagent };
|
|
1010
1012
|
void enqueueConsolidation({
|
|
1011
1013
|
taskCtx,
|
|
@@ -1469,7 +1471,7 @@ export function registerConsolidationCheckExecutor({ ipcServer, agentRegistry, e
|
|
|
1469
1471
|
if (candidates.length === 0 && !ownerCandidates)
|
|
1470
1472
|
return { launched: [] };
|
|
1471
1473
|
await ownerResolver.refresh(selfAid);
|
|
1472
|
-
const ownerAid =
|
|
1474
|
+
const ownerAid = getProtocolOwner(selfAid);
|
|
1473
1475
|
if (ownerCandidates)
|
|
1474
1476
|
candidates.push(...checkConsolidationCandidates({
|
|
1475
1477
|
selfAid, ownerAid, config: agentConfig?.memory, useMetaIndex, ownerOnly: true,
|
|
@@ -1528,7 +1530,7 @@ export function registerRelationConsolidationEvents({ eventBus, agentRegistry, r
|
|
|
1528
1530
|
}) !== 'run')
|
|
1529
1531
|
return;
|
|
1530
1532
|
await ownerResolver.refresh(taskCtx.selfAid);
|
|
1531
|
-
const ownerAid =
|
|
1533
|
+
const ownerAid = getProtocolOwner(taskCtx.selfAid);
|
|
1532
1534
|
await enqueueConsolidation({
|
|
1533
1535
|
taskCtx,
|
|
1534
1536
|
mode: 'notes',
|