evolcore 0.0.41 → 0.0.42-test.0

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 (190) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/bin/codex-managed-hook.mjs +9 -5
  3. package/dist/agents/baseagent.js +156 -16
  4. package/dist/agents/claude-runner.js +10 -3
  5. package/dist/agents/codex/catalog.js +8 -4
  6. package/dist/agents/codex-runner.js +236 -59
  7. package/dist/agents/ecagent-runner.js +82 -13
  8. package/dist/aun/aid/agentmd.js +106 -27
  9. package/dist/aun/aid/client.js +1 -1
  10. package/dist/aun/aid/control-aid.js +65 -13
  11. package/dist/aun/aid/identity.js +70 -4
  12. package/dist/aun/aid/index.js +2 -2
  13. package/dist/aun/service-proxy.js +25 -1
  14. package/dist/channels/aun.js +242 -209
  15. package/dist/channels/dingtalk.js +1 -1
  16. package/dist/channels/feishu.js +1 -1
  17. package/dist/channels/qqbot.js +1 -1
  18. package/dist/channels/wechat.js +1 -1
  19. package/dist/channels/wecom.js +1 -1
  20. package/dist/cli/agent-command.js +183 -3
  21. package/dist/cli/agent-create.js +92 -86
  22. package/dist/cli/agent.js +136 -1
  23. package/dist/cli/aun-commands.js +137 -35
  24. package/dist/cli/bench.js +8 -2
  25. package/dist/cli/command-log.js +1 -1
  26. package/dist/cli/daemon-commands.js +235 -51
  27. package/dist/cli/debug-mode.js +1 -1
  28. package/dist/cli/directory.js +170 -0
  29. package/dist/cli/index.js +40 -30
  30. package/dist/cli/init-channel.js +4 -4
  31. package/dist/cli/init.js +47 -32
  32. package/dist/cli/managed-command-guard.js +4 -1
  33. package/dist/cli/model.js +27 -18
  34. package/dist/cli/pa-workspace-command.js +191 -0
  35. package/dist/cli/{contact.js → peer.js} +19 -25
  36. package/dist/cli/restart-monitor.js +11 -4
  37. package/dist/cli/thread-command.js +47 -18
  38. package/dist/cli/version.js +18 -18
  39. package/dist/config/access-policy.js +29 -12
  40. package/dist/config/boot-log.js +65 -10
  41. package/dist/config/builtin-roles.js +2 -4
  42. package/dist/config/config-field-policy.js +3 -0
  43. package/dist/config/config-manager.js +28 -20
  44. package/dist/config/{contact-bind-code.js → peer-bind-code.js} +6 -6
  45. package/dist/config/{contact-book-store.js → peer-book-store.js} +75 -75
  46. package/dist/config/{contact-book-v2-startup.js → peer-book-v2-startup.js} +2 -2
  47. package/dist/config/{contact-book.js → peer-book.js} +47 -47
  48. package/dist/config/peer-operation-service.js +132 -0
  49. package/dist/config/{contact-request-service.js → peer-request-service.js} +90 -90
  50. package/dist/config/peer-role-resolver.js +3 -3
  51. package/dist/config/providers-config.js +17 -8
  52. package/dist/config/providers.js +1 -1
  53. package/dist/config/schema-migration.js +336 -39
  54. package/dist/core/agent-application-service.js +8 -2
  55. package/dist/core/agent-create-status.js +4 -5
  56. package/dist/core/agent-ipc-registration.js +5 -4
  57. package/dist/core/agent-runtime.js +30 -17
  58. package/dist/core/auth/operation-authorizer.js +0 -24
  59. package/dist/core/auth/operation-catalog.js +4 -20
  60. package/dist/core/baseagent-loader.js +27 -3
  61. package/dist/core/bootstrap-service.js +5 -22
  62. package/dist/core/capability/capability-manager.js +52 -35
  63. package/dist/core/channel-loader.js +43 -2
  64. package/dist/core/channel-runtime.js +2 -2
  65. package/dist/core/command/agent-control.js +54 -18
  66. package/dist/core/command/command-handler.js +92 -72
  67. package/dist/core/command/connect-menu.js +35 -42
  68. package/dist/core/command/daemon-diagnostics.js +41 -5
  69. package/dist/core/command/data-root-error.js +10 -0
  70. package/dist/core/command/data-root-resolver.js +53 -13
  71. package/dist/core/command/menu-catalog.js +1 -0
  72. package/dist/core/command/menu-handler.js +163 -65
  73. package/dist/core/command/menu-protocol.js +52 -0
  74. package/dist/core/command/pa-workspace-calendar.js +223 -0
  75. package/dist/core/command/pa-workspace-store.js +459 -0
  76. package/dist/core/command/role-menu.js +2 -2
  77. package/dist/core/command/slash-gate.js +1 -1
  78. package/dist/core/command/slash-handler.js +57 -41
  79. package/dist/core/daemon-lifecycle.js +90 -31
  80. package/dist/core/evolagent.js +6 -10
  81. package/dist/core/handoff/runtime.js +11 -4
  82. package/dist/core/host-snapshot.js +208 -0
  83. package/dist/core/initialization/service.js +152 -20
  84. package/dist/core/ipc-registration.js +33 -4
  85. package/dist/core/memory/batch-meta.js +27 -0
  86. package/dist/core/memory/consolidation-ops-records.js +44 -1
  87. package/dist/core/memory/consolidation.js +169 -27
  88. package/dist/core/message/aun-ipc-sender.js +2 -8
  89. package/dist/core/message/im-renderer.js +56 -3
  90. package/dist/core/message/message-admission.js +121 -124
  91. package/dist/core/message/message-bridge.js +38 -54
  92. package/dist/core/message/message-queue.js +7 -0
  93. package/dist/core/message/outbound.js +34 -9
  94. package/dist/core/message/response-engine.js +154 -73
  95. package/dist/core/model/catalog-service.js +1 -1
  96. package/dist/core/model/config-scope.js +2 -2
  97. package/dist/core/model/model-catalog.js +5 -4
  98. package/dist/core/model/model-diagnostics.js +6 -5
  99. package/dist/core/model/model-fallback.js +3 -6
  100. package/dist/core/model/model-permission.js +1 -1
  101. package/dist/core/ownership/owner-resolver.js +9 -9
  102. package/dist/core/permission/approval-gateway.js +1 -1
  103. package/dist/core/permission/ec-command-parser.js +2 -2
  104. package/dist/core/permission/tool-canonical.js +96 -46
  105. package/dist/core/permission/tool-error-code.js +41 -0
  106. package/dist/core/permission/tool-policy.js +71 -47
  107. package/dist/core/role/runtime-policy.js +1 -1
  108. package/dist/core/session/session-idle-monitor.js +10 -0
  109. package/dist/core/session/session-manager.js +2 -4
  110. package/dist/core/session/session-title.js +36 -8
  111. package/dist/core/system-session/memory.js +2 -7
  112. package/dist/core/thread/command-parser.js +6 -2
  113. package/dist/core/thread/ipc-operation.js +51 -36
  114. package/dist/core/thread/thread-operation.js +29 -61
  115. package/dist/core/thread/thread-service.js +57 -13
  116. package/dist/directory/canonical-digest.js +54 -0
  117. package/dist/directory/owner-directory-admission.js +114 -43
  118. package/dist/directory/owner-directory-agentmd-sync.js +89 -0
  119. package/dist/directory/owner-directory-cache.js +847 -459
  120. package/dist/directory/owner-directory-markdown.js +272 -0
  121. package/dist/directory/owner-directory-query-operation.js +195 -0
  122. package/dist/directory/owner-directory-remark-operation.js +147 -0
  123. package/dist/directory/owner-directory-remarks.js +145 -0
  124. package/dist/directory/owner-directory-scope.js +55 -0
  125. package/dist/directory/owner-directory-search.js +148 -0
  126. package/dist/directory/owner-directory-store.js +227 -0
  127. package/dist/eck/kit-renderer.js +1 -0
  128. package/dist/ecweb/basic-settings-service.js +4 -1
  129. package/dist/ecweb/message-context-service.js +13 -9
  130. package/dist/index.js +195 -37
  131. package/dist/ipc.js +86 -22
  132. package/dist/paths.js +11 -8
  133. package/dist/product.js +2 -0
  134. package/dist/proxy/manager.js +13 -2
  135. package/dist/proxy/service-supervisor.js +8 -1
  136. package/dist/trigger/history.js +23 -0
  137. package/dist/trigger/scheduler.js +3 -0
  138. package/dist/utils/atomic-write.js +21 -0
  139. package/dist/utils/cross-platform.js +35 -0
  140. package/dist/utils/ecweb-supervisor.js +42 -0
  141. package/dist/utils/error-utils.js +2 -1
  142. package/dist/utils/evolcore-version.js +19 -0
  143. package/dist/utils/host-info.js +242 -5
  144. package/dist/utils/instance-registry.js +28 -6
  145. package/dist/utils/logger.js +59 -14
  146. package/dist/utils/machine-info.js +46 -0
  147. package/dist/utils/process-introspect.js +166 -2
  148. package/dist/utils/startup-trace.js +245 -0
  149. package/ecagent/dist/agent-loop.js +27 -13
  150. package/ecagent/dist/harness/agent-harness.js +3 -3
  151. package/ecagent/dist/harness/types.d.ts +1 -0
  152. package/ecagent/dist/types.d.ts +1 -0
  153. package/kits/docs/INDEX.md +1 -1
  154. package/kits/docs/aun/AUN/346/266/210/346/201/257/347/261/273/345/236/213/344/270/216/345/261/236/346/200/247.md +72 -0
  155. package/kits/docs/evolcore/INDEX.md +3 -2
  156. package/kits/docs/evolcore/agent-create.md +17 -27
  157. package/kits/docs/evolcore/agent.md +4 -1
  158. package/kits/docs/evolcore/aid.md +3 -1
  159. package/kits/docs/evolcore/config.md +16 -5
  160. package/kits/docs/evolcore/ctl.md +9 -0
  161. package/kits/docs/evolcore/ec-capabilities.md +19 -0
  162. package/kits/docs/evolcore/memory-consolidation-batches.md +79 -5
  163. package/kits/docs/evolcore/menu-exec-schema-commands.md +2 -1
  164. package/kits/docs/evolcore/menu-protocol.md +1 -0
  165. package/kits/docs/evolcore/model.md +13 -4
  166. package/kits/docs/evolcore/msg.md +1 -1
  167. package/kits/docs/evolcore/pa-workspace.md +51 -0
  168. package/kits/docs/evolcore/peer.md +73 -0
  169. package/kits/docs/evolcore/thread-chain.md +4 -1
  170. package/kits/eck_manifest.json +21 -0
  171. package/kits/rules/06-channel.md +1 -1
  172. package/kits/schemas/_meta.json +12 -1
  173. package/kits/schemas/agent-config.schema.16.json +6 -0
  174. package/kits/schemas/agent-config.schema.17.json +897 -0
  175. package/kits/schemas/daemon.schema.9.json +8 -1
  176. package/kits/skills/ec-agent-create/SKILL.md +2 -2
  177. package/kits/skills/ec-identity/SKILL.md +45 -27
  178. package/kits/skills/ec-service-proxy/SKILL.md +7 -2
  179. package/kits/skills/personal-assistant/references/03-data-flow-and-gaps.md +4 -5
  180. package/kits/skills/thread-ops/SKILL.md +11 -11
  181. package/kits/templates/bootstrap-welcome.md +3 -15
  182. package/kits/templates/message-fragments/item.md +1 -1
  183. package/kits/templates/system-fragments/bootstrap.md +24 -23
  184. package/kits/templates/system-fragments/commands.md +12 -5
  185. package/kits/templates/system-fragments/thread.md +18 -3
  186. package/package.json +6 -4
  187. package/dist/config/contact-operation-service.js +0 -235
  188. package/dist/directory/owner-directory-authorization.js +0 -309
  189. package/kits/docs/evolcore/contact.md +0 -78
  190. /package/dist/config/{contact-alias.js → peer-alias.js} +0 -0
@@ -2,7 +2,7 @@ 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 { agentConfig, agentContactAuditPath, agentContactConfig, agentDir, agentRelationConfig, agentRelationsDir, resolvePaths } from '../paths.js';
5
+ import { agentConfig, agentPeerAuditPath, agentPeerConfig, agentDir, agentRelationConfig, agentRelationsDir, resolvePaths } from '../paths.js';
6
6
  import { atomicReadJson, atomicWrite, atomicWriteJson } from '../utils/atomic-write.js';
7
7
  import { fileCache } from '../core/daemon-file-cache.js';
8
8
  import { unregisterFile } from '../core/file-integrity/store.js';
@@ -10,7 +10,7 @@ import { ensureManagedLockParent, resolveManagedLockPath } from '../core/runtime
10
10
  import { formatPeerKey, parsePeerKey, readAunPeerKind, recordAunPeerRoute } from '../core/relation/peer-identity.js';
11
11
  import { ConfigTarget, notifyConfigWrite, validateConfig } from './config-manager.js';
12
12
  import { ownerResolver } from '../core/ownership/owner-resolver.js';
13
- import { parseContactAlias } from './contact-alias.js';
13
+ import { parseContactAlias } from './peer-alias.js';
14
14
  import { clearRoleStoreCache } from './role-store.js';
15
15
  import { currentVersion } from './schema-registry.js';
16
16
  const LOCK_NAME = '.contact-book-mutation.lock';
@@ -18,34 +18,34 @@ const JOURNAL_NAME = '.contact-book-mutation.json';
18
18
  const LOCK_WAIT_MS = 5_000;
19
19
  const LOCK_RETRY_MS = 20;
20
20
  const CORRUPT_LOCK_STALE_MS = LOCK_WAIT_MS;
21
- export const EMPTY_CONTACT_REVISION = crypto.createHash('sha256').update('').digest('hex');
22
- export class ContactMutationError extends Error {
21
+ export const EMPTY_PEER_REVISION = crypto.createHash('sha256').update('').digest('hex');
22
+ export class PeerMutationError extends Error {
23
23
  code;
24
24
  data;
25
25
  constructor(code, message, data) {
26
26
  super(message);
27
27
  this.code = code;
28
28
  this.data = data;
29
- this.name = 'ContactMutationError';
29
+ this.name = 'PeerMutationError';
30
30
  }
31
31
  }
32
32
  const mutationTails = new Map();
33
- export function contactRevision(config) {
33
+ export function peerRevision(config) {
34
34
  if (!config)
35
- return EMPTY_CONTACT_REVISION;
35
+ return EMPTY_PEER_REVISION;
36
36
  return crypto.createHash('sha256').update(stableStringify(config)).digest('hex');
37
37
  }
38
- export function readContactRevision(selfAid) {
39
- return contactRevision(readContactBookFromDisk(selfAid));
38
+ export function readPeerRevision(selfAid) {
39
+ return peerRevision(readContactBookFromDisk(selfAid));
40
40
  }
41
- export function mutateContactBook(request) {
41
+ export function mutatePeerBook(request) {
42
42
  return enqueueContactMutation(request, []);
43
43
  }
44
44
  /**
45
45
  * Prepare a mutation while holding the same cross-process lock used by every Contact Book write.
46
46
  * The callback must stay synchronous so the lock is never retained across an await boundary.
47
47
  */
48
- export function mutateContactBookPrepared(selfAid, prepare) {
48
+ export function mutatePeerBookPrepared(selfAid, prepare) {
49
49
  const normalizedAid = normalizeAid(selfAid, 'self AID');
50
50
  const previous = mutationTails.get(normalizedAid) ?? Promise.resolve();
51
51
  let release;
@@ -60,11 +60,11 @@ export function mutateContactBookPrepared(selfAid, prepare) {
60
60
  mutationTails.delete(normalizedAid);
61
61
  });
62
62
  }
63
- export function mutateContactBookTransaction(request, changes) {
63
+ export function mutatePeerBookTransaction(request, changes) {
64
64
  return enqueueContactMutation(request, changes);
65
65
  }
66
66
  /** Synchronous transaction variant for configuration writes that must commit atomically with contacts. */
67
- export function mutateContactBookTransactionSync(request, changes) {
67
+ export function mutatePeerBookTransactionSync(request, changes) {
68
68
  return mutateContactBookSyncInternal(request, changes);
69
69
  }
70
70
  function enqueueContactMutation(request, changes) {
@@ -83,36 +83,36 @@ function enqueueContactMutation(request, changes) {
83
83
  });
84
84
  }
85
85
  /** Synchronous compatibility entry for channel bind flows. The critical section has no await. */
86
- export function mutateContactBookSync(request) {
86
+ export function mutatePeerBookSync(request) {
87
87
  return mutateContactBookSyncInternal(request, []);
88
88
  }
89
- export function synchronizeManagementContactsSync(selfAid) {
90
- return mutateContactBookSync({
89
+ export function synchronizeManagementPeersSync(selfAid) {
90
+ return mutatePeerBookSync({
91
91
  selfAid,
92
92
  actor: 'management-role-sync',
93
93
  mutation: { type: 'sync-management-roles' },
94
94
  });
95
95
  }
96
96
  /** Synchronize contacts using current verified ownership, never a requested binding target. */
97
- export function synchronizeOwnershipContactsSync(subjectAid) {
98
- synchronizeManagementContactsSync(subjectAid);
97
+ export function synchronizeOwnershipPeersSync(subjectAid) {
98
+ synchronizeManagementPeersSync(subjectAid);
99
99
  const ownerAid = ownerResolver.owner(subjectAid);
100
100
  if (!ownerAid || !fs.existsSync(agentConfig(subjectAid)) || !fs.existsSync(agentConfig(ownerAid)))
101
101
  return;
102
102
  // The registered local Agent establishes the type; ownership only selects its Owner's Contact Book.
103
103
  const kind = recordAunPeerRoute(ownerAid, subjectAid, 'private');
104
104
  if (kind.kind !== 'private') {
105
- throw new ContactMutationError('CONTACT_TYPE_UNKNOWN', `Managed Agent type conflicts with Owner relation: ${subjectAid}`);
105
+ throw new PeerMutationError('CONTACT_TYPE_UNKNOWN', `Managed Agent type conflicts with Owner relation: ${subjectAid}`);
106
106
  }
107
107
  // Add the subject to its local Owner's contacts, preserving existing admission decisions.
108
- mutateContactBookSync({
108
+ mutatePeerBookSync({
109
109
  selfAid: ownerAid,
110
110
  actor: 'ownership-contact-sync',
111
111
  mutation: { type: 'ensure-contacts', primaryIds: [subjectAid] },
112
112
  });
113
113
  }
114
114
  /** Read pending relation changes together with verified identity evidence. */
115
- export function resolveContactAidKind(selfAid, aid, changes = []) {
115
+ export function resolvePeerAidKind(selfAid, aid, changes = []) {
116
116
  const relation = readTransactionJson(agentRelationConfig(selfAid, formatPeerKey('aun', aid)), changes);
117
117
  return readAunPeerKind(selfAid, aid, { relation });
118
118
  }
@@ -158,7 +158,7 @@ function managementRoleMapForAgent(selfAid, changes) {
158
158
  }
159
159
  return roles;
160
160
  }
161
- export function synchronizeAllManagementContactsSync() {
161
+ export function synchronizeAllManagementPeersSync() {
162
162
  const agentsRoot = resolvePaths().agentsDir;
163
163
  let entries = [];
164
164
  try {
@@ -173,13 +173,13 @@ export function synchronizeAllManagementContactsSync() {
173
173
  for (const entry of entries) {
174
174
  if (!entry.isDirectory() || !isValidAid(entry.name) || !fs.existsSync(agentConfig(entry.name)))
175
175
  continue;
176
- if (synchronizeManagementContactsSync(entry.name).changed)
176
+ if (synchronizeManagementPeersSync(entry.name).changed)
177
177
  changed += 1;
178
178
  }
179
179
  return changed;
180
180
  }
181
181
  /** Recover every interrupted Contact transaction before startup reads config. */
182
- export function recoverAllContactBookMutationsSync() {
182
+ export function recoverAllPeerBookMutationsSync() {
183
183
  const agentsRoot = resolvePaths().agentsDir;
184
184
  if (!fs.existsSync(agentsRoot))
185
185
  return 0;
@@ -205,14 +205,14 @@ function mutateContactBookSyncInternal(request, transactionChanges) {
205
205
  const release = acquireAgentLock(selfAid);
206
206
  try {
207
207
  recoverMutation(selfAid);
208
- const file = agentContactConfig(selfAid);
208
+ const file = agentPeerConfig(selfAid);
209
209
  const current = readContactBookFromDisk(selfAid);
210
- const previousRevision = contactRevision(current);
210
+ const previousRevision = peerRevision(current);
211
211
  if (request.expectedContactRevision !== undefined
212
212
  && request.expectedContactRevision !== previousRevision) {
213
- throw new ContactMutationError('CONFLICT', 'Contact book changed since it was read', {
213
+ throw new PeerMutationError('CONFLICT', 'Contact book changed since it was read', {
214
214
  expectedContactRevision: request.expectedContactRevision,
215
- contactRevision: previousRevision,
215
+ peerRevision: previousRevision,
216
216
  });
217
217
  }
218
218
  validateTransactionChanges(selfAid, transactionChanges);
@@ -220,9 +220,9 @@ function mutateContactBookSyncInternal(request, transactionChanges) {
220
220
  applyMutation(next, request.mutation, selfAid, transactionChanges);
221
221
  synchronizeManagementRoles(next, selfAid, transactionChanges);
222
222
  if (request.mutation.type === 'replace') {
223
- const errors = validateConfig(ConfigTarget.Contact, next);
223
+ const errors = validateConfig(ConfigTarget.Peer, next);
224
224
  if (errors.length)
225
- throw new ContactMutationError('INVALID_CONTACT_BOOK', errors.join('; '));
225
+ throw new PeerMutationError('INVALID_CONTACT_BOOK', errors.join('; '));
226
226
  }
227
227
  else {
228
228
  validateContactBook(next, selfAid, transactionChanges);
@@ -230,9 +230,9 @@ function mutateContactBookSyncInternal(request, transactionChanges) {
230
230
  const omitEmptySync = request.mutation.type === 'sync-management-roles'
231
231
  && current === null
232
232
  && Object.keys(next.contacts).length === 0;
233
- const nextRevision = omitEmptySync ? previousRevision : contactRevision(next);
233
+ const nextRevision = omitEmptySync ? previousRevision : peerRevision(next);
234
234
  if (nextRevision === previousRevision && transactionChanges.length === 0) {
235
- return { changed: false, contactRevision: previousRevision, previousContactRevision: previousRevision, contact: next };
235
+ return { changed: false, peerRevision: previousRevision, previousContactRevision: previousRevision, contact: next };
236
236
  }
237
237
  const before = readTextOrNull(file);
238
238
  const after = `${JSON.stringify(next, null, 2)}\n`;
@@ -252,7 +252,7 @@ function mutateContactBookSyncInternal(request, transactionChanges) {
252
252
  throw error;
253
253
  }
254
254
  if (nextRevision !== previousRevision) {
255
- notifyConfigWrite(ConfigTarget.Contact, { self: selfAid });
255
+ notifyConfigWrite(ConfigTarget.Peer, { self: selfAid });
256
256
  appendAudit(selfAid, request, previousRevision, nextRevision);
257
257
  }
258
258
  for (const change of transactionChanges)
@@ -261,7 +261,7 @@ function mutateContactBookSyncInternal(request, transactionChanges) {
261
261
  clearRoleStoreCache(selfAid);
262
262
  return {
263
263
  changed: nextRevision !== previousRevision,
264
- contactRevision: nextRevision,
264
+ peerRevision: nextRevision,
265
265
  previousContactRevision: previousRevision,
266
266
  contact: next,
267
267
  };
@@ -274,20 +274,20 @@ function mutateContactBookPreparedSyncInternal(selfAid, prepare) {
274
274
  const release = acquireAgentLock(selfAid);
275
275
  try {
276
276
  recoverMutation(selfAid);
277
- const file = agentContactConfig(selfAid);
277
+ const file = agentPeerConfig(selfAid);
278
278
  const current = readContactBookFromDisk(selfAid);
279
- const previousRevision = contactRevision(current);
279
+ const previousRevision = peerRevision(current);
280
280
  const next = cloneBook(current);
281
- const prepared = prepare({ contact: next, contactRevision: previousRevision });
281
+ const prepared = prepare({ contact: next, peerRevision: previousRevision });
282
282
  if (prepared.mutation)
283
283
  applyMutation(next, prepared.mutation, selfAid);
284
284
  synchronizeManagementRoles(next, selfAid, []);
285
285
  validateContactBook(next, selfAid);
286
- const nextRevision = contactRevision(next);
286
+ const nextRevision = peerRevision(next);
287
287
  if (nextRevision === previousRevision) {
288
288
  return {
289
289
  changed: false,
290
- contactRevision: previousRevision,
290
+ peerRevision: previousRevision,
291
291
  previousContactRevision: previousRevision,
292
292
  contact: next,
293
293
  value: prepared.value,
@@ -296,7 +296,7 @@ function mutateContactBookPreparedSyncInternal(selfAid, prepare) {
296
296
  const preparedChanges = prepared.beforeCommit?.({
297
297
  contact: next,
298
298
  previousContactRevision: previousRevision,
299
- contactRevision: nextRevision,
299
+ peerRevision: nextRevision,
300
300
  });
301
301
  const before = readTextOrNull(file);
302
302
  const after = `${JSON.stringify(next, null, 2)}\n`;
@@ -319,7 +319,7 @@ function mutateContactBookPreparedSyncInternal(selfAid, prepare) {
319
319
  recoverMutation(selfAid);
320
320
  throw error;
321
321
  }
322
- notifyConfigWrite(ConfigTarget.Contact, { self: selfAid });
322
+ notifyConfigWrite(ConfigTarget.Peer, { self: selfAid });
323
323
  appendAudit(selfAid, {
324
324
  selfAid,
325
325
  actor: prepared.actor,
@@ -327,7 +327,7 @@ function mutateContactBookPreparedSyncInternal(selfAid, prepare) {
327
327
  }, previousRevision, nextRevision);
328
328
  return {
329
329
  changed: true,
330
- contactRevision: nextRevision,
330
+ peerRevision: nextRevision,
331
331
  previousContactRevision: previousRevision,
332
332
  contact: next,
333
333
  value: prepared.value,
@@ -362,10 +362,10 @@ function applyMutation(book, mutation, selfAid, changes = []) {
362
362
  const rawPrimaryId = String(mutation.primaryId || '').trim();
363
363
  if (isOwner(selfAid, rawPrimaryId)) {
364
364
  if (mutation.type === 'set-status' && mutation.status !== 'active') {
365
- throw new ContactMutationError('OWNER_PROTECTED', 'An Agent owner must remain active');
365
+ throw new PeerMutationError('OWNER_PROTECTED', 'An Agent owner must remain active');
366
366
  }
367
367
  if (mutation.type === 'set-request') {
368
- throw new ContactMutationError('OWNER_PROTECTED', 'An Agent owner cannot submit a contact request');
368
+ throw new PeerMutationError('OWNER_PROTECTED', 'An Agent owner cannot submit a contact request');
369
369
  }
370
370
  }
371
371
  const prior = contacts[rawPrimaryId];
@@ -395,10 +395,10 @@ function applyMutation(book, mutation, selfAid, changes = []) {
395
395
  }
396
396
  if (mutation.type === 'review-request') {
397
397
  if (!existing || existing.status !== 'pending' || existing.pendingRequest?.id !== mutation.requestId) {
398
- throw new ContactMutationError('REQUEST_STALE', 'The contact request has changed or was already handled');
398
+ throw new PeerMutationError('REQUEST_STALE', 'The contact request has changed or was already handled');
399
399
  }
400
400
  if (Date.parse(existing.pendingRequest.expiresAt) <= Date.parse(mutation.now)) {
401
- throw new ContactMutationError('REQUEST_EXPIRED', 'The contact request has expired');
401
+ throw new PeerMutationError('REQUEST_EXPIRED', 'The contact request has expired');
402
402
  }
403
403
  if (mutation.decision === 'reject') {
404
404
  delete contacts[primaryId];
@@ -435,12 +435,12 @@ function applyMutation(book, mutation, selfAid, changes = []) {
435
435
  const eligible = isOwner(selfAid, primaryId)
436
436
  || (!!existing && (existing.status === undefined || existing.status === 'active'));
437
437
  if (!eligible) {
438
- throw new ContactMutationError('CONTACT_NOT_ACTIVE', 'Only an active contact or Agent owner can bind an alias');
438
+ throw new PeerMutationError('CONTACT_NOT_ACTIVE', 'Only an active contact or Agent owner can bind an alias');
439
439
  }
440
440
  }
441
441
  for (const [owner, entry] of Object.entries(contacts)) {
442
442
  if (owner !== primaryId && entry.aliases?.includes(mutation.alias)) {
443
- throw new ContactMutationError('ALIAS_CONFLICT', `Alias ${mutation.alias} is already bound to ${owner}`);
443
+ throw new PeerMutationError('ALIAS_CONFLICT', `Alias ${mutation.alias} is already bound to ${owner}`);
444
444
  }
445
445
  }
446
446
  const aliases = Array.isArray(contacts[primaryId]?.aliases) ? [...contacts[primaryId].aliases] : [];
@@ -453,7 +453,7 @@ function applyMutation(book, mutation, selfAid, changes = []) {
453
453
  removeAliasEverywhere(contacts, mutation.alias, primaryId);
454
454
  return;
455
455
  }
456
- throw new ContactMutationError('INVALID_MUTATION', `Unsupported Contact Book mutation: ${String(mutation?.type)}`);
456
+ throw new PeerMutationError('INVALID_MUTATION', `Unsupported Contact Book mutation: ${String(mutation?.type)}`);
457
457
  }
458
458
  function synchronizeManagementRoles(book, selfAid, changes) {
459
459
  const roles = managementRoleMapForAgent(selfAid, changes);
@@ -469,51 +469,51 @@ function synchronizeManagementRoles(book, selfAid, changes) {
469
469
  }
470
470
  }
471
471
  function validateContactBook(book, selfAid, changes = []) {
472
- const schemaErrors = validateConfig(ConfigTarget.Contact, book);
472
+ const schemaErrors = validateConfig(ConfigTarget.Peer, book);
473
473
  if (schemaErrors.length) {
474
- throw new ContactMutationError('INVALID_CONTACT_BOOK', schemaErrors.join('; '));
474
+ throw new PeerMutationError('INVALID_CONTACT_BOOK', schemaErrors.join('; '));
475
475
  }
476
476
  const aliases = new Map();
477
477
  const agent = readTransactionJson(agentConfig(selfAid), changes);
478
478
  const configuredChannelKeys = readConfiguredContactChannelKeys(selfAid, agent);
479
479
  for (const [primaryId, entry] of Object.entries(book.contacts)) {
480
- const kind = resolveContactAidKind(selfAid, primaryId, changes);
480
+ const kind = resolvePeerAidKind(selfAid, primaryId, changes);
481
481
  // Retain an existing record when type evidence was removed (for example
482
482
  // an Owner or relation was revoked). Registration still requires private
483
483
  // evidence in normalizeContactAid, and permission consumers recheck type.
484
484
  if (!isValidAid(primaryId) || kind.kind === 'group' || (kind.kind === 'unknown' && kind.reason !== 'missing')) {
485
- throw new ContactMutationError('INVALID_CONTACT_BOOK', `Invalid contact AID: ${primaryId}`);
485
+ throw new PeerMutationError('INVALID_CONTACT_BOOK', `Invalid contact AID: ${primaryId}`);
486
486
  }
487
487
  if (entry.status && isOwner(selfAid, primaryId)) {
488
- throw new ContactMutationError('OWNER_PROTECTED', 'An Agent owner must remain active');
488
+ throw new PeerMutationError('OWNER_PROTECTED', 'An Agent owner must remain active');
489
489
  }
490
490
  if (entry.status === 'pending') {
491
491
  if (!entry.pendingRequest || !Number.isFinite(Date.parse(entry.pendingRequest.submittedAt))
492
492
  || !Number.isFinite(Date.parse(entry.pendingRequest.expiresAt))
493
493
  || Date.parse(entry.pendingRequest.expiresAt) <= Date.parse(entry.pendingRequest.submittedAt)) {
494
- throw new ContactMutationError('INVALID_CONTACT_BOOK', `Invalid pending request for ${primaryId}`);
494
+ throw new PeerMutationError('INVALID_CONTACT_BOOK', `Invalid pending request for ${primaryId}`);
495
495
  }
496
496
  }
497
497
  else if (entry.pendingRequest) {
498
- throw new ContactMutationError('INVALID_CONTACT_BOOK', `pendingRequest requires pending status for ${primaryId}`);
498
+ throw new PeerMutationError('INVALID_CONTACT_BOOK', `pendingRequest requires pending status for ${primaryId}`);
499
499
  }
500
500
  if (entry.status === 'declined' && !Number.isFinite(Date.parse(entry.declinedAt ?? ''))) {
501
- throw new ContactMutationError('INVALID_CONTACT_BOOK', `declinedAt is required for ${primaryId}`);
501
+ throw new PeerMutationError('INVALID_CONTACT_BOOK', `declinedAt is required for ${primaryId}`);
502
502
  }
503
503
  if (entry.status !== 'declined' && entry.declinedAt) {
504
- throw new ContactMutationError('INVALID_CONTACT_BOOK', `declinedAt requires declined status for ${primaryId}`);
504
+ throw new PeerMutationError('INVALID_CONTACT_BOOK', `declinedAt requires declined status for ${primaryId}`);
505
505
  }
506
506
  for (const alias of entry.aliases ?? []) {
507
507
  const parsed = parseContactAlias(alias, selfAid);
508
508
  if (!parsed) {
509
- throw new ContactMutationError('INVALID_CONTACT_BOOK', `Invalid contact alias for ${selfAid}: ${String(alias)}`);
509
+ throw new PeerMutationError('INVALID_CONTACT_BOOK', `Invalid contact alias for ${selfAid}: ${String(alias)}`);
510
510
  }
511
511
  if (!configuredChannelKeys.has(parsed.channelKey)) {
512
- throw new ContactMutationError('INVALID_CONTACT_BOOK', `Contact alias references an unconfigured channel instance: ${alias}`);
512
+ throw new PeerMutationError('INVALID_CONTACT_BOOK', `Contact alias references an unconfigured channel instance: ${alias}`);
513
513
  }
514
514
  const owner = aliases.get(alias);
515
515
  if (owner && owner !== primaryId) {
516
- throw new ContactMutationError('ALIAS_CONFLICT', `Alias ${alias} is bound to both ${owner} and ${primaryId}`);
516
+ throw new PeerMutationError('ALIAS_CONFLICT', `Alias ${alias} is bound to both ${owner} and ${primaryId}`);
517
517
  }
518
518
  aliases.set(alias, primaryId);
519
519
  }
@@ -554,10 +554,10 @@ function removeAliasEverywhere(contacts, alias, onlyOwner) {
554
554
  }
555
555
  function readContactBookFromDisk(selfAid) {
556
556
  try {
557
- return atomicReadJson(agentContactConfig(selfAid));
557
+ return atomicReadJson(agentPeerConfig(selfAid));
558
558
  }
559
559
  catch (error) {
560
- throw new ContactMutationError('INVALID_CONTACT_BOOK', `Cannot read contact book: ${error instanceof Error ? error.message : String(error)}`);
560
+ throw new PeerMutationError('INVALID_CONTACT_BOOK', `Cannot read contact book: ${error instanceof Error ? error.message : String(error)}`);
561
561
  }
562
562
  }
563
563
  function readTransactionJson(file, changes) {
@@ -566,7 +566,7 @@ function readTransactionJson(file, changes) {
566
566
  return change ? change.after === null ? null : JSON.parse(change.after) : atomicReadJson(file);
567
567
  }
568
568
  catch (error) {
569
- throw new ContactMutationError('INVALID_AUTHORITY', `Cannot read management role authority ${file}: ${error instanceof Error ? error.message : String(error)}`);
569
+ throw new PeerMutationError('INVALID_AUTHORITY', `Cannot read management role authority ${file}: ${error instanceof Error ? error.message : String(error)}`);
570
570
  }
571
571
  }
572
572
  function acquireAgentLock(selfAid) {
@@ -609,7 +609,7 @@ function acquireAgentLock(selfAid) {
609
609
  if (Date.now() >= deadline) {
610
610
  if (windowsRenameDenied && !lockExists)
611
611
  throw error;
612
- throw new ContactMutationError('LOCK_TIMEOUT', `Timed out waiting for contact mutation lock: ${lockDir}`);
612
+ throw new PeerMutationError('LOCK_TIMEOUT', `Timed out waiting for contact mutation lock: ${lockDir}`);
613
613
  }
614
614
  Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, LOCK_RETRY_MS);
615
615
  }
@@ -689,7 +689,7 @@ function recoverMutation(selfAid) {
689
689
  const journal = atomicReadJson(file);
690
690
  if (!journal || journal.schemaVersion !== 1 || journal.selfAid !== selfAid
691
691
  || !['prepared', 'committed'].includes(journal.state) || !Array.isArray(journal.changes)) {
692
- throw new ContactMutationError('INVALID_JOURNAL', `Invalid contact mutation journal: ${file}`);
692
+ throw new PeerMutationError('INVALID_JOURNAL', `Invalid contact mutation journal: ${file}`);
693
693
  }
694
694
  validateTransactionChanges(selfAid, journal.changes);
695
695
  if (journal.state === 'prepared') {
@@ -708,20 +708,20 @@ function validateTransactionChanges(selfAid, changes) {
708
708
  const seen = new Set();
709
709
  for (const change of changes) {
710
710
  if (!change || typeof change !== 'object' || typeof change.file !== 'string' || !change.file) {
711
- throw new ContactMutationError('INVALID_TRANSACTION', 'Transaction changes must contain a file path');
711
+ throw new PeerMutationError('INVALID_TRANSACTION', 'Transaction changes must contain a file path');
712
712
  }
713
713
  const file = path.resolve(change.file);
714
714
  const relative = path.relative(root, file);
715
715
  if (!relative || relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
716
- throw new ContactMutationError('UNSAFE_TRANSACTION', `Transaction file is outside the Agent directory: ${file}`);
716
+ throw new PeerMutationError('UNSAFE_TRANSACTION', `Transaction file is outside the Agent directory: ${file}`);
717
717
  }
718
718
  if (seen.has(file)) {
719
- throw new ContactMutationError('INVALID_TRANSACTION', `Transaction contains duplicate file changes: ${file}`);
719
+ throw new PeerMutationError('INVALID_TRANSACTION', `Transaction contains duplicate file changes: ${file}`);
720
720
  }
721
721
  seen.add(file);
722
722
  if ((change.before !== null && typeof change.before !== 'string')
723
723
  || (change.after !== null && typeof change.after !== 'string')) {
724
- throw new ContactMutationError('INVALID_TRANSACTION', `Invalid transaction content for ${file}`);
724
+ throw new PeerMutationError('INVALID_TRANSACTION', `Invalid transaction content for ${file}`);
725
725
  }
726
726
  }
727
727
  }
@@ -751,7 +751,7 @@ function journalFile(selfAid) {
751
751
  return path.join(agentDir(selfAid), JOURNAL_NAME);
752
752
  }
753
753
  function appendAudit(selfAid, request, previousContactRevision, contactRevisionValue) {
754
- const file = agentContactAuditPath(selfAid);
754
+ const file = agentPeerAuditPath(selfAid);
755
755
  fs.mkdirSync(path.dirname(file), { recursive: true });
756
756
  fs.appendFileSync(file, `${JSON.stringify({
757
757
  timestamp: new Date().toISOString(),
@@ -759,7 +759,7 @@ function appendAudit(selfAid, request, previousContactRevision, contactRevisionV
759
759
  actor: request.actor ?? 'system',
760
760
  mutation: request.mutation,
761
761
  previousContactRevision,
762
- contactRevision: contactRevisionValue,
762
+ peerRevision: contactRevisionValue,
763
763
  })}\n`, { mode: 0o600 });
764
764
  }
765
765
  function isOwner(selfAid, primaryId) {
@@ -768,14 +768,14 @@ function isOwner(selfAid, primaryId) {
768
768
  function normalizeAid(value, label) {
769
769
  const aid = String(value || '').trim();
770
770
  if (!isValidAid(aid))
771
- throw new ContactMutationError('INVALID_AID', `Invalid ${label}: ${JSON.stringify(value)}`);
771
+ throw new PeerMutationError('INVALID_AID', `Invalid ${label}: ${JSON.stringify(value)}`);
772
772
  return aid;
773
773
  }
774
774
  function normalizeContactAid(value, selfAid, changes = [], preservesAdmission = false) {
775
775
  const aid = normalizeAid(value, 'contact AID');
776
- const resolution = resolveContactAidKind(selfAid, aid, changes);
776
+ const resolution = resolvePeerAidKind(selfAid, aid, changes);
777
777
  if (resolution.kind !== 'private' && !(preservesAdmission && resolution.reason === 'missing')) {
778
- throw new ContactMutationError('INVALID_AID', resolution.kind === 'group'
778
+ throw new PeerMutationError('INVALID_AID', resolution.kind === 'group'
779
779
  ? `Contact Book does not support group AID: ${JSON.stringify(value)}`
780
780
  : `Contact AID type is unknown (${resolution.reason}): ${JSON.stringify(value)}`);
781
781
  }
@@ -2,10 +2,10 @@ import path from 'path';
2
2
  import { pathToFileURL } from 'url';
3
3
  import { getPackageRoot, resolvePaths } from '../paths.js';
4
4
  import { assertContactBookV2Ready, ConfigError } from './config-manager.js';
5
- import { recoverAllContactBookMutationsSync } from './contact-book-store.js';
5
+ import { recoverAllPeerBookMutationsSync } from './peer-book-store.js';
6
6
  export async function ensureContactBookV2OnStartup() {
7
7
  try {
8
- recoverAllContactBookMutationsSync();
8
+ recoverAllPeerBookMutationsSync();
9
9
  }
10
10
  catch (error) {
11
11
  const detail = error instanceof Error ? error.message : String(error);