evolcore 0.0.46 → 0.0.48

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 (237) hide show
  1. package/CHANGELOG.md +93 -0
  2. package/bin/ec-build.mjs +86 -0
  3. package/dist/agent-template/jobs.js +12 -4
  4. package/dist/agent-template/runtime.js +139 -39
  5. package/dist/agent-template/service.js +66 -13
  6. package/dist/agents/baseagent.js +60 -20
  7. package/dist/agents/claude-runner.js +43 -18
  8. package/dist/agents/codex/app-server-client.js +32 -23
  9. package/dist/agents/codex-runner.js +31 -16
  10. package/dist/agents/ecagent-runner.js +7 -4
  11. package/dist/agents/gemini-runner.js +5 -2
  12. package/dist/agents/runner-types.js +5 -21
  13. package/dist/aun/aid/agentmd.js +5 -1
  14. package/dist/aun/group/fs-download.js +1 -1
  15. package/dist/aun/service-proxy.js +4 -2
  16. package/dist/build-identity.json +1 -0
  17. package/dist/channels/aun.js +100 -32
  18. package/dist/channels/daemon.js +10 -26
  19. package/dist/cli/aun-commands.js +86 -51
  20. package/dist/cli/code-stats.js +19 -8
  21. package/dist/cli/command-log.js +1 -1
  22. package/dist/cli/daemon-commands.js +65 -76
  23. package/dist/cli/daemon-lifecycle-client.js +17 -3
  24. package/dist/cli/directory.js +7 -1
  25. package/dist/cli/ecmsg-gateway.js +5 -2
  26. package/dist/cli/index.js +2 -8
  27. package/dist/cli/init-channel.js +6 -8
  28. package/dist/cli/init.js +74 -46
  29. package/dist/cli/invoke-command.js +1 -1
  30. package/dist/cli/provider-command.js +74 -13
  31. package/dist/cli/restart-monitor.js +104 -28
  32. package/dist/cli/role.js +61 -17
  33. package/dist/cli/stats.js +3 -3
  34. package/dist/cli/task-context.js +83 -15
  35. package/dist/cli/thread-command.js +16 -51
  36. package/dist/cli/upgrade-command.js +4 -2
  37. package/dist/config/boot-log.js +3 -9
  38. package/dist/config/builtin-roles.js +5 -7
  39. package/dist/config/config-manager.js +31 -23
  40. package/dist/config/daemon-services.js +30 -3
  41. package/dist/config/gateway-config.js +2 -2
  42. package/dist/config/invoke-ipc-service.js +6 -4
  43. package/dist/config/peer-bind-code.js +3 -4
  44. package/dist/config/peer-book-store.js +59 -218
  45. package/dist/config/peer-book.js +26 -27
  46. package/dist/config/peer-role-resolver.js +16 -1
  47. package/dist/config/provider-identity-migration.js +161 -6
  48. package/dist/config/provider-ipc-service.js +56 -11
  49. package/dist/config/provider-menu-request.js +24 -5
  50. package/dist/config/provider-templates.js +127 -0
  51. package/dist/config/providers-config.js +59 -8
  52. package/dist/config/providers-management.js +467 -49
  53. package/dist/config/role-command-service.js +248 -1
  54. package/dist/config/schema-migration.js +228 -20
  55. package/dist/config/schema-registry.js +6 -2
  56. package/dist/core/agent-application-service.js +6 -1
  57. package/dist/core/agent-runtime.js +10 -5
  58. package/dist/core/auth/agent-delegation.js +10 -4
  59. package/dist/core/auth/auth-gateway.js +2 -1
  60. package/dist/core/auth/delegation-authorization.js +3 -0
  61. package/dist/core/auth/delegation-diagnostics.js +56 -15
  62. package/dist/core/auth/operation-authorizer.js +26 -1
  63. package/dist/core/auth/operation-catalog.js +28 -64
  64. package/dist/core/capability/providers/codex-capability-provider.js +7 -8
  65. package/dist/core/channel-loader.js +18 -0
  66. package/dist/core/command/agent-control.js +32 -0
  67. package/dist/core/command/command-handler.js +81 -85
  68. package/dist/core/command/menu-catalog.js +1 -0
  69. package/dist/core/command/menu-handler.js +65 -153
  70. package/dist/core/command/menu-protocol.js +7 -1
  71. package/dist/core/command/provider-menu.js +13 -3
  72. package/dist/core/command/role-menu.js +47 -23
  73. package/dist/core/command/slash-handler.js +30 -49
  74. package/dist/core/command/team-workspace-items.js +81 -12
  75. package/dist/core/command/team-workspace-team.js +9 -71
  76. package/dist/core/command/topic-slash.js +9 -30
  77. package/dist/core/daemon-bootstrap.js +19 -10
  78. package/dist/core/daemon-control.js +8 -10
  79. package/dist/core/daemon-lifecycle.js +50 -40
  80. package/dist/core/evolagent-registry.js +22 -3
  81. package/dist/core/file-integrity/store.js +2 -0
  82. package/dist/core/handoff/runtime.js +37 -1
  83. package/dist/core/host-snapshot.js +9 -4
  84. package/dist/core/inference/text-inference.js +3 -1
  85. package/dist/core/initialization/service.js +31 -8
  86. package/dist/core/interaction-router.js +3 -0
  87. package/dist/core/invoke/executors/text.js +72 -19
  88. package/dist/core/ipc-registration.js +6 -4
  89. package/dist/core/memory/consolidation.js +6 -6
  90. package/dist/core/message/aun-ipc-sender.js +165 -55
  91. package/dist/core/message/im-renderer.js +1 -1
  92. package/dist/core/message/message-bridge.js +51 -334
  93. package/dist/core/message/message-log.js +5 -0
  94. package/dist/core/message/message-queue.js +22 -0
  95. package/dist/core/message/message-utils.js +8 -0
  96. package/dist/core/message/response-engine.js +429 -116
  97. package/dist/core/message/send-routing.js +5 -1
  98. package/dist/core/model/catalog-service.js +31 -11
  99. package/dist/core/model/model-capabilities.js +22 -4
  100. package/dist/core/model/model-catalog.js +1 -0
  101. package/dist/core/ownership/owner-resolver.js +355 -60
  102. package/dist/core/permission/protected-paths.js +6 -6
  103. package/dist/core/relation/peer-identity.js +28 -2
  104. package/dist/core/relation/same-owner-proof.js +81 -111
  105. package/dist/core/session/adapters/claude-session-file-adapter.js +1 -1
  106. package/dist/core/session/adapters/codex-session-file-adapter.js +96 -15
  107. package/dist/core/session/session-file-health.js +49 -14
  108. package/dist/core/session/session-fs-store.js +91 -35
  109. package/dist/core/session/session-manager.js +68 -24
  110. package/dist/core/session/session-mapper.js +14 -34
  111. package/dist/core/session/session-transcript.js +5 -1
  112. package/dist/core/task/task-activity-store.js +84 -0
  113. package/dist/core/task/task-image-resources.js +1 -1
  114. package/dist/core/task/task-recovery-service.js +12 -0
  115. package/dist/core/thread/command-parser.js +7 -12
  116. package/dist/core/thread/thread-context-storage.js +3 -2
  117. package/dist/core/thread/thread-operation.js +2 -13
  118. package/dist/core/thread/thread-service.js +15 -46
  119. package/dist/directory/owner-directory-admission.js +1 -1
  120. package/dist/directory/owner-directory-cache.js +45 -28
  121. package/dist/directory/owner-directory-markdown.js +13 -1
  122. package/dist/directory/owner-directory-query-operation.js +29 -3
  123. package/dist/directory/owner-directory-remarks.js +11 -3
  124. package/dist/eck/message-renderer.js +84 -24
  125. package/dist/ecweb/basic-settings-service.js +3 -1
  126. package/dist/ecweb/message-context-service.js +1 -1
  127. package/dist/ecweb/pairing.js +4 -3
  128. package/dist/ecweb/providers-service.js +26 -1
  129. package/dist/ecweb/runtime/lifecycle.js +82 -23
  130. package/dist/ecweb/runtime/proxy-access.js +74 -0
  131. package/dist/ecweb/runtime/supervisor.js +6 -17
  132. package/dist/event-center/registry.js +13 -2
  133. package/dist/event-center/runtime.js +103 -11
  134. package/dist/event-center/script-runner.js +5 -5
  135. package/dist/index.js +129 -93
  136. package/dist/ipc.js +15 -3
  137. package/dist/outputs/events.js +62 -0
  138. package/dist/outputs/protocol.js +102 -0
  139. package/dist/outputs/service.js +279 -0
  140. package/dist/paths.js +3 -0
  141. package/dist/proxy/manager.js +43 -13
  142. package/dist/services/index.js +89 -4
  143. package/dist/services/ipc-operation.js +4 -15
  144. package/dist/services/pack-manager.js +12 -1
  145. package/dist/services/router.js +21 -6
  146. package/dist/services/script-runner.js +5 -4
  147. package/dist/services/validation.js +1 -1
  148. package/dist/stats/budget.js +1 -1
  149. package/dist/stats/db.js +19 -0
  150. package/dist/stats/index.js +1 -1
  151. package/dist/stats/{price-resolver.js → model-resolver.js} +305 -24
  152. package/dist/stats/normalizer.js +2 -0
  153. package/dist/stats/query.js +35 -27
  154. package/dist/stats/role-budget.js +5 -2
  155. package/dist/stats/writer.js +10 -6
  156. package/dist/trigger/audit.js +7 -0
  157. package/dist/trigger/authorization.js +105 -11
  158. package/dist/trigger/feedback.js +10 -0
  159. package/dist/trigger/history.js +37 -11
  160. package/dist/trigger/ipc-service.js +12 -1
  161. package/dist/trigger/manager.js +1 -0
  162. package/dist/trigger/scheduler.js +11 -5
  163. package/dist/trigger/script-executor.js +2 -1
  164. package/dist/trigger/script-sandbox.js +9 -3
  165. package/dist/trigger/state.js +7 -0
  166. package/dist/trigger/validation.js +22 -0
  167. package/dist/utils/aid-bind.js +155 -18
  168. package/dist/utils/atomic-write.js +3 -3
  169. package/dist/utils/cross-platform.js +97 -31
  170. package/dist/utils/error-dict.json +94 -4
  171. package/dist/utils/error-utils.js +40 -4
  172. package/dist/utils/evolcore-version.js +36 -65
  173. package/dist/utils/instance-registry.js +61 -0
  174. package/dist/utils/msg-diag.js +1 -0
  175. package/dist/utils/process-introspect.js +158 -8
  176. package/dist/utils/process-tree.js +50 -2
  177. package/dist/utils/upgrade-jobs.js +4 -4
  178. package/dist/utils/windows-shell-trust.js +2 -0
  179. package/dist/workbench/protocol.js +80 -0
  180. package/dist/workbench/service.js +359 -0
  181. package/ecagent/dist/types.d.ts +6 -2
  182. package/kits/docs/context-assembly.md +1 -1
  183. package/kits/docs/evolcore/INDEX.md +2 -2
  184. package/kits/docs/evolcore/aid.md +3 -1
  185. package/kits/docs/evolcore/config.md +12 -0
  186. package/kits/docs/evolcore/directory.md +22 -3
  187. package/kits/docs/evolcore/ecweb-lifecycle.md +15 -0
  188. package/kits/docs/evolcore/model.md +10 -0
  189. package/kits/docs/evolcore/peer.md +19 -65
  190. package/kits/docs/evolcore/provider.md +133 -5
  191. package/kits/docs/evolcore/role.md +80 -0
  192. package/kits/docs/evolcore/services.md +6 -6
  193. package/kits/docs/evolcore/team-workspace.md +1 -1
  194. package/kits/docs/evolcore/thread-chain.md +14 -15
  195. package/kits/docs/evolcore/tool-authorization.md +5 -0
  196. package/kits/docs/evolcore/trigger.md +10 -0
  197. package/kits/eck_message_manifest.json +12 -0
  198. package/kits/provider-templates.json +1213 -0
  199. package/kits/rules/04-relation.md +3 -3
  200. package/kits/schemas/_meta.json +14 -2
  201. package/kits/schemas/contact-book.schema.4.json +52 -0
  202. package/kits/schemas/providers.schema.3.json +200 -0
  203. package/kits/skills/.switches.json +4 -0
  204. package/kits/skills/ability/references/calling.md +1 -1
  205. package/kits/skills/ec-group/SKILL.md +2 -2
  206. package/kits/skills/ec-identity/SKILL.md +19 -72
  207. package/kits/skills/ec-provider/SKILL.md +221 -0
  208. package/kits/skills/ec-provider/scripts/check-model.mjs +80 -0
  209. package/kits/skills/ec-trigger/SKILL.md +1 -1
  210. package/kits/skills/thread-ops/SKILL.md +34 -21
  211. package/kits/templates/message-fragments/group-batch-item.md +1 -1
  212. package/kits/templates/message-fragments/group-batch.md +1 -1
  213. package/kits/templates/message-fragments/inject-default.md +1 -1
  214. package/kits/templates/message-fragments/interrupt-insert.md +1 -0
  215. package/kits/templates/message-fragments/item-group.md +1 -1
  216. package/kits/templates/message-fragments/item-private.md +1 -1
  217. package/kits/templates/message-fragments/thread-context.md +1 -1
  218. package/kits/templates/message-fragments/trigger-session.md +1 -1
  219. package/kits/templates/message-fragments/trigger-thread-check.md +1 -1
  220. package/kits/templates/roles/admin.json +2 -19
  221. package/kits/templates/roles/member.json +0 -3
  222. package/kits/templates/system-fragments/baseagent.md +6 -0
  223. package/kits/templates/system-fragments/commands.md +3 -3
  224. package/kits/templates/system-fragments/managed-runtime.md +1 -1
  225. package/kits/templates/system-fragments/relation.md +1 -1
  226. package/kits/templates/system-fragments/thread.md +6 -5
  227. package/package.json +6 -4
  228. package/scripts/agent-template/inspect.mjs +4 -1
  229. package/scripts/agent-template/shared/common.mjs +2 -3
  230. package/scripts/agent-template/shared/template-contract.mjs +2 -1
  231. package/scripts/agent-template/shared/template-package.mjs +9 -2
  232. package/scripts/agent-template/shared/template-runtime.mjs +20 -5
  233. package/scripts/agent-template/team-pack.mjs +6 -3
  234. package/dist/cli/peer.js +0 -127
  235. package/dist/config/peer-operation-service.js +0 -132
  236. package/dist/config/peer-request-service.js +0 -532
  237. package/dist/core/command/connect-menu.js +0 -624
@@ -43,7 +43,7 @@ const L_CLASS_RELATIVE_PATTERNS = [
43
43
  /^daemon\.json$/,
44
44
  /^agents\/defaults\.json$/,
45
45
  /^agents\/[^/]+\/config\.json$/,
46
- /^agents\/[^/]+\/contact\.json$/,
46
+ /^agents\/[^/]+\/(?:contact|peers)\.json$/,
47
47
  /^agents\/[^/]+\/contact-operations\.jsonl$/,
48
48
  /^agents\/[^/]+\/relations\/[^/]+\/config\.json$/,
49
49
  /^backups\/config(?:\/|$)/,
@@ -54,7 +54,7 @@ const L_CLASS_RELATIVE_PATTERNS = [
54
54
  ];
55
55
  const L_CLASS_REFERENCE_PATTERNS = [
56
56
  /(?:^|[^A-Za-z0-9_.-])daemon\.json(?=$|[^A-Za-z0-9_.-])/,
57
- /(?:^|[^A-Za-z0-9_.-])agents[\\/](?:defaults\.json|[^/\\\s"']+[\\/](?:(?:config|contact)\.json|contact-operations\.jsonl|relations[\\/][^/\\\s"']+[\\/]config\.json))(?=$|[\s"';&|<>)},])/,
57
+ /(?:^|[^A-Za-z0-9_.-])agents[\\/](?:defaults\.json|[^/\\\s"']+[\\/](?:(?:config|contact|peers)\.json|contact-operations\.jsonl|relations[\\/][^/\\\s"']+[\\/]config\.json))(?=$|[\s"';&|<>)},])/,
58
58
  /(?:^|[^A-Za-z0-9_.-])backups[\\/]config(?:[\\/]|$|[\s"';&|<>)},])/,
59
59
  /(?:^|[^A-Za-z0-9_.-])agents[\\/][^/\\\s"']+[\\/]triggers(?:[\\/]|$|[\s"';&|<>)},])/,
60
60
  /(?:^|[^A-Za-z0-9_.-])agents[\\/][^/\\\s"']+[\\/]roles(?:[\\/]|$|[\s"';&|<>)},])/,
@@ -375,7 +375,7 @@ function getLegacyHClassSandboxPatterns(root) {
375
375
  'daemon.json',
376
376
  path.join('agents', 'defaults.json'),
377
377
  path.join('agents', '*', 'config.json'),
378
- path.join('agents', '*', 'contact.json'),
378
+ path.join('agents', '*', 'contact.json'), path.join('agents', '*', 'peers.json'),
379
379
  path.join('agents', '*', 'contact-operations.jsonl'),
380
380
  path.join('agents', '*', 'relations', '*', 'config.json'),
381
381
  path.join('backups', 'config'), path.join('backups', 'config', '**'),
@@ -560,7 +560,7 @@ export function getExistingHClassMaskTargets(root = resolveRoot(), options = {})
560
560
  if (!entry.isDirectory())
561
561
  continue;
562
562
  const agentRoot = path.join(agentsDir, entry.name);
563
- for (const fileName of ['config.json', 'config.json_', 'contact.json', 'contact.json_', 'contact-operations.jsonl']) {
563
+ for (const fileName of ['config.json', 'config.json_', 'contact.json', 'contact.json_', 'peers.json', 'peers.json_', 'contact-operations.jsonl']) {
564
564
  addExistingTarget(targets, path.join(agentRoot, fileName));
565
565
  }
566
566
  const relationsDir = path.join(agentRoot, 'relations');
@@ -614,7 +614,7 @@ export function getExistingLClassReadOnlyTargets(root = resolveRoot(), options =
614
614
  }
615
615
  const ownRoot = path.join(agentsDir, selfAid);
616
616
  for (const relative of [
617
- 'config.json', 'contact.json', 'contact-operations.jsonl', 'roles', 'triggers', 'events', 'services',
617
+ 'config.json', 'contact.json', 'peers.json', 'contact-operations.jsonl', 'roles', 'triggers', 'events', 'services',
618
618
  ])
619
619
  addExistingTarget(targets, path.join(ownRoot, relative));
620
620
  try {
@@ -1027,7 +1027,7 @@ export function lClassGrantIncludesProtectedPath(value, options = {}) {
1027
1027
  // relations/<peer> 本身时才覆盖它,更深的路径(如 relations/<peer>/memory/…)不会。
1028
1028
  if (segments[2] === 'relations')
1029
1029
  return segments.length <= 4;
1030
- return ['config.json', 'contact.json', 'contact-operations.jsonl', 'roles', 'triggers', 'events', 'services']
1030
+ return ['config.json', 'contact.json', 'peers.json', 'contact-operations.jsonl', 'roles', 'triggers', 'events', 'services']
1031
1031
  .includes(segments[2]);
1032
1032
  }
1033
1033
  return false;
@@ -21,6 +21,9 @@ export function parseAgentMdFrontmatter(content) {
21
21
  const end = lines.slice(1).findIndex(line => line.trim() === '---');
22
22
  if (end < 0)
23
23
  return {};
24
+ // Lifecycle clients only use peer-key helpers; parsing keeps the same
25
+ // synchronous YAML implementation without loading it into those clients.
26
+ const { parse: parseYaml } = requirePeerIdentityDependency('yaml');
24
27
  try {
25
28
  const parsed = parseYaml(lines.slice(1, end + 1).join('\n'));
26
29
  return parsed && typeof parsed === 'object' && !Array.isArray(parsed)
@@ -64,12 +67,13 @@ function normalizeCachedIdentity(raw) {
64
67
  import * as fs from 'fs';
65
68
  import * as path from 'path';
66
69
  import * as crypto from 'crypto';
67
- import { parse as parseYaml } from 'yaml';
70
+ import { createRequire } from 'node:module';
68
71
  import { logger } from '../../utils/logger.js';
69
72
  import { agentDir as resolveAgentDir, agentMdPath } from '../../paths.js';
70
73
  import { ConfigTarget, mutateConfig, read } from '../../config/config-manager.js';
71
74
  import { isValidAid } from '../../aun/aid/validation.js';
72
75
  import { resolveAunTargetKind, verifiedPeerType, } from '../../aun/group/identity.js';
76
+ const requirePeerIdentityDependency = createRequire(import.meta.url);
73
77
  /**
74
78
  * peerKey: 关系层路由键,格式 `<channelType>#<urlEncode(channelId)>`。
75
79
  * 群聊场景下 channelId = groupId,所有发言者共用同一个 peerKey。
@@ -219,6 +223,25 @@ export class PeerIdentityCache {
219
223
  : maxAgeMs;
220
224
  return cached.lastCheckedAt === 0 || Date.now() - cached.lastCheckedAt > effectiveMaxAge;
221
225
  }
226
+ /**
227
+ * 本地 agent.md 是否已与缓存快照不同。
228
+ *
229
+ * 名录同步和 SDK 的 `agentmd.changed` 观察会独立刷新本地 agent.md,但
230
+ * `peer-identity.json` 有 30 天时效;只靠 `lastCheckedAt` 会让名片改名
231
+ * 最长 30 天才生效。命中缓存时比对本地文件哈希,变了就走同步路径;
232
+ * 读不到本地文件则维持缓存。
233
+ */
234
+ static localAgentMdChanged(peerId, cached, aunPath) {
235
+ let content;
236
+ try {
237
+ content = fs.readFileSync(agentMdPath(peerId, aunPath), 'utf-8');
238
+ }
239
+ catch {
240
+ return false;
241
+ }
242
+ const hash = 'sha256:' + crypto.createHash('sha256').update(content, 'utf-8').digest('hex');
243
+ return hash !== cached.agentMdHash;
244
+ }
222
245
  /**
223
246
  * 从 agent.md 更新身份信息
224
247
  * @param source 'agentmd'(验签通过)或 'agentmd-unverified'(内容可解析但验签未过)
@@ -360,10 +383,13 @@ export class PeerIdentityCache {
360
383
  // 1. 缓存检查
361
384
  if (!forceRefresh && !this.needsRefresh(channelType, peerId, agentDir)) {
362
385
  const cached = this.get(channelType, peerId, agentDir);
363
- if (cached) {
386
+ if (cached && !this.localAgentMdChanged(peerId, cached, resolvedAunPath)) {
364
387
  logger.debug(`[PeerIdentityCache] Cache hit: ${channelType}#${peerId} type=${cached.type} age=${Math.floor((Date.now() - cached.lastCheckedAt) / 1000 / 60 / 60 / 24)}d`);
365
388
  return cached;
366
389
  }
390
+ if (cached) {
391
+ logger.debug(`[PeerIdentityCache] Local agent.md changed since cache: ${channelType}#${peerId}, refreshing`);
392
+ }
367
393
  }
368
394
  const cachePath = this.getFilePath(channelType, peerId, agentDir);
369
395
  const revision = this.invalidationRevisions.get(cachePath) ?? 0;
@@ -1,131 +1,101 @@
1
- import { createHash } from 'crypto';
2
- import { agentmdGet } from '../../aun/aid/agentmd.js';
3
1
  import { isValidAid } from '../../aun/aid/validation.js';
4
- import { parseAgentMdFrontmatter } from './peer-identity.js';
5
- export const SAME_OWNER_MAX_AGE_MS = 30_000;
6
- const SAME_OWNER_TIMEOUT_MS = 8_000;
7
- const runtimes = new Map();
2
+ import { ownerResolver, OWNERSHIP_CACHE_MAX_AGE_MS } from '../ownership/owner-resolver.js';
3
+ export const SAME_OWNER_MAX_AGE_MS = OWNERSHIP_CACHE_MAX_AGE_MS;
4
+ const clients = new Map();
5
+ // A fail-closed identity hint, never a second authorization cache.
8
6
  const knownTeams = new Map();
9
- let revision = 0;
10
7
  export function registerSameOwnerClient(selfAid, client, store) {
11
8
  unregisterSameOwnerClient(selfAid);
12
- const peers = knownTeams.get(selfAid) ?? new Set();
13
- knownTeams.set(selfAid, peers);
14
- const runtime = { client, store, generation: 0, entries: new Map(), pending: new Map(), knownTeams: peers, subscriptions: [] };
15
- runtimes.set(selfAid, runtime);
16
- const invalidate = () => {
17
- if (runtimes.get(selfAid) !== runtime)
18
- return;
19
- runtime.generation++;
20
- runtime.entries.clear();
21
- runtime.pending.clear();
22
- revision++;
23
- };
24
- for (const event of ['agentmd.changed', 'storage.object_changed', 'ownership.completed', 'ownership.rejected',
25
- 'ownership.stopped', 'ownership.error', 'disconnected']) {
26
- runtime.subscriptions.push(client.on(event, invalidate));
9
+ ownerResolver.registerEvidenceClient(selfAid, client, store);
10
+ const subscriptions = [];
11
+ for (const event of ['agentmd.changed', 'agent_md_changed', 'ownership.completed', 'ownership.rejected',
12
+ 'ownership.stopped', 'ownership.error']) {
13
+ subscriptions.push(client.on(event, payload => {
14
+ if (clients.get(selfAid)?.client !== client)
15
+ return;
16
+ const value = payload;
17
+ const aid = typeof payload === 'string' ? payload : value?.sub_aid ?? value?.aid;
18
+ if (aid && isValidAid(aid))
19
+ ownerResolver.invalidateEvidence(aid);
20
+ }));
27
21
  }
22
+ subscriptions.push(client.on('storage.object_changed', payload => {
23
+ if (clients.get(selfAid)?.client !== client)
24
+ return;
25
+ const value = payload;
26
+ const key = value?.object_key?.replace(/^\/+/, '');
27
+ const sub = key ? /^sub_aids\/([^/]+)\/owner\.md$/.exec(key)?.[1] : undefined;
28
+ const aid = sub ?? (key === 'agent.md' ? value.owner_aid : undefined);
29
+ if (aid && isValidAid(aid))
30
+ ownerResolver.invalidateEvidence(aid);
31
+ }));
32
+ clients.set(selfAid, { client, subscriptions });
28
33
  }
29
34
  export function unregisterSameOwnerClient(selfAid, client) {
30
- const runtime = runtimes.get(selfAid);
31
- if (!runtime || (client && runtime.client !== client))
35
+ const current = clients.get(selfAid);
36
+ if (!current || (client && current.client !== client))
32
37
  return;
33
- runtimes.delete(selfAid);
34
- revision++;
35
- for (const subscription of runtime.subscriptions)
38
+ clients.delete(selfAid);
39
+ for (const subscription of current.subscriptions)
36
40
  subscription.unsubscribe();
41
+ ownerResolver.unregisterEvidenceClient(selfAid, current.client);
42
+ }
43
+ function qualify(self, peer) {
44
+ if (self.refreshFailure || peer.refreshFailure || self.authorizationStatus !== 'verified'
45
+ || peer.authorizationStatus !== 'verified' || !self.profile || !peer.profile)
46
+ return 'unavailable';
47
+ if (self.profile.type !== 'agent' || peer.profile.type !== 'agent')
48
+ return 'unmatched';
49
+ return self.ownerAid && peer.ownerAid && self.ownerAid === peer.ownerAid ? 'matched' : 'unmatched';
37
50
  }
38
51
  export function sameOwnerQualification(selfAid, peerAid) {
39
- const runtime = runtimes.get(selfAid);
40
- const entry = runtime?.entries.get(peerAid);
41
- return runtime?.client.isReady && entry && entry.expiresAt > Date.now()
42
- ? entry.qualification : 'unavailable';
52
+ if (!isValidAid(selfAid) || !isValidAid(peerAid))
53
+ return 'unavailable';
54
+ return qualify(ownerResolver.snapshot(selfAid), ownerResolver.snapshot(peerAid));
43
55
  }
44
56
  export function sameOwnerRevision(selfAid) {
45
- const runtime = runtimes.get(selfAid);
46
- const entries = [...(runtime?.entries ?? [])].map(([peerAid, entry]) => [peerAid, entry.revision, entry.expiresAt > Date.now()]);
47
- return JSON.stringify([revision, runtime?.client.isReady === true, entries]);
57
+ if (!isValidAid(selfAid))
58
+ return '';
59
+ return JSON.stringify([ownerResolver.revision(selfAid), [...(knownTeams.get(selfAid) ?? [])]
60
+ .map(peer => [peer, ownerResolver.revision(peer), sameOwnerQualification(selfAid, peer)])]);
48
61
  }
49
62
  export function requiresSameOwnerProof(selfAid, peerAid) {
50
- return knownTeams.get(selfAid)?.has(peerAid) === true;
63
+ if (!isValidAid(selfAid) || !isValidAid(peerAid))
64
+ return false;
65
+ if (knownTeams.get(selfAid)?.has(peerAid) === true)
66
+ return true;
67
+ // Historical facts only keep a missing proof fail-closed after restart; they never grant a role.
68
+ const self = ownerResolver.snapshot(selfAid);
69
+ const peer = ownerResolver.snapshot(peerAid);
70
+ return self.profile?.type === 'agent' && peer.profile?.type === 'agent'
71
+ && !!self.relation?.ownerAid && self.relation.ownerAid === peer.relation?.ownerAid;
51
72
  }
52
73
  export async function prepareSameOwnerProof(selfAid, peerAid) {
53
- if (!selfAid || !peerAid || selfAid === peerAid || !isValidAid(selfAid) || !isValidAid(peerAid))
54
- return;
55
- const runtime = runtimes.get(selfAid);
56
- if (!runtime?.client.isReady)
57
- return;
58
- const cached = runtime.entries.get(peerAid);
59
- if (cached && cached.expiresAt > Date.now())
60
- return;
61
- const pending = runtime.pending.get(peerAid);
62
- if (pending)
63
- return pending;
64
- const generation = runtime.generation;
65
- const startedAt = Date.now();
66
- const query = async () => {
67
- const cards = await Promise.all([selfAid, peerAid].map(aid => agentmdGet(aid, { store: runtime.store, withVerification: true, remoteOnly: true })));
68
- const profiles = cards.map((card, index) => {
69
- if (card.source !== 'remote' || card.verification.status !== 'verified')
70
- throw new Error('Unverified agent profile');
71
- const profile = parseAgentMdFrontmatter(card.content);
72
- if (profile.aid !== [selfAid, peerAid][index])
73
- throw new Error('Mismatched agent profile');
74
- return profile;
75
- });
76
- // 这里证明的是「同一个 Owner 名下的内部 agent」,**不是** PA Team 成员关系:
77
- // 团队归属由 contacts.json 的 open_pa_context 决定(见 owner-directory-scope.ts
78
- // 的 isInPaTeam),本模块不读那份名单。判据也不看 exttype 前缀——同 Owner 的
79
- // 非 PA agent 同样是内部联系人。human/service/device 不参与:它们拿不到
80
- // agent.md 里协议共识校验所需的 ownership statement。
81
- if (!profiles.every(profile => String(profile.type || '').trim().toLowerCase() === 'agent'))
82
- return 'unmatched';
83
- const consensuses = await Promise.all([selfAid, peerAid].map(aid => runtime.client.checkOwnershipConsensus(aid, true)));
84
- for (const [index, consensus] of consensuses.entries()) {
85
- const digest = createHash('sha256').update(cards[index].content, 'utf8').digest('hex');
86
- if (consensus.status !== 'consensus' || consensus.sub_aid !== [selfAid, peerAid][index]
87
- || consensus.lock !== 'locked' || !consensus.owner_aid || !isValidAid(consensus.owner_aid)
88
- || !Number.isSafeInteger(consensus.relation_version) || consensus.relation_version < 1
89
- || consensus.agent_md_sha256 !== digest
90
- || profiles[index].owner !== consensus.owner_aid)
91
- return 'unavailable';
92
- }
93
- return consensuses[0].owner_aid === consensuses[1].owner_aid ? 'matched' : 'unmatched';
94
- };
95
- const task = (async () => {
96
- let timeout;
97
- let qualification = 'unavailable';
98
- try {
99
- qualification = await Promise.race([query(), new Promise(resolve => {
100
- timeout = setTimeout(() => resolve('unavailable'), SAME_OWNER_TIMEOUT_MS);
101
- timeout.unref?.();
102
- })]);
103
- }
104
- catch {
105
- qualification = 'unavailable';
106
- }
107
- finally {
108
- if (timeout)
109
- clearTimeout(timeout);
110
- }
111
- if (runtimes.get(selfAid) !== runtime || runtime.generation !== generation || !runtime.client.isReady)
112
- return;
113
- if (qualification === 'matched')
114
- runtime.knownTeams.add(peerAid);
115
- if (qualification === 'unmatched')
116
- runtime.knownTeams.delete(peerAid);
117
- runtime.entries.set(peerAid, {
118
- qualification,
119
- expiresAt: startedAt + (qualification === 'unavailable' ? 2_000 : SAME_OWNER_MAX_AGE_MS),
120
- revision: ++revision,
121
- });
122
- })();
123
- runtime.pending.set(peerAid, task);
124
- try {
125
- await task;
74
+ if (!selfAid || !peerAid || selfAid === peerAid || !isValidAid(selfAid) || !isValidAid(peerAid)) {
75
+ return { qualification: 'unmatched' };
126
76
  }
127
- finally {
128
- if (runtime.pending.get(peerAid) === task)
129
- runtime.pending.delete(peerAid);
77
+ if (ownerResolver.owner(selfAid) === peerAid)
78
+ return { qualification: 'unmatched' };
79
+ if (!clients.has(selfAid)) {
80
+ return { qualification: sameOwnerQualification(selfAid, peerAid), retryable: true,
81
+ reason: 'Same-Owner authorization transport is unavailable' };
82
+ }
83
+ const views = await Promise.all([selfAid, peerAid].map(aid => ownerResolver.refresh(aid, {
84
+ observerAid: selfAid, requireProfile: true, maxAgeMs: SAME_OWNER_MAX_AGE_MS, source: 'same-owner',
85
+ })));
86
+ const qualification = qualify(views[0], views[1]);
87
+ const peers = knownTeams.get(selfAid) ?? new Set();
88
+ knownTeams.set(selfAid, peers);
89
+ if (qualification === 'matched')
90
+ peers.add(peerAid);
91
+ if (qualification === 'unmatched')
92
+ peers.delete(peerAid);
93
+ if (qualification === 'unavailable') {
94
+ const permanent = views.find(view => view.refreshFailure?.kind === 'permanent'
95
+ || ['invalid', 'released', 'unbound', 'single_sided', 'not_applicable'].includes(view.consensusStatus));
96
+ const failed = permanent ?? views.find(view => view.refreshFailure) ?? views[0];
97
+ return { qualification, retryable: !permanent,
98
+ reason: failed.refreshFailure?.reason ?? failed.reason ?? 'Ownership authorization evidence is unavailable' };
130
99
  }
100
+ return { qualification };
131
101
  }
@@ -4,7 +4,6 @@
4
4
  * Reads Claude Agent SDK session files from ~/.claude/projects/{encodedPath}/{sessionId}.jsonl
5
5
  * and wraps sdkListSessions for name synchronization.
6
6
  */
7
- import { listSessions as sdkListSessions } from '@anthropic-ai/claude-agent-sdk';
8
7
  import { encodePath } from '../../../utils/cross-platform.js';
9
8
  import { logger } from '../../../utils/logger.js';
10
9
  import { buildCliSessionPreview } from '../session-title.js';
@@ -207,6 +206,7 @@ export class ClaudeSessionFileAdapter {
207
206
  }
208
207
  async listSdkSessions(projectPath) {
209
208
  try {
209
+ const { listSessions: sdkListSessions } = await import('@anthropic-ai/claude-agent-sdk');
210
210
  const sessions = await sdkListSessions({ dir: projectPath });
211
211
  return sessions.map(s => ({
212
212
  sessionId: s.sessionId,
@@ -15,7 +15,7 @@ import { logger } from '../../../utils/logger.js';
15
15
  import path from 'path';
16
16
  import fs from 'fs';
17
17
  import os from 'os';
18
- import { visitSessionHistory } from '../session-fs-store.js';
18
+ import { visitSessionHistory, visitSessionHistoryLines } from '../session-fs-store.js';
19
19
  const requireFromHere = createRequire(import.meta.url);
20
20
  let sqliteModule; // undefined = not tried, null = unavailable
21
21
  export const sanitizeCodexThreadTitle = sanitizeSessionTitle;
@@ -106,34 +106,30 @@ export class CodexSessionFileAdapter {
106
106
  * recoverable. Require the rollout to contain both its own session metadata
107
107
  * and the exact turn_context before EvolCore publishes a new binding.
108
108
  */
109
- checkTurnPersisted(_projectPath, agentSessionId, turnId, _agentAid) {
109
+ async checkTurnPersisted(_projectPath, agentSessionId, turnId, _agentAid) {
110
110
  const normalizedSessionId = agentSessionId.trim();
111
111
  const normalizedTurnId = turnId.trim();
112
112
  if (!normalizedSessionId || !normalizedTurnId)
113
113
  return false;
114
- let rolloutPath = null;
114
+ let preferred;
115
115
  const db = this.getDb();
116
116
  if (db) {
117
117
  try {
118
118
  const row = db.prepare('SELECT rollout_path FROM threads WHERE id = ? AND archived = 0').get(normalizedSessionId);
119
- rolloutPath = this.resolveRolloutPath(row?.rollout_path, normalizedSessionId);
119
+ preferred = row?.rollout_path;
120
120
  }
121
121
  catch (error) {
122
122
  logger.warn('[CodexAdapter] checkTurnPersisted DB query failed:', error);
123
123
  }
124
124
  }
125
- rolloutPath ??= this.findRolloutFile(normalizedSessionId);
125
+ const rolloutPath = await this.findRolloutFileAsync(normalizedSessionId, preferred);
126
126
  if (!rolloutPath)
127
127
  return false;
128
128
  try {
129
129
  let hasMatchingSession = false;
130
130
  let hasMatchingTurn = false;
131
- const lines = fs.readFileSync(rolloutPath, 'utf-8').split('\n');
132
- for (const line of lines) {
133
- if (!line.trim())
134
- continue;
131
+ await this.visitRolloutEvents(rolloutPath, event => {
135
132
  try {
136
- const event = JSON.parse(line);
137
133
  if (event?.type === 'session_meta') {
138
134
  const persistedSessionId = event.payload?.session_id ?? event.payload?.id;
139
135
  const version = event.payload?.version ?? event.payload?.cli_version;
@@ -144,19 +140,32 @@ export class CodexSessionFileAdapter {
144
140
  else if (event?.type === 'turn_context' && event.payload?.turn_id === normalizedTurnId) {
145
141
  hasMatchingTurn = true;
146
142
  }
147
- if (hasMatchingSession && hasMatchingTurn)
148
- return true;
149
143
  }
150
144
  catch {
151
- // The last JSONL line may still be in flight; a later poll retries it.
145
+ // Ignore unusable metadata, as with malformed JSONL records.
152
146
  }
153
- }
154
- return false;
147
+ if (hasMatchingSession && hasMatchingTurn)
148
+ return false;
149
+ });
150
+ return hasMatchingSession && hasMatchingTurn;
155
151
  }
156
152
  catch {
157
153
  return false;
158
154
  }
159
155
  }
156
+ /** Visit a bounded UTF-8 JSONL snapshot; false stops after sufficient evidence. */
157
+ async visitRolloutEvents(file, visit) {
158
+ await visitSessionHistoryLines(file, line => {
159
+ let event;
160
+ try {
161
+ event = JSON.parse(line);
162
+ }
163
+ catch {
164
+ return;
165
+ }
166
+ return visit(event);
167
+ });
168
+ }
160
169
  /**
161
170
  * 在 ~/.codex/sessions/ 下递归查找含 agentSessionId 的 rollout JSONL 文件
162
171
  */
@@ -216,6 +225,51 @@ export class CodexSessionFileAdapter {
216
225
  }
217
226
  return { turns: 0 };
218
227
  }
228
+ async getFileInfoAsync(_projectPath, agentSessionId) {
229
+ let row;
230
+ let initial;
231
+ const previewOptions = { includeSyntheticFallback: false, maxLength: 80 };
232
+ const db = this.getDb();
233
+ if (db) {
234
+ try {
235
+ const candidate = db.prepare('SELECT title, first_user_message, rollout_path FROM threads WHERE id = ?').get(agentSessionId);
236
+ if (candidate) {
237
+ initial = buildCliSessionPreview([candidate.first_user_message], 'codex', {
238
+ ...previewOptions, explicitTitle: candidate.title,
239
+ });
240
+ row = candidate;
241
+ }
242
+ }
243
+ catch (error) {
244
+ logger.warn('[CodexAdapter] getFileInfo DB query failed:', error);
245
+ }
246
+ }
247
+ const rollout = await this.findRolloutFileAsync(agentSessionId, row?.rollout_path);
248
+ let turns = 0;
249
+ let preview = initial;
250
+ if (rollout) {
251
+ try {
252
+ await this.visitRolloutEvents(rollout, event => {
253
+ if (event?.type === 'turn_context')
254
+ turns++;
255
+ if (preview && !preview.hasReal && event?.type === 'event_msg'
256
+ && event.payload?.type === 'user_message' && event.payload.message) {
257
+ try {
258
+ preview = buildCliSessionPreview([String(event.payload.message)], 'codex', {
259
+ ...previewOptions, explicitTitle: row.title,
260
+ });
261
+ }
262
+ catch { /* Skip unusable user messages, as in the synchronous reader. */ }
263
+ }
264
+ });
265
+ }
266
+ catch {
267
+ turns = 0;
268
+ preview = initial;
269
+ }
270
+ }
271
+ return row ? { turns, title: preview?.title || undefined } : { turns };
272
+ }
219
273
  readFirstMessage(projectPath, agentSessionId) {
220
274
  // 1. 优先查 state DB
221
275
  const db = this.getDb();
@@ -338,6 +392,33 @@ export class CodexSessionFileAdapter {
338
392
  return null;
339
393
  return this.readUserMessageFromRollout(rolloutPath, 'last');
340
394
  }
395
+ async readLastUserMessageAsync(_projectPath, agentSessionId) {
396
+ let preferred;
397
+ try {
398
+ preferred = this.getDb()?.prepare('SELECT rollout_path FROM threads WHERE id = ?').get(agentSessionId)?.rollout_path;
399
+ }
400
+ catch (error) {
401
+ logger.warn('[CodexAdapter] readLastUserMessage DB query failed:', error);
402
+ }
403
+ const rollout = await this.findRolloutFileAsync(agentSessionId, preferred);
404
+ if (!rollout)
405
+ return null;
406
+ const messages = [];
407
+ try {
408
+ await this.visitRolloutEvents(rollout, event => {
409
+ try {
410
+ if (event?.type === 'event_msg' && event.payload?.type === 'user_message' && event.payload.message) {
411
+ messages.push(String(event.payload.message));
412
+ }
413
+ }
414
+ catch { /* Skip unusable user messages, as in the synchronous reader. */ }
415
+ });
416
+ }
417
+ catch {
418
+ return null;
419
+ }
420
+ return buildCliSessionPreview(messages.reverse(), 'codex').title;
421
+ }
341
422
  scanCliSessions(projectPath, limit = 10) {
342
423
  const db = this.getDb();
343
424
  if (!db)
@@ -6,6 +6,7 @@ import { isDeepStrictEqual } from 'node:util';
6
6
  import path from 'path';
7
7
  import { logger } from '../../utils/logger.js';
8
8
  import { withFileLock } from '../../utils/atomic-write.js';
9
+ import { visitSessionHistoryLines } from './session-fs-store.js';
9
10
  /**
10
11
  * 检查会话文件健康度(接收完整文件路径)
11
12
  */
@@ -17,20 +18,25 @@ export async function checkSessionFile(sessionFile) {
17
18
  if (stats.size > 50 * 1024 * 1024) {
18
19
  issues.push(`会话文件过大: ${sizeMB.toFixed(1)}MB`);
19
20
  }
20
- const content = await fsPromises.readFile(sessionFile, 'utf-8');
21
- const lines = content.split('\n').filter(l => l.trim());
22
- for (let i = 0; i < lines.length; i++) {
21
+ let row = 0;
22
+ let corrupt = false;
23
+ await visitSessionHistoryLines(sessionFile, line => {
24
+ if (!line.trim())
25
+ return;
26
+ row++;
23
27
  try {
24
- JSON.parse(lines[i]);
28
+ JSON.parse(line);
25
29
  }
26
30
  catch (e) {
27
- issues.push(`会话文件格式损坏(第 ${i + 1} 行)`);
28
- return { healthy: false, issues, corrupt: true, fileSize: stats.size };
31
+ issues.push(`会话文件格式损坏(第 ${row} 行)`);
32
+ corrupt = true;
33
+ return false;
29
34
  }
30
- }
35
+ });
31
36
  return {
32
37
  healthy: issues.length === 0,
33
38
  issues,
39
+ ...(corrupt ? { corrupt: true } : {}),
34
40
  fileSize: stats.size
35
41
  };
36
42
  }
@@ -157,13 +163,35 @@ export async function repairCodexSessionProvider(options) {
157
163
  const { DatabaseSync } = requireFromHere('node:sqlite');
158
164
  const directory = rollout + '.provider-repair';
159
165
  const journalFile = path.join(directory, 'intent.json');
166
+ const assertIndexedRolloutPath = (indexedPath) => {
167
+ const context = `thread=${threadId}, database=${JSON.stringify(database)},`
168
+ + ` index=${JSON.stringify(indexedPath)}, rollout=${JSON.stringify(rollout)}`;
169
+ let indexedRealPath;
170
+ let rolloutRealPath;
171
+ try {
172
+ // Windows Codex stores verbatim paths (\\?\) in SQLite. Resolve both
173
+ // through the filesystem instead of comparing their textual spelling.
174
+ indexedRealPath = fs.realpathSync.native(indexedPath);
175
+ rolloutRealPath = fs.realpathSync.native(rollout);
176
+ }
177
+ catch (cause) {
178
+ throw new Error(`Codex thread index rollout path cannot be resolved (${context}): `
179
+ + (cause instanceof Error ? cause.message : String(cause)), { cause });
180
+ }
181
+ if (indexedRealPath !== rolloutRealPath) {
182
+ throw new Error(`Codex thread index rollout path mismatch (${context})`);
183
+ }
184
+ };
160
185
  const readIndex = () => {
161
186
  const db = new DatabaseSync(database, { readOnly: true });
162
187
  try {
163
188
  const row = db.prepare('SELECT model_provider, rollout_path FROM threads WHERE id = ?').get(threadId);
164
- if (!row || typeof row.model_provider !== 'string' || typeof row.rollout_path !== 'string'
165
- || path.resolve(row.rollout_path) !== rollout)
166
- throw new Error('Codex thread index does not match its rollout');
189
+ if (!row)
190
+ throw new Error(`Codex thread index row is missing (thread=${threadId})`);
191
+ if (typeof row.model_provider !== 'string' || typeof row.rollout_path !== 'string') {
192
+ throw new Error(`Codex thread index fields are invalid (thread=${threadId})`);
193
+ }
194
+ assertIndexedRolloutPath(row.rollout_path);
167
195
  return row;
168
196
  }
169
197
  finally {
@@ -192,12 +220,13 @@ export async function repairCodexSessionProvider(options) {
192
220
  const apply = (intent) => {
193
221
  const backupRoot = path.join(directory, path.basename(path.dirname(intent.backup)));
194
222
  if (intent.version !== 1 || intent.threadId !== threadId || intent.database !== database
195
- || intent.rollout !== rollout || path.resolve(intent.indexedPath) !== rollout
223
+ || intent.rollout !== rollout || typeof intent.indexedPath !== 'string'
196
224
  || intent.backup !== path.join(backupRoot, 'before.snapshot')
197
225
  || intent.next !== path.join(backupRoot, 'after.snapshot')
198
226
  || !/^evolcore_registry_[a-f0-9]{20}$/.test(intent.provider)) {
199
227
  throw new Error('Invalid Codex Provider repair journal');
200
228
  }
229
+ assertIndexedRolloutPath(intent.indexedPath);
201
230
  assertRepairFile(intent.backup, directory);
202
231
  const original = fs.readFileSync(intent.backup);
203
232
  const replacement = rewriteCodexProvider(original, threadId, intent.provider);
@@ -264,9 +293,15 @@ export async function repairCodexSessionProvider(options) {
264
293
  }
265
294
  const bytes = fs.readFileSync(rollout);
266
295
  const current = readIndex();
267
- if (codexMetadata(bytes, threadId).provider !== provider || current.model_provider !== provider) {
268
- if (codexMetadata(bytes, threadId).provider !== current.model_provider) {
269
- throw new Error('Codex Provider repair rejected: rollout and index disagree');
296
+ const rolloutProvider = codexMetadata(bytes, threadId).provider;
297
+ if (rolloutProvider !== provider || current.model_provider !== provider) {
298
+ // Codex 0.164 can resume with a new Provider by updating only the index.
299
+ // Allow its stale header to catch up when the index already names our
300
+ // resolved Provider; unrelated disagreements still fail closed.
301
+ if (rolloutProvider !== current.model_provider && current.model_provider !== provider) {
302
+ throw new Error('Codex Provider repair rejected: rollout and index disagree'
303
+ + ` (thread=${threadId}, rollout=${JSON.stringify(rolloutProvider)},`
304
+ + ` index=${JSON.stringify(current.model_provider)}, target=${JSON.stringify(provider)})`);
270
305
  }
271
306
  const backupRoot = path.join(directory, randomUUID());
272
307
  fs.mkdirSync(backupRoot, { mode: 0o700 });