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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/dist/agents/baseagent-availability.js +1 -1
  3. package/dist/agents/baseagent.js +20 -43
  4. package/dist/agents/claude-runner.js +177 -92
  5. package/dist/agents/codex-runner.js +84 -28
  6. package/dist/agents/ecagent-runner.js +1 -1
  7. package/dist/agents/gemini-runner.js +1 -1
  8. package/dist/aun/group/fs-download.js +39 -0
  9. package/dist/aun/group/identity.js +36 -21
  10. package/dist/aun/group/operations.js +5 -0
  11. package/dist/aun/msg/managed-operation.js +68 -7
  12. package/dist/aun/msg/p2p.js +5 -0
  13. package/dist/aun/service-proxy.js +36 -12
  14. package/dist/channels/aun.js +334 -20
  15. package/dist/channels/daemon.js +15 -1
  16. package/dist/cli/aun-commands.js +4 -20
  17. package/dist/cli/daemon-commands.js +678 -697
  18. package/dist/cli/fs-command.js +64 -2
  19. package/dist/cli/index.js +48 -4
  20. package/dist/cli/managed-command-guard.js +4 -0
  21. package/dist/cli/model.js +40 -40
  22. package/dist/cli/proxy-command.js +92 -0
  23. package/dist/cli/role.js +85 -0
  24. package/dist/config/access-policy.js +7 -2
  25. package/dist/config/boot-log.js +38 -1
  26. package/dist/config/config-field-policy.js +5 -32
  27. package/dist/config/config-manager.js +46 -39
  28. package/dist/config/config-operation-service.js +5 -19
  29. package/dist/config/contact-book-store.js +47 -21
  30. package/dist/config/contact-book.js +18 -12
  31. package/dist/config/contact-operation-service.js +3 -4
  32. package/dist/config/contact-request-service.js +11 -0
  33. package/dist/config/daemon-services.js +11 -0
  34. package/dist/config/gateway-config.js +88 -594
  35. package/dist/config/peer-role-resolver.js +13 -11
  36. package/dist/config/providers-config.js +12 -7
  37. package/dist/config/providers-import.js +3 -21
  38. package/dist/config/resolved-config-op.js +3 -0
  39. package/dist/config/role-command-service.js +166 -0
  40. package/dist/config/role-request-service.js +193 -0
  41. package/dist/config/schema-migration.js +686 -25
  42. package/dist/config-store.js +79 -3
  43. package/dist/contracts/ecweb-instance.js +41 -0
  44. package/dist/contracts/ecweb-service-protocol.js +3 -1
  45. package/dist/core/agent-runtime.js +1 -1
  46. package/dist/core/auth/agent-delegation.js +2 -1
  47. package/dist/core/auth/auth-gateway.js +1 -1
  48. package/dist/core/auth/authorization-audit.js +17 -6
  49. package/dist/core/auth/delegation-authorization.js +3 -1
  50. package/dist/core/auth/operation-authorizer.js +15 -0
  51. package/dist/core/auth/operation-catalog.js +31 -6
  52. package/dist/core/command/agent-control.js +3 -7
  53. package/dist/core/command/agent-storage-menu.js +5 -3
  54. package/dist/core/command/cli-intent-parser.js +2 -1
  55. package/dist/core/command/command-handler.js +48 -99
  56. package/dist/core/command/connect-menu.js +11 -3
  57. package/dist/core/command/data-root-resolver.js +5 -4
  58. package/dist/core/command/memory-slash.js +16 -8
  59. package/dist/core/command/menu-catalog.js +5 -6
  60. package/dist/core/command/menu-handler.js +49 -62
  61. package/dist/core/command/role-menu.js +147 -30
  62. package/dist/core/command/slash-handler.js +123 -254
  63. package/dist/core/daemon-control.js +8 -14
  64. package/dist/core/evolagent-registry.js +4 -4
  65. package/dist/core/evolagent.js +2 -2
  66. package/dist/core/inference/text-inference.js +31 -40
  67. package/dist/core/ipc-registration.js +6 -2
  68. package/dist/core/memory/consolidation-context.js +51 -5
  69. package/dist/core/memory/consolidation-ops-records.js +1 -1
  70. package/dist/core/memory/consolidation-trigger.js +189 -189
  71. package/dist/core/memory/consolidation.js +316 -29
  72. package/dist/core/memory/forget-log.js +96 -0
  73. package/dist/core/memory/index-manager.js +27 -5
  74. package/dist/core/memory/memory-admin.js +45 -5
  75. package/dist/core/memory/memory-writer.js +163 -18
  76. package/dist/core/memory/relation-idle-monitor.js +119 -58
  77. package/dist/core/memory/relation-sweep.js +44 -39
  78. package/dist/core/message/aun-ipc-sender.js +8 -2
  79. package/dist/core/message/im-renderer.js +7 -4
  80. package/dist/core/message/message-admission.js +89 -4
  81. package/dist/core/message/message-bridge.js +31 -18
  82. package/dist/core/message/response-engine.js +77 -8
  83. package/dist/core/model/catalog-service.js +4 -2
  84. package/dist/core/model/config-scope.js +24 -64
  85. package/dist/core/model/field-scope.js +1 -1
  86. package/dist/core/model/model-catalog.js +30 -41
  87. package/dist/core/model/model-diagnostics.js +4 -3
  88. package/dist/core/model/model-fallback.js +10 -7
  89. package/dist/core/model/model-permission.js +3 -2
  90. package/dist/core/ownership/owner-resolver.js +23 -21
  91. package/dist/core/permission/ec-command-parser.js +30 -2
  92. package/dist/core/permission/sandbox-runtime.js +18 -1
  93. package/dist/core/permission/tool-policy.js +14 -3
  94. package/dist/core/relation/peer-identity.js +64 -1
  95. package/dist/core/role/runtime-policy.js +72 -13
  96. package/dist/core/session/session-capsule.js +1 -1
  97. package/dist/core/session/session-idle-monitor.js +1 -1
  98. package/dist/core/session/session-manager.js +20 -0
  99. package/dist/core/session/session-renew.js +3 -3
  100. package/dist/core/skill/index-generator.js +15 -5
  101. package/dist/core/system-session/memory.js +6 -1
  102. package/dist/core/thread/thread-service.js +19 -6
  103. package/dist/directory/owner-directory-admission.js +95 -0
  104. package/dist/directory/owner-directory-authorization.js +309 -0
  105. package/dist/directory/owner-directory-cache.js +635 -0
  106. package/dist/eck/kit-renderer.js +2 -2
  107. package/dist/ecweb/basic-settings-service.js +33 -40
  108. package/dist/ecweb/message-context-service.js +110 -0
  109. package/dist/index.js +76 -14
  110. package/dist/ipc.js +170 -12
  111. package/dist/paths.js +4 -0
  112. package/dist/proxy/command.js +122 -0
  113. package/dist/proxy/ipc-service.js +68 -0
  114. package/dist/proxy/manager.js +485 -0
  115. package/dist/proxy/service-supervisor.js +603 -0
  116. package/dist/response-system/engines/v1/proactive-flow.js +16 -6
  117. package/dist/utils/cross-platform.js +14 -0
  118. package/dist/utils/ecweb-supervisor.js +258 -83
  119. package/dist/utils/error-utils.js +2 -2
  120. package/dist/utils/logger.js +24 -5
  121. package/dist/utils/package-version-info.js +4 -2
  122. package/kits/docs/channels/aun.md +9 -0
  123. package/kits/docs/evolcore/agent.md +1 -1
  124. package/kits/docs/evolcore/config.md +17 -6
  125. package/kits/docs/evolcore/contact.md +3 -0
  126. package/kits/docs/evolcore/fs.md +11 -0
  127. package/kits/docs/evolcore/memory-architecture.md +2 -2
  128. package/kits/docs/evolcore/memory-consolidation.md +32 -8
  129. package/kits/docs/evolcore/memory.md +1 -1
  130. package/kits/docs/evolcore/menu-protocol.md +4 -0
  131. package/kits/docs/evolcore/model.md +23 -20
  132. package/kits/docs/evolcore/msg.md +4 -7
  133. package/kits/migrations/migrate-contact-book-v2.mjs +30 -11
  134. package/kits/schemas/_meta.json +37 -4
  135. package/kits/schemas/agent-config.schema.13.json +8 -3
  136. package/kits/schemas/agent-config.schema.16.json +891 -0
  137. package/kits/schemas/daemon.schema.9.json +366 -0
  138. package/kits/schemas/defaults.schema.5.json +406 -127
  139. package/kits/schemas/relation-config.schema.11.json +260 -0
  140. package/kits/schemas/role-config.schema.1.json +7 -7
  141. package/kits/skills/.switches.json +3 -7
  142. package/kits/skills/ec-service-proxy/SKILL.md +118 -0
  143. package/kits/skills/ec-trigger/SKILL.md +13 -5
  144. package/kits/skills/personal-assistant/SKILL.md +176 -0
  145. package/kits/skills/personal-assistant/references/01-workspace-spec.md +333 -0
  146. package/kits/skills/personal-assistant/references/02-bootstrap.md +205 -0
  147. package/kits/skills/personal-assistant/references/03-data-flow-and-gaps.md +177 -0
  148. package/kits/skills/personal-assistant/references/04-frontend-contract.md +439 -0
  149. package/kits/skills/personal-assistant/references/05-directory-reference.md +292 -0
  150. package/kits/skills/personal-assistant/references/06-render-config.md +350 -0
  151. package/kits/skills/personal-assistant/schema/workspace.schema.json +85 -0
  152. package/kits/skills/personal-assistant/schema/workspace.v1.json +66 -0
  153. package/kits/skills/personal-assistant/scripts/archive.mjs +154 -0
  154. package/kits/skills/personal-assistant/scripts/check.mjs +114 -0
  155. package/kits/skills/personal-assistant/scripts/index-rebuild.mjs +252 -0
  156. package/kits/skills/personal-assistant/scripts/ingest.mjs +344 -0
  157. package/kits/skills/personal-assistant/scripts/init.mjs +270 -0
  158. package/kits/skills/personal-assistant/scripts/lib/apply.mjs +92 -0
  159. package/kits/skills/personal-assistant/scripts/lib/schema.mjs +96 -0
  160. package/kits/skills/personal-assistant/scripts/lib/time.mjs +28 -0
  161. package/kits/skills/personal-assistant/scripts/migrate.mjs +172 -0
  162. package/kits/skills/personal-assistant/scripts/search.mjs +172 -0
  163. package/kits/skills/personal-assistant/scripts/verify.mjs +196 -0
  164. package/kits/skills/personal-assistant/templates/INDEX.md.tpl +24 -0
  165. package/kits/skills/personal-assistant/templates/README.md.tpl +108 -0
  166. package/kits/skills/personal-assistant/triggers/ingest-daily.json +23 -0
  167. package/kits/skills/personal-assistant/triggers/memory-consolidate.json +23 -0
  168. package/kits/skills/personal-assistant/triggers/report-daily.json +23 -0
  169. package/kits/skills/personal-assistant/triggers/report-weekly.json +23 -0
  170. package/kits/templates/memory-consolidation/forget.md +19 -6
  171. package/kits/templates/memory-consolidation/notes.md +1 -1
  172. package/kits/templates/memory-consolidation/profile.md +2 -2
  173. package/kits/templates/memory-consolidation/promote.md +20 -3
  174. package/kits/templates/roles/member.json +8 -1
  175. package/kits/templates/system-fragments/baseagent.md +2 -2
  176. package/kits/templates/system-fragments/memory.md +4 -4
  177. package/package.json +6 -2
@@ -112,6 +112,81 @@ export function saveDaemonConfig(value) {
112
112
  }
113
113
  catch { /* best-effort */ }
114
114
  }
115
+ function validateServiceManagementFields(service, index) {
116
+ const prefix = `daemon.json.services[${service.name ?? index}]`;
117
+ const runtime = service.runtime;
118
+ if (runtime !== undefined) {
119
+ if (!runtime || typeof runtime !== 'object' || Array.isArray(runtime))
120
+ throw new Error(`${prefix}.runtime must be an object`);
121
+ const unknown = Object.keys(runtime).filter(key => !['mode', 'command', 'stopTimeoutMs', 'restart'].includes(key));
122
+ if (unknown.length)
123
+ throw new Error(`${prefix}.runtime contains unsupported fields: ${unknown.join(', ')}`);
124
+ if (runtime.mode !== undefined && !['managed', 'external'].includes(runtime.mode)) {
125
+ throw new Error(`${prefix}.runtime.mode must be managed or external`);
126
+ }
127
+ if (service.name === 'ecweb' && runtime.command !== undefined) {
128
+ throw new Error('daemon.json.services[ecweb].runtime.command is managed by the internal ECWeb adapter');
129
+ }
130
+ if (runtime.command !== undefined) {
131
+ const command = runtime.command;
132
+ if (!command || typeof command !== 'object' || Array.isArray(command)
133
+ || Object.keys(command).some(key => !['file', 'args', 'cwd'].includes(key))) {
134
+ throw new Error(`${prefix}.runtime.command must contain only file, args, and cwd`);
135
+ }
136
+ if (typeof command.file !== 'string' || !path.isAbsolute(command.file) || command.file.length > 2048) {
137
+ throw new Error(`${prefix}.runtime.command.file must be an absolute executable path`);
138
+ }
139
+ if (command.cwd !== undefined && (typeof command.cwd !== 'string' || !path.isAbsolute(command.cwd) || command.cwd.length > 2048)) {
140
+ throw new Error(`${prefix}.runtime.command.cwd must be an absolute path`);
141
+ }
142
+ if (command.args !== undefined && (!Array.isArray(command.args) || command.args.length > 128
143
+ || command.args.some((arg) => typeof arg !== 'string' || arg.length > 8192))) {
144
+ throw new Error(`${prefix}.runtime.command.args must be at most 128 strings`);
145
+ }
146
+ }
147
+ if (runtime.mode === 'managed' && service.name !== 'ecweb' && !runtime.command) {
148
+ throw new Error(`${prefix}.runtime.command is required for managed services`);
149
+ }
150
+ if (runtime.stopTimeoutMs !== undefined
151
+ && (!Number.isInteger(runtime.stopTimeoutMs) || runtime.stopTimeoutMs < 100 || runtime.stopTimeoutMs > 120000)) {
152
+ throw new Error(`${prefix}.runtime.stopTimeoutMs must be 100-120000`);
153
+ }
154
+ if (runtime.restart !== undefined) {
155
+ const restart = runtime.restart;
156
+ const restartFields = ['enabled', 'backoffMs'];
157
+ if (!restart || typeof restart !== 'object' || Array.isArray(restart)
158
+ || Object.keys(restart).some(key => !restartFields.includes(key))) {
159
+ throw new Error(`${prefix}.runtime.restart contains unsupported fields`);
160
+ }
161
+ if (restart.enabled !== undefined && typeof restart.enabled !== 'boolean') {
162
+ throw new Error(`${prefix}.runtime.restart.enabled must be a boolean`);
163
+ }
164
+ if (restart.backoffMs !== undefined
165
+ && (!Number.isInteger(restart.backoffMs) || restart.backoffMs < 1 || restart.backoffMs > 3600000)) {
166
+ throw new Error(`${prefix}.runtime.restart.backoffMs must be 1-3600000`);
167
+ }
168
+ }
169
+ }
170
+ const health = service.health;
171
+ if (health !== undefined) {
172
+ const fields = ['type', 'path', 'timeoutMs', 'failureThreshold', 'startupTimeoutMs'];
173
+ if (!health || typeof health !== 'object' || Array.isArray(health)
174
+ || Object.keys(health).some(key => !fields.includes(key)))
175
+ throw new Error(`${prefix}.health contains unsupported fields`);
176
+ if (health.type !== undefined && !['http', 'tcp'].includes(health.type))
177
+ throw new Error(`${prefix}.health.type is invalid`);
178
+ if (health.path !== undefined && (typeof health.path !== 'string' || !health.path.startsWith('/') || health.path.length > 1024)) {
179
+ throw new Error(`${prefix}.health.path must be an absolute URL path`);
180
+ }
181
+ for (const field of ['timeoutMs', 'failureThreshold', 'startupTimeoutMs']) {
182
+ const number = health[field];
183
+ const max = field === 'failureThreshold' ? 100 : 300000;
184
+ if (number !== undefined && (!Number.isInteger(number) || number < 1 || number > max)) {
185
+ throw new Error(`${prefix}.health.${field} must be 1-${max}`);
186
+ }
187
+ }
188
+ }
189
+ }
115
190
  function validateDaemonConfig(value, validateAidDomain) {
116
191
  assertOwnerConfigRecord(value, 'daemon.json', isValidAid);
117
192
  if (value.upgrade !== undefined) {
@@ -180,7 +255,7 @@ function validateDaemonConfig(value, validateAidDomain) {
180
255
  throw new Error(`daemon.json.services[${index}] must be an object`);
181
256
  }
182
257
  const service = rawService;
183
- const unknownServiceFields = Object.keys(service).filter((key) => !['name', 'enabled', 'port', 'proxy'].includes(key));
258
+ const unknownServiceFields = Object.keys(service).filter((key) => !['name', 'enabled', 'port', 'runtime', 'health', 'proxy'].includes(key));
184
259
  if (unknownServiceFields.length > 0) {
185
260
  throw new Error(`daemon.json.services[${index}] contains unsupported fields: ${unknownServiceFields.join(', ')}`);
186
261
  }
@@ -197,6 +272,7 @@ function validateDaemonConfig(value, validateAidDomain) {
197
272
  if (service.port !== undefined && (!Number.isInteger(service.port) || service.port < 1 || service.port > 65535)) {
198
273
  throw new Error(`daemon.json.services[${service.name}].port must be an integer from 1 to 65535`);
199
274
  }
275
+ validateServiceManagementFields(service, index);
200
276
  if (service.proxy !== undefined) {
201
277
  if (!service.proxy || typeof service.proxy !== 'object' || Array.isArray(service.proxy)) {
202
278
  throw new Error(`daemon.json.services[${service.name}].proxy must be an object`);
@@ -373,12 +449,12 @@ export function autoMigrateIfNeeded() {
373
449
  : `[migrate] daemon.json schema version -> ${daemonSchemaVersion}`);
374
450
  }
375
451
  /**
376
- * @deprecated Use ConfigManager.read(ConfigTarget.Agent, { self: aid }, { expand: true, cache: true }) instead.
452
+ * @deprecated Use ConfigManager.read(ConfigTarget.Agent, { self: aid }, { cache: true }) instead.
377
453
  * This wrapper exists for backward compatibility. All logic (aid validation, path cleaning, env expansion)
378
454
  * is now handled by ConfigManager.
379
455
  */
380
456
  export function loadAgent(aid) {
381
- return cfgRead(ConfigTarget.Agent, { self: aid }, { expand: true, cache: true });
457
+ return cfgRead(ConfigTarget.Agent, { self: aid }, { cache: true });
382
458
  }
383
459
  /**
384
460
  * @deprecated Use ConfigManager.write(ConfigTarget.Agent, value, { self: value.aid }) instead.
@@ -0,0 +1,41 @@
1
+ import crypto from 'node:crypto';
2
+ import path from 'node:path';
3
+ export function ecwebHomeId(root) {
4
+ const resolved = path.resolve(root);
5
+ const canonical = process.platform === 'win32' ? resolved.toLowerCase() : resolved;
6
+ return crypto.createHash('sha256').update(canonical).digest('hex');
7
+ }
8
+ export function parseEcwebInstanceRecord(value, root, file) {
9
+ if (!value || typeof value !== 'object' || Array.isArray(value))
10
+ return null;
11
+ const record = value;
12
+ if (!Number.isSafeInteger(record.pid) || record.pid <= 0)
13
+ return null;
14
+ const port = record.port === undefined ? 42705 : record.port;
15
+ if (!Number.isInteger(port) || port < 1 || port > 65535)
16
+ return null;
17
+ if (file && !new RegExp(`^(?:ecweb|watch-web)-${record.pid}\\.json$`).test(path.basename(file)))
18
+ return null;
19
+ if (record.startedAt !== undefined && (typeof record.startedAt !== 'number' || !Number.isFinite(record.startedAt) || record.startedAt <= 0))
20
+ return null;
21
+ if (record.schemaVersion !== undefined) {
22
+ if (record.schemaVersion !== 1 || record.service !== 'ecweb' || record.homeId !== ecwebHomeId(root)
23
+ || record.port === undefined || record.startedAt === undefined
24
+ || typeof record.instanceId !== 'string' || !/^[A-Za-z0-9-]{1,128}$/.test(record.instanceId))
25
+ return null;
26
+ }
27
+ return { ...record, pid: record.pid, port: port };
28
+ }
29
+ export function matchesEcwebInstanceHealth(value, record) {
30
+ if (!value || typeof value !== 'object' || Array.isArray(value))
31
+ return false;
32
+ const health = value;
33
+ if (health.ok !== true || health.service !== 'ecweb' || health.processAlive === false)
34
+ return false;
35
+ if (!record)
36
+ return true;
37
+ if (health.pid !== undefined && health.pid !== record.pid)
38
+ return false;
39
+ return record.schemaVersion === undefined
40
+ || (health.processAlive === true && health.pid === record.pid && health.instanceId === record.instanceId && health.homeId === record.homeId);
41
+ }
@@ -1,7 +1,7 @@
1
1
  export const ECWEB_SERVICE_PROTOCOL = Object.freeze({
2
2
  name: 'evolcore.ecweb',
3
3
  major: 1,
4
- minor: 1,
4
+ minor: 3,
5
5
  capabilities: Object.freeze([
6
6
  'daemon.status',
7
7
  'agent.directory',
@@ -15,6 +15,8 @@ export const ECWEB_SERVICE_PROTOCOL = Object.freeze({
15
15
  'monitor.subscription',
16
16
  'remote-auth',
17
17
  'trigger.history',
18
+ 'message.context',
19
+ 'session.runnerTasks',
18
20
  ]),
19
21
  });
20
22
  export function validateEcwebClientProtocolRequirements(value) {
@@ -357,7 +357,7 @@ export function createAgentRuntimeOperations({ agentRegistry, agentLoader, sessi
357
357
  if (!diskCfg || diskCfg.enabled === false) {
358
358
  try {
359
359
  const offlined = await reloadCoordinator.runExclusive(aid, async () => {
360
- const latestDiskCfg = readConfig(ConfigTarget.Agent, { self: aid }, { cache: false, expand: true });
360
+ const latestDiskCfg = readConfig(ConfigTarget.Agent, { self: aid }, { cache: false });
361
361
  if (latestDiskCfg && latestDiskCfg.enabled !== false)
362
362
  return false;
363
363
  const runtimeAgent = agentRegistry.get(aid);
@@ -493,10 +493,11 @@ export async function authorizeDelegatedAunMsgSend(registry, input) {
493
493
  export function trustedExecutionIdentityInput(grant) {
494
494
  return grant.executionIdentity && isValidFullAccessExecutionIdentity(grant.executionIdentity)
495
495
  ? {
496
+ sessionId: grant.sessionId,
496
497
  trustedProcessRole: 'fullaccess-run',
497
498
  trustedFullAccessAuthorization: grant.executionIdentity,
498
499
  }
499
- : {};
500
+ : { sessionId: grant.sessionId };
500
501
  }
501
502
  export function hasTrustedFullAccessDelegation(grant) {
502
503
  return !!grant.executionIdentity && isValidFullAccessExecutionIdentity(grant.executionIdentity);
@@ -107,7 +107,7 @@ export async function authorizeFreshOperation(params) {
107
107
  const configCommand = params.resolvedConfigCommand;
108
108
  const changesOwner = configCommand?.kind === 'field' && configCommand.subcommand !== 'get'
109
109
  && ['owner', 'owners'].includes(configCommand.field.split('.')[0]);
110
- const force = changesOwner || ['ec.aid.bind', 'ec.aid.bind.status', 'ec.aid.unbind', 'ec.aid.transfer']
110
+ const force = changesOwner || ['ec.aid.bind', 'ec.aid.unbind', 'ec.aid.transfer']
111
111
  .includes(params.intent.operation) || params.intent.operation === 'config.restore';
112
112
  const operation = getOperationMeta(params.intent.operation);
113
113
  const sensitive = force || params.intent.dangerous || operation?.dangerous || operation?.category !== 'read'
@@ -12,7 +12,7 @@ export function auditCommandAuthorization(event) {
12
12
  (event.source === 'agent-tool' && event.operation.startsWith('config.')) ||
13
13
  event.operation === 'codex.approval' ||
14
14
  event.operation === 'permission.approval' ||
15
- event.operation === 'permission.runtime' ||
15
+ event.operation.startsWith('permission.runtime') ||
16
16
  event.operation.startsWith('fullaccess.') ||
17
17
  event.operation.startsWith('role.') ||
18
18
  event.operation === 'file.root.storage' ||
@@ -280,14 +280,14 @@ export function auditToolInfrastructureFailure(input) {
280
280
  eventKey: buildToolLifecycleEventKey(input),
281
281
  eventPhase: 'final',
282
282
  source: 'agent-tool',
283
- operation: 'tool.execution.blocked',
283
+ operation: input.fallback ? 'permission.runtime.sandbox_fallback' : 'tool.execution.blocked',
284
284
  scope: 'filesystem',
285
285
  dangerous: false,
286
- decision: 'deny',
286
+ decision: input.fallback ? 'allow' : 'deny',
287
287
  decisionSource: 'infrastructure',
288
288
  errorCode: infrastructureErrorCode(input.policyCode),
289
289
  executed: false,
290
- executionState: 'blocked',
290
+ executionState: input.fallback ? 'authorized' : 'blocked',
291
291
  ...normalizeToolCorrelation(input),
292
292
  sessionId: input.sessionId ?? 'unknown',
293
293
  agentAid: input.agentAid ?? 'unknown',
@@ -301,6 +301,7 @@ export function auditToolInfrastructureFailure(input) {
301
301
  argsSummary: input.occurrences || input.sandboxFailure
302
302
  ? {
303
303
  ...(input.occurrences ? { occurrences: input.occurrences } : {}),
304
+ ...(input.fallback ? { sandboxFallback: true } : {}),
304
305
  // Flat primitive fields survive the audit argument redactor and can
305
306
  // be aggregated without reparsing (possibly truncated) stderr.
306
307
  ...(input.sandboxFailure ? {
@@ -390,9 +391,11 @@ function buildAuditRecord(event) {
390
391
  requestId,
391
392
  sourceRequestId,
392
393
  sessionId: event.sessionId,
393
- ...(event.source === 'ecweb' && !event.sessionId ? { sessionScope: 'not_applicable' } : {}),
394
+ ...(!event.sessionId ? {
395
+ sessionScope: event.source === 'ecweb' ? 'not_applicable' : 'unknown',
396
+ } : {}),
394
397
  agentAid: redactIdentifier(event.agentAid ?? event.selfAid),
395
- agentName: resolveAgentName(event),
398
+ agentName: resolveAgentName(event) ?? 'unknown',
396
399
  permissionMode: normalizeAuditPermissionMode(event.permissionMode),
397
400
  toolName: event.toolName,
398
401
  approvalMethod: event.approvalMethod,
@@ -459,6 +462,14 @@ function resolveAgentName(event) {
459
462
  const selfAid = typeof event.selfAid === 'string' ? event.selfAid.trim() : '';
460
463
  if (selfAid && selfAid !== 'unknown')
461
464
  return selfAid;
465
+ const targetAgentAid = event.source === 'ecweb' && typeof event.targetAgentAid === 'string'
466
+ ? event.targetAgentAid.trim() : '';
467
+ if (targetAgentAid && targetAgentAid !== 'unknown')
468
+ return targetAgentAid;
469
+ const actorId = event.source === 'ecweb' && typeof event.actorId === 'string'
470
+ ? event.actorId.trim() : '';
471
+ if (actorId && !isUnknownAgentLabel(actorId))
472
+ return actorId;
462
473
  return aid === 'unknown' || selfAid === 'unknown' ? 'unknown' : undefined;
463
474
  }
464
475
  function isUnknownAgentLabel(value) {
@@ -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
  },
@@ -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
  }
@@ -212,6 +217,16 @@ function authorizeCommandInternal(ctx, resolvedConfigCommand) {
212
217
  matchedRule: 'daemon-owner-model-options-read',
213
218
  };
214
219
  }
220
+ // 模型参数只在 Agent 级:写操作只能落 agent scope,且只有该 Agent 的 owner/admin
221
+ // (或 DaemonOwner)能改。这是代码级上限,角色文件授予 model.* 也不能越过。
222
+ if (MODEL_WRITE_OPERATIONS.has(operation)) {
223
+ if (intent.scope !== 'agent') {
224
+ return denyDecision(ctx, 'SCOPE_MISMATCH', '模型参数只能在 Agent 级配置,不支持关系级设置', operation, intent.scope, opMeta.dangerous);
225
+ }
226
+ if (!hasDaemonOwnerRole(ctx) && !(isManagementRole(role) && isCurrentAgentTarget(ctx))) {
227
+ return denyDecision(ctx, 'NOT_ALLOWED', '只有当前 Agent 的 owner/admin 可以修改模型', operation, intent.scope, opMeta.dangerous);
228
+ }
229
+ }
215
230
  if (requiresDaemonOwner(ctx, resolvedConfigCommand)) {
216
231
  if (!hasDaemonOwnerRole(ctx)) {
217
232
  const reasonCode = daemonOwnerDenialReasonCode(ctx);
@@ -129,6 +129,30 @@ const QUEUE_OPERATIONS = [['read', 'Read the current Agent message queue'], ['cl
129
129
  * 参照设计文档 docs/command-execution-role-permission-design.md 第 5 节
130
130
  */
131
131
  const OPERATIONS = [
132
+ {
133
+ id: 'proxy.read',
134
+ category: 'read',
135
+ dangerous: false,
136
+ defaultScopes: ['agent'],
137
+ description: '查看当前 daemon 的本地服务与 ServiceProxy 状态',
138
+ sources: ['agent-tool'],
139
+ },
140
+ {
141
+ id: 'proxy.configure',
142
+ category: 'process',
143
+ dangerous: true,
144
+ defaultScopes: ['process'],
145
+ description: '创建、修改、发布或删除本地服务代理配置',
146
+ sources: ['agent-tool'],
147
+ },
148
+ {
149
+ id: 'proxy.lifecycle',
150
+ category: 'process',
151
+ dangerous: true,
152
+ defaultScopes: ['process'],
153
+ description: '启动、停止、重载或守护本地服务',
154
+ sources: ['agent-tool'],
155
+ },
132
156
  // ── Model Operations ──
133
157
  {
134
158
  id: 'baseagent.models.list',
@@ -178,28 +202,29 @@ const OPERATIONS = [
178
202
  description: '检查模型可用性(可能触发网关探测)',
179
203
  sources: ['slash', 'menu.cli', 'agent-tool'],
180
204
  },
205
+ // 模型参数只在 Agent 级配置,仅 owner/admin 可写(operation-authorizer 另有代码级上限)。
181
206
  {
182
207
  id: 'model.use',
183
208
  category: 'write-own',
184
209
  dangerous: false,
185
- defaultScopes: ['relation', 'role', 'agent'],
186
- description: '切换使用的模型',
210
+ defaultScopes: ['agent'],
211
+ description: '设置 Agent 使用的模型',
187
212
  sources: ['slash', 'menu', 'menu.cli', 'agent-tool'],
188
213
  },
189
214
  {
190
215
  id: 'model.effort',
191
216
  category: 'write-own',
192
217
  dangerous: false,
193
- defaultScopes: ['relation', 'role', 'agent'],
194
- description: '设置推理努力度',
218
+ defaultScopes: ['agent'],
219
+ description: '设置 Agent 的推理强度',
195
220
  sources: ['slash', 'menu', 'menu.cli', 'agent-tool'],
196
221
  },
197
222
  {
198
223
  id: 'model.reset',
199
224
  category: 'write-own',
200
225
  dangerous: false,
201
- defaultScopes: ['relation', 'role', 'agent'],
202
- description: '重置模型配置到角色默认值',
226
+ defaultScopes: ['agent'],
227
+ description: '清除 Agent 的模型与推理强度设置',
203
228
  sources: ['slash', 'menu.cli', 'agent-tool'],
204
229
  },
205
230
  // ── Session Operations ──
@@ -463,7 +463,7 @@ async function runCreateInBackground(opts, w, service) {
463
463
  if (res.aidCreated && res.ownershipBinding)
464
464
  w.setOwnershipBinding(res.ownershipBinding);
465
465
  // 环节 4:applying_config(provider/model/effort/chatmode,agentCreateNonInteractive 之外)
466
- if (opts.provider || opts.providerServiceType || opts.model || opts.effort || opts.chatmode) {
466
+ if (opts.provider || opts.model || opts.effort || opts.chatmode) {
467
467
  curPhase = 'applying_config';
468
468
  w.begin('applying_config');
469
469
  let warned;
@@ -478,7 +478,6 @@ async function runCreateInBackground(opts, w, service) {
478
478
  baseagents[opts.baseagent] = {
479
479
  ...current,
480
480
  provider: opts.provider,
481
- ...(opts.providerServiceType ? { providerServiceType: opts.providerServiceType } : {}),
482
481
  ...(opts.model ? { model: opts.model } : {}),
483
482
  ...(opts.effort ? { effort: opts.effort } : {}),
484
483
  };
@@ -644,12 +643,9 @@ export async function execAgentAction(action, args, peerId, eventBus, service, s
644
643
  if (a.provider !== undefined && typeof a.provider !== 'string')
645
644
  return { error: 'provider 必须是字符串', code: 'INVALID_ARGS' };
646
645
  const provider = typeof a.provider === 'string' && a.provider.trim() ? a.provider.trim() : undefined;
647
- if (a.providerServiceType !== undefined && typeof a.providerServiceType !== 'string')
648
- return { error: 'providerServiceType 必须是字符串', code: 'INVALID_ARGS' };
649
- const providerServiceType = typeof a.providerServiceType === 'string' && a.providerServiceType.trim() ? a.providerServiceType.trim() : undefined;
650
646
  if (provider) {
651
647
  try {
652
- const resolved = resolveProviderServiceForBaseagent(provider, a.baseagent, providerServiceType);
648
+ const resolved = resolveProviderServiceForBaseagent(provider, a.baseagent);
653
649
  if (model && resolved.modelOverrides[model]?.enabled === false)
654
650
  throw new Error(`Model ${model} is disabled for provider ${provider}`);
655
651
  }
@@ -694,7 +690,7 @@ export async function execAgentAction(action, args, peerId, eventBus, service, s
694
690
  void runCreateInBackground({
695
691
  aid: a.aid, name: a.name, baseagent: a.baseagent,
696
692
  project: a.project, owner,
697
- provider, providerServiceType, model, effort, description, tags, chatmode: a.chatmode, avatarUrl,
693
+ provider, model, effort, description, tags, chatmode: a.chatmode, avatarUrl,
698
694
  retryFailedCreate: retry.force,
699
695
  eventBus,
700
696
  }, progressWriter, service).catch(e => logger.error(`[agent-control] runCreateInBackground unhandled ${a.aid}: ${e?.message || e}`));
@@ -1,6 +1,6 @@
1
1
  import crypto from 'node:crypto';
2
2
  import { isValidAid } from '../../aun/aid/validation.js';
3
- import { isExplicitGroupId } from '../../aun/group/index.js';
3
+ import { readAunPeerKind } from '../relation/peer-identity.js';
4
4
  import { listStaticAgentOwners } from '../../config/peer-role-resolver.js';
5
5
  import { authorizeOperation } from '../auth/auth-gateway.js';
6
6
  import { auditCommandAuthorization } from '../auth/authorization-audit.js';
@@ -93,8 +93,10 @@ export class AgentStorageMenuService {
93
93
  }
94
94
  if (!subject.menuEncrypted)
95
95
  fail('MENU_TOKEN_ENCRYPTION_REQUIRED', 'Agent storage Menu requests require E2EE');
96
- if (!isValidAid(targetAid) || isExplicitGroupId(targetAid)
97
- || !isValidAid(subject.principalId ?? '') || isExplicitGroupId(subject.principalId ?? '')
96
+ if (!isValidAid(targetAid)
97
+ || !isValidAid(subject.principalId ?? '')
98
+ || readAunPeerKind(targetAid, subject.principalId, { routeKind: 'private' }).kind !== 'private'
99
+ || readAunPeerKind(targetAid, targetAid, { routeKind: 'private' }).kind !== 'private'
98
100
  || subject.role !== 'owner' || !this.isOwner(targetAid, subject.principalId)) {
99
101
  fail('ROOT_FORBIDDEN', 'Agent cloud storage requires the static Agent owner');
100
102
  }
@@ -3,7 +3,8 @@ import { parseOwnershipCommand } from '../../aun/aid/ownership-operation.js';
3
3
  import { normalizeCliArgv } from '../../cli/cli-argv.js';
4
4
  import { resolveConfigCommand, } from '../../config/resolved-config-op.js';
5
5
  export { normalizeCliArgv, parseLegacyCliCommand, validateCliArgv } from '../../cli/cli-argv.js';
6
- const MODEL_RELATION_DEFAULT_SUBCOMMANDS = new Set(['list', 'current', 'info', 'use', 'effort', 'reset']);
6
+ // 只读 model 子命令默认补 --peer(按对端关系查模型生效值);写操作(use/effort/reset)只在 Agent 级,不补 --peer。
7
+ const MODEL_RELATION_DEFAULT_SUBCOMMANDS = new Set(['list', 'current', 'info', 'check']);
7
8
  export function withDefaultRelationContext(inputArgv, defaults) {
8
9
  const argv = normalizeCliArgv(inputArgv);
9
10
  const isModelCommand = argv[0] === 'model' && MODEL_RELATION_DEFAULT_SUBCOMMANDS.has(argv[1] || '');