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
@@ -14,22 +14,21 @@ import fs from 'fs';
14
14
  import path from 'path';
15
15
  import { ensureManagedLockParent, resolveManagedLockPath } from '../core/runtime-lock.js';
16
16
  import crypto from 'crypto';
17
- import { resolvePaths, agentConfig as agentConfigPath, agentContactConfig, agentRelationConfig, agentDir, agentRelationsDir, agentRolesIndex, agentRoleConfig, } from '../paths.js';
17
+ import { resolvePaths, agentConfig as agentConfigPath, agentContactConfig, agentRelationConfig, agentRolesIndex, agentRoleConfig, } from '../paths.js';
18
18
  import { atomicReadJson, atomicWriteJson } from '../utils/atomic-write.js';
19
19
  import { fileCache } from '../core/daemon-file-cache.js';
20
20
  import { registerFile } from '../core/file-integrity/store.js';
21
21
  import { isValidAid } from '../aun/aid/validation.js';
22
22
  import { normalizeAidDomain } from '../aun/aid/domain.js';
23
- import { isExplicitGroupId } from '../aun/group/index.js';
24
23
  import { ensureRelationSharedDirectory } from '../core/relation/shared-data.js';
25
24
  import { parseContactAlias } from './contact-alias.js';
26
25
  import { loadSchema, listSchemaVersions, currentVersion, isSchemaName, } from './schema-registry.js';
27
- import { mergeLayers, expandVars, buildEnvResolver } from './merge.js';
26
+ import { mergeLayers } from './merge.js';
28
27
  import { normalizeAgentLifecycle } from './lifecycle.js';
29
28
  import { isBehaviorConfigFieldPath } from './config-field-policy.js';
30
29
  import { clearRoleStoreCache, isRoleName } from './role-store.js';
31
30
  import { writeRoleDefinition, writeRoleRegistry } from './role-service.js';
32
- import { mutateContactBookTransactionSync } from './contact-book-store.js';
31
+ import { mutateContactBookTransactionSync, resolveContactAidKind } from './contact-book-store.js';
33
32
  import { DAEMON_SCHEMA_NAME } from '../product.js';
34
33
  import { normalizeDaemonServices } from './daemon-services.js';
35
34
  import { assertProviderSelectionWrite, resolveProviderModelOverrides, validateProvidersFile } from './providers-config.js';
@@ -339,13 +338,14 @@ export function assertContactBookV2Ready() {
339
338
  if (!fs.existsSync(agentsRoot))
340
339
  return;
341
340
  const issues = [];
341
+ const contactMigrationAgentSchemaMax = 6;
342
342
  const supportedSchemas = (name, minimumVersion) => (listSchemaVersions(name)
343
343
  .filter(version => version >= minimumVersion)
344
344
  .map(version => loadSchema(name, version)));
345
- const agentSchemas = supportedSchemas('agent-config', 6);
345
+ const agentSchemas = supportedSchemas('agent-config', contactMigrationAgentSchemaMax);
346
346
  const contactSchemas = supportedSchemas('contact-book', 2);
347
347
  const relationSchemas = supportedSchemas('relation-config', 5);
348
- const inspect = (file, schemas) => {
348
+ const inspect = (file, schemas, skipNewerAgentSchema = false) => {
349
349
  let value;
350
350
  try {
351
351
  value = JSON.parse(fs.readFileSync(file, 'utf8'));
@@ -356,6 +356,14 @@ export function assertContactBookV2Ready() {
356
356
  }
357
357
  value = stripLegacyAunGatewayConfig(value, file, message => configWarn(message));
358
358
  const candidates = Array.isArray(schemas) ? schemas : [schemas];
359
+ const schemaVersion = value?.$schema_version;
360
+ if (skipNewerAgentSchema && typeof schemaVersion === 'number'
361
+ && schemaVersion > contactMigrationAgentSchemaMax
362
+ && candidates.some(schema => schema.version === schemaVersion)) {
363
+ // Contact book v2 only migrates Agent schemas through v6; later Agent
364
+ // config is left untouched by that migration and validated elsewhere.
365
+ return;
366
+ }
359
367
  if (!candidates.some(schema => schema.validate(value))) {
360
368
  const detail = (candidates.at(-1)?.validate.errors ?? [])
361
369
  .map(error => `${error.instancePath || '/'} ${error.message}`)
@@ -383,7 +391,7 @@ export function assertContactBookV2Ready() {
383
391
  const agentFile = path.join(dir, 'config.json');
384
392
  if (!fs.existsSync(agentFile))
385
393
  continue;
386
- inspect(agentFile, agentSchemas);
394
+ inspect(agentFile, agentSchemas, true);
387
395
  const contactFile = path.join(dir, 'contact.json');
388
396
  if (fs.existsSync(contactFile)) {
389
397
  inspect(contactFile, contactSchemas);
@@ -435,8 +443,11 @@ function inspectContactBookDomain(contactFile, agentFile, issues) {
435
443
  .filter(Boolean));
436
444
  const aliases = new Map();
437
445
  for (const [primaryId, entry] of Object.entries(contact?.contacts ?? {})) {
438
- if (isExplicitGroupId(primaryId)) {
439
- issues.push({ file: contactFile, detail: `group contact ${primaryId} is not supported` });
446
+ const identity = resolveContactAidKind(String(agent?.aid ?? ''), primaryId);
447
+ if (identity.kind === 'group' || ['conflict', 'invalid', 'unavailable'].includes(identity.reason)) {
448
+ issues.push({ file: contactFile, detail: identity.kind === 'group'
449
+ ? `group contact ${primaryId} is not supported`
450
+ : `contact type for ${primaryId} is unknown (${identity.reason}); explicit type evidence is required` });
440
451
  }
441
452
  if (entry?.status === 'blocked' && owners.has(primaryId)) {
442
453
  issues.push({ file: contactFile, detail: `owner contact ${primaryId} cannot be blocked` });
@@ -592,16 +603,6 @@ function requirePeer(sel, target) {
592
603
  if (!sel?.self || !sel?.peerKey)
593
604
  throw new ConfigError('PEER_REQUIRED', `${target} 需要 selector.self + peerKey`);
594
605
  }
595
- // ── env 作用域 ────────────────────────────────────────────────────────────
596
- function envScopeFor(sel) {
597
- const root = resolvePaths().root;
598
- const scope = { rootDir: root };
599
- if (sel?.self)
600
- scope.agentDir = agentDir(sel.self);
601
- if (sel?.self && sel?.peerKey)
602
- scope.relationDir = path.join(agentRelationsDir(sel.self), sel.peerKey);
603
- return scope;
604
- }
605
606
  /** 读单个配置文件,返回强类型对象;不存在返回 null(不自动创建)。未知字段保留但不校验。 */
606
607
  export function read(target, sel, opts = {}) {
607
608
  const file = targetPath(target, sel);
@@ -631,11 +632,8 @@ export function read(target, sel, opts = {}) {
631
632
  : migrated;
632
633
  // Agent read compatibility may move the legacy top-level `agents` block to
633
634
  // `baseagents`, so canonicalize effort after that structural migration.
634
- const canonicalized = normalizeBaseagentEffortCompat(normalized);
635
- if (!opts.expand)
636
- return canonicalized;
637
- const resolver = buildEnvResolver(envScopeFor(sel));
638
- return expandVars(canonicalized, resolver);
635
+ // config.json 不做 ${VAR} 展开:网关凭证与端点只在 providers.json,那里有独立展开实现。
636
+ return normalizeBaseagentEffortCompat(normalized);
639
637
  }
640
638
  /**
641
639
  * Canonicalize the legacy Codex `reasoning` config key to the public `effort`
@@ -1390,15 +1388,13 @@ export function resolveAgentConfig(sel, opts = {}) {
1390
1388
  const agentConfig = sel.self ? read(ConfigTarget.Agent, sel, opts) : null;
1391
1389
  const relationConfig = (sel.self && sel.peerKey) ? read(ConfigTarget.Relation, sel, opts) : null;
1392
1390
  const layers = [
1393
- stripStaticOwnerField(normalizeDefaultsBehaviorCompat(read(ConfigTarget.Defaults, undefined, opts))),
1391
+ stripDefaultsLegacyModelFields(stripStaticOwnerField(normalizeDefaultsBehaviorCompat(read(ConfigTarget.Defaults, undefined, opts)))),
1394
1392
  agentConfig,
1395
1393
  stripRelationRoleData(stripStaticOwnerField(relationConfig)),
1396
1394
  ];
1397
1395
  const merged = mergeLayers(layers, fields);
1398
- // A baseagent block is a configuration record rather than an atomic value:
1399
- // selecting a model at Agent or relation scope must retain the defaults
1400
- // gateway credentials and endpoint. Keep the generic dictionary merge
1401
- // contract unchanged for every other field.
1396
+ // Model and service selections inherit defaults and are overridden by Agent;
1397
+ // relation config remains role-only for these fields.
1402
1398
  merged.baseagents = mergeBaseagentBlocks(layers);
1403
1399
  merged.Services = layers.reduce((selections, layer) => {
1404
1400
  for (const [serviceType, selection] of Object.entries(layer?.Services ?? {})) {
@@ -1461,18 +1457,27 @@ function stripStaticOwnerField(config) {
1461
1457
  && !Object.prototype.hasOwnProperty.call(config, 'groupSlashRequireMentions')
1462
1458
  && !Object.prototype.hasOwnProperty.call(config, 'fullaccess'))
1463
1459
  return config;
1464
- // fullaccess and groupSlashRequireMentions are Agent-only. Relation/defaults
1465
- // files allow forward-compatible unknown properties, so strip it before the
1466
- // generic merge chain can treat a manually written value as an override.
1467
1460
  const { owner: _owner, owners: _owners, admins: _admins, access: _access, groupSlashRequireMentions: _groupSlashRequireMentions, fullaccess: _fullaccess, ...rest } = config;
1468
1461
  return rest;
1469
1462
  }
1463
+ function stripDefaultsLegacyModelFields(config) {
1464
+ if (!config)
1465
+ return config;
1466
+ const { models: _models, decision_model: _decisionModel, ...rest } = config;
1467
+ return rest;
1468
+ }
1470
1469
  function stripRelationRoleData(config) {
1471
1470
  if (!config || (!Object.prototype.hasOwnProperty.call(config, 'role')
1472
1471
  && !Object.prototype.hasOwnProperty.call(config, 'roles')
1473
- && !Object.prototype.hasOwnProperty.call(config, 'decision_model')))
1472
+ && !Object.prototype.hasOwnProperty.call(config, 'active_baseagent')
1473
+ && !Object.prototype.hasOwnProperty.call(config, 'baseagents')
1474
+ && !Object.prototype.hasOwnProperty.call(config, 'model')
1475
+ && !Object.prototype.hasOwnProperty.call(config, 'models')
1476
+ && !Object.prototype.hasOwnProperty.call(config, 'Services')
1477
+ && !Object.prototype.hasOwnProperty.call(config, 'decision_model')
1478
+ && !Object.prototype.hasOwnProperty.call(config, 'sessionFullAccess')))
1474
1479
  return config;
1475
- const { role: _role, roles: _legacyRoles, decision_model: _decisionModel, ...rest } = config;
1480
+ const { role: _role, roles: _legacyRoles, active_baseagent: _activeBaseagent, baseagents: _baseagents, model: _model, models: _models, Services: _services, decision_model: _decisionModel, sessionFullAccess: _sessionFullAccess, ...rest } = config;
1476
1481
  return rest;
1477
1482
  }
1478
1483
  // ── effective(合并视图)─────────────────────────────────────────────────
@@ -1494,9 +1499,7 @@ export function resolveEffective(sel, opts = {}) {
1494
1499
  owners: [...new Set([...getOwners(sel.self ?? config.aid ?? ''), ...configuredOwnerList(config)])],
1495
1500
  fullaccess: config.fullaccess,
1496
1501
  aun: config.aun,
1497
- decision_model: config.decision_model,
1498
1502
  channels: config.channels ?? [],
1499
- models: config.models,
1500
1503
  projects: config.projects,
1501
1504
  capabilities: config.capabilities,
1502
1505
  readonlySourceDiagnostics: config.readonlySourceDiagnostics,
@@ -1513,7 +1516,6 @@ export function resolveEffective(sel, opts = {}) {
1513
1516
  autoMentionQuietWindowMs: config.autoMentionQuietWindowMs
1514
1517
  ?? (typeof autoMentionQuietWindowMsDefault === 'number' ? autoMentionQuietWindowMsDefault : 3000),
1515
1518
  groupSlashRequireMentions: config.groupSlashRequireMentions ?? true,
1516
- model: config.model,
1517
1519
  responseMode: config.responseMode,
1518
1520
  responseModeParams: config.responseModeParams,
1519
1521
  flush_delay: config.flush_delay,
@@ -1572,12 +1574,17 @@ export function routeFieldPath(fieldPath, scope) {
1572
1574
  if (topField === 'sessionLoop') {
1573
1575
  throw new ConfigError('SESSION_LOOP_MANAGED', 'sessionLoop is managed through the dedicated /loop or session Menu entry');
1574
1576
  }
1577
+ if (topField === 'sessionFullAccess') {
1578
+ throw new ConfigError('SESSION_FULLACCESS_MANAGED', 'sessionFullAccess is managed through the dedicated /fa or session Menu entry');
1579
+ }
1575
1580
  if (scope === 'process')
1576
1581
  return routeIn(DAEMON_SCHEMA_NAME, ConfigTarget.Process, topField);
1577
1582
  if (scope === 'defaults') {
1578
1583
  if (isBehaviorConfigFieldPath(fieldPath)
1579
1584
  && topField !== 'session_renew'
1580
- && topField !== 'autoMentionQuietWindowMs') {
1585
+ && topField !== 'autoMentionQuietWindowMs'
1586
+ && topField !== 'active_baseagent'
1587
+ && topField !== 'baseagents') {
1581
1588
  throw new ConfigError('DEFAULT_BEHAVIOR_REJECT', `--default 不支持行为字段: ${fieldPath}`);
1582
1589
  }
1583
1590
  return routeIn('defaults', ConfigTarget.Defaults, topField);
@@ -1650,7 +1657,7 @@ export function listFields(scope) {
1650
1657
  const add = (name, target) => {
1651
1658
  const s = loadSchema(name);
1652
1659
  for (const f of s.fields.keys()) {
1653
- if (f !== 'sessionLoop')
1660
+ if (f !== 'sessionLoop' && f !== 'sessionFullAccess')
1654
1661
  out.push(mkRoute(s, target, f));
1655
1662
  }
1656
1663
  };
@@ -6,8 +6,7 @@ import fs from 'fs';
6
6
  import path from 'path';
7
7
  import { resolvePaths, agentDir, agentRelationConfig } from '../paths.js';
8
8
  import { roleMenuQuery, roleMenuUpdate } from '../core/command/role-menu.js';
9
- import { parsePeerKey, PeerIdentityCache } from '../core/relation/peer-identity.js';
10
- import { isExplicitGroupId } from '../aun/group/index.js';
9
+ import { parsePeerKey, resolveAunPeerKind } from '../core/relation/peer-identity.js';
11
10
  import { isUnsupportedBaseagentConfigField } from './config-field-policy.js';
12
11
  export const AUTHENTICATED_CONFIG_ROLE_ENV = 'EVOLCORE_AUTHENTICATED_CONFIG_ROLE';
13
12
  export function executeResolvedConfigCommand(command, options = {}) {
@@ -64,7 +63,6 @@ async function executeRelationRoleCommand(op, options) {
64
63
  if (!op.self || !op.peerKey) {
65
64
  return { ok: false, code: 'PEER_REQUIRED', error: 'role requires --self <aid> --peer <peer-aid>' };
66
65
  }
67
- const target = roleTargetFromPeerKey(op.self, op.peerKey);
68
66
  const context = options.roleContext ?? {
69
67
  self: op.self,
70
68
  actorRole: options.role || 'owner',
@@ -76,6 +74,7 @@ async function executeRelationRoleCommand(op, options) {
76
74
  if (context.self !== op.self) {
77
75
  return { ok: false, code: 'SCOPE_MISMATCH', error: 'Role target does not match the receiving Agent' };
78
76
  }
77
+ const target = await roleTargetFromPeerKey(op.self, op.peerKey);
79
78
  const targetArgs = { self: op.self, view: 'target', target };
80
79
  const current = await roleMenuQuery(context, targetArgs);
81
80
  const explicitRole = current?.assignment?.explicitRole
@@ -140,7 +139,7 @@ async function executeRelationRoleCommand(op, options) {
140
139
  roleDetails: updatedDetails,
141
140
  };
142
141
  }
143
- function roleTargetFromPeerKey(self, peerKey) {
142
+ async function roleTargetFromPeerKey(self, peerKey) {
144
143
  let parsed;
145
144
  try {
146
145
  parsed = parsePeerKey(peerKey);
@@ -151,13 +150,11 @@ function roleTargetFromPeerKey(self, peerKey) {
151
150
  if (parsed.channelType !== 'aun') {
152
151
  throw new ConfigError('NOT_SUPPORTED', 'Relation role assignments currently support AUN peers only');
153
152
  }
154
- const relation = read(ConfigTarget.Relation, { self, peerKey });
155
- const identity = PeerIdentityCache.get('aun', parsed.channelId, agentDir(self));
156
- const verifiedType = identity?.aid === parsed.channelId && identity.source === 'agentmd' && identity.verifiedAt > 0
157
- ? identity.type : undefined;
158
- const isGroup = relation?.targetKind ? relation.targetKind === 'group'
159
- : verifiedType ? verifiedType === 'group' : isExplicitGroupId(parsed.channelId);
160
- return isGroup
153
+ const resolution = await resolveAunPeerKind(self, parsed.channelId);
154
+ if (resolution.kind === 'unknown') {
155
+ throw new ConfigError('TARGET_TYPE_UNKNOWN', `Cannot establish relation type (${resolution.reason}): ${parsed.channelId}`);
156
+ }
157
+ return resolution.kind === 'group'
161
158
  ? { kind: 'group', groupId: parsed.channelId }
162
159
  : { kind: 'private', peerAid: parsed.channelId };
163
160
  }
@@ -2,13 +2,12 @@ import crypto from 'crypto';
2
2
  import fs from 'fs';
3
3
  import path from 'path';
4
4
  import { isValidAid } from '../aun/aid/validation.js';
5
- import { isExplicitGroupId } from '../aun/group/index.js';
6
- import { agentConfig, agentContactAuditPath, agentContactConfig, agentDir, agentRelationsDir, resolvePaths } from '../paths.js';
5
+ import { agentConfig, agentContactAuditPath, agentContactConfig, agentDir, agentRelationConfig, agentRelationsDir, resolvePaths } from '../paths.js';
7
6
  import { atomicReadJson, atomicWrite, atomicWriteJson } from '../utils/atomic-write.js';
8
7
  import { fileCache } from '../core/daemon-file-cache.js';
9
8
  import { unregisterFile } from '../core/file-integrity/store.js';
10
9
  import { ensureManagedLockParent, resolveManagedLockPath } from '../core/runtime-lock.js';
11
- import { parsePeerKey } from '../core/relation/peer-identity.js';
10
+ import { formatPeerKey, parsePeerKey, readAunPeerKind, recordAunPeerRoute } from '../core/relation/peer-identity.js';
12
11
  import { ConfigTarget, notifyConfigWrite, validateConfig } from './config-manager.js';
13
12
  import { ownerResolver } from '../core/ownership/owner-resolver.js';
14
13
  import { parseContactAlias } from './contact-alias.js';
@@ -98,8 +97,13 @@ export function synchronizeManagementContactsSync(selfAid) {
98
97
  export function synchronizeOwnershipContactsSync(subjectAid) {
99
98
  synchronizeManagementContactsSync(subjectAid);
100
99
  const ownerAid = ownerResolver.owner(subjectAid);
101
- if (!ownerAid || !fs.existsSync(agentConfig(ownerAid)))
100
+ if (!ownerAid || !fs.existsSync(agentConfig(subjectAid)) || !fs.existsSync(agentConfig(ownerAid)))
102
101
  return;
102
+ // The registered local Agent establishes the type; ownership only selects its Owner's Contact Book.
103
+ const kind = recordAunPeerRoute(ownerAid, subjectAid, 'private');
104
+ if (kind.kind !== 'private') {
105
+ throw new ContactMutationError('CONTACT_TYPE_UNKNOWN', `Managed Agent type conflicts with Owner relation: ${subjectAid}`);
106
+ }
103
107
  // Add the subject to its local Owner's contacts, preserving existing admission decisions.
104
108
  mutateContactBookSync({
105
109
  selfAid: ownerAid,
@@ -107,10 +111,15 @@ export function synchronizeOwnershipContactsSync(subjectAid) {
107
111
  mutation: { type: 'ensure-contacts', primaryIds: [subjectAid] },
108
112
  });
109
113
  }
114
+ /** Read pending relation changes together with verified identity evidence. */
115
+ export function resolveContactAidKind(selfAid, aid, changes = []) {
116
+ const relation = readTransactionJson(agentRelationConfig(selfAid, formatPeerKey('aun', aid)), changes);
117
+ return readAunPeerKind(selfAid, aid, { relation });
118
+ }
110
119
  function managementRoleMapForAgent(selfAid, changes) {
111
120
  const roles = {};
112
121
  for (const owner of ownerResolver.protocolOwners(selfAid)) {
113
- if (isValidAid(owner) && !isExplicitGroupId(owner))
122
+ if (isValidAid(owner))
114
123
  roles[owner] = 'owner';
115
124
  }
116
125
  const relationsRoot = agentRelationsDir(selfAid);
@@ -138,9 +147,11 @@ function managementRoleMapForAgent(selfAid, changes) {
138
147
  catch {
139
148
  continue;
140
149
  }
141
- if (parsed.channelType !== 'aun' || !isValidAid(parsed.channelId) || isExplicitGroupId(parsed.channelId))
150
+ if (parsed.channelType !== 'aun' || !isValidAid(parsed.channelId))
142
151
  continue;
143
152
  const config = readTransactionJson(path.join(relationsRoot, peerKey, 'config.json'), changes);
153
+ if (readAunPeerKind(selfAid, parsed.channelId, { relation: config }).kind !== 'private')
154
+ continue;
144
155
  if (config?.targetKind !== 'group' && config?.role === 'admin' && roles[parsed.channelId] !== 'owner') {
145
156
  roles[parsed.channelId] = 'admin';
146
157
  }
@@ -206,7 +217,7 @@ function mutateContactBookSyncInternal(request, transactionChanges) {
206
217
  }
207
218
  validateTransactionChanges(selfAid, transactionChanges);
208
219
  const next = cloneBook(current);
209
- applyMutation(next, request.mutation, selfAid);
220
+ applyMutation(next, request.mutation, selfAid, transactionChanges);
210
221
  synchronizeManagementRoles(next, selfAid, transactionChanges);
211
222
  if (request.mutation.type === 'replace') {
212
223
  const errors = validateConfig(ConfigTarget.Contact, next);
@@ -326,7 +337,7 @@ function mutateContactBookPreparedSyncInternal(selfAid, prepare) {
326
337
  release();
327
338
  }
328
339
  }
329
- function applyMutation(book, mutation, selfAid) {
340
+ function applyMutation(book, mutation, selfAid, changes = []) {
330
341
  if (mutation.type === 'replace') {
331
342
  book.contacts = cloneBook(mutation.contact).contacts;
332
343
  return;
@@ -334,12 +345,12 @@ function applyMutation(book, mutation, selfAid) {
334
345
  const contacts = book.contacts;
335
346
  if (mutation.type === 'batch') {
336
347
  for (const item of mutation.mutations)
337
- applyMutation(book, item, selfAid);
348
+ applyMutation(book, item, selfAid, changes);
338
349
  return;
339
350
  }
340
351
  if (mutation.type === 'ensure-contacts') {
341
352
  for (const rawPrimaryId of mutation.primaryIds) {
342
- const primaryId = normalizeContactAid(rawPrimaryId);
353
+ const primaryId = normalizeContactAid(rawPrimaryId, selfAid, changes);
343
354
  if (!contacts[primaryId])
344
355
  contacts[primaryId] = {};
345
356
  }
@@ -348,12 +359,23 @@ function applyMutation(book, mutation, selfAid) {
348
359
  if (mutation.type === 'sync-management-roles') {
349
360
  return;
350
361
  }
351
- const primaryId = normalizeContactAid(mutation.primaryId);
352
- const existing = contacts[primaryId];
353
- if (mutation.type === 'set-status') {
354
- if (isOwner(selfAid, primaryId) && mutation.status !== 'active') {
362
+ const rawPrimaryId = String(mutation.primaryId || '').trim();
363
+ if (isOwner(selfAid, rawPrimaryId)) {
364
+ if (mutation.type === 'set-status' && mutation.status !== 'active') {
355
365
  throw new ContactMutationError('OWNER_PROTECTED', 'An Agent owner must remain active');
356
366
  }
367
+ if (mutation.type === 'set-request') {
368
+ throw new ContactMutationError('OWNER_PROTECTED', 'An Agent owner cannot submit a contact request');
369
+ }
370
+ }
371
+ const prior = contacts[rawPrimaryId];
372
+ const preservesAdmission = !!prior && (mutation.type === 'set-display-name' || mutation.type === 'unbind-alias'
373
+ || mutation.type === 'expire-request'
374
+ || (mutation.type === 'review-request' && mutation.decision !== 'approve')
375
+ || (mutation.type === 'set-status' && mutation.status !== 'active'));
376
+ const primaryId = normalizeContactAid(mutation.primaryId, selfAid, changes, preservesAdmission);
377
+ const existing = contacts[primaryId];
378
+ if (mutation.type === 'set-status') {
357
379
  contacts[primaryId] = compactEntry({
358
380
  ...existing,
359
381
  status: mutation.status === 'active' ? undefined : mutation.status,
@@ -363,9 +385,6 @@ function applyMutation(book, mutation, selfAid) {
363
385
  return;
364
386
  }
365
387
  if (mutation.type === 'set-request') {
366
- if (isOwner(selfAid, primaryId)) {
367
- throw new ContactMutationError('OWNER_PROTECTED', 'An Agent owner cannot submit a contact request');
368
- }
369
388
  contacts[primaryId] = compactEntry({
370
389
  ...existing,
371
390
  status: 'pending',
@@ -458,7 +477,11 @@ function validateContactBook(book, selfAid, changes = []) {
458
477
  const agent = readTransactionJson(agentConfig(selfAid), changes);
459
478
  const configuredChannelKeys = readConfiguredContactChannelKeys(selfAid, agent);
460
479
  for (const [primaryId, entry] of Object.entries(book.contacts)) {
461
- if (!isValidAid(primaryId) || isExplicitGroupId(primaryId)) {
480
+ const kind = resolveContactAidKind(selfAid, primaryId, changes);
481
+ // Retain an existing record when type evidence was removed (for example
482
+ // an Owner or relation was revoked). Registration still requires private
483
+ // evidence in normalizeContactAid, and permission consumers recheck type.
484
+ if (!isValidAid(primaryId) || kind.kind === 'group' || (kind.kind === 'unknown' && kind.reason !== 'missing')) {
462
485
  throw new ContactMutationError('INVALID_CONTACT_BOOK', `Invalid contact AID: ${primaryId}`);
463
486
  }
464
487
  if (entry.status && isOwner(selfAid, primaryId)) {
@@ -748,10 +771,13 @@ function normalizeAid(value, label) {
748
771
  throw new ContactMutationError('INVALID_AID', `Invalid ${label}: ${JSON.stringify(value)}`);
749
772
  return aid;
750
773
  }
751
- function normalizeContactAid(value) {
774
+ function normalizeContactAid(value, selfAid, changes = [], preservesAdmission = false) {
752
775
  const aid = normalizeAid(value, 'contact AID');
753
- if (isExplicitGroupId(aid)) {
754
- throw new ContactMutationError('INVALID_AID', `Contact Book does not support group AID: ${JSON.stringify(value)}`);
776
+ const resolution = resolveContactAidKind(selfAid, aid, changes);
777
+ if (resolution.kind !== 'private' && !(preservesAdmission && resolution.reason === 'missing')) {
778
+ throw new ContactMutationError('INVALID_AID', resolution.kind === 'group'
779
+ ? `Contact Book does not support group AID: ${JSON.stringify(value)}`
780
+ : `Contact AID type is unknown (${resolution.reason}): ${JSON.stringify(value)}`);
755
781
  }
756
782
  return aid;
757
783
  }
@@ -1,10 +1,10 @@
1
1
  import { agentContactConfig } from '../paths.js';
2
2
  import { isValidAid } from '../aun/aid/validation.js';
3
- import { isExplicitGroupId } from '../aun/group/index.js';
4
3
  import { ConfigTarget, read, validateConfig } from './config-manager.js';
5
- import { ContactMutationError, contactRevision, mutateContactBookSync } from './contact-book-store.js';
4
+ import { ContactMutationError, contactRevision, resolveContactAidKind, mutateContactBookSync } from './contact-book-store.js';
6
5
  import { formatContactAlias, normalizeContactChannelKey, parseContactAlias, } from './contact-alias.js';
7
- import { getProtocolOwners } from '../core/ownership/owner-resolver.js';
6
+ import { getOwners } from '../core/ownership/owner-resolver.js';
7
+ import { readAunPeerKind } from '../core/relation/peer-identity.js';
8
8
  export class ContactBookError extends Error {
9
9
  code;
10
10
  constructor(code, message) {
@@ -58,7 +58,7 @@ export function resolvePrimaryId(selfAid, channelType, actorId, channelKey) {
58
58
  return resolvePrincipal(selfAid, channelType, actor, channelKey).principalId ?? actor;
59
59
  }
60
60
  export function bindContactAlias(selfAid, primaryId, channelType, actorId, channelKey) {
61
- const primary = normalizePrimaryId(primaryId);
61
+ const primary = normalizePrimaryId(primaryId, selfAid);
62
62
  const type = String(channelType || '').trim().toLowerCase();
63
63
  const actor = String(actorId || '').trim();
64
64
  if (type === 'aun') {
@@ -88,7 +88,7 @@ export function bindContactAlias(selfAid, primaryId, channelType, actorId, chann
88
88
  }
89
89
  }
90
90
  export function unbindContactAlias(selfAid, primaryId, channelType, actorId, channelKey) {
91
- const primary = normalizePrimaryId(primaryId);
91
+ const primary = normalizePrimaryId(primaryId, selfAid, true);
92
92
  const type = String(channelType || '').trim().toLowerCase();
93
93
  const actor = String(actorId || '').trim();
94
94
  const canonicalChannelKey = normalizeContactChannelKey(selfAid, type, channelKey);
@@ -149,11 +149,12 @@ export function resolveContactView(selfAid, primaryId) {
149
149
  export function isBlockedContact(selfAid, primaryId) {
150
150
  return resolveContactView(selfAid, primaryId).blocked;
151
151
  }
152
- export function isAcceptedContact(selfAid, primaryId) {
152
+ export function isAcceptedContact(selfAid, primaryId, routeKind) {
153
153
  const id = String(primaryId || '').trim();
154
154
  const snapshot = getContactSnapshot(selfAid);
155
155
  const entry = snapshot.contacts.get(id);
156
- return !!entry && (entry.status === undefined || entry.status === 'active');
156
+ return !!entry && (entry.status === undefined || entry.status === 'active')
157
+ && readAunPeerKind(selfAid, id, { routeKind }).kind === 'private';
157
158
  }
158
159
  /**
159
160
  * 对端展示名:联系人簿 displayName → principalId。仅用于展示(预览行/日志),
@@ -183,7 +184,8 @@ function buildSnapshot(book, selfAid, aliases) {
183
184
  const blockedIndex = new Set();
184
185
  const owners = new Set(listAgentOwners(selfAid));
185
186
  for (const [primaryId, rawEntry] of Object.entries(book.contacts)) {
186
- if (!isValidAid(primaryId) || isExplicitGroupId(primaryId)) {
187
+ const kind = resolveContactAidKind(selfAid, primaryId);
188
+ if (!isValidAid(primaryId) || kind.kind === 'group' || (kind.kind === 'unknown' && kind.reason !== 'missing')) {
187
189
  throw new ContactBookError('INVALID_CONTACT_BOOK', `Invalid contact AID: ${primaryId}`);
188
190
  }
189
191
  if (rawEntry.status === 'blocked' && owners.has(primaryId)) {
@@ -224,7 +226,9 @@ function buildAliasMap(book, selfAid) {
224
226
  const aliasToPrimary = new Map();
225
227
  const conflictingAliases = new Set();
226
228
  for (const [primaryId, entry] of Object.entries(book?.contacts ?? {})) {
227
- if (!isValidAid(primaryId) || isExplicitGroupId(primaryId) || !entry || typeof entry !== 'object')
229
+ const kind = resolveContactAidKind(selfAid, primaryId);
230
+ if (!isValidAid(primaryId) || kind.kind === 'group' || (kind.kind === 'unknown' && kind.reason !== 'missing')
231
+ || !entry || typeof entry !== 'object')
228
232
  continue;
229
233
  for (const rawAlias of entry.aliases ?? []) {
230
234
  const parsed = parseContactAlias(rawAlias, selfAid);
@@ -246,13 +250,15 @@ function buildAliasMap(book, selfAid) {
246
250
  }
247
251
  return { aliasToPrimary, conflictingAliases };
248
252
  }
249
- function normalizePrimaryId(value) {
253
+ function normalizePrimaryId(value, selfAid, allowMissing = false) {
250
254
  const id = String(value || '').trim();
251
- if (!isValidAid(id) || isExplicitGroupId(id)) {
255
+ const type = resolveContactAidKind(selfAid, id);
256
+ if (!isValidAid(id) || (type.kind !== 'private' && !(allowMissing && type.reason === 'missing'))) {
252
257
  throw new ContactBookError('INVALID_PRIMARY_ID', `Invalid individual contact AID: ${String(value)}`);
253
258
  }
254
259
  return id;
255
260
  }
256
261
  function listAgentOwners(selfAid) {
257
- return getProtocolOwners(selfAid);
262
+ // Keep configured Owners usable while protocol consensus is unavailable.
263
+ return getOwners(selfAid);
258
264
  }
@@ -1,6 +1,5 @@
1
1
  import fs from 'fs';
2
2
  import { isValidAid } from '../aun/aid/validation.js';
3
- import { isExplicitGroupId } from '../aun/group/index.js';
4
3
  import { agentConfig } from '../paths.js';
5
4
  import { getContactSnapshot, resolveContactView } from './contact-book.js';
6
5
  import { ContactMutationError } from './contact-book-store.js';
@@ -33,7 +32,7 @@ export function resolveContactCommand(argv) {
33
32
  };
34
33
  }
35
34
  if (command === 'approve' || command === 'reject' || command === 'block-request') {
36
- if (!isValidAid(subcommand || '') || isExplicitGroupId(subcommand || '')) {
35
+ if (!isValidAid(subcommand || '')) {
37
36
  return invalid('INVALID_AID', 'primaryId must be a valid individual AID');
38
37
  }
39
38
  const requestId = String(argValue(args, '--request-id') || '').trim();
@@ -55,7 +54,7 @@ export function resolveContactCommand(argv) {
55
54
  };
56
55
  }
57
56
  if (command === 'block' || command === 'unblock') {
58
- if (!isValidAid(subcommand || '') || isExplicitGroupId(subcommand || '')) {
57
+ if (!isValidAid(subcommand || '')) {
59
58
  return invalid('INVALID_AID', 'primaryId must be a valid individual AID');
60
59
  }
61
60
  return {
@@ -71,7 +70,7 @@ export function resolveContactCommand(argv) {
71
70
  };
72
71
  }
73
72
  if (command === 'add') {
74
- if (!isValidAid(subcommand || '') || isExplicitGroupId(subcommand || '')) {
73
+ if (!isValidAid(subcommand || '')) {
75
74
  return invalid('INVALID_AID', 'primaryId must be a valid individual AID');
76
75
  }
77
76
  return {
@@ -1,6 +1,7 @@
1
1
  import crypto from 'crypto';
2
2
  import fs from 'fs';
3
3
  import { isValidAid } from '../aun/aid/validation.js';
4
+ import { recordAunPeerRoute, resolveAunPeerKind } from '../core/relation/peer-identity.js';
4
5
  import { agentContactOperations } from '../paths.js';
5
6
  import { listStaticAgentAdmins, listStaticAgentOwners } from './peer-role-resolver.js';
6
7
  import { listAgentOwners } from './access-policy.js';
@@ -48,6 +49,11 @@ export async function addContact(input) {
48
49
  if (!isValidAid(primaryId)) {
49
50
  throw new ContactMutationError('INVALID_AID', `Invalid contact AID: ${primaryId}`);
50
51
  }
52
+ const identity = await resolveAunPeerKind(input.selfAid, primaryId);
53
+ if (identity.kind !== 'private') {
54
+ throw new ContactMutationError(identity.kind === 'group' ? 'INVALID_AID' : 'CONTACT_TYPE_UNKNOWN', identity.kind === 'group' ? `Contact Book does not support group AID: ${primaryId}`
55
+ : `Cannot establish private contact type (${identity.reason}): ${primaryId}`);
56
+ }
51
57
  const at = new Date(input.now ?? Date.now()).toISOString();
52
58
  const logFile = agentContactOperations(input.selfAid);
53
59
  const result = await mutateContactBookPrepared(input.selfAid, ({ contact, contactRevision }) => {
@@ -94,6 +100,11 @@ export async function submitContactRequest(input) {
94
100
  if (owners.length === 0) {
95
101
  return { code: 'no-owner', contactRevision: '' };
96
102
  }
103
+ const identity = input.routeKind
104
+ ? recordAunPeerRoute(input.selfAid, applicantAid, input.routeKind)
105
+ : await resolveAunPeerKind(input.selfAid, applicantAid);
106
+ if (identity.kind !== 'private')
107
+ return { code: 'invalid-applicant', contactRevision: '' };
97
108
  const note = normalizeNote(input.note);
98
109
  if (note === null) {
99
110
  return { code: 'invalid-note', contactRevision: '' };
@@ -1,5 +1,16 @@
1
+ export const SERVICE_RESTART_MAX_ATTEMPTS = 3;
2
+ export const SERVICE_RESTART_WINDOW_MS = 900000;
3
+ export const SERVICE_RESTART_BACKOFF_MS = 5000;
4
+ export const SERVICE_HEALTH_INTERVALS = {
5
+ tcp: { startup: 500, running: 10000 },
6
+ http: { startup: 1000, running: 15000 },
7
+ };
1
8
  const SERVICE_TYPES = new Set(['http', 'websocket', 'ssh']);
2
9
  const SERVICE_VISIBILITIES = new Set(['public', 'private', 'aun-auth']);
10
+ /** Preserve legacy ECWeb ownership; other services are external unless explicitly managed. */
11
+ export function serviceRuntimeMode(service) {
12
+ return service.runtime?.mode ?? (service.name === 'ecweb' ? 'managed' : 'external');
13
+ }
3
14
  export const DEFAULT_ECWEB_PORT = 42705;
4
15
  function isRecord(value) {
5
16
  return !!value && typeof value === 'object' && !Array.isArray(value);