evolcore 0.0.43-test.2 → 0.0.43-test.4
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 +44 -1
- package/bin/ecmsg.js +229 -0
- package/bin/install-codex-managed-hooks.mjs +130 -8
- package/dist/ability/application-service.js +37 -0
- package/dist/ability/resources.js +28 -0
- package/dist/ability/runtime.js +6 -1
- package/dist/agents/claude-runner.js +7 -5
- package/dist/agents/codex/app-server-client.js +0 -12
- package/dist/agents/codex-runner.js +0 -37
- package/dist/agents/ecagent-runner.js +138 -36
- package/dist/aun/aid/agentmd.js +52 -13
- package/dist/aun/menu/client.js +8 -7
- package/dist/aun/menu/index.js +1 -1
- package/dist/aun/menu/transport.js +8 -5
- package/dist/aun/msg/p2p.js +4 -2
- package/dist/aun/service-proxy.js +3 -0
- package/dist/channels/aun.js +105 -53
- package/dist/channels/daemon.js +14 -2
- package/dist/cli/agent-command.js +5 -0
- package/dist/cli/agent-create.js +31 -11
- package/dist/cli/agent.js +9 -3
- package/dist/cli/aun-commands.js +19 -21
- package/dist/cli/daemon-commands.js +30 -18
- package/dist/cli/directory.js +98 -56
- package/dist/cli/getmeta-command.js +2 -1
- package/dist/cli/index.js +1 -1
- package/dist/cli/init.js +13 -5
- package/dist/cli/peer.js +2 -1
- package/dist/cli/task-context.js +3 -1
- package/dist/cli/trigger-command.js +20 -14
- package/dist/config/access-policy.js +0 -1
- package/dist/config/boot-log.js +12 -2
- 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 -0
- package/dist/config/config-manager.js +30 -10
- package/dist/config/peer-role-resolver.js +23 -1
- package/dist/config/role-schema.js +25 -1
- package/dist/config/role-service.js +9 -4
- package/dist/config/role-store.js +30 -8
- package/dist/config/schema-migration.js +121 -0
- package/dist/core/agent-application-service.js +11 -0
- package/dist/core/agent-ipc-registration.js +2 -0
- package/dist/core/agent-runtime.js +41 -9
- package/dist/core/auth/auth-gateway.js +14 -4
- package/dist/core/auth/operation-authorizer.js +19 -1
- package/dist/core/auth/operation-catalog.js +12 -2
- package/dist/core/baseagent-loader.js +11 -3
- package/dist/core/bootstrap-service.js +8 -0
- package/dist/core/channel-loader.js +61 -23
- package/dist/core/channel-runtime.js +5 -0
- package/dist/core/command/agent-control.js +5 -2
- package/dist/core/command/agentmd-menu-request.js +50 -0
- package/dist/core/command/agentmd-menu.js +156 -0
- package/dist/core/command/chatmode-config.js +46 -0
- package/dist/core/command/command-handler.js +44 -17
- package/dist/core/command/daemon-diagnostics.js +2 -1
- package/dist/core/command/menu-catalog.js +14 -1
- package/dist/core/command/menu-handler.js +74 -24
- package/dist/core/command/menu-protocol.js +8 -0
- package/dist/core/command/role-menu.js +23 -9
- package/dist/core/command/slash-handler.js +52 -47
- package/dist/core/daemon-lifecycle.js +43 -17
- package/dist/core/event-catalog.js +19 -0
- package/dist/core/evolagent-registry.js +3 -0
- package/dist/core/evolagent.js +5 -4
- package/dist/core/ipc-registration.js +6 -0
- package/dist/core/lifecycle-notice.js +185 -0
- package/dist/core/message/aun-ipc-sender.js +30 -24
- package/dist/core/message/contact-admission.js +1 -19
- package/dist/core/message/im-renderer.js +81 -40
- package/dist/core/message/message-admission.js +21 -62
- package/dist/core/message/message-bridge.js +18 -5
- package/dist/core/message/message-utils.js +9 -0
- package/dist/core/message/peer-mode.js +16 -8
- package/dist/core/message/response-engine.js +67 -47
- package/dist/core/model/model-capabilities.js +37 -0
- package/dist/core/model/model-catalog.js +6 -2
- package/dist/core/ownership/owner-resolver.js +74 -36
- package/dist/core/permission/ec-command-parser.js +62 -13
- package/dist/core/plugin-lifecycle.js +6 -2
- package/dist/core/relation/pa-team.js +132 -0
- package/dist/core/role/runtime-policy.js +4 -3
- package/dist/core/thread/thread-service.js +6 -4
- package/dist/directory/owner-directory-admission.js +0 -3
- package/dist/directory/owner-directory-cache.js +201 -17
- package/dist/directory/owner-directory-markdown.js +44 -21
- package/dist/directory/owner-directory-policy.js +1 -1
- package/dist/directory/owner-directory-query-operation.js +218 -98
- 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 +76 -23
- package/dist/directory/owner-directory-store.js +5 -38
- package/dist/directory/owner-directory-text.js +60 -0
- package/dist/eck/kit-renderer.js +6 -3
- package/dist/eck/message-renderer.js +2 -5
- package/dist/ecweb/message-context-service.js +4 -0
- package/dist/ecweb/runtime/lifecycle.js +29 -5
- package/dist/ecweb/runtime/supervisor.js +83 -27
- package/dist/index.js +209 -38
- package/dist/paths.js +4 -2
- package/dist/product.js +1 -0
- package/dist/proxy/service-supervisor.js +377 -141
- package/dist/response-system/engines/v1/index.js +2 -4
- package/dist/response-system/modes/single-session/index.js +1 -1
- package/dist/trigger/audit.js +3 -2
- package/dist/trigger/authorization.js +2 -3
- package/dist/trigger/history.js +4 -3
- package/dist/trigger/ipc-service.js +24 -19
- package/dist/trigger/manager.js +3 -5
- package/dist/trigger/parser.js +4 -21
- package/dist/trigger/patch.js +3 -15
- package/dist/trigger/scheduler.js +53 -13
- package/dist/trigger/validation.js +0 -13
- package/dist/utils/error-utils.js +15 -5
- package/dist/utils/macos-autostart.js +31 -0
- package/dist/utils/model-prices.jsonl +15 -8
- package/dist/utils/process-introspect.js +21 -1
- package/dist/utils/startup-trace.js +7 -1
- package/dist/utils/windows-autostart.js +1 -0
- package/ecagent/README.md +18 -0
- package/ecagent/dist/harness/agent-harness.d.ts +2 -0
- package/ecagent/dist/harness/agent-harness.js +24 -8
- package/ecagent/dist/harness/compaction/branch-summarization.js +1 -1
- package/ecagent/dist/harness/compaction/compaction.js +7 -4
- package/ecagent/dist/harness/types.d.ts +1 -0
- package/kits/docs/channels/aun.md +1 -1
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +5 -2
- package/kits/docs/evolcore/directory.md +125 -35
- package/kits/docs/evolcore/ecweb-lifecycle.md +26 -0
- package/kits/docs/evolcore/file-navigation.md +279 -0
- package/kits/docs/evolcore/menu-protocol.md +1 -0
- package/kits/docs/evolcore/model.md +5 -3
- package/kits/docs/evolcore/msg.md +1 -0
- package/kits/docs/evolcore/peer.md +2 -1
- package/kits/docs/evolcore/response.md +4 -2
- package/kits/docs/evolcore/task.md +2 -0
- package/kits/docs/evolcore/thread-chain.md +1 -1
- package/kits/docs/evolcore/tool-authorization.md +4 -1
- package/kits/docs/evolcore/trigger.md +10 -7
- package/kits/docs/identity/ROLE_DETAIL.md +2 -0
- package/kits/eck_manifest.json +6 -23
- package/kits/eck_manifest.memory.json +26 -1
- package/kits/rules/01-overview.md +42 -44
- package/kits/rules/02-navigation.md +44 -53
- package/kits/rules/03-identity.md +21 -25
- package/kits/rules/04-relation.md +23 -33
- package/kits/rules/05-venue.md +24 -25
- package/kits/schemas/_meta.json +10 -10
- package/kits/schemas/agent-config.schema.19.json +10 -6
- package/kits/schemas/relation-config.schema.12.json +2 -2
- package/kits/schemas/role-config.schema.2.json +5 -5
- package/kits/schemas/role-registry.schema.1.json +3 -2
- package/kits/skills/ec-service-proxy/SKILL.md +10 -0
- package/kits/skills/ec-trigger/SKILL.md +1 -1
- package/kits/templates/soul/00-GUIDE.md +20 -42
- package/kits/templates/system-fragments/channel.md +2 -2
- package/kits/templates/system-fragments/commands.md +1 -1
- package/kits/templates/system-fragments/directory-contacts.md +1 -1
- package/kits/templates/system-fragments/identity.md +0 -1
- package/kits/templates/system-fragments/personal-assistant.md +2 -17
- package/kits/templates/system-fragments/reply.md +7 -0
- package/kits/templates/system-fragments/session.md +6 -2
- package/package.json +18 -13
- package/dist/eck/paactive-context.js +0 -45
- package/dist/response-system/engines/v1/paactive-flow.js +0 -18
- package/kits/eck_manifest.paactive.json +0 -528
- package/kits/eck_message_manifest.paactive.json +0 -233
- package/kits/templates/message-fragments/paactive/item.md +0 -3
- package/kits/templates/system-fragments/paactive/channel.md +0 -25
- package/kits/templates/system-fragments/paactive/reply.md +0 -25
- package/kits/templates/system-fragments/paactive/session.md +0 -32
|
@@ -3,12 +3,9 @@ import { resolvePeerView, resolvePrincipal, } from '../../config/peer-book.js';
|
|
|
3
3
|
import { isValidAid } from '../../aun/aid/validation.js';
|
|
4
4
|
import { readOwnerDirectoryMembership } from '../../directory/owner-directory-admission.js';
|
|
5
5
|
import { resolveAunPeerKind } from '../relation/peer-identity.js';
|
|
6
|
-
import {
|
|
6
|
+
import { evaluateAppContactAdmission } from './contact-admission.js';
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* 顺序与入站一致:本地拉黑 → Owner/个人助理 → 黑名单 → 白名单
|
|
11
|
-
* → `allowAllContacts` 总开关 → 名录内部/外部档。
|
|
8
|
+
* AUN 出站私聊固定使用 app-v1,与入站保持相同的绑定和联系人判定。
|
|
12
9
|
* 群聊的准入单位是群,出站到群不做发言人判定。
|
|
13
10
|
*/
|
|
14
11
|
export async function evaluateOutboundContactAdmission(input) {
|
|
@@ -22,67 +19,28 @@ export async function evaluateOutboundContactAdmission(input) {
|
|
|
22
19
|
const target = await resolveAunPeerKind(selfAid, targetAid);
|
|
23
20
|
if (target.kind === 'group')
|
|
24
21
|
return { allow: true, status: 'group' };
|
|
25
|
-
let
|
|
22
|
+
let decision;
|
|
26
23
|
try {
|
|
27
|
-
|
|
24
|
+
decision = evaluateAppContactAdmission(selfAid, targetAid);
|
|
28
25
|
}
|
|
29
26
|
catch (error) {
|
|
30
27
|
return { allow: false, code: 'CONTACT_POLICY_INVALID', status: 'absent', error: error instanceof Error ? error.message : String(error) };
|
|
31
28
|
}
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
if (decision.allow)
|
|
35
|
-
return { allow: true, status: decision.reason === 'owner' ? 'owner' : decision.reason === 'temporary' ? 'temporary' : 'contact' };
|
|
36
|
-
return { allow: false, code: decision.reason === 'unavailable' ? 'CONTACT_DIRECTORY_UNAVAILABLE'
|
|
37
|
-
: decision.reason === 'blocked' ? 'CONTACT_BLOCKED' : 'CONTACT_DENIED',
|
|
38
|
-
status: decision.reason === 'unavailable' ? 'unavailable' : decision.reason === 'blocked' ? 'blocked' : 'denied',
|
|
39
|
-
error: `联系人准入未通过:${decision.reason}` };
|
|
40
|
-
}
|
|
41
|
-
let view;
|
|
42
|
-
try {
|
|
43
|
-
view = resolvePeerView(selfAid, targetAid);
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
return { allow: false, code: 'CONTACT_POLICY_INVALID', status: 'absent', error: error instanceof Error ? error.message : String(error) };
|
|
47
|
-
}
|
|
48
|
-
if (view.blocked) {
|
|
49
|
-
return { allow: false, code: 'CONTACT_BLOCKED', status: 'blocked', error: `目标 ${targetAid} 已被本端拉黑。请先解除拉黑:ec peer unblock ${targetAid} --self ${selfAid}` };
|
|
50
|
-
}
|
|
51
|
-
if (view.isOwner)
|
|
52
|
-
return { allow: true, status: 'owner' };
|
|
53
|
-
if (policy.deniedAids?.includes(targetAid)) {
|
|
54
|
-
return { allow: false, code: 'CONTACT_DENIED', status: 'denied', error: `目标 ${targetAid} 在 Owner 配置的黑名单 deniedAids 中,当前无法联系` };
|
|
55
|
-
}
|
|
56
|
-
if (policy.allowedAids?.includes(targetAid))
|
|
57
|
-
return { allow: true, status: 'allowed_aid' };
|
|
58
|
-
// 总开关:压过名录三档(含名录不可用)。拉黑与 deniedAids 已在本行之前判定。
|
|
59
|
-
if (policy.allowAllContacts === true)
|
|
60
|
-
return { allow: true, status: 'all_contacts' };
|
|
61
|
-
const membership = readOwnerDirectoryMembership(selfAid, targetAid);
|
|
62
|
-
switch (membership?.category) {
|
|
63
|
-
case 'unavailable':
|
|
64
|
-
return { allow: false, code: 'CONTACT_DIRECTORY_UNAVAILABLE', status: 'unavailable', error: 'Owner 名录当前不可用,无法确认目标身份,已拒绝发送;如需无条件联系请开启 allowAllContacts' };
|
|
65
|
-
case 'owner':
|
|
29
|
+
if (decision.allow) {
|
|
30
|
+
if (decision.reason === 'owner')
|
|
66
31
|
return { allow: true, status: 'owner' };
|
|
67
|
-
|
|
68
|
-
return { allow: true, status: '
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (membership.internal) {
|
|
73
|
-
return policy.allowInternalContacts !== false
|
|
74
|
-
? { allow: true, status: 'internal' }
|
|
75
|
-
: { allow: false, code: 'CONTACT_INTERNAL_DISABLED', status: 'disabled', error: '当前 Agent 不接受内部联系,Owner 未开启 allowInternalContacts 与 allowAllContacts' };
|
|
76
|
-
}
|
|
77
|
-
// 与入站同一判据:个人助理未显式配置时默认可以联系外部。
|
|
78
|
-
return membership.effectiveAllowExternalContacts === true
|
|
79
|
-
? { allow: true, status: 'external' }
|
|
80
|
-
: { allow: false, code: 'CONTACT_EXTERNAL_DISABLED', status: 'disabled', error: '当前 Agent 不接受外部联系,Owner 未开启 allowExternalContacts 与 allowAllContacts' };
|
|
32
|
+
if (decision.reason === 'temporary')
|
|
33
|
+
return { allow: true, status: 'temporary' };
|
|
34
|
+
if (decision.reason === 'open') {
|
|
35
|
+
const policy = readAccessPolicy(selfAid);
|
|
36
|
+
return { allow: true, status: policy.allowedAids?.includes(targetAid) ? 'allowed_aid' : 'all_contacts' };
|
|
81
37
|
}
|
|
82
|
-
|
|
83
|
-
default:
|
|
84
|
-
return { allow: false, code: 'CONTACT_ALL_CONTACTS_DISABLED', status: 'disabled', error: `目标 ${targetAid} 不在当前 Agent 的 Owner 名录中,Owner 未开启 allowAllContacts` };
|
|
38
|
+
return { allow: true, status: 'contact' };
|
|
85
39
|
}
|
|
40
|
+
return { allow: false, code: decision.reason === 'unavailable' ? 'CONTACT_DIRECTORY_UNAVAILABLE'
|
|
41
|
+
: decision.reason === 'blocked' ? 'CONTACT_BLOCKED' : 'CONTACT_DENIED',
|
|
42
|
+
status: decision.reason === 'unavailable' ? 'unavailable' : decision.reason === 'blocked' ? 'blocked' : 'denied',
|
|
43
|
+
error: `联系人准入未通过:${decision.reason}` };
|
|
86
44
|
}
|
|
87
45
|
export function evaluateInboundAdmissionPreflight(input) {
|
|
88
46
|
const selfAid = String(input.selfAid || '').trim();
|
|
@@ -166,7 +124,7 @@ export function evaluateInboundAdmissionPreflight(input) {
|
|
|
166
124
|
* 拒绝发生在业务路由之前,被拒的名录发送者不会收到自动回复。
|
|
167
125
|
*/
|
|
168
126
|
export function evaluateOwnerDirectoryInboundAdmission(context) {
|
|
169
|
-
if (context.channelType === 'aun'
|
|
127
|
+
if (context.channelType === 'aun')
|
|
170
128
|
return undefined;
|
|
171
129
|
if (context.trustedHandoffEcho || context.isOwner || !context.primaryId || !context.policy)
|
|
172
130
|
return undefined;
|
|
@@ -226,10 +184,11 @@ function evaluateOrdinaryAdmission(context) {
|
|
|
226
184
|
return { allow: true, reason: 'owner', context };
|
|
227
185
|
return { allow: true, reason: 'group_channel_allowed', context };
|
|
228
186
|
}
|
|
229
|
-
// Owner
|
|
230
|
-
|
|
187
|
+
// Non-AUN channels retain their Owner shortcut; AUN Owner admission comes
|
|
188
|
+
// from the current app-v1 relation binding below.
|
|
189
|
+
if (context.isOwner && context.channelType !== 'aun')
|
|
231
190
|
return { allow: true, reason: 'owner', context };
|
|
232
|
-
if (context.channelType === 'aun'
|
|
191
|
+
if (context.channelType === 'aun') {
|
|
233
192
|
const decision = evaluateAppContactAdmission(context.selfAid, context.primaryId ?? context.actorId);
|
|
234
193
|
if (decision.allow)
|
|
235
194
|
return { allow: true, reason: decision.reason === 'owner' ? 'owner'
|
|
@@ -5,6 +5,8 @@ import { createHash, randomBytes } from 'crypto';
|
|
|
5
5
|
import fs from 'fs';
|
|
6
6
|
import path from 'path';
|
|
7
7
|
import { agentStorageMenuService, isAgentStorageMenuRequest } from '../command/agent-storage-menu.js';
|
|
8
|
+
import { agentMdMenuService } from '../command/agentmd-menu.js';
|
|
9
|
+
import { containsAgentMdMenuRequest } from '../command/agentmd-menu-request.js';
|
|
8
10
|
import { logger, logPreview } from '../../utils/logger.js';
|
|
9
11
|
import { StreamDebouncer } from './stream-debouncer.js';
|
|
10
12
|
import { appendMessageLog, appendMessageLogStrict, buildInboundEntry, isTransientProtocolMessage } from './message-log.js';
|
|
@@ -17,6 +19,7 @@ import { listStaticAgentAdmins, listStaticAgentOwners, resolvePeerRoleDetail, }
|
|
|
17
19
|
import { resolvePeerView, resolvePeerDisplayLabel, resolvePrincipal } from '../../config/peer-book.js';
|
|
18
20
|
import { findPeerRequestNote, expirePendingPeerRequests, reviewPeerRequest, submitPeerRequest, peerRequestSubmissionProtocolResult, queryOwnPeerRequestStatus, } from '../../config/peer-request-service.js';
|
|
19
21
|
import { isValidAid } from '../../aun/aid/validation.js';
|
|
22
|
+
import { prepareOwnerDirectoryAdmission } from '../../directory/owner-directory-admission.js';
|
|
20
23
|
import { PeerIdentityCache, formatPeerKey } from '../relation/peer-identity.js';
|
|
21
24
|
import { ownerResolver, refreshOwnershipForAuthorization, OWNERSHIP_CACHE_MAX_AGE_MS } from '../ownership/owner-resolver.js';
|
|
22
25
|
import { isTopicSession, sessionLocalTopicId } from '../thread/topic-id.js';
|
|
@@ -39,7 +42,6 @@ import { createAgentPolicyAuthorization, createSessionFullAccessAuthorization }
|
|
|
39
42
|
import { auditFullAccessEvent } from '../auth/authorization-audit.js';
|
|
40
43
|
import { DIAGNOSTIC_AGENT_AID, DiagnosticSessionRouter, parseDiagnosticEvent, isDiagnosticSessionActive } from '../command/diag-service.js';
|
|
41
44
|
import { consumeAdmissionReplyBudget, clearAdmissionReplyBudgets, evaluateInboundAdmissionPreflight, evaluateOrdinaryInboundAdmission, evaluateOwnerDirectoryInboundAdmission, } from './message-admission.js';
|
|
42
|
-
import { prepareOwnerDirectoryAdmission } from '../../directory/owner-directory-admission.js';
|
|
43
45
|
const CONTACT_REJECTION_NOTICE = '[rejection] Not accepting messages from you.';
|
|
44
46
|
const REJECTABLE_PEER_TYPES = new Set(['ai', 'bot', 'agent', 'service']);
|
|
45
47
|
const REJECTION_MAX = 3;
|
|
@@ -481,7 +483,7 @@ export class MessageBridge {
|
|
|
481
483
|
catch { /* slash command */ }
|
|
482
484
|
if (!requestMatch && !protocolType)
|
|
483
485
|
return false;
|
|
484
|
-
if (context.channelType === 'aun'
|
|
486
|
+
if (context.channelType === 'aun') {
|
|
485
487
|
// The App owns requests; retired commands cannot create a second approval state.
|
|
486
488
|
return true;
|
|
487
489
|
}
|
|
@@ -925,7 +927,8 @@ export class MessageBridge {
|
|
|
925
927
|
actorId,
|
|
926
928
|
trustedHandoffEcho,
|
|
927
929
|
});
|
|
928
|
-
if (admissionPreflight.allow &&
|
|
930
|
+
if (admissionPreflight.allow && resolvedChannelType !== 'aun'
|
|
931
|
+
&& !trustedHandoffEcho && !admissionPreflight.context.isOwner) {
|
|
929
932
|
if (selfAid && admissionPreflight.context.primaryId) {
|
|
930
933
|
await prepareOwnerDirectoryAdmission(selfAid, admissionPreflight.context.primaryId);
|
|
931
934
|
}
|
|
@@ -1011,7 +1014,7 @@ export class MessageBridge {
|
|
|
1011
1014
|
const admissionDecision = evaluateOrdinaryInboundAdmission(admissionPreflight.context);
|
|
1012
1015
|
// 名录不可用等硬性拒绝不回自动提示,静默丢弃;其余拒绝才发控制面提示。
|
|
1013
1016
|
const directoryDenied = !admissionDecision.allow && (admissionDecision.reason === 'owner_directory_unavailable');
|
|
1014
|
-
const appControl = resolvedChannelType === 'aun' &&
|
|
1017
|
+
const appControl = resolvedChannelType === 'aun' && menuControl.isMenu;
|
|
1015
1018
|
if (!appControl && !admissionDecision.allow && (!isPrivateMenuTokenRequest || directoryDenied)) {
|
|
1016
1019
|
if (chatType === 'private' && !directoryDenied) {
|
|
1017
1020
|
if (menuControl.isMenu) {
|
|
@@ -1869,6 +1872,7 @@ export class MessageBridge {
|
|
|
1869
1872
|
...authSubject,
|
|
1870
1873
|
requestId: parsed.id,
|
|
1871
1874
|
menuEncrypted: msg.encrypted === true,
|
|
1875
|
+
menuTransportChatType: msg.chatType || 'private',
|
|
1872
1876
|
fromControlChannel: authSubject.fromControlChannel || msg.isControlChannel === true,
|
|
1873
1877
|
...(activeSession?.id ? { sessionId: activeSession.id } : {}),
|
|
1874
1878
|
};
|
|
@@ -1928,6 +1932,15 @@ export class MessageBridge {
|
|
|
1928
1932
|
}));
|
|
1929
1933
|
return;
|
|
1930
1934
|
}
|
|
1935
|
+
if (deduped.replayed && containsAgentMdMenuRequest(parsed.request)) {
|
|
1936
|
+
try {
|
|
1937
|
+
await agentMdMenuService.preflight(menuAuthSubject);
|
|
1938
|
+
}
|
|
1939
|
+
catch (error) {
|
|
1940
|
+
await this.sendMenuResponse(adapter, channel, msg, menuFailure(header, normalizeMenuError(error)));
|
|
1941
|
+
return;
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1931
1944
|
// A replay may have awaited an in-flight request; check again before release.
|
|
1932
1945
|
if (isStorageRequest) {
|
|
1933
1946
|
try {
|
|
@@ -2151,7 +2164,7 @@ export class MessageBridge {
|
|
|
2151
2164
|
metadata: {
|
|
2152
2165
|
...(msg.replyContext?.metadata ?? {}),
|
|
2153
2166
|
...evolMenuResponseTransportMetadata(msg.protectedHeaders?.sdk_version, msg.protectedHeaders?.menu_volatile_v1),
|
|
2154
|
-
...(isAgentStorageMenuRequest(request) ? { encrypted: true } : {}),
|
|
2167
|
+
...(isAgentStorageMenuRequest(request) || containsAgentMdMenuRequest(request) ? { encrypted: true } : {}),
|
|
2155
2168
|
},
|
|
2156
2169
|
};
|
|
2157
2170
|
if (msg.channelType === 'aun' && !replyContext.delivery) {
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { sessionLocalTopicId, sessionTopicThreadId } from '../thread/topic-id.js';
|
|
2
2
|
import { renderCommandCardAsText, renderActionAsText } from '../interaction-router.js';
|
|
3
|
+
export const DEFAULT_NOOP_SENTINEL = '[[NOOP]]';
|
|
4
|
+
export function isNoopText(text, sentinel = DEFAULT_NOOP_SENTINEL) {
|
|
5
|
+
return sentinel.length > 0 && text.trimStart().startsWith(sentinel);
|
|
6
|
+
}
|
|
7
|
+
export function mayBeNoopText(text, sentinel = DEFAULT_NOOP_SENTINEL) {
|
|
8
|
+
const prefix = text.trimStart();
|
|
9
|
+
return sentinel.length > 0 && prefix.length > 0
|
|
10
|
+
&& (sentinel.startsWith(prefix) || prefix.startsWith(sentinel));
|
|
11
|
+
}
|
|
3
12
|
/** A legacy adapter resolved its send call without providing a structured receipt. */
|
|
4
13
|
export const LEGACY_INTERACTION_ACCEPTED = 'legacy-accepted';
|
|
5
14
|
export function isInteractionSendAccepted(result) {
|
|
@@ -7,18 +7,20 @@ export const CHAT_MODES = ['interactive', 'proactive', 'paactive'];
|
|
|
7
7
|
export function isChatMode(value) {
|
|
8
8
|
return CHAT_MODES.includes(value);
|
|
9
9
|
}
|
|
10
|
-
/** PA output is supported only in active AUN human
|
|
10
|
+
/** PA output is supported only in active AUN human Owner conversations. */
|
|
11
11
|
export function supportsPaactive(params) {
|
|
12
12
|
const channelType = params.channelType ?? params.peerKey?.split('#')[0];
|
|
13
13
|
return channelType === 'aun'
|
|
14
14
|
&& params.chatType === 'private'
|
|
15
15
|
&& normalizePeerType(params.peerType) === 'human'
|
|
16
|
-
&&
|
|
16
|
+
&& params.role === 'owner'
|
|
17
17
|
&& (params.lifecycle === undefined || params.lifecycle === 'active')
|
|
18
18
|
&& (params.sessionType === undefined || params.sessionType === 'main');
|
|
19
19
|
}
|
|
20
20
|
/** Keep unsupported inherited PA settings from becoming output-as-reply mode. */
|
|
21
21
|
export function chatModeForScene(value, params) {
|
|
22
|
+
if (params.chatType === 'group' || normalizePeerType(params.peerType) === 'group')
|
|
23
|
+
return 'proactive';
|
|
22
24
|
if (value === 'paactive' && supportsPaactive(params))
|
|
23
25
|
return value;
|
|
24
26
|
if (value === 'interactive' || value === 'proactive')
|
|
@@ -51,14 +53,18 @@ export function resolveChatMode(params) {
|
|
|
51
53
|
configured = undefined;
|
|
52
54
|
}
|
|
53
55
|
const kind = normalizePeerType(params.peerType);
|
|
56
|
+
// Group conversations always use proactive delivery; interactive and
|
|
57
|
+
// paactive are private-chat presentation modes.
|
|
58
|
+
if (params.chatType === 'group' || kind === 'group')
|
|
59
|
+
return 'proactive';
|
|
54
60
|
// 运行时硬约束(非配置项):system/service 始终 interactive;agent 始终 proactive
|
|
55
61
|
if (kind === 'system' || kind === 'service')
|
|
56
62
|
return 'interactive';
|
|
57
63
|
if (kind === 'agent')
|
|
58
64
|
return 'proactive';
|
|
59
65
|
const field = chatmodeFieldForPeer(params.chatType, params.peerType);
|
|
60
|
-
//
|
|
61
|
-
//
|
|
66
|
+
// 人类私聊的基础角色门槛:owner/admin 才解析分层配置;
|
|
67
|
+
// paactive 另由 supportsPaactive 限定为 owner,其余角色直接 proactive。
|
|
62
68
|
if (isPrivateChatmodeRoleLocked(field, params.role))
|
|
63
69
|
return 'proactive';
|
|
64
70
|
const decision = resolveRuntimeStringField({
|
|
@@ -72,7 +78,7 @@ export function resolveChatMode(params) {
|
|
|
72
78
|
}
|
|
73
79
|
/**
|
|
74
80
|
* 人类私聊(chatmode.private)是否被角色锁定为 proactive。
|
|
75
|
-
* owner/admin
|
|
81
|
+
* interactive 需要 owner/admin;paactive 在此基础上另由 supportsPaactive 限定为 owner。
|
|
76
82
|
*/
|
|
77
83
|
export function isPrivateChatmodeRoleLocked(field, role) {
|
|
78
84
|
return field === 'private' && !isManagementRole(role);
|
|
@@ -127,7 +133,7 @@ export function isSystemOrServicePeer(peerType) {
|
|
|
127
133
|
}
|
|
128
134
|
/**
|
|
129
135
|
* 解析某会话对端的 chatMode。优先级(高→低):
|
|
130
|
-
* 1.
|
|
136
|
+
* 1. 群聊固定 proactive;私聊 system/service 对端始终 interactive(非配置项)
|
|
131
137
|
* 2. 合并后的 chatmode 场景表 `configured`(chatmode.{private|group|nothuman})——
|
|
132
138
|
* 关系级与 agent 级同名字典,已由 ConfigManager 按 x-merge:dict 逐键合并
|
|
133
139
|
* 3. schema 出厂默认表 `chatmodeFactoryDefaults()`
|
|
@@ -137,6 +143,8 @@ export function isSystemOrServicePeer(peerType) {
|
|
|
137
143
|
*/
|
|
138
144
|
export function resolveChatModeForPeer(params) {
|
|
139
145
|
const kind = normalizePeerType(params.peerType);
|
|
146
|
+
if (params.chatType === 'group' || kind === 'group')
|
|
147
|
+
return 'proactive';
|
|
140
148
|
// 运行时硬约束(非配置项):system/service 对端始终同步交互;agent 对端始终主动响应
|
|
141
149
|
if (kind === 'system' || kind === 'service')
|
|
142
150
|
return 'interactive';
|
|
@@ -163,10 +171,10 @@ export function chatmodeFactoryDefaults() {
|
|
|
163
171
|
}
|
|
164
172
|
export function chatmodeFieldForPeer(chatType, peerType) {
|
|
165
173
|
const kind = normalizePeerType(peerType);
|
|
166
|
-
if (kind === 'system' || kind === 'service')
|
|
167
|
-
return 'private';
|
|
168
174
|
if (chatType === 'group' || kind === 'group')
|
|
169
175
|
return 'group';
|
|
176
|
+
if (kind === 'system' || kind === 'service')
|
|
177
|
+
return 'private';
|
|
170
178
|
if (kind === 'agent' || kind === 'unknown')
|
|
171
179
|
return 'nothuman';
|
|
172
180
|
return 'private';
|
|
@@ -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';
|
|
@@ -40,9 +42,8 @@ import { recordCausationLink, recordCausationSpan } from '../causation/audit.js'
|
|
|
40
42
|
import { normalizeBaseagent, resolveBaseagentModelSelection, resolveRuntimeBaseagentModelSelection } from '../../agents/baseagent.js';
|
|
41
43
|
import { renderActionAsText } from '../interaction-router.js';
|
|
42
44
|
import { formatPeerKey, parsePeerKey } from '../relation/peer-identity.js';
|
|
43
|
-
import { buildEnvelope, isInteractionSendAccepted, replyContextFromSession, sendInteractionPayload, withEnvelopeReplyContext } from './message-utils.js';
|
|
45
|
+
import { buildEnvelope, isInteractionSendAccepted, isNoopText, replyContextFromSession, sendInteractionPayload, withEnvelopeReplyContext } from './message-utils.js';
|
|
44
46
|
import { chatModeForScene, isSystemOrServicePeer, resolveChatMode } from './peer-mode.js';
|
|
45
|
-
import { buildPaactiveSystemVars, buildPaactiveMessageVars, paactiveSystemManifest } from '../../eck/paactive-context.js';
|
|
46
47
|
import { AGENT_DELEGATION_TOKEN_ENV } from '../auth/agent-delegation.js';
|
|
47
48
|
import { hasTrustedPrincipal } from '../auth/authenticated-actor.js';
|
|
48
49
|
import { isValidAid } from '../../aun/aid/identity.js';
|
|
@@ -2438,7 +2439,7 @@ export class ResponseEngine {
|
|
|
2438
2439
|
.catch(error => logger.warn(`[ResponseEngine] compact-start notice send failed: ${error instanceof Error ? error.message : String(error)}`));
|
|
2439
2440
|
}
|
|
2440
2441
|
async emitOperationalNotice(renderer, text, severity, subtype) {
|
|
2441
|
-
if (await renderer.
|
|
2442
|
+
if (await renderer.sendOperationalNotice(text, subtype))
|
|
2442
2443
|
return;
|
|
2443
2444
|
renderer.addNotice(text, severity, subtype, true);
|
|
2444
2445
|
}
|
|
@@ -2488,7 +2489,7 @@ export class ResponseEngine {
|
|
|
2488
2489
|
}
|
|
2489
2490
|
: modelOverride;
|
|
2490
2491
|
// text event 在进入 renderer 前已经剔除了上下文超限错误行。保留缓冲中的
|
|
2491
|
-
// 有效正文,由
|
|
2492
|
+
// 有效正文,由 sendOperationalNotice 先 flush,避免恢复过程丢失已有模型输出。
|
|
2492
2493
|
await this.emitOperationalNotice(renderer, '上下文过长,正在压缩会话...', 'warn', 'compact-trigger');
|
|
2493
2494
|
await renderer.flush();
|
|
2494
2495
|
this.announcedCompactStarts.add(session.id);
|
|
@@ -2667,12 +2668,10 @@ export class ResponseEngine {
|
|
|
2667
2668
|
}
|
|
2668
2669
|
}
|
|
2669
2670
|
async assertCurrentExecutionAuthorization(context, agent) {
|
|
2671
|
+
await assertOwnershipAuthorization(context);
|
|
2670
2672
|
if (context.executionPermission) {
|
|
2671
2673
|
await this.assertCurrentFullAccessExecutionAuthorization(context.executionPermission, agent);
|
|
2672
2674
|
}
|
|
2673
|
-
else {
|
|
2674
|
-
await assertOwnershipAuthorization(context);
|
|
2675
|
-
}
|
|
2676
2675
|
}
|
|
2677
2676
|
/**
|
|
2678
2677
|
* The authorization envelope is immutable for one logical run, but the
|
|
@@ -3026,6 +3025,18 @@ export class ResponseEngine {
|
|
|
3026
3025
|
const accessAdapter = accessChannelInfo?.adapter;
|
|
3027
3026
|
const accessAdapterSelfAid = typeof accessAdapter?._selfAid === 'function' ? accessAdapter._selfAid() : undefined;
|
|
3028
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
|
+
}
|
|
3029
3040
|
await refreshOwnershipForAuthorization(selfAidForAccess, {
|
|
3030
3041
|
maxAgeMs: OWNERSHIP_CACHE_MAX_AGE_MS,
|
|
3031
3042
|
allowTransient: true,
|
|
@@ -3651,6 +3662,15 @@ export class ResponseEngine {
|
|
|
3651
3662
|
const selfName = registrySelfName ?? adapterSelfName;
|
|
3652
3663
|
const peerName = message.peerName || session.metadata?.peerName;
|
|
3653
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
|
+
}
|
|
3654
3674
|
const triggerExecutionIdentity = this.resolveTriggerExecutionIdentity(message, selfAid);
|
|
3655
3675
|
const authorizationIdentity = triggerExecutionIdentity
|
|
3656
3676
|
?? this.resolveHandoffOriginExecutionIdentity(message, selfAid);
|
|
@@ -3673,6 +3693,9 @@ export class ResponseEngine {
|
|
|
3673
3693
|
? formatPeerKey(configChannelType, peerKeyId)
|
|
3674
3694
|
: undefined);
|
|
3675
3695
|
const peerType = message.peerType ?? session.metadata?.peerType;
|
|
3696
|
+
if (configChannelType === 'aun' && configChatType === 'private') {
|
|
3697
|
+
await preparePaTeamQualification(selfAid, configActorId);
|
|
3698
|
+
}
|
|
3676
3699
|
const peerRoleDetail = authorizationIdentity ? undefined : (() => {
|
|
3677
3700
|
try {
|
|
3678
3701
|
return resolvePeerRoleDetail({
|
|
@@ -3743,11 +3766,13 @@ export class ResponseEngine {
|
|
|
3743
3766
|
});
|
|
3744
3767
|
// Resolve overrides before binding a flow so hooks, context and envelope
|
|
3745
3768
|
// all use the same scene-checked mode for this task.
|
|
3746
|
-
const effectiveChatMode =
|
|
3747
|
-
? '
|
|
3748
|
-
:
|
|
3749
|
-
?
|
|
3750
|
-
:
|
|
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;
|
|
3751
3776
|
const responseModeAgentDir = selfAid ? resolveAgentDir(selfAid) : undefined;
|
|
3752
3777
|
// mentionMode:顶层通用参数(先读出备用,投递/入队策略后续接入)
|
|
3753
3778
|
const mentionMode = effectiveAgentConfig?.mentionMode ?? 'disabled';
|
|
@@ -3797,11 +3822,9 @@ export class ResponseEngine {
|
|
|
3797
3822
|
: isShowActivitiesMode(effectiveAgentConfig?.show_activities)
|
|
3798
3823
|
? effectiveAgentConfig.show_activities
|
|
3799
3824
|
: legacyMiddleOutputMode();
|
|
3800
|
-
const middleOutputMode = isProactive
|
|
3801
|
-
? '
|
|
3802
|
-
:
|
|
3803
|
-
? 'none'
|
|
3804
|
-
: configuredMiddleOutputMode;
|
|
3825
|
+
const middleOutputMode = systemOrServicePeer && !isProactive
|
|
3826
|
+
? 'none'
|
|
3827
|
+
: configuredMiddleOutputMode;
|
|
3805
3828
|
outputState.middleOutputMode = middleOutputMode;
|
|
3806
3829
|
// 诊断日志:记录 inbound message_id 和生成的 task_id 的对应关系
|
|
3807
3830
|
logger.info(`[ResponseEngine] task.started: inboundMsgId=${message.messageId ?? 'none'} taskId=${taskId} sessionId=${session.id} chatmode=${chatmode} mode=${resolvedMode?.mode.id ?? 'override/fallback'}`);
|
|
@@ -4269,11 +4292,11 @@ export class ResponseEngine {
|
|
|
4269
4292
|
agentAid: session.selfAID,
|
|
4270
4293
|
permissionMode: () => effectivePermissionMode,
|
|
4271
4294
|
flushDelay: (options?.flushDelay ?? this.agentRegistry?.resolveByChannel(channelKey)?.config?.flush_delay ?? 3) * 1000,
|
|
4272
|
-
suppressActivityItems:
|
|
4273
|
-
suppressIntermediateText:
|
|
4295
|
+
suppressActivityItems: middleOutputMode !== 'all',
|
|
4296
|
+
suppressIntermediateText: middleOutputMode === 'none',
|
|
4274
4297
|
deferTextUntilBoundary: (message.channelType ?? session.channelType) === 'aun' && session.chatType === 'private',
|
|
4275
4298
|
noopSentinel: message.source === 'trigger' ? message.triggerMeta?.noopSentinel : undefined,
|
|
4276
|
-
|
|
4299
|
+
operationalNoticesEnabled: !isProactive && middleOutputMode !== 'none',
|
|
4277
4300
|
fileMarkerPattern: options?.fileMarkerPattern,
|
|
4278
4301
|
recordActivity: async (item, activityId) => {
|
|
4279
4302
|
if (!taskActivityStore || (turnLease && !this.turnCoordinator.canPublish(turnLease)))
|
|
@@ -4377,7 +4400,7 @@ export class ResponseEngine {
|
|
|
4377
4400
|
}
|
|
4378
4401
|
renderer.addLifecycle('started');
|
|
4379
4402
|
if (isProactive) {
|
|
4380
|
-
logger.info(`[ResponseEngine] proactive mode:
|
|
4403
|
+
logger.info(`[ResponseEngine] proactive mode: thought visibility=${middleOutputMode} task=${taskId}`);
|
|
4381
4404
|
}
|
|
4382
4405
|
// 调用 AgentRunner(含上下文过长自动 compact 重试)
|
|
4383
4406
|
// 捕获当前消息的上下文(闭包),避免后续消息处理时串台
|
|
@@ -4618,6 +4641,15 @@ export class ResponseEngine {
|
|
|
4618
4641
|
chatmode: effectiveChatMode,
|
|
4619
4642
|
// 系统会话没有角色
|
|
4620
4643
|
role: systemSessionMarker ? undefined : peerRole,
|
|
4644
|
+
internalContactAuthorization: !systemSessionMarker && configChannelType === 'aun' && configChatType === 'private'
|
|
4645
|
+
&& !!selfAid && !!configActorId && (paTeamQualification(selfAid, configActorId) === 'matched'
|
|
4646
|
+
|| requiresPaTeamVerification(selfAid, configActorId)),
|
|
4647
|
+
internalContactDefaultRole: peerRoleDetail?.source === 'internal-contact-default'
|
|
4648
|
+
|| (authorizationIdentity?.role === peerRole && configChannelType === 'aun'
|
|
4649
|
+
&& configChatType === 'private' && !!selfAid && !!configActorId
|
|
4650
|
+
&& resolvePeerRoleDetail({ selfAid, channelKey: authorizationIdentity.originChannelKey, channelType: 'aun', chatType: 'private',
|
|
4651
|
+
actorId: configActorId, conversationId: configActorId }).source === 'internal-contact-default'),
|
|
4652
|
+
internalContactPolicy: JSON.stringify(getRoleDefinition(peerRole, selfAid)),
|
|
4621
4653
|
chatType: authChatType,
|
|
4622
4654
|
selfAid,
|
|
4623
4655
|
managedTempDir: sessionRuntimeDir,
|
|
@@ -5382,6 +5414,8 @@ export class ResponseEngine {
|
|
|
5382
5414
|
// Stage 3: sessionKey 持久化字段
|
|
5383
5415
|
sessionKey: session.sessionKey,
|
|
5384
5416
|
chatMode: effectiveChatMode,
|
|
5417
|
+
// Message templates receive the same derived reply fact as system templates.
|
|
5418
|
+
activePush: effectiveChatMode === 'proactive' || effectiveChatMode === 'paactive',
|
|
5385
5419
|
isTriggerTask: causationPath.length > 0 || message.source === 'trigger',
|
|
5386
5420
|
readonly: effectivePermissionMode === 'readonly',
|
|
5387
5421
|
baseAgent: normalizedBaseagent.canonical,
|
|
@@ -5397,13 +5431,9 @@ export class ResponseEngine {
|
|
|
5397
5431
|
},
|
|
5398
5432
|
sessionId: session.id,
|
|
5399
5433
|
};
|
|
5400
|
-
if (effectiveChatMode === '
|
|
5401
|
-
kitCtx.vars = buildPaactiveSystemVars(kitCtx.vars);
|
|
5402
|
-
}
|
|
5403
|
-
else {
|
|
5434
|
+
if (effectiveChatMode === 'proactive') {
|
|
5404
5435
|
Object.assign(kitCtx.vars, {
|
|
5405
|
-
//
|
|
5406
|
-
// 默认值不在此硬编码,出厂默认由模式 schema 声明、经 buildState 落入 proactive.*。
|
|
5436
|
+
// Proactive policy variables are scoped to proactive tasks only.
|
|
5407
5437
|
proactivePreTool1stMsgChk: proactive?.preTool1stMsgChk ?? false,
|
|
5408
5438
|
proactiveToolUseReminder: proactive?.toolUseReminder ?? false,
|
|
5409
5439
|
// 明确续跑已表态时,提示词和运行时门禁都不再要求重复开场。
|
|
@@ -5413,8 +5443,7 @@ export class ResponseEngine {
|
|
|
5413
5443
|
proactiveSendTargetLabel: chatType === 'group' ? '群里' : '对方',
|
|
5414
5444
|
});
|
|
5415
5445
|
}
|
|
5416
|
-
const messageVars =
|
|
5417
|
-
? buildPaactiveMessageVars(kitCtx.vars) : kitCtx.vars;
|
|
5446
|
+
const messageVars = kitCtx.vars;
|
|
5418
5447
|
// 确保技能索引是最新的(懒加载机制)
|
|
5419
5448
|
if (selfAid) {
|
|
5420
5449
|
const { ensureSkillIndexUpToDate } = await import('../skill/startup.js');
|
|
@@ -5431,9 +5460,7 @@ export class ResponseEngine {
|
|
|
5431
5460
|
? DEFAULT_MANIFEST_FILE
|
|
5432
5461
|
: systemSessionMarker
|
|
5433
5462
|
? getSystemSessionModule(systemSessionMarker.type).manifest(systemSessionMarker.subtype)
|
|
5434
|
-
:
|
|
5435
|
-
? paactiveSystemManifest(kitCtx.vars)
|
|
5436
|
-
: resolveSessionManifest(sessionType, sessionManifests);
|
|
5463
|
+
: resolveSessionManifest(sessionType, sessionManifests);
|
|
5437
5464
|
const kitContext = renderKitSections(kitCtx, manifestFile);
|
|
5438
5465
|
effectiveSystemPrompt = [options?.systemPromptAppend, kitContext].filter(Boolean).join('\n') || undefined;
|
|
5439
5466
|
// ── Stats: context_breakdown 旁路采集(各段估算 token 数,字符数/4 近似) ──
|
|
@@ -5586,8 +5613,6 @@ export class ResponseEngine {
|
|
|
5586
5613
|
effectivePrompt = wrapPrompt(composeHintFallback(hintItems, fallbackContent));
|
|
5587
5614
|
}
|
|
5588
5615
|
catch (e) {
|
|
5589
|
-
if (effectiveChatMode === 'paactive')
|
|
5590
|
-
throw e;
|
|
5591
5616
|
logger.warn(`[ResponseEngine] renderMessageBody failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
5592
5617
|
if (ownerHintClaim) {
|
|
5593
5618
|
observerHintFailureCode = 'RENDER_FAILED';
|
|
@@ -6230,12 +6255,11 @@ export class ResponseEngine {
|
|
|
6230
6255
|
// 由响应模式插件统一处理(InteractiveMode.afterProcess / ProactiveMode.afterProcess)
|
|
6231
6256
|
const finalReplyText = streamResult.lastReplyText || streamResult.fullText;
|
|
6232
6257
|
const visibleFinalReplyText = stripContextLimitErrorLines(finalReplyText);
|
|
6233
|
-
const
|
|
6234
|
-
|
|
6235
|
-
&& !streamResult.isError
|
|
6258
|
+
const triggerNoopSentinel = message.source === 'trigger' ? message.triggerMeta?.noopSentinel : undefined;
|
|
6259
|
+
const isNoopReply = !!triggerNoopSentinel && !streamResult.isError
|
|
6236
6260
|
&& !isExpectedTerminalInterrupt(streamResult.terminalReason)
|
|
6237
|
-
&&
|
|
6238
|
-
if (resolvedMode?.mode.afterProcess && !
|
|
6261
|
+
&& isNoopText(visibleFinalReplyText, triggerNoopSentinel);
|
|
6262
|
+
if (resolvedMode?.mode.afterProcess && !isNoopReply) {
|
|
6239
6263
|
const flusherText = renderer.getFinalText();
|
|
6240
6264
|
const fullText = flusherText.length >= (streamResult.fullText?.length || 0) ? flusherText : streamResult.fullText;
|
|
6241
6265
|
await resolvedMode.mode.afterProcess({
|
|
@@ -6379,7 +6403,7 @@ export class ResponseEngine {
|
|
|
6379
6403
|
sentErrorAsSystemError = await projectTerminalReply({
|
|
6380
6404
|
isCurrent: () => !turnLease || this.turnCoordinator.canPublish(turnLease),
|
|
6381
6405
|
isInterrupted: () => terminalInterrupt || isNonErrorInterruptReason(this.interruptedSessions.get(session.id)),
|
|
6382
|
-
isNoop:
|
|
6406
|
+
isNoop: isNoopReply,
|
|
6383
6407
|
discardText: () => renderer.discardPendingText(),
|
|
6384
6408
|
isError: streamResult.isError,
|
|
6385
6409
|
text: visibleFinalReplyText,
|
|
@@ -6415,7 +6439,7 @@ export class ResponseEngine {
|
|
|
6415
6439
|
logger.info(`[ResponseEngine] task.finished: session=${session.id} task=${taskId} outcome=${terminalInterrupt ? 'interrupted' : streamResult.isError ? 'error' : 'completed'}`);
|
|
6416
6440
|
import('../../utils/msg-diag.js').then(m => m.diagLog('task_done', { aid: session.selfAID ?? '', msgId: message.messageId ?? '', taskId, text: message.content ?? '' })).catch(() => { });
|
|
6417
6441
|
// 降级模型回复末尾追加标记(代码层硬注入,不依赖模型输出)
|
|
6418
|
-
if (usedFallback && !
|
|
6442
|
+
if (usedFallback && !isNoopReply) {
|
|
6419
6443
|
const curFbState = this.modelFallbackMap.get(session.id);
|
|
6420
6444
|
const showHint = curFbState && curFbState.nextProbeAt >= 8 && !curFbState.hintShown;
|
|
6421
6445
|
const suffix = showHint
|
|
@@ -7136,7 +7160,7 @@ export class ResponseEngine {
|
|
|
7136
7160
|
await adapter.send(withEnvelopeReplyContext(envelope, sendOpts), errorPayload);
|
|
7137
7161
|
}
|
|
7138
7162
|
// Proactive 可观测:catch 块的基础设施错误也透传为 thought,保证按 task_id 聚合完整
|
|
7139
|
-
if (isProactive && adapter.capabilities?.thought) {
|
|
7163
|
+
if (isProactive && adapter.capabilities?.thought && middleOutputMode === 'all') {
|
|
7140
7164
|
await adapter.send(withEnvelopeReplyContext(envelope, sendOpts), {
|
|
7141
7165
|
kind: 'activity.batch',
|
|
7142
7166
|
items: [{
|
|
@@ -7317,12 +7341,8 @@ export class ResponseEngine {
|
|
|
7317
7341
|
}
|
|
7318
7342
|
if (totalTokens <= 0)
|
|
7319
7343
|
return undefined;
|
|
7320
|
-
// 单次请求的上下文不可能超过模型窗口。超过(留 5% 余量容纳输出侧计数)
|
|
7321
|
-
// 说明这行记的不是单次上下文,而是整轮累计用量——历史行里出现过
|
|
7322
|
-
// cache_read 被累加成 119 万的记录,它会让自动压缩在每个任务开始时
|
|
7323
|
-
// 重复触发。这类行一律不参与压缩判断。
|
|
7324
7344
|
const maxTokens = row.max_tokens ?? 0;
|
|
7325
|
-
if (maxTokens > 0 && totalTokens > maxTokens * 1.05) {
|
|
7345
|
+
if (!(recordedTotalTokens && recordedTotalTokens > 0) && maxTokens > 0 && totalTokens > maxTokens * 1.05) {
|
|
7326
7346
|
logger.warn(`[ResponseEngine] Ignoring implausible context_tokens: session=${sessionId} totalTokens=${totalTokens} maxTokens=${maxTokens}`);
|
|
7327
7347
|
return undefined;
|
|
7328
7348
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { findModelSpec } from '../../stats/price-resolver.js';
|
|
2
|
+
import { resolveCatalogModel } from './catalog-service.js';
|
|
3
|
+
import { parseModelId } from './context-window-suffix.js';
|
|
4
|
+
export function resolveModelCapabilities(evolcoreHome, modelId, options) {
|
|
5
|
+
const model = options.catalog ? resolveCatalogModel(options.catalog, modelId) : modelId;
|
|
6
|
+
const entry = options.catalog?.models.find(candidate => candidate.id === model);
|
|
7
|
+
const spec = findModelSpec(evolcoreHome, model);
|
|
8
|
+
const positiveToken = (value) => typeof value === 'number' && Number.isFinite(value) && value >= 1;
|
|
9
|
+
const windowCandidates = [
|
|
10
|
+
[parseModelId(model).contextWindow, 'explicit-suffix'],
|
|
11
|
+
[options.runtimeContextWindow, 'runtime-report'],
|
|
12
|
+
[entry?.contextWindow, 'provider-catalog'],
|
|
13
|
+
[spec?.context_window, 'local-parameters'],
|
|
14
|
+
[options.fallbackContextWindow, 'safe-fallback'],
|
|
15
|
+
];
|
|
16
|
+
const outputCandidates = [
|
|
17
|
+
[entry?.maxOutputTokens, 'provider-catalog'],
|
|
18
|
+
[spec?.max_output_tokens, 'local-parameters'],
|
|
19
|
+
[options.fallbackMaxOutputTokens ?? 8192, 'safe-fallback'],
|
|
20
|
+
];
|
|
21
|
+
const window = windowCandidates.find(([value]) => positiveToken(value));
|
|
22
|
+
const output = outputCandidates.find(([value]) => positiveToken(value));
|
|
23
|
+
if (!window || !output)
|
|
24
|
+
throw new Error('No valid model capabilities for ' + model);
|
|
25
|
+
const contextWindow = Math.floor(window[0]);
|
|
26
|
+
return {
|
|
27
|
+
model,
|
|
28
|
+
contextWindow,
|
|
29
|
+
maxOutputTokens: Math.max(1, Math.min(Math.floor(output[0]), contextWindow - 1)),
|
|
30
|
+
contextWindowSource: window[1],
|
|
31
|
+
maxOutputTokensSource: output[1],
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export function resolveAutoCompactWindow(contextWindow, maxOutputTokens, reserveTokens) {
|
|
35
|
+
const safetyReserve = Math.min(10_000, Math.floor(contextWindow * 0.05));
|
|
36
|
+
return Math.min(650_000, Math.max(1, contextWindow - Math.max(reserveTokens, maxOutputTokens, safetyReserve)));
|
|
37
|
+
}
|