@schema-weaver/pg-connector 0.0.0-stage → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1065) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/LICENSE +21 -0
  3. package/README.md +457 -2
  4. package/dist/cjs/audit/chain.d.ts +365 -0
  5. package/dist/cjs/audit/chain.d.ts.map +1 -0
  6. package/dist/cjs/audit/chain.js +959 -0
  7. package/dist/cjs/audit/chain.js.map +1 -0
  8. package/dist/cjs/audit/cloud-client.d.ts +142 -0
  9. package/dist/cjs/audit/cloud-client.d.ts.map +1 -0
  10. package/dist/cjs/audit/cloud-client.js +364 -0
  11. package/dist/cjs/audit/cloud-client.js.map +1 -0
  12. package/dist/cjs/audit/cloud-writer.d.ts +57 -0
  13. package/dist/cjs/audit/cloud-writer.d.ts.map +1 -0
  14. package/dist/cjs/audit/cloud-writer.js +95 -0
  15. package/dist/cjs/audit/cloud-writer.js.map +1 -0
  16. package/dist/cjs/audit/context.d.ts +51 -0
  17. package/dist/cjs/audit/context.d.ts.map +1 -0
  18. package/dist/cjs/audit/context.js +75 -0
  19. package/dist/cjs/audit/context.js.map +1 -0
  20. package/dist/cjs/audit/files.d.ts +111 -0
  21. package/dist/cjs/audit/files.d.ts.map +1 -0
  22. package/dist/cjs/audit/files.js +406 -0
  23. package/dist/cjs/audit/files.js.map +1 -0
  24. package/dist/cjs/audit/index.d.ts +9 -0
  25. package/dist/cjs/audit/index.d.ts.map +1 -0
  26. package/dist/cjs/audit/index.js +68 -0
  27. package/dist/cjs/audit/index.js.map +1 -0
  28. package/dist/cjs/audit/local-writer.d.ts +255 -0
  29. package/dist/cjs/audit/local-writer.d.ts.map +1 -0
  30. package/dist/cjs/audit/local-writer.js +829 -0
  31. package/dist/cjs/audit/local-writer.js.map +1 -0
  32. package/dist/cjs/audit/redact.d.ts +151 -0
  33. package/dist/cjs/audit/redact.d.ts.map +1 -0
  34. package/dist/cjs/audit/redact.js +549 -0
  35. package/dist/cjs/audit/redact.js.map +1 -0
  36. package/dist/cjs/audit/sanitize.d.ts +78 -0
  37. package/dist/cjs/audit/sanitize.d.ts.map +1 -0
  38. package/dist/cjs/audit/sanitize.js +315 -0
  39. package/dist/cjs/audit/sanitize.js.map +1 -0
  40. package/dist/cjs/audit/sink.d.ts +278 -0
  41. package/dist/cjs/audit/sink.d.ts.map +1 -0
  42. package/dist/cjs/audit/sink.js +819 -0
  43. package/dist/cjs/audit/sink.js.map +1 -0
  44. package/dist/cjs/audit/types.d.ts +226 -0
  45. package/dist/cjs/audit/types.d.ts.map +1 -0
  46. package/dist/cjs/audit/types.js +3 -0
  47. package/dist/cjs/audit/types.js.map +1 -0
  48. package/dist/cjs/audit/verify-cache.d.ts +127 -0
  49. package/dist/cjs/audit/verify-cache.d.ts.map +1 -0
  50. package/dist/cjs/audit/verify-cache.js +668 -0
  51. package/dist/cjs/audit/verify-cache.js.map +1 -0
  52. package/dist/cjs/channels/agent-session.d.ts +228 -0
  53. package/dist/cjs/channels/agent-session.d.ts.map +1 -0
  54. package/dist/cjs/channels/agent-session.js +604 -0
  55. package/dist/cjs/channels/agent-session.js.map +1 -0
  56. package/dist/cjs/channels/data-channel.d.ts +181 -0
  57. package/dist/cjs/channels/data-channel.d.ts.map +1 -0
  58. package/dist/cjs/channels/data-channel.js +607 -0
  59. package/dist/cjs/channels/data-channel.js.map +1 -0
  60. package/dist/cjs/channels/reconnect.d.ts +142 -0
  61. package/dist/cjs/channels/reconnect.d.ts.map +1 -0
  62. package/dist/cjs/channels/reconnect.js +247 -0
  63. package/dist/cjs/channels/reconnect.js.map +1 -0
  64. package/dist/cjs/channels/types.d.ts +112 -0
  65. package/dist/cjs/channels/types.d.ts.map +1 -0
  66. package/dist/cjs/channels/types.js +3 -0
  67. package/dist/cjs/channels/types.js.map +1 -0
  68. package/dist/cjs/channels/wake-channel.d.ts +232 -0
  69. package/dist/cjs/channels/wake-channel.d.ts.map +1 -0
  70. package/dist/cjs/channels/wake-channel.js +752 -0
  71. package/dist/cjs/channels/wake-channel.js.map +1 -0
  72. package/dist/cjs/cli/banner.d.ts +2 -0
  73. package/dist/cjs/cli/banner.d.ts.map +1 -0
  74. package/dist/cjs/cli/banner.js +150 -0
  75. package/dist/cjs/cli/banner.js.map +1 -0
  76. package/dist/cjs/cli/commands/agent.d.ts +30 -0
  77. package/dist/cjs/cli/commands/agent.d.ts.map +1 -0
  78. package/dist/cjs/cli/commands/agent.js +214 -0
  79. package/dist/cjs/cli/commands/agent.js.map +1 -0
  80. package/dist/cjs/cli/commands/audit-verify.d.ts +19 -0
  81. package/dist/cjs/cli/commands/audit-verify.d.ts.map +1 -0
  82. package/dist/cjs/cli/commands/audit-verify.js +382 -0
  83. package/dist/cjs/cli/commands/audit-verify.js.map +1 -0
  84. package/dist/cjs/cli/commands/clean.d.ts +23 -0
  85. package/dist/cjs/cli/commands/clean.d.ts.map +1 -0
  86. package/dist/cjs/cli/commands/clean.js +272 -0
  87. package/dist/cjs/cli/commands/clean.js.map +1 -0
  88. package/dist/cjs/cli/commands/config-show.d.ts +2 -0
  89. package/dist/cjs/cli/commands/config-show.d.ts.map +1 -0
  90. package/dist/cjs/cli/commands/config-show.js +10 -0
  91. package/dist/cjs/cli/commands/config-show.js.map +1 -0
  92. package/dist/cjs/cli/commands/config.d.ts +6 -0
  93. package/dist/cjs/cli/commands/config.d.ts.map +1 -0
  94. package/dist/cjs/cli/commands/config.js +266 -0
  95. package/dist/cjs/cli/commands/config.js.map +1 -0
  96. package/dist/cjs/cli/commands/db-add.d.ts +16 -0
  97. package/dist/cjs/cli/commands/db-add.d.ts.map +1 -0
  98. package/dist/cjs/cli/commands/db-add.js +613 -0
  99. package/dist/cjs/cli/commands/db-add.js.map +1 -0
  100. package/dist/cjs/cli/commands/db-edit.d.ts +2 -0
  101. package/dist/cjs/cli/commands/db-edit.d.ts.map +1 -0
  102. package/dist/cjs/cli/commands/db-edit.js +388 -0
  103. package/dist/cjs/cli/commands/db-edit.js.map +1 -0
  104. package/dist/cjs/cli/commands/db-logs.d.ts +3 -0
  105. package/dist/cjs/cli/commands/db-logs.d.ts.map +1 -0
  106. package/dist/cjs/cli/commands/db-logs.js +67 -0
  107. package/dist/cjs/cli/commands/db-logs.js.map +1 -0
  108. package/dist/cjs/cli/commands/db-ls.d.ts +2 -0
  109. package/dist/cjs/cli/commands/db-ls.d.ts.map +1 -0
  110. package/dist/cjs/cli/commands/db-ls.js +118 -0
  111. package/dist/cjs/cli/commands/db-ls.js.map +1 -0
  112. package/dist/cjs/cli/commands/db-query.d.ts +121 -0
  113. package/dist/cjs/cli/commands/db-query.d.ts.map +1 -0
  114. package/dist/cjs/cli/commands/db-query.js +802 -0
  115. package/dist/cjs/cli/commands/db-query.js.map +1 -0
  116. package/dist/cjs/cli/commands/db-remove.d.ts +2 -0
  117. package/dist/cjs/cli/commands/db-remove.d.ts.map +1 -0
  118. package/dist/cjs/cli/commands/db-remove.js +51 -0
  119. package/dist/cjs/cli/commands/db-remove.js.map +1 -0
  120. package/dist/cjs/cli/commands/db-show.d.ts +2 -0
  121. package/dist/cjs/cli/commands/db-show.d.ts.map +1 -0
  122. package/dist/cjs/cli/commands/db-show.js +134 -0
  123. package/dist/cjs/cli/commands/db-show.js.map +1 -0
  124. package/dist/cjs/cli/commands/db-test.d.ts +3 -0
  125. package/dist/cjs/cli/commands/db-test.d.ts.map +1 -0
  126. package/dist/cjs/cli/commands/db-test.js +311 -0
  127. package/dist/cjs/cli/commands/db-test.js.map +1 -0
  128. package/dist/cjs/cli/commands/db.d.ts +11 -0
  129. package/dist/cjs/cli/commands/db.d.ts.map +1 -0
  130. package/dist/cjs/cli/commands/db.js +90 -0
  131. package/dist/cjs/cli/commands/db.js.map +1 -0
  132. package/dist/cjs/cli/commands/debug.d.ts +2 -0
  133. package/dist/cjs/cli/commands/debug.d.ts.map +1 -0
  134. package/dist/cjs/cli/commands/debug.js +241 -0
  135. package/dist/cjs/cli/commands/debug.js.map +1 -0
  136. package/dist/cjs/cli/commands/doctor.d.ts +5 -0
  137. package/dist/cjs/cli/commands/doctor.d.ts.map +1 -0
  138. package/dist/cjs/cli/commands/doctor.js +117 -0
  139. package/dist/cjs/cli/commands/doctor.js.map +1 -0
  140. package/dist/cjs/cli/commands/index.d.ts +10 -0
  141. package/dist/cjs/cli/commands/index.d.ts.map +1 -0
  142. package/dist/cjs/cli/commands/index.js +30 -0
  143. package/dist/cjs/cli/commands/index.js.map +1 -0
  144. package/dist/cjs/cli/commands/init.d.ts +2 -0
  145. package/dist/cjs/cli/commands/init.d.ts.map +1 -0
  146. package/dist/cjs/cli/commands/init.js +199 -0
  147. package/dist/cjs/cli/commands/init.js.map +1 -0
  148. package/dist/cjs/cli/commands/link.d.ts +5 -0
  149. package/dist/cjs/cli/commands/link.d.ts.map +1 -0
  150. package/dist/cjs/cli/commands/link.js +44 -0
  151. package/dist/cjs/cli/commands/link.js.map +1 -0
  152. package/dist/cjs/cli/commands/logs.d.ts +17 -0
  153. package/dist/cjs/cli/commands/logs.d.ts.map +1 -0
  154. package/dist/cjs/cli/commands/logs.js +314 -0
  155. package/dist/cjs/cli/commands/logs.js.map +1 -0
  156. package/dist/cjs/cli/commands/project-show.d.ts +2 -0
  157. package/dist/cjs/cli/commands/project-show.d.ts.map +1 -0
  158. package/dist/cjs/cli/commands/project-show.js +105 -0
  159. package/dist/cjs/cli/commands/project-show.js.map +1 -0
  160. package/dist/cjs/cli/commands/project.d.ts +3 -0
  161. package/dist/cjs/cli/commands/project.d.ts.map +1 -0
  162. package/dist/cjs/cli/commands/project.js +64 -0
  163. package/dist/cjs/cli/commands/project.js.map +1 -0
  164. package/dist/cjs/cli/commands/service.d.ts +123 -0
  165. package/dist/cjs/cli/commands/service.d.ts.map +1 -0
  166. package/dist/cjs/cli/commands/service.js +554 -0
  167. package/dist/cjs/cli/commands/service.js.map +1 -0
  168. package/dist/cjs/cli/commands/start.d.ts +6 -0
  169. package/dist/cjs/cli/commands/start.d.ts.map +1 -0
  170. package/dist/cjs/cli/commands/start.js +308 -0
  171. package/dist/cjs/cli/commands/start.js.map +1 -0
  172. package/dist/cjs/cli/commands/status.d.ts +2 -0
  173. package/dist/cjs/cli/commands/status.d.ts.map +1 -0
  174. package/dist/cjs/cli/commands/status.js +225 -0
  175. package/dist/cjs/cli/commands/status.js.map +1 -0
  176. package/dist/cjs/cli/commands/stop.d.ts +6 -0
  177. package/dist/cjs/cli/commands/stop.d.ts.map +1 -0
  178. package/dist/cjs/cli/commands/stop.js +99 -0
  179. package/dist/cjs/cli/commands/stop.js.map +1 -0
  180. package/dist/cjs/cli/daemon/error-tracker.d.ts +119 -0
  181. package/dist/cjs/cli/daemon/error-tracker.d.ts.map +1 -0
  182. package/dist/cjs/cli/daemon/error-tracker.js +500 -0
  183. package/dist/cjs/cli/daemon/error-tracker.js.map +1 -0
  184. package/dist/cjs/cli/daemon/fault-shutdown.d.ts +144 -0
  185. package/dist/cjs/cli/daemon/fault-shutdown.d.ts.map +1 -0
  186. package/dist/cjs/cli/daemon/fault-shutdown.js +312 -0
  187. package/dist/cjs/cli/daemon/fault-shutdown.js.map +1 -0
  188. package/dist/cjs/cli/daemon/index.d.ts +12 -0
  189. package/dist/cjs/cli/daemon/index.d.ts.map +1 -0
  190. package/dist/cjs/cli/daemon/index.js +23 -0
  191. package/dist/cjs/cli/daemon/index.js.map +1 -0
  192. package/dist/cjs/cli/daemon/pid-file.d.ts +13 -0
  193. package/dist/cjs/cli/daemon/pid-file.d.ts.map +1 -0
  194. package/dist/cjs/cli/daemon/pid-file.js +90 -0
  195. package/dist/cjs/cli/daemon/pid-file.js.map +1 -0
  196. package/dist/cjs/cli/daemon/readiness.d.ts +30 -0
  197. package/dist/cjs/cli/daemon/readiness.d.ts.map +1 -0
  198. package/dist/cjs/cli/daemon/readiness.js +74 -0
  199. package/dist/cjs/cli/daemon/readiness.js.map +1 -0
  200. package/dist/cjs/cli/daemon/runtime.d.ts +366 -0
  201. package/dist/cjs/cli/daemon/runtime.d.ts.map +1 -0
  202. package/dist/cjs/cli/daemon/runtime.js +1343 -0
  203. package/dist/cjs/cli/daemon/runtime.js.map +1 -0
  204. package/dist/cjs/cli/daemon/shutdown.d.ts +7 -0
  205. package/dist/cjs/cli/daemon/shutdown.d.ts.map +1 -0
  206. package/dist/cjs/cli/daemon/shutdown.js +66 -0
  207. package/dist/cjs/cli/daemon/shutdown.js.map +1 -0
  208. package/dist/cjs/cli/daemon/signal-handlers.d.ts +3 -0
  209. package/dist/cjs/cli/daemon/signal-handlers.d.ts.map +1 -0
  210. package/dist/cjs/cli/daemon/signal-handlers.js +27 -0
  211. package/dist/cjs/cli/daemon/signal-handlers.js.map +1 -0
  212. package/dist/cjs/cli/daemon/state.d.ts +157 -0
  213. package/dist/cjs/cli/daemon/state.d.ts.map +1 -0
  214. package/dist/cjs/cli/daemon/state.js +397 -0
  215. package/dist/cjs/cli/daemon/state.js.map +1 -0
  216. package/dist/cjs/cli/daemon/status-file.d.ts +139 -0
  217. package/dist/cjs/cli/daemon/status-file.d.ts.map +1 -0
  218. package/dist/cjs/cli/daemon/status-file.js +88 -0
  219. package/dist/cjs/cli/daemon/status-file.js.map +1 -0
  220. package/dist/cjs/cli/doctor/checks.d.ts +133 -0
  221. package/dist/cjs/cli/doctor/checks.d.ts.map +1 -0
  222. package/dist/cjs/cli/doctor/checks.js +677 -0
  223. package/dist/cjs/cli/doctor/checks.js.map +1 -0
  224. package/dist/cjs/cli/doctor/fixes.d.ts +9 -0
  225. package/dist/cjs/cli/doctor/fixes.d.ts.map +1 -0
  226. package/dist/cjs/cli/doctor/fixes.js +199 -0
  227. package/dist/cjs/cli/doctor/fixes.js.map +1 -0
  228. package/dist/cjs/cli/doctor/index.d.ts +7 -0
  229. package/dist/cjs/cli/doctor/index.d.ts.map +1 -0
  230. package/dist/cjs/cli/doctor/index.js +27 -0
  231. package/dist/cjs/cli/doctor/index.js.map +1 -0
  232. package/dist/cjs/cli/index.d.ts +3 -0
  233. package/dist/cjs/cli/index.d.ts.map +1 -0
  234. package/dist/cjs/cli/index.js +336 -0
  235. package/dist/cjs/cli/index.js.map +1 -0
  236. package/dist/cjs/cli/interactive.d.ts +8 -0
  237. package/dist/cjs/cli/interactive.d.ts.map +1 -0
  238. package/dist/cjs/cli/interactive.js +670 -0
  239. package/dist/cjs/cli/interactive.js.map +1 -0
  240. package/dist/cjs/cli/logs/format.d.ts +13 -0
  241. package/dist/cjs/cli/logs/format.d.ts.map +1 -0
  242. package/dist/cjs/cli/logs/format.js +178 -0
  243. package/dist/cjs/cli/logs/format.js.map +1 -0
  244. package/dist/cjs/cli/logs/index.d.ts +3 -0
  245. package/dist/cjs/cli/logs/index.d.ts.map +1 -0
  246. package/dist/cjs/cli/logs/index.js +13 -0
  247. package/dist/cjs/cli/logs/index.js.map +1 -0
  248. package/dist/cjs/cli/logs/viewer.d.ts +41 -0
  249. package/dist/cjs/cli/logs/viewer.d.ts.map +1 -0
  250. package/dist/cjs/cli/logs/viewer.js +417 -0
  251. package/dist/cjs/cli/logs/viewer.js.map +1 -0
  252. package/dist/cjs/cli/ops/operation-logger.d.ts +63 -0
  253. package/dist/cjs/cli/ops/operation-logger.d.ts.map +1 -0
  254. package/dist/cjs/cli/ops/operation-logger.js +183 -0
  255. package/dist/cjs/cli/ops/operation-logger.js.map +1 -0
  256. package/dist/cjs/cli/palette.d.ts +11 -0
  257. package/dist/cjs/cli/palette.d.ts.map +1 -0
  258. package/dist/cjs/cli/palette.js +243 -0
  259. package/dist/cjs/cli/palette.js.map +1 -0
  260. package/dist/cjs/cli/prompt.d.ts +186 -0
  261. package/dist/cjs/cli/prompt.d.ts.map +1 -0
  262. package/dist/cjs/cli/prompt.js +541 -0
  263. package/dist/cjs/cli/prompt.js.map +1 -0
  264. package/dist/cjs/cli/ui/box.d.ts +21 -0
  265. package/dist/cjs/cli/ui/box.d.ts.map +1 -0
  266. package/dist/cjs/cli/ui/box.js +72 -0
  267. package/dist/cjs/cli/ui/box.js.map +1 -0
  268. package/dist/cjs/cli/ui/clipboard.d.ts +6 -0
  269. package/dist/cjs/cli/ui/clipboard.d.ts.map +1 -0
  270. package/dist/cjs/cli/ui/clipboard.js +78 -0
  271. package/dist/cjs/cli/ui/clipboard.js.map +1 -0
  272. package/dist/cjs/cli/ui/colors.d.ts +57 -0
  273. package/dist/cjs/cli/ui/colors.d.ts.map +1 -0
  274. package/dist/cjs/cli/ui/colors.js +151 -0
  275. package/dist/cjs/cli/ui/colors.js.map +1 -0
  276. package/dist/cjs/cli/ui/index.d.ts +9 -0
  277. package/dist/cjs/cli/ui/index.d.ts.map +1 -0
  278. package/dist/cjs/cli/ui/index.js +55 -0
  279. package/dist/cjs/cli/ui/index.js.map +1 -0
  280. package/dist/cjs/cli/ui/spinner.d.ts +12 -0
  281. package/dist/cjs/cli/ui/spinner.d.ts.map +1 -0
  282. package/dist/cjs/cli/ui/spinner.js +82 -0
  283. package/dist/cjs/cli/ui/spinner.js.map +1 -0
  284. package/dist/cjs/cli/ui/symbols.d.ts +47 -0
  285. package/dist/cjs/cli/ui/symbols.d.ts.map +1 -0
  286. package/dist/cjs/cli/ui/symbols.js +112 -0
  287. package/dist/cjs/cli/ui/symbols.js.map +1 -0
  288. package/dist/cjs/cli/ui/table.d.ts +23 -0
  289. package/dist/cjs/cli/ui/table.d.ts.map +1 -0
  290. package/dist/cjs/cli/ui/table.js +160 -0
  291. package/dist/cjs/cli/ui/table.js.map +1 -0
  292. package/dist/cjs/cli/ui/terminal.d.ts +7 -0
  293. package/dist/cjs/cli/ui/terminal.d.ts.map +1 -0
  294. package/dist/cjs/cli/ui/terminal.js +40 -0
  295. package/dist/cjs/cli/ui/terminal.js.map +1 -0
  296. package/dist/cjs/config/atomic-write.d.ts +69 -0
  297. package/dist/cjs/config/atomic-write.d.ts.map +1 -0
  298. package/dist/cjs/config/atomic-write.js +289 -0
  299. package/dist/cjs/config/atomic-write.js.map +1 -0
  300. package/dist/cjs/config/db-config.d.ts +134 -0
  301. package/dist/cjs/config/db-config.d.ts.map +1 -0
  302. package/dist/cjs/config/db-config.js +594 -0
  303. package/dist/cjs/config/db-config.js.map +1 -0
  304. package/dist/cjs/config/machine-config.d.ts +85 -0
  305. package/dist/cjs/config/machine-config.d.ts.map +1 -0
  306. package/dist/cjs/config/machine-config.js +232 -0
  307. package/dist/cjs/config/machine-config.js.map +1 -0
  308. package/dist/cjs/config/paths.d.ts +64 -0
  309. package/dist/cjs/config/paths.d.ts.map +1 -0
  310. package/dist/cjs/config/paths.js +155 -0
  311. package/dist/cjs/config/paths.js.map +1 -0
  312. package/dist/cjs/config/schema.d.ts +72 -0
  313. package/dist/cjs/config/schema.d.ts.map +1 -0
  314. package/dist/cjs/config/schema.js +197 -0
  315. package/dist/cjs/config/schema.js.map +1 -0
  316. package/dist/cjs/config/token.d.ts +63 -0
  317. package/dist/cjs/config/token.d.ts.map +1 -0
  318. package/dist/cjs/config/token.js +146 -0
  319. package/dist/cjs/config/token.js.map +1 -0
  320. package/dist/cjs/execution/canceller.d.ts +41 -0
  321. package/dist/cjs/execution/canceller.d.ts.map +1 -0
  322. package/dist/cjs/execution/canceller.js +209 -0
  323. package/dist/cjs/execution/canceller.js.map +1 -0
  324. package/dist/cjs/execution/database-lookup.d.ts +56 -0
  325. package/dist/cjs/execution/database-lookup.d.ts.map +1 -0
  326. package/dist/cjs/execution/database-lookup.js +43 -0
  327. package/dist/cjs/execution/database-lookup.js.map +1 -0
  328. package/dist/cjs/execution/dispatcher.d.ts +181 -0
  329. package/dist/cjs/execution/dispatcher.d.ts.map +1 -0
  330. package/dist/cjs/execution/dispatcher.js +1296 -0
  331. package/dist/cjs/execution/dispatcher.js.map +1 -0
  332. package/dist/cjs/execution/function-effects.d.ts +209 -0
  333. package/dist/cjs/execution/function-effects.d.ts.map +1 -0
  334. package/dist/cjs/execution/function-effects.js +596 -0
  335. package/dist/cjs/execution/function-effects.js.map +1 -0
  336. package/dist/cjs/execution/introspection.d.ts +76 -0
  337. package/dist/cjs/execution/introspection.d.ts.map +1 -0
  338. package/dist/cjs/execution/introspection.js +448 -0
  339. package/dist/cjs/execution/introspection.js.map +1 -0
  340. package/dist/cjs/execution/migration-runner.d.ts +128 -0
  341. package/dist/cjs/execution/migration-runner.d.ts.map +1 -0
  342. package/dist/cjs/execution/migration-runner.js +798 -0
  343. package/dist/cjs/execution/migration-runner.js.map +1 -0
  344. package/dist/cjs/execution/non-tx-detector.d.ts +23 -0
  345. package/dist/cjs/execution/non-tx-detector.d.ts.map +1 -0
  346. package/dist/cjs/execution/non-tx-detector.js +218 -0
  347. package/dist/cjs/execution/non-tx-detector.js.map +1 -0
  348. package/dist/cjs/execution/pool.d.ts +229 -0
  349. package/dist/cjs/execution/pool.d.ts.map +1 -0
  350. package/dist/cjs/execution/pool.js +738 -0
  351. package/dist/cjs/execution/pool.js.map +1 -0
  352. package/dist/cjs/execution/query-runner.d.ts +88 -0
  353. package/dist/cjs/execution/query-runner.d.ts.map +1 -0
  354. package/dist/cjs/execution/query-runner.js +751 -0
  355. package/dist/cjs/execution/query-runner.js.map +1 -0
  356. package/dist/cjs/execution/rate-limiter.d.ts +120 -0
  357. package/dist/cjs/execution/rate-limiter.d.ts.map +1 -0
  358. package/dist/cjs/execution/rate-limiter.js +273 -0
  359. package/dist/cjs/execution/rate-limiter.js.map +1 -0
  360. package/dist/cjs/execution/search-path.d.ts +161 -0
  361. package/dist/cjs/execution/search-path.d.ts.map +1 -0
  362. package/dist/cjs/execution/search-path.js +279 -0
  363. package/dist/cjs/execution/search-path.js.map +1 -0
  364. package/dist/cjs/execution/sql-parser.d.ts +195 -0
  365. package/dist/cjs/execution/sql-parser.d.ts.map +1 -0
  366. package/dist/cjs/execution/sql-parser.js +704 -0
  367. package/dist/cjs/execution/sql-parser.js.map +1 -0
  368. package/dist/cjs/execution/statement-classifier.d.ts +103 -0
  369. package/dist/cjs/execution/statement-classifier.d.ts.map +1 -0
  370. package/dist/cjs/execution/statement-classifier.js +535 -0
  371. package/dist/cjs/execution/statement-classifier.js.map +1 -0
  372. package/dist/cjs/execution/types.d.ts +189 -0
  373. package/dist/cjs/execution/types.d.ts.map +1 -0
  374. package/dist/cjs/execution/types.js +28 -0
  375. package/dist/cjs/execution/types.js.map +1 -0
  376. package/dist/cjs/index.d.ts +34 -0
  377. package/dist/cjs/index.d.ts.map +1 -0
  378. package/dist/cjs/index.js +98 -0
  379. package/dist/cjs/index.js.map +1 -0
  380. package/dist/cjs/permissions/auto-upgrade.d.ts +40 -0
  381. package/dist/cjs/permissions/auto-upgrade.d.ts.map +1 -0
  382. package/dist/cjs/permissions/auto-upgrade.js +168 -0
  383. package/dist/cjs/permissions/auto-upgrade.js.map +1 -0
  384. package/dist/cjs/permissions/checker.d.ts +53 -0
  385. package/dist/cjs/permissions/checker.d.ts.map +1 -0
  386. package/dist/cjs/permissions/checker.js +326 -0
  387. package/dist/cjs/permissions/checker.js.map +1 -0
  388. package/dist/cjs/permissions/manual-approval.d.ts +213 -0
  389. package/dist/cjs/permissions/manual-approval.d.ts.map +1 -0
  390. package/dist/cjs/permissions/manual-approval.js +541 -0
  391. package/dist/cjs/permissions/manual-approval.js.map +1 -0
  392. package/dist/cjs/permissions/plan-registry.d.ts +274 -0
  393. package/dist/cjs/permissions/plan-registry.d.ts.map +1 -0
  394. package/dist/cjs/permissions/plan-registry.js +454 -0
  395. package/dist/cjs/permissions/plan-registry.js.map +1 -0
  396. package/dist/cjs/permissions/role-policy.d.ts +217 -0
  397. package/dist/cjs/permissions/role-policy.d.ts.map +1 -0
  398. package/dist/cjs/permissions/role-policy.js +584 -0
  399. package/dist/cjs/permissions/role-policy.js.map +1 -0
  400. package/dist/cjs/permissions/types.d.ts +126 -0
  401. package/dist/cjs/permissions/types.d.ts.map +1 -0
  402. package/dist/cjs/permissions/types.js +3 -0
  403. package/dist/cjs/permissions/types.js.map +1 -0
  404. package/dist/cjs/protocol/constants.d.ts +72 -0
  405. package/dist/cjs/protocol/constants.d.ts.map +1 -0
  406. package/dist/cjs/protocol/constants.js +107 -0
  407. package/dist/cjs/protocol/constants.js.map +1 -0
  408. package/dist/cjs/protocol/envelope.d.ts +165 -0
  409. package/dist/cjs/protocol/envelope.d.ts.map +1 -0
  410. package/dist/cjs/protocol/envelope.js +309 -0
  411. package/dist/cjs/protocol/envelope.js.map +1 -0
  412. package/dist/cjs/protocol/errors.d.ts +33 -0
  413. package/dist/cjs/protocol/errors.d.ts.map +1 -0
  414. package/dist/cjs/protocol/errors.js +391 -0
  415. package/dist/cjs/protocol/errors.js.map +1 -0
  416. package/dist/cjs/protocol/messages.d.ts +327 -0
  417. package/dist/cjs/protocol/messages.d.ts.map +1 -0
  418. package/dist/cjs/protocol/messages.js +3 -0
  419. package/dist/cjs/protocol/messages.js.map +1 -0
  420. package/dist/cjs/protocol/serialize.d.ts +26 -0
  421. package/dist/cjs/protocol/serialize.d.ts.map +1 -0
  422. package/dist/cjs/protocol/serialize.js +71 -0
  423. package/dist/cjs/protocol/serialize.js.map +1 -0
  424. package/dist/cjs/protocol/validate.d.ts +135 -0
  425. package/dist/cjs/protocol/validate.d.ts.map +1 -0
  426. package/dist/cjs/protocol/validate.js +852 -0
  427. package/dist/cjs/protocol/validate.js.map +1 -0
  428. package/dist/esm/audit/chain.d.ts +365 -0
  429. package/dist/esm/audit/chain.d.ts.map +1 -0
  430. package/dist/esm/audit/chain.js +895 -0
  431. package/dist/esm/audit/chain.js.map +1 -0
  432. package/dist/esm/audit/cloud-client.d.ts +142 -0
  433. package/dist/esm/audit/cloud-client.d.ts.map +1 -0
  434. package/dist/esm/audit/cloud-client.js +326 -0
  435. package/dist/esm/audit/cloud-client.js.map +1 -0
  436. package/dist/esm/audit/cloud-writer.d.ts +57 -0
  437. package/dist/esm/audit/cloud-writer.d.ts.map +1 -0
  438. package/dist/esm/audit/cloud-writer.js +91 -0
  439. package/dist/esm/audit/cloud-writer.js.map +1 -0
  440. package/dist/esm/audit/context.d.ts +51 -0
  441. package/dist/esm/audit/context.d.ts.map +1 -0
  442. package/dist/esm/audit/context.js +69 -0
  443. package/dist/esm/audit/context.js.map +1 -0
  444. package/dist/esm/audit/files.d.ts +111 -0
  445. package/dist/esm/audit/files.d.ts.map +1 -0
  446. package/dist/esm/audit/files.js +361 -0
  447. package/dist/esm/audit/files.js.map +1 -0
  448. package/dist/esm/audit/index.d.ts +9 -0
  449. package/dist/esm/audit/index.d.ts.map +1 -0
  450. package/dist/esm/audit/index.js +8 -0
  451. package/dist/esm/audit/index.js.map +1 -0
  452. package/dist/esm/audit/local-writer.d.ts +255 -0
  453. package/dist/esm/audit/local-writer.d.ts.map +1 -0
  454. package/dist/esm/audit/local-writer.js +785 -0
  455. package/dist/esm/audit/local-writer.js.map +1 -0
  456. package/dist/esm/audit/redact.d.ts +151 -0
  457. package/dist/esm/audit/redact.d.ts.map +1 -0
  458. package/dist/esm/audit/redact.js +506 -0
  459. package/dist/esm/audit/redact.js.map +1 -0
  460. package/dist/esm/audit/sanitize.d.ts +78 -0
  461. package/dist/esm/audit/sanitize.d.ts.map +1 -0
  462. package/dist/esm/audit/sanitize.js +307 -0
  463. package/dist/esm/audit/sanitize.js.map +1 -0
  464. package/dist/esm/audit/sink.d.ts +278 -0
  465. package/dist/esm/audit/sink.d.ts.map +1 -0
  466. package/dist/esm/audit/sink.js +782 -0
  467. package/dist/esm/audit/sink.js.map +1 -0
  468. package/dist/esm/audit/types.d.ts +226 -0
  469. package/dist/esm/audit/types.d.ts.map +1 -0
  470. package/dist/esm/audit/types.js +2 -0
  471. package/dist/esm/audit/types.js.map +1 -0
  472. package/dist/esm/audit/verify-cache.d.ts +127 -0
  473. package/dist/esm/audit/verify-cache.d.ts.map +1 -0
  474. package/dist/esm/audit/verify-cache.js +628 -0
  475. package/dist/esm/audit/verify-cache.js.map +1 -0
  476. package/dist/esm/channels/agent-session.d.ts +228 -0
  477. package/dist/esm/channels/agent-session.d.ts.map +1 -0
  478. package/dist/esm/channels/agent-session.js +566 -0
  479. package/dist/esm/channels/agent-session.js.map +1 -0
  480. package/dist/esm/channels/data-channel.d.ts +181 -0
  481. package/dist/esm/channels/data-channel.d.ts.map +1 -0
  482. package/dist/esm/channels/data-channel.js +567 -0
  483. package/dist/esm/channels/data-channel.js.map +1 -0
  484. package/dist/esm/channels/reconnect.d.ts +142 -0
  485. package/dist/esm/channels/reconnect.d.ts.map +1 -0
  486. package/dist/esm/channels/reconnect.js +234 -0
  487. package/dist/esm/channels/reconnect.js.map +1 -0
  488. package/dist/esm/channels/types.d.ts +112 -0
  489. package/dist/esm/channels/types.d.ts.map +1 -0
  490. package/dist/esm/channels/types.js +2 -0
  491. package/dist/esm/channels/types.js.map +1 -0
  492. package/dist/esm/channels/wake-channel.d.ts +232 -0
  493. package/dist/esm/channels/wake-channel.d.ts.map +1 -0
  494. package/dist/esm/channels/wake-channel.js +715 -0
  495. package/dist/esm/channels/wake-channel.js.map +1 -0
  496. package/dist/esm/cli/banner.d.ts +2 -0
  497. package/dist/esm/cli/banner.d.ts.map +1 -0
  498. package/dist/esm/cli/banner.js +114 -0
  499. package/dist/esm/cli/banner.js.map +1 -0
  500. package/dist/esm/cli/commands/agent.d.ts +30 -0
  501. package/dist/esm/cli/commands/agent.d.ts.map +1 -0
  502. package/dist/esm/cli/commands/agent.js +204 -0
  503. package/dist/esm/cli/commands/agent.js.map +1 -0
  504. package/dist/esm/cli/commands/audit-verify.d.ts +19 -0
  505. package/dist/esm/cli/commands/audit-verify.d.ts.map +1 -0
  506. package/dist/esm/cli/commands/audit-verify.js +345 -0
  507. package/dist/esm/cli/commands/audit-verify.js.map +1 -0
  508. package/dist/esm/cli/commands/clean.d.ts +23 -0
  509. package/dist/esm/cli/commands/clean.d.ts.map +1 -0
  510. package/dist/esm/cli/commands/clean.js +235 -0
  511. package/dist/esm/cli/commands/clean.js.map +1 -0
  512. package/dist/esm/cli/commands/config-show.d.ts +2 -0
  513. package/dist/esm/cli/commands/config-show.d.ts.map +1 -0
  514. package/dist/esm/cli/commands/config-show.js +2 -0
  515. package/dist/esm/cli/commands/config-show.js.map +1 -0
  516. package/dist/esm/cli/commands/config.d.ts +6 -0
  517. package/dist/esm/cli/commands/config.d.ts.map +1 -0
  518. package/dist/esm/cli/commands/config.js +259 -0
  519. package/dist/esm/cli/commands/config.js.map +1 -0
  520. package/dist/esm/cli/commands/db-add.d.ts +16 -0
  521. package/dist/esm/cli/commands/db-add.d.ts.map +1 -0
  522. package/dist/esm/cli/commands/db-add.js +576 -0
  523. package/dist/esm/cli/commands/db-add.js.map +1 -0
  524. package/dist/esm/cli/commands/db-edit.d.ts +2 -0
  525. package/dist/esm/cli/commands/db-edit.d.ts.map +1 -0
  526. package/dist/esm/cli/commands/db-edit.js +352 -0
  527. package/dist/esm/cli/commands/db-edit.js.map +1 -0
  528. package/dist/esm/cli/commands/db-logs.d.ts +3 -0
  529. package/dist/esm/cli/commands/db-logs.d.ts.map +1 -0
  530. package/dist/esm/cli/commands/db-logs.js +64 -0
  531. package/dist/esm/cli/commands/db-logs.js.map +1 -0
  532. package/dist/esm/cli/commands/db-ls.d.ts +2 -0
  533. package/dist/esm/cli/commands/db-ls.d.ts.map +1 -0
  534. package/dist/esm/cli/commands/db-ls.js +115 -0
  535. package/dist/esm/cli/commands/db-ls.js.map +1 -0
  536. package/dist/esm/cli/commands/db-query.d.ts +121 -0
  537. package/dist/esm/cli/commands/db-query.d.ts.map +1 -0
  538. package/dist/esm/cli/commands/db-query.js +754 -0
  539. package/dist/esm/cli/commands/db-query.js.map +1 -0
  540. package/dist/esm/cli/commands/db-remove.d.ts +2 -0
  541. package/dist/esm/cli/commands/db-remove.d.ts.map +1 -0
  542. package/dist/esm/cli/commands/db-remove.js +48 -0
  543. package/dist/esm/cli/commands/db-remove.js.map +1 -0
  544. package/dist/esm/cli/commands/db-show.d.ts +2 -0
  545. package/dist/esm/cli/commands/db-show.d.ts.map +1 -0
  546. package/dist/esm/cli/commands/db-show.js +131 -0
  547. package/dist/esm/cli/commands/db-show.js.map +1 -0
  548. package/dist/esm/cli/commands/db-test.d.ts +3 -0
  549. package/dist/esm/cli/commands/db-test.d.ts.map +1 -0
  550. package/dist/esm/cli/commands/db-test.js +307 -0
  551. package/dist/esm/cli/commands/db-test.js.map +1 -0
  552. package/dist/esm/cli/commands/db.d.ts +11 -0
  553. package/dist/esm/cli/commands/db.d.ts.map +1 -0
  554. package/dist/esm/cli/commands/db.js +76 -0
  555. package/dist/esm/cli/commands/db.js.map +1 -0
  556. package/dist/esm/cli/commands/debug.d.ts +2 -0
  557. package/dist/esm/cli/commands/debug.d.ts.map +1 -0
  558. package/dist/esm/cli/commands/debug.js +205 -0
  559. package/dist/esm/cli/commands/debug.js.map +1 -0
  560. package/dist/esm/cli/commands/doctor.d.ts +5 -0
  561. package/dist/esm/cli/commands/doctor.d.ts.map +1 -0
  562. package/dist/esm/cli/commands/doctor.js +114 -0
  563. package/dist/esm/cli/commands/doctor.js.map +1 -0
  564. package/dist/esm/cli/commands/index.d.ts +10 -0
  565. package/dist/esm/cli/commands/index.d.ts.map +1 -0
  566. package/dist/esm/cli/commands/index.js +10 -0
  567. package/dist/esm/cli/commands/index.js.map +1 -0
  568. package/dist/esm/cli/commands/init.d.ts +2 -0
  569. package/dist/esm/cli/commands/init.d.ts.map +1 -0
  570. package/dist/esm/cli/commands/init.js +163 -0
  571. package/dist/esm/cli/commands/init.js.map +1 -0
  572. package/dist/esm/cli/commands/link.d.ts +5 -0
  573. package/dist/esm/cli/commands/link.d.ts.map +1 -0
  574. package/dist/esm/cli/commands/link.js +41 -0
  575. package/dist/esm/cli/commands/link.js.map +1 -0
  576. package/dist/esm/cli/commands/logs.d.ts +17 -0
  577. package/dist/esm/cli/commands/logs.d.ts.map +1 -0
  578. package/dist/esm/cli/commands/logs.js +278 -0
  579. package/dist/esm/cli/commands/logs.js.map +1 -0
  580. package/dist/esm/cli/commands/project-show.d.ts +2 -0
  581. package/dist/esm/cli/commands/project-show.d.ts.map +1 -0
  582. package/dist/esm/cli/commands/project-show.js +69 -0
  583. package/dist/esm/cli/commands/project-show.js.map +1 -0
  584. package/dist/esm/cli/commands/project.d.ts +3 -0
  585. package/dist/esm/cli/commands/project.d.ts.map +1 -0
  586. package/dist/esm/cli/commands/project.js +60 -0
  587. package/dist/esm/cli/commands/project.js.map +1 -0
  588. package/dist/esm/cli/commands/service.d.ts +123 -0
  589. package/dist/esm/cli/commands/service.d.ts.map +1 -0
  590. package/dist/esm/cli/commands/service.js +505 -0
  591. package/dist/esm/cli/commands/service.js.map +1 -0
  592. package/dist/esm/cli/commands/start.d.ts +6 -0
  593. package/dist/esm/cli/commands/start.d.ts.map +1 -0
  594. package/dist/esm/cli/commands/start.js +272 -0
  595. package/dist/esm/cli/commands/start.js.map +1 -0
  596. package/dist/esm/cli/commands/status.d.ts +2 -0
  597. package/dist/esm/cli/commands/status.d.ts.map +1 -0
  598. package/dist/esm/cli/commands/status.js +222 -0
  599. package/dist/esm/cli/commands/status.js.map +1 -0
  600. package/dist/esm/cli/commands/stop.d.ts +6 -0
  601. package/dist/esm/cli/commands/stop.d.ts.map +1 -0
  602. package/dist/esm/cli/commands/stop.js +96 -0
  603. package/dist/esm/cli/commands/stop.js.map +1 -0
  604. package/dist/esm/cli/daemon/error-tracker.d.ts +119 -0
  605. package/dist/esm/cli/daemon/error-tracker.d.ts.map +1 -0
  606. package/dist/esm/cli/daemon/error-tracker.js +451 -0
  607. package/dist/esm/cli/daemon/error-tracker.js.map +1 -0
  608. package/dist/esm/cli/daemon/fault-shutdown.d.ts +144 -0
  609. package/dist/esm/cli/daemon/fault-shutdown.d.ts.map +1 -0
  610. package/dist/esm/cli/daemon/fault-shutdown.js +273 -0
  611. package/dist/esm/cli/daemon/fault-shutdown.js.map +1 -0
  612. package/dist/esm/cli/daemon/index.d.ts +12 -0
  613. package/dist/esm/cli/daemon/index.d.ts.map +1 -0
  614. package/dist/esm/cli/daemon/index.js +7 -0
  615. package/dist/esm/cli/daemon/index.js.map +1 -0
  616. package/dist/esm/cli/daemon/pid-file.d.ts +13 -0
  617. package/dist/esm/cli/daemon/pid-file.d.ts.map +1 -0
  618. package/dist/esm/cli/daemon/pid-file.js +51 -0
  619. package/dist/esm/cli/daemon/pid-file.js.map +1 -0
  620. package/dist/esm/cli/daemon/readiness.d.ts +30 -0
  621. package/dist/esm/cli/daemon/readiness.d.ts.map +1 -0
  622. package/dist/esm/cli/daemon/readiness.js +70 -0
  623. package/dist/esm/cli/daemon/readiness.js.map +1 -0
  624. package/dist/esm/cli/daemon/runtime.d.ts +366 -0
  625. package/dist/esm/cli/daemon/runtime.d.ts.map +1 -0
  626. package/dist/esm/cli/daemon/runtime.js +1284 -0
  627. package/dist/esm/cli/daemon/runtime.js.map +1 -0
  628. package/dist/esm/cli/daemon/shutdown.d.ts +7 -0
  629. package/dist/esm/cli/daemon/shutdown.d.ts.map +1 -0
  630. package/dist/esm/cli/daemon/shutdown.js +63 -0
  631. package/dist/esm/cli/daemon/shutdown.js.map +1 -0
  632. package/dist/esm/cli/daemon/signal-handlers.d.ts +3 -0
  633. package/dist/esm/cli/daemon/signal-handlers.d.ts.map +1 -0
  634. package/dist/esm/cli/daemon/signal-handlers.js +24 -0
  635. package/dist/esm/cli/daemon/signal-handlers.js.map +1 -0
  636. package/dist/esm/cli/daemon/state.d.ts +157 -0
  637. package/dist/esm/cli/daemon/state.d.ts.map +1 -0
  638. package/dist/esm/cli/daemon/state.js +352 -0
  639. package/dist/esm/cli/daemon/state.js.map +1 -0
  640. package/dist/esm/cli/daemon/status-file.d.ts +139 -0
  641. package/dist/esm/cli/daemon/status-file.d.ts.map +1 -0
  642. package/dist/esm/cli/daemon/status-file.js +50 -0
  643. package/dist/esm/cli/daemon/status-file.js.map +1 -0
  644. package/dist/esm/cli/doctor/checks.d.ts +133 -0
  645. package/dist/esm/cli/doctor/checks.d.ts.map +1 -0
  646. package/dist/esm/cli/doctor/checks.js +624 -0
  647. package/dist/esm/cli/doctor/checks.js.map +1 -0
  648. package/dist/esm/cli/doctor/fixes.d.ts +9 -0
  649. package/dist/esm/cli/doctor/fixes.d.ts.map +1 -0
  650. package/dist/esm/cli/doctor/fixes.js +163 -0
  651. package/dist/esm/cli/doctor/fixes.js.map +1 -0
  652. package/dist/esm/cli/doctor/index.d.ts +7 -0
  653. package/dist/esm/cli/doctor/index.d.ts.map +1 -0
  654. package/dist/esm/cli/doctor/index.js +5 -0
  655. package/dist/esm/cli/doctor/index.js.map +1 -0
  656. package/dist/esm/cli/index.d.ts +3 -0
  657. package/dist/esm/cli/index.d.ts.map +1 -0
  658. package/dist/esm/cli/index.js +333 -0
  659. package/dist/esm/cli/index.js.map +1 -0
  660. package/dist/esm/cli/interactive.d.ts +8 -0
  661. package/dist/esm/cli/interactive.d.ts.map +1 -0
  662. package/dist/esm/cli/interactive.js +665 -0
  663. package/dist/esm/cli/interactive.js.map +1 -0
  664. package/dist/esm/cli/logs/format.d.ts +13 -0
  665. package/dist/esm/cli/logs/format.d.ts.map +1 -0
  666. package/dist/esm/cli/logs/format.js +169 -0
  667. package/dist/esm/cli/logs/format.js.map +1 -0
  668. package/dist/esm/cli/logs/index.d.ts +3 -0
  669. package/dist/esm/cli/logs/index.d.ts.map +1 -0
  670. package/dist/esm/cli/logs/index.js +3 -0
  671. package/dist/esm/cli/logs/index.js.map +1 -0
  672. package/dist/esm/cli/logs/viewer.d.ts +41 -0
  673. package/dist/esm/cli/logs/viewer.d.ts.map +1 -0
  674. package/dist/esm/cli/logs/viewer.js +412 -0
  675. package/dist/esm/cli/logs/viewer.js.map +1 -0
  676. package/dist/esm/cli/ops/operation-logger.d.ts +63 -0
  677. package/dist/esm/cli/ops/operation-logger.d.ts.map +1 -0
  678. package/dist/esm/cli/ops/operation-logger.js +142 -0
  679. package/dist/esm/cli/ops/operation-logger.js.map +1 -0
  680. package/dist/esm/cli/palette.d.ts +11 -0
  681. package/dist/esm/cli/palette.d.ts.map +1 -0
  682. package/dist/esm/cli/palette.js +240 -0
  683. package/dist/esm/cli/palette.js.map +1 -0
  684. package/dist/esm/cli/prompt.d.ts +186 -0
  685. package/dist/esm/cli/prompt.d.ts.map +1 -0
  686. package/dist/esm/cli/prompt.js +483 -0
  687. package/dist/esm/cli/prompt.js.map +1 -0
  688. package/dist/esm/cli/ui/box.d.ts +21 -0
  689. package/dist/esm/cli/ui/box.d.ts.map +1 -0
  690. package/dist/esm/cli/ui/box.js +60 -0
  691. package/dist/esm/cli/ui/box.js.map +1 -0
  692. package/dist/esm/cli/ui/clipboard.d.ts +6 -0
  693. package/dist/esm/cli/ui/clipboard.d.ts.map +1 -0
  694. package/dist/esm/cli/ui/clipboard.js +42 -0
  695. package/dist/esm/cli/ui/clipboard.js.map +1 -0
  696. package/dist/esm/cli/ui/colors.d.ts +57 -0
  697. package/dist/esm/cli/ui/colors.d.ts.map +1 -0
  698. package/dist/esm/cli/ui/colors.js +126 -0
  699. package/dist/esm/cli/ui/colors.js.map +1 -0
  700. package/dist/esm/cli/ui/index.d.ts +9 -0
  701. package/dist/esm/cli/ui/index.d.ts.map +1 -0
  702. package/dist/esm/cli/ui/index.js +7 -0
  703. package/dist/esm/cli/ui/index.js.map +1 -0
  704. package/dist/esm/cli/ui/spinner.d.ts +12 -0
  705. package/dist/esm/cli/ui/spinner.d.ts.map +1 -0
  706. package/dist/esm/cli/ui/spinner.js +78 -0
  707. package/dist/esm/cli/ui/spinner.js.map +1 -0
  708. package/dist/esm/cli/ui/symbols.d.ts +47 -0
  709. package/dist/esm/cli/ui/symbols.d.ts.map +1 -0
  710. package/dist/esm/cli/ui/symbols.js +109 -0
  711. package/dist/esm/cli/ui/symbols.js.map +1 -0
  712. package/dist/esm/cli/ui/table.d.ts +23 -0
  713. package/dist/esm/cli/ui/table.d.ts.map +1 -0
  714. package/dist/esm/cli/ui/table.js +156 -0
  715. package/dist/esm/cli/ui/table.js.map +1 -0
  716. package/dist/esm/cli/ui/terminal.d.ts +7 -0
  717. package/dist/esm/cli/ui/terminal.d.ts.map +1 -0
  718. package/dist/esm/cli/ui/terminal.js +32 -0
  719. package/dist/esm/cli/ui/terminal.js.map +1 -0
  720. package/dist/esm/config/atomic-write.d.ts +69 -0
  721. package/dist/esm/config/atomic-write.d.ts.map +1 -0
  722. package/dist/esm/config/atomic-write.js +246 -0
  723. package/dist/esm/config/atomic-write.js.map +1 -0
  724. package/dist/esm/config/db-config.d.ts +134 -0
  725. package/dist/esm/config/db-config.d.ts.map +1 -0
  726. package/dist/esm/config/db-config.js +542 -0
  727. package/dist/esm/config/db-config.js.map +1 -0
  728. package/dist/esm/config/machine-config.d.ts +85 -0
  729. package/dist/esm/config/machine-config.d.ts.map +1 -0
  730. package/dist/esm/config/machine-config.js +190 -0
  731. package/dist/esm/config/machine-config.js.map +1 -0
  732. package/dist/esm/config/paths.d.ts +64 -0
  733. package/dist/esm/config/paths.d.ts.map +1 -0
  734. package/dist/esm/config/paths.js +108 -0
  735. package/dist/esm/config/paths.js.map +1 -0
  736. package/dist/esm/config/schema.d.ts +72 -0
  737. package/dist/esm/config/schema.d.ts.map +1 -0
  738. package/dist/esm/config/schema.js +180 -0
  739. package/dist/esm/config/schema.js.map +1 -0
  740. package/dist/esm/config/token.d.ts +63 -0
  741. package/dist/esm/config/token.d.ts.map +1 -0
  742. package/dist/esm/config/token.js +104 -0
  743. package/dist/esm/config/token.js.map +1 -0
  744. package/dist/esm/execution/canceller.d.ts +41 -0
  745. package/dist/esm/execution/canceller.d.ts.map +1 -0
  746. package/dist/esm/execution/canceller.js +205 -0
  747. package/dist/esm/execution/canceller.js.map +1 -0
  748. package/dist/esm/execution/database-lookup.d.ts +56 -0
  749. package/dist/esm/execution/database-lookup.d.ts.map +1 -0
  750. package/dist/esm/execution/database-lookup.js +38 -0
  751. package/dist/esm/execution/database-lookup.js.map +1 -0
  752. package/dist/esm/execution/dispatcher.d.ts +181 -0
  753. package/dist/esm/execution/dispatcher.d.ts.map +1 -0
  754. package/dist/esm/execution/dispatcher.js +1258 -0
  755. package/dist/esm/execution/dispatcher.js.map +1 -0
  756. package/dist/esm/execution/function-effects.d.ts +209 -0
  757. package/dist/esm/execution/function-effects.d.ts.map +1 -0
  758. package/dist/esm/execution/function-effects.js +586 -0
  759. package/dist/esm/execution/function-effects.js.map +1 -0
  760. package/dist/esm/execution/introspection.d.ts +76 -0
  761. package/dist/esm/execution/introspection.d.ts.map +1 -0
  762. package/dist/esm/execution/introspection.js +442 -0
  763. package/dist/esm/execution/introspection.js.map +1 -0
  764. package/dist/esm/execution/migration-runner.d.ts +128 -0
  765. package/dist/esm/execution/migration-runner.d.ts.map +1 -0
  766. package/dist/esm/execution/migration-runner.js +754 -0
  767. package/dist/esm/execution/migration-runner.js.map +1 -0
  768. package/dist/esm/execution/non-tx-detector.d.ts +23 -0
  769. package/dist/esm/execution/non-tx-detector.d.ts.map +1 -0
  770. package/dist/esm/execution/non-tx-detector.js +215 -0
  771. package/dist/esm/execution/non-tx-detector.js.map +1 -0
  772. package/dist/esm/execution/pool.d.ts +229 -0
  773. package/dist/esm/execution/pool.d.ts.map +1 -0
  774. package/dist/esm/execution/pool.js +685 -0
  775. package/dist/esm/execution/pool.js.map +1 -0
  776. package/dist/esm/execution/query-runner.d.ts +88 -0
  777. package/dist/esm/execution/query-runner.d.ts.map +1 -0
  778. package/dist/esm/execution/query-runner.js +743 -0
  779. package/dist/esm/execution/query-runner.js.map +1 -0
  780. package/dist/esm/execution/rate-limiter.d.ts +120 -0
  781. package/dist/esm/execution/rate-limiter.d.ts.map +1 -0
  782. package/dist/esm/execution/rate-limiter.js +269 -0
  783. package/dist/esm/execution/rate-limiter.js.map +1 -0
  784. package/dist/esm/execution/search-path.d.ts +161 -0
  785. package/dist/esm/execution/search-path.d.ts.map +1 -0
  786. package/dist/esm/execution/search-path.js +270 -0
  787. package/dist/esm/execution/search-path.js.map +1 -0
  788. package/dist/esm/execution/sql-parser.d.ts +195 -0
  789. package/dist/esm/execution/sql-parser.d.ts.map +1 -0
  790. package/dist/esm/execution/sql-parser.js +683 -0
  791. package/dist/esm/execution/sql-parser.js.map +1 -0
  792. package/dist/esm/execution/statement-classifier.d.ts +103 -0
  793. package/dist/esm/execution/statement-classifier.d.ts.map +1 -0
  794. package/dist/esm/execution/statement-classifier.js +526 -0
  795. package/dist/esm/execution/statement-classifier.js.map +1 -0
  796. package/dist/esm/execution/types.d.ts +189 -0
  797. package/dist/esm/execution/types.d.ts.map +1 -0
  798. package/dist/esm/execution/types.js +22 -0
  799. package/dist/esm/execution/types.js.map +1 -0
  800. package/dist/esm/index.d.ts +34 -0
  801. package/dist/esm/index.d.ts.map +1 -0
  802. package/dist/esm/index.js +38 -0
  803. package/dist/esm/index.js.map +1 -0
  804. package/dist/esm/permissions/auto-upgrade.d.ts +40 -0
  805. package/dist/esm/permissions/auto-upgrade.d.ts.map +1 -0
  806. package/dist/esm/permissions/auto-upgrade.js +164 -0
  807. package/dist/esm/permissions/auto-upgrade.js.map +1 -0
  808. package/dist/esm/permissions/checker.d.ts +53 -0
  809. package/dist/esm/permissions/checker.d.ts.map +1 -0
  810. package/dist/esm/permissions/checker.js +322 -0
  811. package/dist/esm/permissions/checker.js.map +1 -0
  812. package/dist/esm/permissions/manual-approval.d.ts +213 -0
  813. package/dist/esm/permissions/manual-approval.d.ts.map +1 -0
  814. package/dist/esm/permissions/manual-approval.js +503 -0
  815. package/dist/esm/permissions/manual-approval.js.map +1 -0
  816. package/dist/esm/permissions/plan-registry.d.ts +274 -0
  817. package/dist/esm/permissions/plan-registry.d.ts.map +1 -0
  818. package/dist/esm/permissions/plan-registry.js +450 -0
  819. package/dist/esm/permissions/plan-registry.js.map +1 -0
  820. package/dist/esm/permissions/role-policy.d.ts +217 -0
  821. package/dist/esm/permissions/role-policy.d.ts.map +1 -0
  822. package/dist/esm/permissions/role-policy.js +570 -0
  823. package/dist/esm/permissions/role-policy.js.map +1 -0
  824. package/dist/esm/permissions/types.d.ts +126 -0
  825. package/dist/esm/permissions/types.d.ts.map +1 -0
  826. package/dist/esm/permissions/types.js +2 -0
  827. package/dist/esm/permissions/types.js.map +1 -0
  828. package/dist/esm/protocol/constants.d.ts +72 -0
  829. package/dist/esm/protocol/constants.d.ts.map +1 -0
  830. package/dist/esm/protocol/constants.js +104 -0
  831. package/dist/esm/protocol/constants.js.map +1 -0
  832. package/dist/esm/protocol/envelope.d.ts +165 -0
  833. package/dist/esm/protocol/envelope.d.ts.map +1 -0
  834. package/dist/esm/protocol/envelope.js +263 -0
  835. package/dist/esm/protocol/envelope.js.map +1 -0
  836. package/dist/esm/protocol/errors.d.ts +33 -0
  837. package/dist/esm/protocol/errors.d.ts.map +1 -0
  838. package/dist/esm/protocol/errors.js +384 -0
  839. package/dist/esm/protocol/errors.js.map +1 -0
  840. package/dist/esm/protocol/messages.d.ts +327 -0
  841. package/dist/esm/protocol/messages.d.ts.map +1 -0
  842. package/dist/esm/protocol/messages.js +2 -0
  843. package/dist/esm/protocol/messages.js.map +1 -0
  844. package/dist/esm/protocol/serialize.d.ts +26 -0
  845. package/dist/esm/protocol/serialize.d.ts.map +1 -0
  846. package/dist/esm/protocol/serialize.js +63 -0
  847. package/dist/esm/protocol/serialize.js.map +1 -0
  848. package/dist/esm/protocol/validate.d.ts +135 -0
  849. package/dist/esm/protocol/validate.d.ts.map +1 -0
  850. package/dist/esm/protocol/validate.js +830 -0
  851. package/dist/esm/protocol/validate.js.map +1 -0
  852. package/dist/types/audit/chain.d.ts +365 -0
  853. package/dist/types/audit/chain.d.ts.map +1 -0
  854. package/dist/types/audit/cloud-client.d.ts +142 -0
  855. package/dist/types/audit/cloud-client.d.ts.map +1 -0
  856. package/dist/types/audit/cloud-writer.d.ts +57 -0
  857. package/dist/types/audit/cloud-writer.d.ts.map +1 -0
  858. package/dist/types/audit/context.d.ts +51 -0
  859. package/dist/types/audit/context.d.ts.map +1 -0
  860. package/dist/types/audit/files.d.ts +111 -0
  861. package/dist/types/audit/files.d.ts.map +1 -0
  862. package/dist/types/audit/index.d.ts +9 -0
  863. package/dist/types/audit/index.d.ts.map +1 -0
  864. package/dist/types/audit/local-writer.d.ts +255 -0
  865. package/dist/types/audit/local-writer.d.ts.map +1 -0
  866. package/dist/types/audit/redact.d.ts +151 -0
  867. package/dist/types/audit/redact.d.ts.map +1 -0
  868. package/dist/types/audit/sanitize.d.ts +78 -0
  869. package/dist/types/audit/sanitize.d.ts.map +1 -0
  870. package/dist/types/audit/sink.d.ts +278 -0
  871. package/dist/types/audit/sink.d.ts.map +1 -0
  872. package/dist/types/audit/types.d.ts +226 -0
  873. package/dist/types/audit/types.d.ts.map +1 -0
  874. package/dist/types/audit/verify-cache.d.ts +127 -0
  875. package/dist/types/audit/verify-cache.d.ts.map +1 -0
  876. package/dist/types/channels/agent-session.d.ts +228 -0
  877. package/dist/types/channels/agent-session.d.ts.map +1 -0
  878. package/dist/types/channels/data-channel.d.ts +181 -0
  879. package/dist/types/channels/data-channel.d.ts.map +1 -0
  880. package/dist/types/channels/reconnect.d.ts +142 -0
  881. package/dist/types/channels/reconnect.d.ts.map +1 -0
  882. package/dist/types/channels/types.d.ts +112 -0
  883. package/dist/types/channels/types.d.ts.map +1 -0
  884. package/dist/types/channels/wake-channel.d.ts +232 -0
  885. package/dist/types/channels/wake-channel.d.ts.map +1 -0
  886. package/dist/types/cli/banner.d.ts +2 -0
  887. package/dist/types/cli/banner.d.ts.map +1 -0
  888. package/dist/types/cli/commands/agent.d.ts +30 -0
  889. package/dist/types/cli/commands/agent.d.ts.map +1 -0
  890. package/dist/types/cli/commands/audit-verify.d.ts +19 -0
  891. package/dist/types/cli/commands/audit-verify.d.ts.map +1 -0
  892. package/dist/types/cli/commands/clean.d.ts +23 -0
  893. package/dist/types/cli/commands/clean.d.ts.map +1 -0
  894. package/dist/types/cli/commands/config-show.d.ts +2 -0
  895. package/dist/types/cli/commands/config-show.d.ts.map +1 -0
  896. package/dist/types/cli/commands/config.d.ts +6 -0
  897. package/dist/types/cli/commands/config.d.ts.map +1 -0
  898. package/dist/types/cli/commands/db-add.d.ts +16 -0
  899. package/dist/types/cli/commands/db-add.d.ts.map +1 -0
  900. package/dist/types/cli/commands/db-edit.d.ts +2 -0
  901. package/dist/types/cli/commands/db-edit.d.ts.map +1 -0
  902. package/dist/types/cli/commands/db-logs.d.ts +3 -0
  903. package/dist/types/cli/commands/db-logs.d.ts.map +1 -0
  904. package/dist/types/cli/commands/db-ls.d.ts +2 -0
  905. package/dist/types/cli/commands/db-ls.d.ts.map +1 -0
  906. package/dist/types/cli/commands/db-query.d.ts +121 -0
  907. package/dist/types/cli/commands/db-query.d.ts.map +1 -0
  908. package/dist/types/cli/commands/db-remove.d.ts +2 -0
  909. package/dist/types/cli/commands/db-remove.d.ts.map +1 -0
  910. package/dist/types/cli/commands/db-show.d.ts +2 -0
  911. package/dist/types/cli/commands/db-show.d.ts.map +1 -0
  912. package/dist/types/cli/commands/db-test.d.ts +3 -0
  913. package/dist/types/cli/commands/db-test.d.ts.map +1 -0
  914. package/dist/types/cli/commands/db.d.ts +11 -0
  915. package/dist/types/cli/commands/db.d.ts.map +1 -0
  916. package/dist/types/cli/commands/debug.d.ts +2 -0
  917. package/dist/types/cli/commands/debug.d.ts.map +1 -0
  918. package/dist/types/cli/commands/doctor.d.ts +5 -0
  919. package/dist/types/cli/commands/doctor.d.ts.map +1 -0
  920. package/dist/types/cli/commands/index.d.ts +10 -0
  921. package/dist/types/cli/commands/index.d.ts.map +1 -0
  922. package/dist/types/cli/commands/init.d.ts +2 -0
  923. package/dist/types/cli/commands/init.d.ts.map +1 -0
  924. package/dist/types/cli/commands/link.d.ts +5 -0
  925. package/dist/types/cli/commands/link.d.ts.map +1 -0
  926. package/dist/types/cli/commands/logs.d.ts +17 -0
  927. package/dist/types/cli/commands/logs.d.ts.map +1 -0
  928. package/dist/types/cli/commands/project-show.d.ts +2 -0
  929. package/dist/types/cli/commands/project-show.d.ts.map +1 -0
  930. package/dist/types/cli/commands/project.d.ts +3 -0
  931. package/dist/types/cli/commands/project.d.ts.map +1 -0
  932. package/dist/types/cli/commands/service.d.ts +123 -0
  933. package/dist/types/cli/commands/service.d.ts.map +1 -0
  934. package/dist/types/cli/commands/start.d.ts +6 -0
  935. package/dist/types/cli/commands/start.d.ts.map +1 -0
  936. package/dist/types/cli/commands/status.d.ts +2 -0
  937. package/dist/types/cli/commands/status.d.ts.map +1 -0
  938. package/dist/types/cli/commands/stop.d.ts +6 -0
  939. package/dist/types/cli/commands/stop.d.ts.map +1 -0
  940. package/dist/types/cli/daemon/error-tracker.d.ts +119 -0
  941. package/dist/types/cli/daemon/error-tracker.d.ts.map +1 -0
  942. package/dist/types/cli/daemon/fault-shutdown.d.ts +144 -0
  943. package/dist/types/cli/daemon/fault-shutdown.d.ts.map +1 -0
  944. package/dist/types/cli/daemon/index.d.ts +12 -0
  945. package/dist/types/cli/daemon/index.d.ts.map +1 -0
  946. package/dist/types/cli/daemon/pid-file.d.ts +13 -0
  947. package/dist/types/cli/daemon/pid-file.d.ts.map +1 -0
  948. package/dist/types/cli/daemon/readiness.d.ts +30 -0
  949. package/dist/types/cli/daemon/readiness.d.ts.map +1 -0
  950. package/dist/types/cli/daemon/runtime.d.ts +366 -0
  951. package/dist/types/cli/daemon/runtime.d.ts.map +1 -0
  952. package/dist/types/cli/daemon/shutdown.d.ts +7 -0
  953. package/dist/types/cli/daemon/shutdown.d.ts.map +1 -0
  954. package/dist/types/cli/daemon/signal-handlers.d.ts +3 -0
  955. package/dist/types/cli/daemon/signal-handlers.d.ts.map +1 -0
  956. package/dist/types/cli/daemon/state.d.ts +157 -0
  957. package/dist/types/cli/daemon/state.d.ts.map +1 -0
  958. package/dist/types/cli/daemon/status-file.d.ts +139 -0
  959. package/dist/types/cli/daemon/status-file.d.ts.map +1 -0
  960. package/dist/types/cli/doctor/checks.d.ts +133 -0
  961. package/dist/types/cli/doctor/checks.d.ts.map +1 -0
  962. package/dist/types/cli/doctor/fixes.d.ts +9 -0
  963. package/dist/types/cli/doctor/fixes.d.ts.map +1 -0
  964. package/dist/types/cli/doctor/index.d.ts +7 -0
  965. package/dist/types/cli/doctor/index.d.ts.map +1 -0
  966. package/dist/types/cli/index.d.ts +3 -0
  967. package/dist/types/cli/index.d.ts.map +1 -0
  968. package/dist/types/cli/interactive.d.ts +8 -0
  969. package/dist/types/cli/interactive.d.ts.map +1 -0
  970. package/dist/types/cli/logs/format.d.ts +13 -0
  971. package/dist/types/cli/logs/format.d.ts.map +1 -0
  972. package/dist/types/cli/logs/index.d.ts +3 -0
  973. package/dist/types/cli/logs/index.d.ts.map +1 -0
  974. package/dist/types/cli/logs/viewer.d.ts +41 -0
  975. package/dist/types/cli/logs/viewer.d.ts.map +1 -0
  976. package/dist/types/cli/ops/operation-logger.d.ts +63 -0
  977. package/dist/types/cli/ops/operation-logger.d.ts.map +1 -0
  978. package/dist/types/cli/palette.d.ts +11 -0
  979. package/dist/types/cli/palette.d.ts.map +1 -0
  980. package/dist/types/cli/prompt.d.ts +186 -0
  981. package/dist/types/cli/prompt.d.ts.map +1 -0
  982. package/dist/types/cli/ui/box.d.ts +21 -0
  983. package/dist/types/cli/ui/box.d.ts.map +1 -0
  984. package/dist/types/cli/ui/clipboard.d.ts +6 -0
  985. package/dist/types/cli/ui/clipboard.d.ts.map +1 -0
  986. package/dist/types/cli/ui/colors.d.ts +57 -0
  987. package/dist/types/cli/ui/colors.d.ts.map +1 -0
  988. package/dist/types/cli/ui/index.d.ts +9 -0
  989. package/dist/types/cli/ui/index.d.ts.map +1 -0
  990. package/dist/types/cli/ui/spinner.d.ts +12 -0
  991. package/dist/types/cli/ui/spinner.d.ts.map +1 -0
  992. package/dist/types/cli/ui/symbols.d.ts +47 -0
  993. package/dist/types/cli/ui/symbols.d.ts.map +1 -0
  994. package/dist/types/cli/ui/table.d.ts +23 -0
  995. package/dist/types/cli/ui/table.d.ts.map +1 -0
  996. package/dist/types/cli/ui/terminal.d.ts +7 -0
  997. package/dist/types/cli/ui/terminal.d.ts.map +1 -0
  998. package/dist/types/config/atomic-write.d.ts +69 -0
  999. package/dist/types/config/atomic-write.d.ts.map +1 -0
  1000. package/dist/types/config/db-config.d.ts +134 -0
  1001. package/dist/types/config/db-config.d.ts.map +1 -0
  1002. package/dist/types/config/machine-config.d.ts +85 -0
  1003. package/dist/types/config/machine-config.d.ts.map +1 -0
  1004. package/dist/types/config/paths.d.ts +64 -0
  1005. package/dist/types/config/paths.d.ts.map +1 -0
  1006. package/dist/types/config/schema.d.ts +72 -0
  1007. package/dist/types/config/schema.d.ts.map +1 -0
  1008. package/dist/types/config/token.d.ts +63 -0
  1009. package/dist/types/config/token.d.ts.map +1 -0
  1010. package/dist/types/execution/canceller.d.ts +41 -0
  1011. package/dist/types/execution/canceller.d.ts.map +1 -0
  1012. package/dist/types/execution/database-lookup.d.ts +56 -0
  1013. package/dist/types/execution/database-lookup.d.ts.map +1 -0
  1014. package/dist/types/execution/dispatcher.d.ts +181 -0
  1015. package/dist/types/execution/dispatcher.d.ts.map +1 -0
  1016. package/dist/types/execution/function-effects.d.ts +209 -0
  1017. package/dist/types/execution/function-effects.d.ts.map +1 -0
  1018. package/dist/types/execution/introspection.d.ts +76 -0
  1019. package/dist/types/execution/introspection.d.ts.map +1 -0
  1020. package/dist/types/execution/migration-runner.d.ts +128 -0
  1021. package/dist/types/execution/migration-runner.d.ts.map +1 -0
  1022. package/dist/types/execution/non-tx-detector.d.ts +23 -0
  1023. package/dist/types/execution/non-tx-detector.d.ts.map +1 -0
  1024. package/dist/types/execution/pool.d.ts +229 -0
  1025. package/dist/types/execution/pool.d.ts.map +1 -0
  1026. package/dist/types/execution/query-runner.d.ts +88 -0
  1027. package/dist/types/execution/query-runner.d.ts.map +1 -0
  1028. package/dist/types/execution/rate-limiter.d.ts +120 -0
  1029. package/dist/types/execution/rate-limiter.d.ts.map +1 -0
  1030. package/dist/types/execution/search-path.d.ts +161 -0
  1031. package/dist/types/execution/search-path.d.ts.map +1 -0
  1032. package/dist/types/execution/sql-parser.d.ts +195 -0
  1033. package/dist/types/execution/sql-parser.d.ts.map +1 -0
  1034. package/dist/types/execution/statement-classifier.d.ts +103 -0
  1035. package/dist/types/execution/statement-classifier.d.ts.map +1 -0
  1036. package/dist/types/execution/types.d.ts +189 -0
  1037. package/dist/types/execution/types.d.ts.map +1 -0
  1038. package/dist/types/index.d.ts +34 -0
  1039. package/dist/types/index.d.ts.map +1 -0
  1040. package/dist/types/permissions/auto-upgrade.d.ts +40 -0
  1041. package/dist/types/permissions/auto-upgrade.d.ts.map +1 -0
  1042. package/dist/types/permissions/checker.d.ts +53 -0
  1043. package/dist/types/permissions/checker.d.ts.map +1 -0
  1044. package/dist/types/permissions/manual-approval.d.ts +213 -0
  1045. package/dist/types/permissions/manual-approval.d.ts.map +1 -0
  1046. package/dist/types/permissions/plan-registry.d.ts +274 -0
  1047. package/dist/types/permissions/plan-registry.d.ts.map +1 -0
  1048. package/dist/types/permissions/role-policy.d.ts +217 -0
  1049. package/dist/types/permissions/role-policy.d.ts.map +1 -0
  1050. package/dist/types/permissions/types.d.ts +126 -0
  1051. package/dist/types/permissions/types.d.ts.map +1 -0
  1052. package/dist/types/protocol/constants.d.ts +72 -0
  1053. package/dist/types/protocol/constants.d.ts.map +1 -0
  1054. package/dist/types/protocol/envelope.d.ts +165 -0
  1055. package/dist/types/protocol/envelope.d.ts.map +1 -0
  1056. package/dist/types/protocol/errors.d.ts +33 -0
  1057. package/dist/types/protocol/errors.d.ts.map +1 -0
  1058. package/dist/types/protocol/messages.d.ts +327 -0
  1059. package/dist/types/protocol/messages.d.ts.map +1 -0
  1060. package/dist/types/protocol/serialize.d.ts +26 -0
  1061. package/dist/types/protocol/serialize.d.ts.map +1 -0
  1062. package/dist/types/protocol/validate.d.ts +135 -0
  1063. package/dist/types/protocol/validate.d.ts.map +1 -0
  1064. package/package.json +116 -4
  1065. package/scripts/generate-systemd-service.mjs +117 -0
@@ -0,0 +1,1284 @@
1
+ import * as fs from 'fs';
2
+ import { loadDatabasesConfig } from '../../config/db-config';
3
+ import { getDbConfigPath, getDaemonLogPath, AGENT_HOME_ENV_VARS } from '../../config/paths';
4
+ import { ConfigInvalidError, isSecureCloudUrl, isValidIdentifier, redactSecrets, } from '../../config/schema';
5
+ import { writePidFile, deletePidFile } from './pid-file';
6
+ import { writeStatusFile } from './status-file';
7
+ import { createShutdownCoordinator } from './shutdown';
8
+ import { installSignalHandlers } from './signal-handlers';
9
+ import { stripUnrecognisedSecurityEnv, UNRECOGNISED_SECURITY_ENV } from './state';
10
+ import { installGlobalHandlers, trackError, getErrorLogStats } from './error-tracker';
11
+ import { initOperationLogger, shutdownOperationLogger as _shutdownOperationLogger, } from '../ops/operation-logger';
12
+ import { PoolManager, MAX_STATEMENT_TIMEOUT_MS } from '../../execution/pool';
13
+ import { QueryRunner } from '../../execution/query-runner';
14
+ import { MigrationRunner } from '../../execution/migration-runner';
15
+ import { Canceller } from '../../execution/canceller';
16
+ import { Introspector } from '../../execution/introspection';
17
+ import { Dispatcher } from '../../execution/dispatcher';
18
+ import { DEFAULTS } from '../../protocol/constants';
19
+ import { ENVELOPE_MAX_NEGOTIABLE_ROLE_DEFAULT } from '../../protocol/envelope';
20
+ import { PermissionChecker } from '../../permissions/checker';
21
+ import { PlanRegistry } from '../../permissions/plan-registry';
22
+ import { AutoUpgradeChecker } from '../../permissions/auto-upgrade';
23
+ import { ManualApprovalHandler } from '../../permissions/manual-approval';
24
+ import { AuditSink } from '../../audit/sink';
25
+ import { LocalAuditWriter } from '../../audit/local-writer';
26
+ import { CloudAuditWriter } from '../../audit/cloud-writer';
27
+ import { AgentSession } from '../../channels/agent-session';
28
+ import { initSqlParser } from '../../execution/sql-parser';
29
+ import { VERSION } from '../../index';
30
+ export class RuntimeStats {
31
+ queries_served = 0;
32
+ streams_served = 0;
33
+ migrations_run = 0;
34
+ cancellations = 0;
35
+ permission_denies = 0;
36
+ audit_buffer_overflows = 0;
37
+ /**
38
+ * Appends this process saw rejected. `audit_events_written` is deliberately
39
+ * absent: it is derived from the sink, never counted here.
40
+ */
41
+ audit_events_failed = 0;
42
+ }
43
+ /**
44
+ * Reconcile the audit counters from the sink's own health.
45
+ *
46
+ * `events_written` is the sink's count of appends that resolved, so a rejected
47
+ * record can never inflate it. `events_failed` is the greater of the rejection
48
+ * this process counted on the awaited path and the sink's queue-level failure
49
+ * count, which also covers the fire-and-forget `log()` path. `dropped` is the
50
+ * sink's own discard count, carried through unchanged: it has no local counter to
51
+ * reconcile against, because a dropped record never reaches this process at all.
52
+ */
53
+ export function buildDaemonAuditStats(stats, health) {
54
+ return {
55
+ audit_events_written: health.events_written,
56
+ audit_events_failed: Math.max(stats.audit_events_failed, health.events_failed),
57
+ audit_buffer_overflows: stats.audit_buffer_overflows,
58
+ audit_dropped: health.dropped,
59
+ audit: health,
60
+ };
61
+ }
62
+ /**
63
+ * Builds the daemon's audit shutdown step: flush, then close — in that order,
64
+ * exactly once, however many times it is called.
65
+ *
66
+ * Close-after-flush matters: `close()` on its own would be enough for the fd,
67
+ * but the point of flushing first is that records already counted as written by
68
+ * the sink reach the disk, and `LocalAuditWriter.flush()` is what advances the
69
+ * chain head to match. Closing *instead of* flushing would drop both.
70
+ *
71
+ * Idempotent because shutdown can arrive twice (a signal and an explicit
72
+ * `stop`, or a handler registered on two coordinators). Concurrent callers await
73
+ * the *same* promise rather than starting a second flush/close pair, so a signal
74
+ * that lands mid-shutdown cannot interleave with it. A failed attempt is not
75
+ * remembered as done: the memo is cleared so a later stop retries instead of
76
+ * reporting a shutdown that never completed.
77
+ */
78
+ export function createAuditShutdown(target) {
79
+ let pending = null;
80
+ return () => {
81
+ if (pending === null) {
82
+ pending = (async () => {
83
+ await target.flush();
84
+ await target.close();
85
+ })().catch((err) => {
86
+ pending = null;
87
+ throw err;
88
+ });
89
+ }
90
+ return pending;
91
+ };
92
+ }
93
+ /**
94
+ * Validate a relay URL with exactly the rule `cloud_url` must already satisfy
95
+ * in `validateMachineConfig`: a well-formed `wss://` URL with an explicit
96
+ * authority and no userinfo. `ws://`, `http://`, `WSS://`, `wss:/host` and
97
+ * unparseable input are all refused.
98
+ *
99
+ * Throws {@link ConfigInvalidError} rather than falling back to the configured
100
+ * URL: silently ignoring the flag would leave the operator believing the agent
101
+ * is talking to the relay they named.
102
+ */
103
+ export function assertSecureRelayUrl(raw) {
104
+ if (typeof raw !== 'string' || raw.trim().length === 0) {
105
+ throw new ConfigInvalidError('Relay URL is empty. Expected a wss:// URL with an explicit authority.');
106
+ }
107
+ if (!isSecureCloudUrl(raw)) {
108
+ throw new ConfigInvalidError('Refusing relay URL: it must be a wss:// URL with an explicit authority. ' +
109
+ 'ws:// and http:// are refused because the agent token is a permanent ' +
110
+ 'bearer credential and would travel in cleartext.');
111
+ }
112
+ return raw;
113
+ }
114
+ function urlHost(raw) {
115
+ try {
116
+ return new URL(raw).host || null;
117
+ }
118
+ catch {
119
+ return null;
120
+ }
121
+ }
122
+ export function relayHostMismatchWarning(configuredHost, relayHost) {
123
+ return (`[security] WARNING: --relay points at a DIFFERENT host than the configured cloud_url.\n` +
124
+ ` configured cloud_url host: ${configuredHost}\n` +
125
+ ` relay host: ${relayHost}\n` +
126
+ ` The agent's permanent token will be presented to ${relayHost}. ` +
127
+ `Anyone who controls that host receives this agent's credentials. ` +
128
+ `Drop --relay to use the configured host.`);
129
+ }
130
+ /**
131
+ * Decide which URL the agent uses, and whether that silently redirects the
132
+ * token to a host the operator never configured.
133
+ */
134
+ export function resolveRelayOverride(relayUrl, persistedCloudUrl) {
135
+ const configuredHost = urlHost(persistedCloudUrl);
136
+ if (!relayUrl) {
137
+ return {
138
+ url: persistedCloudUrl,
139
+ isOverride: false,
140
+ configuredHost,
141
+ relayHost: null,
142
+ hostChanged: false,
143
+ };
144
+ }
145
+ const url = assertSecureRelayUrl(relayUrl);
146
+ const relayHost = urlHost(url);
147
+ return {
148
+ url,
149
+ isOverride: true,
150
+ configuredHost,
151
+ relayHost,
152
+ hostChanged: relayHost !== null && configuredHost !== null && relayHost !== configuredHost,
153
+ };
154
+ }
155
+ /**
156
+ * Render a URL for a terminal or a log: scheme and host only. Userinfo, path
157
+ * tokens, query and fragment are masked, so echoing a URL can never disclose a
158
+ * credential.
159
+ */
160
+ export function redactUrlForDisplay(raw) {
161
+ if (typeof raw !== 'string' || raw.length === 0)
162
+ return '(unset)';
163
+ let url;
164
+ try {
165
+ url = new URL(raw);
166
+ }
167
+ catch {
168
+ return '(unparseable URL)';
169
+ }
170
+ const hasHiddenParts = url.username.length > 0 ||
171
+ url.password.length > 0 ||
172
+ (url.pathname.length > 0 && url.pathname !== '/') ||
173
+ url.search.length > 0 ||
174
+ url.hash.length > 0;
175
+ const base = `${url.protocol}//${url.host}`;
176
+ return hasHiddenParts ? `${base}/<redacted>` : base;
177
+ }
178
+ /* ------------------------------------------------------------------ */
179
+ /* Security-relevant environment resolution (M-09, L-03) */
180
+ /* ------------------------------------------------------------------ */
181
+ /** Connections per database pool when nothing valid is configured. */
182
+ export const DEFAULT_POOL_MAX = 15;
183
+ export const MIN_POOL_MAX = 1;
184
+ export const MAX_POOL_MAX = 200;
185
+ /**
186
+ * Strict decimal integer parse. `Number()` would accept `0x10`, `1e3` and
187
+ * whitespace-only input, so every override is parsed this way instead.
188
+ */
189
+ function parseStrictInteger(raw) {
190
+ const trimmed = raw.trim();
191
+ if (!/^[+-]?\d+$/.test(trimmed))
192
+ return null;
193
+ const parsed = Number(trimmed);
194
+ return Number.isSafeInteger(parsed) ? parsed : null;
195
+ }
196
+ /**
197
+ * Resolve the per-pool connection ceiling.
198
+ *
199
+ * Anything that is not an integer inside `[MIN_POOL_MAX, MAX_POOL_MAX]` — a
200
+ * non-numeric value, zero, a negative number, or an absurd ceiling that would
201
+ * be refused by PostgreSQL's own `max_connections` — falls back to the
202
+ * default. Previously `SW_PG_POOL_MAX` was passed straight through
203
+ * `parseInt`, so `abc` produced `NaN` and `999999` asked the database for a
204
+ * connection storm.
205
+ */
206
+ export function resolvePoolMax(env = process.env) {
207
+ const raw = env.SW_PG_POOL_MAX;
208
+ if (typeof raw !== 'string' || raw.trim().length === 0)
209
+ return DEFAULT_POOL_MAX;
210
+ const parsed = parseStrictInteger(raw);
211
+ if (parsed === null || parsed < MIN_POOL_MAX || parsed > MAX_POOL_MAX)
212
+ return DEFAULT_POOL_MAX;
213
+ return parsed;
214
+ }
215
+ /** Shortest approval window that is still an approval rather than a formality. */
216
+ export const MIN_APPROVAL_TIMEOUT_MS = 5_000;
217
+ export const MAX_APPROVAL_TIMEOUT_MS = 3_600_000;
218
+ /**
219
+ * Resolve the manual-approval window.
220
+ *
221
+ * `0` and negative values are never honoured: they would expire every pending
222
+ * approval the instant it was created, turning the approval gate into a no-op.
223
+ * Garbage falls back to `DEFAULTS.APPROVAL_TIMEOUT_MS`, and an in-range value
224
+ * is clamped rather than rejected so a deliberate typo cannot silently widen
225
+ * the window.
226
+ */
227
+ export function resolveApprovalTimeoutMs(env = process.env) {
228
+ const raw = env.SW_AGENT_MANUAL_APPROVAL_TIMEOUT_MS;
229
+ const fallback = DEFAULTS.APPROVAL_TIMEOUT_MS;
230
+ if (typeof raw !== 'string' || raw.trim().length === 0)
231
+ return fallback;
232
+ const parsed = parseStrictInteger(raw);
233
+ if (parsed === null || parsed <= 0)
234
+ return fallback;
235
+ if (parsed < MIN_APPROVAL_TIMEOUT_MS)
236
+ return MIN_APPROVAL_TIMEOUT_MS;
237
+ if (parsed > MAX_APPROVAL_TIMEOUT_MS)
238
+ return MAX_APPROVAL_TIMEOUT_MS;
239
+ return parsed;
240
+ }
241
+ /**
242
+ * Mirror `PoolManager.maxStatementTimeoutMs` for the startup posture log: the
243
+ * environment may lower the ceiling but never raise it past the compiled-in
244
+ * hard cap.
245
+ */
246
+ export function resolveStatementTimeoutMs(env = process.env) {
247
+ const raw = env.SW_MAX_STATEMENT_TIMEOUT_MS;
248
+ const fallback = Math.min(DEFAULTS.QUERY_TIMEOUT_MS, MAX_STATEMENT_TIMEOUT_MS);
249
+ if (typeof raw !== 'string' || raw.trim().length === 0)
250
+ return fallback;
251
+ const parsed = parseStrictInteger(raw);
252
+ if (parsed === null || parsed <= 0)
253
+ return fallback;
254
+ return Math.min(parsed, MAX_STATEMENT_TIMEOUT_MS);
255
+ }
256
+ /**
257
+ * Mirror the query runner's streaming row ceiling for the posture log. Same
258
+ * rule as its private `readBoundedEnvInt`, including its `parseInt` semantics:
259
+ * NaN, zero and negatives fall back, absurd values are clamped.
260
+ */
261
+ export function resolveMaxStreamRows(env = process.env) {
262
+ const raw = env.SW_AGENT_MAX_STREAM_ROWS;
263
+ if (typeof raw !== 'string' || raw.trim().length === 0)
264
+ return DEFAULTS.MAX_STREAM_ROWS;
265
+ const parsed = Number.parseInt(raw.trim(), 10);
266
+ if (!Number.isFinite(parsed) || parsed < 1)
267
+ return DEFAULTS.MAX_STREAM_ROWS;
268
+ return Math.min(parsed, 100_000_000);
269
+ }
270
+ /**
271
+ * Gate for the historical `SW_AGENT_E2E` escape hatch that used to start an
272
+ * unauthenticated loopback admin server with `/admin/shutdown`.
273
+ *
274
+ * There is no admin server in this build, so `allowed: true` still starts
275
+ * nothing. The gate exists so the conditions that would have to hold before
276
+ * such a control plane could be reintroduced are stated once, in code, rather
277
+ * than in a comment: never in production, never in a daemonised process, and
278
+ * only with an explicit second opt-in.
279
+ */
280
+ export function resolveE2EAdminGate(env = process.env) {
281
+ const requested = env.SW_AGENT_E2E === '1';
282
+ if (!requested) {
283
+ return { requested: false, allowed: false, reason: 'not requested' };
284
+ }
285
+ const blockers = [];
286
+ if (env.NODE_ENV === 'production')
287
+ blockers.push('NODE_ENV=production');
288
+ if (env.SW_AGENT_DAEMON === '1')
289
+ blockers.push('the process is daemonised');
290
+ if (env.SW_AGENT_DEV_ADMIN !== '1')
291
+ blockers.push('SW_AGENT_DEV_ADMIN=1 not set');
292
+ return {
293
+ requested: true,
294
+ allowed: blockers.length === 0,
295
+ reason: blockers.length === 0
296
+ ? 'explicit development opt-in present, and no admin control plane exists to start'
297
+ : `refused (${blockers.join('; ')})`,
298
+ };
299
+ }
300
+ /**
301
+ * The resolved value of every input that changes this process's security
302
+ * posture, so the effective configuration is observable in the log rather than
303
+ * implicit in whatever environment the process happened to inherit.
304
+ *
305
+ * `env` is the environment the values are actually resolved from — the live one,
306
+ * after the refused variables have been stripped, so a reported value is the
307
+ * value in effect. `inherited` is the pre-strip snapshot, used only to say
308
+ * whether a variable was set at all; pass it so the report can distinguish "not
309
+ * set" from "set, and ignored".
310
+ */
311
+ export function resolveSecurityPosture(env = process.env, inherited = env) {
312
+ const accepted = (name, parse) => {
313
+ const raw = inherited[name];
314
+ if (typeof raw !== 'string' || raw.trim().length === 0)
315
+ return 'from default';
316
+ return parse(raw) === null ? 'rejected, using default' : 'from environment';
317
+ };
318
+ const e2e = resolveE2EAdminGate(inherited);
319
+ const scope = parseScopeEnv(env[ALLOWED_DATABASES_ENV]);
320
+ const agentHome = inherited.PG_CONNECTOR_HOME || inherited.SW_AGENT_HOME;
321
+ return [
322
+ {
323
+ name: 'SW_PG_POOL_MAX',
324
+ resolved: `${resolvePoolMax(env)} connections per database pool`,
325
+ detail: `${accepted('SW_PG_POOL_MAX', (value) => {
326
+ const parsed = parseStrictInteger(value);
327
+ return parsed !== null && parsed >= MIN_POOL_MAX && parsed <= MAX_POOL_MAX ? parsed : null;
328
+ })}; valid range ${MIN_POOL_MAX}-${MAX_POOL_MAX}`,
329
+ },
330
+ {
331
+ name: 'SW_MAX_STATEMENT_TIMEOUT_MS',
332
+ resolved: `${resolveStatementTimeoutMs(env)} ms`,
333
+ detail: `${accepted('SW_MAX_STATEMENT_TIMEOUT_MS', (value) => {
334
+ const parsed = parseStrictInteger(value);
335
+ return parsed !== null && parsed > 0 ? parsed : null;
336
+ })}; hard cap ${MAX_STATEMENT_TIMEOUT_MS} ms`,
337
+ },
338
+ {
339
+ name: 'SW_AGENT_MANUAL_APPROVAL_TIMEOUT_MS',
340
+ resolved: `${resolveApprovalTimeoutMs(env)} ms`,
341
+ detail: `${accepted('SW_AGENT_MANUAL_APPROVAL_TIMEOUT_MS', (value) => {
342
+ const parsed = parseStrictInteger(value);
343
+ return parsed !== null &&
344
+ parsed >= MIN_APPROVAL_TIMEOUT_MS &&
345
+ parsed <= MAX_APPROVAL_TIMEOUT_MS
346
+ ? parsed
347
+ : null;
348
+ })}; clamped to ${MIN_APPROVAL_TIMEOUT_MS}-${MAX_APPROVAL_TIMEOUT_MS} ms`,
349
+ },
350
+ {
351
+ name: 'SW_AGENT_MAX_STREAM_ROWS',
352
+ resolved: `${resolveMaxStreamRows(env)} rows`,
353
+ detail: accepted('SW_AGENT_MAX_STREAM_ROWS', (value) => {
354
+ const parsed = Number.parseInt(value.trim(), 10);
355
+ return Number.isFinite(parsed) && parsed >= 1 ? parsed : null;
356
+ }),
357
+ },
358
+ {
359
+ name: 'SW_AGENT_AUDIT_BUFFER',
360
+ resolved: (() => {
361
+ const buf = env.SW_AGENT_AUDIT_BUFFER;
362
+ return typeof buf === 'string' && buf.trim().length > 0
363
+ ? `${buf} (as provided)`
364
+ : 'audit sink default';
365
+ })(),
366
+ detail: (() => {
367
+ const buf = inherited.SW_AGENT_AUDIT_BUFFER;
368
+ if (typeof buf !== 'string' || buf.trim().length === 0)
369
+ return 'from default';
370
+ return env.SW_AGENT_AUDIT_BUFFER === undefined
371
+ ? 'set but refused; audit queue uses its default depth'
372
+ : 'from environment';
373
+ })(),
374
+ },
375
+ {
376
+ name: 'SW_AGENT_E2E',
377
+ resolved: e2e.requested ? 'requested' : 'not set',
378
+ detail: `${e2e.reason}; this build starts no inbound admin listener`,
379
+ },
380
+ {
381
+ name: ALLOWED_DATABASES_ENV,
382
+ resolved: scope
383
+ ? `${scope.length} allow-list rule(s)`
384
+ : 'unscoped (all configured databases reachable)',
385
+ detail: typeof env[ALLOWED_DATABASES_ENV] === 'string' &&
386
+ env[ALLOWED_DATABASES_ENV].trim().length > 0
387
+ ? 'from environment'
388
+ : `from default (also settable as ${ALLOWED_DATABASES_CONFIG_KEY} in sw-agent.config.json)`,
389
+ },
390
+ {
391
+ // Named for the variable an operator would actually set. This line reports
392
+ // where the agent token and the audit chain live, so a wrong variable name
393
+ // here sends a relocation attempt nowhere while the agent keeps writing
394
+ // secrets to the default path.
395
+ name: AGENT_HOME_ENV_VARS.join(' / '),
396
+ resolved: agentHome ?? 'default (~/.sw-agent)',
397
+ detail: 'holds sw-agent.config.json, the agent token and the audit chain; ' +
398
+ 'set either variable to relocate all of it, or leave unset for ' +
399
+ '~/.sw-agent. Not AGENT_HOME — nothing reads that one. ' +
400
+ 'PG_CONNECTOR_HOME is refused at runtime, but paths already resolved ' +
401
+ 'from it before startup still point there',
402
+ },
403
+ {
404
+ name: 'SW_AGENT_DEBUG',
405
+ resolved: env.SW_AGENT_DEBUG === '1' ? 'on' : 'off',
406
+ detail: 'verbose logging; never enable in production',
407
+ },
408
+ {
409
+ name: 'NODE_ENV',
410
+ resolved: env.NODE_ENV ?? 'development',
411
+ detail: 'production forbids every development-only control plane',
412
+ },
413
+ ];
414
+ }
415
+ /**
416
+ * Render the posture block. `secrets` are replaced with `***` in every line, so
417
+ * an agent token or an ingest URL can never reach the log through this path.
418
+ */
419
+ export function formatSecurityPosture(entries, secrets = []) {
420
+ const width = entries.reduce((max, entry) => Math.max(max, entry.name.length), 0);
421
+ const lines = [
422
+ '[security] Effective configuration (resolved values; secrets redacted):',
423
+ ...entries.map((entry) => `[security] ${entry.name.padEnd(width)} = ${entry.resolved} — ${entry.detail}`),
424
+ ];
425
+ return lines.map((line) => redactSecrets(line, ...secrets));
426
+ }
427
+ /** Environment channel for the allow-list, for installs that cannot edit config. */
428
+ export const ALLOWED_DATABASES_ENV = 'SW_AGENT_ALLOWED_DATABASES';
429
+ /** Config key read for the allow-list; the schema still needs to declare it. */
430
+ export const ALLOWED_DATABASES_CONFIG_KEY = 'allowed_databases';
431
+ function isScopeName(value) {
432
+ return typeof value === 'string' && isValidIdentifier(value, 64);
433
+ }
434
+ /**
435
+ * Parse a `project`, `project:alias` or `:alias` token.
436
+ */
437
+ function parseScopeToken(token) {
438
+ const raw = token.trim();
439
+ const separator = raw.indexOf(':');
440
+ const project = separator === -1 ? raw : raw.slice(0, separator);
441
+ if (separator === -1) {
442
+ if (!isScopeName(project)) {
443
+ throw new ConfigInvalidError(`Invalid ${ALLOWED_DATABASES_ENV} entry '${raw}': names may only contain letters, numbers, hyphens and underscores.`);
444
+ }
445
+ return { project_name: project };
446
+ }
447
+ const alias = raw.slice(separator + 1);
448
+ if (raw.indexOf(':', separator + 1) !== -1) {
449
+ throw new ConfigInvalidError(`Invalid ${ALLOWED_DATABASES_ENV} entry '${raw}': expected 'project', 'project:db_alias' or ':db_alias'.`);
450
+ }
451
+ if (project.length > 0 && !isScopeName(project)) {
452
+ throw new ConfigInvalidError(`Invalid ${ALLOWED_DATABASES_ENV} entry '${raw}': project names may only contain letters, numbers, hyphens and underscores.`);
453
+ }
454
+ if (alias.length === 0 || !isScopeName(alias)) {
455
+ throw new ConfigInvalidError(`Invalid ${ALLOWED_DATABASES_ENV} entry '${raw}': the db_alias part is required when a ':' is present and must be a valid alias.`);
456
+ }
457
+ return project.length > 0 ? { project_name: project, db_alias: alias } : { db_alias: alias };
458
+ }
459
+ /**
460
+ * Validate an allow-list declaration. Returns null when nothing is configured
461
+ * (the backwards-compatible unscoped case) and throws when something is
462
+ * configured but malformed — a typo must not widen the scope it was meant to
463
+ * narrow.
464
+ */
465
+ export function parseScopeRules(raw) {
466
+ if (raw === undefined || raw === null)
467
+ return null;
468
+ const items = Array.isArray(raw) ? raw : [raw];
469
+ const rules = [];
470
+ for (const item of items) {
471
+ if (typeof item === 'string') {
472
+ rules.push(parseScopeToken(item));
473
+ continue;
474
+ }
475
+ if (typeof item !== 'object' || item === null) {
476
+ throw new ConfigInvalidError(`Invalid ${ALLOWED_DATABASES_CONFIG_KEY} entry: expected an object with project_name and/or db_alias.`);
477
+ }
478
+ const record = item;
479
+ const project = record.project_name;
480
+ const alias = record.db_alias;
481
+ if (project !== undefined && !isScopeName(project)) {
482
+ throw new ConfigInvalidError(`Invalid ${ALLOWED_DATABASES_CONFIG_KEY} project_name: must be 1-64 characters of letters, numbers, hyphens and underscores.`);
483
+ }
484
+ if (alias !== undefined && !isScopeName(alias)) {
485
+ throw new ConfigInvalidError(`Invalid ${ALLOWED_DATABASES_CONFIG_KEY} db_alias: must be 1-64 characters of letters, numbers, hyphens and underscores.`);
486
+ }
487
+ if (project === undefined && alias === undefined) {
488
+ throw new ConfigInvalidError(`Invalid ${ALLOWED_DATABASES_CONFIG_KEY} entry: set project_name and/or db_alias; an empty rule would permit everything.`);
489
+ }
490
+ const rule = {};
491
+ if (project !== undefined)
492
+ rule.project_name = project;
493
+ if (alias !== undefined)
494
+ rule.db_alias = alias;
495
+ rules.push(rule);
496
+ }
497
+ return rules.length > 0 ? rules : null;
498
+ }
499
+ /** Parse the comma-separated environment form of the allow-list. */
500
+ export function parseScopeEnv(raw) {
501
+ if (typeof raw !== 'string' || raw.trim().length === 0)
502
+ return null;
503
+ const tokens = raw
504
+ .split(',')
505
+ .map((token) => token.trim())
506
+ .filter((token) => token.length > 0);
507
+ return tokens.length > 0 ? parseScopeRules(tokens) : null;
508
+ }
509
+ /**
510
+ * Effective allow-list, resolved from both declaration channels.
511
+ *
512
+ * The environment can only **NARROW**. the two were unioned, so anybody
513
+ * who could set `SW_AGENT_ALLOWED_DATABASES` in the daemon's environment could
514
+ * add a database the operator had deliberately excluded — an environment
515
+ * variable is a weaker channel than a config file and must not be the stronger
516
+ * one. When both channels declare a scope, the result is their intersection; a
517
+ * rule survives only if some config rule and some env rule can both match the
518
+ * same entry. An empty intersection is a scope that permits nothing.
519
+ *
520
+ * Null means nothing was declared anywhere. That is no longer "every database is
521
+ * permitted": see {@link resolveDatabaseScopeDecision}.
522
+ */
523
+ export function resolveDatabaseScope(machineConfig, env = process.env) {
524
+ const fromConfig = parseScopeRules(machineConfig[ALLOWED_DATABASES_CONFIG_KEY]);
525
+ const fromEnv = parseScopeEnv(env[ALLOWED_DATABASES_ENV]);
526
+ if (!fromConfig)
527
+ return fromEnv;
528
+ if (!fromEnv)
529
+ return fromConfig;
530
+ return intersectScopeRules(fromConfig, fromEnv);
531
+ }
532
+ /**
533
+ * Narrow every rule set to what BOTH permit.
534
+ *
535
+ * Rules carry at most a `project_name` and a `db_alias`, each optional, so the
536
+ * intersection of two rules is either empty (they contradict each other) or a
537
+ * single rule carrying every field they agree on. Duplicates are collapsed: an
538
+ * entry must not be able to widen itself by being named twice.
539
+ */
540
+ function intersectScopeRules(config, env) {
541
+ const out = [];
542
+ for (const c of config) {
543
+ for (const e of env) {
544
+ const merged = {};
545
+ if (c.project_name !== undefined && c.project_name === e.project_name) {
546
+ merged.project_name = c.project_name;
547
+ }
548
+ if (c.db_alias !== undefined && c.db_alias === e.db_alias) {
549
+ merged.db_alias = c.db_alias;
550
+ }
551
+ if (c.project_name !== undefined && e.project_name !== undefined && merged.project_name === undefined) {
552
+ continue; // different projects: no entry satisfies both
553
+ }
554
+ if (c.db_alias !== undefined && e.db_alias !== undefined && merged.db_alias === undefined) {
555
+ continue; // different aliases: no entry satisfies both
556
+ }
557
+ if (merged.project_name === undefined && merged.db_alias === undefined)
558
+ continue;
559
+ if (!out.some((r) => r.project_name === merged.project_name && r.db_alias === merged.db_alias)) {
560
+ out.push(merged);
561
+ }
562
+ }
563
+ }
564
+ return out.length > 0 ? out : [];
565
+ }
566
+ /**
567
+ * Config key that restores the pre-remediation permissive default.
568
+ *
569
+ * RISK: with no allow-list and this key set to `true`, ONE agent token reaches
570
+ * EVERY configured database on the host — typically dev, staging and production —
571
+ * and any authenticated principal on the relay can name any of them. It exists
572
+ * only so an existing deployment can keep working across this upgrade with a
573
+ * deliberate, visible choice; the default is fail-closed.
574
+ */
575
+ export const ALLOW_UNSCOPED_DATABASES_CONFIG_KEY = 'allow_unscoped_databases';
576
+ /** Machine-config path for the same escape hatch. */
577
+ export const ALLOW_UNSCOPED_DATABASES_CONFIG_PATH = `security.${ALLOW_UNSCOPED_DATABASES_CONFIG_KEY}`;
578
+ /**
579
+ * The effective database scope, and whether this installation fails closed.
580
+ *
581
+ * . The default was "no allow-list means every configured database", so an
582
+ * install that had never been configured — the default install — let a session
583
+ * authenticated for one project read any other project on the host, including
584
+ * production. The default is now the opposite: nothing declared means nothing is
585
+ * reachable except `ping`, and the refusal is audited.
586
+ *
587
+ * Restoring the old behaviour requires the explicit
588
+ * `security.allow_unscoped_databases: true`.
589
+ */
590
+ export function resolveDatabaseScopeDecision(machineConfig, env = process.env) {
591
+ const fromConfig = parseScopeRules(machineConfig[ALLOWED_DATABASES_CONFIG_KEY]);
592
+ const fromEnv = parseScopeEnv(env[ALLOWED_DATABASES_ENV]);
593
+ const allowUnscoped = readAllowUnscoped(machineConfig);
594
+ let rules;
595
+ if (!fromConfig) {
596
+ rules = fromEnv;
597
+ }
598
+ else if (!fromEnv) {
599
+ rules = fromConfig;
600
+ }
601
+ else {
602
+ rules = intersectScopeRules(fromConfig, fromEnv);
603
+ }
604
+ const scoped = rules !== null && rules.length > 0;
605
+ return {
606
+ rules,
607
+ env_narrowed: Boolean(fromConfig && fromEnv),
608
+ allow_unscoped: allowUnscoped,
609
+ scoped,
610
+ // An empty intersection is a scope that permits nothing, which is not the
611
+ // same as no scope at all: it is a deliberate contradiction of the two
612
+ // channels, and it must not fall back to "allow everything".
613
+ fail_closed: !scoped && !allowUnscoped,
614
+ };
615
+ }
616
+ /**
617
+ * The escape hatch, read strictly.
618
+ *
619
+ * Read off the raw config object rather than off a typed field so that a config
620
+ * that does not yet declare the key still works; the literal `true` is the only
621
+ * accepted value.
622
+ */
623
+ function readAllowUnscoped(machineConfig) {
624
+ const security = machineConfig['security'];
625
+ if (typeof security !== 'object' || security === null || Array.isArray(security))
626
+ return false;
627
+ return security[ALLOW_UNSCOPED_DATABASES_CONFIG_KEY] === true;
628
+ }
629
+ /** True when the entry is permitted. An absent allow-list permits everything. */
630
+ export function scopeAllowsEntry(rules, entry) {
631
+ if (!rules || rules.length === 0)
632
+ return true;
633
+ return rules.some((rule) => (rule.project_name === undefined || rule.project_name === entry.project_name) &&
634
+ (rule.db_alias === undefined || rule.db_alias === entry.db_alias));
635
+ }
636
+ /**
637
+ * Resolve an inbound frame's self-declared `project_name` / `db_alias` to a
638
+ * database entry, refusing anything outside the allow-list.
639
+ *
640
+ * Two refusals that did not exist before:
641
+ *
642
+ * - **Fail closed with no allow-list**. With nothing declared, this
643
+ * installation serves `ping` only. Restoring the old "everything is
644
+ * reachable" default requires the explicit
645
+ * `security.allow_unscoped_databases: true`.
646
+ * - **Project/alias collision**. When a frame names BOTH a project and
647
+ * an alias and they select *different* entries, the frame is refused. The
648
+ * old code silently preferred the project, executed against it, echoed the
649
+ * alias back and recorded neither — so the operation and the audit trail
650
+ * both named a database the operation never touched. Naming the same entry
651
+ * two ways is accepted.
652
+ *
653
+ * The result carries the refusal code rather than only `null` so the caller can
654
+ * audit the refusal under its own reason instead of a generic "unavailable".
655
+ */
656
+ export function createLookupDb(opts) {
657
+ const deny = (attempt, code) => {
658
+ opts.onDenied?.({ ...attempt, code });
659
+ return {
660
+ ok: false,
661
+ code,
662
+ reason: attempt.reason,
663
+ asserted_project: attempt.project,
664
+ asserted_db_alias: attempt.db_alias ?? '',
665
+ };
666
+ };
667
+ return (project, alias) => {
668
+ const failClosed = opts.decision?.fail_closed === true;
669
+ // Nothing is reachable without an allow-list unless the operator has
670
+ // explicitly restored the permissive default. `ping` never reaches here:
671
+ // the dispatcher answers it before consulting the lookup.
672
+ if (opts.scope === null && failClosed) {
673
+ return deny({
674
+ project,
675
+ db_alias: alias,
676
+ reason: 'no database allow-list is configured for this agent, so no database is reachable',
677
+ }, 'database_scope_not_configured');
678
+ }
679
+ const databases = opts.getDatabases();
680
+ const byProject = databases.find((entry) => entry.project_name === project);
681
+ const byAlias = alias ? databases.find((entry) => entry.db_alias === alias) : undefined;
682
+ // two names for one entry is fine; two names for two entries is not.
683
+ if (byProject && byAlias && byProject.db_alias !== byAlias.db_alias) {
684
+ return deny({
685
+ project,
686
+ db_alias: alias,
687
+ reason: 'the project and the db_alias in this request name different configured databases',
688
+ }, 'db_alias_project_mismatch');
689
+ }
690
+ if (byProject) {
691
+ if (!scopeAllowsEntry(opts.scope, byProject)) {
692
+ return deny({
693
+ project,
694
+ db_alias: byProject.db_alias,
695
+ reason: "the project is not in this agent's permitted database allow-list",
696
+ }, 'database_out_of_scope');
697
+ }
698
+ return { ok: true, entry: byProject };
699
+ }
700
+ // Protocol also addresses DBs by db_alias. Fall back so relay clients that
701
+ // only know the alias (e.g. the Data Explorer relay) still resolve.
702
+ if (byAlias) {
703
+ if (!scopeAllowsEntry(opts.scope, byAlias)) {
704
+ return deny({
705
+ project,
706
+ db_alias: alias,
707
+ reason: "the database alias is not in this agent's permitted database allow-list",
708
+ }, 'database_out_of_scope');
709
+ }
710
+ return { ok: true, entry: byAlias };
711
+ }
712
+ return {
713
+ ok: false,
714
+ code: 'database_not_found',
715
+ reason: `No configured database matches project "${project}"`,
716
+ asserted_project: project,
717
+ asserted_db_alias: alias ?? '',
718
+ };
719
+ };
720
+ }
721
+ /**
722
+ * What an operator needs to know about this installation's database scope.
723
+ *
724
+ * Three states, and they read very differently on purpose:
725
+ *
726
+ * - **scoped** — an allow-list is in force. Nothing to say.
727
+ * - **fail-closed (the new default)** — nothing is declared, so this agent
728
+ * serves `ping` only. This is the upgrade notice asks for: an existing
729
+ * install that never configured `allowed_databases` previously reached every
730
+ * database on the host and will now reach none, and an operator who has not
731
+ * read a changelog needs to be told that in the first seconds of the daemon,
732
+ * not in a log file nobody opens.
733
+ * - **unscoped by explicit opt-in** — every configured database is reachable
734
+ * again, and the risk is named in full.
735
+ */
736
+ export function databaseScopeWarningLines(scope, databases, decision) {
737
+ const scoped = scope !== null && scope.length > 0;
738
+ if (scoped)
739
+ return [];
740
+ const reachable = databases.map((entry) => `${entry.project_name}/${entry.db_alias}`).join(', ');
741
+ const listed = reachable || 'none';
742
+ const restoreHint = `set ${ALLOWED_DATABASES_CONFIG_KEY} in sw-agent.config.json, or ` +
743
+ `${ALLOWED_DATABASES_ENV}, to a list of ` +
744
+ '{ "project_name": ..., "db_alias": ... } pairs';
745
+ if (decision && !decision.allow_unscoped) {
746
+ return [
747
+ '[security] ============================================================================',
748
+ `[security] BREAKING CHANGE: no database allow-list is configured, so this agent now ` +
749
+ `REFUSES every database request. Only 'ping' is answered.`,
750
+ `[security] Before this release an unscoped agent token reached every configured ` +
751
+ `database (${databases.length}): ${listed}.`,
752
+ `[security] To restore that behaviour set 'true' in sw-agent.config.json: ` +
753
+ `{ "security": { "${ALLOW_UNSCOPED_DATABASES_CONFIG_KEY}": true } } — and read ` +
754
+ 'the risk first: one token would again reach every database on this host, including',
755
+ '[security] production, and any authenticated principal could name any of them.',
756
+ `[security] To scope instead, ${restoreHint}.`,
757
+ '[security] ============================================================================',
758
+ ];
759
+ }
760
+ return [
761
+ '[security] WARNING: no database allow-list is configured for this agent.',
762
+ `[security] The agent token is UNSCOPED: it reaches every configured ` +
763
+ `database (${databases.length}): ${listed}.`,
764
+ '[security] A session authenticated for one project can therefore reach ' +
765
+ `every other project on this host, including production. To scope it, ${restoreHint}.`,
766
+ `[security] This permissive mode is active only because ` +
767
+ `${ALLOW_UNSCOPED_DATABASES_CONFIG_PATH} is explicitly true in the machine config.`,
768
+ ];
769
+ }
770
+ /**
771
+ * One-line summary for `sw-agent status`.
772
+ *
773
+ * The warning above goes to the console of a detached daemon, which most
774
+ * operators never see; this is the part that has to reach the CLI an operator
775
+ * actually runs. See the `security` block of `DaemonStatus`.
776
+ */
777
+ export function describeDatabaseScope(decision, databases) {
778
+ if (decision.fail_closed) {
779
+ return ('FAIL CLOSED — no allowed_databases allow-list is configured, so every database request ' +
780
+ 'is refused (ping only). Set allowed_databases in sw-agent.config.json, or ' +
781
+ `${ALLOWED_DATABASES_ENV}, or set ${ALLOW_UNSCOPED_DATABASES_CONFIG_PATH}: true to ` +
782
+ 'restore the previous permissive default.');
783
+ }
784
+ if (decision.allow_unscoped) {
785
+ return (`UNSCOPED BY OPERATOR CHOICE — the token reaches every configured database ` +
786
+ `(${databases.length}): ${databases.map((e) => `${e.project_name}/${e.db_alias}`).join(', ') || 'none'}. ` +
787
+ 'Any authenticated principal can name any of them.');
788
+ }
789
+ return `SCOPED — ${decision.rules?.length ?? 0} allow-list rule(s).`;
790
+ }
791
+ export async function runAgent(opts) {
792
+ const daemonStartedAt = new Date().toISOString();
793
+ // Snapshot the inherited environment before anything is stripped from it, so
794
+ // the posture log below reports what this process was actually started with.
795
+ const inheritedEnv = { ...process.env };
796
+ // Validate the `--relay` override before applying it. Applied after
797
+ // `validateMachineConfig` used to bypass every check, so `--relay
798
+ // ws://attacker.example` sent the permanent agent token in cleartext from a
799
+ // detached process.
800
+ const relay = resolveRelayOverride(opts.relayUrl, opts.machineConfig.cloud_url);
801
+ if (relay.isOverride && relay.hostChanged && relay.configuredHost && relay.relayHost) {
802
+ console.error(relayHostMismatchWarning(relay.configuredHost, relay.relayHost));
803
+ }
804
+ if (relay.isOverride) {
805
+ opts.machineConfig.cloud_url = relay.url;
806
+ }
807
+ // Refuse any inherited variable that would change the security posture of
808
+ // this process (see UNRECOGNISED_SECURITY_ENV). Without this, a `.service`
809
+ // file, wrapper script, PM2 ecosystem file, CI job, or Dockerfile `ENV` that
810
+ // sets e.g. PG_CONNECTOR_HOME or SW_MAX_STATEMENT_TIMEOUT_MS silently
811
+ // reconfigures the agent that inherits it.
812
+ const refusedEnvVars = stripUnrecognisedSecurityEnv();
813
+ // Everything resolved from here on reads the *live* environment, not the
814
+ // snapshot, so a refused variable cannot be honoured through a captured copy.
815
+ // Resolving from `inheritedEnv` would have quietly applied SW_PG_POOL_MAX and
816
+ // SW_AGENT_MANUAL_APPROVAL_TIMEOUT_MS while claiming they were refused.
817
+ // Capture crashes and per-operation errors to errors.jsonl.
818
+ installGlobalHandlers(opts.machineConfig.agent_id);
819
+ for (const name of refusedEnvVars) {
820
+ console.error(`[security] Ignoring ${name}: ${UNRECOGNISED_SECURITY_ENV[name]} — this variable is not an accepted configuration input.`);
821
+ }
822
+ for (const line of formatSecurityPosture(resolveSecurityPosture(process.env, inheritedEnv), [
823
+ opts.machineConfig.agent_token,
824
+ opts.machineConfig.cloud_telemetry?.ingest_url,
825
+ ])) {
826
+ console.log(line);
827
+ }
828
+ const e2eGate = resolveE2EAdminGate(inheritedEnv);
829
+ if (e2eGate.requested) {
830
+ console.error(`[security] WARNING: SW_AGENT_E2E=1 was set in the environment but ${e2eGate.reason}. ` +
831
+ 'This build contains no inbound admin control plane, so nothing was started; ' +
832
+ 'no /admin/shutdown endpoint exists to call.');
833
+ }
834
+ // Load the real PostgreSQL parser before anything that can classify SQL exists.
835
+ // `classifyStatement()` is fail-closed by design (audit finding C-01): with the
836
+ // WASM module unloaded, `parseSql()` throws and every `query`, `stream_query`
837
+ // and `migration_run` is refused with `parser_unavailable`. Awaited here, after
838
+ // `installGlobalHandlers()` so a load failure is tracked like any other
839
+ // startup error, and before `PlanRegistry` / `PermissionChecker` /
840
+ // `Dispatcher` are constructed, so no request can be classified before the
841
+ // parser is ready. There is deliberately no heuristic fallback: a lexical
842
+ // classifier is the entire vulnerability this finding is about.
843
+ try {
844
+ await initSqlParser();
845
+ }
846
+ catch (err) {
847
+ const message = err instanceof Error ? err.message : String(err);
848
+ trackError(err, { op: 'initSqlParser', level: 'fatal' });
849
+ console.error();
850
+ console.error(`[security] FATAL: ${message}`);
851
+ console.error(' The agent cannot classify SQL without it, so every query, stream and migration ' +
852
+ 'would be refused with `parser_unavailable`. Refusing to start rather than falling ' +
853
+ 'back to a lexical classifier.');
854
+ console.error(' Reinstall the package so node_modules/pgsql-parser and its libpg-query WASM binary ' +
855
+ 'are intact, then run `sw-agent doctor` and `sw-agent start` again.');
856
+ console.error(` Agent log: ${getDaemonLogPath()}`);
857
+ console.error();
858
+ return 1;
859
+ }
860
+ const poolManager = new PoolManager({ maxPoolSize: resolvePoolMax() });
861
+ // Assigned further down, after the objects whose callbacks close over it exist.
862
+ // eslint-disable-next-line prefer-const -- deferred initialisation, not reassignment
863
+ let writeStatus;
864
+ let currentDatabasesConfig = opts.databasesConfig;
865
+ let configRevision = Date.now();
866
+ const planRegistry = new PlanRegistry();
867
+ const autoUpgradeChecker = new AutoUpgradeChecker({ planRegistry });
868
+ const auditLocalWriter = new LocalAuditWriter({
869
+ dir: opts.auditDir,
870
+ maxFileSize: 10 * 1024 * 1024,
871
+ maxArchiveFiles: 10,
872
+ });
873
+ const auditSink = new AuditSink({
874
+ agentId: opts.machineConfig.agent_id,
875
+ localWriter: auditLocalWriter,
876
+ cloudWriter: new CloudAuditWriter({
877
+ enabled: opts.machineConfig.cloud_telemetry?.enabled !== false,
878
+ url: opts.machineConfig.cloud_telemetry?.ingest_url,
879
+ cloudUrl: opts.machineConfig.cloud_url,
880
+ agent_token: opts.machineConfig.agent_token,
881
+ agent_id: opts.machineConfig.agent_id,
882
+ }),
883
+ });
884
+ // Deterministic shutdown of the audit path: drain the queue, fsync what was
885
+ // written, then release the handle. Flushing without closing left the long-
886
+ // lived file descriptor to the garbage collector and to process exit (finding
887
+ // M-05), so records that had been counted but not yet committed could be lost
888
+ // and the fd was not released before a restart reopened the same path.
889
+ const closeAudit = createAuditShutdown({
890
+ flush: () => auditSink.flush(),
891
+ close: () => auditLocalWriter.close(),
892
+ });
893
+ // Also enable the operation logger (CLI/lifecycle ops) for cloud delivery.
894
+ initOperationLogger({
895
+ enabled: opts.machineConfig.cloud_telemetry?.enabled !== false,
896
+ cloudUrl: opts.machineConfig.cloud_url,
897
+ token: opts.machineConfig.agent_token,
898
+ agentId: opts.machineConfig.agent_id,
899
+ });
900
+ // Assigned after the dispatcher is built, which itself closes over `session`.
901
+ // eslint-disable-next-line prefer-const -- deferred initialisation, not reassignment
902
+ let session;
903
+ const manualApprovalHandler = new ManualApprovalHandler({
904
+ send: async (msg) => {
905
+ if (session) {
906
+ await session.send(msg);
907
+ }
908
+ },
909
+ timeoutMs: resolveApprovalTimeoutMs(),
910
+ auditSink,
911
+ });
912
+ const permissionChecker = new PermissionChecker({
913
+ autoUpgradeChecker,
914
+ manualApprovalHandler,
915
+ planRegistry,
916
+ });
917
+ const stats = new RuntimeStats();
918
+ const originalLog = auditSink.log.bind(auditSink);
919
+ const originalLogSync = auditSink.logSync.bind(auditSink);
920
+ const updateStatsFromEvent = (partial) => {
921
+ if (partial.decision === 'allow' && partial.outcome !== 'n/a') {
922
+ if (partial.action === 'query') {
923
+ stats.queries_served++;
924
+ }
925
+ else if (partial.action === 'stream_query') {
926
+ stats.streams_served++;
927
+ }
928
+ else if (partial.action === 'migration_run') {
929
+ stats.migrations_run++;
930
+ }
931
+ else if (partial.action === 'cancel') {
932
+ stats.cancellations++;
933
+ }
934
+ }
935
+ else if (partial.decision === 'deny') {
936
+ if (partial.denial_reason === 'buffer_overflow') {
937
+ stats.audit_buffer_overflows++;
938
+ }
939
+ else {
940
+ stats.permission_denies++;
941
+ }
942
+ }
943
+ };
944
+ // `audit_events_written` is NOT incremented here. Both durability counters
945
+ // are reconciled from the sink instead (see `buildDaemonAuditStats`): the
946
+ // sink increments `events_written` only once an append has actually resolved,
947
+ // and `log()` hands back no promise to await. Incrementing before the write
948
+ // resolved claimed a durability the process did not have (audit finding C-06,
949
+ // item 6).
950
+ auditSink.log = (partial) => {
951
+ updateStatsFromEvent(partial);
952
+ originalLog(partial);
953
+ };
954
+ auditSink.logSync = async (partial) => {
955
+ try {
956
+ await originalLogSync(partial);
957
+ }
958
+ catch (err) {
959
+ stats.audit_events_failed++;
960
+ throw err;
961
+ }
962
+ // Only a persisted record may move the activity counters: for `logSync` the
963
+ // append is the gate, so a rejected record means the work never happened.
964
+ updateStatsFromEvent(partial);
965
+ };
966
+ // Create dispatcher dependencies
967
+ const queryRunner = new QueryRunner({ poolManager });
968
+ const migrationRunner = new MigrationRunner({ poolManager });
969
+ // The pool manager is required here, not optional: without it every cancel
970
+ // opened a fresh TCP + TLS + password-authenticated connection, so a stream
971
+ // of cancel requests could exhaust max_connections on the database.
972
+ const canceller = new Canceller({ poolManager });
973
+ const introspector = new Introspector({ poolManager });
974
+ const scopeDecision = resolveDatabaseScopeDecision(opts.machineConfig);
975
+ const databaseScope = scopeDecision.rules;
976
+ for (const line of databaseScopeWarningLines(databaseScope, currentDatabasesConfig.databases, scopeDecision)) {
977
+ console.error(line);
978
+ }
979
+ // an explicit `admin` ceiling is the documented escape hatch and the
980
+ // only way past the default `developer` ceiling. Saying so once, loudly, at
981
+ // startup, is what makes it a deliberate choice rather than an inherited one.
982
+ const configuredRoleCeiling = opts.machineConfig.security
983
+ ?.max_negotiable_role ?? ENVELOPE_MAX_NEGOTIABLE_ROLE_DEFAULT;
984
+ if (configuredRoleCeiling === 'admin') {
985
+ console.error('[security] WARNING: security.max_negotiable_role is "admin". A compromised relay can ' +
986
+ 'then assert the full capability set (ddl, migration_run, approve_ddl) on every ' +
987
+ 'configured database this agent can reach. The default ceiling is ' +
988
+ `"${ENVELOPE_MAX_NEGOTIABLE_ROLE_DEFAULT}".`);
989
+ }
990
+ const deniedScopes = new Set();
991
+ const lookupDb = createLookupDb({
992
+ getDatabases: () => currentDatabasesConfig.databases,
993
+ scope: databaseScope,
994
+ decision: scopeDecision,
995
+ onDenied: (attempt) => {
996
+ const key = `${attempt.code ?? 'refused'}|${attempt.project}|${attempt.db_alias ?? ''}`;
997
+ if (deniedScopes.has(key))
998
+ return;
999
+ deniedScopes.add(key);
1000
+ console.error(`[security] Refused request for project "${attempt.project}"` +
1001
+ `${attempt.db_alias ? ` (alias "${attempt.db_alias}")` : ''}` +
1002
+ `${attempt.code ? ` [${attempt.code}]` : ''}: ${attempt.reason}.`);
1003
+ },
1004
+ });
1005
+ const dispatcher = new Dispatcher({
1006
+ poolManager,
1007
+ queryRunner,
1008
+ migrationRunner,
1009
+ canceller,
1010
+ introspector,
1011
+ permissionChecker,
1012
+ planRegistry,
1013
+ lookupDb,
1014
+ getMachineConfig: () => opts.machineConfig,
1015
+ send: (msg) => session.send(msg),
1016
+ waitForDrain: () => session.waitForDrain(),
1017
+ auditSink,
1018
+ });
1019
+ session = new AgentSession({
1020
+ machineConfig: opts.machineConfig,
1021
+ getDatabases: () => currentDatabasesConfig.databases.map((db) => ({
1022
+ db_alias: db.db_alias,
1023
+ database: db.database,
1024
+ })),
1025
+ onMessage: async (msg) => {
1026
+ try {
1027
+ await dispatcher.handle(msg);
1028
+ }
1029
+ catch (err) {
1030
+ trackError(err, { op: msg.type });
1031
+ throw err;
1032
+ }
1033
+ },
1034
+ onStateChange: () => {
1035
+ writeStatus().catch((err) => {
1036
+ console.error('[stateChange] failed to write status:', err);
1037
+ trackError(err, { op: 'writeStatus' });
1038
+ });
1039
+ },
1040
+ });
1041
+ const shutdown = createShutdownCoordinator();
1042
+ // Shutdown registration order matters (sequential execution)
1043
+ // 1. pool-manager: wait for active queries to finish
1044
+ shutdown.register('pool-manager', async () => {
1045
+ await poolManager.closeAll();
1046
+ });
1047
+ // 2. agent-session: close websocket (data channel)
1048
+ shutdown.register('agent-session', async () => {
1049
+ await session.stop();
1050
+ });
1051
+ // 3. audit-sink: flush what was written, then release the handle. The step is
1052
+ // memoised, so the signal path and an explicit stop can both call it.
1053
+ shutdown.register('audit-sink', closeAudit);
1054
+ // 4. operation-logger: flush operation logs
1055
+ shutdown.register('operation-logger', async () => {
1056
+ await _shutdownOperationLogger();
1057
+ });
1058
+ // NOTE: there is deliberately no inbound HTTP listener anywhere in this
1059
+ // module. An earlier build started an unauthenticated loopback admin server
1060
+ // (`POST /admin/shutdown`, `GET /admin/stats`, `POST /admin/audit-flush`)
1061
+ // whenever `SW_AGENT_E2E=1`, which shipped in the published bundle and made
1062
+ // the README's "never calls listen()" claim false. Test control planes do
1063
+ // not belong in the daemon; if one is ever needed again it must live in a
1064
+ // separate `*-e2e` entry point that is excluded from the published `files`.
1065
+ // See SECURITY.md for the accurate statement of the network posture.
1066
+ const uninstallSignals = installSignalHandlers(shutdown);
1067
+ /**
1068
+ * A startup step that throws leaves the daemon to unwind without reaching the
1069
+ * shutdown coordinator, so the audit handle would not be released until the
1070
+ * process died. Close it here instead, then rethrow unchanged.
1071
+ */
1072
+ const failStartup = async (err, op) => {
1073
+ trackError(err, { op });
1074
+ console.error(`[daemon] ${op} failed; closing the audit writer before giving up:`, err);
1075
+ await closeAudit().catch(() => undefined);
1076
+ throw err;
1077
+ };
1078
+ try {
1079
+ await writePidFile({ path: opts.pidFile }, {
1080
+ pid: process.pid,
1081
+ started_at: daemonStartedAt,
1082
+ version: VERSION,
1083
+ });
1084
+ }
1085
+ catch (err) {
1086
+ await failStartup(err, 'writePidFile');
1087
+ }
1088
+ let isWritingStatus = false;
1089
+ let hasPendingStatusWrite = false;
1090
+ writeStatus = async () => {
1091
+ if (isWritingStatus) {
1092
+ hasPendingStatusWrite = true;
1093
+ return;
1094
+ }
1095
+ isWritingStatus = true;
1096
+ try {
1097
+ for (;;) {
1098
+ const state = session.getState();
1099
+ const errorStats = getErrorLogStats();
1100
+ const auditStats = buildDaemonAuditStats(stats, auditSink.getHealth());
1101
+ const status = {
1102
+ pid: process.pid,
1103
+ started_at: daemonStartedAt,
1104
+ last_heartbeat: new Date().toISOString(),
1105
+ version: VERSION,
1106
+ channels: {
1107
+ sse: state.wake === 'connected'
1108
+ ? 'connected'
1109
+ : state.wake === 'connecting'
1110
+ ? 'connecting'
1111
+ : state.wake === 'error'
1112
+ ? 'error'
1113
+ : 'disconnected',
1114
+ wss: state.data === 'open'
1115
+ ? 'connected'
1116
+ : state.data === 'connecting'
1117
+ ? 'connecting'
1118
+ : state.data === 'error'
1119
+ ? 'error'
1120
+ : state.data === 'closed'
1121
+ ? 'idle'
1122
+ : 'disconnected',
1123
+ },
1124
+ stats: {
1125
+ queries_served: stats.queries_served,
1126
+ streams_served: stats.streams_served,
1127
+ migrations_run: stats.migrations_run,
1128
+ cancellations: stats.cancellations,
1129
+ permission_denies: stats.permission_denies,
1130
+ audit_events_written: auditStats.audit_events_written,
1131
+ audit_events_failed: auditStats.audit_events_failed,
1132
+ audit_buffer_overflows: auditStats.audit_buffer_overflows,
1133
+ audit_dropped: auditStats.audit_dropped,
1134
+ },
1135
+ audit: auditStats.audit,
1136
+ config: {
1137
+ databases: currentDatabasesConfig.databases.length,
1138
+ projects: new Set(currentDatabasesConfig.databases.map((db) => db.project_name)).size,
1139
+ revision: configRevision,
1140
+ },
1141
+ errors_log: {
1142
+ path: errorStats.path,
1143
+ size_bytes: errorStats.size_bytes,
1144
+ },
1145
+ // / the security posture an operator most needs to see is
1146
+ // the one that is invisible when it is wrong, and the daemon's own
1147
+ // console is not where an operator looks. This block is what
1148
+ // `sw-agent status` reads.
1149
+ security: {
1150
+ database_scope: describeDatabaseScope(scopeDecision, currentDatabasesConfig.databases),
1151
+ allowlist_configured: scopeDecision.scoped,
1152
+ allow_unscoped_databases: scopeDecision.allow_unscoped,
1153
+ fail_closed: scopeDecision.fail_closed,
1154
+ env_narrowed_scope: scopeDecision.env_narrowed,
1155
+ max_negotiable_role: configuredRoleCeiling,
1156
+ },
1157
+ };
1158
+ hasPendingStatusWrite = false;
1159
+ await writeStatusFile({ path: opts.statusFile }, status);
1160
+ if (!hasPendingStatusWrite) {
1161
+ break;
1162
+ }
1163
+ }
1164
+ }
1165
+ finally {
1166
+ isWritingStatus = false;
1167
+ }
1168
+ };
1169
+ const dbConfigPath = getDbConfigPath();
1170
+ const reloadDbConfig = async () => {
1171
+ try {
1172
+ const next = loadDatabasesConfig();
1173
+ currentDatabasesConfig = next;
1174
+ configRevision = Date.now();
1175
+ // Close every pool whose connection parameters no longer match the
1176
+ // config: a rotated password, a new host, an ssl_mode change or a
1177
+ // permission_override change. Previously only *removed* aliases were
1178
+ // closed, so an edited entry kept serving from the old pg.Pool until the
1179
+ // idle timer fired — revoking a compromised credential did not take
1180
+ // effect.
1181
+ const closed = await poolManager.reconcile(next.databases);
1182
+ if (closed.length > 0) {
1183
+ console.error(`[config] Closed ${closed.length} connection pool(s) whose settings changed: ${closed.join(', ')}.`);
1184
+ }
1185
+ await writeStatus();
1186
+ }
1187
+ catch (err) {
1188
+ trackError(err, { op: 'reloadDbConfig' });
1189
+ console.error('[config] failed to reload database config:', err);
1190
+ }
1191
+ };
1192
+ try {
1193
+ fs.watchFile(dbConfigPath, { interval: 1000 }, (curr, prev) => {
1194
+ if (curr.mtimeMs !== prev.mtimeMs || curr.size !== prev.size) {
1195
+ void reloadDbConfig();
1196
+ }
1197
+ });
1198
+ shutdown.register('db-config-watcher', async () => {
1199
+ fs.unwatchFile(dbConfigPath);
1200
+ });
1201
+ }
1202
+ catch (err) {
1203
+ trackError(err, { op: 'watchDbConfig' });
1204
+ }
1205
+ try {
1206
+ await session.start();
1207
+ }
1208
+ catch (err) {
1209
+ await failStartup(err, 'session.start');
1210
+ }
1211
+ const heartbeat = setInterval(() => {
1212
+ writeStatus().catch((err) => {
1213
+ console.error('[heartbeat] failed to write status:', err);
1214
+ });
1215
+ }, 30_000);
1216
+ let autoExitTimer;
1217
+ if (opts.autoExitMs) {
1218
+ autoExitTimer = setTimeout(() => {
1219
+ debugLog('[daemon] Auto exit triggered');
1220
+ shutdown.shutdown(5_000).catch(() => { });
1221
+ }, opts.autoExitMs);
1222
+ }
1223
+ await new Promise((resolve) => {
1224
+ const checkShutdown = setInterval(() => {
1225
+ if (shutdown.isShuttingDown()) {
1226
+ clearInterval(checkShutdown);
1227
+ debugLog(`[daemon] ${new Date().toISOString()} Shutdown detected, proceeding to cleanup...`);
1228
+ resolve();
1229
+ }
1230
+ }, 100);
1231
+ });
1232
+ debugLog(`[daemon] ${new Date().toISOString()} Awaiting shutdown coordinator...`);
1233
+ const result = await shutdown.shutdown(30_000);
1234
+ debugLog(`[daemon] ${new Date().toISOString()} Shutdown coordinator finished with result: ${result}`);
1235
+ clearInterval(heartbeat);
1236
+ if (autoExitTimer)
1237
+ clearTimeout(autoExitTimer);
1238
+ debugLog(`[daemon] ${new Date().toISOString()} Deleting pid file...`);
1239
+ await deletePidFile({ path: opts.pidFile });
1240
+ debugLog(`[daemon] ${new Date().toISOString()} Uninstalling signals...`);
1241
+ uninstallSignals();
1242
+ debugLog(`[daemon] ${new Date().toISOString()} Writing final status...`);
1243
+ const finalErrorStats = getErrorLogStats();
1244
+ const finalAuditStats = buildDaemonAuditStats(stats, auditSink.getHealth());
1245
+ await writeStatusFile({ path: opts.statusFile }, {
1246
+ pid: process.pid,
1247
+ started_at: daemonStartedAt,
1248
+ last_heartbeat: new Date().toISOString(),
1249
+ version: VERSION,
1250
+ channels: {
1251
+ sse: 'disconnected',
1252
+ wss: 'disconnected',
1253
+ },
1254
+ stats: {
1255
+ queries_served: stats.queries_served,
1256
+ streams_served: stats.streams_served,
1257
+ migrations_run: stats.migrations_run,
1258
+ cancellations: stats.cancellations,
1259
+ permission_denies: stats.permission_denies,
1260
+ audit_events_written: finalAuditStats.audit_events_written,
1261
+ audit_events_failed: finalAuditStats.audit_events_failed,
1262
+ audit_buffer_overflows: finalAuditStats.audit_buffer_overflows,
1263
+ audit_dropped: finalAuditStats.audit_dropped,
1264
+ },
1265
+ audit: finalAuditStats.audit,
1266
+ config: {
1267
+ databases: currentDatabasesConfig.databases.length,
1268
+ projects: new Set(currentDatabasesConfig.databases.map((db) => db.project_name)).size,
1269
+ revision: configRevision,
1270
+ },
1271
+ errors_log: {
1272
+ path: finalErrorStats.path,
1273
+ size_bytes: finalErrorStats.size_bytes,
1274
+ },
1275
+ });
1276
+ debugLog(`[daemon] runAgent returning exit code: ${result === 'clean' ? 0 : 1}`);
1277
+ return result === 'clean' ? 0 : 1;
1278
+ }
1279
+ function debugLog(message) {
1280
+ if (process.env.SW_AGENT_DEBUG === '1') {
1281
+ console.error(message);
1282
+ }
1283
+ }
1284
+ //# sourceMappingURL=runtime.js.map