evolcore 0.0.43-test.1 → 0.0.43-test.2
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 +24 -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 +26 -9
- package/dist/agents/gemini-runner.js +15 -12
- package/dist/agents/tool-time-context.js +55 -0
- package/dist/aun/menu/client.js +1 -1
- package/dist/aun/model-headers.js +17 -0
- package/dist/aun/msg/p2p.js +3 -0
- package/dist/channels/aun.js +484 -43
- package/dist/channels/builtin-plugins.js +16 -11
- 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 +22 -6
- package/dist/cli/agent.js +1 -79
- package/dist/cli/aun-commands.js +1 -0
- 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 +77 -64
- 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 +1 -1
- 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/thread-command.js +1 -1
- package/dist/cli/watch-msg.js +1 -1
- package/dist/config/access-policy.js +1 -0
- package/dist/config/config-field-policy.js +2 -2
- package/dist/config/config-manager.js +7 -0
- package/dist/config/role-schema.js +4 -3
- package/dist/config/role-service.js +3 -3
- package/dist/config-store.js +75 -4
- package/dist/core/agent-ipc-registration.js +16 -59
- package/dist/core/auth/authorization-audit.js +52 -14
- package/dist/core/auth/operation-authorizer.js +0 -11
- package/dist/core/auth/operation-catalog.js +0 -18
- package/dist/core/channel-loader.js +152 -16
- package/dist/core/command/agent-control.js +2 -1
- package/dist/core/command/cli-intent-parser.js +0 -8
- package/dist/core/command/command-handler.js +17 -46
- package/dist/core/command/connect-menu.js +7 -3
- package/dist/core/command/menu-catalog.js +3 -2
- package/dist/core/command/menu-handler.js +51 -8
- package/dist/core/command/menu-protocol.js +20 -0
- package/dist/core/command/slash-handler.js +101 -40
- package/dist/core/daemon-file-cache.js +3 -3
- package/dist/core/evolagent-registry.js +5 -4
- package/dist/core/evolagent.js +5 -8
- 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/memory/consolidation.js +8 -1
- package/dist/core/memory/relation-sweep.js +20 -8
- package/dist/core/message/aun-ipc-sender.js +28 -1
- package/dist/core/message/contact-admission.js +548 -0
- package/dist/core/message/im-renderer.js +69 -10
- package/dist/core/message/message-admission.js +28 -3
- package/dist/core/message/message-bridge.js +46 -5
- package/dist/core/message/message-utils.js +0 -5
- package/dist/core/message/peer-mode.js +44 -10
- package/dist/core/message/response-engine.js +268 -69
- package/dist/core/message/retry-scheduler.js +4 -0
- package/dist/core/permission/ec-command-parser.js +1 -28
- package/dist/core/permission/readonly-shell-query.js +34 -8
- package/dist/core/permission/tool-policy.js +50 -5
- package/dist/core/role/runtime-policy.js +14 -2
- 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/directory/contact-admission-paths.js +9 -0
- package/dist/directory/owner-directory-admission.js +128 -29
- package/dist/directory/owner-directory-cache.js +364 -50
- package/dist/directory/owner-directory-identity.js +60 -0
- package/dist/directory/owner-directory-markdown.js +120 -47
- package/dist/directory/owner-directory-policy.js +108 -0
- package/dist/directory/owner-directory-query-operation.js +219 -32
- package/dist/directory/owner-directory-remarks.js +29 -2
- package/dist/directory/owner-directory-search.js +50 -18
- package/dist/directory/owner-directory-store.js +150 -30
- package/dist/eck/kit-renderer.js +12 -5
- package/dist/eck/manifest-engine.js +55 -6
- package/dist/eck/message-renderer.js +5 -2
- package/dist/eck/paactive-context.js +45 -0
- package/dist/ecweb/basic-settings-service.js +2 -2
- package/dist/ecweb/message-context-service.js +24 -16
- package/dist/index.js +9 -5
- package/dist/ipc.js +1 -1
- package/dist/paths.js +26 -0
- package/dist/response-system/config-resolver.js +1 -1
- package/dist/response-system/engines/v1/index.js +4 -1
- package/dist/response-system/engines/v1/paactive-flow.js +18 -0
- package/dist/response-system/modes/single-session/index.js +7 -2
- package/dist/trigger/scheduler.js +3 -5
- package/dist/trigger/validation.js +4 -0
- package/dist/utils/error-utils.js +5 -2
- 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/dist/agent-loop.js +43 -1
- package/kits/docs/INDEX.md +1 -0
- package/kits/docs/context-assembly.md +21 -6
- package/kits/docs/eck_templates/INDEX.template.md +1 -2
- package/kits/docs/evolcore/INDEX.md +1 -1
- package/kits/docs/evolcore/agent-create.md +5 -5
- package/kits/docs/evolcore/agent.md +4 -9
- package/kits/docs/evolcore/directory.md +137 -0
- package/kits/docs/evolcore/menu-protocol.md +55 -0
- package/kits/docs/evolcore/response.md +7 -1
- package/kits/docs/evolcore/tool-authorization.md +1 -1
- package/kits/docs/evolcore/trigger.md +4 -0
- package/kits/docs/prompt-loading-architecture.md +6 -2
- package/kits/eck_manifest.auxiliary.json +1 -0
- package/kits/eck_manifest.json +57 -4
- package/kits/eck_manifest.memory.json +67 -3
- package/kits/eck_manifest.paactive.json +528 -0
- package/kits/eck_message_manifest.paactive.json +233 -0
- 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 +31 -3
- package/kits/schemas/agent-config.schema.18.json +5 -0
- package/kits/schemas/agent-config.schema.19.json +924 -0
- package/kits/schemas/relation-config.schema.12.json +289 -0
- package/kits/schemas/role-config.schema.2.json +215 -0
- 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/message-fragments/paactive/item.md +3 -0
- package/kits/templates/soul/00-GUIDE.md +61 -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/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/paactive/channel.md +25 -0
- package/kits/templates/system-fragments/paactive/reply.md +25 -0
- package/kits/templates/system-fragments/paactive/session.md +32 -0
- package/kits/templates/system-fragments/personal-assistant.md +65 -0
- 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
|
@@ -18,6 +18,8 @@ import { projectSubtaskStarted, projectSubtaskTerminal } from './subtask-tool-pr
|
|
|
18
18
|
import { TaskActivityStore } from '../task/task-activity-store.js';
|
|
19
19
|
import { createSendFileMarkerPattern } from './file-markers.js';
|
|
20
20
|
import { hasOwnerDirectoryMarkdown } from '../../directory/owner-directory-markdown.js';
|
|
21
|
+
import { EMPTY_IDENTITY, readOwnerDirectoryIdentity } from '../../directory/owner-directory-identity.js';
|
|
22
|
+
import { resolveContactsState } from '../../directory/owner-directory-policy.js';
|
|
21
23
|
import { createDecisionInferenceProvider, createTextInferenceProvider } from '../inference/text-inference.js';
|
|
22
24
|
import { StreamIdleMonitor } from './stream-idle-monitor.js';
|
|
23
25
|
import { logger } from '../../utils/logger.js';
|
|
@@ -28,7 +30,7 @@ import { describeProactiveSendCommandFailure, isExactEvolcoreSendCommandForSessi
|
|
|
28
30
|
import { resolveThreadRouteTarget } from '../thread/thread-route.js';
|
|
29
31
|
import { isMainSession, isTopicSession, isTopicThreadId, sessionLocalTopicId, sessionTopicThreadId } from '../thread/topic-id.js';
|
|
30
32
|
import { summarizeToolInputForDisplay, toolInputForDisplay } from '../../utils/tool-summary.js';
|
|
31
|
-
import { agentDataDir, agentDir as resolveAgentDir, agentMdPath, getPackageRoot, resolveRoot, resolvePaths, debugSessionsDir } from '../../paths.js';
|
|
33
|
+
import { agentDataDir, agentDir as resolveAgentDir, agentMdPath, agentSoulDir, getPackageRoot, resolveRoot, resolvePaths, debugSessionsDir } from '../../paths.js';
|
|
32
34
|
import { renderKitSections, resolveSessionManifest, DEFAULT_MANIFEST_FILE } from '../../eck/kit-renderer.js';
|
|
33
35
|
import { renderMessageBody } from '../../eck/message-renderer.js';
|
|
34
36
|
import { syncGroupRulesContext } from '../../eck/group-rules-sync.js';
|
|
@@ -39,7 +41,8 @@ import { normalizeBaseagent, resolveBaseagentModelSelection, resolveRuntimeBasea
|
|
|
39
41
|
import { renderActionAsText } from '../interaction-router.js';
|
|
40
42
|
import { formatPeerKey, parsePeerKey } from '../relation/peer-identity.js';
|
|
41
43
|
import { buildEnvelope, isInteractionSendAccepted, replyContextFromSession, sendInteractionPayload, withEnvelopeReplyContext } from './message-utils.js';
|
|
42
|
-
import { isSystemOrServicePeer, resolveChatMode } from './peer-mode.js';
|
|
44
|
+
import { chatModeForScene, isSystemOrServicePeer, resolveChatMode } from './peer-mode.js';
|
|
45
|
+
import { buildPaactiveSystemVars, buildPaactiveMessageVars, paactiveSystemManifest } from '../../eck/paactive-context.js';
|
|
43
46
|
import { AGENT_DELEGATION_TOKEN_ENV } from '../auth/agent-delegation.js';
|
|
44
47
|
import { hasTrustedPrincipal } from '../auth/authenticated-actor.js';
|
|
45
48
|
import { isValidAid } from '../../aun/aid/identity.js';
|
|
@@ -47,8 +50,8 @@ import { isValidAid } from '../../aun/aid/identity.js';
|
|
|
47
50
|
export { buildEnvelope, sendInteractionPayload } from './message-utils.js';
|
|
48
51
|
import { constrainResolvedModelForRole, isModelAllowedForRoleBaseagent } from '../model/model-permission.js';
|
|
49
52
|
import { eligibleFallbackModels } from '../model/model-fallback.js';
|
|
50
|
-
import { RetryScheduler } from './retry-scheduler.js';
|
|
51
|
-
import { assertSessionFullAccessAuthorization, constrainRuntimePermissionMode, resolveRuntimeStringField } from '../role/runtime-policy.js';
|
|
53
|
+
import { isRecoverableProtocolFailure, RetryScheduler } from './retry-scheduler.js';
|
|
54
|
+
import { assertSessionFullAccessAuthorization, constrainRuntimePermissionMode, readSessionFullAccessOverride, resolveRuntimeStringField, updateRelationSessionFullAccess } from '../role/runtime-policy.js';
|
|
52
55
|
import { resolveEffective, resolveEffectiveFieldWithSource } from '../../config/config-manager.js';
|
|
53
56
|
import { resolveAgentLifecycle } from '../../config/lifecycle.js';
|
|
54
57
|
import { authorizationConfigRevision, checkRoleAccess, getFirstStaticAgentOwner, listStaticAgentAdmins, listStaticAgentOwners, resolvePeerRoleDetail, roleToSessionIdentity, } from '../../config/peer-role-resolver.js';
|
|
@@ -64,6 +67,7 @@ import { registerBuiltinModes } from '../../response-system/modes/index.js';
|
|
|
64
67
|
import { deriveSessionTitle, shouldAutoFillSessionTitle } from '../session/session-title.js';
|
|
65
68
|
import { SessionTurnCoordinator } from '../session/session-turn-coordinator.js';
|
|
66
69
|
import { recordTriggerExecutionAnomaly } from '../../trigger/anomaly-store.js';
|
|
70
|
+
import { isTriggerNoopText } from '../../trigger/validation.js';
|
|
67
71
|
import { normalizeToolErrorClassification } from '../permission/tool-error-code.js';
|
|
68
72
|
import { normalizeExecutionPermissionMode } from '../permission/mode.js';
|
|
69
73
|
import { buildToolLifecycleEventKey } from '../audit/event-key.js';
|
|
@@ -1112,8 +1116,12 @@ export function isExpectedStreamInterrupt(terminalReason, interruptReason) {
|
|
|
1112
1116
|
return isExpectedTerminalInterrupt(terminalReason) || isNonErrorInterruptReason(interruptReason);
|
|
1113
1117
|
}
|
|
1114
1118
|
export async function projectTerminalReply(projection) {
|
|
1115
|
-
if (!projection.isCurrent() || projection.isInterrupted()
|
|
1119
|
+
if (!projection.isCurrent() || projection.isInterrupted())
|
|
1116
1120
|
return false;
|
|
1121
|
+
if (projection.isNoop) {
|
|
1122
|
+
projection.discardText();
|
|
1123
|
+
return false;
|
|
1124
|
+
}
|
|
1117
1125
|
if (projection.isError) {
|
|
1118
1126
|
return projection.text || projection.diagnosticText ? projection.sendError() : false;
|
|
1119
1127
|
}
|
|
@@ -1182,10 +1190,9 @@ function withFallbackModel(override, candidate) {
|
|
|
1182
1190
|
};
|
|
1183
1191
|
}
|
|
1184
1192
|
/**
|
|
1185
|
-
* Keep the
|
|
1186
|
-
*
|
|
1187
|
-
*
|
|
1188
|
-
* execution-mode signal for the privileged task.
|
|
1193
|
+
* Keep the existing notice in the user-message prompt: every one-shot task,
|
|
1194
|
+
* once per locally enabled EC session, and never for global policy or Triggers.
|
|
1195
|
+
* This leaves the long-lived system/developer prompt cache unchanged.
|
|
1189
1196
|
*/
|
|
1190
1197
|
const FULL_ACCESS_MESSAGE_PROMPT_CONTEXT = '【当前权限模式提升为fullaccess,可不受限制执行命令,仅当前轮 task 有效】';
|
|
1191
1198
|
/**
|
|
@@ -1521,12 +1528,16 @@ export class ResponseEngine {
|
|
|
1521
1528
|
? (session.metadata?.groupId || channelId)
|
|
1522
1529
|
: (session.metadata?.peerId || channelId);
|
|
1523
1530
|
const peerKey = channelType && peerKeyId ? formatPeerKey(channelType, peerKeyId) : undefined;
|
|
1531
|
+
const agent = this.agentRegistry?.resolveByChannel(channelKey);
|
|
1524
1532
|
return resolveChatMode({
|
|
1525
1533
|
self: self || undefined,
|
|
1526
1534
|
peerKey,
|
|
1527
1535
|
role: session.identity?.role,
|
|
1528
1536
|
chatType: session.chatType,
|
|
1529
1537
|
peerType,
|
|
1538
|
+
channelType,
|
|
1539
|
+
lifecycle: agent ? resolveAgentLifecycle(agent.config) : undefined,
|
|
1540
|
+
sessionType: session.sessionType ?? session.metadata?.sessionType ?? 'main',
|
|
1530
1541
|
});
|
|
1531
1542
|
}
|
|
1532
1543
|
catch {
|
|
@@ -2454,7 +2465,7 @@ export class ResponseEngine {
|
|
|
2454
2465
|
return true;
|
|
2455
2466
|
}
|
|
2456
2467
|
async retryAfterContextRecovery(prompt, opts) {
|
|
2457
|
-
const { streamKey, renderer, agent, session, absoluteProjectPath, effectiveSystemPrompt, modelOverride, runtimeEnv, resetTimer, shouldSuppress, proactive, turnLease, beforeRunQuery, messagePromptContext, } = opts;
|
|
2468
|
+
const { streamKey, renderer, agent, session, absoluteProjectPath, effectiveSystemPrompt, modelOverride, runtimeEnv, resetTimer, shouldSuppress, proactive, turnLease, beforeRunQuery, messagePromptContext, onInputAccepted, } = opts;
|
|
2458
2469
|
if (!session.agentSessionId || !canCompactAgent(agent)) {
|
|
2459
2470
|
throw new Error('CONTEXT_COMPACT_FAILED');
|
|
2460
2471
|
}
|
|
@@ -2494,7 +2505,8 @@ export class ResponseEngine {
|
|
|
2494
2505
|
await this.emitOperationalNotice(renderer, '✅ 压缩完成,继续处理...', 'info', 'compact-retry');
|
|
2495
2506
|
await renderer.flush();
|
|
2496
2507
|
await beforeRunQuery?.();
|
|
2497
|
-
const
|
|
2508
|
+
const rawRetryStream = await agent.runQuery(session.id, insertMessagePromptContext(prompt, messagePromptContext), absoluteProjectPath, session.agentSessionId, undefined, effectiveSystemPrompt, this.sessionManager, recoveryModelOverride, runtimeEnv);
|
|
2509
|
+
const retryStream = this.consumeCapsuleWithInput(rawRetryStream, session, opts.message, turnLease, () => undefined, onInputAccepted);
|
|
2498
2510
|
if (await this.cancelStaleRunnerStart(agent, session.id, streamKey, turnLease, turnLease.taskId)) {
|
|
2499
2511
|
throw new Error('RUNNER_START_SUPERSEDED');
|
|
2500
2512
|
}
|
|
@@ -2503,7 +2515,7 @@ export class ResponseEngine {
|
|
|
2503
2515
|
generation: turnLease.generation,
|
|
2504
2516
|
});
|
|
2505
2517
|
return await this.processEventStream(retryStream, session, agent, renderer, resetTimer, shouldSuppress, proactive, undefined, // 重试分支不调插件钩子
|
|
2506
|
-
undefined, turnLease, opts.permissionMode, opts.proactiveSelfAid);
|
|
2518
|
+
undefined, turnLease, opts.permissionMode, opts.proactiveSelfAid, undefined, undefined, opts.noopSentinel);
|
|
2507
2519
|
}
|
|
2508
2520
|
if (compactResult && typeof compactResult === 'object' && compactResult.message) {
|
|
2509
2521
|
logger.warn(`[ResponseEngine] Context compact failed: ${compactResult.message}`);
|
|
@@ -3710,6 +3722,13 @@ export class ResponseEngine {
|
|
|
3710
3722
|
// trigger override 绝对优先;否则由 Coordinator 解析(responseMode 标量 > 注册表首选)。
|
|
3711
3723
|
const systemOrServicePeer = isSystemOrServicePeer(peerType);
|
|
3712
3724
|
const triggerChatModeOverride = systemOrServicePeer ? undefined : message.triggerMeta?.chatModeOverride;
|
|
3725
|
+
const previousTurn = this.turnCoordinator.current(session);
|
|
3726
|
+
const recoveryChatMode = (message.taskRecovery || message.restartResume?.submitted)
|
|
3727
|
+
? (previousTurn.active ?? previousTurn.lastTerminal)?.recoveryContext?.chatmode
|
|
3728
|
+
: undefined;
|
|
3729
|
+
// Preserve PA's explicit-reply contract across recovery. The existing
|
|
3730
|
+
// interactive/proactive recovery and override rules remain authoritative.
|
|
3731
|
+
const taskChatModeOverride = recoveryChatMode === 'paactive' ? recoveryChatMode : triggerChatModeOverride;
|
|
3713
3732
|
// chatmode 是顶层字典(agent 级与关系级同名,已由 ConfigManager 逐键合并)。
|
|
3714
3733
|
// 实际生效值由对端类型选键(private/nothuman/group),出厂默认走 schema。
|
|
3715
3734
|
const chatModeFallback = resolveChatMode({
|
|
@@ -3718,14 +3737,25 @@ export class ResponseEngine {
|
|
|
3718
3737
|
role: peerRole,
|
|
3719
3738
|
chatType,
|
|
3720
3739
|
peerType,
|
|
3740
|
+
channelType: currentChannelType,
|
|
3741
|
+
lifecycle,
|
|
3742
|
+
sessionType: session.sessionType ?? session.metadata?.sessionType ?? 'main',
|
|
3721
3743
|
});
|
|
3744
|
+
// Resolve overrides before binding a flow so hooks, context and envelope
|
|
3745
|
+
// all use the same scene-checked mode for this task.
|
|
3746
|
+
const effectiveChatMode = systemOrServicePeer
|
|
3747
|
+
? 'interactive'
|
|
3748
|
+
: taskChatModeOverride
|
|
3749
|
+
? chatModeForScene(taskChatModeOverride, { channelType: currentChannelType, chatType, peerType, role: peerRole, lifecycle, sessionType: session.sessionType ?? session.metadata?.sessionType ?? 'main' })
|
|
3750
|
+
: chatModeFallback;
|
|
3722
3751
|
const responseModeAgentDir = selfAid ? resolveAgentDir(selfAid) : undefined;
|
|
3723
3752
|
// mentionMode:顶层通用参数(先读出备用,投递/入队策略后续接入)
|
|
3724
3753
|
const mentionMode = effectiveAgentConfig?.mentionMode ?? 'disabled';
|
|
3725
|
-
const resolvedMode = triggerChatModeOverride
|
|
3726
|
-
|
|
3754
|
+
const resolvedMode = (triggerChatModeOverride && effectiveChatMode !== 'paactive')
|
|
3755
|
+
|| systemOrServicePeer || !responseModeAgentDir
|
|
3756
|
+
? null
|
|
3727
3757
|
: this.responseCoordinator.resolveMode(effectiveAgentConfig?.responseMode, // 标量:关系级>agent级>注册表首选
|
|
3728
|
-
|
|
3758
|
+
effectiveChatMode, effectiveAgentConfig?.responseModeParams, // 按模式分桶的参数字典
|
|
3729
3759
|
{
|
|
3730
3760
|
session,
|
|
3731
3761
|
agentConfig: effectiveAgentConfig,
|
|
@@ -3745,19 +3775,15 @@ export class ResponseEngine {
|
|
|
3745
3775
|
agentDir: responseModeAgentDir,
|
|
3746
3776
|
});
|
|
3747
3777
|
if (resolvedMode) {
|
|
3748
|
-
logger.info('[ResponseSystem] selected mode=' + resolvedMode.mode.id + ' source=' + resolvedMode.source + ' chatType=' + chatType + ' peerKey=' + (peerKey ?? 'none') + ' chatMode=' +
|
|
3778
|
+
logger.info('[ResponseSystem] selected mode=' + resolvedMode.mode.id + ' source=' + resolvedMode.source + ' chatType=' + chatType + ' peerKey=' + (peerKey ?? 'none') + ' chatMode=' + effectiveChatMode);
|
|
3749
3779
|
}
|
|
3750
3780
|
else {
|
|
3751
|
-
logger.info('[ResponseSystem] selected mode=override/fallback source=trigger-or-resolve-failed chatType=' + chatType + ' peerKey=' + (peerKey ?? 'none') + ' chatMode=' +
|
|
3781
|
+
logger.info('[ResponseSystem] selected mode=override/fallback source=trigger-or-resolve-failed chatType=' + chatType + ' peerKey=' + (peerKey ?? 'none') + ' chatMode=' + effectiveChatMode);
|
|
3752
3782
|
}
|
|
3753
3783
|
// 最终 chatMode(怎么投递,与「选哪个模式」正交):
|
|
3754
3784
|
// system/service 运行时硬约束 > trigger override > 配置层级解析(chatModeFallback)。
|
|
3755
3785
|
// 注:mode.id 不再参与——单会话合并后 mode.id 恒为 single-session,
|
|
3756
3786
|
// chatMode 由 resolveChatModeForPeer 按配置层级解析(步骤 1/4)。
|
|
3757
|
-
const effectiveChatMode = systemOrServicePeer
|
|
3758
|
-
? 'interactive'
|
|
3759
|
-
: triggerChatModeOverride
|
|
3760
|
-
?? chatModeFallback;
|
|
3761
3787
|
const chatmode = effectiveChatMode;
|
|
3762
3788
|
const isProactive = effectiveChatMode === 'proactive';
|
|
3763
3789
|
const legacyMiddleOutputMode = () => {
|
|
@@ -3782,12 +3808,15 @@ export class ResponseEngine {
|
|
|
3782
3808
|
{
|
|
3783
3809
|
import('../../utils/msg-diag.js').then(m => m.diagLog('task_created', { aid: session.selfAID ?? '', msgId: message.messageId ?? '', taskId, text: message.content ?? '' })).catch(() => { });
|
|
3784
3810
|
}
|
|
3811
|
+
// Per-turn attempt state; configuration changes cannot mutate this model.
|
|
3812
|
+
let debugRunnerModel;
|
|
3785
3813
|
// 构建带 taskId/chatmode 的 ReplyContext(本次任务所有出站消息共用)
|
|
3786
3814
|
const taskReplyContext = () => {
|
|
3787
3815
|
const base = this.getReplyContext(message);
|
|
3788
3816
|
return {
|
|
3789
3817
|
...replyContextFromSession(session, base),
|
|
3790
3818
|
sessionId: session.id,
|
|
3819
|
+
model: debugRunnerModel,
|
|
3791
3820
|
threadId: sessionTopicThreadId(session) ?? base?.threadId,
|
|
3792
3821
|
metadata: withTaskMetadata(base?.metadata),
|
|
3793
3822
|
};
|
|
@@ -3852,7 +3881,7 @@ export class ResponseEngine {
|
|
|
3852
3881
|
channel: message.channel,
|
|
3853
3882
|
channelId: message.channelId,
|
|
3854
3883
|
agentName: agentNameForStats,
|
|
3855
|
-
chatmode:
|
|
3884
|
+
chatmode: effectiveChatMode,
|
|
3856
3885
|
replyContext: taskReplyContext(),
|
|
3857
3886
|
causation: taskCausation,
|
|
3858
3887
|
});
|
|
@@ -4187,6 +4216,7 @@ export class ResponseEngine {
|
|
|
4187
4216
|
? aunMessageTranscriptUuid(sourceMessageId)
|
|
4188
4217
|
: undefined;
|
|
4189
4218
|
turnLease = await this.turnCoordinator.begin(session, taskId, inputId, configActorId ? {
|
|
4219
|
+
...(effectiveChatMode === 'paactive' ? { chatmode: effectiveChatMode } : {}),
|
|
4190
4220
|
peerId: configActorId,
|
|
4191
4221
|
approvalInteractionPolicy,
|
|
4192
4222
|
encrypted: message.encrypted ?? message.replyContext?.metadata?.encrypted,
|
|
@@ -4233,9 +4263,6 @@ export class ResponseEngine {
|
|
|
4233
4263
|
});
|
|
4234
4264
|
// 创建 IMRenderer(统一 interactive/proactive 两条路径)
|
|
4235
4265
|
let firstReply = true;
|
|
4236
|
-
// 出站 debug.model:每次 runQuery 前更新(含备用模型切换)。单独声明是因为
|
|
4237
|
-
// send 闭包早于下方 modelOverride/agentModel 的 let 声明,直接引用会撞 TDZ。
|
|
4238
|
-
let debugRunnerModel;
|
|
4239
4266
|
const renderer = new IMRenderer({
|
|
4240
4267
|
adapter,
|
|
4241
4268
|
envelope,
|
|
@@ -4245,9 +4272,10 @@ export class ResponseEngine {
|
|
|
4245
4272
|
suppressActivityItems: isProactive ? false : middleOutputMode !== 'all',
|
|
4246
4273
|
suppressIntermediateText: isProactive ? false : middleOutputMode === 'none',
|
|
4247
4274
|
deferTextUntilBoundary: (message.channelType ?? session.channelType) === 'aun' && session.chatType === 'private',
|
|
4275
|
+
noopSentinel: message.source === 'trigger' ? message.triggerMeta?.noopSentinel : undefined,
|
|
4248
4276
|
operationalNoticesAsText: !isProactive && middleOutputMode !== 'none',
|
|
4249
4277
|
fileMarkerPattern: options?.fileMarkerPattern,
|
|
4250
|
-
recordActivity: async (item) => {
|
|
4278
|
+
recordActivity: async (item, activityId) => {
|
|
4251
4279
|
if (!taskActivityStore || (turnLease && !this.turnCoordinator.canPublish(turnLease)))
|
|
4252
4280
|
return;
|
|
4253
4281
|
try {
|
|
@@ -4264,6 +4292,7 @@ export class ResponseEngine {
|
|
|
4264
4292
|
...(activityChatType === 'group' ? { groupId: activityChannelId } : {}),
|
|
4265
4293
|
...(activityChatType === 'private' ? { peerId: activityChannelId } : {}),
|
|
4266
4294
|
item,
|
|
4295
|
+
...(activityId ? { activityId } : {}),
|
|
4267
4296
|
}, { projectPath: absoluteProjectPath, allowedRoots: toolImageReadRoots });
|
|
4268
4297
|
}
|
|
4269
4298
|
catch (error) {
|
|
@@ -4314,6 +4343,7 @@ export class ResponseEngine {
|
|
|
4314
4343
|
...(session.agentSessionId ? { agentSessionId: session.agentSessionId } : {}),
|
|
4315
4344
|
...(debugRunnerModel ? { model: debugRunnerModel } : {}),
|
|
4316
4345
|
};
|
|
4346
|
+
opts.model = debugRunnerModel;
|
|
4317
4347
|
opts.metadata = withTaskMetadata({
|
|
4318
4348
|
...(opts.metadata ?? {}),
|
|
4319
4349
|
...(payload.kind === 'result.text' ? payload.metadata : {}),
|
|
@@ -4372,6 +4402,17 @@ export class ResponseEngine {
|
|
|
4372
4402
|
const permissionReplyContext = authorizationIdentity
|
|
4373
4403
|
? { delivery: { chatType: 'private' } }
|
|
4374
4404
|
: capturedReplyContext;
|
|
4405
|
+
const setRunnerModel = (model) => {
|
|
4406
|
+
debugRunnerModel = model;
|
|
4407
|
+
if (envelope.replyContext)
|
|
4408
|
+
envelope.replyContext.model = model;
|
|
4409
|
+
capturedReplyContext.model = model;
|
|
4410
|
+
permissionReplyContext.model = model;
|
|
4411
|
+
if (model)
|
|
4412
|
+
this.activeRunnerModels.set(session.id, model);
|
|
4413
|
+
else
|
|
4414
|
+
this.activeRunnerModels.delete(session.id);
|
|
4415
|
+
};
|
|
4375
4416
|
let permissionTerminalFailure;
|
|
4376
4417
|
const permissionPromptForOrigin = async (text) => {
|
|
4377
4418
|
await permissionAdapter.send(withEnvelopeReplyContext({
|
|
@@ -4513,7 +4554,24 @@ export class ResponseEngine {
|
|
|
4513
4554
|
})
|
|
4514
4555
|
: undefined;
|
|
4515
4556
|
const systemSessionCheck = systemSessionModule && systemSessionContext
|
|
4516
|
-
? (
|
|
4557
|
+
? (() => {
|
|
4558
|
+
let denyCount = 0;
|
|
4559
|
+
const DENY_STEER_THRESHOLD = 3;
|
|
4560
|
+
return (toolName, toolInput) => {
|
|
4561
|
+
const decision = systemSessionModule.checkTool(toolName, toolInput, systemSessionContext);
|
|
4562
|
+
if (!decision.allow) {
|
|
4563
|
+
denyCount++;
|
|
4564
|
+
if (denyCount >= DENY_STEER_THRESHOLD) {
|
|
4565
|
+
const steerHint = `(已连续拒绝 ${denyCount} 次。请停止重试当前命令形式,改用任务书中列出的文件工具,或用 ec memory create|update|archive 写入记忆)`;
|
|
4566
|
+
return { ...decision, reason: decision.reason + ' ' + steerHint };
|
|
4567
|
+
}
|
|
4568
|
+
}
|
|
4569
|
+
else {
|
|
4570
|
+
denyCount = 0;
|
|
4571
|
+
}
|
|
4572
|
+
return decision;
|
|
4573
|
+
};
|
|
4574
|
+
})()
|
|
4517
4575
|
: undefined;
|
|
4518
4576
|
// 沙箱声明与 runner 有关,但当前所有 runner 共用同一个结论;仍按 runner 问一次,
|
|
4519
4577
|
// 以便将来某个 runner 需要不同取舍时只改模块。
|
|
@@ -4557,7 +4615,7 @@ export class ResponseEngine {
|
|
|
4557
4615
|
channel: permissionAdapter.channelKey,
|
|
4558
4616
|
agentName: agentNameForStats,
|
|
4559
4617
|
taskId,
|
|
4560
|
-
chatmode:
|
|
4618
|
+
chatmode: effectiveChatMode,
|
|
4561
4619
|
// 系统会话没有角色
|
|
4562
4620
|
role: systemSessionMarker ? undefined : peerRole,
|
|
4563
4621
|
chatType: authChatType,
|
|
@@ -4751,6 +4809,26 @@ export class ResponseEngine {
|
|
|
4751
4809
|
// 先用裸文本兜底;vars 构造完成后用消息渲染层重算(见下方 effectivePrompt 重赋值)。
|
|
4752
4810
|
let effectivePrompt = wrapPrompt(message.content);
|
|
4753
4811
|
let fullAccessMessagePromptContext;
|
|
4812
|
+
const markFullAccessPromptShown = async () => {
|
|
4813
|
+
if (!fullAccessMessagePromptContext || fullAccessAuthorization?.source !== 'session-policy')
|
|
4814
|
+
return;
|
|
4815
|
+
const current = isTopicSession(session)
|
|
4816
|
+
? await this.sessionManager.getSessionById(session.id) : session;
|
|
4817
|
+
if (!current || !turnLease || !this.turnCoordinator.isCurrent(turnLease))
|
|
4818
|
+
return;
|
|
4819
|
+
const config = readSessionFullAccessOverride(current);
|
|
4820
|
+
if (!config?.enabled || config.authorizedBy !== fullAccessAuthorization.authorizedBy
|
|
4821
|
+
|| config.promptedSessionId === session.id)
|
|
4822
|
+
return;
|
|
4823
|
+
const prompted = { ...config, promptedSessionId: session.id };
|
|
4824
|
+
if (isTopicSession(current)) {
|
|
4825
|
+
const updated = this.sessionManager.updateSessionFullAccess(current.id, prompted);
|
|
4826
|
+
session.metadata = updated.metadata;
|
|
4827
|
+
}
|
|
4828
|
+
else {
|
|
4829
|
+
updateRelationSessionFullAccess(current, prompted);
|
|
4830
|
+
}
|
|
4831
|
+
};
|
|
4754
4832
|
let renderResult;
|
|
4755
4833
|
let effectiveSystemPrompt;
|
|
4756
4834
|
let modelOverride;
|
|
@@ -4871,7 +4949,10 @@ export class ResponseEngine {
|
|
|
4871
4949
|
// records all observe the same normalized value.
|
|
4872
4950
|
permissionContext.permissionMode = effectivePermissionMode;
|
|
4873
4951
|
permissionContext.executionPermission = fullAccessAuthorization;
|
|
4874
|
-
|
|
4952
|
+
const showFullAccessPrompt = fullAccessAuthorization?.source === 'fullaccess-command'
|
|
4953
|
+
|| (fullAccessAuthorization?.source === 'session-policy'
|
|
4954
|
+
&& readSessionFullAccessOverride(session)?.promptedSessionId !== session.id);
|
|
4955
|
+
fullAccessMessagePromptContext = showFullAccessPrompt
|
|
4875
4956
|
? FULL_ACCESS_MESSAGE_PROMPT_CONTEXT
|
|
4876
4957
|
: undefined;
|
|
4877
4958
|
// 模型/强度按配置、CLI 和 runner 默认值解析后,经角色约束传入 runQuery。
|
|
@@ -5048,13 +5129,13 @@ export class ResponseEngine {
|
|
|
5048
5129
|
bootstrapAgentMdPath: agentMdPath(selfAid),
|
|
5049
5130
|
};
|
|
5050
5131
|
}
|
|
5051
|
-
//
|
|
5052
|
-
//
|
|
5053
|
-
//
|
|
5132
|
+
// 自我定义写在 personal/soul/ 下,每个非空文件每轮注入 system prompt。
|
|
5133
|
+
// 这些文件没有命令行入口,只能由 agent 自己用文件工具维护,所以整目录
|
|
5134
|
+
// 对 owner 会话放行(写入即触发下一轮上下文重组)。
|
|
5054
5135
|
if (selfAid && peerRole === 'owner' && effectivePermissionMode !== 'readonly') {
|
|
5055
5136
|
modelOverride = {
|
|
5056
5137
|
...(modelOverride || {}),
|
|
5057
|
-
|
|
5138
|
+
personalSoulDir: agentSoulDir(selfAid),
|
|
5058
5139
|
};
|
|
5059
5140
|
}
|
|
5060
5141
|
if (normalizedBaseagent.canonical === 'claude') {
|
|
@@ -5173,6 +5254,14 @@ export class ResponseEngine {
|
|
|
5173
5254
|
const memoryMode = session.metadata?.memoryMode;
|
|
5174
5255
|
// Kit renderer: 组装上下文
|
|
5175
5256
|
const pkgRoot = getPackageRoot();
|
|
5257
|
+
// 名录身份(Owner / 个人助理)来自渲染产物旁的小文件,只读一次、只取四个字段:
|
|
5258
|
+
// 每轮都要算,不能去解析 contacts.json。读不出时是空身份,下面的 isPersonalAssistant
|
|
5259
|
+
// / isOwner 随之双双为 false——宁可不注入 PA 段,也不能让非 PA 拿到 PA 的行为约束。
|
|
5260
|
+
const directoryIdentity = selfAid
|
|
5261
|
+
? readOwnerDirectoryIdentity(path.join(resolveRoot(), 'agents', selfAid, 'directory'))
|
|
5262
|
+
: EMPTY_IDENTITY;
|
|
5263
|
+
const personalAssistantAid = directoryIdentity.personalAssistant?.aid;
|
|
5264
|
+
const identityOwnerAid = directoryIdentity.owner?.aid;
|
|
5176
5265
|
const kitCtx = {
|
|
5177
5266
|
vars: {
|
|
5178
5267
|
EVOLCORE_HOME: resolveRoot(),
|
|
@@ -5200,12 +5289,37 @@ export class ResponseEngine {
|
|
|
5200
5289
|
RELATIONS_DIR: selfAid ? path.join(resolveRoot(), 'agents', selfAid, 'relations') : undefined,
|
|
5201
5290
|
VENUES_DIR: selfAid ? path.join(resolveRoot(), 'agents', selfAid, 'venues') : undefined,
|
|
5202
5291
|
selfAid: selfAid || undefined,
|
|
5292
|
+
// Owner 以名录快照为准;快照还没落地(首次接入、未授权)时退回静态配置,
|
|
5293
|
+
// 否则 owner-memory 段会整段消失,而它此前一直是按静态 owner 拼路径的。
|
|
5203
5294
|
ownerAid: (() => {
|
|
5295
|
+
if (identityOwnerAid)
|
|
5296
|
+
return identityOwnerAid;
|
|
5204
5297
|
const raw = selfAid ? getFirstStaticAgentOwner(selfAid) : undefined;
|
|
5205
5298
|
if (!raw)
|
|
5206
5299
|
return undefined;
|
|
5207
5300
|
return isValidAid(raw) ? raw : undefined;
|
|
5208
5301
|
})(),
|
|
5302
|
+
ownerName: directoryIdentity.owner?.name || undefined,
|
|
5303
|
+
personalAssistantAid,
|
|
5304
|
+
personalAssistantName: directoryIdentity.personalAssistant?.name || undefined,
|
|
5305
|
+
// 两个角色布尔**即时比较**,不从文件读:落盘的布尔会过期,也挡不住手改文件伪造。
|
|
5306
|
+
isPersonalAssistant: !!personalAssistantAid && personalAssistantAid === selfAid,
|
|
5307
|
+
isOwner: !!identityOwnerAid && identityOwnerAid === selfAid,
|
|
5308
|
+
// 准入现状压成一句话:只列能联系谁,说不通的档位直接不提。
|
|
5309
|
+
// 只说"能",不说"谁关的"——默认关与显式关在结果上没区别。
|
|
5310
|
+
...(() => {
|
|
5311
|
+
if (!selfAid)
|
|
5312
|
+
return {};
|
|
5313
|
+
const state = resolveContactsState(selfAid, personalAssistantAid);
|
|
5314
|
+
const open = ['Owner', '个人助理'];
|
|
5315
|
+
if (state.internalContacts)
|
|
5316
|
+
open.push('内部联系人');
|
|
5317
|
+
if (state.externalContacts)
|
|
5318
|
+
open.push('外部联系人');
|
|
5319
|
+
if (state.strangerContacts)
|
|
5320
|
+
open.push('名录外的人');
|
|
5321
|
+
return { contactsState: `现在可联系:${open.join('、')}` };
|
|
5322
|
+
})(),
|
|
5209
5323
|
// 记忆系统开关变量(来自 effectiveAgentConfig.memory,默认全部启用)。
|
|
5210
5324
|
// enableRelation 是总开关:relation 是所有记忆的唯一出生地。
|
|
5211
5325
|
// memory.enableRelation 在 relation-config schema 里声明了 x-merge-logic: AND,
|
|
@@ -5267,17 +5381,8 @@ export class ResponseEngine {
|
|
|
5267
5381
|
threadId: sessionTopicThreadId(session),
|
|
5268
5382
|
// Stage 3: sessionKey 持久化字段
|
|
5269
5383
|
sessionKey: session.sessionKey,
|
|
5270
|
-
chatMode:
|
|
5384
|
+
chatMode: effectiveChatMode,
|
|
5271
5385
|
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
5386
|
readonly: effectivePermissionMode === 'readonly',
|
|
5282
5387
|
baseAgent: normalizedBaseagent.canonical,
|
|
5283
5388
|
baseAgentName: normalizedBaseagent.displayName,
|
|
@@ -5292,6 +5397,24 @@ export class ResponseEngine {
|
|
|
5292
5397
|
},
|
|
5293
5398
|
sessionId: session.id,
|
|
5294
5399
|
};
|
|
5400
|
+
if (effectiveChatMode === 'paactive') {
|
|
5401
|
+
kitCtx.vars = buildPaactiveSystemVars(kitCtx.vars);
|
|
5402
|
+
}
|
|
5403
|
+
else {
|
|
5404
|
+
Object.assign(kitCtx.vars, {
|
|
5405
|
+
// proactive 为 null(interactive 模式,这些开关不适用)时如实为 false——
|
|
5406
|
+
// 默认值不在此硬编码,出厂默认由模式 schema 声明、经 buildState 落入 proactive.*。
|
|
5407
|
+
proactivePreTool1stMsgChk: proactive?.preTool1stMsgChk ?? false,
|
|
5408
|
+
proactiveToolUseReminder: proactive?.toolUseReminder ?? false,
|
|
5409
|
+
// 明确续跑已表态时,提示词和运行时门禁都不再要求重复开场。
|
|
5410
|
+
proactiveFirstSendRequired: proactive?.firstSendRequired === true && !proactive.firstToolDone,
|
|
5411
|
+
proactiveToolReportRequired: proactive?.toolReportRequired ?? false,
|
|
5412
|
+
proactiveToolReportInterval: proactive?.toolReportInterval ?? 20,
|
|
5413
|
+
proactiveSendTargetLabel: chatType === 'group' ? '群里' : '对方',
|
|
5414
|
+
});
|
|
5415
|
+
}
|
|
5416
|
+
const messageVars = effectiveChatMode === 'paactive'
|
|
5417
|
+
? buildPaactiveMessageVars(kitCtx.vars) : kitCtx.vars;
|
|
5295
5418
|
// 确保技能索引是最新的(懒加载机制)
|
|
5296
5419
|
if (selfAid) {
|
|
5297
5420
|
const { ensureSkillIndexUpToDate } = await import('../skill/startup.js');
|
|
@@ -5308,7 +5431,9 @@ export class ResponseEngine {
|
|
|
5308
5431
|
? DEFAULT_MANIFEST_FILE
|
|
5309
5432
|
: systemSessionMarker
|
|
5310
5433
|
? getSystemSessionModule(systemSessionMarker.type).manifest(systemSessionMarker.subtype)
|
|
5311
|
-
:
|
|
5434
|
+
: effectiveChatMode === 'paactive'
|
|
5435
|
+
? paactiveSystemManifest(kitCtx.vars)
|
|
5436
|
+
: resolveSessionManifest(sessionType, sessionManifests);
|
|
5312
5437
|
const kitContext = renderKitSections(kitCtx, manifestFile);
|
|
5313
5438
|
effectiveSystemPrompt = [options?.systemPromptAppend, kitContext].filter(Boolean).join('\n') || undefined;
|
|
5314
5439
|
// ── Stats: context_breakdown 旁路采集(各段估算 token 数,字符数/4 近似) ──
|
|
@@ -5437,8 +5562,8 @@ export class ResponseEngine {
|
|
|
5437
5562
|
if (message.restartResume?.pendingInterrupted) {
|
|
5438
5563
|
const resumeIdx = renderItems.findIndex(item => item.kind === 'restart-resume');
|
|
5439
5564
|
if (resumeIdx >= 0 && resumeIdx < renderItems.length - 1) {
|
|
5440
|
-
const resumeRender = renderMessageBody(renderItems.slice(0, resumeIdx + 1),
|
|
5441
|
-
const pendingRender = renderMessageBody(renderItems.slice(resumeIdx + 1),
|
|
5565
|
+
const resumeRender = renderMessageBody(renderItems.slice(0, resumeIdx + 1), messageVars, session.id);
|
|
5566
|
+
const pendingRender = renderMessageBody(renderItems.slice(resumeIdx + 1), messageVars, session.id);
|
|
5442
5567
|
const body = [
|
|
5443
5568
|
resumeRender.body.trim(),
|
|
5444
5569
|
`【新消息插入】\n\n${pendingRender.body.trim()}\n\n【请根据前后消息酌情处理】`,
|
|
@@ -5449,11 +5574,11 @@ export class ResponseEngine {
|
|
|
5449
5574
|
};
|
|
5450
5575
|
}
|
|
5451
5576
|
else {
|
|
5452
|
-
renderResult = renderMessageBody(renderItems,
|
|
5577
|
+
renderResult = renderMessageBody(renderItems, messageVars, session.id);
|
|
5453
5578
|
}
|
|
5454
5579
|
}
|
|
5455
5580
|
else {
|
|
5456
|
-
renderResult = renderMessageBody(renderItems,
|
|
5581
|
+
renderResult = renderMessageBody(renderItems, messageVars, session.id);
|
|
5457
5582
|
}
|
|
5458
5583
|
if (renderResult.body.trim())
|
|
5459
5584
|
effectivePrompt = wrapPrompt(renderResult.body);
|
|
@@ -5461,6 +5586,8 @@ export class ResponseEngine {
|
|
|
5461
5586
|
effectivePrompt = wrapPrompt(composeHintFallback(hintItems, fallbackContent));
|
|
5462
5587
|
}
|
|
5463
5588
|
catch (e) {
|
|
5589
|
+
if (effectiveChatMode === 'paactive')
|
|
5590
|
+
throw e;
|
|
5464
5591
|
logger.warn(`[ResponseEngine] renderMessageBody failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
5465
5592
|
if (ownerHintClaim) {
|
|
5466
5593
|
observerHintFailureCode = 'RENDER_FAILED';
|
|
@@ -5680,11 +5807,7 @@ export class ResponseEngine {
|
|
|
5680
5807
|
data: image.data,
|
|
5681
5808
|
mimeType: image.mimeType,
|
|
5682
5809
|
}));
|
|
5683
|
-
|
|
5684
|
-
if (debugRunnerModel)
|
|
5685
|
-
this.activeRunnerModels.set(session.id, debugRunnerModel);
|
|
5686
|
-
else
|
|
5687
|
-
this.activeRunnerModels.delete(session.id);
|
|
5810
|
+
setRunnerModel(modelOverride?.model || agentModel);
|
|
5688
5811
|
// 每次尝试前覆盖:备用模型切换后,请求模型以最后一次尝试为准
|
|
5689
5812
|
this.recordBgSessionModels(message, { requestedModel: debugRunnerModel });
|
|
5690
5813
|
if (message.restartResume?.submitted && runAgentSessionId) {
|
|
@@ -5714,7 +5837,20 @@ export class ResponseEngine {
|
|
|
5714
5837
|
},
|
|
5715
5838
|
} };
|
|
5716
5839
|
const rawStream = await agent.runQuery(session.id, capsuleInput.prompt, absoluteProjectPath, runAgentSessionId, runnerImages, effectiveSystemPrompt, this.sessionManager, attemptOverride, runtimeEnv);
|
|
5717
|
-
|
|
5840
|
+
// A provider may resolve an alias or report a more precise model at
|
|
5841
|
+
// completion. Update before the renderer flushes the final output.
|
|
5842
|
+
const trackModel = async function* () {
|
|
5843
|
+
for await (const event of rawStream) {
|
|
5844
|
+
if (event.type === 'complete') {
|
|
5845
|
+
const model = event.lastModelCall?.model || event.model || event.contextUsage?.model;
|
|
5846
|
+
if (model) {
|
|
5847
|
+
setRunnerModel(model);
|
|
5848
|
+
}
|
|
5849
|
+
}
|
|
5850
|
+
yield event;
|
|
5851
|
+
}
|
|
5852
|
+
};
|
|
5853
|
+
const stream = this.consumeCapsuleWithInput(trackModel(), session, message, turnLease, () => attemptCapsuleId, markFullAccessPromptShown);
|
|
5718
5854
|
// The turn may be superseded while the runner is still creating its
|
|
5719
5855
|
// backend query. Replay the interrupt after runQuery resolves, when
|
|
5720
5856
|
// every runner is required to have an addressable cancellation handle.
|
|
@@ -5797,7 +5933,8 @@ export class ResponseEngine {
|
|
|
5797
5933
|
}, async () => {
|
|
5798
5934
|
if (proactiveCircuitBreakRequested)
|
|
5799
5935
|
await interruptProactiveCircuitBreak();
|
|
5800
|
-
})
|
|
5936
|
+
}, message.source === 'trigger' && !this.isTrustedDaemonTrigger(message)
|
|
5937
|
+
? message.triggerMeta?.noopSentinel : undefined);
|
|
5801
5938
|
streamResult = attemptTimeout
|
|
5802
5939
|
? await Promise.race([processAttempt, attemptTimeout.promise])
|
|
5803
5940
|
: await processAttempt;
|
|
@@ -5973,6 +6110,8 @@ export class ResponseEngine {
|
|
|
5973
6110
|
permissionMode: effectivePermissionMode,
|
|
5974
6111
|
turnLease,
|
|
5975
6112
|
messagePromptContext: fullAccessMessagePromptContext,
|
|
6113
|
+
message,
|
|
6114
|
+
onInputAccepted: markFullAccessPromptShown,
|
|
5976
6115
|
beforeRunQuery: () => this.assertCurrentExecutionAuthorization(permissionContext, agent),
|
|
5977
6116
|
});
|
|
5978
6117
|
}
|
|
@@ -6013,11 +6152,15 @@ export class ResponseEngine {
|
|
|
6013
6152
|
runtimeEnv,
|
|
6014
6153
|
resetTimer,
|
|
6015
6154
|
shouldSuppress,
|
|
6155
|
+
noopSentinel: message.source === 'trigger' && !this.isTrustedDaemonTrigger(message)
|
|
6156
|
+
? message.triggerMeta?.noopSentinel : undefined,
|
|
6016
6157
|
proactive,
|
|
6017
6158
|
proactiveSelfAid: selfAid,
|
|
6018
6159
|
permissionMode: effectivePermissionMode,
|
|
6019
6160
|
turnLease,
|
|
6020
6161
|
messagePromptContext: fullAccessMessagePromptContext,
|
|
6162
|
+
message,
|
|
6163
|
+
onInputAccepted: markFullAccessPromptShown,
|
|
6021
6164
|
beforeRunQuery: () => this.assertCurrentExecutionAuthorization(permissionContext, agent),
|
|
6022
6165
|
});
|
|
6023
6166
|
// 重试后仍然 prompt_too_long:显示友好提示
|
|
@@ -6085,7 +6228,14 @@ export class ResponseEngine {
|
|
|
6085
6228
|
// proactive 模式:agent 主动调用 ctl file 发送文件,跳过标记处理
|
|
6086
6229
|
// [迁移点6] afterProcess:文件标记(interactive)+ Unknown skill 兜底(proactive)
|
|
6087
6230
|
// 由响应模式插件统一处理(InteractiveMode.afterProcess / ProactiveMode.afterProcess)
|
|
6088
|
-
|
|
6231
|
+
const finalReplyText = streamResult.lastReplyText || streamResult.fullText;
|
|
6232
|
+
const visibleFinalReplyText = stripContextLimitErrorLines(finalReplyText);
|
|
6233
|
+
const isTriggerNoop = message.source === 'trigger'
|
|
6234
|
+
&& !this.isTrustedDaemonTrigger(message)
|
|
6235
|
+
&& !streamResult.isError
|
|
6236
|
+
&& !isExpectedTerminalInterrupt(streamResult.terminalReason)
|
|
6237
|
+
&& isTriggerNoopText(visibleFinalReplyText, message.triggerMeta?.noopSentinel);
|
|
6238
|
+
if (resolvedMode?.mode.afterProcess && !isTriggerNoop) {
|
|
6089
6239
|
const flusherText = renderer.getFinalText();
|
|
6090
6240
|
const fullText = flusherText.length >= (streamResult.fullText?.length || 0) ? flusherText : streamResult.fullText;
|
|
6091
6241
|
await resolvedMode.mode.afterProcess({
|
|
@@ -6186,7 +6336,7 @@ export class ResponseEngine {
|
|
|
6186
6336
|
logger.info(`[${adapter.channelName}] Sending file via ${targetInfo.adapter.channelName}: ${resolvedPath}`);
|
|
6187
6337
|
try {
|
|
6188
6338
|
const targetReplyContext = isCrossChannel
|
|
6189
|
-
? { delivery: { chatType: 'private' } }
|
|
6339
|
+
? { delivery: { chatType: 'private' }, model: debugRunnerModel }
|
|
6190
6340
|
: capturedReplyContext;
|
|
6191
6341
|
await targetInfo.adapter.send(buildEnvelope({ taskId, channel: targetInfo.adapter.channelName, channelId: targetChannelId, agentName: agentNameForStats, replyContext: targetReplyContext }), { kind: 'result.file', filePath: resolvedPath });
|
|
6192
6342
|
this.eventBus.publish({ type: 'runner:file-sent', sessionId: session.id, filePath: resolvedPath, channel: targetInfo.adapter.channelName });
|
|
@@ -6208,13 +6358,7 @@ export class ResponseEngine {
|
|
|
6208
6358
|
// 最终回复文本:suppressed 模式或无 text 事件时需要兜底添加
|
|
6209
6359
|
// 错误诊断串已通过 system.error 单独发出时置 true,下游跳过 result.error 避免重复
|
|
6210
6360
|
let sentErrorAsSystemError = false;
|
|
6211
|
-
const finalReplyText = streamResult.lastReplyText || streamResult.fullText;
|
|
6212
|
-
const visibleFinalReplyText = stripContextLimitErrorLines(finalReplyText);
|
|
6213
6361
|
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
6362
|
if (!this.turnCoordinator.isCurrent(turnLease)) {
|
|
6219
6363
|
agent.cleanupStream(streamKey, turnLease ? { taskId: turnLease.taskId, generation: turnLease.generation } : undefined);
|
|
6220
6364
|
this.sessionManager.clearProcessingIfTask(session.id, taskId);
|
|
@@ -6230,11 +6374,13 @@ export class ResponseEngine {
|
|
|
6230
6374
|
const terminalInterrupt = isExpectedStreamInterrupt(streamResult.terminalReason, this.interruptedSessions.get(session.id));
|
|
6231
6375
|
const streamRecoverable = !permissionTerminalFailure
|
|
6232
6376
|
&& !isExpectedTerminalInterrupt(streamResult.terminalReason)
|
|
6233
|
-
&&
|
|
6377
|
+
&& (isRecoverableProtocolFailure(streamResult.subtype, streamResult.protocolIncompleteReason)
|
|
6378
|
+
|| isRetryableError(new Error(getStreamErrorText(streamResult))));
|
|
6234
6379
|
sentErrorAsSystemError = await projectTerminalReply({
|
|
6235
6380
|
isCurrent: () => !turnLease || this.turnCoordinator.canPublish(turnLease),
|
|
6236
6381
|
isInterrupted: () => terminalInterrupt || isNonErrorInterruptReason(this.interruptedSessions.get(session.id)),
|
|
6237
6382
|
isNoop: isTriggerNoop,
|
|
6383
|
+
discardText: () => renderer.discardPendingText(),
|
|
6238
6384
|
isError: streamResult.isError,
|
|
6239
6385
|
text: visibleFinalReplyText,
|
|
6240
6386
|
diagnosticText: streamResult.syntheticDiagnosticText,
|
|
@@ -6269,7 +6415,7 @@ export class ResponseEngine {
|
|
|
6269
6415
|
logger.info(`[ResponseEngine] task.finished: session=${session.id} task=${taskId} outcome=${terminalInterrupt ? 'interrupted' : streamResult.isError ? 'error' : 'completed'}`);
|
|
6270
6416
|
import('../../utils/msg-diag.js').then(m => m.diagLog('task_done', { aid: session.selfAID ?? '', msgId: message.messageId ?? '', taskId, text: message.content ?? '' })).catch(() => { });
|
|
6271
6417
|
// 降级模型回复末尾追加标记(代码层硬注入,不依赖模型输出)
|
|
6272
|
-
if (usedFallback) {
|
|
6418
|
+
if (usedFallback && !isTriggerNoop) {
|
|
6273
6419
|
const curFbState = this.modelFallbackMap.get(session.id);
|
|
6274
6420
|
const showHint = curFbState && curFbState.nextProbeAt >= 8 && !curFbState.hintShown;
|
|
6275
6421
|
const suffix = showHint
|
|
@@ -7335,15 +7481,23 @@ export class ResponseEngine {
|
|
|
7335
7481
|
};
|
|
7336
7482
|
}
|
|
7337
7483
|
/** Only backend acceptance, never a log write or startup status, consumes context. */
|
|
7338
|
-
async *consumeCapsuleWithInput(stream, session, message, lease, capsuleIdForAttempt) {
|
|
7484
|
+
async *consumeCapsuleWithInput(stream, session, message, lease, capsuleIdForAttempt, onInputAccepted) {
|
|
7339
7485
|
let accepted = false;
|
|
7340
7486
|
let consumed = false;
|
|
7487
|
+
let noticeConsumed = false;
|
|
7341
7488
|
for await (const event of stream) {
|
|
7342
7489
|
if (!lease || this.turnCoordinator.isCurrent(lease)) {
|
|
7343
7490
|
if (event.type === 'input_accepted' && (!lease || event.inputId === lease.inputId))
|
|
7344
7491
|
accepted = true;
|
|
7345
7492
|
if ((event.type === 'text' && !event.synthetic && !!event.text.trim()) || event.type === 'tool_use')
|
|
7346
7493
|
accepted = true;
|
|
7494
|
+
// A successful result is also acceptance evidence for runners that
|
|
7495
|
+
// return only a complete event. Startup errors must not spend the notice.
|
|
7496
|
+
const completedWithResult = event.type === 'complete' && !event.isError && !!event.result?.trim();
|
|
7497
|
+
if (!noticeConsumed && (accepted || completedWithResult) && onInputAccepted) {
|
|
7498
|
+
await onInputAccepted();
|
|
7499
|
+
noticeConsumed = true;
|
|
7500
|
+
}
|
|
7347
7501
|
const capsuleId = capsuleIdForAttempt();
|
|
7348
7502
|
if (accepted && !consumed && capsuleId && this.sessionManager.consumeSessionCapsule) {
|
|
7349
7503
|
const current = await this.sessionManager.getSessionById(session.id);
|
|
@@ -7368,7 +7522,7 @@ export class ResponseEngine {
|
|
|
7368
7522
|
*/
|
|
7369
7523
|
async processEventStream(stream, session, agent, renderer, resetTimer, shouldSuppress, proactive,
|
|
7370
7524
|
/** [迁移点4/5] 响应模式插件 + 状态,用于调 onToolUse/onComplete 钩子 */
|
|
7371
|
-
modeHooks, causation, turnLease, permissionMode, proactiveSelfAid, onAsyncQuestion, onToolCallsSettled) {
|
|
7525
|
+
modeHooks, causation, turnLease, permissionMode, proactiveSelfAid, onAsyncQuestion, onToolCallsSettled, noopSentinel) {
|
|
7372
7526
|
// Per-session agent name for stats bucketing
|
|
7373
7527
|
const statsChannelKey = session.channel === 'daemon' ? session.channel : (session.metadata?.channelKey || session.channel);
|
|
7374
7528
|
const agentNameForStats = this.agentRegistry?.resolveByChannel(statsChannelKey)?.name ?? '<unknown>';
|
|
@@ -7409,6 +7563,26 @@ export class ResponseEngine {
|
|
|
7409
7563
|
};
|
|
7410
7564
|
// 追踪最后一轮 assistant 回复文本(tool_use 之后的纯文本)
|
|
7411
7565
|
let lastReplyText = '';
|
|
7566
|
+
let pendingTriggerText = '';
|
|
7567
|
+
let triggerTextDecision = 'pending';
|
|
7568
|
+
const projectTriggerText = (text, boundary = false) => {
|
|
7569
|
+
if (!noopSentinel || triggerTextDecision === 'visible')
|
|
7570
|
+
return text;
|
|
7571
|
+
if (triggerTextDecision === 'noop')
|
|
7572
|
+
return '';
|
|
7573
|
+
pendingTriggerText += text;
|
|
7574
|
+
if (isTriggerNoopText(pendingTriggerText, noopSentinel)) {
|
|
7575
|
+
triggerTextDecision = 'noop';
|
|
7576
|
+
pendingTriggerText = '';
|
|
7577
|
+
return '';
|
|
7578
|
+
}
|
|
7579
|
+
if (!boundary && noopSentinel.startsWith(pendingTriggerText.trimStart()))
|
|
7580
|
+
return '';
|
|
7581
|
+
triggerTextDecision = 'visible';
|
|
7582
|
+
const visible = pendingTriggerText;
|
|
7583
|
+
pendingTriggerText = '';
|
|
7584
|
+
return visible;
|
|
7585
|
+
};
|
|
7412
7586
|
// 上游合成错误帧的原文(runner 标记 synthetic 的 text)。与正文通道分开存放:
|
|
7413
7587
|
// 它只能作为终态错误文案的来源,不得进入 lastReplyText / 投影 / hasReceivedText。
|
|
7414
7588
|
let syntheticDiagnosticText = '';
|
|
@@ -7615,7 +7789,32 @@ export class ResponseEngine {
|
|
|
7615
7789
|
diagnosticSuffix = formatToolInputDiagnostics(diagnoseToolInputAfterFailure(original, event));
|
|
7616
7790
|
projectedEvent = { ...event, error: getToolResultErrorText(event) + diagnosticSuffix };
|
|
7617
7791
|
}
|
|
7618
|
-
|
|
7792
|
+
// Decide before either interactive text or proactive thoughts can escape.
|
|
7793
|
+
// The prefix may span multiple provider chunks; retain raw text for audit.
|
|
7794
|
+
let projectedText;
|
|
7795
|
+
if (noopSentinel && event.type === 'text' && !event.synthetic) {
|
|
7796
|
+
projectedText = projectTriggerText(stripContextLimitErrorLines(event.text));
|
|
7797
|
+
projectedEvent = { ...event, text: projectedText };
|
|
7798
|
+
}
|
|
7799
|
+
else if (noopSentinel && (event.type === 'tool_use' || event.type === 'complete')) {
|
|
7800
|
+
const pendingText = projectTriggerText('', true);
|
|
7801
|
+
if (pendingText) {
|
|
7802
|
+
renderer.emit({ type: 'text', text: pendingText });
|
|
7803
|
+
this.eventBus.publish({ type: 'message:text', sessionId: session.id, text: pendingText, isFinal: false });
|
|
7804
|
+
if (!shouldSuppress()) {
|
|
7805
|
+
await renderer.addText(pendingText, undefined, undefined, assistantUuid);
|
|
7806
|
+
hasProjectedCurrentReplyText = true;
|
|
7807
|
+
}
|
|
7808
|
+
}
|
|
7809
|
+
if (event.type === 'tool_use') {
|
|
7810
|
+
triggerTextDecision = 'pending';
|
|
7811
|
+
pendingTriggerText = '';
|
|
7812
|
+
}
|
|
7813
|
+
}
|
|
7814
|
+
const suppressNoopProjection = event.type === 'text' && projectedText === ''
|
|
7815
|
+
|| event.type === 'complete' && !event.isError
|
|
7816
|
+
&& isTriggerNoopText(lastReplyText || event.result || '', noopSentinel);
|
|
7817
|
+
renderer.emit(projectedEvent, suppressNoopProjection);
|
|
7619
7818
|
if (event.type === 'text_start') {
|
|
7620
7819
|
await renderer.sendTextStart(event.contentIndex, event.turn);
|
|
7621
7820
|
continue;
|
|
@@ -7793,7 +7992,7 @@ export class ResponseEngine {
|
|
|
7793
7992
|
else {
|
|
7794
7993
|
// 网关偶尔会把上下文超限错误伪装成普通 text event。不要向事件总线或
|
|
7795
7994
|
// 渲染器投影错误行;lastReplyText 仍保留原文本,以便流结束后触发恢复。
|
|
7796
|
-
const visibleText = stripContextLimitErrorLines(event.text);
|
|
7995
|
+
const visibleText = projectedText ?? stripContextLimitErrorLines(event.text);
|
|
7797
7996
|
if (visibleText) {
|
|
7798
7997
|
hasReceivedText = true;
|
|
7799
7998
|
if (visibleText.trim())
|