@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
@@ -0,0 +1,50 @@
1
+ import { type ExtensionNet, type Logger } from "@capybara-hq/plugin-sdk";
2
+ import type { Agent } from "undici";
3
+ import type { KernelConfigService } from "../infra/config/kernel-config.service.js";
4
+ import { type LookupFn } from "../net/public-address.js";
5
+ import type { OrgNetworkAllowances } from "../orgs/network-allowances.service.js";
6
+ /** Tests only: `safeFetch`'s DNS and dispatcher seams for `ctx.net`. */
7
+ export type ExtensionNetSeams = {
8
+ lookup?: LookupFn;
9
+ dispatcherFor?: (ips: string[]) => Agent;
10
+ proxyDispatcherFor?: (proxyUrl: string) => Agent;
11
+ };
12
+ /**
13
+ * Optional provider (a test seam, `KernelAppOptions.overrides`; the kernel never provides it):
14
+ * `ctx.net`'s DNS and dispatcher seams for every extension the host loads, so a kernel test can
15
+ * reach a fake server through a hostname that resolves to a private address.
16
+ */
17
+ export declare const EXTENSION_NET_SEAMS: unique symbol;
18
+ /** The kernel services `ctx.net` reads per call (built once by the extension host). */
19
+ export type ExtensionNetServices = {
20
+ config: Pick<KernelConfigService, "get">;
21
+ allowances: Pick<OrgNetworkAllowances, "policyFor">;
22
+ /** Tests only: `safeFetch`'s DNS and dispatcher seams. */
23
+ seams?: ExtensionNetSeams;
24
+ };
25
+ /** What a refused private address tells the reader of an org-bound request. */
26
+ export declare const ORG_PRIVATE_HINT = "ask a super admin to allow this internal endpoint for the organization";
27
+ /** What a refused private address tells the reader of a request made outside an organization. */
28
+ export declare const NO_ORG_PRIVATE_HINT = "a request made outside an organization reaches public addresses only";
29
+ /**
30
+ * `ctx.net` (plugin safe fetch spec): the kernel's guarded client (`safeFetch`) for URLs a person
31
+ * supplied. Per call:
32
+ * - the policy is built fresh: `net.allowInsecureLoopback` (tests), the org's allowances read from
33
+ * PG when `opts.orgId` is given (no cache: a removal applies to the next request on every
34
+ * replica; another org's allowances never apply), public addresses only without an org, and the
35
+ * deployment's egress proxy (`net.httpsProxy` / `net.noProxy`: a proxied https request is
36
+ * resolved by the proxy, which then owns SSRF protection; IP-literal targets are still checked);
37
+ * - loopback, link-local and cloud metadata addresses are refused whatever the allowances
38
+ * (loopback allowed only under `net.allowInsecureLoopback`);
39
+ * - redirects are never followed: `redirect: "manual"` returns the 3xx response, otherwise a 3xx
40
+ * rejects with `net.redirect`;
41
+ * - no body size cap (bodies stream); `init.signal` is combined with `ctx.signal`;
42
+ * - a refusal rejects with the SDK's `NetDeniedError` and is logged at `warn` with the plugin, org,
43
+ * host and code (never the URL's path, query or headers).
44
+ */
45
+ export declare function createExtensionNet(deps: ExtensionNetServices & {
46
+ log: Pick<Logger, "warn">;
47
+ plugin: string;
48
+ /** `ctx.signal`: aborts every request of the instance. */
49
+ signal: AbortSignal;
50
+ }): ExtensionNet;
@@ -0,0 +1,67 @@
1
+ import { NetDeniedError as SdkNetDeniedError, } from "@capybara-hq/plugin-sdk";
2
+ import { NetDeniedError } from "../net/public-address.js";
3
+ import { safeFetch } from "../net/safe-fetch.js";
4
+ /**
5
+ * Optional provider (a test seam, `KernelAppOptions.overrides`; the kernel never provides it):
6
+ * `ctx.net`'s DNS and dispatcher seams for every extension the host loads, so a kernel test can
7
+ * reach a fake server through a hostname that resolves to a private address.
8
+ */
9
+ export const EXTENSION_NET_SEAMS = Symbol("EXTENSION_NET_SEAMS");
10
+ /** What a refused private address tells the reader of an org-bound request. */
11
+ export const ORG_PRIVATE_HINT = "ask a super admin to allow this internal endpoint for the organization";
12
+ /** What a refused private address tells the reader of a request made outside an organization. */
13
+ export const NO_ORG_PRIVATE_HINT = "a request made outside an organization reaches public addresses only";
14
+ /**
15
+ * `ctx.net` (plugin safe fetch spec): the kernel's guarded client (`safeFetch`) for URLs a person
16
+ * supplied. Per call:
17
+ * - the policy is built fresh: `net.allowInsecureLoopback` (tests), the org's allowances read from
18
+ * PG when `opts.orgId` is given (no cache: a removal applies to the next request on every
19
+ * replica; another org's allowances never apply), public addresses only without an org, and the
20
+ * deployment's egress proxy (`net.httpsProxy` / `net.noProxy`: a proxied https request is
21
+ * resolved by the proxy, which then owns SSRF protection; IP-literal targets are still checked);
22
+ * - loopback, link-local and cloud metadata addresses are refused whatever the allowances
23
+ * (loopback allowed only under `net.allowInsecureLoopback`);
24
+ * - redirects are never followed: `redirect: "manual"` returns the 3xx response, otherwise a 3xx
25
+ * rejects with `net.redirect`;
26
+ * - no body size cap (bodies stream); `init.signal` is combined with `ctx.signal`;
27
+ * - a refusal rejects with the SDK's `NetDeniedError` and is logged at `warn` with the plugin, org,
28
+ * host and code (never the URL's path, query or headers).
29
+ */
30
+ export function createExtensionNet(deps) {
31
+ return {
32
+ async fetch(url, init, opts) {
33
+ const orgId = opts?.orgId;
34
+ const net = deps.config.get().net;
35
+ const exemptions = orgId
36
+ ? await deps.allowances.policyFor(orgId)
37
+ : { allowPrivateHosts: [], trustedOrigins: [] };
38
+ const policy = {
39
+ allowInsecureLoopback: net.allowInsecureLoopback,
40
+ allowPrivateHosts: exemptions.allowPrivateHosts,
41
+ trustedOrigins: exemptions.trustedOrigins,
42
+ ...(net.httpsProxy !== undefined && {
43
+ proxy: { url: net.httpsProxy, noProxy: net.noProxy },
44
+ }),
45
+ extension: { privateHint: orgId ? ORG_PRIVATE_HINT : NO_ORG_PRIVATE_HINT },
46
+ };
47
+ const signal = init?.signal ? AbortSignal.any([deps.signal, init.signal]) : deps.signal;
48
+ try {
49
+ return await safeFetch(url, { ...init, signal }, policy, {
50
+ redirects: init?.redirect === "manual" ? "return" : "refuse",
51
+ ...deps.seams,
52
+ });
53
+ }
54
+ catch (e) {
55
+ if (!(e instanceof NetDeniedError))
56
+ throw e;
57
+ deps.log.warn("ctx.net.fetch refused a request", {
58
+ plugin: deps.plugin,
59
+ orgId: orgId ?? null,
60
+ host: e.host,
61
+ code: e.code,
62
+ });
63
+ throw new SdkNetDeniedError(e.code, e.host, e.message, e.status);
64
+ }
65
+ },
66
+ };
67
+ }
@@ -1,5 +1,5 @@
1
1
  import type { ExtensionContext } from "@capybara-hq/plugin-sdk";
2
- import type { Kysely } from "kysely";
2
+ import { type Kysely } from "kysely";
3
3
  import type { KernelDb } from "../infra/database/kernel-db.js";
4
4
  import type { TransactionHost } from "../infra/database/transaction-host.js";
5
5
  /** 主密钥环:current 用于新包装,previous 仅用于解包。原始密钥只存在于闭包内。 */
@@ -42,12 +42,29 @@ export type KernelSecrets = ExtensionContext["secrets"] & {
42
42
  * `db` 可以是 Kysely 事务:此时读写(含首次创建组织数据密钥)都在该事务内。
43
43
  */
44
44
  export declare function createSecrets(db: AnyDb, keyring: Keyring, namespace: string): KernelSecrets;
45
- /**
46
- * 把非当前主密钥包装的数据密钥改用当前主密钥重新包装,返回处理条数。One transaction over the given
47
- * handles (`KernelDb` + its `TransactionHost`, as `DatabaseModule` provides them).
48
- */
49
- export declare function rewrapDataKeys(handles: {
45
+ /** What {@link rewrapToCurrentMasterKey} rewrapped. */
46
+ export interface RewrapResult {
47
+ /** Org data keys (`org_data_keys`) now wrapped with the current master key. */
48
+ dataKeys: number;
49
+ /** Unexpired one-time initial passwords (`account_initial_passwords`) now sealed with it. */
50
+ initialPasswords: number;
51
+ }
52
+ /** Rows rewrapped per transaction by default. */
53
+ export declare const REWRAP_BATCH_SIZE = 500;
54
+ /** The AAD binding a sealed initial password to its account (a row moved to another one fails). */
55
+ export declare const initialPasswordAad: (accountId: string) => string;
56
+ type RewrapHandles = {
50
57
  db: Pick<KernelDb, "db">;
51
58
  txHost: Pick<TransactionHost, "run">;
52
- }, keyring: Keyring): Promise<number>;
59
+ };
60
+ /**
61
+ * Rewraps everything sealed with a master key other than the keyring's current one (org data keys
62
+ * and unexpired initial passwords) with the current key, `batchSize` rows per transaction, until
63
+ * none is left. Checks first that the keyring holds every master key in use and throws (naming row
64
+ * ids and key ids, never key material) before writing anything when it does not. Idempotent: a
65
+ * second run finds nothing; concurrent runs lock the same rows and skip the ones already done.
66
+ */
67
+ export declare function rewrapToCurrentMasterKey(handles: RewrapHandles, keyring: Keyring, opts?: {
68
+ batchSize?: number;
69
+ }): Promise<RewrapResult>;
53
70
  export {};
@@ -1,4 +1,5 @@
1
1
  import { createCipheriv, createDecipheriv, createHash, hkdfSync, randomBytes } from "node:crypto";
2
+ import { sql } from "kysely";
2
3
  import { assertNamespace } from "./namespace.js";
3
4
  const IV_LEN = 12;
4
5
  const TAG_LEN = 16;
@@ -142,38 +143,104 @@ export function createSecrets(db, keyring, namespace) {
142
143
  },
143
144
  };
144
145
  }
146
+ /** Rows rewrapped per transaction by default. */
147
+ export const REWRAP_BATCH_SIZE = 500;
148
+ /** The AAD binding a sealed initial password to its account (a row moved to another one fails). */
149
+ export const initialPasswordAad = (accountId) => `capybara:initial-password:${accountId}`;
150
+ const MASTER_KEYED = [
151
+ {
152
+ table: "org_data_keys",
153
+ idColumn: "org_id",
154
+ dataColumn: "wrapped_key",
155
+ aad: dekAad,
156
+ hasExpiresAt: false,
157
+ },
158
+ {
159
+ table: "account_initial_passwords",
160
+ idColumn: "account_id",
161
+ dataColumn: "ciphertext",
162
+ aad: initialPasswordAad,
163
+ hasExpiresAt: true,
164
+ },
165
+ ];
166
+ function staleRows(db, t, keyring) {
167
+ let q = db
168
+ .withSchema("capybara")
169
+ .selectFrom(t.table)
170
+ .where("master_key_id", "!=", keyring.currentId);
171
+ if (t.hasExpiresAt)
172
+ q = q.where("expires_at", ">", sql `now()`);
173
+ return q;
174
+ }
175
+ function assertKnown(t, keyring, rows) {
176
+ const unknown = rows.filter((r) => !keyring.has(r.mk));
177
+ if (unknown.length === 0)
178
+ return;
179
+ const shown = unknown.slice(0, 20).map((r) => `${r.id}(master_key_id=${r.mk})`);
180
+ throw new Error(`secrets: master key not in keyring for ${t.table}.${t.idColumn}: ${shown.join(", ")}`);
181
+ }
145
182
  /**
146
- * 把非当前主密钥包装的数据密钥改用当前主密钥重新包装,返回处理条数。One transaction over the given
147
- * handles (`KernelDb` + its `TransactionHost`, as `DatabaseModule` provides them).
183
+ * Rewraps everything sealed with a master key other than the keyring's current one (org data keys
184
+ * and unexpired initial passwords) with the current key, `batchSize` rows per transaction, until
185
+ * none is left. Checks first that the keyring holds every master key in use and throws (naming row
186
+ * ids and key ids, never key material) before writing anything when it does not. Idempotent: a
187
+ * second run finds nothing; concurrent runs lock the same rows and skip the ones already done.
148
188
  */
149
- export async function rewrapDataKeys(handles, keyring) {
150
- return handles.txHost.run(async () => {
151
- const trx = handles.db.db;
152
- const rows = await trx
153
- .withSchema("capybara")
154
- .selectFrom("org_data_keys")
155
- .select(["org_id", "wrapped_key", "master_key_id"])
156
- .where("master_key_id", "!=", keyring.currentId)
157
- .orderBy("org_id")
158
- .forUpdate()
189
+ export async function rewrapToCurrentMasterKey(handles, keyring, opts = {}) {
190
+ const batchSize = opts.batchSize ?? REWRAP_BATCH_SIZE;
191
+ if (!Number.isInteger(batchSize) || batchSize < 1) {
192
+ throw new RangeError("rewrap batch size must be a positive integer");
193
+ }
194
+ const db = () => handles.db.db;
195
+ for (const t of MASTER_KEYED) {
196
+ const rows = await staleRows(db(), t, keyring)
197
+ .select([`${t.idColumn} as id`, "master_key_id as mk"])
198
+ .orderBy(t.idColumn)
159
199
  .execute();
160
- const unknown = rows.filter((r) => !keyring.has(r.master_key_id));
161
- if (unknown.length > 0) {
162
- const shown = unknown
163
- .slice(0, 20)
164
- .map((r) => `${r.org_id}(master_key_id=${r.master_key_id})`);
165
- throw new Error(`secrets: master key not in keyring for org_id: ${shown.join(", ")}`);
166
- }
167
- for (const r of rows) {
168
- const dek = keyring.unwrap(r.master_key_id, Buffer.from(r.wrapped_key), dekAad(r.org_id));
169
- const w = keyring.wrap(dek, dekAad(r.org_id));
170
- await trx
171
- .withSchema("capybara")
172
- .updateTable("org_data_keys")
173
- .set({ wrapped_key: w.data, master_key_id: w.masterKeyId })
174
- .where("org_id", "=", r.org_id)
175
- .execute();
200
+ assertKnown(t, keyring, rows);
201
+ }
202
+ const counts = new Map();
203
+ for (const t of MASTER_KEYED) {
204
+ let total = 0;
205
+ for (;;) {
206
+ const done = await handles.txHost.run(async () => {
207
+ const trx = db();
208
+ const rows = await staleRows(trx, t, keyring)
209
+ .select([`${t.idColumn} as id`, "master_key_id as mk", `${t.dataColumn} as data`])
210
+ .orderBy(t.idColumn)
211
+ .limit(batchSize)
212
+ .forUpdate()
213
+ .execute();
214
+ // a row written meanwhile by a replica that runs an older config
215
+ assertKnown(t, keyring, rows);
216
+ for (const r of rows) {
217
+ let plain;
218
+ try {
219
+ plain = keyring.unwrap(r.mk, Buffer.from(r.data), t.aad(r.id));
220
+ }
221
+ catch (e) {
222
+ const why = e instanceof Error ? e.message : String(e);
223
+ throw new Error(`secrets: cannot unwrap ${t.table}.${t.idColumn}=${r.id}: ${why}`);
224
+ }
225
+ const w = keyring.wrap(plain, t.aad(r.id));
226
+ plain.fill(0);
227
+ await trx
228
+ .withSchema("capybara")
229
+ .updateTable(t.table)
230
+ .set({ [t.dataColumn]: w.data, master_key_id: w.masterKeyId })
231
+ .where(t.idColumn, "=", r.id)
232
+ .execute();
233
+ }
234
+ return rows.length;
235
+ });
236
+ total += done;
237
+ if (done === 0)
238
+ break;
176
239
  }
177
- return rows.length;
178
- });
240
+ counts.set(t.table, total);
241
+ }
242
+ return {
243
+ dataKeys: counts.get("org_data_keys") ?? 0,
244
+ initialPasswords: counts.get("account_initial_passwords") ?? 0,
245
+ };
179
246
  }
@@ -156,6 +156,15 @@ export interface OrgToolSwitchesTable {
156
156
  updated_by: string | null;
157
157
  updated_at: Ts;
158
158
  }
159
+ /** 0145: an internal endpoint a super admin lets the org's extension requests reach. */
160
+ export interface OrgNetworkAllowancesTable {
161
+ id: string;
162
+ org_id: string;
163
+ /** A hostname, `*.domain`, IP, CIDR or origin `http(s)://host[:port]`, normalized. */
164
+ entry: string;
165
+ created_by: string | null;
166
+ created_at: Ts;
167
+ }
159
168
  export interface AuditEventsTable {
160
169
  id: Generated<string>;
161
170
  at: Ts;
@@ -1294,8 +1303,16 @@ export interface ScheduledTaskGrantsTable {
1294
1303
  connector_id: string | null;
1295
1304
  created_at: Ts;
1296
1305
  }
1306
+ /** 0001: the per-org data key, wrapped by the master key (ctx/secrets.ts reads it untyped). */
1307
+ export interface OrgDataKeysTable {
1308
+ org_id: string;
1309
+ wrapped_key: Buffer;
1310
+ master_key_id: string;
1311
+ created_at: Ts;
1312
+ }
1297
1313
  export interface KernelDatabase {
1298
1314
  accounts: AccountsTable;
1315
+ org_data_keys: OrgDataKeysTable;
1299
1316
  account_initial_passwords: AccountInitialPasswordsTable;
1300
1317
  identities: IdentitiesTable;
1301
1318
  local_passwords: LocalPasswordsTable;
@@ -1308,6 +1325,7 @@ export interface KernelDatabase {
1308
1325
  extension_org_configs: ExtensionOrgConfigsTable;
1309
1326
  extension_org_overrides: ExtensionOrgOverridesTable;
1310
1327
  org_tool_switches: OrgToolSwitchesTable;
1328
+ org_network_allowances: OrgNetworkAllowancesTable;
1311
1329
  audit_events: AuditEventsTable;
1312
1330
  secrets: SecretsTable;
1313
1331
  agents: AgentsTable;
@@ -1531,7 +1549,7 @@ export interface CatalogItemsTable {
1531
1549
  builtin: ColumnType<boolean, boolean | undefined, boolean>;
1532
1550
  /** 0075: switched off for every org by the super admin. */
1533
1551
  disabled: ColumnType<boolean, boolean | undefined, boolean>;
1534
- /** 0075: bumped on every scope change. */
1552
+ /** 0075: unused since design review 2026-11-16; dropped by a later contract migration. */
1535
1553
  scope_version: ColumnType<number, number | undefined, number>;
1536
1554
  /** 0077: orgs outside a `named` item's list see it as requestable (never usable). */
1537
1555
  shown_to_others: ColumnType<boolean, boolean | undefined, boolean>;
@@ -1572,6 +1590,7 @@ interface PlatformScopeColumns {
1572
1590
  scope: Dflt<ComponentScope>;
1573
1591
  disabled: Dflt<boolean>;
1574
1592
  shown_to_others: Dflt<boolean>;
1593
+ /** Unused since design review 2026-11-16; dropped by a later contract migration. */
1575
1594
  scope_version: Dflt<number>;
1576
1595
  }
1577
1596
  /** 0081: a skill owned by the deployment (ruling A2). */
@@ -1894,20 +1913,22 @@ export interface CatalogOrgGrantsTable {
1894
1913
  granted_by: string | null;
1895
1914
  granted_at: Generated<Date>;
1896
1915
  }
1897
- /** 0037:应用在组织里的安装。 */
1916
+ /** 0049 / 0138: the states of a plugin install (`LIVE_INSTALL_STATUSES` are the live ones). */
1917
+ export type PluginInstallStatus = "installing" | "installed" | "failed" | "uninstalling";
1918
+ /** 0037: a plugin's install in an org. */
1898
1919
  export interface PluginInstallsTable {
1899
1920
  id: string;
1900
1921
  org_id: string;
1901
1922
  item_id: string;
1902
1923
  version: string;
1903
- /** 0049: `upgrading` while an in-place upgrade runs. */
1904
- status: "installing" | "installed" | "failed" | "uninstalling" | "upgrading";
1924
+ /** 0138 dropped 0049's `upgrading` (no per-org upgrade since ruling F2). */
1925
+ status: PluginInstallStatus;
1905
1926
  installed_by: string | null;
1906
1927
  installed_at: Generated<Date>;
1907
1928
  error: ColumnType<unknown, string | null | undefined, string | null>;
1908
1929
  /**
1909
- * 0049: the journal of the running upgrade, `{ id, from, to, startedAt, done }` with `done` the
1910
- * `UpgradeStep`s of catalog/plugin-install.ts (read by `journalEntries`); null otherwise.
1930
+ * 0049: the journal of a per-org upgrade. Unused since 0138 (no code reads or writes it, every
1931
+ * row null); kept for the replicas of the previous release, dropped by a later migration.
1911
1932
  */
1912
1933
  upgrade: ColumnType<unknown, string | null | undefined, string | null>;
1913
1934
  }
@@ -15,7 +15,7 @@ import { ExtensionDisplayNames } from "../extensions/display-name.js";
15
15
  import { audit } from "../identity/audit.js";
16
16
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
17
17
  import { KernelDb } from "../infra/database/kernel-db.js";
18
- import { TransactionHost } from "../infra/database/transaction-host.js";
18
+ import { assertNotSharedAdmission, TransactionHost } from "../infra/database/transaction-host.js";
19
19
  import { Transactional } from "../infra/database/transactional.decorator.js";
20
20
  import { LockService } from "../infra/lock/lock.service.js";
21
21
  import { OutboxService } from "../infra/outbox/outbox.service.js";
@@ -896,6 +896,7 @@ let DevicesService = class DevicesService {
896
896
  * member (any more) → `org.not_found`, as the org guard answers.
897
897
  */
898
898
  async lockMember(orgId, accountId, mode = "update") {
899
+ assertNotSharedAdmission("locking a membership");
899
900
  const org = await this.db
900
901
  .selectFrom("orgs")
901
902
  .select("id")
package/dist/errors.d.ts CHANGED
@@ -37,6 +37,11 @@ export declare const ERROR_CODES: {
37
37
  readonly "org.sandbox_egress_not_allowed": 400;
38
38
  /** The org asked for auto mode where the platform turned it off, or widened it through a token. */
39
39
  readonly "org.auto_mode_not_allowed": 400;
40
+ /** An org network allowance entry that is malformed, names a link-local address, or is over the cap. */
41
+ readonly "org.network_allowance_invalid": 400;
42
+ readonly "org.network_allowance_not_found": 404;
43
+ /** Adding an org network allowance through an API token or the Platform tool (a person widens). */
44
+ readonly "org.network_allowance_widen_not_allowed": 400;
40
45
  /** A deployment setting set in the startup config (file, Nacos or env): read-only in the admin console. */
41
46
  readonly "deployment.setting_readonly": 409;
42
47
  /** Turning the platform's auto mode on through an API token or the Platform tool (only off). */
@@ -61,7 +66,6 @@ export declare const ERROR_CODES: {
61
66
  readonly "extension.has_dependents": 409;
62
67
  readonly "extension.not_enabled": 409;
63
68
  readonly "extension.package_invalid": 400;
64
- readonly "extension.legacy_format": 422;
65
69
  readonly "extension.no_extension": 400;
66
70
  readonly "extension.package_too_large": 413;
67
71
  readonly "extension.config_declared": 409;
@@ -89,7 +93,6 @@ export declare const ERROR_CODES: {
89
93
  readonly "bootstrap.download_failed": 502;
90
94
  readonly "bootstrap.missing_file": 500;
91
95
  readonly "catalog.invalid_manifest": 422;
92
- readonly "catalog.legacy_format": 422;
93
96
  readonly "catalog.no_extension": 409;
94
97
  readonly "catalog.dependency_unresolved": 409;
95
98
  readonly "catalog.dependency_disabled": 409;
@@ -303,6 +306,11 @@ export declare const ERROR_CODES: {
303
306
  readonly "connector.resources_disabled": 409;
304
307
  /** Per-member tool policies on a connector with one org credential (decision 2026-11-09). */
305
308
  readonly "connector.not_personal": 409;
309
+ /**
310
+ * Loosening a connector's default git push policy through the Platform tool or an API token:
311
+ * only a person in a session widens it.
312
+ */
313
+ readonly "connector.git_push_widen_not_allowed": 400;
306
314
  readonly "approval.not_found": 404;
307
315
  readonly "approval.already_decided": 409;
308
316
  readonly "approval.scope_not_allowed": 409;
package/dist/errors.js CHANGED
@@ -37,6 +37,11 @@ export const ERROR_CODES = {
37
37
  "org.sandbox_egress_not_allowed": 400,
38
38
  /** The org asked for auto mode where the platform turned it off, or widened it through a token. */
39
39
  "org.auto_mode_not_allowed": 400,
40
+ /** An org network allowance entry that is malformed, names a link-local address, or is over the cap. */
41
+ "org.network_allowance_invalid": 400,
42
+ "org.network_allowance_not_found": 404,
43
+ /** Adding an org network allowance through an API token or the Platform tool (a person widens). */
44
+ "org.network_allowance_widen_not_allowed": 400,
40
45
  /** A deployment setting set in the startup config (file, Nacos or env): read-only in the admin console. */
41
46
  "deployment.setting_readonly": 409,
42
47
  /** Turning the platform's auto mode on through an API token or the Platform tool (only off). */
@@ -61,7 +66,6 @@ export const ERROR_CODES = {
61
66
  "extension.has_dependents": 409,
62
67
  "extension.not_enabled": 409,
63
68
  "extension.package_invalid": 400,
64
- "extension.legacy_format": 422,
65
69
  "extension.no_extension": 400,
66
70
  "extension.package_too_large": 413,
67
71
  "extension.config_declared": 409,
@@ -89,7 +93,6 @@ export const ERROR_CODES = {
89
93
  "bootstrap.download_failed": 502,
90
94
  "bootstrap.missing_file": 500,
91
95
  "catalog.invalid_manifest": 422,
92
- "catalog.legacy_format": 422,
93
96
  "catalog.no_extension": 409,
94
97
  "catalog.dependency_unresolved": 409,
95
98
  "catalog.dependency_disabled": 409,
@@ -303,6 +306,11 @@ export const ERROR_CODES = {
303
306
  "connector.resources_disabled": 409,
304
307
  /** Per-member tool policies on a connector with one org credential (decision 2026-11-09). */
305
308
  "connector.not_personal": 409,
309
+ /**
310
+ * Loosening a connector's default git push policy through the Platform tool or an API token:
311
+ * only a person in a session widens it.
312
+ */
313
+ "connector.git_push_widen_not_allowed": 400,
306
314
  "approval.not_found": 404,
307
315
  "approval.already_decided": 409,
308
316
  "approval.scope_not_allowed": 409,
@@ -13,17 +13,10 @@ import { type CaseSnapshot } from "./snapshot.js";
13
13
  * - `system_hash` / `tools_changed`(只在基线判定):system 指纹、工具序列(tools 与 catalog)与记录不同;
14
14
  * - `tool_spec_missing`:快照里缺某个工具定义(从请求里去掉);
15
15
  * - `definition_missing`:快照里缺该 agent 版本的定义(用空指令);
16
- * - `pinned_changed` (phase B, never for a baseline, not with `definition_missing`): the
17
- * `skills_catalog` snapshot in effect at the call pinned skills (`pinned` non-empty). No candidate
18
- * can pin any more (skills default-on spec §9), so any candidate differs from such a call; the
19
- * request still renders the recorded pinned bodies (Decision 1);
20
16
  * - `subagent_changed` (phase C, never for a baseline): a sub-agent's (child) case with a candidate
21
17
  * whose effective definition differs from the one frozen in its `subagent_started` (see
22
18
  * {@link subagentChanged}); the request still renders the logged definition and preamble. A child
23
- * case never consults `definitions` (no `definition_missing`) and has no `pinned_changed` (a
24
- * logged child definition that pinned counts as `subagent_changed`);
25
- * - `legacy_event`:记录缺 `tools` / `params` / `absorbedUpToSeq` / `maxOutputTokens`,或还原出媒体而记录里没有
26
- * `media` / `mediaBudgetBytes`(较早的事件);
19
+ * case never consults `definitions` (no `definition_missing`);
27
20
  * - `params_changed`:没给候选参数时,记录的参数按所用模型的声明清洗后有键被丢弃或值变了(换了模型或模型声明变了);
28
21
  * - `media_missing`:某附件记录里不是「不再可用」,还原时却取不到;
29
22
  * - `media_changed`(只在基线判定):其余任何媒体结果与记录不同(按附件 id 比 outcome 与 etag:预算省略、
@@ -34,13 +27,8 @@ import { type CaseSnapshot } from "./snapshot.js";
34
27
  */
35
28
  /** 还原结果与原请求不一致的原因。 */
36
29
  export type DriftReason = "system_hash" | "tools_changed" | "tool_spec_missing" | "definition_missing"
37
- /**
38
- * The call rendered pinned skills (phase B), which no candidate has any more (skills default-on
39
- * spec §9).
40
- */
41
- | "pinned_changed"
42
30
  /** A child case's candidate has another effective definition than the logged one (phase C). */
43
- | "subagent_changed" | "legacy_event" | "params_changed"
31
+ | "subagent_changed" | "params_changed"
44
32
  /**
45
33
  * UI refresh B: a non-baseline reconstruction whose run used a person's mid-conversation model
46
34
  * switch (`model_switched`) and whose candidate model (`modelRef`) replaces it.
@@ -66,7 +54,7 @@ export interface ReconstructOptions {
66
54
  /** 附件行信息与字节(调用方按 {@link snapshotMediaRefs} 取);缺省表示都取不到。 */
67
55
  mediaInfo?: ReadonlyMap<string, MediaInfo>;
68
56
  media?: ReadonlyMap<string, MediaBytes | null>;
69
- /** 单次请求的媒体字节预算;缺省用记录的 `mediaBudgetBytes`(较早的事件没有时不限)。 */
57
+ /** The request's media byte budget; defaults to the recorded `mediaBudgetBytes` (recorded only when the request had media). */
70
58
  mediaBudgetBytes?: number;
71
59
  /** The candidate's model (a non-baseline reconstruction): checked against the run's switch. */
72
60
  modelRef?: ModelRef;
@@ -116,8 +104,7 @@ export interface SubagentTemplateRef {
116
104
  * Does a candidate change what a sub-agent (child) case would run (`subagent_changed`, spec
117
105
  * §15.1)? Pure, from the snapshot alone, comparing the model-visible parts of the effective
118
106
  * definition (instructions, turned-off skills, tools) with the logged one (`logged`, from its
119
- * `subagent_started`). A logged definition that pinned skills (`started.definition`, read raw)
120
- * differs from every candidate: none pins any more (skills default-on spec §9).
107
+ * `subagent_started`).
121
108
  * - the same agent version (`sameVersion`): the candidate is the logged definition with
122
109
  * overrides (instructions, model, params), compared field by field;
123
110
  * - another version of the case's agent: for an org agent child (`source: "agent"`) that agent's