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
@@ -101,6 +101,7 @@ function readProviderInput(file) {
101
101
  fs.closeSync(descriptor);
102
102
  }
103
103
  }
104
+ /** Standalone IPC callers have already presented the local control token. */
104
105
  export async function executeProviderOperation(command) {
105
106
  try {
106
107
  const parsed = parseProviderCommand(command.argv);
@@ -109,6 +110,15 @@ export async function executeProviderOperation(command) {
109
110
  actorId: 'local-control', role: 'daemon-owner', processRole: 'daemon-owner', dataScope: 'daemon',
110
111
  isDaemonOwner: true, fromControlChannel: true, decision: 'allow', executed: false,
111
112
  argsSummary: parsed.providerId ? { providerId: parsed.providerId } : {}, matchedRule: 'local-control-token' });
113
+ return executeParsedProviderOperation(parsed);
114
+ }
115
+ catch (error) {
116
+ return providerFailure(error);
117
+ }
118
+ }
119
+ /** Shared business execution; callers must authorize before reading input files. */
120
+ export async function executeParsedProviderOperation(parsed) {
121
+ try {
112
122
  const text = parsed.file ? readProviderInput(parsed.file) : undefined;
113
123
  const snapshot = readProvidersSnapshot();
114
124
  if (parsed.operation === 'list')
@@ -76,6 +76,15 @@ const FIXED_STYLES = {
76
76
  codex: 'codex',
77
77
  gemini: 'gemini',
78
78
  };
79
+ export function validateProviderName(value) {
80
+ if (typeof value !== 'string')
81
+ throw new Error('Provider name must be a string');
82
+ const name = value.trim();
83
+ if (name.length < 2 || name.length > 20 || !/^[\p{L}\p{N} _-]+$/u.test(name)) {
84
+ throw new Error('Provider name must be 2–20 characters and contain only letters, numbers, spaces, hyphens, or underscores');
85
+ }
86
+ return name;
87
+ }
79
88
  function isRecord(value) {
80
89
  return !!value && typeof value === 'object' && !Array.isArray(value);
81
90
  }
@@ -245,7 +254,7 @@ export function validateProvidersFile(value) {
245
254
  providers,
246
255
  };
247
256
  }
248
- export function resolveProviderService(providerId, serviceType, config) {
257
+ export function resolveProviderService(providerId, serviceType, config, defaultStyle = 'systemone') {
249
258
  assertSafeRegistrySegment(providerId, 'provider id');
250
259
  assertSafeRegistrySegment(serviceType, 'service type');
251
260
  const providers = config.providers;
@@ -256,7 +265,7 @@ export function resolveProviderService(providerId, serviceType, config) {
256
265
  if (!service)
257
266
  throw new Error(`Provider ${providerId} has no service: ${serviceType}`);
258
267
  const fixedStyle = Object.hasOwn(FIXED_STYLES, serviceType) ? FIXED_STYLES[serviceType] : undefined;
259
- const style = fixedStyle || service.style || 'openai-compatible';
268
+ const style = fixedStyle || service.style || defaultStyle;
260
269
  if (fixedStyle && service.style && service.style !== fixedStyle) {
261
270
  throw new Error(`Provider ${providerId} service ${serviceType} must use style ${fixedStyle}`);
262
271
  }
@@ -288,7 +297,7 @@ export function resolveProviderService(providerId, serviceType, config) {
288
297
  export function resolveProviderServiceForBaseagent(providerId, baseagent, preferredServiceType, config) {
289
298
  const provider = Object.hasOwn(config.providers, providerId) ? config.providers[providerId] : undefined;
290
299
  const serviceType = resolveProviderServiceTypeForBaseagent(baseagent, preferredServiceType, provider);
291
- return resolveProviderService(providerId, serviceType, config);
300
+ return resolveProviderService(providerId, serviceType, config, 'openai-compatible');
292
301
  }
293
302
  export function resolveProviderModelOverrides(providerId, serviceType, config, baseagent) {
294
303
  assertSafeRegistrySegment(providerId, 'provider id');
@@ -5,7 +5,7 @@ import { resolvePaths } from '../paths.js';
5
5
  import { ConfigTarget, mutateConfig } from './config-manager.js';
6
6
  import { atomicReadJson } from '../utils/atomic-write.js';
7
7
  import { readProvidersFile, validateProvidersFile } from './providers.js';
8
- import { providerEnvironmentVariable, providerNameFromBaseUrlIfStatic, resolveProviderService, resolveProviderServiceForBaseagent } from './providers-config.js';
8
+ import { providerEnvironmentVariable, providerNameFromBaseUrlIfStatic, resolveProviderService, resolveProviderServiceForBaseagent, validateProviderName } from './providers-config.js';
9
9
  export const PROVIDER_SECRET_MASK = '<redacted>';
10
10
  function providerReferences(providerId, providerFile) {
11
11
  const root = path.dirname(path.resolve(providerFile));
@@ -87,6 +87,24 @@ export function providersRevision(value) {
87
87
  export function readProvidersSnapshot(file = resolvePaths().providersConfig) {
88
88
  return providersSnapshot(readProvidersFile(file));
89
89
  }
90
+ export function readProviderForExport(providerId, serviceType, file = resolvePaths().providersConfig, includeApiKey = false) {
91
+ if (!/^[A-Za-z0-9_-]+$/u.test(providerId) || ['__proto__', 'constructor', 'prototype'].includes(providerId))
92
+ throw new Error('Invalid provider identifier');
93
+ if (serviceType !== undefined && (!/^[A-Za-z0-9_-]+$/u.test(serviceType) || ['__proto__', 'constructor', 'prototype'].includes(serviceType)))
94
+ throw new Error('Invalid service type');
95
+ const provider = readProvidersFile(file).providers[providerId];
96
+ if (!provider)
97
+ throw Object.assign(new Error('Provider not found'), { statusCode: 404 });
98
+ const exported = structuredClone(provider);
99
+ if (!includeApiKey)
100
+ delete exported.common.apiKey;
101
+ if (serviceType === undefined)
102
+ return exported;
103
+ const service = provider.services?.[serviceType];
104
+ if (!service)
105
+ throw Object.assign(new Error('Service type not found'), { statusCode: 404 });
106
+ return { ...exported, services: { [serviceType]: structuredClone(service) } };
107
+ }
90
108
  function providersSnapshot(value) {
91
109
  const providers = structuredClone(value.providers);
92
110
  for (const provider of Object.values(providers)) {
@@ -166,6 +184,8 @@ export async function updateProvider(input, file = resolvePaths().providersConfi
166
184
  else {
167
185
  const value = retainSecrets(input.value, current.providers[input.providerId]);
168
186
  const normalized = validateProvidersFile({ providers: { [input.providerId]: value } });
187
+ if (normalized.providers[input.providerId].name !== undefined)
188
+ normalized.providers[input.providerId].name = validateProviderName(normalized.providers[input.providerId].name);
169
189
  current.providers[input.providerId] = normalized.providers[input.providerId];
170
190
  }
171
191
  return current;
@@ -247,6 +267,8 @@ export async function createProvider(input, file = resolvePaths().providersConfi
247
267
  rejectMaskedImportSecrets(normalized.providers);
248
268
  const provider = normalized.providers.imported;
249
269
  provider.name ||= providerNameFromBaseUrlIfStatic(provider.common.baseUrl);
270
+ if (provider.name !== undefined)
271
+ provider.name = validateProviderName(provider.name);
250
272
  const result = mutateConfig(ConfigTarget.Providers, { providerFile: file }, config => {
251
273
  const current = config;
252
274
  if (providersRevision(current) !== input.revision) {
@@ -265,7 +287,7 @@ function providerHostname(baseUrl) {
265
287
  return undefined;
266
288
  return new URL(baseUrl).hostname.toLowerCase().replace(/\.$/u, '');
267
289
  }
268
- function mergeImportedProvider(existing, imported) {
290
+ function mergeImportedProvider(existing, imported, replaceServiceTypes = new Set()) {
269
291
  const services = structuredClone(existing.services || {});
270
292
  const existingVariable = providerEnvironmentVariable(existing.common.baseUrl);
271
293
  const importedVariable = providerEnvironmentVariable(imported.common.baseUrl);
@@ -274,7 +296,7 @@ function mergeImportedProvider(existing, imported) {
274
296
  throw new Error('Cannot merge Providers with different environment-variable base URLs');
275
297
  }
276
298
  for (const [serviceType, service] of Object.entries(imported.services || {})) {
277
- if (!Object.hasOwn(services, serviceType))
299
+ if (replaceServiceTypes.has(serviceType) || !Object.hasOwn(services, serviceType))
278
300
  services[serviceType] = structuredClone(service);
279
301
  }
280
302
  return {
@@ -288,7 +310,7 @@ function mergeImportedProvider(existing, imported) {
288
310
  }
289
311
  const baseUrl = new URL(existing.common.baseUrl);
290
312
  for (const [serviceType, service] of Object.entries(imported.services || {})) {
291
- if (Object.hasOwn(services, serviceType))
313
+ if (Object.hasOwn(services, serviceType) && !replaceServiceTypes.has(serviceType))
292
314
  continue;
293
315
  const endpoint = new URL(resolveProviderService('imported', serviceType, { providers: { imported } }).baseUrl);
294
316
  if (baseUrl.protocol !== endpoint.protocol || baseUrl.port !== endpoint.port || providerHostname(baseUrl.href) !== providerHostname(endpoint.href)) {
@@ -360,6 +382,8 @@ export async function saveProviderChanges(input, file = resolvePaths().providers
360
382
  const previous = change.create ? undefined : current.providers[change.providerId];
361
383
  const provider = resolveDraftProvider(change.value, previous, change.imports);
362
384
  provider.name ||= providerNameFromBaseUrlIfStatic(provider.common.baseUrl);
385
+ if (provider.name !== undefined)
386
+ provider.name = validateProviderName(provider.name);
363
387
  const providerId = change.create ? `provider-${nextProviderSequence(current)}` : change.providerId;
364
388
  if (change.create)
365
389
  current.nextId = Number(providerId.slice('provider-'.length)) + 1;
@@ -377,18 +401,30 @@ export async function importOrMergeBaseagentProvider(input, file = resolvePaths(
377
401
  rejectMaskedImportSecrets(normalized.providers);
378
402
  const imported = normalized.providers.imported;
379
403
  imported.name ||= providerNameFromBaseUrlIfStatic(imported.common.baseUrl);
404
+ if (input.name !== undefined)
405
+ imported.name = validateProviderName(input.name);
406
+ if (input.resolution === 'cancel')
407
+ throw Object.assign(new Error('Provider import cancelled'), { code: 'CANCELLED', statusCode: 409 });
380
408
  const result = mutateConfig(ConfigTarget.Providers, { providerFile: file }, config => {
381
409
  const current = config;
382
410
  if (providersRevision(current) !== input.revision) {
383
411
  throw Object.assign(new Error('Providers changed after loading; reload before saving'), { code: 'CONFLICT', statusCode: 409, data: { kind: 'revision_conflict' } });
384
412
  }
385
413
  const importedHost = providerHostname(imported.common.baseUrl);
386
- const match = importedHost
387
- ? Object.entries(current.providers).find(([, provider]) => providerHostname(provider.common.baseUrl) === importedHost)
388
- : undefined;
389
- if (match) {
414
+ const importedName = imported.name?.trim().toLowerCase();
415
+ const match = Object.entries(current.providers).find(([, provider]) => (!!importedName && provider.name?.trim().toLowerCase() === importedName)
416
+ || (!!importedHost && providerHostname(provider.common.baseUrl) === importedHost));
417
+ if (match && input.requireResolution && input.resolution === undefined) {
418
+ const [providerId, existing] = match;
419
+ throw Object.assign(new Error('Provider conflict requires an explicit resolution'), {
420
+ code: 'PROVIDER_CONFLICT', statusCode: 409,
421
+ data: { kind: 'provider_conflict', providerId, overlaps: Object.keys(imported.services || {}).filter(type => Object.hasOwn(existing.services || {}, type)) },
422
+ });
423
+ }
424
+ if (match && input.resolution !== 'create') {
390
425
  const [providerId, existing] = match;
391
- current.providers[providerId] = validateProvidersFile({ providers: { [providerId]: mergeImportedProvider(existing, imported) } }).providers[providerId];
426
+ const replaceServiceTypes = new Set(Object.entries(input.serviceDecisions || {}).filter(([, decision]) => decision === 'imported').map(([type]) => type));
427
+ current.providers[providerId] = validateProvidersFile({ providers: { [providerId]: mergeImportedProvider(existing, imported, replaceServiceTypes) } }).providers[providerId];
392
428
  return { current, providerId, merged: true };
393
429
  }
394
430
  const sequence = nextProviderSequence(current);
@@ -1542,40 +1542,57 @@ export async function ensureRelationConfigVersionMigrationOnStartup() {
1542
1542
  throw new ConfigError('RELATION_CONFIG_VERSION_MIGRATION_FAILED', `Automatic relation-config version migration failed: ${detail}`, { cause: error });
1543
1543
  }
1544
1544
  }
1545
- // ── Agent 消息准入重写:v16 → v17 ────────────────────────────────────────────
1546
- const ACCESS_POLICY_TARGET_VERSION = 17;
1545
+ // ── Agent 消息准入重写:v16 → v17 → v18 ──────────────────────────────────────
1546
+ const ACCESS_POLICY_TARGET_VERSION = 18;
1547
1547
  /**
1548
- * 旧三态 `policyMode` + 两个名录开关 → 新三档开关。
1548
+ * 旧三态 `policyMode` + 两个名录开关 → 新开关。
1549
1549
  *
1550
1550
  * - `owners` → 三档全关,等价于"只收 Owner 与个人助理"。
1551
- * - `open` → 打开陌生人档;内部档保持开启。
1551
+ * - `open` → 打开总开关 `allowAllContacts`,等价于"谁都能进";内部档保持开启。
1552
1552
  * - `contacts`→ 旧语义是"Owner + 本地联系人簿的 active 联系人"。三档里没有对应位置,
1553
1553
  * 因此把该 Agent 本地联系人簿里的 active 条目提升进 `allowedAids`,
1554
1554
  * 避免升级后突然丢联系人;其余按最严格处理(三档全关)。
1555
1555
  * - 两个名录开关合并到 `allowInternalContacts`:都为显式 false 时才收紧内部档。
1556
1556
  *
1557
+ * v18 另做一次纯改名:`allowStrangerContacts` → `allowAllContacts`,取值原样搬过去。
1558
+ * 同名取值 `false` 时旧"陌生人档"与新的"总开关"都等价于不放行;取值 `true` 时
1559
+ * 旧语义只放行名录外主体,新语义压过三档——这是 v18 的有意放宽,不再保持逐档等价。
1560
+ *
1557
1561
  * `allowExternalContacts` 同名保留,语义从"普通外部发送者"收敛为"名录里的外部条目"。
1558
1562
  */
1559
1563
  function rewriteAccessPolicy(access, legacyContacts) {
1560
1564
  const removed = [];
1561
1565
  const migrated = [];
1562
1566
  const promoted = [];
1563
- if (!hasOwn(access, 'policyMode') && !hasOwn(access, 'allowOwnerDirectoryContacts')
1564
- && !hasOwn(access, 'allowOwnerAgentDirectory')) {
1565
- return { value: access, removed, migrated, promoted };
1566
- }
1567
- const mode = typeof access.policyMode === 'string' ? access.policyMode : undefined;
1568
- const ownerContacts = access.allowOwnerDirectoryContacts;
1569
- const ownerAgents = access.allowOwnerAgentDirectory;
1570
- const externalExplicit = typeof access.allowExternalContacts === 'boolean'
1571
- ? access.allowExternalContacts : undefined;
1572
- const value = { ...access };
1567
+ const renamed = [];
1568
+ // v18:陌生人档升格为压过三档的总开关,随之改名。先改名,后续 policyMode
1569
+ // 换算写的也是新字段,两步叠在同一个 value 上。
1570
+ let working = access;
1571
+ if (hasOwn(access, 'allowStrangerContacts')) {
1572
+ const { allowStrangerContacts, ...rest } = access;
1573
+ working = hasOwn(access, 'allowAllContacts')
1574
+ ? { ...rest }
1575
+ : { ...rest, allowAllContacts: allowStrangerContacts };
1576
+ renamed.push('allowStrangerContacts→allowAllContacts');
1577
+ }
1578
+ if (!hasOwn(working, 'policyMode') && !hasOwn(working, 'allowOwnerDirectoryContacts')
1579
+ && !hasOwn(working, 'allowOwnerAgentDirectory')) {
1580
+ return { value: working, removed, migrated, promoted, renamed };
1581
+ }
1582
+ const mode = typeof working.policyMode === 'string' ? working.policyMode : undefined;
1583
+ const ownerContacts = working.allowOwnerDirectoryContacts;
1584
+ const ownerAgents = working.allowOwnerAgentDirectory;
1585
+ const externalExplicit = typeof working.allowExternalContacts === 'boolean'
1586
+ ? working.allowExternalContacts : undefined;
1587
+ const value = { ...working };
1573
1588
  let internal = true;
1574
1589
  let external = externalExplicit ?? false;
1575
- let stranger = false;
1590
+ let allContacts = false;
1576
1591
  if (mode === 'open') {
1592
+ // 旧 open 的含义就是「谁都能进」:直接落到总开关,不必再逐档打开。
1577
1593
  internal = true;
1578
- stranger = true;
1594
+ external = true;
1595
+ allContacts = true;
1579
1596
  }
1580
1597
  else if (mode === 'contacts') {
1581
1598
  // 目标达成方式是旧联系人提升进白名单,三档本身保持最严格。
@@ -1616,17 +1633,17 @@ function rewriteAccessPolicy(access, legacyContacts) {
1616
1633
  value.allowedAids = Array.from(new Set([...existingAllowed, ...promoted]));
1617
1634
  value.allowInternalContacts = internal;
1618
1635
  value.allowExternalContacts = external;
1619
- value.allowStrangerContacts = stranger;
1636
+ value.allowAllContacts = allContacts;
1620
1637
  if (typeof value.$schema_version === 'number' && value.$schema_version < ACCESS_POLICY_TARGET_VERSION) {
1621
1638
  value.$schema_version = ACCESS_POLICY_TARGET_VERSION;
1622
1639
  }
1623
- return { value, removed, migrated, promoted };
1640
+ return { value, removed, migrated, promoted, renamed };
1624
1641
  }
1625
1642
  function planAccessPolicyMigration(home) {
1626
1643
  const changes = [];
1627
1644
  const details = [];
1628
1645
  const summary = {
1629
- configsScanned: 0, filesChanged: 0, modesConverted: 0, promotedContacts: 0, fieldsRemoved: 0,
1646
+ configsScanned: 0, filesChanged: 0, modesConverted: 0, promotedContacts: 0, fieldsRemoved: 0, fieldsRenamed: 0,
1630
1647
  };
1631
1648
  const agentsRoot = path.join(home, 'agents');
1632
1649
  if (!fs.existsSync(agentsRoot))
@@ -1653,7 +1670,7 @@ function planAccessPolicyMigration(home) {
1653
1670
  continue;
1654
1671
  const access = isRecord(parsed.value.access) ? parsed.value.access : undefined;
1655
1672
  if (!access) {
1656
- // 没写过 access:只补版本号,读取层会套用 v17 默认值。
1673
+ // 没写过 access:只补版本号,读取层会套用当前版本默认值。
1657
1674
  if (nowVersion === ACCESS_POLICY_TARGET_VERSION)
1658
1675
  continue;
1659
1676
  const next = { ...parsed.value, $schema_version: ACCESS_POLICY_TARGET_VERSION };
@@ -1682,20 +1699,21 @@ function planAccessPolicyMigration(home) {
1682
1699
  const nextText = jsonText(nextAgent);
1683
1700
  if (nextText === parsed.text)
1684
1701
  continue;
1685
- const migrated = [...result.migrated];
1702
+ const migrated = [...result.migrated, ...result.renamed];
1686
1703
  if (result.promoted.length)
1687
1704
  migrated.push(`allowedAids+=${result.promoted.join(',')}`);
1688
1705
  changes.push({ file, kind: 'agent-only-model', before: parsed.text, after: nextText });
1689
1706
  details.push({ file: path.relative(home, file), removed: result.removed, migrated });
1690
1707
  summary.filesChanged += 1;
1691
1708
  summary.fieldsRemoved += result.removed.length;
1709
+ summary.fieldsRenamed += result.renamed.length;
1692
1710
  if (result.migrated.length > 0)
1693
1711
  summary.modesConverted += 1;
1694
1712
  summary.promotedContacts += result.promoted.length;
1695
1713
  }
1696
1714
  return { home, changes, summary, details };
1697
1715
  }
1698
- /** Plan or apply the Agent access-policy rewrite (v16 → v17). */
1716
+ /** Plan or apply the Agent access-policy rewrite (v16 → v17 → v18). */
1699
1717
  export function runAccessPolicySchemaMigration(options = {}) {
1700
1718
  const id = 'access-policy-v17-v1';
1701
1719
  const home = path.resolve(options.home || resolvePaths().root);
@@ -1,13 +1,14 @@
1
1
  export const ECWEB_SERVICE_PROTOCOL = Object.freeze({
2
2
  name: 'evolcore.ecweb',
3
3
  major: 1,
4
- minor: 4,
4
+ minor: 5,
5
5
  capabilities: Object.freeze([
6
6
  'daemon.status',
7
7
  'agent.directory',
8
8
  'aun.directory',
9
9
  'menu.execute',
10
10
  'provider.management',
11
+ 'ability.management',
11
12
  'initialization',
12
13
  'basic-settings',
13
14
  'model.catalog',
@@ -511,7 +511,7 @@ export function createAgentRuntimeOperations({ agentRegistry, agentLoader, sessi
511
511
  };
512
512
  return { hotLoad, resync };
513
513
  }
514
- // fastaun 0.5.29 start()/capture() only read and verify documents. All writes
514
+ // Audited fastaun start()/capture() only read and verify documents. All writes
515
515
  // and notifications occur in execute(), which converts transport failures to
516
516
  // an error task with its original operation_id. Only this audited artifact
517
517
  // therefore proves that a raw ECONNRESET rejection preceded submission.
@@ -520,6 +520,7 @@ export function createAgentRuntimeOperations({ agentRegistry, agentLoader, sessi
520
520
  const AUDITED_WORKFLOW_SHA256 = {
521
521
  '0.5.28': 'cd736d1fcce0812013ba7d7c2148f86c8f3d3d2d39e451e52a0f9cc2a4d4fb51',
522
522
  '0.5.29': '24ac11a456607019dbbf5e7d247f4632520d7bd70bf0e49d4efa36d2898e7648',
523
+ '0.5.30': '4f63c8116035ec509ffea67dd0a8fc3f0300a78ba89eefdd8c65af6d9da91517',
523
524
  };
524
525
  export function initializationBindPreflightFailure(error) {
525
526
  if (!(error instanceof Error) || error.code !== 'ECONNRESET')
@@ -1,4 +1,5 @@
1
1
  import { assertAgentPolicyAuthorization } from '../role/runtime-policy.js';
2
+ import { PUBLIC_PERMISSION_MODES } from '../permission/mode.js';
2
3
  import crypto from 'crypto';
3
4
  import { authorizeOperation, buildAuthSubject } from './auth-gateway.js';
4
5
  import { refreshOwnershipForAuthorization } from '../ownership/owner-resolver.js';
@@ -491,15 +492,21 @@ export async function authorizeDelegatedAunMsgSend(registry, input) {
491
492
  }
492
493
  return { ok: true, grant };
493
494
  }
494
- /** Build the only AuthGateway input shape accepted for a task-held fullaccess claim. */
495
+ /** Preserve daemon-issued task mode and the only accepted task-held fullaccess claim. */
495
496
  export function trustedExecutionIdentityInput(grant) {
496
- return grant.executionIdentity && isValidFullAccessExecutionIdentity(grant.executionIdentity)
497
+ const isFullAccess = !!grant.executionIdentity && isValidFullAccessExecutionIdentity(grant.executionIdentity);
498
+ const fullAccess = isFullAccess
497
499
  ? {
498
- sessionId: grant.sessionId,
499
500
  trustedProcessRole: 'fullaccess-run',
500
501
  trustedFullAccessAuthorization: grant.executionIdentity,
501
502
  }
502
- : { sessionId: grant.sessionId };
503
+ : {};
504
+ const permissionMode = isFullAccess
505
+ ? 'fullaccess'
506
+ : PUBLIC_PERMISSION_MODES.includes(grant.permissionMode)
507
+ ? grant.permissionMode
508
+ : undefined;
509
+ return { sessionId: grant.sessionId, ...(permissionMode ? { permissionMode } : {}), ...fullAccess };
503
510
  }
504
511
  export function hasTrustedFullAccessDelegation(grant) {
505
512
  return !!grant.executionIdentity && isValidFullAccessExecutionIdentity(grant.executionIdentity);
@@ -601,6 +608,12 @@ export function parseDelegatedExecutionSpec(raw) {
601
608
  return undefined;
602
609
  if (spec.mergeStderr !== undefined && typeof spec.mergeStderr !== 'boolean')
603
610
  return undefined;
611
+ if (spec.discardStdout !== undefined && typeof spec.discardStdout !== 'boolean')
612
+ return undefined;
613
+ if (spec.discardStderr !== undefined && typeof spec.discardStderr !== 'boolean')
614
+ return undefined;
615
+ if ((spec.mergeStderr && spec.discardStderr) || (spec.discardStdout && spec.outputPath !== undefined))
616
+ return undefined;
604
617
  if (spec.suffixArgv !== undefined && (!Array.isArray(spec.suffixArgv)
605
618
  || spec.suffixArgv.some(arg => typeof arg !== 'string' || arg.includes('\0'))))
606
619
  return undefined;
@@ -621,7 +634,10 @@ export function hashDelegatedCommandSpec(spec) {
621
634
  ...(spec.filterChain ?? []).flat(),
622
635
  ...(spec.suffixArgv ?? []),
623
636
  ];
624
- if (spec.version !== 1 || values.some(value => value !== undefined && (typeof value !== 'string' || value.includes('\0')))) {
637
+ if (spec.version !== 1
638
+ || [spec.mergeStderr, spec.discardStdout, spec.discardStderr]
639
+ .some(value => value !== undefined && typeof value !== 'boolean')
640
+ || values.some(value => value !== undefined && (typeof value !== 'string' || value.includes('\0')))) {
625
641
  return undefined;
626
642
  }
627
643
  return crypto.createHash('sha256')
@@ -6,7 +6,7 @@ import { auditCommandAuthorization } from './authorization-audit.js';
6
6
  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
- import { resolveRuntimePermissionMode } from '../role/runtime-policy.js';
9
+ import { constrainRuntimePermissionMode, resolveRuntimePermissionMode } from '../role/runtime-policy.js';
10
10
  import { buildAuthorizationEventKey } from '../audit/event-key.js';
11
11
  export function isCrossAgentTriggerOperationAllowed(input) {
12
12
  return input.control || input.daemonOwner === true || input.taskAgentAid === input.targetAgentAid;
@@ -84,6 +84,7 @@ export function buildAuthSubject(input) {
84
84
  ? 'fullaccess'
85
85
  : input.permissionMode
86
86
  ?? resolveRuntimePermissionMode({ selfAid: input.selfAid, role }).effectiveValue,
87
+ authorizationEvidence: input.authorizationEvidence,
87
88
  };
88
89
  }
89
90
  function isProcessOwner(input) {
@@ -113,13 +114,30 @@ export async function authorizeFreshOperation(params) {
113
114
  const operation = getOperationMeta(params.intent.operation);
114
115
  const sensitive = force || params.intent.dangerous || operation?.dangerous || operation?.category !== 'read'
115
116
  || configCommand?.dangerous || subject.processRole === 'fullaccess-run';
116
- await refreshOwnershipForAuthorization(subject.selfAid, {
117
- force,
118
- ...(sensitive ? {} : { maxAgeMs: OWNERSHIP_CACHE_MAX_AGE_MS }),
119
- includeDaemon: subject.isDaemonOwner || subject.processRole === 'fullaccess-run'
120
- || params.intent.scope === 'process' || params.intent.scope === 'control' || force,
121
- allowTransient: !force,
122
- });
117
+ try {
118
+ await refreshOwnershipForAuthorization(subject.selfAid, {
119
+ force,
120
+ ...(sensitive ? {} : { maxAgeMs: OWNERSHIP_CACHE_MAX_AGE_MS }),
121
+ includeDaemon: subject.isDaemonOwner || subject.processRole === 'fullaccess-run'
122
+ || params.intent.scope === 'process' || params.intent.scope === 'control' || force,
123
+ allowTransient: !force,
124
+ });
125
+ const targetAid = operation?.authorizationTarget === 'same-owner-agent'
126
+ && subject.processRole !== 'fullaccess-run'
127
+ ? String(params.intent.args.targetAgentAid ?? '').trim()
128
+ : '';
129
+ if (targetAid && targetAid !== subject.selfAid) {
130
+ await refreshOwnershipForAuthorization(targetAid, { force: true, allowTransient: false });
131
+ }
132
+ }
133
+ catch (error) {
134
+ return {
135
+ allow: false,
136
+ code: 'OWNER_UNAVAILABLE',
137
+ reason: error instanceof Error ? error.message : 'Ownership authorization could not be refreshed',
138
+ subject,
139
+ };
140
+ }
123
141
  const current = buildAuthSubject({
124
142
  selfAid: subject.selfAid, agentName: subject.agentName, actorId: subject.actorId,
125
143
  channel: subject.channel, channelType: subject.channelType, channelId: subject.channelId,
@@ -137,7 +155,9 @@ export async function authorizeFreshOperation(params) {
137
155
  role: current.role, relationRole: current.relationRole, roleSource: current.roleSource,
138
156
  principalId: current.principalId, processRole: current.processRole, dataScope: current.dataScope,
139
157
  identity: current.identity, isDaemonOwner: current.isDaemonOwner, allowAccess: current.allowAccess,
140
- permissionMode: current.permissionMode,
158
+ permissionMode: constrainRuntimePermissionMode({
159
+ selfAid: subject.selfAid, role: current.role, requestedValue: subject.permissionMode,
160
+ }).effectiveValue,
141
161
  canApprovePersistentFullAccess: subject.canApprovePersistentFullAccess === false ? false : current.canApprovePersistentFullAccess,
142
162
  });
143
163
  }
@@ -235,6 +255,8 @@ export function authorizeOperation(params) {
235
255
  role: params.subject.role,
236
256
  processRole: params.subject.processRole,
237
257
  dataScope: params.subject.dataScope,
258
+ permissionMode: params.subject.permissionMode,
259
+ authorizationEvidence: params.subject.authorizationEvidence,
238
260
  isDaemonOwner: params.subject.isDaemonOwner,
239
261
  fromControlChannel: params.subject.fromControlChannel,
240
262
  allowExplicitRelationTarget: params.allowExplicitRelationTarget,
@@ -11,6 +11,12 @@ function permissionAuditDetails(input) {
11
11
  approverOperatorId: input.approverOperatorId,
12
12
  approverChannelKey: input.approverChannelKey,
13
13
  approverPrincipalId: input.approverPrincipalId,
14
+ authorizationCredentialId: input.authorizationCredentialId,
15
+ approvalAuthorizationCredentialId: input.approvalAuthorizationCredentialId,
16
+ approvalMechanism: input.approvalMechanism,
17
+ approvalCredentialId: input.approvalCredentialId,
18
+ approvalProviderId: input.approvalProviderId,
19
+ approvalModelId: input.approvalModelId,
14
20
  }).filter((entry) => typeof entry[1] === 'string'));
15
21
  }
16
22
  export function auditCommandAuthorization(event) {
@@ -117,6 +123,9 @@ export function auditFullAccessEvent(input) {
117
123
  * denials otherwise only reach `logger.warn` and `TriggerExecutionAnomaly`.
118
124
  */
119
125
  export function auditToolPreflightDenial(input) {
126
+ const reason = input.reason === 'policy denied' && input.matchedRule
127
+ ? `policy denied (matchedRule=${input.matchedRule})`
128
+ : input.reason;
120
129
  const classification = normalizeToolErrorClassification({
121
130
  errorCode: 'POLICY_DENIED',
122
131
  decisionSource: 'policy',
@@ -146,7 +155,8 @@ export function auditToolPreflightDenial(input) {
146
155
  // localized summaries: words such as `daemon.json` or `.lock` may only be
147
156
  // regex/string literals in an otherwise harmless diagnostic command.
148
157
  matchedPath: input.matchedPath,
149
- reason: input.reason,
158
+ matchedRule: input.matchedRule,
159
+ reason,
150
160
  argsSummary: input.summary ? { summary: input.summary } : undefined,
151
161
  sessionId: input.sessionId ?? 'unknown',
152
162
  agentAid: input.agentAid ?? 'unknown',
@@ -192,6 +202,9 @@ export function auditCodexApprovalDecision(input) {
192
202
  policyCode: input.policyCode,
193
203
  protectionClass: protectionClassForPolicy(input.policyCode),
194
204
  parseFailure: sanitizeParseFailure(input.parseFailure),
205
+ commandIntent: input.commandIntent,
206
+ canonicalizationStage: input.canonicalizationStage,
207
+ canonicalWrapper: input.canonicalWrapper,
195
208
  reason: input.reason,
196
209
  role: input.role ?? 'unknown',
197
210
  taskId: input.taskId,
@@ -256,6 +269,12 @@ export function auditPermissionLifecycle(input) {
256
269
  permissionMode: input.permissionMode ?? 'unknown',
257
270
  toolName: input.toolName,
258
271
  approvalMethod: input.approvalMethod,
272
+ authorizationCredentialId: input.authorizationCredentialId,
273
+ approvalAuthorizationCredentialId: input.approvalAuthorizationCredentialId,
274
+ approvalMechanism: input.approvalMechanism,
275
+ approvalCredentialId: input.approvalCredentialId,
276
+ approvalProviderId: input.approvalProviderId,
277
+ approvalModelId: input.approvalModelId,
259
278
  policyCode: input.policyCode,
260
279
  decisionSource: input.decisionSource,
261
280
  errorDetailCode: input.errorDetailCode,
@@ -424,12 +443,22 @@ function buildAuditRecord(event) {
424
443
  policyCode: event.policyCode ?? event.code,
425
444
  protectionClass: event.protectionClass,
426
445
  matchedPath: event.matchedPath,
446
+ matchedRule: event.matchedRule,
427
447
  parseFailure: sanitizeParseFailure(event.parseFailure),
448
+ commandIntent: event.commandIntent,
449
+ canonicalizationStage: event.canonicalizationStage,
450
+ canonicalWrapper: event.canonicalWrapper,
428
451
  decisionSource,
429
452
  ecwebRequestId: event.ecwebRequestId,
430
453
  targetAgentAid: redactIdentifier(event.targetAgentAid),
431
454
  endpoint: event.endpoint,
432
455
  logicalToolName: event.logicalToolName,
456
+ authorizationCredentialId: event.authorizationCredentialId,
457
+ approvalAuthorizationCredentialId: event.approvalAuthorizationCredentialId,
458
+ approvalMechanism: event.approvalMechanism,
459
+ approvalCredentialId: event.approvalCredentialId,
460
+ approvalProviderId: event.approvalProviderId,
461
+ approvalModelId: event.approvalModelId,
433
462
  source: event.source,
434
463
  operation: event.operation,
435
464
  scope: event.scope,
@@ -455,7 +484,6 @@ function buildAuditRecord(event) {
455
484
  executionState,
456
485
  code: event.code,
457
486
  reason: event.reason,
458
- matchedRule: event.matchedRule,
459
487
  argvHash: event.argvHash,
460
488
  argsSummary: summarizeAuthorizationArgs(event.operation, event.argsSummary),
461
489
  durationMs: event.durationMs,
@@ -485,7 +513,18 @@ function sanitizeParseFailure(value) {
485
513
  || ![offset, tokenIndex, inputLength].every(value => Number.isSafeInteger(value) && value >= 0)
486
514
  || offset > inputLength || tokenIndex > inputLength)
487
515
  return undefined;
488
- return { issue: candidate.issue, dialect: candidate.dialect, offset, tokenIndex, inputLength };
516
+ const result = {
517
+ issue: candidate.issue, dialect: candidate.dialect, offset, tokenIndex, inputLength,
518
+ };
519
+ for (const field of ['canonicalizationStage', 'wrapper']) {
520
+ if (typeof candidate[field] === 'string')
521
+ result[field === 'wrapper' ? 'wrapper' : 'canonicalizationStage'] = candidate[field];
522
+ }
523
+ for (const field of ['redirectDetected', 'managedTempPath', 'managedTempResolved']) {
524
+ if (typeof candidate[field] === 'boolean')
525
+ result[field] = candidate[field];
526
+ }
527
+ return result;
489
528
  }
490
529
  function resolveAgentName(event) {
491
530
  const displayName = typeof event.agentName === 'string' ? event.agentName.trim() : '';
@@ -524,6 +563,10 @@ function logAuditEvent(record) {
524
563
  // Keep one machine-readable stream independent from daemon text rotation;
525
564
  // daily analysis can de-duplicate it against events/channel mirrors.
526
565
  writeCommandAuditRecord(record);
566
+ // Mirror the exact redacted preflight record even when the provider never
567
+ // emits a tool result. Keep its lifecycle key and source IDs for de-duplication.
568
+ if (record.operation === 'tool.preflight.deny')
569
+ logger.event(record);
527
570
  // A role-management snapshot fans out into several successful read checks.
528
571
  // Keep those available for verbose ECWeb diagnostics without flooding INFO.
529
572
  const routineEcwebRoleRead = record.source === 'ecweb'
@@ -569,7 +612,11 @@ function logAuditEvent(record) {
569
612
  record.policyCode ? `policy=${record.policyCode}` : null,
570
613
  record.protectionClass ? `protectionClass=${record.protectionClass}` : null,
571
614
  record.matchedPath ? `matchedPath=${JSON.stringify(record.matchedPath)}` : null,
615
+ record.matchedRule ? `matchedRule=${JSON.stringify(record.matchedRule)}` : null,
572
616
  record.parseFailure ? `parseFailure=${JSON.stringify(record.parseFailure)}` : null,
617
+ record.commandIntent ? `commandIntent=${record.commandIntent}` : null,
618
+ record.canonicalizationStage ? `canonicalizationStage=${record.canonicalizationStage}` : null,
619
+ record.canonicalWrapper ? `canonicalWrapper=${record.canonicalWrapper}` : null,
573
620
  record.decisionSource ? `decisionSource=${record.decisionSource}` : null,
574
621
  `executed=${record.executed}`,
575
622
  `executionState=${record.executionState}`,
@@ -678,7 +725,8 @@ function summarizeAuthorizationArgs(operation, args) {
678
725
  continue;
679
726
  }
680
727
  if (typeof value === 'string') {
681
- summary[key] = value.length <= 96 ? value : `${value.slice(0, 93)}...`;
728
+ const maxLength = key === 'summary' ? 512 : 96;
729
+ summary[key] = value.length <= maxLength ? value : `${value.slice(0, maxLength - 3)}...`;
682
730
  }
683
731
  else if (typeof value === 'number' || typeof value === 'boolean' || value === null) {
684
732
  summary[key] = value;