evolcore 0.0.47 → 0.0.49
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 +90 -1
- package/bin/ec-build.mjs +86 -0
- package/dist/agent-template/jobs.js +12 -4
- package/dist/agent-template/runtime.js +143 -40
- package/dist/agent-template/service.js +66 -13
- package/dist/agents/baseagent.js +60 -20
- package/dist/agents/claude-runner.js +34 -17
- package/dist/agents/codex-runner.js +36 -17
- package/dist/agents/ecagent-runner.js +7 -4
- package/dist/agents/gemini-runner.js +5 -2
- package/dist/agents/runner-types.js +5 -21
- package/dist/aun/aid/agentmd.js +5 -1
- package/dist/aun/msg/p2p.js +2 -1
- package/dist/aun/service-proxy.js +4 -2
- package/dist/build-identity.json +1 -0
- package/dist/channels/aun.js +722 -295
- package/dist/channels/daemon.js +9 -25
- package/dist/cli/aun-commands.js +86 -51
- package/dist/cli/code-stats.js +19 -8
- package/dist/cli/command-log.js +1 -1
- package/dist/cli/daemon-commands.js +44 -43
- package/dist/cli/directory.js +13 -2
- package/dist/cli/ecmsg-gateway.js +5 -2
- package/dist/cli/index.js +9 -9
- package/dist/cli/init-channel.js +4 -6
- package/dist/cli/init.js +72 -50
- package/dist/cli/invoke-command.js +1 -1
- package/dist/cli/managed-command-guard.js +2 -0
- package/dist/cli/model.js +20 -5
- package/dist/cli/provider-command.js +74 -13
- package/dist/cli/quota.js +89 -0
- package/dist/cli/role.js +62 -17
- package/dist/cli/services-command.js +1 -0
- package/dist/cli/stats.js +3 -3
- package/dist/cli/team-workspace-command.js +56 -2
- package/dist/cli/thread-command.js +16 -51
- package/dist/config/boot-log.js +3 -9
- package/dist/config/builtin-roles.js +5 -7
- package/dist/config/config-field-policy.js +71 -1
- package/dist/config/config-manager.js +13 -7
- package/dist/config/daemon-services.js +30 -3
- package/dist/config/gateway-config.js +2 -2
- package/dist/config/invoke-ipc-service.js +6 -4
- package/dist/config/peer-bind-code.js +3 -4
- package/dist/config/peer-book-store.js +62 -229
- package/dist/config/peer-book.js +26 -27
- package/dist/config/peer-role-resolver.js +16 -1
- package/dist/config/provider-identity-migration.js +4 -1
- package/dist/config/provider-ipc-service.js +56 -11
- package/dist/config/provider-menu-request.js +24 -5
- package/dist/config/provider-templates.js +127 -0
- package/dist/config/providers-config.js +67 -12
- package/dist/config/providers-management.js +477 -51
- package/dist/config/resolved-config-op.js +3 -2
- package/dist/config/role-command-service.js +248 -1
- package/dist/config/schema-migration.js +105 -4
- package/dist/core/agent-application-service.js +6 -1
- package/dist/core/agent-runtime.js +4 -0
- package/dist/core/auth/agent-delegation.js +2 -1
- package/dist/core/auth/auth-gateway.js +2 -1
- package/dist/core/auth/delegation-authorization.js +36 -26
- package/dist/core/auth/operation-authorizer.js +25 -0
- package/dist/core/auth/operation-catalog.js +37 -64
- package/dist/core/capability/providers/codex-capability-provider.js +7 -8
- package/dist/core/channel-loader.js +18 -0
- package/dist/core/command/agent-control.js +32 -0
- package/dist/core/command/cli-intent-parser.js +13 -0
- package/dist/core/command/command-handler.js +126 -87
- package/dist/core/command/menu-catalog.js +1 -0
- package/dist/core/command/menu-handler.js +67 -150
- package/dist/core/command/menu-protocol.js +31 -1
- package/dist/core/command/provider-menu.js +13 -3
- package/dist/core/command/remote-shell.js +565 -0
- package/dist/core/command/role-menu.js +47 -23
- package/dist/core/command/slash-handler.js +26 -43
- package/dist/core/command/team-workspace-items.js +81 -12
- package/dist/core/command/team-workspace-team.js +9 -71
- package/dist/core/command/topic-slash.js +9 -30
- package/dist/core/daemon-bootstrap.js +8 -1
- package/dist/core/daemon-control.js +64 -8
- package/dist/core/daemon-lifecycle.js +16 -2
- package/dist/core/evolagent-registry.js +20 -3
- package/dist/core/file-integrity/store.js +2 -0
- package/dist/core/handoff/runtime.js +37 -1
- package/dist/core/inference/text-inference.js +3 -1
- package/dist/core/initialization/service.js +11 -6
- package/dist/core/interaction-router.js +3 -0
- package/dist/core/invoke/executors/text.js +72 -19
- package/dist/core/ipc-registration.js +3 -1
- package/dist/core/message/aun-ipc-sender.js +279 -107
- package/dist/core/message/contact-admission.js +91 -6
- package/dist/core/message/contact-pending-inbound.js +113 -0
- package/dist/core/message/contact-thread-approval.js +212 -0
- package/dist/core/message/im-renderer.js +41 -2
- package/dist/core/message/message-admission.js +5 -39
- package/dist/core/message/message-bridge.js +140 -370
- package/dist/core/message/message-log.js +29 -0
- package/dist/core/message/message-queue.js +119 -15
- package/dist/core/message/message-utils.js +8 -0
- package/dist/core/message/response-engine.js +580 -134
- package/dist/core/message/send-routing.js +5 -1
- package/dist/core/model/catalog-service.js +31 -11
- package/dist/core/model/config-scope.js +6 -14
- package/dist/core/model/model-capabilities.js +22 -4
- package/dist/core/model/model-catalog.js +1 -0
- package/dist/core/model/model-diagnostics.js +19 -0
- package/dist/core/model/model-fallback.js +13 -2
- package/dist/core/ownership/owner-resolver.js +328 -50
- package/dist/core/pack-auth.js +3 -0
- package/dist/core/pack-install.js +1 -1
- package/dist/core/permission/ec-command-parser.js +106 -19
- package/dist/core/permission/protected-paths.js +6 -6
- package/dist/core/permission/services-path-acl.js +451 -0
- package/dist/core/permission/tool-policy.js +5 -1
- package/dist/core/relation/peer-identity.js +36 -1
- package/dist/core/relation/same-owner-proof.js +81 -112
- package/dist/core/session/adapters/codex-session-file-adapter.js +96 -15
- package/dist/core/session/session-file-health.js +13 -7
- package/dist/core/session/session-fs-store.js +91 -35
- package/dist/core/session/session-manager.js +68 -24
- package/dist/core/session/session-mapper.js +14 -34
- package/dist/core/session/session-transcript.js +5 -1
- package/dist/core/task/task-activity-store.js +84 -0
- package/dist/core/task/task-recovery-service.js +13 -0
- package/dist/core/thread/command-parser.js +7 -12
- package/dist/core/thread/thread-context-storage.js +3 -2
- package/dist/core/thread/thread-operation.js +2 -13
- package/dist/core/thread/thread-service.js +15 -46
- package/dist/core/thread/topic-id.js +15 -0
- package/dist/directory/owner-directory-admission.js +12 -9
- package/dist/directory/owner-directory-cache.js +64 -28
- package/dist/directory/owner-directory-markdown.js +14 -2
- package/dist/directory/owner-directory-policy.js +5 -30
- package/dist/directory/owner-directory-query-operation.js +29 -3
- package/dist/directory/owner-directory-remarks.js +11 -3
- package/dist/directory/owner-directory-request-operation.js +5 -2
- package/dist/eck/kit-renderer.js +1 -1
- package/dist/eck/message-renderer.js +112 -29
- package/dist/ecweb/basic-settings-service.js +3 -1
- package/dist/ecweb/message-context-service.js +1 -1
- package/dist/ecweb/pairing.js +4 -3
- package/dist/ecweb/providers-service.js +26 -1
- package/dist/ecweb/runtime/lifecycle.js +18 -8
- package/dist/ecweb/runtime/proxy-access.js +74 -0
- package/dist/ecweb/runtime/supervisor.js +36 -6
- package/dist/event-center/center-config.js +9 -5
- package/dist/event-center/dispatcher.js +10 -1
- package/dist/event-center/ipc-operation.js +19 -0
- package/dist/event-center/registry.js +29 -3
- package/dist/event-center/runtime.js +106 -11
- package/dist/event-center/script-runner.js +5 -5
- package/dist/index.js +96 -59
- package/dist/ipc.js +38 -3
- package/dist/outputs/authorization.js +16 -0
- package/dist/outputs/cards.js +336 -0
- package/dist/outputs/events.js +63 -0
- package/dist/outputs/protocol.js +103 -0
- package/dist/outputs/service.js +266 -0
- package/dist/paths.js +3 -0
- package/dist/proxy/manager.js +43 -13
- package/dist/services/index.js +114 -5
- package/dist/services/ipc-operation.js +88 -15
- package/dist/services/pack-manager.js +13 -1
- package/dist/services/router.js +21 -6
- package/dist/services/script-runner.js +5 -4
- package/dist/services/service-payload.js +13 -7
- package/dist/services/validation.js +1 -1
- package/dist/stats/budget.js +2 -2
- package/dist/stats/db.js +19 -0
- package/dist/stats/index.js +1 -1
- package/dist/stats/{price-resolver.js → model-resolver.js} +304 -23
- package/dist/stats/normalizer.js +2 -0
- package/dist/stats/query.js +35 -27
- package/dist/stats/quota-query.js +95 -0
- package/dist/stats/role-budget.js +5 -2
- package/dist/stats/writer.js +10 -6
- package/dist/trigger/audit.js +7 -0
- package/dist/trigger/authorization.js +105 -11
- package/dist/trigger/feedback.js +10 -0
- package/dist/trigger/history.js +37 -11
- package/dist/trigger/ipc-service.js +12 -1
- package/dist/trigger/manager.js +1 -0
- package/dist/trigger/scheduler.js +7 -5
- package/dist/trigger/script-executor.js +2 -1
- package/dist/trigger/script-sandbox.js +21 -3
- package/dist/trigger/validation.js +22 -0
- package/dist/utils/atomic-write.js +22 -8
- package/dist/utils/cross-platform.js +73 -26
- package/dist/utils/error-dict.json +94 -4
- package/dist/utils/error-utils.js +27 -4
- package/dist/utils/evolcore-version.js +36 -65
- package/dist/utils/host-info.js +100 -1
- package/dist/utils/msg-diag.js +1 -0
- package/dist/utils/npm-ops.js +43 -8
- package/dist/utils/process-introspect.js +12 -7
- package/dist/utils/process-tree.js +50 -2
- package/dist/utils/windows-shell-trust.js +2 -0
- package/dist/workbench/protocol.js +80 -0
- package/dist/workbench/service.js +359 -0
- package/ecagent/dist/types.d.ts +6 -2
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +4 -2
- package/kits/docs/evolcore/aid.md +25 -0
- package/kits/docs/evolcore/config.md +16 -1
- package/kits/docs/evolcore/directory.md +30 -12
- package/kits/docs/evolcore/ecweb-lifecycle.md +15 -0
- package/kits/docs/evolcore/model.md +10 -0
- package/kits/docs/evolcore/msg.md +9 -0
- package/kits/docs/evolcore/peer.md +19 -65
- package/kits/docs/evolcore/provider.md +124 -4
- package/kits/docs/evolcore/quota.md +54 -0
- package/kits/docs/evolcore/role.md +83 -0
- package/kits/docs/evolcore/services.md +6 -6
- package/kits/docs/evolcore/stats.md +2 -0
- package/kits/docs/evolcore/team-workspace.md +1 -1
- package/kits/docs/evolcore/thread-chain.md +14 -15
- package/kits/docs/evolcore/tool-authorization.md +5 -0
- package/kits/docs/evolcore/trigger.md +12 -0
- package/kits/eck_message_manifest.json +12 -0
- package/kits/provider-templates.json +1213 -0
- package/kits/rules/04-relation.md +3 -3
- package/kits/schemas/_meta.json +14 -2
- package/kits/schemas/agent-config.schema.20.json +24 -0
- package/kits/schemas/contact-book.schema.4.json +52 -0
- package/kits/schemas/providers.schema.3.json +200 -0
- package/kits/skills/.switches.json +8 -0
- package/kits/skills/ability/references/calling.md +1 -1
- package/kits/skills/agent-output-cards/SKILL.md +57 -0
- package/kits/skills/ec-group/SKILL.md +2 -2
- package/kits/skills/ec-identity/SKILL.md +19 -72
- package/kits/skills/ec-provider/SKILL.md +270 -0
- package/kits/skills/ec-provider/scripts/check-model.mjs +80 -0
- package/kits/skills/ec-trigger/SKILL.md +1 -1
- package/kits/skills/thread-ops/SKILL.md +34 -21
- package/kits/templates/message-fragments/group-batch-item.md +1 -1
- package/kits/templates/message-fragments/group-batch.md +1 -1
- package/kits/templates/message-fragments/inject-default.md +1 -1
- package/kits/templates/message-fragments/interrupt-insert.md +1 -0
- package/kits/templates/message-fragments/item-group.md +1 -1
- package/kits/templates/message-fragments/item-private.md +1 -1
- package/kits/templates/message-fragments/thread-context.md +1 -1
- package/kits/templates/message-fragments/trigger-session.md +1 -1
- package/kits/templates/message-fragments/trigger-thread-check.md +1 -1
- package/kits/templates/roles/admin.json +2 -19
- package/kits/templates/roles/member.json +0 -3
- package/kits/templates/roles/visitor.json +1 -0
- package/kits/templates/system-fragments/baseagent.md +6 -0
- package/kits/templates/system-fragments/commands.md +4 -3
- package/kits/templates/system-fragments/directory-contacts.md +3 -4
- package/kits/templates/system-fragments/managed-runtime.md +1 -1
- package/kits/templates/system-fragments/relation.md +1 -1
- package/kits/templates/system-fragments/thread.md +7 -5
- package/kits/templates/system-fragments/venue.md +11 -0
- package/package.json +6 -4
- package/scripts/agent-template/inspect.mjs +50 -11
- package/scripts/agent-template/shared/common.mjs +11 -6
- package/scripts/agent-template/shared/team-schema.json +6 -4
- package/scripts/agent-template/shared/template-contract.mjs +62 -11
- package/scripts/agent-template/shared/template-package.mjs +189 -21
- package/scripts/agent-template/shared/template-runtime.mjs +54 -6
- package/scripts/agent-template/shared/template.mjs +2 -2
- package/scripts/agent-template/team-pack.mjs +52 -14
- package/dist/cli/peer.js +0 -127
- package/dist/config/peer-operation-service.js +0 -132
- package/dist/config/peer-request-service.js +0 -532
- package/dist/core/command/connect-menu.js +0 -624
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* 权限(沿用 /memory 的两级模型):
|
|
5
5
|
* - 只读(list / show / history / summary show / summary log / peers):
|
|
6
6
|
* 私聊所有角色可看;群聊仅 admin+ 可看
|
|
7
|
-
* - 写(create / rename /
|
|
7
|
+
* - 写(create / rename / status / delete / summary set / summary clear):
|
|
8
8
|
* 仅 admin+(群聊同样要求 admin,且只能操作本群关系)
|
|
9
9
|
* - rebuild-index:仅 admin+,且默认只报告不写盘(--write 才落盘)
|
|
10
10
|
*
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
import { ThreadService, ThreadServiceError } from '../thread/thread-service.js';
|
|
16
16
|
import { isTopicThreadId } from '../thread/topic-id.js';
|
|
17
17
|
import { parseTimeArg, TIME_ARG_FORMATS } from '../../cli/cli-argv.js';
|
|
18
|
-
const TOPIC_STATUSES = ['
|
|
18
|
+
const TOPIC_STATUSES = ['active', 'closed', 'archived'];
|
|
19
19
|
const USAGE = [
|
|
20
20
|
'用法(更名与总结默认作用于当前话题,无需手写 ref):',
|
|
21
21
|
' /thread rename <新名称> 重命名当前话题',
|
|
@@ -26,15 +26,14 @@ const USAGE = [
|
|
|
26
26
|
'',
|
|
27
27
|
' /thread 当前对端的话题列表(等价 /thread list)',
|
|
28
28
|
' /thread list all 本节点所有对端的话题列表',
|
|
29
|
-
' /thread list [ref] [--status <s>] [--
|
|
29
|
+
' /thread list [ref] [--status <s>] [--page <n>]',
|
|
30
30
|
' /thread peers 列出有话题记录的所有对端',
|
|
31
31
|
' /thread show [ref] 查看话题元数据',
|
|
32
32
|
' /thread history [ref] [--limit <n>] [--after <ts>] [--before <ts>]',
|
|
33
33
|
' 读取话题历史消息(--after 上次 summary 的 coveredThroughTs 读增量)',
|
|
34
34
|
'',
|
|
35
|
-
' /thread create <名称> [--
|
|
36
|
-
' /thread
|
|
37
|
-
' /thread status [ref] <状态> 更新话题业务状态',
|
|
35
|
+
' /thread create <名称> [--status <s>] 新建话题',
|
|
36
|
+
' /thread status [ref] <状态> 更新话题状态(active|closed|archived)',
|
|
38
37
|
' /thread delete [ref] 删除话题(session 文件移入 _trash)',
|
|
39
38
|
' /thread rebuild-index [--write] 检查/重建话题索引',
|
|
40
39
|
'',
|
|
@@ -80,7 +79,7 @@ export function topicHelpEntries(ctx) {
|
|
|
80
79
|
out.push({ command: '/thread', aliases: ['/thread list'], description: '当前对端的话题列表', category, roles }, { command: '/thread list all', description: '本节点所有对端的话题列表', category, roles }, { command: '/thread peers', description: '有话题记录的所有对端', category, roles }, { command: '/thread show', description: '查看话题元数据', args: '[ref]', category, roles }, { command: '/thread history', description: '读取话题历史消息', args: '[ref] [--limit <n>]', category, roles });
|
|
81
80
|
// 第三档:其余写操作与索引维护
|
|
82
81
|
if (write) {
|
|
83
|
-
out.push({ command: '/thread create', description: '新建话题', args: '<名称> [--
|
|
82
|
+
out.push({ command: '/thread create', description: '新建话题', args: '<名称> [--status <s>]', category, roles }, { command: '/thread status', description: '更新话题状态', args: '[ref] <状态>', category, roles }, { command: '/thread delete', description: '删除话题', args: '[ref]', category, roles }, { command: '/thread rebuild-index', description: '检查话题索引健康状态', category, roles });
|
|
84
83
|
}
|
|
85
84
|
out.push({ command: '/thread help', description: '全部子命令说明', category, roles });
|
|
86
85
|
return out;
|
|
@@ -133,11 +132,10 @@ function truncate(s, n) {
|
|
|
133
132
|
}
|
|
134
133
|
function formatThreadLine(t, currentThreadId) {
|
|
135
134
|
const mark = currentThreadId && t.threadId === currentThreadId ? ' ←当前' : '';
|
|
136
|
-
//
|
|
135
|
+
// 标题只放标题本身;状态单独成字段,不与标题拼接
|
|
137
136
|
const bits = [
|
|
138
137
|
t.name,
|
|
139
|
-
t.
|
|
140
|
-
t.topicStatus ? `状态:${t.topicStatus}` : '',
|
|
138
|
+
t.topicStatus && t.topicStatus !== 'active' ? `状态:${t.topicStatus}` : '',
|
|
141
139
|
formatTime(t.lastActiveAt),
|
|
142
140
|
t.lastMsgSnippet ? truncate(t.lastMsgSnippet, 30) : '',
|
|
143
141
|
].filter(Boolean);
|
|
@@ -256,7 +254,6 @@ export async function handleTopicSlash(ctx) {
|
|
|
256
254
|
`session: ${t.sessionId}`,
|
|
257
255
|
`对端: ${t.peer}(${t.peerKind === 'group' ? '群' : '私聊'})`,
|
|
258
256
|
`状态: ${t.topicStatus}`,
|
|
259
|
-
`标签: ${t.label ?? '(无)'}`,
|
|
260
257
|
`创建: ${formatTime(t.createdAt)} 最近活跃: ${formatTime(t.lastActiveAt)}`,
|
|
261
258
|
`消息: ${t.msgTotal ?? 0} 条(24h 内 ${t.msg24h ?? 0} 条)`,
|
|
262
259
|
];
|
|
@@ -302,7 +299,7 @@ export async function handleTopicSlash(ctx) {
|
|
|
302
299
|
if (sub === 'create') {
|
|
303
300
|
const name = positional[0];
|
|
304
301
|
if (!name)
|
|
305
|
-
return error('用法: /thread create <名称> [--
|
|
302
|
+
return error('用法: /thread create <名称> [--status <状态>]');
|
|
306
303
|
if (!ctx.peerKey)
|
|
307
304
|
return error('当前会话没有关系上下文,无法新建话题');
|
|
308
305
|
const status = flags.status !== undefined ? needStatus(flags.status) : undefined;
|
|
@@ -315,7 +312,6 @@ export async function handleTopicSlash(ctx) {
|
|
|
315
312
|
peer: ctx.peerKey,
|
|
316
313
|
peerKind: ctx.chatType === 'group' ? 'group' : 'private',
|
|
317
314
|
name,
|
|
318
|
-
...(typeof flags.label === 'string' ? { label: flags.label } : {}),
|
|
319
315
|
...(status ? { topicStatus: status } : {}),
|
|
320
316
|
});
|
|
321
317
|
return result(`✅ 已创建话题: ${created.name}\nref: ${created.threadId}`);
|
|
@@ -333,21 +329,6 @@ export async function handleTopicSlash(ctx) {
|
|
|
333
329
|
const r = await service.renameThread({ selfAid: ctx.selfAid, peer: target.peer, threadId: target.threadId, name });
|
|
334
330
|
return result(r.changed ? `✅ 已重命名为 ${r.name}` : `话题名称已是 ${r.name}`);
|
|
335
331
|
}
|
|
336
|
-
if (sub === 'label') {
|
|
337
|
-
const ref = refSource(positional, flags);
|
|
338
|
-
const target = resolveRef(ref, ctx, service);
|
|
339
|
-
if (isPayload(target))
|
|
340
|
-
return target;
|
|
341
|
-
if (!target.threadId)
|
|
342
|
-
return error('不能标记主会话;请指定 <peer>/<threadId>');
|
|
343
|
-
const clear = flags.clear === true;
|
|
344
|
-
const labelArg = stripRefArg(positional, ref).join(' ').trim();
|
|
345
|
-
if (!clear && !labelArg)
|
|
346
|
-
return error('用法: /thread label <标签> 或 /thread label --clear');
|
|
347
|
-
const label = clear ? null : labelArg;
|
|
348
|
-
await service.labelThread({ selfAid: ctx.selfAid, peer: target.peer, threadId: target.threadId, label });
|
|
349
|
-
return result(clear ? '✅ 已清除标签' : `✅ 已设置标签: ${label}`);
|
|
350
|
-
}
|
|
351
332
|
if (sub === 'status') {
|
|
352
333
|
const ref = refSource(positional, flags);
|
|
353
334
|
const target = resolveRef(ref, ctx, service);
|
|
@@ -416,8 +397,6 @@ async function listThreads(ctx, service, positional, flags) {
|
|
|
416
397
|
selfAid: ctx.selfAid,
|
|
417
398
|
...(peer ? { peer } : {}),
|
|
418
399
|
...(status ? { status } : {}),
|
|
419
|
-
...(typeof flags.label === 'string' ? { label: flags.label } : {}),
|
|
420
|
-
...(flags.unlabeled === true ? { unlabeled: true } : {}),
|
|
421
400
|
...(flags.sort === 'created' ? { sort: 'created' } : {}),
|
|
422
401
|
page: Number.isFinite(page) && page > 0 ? page : 1,
|
|
423
402
|
limit: Number.isFinite(limit) && limit > 0 ? limit : 10,
|
|
@@ -14,13 +14,15 @@ import { TriggerDefinitionManager } from '../trigger/manager.js';
|
|
|
14
14
|
import { seedUpgradeCheckTrigger } from '../trigger/system-definitions.js';
|
|
15
15
|
import { ownerResolver } from './ownership/owner-resolver.js';
|
|
16
16
|
import { ecwebInitializationService } from './initialization/service.js';
|
|
17
|
+
import { readServiceProxySnapshot, ServiceProxyManager } from '../proxy/manager.js';
|
|
17
18
|
export function detectAvailableBaseagents() {
|
|
18
19
|
// 与 init/ECWeb 的探测保持同一判据;claude 在这里也走内置二进制,
|
|
19
20
|
// 不再只看 PATH——否则 daemon 会对外声明一个实际跑不起来的 baseagent。
|
|
20
21
|
return detectBaseagentDetails().filter(item => item.detected).map(item => item.id);
|
|
21
22
|
}
|
|
22
|
-
export async function runBindBootstrapDaemon(daemonCfg) {
|
|
23
|
+
export async function runBindBootstrapDaemon(daemonCfg, ecwebSupervisor) {
|
|
23
24
|
logger.warn('[daemon-bootstrap] starting control AID + IPC only');
|
|
25
|
+
ecwebInitializationService.setRuntimeControlAid(daemonCfg.aid);
|
|
24
26
|
const bootstrapControlAid = daemonCfg.aid || '__daemon__';
|
|
25
27
|
try {
|
|
26
28
|
seedUpgradeCheckTrigger(new TriggerDefinitionManager(bootstrapControlAid), {
|
|
@@ -57,6 +59,8 @@ export async function runBindBootstrapDaemon(daemonCfg) {
|
|
|
57
59
|
aunTrace: daemonCfg.debug?.aunTrace,
|
|
58
60
|
aunSdkLog: daemonCfg.debug?.aunSdkLog,
|
|
59
61
|
});
|
|
62
|
+
const serviceManager = new ServiceProxyManager({ providerAid: daemonCfg.aid, controlChannel, ecwebSupervisor });
|
|
63
|
+
await serviceManager.start();
|
|
60
64
|
controlChannel.onMessage(async (opts) => {
|
|
61
65
|
const text = (opts.content || '').trim();
|
|
62
66
|
let parsed = null;
|
|
@@ -91,6 +95,7 @@ export async function runBindBootstrapDaemon(daemonCfg) {
|
|
|
91
95
|
channels: {},
|
|
92
96
|
channelsByType: {},
|
|
93
97
|
queue: { pending: 0, processing: 0 },
|
|
98
|
+
serviceProxy: readServiceProxySnapshot(serviceManager.transportSnapshot()),
|
|
94
99
|
controlAid: (() => {
|
|
95
100
|
const aidState = controlChannel?.getAidState();
|
|
96
101
|
return {
|
|
@@ -137,6 +142,8 @@ export async function runBindBootstrapDaemon(daemonCfg) {
|
|
|
137
142
|
}
|
|
138
143
|
catch { }
|
|
139
144
|
bindService.stopCleanup();
|
|
145
|
+
await serviceManager.stop();
|
|
146
|
+
await ecwebSupervisor?.stop();
|
|
140
147
|
if (controlChannel) {
|
|
141
148
|
try {
|
|
142
149
|
await controlChannel.disconnect();
|
|
@@ -9,6 +9,7 @@ import { authorizationDenialData, formatAuthorizationDenial } from './auth/autho
|
|
|
9
9
|
import { controlReplyContext } from './message/outbound.js';
|
|
10
10
|
import { deliverMenuResponse, enforceMenuResponseSize, evaluateMenuClientCompatibility, evolMenuResponseTransportMetadata, hasValidMenuId, logMenuRequestCompleted, logMenuRequestReceived, logMenuResponseRetry, MENU_RESPONSE_MAX_BYTES, MENU_RESPONSE_SAFETY_MARGIN_BYTES, MenuRequestDeduper, menuFailure, menuPayloadFingerprint, normalizeMenuResponseTiming, parseMenuControl, validateMenuRequest, withMenuProcessingTime, beginMenuDeliveryTiming, } from './command/menu-protocol.js';
|
|
11
11
|
import { isProcessLevelOwner } from './command/command-handler.js';
|
|
12
|
+
import { RemoteShellService } from './command/remote-shell.js';
|
|
12
13
|
import { onShutdown } from '../utils/cross-platform.js';
|
|
13
14
|
import { logger } from '../utils/logger.js';
|
|
14
15
|
import { resolvePaths } from '../paths.js';
|
|
@@ -17,23 +18,22 @@ import { subscribeUpgradeJob } from '../utils/upgrade-jobs.js';
|
|
|
17
18
|
import { subscribeTemplateJob } from '../agent-template/service.js';
|
|
18
19
|
const controlMenuDeduper = new MenuRequestDeduper();
|
|
19
20
|
export function startDaemonControlAid({ daemonCfg, cmdHandler, bindService, diagService, getProcessOwners, ecwebSupervisor, onServiceProxyManager, connectChannel, startupTrace, waitForServices, }) {
|
|
20
|
-
if (!daemonCfg.aid)
|
|
21
|
-
return undefined;
|
|
22
21
|
const aunPath = resolvePaths().root;
|
|
23
|
-
const certKey = path.join(aunPath, 'AIDs', daemonCfg.aid, 'private', 'key.json');
|
|
24
|
-
if (!fs.existsSync(certKey)) {
|
|
22
|
+
const certKey = daemonCfg.aid ? path.join(aunPath, 'AIDs', daemonCfg.aid, 'private', 'key.json') : undefined;
|
|
23
|
+
if (certKey && !fs.existsSync(certKey)) {
|
|
25
24
|
logger.warn(`控制 AID 证书缺失:${daemonCfg.aid}(AUN 控制通道后台重连;如需重建运行 ec init)`);
|
|
26
25
|
}
|
|
27
|
-
const controlChannel = new AUNChannel({
|
|
26
|
+
const controlChannel = daemonCfg.aid ? new AUNChannel({
|
|
28
27
|
aid: daemonCfg.aid,
|
|
29
28
|
agentName: daemonCfg.aid,
|
|
30
29
|
channelName: 'control',
|
|
31
30
|
pureIdentity: true,
|
|
31
|
+
controlOwnerAid: daemonCfg.owner,
|
|
32
32
|
defaultEncrypt: daemonCfg.aun?.defaultEncrypt,
|
|
33
33
|
aunTrace: daemonCfg.debug?.aunTrace,
|
|
34
34
|
aunSdkLog: daemonCfg.debug?.aunSdkLog,
|
|
35
|
-
});
|
|
36
|
-
const serviceProxyManager = new ServiceProxyManager({ providerAid: daemonCfg.aid, controlChannel, ecwebSupervisor: ecwebSupervisor ?? undefined, startupTrace });
|
|
35
|
+
}) : undefined;
|
|
36
|
+
const serviceProxyManager = new ServiceProxyManager({ providerAid: daemonCfg.aid ?? '', controlChannel, ecwebSupervisor: ecwebSupervisor ?? undefined, startupTrace });
|
|
37
37
|
onServiceProxyManager?.(serviceProxyManager);
|
|
38
38
|
let stopping = false;
|
|
39
39
|
onShutdown(() => { stopping = true; return serviceProxyManager.stop(); });
|
|
@@ -52,7 +52,63 @@ export function startDaemonControlAid({ daemonCfg, cmdHandler, bindService, diag
|
|
|
52
52
|
void proxyStartup.catch((error) => {
|
|
53
53
|
logger.warn(`ServiceProxy manager 启动失败(不影响 daemon 主流程): ${error?.message || error}`);
|
|
54
54
|
});
|
|
55
|
+
if (!controlChannel)
|
|
56
|
+
return undefined;
|
|
57
|
+
const currentShellOwner = () => {
|
|
58
|
+
const view = ownerResolver.snapshot(daemonCfg.aid);
|
|
59
|
+
const aid = ownerResolver.owner(daemonCfg.aid);
|
|
60
|
+
const relationVersion = view.relation?.relationVersion;
|
|
61
|
+
return aid && relationVersion !== undefined ? {
|
|
62
|
+
aid, relationVersion,
|
|
63
|
+
...(view.validUntil !== undefined && !view.refreshFailure?.fallbackUsed
|
|
64
|
+
? { validForMs: Math.max(0, view.validUntil - Date.now()) } : {}),
|
|
65
|
+
} : undefined;
|
|
66
|
+
};
|
|
67
|
+
const remoteShell = new RemoteShellService({
|
|
68
|
+
controlAid: daemonCfg.aid,
|
|
69
|
+
currentOwner: currentShellOwner,
|
|
70
|
+
refreshOwner: async () => {
|
|
71
|
+
await ownerResolver.refresh(daemonCfg.aid, {
|
|
72
|
+
source: 'remote-shell', maxAgeMs: OWNERSHIP_AUTHORIZATION_MAX_AGE_MS, allowTransient: true,
|
|
73
|
+
});
|
|
74
|
+
return currentShellOwner();
|
|
75
|
+
},
|
|
76
|
+
connected: () => controlChannel.isConnected(),
|
|
77
|
+
send: async (input, text) => {
|
|
78
|
+
const result = await controlChannel.sendMessage(input.peerId, text, {
|
|
79
|
+
...controlReplyContext(input, { encrypted: true }),
|
|
80
|
+
toDeviceId: input.peerDeviceId,
|
|
81
|
+
});
|
|
82
|
+
if (result.status === 'failed')
|
|
83
|
+
throw new Error('Remote shell text delivery failed');
|
|
84
|
+
},
|
|
85
|
+
notice: async (input, text, subtype) => {
|
|
86
|
+
await controlChannel.sendStructuredOrThrow(input.peerId, {
|
|
87
|
+
type: 'notice', subtype, severity: 'info', text,
|
|
88
|
+
}, {
|
|
89
|
+
...controlReplyContext(input, { encrypted: true }),
|
|
90
|
+
toDeviceId: input.peerDeviceId,
|
|
91
|
+
});
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
const stopShellTransport = controlChannel.onTransportState(connected => {
|
|
95
|
+
if (!connected)
|
|
96
|
+
void remoteShell.closeAll('disconnected');
|
|
97
|
+
});
|
|
98
|
+
const stopShellOwnership = ownerResolver.onUpdate(aid => {
|
|
99
|
+
if (aid === daemonCfg.aid)
|
|
100
|
+
remoteShell.revalidateOwner();
|
|
101
|
+
});
|
|
102
|
+
onShutdown(async () => {
|
|
103
|
+
stopShellTransport();
|
|
104
|
+
stopShellOwnership();
|
|
105
|
+
await remoteShell.dispose();
|
|
106
|
+
});
|
|
55
107
|
controlChannel.onMessage(async (opts) => {
|
|
108
|
+
if (remoteShell.handles(opts)) {
|
|
109
|
+
await remoteShell.handleText(opts);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
56
112
|
const text = (opts.content || '').trim();
|
|
57
113
|
let activeMenuRequest;
|
|
58
114
|
let menuCompletionLogged = false;
|
|
@@ -239,7 +295,7 @@ export function startDaemonControlAid({ daemonCfg, cmdHandler, bindService, diag
|
|
|
239
295
|
}
|
|
240
296
|
return;
|
|
241
297
|
}
|
|
242
|
-
await controlChannel.sendMessage(opts.channelId, '可用指令:/pair(获取远程控制配对码)、/diag <问题描述>、/diag stop', controlReplyContext(opts));
|
|
298
|
+
await controlChannel.sendMessage(opts.channelId, '可用指令:/pair(获取远程控制配对码)、/diag <问题描述>、/diag stop、/exec(查询终端状态)、/exec on(进入终端,直接发送单条命令)、/exec off、/stop(兼容 /exec stop)', controlReplyContext(opts));
|
|
243
299
|
}
|
|
244
300
|
catch (e) {
|
|
245
301
|
if (activeMenuRequest && !menuCompletionLogged) {
|
|
@@ -467,8 +467,17 @@ export async function recoverStartupObserverHints(options) {
|
|
|
467
467
|
}
|
|
468
468
|
catch (error) {
|
|
469
469
|
attempts++;
|
|
470
|
+
// 一个永久失败的 Agent 不能无限期占住它自己的输入,更不能拖住宿主的总就绪
|
|
471
|
+
// 判定(`startupRecoveryPending` 会一直不清)。到上限后按降级放行,
|
|
472
|
+
// 并把被跳过的提示作为显式错误报出来,而不是静默丢弃。
|
|
473
|
+
if (attempts >= MAX_OBSERVER_HINT_ATTEMPTS) {
|
|
474
|
+
options.trace?.addSpan('daemon.observerHints', started, Date.now(), `${aid}; giving up after ${attempts} attempts`);
|
|
475
|
+
logger.error(`[startup] observer hint registration gave up for ${aid} after ${attempts} attempts; pending hints in this Agent are not restored: ${error}`);
|
|
476
|
+
options.onAgentHintsRecovered(aid);
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
470
479
|
options.trace?.addSpan('daemon.observerHints', started, Date.now(), `${aid}; retry pending`);
|
|
471
|
-
logger.warn(`[startup] observer hint registration waits for ${aid} (attempt ${attempts}): ${error}`);
|
|
480
|
+
logger.warn(`[startup] observer hint registration waits for ${aid} (attempt ${attempts}/${MAX_OBSERVER_HINT_ATTEMPTS}): ${error}`);
|
|
472
481
|
await recoveryRetryDelay();
|
|
473
482
|
}
|
|
474
483
|
}
|
|
@@ -481,6 +490,8 @@ export async function recoverStartupObserverHints(options) {
|
|
|
481
490
|
function recoveryRetryDelay() {
|
|
482
491
|
return new Promise(resolve => { const timer = setTimeout(resolve, 1_000); timer.unref?.(); });
|
|
483
492
|
}
|
|
493
|
+
/** Observer hint 注册的连续失败上限:超过即降级放行,避免单个 Agent 拖住整个宿主就绪。 */
|
|
494
|
+
const MAX_OBSERVER_HINT_ATTEMPTS = 30;
|
|
484
495
|
/**
|
|
485
496
|
* Background recovery never gates Ready. Until an Agent's scan completes its
|
|
486
497
|
* inputs stay queued; afterwards only sessions referenced by unfinished
|
|
@@ -499,8 +510,11 @@ export class StartupHandoffRecovery {
|
|
|
499
510
|
const state = this.states.get(aid);
|
|
500
511
|
if (!state || state.phase === 'ready')
|
|
501
512
|
return;
|
|
513
|
+
// 扫描尚未产出结论时不阻塞:没有证据说明这个会话受任何未完成的 Handoff 影响,
|
|
514
|
+
// 退回 'startup Handoff scan' 会把该 Agent 的每个会话都挂在一次可能永远
|
|
515
|
+
// 等不到结果的后台扫描后面(与类注释的「后台恢复永不 gate Ready」矛盾)。
|
|
502
516
|
if (!state.sessions)
|
|
503
|
-
return
|
|
517
|
+
return;
|
|
504
518
|
if (state.sessions.has(sessionId))
|
|
505
519
|
return 'session Handoff recovery';
|
|
506
520
|
}
|
|
@@ -11,6 +11,7 @@ import { ensureInitialRoleRegistry } from '../config/role-service.js';
|
|
|
11
11
|
import { resolveAgentLifecycle } from '../config/lifecycle.js';
|
|
12
12
|
import { getOwners, getPrimaryOwner, ownerResolver } from './ownership/owner-resolver.js';
|
|
13
13
|
import { configuredOwnerList } from '../config/owner-config.js';
|
|
14
|
+
import { assertTemplateInstallationReady } from '../agent-template/jobs.js';
|
|
14
15
|
// ── Channel Fingerprint ───────────────────────────────────────────────────
|
|
15
16
|
// 用于检测多 agent 之间复用同一外部凭证的冲突(appId、aid、token 等)。
|
|
16
17
|
// 格式:{type}:{primaryKey}
|
|
@@ -299,10 +300,11 @@ export class EvolAgentRegistry {
|
|
|
299
300
|
logger.info(`[EvolAgentRegistry] Hot-loaded agent: ${aid}`);
|
|
300
301
|
return agent;
|
|
301
302
|
}
|
|
302
|
-
async reload(aidOrName, hooks) {
|
|
303
|
+
async reload(aidOrName, hooks, options = {}) {
|
|
303
304
|
const oldAgent = this.agents.get(aidOrName);
|
|
304
305
|
if (!oldAgent)
|
|
305
306
|
throw new Error(`Agent "${aidOrName}" not found`);
|
|
307
|
+
assertTemplateInstallationReady(oldAgent.aid, options.recoveryJobId);
|
|
306
308
|
await hooks.beforeAgentOperation?.(oldAgent.aid);
|
|
307
309
|
const expandedRaw = loadAgent(oldAgent.aid);
|
|
308
310
|
if (!expandedRaw)
|
|
@@ -316,6 +318,16 @@ export class EvolAgentRegistry {
|
|
|
316
318
|
const raw = readConfig(ConfigTarget.Agent, { self: oldAgent.aid }, { cache: true }) ?? expandedRaw;
|
|
317
319
|
ownerResolver.setAgentConfiguredOwners(oldAgent.aid, configuredOwnerList(raw));
|
|
318
320
|
const merged = resolveEffective({ self: raw.aid }, {});
|
|
321
|
+
if (oldAgent.status === 'disabled' && raw.enabled === false
|
|
322
|
+
|| (options.preserveStopped && oldAgent.status === 'stopped' || options.restoreStopped) && raw.enabled !== false) {
|
|
323
|
+
oldAgent.swapConfig(raw, merged);
|
|
324
|
+
oldAgent.invalidatePersonaCache();
|
|
325
|
+
if (options.restoreStopped && raw.enabled !== false) {
|
|
326
|
+
oldAgent.status = 'stopped';
|
|
327
|
+
this.manuallyStopped.add(oldAgent.aid);
|
|
328
|
+
}
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
319
331
|
if (oldAgent.status === 'disabled' && raw.enabled !== false) {
|
|
320
332
|
oldAgent.swapConfig(raw, merged);
|
|
321
333
|
const hotLoad = globalThis.__evolcore_hotLoadAgent;
|
|
@@ -567,6 +579,7 @@ export class EvolAgentRegistry {
|
|
|
567
579
|
}
|
|
568
580
|
async startAgent(aidOrName, hooks) {
|
|
569
581
|
assertAgentAidAvailable(aidOrName);
|
|
582
|
+
assertTemplateInstallationReady(aidOrName);
|
|
570
583
|
const agent = this.agents.get(aidOrName);
|
|
571
584
|
if (!agent)
|
|
572
585
|
throw new Error(`Agent "${aidOrName}" not found`);
|
|
@@ -691,8 +704,12 @@ function safeInfoValue(fn, fallback) {
|
|
|
691
704
|
function findInstanceByKey(raw, agent, channelKey) {
|
|
692
705
|
return raw.channels.find(c => agent.effectiveChannelName(c.type, c.name) === channelKey) ?? null;
|
|
693
706
|
}
|
|
694
|
-
/**
|
|
695
|
-
|
|
707
|
+
/**
|
|
708
|
+
* active Agent 只有本地私钥和证书齐全,才参与启动编排。
|
|
709
|
+
*
|
|
710
|
+
* 纯本地文件判定(不读注册表状态),导出以便单测直接覆盖各 lifecycle / 文件组合。
|
|
711
|
+
*/
|
|
712
|
+
export function precheckAgentConfig(aid, config) {
|
|
696
713
|
if (resolveAgentLifecycle(config) !== 'active')
|
|
697
714
|
return null;
|
|
698
715
|
const directory = aidLocalDir(aid);
|
|
@@ -192,6 +192,8 @@ function verifyLocked(filePath, key, opts) {
|
|
|
192
192
|
const db = getDb();
|
|
193
193
|
const row = db.prepare('SELECT sha256, package_version FROM file_integrity WHERE file_path = ?').get(key);
|
|
194
194
|
if (!row) {
|
|
195
|
+
if (opts?.requireRegistered)
|
|
196
|
+
return { status: 'tampered', actual, restorable: false };
|
|
195
197
|
// 用已读字节登记,避免二次读文件时内容已变
|
|
196
198
|
persistBytes(key, bytes, undefined, fs.statSync(filePath).mtime, packageVersion);
|
|
197
199
|
logger.info(`[file-integrity] auto-registered path=${key} sha256=${short(actual)}`);
|
|
@@ -9,7 +9,7 @@ import { recordCausationSpan } from '../causation/audit.js';
|
|
|
9
9
|
import { logger } from '../../utils/logger.js';
|
|
10
10
|
import { setImmediate as yieldToIo } from 'node:timers/promises';
|
|
11
11
|
import { replyContextFromSession } from '../message/message-utils.js';
|
|
12
|
-
import { sessionTopicThreadId } from '../thread/topic-id.js';
|
|
12
|
+
import { safeFormatMainTopicId, sessionTopicThreadId } from '../thread/topic-id.js';
|
|
13
13
|
const HANDOFF_STALE_WARN_MS = 12 * 60 * 60 * 1000;
|
|
14
14
|
const HANDOFF_RETENTION_MS = 72 * 60 * 60 * 1000;
|
|
15
15
|
const HANDOFF_LARGE_AGGREGATE_COUNT = 10;
|
|
@@ -92,12 +92,48 @@ export class HandoffRuntime {
|
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
94
|
const targetChatType = input.targetChatType;
|
|
95
|
+
const expectedTarget = input.expectedTarget;
|
|
96
|
+
if (expectedTarget) {
|
|
97
|
+
const targetChannelKeyType = tryParseChannelKey(targetChannelKey)?.type;
|
|
98
|
+
const expectedMainThread = safeFormatMainTopicId(input.selfAid, expectedTarget.channelId);
|
|
99
|
+
const threadMatches = expectedTarget.threadId
|
|
100
|
+
? input.thread === expectedTarget.threadId
|
|
101
|
+
: !input.thread || input.thread === expectedMainThread;
|
|
102
|
+
if (input.to !== expectedTarget.channelId || targetChatType !== expectedTarget.chatType
|
|
103
|
+
|| targetChannelType !== expectedTarget.channelType || targetChannelKeyType !== expectedTarget.channelType
|
|
104
|
+
|| !threadMatches) {
|
|
105
|
+
throw Object.assign(new Error('Handoff request does not match the verified send route'), {
|
|
106
|
+
code: 'AUN_OUTBOUND_ROUTE_MISMATCH',
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
if (expectedTarget.sessionId) {
|
|
110
|
+
const indexedTarget = await this.sessionManager.getSessionById(expectedTarget.sessionId);
|
|
111
|
+
if (!indexedTarget || indexedTarget.selfAID !== input.selfAid
|
|
112
|
+
|| indexedTarget.channelType !== expectedTarget.channelType
|
|
113
|
+
|| indexedTarget.channelId !== expectedTarget.channelId
|
|
114
|
+
|| indexedTarget.chatType !== expectedTarget.chatType
|
|
115
|
+
|| sessionTopicThreadId(indexedTarget) !== expectedTarget.threadId) {
|
|
116
|
+
throw Object.assign(new Error('Indexed handoff session does not match the verified send route'), {
|
|
117
|
+
code: 'AUN_OUTBOUND_ROUTE_MISMATCH',
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
95
122
|
const target = await this.sessionManager.getOrCreateSession(targetChannelKey, input.to, origin.projectPath, input.thread, {
|
|
96
123
|
channelKey: targetChannelKey,
|
|
97
124
|
peerId: input.to,
|
|
98
125
|
...(targetChatType === 'group' ? { groupId: input.to } : {}),
|
|
99
126
|
}, undefined, input.to, targetChatType, origin.baseagent, input.selfAid, targetChannelType, targetChatType === 'group' ? 'group' : 'agent');
|
|
100
127
|
throwIfAborted(input.signal);
|
|
128
|
+
const expected = input.expectedTarget;
|
|
129
|
+
if (expected && ((expected.sessionId && target.id !== expected.sessionId)
|
|
130
|
+
|| target.selfAID !== input.selfAid
|
|
131
|
+
|| target.channelType !== expected.channelType || target.channelId !== expected.channelId
|
|
132
|
+
|| target.chatType !== expected.chatType || sessionTopicThreadId(target) !== expected.threadId)) {
|
|
133
|
+
throw Object.assign(new Error('Resolved handoff session does not match the verified send route'), {
|
|
134
|
+
code: 'AUN_OUTBOUND_ROUTE_MISMATCH',
|
|
135
|
+
});
|
|
136
|
+
}
|
|
101
137
|
if (target.id === origin.id) {
|
|
102
138
|
if (input.handoffContext !== undefined)
|
|
103
139
|
throw new Error('handoff context requires a different target session');
|
|
@@ -5,7 +5,7 @@ import { appendRequestPath, appendV1RequestPath } from '../../agents/request-ide
|
|
|
5
5
|
import { assertExplicitProviderModelAllowed, resolveServiceSelection } from '../../config/providers.js';
|
|
6
6
|
import { eligibleServiceFallbackModels } from '../model/model-fallback.js';
|
|
7
7
|
import { RetryScheduler } from '../message/retry-scheduler.js';
|
|
8
|
-
import { classifyError, ErrorType } from '../../utils/error-utils.js';
|
|
8
|
+
import { classifyError, errorQuestionRule, ErrorType } from '../../utils/error-utils.js';
|
|
9
9
|
import { resolveProjectDefaultPath } from '../../utils/project-path.js';
|
|
10
10
|
/** 决策判定用的系统提示词:把 state 与问题一起喂给通用模型,要求只回 JSON。 */
|
|
11
11
|
const DECISION_SYSTEM_PROMPT = 'Evaluate the provided state against each question and its criteria. '
|
|
@@ -75,6 +75,8 @@ async function completeServiceRequest(input) {
|
|
|
75
75
|
input.request.signal?.throwIfAborted();
|
|
76
76
|
if (error?.name === 'AbortError')
|
|
77
77
|
throw error;
|
|
78
|
+
if (errorQuestionRule(error))
|
|
79
|
+
throw error;
|
|
78
80
|
if (classifyError(error) !== ErrorType.MODEL_UNAVAILABLE && error?.status !== 404)
|
|
79
81
|
throw error;
|
|
80
82
|
if (!scheduler) {
|
|
@@ -68,12 +68,14 @@ function qrSvg(payload) {
|
|
|
68
68
|
export class EcwebInitializationService {
|
|
69
69
|
deps;
|
|
70
70
|
agentInitializer;
|
|
71
|
+
runtimeControlAid;
|
|
71
72
|
ownerRecoveryAt = new Map();
|
|
72
73
|
queue = Promise.resolve();
|
|
73
74
|
constructor(deps = {}) {
|
|
74
75
|
this.deps = deps;
|
|
75
76
|
}
|
|
76
77
|
setAgentInitializer(service) { this.agentInitializer = service; }
|
|
78
|
+
setRuntimeControlAid(aid) { this.runtimeControlAid = () => aid; }
|
|
77
79
|
exclusive(action) {
|
|
78
80
|
const result = this.queue.then(action);
|
|
79
81
|
this.queue = result.catch(() => undefined);
|
|
@@ -94,9 +96,10 @@ export class EcwebInitializationService {
|
|
|
94
96
|
fs.chmodSync(file, 0o600);
|
|
95
97
|
}
|
|
96
98
|
read(workflowId) {
|
|
97
|
-
const aid = this.deps.controlAid ? this.deps.controlAid()
|
|
99
|
+
const aid = this.deps.controlAid ? this.deps.controlAid()
|
|
100
|
+
: this.runtimeControlAid ? this.runtimeControlAid() : loadDaemonConfig().aid;
|
|
98
101
|
if (!aid || !isValidAid(aid))
|
|
99
|
-
fail('CONTROL_AID_NOT_READY', '
|
|
102
|
+
fail('CONTROL_AID_NOT_READY', '主机身份待准备,请在本机运行 ec init --web,准备身份并重启后继续', 409);
|
|
100
103
|
let state;
|
|
101
104
|
try {
|
|
102
105
|
state = atomicReadJson(this.file(workflowId));
|
|
@@ -125,7 +128,7 @@ export class EcwebInitializationService {
|
|
|
125
128
|
if (this.deps.refreshOwner)
|
|
126
129
|
return this.deps.refreshOwner(aid, { force });
|
|
127
130
|
const { ownerResolver, OWNERSHIP_AUTHORIZATION_MAX_AGE_MS } = await import('../ownership/owner-resolver.js');
|
|
128
|
-
return ownerResolver.refresh(aid, { force, maxAgeMs: OWNERSHIP_AUTHORIZATION_MAX_AGE_MS, allowTransient:
|
|
131
|
+
return ownerResolver.refresh(aid, { force, maxAgeMs: OWNERSHIP_AUTHORIZATION_MAX_AGE_MS, allowTransient: false, source });
|
|
129
132
|
}
|
|
130
133
|
async bind(aid, owner) {
|
|
131
134
|
if (this.deps.bindOwner)
|
|
@@ -211,7 +214,7 @@ export class EcwebInitializationService {
|
|
|
211
214
|
}
|
|
212
215
|
return defaults;
|
|
213
216
|
}
|
|
214
|
-
async view(state) {
|
|
217
|
+
async view(state, forceOwnership = false) {
|
|
215
218
|
if (state.creation && !state.agent) {
|
|
216
219
|
const { aid, name, project } = state.creation.plan;
|
|
217
220
|
state.agent = { aid, name, project };
|
|
@@ -242,7 +245,9 @@ export class EcwebInitializationService {
|
|
|
242
245
|
}
|
|
243
246
|
}
|
|
244
247
|
const bindingPending = !!state.binding?.ownerAid && ['pending', 'unknown'].includes(state.binding.status);
|
|
245
|
-
|
|
248
|
+
// Stable display polls can reuse valid consensus; pending binds need a fresh
|
|
249
|
+
// observation, and mutations retain their separate forced authorization.
|
|
250
|
+
const ownership = await this.ownership(state.controlAid, forceOwnership || bindingPending, bindingPending ? 'initialization.binding' : 'initialization.view');
|
|
246
251
|
const ownerAid = this.applyVerifiedOwner(state, ownership);
|
|
247
252
|
const pending = bindingPending || ['requesting', 'submitted'].includes(ownership.requestStatus ?? '')
|
|
248
253
|
|| (ownership.task?.operation === 'bind' && ownership.task.status === 'pending');
|
|
@@ -432,7 +437,7 @@ export class EcwebInitializationService {
|
|
|
432
437
|
return { status: 200, body: { success: true, data: await this.view(state) } };
|
|
433
438
|
}
|
|
434
439
|
if (input.method === 'POST' && (pathname === '/api/init/binding-sessions' || pathname === '/api/init/binding-sessions/refresh')) {
|
|
435
|
-
const data = await this.view(state);
|
|
440
|
+
const data = await this.view(state, true);
|
|
436
441
|
const ownership = data.ownership;
|
|
437
442
|
if (ownership.status === 'bound')
|
|
438
443
|
return { status: 200, body: { success: true, data } };
|
|
@@ -48,6 +48,7 @@ export class InteractionRouter {
|
|
|
48
48
|
const pending = {
|
|
49
49
|
blocking: opts?.blocking !== false,
|
|
50
50
|
retainOnRejected: opts?.retainOnRejected === true,
|
|
51
|
+
requireEncrypted: opts?.requireEncrypted === true,
|
|
51
52
|
callback,
|
|
52
53
|
sessionId,
|
|
53
54
|
initiatorId: opts?.initiatorId,
|
|
@@ -85,6 +86,8 @@ export class InteractionRouter {
|
|
|
85
86
|
const handler = this.handlers.get(response.id);
|
|
86
87
|
if (!handler)
|
|
87
88
|
return false;
|
|
89
|
+
if (handler.requireEncrypted && response.encrypted !== true)
|
|
90
|
+
return false;
|
|
88
91
|
// Initiator 校验(集中式 backstop):非发起者的操作直接丢弃,不消费 handler、不解除等待,
|
|
89
92
|
// 让真正的发起者仍可继续操作。身份只信渠道传入的已认证 operatorId(来自消息信封,非 payload 自报)。
|
|
90
93
|
// 渠道层若已自行校验(如飞书的 reject toast),此处不会重复命中(operatorId 已匹配)。
|