@capybara-hq/kernel 0.1.0-rc.36 → 0.1.0-rc.38

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 (351) hide show
  1. package/bootstrap.json +5 -5
  2. package/dist/admin/admin.module.d.ts +3 -2
  3. package/dist/admin/admin.module.js +9 -5
  4. package/dist/admin/audit-log.service.d.ts +51 -0
  5. package/dist/admin/{platform-audit.service.js → audit-log.service.js} +20 -12
  6. package/dist/admin/audit.controller.d.ts +18 -6
  7. package/dist/admin/audit.controller.js +36 -6
  8. package/dist/admin/audit.schemas.d.ts +9 -1
  9. package/dist/admin/audit.schemas.js +22 -2
  10. package/dist/admin/org-network.controller.d.ts +30 -0
  11. package/dist/admin/org-network.controller.js +77 -0
  12. package/dist/admin/org-network.schemas.d.ts +16 -0
  13. package/dist/admin/org-network.schemas.js +27 -0
  14. package/dist/admin/org-network.service.d.ts +41 -0
  15. package/dist/admin/org-network.service.js +101 -0
  16. package/dist/admin/outbox-dead.controller.d.ts +4 -6
  17. package/dist/admin/outbox-dead.controller.js +9 -6
  18. package/dist/admin/outbox-dead.schemas.d.ts +16 -0
  19. package/dist/admin/outbox-dead.schemas.js +25 -1
  20. package/dist/admin/outbox-dead.service.d.ts +16 -7
  21. package/dist/admin/outbox-dead.service.js +34 -10
  22. package/dist/admin/overview.service.d.ts +3 -3
  23. package/dist/admin/overview.service.js +0 -1
  24. package/dist/agents/agent-lookup.js +2 -10
  25. package/dist/agents/agents.service.js +9 -20
  26. package/dist/agents/definition.d.ts +3 -51
  27. package/dist/agents/definition.js +4 -254
  28. package/dist/agents/org-templates.js +2 -6
  29. package/dist/agents/readiness.controller.d.ts +4 -12
  30. package/dist/agents/readiness.controller.js +4 -12
  31. package/dist/agents/readiness.service.d.ts +23 -11
  32. package/dist/agents/readiness.service.js +31 -14
  33. package/dist/agents/templates.d.ts +0 -6
  34. package/dist/agents/templates.js +8 -34
  35. package/dist/background/store.d.ts +2 -0
  36. package/dist/background/store.js +3 -1
  37. package/dist/background/wake-rules.js +2 -1
  38. package/dist/catalog/admin-catalog.controller.d.ts +1 -2
  39. package/dist/catalog/admin-catalog.controller.js +1 -2
  40. package/dist/catalog/appearance.service.js +1 -3
  41. package/dist/catalog/catalog-content.d.ts +1 -1
  42. package/dist/catalog/catalog-content.js +1 -4
  43. package/dist/catalog/catalog-items.js +3 -3
  44. package/dist/catalog/catalog-scope.service.d.ts +10 -28
  45. package/dist/catalog/catalog-scope.service.js +22 -73
  46. package/dist/catalog/cli.d.ts +0 -11
  47. package/dist/catalog/cli.js +0 -20
  48. package/dist/catalog/component-scope.service.js +0 -2
  49. package/dist/catalog/component-state.js +2 -2
  50. package/dist/catalog/install-status.d.ts +6 -0
  51. package/dist/catalog/install-status.js +6 -0
  52. package/dist/catalog/job-ids.d.ts +0 -4
  53. package/dist/catalog/job-ids.js +0 -4
  54. package/dist/catalog/marketplaces.service.d.ts +1 -1
  55. package/dist/catalog/org-catalog.service.d.ts +2 -0
  56. package/dist/catalog/org-catalog.service.js +8 -3
  57. package/dist/catalog/org-extension-switch.d.ts +7 -2
  58. package/dist/catalog/org-extension-switch.js +56 -9
  59. package/dist/catalog/org-plugin-uploads.d.ts +6 -15
  60. package/dist/catalog/org-plugin-uploads.js +9 -27
  61. package/dist/catalog/owned-items.js +1 -3
  62. package/dist/catalog/platform-import-update.js +1 -1
  63. package/dist/catalog/plugin-import.d.ts +15 -13
  64. package/dist/catalog/plugin-import.js +21 -30
  65. package/dist/catalog/plugin-install.d.ts +3 -43
  66. package/dist/catalog/plugin-install.js +8 -150
  67. package/dist/catalog/plugin-package.d.ts +5 -10
  68. package/dist/catalog/plugin-package.js +12 -33
  69. package/dist/catalog/plugin-upgrade.js +5 -4
  70. package/dist/catalog/scope-jobs.d.ts +34 -34
  71. package/dist/catalog/scope-jobs.js +50 -37
  72. package/dist/catalog/scope-orgs.d.ts +1 -1
  73. package/dist/catalog/scope-orgs.js +1 -2
  74. package/dist/catalog/scope-sync-workers.d.ts +4 -3
  75. package/dist/catalog/scope-sync-workers.js +18 -6
  76. package/dist/catalog/scope-sync.d.ts +56 -59
  77. package/dist/catalog/scope-sync.js +96 -166
  78. package/dist/catalog/unshare.d.ts +3 -4
  79. package/dist/catalog/unshare.js +5 -8
  80. package/dist/channels/job-ids.d.ts +2 -6
  81. package/dist/channels/job-ids.js +2 -6
  82. package/dist/channels/outbound.d.ts +1 -1
  83. package/dist/channels/outbound.js +1 -1
  84. package/dist/channels/supervisor.d.ts +2 -3
  85. package/dist/channels/supervisor.js +2 -3
  86. package/dist/client/client-access.service.js +1 -1
  87. package/dist/config/env.js +19 -1
  88. package/dist/config/load.d.ts +0 -6
  89. package/dist/config/load.js +8 -27
  90. package/dist/config/schema.d.ts +54 -47
  91. package/dist/config/schema.js +198 -42
  92. package/dist/conversations/attachments.service.d.ts +10 -3
  93. package/dist/conversations/attachments.service.js +49 -16
  94. package/dist/conversations/conversations.controller.d.ts +0 -39
  95. package/dist/conversations/conversations.controller.js +0 -39
  96. package/dist/conversations/event-log.js +4 -1
  97. package/dist/conversations/events.d.ts +71 -46
  98. package/dist/conversations/events.js +124 -112
  99. package/dist/conversations/media-types.d.ts +25 -0
  100. package/dist/conversations/media-types.js +38 -0
  101. package/dist/conversations/queue.d.ts +3 -1
  102. package/dist/conversations/queue.service.js +9 -2
  103. package/dist/conversations/titles.js +6 -0
  104. package/dist/ctx/create-ctx.d.ts +8 -1
  105. package/dist/ctx/create-ctx.js +13 -3
  106. package/dist/ctx/net.d.ts +50 -0
  107. package/dist/ctx/net.js +67 -0
  108. package/dist/ctx/secrets.d.ts +24 -7
  109. package/dist/ctx/secrets.js +97 -30
  110. package/dist/db/kernel-schema.d.ts +27 -6
  111. package/dist/devices/devices.service.js +2 -1
  112. package/dist/errors.d.ts +10 -2
  113. package/dist/errors.js +10 -2
  114. package/dist/evals/reconstruct.d.ts +4 -17
  115. package/dist/evals/reconstruct.js +13 -53
  116. package/dist/evals/recorded-tools.d.ts +0 -27
  117. package/dist/evals/recorded-tools.js +2 -92
  118. package/dist/evals/run-replay.d.ts +1 -6
  119. package/dist/evals/run-replay.js +10 -17
  120. package/dist/evals/sets.service.d.ts +17 -5
  121. package/dist/evals/sets.service.js +33 -12
  122. package/dist/evals/snapshot.d.ts +1 -2
  123. package/dist/evals/snapshot.js +4 -17
  124. package/dist/extensions/admin-ops.d.ts +6 -1
  125. package/dist/extensions/admin-ops.js +17 -4
  126. package/dist/extensions/admin-view.d.ts +7 -4
  127. package/dist/extensions/admin-view.js +27 -21
  128. package/dist/extensions/bootstrap.js +0 -1
  129. package/dist/extensions/cli.js +0 -1
  130. package/dist/extensions/extensions.module.js +3 -0
  131. package/dist/extensions/host.d.ts +9 -4
  132. package/dist/extensions/host.js +14 -8
  133. package/dist/extensions/installs.d.ts +1 -3
  134. package/dist/extensions/instance.d.ts +0 -2
  135. package/dist/extensions/instance.js +0 -3
  136. package/dist/extensions/org-config.d.ts +4 -4
  137. package/dist/extensions/org-config.js +13 -22
  138. package/dist/extensions/package.d.ts +6 -6
  139. package/dist/extensions/package.js +3 -7
  140. package/dist/extensions/permission-view.d.ts +2 -4
  141. package/dist/extensions/plugin-items.d.ts +21 -1
  142. package/dist/extensions/plugin-items.js +28 -0
  143. package/dist/extensions/sync.js +5 -10
  144. package/dist/extensions/unavailable.js +0 -1
  145. package/dist/http/api.module.js +4 -1
  146. package/dist/identity/audit.d.ts +0 -12
  147. package/dist/identity/audit.js +0 -27
  148. package/dist/identity/auth.controller.js +5 -9
  149. package/dist/identity/cookies.d.ts +4 -9
  150. package/dist/identity/cookies.js +8 -32
  151. package/dist/identity/initial-passwords.d.ts +1 -1
  152. package/dist/identity/initial-passwords.js +1 -2
  153. package/dist/identity/sessions.d.ts +0 -6
  154. package/dist/identity/sessions.js +0 -18
  155. package/dist/inbox/platform-inbox.service.d.ts +33 -1
  156. package/dist/inbox/platform-inbox.service.js +56 -6
  157. package/dist/index.d.ts +4 -2
  158. package/dist/index.js +4 -2
  159. package/dist/infra/cli/master-key-rewrap.d.ts +15 -0
  160. package/dist/infra/cli/master-key-rewrap.js +24 -0
  161. package/dist/infra/config/kernel-config.service.js +0 -17
  162. package/dist/infra/database/transaction-host.d.ts +32 -1
  163. package/dist/infra/database/transaction-host.js +30 -4
  164. package/dist/infra/database/xact-lock.d.ts +16 -0
  165. package/dist/infra/database/xact-lock.js +28 -1
  166. package/dist/infra/health/health.controller.js +8 -0
  167. package/dist/infra/health/process-fault.d.ts +16 -0
  168. package/dist/infra/health/process-fault.js +49 -0
  169. package/dist/infra/lifecycle/process-guards.d.ts +8 -2
  170. package/dist/infra/lifecycle/process-guards.js +12 -3
  171. package/dist/infra/lifecycle/shutdown-signals.d.ts +10 -1
  172. package/dist/infra/lifecycle/shutdown-signals.js +28 -13
  173. package/dist/infra/outbox/outbox.service.d.ts +12 -9
  174. package/dist/infra/outbox/outbox.service.js +22 -26
  175. package/dist/infra/outbox/registry.d.ts +15 -7
  176. package/dist/infra/outbox/registry.js +39 -23
  177. package/dist/lifecycle/kernel-lifecycle.js +1 -7
  178. package/dist/models/enablement.d.ts +5 -6
  179. package/dist/models/enablement.js +7 -14
  180. package/dist/net/public-address.d.ts +21 -1
  181. package/dist/net/public-address.js +56 -10
  182. package/dist/net/safe-fetch.d.ts +4 -1
  183. package/dist/net/safe-fetch.js +15 -4
  184. package/dist/orgs/directory-sync.js +2 -0
  185. package/dist/orgs/members.service.js +5 -0
  186. package/dist/orgs/network-allowances.service.d.ts +79 -0
  187. package/dist/orgs/network-allowances.service.js +371 -0
  188. package/dist/orgs/offboarding.d.ts +3 -1
  189. package/dist/orgs/offboarding.js +9 -2
  190. package/dist/orgs/org-lock.d.ts +28 -2
  191. package/dist/orgs/org-lock.js +59 -4
  192. package/dist/orgs/orgs.controller.d.ts +11 -2
  193. package/dist/orgs/orgs.controller.js +19 -3
  194. package/dist/orgs/orgs.module.d.ts +3 -2
  195. package/dist/orgs/orgs.module.js +6 -2
  196. package/dist/orgs/orgs.schemas.d.ts +12 -0
  197. package/dist/orgs/orgs.schemas.js +5 -0
  198. package/dist/orgs/orgs.service.js +6 -1
  199. package/dist/orgs/settings.controller.d.ts +3 -2
  200. package/dist/orgs/settings.service.d.ts +59 -14
  201. package/dist/orgs/settings.service.js +102 -20
  202. package/dist/overrides.d.ts +7 -7
  203. package/dist/overrides.js +4 -4
  204. package/dist/packages/tgz.d.ts +0 -2
  205. package/dist/packages/tgz.js +0 -2
  206. package/dist/platform/exclusions.js +0 -5
  207. package/dist/platform/operation.js +1 -1
  208. package/dist/platform/ops/admin.ops.d.ts +2 -2
  209. package/dist/platform/ops/admin.ops.js +9 -6
  210. package/dist/platform/ops/agents.ops.js +1 -1
  211. package/dist/platform/ops/connectors.ops.js +46 -1
  212. package/dist/platform/ops/evals.ops.js +1 -64
  213. package/dist/platform/ops/extensions-admin.ops.js +1 -1
  214. package/dist/platform/ops/inbox.ops.js +16 -3
  215. package/dist/platform/ops/org-plugins.ops.js +1 -1
  216. package/dist/platform/ops/orgs.ops.d.ts +11 -3
  217. package/dist/platform/ops/orgs.ops.js +139 -5
  218. package/dist/platform/ops/outbox.ops.js +5 -5
  219. package/dist/platform/route-schemas.js +3 -0
  220. package/dist/roles/worker-role.d.ts +2 -3
  221. package/dist/roles/worker-role.js +3 -13
  222. package/dist/runtime/checkpointer.d.ts +3 -0
  223. package/dist/runtime/checkpointer.js +7 -4
  224. package/dist/runtime/context/build.d.ts +56 -18
  225. package/dist/runtime/context/build.js +143 -50
  226. package/dist/runtime/context/compaction.d.ts +1 -3
  227. package/dist/runtime/context/compaction.js +42 -8
  228. package/dist/runtime/context/run-context.js +1 -2
  229. package/dist/runtime/context/skills.d.ts +27 -56
  230. package/dist/runtime/context/skills.js +42 -114
  231. package/dist/runtime/context/tool-changes.d.ts +3 -3
  232. package/dist/runtime/context/tool-changes.js +6 -16
  233. package/dist/runtime/hook-calls.d.ts +6 -6
  234. package/dist/runtime/hook-calls.js +7 -7
  235. package/dist/runtime/langgraph-loop.js +9 -3
  236. package/dist/runtime/maintenance.d.ts +3 -11
  237. package/dist/runtime/maintenance.js +5 -20
  238. package/dist/runtime/model-call.d.ts +5 -0
  239. package/dist/runtime/model-call.js +48 -36
  240. package/dist/runtime/providers.d.ts +33 -35
  241. package/dist/runtime/providers.js +64 -109
  242. package/dist/runtime/run-context.service.js +7 -22
  243. package/dist/runtime/run-deletion.d.ts +6 -0
  244. package/dist/runtime/run-deletion.js +39 -16
  245. package/dist/runtime/run-execution.d.ts +56 -3
  246. package/dist/runtime/run-execution.js +81 -11
  247. package/dist/runtime/run-finish.js +2 -1
  248. package/dist/runtime/run-liveness.d.ts +11 -0
  249. package/dist/runtime/run-liveness.js +19 -0
  250. package/dist/runtime/run-orphan-check.job.js +2 -1
  251. package/dist/runtime/run-queue.js +8 -16
  252. package/dist/runtime/run-worker.d.ts +2 -2
  253. package/dist/runtime/run-worker.js +8 -6
  254. package/dist/runtime/step-log.d.ts +5 -0
  255. package/dist/runtime/step-log.js +9 -4
  256. package/dist/runtime/subagents/definition.d.ts +16 -20
  257. package/dist/runtime/subagents/definition.js +27 -27
  258. package/dist/runtime/subagents/dispatch.d.ts +6 -2
  259. package/dist/runtime/subagents/dispatch.js +17 -3
  260. package/dist/runtime/subagents/org-agents.js +1 -2
  261. package/dist/runtime/subagents/preamble.d.ts +3 -2
  262. package/dist/runtime/subagents/preamble.js +3 -2
  263. package/dist/runtime/subagents/render.d.ts +1 -2
  264. package/dist/runtime/subagents/render.js +1 -2
  265. package/dist/runtime/subagents/skill-fork.d.ts +2 -4
  266. package/dist/runtime/subagents/template-skills.d.ts +47 -0
  267. package/dist/runtime/subagents/template-skills.js +76 -0
  268. package/dist/runtime/waits.js +3 -1
  269. package/dist/schedules/effective-settings.d.ts +9 -3
  270. package/dist/schedules/effective-settings.js +5 -4
  271. package/dist/schedules/fire.js +11 -0
  272. package/dist/schedules/scheduled-tasks.service.js +5 -0
  273. package/dist/schedules/unattended.d.ts +2 -0
  274. package/dist/schedules/unattended.js +6 -1
  275. package/dist/skills/agent-skills.service.js +1 -2
  276. package/dist/skills/catalog.d.ts +1 -3
  277. package/dist/skills/catalog.js +1 -3
  278. package/dist/skills/conversation-catalog.d.ts +1 -2
  279. package/dist/skills/conversation-catalog.js +1 -2
  280. package/dist/skills/usable.js +2 -3
  281. package/dist/storage/storage.service.js +9 -1
  282. package/dist/tools/approvals.service.js +2 -4
  283. package/dist/tools/builtin-names.d.ts +2 -9
  284. package/dist/tools/builtin-names.js +4 -13
  285. package/dist/tools/builtins/sandbox/bash.js +3 -3
  286. package/dist/tools/builtins/sandbox/common.d.ts +7 -13
  287. package/dist/tools/builtins/sandbox/common.js +8 -115
  288. package/dist/tools/builtins/sandbox/fetch-attachment.d.ts +10 -0
  289. package/dist/tools/builtins/sandbox/fetch-attachment.js +119 -0
  290. package/dist/tools/builtins/sandbox/glob.js +1 -3
  291. package/dist/tools/builtins/sandbox/grep.js +3 -5
  292. package/dist/tools/builtins/sandbox/index.d.ts +8 -5
  293. package/dist/tools/builtins/sandbox/index.js +10 -5
  294. package/dist/tools/builtins/sandbox/read.js +3 -2
  295. package/dist/tools/builtins/tool-search.d.ts +4 -7
  296. package/dist/tools/builtins/tool-search.js +6 -10
  297. package/dist/tools/connector-account-policies.d.ts +30 -3
  298. package/dist/tools/connector-account-policies.js +54 -7
  299. package/dist/tools/connector-content.js +1 -0
  300. package/dist/tools/connectors.controller.d.ts +24 -11
  301. package/dist/tools/connectors.controller.js +35 -6
  302. package/dist/tools/connectors.schemas.d.ts +14 -1
  303. package/dist/tools/connectors.schemas.js +14 -2
  304. package/dist/tools/connectors.service.d.ts +22 -0
  305. package/dist/tools/connectors.service.js +65 -6
  306. package/dist/tools/drift.d.ts +6 -2
  307. package/dist/tools/drift.js +10 -5
  308. package/dist/tools/git-push-policy.d.ts +4 -1
  309. package/dist/tools/git-push-policy.js +3 -1
  310. package/dist/tools/info.d.ts +1 -7
  311. package/dist/tools/info.js +5 -18
  312. package/dist/tools/job-ids.d.ts +0 -4
  313. package/dist/tools/job-ids.js +1 -6
  314. package/dist/tools/pipeline.d.ts +4 -10
  315. package/dist/tools/pipeline.js +17 -62
  316. package/dist/tools/policy.d.ts +6 -2
  317. package/dist/tools/policy.js +14 -12
  318. package/dist/tools/registry.js +1 -5
  319. package/dist/ui/views.d.ts +5 -5
  320. package/dist/ui/views.js +10 -16
  321. package/package.json +3 -3
  322. package/src/migrations/0137_audit_org_idx.sql +5 -0
  323. package/src/migrations/0138_plugin_install_status_no_upgrading.sql +18 -0
  324. package/src/migrations/0139_retire_legacy_forms.sql +183 -0
  325. package/src/migrations/0140_retire_history_forms.sql +148 -0
  326. package/src/migrations/0141_install_ledger_promoted_rows.sql +36 -0
  327. package/src/migrations/0142_backfill_event_fields.sql +74 -0
  328. package/src/migrations/0143_backfill_model_call_fields.sql +105 -0
  329. package/src/migrations/0144_retire_frozen_definition_keys.sql +163 -0
  330. package/src/migrations/0145_org_network_allowances.sql +12 -0
  331. package/dist/admin/platform-audit.service.d.ts +0 -41
  332. package/dist/conversations/job-ids.d.ts +0 -6
  333. package/dist/conversations/job-ids.js +0 -6
  334. package/dist/extensions/job-ids.d.ts +0 -6
  335. package/dist/extensions/job-ids.js +0 -6
  336. package/dist/infra/queue/retired-schedulers.d.ts +0 -7
  337. package/dist/infra/queue/retired-schedulers.js +0 -9
  338. package/dist/orgs/job-ids.d.ts +0 -8
  339. package/dist/orgs/job-ids.js +0 -8
  340. package/dist/runtime/context/legacy-text.d.ts +0 -22
  341. package/dist/runtime/context/legacy-text.js +0 -37
  342. package/dist/runtime/job-ids.d.ts +0 -10
  343. package/dist/runtime/job-ids.js +0 -10
  344. package/dist/runtime/retired-schedulers.d.ts +0 -7
  345. package/dist/runtime/retired-schedulers.js +0 -31
  346. package/dist/storage/job-ids.d.ts +0 -6
  347. package/dist/storage/job-ids.js +0 -6
  348. package/dist/tools/legacy-data.d.ts +0 -34
  349. package/dist/tools/legacy-data.js +0 -76
  350. package/dist/tools/legacy-keys.d.ts +0 -51
  351. package/dist/tools/legacy-keys.js +0 -114
@@ -11,17 +11,6 @@ import { CHILD_REMOVED_TOOLS } from "../runtime/subagents/definition.js";
11
11
  import { AGENT_TOOL } from "../tools/builtin-names.js";
12
12
  import { canonicalJson } from "./recorded-tools.js";
13
13
  import { toEvents } from "./snapshot.js";
14
- /**
15
- * Does a definition from before skills were on by default pin skills? Read raw: the normalizer
16
- * drops `skills.pinned` (skills default-on spec §4, §9).
17
- */
18
- const pinsSkills = (d) => {
19
- const skills = typeof d === "object" && d !== null ? d.skills : undefined;
20
- const pinned = typeof skills === "object" && skills !== null
21
- ? skills.pinned
22
- : undefined;
23
- return Array.isArray(pinned) && pinned.length > 0;
24
- };
25
14
  /** `R` when the caller did not resolve the org's settings (the built-in platform default). */
26
15
  const DEFAULT_RESERVE_TOKENS = COMPACTION_SETTINGS.parse({}).reserveTokens;
27
16
  /** Two hard-fit plans trim the same messages and blocks (the recorded plan may be absent). */
@@ -47,9 +36,7 @@ const DRIFT_ORDER = [
47
36
  "tools_changed",
48
37
  "tool_spec_missing",
49
38
  "definition_missing",
50
- "pinned_changed",
51
39
  "subagent_changed",
52
- "legacy_event",
53
40
  "params_changed",
54
41
  "model_switched",
55
42
  "media_missing",
@@ -85,12 +72,6 @@ export function reconstructRequest(s, modelCallSeq, opts) {
85
72
  const call = findCall(all, modelCallSeq);
86
73
  const rec = call.payload.request;
87
74
  const drift = new Set();
88
- if (rec.tools === undefined ||
89
- rec.params === undefined ||
90
- rec.absorbedUpToSeq === undefined ||
91
- rec.maxOutputTokens === undefined) {
92
- drift.add("legacy_event");
93
- }
94
75
  const origVersion = recordedVersion(s, all, call);
95
76
  const version = opts.agentVersion ?? origVersion;
96
77
  const started = subagentStartedOf(all);
@@ -137,22 +118,11 @@ export function reconstructRequest(s, modelCallSeq, opts) {
137
118
  model: { provider: call.payload.provider, model: call.payload.model },
138
119
  });
139
120
  }
140
- // pinned_changed (skills default-on spec §9): the snapshot in effect at the call pinned skills,
141
- // and no candidate pins any more (the migration rewrote the stored versions without pins). The
142
- // stub of definition_missing is no candidate, so it is skipped then; a child reports a logged
143
- // pin as subagent_changed instead.
144
- if (!baseline && started === undefined && !drift.has("definition_missing")) {
145
- const snap = inputEvents(all, call)
146
- .filter((e) => e.type === "skills_catalog")
147
- .at(-1);
148
- if ((snap?.payload.pinned ?? []).length > 0)
149
- drift.add("pinned_changed");
150
- }
151
121
  // 工具:按记录的顺序从快照取定义;取不到的从请求里去掉(基线与候选一样)
152
122
  const tools = [];
153
123
  const seen = new Set();
154
- const kept = (list) => (list ?? []).filter((t) => s.toolSpecs[t.specHash] !== undefined);
155
- for (const t of [...(rec.tools ?? []), ...(rec.catalog ?? [])]) {
124
+ const kept = (list) => list.filter((t) => s.toolSpecs[t.specHash] !== undefined);
125
+ for (const t of [...rec.tools, ...(rec.catalog ?? [])]) {
156
126
  if (seen.has(t.key))
157
127
  continue;
158
128
  seen.add(t.key);
@@ -173,11 +143,11 @@ export function reconstructRequest(s, modelCallSeq, opts) {
173
143
  }
174
144
  let params = opts.params;
175
145
  if (params === undefined) {
176
- const recorded = rec.params ?? {};
177
- const clean = sanitizeParams(opts.model.parameters, recorded);
146
+ const clean = sanitizeParams(opts.model.parameters, rec.params);
178
147
  params = clean.value;
179
- if (clean.dropped.length > 0 || !sameParams(clean.value, recorded))
148
+ if (clean.dropped.length > 0 || !sameParams(clean.value, rec.params)) {
180
149
  drift.add("params_changed");
150
+ }
181
151
  }
182
152
  const budget = opts.mediaBudgetBytes ?? rec.mediaBudgetBytes;
183
153
  const built = assembleModelRequest({
@@ -186,7 +156,7 @@ export function reconstructRequest(s, modelCallSeq, opts) {
186
156
  agentVersion: version,
187
157
  model: opts.model,
188
158
  step: call.payload.step,
189
- ...(rec.absorbedUpToSeq !== undefined && { absorbedUpToSeq: rec.absorbedUpToSeq }),
159
+ absorbedUpToSeq: rec.absorbedUpToSeq,
190
160
  params,
191
161
  tools,
192
162
  toolSearch: rec.catalog !== undefined,
@@ -194,13 +164,11 @@ export function reconstructRequest(s, modelCallSeq, opts) {
194
164
  ...(opts.mediaInfo !== undefined && { mediaInfo: opts.mediaInfo }),
195
165
  ...(opts.media !== undefined && { media: opts.media }),
196
166
  ...(budget !== undefined && { mediaBudgetBytes: budget }),
197
- defaultMaxOutputTokens: rec.maxOutputTokens ?? opts.model.maxOutputTokens,
167
+ defaultMaxOutputTokens: rec.maxOutputTokens,
198
168
  // The baseline replays the recorded output cap as sent: the runtime may have clamped it below
199
169
  // the agent's `maxOutputTokens` knob (context compaction spec §4.3), and recomputing it from the
200
170
  // knob would replay a larger cap. A candidate below recomputes the clamp and the trim instead.
201
- ...(baseline && rec.maxOutputTokens !== undefined
202
- ? { recordedMaxOutputTokens: rec.maxOutputTokens }
203
- : {}),
171
+ ...(baseline && { recordedMaxOutputTokens: rec.maxOutputTokens }),
204
172
  // the baseline replays the recorded trim (no reserve needed); a candidate below recomputes it
205
173
  ...(baseline && rec.fit !== undefined ? { fit: rec.fit } : {}),
206
174
  });
@@ -240,16 +208,12 @@ export function reconstructRequest(s, modelCallSeq, opts) {
240
208
  if (meta.systemHash !== rec.systemHash)
241
209
  drift.add("system_hash");
242
210
  // 与记录比较时排除快照里缺定义的工具(已记 tool_spec_missing)
243
- if (rec.tools !== undefined &&
244
- (!sameList(meta.tools, kept(rec.tools)) ||
245
- !sameList(meta.catalog, rec.catalog === undefined ? undefined : kept(rec.catalog)))) {
211
+ if (!sameList(meta.tools, kept(rec.tools)) ||
212
+ !sameList(meta.catalog, rec.catalog === undefined ? undefined : kept(rec.catalog))) {
246
213
  drift.add("tools_changed");
247
214
  }
248
215
  }
249
216
  // 媒体:按附件 id 与记录比较
250
- if (meta.media !== undefined && (rec.media === undefined || rec.mediaBudgetBytes === undefined)) {
251
- drift.add("legacy_event");
252
- }
253
217
  const recordedMedia = new Map((rec.media ?? []).map((m) => [m.attachmentId, m]));
254
218
  for (const m of meta.media ?? []) {
255
219
  const was = recordedMedia.get(m.attachmentId);
@@ -257,14 +221,13 @@ export function reconstructRequest(s, modelCallSeq, opts) {
257
221
  drift.add("media_missing");
258
222
  }
259
223
  else if (baseline &&
260
- rec.media !== undefined &&
261
224
  (was === undefined || was.outcome !== m.outcome || was.etag !== m.etag)) {
262
225
  drift.add("media_changed");
263
226
  }
264
227
  }
265
- if (baseline && rec.media !== undefined) {
228
+ if (baseline) {
266
229
  const now = new Set((meta.media ?? []).map((m) => m.attachmentId));
267
- if (rec.media.some((m) => !now.has(m.attachmentId)))
230
+ if ((rec.media ?? []).some((m) => !now.has(m.attachmentId)))
268
231
  drift.add("media_changed");
269
232
  }
270
233
  return { request, meta, drift: DRIFT_ORDER.filter((r) => drift.has(r)), mediaTokens };
@@ -314,8 +277,7 @@ const parentSide = (d, started) => canonicalJson({
314
277
  * Does a candidate change what a sub-agent (child) case would run (`subagent_changed`, spec
315
278
  * §15.1)? Pure, from the snapshot alone, comparing the model-visible parts of the effective
316
279
  * definition (instructions, turned-off skills, tools) with the logged one (`logged`, from its
317
- * `subagent_started`). A logged definition that pinned skills (`started.definition`, read raw)
318
- * differs from every candidate: none pins any more (skills default-on spec §9).
280
+ * `subagent_started`).
319
281
  * - the same agent version (`sameVersion`): the candidate is the logged definition with
320
282
  * overrides (instructions, model, params), compared field by field;
321
283
  * - another version of the case's agent: for an org agent child (`source: "agent"`) that agent's
@@ -336,8 +298,6 @@ const parentSide = (d, started) => canonicalJson({
336
298
  export function subagentChanged(started, logged, candidate, sameVersion,
337
299
  /** The parent's definition at the case's version (the snapshot's), for template children. */
338
300
  original) {
339
- if (pinsSkills(started.definition))
340
- return true;
341
301
  const keepAgent = hasAgent(logged);
342
302
  const childTools = (d) => childToolsOf(d, keepAgent);
343
303
  const differs = (instructions, skills, tools) => instructions !== logged.instructions ||
@@ -1,6 +1,5 @@
1
1
  import type { EventLog } from "../conversations/event-log.js";
2
2
  import { type DevicePathsPayload } from "../runtime/context/device-paths.js";
3
- import { type LegacyScope } from "../tools/legacy-keys.js";
4
3
  import { type ToolPipeline, type ToolStepContext } from "../tools/pipeline.js";
5
4
  import type { CaseSnapshot } from "./snapshot.js";
6
5
  /**
@@ -22,8 +21,6 @@ export interface RecordedCall {
22
21
  contentTypes?: string[];
23
22
  /** 原 `tool_call_started` 的定义指纹(没有开始事件的调用为空串)。 */
24
23
  specHash: string;
25
- /** The recorded call used release-candidate names; `toolKey` and `inputKey` are already the current ones. */
26
- legacy?: true;
27
24
  /**
28
25
  * The payload (roots, and the sandbox level when recorded) of the latest `device_paths` event
29
26
  * the original run had logged by this call's step (environments spec §13.1, ruling R22): set on
@@ -33,27 +30,6 @@ export interface RecordedCall {
33
30
  */
34
31
  devicePaths?: DevicePathsPayload;
35
32
  }
36
- /**
37
- * The connectors and extensions an rc `<x>__<tool>` key can name, from positive evidence in the
38
- * snapshot only (a head with no evidence, or evidence of both kinds, stays unmapped, so its
39
- * recorded calls are unmatched, which is a safe miss):
40
- * - a connector: the tool definition the key was recorded with (`toolSpecs`, found by the specHash of
41
- * its `tool_call_started` or its `model_call` tools / catalog entry) has `connectorData`;
42
- * - an extension: that definition exists without `connectorData` and its name is the key's tool
43
- * part, or an rc-era agent definition names exactly that tool as a `{ kind: "plugin", plugin: x, name }`
44
- * ref.
45
- */
46
- export declare function legacyScopeOf(s: CaseSnapshot): LegacyScope;
47
- /**
48
- * A recorded call in the current names: an rc builtin or `<x>__<tool>` key becomes its current
49
- * key with the input's parameters renamed. Only the recorded side is ever normalized; a call
50
- * already in current names (or one that cannot be mapped) is returned as is.
51
- */
52
- export declare function currentCall(name: string, input: unknown, scope: LegacyScope): {
53
- name: string;
54
- input: unknown;
55
- legacy: boolean;
56
- };
57
33
  /** 规范化 JSON:对象键递归按码点排序,数组保持顺序;`undefined` 按 JSON 规则省略。 */
58
34
  export declare function canonicalJson(v: unknown): string;
59
35
  /** The matching key of a call: the canonical JSON of its input without the ignored fields. */
@@ -76,10 +52,7 @@ export declare class RecordedToolPipeline implements Pick<ToolPipeline, "runStep
76
52
  private readonly d;
77
53
  private readonly used;
78
54
  private misses;
79
- private legacyHits;
80
55
  constructor(d: RecordedToolPipelineDeps);
81
- /** Calls so far matched with a recording made under release-candidate tool names. */
82
- legacyMatches(): number;
83
56
  /** 至今没有匹配到记录的调用数。 */
84
57
  unmatched(): number;
85
58
  runStep(ctx: ToolStepContext): Promise<{
@@ -1,7 +1,6 @@
1
1
  import { devicePathsChange, devicePathsLevel, } from "../runtime/context/device-paths.js";
2
2
  import { assistantIdemKey } from "../runtime/model-call.js";
3
3
  import { MATCH_IGNORED_FIELDS } from "../tools/builtin-names.js";
4
- import { isLegacyPrefixedKey, legacyToolInput, legacyToolKey, } from "../tools/legacy-keys.js";
5
4
  import { RUN_STOPPED_TEXT } from "../tools/pipeline.js";
6
5
  /**
7
6
  * 整轮回放的工具管线(C6 / Review Focus 3):只回放原运行记录的工具结果,**从不执行任何工具**——
@@ -10,85 +9,6 @@ import { RUN_STOPPED_TEXT } from "../tools/pipeline.js";
10
9
  */
11
10
  /** 没有匹配记录时模型看到的工具结果(模型可见,英文)。 */
12
11
  export const REPLAY_NO_RECORDING = "[replay] No recorded result matches this tool call (same tool and arguments); the tool was not executed during replay.";
13
- /**
14
- * The connectors and extensions an rc `<x>__<tool>` key can name, from positive evidence in the
15
- * snapshot only (a head with no evidence, or evidence of both kinds, stays unmapped, so its
16
- * recorded calls are unmatched, which is a safe miss):
17
- * - a connector: the tool definition the key was recorded with (`toolSpecs`, found by the specHash of
18
- * its `tool_call_started` or its `model_call` tools / catalog entry) has `connectorData`;
19
- * - an extension: that definition exists without `connectorData` and its name is the key's tool
20
- * part, or an rc-era agent definition names exactly that tool as a `{ kind: "plugin", plugin: x, name }`
21
- * ref.
22
- */
23
- export function legacyScopeOf(s) {
24
- const hashes = new Map();
25
- const note = (key, hash) => {
26
- if (!isLegacyPrefixedKey(key))
27
- return;
28
- const set = hashes.get(key) ?? new Set();
29
- if (hash !== undefined && hash !== "")
30
- set.add(hash);
31
- hashes.set(key, set);
32
- };
33
- for (const e of s.events) {
34
- if (e.type === "tool_call_started") {
35
- const p = e.payload;
36
- note(p.toolKey, p.specHash);
37
- }
38
- else if (e.type === "model_call") {
39
- const r = e.payload.request;
40
- for (const t of [...(r?.tools ?? []), ...(r?.catalog ?? [])])
41
- note(t.key, t.specHash);
42
- }
43
- }
44
- const extensionNames = new Set();
45
- const connectorSlugs = new Set();
46
- const planted = new Set();
47
- // rc-era snapshots hold definitions from before tools were on by default: an enabled `tools`
48
- // list of refs (tools default-on spec §2)
49
- for (const def of Object.values(s.definitions)) {
50
- const refs = def.tools;
51
- if (!Array.isArray(refs))
52
- continue;
53
- for (const t of refs) {
54
- if (t?.kind === "plugin" && typeof t.plugin === "string" && typeof t.name === "string") {
55
- planted.add(`${t.plugin}__${t.name}`);
56
- }
57
- }
58
- }
59
- for (const [key, set] of hashes) {
60
- const i = key.indexOf("__");
61
- const head = key.slice(0, i);
62
- const tool = key.slice(i + 2);
63
- for (const h of set) {
64
- const spec = s.toolSpecs[h];
65
- if (spec === undefined)
66
- continue;
67
- if (spec.connectorData !== undefined) {
68
- connectorSlugs.add(head);
69
- }
70
- else if (spec.name === tool) {
71
- extensionNames.add(head);
72
- }
73
- }
74
- }
75
- for (const key of planted) {
76
- if (hashes.has(key))
77
- extensionNames.add(key.slice(0, key.indexOf("__")));
78
- }
79
- return { connectorSlugs, extensionNames };
80
- }
81
- /**
82
- * A recorded call in the current names: an rc builtin or `<x>__<tool>` key becomes its current
83
- * key with the input's parameters renamed. Only the recorded side is ever normalized; a call
84
- * already in current names (or one that cannot be mapped) is returned as is.
85
- */
86
- export function currentCall(name, input, scope) {
87
- const key = legacyToolKey(name, scope);
88
- if (key === null)
89
- return { name, input, legacy: false };
90
- return { name: key, input: legacyToolInput(name, input), legacy: true };
91
- }
92
12
  /** 规范化 JSON:对象键递归按码点排序,数组保持顺序;`undefined` 按 JSON 规则省略。 */
93
13
  export function canonicalJson(v) {
94
14
  const norm = (x) => {
@@ -156,7 +76,6 @@ export function recordedCalls(s) {
156
76
  if (current !== undefined)
157
77
  pathsOf.set(a, current);
158
78
  }
159
- const scope = legacyScopeOf(s);
160
79
  const out = [];
161
80
  for (const e of own) {
162
81
  if (e.type !== "assistant_message")
@@ -170,11 +89,9 @@ export function recordedCalls(s) {
170
89
  const r = results.get(call.id);
171
90
  if (!r)
172
91
  continue;
173
- const cur = currentCall(call.name, call.input, scope);
174
92
  out.push({
175
- toolKey: cur.name,
176
- inputKey: matchKey(cur.name, cur.input),
177
- ...(cur.legacy && { legacy: true }),
93
+ toolKey: call.name,
94
+ inputKey: matchKey(call.name, call.input),
178
95
  content: r.content,
179
96
  isError: r.isError,
180
97
  ...(r.loadedTools !== undefined && { loadedTools: r.loadedTools }),
@@ -195,14 +112,9 @@ export class RecordedToolPipeline {
195
112
  d;
196
113
  used = new Set();
197
114
  misses = 0;
198
- legacyHits = 0;
199
115
  constructor(d) {
200
116
  this.d = d;
201
117
  }
202
- /** Calls so far matched with a recording made under release-candidate tool names. */
203
- legacyMatches() {
204
- return this.legacyHits;
205
- }
206
118
  /** 至今没有匹配到记录的调用数。 */
207
119
  unmatched() {
208
120
  return this.misses;
@@ -271,8 +183,6 @@ export class RecordedToolPipeline {
271
183
  if (i < 0)
272
184
  return undefined;
273
185
  this.used.add(i);
274
- if (this.d.recordings[i]?.legacy === true)
275
- this.legacyHits++;
276
186
  return this.d.recordings[i];
277
187
  }
278
188
  }
@@ -11,7 +11,7 @@ import type { AgentLoop, LoopOutcome } from "../runtime/loop.js";
11
11
  import { type MediaSourceDeps } from "../runtime/model-call.js";
12
12
  import type { ProviderRegistry } from "../runtime/providers.js";
13
13
  import type { RunFinish } from "../runtime/run-finish.js";
14
- import type { CaseSnapshot, SnapshotEvent } from "./snapshot.js";
14
+ import { type CaseSnapshot, type SnapshotEvent } from "./snapshot.js";
15
15
  import type { ResolvedCandidate } from "./step-replay.js";
16
16
  /**
17
17
  * 整轮回放(D2 / C6):在 `kind = 'eval'` 的隐藏对话里跑**同一个** `LangGraphLoop`,工具管线换成
@@ -42,11 +42,6 @@ export interface RunReplayResult {
42
42
  usage: ModelUsage;
43
43
  steps: number;
44
44
  unmatched: number;
45
- /**
46
- * Set when a call was matched with a recording made under the release-candidate tool names
47
- * (`sandbox_edit` for `Edit`, `docs__search` for `mcp__docs__search`, old parameter names).
48
- */
49
- legacyKeyMatch?: true;
50
45
  }
51
46
  /** 原运行(基线)的同形摘要。 */
52
47
  export type RunBaseline = Omit<RunReplayResult, "conversationId" | "outcome" | "unmatched">;
@@ -27,7 +27,8 @@ import { runContextIdemKey } from "../runtime/run-context.service.js";
27
27
  import { recordedSkillForks } from "../runtime/subagents/skill-fork.js";
28
28
  import { skillsCatalogIdemKey } from "../skills/catalog.js";
29
29
  import { ACTIVE_EVAL_STATUSES, addUsage, consumeTokens, TOO_MANY_ERRORS, usageTokens, } from "./budget.js";
30
- import { currentCall, legacyScopeOf, RecordedToolPipeline, recordedCalls, } from "./recorded-tools.js";
30
+ import { RecordedToolPipeline, recordedCalls } from "./recorded-tools.js";
31
+ import { toEvents } from "./snapshot.js";
31
32
  /** 写种子时发现已失去认领或运行已不在执行:本次执行停下,不留评测对话。 */
32
33
  export class ReplayClaimLost extends Error {
33
34
  constructor() {
@@ -210,7 +211,7 @@ const ZERO = {
210
211
  cacheWriteTokens: 0,
211
212
  };
212
213
  /** 一次运行的工具调用序列、最后的回复、停止原因、用量与步数(基线与候选同一算法)。 */
213
- function summarize(events, runId, scope) {
214
+ function summarize(events, runId) {
214
215
  const toolCalls = [];
215
216
  let usage = ZERO;
216
217
  let last = null;
@@ -224,12 +225,7 @@ function summarize(events, runId, scope) {
224
225
  for (const b of p.content) {
225
226
  if (b.type !== "tool_call")
226
227
  continue;
227
- if (scope === undefined)
228
- toolCalls.push({ name: b.name, input: b.input });
229
- else {
230
- const { name, input } = currentCall(b.name, b.input, scope);
231
- toolCalls.push({ name, input });
232
- }
228
+ toolCalls.push({ name: b.name, input: b.input });
233
229
  }
234
230
  last = { content: p.content, stopReason: p.stopReason };
235
231
  }
@@ -253,9 +249,7 @@ function summarize(events, runId, scope) {
253
249
  }
254
250
  /** 原运行(快照)的摘要,作为整轮回放的基线。 */
255
251
  export function runBaseline(s) {
256
- // an rc recording is read in the current tool names, so the diff against a candidate only
257
- // shows real differences
258
- return summarize(s.events, s.runId, legacyScopeOf(s));
252
+ return summarize(s.events, s.runId);
259
253
  }
260
254
  /**
261
255
  * 删掉一个评测对话(崩溃重跑前清掉上一次的残留):先删它各次运行的 checkpoint,再删对话(事件、运行随之级联删除)。
@@ -279,17 +273,17 @@ export async function deleteEvalConversation(d, conversationId) {
279
273
  .execute();
280
274
  }
281
275
  /**
282
- * 原运行每步开始时吸收到的位置(第一次尝试的 `absorbedUpToSeq`;较早的事件没有时取该 model_call 的 seq)。
276
+ * Where each step of the original run had taken in absorbable events (its first attempt's
277
+ * `absorbedUpToSeq`).
283
278
  */
284
279
  function absorbedByStep(s) {
285
280
  const out = new Map();
286
- for (const e of s.events) {
281
+ for (const e of toEvents(s)) {
287
282
  if (e.runId !== s.runId || e.type !== "model_call")
288
283
  continue;
289
- const p = e.payload;
290
- if (out.has(p.step))
284
+ if (out.has(e.payload.step))
291
285
  continue;
292
- out.set(p.step, p.request?.absorbedUpToSeq ?? e.seq);
286
+ out.set(e.payload.step, e.payload.request.absorbedUpToSeq);
293
287
  }
294
288
  return out;
295
289
  }
@@ -668,6 +662,5 @@ export async function replayRun(d, s, candidate, evalRunId, signal) {
668
662
  outcome: outcome.kind,
669
663
  ...summary,
670
664
  unmatched: pipeline.unmatched(),
671
- ...(pipeline.legacyMatches() > 0 && { legacyKeyMatch: true }),
672
665
  };
673
666
  }
@@ -61,7 +61,9 @@ export interface SampleInput {
61
61
  /** 用例标题:触发消息文本的前 80 个字符(按码点)。 */
62
62
  export declare const CASE_TITLE_CHARS = 80;
63
63
  /**
64
- * 快照运行的触发消息(该运行 `run_started` 之前最近的一条 `user_message`)的文本,空白折叠后取前 80 个字符。
64
+ * The text of the snapshot run's trigger message (the latest `user_message` before its
65
+ * `run_started`, never a template skill's invocation written after a sub-agent's task),
66
+ * whitespace collapsed, first 80 characters.
65
67
  */
66
68
  export declare function caseTitle(s: CaseSnapshot): string;
67
69
  /**
@@ -118,10 +120,20 @@ export declare class EvalSetsService {
118
120
  */
119
121
  private insertCase;
120
122
  /**
121
- * 把某次运行加为用例。对话不在本组织(或是 eval 对话)→ `conversation.not_found`;对话的 agent 不是集合的 agent →
122
- * `eval.agent_mismatch`;手动压缩运行(无模型步骤)→ `eval.compact_not_replayable`;已在集合里 →
123
- * `eval.case_exists`;集合满了 → `eval.too_many_cases`;运行未终态 / 快照超大 →
124
- * `eval.run_not_finished` / `eval.case_too_large`(`takeSnapshot`)。
123
+ * The admission checks of a case, in one place (the route and the Platform operation's precheck
124
+ * both call it); throws the `ApiError` the route gives. Writes nothing. Capacity is checked before
125
+ * the snapshot is taken (it can be large) and again under the lock when the case is written.
126
+ */
127
+ checkAddCase(orgId: string, setId: string, input: {
128
+ conversationId: string;
129
+ runId: string;
130
+ }): Promise<void>;
131
+ /**
132
+ * Adds a run as a case. Admission is `checkAddCase` (conversation not in the org or an eval
133
+ * conversation -> `conversation.not_found`; the conversation's agent is not the set's ->
134
+ * `eval.agent_mismatch`; manual compaction run -> `eval.compact_not_replayable`; already in the
135
+ * set -> `eval.case_exists`; set full -> `eval.too_many_cases`; run not finished / snapshot too
136
+ * large -> `eval.run_not_finished` / `eval.case_too_large` (`takeSnapshot`)).
125
137
  */
126
138
  addCase(orgId: string, actor: string, setId: string, input: {
127
139
  conversationId: string;
@@ -44,7 +44,9 @@ const STATUSES = {
44
44
  any: ["completed", "failed", "aborted"],
45
45
  };
46
46
  /**
47
- * 快照运行的触发消息(该运行 `run_started` 之前最近的一条 `user_message`)的文本,空白折叠后取前 80 个字符。
47
+ * The text of the snapshot run's trigger message (the latest `user_message` before its
48
+ * `run_started`, never a template skill's invocation written after a sub-agent's task),
49
+ * whitespace collapsed, first 80 characters.
48
50
  */
49
51
  export function caseTitle(s) {
50
52
  const started = s.events.find((e) => e.type === "run_started" && e.runId === s.runId);
@@ -56,6 +58,10 @@ export function caseTitle(s) {
56
58
  if (e.type !== "user_message")
57
59
  continue;
58
60
  const payload = e.payload;
61
+ // a template sub-agent's skill (or the notice that it could not be read), written after its
62
+ // task: the task titles the case
63
+ if (payload.skill?.template || payload.templateSkillNotice !== undefined)
64
+ continue;
59
65
  // a skill invocation: what the person typed, never the rendered skill (content[0])
60
66
  if (payload.skill !== undefined) {
61
67
  text = typedInvocation(payload.skill);
@@ -402,12 +408,11 @@ let EvalSetsService = EvalSetsService_1 = class EvalSetsService {
402
408
  return this.insertCaseIn(orgId, actor, setId, snapshot, extra, { max, json, plans, base });
403
409
  }
404
410
  /**
405
- * 把某次运行加为用例。对话不在本组织(或是 eval 对话)→ `conversation.not_found`;对话的 agent 不是集合的 agent →
406
- * `eval.agent_mismatch`;手动压缩运行(无模型步骤)→ `eval.compact_not_replayable`;已在集合里 →
407
- * `eval.case_exists`;集合满了 → `eval.too_many_cases`;运行未终态 / 快照超大 →
408
- * `eval.run_not_finished` / `eval.case_too_large`(`takeSnapshot`)。
411
+ * The admission checks of a case, in one place (the route and the Platform operation's precheck
412
+ * both call it); throws the `ApiError` the route gives. Writes nothing. Capacity is checked before
413
+ * the snapshot is taken (it can be large) and again under the lock when the case is written.
409
414
  */
410
- async addCase(orgId, actor, setId, input, actorTokenId, auditDetail) {
415
+ async checkAddCase(orgId, setId, input) {
411
416
  const set = await this.liveSet(orgId, setId);
412
417
  const conv = await this.db
413
418
  .selectFrom("conversations")
@@ -423,15 +428,18 @@ let EvalSetsService = EvalSetsService_1 = class EvalSetsService {
423
428
  if (conv.agent_id !== set.agent_id) {
424
429
  throw new ApiError("eval.agent_mismatch", "The run belongs to a different agent");
425
430
  }
426
- // a manual compaction run has no model step to replay (context compaction spec §4.7): it would
427
- // take a set slot and never produce a result, so it is refused with a clear code
428
431
  const run = await this.db
429
432
  .selectFrom("runs")
430
- .select("compact")
433
+ .select(["status", "compact"])
431
434
  .where("id", "=", input.runId)
432
435
  .where("conversation_id", "=", input.conversationId)
433
436
  .executeTakeFirst();
434
- if (run?.compact === true) {
437
+ if (run === undefined) {
438
+ throw new ApiError("conversation.not_found", "Conversation or run not found");
439
+ }
440
+ // a manual compaction run has no model step to replay (context compaction spec §4.7): it would
441
+ // take a set slot and never produce a result, so it is refused with a clear code
442
+ if (run.compact) {
435
443
  throw new ApiError("eval.compact_not_replayable", "A manual compaction run has no model step to replay, so it cannot be an eval case");
436
444
  }
437
445
  const exists = await this.db
@@ -442,10 +450,23 @@ let EvalSetsService = EvalSetsService_1 = class EvalSetsService {
442
450
  .executeTakeFirst();
443
451
  if (exists)
444
452
  throw caseExists();
445
- const { maxCasesPerSet, maxCaseBytes } = this.config.get().evals;
446
- // 先判容量再取快照(快照可能很大);写入时在锁内再判一次
453
+ if (run.status === "running" || run.status === "queued") {
454
+ throw new ApiError("eval.run_not_finished", "The run has not finished yet");
455
+ }
456
+ const { maxCasesPerSet } = this.config.get().evals;
447
457
  if ((await this.caseCount(this.db, setId)) >= maxCasesPerSet)
448
458
  throw tooMany(maxCasesPerSet);
459
+ }
460
+ /**
461
+ * Adds a run as a case. Admission is `checkAddCase` (conversation not in the org or an eval
462
+ * conversation -> `conversation.not_found`; the conversation's agent is not the set's ->
463
+ * `eval.agent_mismatch`; manual compaction run -> `eval.compact_not_replayable`; already in the
464
+ * set -> `eval.case_exists`; set full -> `eval.too_many_cases`; run not finished / snapshot too
465
+ * large -> `eval.run_not_finished` / `eval.case_too_large` (`takeSnapshot`)).
466
+ */
467
+ async addCase(orgId, actor, setId, input, actorTokenId, auditDetail) {
468
+ await this.checkAddCase(orgId, setId, input);
469
+ const { maxCasesPerSet, maxCaseBytes } = this.config.get().evals;
449
470
  const snapshot = await takeSnapshot(this.db, orgId, input.conversationId, input.runId, maxCaseBytes);
450
471
  const r = await this.insertCase(orgId, actor, setId, snapshot, {
451
472
  sampled: false,
@@ -66,8 +66,7 @@ export interface CaseSnapshot {
66
66
  export declare function takeSnapshot(db: KernelSchemaDb, orgId: string, conversationId: string, runId: string, maxBytes: number): Promise<CaseSnapshot>;
67
67
  /**
68
68
  * Reads a stored snapshot (`eval_cases.snapshot`): each version's definition goes through
69
- * `normalizeStoredDefinition` (rc tool keys, and an enabled tool list read as nothing turned off).
70
- * Other fields as they are.
69
+ * `normalizeStoredDefinition` (missing turned-off lists read as empty). Other fields as they are.
71
70
  */
72
71
  export declare function readSnapshot(raw: unknown): CaseSnapshot;
73
72
  /** 快照事件还原为日志事件(`createdAt` 转回 Date)。 */
@@ -84,7 +84,7 @@ export async function takeSnapshot(db, orgId, conversationId, runId, maxBytes) {
84
84
  }
85
85
  else if (e.type === "model_call") {
86
86
  const req = e.payload.request;
87
- for (const t of [...(req.tools ?? []), ...(req.catalog ?? [])])
87
+ for (const t of [...req.tools, ...(req.catalog ?? [])])
88
88
  hashes.add(t.specHash);
89
89
  }
90
90
  }
@@ -97,7 +97,7 @@ export async function takeSnapshot(db, orgId, conversationId, runId, maxBytes) {
97
97
  .orderBy("version")
98
98
  .execute();
99
99
  for (const r of defRows) {
100
- definitions[String(r.version)] = snapshotDefinition(r.definition);
100
+ definitions[String(r.version)] = normalizeStoredDefinition(r.definition);
101
101
  }
102
102
  const toolSpecs = {};
103
103
  if (hashes.size > 0) {
@@ -151,28 +151,15 @@ export async function takeSnapshot(db, orgId, conversationId, runId, maxBytes) {
151
151
  throw tooLarge();
152
152
  return snapshot;
153
153
  }
154
- /**
155
- * A definition as a snapshot holds it: normalized (`normalizeStoredDefinition`), and one from
156
- * before tools were on by default keeps its enabled list next to it: rc tool keys are read by its
157
- * extension refs (`legacyScopeOf`); the runtime ignores it (tools default-on spec §2).
158
- */
159
- function snapshotDefinition(d) {
160
- const enabled = d?.tools;
161
- return {
162
- ...normalizeStoredDefinition(d),
163
- ...(Array.isArray(enabled) && { tools: enabled }),
164
- };
165
- }
166
154
  /**
167
155
  * Reads a stored snapshot (`eval_cases.snapshot`): each version's definition goes through
168
- * `normalizeStoredDefinition` (rc tool keys, and an enabled tool list read as nothing turned off).
169
- * Other fields as they are.
156
+ * `normalizeStoredDefinition` (missing turned-off lists read as empty). Other fields as they are.
170
157
  */
171
158
  export function readSnapshot(raw) {
172
159
  const s = raw;
173
160
  const definitions = {};
174
161
  for (const [v, d] of Object.entries(s.definitions ?? {})) {
175
- definitions[v] = snapshotDefinition(d);
162
+ definitions[v] = normalizeStoredDefinition(d);
176
163
  }
177
164
  return {
178
165
  ...s,
@@ -3,6 +3,7 @@ import { SuperAdminLock } from "../identity/super-admin.js";
3
3
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
4
4
  import { KernelDb } from "../infra/database/kernel-db.js";
5
5
  import { TransactionHost } from "../infra/database/transaction-host.js";
6
+ import { OutboxService } from "../infra/outbox/outbox.service.js";
6
7
  import type { KernelLogger } from "../log.js";
7
8
  import { OrgLock } from "../orgs/org-lock.js";
8
9
  import { ExtensionAdmin, type PublishBus } from "./admin-view.js";
@@ -73,6 +74,8 @@ export declare class ExtensionAdminOps {
73
74
  private readonly log;
74
75
  /** One enabled provider per single-provider extension point (checked in the enable). */
75
76
  private readonly singleProvider;
77
+ /** The plugin scope sync a deploy owes (`oweDeployedExtensionSync`). */
78
+ private readonly outbox;
76
79
  constructor(kdb: KernelDb, txHost: TransactionHost,
77
80
  /** The super admin lock (identity/super-admin.ts): joins the transaction. */
78
81
  adminLock: SuperAdminLock,
@@ -97,7 +100,9 @@ export declare class ExtensionAdminOps {
97
100
  */
98
101
  lifecycle: ExtensionLifecycle, log: KernelLogger,
99
102
  /** One enabled provider per single-provider extension point (checked in the enable). */
100
- singleProvider: SingleProviderGuard);
103
+ singleProvider: SingleProviderGuard,
104
+ /** The plugin scope sync a deploy owes (`oweDeployedExtensionSync`). */
105
+ outbox: Pick<OutboxService, "add">);
101
106
  private get db();
102
107
  /**
103
108
  * New install or version change (upgrade / downgrade): the install record points at package