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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
1
2
|
import { logger } from '../../utils/logger.js';
|
|
2
3
|
import { summarizeToolInput, summarizeToolInputForDisplay, toolInputForDisplay } from '../../utils/tool-summary.js';
|
|
3
4
|
import { getErrorMessage, getToolResultErrorText, isContextTooLongText } from '../../utils/error-utils.js';
|
|
@@ -25,6 +26,7 @@ export class IMRenderer {
|
|
|
25
26
|
opts;
|
|
26
27
|
itemsQueue = [];
|
|
27
28
|
textBuffer = '';
|
|
29
|
+
deferredProactiveText = [];
|
|
28
30
|
timer;
|
|
29
31
|
lastFlush = Date.now();
|
|
30
32
|
allText = '';
|
|
@@ -35,6 +37,7 @@ export class IMRenderer {
|
|
|
35
37
|
/** 串行发送队列:保证消息按序到达 */
|
|
36
38
|
sendChain = Promise.resolve();
|
|
37
39
|
activityRecordChain = Promise.resolve();
|
|
40
|
+
pendingAutomaticText;
|
|
38
41
|
/** proactive:是否已发过 text 文本(用于去重 complete.result) */
|
|
39
42
|
hasEmittedText = false;
|
|
40
43
|
/** 自增 callId 兜底(runner 没提供时用) */
|
|
@@ -57,6 +60,10 @@ export class IMRenderer {
|
|
|
57
60
|
constructor(opts) {
|
|
58
61
|
this.opts = opts;
|
|
59
62
|
const send = opts.send;
|
|
63
|
+
// Only durable task-activity recording needs to gate publication. Keep
|
|
64
|
+
// renderer-only callers synchronous when no store is configured.
|
|
65
|
+
if (!opts.recordActivity)
|
|
66
|
+
return;
|
|
60
67
|
this.opts = { ...opts, send: payload => {
|
|
61
68
|
// Capture the current barrier: later activities must not hold this send.
|
|
62
69
|
const recorded = this.activityRecordChain;
|
|
@@ -67,11 +74,13 @@ export class IMRenderer {
|
|
|
67
74
|
return this.opts.suppressActivityItems ?? this.opts.suppressActivities ?? false;
|
|
68
75
|
}
|
|
69
76
|
suppressIntermediateText() {
|
|
77
|
+
if (this.opts.noopSentinel)
|
|
78
|
+
return true;
|
|
70
79
|
return this.opts.suppressIntermediateText ?? this.opts.suppressActivities ?? false;
|
|
71
80
|
}
|
|
72
81
|
// ── 公开接口 ──
|
|
73
82
|
/** 推入 AgentEvent,按 chatmode 投影 */
|
|
74
|
-
emit(event) {
|
|
83
|
+
emit(event, suppressTextProjection = false) {
|
|
75
84
|
try {
|
|
76
85
|
const correlatedEvent = event.type === 'tool_use' || event.type === 'tool_result'
|
|
77
86
|
? { ...event, correlationId: event.correlationId ?? event.callId }
|
|
@@ -96,7 +105,7 @@ export class IMRenderer {
|
|
|
96
105
|
catch {
|
|
97
106
|
// logger.event 失败不影响业务
|
|
98
107
|
}
|
|
99
|
-
if (this.opts.envelope.chatmode === 'proactive') {
|
|
108
|
+
if (this.opts.envelope.chatmode === 'proactive' && !suppressTextProjection) {
|
|
100
109
|
this.emitProactive(event);
|
|
101
110
|
}
|
|
102
111
|
// interactive 模式由 MessageProcessor 显式调 addText/addToolCall/... 推入 items
|
|
@@ -105,6 +114,16 @@ export class IMRenderer {
|
|
|
105
114
|
async flush(isFinal, attention) {
|
|
106
115
|
await this.activityRecordChain;
|
|
107
116
|
if (this.opts.envelope.chatmode === 'proactive') {
|
|
117
|
+
if (isFinal) {
|
|
118
|
+
const pending = this.deferredProactiveText;
|
|
119
|
+
this.deferredProactiveText = [];
|
|
120
|
+
if (pending.map(item => item.text).join('').trim() !== this.opts.noopSentinel) {
|
|
121
|
+
for (const item of pending) {
|
|
122
|
+
this.recordActivity(item);
|
|
123
|
+
await this.sendPayload({ kind: 'activity.batch', items: [item] });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
108
127
|
// proactive 是 fire-and-forget,无 pending buffer;只需放出仍被扣住的工具结果
|
|
109
128
|
this.releaseHeldToolResults();
|
|
110
129
|
await this.activityRecordChain;
|
|
@@ -120,7 +139,7 @@ export class IMRenderer {
|
|
|
120
139
|
}
|
|
121
140
|
/** 是否有 pending 内容 */
|
|
122
141
|
hasContent() {
|
|
123
|
-
return this.textBuffer.length > 0 || this.itemsQueue.some(it => it.kind !== 'text') || this.hasHeldToolResults();
|
|
142
|
+
return this.textBuffer.length > 0 || this.deferredProactiveText.length > 0 || this.itemsQueue.some(it => it.kind !== 'text') || this.hasHeldToolResults();
|
|
124
143
|
}
|
|
125
144
|
/** 是否有会抑制兜底错误消息的正文/过程内容;lifecycle 边界不算。 */
|
|
126
145
|
hasNonLifecycleContent() {
|
|
@@ -182,7 +201,7 @@ export class IMRenderer {
|
|
|
182
201
|
};
|
|
183
202
|
this.sentContent = true;
|
|
184
203
|
try {
|
|
185
|
-
await this.
|
|
204
|
+
await this.sendAutomaticText(payload);
|
|
186
205
|
}
|
|
187
206
|
catch (error) {
|
|
188
207
|
// A failed durable enqueue must remain retryable by the final flush.
|
|
@@ -209,6 +228,7 @@ export class IMRenderer {
|
|
|
209
228
|
this.itemsQueue = [];
|
|
210
229
|
this.textBuffer = '';
|
|
211
230
|
this.allText = '';
|
|
231
|
+
this.deferredProactiveText = [];
|
|
212
232
|
}
|
|
213
233
|
/** 仅丢弃尚未发送的正文,保留 notice/tool 等活动项。 */
|
|
214
234
|
discardPendingText() {
|
|
@@ -218,6 +238,7 @@ export class IMRenderer {
|
|
|
218
238
|
}
|
|
219
239
|
this.itemsQueue = this.itemsQueue.filter(it => it.kind !== 'text');
|
|
220
240
|
this.textBuffer = '';
|
|
241
|
+
this.deferredProactiveText = [];
|
|
221
242
|
}
|
|
222
243
|
/** 当前 buffer 中尚未 flush 的文本 */
|
|
223
244
|
getRemainingText() {
|
|
@@ -602,7 +623,7 @@ export class IMRenderer {
|
|
|
602
623
|
isFinal: false,
|
|
603
624
|
};
|
|
604
625
|
this.sentContent = true;
|
|
605
|
-
await this.
|
|
626
|
+
await this.sendAutomaticText(payload);
|
|
606
627
|
this.lastFlush = Date.now();
|
|
607
628
|
this.flushCount++;
|
|
608
629
|
return true;
|
|
@@ -686,6 +707,34 @@ export class IMRenderer {
|
|
|
686
707
|
this.sendChain = handled.catch(() => { });
|
|
687
708
|
return handled;
|
|
688
709
|
}
|
|
710
|
+
/** Model output and renderer text notices share PA's automatic-text outlet.
|
|
711
|
+
* Explicit sends, command receipts and interaction fallbacks bypass it.
|
|
712
|
+
*/
|
|
713
|
+
async sendAutomaticText(payload) {
|
|
714
|
+
if (this.opts.envelope.chatmode !== 'paactive')
|
|
715
|
+
return this.sendPayload(payload);
|
|
716
|
+
const signature = JSON.stringify([
|
|
717
|
+
payload.text,
|
|
718
|
+
payload.metadata?.forkAnchor?.assistantMessageId,
|
|
719
|
+
]);
|
|
720
|
+
const pending = this.pendingAutomaticText?.signature === signature
|
|
721
|
+
? this.pendingAutomaticText
|
|
722
|
+
: undefined;
|
|
723
|
+
const item = pending?.item ?? {
|
|
724
|
+
kind: 'text',
|
|
725
|
+
text: payload.text,
|
|
726
|
+
...(payload.metadata?.forkAnchor ? { forkAnchor: payload.metadata.forkAnchor } : {}),
|
|
727
|
+
};
|
|
728
|
+
const activityId = pending?.activityId
|
|
729
|
+
?? `activity-${randomUUID().replace(/-/g, '')}`;
|
|
730
|
+
if (!pending) {
|
|
731
|
+
this.recordActivity(item, activityId);
|
|
732
|
+
this.pendingAutomaticText = { signature, item, activityId };
|
|
733
|
+
}
|
|
734
|
+
await this.sendPayload({ kind: 'activity.batch', items: [item] });
|
|
735
|
+
if (this.pendingAutomaticText?.activityId === activityId)
|
|
736
|
+
this.pendingAutomaticText = undefined;
|
|
737
|
+
}
|
|
689
738
|
scheduleFlush() {
|
|
690
739
|
if (this.timer) {
|
|
691
740
|
return;
|
|
@@ -786,7 +835,10 @@ export class IMRenderer {
|
|
|
786
835
|
item.text = item.text.replace(this.opts.fileMarkerPattern, '');
|
|
787
836
|
}
|
|
788
837
|
}
|
|
789
|
-
if (
|
|
838
|
+
if (isFinal && this.textBuffer.trim() === this.opts.noopSentinel) {
|
|
839
|
+
this.discardPendingText();
|
|
840
|
+
}
|
|
841
|
+
else if (!this.hasSendableText(this.textBuffer, isFinal ? 'final' : 'flush')) {
|
|
790
842
|
this.textBuffer = '';
|
|
791
843
|
}
|
|
792
844
|
else if (isFinal && this.opts.fileMarkerPattern) {
|
|
@@ -845,7 +897,7 @@ export class IMRenderer {
|
|
|
845
897
|
};
|
|
846
898
|
this.sentContent = true;
|
|
847
899
|
try {
|
|
848
|
-
await this.
|
|
900
|
+
await this.sendAutomaticText(payload);
|
|
849
901
|
}
|
|
850
902
|
catch (error) {
|
|
851
903
|
this.textBuffer = text + this.textBuffer;
|
|
@@ -866,7 +918,7 @@ export class IMRenderer {
|
|
|
866
918
|
payload.attention = attention;
|
|
867
919
|
this.sentContent = true;
|
|
868
920
|
try {
|
|
869
|
-
await this.
|
|
921
|
+
await this.sendAutomaticText(payload);
|
|
870
922
|
}
|
|
871
923
|
catch (error) {
|
|
872
924
|
this.textBuffer = finalText + this.textBuffer;
|
|
@@ -956,15 +1008,22 @@ export class IMRenderer {
|
|
|
956
1008
|
this.emitProactiveItem(item);
|
|
957
1009
|
}
|
|
958
1010
|
/** Serialize persistence and resource preparation before publishing items. */
|
|
959
|
-
recordActivity(item) {
|
|
1011
|
+
recordActivity(item, activityId) {
|
|
960
1012
|
this.activityRecordChain = this.activityRecordChain.then(async () => {
|
|
961
|
-
|
|
1013
|
+
if (activityId === undefined)
|
|
1014
|
+
await this.opts.recordActivity?.(item);
|
|
1015
|
+
else
|
|
1016
|
+
await this.opts.recordActivity?.(item, activityId);
|
|
962
1017
|
}).catch(error => {
|
|
963
1018
|
logger.warn(`[IMRenderer] task activity record failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
964
1019
|
});
|
|
965
1020
|
}
|
|
966
1021
|
/** proactive:单个 ThoughtItem 包成 activity.batch[1] 发出。 */
|
|
967
1022
|
emitProactiveItem(item) {
|
|
1023
|
+
if (this.opts.noopSentinel && (item.kind === 'text' || (item.kind === 'summary' && !item.is_error))) {
|
|
1024
|
+
this.deferredProactiveText.push(item);
|
|
1025
|
+
return;
|
|
1026
|
+
}
|
|
968
1027
|
this.recordActivity(item);
|
|
969
1028
|
const evolCommand = item.kind === 'tool_call' ? item.evolCommand : undefined;
|
|
970
1029
|
const payload = evolCommand
|
|
@@ -3,6 +3,7 @@ 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 { appContactAdmissionActive, evaluateAppContactAdmission } from './contact-admission.js';
|
|
6
7
|
/**
|
|
7
8
|
* 出站私聊准入:与入站使用同一套判定,保证双向对称。
|
|
8
9
|
*
|
|
@@ -28,6 +29,15 @@ export async function evaluateOutboundContactAdmission(input) {
|
|
|
28
29
|
catch (error) {
|
|
29
30
|
return { allow: false, code: 'CONTACT_POLICY_INVALID', status: 'absent', error: error instanceof Error ? error.message : String(error) };
|
|
30
31
|
}
|
|
32
|
+
if (policy.contactAdmission === 'app-v1' && appContactAdmissionActive(selfAid)) {
|
|
33
|
+
const decision = evaluateAppContactAdmission(selfAid, targetAid);
|
|
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
|
+
}
|
|
31
41
|
let view;
|
|
32
42
|
try {
|
|
33
43
|
view = resolvePeerView(selfAid, targetAid);
|
|
@@ -64,7 +74,8 @@ export async function evaluateOutboundContactAdmission(input) {
|
|
|
64
74
|
? { allow: true, status: 'internal' }
|
|
65
75
|
: { allow: false, code: 'CONTACT_INTERNAL_DISABLED', status: 'disabled', error: '当前 Agent 不接受内部联系,Owner 未开启 allowInternalContacts 与 allowAllContacts' };
|
|
66
76
|
}
|
|
67
|
-
|
|
77
|
+
// 与入站同一判据:个人助理未显式配置时默认可以联系外部。
|
|
78
|
+
return membership.effectiveAllowExternalContacts === true
|
|
68
79
|
? { allow: true, status: 'external' }
|
|
69
80
|
: { allow: false, code: 'CONTACT_EXTERNAL_DISABLED', status: 'disabled', error: '当前 Agent 不接受外部联系,Owner 未开启 allowExternalContacts 与 allowAllContacts' };
|
|
70
81
|
}
|
|
@@ -147,13 +158,16 @@ export function evaluateInboundAdmissionPreflight(input) {
|
|
|
147
158
|
*
|
|
148
159
|
* - `owner` / `assistant`:恒放行,不受任何开关与名单影响。
|
|
149
160
|
* - 命中条目且属于本 Owner → `allowInternalContacts`。
|
|
150
|
-
* - 命中条目但归属其他 Owner(或缺失归属)→ `
|
|
161
|
+
* - 命中条目但归属其他 Owner(或缺失归属)→ `effectiveAllowExternalContacts`
|
|
162
|
+
* (显式配置 > 个人助理缺省 true > false,与注入共用同一个判据)。
|
|
151
163
|
* - 未命中 → 返回 undefined,由调用方按 `allowAllContacts` 决定。
|
|
152
164
|
* - 名录不可用 → 拒绝,不回退放行(`allowAllContacts` 与白名单都在调用方更早处置)。
|
|
153
165
|
*
|
|
154
166
|
* 拒绝发生在业务路由之前,被拒的名录发送者不会收到自动回复。
|
|
155
167
|
*/
|
|
156
168
|
export function evaluateOwnerDirectoryInboundAdmission(context) {
|
|
169
|
+
if (context.channelType === 'aun' && context.policy?.contactAdmission === 'app-v1' && appContactAdmissionActive(context.selfAid))
|
|
170
|
+
return undefined;
|
|
157
171
|
if (context.trustedHandoffEcho || context.isOwner || !context.primaryId || !context.policy)
|
|
158
172
|
return undefined;
|
|
159
173
|
const membership = readOwnerDirectoryMembership(context.selfAid, context.primaryId);
|
|
@@ -175,7 +189,10 @@ export function evaluateOwnerDirectoryInboundAdmission(context) {
|
|
|
175
189
|
? { allow: true, reason: membership.category === 'agent' ? 'internal_agent' : 'internal_contact', context }
|
|
176
190
|
: { allow: false, reason: 'internal_contacts_disabled', context };
|
|
177
191
|
}
|
|
178
|
-
|
|
192
|
+
// 外部档取"显式配置 > 个人助理判据"的最终值:注入每轮都按这个值渲染,
|
|
193
|
+
// 准入若读补齐后的 `policy.allowExternalContacts`(缺省 false),
|
|
194
|
+
// 个人助理就会出现"目录里能看到人、对方发进来却被拒"。
|
|
195
|
+
return membership.effectiveAllowExternalContacts === true
|
|
179
196
|
? { allow: true, reason: membership.category === 'agent' ? 'external_agent' : 'external_contact', context }
|
|
180
197
|
: { allow: false, reason: 'external_contacts_disabled', context };
|
|
181
198
|
}
|
|
@@ -212,6 +229,14 @@ function evaluateOrdinaryAdmission(context) {
|
|
|
212
229
|
// Owner 恒放行,不查名录也不看三个开关。
|
|
213
230
|
if (context.isOwner)
|
|
214
231
|
return { allow: true, reason: 'owner', context };
|
|
232
|
+
if (context.channelType === 'aun' && policy.contactAdmission === 'app-v1' && appContactAdmissionActive(context.selfAid)) {
|
|
233
|
+
const decision = evaluateAppContactAdmission(context.selfAid, context.primaryId ?? context.actorId);
|
|
234
|
+
if (decision.allow)
|
|
235
|
+
return { allow: true, reason: decision.reason === 'owner' ? 'owner'
|
|
236
|
+
: decision.reason === 'temporary' ? 'temporary_contact' : 'allowed_aid', context };
|
|
237
|
+
return { allow: false, reason: decision.reason === 'unavailable' ? 'owner_directory_unavailable'
|
|
238
|
+
: decision.reason === 'blocked' ? 'denied_aid' : 'all_contacts_disabled', context };
|
|
239
|
+
}
|
|
215
240
|
const directoryDecision = evaluateOwnerDirectoryInboundAdmission(context);
|
|
216
241
|
// Owner 与个人助理恒放行,不受黑名单影响。
|
|
217
242
|
if (directoryDecision?.allow
|
|
@@ -24,6 +24,7 @@ import { resolveEffective } from '../../config/config-manager.js';
|
|
|
24
24
|
import { createDecisionInferenceProvider } from '../inference/text-inference.js';
|
|
25
25
|
import { AutoMentionGate } from './auto-mention-gate.js';
|
|
26
26
|
import { syncGroupRulesContext } from '../../eck/group-rules-sync.js';
|
|
27
|
+
import { readSoulContent } from '../soul.js';
|
|
27
28
|
import { authorizeAccess, buildAuthSubject } from '../auth/auth-gateway.js';
|
|
28
29
|
import { MenuDiagnosticLimiter, MenuRequestDeduper, hasValidMenuId, menuFailure, menuPayloadFingerprint, menuSuccess, normalizeMenuError, parseMenuControl, validateMenuRequest, evaluateEvolMenuVersionGate, evolMenuResponseTransportMetadata, isAunMenuTokenRequired, menuCommandForName, normalizeMenuResponseTiming, withMenuProcessingTime, logMenuRequestCompleted, logMenuRequestReceived, } from '../command/menu-protocol.js';
|
|
29
30
|
import { resolveExplicitMenuExecutionContext, validateMenuCatalogArgs, validateMenuValueBatchArgs } from '../command/menu-catalog.js';
|
|
@@ -128,10 +129,10 @@ export class MessageBridge {
|
|
|
128
129
|
logger.debug(`[MessageBridge] Decision context group rules unavailable: ${String(error)}`);
|
|
129
130
|
}
|
|
130
131
|
}
|
|
131
|
-
//
|
|
132
|
-
const
|
|
133
|
-
if (
|
|
134
|
-
resources.personal =
|
|
132
|
+
// 个人设定在 personal/soul/ 下,按文件名拼接;机制指南与空分册不算个人资料。
|
|
133
|
+
const personal = readSoulContent(item.selfAid);
|
|
134
|
+
if (personal)
|
|
135
|
+
resources.personal = personal;
|
|
135
136
|
if (item.projectPath) {
|
|
136
137
|
const files = [];
|
|
137
138
|
let current = path.resolve(item.projectPath);
|
|
@@ -480,6 +481,10 @@ export class MessageBridge {
|
|
|
480
481
|
catch { /* slash command */ }
|
|
481
482
|
if (!requestMatch && !protocolType)
|
|
482
483
|
return false;
|
|
484
|
+
if (context.channelType === 'aun' && context.policy?.contactAdmission === 'app-v1') {
|
|
485
|
+
// The App owns requests; retired commands cannot create a second approval state.
|
|
486
|
+
return true;
|
|
487
|
+
}
|
|
483
488
|
// Slash commands keep their human-facing response semantics. Structured
|
|
484
489
|
// App requests use contact.request.response and never fall through to the
|
|
485
490
|
// normal command/session pipeline.
|
|
@@ -1006,7 +1011,8 @@ export class MessageBridge {
|
|
|
1006
1011
|
const admissionDecision = evaluateOrdinaryInboundAdmission(admissionPreflight.context);
|
|
1007
1012
|
// 名录不可用等硬性拒绝不回自动提示,静默丢弃;其余拒绝才发控制面提示。
|
|
1008
1013
|
const directoryDenied = !admissionDecision.allow && (admissionDecision.reason === 'owner_directory_unavailable');
|
|
1009
|
-
|
|
1014
|
+
const appControl = resolvedChannelType === 'aun' && admissionPreflight.context.policy?.contactAdmission === 'app-v1' && menuControl.isMenu;
|
|
1015
|
+
if (!appControl && !admissionDecision.allow && (!isPrivateMenuTokenRequest || directoryDenied)) {
|
|
1010
1016
|
if (chatType === 'private' && !directoryDenied) {
|
|
1011
1017
|
if (menuControl.isMenu) {
|
|
1012
1018
|
if (hasValidMenuId(menuControl)) {
|
|
@@ -1940,6 +1946,41 @@ export class MessageBridge {
|
|
|
1940
1946
|
? { ...deduped.value, warning: responseWarning }
|
|
1941
1947
|
: deduped.value;
|
|
1942
1948
|
await this.sendMenuResponse(adapter, channel, msg, response);
|
|
1949
|
+
// The request carries the conversation route; the daemon cannot infer
|
|
1950
|
+
// which App topic is open. This is reliable content, separate from the
|
|
1951
|
+
// device-targeted/volatile Menu acknowledgement, and emitted once per write.
|
|
1952
|
+
const changedModel = response.data && typeof response.data === 'object'
|
|
1953
|
+
? response.data.model : undefined;
|
|
1954
|
+
if (!deduped.replayed && channelType === 'aun' && !msg.isControlChannel
|
|
1955
|
+
&& parsed.type === 'menu.update' && parsed.name === 'model'
|
|
1956
|
+
&& !response.error && typeof changedModel === 'string' && adapter?.send) {
|
|
1957
|
+
try {
|
|
1958
|
+
await adapter.send(buildEnvelope({
|
|
1959
|
+
channel,
|
|
1960
|
+
channelId: msg.channelId,
|
|
1961
|
+
agentName: this.agentRegistry?.resolveByChannel(channel)?.name ?? msg.selfAID,
|
|
1962
|
+
operationId: `model-change:${msg.messageId || parsed.id}`,
|
|
1963
|
+
replyContext: {
|
|
1964
|
+
delivery: msg.replyContext?.delivery,
|
|
1965
|
+
threadId: msg.threadId,
|
|
1966
|
+
suppressPeerMention: true,
|
|
1967
|
+
metadata: {
|
|
1968
|
+
encrypted: msg.encrypted === true,
|
|
1969
|
+
operationId: `model-change:${msg.messageId || parsed.id}`,
|
|
1970
|
+
},
|
|
1971
|
+
},
|
|
1972
|
+
}), {
|
|
1973
|
+
kind: 'system.notice',
|
|
1974
|
+
subtype: 'model.changed',
|
|
1975
|
+
text: `模型已切换为${changedModel},下一轮对话生效`,
|
|
1976
|
+
});
|
|
1977
|
+
}
|
|
1978
|
+
catch (error) {
|
|
1979
|
+
// The configuration write succeeded; notification delivery must not
|
|
1980
|
+
// turn its acknowledgement into a false configuration failure.
|
|
1981
|
+
logger.warn(`[MenuControl] model change notice failed: request=${parsed.id} error=${error}`);
|
|
1982
|
+
}
|
|
1983
|
+
}
|
|
1943
1984
|
const deferredEffect = afterResponse;
|
|
1944
1985
|
if (!deduped.replayed && deferredEffect) {
|
|
1945
1986
|
try {
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 消息处理工具函数
|
|
3
|
-
*
|
|
4
|
-
* 从 message-processor.ts 提取的独立工具函数,供 ResponseEngine 和其他模块使用。
|
|
5
|
-
*/
|
|
6
1
|
import { sessionLocalTopicId, sessionTopicThreadId } from '../thread/topic-id.js';
|
|
7
2
|
import { renderCommandCardAsText, renderActionAsText } from '../interaction-router.js';
|
|
8
3
|
/** A legacy adapter resolved its send call without providing a structured receipt. */
|
|
@@ -2,14 +2,50 @@ import { loadSchema } from '../../config/schema-registry.js';
|
|
|
2
2
|
import { resolveEffective } from '../../config/config-manager.js';
|
|
3
3
|
import { resolveRuntimeStringField } from '../role/runtime-policy.js';
|
|
4
4
|
import { isManagementRole } from '../../config/builtin-roles.js';
|
|
5
|
+
import { resolveAgentLifecycle } from '../../config/lifecycle.js';
|
|
6
|
+
export const CHAT_MODES = ['interactive', 'proactive', 'paactive'];
|
|
7
|
+
export function isChatMode(value) {
|
|
8
|
+
return CHAT_MODES.includes(value);
|
|
9
|
+
}
|
|
10
|
+
/** PA output is supported only in active AUN human management conversations. */
|
|
11
|
+
export function supportsPaactive(params) {
|
|
12
|
+
const channelType = params.channelType ?? params.peerKey?.split('#')[0];
|
|
13
|
+
return channelType === 'aun'
|
|
14
|
+
&& params.chatType === 'private'
|
|
15
|
+
&& normalizePeerType(params.peerType) === 'human'
|
|
16
|
+
&& isManagementRole(params.role)
|
|
17
|
+
&& (params.lifecycle === undefined || params.lifecycle === 'active')
|
|
18
|
+
&& (params.sessionType === undefined || params.sessionType === 'main');
|
|
19
|
+
}
|
|
20
|
+
/** Keep unsupported inherited PA settings from becoming output-as-reply mode. */
|
|
21
|
+
export function chatModeForScene(value, params) {
|
|
22
|
+
if (value === 'paactive' && supportsPaactive(params))
|
|
23
|
+
return value;
|
|
24
|
+
if (value === 'interactive' || value === 'proactive')
|
|
25
|
+
return value;
|
|
26
|
+
if (value === 'paactive') {
|
|
27
|
+
const kind = normalizePeerType(params.peerType);
|
|
28
|
+
if (kind === 'system' || kind === 'service')
|
|
29
|
+
return 'interactive';
|
|
30
|
+
if (kind === 'agent'
|
|
31
|
+
|| isPrivateChatmodeRoleLocked(chatmodeFieldForPeer(params.chatType, params.peerType), params.role))
|
|
32
|
+
return 'proactive';
|
|
33
|
+
}
|
|
34
|
+
const fallback = chatmodeFactoryDefaults()[chatmodeFieldForPeer(params.chatType, params.peerType)];
|
|
35
|
+
return fallback === 'paactive' ? 'interactive' : fallback;
|
|
36
|
+
}
|
|
5
37
|
/** Resolve the effective chat mode from the ConfigManager layering context. */
|
|
6
38
|
export function resolveChatMode(params) {
|
|
7
39
|
let configured;
|
|
40
|
+
let lifecycle = params.lifecycle;
|
|
8
41
|
try {
|
|
9
|
-
|
|
42
|
+
const effective = resolveEffective({
|
|
10
43
|
self: params.self,
|
|
11
44
|
peerKey: params.peerKey,
|
|
12
|
-
}, { cache: true })
|
|
45
|
+
}, { cache: true });
|
|
46
|
+
configured = effective.chatmode;
|
|
47
|
+
if (lifecycle === undefined)
|
|
48
|
+
lifecycle = resolveAgentLifecycle(effective);
|
|
13
49
|
}
|
|
14
50
|
catch {
|
|
15
51
|
configured = undefined;
|
|
@@ -21,9 +57,8 @@ export function resolveChatMode(params) {
|
|
|
21
57
|
if (kind === 'agent')
|
|
22
58
|
return 'proactive';
|
|
23
59
|
const field = chatmodeFieldForPeer(params.chatType, params.peerType);
|
|
24
|
-
// 人类私聊的角色门槛(硬约束):interactive
|
|
25
|
-
// 只有 owner/admin 才走下面的分层配置;其余角色(含未分配/未知)直接 proactive
|
|
26
|
-
// 关系级或 agent 级把 chatmode.private 写成 interactive 都不生效。
|
|
60
|
+
// 人类私聊的角色门槛(硬约束):interactive/paactive 都是管理角色模式,
|
|
61
|
+
// 只有 owner/admin 才走下面的分层配置;其余角色(含未分配/未知)直接 proactive。
|
|
27
62
|
if (isPrivateChatmodeRoleLocked(field, params.role))
|
|
28
63
|
return 'proactive';
|
|
29
64
|
const decision = resolveRuntimeStringField({
|
|
@@ -33,13 +68,11 @@ export function resolveChatMode(params) {
|
|
|
33
68
|
configuredValue: configured?.[field],
|
|
34
69
|
});
|
|
35
70
|
const effectiveValue = decision.effectiveValue;
|
|
36
|
-
return effectiveValue
|
|
37
|
-
? effectiveValue
|
|
38
|
-
: chatmodeFactoryDefaults()[field];
|
|
71
|
+
return chatModeForScene(effectiveValue, { ...params, lifecycle });
|
|
39
72
|
}
|
|
40
73
|
/**
|
|
41
74
|
* 人类私聊(chatmode.private)是否被角色锁定为 proactive。
|
|
42
|
-
* owner/admin 之外的任何角色(含 null/'none'
|
|
75
|
+
* owner/admin 之外的任何角色(含 null/'none'/未知)都锁定 interactive 和 paactive。
|
|
43
76
|
*/
|
|
44
77
|
export function isPrivateChatmodeRoleLocked(field, role) {
|
|
45
78
|
return field === 'private' && !isManagementRole(role);
|
|
@@ -66,6 +99,7 @@ export function resolveChatModeForField(params) {
|
|
|
66
99
|
...params,
|
|
67
100
|
chatType: params.field === 'group' ? 'group' : 'private',
|
|
68
101
|
peerType: params.field === 'nothuman' ? 'agent' : 'human',
|
|
102
|
+
channelType: params.channelType ?? params.peerKey?.split('#')[0] ?? 'aun',
|
|
69
103
|
});
|
|
70
104
|
}
|
|
71
105
|
export function normalizePeerType(value) {
|
|
@@ -110,7 +144,7 @@ export function resolveChatModeForPeer(params) {
|
|
|
110
144
|
return 'proactive';
|
|
111
145
|
// 合并后的场景表 → 出厂默认表
|
|
112
146
|
const field = chatmodeFieldForPeer(params.chatType, params.peerType);
|
|
113
|
-
return params.configured?.[field]
|
|
147
|
+
return chatModeForScene(params.configured?.[field], params);
|
|
114
148
|
}
|
|
115
149
|
/**
|
|
116
150
|
* chatMode 出厂默认表 —— 唯一来源是 agent-config schema 的 chatmode.default
|