@timber-js/app 0.2.0-alpha.240 → 0.2.0-alpha.242

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 (408) hide show
  1. package/dist/_chunks/{actions-DIgnvDrG.js → actions-BkwgRwCl.js} +146 -12
  2. package/dist/_chunks/actions-BkwgRwCl.js.map +1 -0
  3. package/dist/_chunks/{als-registry-PPYstxK0.js → als-registry-C-iwbtvI.js} +4 -3
  4. package/dist/_chunks/{als-registry-PPYstxK0.js.map → als-registry-C-iwbtvI.js.map} +1 -1
  5. package/dist/_chunks/{als-slots-kbQrHTzm.js → als-slots-CVTF-AMz.js} +3 -3
  6. package/dist/_chunks/als-slots-CVTF-AMz.js.map +1 -0
  7. package/dist/_chunks/{cache-api-uWQwuxWb.js → cache-api-BGA7c5qJ.js} +5 -5
  8. package/dist/_chunks/{cache-api-uWQwuxWb.js.map → cache-api-BGA7c5qJ.js.map} +1 -1
  9. package/dist/_chunks/{chains-C7CExrUI.js → chains-Cuwwjv6T.js} +2 -2
  10. package/dist/_chunks/{chains-C7CExrUI.js.map → chains-Cuwwjv6T.js.map} +1 -1
  11. package/dist/_chunks/chains-LGjBHfSN.js +1 -0
  12. package/dist/_chunks/{classify-Cj9EeZoL.js → classify-Y8S9C0Na.js} +2 -2
  13. package/dist/_chunks/{classify-Cj9EeZoL.js.map → classify-Y8S9C0Na.js.map} +1 -1
  14. package/dist/_chunks/{cli-check-C3QOAru7.js → cli-check-KeE1QaIx.js} +7 -6
  15. package/dist/_chunks/cli-check-KeE1QaIx.js.map +1 -0
  16. package/dist/_chunks/{cli-schema-sync-DQUS_o3V.js → cli-schema-sync-DZEF31wd.js} +2 -2
  17. package/dist/_chunks/{cli-schema-sync-DQUS_o3V.js.map → cli-schema-sync-DZEF31wd.js.map} +1 -1
  18. package/dist/_chunks/{cli-schema-sync-BRxZz66D.js → cli-schema-sync-_y5O6MIg.js} +1 -1
  19. package/dist/_chunks/{client-dep-entries-ZETBdLgv.js → client-dep-entries-DpiwvoDi.js} +2 -2
  20. package/dist/_chunks/{client-dep-entries-ZETBdLgv.js.map → client-dep-entries-DpiwvoDi.js.map} +1 -1
  21. package/dist/_chunks/{cloudflare-Dk5Hqo-O.js → cloudflare-9dbhVOxS.js} +2 -2
  22. package/dist/_chunks/{cloudflare-Dk5Hqo-O.js.map → cloudflare-9dbhVOxS.js.map} +1 -1
  23. package/dist/_chunks/{convention-lint-BoVISNS6.js → convention-lint-0AEsPK2T.js} +378 -10
  24. package/dist/_chunks/convention-lint-0AEsPK2T.js.map +1 -0
  25. package/dist/_chunks/dev-server-CboXr8zX.js +1 -0
  26. package/dist/_chunks/{dev-server-C5R6jx8Q.js → dev-server-DYDr8KIc.js} +9 -3
  27. package/dist/_chunks/dev-server-DYDr8KIc.js.map +1 -0
  28. package/dist/_chunks/{dist-C1Rjlo6s.js → dist-GyaJm4GA.js} +18 -2
  29. package/dist/_chunks/dist-GyaJm4GA.js.map +1 -0
  30. package/dist/_chunks/{error-boundary-DB51f9ih.js → error-boundary-wuNvAJ4n.js} +11 -14
  31. package/dist/_chunks/error-boundary-wuNvAJ4n.js.map +1 -0
  32. package/dist/_chunks/{flight-source-node-D9cHBhjP.js → flight-source-node-KQsX_OhS.js} +4 -7
  33. package/dist/_chunks/flight-source-node-KQsX_OhS.js.map +1 -0
  34. package/dist/_chunks/{json-lossy-check-Y1GxqVX_.js → json-lossy-check-BVDALqMf.js} +2 -2
  35. package/dist/_chunks/{json-lossy-check-Y1GxqVX_.js.map → json-lossy-check-BVDALqMf.js.map} +1 -1
  36. package/dist/_chunks/key-headers-uIig1_mU.js +40 -0
  37. package/dist/_chunks/key-headers-uIig1_mU.js.map +1 -0
  38. package/dist/_chunks/{live-graph-BDQWvnMm.js → live-graph-VhzO7Ol9.js} +4 -4
  39. package/dist/_chunks/{live-graph-BDQWvnMm.js.map → live-graph-VhzO7Ol9.js.map} +1 -1
  40. package/dist/_chunks/{logger-DmRR9tmZ.js → logger-C4m8rfMy.js} +2 -2
  41. package/dist/_chunks/{logger-DmRR9tmZ.js.map → logger-C4m8rfMy.js.map} +1 -1
  42. package/dist/_chunks/metadata-routes-MXNjWOt5.js.map +1 -1
  43. package/dist/_chunks/{node-response-yp8zdyRp.js → node-response-8Vz29cGS.js} +2 -2
  44. package/dist/_chunks/{node-response-yp8zdyRp.js.map → node-response-8Vz29cGS.js.map} +1 -1
  45. package/dist/_chunks/{poison-scan-WQgUydF_.js → poison-scan-Dpl3ibG-.js} +2 -2
  46. package/dist/_chunks/{poison-scan-WQgUydF_.js.map → poison-scan-Dpl3ibG-.js.map} +1 -1
  47. package/dist/_chunks/{rsc-cache-key-D0cb0Gmc.js → rsc-cache-key-BGvUtMtN.js} +40 -4
  48. package/dist/_chunks/{rsc-cache-key-D0cb0Gmc.js.map → rsc-cache-key-BGvUtMtN.js.map} +1 -1
  49. package/dist/_chunks/{scanner-C9Lrf77z.js → scanner-CCEHN9Jg.js} +14 -81
  50. package/dist/_chunks/scanner-CCEHN9Jg.js.map +1 -0
  51. package/dist/_chunks/{sizeof-BISkSaU0.js → sizeof-CIF7fwSJ.js} +2 -2
  52. package/dist/_chunks/{sizeof-BISkSaU0.js.map → sizeof-CIF7fwSJ.js.map} +1 -1
  53. package/dist/_chunks/{walkers-Bxv4v7tX.js → walkers-BbotBhNG.js} +3 -3
  54. package/dist/_chunks/{walkers-Bxv4v7tX.js.map → walkers-BbotBhNG.js.map} +1 -1
  55. package/dist/adapters/cloudflare-dev.js +1 -1
  56. package/dist/adapters/cloudflare-kv-cache.js +2 -2
  57. package/dist/adapters/cloudflare.js +1 -1
  58. package/dist/analyze/crawl-entry.js +3 -3
  59. package/dist/analyze/graph-command.js +2 -2
  60. package/dist/cache/index.js +2 -2
  61. package/dist/cache/stores/memory.js +1 -1
  62. package/dist/cdn/workers-cache-purge.js +1 -1
  63. package/dist/cli-check.d.ts +3 -0
  64. package/dist/cli-check.d.ts.map +1 -1
  65. package/dist/cli.js +3 -3
  66. package/dist/client/browser-entry/router-init.d.ts +0 -1
  67. package/dist/client/browser-entry/router-init.d.ts.map +1 -1
  68. package/dist/client/error-boundary.js +1 -1
  69. package/dist/client/index.js +2 -2
  70. package/dist/client/index.js.map +1 -1
  71. package/dist/client/internal.js +4 -5
  72. package/dist/client/internal.js.map +1 -1
  73. package/dist/client/navigation-commit.d.ts +3 -5
  74. package/dist/client/navigation-commit.d.ts.map +1 -1
  75. package/dist/client/outlet-content-cache.d.ts +25 -30
  76. package/dist/client/outlet-content-cache.d.ts.map +1 -1
  77. package/dist/client/outlet-scope-context.d.ts +4 -4
  78. package/dist/client/outlet-scope-context.d.ts.map +1 -1
  79. package/dist/client/params-context.d.ts +1 -1
  80. package/dist/client/router-types.d.ts +3 -13
  81. package/dist/client/router-types.d.ts.map +1 -1
  82. package/dist/client/router.d.ts.map +1 -1
  83. package/dist/client/segment-cache.d.ts +2 -2
  84. package/dist/client/segment-outlet.d.ts +12 -13
  85. package/dist/client/segment-outlet.d.ts.map +1 -1
  86. package/dist/client/stale-segment.d.ts +2 -2
  87. package/dist/config-types.d.ts +22 -15
  88. package/dist/config-types.d.ts.map +1 -1
  89. package/dist/config-validation.d.ts.map +1 -1
  90. package/dist/cookies/define-cookie.d.ts.map +1 -1
  91. package/dist/cookies/index.js +5 -2
  92. package/dist/cookies/index.js.map +1 -1
  93. package/dist/index.d.ts +1 -0
  94. package/dist/index.d.ts.map +1 -1
  95. package/dist/index.js +109 -26
  96. package/dist/index.js.map +1 -1
  97. package/dist/native/rsc/cookies/define-cookie.js +6 -2
  98. package/dist/native/rsc/cookies/define-cookie.js.map +1 -1
  99. package/dist/native/rsc/manifest.json +12 -4
  100. package/dist/native/rsc/routing/segment-keys.js +11 -1
  101. package/dist/native/rsc/routing/segment-keys.js.map +1 -1
  102. package/dist/native/rsc/search-params/define.js +4 -1
  103. package/dist/native/rsc/search-params/define.js.map +1 -1
  104. package/dist/native/rsc/server/als-registry.js +2 -2
  105. package/dist/native/rsc/server/als-registry.js.map +1 -1
  106. package/dist/native/rsc/server/client-state-tree.js +13 -12
  107. package/dist/native/rsc/server/client-state-tree.js.map +1 -1
  108. package/dist/native/rsc/server/cookie-context.js +12 -0
  109. package/dist/native/rsc/server/cookie-context.js.map +1 -1
  110. package/dist/native/rsc/server/flight-source-node.js +2 -5
  111. package/dist/native/rsc/server/flight-source-node.js.map +1 -1
  112. package/dist/native/rsc/server/flight-source.js +8 -40
  113. package/dist/native/rsc/server/flight-source.js.map +1 -1
  114. package/dist/native/rsc/server/framework-stack-frames.js +18 -0
  115. package/dist/native/rsc/server/framework-stack-frames.js.map +1 -0
  116. package/dist/native/rsc/server/prebuilt-builder.js +15 -1
  117. package/dist/native/rsc/server/prebuilt-builder.js.map +1 -1
  118. package/dist/native/rsc/server/request-context.js +11 -5
  119. package/dist/native/rsc/server/request-context.js.map +1 -1
  120. package/dist/native/rsc/server/route-element-builder.js +29 -11
  121. package/dist/native/rsc/server/route-element-builder.js.map +1 -1
  122. package/dist/native/rsc/server/route-module-loader.js +14 -6
  123. package/dist/native/rsc/server/route-module-loader.js.map +1 -1
  124. package/dist/native/rsc/server/rsc-cache-key-guard.js +5 -1
  125. package/dist/native/rsc/server/rsc-cache-key-guard.js.map +1 -1
  126. package/dist/native/rsc/server/rsc-entry/render-route.js +10 -29
  127. package/dist/native/rsc/server/rsc-entry/render-route.js.map +1 -1
  128. package/dist/native/rsc/server/rsc-entry/revalidate-renderer.js +7 -2
  129. package/dist/native/rsc/server/rsc-entry/revalidate-renderer.js.map +1 -1
  130. package/dist/native/rsc/server/rsc-entry/rsc-stream.js +2 -5
  131. package/dist/native/rsc/server/rsc-entry/rsc-stream.js.map +1 -1
  132. package/dist/native/rsc/server/segment-lifetime/document-outlet.js +24 -0
  133. package/dist/native/rsc/server/segment-lifetime/document-outlet.js.map +1 -0
  134. package/dist/native/rsc/server/segment-lifetime/key-digest.js +74 -0
  135. package/dist/native/rsc/server/segment-lifetime/key-digest.js.map +1 -0
  136. package/dist/native/rsc/server/segment-lifetime/outlet-gate.js +44 -0
  137. package/dist/native/rsc/server/segment-lifetime/outlet-gate.js.map +1 -0
  138. package/dist/native/rsc/server/segment-lifetime/read-rule.js +78 -0
  139. package/dist/native/rsc/server/segment-lifetime/read-rule.js.map +1 -0
  140. package/dist/native/rsc/server/segment-lifetime/read-scope.js +41 -0
  141. package/dist/native/rsc/server/segment-lifetime/read-scope.js.map +1 -0
  142. package/dist/native/rsc/server/segment-lifetime/segment-key.js +64 -0
  143. package/dist/native/rsc/server/segment-lifetime/segment-key.js.map +1 -0
  144. package/dist/native/rsc/server/segment-lifetime/slot-outlets.js +72 -0
  145. package/dist/native/rsc/server/segment-lifetime/slot-outlets.js.map +1 -0
  146. package/dist/native/rsc/server/slot-resolver.js +51 -27
  147. package/dist/native/rsc/server/slot-resolver.js.map +1 -1
  148. package/dist/native/rsc/server/slot-subtree-contain.js +17 -89
  149. package/dist/native/rsc/server/slot-subtree-contain.js.map +1 -1
  150. package/dist/native/rsc/server/subtree-walk.js +140 -0
  151. package/dist/native/rsc/server/subtree-walk.js.map +1 -0
  152. package/dist/native/rsc/server/vite-handoff-rsc.js.map +1 -1
  153. package/dist/native/rsc/shared/als-slots.js +2 -2
  154. package/dist/native/rsc/shared/als-slots.js.map +1 -1
  155. package/dist/native/rsc/shared/cookie-read-through.js +5 -0
  156. package/dist/native/rsc/shared/cookie-read-through.js.map +1 -0
  157. package/dist/native/rsc/shared/key-headers.js +20 -0
  158. package/dist/native/rsc/shared/key-headers.js.map +1 -0
  159. package/dist/native/rsc/shared/outlet-decision.js.map +1 -1
  160. package/dist/native/rsc/shared/route-options-export.js +8 -0
  161. package/dist/native/rsc/shared/route-options-export.js.map +1 -0
  162. package/dist/native/rsc/shared/rsc-cache-key.js +19 -3
  163. package/dist/native/rsc/shared/rsc-cache-key.js.map +1 -1
  164. package/dist/native/rsc/shims/headers.js +3 -4
  165. package/dist/native/rsc/shims/headers.js.map +1 -1
  166. package/dist/native/ssr/client/outlet-content-cache.js +12 -18
  167. package/dist/native/ssr/client/outlet-content-cache.js.map +1 -1
  168. package/dist/native/ssr/client/outlet-scope-context.js.map +1 -1
  169. package/dist/native/ssr/client/segment-outlet.js +6 -19
  170. package/dist/native/ssr/client/segment-outlet.js.map +1 -1
  171. package/dist/native/ssr/cookies/define-cookie.js +6 -2
  172. package/dist/native/ssr/cookies/define-cookie.js.map +1 -1
  173. package/dist/native/ssr/manifest.json +5 -1
  174. package/dist/native/ssr/search-params/define.js +4 -1
  175. package/dist/native/ssr/search-params/define.js.map +1 -1
  176. package/dist/native/ssr/server/als-registry.js +2 -2
  177. package/dist/native/ssr/server/als-registry.js.map +1 -1
  178. package/dist/native/ssr/server/client-state-tree.js +13 -12
  179. package/dist/native/ssr/server/client-state-tree.js.map +1 -1
  180. package/dist/native/ssr/server/cookie-context.js +12 -0
  181. package/dist/native/ssr/server/cookie-context.js.map +1 -1
  182. package/dist/native/ssr/server/flight-source-node.js +2 -5
  183. package/dist/native/ssr/server/flight-source-node.js.map +1 -1
  184. package/dist/native/ssr/server/flight-source.js +1 -1
  185. package/dist/native/ssr/server/flight-source.js.map +1 -1
  186. package/dist/native/ssr/server/framework-stack-frames.js +18 -0
  187. package/dist/native/ssr/server/framework-stack-frames.js.map +1 -0
  188. package/dist/native/ssr/server/request-context.js +11 -5
  189. package/dist/native/ssr/server/request-context.js.map +1 -1
  190. package/dist/native/ssr/server/rsc-cache-key-guard.js +5 -1
  191. package/dist/native/ssr/server/rsc-cache-key-guard.js.map +1 -1
  192. package/dist/native/ssr/server/segment-lifetime/key-digest.js +6 -0
  193. package/dist/native/ssr/server/segment-lifetime/key-digest.js.map +1 -0
  194. package/dist/native/ssr/server/segment-lifetime/read-rule.js +78 -0
  195. package/dist/native/ssr/server/segment-lifetime/read-rule.js.map +1 -0
  196. package/dist/native/ssr/server/vite-handoff-rsc.js.map +1 -1
  197. package/dist/native/ssr/shared/als-slots.js +2 -2
  198. package/dist/native/ssr/shared/als-slots.js.map +1 -1
  199. package/dist/native/ssr/shared/cookie-read-through.js +5 -0
  200. package/dist/native/ssr/shared/cookie-read-through.js.map +1 -0
  201. package/dist/native/ssr/shared/key-headers.js +13 -0
  202. package/dist/native/ssr/shared/key-headers.js.map +1 -0
  203. package/dist/native/ssr/shared/rsc-cache-key.js +19 -3
  204. package/dist/native/ssr/shared/rsc-cache-key.js.map +1 -1
  205. package/dist/native/ssr/shims/headers.js +3 -4
  206. package/dist/native/ssr/shims/headers.js.map +1 -1
  207. package/dist/plugins/callsite-jsx.d.ts +8 -1
  208. package/dist/plugins/callsite-jsx.d.ts.map +1 -1
  209. package/dist/plugins/entries.d.ts.map +1 -1
  210. package/dist/plugins/prerender-sugar.d.ts +9 -8
  211. package/dist/plugins/prerender-sugar.d.ts.map +1 -1
  212. package/dist/plugins/routing.d.ts.map +1 -1
  213. package/dist/routing/convention-lint.d.ts +11 -3
  214. package/dist/routing/convention-lint.d.ts.map +1 -1
  215. package/dist/routing/export-detect.d.ts +50 -23
  216. package/dist/routing/export-detect.d.ts.map +1 -1
  217. package/dist/routing/index.js +2 -2
  218. package/dist/routing/route-options-lint.d.ts +36 -0
  219. package/dist/routing/route-options-lint.d.ts.map +1 -0
  220. package/dist/routing/route-options.d.ts +55 -0
  221. package/dist/routing/route-options.d.ts.map +1 -0
  222. package/dist/routing/segment-keys.d.ts +38 -4
  223. package/dist/routing/segment-keys.d.ts.map +1 -1
  224. package/dist/search-params/index.js +5 -2
  225. package/dist/search-params/index.js.map +1 -1
  226. package/dist/server/als-registry.d.ts +22 -13
  227. package/dist/server/als-registry.d.ts.map +1 -1
  228. package/dist/server/client-state-tree.d.ts +11 -10
  229. package/dist/server/client-state-tree.d.ts.map +1 -1
  230. package/dist/server/cookie-context.d.ts +3 -0
  231. package/dist/server/cookie-context.d.ts.map +1 -1
  232. package/dist/server/flight-source-node.d.ts +1 -6
  233. package/dist/server/flight-source-node.d.ts.map +1 -1
  234. package/dist/server/flight-source.d.ts +4 -28
  235. package/dist/server/flight-source.d.ts.map +1 -1
  236. package/dist/server/framework-stack-frames.d.ts +20 -0
  237. package/dist/server/framework-stack-frames.d.ts.map +1 -0
  238. package/dist/server/index.d.ts +1 -0
  239. package/dist/server/index.d.ts.map +1 -1
  240. package/dist/server/index.js +2 -2
  241. package/dist/server/internal.js +102 -28
  242. package/dist/server/internal.js.map +1 -1
  243. package/dist/server/prebuilt/capture-routes.d.ts +1 -1
  244. package/dist/server/prebuilt-builder.d.ts.map +1 -1
  245. package/dist/server/request-context.d.ts +6 -1
  246. package/dist/server/request-context.d.ts.map +1 -1
  247. package/dist/server/route-element-builder.d.ts +2 -2
  248. package/dist/server/route-element-builder.d.ts.map +1 -1
  249. package/dist/server/route-module-loader.d.ts +10 -2
  250. package/dist/server/route-module-loader.d.ts.map +1 -1
  251. package/dist/server/rsc-cache-key-guard.d.ts +3 -1
  252. package/dist/server/rsc-cache-key-guard.d.ts.map +1 -1
  253. package/dist/server/rsc-entry/helpers.d.ts +1 -1
  254. package/dist/server/rsc-entry/index.d.ts.map +1 -1
  255. package/dist/server/rsc-entry/render-route.d.ts +10 -1
  256. package/dist/server/rsc-entry/render-route.d.ts.map +1 -1
  257. package/dist/server/rsc-entry/revalidate-renderer.d.ts +12 -0
  258. package/dist/server/rsc-entry/revalidate-renderer.d.ts.map +1 -1
  259. package/dist/server/rsc-entry/rsc-stream.d.ts +2 -11
  260. package/dist/server/rsc-entry/rsc-stream.d.ts.map +1 -1
  261. package/dist/server/segment-lifetime/document-outlet.d.ts +66 -0
  262. package/dist/server/segment-lifetime/document-outlet.d.ts.map +1 -0
  263. package/dist/server/segment-lifetime/key-digest.d.ts +46 -0
  264. package/dist/server/segment-lifetime/key-digest.d.ts.map +1 -0
  265. package/dist/server/segment-lifetime/outlet-gate.d.ts +58 -0
  266. package/dist/server/segment-lifetime/outlet-gate.d.ts.map +1 -0
  267. package/dist/server/segment-lifetime/read-rule.d.ts +53 -0
  268. package/dist/server/segment-lifetime/read-rule.d.ts.map +1 -0
  269. package/dist/server/segment-lifetime/read-scope.d.ts +40 -0
  270. package/dist/server/segment-lifetime/read-scope.d.ts.map +1 -0
  271. package/dist/server/segment-lifetime/segment-key.d.ts +63 -0
  272. package/dist/server/segment-lifetime/segment-key.d.ts.map +1 -0
  273. package/dist/server/segment-lifetime/slot-outlets.d.ts +81 -0
  274. package/dist/server/segment-lifetime/slot-outlets.d.ts.map +1 -0
  275. package/dist/server/slot-resolver.d.ts +10 -5
  276. package/dist/server/slot-resolver.d.ts.map +1 -1
  277. package/dist/server/slot-subtree-contain.d.ts +2 -6
  278. package/dist/server/slot-subtree-contain.d.ts.map +1 -1
  279. package/dist/server/subtree-walk.d.ts +56 -0
  280. package/dist/server/subtree-walk.d.ts.map +1 -0
  281. package/dist/server/types.d.ts +75 -0
  282. package/dist/server/types.d.ts.map +1 -1
  283. package/dist/server/vite-handoff-rsc.d.ts +1 -10
  284. package/dist/server/vite-handoff-rsc.d.ts.map +1 -1
  285. package/dist/shared/als-slots.d.ts +12 -2
  286. package/dist/shared/als-slots.d.ts.map +1 -1
  287. package/dist/shared/cookie-read-through.d.ts +18 -0
  288. package/dist/shared/cookie-read-through.d.ts.map +1 -0
  289. package/dist/shared/key-headers.d.ts +13 -0
  290. package/dist/shared/key-headers.d.ts.map +1 -0
  291. package/dist/shared/outlet-decision.d.ts +16 -28
  292. package/dist/shared/outlet-decision.d.ts.map +1 -1
  293. package/dist/shared/payload-root.d.ts +1 -1
  294. package/dist/shared/route-options-export.d.ts +13 -0
  295. package/dist/shared/route-options-export.d.ts.map +1 -0
  296. package/dist/shared/rsc-cache-key.d.ts +22 -0
  297. package/dist/shared/rsc-cache-key.d.ts.map +1 -1
  298. package/dist/shared/segment-info.d.ts +7 -5
  299. package/dist/shared/segment-info.d.ts.map +1 -1
  300. package/dist/shims/headers.d.ts.map +1 -1
  301. package/docs/api/30-api-server.mdx +29 -0
  302. package/docs/api/32-api-cache.mdx +10 -4
  303. package/docs/api/34-api-config.mdx +5 -0
  304. package/docs/learn/09-streaming.mdx +6 -2
  305. package/docs/learn/10-caching.mdx +10 -4
  306. package/package.json +1 -1
  307. package/src/cli-check.ts +11 -3
  308. package/src/client/browser-entry/index.ts +0 -2
  309. package/src/client/browser-entry/router-init.ts +2 -4
  310. package/src/client/error-boundary.tsx +1 -1
  311. package/src/client/navigation-commit.ts +9 -14
  312. package/src/client/outlet-content-cache.ts +36 -42
  313. package/src/client/outlet-scope-context.ts +5 -5
  314. package/src/client/params-context.ts +1 -1
  315. package/src/client/router-types.ts +3 -14
  316. package/src/client/router.ts +1 -2
  317. package/src/client/rsc-fetch.ts +1 -1
  318. package/src/client/segment-cache.ts +2 -2
  319. package/src/client/segment-outlet.tsx +19 -45
  320. package/src/client/stale-segment.ts +2 -2
  321. package/src/config-types.ts +23 -15
  322. package/src/config-validation.ts +17 -1
  323. package/src/cookies/define-cookie.ts +5 -1
  324. package/src/index.ts +2 -1
  325. package/src/plugins/callsite-jsx.ts +104 -6
  326. package/src/plugins/entries.ts +3 -1
  327. package/src/plugins/prerender-sugar.ts +34 -18
  328. package/src/plugins/routing.ts +3 -1
  329. package/src/routing/convention-lint.ts +18 -7
  330. package/src/routing/export-detect.ts +14 -117
  331. package/src/routing/route-options-lint.ts +153 -0
  332. package/src/routing/route-options.ts +439 -0
  333. package/src/routing/scanner.ts +1 -1
  334. package/src/routing/segment-keys.ts +53 -4
  335. package/src/rsc-runtime/vendor-types.d.ts +5 -1
  336. package/src/search-params/define.ts +1 -1
  337. package/src/server/als-registry.ts +25 -17
  338. package/src/server/client-state-tree.ts +30 -27
  339. package/src/server/cookie-context.ts +17 -0
  340. package/src/server/flight-source-node.ts +1 -5
  341. package/src/server/flight-source.ts +8 -82
  342. package/src/server/framework-stack-frames.ts +41 -0
  343. package/src/server/index.ts +7 -0
  344. package/src/server/prebuilt/capture-routes.ts +1 -1
  345. package/src/server/prebuilt-builder.ts +30 -2
  346. package/src/server/request-context.ts +31 -6
  347. package/src/server/route-element-builder.ts +92 -18
  348. package/src/server/route-module-loader.ts +43 -10
  349. package/src/server/rsc-cache-key-guard.ts +17 -2
  350. package/src/server/rsc-entry/helpers.ts +1 -1
  351. package/src/server/rsc-entry/index.ts +16 -3
  352. package/src/server/rsc-entry/render-route.ts +22 -51
  353. package/src/server/rsc-entry/revalidate-renderer.ts +16 -2
  354. package/src/server/rsc-entry/rsc-stream.ts +3 -23
  355. package/src/server/segment-lifetime/document-outlet.ts +98 -0
  356. package/src/server/segment-lifetime/key-digest.ts +139 -0
  357. package/src/server/segment-lifetime/outlet-gate.ts +102 -0
  358. package/src/server/segment-lifetime/read-rule.ts +193 -0
  359. package/src/server/segment-lifetime/read-scope.ts +101 -0
  360. package/src/server/segment-lifetime/segment-key.ts +168 -0
  361. package/src/server/segment-lifetime/slot-outlets.ts +180 -0
  362. package/src/server/slot-resolver.ts +103 -60
  363. package/src/server/slot-subtree-contain.ts +35 -182
  364. package/src/server/subtree-walk.ts +316 -0
  365. package/src/server/types.ts +91 -0
  366. package/src/server/vite-handoff-rsc.ts +1 -12
  367. package/src/shared/als-slots.ts +19 -8
  368. package/src/shared/cookie-read-through.ts +18 -0
  369. package/src/shared/key-headers.ts +42 -0
  370. package/src/shared/outlet-decision.ts +16 -30
  371. package/src/shared/payload-root.ts +1 -1
  372. package/src/shared/route-options-export.ts +14 -0
  373. package/src/shared/rsc-cache-key.ts +41 -2
  374. package/src/shared/segment-info.ts +7 -5
  375. package/src/shims/headers.ts +5 -4
  376. package/dist/_chunks/actions-DIgnvDrG.js.map +0 -1
  377. package/dist/_chunks/als-slots-kbQrHTzm.js.map +0 -1
  378. package/dist/_chunks/chains-CSslTUdI.js +0 -1
  379. package/dist/_chunks/cli-check-C3QOAru7.js.map +0 -1
  380. package/dist/_chunks/convention-lint-BoVISNS6.js.map +0 -1
  381. package/dist/_chunks/dev-server-B8roKA3Q.js +0 -1
  382. package/dist/_chunks/dev-server-C5R6jx8Q.js.map +0 -1
  383. package/dist/_chunks/dist-C1Rjlo6s.js.map +0 -1
  384. package/dist/_chunks/error-boundary-DB51f9ih.js.map +0 -1
  385. package/dist/_chunks/flight-source-node-D9cHBhjP.js.map +0 -1
  386. package/dist/_chunks/scanner-C9Lrf77z.js.map +0 -1
  387. package/dist/native/rsc/server/segment-hash/capture.js +0 -107
  388. package/dist/native/rsc/server/segment-hash/capture.js.map +0 -1
  389. package/dist/native/rsc/server/segment-hash/outlet.js +0 -81
  390. package/dist/native/rsc/server/segment-hash/outlet.js.map +0 -1
  391. package/dist/native/rsc/server/segment-hash/stream-tap.js +0 -139
  392. package/dist/native/rsc/server/segment-hash/stream-tap.js.map +0 -1
  393. package/dist/native/rsc/server/segment-hash/value-hash.js +0 -171
  394. package/dist/native/rsc/server/segment-hash/value-hash.js.map +0 -1
  395. package/dist/native/ssr/server/segment-hash/value-hash.js +0 -162
  396. package/dist/native/ssr/server/segment-hash/value-hash.js.map +0 -1
  397. package/dist/server/segment-hash/capture.d.ts +0 -77
  398. package/dist/server/segment-hash/capture.d.ts.map +0 -1
  399. package/dist/server/segment-hash/outlet.d.ts +0 -65
  400. package/dist/server/segment-hash/outlet.d.ts.map +0 -1
  401. package/dist/server/segment-hash/stream-tap.d.ts +0 -49
  402. package/dist/server/segment-hash/stream-tap.d.ts.map +0 -1
  403. package/dist/server/segment-hash/value-hash.d.ts +0 -70
  404. package/dist/server/segment-hash/value-hash.d.ts.map +0 -1
  405. package/src/server/segment-hash/capture.ts +0 -232
  406. package/src/server/segment-hash/outlet.ts +0 -185
  407. package/src/server/segment-hash/stream-tap.ts +0 -244
  408. package/src/server/segment-hash/value-hash.ts +0 -338
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev-server-DYDr8KIc.js","names":["formatTerminalError","PHASE_LABELS","PHASE_LABELS","_formatTerminalError"],"sources":["../../../../node_modules/.pnpm/srvx@1.0.8/node_modules/srvx/dist/adapters/node.mjs","../../src/dev-tools/stack-classifier.ts","../../src/dev-tools/terminal.ts","../../src/dev-tools/overlay.ts","../../src/server/utils/escape-html.ts","../../src/dev-tools/dev-page-shell.ts","../../src/dev-tools/error-page.ts","../../src/plugins/dev-hostname.ts","../../src/config-validation.ts","../../src/routing/manifest-codegen.ts","../../src/plugins/dev-precompile.ts","../../src/plugins/virtual-ids.ts","../../src/plugins/graph-endpoint.ts","../../src/server/compress.ts","../../src/plugins/dev-store-clear.ts","../../src/plugins/dev-server.ts"],"sourcesContent":["import { FastURL, getNativeClass, lazyInherit } from \"../_chunks/_url.mjs\";\nimport { createWaitUntil, fmtURL, printListening, resolvePortAndHost, resolveTLSOptions } from \"../_chunks/_utils2.mjs\";\nimport { createBodyTooLargeError, limitBodyStream } from \"../body-limit.mjs\";\nimport { errorPlugin, gracefulShutdownPlugin, wrapFetch } from \"../_chunks/_plugins.mjs\";\nimport { HOST_RE, forwardedHopValue, resolveClientIP, trustedHops } from \"../_chunks/_trust-proxy.mjs\";\nimport nodeHTTP, { IncomingMessage, ServerResponse } from \"node:http\";\nimport { Duplex, PassThrough, Readable, addAbortSignal } from \"node:stream\";\nimport { pipeline as pipeline$1 } from \"node:stream/promises\";\nimport nodeHTTPS from \"node:https\";\nimport nodeHTTP2 from \"node:http2\";\nfunction sendNodeResponse(nodeRes, webRes) {\n\ttry {\n\t\treturn _sendNodeResponse(nodeRes, webRes, false) || Promise.resolve();\n\t} catch (error) {\n\t\treturn Promise.reject(error);\n\t}\n}\nfunction sendNodeResponseDetached(nodeRes, webRes, silent) {\n\ttry {\n\t\treturn _sendNodeResponse(nodeRes, webRes, true);\n\t} catch (error) {\n\t\thandleSendError(nodeRes, error, silent);\n\t}\n}\nfunction handleSendError(nodeRes, error, silent) {\n\tif (!silent) console.error(\"[srvx] Failed to send response:\", error);\n\tfailResponse(nodeRes);\n}\nfunction sendErrorResponse(nodeRes, error, silent) {\n\tif (!silent) console.error(\"[srvx] Unhandled error in fetch handler:\", error);\n\tfailResponse(nodeRes);\n}\nfunction failResponse(nodeRes) {\n\tif (nodeRes.writableEnded) return;\n\tif (nodeRes.headersSent) nodeRes.destroy();\n\telse {\n\t\tnodeRes.statusCode = 500;\n\t\tif (nodeRes.req?.httpVersion !== \"2.0\") nodeRes.statusMessage = \"\";\n\t\tnodeRes.end();\n\t}\n}\nfunction _sendNodeResponse(nodeRes, webRes, detached) {\n\tif (!webRes) {\n\t\tnodeRes.statusCode = 500;\n\t\treturn endNodeResponse(nodeRes, detached);\n\t}\n\tif (webRes._toNodeResponse) {\n\t\tconst res = webRes._toNodeResponse();\n\t\tif (res.body) {\n\t\t\tif (res.body instanceof ReadableStream) {\n\t\t\t\twriteHead(nodeRes, res.status, res.statusText, res.headers);\n\t\t\t\treturn streamBody(res.body, nodeRes);\n\t\t\t} else if (typeof res.body?.pipe === \"function\") return pipeBody(res.body, nodeRes, res.status, res.statusText, res.headers);\n\t\t\twriteHead(nodeRes, res.status, res.statusText, res.headers);\n\t\t\tnodeRes.write(res.body);\n\t\t} else writeHead(nodeRes, res.status, res.statusText, res.headers);\n\t\treturn endNodeResponse(nodeRes, detached);\n\t}\n\tconst rawHeaders = [];\n\tfor (const [key, value] of webRes.headers) rawHeaders.push(key, value);\n\twriteHead(nodeRes, webRes.status, webRes.statusText, rawHeaders);\n\treturn webRes.body ? streamBody(webRes.body, nodeRes) : endNodeResponse(nodeRes, detached);\n}\nfunction writeHead(nodeRes, status, statusText, rawHeaders) {\n\tif (!nodeRes.headersSent) {\n\t\tif (nodeRes.req?.httpVersion === \"2.0\") nodeRes.writeHead(status, rawHeaders);\n\t\telse nodeRes.writeHead(status, safeStatusText(statusText), rawHeaders);\n\t}\n}\nconst INVALID_REASON_PHRASE_RE = /[^\\t\\u0020-\\u007E\\u0080-\\u00FF]/g;\nfunction safeStatusText(statusText) {\n\treturn typeof statusText === \"string\" && statusText ? statusText.replace(INVALID_REASON_PHRASE_RE, \"\") : statusText;\n}\nfunction endNodeResponse(nodeRes, detached) {\n\tif (detached) {\n\t\tnodeRes.end();\n\t\treturn;\n\t}\n\treturn new Promise((resolve) => nodeRes.end(resolve));\n}\nfunction pipeBody(stream, nodeRes, status, statusText, headers) {\n\tif (nodeRes.destroyed) {\n\t\tstream.destroy?.();\n\t\treturn;\n\t}\n\tif (nodeRes.req?.method === \"HEAD\") {\n\t\tif (typeof stream.destroy === \"function\") stream.destroy();\n\t\telse stream.abort?.();\n\t\twriteHead(nodeRes, status, statusText, headers);\n\t\treturn endNodeResponse(nodeRes);\n\t}\n\tif (typeof stream.on !== \"function\" || typeof stream.destroy !== \"function\") {\n\t\twriteHead(nodeRes, status, statusText, headers);\n\t\tstream.pipe(nodeRes);\n\t\treturn new Promise((resolve) => nodeRes.on(\"close\", resolve));\n\t}\n\tif (stream.readableEnded && !stream.errored) {\n\t\twriteHead(nodeRes, status, statusText, headers);\n\t\treturn endNodeResponse(nodeRes);\n\t}\n\tif (stream.destroyed) {\n\t\twriteHead(nodeRes, 500, \"Internal Server Error\", []);\n\t\treturn endNodeResponse(nodeRes);\n\t}\n\treturn new Promise((resolve) => {\n\t\tfunction cleanup() {\n\t\t\tstream.off(\"error\", onEarlyError);\n\t\t\tstream.off(\"readable\", onReadable);\n\t\t\tstream.off(\"end\", onEnd);\n\t\t\tnodeRes.off(\"close\", onResClose);\n\t\t}\n\t\tfunction onEarlyError() {\n\t\t\tcleanup();\n\t\t\tstream.destroy();\n\t\t\twriteHead(nodeRes, 500, \"Internal Server Error\", []);\n\t\t\tendNodeResponse(nodeRes).then(resolve);\n\t\t}\n\t\tfunction onReadable() {\n\t\t\tcleanup();\n\t\t\tif (nodeRes.destroyed) {\n\t\t\t\tstream.destroy();\n\t\t\t\treturn resolve();\n\t\t\t}\n\t\t\twriteHead(nodeRes, status, statusText, headers);\n\t\t\tpipeline$1(stream, nodeRes).catch(() => {}).then(() => resolve());\n\t\t}\n\t\tfunction onEnd() {\n\t\t\tcleanup();\n\t\t\tif (nodeRes.destroyed) return resolve();\n\t\t\twriteHead(nodeRes, status, statusText, headers);\n\t\t\tendNodeResponse(nodeRes).then(resolve);\n\t\t}\n\t\tfunction onResClose() {\n\t\t\tcleanup();\n\t\t\tstream.destroy();\n\t\t\tresolve();\n\t\t}\n\t\tstream.once(\"error\", onEarlyError);\n\t\tstream.once(\"readable\", onReadable);\n\t\tstream.once(\"end\", onEnd);\n\t\tnodeRes.once(\"close\", onResClose);\n\t});\n}\nfunction streamBody(stream, nodeRes) {\n\tif (nodeRes.destroyed) {\n\t\tstream.cancel().catch(() => {});\n\t\treturn;\n\t}\n\tif (nodeRes.req?.method === \"HEAD\") {\n\t\tstream.cancel().catch(() => {});\n\t\treturn endNodeResponse(nodeRes);\n\t}\n\tconst reader = stream.getReader();\n\tfunction streamCancel(error) {\n\t\treader.cancel(error).catch(() => {});\n\t\tif (error) nodeRes.destroy(error);\n\t}\n\tfunction streamHandle({ done, value }) {\n\t\ttry {\n\t\t\tif (done) nodeRes.end();\n\t\t\telse if (nodeRes.write(value)) reader.read().then(streamHandle, streamCancel);\n\t\t\telse nodeRes.once(\"drain\", () => reader.read().then(streamHandle, streamCancel));\n\t\t} catch (error) {\n\t\t\tstreamCancel(error instanceof Error ? error : void 0);\n\t\t}\n\t}\n\tnodeRes.on(\"close\", streamCancel);\n\tnodeRes.on(\"error\", streamCancel);\n\treader.read().then(streamHandle, streamCancel);\n\treturn reader.closed.catch(streamCancel).finally(() => {\n\t\tnodeRes.off(\"close\", streamCancel);\n\t\tnodeRes.off(\"error\", streamCancel);\n\t});\n}\nvar NodeRequestURL = class extends FastURL {\n\tconstructor({ req, hops = 0 }) {\n\t\tconst path = req.url || \"/\";\n\t\tconst trusted = hops > 0;\n\t\tconst forwardedHost = forwardedHopValue(req.headers[\"x-forwarded-host\"], hops);\n\t\tlet host = (forwardedHost && HOST_RE.test(forwardedHost) ? forwardedHost : void 0) || req.headers.host || req.headers[\":authority\"];\n\t\tif (host && !HOST_RE.test(host)) host = \"_invalid_\";\n\t\telse if (!host) {\n\t\t\tif (req.socket) host = `${req.socket.localFamily === \"IPv6\" ? \"[\" + req.socket.localAddress + \"]\" : req.socket.localAddress}:${req.socket?.localPort || \"80\"}`;\n\t\t\telse host = \"localhost\";\n\t\t}\n\t\tconst forwardedProto = forwardedHopValue(req.headers[\"x-forwarded-proto\"], hops);\n\t\tconst protocol = req.socket?.encrypted || forwardedProto === \"https\" || trusted && req.headers[\":scheme\"] === \"https\" ? \"https:\" : \"http:\";\n\t\tif (path[0] === \"/\") {\n\t\t\tconst qIndex = path.indexOf(\"?\");\n\t\t\tsuper({\n\t\t\t\tprotocol,\n\t\t\t\thost,\n\t\t\t\tpathname: qIndex === -1 ? path : path.slice(0, qIndex) || \"/\",\n\t\t\t\tsearch: qIndex === -1 ? \"\" : path.slice(qIndex) || \"\"\n\t\t\t});\n\t\t} else if (path === \"*\") super({\n\t\t\tprotocol,\n\t\t\thost,\n\t\t\tpathname: \"/*\",\n\t\t\tsearch: \"\"\n\t\t});\n\t\telse {\n\t\t\tconst target = URL.canParse(path) ? new URL(path) : void 0;\n\t\t\tif (target) {\n\t\t\t\tconst targetHost = target.host;\n\t\t\t\tconst targetPath = target.pathname;\n\t\t\t\tsuper({\n\t\t\t\t\tprotocol,\n\t\t\t\t\thost: targetHost ? HOST_RE.test(targetHost) ? targetHost : \"_invalid_\" : host,\n\t\t\t\t\tpathname: targetPath ? targetPath[0] === \"/\" ? targetPath : `/${targetPath}` : \"/\",\n\t\t\t\t\tsearch: target.search\n\t\t\t\t});\n\t\t\t} else super({\n\t\t\t\tprotocol,\n\t\t\t\thost,\n\t\t\t\tpathname: \"/\",\n\t\t\t\tsearch: \"\"\n\t\t\t});\n\t\t}\n\t}\n};\nfunction isValidAbsoluteForm(target) {\n\tif (!URL.canParse(target)) return false;\n\tconst url = new URL(target);\n\treturn (url.protocol === \"http:\" || url.protocol === \"https:\") && url.host !== \"\";\n}\nconst _nonJoinedHeaders = /* @__PURE__ */ new Set([\n\t\"age\",\n\t\"authorization\",\n\t\"content-length\",\n\t\"content-type\",\n\t\"etag\",\n\t\"expires\",\n\t\"from\",\n\t\"host\",\n\t\"if-modified-since\",\n\t\"if-unmodified-since\",\n\t\"last-modified\",\n\t\"location\",\n\t\"max-forwards\",\n\t\"proxy-authorization\",\n\t\"referer\",\n\t\"retry-after\",\n\t\"server\",\n\t\"user-agent\"\n]);\nconst _validHeaderNameRE = /^[!#$%&'*+\\-.^_`|~\\dA-Za-z]+$/;\nfunction _isRepeated(rawHeaders, lowerName) {\n\tlet seen = false;\n\tfor (let i = 0; i < rawHeaders.length; i += 2) {\n\t\tconst key = rawHeaders[i];\n\t\tif (key.length === lowerName.length && key.toLowerCase() === lowerName) {\n\t\t\tif (seen) return true;\n\t\t\tseen = true;\n\t\t}\n\t}\n\treturn false;\n}\nconst NodeRequestHeaders = /* @__PURE__ */ (() => {\n\tconst NativeHeaders = globalThis.Headers;\n\tclass Headers {\n\t\t#req;\n\t\t#headers;\n\t\tconstructor(req) {\n\t\t\tthis.#req = req;\n\t\t}\n\t\tstatic [Symbol.hasInstance](val) {\n\t\t\treturn val instanceof NativeHeaders;\n\t\t}\n\t\t_adopt(headers) {\n\t\t\tthis.#headers = headers;\n\t\t}\n\t\tget _headers() {\n\t\t\tif (!this.#headers) {\n\t\t\t\tconst headers = new NativeHeaders();\n\t\t\t\tconst rawHeaders = this.#req.rawHeaders;\n\t\t\t\tconst len = rawHeaders.length;\n\t\t\t\tfor (let i = 0; i < len; i += 2) {\n\t\t\t\t\tconst key = rawHeaders[i];\n\t\t\t\t\tif (key.charCodeAt(0) === 58) continue;\n\t\t\t\t\tconst value = rawHeaders[i + 1];\n\t\t\t\t\theaders.append(key, value);\n\t\t\t\t}\n\t\t\t\tthis.#headers = headers;\n\t\t\t}\n\t\t\treturn this.#headers;\n\t\t}\n\t\tget(name) {\n\t\t\tif (this.#headers) return this.#headers.get(name);\n\t\t\tconst lower = name.toLowerCase();\n\t\t\tif (lower.charCodeAt(0) === 58) return this._headers.get(name);\n\t\t\tconst value = this.#req.headers[lower];\n\t\t\tif (typeof value === \"string\") return _nonJoinedHeaders.has(lower) && _isRepeated(this.#req.rawHeaders, lower) ? this._headers.get(name) : value;\n\t\t\tif (Array.isArray(value)) return value.join(\", \");\n\t\t\treturn lower !== \"__proto__\" && _validHeaderNameRE.test(name) ? null : this._headers.get(name);\n\t\t}\n\t\thas(name) {\n\t\t\tif (this.#headers) return this.#headers.has(name);\n\t\t\tconst lower = name.toLowerCase();\n\t\t\tif (lower.charCodeAt(0) === 58) return this._headers.has(name);\n\t\t\tif (Object.hasOwn(this.#req.headers, lower)) return true;\n\t\t\treturn lower !== \"__proto__\" && _validHeaderNameRE.test(name) ? false : this._headers.has(name);\n\t\t}\n\t\tgetSetCookie() {\n\t\t\tif (this.#headers) return this.#headers.getSetCookie();\n\t\t\tconst value = this.#req.headers[\"set-cookie\"];\n\t\t\treturn Array.isArray(value) ? value.slice() : value ? [value] : [];\n\t\t}\n\t\tentries() {\n\t\t\treturn this._headers.entries();\n\t\t}\n\t\t[Symbol.iterator]() {\n\t\t\treturn this.entries();\n\t\t}\n\t}\n\tlazyInherit(Headers.prototype, NativeHeaders.prototype, \"_headers\");\n\tObject.setPrototypeOf(Headers, NativeHeaders);\n\tObject.setPrototypeOf(Headers.prototype, NativeHeaders.prototype);\n\treturn Headers;\n})();\nconst kNativeRequest = /* @__PURE__ */ Symbol.for(\"srvx.nativeRequest\");\nfunction bodyUnusable() {\n\treturn /* @__PURE__ */ new TypeError(\"Body is unusable: Body has already been read\");\n}\nfunction abortError() {\n\treturn new DOMException(\"The request was aborted.\", \"AbortError\");\n}\nfunction erroredStream(error) {\n\treturn new ReadableStream({ start(controller) {\n\t\tcontroller.error(error);\n\t} });\n}\nfunction isClientGone(req) {\n\treturn req.aborted || !!req.errored || req.destroyed && !req.complete;\n}\nfunction isBodySourceFinished(req) {\n\treturn isClientGone(req) || req.destroyed || req.readableEnded;\n}\nconst NodeRequest = /* @__PURE__ */ (() => {\n\tconst NativeRequest = getNativeClass(kNativeRequest, globalThis.Request);\n\tclass Request {\n\t\truntime;\n\t\twaitUntil;\n\t\t#req;\n\t\t#url;\n\t\t#bodyStream;\n\t\t#bodyUsed = false;\n\t\t#request;\n\t\t#headers;\n\t\t#abortController;\n\t\t#maxRequestBodySize;\n\t\t#trustProxy;\n\t\t#ip;\n\t\t#ipResolved = false;\n\t\t#remoteAddress;\n\t\t#remoteResolved = false;\n\t\t#hops;\n\t\tconstructor(ctx) {\n\t\t\tthis.#req = ctx.req;\n\t\t\tthis.#maxRequestBodySize = ctx.maxRequestBodySize;\n\t\t\tthis.#trustProxy = ctx.trustProxy;\n\t\t\tthis.runtime = {\n\t\t\t\tname: \"node\",\n\t\t\t\tnode: ctx\n\t\t\t};\n\t\t}\n\t\tstatic [Symbol.hasInstance](val) {\n\t\t\treturn val instanceof NativeRequest;\n\t\t}\n\t\t#remoteAddr() {\n\t\t\tif (!this.#remoteResolved) {\n\t\t\t\tthis.#remoteResolved = true;\n\t\t\t\tthis.#remoteAddress = this.#req.socket?.remoteAddress;\n\t\t\t}\n\t\t\treturn this.#remoteAddress;\n\t\t}\n\t\t#resolveHops() {\n\t\t\tif (this.#hops === void 0) this.#hops = trustedHops(this.#trustProxy, this.#remoteAddr(), this.#req.headers[\"x-forwarded-for\"]);\n\t\t\treturn this.#hops;\n\t\t}\n\t\tget ip() {\n\t\t\tif (this.#ipResolved) return this.#ip;\n\t\t\tthis.#ipResolved = true;\n\t\t\treturn this.#ip = resolveClientIP(this.#trustProxy, this.#remoteAddr(), this.#req.headers[\"x-forwarded-for\"]);\n\t\t}\n\t\tget method() {\n\t\t\tif (this.#request) return this.#request.method;\n\t\t\treturn this.#req.method || \"GET\";\n\t\t}\n\t\tget _url() {\n\t\t\treturn this.#url ||= new NodeRequestURL({\n\t\t\t\treq: this.#req,\n\t\t\t\thops: this.#resolveHops()\n\t\t\t});\n\t\t}\n\t\tset _url(url) {\n\t\t\tthis.#url = url;\n\t\t}\n\t\tget url() {\n\t\t\tif (this.#request) return this.#request.url;\n\t\t\treturn this._url.href;\n\t\t}\n\t\tget headers() {\n\t\t\treturn this.#headers ||= new NodeRequestHeaders(this.#req);\n\t\t}\n\t\tget _abortController() {\n\t\t\tif (!this.#abortController) {\n\t\t\t\tthis.#abortController = new AbortController();\n\t\t\t\tconst { req, res } = this.runtime.node;\n\t\t\t\tconst abortController = this.#abortController;\n\t\t\t\tconst abort = (err) => abortController.abort?.(err);\n\t\t\t\tif (res) {\n\t\t\t\t\tconst onClose = () => {\n\t\t\t\t\t\tconst reqError = req.errored;\n\t\t\t\t\t\tif (reqError) abort(reqError);\n\t\t\t\t\t\telse if (!res.writableEnded) abort();\n\t\t\t\t\t};\n\t\t\t\t\tres.once(\"close\", onClose);\n\t\t\t\t\tif (res.destroyed || isClientGone(req)) onClose();\n\t\t\t\t} else {\n\t\t\t\t\tconst onClose = () => {\n\t\t\t\t\t\tif (!req.complete || req.aborted) abort();\n\t\t\t\t\t};\n\t\t\t\t\treq.once(\"close\", onClose);\n\t\t\t\t\tif (isClientGone(req)) onClose();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn this.#abortController;\n\t\t}\n\t\tget signal() {\n\t\t\treturn this.#request ? this.#request.signal : this._abortController.signal;\n\t\t}\n\t\t#hasBody() {\n\t\t\tconst method = this.method;\n\t\t\treturn method !== \"GET\" && method !== \"HEAD\";\n\t\t}\n\t\tget body() {\n\t\t\tif (this.#request) return this.#request.body;\n\t\t\tif (this.#bodyStream === void 0) {\n\t\t\t\tlet stream = null;\n\t\t\t\tif (this.#hasBody() && !this.#bodyUsed) {\n\t\t\t\t\tif (\"rawBody\" in this.#req && Buffer.isBuffer(this.#req.rawBody)) stream = Readable.toWeb(Readable.from([this.#req.rawBody]));\n\t\t\t\t\telse if (isBodySourceFinished(this.#req)) stream = erroredStream(this.#bodyError());\n\t\t\t\t\telse stream = Readable.toWeb(this.#req);\n\t\t\t\t}\n\t\t\t\tif (stream && this.#maxRequestBodySize !== void 0) stream = limitBodyStream(stream, this.#maxRequestBodySize);\n\t\t\t\tthis.#bodyStream = stream;\n\t\t\t}\n\t\t\treturn this.#bodyStream;\n\t\t}\n\t\tget bodyUsed() {\n\t\t\tif (this.#isBodyUsed()) return true;\n\t\t\treturn this.#request ? this.#request.bodyUsed : false;\n\t\t}\n\t\t#isBodyUsed() {\n\t\t\tif (!this.#bodyUsed && this.#bodyStream && Readable.isDisturbed(this.#bodyStream)) this.#bodyUsed = true;\n\t\t\treturn this.#bodyUsed;\n\t\t}\n\t\t#bodyError() {\n\t\t\tconst signal = this._abortController.signal;\n\t\t\tif (signal.aborted) return signal.reason;\n\t\t\treturn this.#req.errored || (isClientGone(this.#req) ? abortError() : bodyUnusable());\n\t\t}\n\t\t#readBuffered() {\n\t\t\tif (\"rawBody\" in this.#req && Buffer.isBuffer(this.#req.rawBody)) return readBody(this.#req, this.#maxRequestBodySize);\n\t\t\tif (isBodySourceFinished(this.#req)) return Promise.reject(this.#bodyError());\n\t\t\treturn readBody(this.#req, this.#maxRequestBodySize);\n\t\t}\n\t\ttext() {\n\t\t\tif (this.#isBodyUsed()) return Promise.reject(bodyUnusable());\n\t\t\tif (this.#request) return this.#request.text();\n\t\t\tif (!this.#hasBody()) return Promise.resolve(\"\");\n\t\t\tthis.#bodyUsed = true;\n\t\t\tif (this.#bodyStream !== void 0) try {\n\t\t\t\treturn new Response(this.#bodyStream).text();\n\t\t\t} catch (error) {\n\t\t\t\treturn Promise.reject(error);\n\t\t\t}\n\t\t\treturn this.#readBuffered().then((buf) => buf.toString());\n\t\t}\n\t\tjson() {\n\t\t\tif (this.#isBodyUsed()) return Promise.reject(bodyUnusable());\n\t\t\tif (this.#request) return this.#request.json();\n\t\t\tif (!this.#hasBody()) return Promise.resolve().then(() => JSON.parse(\"\"));\n\t\t\tthis.#bodyUsed = true;\n\t\t\tif (this.#bodyStream !== void 0) try {\n\t\t\t\treturn new Response(this.#bodyStream).json();\n\t\t\t} catch (error) {\n\t\t\t\treturn Promise.reject(error);\n\t\t\t}\n\t\t\treturn this.#readBuffered().then((buf) => JSON.parse(buf.toString()));\n\t\t}\n\t\tarrayBuffer() {\n\t\t\treturn this.#consumeNative(\"arrayBuffer\");\n\t\t}\n\t\tbytes() {\n\t\t\treturn this.#consumeNative(\"bytes\");\n\t\t}\n\t\tblob() {\n\t\t\treturn this.#consumeNative(\"blob\");\n\t\t}\n\t\tformData() {\n\t\t\treturn this.#consumeNative(\"formData\");\n\t\t}\n\t\t#consumeNative(method) {\n\t\t\tif (this.#isBodyUsed()) return Promise.reject(bodyUnusable());\n\t\t\ttry {\n\t\t\t\treturn this._request[method]();\n\t\t\t} catch (error) {\n\t\t\t\treturn Promise.reject(error);\n\t\t\t}\n\t\t}\n\t\tget _request() {\n\t\t\tif (!this.#request) {\n\t\t\t\tconst body = this.#isBodyUsed() ? null : this.body;\n\t\t\t\tthis.#request = new NativeRequest(this.url, {\n\t\t\t\t\tmethod: this.method,\n\t\t\t\t\theaders: this.headers,\n\t\t\t\t\tsignal: this._abortController.signal,\n\t\t\t\t\tbody,\n\t\t\t\t\tduplex: body ? \"half\" : void 0\n\t\t\t\t});\n\t\t\t\tthis.#headers._adopt(this.#request.headers);\n\t\t\t\tthis.#bodyStream = void 0;\n\t\t\t}\n\t\t\treturn this.#request;\n\t\t}\n\t}\n\tlazyInherit(Request.prototype, NativeRequest.prototype, \"_request\");\n\tObject.setPrototypeOf(Request.prototype, NativeRequest.prototype);\n\treturn Request;\n})();\nfunction patchGlobalRequest() {\n\tif (globalThis.Request._srvx) return globalThis.Request;\n\tconst NativeRequest = getNativeClass(kNativeRequest, globalThis.Request);\n\tconst PatchedRequest = class Request extends NativeRequest {\n\t\tstatic _srvx = true;\n\t\tstatic [Symbol.hasInstance](instance) {\n\t\t\tif (this === PatchedRequest) return instance instanceof NativeRequest;\n\t\t\telse return Object.prototype.isPrototypeOf.call(this.prototype, instance);\n\t\t}\n\t\tconstructor(input, options) {\n\t\t\tif (typeof input === \"object\" && \"_request\" in input) input = input._request;\n\t\t\tsuper(input, options);\n\t\t}\n\t};\n\tglobalThis.Request = PatchedRequest;\n\treturn PatchedRequest;\n}\nfunction readBody(req, maxRequestBodySize) {\n\tif (\"rawBody\" in req && Buffer.isBuffer(req.rawBody)) {\n\t\tif (maxRequestBodySize !== void 0 && req.rawBody.length > maxRequestBodySize) return Promise.reject(createBodyTooLargeError(maxRequestBodySize));\n\t\treturn Promise.resolve(req.rawBody);\n\t}\n\treturn new Promise((resolve, reject) => {\n\t\tconst chunks = [];\n\t\tlet size = 0;\n\t\tconst cleanup = () => {\n\t\t\treq.off(\"data\", onData);\n\t\t\treq.off(\"end\", onEnd);\n\t\t\treq.off(\"error\", onError);\n\t\t\treq.off(\"close\", onClose);\n\t\t};\n\t\tconst onData = (chunk) => {\n\t\t\tif (maxRequestBodySize !== void 0) {\n\t\t\t\tsize += chunk.length;\n\t\t\t\tif (size > maxRequestBodySize) {\n\t\t\t\t\tcleanup();\n\t\t\t\t\treq.pause?.();\n\t\t\t\t\treject(createBodyTooLargeError(maxRequestBodySize));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tchunks.push(chunk);\n\t\t};\n\t\tconst onError = (err) => {\n\t\t\tcleanup();\n\t\t\treject(err);\n\t\t};\n\t\tconst onEnd = () => {\n\t\t\tcleanup();\n\t\t\tif (isClientGone(req)) {\n\t\t\t\treject(req.errored || abortError());\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tresolve(chunks.length === 1 ? chunks[0] : Buffer.concat(chunks));\n\t\t};\n\t\tconst onClose = () => {\n\t\t\tcleanup();\n\t\t\treject(req.errored || abortError());\n\t\t};\n\t\treq.on(\"data\", onData).once(\"end\", onEnd).once(\"error\", onError).once(\"close\", onClose);\n\t});\n}\nconst kNativeResponse = /* @__PURE__ */ Symbol.for(\"srvx.nativeResponse\");\nconst NodeResponse = /* @__PURE__ */ (() => {\n\tconst NativeResponse = getNativeClass(kNativeResponse, globalThis.Response);\n\tclass NodeResponse {\n\t\t#body;\n\t\t#init;\n\t\t#headers;\n\t\t#response;\n\t\t#contentLength;\n\t\tconstructor(body, init) {\n\t\t\tthis.#body = body;\n\t\t\tthis.#init = init;\n\t\t}\n\t\tstatic [Symbol.hasInstance](val) {\n\t\t\tif (this === NodeResponse) return val instanceof NativeResponse;\n\t\t\treturn Object.prototype.isPrototypeOf.call(this.prototype, val);\n\t\t}\n\t\tstatic json(data, init) {\n\t\t\tconst body = JSON.stringify(data);\n\t\t\tif (body === void 0) throw new TypeError(\"Value is not JSON serializable\");\n\t\t\tlet headers = init?.headers;\n\t\t\tif (!headers) headers = { \"content-type\": \"application/json\" };\n\t\t\telse {\n\t\t\t\tconst merged = new Headers(headers);\n\t\t\t\tif (!merged.has(\"content-type\")) merged.set(\"content-type\", \"application/json\");\n\t\t\t\theaders = merged;\n\t\t\t}\n\t\t\treturn new NodeResponse(body, init ? {\n\t\t\t\t...init,\n\t\t\t\theaders\n\t\t\t} : { headers });\n\t\t}\n\t\tget status() {\n\t\t\treturn this.#response?.status || this.#init?.status || 200;\n\t\t}\n\t\tget statusText() {\n\t\t\treturn this.#response?.statusText || this.#init?.statusText || \"\";\n\t\t}\n\t\tget headers() {\n\t\t\tif (this.#response) return this.#response.headers;\n\t\t\tif (this.#headers) return this.#headers;\n\t\t\treturn this.#headers = new Headers(this.#init?.headers);\n\t\t}\n\t\tget ok() {\n\t\t\tif (this.#response) return this.#response.ok;\n\t\t\tconst status = this.status;\n\t\t\treturn status >= 200 && status < 300;\n\t\t}\n\t\tget _response() {\n\t\t\tif (this.#response) return this.#response;\n\t\t\tlet body = this.#body;\n\t\t\tif (body && typeof body.pipe === \"function\" && !(body instanceof Readable)) {\n\t\t\t\tconst stream = new PassThrough();\n\t\t\t\tbody.pipe(stream);\n\t\t\t\tconst abort = body.abort;\n\t\t\t\tif (abort) stream.once(\"close\", () => abort());\n\t\t\t\tbody = stream;\n\t\t\t}\n\t\t\tif (typeof body === \"string\") this.#contentLength = Buffer.byteLength(body);\n\t\t\telse if (body instanceof ArrayBuffer || body instanceof Uint8Array || body instanceof DataView) this.#contentLength = body.byteLength;\n\t\t\telse if (body instanceof Blob) this.#contentLength = body.size;\n\t\t\tthis.#response = new NativeResponse(body, this.#headers ? {\n\t\t\t\t...this.#init,\n\t\t\t\theaders: this.#headers\n\t\t\t} : this.#init);\n\t\t\tthis.#init = void 0;\n\t\t\tthis.#headers = void 0;\n\t\t\tthis.#body = void 0;\n\t\t\treturn this.#response;\n\t\t}\n\t\t_toNodeResponse() {\n\t\t\tconst status = this.status;\n\t\t\tconst statusText = this.statusText;\n\t\t\tlet body;\n\t\t\tlet contentType;\n\t\t\tlet contentLength;\n\t\t\tif (this.#response) {\n\t\t\t\tbody = this.#response.body;\n\t\t\t\tif (!this.#response.bodyUsed) contentLength = this.#contentLength;\n\t\t\t} else if (this.#body != null) {\n\t\t\t\tif (this.#body instanceof ReadableStream) body = this.#body;\n\t\t\t\telse if (typeof this.#body === \"string\") {\n\t\t\t\t\tbody = this.#body;\n\t\t\t\t\tcontentType = \"text/plain; charset=UTF-8\";\n\t\t\t\t\tcontentLength = Buffer.byteLength(this.#body);\n\t\t\t\t} else if (this.#body instanceof ArrayBuffer) {\n\t\t\t\t\tbody = Buffer.from(this.#body);\n\t\t\t\t\tcontentLength = this.#body.byteLength;\n\t\t\t\t} else if (this.#body instanceof Uint8Array) {\n\t\t\t\t\tbody = this.#body;\n\t\t\t\t\tcontentLength = this.#body.byteLength;\n\t\t\t\t} else if (this.#body instanceof DataView) {\n\t\t\t\t\tbody = Buffer.from(this.#body.buffer, this.#body.byteOffset, this.#body.byteLength);\n\t\t\t\t\tcontentLength = this.#body.byteLength;\n\t\t\t\t} else if (this.#body instanceof Blob) {\n\t\t\t\t\tbody = this.#body.stream();\n\t\t\t\t\tcontentType = this.#body.type;\n\t\t\t\t\tcontentLength = this.#body.size;\n\t\t\t\t} else if (typeof this.#body.pipe === \"function\") body = this.#body;\n\t\t\t\telse body = this._response.body;\n\t\t\t}\n\t\t\tconst headers = [];\n\t\t\tconst initHeaders = this.#init?.headers;\n\t\t\tconst headerEntries = this.#response?.headers || this.#headers || (initHeaders ? Array.isArray(initHeaders) ? initHeaders : initHeaders?.entries ? initHeaders.entries() : Object.entries(initHeaders) : void 0);\n\t\t\tlet hasContentTypeHeader;\n\t\t\tlet hasContentLength;\n\t\t\tif (headerEntries) for (const [key, value] of headerEntries) {\n\t\t\t\tconst lowerKey = typeof key === \"string\" ? key.toLowerCase() : String(key);\n\t\t\t\tif (Array.isArray(value)) for (const v of value) headers.push(lowerKey, v);\n\t\t\t\telse headers.push(lowerKey, value);\n\t\t\t\tif (lowerKey === \"content-type\") hasContentTypeHeader = true;\n\t\t\t\telse if (lowerKey === \"content-length\") hasContentLength = true;\n\t\t\t}\n\t\t\tif (contentType && !hasContentTypeHeader) headers.push(\"content-type\", contentType);\n\t\t\tif (contentLength != null && !hasContentLength) headers.push(\"content-length\", String(contentLength));\n\t\t\tthis.#init = void 0;\n\t\t\tthis.#headers = void 0;\n\t\t\tthis.#response = void 0;\n\t\t\tthis.#contentLength = void 0;\n\t\t\tthis.#body = void 0;\n\t\t\treturn {\n\t\t\t\tstatus,\n\t\t\t\tstatusText,\n\t\t\t\theaders,\n\t\t\t\tbody\n\t\t\t};\n\t\t}\n\t}\n\tlazyInherit(NodeResponse.prototype, NativeResponse.prototype, \"_response\");\n\tObject.setPrototypeOf(NodeResponse, NativeResponse);\n\tObject.setPrototypeOf(NodeResponse.prototype, NativeResponse.prototype);\n\treturn NodeResponse;\n})();\nfunction prematureCloseError() {\n\treturn Object.assign(/* @__PURE__ */ new Error(\"Connection closed before response was finished\"), { code: \"ERR_STREAM_PREMATURE_CLOSE\" });\n}\nvar WebRequestSocket = class extends Duplex {\n\t_httpMessage;\n\tautoSelectFamilyAttemptedAddresses = [];\n\tbufferSize = 0;\n\tbytesRead = 0;\n\tbytesWritten = 0;\n\tconnecting = false;\n\tpending = false;\n\treadyState = \"open\";\n\tserver = null;\n\tremoteAddress = \"\";\n\tremoteFamily = \"\";\n\tremotePort = 0;\n\t#request;\n\t#timeoutTimer;\n\t#reqReader;\n\t#headersWritten;\n\t#_writeBody;\n\t#resBodyController;\n\t#resBodyClosed;\n\t_webResBody;\n\t#tos = 0;\n\tconstructor(request) {\n\t\tsuper({ allowHalfOpen: true });\n\t\tthis.#request = request;\n\t\tthis._webResBody = new ReadableStream({ start: (controller) => {\n\t\t\tthis.#resBodyController = controller;\n\t\t\tthis.#_writeBody = controller.enqueue.bind(controller);\n\t\t\tthis.once(\"finish\", () => {\n\t\t\t\tthis.readyState = \"closed\";\n\t\t\t\tthis.#resBodyClosed = true;\n\t\t\t\tcontroller.close();\n\t\t\t});\n\t\t} });\n\t\tif (request.signal) addAbortSignal(request.signal, this);\n\t}\n\tsetTimeout(ms, cb) {\n\t\tif (typeof ms !== \"number\" || !Number.isFinite(ms) || ms < 0) return this;\n\t\tif (cb) this.on(\"timeout\", cb);\n\t\tif (this.#timeoutTimer) clearTimeout(this.#timeoutTimer);\n\t\tif (ms > 0) this.#timeoutTimer = setTimeout(() => this.emit(\"timeout\"), ms);\n\t\treturn this;\n\t}\n\tsetNoDelay() {\n\t\treturn this;\n\t}\n\tsetKeepAlive() {\n\t\treturn this;\n\t}\n\tref() {\n\t\treturn this;\n\t}\n\tunref() {\n\t\treturn this;\n\t}\n\tdestroySoon() {\n\t\tthis.destroy();\n\t}\n\tconnect() {\n\t\treturn this;\n\t}\n\tresetAndDestroy() {\n\t\tthis.destroy();\n\t\treturn this;\n\t}\n\taddress() {\n\t\treturn {\n\t\t\taddress: \"\",\n\t\t\tfamily: \"\",\n\t\t\tport: 0\n\t\t};\n\t}\n\tbodyReader() {\n\t\ttry {\n\t\t\treturn this.#request.body?.getReader();\n\t\t} catch (error) {\n\t\t\tthis.emit(\"error\", error);\n\t\t}\n\t}\n\tgetTypeOfService() {\n\t\treturn this.#tos;\n\t}\n\tsetTypeOfService(tos) {\n\t\tthis.#tos = tos;\n\t\treturn this;\n\t}\n\t_read(_size) {\n\t\tconst reader = this.#reqReader ??= this.bodyReader();\n\t\tif (!reader) {\n\t\t\tthis.push(null);\n\t\t\treturn;\n\t\t}\n\t\treader.read().then((res) => this._onRead(res)).catch((error) => {\n\t\t\tthis.emit(\"error\", error);\n\t\t});\n\t}\n\t_onRead(res) {\n\t\tif (res.done) {\n\t\t\tthis.push(null);\n\t\t\treturn;\n\t\t}\n\t\tif (res.value) {\n\t\t\tthis.bytesRead += res.value.byteLength;\n\t\t\tthis.push(res.value);\n\t\t}\n\t}\n\t_write(chunk, encoding, callback) {\n\t\tif (this.#headersWritten) this.#_writeBody(typeof chunk === \"string\" ? Buffer.from(chunk, encoding) : chunk);\n\t\telse if (chunk?.length > 0) {\n\t\t\tthis.#headersWritten = true;\n\t\t\tconst headerEnd = chunk.indexOf(\"\\r\\n\\r\\n\");\n\t\t\tif (headerEnd === -1) throw new Error(\"Invalid HTTP headers chunk!\");\n\t\t\tif (headerEnd < chunk.length - 4) {\n\t\t\t\tthis._write(chunk.slice(headerEnd + 4), encoding, () => {\n\t\t\t\t\tcallback(null);\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tcallback(null);\n\t}\n\t_final(callback) {\n\t\tcallback(null);\n\t}\n\t_destroy(err, cb) {\n\t\tif (this.#timeoutTimer) clearTimeout(this.#timeoutTimer);\n\t\tif (this.#reqReader) this.#reqReader.cancel().catch((error) => {\n\t\t\tconsole.error(error);\n\t\t});\n\t\tif (!this.#resBodyClosed) {\n\t\t\tthis.#resBodyClosed = true;\n\t\t\ttry {\n\t\t\t\tthis.#resBodyController?.error(err ?? prematureCloseError());\n\t\t\t} catch {}\n\t\t}\n\t\tthis.readyState = \"closed\";\n\t\tcb(err ?? void 0);\n\t}\n};\nvar WebIncomingMessage = class extends IncomingMessage {\n\t#socket;\n\tconstructor(req, socket) {\n\t\tsuper(socket);\n\t\tthis.#socket = socket;\n\t\tthis.method = req.method;\n\t\tconst url = req._url ??= new FastURL(req.url);\n\t\tthis.url = url.pathname + url.search;\n\t\tthis.httpVersionMajor = 1;\n\t\tthis.httpVersionMinor = 1;\n\t\tthis.httpVersion = \"1.1\";\n\t\tconst headers = {};\n\t\tconst rawHeaders = this.rawHeaders;\n\t\tfor (const [key, value] of req.headers.entries()) {\n\t\t\tconst lowerKey = key.toLowerCase();\n\t\t\tif (lowerKey === \"set-cookie\") continue;\n\t\t\theaders[lowerKey] = value;\n\t\t\trawHeaders.push(key, value);\n\t\t}\n\t\tconst setCookie = req.headers.getSetCookie?.() ?? [];\n\t\tif (setCookie.length > 0) {\n\t\t\theaders[\"set-cookie\"] = setCookie;\n\t\t\tfor (const cookie of setCookie) rawHeaders.push(\"set-cookie\", cookie);\n\t\t}\n\t\tif (req.method !== \"GET\" && req.method !== \"HEAD\" && !headers[\"content-length\"] && !headers[\"transfer-encoding\"]) headers[\"transfer-encoding\"] = \"chunked\";\n\t\tthis.headers = headers;\n\t\tconst onData = (chunk) => {\n\t\t\tif (!this.push(chunk)) socket.pause();\n\t\t};\n\t\tsocket.on(\"data\", onData);\n\t\tsocket.once(\"end\", () => {\n\t\t\tthis.complete = true;\n\t\t\tthis.push(null);\n\t\t\tsocket.off(\"data\", onData);\n\t\t});\n\t}\n\t_read(_size) {\n\t\tthis.#socket.resume();\n\t}\n\t_destroy(_err, cb) {\n\t\tcb();\n\t}\n};\nfunction callNodeHandler(handler, req) {\n\tconst isMiddleware = handler.length > 2;\n\tconst nodeCtx = req.runtime?.node;\n\tif (!nodeCtx || !nodeCtx.req || !nodeCtx.res) throw new Error(\"Node.js runtime context is not available.\");\n\tconst { req: nodeReq, res: nodeRes } = nodeCtx;\n\tlet _headers;\n\tconst webRes = new NodeResponse(void 0, {\n\t\tget status() {\n\t\t\treturn nodeRes.statusCode;\n\t\t},\n\t\tget statusText() {\n\t\t\treturn nodeRes.statusMessage;\n\t\t},\n\t\tget headers() {\n\t\t\tif (!_headers) {\n\t\t\t\tconst headerEntries = [];\n\t\t\t\tconst rawHeaders = nodeRes.getHeaders();\n\t\t\t\tfor (const [name, value] of Object.entries(rawHeaders)) if (Array.isArray(value)) for (const v of value) headerEntries.push([name, v]);\n\t\t\t\telse if (value) headerEntries.push([name, String(value)]);\n\t\t\t\t_headers = new Headers(headerEntries);\n\t\t\t}\n\t\t\treturn _headers;\n\t\t}\n\t});\n\treturn new Promise((resolve, reject) => {\n\t\tnodeRes.once(\"close\", () => resolve(webRes));\n\t\tnodeRes.once(\"finish\", () => resolve(webRes));\n\t\tnodeRes.once(\"error\", (error) => reject(error));\n\t\tlet streamPromise;\n\t\tnodeRes.once(\"pipe\", (stream) => {\n\t\t\tstreamPromise = new Promise((resolve) => {\n\t\t\t\tstream.once(\"end\", () => resolve(webRes));\n\t\t\t\tstream.once(\"error\", (error) => reject(error));\n\t\t\t});\n\t\t});\n\t\ttry {\n\t\t\tif (isMiddleware) Promise.resolve(handler(nodeReq, nodeRes, (error) => error ? reject(error) : streamPromise || resolve(webRes))).catch((error) => reject(error));\n\t\t\telse Promise.resolve(handler(nodeReq, nodeRes)).then(() => streamPromise || webRes).catch((error) => reject(error));\n\t\t} catch (error) {\n\t\t\treject(error);\n\t\t}\n\t});\n}\nlet needDrainSymbol;\nfunction getNeedDrainSymbol(res) {\n\tneedDrainSymbol ??= Object.getOwnPropertySymbols(res).find((s) => s.description === \"kNeedDrain\");\n\treturn needDrainSymbol;\n}\nconst NULL_BODY_STATUSES = /* @__PURE__ */ new Set([\n\t101,\n\t204,\n\t205,\n\t304\n]);\nconst HOP_BY_HOP_HEADERS = /* @__PURE__ */ new Set([\n\t\"connection\",\n\t\"keep-alive\",\n\t\"proxy-authenticate\",\n\t\"proxy-authorization\",\n\t\"te\",\n\t\"trailer\",\n\t\"transfer-encoding\",\n\t\"upgrade\"\n]);\nvar WebServerResponse = class extends ServerResponse {\n\t#socket;\n\t#socketError;\n\t#onHeadersSent;\n\tconstructor(req, socket) {\n\t\tsuper(req);\n\t\tthis.assignSocket(socket);\n\t\tthis.useChunkedEncodingByDefault = false;\n\t\tthis.once(\"finish\", () => {\n\t\t\tsocket.end();\n\t\t});\n\t\tthis.#socket = socket;\n\t\tsocket.once(\"error\", (err) => {\n\t\t\tthis.#socketError ??= err;\n\t\t});\n\t\tsocket.on(\"drain\", () => {\n\t\t\tconst kNeedDrain = getNeedDrainSymbol(this);\n\t\t\tif (kNeedDrain && !this[kNeedDrain]) return;\n\t\t\tif (this.destroyed || this.writableFinished) return;\n\t\t\tif (kNeedDrain) this[kNeedDrain] = false;\n\t\t\tthis.emit(\"drain\");\n\t\t});\n\t\tthis.waitToFinish = this.waitToFinish.bind(this);\n\t\tthis.waitForResponseHead = this.waitForResponseHead.bind(this);\n\t\tthis.toWebResponse = this.toWebResponse.bind(this);\n\t}\n\twriteHead(statusCode, statusMessage, headers) {\n\t\tconst result = typeof statusMessage === \"string\" ? super.writeHead(statusCode, statusMessage, stripTransferEncoding(headers)) : super.writeHead(statusCode, stripTransferEncoding(headers ?? statusMessage));\n\t\tthis.#onHeadersSent?.();\n\t\treturn result;\n\t}\n\tsetHeader(name, value) {\n\t\tif (typeof name === \"string\" && name.toLowerCase() === \"transfer-encoding\") return this;\n\t\treturn super.setHeader(name, value);\n\t}\n\tappendHeader(name, value) {\n\t\tif (typeof name === \"string\" && name.toLowerCase() === \"transfer-encoding\") return this;\n\t\treturn super.appendHeader(name, value);\n\t}\n\twaitToFinish() {\n\t\tif (this.writableFinished) return Promise.resolve();\n\t\tif (this.#socketError || this.#socket.destroyed) return Promise.reject(this.#socketError ?? prematureCloseError());\n\t\tif (this.writableEnded) return Promise.resolve();\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst socket = this.#socket;\n\t\t\tconst settle = (err) => {\n\t\t\t\tthis.removeListener(\"finish\", onFinish);\n\t\t\t\tthis.removeListener(\"error\", onError);\n\t\t\t\tsocket.removeListener(\"error\", onError);\n\t\t\t\tsocket.removeListener(\"close\", onClose);\n\t\t\t\tif (err) reject(err);\n\t\t\t\telse resolve();\n\t\t\t};\n\t\t\tconst onFinish = () => settle();\n\t\t\tconst onError = (err) => settle(err);\n\t\t\tconst onClose = () => {\n\t\t\t\tif (!this.writableFinished) settle(this.#socketError ?? prematureCloseError());\n\t\t\t};\n\t\t\tthis.on(\"finish\", onFinish);\n\t\t\tthis.on(\"error\", onError);\n\t\t\tsocket.on(\"error\", onError);\n\t\t\tsocket.on(\"close\", onClose);\n\t\t});\n\t}\n\twaitForResponseHead() {\n\t\tif (this.headersSent || this.writableEnded || this.writableFinished) return Promise.resolve();\n\t\tif (this.#socketError || this.#socket.destroyed) return Promise.reject(this.#socketError ?? prematureCloseError());\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst socket = this.#socket;\n\t\t\tconst settle = (err) => {\n\t\t\t\tthis.#onHeadersSent = void 0;\n\t\t\t\tthis.removeListener(\"finish\", onFinish);\n\t\t\t\tthis.removeListener(\"error\", onError);\n\t\t\t\tsocket.removeListener(\"error\", onError);\n\t\t\t\tsocket.removeListener(\"close\", onClose);\n\t\t\t\tif (err) reject(err);\n\t\t\t\telse resolve();\n\t\t\t};\n\t\t\tthis.#onHeadersSent = () => settle();\n\t\t\tconst onFinish = () => settle();\n\t\t\tconst onError = (err) => settle(err);\n\t\t\tconst onClose = () => {\n\t\t\t\tif (!this.headersSent && !this.writableFinished) settle(this.#socketError ?? prematureCloseError());\n\t\t\t};\n\t\t\tthis.on(\"finish\", onFinish);\n\t\t\tthis.on(\"error\", onError);\n\t\t\tsocket.on(\"error\", onError);\n\t\t\tsocket.on(\"close\", onClose);\n\t\t});\n\t}\n\tasync toWebResponse() {\n\t\tawait this.waitForResponseHead();\n\t\tconst headers = [];\n\t\tconst httpHeader = this._header?.split(\"\\r\\n\");\n\t\tconst connectionTokens = /* @__PURE__ */ new Set();\n\t\tfor (let i = 1; httpHeader && i < httpHeader.length; i++) {\n\t\t\tconst sepIndex = httpHeader[i].indexOf(\": \");\n\t\t\tif (sepIndex === -1) continue;\n\t\t\tconst key = httpHeader[i].slice(0, Math.max(0, sepIndex));\n\t\t\tconst value = httpHeader[i].slice(Math.max(0, sepIndex + 2));\n\t\t\tif (!key) continue;\n\t\t\tconst lowerKey = key.toLowerCase();\n\t\t\tif (lowerKey === \"connection\") for (const token of value.split(\",\")) {\n\t\t\t\tconst t = token.trim().toLowerCase();\n\t\t\t\tif (t) connectionTokens.add(t);\n\t\t\t}\n\t\t\tif (HOP_BY_HOP_HEADERS.has(lowerKey)) continue;\n\t\t\theaders.push([key, value]);\n\t\t}\n\t\tif (connectionTokens.size > 0) {\n\t\t\tfor (let i = headers.length - 1; i >= 0; i--) if (connectionTokens.has(headers[i][0].toLowerCase())) headers.splice(i, 1);\n\t\t}\n\t\tconst nullBody = NULL_BODY_STATUSES.has(this.statusCode);\n\t\treturn new Response(nullBody ? null : this.#socket._webResBody, {\n\t\t\tstatus: this.statusCode,\n\t\t\tstatusText: this.statusMessage,\n\t\t\theaders\n\t\t});\n\t}\n};\nfunction stripTransferEncoding(headers) {\n\tif (!headers || typeof headers !== \"object\") return headers;\n\tif (Array.isArray(headers)) {\n\t\tif (headers.length > 0 && Array.isArray(headers[0])) return headers.filter(([key]) => String(key).toLowerCase() !== \"transfer-encoding\");\n\t\tconst out = [];\n\t\tfor (let i = 0; i < headers.length; i += 2) {\n\t\t\tif (String(headers[i]).toLowerCase() === \"transfer-encoding\") continue;\n\t\t\tout.push(headers[i], headers[i + 1]);\n\t\t}\n\t\treturn out;\n\t}\n\tlet hasTransferEncoding = false;\n\tfor (const key in headers) if (key.toLowerCase() === \"transfer-encoding\") {\n\t\thasTransferEncoding = true;\n\t\tbreak;\n\t}\n\tif (!hasTransferEncoding) return headers;\n\tconst out = {};\n\tfor (const key in headers) {\n\t\tif (key.toLowerCase() === \"transfer-encoding\") continue;\n\t\tout[key] = headers[key];\n\t}\n\treturn out;\n}\nasync function fetchNodeHandler(handler, req) {\n\tconst nodeRuntime = req.runtime?.node;\n\tif (nodeRuntime && nodeRuntime.req && nodeRuntime.res) return await callNodeHandler(handler, req);\n\tconst socket = new WebRequestSocket(req);\n\tconst nodeReq = new WebIncomingMessage(req, socket);\n\tconst nodeRes = new WebServerResponse(nodeReq, socket);\n\ttry {\n\t\tif (handler.length > 2) await new Promise((resolve, reject) => {\n\t\t\tnodeRes.once(\"finish\", () => resolve());\n\t\t\tnodeRes.once(\"close\", () => resolve());\n\t\t\tnodeRes.once(\"error\", (error) => reject(error));\n\t\t\tPromise.resolve(handler(nodeReq, nodeRes, (error) => {\n\t\t\t\tif (error) return reject(error);\n\t\t\t\tif (!nodeRes.writableEnded) nodeRes.end();\n\t\t\t\tresolve();\n\t\t\t})).catch((error) => reject(error));\n\t\t});\n\t\telse await handler(nodeReq, nodeRes);\n\t\treturn await nodeRes.toWebResponse();\n\t} catch (error) {\n\t\tif (!(req.signal?.aborted || error?.name === \"AbortError\" || error?.code === \"ERR_STREAM_PREMATURE_CLOSE\")) console.error(error, { cause: {\n\t\t\treq,\n\t\t\thandler\n\t\t} });\n\t\treturn new Response(null, {\n\t\t\tstatus: 500,\n\t\t\tstatusText: \"Internal Server Error\"\n\t\t});\n\t}\n}\nfunction toNodeHandler(handler, options) {\n\tif (handler.__nodeHandler) return handler.__nodeHandler;\n\tfunction convertedNodeHandler(nodeReq, nodeRes) {\n\t\tconst res = handler(new NodeRequest({\n\t\t\treq: nodeReq,\n\t\t\tres: nodeRes,\n\t\t\tmaxRequestBodySize: options?.maxRequestBodySize,\n\t\t\ttrustProxy: options?.trustProxy\n\t\t}));\n\t\treturn typeof res?.then === \"function\" ? res.then((resolvedRes) => send(nodeRes, resolvedRes)) : send(nodeRes, res);\n\t}\n\tconvertedNodeHandler.__fetchHandler = handler;\n\tassignFnName(convertedNodeHandler, handler, \" (converted to Node handler)\");\n\treturn convertedNodeHandler;\n}\nfunction send(nodeRes, webRes) {\n\treturn sendNodeResponse(nodeRes, webRes).catch((error) => handleSendError(nodeRes, error));\n}\nfunction toFetchHandler(handler) {\n\tif (handler.__fetchHandler) return handler.__fetchHandler;\n\tfunction convertedNodeHandler(req) {\n\t\treturn fetchNodeHandler(handler, req);\n\t}\n\tconvertedNodeHandler.__nodeHandler = handler;\n\tassignFnName(convertedNodeHandler, handler, \" (converted to Web handler)\");\n\treturn convertedNodeHandler;\n}\nfunction assignFnName(target, source, suffix) {\n\tif (source.name) try {\n\t\tObject.defineProperty(target, \"name\", { value: `${source.name}${suffix}` });\n\t} catch {}\n}\nfunction serve(options) {\n\treturn new NodeServer(options);\n}\nvar NodeServer = class {\n\truntime = \"node\";\n\toptions;\n\tnode;\n\tserveOptions;\n\tfetch;\n\twaitUntil;\n\t#isSecure;\n\t#listeningPromise;\n\t#listenError;\n\t#listenErrorObserved;\n\t#wait;\n\tconstructor(options) {\n\t\tthis.options = {\n\t\t\t...options,\n\t\t\tmiddleware: [...options.middleware || []]\n\t\t};\n\t\tfor (const plugin of options.plugins || []) plugin(this);\n\t\terrorPlugin(this);\n\t\tconst fetchHandler = this.fetch = wrapFetch(this);\n\t\tconst handler = (nodeReq, nodeRes) => {\n\t\t\tconst reqUrl = nodeReq.url;\n\t\t\tif (reqUrl && reqUrl[0] !== \"/\" && reqUrl !== \"*\" && !isValidAbsoluteForm(reqUrl)) {\n\t\t\t\tnodeRes.statusCode = 400;\n\t\t\t\tnodeRes.end();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst request = new NodeRequest({\n\t\t\t\treq: nodeReq,\n\t\t\t\tres: nodeRes,\n\t\t\t\tmaxRequestBodySize: this.options.maxRequestBodySize,\n\t\t\t\ttrustProxy: this.options.trustProxy\n\t\t\t});\n\t\t\trequest.waitUntil = this.#wait?.waitUntil;\n\t\t\tlet res;\n\t\t\ttry {\n\t\t\t\tres = fetchHandler(request);\n\t\t\t} catch (error) {\n\t\t\t\treturn sendErrorResponse(nodeRes, error, this.options.silent);\n\t\t\t}\n\t\t\treturn typeof res?.then === \"function\" ? res.then((resolvedRes) => sendNodeResponseDetached(nodeRes, resolvedRes, this.options.silent), (error) => sendErrorResponse(nodeRes, error, this.options.silent)) : sendNodeResponseDetached(nodeRes, res, this.options.silent);\n\t\t};\n\t\tthis.node = {\n\t\t\thandler,\n\t\t\tserver: void 0\n\t\t};\n\t\tconst loader = globalThis.__srvxLoader__;\n\t\tif (loader) {\n\t\t\tloader({ server: this });\n\t\t\treturn;\n\t\t}\n\t\tgracefulShutdownPlugin(this);\n\t\tthis.#wait = createWaitUntil();\n\t\tthis.waitUntil = this.#wait.waitUntil;\n\t\tconst tls = resolveTLSOptions(this.options);\n\t\tconst nodeListen = this.options.node;\n\t\tconst hasListenTarget = nodeListen?.path != null || nodeListen?.handle != null || nodeListen?.fd != null;\n\t\tlet portAndHost;\n\t\tif (!hasListenTarget) {\n\t\t\tconst { port, hostname: host } = resolvePortAndHost(this.options);\n\t\t\tportAndHost = {\n\t\t\t\tport,\n\t\t\t\thost\n\t\t\t};\n\t\t}\n\t\tthis.serveOptions = {\n\t\t\t...portAndHost,\n\t\t\texclusive: !this.options.reusePort,\n\t\t\treusePort: this.options.reusePort,\n\t\t\t...tls,\n\t\t\t...this.options.node\n\t\t};\n\t\tlet server;\n\t\tthis.#isSecure = !!this.serveOptions.cert && this.options.protocol !== \"http\";\n\t\tif (this.options.node?.http2 ?? this.#isSecure) {\n\t\t\tif (this.#isSecure) server = nodeHTTP2.createSecureServer({\n\t\t\t\tallowHTTP1: true,\n\t\t\t\t...this.serveOptions\n\t\t\t}, handler);\n\t\t\telse throw new Error(\"node.http2 option requires tls certificate!\");\n\t\t} else if (this.#isSecure) server = nodeHTTPS.createServer(this.serveOptions, handler);\n\t\telse server = nodeHTTP.createServer(this.serveOptions, handler);\n\t\tthis.node.server = server;\n\t\tif (!options.manual) this.serve().catch((error) => this.#reportUnobservedListenError(error));\n\t}\n\t#reportUnobservedListenError(error) {\n\t\tif (this.#listenErrorObserved) return;\n\t\tif (!this.options.silent) console.error(\"[srvx] Failed to start server:\", error);\n\t\tconst process = globalThis.process;\n\t\tif (process && !process.exitCode) process.exitCode = 1;\n\t}\n\tserve() {\n\t\tif (this.#listeningPromise) return this.#listeningPromise.then(() => this);\n\t\tconst server = this.node?.server;\n\t\tif (!server) return Promise.reject(/* @__PURE__ */ new Error(\"Server not initialized\"));\n\t\tthis.#listenError = void 0;\n\t\tthis.#listeningPromise = new Promise((resolve, reject) => {\n\t\t\tconst onError = (error) => {\n\t\t\t\tserver.off(\"listening\", onListening);\n\t\t\t\tthis.#listenError = error;\n\t\t\t\tthis.#listeningPromise = void 0;\n\t\t\t\treject(error);\n\t\t\t};\n\t\t\tconst onListening = () => {\n\t\t\t\tserver.off(\"error\", onError);\n\t\t\t\tprintListening(this.options, this.url);\n\t\t\t\tresolve();\n\t\t\t};\n\t\t\tserver.once(\"error\", onError);\n\t\t\tserver.once(\"listening\", onListening);\n\t\t\tserver.listen(this.serveOptions);\n\t\t});\n\t\treturn this.#listeningPromise.then(() => this);\n\t}\n\tget url() {\n\t\tconst addr = this.node?.server?.address();\n\t\tif (!addr) return;\n\t\treturn typeof addr === \"string\" ? addr : fmtURL(addr.address, addr.port, this.#isSecure);\n\t}\n\tready() {\n\t\tthis.#listenErrorObserved = true;\n\t\tif (this.#listenError) return Promise.reject(this.#listenError);\n\t\treturn Promise.resolve(this.#listeningPromise).then(() => this);\n\t}\n\tasync close(closeAll) {\n\t\tawait Promise.all([this.#wait?.wait(), new Promise((resolve, reject) => {\n\t\t\tconst server = this.node?.server;\n\t\t\tif (server && closeAll && \"closeAllConnections\" in server) server.closeAllConnections();\n\t\t\tif (!server || !server.listening) return resolve();\n\t\t\tserver.close((error) => error ? reject(error) : resolve());\n\t\t})]);\n\t}\n};\nexport { NodeResponse as FastResponse, FastURL, NodeRequest, NodeResponse, fetchNodeHandler, patchGlobalRequest, sendNodeResponse, serve, toFetchHandler, toNodeHandler };\n","/**\n * Stack trace frame classifier — categorizes stack frames by origin.\n *\n * Provides `classifyFrame` (single frame) and `classifyStack` (full stack\n * string) as the shared primitives used by the error page, terminal\n * formatter, and overlay.\n *\n * Dev-only: this module is only imported by other dev-tools modules.\n */\n\n// ─── Types ──────────────────────────────────────────────────────────────────\n\nexport type FrameType = 'app' | 'framework' | 'internal';\n\nexport interface ClassifiedFrame {\n raw: string;\n type: FrameType;\n file?: string;\n line?: number;\n col?: number;\n}\n\n// ─── Frame Parsing ──────────────────────────────────────────────────────────\n\n/** Parse file/line/col from a stack frame line. */\nfunction parseFrame(frameLine: string): { file?: string; line?: number; col?: number } {\n const parenMatch = /\\(([^)]+):(\\d+):(\\d+)\\)/.exec(frameLine);\n if (parenMatch) {\n return { file: parenMatch[1], line: Number(parenMatch[2]), col: Number(parenMatch[3]) };\n }\n const bareMatch = /at (\\/[^:]+):(\\d+):(\\d+)/.exec(frameLine);\n if (bareMatch) {\n return { file: bareMatch[1], line: Number(bareMatch[2]), col: Number(bareMatch[3]) };\n }\n return {};\n}\n\n// ─── Classification ─────────────────────────────────────────────────────────\n\n/**\n * Classify a single stack frame line by origin.\n *\n * - 'app': user application code (in project root, not node_modules)\n * - 'framework': timber-app internal code\n * - 'internal': node_modules, Node.js internals\n */\nexport function classifyFrame(frameLine: string, projectRoot: string): FrameType {\n const trimmed = frameLine.trim();\n\n if (trimmed.includes('packages/timber-app/')) return 'framework';\n if (trimmed.includes('node_modules/')) return 'internal';\n if (trimmed.startsWith('at node:') || trimmed.includes('(node:')) return 'internal';\n if (trimmed.includes(projectRoot)) return 'app';\n\n return 'internal';\n}\n\n/**\n * Classify all frames in a full stack trace string.\n *\n * Parses the stack, skips the first line (error message), filters to\n * lines starting with \"at \", and returns classified frames with optional\n * file/line/col metadata.\n */\nexport function classifyStack(stack: string, projectRoot: string): ClassifiedFrame[] {\n return stack\n .split('\\n')\n .slice(1) // skip first line (error message)\n .filter((line) => line.trim().startsWith('at '))\n .map((raw) => {\n const type = classifyFrame(raw, projectRoot);\n const { file, line, col } = parseFrame(raw);\n return { raw, type, file, line, col };\n });\n}\n","/**\n * Terminal error formatting — boxed, color-coded error output for dev mode.\n *\n * Produces a visually scannable error block with:\n * - Unicode box-drawing border around the error\n * - Phase badge and error message\n * - First app frame highlighted as the primary action item\n * - OSC 8 clickable file:line links (VSCode terminal, iTerm2, etc.)\n * - Internal/framework frames collapsed with a count\n * - Component stack (for React render errors)\n *\n * Dev-only: this module is only imported by dev-error-overlay.ts.\n *\n * Design doc: 21-dev-server.md §\"Error Overlay\"\n */\n\nimport { pathToFileURL } from 'node:url';\nimport type { InspectColor } from 'node:util';\nimport { styleText } from 'node:util';\nimport {\n extractComponentStack,\n parseFirstAppFrame,\n PHASE_LABELS,\n type ErrorPhase,\n} from './overlay.ts';\nimport { classifyStack } from './stack-classifier.ts';\n\n// ─── Styling ────────────────────────────────────────────────────────────────\n\ntype Format = InspectColor | readonly InspectColor[];\nconst noValidate = { validateStream: false } as const;\nconst style = (fmt: Format, text: string) => styleText(fmt, text, noValidate);\n\n// ─── OSC 8 Hyperlinks ──────────────────────────────────────────────────────\n\n/**\n * Wrap text in an OSC 8 hyperlink escape sequence.\n *\n * Terminals that support OSC 8 (VSCode, iTerm2, Windows Terminal, etc.)\n * render this as a clickable link. Others ignore the escape sequences\n * and show the text normally.\n *\n * Format: \\x1b]8;;URL\\x07TEXT\\x1b]8;;\\x07\n */\nfunction hyperlink(text: string, url: string): string {\n return `\\x1b]8;;${url}\\x07${text}\\x1b]8;;\\x07`;\n}\n\n/**\n * Format a file:line:col reference as a clickable terminal link.\n *\n * Uses file:// URLs so terminals open the file in the configured editor.\n * The link text is styled with cyan + underline for visibility.\n */\nfunction fileLink(filePath: string, line?: number, col?: number): string {\n const display = line ? `${filePath}:${line}${col ? `:${col}` : ''}` : filePath;\n // Use pathToFileURL for proper encoding of spaces, #, ?, and Windows\n // drive letters (TIM-792). Append :line:col after the URL.\n const base = pathToFileURL(filePath).href;\n const url = line ? `${base}:${line}${col ? `:${col}` : ''}` : base;\n return style(['cyan', 'underline'], hyperlink(display, url));\n}\n\n// ─── Box Drawing ────────────────────────────────────────────────────────────\n\nconst BOX = {\n topLeft: '╭',\n topRight: '╮',\n bottomLeft: '╰',\n bottomRight: '╯',\n horizontal: '─',\n vertical: '│',\n};\n\n/**\n * Wrap lines of text in a Unicode box with a colored left border.\n *\n * @param lines - Content lines (no ANSI length calculation — keeps it simple)\n * @param width - Box width (characters). Lines longer than this are not truncated.\n */\nfunction box(lines: string[], borderFormat: Format, width = 80): string {\n const bar = BOX.horizontal.repeat(width - 2);\n const output: string[] = [];\n\n output.push(style(borderFormat, `${BOX.topLeft}${bar}${BOX.topRight}`));\n for (const line of lines) {\n output.push(`${style(borderFormat, BOX.vertical)} ${line}`);\n }\n output.push(style(borderFormat, `${BOX.bottomLeft}${bar}${BOX.bottomRight}`));\n\n return output.join('\\n');\n}\n\n// Frame classification and parsing provided by stack-classifier.ts\n\n// ─── Public API ─────────────────────────────────────────────────────────────\n\n/**\n * Format an error for terminal output with a boxed layout.\n *\n * The output is designed to be scannable at a glance:\n * 1. Red box with phase badge and error message\n * 2. First app frame as a clickable link (the primary action item)\n * 3. App frames listed normally\n * 4. Internal/framework frames collapsed with count\n * 5. Component stack (if present)\n */\nexport function formatTerminalError(error: Error, phase: ErrorPhase, projectRoot: string): string {\n const sections: string[] = [];\n const componentStack = extractComponentStack(error);\n const loc = parseFirstAppFrame(error.stack ?? '', projectRoot);\n const frames = error.stack ? classifyStack(error.stack, projectRoot) : [];\n const appFrames = frames.filter((f) => f.type === 'app');\n const internalCount = frames.filter((f) => f.type !== 'app').length;\n\n // ── Box: Phase + Message ──────────────────────────────────────────\n const boxLines: string[] = [];\n boxLines.push(style(['red', 'bold'], `${PHASE_LABELS[phase]} Error`));\n boxLines.push('');\n\n // Error message — may be multi-line\n for (const msgLine of error.message.split('\\n')) {\n boxLines.push(style('red', msgLine));\n }\n\n // Primary file location (clickable)\n if (loc) {\n boxLines.push('');\n const relPath = loc.file.startsWith(projectRoot)\n ? loc.file.slice(projectRoot.length + 1)\n : loc.file;\n boxLines.push(\n `${style('bold', '→')} ${fileLink(loc.file, loc.line, loc.column)} ${style('dim', `(${relPath})`)}`\n );\n }\n\n sections.push(box(boxLines, 'red'));\n\n // ── Component Stack ───────────────────────────────────────────────\n if (componentStack) {\n sections.push('');\n sections.push(` ${style('bold', 'Component Stack:')}`);\n for (const csLine of componentStack.trim().split('\\n')) {\n sections.push(` ${style('dim', csLine.trim())}`);\n }\n }\n\n // ── App Frames ────────────────────────────────────────────────────\n if (appFrames.length > 0) {\n sections.push('');\n sections.push(` ${style('bold', 'Application Frames:')}`);\n for (let i = 0; i < appFrames.length; i++) {\n const f = appFrames[i]!;\n if (f.file && f.line) {\n const prefix = i === 0 ? style('bold', '▸') : ' ';\n sections.push(\n ` ${prefix} ${fileLink(f.file, f.line, f.col)} ${style('dim', extractFnName(f.raw))}`\n );\n } else {\n sections.push(` ${f.raw}`);\n }\n }\n }\n\n // ── Internal Frames (collapsed) ───────────────────────────────────\n if (internalCount > 0) {\n sections.push(\n ` ${style('dim', `… ${internalCount} internal frame${internalCount !== 1 ? 's' : ''} hidden`)}`\n );\n }\n\n sections.push('');\n return sections.join('\\n');\n}\n\n// ─── Helpers ────────────────────────────────────────────────────────────────\n\n/** Extract the function name from a stack frame line like \" at fnName (/path:1:2)\". */\nfunction extractFnName(frameLine: string): string {\n const match = /at\\s+(\\S+)\\s+\\(/.exec(frameLine.trim());\n return match ? match[1]! : '';\n}\n","/**\n * Dev error overlay — formats and sends errors to Vite's browser overlay and stderr.\n *\n * Integrates with Vite's built-in error overlay (`server.hot.send`) rather\n * than implementing a custom overlay.\n *\n * Stacks are shown as they arrive: Vite's module runner already reports\n * source positions for the code it runs, and a second mapping pass moves\n * them (TIM-1555).\n *\n * Design doc: 21-dev-server.md §\"Error Overlay\", §\"RSC Source-Mapping\"\n */\n\nimport type { ViteDevServer } from 'vite';\nimport { classifyFrame } from './stack-classifier.ts';\n\n// ─── Types ──────────────────────────────────────────────────────────────────\n\n/** The phase of the pipeline where the error occurred. */\nexport type ErrorPhase =\n | 'module-transform'\n | 'proxy'\n | 'middleware'\n | 'access'\n | 'render'\n | 'handler';\n\n/** Labels for terminal output. */\nexport const PHASE_LABELS: Record<ErrorPhase, string> = {\n 'module-transform': 'Module Transform',\n 'proxy': 'Proxy',\n 'middleware': 'Middleware',\n 'access': 'Access Check',\n 'render': 'RSC Render',\n 'handler': 'Route Handler',\n};\n\n// ─── Frame Classification (re-exported from stack-classifier) ───────────────\n\nexport {\n classifyFrame,\n classifyStack,\n type FrameType,\n type ClassifiedFrame,\n} from './stack-classifier.ts';\n\n// ─── Component Stack Extraction ─────────────────────────────────────────────\n\n/**\n * Extract the React component stack from an error, if present.\n * React attaches this as `componentStack` during renderToReadableStream errors.\n */\nexport function extractComponentStack(error: unknown): string | null {\n if (\n error &&\n typeof error === 'object' &&\n 'componentStack' in error &&\n typeof (error as Record<string, unknown>).componentStack === 'string'\n ) {\n return (error as Record<string, unknown>).componentStack as string;\n }\n return null;\n}\n\n// ─── First App Frame Parsing ────────────────────────────────────────────────\n\ninterface SourceLocation {\n file: string;\n line: number;\n column: number;\n}\n\n/**\n * Parse the first application frame from a stack trace.\n * Returns file/line/column for the overlay's `loc` field.\n */\nexport function parseFirstAppFrame(stack: string, projectRoot: string): SourceLocation | null {\n const lines = stack.split('\\n');\n // Match patterns like:\n // at functionName (/absolute/path:line:column)\n // at /absolute/path:line:column\n const parenRegex = /\\(([^)]+):(\\d+):(\\d+)\\)/;\n const bareRegex = /at (\\/[^:]+):(\\d+):(\\d+)/;\n\n for (const line of lines) {\n if (classifyFrame(line, projectRoot) !== 'app') continue;\n\n const match = parenRegex.exec(line) ?? bareRegex.exec(line);\n if (!match) continue;\n\n const [, file, lineNum, col] = match;\n if (file && lineNum && col) {\n return { file, line: parseInt(lineNum, 10), column: parseInt(col, 10) };\n }\n }\n\n return null;\n}\n\n// ─── Error Phase Classification ─────────────────────────────────────────────\n\n/**\n * Classify the error phase by inspecting the error's stack trace.\n * Falls back to 'render' if no specific phase can be determined.\n */\nexport function classifyErrorPhase(error: Error, projectRoot: string): ErrorPhase {\n const stack = error.stack ?? '';\n\n // Check for React component stack (render error)\n if (extractComponentStack(error)) return 'render';\n\n // Check for specific file patterns in app frames\n const appRoot = projectRoot.replace(/\\/$/, '');\n if (stack.includes(`${appRoot}/app/`) || stack.includes('/app/')) {\n if (stack.includes('/middleware.ts') || stack.includes('/middleware.js')) return 'middleware';\n if (stack.includes('/access.ts') || stack.includes('/access.js')) return 'access';\n if (stack.includes('/route.ts') || stack.includes('/route.js')) return 'handler';\n }\n\n return 'render';\n}\n\n// ─── Terminal Formatting ────────────────────────────────────────────────────\n\n// formatTerminalError is implemented in the dedicated terminal formatter module\n// (terminal.ts) to keep this file under 500 lines.\n// Import for use in sendErrorToOverlay, and re-export for external consumers.\nimport { formatTerminalError as _formatTerminalError } from './terminal.ts';\nexport const formatTerminalError = _formatTerminalError;\n\n// ─── Overlay Integration ────────────────────────────────────────────────────\n\n/**\n * Send an error to Vite's browser overlay and log it to stderr.\n *\n * Reads `error` and never writes it: the pipeline may render the same object\n * on the fallback error page after reporting it here.\n *\n * The dev server remains running — errors are handled, not fatal.\n */\nexport function sendErrorToOverlay(\n server: ViteDevServer,\n error: Error,\n phase: ErrorPhase,\n projectRoot: string\n): void {\n // Log to stderr with frame dimming\n const formatted = formatTerminalError(error, phase, projectRoot);\n process.stderr.write(`${formatted}\\n`);\n\n // Build overlay payload\n const loc = parseFirstAppFrame(error.stack ?? '', projectRoot);\n const componentStack = extractComponentStack(error);\n\n let message = error.message;\n if (componentStack) {\n message = `${error.message}\\n\\nComponent Stack:\\n${componentStack.trim()}`;\n }\n\n // Send to browser via Vite's error overlay protocol\n try {\n server.hot.send({\n type: 'error',\n err: {\n message,\n stack: error.stack ?? '',\n id: loc?.file,\n plugin: `timber (${PHASE_LABELS[phase]})`,\n loc: loc ? { file: loc.file, line: loc.line, column: loc.column } : undefined,\n },\n });\n } catch (e) {\n console.debug('[timber] overlay error send failed:', e instanceof Error ? e.message : e);\n }\n}\n","/**\n * Shared HTML escaping utility.\n *\n * Used by both dev-only paths (error pages, 404 page) and production\n * paths (deny-renderer, RSC helpers). Lives in server/utils/ because\n * it's not dev-only.\n */\n\n/**\n * Escape a string for safe embedding in HTML content or attributes.\n *\n * Replaces `&`, `<`, `>`, and `\"` with their HTML entity equivalents.\n */\nexport function escapeHtml(str: string): string {\n return str\n .replace(/&/g, '&amp;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n .replace(/\"/g, '&quot;');\n}\n","/**\n * Shared scaffold for dev-mode HTML pages (dev error page, dev 404 page).\n *\n * Both pages are self-contained HTML documents served when the normal\n * render pipeline can't produce a page. They share:\n * - The document scaffold (head, container, footer)\n * - Base CSS (layout, light/dark variables, common components)\n * - The HMR auto-reload script that watches Vite's WebSocket and reloads\n * when the developer fixes the error / adds the missing route\n *\n * Dev-only: this module is only imported by dev-mode code paths. It is\n * never included in production builds.\n *\n * Design doc: 21-dev-server.md §\"Error Overlay\", §\"Dev 404 Page\"\n */\n\nimport { escapeHtml } from '../server/utils/escape-html.ts';\n\n// ─── HMR Options ────────────────────────────────────────────────────────────\n\n/**\n * HMR connection options for the dev page auto-reload WebSocket.\n * Derived from Vite's resolved server config so the page can connect\n * to the correct HMR endpoint (TIM-789).\n */\nexport interface DevErrorHmrOptions {\n protocol?: string;\n host?: string;\n port?: number;\n path?: string;\n token?: string;\n}\n\n/**\n * Hooks the dev server hands the RSC environment, which cannot read the\n * Vite server itself (separate module graph). The RSC entry exports\n * `setDevHooks()`; the dev server calls it after importing the entry.\n *\n * Declared here, not in the RSC entry, so the dev-server plugin can name\n * the type without pulling the RSC entry into its type graph.\n */\nexport interface DevHooks {\n /** Forwards a pipeline error to the browser error overlay. */\n onPipelineError?: (error: Error, phase: string) => void;\n /**\n * The resolved HMR endpoint for the auto-reload WebSocket on the dev 404\n * page and the fallback error page (TIM-1067).\n */\n hmrOptions?: DevErrorHmrOptions;\n}\n\n/**\n * Extract HMR connection options from a Vite resolved config.\n * Used by the dev server to pass HMR config to the dev page generators\n * so the auto-reload WebSocket connects to the correct endpoint.\n */\nexport function extractHmrOptions(config: {\n server?: {\n hmr?:\n | { protocol?: string; host?: string; port?: number; clientPort?: number; path?: string }\n | boolean;\n };\n webSocketToken?: string;\n}): DevErrorHmrOptions | undefined {\n const hmr = config.server?.hmr;\n if (hmr === false) return undefined;\n const hmrOpts = typeof hmr === 'object' ? hmr : {};\n const opts: DevErrorHmrOptions = {\n protocol: hmrOpts.protocol,\n host: hmrOpts.host,\n port: hmrOpts.clientPort || hmrOpts.port,\n path: hmrOpts.path,\n token: config.webSocketToken,\n };\n // If no HMR fields were explicitly configured, return undefined so the\n // reload script derives everything from the browser's location, which\n // correctly includes the current port (TIM-805).\n if (!opts.protocol && !opts.host && !opts.port && !opts.path && !opts.token) {\n return undefined;\n }\n return opts;\n}\n\n// ─── Auto-Reload Script ─────────────────────────────────────────────────────\n\n/**\n * Build the inline auto-reload script for dev pages.\n *\n * The page is static HTML, not a Vite-managed module, so the normal HMR\n * update flow can't reach it. Instead we connect to Vite's HMR WebSocket\n * directly and reload on any update event.\n *\n * URL construction mirrors Vite's own client.mjs: explicitly configured\n * values win, and the browser's location fills any gaps at runtime. This\n * matters because Vite 8 requires a `?token=` on browser WS upgrades in\n * every config — a config with only a token still needs the host and port\n * from `location` (TIM-1067).\n */\nexport function buildReloadScript(hmrOptions?: DevErrorHmrOptions): string {\n // `<` is escaped as a unicode escape so config text can never close the\n // <script> block (same defense as escJsonForScript in error-page.ts, TIM-788).\n const opts = JSON.stringify(hmrOptions ?? {}).replace(/</g, '\\\\u003c');\n return ` (function() {\n try {\n var o = ${opts};\n var protocol = o.protocol || (location.protocol === 'https:' ? 'wss' : 'ws');\n var host = o.host || location.hostname;\n var port = o.port || location.port;\n var url = protocol + '://' + host + (port ? ':' + port : '') + (o.path || '')\n + (o.token ? '?token=' + encodeURIComponent(o.token) : '');\n var ws = new WebSocket(url, 'vite-hmr');\n ws.addEventListener('message', function(e) {\n try {\n var data = JSON.parse(e.data);\n if (data.type === 'full-reload' || data.type === 'update') {\n location.reload();\n }\n } catch (ex) {}\n });\n } catch (ex) {}\n })();`;\n}\n\n// ─── Page Shell ─────────────────────────────────────────────────────────────\n\nexport interface DevPageShellOptions {\n /** Page title — escaped by the shell. */\n title: string;\n /** Page-specific CSS appended after the shared base (badge colors, etc.). */\n extraCss?: string;\n /** Inner HTML of the container — must already be escaped by the caller. */\n bodyHtml: string;\n /** Hint text shown next to the timber logo in the footer. */\n footerHint: string;\n /** Additional inline script placed before the auto-reload script. */\n extraScript?: string;\n /** HMR connection options for the auto-reload WebSocket. */\n hmrOptions?: DevErrorHmrOptions;\n}\n\n/**\n * Render a self-contained dev page: scaffold + shared CSS + footer +\n * HMR auto-reload script.\n */\nexport function renderDevPageShell(opts: DevPageShellOptions): string {\n return `<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <title>${escapeHtml(opts.title)}</title>\n <style>${SHARED_CSS}${opts.extraCss ?? ''}</style>\n</head>\n<body>\n <div class=\"container\">\n ${opts.bodyHtml}\n\n <footer class=\"footer\">\n <span class=\"timber-logo\">🪵 timber.js</span>\n <span class=\"footer-hint\">${opts.footerHint}</span>\n </footer>\n </div>\n\n <script>\n${opts.extraScript ?? ''}\n // Auto-reload when Vite HMR signals an update (file fixed, route added).\n${buildReloadScript(opts.hmrOptions)}\n </script>\n</body>\n</html>`;\n}\n\n// ─── Shared CSS ─────────────────────────────────────────────────────────────\n\n/**\n * Base CSS shared by all dev pages. Pages override the --badge-* variables\n * (and add their own component styles) via `extraCss`.\n */\nconst SHARED_CSS = `\n :root {\n --bg: #fff;\n --fg: #1a1a1a;\n --fg-dim: #6b7280;\n --border: #e5e7eb;\n --source-bg: #fafafa;\n --link: #2563eb;\n --code-bg: #f3f4f6;\n --btn-bg: #f3f4f6;\n --btn-fg: #374151;\n --btn-border: #d1d5db;\n --code-font: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;\n }\n\n @media (prefers-color-scheme: dark) {\n :root {\n --bg: #0a0a0a;\n --fg: #f5f5f5;\n --fg-dim: #9ca3af;\n --border: #27272a;\n --source-bg: #18181b;\n --link: #60a5fa;\n --code-bg: #27272a;\n --btn-bg: #27272a;\n --btn-fg: #e5e7eb;\n --btn-border: #3f3f46;\n }\n }\n\n * { margin: 0; padding: 0; box-sizing: border-box; }\n\n body {\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;\n background: var(--bg);\n color: var(--fg);\n line-height: 1.6;\n padding: 2rem;\n }\n\n .container { max-width: 56rem; margin: 0 auto; }\n .header { margin-bottom: 1.5rem; }\n\n .badge {\n display: inline-block;\n font-size: 0.75rem;\n font-weight: 600;\n text-transform: uppercase;\n letter-spacing: 0.05em;\n padding: 0.25rem 0.625rem;\n border-radius: 0.375rem;\n background: var(--badge-bg);\n color: var(--badge-fg);\n border: 1px solid var(--badge-border);\n margin-bottom: 0.75rem;\n }\n\n .message {\n font-size: 1.375rem;\n font-weight: 600;\n line-height: 1.3;\n word-break: break-word;\n }\n\n .hint {\n margin-top: 0.5rem;\n color: var(--fg-dim);\n font-size: 0.875rem;\n }\n\n .section {\n margin-bottom: 1rem;\n border: 1px solid var(--border);\n border-radius: 0.5rem;\n overflow: hidden;\n }\n\n .section-header {\n font-size: 0.75rem;\n font-weight: 600;\n text-transform: uppercase;\n letter-spacing: 0.05em;\n padding: 0.5rem 0.75rem;\n background: var(--source-bg);\n border-bottom: 1px solid var(--border);\n color: var(--fg-dim);\n }\n\n .footer {\n display: flex;\n align-items: center;\n gap: 0.75rem;\n padding-top: 1rem;\n border-top: 1px solid var(--border);\n font-size: 0.75rem;\n color: var(--fg-dim);\n }\n\n .timber-logo { font-weight: 600; white-space: nowrap; }\n`;\n","/**\n * Dev error page — self-contained HTML error page for dev server 500s.\n *\n * Generates a styled, self-contained HTML page when the RSC pipeline fails\n * and the Vite error overlay can't fire (e.g., first page load before HMR\n * WebSocket connects, RSC entry module crash, early pipeline errors).\n *\n * This is NOT a replacement for Vite's error overlay — it's the fallback\n * for when the overlay's transport (WebSocket) isn't available yet.\n *\n * Dev-only: this module is only imported by dev-server.ts (apply: 'serve')\n * and via dynamic import from fallback-error.ts in dev mode. It is never\n * included in production builds.\n *\n * Design doc: 21-dev-server.md §\"Error Overlay\"\n */\n\nimport { readFileSync } from 'node:fs';\nimport { extractComponentStack, parseFirstAppFrame, type ErrorPhase } from './overlay.ts';\nimport { classifyStack } from './stack-classifier.ts';\nimport { escapeHtml } from '../server/utils/escape-html.ts';\nimport { renderDevPageShell, type DevErrorHmrOptions } from './dev-page-shell.ts';\n\n// ─── Phase Labels ───────────────────────────────────────────────────────────\n\nconst PHASE_LABELS: Record<ErrorPhase, string> = {\n 'module-transform': 'Module Transform',\n 'proxy': 'Proxy',\n 'middleware': 'Middleware',\n 'access': 'Access Check',\n 'render': 'RSC Render',\n 'handler': 'Route Handler',\n};\n\nconst PHASE_HINTS: Record<ErrorPhase, string> = {\n 'module-transform':\n 'This error occurred while Vite was transforming a module. Check for syntax errors or missing imports.',\n 'proxy': 'This error occurred in proxy.ts. Check your proxy configuration.',\n 'middleware':\n 'This error occurred in a middleware.ts file. Check the middleware function for unhandled exceptions.',\n 'access': 'This error occurred in an access.ts file. Check your access control logic.',\n 'render':\n 'This error occurred while rendering a server component. Check the component for runtime errors.',\n 'handler': 'This error occurred in a route handler (route.ts). Check the handler function.',\n};\n\n// ─── Source Context ─────────────────────────────────────────────────────────\n\n/**\n * Try to read a few lines of source code around the error location.\n * Returns null if the file can't be read (e.g., virtual modules).\n *\n * Uses a top-level `node:fs` import — this module is dev-server-only and\n * Node-only. A bare `require()` here would throw in the ESM build and the\n * code frame would silently never render (TIM-1067, B48).\n */\nfunction readSourceContext(\n filePath: string,\n line: number,\n contextLines = 3\n): { lines: Array<{ num: number; text: string; highlight: boolean }>; startLine: number } | null {\n try {\n const content = readFileSync(filePath, 'utf-8');\n const allLines = content.split('\\n');\n\n const start = Math.max(0, line - 1 - contextLines);\n const end = Math.min(allLines.length, line + contextLines);\n\n return {\n startLine: start + 1,\n lines: allLines.slice(start, end).map((text: string, i: number) => ({\n num: start + 1 + i,\n text,\n highlight: start + 1 + i === line,\n })),\n };\n } catch (e) {\n console.debug('[timber] source context extraction failed:', e instanceof Error ? e.message : e);\n return null;\n }\n}\n\n// HTML escaping provided by server/utils/escape-html.ts\nconst esc = escapeHtml;\n\n/**\n * Escape a JSON string for safe embedding in an HTML `<script>` block.\n *\n * `JSON.stringify` does not escape `</script>`, so error text containing\n * that sequence breaks out of the script block — an XSS vector.\n * We replace all `<` with the equivalent unicode escape, which is valid in\n * JSON strings and prevents the HTML parser from seeing a closing\n * `</script>` tag.\n *\n * Security: TIM-788\n */\nfunction escJsonForScript(json: string): string {\n return json.replace(/</g, '\\\\u003c');\n}\n\n// ─── HTML Generation ────────────────────────────────────────────────────────\n\n/**\n * Generate a self-contained HTML error page for dev server 500 responses.\n *\n * The page includes:\n * - Error message and phase label\n * - Source code context around the first app frame (if readable)\n * - Component stack (for React render errors)\n * - Classified stack trace (app frames highlighted, internals collapsed)\n * - Copy button for the full error\n * - Dark/light mode via prefers-color-scheme\n * - Auto-reconnect script that watches for Vite HMR and reloads\n */\nexport function generateDevErrorPage(\n error: Error,\n phase: ErrorPhase,\n projectRoot: string,\n hmrOptions?: DevErrorHmrOptions\n): string {\n const message = error.message || 'Unknown error';\n const phaseLabel = PHASE_LABELS[phase];\n const phaseHint = PHASE_HINTS[phase];\n const componentStack = extractComponentStack(error);\n const loc = parseFirstAppFrame(error.stack ?? '', projectRoot);\n const frames = error.stack ? classifyStack(error.stack, projectRoot) : [];\n const appFrames = frames.filter((f) => f.type === 'app');\n const internalFrameCount = frames.filter((f) => f.type !== 'app').length;\n\n // Try to read source code context\n let sourceContext: ReturnType<typeof readSourceContext> = null;\n if (loc) {\n sourceContext = readSourceContext(loc.file, loc.line);\n }\n\n // Relative path for display\n const relPath = loc?.file.startsWith(projectRoot)\n ? loc.file.slice(projectRoot.length + 1)\n : loc?.file;\n\n const bodyHtml = `<header class=\"header\">\n <div class=\"badge\">${esc(phaseLabel)} Error</div>\n <h1 class=\"message\">${esc(message)}</h1>\n ${phaseHint ? `<p class=\"hint\">${esc(phaseHint)}</p>` : ''}\n </header>\n\n ${relPath ? `<div class=\"location\">${esc(relPath)}${loc ? `:${loc.line}:${loc.column}` : ''}</div>` : ''}\n\n ${\n sourceContext\n ? `<div class=\"source-context\">\n <div class=\"section-header\">Source</div>\n <pre class=\"source-code\"><code>${sourceContext.lines\n .map(\n (l) =>\n `<span class=\"source-line${l.highlight ? ' source-line-highlight' : ''}\"` +\n `><span class=\"line-num\">${l.num}</span>${esc(l.text)}</span>`\n )\n .join('\\n')}</code></pre>\n </div>`\n : ''\n }\n\n ${\n componentStack\n ? `<div class=\"section\">\n <div class=\"section-header\">Component Stack</div>\n <pre class=\"component-stack\">${esc(componentStack.trim())}</pre>\n </div>`\n : ''\n }\n\n ${\n appFrames.length > 0\n ? `<div class=\"section\">\n <div class=\"section-header\">Application Frames</div>\n <pre class=\"stack\">${appFrames.map((f) => esc(f.raw)).join('\\n')}</pre>\n </div>`\n : ''\n }\n\n ${\n internalFrameCount > 0\n ? `<details class=\"section internal-frames\">\n <summary class=\"section-header clickable\">${internalFrameCount} internal frame${internalFrameCount !== 1 ? 's' : ''}</summary>\n <pre class=\"stack dimmed\">${frames\n .filter((f) => f.type !== 'app')\n .map((f) => esc(f.raw))\n .join('\\n')}</pre>\n </details>`\n : ''\n }\n\n <div class=\"actions\">\n <button class=\"btn\" onclick=\"copyError()\">Copy Error</button>\n </div>`;\n\n const copyScript = ` function copyError() {\n var text = ${escJsonForScript(\n JSON.stringify(\n `${phaseLabel} Error: ${message}\\n\\n` +\n (relPath ? `File: ${relPath}${loc ? `:${loc.line}:${loc.column}` : ''}\\n\\n` : '') +\n (componentStack ? `Component Stack:\\n${componentStack.trim()}\\n\\n` : '') +\n `Stack Trace:\\n${error.stack ?? ''}`\n )\n )};\n navigator.clipboard.writeText(text).then(function() {\n var btn = document.querySelector('.btn');\n if (btn) { btn.textContent = 'Copied!'; setTimeout(function() { btn.textContent = 'Copy Error'; }, 1500); }\n });\n }\n`;\n\n return renderDevPageShell({\n title: `Error — ${phaseLabel} | timber.js`,\n extraCss: ERROR_CSS,\n bodyHtml,\n footerHint: 'Fix the error and save — the page will reload automatically via HMR.',\n extraScript: copyScript,\n hmrOptions,\n });\n}\n\n// ─── Page-Specific CSS ──────────────────────────────────────────────────────\n\nconst ERROR_CSS = `\n :root {\n --badge-bg: #fef2f2;\n --badge-fg: #991b1b;\n --badge-border: #fecaca;\n --highlight-bg: #fef2f2;\n --highlight-border: #ef4444;\n --line-num: #9ca3af;\n }\n\n @media (prefers-color-scheme: dark) {\n :root {\n --badge-bg: #450a0a;\n --badge-fg: #fca5a5;\n --badge-border: #7f1d1d;\n --highlight-bg: #450a0a;\n --highlight-border: #dc2626;\n --line-num: #6b7280;\n }\n }\n\n .location {\n font-family: var(--code-font);\n font-size: 0.8125rem;\n color: var(--link);\n margin-bottom: 1rem;\n padding: 0.5rem 0.75rem;\n background: var(--source-bg);\n border-radius: 0.375rem;\n border: 1px solid var(--border);\n }\n\n .source-context {\n margin-bottom: 1rem;\n border: 1px solid var(--border);\n border-radius: 0.5rem;\n overflow: hidden;\n }\n\n .source-code {\n overflow-x: auto;\n font-family: var(--code-font);\n font-size: 0.8125rem;\n line-height: 1.7;\n padding: 0;\n margin: 0;\n }\n\n .source-code code {\n display: block;\n }\n\n .source-line {\n display: block;\n padding: 0 0.75rem;\n border-left: 3px solid transparent;\n }\n\n .source-line-highlight {\n background: var(--highlight-bg);\n border-left-color: var(--highlight-border);\n }\n\n .line-num {\n display: inline-block;\n width: 3rem;\n text-align: right;\n margin-right: 1rem;\n color: var(--line-num);\n user-select: none;\n }\n\n .clickable { cursor: pointer; }\n .clickable:hover { background: var(--btn-bg); }\n\n .component-stack, .stack {\n font-family: var(--code-font);\n font-size: 0.8125rem;\n line-height: 1.7;\n padding: 0.75rem;\n overflow-x: auto;\n white-space: pre;\n margin: 0;\n }\n\n .dimmed { color: var(--fg-dim); }\n\n .actions {\n margin: 1.5rem 0;\n }\n\n .btn {\n font-family: inherit;\n font-size: 0.8125rem;\n font-weight: 500;\n padding: 0.5rem 1rem;\n border-radius: 0.375rem;\n border: 1px solid var(--btn-border);\n background: var(--btn-bg);\n color: var(--btn-fg);\n cursor: pointer;\n transition: background 0.15s;\n }\n\n .btn:hover { opacity: 0.85; }\n`;\n","/**\n * Per-app dev hostnames — print and open `<name>.localhost:<port>`.\n *\n * Cookies are not scoped by port, so every app served on `localhost` shares\n * one cookie jar: two apps on :3000 and :3001 overwrite each other's\n * sessions, and service workers stuck to `localhost:3000` carry over to\n * whichever project next gets that port. Browsers resolve\n * `*.localhost` (at any depth) to loopback with no DNS or `/etc/hosts` setup,\n * so giving each app its own name gives it its own cookie jar.\n *\n * This only changes the URL Vite prints, opens, and records for discovery.\n * Nothing is proxied, no `Host` is rewritten, and plain `localhost:<port>`\n * keeps working. Vite's host check already accepts `*.localhost`.\n *\n * See design/21-dev-server.md §\"Dev Hostnames\" (TIM-1613).\n */\n\nimport { X509Certificate } from 'node:crypto';\nimport { readFileSync } from 'node:fs';\nimport { basename, join, resolve } from 'node:path';\n\nconst LOCALHOST = 'localhost';\nconst LOCALHOST_SUFFIX = `.${LOCALHOST}`;\n\n/** RFC 1035 label limit. */\nconst MAX_LABEL_LENGTH = 63;\n\n/** RFC 1035 name limit, `.localhost` included. */\nconst MAX_HOSTNAME_LENGTH = 253;\n\n/**\n * Package names that say nothing about the app: the create-timber-app\n * default (`packages/create-timber-app/src/index.ts`) and the generic names\n * people leave in templates. They would put every unrenamed app on the same\n * hostname, and so the same cookie jar, which is exactly what this\n * feature is for avoiding. The directory name is used instead.\n */\nconst PLACEHOLDER_PACKAGE_NAMES = new Set(['app', 'my-app', 'my-timber-app']);\n\nconst LABEL_RE = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;\n\n/**\n * Reduce arbitrary text to one DNS label: lowercase, anything outside\n * `[a-z0-9-]` becomes `-`, runs of `-` collapse, no leading or trailing\n * `-`, at most 63 characters. May return '' when nothing usable is left.\n */\nexport function sanitizeLabel(raw: string): string {\n return raw\n .toLowerCase()\n .replace(/[^a-z0-9-]+/g, '-')\n .replace(/-{2,}/g, '-')\n .replace(/^-+/, '')\n .slice(0, MAX_LABEL_LENGTH)\n .replace(/-+$/, '');\n}\n\n/**\n * Labels for a package name, most specific first: `@acme/web` →\n * `['web', 'acme']` (so `web.acme.localhost`), `example-blog` →\n * `['example-blog']`. Placeholders and non-strings give `[]`.\n */\nfunction packageNameLabels(name: unknown): string[] {\n if (typeof name !== 'string') return [];\n if (PLACEHOLDER_PACKAGE_NAMES.has(name.trim().toLowerCase())) return [];\n const scoped = /^@([^/]+)\\/(.+)$/.exec(name);\n const parts = scoped ? [scoped[2], scoped[1]] : [name];\n return parts.map(sanitizeLabel).filter(Boolean);\n}\n\n/**\n * Why a `dev.hostname` value is unusable, or null when it is fine. Accepts\n * `false` (opt out: keep plain `localhost`) or a dot-separated sequence of\n * DNS labels, case-insensitively, with or without a trailing `.localhost`.\n */\nexport function devHostnameError(value: unknown): string | null {\n if (value === false) return null;\n if (typeof value !== 'string') {\n return `must be a string like \"blog\" or false, got ${JSON.stringify(value)}.`;\n }\n const labels = stripLocalhost(value.toLowerCase());\n if (labels === '') {\n return `${JSON.stringify(value)} names no app. Use a name like \"blog\", or false to keep plain localhost.`;\n }\n const bad = labels.split('.').find((label) => !LABEL_RE.test(label));\n if (bad !== undefined) {\n return (\n `${JSON.stringify(value)} is not a valid hostname: label ${JSON.stringify(bad)} must be ` +\n '1-63 characters of a-z, 0-9 and \"-\", not starting or ending with \"-\".'\n );\n }\n if (labels.length + LOCALHOST_SUFFIX.length > MAX_HOSTNAME_LENGTH) {\n return `${JSON.stringify(value)} is longer than a hostname can be (253 characters with .localhost).`;\n }\n return null;\n}\n\nfunction stripLocalhost(name: string): string {\n if (name === LOCALHOST) return '';\n return name.endsWith(LOCALHOST_SUFFIX) ? name.slice(0, -LOCALHOST_SUFFIX.length) : name;\n}\n\nexport interface DevHostnameSource {\n /** `dev.hostname` from timber.config.ts. */\n override?: string | false;\n /** `name` from the app's package.json, if it has one. */\n packageName?: unknown;\n /** The app directory's own name. */\n dirName: string;\n}\n\n/**\n * The dev hostname for an app. In order:\n *\n * 1. `dev.hostname`, when set (`false` → plain `localhost`). An invalid value\n * throws; config validation reports it as fatal before this runs.\n * 2. package.json `name`, unless it is a placeholder. Preferred over the\n * directory because it is stable across clones and worktrees, so OAuth\n * callback URLs registered against it keep working, and because monorepo\n * directories are generic (`apps/web` everywhere).\n * 3. The directory name.\n * 4. Plain `localhost`, when nothing usable is left after sanitizing.\n */\nexport function deriveDevHostname(source: DevHostnameSource): string {\n const { override } = source;\n if (override === false) return LOCALHOST;\n if (override !== undefined) {\n const error = devHostnameError(override);\n if (error) throw new Error(`[timber] dev.hostname ${error}`);\n return `${stripLocalhost(override.toLowerCase())}${LOCALHOST_SUFFIX}`;\n }\n let labels = packageNameLabels(source.packageName);\n if (labels.length === 0) labels = [sanitizeLabel(source.dirName)].filter(Boolean);\n return labels.length === 0 ? LOCALHOST : `${labels.join('.')}${LOCALHOST_SUFFIX}`;\n}\n\n/**\n * `deriveDevHostname` for the app in `appDir` — the directory its\n * `.timber/` lives in (`devRecordRoot`), where its package.json is. A\n * missing or unreadable package.json falls through to the directory name.\n */\nexport function resolveDevHostname(appDir: string, override: string | false | undefined): string {\n let packageName: unknown;\n try {\n packageName = (\n JSON.parse(readFileSync(join(appDir, 'package.json'), 'utf8')) as {\n name?: unknown;\n }\n ).name;\n } catch {\n packageName = undefined;\n }\n return deriveDevHostname({ override, packageName, dirName: basename(appDir) });\n}\n\n/**\n * A `cert` entry as Vite reads it (`readFileIfExists` in its\n * `resolveHttpsConfig`): a string is first tried as a file path, resolved\n * against the cwd, and is PEM text only when no such file can be read.\n * `config.server.https` keeps the raw option, so the path is read here too.\n */\nfunction certBytes(entry: unknown): string | Uint8Array | null {\n if (entry instanceof Uint8Array) return entry;\n if (typeof entry !== 'string') return null;\n try {\n return readFileSync(resolve(entry));\n } catch {\n return entry;\n }\n}\n\n/**\n * Whether a TLS `cert` option (PEM string or Buffer, a path to one, or an\n * array of them — Node's `tls` shape plus Vite's paths) names `hostname`.\n * A `pfx`-only config has no `cert` and so keeps `localhost`. An https dev server prints the\n * named URL only when it does: a trusted certificate issued for `localhost`\n * alone (mkcert's default) would turn a working URL into a certificate error.\n */\nexport function certCoversHostname(cert: unknown, hostname: string): boolean {\n const pems = Array.isArray(cert) ? cert : [cert];\n return pems.some((entry) => {\n const pem = certBytes(entry);\n if (pem === null) return false;\n try {\n return new X509Certificate(pem).checkHost(hostname) !== undefined;\n } catch {\n return false;\n }\n });\n}\n\n/**\n * The hostname to print for this server, after the https check. `https` is\n * Vite's resolved `server.https` (undefined for plain http).\n */\nexport function effectiveDevHostname(\n hostname: string,\n https: { cert?: unknown } | undefined\n): string {\n if (hostname === LOCALHOST || !https) return hostname;\n return certCoversHostname(https.cert, hostname) ? hostname : LOCALHOST;\n}\n\n/**\n * Vite's `server.resolvedUrls` shape — the URLs it prints under Local and\n * Network and picks from for `server.open`.\n */\nexport interface ResolvedServerUrls {\n local: string[];\n network: string[];\n}\n\n/**\n * Rename the `localhost` entries of `urls.local` to `hostname`. Only those:\n * an explicit loopback IP (`host: '127.0.0.1'`) is what the developer asked\n * to see, certificate-derived names already name a host, and network URLs\n * are other machines' way in. Idempotent: a renamed URL is no longer a\n * `localhost` URL.\n */\nexport function withDevHostname<T extends ResolvedServerUrls>(urls: T, hostname: string): T {\n if (hostname === LOCALHOST) return urls;\n const local = urls.local.map((href) => {\n const url = new URL(href);\n if (url.hostname !== LOCALHOST) return href;\n url.hostname = hostname;\n return url.href;\n });\n return { ...urls, local: [...new Set(local)] };\n}\n\n/**\n * The same URL through plain `localhost`: what a non-browser HTTP client can\n * reach. Browsers and curl resolve `*.localhost` themselves, but Node, Python\n * and other clients ask the OS, and not every resolver (glibc without\n * systemd-resolved) maps `*.localhost` to loopback. The server answers both\n * names, so only the hostname changes. Other URLs are returned unchanged.\n *\n * Under https the swap also has to survive TLS hostname verification: a\n * certificate issued for `blog.localhost` alone fails for `localhost`\n * (`ERR_TLS_CERT_ALTNAME_INVALID`), so the named URL is kept unless the\n * certificate covers `localhost` too. `https` is Vite's `server.https`.\n */\nexport function loopbackUrl(href: string, https: { cert?: unknown } | undefined): string {\n const url = new URL(href);\n if (!url.hostname.endsWith(LOCALHOST_SUFFIX)) return href;\n if (url.protocol === 'https:' && !certCoversHostname(https?.cert, LOCALHOST)) return href;\n url.hostname = LOCALHOST;\n return url.href;\n}\n\n/**\n * The URL a server is opened at, after the rename: Vite's own choice, as its\n * `getServerUrlByHost` makes it for `server.open` — the first URL containing\n * a string `server.host`, else `local[0]`, else `network[0]`. The discovery\n * record stores this, so `timber dev status` reports the URL Vite opens.\n */\nexport function primaryServerUrl(\n urls: ResolvedServerUrls | null | undefined,\n hostname: string,\n serverHost: string | boolean | undefined\n): string | undefined {\n if (!urls) return undefined;\n const named = withDevHostname(urls, hostname);\n const all = [...named.local, ...named.network];\n const byHost =\n typeof serverHost === 'string' ? all.find((url) => url.includes(serverHost)) : undefined;\n return byHost ?? named.local[0] ?? named.network[0];\n}\n\n/** The URLs a discovery record advertises. */\nexport interface AdvertisedUrls {\n /** What the server printed and opens (`primaryServerUrl`). */\n url: string;\n /** The same server for non-browser HTTP clients (`loopbackUrl`). */\n loopbackUrl: string;\n}\n\n/**\n * The record's URLs, computed by the server, which alone knows its\n * certificate. `server` is Vite's resolved `server` config.\n */\nexport function advertisedUrls(\n urls: ResolvedServerUrls | null | undefined,\n hostname: string,\n server: { host?: string | boolean; https?: { cert?: unknown } } | undefined\n): AdvertisedUrls | undefined {\n const url = primaryServerUrl(urls, hostname, server?.host);\n return url === undefined ? undefined : { url, loopbackUrl: loopbackUrl(url, server?.https) };\n}\n\n/** The slice of `ViteDevServer` the rename needs. */\ninterface DevHostnameServer {\n httpServer: { on(event: 'listening', listener: () => void): unknown } | null;\n resolvedUrls: ResolvedServerUrls | null;\n config: { server?: { https?: { cert?: unknown } } };\n}\n\n/**\n * Resolve the app's dev hostname and rename the printed/opened URL once the\n * server is listening. Returns the hostname so the discovery record can\n * describe the same URL (`primaryServerUrl`).\n *\n * Vite assigns `resolvedUrls` in a `listening` listener it *prepends* in\n * `listen()`, after every `configureServer` hook has run, so this listener\n * always sees them; `printUrls()` and `openBrowser()` run after `listen()`\n * resolves. Middleware mode has no `httpServer` and prints nothing.\n */\nexport function applyDevHostname(\n server: DevHostnameServer,\n appDir: string,\n override: string | false | undefined\n): string {\n const hostname = effectiveDevHostname(\n resolveDevHostname(appDir, override),\n server.config.server?.https\n );\n if (server.httpServer && hostname !== LOCALHOST) {\n server.httpServer.on('listening', () => {\n if (server.resolvedUrls) server.resolvedUrls = withDevHostname(server.resolvedUrls, hostname);\n });\n }\n return hostname;\n}\n","/**\n * Config validation — validates timber.config.ts at startup.\n *\n * Runs in the plugin's configResolved hook (once, at startup/build).\n * Each check produces a clear error message with the invalid value,\n * what's expected, and how to fix it.\n *\n * Design doc: 18-build-system.md\n */\n\nimport { createRequire } from 'node:module';\nimport type { TimberUserConfig } from './config-types.ts';\nimport { devHostnameError } from './plugins/dev-hostname.ts';\nimport { DEFAULT_RENDER_TIMEOUT_MS, RENDER_TIMEOUT_CEILING_MS } from './server/render-timeout.ts';\n\n// ─── Types ──────────────────────────────────────────────────────────────────\n\nexport interface ConfigError {\n field: string;\n message: string;\n value?: unknown;\n suggestion?: string;\n /**\n * Refuse to start rather than log. Most config errors only warn — Vite may\n * still work partially — but a fatal one would leave a security check\n * running on a value the developer did not mean (`allowedOrigins`).\n */\n fatal?: true;\n}\n\n// ─── Known config keys ──────────────────────────────────────────────────────\n\n// `satisfies Record<keyof TimberUserConfig, true>` makes this drift-proof:\n// adding a key to TimberUserConfig without listing it here is a compile\n// error, so validateConfig can never reject a documented option (TIM-1066).\nconst KNOWN_CONFIG_KEYS = {\n output: true,\n debug: true,\n clientJavascript: true,\n adapter: true,\n allowedOrigins: true,\n csrf: true,\n limits: true,\n forms: true,\n pageExtensions: true,\n optimizePackageImports: true,\n slowRequestMs: true,\n renderTimeoutMs: true,\n devBrowserLogs: true,\n dev: true,\n serverTiming: true,\n appDir: true,\n mdx: true,\n actionEncryption: true,\n reactCompiler: true,\n sitemap: true,\n buildDir: true,\n cache: true,\n defaultLayoutLifetime: true,\n topLoader: true,\n budget: true,\n} satisfies Record<keyof TimberUserConfig, true>;\n\nconst knownKeys = new Set<string>(Object.keys(KNOWN_CONFIG_KEYS));\n\n// ─── Validation ─────────────────────────────────────────────────────────────\n\n/**\n * Validate a TimberUserConfig object.\n *\n * Returns an array of errors. Empty array means the config is valid.\n * Does not throw — the caller decides how to surface errors.\n */\nexport function validateConfig(config: TimberUserConfig): ConfigError[] {\n const errors: ConfigError[] = [];\n\n // output\n if (config.output !== undefined && config.output !== 'server' && config.output !== 'static') {\n errors.push({\n field: 'output',\n message: `Invalid output mode: \"${String(config.output)}\". Must be \"server\" or \"static\".`,\n value: config.output,\n suggestion: 'Use output: \"server\" (default) or output: \"static\" for static site generation.',\n });\n }\n\n // pageExtensions\n if (config.pageExtensions !== undefined) {\n if (!Array.isArray(config.pageExtensions)) {\n errors.push({\n field: 'pageExtensions',\n message: 'pageExtensions must be an array of strings.',\n value: config.pageExtensions,\n suggestion: 'Example: pageExtensions: [\"tsx\", \"ts\", \"jsx\", \"js\", \"mdx\"]',\n });\n } else {\n for (const ext of config.pageExtensions) {\n if (typeof ext !== 'string') {\n errors.push({\n field: 'pageExtensions',\n message: `pageExtensions contains a non-string value: ${JSON.stringify(ext)}`,\n value: ext,\n });\n break;\n }\n if (ext.startsWith('.')) {\n errors.push({\n field: 'pageExtensions',\n message: `pageExtensions should not include the leading dot: \"${ext}\"`,\n value: ext,\n suggestion: `Use \"${ext.slice(1)}\" instead of \"${ext}\".`,\n });\n break;\n }\n }\n }\n }\n\n // optimizePackageImports\n if (config.optimizePackageImports !== undefined) {\n const list: unknown = config.optimizePackageImports;\n const badIndex = Array.isArray(list)\n ? list.findIndex((entry) => typeof entry !== 'string' || entry.trim() === '')\n : -1;\n if (!Array.isArray(list) || badIndex !== -1) {\n const value = Array.isArray(list) ? list[badIndex] : list;\n errors.push({\n field: 'optimizePackageImports',\n message: Array.isArray(list)\n ? `optimizePackageImports contains an invalid entry: ${String(JSON.stringify(value))}`\n : 'optimizePackageImports must be an array of import specifiers.',\n value,\n suggestion: 'Example: optimizePackageImports: [\"@acme/icons\", \"react-icons/fa\"]',\n });\n }\n }\n\n // allowedOrigins\n if (config.allowedOrigins !== undefined) {\n if (!Array.isArray(config.allowedOrigins)) {\n errors.push({\n field: 'allowedOrigins',\n message: 'allowedOrigins must be an array of origin strings.',\n value: config.allowedOrigins,\n fatal: true,\n suggestion: 'Example: allowedOrigins: [\"https://app.example.com\"]',\n });\n } else {\n for (const entry of config.allowedOrigins) {\n const error = allowedOriginError(entry);\n if (error) errors.push(error);\n }\n }\n }\n\n // slowRequestMs\n if (config.slowRequestMs !== undefined) {\n if (typeof config.slowRequestMs !== 'number' || config.slowRequestMs < 0) {\n errors.push({\n field: 'slowRequestMs',\n message: `slowRequestMs must be a non-negative number (got ${JSON.stringify(config.slowRequestMs)}).`,\n value: config.slowRequestMs,\n suggestion: 'Use slowRequestMs: 3000 (default) or slowRequestMs: 0 to disable.',\n });\n }\n }\n\n // renderTimeoutMs\n if (config.renderTimeoutMs !== undefined) {\n if (typeof config.renderTimeoutMs !== 'number' || config.renderTimeoutMs < 0) {\n errors.push({\n field: 'renderTimeoutMs',\n message: `renderTimeoutMs must be a non-negative number (got ${JSON.stringify(config.renderTimeoutMs)}).`,\n value: config.renderTimeoutMs,\n suggestion: `Use renderTimeoutMs: ${DEFAULT_RENDER_TIMEOUT_MS} (default). Setting 0 uses a ${RENDER_TIMEOUT_CEILING_MS / 1000}s safety ceiling.`,\n });\n }\n }\n\n // serverTiming\n if (config.serverTiming !== undefined) {\n if (\n config.serverTiming !== 'detailed' &&\n config.serverTiming !== 'total' &&\n config.serverTiming !== false\n ) {\n errors.push({\n field: 'serverTiming',\n message: `Invalid serverTiming value: ${JSON.stringify(config.serverTiming)}.`,\n value: config.serverTiming,\n suggestion: 'Use \"detailed\", \"total\", or false.',\n });\n }\n }\n\n // defaultLayoutLifetime — not fatal: every reader treats a value other than\n // 'document' as 'request', the default, which is slower but never wrong\n // (design/53 §\"App-wide default\").\n if (\n config.defaultLayoutLifetime !== undefined &&\n config.defaultLayoutLifetime !== 'request' &&\n config.defaultLayoutLifetime !== 'document'\n ) {\n errors.push({\n field: 'defaultLayoutLifetime',\n message: `Invalid defaultLayoutLifetime value: ${JSON.stringify(config.defaultLayoutLifetime)}.`,\n value: config.defaultLayoutLifetime,\n suggestion: \"Use 'request' (the default) or 'document'.\",\n });\n }\n\n // devBrowserLogs\n if (config.devBrowserLogs !== undefined) {\n const valid = ['error', 'warn', 'info', 'none'];\n if (!valid.includes(config.devBrowserLogs)) {\n errors.push({\n field: 'devBrowserLogs',\n message: `Invalid devBrowserLogs value: ${JSON.stringify(config.devBrowserLogs)}.`,\n value: config.devBrowserLogs,\n suggestion: `Use one of: ${valid.map((v) => `\"${v}\"`).join(', ')}.`,\n });\n }\n }\n\n // Boolean dev switches — not fatal: dev-only, like dev.hostname below.\n const devSwitches = [\n ['requestPill', 'the dev request pill'],\n ['precompile', 'the background server compile'],\n ] as const;\n for (const [key, what] of devSwitches) {\n const value = config.dev?.[key];\n if (value !== undefined && typeof value !== 'boolean') {\n errors.push({\n field: `dev.${key}`,\n message: `dev.${key} must be a boolean, got ${JSON.stringify(value)}.`,\n value,\n suggestion: `Use dev: { ${key}: false } to turn ${what} off.`,\n });\n }\n }\n\n // dev.hostname — not fatal: it is dev-only, so a typo must not fail\n // `timber build`. Dev startup still refuses it (deriveDevHostname throws).\n if (config.dev?.hostname !== undefined) {\n const problem = devHostnameError(config.dev.hostname);\n if (problem) {\n errors.push({\n field: 'dev.hostname',\n message: `dev.hostname ${problem}`,\n value: config.dev.hostname,\n suggestion:\n 'Use DNS labels separated by dots, e.g. dev: { hostname: \"blog\" } for blog.localhost, ' +\n 'or false to keep plain localhost.',\n });\n }\n }\n\n // sitemap\n if (config.sitemap != null && typeof config.sitemap === 'object') {\n if (config.sitemap.enabled && !config.sitemap.baseUrl) {\n errors.push({\n field: 'sitemap.baseUrl',\n message: 'sitemap.baseUrl is required when sitemap is enabled.',\n suggestion: 'Add sitemap: { enabled: true, baseUrl: \"https://example.com\" }.',\n });\n }\n if (\n config.sitemap.defaultPriority !== undefined &&\n (config.sitemap.defaultPriority < 0 || config.sitemap.defaultPriority > 1)\n ) {\n errors.push({\n field: 'sitemap.defaultPriority',\n message: `sitemap.defaultPriority must be between 0.0 and 1.0 (got ${config.sitemap.defaultPriority}).`,\n value: config.sitemap.defaultPriority,\n });\n }\n }\n\n // budget\n if (config.budget != null && typeof config.budget === 'object') {\n if (\n config.budget.firstLoadJs !== undefined &&\n (typeof config.budget.firstLoadJs !== 'number' || config.budget.firstLoadJs <= 0)\n ) {\n errors.push({\n field: 'budget.firstLoadJs',\n message: `budget.firstLoadJs must be a positive number in bytes (got ${JSON.stringify(config.budget.firstLoadJs)}).`,\n value: config.budget.firstLoadJs,\n suggestion: 'Example: budget: { firstLoadJs: 150_000 } for a ~150 kB limit.',\n });\n }\n }\n\n // cache\n if (config.cache != null && typeof config.cache === 'object') {\n if (\n config.cache.strictKeyDiscipline !== undefined &&\n typeof config.cache.strictKeyDiscipline !== 'boolean'\n ) {\n errors.push({\n field: 'cache.strictKeyDiscipline',\n message: `cache.strictKeyDiscipline must be a boolean (got ${JSON.stringify(config.cache.strictKeyDiscipline)}).`,\n value: config.cache.strictKeyDiscipline,\n suggestion:\n 'Use cache: { strictKeyDiscipline: true } to promote key-discipline warnings to errors.',\n });\n }\n }\n\n const MOVED_TO_CACHE_FILE = new Set(['cacheHandler', 'cdnPurge']);\n\n for (const key of Object.keys(config)) {\n if (!knownKeys.has(key)) {\n errors.push({\n field: key,\n message: `Unknown config option: \"${key}\".`,\n suggestion: MOVED_TO_CACHE_FILE.has(key)\n ? `\"${key}\" has moved to timber.cache.ts. Export cacheHandler as default, cdnPurge as a named export.`\n : `Check for typos. Known options: ${[...knownKeys].sort().join(', ')}.`,\n });\n }\n }\n\n return errors;\n}\n\n/**\n * Why one `allowedOrigins` entry can never match, or null when it can.\n *\n * The CSRF check compares entries to the request's `Origin` header by\n * exact string, and browsers send only the canonical form — scheme, host,\n * and non-default port, lowercased, no path. So an entry that is not its\n * own `new URL(x).origin` (`https://example.com/`, `https://Example.com`,\n * `example.com`) silently matches nothing. `\"null\"` is refused outright:\n * it is the `Origin` of every opaque context at once.\n */\nfunction allowedOriginError(entry: unknown): ConfigError | null {\n const field = 'allowedOrigins';\n const fatal = true;\n if (typeof entry !== 'string') {\n return {\n field,\n message: `allowedOrigins contains a non-string value: ${JSON.stringify(entry)}.`,\n value: entry,\n fatal,\n };\n }\n if (entry === 'null') {\n return {\n field,\n message:\n 'allowedOrigins cannot contain \"null\". Browsers send Origin: null from every opaque ' +\n \"context — sandboxed iframes (an attacker's <iframe sandbox> included), POSTs \" +\n 'redirected across origins, and file: pages — so allowing it allows all of them.',\n value: entry,\n suggestion:\n 'To accept a cross-site POST on one endpoint, handle it in a route.ts that exports ' +\n '`const csrf = false` instead.',\n fatal,\n };\n }\n // `new URL('https://*.example.com').origin` round-trips, so the canonical\n // check alone would accept a wildcard that matches no real Origin.\n if (entry.includes('*')) {\n return {\n field,\n message: `allowedOrigins entry ${JSON.stringify(entry)} uses a wildcard. Matching is exact; wildcards are not supported.`,\n value: entry,\n suggestion:\n 'List each origin, e.g. [\"https://app.example.com\", \"https://admin.example.com\"].',\n fatal,\n };\n }\n const canonical = canonicalOrigin(entry) ?? canonicalOrigin(`https://${entry}`);\n if (canonical === entry) return null;\n return {\n field,\n message: `allowedOrigins entry ${JSON.stringify(entry)} is not a canonical origin, so it can never match a request's Origin header.`,\n value: entry,\n suggestion: canonical\n ? `Did you mean \"${canonical}\"? An origin is scheme://host[:port] — lowercase, no path or trailing slash.`\n : 'An origin is scheme://host[:port], e.g. \"https://app.example.com\".',\n fatal,\n };\n}\n\n/** `new URL(x).origin` for an http(s) URL, or null. Opaque origins are not origins here. */\nfunction canonicalOrigin(value: string): string | null {\n try {\n const url = new URL(value);\n return url.protocol === 'http:' || url.protocol === 'https:' ? url.origin : null;\n } catch {\n return null;\n }\n}\n\n// ─── Formatting ─────────────────────────────────────────────────────────────\n\nconst RED = '\\x1b[31m';\nconst BOLD = '\\x1b[1m';\nconst DIM = '\\x1b[2m';\nconst RESET = '\\x1b[0m';\n\n/**\n * Format config errors for terminal output. Pass `color: false` for text\n * that goes into a thrown `Error` — escapes there reach CI logs and the\n * Vite overlay as raw bytes.\n */\nexport function formatConfigErrors(\n errors: ConfigError[],\n { color = true }: { color?: boolean } = {}\n): string {\n if (errors.length === 0) return '';\n const [red, bold, dim, reset] = color ? [RED, BOLD, DIM, RESET] : ['', '', '', ''];\n\n const lines: string[] = [];\n lines.push(\n `${red}${bold}[timber]${reset} ${red}${errors.length} config error${errors.length !== 1 ? 's' : ''} in timber.config.ts:${reset}`\n );\n\n for (const err of errors) {\n lines.push('');\n lines.push(` ${red}✗${reset} ${bold}${err.field}${reset}: ${err.message}`);\n if (err.suggestion) {\n lines.push(` ${dim}${err.suggestion}${reset}`);\n }\n }\n\n return lines.join('\\n');\n}\n\n/**\n * Surface config errors at startup: non-fatal ones are written to stderr\n * (Vite may still work partially, and the message guides the fix); fatal\n * ones then stop startup with a thrown error. Non-fatal errors are written\n * first so a fatal one does not hide them.\n */\nexport function reportConfigErrors(\n errors: ConfigError[],\n write: (text: string) => void = (text) => process.stderr.write(text)\n): void {\n const warnings = errors.filter((e) => !e.fatal);\n if (warnings.length > 0) write(`${formatConfigErrors(warnings)}\\n\\n`);\n const fatal = errors.filter((e) => e.fatal);\n if (fatal.length > 0) throw new Error(formatConfigErrors(fatal, { color: false }));\n}\n\n// ─── Virtual Module Name Mapping ────────────────────────────────────────────\n\nconst VIRTUAL_MODULE_NAMES: Record<string, string> = {\n 'virtual:timber-rsc-entry': 'RSC entry (server component handler)',\n 'virtual:timber-ssr-entry': 'SSR entry (HTML renderer)',\n 'virtual:timber-browser-entry': 'Browser entry (client hydration)',\n 'virtual:timber-config': 'Runtime config (timber.config.ts)',\n 'virtual:timber-route-manifest': 'Route manifest (app/ file tree)',\n 'virtual:timber-instrumentation': 'Instrumentation (instrumentation.ts)',\n 'virtual:timber-cache-handler': 'Cache handler (timber.cache.ts)',\n 'virtual:timber-build-manifest': 'Build manifest (asset mapping)',\n};\n\n/**\n * Add timber-specific context to an error message that references virtual modules.\n *\n * If the error message contains a `virtual:timber-*` ID, appends a\n * human-readable explanation. Does not replace the original message.\n */\nexport function addVirtualModuleContext(errorMessage: string): string {\n for (const [id, name] of Object.entries(VIRTUAL_MODULE_NAMES)) {\n if (errorMessage.includes(id)) {\n return `${errorMessage}\\n\\n [timber] This error references \"${id}\" — timber's ${name}.\\n This is an internal module. The issue is likely in your app code or timber configuration.`;\n }\n }\n return errorMessage;\n}\n\n// ─── Peer Dependency Check ──────────────────────────────────────────────────\n\ninterface PeerDepResult {\n name: string;\n status: 'ok' | 'missing';\n}\n\n/**\n * Required (non-optional) peer dependencies that must be installed.\n */\nconst REQUIRED_PEERS = ['react', 'react-dom', '@vitejs/plugin-react', '@vitejs/plugin-rsc'];\n\n/**\n * Check that required peer dependencies are installed.\n *\n * Uses require.resolve with a try/catch — no fs scanning.\n * Returns only the missing packages.\n */\nexport function checkPeerDependencies(projectRoot: string): PeerDepResult[] {\n const results: PeerDepResult[] = [];\n\n // Use createRequire from the project root to resolve as the user would.\n // `createRequire` MUST be a top-level ESM import — inline `require('node:module')`\n // throws \"Dynamic require not supported\" in ESM and the catch below would\n // mark every peer as missing. Same class of bug as TIM-796.\n const userRequire = createRequire(`${projectRoot}/package.json`);\n\n for (const name of REQUIRED_PEERS) {\n try {\n userRequire.resolve(name);\n results.push({ name, status: 'ok' });\n } catch {\n results.push({ name, status: 'missing' });\n }\n }\n\n return results;\n}\n\n/**\n * Format missing peer dependencies as an actionable warning.\n */\nexport function formatMissingPeers(results: PeerDepResult[]): string {\n const missing = results.filter((r) => r.status === 'missing');\n if (missing.length === 0) return '';\n\n const names = missing.map((r) => r.name);\n const lines: string[] = [];\n lines.push(`${RED}${BOLD}[timber]${RESET} ${RED}Missing required dependencies:${RESET}`);\n lines.push('');\n for (const name of names) {\n lines.push(` ${RED}✗${RESET} ${name}`);\n }\n lines.push('');\n lines.push(` ${DIM}Install with:${RESET}`);\n lines.push(` ${BOLD}pnpm add ${names.join(' ')}${RESET}`);\n\n return lines.join('\\n');\n}\n","/**\n * Route manifest codegen — generates virtual module source for the route\n * manifest and the global schema loader.\n *\n * Extracted from plugins/routing.ts to keep it under the 500-line budget.\n * See design/18-build-system.md §\"Virtual Modules\".\n *\n * Task: TIM-1071 item 8\n */\n\nimport { existsSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { collectInterceptionRewrites } from './interception.ts';\nimport type { RouteTree, SegmentNode, RouteFile } from './types.ts';\n\n// ── Single-file conventions ─────────────────────────────────────────────\n// Each entry maps to a node property that holds a single RouteFile.\n// Order matches the original serializeNode output for byte-identical diffs.\nexport const SINGLE_FILE_KEYS = [\n 'page',\n 'layout',\n 'middleware',\n 'access',\n 'route',\n 'error',\n 'default',\n 'denied',\n] as const;\n\n// ── Record-shaped conventions ───────────────────────────────────────────\n// Each entry maps to a node property that holds Record<string, RouteFile>.\nexport const RECORD_FILE_KEYS = ['statusFiles', 'jsonStatusFiles', 'metadataRoutes'] as const;\n\nconst SCHEMA_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx'];\n\n// ── Manifest generation ─────────────────────────────────────────────────\n\n/**\n * Generate the virtual module source for the route manifest.\n *\n * The output is a default-exported object containing the serialized route tree.\n * All file references use absolute paths (required for virtual modules).\n */\nexport function generateManifestModule(tree: RouteTree, viteRoot: string): string {\n const imports: string[] = [];\n let importIndex = 0;\n\n function addImport(file: RouteFile): string {\n const varName = `_route${importIndex++}`;\n imports.push(`const ${varName} = () => import(\"${file.filePath}\");`);\n return varName;\n }\n\n function serializeRouteFile(key: string, file: RouteFile, indent: string): string {\n const v = addImport(file);\n return `${indent}${key}: { load: ${v}, filePath: ${JSON.stringify(file.filePath)} },`;\n }\n\n function serializeRouteFileRecord(\n key: string,\n record: Record<string, RouteFile>,\n indent: string\n ): string | null {\n const entries = Object.entries(record);\n if (entries.length === 0) return null;\n const inner = entries.map(([name, file]) => {\n const v = addImport(file);\n return `${indent} ${JSON.stringify(name)}: { load: ${v}, filePath: ${JSON.stringify(file.filePath)} }`;\n });\n return `${indent}${key}: {\\n${inner.join(',\\n')}\\n${indent}},`;\n }\n\n function serializeNode(node: SegmentNode, indent: string): string {\n const nextIndent = indent + ' ';\n const parts: string[] = [];\n\n parts.push(`${nextIndent}segmentName: ${JSON.stringify(node.segmentName)},`);\n parts.push(`${nextIndent}segmentType: ${JSON.stringify(node.segmentType)},`);\n parts.push(`${nextIndent}urlPath: ${JSON.stringify(node.urlPath)},`);\n\n if (node.paramName) {\n parts.push(`${nextIndent}paramName: ${JSON.stringify(node.paramName)},`);\n }\n if (node.paramPrefix) {\n parts.push(`${nextIndent}paramPrefix: ${JSON.stringify(node.paramPrefix)},`);\n }\n if (node.paramSuffix) {\n parts.push(`${nextIndent}paramSuffix: ${JSON.stringify(node.paramSuffix)},`);\n }\n\n if (node.interceptionMarker) {\n parts.push(`${nextIndent}interceptionMarker: ${JSON.stringify(node.interceptionMarker)},`);\n }\n if (node.interceptedSegmentName) {\n parts.push(\n `${nextIndent}interceptedSegmentName: ${JSON.stringify(node.interceptedSegmentName)},`\n );\n }\n\n // Single-file conventions — table-driven to avoid copy-paste drift\n for (const key of SINGLE_FILE_KEYS) {\n const file = node[key];\n if (file) {\n parts.push(serializeRouteFile(key, file, nextIndent));\n }\n }\n\n // Read from route.ts source at scan time; the CSRF gate consults it\n // before any user module loads (design/08 §\"Per-route exemption\").\n if (node.csrfExempt) {\n parts.push(`${nextIndent}csrfExempt: true,`);\n }\n\n // Record-shaped conventions — table-driven\n for (const key of RECORD_FILE_KEYS) {\n const record = node[key];\n if (record) {\n const line = serializeRouteFileRecord(key, record, nextIndent);\n if (line) parts.push(line);\n }\n }\n\n // Children\n if (node.children.length > 0) {\n const childNodes = node.children.map((c) => serializeNode(c, nextIndent));\n parts.push(`${nextIndent}children: [\\n${childNodes.join(',\\n')}\\n${nextIndent}],`);\n } else {\n parts.push(`${nextIndent}children: [],`);\n }\n\n // Parallel slots\n const slotKeys = Object.keys(node.slots);\n if (slotKeys.length > 0) {\n const slotEntries: string[] = [];\n for (const slotName of slotKeys) {\n const slotNode = node.slots[slotName]!;\n slotEntries.push(\n `${nextIndent} ${JSON.stringify(slotName)}: ${serializeNode(slotNode, nextIndent + ' ')}`\n );\n }\n parts.push(`${nextIndent}slots: {\\n${slotEntries.join(',\\n')}\\n${nextIndent}},`);\n } else {\n parts.push(`${nextIndent}slots: {},`);\n }\n\n return `${indent}{\\n${parts.join('\\n')}\\n${indent}}`;\n }\n\n const rootSerialized = serializeNode(tree.root, ' ');\n\n let proxyLine = '';\n if (tree.proxy) {\n const v = addImport(tree.proxy);\n proxyLine = ` proxy: { load: ${v}, filePath: ${JSON.stringify(tree.proxy.filePath)} },`;\n }\n\n let globalErrorLine = '';\n if (tree.globalError) {\n const v = addImport(tree.globalError);\n globalErrorLine = ` globalError: { load: ${v}, filePath: ${JSON.stringify(tree.globalError.filePath)} },`;\n }\n\n // Serialize the rewrite objects wholesale — an explicit field list here\n // silently drops any field added to InterceptionRewrite, and the guard that\n // reads it would then fall back to matching too broadly. InterceptionRewrite\n // is plain JSON data by construction (no file references, no functions).\n const rewrites = collectInterceptionRewrites(tree.root);\n const rewritesLine =\n rewrites.length > 0 ? ` interceptionRewrites: ${JSON.stringify(rewrites)},` : '';\n\n const code = [\n '// Auto-generated route manifest — do not edit.',\n '// Generated by timber-routing plugin.',\n '',\n ...imports,\n '',\n 'const manifest = {',\n ` viteRoot: ${JSON.stringify(viteRoot)},`,\n proxyLine,\n globalErrorLine,\n rewritesLine,\n ` root: ${rootSerialized},`,\n '};',\n '',\n 'export default manifest;',\n ]\n .filter((line) => line !== undefined && line !== '')\n .join('\\n');\n\n return code;\n}\n\n// ── Schema module ───────────────────────────────────────────────────────\n\n/**\n * Generate the virtual:timber-schema module.\n *\n * When app/schema.{ts,tsx,js,jsx} exists, generates a module that\n * imports the schema and resolves its segmentParams codecs into a\n * bare-name codec map for runtime coercion.\n */\nexport function generateSchemaModule(appDir: string): string {\n let schemaPath: string | null = null;\n for (const ext of SCHEMA_EXTENSIONS) {\n const candidate = join(appDir, `schema${ext}`);\n if (existsSync(candidate)) {\n schemaPath = candidate;\n break;\n }\n }\n\n if (!schemaPath) {\n return [\n '// Auto-generated schema loader — no app/schema.ts found.',\n 'export default null;',\n ].join('\\n');\n }\n\n return [\n '// Auto-generated schema loader — do not edit.',\n '// Generated by timber-routing plugin (TIM-931).',\n '',\n `import schema from ${JSON.stringify(schemaPath)};`,\n `import { resolveSchemaCodecs } from '@timber-js/app/params';`,\n '',\n 'const globalCodecs = schema?.segmentParams',\n ' ? resolveSchemaCodecs(schema.segmentParams)',\n ' : null;',\n '',\n 'export default globalCodecs;',\n ].join('\\n');\n}\n","/**\n * Dev pre-compile — transform the server module graphs in the background\n * once the dev server listens, so the first request does not wait on Vite\n * compiling server code module by module.\n *\n * Vite pre-transforms nothing in server environments: the first request's\n * module runner asks for each module as an import reaches it, one after\n * another. On the kitchen-sink that was ~1.2s importing the RSC entry\n * (~270 modules) and ~650ms more importing the SSR entry, which only starts\n * after the RSC render. The crawl here transforms the same graph ahead of\n * the request, without running it.\n *\n * - `env.transformRequest()` only: nothing executes, so the app's\n * instrumentation `register()` and cache handler setup still run at the\n * first request, as before.\n * - Static imports only (`result.deps`), from the entries and every module\n * file in the route tree ({@link routeTreeSeeds}). Route files are dynamic\n * imports of the route manifest, which the crawl does not follow, so they\n * are seeded directly. Crawling only the root layout left most of an app\n * whose UI sits in route groups and slots to the first request: on\n * relisten-web it covered 53 of the 499 SSR modules `GET /` needed, and the\n * whole route tree (~960 modules) takes ~1.6s (TIM-1630).\n * - In waves: what `GET /` can load first, RSC then SSR, so the\n * most common first request is ready soonest; then the rest.\n * - Errors are swallowed. The request that loads the module hits the same\n * error and reports it as it always has; Vite's `warmupRequest` was\n * rejected because it logs each error a second time.\n *\n * - It stops when the HTTP server closes, and after\n * {@link PRECOMPILE_DEADLINE_MS}. Vite's `close()` waits for every\n * transform in flight, and server environments do not refuse new ones\n * while closing, so a crawl that kept going would hold a restart for the\n * rest of the graph.\n *\n * `analyze/crawl.ts` also walks `transformRequest`, for a different job:\n * classifying every module the app can reach, dynamic imports included, in\n * a throwaway middleware-mode server.\n *\n * `dev.precompile: false` in timber.config, or `TIMBER_DEV_PRECOMPILE=0`,\n * turns it off.\n *\n * See design/21-dev-server.md §\"Server Pre-compile\".\n */\n\nimport { normalizePath, type DevEnvironment, type ViteDevServer } from 'vite';\nimport type { PluginApi } from '@vitejs/plugin-rsc';\nimport type { RouteFile, RouteTree, SegmentNode } from '../routing/types.ts';\nimport { RECORD_FILE_KEYS, SINGLE_FILE_KEYS } from '../routing/manifest-codegen.ts';\nimport { isStaticMetadataExtension } from '../server/metadata-routes.ts';\n\n/** `TIMBER_DEV_PRECOMPILE=0` turns the crawl off (A/B measurement, escape hatch). */\nexport const PRECOMPILE_ENV = 'TIMBER_DEV_PRECOMPILE';\n\n/**\n * Past this, the crawl starts no new transform. Generous: the whole route\n * tree takes ~1.6s on relisten-web. It bounds a crawl stuck behind a slow\n * transform plugin, or an app too large to finish.\n */\nexport const PRECOMPILE_DEADLINE_MS = 60_000;\n\n/**\n * The roots of each server environment's crawl. `rsc` is crawled in waves,\n * in order; after each wave the SSR environment crawls `ssr` and every\n * client reference recorded so far.\n */\nexport interface PrecompileRoots {\n rsc: string[][];\n ssr: string[];\n}\n\n/**\n * Segment types whose subtree can match its parent's URL: they consume no\n * URL segment (or none, for an empty optional catch-all).\n */\nconst PATHLESS = new Set(['group', 'optional-catch-all']);\n\n/** `node`, or a pathless segment under it, has a page or handler for its URL. */\nfunction rendersOwnPath(node: SegmentNode): boolean {\n if (node.page || node.route) return true;\n return node.children.some((child) => PATHLESS.has(child.segmentType) && rendersOwnPath(child));\n}\n\n/**\n * The files of a segment that the runtime loads as modules: every file the\n * route manifest lists for it (routing/manifest-codegen.ts, so a convention\n * the manifest learns is crawled too), except JSON status files and static\n * metadata files (`sitemap.xml`, `icon.png`, …), which are read from disk\n * and never imported.\n */\nfunction segmentFiles(node: SegmentNode): RouteFile[] {\n const files: RouteFile[] = [];\n for (const key of SINGLE_FILE_KEYS) {\n const file = node[key];\n if (file) files.push(file);\n }\n for (const key of RECORD_FILE_KEYS) {\n if (key === 'jsonStatusFiles') continue;\n for (const [name, file] of Object.entries(node[key] ?? {})) {\n if (key === 'metadataRoutes' && isStaticMetadataExtension(name, file.extension)) continue;\n files.push(file);\n }\n }\n return files;\n}\n\n/**\n * Every module file in the route tree, in two waves. `home` is what `GET /`\n * can load: `proxy.ts`, `global-error`, the root segment, and under it the\n * pathless segments (groups, optional catch-alls) with a page or handler at\n * `/`, and the slots of those. A group that only organises other sections\n * (`(admin)/admin/…`) is not in it. `rest` is every other segment's.\n */\nexport function routeTreeSeeds(tree: RouteTree): { home: string[]; rest: string[] } {\n const home: string[] = [];\n const rest: string[] = [];\n for (const file of [tree.proxy, tree.globalError]) if (file) home.push(file.filePath);\n const walk = (node: SegmentNode, inHome: boolean): void => {\n for (const file of segmentFiles(node)) (inHome ? home : rest).push(file.filePath);\n for (const child of node.children) {\n walk(child, inHome && PATHLESS.has(child.segmentType) && rendersOwnPath(child));\n }\n // A slot renders beside its parent's page, so it is in whichever wave\n // its parent is.\n for (const slot of Object.values(node.slots)) walk(slot, inHome);\n };\n walk(tree.root, true);\n return { home, rest };\n}\n\n/**\n * The id `transformRequest` takes for an entry of `result.deps`, or null for\n * one it must not follow: a bare specifier, which in a server environment is\n * a Node builtin (`node:fs`) or a package Vite externalized, both loaded by\n * Node natively.\n * Import analysis writes a `\\0` virtual id as `/@id/__x00__…`, and other\n * non-URL ids as `/@id/…`; the module runner unwraps both the same way.\n */\nexport function crawlableId(dep: string): string | null {\n if (dep.startsWith('/@id/__x00__')) return `\\0${dep.slice('/@id/__x00__'.length)}`;\n if (dep.startsWith('/@id/')) return dep.slice('/@id/'.length);\n if (dep.startsWith('/')) return dep;\n return null;\n}\n\n/**\n * The URL a module importing `file` asks for, after import analysis: root\n * relative inside the Vite root, `/@fs/…` outside it. Vite shares a\n * transform in flight only between requests for the same URL, so a root\n * seeded as a bare path would be transformed twice when a request for it\n * arrives mid-crawl.\n */\nexport function fileUrl(file: string, root: string): string {\n const path = normalizePath(file);\n const base = normalizePath(root).replace(/\\/?$/, '/');\n return path.startsWith(base)\n ? path.slice(base.length - 1)\n : `/@fs${path.startsWith('/') ? '' : '/'}${path}`;\n}\n\n/**\n * Transform `roots` and every module they statically import in `env`.\n * Starts no transform once `shouldStop()` is true. Resolves with the\n * number of ids in `seen` (every module visited in `env` so far, across\n * crawls that share it) once the graph is done; never rejects. `seen`\n * carries visited ids across crawls of one environment, so a later wave\n * skips what an earlier one transformed.\n */\nexport async function crawlServerGraph(\n env: DevEnvironment,\n roots: string[],\n shouldStop: () => boolean = () => false,\n seen: Set<string> = new Set()\n): Promise<number> {\n const visit = async (id: string): Promise<void> => {\n if (seen.has(id) || shouldStop()) return;\n seen.add(id);\n let deps: string[];\n try {\n deps = (await env.transformRequest(id))?.deps ?? [];\n } catch {\n return;\n }\n await Promise.all(\n deps.map((dep) => {\n const next = crawlableId(dep);\n return next === null ? undefined : visit(next);\n })\n );\n };\n await Promise.all(roots.map(visit));\n return seen.size;\n}\n\n/**\n * The SSR environment loads each client component the RSC render\n * references, by the id plugin-rsc registered for it. Read after each RSC\n * wave: plugin-rsc records a client reference when it transforms\n * the `'use client'` module in the RSC environment.\n */\nfunction clientReferenceIds(server: ViteDevServer): string[] {\n // What plugin-rsc's own `getPluginApi(config)` does. Vite types a plugin's\n // `api` as `any`; the annotation names its shape. Not imported: plugin-rsc\n // is ESM-only and loaded at runtime (`loadPluginRsc`), never statically.\n const api: PluginApi | undefined = server.config.plugins.find(\n (p) => p.name === 'rsc:minimal'\n )?.api;\n const metaMap = api?.manager.clientReferenceMetaMap ?? {};\n return Object.values(metaMap).flatMap((meta) => {\n const id = crawlableId(meta.importId);\n return id === null ? [] : [id];\n });\n}\n\n/**\n * For each RSC wave, crawl the RSC graph, then the SSR graph with the client\n * references found so far. A request that arrives mid-crawl shares the\n * transforms already in flight for the URLs it asks for.\n */\nexport async function precompileServerGraphs(\n server: ViteDevServer,\n roots: PrecompileRoots,\n shouldStop: () => boolean\n): Promise<void> {\n const { rsc, ssr } = server.environments;\n const rscSeen = new Set<string>();\n const ssrSeen = new Set<string>();\n for (const wave of roots.rsc) {\n if (shouldStop()) return;\n if (rsc) await crawlServerGraph(rsc, wave, shouldStop, rscSeen);\n if (ssr && !shouldStop()) {\n await crawlServerGraph(\n ssr,\n [...roots.ssr, ...clientReferenceIds(server)],\n shouldStop,\n ssrSeen\n );\n }\n }\n}\n\n/**\n * Start the crawl in the background once `server` listens. Middleware mode\n * (no HTTP server of Vite's own) is left alone: the host decides when\n * requests start.\n */\nexport function precompileOnListen(server: ViteDevServer, roots: () => PrecompileRoots): void {\n const { httpServer } = server;\n if (process.env[PRECOMPILE_ENV] === '0' || !httpServer) return;\n let closed = false;\n httpServer.once('close', () => (closed = true));\n httpServer.once('listening', () => {\n const deadline = Date.now() + PRECOMPILE_DEADLINE_MS;\n const shouldStop = () => closed || Date.now() > deadline;\n void precompileServerGraphs(server, roots(), shouldStop).catch(() => {});\n });\n}\n","/**\n * timber's virtual module IDs. A module of its own, with no imports, so any\n * plugin can name an entry without importing `entries.ts`: that module\n * finds `src/` from its own location (`SRC_DIR`), and an import from a\n * plugin the bundler places in another chunk moves it there and breaks the\n * lookup in the published package (TIM-1627).\n */\nexport const VIRTUAL_IDS = {\n rscEntry: 'virtual:timber-rsc-entry',\n ssrEntry: 'virtual:timber-ssr-entry',\n browserEntry: 'virtual:timber-browser-entry',\n config: 'virtual:timber-config',\n instrumentation: 'virtual:timber-instrumentation',\n cacheHandler: 'virtual:timber-cache-handler',\n} as const;\n","/**\n * graph-endpoint — `GET /__timber/graph` (and the `GET /__timber/status`\n * identity probe) on the dev server.\n *\n * The fast path of design/47: when a dev server runs, the env module\n * graphs are already resident and classification is a lookup. Serves\n * the `timber graph` CLI (delegation lands with the fast-path ticket)\n * and the VS Code extension, which additionally needs push updates on\n * HMR — something a CLI cannot provide.\n *\n * Dev-only by construction: registered from the timber-dev-server\n * plugin, which is `apply: 'serve'`; production builds contain none of\n * this. Same JSON contract as the CLI, produced by the same\n * classification module (analyze/live-graph.ts → classify/chains/\n * poison-scan) — never a second implementation.\n *\n * Endpoint hygiene (§10): requests are validated against DNS rebinding\n * consistent with Vite's own dev-endpoint protections — the Host\n * header must be a localhost form or an allowed host (Vite's\n * `server.allowedHosts` semantics, including leading-dot suffix\n * entries), and a present Origin header must pass the same check. A\n * CLI probe sends no Origin and passes; a browser on an attacker's\n * page either fails the Host check (rebinding: Host is the attacker's\n * domain) or the Origin check (direct cross-origin fetch).\n *\n * Push channel: `timber:graph-update` custom HMR events, one per\n * project-source watcher event. The channel just emits — debounce is\n * the consumer's concern (design/47 §\"Dev-server endpoint\").\n *\n * Design docs: 47-module-environment-tooling.md §10, 21-dev-server.md.\n */\n\nimport type { ViteDevServer } from 'vite';\nimport { normalizePath } from 'vite';\nimport type { IncomingMessage, ServerResponse } from 'node:http';\nimport { realpath, stat } from 'node:fs/promises';\nimport { isIP } from 'node:net';\nimport { isAbsolute, join, relative, resolve } from 'node:path';\nimport type { PluginContext } from '../plugin-context.ts';\nimport { buildSourceExtensions, isScannableSourceFile } from '../analyze/scan.ts';\nimport { GRAPH_JSON_VERSION } from '../analyze/graph-cache.ts';\nimport { STATUS_ENDPOINT_PATH } from './dev-discovery.ts';\n\nexport const GRAPH_ENDPOINT_PATH = '/__timber/graph';\n\n/** HMR custom event name for graph-affecting file changes. */\nexport const GRAPH_UPDATE_EVENT = 'timber:graph-update';\n\n/**\n * Host-header allowlist check, ported branch-for-branch from Vite's\n * host-validation middleware (`isHostAllowedWithoutCache`) so this\n * endpoint's reachability matches the rest of the dev server:\n *\n * - `allowedHosts: true` allows everything\n * - a MISSING Host header is allowed (Vite parity — HTTP/1.0 probes)\n * - any IP-literal host is allowed (`vite --host` LAN access sends\n * `Host: 192.168.x.x:port`; rejecting it would 403 this endpoint\n * while every other dev route works)\n * - `localhost` and `*.localhost` are always allowed\n * - allowedHosts entries: exact match, or `.suffix` subdomain entries\n */\nexport function isAllowedGraphHost(\n hostHeader: string | undefined,\n allowedHosts: true | string[] | undefined\n): boolean {\n if (allowedHosts === true) return true;\n if (hostHeader === undefined) return true;\n // Strip the port: `localhost:3000`, `[::1]:3000`, bare `[::1]`.\n let host = hostHeader;\n const bracket = host.match(/^\\[([^\\]]+)\\](?::\\d+)?$/);\n if (bracket) {\n // Bracketed form is only valid for IPv6 literals.\n return isIP(bracket[1]) === 6;\n }\n const colon = host.lastIndexOf(':');\n if (colon !== -1) host = host.slice(0, colon);\n host = host.toLowerCase();\n if (isIP(host) !== 0) return true;\n if (host === 'localhost' || host.endsWith('.localhost')) return true;\n for (const entry of allowedHosts ?? []) {\n const allowed = entry.toLowerCase();\n if (allowed.startsWith('.')) {\n if (host === allowed.slice(1) || host.endsWith(allowed)) return true;\n } else if (host === allowed) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Non-http(s) origins admitted without a host check: Vite's own\n * `file:` / `*-extension:` set (its host-validation regex), plus\n * `vscode-webview:` — VS Code webviews fetch with that Origin, and the\n * extension is this endpoint's primary consumer. Vite itself never\n * origin-checks plain HTTP GETs (only WebSocket upgrades), so this\n * layer is strictly additional; the additions keep it from rejecting\n * consumers Vite would serve.\n *\n * NOT admitted: `Origin: null`. Browsers serialize file:// pages'\n * opaque origin as the literal string `null` — but so do sandboxed\n * iframes and data: documents, exactly the untrusted embedders the\n * check exists to stop, and the header offers nothing to tell them\n * apart. file:// pages therefore cannot use this endpoint from a\n * browser; the `file:` scheme entry covers non-browser clients that\n * send a real scheme-form Origin (Vite admits the same set).\n */\nconst TRUSTED_ORIGIN_SCHEMES = /^(?:file|vscode-webview|.+-extension):/i;\n\n/** Origin check: absent is fine (CLI probe); present must pass the host allowlist. */\nexport function isAllowedGraphOrigin(\n originHeader: string | undefined,\n allowedHosts: true | string[] | undefined\n): boolean {\n if (originHeader === undefined) return true;\n if (TRUSTED_ORIGIN_SCHEMES.test(originHeader)) return true;\n let originUrl: URL;\n try {\n originUrl = new URL(originHeader);\n } catch {\n return false;\n }\n // An http(s) origin has a real host — hold it to the host allowlist,\n // NOT to the missing-Host leniency above (an Origin header is never\n // \"missing\" once present; an empty host must fail).\n if (originUrl.host === '') return false;\n // IP-literal leniency applies to the request's HOST header (LAN dev\n // access), never to Origin: a hostile page at http://203.0.113.10\n // sends that IP as its Origin, and admitting it (plus reflected\n // CORS) would let it read the whole module graph. Only loopback IP\n // origins pass; other IPs need an allowedHosts entry. (A developer\n // browsing the app over LAN fetches same-origin, which sends no\n // Origin header on GET — unaffected.)\n const bareHost = originUrl.hostname.replace(/^\\[|\\]$/g, '');\n if (isIP(bareHost) !== 0) {\n if (bareHost === '127.0.0.1' || bareHost === '::1') return true;\n if (allowedHosts === true) return true;\n return (allowedHosts ?? []).some((entry) => entry.toLowerCase() === bareHost);\n }\n return isAllowedGraphHost(originUrl.host, allowedHosts);\n}\n\nfunction sendJson(res: ServerResponse, status: number, body: unknown): void {\n res.statusCode = status;\n res.setHeader('content-type', 'application/json; charset=utf-8');\n res.end(JSON.stringify(body));\n}\n\n/**\n * Echo an ADMITTED origin back as CORS headers. A webview fetch from\n * `vscode-webview://…` passes the origin check but the browser rejects\n * the response body without `Access-Control-Allow-Origin` — the exact\n * transport design/47 specifies for the extension. Only the validated\n * origin is echoed (never `*`), with `Vary: Origin` for any cache in\n * between; unadmitted origins were already 403'd and get nothing.\n */\nfunction reflectCors(res: ServerResponse, origin: string | undefined): void {\n if (!origin) return;\n res.setHeader('Access-Control-Allow-Origin', origin);\n res.setHeader('Vary', 'Origin');\n}\n\n/**\n * Create the Connect middleware handling GET /__timber/graph and the\n * GET /__timber/status identity probe.\n *\n * Query surface: `?file=<path>` (absolute or project-root-relative) or\n * `?all=1`. Anything else is a 400 — fail loudly, like the CLI.\n */\nexport function createGraphEndpointMiddleware(server: ViteDevServer, ctx: PluginContext) {\n const sourceExtensions = buildSourceExtensions(ctx.config.pageExtensions);\n return async (req: IncomingMessage, res: ServerResponse, next: () => void): Promise<void> => {\n const rawUrl = req.url;\n // Reserve the whole /__timber/ namespace: unknown paths under it\n // must 404 here, not fall through and render the app's 404 page.\n if (!rawUrl || !rawUrl.startsWith('/__timber/')) {\n next();\n return;\n }\n const url = new URL(rawUrl, 'http://placeholder.invalid');\n const isStatus = url.pathname === STATUS_ENDPOINT_PATH;\n if (!isStatus && url.pathname !== GRAPH_ENDPOINT_PATH) {\n sendJson(res, 404, { error: `unknown /__timber/ endpoint: ${url.pathname}` });\n return;\n }\n\n if (req.method !== 'GET') {\n res.setHeader('Allow', 'GET');\n sendJson(res, 405, { error: 'GET only' });\n return;\n }\n\n // Host validation is skipped under server.https, as Vite skips it\n // (TLS cert matching already defeats DNS rebinding). The ORIGIN\n // check is not: it guards cross-site reads, which TLS does nothing\n // about — and since admitted origins get reflected CORS below,\n // skipping it under https would let any page read the endpoint.\n const origin = req.headers.origin as string | undefined;\n const allowedHosts = server.config.server.allowedHosts;\n if (!server.config.server.https && !isAllowedGraphHost(req.headers.host, allowedHosts)) {\n sendJson(res, 403, { error: 'host not allowed' });\n return;\n }\n if (!isAllowedGraphOrigin(origin, allowedHosts)) {\n sendJson(res, 403, { error: 'origin not allowed' });\n return;\n }\n // Past validation: reflect the admitted origin so webview/browser\n // consumers can actually READ the response.\n reflectCors(res, origin);\n\n // Identity probe for `timber dev status` (dev-discovery.ts): the pid\n // lets the CLI confirm this is the server that wrote the record, not\n // a different process that took a crashed server's port.\n if (isStatus) {\n sendJson(res, 200, { pid: process.pid });\n return;\n }\n\n try {\n // Lazy import: the analyze pipeline (oxc parse, chains) loads on\n // first query, not on every dev-server boot.\n const { classifyLiveFile, classifyLiveProject } = await import('../analyze/live-graph.ts');\n // Root must share the graphs' path space: by default Vite\n // resolves through symlinks and nodes carry realpaths, but under\n // resolve.preserveSymlinks the graphs keep the SYMLINK paths and\n // realpathing would break every lookup instead of fixing it —\n // honor the resolved setting (same rule as the crawl).\n const preserveSymlinks = server.config.resolve.preserveSymlinks;\n // Slash-normalized like every other frontend's paths — on\n // Windows a native-separator root beside slash-normalized module\n // paths would break consumers stripping the root prefix.\n const root = normalizePath(preserveSymlinks ? ctx.root : await realpath(ctx.root));\n // appDir must live in the same path space as root and the graph\n // nodes: on a symlinked project ctx.appDir still carries Vite's\n // unresolved prefix — and the appDir itself may be a symlink\n // (src/app -> elsewhere), so realpath the whole thing rather\n // than assuming the relative suffix is symlink-free. Under\n // preserveSymlinks the graphs keep logical paths and ctx.appDir\n // is already in that space.\n const appDir = normalizePath(\n preserveSymlinks\n ? ctx.appDir\n : await realpath(ctx.appDir).catch(() => join(root, relative(ctx.root, ctx.appDir)))\n );\n const liveCtx = {\n rsc: server.environments.rsc.moduleGraph,\n ssr: server.environments.ssr.moduleGraph,\n client: server.environments.client.moduleGraph,\n root,\n appDir,\n pageExtensions: ctx.config.pageExtensions,\n };\n\n const allParam = url.searchParams.get('all');\n if (allParam !== null && allParam !== '1') {\n // Fail loudly: `?all=0`/`?all=false` silently returning the\n // full project would hand API clients the wrong response shape.\n sendJson(res, 400, { error: `unsupported all value: ${allParam} (use ?all=1)` });\n return;\n }\n if (allParam === '1') {\n const report = await classifyLiveProject(liveCtx);\n // `cached: false` always — live answers are never cached, and\n // consumers switching between sources should not lose the\n // field. `stats` stays a static-scan extra (crawl bookkeeping\n // with no live equivalent) — documented in design/47.\n sendJson(res, 200, {\n version: GRAPH_JSON_VERSION,\n source: 'dev-server',\n cached: false,\n ...report,\n });\n return;\n }\n\n const fileParam = url.searchParams.get('file');\n if (!fileParam) {\n sendJson(res, 400, { error: 'missing ?file=<path> (or ?all=1)' });\n return;\n }\n // resolve() in BOTH branches: it collapses `..` segments, and\n // under preserveSymlinks the un-realpathed value is what gets\n // containment-checked — a raw absolute `/root/../outside/x.ts`\n // would pass the prefix check while stat/readFile escape the\n // project.\n // Slash-normalized so every comparison below shares the root's\n // path space (resolve/realpath emit backslashes on Windows).\n const absolute = normalizePath(\n isAbsolute(fileParam) ? resolve(fileParam) : resolve(root, fileParam)\n );\n // Target follows the root's path-space rule. realpath doubles as\n // the existence check in both branches — and the PHYSICAL path is\n // containment-checked even under preserveSymlinks: a symlink\n // inside the project pointing outside it would otherwise pass the\n // lexical prefix check while readFile followed it out of the\n // project. (Symlinks resolving within the project still work.)\n let target: string;\n try {\n const physical = normalizePath(await realpath(absolute));\n const rootPhysical = preserveSymlinks ? normalizePath(await realpath(root)) : root;\n if (\n physical !== rootPhysical &&\n !physical.startsWith(rootPhysical + '/') &&\n !physical.startsWith(rootPhysical + '\\\\')\n ) {\n sendJson(res, 404, { error: `not a project file under ${root}` });\n return;\n }\n if (preserveSymlinks) {\n // Segment-safe symlink check: the disk scan neither follows\n // file symlinks nor descends directory symlinks, so a path\n // reached through EITHER (link.ts, or link/a.ts via\n // link -> src) would 200 here while the ?all sweep omits it.\n // Symlinks ABOVE the root are fine (reaching the project via\n // one is the preserveSymlinks use case) — require only that\n // the path RELATIVE to the root is symlink-free, i.e. the\n // physical path equals the physical root plus that suffix.\n const suffix = absolute.slice(root.length);\n const expected = rootPhysical + suffix;\n if (physical !== expected) {\n sendJson(res, 404, { error: `not a project source file: ${absolute}` });\n return;\n }\n }\n target = normalizePath(preserveSymlinks ? absolute : physical);\n } catch {\n sendJson(res, 404, { error: `file not found: ${absolute}` });\n return;\n }\n if (target !== root && !target.startsWith(root + '/') && !target.startsWith(root + '\\\\')) {\n sendJson(res, 404, { error: `not a project file under ${root}` });\n return;\n }\n // Same admission rules as the CLI's scan (design/47: project\n // source files only) via the shared helper — without it, any\n // real path under the root (package.json, dist/generated.js,\n // types.d.ts, a nested node_modules file, a DIRECTORY named\n // foo.ts) would get a synthetic classification the static scan\n // would refuse, and the frontends would disagree.\n const targetStat = await stat(target).catch(() => null);\n if (\n !targetStat?.isFile() ||\n !isScannableSourceFile(normalizePath(target), normalizePath(root), sourceExtensions)\n ) {\n sendJson(res, 404, { error: `not a project source file: ${target}` });\n return;\n }\n const errors: import('../analyze/live-graph.ts').LiveGraphError[] = [];\n const module = await classifyLiveFile(target, liveCtx, undefined, errors);\n // Explicit field list, mirroring the CLI's single-file output —\n // a spread would leak `file` (redundant with target.resolved) and\n // silently drift the two frontends' key sets. `stats` is a\n // static-scan extra and deliberately absent here.\n sendJson(res, 200, {\n version: GRAPH_JSON_VERSION,\n source: 'dev-server',\n cached: false,\n target: { input: fileParam, resolved: target },\n kind: module.kind,\n pending: module.pending,\n subtreeUnknown: module.subtreeUnknown,\n envs: module.envs,\n boundary: module.boundary,\n chains: module.chains,\n poisonings: module.poisonings,\n errors,\n });\n } catch (error) {\n sendJson(res, 500, {\n error: error instanceof Error ? error.message : String(error),\n });\n }\n };\n}\n\n/** What one hotUpdate invocation tells the emitter. */\nexport interface GraphHotUpdate {\n file: string;\n /** Vite's own hotUpdate vocabulary. */\n type: 'create' | 'update' | 'delete';\n /** Environment the hook ran for (rsc/ssr/client). */\n environment: string;\n}\n\n/** The push channel's two notification points for one edit. */\nexport interface GraphUpdateChannel {\n /** Feed from the plugin's hotUpdate hook (post graph invalidation). */\n onHotUpdate(update: GraphHotUpdate): void;\n /**\n * Feed from the plugin's transform hook (module id, may carry a\n * query suffix). Emits phase \"transformed\" for files with a pending\n * invalidation, once their import edges are actually rebuilt.\n */\n onTransform(id: string, environment: string): void;\n}\n\n/**\n * Accessor the channel uses to decide when a re-transforming module's\n * graph data is current: Vite stores the node's `transformResult` only\n * at the END of the transform request — after `vite:import-analysis`\n * has rebuilt the importer edges — so a non-null result is the\n * edges-are-current signal.\n */\nexport type IsNodeTransformed = (file: string, environment: string) => boolean;\n\n/**\n * Build the push channel: `timber:graph-update` custom HMR events per\n * project-source change. Consumers (the VS Code extension) re-query\n * and debounce on their side; the channel just emits. Non-source noise\n * (build output, dotdirs) is filtered by the same extension set the\n * scanners use.\n *\n * Two phases per edit, because one is not enough (codex review, PR\n * #1057): the `invalidated` event fires from the plugin's `hotUpdate`\n * hook — after Vite clears the module's transform result, but its\n * importer EDGES are only rebuilt when the module is next transformed.\n * The `transformed` event fires for exactly the files with a pending\n * invalidation, and only once the node's `transformResult` is set\n * again — the plugin transform hook itself runs BEFORE Vite's trailing\n * `vite:import-analysis` (which rebuilds the edges), so the hook only\n * marks the file \"settling\" and a short bounded timer confirms\n * completion via `isTransformed` before emitting. (A module nothing\n * re-requests never re-transforms — its `transformed` event waits for\n * the next render, which is also when the graph has new information.)\n */\nexport function makeGraphUpdateChannel(\n ctx: Pick<PluginContext, 'root' | 'config'>,\n send: (payload: { type: 'custom'; event: string; data: unknown }) => void,\n isTransformed?: IsNodeTransformed,\n // Maps a watcher/hook path into the module graphs' path space (the\n // dev-server passes a preserveSymlinks-aware realpath). Watcher\n // events can carry the symlink path while transform ids carry the\n // physical one — unkeyed by a common canonical form, the pending\n // entry would never match its own transform.\n canonicalize: (file: string) => string = (file) => file\n): GraphUpdateChannel {\n /** Files invalidated but not yet re-transformed, per environment. */\n const pending = new Set<string>();\n const key = (file: string, environment: string) => `${environment}\\0${file}`;\n // The root goes through the same canonicalization as the files it\n // contains — containment checks must compare in one path space.\n const root = normalizePath(canonicalize(ctx.root));\n const extensions = buildSourceExtensions(ctx.config.pageExtensions);\n\n const emitTransformed = (file: string, environment: string, structural?: boolean) => {\n send({\n type: 'custom',\n event: GRAPH_UPDATE_EVENT,\n data: structural\n ? { file, event: 'update', environment, phase: 'transformed', structural: true }\n : { file, event: 'update', environment, phase: 'transformed' },\n });\n };\n\n /**\n * Confirm the transform request finished (transformResult set again)\n * before emitting phase `transformed`. If confirmation never arrives\n * within the bounded schedule below, the pending key is RE-ARMED\n * rather than emitted — a `transformed` event over a still-stale\n * graph would be a false all-clear with no corrective event.\n */\n /**\n * Delays between confirmation re-checks: dense while a normal\n * transform request finishes, then exponential backoff for slow\n * import-analysis passes (large graphs, cold dep optimizer) — a\n * completed slow transform is CACHED, so no later transform hook may\n * ever fire for it and the tail checks are the only chance to emit.\n * Total window ≈ 16 s, then give up (bounded — the async-safety\n * rules ban open-ended polling) and re-arm the pending key.\n */\n const CONFIRM_DELAYS_MS = [\n ...Array.from({ length: 25 }, () => 20),\n 500,\n 1_000,\n 2_000,\n 4_000,\n 8_000,\n ];\n\n const confirmAndEmit = (file: string, environment: string, attempt = 0, structural = false) => {\n if (!isTransformed || isTransformed(file, environment)) {\n emitTransformed(file, environment, structural);\n return;\n }\n if (attempt >= CONFIRM_DELAYS_MS.length) {\n // Structural (virtual-id) updates have no pending-key cycle to\n // re-arm; project files wait for their next transform.\n if (!structural) pending.add(key(file, environment));\n return;\n }\n setTimeout(\n () => confirmAndEmit(file, environment, attempt + 1, structural),\n CONFIRM_DELAYS_MS[attempt]\n );\n };\n\n return {\n onHotUpdate(update) {\n // The scanner's FULL admission rules, not just the extension —\n // otherwise the channel pushes updates for files the endpoint\n // itself 404s (node_modules, dist, .d.ts, dot-dirs) and editor\n // consumers refresh into dead ends. Deletes canonicalize too:\n // the dev-server's canonicalizer falls back to resolving the\n // parent directory when the file itself is gone.\n const file = normalizePath(canonicalize(update.file));\n if (!isScannableSourceFile(file, root, extensions)) return;\n if (update.type === 'delete') {\n // Deleted files never re-transform; no second phase to track.\n pending.delete(key(file, update.environment));\n } else {\n pending.add(key(file, update.environment));\n }\n send({\n type: 'custom',\n event: GRAPH_UPDATE_EVENT,\n data: {\n file,\n event: update.type,\n environment: update.environment,\n phase: 'invalidated',\n },\n });\n },\n onTransform(id, environment) {\n const file = normalizePath(id.split('?')[0]);\n // Structural change: the route manifest re-transforms when routes\n // are added/removed (its dynamic-import edges are what connect\n // new route files to the graph). The new FILE itself may not\n // transform until visited, so per-file tracking cannot see this —\n // emit a structural notification, through the same confirmation\n // gate (the manifest's own edges are also rebuilt only by the\n // trailing import-analysis; the accessor resolves virtual ids).\n if (file.includes('virtual:timber-route-manifest')) {\n confirmAndEmit(file, environment, 25, true);\n return;\n }\n const pendingKey = key(file, environment);\n if (!pending.has(pendingKey)) return;\n pending.delete(pendingKey);\n confirmAndEmit(file, environment);\n },\n };\n}\n","// Response compression for self-hosted deployments (dev server, Nitro preview).\n//\n// Gzips with node:zlib, flushing per chunk; a Node body stays a Node stream. Brotli is intentionally\n// left to CDNs and reverse proxies — at streaming-friendly quality levels its\n// ratio advantage is marginal, and node:zlib's brotli transform buffers output\n// internally, breaking streaming. Cloudflare Workers auto-compress at the edge —\n// this module is only used on Node.js/Bun.\n//\n// See design/25-production-deployments.md.\n//\n// This module is also emitted standalone as `_compress.mjs` by\n// `adapters/compress-module.ts`, which strips types but does not bundle. Its\n// imports must therefore be interpolated there — a new import that is not\n// fails the build with an explanatory error rather than resolving to nothing\n// on the deployed server.\n\nimport { RSC_CONTENT_TYPE } from '../shared/rsc-media-type.ts';\n\n// ─── Constants ────────────────────────────────────────────────────────────\n\n/**\n * MIME types that benefit from compression.\n * text/* is handled via prefix matching; these are the specific\n * application/* and image/* types that are compressible.\n */\nexport const COMPRESSIBLE_TYPES = new Set([\n 'text/html',\n 'text/css',\n 'text/plain',\n 'text/xml',\n 'text/javascript',\n RSC_CONTENT_TYPE,\n 'application/json',\n 'application/javascript',\n 'application/xml',\n 'application/xhtml+xml',\n 'application/rss+xml',\n 'application/atom+xml',\n 'image/svg+xml',\n]);\n\n/**\n * Status codes that should never be compressed (no body or special semantics).\n */\nconst NO_COMPRESS_STATUSES = new Set([204, 304]);\n\n// ─── Encoding Negotiation ─────────────────────────────────────────────────\n\n/**\n * Parse Accept-Encoding and return the best supported encoding.\n * Returns 'gzip' if the client accepts it, null otherwise.\n *\n * Brotli (br) is intentionally not handled at the application level.\n * At the streaming-friendly quality levels (0–4), brotli's compression\n * ratio advantage over gzip is marginal, and node:zlib's brotli transform\n * buffers output internally — turning smooth streaming responses into\n * large infrequent bursts. Brotli's real wins come from offline/static\n * compression at higher quality levels (5–11), which CDNs and reverse\n * proxies (Cloudflare, nginx, Caddy) apply on cached responses.\n *\n * See design/25-production-deployments.md.\n */\nexport function negotiateEncoding(acceptEncoding: string): 'gzip' | null {\n if (!acceptEncoding) return null;\n\n // Parse tokens with quality values from the Accept-Encoding header.\n // Per RFC 9110 §12.5.3, q=0 means \"not acceptable\" — the client explicitly\n // rejects that encoding. Tokens without a q-value default to q=1.\n // e.g. \"gzip;q=1.0, br;q=0\" → gzip is acceptable, br is rejected.\n const parts = acceptEncoding.split(',');\n for (const part of parts) {\n const [token, ...params] = part.split(';');\n const name = token.trim().toLowerCase();\n if (name !== 'gzip') continue;\n\n // Check for q=0 (explicitly disabled)\n let qValue = 1; // default quality is 1\n for (const param of params) {\n const trimmed = param.trim().toLowerCase();\n if (trimmed.startsWith('q=')) {\n qValue = parseFloat(trimmed.slice(2));\n if (Number.isNaN(qValue)) qValue = 1;\n break;\n }\n }\n\n if (qValue > 0) return 'gzip';\n }\n\n return null;\n}\n\n// ─── Compressibility Check ────────────────────────────────────────────────\n\n/**\n * Determine if a response should be compressed.\n *\n * Returns false for:\n * - Responses without a body (204, 304, null body)\n * - Already-encoded responses (Content-Encoding set)\n * - Non-compressible content types (images, binary)\n * - SSE streams (text/event-stream — must not be buffered)\n */\nexport function shouldCompress(response: Response): boolean {\n // No body to compress. A Node-body response is asked whether it owns one\n // (a null-body status does not) without reading `.body`, which would\n // convert it to a Web stream.\n const nodeBody = nodeBodyThrough(response);\n if (nodeBody ? !nodeBody.hasBody : !response.body) return false;\n if (NO_COMPRESS_STATUSES.has(response.status)) return false;\n\n // Already compressed\n if (response.headers.has('Content-Encoding')) return false;\n\n // Check content type\n const contentType = response.headers.get('Content-Type');\n if (!contentType) return false;\n\n // Extract the MIME type (strip charset and other parameters)\n const mimeType = contentType.split(';')[0].trim().toLowerCase();\n\n // SSE must not be compressed — it relies on chunk-by-chunk delivery\n if (mimeType === 'text/event-stream') return false;\n\n return COMPRESSIBLE_TYPES.has(mimeType);\n}\n\n// ─── Compression ──────────────────────────────────────────────────────────\n\n/**\n * Compress a Web Response if the client supports it and the content is compressible.\n *\n * Returns the original response unchanged if compression is not applicable.\n * Returns a new Response with the compressed body, Content-Encoding, and Vary headers.\n *\n * The body is piped through a compression stream — no buffering of the full response.\n * This preserves streaming behavior for HTML shell + deferred Suspense chunks.\n */\nexport function compressResponse(request: Request, response: Response): Response {\n // Check if response is compressible\n if (!shouldCompress(response)) return response;\n\n // Negotiate encoding with the client\n const acceptEncoding = request.headers.get('Accept-Encoding') ?? '';\n const encoding = negotiateEncoding(acceptEncoding);\n if (!encoding) return response;\n\n // Build new headers: copy originals, add compression headers, remove Content-Length\n // (compressed size is unknown until streaming completes).\n const headers = new Headers(response.headers);\n headers.set('Content-Encoding', encoding);\n headers.delete('Content-Length');\n\n // Append to Vary header (preserve existing Vary values)\n const existingVary = headers.get('Vary');\n if (existingVary) {\n if (!existingVary.toLowerCase().includes('accept-encoding')) {\n headers.set('Vary', `${existingVary}, Accept-Encoding`);\n }\n } else {\n headers.set('Vary', 'Accept-Encoding');\n }\n\n const init = { status: response.status, statusText: response.statusText, headers };\n // A Node body is gzipped as a Node stream and stays one to the socket.\n const nodeBody = nodeBodyThrough(response);\n if (nodeBody) return nodeBody.through(createSyncFlushGzip(), init);\n return new Response(compressWithGzip(response.body!), init);\n}\n\n// ─── Node bodies ──────────────────────────────────────────────────────────\n//\n// A response with a Node body (SSR and Flight payloads on Node) carries its\n// operations under a registry symbol (server/node-response.ts). This module is\n// emitted standalone and cannot import that one, so it repeats the key;\n// tests/node-body-response.test.ts holds the two to the same string.\n\n/** Registry key of the Node-body brand; must equal `NODE_BODY` in node-response.ts. */\nexport const NODE_BODY_KEY = 'timber.response.nodeBody';\n\n/** The Node-body operations compression needs. */\ninterface NodeBodyThrough {\n readonly hasBody: boolean;\n through(stream: import('node:stream').Duplex, init: ResponseInit): Response;\n}\n\nfunction isNodeBodyThrough(value: unknown): value is NodeBodyThrough {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'through' in value &&\n typeof value.through === 'function' &&\n 'hasBody' in value &&\n typeof value.hasBody === 'boolean'\n );\n}\n\nfunction nodeBodyThrough(response: Response): NodeBodyThrough | null {\n const ops: unknown = Reflect.get(response, Symbol.for(NODE_BODY_KEY));\n return isNodeBodyThrough(ops) ? ops : null;\n}\n\n// ─── Gzip (node:zlib with Z_SYNC_FLUSH) ──────────────────────────────────\n//\n// Uses node:zlib's createGzip with Z_SYNC_FLUSH so each chunk is flushed\n// to the output immediately. The Web Platform CompressionStream API buffers\n// internally and does NOT flush per-chunk — this kills streaming because\n// the browser doesn't receive the HTML shell until the gzip stream closes\n// (i.e. after all Suspense boundaries resolve).\n//\n// Z_SYNC_FLUSH adds ~2–5% size overhead vs Z_NO_FLUSH but preserves\n// correct streaming behavior: the shell renders instantly, Suspense\n// fallbacks are visible immediately, and streamed content appears\n// progressively.\n\nimport { createGzip, constants } from 'node:zlib';\nimport { Readable, pipeline } from 'node:stream';\n\n/** gzip that flushes every chunk as it arrives. */\nfunction createSyncFlushGzip(): ReturnType<typeof createGzip> {\n return createGzip({ flush: constants.Z_SYNC_FLUSH });\n}\n\n/**\n * Compress a ReadableStream with gzip, flushing each chunk immediately.\n *\n * Uses node:zlib's createGzip with Z_SYNC_FLUSH to ensure each HTML chunk\n * (shell, Suspense resolution, RSC payload) is delivered to the browser\n * as soon as it's available — preserving streaming semantics.\n */\nfunction compressWithGzip(body: ReadableStream<Uint8Array>): ReadableStream<Uint8Array> {\n const gzip = createSyncFlushGzip();\n const nodeInput = Readable.fromWeb(body as import('stream/web').ReadableStream);\n\n // pipeline() instead of bare pipe(): pipe() does not forward source errors,\n // so an erroring body (streaming route handler, dropped upstream fetch)\n // would emit an unhandled 'error' event and crash the process. pipeline()\n // destroys gzip on source error — the returned web stream rejects — and\n // tears down nodeInput when the consumer cancels the web stream, which\n // cancels the source body via fromWeb. The error reaches the consumer\n // through the web stream; the callback only marks it handled at the Node\n // layer.\n pipeline(nodeInput, gzip, () => {});\n\n return Readable.toWeb(gzip) as ReadableStream<Uint8Array>;\n}\n","/**\n * Clear the cache.component dev store on every dev-server watcher event\n * (TIM-1588, server/prebuilt/dev-store.ts) — and once more shortly after.\n *\n * A clear is scoped when the RSC module graph can say what a save changed\n * (TIM-1599). A `change` to a file the graph knows as a module can only have\n * changed the output of the modules that import it, transitively, so only\n * the components declared in those modules (and in the file itself) are\n * dropped. Element props need no tracking: non-slot element props make a\n * render unkeyable, and slot content is composed live (design/45 §Cache Key,\n * §Slot Components). Nested cache.component children are baked flat into\n * their parent, whose module imports them, so the walk reaches the parent.\n *\n * The graph also holds file-only entries: files a plugin declared with\n * `addWatchFile`. Tailwind's plugin declares every file its scanner finds,\n * markdown and JSON included, as a dependency of the stylesheet. A file-only\n * entry says what watches the file, never what reads it with fs, so a file\n * with no module node clears everything. When the walk meets one on its way\n * up (a module Tailwind also scans), it goes through it to the stylesheet's\n * importers, which costs extra re-renders of components declared up that\n * chain and never a stale one.\n *\n * Everything else clears every component: a file the graph does not know as\n * a module (markdown or JSON read with fs), and an add or a delete (a glob\n * or a route scan may pick it up). The decision is graph membership, never\n * the file's extension. Not covered: a module loaded by a variable dynamic\n * `import()` that Vite cannot analyze has no importer edge, and a component\n * that reads a project module with fs is not that module's importer. A hard\n * reload covers both.\n *\n * Vite's watcher (chokidar) throttles `change`: once it emits one for a\n * path, it DROPS every further `change` for that path for 50ms, and never\n * emits a trailing event for them. So a save is invisible when it lands\n * inside that window, which is easy to hit: save a file, the next request\n * renders and stores it in a few milliseconds, save again (an editor that\n * writes twice, a script that rewrites a file the page reads with fs).\n * The store keeps the first save's render until some later, unrelated\n * save. Before the store, a dropped event cost nothing: a file read with\n * fs was read again on every request.\n *\n * The trailing clear lands after that window closes, so it follows any\n * write whose event was dropped. A dropped event is always for a path the\n * burst already reported, so the trailing clear covers every path seen in\n * the burst, and resolves them against the graph again when it fires: a\n * request between the saves may have re-transformed a module and given its\n * call sites new IDs. A render of a covered component that started before\n * it cannot store (the clear records an invalidation of it), and a render\n * after it reads the file as written. Debounced, so a burst of saves gets\n * one trailing clear, after the last of them. The cost is at most one\n * extra re-render per save, in dev only.\n */\n\n/** chokidar's per-path `change` throttle (`_throttle(EV_CHANGE, path, 50)`). */\nconst WATCHER_CHANGE_THROTTLE_MS = 50;\n\n/**\n * Comfortably past the throttle window. Both are timers started in the same\n * synchronous emit, so this one always fires after the throttle has expired,\n * however late the event loop runs them.\n */\nconst TRAILING_CLEAR_DELAY_MS = WATCHER_CHANGE_THROTTLE_MS * 2;\n\n/** The part of Vite's `FSWatcher` this needs. */\ninterface WatcherEvents {\n on(event: 'all', listener: (event: string, path: string) => void): unknown;\n}\n\n/**\n * What a clear covers: the paths changed in place, or null for anything\n * else (an add, a delete, a directory event), which clears everything.\n */\nexport type ChangedPaths = ReadonlySet<string> | null;\n\nexport function clearDevStoreOnWatcherEvents(\n watcher: WatcherEvents,\n clear: (changed: ChangedPaths) => void\n): void {\n let trailing: ReturnType<typeof setTimeout> | undefined;\n // Every path the burst reported, or null once anything cleared everything.\n let burst: Set<string> | null = new Set();\n watcher.on('all', (event, path) => {\n const changed = event === 'change' ? new Set([path]) : null;\n clear(changed);\n if (changed === null) burst = null;\n else burst?.add(path);\n clearTimeout(trailing);\n trailing = setTimeout(() => {\n const covered = burst;\n burst = new Set();\n clear(covered);\n }, TRAILING_CLEAR_DELAY_MS);\n // Never the reason the dev process stays alive.\n trailing.unref?.();\n });\n}\n\n/** The part of Vite's `EnvironmentModuleNode` the walk reads. */\nexport interface GraphModule {\n /** Null for a file-only entry (`addWatchFile`), which declares nothing. */\n id: string | null;\n importers: Set<GraphModule>;\n}\n\n/** The part of Vite's `EnvironmentModuleGraph` the walk reads. */\nexport interface ModuleGraphView {\n getModulesByFile(file: string): Set<GraphModule> | undefined;\n}\n\n/**\n * The cache.component IDs whose output the changed paths could have\n * changed: those declared in each changed module and its transitive\n * importers. Null means every component — a path the graph does not know.\n *\n * `componentIds` maps a module ID to the IDs its last transform declared\n * (`PluginContext.devPrebuiltComponentIds`). `toGraphPath` puts a watcher\n * path in the graph's path space (symlinks resolved, `/` separators).\n */\nexport function componentsChangedBy(\n changed: ChangedPaths,\n graph: ModuleGraphView,\n componentIds: ReadonlyMap<string, readonly string[]>,\n toGraphPath: (path: string) => string\n): string[] | null {\n if (changed === null) return null;\n const affected = new Set<string>();\n const visited = new Set<GraphModule>();\n const pending: GraphModule[] = [];\n for (const path of changed) {\n const nodes = [...(graph.getModulesByFile(toGraphPath(path)) ?? [])];\n // Known as a module, or not at all: a file that only a plugin watches\n // may also be read with fs, by any component.\n if (!nodes.some((node) => node.id !== null)) return null;\n pending.push(...nodes);\n }\n while (pending.length > 0) {\n const module = pending.pop()!;\n if (visited.has(module)) continue;\n visited.add(module);\n if (module.id !== null) {\n for (const id of componentIds.get(module.id) ?? []) affected.add(id);\n }\n pending.push(...module.importers);\n }\n return [...affected];\n}\n","/**\n * timber-dev-server — Vite sub-plugin for dev server request handling.\n *\n * Registers a configureServer middleware that intercepts requests and\n * routes them through the timber pipeline:\n * proxy.ts → canonicalize → route match → middleware → access → render → flush\n *\n * The RSC entry module is loaded via Vite's ssrLoadModule, which uses\n * Vite's dev module graph instead of built bundles. The full pipeline\n * (including proxy.ts) runs on every request.\n *\n * Design docs: 18-build-system.md §\"Dev Server\", 02-rendering-pipeline.md\n */\n\nimport {\n loadConfigFromFile,\n normalizePath,\n type Plugin,\n type ViteDevServer,\n type DevEnvironment,\n} from 'vite';\nimport type { IncomingMessage, ServerResponse } from 'node:http';\nimport type { TLSSocket } from 'node:tls';\nimport { existsSync, realpathSync, statSync } from 'node:fs';\nimport { basename, dirname, join } from 'node:path';\nimport { sendNodeResponse } from 'srvx/node';\nimport type { PluginContext } from '../plugin-context.ts';\nimport {\n sendErrorToOverlay,\n classifyErrorPhase,\n parseFirstAppFrame,\n type ErrorPhase,\n} from '../dev-tools/overlay.ts';\nimport { generateDevErrorPage } from '../dev-tools/error-page.ts';\nimport {\n extractHmrOptions,\n type DevErrorHmrOptions,\n type DevHooks,\n} from '../dev-tools/dev-page-shell.ts';\nimport { addVirtualModuleContext } from '../config-validation.ts';\nimport { devRecordRoot, registerDevDiscovery } from './dev-discovery.ts';\nimport { fileUrl, precompileOnListen, routeTreeSeeds } from './dev-precompile.ts';\nimport { VIRTUAL_IDS } from './virtual-ids.ts';\nimport { advertisedUrls, applyDevHostname } from './dev-hostname.ts';\nimport {\n createGraphEndpointMiddleware,\n makeGraphUpdateChannel,\n type GraphUpdateChannel,\n} from './graph-endpoint.ts';\nimport { compressResponse } from '../server/compress.ts';\nimport { isMetadataRouteServePath } from '../server/metadata-routes.ts';\nimport { canonicalize, requestTargetUrl } from '../server/canonicalize.ts';\nimport { PREBUILT_DEV_CLEAR_EVENT, type DevStoreClear } from '../server/prebuilt/dev-store.ts';\nimport { clearDevStoreOnWatcherEvents, componentsChangedBy } from './dev-store-clear.ts';\nimport { matchUrlParts } from '../server/tree-match.ts';\nimport type { RouteTree } from '../routing/types.ts';\n\n// ─── Constants ────────────────────────────────────────────────────────────\n\n/**\n * Exit code used to signal the CLI supervisor that the dev server needs\n * a full process restart (e.g. timber.config.ts changed). The supervisor\n * in cli.ts respawns the worker on this code. 75 = EX_TEMPFAIL (sysexits).\n * See TIM-1444.\n */\nexport const RESTART_EXIT_CODE = 75;\n\n/**\n * Config file names that trigger a full dev server restart when changed.\n * See 21-dev-server.md §HMR Wiring — config is loaded once at startup.\n */\nconst CONFIG_FILE_NAMES = ['timber.config.ts', 'timber.config.js', 'timber.config.mjs'];\n\n/**\n * URL prefixes that are Vite-internal and should never be intercepted.\n * These are passed through to Vite's built-in middleware.\n */\nconst VITE_INTERNAL_PREFIXES = [\n '/@', // /@vite/client, /@fs/, /@id/\n '/__vite', // /__vite_hmr, /__vite_ping\n '/node_modules/',\n];\n\n/**\n * File extensions that indicate static asset requests.\n * These are passed through to Vite's static file serving.\n */\nconst ASSET_EXTENSIONS =\n /\\.(?:js|ts|tsx|jsx|css|map|json|svg|png|jpg|jpeg|gif|webp|avif|ico|woff|woff2|ttf|eot|mp4|webm|ogg|mp3|wav)(?:\\?.*)?$/;\n\n// ─── Plugin ───────────────────────────────────────────────────────────────\n\n/**\n * Create the timber-dev-server Vite plugin.\n *\n * Hook: configureServer (returns post-hook to register after Vite's middleware)\n */\nexport function timberDevServer(ctx: PluginContext): Plugin {\n // Set in configureServer, consumed by hotUpdate/transform — the\n // graph push channel emits through the server's HMR transport.\n let graphChannel: GraphUpdateChannel | null = null;\n\n return {\n name: 'timber-dev-server',\n\n // Only active in dev mode (command === 'serve'), not during build.\n // See 21-dev-server.md §Plugin Registration.\n apply: 'serve',\n\n /**\n * Push channel for the graph endpoint, phase 1: `invalidated`, one\n * per (file, environment). Emitted from hotUpdate — which runs\n * AFTER Vite invalidates the environment module graphs — never\n * from a raw watcher listener, which would race consumers into\n * querying pre-invalidation memberships (design/47 §\"Dev-server\n * endpoint\").\n */\n hotUpdate({ file, type }) {\n graphChannel?.onHotUpdate({ file, type, environment: this.environment.name });\n },\n\n /**\n * Push channel phase 2: `transformed`, when a pending-invalidated\n * module's import edges are actually rebuilt. A Set lookup for\n * everything without a pending invalidation — free on the hot\n * path. Returning nothing leaves the code untouched.\n */\n transform(_code, id) {\n graphChannel?.onTransform(id, this.environment.name);\n },\n\n /**\n * Register the dev server middleware and config file watcher.\n *\n * Registers as a pre-hook (no return value) so our middleware runs\n * before Vite's built-in SPA fallback / historyApiFallback. This\n * ensures we see the original URL (e.g. /blog) rather than a\n * rewritten /index.html. Vite-internal and asset requests are\n * filtered out explicitly and passed through to Vite.\n */\n async configureServer(server: ViteDevServer) {\n // Watch config files for changes. When running under the CLI\n // supervisor (__TIMBER_DEV_WORKER), exit the process so the\n // supervisor respawns with a fresh require cache. Under `vite dev`\n // directly (no supervisor) only say so: an in-process\n // server.restart() would serve the stale config anyway (TIM-1444),\n // and each one leaks the whole previous server — its environments,\n // module runners, and React's dev Flight server stay reachable — so a\n // few config saves ran the dev server out of heap (TIM-1589).\n const configPaths = CONFIG_FILE_NAMES.map((name) => join(ctx.root, name));\n server.watcher.add(configPaths);\n const configPathSet = new Set(configPaths);\n const hasSupervisor = Boolean(process.env.__TIMBER_DEV_WORKER);\n const onConfigChange = (filePath: string) => {\n if (!configPathSet.has(filePath)) return;\n if (hasSupervisor) {\n console.log(`\\n[timber] ${basename(filePath)} changed — restarting dev server...\\n`);\n process.exit(RESTART_EXIT_CODE);\n } else {\n console.warn(\n `\\n[timber] ${basename(filePath)} changed. Restart the dev server to apply it,` +\n ` or run \\`timber dev\\` instead of \\`vite dev\\` to restart automatically.\\n`\n );\n }\n };\n server.watcher.on('change', onConfigChange);\n server.watcher.on('add', onConfigChange);\n server.watcher.on('unlink', onConfigChange);\n\n // Vite's own restarts (vite.config.ts or one of its dependencies, a\n // .env file) go through server.restart(), which\n // builds a new server in this process and leaks the old one through\n // rolldown's native resolver (rolldown#10887). Under the supervisor,\n // restart the process instead, as timber.config.ts changes do\n // (TIM-1590). The new config is loaded here first: a vite.config.ts\n // that fails to evaluate would fail the new worker's startup, and the\n // supervisor respawns only on RESTART_EXIT_CODE, so exiting would take\n // the dev server down. Vite's own restart keeps the old server then.\n if (hasSupervisor) {\n server.restart = async () => {\n const { configFile, mode, root, logger } = server.config;\n try {\n await loadConfigFromFile(\n { command: 'serve', mode },\n configFile || undefined,\n root,\n 'silent'\n );\n } catch (error) {\n logger.error(\n `[timber] ${configFile ? basename(configFile) : 'Vite config'} failed to load — ` +\n `keeping the running server.\\n${error instanceof Error ? error.message : String(error)}`,\n { timestamp: true }\n );\n return;\n }\n console.log('\\n[timber] Restarting the dev server process...\\n');\n process.exit(RESTART_EXIT_CODE);\n };\n }\n\n // Listen for client-side errors forwarded from the browser.\n // The browser entry sends 'timber:client-error' events via HMR\n // for uncaught errors and unhandled rejections. We echo them back\n // as Vite's '{ type: \"error\" }' payload to trigger the overlay.\n listenForClientErrors(server, ctx.root);\n\n // Before any of Vite's middlewares: an absolute-form or asterisk-form\n // target becomes the origin-form path the pipeline will see, so Vite's\n // transform/static middlewares and the checks in the timber\n // middleware agree with it — `GET http://host/@vite/client` is Vite's,\n // not a 404 from the app (TIM-1600). A target that names no URL is\n // left for toWebRequest to answer with 400.\n server.middlewares.use((req, _res, next) => {\n if (req.url && !req.url.startsWith('/')) {\n const url = requestTargetUrl('http://localhost', req.url);\n if (url) req.url = url.pathname + url.search;\n }\n next();\n });\n\n // GET /__timber/graph — module-environment classification from the\n // live env graphs, plus the timber:graph-update HMR push channel.\n // Registered before the timber middleware so /__timber/* requests\n // never reach the app pipeline. Dev-only by construction (this\n // plugin is apply: 'serve'). See design/47 §\"Dev-server endpoint\".\n server.middlewares.use(createGraphEndpointMiddleware(server, ctx));\n\n // Canonicalize watcher/hook paths into the module graphs' path\n // space: under the default preserveSymlinks:false the graphs\n // carry realpaths while watcher events can carry symlink paths\n // — unkeyed by one canonical form, a pending entry would never\n // match its own transform. Deleted files realpath their parent\n // directory instead; virtual ids pass through untouched.\n const toGraphPath = (file: string): string => {\n // Optional-chained: mock servers in unit tests carry a bare\n // config object without resolve options.\n if (server.config?.resolve?.preserveSymlinks || file.includes('virtual:')) return file;\n try {\n return realpathSync(file);\n } catch {\n try {\n return join(realpathSync(dirname(file)), basename(file));\n } catch {\n return file;\n }\n }\n };\n\n // Every watcher event clears the RSC environment's cache.component dev\n // store (TIM-1588) — source files, and files outside the module graph\n // that a component reads with fs. A save of a module clears only the\n // components it could have changed (TIM-1599). A raw listener, not\n // hotUpdate: it runs in the same synchronous dispatch as every other\n // watcher listener (timber-routing's reloads included), before Vite's\n // own handling sends any HMR update. A browser that a reload or update\n // makes refetch can only reach the server after the clear has gone\n // out. A trailing clear covers the saves the watcher drops\n // (dev-store-clear.ts).\n const rsc = server.environments.rsc;\n clearDevStoreOnWatcherEvents(server.watcher, (changed) => {\n if (!rsc) return;\n const componentIds = componentsChangedBy(\n changed,\n rsc.moduleGraph,\n ctx.devPrebuiltComponentIds ?? new Map(),\n (path) => normalizePath(toGraphPath(path))\n );\n const data: DevStoreClear = componentIds === null ? {} : { componentIds };\n rsc.hot.send({ type: 'custom', event: PREBUILT_DEV_CLEAR_EVENT, data });\n });\n graphChannel = makeGraphUpdateChannel(\n ctx,\n (payload) => server.hot.send(payload),\n // \"Edges rebuilt\" signal: Vite sets a node's transformResult at\n // the END of the transform request, after vite:import-analysis\n // has updated the importer edges. Virtual ids (the route\n // manifest's structural updates) have no file index — resolve\n // them by id.\n (file, environment) => {\n const graph = server.environments[environment]?.moduleGraph;\n if (!graph) return false;\n const nodes = graph.getModulesByFile(file);\n if (nodes) {\n for (const node of nodes) {\n if (node.transformResult != null) return true;\n }\n return false;\n }\n return graph.getModuleById(file)?.transformResult != null;\n },\n toGraphPath\n );\n\n // Pre-hook — registers middleware before Vite's internals\n server.middlewares.use(createTimberMiddleware(server, ctx));\n\n // Print and open <name>.localhost:<port> instead of localhost:<port>, so\n // each app gets its own cookie jar. See design/21 §Dev Hostnames.\n const appDir = devRecordRoot(ctx.root, server.config.configFile);\n const hostname = applyDevHostname(server, appDir, ctx.config.dev?.hostname);\n\n // Write this server's .timber/dev/<pid>-<port>-<token>.json record once\n // the server is listening so `timber dev status`, the graph CLI and the\n // VS Code extension can discover it. See design/21 §Discovery Records.\n registerDevDiscovery(\n server.httpServer,\n ctx.root,\n () => advertisedUrls(server.resolvedUrls, hostname, server.config.server),\n server.config\n );\n\n // Transform the server graphs in the background once listening, so\n // the first request does not compile them one module at a time. See\n // design/21 §Server Pre-compile. `dev.precompile: false` opts out.\n if (ctx.config.dev?.precompile !== false) {\n precompileOnListen(server, () => {\n const toUrl = (file: string) => fileUrl(file, server.config.root);\n const seeds = ctx.routeTree ? routeTreeSeeds(ctx.routeTree) : { home: [], rest: [] };\n return {\n rsc: [[VIRTUAL_IDS.rscEntry, ...seeds.home.map(toUrl)], seeds.rest.map(toUrl)],\n ssr: [VIRTUAL_IDS.ssrEntry],\n };\n });\n }\n\n // Close the holding server and await the port release so Vite's\n // port probe and bind see a free port. configureServer is awaited\n // by Vite during createServer(), before startServer() runs\n // isPortAvailable() and httpServer.listen().\n // closeAllConnections() (in HoldingServer.close) kills keep-alive\n // sockets from the meta-refresh page so close() resolves promptly.\n // See design/21-dev-server.md §\"Startup Holding Server\", TIM-1419.\n if (ctx.holdingServer) {\n await ctx.holdingServer.close().catch(() => {});\n ctx.holdingServer = null;\n }\n\n // Log startup timing summary. configureServer runs on all plugins\n // before the server listens, so this captures the full cold start.\n ctx.timer.end('dev-server-setup');\n const summary = ctx.timer.formatSummary();\n if (summary) {\n console.log(summary);\n }\n },\n };\n}\n\n// ─── Middleware ────────────────────────────────────────────────────────────\n\n/**\n * Create the Connect middleware that routes requests through the timber pipeline.\n *\n * For route requests (HTML pages, API endpoints), the middleware:\n * 1. Loads the RSC entry via ssrLoadModule\n * 2. Converts the Node request to a Web Request\n * 3. Passes it through the RSC handler (which runs the full pipeline)\n * 4. Converts the Web Response back to a Node response\n *\n * For non-route requests (assets, Vite internals, HMR), the middleware\n * calls next() to let Vite handle them.\n */\nfunction createTimberMiddleware(server: ViteDevServer, ctx: PluginContext) {\n const projectRoot = ctx.root;\n // Extract HMR connection options once so the error page can construct\n // a correct WebSocket URL (TIM-789).\n const hmrOptions = extractHmrOptions(server.config);\n\n // Debug channel registry: buffers RSC debug rows per request and replays\n return async (req: IncomingMessage, res: ServerResponse, next: () => void): Promise<void> => {\n const url = req.url;\n if (!url) {\n next();\n return;\n }\n\n // Pass through Vite-internal requests\n if (isViteInternal(url)) {\n next();\n return;\n }\n\n // Files that exist in public/ are always served by Vite's static\n // middleware, regardless of extension. Without this, extensions like\n // .ico, .txt, .xml, .html either get caught by the metadata route\n // check or aren't in ASSET_EXTENSIONS, so they fall through to the\n // app router where a dynamic segment like [artistSlug] 404s them.\n if (isPublicFile(server, url)) {\n next();\n return;\n }\n\n // Pass through static asset requests — but not metadata routes like\n // /favicon.ico that match asset extensions but are handled by timber,\n // and not registered routes like app/feed.json/route.ts whose URL ends\n // in an asset extension. Production serves these through the RSC\n // handler, so letting them fall through to Vite would 404 in dev only\n // (TIM-1038).\n if (\n isAssetRequest(url) &&\n !isMetadataRouteServePath(url) &&\n !isRouteOwnedAsset(ctx.routeTree, server, url)\n ) {\n next();\n return;\n }\n\n // Step 1: Load the RSC entry module from the RSC environment.\n // The RSC entry runs in the 'rsc' Vite environment (separate module\n // graph with react-server conditions). In dev mode, this uses the\n // environment's module runner for HMR-aware loading.\n let handler: (req: Request) => Promise<Response>;\n try {\n const rscEnv = server.environments.rsc as DevEnvironment & {\n runner?: { import: (id: string) => Promise<any> };\n };\n // Duck-type check instead of isRunnableDevEnvironment() — the vite\n // import-based check fails across pnpm link boundaries where the\n // linked package resolves a different vite module instance.\n if (!rscEnv?.runner?.import) {\n throw new Error('[timber] RSC environment is not runnable');\n }\n const rscModule = await rscEnv.runner.import(VIRTUAL_IDS.rscEntry);\n handler = rscModule.default as (req: Request) => Promise<Response>;\n\n // Wire pipeline errors into the browser error overlay, and plumb the\n // resolved HMR options into the RSC environment. The RSC entry can't\n // read the Vite server config (separate module graph), but its dev 404\n // page and fallback error page need the HMR endpoint (including Vite\n // 8's required WS token) for auto-reload (TIM-1067).\n const setDevHooks = rscModule.setDevHooks as ((hooks: DevHooks) => void) | undefined;\n setDevHooks?.({\n onPipelineError: (error) => {\n sendErrorToOverlay(server, error, classifyErrorPhase(error, projectRoot), projectRoot);\n },\n hmrOptions,\n });\n } catch (error) {\n // Module transform error — syntax error, missing import, etc.\n // Vite may already show its own overlay for these, but we still\n // log to stderr with frame dimming for the terminal.\n if (error instanceof Error) {\n // Add context for virtual:timber-* module errors\n addTimberContext(error);\n sendErrorToOverlay(server, error, 'module-transform', projectRoot);\n }\n respond500(res, error, 'module-transform', projectRoot, hmrOptions);\n return;\n }\n\n if (typeof handler !== 'function') {\n console.error('[timber] RSC entry module does not export a default function');\n next();\n return;\n }\n\n // Step 2: Run the pipeline.\n try {\n // Convert Node IncomingMessage → Web Request\n const webRequest = toWebRequest(req);\n // A malformed Host or request target is the client's error: a 400,\n // not a 500 and an overlay for a bug the app doesn't have (TIM-1600).\n if (!webRequest) {\n res.writeHead(400, { 'content-type': 'text/plain; charset=utf-8' });\n res.end('Bad Request');\n return;\n }\n\n // Check for a platform-specific request wrapper (e.g., Cloudflare\n // dev bindings). The cloudflareDevBindings() plugin stores a wrapper\n // function on the server instance using a well-known Symbol. The\n // wrapper runs the handler inside an ALS context so platform APIs\n // like getCloudflareBindings() work during dev.\n // See design/35-cloudflare-primitives.md §\"Dev Experience\".\n const wrapper = (server as any)[Symbol.for('timber:dev-request-wrapper')] as\n | (<T>(fn: () => T) => T)\n | undefined;\n\n // Run the full pipeline (wrapped if a platform dev plugin is active)\n const webResponse = wrapper\n ? await wrapper(() => handler(webRequest))\n : await handler(webRequest);\n\n // Compress the response if the client supports it.\n // In dev mode, compression is always enabled for parity with production.\n // See design/25-production-deployments.md.\n const finalResponse = compressResponse(webRequest, webResponse);\n\n // Flush headers eagerly so streaming responses (SSE, long-polling)\n // reach the client before the first body chunk. Node.js buffers\n // headers until write()/end() otherwise, which stalls EventSource\n // clients that wait for the response to open. srvx's writeHead\n // skips if headersSent is already true, so pre-flushing is safe.\n res.writeHead(finalResponse.status, [...finalResponse.headers].flat());\n res.flushHeaders();\n\n // Stream the body with backpressure and disconnect handling.\n // srvx skips its own writeHead since headers are already sent.\n await sendNodeResponse(res, finalResponse);\n } catch (error) {\n // An error the pipeline did not turn into a response, or one sending\n // the response threw — classify the phase, send to overlay, respond\n // 500. The pipeline answers render errors itself (an SsrStreamError\n // never gets here), so this sees the error as thrown. The dev server\n // remains running for recovery on file fix + HMR.\n if (error instanceof Error) {\n const phase = classifyErrorPhase(error, projectRoot);\n sendErrorToOverlay(server, error, phase, projectRoot);\n respond500(res, error, phase, projectRoot, hmrOptions);\n } else {\n process.stderr.write(`\\x1b[31m[timber] Dev server error:\\x1b[0m ${String(error)}\\n`);\n respond500(res, error, 'render', projectRoot, hmrOptions);\n }\n }\n };\n}\n\n/**\n * Send a 500 response without crashing the dev server.\n *\n * In dev mode, renders a styled HTML error page with source context,\n * classified stack trace, and auto-reload on HMR. Falls back to\n * text/plain if the HTML generator fails (must never crash).\n */\nfunction respond500(\n res: ServerResponse,\n error: unknown,\n phase: ErrorPhase,\n projectRoot: string,\n hmrOptions?: DevErrorHmrOptions\n): void {\n if (res.headersSent) return;\n\n // Try to render the rich HTML error page\n if (error instanceof Error) {\n try {\n const html = generateDevErrorPage(error, phase, projectRoot, hmrOptions);\n res.statusCode = 500;\n res.setHeader('content-type', 'text/html; charset=utf-8');\n res.end(html);\n return;\n } catch (e) {\n console.debug(\n '[timber] dev error page generation failed, falling back to text/plain:',\n e instanceof Error ? e.message : e\n );\n }\n }\n\n // Fallback: plain text (same as before)\n res.statusCode = 500;\n res.setHeader('content-type', 'text/plain');\n res.end(\n `[timber] Internal server error\\n\\n${error instanceof Error ? (error.stack ?? error.message) : String(error)}`\n );\n}\n\n/**\n * Add timber-specific context to an error's message if it references\n * internal virtual modules (virtual:timber-*). Mutates the error in place.\n */\nfunction addTimberContext(error: Error): void {\n const enriched = addVirtualModuleContext(error.message);\n if (enriched !== error.message) {\n error.message = enriched;\n }\n}\n\n// ─── Request/Response Conversion ──────────────────────────────────────────\n\n/**\n * Convert a Node IncomingMessage to a Web Request.\n *\n * Constructs the full URL from the Host header and request URL,\n * and forwards the method, headers, and body.\n *\n * The scheme comes from the socket's TLS state — with `server.https` the\n * browser sends `Origin: https://host`, and a hardcoded `http://` would\n * fail CSRF origin comparison on every POST. X-Forwarded-Proto is NOT\n * consulted: dev connections are direct, so the header would be\n * attacker-controlled. (TIM-1067, B32)\n *\n * Returns null for a request that names no URL — a Host that is not a bare\n * host[:port], or a request target that does not parse — which the caller\n * answers with 400. (TIM-1600)\n *\n * Exported for tests.\n */\nexport function toWebRequest(nodeReq: IncomingMessage): Request | null {\n const protocol = (nodeReq.socket as TLSSocket | undefined)?.encrypted ? 'https' : 'http';\n // Under HTTP/2 there is no Host header — the authority lives in the\n // `:authority` pseudo-header.\n const host =\n nodeReq.headers.host ?? (nodeReq.headers[':authority'] as string | undefined) ?? 'localhost';\n // The Host is an authority, nothing more. Pasted into the URL, one with a\n // path or query moves the request target: `Host: localhost:5173/x?` and\n // target `/admin` would route `/x` with search `?/admin`. A backslash is a\n // path separator to the URL parser, and `@` would make the host userinfo.\n const origin = /[/?#@\\\\]/.test(host) ? null : URL.parse(`${protocol}://${host}`)?.origin;\n const url = origin ? requestTargetUrl(origin, nodeReq.url || '/') : null;\n if (!url) return null;\n\n const headers = new Headers();\n for (const [key, value] of Object.entries(nodeReq.headers)) {\n if (value === undefined) continue;\n // HTTP/2 pseudo-headers (:method, :path, :authority, :scheme) are not\n // valid Headers names — Headers.set() throws on them. They're already\n // reflected in the request URL/method above.\n if (key.startsWith(':')) continue;\n if (Array.isArray(value)) {\n for (const v of value) {\n headers.append(key, v);\n }\n } else {\n headers.set(key, value);\n }\n }\n // HTTP/2 requests carry the authority in `:authority`, not Host — but\n // downstream consumers (CSRF origin validation) read the Host header.\n if (!headers.has('host')) {\n headers.set('host', host);\n }\n\n const method = nodeReq.method ?? 'GET';\n const hasBody = method !== 'GET' && method !== 'HEAD';\n\n return new Request(url, {\n method,\n headers,\n body: hasBody ? nodeReadableToWebStream(nodeReq) : undefined,\n // @ts-expect-error — duplex is required for streaming request bodies\n duplex: hasBody ? 'half' : undefined,\n });\n}\n\n/**\n * Convert a Node Readable stream to a Web ReadableStream.\n */\nfunction nodeReadableToWebStream(nodeStream: IncomingMessage): ReadableStream<Uint8Array> {\n return new ReadableStream({\n start(controller) {\n nodeStream.on('data', (chunk: Buffer) => {\n controller.enqueue(new Uint8Array(chunk));\n });\n nodeStream.on('end', () => {\n controller.close();\n });\n nodeStream.on('error', (err) => {\n controller.error(err);\n });\n },\n });\n}\n\n// ─── URL Classification ──────────────────────────────────────────────────\n\n/**\n * Check if a URL is a Vite-internal request that should be passed through.\n */\nfunction isViteInternal(url: string): boolean {\n return VITE_INTERNAL_PREFIXES.some((prefix) => url.startsWith(prefix));\n}\n\n/**\n * Check if a URL looks like a static asset request.\n */\nfunction isAssetRequest(url: string): boolean {\n return ASSET_EXTENSIONS.test(url);\n}\n\n/**\n * Check if a URL maps to a real file in the project's public/ directory.\n * Vite serves public/ files as static assets — if a file exists there it\n * must be passed through to Vite regardless of extension.\n */\nfunction isPublicFile(server: ViteDevServer, url: string): boolean {\n const { publicDir } = server.config;\n if (!publicDir) return false;\n const pathname = url.split('?')[0];\n const relativePath = pathname.startsWith('/') ? pathname.slice(1) : pathname;\n if (!relativePath) return false;\n const fullPath = join(publicDir, relativePath);\n try {\n return statSync(fullPath).isFile();\n } catch {\n return false;\n }\n}\n\n/**\n * Check whether an asset-extension URL belongs to a scanned route rather\n * than a static file.\n *\n * Route handlers may live at paths ending in asset-like extensions\n * (app/feed.json/route.ts → /feed.json), which the asset bypass would\n * otherwise hand to Vite — 404ing in dev while working in production.\n * Uses the same canonicalization and tree walker as the runtime matcher\n * so dev classification agrees with what the pipeline would match.\n *\n * A file that actually exists on disk wins over the route match: the\n * production server serves public/ statics before the RSC handler (see\n * adapters/nitro.ts), and Vite serves root-relative source files (e.g.\n * /app/global.css) in dev. Without this, a broad catch-all route like\n * app/[...slug] would shadow every static asset. Joining the canonical\n * pathname is traversal-safe — canonicalize() resolves `..` segments and\n * rejects root escapes and encoded separators.\n *\n * Reads ctx.routeTree per request — the routing plugin rescans it on\n * file add/unlink/change, so newly created routes are picked up live.\n */\nfunction isRouteOwnedAsset(\n routeTree: RouteTree | null,\n server: ViteDevServer,\n url: string\n): boolean {\n if (!routeTree) return false;\n const rawPathname = url.split('?')[0];\n const result = canonicalize(rawPathname);\n // Malformed URLs can't match a route — let Vite handle them as before.\n if (!result.ok) return false;\n const parts = result.pathname === '/' ? [] : result.pathname.slice(1).split('/');\n if (matchUrlParts(routeTree.root, parts) === null) return false;\n\n // Real static files win over the route match (dev/prod parity: the\n // production server tries public/ before the RSC handler).\n const relativePath = result.pathname.slice(1);\n const { publicDir, root } = server.config;\n if (publicDir && existsSync(join(publicDir, relativePath))) return false;\n if (existsSync(join(root, relativePath))) return false;\n\n return true;\n}\n\n// ─── Client Error Listener ─────────────────────────────────────────────\n\ninterface ClientErrorPayload {\n message: string;\n stack: string;\n componentStack: string | null;\n}\n\n/**\n * Listen for client-side errors forwarded from the browser via HMR.\n *\n * The browser entry catches uncaught errors and unhandled rejections,\n * then sends them as 'timber:client-error' custom events. We parse\n * the first app frame for the overlay's loc field and forward the\n * error to Vite's overlay protocol.\n */\nfunction listenForClientErrors(server: ViteDevServer, projectRoot: string): void {\n server.hot.on('timber:client-error', (data: ClientErrorPayload) => {\n const loc = parseFirstAppFrame(data.stack, projectRoot);\n\n let message = data.message;\n if (data.componentStack) {\n message = `${data.message}\\n\\nComponent Stack:\\n${data.componentStack.trim()}`;\n }\n\n // Log to stderr\n const RED = '\\x1b[31m';\n const BOLD = '\\x1b[1m';\n const RESET = '\\x1b[0m';\n process.stderr.write(\n `${RED}${BOLD}[timber] Client Error${RESET}\\n${RED}${data.message}${RESET}\\n\\n`\n );\n\n // Forward to Vite's overlay\n try {\n server.hot.send({\n type: 'error',\n err: {\n message,\n stack: data.stack,\n id: loc?.file,\n plugin: 'timber (Client)',\n loc: loc ? { file: loc.file, line: loc.line, column: loc.column } : undefined,\n },\n });\n } catch (e) {\n console.debug('[timber] overlay send failed:', e instanceof Error ? e.message : e);\n }\n });\n}\n"],"ignoreList":[0],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAUA,SAAS,iBAAiB,SAAS,QAAQ;CAC1C,IAAI;EACH,OAAO,kBAAkB,SAAS,QAAQ,KAAK,K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