evolcore 0.0.40 → 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 (226) hide show
  1. package/CHANGELOG.md +94 -1
  2. package/bin/codex-managed-hook.mjs +11 -0
  3. package/bin/ec-safe-output.js +11 -1
  4. package/dist/agents/baseagent-availability.js +1 -1
  5. package/dist/agents/baseagent.js +20 -43
  6. package/dist/agents/claude-runner.js +197 -197
  7. package/dist/agents/codex-runner.js +535 -259
  8. package/dist/agents/ecagent-runner.js +31 -12
  9. package/dist/agents/gemini-runner.js +27 -7
  10. package/dist/agents/runner-types.js +11 -3
  11. package/dist/aun/ability-device-routing.js +26 -0
  12. package/dist/aun/aid/client.js +1 -1
  13. package/dist/aun/group/fs-download.js +39 -0
  14. package/dist/aun/group/identity.js +36 -13
  15. package/dist/aun/group/operations.js +5 -0
  16. package/dist/aun/msg/managed-operation.js +72 -11
  17. package/dist/aun/msg/p2p.js +32 -7
  18. package/dist/aun/service-proxy.js +36 -12
  19. package/dist/aun/storage/download.js +30 -0
  20. package/dist/aun/storage/index.js +14 -6
  21. package/dist/channels/aun.js +367 -24
  22. package/dist/channels/daemon.js +39 -5
  23. package/dist/cli/agent-command.js +2 -0
  24. package/dist/cli/agent-create.js +98 -19
  25. package/dist/cli/agent.js +10 -3
  26. package/dist/cli/aun-commands.js +85 -41
  27. package/dist/cli/daemon-commands.js +678 -688
  28. package/dist/cli/fs-command.js +64 -2
  29. package/dist/cli/index.js +48 -4
  30. package/dist/cli/managed-command-guard.js +4 -0
  31. package/dist/cli/model.js +40 -40
  32. package/dist/cli/proxy-command.js +92 -0
  33. package/dist/cli/restart-monitor.js +17 -0
  34. package/dist/cli/role.js +85 -0
  35. package/dist/cli/session-command.js +128 -13
  36. package/dist/cli/stats.js +60 -4
  37. package/dist/cli/trigger-command.js +2 -2
  38. package/dist/config/access-policy.js +8 -1
  39. package/dist/config/boot-log.js +38 -1
  40. package/dist/config/config-field-policy.js +5 -32
  41. package/dist/config/config-manager.js +46 -39
  42. package/dist/config/config-operation-service.js +8 -11
  43. package/dist/config/contact-book-store.js +47 -21
  44. package/dist/config/contact-book.js +18 -12
  45. package/dist/config/contact-operation-service.js +3 -4
  46. package/dist/config/contact-request-service.js +11 -0
  47. package/dist/config/daemon-services.js +11 -0
  48. package/dist/config/gateway-config.js +89 -595
  49. package/dist/config/peer-role-resolver.js +15 -11
  50. package/dist/config/providers-config.js +12 -7
  51. package/dist/config/providers-import.js +3 -21
  52. package/dist/config/resolved-config-op.js +3 -0
  53. package/dist/config/role-command-service.js +166 -0
  54. package/dist/config/role-request-service.js +193 -0
  55. package/dist/config/schema-migration.js +686 -25
  56. package/dist/config-store.js +79 -3
  57. package/dist/contracts/ecweb-instance.js +41 -0
  58. package/dist/contracts/ecweb-service-protocol.js +3 -1
  59. package/dist/core/agent-application-service.js +11 -1
  60. package/dist/core/agent-ipc-registration.js +4 -0
  61. package/dist/core/agent-runtime.js +1 -1
  62. package/dist/core/auth/agent-delegation.js +82 -6
  63. package/dist/core/auth/auth-gateway.js +1 -1
  64. package/dist/core/auth/authorization-audit.js +37 -9
  65. package/dist/core/auth/delegation-authorization.js +3 -1
  66. package/dist/core/auth/operation-authorizer.js +15 -0
  67. package/dist/core/auth/operation-catalog.js +39 -6
  68. package/dist/core/command/agent-control.js +94 -19
  69. package/dist/core/command/agent-storage-menu.js +5 -3
  70. package/dist/core/command/cli-intent-parser.js +2 -1
  71. package/dist/core/command/command-handler.js +105 -145
  72. package/dist/core/command/connect-menu.js +31 -2
  73. package/dist/core/command/data-root-resolver.js +5 -4
  74. package/dist/core/command/memory-slash.js +16 -8
  75. package/dist/core/command/menu-catalog.js +6 -6
  76. package/dist/core/command/menu-handler.js +87 -163
  77. package/dist/core/command/menu-protocol.js +9 -2
  78. package/dist/core/command/role-menu.js +148 -30
  79. package/dist/core/command/slash-gate.js +13 -10
  80. package/dist/core/command/slash-handler.js +157 -352
  81. package/dist/core/daemon-control.js +8 -14
  82. package/dist/core/event-catalog.js +15 -0
  83. package/dist/core/evolagent-registry.js +4 -4
  84. package/dist/core/evolagent.js +2 -2
  85. package/dist/core/inference/text-inference.js +31 -40
  86. package/dist/core/ipc-registration.js +24 -3
  87. package/dist/core/memory/consolidation-context.js +51 -5
  88. package/dist/core/memory/consolidation-ops-records.js +1 -1
  89. package/dist/core/memory/consolidation-trigger.js +190 -190
  90. package/dist/core/memory/consolidation.js +316 -29
  91. package/dist/core/memory/forget-log.js +96 -0
  92. package/dist/core/memory/index-manager.js +27 -5
  93. package/dist/core/memory/memory-admin.js +45 -5
  94. package/dist/core/memory/memory-writer.js +163 -18
  95. package/dist/core/memory/relation-idle-monitor.js +119 -58
  96. package/dist/core/memory/relation-sweep.js +44 -39
  97. package/dist/core/message/aun-ipc-sender.js +34 -7
  98. package/dist/core/message/aun-request-registry.js +97 -3
  99. package/dist/core/message/im-renderer.js +11 -4
  100. package/dist/core/message/message-admission.js +97 -8
  101. package/dist/core/message/message-bridge.js +71 -24
  102. package/dist/core/message/message-log.js +55 -0
  103. package/dist/core/message/message-queue.js +5 -5
  104. package/dist/core/message/response-engine.js +387 -144
  105. package/dist/core/model/catalog-service.js +4 -2
  106. package/dist/core/model/config-scope.js +24 -64
  107. package/dist/core/model/field-scope.js +1 -1
  108. package/dist/core/model/model-catalog.js +37 -47
  109. package/dist/core/model/model-diagnostics.js +4 -3
  110. package/dist/core/model/model-fallback.js +10 -7
  111. package/dist/core/model/model-permission.js +3 -2
  112. package/dist/core/ownership/owner-resolver.js +25 -23
  113. package/dist/core/permission/ec-command-parser.js +138 -5
  114. package/dist/core/permission/sandbox-runtime.js +18 -1
  115. package/dist/core/permission/tool-policy.js +42 -10
  116. package/dist/core/relation/peer-identity.js +64 -1
  117. package/dist/core/role/runtime-policy.js +72 -13
  118. package/dist/core/session/session-capsule.js +197 -0
  119. package/dist/core/session/session-idle-monitor.js +1 -1
  120. package/dist/core/session/session-manager.js +168 -14
  121. package/dist/core/session/session-mapper.js +2 -0
  122. package/dist/core/session/session-renew.js +3 -3
  123. package/dist/core/skill/index-generator.js +15 -5
  124. package/dist/core/system-session/memory.js +6 -1
  125. package/dist/core/thread/thread-service.js +19 -6
  126. package/dist/directory/owner-directory-admission.js +95 -0
  127. package/dist/directory/owner-directory-authorization.js +309 -0
  128. package/dist/directory/owner-directory-cache.js +635 -0
  129. package/dist/eck/kit-renderer.js +2 -2
  130. package/dist/ecweb/basic-settings-service.js +33 -40
  131. package/dist/ecweb/message-context-service.js +110 -0
  132. package/dist/index.js +79 -17
  133. package/dist/ipc.js +189 -17
  134. package/dist/paths.js +4 -0
  135. package/dist/proxy/command.js +122 -0
  136. package/dist/proxy/ipc-service.js +68 -0
  137. package/dist/proxy/manager.js +485 -0
  138. package/dist/proxy/service-supervisor.js +603 -0
  139. package/dist/response-system/engines/v1/proactive-flow.js +16 -6
  140. package/dist/stats/budget.js +1 -1
  141. package/dist/stats/db.js +15 -0
  142. package/dist/stats/index.js +2 -2
  143. package/dist/stats/price-resolver.js +304 -5
  144. package/dist/stats/query.js +82 -3
  145. package/dist/stats/writer.js +38 -5
  146. package/dist/trigger/feedback.js +18 -7
  147. package/dist/trigger/manager.js +20 -3
  148. package/dist/trigger/parser.js +6 -3
  149. package/dist/trigger/patch.js +1 -1
  150. package/dist/trigger/system-definitions.js +43 -7
  151. package/dist/trigger/validation.js +13 -5
  152. package/dist/utils/cross-platform.js +14 -0
  153. package/dist/utils/ecweb-supervisor.js +258 -83
  154. package/dist/utils/error-utils.js +16 -2
  155. package/dist/utils/logger.js +24 -5
  156. package/dist/utils/npm-ops.js +2 -1
  157. package/dist/utils/package-version-info.js +5 -3
  158. package/dist/utils/upgrade-jobs.js +45 -5
  159. package/kits/docs/INDEX.md +1 -1
  160. package/kits/docs/aun/ABILITY_CALLING.md +20 -2
  161. package/kits/docs/channels/aun.md +9 -0
  162. package/kits/docs/evolcore/INDEX.md +2 -1
  163. package/kits/docs/evolcore/agent-create.md +3 -2
  164. package/kits/docs/evolcore/agent.md +1 -1
  165. package/kits/docs/evolcore/config.md +18 -7
  166. package/kits/docs/evolcore/contact.md +3 -0
  167. package/kits/docs/evolcore/event.md +1 -0
  168. package/kits/docs/evolcore/fs.md +16 -0
  169. package/kits/docs/evolcore/memory-architecture.md +2 -2
  170. package/kits/docs/evolcore/memory-consolidation.md +32 -8
  171. package/kits/docs/evolcore/memory.md +1 -1
  172. package/kits/docs/evolcore/menu-protocol.md +36 -0
  173. package/kits/docs/evolcore/model.md +23 -20
  174. package/kits/docs/evolcore/msg.md +21 -8
  175. package/kits/docs/evolcore/session.md +14 -0
  176. package/kits/migrations/migrate-contact-book-v2.mjs +30 -11
  177. package/kits/schemas/_meta.json +37 -4
  178. package/kits/schemas/agent-config.schema.13.json +23 -3
  179. package/kits/schemas/agent-config.schema.16.json +891 -0
  180. package/kits/schemas/daemon.schema.9.json +366 -0
  181. package/kits/schemas/defaults.schema.5.json +406 -127
  182. package/kits/schemas/relation-config.schema.11.json +260 -0
  183. package/kits/schemas/role-config.schema.1.json +7 -7
  184. package/kits/skills/.switches.json +3 -7
  185. package/kits/skills/aid-ability/SKILL.md +35 -6
  186. package/kits/skills/ec-service-proxy/SKILL.md +118 -0
  187. package/kits/skills/ec-trigger/SKILL.md +13 -5
  188. package/kits/skills/personal-assistant/SKILL.md +176 -0
  189. package/kits/skills/personal-assistant/references/01-workspace-spec.md +333 -0
  190. package/kits/skills/personal-assistant/references/02-bootstrap.md +205 -0
  191. package/kits/skills/personal-assistant/references/03-data-flow-and-gaps.md +177 -0
  192. package/kits/skills/personal-assistant/references/04-frontend-contract.md +439 -0
  193. package/kits/skills/personal-assistant/references/05-directory-reference.md +292 -0
  194. package/kits/skills/personal-assistant/references/06-render-config.md +350 -0
  195. package/kits/skills/personal-assistant/schema/workspace.schema.json +85 -0
  196. package/kits/skills/personal-assistant/schema/workspace.v1.json +66 -0
  197. package/kits/skills/personal-assistant/scripts/archive.mjs +154 -0
  198. package/kits/skills/personal-assistant/scripts/check.mjs +114 -0
  199. package/kits/skills/personal-assistant/scripts/index-rebuild.mjs +252 -0
  200. package/kits/skills/personal-assistant/scripts/ingest.mjs +344 -0
  201. package/kits/skills/personal-assistant/scripts/init.mjs +270 -0
  202. package/kits/skills/personal-assistant/scripts/lib/apply.mjs +92 -0
  203. package/kits/skills/personal-assistant/scripts/lib/schema.mjs +96 -0
  204. package/kits/skills/personal-assistant/scripts/lib/time.mjs +28 -0
  205. package/kits/skills/personal-assistant/scripts/migrate.mjs +172 -0
  206. package/kits/skills/personal-assistant/scripts/search.mjs +172 -0
  207. package/kits/skills/personal-assistant/scripts/verify.mjs +196 -0
  208. package/kits/skills/personal-assistant/templates/INDEX.md.tpl +24 -0
  209. package/kits/skills/personal-assistant/templates/README.md.tpl +108 -0
  210. package/kits/skills/personal-assistant/triggers/ingest-daily.json +23 -0
  211. package/kits/skills/personal-assistant/triggers/memory-consolidate.json +23 -0
  212. package/kits/skills/personal-assistant/triggers/report-daily.json +23 -0
  213. package/kits/skills/personal-assistant/triggers/report-weekly.json +23 -0
  214. package/kits/templates/memory-consolidation/forget.md +19 -6
  215. package/kits/templates/memory-consolidation/notes.md +1 -1
  216. package/kits/templates/memory-consolidation/profile.md +2 -2
  217. package/kits/templates/memory-consolidation/promote.md +20 -3
  218. package/kits/templates/roles/member.json +8 -1
  219. package/kits/templates/session-capsule/recovery.md +5 -0
  220. package/kits/templates/session-capsule/renew.md +5 -0
  221. package/kits/templates/system-fragments/baseagent.md +2 -2
  222. package/kits/templates/system-fragments/bootstrap.md +6 -6
  223. package/kits/templates/system-fragments/channel.md +1 -1
  224. package/kits/templates/system-fragments/memory.md +4 -4
  225. package/package.json +7 -3
  226. package/dist/stats/billing.js +0 -215
@@ -1,7 +1,7 @@
1
1
  import fs from 'node:fs';
2
2
  import { ownerResolver } from '../ownership/owner-resolver.js';
3
3
  import { agentFullAccessStatus, agentFullAccessWriteError } from '../role/runtime-policy.js';
4
- import { initializationSummary } from '../../cli/agent-create.js';
4
+ import { initializationSummary, validateInitializationModelArgs } from '../../cli/agent-create.js';
5
5
  import { agentDelete, agentEnable, agentDisable, agentList, agentShow, agentSet, agentReload, } from '../../cli/agent.js';
6
6
  import { agentCreateNonInteractive } from '../../cli/agent-create.js';
7
7
  import { logger } from '../../utils/logger.js';
@@ -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
  };
@@ -546,18 +545,78 @@ export async function execAgentAction(action, args, peerId, eventBus, service, s
546
545
  if (action === 'initialize') {
547
546
  if (!service?.initialization)
548
547
  return { error: '初始化服务不可用', code: 'NOT_CONFIGURED' };
549
- const plan = a.plan && typeof a.plan === 'object' ? a.plan : {
550
- aid: a.aid,
551
- project: typeof a.project === 'string' ? a.project : '',
552
- baseagent: a.baseagent,
553
- owners: Array.isArray(a.owners) ? a.owners : (a.owner ? [a.owner] : []),
554
- name: a.name,
555
- description: a.description,
556
- type: a.type || 'agent',
557
- tags: a.tags,
558
- ...(typeof a.persona === 'string' ? { persona: a.persona } : {}),
548
+ if (!peerId)
549
+ return { error: '缺少发起者 AID', code: 'INVALID_ARGS' };
550
+ if (a.resume !== undefined && typeof a.resume !== 'boolean') {
551
+ return { error: 'resume 必须是布尔值', code: 'INVALID_ARGS' };
552
+ }
553
+ if (a.resume === true) {
554
+ const aid = typeof a.aid === 'string' ? a.aid.trim() : '';
555
+ if (!aid || !isValidAid(aid))
556
+ return { error: 'resume 需要有效的 aid', code: 'INVALID_ARGS' };
557
+ if (Object.keys(a).some(key => !['aid', 'resume', 'context'].includes(key))) {
558
+ return { error: '恢复请求不能携带新的初始化计划', code: 'INVALID_ARGS' };
559
+ }
560
+ try {
561
+ return { data: service.initialization.resume(aid, peerId) };
562
+ }
563
+ catch (error) {
564
+ return { error: error instanceof Error ? error.message : String(error), code: error.code || 'INITIALIZE_FAILED' };
565
+ }
566
+ }
567
+ if (a.plan !== undefined && (!a.plan || typeof a.plan !== 'object' || Array.isArray(a.plan))) {
568
+ return { error: 'plan 必须是对象', code: 'INVALID_ARGS' };
569
+ }
570
+ const supplied = a.plan && typeof a.plan === 'object' && !Array.isArray(a.plan) ? a.plan : {};
571
+ if (a.project !== undefined && supplied.project !== undefined
572
+ && typeof a.project === 'string' && typeof supplied.project === 'string'
573
+ && a.project.trim() && supplied.project.trim()
574
+ && a.project.trim() !== supplied.project.trim()) {
575
+ return { error: 'project 与 plan.project 必须一致', code: 'INVALID_ARGS' };
576
+ }
577
+ const aid = supplied.aid ?? a.aid;
578
+ if (typeof aid !== 'string' || !isValidAid(aid))
579
+ return { error: '无效 Agent AID', code: 'INVALID_ARGS' };
580
+ if (a.aid !== undefined && a.aid !== aid) {
581
+ return { error: 'aid 与 plan.aid 必须一致', code: 'INVALID_ARGS' };
582
+ }
583
+ for (const owners of [supplied.owners, a.owners]) {
584
+ if (owners !== undefined && (!Array.isArray(owners) || owners.length !== 1)) {
585
+ return { error: '初始化必须指定一位 Owner', code: 'INVALID_ARGS' };
586
+ }
587
+ }
588
+ const ownerAid = supplied.ownerAid ?? supplied.owner
589
+ ?? a.ownerAid ?? a.owner
590
+ ?? (Array.isArray(supplied.owners) ? supplied.owners[0] : undefined)
591
+ ?? (Array.isArray(a.owners) ? a.owners[0] : undefined);
592
+ const rawModel = supplied.model ?? a.model;
593
+ const rawEffort = supplied.effort ?? a.effort;
594
+ for (const [field, value] of [['model', rawModel], ['effort', rawEffort]]) {
595
+ if (value !== undefined && typeof value !== 'string') {
596
+ return { error: `${field} 必须是字符串`, code: 'INVALID_ARGS' };
597
+ }
598
+ }
599
+ const effort = typeof rawEffort === 'string' && rawEffort.trim() && rawEffort.trim() !== 'auto'
600
+ ? rawEffort.trim() : undefined;
601
+ const plan = {
602
+ aid,
603
+ project: supplied.project ?? a.project ?? '',
604
+ baseagent: supplied.baseagent ?? a.baseagent,
605
+ ...(typeof rawModel === 'string' && rawModel.trim() ? { model: rawModel.trim() } : {}),
606
+ ...(effort ? { effort } : {}),
607
+ ownerAid,
608
+ name: supplied.name ?? a.name,
609
+ description: supplied.description ?? a.description,
610
+ type: supplied.type ?? a.type ?? 'agent',
611
+ tags: supplied.tags ?? a.tags,
612
+ ...(typeof (supplied.persona ?? a.persona) === 'string' ? { persona: supplied.persona ?? a.persona } : {}),
613
+ ...(typeof (supplied.avatarFile ?? a.avatarFile) === 'string' ? { avatarFile: supplied.avatarFile ?? a.avatarFile } : {}),
614
+ ...(typeof (supplied.avatarUrl ?? a.avatarUrl) === 'string' ? { avatarUrl: supplied.avatarUrl ?? a.avatarUrl } : {}),
559
615
  };
560
616
  try {
617
+ const modelError = await validateInitializationModelArgs(plan);
618
+ if (modelError)
619
+ return modelError;
561
620
  return { data: service.initialization.start(plan, peerId, a.dryRun === true) };
562
621
  }
563
622
  catch (error) {
@@ -584,12 +643,9 @@ export async function execAgentAction(action, args, peerId, eventBus, service, s
584
643
  if (a.provider !== undefined && typeof a.provider !== 'string')
585
644
  return { error: 'provider 必须是字符串', code: 'INVALID_ARGS' };
586
645
  const provider = typeof a.provider === 'string' && a.provider.trim() ? a.provider.trim() : undefined;
587
- if (a.providerServiceType !== undefined && typeof a.providerServiceType !== 'string')
588
- return { error: 'providerServiceType 必须是字符串', code: 'INVALID_ARGS' };
589
- const providerServiceType = typeof a.providerServiceType === 'string' && a.providerServiceType.trim() ? a.providerServiceType.trim() : undefined;
590
646
  if (provider) {
591
647
  try {
592
- const resolved = resolveProviderServiceForBaseagent(provider, a.baseagent, providerServiceType);
648
+ const resolved = resolveProviderServiceForBaseagent(provider, a.baseagent);
593
649
  if (model && resolved.modelOverrides[model]?.enabled === false)
594
650
  throw new Error(`Model ${model} is disabled for provider ${provider}`);
595
651
  }
@@ -634,7 +690,7 @@ export async function execAgentAction(action, args, peerId, eventBus, service, s
634
690
  void runCreateInBackground({
635
691
  aid: a.aid, name: a.name, baseagent: a.baseagent,
636
692
  project: a.project, owner,
637
- provider, providerServiceType, model, effort, description, tags, chatmode: a.chatmode, avatarUrl,
693
+ provider, model, effort, description, tags, chatmode: a.chatmode, avatarUrl,
638
694
  retryFailedCreate: retry.force,
639
695
  eventBus,
640
696
  }, progressWriter, service).catch(e => logger.error(`[agent-control] runCreateInBackground unhandled ${a.aid}: ${e?.message || e}`));
@@ -865,13 +921,31 @@ export async function execAgentQuery(args, service, subject) {
865
921
  const agentDir = path.join(resolvePaths().agentsDir, aid);
866
922
  const progress = readCreateStatus(agentDir);
867
923
  const initialization = initializationSummary(aid);
924
+ let usable;
925
+ if (initialization && service?.initialization) {
926
+ try {
927
+ const state = service.initialization.status(aid);
928
+ if (typeof state.usable === 'boolean')
929
+ usable = state.usable;
930
+ }
931
+ catch {
932
+ usable = false;
933
+ }
934
+ }
868
935
  const res = service
869
936
  ? await service.show(aid)
870
937
  : await agentShow(aid);
871
938
  if (!('ok' in res) || res.ok !== true) {
872
939
  const code = classifyError(res.error);
873
940
  if (code === 'NOT_FOUND' && initialization)
874
- return { data: { aid, lifecycle: service?.readConfig(aid)?.lifecycle ?? null, initialization } };
941
+ return {
942
+ data: {
943
+ aid,
944
+ lifecycle: service?.readConfig(aid)?.lifecycle ?? null,
945
+ initialization,
946
+ ...(usable === undefined ? {} : { usable }),
947
+ },
948
+ };
875
949
  if (code === 'NOT_FOUND' && progress)
876
950
  return { data: buildCreateProgressOnlyAgent(aid, progress) };
877
951
  return { error: res.error, code };
@@ -884,6 +958,7 @@ export async function execAgentQuery(args, service, subject) {
884
958
  const data = {
885
959
  ...res,
886
960
  ...(initialization ? { initialization } : {}),
961
+ ...(usable === undefined ? {} : { usable }),
887
962
  config: {
888
963
  ...(res.config ?? {}),
889
964
  active_baseagent: safeAgentConfig.active_baseagent ?? res.config?.baseagent ?? null,
@@ -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] || '');
@@ -36,6 +36,8 @@ import { parseTimeArg, TIME_ARG_FORMATS, splitConfigBatchGetArgv } from '../../c
36
36
  import { auditCommandAuthorization, auditFullAccessEvent, hashArgv } from '../auth/authorization-audit.js';
37
37
  import { ResponseModeRegistry } from '../../response-system/registry.js';
38
38
  import { registerBuiltinModes } from '../../response-system/modes/index.js';
39
+ import { executeResolvedRoleCommand, resolveRoleCommand } from '../../config/role-command-service.js';
40
+ import { applyApprovedRoleAssignment } from './role-menu.js';
39
41
  import { executeResolvedContactCommand, resolveContactCommand } from '../../config/contact-operation-service.js';
40
42
  import { hasTrustedFullAccessDelegation, trustedExecutionIdentityInput } from '../auth/agent-delegation.js';
41
43
  import { executeManagedAidOperation, ManagedAidOperationError, managedAidShowViewForRole, resolveManagedAidOperation, } from '../../aun/aid/managed-operation.js';
@@ -56,45 +58,6 @@ import { resolveCurrentSessionLoopTarget, sessionLoopError } from '../session/se
56
58
  export { isProcessLevelOwner } from './menu-handler.js';
57
59
  const CLI_EXEC_TIMEOUT_MS = 15_000;
58
60
  const CLI_EXEC_MAX_OUTPUT = 128 * 1024;
59
- /**
60
- * 写入用户级 ~/.claude/settings.json(与 Claude CLI 行为一致)
61
- * ⚠️ 已禁用:按需求不再修改用户的 ~/.claude/settings.json 文件。
62
- * 原会把 model/effortLevel 写入 settings.json(仅在找不到 owning agent 的 fallback 路径触发)。
63
- * 现直接返回成功且不落盘;如需恢复,取消下方注释即可。
64
- */
65
- function writeUserSettings(updates) {
66
- void updates;
67
- return { success: true };
68
- /* eslint-disable no-unreachable */
69
- // try {
70
- // const settingsPath = path.join(os.homedir(), '.claude', 'settings.json');
71
- // let settings: any = {};
72
- //
73
- // if (fs.existsSync(settingsPath)) {
74
- // settings = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'));
75
- // }
76
- //
77
- // if (updates.model !== undefined) settings.model = updates.model;
78
- // if (updates.effortLevel !== undefined) {
79
- // if (updates.effortLevel === null) {
80
- // delete settings.effortLevel;
81
- // } else {
82
- // settings.effortLevel = updates.effortLevel;
83
- // }
84
- // }
85
- //
86
- // const claudeDir = path.join(os.homedir(), '.claude');
87
- // if (!fs.existsSync(claudeDir)) {
88
- // fs.mkdirSync(claudeDir, { recursive: true });
89
- // }
90
- //
91
- // fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2), 'utf-8');
92
- // return { success: true };
93
- // } catch (error: any) {
94
- // return { success: false, error: error.message };
95
- // }
96
- /* eslint-enable no-unreachable */
97
- }
98
61
  function isAdminRole(role) {
99
62
  return isManagementRole(role);
100
63
  }
@@ -804,7 +767,7 @@ export class CommandHandler {
804
767
  reliability: {
805
768
  concurrency: 'forbid',
806
769
  missedPolicy: 'run_once',
807
- retry: { maxAttempts: 0, backoffMs: 30_000 },
770
+ retry: { maxAttempts: 1, backoffMs: 30_000 },
808
771
  },
809
772
  limits: this.limitsFromParsed(parsed),
810
773
  };
@@ -820,60 +783,6 @@ export class CommandHandler {
820
783
  return owning.projectPath;
821
784
  return process.cwd();
822
785
  }
823
- /**
824
- * 持久化 baseagent.model:写到 agent config.json;找不到 owning agent 时
825
- * 退到用户级 ~/.claude/settings.json(Claude 专用)。
826
- */
827
- persistBaseagentModel(channel, baseagentName, newModel) {
828
- const owning = this.getOwningAgent(channel);
829
- if (owning) {
830
- try {
831
- owning.setBaseagentModel(newModel, baseagentName);
832
- }
833
- catch (e) {
834
- return `⚠️ 写入 agent config 失败: ${e?.message || e}`;
835
- }
836
- return undefined;
837
- }
838
- // 无 owning agent(罕见,新结构下应当不会发生)→ 仅 Claude 走用户级 fallback
839
- if (baseagentName !== 'claude') {
840
- return `⚠️ 找不到通道 "${channel}" 所属的 self-agent`;
841
- }
842
- const updates = {};
843
- if (newModel)
844
- updates.model = newModel;
845
- const writeResult = writeUserSettings(updates);
846
- // writeUserSettings 已禁用写入,总是返回 success: true
847
- if (!writeResult.success) {
848
- return `⚠️ 写入用户配置失败: ${writeResult.error}`;
849
- }
850
- return undefined;
851
- }
852
- /**
853
- * 持久化 baseagent.effort:写到 agent config.json;找不到时退到用户级 settings。
854
- */
855
- persistBaseagentEffort(channel, baseagentName, newEffort) {
856
- const owning = this.getOwningAgent(channel);
857
- if (owning) {
858
- try {
859
- owning.setBaseagentEffort(newEffort, baseagentName);
860
- }
861
- catch (e) {
862
- return `⚠️ 写入 agent config 失败: ${e?.message || e}`;
863
- }
864
- return undefined;
865
- }
866
- if (baseagentName !== 'claude') {
867
- return `⚠️ 找不到通道 "${channel}" 所属的 self-agent`;
868
- }
869
- const updates = { effortLevel: newEffort ?? null };
870
- const writeResult = writeUserSettings(updates);
871
- // writeUserSettings 已禁用写入,总是返回 success: true
872
- if (!writeResult.success) {
873
- return `⚠️ 写入用户配置失败: ${writeResult.error}`;
874
- }
875
- return undefined;
876
- }
877
786
  /** 项目列表快捷访问(无 channel 上下文时的 fallback,尽量不用) */
878
787
  get projects() {
879
788
  return {};
@@ -2217,6 +2126,7 @@ export class CommandHandler {
2217
2126
  const subject = buildAuthSubject({
2218
2127
  selfAid: targetAid, actorId: grant.actorId, channel: grant.channel, channelType: grant.channelType,
2219
2128
  channelId: conversationId, chatType: grant.chatType, conversationId,
2129
+ sessionId,
2220
2130
  processOwners: ownerResolver.daemonOwners(),
2221
2131
  });
2222
2132
  if (targetAid !== grant.selfAid && !subject.isDaemonOwner) {
@@ -2246,6 +2156,39 @@ export class CommandHandler {
2246
2156
  return ownershipFailure(error);
2247
2157
  }
2248
2158
  }
2159
+ /**
2160
+ * Agent-managed role-request CLI entrypoint. Submitting a request never
2161
+ * changes permissions; only the Agent owner can approve it, and approval is
2162
+ * what actually applies the relation role.
2163
+ */
2164
+ async handleRoleOperation(argv, sessionId, delegationToken, delegationCommandHash) {
2165
+ if (!this.agentDelegationRegistry) {
2166
+ return { ok: false, code: 'DELEGATION_REQUIRED', error: 'Task delegation is not configured' };
2167
+ }
2168
+ const delegation = this.agentDelegationRegistry.validate(delegationToken, sessionId, delegationCommandHash);
2169
+ if (!delegation.ok)
2170
+ return { ok: false, code: delegation.code, error: delegation.reason };
2171
+ const session = await this.sessionManager.getSessionById(sessionId);
2172
+ if (!session)
2173
+ return { ok: false, code: 'INVALID_SESSION', error: 'Invalid session' };
2174
+ const grant = delegation.grant;
2175
+ const resolvedArgv = argv.includes('--self') ? argv : [...argv, '--self', grant.selfAid];
2176
+ const resolved = resolveRoleCommand(resolvedArgv);
2177
+ if (!resolved.ok)
2178
+ return { ok: false, code: resolved.code, error: resolved.reason };
2179
+ if (resolved.command.selfAid !== grant.selfAid) {
2180
+ return { ok: false, code: 'SCOPE_MISMATCH', error: 'Only the current Agent role requests can be targeted' };
2181
+ }
2182
+ try {
2183
+ const result = await executeResolvedRoleCommand(resolved.command, grant.actorId, applyApprovedRoleAssignment);
2184
+ if (!result.ok)
2185
+ return { ok: false, code: result.code, error: result.error, data: result.data };
2186
+ return { ok: true, result };
2187
+ }
2188
+ catch (error) {
2189
+ return { ok: false, code: 'ROLE_OPERATION_FAILED', error: error?.message ?? String(error) };
2190
+ }
2191
+ }
2249
2192
  async handleAidOperation(argv, sessionId, delegationToken, delegationCommandHash) {
2250
2193
  if (!this.agentDelegationRegistry) {
2251
2194
  return { ok: false, code: 'DELEGATION_REQUIRED', error: 'Task delegation is not configured' };
@@ -2742,21 +2685,49 @@ export class CommandHandler {
2742
2685
  if (sessionSelfAid && sessionSelfAid !== actorAid) {
2743
2686
  return { ok: false, code: 'INVALID_DELEGATION', error: 'Delegation self agent does not match the active session' };
2744
2687
  }
2745
- const isSelfPersonalTarget = parsed.command.targetAid === actorAid;
2746
- let currentPrivatePeer;
2747
- let currentGroup;
2748
- if (grant.channelType === 'aun' && grant.chatType === 'private') {
2688
+ let relationId;
2689
+ try {
2690
+ const relation = parsePeerKey(grant.peerKey);
2691
+ if (relation.channelType !== grant.channelType)
2692
+ throw new Error('relation channel mismatch');
2693
+ relationId = relation.channelId;
2694
+ }
2695
+ catch {
2696
+ return { ok: false, code: 'INVALID_DELEGATION', error: 'Delegation contains an invalid relation key' };
2697
+ }
2698
+ const isSelfTarget = parsed.command.targetAid === actorAid;
2699
+ const isCurrentPrivatePeerCat = grant.channelType === 'aun'
2700
+ && grant.chatType === 'private'
2701
+ && parsed.command.kind === 'cat'
2702
+ && parsed.command.targetAid === relationId;
2703
+ let storageBackend;
2704
+ if (isSelfTarget) {
2705
+ storageBackend = 'personal';
2706
+ }
2707
+ else {
2708
+ let targetType;
2749
2709
  try {
2750
- currentPrivatePeer = parsePeerKey(grant.peerKey).channelId;
2710
+ const card = await agentmdGet(parsed.command.targetAid, { withVerification: true, remoteOnly: true });
2711
+ if (card.verification.status !== 'verified') {
2712
+ return { ok: false, code: 'INVALID_TARGET', error: 'Target AID agent.md verification did not succeed' };
2713
+ }
2714
+ const frontmatter = card.content.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/)?.[1];
2715
+ const document = frontmatter ? parseDocument(frontmatter) : undefined;
2716
+ const rawTargetType = document && document.errors.length === 0
2717
+ ? document.toJS()?.type
2718
+ : undefined;
2719
+ targetType = typeof rawTargetType === 'string' ? rawTargetType.trim().toLowerCase() : undefined;
2720
+ if (!targetType) {
2721
+ return { ok: false, code: 'INVALID_TARGET', error: 'Target AID agent.md has no valid type' };
2722
+ }
2751
2723
  }
2752
2724
  catch {
2753
- return { ok: false, code: 'INVALID_DELEGATION', error: 'Delegation contains an invalid relation key' };
2725
+ return { ok: false, code: 'INVALID_TARGET', error: 'Target AID agent.md could not be verified' };
2754
2726
  }
2727
+ storageBackend = targetType === 'group' ? 'group' : 'personal';
2755
2728
  }
2756
- const isCurrentPrivatePeerCat = parsed.command.kind === 'cat'
2757
- && currentPrivatePeer !== undefined
2758
- && parsed.command.targetAid === currentPrivatePeer;
2759
- if (isSelfPersonalTarget) {
2729
+ let currentGroup;
2730
+ if (storageBackend === 'personal' && isSelfTarget) {
2760
2731
  if (grant.issuedRole !== 'owner' && !hasTrustedFullAccessDelegation(grant)) {
2761
2732
  return { ok: false, code: 'NO_PERMISSION', error: 'Managed personal storage requires the current Agent owner relation' };
2762
2733
  }
@@ -2764,56 +2735,39 @@ export class CommandHandler {
2764
2735
  return { ok: false, code: 'SCOPE_MISMATCH', error: 'Only the current Agent can access its personal storage' };
2765
2736
  }
2766
2737
  }
2767
- else if (isCurrentPrivatePeerCat) {
2738
+ else if (storageBackend === 'personal' && isCurrentPrivatePeerCat) {
2768
2739
  if (parsed.command.actorAid && parsed.command.actorAid !== actorAid) {
2769
2740
  return { ok: false, code: 'SCOPE_MISMATCH', error: 'Managed fs cannot switch the execution identity with --as' };
2770
2741
  }
2771
2742
  }
2772
- else {
2773
- const trustedFullAccess = hasTrustedFullAccessDelegation(grant);
2774
- if (trustedFullAccess) {
2775
- let targetType;
2776
- try {
2777
- const card = await agentmdGet(parsed.command.targetAid, { withVerification: true, remoteOnly: true });
2778
- if (card.verification.status !== 'verified') {
2779
- return { ok: false, code: 'INVALID_TARGET', error: 'Target AID agent.md verification did not succeed' };
2780
- }
2781
- const frontmatter = card.content.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/)?.[1];
2782
- const document = frontmatter ? parseDocument(frontmatter) : undefined;
2783
- targetType = document && document.errors.length === 0
2784
- ? String(document.toJS()?.type ?? '').trim().toLowerCase()
2785
- : undefined;
2786
- }
2787
- catch {
2788
- return { ok: false, code: 'INVALID_TARGET', error: 'Target AID agent.md could not be verified' };
2789
- }
2790
- if (targetType !== 'group') {
2791
- return { ok: false, code: 'INVALID_TARGET', error: 'Managed group storage requires a verified group AID' };
2792
- }
2793
- }
2743
+ else if (storageBackend === 'group') {
2794
2744
  if (!hasTrustedFullAccessDelegation(grant) && (grant.channelType !== 'aun' || grant.chatType !== 'group')) {
2795
- return { ok: false, code: 'SCOPE_MISMATCH', error: 'Managed group fs operations require the current AUN group relation' };
2796
- }
2797
- try {
2798
- currentGroup = parsePeerKey(grant.peerKey).channelId;
2799
- }
2800
- catch {
2801
- return { ok: false, code: 'INVALID_DELEGATION', error: 'Delegation contains an invalid relation key' };
2745
+ return { ok: false, code: 'SCOPE_MISMATCH', error: 'Group storage requires the current AUN group relation' };
2802
2746
  }
2747
+ if (grant.channelType === 'aun' && grant.chatType === 'group')
2748
+ currentGroup = relationId;
2803
2749
  if (parsed.command.actorAid && parsed.command.actorAid !== actorAid) {
2804
2750
  return { ok: false, code: 'SCOPE_MISMATCH', error: 'Managed fs cannot switch the execution identity with --as' };
2805
2751
  }
2806
2752
  if (!hasTrustedFullAccessDelegation(grant)
2807
- && !sameGroupAid(parsed.command.targetAid, currentGroup)) {
2753
+ && (!currentGroup || !sameGroupAid(parsed.command.targetAid, currentGroup))) {
2808
2754
  return { ok: false, code: 'SCOPE_MISMATCH', error: 'Only the current AUN group can be targeted' };
2809
2755
  }
2810
2756
  }
2757
+ else {
2758
+ return {
2759
+ ok: false,
2760
+ code: 'SCOPE_MISMATCH',
2761
+ error: 'Managed personal storage is limited to the current Agent and cat of the current AUN private peer',
2762
+ };
2763
+ }
2811
2764
  const resolvedCommand = parsed.command;
2812
- resolvedCommand.storageBackend = isSelfPersonalTarget || isCurrentPrivatePeerCat ? 'personal' : 'group';
2813
- resolvedCommand.actorAid = hasTrustedFullAccessDelegation(grant) && !isSelfPersonalTarget && !isCurrentPrivatePeerCat
2765
+ resolvedCommand.storageBackend = storageBackend;
2766
+ resolvedCommand.actorAid = hasTrustedFullAccessDelegation(grant) && !isSelfTarget && !isCurrentPrivatePeerCat
2814
2767
  ? (resolvedCommand.actorAid ?? actorAid)
2815
2768
  : actorAid;
2816
- const relationTarget = currentPrivatePeer ?? currentGroup;
2769
+ const relationTarget = currentGroup
2770
+ ?? (grant.channelType === 'aun' && grant.chatType === 'private' ? relationId : undefined);
2817
2771
  const subject = buildAuthSubject({
2818
2772
  selfAid: grant.selfAid,
2819
2773
  actorId: grant.actorId,
@@ -2846,7 +2800,7 @@ export class CommandHandler {
2846
2800
  subject,
2847
2801
  intent: {
2848
2802
  operation: parsed.command.operationId,
2849
- scope: isSelfPersonalTarget ? 'agent' : 'relation',
2803
+ scope: isSelfTarget ? 'agent' : 'relation',
2850
2804
  source: 'agent-tool',
2851
2805
  args: intentArgs,
2852
2806
  },
@@ -3256,6 +3210,13 @@ export class CommandHandler {
3256
3210
  : 'read';
3257
3211
  return intent(`ec.ctl.queue.${action}`);
3258
3212
  }
3213
+ // 模型参数只在 Agent 级:写操作按 agent scope 鉴权(仅当前 Agent 的 owner/admin)。
3214
+ const agentIntent = (operation, extra = {}) => ({
3215
+ operation,
3216
+ scope: 'agent',
3217
+ source: 'agent-tool',
3218
+ args: { self: selfAid, ...extra },
3219
+ });
3259
3220
  if (name === 'model') {
3260
3221
  if (args.length === 0 || args[0] === 'list')
3261
3222
  return intent('model.list');
@@ -3264,16 +3225,15 @@ export class CommandHandler {
3264
3225
  if (args[0] === 'info')
3265
3226
  return intent('model.info', { model: args[1] });
3266
3227
  if (args[0] === 'reset')
3267
- return intent('model.reset');
3268
- if (args[0] === 'check') {
3269
- return { operation: 'model.check', scope: 'agent', source: 'agent-tool', args: { self: selfAid } };
3270
- }
3271
- return intent('model.use', { model: args[0] });
3228
+ return agentIntent('model.reset');
3229
+ if (args[0] === 'check')
3230
+ return agentIntent('model.check');
3231
+ return agentIntent('model.use', { model: args[0] });
3272
3232
  }
3273
3233
  if (name === 'effort') {
3274
3234
  return args.length === 0
3275
3235
  ? intent('model.effort.current')
3276
- : intent('model.effort', { effort: args[0] });
3236
+ : agentIntent('model.effort', { effort: args[0] });
3277
3237
  }
3278
3238
  if (name === 'restart') {
3279
3239
  return { operation: 'system.restart', scope: 'process', source: 'agent-tool', args: { self: selfAid } };
@@ -3,6 +3,7 @@ import { getContactSnapshot, resolveContactView } from '../../config/contact-boo
3
3
  import { mutateAccessPolicy, readAccessPolicySnapshot, } from '../../config/access-policy.js';
4
4
  import { expirePendingContactRequests, addContact, mutateContactWithOperation, reviewContactRequest, } from '../../config/contact-request-service.js';
5
5
  import { formatPeerKey, parsePeerKey } from '../relation/peer-identity.js';
6
+ import { isValidAid } from '../../aun/aid/validation.js';
6
7
  /**
7
8
  * Connect Menu — 联系人与关系管理协议
8
9
  *
@@ -31,7 +32,7 @@ export function connectMenuOperation(kind, args, value) {
31
32
  if (kind === 'action')
32
33
  return 'connect.write';
33
34
  const resource = String(args?.resource ?? '');
34
- if (resource === 'policyMode' || resource === 'requestLimit') {
35
+ if (isAccessUpdateResource(resource)) {
35
36
  return 'connect.access.write';
36
37
  }
37
38
  if (resource === 'admin')
@@ -100,7 +101,7 @@ async function handleOptions(self, args, context) {
100
101
  {
101
102
  option: 'access',
102
103
  label: '访问设置',
103
- description: '设置消息准入模式和准入控制消息限额',
104
+ description: '设置 Owner 名录与外部联系开关、指定 AID 名单、消息准入模式和准入控制消息限额',
104
105
  },
105
106
  ],
106
107
  });
@@ -265,6 +266,10 @@ async function handleAction(req, self, context) {
265
266
  }
266
267
  function isAccessUpdateResource(resource) {
267
268
  return resource === 'policyMode'
269
+ || resource === 'allowOwnerDirectoryContacts'
270
+ || resource === 'allowOwnerAgentDirectory'
271
+ || resource === 'allowExternalContacts'
272
+ || resource === 'allowedAids'
268
273
  || resource === 'requestLimit';
269
274
  }
270
275
  function updateAccessResource(req, context, resource) {
@@ -281,6 +286,18 @@ function updateAccessResource(req, context, resource) {
281
286
  return fail('INVALID_ARGUMENT', 'policyMode must be open, contacts, or owners');
282
287
  }
283
288
  }
289
+ else if (resource === 'allowOwnerDirectoryContacts' || resource === 'allowOwnerAgentDirectory' || resource === 'allowExternalContacts') {
290
+ if (typeof decoded !== 'boolean') {
291
+ return fail('INVALID_ARGUMENT', `${resource} must be a JSON boolean`);
292
+ }
293
+ }
294
+ else if (resource === 'allowedAids') {
295
+ if (!Array.isArray(decoded)
296
+ || decoded.some(aid => typeof aid !== 'string' || !isValidAid(aid))
297
+ || new Set(decoded).size !== decoded.length) {
298
+ return fail('INVALID_ARGUMENT', 'allowedAids must be a JSON array of unique valid AIDs');
299
+ }
300
+ }
284
301
  else {
285
302
  const requestLimit = decoded;
286
303
  if (!requestLimit || typeof requestLimit !== 'object' || Array.isArray(requestLimit)
@@ -534,6 +551,18 @@ function accessPolicyWithUpdate(current, resource, decoded) {
534
551
  if (resource === 'policyMode') {
535
552
  return { ...current, policyMode: decoded };
536
553
  }
554
+ if (resource === 'allowOwnerDirectoryContacts') {
555
+ return { ...current, allowOwnerDirectoryContacts: decoded };
556
+ }
557
+ if (resource === 'allowOwnerAgentDirectory') {
558
+ return { ...current, allowOwnerAgentDirectory: decoded };
559
+ }
560
+ if (resource === 'allowExternalContacts') {
561
+ return { ...current, allowExternalContacts: decoded };
562
+ }
563
+ if (resource === 'allowedAids') {
564
+ return { ...current, allowedAids: [...decoded] };
565
+ }
537
566
  const requestLimit = decoded;
538
567
  return {
539
568
  ...current,