evolcore 0.0.48 → 0.0.50
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 +97 -0
- package/bin/ecmsg.js +9 -4
- package/dist/ability/caller/authorization.js +21 -0
- package/dist/ability/caller/command.js +164 -0
- package/dist/ability/caller/contract.js +102 -0
- package/dist/ability/caller/daemon.js +158 -0
- package/dist/ability/caller/service.js +380 -0
- package/dist/ability/command-contract.js +5 -0
- package/dist/ability/daemon.js +5 -1
- package/dist/ability/interop-v1.js +10 -3
- package/dist/ability/management.js +1 -0
- package/dist/agent-template/jobs.js +173 -1
- package/dist/agent-template/runtime.js +285 -8
- package/dist/agent-template/service.js +1159 -40
- package/dist/agent-template/types.js +2 -1
- package/dist/agents/baseagent-availability.js +27 -3
- package/dist/agents/baseagent-capability-adapter.js +102 -0
- package/dist/agents/baseagent-plugin-descriptor.js +274 -0
- package/dist/agents/baseagent-plugin-loader.js +145 -0
- package/dist/agents/baseagent.js +68 -2
- package/dist/agents/claude-gateway/agent-registration.js +389 -0
- package/dist/agents/claude-gateway/binding.js +96 -0
- package/dist/agents/claude-gateway/inbox.js +138 -0
- package/dist/agents/claude-gateway/index.js +125 -0
- package/dist/agents/claude-gateway/listing.js +330 -0
- package/dist/agents/claude-gateway/router.js +328 -0
- package/dist/agents/claude-gateway/sessions.js +128 -0
- package/dist/agents/claude-gateway/terminal.js +250 -0
- package/dist/agents/claude-gateway/transcript.js +272 -0
- package/dist/agents/claude-gateway/types.js +14 -0
- package/dist/agents/claude-runner.js +6 -10
- package/dist/agents/codex-runner.js +9 -2
- package/dist/agents/{gemini-runner.js → gemini/gemini-runner.js} +17 -17
- package/dist/{core/session/adapters → agents/gemini}/gemini-session-file-adapter.js +2 -2
- package/dist/agents/gemini/index.js +51 -0
- package/dist/aun/aid/control-aid.js +52 -32
- package/dist/aun/group/invite-service.js +6 -36
- package/dist/aun/group/operations.js +6 -0
- package/dist/aun/msg/mention-schema.js +1 -1
- package/dist/aun/msg/p2p.js +31 -2
- package/dist/aun/msg/upload.js +126 -3
- package/dist/build-identity.json +1 -1
- package/dist/channels/aun.js +1175 -457
- package/dist/cli/ability-command.js +42 -0
- package/dist/cli/agent-command.js +20 -1
- package/dist/cli/agent-create.js +78 -18
- package/dist/cli/agent-template.js +5 -3
- package/dist/cli/agent.js +91 -0
- package/dist/cli/aun-commands.js +92 -34
- package/dist/cli/bench.js +5 -2
- package/dist/cli/config.js +22 -6
- package/dist/cli/daemon-commands.js +245 -101
- package/dist/cli/directory.js +6 -1
- package/dist/cli/ecmsg-gateway.js +11 -9
- package/dist/cli/index.js +30 -5
- package/dist/cli/init.js +39 -63
- package/dist/cli/managed-command-guard.js +3 -0
- package/dist/cli/menu-client.js +32 -7
- package/dist/cli/model.js +20 -5
- package/dist/cli/pay-command.js +30 -0
- package/dist/cli/provider-command.js +6 -2
- package/dist/cli/quota.js +89 -0
- package/dist/cli/restart-monitor.js +2 -2
- package/dist/cli/role.js +1 -0
- package/dist/cli/services-command.js +12 -9
- package/dist/cli/team-workspace-command.js +56 -2
- package/dist/cli/thread-command.js +78 -12
- package/dist/config/access-policy.js +16 -3
- package/dist/config/config-field-policy.js +88 -9
- package/dist/config/config-manager.js +97 -47
- package/dist/config/config-operation-service.js +22 -1
- package/dist/config/gateway-config.js +9 -8
- package/dist/config/owner-config.js +0 -16
- package/dist/config/peer-role-resolver.js +1 -7
- package/dist/config/providers-config.js +107 -20
- package/dist/config/providers-management.js +45 -21
- package/dist/config/resolved-config-op.js +4 -44
- package/dist/config/schema-migration.js +78 -5
- package/dist/config/schema-registry.js +52 -7
- package/dist/config-store.js +1309 -17
- package/dist/core/agent-application-service.js +220 -1
- package/dist/core/agent-ipc-registration.js +19 -2
- package/dist/core/agent-reload-coordinator.js +5 -0
- package/dist/core/agent-runtime.js +198 -54
- package/dist/core/auth/agent-delegation.js +14 -0
- package/dist/core/auth/delegation-authorization.js +33 -26
- package/dist/core/auth/operation-authorizer.js +16 -1
- package/dist/core/auth/operation-catalog.js +59 -7
- package/dist/core/baseagent-loader.js +30 -3
- package/dist/core/capability/capability-manager.js +16 -7
- package/dist/core/channel-runtime.js +4 -2
- package/dist/core/command/agent-control.js +20 -2
- package/dist/core/command/agent-template-menu.js +4 -3
- package/dist/core/command/cli-intent-parser.js +28 -0
- package/dist/core/command/command-handler.js +45 -2
- package/dist/core/command/menu-catalog.js +20 -4
- package/dist/core/command/menu-file-path.js +70 -0
- package/dist/core/command/menu-handler.js +97 -73
- package/dist/core/command/menu-protocol.js +29 -0
- package/dist/core/command/menu-query-batch.js +2 -2
- package/dist/core/command/private-mention-menu.js +71 -0
- package/dist/core/command/remote-shell.js +565 -0
- package/dist/core/command/slash-handler.js +17 -26
- package/dist/core/command/team-workspace-bootstrap.js +2 -1
- package/dist/core/command/topic-slash.js +7 -1
- package/dist/core/daemon-bootstrap.js +0 -4
- package/dist/core/daemon-control.js +58 -1
- package/dist/core/daemon-lifecycle.js +29 -7
- package/dist/core/evolagent-registry.js +18 -9
- package/dist/core/handoff/runtime.js +1 -1
- package/dist/core/host-snapshot.js +8 -3
- package/dist/core/initialization/service.js +3 -0
- package/dist/core/interaction-router.js +130 -0
- package/dist/core/ipc-registration.js +5 -0
- package/dist/core/memory/consolidation-context.js +2 -1
- package/dist/core/memory/consolidation.js +35 -64
- package/dist/core/message/aun-ipc-sender.js +213 -74
- package/dist/core/message/aun-request-registry.js +31 -0
- package/dist/core/message/contact-admission.js +91 -6
- package/dist/core/message/contact-pending-inbound.js +113 -0
- package/dist/core/message/contact-thread-approval.js +212 -0
- package/dist/core/message/im-renderer.js +40 -1
- package/dist/core/message/message-admission.js +5 -39
- package/dist/core/message/message-bridge.js +197 -45
- package/dist/core/message/message-log.js +32 -0
- package/dist/core/message/message-queue.js +102 -18
- package/dist/core/message/peer-mode.js +15 -4
- package/dist/core/message/response-engine.js +174 -26
- package/dist/core/message/send-options.js +37 -3
- package/dist/core/message/send-routing.js +11 -7
- package/dist/core/model/config-scope.js +6 -14
- package/dist/core/model/model-catalog.js +5 -5
- package/dist/core/model/model-diagnostics.js +19 -0
- package/dist/core/model/model-fallback.js +13 -2
- package/dist/core/ownership/owner-resolver.js +12 -86
- package/dist/core/pack-auth.js +7 -0
- package/dist/core/pack-install.js +1 -1
- package/dist/core/permission/ec-command-parser.js +288 -77
- package/dist/core/permission/protected-paths.js +64 -9
- package/dist/core/permission/services-path-acl.js +458 -0
- package/dist/core/permission/tool-policy.js +26 -10
- package/dist/core/relation/peer-identity.js +13 -0
- package/dist/core/session/adapters/claude-session-file-adapter.js +6 -2
- package/dist/core/session/adapters/codex-session-file-adapter.js +4 -0
- package/dist/core/session/session-manager.js +47 -10
- package/dist/core/session/session-mapper.js +16 -0
- package/dist/core/skill/index-generator.js +2 -3
- package/dist/core/skill/switch-resolver.js +3 -0
- package/dist/core/task/task-recovery-service.js +1 -0
- package/dist/core/thread/command-parser.js +4 -1
- package/dist/core/thread/ipc-operation.js +4 -2
- package/dist/core/thread/thread-operation.js +25 -10
- package/dist/core/thread/thread-service.js +294 -55
- package/dist/core/thread/topic-id.js +67 -2
- package/dist/core/thread/types.js +15 -1
- package/dist/directory/owner-directory-admission.js +11 -8
- package/dist/directory/owner-directory-cache.js +19 -0
- package/dist/directory/owner-directory-markdown.js +1 -1
- package/dist/directory/owner-directory-policy.js +5 -30
- package/dist/directory/owner-directory-request-operation.js +5 -2
- package/dist/eck/kit-renderer.js +3 -2
- package/dist/eck/message-renderer.js +28 -5
- package/dist/ecweb/basic-settings-service.js +5 -9
- package/dist/ecweb/providers-service.js +4 -2
- package/dist/ecweb/runtime/supervisor.js +36 -8
- package/dist/event-center/center-config.js +9 -5
- package/dist/event-center/dispatcher.js +10 -1
- package/dist/event-center/ipc-operation.js +19 -0
- package/dist/event-center/registry.js +20 -5
- package/dist/event-center/runtime.js +10 -7
- package/dist/index.js +120 -41
- package/dist/ipc.js +83 -3
- package/dist/outputs/authorization.js +16 -0
- package/dist/outputs/cards.js +336 -0
- package/dist/outputs/events.js +3 -2
- package/dist/outputs/protocol.js +1 -0
- package/dist/outputs/service.js +2 -15
- package/dist/paths.js +48 -1
- package/dist/pay/command.js +38 -0
- package/dist/pay/protocol.js +136 -0
- package/dist/pay/runtime.js +188 -0
- package/dist/pay/service.js +384 -0
- package/dist/pay/store.js +81 -0
- package/dist/response-system/engines/v1/proactive-flow.js +29 -2
- package/dist/services/dispatcher.js +23 -5
- package/dist/services/host/main.js +388 -0
- package/dist/services/host/protocol.js +118 -0
- package/dist/services/host/resident.js +310 -0
- package/dist/services/host-client.js +386 -0
- package/dist/services/host-deploy.js +180 -0
- package/dist/services/host-launch.js +117 -0
- package/dist/services/host-recycle.js +203 -0
- package/dist/services/host-runtime.js +802 -0
- package/dist/services/idempotency.js +44 -86
- package/dist/services/index-generator.js +4 -3
- package/dist/services/index.js +204 -22
- package/dist/services/ipc-operation.js +288 -44
- package/dist/services/pack-manager.js +1 -0
- package/dist/services/script-runner.js +515 -83
- package/dist/services/service-payload.js +13 -7
- package/dist/services/validation.js +109 -4
- package/dist/stats/budget.js +1 -1
- package/dist/stats/model-resolver.js +2 -2
- package/dist/stats/quota-query.js +95 -0
- package/dist/trigger/application-service.js +6 -4
- package/dist/trigger/local-files.js +19 -9
- package/dist/trigger/scheduler.js +22 -12
- package/dist/trigger/script-sandbox.js +51 -8
- package/dist/utils/aid-bind.js +3 -0
- package/dist/utils/atomic-write.js +22 -8
- package/dist/utils/evolcore-version.js +2 -2
- package/dist/utils/host-info.js +173 -1
- package/dist/utils/logger.js +2 -2
- package/dist/utils/media-cache.js +190 -43
- package/dist/utils/npm-ops.js +43 -8
- package/dist/utils/restart-safety.js +14 -1
- package/dist/utils/system-memory.js +113 -25
- package/dist/utils/systemd-lifecycle.js +154 -0
- package/dist/utils/windows-shell-trust.js +7 -3
- package/dist/workbench/service.js +1 -1
- package/kits/docs/INDEX.md +3 -2
- package/kits/docs/aun/AUN/346/266/210/346/201/257/347/261/273/345/236/213/344/270/216/345/261/236/346/200/247.md +1 -0
- package/kits/docs/channels/aun.md +1 -1
- package/kits/docs/evolcore/INDEX.md +9 -6
- package/kits/docs/evolcore/agent.md +36 -1
- package/kits/docs/evolcore/aid.md +45 -3
- package/kits/docs/evolcore/config.md +5 -2
- package/kits/docs/evolcore/directory.md +8 -9
- package/kits/docs/evolcore/group.md +2 -1
- package/kits/docs/evolcore/memory-tags.md +2 -0
- package/kits/docs/evolcore/menu-client.md +3 -3
- package/kits/docs/evolcore/menu-protocol.md +7 -0
- package/kits/docs/evolcore/model.md +3 -0
- package/kits/docs/evolcore/msg.md +77 -10
- package/kits/docs/evolcore/pay.md +34 -0
- package/kits/docs/evolcore/provider.md +22 -1
- package/kits/docs/evolcore/quota.md +54 -0
- package/kits/docs/evolcore/role.md +3 -0
- package/kits/docs/evolcore/services.md +46 -18
- package/kits/docs/evolcore/stats.md +2 -0
- package/kits/docs/evolcore/thread-chain.md +2 -0
- package/kits/docs/evolcore/tool-authorization.md +10 -0
- package/kits/docs/evolcore/trigger.md +2 -0
- package/kits/rules/01-overview.md +11 -32
- package/kits/rules/02-navigation.md +7 -0
- package/kits/rules/06-channel.md +3 -3
- package/kits/schemas/_meta.json +38 -5
- package/kits/schemas/agent-config.schema.20.json +24 -0
- package/kits/schemas/agent-config.schema.21.json +974 -0
- package/kits/schemas/agent-config.schema.22.json +977 -0
- package/kits/schemas/agent-config.schema.23.json +958 -0
- package/kits/schemas/daemon.schema.10.json +373 -0
- package/kits/schemas/daemon.schema.9.json +12 -0
- package/kits/schemas/defaults.schema.7.json +472 -0
- package/kits/schemas/providers.schema.3.json +18 -2
- package/kits/schemas/relation-config.schema.13.json +289 -0
- package/kits/skills/.switches.json +17 -1
- package/kits/skills/ability/SKILL.md +229 -34
- package/kits/skills/ability/STRUCTURE.md +333 -0
- package/kits/skills/ability/references/cli.md +208 -0
- package/kits/skills/ability/references/development.md +107 -37
- package/kits/skills/ability/references/management.md +106 -46
- package/kits/skills/ability/references/runtime-protocol.md +65 -63
- package/kits/skills/agent-output-cards/SKILL.md +64 -0
- package/kits/skills/ec-group/SKILL.md +8 -6
- package/kits/skills/ec-group/TASK.md +186 -0
- package/kits/skills/ec-group/WORKLOG.md +180 -0
- package/kits/skills/ec-group-collaboration/SKILL.md +3 -3
- package/kits/skills/ec-pay/SKILL.md +101 -0
- package/kits/skills/ec-pay/references/pay-cli.md +110 -0
- package/kits/skills/ec-provider/SKILL.md +58 -9
- package/kits/skills/{ec-service-proxy → ec-proxy}/SKILL.md +8 -5
- package/kits/skills/ec-service-call/SKILL.md +135 -0
- package/kits/skills/ec-service-pack/SKILL.md +277 -0
- package/kits/skills/ec-trigger/SKILL.md +1 -1
- package/kits/templates/memory-consolidation/notes.md +2 -2
- package/kits/templates/memory-consolidation/workflow.md +46 -0
- package/kits/templates/roles/visitor.json +1 -0
- package/kits/templates/system-fragments/channel.md +13 -4
- package/kits/templates/system-fragments/commands.md +5 -3
- package/kits/templates/system-fragments/directory-contacts.md +3 -4
- package/kits/templates/system-fragments/reply.md +1 -0
- package/kits/templates/system-fragments/session.md +1 -1
- package/kits/templates/system-fragments/thread.md +27 -128
- package/kits/templates/system-fragments/venue.md +27 -0
- package/package.json +4 -5
- package/scripts/agent-template/inspect.mjs +79 -29
- package/scripts/agent-template/overlay.mjs +20 -2
- package/scripts/agent-template/shared/common.mjs +24 -6
- package/scripts/agent-template/shared/team-schema.json +23 -5
- package/scripts/agent-template/shared/template-contract.mjs +107 -17
- package/scripts/agent-template/shared/template-package.mjs +254 -29
- package/scripts/agent-template/shared/template-runtime.mjs +145 -2
- package/scripts/agent-template/shared/template.mjs +67 -9
- package/scripts/agent-template/team-pack.mjs +132 -41
- package/scripts/agent-template/team-preview.mjs +249 -5
- package/kits/docs/aun/ABILITY_CALLING.md +0 -280
- package/kits/docs/evolcore/ability.md +0 -185
- package/kits/skills/ability/references/calling.md +0 -56
- package/kits/skills/ability/references/contract-checklist.md +0 -37
- package/kits/skills/ability/references/recovery.md +0 -27
- /package/dist/{core/capability/providers → agents/gemini}/gemini-capability-provider.js +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CONTACT_RECEIPT_TTL_MS, trustedContactInboundDelivery } from './contact-pending-inbound.js';
|
|
1
2
|
import path from 'path';
|
|
2
3
|
import fs from 'fs';
|
|
3
4
|
import { logger } from '../../utils/logger.js';
|
|
@@ -9,12 +10,15 @@ import { isTopicThreadId, normalizeTopicAid, safeFormatMainTopicId } from '../th
|
|
|
9
10
|
/** Validate before either classification or restoration can rewrite the snapshot. */
|
|
10
11
|
export function parseQueueSnapshot(value) {
|
|
11
12
|
const file = value;
|
|
12
|
-
if (!file || ![1, 2, 3].includes(file.version) || !Array.isArray(file.queues)
|
|
13
|
+
if (!file || ![1, 2, 3, 4].includes(file.version) || !Array.isArray(file.queues)
|
|
13
14
|
|| (file.active !== undefined && !Array.isArray(file.active))
|
|
14
|
-
|| (file.version
|
|
15
|
+
|| (file.version >= 3 && (!Array.isArray(file.recoveryIndexedAids)
|
|
15
16
|
|| file.recoveryIndexedAids.some(aid => typeof aid !== 'string' || !aid) || !Array.isArray(file.active)))) {
|
|
16
17
|
throw new Error('invalid message queue snapshot');
|
|
17
18
|
}
|
|
19
|
+
if (file.version === 4 && (!Array.isArray(file.contactReceipts) || file.contactReceipts.some(receipt => !receipt || !/^[a-f0-9]{64}$/.test(receipt.key) || !Number.isFinite(receipt.acceptedAt)
|
|
20
|
+
|| !['queued', 'handled'].includes(receipt.outcome))))
|
|
21
|
+
throw new Error('invalid contact receipts');
|
|
18
22
|
const validPart = (part) => !!part && typeof part.projectPath === 'string'
|
|
19
23
|
&& !!part.projectPath && !!part.message && typeof part.message === 'object'
|
|
20
24
|
&& typeof part.message.channel === 'string' && typeof part.message.channelId === 'string';
|
|
@@ -28,7 +32,7 @@ export function parseQueueSnapshot(value) {
|
|
|
28
32
|
return file;
|
|
29
33
|
}
|
|
30
34
|
export function hasIndexedRecovery(file, aid) {
|
|
31
|
-
return file?.version
|
|
35
|
+
return (file?.version ?? 0) >= 3 && file?.recoveryIndexedAids?.includes(aid) === true;
|
|
32
36
|
}
|
|
33
37
|
const DEFAULT_AGENT_NAME = '<unknown>';
|
|
34
38
|
const RESTART_RESUME_CONTENT = 'evolcore 服务已重启,请继续之前未完成的任务。';
|
|
@@ -87,6 +91,42 @@ export class MessageQueue {
|
|
|
87
91
|
blockedReason;
|
|
88
92
|
wasObserverHintConsumed;
|
|
89
93
|
recoveryIndexedAids = [];
|
|
94
|
+
contactReceipts = new Map();
|
|
95
|
+
contactReceiptsLoaded = false;
|
|
96
|
+
contactDeliveryReceipt(key) {
|
|
97
|
+
if (!this.persistencePath)
|
|
98
|
+
throw new Error('durable contact queue unavailable');
|
|
99
|
+
if (!this.contactReceiptsLoaded) {
|
|
100
|
+
let snapshot;
|
|
101
|
+
try {
|
|
102
|
+
snapshot = parseQueueSnapshot(JSON.parse(fs.readFileSync(this.persistencePath, 'utf8')));
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
if (error.code !== 'ENOENT')
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
for (const receipt of snapshot?.contactReceipts ?? [])
|
|
109
|
+
this.contactReceipts.set(receipt.key, receipt);
|
|
110
|
+
this.contactReceiptsLoaded = true;
|
|
111
|
+
}
|
|
112
|
+
return this.contactReceipts.get(key);
|
|
113
|
+
}
|
|
114
|
+
finishContactDelivery(delivery) {
|
|
115
|
+
if (!trustedContactInboundDelivery(delivery))
|
|
116
|
+
throw new Error('untrusted contact delivery');
|
|
117
|
+
const previous = this.contactDeliveryReceipt(delivery.key);
|
|
118
|
+
if (previous) {
|
|
119
|
+
delivery.receipt = previous;
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const receipt = { key: delivery.key, acceptedAt: Date.now(), outcome: 'handled' };
|
|
123
|
+
this.contactReceipts.set(delivery.key, receipt);
|
|
124
|
+
if (!this.persistQueuesSync()) {
|
|
125
|
+
this.contactReceipts.delete(delivery.key);
|
|
126
|
+
throw new Error('failed to persist contact terminal outcome');
|
|
127
|
+
}
|
|
128
|
+
delivery.receipt = receipt;
|
|
129
|
+
}
|
|
90
130
|
blockedQueues = new Map();
|
|
91
131
|
readinessRetry;
|
|
92
132
|
shutdownPromise;
|
|
@@ -847,8 +887,13 @@ export class MessageQueue {
|
|
|
847
887
|
});
|
|
848
888
|
}
|
|
849
889
|
fs.mkdirSync(path.dirname(this.persistencePath), { recursive: true });
|
|
890
|
+
for (const [key, receipt] of this.contactReceipts) {
|
|
891
|
+
if (receipt.acceptedAt + CONTACT_RECEIPT_TTL_MS <= Date.now())
|
|
892
|
+
this.contactReceipts.delete(key);
|
|
893
|
+
}
|
|
850
894
|
const data = {
|
|
851
|
-
version:
|
|
895
|
+
version: 4,
|
|
896
|
+
contactReceipts: [...this.contactReceipts.values()],
|
|
852
897
|
recoveryIndexedAids: this.recoveryIndexedAids,
|
|
853
898
|
updatedAt: Date.now(),
|
|
854
899
|
queues: buckets,
|
|
@@ -976,7 +1021,10 @@ export class MessageQueue {
|
|
|
976
1021
|
}
|
|
977
1022
|
}
|
|
978
1023
|
const parsed = parseQueueSnapshot(captured);
|
|
979
|
-
this.recoveryIndexedAids = parsed.version
|
|
1024
|
+
this.recoveryIndexedAids = parsed.version >= 3 ? [...parsed.recoveryIndexedAids] : [];
|
|
1025
|
+
for (const receipt of parsed.contactReceipts ?? [])
|
|
1026
|
+
this.contactReceipts.set(receipt.key, receipt);
|
|
1027
|
+
this.contactReceiptsLoaded = true;
|
|
980
1028
|
// Version-1 snapshots did not carry per-item enqueue times. Preserve
|
|
981
1029
|
// their last durable snapshot time instead of making restored history
|
|
982
1030
|
// look newly queued at the moment of daemon restart.
|
|
@@ -1072,10 +1120,12 @@ export class MessageQueue {
|
|
|
1072
1120
|
shouldRestoreMessage(message, sessionId) {
|
|
1073
1121
|
if (message.source === 'owner-inject')
|
|
1074
1122
|
return false;
|
|
1075
|
-
//
|
|
1076
|
-
//
|
|
1077
|
-
|
|
1123
|
+
// One-shot grants do not survive a restart. Persistent Agent/session policy
|
|
1124
|
+
// tasks do: ResponseEngine revalidates the current policy before execution.
|
|
1125
|
+
const authorization = message.executionPermissionOverride;
|
|
1126
|
+
if (authorization && authorization.source !== 'agent-policy' && authorization.source !== 'session-policy')
|
|
1078
1127
|
return false;
|
|
1128
|
+
// Trigger continuations belong to the scheduler's durable run checkpoint.
|
|
1079
1129
|
if (message.source !== 'trigger' && !message.triggerMeta)
|
|
1080
1130
|
return true;
|
|
1081
1131
|
this.droppedTriggerSessionIds.add(sessionId);
|
|
@@ -1095,14 +1145,24 @@ export class MessageQueue {
|
|
|
1095
1145
|
// broadcast object must be cloned per agent before dedup/cancel logic.
|
|
1096
1146
|
message = { ...message, selfAID: options.selfAID };
|
|
1097
1147
|
}
|
|
1148
|
+
const contactDelivery = trustedContactInboundDelivery(options?.contactDelivery);
|
|
1149
|
+
if (contactDelivery) {
|
|
1150
|
+
const receipt = this.contactDeliveryReceipt(contactDelivery.key);
|
|
1151
|
+
if (receipt) {
|
|
1152
|
+
contactDelivery.receipt = receipt;
|
|
1153
|
+
options?.onPersisted?.();
|
|
1154
|
+
return;
|
|
1155
|
+
}
|
|
1156
|
+
contactDelivery.validate();
|
|
1157
|
+
}
|
|
1098
1158
|
// 消息去重检查
|
|
1099
|
-
if (message.source !== 'owner-inject' && !this.shouldProcess(sessionKey, message, options?.selfAID)) {
|
|
1159
|
+
if (!contactDelivery && message.source !== 'owner-inject' && !this.shouldProcess(sessionKey, message, options?.selfAID)) {
|
|
1100
1160
|
options?.onPersisted?.();
|
|
1101
1161
|
return Promise.resolve();
|
|
1102
1162
|
}
|
|
1103
1163
|
// 拦截器检查:AskUserQuestion 等场景的一次性消息拦截
|
|
1104
1164
|
const interceptor = this.interceptors.get(sessionKey);
|
|
1105
|
-
const canAnswerInteraction = !message.executionPermissionOverride && (message.source === undefined
|
|
1165
|
+
const canAnswerInteraction = !contactDelivery && !message.executionPermissionOverride && (message.source === undefined
|
|
1106
1166
|
|| message.source === 'user'
|
|
1107
1167
|
|| message.source === 'card-trigger');
|
|
1108
1168
|
if (interceptor && canAnswerInteraction) {
|
|
@@ -1217,7 +1277,23 @@ export class MessageQueue {
|
|
|
1217
1277
|
abortHandler();
|
|
1218
1278
|
return;
|
|
1219
1279
|
}
|
|
1280
|
+
let contactReceipt;
|
|
1281
|
+
if (contactDelivery) {
|
|
1282
|
+
try {
|
|
1283
|
+
contactDelivery.validate();
|
|
1284
|
+
}
|
|
1285
|
+
catch (error) {
|
|
1286
|
+
queue.splice(queue.indexOf(queuedItem), 1);
|
|
1287
|
+
this.logicalQueue.removeProcessed(queueKey, message.messageId ? [message.messageId] : []);
|
|
1288
|
+
rejectOnce(error);
|
|
1289
|
+
return;
|
|
1290
|
+
}
|
|
1291
|
+
contactReceipt = { key: contactDelivery.key, sessionId: sessionKey, acceptedAt: Date.now(), outcome: 'queued' };
|
|
1292
|
+
this.contactReceipts.set(contactDelivery.key, contactReceipt);
|
|
1293
|
+
}
|
|
1220
1294
|
if (!this.persistQueues()) {
|
|
1295
|
+
if (contactDelivery)
|
|
1296
|
+
this.contactReceipts.delete(contactDelivery.key);
|
|
1221
1297
|
const index = queue.indexOf(queuedItem);
|
|
1222
1298
|
if (index >= 0)
|
|
1223
1299
|
queue.splice(index, 1);
|
|
@@ -1226,6 +1302,8 @@ export class MessageQueue {
|
|
|
1226
1302
|
rejectOnce(new Error('failed to persist message queue'));
|
|
1227
1303
|
return;
|
|
1228
1304
|
}
|
|
1305
|
+
if (contactDelivery && contactReceipt)
|
|
1306
|
+
contactDelivery.receipt = contactReceipt;
|
|
1229
1307
|
// A duplicate must not re-enter a runner after the queue entry has
|
|
1230
1308
|
// survived its write-ahead snapshot. Keep this separate from the queue
|
|
1231
1309
|
// snapshot because deduplication must survive task completion.
|
|
@@ -1235,14 +1313,20 @@ export class MessageQueue {
|
|
|
1235
1313
|
options?.onPersisted?.();
|
|
1236
1314
|
}
|
|
1237
1315
|
catch (error) {
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1316
|
+
if (contactDelivery) {
|
|
1317
|
+
// Persistence is already committed; a diagnostic/release callback must not retract acceptance.
|
|
1318
|
+
logger.warn('[Queue] Contact onPersisted callback failed:', error);
|
|
1319
|
+
}
|
|
1320
|
+
else {
|
|
1321
|
+
const index = queue.indexOf(queuedItem);
|
|
1322
|
+
if (index >= 0)
|
|
1323
|
+
queue.splice(index, 1);
|
|
1324
|
+
this.logicalQueue.removeProcessed(queueKey, message.messageId ? [message.messageId] : []);
|
|
1325
|
+
this.forgetProcessed(sessionKey, message);
|
|
1326
|
+
this.persistQueues();
|
|
1327
|
+
rejectOnce(error);
|
|
1328
|
+
return;
|
|
1329
|
+
}
|
|
1246
1330
|
}
|
|
1247
1331
|
if (options?.resolveOnPersist)
|
|
1248
1332
|
resolveOnce();
|
|
@@ -136,11 +136,22 @@ export function resolveChatModeForPeer(params) {
|
|
|
136
136
|
* invalidateKitCache——schema 换了新的,出厂默认表却永久停在进程启动那一刻。
|
|
137
137
|
*/
|
|
138
138
|
export function chatmodeFactoryDefaults() {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
139
|
+
// 默认值挂在 chatmode 的三个子字段上(不接受 chatmode 对象级 default:
|
|
140
|
+
// 对象级默认值会让"整块未配置"变成"整块已配置",见
|
|
141
|
+
// docs/config/11-default-value-levels.md)。
|
|
142
|
+
const children = loadSchema('agent-config').fields.get('chatmode')?.children;
|
|
143
|
+
const field = (name) => {
|
|
144
|
+
const value = children?.get(name)?.default;
|
|
145
|
+
return value === 'interactive' || value === 'proactive' ? value : undefined;
|
|
146
|
+
};
|
|
147
|
+
const privateMode = field('private');
|
|
148
|
+
const nothumanMode = field('nothuman');
|
|
149
|
+
// group 场景只有 proactive 一个合法值,schema 枚举已把这一点固定住。
|
|
150
|
+
const groupMode = field('group') === 'proactive' ? 'proactive' : undefined;
|
|
151
|
+
if (!privateMode || !groupMode || !nothumanMode) {
|
|
152
|
+
throw new Error('[peer-mode] agent-config schema 缺少 chatmode 出厂默认值(chatmode.{private,group,nothuman}.default)');
|
|
142
153
|
}
|
|
143
|
-
return {
|
|
154
|
+
return { private: privateMode, group: groupMode, nothuman: nothumanMode };
|
|
144
155
|
}
|
|
145
156
|
export function chatmodeFieldForPeer(chatType, peerType) {
|
|
146
157
|
const kind = normalizePeerType(peerType);
|
|
@@ -23,7 +23,6 @@ import { notifyWorkbenchRuntimeChanged } from '../../workbench/service.js';
|
|
|
23
23
|
import { createSendFileMarkerPattern } from './file-markers.js';
|
|
24
24
|
import { hasOwnerDirectoryMarkdown } from '../../directory/owner-directory-markdown.js';
|
|
25
25
|
import { EMPTY_IDENTITY, readOwnerDirectoryIdentity } from '../../directory/owner-directory-identity.js';
|
|
26
|
-
import { resolveContactsState } from '../../directory/owner-directory-policy.js';
|
|
27
26
|
import { createDecisionInferenceProvider, createTextInferenceProvider } from '../inference/text-inference.js';
|
|
28
27
|
import { StreamIdleMonitor } from './stream-idle-monitor.js';
|
|
29
28
|
import { logger } from '../../utils/logger.js';
|
|
@@ -92,6 +91,24 @@ import { aunMessageTranscriptUuid } from '../session/session-transcript.js';
|
|
|
92
91
|
import { assertAgentPolicyAuthorization } from '../role/runtime-policy.js';
|
|
93
92
|
import { auditFullAccessEvent } from '../auth/authorization-audit.js';
|
|
94
93
|
import { REPLY_DELIVERY_FAILED_REASON, TaskRecoveryService, isTaskRecoveryCurrent } from '../task/task-recovery-service.js';
|
|
94
|
+
/** Keep diagnostic logs useful without dumping command bodies or tool output. */
|
|
95
|
+
function diagnosticPreview(value, maxLength = 240) {
|
|
96
|
+
if (value === undefined || value === null)
|
|
97
|
+
return '';
|
|
98
|
+
let text;
|
|
99
|
+
if (typeof value === 'string')
|
|
100
|
+
text = value;
|
|
101
|
+
else {
|
|
102
|
+
try {
|
|
103
|
+
text = JSON.stringify(value);
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
text = String(value);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
text = text.replace(/[\r\n\u2028\u2029]/g, ' ');
|
|
110
|
+
return text.length <= maxLength ? text : `${text.slice(0, maxLength - 1)}…`;
|
|
111
|
+
}
|
|
95
112
|
/** Resolve the channel type separately from a channel instance name. */
|
|
96
113
|
export function resolveMessageChannelType(options, message) {
|
|
97
114
|
return options?.channelType || message.channelType || message.channel;
|
|
@@ -4027,6 +4044,12 @@ export class ResponseEngine {
|
|
|
4027
4044
|
? (peerRoleDetail.effectiveRole ?? 'visitor')
|
|
4028
4045
|
: (isOwnerDirectoryContact(selfAid || '', configActorId || '') ? 'member' : 'visitor'))
|
|
4029
4046
|
: peerRole;
|
|
4047
|
+
const sameOwnerQualificationResult = configChannelType === 'aun'
|
|
4048
|
+
&& configChatType === 'private'
|
|
4049
|
+
&& !!selfAid
|
|
4050
|
+
&& !!configActorId
|
|
4051
|
+
? sameOwnerQualification(selfAid, configActorId)
|
|
4052
|
+
: 'not_applicable';
|
|
4030
4053
|
let effectiveAgentConfigError;
|
|
4031
4054
|
const effectiveAgentConfig = (() => {
|
|
4032
4055
|
try {
|
|
@@ -4041,7 +4064,8 @@ export class ResponseEngine {
|
|
|
4041
4064
|
// ─── 响应模式解析(插件化机制中枢)───
|
|
4042
4065
|
// trigger override 绝对优先;否则由 Coordinator 解析(responseMode 标量 > 注册表首选)。
|
|
4043
4066
|
const systemOrServicePeer = isSystemOrServicePeer(peerType);
|
|
4044
|
-
const triggerChatModeOverride = systemOrServicePeer
|
|
4067
|
+
const triggerChatModeOverride = systemOrServicePeer && message.source !== 'trigger'
|
|
4068
|
+
? undefined : message.triggerMeta?.chatModeOverride;
|
|
4045
4069
|
// chatmode 是顶层字典(agent 级与关系级同名,已由 ConfigManager 逐键合并)。
|
|
4046
4070
|
// 实际生效值由对端类型选键(private/nothuman/group),出厂默认走 schema。
|
|
4047
4071
|
const chatModeFallback = resolveChatMode({
|
|
@@ -4054,13 +4078,25 @@ export class ResponseEngine {
|
|
|
4054
4078
|
});
|
|
4055
4079
|
// Resolve overrides before binding a flow so hooks, context and envelope
|
|
4056
4080
|
// all use the same scene-checked mode for this task.
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4081
|
+
// Trigger 轮次的 chatMode 一律沿用会话自身,不按唤醒源的 peerType 判定。
|
|
4082
|
+
// message.peerType 在这里表达的是「谁把我叫醒」(trigger 恒为 system),与
|
|
4083
|
+
// 「这个会话在跟谁说话」正交;拿它走下面的 systemOrServicePeer 分支,会把
|
|
4084
|
+
// agent 对端的会话压成 interactive。真系统会话(记忆整理、daemon 内部)由
|
|
4085
|
+
// systemSession 标记排除,保持原行为。
|
|
4086
|
+
const sessionChatModeSource = message.source === 'trigger'
|
|
4087
|
+
&& !readSystemSessionMarker(session.metadata)
|
|
4088
|
+
? this.resolveEffectiveChatmodeForSession(session, channelKey, message.channelId)
|
|
4089
|
+
: undefined;
|
|
4090
|
+
const effectiveChatMode = triggerChatModeOverride && sessionChatModeSource
|
|
4091
|
+
? chatModeForScene(triggerChatModeOverride, { channelType: currentChannelType, chatType,
|
|
4092
|
+
peerType: session.metadata?.peerType, role: peerRole })
|
|
4093
|
+
: sessionChatModeSource ?? (chatType === 'group'
|
|
4094
|
+
? 'proactive'
|
|
4095
|
+
: systemOrServicePeer
|
|
4096
|
+
? 'interactive'
|
|
4097
|
+
: triggerChatModeOverride
|
|
4098
|
+
? chatModeForScene(triggerChatModeOverride, { channelType: currentChannelType, chatType, peerType, role: peerRole })
|
|
4099
|
+
: chatModeFallback);
|
|
4064
4100
|
const responseModeAgentDir = selfAid ? resolveAgentDir(selfAid) : undefined;
|
|
4065
4101
|
// mentionMode:顶层通用参数(先读出备用,投递/入队策略后续接入)
|
|
4066
4102
|
const mentionMode = effectiveAgentConfig?.mentionMode ?? 'disabled';
|
|
@@ -4650,17 +4686,39 @@ export class ResponseEngine {
|
|
|
4650
4686
|
send: async (payload) => {
|
|
4651
4687
|
if (turnLease && !this.turnCoordinator.canPublish(turnLease)) {
|
|
4652
4688
|
snapshot.pushOutbound(session.id, taskId, { kind: payload.kind, decision: 'suppressed-stale-turn' });
|
|
4689
|
+
logger.info(`[ResponseEngine] outbound.suppressed ${JSON.stringify({
|
|
4690
|
+
reason: 'stale_turn',
|
|
4691
|
+
kind: payload.kind,
|
|
4692
|
+
taskId,
|
|
4693
|
+
sessionId: session.id,
|
|
4694
|
+
messageId: message.messageId ?? 'none',
|
|
4695
|
+
})}`);
|
|
4653
4696
|
return;
|
|
4654
4697
|
}
|
|
4655
4698
|
// proactive 模式:activity.batch 是 thought 协议内容,只发给支持 thought 的 channel
|
|
4656
4699
|
// (不支持 thought 的 channel 静默丢弃,避免降级为普通消息)
|
|
4657
4700
|
if (isProactive && payload.kind === 'activity.batch' && !adapter.capabilities?.thought) {
|
|
4658
4701
|
snapshot.pushOutbound(session.id, taskId, { kind: payload.kind, decision: 'suppressed-thought' });
|
|
4702
|
+
logger.info(`[ResponseEngine] outbound.suppressed ${JSON.stringify({
|
|
4703
|
+
reason: 'channel_without_thought_capability',
|
|
4704
|
+
kind: payload.kind,
|
|
4705
|
+
chatmode,
|
|
4706
|
+
activityTransport,
|
|
4707
|
+
taskId,
|
|
4708
|
+
sessionId: session.id,
|
|
4709
|
+
})}`);
|
|
4659
4710
|
return;
|
|
4660
4711
|
}
|
|
4661
4712
|
const isCurrentlyBackground = this.isBackgroundSession(session, message.channel, message.channelId);
|
|
4662
4713
|
if (isCurrentlyBackground) {
|
|
4663
4714
|
snapshot.pushOutbound(session.id, taskId, { kind: payload.kind, decision: 'suppressed-bg' });
|
|
4715
|
+
logger.info(`[ResponseEngine] outbound.suppressed ${JSON.stringify({
|
|
4716
|
+
reason: 'background_session',
|
|
4717
|
+
kind: payload.kind,
|
|
4718
|
+
chatmode,
|
|
4719
|
+
taskId,
|
|
4720
|
+
sessionId: session.id,
|
|
4721
|
+
})}`);
|
|
4664
4722
|
return;
|
|
4665
4723
|
}
|
|
4666
4724
|
const opts = {};
|
|
@@ -4702,7 +4760,46 @@ export class ResponseEngine {
|
|
|
4702
4760
|
}
|
|
4703
4761
|
const enrichedEnvelope = withEnvelopeReplyContext(envelope, opts);
|
|
4704
4762
|
snapshot.pushOutbound(session.id, taskId, { kind: payload.kind, decision: 'sent' });
|
|
4705
|
-
|
|
4763
|
+
const shouldTraceDelivery = payload.kind === 'result.text'
|
|
4764
|
+
|| (payload.kind === 'activity.batch' && payload.isFinal === true);
|
|
4765
|
+
if (shouldTraceDelivery) {
|
|
4766
|
+
logger.info(`[ResponseEngine] outbound.attempt ${JSON.stringify({
|
|
4767
|
+
kind: payload.kind,
|
|
4768
|
+
isFinal: payload.isFinal === true,
|
|
4769
|
+
chatmode,
|
|
4770
|
+
activityTransport,
|
|
4771
|
+
taskId,
|
|
4772
|
+
sessionId: session.id,
|
|
4773
|
+
messageId: message.messageId ?? 'none',
|
|
4774
|
+
textLength: typeof payload.text === 'string' ? payload.text.length : undefined,
|
|
4775
|
+
})}`);
|
|
4776
|
+
}
|
|
4777
|
+
try {
|
|
4778
|
+
const receipt = await adapter.send(enrichedEnvelope, payload);
|
|
4779
|
+
if (shouldTraceDelivery) {
|
|
4780
|
+
logger.info(`[ResponseEngine] outbound.accepted ${JSON.stringify({
|
|
4781
|
+
kind: payload.kind,
|
|
4782
|
+
isFinal: payload.isFinal === true,
|
|
4783
|
+
taskId,
|
|
4784
|
+
sessionId: session.id,
|
|
4785
|
+
})}`);
|
|
4786
|
+
}
|
|
4787
|
+
return receipt;
|
|
4788
|
+
}
|
|
4789
|
+
catch (error) {
|
|
4790
|
+
logger.error(`[ResponseEngine] outbound.failed ${JSON.stringify({
|
|
4791
|
+
kind: payload.kind,
|
|
4792
|
+
isFinal: payload.isFinal === true,
|
|
4793
|
+
chatmode,
|
|
4794
|
+
activityTransport,
|
|
4795
|
+
taskId,
|
|
4796
|
+
sessionId: session.id,
|
|
4797
|
+
messageId: message.messageId ?? 'none',
|
|
4798
|
+
error: diagnosticPreview(error instanceof Error ? error.message : error),
|
|
4799
|
+
code: error?.code,
|
|
4800
|
+
})}`);
|
|
4801
|
+
throw error;
|
|
4802
|
+
}
|
|
4706
4803
|
},
|
|
4707
4804
|
});
|
|
4708
4805
|
this.activeRenderers.set(session.id, {
|
|
@@ -5319,6 +5416,25 @@ export class ResponseEngine {
|
|
|
5319
5416
|
// records all observe the same normalized value.
|
|
5320
5417
|
permissionContext.permissionMode = effectivePermissionMode;
|
|
5321
5418
|
permissionContext.executionPermission = fullAccessAuthorization;
|
|
5419
|
+
logger.info(`[ResponseEngine] authorization.resolved ${JSON.stringify({
|
|
5420
|
+
messageId: message.messageId ?? 'none',
|
|
5421
|
+
taskId,
|
|
5422
|
+
sessionId: session.id,
|
|
5423
|
+
selfAid: selfAid ?? 'none',
|
|
5424
|
+
actorId: configActorId ?? 'none',
|
|
5425
|
+
peerKey: peerKey ?? 'none',
|
|
5426
|
+
peerType: peerType ?? 'unknown',
|
|
5427
|
+
peerRole,
|
|
5428
|
+
speakerRelation,
|
|
5429
|
+
roleSource: authorizationIdentity ? 'execution-identity' : peerRoleDetail?.source ?? 'session-fallback',
|
|
5430
|
+
roleExists: peerRoleDetail?.roleExists,
|
|
5431
|
+
allowAccess: peerRoleDetail?.allowAccess,
|
|
5432
|
+
authenticated: peerRoleDetail?.isAuthenticated ?? hasTrustedPrincipal(authenticatedActor),
|
|
5433
|
+
principalStatus: authenticatedActor.principalStatus,
|
|
5434
|
+
sameOwnerQualification: sameOwnerQualificationResult,
|
|
5435
|
+
permissionMode: effectivePermissionMode,
|
|
5436
|
+
permissionOverride: triggerPermissionModeOverride ?? commandFullAccess?.permissionMode ?? 'none',
|
|
5437
|
+
})}`);
|
|
5322
5438
|
const showFullAccessPrompt = fullAccessAuthorization?.source === 'fullaccess-command'
|
|
5323
5439
|
|| (fullAccessAuthorization?.source === 'session-policy'
|
|
5324
5440
|
&& readSessionFullAccessOverride(session)?.promptedSessionId !== session.id);
|
|
@@ -5678,21 +5794,7 @@ export class ResponseEngine {
|
|
|
5678
5794
|
// isOwner 与 ownerAid 同源(归属协议),避免名录快照滞后时把自封 Owner 的角色注入进去。
|
|
5679
5795
|
isPersonalAssistant: !!personalAssistantAid && personalAssistantAid === selfAid,
|
|
5680
5796
|
isOwner: !!protocolOwnerAid && protocolOwnerAid === selfAid,
|
|
5681
|
-
|
|
5682
|
-
// 只说"能",不说"谁关的"——默认关与显式关在结果上没区别。
|
|
5683
|
-
...(() => {
|
|
5684
|
-
if (!selfAid)
|
|
5685
|
-
return {};
|
|
5686
|
-
const state = resolveContactsState(selfAid, personalAssistantAid);
|
|
5687
|
-
const open = ['Owner', '个人助理'];
|
|
5688
|
-
if (state.internalContacts)
|
|
5689
|
-
open.push('内部联系人');
|
|
5690
|
-
if (state.externalContacts)
|
|
5691
|
-
open.push('外部联系人');
|
|
5692
|
-
if (state.strangerContacts)
|
|
5693
|
-
open.push('名录外的人');
|
|
5694
|
-
return { contactsState: `现在可联系:${open.join('、')}` };
|
|
5695
|
-
})(),
|
|
5797
|
+
contactsState: '普通出站消息可直接按 AID 发送;入站按联系人范围与许可准入',
|
|
5696
5798
|
// 记忆系统开关变量(来自 effectiveAgentConfig.memory,默认全部启用)。
|
|
5697
5799
|
// enableRelation 是总开关:relation 是所有记忆的唯一出生地。
|
|
5698
5800
|
// memory.enableRelation 在 relation-config schema 里声明了 x-merge-logic: AND,
|
|
@@ -5757,6 +5859,8 @@ export class ResponseEngine {
|
|
|
5757
5859
|
?? session.metadata?.mentionMode
|
|
5758
5860
|
?? message.mentionMode
|
|
5759
5861
|
?? undefined,
|
|
5862
|
+
// 私聊 @ 策略只从 Agent 级取:没有服务器下发值,也没有关系级覆盖。
|
|
5863
|
+
privateMentionMode: effectiveAgentConfig?.privateMentionMode ?? 'disabled',
|
|
5760
5864
|
groupHistoryAvailable: canUseGroupHistory('ec.group.history'),
|
|
5761
5865
|
clientType: message.clientType || undefined,
|
|
5762
5866
|
permissionMode: effectivePermissionMode,
|
|
@@ -6901,6 +7005,20 @@ export class ResponseEngine {
|
|
|
6901
7005
|
throw tagged;
|
|
6902
7006
|
}
|
|
6903
7007
|
}
|
|
7008
|
+
logger.info(`[ResponseEngine] output.decision ${JSON.stringify({
|
|
7009
|
+
sessionId: session.id,
|
|
7010
|
+
taskId,
|
|
7011
|
+
messageId: message.messageId ?? 'none',
|
|
7012
|
+
chatmode,
|
|
7013
|
+
activityTransport: activityTransport ?? 'none',
|
|
7014
|
+
isProactive,
|
|
7015
|
+
streamIsError: streamResult.isError,
|
|
7016
|
+
terminalInterrupt,
|
|
7017
|
+
isNoopReply,
|
|
7018
|
+
streamTextLength: (streamResult.lastReplyText || streamResult.fullText || '').length,
|
|
7019
|
+
rendererTextLength: renderer.getFinalText().length,
|
|
7020
|
+
rendererSentContent: renderer.hasSentContent(),
|
|
7021
|
+
})}`);
|
|
6904
7022
|
if (!streamResult.isError && !terminalInterrupt) {
|
|
6905
7023
|
const commitDecision = await this.turnCoordinator.commit(session, turnLease, this.buildTurnCommitEvidence(session, streamResult));
|
|
6906
7024
|
if (!commitDecision.ok) {
|
|
@@ -8281,7 +8399,12 @@ export class ResponseEngine {
|
|
|
8281
8399
|
?? (decision === 'deny' ? 'blocked' : event.isError ? 'failed' : 'completed');
|
|
8282
8400
|
eventDetail = ` tool=${event.name} ok=${decision === 'allow' && executed}`
|
|
8283
8401
|
+ ` decision=${decision} executed=${executed} executionState=${executionState}`
|
|
8284
|
-
+ (event.policyCode ? ` policy=${event.policyCode}` : '')
|
|
8402
|
+
+ (event.policyCode ? ` policy=${event.policyCode}` : '')
|
|
8403
|
+
+ (event.exitCode !== undefined ? ` exitCode=${event.exitCode}` : '')
|
|
8404
|
+
+ (event.errorCode ? ` errorCode=${event.errorCode}` : '')
|
|
8405
|
+
+ (event.error ? ` error="${diagnosticPreview(event.error, 180)}"` : '')
|
|
8406
|
+
+ (event.result !== undefined && (event.isError || event.exitCode !== undefined)
|
|
8407
|
+
? ` result="${diagnosticPreview(event.result, 180)}"` : '');
|
|
8285
8408
|
}
|
|
8286
8409
|
const frameworkEvents = new Set(['session_id', 'state_changed', 'status']);
|
|
8287
8410
|
if (frameworkEvents.has(event.type)) {
|
|
@@ -8718,6 +8841,31 @@ export class ResponseEngine {
|
|
|
8718
8841
|
}
|
|
8719
8842
|
if (original)
|
|
8720
8843
|
removePendingToolInput(original);
|
|
8844
|
+
if (event.isError || event.error || event.exitCode !== undefined) {
|
|
8845
|
+
const command = typeof original?.input?.command === 'string'
|
|
8846
|
+
? original.input.command
|
|
8847
|
+
: typeof original?.input?.input === 'string'
|
|
8848
|
+
? original.input.input
|
|
8849
|
+
: undefined;
|
|
8850
|
+
logger.warn(`[ResponseEngine] tool.result.diagnostic ${JSON.stringify({
|
|
8851
|
+
sessionId: session.id,
|
|
8852
|
+
taskId: turnLease?.taskId ?? 'none',
|
|
8853
|
+
toolName: event.name,
|
|
8854
|
+
callId: event.callId ?? 'none',
|
|
8855
|
+
correlationId: event.correlationId ?? 'none',
|
|
8856
|
+
command: command ? diagnosticPreview(command) : undefined,
|
|
8857
|
+
isError: event.isError === true,
|
|
8858
|
+
decision: event.decision ?? 'error',
|
|
8859
|
+
decisionSource: event.decisionSource ?? 'runner',
|
|
8860
|
+
executed: event.executed,
|
|
8861
|
+
executionState: event.executionState,
|
|
8862
|
+
exitCode: event.exitCode,
|
|
8863
|
+
errorCode: event.errorCode,
|
|
8864
|
+
errorDetailCode: event.errorDetailCode,
|
|
8865
|
+
error: diagnosticPreview(event.error),
|
|
8866
|
+
result: diagnosticPreview(event.result),
|
|
8867
|
+
})}`);
|
|
8868
|
+
}
|
|
8721
8869
|
if (original && modeHooks?.mode?.onToolResult) {
|
|
8722
8870
|
const proactiveState = modeHooks.state.get('proactive');
|
|
8723
8871
|
await modeHooks.mode.onToolResult({
|
|
@@ -16,13 +16,46 @@ export const MANAGED_SEND_VALUE_FLAGS = [
|
|
|
16
16
|
];
|
|
17
17
|
/** 布尔选项。 */
|
|
18
18
|
export const MANAGED_SEND_BOOLEAN_FLAGS = [
|
|
19
|
-
'--
|
|
19
|
+
'--mention-all',
|
|
20
20
|
];
|
|
21
|
+
/**
|
|
22
|
+
* 三态取值的选项:必须带 `yes|no|auto` 之一,裸写即参数错误。
|
|
23
|
+
*
|
|
24
|
+
* 为什么单独一类:`--encrypt` 曾同时被当成布尔(`ec msg send`)和取值
|
|
25
|
+
* (`ecmsg` 网关)两种东西,于是文档示例 `--encrypt yes` 在托管发送里把
|
|
26
|
+
* `yes` 读成正文,和 `--payload-file` 撞成正文冲突、被判违规直到熔断。
|
|
27
|
+
* 现在三处解析共用这一张表,且只有三态、没有"裸写等价某值"这回事。
|
|
28
|
+
*
|
|
29
|
+
* 不带 `--encrypt` 整个参数时才是默认值 `auto`。
|
|
30
|
+
*/
|
|
31
|
+
export const MANAGED_SEND_TRISTATE_FLAGS = [
|
|
32
|
+
'--encrypt',
|
|
33
|
+
];
|
|
34
|
+
/** `--encrypt` 的合法取值。 */
|
|
35
|
+
export const ENCRYPT_MODES = ['yes', 'no', 'auto'];
|
|
36
|
+
/**
|
|
37
|
+
* 把 `--encrypt` 的取值归一成下游的二态布尔。
|
|
38
|
+
*
|
|
39
|
+
* `auto` 无法在本地判定(要看本轮是否被对端消息触发、以及那条消息的加密态),
|
|
40
|
+
* 因此返回 undefined,交给路由层按 `auto` 语义解析。本函数只接受三态之一,
|
|
41
|
+
* 裸写(undefined)属于参数错误,由调用方在解析阶段拒绝。
|
|
42
|
+
*/
|
|
43
|
+
export function resolveEncryptFlagValue(value) {
|
|
44
|
+
if (value === 'yes')
|
|
45
|
+
return true;
|
|
46
|
+
if (value === 'no')
|
|
47
|
+
return false;
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
/** `--encrypt` 取值是否合法(供各解析点给出统一报错)。 */
|
|
51
|
+
export function isValidEncryptMode(value) {
|
|
52
|
+
return value !== undefined && ENCRYPT_MODES.includes(value);
|
|
53
|
+
}
|
|
21
54
|
/**
|
|
22
55
|
* 网关自己消费、不向下游透传的选项。
|
|
23
56
|
*
|
|
24
|
-
*
|
|
25
|
-
* `--encrypt
|
|
57
|
+
* `--encrypt` 在网关侧就是三态取值参数,解析后向下游下发二态。
|
|
58
|
+
* `--no-encrypt` 已移除:等价写法是 `--encrypt no`。
|
|
26
59
|
*/
|
|
27
60
|
export const GATEWAY_ROUTE_VALUE_FLAGS = [
|
|
28
61
|
'--thread', '--to', '--from', '--check-every', '--encrypt', '--format',
|
|
@@ -40,4 +73,5 @@ export const GATEWAY_FLAG_ALIASES = {};
|
|
|
40
73
|
export const MANAGED_SEND_KNOWN_FLAGS = [
|
|
41
74
|
...MANAGED_SEND_VALUE_FLAGS,
|
|
42
75
|
...MANAGED_SEND_BOOLEAN_FLAGS,
|
|
76
|
+
...MANAGED_SEND_TRISTATE_FLAGS,
|
|
43
77
|
];
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* I5 跨话题必有复查周期(缺省补默认);同话题永不建复查
|
|
19
19
|
* I6 加密默认 auto;只有目标对端是 AUN 时才能加密
|
|
20
20
|
*/
|
|
21
|
-
import { canonicalizeMainTopicId, formatMainTopicId, isExternalTopicThreadId, isMainTopicId, mainTopicPeer, normalizeTopicAid, } from '../thread/topic-id.js';
|
|
21
|
+
import { canonicalizeMainTopicId, formatMainTopicId, isExternalTopicThreadId, isMainTopicId, isSelfTopicPeer, mainTopicPeer, normalizeTopicAid, } from '../thread/topic-id.js';
|
|
22
22
|
// ── 常量 ────────────────────────────────────────────────────────────────
|
|
23
23
|
/** 跨话题缺省复查周期(plan 假设 A1)。改这里即可调整全局节奏。 */
|
|
24
24
|
export const DEFAULT_CROSS_TOPIC_CHECK_EVERY = '20m';
|
|
@@ -98,6 +98,10 @@ function resolveThreadOption(raw, self, deps) {
|
|
|
98
98
|
if (!peerId) {
|
|
99
99
|
return fail('IDENTITY_MISMATCH', `主话题 ${value} 不属于当前本端 ${self}——主话题 id 由本端与对端共同构成`);
|
|
100
100
|
}
|
|
101
|
+
// `main:<本端>:<本端>` 这类自反主话题同样是残缺结构,不能当正常话题投递。
|
|
102
|
+
if (isSelfTopicPeer(peerId, self)) {
|
|
103
|
+
return fail('SELF_PEER_NOT_ALLOWED', `话题对端不能是本端自己(${peerId})`, `跨话题自派请写 --thread <真实对端的话题id> --to ${self}`);
|
|
104
|
+
}
|
|
101
105
|
const threadId = canonicalizeMainTopicId(value) ?? value;
|
|
102
106
|
// 主话题 id 里只有两个 AID,没有类型信息:群的主话题同样写成 main:<self>:<群AID>。
|
|
103
107
|
// 类型由调用方按关系证据注入;没有注入时才按私聊,保持旧行为。
|
|
@@ -112,6 +116,11 @@ function resolveThreadOption(raw, self, deps) {
|
|
|
112
116
|
if (normalizeTopicAid(info.selfAid) !== normalizeTopicAid(self)) {
|
|
113
117
|
return fail('IDENTITY_MISMATCH', `话题 ${value} 的本端是 ${info.selfAid},不是当前会话本端 ${self}`);
|
|
114
118
|
}
|
|
119
|
+
// 历史残题(对端 = 本端)在索引里仍然存在,这里兜住:既有的残缺话题不再能继续发消息。
|
|
120
|
+
// 创建侧的拦截只管新话题,已经建出来的只能靠这一层和 `ec thread delete` 清理。
|
|
121
|
+
if (isSelfTopicPeer(info.peer.id, self)) {
|
|
122
|
+
return fail('SELF_PEER_NOT_ALLOWED', `话题 ${value} 的对端是本端自己(${info.peer.id}),该话题结构残缺,无法投递`, `请用 ec thread delete ${info.peer.id}/${value} 清理后,改以真实对端建话题`);
|
|
123
|
+
}
|
|
115
124
|
return { peer: info.peer, threadId: value };
|
|
116
125
|
}
|
|
117
126
|
return fail('INVALID_THREAD_REF', `--thread 只接受 thread-… 或 main:<aidA>:<aidB>,收到 "${value}"`, '裸对端 AID 不是话题 id;要指定对端请用 --to');
|
|
@@ -265,12 +274,7 @@ export function resolveSendRoute(input, session, deps = {}) {
|
|
|
265
274
|
}
|
|
266
275
|
// 6. 加密
|
|
267
276
|
let encrypt = 'auto';
|
|
268
|
-
if (input.
|
|
269
|
-
return fail('INVALID_ARGUMENT', '--no-encrypt 与 --encrypt 互斥');
|
|
270
|
-
}
|
|
271
|
-
if (input.noEncrypt === true)
|
|
272
|
-
encrypt = 'no';
|
|
273
|
-
else if (input.encrypt !== undefined) {
|
|
277
|
+
if (input.encrypt !== undefined) {
|
|
274
278
|
if (!['yes', 'no', 'auto'].includes(input.encrypt)) {
|
|
275
279
|
return fail('INVALID_ARGUMENT', `--encrypt 只接受 yes|no|auto,收到 ${input.encrypt}`);
|
|
276
280
|
}
|