evolcore 0.0.41-test.0 → 0.0.41-test.1

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.
Files changed (177) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/dist/agents/baseagent-availability.js +1 -1
  3. package/dist/agents/baseagent.js +20 -43
  4. package/dist/agents/claude-runner.js +177 -92
  5. package/dist/agents/codex-runner.js +84 -28
  6. package/dist/agents/ecagent-runner.js +1 -1
  7. package/dist/agents/gemini-runner.js +1 -1
  8. package/dist/aun/group/fs-download.js +39 -0
  9. package/dist/aun/group/identity.js +36 -21
  10. package/dist/aun/group/operations.js +5 -0
  11. package/dist/aun/msg/managed-operation.js +68 -7
  12. package/dist/aun/msg/p2p.js +5 -0
  13. package/dist/aun/service-proxy.js +36 -12
  14. package/dist/channels/aun.js +334 -20
  15. package/dist/channels/daemon.js +15 -1
  16. package/dist/cli/aun-commands.js +4 -20
  17. package/dist/cli/daemon-commands.js +678 -697
  18. package/dist/cli/fs-command.js +64 -2
  19. package/dist/cli/index.js +48 -4
  20. package/dist/cli/managed-command-guard.js +4 -0
  21. package/dist/cli/model.js +40 -40
  22. package/dist/cli/proxy-command.js +92 -0
  23. package/dist/cli/role.js +85 -0
  24. package/dist/config/access-policy.js +7 -2
  25. package/dist/config/boot-log.js +38 -1
  26. package/dist/config/config-field-policy.js +5 -32
  27. package/dist/config/config-manager.js +46 -39
  28. package/dist/config/config-operation-service.js +5 -19
  29. package/dist/config/contact-book-store.js +47 -21
  30. package/dist/config/contact-book.js +18 -12
  31. package/dist/config/contact-operation-service.js +3 -4
  32. package/dist/config/contact-request-service.js +11 -0
  33. package/dist/config/daemon-services.js +11 -0
  34. package/dist/config/gateway-config.js +88 -594
  35. package/dist/config/peer-role-resolver.js +13 -11
  36. package/dist/config/providers-config.js +12 -7
  37. package/dist/config/providers-import.js +3 -21
  38. package/dist/config/resolved-config-op.js +3 -0
  39. package/dist/config/role-command-service.js +166 -0
  40. package/dist/config/role-request-service.js +193 -0
  41. package/dist/config/schema-migration.js +686 -25
  42. package/dist/config-store.js +79 -3
  43. package/dist/contracts/ecweb-instance.js +41 -0
  44. package/dist/contracts/ecweb-service-protocol.js +3 -1
  45. package/dist/core/agent-runtime.js +1 -1
  46. package/dist/core/auth/agent-delegation.js +2 -1
  47. package/dist/core/auth/auth-gateway.js +1 -1
  48. package/dist/core/auth/authorization-audit.js +17 -6
  49. package/dist/core/auth/delegation-authorization.js +3 -1
  50. package/dist/core/auth/operation-authorizer.js +15 -0
  51. package/dist/core/auth/operation-catalog.js +31 -6
  52. package/dist/core/command/agent-control.js +3 -7
  53. package/dist/core/command/agent-storage-menu.js +5 -3
  54. package/dist/core/command/cli-intent-parser.js +2 -1
  55. package/dist/core/command/command-handler.js +48 -99
  56. package/dist/core/command/connect-menu.js +11 -3
  57. package/dist/core/command/data-root-resolver.js +5 -4
  58. package/dist/core/command/memory-slash.js +16 -8
  59. package/dist/core/command/menu-catalog.js +5 -6
  60. package/dist/core/command/menu-handler.js +49 -62
  61. package/dist/core/command/role-menu.js +147 -30
  62. package/dist/core/command/slash-handler.js +123 -254
  63. package/dist/core/daemon-control.js +8 -14
  64. package/dist/core/evolagent-registry.js +4 -4
  65. package/dist/core/evolagent.js +2 -2
  66. package/dist/core/inference/text-inference.js +31 -40
  67. package/dist/core/ipc-registration.js +6 -2
  68. package/dist/core/memory/consolidation-context.js +51 -5
  69. package/dist/core/memory/consolidation-ops-records.js +1 -1
  70. package/dist/core/memory/consolidation-trigger.js +189 -189
  71. package/dist/core/memory/consolidation.js +316 -29
  72. package/dist/core/memory/forget-log.js +96 -0
  73. package/dist/core/memory/index-manager.js +27 -5
  74. package/dist/core/memory/memory-admin.js +45 -5
  75. package/dist/core/memory/memory-writer.js +163 -18
  76. package/dist/core/memory/relation-idle-monitor.js +119 -58
  77. package/dist/core/memory/relation-sweep.js +44 -39
  78. package/dist/core/message/aun-ipc-sender.js +8 -2
  79. package/dist/core/message/im-renderer.js +7 -4
  80. package/dist/core/message/message-admission.js +89 -4
  81. package/dist/core/message/message-bridge.js +31 -18
  82. package/dist/core/message/response-engine.js +77 -8
  83. package/dist/core/model/catalog-service.js +4 -2
  84. package/dist/core/model/config-scope.js +24 -64
  85. package/dist/core/model/field-scope.js +1 -1
  86. package/dist/core/model/model-catalog.js +30 -41
  87. package/dist/core/model/model-diagnostics.js +4 -3
  88. package/dist/core/model/model-fallback.js +10 -7
  89. package/dist/core/model/model-permission.js +3 -2
  90. package/dist/core/ownership/owner-resolver.js +23 -21
  91. package/dist/core/permission/ec-command-parser.js +30 -2
  92. package/dist/core/permission/sandbox-runtime.js +18 -1
  93. package/dist/core/permission/tool-policy.js +14 -3
  94. package/dist/core/relation/peer-identity.js +64 -1
  95. package/dist/core/role/runtime-policy.js +72 -13
  96. package/dist/core/session/session-capsule.js +1 -1
  97. package/dist/core/session/session-idle-monitor.js +1 -1
  98. package/dist/core/session/session-manager.js +20 -0
  99. package/dist/core/session/session-renew.js +3 -3
  100. package/dist/core/skill/index-generator.js +15 -5
  101. package/dist/core/system-session/memory.js +6 -1
  102. package/dist/core/thread/thread-service.js +19 -6
  103. package/dist/directory/owner-directory-admission.js +95 -0
  104. package/dist/directory/owner-directory-authorization.js +309 -0
  105. package/dist/directory/owner-directory-cache.js +635 -0
  106. package/dist/eck/kit-renderer.js +2 -2
  107. package/dist/ecweb/basic-settings-service.js +33 -40
  108. package/dist/ecweb/message-context-service.js +110 -0
  109. package/dist/index.js +76 -14
  110. package/dist/ipc.js +170 -12
  111. package/dist/paths.js +4 -0
  112. package/dist/proxy/command.js +122 -0
  113. package/dist/proxy/ipc-service.js +68 -0
  114. package/dist/proxy/manager.js +485 -0
  115. package/dist/proxy/service-supervisor.js +603 -0
  116. package/dist/response-system/engines/v1/proactive-flow.js +16 -6
  117. package/dist/utils/cross-platform.js +14 -0
  118. package/dist/utils/ecweb-supervisor.js +258 -83
  119. package/dist/utils/error-utils.js +2 -2
  120. package/dist/utils/logger.js +24 -5
  121. package/dist/utils/package-version-info.js +4 -2
  122. package/kits/docs/channels/aun.md +9 -0
  123. package/kits/docs/evolcore/agent.md +1 -1
  124. package/kits/docs/evolcore/config.md +17 -6
  125. package/kits/docs/evolcore/contact.md +3 -0
  126. package/kits/docs/evolcore/fs.md +11 -0
  127. package/kits/docs/evolcore/memory-architecture.md +2 -2
  128. package/kits/docs/evolcore/memory-consolidation.md +32 -8
  129. package/kits/docs/evolcore/memory.md +1 -1
  130. package/kits/docs/evolcore/menu-protocol.md +4 -0
  131. package/kits/docs/evolcore/model.md +23 -20
  132. package/kits/docs/evolcore/msg.md +4 -7
  133. package/kits/migrations/migrate-contact-book-v2.mjs +30 -11
  134. package/kits/schemas/_meta.json +37 -4
  135. package/kits/schemas/agent-config.schema.13.json +8 -3
  136. package/kits/schemas/agent-config.schema.16.json +891 -0
  137. package/kits/schemas/daemon.schema.9.json +366 -0
  138. package/kits/schemas/defaults.schema.5.json +406 -127
  139. package/kits/schemas/relation-config.schema.11.json +260 -0
  140. package/kits/schemas/role-config.schema.1.json +7 -7
  141. package/kits/skills/.switches.json +3 -7
  142. package/kits/skills/ec-service-proxy/SKILL.md +118 -0
  143. package/kits/skills/ec-trigger/SKILL.md +13 -5
  144. package/kits/skills/personal-assistant/SKILL.md +176 -0
  145. package/kits/skills/personal-assistant/references/01-workspace-spec.md +333 -0
  146. package/kits/skills/personal-assistant/references/02-bootstrap.md +205 -0
  147. package/kits/skills/personal-assistant/references/03-data-flow-and-gaps.md +177 -0
  148. package/kits/skills/personal-assistant/references/04-frontend-contract.md +439 -0
  149. package/kits/skills/personal-assistant/references/05-directory-reference.md +292 -0
  150. package/kits/skills/personal-assistant/references/06-render-config.md +350 -0
  151. package/kits/skills/personal-assistant/schema/workspace.schema.json +85 -0
  152. package/kits/skills/personal-assistant/schema/workspace.v1.json +66 -0
  153. package/kits/skills/personal-assistant/scripts/archive.mjs +154 -0
  154. package/kits/skills/personal-assistant/scripts/check.mjs +114 -0
  155. package/kits/skills/personal-assistant/scripts/index-rebuild.mjs +252 -0
  156. package/kits/skills/personal-assistant/scripts/ingest.mjs +344 -0
  157. package/kits/skills/personal-assistant/scripts/init.mjs +270 -0
  158. package/kits/skills/personal-assistant/scripts/lib/apply.mjs +92 -0
  159. package/kits/skills/personal-assistant/scripts/lib/schema.mjs +96 -0
  160. package/kits/skills/personal-assistant/scripts/lib/time.mjs +28 -0
  161. package/kits/skills/personal-assistant/scripts/migrate.mjs +172 -0
  162. package/kits/skills/personal-assistant/scripts/search.mjs +172 -0
  163. package/kits/skills/personal-assistant/scripts/verify.mjs +196 -0
  164. package/kits/skills/personal-assistant/templates/INDEX.md.tpl +24 -0
  165. package/kits/skills/personal-assistant/templates/README.md.tpl +108 -0
  166. package/kits/skills/personal-assistant/triggers/ingest-daily.json +23 -0
  167. package/kits/skills/personal-assistant/triggers/memory-consolidate.json +23 -0
  168. package/kits/skills/personal-assistant/triggers/report-daily.json +23 -0
  169. package/kits/skills/personal-assistant/triggers/report-weekly.json +23 -0
  170. package/kits/templates/memory-consolidation/forget.md +19 -6
  171. package/kits/templates/memory-consolidation/notes.md +1 -1
  172. package/kits/templates/memory-consolidation/profile.md +2 -2
  173. package/kits/templates/memory-consolidation/promote.md +20 -3
  174. package/kits/templates/roles/member.json +8 -1
  175. package/kits/templates/system-fragments/baseagent.md +2 -2
  176. package/kits/templates/system-fragments/memory.md +4 -4
  177. package/package.json +6 -2
@@ -1,7 +1,9 @@
1
1
  import { AccessPolicyError, readAccessPolicy, } from '../../config/access-policy.js';
2
2
  import { getContactSnapshot, isAcceptedContact, resolveContactView, resolvePrincipal, } from '../../config/contact-book.js';
3
3
  import { isValidAid } from '../../aun/aid/validation.js';
4
- import { expirePendingContactRequests } from '../../config/contact-request-service.js';
4
+ import { addContact, expirePendingContactRequests } from '../../config/contact-request-service.js';
5
+ import { readOwnerDirectoryMembership } from '../../directory/owner-directory-admission.js';
6
+ import { readAunPeerKind, resolveAunPeerKind } from '../relation/peer-identity.js';
5
7
  /** Validate managed private AUN sends against the sender's local contact policy. */
6
8
  export async function evaluateOutboundContactAdmission(input) {
7
9
  const selfAid = String(input.selfAid || '').trim();
@@ -34,8 +36,12 @@ export async function evaluateOutboundContactAdmission(input) {
34
36
  const view = resolveContactView(selfAid, targetAid);
35
37
  if (view.isOwner)
36
38
  return { allow: true, status: 'owner' };
37
- if (entry && (entry.status === undefined || entry.status === 'active'))
38
- return { allow: true, status: 'active' };
39
+ if (entry && (entry.status === undefined || entry.status === 'active')) {
40
+ const kind = readAunPeerKind(selfAid, targetAid);
41
+ return kind.kind === 'private' ? { allow: true, status: 'active' }
42
+ : { allow: false, code: 'CONTACT_POLICY_INVALID', status: 'absent',
43
+ error: `Cannot establish private contact type (${kind.reason}): ${targetAid}` };
44
+ }
39
45
  const status = entry?.status ?? 'absent';
40
46
  if (status === 'blocked')
41
47
  return { allow: false, code: 'CONTACT_BLOCKED', status, error: `目标联系人 ${targetAid} 已被拉黑。请先解除拉黑:ec contact unblock ${targetAid} --self ${selfAid}` };
@@ -50,6 +56,58 @@ export async function evaluateOutboundContactAdmission(input) {
50
56
  return { allow: false, code: 'CONTACT_POLICY_INVALID', status: 'absent', error: error instanceof Error ? error.message : String(error) };
51
57
  }
52
58
  }
59
+ /** An explicit managed private send establishes the target as an active contact. */
60
+ export async function ensureOutboundContactForSend(input) {
61
+ const selfAid = String(input.selfAid || '').trim();
62
+ const targetAid = String(input.targetAid || '').trim();
63
+ if (!isValidAid(selfAid) || !isValidAid(targetAid))
64
+ return evaluateOutboundContactAdmission(input);
65
+ input = { ...input, selfAid, targetAid };
66
+ const target = await resolveAunPeerKind(selfAid, targetAid);
67
+ if (target.kind !== 'private') {
68
+ return {
69
+ allow: false, code: 'CONTACT_POLICY_INVALID', status: 'absent',
70
+ error: target.kind === 'group' ? `Target ${targetAid} is a group AID; use group send`
71
+ : `Cannot establish private target type (${target.reason}): ${targetAid}`,
72
+ };
73
+ }
74
+ const admission = await evaluateOutboundContactAdmission(input);
75
+ if (!admission.allow && (admission.code === 'CONTACT_BLOCKED' || admission.code === 'CONTACT_POLICY_INVALID')) {
76
+ return admission;
77
+ }
78
+ try {
79
+ const view = resolveContactView(input.selfAid, input.targetAid);
80
+ if (view.isOwner || (view.source === 'contact' && view.status === 'active'))
81
+ return admission;
82
+ await addContact({
83
+ selfAid: input.selfAid,
84
+ primaryId: input.targetAid,
85
+ actorId: input.actorId,
86
+ });
87
+ return evaluateOutboundContactAdmission(input);
88
+ }
89
+ catch (error) {
90
+ const current = await evaluateOutboundContactAdmission(input);
91
+ if (!current.allow && current.code === 'CONTACT_BLOCKED')
92
+ return current;
93
+ if (current.allow) {
94
+ try {
95
+ const view = resolveContactView(input.selfAid, input.targetAid);
96
+ if (view.isOwner || (view.source === 'contact' && view.status === 'active'))
97
+ return current;
98
+ }
99
+ catch {
100
+ // Return the original mutation error below.
101
+ }
102
+ }
103
+ return {
104
+ allow: false,
105
+ code: 'CONTACT_POLICY_INVALID',
106
+ status: 'absent',
107
+ error: error instanceof Error ? error.message : String(error),
108
+ };
109
+ }
110
+ }
53
111
  export function evaluateInboundAdmissionPreflight(input) {
54
112
  const selfAid = String(input.selfAid || '').trim();
55
113
  const channelType = String(input.channelType || '').trim().toLowerCase();
@@ -122,6 +180,30 @@ export function evaluateInboundAdmissionPreflight(input) {
122
180
  }
123
181
  return { allow: true, context };
124
182
  }
183
+ /** Directory rules also guard control routes; a denied directory sender receives no automatic reply. */
184
+ export function evaluateOwnerDirectoryInboundAdmission(context) {
185
+ if (context.trustedHandoffEcho || context.isOwner || !context.primaryId || !context.policy)
186
+ return undefined;
187
+ const membership = readOwnerDirectoryMembership(context.selfAid, context.primaryId);
188
+ if (!membership)
189
+ return undefined;
190
+ if (membership.agents === 'found') {
191
+ return context.policy.allowOwnerAgentDirectory !== false
192
+ ? { allow: true, reason: 'owner_directory_agent', context }
193
+ : { allow: false, reason: 'owner_agent_directory_disabled', context };
194
+ }
195
+ // Resolve the higher-priority Agent category before admitting a contact.
196
+ if (membership.agents === 'unavailable')
197
+ return { allow: false, reason: 'owner_directory_unavailable', context };
198
+ if (membership.contacts === 'found') {
199
+ return context.policy.allowOwnerDirectoryContacts !== false
200
+ ? { allow: true, reason: 'owner_directory_contact', context }
201
+ : { allow: false, reason: 'owner_directory_contacts_disabled', context };
202
+ }
203
+ if (membership.contacts === 'unavailable')
204
+ return { allow: false, reason: 'owner_directory_unavailable', context };
205
+ return undefined;
206
+ }
125
207
  export function evaluateOrdinaryInboundAdmission(context) {
126
208
  if (context.trustedHandoffEcho)
127
209
  return { allow: true, reason: 'trusted_handoff', context };
@@ -130,6 +212,9 @@ export function evaluateOrdinaryInboundAdmission(context) {
130
212
  return { allow: false, reason: 'invalid_access_policy', context };
131
213
  if (context.isOwner)
132
214
  return { allow: true, reason: 'owner', context };
215
+ const directoryDecision = evaluateOwnerDirectoryInboundAdmission(context);
216
+ if (directoryDecision)
217
+ return directoryDecision;
133
218
  if (context.primaryId && policy.allowedAids?.includes(context.primaryId)) {
134
219
  return { allow: true, reason: 'allowed_aid', context };
135
220
  }
@@ -146,7 +231,7 @@ export function evaluateOrdinaryInboundAdmission(context) {
146
231
  return { allow: true, reason: 'open', context };
147
232
  if (policy.policyMode === 'owners')
148
233
  return { allow: false, reason: 'owners', context };
149
- if (context.primaryId && isAcceptedContact(context.selfAid, context.primaryId)) {
234
+ if (context.primaryId && isAcceptedContact(context.selfAid, context.primaryId, context.channelType === 'aun' && context.chatType === 'private' ? 'private' : undefined)) {
150
235
  return { allow: true, reason: 'contact', context };
151
236
  }
152
237
  return { allow: false, reason: 'contact_required', context };
@@ -19,7 +19,7 @@ import { findContactRequestNote, expirePendingContactRequests, reviewContactRequ
19
19
  import { isValidAid } from '../../aun/aid/validation.js';
20
20
  import { PeerIdentityCache, formatPeerKey } from '../relation/peer-identity.js';
21
21
  import { ownerResolver } from '../ownership/owner-resolver.js';
22
- import { isMainSession, isTopicSession, sessionLocalTopicId } from '../thread/topic-id.js';
22
+ import { isTopicSession, sessionLocalTopicId } from '../thread/topic-id.js';
23
23
  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';
@@ -39,10 +39,11 @@ import { recordCausationSpan } from '../causation/audit.js';
39
39
  import { renderActionAsText } from '../interaction-router.js';
40
40
  import { planApprovalRoute } from '../permission/approval-gateway.js';
41
41
  import { guardGroupSlashCommand, parseFullAccessCommand } from '../command/slash-gate.js';
42
- import { createAgentPolicyAuthorization, createSessionFullAccessAuthorization, hasSessionFullAccessOverride } from '../role/runtime-policy.js';
42
+ import { createAgentPolicyAuthorization, createSessionFullAccessAuthorization } from '../role/runtime-policy.js';
43
43
  import { auditFullAccessEvent } from '../auth/authorization-audit.js';
44
44
  import { DIAGNOSTIC_AGENT_AID, DiagnosticSessionRouter, parseDiagnosticEvent, isDiagnosticSessionActive } from '../command/diag-service.js';
45
- import { consumeAdmissionReplyBudget, clearAdmissionReplyBudgets, evaluateInboundAdmissionPreflight, evaluateOrdinaryInboundAdmission, } from './message-admission.js';
45
+ import { consumeAdmissionReplyBudget, clearAdmissionReplyBudgets, evaluateInboundAdmissionPreflight, evaluateOrdinaryInboundAdmission, evaluateOwnerDirectoryInboundAdmission, } from './message-admission.js';
46
+ import { prepareOwnerDirectoryAdmission } from '../../directory/owner-directory-admission.js';
46
47
  const CONTACT_REJECTION_NOTICE = '[rejection] Not accepting messages from you.';
47
48
  const REJECTABLE_PEER_TYPES = new Set(['ai', 'bot', 'agent', 'service']);
48
49
  const REJECTION_MAX = 3;
@@ -118,16 +119,16 @@ export class MessageBridge {
118
119
  const config = resolveEffective({
119
120
  self: item.selfAid,
120
121
  peerKey: formatPeerKey('aun', item.groupId),
121
- }, { cache: true, expand: true });
122
- const model = config.Services?.decision ? config.Services.decision.model?.trim() : config.decision_model?.model?.trim();
123
- const provider = createDecisionInferenceProvider(config.decision_model, config.Services);
122
+ }, { cache: true });
123
+ const model = config.Services?.decision?.model?.trim();
124
+ const provider = createDecisionInferenceProvider(config.Services);
124
125
  return model && provider ? { model, provider } : undefined;
125
126
  },
126
127
  resolveResources: async (item) => {
127
128
  const config = resolveEffective({
128
129
  self: item.selfAid,
129
130
  peerKey: formatPeerKey('aun', item.groupId),
130
- }, { cache: true, expand: true });
131
+ }, { cache: true });
131
132
  const resources = {};
132
133
  if (config.groupRules?.mode !== 'ignore') {
133
134
  try {
@@ -165,7 +166,7 @@ export class MessageBridge {
165
166
  resolveQuietWindowMs: item => resolveEffective({
166
167
  self: item.selfAid,
167
168
  peerKey: formatPeerKey('aun', item.groupId),
168
- }, { cache: true, expand: true }).autoMentionQuietWindowMs,
169
+ }, { cache: true }).autoMentionQuietWindowMs,
169
170
  resolveMessageState: item => {
170
171
  if (!item.messageId)
171
172
  return 'missing';
@@ -532,6 +533,7 @@ export class MessageBridge {
532
533
  applicantAid: context.primaryId,
533
534
  note: requestMatch[1],
534
535
  sourceChannelKey: context.channelKey,
536
+ routeKind: 'private',
535
537
  });
536
538
  if ((submission.code === 'submitted' || submission.code === 'resubmitted') && submission.requestId) {
537
539
  void this.deliverContactReviewCard(context.selfAid, context.primaryId, submission, owningAgent)
@@ -596,6 +598,7 @@ export class MessageBridge {
596
598
  applicantAid: context.primaryId,
597
599
  note: typeof protocolPayload?.note === 'string' ? protocolPayload.note : undefined,
598
600
  sourceChannelKey: context.channelKey,
601
+ routeKind: 'private',
599
602
  });
600
603
  result = contactRequestSubmissionProtocolResult(submission);
601
604
  if ((submission.code === 'submitted' || submission.code === 'resubmitted') && submission.requestId) {
@@ -953,6 +956,16 @@ export class MessageBridge {
953
956
  actorId,
954
957
  trustedHandoffEcho,
955
958
  });
959
+ if (admissionPreflight.allow && !trustedHandoffEcho && !admissionPreflight.context.isOwner) {
960
+ if (selfAid && admissionPreflight.context.primaryId) {
961
+ await prepareOwnerDirectoryAdmission(selfAid, admissionPreflight.context.primaryId);
962
+ }
963
+ const directoryDecision = evaluateOwnerDirectoryInboundAdmission(admissionPreflight.context);
964
+ if (directoryDecision && !directoryDecision.allow) {
965
+ logger.info(`[MessageBridge] Owner directory admission denied before control routing: self=${selfAid} actor=${actorId ?? '<none>'} reason=${directoryDecision.reason}`);
966
+ return;
967
+ }
968
+ }
956
969
  if (!trustedHandoffEcho && await this.handleContactRequestProtocol({
957
970
  context: admissionPreflight.context,
958
971
  msg,
@@ -1010,8 +1023,11 @@ export class MessageBridge {
1010
1023
  return;
1011
1024
  }
1012
1025
  const admissionDecision = evaluateOrdinaryInboundAdmission(admissionPreflight.context);
1013
- if (!admissionDecision.allow && !isPrivateMenuTokenRequest) {
1014
- if (chatType === 'private') {
1026
+ const directoryDenied = !admissionDecision.allow && (admissionDecision.reason === 'owner_directory_contacts_disabled'
1027
+ || admissionDecision.reason === 'owner_agent_directory_disabled'
1028
+ || admissionDecision.reason === 'owner_directory_unavailable');
1029
+ if (!admissionDecision.allow && (!isPrivateMenuTokenRequest || directoryDenied)) {
1030
+ if (chatType === 'private' && !directoryDenied) {
1015
1031
  if (menuControl.isMenu) {
1016
1032
  if (hasValidMenuId(menuControl)) {
1017
1033
  const header = { id: menuControl.id, ...(menuControl.name?.trim() ? { name: menuControl.name } : {}) };
@@ -1285,7 +1301,7 @@ export class MessageBridge {
1285
1301
  let autoMode = false;
1286
1302
  if (resolvedChannelType === 'aun' && chatType === 'group' && selfAid && msg.source !== 'handoff') {
1287
1303
  try {
1288
- const config = resolveEffective({ self: selfAid, peerKey: formatPeerKey('aun', msg.groupId || msg.channelId) }, { cache: true, expand: true });
1304
+ const config = resolveEffective({ self: selfAid, peerKey: formatPeerKey('aun', msg.groupId || msg.channelId) }, { cache: true });
1289
1305
  autoMode = config.mentionMode === 'auto';
1290
1306
  }
1291
1307
  catch (error) {
@@ -1511,18 +1527,15 @@ export class MessageBridge {
1511
1527
  });
1512
1528
  session = renewResult.session;
1513
1529
  if (!executionPermissionOverride && selfAid && owningAgent?.aid === selfAid) {
1514
- executionPermissionOverride = createSessionFullAccessAuthorization({
1530
+ executionPermissionOverride = createAgentPolicyAuthorization({
1531
+ agentAid: selfAid, actor: roleDetail.actor, chatType,
1532
+ source: msg.source, peerType: msg.peerType,
1533
+ }) ?? createSessionFullAccessAuthorization({
1515
1534
  session,
1516
1535
  actor: roleDetail.actor,
1517
1536
  source: msg.source,
1518
1537
  peerType: msg.peerType,
1519
1538
  });
1520
- if (!executionPermissionOverride && isMainSession(session) && !hasSessionFullAccessOverride(session)) {
1521
- executionPermissionOverride = createAgentPolicyAuthorization({
1522
- agentAid: selfAid, actor: roleDetail.actor, chatType,
1523
- source: msg.source, peerType: msg.peerType,
1524
- });
1525
- }
1526
1539
  }
1527
1540
  if ('renewed' in renewResult && renewResult.renewed) {
1528
1541
  const notice = '已自动切换到新会话';
@@ -653,6 +653,39 @@ function findDiagnosticShellSeparator(value, startOffset, endOffset) {
653
653
  }
654
654
  return -1;
655
655
  }
656
+ function findDiagnosticPatchDocumentEnd(value, startOffset, endOffset) {
657
+ let lineStart = startOffset;
658
+ while (lineStart < endOffset && (value[lineStart] === ' ' || value[lineStart] === '\t'))
659
+ lineStart++;
660
+ const beginEnd = diagnosticLineEnd(value, lineStart);
661
+ if (value.slice(lineStart, beginEnd).replace(/\r$/u, '') !== '*** Begin Patch')
662
+ return undefined;
663
+ let cursor = beginEnd < endOffset ? beginEnd + 1 : endOffset;
664
+ while (cursor < endOffset) {
665
+ const lineEnd = diagnosticLineEnd(value, cursor);
666
+ if (value.slice(cursor, lineEnd).replace(/\r$/u, '') === '*** End Patch')
667
+ return lineEnd;
668
+ if (lineEnd >= endOffset)
669
+ break;
670
+ cursor = lineEnd + 1;
671
+ }
672
+ return undefined;
673
+ }
674
+ function findDiagnosticTrailingCommand(value, startOffset, endOffset) {
675
+ let cursor = startOffset;
676
+ while (cursor < endOffset) {
677
+ const lineEnd = diagnosticLineEnd(value, cursor);
678
+ const line = value.slice(cursor, lineEnd).trim();
679
+ if (line && !line.startsWith('#')) {
680
+ const leadingWhitespace = value.slice(cursor, lineEnd).length - value.slice(cursor, lineEnd).trimStart().length;
681
+ return cursor + leadingWhitespace;
682
+ }
683
+ if (lineEnd >= endOffset)
684
+ break;
685
+ cursor = lineEnd + 1;
686
+ }
687
+ return undefined;
688
+ }
656
689
  function diagnosticLocation(source, startOffset, endOffset = startOffset) {
657
690
  const start = Math.max(0, Math.min(startOffset, source.value.length));
658
691
  const end = Math.max(start, Math.min(endOffset, source.value.length));
@@ -751,9 +784,21 @@ function addApplyPatchCompositionFinding(findings, candidate) {
751
784
  return;
752
785
  const heredocOffset = findUnquotedDiagnosticText(candidate.command, '<<', argumentsOffset);
753
786
  const endOffset = heredocOffset >= 0 ? heredocOffset : candidate.command.length;
754
- const separator = findDiagnosticShellSeparator(candidate.command, argumentsOffset, endOffset);
787
+ let separator = findDiagnosticShellSeparator(candidate.command, argumentsOffset, endOffset);
755
788
  if (separator < 0)
756
789
  return;
790
+ if (candidate.command[separator] === '\n' || candidate.command[separator] === '\r') {
791
+ const newlineLength = candidate.command[separator] === '\r' && candidate.command[separator + 1] === '\n' ? 2 : 1;
792
+ const patchEnd = findDiagnosticPatchDocumentEnd(candidate.command, separator + newlineLength, candidate.command.length);
793
+ if (patchEnd !== undefined) {
794
+ const afterPatch = patchEnd + (candidate.command[patchEnd] === '\r' && candidate.command[patchEnd + 1] === '\n'
795
+ ? 2 : candidate.command[patchEnd] === '\n' ? 1 : 0);
796
+ const trailingCommand = findDiagnosticTrailingCommand(candidate.command, afterPatch, candidate.command.length);
797
+ if (trailingCommand === undefined)
798
+ return;
799
+ separator = trailingCommand;
800
+ }
801
+ }
757
802
  findings.push(diagnosticFinding('apply-patch-composed-command', 'apply_patch 与其它 Shell 命令组合提交', '一次工具调用只提交完整的 apply_patch;测试、检查或其它命令另行调用。', '高', candidate.source, candidate.commandOffset + separator, candidate.commandOffset + separator + 1));
758
803
  }
759
804
  function addNestedShellDiagnosticFinding(findings, candidate) {
@@ -1417,15 +1462,15 @@ export class ResponseEngine {
1417
1462
  const aid = selfAID || (channel ? this.agentRegistry?.resolveByChannel(channel)?.aid : undefined);
1418
1463
  if (!aid)
1419
1464
  return undefined;
1420
- const config = resolveEffective({ self: aid }, { cache: true, expand: true });
1465
+ const config = resolveEffective({ self: aid }, { cache: true });
1421
1466
  return createTextInferenceProvider(baseagent, config);
1422
1467
  }
1423
1468
  getDecisionInferenceProvider(selfAID) {
1424
1469
  const aid = selfAID;
1425
1470
  if (!aid)
1426
1471
  return undefined;
1427
- const config = resolveEffective({ self: aid }, { cache: true, expand: true });
1428
- return createDecisionInferenceProvider(config.decision_model, config.Services);
1472
+ const config = resolveEffective({ self: aid }, { cache: true });
1473
+ return createDecisionInferenceProvider(config.Services);
1429
1474
  }
1430
1475
  getAvailableBaseagentsForOwner(evolName) {
1431
1476
  return loadedBaseagentIds(this.agentMap.keys(), evolName);
@@ -4022,6 +4067,29 @@ export class ResponseEngine {
4022
4067
  return;
4023
4068
  }
4024
4069
  }
4070
+ // ── 模型只在 Agent 级配置:Agent 级没有模型就没有模型可用,不回落 runner/defaults 默认值 ──
4071
+ {
4072
+ const modelBaseagent = normalizeBaseagent(agent.name).canonical;
4073
+ const agentModel = effectiveAgentConfig?.baseagents?.[modelBaseagent]?.model;
4074
+ const triggerModel = message.triggerMeta?.modelOverride;
4075
+ const hasModel = (typeof agentModel === 'string' && agentModel.trim().length > 0)
4076
+ || (typeof triggerModel === 'string' && triggerModel.trim().length > 0);
4077
+ if (modelBaseagent !== 'unknown' && !hasModel) {
4078
+ logger.warn(`[ResponseEngine] No Agent-level model configured: agent=${selfAid ?? session.selfAID ?? '<none>'} baseagent=${modelBaseagent} session=${session.id}`);
4079
+ this.touchAgentActivity(channelKey);
4080
+ adapter.send(envelope, {
4081
+ kind: 'system.error',
4082
+ text: isHostChinese()
4083
+ ? `⚠️ 当前 Agent 未配置模型(baseagents.${modelBaseagent}.model),无法回复。请 Agent 的 owner/admin 使用 /model 设置模型。`
4084
+ : `⚠️ This Agent has no model configured (baseagents.${modelBaseagent}.model) and cannot reply. An Agent owner/admin must set one with /model.`,
4085
+ subtype: 'model_not_configured',
4086
+ recoverable: false,
4087
+ }).catch(() => { });
4088
+ adapter.send(envelope, { kind: 'status.completed', metadata: { durationMs: 0 } }).catch(() => { });
4089
+ this.publishTriggerExecutionFailure(message, 'model_not_configured');
4090
+ return;
4091
+ }
4092
+ }
4025
4093
  const imageInfo = message.images && message.images.length > 0 ? ` [${message.images.length} image(s)]` : '';
4026
4094
  const modeInfo = isBackground ? ' [\u540e\u53f0]' : '';
4027
4095
  const e2eeInfo = message.replyContext?.metadata?.encrypted != null ? ` encrypt=${message.replyContext.metadata.encrypted}` : '';
@@ -4732,8 +4800,8 @@ export class ResponseEngine {
4732
4800
  fullAccessMessagePromptContext = fullAccessAuthorization
4733
4801
  ? FULL_ACCESS_MESSAGE_PROMPT_CONTEXT
4734
4802
  : undefined;
4735
- // 按 关系级 > agent级 > 全局 解析本次调用的模型/强度,作为 per-call 入参传入 runQuery。
4736
- // 不缓存、不绑会话——改关系级/agent级后该范围所有会话的下条消息即时生效;
4803
+ // 模型/强度只取 Agent 级配置(再经角色约束),作为 per-call 入参传入 runQuery。
4804
+ // 不缓存、不绑会话——改 Agent 级后该 Agent 所有会话的下条消息即时生效;
4737
4805
  // 多对端并发各自独立解析、各自传参,无共享状态可被污染。
4738
4806
  let effectiveModel;
4739
4807
  let effectiveModelSource;
@@ -4970,7 +5038,7 @@ export class ResponseEngine {
4970
5038
  }
4971
5039
  };
4972
5040
  // 预压缩必须使用与本轮 runQuery 相同的有效模型/强度覆盖。
4973
- // 模型解析完成后再执行,避免关系级模型存在时回落到 runner 默认模型。
5041
+ // 模型解析完成后再执行,避免回落到 runner 默认模型。
4974
5042
  await this.runPendingAutoCompactAtTaskStart(session, agent, absoluteProjectPath, renderer, modelOverride, () => this.assertCurrentExecutionAuthorization(permissionContext, agent));
4975
5043
  startTime = Date.now();
4976
5044
  const causationPath = inputCausation.trigger?.path ?? [];
@@ -5061,7 +5129,8 @@ export class ResponseEngine {
5061
5129
  isBootstrapping,
5062
5130
  hasPersona: !!persona,
5063
5131
  peerId: peerIdRaw || undefined,
5064
- peerKey,
5132
+ // 与任务上下文同源:系统会话取目标关系,否则 peer-profile / relation 索引会按 bg: 伪对端注入
5133
+ peerKey: systemSessionContext?.peerKey ?? peerKey,
5065
5134
  peerName: peerName || undefined,
5066
5135
  // 系统会话与角色体系无关:不给 peerRole,消息头就不渲染 `· role:` 段
5067
5136
  peerRole: systemSessionMarker ? undefined : peerRole,
@@ -104,7 +104,7 @@ export function parseModelList(json, _url) {
104
104
  }
105
105
  const BUILTIN_IDS = {
106
106
  codex: ['gpt-5.5', 'gpt-5.4', 'gpt-5.4-mini', 'gpt-5.3-codex', 'gpt-5.2'],
107
- claude: ['claude-opus-5', 'claude-sonnet-5', 'claude-opus-4-8', 'claude-opus-4-7', 'claude-opus-4-6', 'claude-sonnet-4-6', 'claude-haiku-4-5-20251001', 'deepseek-v4-pro', 'deepseek-v4-flash', 'kimi-k2.6', 'kimi-k2.5', 'glm-5.1', 'glm-5', 'glm-4.7', 'MiniMax-M2.7'],
107
+ claude: ['claude-opus-5-5', 'claude-sonnet-5-5', 'claude-haiku-5-5', 'claude-opus-5', 'claude-sonnet-5', 'claude-opus-4-8', 'claude-opus-4-7', 'claude-opus-4-6', 'claude-sonnet-4-6', 'claude-haiku-4-5-20251001', 'claude-fable-5', 'claude-fable-5-1', 'deepseek-v4.1-flash', 'deepseek-v4-pro', 'deepseek-v4-flash', 'kimi-k3', 'glm-5.3', 'glm-5.3-flash', 'glm-5.3-flashx', 'glm-5.2'],
108
108
  ecagent: ['claude-sonnet-4-6'],
109
109
  gemini: ['gemini-2.5-pro', 'gemini-2.5-flash', 'gemini-2.5-flash-lite'],
110
110
  };
@@ -359,7 +359,9 @@ export class ModelCatalogService {
359
359
  diagnostics.push({ code: auth ? 'AUTH_FAILED' : 'GATEWAY_UNAVAILABLE', message: auth ? '当前模型网关鉴权失败' : '当前模型网关不可用或响应格式不支持', ...(status ? { status } : {}) });
360
360
  if (previous?.source === 'gateway')
361
361
  return { ...previous, freshness: 'stale', diagnostics: [...diagnostics, { code: 'STALE_CACHE', message: '使用同一连接的最近成功目录' }] };
362
- if (auth)
362
+ // 有显式 provider 时,鉴权失败返回空网关目录(提示是凭据问题);环境变量
363
+ // 兜底(无 providerId)则继续往下回落内置清单,避免兜底变成空列表。
364
+ if (auth && context.providerId)
363
365
  return this.make(context, 'gateway', 'fallback', [], diagnostics);
364
366
  }
365
367
  }
@@ -1,17 +1,16 @@
1
1
  /**
2
- * config-scope: model/effort 的多作用域读写,以及角色 permissionMode 解析。
2
+ * config-scope: model/effort 的读写,以及角色 permissionMode 解析。
3
3
  *
4
4
  * 所有参数统一在 config.json。
5
5
  * 存储经 ConfigManager(全项目唯一合并实现点)。本模块是面向 CLI / 运行时的薄封装:
6
6
  * 把"作用域 + baseagent"语义映射到 config 链的读写。
7
7
  *
8
- * model/effort 作用域(越具体越优先):关系 > 角色 > agent。
8
+ * model/effort 只在 Agent 级配置:
9
9
  * agent agents/<self>/config.json → baseagents.<ba>.{model,effort}
10
- * 角色 agents/<self>/config.json 的 roles.definitions 块 → model 白名单/默认值
11
- * 关系 agents/<self>/relations/<peerKey>/config.json → baseagents
12
- * global(历史保留):全局 model 作用域已退场,只读 agent 兜底。
10
+ * 角色 角色策略 → 只约束 Agent 级模型(白名单/固定模型),不提供模型
11
+ * 关系级与 defaults 都不承载模型参数;Agent 级未设置模型即无模型可用。
13
12
  *
14
- * 改任一作用域后,对应范围所有会话的下一条消息即时生效(运行时每条消息解析,不缓存)。
13
+ * 改 Agent 级后,该 Agent 所有会话的下一条消息即时生效(运行时每条消息解析,不缓存)。
15
14
  *
16
15
  * 详见 docs/config/
17
16
  */
@@ -82,60 +81,30 @@ export function activeBaseagent(self) {
82
81
  catch { /* fall through */ }
83
82
  return 'claude';
84
83
  }
85
- /** 所有 baseagent 统一使用 effort 表达推理强度。 */
86
- function effortField(_ba) {
87
- return 'effort';
88
- }
89
- // ── 写:单作用域 ──────────────────────────────────────────────────────
90
- /** 写入指定作用域。patch 中 undefined 不动;显式 null 删除字段。 */
91
- export function writeScope(scope, sel, ba, patch) {
92
- const ef = effortField(ba);
93
- if (scope === 'global') {
94
- throw new ModelScopeError('NO_GLOBAL_SCOPE', '全局 model 作用域已退场:请用 --self 逐 agent 设置');
95
- }
96
- if (scope === 'agent') {
97
- requireSelf(sel);
98
- const target = ConfigTarget.Agent;
99
- const cur = read(target, { self: sel.self }) || {};
100
- applyBaPatch(cur, ba, ef, patch);
101
- ensureFile(target, { self: sel.self });
102
- write(target, cur, { self: sel.self });
103
- return;
104
- }
105
- if (scope === 'role') {
106
- throw new ModelScopeError('ROLE_POLICY_MANAGED', '角色模型策略只能通过角色策略编辑器修改');
107
- }
108
- // relation
109
- requirePeer(sel);
110
- const target = ConfigTarget.Relation;
111
- const selr = { self: sel.self, peerKey: sel.peerKey };
112
- const cur = read(target, selr) || {};
113
- applyBaPatch(cur, ba, ef, patch);
114
- ensureFile(target, selr);
115
- write(target, cur, selr);
116
- }
117
- function applyBaPatch(cfg, ba, ef, patch) {
118
- cfg.baseagents = cfg.baseagents || {};
119
- applyBaPatchTo(cfg.baseagents, ba, ef, patch);
120
- }
121
- function applyBaPatchTo(block, ba, ef, patch) {
122
- block[ba] = block[ba] || {};
123
- const sub = block[ba];
84
+ // ── 写:Agent 级 ──────────────────────────────────────────────────────
85
+ /** 写入 Agent 级 baseagents.<ba>.{model,effort}。patch 中 undefined 不动;显式 null 删除字段。 */
86
+ export function writeAgentModelConfig(self, ba, patch) {
87
+ if (!self)
88
+ throw new ModelScopeError('AGENT_NOT_FOUND', '模型参数只能在 Agent 级设置,需要 --self');
89
+ const target = ConfigTarget.Agent;
90
+ const cur = read(target, { self }) || {};
91
+ const baseagents = (cur.baseagents || {});
92
+ const block = { ...(baseagents[ba] || {}) };
124
93
  if (patch.model === null)
125
- delete sub.model;
94
+ delete block.model;
126
95
  else if (patch.model !== undefined)
127
- sub.model = patch.model;
96
+ block.model = patch.model;
128
97
  if (patch.effort === null)
129
- delete sub[ef];
98
+ delete block.effort;
130
99
  else if (patch.effort !== undefined)
131
- sub[ef] = patch.effort;
100
+ block.effort = patch.effort;
101
+ cur.baseagents = { ...baseagents, [ba]: block };
102
+ ensureFile(target, { self });
103
+ write(target, cur, { self });
132
104
  }
133
- // ── 清除:单作用域 ────────────────────────────────────────────────────
134
- /** 清除指定作用域的 model+effort。 */
135
- export function clearScope(scope, sel, ba) {
136
- if (scope === 'global')
137
- return;
138
- writeScope(scope, sel, ba, { model: null, effort: null });
105
+ /** 清除 Agent 级 model+effort。清除后该 Agent 没有模型可用,直到重新设置。 */
106
+ export function clearAgentModelConfig(self, ba) {
107
+ writeAgentModelConfig(self, ba, { model: null, effort: null });
139
108
  }
140
109
  // ── permissionMode 解析 ────────────────────────────────────────────────────
141
110
  const FALLBACK_PERMISSION_MODE = 'readonly';
@@ -151,12 +120,3 @@ export function resolvePermissionMode(sel) {
151
120
  return FALLBACK_PERMISSION_MODE;
152
121
  }
153
122
  }
154
- // ── helpers ──────────────────────────────────────────────────────────────────
155
- function requireSelf(sel) {
156
- if (!sel.self)
157
- throw new ModelScopeError('AGENT_NOT_FOUND', 'agent 作用域需要 --self');
158
- }
159
- function requirePeer(sel) {
160
- if (!sel.self || !sel.peerKey)
161
- throw new ModelScopeError('PEER_WITHOUT_SELF', '关系作用域需要 --self + --peer');
162
- }
@@ -2,7 +2,7 @@
2
2
  * field-scope: 顶层配置字段的多作用域读写(通用框架)。
3
3
  *
4
4
  * 与 config-scope.ts(model 专用,处理 baseagents/roles 嵌套结构)互补:
5
- * - config-scope:model/effort → config.json / relation config.json 的嵌套结构
5
+ * - config-scope:model/effort → Agent 级 config.json 的 baseagents 嵌套结构(只此一级)
6
6
  * - field-scope:顶层字段(如 responseMode / responseModeParams)→ config.json(H 链)
7
7
  *
8
8
  * 复用 config-scope 的作用域判定与 peer 归一化(同一套语义,不重复造)。