omnicell-router 0.8.2 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (400) hide show
  1. package/README.md +26 -7
  2. package/README.zh-CN.md +18 -5
  3. package/backend/dist/auth/api-keys.js +11 -0
  4. package/backend/dist/auth/key-models.d.ts +36 -0
  5. package/backend/dist/auth/key-models.js +99 -0
  6. package/backend/dist/capture/recorder.d.ts +4 -10
  7. package/backend/dist/capture/recorder.js +6 -58
  8. package/backend/dist/cli/clients/activity.js +2 -0
  9. package/backend/dist/cli/clients/base.d.ts +36 -11
  10. package/backend/dist/cli/clients/base.js +31 -15
  11. package/backend/dist/cli/clients/claude.d.ts +9 -0
  12. package/backend/dist/cli/clients/claude.js +6 -0
  13. package/backend/dist/cli/clients/codex.d.ts +78 -0
  14. package/backend/dist/cli/clients/codex.js +475 -57
  15. package/backend/dist/cli/clients/core-adapters.d.ts +1 -1
  16. package/backend/dist/cli/clients/core-adapters.js +1 -1
  17. package/backend/dist/cli/clients/dsh.d.ts +8 -0
  18. package/backend/dist/cli/clients/dsh.js +5 -0
  19. package/backend/dist/cli/clients/follow-catalog-sync.d.ts +62 -0
  20. package/backend/dist/cli/clients/follow-catalog-sync.js +435 -0
  21. package/backend/dist/cli/clients/grok.d.ts +15 -1
  22. package/backend/dist/cli/clients/grok.js +16 -2
  23. package/backend/dist/cli/clients/index.d.ts +13 -1
  24. package/backend/dist/cli/clients/index.js +97 -19
  25. package/backend/dist/cli/clients/kimi.d.ts +6 -0
  26. package/backend/dist/cli/clients/kimi.js +3 -0
  27. package/backend/dist/cli/clients/launcher.d.ts +1 -1
  28. package/backend/dist/cli/clients/model-meta.js +6 -3
  29. package/backend/dist/cli/clients/omp.d.ts +6 -0
  30. package/backend/dist/cli/clients/omp.js +3 -0
  31. package/backend/dist/cli/clients/openclaw.d.ts +6 -0
  32. package/backend/dist/cli/clients/openclaw.js +3 -0
  33. package/backend/dist/cli/clients/opencode.d.ts +8 -0
  34. package/backend/dist/cli/clients/opencode.js +8 -2
  35. package/backend/dist/cli/clients/pi.d.ts +6 -0
  36. package/backend/dist/cli/clients/pi.js +3 -0
  37. package/backend/dist/cli/clients/reserved.js +2 -0
  38. package/backend/dist/cli/clients/update-check.d.ts +37 -0
  39. package/backend/dist/cli/clients/update-check.js +309 -0
  40. package/backend/dist/cli/clients/workbuddy.d.ts +19 -0
  41. package/backend/dist/cli/clients/workbuddy.js +66 -0
  42. package/backend/dist/cli/index.js +5 -4
  43. package/backend/dist/cli/paths.js +8 -0
  44. package/backend/dist/cli/types.d.ts +101 -16
  45. package/backend/dist/config/comments-en.js +34 -25
  46. package/backend/dist/config/comments-zh.js +33 -24
  47. package/backend/dist/config/defaults.d.ts +280 -22
  48. package/backend/dist/config/defaults.js +279 -21
  49. package/backend/dist/config/env.d.ts +10 -0
  50. package/backend/dist/config/env.js +3 -2
  51. package/backend/dist/config/index.d.ts +22 -1
  52. package/backend/dist/config/index.js +218 -43
  53. package/backend/dist/config/migrations/v0-to-v1.d.ts +2 -2
  54. package/backend/dist/config/migrations/v10-to-v11.d.ts +38 -0
  55. package/backend/dist/config/migrations/v10-to-v11.js +43 -0
  56. package/backend/dist/config/migrations/v4-to-v5.d.ts +36 -0
  57. package/backend/dist/config/migrations/v4-to-v5.js +42 -0
  58. package/backend/dist/config/migrations/v5-to-v6.d.ts +27 -0
  59. package/backend/dist/config/migrations/v5-to-v6.js +29 -0
  60. package/backend/dist/config/migrations/v6-to-v7.d.ts +45 -0
  61. package/backend/dist/config/migrations/v6-to-v7.js +97 -0
  62. package/backend/dist/config/migrations/v7-to-v8.d.ts +36 -0
  63. package/backend/dist/config/migrations/v7-to-v8.js +43 -0
  64. package/backend/dist/config/migrations/v8-to-v9.d.ts +38 -0
  65. package/backend/dist/config/migrations/v8-to-v9.js +43 -0
  66. package/backend/dist/config/migrations/v9-to-v10.d.ts +51 -0
  67. package/backend/dist/config/migrations/v9-to-v10.js +71 -0
  68. package/backend/dist/config/runtime.js +1 -1
  69. package/backend/dist/config/schema.d.ts +3 -3
  70. package/backend/dist/config/schema.js +18 -4
  71. package/backend/dist/config/types.d.ts +221 -41
  72. package/backend/dist/egress-proxy/asset-download.d.ts +54 -0
  73. package/backend/dist/egress-proxy/asset-download.js +420 -0
  74. package/backend/dist/egress-proxy/manual-node-spec.d.ts +92 -0
  75. package/backend/dist/egress-proxy/manual-node-spec.js +408 -0
  76. package/backend/dist/egress-proxy/mihomo-binary.d.ts +54 -0
  77. package/backend/dist/egress-proxy/mihomo-binary.js +278 -0
  78. package/backend/dist/egress-proxy/mihomo-client.d.ts +94 -0
  79. package/backend/dist/egress-proxy/mihomo-client.js +308 -0
  80. package/backend/dist/egress-proxy/mihomo-config.d.ts +40 -0
  81. package/backend/dist/egress-proxy/mihomo-config.js +161 -0
  82. package/backend/dist/egress-proxy/mihomo-geo.d.ts +87 -0
  83. package/backend/dist/egress-proxy/mihomo-geo.js +213 -0
  84. package/backend/dist/egress-proxy/mihomo-logs.d.ts +43 -0
  85. package/backend/dist/egress-proxy/mihomo-logs.js +84 -0
  86. package/backend/dist/egress-proxy/mihomo-pac.d.ts +37 -0
  87. package/backend/dist/egress-proxy/mihomo-pac.js +75 -0
  88. package/backend/dist/egress-proxy/mihomo-rules-import.d.ts +43 -0
  89. package/backend/dist/egress-proxy/mihomo-rules-import.js +193 -0
  90. package/backend/dist/egress-proxy/mihomo-sidecar.d.ts +81 -0
  91. package/backend/dist/egress-proxy/mihomo-sidecar.js +637 -0
  92. package/backend/dist/forward-proxy/egress.d.ts +50 -11
  93. package/backend/dist/forward-proxy/egress.js +63 -17
  94. package/backend/dist/forward-proxy/h2-forward.js +42 -15
  95. package/backend/dist/forward-proxy/index.d.ts +11 -8
  96. package/backend/dist/forward-proxy/index.js +27 -60
  97. package/backend/dist/forward-proxy/interceptor.d.ts +3 -2
  98. package/backend/dist/forward-proxy/interceptor.js +4 -4
  99. package/backend/dist/forward-proxy/relay.js +3 -3
  100. package/backend/dist/forward-proxy/rules.d.ts +4 -4
  101. package/backend/dist/forward-proxy/rules.js +25 -4
  102. package/backend/dist/forward-proxy/server.d.ts +12 -16
  103. package/backend/dist/forward-proxy/server.js +237 -171
  104. package/backend/dist/harness/host/hosts.js +3 -2
  105. package/backend/dist/index.js +59 -19
  106. package/backend/dist/ingress-proxy/access-log.d.ts +176 -0
  107. package/backend/dist/ingress-proxy/access-log.js +774 -0
  108. package/backend/dist/ingress-proxy/ca-inventory.d.ts +106 -0
  109. package/backend/dist/ingress-proxy/ca-inventory.js +525 -0
  110. package/backend/dist/ingress-proxy/ca-trust.d.ts +96 -0
  111. package/backend/dist/ingress-proxy/ca-trust.js +315 -0
  112. package/backend/dist/ingress-proxy/ca.d.ts +104 -0
  113. package/backend/dist/ingress-proxy/ca.js +273 -0
  114. package/backend/dist/ingress-proxy/data-dir.d.ts +28 -0
  115. package/backend/dist/ingress-proxy/data-dir.js +45 -0
  116. package/backend/dist/ingress-proxy/egress.d.ts +151 -0
  117. package/backend/dist/ingress-proxy/egress.js +364 -0
  118. package/backend/dist/ingress-proxy/h2-forward.d.ts +66 -0
  119. package/backend/dist/ingress-proxy/h2-forward.js +561 -0
  120. package/backend/dist/ingress-proxy/index.d.ts +24 -0
  121. package/backend/dist/ingress-proxy/index.js +144 -0
  122. package/backend/dist/ingress-proxy/interceptor.d.ts +25 -0
  123. package/backend/dist/ingress-proxy/interceptor.js +52 -0
  124. package/backend/dist/ingress-proxy/ordered-relay.d.ts +29 -0
  125. package/backend/dist/ingress-proxy/ordered-relay.js +46 -0
  126. package/backend/dist/ingress-proxy/relay.d.ts +54 -0
  127. package/backend/dist/ingress-proxy/relay.js +188 -0
  128. package/backend/dist/ingress-proxy/rules.d.ts +195 -0
  129. package/backend/dist/ingress-proxy/rules.js +348 -0
  130. package/backend/dist/ingress-proxy/server.d.ts +153 -0
  131. package/backend/dist/ingress-proxy/server.js +2065 -0
  132. package/backend/dist/ingress-proxy/sni.d.ts +35 -0
  133. package/backend/dist/ingress-proxy/sni.js +124 -0
  134. package/backend/dist/ingress-proxy/status.d.ts +32 -0
  135. package/backend/dist/ingress-proxy/status.js +15 -0
  136. package/backend/dist/ingress-proxy/system-proxy.d.ts +112 -0
  137. package/backend/dist/ingress-proxy/system-proxy.js +481 -0
  138. package/backend/dist/ingress-proxy/traffic-delete.d.ts +21 -0
  139. package/backend/dist/ingress-proxy/traffic-delete.js +64 -0
  140. package/backend/dist/ingress-proxy/traffic-delete.worker.d.ts +44 -0
  141. package/backend/dist/ingress-proxy/traffic-delete.worker.js +228 -0
  142. package/backend/dist/ingress-proxy/traffic-files.d.ts +10 -0
  143. package/backend/dist/ingress-proxy/traffic-files.js +10 -0
  144. package/backend/dist/ingress-proxy/upstream-tls.d.ts +46 -0
  145. package/backend/dist/ingress-proxy/upstream-tls.js +105 -0
  146. package/backend/dist/ingress-proxy/ws-frames.d.ts +45 -0
  147. package/backend/dist/ingress-proxy/ws-frames.js +153 -0
  148. package/backend/dist/ir/adapters/anthropic-messages-stream.js +6 -1
  149. package/backend/dist/ir/adapters/anthropic-messages.js +12 -5
  150. package/backend/dist/ir/adapters/google-gemini-stream.js +7 -2
  151. package/backend/dist/ir/adapters/google-gemini.js +5 -2
  152. package/backend/dist/ir/adapters/openai-chat-stream.js +5 -1
  153. package/backend/dist/ir/adapters/openai-chat.d.ts +25 -0
  154. package/backend/dist/ir/adapters/openai-chat.js +50 -6
  155. package/backend/dist/ir/adapters/openai-responses-output.d.ts +1 -0
  156. package/backend/dist/ir/adapters/openai-responses-output.js +67 -21
  157. package/backend/dist/ir/adapters/openai-responses-stream.d.ts +13 -0
  158. package/backend/dist/ir/adapters/openai-responses-stream.js +34 -1
  159. package/backend/dist/ir/adapters/openai-responses.d.ts +92 -1
  160. package/backend/dist/ir/adapters/openai-responses.js +163 -12
  161. package/backend/dist/ir/capabilities.js +4 -0
  162. package/backend/dist/ir/media.d.ts +20 -0
  163. package/backend/dist/ir/media.js +41 -0
  164. package/backend/dist/ir/tool-identity.d.ts +35 -0
  165. package/backend/dist/ir/tool-identity.js +40 -0
  166. package/backend/dist/ir/types.d.ts +9 -1
  167. package/backend/dist/ir/validate.d.ts +24 -0
  168. package/backend/dist/ir/validate.js +113 -63
  169. package/backend/dist/local/build-jobs.d.ts +66 -0
  170. package/backend/dist/local/build-jobs.js +243 -0
  171. package/backend/dist/local/detect.d.ts +32 -0
  172. package/backend/dist/local/detect.js +145 -0
  173. package/backend/dist/local/draft-match.d.ts +58 -0
  174. package/backend/dist/local/draft-match.js +124 -0
  175. package/backend/dist/local/engine-runtime.d.ts +522 -0
  176. package/backend/dist/local/engine-runtime.js +1 -0
  177. package/backend/dist/local/engines.d.ts +241 -0
  178. package/backend/dist/local/engines.js +651 -0
  179. package/backend/dist/local/gguf.d.ts +35 -0
  180. package/backend/dist/local/gguf.js +314 -0
  181. package/backend/dist/local/hf.d.ts +120 -0
  182. package/backend/dist/local/hf.js +304 -0
  183. package/backend/dist/local/install.d.ts +90 -0
  184. package/backend/dist/local/install.js +421 -0
  185. package/backend/dist/local/llamacpp.d.ts +55 -0
  186. package/backend/dist/local/llamacpp.js +177 -0
  187. package/backend/dist/local/local-provider.d.ts +81 -0
  188. package/backend/dist/local/local-provider.js +301 -0
  189. package/backend/dist/local/machine-stats.d.ts +87 -0
  190. package/backend/dist/local/machine-stats.js +332 -0
  191. package/backend/dist/local/model-store.d.ts +347 -0
  192. package/backend/dist/local/model-store.js +1215 -0
  193. package/backend/dist/local/part-sweep.d.ts +32 -0
  194. package/backend/dist/local/part-sweep.js +156 -0
  195. package/backend/dist/local/plan.d.ts +65 -0
  196. package/backend/dist/local/plan.js +146 -0
  197. package/backend/dist/local/resources.d.ts +49 -0
  198. package/backend/dist/local/resources.js +64 -0
  199. package/backend/dist/local/run-stats.d.ts +95 -0
  200. package/backend/dist/local/run-stats.js +195 -0
  201. package/backend/dist/local/runner.d.ts +235 -0
  202. package/backend/dist/local/runner.js +1392 -0
  203. package/backend/dist/local/settings.d.ts +79 -0
  204. package/backend/dist/local/settings.js +180 -0
  205. package/backend/dist/local/strata-catalog.d.ts +30 -0
  206. package/backend/dist/local/strata-catalog.js +511 -0
  207. package/backend/dist/local/strata-drafting.d.ts +46 -0
  208. package/backend/dist/local/strata-drafting.js +265 -0
  209. package/backend/dist/local/strata.d.ts +278 -0
  210. package/backend/dist/local/strata.js +1392 -0
  211. package/backend/dist/local/tar.d.ts +20 -0
  212. package/backend/dist/local/tar.js +367 -0
  213. package/backend/dist/local/transport.d.ts +35 -0
  214. package/backend/dist/local/transport.js +89 -0
  215. package/backend/dist/local/tune.d.ts +58 -0
  216. package/backend/dist/local/tune.js +324 -0
  217. package/backend/dist/observability/http-exchange.d.ts +2 -2
  218. package/backend/dist/opencode/catalog/auto-pull.d.ts +14 -3
  219. package/backend/dist/opencode/catalog/auto-pull.js +284 -77
  220. package/backend/dist/opencode/catalog/ocr-store.d.ts +7 -6
  221. package/backend/dist/opencode/catalog/ocr-store.js +4 -2
  222. package/backend/dist/opencode/catalog/overrides-store.d.ts +15 -4
  223. package/backend/dist/opencode/catalog/overrides-store.js +28 -19
  224. package/backend/dist/opencode/catalog/reasoning-declaration.d.ts +35 -0
  225. package/backend/dist/opencode/catalog/reasoning-declaration.js +66 -0
  226. package/backend/dist/opencode/catalog/repository.js +28 -5
  227. package/backend/dist/opencode/catalog/sources/models-dev.d.ts +3 -3
  228. package/backend/dist/opencode/catalog/sources/models-dev.js +42 -14
  229. package/backend/dist/opencode/catalog/types.d.ts +42 -12
  230. package/backend/dist/opencode/catalog/types.js +38 -1
  231. package/backend/dist/opencode/credentials/def-materialize.js +27 -21
  232. package/backend/dist/opencode/credentials/ocr-store.js +11 -2
  233. package/backend/dist/opencode/credentials/sync.js +12 -3
  234. package/backend/dist/opencode/credentials/types.d.ts +31 -4
  235. package/backend/dist/opencode/credentials/types.js +25 -0
  236. package/backend/dist/opencode/migrate/engine.d.ts +20 -0
  237. package/backend/dist/opencode/migrate/engine.js +71 -0
  238. package/backend/dist/opencode/migrate/migrator.d.ts +11 -0
  239. package/backend/dist/opencode/migrate/migrator.js +6 -0
  240. package/backend/dist/opencode/migrate/steps/overrides-v1-to-v2.d.ts +6 -0
  241. package/backend/dist/opencode/migrate/steps/overrides-v1-to-v2.js +31 -0
  242. package/backend/dist/opencode/migrate/steps/providers-v1-to-v2.d.ts +6 -0
  243. package/backend/dist/opencode/migrate/steps/providers-v1-to-v2.js +62 -0
  244. package/backend/dist/opencode/probe.d.ts +21 -4
  245. package/backend/dist/opencode/probe.js +34 -10
  246. package/backend/dist/opencode/provider-def-adapters.d.ts +12 -11
  247. package/backend/dist/opencode/provider-def-adapters.js +43 -27
  248. package/backend/dist/opencode/provider-defs.d.ts +10 -16
  249. package/backend/dist/opencode/provider-defs.js +45 -45
  250. package/backend/dist/opencode/user-config.d.ts +23 -26
  251. package/backend/dist/opencode/user-config.js +95 -77
  252. package/backend/dist/pipeline/directives.d.ts +9 -4
  253. package/backend/dist/pipeline/directives.js +14 -10
  254. package/backend/dist/pipeline/orchestrator.d.ts +42 -13
  255. package/backend/dist/pipeline/orchestrator.js +514 -172
  256. package/backend/dist/plugins/builtin/model-gateway.js +38 -12
  257. package/backend/dist/plugins/environment-ack.d.ts +51 -0
  258. package/backend/dist/plugins/environment-ack.js +81 -0
  259. package/backend/dist/plugins/gateways.d.ts +6 -6
  260. package/backend/dist/plugins/gateways.js +2 -2
  261. package/backend/dist/plugins/host.d.ts +100 -16
  262. package/backend/dist/plugins/host.js +637 -99
  263. package/backend/dist/plugins/install-run.d.ts +27 -0
  264. package/backend/dist/plugins/install-run.js +99 -0
  265. package/backend/dist/plugins/manifest.d.ts +84 -32
  266. package/backend/dist/plugins/manifest.js +149 -45
  267. package/backend/dist/plugins/market-install.d.ts +18 -0
  268. package/backend/dist/plugins/market-install.js +111 -0
  269. package/backend/dist/plugins/market-source.d.ts +100 -0
  270. package/backend/dist/plugins/market-source.js +449 -0
  271. package/backend/dist/plugins/market-updates.d.ts +70 -0
  272. package/backend/dist/plugins/market-updates.js +97 -0
  273. package/backend/dist/plugins/market.d.ts +677 -0
  274. package/backend/dist/plugins/market.js +2113 -0
  275. package/backend/dist/plugins/source-index.d.ts +155 -0
  276. package/backend/dist/plugins/source-index.js +217 -0
  277. package/backend/dist/plugins/types.d.ts +402 -37
  278. package/backend/dist/projects/worktrees.d.ts +88 -0
  279. package/backend/dist/projects/worktrees.js +220 -0
  280. package/backend/dist/providers/boot-direct.d.ts +41 -7
  281. package/backend/dist/providers/boot-direct.js +284 -44
  282. package/backend/dist/providers/compat/tool-markup-recovery.js +31 -6
  283. package/backend/dist/providers/dial-wire.d.ts +17 -0
  284. package/backend/dist/providers/dial-wire.js +49 -0
  285. package/backend/dist/providers/executors/dispatch.d.ts +17 -7
  286. package/backend/dist/providers/executors/dispatch.js +28 -9
  287. package/backend/dist/providers/executors/openai-chat.js +14 -2
  288. package/backend/dist/providers/executors/plugin-adapter.d.ts +23 -1
  289. package/backend/dist/providers/executors/plugin-adapter.js +59 -3
  290. package/backend/dist/providers/member-match.d.ts +32 -9
  291. package/backend/dist/providers/member-match.js +65 -21
  292. package/backend/dist/providers/model-resolution.d.ts +62 -0
  293. package/backend/dist/providers/model-resolution.js +62 -0
  294. package/backend/dist/providers/price-order.d.ts +51 -0
  295. package/backend/dist/providers/price-order.js +54 -0
  296. package/backend/dist/providers/protocols-field.d.ts +24 -0
  297. package/backend/dist/providers/protocols-field.js +66 -0
  298. package/backend/dist/providers/provider-takedown.d.ts +5 -2
  299. package/backend/dist/providers/registry.d.ts +87 -26
  300. package/backend/dist/providers/registry.js +232 -121
  301. package/backend/dist/providers/selection.d.ts +91 -0
  302. package/backend/dist/providers/selection.js +158 -0
  303. package/backend/dist/providers/virtual-meta.d.ts +33 -2
  304. package/backend/dist/providers/virtual-meta.js +74 -18
  305. package/backend/dist/quota/cli-login.d.ts +25 -4
  306. package/backend/dist/quota/cli-login.js +38 -6
  307. package/backend/dist/quota/coverage-generation.d.ts +24 -0
  308. package/backend/dist/quota/coverage-generation.js +29 -0
  309. package/backend/dist/quota/declarations.js +8 -4
  310. package/backend/dist/quota/engine.js +2 -2
  311. package/backend/dist/quota/prober.d.ts +43 -2
  312. package/backend/dist/quota/prober.js +97 -22
  313. package/backend/dist/ratelimit/rate-limiter.d.ts +1 -1
  314. package/backend/dist/resilience/error-classifier.js +29 -0
  315. package/backend/dist/router/index.d.ts +1 -1
  316. package/backend/dist/router/index.js +17 -1
  317. package/backend/dist/router/layer2-decision.d.ts +1 -1
  318. package/backend/dist/router/layer2-decision.js +2 -2
  319. package/backend/dist/routes/console.js +1043 -405
  320. package/backend/dist/routes/environments.js +1 -1
  321. package/backend/dist/routes/local-models.d.ts +2 -0
  322. package/backend/dist/routes/local-models.js +1414 -0
  323. package/backend/dist/routes/mihomo.d.ts +2 -2
  324. package/backend/dist/routes/mihomo.js +20 -11
  325. package/backend/dist/routes/projects.js +121 -0
  326. package/backend/dist/server.js +409 -15
  327. package/backend/dist/session/session-manager.d.ts +42 -5
  328. package/backend/dist/session/session-manager.js +64 -11
  329. package/backend/dist/session/session-row.d.ts +29 -8
  330. package/backend/dist/session/session-row.js +18 -13
  331. package/backend/dist/snapshot/bundle.d.ts +40 -0
  332. package/backend/dist/snapshot/bundle.js +177 -0
  333. package/backend/dist/snapshot/handoff/compress.d.ts +46 -0
  334. package/backend/dist/snapshot/handoff/compress.js +77 -0
  335. package/backend/dist/snapshot/handoff/index.d.ts +119 -0
  336. package/backend/dist/snapshot/handoff/index.js +160 -0
  337. package/backend/dist/snapshot/handoff/jsonl-writer.d.ts +78 -0
  338. package/backend/dist/snapshot/handoff/jsonl-writer.js +175 -0
  339. package/backend/dist/snapshot/handoff/opencode-writer.d.ts +51 -0
  340. package/backend/dist/snapshot/handoff/opencode-writer.js +214 -0
  341. package/backend/dist/snapshot/handoff/summarize.d.ts +39 -0
  342. package/backend/dist/snapshot/handoff/summarize.js +118 -0
  343. package/backend/dist/snapshot/handoff/transcript.d.ts +71 -0
  344. package/backend/dist/snapshot/handoff/transcript.js +167 -0
  345. package/backend/dist/snapshot/media-fs.d.ts +10 -0
  346. package/backend/dist/snapshot/media-fs.js +50 -0
  347. package/backend/dist/snapshot/media.d.ts +32 -0
  348. package/backend/dist/snapshot/media.js +87 -0
  349. package/backend/dist/snapshot/store.d.ts +226 -0
  350. package/backend/dist/snapshot/store.js +887 -0
  351. package/backend/dist/snapshot/tree.d.ts +112 -0
  352. package/backend/dist/snapshot/tree.js +207 -0
  353. package/backend/dist/snapshot/types.d.ts +212 -0
  354. package/backend/dist/snapshot/types.js +14 -0
  355. package/backend/dist/snapshot/view.d.ts +19 -0
  356. package/backend/dist/snapshot/view.js +57 -0
  357. package/backend/dist/snapshot/write-worker.d.ts +67 -0
  358. package/backend/dist/snapshot/write-worker.js +129 -0
  359. package/backend/dist/surfaces/anthropic.js +4 -1
  360. package/backend/dist/surfaces/body-admission.d.ts +344 -0
  361. package/backend/dist/surfaces/body-admission.js +818 -0
  362. package/backend/dist/surfaces/chat-pipeline.js +8 -0
  363. package/backend/dist/surfaces/decision-pipeline.js +10 -7
  364. package/backend/dist/surfaces/gateway-catalog.d.ts +26 -0
  365. package/backend/dist/surfaces/gateway-catalog.js +202 -0
  366. package/backend/dist/surfaces/gateway-chat.d.ts +7 -11
  367. package/backend/dist/surfaces/gateway-chat.js +50 -12
  368. package/backend/dist/surfaces/ocr-headers.d.ts +6 -4
  369. package/backend/dist/surfaces/ocr-headers.js +11 -7
  370. package/backend/dist/surfaces/systemone.js +1 -1
  371. package/backend/dist/surfaces/transport-fastify.js +32 -5
  372. package/backend/dist/surfaces/transport-node-http.d.ts +51 -6
  373. package/backend/dist/surfaces/transport-node-http.js +76 -16
  374. package/backend/dist/surfaces/types.d.ts +11 -3
  375. package/backend/dist/trace/persist.js +21 -1
  376. package/backend/dist/trace/tracker.d.ts +35 -3
  377. package/backend/dist/trace/tracker.js +23 -0
  378. package/backend/dist/types/openai.d.ts +8 -0
  379. package/backend/dist/types/router.d.ts +17 -6
  380. package/backend/dist/types/router.js +14 -2
  381. package/backend/dist/utils/client-families.d.ts +66 -0
  382. package/backend/dist/utils/client-families.js +127 -0
  383. package/backend/dist/utils/event-ring.d.ts +1 -1
  384. package/backend/dist/utils/event-ring.js +1 -1
  385. package/backend/dist/utils/proxy-node.js +1 -1
  386. package/backend/dist/utils/proxy.d.ts +135 -11
  387. package/backend/dist/utils/proxy.js +144 -29
  388. package/backend/dist/utils/run-command.d.ts +21 -1
  389. package/backend/dist/utils/run-command.js +64 -4
  390. package/backend/dist/utils/server-liveness.d.ts +28 -0
  391. package/backend/dist/utils/server-liveness.js +32 -0
  392. package/backend/dist/utils/session-file.d.ts +28 -0
  393. package/backend/dist/utils/session-file.js +34 -0
  394. package/frontend/dist/assets/antigravity.color-DXFfVr6X.svg +39 -0
  395. package/frontend/dist/assets/gemini-cli.color-BfquLd1p.svg +1 -0
  396. package/frontend/dist/assets/index-CTZNvn1d.js +1707 -0
  397. package/frontend/dist/assets/{index-DxZ9MHKB.css → index-CqDSOPQ0.css} +1 -1
  398. package/frontend/dist/index.html +2 -2
  399. package/package.json +3 -1
  400. package/frontend/dist/assets/index-55VVwfFQ.js +0 -1521
@@ -182,6 +182,12 @@ export class SessionManager {
182
182
  * arguments on resend, so raw JSON.stringify of the whole object would
183
183
  * miss every tool-call boundary on the next turn.
184
184
  */
185
+ /**
186
+ * PUBLIC on purpose: the snapshot message tree (ADR-0038 §8) derives node
187
+ * identity from THIS canonical form, so two branches that share an ancestry
188
+ * must collapse onto the same node ids it would produce. Exposing it keeps ONE
189
+ * canonicalization instead of a second copy that could drift from the anchors.
190
+ */
185
191
  static serializeMessage(item) {
186
192
  if (item.type === 'message') {
187
193
  const name = 'name' in item ? item.name : undefined;
@@ -315,9 +321,10 @@ export class SessionManager {
315
321
  * is no second namespace to map, while the body channel below covers wires
316
322
  * that have no HTTP headers at all). Returns the alphabetically first
317
323
  * matching header's value (array header → first entry), or null. The bare
318
- * `x-session-id` / `x-conversation-id` / `session-id` / `conversation-id`
319
- * forms never match (the app segment must be non-empty) — they are step 1's
320
- * explicit_header territory. Two namespace guards bind each value: a value
324
+ * explicit forms (`x-session-id`, `x-conversation-id`, `x-session-affinity`,
325
+ * `session_id`, `session-id`, `conversation-id`) never match (the app
326
+ * segment must be non-empty) — they are step 1's explicit_header territory.
327
+ * Two namespace guards bind each value: a value
321
328
  * claiming the reserved `ocr-internal:` prefix (a gateway-internal row
322
329
  * marker — a client must not be able to hide its row from the console) or
323
330
  * exceeding `VENDOR_SESSION_ID_MAX` is skipped, falling through to the next
@@ -367,19 +374,56 @@ export class SessionManager {
367
374
  * and the session it names can never disagree.
368
375
  */
369
376
  /**
370
- * Caller-supplied conversation id. Reads the four explicit header names and
377
+ * Header names that carry a client conversation id, in precedence order.
378
+ * Every entry is conversation-scoped on the clients that emit it, and none
379
+ * is reachable by the vendor probe: `x-session-id` (explicit contract,
380
+ * console, billion-context proxy — proven 1:1 in the capture archive),
381
+ * `x-conversation-id` (same explicit namespace, backward compatibility),
382
+ * `x-session-affinity` (pi chat on a non-OpenRouter endpoint and the
383
+ * Anthropic leg — an affinity key only works per-conversation; the probe
384
+ * regex needs a trailing `-id`, so this spelling is never claimed twice),
385
+ * `session_id` (pi's openai-format id on the chat and Responses HTTP legs;
386
+ * underscore, so the hyphen-only probe can never match it), then the legacy
387
+ * `session-id` / `conversation-id`.
388
+ */
389
+ static EXPLICIT_SESSION_HEADERS = [
390
+ 'x-session-id',
391
+ 'x-conversation-id',
392
+ 'x-session-affinity',
393
+ 'session_id',
394
+ 'session-id',
395
+ 'conversation-id',
396
+ ];
397
+ /** Trimmed first entry of a possibly-array header value, else ''. */
398
+ static headerValue(raw) {
399
+ const id = (Array.isArray(raw) ? raw[0] : raw)?.trim();
400
+ return id ?? '';
401
+ }
402
+ /**
403
+ * Caller-supplied conversation id. Reads the explicit header list and
371
404
  * nothing else: no mint, no anchor, no session-manager write. Archive code
372
405
  * uses this when it needs a file name and the request is not a conversation.
406
+ *
407
+ * A blank value falls through to the next name — a truthy-but-empty header
408
+ * must never mask a real id later in the list. `session-id` is skipped when
409
+ * it equals the request's `x-client-request-id`: pi's Codex Responses
410
+ * websocket leg stamps both with the PER-REQUEST id, so that pair is a
411
+ * correlation id, not a conversation id (a legitimate client never names a
412
+ * conversation after its own per-request id).
373
413
  */
374
414
  static explicitSessionId(headers) {
375
- const raw = headers?.['x-session-id'] ||
376
- headers?.['x-conversation-id'] ||
377
- headers?.['session-id'] ||
378
- headers?.['conversation-id'];
379
- if (!raw)
415
+ if (!headers)
380
416
  return undefined;
381
- const id = (Array.isArray(raw) ? raw[0] : raw).trim();
382
- return id.length > 0 ? id : undefined;
417
+ const requestId = SessionManager.headerValue(headers['x-client-request-id']);
418
+ for (const name of SessionManager.EXPLICIT_SESSION_HEADERS) {
419
+ const id = SessionManager.headerValue(headers[name]);
420
+ if (!id)
421
+ continue;
422
+ if (name === 'session-id' && requestId && id === requestId)
423
+ continue;
424
+ return id;
425
+ }
426
+ return undefined;
383
427
  }
384
428
  static clientRefOf(request) {
385
429
  return SessionManager.normalizeClientRef(request.routerOptions?.clientRef);
@@ -595,6 +639,15 @@ export class SessionManager {
595
639
  map.delete(oldest);
596
640
  }
597
641
  }
642
+ /**
643
+ * True when a ratchet call actually persists a per-session model pin.
644
+ * `applyRatchet` still resolves a representative model in the stateless /
645
+ * disabled branch, but that representative is thrown away with the dummy
646
+ * session — callers must not let it consume a rotation pick.
647
+ */
648
+ pinsModels() {
649
+ return this.config.enabled && this.config.strategy !== 'stateless';
650
+ }
598
651
  /**
599
652
  * Applies the Monotonic Session Ratchet policy.
600
653
  *
@@ -18,6 +18,7 @@ import type { CallCredential } from '../opencode/credentials/types.js';
18
18
  import type { ClientConversationRef, ConversationSession } from './session-manager.js';
19
19
  import type { ExecutionTrace, TraceTracker } from '../trace/tracker.js';
20
20
  import type { CaptureKeyIdentity } from '../capture/recorder.js';
21
+ import type { SessionClientFamily } from '../utils/client-families.js';
21
22
  /**
22
23
  * How the client addressed a session's turns, derived from persisted traces
23
24
  * (observability reconstruction — never routing state):
@@ -131,10 +132,23 @@ export interface SessionRow extends SessionEntityView, SessionAggregates {
131
132
  * in that provider's chain; the console then falls back to the prefix.
132
133
  */
133
134
  boundCredentialLabel?: string;
135
+ /**
136
+ * True when the bound credential is this machine's own CLI login. Its NAME is fixed
137
+ * (the console refuses to rename it) and it has no stored label, so without this flag
138
+ * a caller could not tell it apart from an unnamed credential.
139
+ */
140
+ boundCredentialMachineLogin?: boolean;
134
141
  /** Distinct client API-key identities, write order (first = display anchor). */
135
142
  apiKeys?: CaptureKeyIdentity[];
136
143
  /** Distinct client User-Agents, write order (console display only). */
137
144
  clients?: string[];
145
+ /**
146
+ * Distinct client FAMILIES derived from `clients` (write order), the axis the
147
+ * console filters on. Ids are machine keys (`opencode`, `claude-code`, `pi`,
148
+ * `unknown`, …) from the canonical classifier in utils/client-families.ts;
149
+ * labels are English fallbacks. Display/filter only — never identity.
150
+ */
151
+ clientFamilies?: SessionClientFamily[];
138
152
  /**
139
153
  * Client-minted conversation ids seen on this session's turns (write order,
140
154
  * first = display anchor), derived from the traces' `request.clientRef`. The
@@ -145,13 +159,20 @@ export interface SessionRow extends SessionEntityView, SessionAggregates {
145
159
  clientRefs?: ClientConversationRef[];
146
160
  }
147
161
  /**
148
- * Operator label for a bound credential, matched against the serving
149
- * provider's LIVE registry chain at serialization time. The session entity
150
- * persists only the display-safe `boundKeyHashPrefix` (ADR-0002 §3); labels
151
- * are credential-store metadata that can be renamed without touching any
152
- * session, so the join happens on read. `undefined` = unnamed credential, no
153
- * chain (mock/stub or provider gone), or the credential left the chain — the
154
- * console then falls back to the prefix.
162
+ * Display identity of the credential a session is bound to, matched against the serving
163
+ * provider's LIVE registry chain at serialization time. The session entity persists only
164
+ * the display-safe `boundKeyHashPrefix` (ADR-0002 §3); labels are credential-store
165
+ * metadata that can be renamed without touching any session, so the join happens on read.
166
+ * No entry / an entry with no label = unnamed — the console then falls back to the prefix.
167
+ *
168
+ * `machineLogin` rides along because that row's NAME is fixed (the console refuses to
169
+ * rename it) and it carries no stored label, so a caller given only `label` could never
170
+ * tell "unnamed" from "this machine's login". It is detected from the marker VALUE
171
+ * (`isMachineLoginValue`) — the whole identity of that chain member — so `CallCredential`
172
+ * needs no extra field.
155
173
  */
156
- export declare function boundCredentialLabelOf(chain: readonly CallCredential[] | undefined, keyHashPrefix: string | undefined): string | undefined;
174
+ export declare function boundCredentialOf(chain: readonly CallCredential[] | undefined, keyHashPrefix: string | undefined): {
175
+ label?: string;
176
+ machineLogin: boolean;
177
+ };
157
178
  export {};
@@ -1,3 +1,4 @@
1
+ import { isMachineLoginValue } from '../opencode/credentials/types.js';
1
2
  /** Classify a session from its traces (chronological order irrelevant). */
2
3
  export function deriveSessionEntryMode(traces) {
3
4
  // Virtual auto aliases: bare auto plus the four tier-forced aliases
@@ -83,7 +84,7 @@ export function sessionTitleOf(traces) {
83
84
  * `SessionLookupType` (types/router.ts) and the resolver's layer comments.
84
85
  */
85
86
  const CLIENT_NAMED_LOOKUP_TYPES = new Set([
86
- 'explicit_header', // 1. x-session-id / x-conversation-id / router_options.session_id
87
+ 'explicit_header', // 1. x-session-id / x-session-affinity / session_id / router_options.session_id
87
88
  'embedded_user_id', // 2. Claude Code metadata.user_id → cc_<uuid>
88
89
  'request_user', // 3. RETIRED — bare OpenAI request.user, still read for pre-removal trace rows
89
90
  'header_fallback', // 9. vendor x-<app>-session-id rename of a fresh mint
@@ -104,17 +105,21 @@ export function sessionIdSourceOf(traces, birthLookupType) {
104
105
  return CLIENT_NAMED_LOOKUP_TYPES.has(lookup) ? 'client' : 'gateway';
105
106
  }
106
107
  /**
107
- * Operator label for a bound credential, matched against the serving
108
- * provider's LIVE registry chain at serialization time. The session entity
109
- * persists only the display-safe `boundKeyHashPrefix` (ADR-0002 §3); labels
110
- * are credential-store metadata that can be renamed without touching any
111
- * session, so the join happens on read. `undefined` = unnamed credential, no
112
- * chain (mock/stub or provider gone), or the credential left the chain — the
113
- * console then falls back to the prefix.
108
+ * Display identity of the credential a session is bound to, matched against the serving
109
+ * provider's LIVE registry chain at serialization time. The session entity persists only
110
+ * the display-safe `boundKeyHashPrefix` (ADR-0002 §3); labels are credential-store
111
+ * metadata that can be renamed without touching any session, so the join happens on read.
112
+ * No entry / an entry with no label = unnamed — the console then falls back to the prefix.
113
+ *
114
+ * `machineLogin` rides along because that row's NAME is fixed (the console refuses to
115
+ * rename it) and it carries no stored label, so a caller given only `label` could never
116
+ * tell "unnamed" from "this machine's login". It is detected from the marker VALUE
117
+ * (`isMachineLoginValue`) — the whole identity of that chain member — so `CallCredential`
118
+ * needs no extra field.
114
119
  */
115
- export function boundCredentialLabelOf(chain, keyHashPrefix) {
116
- if (!keyHashPrefix)
117
- return undefined;
118
- const label = chain?.find(c => c.keyHashPrefix === keyHashPrefix)?.label?.trim();
119
- return label || undefined;
120
+ export function boundCredentialOf(chain, keyHashPrefix) {
121
+ const entry = keyHashPrefix ? chain?.find((c) => c.keyHashPrefix === keyHashPrefix) : undefined;
122
+ const machineLogin = entry ? isMachineLoginValue(entry.key) : false;
123
+ const label = entry?.label?.trim();
124
+ return { ...(label ? { label } : {}), machineLogin };
120
125
  }
@@ -0,0 +1,40 @@
1
+ import type { SessionSnapshotStore } from './store.js';
2
+ import { type SnapshotBundleManifest, type SnapshotTurn } from './types.js';
3
+ /**
4
+ * Portable session handoff bundle (ADR-0038) — format `ocr-session` v1.
5
+ *
6
+ * A zip of `manifest.json` + `transcript.jsonl` (the exact per-record lines the
7
+ * store already holds) + `media/<sha256>.<ext>` for every payload the
8
+ * transcript references. Deliberately its OWN envelope, not the env book-set
9
+ * (`ocr-env`): that archive's payload whitelist is a closed two-key set and
10
+ * explicitly excludes captured/session bytes (ADR-0007), so folding a
11
+ * transcript into it would require reopening a decision that exists precisely
12
+ * to keep secrets out of a shared book-set. A session bundle carries
13
+ * conversation text, is operator-initiated per session, and never touches the
14
+ * env archive pipeline.
15
+ *
16
+ * Integrity: every payload key gets a `sha256:<hex>` in the manifest and the
17
+ * import re-verifies it byte-for-byte before writing anything — a truncated or
18
+ * tampered bundle is refused whole, never half-imported.
19
+ */
20
+ export declare const TRANSCRIPT_ENTRY = "transcript.jsonl";
21
+ export declare const MANIFEST_ENTRY = "manifest.json";
22
+ export declare class SessionBundleError extends Error {
23
+ readonly code: number;
24
+ constructor(message: string, code?: number);
25
+ }
26
+ /** Build a bundle from a stored session. Refuses an incomplete session. */
27
+ export declare function buildSessionBundle(store: SessionSnapshotStore, sessionId: string): Uint8Array;
28
+ export interface ParsedSessionBundle {
29
+ manifest: SnapshotBundleManifest;
30
+ turns: SnapshotTurn[];
31
+ media: Map<string, Uint8Array>;
32
+ }
33
+ /**
34
+ * Parse + verify a bundle. Everything is checked before the caller writes:
35
+ * manifest shape, schema match, per-entry checksums, then turn validity. A
36
+ * bundle that fails any check is refused whole.
37
+ */
38
+ export declare function parseSessionBundle(bytes: Uint8Array): ParsedSessionBundle;
39
+ /** Suggested download file name for a session bundle. */
40
+ export declare function sessionBundleName(sessionId: string): string;
@@ -0,0 +1,177 @@
1
+ import crypto from 'node:crypto';
2
+ import { strToU8, unzipSync, zipSync } from 'fflate';
3
+ import { APP_VERSION } from '../version.js';
4
+ import { mediaKeysOf } from './media.js';
5
+ import { SNAPSHOT_BUNDLE_FORMAT, SNAPSHOT_BUNDLE_VERSION, SNAPSHOT_SCHEMA, } from './types.js';
6
+ /**
7
+ * Portable session handoff bundle (ADR-0038) — format `ocr-session` v1.
8
+ *
9
+ * A zip of `manifest.json` + `transcript.jsonl` (the exact per-record lines the
10
+ * store already holds) + `media/<sha256>.<ext>` for every payload the
11
+ * transcript references. Deliberately its OWN envelope, not the env book-set
12
+ * (`ocr-env`): that archive's payload whitelist is a closed two-key set and
13
+ * explicitly excludes captured/session bytes (ADR-0007), so folding a
14
+ * transcript into it would require reopening a decision that exists precisely
15
+ * to keep secrets out of a shared book-set. A session bundle carries
16
+ * conversation text, is operator-initiated per session, and never touches the
17
+ * env archive pipeline.
18
+ *
19
+ * Integrity: every payload key gets a `sha256:<hex>` in the manifest and the
20
+ * import re-verifies it byte-for-byte before writing anything — a truncated or
21
+ * tampered bundle is refused whole, never half-imported.
22
+ */
23
+ export const TRANSCRIPT_ENTRY = 'transcript.jsonl';
24
+ export const MANIFEST_ENTRY = 'manifest.json';
25
+ const MEDIA_PREFIX = 'media/';
26
+ const MAX_ENTRY_BYTES = 32 * 1024 * 1024;
27
+ const MAX_TOTAL_BYTES = 128 * 1024 * 1024;
28
+ const sha256Entry = (text) => 'sha256:' + crypto.createHash('sha256').update(strToU8(text)).digest('hex');
29
+ const sha256Bytes = (bytes) => 'sha256:' + crypto.createHash('sha256').update(bytes).digest('hex');
30
+ export class SessionBundleError extends Error {
31
+ code;
32
+ constructor(message, code = 400) {
33
+ super(message);
34
+ this.code = code;
35
+ }
36
+ }
37
+ /** Build a bundle from a stored session. Refuses an incomplete session. */
38
+ export function buildSessionBundle(store, sessionId) {
39
+ const snap = store.read(sessionId);
40
+ if (!snap || !snap.turns.length) {
41
+ throw new SessionBundleError(`Session '${sessionId}' has no snapshot transcript`, 404);
42
+ }
43
+ if (snap.incomplete) {
44
+ // A cap-halted session is NOT exportable: its transcript stops mid-turn, so
45
+ // replaying it would either fail upstream or silently drop a step. Say so
46
+ // instead of shipping a broken conversation.
47
+ throw new SessionBundleError(`Session '${sessionId}' is incomplete (${snap.incomplete.reason} at turn ${snap.incomplete.turnIndex ?? 'none'}) — it cannot be exported as a faithful transcript`, 409);
48
+ }
49
+ const transcript = snap.turns.map((t) => JSON.stringify(t)).join('\n') + '\n';
50
+ const entries = { [TRANSCRIPT_ENTRY]: strToU8(transcript) };
51
+ const checksums = { [TRANSCRIPT_ENTRY]: sha256Entry(transcript) };
52
+ // Collect every media key referenced across the whole transcript.
53
+ const keys = new Set();
54
+ for (const turn of snap.turns)
55
+ for (const k of mediaKeysOf(turn.media))
56
+ keys.add(k);
57
+ let mediaCount = 0;
58
+ for (const key of keys) {
59
+ const raw = store.readMediaByKey(key);
60
+ if (!raw)
61
+ continue; // payload evicted by the sweep — the transcript still references it, import will surface the gap
62
+ const name = MEDIA_PREFIX + key;
63
+ const body = new Uint8Array(raw);
64
+ entries[name] = body;
65
+ checksums[name] = sha256Bytes(body);
66
+ mediaCount++;
67
+ }
68
+ const manifest = {
69
+ format: SNAPSHOT_BUNDLE_FORMAT,
70
+ version: SNAPSHOT_BUNDLE_VERSION,
71
+ schema: SNAPSHOT_SCHEMA,
72
+ sessionId,
73
+ exportedAt: new Date().toISOString(),
74
+ appVersion: APP_VERSION,
75
+ turns: snap.turns.length,
76
+ media: mediaCount,
77
+ checksums,
78
+ };
79
+ entries[MANIFEST_ENTRY] = strToU8(JSON.stringify(manifest, null, 2));
80
+ return zipSync(entries, { level: 6 });
81
+ }
82
+ /**
83
+ * Parse + verify a bundle. Everything is checked before the caller writes:
84
+ * manifest shape, schema match, per-entry checksums, then turn validity. A
85
+ * bundle that fails any check is refused whole.
86
+ */
87
+ export function parseSessionBundle(bytes) {
88
+ if (bytes.byteLength > MAX_TOTAL_BYTES) {
89
+ throw new SessionBundleError(`Session bundle exceeds the ${Math.round(MAX_TOTAL_BYTES / 1024 / 1024)} MB limit`, 413);
90
+ }
91
+ let files;
92
+ try {
93
+ files = unzipSync(bytes);
94
+ }
95
+ catch {
96
+ throw new SessionBundleError('Session bundle is not a readable zip', 400);
97
+ }
98
+ const manifestRaw = files[MANIFEST_ENTRY];
99
+ const transcriptRaw = files[TRANSCRIPT_ENTRY];
100
+ if (!manifestRaw || !transcriptRaw) {
101
+ throw new SessionBundleError(`Session bundle must contain ${MANIFEST_ENTRY} and ${TRANSCRIPT_ENTRY}`, 400);
102
+ }
103
+ let manifest;
104
+ try {
105
+ manifest = JSON.parse(Buffer.from(manifestRaw).toString('utf8'));
106
+ }
107
+ catch {
108
+ throw new SessionBundleError(`${MANIFEST_ENTRY} is not valid JSON`, 400);
109
+ }
110
+ if (manifest?.format !== SNAPSHOT_BUNDLE_FORMAT) {
111
+ throw new SessionBundleError(`Not an ${SNAPSHOT_BUNDLE_FORMAT} bundle (format=${String(manifest?.format)})`, 400);
112
+ }
113
+ if (manifest.version > SNAPSHOT_BUNDLE_VERSION) {
114
+ throw new SessionBundleError(`Session bundle version ${manifest.version} is newer than this build supports`, 400);
115
+ }
116
+ if (manifest.schema !== SNAPSHOT_SCHEMA) {
117
+ throw new SessionBundleError(`Session bundle schema ${String(manifest.schema)} is not supported (expected ${SNAPSHOT_SCHEMA})`, 400);
118
+ }
119
+ // Verify checksums for every declared entry, and refuse unknown entries so a
120
+ // bundle cannot smuggle files past the whitelist (mirrors the env-archive
121
+ // import guard's spirit).
122
+ const declared = manifest.checksums ?? {};
123
+ for (const [name, checksum] of Object.entries(declared)) {
124
+ const body = files[name];
125
+ if (!body)
126
+ throw new SessionBundleError(`Session bundle is missing a declared entry '${name}'`, 400);
127
+ if (body.byteLength > MAX_ENTRY_BYTES)
128
+ throw new SessionBundleError(`Session bundle entry '${name}' is too large`, 413);
129
+ if (sha256Bytes(body) !== checksum) {
130
+ throw new SessionBundleError(`Session bundle entry '${name}' failed its checksum — truncated or tampered`, 400);
131
+ }
132
+ }
133
+ for (const name of Object.keys(files)) {
134
+ if (name === MANIFEST_ENTRY || name === TRANSCRIPT_ENTRY)
135
+ continue;
136
+ if (!declared[name])
137
+ throw new SessionBundleError(`Session bundle carries an undeclared entry '${name}'`, 400);
138
+ if (!name.startsWith(MEDIA_PREFIX))
139
+ throw new SessionBundleError(`Session bundle entry '${name}' is outside the whitelist`, 400);
140
+ }
141
+ const turns = [];
142
+ for (const line of Buffer.from(transcriptRaw).toString('utf8').split(/\r?\n/)) {
143
+ const trimmed = line.trim();
144
+ if (!trimmed)
145
+ continue;
146
+ let parsed;
147
+ try {
148
+ parsed = JSON.parse(trimmed);
149
+ }
150
+ catch {
151
+ throw new SessionBundleError('Transcript contains a malformed line', 400);
152
+ }
153
+ const t = parsed;
154
+ if (t?.kind !== 'turn' || t.schema !== SNAPSHOT_SCHEMA || typeof t.sessionId !== 'string') {
155
+ throw new SessionBundleError('Transcript contains an invalid turn record', 400);
156
+ }
157
+ turns.push(t);
158
+ }
159
+ if (!turns.length)
160
+ throw new SessionBundleError('Transcript carries no turns', 400);
161
+ if (manifest.turns !== turns.length) {
162
+ throw new SessionBundleError(`Manifest declares ${manifest.turns} turns but the transcript carries ${turns.length}`, 400);
163
+ }
164
+ const media = new Map();
165
+ for (const name of Object.keys(declared)) {
166
+ if (!name.startsWith(MEDIA_PREFIX))
167
+ continue;
168
+ media.set(name.slice(MEDIA_PREFIX.length), files[name]);
169
+ }
170
+ return { manifest, turns, media };
171
+ }
172
+ /** Suggested download file name for a session bundle. */
173
+ export function sessionBundleName(sessionId) {
174
+ const safe = sessionId.replace(/[^\w.@:-]/g, '_').slice(0, 80) || 'session';
175
+ const today = new Date().toISOString().slice(0, 10).replace(/-/g, '');
176
+ return `${safe}-${today}.ocr_session.zip`;
177
+ }
@@ -0,0 +1,46 @@
1
+ import type { HandoffTranscript } from './transcript.js';
2
+ /**
3
+ * Handoff modes (ADR-0039 §8).
4
+ *
5
+ * `fork` keeps every stored part verbatim — the target receives a true branch
6
+ * of the conversation. `compact` is the agent-client semantics: a MODEL reads
7
+ * the conversation and writes a structured handoff summary that replaces it
8
+ * (`summarize.ts`); this module supplies the input bounding for that call.
9
+ * `trim` is the mechanical compression applied to the neutral transcript
10
+ * before any writer runs: zero model calls, deterministic (same input → same
11
+ * file), and honest about what it removes (omission placeholders stay in the
12
+ * text stream).
13
+ *
14
+ * Trim rules (each one targets bulk that carries no continuation value):
15
+ * - `thinking` parts are dropped — reasoning is neither reproducible nor
16
+ * resendable (clients never resend prior thinking), so it only inflates.
17
+ * - `image` parts become a `[image omitted]` text placeholder — the count of
18
+ * attachments stays visible, the base64 payload does not travel.
19
+ * - `toolResult` text is truncated to the limit with a marker naming the
20
+ * original size. The message SHELL (toolCallId / toolName / isError) is
21
+ * always kept so the call/result pairing stays valid.
22
+ * - `toolCall` parts, user/assistant/system text, and message order are kept
23
+ * verbatim — that is the narrative being handed off.
24
+ */
25
+ export type HandoffMode = 'fork' | 'compact' | 'trim';
26
+ export interface CompressionStats {
27
+ thinkingParts: number;
28
+ imageParts: number;
29
+ truncatedToolResults: number;
30
+ /** JSON size of the message list before/after, for the console's "-X%" line. */
31
+ charsBefore: number;
32
+ charsAfter: number;
33
+ }
34
+ /**
35
+ * Tool results longer than this are cut with a size marker. The trim MODE uses
36
+ * the small limit (bulk is what it exists to remove); the compact mode's
37
+ * summarizer-input pass uses a larger one, because the model can still mine
38
+ * detail out of a long result that a target client would merely re-read.
39
+ */
40
+ export declare const TRIM_TOOL_RESULT_LIMIT = 500;
41
+ export declare function compressTranscript(t: HandoffTranscript, opts?: {
42
+ toolResultLimit?: number;
43
+ }): {
44
+ transcript: HandoffTranscript;
45
+ stats: CompressionStats;
46
+ };
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Tool results longer than this are cut with a size marker. The trim MODE uses
3
+ * the small limit (bulk is what it exists to remove); the compact mode's
4
+ * summarizer-input pass uses a larger one, because the model can still mine
5
+ * detail out of a long result that a target client would merely re-read.
6
+ */
7
+ export const TRIM_TOOL_RESULT_LIMIT = 500;
8
+ const OMITTED_IMAGE = '[image omitted]';
9
+ function truncateToolText(text, limit) {
10
+ if (text.length <= limit)
11
+ return { text, truncated: false };
12
+ return {
13
+ text: `${text.slice(0, limit)}\n…[truncated, ${text.length} chars total]`,
14
+ truncated: true,
15
+ };
16
+ }
17
+ export function compressTranscript(t, opts = {}) {
18
+ const limit = opts.toolResultLimit ?? TRIM_TOOL_RESULT_LIMIT;
19
+ let thinkingParts = 0;
20
+ let imageParts = 0;
21
+ let truncatedToolResults = 0;
22
+ const charsBefore = JSON.stringify(t.messages).length;
23
+ const messages = [];
24
+ for (const msg of t.messages) {
25
+ const content = [];
26
+ let resultTruncated = false;
27
+ for (const part of msg.content) {
28
+ switch (part.type) {
29
+ case 'thinking':
30
+ thinkingParts++;
31
+ break;
32
+ case 'image':
33
+ imageParts++;
34
+ content.push({ type: 'text', text: OMITTED_IMAGE });
35
+ break;
36
+ case 'text': {
37
+ if (msg.role === 'toolResult') {
38
+ const cut = truncateToolText(part.text, limit);
39
+ if (cut.truncated)
40
+ resultTruncated = true;
41
+ content.push({ type: 'text', text: cut.text });
42
+ }
43
+ else if (part.text) {
44
+ content.push(part);
45
+ }
46
+ break;
47
+ }
48
+ case 'toolCall':
49
+ content.push(part);
50
+ break;
51
+ }
52
+ }
53
+ if (resultTruncated)
54
+ truncatedToolResults++;
55
+ if (!content.length) {
56
+ // A message that was ONLY thinking disappears entirely. An emptied
57
+ // toolResult keeps a shell — dropping it would orphan the tool call.
58
+ if (msg.role === 'toolResult') {
59
+ content.push({ type: 'text', text: '[result omitted]' });
60
+ }
61
+ else {
62
+ continue;
63
+ }
64
+ }
65
+ messages.push({ ...msg, content });
66
+ }
67
+ return {
68
+ transcript: { ...t, messages },
69
+ stats: {
70
+ thinkingParts,
71
+ imageParts,
72
+ truncatedToolResults,
73
+ charsBefore,
74
+ charsAfter: JSON.stringify(messages).length,
75
+ },
76
+ };
77
+ }