evolcore 0.0.42 → 0.0.43-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 (189) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/bin/ec-safe-output.js +4 -1
  3. package/dist/ability/application-service.js +882 -0
  4. package/dist/ability/authorization.js +70 -0
  5. package/dist/ability/command-contract.js +105 -0
  6. package/dist/ability/daemon.js +137 -0
  7. package/dist/ability/development.js +450 -0
  8. package/dist/ability/environment.js +75 -0
  9. package/dist/ability/interop-v1.js +547 -0
  10. package/dist/ability/management.js +79 -0
  11. package/dist/ability/package.js +264 -0
  12. package/dist/ability/provider.js +73 -0
  13. package/dist/ability/publication.js +107 -0
  14. package/dist/ability/resources.js +106 -0
  15. package/dist/ability/runtime.js +212 -0
  16. package/dist/ability/secrets.js +47 -0
  17. package/dist/ability/store.js +112 -0
  18. package/dist/ability/toolchain.js +69 -0
  19. package/dist/ability/types.js +14 -0
  20. package/dist/ability/versions.js +32 -0
  21. package/dist/agents/baseagent.js +2 -2
  22. package/dist/agents/claude-runner.js +4 -0
  23. package/dist/agents/codex-runner.js +81 -17
  24. package/dist/agents/ecagent-plugin-lazy.js +41 -0
  25. package/dist/agents/ecagent-runner.js +18 -11
  26. package/dist/aun/ability-device-routing.js +12 -1
  27. package/dist/aun/aid/agentmd.js +2 -2
  28. package/dist/aun/aid/client.js +1 -1
  29. package/dist/aun/aid/identity.js +45 -0
  30. package/dist/aun/aid/index.js +1 -0
  31. package/dist/aun/aid/managed-operation.js +73 -2
  32. package/dist/channels/aun.js +64 -18
  33. package/dist/channels/builtin-plugins.js +14 -0
  34. package/dist/channels/dingtalk.js +78 -26
  35. package/dist/channels/feishu.js +89 -14
  36. package/dist/channels/qqbot.js +84 -19
  37. package/dist/channels/wechat.js +77 -19
  38. package/dist/channels/wecom.js +67 -22
  39. package/dist/cli/ability-command.js +92 -0
  40. package/dist/cli/aun-commands.js +124 -85
  41. package/dist/cli/daemon-commands.js +37 -85
  42. package/dist/cli/index.js +14 -0
  43. package/dist/cli/init.js +11 -13
  44. package/dist/cli/managed-command-guard.js +6 -0
  45. package/dist/cli/model.js +101 -104
  46. package/dist/cli/provider-command.js +6 -4
  47. package/dist/cli/restart-monitor.js +52 -11
  48. package/dist/cli/upgrade-command.js +102 -0
  49. package/dist/cli/version.js +1 -1
  50. package/dist/config/access-policy.js +4 -2
  51. package/dist/config/builtin-roles.js +1 -0
  52. package/dist/config/config-field-policy.js +4 -0
  53. package/dist/config/config-manager.js +7 -0
  54. package/dist/config/provider-ipc-service.js +10 -0
  55. package/dist/config/providers-config.js +12 -3
  56. package/dist/config/providers-management.js +45 -9
  57. package/dist/config/schema-migration.js +40 -22
  58. package/dist/contracts/ecweb-service-protocol.js +2 -1
  59. package/dist/core/agent-runtime.js +2 -1
  60. package/dist/core/auth/agent-delegation.js +21 -5
  61. package/dist/core/auth/auth-gateway.js +31 -9
  62. package/dist/core/auth/authorization-audit.js +52 -4
  63. package/dist/core/auth/delegation-authorization.js +140 -4
  64. package/dist/core/auth/operation-authorizer.js +114 -13
  65. package/dist/core/auth/operation-catalog.js +118 -4
  66. package/dist/core/baseagent-loader.js +14 -1
  67. package/dist/core/channel-loader.js +47 -9
  68. package/dist/core/channel-runtime.js +1 -1
  69. package/dist/core/command/agent-storage-menu.js +1 -1
  70. package/dist/core/command/cli-intent-parser.js +26 -13
  71. package/dist/core/command/command-handler.js +232 -76
  72. package/dist/core/command/connect-menu.js +10 -4
  73. package/dist/core/command/daemon-diagnostics.js +3 -3
  74. package/dist/core/command/data-root-resolver.js +2 -3
  75. package/dist/core/command/menu-catalog.js +10 -3
  76. package/dist/core/command/menu-handler.js +321 -46
  77. package/dist/core/command/menu-protocol.js +53 -7
  78. package/dist/core/command/pa-workspace-calendar.js +1 -2
  79. package/dist/core/command/pa-workspace-items.js +486 -0
  80. package/dist/core/command/pa-workspace-store.js +10 -1
  81. package/dist/core/command/slash-gate.js +2 -2
  82. package/dist/core/command/slash-handler.js +67 -25
  83. package/dist/core/contact-bind-registry.js +27 -0
  84. package/dist/core/daemon-control.js +3 -3
  85. package/dist/core/daemon-lifecycle.js +2 -1
  86. package/dist/core/event-bus.js +9 -2
  87. package/dist/core/handoff/ipc-registration.js +1 -0
  88. package/dist/core/host-snapshot.js +1 -2
  89. package/dist/core/initialization/service.js +32 -11
  90. package/dist/core/ipc-registration.js +18 -5
  91. package/dist/core/memory/consolidation-context.js +2 -2
  92. package/dist/core/message/aun-request-registry.js +99 -18
  93. package/dist/core/message/im-renderer.js +16 -11
  94. package/dist/core/message/message-admission.js +25 -20
  95. package/dist/core/message/message-bridge.js +21 -47
  96. package/dist/core/message/message-queue.js +3 -0
  97. package/dist/core/message/response-engine.js +7 -5
  98. package/dist/core/model/catalog-service.js +1 -1
  99. package/dist/core/permission/ec-command-parser.js +41 -9
  100. package/dist/core/permission/permission-result.js +1 -0
  101. package/dist/core/permission/protected-paths.js +25 -14
  102. package/dist/core/permission/tool-policy.js +108 -107
  103. package/dist/core/plugin-lifecycle.js +133 -0
  104. package/dist/core/runner-reload-transaction.js +4 -1
  105. package/dist/core/system-session/memory.js +16 -3
  106. package/dist/core/task/task-activity-store.js +50 -0
  107. package/dist/core/task/task-image-resources.js +140 -0
  108. package/dist/core/thread/ipc-operation.js +1 -1
  109. package/dist/core/thread/thread-service.js +0 -1
  110. package/dist/directory/canonical-digest.js +5 -3
  111. package/dist/directory/owner-directory-admission.js +22 -2
  112. package/dist/directory/owner-directory-cache.js +394 -60
  113. package/dist/directory/owner-directory-markdown.js +29 -2
  114. package/dist/directory/owner-directory-scope.js +35 -16
  115. package/dist/ecweb/basic-settings-service.js +4 -1
  116. package/dist/ecweb/pairing.js +41 -0
  117. package/dist/ecweb/providers-service.js +8 -1
  118. package/dist/{utils/ecweb-utils.js → ecweb/runtime/launch.js} +3 -27
  119. package/dist/ecweb/runtime/lifecycle.js +184 -0
  120. package/dist/{utils/ecweb-supervisor.js → ecweb/runtime/supervisor.js} +32 -27
  121. package/dist/index.js +34 -25
  122. package/dist/ipc.js +124 -7
  123. package/dist/response-system/engines/v1/proactive-flow.js +1 -1
  124. package/dist/trigger/authorization.js +2 -2
  125. package/dist/utils/atomic-write.js +24 -0
  126. package/dist/utils/avatar-upload.js +3 -1
  127. package/dist/utils/cross-platform.js +31 -2
  128. package/dist/utils/host-info.js +36 -0
  129. package/dist/utils/instance-registry.js +38 -11
  130. package/dist/utils/logger.js +9 -0
  131. package/dist/utils/{process-tree-stats.js → process-tree.js} +29 -0
  132. package/dist/utils/tool-summary.js +9 -1
  133. package/dist/utils/upgrade-jobs.js +96 -15
  134. package/dist/utils/windows-autostart.js +1 -1
  135. package/ecagent/README.md +19 -0
  136. package/ecagent/dist/harness/agent-harness.js +9 -0
  137. package/ecagent/dist/harness/env/nodejs.js +71 -11
  138. package/ecagent/dist/harness/env/windows-shell.d.ts +7 -0
  139. package/ecagent/dist/harness/env/windows-shell.js +132 -0
  140. package/kits/docs/aun/ABILITY_CALLING.md +38 -9
  141. package/kits/docs/evolcore/INDEX.md +5 -1
  142. package/kits/docs/evolcore/ability.md +181 -0
  143. package/kits/docs/evolcore/aid.md +20 -0
  144. package/kits/docs/evolcore/config.md +10 -6
  145. package/kits/docs/evolcore/menu-protocol.md +40 -1
  146. package/kits/docs/evolcore/provider.md +2 -2
  147. package/kits/docs/evolcore/tool-authorization.md +270 -0
  148. package/kits/runtime/ability-job.ps1 +41 -0
  149. package/kits/runtime/ability-runner.mjs +67 -0
  150. package/kits/runtime/ability-secret.ps1 +59 -0
  151. package/kits/runtime/ability-templates/go/main.go +59 -0
  152. package/kits/runtime/ability-templates/java/Json.java +67 -0
  153. package/kits/runtime/ability-templates/java/Runner.java +42 -0
  154. package/kits/runtime/ability-templates/python/runner.py +48 -0
  155. package/kits/runtime/ability-templates/rust/json.rs +87 -0
  156. package/kits/runtime/ability-templates/rust/runner.rs +35 -0
  157. package/kits/schemas/_meta.json +12 -1
  158. package/kits/schemas/ability-plugin.schema.1.json +107 -0
  159. package/kits/schemas/ability-project.schema.1.json +31 -0
  160. package/kits/schemas/agent-config.schema.16.json +20 -0
  161. package/kits/schemas/agent-config.schema.17.json +20 -0
  162. package/kits/schemas/agent-config.schema.18.json +917 -0
  163. package/kits/skills/.switches.json +4 -0
  164. package/kits/skills/aid-ability/SKILL.md +5 -4
  165. package/kits/skills/ec-ability/SKILL.md +67 -0
  166. package/kits/skills/ec-ability/references/contract-checklist.md +37 -0
  167. package/kits/skills/ec-ability/references/development.md +104 -0
  168. package/kits/skills/ec-ability/references/management.md +117 -0
  169. package/kits/skills/ec-ability/references/recovery.md +27 -0
  170. package/kits/skills/ec-ability/references/runtime-protocol.md +109 -0
  171. package/kits/skills/ec-ability/references/workflows.md +15 -0
  172. package/kits/skills/ec-service-proxy/SKILL.md +12 -0
  173. package/kits/skills/personal-assistant/SKILL.md +240 -6
  174. package/kits/skills/personal-assistant/references/02-bootstrap.md +78 -4
  175. package/kits/skills/personal-assistant/scripts/clean.mjs +397 -0
  176. package/kits/skills/personal-assistant/scripts/init.mjs +113 -25
  177. package/kits/skills/personal-assistant/scripts/lock.mjs +189 -0
  178. package/kits/skills/personal-assistant/scripts/migrate.mjs +35 -10
  179. package/kits/skills/personal-assistant/scripts/verify.mjs +2 -1
  180. package/kits/skills/personal-assistant/templates/persona-section.md +54 -0
  181. package/kits/skills/personal-assistant/triggers/ingest-daily.json +1 -1
  182. package/kits/templates/memory-consolidation/notes.md +1 -1
  183. package/kits/templates/system-fragments/channel.md +2 -1
  184. package/kits/templates/system-fragments/commands.md +1 -0
  185. package/package.json +5 -3
  186. package/dist/core/command/data-root-error.js +0 -10
  187. package/dist/utils/machine-info.js +0 -46
  188. package/dist/utils/process-tree-worker.js +0 -31
  189. package/dist/utils/windows-output.js +0 -36
@@ -1,10 +1,140 @@
1
- import { authorizeFreshOperation as authorizeOperation, buildAuthSubject } from './auth-gateway.js';
2
- import { hasTrustedFullAccessDelegation, trustedExecutionIdentityInput } from './agent-delegation.js';
1
+ import path from 'node:path';
2
+ import crypto from 'node:crypto';
3
+ import { authorizeFreshOperation as authorizeOperation, buildAuthSubject, executeAuditedOperation, } from './auth-gateway.js';
4
+ import { hashDelegatedCommandArgv, hasTrustedFullAccessDelegation, trustedExecutionIdentityInput, } from './agent-delegation.js';
3
5
  import { isManagementRole } from '../../config/builtin-roles.js';
4
6
  import { parsePeerKey } from '../relation/peer-identity.js';
7
+ import { executeParsedProviderOperation, parseProviderCommand } from '../../config/provider-ipc-service.js';
8
+ import { MAIN_CLI_BIN } from '../../product.js';
9
+ import { executeUpgradeOperation, parseUpgradeCommand } from '../../cli/upgrade-command.js';
10
+ export function createDelegatedUpgradeOperationExecutor({ agentDelegationRegistry, sessionManager, getProcessOwners, }) {
11
+ return async function executeDelegatedUpgradeOperation(params) {
12
+ const validation = agentDelegationRegistry.validate(params.delegationToken, params.sessionId, params.delegationCommandHash);
13
+ if (!validation.ok)
14
+ return { ok: false, code: validation.code, error: validation.reason };
15
+ const grant = validation.grant;
16
+ const session = await sessionManager.getSessionById(params.sessionId);
17
+ if (!session || session.selfAID !== grant.selfAid) {
18
+ return { ok: false, code: 'INVALID_DELEGATION', error: 'delegation does not match the current session' };
19
+ }
20
+ let parsed;
21
+ try {
22
+ parsed = parseUpgradeCommand(params.argv);
23
+ }
24
+ catch (error) {
25
+ return { ok: false, code: 'INVALID_ARGUMENT', error: error instanceof Error ? error.message : String(error) };
26
+ }
27
+ const conversationId = parsePeerKey(grant.peerKey).channelId;
28
+ const subject = buildAuthSubject({
29
+ selfAid: grant.selfAid,
30
+ sessionId: params.sessionId,
31
+ requestId: params.requestId,
32
+ actorId: grant.actorId,
33
+ channel: grant.channel,
34
+ channelType: grant.channelType,
35
+ channelId: conversationId,
36
+ chatType: grant.chatType,
37
+ conversationId,
38
+ processOwners: getProcessOwners(),
39
+ ...trustedExecutionIdentityInput(grant),
40
+ });
41
+ const operation = parsed.mode === 'check' ? 'system.upgrade.check'
42
+ : parsed.mode === 'update' ? 'system.update' : 'system.update.status';
43
+ const result = await executeAuditedOperation({
44
+ source: 'agent-tool', subject,
45
+ intent: { operation, scope: 'process', source: 'agent-tool', args: { mode: parsed.mode } },
46
+ auditMetadata: {
47
+ argvHash: hashDelegatedCommandArgv([MAIN_CLI_BIN, ...params.argv]),
48
+ taskId: grant.taskId,
49
+ messageId: grant.messageId,
50
+ sessionId: params.sessionId,
51
+ agentAid: grant.selfAid,
52
+ },
53
+ }, async (onExecutionStarted) => {
54
+ onExecutionStarted();
55
+ const response = await executeUpgradeOperation({ argv: params.argv, requestId: params.requestId ?? crypto.randomUUID() });
56
+ const menuError = response.error;
57
+ if (menuError)
58
+ return { ok: false, code: menuError.code, error: menuError.message, response };
59
+ return { ok: true, response };
60
+ });
61
+ if ('response' in result)
62
+ return result.response;
63
+ return result;
64
+ };
65
+ }
66
+ /** Execute a structurally valid Provider command under its authenticated task identity. */
67
+ export function createDelegatedProviderOperationExecutor({ agentDelegationRegistry, sessionManager, getProcessOwners, }) {
68
+ return async function executeDelegatedProviderOperation(params) {
69
+ const validation = agentDelegationRegistry.validate(params.delegationToken, params.sessionId, params.delegationCommandHash);
70
+ if (!validation.ok)
71
+ return { ok: false, code: validation.code, error: validation.reason };
72
+ const grant = validation.grant;
73
+ const session = await sessionManager.getSessionById(params.sessionId);
74
+ if (!session || session.selfAID !== grant.selfAid) {
75
+ return { ok: false, code: 'INVALID_DELEGATION', error: 'delegation does not match the current session' };
76
+ }
77
+ let parsed;
78
+ try {
79
+ parsed = parseProviderCommand(params.argv);
80
+ }
81
+ catch (error) {
82
+ return { ok: false, code: 'INVALID_ARGUMENT', error: error instanceof Error ? error.message : String(error) };
83
+ }
84
+ let conversationId;
85
+ try {
86
+ conversationId = parsePeerKey(grant.peerKey).channelId;
87
+ }
88
+ catch {
89
+ return { ok: false, code: 'INVALID_DELEGATION', error: 'delegation contains an invalid relation key' };
90
+ }
91
+ const subject = buildAuthSubject({
92
+ selfAid: grant.selfAid,
93
+ sessionId: params.sessionId,
94
+ requestId: params.requestId,
95
+ actorId: grant.actorId,
96
+ channel: grant.channel,
97
+ channelType: grant.channelType,
98
+ channelId: conversationId,
99
+ chatType: grant.chatType,
100
+ conversationId,
101
+ permissionMode: grant.permissionMode,
102
+ processOwners: getProcessOwners(),
103
+ ...trustedExecutionIdentityInput(grant),
104
+ });
105
+ return executeAuditedOperation({
106
+ source: 'agent-tool',
107
+ subject,
108
+ intent: {
109
+ operation: `provider.${parsed.operation}`,
110
+ scope: 'process',
111
+ source: 'agent-tool',
112
+ args: parsed.providerId ? { providerId: parsed.providerId } : {},
113
+ },
114
+ auditMetadata: {
115
+ argvHash: hashProviderArgv(params.argv),
116
+ taskId: grant.taskId,
117
+ messageId: grant.messageId,
118
+ sessionId: params.sessionId,
119
+ agentAid: grant.selfAid,
120
+ },
121
+ }, async (onExecutionStarted) => {
122
+ onExecutionStarted();
123
+ const command = parsed.file && !path.isAbsolute(parsed.file)
124
+ ? { ...parsed, file: path.resolve(session.projectPath, parsed.file) }
125
+ : parsed;
126
+ return executeParsedProviderOperation(command);
127
+ });
128
+ };
129
+ }
130
+ function hashProviderArgv(argv) {
131
+ return hashDelegatedCommandArgv([MAIN_CLI_BIN, ...argv]);
132
+ }
5
133
  export function createDelegationAuthorizer({ agentDelegationRegistry, sessionManager, getProcessOwners, }) {
6
134
  return async function authorizeManagedAgentOperation(params, operation) {
7
- const delegation = agentDelegationRegistry.validate(params.delegationToken, params.sessionId, params.delegationCommandHash);
135
+ const delegation = params.delegationGrant
136
+ ? { ok: true, grant: params.delegationGrant }
137
+ : agentDelegationRegistry.validate(params.delegationToken, params.sessionId, params.delegationCommandHash);
8
138
  if (!delegation.ok)
9
139
  return { ok: false, code: delegation.code, error: delegation.reason };
10
140
  const session = await sessionManager.getSessionById(params.sessionId);
@@ -41,10 +171,15 @@ export function createDelegationAuthorizer({ agentDelegationRegistry, sessionMan
41
171
  intent: {
42
172
  operation,
43
173
  scope: operation === 'system.status' || operation === 'proxy.configure' || operation === 'proxy.lifecycle'
174
+ || operation.startsWith('provider.')
44
175
  ? 'process'
45
176
  : 'agent',
46
177
  source: 'agent-tool',
47
- args: { self: delegation.grant.selfAid, aid: params.targetAid ?? delegation.grant.selfAid },
178
+ args: {
179
+ self: delegation.grant.selfAid,
180
+ aid: params.targetAid ?? delegation.grant.selfAid,
181
+ targetAgentAid: params.targetAid ?? delegation.grant.selfAid,
182
+ },
48
183
  },
49
184
  auditMetadata: { taskId: delegation.grant.taskId, messageId: delegation.grant.messageId },
50
185
  });
@@ -56,6 +191,7 @@ export function createDelegationAuthorizer({ agentDelegationRegistry, sessionMan
56
191
  fullAccess: hasTrustedFullAccessDelegation(delegation.grant),
57
192
  management: isManagementRole(subject.role),
58
193
  sessionRuntimeDir: delegation.grant.sessionRuntimeDir,
194
+ grant: delegation.grant,
59
195
  }
60
196
  : { ok: false, code: decision.code, error: decision.reason };
61
197
  };
@@ -6,6 +6,7 @@ import { normalizePeer } from '../model/config-scope.js';
6
6
  import { getOperationMeta } from './operation-catalog.js';
7
7
  import { formatPeerKey, parsePeerKey } from '../relation/peer-identity.js';
8
8
  import { sameGroupAid } from '../../aun/group/index.js';
9
+ import { ownerResolver } from '../ownership/owner-resolver.js';
9
10
  const DAEMON_OWNER_PROCESS_OPERATIONS = new Set([
10
11
  'agent.list',
11
12
  'agent.create',
@@ -15,6 +16,9 @@ const DAEMON_OWNER_PROCESS_OPERATIONS = new Set([
15
16
  'agent.disable',
16
17
  'system.restart',
17
18
  'system.upgrade',
19
+ 'system.upgrade.check',
20
+ 'system.update',
21
+ 'system.update.status',
18
22
  'system.paircode',
19
23
  'gateway.read',
20
24
  'gateway.write',
@@ -40,6 +44,9 @@ const DAEMON_SERVICE_OPERATIONS = new Set([
40
44
  'agent.reload',
41
45
  'system.restart',
42
46
  'system.upgrade',
47
+ 'system.upgrade.check',
48
+ 'system.update',
49
+ 'system.update.status',
43
50
  ]);
44
51
  const DAEMON_OWNER_MODEL_OPTION_READ_OPERATIONS = new Set([
45
52
  'model.list',
@@ -79,6 +86,7 @@ export function evaluateRoleOperationCapability(params) {
79
86
  source: 'menu',
80
87
  args: {
81
88
  self: capabilitySelf,
89
+ targetAgentAid: capabilitySelf,
82
90
  peer: capabilityPeer,
83
91
  peerKey: capabilityPeer,
84
92
  },
@@ -103,14 +111,6 @@ function authorizeCommandInternal(ctx, resolvedConfigCommand) {
103
111
  if (!opMeta) {
104
112
  return denyDecision(ctx, 'NOT_ALLOWED', `Unknown operation: ${operation}`, operation, intent.scope);
105
113
  }
106
- if (operation.startsWith('provider.')) {
107
- if (intent.scope !== 'process' || !ctx.fromControlChannel
108
- || !(ctx.isDaemonOwner === true || ctx.processRole === 'daemon-owner')
109
- || !['menu', 'control', 'ecweb'].includes(ctx.source)) {
110
- return denyDecision(ctx, 'NOT_ALLOWED', 'Provider management requires DaemonOwner process control', operation, intent.scope, opMeta.dangerous);
111
- }
112
- return { allow: true, operation, scope: intent.scope, role: 'daemon-owner', dangerous: opMeta.dangerous, matchedRule: 'provider-process-owner' };
113
- }
114
114
  if (isFieldConfigOperation(operation) && !resolvedConfigCommand) {
115
115
  return denyDecision(ctx, 'NOT_ALLOWED', 'Resolved config operation is required', operation, intent.scope, opMeta.dangerous);
116
116
  }
@@ -128,9 +128,8 @@ function authorizeCommandInternal(ctx, resolvedConfigCommand) {
128
128
  // still has to name a known operation and pass structural command parsing,
129
129
  // but relation/Agent role rules, source lists, and daemon-owner gates are
130
130
  // not meaningful limits for code already approved for host-level execution.
131
- if (ctx.processRole === 'fullaccess-run' && ctx.dataScope === 'daemon'
132
- && operation !== 'ec.aid.bind' && operation !== 'ec.aid.transfer' && operation !== 'ec.aid.bind.status') {
133
- if (operation === 'system.restart' || operation === 'system.upgrade') {
131
+ if (ctx.processRole === 'fullaccess-run' && ctx.dataScope === 'daemon') {
132
+ if (['system.restart', 'system.upgrade', 'system.update'].includes(operation)) {
134
133
  return denyDecision(ctx, 'NOT_ALLOWED', 'The EvolCore instance hosting the current fullaccess task is protected from lifecycle changes', operation, intent.scope, opMeta.dangerous, 'fullaccess-current-runtime-protected');
135
134
  }
136
135
  return {
@@ -153,6 +152,20 @@ function authorizeCommandInternal(ctx, resolvedConfigCommand) {
153
152
  if (!sourceAllowed) {
154
153
  return denyDecision(ctx, 'NOT_ALLOWED', `Operation ${operation} is not available from source ${ctx.source}`, operation, intent.scope, opMeta.dangerous);
155
154
  }
155
+ const authorizationTarget = checkCatalogTarget(ctx, opMeta);
156
+ if (!authorizationTarget.ok) {
157
+ return denyDecision(ctx, 'SCOPE_MISMATCH', authorizationTarget.reason, operation, intent.scope, opMeta.dangerous);
158
+ }
159
+ if (ctx.source === 'agent-tool' && opMeta.minimumPermissionMode === 'request'
160
+ && !['request', 'bypass'].includes(ctx.permissionMode ?? '')) {
161
+ return denyDecision(ctx, 'NOT_ALLOWED', 'This operation requires a request or bypass task', operation, intent.scope, opMeta.dangerous, 'catalog-task-mode');
162
+ }
163
+ if (opMeta.personalStorageRequiresOwner && intent.args.personalStorage === true && role !== 'owner') {
164
+ return denyDecision(ctx, 'NOT_ALLOWED', 'Managed personal storage requires the current Agent Owner', operation, intent.scope, opMeta.dangerous, 'catalog-agent-owner');
165
+ }
166
+ const authorizationOverride = authorizeCatalogPolicy(ctx, opMeta);
167
+ if (authorizationOverride)
168
+ return authorizationOverride;
156
169
  if (operation === 'ec.aid.bind.status') {
157
170
  if (intent.scope !== 'agent') {
158
171
  return denyDecision(ctx, 'NOT_ALLOWED', 'Ownership status is only available for an Agent subject', operation, intent.scope, opMeta.dangerous);
@@ -280,7 +293,7 @@ function authorizeCommandInternal(ctx, resolvedConfigCommand) {
280
293
  return denyDecision(ctx, 'NOT_ALLOWED', `${operation} may only target the current Agent from a managed Agent task.`, operation, intent.scope, opMeta.dangerous, undefined, 'TARGET_SELF_ONLY');
281
294
  }
282
295
  if (operation === 'agent.persona' && isCurrentAgentTarget(ctx)
283
- && (role === 'owner' || hasDaemonOwnerRole(ctx))) {
296
+ && (role === 'owner' || (ctx.fromControlChannel && hasDaemonOwnerRole(ctx)))) {
284
297
  return {
285
298
  allow: true,
286
299
  operation,
@@ -449,6 +462,91 @@ function authorizeCommandInternal(ctx, resolvedConfigCommand) {
449
462
  permissionMode: permission.permissionMode,
450
463
  };
451
464
  }
465
+ function checkCatalogTarget(ctx, meta) {
466
+ const targetPolicy = meta.authorizationTarget;
467
+ if (!targetPolicy)
468
+ return { ok: true };
469
+ const targetAid = stringArg(ctx.intent.args.targetAgentAid);
470
+ if (!targetAid || !ctx.selfAid)
471
+ return { ok: false, reason: 'Explicit targetAgentAid and the current Agent identity are required', code: 'SCOPE_MISMATCH' };
472
+ if (targetPolicy === 'any-local-aid') {
473
+ const ownerBypass = ctx.role === 'owner' && ctx.permissionMode === 'bypass' && ctx.source === 'agent-tool';
474
+ return ownerBypass || targetAid === ctx.selfAid
475
+ ? { ok: true }
476
+ : { ok: false, reason: 'Only the current Agent AID may be targeted', code: 'SCOPE_MISMATCH' };
477
+ }
478
+ if (targetPolicy === 'current-agent') {
479
+ return targetAid === ctx.selfAid
480
+ ? { ok: true }
481
+ : { ok: false, reason: 'Only the current Agent may be targeted', code: 'SCOPE_MISMATCH' };
482
+ }
483
+ const actorOwner = ownerResolver.owner(ctx.selfAid);
484
+ const targetOwner = ownerResolver.owner(targetAid);
485
+ return targetAid === ctx.selfAid || (!!actorOwner && targetOwner === actorOwner)
486
+ ? { ok: true }
487
+ : { ok: false, reason: 'Target Agent does not share the current Agent\'s verified Owner', code: 'SCOPE_MISMATCH' };
488
+ }
489
+ /** Catalog policies run once, after structural/source checks and trusted fullaccess. */
490
+ function authorizeCatalogPolicy(ctx, meta) {
491
+ const policy = meta.authorizationPolicy;
492
+ const { operation, scope, args } = ctx.intent;
493
+ const allow = (role, matchedRule) => ({
494
+ allow: true, operation, scope, role, dangerous: meta.dangerous, matchedRule,
495
+ });
496
+ const deny = (reason, code = 'NOT_ALLOWED') => denyDecision(ctx, code, reason, operation, scope, meta.dangerous, policy?.authority ?? 'catalog-requirement');
497
+ if (meta.requiredChannelType && ctx.channel?.split('#')[0] !== meta.requiredChannelType) {
498
+ return deny(`This operation requires an ${meta.requiredChannelType} Agent channel`);
499
+ }
500
+ if (meta.requiredChatType && ctx.chatType !== meta.requiredChatType) {
501
+ return deny(`This operation requires a ${meta.requiredChatType} chat`);
502
+ }
503
+ if (meta.minimumAgentRole === 'owner' && ctx.role !== 'owner') {
504
+ return deny('This operation requires the current Agent Owner');
505
+ }
506
+ if (meta.minimumAgentRole === 'management' && !isManagementRole(ctx.role)) {
507
+ return deny('This operation requires an Agent management role');
508
+ }
509
+ if (meta.relationRequiresAun && !isManagementRole(ctx.role) && ctx.channel?.split('#')[0] !== 'aun') {
510
+ return deny('This operation requires the current AUN relation or an Agent management role');
511
+ }
512
+ if (meta.memberTargetRequiresManagement && !isManagementRole(ctx.role)
513
+ && args.memberAid !== args.self) {
514
+ return deny('Only an Agent management role may change another member');
515
+ }
516
+ if (!policy)
517
+ return undefined;
518
+ if (policy.authority === 'daemon-owner') {
519
+ return scope === policy.scope && policy.channel === 'control' && ctx.fromControlChannel
520
+ && hasDaemonOwnerRole(ctx) && ctx.processRole !== 'daemon-service'
521
+ ? allow('daemon-owner', 'catalog-daemon-owner')
522
+ : deny('This operation requires DaemonOwner process control');
523
+ }
524
+ // This restriction is for delegated execution only; management surfaces
525
+ // continue through the ordinary process-owner rules below.
526
+ if (policy.authority === 'trusted-fullaccess') {
527
+ return ctx.source === 'agent-tool'
528
+ ? deny('This delegated operation requires a trusted fullaccess task')
529
+ : undefined;
530
+ }
531
+ if (policy.previewOnly && args.preview !== true)
532
+ return undefined;
533
+ const ownerBypass = ctx.role === 'owner'
534
+ && ctx.permissionMode === policy.permissionMode
535
+ && ctx.source === 'agent-tool';
536
+ if (policy.previewOnly && args.preview === true && !ownerBypass) {
537
+ return deny('Model previews require the current Agent Owner with bypass permission');
538
+ }
539
+ if (policy.mode === 'require' && !ownerBypass) {
540
+ return deny('This operation requires the current Agent Owner with bypass permission');
541
+ }
542
+ if (policy.mode === 'elevate' && !ownerBypass)
543
+ return undefined;
544
+ if (!meta.defaultScopes.includes(scope))
545
+ return deny('Operation scope is not supported', 'SCOPE_MISMATCH');
546
+ if (!ctx.selfAid)
547
+ return deny('Current Agent is unavailable', 'SCOPE_MISMATCH');
548
+ return allow(ctx.role, 'catalog-owner-bypass');
549
+ }
452
550
  function matchCommandPermission(operation, category, commandPerms, isDangerous) {
453
551
  const matches = [];
454
552
  for (const [rule, permission] of Object.entries(commandPerms)) {
@@ -571,7 +669,10 @@ function checkConstraints(ctx, constraints, resolvedConfigCommand) {
571
669
  return peerCheck;
572
670
  }
573
671
  if (constraints.ownAgentOnly || constraints.targetCurrentAgentOnly) {
574
- const controlOwnerOverride = ctx.fromControlChannel && hasDaemonOwnerRole(ctx);
672
+ const controlOwnerOverride = (ctx.fromControlChannel && hasDaemonOwnerRole(ctx))
673
+ || (ctx.intent.operation === 'ec.aid.show'
674
+ && ctx.role === 'owner'
675
+ && ctx.permissionMode === 'bypass');
575
676
  const targetAid = stringArg(ctx.intent.args.targetAgentAid)
576
677
  ?? stringArg(ctx.intent.args.aid)
577
678
  ?? stringArg(ctx.intent.args.self);
@@ -21,6 +21,12 @@ const CONFIG_MANAGEMENT_OPERATIONS = [
21
21
  description,
22
22
  sources: ['menu.cli', 'agent-tool', 'control'],
23
23
  }));
24
+ const GROUP_OWNER_OPERATIONS = new Set(['ec.group.dissolve', 'ec.group.owner', 'ec.group.accept-invite', 'ec.group.reject-invite']);
25
+ const GROUP_RELATION_OPERATIONS = new Set([
26
+ 'ec.group.info', 'ec.group.pull', 'ec.group.history', 'ec.group.members', 'ec.group.online',
27
+ 'ec.group.member-statuses', 'ec.group.rules.get', 'ec.group.rules.read', 'ec.group.mention',
28
+ 'ec.group.report-status', 'ec.group.block', 'ec.group.unblock',
29
+ ]);
24
30
  const GROUP_MANAGEMENT_OPERATIONS = [
25
31
  ['ec.group.list', 'read', ['agent'], 'List groups joined by the current Agent'],
26
32
  ['ec.group.info', 'read', ['relation', 'agent'], 'Read group information'],
@@ -64,6 +70,14 @@ const GROUP_MANAGEMENT_OPERATIONS = [
64
70
  defaultScopes,
65
71
  description,
66
72
  sources: ['agent-tool'],
73
+ authorizationTarget: 'current-agent',
74
+ ...(GROUP_OWNER_OPERATIONS.has(id) ? { minimumAgentRole: 'owner' }
75
+ : GROUP_RELATION_OPERATIONS.has(id) ? { relationRequiresAun: true }
76
+ : id === 'ec.group.list' ? {}
77
+ : { minimumAgentRole: 'management' }),
78
+ ...(id === 'ec.group.block' || id === 'ec.group.unblock' ? { memberTargetRequiresManagement: true } : {}),
79
+ ...(id === 'ec.group.accept-invite' || id === 'ec.group.reject-invite'
80
+ ? { requiredChatType: 'private', requiredChannelType: 'aun' } : {}),
67
81
  }));
68
82
  const MSG_READ_OPERATIONS = [
69
83
  ['ec.msg.history', 'Read message history for a controlled private relation'],
@@ -83,14 +97,16 @@ const GROUP_FS_READ_OPERATIONS = ['ls', 'stat', 'lstat', 'cat', 'find', 'df', 'g
83
97
  defaultScopes: ['relation', 'agent'],
84
98
  description: `Read managed filesystem (${kind})`,
85
99
  sources: ['agent-tool'],
100
+ personalStorageRequiresOwner: true,
86
101
  }));
87
- const GROUP_FS_WRITE_OPERATIONS = [['mkdir', 'write-own'], ['upload', 'write-own'], ['copy', 'write-own'], ['move', 'write-own'], ['remove', 'write-own'], ['setfacl', 'write-agent']].map(([kind, category]) => ({
102
+ const GROUP_FS_WRITE_OPERATIONS = [['mkdir', 'write-own'], ['upload', 'write-own'], ['copy', 'write-own'], ['move', 'write-own'], ['remove', 'write-own'], ['link', 'write-own'], ['setfacl', 'write-agent']].map(([kind, category]) => ({
88
103
  id: `ec.fs.${kind}`,
89
104
  category,
90
105
  dangerous: false,
91
106
  defaultScopes: ['relation', 'agent'],
92
107
  description: `Write managed filesystem (${kind})`,
93
108
  sources: ['agent-tool'],
109
+ personalStorageRequiresOwner: true,
94
110
  }));
95
111
  const HANDOFF_READ_OPERATIONS = ['status', 'list', 'trace'].map(kind => ({
96
112
  id: `ec.handoff.${kind}`,
@@ -135,8 +151,34 @@ const PROVIDER_OPERATIONS = ['list', 'show', 'create', 'import', 'update', 'dele
135
151
  defaultScopes: ['process'],
136
152
  description: 'Manage the daemon Provider registry: ' + action,
137
153
  sources: ['menu', 'control', 'ecweb'],
154
+ authorizationPolicy: { authority: 'daemon-owner', scope: 'process', channel: 'control' },
138
155
  }));
139
156
  const OPERATIONS = [
157
+ ...['read', 'result-read', 'install', 'configure', 'enable', 'disable', 'invoke', 'publish', 'upgrade', 'rollback', 'uninstall', 'grant', 'retire'].map(action => ({
158
+ id: 'ability.' + action, category: action === 'read' ? 'read' : 'write-agent',
159
+ dangerous: action !== 'read', defaultScopes: ['agent'], description: 'Manage AID ability plugins: ' + action,
160
+ sources: ['agent-tool', 'control', 'ecweb'],
161
+ })),
162
+ {
163
+ id: 'ec.directory.query',
164
+ category: 'read',
165
+ dangerous: false,
166
+ defaultScopes: ['agent'],
167
+ description: 'Query the current Agent owner directory',
168
+ sources: ['agent-tool'],
169
+ authorizationTarget: 'same-owner-agent',
170
+ authorizationPolicy: { authority: 'agent-owner', permissionMode: 'bypass', mode: 'require' },
171
+ },
172
+ {
173
+ id: 'ec.directory.remark',
174
+ category: 'write-own',
175
+ dangerous: false,
176
+ defaultScopes: ['agent'],
177
+ description: 'Manage the current Agent owner directory remarks',
178
+ sources: ['agent-tool'],
179
+ authorizationTarget: 'same-owner-agent',
180
+ authorizationPolicy: { authority: 'agent-owner', permissionMode: 'bypass', mode: 'require' },
181
+ },
140
182
  ...PROVIDER_OPERATIONS,
141
183
  {
142
184
  id: 'proxy.read',
@@ -178,6 +220,8 @@ const OPERATIONS = [
178
220
  defaultScopes: ['relation', 'role', 'agent'],
179
221
  description: '列出可用模型',
180
222
  sources: ['slash', 'menu', 'menu.cli', 'agent-tool'],
223
+ authorizationTarget: 'current-agent',
224
+ authorizationPolicy: { authority: 'agent-owner', permissionMode: 'bypass', mode: 'elevate', previewOnly: true },
181
225
  },
182
226
  {
183
227
  id: 'model.current',
@@ -186,6 +230,8 @@ const OPERATIONS = [
186
230
  defaultScopes: ['relation', 'role', 'agent'],
187
231
  description: '查询当前使用的模型',
188
232
  sources: ['slash', 'menu', 'menu.cli', 'agent-tool'],
233
+ authorizationTarget: 'current-agent',
234
+ authorizationPolicy: { authority: 'agent-owner', permissionMode: 'bypass', mode: 'elevate', previewOnly: true },
189
235
  },
190
236
  {
191
237
  id: 'model.effort.current',
@@ -194,6 +240,8 @@ const OPERATIONS = [
194
240
  defaultScopes: ['relation', 'role', 'agent'],
195
241
  description: '查询当前推理努力度',
196
242
  sources: ['slash', 'menu', 'menu.cli', 'agent-tool'],
243
+ authorizationTarget: 'current-agent',
244
+ authorizationPolicy: { authority: 'agent-owner', permissionMode: 'bypass', mode: 'elevate', previewOnly: true },
197
245
  },
198
246
  {
199
247
  id: 'model.info',
@@ -202,6 +250,8 @@ const OPERATIONS = [
202
250
  defaultScopes: ['relation', 'role', 'agent'],
203
251
  description: '查询指定模型的详细信息',
204
252
  sources: ['menu.cli', 'agent-tool'],
253
+ authorizationTarget: 'current-agent',
254
+ authorizationPolicy: { authority: 'agent-owner', permissionMode: 'bypass', mode: 'elevate', previewOnly: true },
205
255
  },
206
256
  {
207
257
  id: 'model.check',
@@ -210,6 +260,8 @@ const OPERATIONS = [
210
260
  defaultScopes: ['agent'],
211
261
  description: '检查模型可用性(可能触发网关探测)',
212
262
  sources: ['slash', 'menu.cli', 'agent-tool'],
263
+ authorizationTarget: 'current-agent',
264
+ authorizationPolicy: { authority: 'agent-owner', permissionMode: 'bypass', mode: 'elevate', previewOnly: true },
213
265
  },
214
266
  // 模型参数只在 Agent 级配置,仅 owner/admin 可写(operation-authorizer 另有代码级上限)。
215
267
  {
@@ -446,6 +498,22 @@ const OPERATIONS = [
446
498
  description: '搜索当前项目文件(需文件权限和项目路径沙箱检查)',
447
499
  sources: ['menu'],
448
500
  },
501
+ {
502
+ id: 'file.move',
503
+ category: 'write-own',
504
+ dangerous: false,
505
+ defaultScopes: ['filesystem'],
506
+ description: '移动或重命名当前项目内文件和目录',
507
+ sources: ['menu'],
508
+ },
509
+ {
510
+ id: 'file.delete',
511
+ category: 'write-own',
512
+ dangerous: false,
513
+ defaultScopes: ['filesystem'],
514
+ description: '删除当前项目内文件或目录',
515
+ sources: ['menu'],
516
+ },
449
517
  {
450
518
  id: 'file.root.agent',
451
519
  category: 'read',
@@ -767,7 +835,7 @@ const OPERATIONS = [
767
835
  dangerous: false,
768
836
  defaultScopes: ['agent'],
769
837
  description: '读取或更新当前 Agent 的 persona.md',
770
- sources: ['agent-tool', 'control'],
838
+ sources: ['agent-tool', 'slash', 'menu', 'control'],
771
839
  },
772
840
  {
773
841
  id: 'agent.welcome',
@@ -775,7 +843,7 @@ const OPERATIONS = [
775
843
  dangerous: false,
776
844
  defaultScopes: ['agent'],
777
845
  description: '读取或更新当前 Agent 的 Bootstrap welcome.md',
778
- sources: ['agent-tool', 'control'],
846
+ sources: ['agent-tool', 'slash', 'menu', 'control'],
779
847
  },
780
848
  {
781
849
  id: 'agent.rename',
@@ -831,7 +899,7 @@ const OPERATIONS = [
831
899
  dangerous: false,
832
900
  defaultScopes: ['agent', 'control'],
833
901
  description: '重建技能索引文件',
834
- sources: ['agent-tool', 'control'],
902
+ sources: ['agent-tool', 'slash', 'menu', 'control'],
835
903
  },
836
904
  ...['list', 'list-peers', 'show', 'history', 'check-index', 'summary-show', 'summary-log', 'create', 'rename', 'label', 'status', 'delete', 'summary-set', 'summary-clear', 'rebuild-index'].map(action => ({
837
905
  id: `ec.thread.${action}`,
@@ -941,6 +1009,33 @@ const OPERATIONS = [
941
1009
  description: '升级 evolcore 版本',
942
1010
  sources: ['slash', 'menu', 'control'],
943
1011
  },
1012
+ {
1013
+ id: 'system.upgrade.check',
1014
+ category: 'process',
1015
+ dangerous: true,
1016
+ defaultScopes: ['process'],
1017
+ description: '检查 EvolCore 及相关组件版本',
1018
+ sources: ['agent-tool', 'slash', 'menu', 'control'],
1019
+ authorizationPolicy: { authority: 'trusted-fullaccess' },
1020
+ },
1021
+ {
1022
+ id: 'system.update',
1023
+ category: 'process',
1024
+ dangerous: true,
1025
+ defaultScopes: ['process'],
1026
+ description: '执行 EvolCore 更新并重启 daemon',
1027
+ sources: ['agent-tool', 'slash', 'menu', 'control'],
1028
+ authorizationPolicy: { authority: 'trusted-fullaccess' },
1029
+ },
1030
+ {
1031
+ id: 'system.update.status',
1032
+ category: 'process',
1033
+ dangerous: false,
1034
+ defaultScopes: ['process'],
1035
+ description: '查询当前 EvolCore 更新任务',
1036
+ sources: ['agent-tool', 'slash', 'menu', 'control'],
1037
+ authorizationPolicy: { authority: 'trusted-fullaccess' },
1038
+ },
944
1039
  // ── Stats Operations ──
945
1040
  {
946
1041
  id: 'stats.summary',
@@ -1162,13 +1257,26 @@ const OPERATIONS = [
1162
1257
  defaultScopes: ['relation', 'agent'],
1163
1258
  description: 'Inspect the current Agent local AID identity and signing state',
1164
1259
  sources: ['agent-tool'],
1260
+ authorizationTarget: 'any-local-aid',
1261
+ authorizationPolicy: { authority: 'agent-owner', permissionMode: 'bypass', mode: 'elevate' },
1262
+ },
1263
+ {
1264
+ id: 'ec.aid.list',
1265
+ category: 'read',
1266
+ dangerous: true,
1267
+ defaultScopes: ['agent'],
1268
+ description: 'List local AID identities and signing state',
1269
+ sources: ['agent-tool'],
1270
+ authorizationPolicy: { authority: 'agent-owner', permissionMode: 'bypass', mode: 'require' },
1165
1271
  },
1166
1272
  {
1167
1273
  id: 'ec.aid.bind', category: 'write-agent', dangerous: true, defaultScopes: ['agent'],
1274
+ minimumPermissionMode: 'request',
1168
1275
  description: 'Request or decide a protocol Owner binding using the subject SDK client', sources: ['agent-tool', 'menu.cli'],
1169
1276
  },
1170
1277
  {
1171
1278
  id: 'ec.aid.transfer', category: 'write-agent', dangerous: true, defaultScopes: ['agent'],
1279
+ minimumPermissionMode: 'request',
1172
1280
  description: 'Transfer a protocol Owner relationship to a new Owner using the subject SDK client', sources: ['agent-tool', 'menu.cli'],
1173
1281
  },
1174
1282
  {
@@ -1198,6 +1306,8 @@ const OPERATIONS = [
1198
1306
  defaultScopes: ['agent'],
1199
1307
  description: 'Sign and publish the current Agent local agent.md',
1200
1308
  sources: ['agent-tool'],
1309
+ minimumPermissionMode: 'request',
1310
+ authorizationTarget: 'current-agent',
1201
1311
  },
1202
1312
  {
1203
1313
  id: 'ec.aid.agentmd.set',
@@ -1206,6 +1316,8 @@ const OPERATIONS = [
1206
1316
  defaultScopes: ['agent'],
1207
1317
  description: 'Update one field and publish the current Agent agent.md',
1208
1318
  sources: ['agent-tool'],
1319
+ minimumPermissionMode: 'request',
1320
+ authorizationTarget: 'current-agent',
1209
1321
  },
1210
1322
  {
1211
1323
  id: 'ec.aid.avatar',
@@ -1214,6 +1326,8 @@ const OPERATIONS = [
1214
1326
  defaultScopes: ['agent'],
1215
1327
  description: 'Upload and publish the current Agent avatar',
1216
1328
  sources: ['agent-tool', 'menu', 'menu.cli'],
1329
+ minimumPermissionMode: 'request',
1330
+ authorizationTarget: 'current-agent',
1217
1331
  },
1218
1332
  {
1219
1333
  id: 'ec.msg.send',
@@ -6,6 +6,7 @@
6
6
  * is fully isolated.
7
7
  */
8
8
  import { logger } from '../utils/logger.js';
9
+ import { PluginHandle } from './plugin-lifecycle.js';
9
10
  /**
10
11
  * 有界并发 map:保持输入顺序返回结果。
11
12
  *
@@ -60,16 +61,28 @@ export class AgentLoader {
60
61
  logger.debug(`Plugin '${pluginName}' disabled for agent '${agent.name}', skipping`);
61
62
  continue;
62
63
  }
64
+ let teardown;
65
+ const lifecycle = new PluginHandle(`${agent.name}::${pluginName}`, () => teardown?.());
63
66
  try {
64
- const instance = await plugin.createAgent(agent, callbacks);
67
+ const instance = await plugin.createAgent(agent, callbacks, lifecycle);
65
68
  if (!instance) {
69
+ await lifecycle.dispose();
66
70
  logger.debug(`Plugin '${pluginName}' returned null for agent '${agent.name}', skipping`);
67
71
  continue;
68
72
  }
73
+ teardown = instance.agent.dispose?.bind(instance.agent);
74
+ instance.agent.dispose = () => lifecycle.dispose();
75
+ instance.lifecycle = lifecycle;
69
76
  instances.push(instance);
70
77
  logger.info(`✓ Runner created: agent=${instance.evolagentName} baseagent=${instance.baseagent}`);
71
78
  }
72
79
  catch (error) {
80
+ try {
81
+ await lifecycle.dispose();
82
+ }
83
+ catch (disposeError) {
84
+ logger.warn(`[AgentLoader] Cleanup failed for ${lifecycle.owner}:`, disposeError);
85
+ }
73
86
  const message = error instanceof Error ? error.message : String(error);
74
87
  creationErrors?.push({ evolagentName: agent.name, baseagent: pluginName, message });
75
88
  logger.error(`✗ Failed to create runner for agent='${agent.name}' baseagent='${pluginName}':`, error);