@pyric/cli 0.1.0-alpha.19 → 0.1.0-alpha.21

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 (642) hide show
  1. package/README.md +64 -89
  2. package/dist/assurance/.generated/conformance-verdicts.d.ts +68 -1
  3. package/dist/assurance/.generated/conformance-verdicts.d.ts.map +1 -1
  4. package/dist/assurance/.generated/conformance-verdicts.js +68 -1
  5. package/dist/assurance/.generated/conformance-verdicts.js.map +1 -1
  6. package/dist/bridge/client/dispatch.d.ts +25 -19
  7. package/dist/bridge/client/dispatch.d.ts.map +1 -1
  8. package/dist/bridge/client/dispatch.js +41 -48
  9. package/dist/bridge/client/dispatch.js.map +1 -1
  10. package/dist/bridge/client/tool-family-factories.d.ts +26 -0
  11. package/dist/bridge/client/tool-family-factories.d.ts.map +1 -0
  12. package/dist/bridge/client/tool-family-factories.js +10 -0
  13. package/dist/bridge/client/tool-family-factories.js.map +1 -0
  14. package/dist/bridge/server/mcp-contract.d.ts +7 -6
  15. package/dist/bridge/server/mcp-contract.d.ts.map +1 -1
  16. package/dist/bridge/server/mcp-contract.js +9 -48
  17. package/dist/bridge/server/mcp-contract.js.map +1 -1
  18. package/dist/bridge/server/peer.d.ts +11 -1
  19. package/dist/bridge/server/peer.d.ts.map +1 -1
  20. package/dist/bridge/server/peer.js +22 -1
  21. package/dist/bridge/server/peer.js.map +1 -1
  22. package/dist/bridge/server/tool-family-factories.d.ts +30 -0
  23. package/dist/bridge/server/tool-family-factories.d.ts.map +1 -0
  24. package/dist/bridge/server/tool-family-factories.js +22 -0
  25. package/dist/bridge/server/tool-family-factories.js.map +1 -0
  26. package/dist/bridge/server/tool-metadata.d.ts +17 -18
  27. package/dist/bridge/server/tool-metadata.d.ts.map +1 -1
  28. package/dist/bridge/server/tool-metadata.js +24 -59
  29. package/dist/bridge/server/tool-metadata.js.map +1 -1
  30. package/dist/bridge/tool-families.d.ts +48 -0
  31. package/dist/bridge/tool-families.d.ts.map +1 -0
  32. package/dist/bridge/tool-families.generated.d.ts +32 -0
  33. package/dist/bridge/tool-families.generated.d.ts.map +1 -0
  34. package/dist/bridge/tool-families.generated.js +15 -0
  35. package/dist/bridge/tool-families.generated.js.map +1 -0
  36. package/dist/bridge/tool-families.js +51 -0
  37. package/dist/bridge/tool-families.js.map +1 -0
  38. package/dist/bridge/tool-family-records/conformance.d.ts +7 -0
  39. package/dist/bridge/tool-family-records/conformance.d.ts.map +1 -0
  40. package/dist/bridge/tool-family-records/conformance.js +6 -0
  41. package/dist/bridge/tool-family-records/conformance.js.map +1 -0
  42. package/dist/bridge/tool-family-records/firestore-data.d.ts +7 -0
  43. package/dist/bridge/tool-family-records/firestore-data.d.ts.map +1 -0
  44. package/dist/bridge/tool-family-records/firestore-data.js +15 -0
  45. package/dist/bridge/tool-family-records/firestore-data.js.map +1 -0
  46. package/dist/bridge/tool-family-records/firestore-inspect.d.ts +7 -0
  47. package/dist/bridge/tool-family-records/firestore-inspect.d.ts.map +1 -0
  48. package/dist/bridge/tool-family-records/firestore-inspect.js +6 -0
  49. package/dist/bridge/tool-family-records/firestore-inspect.js.map +1 -0
  50. package/dist/bridge/tool-family-records/firestore-rules.d.ts +7 -0
  51. package/dist/bridge/tool-family-records/firestore-rules.d.ts.map +1 -0
  52. package/dist/bridge/tool-family-records/firestore-rules.js +15 -0
  53. package/dist/bridge/tool-family-records/firestore-rules.js.map +1 -0
  54. package/dist/bridge/tool-family-records/firestore-simulator.d.ts +7 -0
  55. package/dist/bridge/tool-family-records/firestore-simulator.d.ts.map +1 -0
  56. package/dist/bridge/tool-family-records/firestore-simulator.js +16 -0
  57. package/dist/bridge/tool-family-records/firestore-simulator.js.map +1 -0
  58. package/dist/bridge/tool-family-records/rtdb-inspection.d.ts +7 -0
  59. package/dist/bridge/tool-family-records/rtdb-inspection.d.ts.map +1 -0
  60. package/dist/bridge/tool-family-records/rtdb-inspection.js +6 -0
  61. package/dist/bridge/tool-family-records/rtdb-inspection.js.map +1 -0
  62. package/dist/bundler/externals.d.ts +37 -0
  63. package/dist/bundler/externals.d.ts.map +1 -0
  64. package/dist/bundler/externals.js +52 -0
  65. package/dist/bundler/externals.js.map +1 -0
  66. package/dist/bundler/index.d.ts +17 -0
  67. package/dist/bundler/index.d.ts.map +1 -0
  68. package/dist/bundler/index.js +17 -0
  69. package/dist/bundler/index.js.map +1 -0
  70. package/dist/cli/index.d.ts +2 -2
  71. package/dist/cli/index.d.ts.map +1 -1
  72. package/dist/cli/index.js +48 -42
  73. package/dist/cli/index.js.map +1 -1
  74. package/dist/cli/inlined-sdk-scanner.d.ts +6 -0
  75. package/dist/cli/inlined-sdk-scanner.d.ts.map +1 -0
  76. package/dist/cli/inlined-sdk-scanner.js +82 -0
  77. package/dist/cli/inlined-sdk-scanner.js.map +1 -0
  78. package/dist/cli/mcp-proxy.js +3 -3
  79. package/dist/cli/mcp-proxy.js.map +1 -1
  80. package/dist/cli/parse-args.d.ts +1 -1
  81. package/dist/cli/parse-args.d.ts.map +1 -1
  82. package/dist/cli/parse-args.js +51 -15
  83. package/dist/cli/parse-args.js.map +1 -1
  84. package/dist/cli/pyric-config.d.ts +24 -0
  85. package/dist/cli/pyric-config.d.ts.map +1 -0
  86. package/dist/cli/pyric-config.js +28 -0
  87. package/dist/cli/pyric-config.js.map +1 -0
  88. package/dist/cli/sandbox-interlock.d.ts +97 -0
  89. package/dist/cli/sandbox-interlock.d.ts.map +1 -0
  90. package/dist/cli/sandbox-interlock.js +112 -0
  91. package/dist/cli/sandbox-interlock.js.map +1 -0
  92. package/dist/cli/{dev-runner.d.ts → sandbox-runner.d.ts} +53 -48
  93. package/dist/cli/sandbox-runner.d.ts.map +1 -0
  94. package/dist/cli/{dev-runner.js → sandbox-runner.js} +105 -67
  95. package/dist/cli/sandbox-runner.js.map +1 -0
  96. package/dist/cli/serve.d.ts +12 -14
  97. package/dist/cli/serve.d.ts.map +1 -1
  98. package/dist/cli/serve.js +155 -116
  99. package/dist/cli/serve.js.map +1 -1
  100. package/dist/cli/snapshot.js +5 -5
  101. package/dist/cli/snapshot.js.map +1 -1
  102. package/dist/cli/unsupported-runtime.d.ts +27 -0
  103. package/dist/cli/unsupported-runtime.d.ts.map +1 -0
  104. package/dist/cli/unsupported-runtime.js +63 -0
  105. package/dist/cli/unsupported-runtime.js.map +1 -0
  106. package/dist/cli/verify.js +1 -1
  107. package/dist/cli/verify.js.map +1 -1
  108. package/dist/conformance/.generated/can-i-use-browser.d.ts +1 -1
  109. package/dist/conformance/.generated/can-i-use-browser.d.ts.map +1 -1
  110. package/dist/conformance/.generated/can-i-use-browser.js +1 -1
  111. package/dist/conformance/.generated/can-i-use-browser.js.map +1 -1
  112. package/dist/conformance/.generated/can-i-use.d.ts +1 -1
  113. package/dist/conformance/.generated/can-i-use.d.ts.map +1 -1
  114. package/dist/conformance/.generated/can-i-use.js +1 -1
  115. package/dist/conformance/.generated/can-i-use.js.map +1 -1
  116. package/dist/conformance/.generated/conformance-docs.d.ts.map +1 -1
  117. package/dist/conformance/.generated/conformance-docs.js +1 -1
  118. package/dist/conformance/.generated/conformance-docs.js.map +1 -1
  119. package/dist/functions-rtdb/child.d.ts +37 -0
  120. package/dist/functions-rtdb/child.d.ts.map +1 -1
  121. package/dist/functions-rtdb/child.js +90 -21
  122. package/dist/functions-rtdb/child.js.map +1 -1
  123. package/dist/functions-rtdb/development-runtime.d.ts +3 -0
  124. package/dist/functions-rtdb/development-runtime.d.ts.map +1 -1
  125. package/dist/functions-rtdb/development-runtime.js +2 -1
  126. package/dist/functions-rtdb/development-runtime.js.map +1 -1
  127. package/dist/functions-rtdb/project.js +8 -8
  128. package/dist/functions-rtdb/project.js.map +1 -1
  129. package/dist/google-endpoints.d.ts +67 -0
  130. package/dist/google-endpoints.d.ts.map +1 -0
  131. package/dist/google-endpoints.js +119 -0
  132. package/dist/google-endpoints.js.map +1 -0
  133. package/dist/next/guard.js +1 -1
  134. package/dist/next/guard.js.map +1 -1
  135. package/dist/next/runtime-env.d.ts.map +1 -1
  136. package/dist/next/runtime-env.js +5 -0
  137. package/dist/next/runtime-env.js.map +1 -1
  138. package/dist/next/with-pyric.d.ts +1 -1
  139. package/dist/next/with-pyric.js +1 -1
  140. package/dist/register/beacon.d.ts +69 -0
  141. package/dist/register/beacon.d.ts.map +1 -0
  142. package/dist/register/beacon.js +199 -0
  143. package/dist/register/beacon.js.map +1 -0
  144. package/dist/register/index.d.ts.map +1 -1
  145. package/dist/register/index.js +65 -6
  146. package/dist/register/index.js.map +1 -1
  147. package/dist/register/net-guard.d.ts +110 -0
  148. package/dist/register/net-guard.d.ts.map +1 -0
  149. package/dist/register/net-guard.js +462 -0
  150. package/dist/register/net-guard.js.map +1 -0
  151. package/dist/remote/index.d.ts +1 -1
  152. package/dist/remote/index.js +9 -9
  153. package/dist/remote/index.js.map +1 -1
  154. package/dist/serve/ai-diagnostics-relay.d.ts +63 -0
  155. package/dist/serve/ai-diagnostics-relay.d.ts.map +1 -0
  156. package/dist/serve/ai-diagnostics-relay.js +125 -0
  157. package/dist/serve/ai-diagnostics-relay.js.map +1 -0
  158. package/dist/serve/ai-proxy.d.ts +92 -0
  159. package/dist/serve/ai-proxy.d.ts.map +1 -0
  160. package/dist/serve/ai-proxy.js +269 -0
  161. package/dist/serve/ai-proxy.js.map +1 -0
  162. package/dist/serve/ai-status.d.ts +44 -0
  163. package/dist/serve/ai-status.d.ts.map +1 -0
  164. package/dist/serve/ai-status.js +77 -0
  165. package/dist/serve/ai-status.js.map +1 -0
  166. package/dist/serve/ai-terminal-blocks.d.ts +97 -0
  167. package/dist/serve/ai-terminal-blocks.d.ts.map +1 -0
  168. package/dist/serve/ai-terminal-blocks.js +128 -0
  169. package/dist/serve/ai-terminal-blocks.js.map +1 -0
  170. package/dist/serve/ai-terminal-text.d.ts +36 -0
  171. package/dist/serve/ai-terminal-text.d.ts.map +1 -0
  172. package/dist/serve/ai-terminal-text.js +48 -0
  173. package/dist/serve/ai-terminal-text.js.map +1 -0
  174. package/dist/serve/beacon-route.d.ts +53 -0
  175. package/dist/serve/beacon-route.d.ts.map +1 -0
  176. package/dist/serve/beacon-route.js +101 -0
  177. package/dist/serve/beacon-route.js.map +1 -0
  178. package/dist/serve/bundler.js +10 -10
  179. package/dist/serve/bundler.js.map +1 -1
  180. package/dist/serve/entries/active-auth-registry.d.ts +16 -0
  181. package/dist/serve/entries/active-auth-registry.d.ts.map +1 -0
  182. package/dist/serve/entries/active-auth-registry.js +48 -0
  183. package/dist/serve/entries/active-auth-registry.js.map +1 -0
  184. package/dist/serve/entries/active-auth.d.ts +18 -0
  185. package/dist/serve/entries/active-auth.d.ts.map +1 -0
  186. package/dist/serve/entries/active-auth.js +84 -0
  187. package/dist/serve/entries/active-auth.js.map +1 -0
  188. package/dist/serve/entries/ai.d.ts.map +1 -1
  189. package/dist/serve/entries/ai.js +27 -1
  190. package/dist/serve/entries/ai.js.map +1 -1
  191. package/dist/serve/entries/auth-helper-core.d.ts +1 -0
  192. package/dist/serve/entries/auth-helper-core.d.ts.map +1 -1
  193. package/dist/serve/entries/auth-helper-core.js +4 -0
  194. package/dist/serve/entries/auth-helper-core.js.map +1 -1
  195. package/dist/serve/entries/auth-helper-dom.d.ts.map +1 -1
  196. package/dist/serve/entries/auth-helper-dom.js +29 -3
  197. package/dist/serve/entries/auth-helper-dom.js.map +1 -1
  198. package/dist/serve/entries/auth-helper-runtime.js +1 -1
  199. package/dist/serve/entries/auth-helper-runtime.js.map +1 -1
  200. package/dist/serve/entries/auth.d.ts.map +1 -1
  201. package/dist/serve/entries/auth.js +8 -0
  202. package/dist/serve/entries/auth.js.map +1 -1
  203. package/dist/serve/entries/bridge-url.d.ts +1 -1
  204. package/dist/serve/entries/bridge-url.js +1 -1
  205. package/dist/serve/entries/firestore.js +3 -3
  206. package/dist/serve/entries/firestore.js.map +1 -1
  207. package/dist/serve/entries/init.d.ts.map +1 -1
  208. package/dist/serve/entries/init.js +70 -4
  209. package/dist/serve/entries/init.js.map +1 -1
  210. package/dist/serve/entries/keepalive.js +1 -1
  211. package/dist/serve/entries/keepalive.js.map +1 -1
  212. package/dist/serve/entries/runtime.d.ts.map +1 -1
  213. package/dist/serve/entries/runtime.js +30 -14
  214. package/dist/serve/entries/runtime.js.map +1 -1
  215. package/dist/serve/entries/storage.js +1 -1
  216. package/dist/serve/entries/storage.js.map +1 -1
  217. package/dist/serve/entries/worker-runtime.js +1 -1
  218. package/dist/serve/entries/worker-runtime.js.map +1 -1
  219. package/dist/serve/init-payload.d.ts +4 -0
  220. package/dist/serve/init-payload.d.ts.map +1 -1
  221. package/dist/serve/namespace.d.ts +20 -5
  222. package/dist/serve/namespace.d.ts.map +1 -1
  223. package/dist/serve/namespace.js +93 -129
  224. package/dist/serve/namespace.js.map +1 -1
  225. package/dist/serve/rules.d.ts.map +1 -1
  226. package/dist/serve/rules.js +44 -21
  227. package/dist/serve/rules.js.map +1 -1
  228. package/dist/serve/runtime/chip-config.d.ts.map +1 -1
  229. package/dist/serve/runtime/chip-config.js +16 -2
  230. package/dist/serve/runtime/chip-config.js.map +1 -1
  231. package/dist/serve/runtime/chip-dialog.d.ts +18 -0
  232. package/dist/serve/runtime/chip-dialog.d.ts.map +1 -0
  233. package/dist/serve/runtime/chip-dialog.js +315 -0
  234. package/dist/serve/runtime/chip-dialog.js.map +1 -0
  235. package/dist/serve/runtime/chip-install.d.ts +2 -0
  236. package/dist/serve/runtime/chip-install.d.ts.map +1 -1
  237. package/dist/serve/runtime/chip-install.js +9 -4
  238. package/dist/serve/runtime/chip-install.js.map +1 -1
  239. package/dist/serve/runtime/chip-user-search.d.ts +16 -0
  240. package/dist/serve/runtime/chip-user-search.d.ts.map +1 -0
  241. package/dist/serve/runtime/chip-user-search.js +354 -0
  242. package/dist/serve/runtime/chip-user-search.js.map +1 -0
  243. package/dist/serve/runtime/chip.d.ts +10 -0
  244. package/dist/serve/runtime/chip.d.ts.map +1 -1
  245. package/dist/serve/runtime/chip.js +149 -15
  246. package/dist/serve/runtime/chip.js.map +1 -1
  247. package/dist/serve/runtime/identity.d.ts +17 -0
  248. package/dist/serve/runtime/identity.d.ts.map +1 -0
  249. package/dist/serve/runtime/identity.js +10 -0
  250. package/dist/serve/runtime/identity.js.map +1 -0
  251. package/dist/serve/runtime/manifest.d.ts +1 -1
  252. package/dist/serve/runtime/manifest.d.ts.map +1 -1
  253. package/dist/serve/runtime/manifest.js +1 -1
  254. package/dist/serve/runtime/manifest.js.map +1 -1
  255. package/dist/serve/runtime/status.d.ts.map +1 -1
  256. package/dist/serve/runtime/status.js +23 -0
  257. package/dist/serve/runtime/status.js.map +1 -1
  258. package/dist/serve/sandbox-session.d.ts +8 -0
  259. package/dist/serve/sandbox-session.d.ts.map +1 -1
  260. package/dist/serve/sandbox-session.js +12 -4
  261. package/dist/serve/sandbox-session.js.map +1 -1
  262. package/dist/serve/server.d.ts +7 -0
  263. package/dist/serve/server.d.ts.map +1 -1
  264. package/dist/serve/server.js +15 -1
  265. package/dist/serve/server.js.map +1 -1
  266. package/dist/serve/site-ui/404.html +1 -1
  267. package/dist/serve/site-ui/_astro/{RulesCodeEditor.Bl-XMkhD.js → RulesCodeEditor.DsTAsKIa.js} +1 -1
  268. package/dist/serve/site-ui/_astro/_slug_.Da5VLhW1.css +1 -0
  269. package/dist/serve/site-ui/_astro/_studio_.BnfYCKoI.css +1 -0
  270. package/dist/serve/site-ui/_astro/app.BOr2kwae.js +115 -0
  271. package/dist/serve/site-ui/_astro/app.DhAcImFD.js +1 -0
  272. package/dist/serve/site-ui/_astro/app.pMSnN6Qw.css +1 -0
  273. package/dist/serve/site-ui/_astro/{chess-showcase.Dh5D8kqe.js → chess-showcase.Bn_pP6UJ.js} +2 -2
  274. package/dist/serve/site-ui/_astro/{example-runtime.CuyAjjiG.js → example-runtime.CXopTGv7.js} +1 -1
  275. package/dist/serve/site-ui/_astro/index.Tb-31efc.css +1 -0
  276. package/dist/serve/site-ui/_astro/index.UkCBr-_0.css +1 -0
  277. package/dist/serve/site-ui/_astro/sandbox-controls.rOuZTOUG.js +510 -0
  278. package/dist/serve/site-ui/_astro/{seed.CSUkloMi.js → seed.03a08f9t.js} +2 -2
  279. package/dist/serve/site-ui/_astro/writes.BsPBG3dp.js +653 -0
  280. package/dist/serve/site-ui/auth/index.html +5 -3
  281. package/dist/serve/site-ui/david-east.jpg +0 -0
  282. package/dist/serve/site-ui/docs/_rhythm/index.html +6 -3
  283. package/dist/serve/site-ui/docs/_rhythm.md +1 -1
  284. package/dist/serve/site-ui/docs/agent/set-up-your-agent/index.html +18 -15
  285. package/dist/serve/site-ui/docs/agent/set-up-your-agent.md +16 -16
  286. package/dist/serve/site-ui/docs/agent/watch-and-review/index.html +6 -5
  287. package/dist/serve/site-ui/docs/agent/watch-and-review.md +1 -5
  288. package/dist/serve/site-ui/docs/agent/work-with-an-agent/index.html +8 -5
  289. package/dist/serve/site-ui/docs/agent/work-with-an-agent.md +4 -4
  290. package/dist/serve/site-ui/docs/ai-compat/index.html +5 -2
  291. package/dist/serve/site-ui/docs/api-reference/index.html +13 -2
  292. package/dist/serve/site-ui/docs/api-reference.md +8 -0
  293. package/dist/serve/site-ui/docs/app-compat/index.html +5 -2
  294. package/dist/serve/site-ui/docs/auth-compat/index.html +7 -4
  295. package/dist/serve/site-ui/docs/auth-compat.md +2 -2
  296. package/dist/serve/site-ui/docs/build/ai-logic/index.html +10 -2
  297. package/dist/serve/site-ui/docs/build/ai-logic.md +6 -0
  298. package/dist/serve/site-ui/docs/build/authentication/index.html +7 -4
  299. package/dist/serve/site-ui/docs/build/authentication.md +2 -2
  300. package/dist/serve/site-ui/docs/build/cloud-firestore/index.html +5 -2
  301. package/dist/serve/site-ui/docs/build/cloud-messaging/index.html +5 -2
  302. package/dist/serve/site-ui/docs/build/cloud-storage/index.html +6 -3
  303. package/dist/serve/site-ui/docs/build/cloud-storage.md +1 -1
  304. package/dist/serve/site-ui/docs/build/realtime-database/index.html +9 -6
  305. package/dist/serve/site-ui/docs/build/realtime-database.md +4 -4
  306. package/dist/serve/site-ui/docs/conformance-scores/index.html +10 -3
  307. package/dist/serve/site-ui/docs/conformance-scores.md +5 -1
  308. package/dist/serve/site-ui/docs/create-pyric-reference-api/index.html +6 -3
  309. package/dist/serve/site-ui/docs/create-pyric-reference-api.md +1 -1
  310. package/dist/serve/site-ui/docs/database-compat/index.html +48 -45
  311. package/dist/serve/site-ui/docs/database-compat.md +43 -43
  312. package/dist/serve/site-ui/docs/examples/chess/index.html +5 -2
  313. package/dist/serve/site-ui/docs/examples/index.html +5 -2
  314. package/dist/serve/site-ui/docs/firestore-compat/index.html +8 -5
  315. package/dist/serve/site-ui/docs/firestore-compat.md +3 -3
  316. package/dist/serve/site-ui/docs/firestore-flutter-compat/index.html +319 -0
  317. package/dist/serve/site-ui/docs/firestore-flutter-compat.md +344 -0
  318. package/dist/serve/site-ui/docs/functions-rtdb-compat/index.html +5 -2
  319. package/dist/serve/site-ui/docs/get-started/backend-bundlers/index.html +105 -0
  320. package/dist/serve/site-ui/docs/get-started/backend-bundlers.md +165 -0
  321. package/dist/serve/site-ui/docs/get-started/how-the-swap-works/index.html +9 -6
  322. package/dist/serve/site-ui/docs/get-started/how-the-swap-works.md +5 -5
  323. package/dist/serve/site-ui/docs/get-started/nextjs/index.html +9 -6
  324. package/dist/serve/site-ui/docs/get-started/nextjs.md +4 -4
  325. package/dist/serve/site-ui/docs/get-started/start-building/index.html +14 -9
  326. package/dist/serve/site-ui/docs/get-started/start-building.md +16 -10
  327. package/dist/serve/site-ui/docs/get-started/vite/index.html +6 -3
  328. package/dist/serve/site-ui/docs/get-started/vite.md +1 -1
  329. package/dist/serve/site-ui/docs/index.json +3128 -1613
  330. package/dist/serve/site-ui/docs/messaging-compat/index.html +5 -2
  331. package/dist/serve/site-ui/docs/observe/resolve-runtime-status/index.html +5 -2
  332. package/dist/serve/site-ui/docs/observe/see-whats-happening/index.html +6 -4
  333. package/dist/serve/site-ui/docs/observe/see-whats-happening.md +2 -4
  334. package/dist/serve/site-ui/docs/observe/shape-your-data/index.html +9 -6
  335. package/dist/serve/site-ui/docs/observe/shape-your-data.md +4 -4
  336. package/dist/serve/site-ui/docs/overview/index.html +16 -10
  337. package/dist/serve/site-ui/docs/overview.md +19 -11
  338. package/dist/serve/site-ui/docs/pyric-admin-app-reference-api/index.html +5 -2
  339. package/dist/serve/site-ui/docs/pyric-admin-auth-reference-api/index.html +5 -2
  340. package/dist/serve/site-ui/docs/pyric-admin-database-reference-api/index.html +5 -2
  341. package/dist/serve/site-ui/docs/pyric-admin-firestore-reference-api/index.html +8 -5
  342. package/dist/serve/site-ui/docs/pyric-admin-firestore-reference-api.md +3 -3
  343. package/dist/serve/site-ui/docs/pyric-admin-messaging-reference-api/index.html +5 -2
  344. package/dist/serve/site-ui/docs/pyric-admin-reference-api/index.html +501 -0
  345. package/dist/serve/site-ui/docs/pyric-admin-reference-api.md +587 -0
  346. package/dist/serve/site-ui/docs/pyric-admin-storage-reference-api/index.html +5 -2
  347. package/dist/serve/site-ui/docs/pyric-ai-reference-api/index.html +5 -2
  348. package/dist/serve/site-ui/docs/pyric-ai-scripting-reference-api/index.html +5 -2
  349. package/dist/serve/site-ui/docs/pyric-analytics-reference-api/index.html +124 -0
  350. package/dist/serve/site-ui/docs/pyric-analytics-reference-api.md +287 -0
  351. package/dist/serve/site-ui/docs/pyric-app-check-reference-api/index.html +87 -0
  352. package/dist/serve/site-ui/docs/pyric-app-check-reference-api.md +199 -0
  353. package/dist/serve/site-ui/docs/pyric-app-reference-api/index.html +5 -2
  354. package/dist/serve/site-ui/docs/pyric-auth-reference-api/index.html +10 -3
  355. package/dist/serve/site-ui/docs/pyric-auth-reference-api.md +2 -1
  356. package/dist/serve/site-ui/docs/pyric-cli-assurance-browser-reference-api/index.html +5 -2
  357. package/dist/serve/site-ui/docs/pyric-cli-assurance-reference-api/index.html +5 -2
  358. package/dist/serve/site-ui/docs/pyric-cli-bridge-client-reference-api/index.html +6 -3
  359. package/dist/serve/site-ui/docs/pyric-cli-bridge-client-reference-api.md +1 -1
  360. package/dist/serve/site-ui/docs/pyric-cli-bridge-reference-api/index.html +5 -2
  361. package/dist/serve/site-ui/docs/pyric-cli-bundler-reference-api/index.html +56 -0
  362. package/dist/serve/site-ui/docs/pyric-cli-bundler-reference-api.md +72 -0
  363. package/dist/serve/site-ui/docs/pyric-cli-conformance-browser-reference-api/index.html +6 -2
  364. package/dist/serve/site-ui/docs/pyric-cli-conformance-browser-reference-api.md +1 -0
  365. package/dist/serve/site-ui/docs/pyric-cli-conformance-docs-reference-api/index.html +5 -2
  366. package/dist/serve/site-ui/docs/pyric-cli-conformance-reference-api/index.html +6 -2
  367. package/dist/serve/site-ui/docs/pyric-cli-conformance-reference-api.md +1 -0
  368. package/dist/serve/site-ui/docs/pyric-cli-credentials-node-reference-api/index.html +5 -2
  369. package/dist/serve/site-ui/docs/pyric-cli-discover-reference-api/index.html +5 -2
  370. package/dist/serve/site-ui/docs/pyric-cli-next-reference-api/index.html +6 -3
  371. package/dist/serve/site-ui/docs/pyric-cli-next-reference-api.md +1 -1
  372. package/dist/serve/site-ui/docs/pyric-cli-register-app-bridge-reference-api/index.html +5 -2
  373. package/dist/serve/site-ui/docs/pyric-cli-register-reference-api/index.html +5 -2
  374. package/dist/serve/site-ui/docs/pyric-cli-remote-reference-api/index.html +39 -11
  375. package/dist/serve/site-ui/docs/pyric-cli-remote-reference-api.md +17 -9
  376. package/dist/serve/site-ui/docs/pyric-cli-serve-worker-reference-api/index.html +137 -94
  377. package/dist/serve/site-ui/docs/pyric-cli-serve-worker-reference-api.md +61 -1
  378. package/dist/serve/site-ui/docs/pyric-cli-verify-reference-api/index.html +6 -3
  379. package/dist/serve/site-ui/docs/pyric-cli-verify-reference-api.md +1 -1
  380. package/dist/serve/site-ui/docs/pyric-cli-vite-reference-api/index.html +6 -3
  381. package/dist/serve/site-ui/docs/pyric-cli-vite-reference-api.md +2 -2
  382. package/dist/serve/site-ui/docs/pyric-database-reference-api/index.html +167 -96
  383. package/dist/serve/site-ui/docs/pyric-database-reference-api.md +108 -2
  384. package/dist/serve/site-ui/docs/pyric-firestore-lite-reference-api/index.html +559 -0
  385. package/dist/serve/site-ui/docs/pyric-firestore-lite-reference-api.md +1240 -0
  386. package/dist/serve/site-ui/docs/pyric-firestore-reference-api/index.html +44 -12
  387. package/dist/serve/site-ui/docs/pyric-firestore-reference-api.md +18 -8
  388. package/dist/serve/site-ui/docs/pyric-functions-reference-api/index.html +67 -0
  389. package/dist/serve/site-ui/docs/pyric-functions-reference-api.md +149 -0
  390. package/dist/serve/site-ui/docs/pyric-messaging-reference-api/index.html +10 -4
  391. package/dist/serve/site-ui/docs/pyric-messaging-reference-api.md +5 -2
  392. package/dist/serve/site-ui/docs/pyric-messaging-sw-reference-api/index.html +10 -4
  393. package/dist/serve/site-ui/docs/pyric-messaging-sw-reference-api.md +5 -2
  394. package/dist/serve/site-ui/docs/pyric-performance-reference-api/index.html +35 -0
  395. package/dist/serve/site-ui/docs/pyric-performance-reference-api.md +69 -0
  396. package/dist/serve/site-ui/docs/pyric-remote-config-reference-api/index.html +132 -0
  397. package/dist/serve/site-ui/docs/pyric-remote-config-reference-api.md +307 -0
  398. package/dist/serve/site-ui/docs/pyric-rules-reference-api/index.html +5 -2
  399. package/dist/serve/site-ui/docs/pyric-sandbox-database-reference-api/index.html +56 -18
  400. package/dist/serve/site-ui/docs/pyric-sandbox-database-reference-api.md +48 -9
  401. package/dist/serve/site-ui/docs/pyric-sandbox-firestore-reference-api/index.html +6 -3
  402. package/dist/serve/site-ui/docs/pyric-sandbox-firestore-reference-api.md +2 -2
  403. package/dist/serve/site-ui/docs/pyric-sandbox-reference-api/index.html +243 -50
  404. package/dist/serve/site-ui/docs/pyric-sandbox-reference-api.md +148 -31
  405. package/dist/serve/site-ui/docs/pyric-storage-reference-api/index.html +26 -5
  406. package/dist/serve/site-ui/docs/pyric-storage-reference-api.md +24 -2
  407. package/dist/serve/site-ui/docs/pyric-ui-agents-reference-api/index.html +30 -97
  408. package/dist/serve/site-ui/docs/pyric-ui-agents-reference-api.md +20 -51
  409. package/dist/serve/site-ui/docs/pyric-ui-auth-hooks-reference-api/index.html +5 -2
  410. package/dist/serve/site-ui/docs/pyric-ui-auth-reference-api/index.html +6 -3
  411. package/dist/serve/site-ui/docs/pyric-ui-auth-reference-api.md +1 -1
  412. package/dist/serve/site-ui/docs/pyric-ui-events-hooks-reference-api/index.html +5 -2
  413. package/dist/serve/site-ui/docs/pyric-ui-events-reference-api/index.html +5 -2
  414. package/dist/serve/site-ui/docs/pyric-ui-firestore-hooks-reference-api/index.html +5 -2
  415. package/dist/serve/site-ui/docs/pyric-ui-firestore-reference-api/index.html +6 -3
  416. package/dist/serve/site-ui/docs/pyric-ui-firestore-reference-api.md +1 -1
  417. package/dist/serve/site-ui/docs/pyric-ui-primitives-reference-api/index.html +128 -27
  418. package/dist/serve/site-ui/docs/pyric-ui-primitives-reference-api.md +58 -5
  419. package/dist/serve/site-ui/docs/pyric-ui-rtdb-reference-api/index.html +5 -2
  420. package/dist/serve/site-ui/docs/pyric-ui-rules-hooks-reference-api/index.html +5 -2
  421. package/dist/serve/site-ui/docs/pyric-ui-rules-reference-api/index.html +5 -2
  422. package/dist/serve/site-ui/docs/pyric-ui-storage-hooks-reference-api/index.html +5 -2
  423. package/dist/serve/site-ui/docs/pyric-ui-storage-reference-api/index.html +8 -6
  424. package/dist/serve/site-ui/docs/pyric-ui-storage-reference-api.md +3 -4
  425. package/dist/serve/site-ui/docs/pyric-ui-traffic-hooks-reference-api/index.html +5 -2
  426. package/dist/serve/site-ui/docs/pyric-ui-traffic-reference-api/index.html +5 -2
  427. package/dist/serve/site-ui/docs/reference/cli/index.html +156 -0
  428. package/dist/serve/site-ui/docs/reference/cli.md +120 -0
  429. package/dist/serve/site-ui/docs/rules-compat/index.html +14 -3
  430. package/dist/serve/site-ui/docs/rules-compat.md +9 -1
  431. package/dist/serve/site-ui/docs/secure/audit-your-rules/index.html +5 -2
  432. package/dist/serve/site-ui/docs/secure/firestore-rules-limits/index.html +5 -2
  433. package/dist/serve/site-ui/docs/secure/read-a-denial/index.html +6 -3
  434. package/dist/serve/site-ui/docs/secure/read-a-denial.md +1 -1
  435. package/dist/serve/site-ui/docs/secure/rtdb-rules-in-typescript/index.html +5 -2
  436. package/dist/serve/site-ui/docs/secure/rules-standard-library/index.html +5 -2
  437. package/dist/serve/site-ui/docs/secure/secure-it-with-rules/index.html +5 -2
  438. package/dist/serve/site-ui/docs/secure/simulate-and-lint/index.html +5 -2
  439. package/dist/serve/site-ui/docs/secure/write-a-rules-test-suite/index.html +5 -2
  440. package/dist/serve/site-ui/docs/ship/ship-to-production/index.html +7 -4
  441. package/dist/serve/site-ui/docs/ship/ship-to-production.md +2 -2
  442. package/dist/serve/site-ui/docs/ship/test-in-node/index.html +9 -6
  443. package/dist/serve/site-ui/docs/ship/test-in-node.md +4 -4
  444. package/dist/serve/site-ui/docs/storage-compat/index.html +17 -14
  445. package/dist/serve/site-ui/docs/storage-compat.md +12 -12
  446. package/dist/serve/site-ui/docs/trust/how-we-know-it-matches-firebase/index.html +5 -2
  447. package/dist/serve/site-ui/docs/trust/rules-standard-library/index.html +5 -2
  448. package/dist/serve/site-ui/docs/trust/versioning-and-compatibility/index.html +5 -2
  449. package/dist/serve/site-ui/docs/tutorial/index.html +10 -7
  450. package/dist/serve/site-ui/docs/tutorial.md +4 -4
  451. package/dist/serve/site-ui/examples/chess/index.html +4 -2
  452. package/dist/serve/site-ui/firestore/index.html +5 -3
  453. package/dist/serve/site-ui/hero-charcoal.jpg +0 -0
  454. package/dist/serve/site-ui/index.html +9 -7
  455. package/dist/serve/site-ui/llms.txt +13 -3
  456. package/dist/serve/site-ui/pyric-campfire-full.png +0 -0
  457. package/dist/serve/site-ui/pyric-campfire.png +0 -0
  458. package/dist/serve/site-ui/rtdb/index.html +5 -3
  459. package/dist/serve/site-ui/settings/index.html +5 -3
  460. package/dist/serve/site-ui/storage/index.html +5 -3
  461. package/dist/serve/site-ui/studio/index.html +13 -0
  462. package/dist/serve/site-ui/studio-routes.json +1 -1
  463. package/dist/serve/site-ui/traffic/index.html +5 -3
  464. package/dist/serve/studio/disk-workspace.d.ts.map +1 -1
  465. package/dist/serve/studio/disk-workspace.js +64 -2
  466. package/dist/serve/studio/disk-workspace.js.map +1 -1
  467. package/dist/serve/studio/routes.d.ts +9 -0
  468. package/dist/serve/studio/routes.d.ts.map +1 -1
  469. package/dist/serve/studio/routes.js +47 -7
  470. package/dist/serve/studio/routes.js.map +1 -1
  471. package/dist/serve/vite-ai-config.d.ts.map +1 -1
  472. package/dist/serve/vite-ai-config.js +38 -8
  473. package/dist/serve/vite-ai-config.js.map +1 -1
  474. package/dist/serve/vite-module-swap.d.ts.map +1 -1
  475. package/dist/serve/vite-module-swap.js +0 -28
  476. package/dist/serve/vite-module-swap.js.map +1 -1
  477. package/dist/serve/vite-plugin.d.ts +7 -7
  478. package/dist/serve/vite-plugin.js +1 -1
  479. package/dist/serve/vite-plugin.js.map +1 -1
  480. package/dist/serve/vite-sandbox-generation.d.ts +1 -1
  481. package/dist/serve/vite-sandbox-generation.d.ts.map +1 -1
  482. package/dist/serve/vite-sandbox-generation.js +13 -1
  483. package/dist/serve/vite-sandbox-generation.js.map +1 -1
  484. package/dist/serve/worker/client/auth.js +1 -2
  485. package/dist/serve/worker/client/auth.js.map +1 -1
  486. package/dist/serve/worker/client/core.d.ts +21 -1
  487. package/dist/serve/worker/client/core.d.ts.map +1 -1
  488. package/dist/serve/worker/client/core.js +79 -3
  489. package/dist/serve/worker/client/core.js.map +1 -1
  490. package/dist/serve/worker/client/disconnect.js +1 -1
  491. package/dist/serve/worker/client/disconnect.js.map +1 -1
  492. package/dist/serve/worker/client/presence.d.ts.map +1 -1
  493. package/dist/serve/worker/client/presence.js +18 -5
  494. package/dist/serve/worker/client/presence.js.map +1 -1
  495. package/dist/serve/worker/client.d.ts +1 -1
  496. package/dist/serve/worker/client.d.ts.map +1 -1
  497. package/dist/serve/worker/client.js +1 -1
  498. package/dist/serve/worker/client.js.map +1 -1
  499. package/dist/serve/worker/context-resolver.d.ts +30 -0
  500. package/dist/serve/worker/context-resolver.d.ts.map +1 -0
  501. package/dist/serve/worker/context-resolver.js +44 -0
  502. package/dist/serve/worker/context-resolver.js.map +1 -0
  503. package/dist/serve/worker/entry.js +23 -19
  504. package/dist/serve/worker/entry.js.map +1 -1
  505. package/dist/serve/worker/host/core.d.ts +1 -0
  506. package/dist/serve/worker/host/core.d.ts.map +1 -1
  507. package/dist/serve/worker/host/core.js +12 -6
  508. package/dist/serve/worker/host/core.js.map +1 -1
  509. package/dist/serve/worker/host/storage.js +2 -2
  510. package/dist/serve/worker/host-ai.d.ts.map +1 -1
  511. package/dist/serve/worker/host-ai.js +15 -0
  512. package/dist/serve/worker/host-ai.js.map +1 -1
  513. package/dist/serve/worker/host-auth.js +1 -2
  514. package/dist/serve/worker/host-auth.js.map +1 -1
  515. package/dist/serve/worker/index.d.ts +1 -1
  516. package/dist/serve/worker/index.d.ts.map +1 -1
  517. package/dist/serve/worker/index.js +2 -2
  518. package/dist/serve/worker/index.js.map +1 -1
  519. package/dist/serve/worker/port-lifecycle.d.ts +18 -0
  520. package/dist/serve/worker/port-lifecycle.d.ts.map +1 -0
  521. package/dist/serve/worker/port-lifecycle.js +28 -0
  522. package/dist/serve/worker/port-lifecycle.js.map +1 -0
  523. package/dist/serve/worker/protocol.d.ts +4 -0
  524. package/dist/serve/worker/protocol.d.ts.map +1 -1
  525. package/dist/serve/worker/protocol.js.map +1 -1
  526. package/dist/serve/worker/serve-init.d.ts.map +1 -1
  527. package/dist/serve/worker/serve-init.js +15 -3
  528. package/dist/serve/worker/serve-init.js.map +1 -1
  529. package/dist/verify/fixture.d.ts +1 -1
  530. package/package.json +17 -6
  531. package/src/assurance/.generated/conformance-verdicts.ts +68 -1
  532. package/src/bridge/client/dispatch.ts +52 -56
  533. package/src/bridge/client/tool-family-factories.ts +34 -0
  534. package/src/bridge/server/mcp-contract.ts +15 -59
  535. package/src/bridge/server/peer.ts +24 -1
  536. package/src/bridge/server/tool-family-factories.ts +40 -0
  537. package/src/bridge/server/tool-metadata.ts +29 -61
  538. package/src/bridge/tool-families.generated.ts +17 -0
  539. package/src/bridge/tool-families.ts +87 -0
  540. package/src/bridge/tool-family-records/conformance.ts +6 -0
  541. package/src/bridge/tool-family-records/firestore-data.ts +15 -0
  542. package/src/bridge/tool-family-records/firestore-inspect.ts +6 -0
  543. package/src/bridge/tool-family-records/firestore-rules.ts +15 -0
  544. package/src/bridge/tool-family-records/firestore-simulator.ts +16 -0
  545. package/src/bridge/tool-family-records/rtdb-inspection.ts +6 -0
  546. package/src/bundler/externals.ts +55 -0
  547. package/src/bundler/index.ts +21 -0
  548. package/src/cli/cli.test.ts +2 -46
  549. package/src/cli/index.ts +48 -42
  550. package/src/cli/inlined-sdk-scanner.ts +77 -0
  551. package/src/cli/mcp-proxy.ts +4 -4
  552. package/src/cli/parse-args.ts +61 -15
  553. package/src/cli/pyric-config.ts +45 -0
  554. package/src/cli/sandbox-interlock.ts +167 -0
  555. package/src/cli/{dev-runner.ts → sandbox-runner.ts} +142 -86
  556. package/src/cli/serve.ts +182 -115
  557. package/src/cli/snapshot.ts +5 -5
  558. package/src/cli/unsupported-runtime.ts +68 -0
  559. package/src/cli/verify.ts +1 -1
  560. package/src/conformance/.generated/can-i-use-browser.ts +2 -2
  561. package/src/conformance/.generated/can-i-use.ts +2 -2
  562. package/src/conformance/.generated/conformance-docs.ts +1 -1
  563. package/src/functions-rtdb/child.ts +115 -21
  564. package/src/functions-rtdb/development-runtime.ts +5 -1
  565. package/src/functions-rtdb/project.ts +8 -8
  566. package/src/google-endpoints.ts +155 -0
  567. package/src/next/guard.ts +1 -1
  568. package/src/next/runtime-env.ts +5 -0
  569. package/src/next/with-pyric.ts +1 -1
  570. package/src/register/beacon.ts +232 -0
  571. package/src/register/index.ts +68 -6
  572. package/src/register/net-guard.ts +567 -0
  573. package/src/remote/index.ts +9 -9
  574. package/src/serve/ai-diagnostics-relay.ts +243 -0
  575. package/src/serve/ai-proxy.ts +327 -0
  576. package/src/serve/ai-status.ts +109 -0
  577. package/src/serve/ai-terminal-blocks.ts +210 -0
  578. package/src/serve/ai-terminal-text.ts +52 -0
  579. package/src/serve/beacon-route.ts +141 -0
  580. package/src/serve/bundler.ts +10 -10
  581. package/src/serve/entries/active-auth-registry.ts +56 -0
  582. package/src/serve/entries/active-auth.ts +100 -0
  583. package/src/serve/entries/ai.ts +27 -1
  584. package/src/serve/entries/auth-helper-core.ts +5 -0
  585. package/src/serve/entries/auth-helper-dom.ts +27 -3
  586. package/src/serve/entries/auth-helper-runtime.ts +1 -1
  587. package/src/serve/entries/auth.ts +8 -0
  588. package/src/serve/entries/bridge-url.ts +1 -1
  589. package/src/serve/entries/firestore.ts +3 -3
  590. package/src/serve/entries/init.ts +78 -3
  591. package/src/serve/entries/keepalive.ts +1 -1
  592. package/src/serve/entries/runtime.ts +29 -14
  593. package/src/serve/entries/storage.ts +1 -1
  594. package/src/serve/entries/worker-runtime.ts +1 -1
  595. package/src/serve/init-payload.ts +4 -0
  596. package/src/serve/namespace.ts +117 -145
  597. package/src/serve/rules.ts +47 -22
  598. package/src/serve/runtime/chip-config.ts +16 -2
  599. package/src/serve/runtime/chip-dialog.ts +366 -0
  600. package/src/serve/runtime/chip-install.ts +10 -4
  601. package/src/serve/runtime/chip-user-search.ts +391 -0
  602. package/src/serve/runtime/chip.ts +177 -15
  603. package/src/serve/runtime/identity.ts +26 -0
  604. package/src/serve/runtime/manifest.ts +1 -1
  605. package/src/serve/runtime/status.ts +24 -0
  606. package/src/serve/sandbox-session.ts +19 -4
  607. package/src/serve/server.ts +18 -1
  608. package/src/serve/studio/disk-workspace.ts +76 -2
  609. package/src/serve/studio/routes.ts +63 -7
  610. package/src/serve/vite-ai-config.ts +37 -7
  611. package/src/serve/vite-module-swap.ts +0 -28
  612. package/src/serve/vite-plugin.ts +8 -8
  613. package/src/serve/vite-sandbox-generation.ts +16 -1
  614. package/src/serve/worker/client/auth.ts +1 -1
  615. package/src/serve/worker/client/core.ts +80 -3
  616. package/src/serve/worker/client/disconnect.ts +1 -1
  617. package/src/serve/worker/client/presence.ts +25 -5
  618. package/src/serve/worker/client.ts +1 -1
  619. package/src/serve/worker/context-resolver.ts +60 -0
  620. package/src/serve/worker/entry.ts +22 -18
  621. package/src/serve/worker/host/core.ts +9 -7
  622. package/src/serve/worker/host/storage.ts +2 -2
  623. package/src/serve/worker/host-ai.ts +15 -0
  624. package/src/serve/worker/host-auth.ts +1 -1
  625. package/src/serve/worker/index.ts +4 -1
  626. package/src/serve/worker/port-lifecycle.ts +45 -0
  627. package/src/serve/worker/protocol.ts +2 -1
  628. package/src/serve/worker/serve-init.ts +14 -3
  629. package/src/verify/fixture.ts +1 -1
  630. package/README.md.orig +0 -145
  631. package/dist/cli/dev-runner.d.ts.map +0 -1
  632. package/dist/cli/dev-runner.js.map +0 -1
  633. package/dist/serve/site-ui/_astro/_slug_.CXh9yTP1.css +0 -1
  634. package/dist/serve/site-ui/_astro/_slug_.CupVK4TM.css +0 -1
  635. package/dist/serve/site-ui/_astro/_studio_.CfxiQWkk.css +0 -1
  636. package/dist/serve/site-ui/_astro/app.BsFsMjn0.css +0 -1
  637. package/dist/serve/site-ui/_astro/app.Ce3MTLQm.js +0 -1
  638. package/dist/serve/site-ui/_astro/app.taqzyjD0.js +0 -11
  639. package/dist/serve/site-ui/_astro/sandbox-controls.BP4M5f1M.js +0 -1169
  640. package/dist/serve/site-ui/_astro/writes.C57paAj2.js +0 -99
  641. package/dist/serve/site-ui/docs/trust/storage-rules-stdlib-research/index.html +0 -582
  642. package/dist/serve/site-ui/docs/trust/storage-rules-stdlib-research.md +0 -448
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * `@pyric/cli/register` — the Node substitution seam (adoption layer 2).
3
3
  *
4
- * Loaded via `node --import @pyric/cli/register` (which `pyric dev` injects
5
- * through NODE_OPTIONS), it makes the user's UNCHANGED `firebase-admin` /
6
- * `firebase` imports resolve to `pyric-admin` / `pyric`, every subpath 1:1,
4
+ * Loaded via `node --import @pyric/cli/register` (which `pyric sandbox`
5
+ * injects through NODE_OPTIONS), it makes the user's UNCHANGED `firebase-admin`
6
+ * and `firebase` imports resolve to `pyric-admin` and `pyric`, every subpath 1:1,
7
7
  * and installs the sandbox-factory global that `pyric-admin`'s ambient
8
8
  * `initializeApp()` consumes.
9
9
  *
@@ -17,6 +17,17 @@
17
17
  * `require()` and `import`. On older 22.x it falls back to
18
18
  * `module.register()` (ESM-only) with a warning that CJS require() is not
19
19
  * rewritten.
20
+ *
21
+ * On activation it also installs the NETWORK GUARD (`./net-guard.js`), which
22
+ * reports egress from this process to live Google/Firebase endpoints, or
23
+ * refuses it under `PYRIC_GUARD=block`. See that module for the policy and the
24
+ * `PYRIC_GUARD` and `PYRIC_GUARD_ALLOW` knobs.
25
+ *
26
+ * Finally it emits the HANDSHAKE BEACON (`./beacon.js`): a fire-and-forget
27
+ * `POST /__pyric/beacon` when the activator carries a bridge URL, plus a
28
+ * stderr line when the developer asked for detail. That is how `pyric sandbox`
29
+ * learns that interception actually reached this child rather than assuming
30
+ * it did.
20
31
  */
21
32
  import Module from 'node:module';
22
33
  import { readFileSync } from 'node:fs';
@@ -24,6 +35,8 @@ import { dirname, join } from 'node:path';
24
35
  import { pathToFileURL } from 'node:url';
25
36
  import { mapFirebaseSpecifier } from './mapping.js';
26
37
  import { resolveEsmOnlySubpath } from './esm-exports.js';
38
+ import { installNetGuard, parseGuardMode, type GuardMode } from './net-guard.js';
39
+ import { emitBeacon } from './beacon.js';
27
40
  import { remoteSandbox } from '../remote/index.js';
28
41
 
29
42
  /** The shared seam with pyric-admin's ambient init: a synchronous factory
@@ -89,7 +102,30 @@ function resolveEsmOnlyForRequire(mapped: string): string | null {
89
102
  }
90
103
 
91
104
  function activate(): void {
105
+ // FIRST, before any hook or global: the network guard.
106
+ //
107
+ // Order matters in one direction only. Everything after this line makes the
108
+ // process load MORE code (the resolution hooks pull in the pyric mirrors,
109
+ // the factory global pulls in the remote sandbox) and any of it could open
110
+ // a socket. Installing the guard first leaves no window in which
111
+ // sandbox-substituted code runs unguarded. The reverse ordering buys
112
+ // nothing: the guard mutates globals only (`undici.globalDispatcher.1`,
113
+ // `net`/`tls` connect) and depends on nothing the hooks establish.
114
+ //
115
+ // It stays BELOW the NODE_ENV=production refusal, deliberately. A refused
116
+ // process is a real production run that we declined to touch, and warning
117
+ // about its perfectly legitimate Google traffic, let alone blocking it,
118
+ // would be actively harmful. `PYRIC_SANDBOX` plus no refusal is the only
119
+ // state in which "traffic to live Google is a bug" is a true statement.
120
+ const guard = installNetGuard();
121
+
122
+ // Whether module resolution is actually being intercepted. Both branches
123
+ // below install SOMETHING, but a runtime with neither API installs nothing,
124
+ // which is precisely the state the beacon exists to make visible.
125
+ let hooksInstalled = false;
126
+
92
127
  if (typeof moduleApi.registerHooks === 'function') {
128
+ hooksInstalled = true;
93
129
  moduleApi.registerHooks({
94
130
  resolve(specifier, context, nextResolve) {
95
131
  const mapped = mapFirebaseSpecifier(specifier, context.parentURL);
@@ -112,10 +148,11 @@ function activate(): void {
112
148
  });
113
149
  } else {
114
150
  process.stderr.write(
115
- '@pyric/cli/register: this Node version lacks module.registerHooks (needs >= 22.15) ' +
116
- 'falling back to module.register: ESM imports of firebase-admin/firebase are rewritten, ' +
151
+ '@pyric/cli/register: this Node version lacks module.registerHooks (needs >= 22.15). ' +
152
+ 'Falling back to module.register: ESM imports of firebase-admin/firebase are rewritten, ' +
117
153
  "but CJS require('firebase-admin') is NOT intercepted. Upgrade Node to >= 22.15 for full coverage.\n",
118
154
  );
155
+ hooksInstalled = typeof moduleApi.register === 'function';
119
156
  moduleApi.register?.(new URL('./hooks.js', import.meta.url));
120
157
  }
121
158
 
@@ -125,9 +162,34 @@ function activate(): void {
125
162
  remoteSandbox(opts);
126
163
 
127
164
  process.stderr.write(
128
- `@pyric/cli/register: active firebase-admin/firebase imports now resolve to the ` +
165
+ `@pyric/cli/register: active. firebase-admin/firebase imports now resolve to the ` +
129
166
  `pyric sandbox (PYRIC_SANDBOX=${process.env.PYRIC_SANDBOX}).\n`,
130
167
  );
168
+
169
+ // LAST: the handshake beacon, after the guard, the hooks and the factory
170
+ // global are all in place. Its whole claim is "interception is live in this
171
+ // process", so it must not be able to run before that is true. See
172
+ // `./beacon.js` for the two channels and why the POST is fire-and-forget.
173
+ emitBeacon({
174
+ pid: process.pid,
175
+ guard: installedGuardMode(guard),
176
+ hooks: hooksInstalled,
177
+ sandbox: process.env.PYRIC_SANDBOX ?? '',
178
+ });
179
+ }
180
+
181
+ /**
182
+ * The net-guard mode actually in force, for the beacon to report.
183
+ *
184
+ * Policy: the installed guard is the authority when there is one. There is no
185
+ * guard object in exactly one case, `PYRIC_GUARD=off` (the `PYRIC_SANDBOX`
186
+ * gate `installNetGuard` shares with this module has already passed by the
187
+ * time it runs), and re-parsing the env is how that case names itself rather
188
+ * than guessing a default.
189
+ */
190
+ function installedGuardMode(guard: { mode: GuardMode } | null): GuardMode {
191
+ if (guard !== null) return guard.mode;
192
+ return parseGuardMode(process.env.PYRIC_GUARD);
131
193
  }
132
194
 
133
195
  /** Whether this process's firebase-admin/firebase imports are being rewritten
@@ -0,0 +1,567 @@
1
+ /**
2
+ * The runtime network guard: the enforcement half of the production-leak
3
+ * invariant.
4
+ *
5
+ * A sandboxed app's Firebase traffic all routes to the local `/__pyric/*`
6
+ * namespace. So a pyric-launched process that opens a connection to a real
7
+ * Google/Firebase endpoint has escaped the sandbox: it is reading or writing
8
+ * live production data with the developer believing otherwise. This module
9
+ * detects that egress and, depending on one knob, warns about it or fails it.
10
+ *
11
+ * Where it hooks, and why exactly there
12
+ * -------------------------------------
13
+ * 1. `Symbol.for('undici.globalDispatcher.1')`, the undici global dispatcher.
14
+ * Measured against Next 15.5 / Node 24 / undici 7, this one seam covers
15
+ * Node route handlers, edge route handlers and middleware, under both the
16
+ * webpack and turbopack dev servers. Patching `globalThis.fetch` does not:
17
+ * the edge sandbox bundles its own undici, and that copy's
18
+ * `getGlobalDispatcher()` reads the host realm's symbol, which is precisely
19
+ * why hooking the dispatcher reaches it and hooking `fetch` does not.
20
+ *
21
+ * Three mechanics the seam depends on:
22
+ * - undici installs the property `configurable: false, writable: true`, so
23
+ * we install by plain assignment. A `defineProperty` with
24
+ * `configurable: true` throws a TypeError and takes the dev server down
25
+ * with it. Accessor traps are useless anyway, because
26
+ * `setGlobalDispatcher` uses `defineProperty`, which bypasses setters.
27
+ * - The property does not exist until undici is first touched, and undici
28
+ * only installs a default agent when it finds the slot empty. So we
29
+ * materialize it first with `new Headers()` (loads undici, zero
30
+ * network) and wrap whatever real Agent that produces.
31
+ * - The `handler` argument of `dispatch(opts, handler)` must pass through
32
+ * opaque and by identity. Edge hands a v6-shaped handler to the host's
33
+ * v7 Agent and that cross-version handoff only survives untouched. We
34
+ * read `opts.origin` and nothing else.
35
+ *
36
+ * 2. `net.connect` / `net.createConnection` / `tls.connect`, plus the
37
+ * `createConnection` on the `http.Agent` and `https.Agent` prototypes: the
38
+ * backstop for traffic that never goes through undici, such as
39
+ * `http.request`, gRPC, database drivers, anything holding a raw socket.
40
+ * Same catalog, same policy. (undici itself connects through `net.connect`,
41
+ * so a warn-mode fetch would report twice; the once-per-host dedupe below
42
+ * collapses that.)
43
+ *
44
+ * The Agent prototypes need their own patch because
45
+ * `http.Agent.prototype.createConnection` is a copied reference to
46
+ * `net.createConnection`, taken when `_http_agent` first loaded. If anything
47
+ * loaded `node:http` before this module ran, that copy is the unpatched
48
+ * function and every plain `http.request` would sail past the backstop,
49
+ * including a request to the metadata server. It is also why the socket
50
+ * patches are installed BEFORE the dispatcher is materialized: materializing
51
+ * loads undici, which loads `_http_agent`.
52
+ *
53
+ * Policy
54
+ * ------
55
+ * One knob, `PYRIC_GUARD=warn|block|off`, default `warn`:
56
+ * warn report the egress, let it through
57
+ * block report it and fail the request
58
+ * off no hooks at all, one notice line at install time
59
+ * The GCE metadata IP (`169.254.169.254`, `alwaysBlock` in the catalog) is
60
+ * refused in warn mode and cannot be allowlisted, since its only use from a
61
+ * dev process is credential theft. `off` is genuinely off, metadata IP
62
+ * included; the off notice says so out loud.
63
+ *
64
+ * A blocked fetch surfaces to app code as a bare `TypeError: fetch failed`
65
+ * (the reason is buried on `error.cause`), so the guard must log its own
66
+ * denial: the app's error will never explain itself.
67
+ *
68
+ * The allowlist seam
69
+ * ------------------
70
+ * `PYRIC_GUARD_ALLOW` is a comma/whitespace separated list of hosts or URLs,
71
+ * matched on label boundaries, permitting an otherwise-flagged catalog host
72
+ * (an allowlisted hit is still reported once). Env is the seam by design:
73
+ * - the AI engine baseUrls live in the user's Vite config
74
+ * (`PyricAiOptions.engine.baseUrl`, `serve/vite-ai-config.ts`), which is
75
+ * read by the Vite plugin inside the serve host, a different process from
76
+ * the one this module loads into, and not parsed by the CLI at all;
77
+ * - `pyric.json` is read asynchronously by `runServe` (`cli/pyric-config.ts`)
78
+ * and this module runs on the `--import` hot path of every child, where a
79
+ * synchronous config-file read has no business being.
80
+ * `cli/sandbox-runner.ts:buildChildEnv` spreads the parent env into the child,
81
+ * so anything the pyric process exports reaches every descendant for free
82
+ * (`NODE_OPTIONS` already propagates the register import the same way). To
83
+ * wire a `pyric.json` `guardAllow` through, the whole change is: add the field
84
+ * to `PyricConfig`, and have `buildChildEnv` set `PYRIC_GUARD_ALLOW` from it
85
+ * at the `cli/serve.ts` call site, where `pyricConfig` is already in scope.
86
+ *
87
+ * Bun and Deno are out of scope: neither evaluates Node loader hooks (the
88
+ * register module never loads there) and neither routes `fetch` through
89
+ * undici's global dispatcher. `installNetGuard` degrades to the socket
90
+ * backstop instead of throwing.
91
+ */
92
+ import { createRequire } from 'node:module';
93
+ import {
94
+ lookupGoogleEndpoint,
95
+ matchesHostSuffix,
96
+ normalizeHostname,
97
+ type GoogleEndpoint,
98
+ } from '../google-endpoints.js';
99
+
100
+ /** undici's global-dispatcher slot. Version-suffixed by undici itself. */
101
+ const UNDICI_GLOBAL_DISPATCHER = Symbol.for('undici.globalDispatcher.1');
102
+
103
+ /** Marks a rejection as the guard's, so callers can tell it from a DNS/TLS
104
+ * failure. A blocked `fetch` only exposes it as `error.cause.code`. */
105
+ export const GUARD_BLOCKED_CODE = 'PYRIC_GUARD_BLOCKED';
106
+
107
+ const LOG_PREFIX = '@pyric/cli/register: net-guard';
108
+
109
+ /** How often to check that nobody replaced the global dispatcher under us. */
110
+ const REASSERT_INTERVAL_MS = 5_000;
111
+
112
+ export type GuardMode = 'warn' | 'block' | 'off';
113
+
114
+ /** What the guard decided about one outbound connection. */
115
+ export interface EgressVerdict {
116
+ /** `warn` reported-and-permitted, `block` refused, `allow` allowlisted. */
117
+ readonly verdict: 'warn' | 'block' | 'allow';
118
+ /** Whether the connection may proceed. */
119
+ readonly permitted: boolean;
120
+ /**
121
+ * The hostname actually being contacted, which is what the developer needs
122
+ * in order to find the call. Not the catalog suffix: `cloudfunctions.net`
123
+ * does not tell you which region or project a callable went to.
124
+ */
125
+ readonly host: string;
126
+ /** The catalog suffix that matched (`host` when the match was exact). */
127
+ readonly endpoint: string;
128
+ /** Human service label, verbatim from the shared catalog. */
129
+ readonly service: string;
130
+ /** Present only for catalog entries that can never be a false positive. */
131
+ readonly alwaysBlock?: true;
132
+ }
133
+
134
+ /** `PYRIC_GUARD` → mode. Unset, empty or unrecognised all mean the safe
135
+ * default: report, do not break the developer's app. */
136
+ export function parseGuardMode(raw: string | undefined): GuardMode {
137
+ const value = (raw ?? '').trim().toLowerCase();
138
+ if (value === 'block') return 'block';
139
+ if (value === 'off') return 'off';
140
+ return 'warn';
141
+ }
142
+
143
+ /** `PYRIC_GUARD_ALLOW` → hostnames. Accepts bare hosts and full URLs, because
144
+ * the values it carries are configured as URLs (AI engine baseUrls). */
145
+ export function parseAllowHosts(raw: string | undefined): string[] {
146
+ if (!raw) return [];
147
+ const out: string[] = [];
148
+ for (const token of raw.split(/[\s,]+/)) {
149
+ const entry = token.trim();
150
+ if (entry.length === 0) continue;
151
+ out.push(hostnameOf(entry));
152
+ }
153
+ return out;
154
+ }
155
+
156
+ /** Only a trailing `:port` is stripped; a bare IPv6 address is left alone. */
157
+ const HOST_WITH_PORT = /^(.+):\d+$/;
158
+
159
+ /**
160
+ * Best-effort hostname from a host, `host:port`, or full URL. Normalization
161
+ * and suffix matching are the catalog's, so the guard and the catalog can
162
+ * never disagree about what a hostname is.
163
+ */
164
+ function hostnameOf(value: string): string {
165
+ const trimmed = value.trim();
166
+ if (trimmed.includes('://')) {
167
+ try {
168
+ return normalizeHostname(new URL(trimmed).hostname).replace(/^\[|\]$/g, '');
169
+ } catch {
170
+ // Not a parseable URL: fall through to the textual forms.
171
+ }
172
+ }
173
+ const withoutPath = trimmed.split('/')[0] ?? trimmed;
174
+ const portMatch = HOST_WITH_PORT.exec(withoutPath);
175
+ let hostPart: string;
176
+ if (portMatch === null) {
177
+ hostPart = withoutPath;
178
+ } else {
179
+ hostPart = portMatch[1]!;
180
+ }
181
+ return normalizeHostname(hostPart);
182
+ }
183
+
184
+ /**
185
+ * The whole verdict, pure: catalog lookup, then `alwaysBlock`, then the
186
+ * allowlist, then the mode. `null` means nothing to say: either not a
187
+ * production endpoint, or the guard is off.
188
+ */
189
+ export function evaluateEgress(
190
+ hostname: string,
191
+ policy: { mode: GuardMode; allow: readonly string[] },
192
+ ): EgressVerdict | null {
193
+ if (policy.mode === 'off') return null;
194
+ const host = hostnameOf(hostname);
195
+ if (host.length === 0) return null;
196
+ const entry: GoogleEndpoint | undefined = lookupGoogleEndpoint(host);
197
+ if (entry === undefined) return null;
198
+
199
+ // `alwaysBlock` outranks both the mode and the allowlist: the metadata
200
+ // server is never a legitimate destination for a sandboxed dev process, so
201
+ // there is no configuration that should be able to permit it.
202
+ if (entry.alwaysBlock === true) {
203
+ return {
204
+ verdict: 'block',
205
+ permitted: false,
206
+ host,
207
+ endpoint: entry.host,
208
+ service: entry.service,
209
+ alwaysBlock: true,
210
+ };
211
+ }
212
+
213
+ if (policy.allow.some((allowed) => matchesHostSuffix(host, allowed))) {
214
+ return { verdict: 'allow', permitted: true, host, endpoint: entry.host, service: entry.service };
215
+ }
216
+
217
+ if (policy.mode === 'block') {
218
+ return {
219
+ verdict: 'block',
220
+ permitted: false,
221
+ host,
222
+ endpoint: entry.host,
223
+ service: entry.service,
224
+ };
225
+ }
226
+ return { verdict: 'warn', permitted: true, host, endpoint: entry.host, service: entry.service };
227
+ }
228
+
229
+ /** One stderr line per verdict: structured (fixed leading fields, so it is
230
+ * greppable) and attributable (service + transport + initiating command).
231
+ * The request PATH is deliberately never logged: it carries ids and tokens. */
232
+ export function formatGuardLine(
233
+ verdict: EgressVerdict,
234
+ transport: 'fetch' | 'socket',
235
+ context: string | undefined,
236
+ ): string {
237
+ let where = `via ${transport}`;
238
+ if (context !== undefined && context.length > 0) where = `${where} from ${context}`;
239
+ const head = `${LOG_PREFIX} ${verdict.verdict.toUpperCase()} ${verdict.host} (${verdict.service}) ${where}:`;
240
+ const tail = 'Further attempts to this host are not logged.';
241
+ if (verdict.verdict === 'allow') {
242
+ return `${head} live production egress permitted by PYRIC_GUARD_ALLOW. ${tail}\n`;
243
+ }
244
+ if (verdict.verdict === 'warn') {
245
+ return (
246
+ `${head} LIVE production egress. A sandboxed app routes Firebase traffic to /__pyric/*, ` +
247
+ `so this is reaching real data. Set PYRIC_GUARD=block to fail these requests instead. ${tail}\n`
248
+ );
249
+ }
250
+ let why: string;
251
+ if (verdict.alwaysBlock === true) {
252
+ why = 'the credential metadata server is refused in every mode except PYRIC_GUARD=off';
253
+ } else {
254
+ why = 'live production egress refused (PYRIC_GUARD=block)';
255
+ }
256
+ // What the app actually observes differs by seam: undici swallows our throw
257
+ // into the opaque `TypeError: fetch failed`, while a raw socket caller gets
258
+ // the error itself. Say which, or the developer cannot connect the two.
259
+ let surfaces: string;
260
+ if (transport === 'fetch') {
261
+ surfaces = `the caller sees \`TypeError: fetch failed\` with cause ${GUARD_BLOCKED_CODE}`;
262
+ } else {
263
+ surfaces = `the caller sees an error with code ${GUARD_BLOCKED_CODE}`;
264
+ }
265
+ return `${head} ${why}; ${surfaces}. ${tail}\n`;
266
+ }
267
+
268
+ function blockedError(verdict: EgressVerdict, transport: 'fetch' | 'socket'): Error {
269
+ return Object.assign(
270
+ new Error(
271
+ `pyric net-guard blocked ${transport} egress to ${verdict.host} (${verdict.service}): ` +
272
+ `this is LIVE production, not the pyric sandbox. ` +
273
+ `Set PYRIC_GUARD=warn to allow it, or PYRIC_GUARD_ALLOW to permit this host.`,
274
+ ),
275
+ { code: GUARD_BLOCKED_CODE, host: verdict.host, service: verdict.service },
276
+ );
277
+ }
278
+
279
+ // ─── the reporter: evaluate, log once, permit or refuse ───────────────────────
280
+
281
+ export interface ReporterOptions {
282
+ readonly mode: GuardMode;
283
+ readonly allow: readonly string[];
284
+ readonly write?: (line: string) => void;
285
+ /** Initiating command, for attribution. Usually `basename(argv[1])`. */
286
+ readonly context?: string;
287
+ /**
288
+ * The shared "already reported" ledger. `installNetGuard` hands the SAME set
289
+ * to the dispatcher wrapper and the socket backstop, because undici connects
290
+ * through `net.connect`: a warn-mode fetch trips both seams and would
291
+ * otherwise print the same host twice. It also survives a re-assert, so
292
+ * being re-wrapped does not restart the noise.
293
+ */
294
+ readonly reported?: Set<string>;
295
+ }
296
+
297
+ interface Reporter {
298
+ /** Returns the verdict, having logged it at most once per host, and throws
299
+ * when the verdict refuses the connection. */
300
+ check(hostname: string | undefined, transport: 'fetch' | 'socket'): void;
301
+ }
302
+
303
+ function createReporter(options: ReporterOptions): Reporter {
304
+ const write = options.write ?? ((line: string) => void process.stderr.write(line));
305
+ const policy = { mode: options.mode, allow: options.allow };
306
+ const reported = options.reported ?? new Set<string>();
307
+ return {
308
+ check(hostname, transport) {
309
+ if (hostname === undefined) return;
310
+ const verdict = evaluateEgress(hostname, policy);
311
+ if (verdict === null) return;
312
+ // A dev server retries relentlessly; one line per host is the signal,
313
+ // and it also collapses the undici-over-net.connect double report.
314
+ const key = `${verdict.verdict}:${verdict.host}`;
315
+ if (!reported.has(key)) {
316
+ reported.add(key);
317
+ write(formatGuardLine(verdict, transport, options.context));
318
+ }
319
+ if (!verdict.permitted) throw blockedError(verdict, transport);
320
+ },
321
+ };
322
+ }
323
+
324
+ // ─── the undici dispatcher wrapper ─────────────────────────────────────────
325
+
326
+ interface Dispatcher {
327
+ dispatch(opts: unknown, handler: unknown): unknown;
328
+ }
329
+
330
+ /** `opts.origin` is a URL or an origin string; anything else means "no idea",
331
+ * and an unrecognisable origin is passed through rather than guessed at. */
332
+ function originHost(opts: unknown): string | undefined {
333
+ const origin = (opts as { origin?: unknown } | null | undefined)?.origin;
334
+ if (origin === undefined || origin === null) return undefined;
335
+ if (typeof origin === 'object' && 'hostname' in origin) {
336
+ const hostname = (origin as { hostname?: unknown }).hostname;
337
+ return typeof hostname === 'string' ? hostname.toLowerCase() : undefined;
338
+ }
339
+ if (typeof origin !== 'string') return undefined;
340
+ try {
341
+ return new URL(origin).hostname.toLowerCase();
342
+ } catch {
343
+ return undefined;
344
+ }
345
+ }
346
+
347
+ /**
348
+ * Wrap a dispatcher so `dispatch` is guarded and every other member still
349
+ * belongs to the real instance.
350
+ *
351
+ * A `Proxy` rather than a subclass or a copy: undici's Agent keeps state in
352
+ * private fields and internal symbols, and every forwarded call must run with
353
+ * `this` bound to the REAL instance (hence `Reflect.get(target, prop, target)`
354
+ * and the bind) or those fields are not there. `instanceof` keeps working.
355
+ */
356
+ export function wrapDispatcher<T extends Dispatcher>(real: T, options: ReporterOptions): T {
357
+ const reporter = createReporter(options);
358
+ const guardedDispatch = (opts: unknown, handler: unknown): unknown => {
359
+ reporter.check(originHost(opts), 'fetch');
360
+ // Both arguments cross UNTOUCHED. Edge hands a v6 handler to the host's
361
+ // v7 Agent, and that handoff only survives by identity.
362
+ return real.dispatch(opts, handler);
363
+ };
364
+ return new Proxy(real, {
365
+ get(target, prop) {
366
+ if (prop === 'dispatch') return guardedDispatch;
367
+ const value = Reflect.get(target, prop, target);
368
+ return typeof value === 'function' ? (value as (...a: unknown[]) => unknown).bind(target) : value;
369
+ },
370
+ }) as T;
371
+ }
372
+
373
+ // ─── install ───────────────────────────────────────────────────────────────
374
+
375
+ type ConnectFn = (...args: unknown[]) => unknown;
376
+
377
+ /** A `createConnection`-bearing object: an `http.Agent`/`https.Agent`
378
+ * prototype in production, a stand-in under test. */
379
+ type AgentPrototype = { createConnection?: unknown };
380
+
381
+ export interface NetGuardHooks {
382
+ /** Object carrying the undici dispatcher symbol. Defaults to `globalThis`. */
383
+ scope?: Record<symbol, unknown>;
384
+ env?: Record<string, string | undefined>;
385
+ argv?: readonly string[];
386
+ write?: (line: string) => void;
387
+ net?: { connect: ConnectFn; createConnection: ConnectFn };
388
+ tls?: { connect: ConnectFn };
389
+ /** Prototypes whose `createConnection` is patched. Defaults to the
390
+ * `http.Agent` and `https.Agent` prototypes. */
391
+ agentPrototypes?: readonly AgentPrototype[];
392
+ }
393
+
394
+ export interface NetGuard {
395
+ readonly mode: GuardMode;
396
+ readonly allow: readonly string[];
397
+ /** Re-wrap the global dispatcher if something replaced it (a future Next
398
+ * calling `setGlobalDispatcher` would otherwise silently unhook us). */
399
+ reassert(): void;
400
+ /** Stop the periodic re-assert. Used by the CLI's own tests. */
401
+ stop(): void;
402
+ }
403
+
404
+ /** `basename(argv[1])`, the cheapest honest attribution available. */
405
+ function contextFrom(argv: readonly string[] | undefined): string | undefined {
406
+ const entry = argv?.[1];
407
+ if (typeof entry !== 'string' || entry.length === 0) return undefined;
408
+ const parts = entry.split(/[\\/]/);
409
+ return parts[parts.length - 1] || undefined;
410
+ }
411
+
412
+ /**
413
+ * Materialize undici's lazy global dispatcher without touching the network.
414
+ * `new Headers()` loads Node's undici, whose module body installs a default
415
+ * Agent into the symbol only if the slot is still empty, so this must run
416
+ * before we put anything there. It also loads `_http_agent`, which is why the
417
+ * socket patches go in first.
418
+ */
419
+ function materializeGlobalDispatcher(): void {
420
+ try {
421
+ new Headers();
422
+ } catch {
423
+ // No WHATWG Headers, or a runtime that never had undici. The socket
424
+ // backstop still applies.
425
+ }
426
+ }
427
+
428
+ /**
429
+ * The `http.Agent` and `https.Agent` prototypes, or an empty list on a runtime
430
+ * without them. Each carries its own `createConnection`: `http`'s is a copied
431
+ * reference to `net.createConnection` snapshotted at `_http_agent` load time,
432
+ * so patching `net` alone leaves it unguarded whenever `node:http` loaded
433
+ * first.
434
+ */
435
+ function nodeAgentPrototypes(): AgentPrototype[] {
436
+ const require = createRequire(import.meta.url);
437
+ const prototypes: AgentPrototype[] = [];
438
+ for (const id of ['node:http', 'node:https']) {
439
+ try {
440
+ const mod = require(id) as { Agent?: { prototype?: unknown } };
441
+ const prototype = mod.Agent?.prototype;
442
+ if (typeof prototype === 'object' && prototype !== null) {
443
+ prototypes.push(prototype as AgentPrototype);
444
+ }
445
+ } catch {
446
+ // Runtime without that module: the other seams still apply.
447
+ }
448
+ }
449
+ return prototypes;
450
+ }
451
+
452
+ /**
453
+ * Install the guard. Gated on `PYRIC_SANDBOX` exactly like the rest of the
454
+ * register module: without the activator this is a no-op, so the module stays
455
+ * safe to import anywhere. Returns `null` when nothing was installed.
456
+ */
457
+ export function installNetGuard(hooks: NetGuardHooks = {}): NetGuard | null {
458
+ const env = hooks.env ?? process.env;
459
+ if (!env.PYRIC_SANDBOX) return null;
460
+
461
+ const write = hooks.write ?? ((line: string) => void process.stderr.write(line));
462
+ const mode = parseGuardMode(env.PYRIC_GUARD);
463
+
464
+ if (mode === 'off') {
465
+ write(
466
+ `${LOG_PREFIX} disabled (PYRIC_GUARD=off): egress from this process to live ` +
467
+ `Google/Firebase endpoints is neither reported nor blocked, not even the GCE ` +
468
+ `metadata server (169.254.169.254).\n`,
469
+ );
470
+ return null;
471
+ }
472
+
473
+ const allow = parseAllowHosts(env.PYRIC_GUARD_ALLOW);
474
+ const context = contextFrom(hooks.argv ?? process.argv);
475
+ const reporterOptions: ReporterOptions = { mode, allow, write, context, reported: new Set() };
476
+
477
+ const scope = hooks.scope ?? (globalThis as unknown as Record<symbol, unknown>);
478
+
479
+ // ── socket backstop: http.request, gRPC, DB drivers, raw sockets ──
480
+ //
481
+ // This runs FIRST, before the dispatcher is materialized. Materializing
482
+ // loads undici, which loads `_http_agent`, which snapshots
483
+ // `net.createConnection` onto `http.Agent.prototype.createConnection`. With
484
+ // the order reversed, that snapshot is the unpatched function and every
485
+ // plain `http.request` escapes the guard, the metadata server included.
486
+ const require = createRequire(import.meta.url);
487
+ const netModule =
488
+ hooks.net ?? (require('node:net') as { connect: ConnectFn; createConnection: ConnectFn });
489
+ const tlsModule = hooks.tls ?? (require('node:tls') as { connect: ConnectFn });
490
+ const reporter = createReporter(reporterOptions);
491
+
492
+ const guardConnect = (target: { [k: string]: unknown }, name: string): void => {
493
+ const original = target[name];
494
+ if (typeof original !== 'function') return;
495
+ const wrapped = function (this: unknown, ...args: unknown[]): unknown {
496
+ reporter.check(connectHost(args), 'socket');
497
+ return (original as ConnectFn).apply(this, args);
498
+ };
499
+ target[name] = wrapped;
500
+ };
501
+ guardConnect(netModule as unknown as { [k: string]: unknown }, 'connect');
502
+ guardConnect(netModule as unknown as { [k: string]: unknown }, 'createConnection');
503
+ guardConnect(tlsModule as unknown as { [k: string]: unknown }, 'connect');
504
+ // And the Agent prototypes, so a `node:http` that loaded before this module
505
+ // is still covered. `https.Agent` also reaches the patched `tls.connect`, so
506
+ // its own patch is a second check on the same egress; the once-per-host
507
+ // dedupe keeps that from printing twice.
508
+ for (const prototype of hooks.agentPrototypes ?? nodeAgentPrototypes()) {
509
+ guardConnect(prototype as { [k: string]: unknown }, 'createConnection');
510
+ }
511
+
512
+ let installed: unknown;
513
+ const wrapGlobalDispatcher = (): void => {
514
+ const current = scope[UNDICI_GLOBAL_DISPATCHER];
515
+ if (current === undefined || current === null) return;
516
+ if (current === installed) return;
517
+ if (typeof (current as Dispatcher).dispatch !== 'function') return;
518
+ // PLAIN ASSIGNMENT. undici's own property is
519
+ // `configurable: false, writable: true`; a `defineProperty` that tries to
520
+ // make it configurable throws and takes the process down.
521
+ installed = wrapDispatcher(current as Dispatcher, reporterOptions);
522
+ scope[UNDICI_GLOBAL_DISPATCHER] = installed;
523
+ };
524
+ if (hooks.scope === undefined) materializeGlobalDispatcher();
525
+ wrapGlobalDispatcher();
526
+
527
+ let timer: ReturnType<typeof setInterval> | undefined;
528
+ if (hooks.scope === undefined) {
529
+ timer = setInterval(wrapGlobalDispatcher, REASSERT_INTERVAL_MS);
530
+ // Never hold the event loop open: a guarded child must still exit.
531
+ timer.unref?.();
532
+ }
533
+
534
+ return {
535
+ mode,
536
+ allow,
537
+ reassert: wrapGlobalDispatcher,
538
+ stop(): void {
539
+ if (timer !== undefined) clearInterval(timer);
540
+ },
541
+ };
542
+ }
543
+
544
+ /**
545
+ * Extract the destination host from `net.connect` / `tls.connect` arguments,
546
+ * across all of their overloads: `(options[, cb])`, `(port[, host][, cb])`,
547
+ * `(path[, cb])`. An IPC path or a portless local socket has no host, which is
548
+ * exactly the "nothing to say" answer.
549
+ */
550
+ function connectHost(args: readonly unknown[]): string | undefined {
551
+ const first = args[0];
552
+ if (typeof first === 'object' && first !== null) {
553
+ const host = (first as { host?: unknown; hostname?: unknown }).host ??
554
+ (first as { hostname?: unknown }).hostname;
555
+ return typeof host === 'string' ? host : undefined;
556
+ }
557
+ if (typeof first === 'number' || (typeof first === 'string' && /^\d+$/.test(first))) {
558
+ // (port, host?, ...): the host, when given, is the next string argument.
559
+ const second = args[1];
560
+ if (typeof second === 'string') return second;
561
+ if (typeof second === 'object' && second !== null) {
562
+ const host = (second as { host?: unknown }).host;
563
+ return typeof host === 'string' ? host : undefined;
564
+ }
565
+ }
566
+ return undefined;
567
+ }