theokit 0.48.14 → 0.50.1

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 (337) hide show
  1. package/README.md +1 -0
  2. package/dist/{actions-virtual-module-YZRZMHAX.js → actions-virtual-module-DSIVNGK7.js} +14 -8
  3. package/dist/{actions-virtual-module-YZRZMHAX.js.map → actions-virtual-module-DSIVNGK7.js.map} +1 -1
  4. package/dist/{actions-virtual-module-E4PISKMB.js → actions-virtual-module-RXL2RJTW.js} +23 -12
  5. package/dist/actions-virtual-module-RXL2RJTW.js.map +1 -0
  6. package/dist/adapters/agent-mount.d.ts +127 -0
  7. package/dist/adapters/agent-mount.js +25 -0
  8. package/dist/adapters/security-headers.d.ts +132 -0
  9. package/dist/adapters/security-headers.js +64 -0
  10. package/dist/adapters/security-headers.js.map +1 -0
  11. package/dist/adapters/web-shim.d.ts +100 -13
  12. package/dist/adapters/web-shim.js +158 -54
  13. package/dist/adapters/web-shim.js.map +1 -1
  14. package/dist/agent-7IPEVCAY.js +15 -0
  15. package/dist/agent-scan-BZa-pagG.d.ts +16 -0
  16. package/dist/{app-typed-client-I4X2UJWW.js → app-typed-client-UTBMJZOE.js} +15 -9
  17. package/dist/app-typed-client-UTBMJZOE.js.map +1 -0
  18. package/dist/{app-typed-client-HLP26EYM.js → app-typed-client-XGDZKH73.js} +24 -13
  19. package/dist/app-typed-client-XGDZKH73.js.map +1 -0
  20. package/dist/aws-lambda-VKMYUMP2.js +261 -0
  21. package/dist/aws-lambda-VKMYUMP2.js.map +1 -0
  22. package/dist/{body-parser-web-4Z2QTPDU.js → body-parser-web-ON5CUTEL.js} +5 -2
  23. package/dist/body-parser-web-ON5CUTEL.js.map +1 -0
  24. package/dist/{body-parser-web-TIOTXPDW.js → body-parser-web-RV2SSAI3.js} +5 -2
  25. package/dist/body-parser-web-RV2SSAI3.js.map +1 -0
  26. package/dist/{build-F2Q5QTSC.js → build-VZODSYIQ.js} +72 -26
  27. package/dist/build-VZODSYIQ.js.map +1 -0
  28. package/dist/{bun-A5B2MJMO.js → bun-L7PP6ID5.js} +105 -13
  29. package/dist/bun-L7PP6ID5.js.map +1 -0
  30. package/dist/{check-45NKUVSQ.js → check-GIPZBFTX.js} +2 -2
  31. package/dist/{chunk-WYHYOYRH.js → chunk-2COPDKIG.js} +468 -203
  32. package/dist/chunk-2COPDKIG.js.map +1 -0
  33. package/dist/chunk-3PBAN2YE.js +146 -0
  34. package/dist/chunk-3PBAN2YE.js.map +1 -0
  35. package/dist/{chunk-HBU2GIMZ.js → chunk-3QPVEJ7D.js} +15 -9
  36. package/dist/chunk-3QPVEJ7D.js.map +1 -0
  37. package/dist/{chunk-IEES3CHD.js → chunk-47MM2JUK.js} +8 -2
  38. package/dist/chunk-47MM2JUK.js.map +1 -0
  39. package/dist/chunk-4X6H2BXP.js +108 -0
  40. package/dist/chunk-4X6H2BXP.js.map +1 -0
  41. package/dist/{chunk-A7JBF5FO.js → chunk-5K4TDLRG.js} +8 -5
  42. package/dist/chunk-5K4TDLRG.js.map +1 -0
  43. package/dist/chunk-5YPXXSYY.js +181 -0
  44. package/dist/chunk-5YPXXSYY.js.map +1 -0
  45. package/dist/{chunk-YGAXV5HR.js → chunk-6J4JWHDJ.js} +191 -112
  46. package/dist/chunk-6J4JWHDJ.js.map +1 -0
  47. package/dist/{chunk-FTFN4MYN.js → chunk-7AEBH52I.js} +639 -516
  48. package/dist/chunk-7AEBH52I.js.map +1 -0
  49. package/dist/chunk-7UZZHCRN.js +21 -0
  50. package/dist/chunk-7UZZHCRN.js.map +1 -0
  51. package/dist/{chunk-MTEWLGVY.js → chunk-BPYMC7SU.js} +4 -48
  52. package/dist/chunk-BPYMC7SU.js.map +1 -0
  53. package/dist/chunk-BU6RJPPJ.js +421 -0
  54. package/dist/chunk-BU6RJPPJ.js.map +1 -0
  55. package/dist/{chunk-FB2HBNIC.js → chunk-BX6EUYHU.js} +6 -2
  56. package/dist/chunk-BX6EUYHU.js.map +1 -0
  57. package/dist/chunk-CHTAWXC2.js +18 -0
  58. package/dist/chunk-CHTAWXC2.js.map +1 -0
  59. package/dist/chunk-D4VP2QPR.js +16 -0
  60. package/dist/chunk-D4VP2QPR.js.map +1 -0
  61. package/dist/{chunk-YXG2SGQ3.js → chunk-DHAD2O3S.js} +6 -6
  62. package/dist/chunk-DHAD2O3S.js.map +1 -0
  63. package/dist/chunk-DOI4G4X3.js +428 -0
  64. package/dist/chunk-DOI4G4X3.js.map +1 -0
  65. package/dist/chunk-E43VJ3E5.js +188 -0
  66. package/dist/chunk-E43VJ3E5.js.map +1 -0
  67. package/dist/{chunk-47CINLWF.js → chunk-EDWEYQRG.js} +2 -2
  68. package/dist/chunk-EVZKNA2W.js +110 -0
  69. package/dist/chunk-EVZKNA2W.js.map +1 -0
  70. package/dist/chunk-FD4ZDTQ6.js +181 -0
  71. package/dist/chunk-FD4ZDTQ6.js.map +1 -0
  72. package/dist/chunk-FDOOBTXJ.js +17 -0
  73. package/dist/chunk-FDOOBTXJ.js.map +1 -0
  74. package/dist/chunk-FH3SQR6P.js +275 -0
  75. package/dist/chunk-FH3SQR6P.js.map +1 -0
  76. package/dist/{chunk-T5C46IIU.js → chunk-FMTRNQQ7.js} +28 -269
  77. package/dist/chunk-FMTRNQQ7.js.map +1 -0
  78. package/dist/chunk-H53KNS6Q.js +513 -0
  79. package/dist/chunk-H53KNS6Q.js.map +1 -0
  80. package/dist/chunk-HJHGTFEJ.js +23 -0
  81. package/dist/chunk-HJHGTFEJ.js.map +1 -0
  82. package/dist/{chunk-LXAESF4Y.js → chunk-HK4AZBKX.js} +7 -4
  83. package/dist/chunk-HK4AZBKX.js.map +1 -0
  84. package/dist/chunk-IRQGAC4L.js +52 -0
  85. package/dist/chunk-IRQGAC4L.js.map +1 -0
  86. package/dist/{chunk-FNTLKHZ7.js → chunk-JDN5SAAD.js} +7 -4
  87. package/dist/chunk-JDN5SAAD.js.map +1 -0
  88. package/dist/{chunk-XALU5LCU.js → chunk-JKF25N73.js} +555 -147
  89. package/dist/chunk-JKF25N73.js.map +1 -0
  90. package/dist/{chunk-BHOTGS7N.js → chunk-KI4DOTN4.js} +25 -2
  91. package/dist/chunk-KI4DOTN4.js.map +1 -0
  92. package/dist/chunk-KOS567NB.js +790 -0
  93. package/dist/chunk-KOS567NB.js.map +1 -0
  94. package/dist/{chunk-OOBYPCZC.js → chunk-KTS6G26H.js} +304 -195
  95. package/dist/chunk-KTS6G26H.js.map +1 -0
  96. package/dist/{chunk-ZB7D62OA.js → chunk-KUZVRJ7M.js} +3 -3
  97. package/dist/chunk-L4VFNFDL.js +248 -0
  98. package/dist/chunk-L4VFNFDL.js.map +1 -0
  99. package/dist/chunk-M2WC5MF7.js +127 -0
  100. package/dist/chunk-M2WC5MF7.js.map +1 -0
  101. package/dist/chunk-N42ZWWOW.js +273 -0
  102. package/dist/chunk-N42ZWWOW.js.map +1 -0
  103. package/dist/chunk-OGLS76RN.js +43 -0
  104. package/dist/chunk-OGLS76RN.js.map +1 -0
  105. package/dist/{chunk-7LVM22VG.js → chunk-OQCRCXCP.js} +6 -6
  106. package/dist/chunk-OQCRCXCP.js.map +1 -0
  107. package/dist/{chunk-OLGPYOLO.js → chunk-P6OS7652.js} +5 -2
  108. package/dist/chunk-P6OS7652.js.map +1 -0
  109. package/dist/{chunk-O3JIAU3V.js → chunk-PF3YM6NY.js} +157 -103
  110. package/dist/chunk-PF3YM6NY.js.map +1 -0
  111. package/dist/{chunk-NTWNO24W.js → chunk-PLUHPNGA.js} +266 -110
  112. package/dist/chunk-PLUHPNGA.js.map +1 -0
  113. package/dist/chunk-Q5L5EGWZ.js +26 -0
  114. package/dist/chunk-Q5L5EGWZ.js.map +1 -0
  115. package/dist/{chunk-AATSV4UV.js → chunk-QTHVHNJJ.js} +6 -36
  116. package/dist/chunk-QTHVHNJJ.js.map +1 -0
  117. package/dist/{chunk-KD5G3YXI.js → chunk-RARK7JBR.js} +39 -10
  118. package/dist/chunk-RARK7JBR.js.map +1 -0
  119. package/dist/chunk-RJJF457I.js +111 -0
  120. package/dist/chunk-RJJF457I.js.map +1 -0
  121. package/dist/chunk-RPET332G.js +84 -0
  122. package/dist/chunk-RPET332G.js.map +1 -0
  123. package/dist/{chunk-646CA6RV.js → chunk-RQW5YMH7.js} +12 -4
  124. package/dist/chunk-RQW5YMH7.js.map +1 -0
  125. package/dist/chunk-U5PWXS3J.js +39 -0
  126. package/dist/chunk-U5PWXS3J.js.map +1 -0
  127. package/dist/{chunk-RWNSW4FM.js → chunk-UMNXCU3K.js} +12 -6
  128. package/dist/{chunk-RWNSW4FM.js.map → chunk-UMNXCU3K.js.map} +1 -1
  129. package/dist/{chunk-DS5MCU2X.js → chunk-URCXSUI3.js} +9 -9
  130. package/dist/chunk-VI7ZANB3.js +193 -0
  131. package/dist/chunk-VI7ZANB3.js.map +1 -0
  132. package/dist/chunk-VQPHPQ5L.js +14 -0
  133. package/dist/chunk-VQPHPQ5L.js.map +1 -0
  134. package/dist/chunk-WNJTJRM6.js +147 -0
  135. package/dist/chunk-WNJTJRM6.js.map +1 -0
  136. package/dist/{chunk-BMHS4WAN.js → chunk-XS7EX55U.js} +156 -42
  137. package/dist/chunk-XS7EX55U.js.map +1 -0
  138. package/dist/chunk-YN4W7LCX.js +31 -0
  139. package/dist/chunk-YN4W7LCX.js.map +1 -0
  140. package/dist/chunk-YSJOZEI6.js +1 -0
  141. package/dist/{chunk-JA2ZAT5Q.js → chunk-Z4PJMZLM.js} +2 -2
  142. package/dist/chunk-Z4PJMZLM.js.map +1 -0
  143. package/dist/{chunk-WSXNGF7X.js → chunk-ZNZISJDZ.js} +6 -2
  144. package/dist/chunk-ZNZISJDZ.js.map +1 -0
  145. package/dist/chunk-ZWN3AODA.js +11 -0
  146. package/dist/chunk-ZWN3AODA.js.map +1 -0
  147. package/dist/cli/index.js +25 -10
  148. package/dist/cli/index.js.map +1 -1
  149. package/dist/client/core.d.ts +1 -1
  150. package/dist/client/core.js +2 -0
  151. package/dist/client/core.js.map +1 -1
  152. package/dist/client/index.d.ts +44 -10
  153. package/dist/client/index.js +35 -0
  154. package/dist/client/index.js.map +1 -1
  155. package/dist/cloudflare-SIG42OIW.js +335 -0
  156. package/dist/cloudflare-SIG42OIW.js.map +1 -0
  157. package/dist/config-support-WQHQIJTA.js +104 -0
  158. package/dist/config-support-WQHQIJTA.js.map +1 -0
  159. package/dist/{csrf-BBrEZSBW.d.ts → csrf-Dgot9qSM.d.ts} +1 -1
  160. package/dist/deno-deploy-LQAYOOPW.js +196 -0
  161. package/dist/deno-deploy-LQAYOOPW.js.map +1 -0
  162. package/dist/{dev-CDFPXISP.js → dev-3UQVD2W6.js} +29 -18
  163. package/dist/dev-3UQVD2W6.js.map +1 -0
  164. package/dist/{dev-emit-GWD6IXV7.js → dev-emit-BFNMDCPB.js} +5 -5
  165. package/dist/{dev-emit-NBT6JD7R.js → dev-emit-MVAJAFGX.js} +5 -3
  166. package/dist/dev-emit-MVAJAFGX.js.map +1 -0
  167. package/dist/engine-singleton-X4R7AZBJ.js +315 -0
  168. package/dist/engine-singleton-X4R7AZBJ.js.map +1 -0
  169. package/dist/{generate-Y3GWM57K.js → generate-EN6EDITF.js} +43 -4
  170. package/dist/generate-EN6EDITF.js.map +1 -0
  171. package/dist/index-DctfHtv-.d.ts +1058 -0
  172. package/dist/index.d.ts +8 -4
  173. package/dist/index.js +25 -13
  174. package/dist/index.js.map +1 -1
  175. package/dist/{info-QXZW722N.js → info-Y55RWS42.js} +8 -6
  176. package/dist/{info-QXZW722N.js.map → info-Y55RWS42.js.map} +1 -1
  177. package/dist/{internal-api-FBK2YXSI.js → internal-api-4X6NDS2F.js} +23 -12
  178. package/dist/{internal-api-ZCJWJ5EC.js → internal-api-XQHU5JKY.js} +31 -16
  179. package/dist/internal-api-XQHU5JKY.js.map +1 -0
  180. package/dist/load-config-4ATXQUN3.js +16 -0
  181. package/dist/match-DmGgxjIU.d.ts +44 -0
  182. package/dist/{mcp-KTYP4ZON.js → mcp-IQRHFP3Y.js} +7 -7
  183. package/dist/netlify-C2IRCZKI.js +245 -0
  184. package/dist/netlify-C2IRCZKI.js.map +1 -0
  185. package/dist/node-OSVPYQ3D.js +10 -0
  186. package/dist/nonce-BXt7Qu_C.d.ts +31 -0
  187. package/dist/observability-bootstrap-LERYDHKY.js +16 -0
  188. package/dist/{openapi-OUXNB2F2.js → openapi-VFPEZSRI.js} +13 -11
  189. package/dist/{openapi-OUXNB2F2.js.map → openapi-VFPEZSRI.js.map} +1 -1
  190. package/dist/{plugin-runner-DHVr1cC5.d.ts → plugin-runner-BVMOSxvb.d.ts} +1 -1
  191. package/dist/{plugin-types-4VN1GMqV.d.ts → plugin-types-BUVfUQ0V.d.ts} +1 -1
  192. package/dist/preview-BT47VMIB.js +23 -0
  193. package/dist/preview-BT47VMIB.js.map +1 -0
  194. package/dist/provider-resolver-Dx6QuWrw.d.ts +128 -0
  195. package/dist/registry-KBZDCFVQ.js +23 -0
  196. package/dist/route-config-Cm_ZMA1C.d.ts +72 -0
  197. package/dist/route-policy-BxOycCDq.d.ts +65 -0
  198. package/dist/router/element-scroll-restoration.d.ts +28 -0
  199. package/dist/router/element-scroll-restoration.js +96 -0
  200. package/dist/router/element-scroll-restoration.js.map +1 -0
  201. package/dist/{routes-NJR4ISCT.js → routes-BPLU3ISV.js} +11 -9
  202. package/dist/{routes-NJR4ISCT.js.map → routes-BPLU3ISV.js.map} +1 -1
  203. package/dist/{scan-7MJC6PYU.js → scan-YJEE4KQK.js} +2 -2
  204. package/dist/{schema-DNIT7JQX.js → schema-SOAD43RQ.js} +7 -5
  205. package/dist/schemas-4AXHQMV3.js +25 -0
  206. package/dist/schemas-4AXHQMV3.js.map +1 -0
  207. package/dist/security-headers-Ccj7ncNx.d.ts +129 -0
  208. package/dist/server/agent/index.d.ts +2 -105
  209. package/dist/server/agent/index.js +1 -1
  210. package/dist/server/auth/index.d.ts +2 -21
  211. package/dist/server/auth/index.js +3 -2
  212. package/dist/server/cron/index.js +4 -3
  213. package/dist/server/define/index.d.ts +43 -57
  214. package/dist/server/define/index.js +10 -1
  215. package/dist/server/http/index.d.ts +7 -5
  216. package/dist/server/http/index.js +57 -12
  217. package/dist/server/index.d.ts +47 -439
  218. package/dist/server/index.js +120 -201
  219. package/dist/server/index.js.map +1 -1
  220. package/dist/server/jobs/index.js +4 -3
  221. package/dist/server/observability/index.d.ts +109 -35
  222. package/dist/server/observability/index.js +11 -7
  223. package/dist/server/plugins/index.d.ts +3 -3
  224. package/dist/server/scan/index.d.ts +47 -12
  225. package/dist/server/scan/index.js +13 -4
  226. package/dist/server/security/index.d.ts +61 -103
  227. package/dist/server/security/index.js +15 -6
  228. package/dist/server/webhook/index.d.ts +90 -3
  229. package/dist/server/webhook/index.js +12 -2
  230. package/dist/server-boundary-2WFT546S.js +149 -0
  231. package/dist/server-boundary-2WFT546S.js.map +1 -0
  232. package/dist/server-boundary-A67OPRKO.js +134 -0
  233. package/dist/server-boundary-A67OPRKO.js.map +1 -0
  234. package/dist/{services-typed-client-P4JERLBL.js → services-typed-client-XGT5SUUN.js} +2 -2
  235. package/dist/{start-25OV2CAK.js → start-3K3C4Z2X.js} +224 -161
  236. package/dist/start-3K3C4Z2X.js.map +1 -0
  237. package/dist/{static-RTO637XW.js → static-SVDWIOXJ.js} +24 -13
  238. package/dist/static-SVDWIOXJ.js.map +1 -0
  239. package/dist/{theo-cloud-UZ3GINRU.js → theo-cloud-3ET4G5T6.js} +9 -2
  240. package/dist/theo-cloud-3ET4G5T6.js.map +1 -0
  241. package/dist/vercel-BMCQKCWE.js +277 -0
  242. package/dist/vercel-BMCQKCWE.js.map +1 -0
  243. package/dist/vite-plugin/index.js +25 -13
  244. package/dist/vite-plugin-USXUIV3H.js +43 -0
  245. package/dist/vite-plugin-USXUIV3H.js.map +1 -0
  246. package/package.json +19 -6
  247. package/dist/actions-virtual-module-E4PISKMB.js.map +0 -1
  248. package/dist/agent-XAQCUQNB.js +0 -15
  249. package/dist/app-typed-client-HLP26EYM.js.map +0 -1
  250. package/dist/app-typed-client-I4X2UJWW.js.map +0 -1
  251. package/dist/aws-lambda-KES4MFJV.js +0 -172
  252. package/dist/aws-lambda-KES4MFJV.js.map +0 -1
  253. package/dist/body-parser-web-4Z2QTPDU.js.map +0 -1
  254. package/dist/body-parser-web-TIOTXPDW.js.map +0 -1
  255. package/dist/build-F2Q5QTSC.js.map +0 -1
  256. package/dist/bun-A5B2MJMO.js.map +0 -1
  257. package/dist/chunk-646CA6RV.js.map +0 -1
  258. package/dist/chunk-7LVM22VG.js.map +0 -1
  259. package/dist/chunk-A7JBF5FO.js.map +0 -1
  260. package/dist/chunk-AATSV4UV.js.map +0 -1
  261. package/dist/chunk-AM3QABW5.js +0 -161
  262. package/dist/chunk-AM3QABW5.js.map +0 -1
  263. package/dist/chunk-AXKUA57G.js +0 -94
  264. package/dist/chunk-AXKUA57G.js.map +0 -1
  265. package/dist/chunk-BHOTGS7N.js.map +0 -1
  266. package/dist/chunk-BMHS4WAN.js.map +0 -1
  267. package/dist/chunk-CMYSHZFT.js +0 -422
  268. package/dist/chunk-CMYSHZFT.js.map +0 -1
  269. package/dist/chunk-DQIPV7L5.js +0 -118
  270. package/dist/chunk-DQIPV7L5.js.map +0 -1
  271. package/dist/chunk-FB2HBNIC.js.map +0 -1
  272. package/dist/chunk-FNTLKHZ7.js.map +0 -1
  273. package/dist/chunk-FTFN4MYN.js.map +0 -1
  274. package/dist/chunk-HBU2GIMZ.js.map +0 -1
  275. package/dist/chunk-IEES3CHD.js.map +0 -1
  276. package/dist/chunk-JA2ZAT5Q.js.map +0 -1
  277. package/dist/chunk-KD5G3YXI.js.map +0 -1
  278. package/dist/chunk-KTKTHIUF.js +0 -405
  279. package/dist/chunk-KTKTHIUF.js.map +0 -1
  280. package/dist/chunk-LNVMHQ2Z.js +0 -54
  281. package/dist/chunk-LNVMHQ2Z.js.map +0 -1
  282. package/dist/chunk-LXAESF4Y.js.map +0 -1
  283. package/dist/chunk-MTEWLGVY.js.map +0 -1
  284. package/dist/chunk-NTWNO24W.js.map +0 -1
  285. package/dist/chunk-O3JIAU3V.js.map +0 -1
  286. package/dist/chunk-OLGPYOLO.js.map +0 -1
  287. package/dist/chunk-OOBYPCZC.js.map +0 -1
  288. package/dist/chunk-T5C46IIU.js.map +0 -1
  289. package/dist/chunk-U267AOWS.js +0 -28
  290. package/dist/chunk-U267AOWS.js.map +0 -1
  291. package/dist/chunk-UW2TEAGR.js +0 -77
  292. package/dist/chunk-UW2TEAGR.js.map +0 -1
  293. package/dist/chunk-WPJOTQA5.js +0 -1
  294. package/dist/chunk-WSXNGF7X.js.map +0 -1
  295. package/dist/chunk-WYHYOYRH.js.map +0 -1
  296. package/dist/chunk-XALU5LCU.js.map +0 -1
  297. package/dist/chunk-XR74JD4M.js +0 -457
  298. package/dist/chunk-XR74JD4M.js.map +0 -1
  299. package/dist/chunk-YGAXV5HR.js.map +0 -1
  300. package/dist/chunk-YXG2SGQ3.js.map +0 -1
  301. package/dist/cloudflare-IN2WB7FZ.js +0 -122
  302. package/dist/cloudflare-IN2WB7FZ.js.map +0 -1
  303. package/dist/deno-deploy-LYXQEJ6A.js +0 -107
  304. package/dist/deno-deploy-LYXQEJ6A.js.map +0 -1
  305. package/dist/dev-CDFPXISP.js.map +0 -1
  306. package/dist/dev-emit-NBT6JD7R.js.map +0 -1
  307. package/dist/generate-Y3GWM57K.js.map +0 -1
  308. package/dist/index-D_PxPXgQ.d.ts +0 -575
  309. package/dist/load-config-FIWNKOJO.js +0 -14
  310. package/dist/match-CfbEFRG4.d.ts +0 -26
  311. package/dist/netlify-DLEOCFAD.js +0 -150
  312. package/dist/netlify-DLEOCFAD.js.map +0 -1
  313. package/dist/node-QXYSUWQ4.js +0 -10
  314. package/dist/registry-S7OMF3OS.js +0 -23
  315. package/dist/start-25OV2CAK.js.map +0 -1
  316. package/dist/static-RTO637XW.js.map +0 -1
  317. package/dist/theo-cloud-UZ3GINRU.js.map +0 -1
  318. package/dist/vercel-6D6EZUVD.js +0 -133
  319. package/dist/vercel-6D6EZUVD.js.map +0 -1
  320. package/dist/vite-plugin-RJFKLF2U.js +0 -36
  321. /package/dist/{chunk-WPJOTQA5.js.map → adapters/agent-mount.js.map} +0 -0
  322. /package/dist/{agent-XAQCUQNB.js.map → agent-7IPEVCAY.js.map} +0 -0
  323. /package/dist/{check-45NKUVSQ.js.map → check-GIPZBFTX.js.map} +0 -0
  324. /package/dist/{chunk-47CINLWF.js.map → chunk-EDWEYQRG.js.map} +0 -0
  325. /package/dist/{chunk-ZB7D62OA.js.map → chunk-KUZVRJ7M.js.map} +0 -0
  326. /package/dist/{chunk-DS5MCU2X.js.map → chunk-URCXSUI3.js.map} +0 -0
  327. /package/dist/{internal-api-ZCJWJ5EC.js.map → chunk-YSJOZEI6.js.map} +0 -0
  328. /package/dist/{dev-emit-GWD6IXV7.js.map → dev-emit-BFNMDCPB.js.map} +0 -0
  329. /package/dist/{internal-api-FBK2YXSI.js.map → internal-api-4X6NDS2F.js.map} +0 -0
  330. /package/dist/{load-config-FIWNKOJO.js.map → load-config-4ATXQUN3.js.map} +0 -0
  331. /package/dist/{mcp-KTYP4ZON.js.map → mcp-IQRHFP3Y.js.map} +0 -0
  332. /package/dist/{node-QXYSUWQ4.js.map → node-OSVPYQ3D.js.map} +0 -0
  333. /package/dist/{scan-7MJC6PYU.js.map → observability-bootstrap-LERYDHKY.js.map} +0 -0
  334. /package/dist/{registry-S7OMF3OS.js.map → registry-KBZDCFVQ.js.map} +0 -0
  335. /package/dist/{schema-DNIT7JQX.js.map → scan-YJEE4KQK.js.map} +0 -0
  336. /package/dist/{vite-plugin-RJFKLF2U.js.map → schema-SOAD43RQ.js.map} +0 -0
  337. /package/dist/{services-typed-client-P4JERLBL.js.map → services-typed-client-XGT5SUUN.js.map} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/adapters/deployed-cors.ts","../src/adapters/deployed-csrf.ts","../src/adapters/deployed-runtime-config.ts","../src/adapters/deployed-trace.ts","../src/adapters/security-headers.ts"],"sourcesContent":["/**\n * The CORS configuration a deployed entry carries, baked at build time.\n *\n * ## The defect this closes\n *\n * `security.cors` reached exactly one consumer: Vite's `configureServer` hook. So an app that\n * worked cross-origin under `theokit dev` stopped working the moment anything else served it —\n * `theokit start` (fixed separately) and all six Web deploy targets (usetheokit/theokit#409). Same\n * config, same code, no error and no warning; the failure surfaces in a browser as a blocked fetch\n * on the deployed URL, three layers from the key that had quietly stopped being read.\n *\n * The pure half was written twice and called once: `createCorsWebHandler` — the Web mirror — had no\n * caller anywhere in the repository. Nothing here reimplements it.\n *\n * ## A callback origin is REFUSED, not silently dropped\n *\n * `corsSchema.origins` accepts `z.function(...)` alongside the string / RegExp / array shapes. A\n * deployed function has no `theo.config.ts` to read, and there is no literal for a closure — so a\n * build that baked only the serialisable shapes would produce an app whose CORS silently allowed\n * nothing, which is the exact class of failure this issue reports.\n *\n * `rules/three-target-parity.md` § 3 is explicit about the alternative: \"a target that cannot serve\n * a capability refuses by name. Silent degradation is the failure mode this rule exists to\n * prevent.\" So the build throws, naming the target, the key and the two ways forward.\n */\nimport type { TheoConfig } from '../config/schema.js'\n\ntype CorsConfig = NonNullable<NonNullable<TheoConfig['security']>['cors']>\n\n/**\n * The CORS slice of an adapter's build options.\n *\n * Narrow and named once, matching how `securityHeaders` and `DeployedCsrfOptions` already reach the\n * emitters: each renderer receives what it uses, and six signatures name one type instead of six\n * inline shapes that can drift.\n */\nexport interface DeployedCorsOptions {\n cors?: CorsConfig\n}\n\n/**\n * Thrown at BUILD time when the declared CORS cannot be carried to a deployed target.\n *\n * A build error is the point: the alternative is a deploy that looks configured and refuses every\n * cross-origin request, discovered by a browser rather than by the build.\n */\nexport class UnserializableCorsOriginError extends Error {\n constructor(target: string) {\n super(\n `security.cors.origins is a function, and the \\`${target}\\` target cannot carry it: a deployed ` +\n `function has no theo.config.ts to read, and a callback cannot be written into the emitted ` +\n `entry. Replace it with the origin, a RegExp, or an array of either — all of which travel — ` +\n `or build for \\`node\\` and run \\`theokit start\\`, which evaluates the callback at runtime.`,\n )\n this.name = 'UnserializableCorsOriginError'\n }\n}\n\n/** Source text for one origin matcher: a RegExp as a literal, anything else as JSON. */\nfunction renderOrigin(origin: unknown, target: string): string {\n if (typeof origin === 'function') throw new UnserializableCorsOriginError(target)\n if (origin instanceof RegExp) return String(origin)\n if (Array.isArray(origin)) return `[${origin.map((o) => renderOrigin(o, target)).join(', ')}]`\n return JSON.stringify(origin)\n}\n\n/**\n * Source text for the CORS config, or `undefined` when the app declared none.\n *\n * RegExp entries are emitted as regex literals for the reason `deployed-csrf.ts` gives at length:\n * `JSON.stringify` renders a RegExp as `{}`, and `matchesOrigin` checks `instanceof RegExp`, so a\n * JSON-rendered origin would sit in the emitted file looking configured and matching nothing.\n *\n * @throws UnserializableCorsOriginError when `origins` is a callback\n */\nexport function renderDeployedCorsLiteral(cors: CorsConfig | undefined, target: string): string {\n if (cors === undefined) return 'undefined'\n\n const parts = [`origins: ${renderOrigin(cors.origins, target)}`]\n if (cors.methods !== undefined) parts.push(`methods: ${JSON.stringify(cors.methods)}`)\n if (cors.allowedHeaders !== undefined)\n parts.push(`allowedHeaders: ${JSON.stringify(cors.allowedHeaders)}`)\n if (cors.exposedHeaders !== undefined)\n parts.push(`exposedHeaders: ${JSON.stringify(cors.exposedHeaders)}`)\n // Both carry schema defaults, so they are always present and always emitted — unlike the\n // optional fields above, whose absence is a real answer the handler already has one for.\n parts.push(\n `credentials: ${JSON.stringify(cors.credentials)}`,\n `maxAge: ${JSON.stringify(cors.maxAge)}`,\n )\n\n return `{ ${parts.join(', ')} }`\n}\n\n/**\n * The lines that declare the CORS handler in a generated entry.\n *\n * `null` when nothing was declared, which is what \"no cors block\" meant before and still means: no\n * headers, not permissive ones.\n */\nexport function deployedCorsFragment(cors: CorsConfig | undefined, target: string): string[] {\n return [\n `// #409 — the CORS the app declared, carried as a literal because a deployed function has no`,\n `// theo.config.ts to read. \\`null\\` when the app declared none: no headers, not permissive ones.`,\n `const CORS_CONFIG = ${renderDeployedCorsLiteral(cors, target)}`,\n `const CORS_HANDLER = CORS_CONFIG === undefined ? null : createCorsWebHandler(CORS_CONFIG)`,\n ``,\n `/** Answer a preflight before routing — an OPTIONS the router handles never gets a CORS answer. */`,\n `function corsPreflight(request) {`,\n ` return CORS_HANDLER === null ? null : CORS_HANDLER.handlePreflightRequest(request)`,\n `}`,\n ``,\n `/** Put the headers on whatever the app answered, including its 404s — a browser reads a 404`,\n ` * without them as a CORS failure rather than as the 404 it is. */`,\n `function withCors(request, response) {`,\n ` if (CORS_HANDLER !== null) CORS_HANDLER.applyCorsHeaders(request, response.headers)`,\n ` return response`,\n `}`,\n ]\n}\n","/**\n * The CSRF configuration a deployed entry carries, baked at build time.\n *\n * ## The defect this closes\n *\n * The six Web-standards adapter entries built `executeRoute`'s context from an eight-field\n * literal, and neither `csrfMode` nor `disallowed` was among the eight (usetheokit/theokit#410).\n * `executeRoute` defaults an absent mode to `'strict'`, so an app declaring\n * `security: { csrf: 'off' }` — or `'warn'` — got `'strict'` on every deploy target: a `POST` that\n * works under `theokit dev` and `theokit start` answers `403 CSRF_INVALID` on Vercel, naming a\n * mechanism the operator had switched off. The config still validated and the build still\n * succeeded; the behaviour simply changed.\n *\n * The deployed function has no `theo.config.ts` to read, which is why the value is carried as a\n * literal — the same shape `security.headers` already uses (`renderSecurityHeadersConfigLiteral`).\n *\n * ## Why this is not `JSON.stringify`\n *\n * `disallowed.routes` accepts RegExp entries (`config/schemas/security.ts`), and `JSON.stringify`\n * renders a RegExp as `{}`. That is not a formatting problem: `matchDisallowed` checks\n * `p instanceof RegExp`, so a `{}` matches nothing while reading, in the emitted file, as a rule\n * that is present and configured. Reaching for JSON here would reproduce this issue's own defect —\n * configuration that survives validation and quietly stops applying — one layer further down.\n */\nimport type { TheoConfig } from '../config/schema.js'\n\ntype SecurityConfig = NonNullable<TheoConfig['security']>\n\n/**\n * The two slices of `security` that reach `executeRoute`'s context.\n *\n * Narrow rather than the whole block, matching how `securityHeaders` is already passed: each\n * renderer receives what it uses and nothing else, so a headers change cannot reach the CSRF\n * literal and vice versa.\n */\nexport interface DeployedCsrfOptions {\n csrf?: SecurityConfig['csrf']\n disallowed?: SecurityConfig['disallowed']\n}\n\n/**\n * Source text for one route pattern.\n *\n * A RegExp is emitted as a regex literal so it arrives as a RegExp; a string goes through\n * `JSON.stringify`, which is the correct escaper for a JS string literal (quotes, backslashes,\n * control characters, line separators).\n */\nfunction renderRoutePattern(pattern: string | RegExp): string {\n return pattern instanceof RegExp ? String(pattern) : JSON.stringify(pattern)\n}\n\n/**\n * Source text for the CSRF slice of `executeRoute`'s context.\n *\n * Absent values are OMITTED rather than defaulted. `executeRoute` already defaults an absent\n * `csrfMode` to `'strict'`, and writing `'strict'` here would put that default in a second place\n * where the two can disagree — which is the class of drift the whole issue is about.\n *\n * @param security - the declared csrf slices, or `undefined` when the app declared no security block\n */\nexport function renderDeployedCsrfLiteral(security: DeployedCsrfOptions | undefined): string {\n if (security === undefined) return '{}'\n\n const parts: string[] = []\n if (security.csrf !== undefined) parts.push(`csrfMode: ${JSON.stringify(security.csrf)}`)\n\n const { disallowed } = security\n if (disallowed !== undefined) {\n const routes = disallowed.routes.map(renderRoutePattern).join(', ')\n parts.push(\n `disallowed: { routes: [${routes}], behavior: ${JSON.stringify(disallowed.behavior)} }`,\n )\n }\n\n // `{}` and not `{ }` when nothing was declared: the emitted file is read by people, and the\n // two-space version reads as though something was meant to be there.\n return parts.length === 0 ? '{}' : `{ ${parts.join(', ')} }`\n}\n\n/**\n * The lines that declare `CSRF_CONFIG` in a generated entry.\n *\n * One function rather than the same six lines pasted into each of the six adapters: that\n * duplication is how the eight-field context literal came to be wrong in six places at once, and\n * repeating the fix in the same shape would leave the next field with the same six places to be\n * forgotten in. It also keeps the two largest emitters under the `max-lines-per-function` ceiling,\n * which `vercel.ts` already extracts fragments to respect.\n *\n * @param opts - the declared csrf slices, passed straight through from the adapter's build options\n * @param home - what the target has instead of a config file, for the comment's second sentence\n */\nexport function deployedCsrfFragment(\n opts: DeployedCsrfOptions,\n home = 'a deployed function',\n): string[] {\n return [\n `// #410 — the CSRF mode and per-route escalation the app declared. Carried as a`,\n `// literal for the same reason as the headers above: ${home} has no theo.config.ts`,\n `// to read. Absent keys stay absent so executeRoute's own default ('strict') applies,`,\n `// rather than this file becoming a second place it can drift.`,\n `const CSRF_CONFIG = ${renderDeployedCsrfLiteral(opts)}`,\n ]\n}\n","/**\n * The configuration a deployed entry could not apply (usetheokit/theokit#425).\n *\n * ## Why this is not another literal renderer\n *\n * `deployed-csrf.ts` and `deployed-cors.ts` bake their values into the emitted source, which works\n * because `csrf` is an enum and `disallowed` is a `{ routes, behavior }` object — plain data, and a\n * deployed function has no `theo.config.ts` to read.\n *\n * The two concerns left over from #410 turn out to be different from each other, and the difference\n * is the whole design:\n *\n * - **`serialization` is plain data too.** The config field is `z.enum(['json', 'superjson'])`\n * (`config/schema.ts:147`) — a selector, not a transformer. `resolveTransformer` turns it into the\n * functions, and it already ships from `theokit/server`. So this half is a literal like the rest,\n * and the deployed entry resolves it exactly the way `theokit start` does\n * (`cli/commands/start/index.ts:108`), from the same string, through the same function.\n * - **`plugins` genuinely carries functions.** A plugin is constructed in `theo.config.ts` and there\n * is no literal for a closure, so this half needs the entry to import a module instead.\n *\n * ## Static import, not `import()` in the request path\n *\n * The tempting shortcut is `await import('../../theo.config.js')` inside the handler. It trades a\n * silent failure for a louder one on targets with no filesystem, and it moves configuration\n * resolution into every request on the targets that do have one.\n *\n * What this emits instead is a TOP-LEVEL import of a module the build already resolved and wrote\n * beside the entry — the same shape `renderBakedRoutes` uses for route modules (#369): decide on\n * the build machine, emit a static specifier. It is evaluated once at module load, the target's\n * bundler can see through it, and a plugin that needs an API the target lacks fails the build\n * rather than the first request.\n *\n * ## Why each half is optional\n *\n * An app that declares neither concern must produce the entry it produced before this existed.\n * Importing a module the build did not emit fails at load, and spreading an empty object costs an\n * allocation per request for nothing. So an empty request renders to nothing at all, and the\n * caller's `executeRoute` literal is unchanged.\n *\n * The halves are independent on purpose: an app that only picks `superjson` must not be made to\n * carry a plugins module, and an app with plugins and default JSON must not gain a transformer\n * lookup. Coupling them would have made the common case pay for the rare one.\n */\n\n/**\n * The option every Web-standards adapter grows to carry non-serialisable configuration.\n *\n * Composed into each adapter's option type the way `DeployedCsrfOptions` already is, so the six\n * targets cannot drift into six spellings of the same field.\n */\nexport interface DeployedRuntimeConfigOptions {\n /**\n * Specifier of the plugins module the build wrote beside the entry, or `undefined` when the app\n * declares no plugins and the build wrote none.\n */\n runtimeConfigModule?: string\n /**\n * The app's `serialization` selector, carried as a literal.\n *\n * `'json'` and `undefined` both mean the default, and neither emits anything: `executeRoute`\n * already falls back to `JSON.stringify`, and the `x-theo-transformer` header is deliberately\n * absent for the default so a client is told only when there is something to be told.\n */\n serialization?: 'json' | 'superjson'\n}\n\n/** The three places an entry has to grow to carry non-serialisable configuration. */\nexport interface DeployedRuntimeConfigFragment {\n /** Top-level imports. Empty when the build emitted no config module. */\n readonly imports: string[]\n /** Module-scope declarations — evaluated once, at load. Empty when there is nothing to carry. */\n readonly declarations: string[]\n /**\n * Spread into the entry's `executeRoute({ … })` literal, inside an async function.\n *\n * Empty string when there is nothing to carry, so the call site keeps the exact shape it had.\n */\n readonly executeRouteSpread: string\n}\n\nconst EMPTY: DeployedRuntimeConfigFragment = {\n imports: [],\n declarations: [],\n executeRouteSpread: '',\n}\n\n/**\n * What a deployed entry needs in order to apply `config.plugins` and `config.serialization`.\n *\n * @param moduleSpecifier - specifier of the runtime-config module the build emitted beside the\n * entry, or `undefined` when the app declared neither concern and the build emitted none.\n */\nexport function deployedRuntimeConfigFragment(\n options: DeployedRuntimeConfigOptions | undefined,\n): DeployedRuntimeConfigFragment {\n const pluginsModule = options?.runtimeConfigModule\n // 'json' is the default and emits nothing — see `serialization` above.\n const serialization = options?.serialization === 'superjson' ? 'superjson' : undefined\n if (pluginsModule === undefined && serialization === undefined) return EMPTY\n\n const imports: string[] = []\n const declarations: string[] = []\n const spread: string[] = []\n\n if (pluginsModule !== undefined) {\n imports.push(\n `import { createPluginRunnerFromConfig } from 'theokit/server'`,\n `// #425 — the app's own plugins, resolved on the build machine and written beside this entry.`,\n `// A closure has no literal, so this is an import rather than a baked value.`,\n `import theoRuntimeConfig from '${pluginsModule}'`,\n )\n declarations.push(\n `// Built ONCE, at module load. A runner rebuilt per request would re-run every plugin's`,\n `// \\`register\\`, which is where a plugin allocates the state its hooks then read.`,\n `const THEO_PLUGIN_RUNNER = createPluginRunnerFromConfig(theoRuntimeConfig.plugins)`,\n )\n // Awaited, not passed along: `createPluginRunnerFromConfig` is async because `register` is, and\n // a pending promise handed to `executeRoute` is a truthy object with none of the runner's\n // methods — every hook would silently not fire, which is this issue's own defect one layer in.\n spread.push(`pluginRunner: await THEO_PLUGIN_RUNNER`)\n }\n\n if (serialization !== undefined) {\n imports.push(`import { resolveTransformer } from 'theokit/server'`)\n declarations.push(\n `// #425 — a literal, because \\`config.serialization\\` is a SELECTOR and not a transformer.`,\n `// Same string, same function \\`theokit start\\` calls, so the deployed response and the local`,\n `// one cannot disagree about what the app asked for — including the \\`x-theo-transformer\\``,\n `// header, whose absence is what made this a data bug rather than a formatting one.`,\n `const THEO_TRANSFORMER = resolveTransformer('${serialization}')`,\n )\n spread.push(`transformer: THEO_TRANSFORMER`)\n }\n\n return { imports, declarations, executeRouteSpread: `${spread.join(', ')},` }\n}\n","/**\n * The request id a deployed entry uses, and the header it echoes back.\n *\n * ## The defect this closes\n *\n * Every generated entry minted a fresh `randomUUID()` per request and set no correlation header\n * at all on a success path (usetheokit/theokit#410). Both Node paths do the opposite: they resolve\n * an incoming `traceparent` / `x-request-id` through `extractTraceId` and echo the result under\n * both `x-request-id` and `x-trace-id` (`cli/commands/start/request-handler.ts`,\n * `vite-plugin/api-middleware.ts`).\n *\n * The consequence is that a trace crossing into a deployed function starts over. The caller's id\n * is discarded, and the response carries nothing to correlate against — so a request that fails in\n * production cannot be tied to the client that made it, which is the one situation the id exists\n * for.\n *\n * ## Why `setHeader` before the handler, rather than wrapping the response\n *\n * It is what the Node path does, and the shim reproduces Node's semantics exactly: `writeHead`\n * MERGES into the header map rather than replacing it (`web-shim.ts`), so a header set here\n * survives the handler's own `writeHead` and a handler that sets its own id still wins. Wrapping\n * the finished `Response` instead would have to mutate a response whose body is already streaming\n * (#382), and would miss the branches that return before the shim is built.\n */\n\n/**\n * Lines that resolve the request id and echo it, as generated source.\n *\n * @param requestVar - the name the entry gave the Web `Request` in scope\n * @param indent - leading whitespace, so the emitted file stays readable\n */\nexport function deployedTraceFragment(requestVar: string, indent: string): string[] {\n return [\n `${indent}// #410 — honour the caller's trace id instead of minting a new one, and echo it.`,\n `${indent}// \\`extractTraceIdFromRequest\\` validates the caller-controlled \\`x-request-id\\``,\n `${indent}// before trusting it, and falls back to a fresh UUID when neither header is present.`,\n `${indent}const requestId = extractTraceIdFromRequest(${requestVar})`,\n `${indent}res.setHeader('x-request-id', requestId)`,\n `${indent}res.setHeader(TRACE_HEADER, requestId)`,\n ]\n}\n","/**\n * The security headers a deployed target puts on its responses.\n *\n * `theokit start` applies the configured baseline to every response it writes\n * (`cli/commands/start/request-handler.ts`). None of the six Web-standards\n * deploy adapters applied any, so the same page carried a CSP,\n * `X-Frame-Options`, HSTS and `nosniff` under `theokit start` and none of them\n * once deployed (usetheokit/theokit#410, GHSA-87qq-fgcr-384x).\n *\n * This module is the seam that closes that half of the gap. It has two halves\n * and they live together on purpose: the code that writes the literal into a\n * generated entry and the code that reads it at request time have to agree on\n * one shape, and a shape stated in two files drifts.\n *\n * - **Build time** — {@link renderSecurityHeadersConfigLiteral} turns\n * `security.headers` into a JSON literal the adapter inlines. A deployed\n * runtime has no `theo.config.ts` to read, so the configuration travels as\n * data.\n * - **Request time** — the generated entry calls {@link buildSecurityHeaders}\n * on that literal and hands every response to {@link withSecurityHeaders}.\n * The same function `theokit start` calls, on the same input, so the two\n * cannot disagree about what the configuration means.\n *\n * ## The per-request nonce, and where it stops\n *\n * `buildSecurityHeaders` accepts a per-request `nonce` and substitutes it into\n * `script-src`. A nonce cannot survive a build-time literal — it is minted per\n * response — so a target reaches one only if it renders the HTML at request\n * time and can put the same value on the script tags it emits.\n *\n * Exactly one deploy path does: **Cloudflare with `ssrStreaming: true`**, whose\n * worker calls `renderStreamingWeb(request, { nonce })`, and that renderer\n * threads the value into `renderToReadableStream` and into the hydration script\n * (`router/entry-server.ts`). That branch mints a nonce per request and builds\n * its CSP from it. Everything else serves HTML written at build time, or no\n * HTML at all, and carries a **nonce-less CSP** — the same answer\n * `buildSecurityHeaders` already gives a prerendered route (EC-4), for the same\n * reason: a nonce in the header with no nonce on the tag blocks every inline\n * script.\n *\n * That asymmetry is real and is not smoothed over. It is stated in the emitted\n * entry, printed by the build through\n * {@link describeDeployedSecurityHeaders}, and written down in\n * `docs/surfaces/build-adapters.md`.\n */\nimport { generateNonce } from '../core/contracts/nonce.js'\nimport type { SecurityHeadersConfig } from '../core/contracts/security-headers.js'\nimport { buildSecurityHeaders } from '../core/contracts/security-headers.js'\n\n/**\n * Re-exported so a generated entry has ONE import for the whole concern.\n *\n * Reaching it through `theokit/server/security` would work and would also drag\n * that barrel's CSRF surface into a Worker bundle, for a function that is forty\n * lines of string concatenation. It is defined in `core/contracts/`, which is\n * the module every target may import from — `adapters → server` is not an edge\n * in the DAG, and the header policy was never server code.\n */\nexport { buildSecurityHeaders }\n\n/**\n * Re-exported for the same reason, and so the streamed Cloudflare worker mints\n * its nonce with the identical primitive `theokit start` uses\n * (`cli/commands/start/request-handler.ts`) rather than a second, hand-rolled\n * one. It is already runtime-portable: Web Crypto first, with a named error\n * when the runtime has none.\n */\nexport { generateNonce }\n\n/**\n * The `security.headers` block, as a literal a generated entry can carry.\n *\n * `{}` when the app declares none — which is not the same as \"no headers\".\n * `buildSecurityHeaders({})` returns the full default baseline, and `{}` is\n * exactly what `theokit start` passes when `security.headers` is absent\n * (`cli/commands/start/index.ts`). An app with no security block gets the same\n * baseline deployed as it gets locally.\n */\nexport function renderSecurityHeadersConfigLiteral(\n headers: SecurityHeadersConfig | undefined,\n): string {\n return JSON.stringify(headers ?? {})\n}\n\n/**\n * Put the headers on a response, without overruling the handler.\n *\n * `theokit start` sets the baseline BEFORE the route handler runs, so a handler\n * can override it with `res.setHeader` (last write wins, Node convention). On a\n * Web target the response arrives already built, so the equivalent of \"the\n * handler wins\" is to skip a header the response already carries: a route that\n * set its own `Content-Security-Policy` keeps it.\n *\n * Mutates and returns the same `Response` rather than constructing a\n * replacement, because these responses are handed to the runtime while their\n * body is still being written (#382) and re-wrapping the stream is exactly the\n * second buffering point that change removed.\n *\n * Mutation is safe for every response these entries produce: the Fetch spec\n * gives a locally constructed `Response` the `response` header guard, which\n * permits `set` for every name used here. The `immutable` guard belongs to\n * responses that came back from `fetch()`, and none of the six emitted handlers\n * returns one — each builds its response from `createWebShim`, from a `new\n * Response(...)`, or from the SSR renderer. The WebSocket upgrade, which is the\n * one response an adapter gets from its runtime rather than building, is\n * deliberately not routed through here.\n */\nexport function withSecurityHeaders(response: Response, headers: Record<string, string>): Response {\n for (const [key, value] of Object.entries(headers)) {\n if (!response.headers.has(key)) response.headers.set(key, value)\n }\n return response\n}\n\nexport interface DeployedSecurityHeaderLimits {\n target: string\n /** The app's `security.headers` block, or undefined when it declares none. */\n securityHeaders: SecurityHeadersConfig | undefined\n /**\n * Does the emitted handler render HTML at request time and mint a CSP nonce\n * for it? True only for Cloudflare with `ssrStreaming: true`.\n */\n mintsNonce: boolean\n /**\n * Is the HTML document served by a platform static host rather than by the\n * handler this build emits? True wherever the emitted handler answers\n * `/api/*` and returns 404 for everything else.\n */\n /**\n * Who puts the security headers on the HTML DOCUMENT — a different question from who serves it,\n * and the two used to be collapsed into one boolean (usetheokit/theokit#412).\n *\n * - `handler` — this target's own handler returns the document, so it carries the same baseline\n * every API response carries. No caveat.\n * - `platform-configured` — the platform's static host serves the document, AND this build emits\n * the configuration that puts the headers on it (`.vercel/output/config.json`, `netlify.toml`).\n * Still worth stating, because nothing here has seen a deployed response.\n * - `platform-unmanaged` — the platform serves it and this build owns no artifact that could\n * configure it. This is the real remaining gap, and it stays named.\n *\n * The two-value version reported `platform-configured` targets with the same message as\n * `platform-unmanaged` ones, telling an operator to go and do work the build had already done —\n * and a stale limitation reads exactly like a current one.\n */\n documentHeaders: 'handler' | 'platform-configured' | 'platform-unmanaged'\n}\n\n/**\n * What the build tells the operator, once, per target.\n *\n * Silent degradation is the failure mode `rules/three-target-parity.md` exists\n * to prevent. Two things degrade quietly here and both are named rather than\n * discovered in production: a CSP that refuses inline scripts on a deploy while\n * allowing them locally, and an HTML document that never passes through the\n * handler these headers are attached to.\n *\n * The header names are read from the map the entry will actually carry, not\n * from a list written next to it. A configuration that switches HSTS or the CSP\n * off would otherwise be announced as sending them.\n */\nexport function describeDeployedSecurityHeaders(limits: DeployedSecurityHeaderLimits): string {\n const headers = buildSecurityHeaders(limits.securityHeaders ?? {}, { production: true })\n const names = Object.keys(headers)\n if (names.length === 0) {\n return ` ! \\`${limits.target}\\` sends no security headers: the configuration switched every one of them off.`\n }\n\n const lines = [\n ` ✓ security headers on every response \\`${limits.target}\\` returns: ${names.join(', ')}.`,\n ]\n const sendsCsp = names.some((name) => name.startsWith('Content-Security-Policy'))\n if (sendsCsp && !limits.mintsNonce) {\n lines.push(\n ` - The CSP carries no nonce: this target serves HTML written at build time,`,\n ` so there is no per-request value to put on a script tag. An inline`,\n ` <script> is refused by \\`script-src 'self'\\` here, while the same page`,\n ` under \\`theokit start\\` gets a nonce and runs it. Move inline scripts to`,\n ` \\`<script src=\"...\">\\`, or set \\`security.headers.cspMode: 'report-only'\\``,\n ` while you migrate.`,\n )\n }\n if (limits.documentHeaders === 'platform-configured') {\n lines.push(\n ` - The HTML document is served by the platform's static host, and reaches`,\n ` the browser with these headers through config this build emits. That`,\n ` path is not verified by a deploy from here — the values come from the`,\n ` same function the handler uses, but no response has been read back.`,\n )\n }\n if (limits.documentHeaders === 'platform-unmanaged') {\n lines.push(\n ` - The HTML document does NOT pass through this handler — the platform's`,\n ` static host serves it — so these headers reach \\`/api/*\\` responses and`,\n ` not the page. This build emits no artifact that could configure it, so`,\n ` set the document's headers on the platform (usetheokit/theokit#412).`,\n )\n }\n return lines.join('\\n')\n}\n"],"mappings":";;;;;;;AA8CO,IAAM,gCAAN,cAA4C,MAAM;AAAA,EACvD,YAAY,QAAgB;AAC1B;AAAA,MACE,kDAAkD,MAAM;AAAA,IAI1D;AACA,SAAK,OAAO;AAAA,EACd;AACF;AAGA,SAAS,aAAa,QAAiB,QAAwB;AAC7D,MAAI,OAAO,WAAW,WAAY,OAAM,IAAI,8BAA8B,MAAM;AAChF,MAAI,kBAAkB,OAAQ,QAAO,OAAO,MAAM;AAClD,MAAI,MAAM,QAAQ,MAAM,EAAG,QAAO,IAAI,OAAO,IAAI,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,EAAE,KAAK,IAAI,CAAC;AAC3F,SAAO,KAAK,UAAU,MAAM;AAC9B;AAWO,SAAS,0BAA0B,MAA8B,QAAwB;AAC9F,MAAI,SAAS,OAAW,QAAO;AAE/B,QAAM,QAAQ,CAAC,YAAY,aAAa,KAAK,SAAS,MAAM,CAAC,EAAE;AAC/D,MAAI,KAAK,YAAY,OAAW,OAAM,KAAK,YAAY,KAAK,UAAU,KAAK,OAAO,CAAC,EAAE;AACrF,MAAI,KAAK,mBAAmB;AAC1B,UAAM,KAAK,mBAAmB,KAAK,UAAU,KAAK,cAAc,CAAC,EAAE;AACrE,MAAI,KAAK,mBAAmB;AAC1B,UAAM,KAAK,mBAAmB,KAAK,UAAU,KAAK,cAAc,CAAC,EAAE;AAGrE,QAAM;AAAA,IACJ,gBAAgB,KAAK,UAAU,KAAK,WAAW,CAAC;AAAA,IAChD,WAAW,KAAK,UAAU,KAAK,MAAM,CAAC;AAAA,EACxC;AAEA,SAAO,KAAK,MAAM,KAAK,IAAI,CAAC;AAC9B;AAQO,SAAS,qBAAqB,MAA8B,QAA0B;AAC3F,SAAO;AAAA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UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACA,MAAI,OAAO,oBAAoB,uBAAuB;AACpD,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACA,MAAI,OAAO,oBAAoB,sBAAsB;AACnD,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACA,SAAO,MAAM,KAAK,IAAI;AACxB;","names":[]}
@@ -2,7 +2,7 @@
2
2
  import "tsx/esm";
3
3
  import {
4
4
  findControllerFiles
5
- } from "./chunk-T5C46IIU.js";
5
+ } from "./chunk-FMTRNQQ7.js";
6
6
 
7
7
  // src/cli/commands/build/emit-controllers.ts
8
8
  import { mkdirSync, readFileSync, writeFileSync } from "fs";
@@ -43,4 +43,4 @@ export {
43
43
  emitControllerArtifacts,
44
44
  describeControllerArtifacts
45
45
  };
46
- //# sourceMappingURL=chunk-47CINLWF.js.map
46
+ //# sourceMappingURL=chunk-EDWEYQRG.js.map
@@ -0,0 +1,110 @@
1
+ #!/usr/bin/env node
2
+ import "tsx/esm";
3
+ import {
4
+ MissingAgentPolicyError,
5
+ createFileStampCache,
6
+ walkSourceFiles
7
+ } from "./chunk-FD4ZDTQ6.js";
8
+
9
+ // src/server/scan/agent-scan.ts
10
+ import { existsSync, readFileSync, statSync } from "fs";
11
+ import { extname, join, relative } from "path";
12
+
13
+ // src/server/scan/detect-agent-policy.ts
14
+ import { createRequire } from "module";
15
+ var require_ = createRequire(import.meta.url);
16
+ var ts = require_("typescript");
17
+ var POLICY_EXPORT = "policy";
18
+ function hasExportModifier(modifiers) {
19
+ if (!modifiers) return false;
20
+ for (const m of modifiers) {
21
+ if (m.kind === ts.SyntaxKind.ExportKeyword) return true;
22
+ }
23
+ return false;
24
+ }
25
+ function variableStatementDeclaresPolicy(stmt) {
26
+ if (!hasExportModifier(ts.getModifiers(stmt))) return false;
27
+ return stmt.declarationList.declarations.some(
28
+ (decl) => ts.isIdentifier(decl.name) && decl.name.text === POLICY_EXPORT
29
+ );
30
+ }
31
+ function exportDeclarationDeclaresPolicy(stmt) {
32
+ if (!stmt.exportClause || !ts.isNamedExports(stmt.exportClause)) return false;
33
+ return stmt.exportClause.elements.some((spec) => spec.name.text === POLICY_EXPORT);
34
+ }
35
+ function functionDeclarationDeclaresPolicy(stmt) {
36
+ return hasExportModifier(ts.getModifiers(stmt)) && stmt.name?.text === POLICY_EXPORT;
37
+ }
38
+ function declaresAgentPolicy(filePath, content) {
39
+ const sourceFile = ts.createSourceFile(
40
+ filePath,
41
+ content,
42
+ ts.ScriptTarget.Latest,
43
+ /* setParentNodes */
44
+ false,
45
+ ts.ScriptKind.TS
46
+ );
47
+ for (const stmt of sourceFile.statements) {
48
+ if (ts.isVariableStatement(stmt) && variableStatementDeclaresPolicy(stmt)) return true;
49
+ if (ts.isExportDeclaration(stmt) && exportDeclarationDeclaresPolicy(stmt)) return true;
50
+ if (ts.isFunctionDeclaration(stmt) && functionDeclarationDeclaresPolicy(stmt)) return true;
51
+ }
52
+ return false;
53
+ }
54
+
55
+ // src/server/scan/agent-scan.ts
56
+ var AGENT_EXTENSIONS = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx"]);
57
+ var TEST_FILE = /\.(test|spec)$/;
58
+ var AGENT_SUBFOLDERS = /* @__PURE__ */ new Set([
59
+ "tools",
60
+ "skills",
61
+ "prompts",
62
+ "lib",
63
+ "hooks",
64
+ "channels",
65
+ "connections",
66
+ "subagents",
67
+ "schedules",
68
+ "sandbox",
69
+ "workflows",
70
+ "evals",
71
+ "memory"
72
+ ]);
73
+ function scanAgents(projectRoot, agentsDirName = "agents") {
74
+ const agentsDir = join(projectRoot, agentsDirName);
75
+ if (!existsSync(agentsDir) || !statSync(agentsDir).isDirectory()) {
76
+ return [];
77
+ }
78
+ const results = [];
79
+ walkSourceFiles(agentsDir, { extensions: AGENT_EXTENSIONS }, (absPath) => {
80
+ let rel = relative(agentsDir, absPath);
81
+ rel = rel.replace(/\\/g, "/");
82
+ rel = rel.slice(0, -extname(rel).length);
83
+ if (TEST_FILE.test(rel)) return;
84
+ const dirs = rel.split("/").slice(0, -1);
85
+ if (dirs.some((segment) => AGENT_SUBFOLDERS.has(segment))) return;
86
+ if (rel.endsWith("/index")) rel = rel.slice(0, -6);
87
+ if (rel === "index" || rel === "") return;
88
+ const agentPath = `/api/agents/${rel}`;
89
+ assertAgentDeclaresPolicy(absPath, agentPath);
90
+ results.push({
91
+ filePath: absPath,
92
+ agentPath,
93
+ name: rel
94
+ });
95
+ });
96
+ return results;
97
+ }
98
+ var policyDeclarationCache = createFileStampCache();
99
+ function assertAgentDeclaresPolicy(filePath, agentPath) {
100
+ const declared = policyDeclarationCache.get(
101
+ filePath,
102
+ () => declaresAgentPolicy(filePath, readFileSync(filePath, "utf8"))
103
+ );
104
+ if (!declared) throw new MissingAgentPolicyError({ file: filePath, agentPath });
105
+ }
106
+
107
+ export {
108
+ scanAgents
109
+ };
110
+ //# sourceMappingURL=chunk-EVZKNA2W.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/server/scan/agent-scan.ts","../src/server/scan/detect-agent-policy.ts"],"sourcesContent":["/* eslint-disable security/detect-non-literal-fs-filename --\n * Build-time scanner: walks `<projectRoot>/agents/` derived from cwd.\n * No HTTP input ever reaches these fs calls.\n */\nimport { existsSync, readFileSync, statSync } from 'node:fs'\nimport { extname, join, relative } from 'node:path'\n\nimport { walkSourceFiles } from '../_internal/scan-walker.js'\n\nimport { declaresAgentPolicy } from './detect-agent-policy.js'\nimport { MissingAgentPolicyError } from './errors.js'\nimport { createFileStampCache } from './file-stamp-cache.js'\n\nconst AGENT_EXTENSIONS = new Set(['.ts', '.tsx', '.js', '.jsx'])\n// Convention § 5: a co-located test file is not an agent.\nconst TEST_FILE = /\\.(test|spec)$/\n\n/**\n * Folder-semantic discovery (Eve-style \"file = identity\"): an agent may be a self-contained folder that\n * co-locates its composition — `agents/<name>/{index.ts, tools/, skills/, prompts/, lib/}`. Files INSIDE\n * these conventional sub-folders are that concern (a tool, a skill, a prompt, a helper), NOT a routed\n * agent, so the scanner skips any file whose path passes through one of them. Only `<name>.ts` or\n * `<name>/index.ts` is served at `/api/agents/<name>`. A flat file literally named `tools.ts` is still a\n * valid agent (the reserved names only apply to intermediate DIRECTORIES, never the agent file itself).\n */\nconst AGENT_SUBFOLDERS = new Set([\n 'tools',\n 'skills',\n 'prompts',\n 'lib',\n 'hooks',\n 'channels',\n 'connections',\n 'subagents',\n 'schedules',\n 'sandbox',\n 'workflows',\n 'evals',\n 'memory',\n])\n\n/**\n * A discovered agent file. `name` is the client-facing key; `agentPath` is the mounted\n * SSE route (M0/M1 `UIMessageStream`).\n */\nexport interface AgentNode {\n filePath: string\n agentPath: string\n name: string\n}\n\n/**\n * M2 — scan the TOP-LEVEL `agents/` convention (sibling of `server/`, per the LOCKED naming\n * decision). Mirrors `scanWebSocketRoutes`: one file → one endpoint, `index` stripped.\n */\nexport function scanAgents(projectRoot: string, agentsDirName = 'agents'): AgentNode[] {\n // `agentsDirName` (config `agentsDir`, default \"agents\") — the dir holding `<name>.ts` agent\n // definitions, relative to the project root. May be nested (e.g. \"core/agents\"). (#95 follow-up)\n const agentsDir = join(projectRoot, agentsDirName)\n if (!existsSync(agentsDir) || !statSync(agentsDir).isDirectory()) {\n return []\n }\n\n const results: AgentNode[] = []\n walkSourceFiles(agentsDir, { extensions: AGENT_EXTENSIONS }, (absPath) => {\n let rel = relative(agentsDir, absPath)\n rel = rel.replace(/\\\\/g, '/')\n rel = rel.slice(0, -extname(rel).length)\n if (TEST_FILE.test(rel)) return\n // Eve-style: a file living under a composition sub-folder (tools/, skills/, prompts/, …) is that\n // concern, not a routed agent. Check the intermediate DIRECTORIES only — the agent file itself may\n // be named anything.\n const dirs = rel.split('/').slice(0, -1)\n if (dirs.some((segment) => AGENT_SUBFOLDERS.has(segment))) return\n // Unlike routes/ws, an agent needs an explicit name — a bare `agents/index.ts`\n // (name `''` → `/api/agents/`) is nonsensical for a typed `useAgent(name)` binding.\n // `agents/foo/index.ts` still collapses to `foo` (a named nested agent).\n if (rel.endsWith('/index')) rel = rel.slice(0, -6)\n if (rel === 'index' || rel === '') return\n const agentPath = `/api/agents/${rel}`\n assertAgentDeclaresPolicy(absPath, agentPath)\n results.push({\n filePath: absPath,\n agentPath,\n name: rel,\n })\n })\n return results\n}\n\n/**\n * Cache of the policy-declaration answer, keyed by path + mtime + size.\n *\n * `theokit dev` re-scans the agents directory on EVERY request, so parsing each agent file with the\n * TypeScript AST per request would turn a build-time check into per-request latency. Keying on the\n * file's own mtime and size means an edit invalidates the entry without anyone remembering to, and\n * a `theokit build` (one process, one scan) never notices the cache exists.\n */\nconst policyDeclarationCache = createFileStampCache<boolean>()\n\n/** Test seam — the module-level cache would otherwise outlive a fixture directory. */\nexport function _resetAgentPolicyCacheForTests(): void {\n policyDeclarationCache.clear()\n}\n\n/**\n * Refuse an agent file that declares no access policy (usetheokit/theokit#365).\n *\n * The refusal lives in the scanner, next to the reserved-name and empty-name refusals, because this\n * is the one place every entry point passes through: `theokit build`, `theokit start`, `theokit dev`\n * and the manifest generator all reach agents by calling `scanAgents`.\n *\n * The blast radius stops at the file system, exactly as it does for routes. A module handed to\n * `mountAgent` in memory — a test, an embedder, an `@Expose`d controller method — never passed a\n * scanner, and `admitAgentRequest` still treats an undeclared policy as \"not declared\" rather than\n * as denial. Absence is refused where an application DECLARES its agents, not where a caller passes\n * one.\n */\nfunction assertAgentDeclaresPolicy(filePath: string, agentPath: string): void {\n // The stamping and the `has`-vs-truthy subtlety moved into `createFileStampCache` (#417), where\n // the route scanner shares them rather than growing a second copy keyed \"the same way\".\n const declared = policyDeclarationCache.get(filePath, () =>\n declaresAgentPolicy(filePath, readFileSync(filePath, 'utf8')),\n )\n if (!declared) throw new MissingAgentPolicyError({ file: filePath, agentPath })\n}\n","/**\n * Does this agent file declare an access policy? (usetheokit/theokit#365)\n *\n * The sibling of `detect-route-policy.ts`, and deliberately the same instrument: the TypeScript\n * AST rather than a regex, because `// policy: ...` in a comment and the word `policy` in a doc\n * block are both things an agent file legitimately contains, and neither declares anything.\n *\n * ## What it looks for, and why it is simpler than the route detector\n *\n * A route file declares one policy PER exported HTTP method, so the route detector has to return a\n * set and reason about which method carried which config. An agent file is one agent, so the\n * question is a single yes or no: is there a top-level export named `policy`?\n *\n * ```ts\n * export const policy = 'public'\n * export const policy = ({ subject, params }) => requireOwner(subject, ownerOf(params.sessionId))\n * const policy = ...; export { policy }\n * export { agentPolicy as policy } from './shared' // ← also counts; see below\n * ```\n *\n * ## Where this is deliberately laxer than the route detector\n *\n * The route detector refuses `export { GET } from './shared'`, on the reasoning that it cannot see\n * whether the re-exported value declares a policy. Here there is nothing to look inside: the export\n * IS the policy, so a re-export names one as surely as a local const does. The value's SHAPE is\n * checked at runtime by `readAgentPolicy`, which throws on anything that is neither `'public'` nor\n * a function — so a wrong type fails loudly rather than being served open.\n */\nimport { createRequire } from 'node:module'\n\nimport type * as TS from 'typescript'\n\nconst require_ = createRequire(import.meta.url)\n\nconst ts = require_('typescript') as typeof TS\n\nconst POLICY_EXPORT = 'policy'\n\nfunction hasExportModifier(modifiers: readonly TS.Modifier[] | undefined): boolean {\n if (!modifiers) return false\n for (const m of modifiers) {\n if (m.kind === ts.SyntaxKind.ExportKeyword) return true\n }\n return false\n}\n\n/** `export const policy = ...` (also `let`/`var`, which are legal if unusual). */\nfunction variableStatementDeclaresPolicy(stmt: TS.VariableStatement): boolean {\n if (!hasExportModifier(ts.getModifiers(stmt))) return false\n return stmt.declarationList.declarations.some(\n (decl) => ts.isIdentifier(decl.name) && decl.name.text === POLICY_EXPORT,\n )\n}\n\n/** `export { policy }`, `export { p as policy }`, `export { p as policy } from './shared'`. */\nfunction exportDeclarationDeclaresPolicy(stmt: TS.ExportDeclaration): boolean {\n if (!stmt.exportClause || !ts.isNamedExports(stmt.exportClause)) return false\n return stmt.exportClause.elements.some((spec) => spec.name.text === POLICY_EXPORT)\n}\n\n/** `export function policy() {}` — a function declaration is a policy as much as a const is. */\nfunction functionDeclarationDeclaresPolicy(stmt: TS.FunctionDeclaration): boolean {\n return hasExportModifier(ts.getModifiers(stmt)) && stmt.name?.text === POLICY_EXPORT\n}\n\n/**\n * True when the file has a top-level export named `policy`.\n *\n * `content` is passed in rather than read here so the caller reads each file once — the same\n * contract `detectMethodsWithDeclaredPolicy` follows.\n */\nexport function declaresAgentPolicy(filePath: string, content: string): boolean {\n const sourceFile = ts.createSourceFile(\n filePath,\n content,\n ts.ScriptTarget.Latest,\n /* setParentNodes */ false,\n ts.ScriptKind.TS,\n )\n for (const stmt of sourceFile.statements) {\n if (ts.isVariableStatement(stmt) && variableStatementDeclaresPolicy(stmt)) return true\n if (ts.isExportDeclaration(stmt) && exportDeclarationDeclaresPolicy(stmt)) return true\n if (ts.isFunctionDeclaration(stmt) && functionDeclarationDeclaresPolicy(stmt)) return true\n }\n return false\n}\n"],"mappings":";;;;;;;;;AAIA,SAAS,YAAY,cAAc,gBAAgB;AACnD,SAAS,SAAS,MAAM,gBAAgB;;;ACuBxC,SAAS,qBAAqB;AAI9B,IAAM,WAAW,cAAc,YAAY,GAAG;AAE9C,IAAM,KAAK,SAAS,YAAY;AAEhC,IAAM,gBAAgB;AAEtB,SAAS,kBAAkB,WAAwD;AACjF,MAAI,CAAC,UAAW,QAAO;AACvB,aAAW,KAAK,WAAW;AACzB,QAAI,EAAE,SAAS,GAAG,WAAW,cAAe,QAAO;AAAA,EACrD;AACA,SAAO;AACT;AAGA,SAAS,gCAAgC,MAAqC;AAC5E,MAAI,CAAC,kBAAkB,GAAG,aAAa,IAAI,CAAC,EAAG,QAAO;AACtD,SAAO,KAAK,gBAAgB,aAAa;AAAA,IACvC,CAAC,SAAS,GAAG,aAAa,KAAK,IAAI,KAAK,KAAK,KAAK,SAAS;AAAA,EAC7D;AACF;AAGA,SAAS,gC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xE,QAAI,MAAM,SAAS,WAAW,OAAO;AACrC,UAAM,IAAI,QAAQ,OAAO,GAAG;AAC5B,UAAM,IAAI,MAAM,GAAG,CAAC,QAAQ,GAAG,EAAE,MAAM;AACvC,QAAI,UAAU,KAAK,GAAG,EAAG;AAIzB,UAAM,OAAO,IAAI,MAAM,GAAG,EAAE,MAAM,GAAG,EAAE;AACvC,QAAI,KAAK,KAAK,CAAC,YAAY,iBAAiB,IAAI,OAAO,CAAC,EAAG;AAI3D,QAAI,IAAI,SAAS,QAAQ,EAAG,OAAM,IAAI,MAAM,GAAG,EAAE;AACjD,QAAI,QAAQ,WAAW,QAAQ,GAAI;AACnC,UAAM,YAAY,eAAe,GAAG;AACpC,8BAA0B,SAAS,SAAS;AAC5C,YAAQ,KAAK;AAAA,MACX,UAAU;AAAA,MACV;AAAA,MACA,MAAM;AAAA,IACR,CAAC;AAAA,EACH,CAAC;AACD,SAAO;AACT;AAUA,IAAM,yBAAyB,qBAA8B;AAoB7D,SAAS,0BAA0B,UAAkB,WAAyB;AAG5E,QAAM,WAAW,uBAAuB;AAAA,IAAI;AAAA,IAAU,MACpD,oBAAoB,UAAU,aAAa,UAAU,MAAM,CAAC;AAAA,EAC9D;AACA,MAAI,CAAC,SAAU,OAAM,IAAI,wBAAwB,EAAE,MAAM,UAAU,UAAU,CAAC;AAChF;","names":[]}
@@ -0,0 +1,181 @@
1
+ #!/usr/bin/env node
2
+ import "tsx/esm";
3
+
4
+ // src/server/_internal/compare-by-code-unit.ts
5
+ function compareByCodeUnit(a, b) {
6
+ if (a < b) return -1;
7
+ if (a > b) return 1;
8
+ return 0;
9
+ }
10
+
11
+ // src/server/_internal/scan-walker.ts
12
+ import { readdirSync } from "fs";
13
+ import { extname, join, resolve } from "path";
14
+ function walkSourceFiles(root, opts, onFile) {
15
+ const skipPrefixes = opts.skipPrefixes ?? ["_", "."];
16
+ const readDir = opts.readDir ?? ((dir) => readdirSync(dir, { withFileTypes: true }));
17
+ const visit = (dir) => {
18
+ let entries;
19
+ try {
20
+ entries = readDir(dir);
21
+ } catch {
22
+ return;
23
+ }
24
+ const ordered = [...entries].sort((a, b) => compareByCodeUnit(a.name, b.name));
25
+ for (const entry of ordered) {
26
+ const fullPath = join(dir, entry.name);
27
+ if (entry.isDirectory() && !skipPrefixes.some((p) => entry.name.startsWith(p))) {
28
+ visit(fullPath);
29
+ } else if (entry.isFile() && opts.extensions.has(extname(entry.name))) {
30
+ onFile(resolve(fullPath));
31
+ }
32
+ }
33
+ };
34
+ visit(root);
35
+ }
36
+
37
+ // src/server/scan/errors.ts
38
+ var ROUTER_MIGRATION_GUIDE_URL = "https://theokit.dev/migration/0.3-to-0.4-router";
39
+ var RouterConventionError = class extends Error {
40
+ name = "RouterConventionError";
41
+ file;
42
+ suggestion;
43
+ migrationUrl;
44
+ constructor(opts) {
45
+ const migrationUrl = opts.migrationUrl ?? ROUTER_MIGRATION_GUIDE_URL;
46
+ const message = [
47
+ `Router convention violation: dotted route basename is not supported in theokit 0.4+.`,
48
+ ``,
49
+ ` File: ${opts.file}`,
50
+ ` Use directory-nested form: ${opts.suggestion}`,
51
+ ``,
52
+ `Migration guide: ${migrationUrl}`,
53
+ `Run \`theokit migrate router\` to convert all dotted basenames automatically.`
54
+ ].join("\n");
55
+ super(message);
56
+ this.file = opts.file;
57
+ this.suggestion = opts.suggestion;
58
+ this.migrationUrl = migrationUrl;
59
+ }
60
+ };
61
+ var ROUTE_POLICY_MIGRATION_GUIDE_URL = "https://theokit.dev/migration/route-policy";
62
+ var MissingRoutePolicyError = class extends Error {
63
+ name = "MissingRoutePolicyError";
64
+ file;
65
+ routePath;
66
+ methods;
67
+ migrationUrl;
68
+ constructor(opts) {
69
+ const migrationUrl = opts.migrationUrl ?? ROUTE_POLICY_MIGRATION_GUIDE_URL;
70
+ const methods = [...opts.methods].sort(compareByCodeUnit);
71
+ const message = [
72
+ `Route policy not declared: every route says who may call it (ADR 0001).`,
73
+ ``,
74
+ ` File: ${opts.file}`,
75
+ ` Route: ${opts.routePath}`,
76
+ ` Missing: ${methods.join(", ")}`,
77
+ ``,
78
+ `Add a policy to each method listed above:`,
79
+ ``,
80
+ // The import is part of the remedy, not decoration. This message shipped
81
+ // naming `requireOwner` while no entry point exported it, so it read as
82
+ // actionable and was not. `tests/unit/policy-gate-remedy-is-importable.test.ts`
83
+ // asserts that every symbol named here is reachable from the path named here.
84
+ ` import { route, requireOwner } from 'theokit/server/define'`,
85
+ ``,
86
+ ` export const ${methods[0] ?? "GET"} = route()`,
87
+ ` .policy('public') // anyone may call this`,
88
+ ` .handler(...)`,
89
+ ` .build()`,
90
+ ``,
91
+ ` export const ${methods[0] ?? "GET"} = route()`,
92
+ ` .policy(({ subject, params }) => requireOwner(subject, ownerOf(params.id)))`,
93
+ ` .handler(...)`,
94
+ ` .build()`,
95
+ ``,
96
+ `Writing 'public' is a decision and not a default. It states that this route`,
97
+ `is open to anyone who can reach it, and it is greppable, so how much of the`,
98
+ `app is open becomes a number somebody can read.`,
99
+ ``,
100
+ `Migration guide: ${migrationUrl}`
101
+ ].join("\n");
102
+ super(message);
103
+ this.file = opts.file;
104
+ this.routePath = opts.routePath;
105
+ this.methods = methods;
106
+ this.migrationUrl = migrationUrl;
107
+ }
108
+ };
109
+ var AGENT_POLICY_MIGRATION_GUIDE_URL = "https://theokit.dev/migration/agent-policy";
110
+ var MissingAgentPolicyError = class extends Error {
111
+ name = "MissingAgentPolicyError";
112
+ file;
113
+ agentPath;
114
+ migrationUrl;
115
+ constructor(opts) {
116
+ const migrationUrl = opts.migrationUrl ?? AGENT_POLICY_MIGRATION_GUIDE_URL;
117
+ const message = [
118
+ `Agent policy not declared: every agent says who may run it (ADR 0001).`,
119
+ ``,
120
+ ` File: ${opts.file}`,
121
+ ` Agent: ${opts.agentPath}`,
122
+ ``,
123
+ `This one declaration covers every endpoint the agent exposes - the run, the`,
124
+ `thread routes, the pending-approval listing, the approve route and MCP - because`,
125
+ `they all reach the same conversation and the same paused tools.`,
126
+ ``,
127
+ `Add ONE of these to the file above:`,
128
+ ``,
129
+ ` export const policy = 'public' // anyone who can reach it may run it`,
130
+ ``,
131
+ ` import { requireOwner } from 'theokit/server/define'`,
132
+ ``,
133
+ ` // subject <- what server/context.ts put on ctx.subject`,
134
+ ` // params <- { agent, endpoint, sessionId?, approvalId? }`,
135
+ ` // body <- the parsed chat body, on the endpoints that have one`,
136
+ ` export const policy = ({ subject, params }) =>`,
137
+ ` requireOwner(subject, ownerOf(params.sessionId))`,
138
+ ``,
139
+ `Writing 'public' is a decision and not a default. The endpoint resumes whatever`,
140
+ `conversation the CALLER names, so 'public' means any caller holding an id may read`,
141
+ `and continue that conversation - a capability model, which is legitimate when it is`,
142
+ `the choice somebody made and greppable once it is written down.`,
143
+ ``,
144
+ `Migration guide: ${migrationUrl}`
145
+ ].join("\n");
146
+ super(message);
147
+ this.file = opts.file;
148
+ this.agentPath = opts.agentPath;
149
+ this.migrationUrl = migrationUrl;
150
+ }
151
+ };
152
+
153
+ // src/server/scan/file-stamp-cache.ts
154
+ import { statSync } from "fs";
155
+ function createFileStampCache() {
156
+ const entries = /* @__PURE__ */ new Map();
157
+ return {
158
+ get(filePath, compute) {
159
+ const stat = statSync(filePath);
160
+ const key = `${filePath}:${String(stat.mtimeMs)}:${String(stat.size)}`;
161
+ const hit = entries.get(key);
162
+ if (hit !== void 0 || entries.has(key)) return hit;
163
+ const value = compute();
164
+ entries.set(key, value);
165
+ return value;
166
+ },
167
+ clear() {
168
+ entries.clear();
169
+ }
170
+ };
171
+ }
172
+
173
+ export {
174
+ compareByCodeUnit,
175
+ walkSourceFiles,
176
+ RouterConventionError,
177
+ MissingRoutePolicyError,
178
+ MissingAgentPolicyError,
179
+ createFileStampCache
180
+ };
181
+ //# sourceMappingURL=chunk-FD4ZDTQ6.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/server/_internal/compare-by-code-unit.ts","../src/server/_internal/scan-walker.ts","../src/server/scan/errors.ts","../src/server/scan/file-stamp-cache.ts"],"sourcesContent":["/**\n * Total order over strings by UTF-16 code unit — the ordering build-time output\n * must use.\n *\n * `localeCompare` is the wrong instrument here, and reads like the right one,\n * which is why it kept being chosen. With no locale argument it uses the default\n * collator, and Node derives that from `LC_ALL`/`LANG`: under `sv-SE` an `ä`\n * sorts after `z`, under `en-US` before `a`. A scanner ordering that way emits a\n * different manifest per machine — and where the order being emitted is an\n * execution order, it decides which middleware runs first\n * (usetheokit/theokit#346, usetheokit/theokit#351).\n *\n * What build output needs from a comparator is that it be total and stable.\n * Being alphabetical for a reader of one particular language is not a property\n * it needs, and is the one that costs reproducibility.\n *\n * Presentation code is the opposite case and should keep `localeCompare`: a list\n * a human reads should collate the way that human's language collates.\n *\n * @internal\n */\nexport function compareByCodeUnit(a: string, b: string): number {\n if (a < b) return -1\n if (a > b) return 1\n return 0\n}\n","/* eslint-disable security/detect-non-literal-fs-filename --\n * Build-time scanner: walks directories derived from cwd.\n * No HTTP input ever reaches these fs calls.\n */\nimport { readdirSync } from 'node:fs'\nimport type { Dirent } from 'node:fs'\nimport { extname, join, resolve } from 'node:path'\n\nimport { compareByCodeUnit } from './compare-by-code-unit.js'\n\n/**\n * Options for walkSourceFiles.\n *\n * Sequential by design — callers (route precedence) depend on insertion\n * order (EC-19 documented decision). Async-callback support is implicit\n * via JavaScript's serial await loop.\n *\n * Tested on macOS + Linux. Windows long-path support not validated (EC-20).\n */\ninterface WalkOptions {\n /** File extensions to include (e.g., new Set(['.ts', '.tsx'])). */\n extensions: ReadonlySet<string>\n /** Skip directories whose name starts with any of these (default: ['_', '.']). */\n skipPrefixes?: readonly string[]\n /**\n * Read one directory. Defaults to `readdirSync`.\n *\n * Injected for one reason: the ordering below cannot be tested against a real\n * filesystem. `readdirSync` returns whatever the filesystem returns — creation\n * order on tmpfs, hash order on ext4 with `dir_index` — and on the machine\n * this was written on those four names came back already sorted, so a\n * name-based test passed before the sort existed and proved nothing. A test\n * that agrees with the code because both read the same accidental order is\n * `B-022`, and writing one here would have been that item committed inside its\n * own fix.\n */\n readDir?: (dir: string) => Dirent[]\n}\n\n/**\n * Recursively walk `root`, invoking `onFile(absPath)` for every file matching\n * `opts.extensions`. Directories whose name starts with any `skipPrefixes`\n * char are skipped (defaults to `_` and `.`).\n *\n * Entries are emitted in UTF-16 code-unit order, files and directories in one\n * total order. Without it the walker passed the filesystem's order through to\n * six scanners — routes, actions, websockets, cron, agents, jobs — and only one\n * re-orders afterwards, so five emitted a different manifest per machine. Where\n * that order is an execution order it decides what runs first (#346, B-004).\n *\n * Replaces 3 near-identical recursive walkers in scan.ts, action-scan.ts,\n * ws-scan.ts (PV-3 — DRY consolidation). Resolves T3.1 of\n * architecture-review-remediation-plan. Six call sites consume it today, not\n * three; the count in this paragraph was true when it was written.\n *\n * Symlink loops are NOT tracked — callers must avoid them or pre-resolve\n * via `fs.realpath`. EC-11 documented but not implemented (rare in dev).\n */\nexport function walkSourceFiles(\n root: string,\n opts: WalkOptions,\n onFile: (absPath: string) => void,\n): void {\n const skipPrefixes = opts.skipPrefixes ?? ['_', '.']\n const readDir = opts.readDir ?? ((dir: string) => readdirSync(dir, { withFileTypes: true }))\n const visit = (dir: string): void => {\n let entries\n try {\n entries = readDir(dir)\n } catch {\n // Silently skip unreadable directories — caller controls discoverability\n return\n }\n // One total order over files and directories together, so a name sorts the\n // same way whichever it is. Sorting the two groups separately would emit a\n // different interleaving than a single pass, which is an ordering decision\n // nobody made (#346).\n const ordered = [...entries].sort((a, b) => compareByCodeUnit(a.name, b.name))\n for (const entry of ordered) {\n const fullPath = join(dir, entry.name)\n if (entry.isDirectory() && !skipPrefixes.some((p) => entry.name.startsWith(p))) {\n visit(fullPath)\n } else if (entry.isFile() && opts.extensions.has(extname(entry.name))) {\n onFile(resolve(fullPath))\n }\n }\n }\n visit(root)\n}\n","import { compareByCodeUnit } from '../_internal/compare-by-code-unit.js'\n\n/**\n * Router-convention errors thrown by the server-route scanner.\n *\n *\n * theokit 0.4.0+ enforces directory-nested file-system routing\n * (`auth/[provider]/login.ts`) and REJECTS dotted-basename routes\n * (`auth.[provider].login.ts`) because the legacy regex extracted the\n * dotted basename incorrectly — `params.provider` was undefined at request\n * time. Decision recorded in the plan above (`g6-router-convention-plan.md`) and CHANGELOG 0.4.0\n * (no standalone ADR was cut for this router-convention change).\n */\n\n/**\n * Canonical migration guide URL. T4.2 establishes this as the authoritative\n * landing page. EC-3: error message uses this constant so the URL never\n * drifts from the doc location.\n */\nexport const ROUTER_MIGRATION_GUIDE_URL = 'https://theokit.dev/migration/0.3-to-0.4-router'\n\ninterface RouterConventionErrorOptions {\n /** Absolute path of the offending route file. */\n file: string\n /** Suggested directory-nested replacement path (relative, e.g. `routes/auth/[provider]/login.ts`). */\n suggestion: string\n /** Migration guide URL (defaults to `ROUTER_MIGRATION_GUIDE_URL`). */\n migrationUrl?: string\n}\n\n/**\n * Thrown by `scanServerRoutes` when a route file uses the legacy\n * dotted-basename convention (`auth.[provider].login.ts`).\n *\n * The error is FAIL-FAST by design — running with a route that has wrong\n * `paramNames` produces silent 404s at request time, which is strictly\n * worse than a build-time error.\n */\nexport class RouterConventionError extends Error {\n override readonly name = 'RouterConventionError'\n readonly file: string\n readonly suggestion: string\n readonly migrationUrl: string\n\n constructor(opts: RouterConventionErrorOptions) {\n const migrationUrl = opts.migrationUrl ?? ROUTER_MIGRATION_GUIDE_URL\n const message = [\n `Router convention violation: dotted route basename is not supported in theokit 0.4+.`,\n ``,\n ` File: ${opts.file}`,\n ` Use directory-nested form: ${opts.suggestion}`,\n ``,\n `Migration guide: ${migrationUrl}`,\n `Run \\`theokit migrate router\\` to convert all dotted basenames automatically.`,\n ].join('\\n')\n super(message)\n this.file = opts.file\n this.suggestion = opts.suggestion\n this.migrationUrl = migrationUrl\n }\n}\n\n/**\n * Canonical landing page for the policy-declaration migration. Held as a\n * constant for the same reason as {@link ROUTER_MIGRATION_GUIDE_URL}: the error\n * message and the doc cannot drift apart if only one of them names the URL.\n *\n * Module-local, unlike its sibling: nothing outside this file needs to name it,\n * and an export with no consumer is what `knip` exists to refuse.\n */\nconst ROUTE_POLICY_MIGRATION_GUIDE_URL = 'https://theokit.dev/migration/route-policy'\n\ninterface MissingRoutePolicyErrorOptions {\n /** Absolute path of the route file. */\n file: string\n /** The URL path the file resolves to, so the message reads like the app, not like the disk. */\n routePath: string\n /** The exported HTTP methods that declare no policy. */\n methods: string[]\n /** Migration guide URL (defaults to {@link ROUTE_POLICY_MIGRATION_GUIDE_URL}). */\n migrationUrl?: string\n}\n\n/**\n * Thrown by `scanServerRoutes` when a route file exports an HTTP method that\n * declares no access policy (ADR 0001, Decision point 5).\n *\n * Absence used to mean \"not declared\", which every reader and every transport\n * had to interpret as open. The interpretation was the bug: a route nobody\n * thought about looked exactly like a route deliberately left open. This error\n * is where the two stop looking alike.\n *\n * It fires at scan time — `theo build`, `theo start`, `theo dev`, `theo routes`\n * and every deployment adapter go through the same scanner — so the answer\n * arrives before a request does, in the same place the scanner already refuses\n * a dotted basename and a collision with the reserved batch path.\n */\nexport class MissingRoutePolicyError extends Error {\n override readonly name = 'MissingRoutePolicyError'\n readonly file: string\n readonly routePath: string\n readonly methods: string[]\n readonly migrationUrl: string\n\n constructor(opts: MissingRoutePolicyErrorOptions) {\n const migrationUrl = opts.migrationUrl ?? ROUTE_POLICY_MIGRATION_GUIDE_URL\n const methods = [...opts.methods].sort(compareByCodeUnit)\n const message = [\n `Route policy not declared: every route says who may call it (ADR 0001).`,\n ``,\n ` File: ${opts.file}`,\n ` Route: ${opts.routePath}`,\n ` Missing: ${methods.join(', ')}`,\n ``,\n `Add a policy to each method listed above:`,\n ``,\n // The import is part of the remedy, not decoration. This message shipped\n // naming `requireOwner` while no entry point exported it, so it read as\n // actionable and was not. `tests/unit/policy-gate-remedy-is-importable.test.ts`\n // asserts that every symbol named here is reachable from the path named here.\n ` import { route, requireOwner } from 'theokit/server/define'`,\n ``,\n ` export const ${methods[0] ?? 'GET'} = route()`,\n ` .policy('public') // anyone may call this`,\n ` .handler(...)`,\n ` .build()`,\n ``,\n ` export const ${methods[0] ?? 'GET'} = route()`,\n ` .policy(({ subject, params }) => requireOwner(subject, ownerOf(params.id)))`,\n ` .handler(...)`,\n ` .build()`,\n ``,\n `Writing 'public' is a decision and not a default. It states that this route`,\n `is open to anyone who can reach it, and it is greppable, so how much of the`,\n `app is open becomes a number somebody can read.`,\n ``,\n `Migration guide: ${migrationUrl}`,\n ].join('\\n')\n super(message)\n this.file = opts.file\n this.routePath = opts.routePath\n this.methods = methods\n this.migrationUrl = migrationUrl\n }\n}\n\n/**\n * Canonical landing page for the agent-policy migration. Module-local for the same reason as its\n * route sibling: nothing outside this file names it, and an export with no consumer is what `knip`\n * exists to refuse.\n */\nconst AGENT_POLICY_MIGRATION_GUIDE_URL = 'https://theokit.dev/migration/agent-policy'\n\ninterface MissingAgentPolicyErrorOptions {\n /** Absolute path of the agent file. */\n file: string\n /** The URL the agent is served at, so the message reads like the app rather than like the disk. */\n agentPath: string\n /** Migration guide URL (defaults to {@link AGENT_POLICY_MIGRATION_GUIDE_URL}). */\n migrationUrl?: string\n}\n\n/**\n * Thrown by `scanAgents` when an agent file declares no access policy\n * (ADR 0001 Decision point 5, extended to the agent surface by usetheokit/theokit#365).\n *\n * ## Why absence had to stop meaning open HERE and not at runtime\n *\n * The agent endpoints resume a conversation the CALLER names, and they are dispatched before route\n * matching, so no route, no middleware and no `server/context.ts` ever saw those URLs. A caller\n * holding a conversation id and no credential read that conversation back.\n *\n * There is no safe runtime default for that. Refusing every caller-named session id would break\n * multi-turn chat, which is the base case; admitting them is the defect. So the decision moves to\n * where a person can answer it once, in the file that owns the agent — the same place and the same\n * reasoning as the route gate, which is why this error reads like its sibling.\n *\n * ## What it costs\n *\n * Every existing application with an agent fails its next build until it adds one line. That is the\n * half of ADR 0001 the ADR itself called breaking, and the trade it names: a build error that\n * points at a file beats a silent 200 that hands over somebody else's conversation.\n */\nexport class MissingAgentPolicyError extends Error {\n override readonly name = 'MissingAgentPolicyError'\n readonly file: string\n readonly agentPath: string\n readonly migrationUrl: string\n\n constructor(opts: MissingAgentPolicyErrorOptions) {\n const migrationUrl = opts.migrationUrl ?? AGENT_POLICY_MIGRATION_GUIDE_URL\n const message = [\n `Agent policy not declared: every agent says who may run it (ADR 0001).`,\n ``,\n ` File: ${opts.file}`,\n ` Agent: ${opts.agentPath}`,\n ``,\n `This one declaration covers every endpoint the agent exposes - the run, the`,\n `thread routes, the pending-approval listing, the approve route and MCP - because`,\n `they all reach the same conversation and the same paused tools.`,\n ``,\n `Add ONE of these to the file above:`,\n ``,\n ` export const policy = 'public' // anyone who can reach it may run it`,\n ``,\n ` import { requireOwner } from 'theokit/server/define'`,\n ``,\n ` // subject <- what server/context.ts put on ctx.subject`,\n ` // params <- { agent, endpoint, sessionId?, approvalId? }`,\n ` // body <- the parsed chat body, on the endpoints that have one`,\n ` export const policy = ({ subject, params }) =>`,\n ` requireOwner(subject, ownerOf(params.sessionId))`,\n ``,\n `Writing 'public' is a decision and not a default. The endpoint resumes whatever`,\n `conversation the CALLER names, so 'public' means any caller holding an id may read`,\n `and continue that conversation - a capability model, which is legitimate when it is`,\n `the choice somebody made and greppable once it is written down.`,\n ``,\n `Migration guide: ${migrationUrl}`,\n ].join('\\n')\n super(message)\n this.file = opts.file\n this.agentPath = opts.agentPath\n this.migrationUrl = migrationUrl\n }\n}\n","/**\n * Memoise per source file, invalidated by the file's own stamp.\n *\n * ## Why this exists\n *\n * `theokit dev` re-scans the routes and agents directories on EVERY request, so any work that\n * parses a file with the TypeScript AST turns a build-time check into per-request latency.\n * `agent-scan.ts` recognised this and carried its own `Map` keyed on `path:mtimeMs:size`;\n * `scan.ts` — with far more files — carried neither the cache nor the reasoning, and the\n * route-policy gate then added a SECOND full parse of every route file on top of the one\n * `detectExportedHttpMethods` had been paying since before it (usetheokit/theokit#417).\n *\n * Lifting the mechanism here rather than copying it is the point: two hand-rolled caches keyed\n * \"the same way\" are two chances for the keys to stop being the same.\n *\n * ## Why the stamp and not a watcher\n *\n * `mtimeMs` and `size` together come from the `statSync` the scanner is doing anyway, so an edit\n * invalidates the entry without anyone remembering to, and a `theokit build` — one process, one\n * scan — never notices the cache exists.\n *\n * The known limit, stated rather than discovered: a rewrite that preserves BOTH mtime and size is\n * invisible. That is a deliberate trade every mtime cache makes, and the alternative (hashing the\n * contents) reads the file to avoid reading the file.\n */\nimport { statSync } from 'node:fs'\n\nexport interface FileStampCache<T> {\n /** The memoised value for `filePath`, computing it when the file's stamp has changed. */\n get: (filePath: string, compute: () => T) => T\n /** Test seam — a module-level cache would otherwise outlive a fixture directory. */\n clear: () => void\n}\n\nexport function createFileStampCache<T>(): FileStampCache<T> {\n const entries = new Map<string, T>()\n\n return {\n get(filePath, compute) {\n // A path the scanner itself discovered by globbing the project, never caller input at runtime.\n // eslint-disable-next-line security/detect-non-literal-fs-filename -- see above\n const stat = statSync(filePath)\n const key = `${filePath}:${String(stat.mtimeMs)}:${String(stat.size)}`\n\n const hit = entries.get(key)\n // `has` rather than a truthiness check on the value: `false`, `0` and `''` are all legitimate\n // results to cache, and a truthiness test would recompute them on every call — which is the\n // defect this file exists to remove, wearing a subtler hat.\n if (hit !== undefined || entries.has(key)) return hit as T\n\n const value = compute()\n entries.set(key, value)\n return value\n },\n clear() {\n entries.clear()\n },\n }\n}\n"],"mappings":";;;;AAqBO,SAAS,kBAAkB,GAAW,GAAmB;AAC9D,MAAI,IAAI,EAAG,QAAO;AAClB,MAAI,IAAI,EAAG,QAAO;AAClB,SAAO;AACT;;;ACrBA,SAAS,mBAAmB;AAE5B,SAAS,SAAS,MAAM,eAAe;AAoDhC,SAAS,gBACd,MACA,MACA,QACM;AACN,QAAM,eAAe,KAAK,gBAAgB,CAAC,KAAK,GAAG;AACnD,QAAM,UAAU,KAAK,YAAY,CAAC,QAAgB,YAAY,KAAK,EAAE,eAAe,KAAK,CAAC;AAC1F,QAAM,QAAQ,CAAC,QAAsB;AACnC,QAAI;AACJ,QAAI;AACF,gBAAU,QAAQ,GAAG;AAAA,IACvB,QAA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,gBAAgB;AASlB,SAAS,uBAA6C;AAC3D,QAAM,UAAU,oBAAI,IAAe;AAEnC,SAAO;AAAA,IACL,IAAI,UAAU,SAAS;AAGrB,YAAM,OAAO,SAAS,QAAQ;AAC9B,YAAM,MAAM,GAAG,QAAQ,IAAI,OAAO,KAAK,OAAO,CAAC,IAAI,OAAO,KAAK,IAAI,CAAC;AAEpE,YAAM,MAAM,QAAQ,IAAI,GAAG;AAI3B,UAAI,QAAQ,UAAa,QAAQ,IAAI,GAAG,EAAG,QAAO;AAElD,YAAM,QAAQ,QAAQ;AACtB,cAAQ,IAAI,KAAK,KAAK;AACtB,aAAO;AAAA,IACT;AAAA,IACA,QAAQ;AACN,cAAQ,MAAM;AAAA,IAChB;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+ import "tsx/esm";
3
+
4
+ // src/vite-plugin/resolve-theo-root.ts
5
+ import { existsSync } from "fs";
6
+ import { resolve } from "path";
7
+ function resolveTheoRootDir(currentDir) {
8
+ if (existsSync(resolve(currentDir, "client"))) {
9
+ return currentDir;
10
+ }
11
+ return resolve(currentDir, "..");
12
+ }
13
+
14
+ export {
15
+ resolveTheoRootDir
16
+ };
17
+ //# sourceMappingURL=chunk-FDOOBTXJ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/vite-plugin/resolve-theo-root.ts"],"sourcesContent":["/* eslint-disable security/detect-non-literal-fs-filename --\n * Resolves theokit's own install directory (the `node_modules/theokit/`).\n * Build-time tool. Read-only check. No HTTP input.\n */\nimport { existsSync } from 'node:fs'\nimport { resolve } from 'node:path'\n\n/**\n * Resolve the directory that holds the framework's compiled (or source)\n * subpaths — `client/`, `server/`, `react-query/`, etc.\n *\n * Cases (regression T1.3):\n * - Source mode (`src/vite-plugin/index.ts`) — `currentDir` is\n * `…/src/vite-plugin`. Parent (`…/src`) contains `client/`. Return parent.\n * - Dist mode (`dist/chunk-XYZ.js`) — `currentDir` is `…/dist`. That dir\n * itself contains `client/`. Return currentDir.\n * - Unknown shape — fall back to parent (legacy behavior). The dogfood\n * validator will catch the misconfiguration before runtime.\n *\n * Pure function — no side effects, only filesystem reads via `existsSync`.\n * Exported so the regression test can exercise the branch logic directly.\n */\nexport function resolveTheoRootDir(currentDir: string): string {\n if (existsSync(resolve(currentDir, 'client'))) {\n return currentDir\n }\n return resolve(currentDir, '..')\n}\n"],"mappings":";;;;AAIA,SAAS,kBAAkB;AAC3B,SAAS,eAAe;AAiBjB,SAAS,mBAAmB,YAA4B;AAC7D,MAAI,WAAW,QAAQ,YAAY,QAAQ,CAAC,GAAG;AAC7C,WAAO;AAAA,EACT;AACA,SAAO,QAAQ,YAAY,IAAI;AACjC;","names":[]}