evolcore 0.0.43-test.5 → 0.0.43-test.7
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 +281 -81
- package/dist/agents/baseagent-availability.js +20 -5
- package/dist/agents/baseagent.js +2 -2
- package/dist/agents/claude-runner.js +19 -4
- package/dist/agents/codex/app-server-client.js +36 -3
- package/dist/agents/codex-runner.js +75 -8
- package/dist/aun/group/invite-service.js +3 -2
- package/dist/aun/msg/p2p.js +6 -1
- package/dist/aun/service-proxy.js +18 -6
- package/dist/channels/aun.js +306 -30
- package/dist/cli/agent-create.js +18 -8
- package/dist/cli/aun-commands.js +9 -1
- package/dist/cli/daemon-commands.js +34 -65
- package/dist/cli/daemon-lifecycle-client.js +61 -0
- package/dist/cli/ecmsg-gateway.js +38 -3
- package/dist/cli/events-command.js +73 -0
- package/dist/cli/index.js +31 -14
- package/dist/cli/init.js +75 -0
- package/dist/cli/invoke-command.js +182 -0
- package/dist/cli/managed-command-guard.js +6 -1
- package/dist/cli/provider-command.js +1 -1
- package/dist/cli/restart-monitor.js +67 -50
- package/dist/cli/services-command.js +111 -0
- package/dist/cli/task-context.js +38 -1
- package/dist/cli/team-workspace-command.js +134 -0
- package/dist/cli/thread-command.js +6 -2
- package/dist/cli/watch-logs.js +6 -4
- package/dist/cli/watch-msg.js +1 -1
- package/dist/config/boot-log.js +6 -4
- package/dist/config/builtin-roles.js +2 -2
- package/dist/config/config-field-policy.js +2 -2
- package/dist/config/config-manager.js +1 -8
- package/dist/config/invoke-ipc-service.js +118 -0
- package/dist/config/peer-role-resolver.js +1 -1
- package/dist/config/provider-identity-migration.js +92 -17
- package/dist/config/provider-local-sync.js +2 -0
- package/dist/config/providers-config.js +13 -0
- package/dist/config/providers-management.js +100 -10
- package/dist/config/role-service.js +8 -8
- package/dist/config/role-store.js +22 -22
- package/dist/config/schema-migration.js +86 -88
- package/dist/config/snapshot.js +70 -41
- package/dist/config-store.js +2 -1
- package/dist/core/agent-reload-coordinator.js +6 -4
- package/dist/core/agent-runtime.js +146 -15
- package/dist/core/auth/delegation-authorization.js +66 -0
- package/dist/core/auth/operation-catalog.js +20 -0
- package/dist/core/baseagent-loader.js +75 -42
- package/dist/core/channel-loader.js +45 -13
- package/dist/core/channel-runtime.js +116 -45
- package/dist/core/command/agent-control.js +1 -1
- package/dist/core/command/agent-storage-menu.js +1 -1
- package/dist/core/command/chatmode-config.js +2 -36
- package/dist/core/command/command-handler.js +58 -16
- package/dist/core/command/data-root-resolver.js +32 -23
- package/dist/core/command/eventcenter-menu.js +338 -0
- package/dist/core/command/menu-catalog.js +8 -0
- package/dist/core/command/menu-handler.js +206 -87
- package/dist/core/command/menu-protocol.js +142 -22
- package/dist/core/command/menu-query-batch.js +194 -0
- package/dist/core/command/role-menu.js +27 -15
- 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 +45 -15
- package/dist/core/daemon-lifecycle.js +478 -75
- package/dist/core/handoff/dispatcher.js +9 -3
- package/dist/core/handoff/runtime.js +130 -42
- package/dist/core/handoff/store.js +190 -2
- package/dist/core/handoff/types.js +5 -0
- package/dist/core/initialization/service.js +4 -4
- 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 +51 -11
- package/dist/core/lifecycle-notice.js +10 -4
- package/dist/core/memory/consolidation.js +7 -5
- package/dist/core/message/aun-ipc-sender.js +149 -19
- package/dist/core/message/im-renderer.js +28 -84
- package/dist/core/message/message-bridge.js +57 -4
- package/dist/core/message/message-queue.js +46 -4
- 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 +4 -10
- package/dist/core/message/response-engine.js +163 -52
- package/dist/core/message/send-options.js +7 -4
- package/dist/core/message/send-routing.js +55 -7
- package/dist/core/ownership/owner-resolver.js +8 -0
- package/dist/core/permission/ec-command-parser.js +14 -3
- package/dist/core/permission/protected-paths.js +12 -2
- package/dist/core/permission/shell-environment.js +9 -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-file-health.js +243 -0
- package/dist/core/session/session-fs-store.js +163 -3
- package/dist/core/session/session-idle-monitor.js +9 -1
- package/dist/core/session/session-manager.js +36 -2
- 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/directory/owner-directory-admission.js +42 -30
- package/dist/directory/owner-directory-cache.js +143 -126
- package/dist/directory/owner-directory-query-operation.js +9 -8
- package/dist/eck/kit-renderer.js +7 -5
- package/dist/ecweb/basic-settings-service.js +1 -1
- package/dist/ecweb/message-context-service.js +0 -4
- package/dist/ecweb/runtime/lifecycle.js +14 -8
- package/dist/ecweb/runtime/supervisor.js +62 -30
- package/dist/event-center/admission-materializer.js +114 -0
- package/dist/event-center/bus-gate.js +136 -0
- package/dist/event-center/bus-host.js +290 -0
- package/dist/event-center/bus-resolver.js +120 -0
- package/dist/event-center/center-config.js +100 -0
- package/dist/event-center/client-factory.js +50 -0
- package/dist/event-center/daemon.js +45 -0
- package/dist/event-center/directory-source.js +53 -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 +63 -0
- package/dist/event-center/ipc-operation.js +308 -0
- package/dist/event-center/ledger.js +52 -0
- package/dist/event-center/pack-loader.js +202 -0
- package/dist/event-center/pack-manager.js +85 -0
- package/dist/event-center/registry.js +238 -0
- package/dist/event-center/runtime.js +641 -0
- package/dist/event-center/script-runner.js +356 -0
- package/dist/event-center/types.js +35 -0
- package/dist/event-center/validation.js +413 -0
- package/dist/index.js +751 -268
- package/dist/ipc.js +66 -12
- package/dist/paths.js +20 -0
- package/dist/product.js +14 -0
- package/dist/proxy/manager.js +43 -18
- package/dist/proxy/service-supervisor.js +78 -35
- package/dist/response-system/engines/v1/index.js +0 -1
- 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 +458 -0
- package/dist/services/ledger.js +52 -0
- package/dist/services/message-log.js +112 -0
- package/dist/services/pack-manager.js +204 -0
- package/dist/services/reply.js +55 -0
- package/dist/services/router.js +95 -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 +21 -1
- package/dist/trigger/audit.js +19 -4
- package/dist/trigger/authorization.js +14 -5
- package/dist/trigger/event-source.js +1 -1
- package/dist/trigger/history.js +176 -7
- package/dist/trigger/ipc-service.js +3 -1
- package/dist/trigger/manager.js +1 -3
- package/dist/trigger/scheduler.js +78 -5
- package/dist/trigger/script-sandbox.js +118 -22
- package/dist/utils/cross-platform.js +175 -13
- package/dist/utils/evolcore-version.js +69 -27
- package/dist/utils/host-info.js +11 -8
- package/dist/utils/instance-registry.js +19 -13
- package/dist/utils/npm-ops.js +48 -0
- package/dist/utils/process-introspect.js +109 -10
- package/dist/utils/startup-trace.js +222 -44
- package/dist/utils/windows-shell-trust.js +80 -6
- package/kits/docs/INDEX.md +2 -2
- package/kits/docs/aun/ABILITY_CALLING.md +10 -17
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +5 -2
- package/kits/docs/evolcore/ability.md +4 -0
- package/kits/docs/evolcore/aid.md +1 -1
- package/kits/docs/evolcore/ctl.md +2 -1
- package/kits/docs/evolcore/event-center.md +207 -0
- package/kits/docs/evolcore/file-navigation.md +10 -264
- package/kits/docs/evolcore/fs.md +3 -2
- package/kits/docs/evolcore/group.md +2 -2
- package/kits/docs/evolcore/memory-architecture.md +2 -0
- package/kits/docs/evolcore/menu-exec-schema-commands.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +21 -0
- package/kits/docs/evolcore/msg.md +27 -8
- package/kits/docs/evolcore/provider.md +23 -3
- package/kits/docs/evolcore/response.md +5 -5
- package/kits/docs/evolcore/services.md +277 -0
- package/kits/docs/evolcore/task.md +2 -0
- package/kits/docs/evolcore/team-workspace.md +41 -0
- package/kits/eck_manifest.json +45 -7
- package/kits/eck_message_manifest.json +3 -3
- package/kits/rules/02-navigation.md +10 -1
- package/kits/rules/06-channel.md +5 -6
- 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/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/relation-config.schema.12.json +2 -3
- package/kits/schemas/role-config.schema.2.json +4 -4
- 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/.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 +8 -5
- 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/system-fragments/channel.md +3 -3
- package/kits/templates/system-fragments/commands.md +9 -7
- package/kits/templates/system-fragments/reply.md +2 -6
- package/kits/templates/system-fragments/session.md +1 -1
- package/kits/templates/system-fragments/thread.md +11 -9
- package/package.json +5 -6
- 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
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import fs from 'fs';
|
|
5
5
|
import path from 'path';
|
|
6
6
|
import crypto from 'crypto';
|
|
7
|
-
import { chatDirPath, appendJsonl, readAllJsonlLines,
|
|
7
|
+
import { chatDirPath, appendJsonl, readAllJsonlLines, readAllJsonlLinesAsync, scanAgentChatDirsAsync } from '../session/session-fs-store.js';
|
|
8
8
|
import { logger } from '../../utils/logger.js';
|
|
9
9
|
const PENDING_HINTS_FILE = 'pending-hints.jsonl';
|
|
10
10
|
export const OBSERVER_HINT_FAILURE_MESSAGES = {
|
|
@@ -121,18 +121,12 @@ function deleteFile(fp) {
|
|
|
121
121
|
function claimKey(claim) {
|
|
122
122
|
return targetKey(claim.sessionsDir, claim.channelType, claim.channelId, claim.selfAID, claim.chatType, claim.threadId, claim.channelKey);
|
|
123
123
|
}
|
|
124
|
-
export function pendingInterruptHints(sessionsDir, selfAID) {
|
|
124
|
+
export async function pendingInterruptHints(sessionsDir, selfAID, channelKey) {
|
|
125
125
|
const pending = [];
|
|
126
|
-
for (const chat of
|
|
126
|
+
for (const chat of await scanAgentChatDirsAsync(sessionsDir, selfAID, channelKey)) {
|
|
127
127
|
if (chat.selfAID !== selfAID || chat.channelType !== 'aun' || !chat.channelKey)
|
|
128
128
|
continue;
|
|
129
|
-
|
|
130
|
-
try {
|
|
131
|
-
events = readEvents(path.join(chat.dirPath, PENDING_HINTS_FILE));
|
|
132
|
-
}
|
|
133
|
-
catch {
|
|
134
|
-
continue;
|
|
135
|
-
}
|
|
129
|
+
const events = await readAllJsonlLinesAsync(path.join(chat.dirPath, PENDING_HINTS_FILE));
|
|
136
130
|
const keys = new Set(events.filter(event => event.action === 'add')
|
|
137
131
|
.map(event => `${eventChatType(event)}\u0000${normThread(event.threadId)}`));
|
|
138
132
|
for (const key of keys) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { initializationBlocksTasks } from '../../cli/agent-create.js';
|
|
2
|
-
import { assertOwnershipAuthorization, getDaemonOwners, refreshOwnershipForAuthorization, OWNERSHIP_CACHE_MAX_AGE_MS } from '../ownership/owner-resolver.js';
|
|
2
|
+
import { assertOwnershipAuthorization, getDaemonOwners, refreshOwnershipForAuthorization, resolveContextOwner, OWNERSHIP_CACHE_MAX_AGE_MS } from '../ownership/owner-resolver.js';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import fs from 'fs';
|
|
5
5
|
import os from 'os';
|
|
@@ -12,7 +12,7 @@ import { evaluateInboundAdmissionPreflight, evaluateOrdinaryInboundAdmission } f
|
|
|
12
12
|
import { authorizeAccess, authorizeOperation, buildAuthSubject } from '../auth/auth-gateway.js';
|
|
13
13
|
import { prepareSameOwnerProof, sameOwnerQualification, requiresSameOwnerProof } from '../relation/same-owner-proof.js';
|
|
14
14
|
import { getRoleDefinition } from '../../config/roles.js';
|
|
15
|
-
import { buildTaskRuntimeEnv, ensureRuntimeLockDir,
|
|
15
|
+
import { buildTaskRuntimeEnv, ensureRuntimeLockDir, ensureSessionRuntimeDirAsync } from '../../cli/task-context.js';
|
|
16
16
|
import { BUILTIN_SESSION_PATH_GRANTS, mergeRuntimeGrantsForSession, resolveGrantedReadRoots, } from '../permission/session-path-grants.js';
|
|
17
17
|
import { buildSystemSessionContext, getSystemSessionModule, isSystemSessionType, readSystemSessionMarker } from '../system-session/registry.js';
|
|
18
18
|
import { IMRenderer } from './im-renderer.js';
|
|
@@ -46,9 +46,13 @@ import { buildEnvelope, isInteractionSendAccepted, isNoopText, replyContextFromS
|
|
|
46
46
|
import { chatModeForScene, isSystemOrServicePeer, resolveChatMode } from './peer-mode.js';
|
|
47
47
|
import { AGENT_DELEGATION_TOKEN_ENV } from '../auth/agent-delegation.js';
|
|
48
48
|
import { hasTrustedPrincipal } from '../auth/authenticated-actor.js';
|
|
49
|
-
import { isValidAid } from '../../aun/aid/identity.js';
|
|
50
49
|
// Re-export 工具函数(向后兼容,让其他模块可以从 response-engine 导入)
|
|
51
50
|
export { buildEnvelope, sendInteractionPayload } from './message-utils.js';
|
|
51
|
+
/**
|
|
52
|
+
* 上一次告警过的 owner 来源不一致组合(self:protocol:directory)。
|
|
53
|
+
* 一致性的检查每轮都做,但日志只在组合变化时报一次,避免每个 turn 刷屏。
|
|
54
|
+
*/
|
|
55
|
+
let lastReportedOwnerSourceMismatch;
|
|
52
56
|
import { constrainResolvedModelForRole, isModelAllowedForRoleBaseagent } from '../model/model-permission.js';
|
|
53
57
|
import { eligibleFallbackModels } from '../model/model-fallback.js';
|
|
54
58
|
import { isRecoverableProtocolFailure, RetryScheduler } from './retry-scheduler.js';
|
|
@@ -1294,6 +1298,18 @@ function stripContextLimitErrorLines(text) {
|
|
|
1294
1298
|
.filter(line => !isStandaloneContextLimitErrorLine(line))
|
|
1295
1299
|
.join('\n');
|
|
1296
1300
|
}
|
|
1301
|
+
const GATEWAY_EMPTY_MESSAGE_PLACEHOLDER = '[System: Empty message content sanitised to satisfy protocol]';
|
|
1302
|
+
function isGatewayEmptyMessagePlaceholder(text) {
|
|
1303
|
+
return text.trim() === GATEWAY_EMPTY_MESSAGE_PLACEHOLDER;
|
|
1304
|
+
}
|
|
1305
|
+
export function filterGatewayEmptyMessageEvent(event) {
|
|
1306
|
+
if (event.type === 'text' && isGatewayEmptyMessagePlaceholder(event.text))
|
|
1307
|
+
return undefined;
|
|
1308
|
+
if (event.type === 'complete' && typeof event.result === 'string' && isGatewayEmptyMessagePlaceholder(event.result)) {
|
|
1309
|
+
return { ...event, result: '' };
|
|
1310
|
+
}
|
|
1311
|
+
return event;
|
|
1312
|
+
}
|
|
1297
1313
|
const SHELL_CONTROL_RE = /[;&|`]|[$][(]|\r|\n/;
|
|
1298
1314
|
function isCtlQueueReadCommand(toolName, input) {
|
|
1299
1315
|
if (toolName !== 'Bash' && toolName !== 'Shell')
|
|
@@ -1411,6 +1427,8 @@ export class ResponseEngine {
|
|
|
1411
1427
|
triggerTerminalMessages = new WeakSet();
|
|
1412
1428
|
fullAccessTerminalMessages = new WeakSet();
|
|
1413
1429
|
agentDelegationRegistry;
|
|
1430
|
+
/** 能力清单查询;未注入时两个变量恒为 false(无包 = 无该段)。 */
|
|
1431
|
+
capabilityIndexes;
|
|
1414
1432
|
turnCoordinator;
|
|
1415
1433
|
/** 响应模式协调器(插件化机制中枢)。内置模式在构造时注册。 */
|
|
1416
1434
|
responseCoordinator;
|
|
@@ -1473,6 +1491,31 @@ export class ResponseEngine {
|
|
|
1473
1491
|
}
|
|
1474
1492
|
throw new BaseagentRunnerUnavailableError('<unknown>', requestedBaseagent || '<missing>', []);
|
|
1475
1493
|
}
|
|
1494
|
+
async ensureAgent(channel, baseagent, selfAID) {
|
|
1495
|
+
const aid = channel === 'daemon' && selfAID === this.daemonTriggerOwnerAid
|
|
1496
|
+
? this.primaryRunnerKey.slice(0, this.primaryRunnerKey.lastIndexOf('::'))
|
|
1497
|
+
: selfAID || this.agentRegistry?.resolveByChannel(channel)?.aid;
|
|
1498
|
+
if (aid)
|
|
1499
|
+
await this.runnerReadiness?.(aid, baseagent);
|
|
1500
|
+
return this.getAgent(channel, baseagent, selfAID);
|
|
1501
|
+
}
|
|
1502
|
+
runnerWaiters = new Map();
|
|
1503
|
+
/** An interrupt releases the task even if a shared backend load is still queued. */
|
|
1504
|
+
async ensureSessionAgent(session, channel, selfAID) {
|
|
1505
|
+
const waiters = this.runnerWaiters.get(session.id) ?? new Set();
|
|
1506
|
+
this.runnerWaiters.set(session.id, waiters);
|
|
1507
|
+
let cancel;
|
|
1508
|
+
const interrupted = new Promise(resolve => { cancel = () => resolve(undefined); });
|
|
1509
|
+
waiters.add(cancel);
|
|
1510
|
+
try {
|
|
1511
|
+
return await Promise.race([this.ensureAgent(channel, session.baseagent, selfAID), interrupted]);
|
|
1512
|
+
}
|
|
1513
|
+
finally {
|
|
1514
|
+
waiters.delete(cancel);
|
|
1515
|
+
if (!waiters.size)
|
|
1516
|
+
this.runnerWaiters.delete(session.id);
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1476
1519
|
getTextInferenceProvider(channel, baseagent, selfAID) {
|
|
1477
1520
|
if (!baseagent)
|
|
1478
1521
|
return undefined;
|
|
@@ -1524,7 +1567,6 @@ export class ResponseEngine {
|
|
|
1524
1567
|
? (session.metadata?.groupId || channelId)
|
|
1525
1568
|
: (session.metadata?.peerId || channelId);
|
|
1526
1569
|
const peerKey = channelType && peerKeyId ? formatPeerKey(channelType, peerKeyId) : undefined;
|
|
1527
|
-
const agent = this.agentRegistry?.resolveByChannel(channelKey);
|
|
1528
1570
|
return resolveChatMode({
|
|
1529
1571
|
self: self || undefined,
|
|
1530
1572
|
peerKey,
|
|
@@ -1532,8 +1574,6 @@ export class ResponseEngine {
|
|
|
1532
1574
|
chatType: session.chatType,
|
|
1533
1575
|
peerType,
|
|
1534
1576
|
channelType,
|
|
1535
|
-
lifecycle: agent ? resolveAgentLifecycle(agent.config) : undefined,
|
|
1536
|
-
sessionType: session.sessionType ?? session.metadata?.sessionType ?? 'main',
|
|
1537
1577
|
});
|
|
1538
1578
|
}
|
|
1539
1579
|
catch {
|
|
@@ -1561,7 +1601,7 @@ export class ResponseEngine {
|
|
|
1561
1601
|
this.commandHandler = commandHandler;
|
|
1562
1602
|
this.turnCoordinator = new SessionTurnCoordinator(sessionManager);
|
|
1563
1603
|
sessionManager.setCapsuleTranscriptReader?.(async (session) => {
|
|
1564
|
-
const runner = this.
|
|
1604
|
+
const runner = await this.ensureAgent(session.channel, session.baseagent, session.selfAID);
|
|
1565
1605
|
return await runner.getSessionMessages?.(session.agentSessionId, session.projectPath) ?? [];
|
|
1566
1606
|
});
|
|
1567
1607
|
if (agentRunnerOrMap instanceof Map) {
|
|
@@ -1680,12 +1720,21 @@ export class ResponseEngine {
|
|
|
1680
1720
|
for (const { adapter } of this.channels.values())
|
|
1681
1721
|
this.restoreAsyncQuestions(adapter);
|
|
1682
1722
|
}
|
|
1723
|
+
/**
|
|
1724
|
+
* 注入能力清单查询(ECK 的 hasServicePacks / hasEventPacks)。
|
|
1725
|
+
*
|
|
1726
|
+
* 必须只读内存状态、不做 IO:渲染是热路径(每条入站消息一次),
|
|
1727
|
+
* 扫目录会让延迟不可控。两个运行时在启动/热重载时已把包集合挂在内存里。
|
|
1728
|
+
*/
|
|
1729
|
+
setCapabilityIndexes(provider) {
|
|
1730
|
+
this.capabilityIndexes = provider;
|
|
1731
|
+
}
|
|
1683
1732
|
setMessageQueue(queue) {
|
|
1684
1733
|
this.messageQueue = queue;
|
|
1685
1734
|
this.taskRecoveryService = new TaskRecoveryService({
|
|
1686
1735
|
sessions: this.sessionManager,
|
|
1687
1736
|
queue,
|
|
1688
|
-
getRunner: (session) => this.
|
|
1737
|
+
getRunner: (session) => this.ensureAgent(session.metadata?.channelKey || session.channel, session.baseagent, session.selfAID),
|
|
1689
1738
|
resumePause: (sessionId) => this.resumeSession(sessionId),
|
|
1690
1739
|
hasChannel: (session) => !!this.resolveChannelInfo(session.metadata?.channelKey || session.channel),
|
|
1691
1740
|
});
|
|
@@ -1940,7 +1989,7 @@ export class ResponseEngine {
|
|
|
1940
1989
|
})).allow;
|
|
1941
1990
|
}
|
|
1942
1991
|
async submitAsyncQuestionAnswer(record, session, answer) {
|
|
1943
|
-
const runner = this.
|
|
1992
|
+
const runner = await this.ensureAgent(record.origin.channel, 'codex', record.selfAid);
|
|
1944
1993
|
if (!runner.steerAsyncQuestionAnswer)
|
|
1945
1994
|
throw new Error('Codex async input is unavailable');
|
|
1946
1995
|
if (await runner.steerAsyncQuestionAnswer(session.id, answer) === 'accepted')
|
|
@@ -1986,8 +2035,15 @@ export class ResponseEngine {
|
|
|
1986
2035
|
|| active.interactions.some(item => !item.settlement)
|
|
1987
2036
|
|| this.isPauseRequested(sessionId) || this.retryDelayWaiters.has(sessionId))
|
|
1988
2037
|
return { state: 'live', ...identity };
|
|
1989
|
-
|
|
1990
|
-
|
|
2038
|
+
let runner;
|
|
2039
|
+
try {
|
|
2040
|
+
runner = this.getAgent(session.metadata?.channelKey || session.channel, session.baseagent, selfAid);
|
|
2041
|
+
}
|
|
2042
|
+
catch (error) {
|
|
2043
|
+
if (!(error instanceof BaseagentRunnerUnavailableError))
|
|
2044
|
+
throw error;
|
|
2045
|
+
}
|
|
2046
|
+
const owned = runner?.hasActiveOperation?.(sessionId, active.taskId) ?? runner?.hasActiveStream(sessionId) ?? false;
|
|
1991
2047
|
return { state: owned ? 'live' : 'missing', ...identity,
|
|
1992
2048
|
hasTerminalOwner: this.activeTimeoutHandlers.has(sessionId) };
|
|
1993
2049
|
}
|
|
@@ -2049,9 +2105,18 @@ export class ResponseEngine {
|
|
|
2049
2105
|
this.interruptedSessions.set(sessionId, effectiveReason);
|
|
2050
2106
|
this.messageQueue?.markActiveTerminal?.(sessionId, effectiveReason);
|
|
2051
2107
|
const channelKey = session.metadata?.channelKey || session.channel;
|
|
2052
|
-
|
|
2108
|
+
// An interrupted task may still be waiting for on-demand initialization.
|
|
2109
|
+
// Commit its terminal state without starting a backend just to stop it.
|
|
2110
|
+
let agent;
|
|
2111
|
+
try {
|
|
2112
|
+
agent = this.getAgent(channelKey, session.baseagent, session.selfAID);
|
|
2113
|
+
}
|
|
2114
|
+
catch (error) {
|
|
2115
|
+
if (!(error instanceof BaseagentRunnerUnavailableError))
|
|
2116
|
+
throw error;
|
|
2117
|
+
}
|
|
2053
2118
|
const cancelledQueuedTurn = interruptedTurn?.active
|
|
2054
|
-
? agent
|
|
2119
|
+
? agent?.cancelQueuedTurn?.(sessionId, {
|
|
2055
2120
|
taskId: interruptedTurn.active.taskId,
|
|
2056
2121
|
generation: interruptedTurn.active.generation,
|
|
2057
2122
|
}) ?? false
|
|
@@ -2063,6 +2128,9 @@ export class ResponseEngine {
|
|
|
2063
2128
|
const taskId = (await this.turnCoordinator.completeInterrupt(session, effectiveReason, recoverable))
|
|
2064
2129
|
?? interruptedTaskId
|
|
2065
2130
|
?? taskSpan?.taskId;
|
|
2131
|
+
// Release first-use waits only after the interrupt is durable.
|
|
2132
|
+
for (const cancel of this.runnerWaiters?.get(sessionId) ?? [])
|
|
2133
|
+
cancel();
|
|
2066
2134
|
if (taskId) {
|
|
2067
2135
|
const taskCausation = taskSpan?.causation ?? runtimeContext?.causation;
|
|
2068
2136
|
if (taskCausation && effectiveReason === 'daemon_restart') {
|
|
@@ -2100,7 +2168,7 @@ export class ResponseEngine {
|
|
|
2100
2168
|
sessionId: session.id,
|
|
2101
2169
|
channel: channelInfo.adapter.channelName,
|
|
2102
2170
|
channelId: session.channelId,
|
|
2103
|
-
agentName: agent.
|
|
2171
|
+
agentName: agent?.name ?? session.baseagent,
|
|
2104
2172
|
chatmode: this.resolveEffectiveChatmodeForSession(session, channelKey, session.channelId),
|
|
2105
2173
|
replyContext: {
|
|
2106
2174
|
...replyContextFromSession(session),
|
|
@@ -2118,7 +2186,7 @@ export class ResponseEngine {
|
|
|
2118
2186
|
})();
|
|
2119
2187
|
const runnerInterrupt = (cancelledQueuedTurn || !interruptTarget
|
|
2120
2188
|
? Promise.resolve()
|
|
2121
|
-
: agent
|
|
2189
|
+
: agent?.interrupt(sessionId, interruptTarget) ?? Promise.resolve()).catch(error => {
|
|
2122
2190
|
logger.debug(`[ResponseEngine] interrupt barrier runner failure: session=${sessionId} error=${error instanceof Error ? error.message : String(error)}`);
|
|
2123
2191
|
if (strict)
|
|
2124
2192
|
throw error;
|
|
@@ -2156,6 +2224,10 @@ export class ResponseEngine {
|
|
|
2156
2224
|
setHandoffRuntime(runtime) {
|
|
2157
2225
|
this.handoffRuntime = runtime;
|
|
2158
2226
|
}
|
|
2227
|
+
runnerReadiness;
|
|
2228
|
+
setRunnerReadiness(wait) {
|
|
2229
|
+
this.runnerReadiness = wait;
|
|
2230
|
+
}
|
|
2159
2231
|
getTaskRuntimeContext(sessionId) {
|
|
2160
2232
|
return this.activeTaskRuntimeContexts.get(sessionId) ?? null;
|
|
2161
2233
|
}
|
|
@@ -3161,7 +3233,12 @@ export class ResponseEngine {
|
|
|
3161
3233
|
const runnerSelfAid = this.agentRegistry?.resolveByChannel(channelKey)?.aid
|
|
3162
3234
|
|| session.selfAID
|
|
3163
3235
|
|| message.selfAID;
|
|
3164
|
-
|
|
3236
|
+
const loaded = await this.ensureSessionAgent(session, channelKey, runnerSelfAid);
|
|
3237
|
+
if (!loaded) {
|
|
3238
|
+
this.publishTriggerExecutionSkipped(message, 'interrupted_before_runner_ready');
|
|
3239
|
+
return;
|
|
3240
|
+
}
|
|
3241
|
+
agent = loaded;
|
|
3165
3242
|
}
|
|
3166
3243
|
catch (error) {
|
|
3167
3244
|
if (error instanceof BaseagentRunnerUnavailableError) {
|
|
@@ -3564,7 +3641,12 @@ export class ResponseEngine {
|
|
|
3564
3641
|
let agent;
|
|
3565
3642
|
let turnLease;
|
|
3566
3643
|
try {
|
|
3567
|
-
|
|
3644
|
+
const loaded = await this.ensureSessionAgent(session, channelKey, runnerSelfAid);
|
|
3645
|
+
if (!loaded) {
|
|
3646
|
+
this.publishTriggerExecutionSkipped(message, 'interrupted_before_runner_ready');
|
|
3647
|
+
return;
|
|
3648
|
+
}
|
|
3649
|
+
agent = loaded;
|
|
3568
3650
|
}
|
|
3569
3651
|
catch (error) {
|
|
3570
3652
|
if (error instanceof BaseagentRunnerUnavailableError) {
|
|
@@ -3740,13 +3822,6 @@ export class ResponseEngine {
|
|
|
3740
3822
|
// trigger override 绝对优先;否则由 Coordinator 解析(responseMode 标量 > 注册表首选)。
|
|
3741
3823
|
const systemOrServicePeer = isSystemOrServicePeer(peerType);
|
|
3742
3824
|
const triggerChatModeOverride = systemOrServicePeer ? undefined : message.triggerMeta?.chatModeOverride;
|
|
3743
|
-
const previousTurn = this.turnCoordinator.current(session);
|
|
3744
|
-
const recoveryChatMode = (message.taskRecovery || message.restartResume?.submitted)
|
|
3745
|
-
? (previousTurn.active ?? previousTurn.lastTerminal)?.recoveryContext?.chatmode
|
|
3746
|
-
: undefined;
|
|
3747
|
-
// Preserve PA's explicit-reply contract across recovery. The existing
|
|
3748
|
-
// interactive/proactive recovery and override rules remain authoritative.
|
|
3749
|
-
const taskChatModeOverride = recoveryChatMode === 'paactive' ? recoveryChatMode : triggerChatModeOverride;
|
|
3750
3825
|
// chatmode 是顶层字典(agent 级与关系级同名,已由 ConfigManager 逐键合并)。
|
|
3751
3826
|
// 实际生效值由对端类型选键(private/nothuman/group),出厂默认走 schema。
|
|
3752
3827
|
const chatModeFallback = resolveChatMode({
|
|
@@ -3756,8 +3831,6 @@ export class ResponseEngine {
|
|
|
3756
3831
|
chatType,
|
|
3757
3832
|
peerType,
|
|
3758
3833
|
channelType: currentChannelType,
|
|
3759
|
-
lifecycle,
|
|
3760
|
-
sessionType: session.sessionType ?? session.metadata?.sessionType ?? 'main',
|
|
3761
3834
|
});
|
|
3762
3835
|
// Resolve overrides before binding a flow so hooks, context and envelope
|
|
3763
3836
|
// all use the same scene-checked mode for this task.
|
|
@@ -3765,13 +3838,13 @@ export class ResponseEngine {
|
|
|
3765
3838
|
? 'proactive'
|
|
3766
3839
|
: systemOrServicePeer
|
|
3767
3840
|
? 'interactive'
|
|
3768
|
-
:
|
|
3769
|
-
? chatModeForScene(
|
|
3841
|
+
: triggerChatModeOverride
|
|
3842
|
+
? chatModeForScene(triggerChatModeOverride, { channelType: currentChannelType, chatType, peerType, role: peerRole })
|
|
3770
3843
|
: chatModeFallback;
|
|
3771
3844
|
const responseModeAgentDir = selfAid ? resolveAgentDir(selfAid) : undefined;
|
|
3772
3845
|
// mentionMode:顶层通用参数(先读出备用,投递/入队策略后续接入)
|
|
3773
3846
|
const mentionMode = effectiveAgentConfig?.mentionMode ?? 'disabled';
|
|
3774
|
-
const resolvedMode =
|
|
3847
|
+
const resolvedMode = triggerChatModeOverride
|
|
3775
3848
|
|| systemOrServicePeer || !responseModeAgentDir
|
|
3776
3849
|
? null
|
|
3777
3850
|
: this.responseCoordinator.resolveMode(effectiveAgentConfig?.responseMode, // 标量:关系级>agent级>注册表首选
|
|
@@ -3806,6 +3879,24 @@ export class ResponseEngine {
|
|
|
3806
3879
|
// chatMode 由 resolveChatModeForPeer 按配置层级解析(步骤 1/4)。
|
|
3807
3880
|
const chatmode = effectiveChatMode;
|
|
3808
3881
|
const isProactive = effectiveChatMode === 'proactive';
|
|
3882
|
+
// Use the same PA identity fact for transport and ECK. Snapshot once per
|
|
3883
|
+
// task so an identity refresh cannot switch protocols halfway through it.
|
|
3884
|
+
const directoryIdentity = selfAid
|
|
3885
|
+
? readOwnerDirectoryIdentity(path.join(resolveRoot(), 'agents', selfAid, 'directory'))
|
|
3886
|
+
: EMPTY_IDENTITY;
|
|
3887
|
+
const contextOwner = resolveContextOwner(selfAid, directoryIdentity.owner?.aid);
|
|
3888
|
+
const activityTransport = isProactive
|
|
3889
|
+
&& currentChannelType === 'aun'
|
|
3890
|
+
&& chatType === 'private'
|
|
3891
|
+
&& peerType === 'human'
|
|
3892
|
+
&& peerRole === 'owner'
|
|
3893
|
+
&& lifecycle === 'active'
|
|
3894
|
+
&& (session.sessionType ?? session.metadata?.sessionType ?? 'main') === 'main'
|
|
3895
|
+
&& directoryIdentity.personalAssistant?.aid === selfAid
|
|
3896
|
+
&& !!contextOwner.ownerAid
|
|
3897
|
+
&& contextOwner.ownerAid === message.channelId
|
|
3898
|
+
&& directoryIdentity.owner?.aid === contextOwner.ownerAid
|
|
3899
|
+
? 'message' : undefined;
|
|
3809
3900
|
const legacyMiddleOutputMode = () => {
|
|
3810
3901
|
const mode = policy.middleOutputMode?.(chatType, identityRole, peerType);
|
|
3811
3902
|
if (isShowActivitiesMode(mode))
|
|
@@ -3902,6 +3993,7 @@ export class ResponseEngine {
|
|
|
3902
3993
|
channelId: message.channelId,
|
|
3903
3994
|
agentName: agentNameForStats,
|
|
3904
3995
|
chatmode: effectiveChatMode,
|
|
3996
|
+
activityTransport,
|
|
3905
3997
|
replyContext: taskReplyContext(),
|
|
3906
3998
|
causation: taskCausation,
|
|
3907
3999
|
});
|
|
@@ -4236,7 +4328,6 @@ export class ResponseEngine {
|
|
|
4236
4328
|
? aunMessageTranscriptUuid(sourceMessageId)
|
|
4237
4329
|
: undefined;
|
|
4238
4330
|
turnLease = await this.turnCoordinator.begin(session, taskId, inputId, configActorId ? {
|
|
4239
|
-
...(effectiveChatMode === 'paactive' ? { chatmode: effectiveChatMode } : {}),
|
|
4240
4331
|
peerId: configActorId,
|
|
4241
4332
|
approvalInteractionPolicy,
|
|
4242
4333
|
encrypted: message.encrypted ?? message.replyContext?.metadata?.encrypted,
|
|
@@ -4528,7 +4619,7 @@ export class ResponseEngine {
|
|
|
4528
4619
|
// Allocate the stable session-owned root before any runner preflight
|
|
4529
4620
|
// context is installed. Every runner for this EvolCore session receives
|
|
4530
4621
|
// the same directory, independent of daemon or runner lifetimes.
|
|
4531
|
-
const sessionRuntimeDir =
|
|
4622
|
+
const sessionRuntimeDir = await ensureSessionRuntimeDirAsync(session.id);
|
|
4532
4623
|
const recordExecutionAnomaly = triggerRunId
|
|
4533
4624
|
? (anomaly) => {
|
|
4534
4625
|
recordTriggerExecutionAnomaly(triggerRunId, {
|
|
@@ -5283,14 +5374,21 @@ export class ResponseEngine {
|
|
|
5283
5374
|
const memoryMode = session.metadata?.memoryMode;
|
|
5284
5375
|
// Kit renderer: 组装上下文
|
|
5285
5376
|
const pkgRoot = getPackageRoot();
|
|
5286
|
-
// 名录身份(Owner / 个人助理)来自渲染产物旁的小文件,只读一次、只取四个字段:
|
|
5287
|
-
// 每轮都要算,不能去解析 contacts.json。读不出时是空身份,下面的 isPersonalAssistant
|
|
5288
|
-
// / isOwner 随之双双为 false——宁可不注入 PA 段,也不能让非 PA 拿到 PA 的行为约束。
|
|
5289
|
-
const directoryIdentity = selfAid
|
|
5290
|
-
? readOwnerDirectoryIdentity(path.join(resolveRoot(), 'agents', selfAid, 'directory'))
|
|
5291
|
-
: EMPTY_IDENTITY;
|
|
5292
5377
|
const personalAssistantAid = directoryIdentity.personalAssistant?.aid;
|
|
5293
5378
|
const identityOwnerAid = directoryIdentity.owner?.aid;
|
|
5379
|
+
// Owner 只有一个来源:归属协议共识,与记忆写入/整理(ipc.ts 的 memory.create /
|
|
5380
|
+
// memory.consolidate)走同一个解析。名录快照里的 owner 是网络缓存,可能滞后于
|
|
5381
|
+
// 协议绑定变更;若拿它拼 owner-memory 路径,就会写进一处、读的时候去另一处找。
|
|
5382
|
+
// 快照身份在这里只与协议 owner 交叉核对,不一致时按组合变化告警一次。
|
|
5383
|
+
const protocolOwnerAid = contextOwner.ownerAid;
|
|
5384
|
+
if (contextOwner.mismatch) {
|
|
5385
|
+
const mismatchKey = `${selfAid}:${contextOwner.mismatch.protocolOwnerAid}:${contextOwner.mismatch.directoryOwnerAid}`;
|
|
5386
|
+
if (mismatchKey !== lastReportedOwnerSourceMismatch) {
|
|
5387
|
+
lastReportedOwnerSourceMismatch = mismatchKey;
|
|
5388
|
+
logger.warn(`[ResponseEngine] owner 来源不一致 self=${selfAid} protocol=${contextOwner.mismatch.protocolOwnerAid} directory=${contextOwner.mismatch.directoryOwnerAid};`
|
|
5389
|
+
+ '上下文注入与记忆写入一律按归属协议取 owner,请检查名录快照是否过期');
|
|
5390
|
+
}
|
|
5391
|
+
}
|
|
5294
5392
|
const kitCtx = {
|
|
5295
5393
|
vars: {
|
|
5296
5394
|
EVOLCORE_HOME: resolveRoot(),
|
|
@@ -5318,22 +5416,18 @@ export class ResponseEngine {
|
|
|
5318
5416
|
RELATIONS_DIR: selfAid ? path.join(resolveRoot(), 'agents', selfAid, 'relations') : undefined,
|
|
5319
5417
|
VENUES_DIR: selfAid ? path.join(resolveRoot(), 'agents', selfAid, 'venues') : undefined,
|
|
5320
5418
|
selfAid: selfAid || undefined,
|
|
5321
|
-
//
|
|
5322
|
-
//
|
|
5323
|
-
ownerAid:
|
|
5324
|
-
|
|
5325
|
-
|
|
5326
|
-
|
|
5327
|
-
if (!raw)
|
|
5328
|
-
return undefined;
|
|
5329
|
-
return isValidAid(raw) ? raw : undefined;
|
|
5330
|
-
})(),
|
|
5331
|
-
ownerName: directoryIdentity.owner?.name || undefined,
|
|
5419
|
+
// 与记忆写入/整理同源:owner-memory 段注入的路径必须和写入落盘的路径一致。
|
|
5420
|
+
// 名录快照不再是 owner 的来源,只在确认是同一个人时提供展示用名字。
|
|
5421
|
+
ownerAid: protocolOwnerAid,
|
|
5422
|
+
ownerName: protocolOwnerAid && protocolOwnerAid === identityOwnerAid
|
|
5423
|
+
? directoryIdentity.owner?.name || undefined
|
|
5424
|
+
: undefined,
|
|
5332
5425
|
personalAssistantAid,
|
|
5333
5426
|
personalAssistantName: directoryIdentity.personalAssistant?.name || undefined,
|
|
5334
5427
|
// 两个角色布尔**即时比较**,不从文件读:落盘的布尔会过期,也挡不住手改文件伪造。
|
|
5428
|
+
// isOwner 与 ownerAid 同源(归属协议),避免名录快照滞后时把自封 Owner 的角色注入进去。
|
|
5335
5429
|
isPersonalAssistant: !!personalAssistantAid && personalAssistantAid === selfAid,
|
|
5336
|
-
isOwner: !!
|
|
5430
|
+
isOwner: !!protocolOwnerAid && protocolOwnerAid === selfAid,
|
|
5337
5431
|
// 准入现状压成一句话:只列能联系谁,说不通的档位直接不提。
|
|
5338
5432
|
// 只说"能",不说"谁关的"——默认关与显式关在结果上没区别。
|
|
5339
5433
|
...(() => {
|
|
@@ -5364,6 +5458,17 @@ export class ResponseEngine {
|
|
|
5364
5458
|
lifecycle,
|
|
5365
5459
|
isBootstrapping,
|
|
5366
5460
|
hasPersona: !!persona,
|
|
5461
|
+
// 能力清单:没有包时恒 false,manifest 对应 section 整段不注入。
|
|
5462
|
+
...(() => {
|
|
5463
|
+
if (!selfAid || !this.capabilityIndexes)
|
|
5464
|
+
return { hasServicePacks: false, hasEventPacks: false };
|
|
5465
|
+
try {
|
|
5466
|
+
return this.capabilityIndexes(selfAid);
|
|
5467
|
+
}
|
|
5468
|
+
catch {
|
|
5469
|
+
return { hasServicePacks: false, hasEventPacks: false };
|
|
5470
|
+
}
|
|
5471
|
+
})(),
|
|
5367
5472
|
peerId: peerIdRaw || undefined,
|
|
5368
5473
|
// 与任务上下文同源:系统会话取目标关系,否则 peer-profile / relation 索引会按 bg: 伪对端注入
|
|
5369
5474
|
peerKey: systemSessionContext?.peerKey ?? peerKey,
|
|
@@ -5412,7 +5517,7 @@ export class ResponseEngine {
|
|
|
5412
5517
|
sessionKey: session.sessionKey,
|
|
5413
5518
|
chatMode: effectiveChatMode,
|
|
5414
5519
|
// Message templates receive the same derived reply fact as system templates.
|
|
5415
|
-
activePush:
|
|
5520
|
+
activePush: isProactive,
|
|
5416
5521
|
isTriggerTask: causationPath.length > 0 || message.source === 'trigger',
|
|
5417
5522
|
readonly: effectivePermissionMode === 'readonly',
|
|
5418
5523
|
baseAgent: normalizedBaseagent.canonical,
|
|
@@ -5428,7 +5533,7 @@ export class ResponseEngine {
|
|
|
5428
5533
|
},
|
|
5429
5534
|
sessionId: session.id,
|
|
5430
5535
|
};
|
|
5431
|
-
if (
|
|
5536
|
+
if (isProactive) {
|
|
5432
5537
|
Object.assign(kitCtx.vars, {
|
|
5433
5538
|
// Proactive policy variables are scoped to proactive tasks only.
|
|
5434
5539
|
proactivePreTool1stMsgChk: proactive?.preTool1stMsgChk ?? false,
|
|
@@ -7160,7 +7265,9 @@ export class ResponseEngine {
|
|
|
7160
7265
|
await adapter.send(withEnvelopeReplyContext(envelope, sendOpts), errorPayload);
|
|
7161
7266
|
}
|
|
7162
7267
|
// Proactive 可观测:catch 块的基础设施错误也透传为 thought,保证按 task_id 聚合完整
|
|
7163
|
-
if (isProactive
|
|
7268
|
+
if (isProactive
|
|
7269
|
+
&& adapter.capabilities?.thought
|
|
7270
|
+
&& middleOutputMode === 'all') {
|
|
7164
7271
|
await adapter.send(withEnvelopeReplyContext(envelope, sendOpts), {
|
|
7165
7272
|
kind: 'activity.batch',
|
|
7166
7273
|
items: [{
|
|
@@ -7639,6 +7746,10 @@ export class ResponseEngine {
|
|
|
7639
7746
|
if (event.type === 'complete') {
|
|
7640
7747
|
event = normalizeCompleteAgentEvent(event);
|
|
7641
7748
|
}
|
|
7749
|
+
const filteredEvent = filterGatewayEmptyMessageEvent(event);
|
|
7750
|
+
if (!filteredEvent)
|
|
7751
|
+
continue;
|
|
7752
|
+
event = filteredEvent;
|
|
7642
7753
|
if (event.type === 'tool_result' && isToolResultFailure(event)) {
|
|
7643
7754
|
const classification = normalizeToolErrorClassification(event);
|
|
7644
7755
|
event = {
|
|
@@ -29,10 +29,13 @@ export const GATEWAY_ROUTE_VALUE_FLAGS = [
|
|
|
29
29
|
];
|
|
30
30
|
/** 只有网关认识、`ec msg send` 不认识的选项。 */
|
|
31
31
|
export const GATEWAY_ONLY_VALUE_FLAGS = ['--to', '--from'];
|
|
32
|
-
/**
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
/**
|
|
33
|
+
* 网关的别名映射。
|
|
34
|
+
*
|
|
35
|
+
* 曾把 `--self` 映射到 `--from`。现在 `ecmsg send` 只用 `--from` 表达本端,
|
|
36
|
+
* 不再接受 `--self`(其它命令的 `--self` 不过这个网关,不受影响)。
|
|
37
|
+
*/
|
|
38
|
+
export const GATEWAY_FLAG_ALIASES = {};
|
|
36
39
|
/** 下游允许的选项总数,用于漂移自检。 */
|
|
37
40
|
export const MANAGED_SEND_KNOWN_FLAGS = [
|
|
38
41
|
...MANAGED_SEND_VALUE_FLAGS,
|
|
@@ -108,7 +108,10 @@ function resolveThreadOption(raw, self, deps) {
|
|
|
108
108
|
return fail('IDENTITY_MISMATCH', `主话题 ${value} 不属于当前本端 ${self}——主话题 id 由本端与对端共同构成`);
|
|
109
109
|
}
|
|
110
110
|
const threadId = canonicalizeMainTopicId(value) ?? value;
|
|
111
|
-
|
|
111
|
+
// 主话题 id 里只有两个 AID,没有类型信息:群的主话题同样写成 main:<self>:<群AID>。
|
|
112
|
+
// 类型由调用方按关系证据注入;没有注入时才按私聊,保持旧行为。
|
|
113
|
+
const peerKind = deps.resolvePeerKind?.(peerId) ?? 'private';
|
|
114
|
+
return { peer: { channelType: 'aun', peerKind, id: peerId }, threadId };
|
|
112
115
|
}
|
|
113
116
|
if (isThreadTopicId(value)) {
|
|
114
117
|
const info = deps.resolveThread?.(value);
|
|
@@ -159,6 +162,7 @@ export function resolveSendRoute(input, session, deps = {}) {
|
|
|
159
162
|
let peer;
|
|
160
163
|
let threadId;
|
|
161
164
|
let source;
|
|
165
|
+
let firstContact = false;
|
|
162
166
|
if (input.thread !== undefined) {
|
|
163
167
|
const resolved = resolveThreadOption(input.thread, self, deps);
|
|
164
168
|
if ('ok' in resolved)
|
|
@@ -172,6 +176,11 @@ export function resolveSendRoute(input, session, deps = {}) {
|
|
|
172
176
|
if (!targetId) {
|
|
173
177
|
return fail('INVALID_ARGUMENT', '--to 不能为空', '省略 --to 表示发给当前会话对端');
|
|
174
178
|
}
|
|
179
|
+
// `--to <本端AID>` 只在给出 `--thread` 时有意义:话题是投递落点的唯一依据。
|
|
180
|
+
// 不带话题时它会走下面「跨对端」的分支,拼出 `main:<self>:<self>` 这种自反主话题。
|
|
181
|
+
if (normalizeTopicAid(targetId).toLowerCase() === self.toLowerCase()) {
|
|
182
|
+
return fail('INVALID_ARGUMENT', '--to 是本端自己时必须同时指定 --thread(话题决定投递落点)', `投给自己请写:--thread <话题id> --to ${self}`);
|
|
183
|
+
}
|
|
175
184
|
const resolvedPeer = deps.resolveTarget?.(targetId) ?? {
|
|
176
185
|
channelType: session.channelType,
|
|
177
186
|
peerKind: session.chatType,
|
|
@@ -193,6 +202,11 @@ export function resolveSendRoute(input, session, deps = {}) {
|
|
|
193
202
|
}
|
|
194
203
|
threadId = derived;
|
|
195
204
|
source = { peer: 'to', thread: 'derived' };
|
|
205
|
+
// 还没有主会话 = 首次联系:话题还没被创建,不能要求它存在。
|
|
206
|
+
// 交给投递侧按普通私聊发出,会话随首条消息建立。
|
|
207
|
+
firstContact = deps.mainSessionExists !== undefined
|
|
208
|
+
&& peer.peerKind === 'private'
|
|
209
|
+
&& !deps.mainSessionExists(peer);
|
|
196
210
|
}
|
|
197
211
|
}
|
|
198
212
|
else {
|
|
@@ -200,7 +214,8 @@ export function resolveSendRoute(input, session, deps = {}) {
|
|
|
200
214
|
threadId = currentThread;
|
|
201
215
|
source = { peer: 'session', thread: 'session' };
|
|
202
216
|
}
|
|
203
|
-
// 3. --thread 与 --to
|
|
217
|
+
// 3. --thread 与 --to 同时给出:对端一致 → peer;本端自己 → self;其它 → 冲突
|
|
218
|
+
let recipient = 'peer';
|
|
204
219
|
if (input.thread !== undefined && input.to !== undefined) {
|
|
205
220
|
const targetId = String(input.to ?? '').trim();
|
|
206
221
|
const explicitPeer = deps.resolveTarget?.(targetId) ?? {
|
|
@@ -208,17 +223,30 @@ export function resolveSendRoute(input, session, deps = {}) {
|
|
|
208
223
|
peerKind: session.chatType,
|
|
209
224
|
id: targetId,
|
|
210
225
|
};
|
|
211
|
-
if (
|
|
212
|
-
|
|
226
|
+
if (sameRoutePeer(explicitPeer, peer, deps)) {
|
|
227
|
+
recipient = 'peer';
|
|
228
|
+
}
|
|
229
|
+
else if (normalizeTopicAid(targetId).toLowerCase() === self.toLowerCase()) {
|
|
230
|
+
// 话题内投给自己:话题仍属于 (self, peer),只是收件人是本端。
|
|
231
|
+
recipient = 'self';
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
return fail('TOPIC_CONFLICT', `--thread 指向 ${peer.id},--to 指向 ${explicitPeer.id},两者冲突`, '--to 只能是话题对端或本端自己;一次发送只能有一个目标');
|
|
213
235
|
}
|
|
214
236
|
}
|
|
237
|
+
// 自发只适用于私聊话题:群投递的位置参数恒为群 AID,`--to 本端` 会被当成
|
|
238
|
+
// 发群消息,收件人与回执对不上,还会把本应给自己的内容发进群。
|
|
239
|
+
if (recipient === 'self' && peer.peerKind === 'group') {
|
|
240
|
+
return fail('INVALID_ARGUMENT', '群话题不支持发给自己', '群消息的收件人恒为群;自发只用于私聊话题(--thread <私聊话题> --to <本端AID>)');
|
|
241
|
+
}
|
|
242
|
+
const recipientId = recipient === 'self' ? self : peer.id;
|
|
215
243
|
// 4. 跨话题判定
|
|
216
244
|
const crossTopic = !sameRoutePeer(peer, currentPeer, deps) || threadId !== currentThread;
|
|
217
245
|
// 5. 复查周期
|
|
218
246
|
let checkEveryMs;
|
|
219
247
|
let checkEveryDefaulted = false;
|
|
220
248
|
let checkEveryIgnored = false;
|
|
221
|
-
if (crossTopic) {
|
|
249
|
+
if (crossTopic && !firstContact) {
|
|
222
250
|
if (input.checkEvery === undefined) {
|
|
223
251
|
checkEveryMs = DEFAULT_CROSS_TOPIC_CHECK_EVERY_MS;
|
|
224
252
|
checkEveryDefaulted = true;
|
|
@@ -251,15 +279,28 @@ export function resolveSendRoute(input, session, deps = {}) {
|
|
|
251
279
|
if (peer.channelType !== 'aun' && encrypt === 'yes') {
|
|
252
280
|
return fail('ENCRYPT_UNSUPPORTED', `目标对端 ${peer.id} 不在 AUN 网络上(channel=${peer.channelType}),无法端到端加密`, '去掉 --encrypt 或改用 --encrypt no');
|
|
253
281
|
}
|
|
282
|
+
// auto 的取值:
|
|
283
|
+
// - 自发(recipient='self'):跟随话题 T 上一条消息的加密态(D4)。自发不是
|
|
284
|
+
// 被对端触发的,`inboundEncrypted` 描述的是当前会话而非话题 T,不能拿来用。
|
|
285
|
+
// - 其余:本轮被入站消息触发就沿用该消息,否则明文。
|
|
286
|
+
let lastTopicEncrypted;
|
|
287
|
+
if (recipient === 'self' && encrypt === 'auto') {
|
|
288
|
+
lastTopicEncrypted = deps.resolveLastTopicEncrypt?.(threadId);
|
|
289
|
+
}
|
|
254
290
|
const encryptResolved = encrypt === 'auto' && peer.channelType === 'aun'
|
|
255
|
-
?
|
|
291
|
+
? recipient === 'self'
|
|
292
|
+
? lastTopicEncrypted === true
|
|
293
|
+
: (input.inboundTriggered === true ? input.inboundEncrypted === true : false)
|
|
256
294
|
: encrypt === 'yes';
|
|
257
295
|
return {
|
|
258
296
|
ok: true,
|
|
259
297
|
self,
|
|
260
298
|
peer,
|
|
299
|
+
recipient,
|
|
300
|
+
recipientId,
|
|
261
301
|
threadId,
|
|
262
302
|
crossTopic,
|
|
303
|
+
firstContact,
|
|
263
304
|
...(checkEveryMs !== undefined ? { checkEveryMs } : {}),
|
|
264
305
|
checkEveryDefaulted,
|
|
265
306
|
checkEveryIgnored,
|
|
@@ -298,13 +339,20 @@ function sourceLabel(source, field) {
|
|
|
298
339
|
*
|
|
299
340
|
* 格式:`from=<self> to=<id>(<来源>) thread=<threadId>(<来源>) chatType=<kind>`
|
|
300
341
|
* 推断补全的值标来源,全部为归一化后的实际生效值,不是输入原文。
|
|
342
|
+
*
|
|
343
|
+
* 自发(`recipient === 'self'`)时 `to` 回显本端 AID 并附 `recipient=self`,
|
|
344
|
+
* 让调用方一眼看出这不是发给对端的。话题仍按对端所属话题回显。
|
|
301
345
|
*/
|
|
302
346
|
export function formatRouteReceipt(route) {
|
|
303
347
|
const threadLabel = route.threadId ? route.threadId : 'main';
|
|
348
|
+
const target = route.recipient === 'self'
|
|
349
|
+
? `to=${route.recipientId}(自发)`
|
|
350
|
+
: `to=${route.peer.id}(${sourceLabel(route.source, 'peer')})`;
|
|
304
351
|
return [
|
|
305
352
|
`from=${route.self}`,
|
|
306
|
-
|
|
353
|
+
target,
|
|
307
354
|
`thread=${threadLabel}(${sourceLabel(route.source, 'thread')})`,
|
|
308
355
|
`chatType=${route.peer.peerKind}`,
|
|
356
|
+
...(route.recipient === 'self' ? ['recipient=self'] : []),
|
|
309
357
|
].join(' ');
|
|
310
358
|
}
|