omnicell-router 0.8.4 → 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 (363) hide show
  1. package/README.md +26 -7
  2. package/README.zh-CN.md +18 -5
  3. package/backend/dist/capture/recorder.d.ts +4 -10
  4. package/backend/dist/capture/recorder.js +6 -58
  5. package/backend/dist/cli/clients/base.d.ts +36 -11
  6. package/backend/dist/cli/clients/base.js +31 -15
  7. package/backend/dist/cli/clients/claude.d.ts +9 -0
  8. package/backend/dist/cli/clients/claude.js +6 -0
  9. package/backend/dist/cli/clients/codex.d.ts +8 -0
  10. package/backend/dist/cli/clients/codex.js +5 -0
  11. package/backend/dist/cli/clients/core-adapters.d.ts +1 -1
  12. package/backend/dist/cli/clients/core-adapters.js +1 -1
  13. package/backend/dist/cli/clients/dsh.d.ts +8 -0
  14. package/backend/dist/cli/clients/dsh.js +5 -0
  15. package/backend/dist/cli/clients/grok.d.ts +15 -1
  16. package/backend/dist/cli/clients/grok.js +16 -2
  17. package/backend/dist/cli/clients/index.d.ts +13 -1
  18. package/backend/dist/cli/clients/index.js +97 -19
  19. package/backend/dist/cli/clients/kimi.d.ts +6 -0
  20. package/backend/dist/cli/clients/kimi.js +3 -0
  21. package/backend/dist/cli/clients/launcher.d.ts +1 -1
  22. package/backend/dist/cli/clients/model-meta.js +6 -3
  23. package/backend/dist/cli/clients/omp.d.ts +6 -0
  24. package/backend/dist/cli/clients/omp.js +3 -0
  25. package/backend/dist/cli/clients/openclaw.d.ts +6 -0
  26. package/backend/dist/cli/clients/openclaw.js +3 -0
  27. package/backend/dist/cli/clients/opencode.d.ts +8 -0
  28. package/backend/dist/cli/clients/opencode.js +5 -0
  29. package/backend/dist/cli/clients/pi.d.ts +6 -0
  30. package/backend/dist/cli/clients/pi.js +3 -0
  31. package/backend/dist/cli/clients/update-check.d.ts +37 -0
  32. package/backend/dist/cli/clients/update-check.js +309 -0
  33. package/backend/dist/cli/clients/workbuddy.d.ts +19 -0
  34. package/backend/dist/cli/clients/workbuddy.js +66 -0
  35. package/backend/dist/cli/index.js +5 -4
  36. package/backend/dist/cli/paths.js +8 -0
  37. package/backend/dist/cli/types.d.ts +92 -16
  38. package/backend/dist/config/comments-en.js +31 -26
  39. package/backend/dist/config/comments-zh.js +29 -24
  40. package/backend/dist/config/defaults.d.ts +194 -33
  41. package/backend/dist/config/defaults.js +193 -32
  42. package/backend/dist/config/env.d.ts +10 -0
  43. package/backend/dist/config/env.js +3 -2
  44. package/backend/dist/config/index.d.ts +7 -0
  45. package/backend/dist/config/index.js +184 -43
  46. package/backend/dist/config/migrations/v0-to-v1.d.ts +2 -2
  47. package/backend/dist/config/migrations/v10-to-v11.d.ts +38 -0
  48. package/backend/dist/config/migrations/v10-to-v11.js +43 -0
  49. package/backend/dist/config/migrations/v6-to-v7.d.ts +45 -0
  50. package/backend/dist/config/migrations/v6-to-v7.js +97 -0
  51. package/backend/dist/config/migrations/v7-to-v8.d.ts +36 -0
  52. package/backend/dist/config/migrations/v7-to-v8.js +43 -0
  53. package/backend/dist/config/migrations/v8-to-v9.d.ts +38 -0
  54. package/backend/dist/config/migrations/v8-to-v9.js +43 -0
  55. package/backend/dist/config/migrations/v9-to-v10.d.ts +51 -0
  56. package/backend/dist/config/migrations/v9-to-v10.js +71 -0
  57. package/backend/dist/config/runtime.js +1 -1
  58. package/backend/dist/config/schema.d.ts +3 -3
  59. package/backend/dist/config/schema.js +14 -4
  60. package/backend/dist/config/types.d.ts +167 -38
  61. package/backend/dist/egress-proxy/asset-download.d.ts +54 -0
  62. package/backend/dist/egress-proxy/asset-download.js +420 -0
  63. package/backend/dist/egress-proxy/manual-node-spec.d.ts +92 -0
  64. package/backend/dist/egress-proxy/manual-node-spec.js +408 -0
  65. package/backend/dist/egress-proxy/mihomo-binary.d.ts +54 -0
  66. package/backend/dist/egress-proxy/mihomo-binary.js +278 -0
  67. package/backend/dist/egress-proxy/mihomo-client.d.ts +94 -0
  68. package/backend/dist/egress-proxy/mihomo-client.js +308 -0
  69. package/backend/dist/egress-proxy/mihomo-config.d.ts +40 -0
  70. package/backend/dist/egress-proxy/mihomo-config.js +161 -0
  71. package/backend/dist/egress-proxy/mihomo-geo.d.ts +87 -0
  72. package/backend/dist/egress-proxy/mihomo-geo.js +213 -0
  73. package/backend/dist/egress-proxy/mihomo-logs.d.ts +43 -0
  74. package/backend/dist/egress-proxy/mihomo-logs.js +84 -0
  75. package/backend/dist/egress-proxy/mihomo-pac.d.ts +37 -0
  76. package/backend/dist/egress-proxy/mihomo-pac.js +75 -0
  77. package/backend/dist/egress-proxy/mihomo-rules-import.d.ts +43 -0
  78. package/backend/dist/egress-proxy/mihomo-rules-import.js +193 -0
  79. package/backend/dist/egress-proxy/mihomo-sidecar.d.ts +81 -0
  80. package/backend/dist/egress-proxy/mihomo-sidecar.js +637 -0
  81. package/backend/dist/forward-proxy/egress.d.ts +50 -11
  82. package/backend/dist/forward-proxy/egress.js +50 -17
  83. package/backend/dist/forward-proxy/h2-forward.js +36 -10
  84. package/backend/dist/forward-proxy/index.d.ts +11 -8
  85. package/backend/dist/forward-proxy/index.js +22 -60
  86. package/backend/dist/forward-proxy/interceptor.d.ts +3 -2
  87. package/backend/dist/forward-proxy/interceptor.js +4 -4
  88. package/backend/dist/forward-proxy/relay.js +3 -3
  89. package/backend/dist/forward-proxy/rules.d.ts +4 -4
  90. package/backend/dist/forward-proxy/rules.js +25 -4
  91. package/backend/dist/forward-proxy/server.d.ts +0 -16
  92. package/backend/dist/forward-proxy/server.js +124 -156
  93. package/backend/dist/harness/host/hosts.js +3 -2
  94. package/backend/dist/index.js +53 -18
  95. package/backend/dist/ingress-proxy/access-log.d.ts +176 -0
  96. package/backend/dist/ingress-proxy/access-log.js +774 -0
  97. package/backend/dist/ingress-proxy/ca-inventory.d.ts +106 -0
  98. package/backend/dist/ingress-proxy/ca-inventory.js +525 -0
  99. package/backend/dist/ingress-proxy/ca-trust.d.ts +96 -0
  100. package/backend/dist/ingress-proxy/ca-trust.js +315 -0
  101. package/backend/dist/ingress-proxy/ca.d.ts +104 -0
  102. package/backend/dist/ingress-proxy/ca.js +273 -0
  103. package/backend/dist/ingress-proxy/data-dir.d.ts +28 -0
  104. package/backend/dist/ingress-proxy/data-dir.js +45 -0
  105. package/backend/dist/ingress-proxy/egress.d.ts +151 -0
  106. package/backend/dist/ingress-proxy/egress.js +364 -0
  107. package/backend/dist/ingress-proxy/h2-forward.d.ts +66 -0
  108. package/backend/dist/ingress-proxy/h2-forward.js +561 -0
  109. package/backend/dist/ingress-proxy/index.d.ts +24 -0
  110. package/backend/dist/ingress-proxy/index.js +144 -0
  111. package/backend/dist/ingress-proxy/interceptor.d.ts +25 -0
  112. package/backend/dist/ingress-proxy/interceptor.js +52 -0
  113. package/backend/dist/ingress-proxy/ordered-relay.d.ts +29 -0
  114. package/backend/dist/ingress-proxy/ordered-relay.js +46 -0
  115. package/backend/dist/ingress-proxy/relay.d.ts +54 -0
  116. package/backend/dist/ingress-proxy/relay.js +188 -0
  117. package/backend/dist/ingress-proxy/rules.d.ts +195 -0
  118. package/backend/dist/ingress-proxy/rules.js +348 -0
  119. package/backend/dist/ingress-proxy/server.d.ts +153 -0
  120. package/backend/dist/ingress-proxy/server.js +2065 -0
  121. package/backend/dist/ingress-proxy/sni.d.ts +35 -0
  122. package/backend/dist/ingress-proxy/sni.js +124 -0
  123. package/backend/dist/ingress-proxy/status.d.ts +32 -0
  124. package/backend/dist/ingress-proxy/status.js +15 -0
  125. package/backend/dist/ingress-proxy/system-proxy.d.ts +112 -0
  126. package/backend/dist/ingress-proxy/system-proxy.js +481 -0
  127. package/backend/dist/ingress-proxy/traffic-delete.d.ts +21 -0
  128. package/backend/dist/ingress-proxy/traffic-delete.js +64 -0
  129. package/backend/dist/ingress-proxy/traffic-delete.worker.d.ts +44 -0
  130. package/backend/dist/ingress-proxy/traffic-delete.worker.js +228 -0
  131. package/backend/dist/ingress-proxy/traffic-files.d.ts +10 -0
  132. package/backend/dist/ingress-proxy/traffic-files.js +10 -0
  133. package/backend/dist/ingress-proxy/upstream-tls.d.ts +46 -0
  134. package/backend/dist/ingress-proxy/upstream-tls.js +105 -0
  135. package/backend/dist/ingress-proxy/ws-frames.d.ts +45 -0
  136. package/backend/dist/ingress-proxy/ws-frames.js +153 -0
  137. package/backend/dist/ir/adapters/anthropic-messages-stream.js +6 -1
  138. package/backend/dist/ir/adapters/anthropic-messages.js +12 -5
  139. package/backend/dist/ir/adapters/google-gemini-stream.js +7 -2
  140. package/backend/dist/ir/adapters/google-gemini.js +5 -2
  141. package/backend/dist/ir/adapters/openai-chat-stream.js +5 -1
  142. package/backend/dist/ir/adapters/openai-chat.d.ts +25 -0
  143. package/backend/dist/ir/adapters/openai-chat.js +45 -3
  144. package/backend/dist/ir/adapters/openai-responses-output.d.ts +1 -0
  145. package/backend/dist/ir/adapters/openai-responses-output.js +67 -21
  146. package/backend/dist/ir/adapters/openai-responses-stream.d.ts +13 -0
  147. package/backend/dist/ir/adapters/openai-responses-stream.js +34 -1
  148. package/backend/dist/ir/adapters/openai-responses.d.ts +82 -24
  149. package/backend/dist/ir/adapters/openai-responses.js +146 -37
  150. package/backend/dist/ir/media.d.ts +20 -0
  151. package/backend/dist/ir/media.js +41 -0
  152. package/backend/dist/ir/tool-identity.d.ts +35 -0
  153. package/backend/dist/ir/tool-identity.js +40 -0
  154. package/backend/dist/ir/types.d.ts +9 -1
  155. package/backend/dist/local/build-jobs.d.ts +66 -0
  156. package/backend/dist/local/build-jobs.js +243 -0
  157. package/backend/dist/local/detect.d.ts +32 -0
  158. package/backend/dist/local/detect.js +145 -0
  159. package/backend/dist/local/draft-match.d.ts +58 -0
  160. package/backend/dist/local/draft-match.js +124 -0
  161. package/backend/dist/local/engine-runtime.d.ts +522 -0
  162. package/backend/dist/local/engine-runtime.js +1 -0
  163. package/backend/dist/local/engines.d.ts +241 -0
  164. package/backend/dist/local/engines.js +651 -0
  165. package/backend/dist/local/gguf.d.ts +35 -0
  166. package/backend/dist/local/gguf.js +314 -0
  167. package/backend/dist/local/hf.d.ts +120 -0
  168. package/backend/dist/local/hf.js +304 -0
  169. package/backend/dist/local/install.d.ts +90 -0
  170. package/backend/dist/local/install.js +421 -0
  171. package/backend/dist/local/llamacpp.d.ts +55 -0
  172. package/backend/dist/local/llamacpp.js +177 -0
  173. package/backend/dist/local/local-provider.d.ts +81 -0
  174. package/backend/dist/local/local-provider.js +301 -0
  175. package/backend/dist/local/machine-stats.d.ts +87 -0
  176. package/backend/dist/local/machine-stats.js +332 -0
  177. package/backend/dist/local/model-store.d.ts +347 -0
  178. package/backend/dist/local/model-store.js +1215 -0
  179. package/backend/dist/local/part-sweep.d.ts +32 -0
  180. package/backend/dist/local/part-sweep.js +156 -0
  181. package/backend/dist/local/plan.d.ts +65 -0
  182. package/backend/dist/local/plan.js +146 -0
  183. package/backend/dist/local/resources.d.ts +49 -0
  184. package/backend/dist/local/resources.js +64 -0
  185. package/backend/dist/local/run-stats.d.ts +95 -0
  186. package/backend/dist/local/run-stats.js +195 -0
  187. package/backend/dist/local/runner.d.ts +235 -0
  188. package/backend/dist/local/runner.js +1392 -0
  189. package/backend/dist/local/settings.d.ts +79 -0
  190. package/backend/dist/local/settings.js +180 -0
  191. package/backend/dist/local/strata-catalog.d.ts +30 -0
  192. package/backend/dist/local/strata-catalog.js +511 -0
  193. package/backend/dist/local/strata-drafting.d.ts +46 -0
  194. package/backend/dist/local/strata-drafting.js +265 -0
  195. package/backend/dist/local/strata.d.ts +278 -0
  196. package/backend/dist/local/strata.js +1392 -0
  197. package/backend/dist/local/tar.d.ts +20 -0
  198. package/backend/dist/local/tar.js +367 -0
  199. package/backend/dist/local/transport.d.ts +35 -0
  200. package/backend/dist/local/transport.js +89 -0
  201. package/backend/dist/local/tune.d.ts +58 -0
  202. package/backend/dist/local/tune.js +324 -0
  203. package/backend/dist/observability/http-exchange.d.ts +2 -2
  204. package/backend/dist/opencode/catalog/auto-pull.d.ts +14 -3
  205. package/backend/dist/opencode/catalog/auto-pull.js +276 -70
  206. package/backend/dist/opencode/catalog/ocr-store.js +3 -1
  207. package/backend/dist/opencode/catalog/overrides-store.d.ts +10 -1
  208. package/backend/dist/opencode/catalog/overrides-store.js +6 -0
  209. package/backend/dist/opencode/catalog/reasoning-declaration.d.ts +35 -0
  210. package/backend/dist/opencode/catalog/reasoning-declaration.js +66 -0
  211. package/backend/dist/opencode/catalog/repository.js +25 -2
  212. package/backend/dist/opencode/catalog/sources/models-dev.js +13 -3
  213. package/backend/dist/opencode/catalog/types.d.ts +35 -3
  214. package/backend/dist/opencode/catalog/types.js +38 -1
  215. package/backend/dist/opencode/credentials/ocr-store.js +11 -2
  216. package/backend/dist/opencode/credentials/sync.js +12 -3
  217. package/backend/dist/opencode/credentials/types.d.ts +31 -4
  218. package/backend/dist/opencode/credentials/types.js +25 -0
  219. package/backend/dist/opencode/probe.d.ts +21 -4
  220. package/backend/dist/opencode/probe.js +34 -10
  221. package/backend/dist/pipeline/directives.d.ts +9 -4
  222. package/backend/dist/pipeline/directives.js +14 -10
  223. package/backend/dist/pipeline/orchestrator.d.ts +42 -13
  224. package/backend/dist/pipeline/orchestrator.js +497 -165
  225. package/backend/dist/plugins/environment-ack.d.ts +51 -0
  226. package/backend/dist/plugins/environment-ack.js +81 -0
  227. package/backend/dist/plugins/gateways.d.ts +6 -6
  228. package/backend/dist/plugins/gateways.js +2 -2
  229. package/backend/dist/plugins/host.d.ts +98 -14
  230. package/backend/dist/plugins/host.js +622 -87
  231. package/backend/dist/plugins/install-run.d.ts +27 -0
  232. package/backend/dist/plugins/install-run.js +99 -0
  233. package/backend/dist/plugins/manifest.d.ts +84 -32
  234. package/backend/dist/plugins/manifest.js +149 -45
  235. package/backend/dist/plugins/market-install.d.ts +18 -0
  236. package/backend/dist/plugins/market-install.js +111 -0
  237. package/backend/dist/plugins/market-source.d.ts +100 -0
  238. package/backend/dist/plugins/market-source.js +449 -0
  239. package/backend/dist/plugins/market-updates.d.ts +70 -0
  240. package/backend/dist/plugins/market-updates.js +97 -0
  241. package/backend/dist/plugins/market.d.ts +677 -0
  242. package/backend/dist/plugins/market.js +2113 -0
  243. package/backend/dist/plugins/source-index.d.ts +155 -0
  244. package/backend/dist/plugins/source-index.js +217 -0
  245. package/backend/dist/plugins/types.d.ts +402 -37
  246. package/backend/dist/projects/worktrees.d.ts +88 -0
  247. package/backend/dist/projects/worktrees.js +220 -0
  248. package/backend/dist/providers/boot-direct.d.ts +41 -7
  249. package/backend/dist/providers/boot-direct.js +252 -36
  250. package/backend/dist/providers/compat/tool-markup-recovery.js +31 -6
  251. package/backend/dist/providers/executors/dispatch.d.ts +17 -7
  252. package/backend/dist/providers/executors/dispatch.js +28 -9
  253. package/backend/dist/providers/executors/openai-chat.js +14 -2
  254. package/backend/dist/providers/executors/plugin-adapter.d.ts +23 -1
  255. package/backend/dist/providers/executors/plugin-adapter.js +59 -3
  256. package/backend/dist/providers/member-match.d.ts +32 -9
  257. package/backend/dist/providers/member-match.js +65 -21
  258. package/backend/dist/providers/model-resolution.d.ts +62 -0
  259. package/backend/dist/providers/model-resolution.js +62 -0
  260. package/backend/dist/providers/price-order.d.ts +51 -0
  261. package/backend/dist/providers/price-order.js +54 -0
  262. package/backend/dist/providers/provider-takedown.d.ts +5 -2
  263. package/backend/dist/providers/registry.d.ts +84 -25
  264. package/backend/dist/providers/registry.js +209 -114
  265. package/backend/dist/providers/selection.d.ts +91 -0
  266. package/backend/dist/providers/selection.js +158 -0
  267. package/backend/dist/providers/virtual-meta.d.ts +33 -2
  268. package/backend/dist/providers/virtual-meta.js +74 -18
  269. package/backend/dist/quota/cli-login.d.ts +25 -4
  270. package/backend/dist/quota/cli-login.js +35 -5
  271. package/backend/dist/quota/coverage-generation.d.ts +24 -0
  272. package/backend/dist/quota/coverage-generation.js +29 -0
  273. package/backend/dist/quota/declarations.js +8 -4
  274. package/backend/dist/quota/engine.js +2 -2
  275. package/backend/dist/quota/prober.d.ts +43 -2
  276. package/backend/dist/quota/prober.js +97 -22
  277. package/backend/dist/ratelimit/rate-limiter.d.ts +1 -1
  278. package/backend/dist/resilience/error-classifier.js +29 -0
  279. package/backend/dist/router/index.d.ts +1 -1
  280. package/backend/dist/router/index.js +17 -1
  281. package/backend/dist/router/layer2-decision.d.ts +1 -1
  282. package/backend/dist/router/layer2-decision.js +2 -2
  283. package/backend/dist/routes/console.js +928 -310
  284. package/backend/dist/routes/environments.js +1 -1
  285. package/backend/dist/routes/local-models.d.ts +2 -0
  286. package/backend/dist/routes/local-models.js +1414 -0
  287. package/backend/dist/routes/mihomo.d.ts +2 -2
  288. package/backend/dist/routes/mihomo.js +20 -11
  289. package/backend/dist/routes/projects.js +121 -0
  290. package/backend/dist/server.js +318 -13
  291. package/backend/dist/session/session-manager.d.ts +42 -5
  292. package/backend/dist/session/session-manager.js +64 -11
  293. package/backend/dist/session/session-row.d.ts +29 -8
  294. package/backend/dist/session/session-row.js +18 -13
  295. package/backend/dist/snapshot/bundle.d.ts +40 -0
  296. package/backend/dist/snapshot/bundle.js +177 -0
  297. package/backend/dist/snapshot/handoff/compress.d.ts +46 -0
  298. package/backend/dist/snapshot/handoff/compress.js +77 -0
  299. package/backend/dist/snapshot/handoff/index.d.ts +119 -0
  300. package/backend/dist/snapshot/handoff/index.js +160 -0
  301. package/backend/dist/snapshot/handoff/jsonl-writer.d.ts +78 -0
  302. package/backend/dist/snapshot/handoff/jsonl-writer.js +175 -0
  303. package/backend/dist/snapshot/handoff/opencode-writer.d.ts +51 -0
  304. package/backend/dist/snapshot/handoff/opencode-writer.js +214 -0
  305. package/backend/dist/snapshot/handoff/summarize.d.ts +39 -0
  306. package/backend/dist/snapshot/handoff/summarize.js +118 -0
  307. package/backend/dist/snapshot/handoff/transcript.d.ts +71 -0
  308. package/backend/dist/snapshot/handoff/transcript.js +167 -0
  309. package/backend/dist/snapshot/media-fs.d.ts +10 -0
  310. package/backend/dist/snapshot/media-fs.js +50 -0
  311. package/backend/dist/snapshot/media.d.ts +32 -0
  312. package/backend/dist/snapshot/media.js +87 -0
  313. package/backend/dist/snapshot/store.d.ts +226 -0
  314. package/backend/dist/snapshot/store.js +887 -0
  315. package/backend/dist/snapshot/tree.d.ts +112 -0
  316. package/backend/dist/snapshot/tree.js +207 -0
  317. package/backend/dist/snapshot/types.d.ts +212 -0
  318. package/backend/dist/snapshot/types.js +14 -0
  319. package/backend/dist/snapshot/view.d.ts +19 -0
  320. package/backend/dist/snapshot/view.js +57 -0
  321. package/backend/dist/snapshot/write-worker.d.ts +67 -0
  322. package/backend/dist/snapshot/write-worker.js +129 -0
  323. package/backend/dist/surfaces/body-admission.d.ts +67 -2
  324. package/backend/dist/surfaces/body-admission.js +218 -13
  325. package/backend/dist/surfaces/chat-pipeline.js +8 -0
  326. package/backend/dist/surfaces/decision-pipeline.js +10 -7
  327. package/backend/dist/surfaces/gateway-catalog.d.ts +26 -0
  328. package/backend/dist/surfaces/gateway-catalog.js +202 -0
  329. package/backend/dist/surfaces/gateway-chat.d.ts +7 -11
  330. package/backend/dist/surfaces/gateway-chat.js +50 -12
  331. package/backend/dist/surfaces/ocr-headers.d.ts +6 -4
  332. package/backend/dist/surfaces/ocr-headers.js +11 -7
  333. package/backend/dist/surfaces/systemone.js +1 -1
  334. package/backend/dist/surfaces/transport-fastify.js +32 -5
  335. package/backend/dist/surfaces/transport-node-http.d.ts +9 -3
  336. package/backend/dist/surfaces/transport-node-http.js +6 -19
  337. package/backend/dist/surfaces/types.d.ts +11 -3
  338. package/backend/dist/trace/persist.js +21 -1
  339. package/backend/dist/trace/tracker.d.ts +35 -3
  340. package/backend/dist/trace/tracker.js +23 -0
  341. package/backend/dist/types/openai.d.ts +8 -0
  342. package/backend/dist/types/router.d.ts +17 -6
  343. package/backend/dist/types/router.js +14 -2
  344. package/backend/dist/utils/client-families.d.ts +66 -0
  345. package/backend/dist/utils/client-families.js +127 -0
  346. package/backend/dist/utils/event-ring.d.ts +1 -1
  347. package/backend/dist/utils/event-ring.js +1 -1
  348. package/backend/dist/utils/proxy-node.js +1 -1
  349. package/backend/dist/utils/proxy.d.ts +135 -11
  350. package/backend/dist/utils/proxy.js +144 -29
  351. package/backend/dist/utils/run-command.d.ts +21 -1
  352. package/backend/dist/utils/run-command.js +64 -4
  353. package/backend/dist/utils/server-liveness.d.ts +3 -2
  354. package/backend/dist/utils/server-liveness.js +3 -2
  355. package/backend/dist/utils/session-file.d.ts +28 -0
  356. package/backend/dist/utils/session-file.js +34 -0
  357. package/frontend/dist/assets/antigravity.color-DXFfVr6X.svg +39 -0
  358. package/frontend/dist/assets/gemini-cli.color-BfquLd1p.svg +1 -0
  359. package/frontend/dist/assets/index-CTZNvn1d.js +1707 -0
  360. package/frontend/dist/assets/{index-KI1OW5x6.css → index-CqDSOPQ0.css} +1 -1
  361. package/frontend/dist/index.html +2 -2
  362. package/package.json +3 -1
  363. package/frontend/dist/assets/index-Dk76uc7e.js +0 -1522
@@ -0,0 +1,106 @@
1
+ import { type CommandRunner, type LinuxTrustStores } from './ca-trust.js';
2
+ /** Every store this inventory can enumerate. The id is a machine token — the
3
+ * console renders it through its own i18n key (`ingressProxy.caInvStore*`). */
4
+ export type CaInventoryStoreId = 'win-user-root' | 'win-machine-root' | 'darwin-login' | 'darwin-system' | 'darwin-system-roots' | 'linux-anchor' | 'linux-bundle' | 'linux-nss';
5
+ /** Why a row carries no removal command (frontend i18n key suffix). */
6
+ export type CaRemoveHint =
7
+ /** The command needs an elevated shell. */
8
+ 'elevation'
9
+ /** The occurrence is inside a regenerated bundle: remove its SOURCE anchor
10
+ * and let the distro tool re-merge. */
11
+ | 'sourceAnchor'
12
+ /** The NSS nickname is not the CN; read `certutil -L` before deleting. */
13
+ | 'nssNickname'
14
+ /** The tool's output gave us a DN but no fingerprint, so we cannot target a
15
+ * delete honestly. */
16
+ | 'noIdentity'
17
+ /** This platform offers no removal path we are willing to hand out. */
18
+ | 'unsupported';
19
+ /** Why a store produced no answer (frontend i18n key suffix). */
20
+ export type CaStoreFailure = 'toolMissing' | 'notReadable' | 'unparsed' | 'tooLarge';
21
+ /** One installed OCR root, as found in ONE store. The same certificate can
22
+ * legitimately appear in several stores (user + machine) and is reported once
23
+ * per store: removal is per store, so merging them would hide a remaining
24
+ * copy. */
25
+ export interface CaInstalledRoot {
26
+ store: CaInventoryStoreId;
27
+ /** Concrete location: a file path, an NSS db path or a keychain path. */
28
+ location: string;
29
+ /** SHA-1 of the DER body, lowercase hex, no separators. The identity the
30
+ * platform tools delete by, and the value compared against the CA on disk.
31
+ * (SHA-256 is what the console CA card shows — that is a different field on
32
+ * a different contract; never feed it to a delete command.) */
33
+ thumbprintSha1: string;
34
+ subject: string;
35
+ commonName: string;
36
+ notBefore?: string;
37
+ notAfter?: string;
38
+ /** True for the certificate this gateway signs with right now. */
39
+ isActive: boolean;
40
+ /** Platform command that removes THIS occurrence, when one is honest. */
41
+ removeCommand?: string;
42
+ /** Why `removeCommand` is absent. */
43
+ removeHint?: CaRemoveHint;
44
+ }
45
+ /** One consulted store. `skipped` = absent on this host (a Linux anchor dir on
46
+ * Windows), which is not a failure; `unreadable` = present but no answer. */
47
+ export interface CaInventoryStore {
48
+ store: CaInventoryStoreId;
49
+ location: string;
50
+ status: 'ok' | 'skipped' | 'unreadable';
51
+ reason?: CaStoreFailure;
52
+ /** First line of the tool's own error output. Diagnostic detail only — never
53
+ * a label (platform tools answer in the OS locale). */
54
+ detail?: string;
55
+ /** Certificates this store contributed to `certs`. Only meaningful on an
56
+ * `ok` store: a store that could not be read contributed nothing to count. */
57
+ matched?: number;
58
+ }
59
+ export interface CaInventoryReport {
60
+ /** `ok` when at least one store was READ; `unknown` when none could be. */
61
+ state: 'ok' | 'unknown';
62
+ platform: string;
63
+ /** Epoch ms of this detection pass. */
64
+ checkedAt: number;
65
+ /** SHA-1 of the CA on disk; null when there is no CA yet (nothing to compare
66
+ * against, so no row can be `isActive`). */
67
+ activeThumbprintSha1: string | null;
68
+ activeSubject: string | null;
69
+ certs: CaInstalledRoot[];
70
+ stores: CaInventoryStore[];
71
+ /** True when the row cap (`MAX_ROWS`) cut the list short: the console says so
72
+ * instead of presenting a partial list as the whole truth. */
73
+ truncated: boolean;
74
+ }
75
+ export interface CaInventoryOptions {
76
+ /** Operator override + `OCR_CA_DIR` sandbox pin, same resolver as the proxy. */
77
+ caDir?: string;
78
+ /** Injectable for the tests only; production reads the running platform. */
79
+ platform?: NodeJS.Platform;
80
+ /** Injectable for the tests only; production reads the host's real stores. */
81
+ linuxStores?: LinuxTrustStores;
82
+ /** Injectable for the tests only; production reads this user's keychains. */
83
+ keychains?: DarwinKeychain[];
84
+ /** Injectable for the tests only. Defaults to the SAME seam the trust probe
85
+ * uses, so one `setCaTrustCommandRunner` swap covers both. */
86
+ run?: CommandRunner;
87
+ }
88
+ /**
89
+ * macOS: `security find-certificate -a -p` dumps every certificate in a
90
+ * keychain as PEM, so the comparison reuses the same DER→SHA-1 identity as every
91
+ * other platform instead of parsing `security`'s text output.
92
+ *
93
+ * Built per call (not a module constant): the login keychain path comes from
94
+ * `os.homedir()`, which a sandbox or a test can change between passes.
95
+ */
96
+ export interface DarwinKeychain {
97
+ store: CaInventoryStoreId;
98
+ location: string;
99
+ }
100
+ /**
101
+ * Enumerate every OCR root this machine's trust stores hold.
102
+ *
103
+ * One-shot and read-only. `state: 'unknown'` means NO store could be read —
104
+ * the caller must render "this pass could not run", never "nothing installed".
105
+ */
106
+ export declare function listInstalledOcrCas(opts?: CaInventoryOptions): Promise<CaInventoryReport>;
@@ -0,0 +1,525 @@
1
+ import fs from 'node:fs';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ import crypto from 'node:crypto';
5
+ import { CA_CN, defaultCaDir } from './ca.js';
6
+ import { anchorFiles, caTrustCommand, DEFAULT_LINUX_TRUST_STORES, } from './ca-trust.js';
7
+ /**
8
+ * Which OCR roots are INSTALLED in this machine's trust stores?
9
+ *
10
+ * `ca-trust.ts` answers "is the CA we sign with trusted"; it cannot answer "how
11
+ * many OCR roots are trusted". Those are different questions, and the second
12
+ * one hid a real failure: a live install carried six `OmniCellRouter*` roots in
13
+ * the user store (five orphans left behind by CA rotations) while the trust chip
14
+ * stayed green, because the chip only ever looks for ONE fingerprint. An
15
+ * orphaned root keeps its public key trusted by every verifier on the box.
16
+ *
17
+ * Detection, NOT monitoring: this is an on-demand enumeration (the console calls
18
+ * it from a button), it writes no state, schedules nothing and caches nothing —
19
+ * trust is machine state (ADR-0008), so every answer is read live.
20
+ *
21
+ * Three invariants, each of which turns the feature into a liar when broken:
22
+ *
23
+ * 1. `unknown` is a first-class answer. A store we could not read (missing
24
+ * tool, permission, an output shape we cannot parse) is reported as such,
25
+ * NEVER as an empty list — an empty list reads as "no orphans here", which
26
+ * is the same false green this module exists to remove.
27
+ * 2. An identifier is matched by FINGERPRINT, never by CN: two roots can share
28
+ * the CN (the key-derived OU in `ca.ts` exists for exactly that reason), and
29
+ * a CN witness is what produced the old `CERT_SIGNATURE_FAILURE` false
30
+ * green.
31
+ * 3. Nothing here mints or mutates a certificate. The CA on disk is READ (never
32
+ * `ensureCa`, which generates on first use): a detection pass must not
33
+ * create the artifact it is reporting on.
34
+ */
35
+ /**
36
+ * The pre-rename spelling of {@link CA_CN}. Load-bearing, not cosmetic: the
37
+ * rename is mint-time only (`ca.ts`), so a live install keeps the CN it was
38
+ * created with — the CA this gateway signs with TODAY may carry it. Dropping it
39
+ * from the allowlist would make the ACTIVE root read as a foreign certificate.
40
+ */
41
+ const LEGACY_CA_CN = 'OmniCellRouter Forward Proxy CA';
42
+ /** CNs OCR mints. A future rename adds its spelling here. */
43
+ const OCR_CA_COMMON_NAMES = [CA_CN, LEGACY_CA_CN];
44
+ /** The per-key marker `ca.ts` stamps into every minted subject (ADR-0017: one
45
+ * OU per CA key so same-subject roots stay distinguishable). */
46
+ const OCR_CA_OU_MARKER = /OU\s*=\s*CA\s+[0-9a-f]{8}/i;
47
+ /** Upper bound on reported rows; a store that somehow holds more is not a case
48
+ * worth a 10 MB console payload. */
49
+ const MAX_ROWS = 100;
50
+ /** A merged distro bundle holds every vendor root; past this the parse is a
51
+ * bug or a corrupted file, so the store is skipped rather than chewed on. */
52
+ const MAX_PEM_BLOCKS = 512;
53
+ /**
54
+ * Byte ceiling on ONE PEM file, checked BEFORE reading it. `MAX_PEM_BLOCKS`
55
+ * bounds the parse but only after the whole file is already in memory, so a
56
+ * 2 GB “bundle” (a truncated download, a device node) would still be slurped.
57
+ * The largest real bundle (Ubuntu/RHEL) is ~250 KB.
58
+ */
59
+ const MAX_PEM_FILE_BYTES = 8 * 1024 * 1024;
60
+ /** A `certutil -store` / `security find-certificate` answer past this size is
61
+ * refused. A trust store with more certificates than this is not a real host,
62
+ * and parsing it would hand a bounded report an unbounded input. */
63
+ const MAX_TOOL_STDOUT_BYTES = 4 * 1024 * 1024;
64
+ const TOOL_TIMEOUT_MS = 8000;
65
+ /**
66
+ * Is this certificate one OCR minted?
67
+ *
68
+ * The CN allowlist is the primary answer, and it is the ONLY answer for a
69
+ * certificate that carries a CN: a CA someone minted here under a custom name is
70
+ * not an OCR root, and reporting it would hand out a delete command for a
71
+ * stranger's certificate. The OU marker (`ca.ts` stamps every minted CA with
72
+ * `OU=CA <keyhash8>` so same-subject roots stay distinguishable) is consulted
73
+ * only when the subject has NO CN at all — the shape older OCR roots minted, and
74
+ * the one case where the CN allowlist has nothing to read.
75
+ */
76
+ function isOcrRoot(cert) {
77
+ if (cert.commonName.length > 0)
78
+ return OCR_CA_COMMON_NAMES.includes(cert.commonName);
79
+ return OCR_CA_OU_MARKER.test(cert.subject);
80
+ }
81
+ /** CN out of a DN string (`CN=x\nOU=y` from node, or `OU=y, CN=x` from a
82
+ * listing). Never the whole DN: the allowlist is on the CN. */
83
+ function dnCommonName(dn) {
84
+ const match = /(?:^|[,\n])\s*CN=([^,\n]+)/.exec(dn);
85
+ return match?.[1]?.trim() ?? '';
86
+ }
87
+ function isoOrUndefined(value) {
88
+ if (!value)
89
+ return undefined;
90
+ const at = new Date(value);
91
+ return Number.isNaN(at.getTime()) ? undefined : at.toISOString();
92
+ }
93
+ function pemCertificateBlocks(text) {
94
+ return text.match(/-----BEGIN CERTIFICATE-----[\s\S]*?-----END CERTIFICATE-----/g) ?? [];
95
+ }
96
+ /** Identity of one PEM certificate; null when the body does not parse. */
97
+ function inspectPem(pem) {
98
+ try {
99
+ const x509 = new crypto.X509Certificate(pem);
100
+ const subject = x509.subject.split('\n').join(', ');
101
+ return {
102
+ // SHA-1 on purpose: every platform store keys a delete on this hash
103
+ // (Windows thumbprint, macOS `-Z`). SHA-256 stays on the CA card.
104
+ thumbprintSha1: x509.fingerprint.replace(/:/g, '').toLowerCase(),
105
+ subject,
106
+ commonName: dnCommonName(subject),
107
+ notBefore: isoOrUndefined(x509.validFrom),
108
+ notAfter: isoOrUndefined(x509.validTo),
109
+ };
110
+ }
111
+ catch {
112
+ return null;
113
+ }
114
+ }
115
+ function inspectPemText(text) {
116
+ const blocks = pemCertificateBlocks(text);
117
+ const certs = [];
118
+ for (const block of blocks) {
119
+ const cert = inspectPem(block);
120
+ if (cert)
121
+ certs.push(cert);
122
+ }
123
+ return { certs, blocks: blocks.length };
124
+ }
125
+ /**
126
+ * Parse a `certutil -store Root` listing.
127
+ *
128
+ * The tool answers in the OS locale, and its labels arrive as mojibake in a
129
+ * UTF-8 pipe on a CJK Windows (verified on a zh-CN box: `证书哈希(sha1)` comes
130
+ * back as bytes no decoder recognizes). So NOTHING here matches a label. The
131
+ * two anchors are locale-independent:
132
+ * - `(sha1)` inside the hash line — the ASCII token survives, and GBK trail
133
+ * bytes are >= 0x40, so `(` / `:` can never be manufactured by mojibake;
134
+ * - `CN=` inside the subject line.
135
+ *
136
+ * Blocks are separated by a `====` rule (the label between the rules is
137
+ * localized and ignored). The SUBJECT is the LAST `CN=` line in a block — the
138
+ * issuer prints first and a self-signed root repeats the same DN twice — and the
139
+ * whole block must AGREE on that CN: a block with one CN line is a shape we do
140
+ * not understand, and guessing which DN is the subject mis-attributes a
141
+ * certificate whose name a delete command is built from.
142
+ *
143
+ * Dates are deliberately NOT parsed: `NotBefore` keeps its English label but the
144
+ * date FORMAT follows the locale (`2026/11/5` vs `11/5/2026`), and a wrong date
145
+ * is worse than an absent one.
146
+ */
147
+ function parseCertutilStore(stdout) {
148
+ const blocks = [];
149
+ let current = null;
150
+ for (const raw of stdout.split(/\r?\n/)) {
151
+ // Some locales/typeset both colons; normalize so `slice(indexOf(':'))` below
152
+ // is not off by a fullwidth character.
153
+ const line = raw.replace(/:/g, ':');
154
+ if (/^\s*={4,}/.test(line)) {
155
+ current = [];
156
+ blocks.push(current);
157
+ continue;
158
+ }
159
+ current?.push(line);
160
+ }
161
+ const certs = [];
162
+ let parsedBlocks = 0;
163
+ for (const block of blocks) {
164
+ const text = block.join('\n');
165
+ // `(sha1)` is the ASCII anchor: it survives the GBK mojibake a CJK Windows
166
+ // hands us, and it is the SUBJECT's hash line. A block WITHOUT one is a
167
+ // listing whose shape we no longer understand — that, and only that, is what
168
+ // makes a store `unparsed`.
169
+ const thumbprintSha1 = /\(sha1\)\s*:\s*([0-9a-f]{40})/i.exec(text)?.[1]?.toLowerCase();
170
+ if (!thumbprintSha1)
171
+ continue;
172
+ parsedBlocks += 1;
173
+ // `certutil` prints the ISSUER line before the SUBJECT line, so the SUBJECT
174
+ // is the LAST line carrying an RDN. Two CN lines that DIFFER are the normal
175
+ // shape of a non-self-signed root — every public root in the store looks like
176
+ // that — so disagreement is expected and the last one wins. Treating
177
+ // disagreement as "unparseable" made every Windows machine store unreadable
178
+ // on the first real run.
179
+ //
180
+ // The subject is taken as a DN, not as "the last CN": a root whose subject
181
+ // has no CN at all (`OU=CA <id>`) still has to be reported, and its issuer's
182
+ // CN is not its name.
183
+ const subjectLine = block.filter((line) => /(?:^|[,\s])(?:CN|OU|O|L|C|E)=/.test(line)).pop();
184
+ if (!subjectLine)
185
+ continue;
186
+ const colon = subjectLine.indexOf(':');
187
+ const subject = (colon >= 0 ? subjectLine.slice(colon + 1) : subjectLine).trim();
188
+ certs.push({ thumbprintSha1, subject, commonName: dnCommonName(subject) });
189
+ }
190
+ return { certs, blocks: blocks.length, parsedBlocks };
191
+ }
192
+ /** First line of a tool's error output, capped — the raw string is diagnostic
193
+ * detail the operator may need to recognise, not something we translate. */
194
+ function firstLine(text) {
195
+ const line = text.split(/\r?\n/).find((l) => l.trim().length > 0)?.trim();
196
+ return line ? line.slice(0, 200) : undefined;
197
+ }
198
+ /** POSIX single-quote a path for a command we hand to the operator to paste. */
199
+ function shellQuote(value) {
200
+ return /^[A-Za-z0-9_@%+=:,./-]+$/.test(value) ? value : `'${value.replace(/'/g, `'\\''`)}'`;
201
+ }
202
+ /** The command that removes ONE occurrence, and the reason when there is none. */
203
+ function removalFor(store, location, cert, anchorRoot) {
204
+ const thumb = cert.thumbprintSha1;
205
+ switch (store) {
206
+ case 'win-user-root':
207
+ // `-user` hits HKCU, which the desktop user owns: no elevation, so this is
208
+ // the one platform where the console COULD act. It still hands the
209
+ // operator a command — the parse above is best-effort and a delete is not
210
+ // reversible by re-reading a listing.
211
+ return { removeCommand: `certutil -user -delstore Root ${thumb}` };
212
+ case 'win-machine-root':
213
+ return { removeCommand: `certutil -delstore Root ${thumb}`, removeHint: 'elevation' };
214
+ case 'darwin-login':
215
+ // The row's own location, not a hardcoded `~/...`: the command must target
216
+ // the keychain it was found in (a sandbox or a symlinked home would
217
+ // otherwise delete from the wrong store).
218
+ return { removeCommand: `security delete-certificate -Z ${thumb} ${shellQuote(location)}` };
219
+ case 'darwin-system':
220
+ return {
221
+ removeCommand: `sudo security delete-certificate -Z ${thumb} ${shellQuote(location)}`,
222
+ removeHint: 'elevation',
223
+ };
224
+ case 'darwin-system-roots':
225
+ // Apple's own store: an OCR root here is evidence of a manual, privileged
226
+ // import. Let the cert sit in the row, but do not hand out a command that
227
+ // edits the OS vendor store.
228
+ return { removeHint: 'unsupported' };
229
+ case 'linux-anchor': {
230
+ // The anchor FILE is what the distro tool reads; removing it and
231
+ // re-merging is the supported path. The refresh tool depends on the anchor
232
+ // DIRECTORY (its root), never on the file path: a vendored anchor lives in
233
+ // `<dir>/<org>/x.crt`, so testing the file path would pick the Debian tool
234
+ // for a RHEL tree.
235
+ const refresh = /ca-trust|pki\/trust/.test(anchorRoot ?? location) ? 'update-ca-trust' : 'update-ca-certificates';
236
+ return { removeCommand: `sudo rm ${shellQuote(location)} && sudo ${refresh}` };
237
+ }
238
+ case 'linux-bundle':
239
+ return { removeHint: 'sourceAnchor' };
240
+ case 'linux-nss':
241
+ // `-L -a` dumps PEM without the nickname, and `-D` deletes BY NICKNAME.
242
+ // The import default is the CN, but a mismatch is a silent no-op, so the
243
+ // operator confirms against `-L` first.
244
+ //
245
+ // A SYSTEM database (`/etc/pki/nssdb`) is root-owned, so its command needs
246
+ // the same elevation the machine store carries — handed out WITH the
247
+ // prefix rather than left to the operator to discover from EACCES.
248
+ return {
249
+ removeCommand: `${location.startsWith('/etc/') ? 'sudo ' : ''}certutil -d sql:${shellQuote(location)} -D -n ${shellQuote(cert.commonName)}`,
250
+ removeHint: 'nssNickname',
251
+ };
252
+ }
253
+ }
254
+ function toRow(store, location, cert, activeThumbprintSha1, anchorRoot) {
255
+ const isActive = activeThumbprintSha1 !== null && cert.thumbprintSha1 === activeThumbprintSha1;
256
+ // Two rows get NO removal path, not even for an API consumer that ignores
257
+ // `isActive`:
258
+ // - the root this gateway signs with (deleting it breaks every client
259
+ // holding a certificate it issued);
260
+ // - every row, when there is no CA on disk. With no identity to compare
261
+ // against, NO row can be proven not-active, so handing out five delete
262
+ // commands could destroy the one that is.
263
+ const { removeCommand, removeHint } = isActive
264
+ ? { removeCommand: undefined, removeHint: undefined }
265
+ : activeThumbprintSha1 === null
266
+ ? { removeCommand: undefined, removeHint: 'noIdentity' }
267
+ : removalFor(store, location, cert, anchorRoot);
268
+ return {
269
+ store,
270
+ location,
271
+ thumbprintSha1: cert.thumbprintSha1,
272
+ subject: cert.subject,
273
+ commonName: cert.commonName,
274
+ notBefore: cert.notBefore,
275
+ notAfter: cert.notAfter,
276
+ isActive,
277
+ removeCommand,
278
+ removeHint,
279
+ };
280
+ }
281
+ /**
282
+ * Read one store and append what it contributed.
283
+ *
284
+ * The status rules are the honesty contract: `ok` means the store was READ. A
285
+ * PARTIAL read is never `ok` even when it produced rows — those rows are kept
286
+ * (an orphan we can see is still actionable) and the store is still flagged, so
287
+ * the console can say "listed, but not completely".
288
+ */
289
+ function collect(stores, certs, store, location, result, activeThumbprintSha1, anchorRoot) {
290
+ let matched = 0;
291
+ for (const cert of result.found ?? []) {
292
+ if (!isOcrRoot(cert))
293
+ continue;
294
+ if (certs.length >= MAX_ROWS) {
295
+ certs.truncated = true;
296
+ break;
297
+ }
298
+ certs.push(toRow(store, location, cert, activeThumbprintSha1, anchorRoot));
299
+ matched += 1;
300
+ }
301
+ stores.push({
302
+ store,
303
+ location,
304
+ status: result.status,
305
+ ...(result.reason ? { reason: result.reason } : {}),
306
+ detail: result.detail,
307
+ matched,
308
+ });
309
+ }
310
+ /** An answer past the size cap is refused, never parsed. */
311
+ function stdoutRefusal(result) {
312
+ return result.stdout.length > MAX_TOOL_STDOUT_BYTES ? 'tooLarge' : undefined;
313
+ }
314
+ /**
315
+ * `unparsed` when a parse read only PART of what the store printed — some blocks
316
+ * carried a hash or a DN that could not be attributed.
317
+ *
318
+ * This is the difference between "the store was listed" and "we read all of it",
319
+ * and it is the reason `ok` never means "0 roots" for a listing we half-read.
320
+ */
321
+ function parseRefusal(parsed) {
322
+ return parsed.blocks > 0 && parsed.parsedBlocks < parsed.blocks ? 'unparsed' : undefined;
323
+ }
324
+ async function listWindows(run, stores, certs, activeThumbprintSha1) {
325
+ const targets = [
326
+ { store: 'win-user-root', args: ['-user', '-store', 'Root'], location: 'HKCU\Software\Microsoft\SystemCertificates\Root' },
327
+ { store: 'win-machine-root', args: ['-store', 'Root'], location: 'HKLM\SOFTWARE\Microsoft\SystemCertificates\Root' },
328
+ ];
329
+ for (const target of targets) {
330
+ const result = await run('certutil', target.args, TOOL_TIMEOUT_MS);
331
+ const parsed = parseCertutilStore(result.stdout);
332
+ if (!result.ok) {
333
+ // Dying AFTER printing part of the listing is still a partial read: the
334
+ // roots it never reached are invisible, so `ok` would be a lie. Rows the
335
+ // parse did recover are kept.
336
+ collect(stores, certs, target.store, target.location, {
337
+ status: 'unreadable',
338
+ reason: /not found|ENOENT/i.test(result.stderr) ? 'toolMissing' : 'notReadable',
339
+ detail: firstLine(result.stderr),
340
+ found: parsed.certs,
341
+ }, activeThumbprintSha1);
342
+ continue;
343
+ }
344
+ const refusal = stdoutRefusal(result) ?? parseRefusal(parsed);
345
+ collect(stores, certs, target.store, target.location, refusal ? { status: 'unreadable', reason: refusal, found: parsed.certs } : { status: 'ok', found: parsed.certs }, activeThumbprintSha1);
346
+ }
347
+ }
348
+ function defaultDarwinKeychains() {
349
+ return [
350
+ { store: 'darwin-login', location: path.join(os.homedir(), 'Library', 'Keychains', 'login.keychain-db') },
351
+ { store: 'darwin-system', location: '/Library/Keychains/System.keychain' },
352
+ { store: 'darwin-system-roots', location: '/System/Library/Keychains/SystemRootCertificates.keychain' },
353
+ ];
354
+ }
355
+ async function listDarwin(run, keychains, stores, certs, activeThumbprintSha1) {
356
+ for (const keychain of keychains) {
357
+ if (!fs.existsSync(keychain.location)) {
358
+ collect(stores, certs, keychain.store, keychain.location, { status: 'skipped' }, activeThumbprintSha1);
359
+ continue;
360
+ }
361
+ const result = await run('security', ['find-certificate', '-a', '-p', keychain.location], TOOL_TIMEOUT_MS);
362
+ const inspected = inspectPemText(result.stdout);
363
+ if (!result.ok) {
364
+ collect(stores, certs, keychain.store, keychain.location, {
365
+ status: 'unreadable',
366
+ reason: /command not found|ENOENT/i.test(result.stderr) ? 'toolMissing' : 'notReadable',
367
+ detail: firstLine(result.stderr),
368
+ found: inspected.certs,
369
+ }, activeThumbprintSha1);
370
+ continue;
371
+ }
372
+ const refusal = stdoutRefusal(result) ?? parseRefusal({ blocks: inspected.blocks, parsedBlocks: inspected.certs.length });
373
+ collect(stores, certs, keychain.store, keychain.location, refusal ? { status: 'unreadable', reason: refusal, found: inspected.certs } : { status: 'ok', found: inspected.certs }, activeThumbprintSha1);
374
+ }
375
+ }
376
+ async function listLinux(run, source, stores, certs, activeThumbprintSha1) {
377
+ for (const dir of source.dirs) {
378
+ if (!fs.existsSync(dir)) {
379
+ collect(stores, certs, 'linux-anchor', dir, { status: 'skipped' }, activeThumbprintSha1);
380
+ continue;
381
+ }
382
+ // ONE walk, shared with the TRUST probe (`ca-trust.ts anchorFiles`): a flat
383
+ // readdir misses a vendored anchor (`<dir>/<org>/x.crt`) and then reports the
384
+ // store clean, and a separate walk per caller lets the two disagree.
385
+ const walked = anchorFiles(dir);
386
+ for (const file of walked.files) {
387
+ let inspected;
388
+ try {
389
+ // Size is checked on the file we are about to read: `pemBlocks` bounds
390
+ // the parse but only after the bytes are already in memory.
391
+ if (fs.statSync(file).size > MAX_PEM_FILE_BYTES) {
392
+ collect(stores, certs, 'linux-anchor', file, { status: 'unreadable', reason: 'tooLarge' }, activeThumbprintSha1, dir);
393
+ continue;
394
+ }
395
+ inspected = inspectPemText(fs.readFileSync(file, 'utf8'));
396
+ }
397
+ catch (err) {
398
+ collect(stores, certs, 'linux-anchor', file, { status: 'unreadable', reason: 'notReadable', detail: firstLine(String(err?.message ?? err)) }, activeThumbprintSha1, dir);
399
+ continue;
400
+ }
401
+ const refusal = parseRefusal({ blocks: inspected.blocks, parsedBlocks: inspected.certs.length });
402
+ collect(stores, certs, 'linux-anchor', file, refusal ? { status: 'unreadable', reason: refusal, found: inspected.certs } : { status: 'ok', found: inspected.certs }, activeThumbprintSha1, dir);
403
+ }
404
+ // Directories we could not ENTER, and directories deeper than the walk:
405
+ // both are "nobody looked there", and both are named so the operator can.
406
+ for (const blind of walked.blind) {
407
+ collect(stores, certs, 'linux-anchor', blind, { status: 'unreadable', reason: 'notReadable' }, activeThumbprintSha1, dir);
408
+ }
409
+ for (const unswept of walked.unswept) {
410
+ collect(stores, certs, 'linux-anchor', unswept, { status: 'unreadable', reason: 'notReadable', detail: 'not walked (depth cap)' }, activeThumbprintSha1, dir);
411
+ }
412
+ }
413
+ for (const bundle of source.bundles) {
414
+ if (!fs.existsSync(bundle)) {
415
+ collect(stores, certs, 'linux-bundle', bundle, { status: 'skipped' }, activeThumbprintSha1);
416
+ continue;
417
+ }
418
+ let text;
419
+ try {
420
+ if (fs.statSync(bundle).size > MAX_PEM_FILE_BYTES) {
421
+ collect(stores, certs, 'linux-bundle', bundle, { status: 'unreadable', reason: 'tooLarge' }, activeThumbprintSha1);
422
+ continue;
423
+ }
424
+ text = fs.readFileSync(bundle, 'utf8');
425
+ }
426
+ catch (err) {
427
+ collect(stores, certs, 'linux-bundle', bundle, { status: 'unreadable', reason: 'notReadable', detail: firstLine(String(err?.message ?? err)) }, activeThumbprintSha1);
428
+ continue;
429
+ }
430
+ const inspected = inspectPemText(text);
431
+ if (inspected.blocks > MAX_PEM_BLOCKS) {
432
+ collect(stores, certs, 'linux-bundle', bundle, { status: 'unreadable', reason: 'tooLarge' }, activeThumbprintSha1);
433
+ continue;
434
+ }
435
+ const refusal = parseRefusal({ blocks: inspected.blocks, parsedBlocks: inspected.certs.length });
436
+ collect(stores, certs, 'linux-bundle', bundle, refusal ? { status: 'unreadable', reason: refusal, found: inspected.certs } : { status: 'ok', found: inspected.certs }, activeThumbprintSha1);
437
+ }
438
+ // Chromium/Electron read their own NSS database; a distro bundle update never
439
+ // reaches it, so an orphan can survive there after the bundle is clean.
440
+ for (const db of source.nssDbs) {
441
+ if (!fs.existsSync(db)) {
442
+ collect(stores, certs, 'linux-nss', db, { status: 'skipped' }, activeThumbprintSha1);
443
+ continue;
444
+ }
445
+ const result = await run('certutil', ['-d', `sql:${db}`, '-L', '-a'], TOOL_TIMEOUT_MS);
446
+ const inspected = inspectPemText(result.stdout);
447
+ if (!result.ok && inspected.blocks === 0) {
448
+ // No `certutil` on the box is the normal case on a headless server: a
449
+ // SKIP, not a failure — there is no NSS store to be wrong about.
450
+ const missing = /ENOENT|not found/i.test(result.stderr);
451
+ collect(stores, certs, 'linux-nss', db, missing
452
+ ? { status: 'skipped', detail: firstLine(result.stderr) }
453
+ : { status: 'unreadable', reason: 'notReadable', detail: firstLine(result.stderr) }, activeThumbprintSha1);
454
+ continue;
455
+ }
456
+ const refusal = result.ok
457
+ ? stdoutRefusal(result) ?? parseRefusal({ blocks: inspected.blocks, parsedBlocks: inspected.certs.length })
458
+ : 'notReadable';
459
+ collect(stores, certs, 'linux-nss', db, refusal
460
+ ? { status: 'unreadable', reason: refusal, detail: firstLine(result.stderr), found: inspected.certs }
461
+ : { status: 'ok', found: inspected.certs }, activeThumbprintSha1);
462
+ }
463
+ }
464
+ /** Read the CA on disk WITHOUT generating it: detection must never create the
465
+ * artifact it reports on (`ensureCa` would mint one on a fresh home). */
466
+ /**
467
+ * The CA this gateway SIGNS WITH, read without resolving a directory: every
468
+ * resolver here may adopt a legacy CA dir by COPYING files, and a read-only
469
+ * inspection must not write. Boot has already adopted, so the path we compute
470
+ * is the one the gateway uses.
471
+ */
472
+ function activeCaDir(caDir) {
473
+ return caDir?.trim() || process.env.OCR_CA_DIR?.trim() || defaultCaDir();
474
+ }
475
+ function readActiveCa(caDir) {
476
+ try {
477
+ const pem = fs.readFileSync(path.join(activeCaDir(caDir), 'ca.pem'), 'utf8');
478
+ const x509 = new crypto.X509Certificate(pem);
479
+ return {
480
+ thumbprintSha1: x509.fingerprint.replace(/:/g, '').toLowerCase(),
481
+ subject: x509.subject.split('\n').join(', '),
482
+ };
483
+ }
484
+ catch {
485
+ return null;
486
+ }
487
+ }
488
+ /**
489
+ * Enumerate every OCR root this machine's trust stores hold.
490
+ *
491
+ * One-shot and read-only. `state: 'unknown'` means NO store could be read —
492
+ * the caller must render "this pass could not run", never "nothing installed".
493
+ */
494
+ export async function listInstalledOcrCas(opts = {}) {
495
+ const platform = opts.platform ?? process.platform;
496
+ const run = opts.run ?? caTrustCommand();
497
+ const active = readActiveCa(opts.caDir);
498
+ const activeThumbprintSha1 = active?.thumbprintSha1 ?? null;
499
+ const stores = [];
500
+ const certs = [];
501
+ if (platform === 'win32') {
502
+ await listWindows(run, stores, certs, activeThumbprintSha1);
503
+ }
504
+ else if (platform === 'darwin') {
505
+ await listDarwin(run, opts.keychains ?? defaultDarwinKeychains(), stores, certs, activeThumbprintSha1);
506
+ }
507
+ else {
508
+ await listLinux(run, opts.linuxStores ?? DEFAULT_LINUX_TRUST_STORES, stores, certs, activeThumbprintSha1);
509
+ }
510
+ const read = stores.some((s) => s.status === 'ok');
511
+ return {
512
+ state: read ? 'ok' : 'unknown',
513
+ platform,
514
+ checkedAt: Date.now(),
515
+ activeThumbprintSha1,
516
+ activeSubject: active?.subject ?? null,
517
+ // Active first, then a stable fingerprint order: the one row an operator
518
+ // must KEEP is the one they should not have to hunt for in a long list.
519
+ certs: [...certs].sort((a, b) => a.isActive === b.isActive ? a.thumbprintSha1.localeCompare(b.thumbprintSha1) : a.isActive ? -1 : 1),
520
+ stores,
521
+ // Exactly at the cap the list MAY have been cut; saying so is cheaper than
522
+ // claiming a completeness we did not verify.
523
+ truncated: certs.truncated === true,
524
+ };
525
+ }