evolcore 0.0.43-test.2 → 0.0.43-test.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/CHANGELOG.md +44 -1
  2. package/bin/ecmsg.js +229 -0
  3. package/bin/install-codex-managed-hooks.mjs +130 -8
  4. package/dist/ability/application-service.js +37 -0
  5. package/dist/ability/resources.js +28 -0
  6. package/dist/ability/runtime.js +6 -1
  7. package/dist/agents/claude-runner.js +7 -5
  8. package/dist/agents/codex/app-server-client.js +0 -12
  9. package/dist/agents/codex-runner.js +0 -37
  10. package/dist/agents/ecagent-runner.js +138 -36
  11. package/dist/aun/aid/agentmd.js +52 -13
  12. package/dist/aun/menu/client.js +8 -7
  13. package/dist/aun/menu/index.js +1 -1
  14. package/dist/aun/menu/transport.js +8 -5
  15. package/dist/aun/msg/p2p.js +4 -2
  16. package/dist/aun/service-proxy.js +3 -0
  17. package/dist/channels/aun.js +105 -53
  18. package/dist/channels/daemon.js +14 -2
  19. package/dist/cli/agent-command.js +5 -0
  20. package/dist/cli/agent-create.js +31 -11
  21. package/dist/cli/agent.js +9 -3
  22. package/dist/cli/aun-commands.js +19 -21
  23. package/dist/cli/daemon-commands.js +30 -18
  24. package/dist/cli/directory.js +98 -56
  25. package/dist/cli/getmeta-command.js +2 -1
  26. package/dist/cli/index.js +1 -1
  27. package/dist/cli/init.js +13 -5
  28. package/dist/cli/peer.js +2 -1
  29. package/dist/cli/task-context.js +3 -1
  30. package/dist/cli/trigger-command.js +20 -14
  31. package/dist/config/access-policy.js +0 -1
  32. package/dist/config/boot-log.js +12 -2
  33. package/dist/config/builtin-role-templates.js +2 -2
  34. package/dist/config/builtin-roles.js +2 -1
  35. package/dist/config/config-field-policy.js +7 -0
  36. package/dist/config/config-manager.js +30 -10
  37. package/dist/config/peer-role-resolver.js +23 -1
  38. package/dist/config/role-schema.js +25 -1
  39. package/dist/config/role-service.js +9 -4
  40. package/dist/config/role-store.js +30 -8
  41. package/dist/config/schema-migration.js +121 -0
  42. package/dist/core/agent-application-service.js +11 -0
  43. package/dist/core/agent-ipc-registration.js +2 -0
  44. package/dist/core/agent-runtime.js +41 -9
  45. package/dist/core/auth/auth-gateway.js +14 -4
  46. package/dist/core/auth/operation-authorizer.js +19 -1
  47. package/dist/core/auth/operation-catalog.js +12 -2
  48. package/dist/core/baseagent-loader.js +11 -3
  49. package/dist/core/bootstrap-service.js +8 -0
  50. package/dist/core/channel-loader.js +61 -23
  51. package/dist/core/channel-runtime.js +5 -0
  52. package/dist/core/command/agent-control.js +5 -2
  53. package/dist/core/command/agentmd-menu-request.js +50 -0
  54. package/dist/core/command/agentmd-menu.js +156 -0
  55. package/dist/core/command/chatmode-config.js +46 -0
  56. package/dist/core/command/command-handler.js +44 -17
  57. package/dist/core/command/daemon-diagnostics.js +2 -1
  58. package/dist/core/command/menu-catalog.js +14 -1
  59. package/dist/core/command/menu-handler.js +74 -24
  60. package/dist/core/command/menu-protocol.js +8 -0
  61. package/dist/core/command/role-menu.js +23 -9
  62. package/dist/core/command/slash-handler.js +52 -47
  63. package/dist/core/daemon-lifecycle.js +43 -17
  64. package/dist/core/event-catalog.js +19 -0
  65. package/dist/core/evolagent-registry.js +3 -0
  66. package/dist/core/evolagent.js +5 -4
  67. package/dist/core/ipc-registration.js +6 -0
  68. package/dist/core/lifecycle-notice.js +185 -0
  69. package/dist/core/message/aun-ipc-sender.js +30 -24
  70. package/dist/core/message/contact-admission.js +1 -19
  71. package/dist/core/message/im-renderer.js +81 -40
  72. package/dist/core/message/message-admission.js +21 -62
  73. package/dist/core/message/message-bridge.js +18 -5
  74. package/dist/core/message/message-utils.js +9 -0
  75. package/dist/core/message/peer-mode.js +16 -8
  76. package/dist/core/message/response-engine.js +67 -47
  77. package/dist/core/model/model-capabilities.js +37 -0
  78. package/dist/core/model/model-catalog.js +6 -2
  79. package/dist/core/ownership/owner-resolver.js +74 -36
  80. package/dist/core/permission/ec-command-parser.js +62 -13
  81. package/dist/core/plugin-lifecycle.js +6 -2
  82. package/dist/core/relation/pa-team.js +132 -0
  83. package/dist/core/role/runtime-policy.js +4 -3
  84. package/dist/core/thread/thread-service.js +6 -4
  85. package/dist/directory/owner-directory-admission.js +0 -3
  86. package/dist/directory/owner-directory-cache.js +201 -17
  87. package/dist/directory/owner-directory-markdown.js +44 -21
  88. package/dist/directory/owner-directory-policy.js +1 -1
  89. package/dist/directory/owner-directory-query-operation.js +218 -98
  90. package/dist/directory/owner-directory-request-operation.js +76 -0
  91. package/dist/directory/owner-directory-scope.js +35 -4
  92. package/dist/directory/owner-directory-search.js +76 -23
  93. package/dist/directory/owner-directory-store.js +5 -38
  94. package/dist/directory/owner-directory-text.js +60 -0
  95. package/dist/eck/kit-renderer.js +6 -3
  96. package/dist/eck/message-renderer.js +2 -5
  97. package/dist/ecweb/message-context-service.js +4 -0
  98. package/dist/ecweb/runtime/lifecycle.js +29 -5
  99. package/dist/ecweb/runtime/supervisor.js +83 -27
  100. package/dist/index.js +209 -38
  101. package/dist/paths.js +4 -2
  102. package/dist/product.js +1 -0
  103. package/dist/proxy/service-supervisor.js +377 -141
  104. package/dist/response-system/engines/v1/index.js +2 -4
  105. package/dist/response-system/modes/single-session/index.js +1 -1
  106. package/dist/trigger/audit.js +3 -2
  107. package/dist/trigger/authorization.js +2 -3
  108. package/dist/trigger/history.js +4 -3
  109. package/dist/trigger/ipc-service.js +24 -19
  110. package/dist/trigger/manager.js +3 -5
  111. package/dist/trigger/parser.js +4 -21
  112. package/dist/trigger/patch.js +3 -15
  113. package/dist/trigger/scheduler.js +53 -13
  114. package/dist/trigger/validation.js +0 -13
  115. package/dist/utils/error-utils.js +15 -5
  116. package/dist/utils/macos-autostart.js +31 -0
  117. package/dist/utils/model-prices.jsonl +15 -8
  118. package/dist/utils/process-introspect.js +21 -1
  119. package/dist/utils/startup-trace.js +7 -1
  120. package/dist/utils/windows-autostart.js +1 -0
  121. package/ecagent/README.md +18 -0
  122. package/ecagent/dist/harness/agent-harness.d.ts +2 -0
  123. package/ecagent/dist/harness/agent-harness.js +24 -8
  124. package/ecagent/dist/harness/compaction/branch-summarization.js +1 -1
  125. package/ecagent/dist/harness/compaction/compaction.js +7 -4
  126. package/ecagent/dist/harness/types.d.ts +1 -0
  127. package/kits/docs/channels/aun.md +1 -1
  128. package/kits/docs/context-assembly.md +1 -1
  129. package/kits/docs/evolcore/INDEX.md +5 -2
  130. package/kits/docs/evolcore/directory.md +125 -35
  131. package/kits/docs/evolcore/ecweb-lifecycle.md +26 -0
  132. package/kits/docs/evolcore/file-navigation.md +279 -0
  133. package/kits/docs/evolcore/menu-protocol.md +1 -0
  134. package/kits/docs/evolcore/model.md +5 -3
  135. package/kits/docs/evolcore/msg.md +1 -0
  136. package/kits/docs/evolcore/peer.md +2 -1
  137. package/kits/docs/evolcore/response.md +4 -2
  138. package/kits/docs/evolcore/task.md +2 -0
  139. package/kits/docs/evolcore/thread-chain.md +1 -1
  140. package/kits/docs/evolcore/tool-authorization.md +4 -1
  141. package/kits/docs/evolcore/trigger.md +10 -7
  142. package/kits/docs/identity/ROLE_DETAIL.md +2 -0
  143. package/kits/eck_manifest.json +6 -23
  144. package/kits/eck_manifest.memory.json +26 -1
  145. package/kits/rules/01-overview.md +42 -44
  146. package/kits/rules/02-navigation.md +44 -53
  147. package/kits/rules/03-identity.md +21 -25
  148. package/kits/rules/04-relation.md +23 -33
  149. package/kits/rules/05-venue.md +24 -25
  150. package/kits/schemas/_meta.json +10 -10
  151. package/kits/schemas/agent-config.schema.19.json +10 -6
  152. package/kits/schemas/relation-config.schema.12.json +2 -2
  153. package/kits/schemas/role-config.schema.2.json +5 -5
  154. package/kits/schemas/role-registry.schema.1.json +3 -2
  155. package/kits/skills/ec-service-proxy/SKILL.md +10 -0
  156. package/kits/skills/ec-trigger/SKILL.md +1 -1
  157. package/kits/templates/soul/00-GUIDE.md +20 -42
  158. package/kits/templates/system-fragments/channel.md +2 -2
  159. package/kits/templates/system-fragments/commands.md +1 -1
  160. package/kits/templates/system-fragments/directory-contacts.md +1 -1
  161. package/kits/templates/system-fragments/identity.md +0 -1
  162. package/kits/templates/system-fragments/personal-assistant.md +2 -17
  163. package/kits/templates/system-fragments/reply.md +7 -0
  164. package/kits/templates/system-fragments/session.md +6 -2
  165. package/package.json +18 -13
  166. package/dist/eck/paactive-context.js +0 -45
  167. package/dist/response-system/engines/v1/paactive-flow.js +0 -18
  168. package/kits/eck_manifest.paactive.json +0 -528
  169. package/kits/eck_message_manifest.paactive.json +0 -233
  170. package/kits/templates/message-fragments/paactive/item.md +0 -3
  171. package/kits/templates/system-fragments/paactive/channel.md +0 -25
  172. package/kits/templates/system-fragments/paactive/reply.md +0 -25
  173. package/kits/templates/system-fragments/paactive/session.md +0 -32
@@ -146,7 +146,7 @@ async function execOneShotCreate(a, peerId, service, subject) {
146
146
  }
147
147
  if (a.chatmode !== undefined && (!a.chatmode || typeof a.chatmode !== 'object' || Array.isArray(a.chatmode)
148
148
  || Object.entries(a.chatmode).some(([key, value]) => !['private', 'group', 'nothuman'].includes(key)
149
- || !['interactive', 'proactive', ...(key === 'private' ? ['paactive'] : [])].includes(value)))) {
149
+ || !(key === 'group' ? ['proactive'] : ['interactive', 'proactive', ...(key === 'private' ? ['paactive'] : [])]).includes(value)))) {
150
150
  return { error: 'chatmode 必须包含有效的 private/group/nothuman 模式', code: 'INVALID_ARGS' };
151
151
  }
152
152
  let avatarUrl;
@@ -785,17 +785,20 @@ export async function execAgentAction(action, args, peerId, eventBus, service, s
785
785
  ?? (Array.isArray(a.owners) ? a.owners[0] : undefined);
786
786
  const rawModel = supplied.model ?? a.model;
787
787
  const rawEffort = supplied.effort ?? a.effort;
788
- for (const [field, value] of [['model', rawModel], ['effort', rawEffort]]) {
788
+ const rawProvider = supplied.provider ?? a.provider;
789
+ for (const [field, value] of [['provider', rawProvider], ['model', rawModel], ['effort', rawEffort]]) {
789
790
  if (value !== undefined && typeof value !== 'string') {
790
791
  return { error: `${field} 必须是字符串`, code: 'INVALID_ARGS' };
791
792
  }
792
793
  }
794
+ const provider = typeof rawProvider === 'string' && rawProvider.trim() ? rawProvider.trim() : undefined;
793
795
  const effort = typeof rawEffort === 'string' && rawEffort.trim() && rawEffort.trim() !== 'auto'
794
796
  ? rawEffort.trim() : undefined;
795
797
  const plan = {
796
798
  aid,
797
799
  project: supplied.project ?? a.project ?? '',
798
800
  baseagent: supplied.baseagent ?? a.baseagent,
801
+ ...(provider ? { provider } : {}),
799
802
  ...(typeof rawModel === 'string' && rawModel.trim() ? { model: rawModel.trim() } : {}),
800
803
  ...(effort ? { effort } : {}),
801
804
  ownerAid,
@@ -0,0 +1,50 @@
1
+ /** Includes value batches containing the AgentMD entry, for replay and E2EE guards. */
2
+ export function containsAgentMdMenuRequest(request) {
3
+ const args = request.args;
4
+ const command = typeof request.cmd === 'string' ? request.cmd.trim().split(/\s+/)[0] : '';
5
+ if (request.name === 'aid' || command === '/aid') {
6
+ return (request.type === 'menu.query' && args?.view === 'agentmd')
7
+ || (request.type === 'menu.action' && request.action === 'agentmd.publish');
8
+ }
9
+ return request.type === 'menu.query' && request.name === 'menu' && args?.view === 'values'
10
+ && Array.isArray(args.items) && args.items.some(item => item?.entryId === 'aid.agentmd');
11
+ }
12
+ /** Shared by the JSON validator and direct Menu execution entry points. */
13
+ export function validateAgentMdMenuRequest(request) {
14
+ const fail = (message) => ({ code: 'INVALID_ARGUMENT', message });
15
+ const args = request.args;
16
+ if (!args || typeof args !== 'object' || Array.isArray(args))
17
+ return fail('agentmd requires args');
18
+ const a = args;
19
+ const query = request.type === 'menu.query' && a.view === 'agentmd';
20
+ const publish = request.type === 'menu.action' && request.action === 'agentmd.publish';
21
+ if (!query && !publish)
22
+ return { code: 'NOT_SUPPORTED', message: 'Unsupported agentmd Menu operation' };
23
+ const allowed = query ? ['aid', 'view', 'protocolVersion', 'scope', 'self']
24
+ : ['aid', 'content', 'expectedEtag', 'expectedRelationVersion', 'protocolVersion', 'scope', 'self'];
25
+ if (Object.keys(a).some(key => !allowed.includes(key)))
26
+ return fail('Unsupported agentmd argument');
27
+ if (a.protocolVersion !== undefined && a.protocolVersion !== 1) {
28
+ return { code: 'SCHEMA_VERSION_UNSUPPORTED', message: 'Only agentmd protocol version 1 is supported' };
29
+ }
30
+ if (a.aid !== undefined && (typeof a.aid !== 'string' || !a.aid.trim()))
31
+ return fail('aid must be a non-empty string');
32
+ if (a.self !== undefined && (typeof a.self !== 'string' || !a.self.trim()))
33
+ return fail('self must be a non-empty string');
34
+ if (a.scope !== undefined && a.scope !== 'agent')
35
+ return fail('agentmd requires Agent scope');
36
+ if (publish) {
37
+ if (typeof a.content !== 'string' || !a.content.trim())
38
+ return fail('content must be non-empty Markdown');
39
+ // Includes a possible SDK tail signature. The payload has a separate 4096-byte limit.
40
+ if (Buffer.byteLength(a.content, 'utf8') > 6144)
41
+ return fail('agent.md document exceeds 6144 bytes');
42
+ if (typeof a.expectedEtag !== 'string' || !a.expectedEtag.trim()
43
+ || a.expectedEtag.length > 512 || /[\r\n]/.test(a.expectedEtag))
44
+ return fail('expectedEtag is required');
45
+ if (!Number.isSafeInteger(a.expectedRelationVersion) || a.expectedRelationVersion < 1) {
46
+ return fail('expectedRelationVersion must be a positive integer');
47
+ }
48
+ }
49
+ return null;
50
+ }
@@ -0,0 +1,156 @@
1
+ import { isDeepStrictEqual } from 'node:util';
2
+ import { validateAgentMdDocument } from '@agentunion/fastaun';
3
+ import { agentmdGet, agentmdUpdate, AGENT_MD_MAX_PAYLOAD_BYTES, AGENT_DESCRIPTION_MAX_LENGTH, } from '../../aun/aid/agentmd.js';
4
+ import { ownerResolver } from '../ownership/owner-resolver.js';
5
+ import { validateAgentMdMenuRequest } from './agentmd-menu-request.js';
6
+ export const AGENT_MD_PROTECTED_FIELDS = [
7
+ 'aid', 'type', 'owner', 'ownership', 'ownership_proof', 'ownership_release', 'entity_cert_fingerprint',
8
+ ];
9
+ function fail(code, message) {
10
+ throw Object.assign(new Error(message), { code });
11
+ }
12
+ function parse(content, aid) {
13
+ try {
14
+ return validateAgentMdDocument(content, { expectedAid: aid, validateOwnership: false });
15
+ }
16
+ catch (error) {
17
+ return fail('INVALID_ARGUMENT', error instanceof Error ? error.message : 'Invalid agent.md document');
18
+ }
19
+ }
20
+ const defaults = {
21
+ refresh: (aid) => ownerResolver.refresh(aid, { force: true, allowTransient: false, source: 'agentmd-menu' }),
22
+ read: (aid) => agentmdGet(aid, { withVerification: true, remoteOnly: true }),
23
+ update: agentmdUpdate,
24
+ };
25
+ /** Only protocol Ownership authorizes this editor; configured Owners and roles cannot grant it. */
26
+ export class AgentMdMenuService {
27
+ deps;
28
+ constructor(deps = defaults) {
29
+ this.deps = deps;
30
+ }
31
+ target(subject, args) {
32
+ const aid = subject.selfAid;
33
+ if (!aid || (args.aid !== undefined && args.aid !== aid) || (args.self !== undefined && args.self !== aid)) {
34
+ fail('FORBIDDEN', 'AgentMD must target the receiving Agent');
35
+ }
36
+ if (subject.channelType !== 'aun' || subject.chatType !== 'private'
37
+ || (subject.menuTransportChatType ?? subject.chatType) !== 'private' || subject.menuEncrypted !== true
38
+ || subject.fromControlChannel || subject.ecwebManagement
39
+ || !subject.principalId || subject.actorId !== subject.principalId || subject.processRole === 'daemon-service') {
40
+ fail('FORBIDDEN', 'AgentMD editing requires an encrypted AUN request from the authenticated Owner');
41
+ }
42
+ return aid;
43
+ }
44
+ /** Cached Menu responses must still require the current protocol Owner. */
45
+ async preflight(subject) {
46
+ await this.authorize(this.target(subject, {}), subject);
47
+ }
48
+ async authorize(aid, subject, relationVersion) {
49
+ let view;
50
+ try {
51
+ view = await this.deps.refresh(aid);
52
+ }
53
+ catch {
54
+ return fail('OWNER_UNAVAILABLE', 'Fresh Ownership consensus is unavailable');
55
+ }
56
+ const c = view.consensus;
57
+ if (view.refreshFailure || view.consensusStatus === 'unavailable' || !c) {
58
+ fail('OWNER_UNAVAILABLE', 'Fresh Ownership consensus is unavailable');
59
+ }
60
+ if (view.consensusStatus !== 'consensus' || c.status !== 'consensus' || c.sub_aid !== aid
61
+ || c.lock !== 'locked' || !Number.isSafeInteger(c.relation_version) || c.relation_version < 1
62
+ || c.owner_aid !== subject.principalId) {
63
+ fail('FORBIDDEN', 'Only the current protocol Owner can edit this AgentMD');
64
+ }
65
+ if (relationVersion !== undefined && c.relation_version !== relationVersion) {
66
+ fail('OWNERSHIP_CONFLICT', 'Ownership changed; reopen the editor');
67
+ }
68
+ return c;
69
+ }
70
+ card(current, aid, consensus) {
71
+ if (current.source !== 'remote' || current.verification.status !== 'verified') {
72
+ fail('AGENTMD_UNVERIFIED', 'A verified remote AgentMD is required');
73
+ }
74
+ const parsed = parse(current.content, aid);
75
+ const fields = parsed.frontmatter;
76
+ if (['human', 'group', 'org', 'host'].includes(String(fields.type).trim().toLowerCase())) {
77
+ fail('NOT_SUPPORTED', 'This editor supports ordinary Agents only');
78
+ }
79
+ if (fields.owner !== consensus.owner_aid)
80
+ fail('OWNERSHIP_CONFLICT', 'AgentMD Owner does not match consensus');
81
+ const etag = current.remoteVersion?.etag;
82
+ if (!etag)
83
+ fail('REMOTE_VERSION_UNAVAILABLE', 'Remote AgentMD has no ETag');
84
+ if (consensus.agent_md_etag !== etag)
85
+ fail('REMOTE_VERSION_CONFLICT', 'AgentMD changed during ownership verification; reload');
86
+ return { ...parsed, etag };
87
+ }
88
+ async query(subject, args) {
89
+ const invalid = validateAgentMdMenuRequest({ type: 'menu.query', args });
90
+ if (invalid)
91
+ fail(invalid.code, invalid.message);
92
+ const aid = this.target(subject, args);
93
+ await this.authorize(aid, subject);
94
+ const current = await this.deps.read(aid);
95
+ const c = await this.authorize(aid, subject);
96
+ const card = this.card(current, aid, c);
97
+ return {
98
+ protocol: 'evol.agentmd', protocolVersion: 1, aid,
99
+ content: card.payload, etag: card.etag, relationVersion: c.relation_version,
100
+ verification: 'verified', protectedFields: AGENT_MD_PROTECTED_FIELDS,
101
+ limits: { maxPayloadBytes: AGENT_MD_MAX_PAYLOAD_BYTES, maxDescriptionCharacters: AGENT_DESCRIPTION_MAX_LENGTH },
102
+ atomicVersionCheck: false,
103
+ };
104
+ }
105
+ async publish(subject, args) {
106
+ const invalid = validateAgentMdMenuRequest({ type: 'menu.action', action: 'agentmd.publish', args });
107
+ if (invalid)
108
+ fail(invalid.code, invalid.message);
109
+ const aid = this.target(subject, args);
110
+ const version = args.expectedRelationVersion;
111
+ await this.authorize(aid, subject, version);
112
+ const candidate = parse(args.content, aid);
113
+ let previousFields = {};
114
+ let result;
115
+ try {
116
+ result = await this.deps.update(aid, async (current) => {
117
+ const consensus = await this.authorize(aid, subject, version);
118
+ const base = this.card(current, aid, consensus);
119
+ if (base.etag !== args.expectedEtag)
120
+ fail('REMOTE_VERSION_CONFLICT', 'AgentMD changed; reload before publishing');
121
+ previousFields = base.frontmatter;
122
+ for (const field of AGENT_MD_PROTECTED_FIELDS) {
123
+ if (Object.hasOwn(base.frontmatter, field) !== Object.hasOwn(candidate.frontmatter, field)
124
+ || !isDeepStrictEqual(base.frontmatter[field], candidate.frontmatter[field])) {
125
+ fail('PROTECTED_FIELD', `AgentMD field ${field} cannot be changed by this editor`);
126
+ }
127
+ }
128
+ return candidate.payload;
129
+ });
130
+ }
131
+ catch (error) {
132
+ // Keep SDK conditional-upload conflicts actionable at the Menu boundary.
133
+ if (String(error?.code ?? '').toLowerCase() === 'conflict') {
134
+ fail('REMOTE_VERSION_CONFLICT', 'AgentMD changed during upload; reload before retrying');
135
+ }
136
+ throw error;
137
+ }
138
+ // SDK acknowledgement is insufficient: confirm the actual remotely verified document.
139
+ const published = await this.deps.read(aid);
140
+ const consensus = await this.authorize(aid, subject, version);
141
+ const accepted = this.card(published, aid, consensus);
142
+ const body = (payload) => payload.replace(/\r\n/g, '\n')
143
+ .replace(/^---\n[\s\S]*?\n---(?:\n|$)/, '').trim();
144
+ if (!isDeepStrictEqual(candidate.frontmatter, accepted.frontmatter) || body(candidate.payload) !== body(accepted.payload)) {
145
+ fail('PUBLISH_NOT_CONFIRMED', 'The remote AgentMD does not confirm this edit; refresh before retrying');
146
+ }
147
+ return {
148
+ protocol: 'evol.agentmd', protocolVersion: 1, aid, published: true,
149
+ content: accepted.payload, etag: accepted.etag, relationVersion: consensus.relation_version,
150
+ verification: 'verified', versionChecked: result.versionChecked, atomicVersionCheck: false,
151
+ nameChanged: previousFields.name !== accepted.frontmatter.name,
152
+ ...(previousFields.avatar !== accepted.frontmatter.avatar ? { avatar: accepted.frontmatter.avatar ?? '' } : {}),
153
+ };
154
+ }
155
+ }
156
+ export const agentMdMenuService = new AgentMdMenuService();
@@ -0,0 +1,46 @@
1
+ import { ConfigError, ConfigTarget, mutateConfig, routeFieldPath, } from '../../config/config-manager.js';
2
+ import { formatPeerKey, parsePeerKey, readAunPeerKind } from '../relation/peer-identity.js';
3
+ /** Both command entry points authorize the operation before calling this writer. */
4
+ export function writeChatmodeConfig(target, value, subject) {
5
+ const route = routeFieldPath(`chatmode.${target.field}`, target.scope);
6
+ mutateConfig(route.target, target.sel, config => {
7
+ if (route.target === ConfigTarget.Relation && value === 'paactive') {
8
+ const denied = () => new ConfigError('NOT_APPLICABLE', 'paactive 仅支持已确认的 AUN 私聊关系');
9
+ if (target.field !== 'private' || !target.sel.self || !target.sel.peerKey)
10
+ throw denied();
11
+ let peer;
12
+ try {
13
+ peer = parsePeerKey(target.sel.peerKey);
14
+ }
15
+ catch {
16
+ throw denied();
17
+ }
18
+ if (peer.channelType !== 'aun')
19
+ throw denied();
20
+ // Request args select a relation, but cannot supply its kind. Only use
21
+ // authenticated routing when it names this exact Agent and conversation.
22
+ let routeKind;
23
+ if (!subject.fromControlChannel && subject.selfAid === target.sel.self
24
+ && subject.channelType === 'aun' && subject.conversationId === peer.channelId
25
+ && (!subject.peerKey || subject.peerKey === formatPeerKey('aun', peer.channelId))) {
26
+ if (subject.chatType === 'group' || subject.menuTransportChatType === 'group') {
27
+ routeKind = 'group';
28
+ }
29
+ else if (subject.chatType === 'private' && subject.actorId === peer.channelId) {
30
+ routeKind = 'private';
31
+ }
32
+ }
33
+ const resolution = readAunPeerKind(target.sel.self, peer.channelId, {
34
+ routeKind, relation: config,
35
+ });
36
+ if (resolution.kind !== 'private')
37
+ throw denied();
38
+ config.targetKind = 'private';
39
+ }
40
+ const block = config.chatmode && typeof config.chatmode === 'object' && !Array.isArray(config.chatmode)
41
+ ? { ...config.chatmode }
42
+ : {};
43
+ block[target.field] = value;
44
+ config.chatmode = block;
45
+ });
46
+ }
@@ -39,6 +39,7 @@ import { auditCommandAuthorization, auditFullAccessEvent, hashArgv } from '../au
39
39
  import { ResponseModeRegistry } from '../../response-system/registry.js';
40
40
  import { registerBuiltinModes } from '../../response-system/modes/index.js';
41
41
  import { DirectoryQueryError, executeDirectoryQueryCommand, resolveDirectoryQueryCommand, } from '../../directory/owner-directory-query-operation.js';
42
+ import { executeDirectoryRequestCommand, resolveDirectoryRequestCommand, } from '../../directory/owner-directory-request-operation.js';
42
43
  import { executeResolvedRoleCommand, resolveRoleCommand } from '../../config/role-command-service.js';
43
44
  import { applyApprovedRoleAssignment } from './role-menu.js';
44
45
  import { executeResolvedPeerCommand, resolvePeerCommand } from '../../config/peer-operation-service.js';
@@ -593,9 +594,7 @@ export class CommandHandler {
593
594
  validateTriggerRuntimeFields(definition, role, baseagent) {
594
595
  if (!role)
595
596
  return undefined;
596
- const executionBaseagent = definition.execution.type === 'trigger_session'
597
- ? definition.execution.baseagent ?? baseagent
598
- : baseagent;
597
+ const executionBaseagent = baseagent;
599
598
  if (definition.execution.model) {
600
599
  const modelDecision = validateModelSelectionForRole({
601
600
  role,
@@ -711,20 +710,14 @@ export class CommandHandler {
711
710
  if (permissionMode === 'fullaccess' && !canApprovePersistentFullAccess) {
712
711
  return { error: '当前认证通道不能批准持久 fullaccess Trigger' };
713
712
  }
714
- if (parsed.baseagent !== undefined) {
715
- if (typeof parsed.baseagent !== 'string' || !parsed.baseagent.trim()) {
716
- return { error: 'Trigger baseagent 不能为空' };
717
- }
718
- if (parsed.executionType !== 'trigger_session') {
719
- return { error: 'Trigger baseagent 仅适用于 trigger_session' };
720
- }
721
- }
713
+ if ('baseagent' in parsed)
714
+ return { error: 'Trigger 不支持覆盖 baseagent;使用所属 Agent 当前基座' };
722
715
  const daemonScheduler = schedulerAid === this.getDaemonTriggerOwnerAid(channel);
723
716
  const triggerOwner = daemonScheduler
724
717
  ? undefined
725
718
  : this.agentRegistry?.get?.(schedulerAid) ?? this.getOwningAgent(channel);
726
719
  const executionBaseagent = parsed.executionType === 'trigger_session'
727
- ? parsed.baseagent?.trim() ?? triggerOwner?.baseagent ?? triggerRole.baseagent
720
+ ? triggerOwner?.baseagent ?? triggerRole.baseagent
728
721
  ?? (daemonScheduler ? this.parseDefaultBaseagent() : undefined)
729
722
  : undefined;
730
723
  if (parsed.executionType === 'trigger_session') {
@@ -760,7 +753,6 @@ export class CommandHandler {
760
753
  ...(script ? { script } : { prompt: parsed.prompt || '' }),
761
754
  ...(parsed.executionType === 'trigger_session' ? {
762
755
  thread: parsed.triggerThread ?? 'by_trigger',
763
- baseagent: executionBaseagent,
764
756
  } : {}),
765
757
  model: parsed.model,
766
758
  timeoutMs: parsed.executionTimeoutMs,
@@ -1519,7 +1511,7 @@ export class CommandHandler {
1519
1511
  /trigger list [--all] — 查看所有触发器
1520
1512
  /trigger create <参数> — 创建触发器(set 为兼容别名)
1521
1513
  /trigger update <名称|ID> <参数> — 修改触发器
1522
- 常用参数:--delay/--at/--cron/--every、--prompt、--description、--model、--effort、--permission(省略则继承;update 可用 inherit 清除覆盖)、--feedback、--target-channel/--target-channel-id、--trigger-thread、--baseagent、--on-error、--retry-attempts/--retry-backoff、--script-runtime/--script-args/--script-timeout
1514
+ 常用参数:--delay/--at/--cron/--every、--prompt、--description、--model、--effort、--permission(省略则继承;update 可用 inherit 清除覆盖)、--feedback、--target-channel/--target-channel-id、--trigger-thread、--on-error、--retry-attempts/--retry-backoff、--script-runtime/--script-args/--script-timeout
1523
1515
  /trigger enable <名称|ID> — 启用触发器
1524
1516
  /trigger disable <名称|ID> — 暂停触发器
1525
1517
  /trigger show <名称|ID> — 查看触发器详情
@@ -2154,7 +2146,7 @@ export class CommandHandler {
2154
2146
  }
2155
2147
  }
2156
2148
  /**
2157
- * `ec directory ...`:只读查询 + 重算注入。
2149
+ * `ec directory ...`:查询、重算注入与向当前 Agent 的 Owner 申请入录。
2158
2150
  *
2159
2151
  * 备注不走命令——它是自己的 agent 目录下的一个 markdown 文件,由 Agent 直接读写。
2160
2152
  * 权限边界:目标 Agent 必须是调用方自身,或者与调用方同属一个 Owner。
@@ -2170,12 +2162,18 @@ export class CommandHandler {
2170
2162
  if (!session)
2171
2163
  return { ok: false, code: 'INVALID_SESSION', error: 'Invalid session' };
2172
2164
  // argv 形如 ['directory', '<sub>', ...]
2173
- const subArgv = argv.slice(1);
2165
+ const rawSubArgv = argv.slice(1);
2174
2166
  const grantSelfAid = delegation.grant.selfAid.replace(/^@/, '');
2175
2167
  const sessionSelfAid = session.selfAID?.replace(/^@/, '');
2176
2168
  if (sessionSelfAid && sessionSelfAid !== grantSelfAid) {
2177
2169
  return { ok: false, code: 'INVALID_DELEGATION', error: 'Delegation self agent does not match the active session' };
2178
2170
  }
2171
+ // `--self` 缺省时回落到委托凭据里的本端 Agent:托管 runner 只注入任务上下文、
2172
+ // 不注入 EVOLCORE_SELF_AID,而调用方本来就只可能查自己(下面还会校验 target
2173
+ // 与凭据一致)。这与 peer / role 的补齐方式保持一致,不构成权限放宽。
2174
+ const subArgv = rawSubArgv.includes('--self')
2175
+ ? rawSubArgv
2176
+ : [...rawSubArgv, '--self', grantSelfAid];
2179
2177
  const selfIndex = subArgv.indexOf('--self');
2180
2178
  const targetAid = selfIndex >= 0 && selfIndex === subArgv.lastIndexOf('--self')
2181
2179
  ? subArgv[selfIndex + 1]
@@ -2190,7 +2188,11 @@ export class CommandHandler {
2190
2188
  catch {
2191
2189
  return { ok: false, code: 'INVALID_DELEGATION', error: 'Delegation contains an invalid relation key' };
2192
2190
  }
2193
- const operation = 'ec.directory.query';
2191
+ const isRequest = subArgv[0] === 'request';
2192
+ if (isRequest && targetAid !== grantSelfAid) {
2193
+ return { ok: false, code: 'SCOPE_MISMATCH', error: '加好友申请只能由当前任务所属 Agent 发起' };
2194
+ }
2195
+ const operation = isRequest ? 'ec.directory.request' : 'ec.directory.query';
2194
2196
  const subject = buildAuthSubject({
2195
2197
  selfAid: grantSelfAid,
2196
2198
  sessionId,
@@ -2219,6 +2221,31 @@ export class CommandHandler {
2219
2221
  messageId: delegation.grant.messageId,
2220
2222
  },
2221
2223
  }, async (onExecutionStarted) => {
2224
+ if (isRequest) {
2225
+ try {
2226
+ const command = resolveDirectoryRequestCommand(subArgv);
2227
+ if (command.selfAid !== grantSelfAid) {
2228
+ return { ok: false, code: 'SCOPE_MISMATCH', error: '加好友申请只能使用当前任务所属 Agent AID' };
2229
+ }
2230
+ onExecutionStarted();
2231
+ const result = await executeDirectoryRequestCommand(command, async (input) => {
2232
+ const channel = [...this.channelObjects.entries()].find(([name]) => this.resolveChannelType(name) === 'aun' && this.resolveSelfAID(name) === command.selfAid)?.[1];
2233
+ if (typeof channel?.sendDaemonMsg !== 'function') {
2234
+ return { ok: false, code: 'AUN_CHANNEL_NOT_FOUND', error: `找不到 ${command.selfAid} 的 AUN 发送渠道` };
2235
+ }
2236
+ const sent = await channel.sendDaemonMsg({
2237
+ to: input.to, payload: input.payload, rawPayload: true, encrypt: true,
2238
+ log: { content: '[friend.invite.v1]', threadId: '', msgType: 'custom', payloadType: 'friend.invite.v1', source: 'msg' },
2239
+ });
2240
+ return { ok: sent.ok, message_id: sent.message_id, error: sent.error, code: sent.code };
2241
+ });
2242
+ return result.ok ? { ok: true, result } : { ok: false, code: result.code, error: result.error };
2243
+ }
2244
+ catch (error) {
2245
+ return { ok: false, code: error instanceof DirectoryQueryError ? error.code : 'FRIEND_INVITE_FAILED',
2246
+ error: error instanceof Error ? error.message : String(error) };
2247
+ }
2248
+ }
2222
2249
  let command;
2223
2250
  try {
2224
2251
  command = resolveDirectoryQueryCommand(subArgv);
@@ -11,7 +11,8 @@ export function parseManagedDaemonLogArgv(argv) {
11
11
  for (let index = 1; index < argv.length; index += 1) {
12
12
  const flag = argv[index];
13
13
  if (flag === '--raw') {
14
- throw { code: 'NOT_ALLOWED', message: '--raw is unavailable in managed tasks; use it from the host terminal' };
14
+ query.raw = true;
15
+ continue;
15
16
  }
16
17
  if (flag === '--no-color')
17
18
  continue;
@@ -100,7 +100,7 @@ const ENTRIES = [
100
100
  },
101
101
  // 模型与推理强度只在 Agent 级配置(见 model.agent / effort.agent),关系菜单不再提供。
102
102
  relation('chatmode.relation', 'chatmode', '对话模式', 30, '/chatmode', 'chatmode.current', { options: { cmd: '/chatmode', operation: 'chatmode.current', scope: 'relation', mode: 'dynamic' }, update: { cmd: '/chatmode', operation: 'chatmode.update', scope: 'relation' }, control: 'select' }),
103
- relation('activity.relation', 'activity', '中间输出', 40, '/activity', 'activity.current', { options: { cmd: '/activity', operation: 'activity.current', scope: 'relation', mode: 'static', items: [{ value: 'all', label: '私聊显示' }, { value: 'text', label: '仅文字进展' }, { value: 'none', label: '全部静默' }] }, update: { cmd: '/activity', operation: 'activity.update', scope: 'relation' }, control: 'select' }),
103
+ relation('activity.relation', 'activity', '中间输出', 40, '/activity', 'activity.current', { options: { cmd: '/activity', operation: 'activity.current', scope: 'relation', mode: 'static', items: [{ value: 'all', label: '全部显示' }, { value: 'text', label: '仅文字进展' }, { value: 'none', label: '全部静默' }] }, update: { cmd: '/activity', operation: 'activity.update', scope: 'relation' }, control: 'select' }),
104
104
  { id: 'task.activities', type: 'list', contexts: ['private_relation', 'group_relation'], name: 'task', label: '任务活动', section: 'relation_behavior', order: 45, query: { cmd: '/task', args: { view: 'activities' }, operation: 'task.activity.read', scope: 'relation', mode: 'dynamic' }, control: 'list' },
105
105
  relation('permissionMode.relation', 'permission', '权限模式', 50, '/perm', 'permission.current', { query: { cmd: '/perm', args: { scope: 'role' }, operation: 'permission.current', scope: 'relation' }, options: undefined, update: { cmd: '/perm', operation: 'permission.current', scope: 'relation', supported: false }, control: 'select' }),
106
106
  relation('mentionMode.relation', 'group', '群消息响应', 60, '/group', 'group.mentionmode.current', { contexts: ['group_relation'], query: { cmd: '/group', args: { view: 'mentionMode', scope: 'relation' }, operation: 'group.mentionmode.current', scope: 'relation' }, options: { cmd: '/group', args: { option: 'mentionMode', scope: 'relation' }, operation: 'group.mentionmode.current', scope: 'relation' }, update: { cmd: '/group', args: { resource: 'mentionMode', scope: 'relation' }, operation: 'group.mentionmode.update', scope: 'relation' }, control: 'select' }),
@@ -114,6 +114,12 @@ const ENTRIES = [
114
114
  { id: 'activity.agent', type: 'setting', contexts: ['agent'], name: 'activity', label: 'Agent 中间输出', section: 'agent', order: 50, query: { cmd: '/activity', args: { scope: 'agent' }, operation: 'activity.current', scope: 'agent' }, options: { cmd: '/activity', args: { scope: 'agent' }, operation: 'activity.current', scope: 'agent' }, update: { cmd: '/activity', args: { scope: 'agent' }, operation: 'activity.update', scope: 'agent' }, control: 'select' },
115
115
  { id: 'observable.agent', type: 'setting', contexts: ['agent'], name: 'observable', label: '观察模式', section: 'agent', order: 60, query: { cmd: '/observable', operation: 'observable.current', scope: 'agent' }, update: { cmd: '/observable', operation: 'observable.update', scope: 'agent' }, valueSchema: { type: 'boolean' }, control: 'toggle' },
116
116
  { id: 'aid.avatar', type: 'action', contexts: ['agent'], name: 'aid', label: '更换头像', section: 'agent', order: 70, action: { cmd: '/aid', action: 'avatar', operation: 'ec.aid.avatar', scope: 'agent' }, valueSchema: { type: 'object', properties: { data: { type: 'string' }, url: { type: 'string', format: 'uri' } }, oneOf: [{ required: ['data'] }, { required: ['url'] }] }, control: 'action' },
117
+ { id: 'aid.agentmd', type: 'setting', contexts: ['agent'], name: 'aid', label: 'AgentMD', section: 'agent', order: 71,
118
+ query: { cmd: '/aid', args: { view: 'agentmd', protocolVersion: 1 }, operation: 'ec.aid.agentmd.get', scope: 'agent' },
119
+ action: { cmd: '/aid', action: 'agentmd.publish', args: { protocolVersion: 1 }, operation: 'ec.aid.agentmd.put', scope: 'agent' },
120
+ valueSchema: { type: 'object', required: ['content', 'expectedEtag', 'expectedRelationVersion'], properties: {
121
+ content: { type: 'string' }, expectedEtag: { type: 'string' }, expectedRelationVersion: { type: 'integer', minimum: 1 },
122
+ } }, control: 'markdown-editor' },
117
123
  { id: 'baseagents.inventory', type: 'list', contexts: ['process'], name: 'baseagents', label: 'Base Agent 清单', section: 'process', order: 9, query: { cmd: '/baseagents', operation: 'system.status', scope: 'process' }, control: 'list' },
118
124
  { id: 'system.status', type: 'list', contexts: ['process'], name: 'system', label: '系统状态', section: 'process', order: 10, query: { cmd: '/system', operation: 'system.status', scope: 'process' }, control: 'list' },
119
125
  { id: 'system.monitor', type: 'list', contexts: ['process'], name: 'system', label: '运行监控快照', section: 'process', order: 11, query: { cmd: '/system', args: { view: 'monitor' }, operation: 'system.status', scope: 'process' }, control: 'list' },
@@ -166,6 +172,7 @@ export async function resolveMenuCatalogContext(input) {
166
172
  }
167
173
  const bound = {
168
174
  ...subject,
175
+ menuTransportChatType: subject.menuTransportChatType ?? subject.chatType,
169
176
  chatType: 'private',
170
177
  conversationId: subject.selfAid,
171
178
  channelId: subject.selfAid,
@@ -389,6 +396,12 @@ async function operationView(binding, context, options = {}) {
389
396
  return undefined;
390
397
  if (binding.supported === false)
391
398
  return { supported: false, allowed: false, reason: { code: 'NOT_SUPPORTED', message: 'operation is not supported' } };
399
+ if (['ec.aid.agentmd.get', 'ec.aid.agentmd.put'].includes(binding.operation)
400
+ && (context.subject.channelType !== 'aun' || context.subject.menuEncrypted !== true
401
+ || (context.subject.menuTransportChatType ?? context.subject.chatType) !== 'private'
402
+ || context.subject.fromControlChannel || context.subject.ecwebManagement)) {
403
+ return { supported: true, allowed: false, reason: { code: 'FORBIDDEN', message: 'AgentMD requires an encrypted AUN private Agent channel' } };
404
+ }
392
405
  if (binding.operation === 'system.paircode' && options.paircodeAllowed === false) {
393
406
  return {
394
407
  supported: true,