@fuzdev/fuz_app 0.149.0 → 0.151.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 (650) hide show
  1. package/README.md +1 -1
  2. package/dist/actions/CLAUDE.md +327 -300
  3. package/dist/actions/action_bridge.d.ts +5 -79
  4. package/dist/actions/action_bridge.d.ts.map +1 -1
  5. package/dist/actions/action_bridge.js +4 -74
  6. package/dist/actions/action_codegen.d.ts +8 -166
  7. package/dist/actions/action_codegen.d.ts.map +1 -1
  8. package/dist/actions/action_codegen.js +19 -95
  9. package/dist/actions/action_dispatcher.d.ts +10 -0
  10. package/dist/actions/action_dispatcher.d.ts.map +1 -1
  11. package/dist/actions/action_dispatcher.js +9 -6
  12. package/dist/actions/action_event.d.ts +1 -2
  13. package/dist/actions/action_event.d.ts.map +1 -1
  14. package/dist/actions/action_event.js +7 -13
  15. package/dist/actions/action_event_helpers.d.ts +1 -40
  16. package/dist/actions/action_event_helpers.d.ts.map +1 -1
  17. package/dist/actions/action_event_helpers.js +1 -25
  18. package/dist/actions/action_event_types.d.ts +1 -1
  19. package/dist/actions/action_event_types.d.ts.map +1 -1
  20. package/dist/actions/action_rpc.d.ts +10 -215
  21. package/dist/actions/action_rpc.d.ts.map +1 -1
  22. package/dist/actions/action_rpc.js +56 -111
  23. package/dist/actions/action_spec.d.ts +2 -2
  24. package/dist/actions/action_spec.js +2 -2
  25. package/dist/actions/action_types.d.ts +229 -8
  26. package/dist/actions/action_types.d.ts.map +1 -1
  27. package/dist/actions/action_types.js +56 -5
  28. package/dist/actions/broadcast_api.d.ts +22 -17
  29. package/dist/actions/broadcast_api.d.ts.map +1 -1
  30. package/dist/actions/broadcast_api.js +16 -27
  31. package/dist/actions/cancel.d.ts +4 -13
  32. package/dist/actions/cancel.d.ts.map +1 -1
  33. package/dist/actions/cancel.js +5 -17
  34. package/dist/actions/compile_action_registry.d.ts +1 -2
  35. package/dist/actions/compile_action_registry.d.ts.map +1 -1
  36. package/dist/actions/connection_closer.d.ts +120 -50
  37. package/dist/actions/connection_closer.d.ts.map +1 -1
  38. package/dist/actions/connection_closer.js +139 -31
  39. package/dist/actions/{transports_ws_backend.d.ts → connection_registry.d.ts} +120 -132
  40. package/dist/actions/connection_registry.d.ts.map +1 -0
  41. package/dist/actions/{transports_ws_backend.js → connection_registry.js} +149 -152
  42. package/dist/actions/frontend_rpc_client.d.ts +52 -2
  43. package/dist/actions/frontend_rpc_client.d.ts.map +1 -1
  44. package/dist/actions/frontend_rpc_client.js +42 -4
  45. package/dist/actions/peer_ping.d.ts +7 -9
  46. package/dist/actions/peer_ping.d.ts.map +1 -1
  47. package/dist/actions/peer_ping.js +6 -8
  48. package/dist/actions/peer_request.d.ts +6 -5
  49. package/dist/actions/peer_request.d.ts.map +1 -1
  50. package/dist/actions/peer_request.js +6 -5
  51. package/dist/actions/perform_action.d.ts +36 -28
  52. package/dist/actions/perform_action.d.ts.map +1 -1
  53. package/dist/actions/perform_action.js +60 -31
  54. package/dist/actions/protocol.d.ts +14 -0
  55. package/dist/actions/protocol.d.ts.map +1 -1
  56. package/dist/actions/protocol.js +18 -0
  57. package/dist/actions/register_action_ws.d.ts +137 -292
  58. package/dist/actions/register_action_ws.d.ts.map +1 -1
  59. package/dist/actions/register_action_ws.js +155 -903
  60. package/dist/actions/socket.svelte.d.ts +9 -0
  61. package/dist/actions/socket.svelte.d.ts.map +1 -1
  62. package/dist/actions/socket.svelte.js +16 -5
  63. package/dist/actions/transports.d.ts +88 -34
  64. package/dist/actions/transports.d.ts.map +1 -1
  65. package/dist/actions/transports.js +76 -76
  66. package/dist/actions/transports_http.d.ts +48 -12
  67. package/dist/actions/transports_http.d.ts.map +1 -1
  68. package/dist/actions/transports_http.js +75 -44
  69. package/dist/actions/transports_ws.d.ts +29 -0
  70. package/dist/actions/transports_ws.d.ts.map +1 -1
  71. package/dist/actions/transports_ws.js +34 -8
  72. package/dist/actions/ws_endpoint_spec.d.ts +53 -76
  73. package/dist/actions/ws_endpoint_spec.d.ts.map +1 -1
  74. package/dist/actions/ws_endpoint_spec.js +27 -10
  75. package/dist/actions/ws_outbound_writer.d.ts +3 -3
  76. package/dist/actions/ws_outbound_writer.js +3 -3
  77. package/dist/actions/ws_socket_session.d.ts +321 -0
  78. package/dist/actions/ws_socket_session.d.ts.map +1 -0
  79. package/dist/actions/ws_socket_session.js +783 -0
  80. package/dist/auth/CLAUDE.md +132 -68
  81. package/dist/auth/account_action_specs.d.ts +2 -0
  82. package/dist/auth/account_action_specs.d.ts.map +1 -1
  83. package/dist/auth/account_actions.d.ts +1 -1
  84. package/dist/auth/account_actions.d.ts.map +1 -1
  85. package/dist/auth/account_actions.js +9 -3
  86. package/dist/auth/account_queries.d.ts +10 -0
  87. package/dist/auth/account_queries.d.ts.map +1 -1
  88. package/dist/auth/account_queries.js +27 -17
  89. package/dist/auth/account_routes.d.ts +2 -1
  90. package/dist/auth/account_routes.d.ts.map +1 -1
  91. package/dist/auth/account_routes.js +14 -17
  92. package/dist/auth/account_schema.d.ts +5 -5
  93. package/dist/auth/account_schema.d.ts.map +1 -1
  94. package/dist/auth/account_schema.js +5 -2
  95. package/dist/auth/actor_lookup_actions.d.ts +1 -1
  96. package/dist/auth/actor_lookup_actions.d.ts.map +1 -1
  97. package/dist/auth/actor_lookup_actions.js +1 -1
  98. package/dist/auth/actor_lookup_queries.d.ts +3 -2
  99. package/dist/auth/actor_lookup_queries.d.ts.map +1 -1
  100. package/dist/auth/actor_lookup_queries.js +6 -3
  101. package/dist/auth/actor_search_action_specs.d.ts.map +1 -1
  102. package/dist/auth/actor_search_action_specs.js +2 -1
  103. package/dist/auth/actor_search_actions.d.ts +1 -1
  104. package/dist/auth/actor_search_actions.d.ts.map +1 -1
  105. package/dist/auth/actor_search_actions.js +1 -1
  106. package/dist/auth/actor_search_queries.d.ts +10 -7
  107. package/dist/auth/actor_search_queries.d.ts.map +1 -1
  108. package/dist/auth/actor_search_queries.js +18 -11
  109. package/dist/auth/admin_action_specs.d.ts +4 -4
  110. package/dist/auth/admin_action_specs.d.ts.map +1 -1
  111. package/dist/auth/admin_action_specs.js +7 -5
  112. package/dist/auth/admin_actions.d.ts +1 -1
  113. package/dist/auth/admin_actions.d.ts.map +1 -1
  114. package/dist/auth/admin_actions.js +47 -48
  115. package/dist/auth/all_cell_actions.d.ts +14 -3
  116. package/dist/auth/all_cell_actions.d.ts.map +1 -1
  117. package/dist/auth/all_cell_actions.js +2 -1
  118. package/dist/auth/api_token_queries.d.ts +1 -0
  119. package/dist/auth/api_token_queries.d.ts.map +1 -1
  120. package/dist/auth/api_token_queries.js +1 -0
  121. package/dist/auth/audit_emitter.d.ts +12 -6
  122. package/dist/auth/audit_emitter.d.ts.map +1 -1
  123. package/dist/auth/audit_emitter.js +11 -5
  124. package/dist/auth/audit_log_route_schema.d.ts.map +1 -1
  125. package/dist/auth/audit_log_route_schema.js +3 -2
  126. package/dist/auth/audit_log_routes.d.ts +20 -11
  127. package/dist/auth/audit_log_routes.d.ts.map +1 -1
  128. package/dist/auth/audit_log_routes.js +49 -29
  129. package/dist/auth/audit_log_schema.d.ts +14 -21
  130. package/dist/auth/audit_log_schema.d.ts.map +1 -1
  131. package/dist/auth/audit_log_schema.js +19 -23
  132. package/dist/auth/bearer_auth.d.ts +7 -4
  133. package/dist/auth/bearer_auth.d.ts.map +1 -1
  134. package/dist/auth/bearer_auth.js +21 -15
  135. package/dist/auth/bootstrap_account.d.ts +25 -1
  136. package/dist/auth/bootstrap_account.d.ts.map +1 -1
  137. package/dist/auth/bootstrap_account.js +37 -4
  138. package/dist/auth/bootstrap_routes.d.ts +3 -2
  139. package/dist/auth/bootstrap_routes.d.ts.map +1 -1
  140. package/dist/auth/bootstrap_routes.js +5 -4
  141. package/dist/auth/cell_action_helpers.d.ts +89 -0
  142. package/dist/auth/cell_action_helpers.d.ts.map +1 -0
  143. package/dist/auth/cell_action_helpers.js +113 -0
  144. package/dist/auth/cell_action_specs.d.ts +215 -15
  145. package/dist/auth/cell_action_specs.d.ts.map +1 -1
  146. package/dist/auth/cell_action_specs.js +103 -16
  147. package/dist/auth/cell_actions.d.ts +58 -27
  148. package/dist/auth/cell_actions.d.ts.map +1 -1
  149. package/dist/auth/cell_actions.js +206 -161
  150. package/dist/auth/cell_audit_actions.d.ts +1 -1
  151. package/dist/auth/cell_audit_actions.d.ts.map +1 -1
  152. package/dist/auth/cell_audit_actions.js +3 -12
  153. package/dist/auth/cell_audit_events.d.ts +1 -1
  154. package/dist/auth/cell_audit_events.d.ts.map +1 -1
  155. package/dist/auth/cell_audit_events.js +3 -2
  156. package/dist/auth/cell_audit_metadata.d.ts +12 -1
  157. package/dist/auth/cell_audit_metadata.d.ts.map +1 -1
  158. package/dist/auth/cell_audit_metadata.js +11 -1
  159. package/dist/auth/cell_field_actions.d.ts +1 -1
  160. package/dist/auth/cell_field_actions.d.ts.map +1 -1
  161. package/dist/auth/cell_field_actions.js +16 -66
  162. package/dist/auth/cell_grant_action_specs.d.ts +9 -2
  163. package/dist/auth/cell_grant_action_specs.d.ts.map +1 -1
  164. package/dist/auth/cell_grant_action_specs.js +10 -3
  165. package/dist/auth/cell_grant_actions.d.ts +105 -11
  166. package/dist/auth/cell_grant_actions.d.ts.map +1 -1
  167. package/dist/auth/cell_grant_actions.js +81 -56
  168. package/dist/auth/cell_grant_audit_metadata.d.ts +6 -3
  169. package/dist/auth/cell_grant_audit_metadata.d.ts.map +1 -1
  170. package/dist/auth/cell_grant_audit_metadata.js +7 -4
  171. package/dist/auth/cell_item_actions.d.ts +1 -1
  172. package/dist/auth/cell_item_actions.d.ts.map +1 -1
  173. package/dist/auth/cell_item_actions.js +21 -82
  174. package/dist/auth/cleanup.d.ts +1 -1
  175. package/dist/auth/cleanup.d.ts.map +1 -1
  176. package/dist/auth/cleanup.js +6 -3
  177. package/dist/auth/credential_deadline.d.ts +3 -3
  178. package/dist/auth/credential_deadline.js +3 -3
  179. package/dist/auth/credential_type_schema.d.ts +8 -7
  180. package/dist/auth/credential_type_schema.d.ts.map +1 -1
  181. package/dist/auth/credential_type_schema.js +8 -7
  182. package/dist/auth/daemon_token_middleware.d.ts +12 -6
  183. package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
  184. package/dist/auth/daemon_token_middleware.js +28 -17
  185. package/dist/auth/deps.d.ts +4 -4
  186. package/dist/auth/fail_floor.d.ts +55 -0
  187. package/dist/auth/fail_floor.d.ts.map +1 -0
  188. package/dist/auth/fail_floor.js +63 -0
  189. package/dist/auth/invite_queries.d.ts +3 -15
  190. package/dist/auth/invite_queries.d.ts.map +1 -1
  191. package/dist/auth/invite_queries.js +3 -21
  192. package/dist/auth/middleware.d.ts +12 -7
  193. package/dist/auth/middleware.d.ts.map +1 -1
  194. package/dist/auth/middleware.js +42 -29
  195. package/dist/auth/migrations.d.ts +5 -33
  196. package/dist/auth/migrations.d.ts.map +1 -1
  197. package/dist/auth/migrations.js +9 -16
  198. package/dist/auth/request_context.d.ts +101 -71
  199. package/dist/auth/request_context.d.ts.map +1 -1
  200. package/dist/auth/request_context.js +137 -140
  201. package/dist/auth/resolved_auth.d.ts +122 -36
  202. package/dist/auth/resolved_auth.d.ts.map +1 -1
  203. package/dist/auth/resolved_auth.js +89 -38
  204. package/dist/auth/role_grant_offer_action_specs.d.ts +117 -16
  205. package/dist/auth/role_grant_offer_action_specs.d.ts.map +1 -1
  206. package/dist/auth/role_grant_offer_action_specs.js +51 -16
  207. package/dist/auth/role_grant_offer_actions.d.ts +22 -11
  208. package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
  209. package/dist/auth/role_grant_offer_actions.js +72 -19
  210. package/dist/auth/role_grant_offer_notifications.d.ts +6 -5
  211. package/dist/auth/role_grant_offer_notifications.d.ts.map +1 -1
  212. package/dist/auth/role_grant_offer_notifications.js +4 -3
  213. package/dist/auth/role_grant_offer_queries.d.ts +20 -5
  214. package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
  215. package/dist/auth/role_grant_offer_queries.js +40 -37
  216. package/dist/auth/role_grant_queries.d.ts +44 -76
  217. package/dist/auth/role_grant_queries.d.ts.map +1 -1
  218. package/dist/auth/role_grant_queries.js +73 -118
  219. package/dist/auth/role_grant_sql.d.ts +42 -0
  220. package/dist/auth/role_grant_sql.d.ts.map +1 -0
  221. package/dist/auth/role_grant_sql.js +54 -0
  222. package/dist/auth/role_schema.d.ts +14 -8
  223. package/dist/auth/role_schema.d.ts.map +1 -1
  224. package/dist/auth/role_schema.js +6 -3
  225. package/dist/auth/scope_kind_schema.d.ts +1 -1
  226. package/dist/auth/scope_kind_schema.js +1 -1
  227. package/dist/auth/self_service_role_actions.d.ts +1 -1
  228. package/dist/auth/self_service_role_actions.d.ts.map +1 -1
  229. package/dist/auth/self_service_role_actions.js +21 -1
  230. package/dist/auth/session_queries.d.ts +2 -1
  231. package/dist/auth/session_queries.d.ts.map +1 -1
  232. package/dist/auth/session_queries.js +2 -1
  233. package/dist/auth/signup_routes.d.ts +2 -1
  234. package/dist/auth/signup_routes.d.ts.map +1 -1
  235. package/dist/auth/signup_routes.js +14 -13
  236. package/dist/auth/standard_rpc_actions.d.ts +1 -1
  237. package/dist/auth/standard_rpc_actions.d.ts.map +1 -1
  238. package/dist/auth/token_scope.d.ts +19 -46
  239. package/dist/auth/token_scope.d.ts.map +1 -1
  240. package/dist/auth/token_scope.js +23 -41
  241. package/dist/db/CLAUDE.md +18 -6
  242. package/dist/db/cell_ddl.d.ts +5 -134
  243. package/dist/db/cell_ddl.d.ts.map +1 -1
  244. package/dist/db/cell_ddl.js +28 -17
  245. package/dist/db/cell_field_queries.d.ts +0 -13
  246. package/dist/db/cell_field_queries.d.ts.map +1 -1
  247. package/dist/db/cell_field_queries.js +0 -16
  248. package/dist/db/cell_grant_queries.d.ts +10 -5
  249. package/dist/db/cell_grant_queries.d.ts.map +1 -1
  250. package/dist/db/cell_grant_queries.js +13 -7
  251. package/dist/db/cell_item_queries.d.ts +0 -7
  252. package/dist/db/cell_item_queries.d.ts.map +1 -1
  253. package/dist/db/cell_item_queries.js +0 -10
  254. package/dist/db/cell_queries.d.ts +65 -55
  255. package/dist/db/cell_queries.d.ts.map +1 -1
  256. package/dist/db/cell_queries.js +85 -62
  257. package/dist/db/cell_view_sql.d.ts +1 -6
  258. package/dist/db/cell_view_sql.d.ts.map +1 -1
  259. package/dist/db/cell_view_sql.js +1 -2
  260. package/dist/db/fact_ddl.d.ts +5 -30
  261. package/dist/db/fact_ddl.d.ts.map +1 -1
  262. package/dist/db/fact_ddl.js +14 -13
  263. package/dist/db/fact_store.d.ts +11 -0
  264. package/dist/db/fact_store.d.ts.map +1 -1
  265. package/dist/db/fact_store.js +4 -1
  266. package/dist/db/migrate.d.ts +44 -6
  267. package/dist/db/migrate.d.ts.map +1 -1
  268. package/dist/db/migrate.js +63 -4
  269. package/dist/dev/setup.d.ts +18 -14
  270. package/dist/dev/setup.d.ts.map +1 -1
  271. package/dist/dev/setup.js +42 -39
  272. package/dist/env/dotenv.d.ts +2 -2
  273. package/dist/env/dotenv.js +2 -2
  274. package/dist/env/update_env_variable.d.ts +33 -21
  275. package/dist/env/update_env_variable.d.ts.map +1 -1
  276. package/dist/env/update_env_variable.js +54 -35
  277. package/dist/hono_context.d.ts +15 -90
  278. package/dist/hono_context.d.ts.map +1 -1
  279. package/dist/hono_context.js +9 -56
  280. package/dist/http/CLAUDE.md +35 -20
  281. package/dist/http/auth_shape.d.ts +1 -8
  282. package/dist/http/auth_shape.d.ts.map +1 -1
  283. package/dist/http/auth_shape.js +6 -12
  284. package/dist/http/body_limit.d.ts +3 -1
  285. package/dist/http/body_limit.d.ts.map +1 -1
  286. package/dist/http/body_limit.js +6 -1
  287. package/dist/http/common_routes.d.ts.map +1 -1
  288. package/dist/http/common_routes.js +3 -2
  289. package/dist/http/db_routes.d.ts +3 -3
  290. package/dist/http/db_routes.js +3 -3
  291. package/dist/http/error_schemas.d.ts +1 -2
  292. package/dist/http/error_schemas.d.ts.map +1 -1
  293. package/dist/http/error_schemas.js +1 -2
  294. package/dist/http/health_schema.d.ts +16 -0
  295. package/dist/http/health_schema.d.ts.map +1 -0
  296. package/dist/http/health_schema.js +12 -0
  297. package/dist/http/jsonrpc.d.ts +9 -0
  298. package/dist/http/jsonrpc.d.ts.map +1 -1
  299. package/dist/http/jsonrpc.js +17 -0
  300. package/dist/http/jsonrpc_errors.d.ts +22 -2
  301. package/dist/http/jsonrpc_errors.d.ts.map +1 -1
  302. package/dist/http/jsonrpc_errors.js +70 -23
  303. package/dist/http/jsonrpc_helpers.d.ts +60 -17
  304. package/dist/http/jsonrpc_helpers.d.ts.map +1 -1
  305. package/dist/http/jsonrpc_helpers.js +67 -25
  306. package/dist/http/origin.d.ts +30 -1
  307. package/dist/http/origin.d.ts.map +1 -1
  308. package/dist/http/origin.js +46 -9
  309. package/dist/http/origin_wildcard.d.ts +97 -0
  310. package/dist/http/origin_wildcard.d.ts.map +1 -0
  311. package/dist/http/origin_wildcard.js +142 -0
  312. package/dist/http/pending_effects.d.ts +28 -0
  313. package/dist/http/pending_effects.d.ts.map +1 -1
  314. package/dist/http/pending_effects.js +32 -1
  315. package/dist/http/proxy.d.ts +4 -2
  316. package/dist/http/proxy.d.ts.map +1 -1
  317. package/dist/http/proxy.js +7 -2
  318. package/dist/http/route_spec.d.ts +4 -3
  319. package/dist/http/route_spec.d.ts.map +1 -1
  320. package/dist/http/route_spec.js +54 -45
  321. package/dist/http/surface.d.ts +4 -2
  322. package/dist/http/surface.d.ts.map +1 -1
  323. package/dist/http/surface.js +7 -4
  324. package/dist/http/surface_query.d.ts +9 -50
  325. package/dist/http/surface_query.d.ts.map +1 -1
  326. package/dist/http/surface_query.js +48 -94
  327. package/dist/realtime/audit_log_sse.d.ts +180 -0
  328. package/dist/realtime/audit_log_sse.d.ts.map +1 -0
  329. package/dist/realtime/audit_log_sse.js +154 -0
  330. package/dist/realtime/sse.d.ts +21 -6
  331. package/dist/realtime/sse.d.ts.map +1 -1
  332. package/dist/realtime/sse.js +33 -10
  333. package/dist/realtime/sse_constants.d.ts +29 -2
  334. package/dist/realtime/sse_constants.d.ts.map +1 -1
  335. package/dist/realtime/sse_constants.js +35 -2
  336. package/dist/realtime/{subscriber_registry.d.ts → sse_registry.d.ts} +12 -12
  337. package/dist/realtime/sse_registry.d.ts.map +1 -0
  338. package/dist/realtime/{subscriber_registry.js → sse_registry.js} +4 -4
  339. package/dist/schema_meta.d.ts +52 -1
  340. package/dist/schema_meta.d.ts.map +1 -1
  341. package/dist/schema_meta.js +123 -6
  342. package/dist/sensitivity.d.ts +9 -3
  343. package/dist/sensitivity.d.ts.map +1 -1
  344. package/dist/sensitivity.js +3 -2
  345. package/dist/server/app_backend.d.ts +8 -5
  346. package/dist/server/app_backend.d.ts.map +1 -1
  347. package/dist/server/app_backend.js +6 -12
  348. package/dist/server/app_server.d.ts +73 -54
  349. package/dist/server/app_server.d.ts.map +1 -1
  350. package/dist/server/app_server.js +115 -78
  351. package/dist/server/app_server_context.d.ts +1 -1
  352. package/dist/server/app_server_context.d.ts.map +1 -1
  353. package/dist/server/env.d.ts +24 -20
  354. package/dist/server/env.d.ts.map +1 -1
  355. package/dist/server/env.js +24 -34
  356. package/dist/server/serve_fact_route.d.ts +12 -16
  357. package/dist/server/serve_fact_route.d.ts.map +1 -1
  358. package/dist/server/serve_fact_route.js +59 -34
  359. package/dist/server/static.d.ts.map +1 -1
  360. package/dist/server/static.js +2 -2
  361. package/dist/testing/CLAUDE.md +213 -179
  362. package/dist/testing/admin_integration.d.ts.map +1 -1
  363. package/dist/testing/admin_integration.js +10 -19
  364. package/dist/testing/adversarial_headers.d.ts.map +1 -1
  365. package/dist/testing/adversarial_headers.js +8 -0
  366. package/dist/testing/app_server.d.ts +9 -75
  367. package/dist/testing/app_server.d.ts.map +1 -1
  368. package/dist/testing/app_server.js +31 -112
  369. package/dist/testing/attack_surface.d.ts.map +1 -1
  370. package/dist/testing/attack_surface.js +3 -4
  371. package/dist/testing/audit_completeness.d.ts.map +1 -1
  372. package/dist/testing/audit_completeness.js +4 -5
  373. package/dist/testing/auth_apps.d.ts +3 -3
  374. package/dist/testing/auth_apps.d.ts.map +1 -1
  375. package/dist/testing/auth_apps.js +9 -6
  376. package/dist/testing/connection_closer_helpers.d.ts +8 -16
  377. package/dist/testing/connection_closer_helpers.d.ts.map +1 -1
  378. package/dist/testing/connection_closer_helpers.js +7 -20
  379. package/dist/testing/cross_backend/action_manifest.d.ts +15 -4
  380. package/dist/testing/cross_backend/action_manifest.d.ts.map +1 -1
  381. package/dist/testing/cross_backend/action_manifest.js +13 -3
  382. package/dist/testing/cross_backend/action_manifest_parity.d.ts +15 -7
  383. package/dist/testing/cross_backend/action_manifest_parity.d.ts.map +1 -1
  384. package/dist/testing/cross_backend/action_manifest_parity.js +8 -1
  385. package/dist/testing/cross_backend/actor_lookup.d.ts.map +1 -1
  386. package/dist/testing/cross_backend/actor_lookup.js +27 -0
  387. package/dist/testing/cross_backend/body_size.d.ts.map +1 -1
  388. package/dist/testing/cross_backend/body_size.js +25 -22
  389. package/dist/testing/cross_backend/build_test_backend_paths.d.ts +22 -3
  390. package/dist/testing/cross_backend/build_test_backend_paths.d.ts.map +1 -1
  391. package/dist/testing/cross_backend/build_test_backend_paths.js +34 -11
  392. package/dist/testing/cross_backend/capabilities.d.ts +15 -8
  393. package/dist/testing/cross_backend/capabilities.d.ts.map +1 -1
  394. package/dist/testing/cross_backend/cell_gated_create.d.ts.map +1 -1
  395. package/dist/testing/cross_backend/cell_gated_create.js +109 -13
  396. package/dist/testing/cross_backend/cell_grant_role.js +2 -2
  397. package/dist/testing/cross_backend/cell_grant_steward.d.ts +4 -0
  398. package/dist/testing/cross_backend/cell_grant_steward.d.ts.map +1 -0
  399. package/dist/testing/cross_backend/cell_grant_steward.js +120 -0
  400. package/dist/testing/cross_backend/cell_moderate.d.ts +7 -1
  401. package/dist/testing/cross_backend/cell_moderate.d.ts.map +1 -1
  402. package/dist/testing/cross_backend/cell_moderate.js +68 -4
  403. package/dist/testing/cross_backend/cell_ref_admission.d.ts.map +1 -1
  404. package/dist/testing/cross_backend/cell_ref_admission.js +18 -9
  405. package/dist/testing/cross_backend/cell_relations.d.ts.map +1 -1
  406. package/dist/testing/cross_backend/cell_relations.js +21 -0
  407. package/dist/testing/cross_backend/conformance_table.d.ts +6 -1
  408. package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
  409. package/dist/testing/cross_backend/conformance_table.js +12 -10
  410. package/dist/testing/cross_backend/default_backend_configs.d.ts +18 -4
  411. package/dist/testing/cross_backend/default_backend_configs.d.ts.map +1 -1
  412. package/dist/testing/cross_backend/default_backend_configs.js +29 -9
  413. package/dist/testing/cross_backend/default_spine_surface.d.ts +7 -7
  414. package/dist/testing/cross_backend/default_spine_surface.js +2 -2
  415. package/dist/testing/cross_backend/differential.d.ts +7 -0
  416. package/dist/testing/cross_backend/differential.d.ts.map +1 -1
  417. package/dist/testing/cross_backend/differential.js +17 -0
  418. package/dist/testing/cross_backend/expected_schema.json +1 -0
  419. package/dist/testing/cross_backend/fact_serving.d.ts.map +1 -1
  420. package/dist/testing/cross_backend/fact_serving.js +48 -0
  421. package/dist/testing/cross_backend/full_spine_mount.d.ts +3 -4
  422. package/dist/testing/cross_backend/full_spine_mount.d.ts.map +1 -1
  423. package/dist/testing/cross_backend/full_spine_mount.js +13 -5
  424. package/dist/testing/cross_backend/origin_scope.d.ts.map +1 -1
  425. package/dist/testing/cross_backend/origin_scope.js +5 -13
  426. package/dist/testing/cross_backend/peer_ping_ws.d.ts.map +1 -1
  427. package/dist/testing/cross_backend/peer_ping_ws.js +29 -4
  428. package/dist/testing/cross_backend/postgres_database.d.ts +32 -0
  429. package/dist/testing/cross_backend/postgres_database.d.ts.map +1 -1
  430. package/dist/testing/cross_backend/postgres_database.js +56 -1
  431. package/dist/testing/cross_backend/query_shape.d.ts.map +1 -1
  432. package/dist/testing/cross_backend/query_shape.js +18 -1
  433. package/dist/testing/cross_backend/role_grant_offer_lifecycle.d.ts.map +1 -1
  434. package/dist/testing/cross_backend/role_grant_offer_lifecycle.js +96 -2
  435. package/dist/testing/cross_backend/rpc_success_fixtures.js +2 -2
  436. package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +1 -1
  437. package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
  438. package/dist/testing/cross_backend/rust_spine_stub_backend_config.d.ts +17 -5
  439. package/dist/testing/cross_backend/rust_spine_stub_backend_config.d.ts.map +1 -1
  440. package/dist/testing/cross_backend/rust_spine_stub_backend_config.js +5 -4
  441. package/dist/testing/cross_backend/session_cap.d.ts +8 -0
  442. package/dist/testing/cross_backend/session_cap.d.ts.map +1 -1
  443. package/dist/testing/cross_backend/session_cap.js +66 -2
  444. package/dist/testing/cross_backend/setup.d.ts.map +1 -1
  445. package/dist/testing/cross_backend/setup.js +5 -4
  446. package/dist/testing/cross_backend/spine_suites.d.ts +4 -1
  447. package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
  448. package/dist/testing/cross_backend/spine_suites.js +21 -0
  449. package/dist/testing/cross_backend/spine_surface_constants.d.ts +22 -7
  450. package/dist/testing/cross_backend/spine_surface_constants.d.ts.map +1 -1
  451. package/dist/testing/cross_backend/spine_surface_constants.js +22 -7
  452. package/dist/testing/cross_backend/sse_round_trip.d.ts.map +1 -1
  453. package/dist/testing/cross_backend/sse_round_trip.js +4 -3
  454. package/dist/testing/cross_backend/standard.d.ts +6 -12
  455. package/dist/testing/cross_backend/standard.d.ts.map +1 -1
  456. package/dist/testing/cross_backend/test_cell_gated_create_authorize.d.ts +18 -19
  457. package/dist/testing/cross_backend/test_cell_gated_create_authorize.d.ts.map +1 -1
  458. package/dist/testing/cross_backend/test_cell_gated_create_authorize.js +66 -42
  459. package/dist/testing/cross_backend/test_cell_grant_steward_revoke_authorize.d.ts +8 -0
  460. package/dist/testing/cross_backend/test_cell_grant_steward_revoke_authorize.d.ts.map +1 -0
  461. package/dist/testing/cross_backend/test_cell_grant_steward_revoke_authorize.js +22 -0
  462. package/dist/testing/cross_backend/testing_backdoor.d.ts.map +1 -1
  463. package/dist/testing/cross_backend/testing_backdoor.js +4 -6
  464. package/dist/testing/cross_backend/testing_origin_check.d.ts +1 -1
  465. package/dist/testing/cross_backend/testing_origin_check.d.ts.map +1 -1
  466. package/dist/testing/cross_backend/testing_origin_check.js +1 -1
  467. package/dist/testing/cross_backend/testing_reset_actions.d.ts +10 -5
  468. package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
  469. package/dist/testing/cross_backend/testing_reset_actions.js +7 -6
  470. package/dist/testing/cross_backend/testing_server_bun.d.ts.map +1 -1
  471. package/dist/testing/cross_backend/testing_server_bun.js +5 -4
  472. package/dist/testing/cross_backend/testing_server_core.d.ts +6 -7
  473. package/dist/testing/cross_backend/testing_server_core.d.ts.map +1 -1
  474. package/dist/testing/cross_backend/testing_server_core.js +1 -1
  475. package/dist/testing/cross_backend/testing_server_node.d.ts.map +1 -1
  476. package/dist/testing/cross_backend/testing_server_node.js +13 -2
  477. package/dist/testing/cross_backend/token_lifetime.d.ts.map +1 -1
  478. package/dist/testing/cross_backend/token_lifetime.js +68 -0
  479. package/dist/testing/cross_backend/transport_composition.d.ts +1 -1
  480. package/dist/testing/cross_backend/transport_composition.d.ts.map +1 -1
  481. package/dist/testing/cross_backend/transport_composition.js +48 -6
  482. package/dist/testing/cross_backend/ts_spine_backend_config.d.ts +16 -2
  483. package/dist/testing/cross_backend/ts_spine_backend_config.d.ts.map +1 -1
  484. package/dist/testing/cross_backend/ts_spine_backend_config.js +11 -8
  485. package/dist/testing/cross_backend/ws_action_rate_limit.d.ts.map +1 -1
  486. package/dist/testing/cross_backend/ws_action_rate_limit.js +30 -12
  487. package/dist/testing/cross_backend/ws_connection_cap.d.ts.map +1 -1
  488. package/dist/testing/cross_backend/ws_connection_cap.js +5 -7
  489. package/dist/testing/cross_backend/ws_endpoint.d.ts +2 -3
  490. package/dist/testing/cross_backend/ws_endpoint.d.ts.map +1 -1
  491. package/dist/testing/cross_backend/ws_envelope.d.ts +17 -0
  492. package/dist/testing/cross_backend/ws_envelope.d.ts.map +1 -0
  493. package/dist/testing/cross_backend/ws_envelope.js +172 -0
  494. package/dist/testing/cross_backend/ws_inbound_dispatch.d.ts +16 -0
  495. package/dist/testing/cross_backend/ws_inbound_dispatch.d.ts.map +1 -1
  496. package/dist/testing/cross_backend/ws_inbound_dispatch.js +8 -4
  497. package/dist/testing/cross_backend/ws_outbound_overflow.d.ts.map +1 -1
  498. package/dist/testing/cross_backend/ws_outbound_overflow.js +5 -8
  499. package/dist/testing/cross_backend/ws_role_gated.js +2 -2
  500. package/dist/testing/cross_backend/ws_round_trip.d.ts.map +1 -1
  501. package/dist/testing/cross_backend/ws_round_trip.js +6 -4
  502. package/dist/{cli/daemon.d.ts → testing/daemon_info.d.ts} +15 -47
  503. package/dist/testing/daemon_info.d.ts.map +1 -0
  504. package/dist/testing/daemon_info.js +108 -0
  505. package/dist/testing/daemon_token_rotation.js +1 -1
  506. package/dist/testing/data_exposure.d.ts.map +1 -1
  507. package/dist/testing/data_exposure.js +3 -4
  508. package/dist/testing/db.js +2 -2
  509. package/dist/testing/integration.d.ts.map +1 -1
  510. package/dist/testing/integration.js +35 -65
  511. package/dist/testing/integration_helpers.d.ts +0 -15
  512. package/dist/testing/integration_helpers.d.ts.map +1 -1
  513. package/dist/testing/integration_helpers.js +2 -42
  514. package/dist/testing/middleware.d.ts +20 -12
  515. package/dist/testing/middleware.d.ts.map +1 -1
  516. package/dist/testing/middleware.js +49 -40
  517. package/dist/testing/rate_limiting.d.ts.map +1 -1
  518. package/dist/testing/rate_limiting.js +13 -22
  519. package/dist/testing/resolved_auth.d.ts +30 -0
  520. package/dist/testing/resolved_auth.d.ts.map +1 -0
  521. package/dist/testing/resolved_auth.js +41 -0
  522. package/dist/testing/rpc_envelope_cases.d.ts.map +1 -1
  523. package/dist/testing/rpc_envelope_cases.js +3 -0
  524. package/dist/testing/rpc_helpers.d.ts +1 -1
  525. package/dist/testing/rpc_helpers.d.ts.map +1 -1
  526. package/dist/testing/rpc_helpers.js +2 -1
  527. package/dist/testing/sse_round_trip.d.ts +5 -4
  528. package/dist/testing/sse_round_trip.d.ts.map +1 -1
  529. package/dist/testing/sse_round_trip.js +2 -2
  530. package/dist/testing/stubs.d.ts +2 -2
  531. package/dist/testing/stubs.d.ts.map +1 -1
  532. package/dist/testing/stubs.js +24 -21
  533. package/dist/testing/test_origin.d.ts +25 -0
  534. package/dist/testing/test_origin.d.ts.map +1 -0
  535. package/dist/testing/test_origin.js +28 -0
  536. package/dist/testing/transports/raw_http.d.ts +54 -0
  537. package/dist/testing/transports/raw_http.d.ts.map +1 -1
  538. package/dist/testing/transports/raw_http.js +58 -0
  539. package/dist/testing/transports/ws_raw_client.d.ts +8 -0
  540. package/dist/testing/transports/ws_raw_client.d.ts.map +1 -1
  541. package/dist/testing/transports/ws_raw_client.js +13 -0
  542. package/dist/testing/transports/ws_transport.d.ts +15 -2
  543. package/dist/testing/transports/ws_transport.d.ts.map +1 -1
  544. package/dist/testing/transports/ws_transport.js +4 -2
  545. package/dist/testing/ws_round_trip.d.ts +27 -25
  546. package/dist/testing/ws_round_trip.d.ts.map +1 -1
  547. package/dist/testing/ws_round_trip.js +34 -26
  548. package/dist/ui/AccountSessions.svelte +48 -19
  549. package/dist/ui/AccountSessions.svelte.d.ts +2 -17
  550. package/dist/ui/AccountSessions.svelte.d.ts.map +1 -1
  551. package/dist/ui/AdminAccounts.svelte +6 -1
  552. package/dist/ui/AdminAuditLog.svelte +61 -22
  553. package/dist/ui/AdminAuditLog.svelte.d.ts.map +1 -1
  554. package/dist/ui/AdminInvites.svelte +1 -1
  555. package/dist/ui/AdminOverview.svelte +76 -37
  556. package/dist/ui/AdminOverview.svelte.d.ts.map +1 -1
  557. package/dist/ui/AdminRoleGrantHistory.svelte +6 -1
  558. package/dist/ui/AdminSessions.svelte +1 -1
  559. package/dist/ui/AppShell.svelte +3 -2
  560. package/dist/ui/AppShell.svelte.d.ts +3 -2
  561. package/dist/ui/AppShell.svelte.d.ts.map +1 -1
  562. package/dist/ui/CLAUDE.md +121 -35
  563. package/dist/ui/Datatable.svelte +33 -18
  564. package/dist/ui/Datatable.svelte.d.ts +2 -14
  565. package/dist/ui/Datatable.svelte.d.ts.map +1 -1
  566. package/dist/ui/OpenSignupToggle.svelte +10 -1
  567. package/dist/ui/OpenSignupToggle.svelte.d.ts.map +1 -1
  568. package/dist/ui/PopoverButton.svelte +13 -8
  569. package/dist/ui/PopoverButton.svelte.d.ts.map +1 -1
  570. package/dist/ui/RoleGrantOfferForm.svelte +3 -2
  571. package/dist/ui/RoleGrantOfferForm.svelte.d.ts +3 -2
  572. package/dist/ui/RoleGrantOfferForm.svelte.d.ts.map +1 -1
  573. package/dist/ui/RoleGrantOfferHistory.svelte +3 -3
  574. package/dist/ui/RoleGrantOfferInbox.svelte +19 -15
  575. package/dist/ui/RoleGrantOfferInbox.svelte.d.ts.map +1 -1
  576. package/dist/ui/SurfaceExplorer.svelte +66 -27
  577. package/dist/ui/SurfaceExplorer.svelte.d.ts.map +1 -1
  578. package/dist/ui/account_sessions_state.svelte.d.ts +7 -14
  579. package/dist/ui/account_sessions_state.svelte.d.ts.map +1 -1
  580. package/dist/ui/admin_accounts_state.svelte.d.ts +14 -9
  581. package/dist/ui/admin_accounts_state.svelte.d.ts.map +1 -1
  582. package/dist/ui/admin_accounts_state.svelte.js +6 -4
  583. package/dist/ui/admin_invites_state.svelte.d.ts +2 -2
  584. package/dist/ui/admin_invites_state.svelte.d.ts.map +1 -1
  585. package/dist/ui/admin_rpc_adapters.d.ts +9 -9
  586. package/dist/ui/admin_rpc_adapters.d.ts.map +1 -1
  587. package/dist/ui/admin_rpc_adapters.js +9 -9
  588. package/dist/ui/app_settings_state.svelte.d.ts +2 -2
  589. package/dist/ui/app_settings_state.svelte.d.ts.map +1 -1
  590. package/dist/ui/audit_log_state.svelte.d.ts +70 -13
  591. package/dist/ui/audit_log_state.svelte.d.ts.map +1 -1
  592. package/dist/ui/audit_log_state.svelte.js +239 -47
  593. package/dist/ui/backend_probe.svelte.d.ts +93 -0
  594. package/dist/ui/backend_probe.svelte.d.ts.map +1 -0
  595. package/dist/ui/backend_probe.svelte.js +140 -0
  596. package/dist/ui/format_scope.d.ts +7 -7
  597. package/dist/ui/format_scope.d.ts.map +1 -1
  598. package/dist/ui/format_scope.js +4 -4
  599. package/dist/ui/keyed_async_slot.svelte.d.ts +2 -2
  600. package/dist/ui/keyed_async_slot.svelte.js +2 -2
  601. package/dist/ui/popover.svelte.d.ts +18 -19
  602. package/dist/ui/popover.svelte.d.ts.map +1 -1
  603. package/dist/ui/popover.svelte.js +103 -16
  604. package/dist/ui/role_grant_offers_state.svelte.d.ts +41 -46
  605. package/dist/ui/role_grant_offers_state.svelte.d.ts.map +1 -1
  606. package/dist/ui/role_grant_offers_state.svelte.js +37 -19
  607. package/dist/ui/ui_format.d.ts +17 -0
  608. package/dist/ui/ui_format.d.ts.map +1 -1
  609. package/dist/ui/ui_format.js +20 -0
  610. package/package.json +2 -1
  611. package/dist/actions/register_ws_endpoint.d.ts +0 -79
  612. package/dist/actions/register_ws_endpoint.d.ts.map +0 -1
  613. package/dist/actions/register_ws_endpoint.js +0 -109
  614. package/dist/actions/transports_ws_auth_guard.d.ts +0 -94
  615. package/dist/actions/transports_ws_auth_guard.d.ts.map +0 -1
  616. package/dist/actions/transports_ws_auth_guard.js +0 -138
  617. package/dist/actions/transports_ws_backend.d.ts.map +0 -1
  618. package/dist/cli/args.d.ts +0 -55
  619. package/dist/cli/args.d.ts.map +0 -1
  620. package/dist/cli/args.js +0 -100
  621. package/dist/cli/config.d.ts +0 -47
  622. package/dist/cli/config.d.ts.map +0 -1
  623. package/dist/cli/config.js +0 -77
  624. package/dist/cli/daemon.d.ts.map +0 -1
  625. package/dist/cli/daemon.js +0 -181
  626. package/dist/cli/help.d.ts +0 -124
  627. package/dist/cli/help.d.ts.map +0 -1
  628. package/dist/cli/help.js +0 -215
  629. package/dist/cli/logger.d.ts +0 -46
  630. package/dist/cli/logger.d.ts.map +0 -1
  631. package/dist/cli/logger.js +0 -48
  632. package/dist/cli/util.d.ts +0 -36
  633. package/dist/cli/util.d.ts.map +0 -1
  634. package/dist/cli/util.js +0 -50
  635. package/dist/realtime/sse_auth_guard.d.ts +0 -197
  636. package/dist/realtime/sse_auth_guard.d.ts.map +0 -1
  637. package/dist/realtime/sse_auth_guard.js +0 -238
  638. package/dist/realtime/subscriber_registry.d.ts.map +0 -1
  639. package/dist/testing/bootstrap_success.d.ts +0 -29
  640. package/dist/testing/bootstrap_success.d.ts.map +0 -1
  641. package/dist/testing/bootstrap_success.js +0 -144
  642. package/dist/testing/mock_fs.d.ts +0 -20
  643. package/dist/testing/mock_fs.d.ts.map +0 -1
  644. package/dist/testing/mock_fs.js +0 -28
  645. package/dist/testing/standard.d.ts +0 -122
  646. package/dist/testing/standard.d.ts.map +0 -1
  647. package/dist/testing/standard.js +0 -73
  648. package/dist/testing/testing_rate_limiter.d.ts +0 -65
  649. package/dist/testing/testing_rate_limiter.d.ts.map +0 -1
  650. package/dist/testing/testing_rate_limiter.js +0 -80
@@ -1,39 +1,51 @@
1
1
  /**
2
2
  * Write updates to `.env` files while preserving formatting.
3
3
  *
4
+ * `update_env_content` is the one env-file writer: a pure line rebuild that
5
+ * `update_env_variable` (read, update, write) and `dev/setup.ts`'s
6
+ * `setup_env_file` both build on, so every value lands quoted and escaped the
7
+ * same way and round-trips through `parse_dotenv`.
8
+ *
4
9
  * @module
5
10
  */
11
+ import type { FsReadDeps, FsRemoveDeps, FsWriteDeps } from '../runtime/deps.js';
6
12
  /**
7
- * Options for updating environment variables in a .env file.
8
- */
9
- export interface UpdateEnvVariableOptions {
10
- /** Path to the .env file. */
11
- env_file_path: string;
12
- /** Function to read file contents (defaults to `node:fs/promises` `readFile`). */
13
- read_file?: (path: string, encoding: string) => Promise<string>;
14
- /** Function to write file contents (defaults to `node:fs/promises` `writeFile`). */
15
- write_file?: (path: string, content: string, encoding: string) => Promise<void>;
16
- }
17
- /**
18
- * Updates or adds an environment variable in the .env file.
13
+ * Set `key` to `value` in dotenv `content`, returning the new content.
19
14
  * Preserves existing formatting, comments, and other variables.
20
15
  *
21
16
  * Behavior:
22
17
  * - **Duplicate keys**: updates the LAST occurrence (matches dotenv behavior)
23
18
  * - **Inline comments**: preserved after the value (e.g., `KEY=value # comment`)
24
- * - **Quote style**: preserved from original (quoted/unquoted)
19
+ * - **Quote style**: a quoted value stays quoted; an unquoted one stays bare
20
+ * unless the new value would not read back bare (surrounding whitespace, a
21
+ * `#` comment marker, a leading quote, a line break), which is quoted
25
22
  * - **`export ` prefix**: preserved when updating an `export KEY=…` line
23
+ * - **Absent key**: appended as a quoted assignment
24
+ *
25
+ * The line is rebuilt from its parts, so no character of `value` (`$&`, `` $` ``,
26
+ * `$'`, `\`) is interpreted.
27
+ *
28
+ * @param content - dotenv file content (`''` for a new file)
29
+ * @param key - the environment variable name
30
+ * @param value - the new value
31
+ * @returns the updated content
32
+ */
33
+ export declare const update_env_content: (content: string, key: string, value: string) => string;
34
+ /**
35
+ * Updates or adds an environment variable in an env file — read,
36
+ * `update_env_content`, then an atomic replace at mode `0o600` (an env file
37
+ * holds secrets, so the fresh owner-only inode also tightens a permissive
38
+ * hand-made one). A missing file is created.
26
39
  *
27
- * @warning Not atomic; not safe for concurrent writers. Reads the file, mutates
28
- * in memory, then writes it back — a crash or concurrent write can corrupt
29
- * the file. Acceptable for single-user, infrequent edits; revisit if a
30
- * concurrent-writer consumer emerges.
40
+ * A read-modify-write: a concurrent writer's update can be lost (the last
41
+ * replace wins), though the file is never left half-written.
31
42
  *
43
+ * @param deps - file read and write capabilities; pass `remove` too for best-effort temp cleanup on a failed write
44
+ * @param env_path - path to the env file
32
45
  * @param key - the environment variable name (e.g., `'SOME_CONFIGURATION_KEY'`)
33
46
  * @param value - the new value for the environment variable
34
- * @param options - file path and optional read/write overrides
35
- * @mutates filesystem - writes the updated content back to `options.env_file_path`
36
- * @throws Error if the file read fails for any reason other than `ENOENT`, or if the write fails
47
+ * @mutates filesystem - atomically replaces `env_path` at mode `0o600`
48
+ * @throws Error if the read or the write fails
37
49
  */
38
- export declare const update_env_variable: (key: string, value: string, options: UpdateEnvVariableOptions) => Promise<void>;
50
+ export declare const update_env_variable: (deps: FsReadDeps & FsWriteDeps & Partial<FsRemoveDeps>, env_path: string, key: string, value: string) => Promise<void>;
39
51
  //# sourceMappingURL=update_env_variable.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"update_env_variable.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/env/update_env_variable.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACxC,6BAA6B;IAC7B,aAAa,EAAE,MAAM,CAAC;IACtB,kFAAkF;IAClF,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAChE,oFAAoF;IACpF,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAChF;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,mBAAmB,GAC/B,KAAK,MAAM,EACX,OAAO,MAAM,EACb,SAAS,wBAAwB,KAC/B,OAAO,CAAC,IAAI,CAsDd,CAAC"}
1
+ {"version":3,"file":"update_env_variable.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/env/update_env_variable.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGhF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,kBAAkB,GAAI,SAAS,MAAM,EAAE,KAAK,MAAM,EAAE,OAAO,MAAM,KAAG,MAmChF,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,mBAAmB,GAC/B,MAAM,UAAU,GAAG,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,EACtD,UAAU,MAAM,EAChB,KAAK,MAAM,EACX,OAAO,MAAM,KACX,OAAO,CAAC,IAAI,CAId,CAAC"}
@@ -1,47 +1,42 @@
1
1
  /**
2
2
  * Write updates to `.env` files while preserving formatting.
3
3
  *
4
+ * `update_env_content` is the one env-file writer: a pure line rebuild that
5
+ * `update_env_variable` (read, update, write) and `dev/setup.ts`'s
6
+ * `setup_env_file` both build on, so every value lands quoted and escaped the
7
+ * same way and round-trips through `parse_dotenv`.
8
+ *
4
9
  * @module
5
10
  */
6
- import { readFile, writeFile } from 'node:fs/promises';
7
- import { resolve } from 'node:path';
11
+ import { write_file_atomic } from '../runtime/fs.js';
8
12
  /**
9
- * Updates or adds an environment variable in the .env file.
13
+ * Set `key` to `value` in dotenv `content`, returning the new content.
10
14
  * Preserves existing formatting, comments, and other variables.
11
15
  *
12
16
  * Behavior:
13
17
  * - **Duplicate keys**: updates the LAST occurrence (matches dotenv behavior)
14
18
  * - **Inline comments**: preserved after the value (e.g., `KEY=value # comment`)
15
- * - **Quote style**: preserved from original (quoted/unquoted)
19
+ * - **Quote style**: a quoted value stays quoted; an unquoted one stays bare
20
+ * unless the new value would not read back bare (surrounding whitespace, a
21
+ * `#` comment marker, a leading quote, a line break), which is quoted
16
22
  * - **`export ` prefix**: preserved when updating an `export KEY=…` line
23
+ * - **Absent key**: appended as a quoted assignment
17
24
  *
18
- * @warning Not atomic; not safe for concurrent writers. Reads the file, mutates
19
- * in memory, then writes it back — a crash or concurrent write can corrupt
20
- * the file. Acceptable for single-user, infrequent edits; revisit if a
21
- * concurrent-writer consumer emerges.
25
+ * The line is rebuilt from its parts, so no character of `value` (`$&`, `` $` ``,
26
+ * `$'`, `\`) is interpreted.
22
27
  *
23
- * @param key - the environment variable name (e.g., `'SOME_CONFIGURATION_KEY'`)
24
- * @param value - the new value for the environment variable
25
- * @param options - file path and optional read/write overrides
26
- * @mutates filesystem - writes the updated content back to `options.env_file_path`
27
- * @throws Error if the file read fails for any reason other than `ENOENT`, or if the write fails
28
+ * @param content - dotenv file content (`''` for a new file)
29
+ * @param key - the environment variable name
30
+ * @param value - the new value
31
+ * @returns the updated content
28
32
  */
29
- export const update_env_variable = async (key, value, options) => {
30
- const { env_file_path, read_file = readFile, write_file = writeFile } = options;
31
- const file_path = resolve(env_file_path);
32
- let content = '';
33
- try {
34
- content = await read_file(file_path, 'utf-8');
35
- }
36
- catch (error) {
37
- if (error?.code !== 'ENOENT') {
38
- throw error;
39
- }
40
- }
33
+ export const update_env_content = (content, key, value) => {
41
34
  // TODO CRLF: split on `/\r?\n/` + remember per-line delimiter (pinned by edge_cases.test.ts)
42
35
  // Preserve trailing-newline state: `split('\n')` on `'a\n'` yields `['a', '']`
43
36
  // — drop that trailing empty so appends don't insert a blank line. Re-add
44
37
  // the trailing `\n` at the end if the original had one.
38
+ if (content === '')
39
+ return `${key}=${quote_value(value)}\n`;
45
40
  const has_trailing_newline = content.endsWith('\n');
46
41
  const lines = content.split('\n');
47
42
  if (has_trailing_newline)
@@ -57,22 +52,36 @@ export const update_env_variable = async (key, value, options) => {
57
52
  const value_part = line.substring(equals_pos + 1);
58
53
  const inline_comment = extract_inline_comment(value_part);
59
54
  const trimmed_value = value_part.trim();
60
- const has_quotes = is_quoted_value(trimmed_value);
61
- return has_quotes
62
- ? `${export_prefix}${key}=${quote_value(value)}${inline_comment}`
63
- : `${export_prefix}${key}=${value}${inline_comment}`;
55
+ const written = is_quoted_value(trimmed_value) || !reads_back_bare(value) ? quote_value(value) : value;
56
+ return `${export_prefix}${key}=${written}${inline_comment}`;
64
57
  }
65
58
  return line;
66
59
  });
67
60
  if (last_match_idx === -1) {
68
- if (content === '') {
69
- await write_file(file_path, `${key}=${quote_value(value)}\n`, 'utf-8');
70
- return;
71
- }
72
61
  updated_lines.push(`${key}=${quote_value(value)}`);
73
62
  }
74
- const updated_content = updated_lines.join('\n') + (has_trailing_newline ? '\n' : '');
75
- await write_file(file_path, updated_content, 'utf-8');
63
+ return updated_lines.join('\n') + (has_trailing_newline ? '\n' : '');
64
+ };
65
+ /**
66
+ * Updates or adds an environment variable in an env file — read,
67
+ * `update_env_content`, then an atomic replace at mode `0o600` (an env file
68
+ * holds secrets, so the fresh owner-only inode also tightens a permissive
69
+ * hand-made one). A missing file is created.
70
+ *
71
+ * A read-modify-write: a concurrent writer's update can be lost (the last
72
+ * replace wins), though the file is never left half-written.
73
+ *
74
+ * @param deps - file read and write capabilities; pass `remove` too for best-effort temp cleanup on a failed write
75
+ * @param env_path - path to the env file
76
+ * @param key - the environment variable name (e.g., `'SOME_CONFIGURATION_KEY'`)
77
+ * @param value - the new value for the environment variable
78
+ * @mutates filesystem - atomically replaces `env_path` at mode `0o600`
79
+ * @throws Error if the read or the write fails
80
+ */
81
+ export const update_env_variable = async (deps, env_path, key, value) => {
82
+ const stat = await deps.stat(env_path);
83
+ const content = stat ? await deps.read_text_file(env_path) : '';
84
+ await write_file_atomic(deps, env_path, update_env_content(content, key, value), { mode: 0o600 });
76
85
  };
77
86
  // Keep this tokenization aligned with `parse_dotenv` in `env/dotenv.ts`:
78
87
  // trim, skip empties/comments, strip a leading `export `, split on the first `=`.
@@ -160,6 +169,16 @@ const quote_value = (value) => {
160
169
  return `"${escape_for_double_quoted(value)}"`;
161
170
  };
162
171
  const has_newline_chars = (value) => value.includes('\n') || value.includes('\r');
172
+ /**
173
+ * Whether `value`, written unquoted, reads back unchanged through
174
+ * `parse_dotenv` — no surrounding whitespace, no leading quote or `#`, no
175
+ * whitespace-then-`#` comment marker, no line break.
176
+ */
177
+ const reads_back_bare = (value) => value === value.trim() &&
178
+ !has_newline_chars(value) &&
179
+ !is_quoted_value(value) &&
180
+ !value.startsWith('#') &&
181
+ !/\s#/.test(value);
163
182
  /**
164
183
  * Order matters: backslashes must be escaped first so the introduced
165
184
  * backslashes from later replacements aren't re-escaped.
@@ -5,75 +5,28 @@
5
5
  * variables used by auth, http, server, and testing modules.
6
6
  *
7
7
  * Auto-loaded by `server/app_server.ts` (side-effect import) and
8
- * transitively by auth middleware modules that import `CREDENTIAL_TYPE_KEY`.
8
+ * transitively by auth middleware modules that import `RESOLVED_AUTH_KEY`.
9
9
  * Consumers don't need a manual import unless bypassing the standard server assembly.
10
10
  *
11
11
  * @module
12
12
  */
13
- import { z } from 'zod';
14
- import type { TokenScope } from './auth/token_scope.js';
15
13
  import type { RequestContext } from './auth/request_context.js';
14
+ import type { ResolvedAuth } from './auth/resolved_auth.js';
16
15
  /**
17
- * The credential types that can authenticate a request — the closed set
18
- * of fuz_app builtins. The open registry on top
19
- * (`create_credential_type_schema(consumer_types)`) is consulted at
20
- * registry time by `create_role_schema` for `RoleSpec.required_credential_types`
21
- * validation; the wire-validated `CredentialType` enum here stays
22
- * narrow because middleware only ever sets one of the three builtins.
23
- */
24
- export declare const CREDENTIAL_TYPES: readonly ["session", "api_token", "daemon_token"];
25
- /** Credential type — how a request was authenticated. */
26
- export declare const CredentialType: z.ZodEnum<{
27
- daemon_token: "daemon_token";
28
- session: "session";
29
- api_token: "api_token";
30
- }>;
31
- export type CredentialType = z.infer<typeof CredentialType>;
32
- /** Hono context variable name for the credential type. */
33
- export declare const CREDENTIAL_TYPE_KEY = "credential_type";
34
- /** Hono context variable name for the authenticated API token id. */
35
- export declare const AUTH_API_TOKEN_ID_KEY = "auth_api_token_id";
36
- /**
37
- * Hono context variable name for the credential's `TokenScope`.
38
- *
39
- * Set by every auth middleware that resolves a credential — bearer reads it
40
- * from the token row; session and daemon-token set `full`, because a browser
41
- * session *is* full account authority (narrowing it is what role grants are
42
- * for) and the daemon token is singular, filesystem-proved, and keeper-bound.
43
- *
44
- * Unset only for the anonymous caller, who holds no credential to narrow.
45
- * Downstream must not read an unset value as permissive for an *authenticated*
46
- * caller — that absent case is exactly the permissive default this design
47
- * removes.
48
- */
49
- export declare const TOKEN_SCOPE_KEY = "token_scope";
50
- /**
51
- * Hono context variable name for the authenticated account id.
16
+ * Hono context variable name for the request's resolved credential
17
+ * (`ResolvedAuth`) — the one value every auth middleware leg writes, read
18
+ * through `get_resolved_auth`.
52
19
  *
53
- * Set by the auth middleware (session, bearer, or daemon token) on a valid
54
- * credential. `null` for unauthenticated requests. The route-spec wrapper /
55
- * RPC dispatcher's authorization phase reads this when resolving the acting
56
- * actor; account-grain auth guards (`require_auth`) and account-grain handlers
57
- * read it directly.
20
+ * The daemon-token, session, and bearer legs run in that order, and the first
21
+ * that authenticates sets it; the legs after it see it set and skip. Unset
22
+ * (read as `null`) for an unauthenticated request.
58
23
  */
59
- export declare const ACCOUNT_ID_KEY = "auth_account_id";
60
- /**
61
- * Hono context variable name for the credential's deadline — when it stops
62
- * authenticating, as a monotonic `performance.now()` timestamp
63
- * (`auth/credential_deadline.ts`), or `null` for one with no expiry (a daemon
64
- * token, an eternal API token) and for an unauthenticated request.
65
- *
66
- * Set by every auth middleware that resolves a credential: session (the
67
- * earlier of the signed cookie's expiry and the row's), bearer (the row's),
68
- * daemon token (`null`). A long-lived connection opened on the credential
69
- * closes at it (`ResolvedAuth.credential_deadline`).
70
- */
71
- export declare const CREDENTIAL_DEADLINE_KEY = "credential_deadline";
24
+ export declare const RESOLVED_AUTH_KEY = "resolved_auth";
72
25
  /**
73
26
  * Hono context variable name for the session cookie's signed expiry, in
74
27
  * seconds since the Unix epoch — set by the session middleware on a cookie
75
28
  * that verified and has not expired, `null` otherwise. The request-context
76
- * middleware folds it into `CREDENTIAL_DEADLINE_KEY`.
29
+ * middleware folds it into the session's `ResolvedAuth.credential_deadline`.
77
30
  */
78
31
  export declare const SESSION_COOKIE_EXPIRES_AT_KEY = "auth_session_cookie_expires_at";
79
32
  /**
@@ -99,45 +52,17 @@ declare module 'hono' {
99
52
  validated_input: unknown;
100
53
  validated_params: unknown;
101
54
  validated_query: unknown;
102
- /** How the request was authenticated (`'session'`, `'api_token'`, or `'daemon_token'`). */
103
- credential_type: CredentialType | null;
104
- /**
105
- * The credential's authority narrowing. Set by every auth middleware that
106
- * resolves a credential — bearer reads it off the token row; session and
107
- * daemon-token set `full`. Absent only for the anonymous caller, who holds
108
- * no credential to narrow; downstream must not read absent as permissive
109
- * for an authenticated one.
110
- */
111
- token_scope: TokenScope | undefined;
112
- /**
113
- * Authenticated account id. Set by the session / bearer / daemon-token
114
- * middleware on a valid credential; `null` for unauthenticated requests.
115
- * The dispatcher's authorization phase resolves the acting actor against
116
- * this id; `require_auth` 401s when it is `null`.
117
- */
118
- auth_account_id: string | null;
119
- /**
120
- * blake3 hash of the authenticated session token, or `null` for non-session
121
- * credentials. Set by `create_request_context_middleware`. Used to scope
122
- * per-session resources (e.g., SSE stream identity for `session_revoke`
123
- * disconnection) without re-hashing the cookie in every handler.
124
- */
125
- auth_session_token_hash: string | null;
126
55
  /**
127
- * `api_token.id` when the request authenticated via `Authorization: Bearer`,
128
- * or `null` for session/daemon-token/unauthenticated requests. Set by
129
- * `create_bearer_auth_middleware`. Used to scope per-token resources
130
- * (e.g., WS connection revocation on `token_revoke`) without re-looking
131
- * up the token.
56
+ * The credential the auth middleware resolved (`RESOLVED_AUTH_KEY`);
57
+ * `null` or unset for an unauthenticated request. Read it with
58
+ * `get_resolved_auth`.
132
59
  */
133
- auth_api_token_id: string | null;
134
- /** The credential's deadline (`CREDENTIAL_DEADLINE_KEY`). */
135
- credential_deadline: number | null;
60
+ resolved_auth: ResolvedAuth | null;
136
61
  /** The session cookie's signed expiry, epoch seconds (`SESSION_COOKIE_EXPIRES_AT_KEY`). */
137
62
  auth_session_cookie_expires_at: number | null;
138
63
  /**
139
64
  * Eager fire-and-forget pool writes for this request — audit emits,
140
- * session-touch UPDATE, api-token usage tracking. Producers push the
65
+ * api-token usage tracking. Producers push the
141
66
  * in-flight `Promise<void>` directly. The flush middleware drains via
142
67
  * `flush_pending_effects` after the handler returns. Initialized by
143
68
  * `create_app_server`. In test mode (`await_pending_effects: true`),
@@ -1 +1 @@
1
- {"version":3,"file":"hono_context.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/hono_context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAOhE;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,mDAInB,CAAC;AAEX,yDAAyD;AACzD,eAAO,MAAM,cAAc;;;;EAA2B,CAAC;AACvD,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAE5D,0DAA0D;AAC1D,eAAO,MAAM,mBAAmB,oBAAoB,CAAC;AAErD,qEAAqE;AACrE,eAAO,MAAM,qBAAqB,sBAAsB,CAAC;AAEzD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,eAAe,gBAAgB,CAAC;AAE7C;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,oBAAoB,CAAC;AAEhD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,uBAAuB,wBAAwB,CAAC;AAE7D;;;;;GAKG;AACH,eAAO,MAAM,6BAA6B,mCAAmC,CAAC;AAE9E;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,uBAAuB,wBAAwB,CAAC;AAE7D,OAAO,QAAQ,MAAM,CAAC;IACrB,UAAU,kBAAkB;QAC3B,+DAA+D;QAC/D,SAAS,EAAE,MAAM,CAAC;QAClB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;QAC/B,eAAe,EAAE,cAAc,GAAG,IAAI,CAAC;QACvC,eAAe,EAAE,OAAO,CAAC;QACzB,gBAAgB,EAAE,OAAO,CAAC;QAC1B,eAAe,EAAE,OAAO,CAAC;QACzB,2FAA2F;QAC3F,eAAe,EAAE,cAAc,GAAG,IAAI,CAAC;QACvC;;;;;;WAMG;QACH,WAAW,EAAE,UAAU,GAAG,SAAS,CAAC;QACpC;;;;;WAKG;QACH,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;QAC/B;;;;;WAKG;QACH,uBAAuB,EAAE,MAAM,GAAG,IAAI,CAAC;QACvC;;;;;;WAMG;QACH,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;QACjC,6DAA6D;QAC7D,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAAC;QACnC,2FAA2F;QAC3F,8BAA8B,EAAE,MAAM,GAAG,IAAI,CAAC;QAC9C;;;;;;;WAOG;QACH,eAAe,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QACtC;;;;;;;;;;;;WAYG;QACH,mBAAmB,EAAE,KAAK,CAAC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QACvD;;;;WAIG;QACH,mBAAmB,EAAE,OAAO,CAAC;KAC7B;CACD"}
1
+ {"version":3,"file":"hono_context.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/hono_context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAE5D;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,kBAAkB,CAAC;AAEjD;;;;;GAKG;AACH,eAAO,MAAM,6BAA6B,mCAAmC,CAAC;AAE9E;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,uBAAuB,wBAAwB,CAAC;AAE7D,OAAO,QAAQ,MAAM,CAAC;IACrB,UAAU,kBAAkB;QAC3B,+DAA+D;QAC/D,SAAS,EAAE,MAAM,CAAC;QAClB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;QAC/B,eAAe,EAAE,cAAc,GAAG,IAAI,CAAC;QACvC,eAAe,EAAE,OAAO,CAAC;QACzB,gBAAgB,EAAE,OAAO,CAAC;QAC1B,eAAe,EAAE,OAAO,CAAC;QACzB;;;;WAIG;QACH,aAAa,EAAE,YAAY,GAAG,IAAI,CAAC;QACnC,2FAA2F;QAC3F,8BAA8B,EAAE,MAAM,GAAG,IAAI,CAAC;QAC9C;;;;;;;WAOG;QACH,eAAe,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QACtC;;;;;;;;;;;;WAYG;QACH,mBAAmB,EAAE,KAAK,CAAC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QACvD;;;;WAIG;QACH,mBAAmB,EAAE,OAAO,CAAC;KAC7B;CACD"}
@@ -5,73 +5,26 @@
5
5
  * variables used by auth, http, server, and testing modules.
6
6
  *
7
7
  * Auto-loaded by `server/app_server.ts` (side-effect import) and
8
- * transitively by auth middleware modules that import `CREDENTIAL_TYPE_KEY`.
8
+ * transitively by auth middleware modules that import `RESOLVED_AUTH_KEY`.
9
9
  * Consumers don't need a manual import unless bypassing the standard server assembly.
10
10
  *
11
11
  * @module
12
12
  */
13
- import { z } from 'zod';
14
- import { CREDENTIAL_TYPE_API_TOKEN, CREDENTIAL_TYPE_DAEMON_TOKEN, CREDENTIAL_TYPE_SESSION } from './auth/credential_type_schema.js';
15
13
  /**
16
- * The credential types that can authenticate a request — the closed set
17
- * of fuz_app builtins. The open registry on top
18
- * (`create_credential_type_schema(consumer_types)`) is consulted at
19
- * registry time by `create_role_schema` for `RoleSpec.required_credential_types`
20
- * validation; the wire-validated `CredentialType` enum here stays
21
- * narrow because middleware only ever sets one of the three builtins.
22
- */
23
- export const CREDENTIAL_TYPES = [
24
- CREDENTIAL_TYPE_SESSION,
25
- CREDENTIAL_TYPE_API_TOKEN,
26
- CREDENTIAL_TYPE_DAEMON_TOKEN
27
- ];
28
- /** Credential type — how a request was authenticated. */
29
- export const CredentialType = z.enum(CREDENTIAL_TYPES);
30
- /** Hono context variable name for the credential type. */
31
- export const CREDENTIAL_TYPE_KEY = 'credential_type';
32
- /** Hono context variable name for the authenticated API token id. */
33
- export const AUTH_API_TOKEN_ID_KEY = 'auth_api_token_id';
34
- /**
35
- * Hono context variable name for the credential's `TokenScope`.
36
- *
37
- * Set by every auth middleware that resolves a credential — bearer reads it
38
- * from the token row; session and daemon-token set `full`, because a browser
39
- * session *is* full account authority (narrowing it is what role grants are
40
- * for) and the daemon token is singular, filesystem-proved, and keeper-bound.
41
- *
42
- * Unset only for the anonymous caller, who holds no credential to narrow.
43
- * Downstream must not read an unset value as permissive for an *authenticated*
44
- * caller — that absent case is exactly the permissive default this design
45
- * removes.
46
- */
47
- export const TOKEN_SCOPE_KEY = 'token_scope';
48
- /**
49
- * Hono context variable name for the authenticated account id.
50
- *
51
- * Set by the auth middleware (session, bearer, or daemon token) on a valid
52
- * credential. `null` for unauthenticated requests. The route-spec wrapper /
53
- * RPC dispatcher's authorization phase reads this when resolving the acting
54
- * actor; account-grain auth guards (`require_auth`) and account-grain handlers
55
- * read it directly.
56
- */
57
- export const ACCOUNT_ID_KEY = 'auth_account_id';
58
- /**
59
- * Hono context variable name for the credential's deadline — when it stops
60
- * authenticating, as a monotonic `performance.now()` timestamp
61
- * (`auth/credential_deadline.ts`), or `null` for one with no expiry (a daemon
62
- * token, an eternal API token) and for an unauthenticated request.
14
+ * Hono context variable name for the request's resolved credential
15
+ * (`ResolvedAuth`) — the one value every auth middleware leg writes, read
16
+ * through `get_resolved_auth`.
63
17
  *
64
- * Set by every auth middleware that resolves a credential: session (the
65
- * earlier of the signed cookie's expiry and the row's), bearer (the row's),
66
- * daemon token (`null`). A long-lived connection opened on the credential
67
- * closes at it (`ResolvedAuth.credential_deadline`).
18
+ * The daemon-token, session, and bearer legs run in that order, and the first
19
+ * that authenticates sets it; the legs after it see it set and skip. Unset
20
+ * (read as `null`) for an unauthenticated request.
68
21
  */
69
- export const CREDENTIAL_DEADLINE_KEY = 'credential_deadline';
22
+ export const RESOLVED_AUTH_KEY = 'resolved_auth';
70
23
  /**
71
24
  * Hono context variable name for the session cookie's signed expiry, in
72
25
  * seconds since the Unix epoch — set by the session middleware on a cookie
73
26
  * that verified and has not expired, `null` otherwise. The request-context
74
- * middleware folds it into `CREDENTIAL_DEADLINE_KEY`.
27
+ * middleware folds it into the session's `ResolvedAuth.credential_deadline`.
75
28
  */
76
29
  export const SESSION_COOKIE_EXPIRES_AT_KEY = 'auth_session_cookie_expires_at';
77
30
  /**
@@ -28,10 +28,11 @@ effects, see ../../../docs/architecture.md.
28
28
  - `http/origin.ts` — origin allowlist: the strict pattern grammar shared with the Rust spine, typed refusals, and the Origin-only middleware.
29
29
  - `http/jsonrpc.ts` — JSON-RPC 2.0 envelope schemas (MCP superset), `JsonrpcErrorCode`, `_meta`.
30
30
  - `http/jsonrpc_errors.ts` — `ThrownJsonrpcError`, `jsonrpc_errors` throwers, HTTP-status mappings.
31
- - `http/jsonrpc_helpers.ts` — message builders, type guards, input/result normalizers.
31
+ - `http/jsonrpc_helpers.ts` — message builders, type guards, input/result normalizers, and `classify_jsonrpc_message`, the one envelope classifier both transports run.
32
+ - `http/health_schema.ts` — `HEALTH_PATH` + the `HealthResponse` schema, browser-safe, shared by the health route spec and the client probe (`ui/backend_probe.svelte.ts`).
32
33
  - `http/common_routes.ts` — health check + readiness probe (`/ready` schema-drift deploy gate) + authenticated server-status route specs (the surface explorer route lives in `server/surface_route.ts`).
33
34
  - `http/db_routes.ts` — allowlist-gated keeper-only table browser route specs (`public` schema, minus the `NON_BROWSABLE_TABLES` credential floor).
34
- - `http/pending_effects.ts` — `emit_after_commit` + `dispatch_with_post_commit_rollback` (the shared rollback-discard wrapper both dispatch sites use) + `flush_pending_effects` + `flush_post_commit_effects` + `EmitAfterCommitContext`.
35
+ - `http/pending_effects.ts` — `emit_after_commit` + `dispatch_with_post_commit_rollback` (the shared rollback-discard wrapper both dispatch sites use) + `flush_request_effects` (the one two-queue flush HTTP and WS share, over `flush_pending_effects` + `flush_post_commit_effects`) + `EffectErrorContext` + `EmitAfterCommitContext`.
35
36
 
36
37
  ## Route Spec System
37
38
 
@@ -44,7 +45,7 @@ consumers.
44
45
 
45
46
  - `method` — `'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'`
46
47
  - `path` — Hono path (supports `:param` segments)
47
- - `auth: RouteAuth` — flat record `{account, actor, roles?, credential_types?, required_scope?}` from `http/auth_shape.ts`. `account` / `actor` are `'none' | 'optional' | 'required'`. `required_scope` names the capability a narrowed api token's scope must admit — `surface:<name>` (a non-RPC surface, refused to every narrowed token) or `rpc:<method>` (one action method) — and is route-spec-only: `compile_action_registry` rejects it on an `ActionSpec`, where the dispatcher derives the same capability from `spec.method`. Otherwise the same shape governs `ActionSpec.auth` (see `actions/CLAUDE.md`).
48
+ - `auth: RouteAuth` — flat record `{account, actor, roles?, credential_types?, required_scope?}` from `http/auth_shape.ts`. `account` / `actor` are `'none' | 'optional' | 'required'`. `required_scope` names the capability a narrowed api token's scope must admit — `surface:<name>`, a non-RPC surface refused to every narrowed token (an `rpc:<method>` capability throws at registration: it is the dispatcher's per-method gate, which a route never reaches) — and is route-spec-only: `compile_action_registry` rejects it on an `ActionSpec`, where the dispatcher derives `rpc:<method>` from `spec.method`. Otherwise the same shape governs `ActionSpec.auth` (see `actions/CLAUDE.md`).
48
49
  - `handler: RouteHandler` — `(c: Context, route: RouteContext) => Response | Promise<Response>`
49
50
  - `description` — free-text, surfaced in `AppSurface`
50
51
  - `params?: z.ZodObject` — strict-object schema for URL path params
@@ -101,12 +102,12 @@ wrapper). See `auth/signup_routes.ts`.
101
102
  1. **Params validation** — `spec.params` → `validated_params` context var; mismatch returns 400 `ERROR_INVALID_ROUTE_PARAMS` with Zod `issues`
102
103
  2. **Query validation** — `spec.query` → `validated_query`; mismatch returns 400 `ERROR_INVALID_QUERY_PARAMS`
103
104
  3. **Pre-authorization auth guards** — every gate that reads only what the auth middleware set, in coarse-to-fine order: `require_auth` (401 `ERROR_AUTHENTICATION_REQUIRED`) when `auth.account === 'required'` or `auth.actor === 'required'`; `require_credential_types(types)` (403 `ERROR_CREDENTIAL_TYPE_REQUIRED` with `required_credential_types: ReadonlyArray<string>`) when `auth.credential_types?.length`; `require_token_scope(capability)` (403 `ERROR_TOKEN_SCOPE_REQUIRED` with `required_scope`, the token-scope refusal) when `auth.required_scope` names a capability. All fire before any body parsing — so a caller they refuse never sees route-shape information from input parse failures — and before actor resolution, so a wrong channel costs no DB work and never learns account state (e.g. that the account is multi-actor). The `AuthGuardResolver` (e.g. `fuz_auth_guard_resolver` from `auth/auth_guard_resolver.ts`) returns this set as `pre_authorization: Array<MiddlewareHandler>`.
104
- 4. **Authorization phase** — when `spec.auth.actor !== 'none'`, resolves the acting actor against `c.var.account_id` (set by the auth middleware) plus the `acting` selector (`validated_query.acting` on GETs; read off the raw body on mutations, since body validation now runs after the gates), builds `RequestContext` via `build_request_context`, and sets `REQUEST_CONTEXT_KEY`. When `auth.account !== 'none' && auth.actor === 'none'`, an account-only context is built. Resolution failures return 400 `ERROR_ACTOR_REQUIRED` (with `available[]`) or `ERROR_ACTOR_NOT_ON_ACCOUNT` (or 500 `ERROR_NO_ACTORS_ON_ACCOUNT` on signup-invariant violation, 500 `ERROR_ACCOUNT_VANISHED` on torn account/actor reads after a successful resolve). Public routes (`account: 'none' && actor: 'none'`) skip this phase entirely.
105
+ 4. **Authorization phase** — when `spec.auth.actor !== 'none'`, resolves the acting actor against the resolved credential's account (`get_resolved_auth`, set by the auth middleware) plus the `acting` selector (`validated_query.acting` on GETs; read off the raw body on mutations, since body validation now runs after the gates), builds `RequestContext` via `build_request_context`, and sets `REQUEST_CONTEXT_KEY`. When `auth.account !== 'none' && auth.actor === 'none'`, an account-only context is built. Resolution failures return 400 `ERROR_ACTOR_REQUIRED` (with `available[]`) or `ERROR_ACTOR_NOT_ON_ACCOUNT` (or 500 `ERROR_NO_ACTORS_ON_ACCOUNT` on signup-invariant violation, 500 `ERROR_ACCOUNT_VANISHED` on torn account/actor reads after a successful resolve). Public routes (`account: 'none' && actor: 'none'`) skip this phase entirely.
105
106
  5. **Post-authorization auth guards** — `require_role(roles)` (403 `ERROR_INSUFFICIENT_PERMISSIONS` with `required_roles: ReadonlyArray<string>`) when `auth.roles?.length`. The only gate in this phase, because it is the only one that reads `REQUEST_CONTEXT_KEY` (populated by step 4) rather than the auth middleware's own context vars. Multi-role specs admit any-of via `has_any_scoped_role(ctx, roles, null)`.
106
107
  6. **Input validation** — JSON body parsed + validated; mismatch returns 400 `ERROR_INVALID_JSON_BODY` (not JSON) or `ERROR_INVALID_REQUEST_BODY` (schema failure with `issues`). Skipped on GET and `z.null()` inputs. The validated input lands on `c.var.validated_input`.
107
108
  7. **Handler** — wrapped in transaction when `use_transaction` (see above), receives `RouteContext`
108
- 8. **DEV-only output + error validation** — wraps the handler (see below)
109
- 9. **Error catch** — catches `ThrownJsonrpcError` → maps to HTTP status + the flat REST `ApiError` body (`{error: <reason>, message?, ...rest_data}`); catches generic `Error` → 500 `{error: 'internal_error', message?}` (message only in DEV). The reason string comes from `err.data.reason` when set (consumer-supplied canonical reason override) or from `jsonrpc_error_code_to_name(err.code)` (e.g. `-32003 → 'not_found'`). The flat shape matches what middleware and direct handlers emit — REST callers see one envelope across every emit site, while the JSON-RPC dispatcher keeps its own `{jsonrpc, id, error: {code, message, data}}` envelope on the RPC mount.
109
+ 8. **Error catch** — catches a thrown JSON-RPC error (`ThrownJsonrpcError`, recognized by brand through `to_thrown_jsonrpc_error`, so one from a second fuz_app copy maps too; a foreign error class carrying a JSON-RPC `code` falls to the generic path) → maps to HTTP status + the flat REST `ApiError` body (`{error: <reason>, message?, ...rest_data}`); catches generic `Error` → 500 `{error: 'internal_error', message?}` (message only in DEV). The reason string comes from `err.data.reason` when set (consumer-supplied canonical reason override) or from `jsonrpc_error_code_to_name(err.code)` (e.g. `-32003 → 'not_found'`). The flat shape matches what middleware and direct handlers emit — REST callers see one envelope across every emit site, while the JSON-RPC dispatcher keeps its own `{jsonrpc, id, error: {code, message, data}}` envelope on the RPC mount.
110
+ 9. **DEV-only output + error validation** — wraps the error catch (see below), so a body built from a thrown error is validated like a returned one
110
111
 
111
112
  **Ordering: 401 → authz → 403 → 400 → handler.** Mirrors the RPC dispatcher
112
113
  (`actions/action_rpc.ts`) so HTTP RPC and REST fail with the same priority, and
@@ -137,7 +138,8 @@ are the contract with external callers.
137
138
 
138
139
  - Skips streaming responses (non-`application/json` Content-Type) so SSE doesn't hang on `.json()`
139
140
  - On 2xx JSON: validates body against `spec.output`
140
- - On non-2xx JSON: validates body against the merged error schema for that HTTP status
141
+ - On non-2xx JSON: validates body against the merged error schema for that HTTP status — returned or built by the error catch from a thrown error
142
+ - Always accepts a 500 `{error: 'internal_error'}`: the error catch answers it for any generic throw, so no route declares it
141
143
  - **Logs on mismatch, returns the response unchanged** — never throws, never mutates the body
142
144
 
143
145
  Production short-circuits to the unwrapped handler — no parse work on the
@@ -273,15 +275,14 @@ the source specs, for tests that need to iterate over raw specs.
273
275
  No side effects, no state — filters and groupings over `AppSurface`:
274
276
 
275
277
  - `filter_protected_routes` / `filter_public_routes`
276
- - `filter_role_routes` / `filter_authenticated_routes` / `filter_keeper_routes` / `filter_credential_gated_routes` (any `auth.credential_types` gate — superset of keeper) / `filter_routes_for_role(role)`
277
- - `filter_routes_by_prefix(prefix)` / `filter_routes_with_input` / `filter_routes_with_params` / `filter_routes_with_query` / `filter_mutation_routes` / `filter_rate_limited_routes`
278
- - `routes_by_auth_type(surface)` — `Map<RouteAuthCategory, Array<AppSurfaceRoute>>` where `RouteAuthCategory = 'none' | 'authenticated' | 'optional' | 'keeper' | 'role:<name>' | 'credential:<type>' | 'other'`. Multi-role / multi-channel specs appear under each bucket. Keeper is tested before the role bucket and the general credential bucket after it — keeper is an authority _level_ and names the route, a session gate is a _channel_ restriction over the authority the route already declares (so the audit SSE stream buckets as `role:admin`)
278
+ - `filter_role_routes` / `filter_keeper_routes` / `filter_credential_gated_routes` (any `auth.credential_types` gate — superset of keeper)
279
+ - `filter_routes_with_input` / `filter_routes_with_params` / `filter_routes_with_query`
279
280
  - `format_route_key(route)` → `'METHOD /path'`
280
- - `surface_auth_summary(surface)` — counts per auth type, roles and credential channels broken out by name; buckets exactly as `routes_by_auth_type`
281
+ - `surface_auth_summary(surface)` — counts per auth bucket (`none`, `keeper`, `role`, `credential`, `authenticated`, `optional`, `other`), roles and credential channels broken out by name; multi-role / multi-channel specs count once per name. One private categorizer decides the bucket: keeper is tested before the role bucket and the general credential bucket after it — keeper is an authority _level_ and names the route, a session gate is a _channel_ restriction over the authority the route already declares (so the audit SSE stream counts under `role`)
281
282
 
282
283
  The per-route auth predicates these filters compose over (`is_public_auth`,
283
284
  `is_role_auth`, `is_credential_gated_auth`, `is_keeper_auth`,
284
- `is_plain_authenticated_auth`, plus `needs_actor` / `needs_account`) live
285
+ `is_plain_authenticated_auth`, plus `needs_actor`) live
285
286
  in `http/auth_shape.ts` next to the canonical `RouteAuth` schema — import
286
287
  them from there, not from this module. Same predicates back the
287
288
  dispatcher's authorization phase, the route-spec auth-guard resolver,
@@ -364,6 +365,17 @@ whitespace and written as a browser writes an `Origin` — exact
364
365
  position — matches `api.fuz.dev`, NOT `fuz.dev` or `a.b.fuz.dev`); several
365
366
  `https://*.*.corp.fuz.dev`; port wildcard `http://localhost:*` (any port or
366
367
  none); IPv6 `http://[::1]:3000` (exact, no wildcard inside the brackets).
368
+ A wildcard entry boots only with `FUZ_ALLOW_ORIGIN_WILDCARDS=true`:
369
+ `origin_wildcard.ts` classifies each parsed entry (`origin_wildcard_kind` —
370
+ port, host with some or no label fixed, or both — from the `OriginPattern`
371
+ `parse_allowed_origins` returns beside each matcher and brands onto it under
372
+ the realm-global `Symbol.for('@fuzdev/fuz_app/OriginPattern')`, so a second
373
+ fuz_app copy reads it — `origin_pattern_of`), renders what it admits
374
+ (`origin_wildcard_warning`, the Rust `fuz_http::origin_wildcard_warning` text
375
+ word for word), and `admit_origin_wildcards` gives `validate_server_env` and
376
+ `create_app_server` (the server list and each `ws_endpoints` spec's own) the
377
+ refusal or the warnings (`allow_origin_wildcards`). A matcher with no brand —
378
+ hand-built, or copied with `new RegExp` — is refused, flag or not.
367
379
  **Nothing is normalized** — the matcher is built from the entry as written, so
368
380
  an entry a browser would never send is refused rather than rewritten: non-ASCII
369
381
  (punycode an IDN host), a scheme other than http/https (`null`, `file://`,
@@ -440,15 +452,18 @@ which holds a declaration to the same rules.
440
452
  - `jsonrpc_error_messages` — named constructors returning `JsonrpcErrorObject`
441
453
  - `jsonrpc_errors` — named constructors returning `ThrownJsonrpcError` (derived from `jsonrpc_error_messages` via `create_error_thrower`). Usage: `throw jsonrpc_errors.not_found('user')`, `throw jsonrpc_errors.forbidden()`
442
454
  - `ThrownJsonrpcError` — `Error` subclass carrying `code` + optional `data`
455
+ - `to_thrown_jsonrpc_error(err)` — the one thrown → wire conversion: the `JsonrpcErrorObject` a `ThrownJsonrpcError` carries, recognized by a realm-global `Symbol.for` brand on its prototype (so one from a second fuz_app copy is read too), when its `code` is a JSON-RPC error code; else `null` — a foreign error class with a JSON-RPC-shaped `code` (another library's RPC error) or a `DOMException` included. Read by the REST catch layer, `perform_action`, `create_jsonrpc_error_response_from_thrown`, the frontend HTTP and WS transports, and `ActionEvent`'s handler-throw normalization, each masking everything else its own way
443
456
  - `jsonrpc_error_code_to_http_status` / `http_status_to_jsonrpc_error_code` (fall back to 500 / `internal_error`) — the code → status table is module-private; `HTTP_STATUS_TO_JSONRPC_ERROR_CODE` (frozen) is the reverse over the base set
444
457
  - `register_jsonrpc_error_code(code, http_status)` — declares a consumer code's status (see **Consumer codes** above)
445
458
  - Envelope schemas in `http/jsonrpc.ts`: `JsonrpcRequest`, `JsonrpcNotification`, `JsonrpcResponse`, `JsonrpcErrorResponse`, `JsonrpcResponseOrError`, `JsonrpcMessage`, `JsonrpcMessageFromClientToServer`, `JsonrpcMessageFromServerToClient`. Also `JsonrpcRequestId`, `JsonrpcMethod`, `JsonrpcProgressToken`, `JsonrpcMcpMeta`, `JsonrpcRequestParamsMeta`
446
- - Builders in `http/jsonrpc_helpers.ts`: `create_jsonrpc_request`, `create_jsonrpc_notification`, `create_jsonrpc_response`, `create_jsonrpc_error_response`, `create_jsonrpc_error_response_from_thrown` (preserves code/message/data on `ThrownJsonrpcError`; plain `Error` → `internal_error` with `{stack}` in DEV)
447
- - Type guards: `is_jsonrpc_request_id` (rejects NaN/Infinity), `is_jsonrpc_object`, `is_jsonrpc_message`, `is_jsonrpc_request` / `_notification` / `_response` / `_error_response`
459
+ - Builders in `http/jsonrpc_helpers.ts`: `create_jsonrpc_request`, `create_jsonrpc_notification`, `create_jsonrpc_response`, `create_jsonrpc_error_response`, `create_jsonrpc_error_response_from_thrown` (preserves code/message/data on a thrown JSON-RPC error, via `to_thrown_jsonrpc_error`; plain `Error` → `internal_error` with `{stack}` in DEV)
460
+ - Type guards: `is_jsonrpc_request_id` (rejects NaN/Infinity), `is_jsonrpc_object`, `is_jsonrpc_request` / `_notification` / `_response` / `_error_response`
448
461
  - Converters: `to_jsonrpc_message_id`, `to_jsonrpc_params` (normalizes primitives to `{value}`)
462
+ - Classifier: `classify_jsonrpc_message(json)` → `ClassifiedJsonrpcMessage` (`request` / `notification` / `response` / `invalid`, the last carrying the error and the id to answer it on), twin of the Rust `fuz_http::classify` in order and answers. The WS frame handler and the HTTP POST handler switch on it, each keeping its transport's arms: WS refuses batches before it, routes `cancel` and peer responses, and checks duplicate ids and the in-flight ceiling after; POST answers a notification or a response `invalid_request` on `id: null`. Only a refused request envelope carries data — the schema's issues, DEV-only.
449
463
 
450
464
  Handlers can `throw jsonrpc_errors.*` — `apply_route_specs`' error-catch
451
- layer converts to `{error: JsonrpcErrorObject}` at the correct HTTP status.
465
+ layer converts to the flat REST body (`{error: <reason>, message?, ...rest_data}`)
466
+ at the correct HTTP status.
452
467
  Generic `Error` maps to 500 `internal_error` (message in DEV only).
453
468
 
454
469
  ## Pending Effects
@@ -467,7 +482,7 @@ interface EmitAfterCommitContext {
467
482
  ```
468
483
 
469
484
  - **`pending_effects: Array<Promise<void>>`** — eager. Producers push the in-flight `Promise<void>` for fire-and-forget pool writes already running: audit emits via `AppDeps.audit`, session-touch UPDATE, api-token usage tracking. The pool write is rollback-resilient by virtue of running outside the request transaction; pushing the in-flight handle lets test mode (`await_pending_effects: true`) await it. Drain: `flush_pending_effects(effects, log, on_rejection?)`.
470
- - **`post_commit_effects: Array<() => void | Promise<void>>`** — deferred. Producers go through `emit_after_commit(ctx, fn)` exclusively; raw thunks should not be pushed directly. The flush middleware (in `server/app_server.ts` and the per-message WS dispatcher in `actions/register_action_ws.ts`) is the only site that invokes each thunk, after the wrapping `db.transaction` resolves. Drain: `flush_post_commit_effects(effects, log)`.
485
+ - **`post_commit_effects: Array<() => void | Promise<void>>`** — deferred. Producers go through `emit_after_commit(ctx, fn)` exclusively; raw thunks should not be pushed directly. The flush middleware (in `server/app_server.ts` and the per-message WS dispatcher in `actions/ws_socket_session.ts`) is the only site that invokes each thunk, after the wrapping `db.transaction` resolves. Drain: `flush_post_commit_effects(effects, log)`.
471
486
 
472
487
  ### Why split
473
488
 
@@ -512,7 +527,7 @@ must run only after the transaction commits.
512
527
  ### Key properties
513
528
 
514
529
  - **The flush owns the safety net.** `flush_post_commit_effects` wraps every thunk in `try/catch` and routes errors through `ctx.log.error`, so one failing send cannot starve sibling effects in the same batch nor corrupt the already-committed response. Per-thunk `try/catch` inside `emit_after_commit` would skip directly-pushed thunks (e.g. tests); centralizing the wrap in the flush closes that gap.
515
- - **Test mode (`await_pending_effects: true`) flushes both queues.** Eager: `await flush_pending_effects(pending_effects, log)`. Deferred: `await flush_post_commit_effects(post_commit_effects, log)`. Both complete before the response returns. Production mode wraps the same helpers in `void ...` and threads `on_effect_error` into `flush_pending_effects`'s `on_rejection` callback for fan-out.
530
+ - **One flush, every transport.** `flush_request_effects(pending_effects, post_commit_effects, log, on_rejection?)` drains both queues; the HTTP middleware and the per-message WS flush both call it, threading `on_effect_error` (with `{transport, method, path}`) into `on_rejection`. Test mode (`await_pending_effects: true`) awaits it before the response returns; production HTTP runs it fire-and-forget; WS awaits it per frame, after the reply.
516
531
  - **The deferred thunks never wait on the eager writes.** Every flush site (both modes here, and the per-message WS flush) invokes the `post_commit_effects` thunks before it awaits `pending_effects`, so a revocation's connection close is not held behind a slow audit INSERT. A thunk that needs a write — the audit emitter's success-row fan-out — awaits that write itself.
517
532
  - **Drain at the outer flush; discard at the dispatch site.** The successful-path _drain_ of both queues stays at the outer flush middleware (`server/app_server.ts`) + the per-message WS flush — adjacent, one location, no per-wrapper drain timing. What the dispatch sites (route-spec wrapper / `perform_action`) own is the _rollback discard_, via the shared `dispatch_with_post_commit_rollback` helper: on a handler throw they truncate `post_commit_effects` before the outer flush ever sees it, so the flush only drains effects from a committed handler. The eager `pending_effects` queue is never truncated — it drains regardless (attempt audits survive rollback).
518
533
  - Structurally satisfied by both `RouteContext` (HTTP) and `ActionContext` (RPC + WS) — they share the `{log, post_commit_effects}` shape, which is why this helper lives in `http/` rather than `actions/` or `auth/`.
@@ -527,7 +542,7 @@ at send time.
527
542
  `http/common_routes.ts` exposes three generic route-spec factories with no
528
543
  auth-domain dependencies:
529
544
 
530
- - `create_health_route_spec()` — `GET /health`, public, returns `{status: 'ok'}`. Infrastructure endpoint for uptime monitors
545
+ - `create_health_route_spec()` — `GET /health` (`HEALTH_PATH`), public, returns `{status: 'ok'}` (`HealthResponse`, both from `http/health_schema.ts`). Infrastructure endpoint for uptime monitors, and what `ui/backend_probe.svelte.ts` reads
531
546
  - `create_ready_route_spec({expected, log})` — `GET /ready`, public, the deploy gate. Introspects the live DB's columns (`db/schema_ready.ts`) and compares against the committed `expected` column map: `200 {ready: true}` on match, else `503 {error: 'schema_drift' | 'db_unreachable'}`. Detailed drift logs server-side only (minimal body — no schema leak, mirrors why `/api/surface` is admin-only). Throws at assembly on an empty `expected` (fail-loud). Opt-in like `/health`; pair with `load_expected_schema(url)` — loads + URL-caches a consumer's committed `expected_schema.json` and throws on an empty map
532
547
  - `create_server_status_route_spec({version, get_uptime_ms})` — `GET /api/server/status`, authenticated, returns `{version, uptime_ms}`
533
548
 
@@ -576,7 +591,7 @@ a request. Twin of the Rust spine's `fuz_db_admin` router.
576
591
  400 `ERROR_TABLE_NOT_DELETABLE` before the key-shape check, because a generic
577
592
  storage endpoint has no business deleting a row whose meaning lives in the
578
593
  domain layer. `audit_log` is the sharpest: it is both the trail and, since
579
- `realtime/sse_auth_guard.ts` and the WS auth guard close live connections by
594
+ the revocation guard (`create_revocation_guard`) closes live connections by
580
595
  listening to audit events, part of how revocation propagates. The three
581
596
  singletons each fail differently on deletion — `bootstrap_lock` leaves
582
597
  `check_bootstrap_status` advertising a window `bootstrap_account.ts` then always
@@ -629,5 +644,5 @@ Interfaces exported for consumer use: `TableInfo`, `TableWithCount`,
629
644
 
630
645
  - **Middleware ordering** is assembled by `create_app_server` — see the root ../../../CLAUDE.md §Middleware Ordering. The invariants `http/` needs consumers to uphold: trusted-proxy runs before auth/rate-limit; origin verification runs before session parsing; `client_ip` must be set before any handler or rate limiter reads it
631
646
  - **No re-exports.** Import every symbol from its canonical source module. `http/surface.ts` no longer re-exports schema helpers — go through `http/schema_helpers.ts`
632
- - **Input/output schemas align with SAES.** When wiring RPC via `actions/action_rpc.ts` or bridging to `RouteSpec` via `actions/action_bridge.ts`, the same Zod types flow through unchanged (see `actions/CLAUDE.md` §Single JSON-RPC 2.0 endpoint and §HTTP bridge)
647
+ - **Input/output schemas align with SAES.** When wiring RPC via `actions/action_rpc.ts`, the same Zod types flow through unchanged (see `actions/CLAUDE.md` §Single JSON-RPC 2.0 endpoint)
633
648
  - **Error modules are complementary, not redundant.** `http/error_schemas.ts` is Zod-first (for routes and surface); `http/jsonrpc_errors.ts` is throw-first (for handlers and the catch layer). A single `ERROR_*` code can be raised either way depending on whether the handler needs to also attach diagnostic fields