evolcore 0.0.41-test.0 → 0.0.41-test.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (235) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/dist/agents/baseagent-availability.js +1 -1
  3. package/dist/agents/baseagent.js +88 -49
  4. package/dist/agents/claude-runner.js +177 -92
  5. package/dist/agents/codex-runner.js +146 -71
  6. package/dist/agents/ecagent-runner.js +1 -1
  7. package/dist/agents/gemini-runner.js +1 -1
  8. package/dist/aun/aid/agentmd.js +98 -11
  9. package/dist/aun/aid/client.js +1 -1
  10. package/dist/aun/aid/control-aid.js +26 -2
  11. package/dist/aun/aid/identity.js +91 -0
  12. package/dist/aun/aid/index.js +1 -1
  13. package/dist/aun/aid/managed-operation.js +1 -1
  14. package/dist/aun/aid/ownership-operation.js +23 -22
  15. package/dist/aun/group/fs-download.js +39 -0
  16. package/dist/aun/group/identity.js +36 -21
  17. package/dist/aun/group/operations.js +5 -0
  18. package/dist/aun/menu/client.js +27 -0
  19. package/dist/aun/msg/managed-operation.js +68 -7
  20. package/dist/aun/msg/p2p.js +8 -8
  21. package/dist/aun/service-proxy.js +53 -12
  22. package/dist/channels/aun.js +633 -32
  23. package/dist/channels/daemon.js +15 -1
  24. package/dist/cli/agent-command.js +5 -2
  25. package/dist/cli/agent-create.js +991 -233
  26. package/dist/cli/agent.js +49 -10
  27. package/dist/cli/aid-bind-command.js +48 -19
  28. package/dist/cli/aun-commands.js +48 -36
  29. package/dist/cli/daemon-commands.js +679 -697
  30. package/dist/cli/fs-command.js +64 -2
  31. package/dist/cli/index.js +72 -5
  32. package/dist/cli/init-channel.js +1 -1
  33. package/dist/cli/init.js +75 -1
  34. package/dist/cli/managed-command-guard.js +17 -1
  35. package/dist/cli/model.js +40 -40
  36. package/dist/cli/provider-command.js +57 -0
  37. package/dist/cli/proxy-command.js +92 -0
  38. package/dist/cli/restart-monitor.js +4 -2
  39. package/dist/cli/role.js +85 -0
  40. package/dist/cli/stats.js +10 -3
  41. package/dist/cli/task-context.js +19 -0
  42. package/dist/config/access-policy.js +7 -2
  43. package/dist/config/boot-log.js +39 -1
  44. package/dist/config/config-field-policy.js +17 -39
  45. package/dist/config/config-manager.js +183 -44
  46. package/dist/config/config-operation-service.js +5 -19
  47. package/dist/config/contact-book-store.js +47 -21
  48. package/dist/config/contact-book.js +18 -12
  49. package/dist/config/contact-operation-service.js +3 -4
  50. package/dist/config/contact-request-service.js +11 -0
  51. package/dist/config/daemon-services.js +11 -0
  52. package/dist/config/gateway-config.js +88 -594
  53. package/dist/config/owner-config.js +2 -2
  54. package/dist/config/peer-role-resolver.js +15 -12
  55. package/dist/config/provider-ipc-service.js +132 -0
  56. package/dist/config/provider-menu-request.js +58 -0
  57. package/dist/config/providers-config.js +12 -7
  58. package/dist/config/providers-import.js +3 -21
  59. package/dist/config/providers-management.js +78 -5
  60. package/dist/config/resolved-config-op.js +11 -1
  61. package/dist/config/role-command-service.js +166 -0
  62. package/dist/config/role-request-service.js +193 -0
  63. package/dist/config/schema-migration.js +1000 -25
  64. package/dist/config-store.js +89 -4
  65. package/dist/contracts/ecweb-instance.js +41 -0
  66. package/dist/contracts/ecweb-service-protocol.js +4 -1
  67. package/dist/core/agent-application-service.js +60 -11
  68. package/dist/core/agent-create-status.js +203 -0
  69. package/dist/core/agent-creation-claim.js +177 -0
  70. package/dist/core/agent-ipc-registration.js +39 -18
  71. package/dist/core/agent-runtime.js +194 -24
  72. package/dist/core/auth/agent-delegation.js +6 -3
  73. package/dist/core/auth/auth-gateway.js +67 -2
  74. package/dist/core/auth/authorization-audit.js +58 -11
  75. package/dist/core/auth/delegation-authorization.js +5 -2
  76. package/dist/core/auth/operation-authorizer.js +43 -6
  77. package/dist/core/auth/operation-catalog.js +45 -7
  78. package/dist/core/channel-loader.js +2 -0
  79. package/dist/core/command/agent-control.js +260 -21
  80. package/dist/core/command/agent-storage-menu.js +5 -3
  81. package/dist/core/command/cli-intent-parser.js +8 -3
  82. package/dist/core/command/command-handler.js +112 -154
  83. package/dist/core/command/connect-menu.js +11 -3
  84. package/dist/core/command/data-root-resolver.js +5 -4
  85. package/dist/core/command/memory-slash.js +16 -8
  86. package/dist/core/command/menu-catalog.js +10 -6
  87. package/dist/core/command/menu-handler.js +106 -73
  88. package/dist/core/command/menu-protocol.js +15 -1
  89. package/dist/core/command/provider-menu.js +46 -0
  90. package/dist/core/command/role-menu.js +147 -30
  91. package/dist/core/command/slash-handler.js +125 -255
  92. package/dist/core/daemon-control.js +26 -27
  93. package/dist/core/event-catalog.js +10 -0
  94. package/dist/core/evolagent-registry.js +7 -5
  95. package/dist/core/evolagent.js +10 -8
  96. package/dist/core/file-integrity/store.js +11 -0
  97. package/dist/core/handoff/ipc-registration.js +3 -0
  98. package/dist/core/inference/text-inference.js +31 -40
  99. package/dist/core/initialization/service.js +491 -0
  100. package/dist/core/ipc-registration.js +40 -24
  101. package/dist/core/memory/consolidation-context.js +51 -5
  102. package/dist/core/memory/consolidation-ops-records.js +96 -1
  103. package/dist/core/memory/consolidation-trigger.js +208 -191
  104. package/dist/core/memory/consolidation.js +333 -35
  105. package/dist/core/memory/index-manager.js +27 -5
  106. package/dist/core/memory/memory-admin.js +45 -5
  107. package/dist/core/memory/memory-writer.js +163 -18
  108. package/dist/core/memory/relation-idle-monitor.js +119 -58
  109. package/dist/core/memory/relation-sweep.js +55 -45
  110. package/dist/core/message/aun-ipc-sender.js +81 -69
  111. package/dist/core/message/im-renderer.js +25 -4
  112. package/dist/core/message/message-admission.js +89 -4
  113. package/dist/core/message/message-bridge.js +66 -21
  114. package/dist/core/message/response-engine.js +108 -35
  115. package/dist/core/model/catalog-service.js +5 -3
  116. package/dist/core/model/config-scope.js +29 -71
  117. package/dist/core/model/field-scope.js +1 -1
  118. package/dist/core/model/model-catalog.js +30 -41
  119. package/dist/core/model/model-diagnostics.js +4 -3
  120. package/dist/core/model/model-fallback.js +10 -7
  121. package/dist/core/model/model-permission.js +3 -2
  122. package/dist/core/ownership/owner-resolver.js +772 -158
  123. package/dist/core/permission/approval-gateway.js +103 -403
  124. package/dist/core/permission/ec-command-parser.js +62 -6
  125. package/dist/core/permission/index.js +1 -0
  126. package/dist/core/permission/permission-result.js +78 -0
  127. package/dist/core/permission/sandbox-runtime.js +18 -1
  128. package/dist/core/permission/tool-policy.js +21 -46
  129. package/dist/core/relation/peer-identity.js +64 -1
  130. package/dist/core/role/runtime-policy.js +72 -13
  131. package/dist/core/session/session-capsule.js +1 -1
  132. package/dist/core/session/session-idle-monitor.js +1 -1
  133. package/dist/core/session/session-manager.js +20 -0
  134. package/dist/core/session/session-renew.js +3 -3
  135. package/dist/core/skill/index-generator.js +15 -5
  136. package/dist/core/system-session/memory.js +43 -8
  137. package/dist/core/thread/thread-service.js +19 -6
  138. package/dist/directory/owner-directory-admission.js +95 -0
  139. package/dist/directory/owner-directory-authorization.js +309 -0
  140. package/dist/directory/owner-directory-cache.js +635 -0
  141. package/dist/eck/kit-renderer.js +2 -2
  142. package/dist/ecweb/basic-settings-service.js +33 -40
  143. package/dist/ecweb/init-menu.js +32 -0
  144. package/dist/ecweb/message-context-service.js +110 -0
  145. package/dist/index.js +93 -19
  146. package/dist/ipc.js +247 -29
  147. package/dist/paths.js +7 -0
  148. package/dist/proxy/command.js +122 -0
  149. package/dist/proxy/ipc-service.js +68 -0
  150. package/dist/proxy/manager.js +484 -0
  151. package/dist/proxy/service-supervisor.js +603 -0
  152. package/dist/response-system/engines/v1/proactive-flow.js +16 -6
  153. package/dist/trigger/authorization.js +27 -17
  154. package/dist/trigger/feedback.js +2 -3
  155. package/dist/trigger/ipc-service.js +105 -78
  156. package/dist/trigger/local-files.js +2 -1
  157. package/dist/trigger/manager.js +5 -3
  158. package/dist/trigger/scheduler.js +88 -6
  159. package/dist/utils/atomic-write.js +28 -0
  160. package/dist/utils/cross-platform.js +14 -0
  161. package/dist/utils/ecweb-supervisor.js +258 -83
  162. package/dist/utils/error-utils.js +26 -2
  163. package/dist/utils/logger.js +92 -6
  164. package/dist/utils/package-version-info.js +4 -2
  165. package/dist/utils/welcome.js +1 -1
  166. package/kits/docs/INDEX.md +1 -0
  167. package/kits/docs/aun/SDK.md +4 -1
  168. package/kits/docs/channels/aun.md +9 -0
  169. package/kits/docs/evolcore/INDEX.md +1 -0
  170. package/kits/docs/evolcore/agent.md +8 -1
  171. package/kits/docs/evolcore/aid.md +67 -17
  172. package/kits/docs/evolcore/config.md +28 -7
  173. package/kits/docs/evolcore/contact.md +3 -0
  174. package/kits/docs/evolcore/fs.md +11 -0
  175. package/kits/docs/evolcore/group.md +1 -1
  176. package/kits/docs/evolcore/memory-architecture.md +2 -2
  177. package/kits/docs/evolcore/memory-consolidation.md +32 -8
  178. package/kits/docs/evolcore/memory.md +1 -1
  179. package/kits/docs/evolcore/menu-protocol.md +4 -0
  180. package/kits/docs/evolcore/model.md +23 -20
  181. package/kits/docs/evolcore/msg.md +4 -7
  182. package/kits/docs/evolcore/provider.md +50 -0
  183. package/kits/docs/identity/AID_PROFILE_SPEC.md +52 -17
  184. package/kits/migrations/migrate-contact-book-v2.mjs +30 -11
  185. package/kits/rules/01-overview.md +3 -0
  186. package/kits/rules/04-relation.md +1 -1
  187. package/kits/schemas/_meta.json +37 -4
  188. package/kits/schemas/agent-config.schema.13.json +8 -3
  189. package/kits/schemas/agent-config.schema.16.json +891 -0
  190. package/kits/schemas/daemon.schema.9.json +366 -0
  191. package/kits/schemas/defaults.schema.5.json +406 -127
  192. package/kits/schemas/relation-config.schema.11.json +277 -0
  193. package/kits/schemas/role-config.schema.1.json +7 -7
  194. package/kits/skills/.switches.json +4 -0
  195. package/kits/skills/ec-agent-create/SKILL.md +3 -0
  196. package/kits/skills/ec-identity/SKILL.md +2 -2
  197. package/kits/skills/ec-service-proxy/SKILL.md +118 -0
  198. package/kits/skills/ec-skill/scripts/skill.mjs +6 -0
  199. package/kits/skills/personal-assistant/SKILL.md +176 -0
  200. package/kits/skills/personal-assistant/references/01-workspace-spec.md +333 -0
  201. package/kits/skills/personal-assistant/references/02-bootstrap.md +205 -0
  202. package/kits/skills/personal-assistant/references/03-data-flow-and-gaps.md +177 -0
  203. package/kits/skills/personal-assistant/references/04-frontend-contract.md +439 -0
  204. package/kits/skills/personal-assistant/references/05-directory-reference.md +292 -0
  205. package/kits/skills/personal-assistant/references/06-render-config.md +350 -0
  206. package/kits/skills/personal-assistant/schema/workspace.schema.json +85 -0
  207. package/kits/skills/personal-assistant/schema/workspace.v1.json +66 -0
  208. package/kits/skills/personal-assistant/scripts/archive.mjs +154 -0
  209. package/kits/skills/personal-assistant/scripts/check.mjs +114 -0
  210. package/kits/skills/personal-assistant/scripts/index-rebuild.mjs +252 -0
  211. package/kits/skills/personal-assistant/scripts/ingest.mjs +344 -0
  212. package/kits/skills/personal-assistant/scripts/init.mjs +270 -0
  213. package/kits/skills/personal-assistant/scripts/lib/apply.mjs +92 -0
  214. package/kits/skills/personal-assistant/scripts/lib/schema.mjs +96 -0
  215. package/kits/skills/personal-assistant/scripts/lib/time.mjs +28 -0
  216. package/kits/skills/personal-assistant/scripts/migrate.mjs +172 -0
  217. package/kits/skills/personal-assistant/scripts/search.mjs +172 -0
  218. package/kits/skills/personal-assistant/scripts/verify.mjs +196 -0
  219. package/kits/skills/personal-assistant/templates/INDEX.md.tpl +24 -0
  220. package/kits/skills/personal-assistant/templates/README.md.tpl +108 -0
  221. package/kits/skills/personal-assistant/triggers/ingest-daily.json +23 -0
  222. package/kits/skills/personal-assistant/triggers/memory-consolidate.json +23 -0
  223. package/kits/skills/personal-assistant/triggers/report-daily.json +23 -0
  224. package/kits/skills/personal-assistant/triggers/report-weekly.json +23 -0
  225. package/kits/skills/thread-ops/SKILL.md +5 -0
  226. package/kits/templates/memory-consolidation/forget.md +19 -6
  227. package/kits/templates/memory-consolidation/notes.md +1 -1
  228. package/kits/templates/memory-consolidation/profile.md +2 -2
  229. package/kits/templates/memory-consolidation/promote.md +20 -3
  230. package/kits/templates/roles/member.json +8 -1
  231. package/kits/templates/system-fragments/baseagent.md +2 -2
  232. package/kits/templates/system-fragments/memory.md +4 -4
  233. package/kits/templates/system-fragments/venue.md +1 -1
  234. package/package.json +7 -3
  235. package/dist/core/message/create-status.js +0 -96
@@ -7,6 +7,7 @@ import { hasTrustedPrincipal } from './authenticated-actor.js';
7
7
  import { ownerResolver, refreshOwnershipForAuthorization, OWNERSHIP_CACHE_MAX_AGE_MS } from '../ownership/owner-resolver.js';
8
8
  import { getOperationMeta } from './operation-catalog.js';
9
9
  import { resolveRuntimePermissionMode } from '../role/runtime-policy.js';
10
+ import { buildAuthorizationEventKey } from '../audit/event-key.js';
10
11
  export function isCrossAgentTriggerOperationAllowed(input) {
11
12
  return input.control || input.daemonOwner === true || input.taskAgentAid === input.targetAgentAid;
12
13
  }
@@ -107,7 +108,7 @@ export async function authorizeFreshOperation(params) {
107
108
  const configCommand = params.resolvedConfigCommand;
108
109
  const changesOwner = configCommand?.kind === 'field' && configCommand.subcommand !== 'get'
109
110
  && ['owner', 'owners'].includes(configCommand.field.split('.')[0]);
110
- const force = changesOwner || ['ec.aid.bind', 'ec.aid.bind.status', 'ec.aid.unbind', 'ec.aid.transfer']
111
+ const force = changesOwner || ['ec.aid.bind', 'ec.aid.unbind', 'ec.aid.transfer']
111
112
  .includes(params.intent.operation) || params.intent.operation === 'config.restore';
112
113
  const operation = getOperationMeta(params.intent.operation);
113
114
  const sensitive = force || params.intent.dangerous || operation?.dangerous || operation?.category !== 'read'
@@ -143,6 +144,69 @@ export async function authorizeFreshOperation(params) {
143
144
  }
144
145
  return authorizeOperation(params);
145
146
  }
147
+ /** Record managed command stages using the existing transport request identity. */
148
+ export async function executeAuditedOperation(params, execute, itemIndex) {
149
+ const startedAt = Date.now();
150
+ const metadata = params.auditMetadata;
151
+ const eventKey = metadata?.eventKey ?? buildAuthorizationEventKey({
152
+ sessionId: metadata?.sessionId ?? params.subject.sessionId,
153
+ requestId: metadata?.requestId ?? params.subject.requestId,
154
+ callId: metadata?.callId,
155
+ correlationId: metadata?.correlationId,
156
+ operation: params.intent.operation,
157
+ });
158
+ const auditedParams = {
159
+ ...params,
160
+ auditMetadata: {
161
+ ...metadata,
162
+ eventKey: itemIndex === undefined ? eventKey : `${eventKey}:item:${itemIndex}`,
163
+ },
164
+ };
165
+ let snapshot = {
166
+ allow: true,
167
+ operation: params.intent.operation,
168
+ scope: params.intent.scope,
169
+ role: params.subject.role,
170
+ dangerous: params.intent.dangerous ?? getOperationMeta(params.intent.operation)?.dangerous ?? false,
171
+ };
172
+ const record = (overrides) => {
173
+ if (params.audit !== false)
174
+ auditDecision(auditedParams, snapshot, overrides);
175
+ };
176
+ record({ eventPhase: 'request', decision: 'pending', decisionSource: 'command', executionState: 'requested' });
177
+ let executed = false;
178
+ try {
179
+ const decision = await authorizeFreshOperation(auditedParams);
180
+ if (decision.command)
181
+ snapshot = decision.command;
182
+ if (!decision.allow) {
183
+ record({
184
+ eventPhase: 'response', decision: 'deny', executionState: 'blocked',
185
+ decisionSource: decision.command ? undefined : 'policy',
186
+ code: decision.code, durationMs: Date.now() - startedAt,
187
+ });
188
+ return { ok: false, code: decision.code, error: decision.reason };
189
+ }
190
+ const result = await execute(() => { executed = true; });
191
+ record({
192
+ eventPhase: 'response', executed,
193
+ executionState: result.ok ? 'completed' : executed ? 'failed' : 'blocked',
194
+ code: result.ok ? undefined : result.code,
195
+ errorCode: result.ok ? undefined : 'EXECUTION_FAILED',
196
+ durationMs: Date.now() - startedAt,
197
+ });
198
+ return result;
199
+ }
200
+ catch (error) {
201
+ record({
202
+ eventPhase: 'response', executed, executionState: executed ? 'failed' : 'blocked',
203
+ decision: executed ? 'allow' : 'pending',
204
+ decisionSource: executed ? 'command' : 'infrastructure',
205
+ errorCode: 'EXECUTION_FAILED', durationMs: Date.now() - startedAt,
206
+ });
207
+ throw error;
208
+ }
209
+ }
146
210
  export function authorizeOperation(params) {
147
211
  const access = authorizeAccess(params.subject);
148
212
  if (!access.allow) {
@@ -228,7 +292,7 @@ function resolveRoleDetail(input) {
228
292
  peerType: input.peerType,
229
293
  });
230
294
  }
231
- function auditDecision(params, decision) {
295
+ function auditDecision(params, decision, overrides) {
232
296
  const roleDenial = !decision.allow && decision.code === 'ROLE_ACCESS_DENIED';
233
297
  auditCommandAuthorization({
234
298
  ts: Date.now(),
@@ -278,5 +342,6 @@ function auditDecision(params, decision) {
278
342
  reason: decision.allow ? undefined : decision.reason,
279
343
  matchedRule: decision.matchedRule,
280
344
  argsSummary: params.intent.args,
345
+ ...Object.fromEntries(Object.entries(overrides ?? {}).filter(([, value]) => value !== undefined)),
281
346
  });
282
347
  }
@@ -5,14 +5,25 @@ import crypto from 'node:crypto';
5
5
  import { buildAuthorizationEventKey, buildToolLifecycleEventKey, normalizeToolCorrelation } from '../audit/event-key.js';
6
6
  import { normalizeExecutionPermissionMode } from '../permission/mode.js';
7
7
  import { normalizeToolErrorClassification } from '../permission/tool-error-code.js';
8
+ function permissionAuditDetails(input) {
9
+ return Object.fromEntries(Object.entries({
10
+ approvalRequestId: input.approvalRequestId,
11
+ approverOperatorId: input.approverOperatorId,
12
+ approverChannelKey: input.approverChannelKey,
13
+ approverPrincipalId: input.approverPrincipalId,
14
+ }).filter((entry) => typeof entry[1] === 'string'));
15
+ }
8
16
  export function auditCommandAuthorization(event) {
9
17
  const shouldAudit = event.source === 'menu.cli' ||
10
18
  event.decision === 'deny' ||
11
19
  (event.decision === 'allow' && event.dangerous) ||
12
20
  (event.source === 'agent-tool' && event.operation.startsWith('config.')) ||
21
+ (event.source === 'agent-tool' && event.decisionSource === 'command'
22
+ && (event.eventPhase === 'request' || event.eventPhase === 'response'
23
+ || (event.eventPhase === 'final' && !!event.requestId))) ||
13
24
  event.operation === 'codex.approval' ||
14
25
  event.operation === 'permission.approval' ||
15
- event.operation === 'permission.runtime' ||
26
+ event.operation.startsWith('permission.runtime') ||
16
27
  event.operation.startsWith('fullaccess.') ||
17
28
  event.operation.startsWith('role.') ||
18
29
  event.operation === 'file.root.storage' ||
@@ -180,15 +191,17 @@ export function auditCodexApprovalDecision(input) {
180
191
  approvalMethod: input.method,
181
192
  policyCode: input.policyCode,
182
193
  protectionClass: protectionClassForPolicy(input.policyCode),
194
+ parseFailure: sanitizeParseFailure(input.parseFailure),
183
195
  reason: input.reason,
184
196
  role: input.role ?? 'unknown',
185
197
  taskId: input.taskId,
186
198
  argsSummary: {
199
+ ...permissionAuditDetails(input),
187
200
  method: input.method,
188
201
  ...(input.summary ? { summary: input.summary } : {}),
189
202
  ...(input.threadId ? { threadId: input.threadId } : {}),
190
203
  ...(input.cwd ? { cwd: input.cwd } : {}),
191
- ...(input.parseFailure ? { parseFailure: input.parseFailure } : {}),
204
+ ...(input.parseFailure ? { parseFailure: sanitizeParseFailure(input.parseFailure) } : {}),
192
205
  },
193
206
  });
194
207
  }
@@ -200,6 +213,7 @@ export function auditCodexApprovalDecision(input) {
200
213
  export function auditPermissionDecision(input) {
201
214
  const requestId = input.requestId ?? `perm-audit-${crypto.randomUUID()}`;
202
215
  auditPermissionLifecycle({
216
+ ...input,
203
217
  phase: 'final',
204
218
  requestId,
205
219
  callId: input.callId,
@@ -244,6 +258,7 @@ export function auditPermissionLifecycle(input) {
244
258
  approvalMethod: input.approvalMethod,
245
259
  policyCode: input.policyCode,
246
260
  decisionSource: input.decisionSource,
261
+ errorDetailCode: input.errorDetailCode,
247
262
  errorCode: input.decision === 'deny'
248
263
  ? input.decisionSource === 'approval'
249
264
  ? 'USER_DENIED'
@@ -257,8 +272,9 @@ export function auditPermissionLifecycle(input) {
257
272
  dangerous: false,
258
273
  role: input.role ?? 'unknown',
259
274
  taskId: input.taskId,
260
- argsSummary: input.summary || input.response
275
+ argsSummary: input.summary || input.response || Object.keys(permissionAuditDetails(input)).length
261
276
  ? {
277
+ ...permissionAuditDetails(input),
262
278
  ...(input.summary ? { summary: input.summary } : {}),
263
279
  ...(input.response ? { response: input.response } : {}),
264
280
  }
@@ -267,9 +283,9 @@ export function auditPermissionLifecycle(input) {
267
283
  executed: false,
268
284
  executionState: input.phase === 'request'
269
285
  ? 'requested'
270
- : input.phase === 'response'
271
- ? 'responded'
272
- : input.decision === 'deny' ? 'blocked' : 'authorized',
286
+ : input.decision === 'deny'
287
+ ? 'blocked'
288
+ : input.phase === 'response' ? 'responded' : 'authorized',
273
289
  reason: input.reason,
274
290
  });
275
291
  }
@@ -280,14 +296,14 @@ export function auditToolInfrastructureFailure(input) {
280
296
  eventKey: buildToolLifecycleEventKey(input),
281
297
  eventPhase: 'final',
282
298
  source: 'agent-tool',
283
- operation: 'tool.execution.blocked',
299
+ operation: input.fallback ? 'permission.runtime.sandbox_fallback' : 'tool.execution.blocked',
284
300
  scope: 'filesystem',
285
301
  dangerous: false,
286
- decision: 'deny',
302
+ decision: input.fallback ? 'allow' : 'deny',
287
303
  decisionSource: 'infrastructure',
288
304
  errorCode: infrastructureErrorCode(input.policyCode),
289
305
  executed: false,
290
- executionState: 'blocked',
306
+ executionState: input.fallback ? 'authorized' : 'blocked',
291
307
  ...normalizeToolCorrelation(input),
292
308
  sessionId: input.sessionId ?? 'unknown',
293
309
  agentAid: input.agentAid ?? 'unknown',
@@ -301,6 +317,7 @@ export function auditToolInfrastructureFailure(input) {
301
317
  argsSummary: input.occurrences || input.sandboxFailure
302
318
  ? {
303
319
  ...(input.occurrences ? { occurrences: input.occurrences } : {}),
320
+ ...(input.fallback ? { sandboxFallback: true } : {}),
304
321
  // Flat primitive fields survive the audit argument redactor and can
305
322
  // be aggregated without reparsing (possibly truncated) stderr.
306
323
  ...(input.sandboxFailure ? {
@@ -316,6 +333,8 @@ export function auditToolInfrastructureFailure(input) {
316
333
  });
317
334
  }
318
335
  function infrastructureErrorCode(policyCode) {
336
+ if (policyCode === 'approval_expired' || policyCode === 'approval_timeout')
337
+ return 'APPROVAL_TIMEOUT';
319
338
  const code = String(policyCode ?? '').toLowerCase();
320
339
  if (/delegat|carrier|not.?armed/.test(code))
321
340
  return 'DELEGATION_FAILED';
@@ -390,9 +409,11 @@ function buildAuditRecord(event) {
390
409
  requestId,
391
410
  sourceRequestId,
392
411
  sessionId: event.sessionId,
393
- ...(event.source === 'ecweb' && !event.sessionId ? { sessionScope: 'not_applicable' } : {}),
412
+ ...(!event.sessionId ? {
413
+ sessionScope: event.source === 'ecweb' ? 'not_applicable' : 'unknown',
414
+ } : {}),
394
415
  agentAid: redactIdentifier(event.agentAid ?? event.selfAid),
395
- agentName: resolveAgentName(event),
416
+ agentName: resolveAgentName(event) ?? 'unknown',
396
417
  permissionMode: normalizeAuditPermissionMode(event.permissionMode),
397
418
  toolName: event.toolName,
398
419
  approvalMethod: event.approvalMethod,
@@ -403,6 +424,7 @@ function buildAuditRecord(event) {
403
424
  policyCode: event.policyCode ?? event.code,
404
425
  protectionClass: event.protectionClass,
405
426
  matchedPath: event.matchedPath,
427
+ parseFailure: sanitizeParseFailure(event.parseFailure),
406
428
  decisionSource,
407
429
  ecwebRequestId: event.ecwebRequestId,
408
430
  targetAgentAid: redactIdentifier(event.targetAgentAid),
@@ -449,6 +471,22 @@ function namespaceAuditRequestId(source, sessionId, sourceRequestId) {
449
471
  const parts = [...namespace, sourceRequestId].map(part => encodeURIComponent(JSON.stringify(part).slice(1, -1)));
450
472
  return `audit:v1:${parts.join(':')}`;
451
473
  }
474
+ function sanitizeParseFailure(value) {
475
+ if (!value || typeof value !== 'object')
476
+ return undefined;
477
+ const candidate = value;
478
+ const issues = ['empty-command', 'invalid-control-char', 'unsafe-expansion', 'invalid-quote',
479
+ 'structural-newline', 'unsupported-escape', 'lossy-cmd-shim', 'shell-composition', 'untrusted-shell'];
480
+ if (typeof candidate.issue !== 'string' || !issues.includes(candidate.issue)
481
+ || typeof candidate.dialect !== 'string' || !['posix', 'powershell', 'cmd'].includes(candidate.dialect))
482
+ return undefined;
483
+ const { offset, tokenIndex, inputLength } = candidate;
484
+ if (typeof offset !== 'number' || typeof tokenIndex !== 'number' || typeof inputLength !== 'number'
485
+ || ![offset, tokenIndex, inputLength].every(value => Number.isSafeInteger(value) && value >= 0)
486
+ || offset > inputLength || tokenIndex > inputLength)
487
+ return undefined;
488
+ return { issue: candidate.issue, dialect: candidate.dialect, offset, tokenIndex, inputLength };
489
+ }
452
490
  function resolveAgentName(event) {
453
491
  const displayName = typeof event.agentName === 'string' ? event.agentName.trim() : '';
454
492
  if (displayName && !isUnknownAgentLabel(displayName))
@@ -459,6 +497,14 @@ function resolveAgentName(event) {
459
497
  const selfAid = typeof event.selfAid === 'string' ? event.selfAid.trim() : '';
460
498
  if (selfAid && selfAid !== 'unknown')
461
499
  return selfAid;
500
+ const targetAgentAid = event.source === 'ecweb' && typeof event.targetAgentAid === 'string'
501
+ ? event.targetAgentAid.trim() : '';
502
+ if (targetAgentAid && targetAgentAid !== 'unknown')
503
+ return targetAgentAid;
504
+ const actorId = event.source === 'ecweb' && typeof event.actorId === 'string'
505
+ ? event.actorId.trim() : '';
506
+ if (actorId && !isUnknownAgentLabel(actorId))
507
+ return actorId;
462
508
  return aid === 'unknown' || selfAid === 'unknown' ? 'unknown' : undefined;
463
509
  }
464
510
  function isUnknownAgentLabel(value) {
@@ -523,6 +569,7 @@ function logAuditEvent(record) {
523
569
  record.policyCode ? `policy=${record.policyCode}` : null,
524
570
  record.protectionClass ? `protectionClass=${record.protectionClass}` : null,
525
571
  record.matchedPath ? `matchedPath=${JSON.stringify(record.matchedPath)}` : null,
572
+ record.parseFailure ? `parseFailure=${JSON.stringify(record.parseFailure)}` : null,
526
573
  record.decisionSource ? `decisionSource=${record.decisionSource}` : null,
527
574
  `executed=${record.executed}`,
528
575
  `executionState=${record.executionState}`,
@@ -1,5 +1,5 @@
1
1
  import { authorizeFreshOperation as authorizeOperation, buildAuthSubject } from './auth-gateway.js';
2
- import { trustedExecutionIdentityInput } from './agent-delegation.js';
2
+ import { hasTrustedFullAccessDelegation, trustedExecutionIdentityInput } from './agent-delegation.js';
3
3
  import { isManagementRole } from '../../config/builtin-roles.js';
4
4
  import { parsePeerKey } from '../relation/peer-identity.js';
5
5
  export function createDelegationAuthorizer({ agentDelegationRegistry, sessionManager, getProcessOwners, }) {
@@ -40,7 +40,9 @@ export function createDelegationAuthorizer({ agentDelegationRegistry, sessionMan
40
40
  subject,
41
41
  intent: {
42
42
  operation,
43
- scope: operation === 'system.status' ? 'process' : 'agent',
43
+ scope: operation === 'system.status' || operation === 'proxy.configure' || operation === 'proxy.lifecycle'
44
+ ? 'process'
45
+ : 'agent',
44
46
  source: 'agent-tool',
45
47
  args: { self: delegation.grant.selfAid, aid: params.targetAid ?? delegation.grant.selfAid },
46
48
  },
@@ -51,6 +53,7 @@ export function createDelegationAuthorizer({ agentDelegationRegistry, sessionMan
51
53
  ok: true,
52
54
  aid: subject.dataScope === 'daemon' ? (params.targetAid ?? delegation.grant.selfAid) : delegation.grant.selfAid,
53
55
  dataScope: subject.dataScope,
56
+ fullAccess: hasTrustedFullAccessDelegation(delegation.grant),
54
57
  management: isManagementRole(subject.role),
55
58
  sessionRuntimeDir: delegation.grant.sessionRuntimeDir,
56
59
  }
@@ -1,6 +1,6 @@
1
1
  import { getRoleDefinition } from '../../config/roles.js';
2
2
  import { isManagementRole } from '../../config/builtin-roles.js';
3
- import { isUnsupportedBaseagentConfigField, relationFieldWriteOperation, resolveRoleFieldPermission, } from '../../config/config-field-policy.js';
3
+ import { isAgentOnlyBaseagentField, isUnsupportedBaseagentConfigField, relationFieldWriteOperation, resolveRoleFieldPermission, } from '../../config/config-field-policy.js';
4
4
  import { isResolvedConfigMutation, } from '../../config/resolved-config-op.js';
5
5
  import { normalizePeer } from '../model/config-scope.js';
6
6
  import { getOperationMeta } from './operation-catalog.js';
@@ -45,6 +45,11 @@ const DAEMON_OWNER_MODEL_OPTION_READ_OPERATIONS = new Set([
45
45
  'model.list',
46
46
  'model.effort.current',
47
47
  ]);
48
+ const MODEL_WRITE_OPERATIONS = new Set([
49
+ 'model.use',
50
+ 'model.effort',
51
+ 'model.reset',
52
+ ]);
48
53
  export function authorizeCommand(ctx) {
49
54
  return authorizeCommandInternal(ctx);
50
55
  }
@@ -98,6 +103,14 @@ function authorizeCommandInternal(ctx, resolvedConfigCommand) {
98
103
  if (!opMeta) {
99
104
  return denyDecision(ctx, 'NOT_ALLOWED', `Unknown operation: ${operation}`, operation, intent.scope);
100
105
  }
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
+ }
101
114
  if (isFieldConfigOperation(operation) && !resolvedConfigCommand) {
102
115
  return denyDecision(ctx, 'NOT_ALLOWED', 'Resolved config operation is required', operation, intent.scope, opMeta.dangerous);
103
116
  }
@@ -116,7 +129,10 @@ function authorizeCommandInternal(ctx, resolvedConfigCommand) {
116
129
  // but relation/Agent role rules, source lists, and daemon-owner gates are
117
130
  // not meaningful limits for code already approved for host-level execution.
118
131
  if (ctx.processRole === 'fullaccess-run' && ctx.dataScope === 'daemon'
119
- && operation !== 'ec.aid.bind' && operation !== 'ec.aid.bind.status') {
132
+ && operation !== 'ec.aid.bind' && operation !== 'ec.aid.transfer' && operation !== 'ec.aid.bind.status') {
133
+ if (operation === 'system.restart' || operation === 'system.upgrade') {
134
+ 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
+ }
120
136
  return {
121
137
  allow: true,
122
138
  operation,
@@ -137,12 +153,18 @@ function authorizeCommandInternal(ctx, resolvedConfigCommand) {
137
153
  if (!sourceAllowed) {
138
154
  return denyDecision(ctx, 'NOT_ALLOWED', `Operation ${operation} is not available from source ${ctx.source}`, operation, intent.scope, opMeta.dangerous);
139
155
  }
140
- if (operation === 'ec.aid.bind' || operation === 'ec.aid.bind.status') {
141
- const permitted = intent.scope === 'agent' && ctx.processRole !== 'fullaccess-run' && ctx.processRole !== 'daemon-service'
156
+ if (operation === 'ec.aid.bind.status') {
157
+ if (intent.scope !== 'agent') {
158
+ return denyDecision(ctx, 'NOT_ALLOWED', 'Ownership status is only available for an Agent subject', operation, intent.scope, opMeta.dangerous);
159
+ }
160
+ return { allow: true, operation, scope: intent.scope, role, dangerous: opMeta.dangerous, matchedRule: 'ownership-status-read' };
161
+ }
162
+ if (operation === 'ec.aid.bind' || operation === 'ec.aid.transfer') {
163
+ const permitted = intent.scope === 'agent' && ctx.processRole !== 'daemon-service'
142
164
  && (ctx.isDaemonOwner === true || ctx.processRole === 'daemon-owner'
143
- || (isCurrentAgentTarget(ctx) && (role === 'owner' || (operation === 'ec.aid.bind.status' && role === 'admin'))));
165
+ || (isCurrentAgentTarget(ctx) && role === 'owner'));
144
166
  if (!permitted)
145
- return denyDecision(ctx, 'NOT_ALLOWED', 'Protocol Owner binding requires the subject Owner or daemon Owner', operation, intent.scope, opMeta.dangerous);
167
+ return denyDecision(ctx, 'NOT_ALLOWED', 'Protocol Owner binding or transfer requires the subject Owner or daemon Owner', operation, intent.scope, opMeta.dangerous);
146
168
  return { allow: true, operation, scope: intent.scope, role, dangerous: opMeta.dangerous, matchedRule: 'protocol-owner-binding' };
147
169
  }
148
170
  if (ctx.processRole === 'daemon-service') {
@@ -212,6 +234,16 @@ function authorizeCommandInternal(ctx, resolvedConfigCommand) {
212
234
  matchedRule: 'daemon-owner-model-options-read',
213
235
  };
214
236
  }
237
+ // 模型参数只在 Agent 级:写操作只能落 agent scope,且只有该 Agent 的 owner/admin
238
+ // (或 DaemonOwner)能改。这是代码级上限,角色文件授予 model.* 也不能越过。
239
+ if (MODEL_WRITE_OPERATIONS.has(operation)) {
240
+ if (intent.scope !== 'agent') {
241
+ return denyDecision(ctx, 'SCOPE_MISMATCH', '模型参数只能在 Agent 级配置,不支持关系级设置', operation, intent.scope, opMeta.dangerous);
242
+ }
243
+ if (!hasDaemonOwnerRole(ctx) && !(isManagementRole(role) && isCurrentAgentTarget(ctx))) {
244
+ return denyDecision(ctx, 'NOT_ALLOWED', '只有当前 Agent 的 owner/admin 可以修改模型', operation, intent.scope, opMeta.dangerous);
245
+ }
246
+ }
215
247
  if (requiresDaemonOwner(ctx, resolvedConfigCommand)) {
216
248
  if (!hasDaemonOwnerRole(ctx)) {
217
249
  const reasonCode = daemonOwnerDenialReasonCode(ctx);
@@ -660,6 +692,11 @@ function checkConfigFieldPolicy(ctx, policy, resolvedConfigOp) {
660
692
  return { ok: false, reason: 'Resolved config operation is required' };
661
693
  const field = resolvedConfigOp.field;
662
694
  if (!resolvedConfigOp.route || (resolvedConfigOp.fieldRule.class !== 'safe-scalar' && resolvedConfigOp.fieldRule.class !== 'safe-readonly-object')) {
695
+ if (policy === 'behavior-read'
696
+ && resolvedConfigOp.configScope === 'relation'
697
+ && isAgentOnlyBaseagentField(field)) {
698
+ return { ok: true };
699
+ }
663
700
  if (policy === 'behavior-read'
664
701
  && !isCurrentAgentTarget(ctx)
665
702
  && hasDaemonOwnerRole(ctx)
@@ -128,7 +128,40 @@ const QUEUE_OPERATIONS = [['read', 'Read the current Agent message queue'], ['cl
128
128
  *
129
129
  * 参照设计文档 docs/command-execution-role-permission-design.md 第 5 节
130
130
  */
131
+ const PROVIDER_OPERATIONS = ['list', 'show', 'create', 'import', 'update', 'delete'].map(action => ({
132
+ id: 'provider.' + action,
133
+ category: action === 'list' || action === 'show' ? 'read' : 'process',
134
+ dangerous: action !== 'list' && action !== 'show',
135
+ defaultScopes: ['process'],
136
+ description: 'Manage the daemon Provider registry: ' + action,
137
+ sources: ['menu', 'control', 'ecweb'],
138
+ }));
131
139
  const OPERATIONS = [
140
+ ...PROVIDER_OPERATIONS,
141
+ {
142
+ id: 'proxy.read',
143
+ category: 'read',
144
+ dangerous: false,
145
+ defaultScopes: ['agent'],
146
+ description: '查看当前 daemon 的本地服务与 ServiceProxy 状态',
147
+ sources: ['agent-tool'],
148
+ },
149
+ {
150
+ id: 'proxy.configure',
151
+ category: 'process',
152
+ dangerous: true,
153
+ defaultScopes: ['process'],
154
+ description: '创建、修改、发布或删除本地服务代理配置',
155
+ sources: ['agent-tool'],
156
+ },
157
+ {
158
+ id: 'proxy.lifecycle',
159
+ category: 'process',
160
+ dangerous: true,
161
+ defaultScopes: ['process'],
162
+ description: '启动、停止、重载或守护本地服务',
163
+ sources: ['agent-tool'],
164
+ },
132
165
  // ── Model Operations ──
133
166
  {
134
167
  id: 'baseagent.models.list',
@@ -178,28 +211,29 @@ const OPERATIONS = [
178
211
  description: '检查模型可用性(可能触发网关探测)',
179
212
  sources: ['slash', 'menu.cli', 'agent-tool'],
180
213
  },
214
+ // 模型参数只在 Agent 级配置,仅 owner/admin 可写(operation-authorizer 另有代码级上限)。
181
215
  {
182
216
  id: 'model.use',
183
217
  category: 'write-own',
184
218
  dangerous: false,
185
- defaultScopes: ['relation', 'role', 'agent'],
186
- description: '切换使用的模型',
219
+ defaultScopes: ['agent'],
220
+ description: '设置 Agent 使用的模型',
187
221
  sources: ['slash', 'menu', 'menu.cli', 'agent-tool'],
188
222
  },
189
223
  {
190
224
  id: 'model.effort',
191
225
  category: 'write-own',
192
226
  dangerous: false,
193
- defaultScopes: ['relation', 'role', 'agent'],
194
- description: '设置推理努力度',
227
+ defaultScopes: ['agent'],
228
+ description: '设置 Agent 的推理强度',
195
229
  sources: ['slash', 'menu', 'menu.cli', 'agent-tool'],
196
230
  },
197
231
  {
198
232
  id: 'model.reset',
199
233
  category: 'write-own',
200
234
  dangerous: false,
201
- defaultScopes: ['relation', 'role', 'agent'],
202
- description: '重置模型配置到角色默认值',
235
+ defaultScopes: ['agent'],
236
+ description: '清除 Agent 的模型与推理强度设置',
203
237
  sources: ['slash', 'menu.cli', 'agent-tool'],
204
238
  },
205
239
  // ── Session Operations ──
@@ -1149,9 +1183,13 @@ const OPERATIONS = [
1149
1183
  id: 'ec.aid.bind', category: 'write-agent', dangerous: true, defaultScopes: ['agent'],
1150
1184
  description: 'Request or decide a protocol Owner binding using the subject SDK client', sources: ['agent-tool', 'menu.cli'],
1151
1185
  },
1186
+ {
1187
+ id: 'ec.aid.transfer', category: 'write-agent', dangerous: true, defaultScopes: ['agent'],
1188
+ description: 'Transfer a protocol Owner relationship to a new Owner using the subject SDK client', sources: ['agent-tool', 'menu.cli'],
1189
+ },
1152
1190
  {
1153
1191
  id: 'ec.aid.bind.status', category: 'read', dangerous: false, defaultScopes: ['agent'],
1154
- description: 'Refresh the protocol Owner consensus and binding task projection', sources: ['agent-tool', 'menu.cli'],
1192
+ description: 'Read the protocol Owner consensus and binding task projection; status --refresh forces a fresh query', sources: ['agent-tool', 'menu.cli'],
1155
1193
  },
1156
1194
  {
1157
1195
  id: 'ec.aid.lookup',
@@ -6,6 +6,7 @@
6
6
  * The main service (index.ts) handles registration and message flow wiring.
7
7
  */
8
8
  import { logger } from '../utils/logger.js';
9
+ import { assertAgentAidAvailable } from '../config/config-manager.js';
9
10
  // ── Shared helpers for plugins ─────────────────────────────────────────────
10
11
  /** Resolve showActivities for a single instance (instance overrides default). */
11
12
  export function resolveShowActivities(inst) {
@@ -49,6 +50,7 @@ export class ChannelLoader {
49
50
  * AUN is always created implicitly from agent.aid (no explicit entry required).
50
51
  */
51
52
  async createForAgent(agent) {
53
+ assertAgentAidAvailable(agent.aid);
52
54
  const ctx = {
53
55
  agentName: agent.aid,
54
56
  defaultProjectPath: agent.config.projects?.defaultPath ?? process.cwd(),