evolcore 0.0.43-test.1 → 0.0.43-test.3
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 +31 -1
- package/README.md +22 -0
- package/dist/agents/claude-runner.js +26 -2
- package/dist/agents/codex/app-server-client.js +12 -0
- package/dist/agents/codex-runner.js +49 -8
- package/dist/agents/ecagent-runner.js +39 -15
- package/dist/agents/gemini-runner.js +15 -12
- package/dist/agents/tool-time-context.js +55 -0
- package/dist/aun/aid/agentmd.js +21 -1
- package/dist/aun/menu/client.js +1 -1
- package/dist/aun/model-headers.js +17 -0
- package/dist/aun/msg/p2p.js +7 -2
- package/dist/channels/aun.js +522 -50
- package/dist/channels/builtin-plugins.js +16 -11
- package/dist/channels/daemon.js +4 -0
- package/dist/channels/dingtalk.js +83 -31
- package/dist/channels/feishu.js +29 -13
- package/dist/channels/qqbot.js +32 -11
- package/dist/channels/wechat.js +13 -3
- package/dist/channels/wecom.js +67 -27
- package/dist/cli/agent-command.js +3 -86
- package/dist/cli/agent-create.js +20 -6
- package/dist/cli/agent.js +1 -79
- package/dist/cli/aun-commands.js +18 -19
- package/dist/cli/config.js +1 -1
- package/dist/cli/daemon-commands.js +47 -2
- package/dist/cli/data-command.js +9 -1
- package/dist/cli/debug-mode.js +1 -1
- package/dist/cli/diag.js +1 -1
- package/dist/cli/directory.js +149 -91
- package/dist/cli/getmeta-command.js +1 -1
- package/dist/cli/index.js +79 -22
- package/dist/cli/init.js +1 -23
- package/dist/cli/link-rules.js +1 -1
- package/dist/cli/managed-command-guard.js +0 -1
- package/dist/cli/pa-workspace-command.js +36 -2
- package/dist/cli/peer.js +3 -2
- package/dist/cli/restart-monitor.js +17 -3
- package/dist/cli/role.js +1 -1
- package/dist/cli/session-command.js +1 -1
- package/dist/cli/stats.js +2 -2
- package/dist/cli/task-context.js +3 -1
- package/dist/cli/thread-command.js +1 -1
- package/dist/cli/watch-msg.js +1 -1
- package/dist/config/builtin-role-templates.js +2 -2
- package/dist/config/builtin-roles.js +2 -1
- package/dist/config/config-field-policy.js +7 -2
- package/dist/config/config-manager.js +32 -10
- package/dist/config/peer-role-resolver.js +23 -1
- package/dist/config/role-schema.js +29 -4
- package/dist/config/role-service.js +12 -7
- package/dist/config/role-store.js +30 -8
- package/dist/config-store.js +75 -4
- package/dist/core/agent-ipc-registration.js +16 -59
- package/dist/core/auth/auth-gateway.js +14 -4
- package/dist/core/auth/authorization-audit.js +52 -14
- package/dist/core/auth/operation-authorizer.js +17 -11
- package/dist/core/auth/operation-catalog.js +5 -13
- package/dist/core/channel-loader.js +152 -16
- package/dist/core/channel-runtime.js +5 -0
- package/dist/core/command/agent-control.js +2 -1
- package/dist/core/command/agentmd-menu-request.js +50 -0
- package/dist/core/command/agentmd-menu.js +156 -0
- package/dist/core/command/cli-intent-parser.js +0 -8
- package/dist/core/command/command-handler.js +47 -40
- package/dist/core/command/connect-menu.js +7 -3
- package/dist/core/command/menu-catalog.js +16 -2
- package/dist/core/command/menu-handler.js +107 -14
- package/dist/core/command/menu-protocol.js +28 -0
- package/dist/core/command/role-menu.js +23 -9
- package/dist/core/command/slash-handler.js +139 -51
- package/dist/core/daemon-file-cache.js +3 -3
- package/dist/core/daemon-lifecycle.js +9 -1
- package/dist/core/evolagent-registry.js +5 -4
- package/dist/core/evolagent.js +10 -12
- package/dist/core/handoff/argv-parse.js +115 -0
- package/dist/core/handoff/ipc-registration.js +1 -1
- package/dist/core/ipc-registration.js +19 -2
- package/dist/core/lifecycle-notice.js +185 -0
- package/dist/core/memory/consolidation.js +8 -1
- package/dist/core/memory/relation-sweep.js +20 -8
- package/dist/core/message/aun-ipc-sender.js +35 -2
- package/dist/core/message/contact-admission.js +530 -0
- package/dist/core/message/im-renderer.js +111 -16
- package/dist/core/message/message-admission.js +29 -54
- package/dist/core/message/message-bridge.js +62 -8
- package/dist/core/message/message-utils.js +9 -5
- package/dist/core/message/peer-mode.js +55 -13
- package/dist/core/message/response-engine.js +298 -78
- package/dist/core/message/retry-scheduler.js +4 -0
- package/dist/core/ownership/owner-resolver.js +72 -34
- package/dist/core/permission/ec-command-parser.js +25 -38
- package/dist/core/permission/readonly-shell-query.js +34 -8
- package/dist/core/permission/tool-policy.js +50 -5
- package/dist/core/relation/pa-team.js +127 -0
- package/dist/core/role/runtime-policy.js +18 -5
- package/dist/core/session/session-manager.js +9 -1
- package/dist/core/soul.js +66 -0
- package/dist/core/system-session/memory.js +2 -2
- package/dist/core/thread/thread-service.js +6 -4
- package/dist/directory/contact-admission-paths.js +9 -0
- package/dist/directory/owner-directory-admission.js +125 -29
- package/dist/directory/owner-directory-cache.js +554 -58
- package/dist/directory/owner-directory-identity.js +60 -0
- package/dist/directory/owner-directory-markdown.js +154 -58
- package/dist/directory/owner-directory-policy.js +108 -0
- package/dist/directory/owner-directory-query-operation.js +399 -90
- package/dist/directory/owner-directory-remarks.js +29 -2
- package/dist/directory/owner-directory-request-operation.js +76 -0
- package/dist/directory/owner-directory-scope.js +35 -4
- package/dist/directory/owner-directory-search.js +118 -33
- package/dist/directory/owner-directory-store.js +117 -30
- package/dist/directory/owner-directory-text.js +60 -0
- package/dist/eck/kit-renderer.js +18 -8
- package/dist/eck/manifest-engine.js +55 -6
- package/dist/ecweb/basic-settings-service.js +2 -2
- package/dist/ecweb/message-context-service.js +28 -16
- package/dist/index.js +20 -5
- package/dist/ipc.js +1 -1
- package/dist/paths.js +29 -1
- package/dist/product.js +1 -0
- package/dist/response-system/config-resolver.js +1 -1
- package/dist/response-system/engines/v1/index.js +2 -1
- package/dist/response-system/modes/single-session/index.js +7 -2
- package/dist/trigger/scheduler.js +7 -4
- package/dist/trigger/validation.js +4 -0
- package/dist/utils/error-utils.js +12 -7
- package/dist/utils/logger.js +13 -4
- package/dist/utils/npm-ops.js +2 -2
- package/dist/utils/windows-autostart.js +1 -1
- package/ecagent/README.md +18 -0
- package/ecagent/dist/agent-loop.js +43 -1
- package/ecagent/dist/harness/agent-harness.d.ts +2 -0
- package/ecagent/dist/harness/agent-harness.js +24 -8
- package/ecagent/dist/harness/compaction/compaction.js +3 -0
- package/ecagent/dist/harness/types.d.ts +1 -0
- package/kits/docs/INDEX.md +1 -0
- package/kits/docs/channels/aun.md +1 -1
- package/kits/docs/context-assembly.md +21 -6
- package/kits/docs/eck_templates/INDEX.template.md +1 -2
- package/kits/docs/evolcore/INDEX.md +4 -1
- package/kits/docs/evolcore/agent-create.md +5 -5
- package/kits/docs/evolcore/agent.md +4 -9
- package/kits/docs/evolcore/directory.md +227 -0
- package/kits/docs/evolcore/ecweb-lifecycle.md +26 -0
- package/kits/docs/evolcore/file-navigation.md +265 -0
- package/kits/docs/evolcore/menu-protocol.md +55 -0
- package/kits/docs/evolcore/msg.md +1 -0
- package/kits/docs/evolcore/peer.md +2 -1
- package/kits/docs/evolcore/response.md +7 -1
- package/kits/docs/evolcore/task.md +2 -0
- package/kits/docs/evolcore/tool-authorization.md +1 -1
- package/kits/docs/evolcore/trigger.md +4 -0
- package/kits/docs/identity/ROLE_DETAIL.md +2 -0
- package/kits/docs/prompt-loading-architecture.md +6 -2
- package/kits/eck_manifest.auxiliary.json +1 -0
- package/kits/eck_manifest.json +64 -7
- package/kits/eck_manifest.memory.json +93 -4
- package/kits/rules/01-overview.md +2 -2
- package/kits/rules/03-identity.md +10 -9
- package/kits/rules/05-venue.md +2 -4
- package/kits/rules/06-channel.md +1 -1
- package/kits/schemas/_meta.json +44 -3
- package/kits/schemas/agent-config.schema.18.json +5 -0
- package/kits/schemas/agent-config.schema.19.json +924 -0
- package/kits/schemas/agent-config.schema.20.json +925 -0
- package/kits/schemas/relation-config.schema.12.json +289 -0
- package/kits/schemas/relation-config.schema.13.json +289 -0
- package/kits/schemas/role-config.schema.2.json +215 -0
- package/kits/schemas/role-config.schema.3.json +1038 -0
- package/kits/schemas/role-registry.schema.1.json +3 -2
- package/kits/skills/ec-skill/scripts/cli.mjs +3 -2
- package/kits/skills/ec-trigger/SKILL.md +4 -4
- package/kits/skills/personal-assistant/SKILL.md +109 -53
- package/kits/skills/personal-assistant/references/02-bootstrap.md +73 -30
- package/kits/skills/personal-assistant/scripts/clean.mjs +35 -18
- package/kits/skills/personal-assistant/scripts/init.mjs +41 -2
- package/kits/skills/personal-assistant/scripts/lib/persona.mjs +185 -0
- package/kits/skills/personal-assistant/scripts/migrate.mjs +55 -4
- package/kits/skills/personal-assistant/scripts/pa.mjs +173 -0
- package/kits/skills/personal-assistant/scripts/uninstall.mjs +130 -0
- package/kits/skills/personal-assistant/templates/persona-section.md +3 -3
- package/kits/templates/message-fragments/handoff-request-to-target.md +1 -1
- package/kits/templates/soul/00-GUIDE.md +39 -0
- package/kits/templates/soul/01-identity.md +5 -0
- package/kits/templates/soul/02-persona.md +11 -0
- package/kits/templates/soul/03-duties.md +5 -0
- package/kits/templates/soul/04-working-style.md +5 -0
- package/kits/templates/system-fragments/bootstrap.md +7 -7
- package/kits/templates/system-fragments/channel.md +2 -2
- package/kits/templates/system-fragments/commands.md +3 -2
- package/kits/templates/system-fragments/directory-contacts.md +9 -0
- package/kits/templates/system-fragments/memory.md +1 -1
- package/kits/templates/system-fragments/personal-assistant.md +50 -0
- package/kits/templates/system-fragments/reply.md +7 -0
- package/kits/templates/system-fragments/session.md +6 -2
- package/package.json +3 -2
- package/dist/cli/handoff-command.js +0 -353
- package/dist/directory/owner-directory-remark-operation.js +0 -147
- package/kits/docs/evolcore/self-summary.md +0 -29
|
@@ -10,6 +10,8 @@ import { loadedBaseagentIds } from '../../agents/baseagent-availability.js';
|
|
|
10
10
|
import { isDiagnosticSessionActive } from '../command/diag-service.js';
|
|
11
11
|
import { evaluateInboundAdmissionPreflight, evaluateOrdinaryInboundAdmission } from './message-admission.js';
|
|
12
12
|
import { authorizeAccess, authorizeOperation, buildAuthSubject } from '../auth/auth-gateway.js';
|
|
13
|
+
import { preparePaTeamQualification, paTeamQualification, requiresPaTeamVerification } from '../relation/pa-team.js';
|
|
14
|
+
import { getRoleDefinition } from '../../config/roles.js';
|
|
13
15
|
import { buildTaskRuntimeEnv, ensureRuntimeLockDir, ensureSessionRuntimeDir } from '../../cli/task-context.js';
|
|
14
16
|
import { BUILTIN_SESSION_PATH_GRANTS, mergeRuntimeGrantsForSession, resolveGrantedReadRoots, } from '../permission/session-path-grants.js';
|
|
15
17
|
import { buildSystemSessionContext, getSystemSessionModule, isSystemSessionType, readSystemSessionMarker } from '../system-session/registry.js';
|
|
@@ -18,6 +20,8 @@ import { projectSubtaskStarted, projectSubtaskTerminal } from './subtask-tool-pr
|
|
|
18
20
|
import { TaskActivityStore } from '../task/task-activity-store.js';
|
|
19
21
|
import { createSendFileMarkerPattern } from './file-markers.js';
|
|
20
22
|
import { hasOwnerDirectoryMarkdown } from '../../directory/owner-directory-markdown.js';
|
|
23
|
+
import { EMPTY_IDENTITY, readOwnerDirectoryIdentity } from '../../directory/owner-directory-identity.js';
|
|
24
|
+
import { resolveContactsState } from '../../directory/owner-directory-policy.js';
|
|
21
25
|
import { createDecisionInferenceProvider, createTextInferenceProvider } from '../inference/text-inference.js';
|
|
22
26
|
import { StreamIdleMonitor } from './stream-idle-monitor.js';
|
|
23
27
|
import { logger } from '../../utils/logger.js';
|
|
@@ -28,7 +32,7 @@ import { describeProactiveSendCommandFailure, isExactEvolcoreSendCommandForSessi
|
|
|
28
32
|
import { resolveThreadRouteTarget } from '../thread/thread-route.js';
|
|
29
33
|
import { isMainSession, isTopicSession, isTopicThreadId, sessionLocalTopicId, sessionTopicThreadId } from '../thread/topic-id.js';
|
|
30
34
|
import { summarizeToolInputForDisplay, toolInputForDisplay } from '../../utils/tool-summary.js';
|
|
31
|
-
import { agentDataDir, agentDir as resolveAgentDir, agentMdPath, getPackageRoot, resolveRoot, resolvePaths, debugSessionsDir } from '../../paths.js';
|
|
35
|
+
import { agentDataDir, agentDir as resolveAgentDir, agentMdPath, agentSoulDir, getPackageRoot, resolveRoot, resolvePaths, debugSessionsDir } from '../../paths.js';
|
|
32
36
|
import { renderKitSections, resolveSessionManifest, DEFAULT_MANIFEST_FILE } from '../../eck/kit-renderer.js';
|
|
33
37
|
import { renderMessageBody } from '../../eck/message-renderer.js';
|
|
34
38
|
import { syncGroupRulesContext } from '../../eck/group-rules-sync.js';
|
|
@@ -38,8 +42,8 @@ import { recordCausationLink, recordCausationSpan } from '../causation/audit.js'
|
|
|
38
42
|
import { normalizeBaseagent, resolveBaseagentModelSelection, resolveRuntimeBaseagentModelSelection } from '../../agents/baseagent.js';
|
|
39
43
|
import { renderActionAsText } from '../interaction-router.js';
|
|
40
44
|
import { formatPeerKey, parsePeerKey } from '../relation/peer-identity.js';
|
|
41
|
-
import { buildEnvelope, isInteractionSendAccepted, replyContextFromSession, sendInteractionPayload, withEnvelopeReplyContext } from './message-utils.js';
|
|
42
|
-
import { isSystemOrServicePeer, resolveChatMode } from './peer-mode.js';
|
|
45
|
+
import { buildEnvelope, isInteractionSendAccepted, isNoopText, replyContextFromSession, sendInteractionPayload, withEnvelopeReplyContext } from './message-utils.js';
|
|
46
|
+
import { chatModeForScene, isSystemOrServicePeer, resolveChatMode } from './peer-mode.js';
|
|
43
47
|
import { AGENT_DELEGATION_TOKEN_ENV } from '../auth/agent-delegation.js';
|
|
44
48
|
import { hasTrustedPrincipal } from '../auth/authenticated-actor.js';
|
|
45
49
|
import { isValidAid } from '../../aun/aid/identity.js';
|
|
@@ -47,8 +51,8 @@ import { isValidAid } from '../../aun/aid/identity.js';
|
|
|
47
51
|
export { buildEnvelope, sendInteractionPayload } from './message-utils.js';
|
|
48
52
|
import { constrainResolvedModelForRole, isModelAllowedForRoleBaseagent } from '../model/model-permission.js';
|
|
49
53
|
import { eligibleFallbackModels } from '../model/model-fallback.js';
|
|
50
|
-
import { RetryScheduler } from './retry-scheduler.js';
|
|
51
|
-
import { assertSessionFullAccessAuthorization, constrainRuntimePermissionMode, resolveRuntimeStringField } from '../role/runtime-policy.js';
|
|
54
|
+
import { isRecoverableProtocolFailure, RetryScheduler } from './retry-scheduler.js';
|
|
55
|
+
import { assertSessionFullAccessAuthorization, constrainRuntimePermissionMode, readSessionFullAccessOverride, resolveRuntimeStringField, updateRelationSessionFullAccess } from '../role/runtime-policy.js';
|
|
52
56
|
import { resolveEffective, resolveEffectiveFieldWithSource } from '../../config/config-manager.js';
|
|
53
57
|
import { resolveAgentLifecycle } from '../../config/lifecycle.js';
|
|
54
58
|
import { authorizationConfigRevision, checkRoleAccess, getFirstStaticAgentOwner, listStaticAgentAdmins, listStaticAgentOwners, resolvePeerRoleDetail, roleToSessionIdentity, } from '../../config/peer-role-resolver.js';
|
|
@@ -64,6 +68,7 @@ import { registerBuiltinModes } from '../../response-system/modes/index.js';
|
|
|
64
68
|
import { deriveSessionTitle, shouldAutoFillSessionTitle } from '../session/session-title.js';
|
|
65
69
|
import { SessionTurnCoordinator } from '../session/session-turn-coordinator.js';
|
|
66
70
|
import { recordTriggerExecutionAnomaly } from '../../trigger/anomaly-store.js';
|
|
71
|
+
import { isTriggerNoopText } from '../../trigger/validation.js';
|
|
67
72
|
import { normalizeToolErrorClassification } from '../permission/tool-error-code.js';
|
|
68
73
|
import { normalizeExecutionPermissionMode } from '../permission/mode.js';
|
|
69
74
|
import { buildToolLifecycleEventKey } from '../audit/event-key.js';
|
|
@@ -1112,8 +1117,12 @@ export function isExpectedStreamInterrupt(terminalReason, interruptReason) {
|
|
|
1112
1117
|
return isExpectedTerminalInterrupt(terminalReason) || isNonErrorInterruptReason(interruptReason);
|
|
1113
1118
|
}
|
|
1114
1119
|
export async function projectTerminalReply(projection) {
|
|
1115
|
-
if (!projection.isCurrent() || projection.isInterrupted()
|
|
1120
|
+
if (!projection.isCurrent() || projection.isInterrupted())
|
|
1116
1121
|
return false;
|
|
1122
|
+
if (projection.isNoop) {
|
|
1123
|
+
projection.discardText();
|
|
1124
|
+
return false;
|
|
1125
|
+
}
|
|
1117
1126
|
if (projection.isError) {
|
|
1118
1127
|
return projection.text || projection.diagnosticText ? projection.sendError() : false;
|
|
1119
1128
|
}
|
|
@@ -1182,10 +1191,9 @@ function withFallbackModel(override, candidate) {
|
|
|
1182
1191
|
};
|
|
1183
1192
|
}
|
|
1184
1193
|
/**
|
|
1185
|
-
* Keep the
|
|
1186
|
-
*
|
|
1187
|
-
*
|
|
1188
|
-
* execution-mode signal for the privileged task.
|
|
1194
|
+
* Keep the existing notice in the user-message prompt: every one-shot task,
|
|
1195
|
+
* once per locally enabled EC session, and never for global policy or Triggers.
|
|
1196
|
+
* This leaves the long-lived system/developer prompt cache unchanged.
|
|
1189
1197
|
*/
|
|
1190
1198
|
const FULL_ACCESS_MESSAGE_PROMPT_CONTEXT = '【当前权限模式提升为fullaccess,可不受限制执行命令,仅当前轮 task 有效】';
|
|
1191
1199
|
/**
|
|
@@ -1521,12 +1529,16 @@ export class ResponseEngine {
|
|
|
1521
1529
|
? (session.metadata?.groupId || channelId)
|
|
1522
1530
|
: (session.metadata?.peerId || channelId);
|
|
1523
1531
|
const peerKey = channelType && peerKeyId ? formatPeerKey(channelType, peerKeyId) : undefined;
|
|
1532
|
+
const agent = this.agentRegistry?.resolveByChannel(channelKey);
|
|
1524
1533
|
return resolveChatMode({
|
|
1525
1534
|
self: self || undefined,
|
|
1526
1535
|
peerKey,
|
|
1527
1536
|
role: session.identity?.role,
|
|
1528
1537
|
chatType: session.chatType,
|
|
1529
1538
|
peerType,
|
|
1539
|
+
channelType,
|
|
1540
|
+
lifecycle: agent ? resolveAgentLifecycle(agent.config) : undefined,
|
|
1541
|
+
sessionType: session.sessionType ?? session.metadata?.sessionType ?? 'main',
|
|
1530
1542
|
});
|
|
1531
1543
|
}
|
|
1532
1544
|
catch {
|
|
@@ -2454,7 +2466,7 @@ export class ResponseEngine {
|
|
|
2454
2466
|
return true;
|
|
2455
2467
|
}
|
|
2456
2468
|
async retryAfterContextRecovery(prompt, opts) {
|
|
2457
|
-
const { streamKey, renderer, agent, session, absoluteProjectPath, effectiveSystemPrompt, modelOverride, runtimeEnv, resetTimer, shouldSuppress, proactive, turnLease, beforeRunQuery, messagePromptContext, } = opts;
|
|
2469
|
+
const { streamKey, renderer, agent, session, absoluteProjectPath, effectiveSystemPrompt, modelOverride, runtimeEnv, resetTimer, shouldSuppress, proactive, turnLease, beforeRunQuery, messagePromptContext, onInputAccepted, } = opts;
|
|
2458
2470
|
if (!session.agentSessionId || !canCompactAgent(agent)) {
|
|
2459
2471
|
throw new Error('CONTEXT_COMPACT_FAILED');
|
|
2460
2472
|
}
|
|
@@ -2494,7 +2506,8 @@ export class ResponseEngine {
|
|
|
2494
2506
|
await this.emitOperationalNotice(renderer, '✅ 压缩完成,继续处理...', 'info', 'compact-retry');
|
|
2495
2507
|
await renderer.flush();
|
|
2496
2508
|
await beforeRunQuery?.();
|
|
2497
|
-
const
|
|
2509
|
+
const rawRetryStream = await agent.runQuery(session.id, insertMessagePromptContext(prompt, messagePromptContext), absoluteProjectPath, session.agentSessionId, undefined, effectiveSystemPrompt, this.sessionManager, recoveryModelOverride, runtimeEnv);
|
|
2510
|
+
const retryStream = this.consumeCapsuleWithInput(rawRetryStream, session, opts.message, turnLease, () => undefined, onInputAccepted);
|
|
2498
2511
|
if (await this.cancelStaleRunnerStart(agent, session.id, streamKey, turnLease, turnLease.taskId)) {
|
|
2499
2512
|
throw new Error('RUNNER_START_SUPERSEDED');
|
|
2500
2513
|
}
|
|
@@ -2503,7 +2516,7 @@ export class ResponseEngine {
|
|
|
2503
2516
|
generation: turnLease.generation,
|
|
2504
2517
|
});
|
|
2505
2518
|
return await this.processEventStream(retryStream, session, agent, renderer, resetTimer, shouldSuppress, proactive, undefined, // 重试分支不调插件钩子
|
|
2506
|
-
undefined, turnLease, opts.permissionMode, opts.proactiveSelfAid);
|
|
2519
|
+
undefined, turnLease, opts.permissionMode, opts.proactiveSelfAid, undefined, undefined, opts.noopSentinel);
|
|
2507
2520
|
}
|
|
2508
2521
|
if (compactResult && typeof compactResult === 'object' && compactResult.message) {
|
|
2509
2522
|
logger.warn(`[ResponseEngine] Context compact failed: ${compactResult.message}`);
|
|
@@ -2655,12 +2668,10 @@ export class ResponseEngine {
|
|
|
2655
2668
|
}
|
|
2656
2669
|
}
|
|
2657
2670
|
async assertCurrentExecutionAuthorization(context, agent) {
|
|
2671
|
+
await assertOwnershipAuthorization(context);
|
|
2658
2672
|
if (context.executionPermission) {
|
|
2659
2673
|
await this.assertCurrentFullAccessExecutionAuthorization(context.executionPermission, agent);
|
|
2660
2674
|
}
|
|
2661
|
-
else {
|
|
2662
|
-
await assertOwnershipAuthorization(context);
|
|
2663
|
-
}
|
|
2664
2675
|
}
|
|
2665
2676
|
/**
|
|
2666
2677
|
* The authorization envelope is immutable for one logical run, but the
|
|
@@ -3014,6 +3025,18 @@ export class ResponseEngine {
|
|
|
3014
3025
|
const accessAdapter = accessChannelInfo?.adapter;
|
|
3015
3026
|
const accessAdapterSelfAid = typeof accessAdapter?._selfAid === 'function' ? accessAdapter._selfAid() : undefined;
|
|
3016
3027
|
const selfAidForAccess = accessAdapterSelfAid || message.selfAID || session.selfAID || undefined;
|
|
3028
|
+
if (message.source === 'trigger' && message.triggerMeta?.originChannelType === 'aun'
|
|
3029
|
+
&& message.triggerMeta.originChatType !== 'group') {
|
|
3030
|
+
await preparePaTeamQualification(selfAidForAccess, message.triggerMeta.originPeerId);
|
|
3031
|
+
}
|
|
3032
|
+
if (message.source === 'handoff' && message.handoffDelivery?.direction === 'origin'
|
|
3033
|
+
&& message.handoffDelivery.originAuthorization?.channelType === 'aun'
|
|
3034
|
+
&& message.handoffDelivery.originAuthorization.chatType === 'private') {
|
|
3035
|
+
await preparePaTeamQualification(selfAidForAccess, message.handoffDelivery.originAuthorization.actorId);
|
|
3036
|
+
}
|
|
3037
|
+
if ((message.channelType || accessChannelKey.split('#')[0]) === 'aun' && message.chatType !== 'group') {
|
|
3038
|
+
await preparePaTeamQualification(selfAidForAccess, message.peerId);
|
|
3039
|
+
}
|
|
3017
3040
|
await refreshOwnershipForAuthorization(selfAidForAccess, {
|
|
3018
3041
|
maxAgeMs: OWNERSHIP_CACHE_MAX_AGE_MS,
|
|
3019
3042
|
allowTransient: true,
|
|
@@ -3639,6 +3662,15 @@ export class ResponseEngine {
|
|
|
3639
3662
|
const selfName = registrySelfName ?? adapterSelfName;
|
|
3640
3663
|
const peerName = message.peerName || session.metadata?.peerName;
|
|
3641
3664
|
const peerIdRaw = message.peerId;
|
|
3665
|
+
if (message.source === 'trigger' && message.triggerMeta?.originChannelType === 'aun'
|
|
3666
|
+
&& message.triggerMeta.originChatType !== 'group') {
|
|
3667
|
+
await preparePaTeamQualification(selfAid, message.triggerMeta.originPeerId);
|
|
3668
|
+
}
|
|
3669
|
+
if (message.handoffDelivery?.direction === 'origin'
|
|
3670
|
+
&& message.handoffDelivery.originAuthorization?.channelType === 'aun'
|
|
3671
|
+
&& message.handoffDelivery.originAuthorization.chatType === 'private') {
|
|
3672
|
+
await preparePaTeamQualification(selfAid, message.handoffDelivery.originAuthorization.actorId);
|
|
3673
|
+
}
|
|
3642
3674
|
const triggerExecutionIdentity = this.resolveTriggerExecutionIdentity(message, selfAid);
|
|
3643
3675
|
const authorizationIdentity = triggerExecutionIdentity
|
|
3644
3676
|
?? this.resolveHandoffOriginExecutionIdentity(message, selfAid);
|
|
@@ -3661,6 +3693,9 @@ export class ResponseEngine {
|
|
|
3661
3693
|
? formatPeerKey(configChannelType, peerKeyId)
|
|
3662
3694
|
: undefined);
|
|
3663
3695
|
const peerType = message.peerType ?? session.metadata?.peerType;
|
|
3696
|
+
if (configChannelType === 'aun' && configChatType === 'private') {
|
|
3697
|
+
await preparePaTeamQualification(selfAid, configActorId);
|
|
3698
|
+
}
|
|
3664
3699
|
const peerRoleDetail = authorizationIdentity ? undefined : (() => {
|
|
3665
3700
|
try {
|
|
3666
3701
|
return resolvePeerRoleDetail({
|
|
@@ -3710,6 +3745,13 @@ export class ResponseEngine {
|
|
|
3710
3745
|
// trigger override 绝对优先;否则由 Coordinator 解析(responseMode 标量 > 注册表首选)。
|
|
3711
3746
|
const systemOrServicePeer = isSystemOrServicePeer(peerType);
|
|
3712
3747
|
const triggerChatModeOverride = systemOrServicePeer ? undefined : message.triggerMeta?.chatModeOverride;
|
|
3748
|
+
const previousTurn = this.turnCoordinator.current(session);
|
|
3749
|
+
const recoveryChatMode = (message.taskRecovery || message.restartResume?.submitted)
|
|
3750
|
+
? (previousTurn.active ?? previousTurn.lastTerminal)?.recoveryContext?.chatmode
|
|
3751
|
+
: undefined;
|
|
3752
|
+
// Preserve PA's explicit-reply contract across recovery. The existing
|
|
3753
|
+
// interactive/proactive recovery and override rules remain authoritative.
|
|
3754
|
+
const taskChatModeOverride = recoveryChatMode === 'paactive' ? recoveryChatMode : triggerChatModeOverride;
|
|
3713
3755
|
// chatmode 是顶层字典(agent 级与关系级同名,已由 ConfigManager 逐键合并)。
|
|
3714
3756
|
// 实际生效值由对端类型选键(private/nothuman/group),出厂默认走 schema。
|
|
3715
3757
|
const chatModeFallback = resolveChatMode({
|
|
@@ -3718,14 +3760,27 @@ export class ResponseEngine {
|
|
|
3718
3760
|
role: peerRole,
|
|
3719
3761
|
chatType,
|
|
3720
3762
|
peerType,
|
|
3763
|
+
channelType: currentChannelType,
|
|
3764
|
+
lifecycle,
|
|
3765
|
+
sessionType: session.sessionType ?? session.metadata?.sessionType ?? 'main',
|
|
3721
3766
|
});
|
|
3767
|
+
// Resolve overrides before binding a flow so hooks, context and envelope
|
|
3768
|
+
// all use the same scene-checked mode for this task.
|
|
3769
|
+
const effectiveChatMode = chatType === 'group'
|
|
3770
|
+
? 'proactive'
|
|
3771
|
+
: systemOrServicePeer
|
|
3772
|
+
? 'interactive'
|
|
3773
|
+
: taskChatModeOverride
|
|
3774
|
+
? chatModeForScene(taskChatModeOverride, { channelType: currentChannelType, chatType, peerType, role: peerRole, lifecycle, sessionType: session.sessionType ?? session.metadata?.sessionType ?? 'main' })
|
|
3775
|
+
: chatModeFallback;
|
|
3722
3776
|
const responseModeAgentDir = selfAid ? resolveAgentDir(selfAid) : undefined;
|
|
3723
3777
|
// mentionMode:顶层通用参数(先读出备用,投递/入队策略后续接入)
|
|
3724
3778
|
const mentionMode = effectiveAgentConfig?.mentionMode ?? 'disabled';
|
|
3725
|
-
const resolvedMode = triggerChatModeOverride
|
|
3726
|
-
|
|
3779
|
+
const resolvedMode = (triggerChatModeOverride && effectiveChatMode !== 'paactive')
|
|
3780
|
+
|| systemOrServicePeer || !responseModeAgentDir
|
|
3781
|
+
? null
|
|
3727
3782
|
: this.responseCoordinator.resolveMode(effectiveAgentConfig?.responseMode, // 标量:关系级>agent级>注册表首选
|
|
3728
|
-
|
|
3783
|
+
effectiveChatMode, effectiveAgentConfig?.responseModeParams, // 按模式分桶的参数字典
|
|
3729
3784
|
{
|
|
3730
3785
|
session,
|
|
3731
3786
|
agentConfig: effectiveAgentConfig,
|
|
@@ -3745,19 +3800,15 @@ export class ResponseEngine {
|
|
|
3745
3800
|
agentDir: responseModeAgentDir,
|
|
3746
3801
|
});
|
|
3747
3802
|
if (resolvedMode) {
|
|
3748
|
-
logger.info('[ResponseSystem] selected mode=' + resolvedMode.mode.id + ' source=' + resolvedMode.source + ' chatType=' + chatType + ' peerKey=' + (peerKey ?? 'none') + ' chatMode=' +
|
|
3803
|
+
logger.info('[ResponseSystem] selected mode=' + resolvedMode.mode.id + ' source=' + resolvedMode.source + ' chatType=' + chatType + ' peerKey=' + (peerKey ?? 'none') + ' chatMode=' + effectiveChatMode);
|
|
3749
3804
|
}
|
|
3750
3805
|
else {
|
|
3751
|
-
logger.info('[ResponseSystem] selected mode=override/fallback source=trigger-or-resolve-failed chatType=' + chatType + ' peerKey=' + (peerKey ?? 'none') + ' chatMode=' +
|
|
3806
|
+
logger.info('[ResponseSystem] selected mode=override/fallback source=trigger-or-resolve-failed chatType=' + chatType + ' peerKey=' + (peerKey ?? 'none') + ' chatMode=' + effectiveChatMode);
|
|
3752
3807
|
}
|
|
3753
3808
|
// 最终 chatMode(怎么投递,与「选哪个模式」正交):
|
|
3754
3809
|
// system/service 运行时硬约束 > trigger override > 配置层级解析(chatModeFallback)。
|
|
3755
3810
|
// 注:mode.id 不再参与——单会话合并后 mode.id 恒为 single-session,
|
|
3756
3811
|
// chatMode 由 resolveChatModeForPeer 按配置层级解析(步骤 1/4)。
|
|
3757
|
-
const effectiveChatMode = systemOrServicePeer
|
|
3758
|
-
? 'interactive'
|
|
3759
|
-
: triggerChatModeOverride
|
|
3760
|
-
?? chatModeFallback;
|
|
3761
3812
|
const chatmode = effectiveChatMode;
|
|
3762
3813
|
const isProactive = effectiveChatMode === 'proactive';
|
|
3763
3814
|
const legacyMiddleOutputMode = () => {
|
|
@@ -3782,12 +3833,15 @@ export class ResponseEngine {
|
|
|
3782
3833
|
{
|
|
3783
3834
|
import('../../utils/msg-diag.js').then(m => m.diagLog('task_created', { aid: session.selfAID ?? '', msgId: message.messageId ?? '', taskId, text: message.content ?? '' })).catch(() => { });
|
|
3784
3835
|
}
|
|
3836
|
+
// Per-turn attempt state; configuration changes cannot mutate this model.
|
|
3837
|
+
let debugRunnerModel;
|
|
3785
3838
|
// 构建带 taskId/chatmode 的 ReplyContext(本次任务所有出站消息共用)
|
|
3786
3839
|
const taskReplyContext = () => {
|
|
3787
3840
|
const base = this.getReplyContext(message);
|
|
3788
3841
|
return {
|
|
3789
3842
|
...replyContextFromSession(session, base),
|
|
3790
3843
|
sessionId: session.id,
|
|
3844
|
+
model: debugRunnerModel,
|
|
3791
3845
|
threadId: sessionTopicThreadId(session) ?? base?.threadId,
|
|
3792
3846
|
metadata: withTaskMetadata(base?.metadata),
|
|
3793
3847
|
};
|
|
@@ -3852,7 +3906,7 @@ export class ResponseEngine {
|
|
|
3852
3906
|
channel: message.channel,
|
|
3853
3907
|
channelId: message.channelId,
|
|
3854
3908
|
agentName: agentNameForStats,
|
|
3855
|
-
chatmode:
|
|
3909
|
+
chatmode: effectiveChatMode,
|
|
3856
3910
|
replyContext: taskReplyContext(),
|
|
3857
3911
|
causation: taskCausation,
|
|
3858
3912
|
});
|
|
@@ -4187,6 +4241,7 @@ export class ResponseEngine {
|
|
|
4187
4241
|
? aunMessageTranscriptUuid(sourceMessageId)
|
|
4188
4242
|
: undefined;
|
|
4189
4243
|
turnLease = await this.turnCoordinator.begin(session, taskId, inputId, configActorId ? {
|
|
4244
|
+
...(effectiveChatMode === 'paactive' ? { chatmode: effectiveChatMode } : {}),
|
|
4190
4245
|
peerId: configActorId,
|
|
4191
4246
|
approvalInteractionPolicy,
|
|
4192
4247
|
encrypted: message.encrypted ?? message.replyContext?.metadata?.encrypted,
|
|
@@ -4233,9 +4288,6 @@ export class ResponseEngine {
|
|
|
4233
4288
|
});
|
|
4234
4289
|
// 创建 IMRenderer(统一 interactive/proactive 两条路径)
|
|
4235
4290
|
let firstReply = true;
|
|
4236
|
-
// 出站 debug.model:每次 runQuery 前更新(含备用模型切换)。单独声明是因为
|
|
4237
|
-
// send 闭包早于下方 modelOverride/agentModel 的 let 声明,直接引用会撞 TDZ。
|
|
4238
|
-
let debugRunnerModel;
|
|
4239
4291
|
const renderer = new IMRenderer({
|
|
4240
4292
|
adapter,
|
|
4241
4293
|
envelope,
|
|
@@ -4245,9 +4297,10 @@ export class ResponseEngine {
|
|
|
4245
4297
|
suppressActivityItems: isProactive ? false : middleOutputMode !== 'all',
|
|
4246
4298
|
suppressIntermediateText: isProactive ? false : middleOutputMode === 'none',
|
|
4247
4299
|
deferTextUntilBoundary: (message.channelType ?? session.channelType) === 'aun' && session.chatType === 'private',
|
|
4300
|
+
noopSentinel: message.source === 'trigger' ? message.triggerMeta?.noopSentinel : undefined,
|
|
4248
4301
|
operationalNoticesAsText: !isProactive && middleOutputMode !== 'none',
|
|
4249
4302
|
fileMarkerPattern: options?.fileMarkerPattern,
|
|
4250
|
-
recordActivity: async (item) => {
|
|
4303
|
+
recordActivity: async (item, activityId) => {
|
|
4251
4304
|
if (!taskActivityStore || (turnLease && !this.turnCoordinator.canPublish(turnLease)))
|
|
4252
4305
|
return;
|
|
4253
4306
|
try {
|
|
@@ -4264,6 +4317,7 @@ export class ResponseEngine {
|
|
|
4264
4317
|
...(activityChatType === 'group' ? { groupId: activityChannelId } : {}),
|
|
4265
4318
|
...(activityChatType === 'private' ? { peerId: activityChannelId } : {}),
|
|
4266
4319
|
item,
|
|
4320
|
+
...(activityId ? { activityId } : {}),
|
|
4267
4321
|
}, { projectPath: absoluteProjectPath, allowedRoots: toolImageReadRoots });
|
|
4268
4322
|
}
|
|
4269
4323
|
catch (error) {
|
|
@@ -4314,6 +4368,7 @@ export class ResponseEngine {
|
|
|
4314
4368
|
...(session.agentSessionId ? { agentSessionId: session.agentSessionId } : {}),
|
|
4315
4369
|
...(debugRunnerModel ? { model: debugRunnerModel } : {}),
|
|
4316
4370
|
};
|
|
4371
|
+
opts.model = debugRunnerModel;
|
|
4317
4372
|
opts.metadata = withTaskMetadata({
|
|
4318
4373
|
...(opts.metadata ?? {}),
|
|
4319
4374
|
...(payload.kind === 'result.text' ? payload.metadata : {}),
|
|
@@ -4372,6 +4427,17 @@ export class ResponseEngine {
|
|
|
4372
4427
|
const permissionReplyContext = authorizationIdentity
|
|
4373
4428
|
? { delivery: { chatType: 'private' } }
|
|
4374
4429
|
: capturedReplyContext;
|
|
4430
|
+
const setRunnerModel = (model) => {
|
|
4431
|
+
debugRunnerModel = model;
|
|
4432
|
+
if (envelope.replyContext)
|
|
4433
|
+
envelope.replyContext.model = model;
|
|
4434
|
+
capturedReplyContext.model = model;
|
|
4435
|
+
permissionReplyContext.model = model;
|
|
4436
|
+
if (model)
|
|
4437
|
+
this.activeRunnerModels.set(session.id, model);
|
|
4438
|
+
else
|
|
4439
|
+
this.activeRunnerModels.delete(session.id);
|
|
4440
|
+
};
|
|
4375
4441
|
let permissionTerminalFailure;
|
|
4376
4442
|
const permissionPromptForOrigin = async (text) => {
|
|
4377
4443
|
await permissionAdapter.send(withEnvelopeReplyContext({
|
|
@@ -4513,7 +4579,24 @@ export class ResponseEngine {
|
|
|
4513
4579
|
})
|
|
4514
4580
|
: undefined;
|
|
4515
4581
|
const systemSessionCheck = systemSessionModule && systemSessionContext
|
|
4516
|
-
? (
|
|
4582
|
+
? (() => {
|
|
4583
|
+
let denyCount = 0;
|
|
4584
|
+
const DENY_STEER_THRESHOLD = 3;
|
|
4585
|
+
return (toolName, toolInput) => {
|
|
4586
|
+
const decision = systemSessionModule.checkTool(toolName, toolInput, systemSessionContext);
|
|
4587
|
+
if (!decision.allow) {
|
|
4588
|
+
denyCount++;
|
|
4589
|
+
if (denyCount >= DENY_STEER_THRESHOLD) {
|
|
4590
|
+
const steerHint = `(已连续拒绝 ${denyCount} 次。请停止重试当前命令形式,改用任务书中列出的文件工具,或用 ec memory create|update|archive 写入记忆)`;
|
|
4591
|
+
return { ...decision, reason: decision.reason + ' ' + steerHint };
|
|
4592
|
+
}
|
|
4593
|
+
}
|
|
4594
|
+
else {
|
|
4595
|
+
denyCount = 0;
|
|
4596
|
+
}
|
|
4597
|
+
return decision;
|
|
4598
|
+
};
|
|
4599
|
+
})()
|
|
4517
4600
|
: undefined;
|
|
4518
4601
|
// 沙箱声明与 runner 有关,但当前所有 runner 共用同一个结论;仍按 runner 问一次,
|
|
4519
4602
|
// 以便将来某个 runner 需要不同取舍时只改模块。
|
|
@@ -4557,9 +4640,18 @@ export class ResponseEngine {
|
|
|
4557
4640
|
channel: permissionAdapter.channelKey,
|
|
4558
4641
|
agentName: agentNameForStats,
|
|
4559
4642
|
taskId,
|
|
4560
|
-
chatmode:
|
|
4643
|
+
chatmode: effectiveChatMode,
|
|
4561
4644
|
// 系统会话没有角色
|
|
4562
4645
|
role: systemSessionMarker ? undefined : peerRole,
|
|
4646
|
+
paTeamAuthorization: !systemSessionMarker && configChannelType === 'aun' && configChatType === 'private'
|
|
4647
|
+
&& !!selfAid && !!configActorId && (paTeamQualification(selfAid, configActorId) === 'matched'
|
|
4648
|
+
|| requiresPaTeamVerification(selfAid, configActorId)),
|
|
4649
|
+
paTeamDefaultRole: peerRoleDetail?.source === 'pa-team-default'
|
|
4650
|
+
|| (authorizationIdentity?.role === peerRole && configChannelType === 'aun'
|
|
4651
|
+
&& configChatType === 'private' && !!selfAid && !!configActorId
|
|
4652
|
+
&& resolvePeerRoleDetail({ selfAid, channelKey: authorizationIdentity.originChannelKey, channelType: 'aun', chatType: 'private',
|
|
4653
|
+
actorId: configActorId, conversationId: configActorId }).source === 'pa-team-default'),
|
|
4654
|
+
paTeamPolicy: JSON.stringify(getRoleDefinition(peerRole, selfAid)),
|
|
4563
4655
|
chatType: authChatType,
|
|
4564
4656
|
selfAid,
|
|
4565
4657
|
managedTempDir: sessionRuntimeDir,
|
|
@@ -4751,6 +4843,26 @@ export class ResponseEngine {
|
|
|
4751
4843
|
// 先用裸文本兜底;vars 构造完成后用消息渲染层重算(见下方 effectivePrompt 重赋值)。
|
|
4752
4844
|
let effectivePrompt = wrapPrompt(message.content);
|
|
4753
4845
|
let fullAccessMessagePromptContext;
|
|
4846
|
+
const markFullAccessPromptShown = async () => {
|
|
4847
|
+
if (!fullAccessMessagePromptContext || fullAccessAuthorization?.source !== 'session-policy')
|
|
4848
|
+
return;
|
|
4849
|
+
const current = isTopicSession(session)
|
|
4850
|
+
? await this.sessionManager.getSessionById(session.id) : session;
|
|
4851
|
+
if (!current || !turnLease || !this.turnCoordinator.isCurrent(turnLease))
|
|
4852
|
+
return;
|
|
4853
|
+
const config = readSessionFullAccessOverride(current);
|
|
4854
|
+
if (!config?.enabled || config.authorizedBy !== fullAccessAuthorization.authorizedBy
|
|
4855
|
+
|| config.promptedSessionId === session.id)
|
|
4856
|
+
return;
|
|
4857
|
+
const prompted = { ...config, promptedSessionId: session.id };
|
|
4858
|
+
if (isTopicSession(current)) {
|
|
4859
|
+
const updated = this.sessionManager.updateSessionFullAccess(current.id, prompted);
|
|
4860
|
+
session.metadata = updated.metadata;
|
|
4861
|
+
}
|
|
4862
|
+
else {
|
|
4863
|
+
updateRelationSessionFullAccess(current, prompted);
|
|
4864
|
+
}
|
|
4865
|
+
};
|
|
4754
4866
|
let renderResult;
|
|
4755
4867
|
let effectiveSystemPrompt;
|
|
4756
4868
|
let modelOverride;
|
|
@@ -4871,7 +4983,10 @@ export class ResponseEngine {
|
|
|
4871
4983
|
// records all observe the same normalized value.
|
|
4872
4984
|
permissionContext.permissionMode = effectivePermissionMode;
|
|
4873
4985
|
permissionContext.executionPermission = fullAccessAuthorization;
|
|
4874
|
-
|
|
4986
|
+
const showFullAccessPrompt = fullAccessAuthorization?.source === 'fullaccess-command'
|
|
4987
|
+
|| (fullAccessAuthorization?.source === 'session-policy'
|
|
4988
|
+
&& readSessionFullAccessOverride(session)?.promptedSessionId !== session.id);
|
|
4989
|
+
fullAccessMessagePromptContext = showFullAccessPrompt
|
|
4875
4990
|
? FULL_ACCESS_MESSAGE_PROMPT_CONTEXT
|
|
4876
4991
|
: undefined;
|
|
4877
4992
|
// 模型/强度按配置、CLI 和 runner 默认值解析后,经角色约束传入 runQuery。
|
|
@@ -5048,13 +5163,13 @@ export class ResponseEngine {
|
|
|
5048
5163
|
bootstrapAgentMdPath: agentMdPath(selfAid),
|
|
5049
5164
|
};
|
|
5050
5165
|
}
|
|
5051
|
-
//
|
|
5052
|
-
//
|
|
5053
|
-
//
|
|
5166
|
+
// 自我定义写在 personal/soul/ 下,每个非空文件每轮注入 system prompt。
|
|
5167
|
+
// 这些文件没有命令行入口,只能由 agent 自己用文件工具维护,所以整目录
|
|
5168
|
+
// 对 owner 会话放行(写入即触发下一轮上下文重组)。
|
|
5054
5169
|
if (selfAid && peerRole === 'owner' && effectivePermissionMode !== 'readonly') {
|
|
5055
5170
|
modelOverride = {
|
|
5056
5171
|
...(modelOverride || {}),
|
|
5057
|
-
|
|
5172
|
+
personalSoulDir: agentSoulDir(selfAid),
|
|
5058
5173
|
};
|
|
5059
5174
|
}
|
|
5060
5175
|
if (normalizedBaseagent.canonical === 'claude') {
|
|
@@ -5173,6 +5288,14 @@ export class ResponseEngine {
|
|
|
5173
5288
|
const memoryMode = session.metadata?.memoryMode;
|
|
5174
5289
|
// Kit renderer: 组装上下文
|
|
5175
5290
|
const pkgRoot = getPackageRoot();
|
|
5291
|
+
// 名录身份(Owner / 个人助理)来自渲染产物旁的小文件,只读一次、只取四个字段:
|
|
5292
|
+
// 每轮都要算,不能去解析 contacts.json。读不出时是空身份,下面的 isPersonalAssistant
|
|
5293
|
+
// / isOwner 随之双双为 false——宁可不注入 PA 段,也不能让非 PA 拿到 PA 的行为约束。
|
|
5294
|
+
const directoryIdentity = selfAid
|
|
5295
|
+
? readOwnerDirectoryIdentity(path.join(resolveRoot(), 'agents', selfAid, 'directory'))
|
|
5296
|
+
: EMPTY_IDENTITY;
|
|
5297
|
+
const personalAssistantAid = directoryIdentity.personalAssistant?.aid;
|
|
5298
|
+
const identityOwnerAid = directoryIdentity.owner?.aid;
|
|
5176
5299
|
const kitCtx = {
|
|
5177
5300
|
vars: {
|
|
5178
5301
|
EVOLCORE_HOME: resolveRoot(),
|
|
@@ -5200,12 +5323,37 @@ export class ResponseEngine {
|
|
|
5200
5323
|
RELATIONS_DIR: selfAid ? path.join(resolveRoot(), 'agents', selfAid, 'relations') : undefined,
|
|
5201
5324
|
VENUES_DIR: selfAid ? path.join(resolveRoot(), 'agents', selfAid, 'venues') : undefined,
|
|
5202
5325
|
selfAid: selfAid || undefined,
|
|
5326
|
+
// Owner 以名录快照为准;快照还没落地(首次接入、未授权)时退回静态配置,
|
|
5327
|
+
// 否则 owner-memory 段会整段消失,而它此前一直是按静态 owner 拼路径的。
|
|
5203
5328
|
ownerAid: (() => {
|
|
5329
|
+
if (identityOwnerAid)
|
|
5330
|
+
return identityOwnerAid;
|
|
5204
5331
|
const raw = selfAid ? getFirstStaticAgentOwner(selfAid) : undefined;
|
|
5205
5332
|
if (!raw)
|
|
5206
5333
|
return undefined;
|
|
5207
5334
|
return isValidAid(raw) ? raw : undefined;
|
|
5208
5335
|
})(),
|
|
5336
|
+
ownerName: directoryIdentity.owner?.name || undefined,
|
|
5337
|
+
personalAssistantAid,
|
|
5338
|
+
personalAssistantName: directoryIdentity.personalAssistant?.name || undefined,
|
|
5339
|
+
// 两个角色布尔**即时比较**,不从文件读:落盘的布尔会过期,也挡不住手改文件伪造。
|
|
5340
|
+
isPersonalAssistant: !!personalAssistantAid && personalAssistantAid === selfAid,
|
|
5341
|
+
isOwner: !!identityOwnerAid && identityOwnerAid === selfAid,
|
|
5342
|
+
// 准入现状压成一句话:只列能联系谁,说不通的档位直接不提。
|
|
5343
|
+
// 只说"能",不说"谁关的"——默认关与显式关在结果上没区别。
|
|
5344
|
+
...(() => {
|
|
5345
|
+
if (!selfAid)
|
|
5346
|
+
return {};
|
|
5347
|
+
const state = resolveContactsState(selfAid, personalAssistantAid);
|
|
5348
|
+
const open = ['Owner', '个人助理'];
|
|
5349
|
+
if (state.internalContacts)
|
|
5350
|
+
open.push('内部联系人');
|
|
5351
|
+
if (state.externalContacts)
|
|
5352
|
+
open.push('外部联系人');
|
|
5353
|
+
if (state.strangerContacts)
|
|
5354
|
+
open.push('名录外的人');
|
|
5355
|
+
return { contactsState: `现在可联系:${open.join('、')}` };
|
|
5356
|
+
})(),
|
|
5209
5357
|
// 记忆系统开关变量(来自 effectiveAgentConfig.memory,默认全部启用)。
|
|
5210
5358
|
// enableRelation 是总开关:relation 是所有记忆的唯一出生地。
|
|
5211
5359
|
// memory.enableRelation 在 relation-config schema 里声明了 x-merge-logic: AND,
|
|
@@ -5267,17 +5415,10 @@ export class ResponseEngine {
|
|
|
5267
5415
|
threadId: sessionTopicThreadId(session),
|
|
5268
5416
|
// Stage 3: sessionKey 持久化字段
|
|
5269
5417
|
sessionKey: session.sessionKey,
|
|
5270
|
-
chatMode:
|
|
5418
|
+
chatMode: effectiveChatMode,
|
|
5419
|
+
// Message templates receive the same derived reply fact as system templates.
|
|
5420
|
+
activePush: effectiveChatMode === 'proactive' || effectiveChatMode === 'paactive',
|
|
5271
5421
|
isTriggerTask: causationPath.length > 0 || message.source === 'trigger',
|
|
5272
|
-
// proactive 为 null(interactive 模式,这些开关不适用)时如实为 false——
|
|
5273
|
-
// 默认值不在此硬编码,出厂默认由模式 schema 声明、经 buildState 落入 proactive.*。
|
|
5274
|
-
proactivePreTool1stMsgChk: proactive?.preTool1stMsgChk ?? false,
|
|
5275
|
-
proactiveToolUseReminder: proactive?.toolUseReminder ?? false,
|
|
5276
|
-
// 明确续跑已表态时,提示词和运行时门禁都不再要求重复开场。
|
|
5277
|
-
proactiveFirstSendRequired: proactive?.firstSendRequired === true && !proactive.firstToolDone,
|
|
5278
|
-
proactiveToolReportRequired: proactive?.toolReportRequired ?? false,
|
|
5279
|
-
proactiveToolReportInterval: proactive?.toolReportInterval ?? 20,
|
|
5280
|
-
proactiveSendTargetLabel: chatType === 'group' ? '群里' : '对方',
|
|
5281
5422
|
readonly: effectivePermissionMode === 'readonly',
|
|
5282
5423
|
baseAgent: normalizedBaseagent.canonical,
|
|
5283
5424
|
baseAgentName: normalizedBaseagent.displayName,
|
|
@@ -5292,6 +5433,19 @@ export class ResponseEngine {
|
|
|
5292
5433
|
},
|
|
5293
5434
|
sessionId: session.id,
|
|
5294
5435
|
};
|
|
5436
|
+
if (effectiveChatMode === 'proactive') {
|
|
5437
|
+
Object.assign(kitCtx.vars, {
|
|
5438
|
+
// Proactive policy variables are scoped to proactive tasks only.
|
|
5439
|
+
proactivePreTool1stMsgChk: proactive?.preTool1stMsgChk ?? false,
|
|
5440
|
+
proactiveToolUseReminder: proactive?.toolUseReminder ?? false,
|
|
5441
|
+
// 明确续跑已表态时,提示词和运行时门禁都不再要求重复开场。
|
|
5442
|
+
proactiveFirstSendRequired: proactive?.firstSendRequired === true && !proactive.firstToolDone,
|
|
5443
|
+
proactiveToolReportRequired: proactive?.toolReportRequired ?? false,
|
|
5444
|
+
proactiveToolReportInterval: proactive?.toolReportInterval ?? 20,
|
|
5445
|
+
proactiveSendTargetLabel: chatType === 'group' ? '群里' : '对方',
|
|
5446
|
+
});
|
|
5447
|
+
}
|
|
5448
|
+
const messageVars = kitCtx.vars;
|
|
5295
5449
|
// 确保技能索引是最新的(懒加载机制)
|
|
5296
5450
|
if (selfAid) {
|
|
5297
5451
|
const { ensureSkillIndexUpToDate } = await import('../skill/startup.js');
|
|
@@ -5437,8 +5591,8 @@ export class ResponseEngine {
|
|
|
5437
5591
|
if (message.restartResume?.pendingInterrupted) {
|
|
5438
5592
|
const resumeIdx = renderItems.findIndex(item => item.kind === 'restart-resume');
|
|
5439
5593
|
if (resumeIdx >= 0 && resumeIdx < renderItems.length - 1) {
|
|
5440
|
-
const resumeRender = renderMessageBody(renderItems.slice(0, resumeIdx + 1),
|
|
5441
|
-
const pendingRender = renderMessageBody(renderItems.slice(resumeIdx + 1),
|
|
5594
|
+
const resumeRender = renderMessageBody(renderItems.slice(0, resumeIdx + 1), messageVars, session.id);
|
|
5595
|
+
const pendingRender = renderMessageBody(renderItems.slice(resumeIdx + 1), messageVars, session.id);
|
|
5442
5596
|
const body = [
|
|
5443
5597
|
resumeRender.body.trim(),
|
|
5444
5598
|
`【新消息插入】\n\n${pendingRender.body.trim()}\n\n【请根据前后消息酌情处理】`,
|
|
@@ -5449,11 +5603,11 @@ export class ResponseEngine {
|
|
|
5449
5603
|
};
|
|
5450
5604
|
}
|
|
5451
5605
|
else {
|
|
5452
|
-
renderResult = renderMessageBody(renderItems,
|
|
5606
|
+
renderResult = renderMessageBody(renderItems, messageVars, session.id);
|
|
5453
5607
|
}
|
|
5454
5608
|
}
|
|
5455
5609
|
else {
|
|
5456
|
-
renderResult = renderMessageBody(renderItems,
|
|
5610
|
+
renderResult = renderMessageBody(renderItems, messageVars, session.id);
|
|
5457
5611
|
}
|
|
5458
5612
|
if (renderResult.body.trim())
|
|
5459
5613
|
effectivePrompt = wrapPrompt(renderResult.body);
|
|
@@ -5680,11 +5834,7 @@ export class ResponseEngine {
|
|
|
5680
5834
|
data: image.data,
|
|
5681
5835
|
mimeType: image.mimeType,
|
|
5682
5836
|
}));
|
|
5683
|
-
|
|
5684
|
-
if (debugRunnerModel)
|
|
5685
|
-
this.activeRunnerModels.set(session.id, debugRunnerModel);
|
|
5686
|
-
else
|
|
5687
|
-
this.activeRunnerModels.delete(session.id);
|
|
5837
|
+
setRunnerModel(modelOverride?.model || agentModel);
|
|
5688
5838
|
// 每次尝试前覆盖:备用模型切换后,请求模型以最后一次尝试为准
|
|
5689
5839
|
this.recordBgSessionModels(message, { requestedModel: debugRunnerModel });
|
|
5690
5840
|
if (message.restartResume?.submitted && runAgentSessionId) {
|
|
@@ -5714,7 +5864,20 @@ export class ResponseEngine {
|
|
|
5714
5864
|
},
|
|
5715
5865
|
} };
|
|
5716
5866
|
const rawStream = await agent.runQuery(session.id, capsuleInput.prompt, absoluteProjectPath, runAgentSessionId, runnerImages, effectiveSystemPrompt, this.sessionManager, attemptOverride, runtimeEnv);
|
|
5717
|
-
|
|
5867
|
+
// A provider may resolve an alias or report a more precise model at
|
|
5868
|
+
// completion. Update before the renderer flushes the final output.
|
|
5869
|
+
const trackModel = async function* () {
|
|
5870
|
+
for await (const event of rawStream) {
|
|
5871
|
+
if (event.type === 'complete') {
|
|
5872
|
+
const model = event.lastModelCall?.model || event.model || event.contextUsage?.model;
|
|
5873
|
+
if (model) {
|
|
5874
|
+
setRunnerModel(model);
|
|
5875
|
+
}
|
|
5876
|
+
}
|
|
5877
|
+
yield event;
|
|
5878
|
+
}
|
|
5879
|
+
};
|
|
5880
|
+
const stream = this.consumeCapsuleWithInput(trackModel(), session, message, turnLease, () => attemptCapsuleId, markFullAccessPromptShown);
|
|
5718
5881
|
// The turn may be superseded while the runner is still creating its
|
|
5719
5882
|
// backend query. Replay the interrupt after runQuery resolves, when
|
|
5720
5883
|
// every runner is required to have an addressable cancellation handle.
|
|
@@ -5797,7 +5960,8 @@ export class ResponseEngine {
|
|
|
5797
5960
|
}, async () => {
|
|
5798
5961
|
if (proactiveCircuitBreakRequested)
|
|
5799
5962
|
await interruptProactiveCircuitBreak();
|
|
5800
|
-
})
|
|
5963
|
+
}, message.source === 'trigger' && !this.isTrustedDaemonTrigger(message)
|
|
5964
|
+
? message.triggerMeta?.noopSentinel : undefined);
|
|
5801
5965
|
streamResult = attemptTimeout
|
|
5802
5966
|
? await Promise.race([processAttempt, attemptTimeout.promise])
|
|
5803
5967
|
: await processAttempt;
|
|
@@ -5973,6 +6137,8 @@ export class ResponseEngine {
|
|
|
5973
6137
|
permissionMode: effectivePermissionMode,
|
|
5974
6138
|
turnLease,
|
|
5975
6139
|
messagePromptContext: fullAccessMessagePromptContext,
|
|
6140
|
+
message,
|
|
6141
|
+
onInputAccepted: markFullAccessPromptShown,
|
|
5976
6142
|
beforeRunQuery: () => this.assertCurrentExecutionAuthorization(permissionContext, agent),
|
|
5977
6143
|
});
|
|
5978
6144
|
}
|
|
@@ -6013,11 +6179,15 @@ export class ResponseEngine {
|
|
|
6013
6179
|
runtimeEnv,
|
|
6014
6180
|
resetTimer,
|
|
6015
6181
|
shouldSuppress,
|
|
6182
|
+
noopSentinel: message.source === 'trigger' && !this.isTrustedDaemonTrigger(message)
|
|
6183
|
+
? message.triggerMeta?.noopSentinel : undefined,
|
|
6016
6184
|
proactive,
|
|
6017
6185
|
proactiveSelfAid: selfAid,
|
|
6018
6186
|
permissionMode: effectivePermissionMode,
|
|
6019
6187
|
turnLease,
|
|
6020
6188
|
messagePromptContext: fullAccessMessagePromptContext,
|
|
6189
|
+
message,
|
|
6190
|
+
onInputAccepted: markFullAccessPromptShown,
|
|
6021
6191
|
beforeRunQuery: () => this.assertCurrentExecutionAuthorization(permissionContext, agent),
|
|
6022
6192
|
});
|
|
6023
6193
|
// 重试后仍然 prompt_too_long:显示友好提示
|
|
@@ -6085,7 +6255,12 @@ export class ResponseEngine {
|
|
|
6085
6255
|
// proactive 模式:agent 主动调用 ctl file 发送文件,跳过标记处理
|
|
6086
6256
|
// [迁移点6] afterProcess:文件标记(interactive)+ Unknown skill 兜底(proactive)
|
|
6087
6257
|
// 由响应模式插件统一处理(InteractiveMode.afterProcess / ProactiveMode.afterProcess)
|
|
6088
|
-
|
|
6258
|
+
const finalReplyText = streamResult.lastReplyText || streamResult.fullText;
|
|
6259
|
+
const visibleFinalReplyText = stripContextLimitErrorLines(finalReplyText);
|
|
6260
|
+
const isNoopReply = !streamResult.isError
|
|
6261
|
+
&& !isExpectedTerminalInterrupt(streamResult.terminalReason)
|
|
6262
|
+
&& isNoopText(visibleFinalReplyText, message.triggerMeta?.noopSentinel || undefined);
|
|
6263
|
+
if (resolvedMode?.mode.afterProcess && !isNoopReply) {
|
|
6089
6264
|
const flusherText = renderer.getFinalText();
|
|
6090
6265
|
const fullText = flusherText.length >= (streamResult.fullText?.length || 0) ? flusherText : streamResult.fullText;
|
|
6091
6266
|
await resolvedMode.mode.afterProcess({
|
|
@@ -6186,7 +6361,7 @@ export class ResponseEngine {
|
|
|
6186
6361
|
logger.info(`[${adapter.channelName}] Sending file via ${targetInfo.adapter.channelName}: ${resolvedPath}`);
|
|
6187
6362
|
try {
|
|
6188
6363
|
const targetReplyContext = isCrossChannel
|
|
6189
|
-
? { delivery: { chatType: 'private' } }
|
|
6364
|
+
? { delivery: { chatType: 'private' }, model: debugRunnerModel }
|
|
6190
6365
|
: capturedReplyContext;
|
|
6191
6366
|
await targetInfo.adapter.send(buildEnvelope({ taskId, channel: targetInfo.adapter.channelName, channelId: targetChannelId, agentName: agentNameForStats, replyContext: targetReplyContext }), { kind: 'result.file', filePath: resolvedPath });
|
|
6192
6367
|
this.eventBus.publish({ type: 'runner:file-sent', sessionId: session.id, filePath: resolvedPath, channel: targetInfo.adapter.channelName });
|
|
@@ -6208,13 +6383,7 @@ export class ResponseEngine {
|
|
|
6208
6383
|
// 最终回复文本:suppressed 模式或无 text 事件时需要兜底添加
|
|
6209
6384
|
// 错误诊断串已通过 system.error 单独发出时置 true,下游跳过 result.error 避免重复
|
|
6210
6385
|
let sentErrorAsSystemError = false;
|
|
6211
|
-
const finalReplyText = streamResult.lastReplyText || streamResult.fullText;
|
|
6212
|
-
const visibleFinalReplyText = stripContextLimitErrorLines(finalReplyText);
|
|
6213
6386
|
const streamRawErrorText = getStreamRawErrorText(streamResult, visibleFinalReplyText || undefined);
|
|
6214
|
-
const isTriggerNoop = message.source === 'trigger'
|
|
6215
|
-
&& typeof message.triggerMeta?.noopSentinel === 'string'
|
|
6216
|
-
&& message.triggerMeta.noopSentinel.length > 0
|
|
6217
|
-
&& visibleFinalReplyText.trim() === message.triggerMeta.noopSentinel;
|
|
6218
6387
|
if (!this.turnCoordinator.isCurrent(turnLease)) {
|
|
6219
6388
|
agent.cleanupStream(streamKey, turnLease ? { taskId: turnLease.taskId, generation: turnLease.generation } : undefined);
|
|
6220
6389
|
this.sessionManager.clearProcessingIfTask(session.id, taskId);
|
|
@@ -6230,11 +6399,13 @@ export class ResponseEngine {
|
|
|
6230
6399
|
const terminalInterrupt = isExpectedStreamInterrupt(streamResult.terminalReason, this.interruptedSessions.get(session.id));
|
|
6231
6400
|
const streamRecoverable = !permissionTerminalFailure
|
|
6232
6401
|
&& !isExpectedTerminalInterrupt(streamResult.terminalReason)
|
|
6233
|
-
&&
|
|
6402
|
+
&& (isRecoverableProtocolFailure(streamResult.subtype, streamResult.protocolIncompleteReason)
|
|
6403
|
+
|| isRetryableError(new Error(getStreamErrorText(streamResult))));
|
|
6234
6404
|
sentErrorAsSystemError = await projectTerminalReply({
|
|
6235
6405
|
isCurrent: () => !turnLease || this.turnCoordinator.canPublish(turnLease),
|
|
6236
6406
|
isInterrupted: () => terminalInterrupt || isNonErrorInterruptReason(this.interruptedSessions.get(session.id)),
|
|
6237
|
-
isNoop:
|
|
6407
|
+
isNoop: isNoopReply,
|
|
6408
|
+
discardText: () => renderer.discardPendingText(),
|
|
6238
6409
|
isError: streamResult.isError,
|
|
6239
6410
|
text: visibleFinalReplyText,
|
|
6240
6411
|
diagnosticText: streamResult.syntheticDiagnosticText,
|
|
@@ -6269,7 +6440,7 @@ export class ResponseEngine {
|
|
|
6269
6440
|
logger.info(`[ResponseEngine] task.finished: session=${session.id} task=${taskId} outcome=${terminalInterrupt ? 'interrupted' : streamResult.isError ? 'error' : 'completed'}`);
|
|
6270
6441
|
import('../../utils/msg-diag.js').then(m => m.diagLog('task_done', { aid: session.selfAID ?? '', msgId: message.messageId ?? '', taskId, text: message.content ?? '' })).catch(() => { });
|
|
6271
6442
|
// 降级模型回复末尾追加标记(代码层硬注入,不依赖模型输出)
|
|
6272
|
-
if (usedFallback) {
|
|
6443
|
+
if (usedFallback && !isNoopReply) {
|
|
6273
6444
|
const curFbState = this.modelFallbackMap.get(session.id);
|
|
6274
6445
|
const showHint = curFbState && curFbState.nextProbeAt >= 8 && !curFbState.hintShown;
|
|
6275
6446
|
const suffix = showHint
|
|
@@ -7171,12 +7342,8 @@ export class ResponseEngine {
|
|
|
7171
7342
|
}
|
|
7172
7343
|
if (totalTokens <= 0)
|
|
7173
7344
|
return undefined;
|
|
7174
|
-
// 单次请求的上下文不可能超过模型窗口。超过(留 5% 余量容纳输出侧计数)
|
|
7175
|
-
// 说明这行记的不是单次上下文,而是整轮累计用量——历史行里出现过
|
|
7176
|
-
// cache_read 被累加成 119 万的记录,它会让自动压缩在每个任务开始时
|
|
7177
|
-
// 重复触发。这类行一律不参与压缩判断。
|
|
7178
7345
|
const maxTokens = row.max_tokens ?? 0;
|
|
7179
|
-
if (maxTokens > 0 && totalTokens > maxTokens * 1.05) {
|
|
7346
|
+
if (!(recordedTotalTokens && recordedTotalTokens > 0) && maxTokens > 0 && totalTokens > maxTokens * 1.05) {
|
|
7180
7347
|
logger.warn(`[ResponseEngine] Ignoring implausible context_tokens: session=${sessionId} totalTokens=${totalTokens} maxTokens=${maxTokens}`);
|
|
7181
7348
|
return undefined;
|
|
7182
7349
|
}
|
|
@@ -7335,15 +7502,23 @@ export class ResponseEngine {
|
|
|
7335
7502
|
};
|
|
7336
7503
|
}
|
|
7337
7504
|
/** Only backend acceptance, never a log write or startup status, consumes context. */
|
|
7338
|
-
async *consumeCapsuleWithInput(stream, session, message, lease, capsuleIdForAttempt) {
|
|
7505
|
+
async *consumeCapsuleWithInput(stream, session, message, lease, capsuleIdForAttempt, onInputAccepted) {
|
|
7339
7506
|
let accepted = false;
|
|
7340
7507
|
let consumed = false;
|
|
7508
|
+
let noticeConsumed = false;
|
|
7341
7509
|
for await (const event of stream) {
|
|
7342
7510
|
if (!lease || this.turnCoordinator.isCurrent(lease)) {
|
|
7343
7511
|
if (event.type === 'input_accepted' && (!lease || event.inputId === lease.inputId))
|
|
7344
7512
|
accepted = true;
|
|
7345
7513
|
if ((event.type === 'text' && !event.synthetic && !!event.text.trim()) || event.type === 'tool_use')
|
|
7346
7514
|
accepted = true;
|
|
7515
|
+
// A successful result is also acceptance evidence for runners that
|
|
7516
|
+
// return only a complete event. Startup errors must not spend the notice.
|
|
7517
|
+
const completedWithResult = event.type === 'complete' && !event.isError && !!event.result?.trim();
|
|
7518
|
+
if (!noticeConsumed && (accepted || completedWithResult) && onInputAccepted) {
|
|
7519
|
+
await onInputAccepted();
|
|
7520
|
+
noticeConsumed = true;
|
|
7521
|
+
}
|
|
7347
7522
|
const capsuleId = capsuleIdForAttempt();
|
|
7348
7523
|
if (accepted && !consumed && capsuleId && this.sessionManager.consumeSessionCapsule) {
|
|
7349
7524
|
const current = await this.sessionManager.getSessionById(session.id);
|
|
@@ -7368,7 +7543,7 @@ export class ResponseEngine {
|
|
|
7368
7543
|
*/
|
|
7369
7544
|
async processEventStream(stream, session, agent, renderer, resetTimer, shouldSuppress, proactive,
|
|
7370
7545
|
/** [迁移点4/5] 响应模式插件 + 状态,用于调 onToolUse/onComplete 钩子 */
|
|
7371
|
-
modeHooks, causation, turnLease, permissionMode, proactiveSelfAid, onAsyncQuestion, onToolCallsSettled) {
|
|
7546
|
+
modeHooks, causation, turnLease, permissionMode, proactiveSelfAid, onAsyncQuestion, onToolCallsSettled, noopSentinel) {
|
|
7372
7547
|
// Per-session agent name for stats bucketing
|
|
7373
7548
|
const statsChannelKey = session.channel === 'daemon' ? session.channel : (session.metadata?.channelKey || session.channel);
|
|
7374
7549
|
const agentNameForStats = this.agentRegistry?.resolveByChannel(statsChannelKey)?.name ?? '<unknown>';
|
|
@@ -7409,6 +7584,26 @@ export class ResponseEngine {
|
|
|
7409
7584
|
};
|
|
7410
7585
|
// 追踪最后一轮 assistant 回复文本(tool_use 之后的纯文本)
|
|
7411
7586
|
let lastReplyText = '';
|
|
7587
|
+
let pendingTriggerText = '';
|
|
7588
|
+
let triggerTextDecision = 'pending';
|
|
7589
|
+
const projectTriggerText = (text, boundary = false) => {
|
|
7590
|
+
if (!noopSentinel || triggerTextDecision === 'visible')
|
|
7591
|
+
return text;
|
|
7592
|
+
if (triggerTextDecision === 'noop')
|
|
7593
|
+
return '';
|
|
7594
|
+
pendingTriggerText += text;
|
|
7595
|
+
if (isTriggerNoopText(pendingTriggerText, noopSentinel)) {
|
|
7596
|
+
triggerTextDecision = 'noop';
|
|
7597
|
+
pendingTriggerText = '';
|
|
7598
|
+
return '';
|
|
7599
|
+
}
|
|
7600
|
+
if (!boundary && noopSentinel.startsWith(pendingTriggerText.trimStart()))
|
|
7601
|
+
return '';
|
|
7602
|
+
triggerTextDecision = 'visible';
|
|
7603
|
+
const visible = pendingTriggerText;
|
|
7604
|
+
pendingTriggerText = '';
|
|
7605
|
+
return visible;
|
|
7606
|
+
};
|
|
7412
7607
|
// 上游合成错误帧的原文(runner 标记 synthetic 的 text)。与正文通道分开存放:
|
|
7413
7608
|
// 它只能作为终态错误文案的来源,不得进入 lastReplyText / 投影 / hasReceivedText。
|
|
7414
7609
|
let syntheticDiagnosticText = '';
|
|
@@ -7615,7 +7810,32 @@ export class ResponseEngine {
|
|
|
7615
7810
|
diagnosticSuffix = formatToolInputDiagnostics(diagnoseToolInputAfterFailure(original, event));
|
|
7616
7811
|
projectedEvent = { ...event, error: getToolResultErrorText(event) + diagnosticSuffix };
|
|
7617
7812
|
}
|
|
7618
|
-
|
|
7813
|
+
// Decide before either interactive text or proactive thoughts can escape.
|
|
7814
|
+
// The prefix may span multiple provider chunks; retain raw text for audit.
|
|
7815
|
+
let projectedText;
|
|
7816
|
+
if (noopSentinel && event.type === 'text' && !event.synthetic) {
|
|
7817
|
+
projectedText = projectTriggerText(stripContextLimitErrorLines(event.text));
|
|
7818
|
+
projectedEvent = { ...event, text: projectedText };
|
|
7819
|
+
}
|
|
7820
|
+
else if (noopSentinel && (event.type === 'tool_use' || event.type === 'complete')) {
|
|
7821
|
+
const pendingText = projectTriggerText('', true);
|
|
7822
|
+
if (pendingText) {
|
|
7823
|
+
renderer.emit({ type: 'text', text: pendingText });
|
|
7824
|
+
this.eventBus.publish({ type: 'message:text', sessionId: session.id, text: pendingText, isFinal: false });
|
|
7825
|
+
if (!shouldSuppress()) {
|
|
7826
|
+
await renderer.addText(pendingText, undefined, undefined, assistantUuid);
|
|
7827
|
+
hasProjectedCurrentReplyText = true;
|
|
7828
|
+
}
|
|
7829
|
+
}
|
|
7830
|
+
if (event.type === 'tool_use') {
|
|
7831
|
+
triggerTextDecision = 'pending';
|
|
7832
|
+
pendingTriggerText = '';
|
|
7833
|
+
}
|
|
7834
|
+
}
|
|
7835
|
+
const suppressNoopProjection = event.type === 'text' && projectedText === ''
|
|
7836
|
+
|| event.type === 'complete' && !event.isError
|
|
7837
|
+
&& isTriggerNoopText(lastReplyText || event.result || '', noopSentinel);
|
|
7838
|
+
renderer.emit(projectedEvent, suppressNoopProjection);
|
|
7619
7839
|
if (event.type === 'text_start') {
|
|
7620
7840
|
await renderer.sendTextStart(event.contentIndex, event.turn);
|
|
7621
7841
|
continue;
|
|
@@ -7793,7 +8013,7 @@ export class ResponseEngine {
|
|
|
7793
8013
|
else {
|
|
7794
8014
|
// 网关偶尔会把上下文超限错误伪装成普通 text event。不要向事件总线或
|
|
7795
8015
|
// 渲染器投影错误行;lastReplyText 仍保留原文本,以便流结束后触发恢复。
|
|
7796
|
-
const visibleText = stripContextLimitErrorLines(event.text);
|
|
8016
|
+
const visibleText = projectedText ?? stripContextLimitErrorLines(event.text);
|
|
7797
8017
|
if (visibleText) {
|
|
7798
8018
|
hasReceivedText = true;
|
|
7799
8019
|
if (visibleText.trim())
|