@capybara-hq/kernel 0.1.0-rc.105 → 0.1.0-rc.107

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 (359) hide show
  1. package/dist/admin/admin.schemas.d.ts +3 -0
  2. package/dist/agents/agents.schemas.d.ts +9 -9
  3. package/dist/{schedules/schedules.controller.d.ts → automations/automations.controller.d.ts} +37 -32
  4. package/dist/{schedules/schedules.controller.js → automations/automations.controller.js} +68 -57
  5. package/dist/automations/automations.module.d.ts +16 -0
  6. package/dist/{schedules/schedules.module.js → automations/automations.module.js} +18 -15
  7. package/dist/{schedules/schedules.schemas.d.ts → automations/automations.schemas.d.ts} +151 -50
  8. package/dist/automations/automations.schemas.js +253 -0
  9. package/dist/{schedules/scheduled-tasks.service.d.ts → automations/automations.service.d.ts} +99 -52
  10. package/dist/{schedules/scheduled-tasks.service.js → automations/automations.service.js} +303 -134
  11. package/dist/{schedules → automations}/calendar.d.ts +8 -8
  12. package/dist/{schedules → automations}/calendar.js +2 -2
  13. package/dist/automations/effective-settings.d.ts +28 -0
  14. package/dist/automations/effective-settings.js +25 -0
  15. package/dist/automations/errors.d.ts +19 -0
  16. package/dist/automations/errors.js +19 -0
  17. package/dist/automations/events/coalesce.d.ts +28 -0
  18. package/dist/automations/events/coalesce.js +131 -0
  19. package/dist/automations/events/deadline.d.ts +10 -0
  20. package/dist/automations/events/deadline.js +24 -0
  21. package/dist/automations/events/dispatcher.d.ts +74 -0
  22. package/dist/automations/events/dispatcher.js +353 -0
  23. package/dist/automations/events/events.module.d.ts +7 -0
  24. package/dist/automations/events/events.module.js +26 -0
  25. package/dist/automations/events/guards.d.ts +32 -0
  26. package/dist/automations/events/guards.js +87 -0
  27. package/dist/automations/events/sweep.job.d.ts +49 -0
  28. package/dist/automations/events/sweep.job.js +202 -0
  29. package/dist/automations/events/token.d.ts +5 -0
  30. package/dist/automations/events/token.js +5 -0
  31. package/dist/automations/events/trigger-events.service.d.ts +47 -0
  32. package/dist/automations/events/trigger-events.service.js +254 -0
  33. package/dist/{schedules → automations}/fire.d.ts +57 -17
  34. package/dist/{schedules → automations}/fire.js +311 -79
  35. package/dist/{schedules → automations}/grant-rules.d.ts +1 -1
  36. package/dist/{schedules → automations}/grant-rules.js +5 -5
  37. package/dist/automations/job-ids.d.ts +113 -0
  38. package/dist/automations/job-ids.js +117 -0
  39. package/dist/{schedules → automations}/pause.d.ts +3 -3
  40. package/dist/{schedules → automations}/pause.js +3 -3
  41. package/dist/{schedules → automations}/run-tracker.d.ts +21 -10
  42. package/dist/{schedules → automations}/run-tracker.js +68 -56
  43. package/dist/{schedules → automations}/scan.job.d.ts +12 -8
  44. package/dist/{schedules → automations}/scan.job.js +39 -23
  45. package/dist/{schedules → automations}/schedule-math.d.ts +19 -12
  46. package/dist/{schedules → automations}/schedule-math.js +17 -7
  47. package/dist/{schedules → automations}/store.d.ts +57 -27
  48. package/dist/{schedules → automations}/store.js +102 -52
  49. package/dist/automations/store.module.d.ts +6 -0
  50. package/dist/{schedules → automations}/store.module.js +9 -9
  51. package/dist/automations/types.d.ts +178 -0
  52. package/dist/{schedules → automations}/unattended.d.ts +22 -11
  53. package/dist/{schedules → automations}/unattended.js +53 -30
  54. package/dist/catalog/marketplaces.service.d.ts +1 -1
  55. package/dist/channels/channels.module.js +7 -6
  56. package/dist/channels/file-delivery.d.ts +26 -11
  57. package/dist/channels/file-delivery.js +32 -11
  58. package/dist/channels/outbound.d.ts +8 -8
  59. package/dist/channels/outbound.js +32 -30
  60. package/dist/channels/threads.d.ts +1 -1
  61. package/dist/channels/threads.js +1 -1
  62. package/dist/config/schema.d.ts +8 -1
  63. package/dist/config/schema.js +56 -6
  64. package/dist/conversations/approval-profile.d.ts +2 -2
  65. package/dist/conversations/approval-profile.js +3 -3
  66. package/dist/conversations/artifacts.d.ts +20 -17
  67. package/dist/conversations/artifacts.js +30 -37
  68. package/dist/conversations/attachments.controller.d.ts +6 -19
  69. package/dist/conversations/attachments.controller.js +8 -59
  70. package/dist/conversations/attachments.service.d.ts +30 -74
  71. package/dist/conversations/attachments.service.js +51 -193
  72. package/dist/conversations/conversations.controller.d.ts +7 -1
  73. package/dist/conversations/conversations.controller.js +26 -10
  74. package/dist/conversations/conversations.module.js +4 -0
  75. package/dist/conversations/conversations.service.d.ts +112 -35
  76. package/dist/conversations/conversations.service.js +160 -43
  77. package/dist/conversations/event-log.d.ts +1 -0
  78. package/dist/conversations/events.d.ts +95 -27
  79. package/dist/conversations/events.js +108 -10
  80. package/dist/conversations/files.d.ts +66 -64
  81. package/dist/conversations/files.js +127 -147
  82. package/dist/conversations/message-context.d.ts +2 -2
  83. package/dist/conversations/message-context.js +1 -1
  84. package/dist/conversations/permission-profile-store.d.ts +2 -1
  85. package/dist/conversations/permission-profiles.controller.d.ts +3 -0
  86. package/dist/conversations/permission-profiles.service.js +1 -1
  87. package/dist/conversations/prompt-suggestion-request.d.ts +1 -1
  88. package/dist/conversations/prompt-suggestion-request.js +4 -2
  89. package/dist/conversations/prompt-suggestions.d.ts +3 -3
  90. package/dist/conversations/prompt-suggestions.js +11 -10
  91. package/dist/conversations/queue.d.ts +7 -4
  92. package/dist/conversations/queue.js +6 -2
  93. package/dist/conversations/queue.service.d.ts +5 -5
  94. package/dist/conversations/queue.service.js +27 -16
  95. package/dist/ctx/create-ctx.d.ts +23 -2
  96. package/dist/ctx/create-ctx.js +78 -3
  97. package/dist/db/kernel-schema.d.ts +184 -27
  98. package/dist/devices/device-project-files.service.d.ts +88 -0
  99. package/dist/devices/device-project-files.service.js +249 -0
  100. package/dist/devices/device-projects.service.d.ts +40 -0
  101. package/dist/devices/device-projects.service.js +16 -13
  102. package/dist/devices/devices.controller.d.ts +9 -3
  103. package/dist/devices/devices.controller.js +27 -5
  104. package/dist/devices/devices.module.js +9 -1
  105. package/dist/devices/devices.schemas.js +6 -1
  106. package/dist/devices/dto.d.ts +15 -0
  107. package/dist/devices/dto.js +11 -0
  108. package/dist/devices/project-paths.d.ts +29 -0
  109. package/dist/devices/project-paths.js +66 -0
  110. package/dist/devices/project-rules.d.ts +5 -1
  111. package/dist/devices/project-rules.js +5 -1
  112. package/dist/errors.d.ts +53 -13
  113. package/dist/errors.js +53 -13
  114. package/dist/evals/canonical-json.d.ts +7 -0
  115. package/dist/evals/canonical-json.js +21 -0
  116. package/dist/evals/reconstruct.d.ts +10 -1
  117. package/dist/evals/reconstruct.js +20 -1
  118. package/dist/evals/recorded-tools.d.ts +0 -2
  119. package/dist/evals/recorded-tools.js +1 -16
  120. package/dist/evals/snapshot.d.ts +26 -3
  121. package/dist/evals/snapshot.js +110 -57
  122. package/dist/evals/worker.d.ts +4 -3
  123. package/dist/evals/worker.js +8 -4
  124. package/dist/extensions/host.d.ts +9 -2
  125. package/dist/extensions/host.js +12 -0
  126. package/dist/extensions/instance.d.ts +3 -1
  127. package/dist/extensions/instance.js +4 -0
  128. package/dist/extensions/ledger.d.ts +1 -1
  129. package/dist/extensions/permission-set.d.ts +17 -1
  130. package/dist/extensions/permission-set.js +13 -1
  131. package/dist/extensions/permission-view.d.ts +1 -1
  132. package/dist/extensions/permission-view.js +4 -1
  133. package/dist/files/blob-objects.d.ts +124 -0
  134. package/dist/files/blob-objects.js +341 -0
  135. package/dist/files/blob-sweep.job.d.ts +122 -0
  136. package/dist/files/blob-sweep.job.js +389 -0
  137. package/dist/files/blobs.service.d.ts +135 -0
  138. package/dist/files/blobs.service.js +300 -0
  139. package/dist/files/conversation-media.d.ts +41 -0
  140. package/dist/files/conversation-media.js +124 -0
  141. package/dist/files/deliveries.d.ts +64 -0
  142. package/dist/files/deliveries.js +156 -0
  143. package/dist/files/deliveries.module.d.ts +6 -0
  144. package/dist/files/deliveries.module.js +24 -0
  145. package/dist/files/draft-cleanup.job.d.ts +26 -0
  146. package/dist/files/draft-cleanup.job.js +93 -0
  147. package/dist/files/files.module.d.ts +1 -1
  148. package/dist/files/files.module.js +3 -2
  149. package/dist/files/hash-job.d.ts +127 -0
  150. package/dist/files/hash-job.js +447 -0
  151. package/dist/files/library-backfill.d.ts +63 -0
  152. package/dist/files/library-backfill.js +143 -0
  153. package/dist/files/library-files.service.d.ts +255 -0
  154. package/dist/files/library-files.service.js +883 -0
  155. package/dist/files/library-jobs.module.d.ts +8 -0
  156. package/dist/files/library-jobs.module.js +27 -0
  157. package/dist/files/library-query.d.ts +127 -0
  158. package/dist/files/library-query.js +322 -0
  159. package/dist/files/library-read.module.d.ts +9 -0
  160. package/dist/files/library-read.module.js +30 -0
  161. package/dist/files/library.controller.d.ts +77 -0
  162. package/dist/files/library.controller.js +235 -0
  163. package/dist/files/library.module.d.ts +9 -0
  164. package/dist/files/library.module.js +29 -0
  165. package/dist/files/library.schemas.d.ts +46 -0
  166. package/dist/files/library.schemas.js +49 -0
  167. package/dist/files/previewers.controller.d.ts +20 -0
  168. package/dist/files/previewers.controller.js +47 -0
  169. package/dist/files/previewers.d.ts +25 -11
  170. package/dist/files/previewers.js +43 -27
  171. package/dist/files/referenced-files.d.ts +150 -0
  172. package/dist/files/referenced-files.js +234 -0
  173. package/dist/git/gateway.js +2 -2
  174. package/dist/html/html-document.controller.d.ts +8 -1
  175. package/dist/html/html-document.controller.js +19 -1
  176. package/dist/html/html-document.service.d.ts +19 -4
  177. package/dist/html/html-document.service.js +43 -22
  178. package/dist/html/html-token.d.ts +10 -1
  179. package/dist/html/html-token.js +14 -0
  180. package/dist/html/html.module.js +8 -1
  181. package/dist/http/api.module.js +10 -5
  182. package/dist/http/request-signal.d.ts +8 -0
  183. package/dist/http/request-signal.js +14 -0
  184. package/dist/identity/settings.d.ts +26 -0
  185. package/dist/identity/settings.js +33 -2
  186. package/dist/inbox/inbox.module.js +2 -2
  187. package/dist/inbox/inbox.service.d.ts +8 -8
  188. package/dist/inbox/inbox.service.js +7 -7
  189. package/dist/infra/config/kernel-config.service.js +10 -5
  190. package/dist/infra/outbox/registry.d.ts +111 -2
  191. package/dist/infra/outbox/registry.js +104 -9
  192. package/dist/infra/throttler/named-throttlers.d.ts +2 -0
  193. package/dist/infra/throttler/named-throttlers.js +14 -0
  194. package/dist/kernel.module.js +3 -0
  195. package/dist/lifecycle/kernel-lifecycle.js +6 -0
  196. package/dist/models/purposes.js +1 -1
  197. package/dist/orgs/offboarding.js +1 -1
  198. package/dist/orgs/roles.d.ts +1 -1
  199. package/dist/orgs/roles.js +3 -3
  200. package/dist/orgs/settings.controller.d.ts +1 -1
  201. package/dist/orgs/settings.service.d.ts +75 -13
  202. package/dist/orgs/settings.service.js +104 -26
  203. package/dist/platform/exclusions.js +45 -8
  204. package/dist/platform/file-ref.d.ts +18 -3
  205. package/dist/platform/file-ref.js +22 -11
  206. package/dist/platform/operation.js +6 -2
  207. package/dist/platform/ops/admin.ops.js +5 -2
  208. package/dist/platform/ops/{schedules.ops.d.ts → automations.ops.d.ts} +4 -4
  209. package/dist/platform/ops/automations.ops.js +560 -0
  210. package/dist/platform/ops/devices.ops.d.ts +3 -1
  211. package/dist/platform/ops/devices.ops.js +77 -3
  212. package/dist/platform/ops/files.ops.d.ts +18 -0
  213. package/dist/platform/ops/files.ops.js +267 -0
  214. package/dist/platform/ops/inbox.ops.js +4 -4
  215. package/dist/platform/ops/org-settings.ops.js +6 -2
  216. package/dist/platform/ops/orgs.ops.js +2 -1
  217. package/dist/platform/ops/platform.ops.js +4 -4
  218. package/dist/platform/ops/shares.ops.js +2 -2
  219. package/dist/platform/platform-ops.module.d.ts +3 -2
  220. package/dist/platform/platform-ops.module.js +10 -5
  221. package/dist/platform/route-schemas.js +6 -3
  222. package/dist/push/jobs.d.ts +3 -3
  223. package/dist/push/jobs.js +2 -2
  224. package/dist/push/preferences.service.js +1 -1
  225. package/dist/push/push-owed.d.ts +3 -3
  226. package/dist/push/push-owed.js +6 -6
  227. package/dist/push/push.schemas.d.ts +4 -4
  228. package/dist/push/push.schemas.js +3 -3
  229. package/dist/push/recipients.d.ts +4 -4
  230. package/dist/push/recipients.js +23 -23
  231. package/dist/push/texts.d.ts +3 -3
  232. package/dist/push/texts.js +2 -2
  233. package/dist/push/triggers.d.ts +1 -1
  234. package/dist/roles/worker.module.js +18 -4
  235. package/dist/runtime/compaction-settings.service.d.ts +13 -1
  236. package/dist/runtime/compaction-settings.service.js +16 -1
  237. package/dist/runtime/compaction.service.d.ts +3 -1
  238. package/dist/runtime/compaction.service.js +3 -1
  239. package/dist/runtime/context/build.d.ts +24 -1
  240. package/dist/runtime/context/build.js +33 -11
  241. package/dist/runtime/context/cache-expiry.d.ts +31 -0
  242. package/dist/runtime/context/cache-expiry.js +60 -0
  243. package/dist/runtime/context/cache-ttl.d.ts +18 -0
  244. package/dist/runtime/context/cache-ttl.js +30 -0
  245. package/dist/runtime/context/compaction.d.ts +9 -2
  246. package/dist/runtime/context/compaction.js +64 -21
  247. package/dist/runtime/context/in-context-compaction.d.ts +156 -0
  248. package/dist/runtime/context/in-context-compaction.js +310 -0
  249. package/dist/runtime/context/run-context.d.ts +38 -0
  250. package/dist/runtime/context/run-context.js +54 -0
  251. package/dist/runtime/hook-calls.d.ts +2 -1
  252. package/dist/runtime/hook-calls.js +5 -2
  253. package/dist/runtime/maintenance.d.ts +16 -4
  254. package/dist/runtime/maintenance.js +79 -18
  255. package/dist/runtime/model-call.d.ts +34 -5
  256. package/dist/runtime/model-call.js +207 -22
  257. package/dist/runtime/providers.js +11 -1
  258. package/dist/runtime/run-finish.d.ts +4 -4
  259. package/dist/runtime/run-finish.js +3 -3
  260. package/dist/runtime/run-queue.js +12 -7
  261. package/dist/runtime/run-steps.d.ts +4 -2
  262. package/dist/runtime/run-steps.js +10 -5
  263. package/dist/runtime/run-worker.js +7 -1
  264. package/dist/runtime/runtime.module.js +6 -3
  265. package/dist/runtime/subagents/dispatch.js +11 -3
  266. package/dist/sandbox/browse-roots.d.ts +8 -0
  267. package/dist/sandbox/browse-roots.js +22 -0
  268. package/dist/sandbox/network-grants.d.ts +4 -4
  269. package/dist/sandbox/network-grants.js +7 -7
  270. package/dist/sandbox/operation-authority.d.ts +10 -3
  271. package/dist/sandbox/operation-authority.js +20 -10
  272. package/dist/sandbox/operation-intents.d.ts +3 -1
  273. package/dist/sandbox/operation-intents.js +11 -4
  274. package/dist/sandbox/permission-call-grants.js +2 -2
  275. package/dist/sandbox/permission-facts.js +1 -1
  276. package/dist/sandbox/review/classifier.d.ts +2 -2
  277. package/dist/sandbox/review/classifier.js +22 -11
  278. package/dist/sandbox/review/permission-candidate.d.ts +1 -1
  279. package/dist/sandbox/review/permission-candidate.js +1 -1
  280. package/dist/sandbox/sandbox.service.d.ts +15 -5
  281. package/dist/sandbox/sandbox.service.js +14 -8
  282. package/dist/shares/liveness.d.ts +26 -12
  283. package/dist/shares/liveness.js +79 -20
  284. package/dist/shares/revoke.d.ts +16 -11
  285. package/dist/shares/revoke.js +18 -14
  286. package/dist/shares/share-objects.d.ts +16 -21
  287. package/dist/shares/share-objects.js +25 -55
  288. package/dist/shares/share-open.service.d.ts +8 -4
  289. package/dist/shares/share-open.service.js +14 -11
  290. package/dist/shares/shares.controller.d.ts +16 -5
  291. package/dist/shares/shares.controller.js +39 -5
  292. package/dist/shares/shares.module.d.ts +4 -4
  293. package/dist/shares/shares.module.js +7 -6
  294. package/dist/shares/shares.schemas.d.ts +4 -0
  295. package/dist/shares/shares.schemas.js +2 -0
  296. package/dist/shares/shares.service.d.ts +93 -54
  297. package/dist/shares/shares.service.js +292 -131
  298. package/dist/shares/sweep.job.d.ts +18 -39
  299. package/dist/shares/sweep.job.js +47 -206
  300. package/dist/storage/purge.d.ts +1 -1
  301. package/dist/storage/purge.js +2 -2
  302. package/dist/tools/approvals.service.d.ts +6 -6
  303. package/dist/tools/approvals.service.js +19 -19
  304. package/dist/tools/builtin-names.d.ts +12 -12
  305. package/dist/tools/builtin-names.js +29 -29
  306. package/dist/tools/builtins/artifacts.d.ts +21 -13
  307. package/dist/tools/builtins/artifacts.js +81 -51
  308. package/dist/tools/builtins/{schedules.d.ts → automations.d.ts} +35 -33
  309. package/dist/tools/builtins/{schedules.js → automations.js} +236 -105
  310. package/dist/tools/builtins/builtin-tools.d.ts +15 -9
  311. package/dist/tools/builtins/builtin-tools.js +33 -22
  312. package/dist/tools/builtins/conversation-files.d.ts +23 -13
  313. package/dist/tools/builtins/conversation-files.js +62 -83
  314. package/dist/tools/builtins/image/generate.d.ts +7 -1
  315. package/dist/tools/builtins/image/generate.js +1 -1
  316. package/dist/tools/builtins/platform.js +1 -0
  317. package/dist/tools/builtins/sandbox/common.d.ts +6 -2
  318. package/dist/tools/builtins/sandbox/deliver.js +6 -7
  319. package/dist/tools/builtins/sandbox/fetch-attachment.d.ts +6 -5
  320. package/dist/tools/builtins/sandbox/fetch-attachment.js +19 -12
  321. package/dist/tools/call-scope.d.ts +1 -1
  322. package/dist/tools/git-asks.js +1 -1
  323. package/dist/tools/git-push-policy.d.ts +3 -3
  324. package/dist/tools/git-push-policy.js +6 -6
  325. package/dist/tools/network-asks.d.ts +3 -3
  326. package/dist/tools/network-asks.js +3 -3
  327. package/dist/tools/pipeline.d.ts +4 -4
  328. package/dist/tools/pipeline.js +2 -2
  329. package/dist/tools/policy.d.ts +3 -3
  330. package/dist/tools/policy.js +3 -3
  331. package/dist/tools/tools.module.js +15 -9
  332. package/dist/ui/call-extension.d.ts +6 -4
  333. package/dist/ui/call-extension.js +5 -4
  334. package/dist/ui/embed-token.js +6 -3
  335. package/dist/ui/registry.d.ts +21 -5
  336. package/dist/ui/registry.js +24 -6
  337. package/dist/ui/ui.schemas.d.ts +22 -0
  338. package/dist/ui/ui.schemas.js +22 -4
  339. package/dist/ui/views.controller.d.ts +13 -3
  340. package/dist/ui/views.controller.js +33 -2
  341. package/dist/ui/views.d.ts +29 -1
  342. package/dist/ui/views.js +131 -7
  343. package/package.json +3 -3
  344. package/src/migrations/0188_automations_rename.sql +309 -0
  345. package/src/migrations/0189_event_automations.sql +136 -0
  346. package/src/migrations/0190_file_library.sql +285 -0
  347. package/src/migrations/0191_file_library_copy.sql +4 -0
  348. package/dist/platform/ops/schedules.ops.js +0 -509
  349. package/dist/schedules/effective-settings.d.ts +0 -22
  350. package/dist/schedules/effective-settings.js +0 -18
  351. package/dist/schedules/errors.d.ts +0 -8
  352. package/dist/schedules/errors.js +0 -8
  353. package/dist/schedules/job-ids.d.ts +0 -81
  354. package/dist/schedules/job-ids.js +0 -95
  355. package/dist/schedules/schedules.module.d.ts +0 -16
  356. package/dist/schedules/schedules.schemas.js +0 -213
  357. package/dist/schedules/store.module.d.ts +0 -6
  358. package/dist/schedules/types.d.ts +0 -110
  359. /package/dist/{schedules → automations}/types.js +0 -0
@@ -0,0 +1,66 @@
1
+ import { posix } from "node:path";
2
+ import { ApiError } from "../errors.js";
3
+ import { clipped } from "./project-rules.js";
4
+ /** The longest path relative to a project the kernel takes (the add route's bound). */
5
+ export const MAX_PROJECT_RELATIVE_PATH = 4096;
6
+ // biome-ignore lint/suspicious/noControlCharactersInRegex: control characters are what it refuses
7
+ const CONTROL = /[\u0000-\u001f\u007f]/;
8
+ /**
9
+ * A path relative to a device project (composer menus §5) that is refused: absolute, escaping the
10
+ * project root with `..`, holding a backslash or a control character, or too long. 422
11
+ * `device.path_outside_project` with the path (clipped) in `details`.
12
+ */
13
+ export const pathOutsideProject = (rel) => new ApiError("device.path_outside_project", "Give a path relative to the project root that stays inside it: no absolute path, no .. above the root, no backslashes or control characters", [{ path: clipped(rel) }]);
14
+ /**
15
+ * `rel` normalized as a posix path relative to a project's root: `""` for the root itself, no
16
+ * `.` segments, no doubled or trailing `/`, `..` resolved. Refused ({@link pathOutsideProject})
17
+ * when it is absolute, climbs above the root, holds a backslash or a control character (NUL
18
+ * included), or is longer than {@link MAX_PROJECT_RELATIVE_PATH}. Pure string work: the device
19
+ * is never asked, so a symlink below the root is the provider's and its browse scope's to judge.
20
+ */
21
+ export function projectRelativePath(rel) {
22
+ if (rel.length > MAX_PROJECT_RELATIVE_PATH ||
23
+ rel.startsWith("/") ||
24
+ rel.includes("\\") ||
25
+ CONTROL.test(rel)) {
26
+ throw pathOutsideProject(rel);
27
+ }
28
+ if (rel === "")
29
+ return "";
30
+ const n = posix.normalize(rel);
31
+ if (n === ".." || n.startsWith("../") || posix.isAbsolute(n))
32
+ throw pathOutsideProject(rel);
33
+ const trimmed = n.endsWith("/") ? n.slice(0, -1) : n;
34
+ return trimmed === "." ? "" : trimmed;
35
+ }
36
+ /**
37
+ * The absolute device path of `rel` (normalized through {@link projectRelativePath}, so refused
38
+ * the same way) inside the project rooted at `projectPath`, which must itself be absolute and
39
+ * normalized (no `.` / `..` segments, no doubled or trailing `/`): an internal error otherwise.
40
+ */
41
+ export function joinProjectPath(projectPath, rel) {
42
+ // the project path is the kernel's own (a stored project): one that is not absolute and
43
+ // normalized is a kernel bug, never the person's path
44
+ if (!posix.isAbsolute(projectPath) ||
45
+ posix.normalize(projectPath) !== projectPath ||
46
+ (projectPath !== "/" && projectPath.endsWith("/"))) {
47
+ throw new Error(`joinProjectPath: the project path ${JSON.stringify(clipped(projectPath))} is not absolute and normalized`);
48
+ }
49
+ const r = projectRelativePath(rel);
50
+ const root = projectPath;
51
+ if (r === "")
52
+ return root;
53
+ return root === "/" ? `/${r}` : `${root}/${r}`;
54
+ }
55
+ /**
56
+ * {@link projectRelativePath} for a path that must name a file below the root: one that
57
+ * normalizes to the root itself (`"."`, `"./"`, `"a/.."`) is refused with
58
+ * `device.path_outside_project` as well, its path in `details` as given (none when empty).
59
+ */
60
+ export function projectFilePath(rel) {
61
+ const r = projectRelativePath(rel);
62
+ if (r === "") {
63
+ throw new ApiError("device.path_outside_project", "The project root is not a file; give the path of a file inside the project", rel === "" ? undefined : [{ path: clipped(rel) }]);
64
+ }
65
+ return r;
66
+ }
@@ -24,7 +24,11 @@ export declare const projectNotFound: (name: string) => ApiError;
24
24
  * the resolved path is not one a device can hold.
25
25
  */
26
26
  export declare const outsideMode: (path: string) => ApiError;
27
- export declare const tooBroad: (path: string) => ApiError;
27
+ /**
28
+ * A project directory above the owner's home: named by the project (`name`, when there is one),
29
+ * never by its absolute path, which stays out of the message.
30
+ */
31
+ export declare const tooBroad: (name?: string) => ApiError;
28
32
  /** A device-supplied or person-supplied string inside a message, bounded. */
29
33
  export declare function clipped(s: string, max?: number): string;
30
34
  export {};
@@ -9,7 +9,11 @@ export const projectNotFound = (name) => new ApiError("device.project_not_found"
9
9
  * the resolved path is not one a device can hold.
10
10
  */
11
11
  export const outsideMode = (path) => new ApiError("device.project_outside_mode", `${clipped(path)} is outside what the device lets a project reach; pick a directory inside its base`);
12
- export const tooBroad = (path) => new ApiError("device.project_path_too_broad", `${clipped(path)} holds the owner's home directory (or other people's): pick the project's own directory, the home or below it`);
12
+ /**
13
+ * A project directory above the owner's home: named by the project (`name`, when there is one),
14
+ * never by its absolute path, which stays out of the message.
15
+ */
16
+ export const tooBroad = (name) => new ApiError("device.project_path_too_broad", `${name === undefined ? "This directory" : `The project "${clipped(name)}"`} holds the owner's home directory (or other people's): pick the project's own directory, the home or below it`);
13
17
  /** A device-supplied or person-supplied string inside a message, bounded. */
14
18
  export function clipped(s, max = 200) {
15
19
  return s.length <= max ? s : `${s.slice(0, max)}…`;
package/dist/errors.d.ts CHANGED
@@ -80,6 +80,8 @@ export declare const ERROR_CODES: {
80
80
  * the Platform tool (only a person turns it on).
81
81
  */
82
82
  readonly "org.external_sharing_not_allowed": 400;
83
+ /** An org's navigation setting puts more than 3 plugin pages in the primary navigation. */
84
+ readonly "org_settings.nav_primary_limit": 400;
83
85
  /** A deployment setting set in the startup config (file, Nacos or env): read-only in the admin console. */
84
86
  readonly "deployment.setting_readonly": 409;
85
87
  /** Allowing outside-sandbox runs platform-wide through an API token or the Platform tool (only off). */
@@ -381,6 +383,12 @@ export declare const ERROR_CODES: {
381
383
  readonly "conversation.queue_item_not_found": 404;
382
384
  /** A sub-agent's conversation takes no messages from people (sub-agents spec §6.1). */
383
385
  readonly "conversation.read_only": 409;
386
+ /**
387
+ * A referenced project file is not there to reference (composer menus §5): the conversation has
388
+ * no device project, the path leaves it, or the device reports no file there;
389
+ * `details: [{ path?, reason? }]`.
390
+ */
391
+ readonly "conversation.project_file_unavailable": 422;
384
392
  readonly "run.not_active": 409;
385
393
  /** A run that is not one of the conversation's (the live draft route, spec 2026-11-07 §3.2). */
386
394
  readonly "run.not_found": 404;
@@ -446,12 +454,29 @@ export declare const ERROR_CODES: {
446
454
  readonly "ui.action_failed": 502;
447
455
  readonly "ui.invalid_view": 502;
448
456
  readonly "ui.timeout": 504;
457
+ /** A component query's params are over `UI_LIMITS.componentQueryParamsBytes` as JSON. */
458
+ readonly "ui.query_params_too_large": 413;
459
+ /** A component query's result is over `UI_LIMITS.componentQueryBytes` as JSON, or not JSON. */
460
+ readonly "ui.query_result_too_large": 502;
461
+ /** A component query did not answer within 10 seconds (its signal aborted). */
462
+ readonly "ui.query_timeout": 504;
463
+ /** A component query handler threw. */
464
+ readonly "ui.query_failed": 502;
465
+ /** No query handler for that component, or the component is not offered to the caller. */
466
+ readonly "ui.query_not_found": 404;
449
467
  readonly "storage.unavailable": 503;
450
468
  readonly "attachment.not_found": 404;
451
469
  readonly "attachment.not_ready": 409;
452
470
  readonly "attachment.too_large": 413;
453
471
  readonly "attachment.type_not_allowed": 415;
454
472
  readonly "attachment.too_many_pending": 429;
473
+ readonly "file.not_found": 404;
474
+ readonly "file.not_ready": 409;
475
+ readonly "file.hash_mismatch": 422;
476
+ readonly "file.deleted": 410;
477
+ readonly "file.too_large": 413;
478
+ readonly "file.type_not_allowed": 415;
479
+ readonly "file.too_many_pending": 429;
455
480
  readonly "sandbox.unavailable": 503;
456
481
  readonly "sandbox.busy": 409;
457
482
  /** A cloud sandbox provider refused an instance with the open public network. */
@@ -549,6 +574,13 @@ export declare const ERROR_CODES: {
549
574
  readonly "device.project_path_unreadable": 422;
550
575
  /** The device provider refused the project's directory (its reason is the message and details). */
551
576
  readonly "device.project_refused": 422;
577
+ /**
578
+ * A path relative to a device project that leaves it (composer menus §5): absolute, `..` above
579
+ * the root, a backslash or a control character; `details: [{ path }]`.
580
+ */
581
+ readonly "device.path_outside_project": 422;
582
+ /** The device's provider cannot list its directories for its owner (no `list` / owner browse). */
583
+ readonly "device.list_unsupported": 409;
552
584
  /** Device sign-in (RFC 8628 style): the person has not approved the code yet; keep polling. */
553
585
  readonly "device_sign_in.authorization_pending": 400;
554
586
  /** Device sign-in: the program polls faster than the interval; add 5 seconds and keep polling. */
@@ -565,28 +597,36 @@ export declare const ERROR_CODES: {
565
597
  readonly "device.credential_invalid": 401;
566
598
  /** A device stream hop from another gateway replica without a valid MAC (or replayed). */
567
599
  readonly "device.stream_hop_refused": 401;
568
- /** The scheduled task is missing, deleted, in another org or not the caller's to see. */
569
- readonly "schedule.not_found": 404;
600
+ /** The automation is missing, deleted, in another org or not the caller's to see. */
601
+ readonly "automation.not_found": 404;
570
602
  /** Not a 5-field cron expression (no seconds field). */
571
- readonly "schedule.invalid_cron": 400;
603
+ readonly "automation.invalid_cron": 400;
572
604
  /** Not an IANA time zone. */
573
- readonly "schedule.invalid_time_zone": 400;
605
+ readonly "automation.invalid_time_zone": 400;
574
606
  /** A `once` time that is not a local date-time `YYYY-MM-DDTHH:mm[:ss]`. */
575
- readonly "schedule.invalid_once_time": 400;
607
+ readonly "automation.invalid_once_time": 400;
576
608
  /** A `once` time that is not in the future. */
577
- readonly "schedule.once_in_past": 400;
609
+ readonly "automation.once_in_past": 400;
578
610
  /** Two fire times closer than the org's `minIntervalMinutes`. */
579
- readonly "schedule.interval_too_short": 400;
611
+ readonly "automation.interval_too_short": 400;
580
612
  /** The creator or the org has as many active and paused tasks as the org allows. */
581
- readonly "schedule.limit_reached": 409;
582
- /** The org turned scheduled tasks off. */
583
- readonly "schedule.disabled": 409;
613
+ readonly "automation.limit_reached": 409;
614
+ /** The org turned automations off. */
615
+ readonly "automation.disabled": 409;
584
616
  /** Where the task runs is inconsistent or not the creator's to use (conversation, chat, device). */
585
- readonly "schedule.target_invalid": 400;
617
+ readonly "automation.target_invalid": 400;
586
618
  /** A tool the creator cannot pre-approve for the task (spec §7). */
587
- readonly "schedule.grant_not_allowed": 400;
619
+ readonly "automation.grant_not_allowed": 400;
620
+ /** An event trigger names a source that is not an enabled trigger source of the org. */
621
+ readonly "automation.event_source_unavailable": 400;
622
+ /** An event trigger names an event type its source does not declare (or a directed one). */
623
+ readonly "automation.event_type_unknown": 400;
624
+ /** An event trigger's filter names a missing or unfilterable fact, or mistypes a value. */
625
+ readonly "automation.filter_invalid": 400;
588
626
  /** An org admin may pause, resume and delete another person's task, never edit it. */
589
- readonly "schedule.forbidden": 403;
627
+ readonly "automation.forbidden": 403;
628
+ /** "Run now" and trial runs: an event automation runs only on its events (no run now, no trial). */
629
+ readonly "automation.run_now_unsupported": 409;
590
630
  readonly "skill.not_found": 404;
591
631
  /** The skill's file routes: no such version of the skill, or no such path in that version. */
592
632
  readonly "skill.file_not_found": 404;
package/dist/errors.js CHANGED
@@ -80,6 +80,8 @@ export const ERROR_CODES = {
80
80
  * the Platform tool (only a person turns it on).
81
81
  */
82
82
  "org.external_sharing_not_allowed": 400,
83
+ /** An org's navigation setting puts more than 3 plugin pages in the primary navigation. */
84
+ "org_settings.nav_primary_limit": 400,
83
85
  /** A deployment setting set in the startup config (file, Nacos or env): read-only in the admin console. */
84
86
  "deployment.setting_readonly": 409,
85
87
  /** Allowing outside-sandbox runs platform-wide through an API token or the Platform tool (only off). */
@@ -381,6 +383,12 @@ export const ERROR_CODES = {
381
383
  "conversation.queue_item_not_found": 404,
382
384
  /** A sub-agent's conversation takes no messages from people (sub-agents spec §6.1). */
383
385
  "conversation.read_only": 409,
386
+ /**
387
+ * A referenced project file is not there to reference (composer menus §5): the conversation has
388
+ * no device project, the path leaves it, or the device reports no file there;
389
+ * `details: [{ path?, reason? }]`.
390
+ */
391
+ "conversation.project_file_unavailable": 422,
384
392
  "run.not_active": 409,
385
393
  /** A run that is not one of the conversation's (the live draft route, spec 2026-11-07 §3.2). */
386
394
  "run.not_found": 404,
@@ -446,12 +454,29 @@ export const ERROR_CODES = {
446
454
  "ui.action_failed": 502,
447
455
  "ui.invalid_view": 502,
448
456
  "ui.timeout": 504,
457
+ /** A component query's params are over `UI_LIMITS.componentQueryParamsBytes` as JSON. */
458
+ "ui.query_params_too_large": 413,
459
+ /** A component query's result is over `UI_LIMITS.componentQueryBytes` as JSON, or not JSON. */
460
+ "ui.query_result_too_large": 502,
461
+ /** A component query did not answer within 10 seconds (its signal aborted). */
462
+ "ui.query_timeout": 504,
463
+ /** A component query handler threw. */
464
+ "ui.query_failed": 502,
465
+ /** No query handler for that component, or the component is not offered to the caller. */
466
+ "ui.query_not_found": 404,
449
467
  "storage.unavailable": 503,
450
468
  "attachment.not_found": 404,
451
469
  "attachment.not_ready": 409,
452
470
  "attachment.too_large": 413,
453
471
  "attachment.type_not_allowed": 415,
454
472
  "attachment.too_many_pending": 429,
473
+ "file.not_found": 404,
474
+ "file.not_ready": 409,
475
+ "file.hash_mismatch": 422,
476
+ "file.deleted": 410,
477
+ "file.too_large": 413,
478
+ "file.type_not_allowed": 415,
479
+ "file.too_many_pending": 429,
455
480
  "sandbox.unavailable": 503,
456
481
  "sandbox.busy": 409,
457
482
  /** A cloud sandbox provider refused an instance with the open public network. */
@@ -549,6 +574,13 @@ export const ERROR_CODES = {
549
574
  "device.project_path_unreadable": 422,
550
575
  /** The device provider refused the project's directory (its reason is the message and details). */
551
576
  "device.project_refused": 422,
577
+ /**
578
+ * A path relative to a device project that leaves it (composer menus §5): absolute, `..` above
579
+ * the root, a backslash or a control character; `details: [{ path }]`.
580
+ */
581
+ "device.path_outside_project": 422,
582
+ /** The device's provider cannot list its directories for its owner (no `list` / owner browse). */
583
+ "device.list_unsupported": 409,
552
584
  /** Device sign-in (RFC 8628 style): the person has not approved the code yet; keep polling. */
553
585
  "device_sign_in.authorization_pending": 400,
554
586
  /** Device sign-in: the program polls faster than the interval; add 5 seconds and keep polling. */
@@ -565,28 +597,36 @@ export const ERROR_CODES = {
565
597
  "device.credential_invalid": 401,
566
598
  /** A device stream hop from another gateway replica without a valid MAC (or replayed). */
567
599
  "device.stream_hop_refused": 401,
568
- /** The scheduled task is missing, deleted, in another org or not the caller's to see. */
569
- "schedule.not_found": 404,
600
+ /** The automation is missing, deleted, in another org or not the caller's to see. */
601
+ "automation.not_found": 404,
570
602
  /** Not a 5-field cron expression (no seconds field). */
571
- "schedule.invalid_cron": 400,
603
+ "automation.invalid_cron": 400,
572
604
  /** Not an IANA time zone. */
573
- "schedule.invalid_time_zone": 400,
605
+ "automation.invalid_time_zone": 400,
574
606
  /** A `once` time that is not a local date-time `YYYY-MM-DDTHH:mm[:ss]`. */
575
- "schedule.invalid_once_time": 400,
607
+ "automation.invalid_once_time": 400,
576
608
  /** A `once` time that is not in the future. */
577
- "schedule.once_in_past": 400,
609
+ "automation.once_in_past": 400,
578
610
  /** Two fire times closer than the org's `minIntervalMinutes`. */
579
- "schedule.interval_too_short": 400,
611
+ "automation.interval_too_short": 400,
580
612
  /** The creator or the org has as many active and paused tasks as the org allows. */
581
- "schedule.limit_reached": 409,
582
- /** The org turned scheduled tasks off. */
583
- "schedule.disabled": 409,
613
+ "automation.limit_reached": 409,
614
+ /** The org turned automations off. */
615
+ "automation.disabled": 409,
584
616
  /** Where the task runs is inconsistent or not the creator's to use (conversation, chat, device). */
585
- "schedule.target_invalid": 400,
617
+ "automation.target_invalid": 400,
586
618
  /** A tool the creator cannot pre-approve for the task (spec §7). */
587
- "schedule.grant_not_allowed": 400,
619
+ "automation.grant_not_allowed": 400,
620
+ /** An event trigger names a source that is not an enabled trigger source of the org. */
621
+ "automation.event_source_unavailable": 400,
622
+ /** An event trigger names an event type its source does not declare (or a directed one). */
623
+ "automation.event_type_unknown": 400,
624
+ /** An event trigger's filter names a missing or unfilterable fact, or mistypes a value. */
625
+ "automation.filter_invalid": 400,
588
626
  /** An org admin may pause, resume and delete another person's task, never edit it. */
589
- "schedule.forbidden": 403,
627
+ "automation.forbidden": 403,
628
+ /** "Run now" and trial runs: an event automation runs only on its events (no run now, no trial). */
629
+ "automation.run_now_unsupported": 409,
590
630
  "skill.not_found": 404,
591
631
  /** The skill's file routes: no such version of the skill, or no such path in that version. */
592
632
  "skill.file_not_found": 404,
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Canonical JSON (eval replay matching): object keys sorted recursively by code point, arrays in
3
+ * order, `undefined` left out by the JSON rules. A leaf module, so request building
4
+ * (`evals/reconstruct.ts`, reached from the runtime through the in-context summary) does not pull
5
+ * in the tool pipeline that `recorded-tools.ts` needs.
6
+ */
7
+ export declare function canonicalJson(v: unknown): string;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Canonical JSON (eval replay matching): object keys sorted recursively by code point, arrays in
3
+ * order, `undefined` left out by the JSON rules. A leaf module, so request building
4
+ * (`evals/reconstruct.ts`, reached from the runtime through the in-context summary) does not pull
5
+ * in the tool pipeline that `recorded-tools.ts` needs.
6
+ */
7
+ export function canonicalJson(v) {
8
+ const norm = (x) => {
9
+ if (Array.isArray(x))
10
+ return x.map(norm);
11
+ if (x !== null && typeof x === "object") {
12
+ const o = x;
13
+ const out = {};
14
+ for (const k of Object.keys(o).sort())
15
+ out[k] = norm(o[k]);
16
+ return out;
17
+ }
18
+ return x;
19
+ };
20
+ return JSON.stringify(norm(v) ?? null);
21
+ }
@@ -27,7 +27,9 @@ import { type CaseSnapshot } from "./snapshot.js";
27
27
  * - `context_fit` (context compaction spec §4.9, never for a baseline): the candidate model's window
28
28
  * makes the hard fit guard plan a different trim than the recorded `model_call.request.fit` (the
29
29
  * recorded plan is replayed for a baseline; a candidate applies its recomputed plan);
30
- * - `run_outcome_note`: the rebuilt run outcome notes differ from the recorded `runOutcomeSeqs`.
30
+ * - `run_outcome_note`: the rebuilt run outcome notes differ from the recorded `runOutcomeSeqs`;
31
+ * - `automation_event_block`: the rebuilt event automation blocks differ from the recorded
32
+ * `automationEventSeqs`.
31
33
  */
32
34
  /** 还原结果与原请求不一致的原因。 */
33
35
  export type DriftReason = "system_hash" | "tools_changed" | "tool_spec_missing" | "definition_missing"
@@ -59,6 +61,13 @@ export type DriftReason = "system_hash" | "tools_changed" | "tool_spec_missing"
59
61
  * the log alone, so a candidate cannot change them.
60
62
  */
61
63
  | "run_outcome_note"
64
+ /**
65
+ * Collaboration spec §4.6: the rebuild renders the event automation block
66
+ * (`automationEventBlock`) for another set of messages than the request recorded in
67
+ * `model_call.request.automationEventSeqs`: a request sent before the block was rendered.
68
+ * Judged for every reconstruction: the block comes from the log alone.
69
+ */
70
+ | "automation_event_block"
62
71
  /** 整轮回放(T5):有工具调用没有匹配到记录(模型收到 REPLAY_NO_RECORDING)。 */
63
72
  | "tool_unmatched";
64
73
  export interface ReconstructOptions {
@@ -5,13 +5,14 @@ import { sameModel, selectionAt } from "../conversations/selection.js";
5
5
  import { ApiError } from "../errors.js";
6
6
  import { COMPACTION_SETTINGS } from "../identity/settings.js";
7
7
  import { latestSummary, mediaRefs, planMedia, } from "../runtime/context/build.js";
8
+ import { selectCacheTtl, trustedCache } from "../runtime/context/cache-ttl.js";
8
9
  import { applyFit, estimateAfterFit, planFit, planningBounds, planSqueezedFit, sentOutputCap, } from "../runtime/context/fit.js";
9
10
  import { assertRecordedPermissionEvents, permissionContextHistory, RecordedPermissionContextError, } from "../runtime/context/permission-profile.js";
10
11
  import { estimateTokens } from "../runtime/context/tokens.js";
11
12
  import { assembleModelRequest, } from "../runtime/model-call.js";
12
13
  import { CHILD_REMOVED_TOOLS } from "../runtime/subagents/definition.js";
13
14
  import { AGENT_TOOL } from "../tools/builtin-names.js";
14
- import { canonicalJson } from "./recorded-tools.js";
15
+ import { canonicalJson } from "./canonical-json.js";
15
16
  import { toEvents } from "./snapshot.js";
16
17
  /** `R` when the caller did not resolve the org's settings (the built-in platform default). */
17
18
  const DEFAULT_RESERVE_TOKENS = COMPACTION_SETTINGS.parse({}).reserveTokens;
@@ -47,6 +48,7 @@ const DRIFT_ORDER = [
47
48
  "media_changed",
48
49
  "context_fit",
49
50
  "run_outcome_note",
51
+ "automation_event_block",
50
52
  "tool_unmatched",
51
53
  ];
52
54
  function findCall(events, seq) {
@@ -198,6 +200,16 @@ export function reconstructInputs(s, modelCallSeq, opts) {
198
200
  }
199
201
  const budget = opts.mediaBudgetBytes ?? rec.mediaBudgetBytes;
200
202
  const readWindow = opts.readImagesPerRequest ?? rec.readImagesPerRequest;
203
+ // the prompt cache tier: a recorded transport option, not model-visible, so no DriftReason
204
+ // either way (idle compaction spec §9.2). The baseline sends the recorded value while the model
205
+ // still offers it (never a value the model does not offer); a candidate recomputes it for its
206
+ // model, with the long tier on when the recording asked for one.
207
+ const cacheTtl = baseline
208
+ ? rec.cacheTtl !== undefined &&
209
+ trustedCache(opts.model.cache)?.ttlOptions.includes(rec.cacheTtl)
210
+ ? rec.cacheTtl
211
+ : undefined
212
+ : selectCacheTtl(opts.model.cache, rec.cacheTtl !== undefined);
201
213
  const input = {
202
214
  events: inputEvents(all, call),
203
215
  agent,
@@ -209,6 +221,7 @@ export function reconstructInputs(s, modelCallSeq, opts) {
209
221
  tools,
210
222
  toolSearch: rec.catalog !== undefined,
211
223
  ...(rec.toolChoice !== undefined && { toolChoice: rec.toolChoice }),
224
+ ...(cacheTtl !== undefined && { cacheTtl }),
212
225
  ...(opts.mediaInfo !== undefined && { mediaInfo: opts.mediaInfo }),
213
226
  ...(opts.media !== undefined && { media: opts.media }),
214
227
  ...(budget !== undefined && { mediaBudgetBytes: budget }),
@@ -283,6 +296,12 @@ export function reconstructFromInputs(s, gathered, opts) {
283
296
  if (notes.length !== recordedNotes.length || notes.some((x, i) => x !== recordedNotes[i])) {
284
297
  drift.add("run_outcome_note");
285
298
  }
299
+ // event automation blocks: from the log alone, so only a request sent before they existed differs
300
+ const blocks = meta.automationEventSeqs ?? [];
301
+ const recordedBlocks = rec.automationEventSeqs ?? [];
302
+ if (blocks.length !== recordedBlocks.length || blocks.some((x, i) => x !== recordedBlocks[i])) {
303
+ drift.add("automation_event_block");
304
+ }
286
305
  // 媒体:按附件 id 与记录比较
287
306
  const recordedMedia = new Map((rec.media ?? []).map((m) => [m.attachmentId, m]));
288
307
  for (const m of meta.media ?? []) {
@@ -46,8 +46,6 @@ export interface RecordedCall {
46
46
  */
47
47
  media?: ReadMedia[];
48
48
  }
49
- /** 规范化 JSON:对象键递归按码点排序,数组保持顺序;`undefined` 按 JSON 规则省略。 */
50
- export declare function canonicalJson(v: unknown): string;
51
49
  /** The matching key of a call: the canonical JSON of its input without the ignored fields. */
52
50
  export declare function matchKey(toolKey: string, input: unknown): string;
53
51
  /**
@@ -4,6 +4,7 @@ import { devicePathsChangeFromPayload, devicePathsLevel, } from "../runtime/cont
4
4
  import { assistantIdemKey } from "../runtime/model-call.js";
5
5
  import { MATCH_IGNORED_FIELDS } from "../tools/builtin-names.js";
6
6
  import { RUN_STOPPED_TEXT } from "../tools/pipeline.js";
7
+ import { canonicalJson } from "./canonical-json.js";
7
8
  /**
8
9
  * 整轮回放的工具管线(C6 / Review Focus 3):只回放原运行记录的工具结果,**从不执行任何工具**——
9
10
  * 不经过策略、审批、沙箱、连接器,也不调用任何处理函数。每个调用按 (toolKey, 规范化参数) 精确匹配第一条未用的记录;
@@ -11,22 +12,6 @@ import { RUN_STOPPED_TEXT } from "../tools/pipeline.js";
11
12
  */
12
13
  /** 没有匹配记录时模型看到的工具结果(模型可见,英文)。 */
13
14
  export const REPLAY_NO_RECORDING = "[replay] No recorded result matches this tool call (same tool and arguments); the tool was not executed during replay.";
14
- /** 规范化 JSON:对象键递归按码点排序,数组保持顺序;`undefined` 按 JSON 规则省略。 */
15
- export function canonicalJson(v) {
16
- const norm = (x) => {
17
- if (Array.isArray(x))
18
- return x.map(norm);
19
- if (x !== null && typeof x === "object") {
20
- const o = x;
21
- const out = {};
22
- for (const k of Object.keys(o).sort())
23
- out[k] = norm(o[k]);
24
- return out;
25
- }
26
- return x;
27
- };
28
- return JSON.stringify(norm(v) ?? null);
29
- }
30
15
  /** The matching key of a call: the canonical JSON of its input without the ignored fields. */
31
16
  export function matchKey(toolKey, input) {
32
17
  const ignored = MATCH_IGNORED_FIELDS[toolKey];
@@ -2,6 +2,7 @@ import type { ConversationSource, ToolSpec } from "@capybara-hq/plugin-sdk";
2
2
  import { type AgentDefinition } from "../agents/definition.js";
3
3
  import type { ConversationEvent, ConversationEventType } from "../conversations/events.js";
4
4
  import type { KernelSchemaDb } from "../db/kernel-schema.js";
5
+ import { type FollowUpNarrowing } from "../runtime/subagents/definition.js";
5
6
  /**
6
7
  * 评测用例快照(C3):复制截至某次运行终态的会话事件、这些事件引用的 agent 版本定义、请求用到的工具定义
7
8
  * (按 specHash)。回放只读快照,不改原对话的日志;媒体不复制字节,回放时按引用取原附件。
@@ -59,11 +60,33 @@ export interface CaseSnapshot {
59
60
  };
60
61
  }
61
62
  /**
62
- * 给某次运行建用例快照。会话不在该组织、或运行不属于该会话 → `conversation.not_found`;
63
- * 运行还没有终态事件 → `eval.run_not_finished`(409);序列化后超过 `maxBytes` 字节 → `eval.case_too_large`(413)。
64
- * `maxBytes` 由调用方传入(`evals.maxCaseBytes`)。
63
+ * The follow-up narrowing of run `runId`: the one on the last sub-agent task message up to the
64
+ * run's last event (its terminal event when it has one), if any. A task message logged after the
65
+ * run (a later follow-up's, which a live snapshot may hold) never narrows this run's definition.
66
+ * Without any event of the run, every event counts.
67
+ */
68
+ export declare function runTaskNarrowing(events: readonly SnapshotEvent[], runId: string): FollowUpNarrowing | undefined;
69
+ /**
70
+ * Takes a case snapshot of a run. The conversation not in the org, or the run not the
71
+ * conversation's → `conversation.not_found`; the run without a terminal event yet →
72
+ * `eval.run_not_finished` (409); over `maxBytes` bytes serialized → `eval.case_too_large` (413).
73
+ * The caller passes `maxBytes` (`evals.maxCaseBytes`).
65
74
  */
66
75
  export declare function takeSnapshot(db: KernelSchemaDb, orgId: string, conversationId: string, runId: string, maxBytes: number): Promise<CaseSnapshot>;
76
+ /**
77
+ * A snapshot of events the caller already holds, for a request built live rather than stored (the
78
+ * in-context compaction summary, idle compaction spec §9.4): no terminal event is required and no
79
+ * byte cap applies, since nothing is stored. `runId` is the run of the call the request rebuilds;
80
+ * `conversation.not_found` as in {@link takeSnapshot}. `agentId` is the caller's check: a
81
+ * conversation whose agent differs is not found either.
82
+ */
83
+ export declare function liveSnapshot(db: KernelSchemaDb, input: {
84
+ orgId: string;
85
+ conversationId: string;
86
+ runId: string;
87
+ agentId: string;
88
+ events: readonly ConversationEvent[];
89
+ }): Promise<CaseSnapshot>;
67
90
  /**
68
91
  * Reads a stored snapshot (`eval_cases.snapshot`): each version's definition goes through
69
92
  * `normalizeStoredDefinition` (missing turned-off lists read as empty). Other fields as they are.