@geekmidas/cli 10.0.0-alpha.164 → 10.0.0-alpha.165

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 (201) hide show
  1. package/dist/{GoDaddyProvider-BrZ7WtmP.mjs → GoDaddyProvider-C7zClznh.mjs} +2 -2
  2. package/dist/{GoDaddyProvider-BrZ7WtmP.mjs.map → GoDaddyProvider-C7zClznh.mjs.map} +1 -1
  3. package/dist/{GoDaddyProvider-DSzYpSc3.cjs → GoDaddyProvider-Dx6v4Goj.cjs} +2 -2
  4. package/dist/{GoDaddyProvider-DSzYpSc3.cjs.map → GoDaddyProvider-Dx6v4Goj.cjs.map} +1 -1
  5. package/dist/{HostingerProvider-D7N8GbQm.mjs → HostingerProvider-BALtMnss.mjs} +2 -2
  6. package/dist/{HostingerProvider-D7N8GbQm.mjs.map → HostingerProvider-BALtMnss.mjs.map} +1 -1
  7. package/dist/{HostingerProvider-DQusFkZJ.cjs → HostingerProvider-COuTy74z.cjs} +2 -2
  8. package/dist/{HostingerProvider-DQusFkZJ.cjs.map → HostingerProvider-COuTy74z.cjs.map} +1 -1
  9. package/dist/{LegacyStateStore-CxQkI3fQ.cjs → LegacyStateStore-C0rh3dKV.cjs} +3 -3
  10. package/dist/{LegacyStateStore-CxQkI3fQ.cjs.map → LegacyStateStore-C0rh3dKV.cjs.map} +1 -1
  11. package/dist/{LegacyStateStore-B2vZVXVe.mjs → LegacyStateStore-CcNLLGX-.mjs} +3 -3
  12. package/dist/{LegacyStateStore-B2vZVXVe.mjs.map → LegacyStateStore-CcNLLGX-.mjs.map} +1 -1
  13. package/dist/{LocalStateStore-ff4XiebR.mjs → LocalStateStore-CxCCBQkS.mjs} +2 -2
  14. package/dist/{LocalStateStore-ff4XiebR.mjs.map → LocalStateStore-CxCCBQkS.mjs.map} +1 -1
  15. package/dist/{LocalStateStore-CrrjFgMc.cjs → LocalStateStore-Dcq3wd1v.cjs} +2 -2
  16. package/dist/{LocalStateStore-CrrjFgMc.cjs.map → LocalStateStore-Dcq3wd1v.cjs.map} +1 -1
  17. package/dist/{S3StateStore-EnatbBd3.cjs → S3StateStore-Cgf1owUZ.cjs} +4 -4
  18. package/dist/{S3StateStore-EnatbBd3.cjs.map → S3StateStore-Cgf1owUZ.cjs.map} +1 -1
  19. package/dist/{S3StateStore-62sFppnE.mjs → S3StateStore-DUwCcCgj.mjs} +4 -4
  20. package/dist/{S3StateStore-62sFppnE.mjs.map → S3StateStore-DUwCcCgj.mjs.map} +1 -1
  21. package/dist/{SSMStateStore-BON4jyRR.mjs → SSMStateStore-A_N_T4b0.mjs} +2 -2
  22. package/dist/{SSMStateStore-BON4jyRR.mjs.map → SSMStateStore-A_N_T4b0.mjs.map} +1 -1
  23. package/dist/{SSMStateStore-CYPYh1c7.cjs → SSMStateStore-BarWA07O.cjs} +2 -2
  24. package/dist/{SSMStateStore-CYPYh1c7.cjs.map → SSMStateStore-BarWA07O.cjs.map} +1 -1
  25. package/dist/{add-CzoX8swL.mjs → add-DAeCqI9O.mjs} +4 -4
  26. package/dist/{add-CzoX8swL.mjs.map → add-DAeCqI9O.mjs.map} +1 -1
  27. package/dist/{add-D65M2URP.cjs → add-DVSNjsI8.cjs} +4 -4
  28. package/dist/{add-D65M2URP.cjs.map → add-DVSNjsI8.cjs.map} +1 -1
  29. package/dist/{apps-Dquc1K9N.mjs → apps-Ck_Ie6gN.mjs} +3 -3
  30. package/dist/{apps-Dquc1K9N.mjs.map → apps-Ck_Ie6gN.mjs.map} +1 -1
  31. package/dist/{apps-DY82zCeA.cjs → apps-S3RMvFyk.cjs} +3 -3
  32. package/dist/{apps-DY82zCeA.cjs.map → apps-S3RMvFyk.cjs.map} +1 -1
  33. package/dist/{bundler-wtMYRk9K.cjs → bundler-B_vQ_591.cjs} +6 -6
  34. package/dist/{bundler-wtMYRk9K.cjs.map → bundler-B_vQ_591.cjs.map} +1 -1
  35. package/dist/{bundler-9RpLU2H3.mjs → bundler-Bbn0opSb.mjs} +6 -6
  36. package/dist/{bundler-9RpLU2H3.mjs.map → bundler-Bbn0opSb.mjs.map} +1 -1
  37. package/dist/{cli-D0Tu6u1G.mjs → cli-CMykD9Py.mjs} +4 -4
  38. package/dist/{cli-D0Tu6u1G.mjs.map → cli-CMykD9Py.mjs.map} +1 -1
  39. package/dist/{cli-CgZuiNWv.cjs → cli-fs4D-3cd.cjs} +4 -4
  40. package/dist/{cli-CgZuiNWv.cjs.map → cli-fs4D-3cd.cjs.map} +1 -1
  41. package/dist/{compose-BfTrMiAk.mjs → compose-BtjZNCC-.mjs} +21 -9
  42. package/dist/compose-BtjZNCC-.mjs.map +1 -0
  43. package/dist/{compose-DgBUpgXh.cjs → compose-CNJO99Tv.cjs} +4 -4
  44. package/dist/{compose-DgBUpgXh.cjs.map → compose-CNJO99Tv.cjs.map} +1 -1
  45. package/dist/{compose-pbLaJlts.mjs → compose-Cm6EWvjX.mjs} +4 -4
  46. package/dist/{compose-pbLaJlts.mjs.map → compose-Cm6EWvjX.mjs.map} +1 -1
  47. package/dist/{compose-kEjxTamg.cjs → compose-DmcYTLhO.cjs} +21 -9
  48. package/dist/compose-DmcYTLhO.cjs.map +1 -0
  49. package/dist/{config-DNoWqavN.d.cts → config-B8gSu59v.d.mts} +3 -3
  50. package/dist/{config-BxSSAzVi.d.mts.map → config-B8gSu59v.d.mts.map} +1 -1
  51. package/dist/{config-BxSSAzVi.d.mts → config-u5XdE1Cq.d.cts} +3 -3
  52. package/dist/{config-DNoWqavN.d.cts.map → config-u5XdE1Cq.d.cts.map} +1 -1
  53. package/dist/config.d.cts +3 -3
  54. package/dist/config.d.mts +3 -3
  55. package/dist/{credentials-BgtOz5ec.mjs → credentials-C-yuISKH.mjs} +5 -5
  56. package/dist/{credentials-BgtOz5ec.mjs.map → credentials-C-yuISKH.mjs.map} +1 -1
  57. package/dist/{credentials-Bel6afW2.cjs → credentials-DVYgFK_H.cjs} +5 -5
  58. package/dist/{credentials-Bel6afW2.cjs.map → credentials-DVYgFK_H.cjs.map} +1 -1
  59. package/dist/deploy/public.cjs +11 -11
  60. package/dist/deploy/public.d.cts +4 -4
  61. package/dist/deploy/public.d.mts +4 -4
  62. package/dist/deploy/public.mjs +11 -11
  63. package/dist/{deploy-D-5ib-ah.mjs → deploy-CuSF9y7t.mjs} +161 -55
  64. package/dist/deploy-CuSF9y7t.mjs.map +1 -0
  65. package/dist/{deploy-C4V-nsOF.cjs → deploy-DGXMqTan.cjs} +160 -54
  66. package/dist/deploy-DGXMqTan.cjs.map +1 -0
  67. package/dist/{destroy-DuQqz53a.cjs → destroy-BROvAzQQ.cjs} +9 -9
  68. package/dist/{destroy-DuQqz53a.cjs.map → destroy-BROvAzQQ.cjs.map} +1 -1
  69. package/dist/{destroy-CYQCEn4A.mjs → destroy-DpRGLdt1.mjs} +9 -9
  70. package/dist/{destroy-CYQCEn4A.mjs.map → destroy-DpRGLdt1.mjs.map} +1 -1
  71. package/dist/{docker-BEsTfsFc.mjs → docker-CRVWdGH9.mjs} +4 -4
  72. package/dist/{docker-BEsTfsFc.mjs.map → docker-CRVWdGH9.mjs.map} +1 -1
  73. package/dist/{docker-BMReDeMB.cjs → docker-qq5xNUP2.cjs} +4 -4
  74. package/dist/{docker-BMReDeMB.cjs.map → docker-qq5xNUP2.cjs.map} +1 -1
  75. package/dist/{dokploy-BuYCnz9U.mjs → dokploy-DcH7hY84.mjs} +2 -2
  76. package/dist/{dokploy-BuYCnz9U.mjs.map → dokploy-DcH7hY84.mjs.map} +1 -1
  77. package/dist/{dokploy-BpPAgZ0u.cjs → dokploy-Duyj4-pa.cjs} +2 -2
  78. package/dist/{dokploy-BpPAgZ0u.cjs.map → dokploy-Duyj4-pa.cjs.map} +1 -1
  79. package/dist/{eas-DjVtUdb4.mjs → eas-C11dyfIw.mjs} +2 -2
  80. package/dist/{eas-DjVtUdb4.mjs.map → eas-C11dyfIw.mjs.map} +1 -1
  81. package/dist/{eas-H-6ixmsY.cjs → eas-DqTDImhv.cjs} +2 -2
  82. package/dist/{eas-H-6ixmsY.cjs.map → eas-DqTDImhv.cjs.map} +1 -1
  83. package/dist/{encryption-BvCsBp2p.cjs → encryption-CsOfA6QT.cjs} +2 -2
  84. package/dist/{encryption-BvCsBp2p.cjs.map → encryption-CsOfA6QT.cjs.map} +1 -1
  85. package/dist/{encryption-CR4aMkSK.mjs → encryption-DsZwqQyL.mjs} +2 -2
  86. package/dist/{encryption-CR4aMkSK.mjs.map → encryption-DsZwqQyL.mjs.map} +1 -1
  87. package/dist/{engine-upEpdhEF.mjs → engine-CdU3Oggs.mjs} +9 -9
  88. package/dist/{engine-upEpdhEF.mjs.map → engine-CdU3Oggs.mjs.map} +1 -1
  89. package/dist/{engine-CV2wqRFl.cjs → engine-WllCnGNy.cjs} +9 -9
  90. package/dist/{engine-CV2wqRFl.cjs.map → engine-WllCnGNy.cjs.map} +1 -1
  91. package/dist/{github-BDOLgdMp.cjs → github-B3lKrKIn.cjs} +6 -6
  92. package/dist/{github-BDOLgdMp.cjs.map → github-B3lKrKIn.cjs.map} +1 -1
  93. package/dist/{github-D2l7aqFx.mjs → github-Bt3V7pdf.mjs} +6 -6
  94. package/dist/{github-D2l7aqFx.mjs.map → github-Bt3V7pdf.mjs.map} +1 -1
  95. package/dist/{googlePlay-B3FR1VGL.cjs → googlePlay-B7P3Ahps.cjs} +4 -4
  96. package/dist/{googlePlay-B3FR1VGL.cjs.map → googlePlay-B7P3Ahps.cjs.map} +1 -1
  97. package/dist/{googlePlay-DJ2Kv0UX.mjs → googlePlay-D-6pUHGU.mjs} +4 -4
  98. package/dist/{googlePlay-DJ2Kv0UX.mjs.map → googlePlay-D-6pUHGU.mjs.map} +1 -1
  99. package/dist/{index-Dy4ojz5P.d.cts → index-1H93w_H6.d.cts} +2 -2
  100. package/dist/{index-BC1BLv9Q.d.mts.map → index-1H93w_H6.d.cts.map} +1 -1
  101. package/dist/{index-BC1BLv9Q.d.mts → index-DFZ0SMwN.d.mts} +2 -2
  102. package/dist/{index-Dy4ojz5P.d.cts.map → index-DFZ0SMwN.d.mts.map} +1 -1
  103. package/dist/index.cjs +62 -62
  104. package/dist/index.cjs.map +1 -1
  105. package/dist/index.mjs +62 -62
  106. package/dist/index.mjs.map +1 -1
  107. package/dist/{local-COaqGFDc.mjs → local-B4H2Lsr6.mjs} +2 -2
  108. package/dist/{local-COaqGFDc.mjs.map → local-B4H2Lsr6.mjs.map} +1 -1
  109. package/dist/{local-DhAnAhXn.cjs → local-Cs_aQJ45.cjs} +2 -2
  110. package/dist/{local-DhAnAhXn.cjs.map → local-Cs_aQJ45.cjs.map} +1 -1
  111. package/dist/{migrate-CusdrYsn.cjs → migrate-BQSPfKHa.cjs} +4 -4
  112. package/dist/{migrate-CusdrYsn.cjs.map → migrate-BQSPfKHa.cjs.map} +1 -1
  113. package/dist/{migrate-CpT7qBZE.mjs → migrate-C8JFuMT-.mjs} +2 -2
  114. package/dist/{migrate-CpT7qBZE.mjs.map → migrate-C8JFuMT-.mjs.map} +1 -1
  115. package/dist/{migrate-Nt9NOr1s.mjs → migrate-CQ-PNghX.mjs} +4 -4
  116. package/dist/{migrate-Nt9NOr1s.mjs.map → migrate-CQ-PNghX.mjs.map} +1 -1
  117. package/dist/{migrate-Hjvo9j_J.cjs → migrate-CphnV0sY.cjs} +2 -2
  118. package/dist/{migrate-Hjvo9j_J.cjs.map → migrate-CphnV0sY.cjs.map} +1 -1
  119. package/dist/{notes-CZvLIjfg.cjs → notes-BtyuHcKA.cjs} +2 -2
  120. package/dist/{notes-CZvLIjfg.cjs.map → notes-BtyuHcKA.cjs.map} +1 -1
  121. package/dist/{notes-B-tgKkvp.mjs → notes-IlQ35E3R.mjs} +2 -2
  122. package/dist/{notes-B-tgKkvp.mjs.map → notes-IlQ35E3R.mjs.map} +1 -1
  123. package/dist/openapi.d.cts +1 -1
  124. package/dist/openapi.d.mts +1 -1
  125. package/dist/{projectBucket-XyxlpATc.cjs → projectBucket-0Lvy2J0h.cjs} +2 -2
  126. package/dist/{projectBucket-XyxlpATc.cjs.map → projectBucket-0Lvy2J0h.cjs.map} +1 -1
  127. package/dist/{projectBucket-DNAOBIYZ.mjs → projectBucket-SHlF0_Pr.mjs} +2 -2
  128. package/dist/{projectBucket-DNAOBIYZ.mjs.map → projectBucket-SHlF0_Pr.mjs.map} +1 -1
  129. package/dist/{publish-CwjRq8Ye.mjs → publish-C9IJb1Ez.mjs} +2 -2
  130. package/dist/{publish-CwjRq8Ye.mjs.map → publish-C9IJb1Ez.mjs.map} +1 -1
  131. package/dist/{publish-DmBXVNlk.cjs → publish-igpjCzZj.cjs} +2 -2
  132. package/dist/{publish-DmBXVNlk.cjs.map → publish-igpjCzZj.cjs.map} +1 -1
  133. package/dist/reconcile/public.d.cts +1 -1
  134. package/dist/reconcile/public.d.mts +1 -1
  135. package/dist/{resolve-BuqA14hD.cjs → resolve-5T34quci.cjs} +4 -4
  136. package/dist/{resolve-BuqA14hD.cjs.map → resolve-5T34quci.cjs.map} +1 -1
  137. package/dist/{resolve-vOUrXSHP.mjs → resolve-Cl8CVASM.mjs} +4 -4
  138. package/dist/{resolve-vOUrXSHP.mjs.map → resolve-Cl8CVASM.mjs.map} +1 -1
  139. package/dist/{rollback-glkFgz6-.mjs → rollback-1JLE6qPo.mjs} +6 -6
  140. package/dist/{rollback-glkFgz6-.mjs.map → rollback-1JLE6qPo.mjs.map} +1 -1
  141. package/dist/{rollback-CiyKH1HK.cjs → rollback-DMPb940C.cjs} +6 -6
  142. package/dist/{rollback-CiyKH1HK.cjs.map → rollback-DMPb940C.cjs.map} +1 -1
  143. package/dist/{runtime-MZ5Pqgan.d.mts → runtime-CKOkIrw0.d.cts} +2 -2
  144. package/dist/{runtime-BySbkdBz.d.cts.map → runtime-CKOkIrw0.d.cts.map} +1 -1
  145. package/dist/{runtime-BySbkdBz.d.cts → runtime-Cdvv8SfU.d.mts} +2 -2
  146. package/dist/{runtime-MZ5Pqgan.d.mts.map → runtime-Cdvv8SfU.d.mts.map} +1 -1
  147. package/dist/{s3-BZbRcH8T.mjs → s3-CCuNLgHk.mjs} +2 -2
  148. package/dist/{s3-BZbRcH8T.mjs.map → s3-CCuNLgHk.mjs.map} +1 -1
  149. package/dist/{s3-C0EBuF8n.cjs → s3-DkiOi5J1.cjs} +2 -2
  150. package/dist/{s3-C0EBuF8n.cjs.map → s3-DkiOi5J1.cjs.map} +1 -1
  151. package/dist/{seeds-D7q1zKCJ.cjs → seeds-Bc3niNVb.cjs} +95 -82
  152. package/dist/seeds-Bc3niNVb.cjs.map +1 -0
  153. package/dist/{seeds-y1rzXlAc.mjs → seeds-Ccn0Ru2T.mjs} +84 -83
  154. package/dist/seeds-Ccn0Ru2T.mjs.map +1 -0
  155. package/dist/{serverSetup-Dlj7JQW-.mjs → serverSetup-C0pLpF5w.mjs} +6 -6
  156. package/dist/{serverSetup-Dlj7JQW-.mjs.map → serverSetup-C0pLpF5w.mjs.map} +1 -1
  157. package/dist/{serverSetup-n1Znminh.cjs → serverSetup-JYZxj371.cjs} +6 -6
  158. package/dist/{serverSetup-n1Znminh.cjs.map → serverSetup-JYZxj371.cjs.map} +1 -1
  159. package/dist/{sniffer-BgzTs_Zt.mjs → sniffer-CiV4xGbe.mjs} +7 -7
  160. package/dist/{sniffer-BgzTs_Zt.mjs.map → sniffer-CiV4xGbe.mjs.map} +1 -1
  161. package/dist/{sniffer-DDAxYDqU.cjs → sniffer-DB4Ocija.cjs} +7 -7
  162. package/dist/{sniffer-DDAxYDqU.cjs.map → sniffer-DB4Ocija.cjs.map} +1 -1
  163. package/dist/{snsSubscriptions-CCyxCMoc.mjs → snsSubscriptions-C_-6fqBd.mjs} +2 -2
  164. package/dist/{snsSubscriptions-CCyxCMoc.mjs.map → snsSubscriptions-C_-6fqBd.mjs.map} +1 -1
  165. package/dist/{snsSubscriptions-Dr5ghfa5.cjs → snsSubscriptions-DpYvMVR9.cjs} +2 -2
  166. package/dist/{snsSubscriptions-Dr5ghfa5.cjs.map → snsSubscriptions-DpYvMVR9.cjs.map} +1 -1
  167. package/dist/{sst-CV5TemXa.mjs → sst-BUzuE84X.mjs} +4 -4
  168. package/dist/{sst-CV5TemXa.mjs.map → sst-BUzuE84X.mjs.map} +1 -1
  169. package/dist/{sst-DBkHn3mA.cjs → sst-D1oSl_1d.cjs} +4 -4
  170. package/dist/{sst-DBkHn3mA.cjs.map → sst-D1oSl_1d.cjs.map} +1 -1
  171. package/dist/{stack-r97Ao-uG.mjs → stack-DhBBTTIa.mjs} +6 -6
  172. package/dist/{stack-r97Ao-uG.mjs.map → stack-DhBBTTIa.mjs.map} +1 -1
  173. package/dist/{stack-Dku1pOA2.cjs → stack-TUs2DY7v.cjs} +6 -6
  174. package/dist/{stack-Dku1pOA2.cjs.map → stack-TUs2DY7v.cjs.map} +1 -1
  175. package/dist/{stage-Du8I-UIa.cjs → stage-B3qg7LoZ.cjs} +5 -5
  176. package/dist/{stage-Du8I-UIa.cjs.map → stage-B3qg7LoZ.cjs.map} +1 -1
  177. package/dist/{stage-Deb-7Ohk.mjs → stage-DuLwZ9wu.mjs} +5 -5
  178. package/dist/{stage-Deb-7Ohk.mjs.map → stage-DuLwZ9wu.mjs.map} +1 -1
  179. package/dist/target/public.cjs +1 -1
  180. package/dist/target/public.d.cts +2 -2
  181. package/dist/target/public.d.mts +2 -2
  182. package/dist/target/public.mjs +1 -1
  183. package/dist/{terminal-BEa0E3pz.mjs → terminal-B_TanNPL.mjs} +2 -2
  184. package/dist/{terminal-BEa0E3pz.mjs.map → terminal-B_TanNPL.mjs.map} +1 -1
  185. package/dist/{terminal-BXpp9kBr.cjs → terminal-CXZWPHMW.cjs} +2 -2
  186. package/dist/{terminal-BXpp9kBr.cjs.map → terminal-CXZWPHMW.cjs.map} +1 -1
  187. package/dist/{types-BsfPHUFZ.d.cts → types-DEmuMHsS.d.cts} +9 -1
  188. package/dist/types-DEmuMHsS.d.cts.map +1 -0
  189. package/dist/{types-BXboFkn9.d.mts → types-g_S0_RAi.d.mts} +9 -1
  190. package/dist/types-g_S0_RAi.d.mts.map +1 -0
  191. package/dist/workspace/index.d.cts +2 -2
  192. package/dist/workspace/index.d.mts +2 -2
  193. package/package.json +15 -15
  194. package/dist/compose-BfTrMiAk.mjs.map +0 -1
  195. package/dist/compose-kEjxTamg.cjs.map +0 -1
  196. package/dist/deploy-C4V-nsOF.cjs.map +0 -1
  197. package/dist/deploy-D-5ib-ah.mjs.map +0 -1
  198. package/dist/seeds-D7q1zKCJ.cjs.map +0 -1
  199. package/dist/seeds-y1rzXlAc.mjs.map +0 -1
  200. package/dist/types-BXboFkn9.d.mts.map +0 -1
  201. package/dist/types-BsfPHUFZ.d.cts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"compose-pbLaJlts.mjs","names":[],"sources":["../src/workspace/rootSite.ts","../src/target/dokploy/domain.ts","../src/compose/logs.ts","../src/reconcile/containers.ts","../src/reconcile/emulator.ts","../src/reconcile/objectEvents.ts","../src/compose/redis.ts","../src/deploy/generated.ts","../src/reconcile/localCredentials.ts","../src/credentials/index.ts","../src/reconcile/compose.ts"],"sourcesContent":["/**\n * Which site the base domain points at — deployed and locally alike.\n *\n * Three rules, in order, and the last one is the point:\n *\n * 1. **One site** — it is the root. Unambiguous, so nothing has to be said.\n * 2. **Named `web`** — the convention wins, because people already rely on it.\n * 3. **Declared `root: true`** — the site says so itself.\n *\n * Anything else throws. It used to take the *first* site it iterated, and that\n * order came from the manifest, which is built in glob traversal order — so two\n * sites with neither named `web` meant renaming a file could move the root\n * domain, silently.\n *\n * One rule for both targets: deployed the root site gets the base domain, and\n * locally it gets the project's bare host behind the edge. Before this was\n * shared, the local edge put every site on a subdomain, so what a developer\n * browsed was not the shape production served.\n *\n * @returns the root site's name, or `undefined` when there are no sites\n * @throws {AmbiguousRootSite} when several sites could be the root and none says it is\n */\n\nimport { GkmError } from '../errors';\nexport function rootSite(\n\tsites: readonly { name: string; root?: boolean }[],\n): string | undefined {\n\tif (sites.length === 0) return undefined;\n\n\t// 1. The only site there is.\n\tif (sites.length === 1) return sites[0]!.name;\n\n\t// 2. The convention.\n\tif (sites.some(({ name }) => name === 'web')) return 'web';\n\n\t// 3. What a site declared about itself.\n\tconst declared = sites.filter(({ root }) => root === true);\n\tif (declared.length === 1) return declared[0]!.name;\n\n\tthrow new AmbiguousRootSite(\n\t\tsites.map(({ name }) => name),\n\t\tdeclared.length > 1,\n\t);\n}\n\n/** Several sites could hold the base domain, and none of them says it does. */\nexport class AmbiguousRootSite extends GkmError {\n\tconstructor(\n\t\treadonly sites: readonly string[],\n\t\treadonly tooMany = false,\n\t) {\n\t\tsuper(\n\t\t\ttooMany\n\t\t\t\t? `More than one site declares \\`root: true\\` — ${sites.join(', ')}. ` +\n\t\t\t\t\t\t`The base domain points at one of them.`\n\t\t\t\t: `${sites.length} sites and nothing says which holds the base ` +\n\t\t\t\t\t\t`domain: ${sites.join(', ')}. Name one of them \\`web\\`, or ` +\n\t\t\t\t\t\t`declare \\`root: true\\` on the one the base domain points at. ` +\n\t\t\t\t\t\t`It used to be whichever the glob reached first, which is not a ` +\n\t\t\t\t\t\t`thing to decide a hostname.`,\n\t\t);\n\t\tthis.name = 'AmbiguousRootSite';\n\t}\n}\n","import { WILDCARD_SUBDOMAIN } from '@geekmidas/manifest';\nimport { GkmError } from '../../errors';\nimport { getPublicEnvPrefix } from '../../workspace/index.js';\nimport { rootSite } from '../../workspace/rootSite.js';\nimport type {\n\tDomainsConfig,\n\tNormalizedAppConfig,\n} from '../../workspace/types.js';\n\n/** A stage was deployed that `domains` gives no domain. */\nexport class NoDomainForStage extends GkmError {\n\tconstructor(readonly stage: string) {\n\t\tsuper(\n\t\t\t`No domain for stage \"${stage}\". Add it to gkm.config.ts: domains: { ${stage}: 'example.com' }.`,\n\t\t);\n\t\tthis.name = 'NoDomainForStage';\n\t}\n}\n\n/**\n * The hostname an app answers on for a stage.\n *\n * 1. An explicit `app.domain` — a string, or one per stage — wins.\n * 2. Otherwise from the stage's base domain in `domains`: the root site\n * answers on the domain itself, and every other app on\n * `{subdomain}.{domain}` — its declaration's `subdomain`, or its own name.\n *\n * @throws {NoDomainForStage} when `domains` names no domain for it\n */\nexport function resolveHost(\n\tappName: string,\n\tapp: NormalizedAppConfig,\n\tstage: string,\n\tdomains: DomainsConfig | undefined,\n\tisMainFrontend: boolean,\n): string {\n\tif (app.domain) {\n\t\tif (typeof app.domain === 'string') {\n\t\t\treturn app.domain;\n\t\t}\n\t\tif (app.domain[stage]) {\n\t\t\treturn app.domain[stage]!;\n\t\t}\n\t}\n\n\tconst baseDomain = domains?.[stage];\n\tif (!baseDomain) throw new NoDomainForStage(stage);\n\n\tif (isMainFrontend) return baseDomain;\n\n\treturn `${app.subdomain ?? appName}.${baseDomain}`;\n}\n\n/**\n * Whether this app is the site the base domain points at — see `rootSite`,\n * which the local edge asks too.\n *\n * @throws {AmbiguousRootSite} when several sites could be the root and none says it is\n */\nexport function isMainFrontendApp(\n\tappName: string,\n\tapp: NormalizedAppConfig,\n\tallApps: Record<string, NormalizedAppConfig>,\n): boolean {\n\t// A wildcard site answers on every subdomain, never on the domain itself.\n\tconst holds = (a: NormalizedAppConfig) =>\n\t\ta.type === 'web' && a.subdomain !== WILDCARD_SUBDOMAIN;\n\tif (!holds(app)) return false;\n\n\tconst sites = Object.entries(allApps)\n\t\t.filter(([, a]) => holds(a))\n\t\t.map(([name, a]) => ({ name, root: a.root }));\n\n\treturn rootSite(sites) === appName;\n}\n\nexport { AmbiguousRootSite } from '../../workspace/rootSite.js';\n\n/**\n * Generate public URL build args for a web/mobile app based on its dependencies.\n *\n * The prefix is chosen by the app's framework (NEXT_PUBLIC_, VITE_,\n * EXPO_PUBLIC_, or none for Remix). Apps without a public prefix get no\n * build args — they should fetch URLs at runtime instead.\n *\n * @param app - The web/mobile app configuration\n * @param deployedUrls - Map of app name to deployed public URL\n * @returns Array of build args like 'NEXT_PUBLIC_API_URL=https://api.example.com'\n */\nexport function generatePublicUrlBuildArgs(\n\tapp: NormalizedAppConfig,\n\tdeployedUrls: Record<string, string>,\n): string[] {\n\tconst prefix = getPublicEnvPrefix(app.framework);\n\tif (!prefix) return [];\n\n\tconst buildArgs: string[] = [];\n\tfor (const dep of app.dependencies) {\n\t\tconst publicUrl = deployedUrls[dep];\n\t\tif (publicUrl) {\n\t\t\tbuildArgs.push(`${prefix}${dep.toUpperCase()}_URL=${publicUrl}`);\n\t\t}\n\t}\n\n\treturn buildArgs;\n}\n\n/**\n * Get public URL arg names from app dependencies.\n *\n * @param app - The web/mobile app configuration\n * @returns Array of arg names like 'NEXT_PUBLIC_API_URL', or [] for frameworks\n * without a public prefix (e.g. Remix).\n */\nexport function getPublicUrlArgNames(app: NormalizedAppConfig): string[] {\n\tconst prefix = getPublicEnvPrefix(app.framework);\n\tif (!prefix) return [];\n\treturn app.dependencies.map((dep) => `${prefix}${dep.toUpperCase()}_URL`);\n}\n","/**\n * The stack's log UI: OpenObserve, run beside the apps as telemetry's\n * self-hosted provider, and every process with a `Telemetry` edge pointed at\n * it.\n *\n * The production server already exports its traces and pino logs over\n * OTLP/HTTP when `OTEL_EXPORTER_OTLP_ENDPOINT` is set. OpenObserve takes OTLP\n * at `/api/<org>/v1/{logs,traces}` with HTTP basic auth, so wiring an app is\n * two variables: the endpoint, `http://openobserve:5080/api/default`, and\n * the header that signs in as the root user.\n *\n * It is reached, by default, through an SSH tunnel: published on 127.0.0.1\n * only, because a port Docker publishes on every interface is opened in the\n * firewall by Docker itself, past ufw's rules. Served publicly, it is a host\n * on the stack's Caddy that refuses every address not allowed.\n *\n * Pure: the stack decides it, and the phases print and check it.\n */\n\nimport { randomBytes } from 'node:crypto';\nimport { GkmError } from '../errors';\nimport type { StageSecrets } from '../secrets/types.js';\nimport { NoDomainForStage } from '../target/dokploy/domain.js';\nimport { LOGS_PORT, type ResolvedLogs } from './logsConfig.js';\nimport type { StackService } from './stack.js';\n\n/**\n * The image, pinned. A log store's on-disk format is the thing that must not\n * move under a running stack, so a new version is a change to this line.\n */\nexport const OPENOBSERVE_IMAGE = 'public.ecr.aws/zinclabs/openobserve:v1.0.4';\n\n/** Its compose service name — the host the apps send to. */\nexport const LOGS_SERVICE = 'openobserve';\n\n/** The organisation every app's telemetry lands in. */\nexport const LOGS_ORG = 'default';\n\n/** The stage secrets that sign in as OpenObserve's root user. */\nexport const LOGS_EMAIL_KEY = 'ZO_ROOT_USER_EMAIL';\nexport const LOGS_PASSWORD_KEY = 'ZO_ROOT_USER_PASSWORD';\n\n/**\n * The local stage's root user. Its password is generated per machine with\n * the other local logins — see `reconcile/localCredentials.ts`.\n */\nexport const LOCAL_LOGS_EMAIL = 'admin@gkm.localhost';\n\n/** The stack's OpenObserve, as the stack runs it. */\nexport interface StackLogs extends ResolvedLogs {\n\t/** The root user's email and password. */\n\temail: string;\n\tpassword: string;\n\t/** Whether the stage's secrets set the password, rather than the local login. */\n\tpasswordFromSecrets: boolean;\n\t/** Where a browser opens it: the tunnel's end, or its public host. */\n\turl: string;\n\t/** Its public host, when it is served through Caddy. */\n\thost?: string;\n\t/** Its own environment, written to `openobserve.env` (0600). */\n\tenv: Record<string, string>;\n\t/** Where every process with a `Telemetry` edge sends, and how it signs. */\n\tappEnv: {\n\t\tOTEL_EXPORTER_OTLP_ENDPOINT: string;\n\t\tOTEL_EXPORTER_OTLP_HEADERS: string;\n\t};\n}\n\n/** A root password OpenObserve would refuse to start with. */\nexport class LogsPasswordWeak extends GkmError {\n\tconstructor(readonly stage: string) {\n\t\tsuper(\n\t\t\t`The stage '${stage}' sets ${LOGS_PASSWORD_KEY}, and OpenObserve refuses ` +\n\t\t\t\t'it: a root password must be 8 to 128 characters with a lowercase ' +\n\t\t\t\t'letter, an uppercase letter, a digit and a symbol. Set another with ' +\n\t\t\t\t`gkm secrets:set ${LOGS_PASSWORD_KEY} '…' --stage ${stage}, or unset ` +\n\t\t\t\t'it to have one generated.',\n\t\t);\n\t\tthis.name = 'LogsPasswordWeak';\n\t}\n}\n\n/** A deployed stage with logs on and no root password generated yet. */\nexport class LogsPasswordMissing extends GkmError {\n\tconstructor(readonly stage: string) {\n\t\tsuper(\n\t\t\t`The stage '${stage}' runs OpenObserve and has no ${LOGS_PASSWORD_KEY} ` +\n\t\t\t\t`in its secrets. Run gkm compose --stage ${stage} without --dry-run ` +\n\t\t\t\t'once to generate it, or set one: ' +\n\t\t\t\t`gkm secrets:set ${LOGS_PASSWORD_KEY} '…' --stage ${stage}`,\n\t\t);\n\t\tthis.name = 'LogsPasswordMissing';\n\t}\n}\n\n/** Whether OpenObserve accepts `password` for its root user. */\nexport function isStrongLogsPassword(password: string): boolean {\n\treturn (\n\t\tpassword.length >= 8 &&\n\t\tpassword.length <= 128 &&\n\t\t/[a-z]/.test(password) &&\n\t\t/[A-Z]/.test(password) &&\n\t\t/\\d/.test(password) &&\n\t\t/[^A-Za-z0-9]/.test(password)\n\t);\n}\n\n/**\n * A root password: 192 random bits, with a fixed tail so every class\n * OpenObserve requires is present whatever the random part drew.\n */\nexport function generateLogsPassword(): string {\n\treturn `${randomBytes(24).toString('base64url')}-Zo1`;\n}\n\n/**\n * The stage's secrets with a generated root password, where it has none.\n * Pure, like `withGeneratedSecrets`: the caller keeps the result once the\n * run goes ahead.\n */\nexport function withLogsPassword(secrets: StageSecrets): {\n\tsecrets: StageSecrets;\n\tgenerated: string[];\n} {\n\tif (secrets.custom?.[LOGS_PASSWORD_KEY]) return { secrets, generated: [] };\n\treturn {\n\t\tsecrets: {\n\t\t\t...secrets,\n\t\t\tcustom: {\n\t\t\t\t...secrets.custom,\n\t\t\t\t[LOGS_PASSWORD_KEY]: generateLogsPassword(),\n\t\t\t},\n\t\t\tupdatedAt: new Date().toISOString(),\n\t\t},\n\t\tgenerated: [LOGS_PASSWORD_KEY],\n\t};\n}\n\n/**\n * `OTEL_EXPORTER_OTLP_HEADERS` signing in as `email`.\n *\n * The variable's values are percent-decoded by the SDK (they follow the W3C\n * baggage format), so the space after `Basic` is written `%20`. Base64's own\n * `+`, `/` and `=` pass through decoding unchanged.\n */\nexport function otlpHeaders(email: string, password: string): string {\n\tconst token = Buffer.from(`${email}:${password}`).toString('base64');\n\treturn `Authorization=Basic%20${token}`;\n}\n\n/** The stack's OpenObserve for one stage. */\nexport function stackLogs(options: {\n\tconfig: ResolvedLogs;\n\tstage: string;\n\tlocal: boolean;\n\t/** The workspace's name: the local stage's public host is under it. */\n\tproject: string;\n\tdomain?: string;\n\tcustom: Readonly<Record<string, string>>;\n\t/** The edge's HTTPS port, which a local public URL carries. */\n\thttps: number;\n\t/** The local stage's generated root login — required for it. */\n\tlocalLogin?: { email: string; password: string };\n}): StackLogs {\n\tconst { config, stage, local, custom } = options;\n\n\tif (!local && !options.domain) throw new NoDomainForStage(stage);\n\n\tconst email =\n\t\tcustom[LOGS_EMAIL_KEY] ??\n\t\t(local\n\t\t\t? (options.localLogin?.email ?? LOCAL_LOGS_EMAIL)\n\t\t\t: `admin@${options.domain}`);\n\tconst set = custom[LOGS_PASSWORD_KEY];\n\tconst password = set ?? (local ? options.localLogin?.password : undefined);\n\tif (!password) throw new LogsPasswordMissing(stage);\n\tif (!isStrongLogsPassword(password)) throw new LogsPasswordWeak(stage);\n\n\tconst host = config.public\n\t\t? local\n\t\t\t? `logs.${options.project}.localhost`\n\t\t\t: `logs.${options.domain}`\n\t\t: undefined;\n\tconst url = host\n\t\t? `https://${host}${local && options.https !== 443 ? `:${options.https}` : ''}`\n\t\t: `http://localhost:${config.port}`;\n\n\treturn {\n\t\t...config,\n\t\temail,\n\t\tpassword,\n\t\tpasswordFromSecrets: Boolean(set),\n\t\turl,\n\t\t...(host ? { host } : {}),\n\t\tenv: {\n\t\t\t[LOGS_EMAIL_KEY]: email,\n\t\t\t[LOGS_PASSWORD_KEY]: password,\n\t\t\tZO_DATA_DIR: '/data',\n\t\t\t// Verified against the image: days, and it refuses fewer than 3.\n\t\t\tZO_COMPACT_DATA_RETENTION_DAYS: String(config.retentionDays),\n\t\t\t// A self-hosted log store on a stage's box does not report home.\n\t\t\tZO_TELEMETRY: 'false',\n\t\t},\n\t\tappEnv: {\n\t\t\tOTEL_EXPORTER_OTLP_ENDPOINT: `http://${LOGS_SERVICE}:${LOGS_PORT}/api/${LOGS_ORG}`,\n\t\t\tOTEL_EXPORTER_OTLP_HEADERS: otlpHeaders(email, password),\n\t\t},\n\t};\n}\n\n/**\n * OpenObserve's service. The image has no shell, `wget` or `curl`, so its\n * health check is its own binary asking the running server for its status —\n * which exits non-zero when nothing answers on its port.\n */\nexport function logsService(logs: StackLogs): StackService {\n\treturn {\n\t\timage: OPENOBSERVE_IMAGE,\n\t\trestart: 'unless-stopped',\n\t\tenv_file: [{ path: `./${LOGS_SERVICE}.env`, format: 'raw' }],\n\t\tvolumes: ['openobserve-data:/data'],\n\t\t// Loopback only: Docker opens a port it publishes on every interface in\n\t\t// the firewall itself, past ufw. Served publicly, Caddy is the way in.\n\t\t...(logs.public ? {} : { ports: [`127.0.0.1:${logs.port}:${LOGS_PORT}`] }),\n\t\thealthcheck: {\n\t\t\ttest: ['CMD', '/openobserve', 'node', 'status'],\n\t\t\tinterval: '10s',\n\t\t\ttimeout: '5s',\n\t\t\tretries: 12,\n\t\t\tstart_period: '20s',\n\t\t},\n\t};\n}\n\n/** Where to guess the stack is reached from, for the printed tunnel. */\nexport interface LogsAccessContext {\n\tstage: string;\n\tlocal: boolean;\n\t/**\n\t * The SSH target: the stage's server login, or — for the local stage —\n\t * this machine's user and name, the best guess at it.\n\t */\n\tuser: string;\n\thostname: string;\n\t/** Whether `user` and `hostname` are the stage's server, not a guess. */\n\tknown?: boolean;\n}\n\n/** What `gkm compose` prints once the stack is up: how to open the logs. */\nexport function logsAccess(logs: StackLogs, ctx: LogsAccessContext): string[] {\n\tconst login = `login: ${logs.email}, password: ${\n\t\tctx.local && !logs.passwordFromSecrets\n\t\t\t? logs.password\n\t\t\t: `gkm secrets:show --stage ${ctx.stage} --reveal → ${LOGS_PASSWORD_KEY}`\n\t}`;\n\n\tif (logs.public) {\n\t\treturn [\n\t\t\t`📜 Logs (OpenObserve): ${logs.url} (${login})`,\n\t\t\t` answered only for ${logs.public.allow.join(', ')}; every other address gets 403`,\n\t\t];\n\t}\n\n\treturn [\n\t\t`📜 Logs (OpenObserve) on 127.0.0.1:${logs.port} — from your computer:`,\n\t\t// The local stage usually runs where you are; it can run on a box too.\n\t\t...(ctx.local\n\t\t\t? [\n\t\t\t\t\t` on this machine, open http://localhost:${logs.port} directly; from another:`,\n\t\t\t\t]\n\t\t\t: []),\n\t\t` ssh -N -L ${logs.port}:localhost:${logs.port} ${ctx.user}@${ctx.hostname}${ctx.known ? '' : \" (user and host are guesses: this machine's)\"}`,\n\t\t` then open http://localhost:${logs.port} (${login})`,\n\t\t`⚠️ Docker-published ports bypass ufw, so OpenObserve is bound to 127.0.0.1 only — reach it through the tunnel, not by opening the port.`,\n\t];\n}\n","import {\n\tDEFAULT_POSTGRES_VERSION,\n\tkebabCase,\n\ttype PostgresVersion,\n} from '@geekmidas/manifest';\nimport { OPENOBSERVE_IMAGE } from '../compose/logs.js';\nimport { LOGS_PORT } from '../compose/logsConfig.js';\n/**\n * What gkm knows about each container it can derive.\n *\n * Everything provider-specific about the local target lives here: the image, the\n * ports the image listens on, and whether its data is worth keeping. The plan\n * says *which* containers exist and never says any of this, which is the split\n * the design asks for — neutral facts from the declaration, provider detail\n * from here and from config.\n *\n * Shared by allocation and by the compose writer so the two cannot disagree\n * about how many ports a container needs.\n */\n\n/**\n * The Postgres image for a major version.\n *\n * One place that knows the tag shape, so a declared version reaches the\n * container without anyone restating `-alpine` beside it.\n */\nexport function postgresImage(version: PostgresVersion): string {\n\treturn `postgres:${version}-alpine`;\n}\n\n/**\n * The default image for each container.\n *\n * Pinned to a major rather than `latest` where the image publishes one, so a\n * rebuild does not silently move a developer's Postgres a version. A database\n * can name its own (`image: 'postgis/postgis:…'`); any other pin is the\n * project's own `docker-compose.yml`.\n */\nexport const DEFAULT_IMAGES: Readonly<Record<string, string>> = {\n\tpostgres: postgresImage(DEFAULT_POSTGRES_VERSION),\n\tminio: 'pgsty/minio:RELEASE.2026-08-04T00-00-00Z',\n\tmailpit: 'axllent/mailpit:latest',\n\tredis: 'redis:8-alpine',\n\t'redis-http': 'hiett/serverless-redis-http:latest',\n\trabbitmq: 'rabbitmq:4-management-alpine',\n\t// Pinned: 2.2.0 answers a KMS decrypt under the wrong encryption context\n\t// with UnknownError instead of InvalidCiphertextException.\n\tlocalstack: 'floci/floci:2.1.0',\n\t// The local edge: TLS with gkm's local CA, and host-based routing onto the\n\t// bucket behind it. Not a CDN — what is missing locally is the *mapping*\n\t// and the certificate, not caching, and a caching proxy would add an\n\t// invalidation story no local stack needs.\n\tcaddy: 'caddy:2-alpine',\n\t// Telemetry's collector and its UI — the image the compose stack runs.\n\topenobserve: OPENOBSERVE_IMAGE,\n};\n\n/** One port an image listens on. */\nexport interface ContainerPort {\n\t/**\n\t * The name this port is allocated and persisted under.\n\t *\n\t * Per port rather than per container so that adding a console port later\n\t * assigns a new one instead of shifting the port the app already connects to.\n\t */\n\tkey: string;\n\t/** The port inside the container, fixed by the image. */\n\tinside: number;\n\t/** What it is for, in the one line `gkm dev` and `gkm setup` print. */\n\tlabel: string;\n\t/** A page a person opens, so it prints as a link rather than an address. */\n\tweb?: true;\n}\n\n/**\n * The ports each container listens on.\n *\n * The first is always the one an app connects to; the rest are consoles and\n * management UIs, published because a bucket or an inbox you can look at is most\n * of why these are real containers rather than stubs.\n */\nconst PORTS: Readonly<Record<string, readonly ContainerPort[]>> = {\n\tpostgres: [{ key: 'postgres', inside: 5432, label: 'postgres' }],\n\tminio: [\n\t\t{ key: 'minio', inside: 9000, label: 'minio api' },\n\t\t{ key: 'minio-console', inside: 9001, label: 'minio console', web: true },\n\t],\n\tmailpit: [\n\t\t{ key: 'mailpit', inside: 1025, label: 'smtp' },\n\t\t{ key: 'mailpit-web', inside: 8025, label: 'mailpit inbox', web: true },\n\t],\n\tredis: [{ key: 'redis', inside: 6379, label: 'redis' }],\n\t'redis-http': [{ key: 'redis-http', inside: 80, label: 'cache' }],\n\trabbitmq: [\n\t\t{ key: 'rabbitmq', inside: 5672, label: 'amqp' },\n\t\t{\n\t\t\tkey: 'rabbitmq-management',\n\t\t\tinside: 15672,\n\t\t\tlabel: 'rabbitmq console',\n\t\t\tweb: true,\n\t\t},\n\t],\n\tlocalstack: [{ key: 'localstack', inside: 4566, label: 'localstack' }],\n\t// One port, and an assigned one rather than 443. The whole point of\n\t// allocation is that two projects run at once, and an edge that insists on\n\t// the privileged port puts that back — at the cost of a port in the URL,\n\t// which no cookie or CORS rule looks at.\n\tcaddy: [{ key: 'caddy', inside: 443, label: 'https edge' }],\n\t// OTLP ingest and the UI on one port.\n\topenobserve: [\n\t\t{ key: 'openobserve', inside: LOGS_PORT, label: 'openobserve', web: true },\n\t],\n};\n\n/**\n * An external API's fake, as the local target runs it.\n *\n * Keyed by its port key, `<id>-fake`, which is also its container's name when\n * it has one — so `primaryPortKey` finds its port with no table to consult.\n * A module fake has no image: gkm serves it, on the port this key is assigned.\n */\nexport interface PlannedFake {\n\t/** The external API it stands in for. */\n\tid: string;\n\t/** The image to run, for a fake the provider publishes. */\n\timage?: string;\n\t/** The port that image listens on inside the container. */\n\tport?: number;\n}\n\n/** The port key — and container name, for an image — of an API's fake. */\nexport function fakeKey(id: string): string {\n\treturn `${kebabCase(id)}-fake`;\n}\n\n/**\n * The ports a container needs published. Empty for one gkm does not know.\n *\n * `fakes` answers for the containers no table can: an external API's fake\n * listens wherever its declaration says.\n */\nexport function portsOf(\n\tcontainer: string,\n\tfakes: Readonly<Record<string, PlannedFake>> = {},\n): readonly ContainerPort[] {\n\tconst fake = fakes[container];\n\tif (fake?.port !== undefined) {\n\t\treturn [{ key: container, inside: fake.port, label: `${fake.id} fake` }];\n\t}\n\n\treturn PORTS[container] ?? [];\n}\n\n/** One published port, as a person reads it. */\nexport interface ServiceAddress {\n\tcontainer: string;\n\tlabel: string;\n\t/** `http://localhost:<port>` for a page, `localhost:<port>` otherwise. */\n\taddress: string;\n}\n\n/**\n * Every port the containers publish — not only the one an app connects to.\n *\n * The consoles and the inbox are most of why these are real containers, and an\n * inbox nobody can find is an inbox nobody opens: a sign-in link gets fished\n * out of `docker ps` instead.\n */\nexport function serviceAddresses(\n\tcontainers: readonly string[],\n\tports: Readonly<Record<string, number>>,\n\tfakes: Readonly<Record<string, PlannedFake>> = {},\n): ServiceAddress[] {\n\treturn containers.flatMap((container) =>\n\t\tportsOf(container, fakes).flatMap((port) => {\n\t\t\tconst assigned = ports[port.key];\n\t\t\tif (assigned === undefined) return [];\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tcontainer,\n\t\t\t\t\tlabel: port.label,\n\t\t\t\t\taddress: port.web\n\t\t\t\t\t\t? `http://localhost:${assigned}`\n\t\t\t\t\t\t: `localhost:${assigned}`,\n\t\t\t\t},\n\t\t\t];\n\t\t}),\n\t);\n}\n\n/** The lines `gkm dev` and `gkm setup` print under the services heading. */\nexport function describeServices(\n\tservices: readonly ServiceAddress[],\n): string[] {\n\tconst width = Math.max(0, ...services.map(({ label }) => label.length));\n\treturn services.map(\n\t\t({ label, address }) => ` ${label.padEnd(width)} ${address}`,\n\t);\n}\n\n/** The key a container's primary port is allocated under. */\nexport function primaryPortKey(container: string): string {\n\treturn portsOf(container)[0]?.key ?? container;\n}\n\n/**\n * Every port key a set of containers needs, in a stable order.\n *\n * What allocation is handed: it assigns ports to names and knows nothing about\n * what listens on them.\n */\nexport function portKeys(\n\tcontainers: readonly string[],\n\tfakes: Readonly<Record<string, PlannedFake>> = {},\n): string[] {\n\tconst keys = [...containers]\n\t\t.sort()\n\t\t.flatMap((container) => portsOf(container, fakes).map((port) => port.key));\n\n\t// A module fake runs in no container, and still needs a port to answer on.\n\treturn [...new Set([...keys, ...Object.keys(fakes).sort()])];\n}\n\n/**\n * The named volume a container's data lives in.\n *\n * Mailpit deliberately has none: local mail is disposable, and an inbox that\n * survives days of dev is noise rather than state.\n */\nexport function volumeOf(container: string): string | undefined {\n\tconst volumes: Readonly<Record<string, string>> = {\n\t\tpostgres: 'postgres-data',\n\t\tminio: 'minio-data',\n\t\tredis: 'redis-data',\n\t\trabbitmq: 'rabbitmq-data',\n\t\tlocalstack: 'localstack-data',\n\t\t// Holds the CA it generated. Losing it means a new root on every start,\n\t\t// and a trust store full of dead authorities.\n\t\tcaddy: 'caddy-data',\n\t\topenobserve: 'openobserve-data',\n\t};\n\n\treturn volumes[container];\n}\n","/**\n * The AWS emulator (floci, LocalStack-compatible) the `sns` backend runs on\n * locally — the facts the compose file, the env writer and the applier must\n * agree on.\n *\n * The emulator has one account and answers with deterministic ARNs and queue\n * URLs, which is what lets a connection string be composed before the topic\n * or queue it names has been created.\n */\n\n/** The emulator's single account. */\nexport const EMULATOR_ACCOUNT = '000000000000';\n\nexport const EMULATOR_REGION = 'us-east-1';\n\n/**\n * The emulator's access key id. The `LSIA` prefix is what LocalStack required\n * on issued keys, and LocalStack reads the account from the id — so it is\n * fixed, where the secret key beside it is generated per machine (see\n * `localCredentials.ts`). Floci does not care; keeping it means a project\n * that pins the old image still works.\n */\nexport const EMULATOR_ACCESS_KEY_ID = 'LSIAQAAAAAAVNCBMPNSG';\n\n/** The emulator's address from the host, on the port it was published on. */\nexport function emulatorEndpoint(port: number): string {\n\treturn `http://localhost:${port}`;\n}\n\nexport function emulatorTopicArn(name: string): string {\n\treturn `arn:aws:sns:${EMULATOR_REGION}:${EMULATOR_ACCOUNT}:${name}`;\n}\n\nexport function emulatorQueueUrl(name: string, port: number): string {\n\treturn `${emulatorEndpoint(port)}/${EMULATOR_ACCOUNT}/${name}`;\n}\n","/**\n * A bucket's object events, where the bucket is a local MinIO.\n *\n * S3 publishes a bucket's events to a topic the deploy creates; MinIO has no\n * topic to publish to, but it can post each event to a webhook. So where MinIO\n * holds a watched bucket, it posts the bucket's events to the process that\n * runs the bucket's subscribers, on a route only it can use, and that process\n * relays each one onto the events broker — under the bucket's name, as\n * `object.created` or `object.deleted` — where every subscriber drains a queue\n * of its own, as a topic's subscribers do.\n *\n * Declared to MinIO in two halves, both derived here so they cannot drift:\n *\n * - **a webhook target per bucket**, as container environment: where to post,\n * the token to present, and a queue on disk, because MinIO starts before the\n * process it posts to and must keep what it could not deliver;\n * - **the bucket's notification**, written through the S3 API once the bucket\n * exists: every created and removed object, to that target. Unfiltered —\n * two subscribers watching overlapping prefixes are two rules S3 refuses on\n * one bucket, and each subscriber filters what it is handed anyway.\n */\n\nimport { createHash } from 'node:crypto';\nimport { type ConstructManifest, provideKey } from '@geekmidas/manifest';\nimport type { BoundSubscriber } from './discover.js';\nimport type { BucketNotification } from './provision.js';\n\n/** Where MinIO posts one bucket's events. */\nexport interface ObjectWebhook {\n\t/** The bucket construct, `Uploads`. */\n\tbucket: string;\n\t/** The route on the process that runs the bucket's subscribers. */\n\tendpoint: string;\n\t/** What MinIO presents, and that process checks. */\n\ttoken: string;\n}\n\n/**\n * The token MinIO presents when it posts a bucket's events.\n *\n * Derived, never stored: the container and the process it posts to are handed\n * the same value by the same derivation — with the stage's random seed where a\n * deployed stage's stack has one, so the token is a secret there, and from the\n * project alone locally, where everything it would protect is on loopback.\n * Not salted by the stage: one MinIO serves `gkm dev` and `gkm test`, and a\n * target is declared once per container.\n */\nexport function objectsWebhookToken(\n\tproject: string,\n\tbucket: string,\n\tseed?: string,\n): string {\n\treturn createHash('sha256')\n\t\t.update(`${seed ? `${seed}:` : ''}${project}:objects-webhook:${bucket}`)\n\t\t.digest('base64url')\n\t\t.slice(0, 32);\n}\n\n/**\n * The target's id in MinIO's environment — `MINIO_NOTIFY_WEBHOOK_*_<ID>`.\n *\n * Upper-cased with nothing between words: a canonical id is letters and\n * digits, and an underscore inside the id would read as part of the setting's\n * name.\n */\nexport function minioTargetId(bucket: string): string {\n\treturn bucket.toUpperCase();\n}\n\n/** The target as a notification names it. */\nexport function minioTargetArn(bucket: string): string {\n\treturn `arn:minio:sqs::${minioTargetId(bucket)}:webhook`;\n}\n\n/** How a container reaches a process on the host. */\nexport const HOST_GATEWAY = 'host.docker.internal';\n\n/** Where MinIO keeps what it could not deliver yet, inside its container. */\nconst QUEUE_ROOT = '/gkm-object-events';\n\n/** The id of the notification rule gkm owns on a bucket. */\nexport const NOTIFICATION_RULE_PREFIX = 'gkm-';\n\n/**\n * MinIO's environment for each watched bucket's webhook target.\n *\n * Sorted, so the same buckets always render the same environment and a\n * reconcile that changed nothing does not recreate the container.\n */\nexport function minioWebhookEnv(\n\thooks: readonly ObjectWebhook[],\n): Record<string, string> {\n\tconst env: Record<string, string> = {};\n\tfor (const hook of [...hooks].sort((a, b) =>\n\t\ta.bucket.localeCompare(b.bucket),\n\t)) {\n\t\tconst id = minioTargetId(hook.bucket);\n\t\tenv[`MINIO_NOTIFY_WEBHOOK_ENABLE_${id}`] = 'on';\n\t\tenv[`MINIO_NOTIFY_WEBHOOK_ENDPOINT_${id}`] = hook.endpoint;\n\t\t// Sent as `Authorization: Bearer <token>`.\n\t\tenv[`MINIO_NOTIFY_WEBHOOK_AUTH_TOKEN_${id}`] = hook.token;\n\t\t// MinIO is up before whatever it posts to: what it cannot deliver is\n\t\t// kept here and sent once the route answers.\n\t\tenv[`MINIO_NOTIFY_WEBHOOK_QUEUE_DIR_${id}`] =\n\t\t\t`${QUEUE_ROOT}/${id.toLowerCase()}`;\n\t}\n\treturn env;\n}\n\n/** The rule that sends every created and removed object to the bucket's target. */\nexport function minioNotificationRule(\n\tbucket: string,\n): NonNullable<BucketNotification['QueueConfigurations']>[number] {\n\treturn {\n\t\tId: `${NOTIFICATION_RULE_PREFIX}${bucket}`,\n\t\tQueueArn: minioTargetArn(bucket),\n\t\tEvents: ['s3:ObjectCreated:*', 's3:ObjectRemoved:*'],\n\t};\n}\n\n/**\n * Each watched bucket, and the workers that run one of its subscribers.\n *\n * A bucket is watched when a subscriber reads its events key. MinIO posts a\n * bucket's events to one place, and the relay fans them out to every\n * subscriber whichever worker received them — so one worker per bucket is\n * enough, and the first, by id, is the one chosen, so the choice is stable.\n */\nexport function watchedBuckets(\n\tmanifest: ConstructManifest,\n\tsubscribers: Readonly<Record<string, readonly BoundSubscriber[]>>,\n): Map<string, string> {\n\tconst byKey = new Map<string, string>();\n\tfor (const declaration of Object.values(manifest)) {\n\t\tif (declaration.kind !== 'objects') continue;\n\t\tbyKey.set(\n\t\t\tprovideKey(declaration.id, 'eventsConnectionString'),\n\t\t\tdeclaration.id,\n\t\t);\n\t}\n\n\tconst watched = new Map<string, string>();\n\tfor (const worker of Object.keys(subscribers).sort()) {\n\t\tfor (const { connectionKey } of subscribers[worker] ?? []) {\n\t\t\tconst bucket = byKey.get(connectionKey);\n\t\t\tif (bucket && !watched.has(bucket)) watched.set(bucket, worker);\n\t\t}\n\t}\n\treturn watched;\n}\n","/**\n * The stack's Redis: what every declared cache lives in when a workspace runs\n * as a `gkm compose` stack, on the local stage and on a deployed one alike.\n *\n * A cache is the one store whose contents can always be rebuilt, so unlike\n * Mailpit and MinIO it is a production service, not a dev stand-in: it runs\n * for every stage, on the compose network only, with nothing published. It\n * is bounded (`maxmemory`, evicting the least recently used key), persisted\n * (an append-only file on a named volume, kept by `--down`) and password\n * protected — the stage's own password, generated once like its seed.\n *\n * A stage that sets a cache's URL in its secrets — a managed Redis — keeps\n * it, and a stack whose every cache is set that way runs no Redis at all.\n *\n * Pure: the stack decides it, and the phases keep the password.\n */\n\nimport { randomBytes } from 'node:crypto';\nimport { type ConstructManifest, provideKey } from '@geekmidas/manifest';\nimport { GkmError } from '../errors';\nimport { DEFAULT_IMAGES } from '../reconcile/containers.js';\nimport type { Plan } from '../reconcile/plan.js';\nimport type { StageSecrets } from '../secrets/types.js';\nimport type { CacheBackend } from '../types.js';\nimport type { StackService } from './stack.js';\n\n/**\n * Where a stack's caches live: its own Redis, whatever the deploy target's\n * default is. A stack is one machine running containers, and a Redis beside\n * the apps is cheaper for a cache than a table in the database they share.\n */\nexport const STACK_CACHE: CacheBackend = 'redis';\n\n/** Its compose service name — the host every cache URL points at. */\nexport const REDIS_SERVICE = 'redis';\n\n/** The port it answers on, inside the network. */\nexport const REDIS_PORT = 6379;\n\n/** Reconcile's pin, so `gkm dev` and the stack run one Redis. */\nexport const REDIS_IMAGE = DEFAULT_IMAGES.redis!;\n\n/**\n * How much it may hold before it evicts. A cache that grows until the box\n * runs out of memory takes the apps with it; 256 MB is a lot of sessions and\n * little of a small server. A project's `docker-compose.<stage>.yml` can\n * replace the command to change it.\n */\nexport const REDIS_MAXMEMORY = '256mb';\n\n/** The stage secret holding its password. */\nexport const REDIS_PASSWORD_KEY = 'REDIS_PASSWORD';\n\n/** Redis's own count of logical databases, before `--databases` raises it. */\nconst REDIS_DATABASES = 16;\n\n/** A deployed stage that runs the stack's Redis and has no password yet. */\nexport class RedisPasswordMissing extends GkmError {\n\tconstructor(readonly stage: string) {\n\t\tsuper(\n\t\t\t`The stage '${stage}' runs the stack's Redis and has no ` +\n\t\t\t\t`${REDIS_PASSWORD_KEY} in its secrets. Run gkm compose --stage ` +\n\t\t\t\t`${stage} without --dry-run once to generate it, or set one: ` +\n\t\t\t\t`gkm secrets:set ${REDIS_PASSWORD_KEY} '…' --stage ${stage}`,\n\t\t);\n\t\tthis.name = 'RedisPasswordMissing';\n\t}\n}\n\n/** The stack's Redis, as the stack runs it. */\nexport interface StackRedis {\n\tpassword: string;\n\t/** Whether the stage's secrets set the password, rather than the local one. */\n\tpasswordFromSecrets: boolean;\n\t/**\n\t * Each cache it holds — its URL key, and the URL — and each WebSocket\n\t * surface's publisher, whose sockets meet their senders on its pub/sub.\n\t */\n\turls: Record<string, string>;\n\t/** Its own environment, written to `redis.env` (0600). */\n\tenv: Record<string, string>;\n\t/** How many logical databases it keeps — one per cache, at least 16. */\n\tdatabases: number;\n}\n\n/**\n * Whether a stage's stack runs Redis: a cache or a WebSocket surface is\n * declared and the stage's secrets do not set the URL of every one.\n */\nexport function runsRedis(\n\tmanifest: ConstructManifest,\n\tcustom: Readonly<Record<string, string>>,\n): boolean {\n\treturn Object.values(manifest).some((declaration) => {\n\t\tif (declaration?.kind === 'cache') {\n\t\t\treturn (declaration.provides ?? []).some(\n\t\t\t\t(key) => custom[key] === undefined,\n\t\t\t);\n\t\t}\n\t\treturn (\n\t\t\tdeclaration?.kind === 'websocket-api' &&\n\t\t\tcustom[provideKey(declaration.id, 'publisherConnectionString')] ===\n\t\t\t\tundefined\n\t\t);\n\t});\n}\n\n/** A password: 256 random bits, URL-safe, so it sits in a URL unescaped. */\nexport function generateRedisPassword(): string {\n\treturn randomBytes(32).toString('base64url');\n}\n\n/**\n * The stage's secrets with a generated Redis password, where it has none.\n * Pure, like `withGeneratedSecrets`: the caller keeps the result once the run\n * goes ahead.\n */\nexport function withRedisPassword(secrets: StageSecrets): {\n\tsecrets: StageSecrets;\n\tgenerated: string[];\n} {\n\tif (secrets.custom?.[REDIS_PASSWORD_KEY]) return { secrets, generated: [] };\n\treturn {\n\t\tsecrets: {\n\t\t\t...secrets,\n\t\t\tcustom: {\n\t\t\t\t...secrets.custom,\n\t\t\t\t[REDIS_PASSWORD_KEY]: generateRedisPassword(),\n\t\t\t},\n\t\t\tupdatedAt: new Date().toISOString(),\n\t\t},\n\t\tgenerated: [REDIS_PASSWORD_KEY],\n\t};\n}\n\n/**\n * The stack's Redis for one stage, or nothing where no cache needs it.\n *\n * Each cache it holds gets a logical database of its own, by the order of\n * their ids, so two caches never read each other's keys.\n */\nexport function stackRedis(options: {\n\tplan: Plan;\n\tstage: string;\n\tlocal: boolean;\n\tcustom: Readonly<Record<string, string>>;\n\t/** The local stage's generated password — `gkm dev`'s Redis's too. */\n\tlocalPassword?: string;\n}): StackRedis | undefined {\n\tconst { plan, stage, local, custom } = options;\n\n\tconst caches = plan.resources\n\t\t.filter((r) => r.kind === 'cache' && custom[r.envKey] === undefined)\n\t\t.sort((a, b) => a.id.localeCompare(b.id));\n\tconst publishers = plan.resources\n\t\t.filter((r) => r.kind === 'websocket-api')\n\t\t.map((r) => provideKey(r.id, 'publisherConnectionString'))\n\t\t.filter((key) => custom[key] === undefined);\n\tif (caches.length === 0 && publishers.length === 0) return undefined;\n\n\tconst set = custom[REDIS_PASSWORD_KEY];\n\tconst password = set ?? (local ? options.localPassword : undefined);\n\tif (!password) throw new RedisPasswordMissing(stage);\n\tconst auth = encodeURIComponent(password);\n\n\treturn {\n\t\tpassword,\n\t\tpasswordFromSecrets: Boolean(set),\n\t\turls: Object.fromEntries([\n\t\t\t...caches.map((cache, index) => [\n\t\t\t\tcache.envKey,\n\t\t\t\t`redis://:${auth}@${REDIS_SERVICE}:${REDIS_PORT}/${index}`,\n\t\t\t]),\n\t\t\t// Pub/sub is not scoped by database, so no index: a surface's\n\t\t\t// channels are named for it.\n\t\t\t...publishers.map((key) => [\n\t\t\t\tkey,\n\t\t\t\t`redis://:${auth}@${REDIS_SERVICE}:${REDIS_PORT}`,\n\t\t\t]),\n\t\t]),\n\t\tenv: {\n\t\t\t// What the server is started with, by name: the command reads it\n\t\t\t// from the environment, so the value is never in its arguments.\n\t\t\t[REDIS_PASSWORD_KEY]: password,\n\t\t\t// What `redis-cli` signs in with — the health check's, and anyone's\n\t\t\t// who execs into the container — without `-a` on a command line.\n\t\t\tREDISCLI_AUTH: password,\n\t\t},\n\t\tdatabases: Math.max(REDIS_DATABASES, caches.length),\n\t};\n}\n\n/**\n * Redis's service: bounded, persisted and password protected, on the\n * network alone.\n *\n * The command runs the image's own entrypoint with `redis-server` first, so\n * it still drops to the `redis` user and owns `/data`; the password is read\n * from the env file by the shell (`$$` is compose's escape for `$`), so\n * neither the compose file nor the container's command holds it.\n */\nexport function redisService(redis: StackRedis): StackService {\n\tconst flags = [\n\t\t`--requirepass \"$$${REDIS_PASSWORD_KEY}\"`,\n\t\t`--maxmemory ${REDIS_MAXMEMORY}`,\n\t\t'--maxmemory-policy allkeys-lru',\n\t\t'--appendonly yes',\n\t\t...(redis.databases > REDIS_DATABASES\n\t\t\t? [`--databases ${redis.databases}`]\n\t\t\t: []),\n\t];\n\treturn {\n\t\timage: REDIS_IMAGE,\n\t\trestart: 'unless-stopped',\n\t\tcommand: [\n\t\t\t'sh',\n\t\t\t'-c',\n\t\t\t`exec docker-entrypoint.sh redis-server ${flags.join(' ')}`,\n\t\t],\n\t\tenv_file: [{ path: `./${REDIS_SERVICE}.env`, format: 'raw' }],\n\t\tvolumes: ['redis-data:/data'],\n\t\thealthcheck: {\n\t\t\t// `redis-cli` signs in with REDISCLI_AUTH; an unauthenticated ping\n\t\t\t// answers NOAUTH, which is not PONG.\n\t\t\ttest: ['CMD-SHELL', 'redis-cli ping | grep -q PONG'],\n\t\t\tinterval: '5s',\n\t\t\ttimeout: '3s',\n\t\t\tretries: 10,\n\t\t},\n\t};\n}\n","/**\n * The values a deployed stage generates once and keeps: what nothing can\n * provision and nobody else issues.\n *\n * - **A seed**, which salts every password a deploy derives — a database's\n * master and roles, a bucket's root user. Derived from repo facts alone\n * (project, stage, construct id), those passwords were computable by anyone\n * who could read the repo.\n * - **Each `secret` construct's value** — an auth server's signing secret, a\n * `RandomPassword` — random, rather than derived, in its declared format.\n * - **Each `encryption` construct's keyring** — one random key and an index\n * key. Later keys are added by `gkm encryption:rotate`, never by a deploy.\n *\n * Both are generated on the first deploy that needs them and written to the\n * stage's store, so every later deploy reads the same values: sessions survive\n * a redeploy, and a role's password does not move. A value set by hand with\n * `gkm secrets:set` is kept, never replaced.\n */\n\nimport { randomBytes, randomInt } from 'node:crypto';\nimport { generateKeyring } from '@geekmidas/constructs/encryption';\nimport { type ConstructManifest, drawSecret } from '@geekmidas/manifest';\nimport type { StageSecrets } from '../secrets/types.js';\n\nexport interface GeneratedSecrets {\n\t/** The stage's secrets with everything it generates present. */\n\tsecrets: StageSecrets;\n\t/** What was generated this time, by key — empty when nothing was missing. */\n\tgenerated: string[];\n}\n\n/**\n * The stage's secrets with its seed and every declared `secret`'s value\n * present, generating what is missing. Pure: the caller writes the result\n * back to the stage's store when `generated` is not empty.\n */\nexport function withGeneratedSecrets(\n\tsecrets: StageSecrets,\n\tmanifest: ConstructManifest,\n): GeneratedSecrets {\n\tconst generated: string[] = [];\n\tconst custom = { ...secrets.custom };\n\n\tfor (const declaration of Object.values(manifest)) {\n\t\tif (declaration?.kind !== 'secret' && declaration?.kind !== 'encryption') {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst key = declaration.provides?.[0];\n\t\tif (!key || custom[key]) continue;\n\n\t\tcustom[key] =\n\t\t\tdeclaration.kind === 'encryption'\n\t\t\t\t? generateKeyring()\n\t\t\t\t: drawSecret(randomInt, declaration);\n\t\tgenerated.push(key);\n\t}\n\n\tconst seed = secrets.seed ?? generateSeed();\n\tif (!secrets.seed) generated.push('seed');\n\n\treturn {\n\t\tsecrets: generated.length\n\t\t\t? { ...secrets, seed, custom, updatedAt: new Date().toISOString() }\n\t\t\t: secrets,\n\t\tgenerated,\n\t};\n}\n\n/** A stage's seed: 256 random bits, URL-safe. */\nexport function generateSeed(): string {\n\treturn random();\n}\n\n/** 256 bits, URL-safe. */\nfunction random(): string {\n\treturn randomBytes(32).toString('base64url');\n}\n","/**\n * The logins of the containers `gkm dev`, `gkm test` and the compose local\n * stage run — generated once per machine and workspace, and read back on\n * every later run.\n *\n * They used to be one fixed word, the same on every laptop, so anyone who\n * could reach a developer's Postgres could sign in to it. Now each password,\n * token and secret key is random, in the shape its service accepts, and the\n * user names are neutral ones derived from the workspace.\n *\n * **Where they are kept.** Encrypted with the local stage's key, in the CLI's\n * home beside the keys (`<home>/local/<namespace>/<project>.json`), rather\n * than in a checkout's `.gkm/`. The containers are per machine and project —\n * every checkout of a repo attaches to the same Postgres — so their logins\n * have to be too: two worktrees each generating their own would take turns\n * locking each other out of one database.\n *\n * **Why stored, not derived from a seed.** One cluster serves the local stage\n * and `test`, while a derivation is per stage; each service has its own rules\n * a hash does not meet by default; and a volume that cannot be rotated keeps\n * the login it has, which a derivation cannot express. The seed is generated\n * beside them all the same, and salts the per-role passwords the way a\n * deployed stage's does.\n */\n\nimport { randomBytes, randomInt } from 'node:crypto';\nimport { existsSync } from 'node:fs';\nimport { mkdir, readFile, rm, stat, writeFile } from 'node:fs/promises';\nimport { dirname, join } from 'node:path';\nimport { generateLogsPassword, LOCAL_LOGS_EMAIL } from '../compose/logs.js';\nimport { generateRedisPassword } from '../compose/redis.js';\nimport { generateSeed } from '../deploy/generated.js';\nimport { GkmError } from '../errors';\nimport { gkmHome } from '../home.js';\nimport {\n\tdecrypt,\n\ttype EncryptedSecretsFile,\n\tencrypt,\n} from '../secrets/file.js';\nimport {\n\tgetKeystoreDir,\n\tgetOrCreateKey,\n\ttype KeystoreProject,\n\tkeystoreProject,\n\treadKey,\n} from '../secrets/keystore.js';\nimport type { NormalizedWorkspace } from '../workspace/types.js';\nimport { EMULATOR_ACCESS_KEY_ID } from './emulator.js';\n\n/** A user name and its password. */\nexport interface Login {\n\tuser: string;\n\tpassword: string;\n}\n\n/**\n * What every container a plan implies is brought up with, and every URL\n * that reaches one carries.\n */\nexport interface ContainerCredentials {\n\t/** The cluster's superuser — what creates databases and roles. */\n\tpostgres: Login;\n\t/** MinIO's root user, which the S3 client signs with. */\n\tminio: Login;\n\t/** RabbitMQ's administrator. */\n\trabbitmq: Login;\n\t/** Redis's `requirepass`. */\n\tredis: { password: string };\n\t/** The token the cache's HTTP proxy accepts. */\n\tcacheToken: string;\n\t/** The AWS emulator's key pair. */\n\temulator: { accessKeyId: string; secretAccessKey: string };\n\t/**\n\t * OpenObserve's root user — `gkm dev`'s, where a process uses a\n\t * `Telemetry` construct, and `gkm compose`'s on the local stage.\n\t */\n\tlogs: { email: string; password: string };\n}\n\n/** The local stage's logins: the containers', and what else it generates. */\nexport interface LocalCredentials extends ContainerCredentials {\n\t/** Salts every per-role password, as a deployed stage's seed does. */\n\tseed: string;\n}\n\n/** MinIO refuses a root password shorter than 8 or longer than 40. */\nexport const MINIO_PASSWORD_LENGTH = 32;\n\n/** An AWS secret key is 40 characters. */\nexport const EMULATOR_SECRET_KEY_LENGTH = 40;\n\n/** MinIO's root user, the same for every workspace: it is not a secret. */\nexport const LOCAL_MINIO_USER = 'minio';\n\n/** RabbitMQ's administrator, the same way. */\nexport const LOCAL_RABBITMQ_USER = 'rabbitmq';\n\n/**\n * The Postgres superuser for a workspace: its name as an identifier, with\n * `_admin` — never the bare name, which a database construct of the same\n * name would claim as its runtime role.\n */\nexport function postgresSuperuser(project: string): string {\n\treturn `${postgresRoleSlug(project)}_admin`;\n}\n\n/**\n * The project as the start of a role's name: lowercase, `_` for anything\n * else, never starting with a digit — `gkm` when nothing is left.\n */\nexport function postgresRoleSlug(project: string): string {\n\tconst slug = project\n\t\t.toLowerCase()\n\t\t.replace(/^@[^/]+\\//, '')\n\t\t.replace(/[^a-z0-9]+/g, '_')\n\t\t.replace(/^_+|_+$/g, '')\n\t\t.replace(/^(\\d)/, '_$1');\n\treturn slug || 'gkm';\n}\n\n/** 256 random bits, URL-safe. */\nfunction token(): string {\n\treturn randomBytes(32).toString('base64url');\n}\n\n/** `length` characters of letters and digits, which every client takes as is. */\nfunction alphanumeric(length: number): string {\n\tconst alphabet =\n\t\t'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';\n\tlet out = '';\n\tfor (let i = 0; i < length; i++) out += alphabet[randomInt(alphabet.length)];\n\treturn out;\n}\n\n/** A fresh set of local logins for a workspace. */\nexport function generateLocalCredentials(project: string): LocalCredentials {\n\treturn {\n\t\tseed: generateSeed(),\n\t\tpostgres: { user: postgresSuperuser(project), password: token() },\n\t\tminio: {\n\t\t\tuser: LOCAL_MINIO_USER,\n\t\t\tpassword: alphanumeric(MINIO_PASSWORD_LENGTH),\n\t\t},\n\t\trabbitmq: { user: LOCAL_RABBITMQ_USER, password: token() },\n\t\tredis: { password: generateRedisPassword() },\n\t\tcacheToken: token(),\n\t\temulator: {\n\t\t\t// Fixed: the emulator reads its account from the key id, and every\n\t\t\t// ARN reconcile composes names that account. Only the secret is one.\n\t\t\taccessKeyId: EMULATOR_ACCESS_KEY_ID,\n\t\t\tsecretAccessKey: alphanumeric(EMULATOR_SECRET_KEY_LENGTH),\n\t\t},\n\t\tlogs: { email: LOCAL_LOGS_EMAIL, password: generateLogsPassword() },\n\t};\n}\n\n/**\n * The stored logins with anything missing generated — a file an older gkm\n * wrote before a service existed. Pure: the caller writes the result back\n * when `generated` is not empty.\n */\nexport function withLocalCredentials(\n\tstored: Partial<LocalCredentials> | null | undefined,\n\tproject: string,\n): { credentials: LocalCredentials; generated: string[] } {\n\tconst fresh = generateLocalCredentials(project);\n\tconst generated = (Object.keys(fresh) as (keyof LocalCredentials)[]).filter(\n\t\t(key) => stored?.[key] === undefined,\n\t);\n\treturn {\n\t\tcredentials: { ...fresh, ...stored } as LocalCredentials,\n\t\tgenerated,\n\t};\n}\n\n/** Where a workspace's local logins are kept on this machine. */\nexport function localCredentialsPath(project: KeystoreProject): string {\n\t// Validates the key and splits it the way the keystore does.\n\tconst keys = getKeystoreDir(project);\n\tconst name = keys.split(/[\\\\/]/).at(-1)!;\n\tconst namespace = keys.split(/[\\\\/]/).at(-2)!;\n\treturn join(project.home ?? gkmHome(), 'local', namespace, `${name}.json`);\n}\n\n/** The local stage's logins file is there, and its key is not. */\nexport class LocalCredentialsKeyMissing extends GkmError {\n\tconstructor(\n\t\treadonly path: string,\n\t\treadonly stage: string,\n\t) {\n\t\tsuper(\n\t\t\t`The local logins at ${path} are encrypted with the '${stage}' stage's ` +\n\t\t\t\t\"key, and this machine has none. Remove the file to generate new ones — the containers' volumes are rotated to them on the next gkm dev.\",\n\t\t);\n\t\tthis.name = 'LocalCredentialsKeyMissing';\n\t}\n}\n\n/** Another gkm held the logins file's lock for longer than any write takes. */\nexport class LocalCredentialsLocked extends GkmError {\n\tconstructor(readonly lock: string) {\n\t\tsuper(\n\t\t\t`Another gkm has been writing the local logins for over ${LOCK_TIMEOUT_MS / 1000}s. If none is running, remove ${lock} and run the command again.`,\n\t\t);\n\t\tthis.name = 'LocalCredentialsLocked';\n\t}\n}\n\n/** Read the stored logins, or `null` where none were generated yet. */\nexport async function readLocalCredentials(\n\tworkspace: Pick<NormalizedWorkspace, 'name' | 'root' | 'stages'> &\n\t\tParameters<typeof keystoreProject>[0],\n\thome?: string,\n): Promise<LocalCredentials | null> {\n\tconst project = keystoreProject(workspace, home);\n\tconst path = localCredentialsPath(project);\n\tif (!existsSync(path)) return null;\n\n\tconst stage = workspace.stages.local;\n\tconst key = await readKey(stage, project);\n\tif (!key) throw new LocalCredentialsKeyMissing(path, stage);\n\tconst file = JSON.parse(\n\t\tawait readFile(path, 'utf-8'),\n\t) as EncryptedSecretsFile;\n\treturn decrypt<LocalCredentials>(file, key);\n}\n\n/** Write the logins, encrypted with the local stage's key, owner-only. */\nexport async function saveLocalCredentials(\n\tworkspace: Parameters<typeof readLocalCredentials>[0],\n\tcredentials: LocalCredentials,\n\thome?: string,\n): Promise<void> {\n\tconst project = keystoreProject(workspace, home);\n\tconst path = localCredentialsPath(project);\n\tconst key = await getOrCreateKey(workspace.stages.local, project);\n\tawait mkdir(dirname(path), { recursive: true, mode: 0o700 });\n\tawait writeFile(path, JSON.stringify(encrypt(credentials, key), null, 2), {\n\t\tmode: 0o600,\n\t});\n}\n\n/**\n * The workspace's local logins: read back, or generated and kept the first\n * time anything needs them.\n *\n * Under a lock, because a workspace's `gkm dev` starts one per app and the\n * first run of each would otherwise generate — and keep — its own.\n */\nexport async function loadLocalCredentials(\n\tworkspace: Parameters<typeof readLocalCredentials>[0],\n\thome?: string,\n): Promise<{ credentials: LocalCredentials; generated: string[] }> {\n\tconst path = localCredentialsPath(keystoreProject(workspace, home));\n\treturn withLock(`${path}.lock`, async () => {\n\t\tconst stored = await readLocalCredentials(workspace, home);\n\t\tconst result = withLocalCredentials(stored, workspace.name);\n\t\tif (result.generated.length > 0) {\n\t\t\tawait saveLocalCredentials(workspace, result.credentials, home);\n\t\t}\n\t\treturn result;\n\t});\n}\n\n/** How long a lock may be held before it is someone else's problem. */\nconst LOCK_TIMEOUT_MS = 15_000;\n\nasync function withLock<T>(lock: string, body: () => Promise<T>): Promise<T> {\n\tawait mkdir(dirname(lock), { recursive: true, mode: 0o700 });\n\tconst started = Date.now();\n\tfor (;;) {\n\t\ttry {\n\t\t\tawait mkdir(lock);\n\t\t\tbreak;\n\t\t} catch (error) {\n\t\t\tif ((error as NodeJS.ErrnoException).code !== 'EEXIST') throw error;\n\t\t\t// A lock older than any write is left over from a process that died\n\t\t\t// holding it.\n\t\t\tconst age = await stat(lock)\n\t\t\t\t.then((s) => Date.now() - s.mtimeMs)\n\t\t\t\t.catch(() => 0);\n\t\t\tif (age > LOCK_TIMEOUT_MS) {\n\t\t\t\tawait rm(lock, { recursive: true, force: true });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (Date.now() - started > LOCK_TIMEOUT_MS) {\n\t\t\t\tthrow new LocalCredentialsLocked(lock);\n\t\t\t}\n\t\t\tawait new Promise((resolve) => setTimeout(resolve, 50));\n\t\t}\n\t}\n\ttry {\n\t\treturn await body();\n\t} finally {\n\t\tawait rm(lock, { recursive: true, force: true });\n\t}\n}\n","import { existsSync } from 'node:fs';\nimport { mkdir, readFile, writeFile } from 'node:fs/promises';\nimport { createServer } from 'node:net';\nimport { dirname, join, resolve } from 'node:path';\nimport { config as dotenvConfig } from 'dotenv';\nimport {\n\tConfigNotFound,\n\tloadWorkspaceAppInfo,\n\tloadWorkspaceConfig,\n\tNotInAnApp,\n\ttype WorkspaceAppInfo,\n} from '../config';\nimport type { ReconcileResult } from '../reconcile/index.js';\nimport { toEmbeddableSecrets } from '../secrets/storage.js';\nimport {\n\tFileSecretsStore,\n\ttype SecretsStore,\n\tsecretsStoreFor,\n} from '../secrets/store.js';\nimport type { NormalizedWorkspace } from '../workspace/index.js';\n\nconst logger = console;\n\n// ---------------------------------------------------------------------------\n// Environment files\n// ---------------------------------------------------------------------------\n\n/**\n * Load environment files\n * @internal Exported for testing\n */\nexport function loadEnvFiles(\n\tenvConfig: string | string[] | undefined,\n\tcwd: string = process.cwd(),\n): { loaded: string[]; missing: string[] } {\n\tconst loaded: string[] = [];\n\tconst missing: string[] = [];\n\n\t// Normalize to array\n\tconst envFiles = envConfig\n\t\t? Array.isArray(envConfig)\n\t\t\t? envConfig\n\t\t\t: [envConfig]\n\t\t: ['.env'];\n\n\t// Load each env file in order (later files override earlier)\n\tfor (const envFile of envFiles) {\n\t\tconst envPath = resolve(cwd, envFile);\n\t\tif (existsSync(envPath)) {\n\t\t\tdotenvConfig({ path: envPath, override: true, quiet: true });\n\t\t\tloaded.push(envFile);\n\t\t} else if (envConfig) {\n\t\t\t// Only report as missing if explicitly configured\n\t\t\tmissing.push(envFile);\n\t\t}\n\t}\n\n\treturn { loaded, missing };\n}\n\n// ---------------------------------------------------------------------------\n// Port utilities\n// ---------------------------------------------------------------------------\n\n/**\n * Check if a port is available\n * @internal Exported for testing\n */\nexport async function isPortAvailable(port: number): Promise<boolean> {\n\treturn new Promise((resolve) => {\n\t\tconst server = createServer();\n\n\t\tserver.once('error', (err: NodeJS.ErrnoException) => {\n\t\t\tif (err.code === 'EADDRINUSE') {\n\t\t\t\tresolve(false);\n\t\t\t} else {\n\t\t\t\tresolve(false);\n\t\t\t}\n\t\t});\n\n\t\tserver.once('listening', () => {\n\t\t\tserver.close();\n\t\t\tresolve(true);\n\t\t});\n\n\t\tserver.listen(port);\n\t});\n}\n\n/**\n * Find an available port starting from the preferred port\n * @internal Exported for testing\n */\nexport async function findAvailablePort(\n\tpreferredPort: number,\n\tmaxAttempts = 10,\n): Promise<number> {\n\tfor (let i = 0; i < maxAttempts; i++) {\n\t\tconst port = preferredPort + i;\n\t\tif (await isPortAvailable(port)) {\n\t\t\treturn port;\n\t\t}\n\t\tlogger.log(`⚠️ Port ${port} is in use, trying ${port + 1}...`);\n\t}\n\n\tthrow new Error(\n\t\t`Could not find an available port after trying ${maxAttempts} ports starting from ${preferredPort}`,\n\t);\n}\n\n// ---------------------------------------------------------------------------\n// Docker Compose port mapping\n// ---------------------------------------------------------------------------\n\n/** Port state persisted to .gkm/ports.json, keyed by env var name. */\nexport type PortState = Record<string, number>;\n\nconst PORT_STATE_PATH = '.gkm/ports.json';\n\n/**\n * Load saved port state from .gkm/ports.json.\n * @internal Exported for testing\n */\nexport async function loadPortState(workspaceRoot: string): Promise<PortState> {\n\ttry {\n\t\tconst raw = await readFile(join(workspaceRoot, PORT_STATE_PATH), 'utf-8');\n\t\treturn JSON.parse(raw) as PortState;\n\t} catch {\n\t\treturn {};\n\t}\n}\n\n/**\n * Save port state to .gkm/ports.json.\n * @internal Exported for testing\n */\nexport async function savePortState(\n\tworkspaceRoot: string,\n\tports: PortState,\n): Promise<void> {\n\tconst dir = join(workspaceRoot, '.gkm');\n\tawait mkdir(dir, { recursive: true });\n\tawait writeFile(\n\t\tjoin(workspaceRoot, PORT_STATE_PATH),\n\t\t`${JSON.stringify(ports, null, 2)}\\n`,\n\t);\n}\n\n// ---------------------------------------------------------------------------\n// URL rewriting\n// ---------------------------------------------------------------------------\n\n// ---------------------------------------------------------------------------\n// Docker Compose services\n// ---------------------------------------------------------------------------\n\n// ---------------------------------------------------------------------------\n// Secrets loading\n// ---------------------------------------------------------------------------\n\n/**\n * Load and flatten a stage's secrets from its store.\n *\n * Every key as stored — nothing renamed. An app's database URL is its\n * construct's key, derived by reconcile, and never a stored per-app value\n * mapped onto `DATABASE_URL`.\n * @internal Exported for testing\n */\nexport async function loadSecretsForApp(\n\tstore: SecretsStore,\n\tstage: string,\n): Promise<Record<string, string>> {\n\tconst stageSecrets = await store.read(stage);\n\tif (!stageSecrets) return {};\n\n\tlogger.log(`🔐 Loading secrets from stage: ${stage}`);\n\treturn toEmbeddableSecrets(stageSecrets);\n}\n\n/**\n * Walk up the directory tree to find the root containing .gkm/secrets/.\n * @internal Exported for testing\n */\nexport function findSecretsRoot(startDir: string): string {\n\tlet dir = startDir;\n\twhile (dir !== '/') {\n\t\tif (existsSync(join(dir, '.gkm', 'secrets'))) {\n\t\t\treturn dir;\n\t\t}\n\t\tconst parent = dirname(dir);\n\t\tif (parent === dir) break;\n\t\tdir = parent;\n\t}\n\treturn startDir;\n}\n\n// ---------------------------------------------------------------------------\n// Credentials preload / injection\n// ---------------------------------------------------------------------------\n\n/**\n * Generate the credentials injection code snippet.\n * This is the common logic used by both entry wrapper and exec preload.\n * @internal\n */\nfunction generateCredentialsInjection(secretsJsonPath: string): string {\n\treturn `import { existsSync, readFileSync } from 'node:fs';\n\n// Inject dev secrets via globalThis and process.env\n// Using globalThis.__gkm_credentials__ avoids CJS/ESM interop issues where\n// Object.assign on the Credentials export only mutates one module copy.\nconst secretsPath = '${secretsJsonPath}';\nif (existsSync(secretsPath)) {\n const secrets = JSON.parse(readFileSync(secretsPath, 'utf-8'));\n globalThis.__gkm_credentials__ = secrets;\n Object.assign(process.env, secrets);\n}\n`;\n}\n\n/**\n * Create a preload script that injects secrets into Credentials.\n * Used by `gkm exec` to inject secrets before running any command.\n * @internal Exported for testing\n */\nexport async function createCredentialsPreload(\n\tpreloadPath: string,\n\tsecretsJsonPath: string,\n): Promise<void> {\n\tconst content = `/**\n * Credentials preload generated by 'gkm exec'\n * This file is loaded via NODE_OPTIONS=\"--import <path>\"\n */\n${generateCredentialsInjection(secretsJsonPath)}`;\n\n\tawait writeFile(preloadPath, content);\n}\n\n/**\n * Create a wrapper script that injects secrets before importing the entry file.\n * @internal Exported for testing\n */\nexport async function createEntryWrapper(\n\twrapperPath: string,\n\tentryPath: string,\n\tsecretsJsonPath?: string,\n): Promise<void> {\n\tconst credentialsInjection = secretsJsonPath\n\t\t? `${generateCredentialsInjection(secretsJsonPath)}\n`\n\t\t: '';\n\n\t// Use dynamic import() to ensure secrets are assigned before the entry file loads\n\t// Static imports are hoisted, so Object.assign would run after the entry file is loaded\n\tconst content = `#!/usr/bin/env node\n/**\n * Entry wrapper generated by 'gkm dev --entry'\n */\n${credentialsInjection}// Import and run the user's entry file (dynamic import ensures secrets load first)\nawait import('${entryPath}');\n`;\n\n\tawait writeFile(wrapperPath, content);\n}\n\n// ---------------------------------------------------------------------------\n// Prepare credentials (shared by dev, exec, test)\n// ---------------------------------------------------------------------------\n\n/**\n * Result of preparing credentials.\n */\nexport interface EntryCredentialsResult {\n\t/** Credentials to inject (secrets + PORT) */\n\tcredentials: Record<string, string>;\n\t/** Resolved port (from --port, workspace config, or default 3000) */\n\tresolvedPort: number;\n\t/** Path where credentials JSON was written */\n\tsecretsJsonPath: string;\n\t/** Resolved app name (if in workspace) */\n\tappName: string | undefined;\n\t/** Secrets root directory */\n\tsecretsRoot: string;\n\t/** Workspace app info (if in a workspace) */\n\tappInfo?: WorkspaceAppInfo;\n\t/**\n\t * The keys the manifest declared, as opposed to those a secret store held.\n\t *\n\t * Kept apart because they cannot be *sniffed*. A construct reads its own key\n\t * inside `@geekmidas/constructs`, not in application code, so a walk of the\n\t * app finds no `get('MAIL_URL')` to find — and a caller that filters the\n\t * environment down to what it sniffed would drop every URL the target just\n\t * resolved. `gkm test` did exactly that.\n\t */\n\tdeclaredKeys: string[];\n\t/** The reconcile just run, in a workspace: its plan and its ports. */\n\treconciled?: ReconcileResult;\n}\n\n/**\n * Prepare credentials for dev/exec/test modes.\n * Loads workspace config, secrets, resolves Docker ports, rewrites URLs,\n * injects PORT, dependency URLs, and writes credentials JSON.\n *\n * @param options.stage - The stage whose secrets to load. Default: the project's `stages.local`.\n * @param options.startDocker - Start Docker Compose services after port resolution. Default: false.\n * @param options.secretsFileName - Custom secrets JSON filename. Default: 'dev-secrets-{appName}.json' or 'dev-secrets.json'.\n * @internal Exported for testing\n */\nexport async function prepareEntryCredentials(options: {\n\texplicitPort?: number;\n\tcwd?: string;\n\t/** The stage whose secrets to load. Default: the project's `stages.local` */\n\tstage?: string;\n\t/** Start Docker Compose services after port resolution. Default: false */\n\tstartDocker?: boolean;\n\t/** Custom secrets JSON filename. Default: 'dev-secrets-{appName}.json' or 'dev-secrets.json' */\n\tsecretsFileName?: string;\n\t/**\n\t * The stage to reconcile the local target for.\n\t *\n\t * `gkm test` passes `test` and gets the same containers with suffixed\n\t * resources; left out, it is the project's local stage and they are\n\t * unsuffixed. Only read by workspaces that have adopted the constructs glob.\n\t */\n\treconcileStage?: string;\n\t/**\n\t * Hand an app only what its own process reads (`processEnv`) — its\n\t * edges' keys and the stage's own — as `gkm dev` and `gkm compose` do.\n\t * `gkm exec` asks; `gkm test` does not, since a feature test runs every\n\t * process's code in one.\n\t */\n\tscoped?: boolean;\n}): Promise<EntryCredentialsResult> {\n\tconst cwd = options.cwd ?? process.cwd();\n\n\t// Try to get workspace app config for port and secrets\n\tlet workspaceAppPort: number | undefined;\n\tlet secretsRoot: string = cwd;\n\tlet appName: string | undefined;\n\tlet appInfo: WorkspaceAppInfo | undefined;\n\n\tlet workspace: NormalizedWorkspace | undefined;\n\n\ttry {\n\t\tappInfo = await loadWorkspaceAppInfo(cwd);\n\t\tworkspace = appInfo.workspace;\n\t\tworkspaceAppPort = appInfo.app.port;\n\t\tsecretsRoot = appInfo.workspaceRoot;\n\t\tappName = appInfo.appName;\n\t} catch (error) {\n\t\t// Anything but \"not in an app\" or \"not in a workspace\" is a real fault —\n\t\t// a config that does not load — and must not be mistaken for either.\n\t\tif (!(error instanceof NotInAnApp || error instanceof ConfigNotFound)) {\n\t\t\tthrow error;\n\t\t}\n\t\t// Not an app — but possibly the workspace root, which is where the\n\t\t// scaffold's own `pnpm test` runs `gkm test` from. Without the workspace\n\t\t// here that run skipped the reconcile below: no container started, and the\n\t\t// URLs were whatever the stored secrets said, on ports nothing listened on.\n\t\tworkspace = await loadWorkspaceConfig(cwd)\n\t\t\t.then((loaded) => loaded.workspace)\n\t\t\t.catch(() => undefined);\n\t\t// Otherwise not in a workspace at all (expected for non-gkm apps using\n\t\t// gkm exec) — use defaults.\n\t\t// No app here, so no per-app keys to map.\n\t\tsecretsRoot = workspace?.root ?? findSecretsRoot(cwd);\n\t}\n\n\t// The app's local port, by the rule `gkm dev` applies: moved off a port\n\t// another project holds, and kept. Never refused here — the command may be\n\t// a build or a script that binds nothing, so this app's own dev server\n\t// holding the port is no reason to stop it.\n\tif (appName && workspace && options.explicitPort === undefined) {\n\t\tconst { assignAppPorts, describeMove, holderOf, withAppPorts } =\n\t\t\tawait import('../dev/appPorts.js');\n\t\tconst assigned = await assignAppPorts(workspace, [appName], {\n\t\t\tfree: isPortAvailable,\n\t\t\tholder: holderOf,\n\t\t});\n\t\tfor (const move of assigned.moved) logger.log(describeMove(move));\n\t\tworkspace = withAppPorts(workspace, assigned.ports);\n\t\tworkspaceAppPort = assigned.ports[appName] ?? workspaceAppPort;\n\t}\n\n\t// Tagged, so a later `gkm dev` can tell what this starts from another\n\t// project's process on the same port; the command inherits it.\n\tif (appName) {\n\t\tconst { APP_TAG_ENV, appTag } = await import('../dev/appPorts.js');\n\t\tprocess.env[APP_TAG_ENV] = appTag(secretsRoot, appName);\n\t}\n\n\t// Determine port: explicit --port > the app's local port > default 3000\n\tconst resolvedPort = options.explicitPort ?? workspaceAppPort ?? 3000;\n\n\t// Load secrets and inject PORT. Outside a workspace there are no declared\n\t// stages to read, so only a stage asked for by name is loaded.\n\tconst stage = options.stage ?? workspace?.stages.local;\n\t// The stage's own store; outside a workspace nothing names one but the file.\n\tconst store = stage\n\t\t? workspace\n\t\t\t? await secretsStoreFor(workspace, stage)\n\t\t\t: new FileSecretsStore(secretsRoot)\n\t\t: undefined;\n\tconst credentials =\n\t\tstore && stage ? await loadSecretsForApp(store, stage) : {};\n\n\t// Always inject PORT into credentials so apps can read it\n\tcredentials.PORT = String(resolvedPort);\n\t// Expo reads its Metro port from here when `expo start` is given none, so\n\t// a mobile app runs where the workspace placed it — and where the `exp://`\n\t// origins its auth server trusts say it is.\n\tif (appInfo?.app.type === 'mobile') {\n\t\tcredentials.RCT_METRO_PORT = String(resolvedPort);\n\t}\n\n\tconst declaredKeys: string[] = [];\n\tlet reconciled: ReconcileResult | undefined;\n\n\t// Every address — containers, the edge, each app — comes from what the\n\t// workspace declares. Outside a workspace (a non-gkm app using `gkm exec`)\n\t// there is nothing to resolve, only the secrets above.\n\tif (workspace) {\n\t\tconst { reconcileWorkspace } = await import('../reconcile/workspace.js');\n\t\tconst result = await reconcileWorkspace(workspace, {\n\t\t\tstage: options.reconcileStage ?? workspace.stages.local,\n\t\t\tstart: options.startDocker ?? false,\n\t\t});\n\t\treconciled = result;\n\n\t\t// Declared URLs win over anything stored: the manifest is the statement\n\t\t// of what exists, and a stale secret naming an old port is exactly the\n\t\t// drift this replaces.\n\t\tif (options.scoped && appName) {\n\t\t\tconst { appProcess, processEnv } = await import('../reconcile/apps.js');\n\t\t\tconst own = processEnv(\n\t\t\t\tresult.manifest,\n\t\t\t\tappProcess(workspace, result.manifest, result.background, appName),\n\t\t\t\t{ ...credentials },\n\t\t\t\tresult.env,\n\t\t\t);\n\t\t\tfor (const key of Object.keys(credentials)) delete credentials[key];\n\t\t\tObject.assign(credentials, own);\n\t\t} else {\n\t\t\tObject.assign(credentials, reconciled.env);\n\t\t}\n\t\tdeclaredKeys.push(\n\t\t\t...Object.keys(reconciled.env).filter((key) => key in credentials),\n\t\t);\n\n\t\tif (Object.keys(reconciled.env).length > 0) {\n\t\t\tlogger.log(\n\t\t\t\t`🔌 Resolved ${Object.keys(reconciled.env).length} declared URL(s)`,\n\t\t\t);\n\t\t}\n\t}\n\n\t// Write secrets to temp JSON file (always write since we have PORT)\n\t// Use app-specific filename to avoid race conditions when running multiple apps via turbo\n\tconst secretsDir = join(secretsRoot, '.gkm');\n\tawait mkdir(secretsDir, { recursive: true });\n\tconst secretsFileName =\n\t\toptions.secretsFileName ??\n\t\t(appName ? `dev-secrets-${appName}.json` : 'dev-secrets.json');\n\tconst secretsJsonPath = join(secretsDir, secretsFileName);\n\tawait writeFile(secretsJsonPath, JSON.stringify(credentials, null, 2));\n\n\treturn {\n\t\tcredentials,\n\t\tresolvedPort,\n\t\tsecretsJsonPath,\n\t\tappName,\n\t\tsecretsRoot,\n\t\tappInfo,\n\t\tdeclaredKeys,\n\t\t...(reconciled ? { reconciled } : {}),\n\t};\n}\n","/**\n * The compose document a plan implies.\n *\n * The third declaration of the same containers disappears here: today a\n * `services: ['postgres','minio']` block is kept in step with the code by hand,\n * which is the triplication this design exists to remove, in the one place you\n * touch every day. A `database` implies Postgres; the list is derived.\n *\n * Returns an object rather than a string for the same reason `plan` is pure —\n * what should exist is asserted as data, and turning it into YAML is one line at\n * the edge.\n *\n * What stays config is unchanged: images and versions are pinned explicitly, and\n * a container no construct implies is still declared by hand. Neutral facts come\n * from the declaration, provider detail from config.\n */\n\nimport { stringify } from 'yaml';\nimport { LOGS_EMAIL_KEY, LOGS_PASSWORD_KEY } from '../compose/logs.js';\nimport { LOGS_RETENTION_DAYS } from '../compose/logsConfig.js';\nimport { DEFAULT_IMAGES, portsOf, postgresImage, volumeOf } from './containers';\nimport { EMULATOR_REGION } from './emulator';\nimport type { ContainerCredentials } from './localCredentials';\nimport {\n\tHOST_GATEWAY,\n\tminioWebhookEnv,\n\ttype ObjectWebhook,\n} from './objectEvents';\nimport type { Plan } from './plan';\nimport type { PortAssignments } from './ports';\n\n/** A compose service definition — as much of the schema as is emitted here. */\nexport interface ComposeService {\n\timage: string;\n\t/** An app is built from its generated Dockerfile; a container is pulled. */\n\tbuild?: {\n\t\tcontext: string;\n\t\tdockerfile: string;\n\t\t/** A site's public URLs, which its bundler inlines at build time. */\n\t\targs?: Record<string, string>;\n\t};\n\t/** Behind a profile, so starting the containers does not start the apps. */\n\tprofiles?: string[];\n\trestart?: string;\n\tentrypoint?: string;\n\tcommand?: string;\n\tports?: string[];\n\tenvironment?: Record<string, string>;\n\tvolumes?: string[];\n\tdepends_on?: string[];\n\thealthcheck?: {\n\t\ttest: string[];\n\t\tinterval: string;\n\t\ttimeout: string;\n\t\tretries: number;\n\t\tstart_period?: string;\n\t};\n\textra_hosts?: string[];\n}\n\nexport interface ComposeFile {\n\tname: string;\n\tservices: Record<string, ComposeService>;\n\tvolumes?: Record<string, Record<string, never>>;\n}\n\n/** The database every connection opens first: every cluster has it. */\nexport const CLUSTER_DATABASE = 'postgres';\n\nexport interface ComposeOptions {\n\t/** Names the compose project, which is what isolates it from other stacks. */\n\tproject: string;\n\t/** Ports assigned by `allocate`, keyed by port key — see `portKeys`. */\n\tports: PortAssignments;\n\t/** App services to write beside the containers — see `reconcile/apps.ts`. */\n\tapps?: Readonly<Record<string, ComposeService>>;\n\t/**\n\t * What each container is brought up with: the workspace's generated local\n\t * logins — see `localCredentials.ts` — or a stack's derived ones.\n\t */\n\tcredentials: ContainerCredentials;\n\t/**\n\t * Where MinIO posts each watched bucket's events — see `objectEvents.ts`.\n\t * Declared as MinIO's environment, so a change recreates the container.\n\t */\n\tobjectWebhooks?: readonly ObjectWebhook[];\n\t/**\n\t * Where Mailpit posts each message it receives, when an inbox is declared:\n\t * `gkm dev`'s relay, on the host. Mailpit's environment, so a change\n\t * recreates the container.\n\t */\n\tinboxRelay?: string;\n}\n\n/**\n * Build the compose document for a plan.\n *\n * Every container is published on its assigned port, never on the image's\n * default: the point of allocation is that two projects can run at once, and\n * one container publishing 5432 puts that back.\n */\nexport function composeFor(plan: Plan, options: ComposeOptions): ComposeFile {\n\tconst services: Record<string, ComposeService> = {};\n\tconst volumes: Record<string, Record<string, never>> = {};\n\n\tfor (const container of [...plan.containers].sort()) {\n\t\t// A declared version beats the default image, so the container a\n\t\t// developer runs is the major the declaration names — and the same one a\n\t\t// deploy provisions. An image pin is the project's own\n\t\t// `docker-compose.yml`, merged over this file, and wins over both.\n\t\t//\n\t\t// A database can name its own image (PostGIS, pgvector). The local\n\t\t// cluster is shared, so that image runs every database in it — and two\n\t\t// databases naming different ones cannot both have theirs.\n\t\tconst declared =\n\t\t\tcontainer === 'postgres'\n\t\t\t\t? plan.resources.find((r) => r.version)?.version\n\t\t\t\t: undefined;\n\t\tconst named =\n\t\t\tcontainer === 'postgres' ? declaredPostgresImage(plan) : undefined;\n\n\t\tconst fake = plan.fakes?.[container];\n\t\tconst image =\n\t\t\tnamed ??\n\t\t\t(declared\n\t\t\t\t? postgresImage(declared)\n\t\t\t\t: (fake?.image ?? DEFAULT_IMAGES[container]));\n\t\tif (!image) throw new UnknownContainer(container);\n\n\t\tconst published = publish(container, options.ports, plan.fakes);\n\t\tservices[container] = fake\n\t\t\t? // An external API's fake: the provider's image, as it ships. It has\n\t\t\t\t// no volume — a fake keeps nothing worth keeping — and no\n\t\t\t\t// healthcheck, so running is what ready means.\n\t\t\t\t{ image, restart: 'unless-stopped', ports: published }\n\t\t\t: define(container, image, published, options.credentials);\n\n\t\tconst volume = volumeOf(container);\n\t\tif (volume) volumes[volume] = {};\n\t}\n\n\tconst minio = services.minio;\n\tif (minio && options.objectWebhooks?.length) {\n\t\tminio.environment = {\n\t\t\t...minio.environment,\n\t\t\t...minioWebhookEnv(options.objectWebhooks),\n\t\t};\n\t\t// Locally it posts to a process on the host, which Docker Desktop\n\t\t// resolves on its own and Linux needs mapped.\n\t\tif (\n\t\t\toptions.objectWebhooks.some((hook) =>\n\t\t\t\thook.endpoint.includes(`//${HOST_GATEWAY}:`),\n\t\t\t)\n\t\t) {\n\t\t\tminio.extra_hosts = [`${HOST_GATEWAY}:host-gateway`];\n\t\t}\n\t}\n\n\tconst mailpit = services.mailpit;\n\tif (mailpit && options.inboxRelay) {\n\t\tmailpit.environment = {\n\t\t\t...mailpit.environment,\n\t\t\tMP_WEBHOOK_URL: options.inboxRelay,\n\t\t};\n\t\tif (options.inboxRelay.includes(`//${HOST_GATEWAY}:`)) {\n\t\t\tmailpit.extra_hosts = [`${HOST_GATEWAY}:host-gateway`];\n\t\t}\n\t}\n\n\treturn {\n\t\t// Compose derives a project name from the directory otherwise, so two\n\t\t// checkouts of the same repo would fight over one set of containers.\n\t\tname: options.project,\n\t\tservices: { ...services, ...options.apps },\n\t\t...(Object.keys(volumes).length ? { volumes } : {}),\n\t};\n}\n\n/** Render a compose document as the file it becomes. */\nexport function toYaml(file: ComposeFile): string {\n\treturn `# Generated by gkm from the construct manifest — do not edit.\n# Containers are derived from what the app declares. Image pins and anything\n# no construct implies go in your own docker-compose.yml, which is merged over\n# this file and wins:\n#\n# docker compose -f docker-compose.constructs.yml -f docker-compose.yml …\n#\n# \"gkm dev\" and \"gkm test\" start the containers. The apps sit behind the\n# \"apps\" profile: run \"gkm setup\", then\n# docker compose -f docker-compose.constructs.yml --profile apps up --build\n${stringify(file, { lineWidth: 0 })}`;\n}\n\n/** A container with no image, from config or from the defaults. */\n/**\n * The image the databases in the plan named for the shared local cluster, if\n * any did.\n */\nfunction declaredPostgresImage(plan: Plan): string | undefined {\n\tconst named = plan.resources.filter(\n\t\t(r): r is typeof r & { image: string } =>\n\t\t\tr.kind === 'database' && Boolean(r.image),\n\t);\n\tconst images = [...new Set(named.map((r) => r.image))];\n\n\tif (images.length > 1) {\n\t\tthrow new ConflictingPostgresImages(\n\t\t\tnamed.map((r) => ({ id: r.id, image: r.image })),\n\t\t);\n\t}\n\n\treturn images[0];\n}\n\n/** Two databases on the one local cluster named different images for it. */\nexport class ConflictingPostgresImages extends Error {\n\tconstructor(readonly databases: readonly { id: string; image: string }[]) {\n\t\tsuper(\n\t\t\t`Locally every database runs in one Postgres container, and these ` +\n\t\t\t\t`name different images for it: ` +\n\t\t\t\t`${databases.map((d) => `${d.id} (${d.image})`).join(', ')}. ` +\n\t\t\t\t`Give them the same image — one that ships every extension they ` +\n\t\t\t\t`declare.`,\n\t\t);\n\t\tthis.name = 'ConflictingPostgresImages';\n\t}\n}\n\nexport class UnknownContainer extends Error {\n\t/** The container that could not be resolved. */\n\treadonly container: string;\n\t/** The containers that have a default, so the caller can see the set. */\n\treadonly known: readonly string[] = Object.keys(DEFAULT_IMAGES).sort();\n\n\tconstructor(container: string) {\n\t\tsuper('No image is known for this container; pin one in config');\n\t\tthis.name = 'UnknownContainer';\n\t\tthis.container = container;\n\t}\n}\n\n/** One container's definition, published on the port it was assigned. */\nfunction define(\n\tcontainer: string,\n\timage: string,\n\tpublished: string[],\n\tcredentials: ContainerCredentials,\n): ComposeService {\n\tswitch (container) {\n\t\tcase 'postgres':\n\t\t\treturn {\n\t\t\t\timage,\n\t\t\t\trestart: 'unless-stopped',\n\t\t\t\tports: published,\n\t\t\t\tenvironment: {\n\t\t\t\t\t// Read only when the volume is first initialised. A volume made\n\t\t\t\t\t// with another login is rotated to this one by reconcile — see\n\t\t\t\t\t// `logins.ts` — rather than being trusted to follow.\n\t\t\t\t\tPOSTGRES_USER: credentials.postgres.user,\n\t\t\t\t\tPOSTGRES_PASSWORD: credentials.postgres.password,\n\t\t\t\t\t// Every declared database is created inside this cluster by the\n\t\t\t\t\t// applier, not by the image; connections open `postgres` first.\n\t\t\t\t\tPOSTGRES_DB: CLUSTER_DATABASE,\n\t\t\t\t},\n\t\t\t\t// One mount at the parent, not at `data`: the 18 image keeps its\n\t\t\t\t// cluster in a version-named subdirectory and refuses to start when\n\t\t\t\t// something is mounted over the legacy path. Mounting the parent is\n\t\t\t\t// also what makes the next major bump a `pg_upgrade --link` rather\n\t\t\t\t// than a new volume.\n\t\t\t\tvolumes: ['postgres-data:/var/lib/postgresql'],\n\t\t\t\thealthcheck: {\n\t\t\t\t\ttest: [\n\t\t\t\t\t\t'CMD-SHELL',\n\t\t\t\t\t\t`pg_isready -U ${credentials.postgres.user} -d ${CLUSTER_DATABASE}`,\n\t\t\t\t\t],\n\t\t\t\t\tinterval: '5s',\n\t\t\t\t\ttimeout: '3s',\n\t\t\t\t\tretries: 10,\n\t\t\t\t\tstart_period: '10s',\n\t\t\t\t},\n\t\t\t};\n\n\t\tcase 'minio':\n\t\t\treturn {\n\t\t\t\timage,\n\t\t\t\trestart: 'unless-stopped',\n\t\t\t\tports: published,\n\t\t\t\tenvironment: {\n\t\t\t\t\t// Read on every start, so a changed login takes effect when the\n\t\t\t\t\t// container is recreated with it; the buckets stay.\n\t\t\t\t\tMINIO_ROOT_USER: credentials.minio.user,\n\t\t\t\t\tMINIO_ROOT_PASSWORD: credentials.minio.password,\n\t\t\t\t},\n\t\t\t\t// No bucket is created here: buckets are planned resources, and\n\t\t\t\t// creating them in the entrypoint would put their names back in the\n\t\t\t\t// compose file — the declaration this change removes.\n\t\t\t\tcommand: 'server --console-address \":9001\" /data',\n\t\t\t\tvolumes: ['minio-data:/data'],\n\t\t\t\thealthcheck: {\n\t\t\t\t\ttest: ['CMD', 'mc', 'ready', 'local'],\n\t\t\t\t\tinterval: '10s',\n\t\t\t\t\ttimeout: '5s',\n\t\t\t\t\tretries: 5,\n\t\t\t\t\tstart_period: '10s',\n\t\t\t\t},\n\t\t\t};\n\n\t\tcase 'caddy':\n\t\t\treturn {\n\t\t\t\timage,\n\t\t\t\trestart: 'unless-stopped',\n\t\t\t\tports: published,\n\t\t\t\t// Relative to this file, which is at the project root, so the\n\t\t\t\t// mount resolves into `.gkm/` wherever the project lives.\n\t\t\t\tvolumes: [\n\t\t\t\t\t'./.gkm/Caddyfile:/etc/caddy/Caddyfile:ro',\n\t\t\t\t\t// A directory, not a file: every stage writes its own routes into\n\t\t\t\t\t// it, so `gkm test` cannot delete what `gkm dev` is serving.\n\t\t\t\t\t'./.gkm/caddy-sites:/etc/caddy/sites:ro',\n\t\t\t\t\t'caddy-data:/data',\n\t\t\t\t],\n\t\t\t\t// A surface and a site are processes on the *host*, not containers,\n\t\t\t\t// so the edge has to leave Docker's network to reach them. Docker\n\t\t\t\t// Desktop resolves this name already; on Linux it needs saying.\n\t\t\t\textra_hosts: ['host.docker.internal:host-gateway'],\n\t\t\t\thealthcheck: {\n\t\t\t\t\ttest: ['CMD', 'caddy', 'version'],\n\t\t\t\t\tinterval: '10s',\n\t\t\t\t\ttimeout: '5s',\n\t\t\t\t\tretries: 5,\n\t\t\t\t},\n\t\t\t};\n\n\t\tcase 'mailpit':\n\t\t\treturn {\n\t\t\t\timage,\n\t\t\t\trestart: 'unless-stopped',\n\t\t\t\tports: published,\n\t\t\t\tenvironment: {\n\t\t\t\t\t// Accept mail from anything on this network. The URL carries no\n\t\t\t\t\t// credentials locally, which is what the parser's optional `auth`\n\t\t\t\t\t// exists for.\n\t\t\t\t\tMP_SMTP_AUTH_ACCEPT_ANY: '1',\n\t\t\t\t\tMP_SMTP_AUTH_ALLOW_INSECURE: '1',\n\t\t\t\t},\n\t\t\t\thealthcheck: {\n\t\t\t\t\ttest: ['CMD', 'wget', '-q', '--spider', 'http://localhost:8025'],\n\t\t\t\t\tinterval: '10s',\n\t\t\t\t\ttimeout: '5s',\n\t\t\t\t\tretries: 5,\n\t\t\t\t},\n\t\t\t};\n\n\t\tcase 'redis':\n\t\t\treturn {\n\t\t\t\timage,\n\t\t\t\trestart: 'unless-stopped',\n\t\t\t\tports: published,\n\t\t\t\t// The password from the environment, by name, so it is not in the\n\t\t\t\t// container's arguments; `$$` is compose's escape for `$`.\n\t\t\t\t// Through the image's own entrypoint, so it still drops to `redis`.\n\t\t\t\tcommand:\n\t\t\t\t\t'sh -c \\'exec docker-entrypoint.sh redis-server --requirepass \"$$REDIS_PASSWORD\"\\'',\n\t\t\t\tenvironment: {\n\t\t\t\t\tREDIS_PASSWORD: credentials.redis.password,\n\t\t\t\t\t// What `redis-cli` signs in with — the health check's.\n\t\t\t\t\tREDISCLI_AUTH: credentials.redis.password,\n\t\t\t\t},\n\t\t\t\tvolumes: ['redis-data:/data'],\n\t\t\t\thealthcheck: {\n\t\t\t\t\t// Unauthenticated, a ping answers NOAUTH, which is not PONG.\n\t\t\t\t\ttest: ['CMD-SHELL', 'redis-cli ping | grep -q PONG'],\n\t\t\t\t\tinterval: '5s',\n\t\t\t\t\ttimeout: '3s',\n\t\t\t\t\tretries: 5,\n\t\t\t\t},\n\t\t\t};\n\n\t\tcase 'redis-http':\n\t\t\treturn {\n\t\t\t\timage,\n\t\t\t\trestart: 'unless-stopped',\n\t\t\t\tports: published,\n\t\t\t\tenvironment: {\n\t\t\t\t\tSRH_MODE: 'env',\n\t\t\t\t\tSRH_TOKEN: credentials.cacheToken,\n\t\t\t\t\t// The Redis beside it, by compose service name — the one address\n\t\t\t\t\t// in this file that is not published, because nothing outside the\n\t\t\t\t\t// network speaks to it.\n\t\t\t\t\tSRH_CONNECTION_STRING: `redis://:${encodeURIComponent(credentials.redis.password)}@redis:6379`,\n\t\t\t\t},\n\t\t\t\tdepends_on: ['redis'],\n\t\t\t\thealthcheck: {\n\t\t\t\t\t// 127.0.0.1, not localhost: the proxy binds IPv4 only, and\n\t\t\t\t\t// `localhost` resolves to ::1 first inside the container — which\n\t\t\t\t\t// is a health check that never passes and a container that never\n\t\t\t\t\t// comes up.\n\t\t\t\t\ttest: [\n\t\t\t\t\t\t'CMD',\n\t\t\t\t\t\t'wget',\n\t\t\t\t\t\t'-q',\n\t\t\t\t\t\t'-O',\n\t\t\t\t\t\t'/dev/null',\n\t\t\t\t\t\t'http://127.0.0.1:80/',\n\t\t\t\t\t],\n\t\t\t\t\tinterval: '5s',\n\t\t\t\t\ttimeout: '3s',\n\t\t\t\t\tretries: 10,\n\t\t\t\t},\n\t\t\t};\n\n\t\tcase 'rabbitmq':\n\t\t\treturn {\n\t\t\t\timage,\n\t\t\t\trestart: 'unless-stopped',\n\t\t\t\tports: published,\n\t\t\t\tenvironment: {\n\t\t\t\t\t// Read only when the volume is first initialised; reconcile\n\t\t\t\t\t// brings an older volume's users in line — see `logins.ts`.\n\t\t\t\t\tRABBITMQ_DEFAULT_USER: credentials.rabbitmq.user,\n\t\t\t\t\tRABBITMQ_DEFAULT_PASS: credentials.rabbitmq.password,\n\t\t\t\t},\n\t\t\t\tvolumes: ['rabbitmq-data:/var/lib/rabbitmq'],\n\t\t\t\thealthcheck: {\n\t\t\t\t\ttest: ['CMD', 'rabbitmq-diagnostics', '-q', 'ping'],\n\t\t\t\t\tinterval: '10s',\n\t\t\t\t\ttimeout: '5s',\n\t\t\t\t\tretries: 5,\n\t\t\t\t},\n\t\t\t};\n\n\t\tcase 'localstack':\n\t\t\treturn {\n\t\t\t\timage,\n\t\t\t\trestart: 'unless-stopped',\n\t\t\t\tports: published,\n\t\t\t\t// SNS pushes to subscribers on the host — the dev server — and only\n\t\t\t\t// Docker Desktop resolves host.docker.internal on its own. On Linux\n\t\t\t\t// the name has to be mapped, or every push is refused.\n\t\t\t\textra_hosts: ['host.docker.internal:host-gateway'],\n\t\t\t\tenvironment: {\n\t\t\t\t\tAWS_DEFAULT_REGION: EMULATOR_REGION,\n\t\t\t\t\tAWS_ACCESS_KEY_ID: credentials.emulator.accessKeyId,\n\t\t\t\t\tAWS_SECRET_ACCESS_KEY: credentials.emulator.secretAccessKey,\n\t\t\t\t},\n\t\t\t\tvolumes: ['localstack-data:/var/lib/localstack'],\n\t\t\t\thealthcheck: {\n\t\t\t\t\t// Bash, not curl: the floci image ships no curl, so a curl check\n\t\t\t\t\t// never passes and `--wait` fails every start. A TCP connect is\n\t\t\t\t\t// the fact a waiter needs — the gateway binds the port once its\n\t\t\t\t\t// HTTP server is up — and the repo's own compose file does the\n\t\t\t\t\t// same.\n\t\t\t\t\ttest: ['CMD', 'bash', '-c', 'exec 3<>/dev/tcp/localhost/4566'],\n\t\t\t\t\tinterval: '10s',\n\t\t\t\t\ttimeout: '5s',\n\t\t\t\t\tretries: 5,\n\t\t\t\t\tstart_period: '10s',\n\t\t\t\t},\n\t\t\t};\n\n\t\tcase 'openobserve': {\n\t\t\t// The compose stack's own service, with the local stage's login and\n\t\t\t// the default retention — what `gkm compose` on the local stage runs.\n\t\t\tconst login = credentials.logs;\n\t\t\treturn {\n\t\t\t\timage,\n\t\t\t\trestart: 'unless-stopped',\n\t\t\t\tports: published,\n\t\t\t\tenvironment: {\n\t\t\t\t\t[LOGS_EMAIL_KEY]: login.email,\n\t\t\t\t\t[LOGS_PASSWORD_KEY]: login.password,\n\t\t\t\t\tZO_DATA_DIR: '/data',\n\t\t\t\t\tZO_COMPACT_DATA_RETENTION_DAYS: String(LOGS_RETENTION_DAYS),\n\t\t\t\t\t// A local log store does not report home.\n\t\t\t\t\tZO_TELEMETRY: 'false',\n\t\t\t\t},\n\t\t\t\tvolumes: ['openobserve-data:/data'],\n\t\t\t\t// The image has no shell, `wget` or `curl`: its own binary asks the\n\t\t\t\t// running server for its status.\n\t\t\t\thealthcheck: {\n\t\t\t\t\ttest: ['CMD', '/openobserve', 'node', 'status'],\n\t\t\t\t\tinterval: '10s',\n\t\t\t\t\ttimeout: '5s',\n\t\t\t\t\tretries: 12,\n\t\t\t\t\tstart_period: '20s',\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\tdefault:\n\t\t\tthrow new UnknownContainer(container);\n\t}\n}\n\n/**\n * The published port mappings for a container.\n *\n * Every port is looked up by its own key rather than being derived as an offset\n * from the container's first, so MinIO's console cannot land on whatever was\n * allocated to the next container.\n */\nfunction publish(\n\tcontainer: string,\n\tports: PortAssignments,\n\tfakes?: Plan['fakes'],\n): string[] {\n\treturn portsOf(container, fakes).map((port) => {\n\t\tconst assigned = ports[port.key];\n\t\tif (assigned === undefined) throw new UnassignedPort(port.key);\n\n\t\treturn `${assigned}:${port.inside}`;\n\t});\n}\n\n/** A planned port that allocation never assigned. */\nexport class UnassignedPort extends Error {\n\t/** The port key that went unassigned, e.g. `minio-console`. */\n\treadonly key: string;\n\n\tconstructor(key: string) {\n\t\tsuper('No port was assigned for this container port');\n\t\tthis.name = 'UnassignedPort';\n\t\tthis.key = key;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,SAAgB,SACf,OACqB;CACrB,IAAI,MAAM,WAAW,GAAG,OAAO,KAAA;CAG/B,IAAI,MAAM,WAAW,GAAG,OAAO,MAAM,EAAE,CAAE;CAGzC,IAAI,MAAM,MAAM,EAAE,WAAW,SAAS,KAAK,GAAG,OAAO;CAGrD,MAAM,WAAW,MAAM,QAAQ,EAAE,WAAW,SAAS,IAAI;CACzD,IAAI,SAAS,WAAW,GAAG,OAAO,SAAS,EAAE,CAAE;CAE/C,MAAM,IAAI,kBACT,MAAM,KAAK,EAAE,WAAW,IAAI,GAC5B,SAAS,SAAS,CACnB;AACD;;AAGA,IAAa,oBAAb,cAAuC,SAAS;CAErC;CACA;CAFV,YACC,OACA,UAAmB,OAClB;EACD,MACC,UACG,gDAAgD,MAAM,KAAK,IAAI,EAAE,4CAEjE,GAAG,MAAM,OAAO,uDACL,MAAM,KAAK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A,OACA,OACW;CACX,OAAO,QAAQ,WAAW,KAAK,CAAC,CAAC,KAAK,SAAS;EAC9C,MAAM,WAAW,MAAM,KAAK;EAC5B,IAAI,aAAa,KAAA,GAAW,MAAM,IAAI,eAAe,KAAK,GAAG;EAE7D,OAAO,GAAG,SAAS,GAAG,KAAK;CAC5B,CAAC;AACF;;AAGA,IAAa,iBAAb,cAAoC,MAAM;;CAEzC;CAEA,YAAY,KAAa;EACxB,MAAM,8CAA8C;EACpD,KAAK,OAAO;EACZ,KAAK,MAAM;CACZ;AACD"}
1
+ {"version":3,"file":"compose-Cm6EWvjX.mjs","names":[],"sources":["../src/workspace/rootSite.ts","../src/target/dokploy/domain.ts","../src/compose/logs.ts","../src/reconcile/containers.ts","../src/reconcile/emulator.ts","../src/reconcile/objectEvents.ts","../src/compose/redis.ts","../src/deploy/generated.ts","../src/reconcile/localCredentials.ts","../src/credentials/index.ts","../src/reconcile/compose.ts"],"sourcesContent":["/**\n * Which site the base domain points at — deployed and locally alike.\n *\n * Three rules, in order, and the last one is the point:\n *\n * 1. **One site** — it is the root. Unambiguous, so nothing has to be said.\n * 2. **Named `web`** — the convention wins, because people already rely on it.\n * 3. **Declared `root: true`** — the site says so itself.\n *\n * Anything else throws. It used to take the *first* site it iterated, and that\n * order came from the manifest, which is built in glob traversal order — so two\n * sites with neither named `web` meant renaming a file could move the root\n * domain, silently.\n *\n * One rule for both targets: deployed the root site gets the base domain, and\n * locally it gets the project's bare host behind the edge. Before this was\n * shared, the local edge put every site on a subdomain, so what a developer\n * browsed was not the shape production served.\n *\n * @returns the root site's name, or `undefined` when there are no sites\n * @throws {AmbiguousRootSite} when several sites could be the root and none says it is\n */\n\nimport { GkmError } from '../errors';\nexport function rootSite(\n\tsites: readonly { name: string; root?: boolean }[],\n): string | undefined {\n\tif (sites.length === 0) return undefined;\n\n\t// 1. The only site there is.\n\tif (sites.length === 1) return sites[0]!.name;\n\n\t// 2. The convention.\n\tif (sites.some(({ name }) => name === 'web')) return 'web';\n\n\t// 3. What a site declared about itself.\n\tconst declared = sites.filter(({ root }) => root === true);\n\tif (declared.length === 1) return declared[0]!.name;\n\n\tthrow new AmbiguousRootSite(\n\t\tsites.map(({ name }) => name),\n\t\tdeclared.length > 1,\n\t);\n}\n\n/** Several sites could hold the base domain, and none of them says it does. */\nexport class AmbiguousRootSite extends GkmError {\n\tconstructor(\n\t\treadonly sites: readonly string[],\n\t\treadonly tooMany = false,\n\t) {\n\t\tsuper(\n\t\t\ttooMany\n\t\t\t\t? `More than one site declares \\`root: true\\` — ${sites.join(', ')}. ` +\n\t\t\t\t\t\t`The base domain points at one of them.`\n\t\t\t\t: `${sites.length} sites and nothing says which holds the base ` +\n\t\t\t\t\t\t`domain: ${sites.join(', ')}. Name one of them \\`web\\`, or ` +\n\t\t\t\t\t\t`declare \\`root: true\\` on the one the base domain points at. ` +\n\t\t\t\t\t\t`It used to be whichever the glob reached first, which is not a ` +\n\t\t\t\t\t\t`thing to decide a hostname.`,\n\t\t);\n\t\tthis.name = 'AmbiguousRootSite';\n\t}\n}\n","import { WILDCARD_SUBDOMAIN } from '@geekmidas/manifest';\nimport { GkmError } from '../../errors';\nimport { getPublicEnvPrefix } from '../../workspace/index.js';\nimport { rootSite } from '../../workspace/rootSite.js';\nimport type {\n\tDomainsConfig,\n\tNormalizedAppConfig,\n} from '../../workspace/types.js';\n\n/** A stage was deployed that `domains` gives no domain. */\nexport class NoDomainForStage extends GkmError {\n\tconstructor(readonly stage: string) {\n\t\tsuper(\n\t\t\t`No domain for stage \"${stage}\". Add it to gkm.config.ts: domains: { ${stage}: 'example.com' }.`,\n\t\t);\n\t\tthis.name = 'NoDomainForStage';\n\t}\n}\n\n/**\n * The hostname an app answers on for a stage.\n *\n * 1. An explicit `app.domain` — a string, or one per stage — wins.\n * 2. Otherwise from the stage's base domain in `domains`: the root site\n * answers on the domain itself, and every other app on\n * `{subdomain}.{domain}` — its declaration's `subdomain`, or its own name.\n *\n * @throws {NoDomainForStage} when `domains` names no domain for it\n */\nexport function resolveHost(\n\tappName: string,\n\tapp: NormalizedAppConfig,\n\tstage: string,\n\tdomains: DomainsConfig | undefined,\n\tisMainFrontend: boolean,\n): string {\n\tif (app.domain) {\n\t\tif (typeof app.domain === 'string') {\n\t\t\treturn app.domain;\n\t\t}\n\t\tif (app.domain[stage]) {\n\t\t\treturn app.domain[stage]!;\n\t\t}\n\t}\n\n\tconst baseDomain = domains?.[stage];\n\tif (!baseDomain) throw new NoDomainForStage(stage);\n\n\tif (isMainFrontend) return baseDomain;\n\n\treturn `${app.subdomain ?? appName}.${baseDomain}`;\n}\n\n/**\n * Whether this app is the site the base domain points at — see `rootSite`,\n * which the local edge asks too.\n *\n * @throws {AmbiguousRootSite} when several sites could be the root and none says it is\n */\nexport function isMainFrontendApp(\n\tappName: string,\n\tapp: NormalizedAppConfig,\n\tallApps: Record<string, NormalizedAppConfig>,\n): boolean {\n\t// A wildcard site answers on every subdomain, never on the domain itself.\n\tconst holds = (a: NormalizedAppConfig) =>\n\t\ta.type === 'web' && a.subdomain !== WILDCARD_SUBDOMAIN;\n\tif (!holds(app)) return false;\n\n\tconst sites = Object.entries(allApps)\n\t\t.filter(([, a]) => holds(a))\n\t\t.map(([name, a]) => ({ name, root: a.root }));\n\n\treturn rootSite(sites) === appName;\n}\n\nexport { AmbiguousRootSite } from '../../workspace/rootSite.js';\n\n/**\n * Generate public URL build args for a web/mobile app based on its dependencies.\n *\n * The prefix is chosen by the app's framework (NEXT_PUBLIC_, VITE_,\n * EXPO_PUBLIC_, or none for Remix). Apps without a public prefix get no\n * build args — they should fetch URLs at runtime instead.\n *\n * @param app - The web/mobile app configuration\n * @param deployedUrls - Map of app name to deployed public URL\n * @returns Array of build args like 'NEXT_PUBLIC_API_URL=https://api.example.com'\n */\nexport function generatePublicUrlBuildArgs(\n\tapp: NormalizedAppConfig,\n\tdeployedUrls: Record<string, string>,\n): string[] {\n\tconst prefix = getPublicEnvPrefix(app.framework);\n\tif (!prefix) return [];\n\n\tconst buildArgs: string[] = [];\n\tfor (const dep of app.dependencies) {\n\t\tconst publicUrl = deployedUrls[dep];\n\t\tif (publicUrl) {\n\t\t\tbuildArgs.push(`${prefix}${dep.toUpperCase()}_URL=${publicUrl}`);\n\t\t}\n\t}\n\n\treturn buildArgs;\n}\n\n/**\n * Get public URL arg names from app dependencies.\n *\n * @param app - The web/mobile app configuration\n * @returns Array of arg names like 'NEXT_PUBLIC_API_URL', or [] for frameworks\n * without a public prefix (e.g. Remix).\n */\nexport function getPublicUrlArgNames(app: NormalizedAppConfig): string[] {\n\tconst prefix = getPublicEnvPrefix(app.framework);\n\tif (!prefix) return [];\n\treturn app.dependencies.map((dep) => `${prefix}${dep.toUpperCase()}_URL`);\n}\n","/**\n * The stack's log UI: OpenObserve, run beside the apps as telemetry's\n * self-hosted provider, and every process with a `Telemetry` edge pointed at\n * it.\n *\n * The production server already exports its traces and pino logs over\n * OTLP/HTTP when `OTEL_EXPORTER_OTLP_ENDPOINT` is set. OpenObserve takes OTLP\n * at `/api/<org>/v1/{logs,traces}` with HTTP basic auth, so wiring an app is\n * two variables: the endpoint, `http://openobserve:5080/api/default`, and\n * the header that signs in as the root user.\n *\n * It is reached, by default, through an SSH tunnel: published on 127.0.0.1\n * only, because a port Docker publishes on every interface is opened in the\n * firewall by Docker itself, past ufw's rules. Served publicly, it is a host\n * on the stack's Caddy that refuses every address not allowed.\n *\n * Pure: the stack decides it, and the phases print and check it.\n */\n\nimport { randomBytes } from 'node:crypto';\nimport { GkmError } from '../errors';\nimport type { StageSecrets } from '../secrets/types.js';\nimport { NoDomainForStage } from '../target/dokploy/domain.js';\nimport { LOGS_PORT, type ResolvedLogs } from './logsConfig.js';\nimport type { StackService } from './stack.js';\n\n/**\n * The image, pinned. A log store's on-disk format is the thing that must not\n * move under a running stack, so a new version is a change to this line.\n */\nexport const OPENOBSERVE_IMAGE = 'public.ecr.aws/zinclabs/openobserve:v1.0.4';\n\n/** Its compose service name — the host the apps send to. */\nexport const LOGS_SERVICE = 'openobserve';\n\n/** The organisation every app's telemetry lands in. */\nexport const LOGS_ORG = 'default';\n\n/** The stage secrets that sign in as OpenObserve's root user. */\nexport const LOGS_EMAIL_KEY = 'ZO_ROOT_USER_EMAIL';\nexport const LOGS_PASSWORD_KEY = 'ZO_ROOT_USER_PASSWORD';\n\n/**\n * The local stage's root user. Its password is generated per machine with\n * the other local logins — see `reconcile/localCredentials.ts`.\n */\nexport const LOCAL_LOGS_EMAIL = 'admin@gkm.localhost';\n\n/** The stack's OpenObserve, as the stack runs it. */\nexport interface StackLogs extends ResolvedLogs {\n\t/** The root user's email and password. */\n\temail: string;\n\tpassword: string;\n\t/** Whether the stage's secrets set the password, rather than the local login. */\n\tpasswordFromSecrets: boolean;\n\t/** Where a browser opens it: the tunnel's end, or its public host. */\n\turl: string;\n\t/** Its public host, when it is served through Caddy. */\n\thost?: string;\n\t/** Its own environment, written to `openobserve.env` (0600). */\n\tenv: Record<string, string>;\n\t/** Where every process with a `Telemetry` edge sends, and how it signs. */\n\tappEnv: {\n\t\tOTEL_EXPORTER_OTLP_ENDPOINT: string;\n\t\tOTEL_EXPORTER_OTLP_HEADERS: string;\n\t};\n}\n\n/** A root password OpenObserve would refuse to start with. */\nexport class LogsPasswordWeak extends GkmError {\n\tconstructor(readonly stage: string) {\n\t\tsuper(\n\t\t\t`The stage '${stage}' sets ${LOGS_PASSWORD_KEY}, and OpenObserve refuses ` +\n\t\t\t\t'it: a root password must be 8 to 128 characters with a lowercase ' +\n\t\t\t\t'letter, an uppercase letter, a digit and a symbol. Set another with ' +\n\t\t\t\t`gkm secrets:set ${LOGS_PASSWORD_KEY} '…' --stage ${stage}, or unset ` +\n\t\t\t\t'it to have one generated.',\n\t\t);\n\t\tthis.name = 'LogsPasswordWeak';\n\t}\n}\n\n/** A deployed stage with logs on and no root password generated yet. */\nexport class LogsPasswordMissing extends GkmError {\n\tconstructor(readonly stage: string) {\n\t\tsuper(\n\t\t\t`The stage '${stage}' runs OpenObserve and has no ${LOGS_PASSWORD_KEY} ` +\n\t\t\t\t`in its secrets. Run gkm compose --stage ${stage} without --dry-run ` +\n\t\t\t\t'once to generate it, or set one: ' +\n\t\t\t\t`gkm secrets:set ${LOGS_PASSWORD_KEY} '…' --stage ${stage}`,\n\t\t);\n\t\tthis.name = 'LogsPasswordMissing';\n\t}\n}\n\n/** Whether OpenObserve accepts `password` for its root user. */\nexport function isStrongLogsPassword(password: string): boolean {\n\treturn (\n\t\tpassword.length >= 8 &&\n\t\tpassword.length <= 128 &&\n\t\t/[a-z]/.test(password) &&\n\t\t/[A-Z]/.test(password) &&\n\t\t/\\d/.test(password) &&\n\t\t/[^A-Za-z0-9]/.test(password)\n\t);\n}\n\n/**\n * A root password: 192 random bits, with a fixed tail so every class\n * OpenObserve requires is present whatever the random part drew.\n */\nexport function generateLogsPassword(): string {\n\treturn `${randomBytes(24).toString('base64url')}-Zo1`;\n}\n\n/**\n * The stage's secrets with a generated root password, where it has none.\n * Pure, like `withGeneratedSecrets`: the caller keeps the result once the\n * run goes ahead.\n */\nexport function withLogsPassword(secrets: StageSecrets): {\n\tsecrets: StageSecrets;\n\tgenerated: string[];\n} {\n\tif (secrets.custom?.[LOGS_PASSWORD_KEY]) return { secrets, generated: [] };\n\treturn {\n\t\tsecrets: {\n\t\t\t...secrets,\n\t\t\tcustom: {\n\t\t\t\t...secrets.custom,\n\t\t\t\t[LOGS_PASSWORD_KEY]: generateLogsPassword(),\n\t\t\t},\n\t\t\tupdatedAt: new Date().toISOString(),\n\t\t},\n\t\tgenerated: [LOGS_PASSWORD_KEY],\n\t};\n}\n\n/**\n * `OTEL_EXPORTER_OTLP_HEADERS` signing in as `email`.\n *\n * The variable's values are percent-decoded by the SDK (they follow the W3C\n * baggage format), so the space after `Basic` is written `%20`. Base64's own\n * `+`, `/` and `=` pass through decoding unchanged.\n */\nexport function otlpHeaders(email: string, password: string): string {\n\tconst token = Buffer.from(`${email}:${password}`).toString('base64');\n\treturn `Authorization=Basic%20${token}`;\n}\n\n/** The stack's OpenObserve for one stage. */\nexport function stackLogs(options: {\n\tconfig: ResolvedLogs;\n\tstage: string;\n\tlocal: boolean;\n\t/** The workspace's name: the local stage's public host is under it. */\n\tproject: string;\n\tdomain?: string;\n\tcustom: Readonly<Record<string, string>>;\n\t/** The edge's HTTPS port, which a local public URL carries. */\n\thttps: number;\n\t/** The local stage's generated root login — required for it. */\n\tlocalLogin?: { email: string; password: string };\n}): StackLogs {\n\tconst { config, stage, local, custom } = options;\n\n\tif (!local && !options.domain) throw new NoDomainForStage(stage);\n\n\tconst email =\n\t\tcustom[LOGS_EMAIL_KEY] ??\n\t\t(local\n\t\t\t? (options.localLogin?.email ?? LOCAL_LOGS_EMAIL)\n\t\t\t: `admin@${options.domain}`);\n\tconst set = custom[LOGS_PASSWORD_KEY];\n\tconst password = set ?? (local ? options.localLogin?.password : undefined);\n\tif (!password) throw new LogsPasswordMissing(stage);\n\tif (!isStrongLogsPassword(password)) throw new LogsPasswordWeak(stage);\n\n\tconst host = config.public\n\t\t? local\n\t\t\t? `logs.${options.project}.localhost`\n\t\t\t: `logs.${options.domain}`\n\t\t: undefined;\n\tconst url = host\n\t\t? `https://${host}${local && options.https !== 443 ? `:${options.https}` : ''}`\n\t\t: `http://localhost:${config.port}`;\n\n\treturn {\n\t\t...config,\n\t\temail,\n\t\tpassword,\n\t\tpasswordFromSecrets: Boolean(set),\n\t\turl,\n\t\t...(host ? { host } : {}),\n\t\tenv: {\n\t\t\t[LOGS_EMAIL_KEY]: email,\n\t\t\t[LOGS_PASSWORD_KEY]: password,\n\t\t\tZO_DATA_DIR: '/data',\n\t\t\t// Verified against the image: days, and it refuses fewer than 3.\n\t\t\tZO_COMPACT_DATA_RETENTION_DAYS: String(config.retentionDays),\n\t\t\t// A self-hosted log store on a stage's box does not report home.\n\t\t\tZO_TELEMETRY: 'false',\n\t\t},\n\t\tappEnv: {\n\t\t\tOTEL_EXPORTER_OTLP_ENDPOINT: `http://${LOGS_SERVICE}:${LOGS_PORT}/api/${LOGS_ORG}`,\n\t\t\tOTEL_EXPORTER_OTLP_HEADERS: otlpHeaders(email, password),\n\t\t},\n\t};\n}\n\n/**\n * OpenObserve's service. The image has no shell, `wget` or `curl`, so its\n * health check is its own binary asking the running server for its status —\n * which exits non-zero when nothing answers on its port.\n */\nexport function logsService(logs: StackLogs): StackService {\n\treturn {\n\t\timage: OPENOBSERVE_IMAGE,\n\t\trestart: 'unless-stopped',\n\t\tenv_file: [{ path: `./${LOGS_SERVICE}.env`, format: 'raw' }],\n\t\tvolumes: ['openobserve-data:/data'],\n\t\t// Loopback only: Docker opens a port it publishes on every interface in\n\t\t// the firewall itself, past ufw. Served publicly, Caddy is the way in.\n\t\t...(logs.public ? {} : { ports: [`127.0.0.1:${logs.port}:${LOGS_PORT}`] }),\n\t\thealthcheck: {\n\t\t\ttest: ['CMD', '/openobserve', 'node', 'status'],\n\t\t\tinterval: '10s',\n\t\t\ttimeout: '5s',\n\t\t\tretries: 12,\n\t\t\tstart_period: '20s',\n\t\t},\n\t};\n}\n\n/** Where to guess the stack is reached from, for the printed tunnel. */\nexport interface LogsAccessContext {\n\tstage: string;\n\tlocal: boolean;\n\t/**\n\t * The SSH target: the stage's server login, or — for the local stage —\n\t * this machine's user and name, the best guess at it.\n\t */\n\tuser: string;\n\thostname: string;\n\t/** Whether `user` and `hostname` are the stage's server, not a guess. */\n\tknown?: boolean;\n}\n\n/** What `gkm compose` prints once the stack is up: how to open the logs. */\nexport function logsAccess(logs: StackLogs, ctx: LogsAccessContext): string[] {\n\tconst login = `login: ${logs.email}, password: ${\n\t\tctx.local && !logs.passwordFromSecrets\n\t\t\t? logs.password\n\t\t\t: `gkm secrets:show --stage ${ctx.stage} --reveal → ${LOGS_PASSWORD_KEY}`\n\t}`;\n\n\tif (logs.public) {\n\t\treturn [\n\t\t\t`📜 Logs (OpenObserve): ${logs.url} (${login})`,\n\t\t\t` answered only for ${logs.public.allow.join(', ')}; every other address gets 403`,\n\t\t];\n\t}\n\n\treturn [\n\t\t`📜 Logs (OpenObserve) on 127.0.0.1:${logs.port} — from your computer:`,\n\t\t// The local stage usually runs where you are; it can run on a box too.\n\t\t...(ctx.local\n\t\t\t? [\n\t\t\t\t\t` on this machine, open http://localhost:${logs.port} directly; from another:`,\n\t\t\t\t]\n\t\t\t: []),\n\t\t` ssh -N -L ${logs.port}:localhost:${logs.port} ${ctx.user}@${ctx.hostname}${ctx.known ? '' : \" (user and host are guesses: this machine's)\"}`,\n\t\t` then open http://localhost:${logs.port} (${login})`,\n\t\t`⚠️ Docker-published ports bypass ufw, so OpenObserve is bound to 127.0.0.1 only — reach it through the tunnel, not by opening the port.`,\n\t];\n}\n","import {\n\tDEFAULT_POSTGRES_VERSION,\n\tkebabCase,\n\ttype PostgresVersion,\n} from '@geekmidas/manifest';\nimport { OPENOBSERVE_IMAGE } from '../compose/logs.js';\nimport { LOGS_PORT } from '../compose/logsConfig.js';\n/**\n * What gkm knows about each container it can derive.\n *\n * Everything provider-specific about the local target lives here: the image, the\n * ports the image listens on, and whether its data is worth keeping. The plan\n * says *which* containers exist and never says any of this, which is the split\n * the design asks for — neutral facts from the declaration, provider detail\n * from here and from config.\n *\n * Shared by allocation and by the compose writer so the two cannot disagree\n * about how many ports a container needs.\n */\n\n/**\n * The Postgres image for a major version.\n *\n * One place that knows the tag shape, so a declared version reaches the\n * container without anyone restating `-alpine` beside it.\n */\nexport function postgresImage(version: PostgresVersion): string {\n\treturn `postgres:${version}-alpine`;\n}\n\n/**\n * The default image for each container.\n *\n * Pinned to a major rather than `latest` where the image publishes one, so a\n * rebuild does not silently move a developer's Postgres a version. A database\n * can name its own (`image: 'postgis/postgis:…'`); any other pin is the\n * project's own `docker-compose.yml`.\n */\nexport const DEFAULT_IMAGES: Readonly<Record<string, string>> = {\n\tpostgres: postgresImage(DEFAULT_POSTGRES_VERSION),\n\tminio: 'pgsty/minio:RELEASE.2026-08-04T00-00-00Z',\n\tmailpit: 'axllent/mailpit:latest',\n\tredis: 'redis:8-alpine',\n\t'redis-http': 'hiett/serverless-redis-http:latest',\n\trabbitmq: 'rabbitmq:4-management-alpine',\n\t// Pinned: 2.2.0 answers a KMS decrypt under the wrong encryption context\n\t// with UnknownError instead of InvalidCiphertextException.\n\tlocalstack: 'floci/floci:2.1.0',\n\t// The local edge: TLS with gkm's local CA, and host-based routing onto the\n\t// bucket behind it. Not a CDN — what is missing locally is the *mapping*\n\t// and the certificate, not caching, and a caching proxy would add an\n\t// invalidation story no local stack needs.\n\tcaddy: 'caddy:2-alpine',\n\t// Telemetry's collector and its UI — the image the compose stack runs.\n\topenobserve: OPENOBSERVE_IMAGE,\n};\n\n/** One port an image listens on. */\nexport interface ContainerPort {\n\t/**\n\t * The name this port is allocated and persisted under.\n\t *\n\t * Per port rather than per container so that adding a console port later\n\t * assigns a new one instead of shifting the port the app already connects to.\n\t */\n\tkey: string;\n\t/** The port inside the container, fixed by the image. */\n\tinside: number;\n\t/** What it is for, in the one line `gkm dev` and `gkm setup` print. */\n\tlabel: string;\n\t/** A page a person opens, so it prints as a link rather than an address. */\n\tweb?: true;\n}\n\n/**\n * The ports each container listens on.\n *\n * The first is always the one an app connects to; the rest are consoles and\n * management UIs, published because a bucket or an inbox you can look at is most\n * of why these are real containers rather than stubs.\n */\nconst PORTS: Readonly<Record<string, readonly ContainerPort[]>> = {\n\tpostgres: [{ key: 'postgres', inside: 5432, label: 'postgres' }],\n\tminio: [\n\t\t{ key: 'minio', inside: 9000, label: 'minio api' },\n\t\t{ key: 'minio-console', inside: 9001, label: 'minio console', web: true },\n\t],\n\tmailpit: [\n\t\t{ key: 'mailpit', inside: 1025, label: 'smtp' },\n\t\t{ key: 'mailpit-web', inside: 8025, label: 'mailpit inbox', web: true },\n\t],\n\tredis: [{ key: 'redis', inside: 6379, label: 'redis' }],\n\t'redis-http': [{ key: 'redis-http', inside: 80, label: 'cache' }],\n\trabbitmq: [\n\t\t{ key: 'rabbitmq', inside: 5672, label: 'amqp' },\n\t\t{\n\t\t\tkey: 'rabbitmq-management',\n\t\t\tinside: 15672,\n\t\t\tlabel: 'rabbitmq console',\n\t\t\tweb: true,\n\t\t},\n\t],\n\tlocalstack: [{ key: 'localstack', inside: 4566, label: 'localstack' }],\n\t// One port, and an assigned one rather than 443. The whole point of\n\t// allocation is that two projects run at once, and an edge that insists on\n\t// the privileged port puts that back — at the cost of a port in the URL,\n\t// which no cookie or CORS rule looks at.\n\tcaddy: [{ key: 'caddy', inside: 443, label: 'https edge' }],\n\t// OTLP ingest and the UI on one port.\n\topenobserve: [\n\t\t{ key: 'openobserve', inside: LOGS_PORT, label: 'openobserve', web: true },\n\t],\n};\n\n/**\n * An external API's fake, as the local target runs it.\n *\n * Keyed by its port key, `<id>-fake`, which is also its container's name when\n * it has one — so `primaryPortKey` finds its port with no table to consult.\n * A module fake has no image: gkm serves it, on the port this key is assigned.\n */\nexport interface PlannedFake {\n\t/** The external API it stands in for. */\n\tid: string;\n\t/** The image to run, for a fake the provider publishes. */\n\timage?: string;\n\t/** The port that image listens on inside the container. */\n\tport?: number;\n}\n\n/** The port key — and container name, for an image — of an API's fake. */\nexport function fakeKey(id: string): string {\n\treturn `${kebabCase(id)}-fake`;\n}\n\n/**\n * The ports a container needs published. Empty for one gkm does not know.\n *\n * `fakes` answers for the containers no table can: an external API's fake\n * listens wherever its declaration says.\n */\nexport function portsOf(\n\tcontainer: string,\n\tfakes: Readonly<Record<string, PlannedFake>> = {},\n): readonly ContainerPort[] {\n\tconst fake = fakes[container];\n\tif (fake?.port !== undefined) {\n\t\treturn [{ key: container, inside: fake.port, label: `${fake.id} fake` }];\n\t}\n\n\treturn PORTS[container] ?? [];\n}\n\n/** One published port, as a person reads it. */\nexport interface ServiceAddress {\n\tcontainer: string;\n\tlabel: string;\n\t/** `http://localhost:<port>` for a page, `localhost:<port>` otherwise. */\n\taddress: string;\n}\n\n/**\n * Every port the containers publish — not only the one an app connects to.\n *\n * The consoles and the inbox are most of why these are real containers, and an\n * inbox nobody can find is an inbox nobody opens: a sign-in link gets fished\n * out of `docker ps` instead.\n */\nexport function serviceAddresses(\n\tcontainers: readonly string[],\n\tports: Readonly<Record<string, number>>,\n\tfakes: Readonly<Record<string, PlannedFake>> = {},\n): ServiceAddress[] {\n\treturn containers.flatMap((container) =>\n\t\tportsOf(container, fakes).flatMap((port) => {\n\t\t\tconst assigned = ports[port.key];\n\t\t\tif (assigned === undefined) return [];\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tcontainer,\n\t\t\t\t\tlabel: port.label,\n\t\t\t\t\taddress: port.web\n\t\t\t\t\t\t? `http://localhost:${assigned}`\n\t\t\t\t\t\t: `localhost:${assigned}`,\n\t\t\t\t},\n\t\t\t];\n\t\t}),\n\t);\n}\n\n/** The lines `gkm dev` and `gkm setup` print under the services heading. */\nexport function describeServices(\n\tservices: readonly ServiceAddress[],\n): string[] {\n\tconst width = Math.max(0, ...services.map(({ label }) => label.length));\n\treturn services.map(\n\t\t({ label, address }) => ` ${label.padEnd(width)} ${address}`,\n\t);\n}\n\n/** The key a container's primary port is allocated under. */\nexport function primaryPortKey(container: string): string {\n\treturn portsOf(container)[0]?.key ?? container;\n}\n\n/**\n * Every port key a set of containers needs, in a stable order.\n *\n * What allocation is handed: it assigns ports to names and knows nothing about\n * what listens on them.\n */\nexport function portKeys(\n\tcontainers: readonly string[],\n\tfakes: Readonly<Record<string, PlannedFake>> = {},\n): string[] {\n\tconst keys = [...containers]\n\t\t.sort()\n\t\t.flatMap((container) => portsOf(container, fakes).map((port) => port.key));\n\n\t// A module fake runs in no container, and still needs a port to answer on.\n\treturn [...new Set([...keys, ...Object.keys(fakes).sort()])];\n}\n\n/**\n * The named volume a container's data lives in.\n *\n * Mailpit deliberately has none: local mail is disposable, and an inbox that\n * survives days of dev is noise rather than state.\n */\nexport function volumeOf(container: string): string | undefined {\n\tconst volumes: Readonly<Record<string, string>> = {\n\t\tpostgres: 'postgres-data',\n\t\tminio: 'minio-data',\n\t\tredis: 'redis-data',\n\t\trabbitmq: 'rabbitmq-data',\n\t\tlocalstack: 'localstack-data',\n\t\t// Holds the CA it generated. Losing it means a new root on every start,\n\t\t// and a trust store full of dead authorities.\n\t\tcaddy: 'caddy-data',\n\t\topenobserve: 'openobserve-data',\n\t};\n\n\treturn volumes[container];\n}\n","/**\n * The AWS emulator (floci, LocalStack-compatible) the `sns` backend runs on\n * locally — the facts the compose file, the env writer and the applier must\n * agree on.\n *\n * The emulator has one account and answers with deterministic ARNs and queue\n * URLs, which is what lets a connection string be composed before the topic\n * or queue it names has been created.\n */\n\n/** The emulator's single account. */\nexport const EMULATOR_ACCOUNT = '000000000000';\n\nexport const EMULATOR_REGION = 'us-east-1';\n\n/**\n * The emulator's access key id. The `LSIA` prefix is what LocalStack required\n * on issued keys, and LocalStack reads the account from the id — so it is\n * fixed, where the secret key beside it is generated per machine (see\n * `localCredentials.ts`). Floci does not care; keeping it means a project\n * that pins the old image still works.\n */\nexport const EMULATOR_ACCESS_KEY_ID = 'LSIAQAAAAAAVNCBMPNSG';\n\n/** The emulator's address from the host, on the port it was published on. */\nexport function emulatorEndpoint(port: number): string {\n\treturn `http://localhost:${port}`;\n}\n\nexport function emulatorTopicArn(name: string): string {\n\treturn `arn:aws:sns:${EMULATOR_REGION}:${EMULATOR_ACCOUNT}:${name}`;\n}\n\nexport function emulatorQueueUrl(name: string, port: number): string {\n\treturn `${emulatorEndpoint(port)}/${EMULATOR_ACCOUNT}/${name}`;\n}\n","/**\n * A bucket's object events, where the bucket is a local MinIO.\n *\n * S3 publishes a bucket's events to a topic the deploy creates; MinIO has no\n * topic to publish to, but it can post each event to a webhook. So where MinIO\n * holds a watched bucket, it posts the bucket's events to the process that\n * runs the bucket's subscribers, on a route only it can use, and that process\n * relays each one onto the events broker — under the bucket's name, as\n * `object.created` or `object.deleted` — where every subscriber drains a queue\n * of its own, as a topic's subscribers do.\n *\n * Declared to MinIO in two halves, both derived here so they cannot drift:\n *\n * - **a webhook target per bucket**, as container environment: where to post,\n * the token to present, and a queue on disk, because MinIO starts before the\n * process it posts to and must keep what it could not deliver;\n * - **the bucket's notification**, written through the S3 API once the bucket\n * exists: every created and removed object, to that target. Unfiltered —\n * two subscribers watching overlapping prefixes are two rules S3 refuses on\n * one bucket, and each subscriber filters what it is handed anyway.\n */\n\nimport { createHash } from 'node:crypto';\nimport { type ConstructManifest, provideKey } from '@geekmidas/manifest';\nimport type { BoundSubscriber } from './discover.js';\nimport type { BucketNotification } from './provision.js';\n\n/** Where MinIO posts one bucket's events. */\nexport interface ObjectWebhook {\n\t/** The bucket construct, `Uploads`. */\n\tbucket: string;\n\t/** The route on the process that runs the bucket's subscribers. */\n\tendpoint: string;\n\t/** What MinIO presents, and that process checks. */\n\ttoken: string;\n}\n\n/**\n * The token MinIO presents when it posts a bucket's events.\n *\n * Derived, never stored: the container and the process it posts to are handed\n * the same value by the same derivation — with the stage's random seed where a\n * deployed stage's stack has one, so the token is a secret there, and from the\n * project alone locally, where everything it would protect is on loopback.\n * Not salted by the stage: one MinIO serves `gkm dev` and `gkm test`, and a\n * target is declared once per container.\n */\nexport function objectsWebhookToken(\n\tproject: string,\n\tbucket: string,\n\tseed?: string,\n): string {\n\treturn createHash('sha256')\n\t\t.update(`${seed ? `${seed}:` : ''}${project}:objects-webhook:${bucket}`)\n\t\t.digest('base64url')\n\t\t.slice(0, 32);\n}\n\n/**\n * The target's id in MinIO's environment — `MINIO_NOTIFY_WEBHOOK_*_<ID>`.\n *\n * Upper-cased with nothing between words: a canonical id is letters and\n * digits, and an underscore inside the id would read as part of the setting's\n * name.\n */\nexport function minioTargetId(bucket: string): string {\n\treturn bucket.toUpperCase();\n}\n\n/** The target as a notification names it. */\nexport function minioTargetArn(bucket: string): string {\n\treturn `arn:minio:sqs::${minioTargetId(bucket)}:webhook`;\n}\n\n/** How a container reaches a process on the host. */\nexport const HOST_GATEWAY = 'host.docker.internal';\n\n/** Where MinIO keeps what it could not deliver yet, inside its container. */\nconst QUEUE_ROOT = '/gkm-object-events';\n\n/** The id of the notification rule gkm owns on a bucket. */\nexport const NOTIFICATION_RULE_PREFIX = 'gkm-';\n\n/**\n * MinIO's environment for each watched bucket's webhook target.\n *\n * Sorted, so the same buckets always render the same environment and a\n * reconcile that changed nothing does not recreate the container.\n */\nexport function minioWebhookEnv(\n\thooks: readonly ObjectWebhook[],\n): Record<string, string> {\n\tconst env: Record<string, string> = {};\n\tfor (const hook of [...hooks].sort((a, b) =>\n\t\ta.bucket.localeCompare(b.bucket),\n\t)) {\n\t\tconst id = minioTargetId(hook.bucket);\n\t\tenv[`MINIO_NOTIFY_WEBHOOK_ENABLE_${id}`] = 'on';\n\t\tenv[`MINIO_NOTIFY_WEBHOOK_ENDPOINT_${id}`] = hook.endpoint;\n\t\t// Sent as `Authorization: Bearer <token>`.\n\t\tenv[`MINIO_NOTIFY_WEBHOOK_AUTH_TOKEN_${id}`] = hook.token;\n\t\t// MinIO is up before whatever it posts to: what it cannot deliver is\n\t\t// kept here and sent once the route answers.\n\t\tenv[`MINIO_NOTIFY_WEBHOOK_QUEUE_DIR_${id}`] =\n\t\t\t`${QUEUE_ROOT}/${id.toLowerCase()}`;\n\t}\n\treturn env;\n}\n\n/** The rule that sends every created and removed object to the bucket's target. */\nexport function minioNotificationRule(\n\tbucket: string,\n): NonNullable<BucketNotification['QueueConfigurations']>[number] {\n\treturn {\n\t\tId: `${NOTIFICATION_RULE_PREFIX}${bucket}`,\n\t\tQueueArn: minioTargetArn(bucket),\n\t\tEvents: ['s3:ObjectCreated:*', 's3:ObjectRemoved:*'],\n\t};\n}\n\n/**\n * Each watched bucket, and the workers that run one of its subscribers.\n *\n * A bucket is watched when a subscriber reads its events key. MinIO posts a\n * bucket's events to one place, and the relay fans them out to every\n * subscriber whichever worker received them — so one worker per bucket is\n * enough, and the first, by id, is the one chosen, so the choice is stable.\n */\nexport function watchedBuckets(\n\tmanifest: ConstructManifest,\n\tsubscribers: Readonly<Record<string, readonly BoundSubscriber[]>>,\n): Map<string, string> {\n\tconst byKey = new Map<string, string>();\n\tfor (const declaration of Object.values(manifest)) {\n\t\tif (declaration.kind !== 'objects') continue;\n\t\tbyKey.set(\n\t\t\tprovideKey(declaration.id, 'eventsConnectionString'),\n\t\t\tdeclaration.id,\n\t\t);\n\t}\n\n\tconst watched = new Map<string, string>();\n\tfor (const worker of Object.keys(subscribers).sort()) {\n\t\tfor (const { connectionKey } of subscribers[worker] ?? []) {\n\t\t\tconst bucket = byKey.get(connectionKey);\n\t\t\tif (bucket && !watched.has(bucket)) watched.set(bucket, worker);\n\t\t}\n\t}\n\treturn watched;\n}\n","/**\n * The stack's Redis: what every declared cache lives in when a workspace runs\n * as a `gkm compose` stack, on the local stage and on a deployed one alike.\n *\n * A cache is the one store whose contents can always be rebuilt, so unlike\n * Mailpit and MinIO it is a production service, not a dev stand-in: it runs\n * for every stage, on the compose network only, with nothing published. It\n * is bounded (`maxmemory`, evicting the least recently used key), persisted\n * (an append-only file on a named volume, kept by `--down`) and password\n * protected — the stage's own password, generated once like its seed.\n *\n * A stage that sets a cache's URL in its secrets — a managed Redis — keeps\n * it, and a stack whose every cache is set that way runs no Redis at all.\n *\n * Pure: the stack decides it, and the phases keep the password.\n */\n\nimport { randomBytes } from 'node:crypto';\nimport { type ConstructManifest, provideKey } from '@geekmidas/manifest';\nimport { GkmError } from '../errors';\nimport { DEFAULT_IMAGES } from '../reconcile/containers.js';\nimport type { Plan } from '../reconcile/plan.js';\nimport type { StageSecrets } from '../secrets/types.js';\nimport type { CacheBackend } from '../types.js';\nimport type { StackService } from './stack.js';\n\n/**\n * Where a stack's caches live: its own Redis, whatever the deploy target's\n * default is. A stack is one machine running containers, and a Redis beside\n * the apps is cheaper for a cache than a table in the database they share.\n */\nexport const STACK_CACHE: CacheBackend = 'redis';\n\n/** Its compose service name — the host every cache URL points at. */\nexport const REDIS_SERVICE = 'redis';\n\n/** The port it answers on, inside the network. */\nexport const REDIS_PORT = 6379;\n\n/** Reconcile's pin, so `gkm dev` and the stack run one Redis. */\nexport const REDIS_IMAGE = DEFAULT_IMAGES.redis!;\n\n/**\n * How much it may hold before it evicts. A cache that grows until the box\n * runs out of memory takes the apps with it; 256 MB is a lot of sessions and\n * little of a small server. A project's `docker-compose.<stage>.yml` can\n * replace the command to change it.\n */\nexport const REDIS_MAXMEMORY = '256mb';\n\n/** The stage secret holding its password. */\nexport const REDIS_PASSWORD_KEY = 'REDIS_PASSWORD';\n\n/** Redis's own count of logical databases, before `--databases` raises it. */\nconst REDIS_DATABASES = 16;\n\n/** A deployed stage that runs the stack's Redis and has no password yet. */\nexport class RedisPasswordMissing extends GkmError {\n\tconstructor(readonly stage: string) {\n\t\tsuper(\n\t\t\t`The stage '${stage}' runs the stack's Redis and has no ` +\n\t\t\t\t`${REDIS_PASSWORD_KEY} in its secrets. Run gkm compose --stage ` +\n\t\t\t\t`${stage} without --dry-run once to generate it, or set one: ` +\n\t\t\t\t`gkm secrets:set ${REDIS_PASSWORD_KEY} '…' --stage ${stage}`,\n\t\t);\n\t\tthis.name = 'RedisPasswordMissing';\n\t}\n}\n\n/** The stack's Redis, as the stack runs it. */\nexport interface StackRedis {\n\tpassword: string;\n\t/** Whether the stage's secrets set the password, rather than the local one. */\n\tpasswordFromSecrets: boolean;\n\t/**\n\t * Each cache it holds — its URL key, and the URL — and each WebSocket\n\t * surface's publisher, whose sockets meet their senders on its pub/sub.\n\t */\n\turls: Record<string, string>;\n\t/** Its own environment, written to `redis.env` (0600). */\n\tenv: Record<string, string>;\n\t/** How many logical databases it keeps — one per cache, at least 16. */\n\tdatabases: number;\n}\n\n/**\n * Whether a stage's stack runs Redis: a cache or a WebSocket surface is\n * declared and the stage's secrets do not set the URL of every one.\n */\nexport function runsRedis(\n\tmanifest: ConstructManifest,\n\tcustom: Readonly<Record<string, string>>,\n): boolean {\n\treturn Object.values(manifest).some((declaration) => {\n\t\tif (declaration?.kind === 'cache') {\n\t\t\treturn (declaration.provides ?? []).some(\n\t\t\t\t(key) => custom[key] === undefined,\n\t\t\t);\n\t\t}\n\t\treturn (\n\t\t\tdeclaration?.kind === 'websocket-api' &&\n\t\t\tcustom[provideKey(declaration.id, 'publisherConnectionString')] ===\n\t\t\t\tundefined\n\t\t);\n\t});\n}\n\n/** A password: 256 random bits, URL-safe, so it sits in a URL unescaped. */\nexport function generateRedisPassword(): string {\n\treturn randomBytes(32).toString('base64url');\n}\n\n/**\n * The stage's secrets with a generated Redis password, where it has none.\n * Pure, like `withGeneratedSecrets`: the caller keeps the result once the run\n * goes ahead.\n */\nexport function withRedisPassword(secrets: StageSecrets): {\n\tsecrets: StageSecrets;\n\tgenerated: string[];\n} {\n\tif (secrets.custom?.[REDIS_PASSWORD_KEY]) return { secrets, generated: [] };\n\treturn {\n\t\tsecrets: {\n\t\t\t...secrets,\n\t\t\tcustom: {\n\t\t\t\t...secrets.custom,\n\t\t\t\t[REDIS_PASSWORD_KEY]: generateRedisPassword(),\n\t\t\t},\n\t\t\tupdatedAt: new Date().toISOString(),\n\t\t},\n\t\tgenerated: [REDIS_PASSWORD_KEY],\n\t};\n}\n\n/**\n * The stack's Redis for one stage, or nothing where no cache needs it.\n *\n * Each cache it holds gets a logical database of its own, by the order of\n * their ids, so two caches never read each other's keys.\n */\nexport function stackRedis(options: {\n\tplan: Plan;\n\tstage: string;\n\tlocal: boolean;\n\tcustom: Readonly<Record<string, string>>;\n\t/** The local stage's generated password — `gkm dev`'s Redis's too. */\n\tlocalPassword?: string;\n}): StackRedis | undefined {\n\tconst { plan, stage, local, custom } = options;\n\n\tconst caches = plan.resources\n\t\t.filter((r) => r.kind === 'cache' && custom[r.envKey] === undefined)\n\t\t.sort((a, b) => a.id.localeCompare(b.id));\n\tconst publishers = plan.resources\n\t\t.filter((r) => r.kind === 'websocket-api')\n\t\t.map((r) => provideKey(r.id, 'publisherConnectionString'))\n\t\t.filter((key) => custom[key] === undefined);\n\tif (caches.length === 0 && publishers.length === 0) return undefined;\n\n\tconst set = custom[REDIS_PASSWORD_KEY];\n\tconst password = set ?? (local ? options.localPassword : undefined);\n\tif (!password) throw new RedisPasswordMissing(stage);\n\tconst auth = encodeURIComponent(password);\n\n\treturn {\n\t\tpassword,\n\t\tpasswordFromSecrets: Boolean(set),\n\t\turls: Object.fromEntries([\n\t\t\t...caches.map((cache, index) => [\n\t\t\t\tcache.envKey,\n\t\t\t\t`redis://:${auth}@${REDIS_SERVICE}:${REDIS_PORT}/${index}`,\n\t\t\t]),\n\t\t\t// Pub/sub is not scoped by database, so no index: a surface's\n\t\t\t// channels are named for it.\n\t\t\t...publishers.map((key) => [\n\t\t\t\tkey,\n\t\t\t\t`redis://:${auth}@${REDIS_SERVICE}:${REDIS_PORT}`,\n\t\t\t]),\n\t\t]),\n\t\tenv: {\n\t\t\t// What the server is started with, by name: the command reads it\n\t\t\t// from the environment, so the value is never in its arguments.\n\t\t\t[REDIS_PASSWORD_KEY]: password,\n\t\t\t// What `redis-cli` signs in with — the health check's, and anyone's\n\t\t\t// who execs into the container — without `-a` on a command line.\n\t\t\tREDISCLI_AUTH: password,\n\t\t},\n\t\tdatabases: Math.max(REDIS_DATABASES, caches.length),\n\t};\n}\n\n/**\n * Redis's service: bounded, persisted and password protected, on the\n * network alone.\n *\n * The command runs the image's own entrypoint with `redis-server` first, so\n * it still drops to the `redis` user and owns `/data`; the password is read\n * from the env file by the shell (`$$` is compose's escape for `$`), so\n * neither the compose file nor the container's command holds it.\n */\nexport function redisService(redis: StackRedis): StackService {\n\tconst flags = [\n\t\t`--requirepass \"$$${REDIS_PASSWORD_KEY}\"`,\n\t\t`--maxmemory ${REDIS_MAXMEMORY}`,\n\t\t'--maxmemory-policy allkeys-lru',\n\t\t'--appendonly yes',\n\t\t...(redis.databases > REDIS_DATABASES\n\t\t\t? [`--databases ${redis.databases}`]\n\t\t\t: []),\n\t];\n\treturn {\n\t\timage: REDIS_IMAGE,\n\t\trestart: 'unless-stopped',\n\t\tcommand: [\n\t\t\t'sh',\n\t\t\t'-c',\n\t\t\t`exec docker-entrypoint.sh redis-server ${flags.join(' ')}`,\n\t\t],\n\t\tenv_file: [{ path: `./${REDIS_SERVICE}.env`, format: 'raw' }],\n\t\tvolumes: ['redis-data:/data'],\n\t\thealthcheck: {\n\t\t\t// `redis-cli` signs in with REDISCLI_AUTH; an unauthenticated ping\n\t\t\t// answers NOAUTH, which is not PONG.\n\t\t\ttest: ['CMD-SHELL', 'redis-cli ping | grep -q PONG'],\n\t\t\tinterval: '5s',\n\t\t\ttimeout: '3s',\n\t\t\tretries: 10,\n\t\t},\n\t};\n}\n","/**\n * The values a deployed stage generates once and keeps: what nothing can\n * provision and nobody else issues.\n *\n * - **A seed**, which salts every password a deploy derives — a database's\n * master and roles, a bucket's root user. Derived from repo facts alone\n * (project, stage, construct id), those passwords were computable by anyone\n * who could read the repo.\n * - **Each `secret` construct's value** — an auth server's signing secret, a\n * `RandomPassword` — random, rather than derived, in its declared format.\n * - **Each `encryption` construct's keyring** — one random key and an index\n * key. Later keys are added by `gkm encryption:rotate`, never by a deploy.\n *\n * Both are generated on the first deploy that needs them and written to the\n * stage's store, so every later deploy reads the same values: sessions survive\n * a redeploy, and a role's password does not move. A value set by hand with\n * `gkm secrets:set` is kept, never replaced.\n */\n\nimport { randomBytes, randomInt } from 'node:crypto';\nimport { generateKeyring } from '@geekmidas/constructs/encryption';\nimport { type ConstructManifest, drawSecret } from '@geekmidas/manifest';\nimport type { StageSecrets } from '../secrets/types.js';\n\nexport interface GeneratedSecrets {\n\t/** The stage's secrets with everything it generates present. */\n\tsecrets: StageSecrets;\n\t/** What was generated this time, by key — empty when nothing was missing. */\n\tgenerated: string[];\n}\n\n/**\n * The stage's secrets with its seed and every declared `secret`'s value\n * present, generating what is missing. Pure: the caller writes the result\n * back to the stage's store when `generated` is not empty.\n */\nexport function withGeneratedSecrets(\n\tsecrets: StageSecrets,\n\tmanifest: ConstructManifest,\n): GeneratedSecrets {\n\tconst generated: string[] = [];\n\tconst custom = { ...secrets.custom };\n\n\tfor (const declaration of Object.values(manifest)) {\n\t\tif (declaration?.kind !== 'secret' && declaration?.kind !== 'encryption') {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst key = declaration.provides?.[0];\n\t\tif (!key || custom[key]) continue;\n\n\t\tcustom[key] =\n\t\t\tdeclaration.kind === 'encryption'\n\t\t\t\t? generateKeyring()\n\t\t\t\t: drawSecret(randomInt, declaration);\n\t\tgenerated.push(key);\n\t}\n\n\tconst seed = secrets.seed ?? generateSeed();\n\tif (!secrets.seed) generated.push('seed');\n\n\treturn {\n\t\tsecrets: generated.length\n\t\t\t? { ...secrets, seed, custom, updatedAt: new Date().toISOString() }\n\t\t\t: secrets,\n\t\tgenerated,\n\t};\n}\n\n/** A stage's seed: 256 random bits, URL-safe. */\nexport function generateSeed(): string {\n\treturn random();\n}\n\n/** 256 bits, URL-safe. */\nfunction random(): string {\n\treturn randomBytes(32).toString('base64url');\n}\n","/**\n * The logins of the containers `gkm dev`, `gkm test` and the compose local\n * stage run — generated once per machine and workspace, and read back on\n * every later run.\n *\n * They used to be one fixed word, the same on every laptop, so anyone who\n * could reach a developer's Postgres could sign in to it. Now each password,\n * token and secret key is random, in the shape its service accepts, and the\n * user names are neutral ones derived from the workspace.\n *\n * **Where they are kept.** Encrypted with the local stage's key, in the CLI's\n * home beside the keys (`<home>/local/<namespace>/<project>.json`), rather\n * than in a checkout's `.gkm/`. The containers are per machine and project —\n * every checkout of a repo attaches to the same Postgres — so their logins\n * have to be too: two worktrees each generating their own would take turns\n * locking each other out of one database.\n *\n * **Why stored, not derived from a seed.** One cluster serves the local stage\n * and `test`, while a derivation is per stage; each service has its own rules\n * a hash does not meet by default; and a volume that cannot be rotated keeps\n * the login it has, which a derivation cannot express. The seed is generated\n * beside them all the same, and salts the per-role passwords the way a\n * deployed stage's does.\n */\n\nimport { randomBytes, randomInt } from 'node:crypto';\nimport { existsSync } from 'node:fs';\nimport { mkdir, readFile, rm, stat, writeFile } from 'node:fs/promises';\nimport { dirname, join } from 'node:path';\nimport { generateLogsPassword, LOCAL_LOGS_EMAIL } from '../compose/logs.js';\nimport { generateRedisPassword } from '../compose/redis.js';\nimport { generateSeed } from '../deploy/generated.js';\nimport { GkmError } from '../errors';\nimport { gkmHome } from '../home.js';\nimport {\n\tdecrypt,\n\ttype EncryptedSecretsFile,\n\tencrypt,\n} from '../secrets/file.js';\nimport {\n\tgetKeystoreDir,\n\tgetOrCreateKey,\n\ttype KeystoreProject,\n\tkeystoreProject,\n\treadKey,\n} from '../secrets/keystore.js';\nimport type { NormalizedWorkspace } from '../workspace/types.js';\nimport { EMULATOR_ACCESS_KEY_ID } from './emulator.js';\n\n/** A user name and its password. */\nexport interface Login {\n\tuser: string;\n\tpassword: string;\n}\n\n/**\n * What every container a plan implies is brought up with, and every URL\n * that reaches one carries.\n */\nexport interface ContainerCredentials {\n\t/** The cluster's superuser — what creates databases and roles. */\n\tpostgres: Login;\n\t/** MinIO's root user, which the S3 client signs with. */\n\tminio: Login;\n\t/** RabbitMQ's administrator. */\n\trabbitmq: Login;\n\t/** Redis's `requirepass`. */\n\tredis: { password: string };\n\t/** The token the cache's HTTP proxy accepts. */\n\tcacheToken: string;\n\t/** The AWS emulator's key pair. */\n\temulator: { accessKeyId: string; secretAccessKey: string };\n\t/**\n\t * OpenObserve's root user — `gkm dev`'s, where a process uses a\n\t * `Telemetry` construct, and `gkm compose`'s on the local stage.\n\t */\n\tlogs: { email: string; password: string };\n}\n\n/** The local stage's logins: the containers', and what else it generates. */\nexport interface LocalCredentials extends ContainerCredentials {\n\t/** Salts every per-role password, as a deployed stage's seed does. */\n\tseed: string;\n}\n\n/** MinIO refuses a root password shorter than 8 or longer than 40. */\nexport const MINIO_PASSWORD_LENGTH = 32;\n\n/** An AWS secret key is 40 characters. */\nexport const EMULATOR_SECRET_KEY_LENGTH = 40;\n\n/** MinIO's root user, the same for every workspace: it is not a secret. */\nexport const LOCAL_MINIO_USER = 'minio';\n\n/** RabbitMQ's administrator, the same way. */\nexport const LOCAL_RABBITMQ_USER = 'rabbitmq';\n\n/**\n * The Postgres superuser for a workspace: its name as an identifier, with\n * `_admin` — never the bare name, which a database construct of the same\n * name would claim as its runtime role.\n */\nexport function postgresSuperuser(project: string): string {\n\treturn `${postgresRoleSlug(project)}_admin`;\n}\n\n/**\n * The project as the start of a role's name: lowercase, `_` for anything\n * else, never starting with a digit — `gkm` when nothing is left.\n */\nexport function postgresRoleSlug(project: string): string {\n\tconst slug = project\n\t\t.toLowerCase()\n\t\t.replace(/^@[^/]+\\//, '')\n\t\t.replace(/[^a-z0-9]+/g, '_')\n\t\t.replace(/^_+|_+$/g, '')\n\t\t.replace(/^(\\d)/, '_$1');\n\treturn slug || 'gkm';\n}\n\n/** 256 random bits, URL-safe. */\nfunction token(): string {\n\treturn randomBytes(32).toString('base64url');\n}\n\n/** `length` characters of letters and digits, which every client takes as is. */\nfunction alphanumeric(length: number): string {\n\tconst alphabet =\n\t\t'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';\n\tlet out = '';\n\tfor (let i = 0; i < length; i++) out += alphabet[randomInt(alphabet.length)];\n\treturn out;\n}\n\n/** A fresh set of local logins for a workspace. */\nexport function generateLocalCredentials(project: string): LocalCredentials {\n\treturn {\n\t\tseed: generateSeed(),\n\t\tpostgres: { user: postgresSuperuser(project), password: token() },\n\t\tminio: {\n\t\t\tuser: LOCAL_MINIO_USER,\n\t\t\tpassword: alphanumeric(MINIO_PASSWORD_LENGTH),\n\t\t},\n\t\trabbitmq: { user: LOCAL_RABBITMQ_USER, password: token() },\n\t\tredis: { password: generateRedisPassword() },\n\t\tcacheToken: token(),\n\t\temulator: {\n\t\t\t// Fixed: the emulator reads its account from the key id, and every\n\t\t\t// ARN reconcile composes names that account. Only the secret is one.\n\t\t\taccessKeyId: EMULATOR_ACCESS_KEY_ID,\n\t\t\tsecretAccessKey: alphanumeric(EMULATOR_SECRET_KEY_LENGTH),\n\t\t},\n\t\tlogs: { email: LOCAL_LOGS_EMAIL, password: generateLogsPassword() },\n\t};\n}\n\n/**\n * The stored logins with anything missing generated — a file an older gkm\n * wrote before a service existed. Pure: the caller writes the result back\n * when `generated` is not empty.\n */\nexport function withLocalCredentials(\n\tstored: Partial<LocalCredentials> | null | undefined,\n\tproject: string,\n): { credentials: LocalCredentials; generated: string[] } {\n\tconst fresh = generateLocalCredentials(project);\n\tconst generated = (Object.keys(fresh) as (keyof LocalCredentials)[]).filter(\n\t\t(key) => stored?.[key] === undefined,\n\t);\n\treturn {\n\t\tcredentials: { ...fresh, ...stored } as LocalCredentials,\n\t\tgenerated,\n\t};\n}\n\n/** Where a workspace's local logins are kept on this machine. */\nexport function localCredentialsPath(project: KeystoreProject): string {\n\t// Validates the key and splits it the way the keystore does.\n\tconst keys = getKeystoreDir(project);\n\tconst name = keys.split(/[\\\\/]/).at(-1)!;\n\tconst namespace = keys.split(/[\\\\/]/).at(-2)!;\n\treturn join(project.home ?? gkmHome(), 'local', namespace, `${name}.json`);\n}\n\n/** The local stage's logins file is there, and its key is not. */\nexport class LocalCredentialsKeyMissing extends GkmError {\n\tconstructor(\n\t\treadonly path: string,\n\t\treadonly stage: string,\n\t) {\n\t\tsuper(\n\t\t\t`The local logins at ${path} are encrypted with the '${stage}' stage's ` +\n\t\t\t\t\"key, and this machine has none. Remove the file to generate new ones — the containers' volumes are rotated to them on the next gkm dev.\",\n\t\t);\n\t\tthis.name = 'LocalCredentialsKeyMissing';\n\t}\n}\n\n/** Another gkm held the logins file's lock for longer than any write takes. */\nexport class LocalCredentialsLocked extends GkmError {\n\tconstructor(readonly lock: string) {\n\t\tsuper(\n\t\t\t`Another gkm has been writing the local logins for over ${LOCK_TIMEOUT_MS / 1000}s. If none is running, remove ${lock} and run the command again.`,\n\t\t);\n\t\tthis.name = 'LocalCredentialsLocked';\n\t}\n}\n\n/** Read the stored logins, or `null` where none were generated yet. */\nexport async function readLocalCredentials(\n\tworkspace: Pick<NormalizedWorkspace, 'name' | 'root' | 'stages'> &\n\t\tParameters<typeof keystoreProject>[0],\n\thome?: string,\n): Promise<LocalCredentials | null> {\n\tconst project = keystoreProject(workspace, home);\n\tconst path = localCredentialsPath(project);\n\tif (!existsSync(path)) return null;\n\n\tconst stage = workspace.stages.local;\n\tconst key = await readKey(stage, project);\n\tif (!key) throw new LocalCredentialsKeyMissing(path, stage);\n\tconst file = JSON.parse(\n\t\tawait readFile(path, 'utf-8'),\n\t) as EncryptedSecretsFile;\n\treturn decrypt<LocalCredentials>(file, key);\n}\n\n/** Write the logins, encrypted with the local stage's key, owner-only. */\nexport async function saveLocalCredentials(\n\tworkspace: Parameters<typeof readLocalCredentials>[0],\n\tcredentials: LocalCredentials,\n\thome?: string,\n): Promise<void> {\n\tconst project = keystoreProject(workspace, home);\n\tconst path = localCredentialsPath(project);\n\tconst key = await getOrCreateKey(workspace.stages.local, project);\n\tawait mkdir(dirname(path), { recursive: true, mode: 0o700 });\n\tawait writeFile(path, JSON.stringify(encrypt(credentials, key), null, 2), {\n\t\tmode: 0o600,\n\t});\n}\n\n/**\n * The workspace's local logins: read back, or generated and kept the first\n * time anything needs them.\n *\n * Under a lock, because a workspace's `gkm dev` starts one per app and the\n * first run of each would otherwise generate — and keep — its own.\n */\nexport async function loadLocalCredentials(\n\tworkspace: Parameters<typeof readLocalCredentials>[0],\n\thome?: string,\n): Promise<{ credentials: LocalCredentials; generated: string[] }> {\n\tconst path = localCredentialsPath(keystoreProject(workspace, home));\n\treturn withLock(`${path}.lock`, async () => {\n\t\tconst stored = await readLocalCredentials(workspace, home);\n\t\tconst result = withLocalCredentials(stored, workspace.name);\n\t\tif (result.generated.length > 0) {\n\t\t\tawait saveLocalCredentials(workspace, result.credentials, home);\n\t\t}\n\t\treturn result;\n\t});\n}\n\n/** How long a lock may be held before it is someone else's problem. */\nconst LOCK_TIMEOUT_MS = 15_000;\n\nasync function withLock<T>(lock: string, body: () => Promise<T>): Promise<T> {\n\tawait mkdir(dirname(lock), { recursive: true, mode: 0o700 });\n\tconst started = Date.now();\n\tfor (;;) {\n\t\ttry {\n\t\t\tawait mkdir(lock);\n\t\t\tbreak;\n\t\t} catch (error) {\n\t\t\tif ((error as NodeJS.ErrnoException).code !== 'EEXIST') throw error;\n\t\t\t// A lock older than any write is left over from a process that died\n\t\t\t// holding it.\n\t\t\tconst age = await stat(lock)\n\t\t\t\t.then((s) => Date.now() - s.mtimeMs)\n\t\t\t\t.catch(() => 0);\n\t\t\tif (age > LOCK_TIMEOUT_MS) {\n\t\t\t\tawait rm(lock, { recursive: true, force: true });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (Date.now() - started > LOCK_TIMEOUT_MS) {\n\t\t\t\tthrow new LocalCredentialsLocked(lock);\n\t\t\t}\n\t\t\tawait new Promise((resolve) => setTimeout(resolve, 50));\n\t\t}\n\t}\n\ttry {\n\t\treturn await body();\n\t} finally {\n\t\tawait rm(lock, { recursive: true, force: true });\n\t}\n}\n","import { existsSync } from 'node:fs';\nimport { mkdir, readFile, writeFile } from 'node:fs/promises';\nimport { createServer } from 'node:net';\nimport { dirname, join, resolve } from 'node:path';\nimport { config as dotenvConfig } from 'dotenv';\nimport {\n\tConfigNotFound,\n\tloadWorkspaceAppInfo,\n\tloadWorkspaceConfig,\n\tNotInAnApp,\n\ttype WorkspaceAppInfo,\n} from '../config';\nimport type { ReconcileResult } from '../reconcile/index.js';\nimport { toEmbeddableSecrets } from '../secrets/storage.js';\nimport {\n\tFileSecretsStore,\n\ttype SecretsStore,\n\tsecretsStoreFor,\n} from '../secrets/store.js';\nimport type { NormalizedWorkspace } from '../workspace/index.js';\n\nconst logger = console;\n\n// ---------------------------------------------------------------------------\n// Environment files\n// ---------------------------------------------------------------------------\n\n/**\n * Load environment files\n * @internal Exported for testing\n */\nexport function loadEnvFiles(\n\tenvConfig: string | string[] | undefined,\n\tcwd: string = process.cwd(),\n): { loaded: string[]; missing: string[] } {\n\tconst loaded: string[] = [];\n\tconst missing: string[] = [];\n\n\t// Normalize to array\n\tconst envFiles = envConfig\n\t\t? Array.isArray(envConfig)\n\t\t\t? envConfig\n\t\t\t: [envConfig]\n\t\t: ['.env'];\n\n\t// Load each env file in order (later files override earlier)\n\tfor (const envFile of envFiles) {\n\t\tconst envPath = resolve(cwd, envFile);\n\t\tif (existsSync(envPath)) {\n\t\t\tdotenvConfig({ path: envPath, override: true, quiet: true });\n\t\t\tloaded.push(envFile);\n\t\t} else if (envConfig) {\n\t\t\t// Only report as missing if explicitly configured\n\t\t\tmissing.push(envFile);\n\t\t}\n\t}\n\n\treturn { loaded, missing };\n}\n\n// ---------------------------------------------------------------------------\n// Port utilities\n// ---------------------------------------------------------------------------\n\n/**\n * Check if a port is available\n * @internal Exported for testing\n */\nexport async function isPortAvailable(port: number): Promise<boolean> {\n\treturn new Promise((resolve) => {\n\t\tconst server = createServer();\n\n\t\tserver.once('error', (err: NodeJS.ErrnoException) => {\n\t\t\tif (err.code === 'EADDRINUSE') {\n\t\t\t\tresolve(false);\n\t\t\t} else {\n\t\t\t\tresolve(false);\n\t\t\t}\n\t\t});\n\n\t\tserver.once('listening', () => {\n\t\t\tserver.close();\n\t\t\tresolve(true);\n\t\t});\n\n\t\tserver.listen(port);\n\t});\n}\n\n/**\n * Find an available port starting from the preferred port\n * @internal Exported for testing\n */\nexport async function findAvailablePort(\n\tpreferredPort: number,\n\tmaxAttempts = 10,\n): Promise<number> {\n\tfor (let i = 0; i < maxAttempts; i++) {\n\t\tconst port = preferredPort + i;\n\t\tif (await isPortAvailable(port)) {\n\t\t\treturn port;\n\t\t}\n\t\tlogger.log(`⚠️ Port ${port} is in use, trying ${port + 1}...`);\n\t}\n\n\tthrow new Error(\n\t\t`Could not find an available port after trying ${maxAttempts} ports starting from ${preferredPort}`,\n\t);\n}\n\n// ---------------------------------------------------------------------------\n// Docker Compose port mapping\n// ---------------------------------------------------------------------------\n\n/** Port state persisted to .gkm/ports.json, keyed by env var name. */\nexport type PortState = Record<string, number>;\n\nconst PORT_STATE_PATH = '.gkm/ports.json';\n\n/**\n * Load saved port state from .gkm/ports.json.\n * @internal Exported for testing\n */\nexport async function loadPortState(workspaceRoot: string): Promise<PortState> {\n\ttry {\n\t\tconst raw = await readFile(join(workspaceRoot, PORT_STATE_PATH), 'utf-8');\n\t\treturn JSON.parse(raw) as PortState;\n\t} catch {\n\t\treturn {};\n\t}\n}\n\n/**\n * Save port state to .gkm/ports.json.\n * @internal Exported for testing\n */\nexport async function savePortState(\n\tworkspaceRoot: string,\n\tports: PortState,\n): Promise<void> {\n\tconst dir = join(workspaceRoot, '.gkm');\n\tawait mkdir(dir, { recursive: true });\n\tawait writeFile(\n\t\tjoin(workspaceRoot, PORT_STATE_PATH),\n\t\t`${JSON.stringify(ports, null, 2)}\\n`,\n\t);\n}\n\n// ---------------------------------------------------------------------------\n// URL rewriting\n// ---------------------------------------------------------------------------\n\n// ---------------------------------------------------------------------------\n// Docker Compose services\n// ---------------------------------------------------------------------------\n\n// ---------------------------------------------------------------------------\n// Secrets loading\n// ---------------------------------------------------------------------------\n\n/**\n * Load and flatten a stage's secrets from its store.\n *\n * Every key as stored — nothing renamed. An app's database URL is its\n * construct's key, derived by reconcile, and never a stored per-app value\n * mapped onto `DATABASE_URL`.\n * @internal Exported for testing\n */\nexport async function loadSecretsForApp(\n\tstore: SecretsStore,\n\tstage: string,\n): Promise<Record<string, string>> {\n\tconst stageSecrets = await store.read(stage);\n\tif (!stageSecrets) return {};\n\n\tlogger.log(`🔐 Loading secrets from stage: ${stage}`);\n\treturn toEmbeddableSecrets(stageSecrets);\n}\n\n/**\n * Walk up the directory tree to find the root containing .gkm/secrets/.\n * @internal Exported for testing\n */\nexport function findSecretsRoot(startDir: string): string {\n\tlet dir = startDir;\n\twhile (dir !== '/') {\n\t\tif (existsSync(join(dir, '.gkm', 'secrets'))) {\n\t\t\treturn dir;\n\t\t}\n\t\tconst parent = dirname(dir);\n\t\tif (parent === dir) break;\n\t\tdir = parent;\n\t}\n\treturn startDir;\n}\n\n// ---------------------------------------------------------------------------\n// Credentials preload / injection\n// ---------------------------------------------------------------------------\n\n/**\n * Generate the credentials injection code snippet.\n * This is the common logic used by both entry wrapper and exec preload.\n * @internal\n */\nfunction generateCredentialsInjection(secretsJsonPath: string): string {\n\treturn `import { existsSync, readFileSync } from 'node:fs';\n\n// Inject dev secrets via globalThis and process.env\n// Using globalThis.__gkm_credentials__ avoids CJS/ESM interop issues where\n// Object.assign on the Credentials export only mutates one module copy.\nconst secretsPath = '${secretsJsonPath}';\nif (existsSync(secretsPath)) {\n const secrets = JSON.parse(readFileSync(secretsPath, 'utf-8'));\n globalThis.__gkm_credentials__ = secrets;\n Object.assign(process.env, secrets);\n}\n`;\n}\n\n/**\n * Create a preload script that injects secrets into Credentials.\n * Used by `gkm exec` to inject secrets before running any command.\n * @internal Exported for testing\n */\nexport async function createCredentialsPreload(\n\tpreloadPath: string,\n\tsecretsJsonPath: string,\n): Promise<void> {\n\tconst content = `/**\n * Credentials preload generated by 'gkm exec'\n * This file is loaded via NODE_OPTIONS=\"--import <path>\"\n */\n${generateCredentialsInjection(secretsJsonPath)}`;\n\n\tawait writeFile(preloadPath, content);\n}\n\n/**\n * Create a wrapper script that injects secrets before importing the entry file.\n * @internal Exported for testing\n */\nexport async function createEntryWrapper(\n\twrapperPath: string,\n\tentryPath: string,\n\tsecretsJsonPath?: string,\n): Promise<void> {\n\tconst credentialsInjection = secretsJsonPath\n\t\t? `${generateCredentialsInjection(secretsJsonPath)}\n`\n\t\t: '';\n\n\t// Use dynamic import() to ensure secrets are assigned before the entry file loads\n\t// Static imports are hoisted, so Object.assign would run after the entry file is loaded\n\tconst content = `#!/usr/bin/env node\n/**\n * Entry wrapper generated by 'gkm dev --entry'\n */\n${credentialsInjection}// Import and run the user's entry file (dynamic import ensures secrets load first)\nawait import('${entryPath}');\n`;\n\n\tawait writeFile(wrapperPath, content);\n}\n\n// ---------------------------------------------------------------------------\n// Prepare credentials (shared by dev, exec, test)\n// ---------------------------------------------------------------------------\n\n/**\n * Result of preparing credentials.\n */\nexport interface EntryCredentialsResult {\n\t/** Credentials to inject (secrets + PORT) */\n\tcredentials: Record<string, string>;\n\t/** Resolved port (from --port, workspace config, or default 3000) */\n\tresolvedPort: number;\n\t/** Path where credentials JSON was written */\n\tsecretsJsonPath: string;\n\t/** Resolved app name (if in workspace) */\n\tappName: string | undefined;\n\t/** Secrets root directory */\n\tsecretsRoot: string;\n\t/** Workspace app info (if in a workspace) */\n\tappInfo?: WorkspaceAppInfo;\n\t/**\n\t * The keys the manifest declared, as opposed to those a secret store held.\n\t *\n\t * Kept apart because they cannot be *sniffed*. A construct reads its own key\n\t * inside `@geekmidas/constructs`, not in application code, so a walk of the\n\t * app finds no `get('MAIL_URL')` to find — and a caller that filters the\n\t * environment down to what it sniffed would drop every URL the target just\n\t * resolved. `gkm test` did exactly that.\n\t */\n\tdeclaredKeys: string[];\n\t/** The reconcile just run, in a workspace: its plan and its ports. */\n\treconciled?: ReconcileResult;\n}\n\n/**\n * Prepare credentials for dev/exec/test modes.\n * Loads workspace config, secrets, resolves Docker ports, rewrites URLs,\n * injects PORT, dependency URLs, and writes credentials JSON.\n *\n * @param options.stage - The stage whose secrets to load. Default: the project's `stages.local`.\n * @param options.startDocker - Start Docker Compose services after port resolution. Default: false.\n * @param options.secretsFileName - Custom secrets JSON filename. Default: 'dev-secrets-{appName}.json' or 'dev-secrets.json'.\n * @internal Exported for testing\n */\nexport async function prepareEntryCredentials(options: {\n\texplicitPort?: number;\n\tcwd?: string;\n\t/** The stage whose secrets to load. Default: the project's `stages.local` */\n\tstage?: string;\n\t/** Start Docker Compose services after port resolution. Default: false */\n\tstartDocker?: boolean;\n\t/** Custom secrets JSON filename. Default: 'dev-secrets-{appName}.json' or 'dev-secrets.json' */\n\tsecretsFileName?: string;\n\t/**\n\t * The stage to reconcile the local target for.\n\t *\n\t * `gkm test` passes `test` and gets the same containers with suffixed\n\t * resources; left out, it is the project's local stage and they are\n\t * unsuffixed. Only read by workspaces that have adopted the constructs glob.\n\t */\n\treconcileStage?: string;\n\t/**\n\t * Hand an app only what its own process reads (`processEnv`) — its\n\t * edges' keys and the stage's own — as `gkm dev` and `gkm compose` do.\n\t * `gkm exec` asks; `gkm test` does not, since a feature test runs every\n\t * process's code in one.\n\t */\n\tscoped?: boolean;\n}): Promise<EntryCredentialsResult> {\n\tconst cwd = options.cwd ?? process.cwd();\n\n\t// Try to get workspace app config for port and secrets\n\tlet workspaceAppPort: number | undefined;\n\tlet secretsRoot: string = cwd;\n\tlet appName: string | undefined;\n\tlet appInfo: WorkspaceAppInfo | undefined;\n\n\tlet workspace: NormalizedWorkspace | undefined;\n\n\ttry {\n\t\tappInfo = await loadWorkspaceAppInfo(cwd);\n\t\tworkspace = appInfo.workspace;\n\t\tworkspaceAppPort = appInfo.app.port;\n\t\tsecretsRoot = appInfo.workspaceRoot;\n\t\tappName = appInfo.appName;\n\t} catch (error) {\n\t\t// Anything but \"not in an app\" or \"not in a workspace\" is a real fault —\n\t\t// a config that does not load — and must not be mistaken for either.\n\t\tif (!(error instanceof NotInAnApp || error instanceof ConfigNotFound)) {\n\t\t\tthrow error;\n\t\t}\n\t\t// Not an app — but possibly the workspace root, which is where the\n\t\t// scaffold's own `pnpm test` runs `gkm test` from. Without the workspace\n\t\t// here that run skipped the reconcile below: no container started, and the\n\t\t// URLs were whatever the stored secrets said, on ports nothing listened on.\n\t\tworkspace = await loadWorkspaceConfig(cwd)\n\t\t\t.then((loaded) => loaded.workspace)\n\t\t\t.catch(() => undefined);\n\t\t// Otherwise not in a workspace at all (expected for non-gkm apps using\n\t\t// gkm exec) — use defaults.\n\t\t// No app here, so no per-app keys to map.\n\t\tsecretsRoot = workspace?.root ?? findSecretsRoot(cwd);\n\t}\n\n\t// The app's local port, by the rule `gkm dev` applies: moved off a port\n\t// another project holds, and kept. Never refused here — the command may be\n\t// a build or a script that binds nothing, so this app's own dev server\n\t// holding the port is no reason to stop it.\n\tif (appName && workspace && options.explicitPort === undefined) {\n\t\tconst { assignAppPorts, describeMove, holderOf, withAppPorts } =\n\t\t\tawait import('../dev/appPorts.js');\n\t\tconst assigned = await assignAppPorts(workspace, [appName], {\n\t\t\tfree: isPortAvailable,\n\t\t\tholder: holderOf,\n\t\t});\n\t\tfor (const move of assigned.moved) logger.log(describeMove(move));\n\t\tworkspace = withAppPorts(workspace, assigned.ports);\n\t\tworkspaceAppPort = assigned.ports[appName] ?? workspaceAppPort;\n\t}\n\n\t// Tagged, so a later `gkm dev` can tell what this starts from another\n\t// project's process on the same port; the command inherits it.\n\tif (appName) {\n\t\tconst { APP_TAG_ENV, appTag } = await import('../dev/appPorts.js');\n\t\tprocess.env[APP_TAG_ENV] = appTag(secretsRoot, appName);\n\t}\n\n\t// Determine port: explicit --port > the app's local port > default 3000\n\tconst resolvedPort = options.explicitPort ?? workspaceAppPort ?? 3000;\n\n\t// Load secrets and inject PORT. Outside a workspace there are no declared\n\t// stages to read, so only a stage asked for by name is loaded.\n\tconst stage = options.stage ?? workspace?.stages.local;\n\t// The stage's own store; outside a workspace nothing names one but the file.\n\tconst store = stage\n\t\t? workspace\n\t\t\t? await secretsStoreFor(workspace, stage)\n\t\t\t: new FileSecretsStore(secretsRoot)\n\t\t: undefined;\n\tconst credentials =\n\t\tstore && stage ? await loadSecretsForApp(store, stage) : {};\n\n\t// Always inject PORT into credentials so apps can read it\n\tcredentials.PORT = String(resolvedPort);\n\t// Expo reads its Metro port from here when `expo start` is given none, so\n\t// a mobile app runs where the workspace placed it — and where the `exp://`\n\t// origins its auth server trusts say it is.\n\tif (appInfo?.app.type === 'mobile') {\n\t\tcredentials.RCT_METRO_PORT = String(resolvedPort);\n\t}\n\n\tconst declaredKeys: string[] = [];\n\tlet reconciled: ReconcileResult | undefined;\n\n\t// Every address — containers, the edge, each app — comes from what the\n\t// workspace declares. Outside a workspace (a non-gkm app using `gkm exec`)\n\t// there is nothing to resolve, only the secrets above.\n\tif (workspace) {\n\t\tconst { reconcileWorkspace } = await import('../reconcile/workspace.js');\n\t\tconst result = await reconcileWorkspace(workspace, {\n\t\t\tstage: options.reconcileStage ?? workspace.stages.local,\n\t\t\tstart: options.startDocker ?? false,\n\t\t});\n\t\treconciled = result;\n\n\t\t// Declared URLs win over anything stored: the manifest is the statement\n\t\t// of what exists, and a stale secret naming an old port is exactly the\n\t\t// drift this replaces.\n\t\tif (options.scoped && appName) {\n\t\t\tconst { appProcess, processEnv } = await import('../reconcile/apps.js');\n\t\t\tconst own = processEnv(\n\t\t\t\tresult.manifest,\n\t\t\t\tappProcess(workspace, result.manifest, result.background, appName),\n\t\t\t\t{ ...credentials },\n\t\t\t\tresult.env,\n\t\t\t);\n\t\t\tfor (const key of Object.keys(credentials)) delete credentials[key];\n\t\t\tObject.assign(credentials, own);\n\t\t} else {\n\t\t\tObject.assign(credentials, reconciled.env);\n\t\t}\n\t\tdeclaredKeys.push(\n\t\t\t...Object.keys(reconciled.env).filter((key) => key in credentials),\n\t\t);\n\n\t\tif (Object.keys(reconciled.env).length > 0) {\n\t\t\tlogger.log(\n\t\t\t\t`🔌 Resolved ${Object.keys(reconciled.env).length} declared URL(s)`,\n\t\t\t);\n\t\t}\n\t}\n\n\t// Write secrets to temp JSON file (always write since we have PORT)\n\t// Use app-specific filename to avoid race conditions when running multiple apps via turbo\n\tconst secretsDir = join(secretsRoot, '.gkm');\n\tawait mkdir(secretsDir, { recursive: true });\n\tconst secretsFileName =\n\t\toptions.secretsFileName ??\n\t\t(appName ? `dev-secrets-${appName}.json` : 'dev-secrets.json');\n\tconst secretsJsonPath = join(secretsDir, secretsFileName);\n\tawait writeFile(secretsJsonPath, JSON.stringify(credentials, null, 2));\n\n\treturn {\n\t\tcredentials,\n\t\tresolvedPort,\n\t\tsecretsJsonPath,\n\t\tappName,\n\t\tsecretsRoot,\n\t\tappInfo,\n\t\tdeclaredKeys,\n\t\t...(reconciled ? { reconciled } : {}),\n\t};\n}\n","/**\n * The compose document a plan implies.\n *\n * The third declaration of the same containers disappears here: today a\n * `services: ['postgres','minio']` block is kept in step with the code by hand,\n * which is the triplication this design exists to remove, in the one place you\n * touch every day. A `database` implies Postgres; the list is derived.\n *\n * Returns an object rather than a string for the same reason `plan` is pure —\n * what should exist is asserted as data, and turning it into YAML is one line at\n * the edge.\n *\n * What stays config is unchanged: images and versions are pinned explicitly, and\n * a container no construct implies is still declared by hand. Neutral facts come\n * from the declaration, provider detail from config.\n */\n\nimport { stringify } from 'yaml';\nimport { LOGS_EMAIL_KEY, LOGS_PASSWORD_KEY } from '../compose/logs.js';\nimport { LOGS_RETENTION_DAYS } from '../compose/logsConfig.js';\nimport { DEFAULT_IMAGES, portsOf, postgresImage, volumeOf } from './containers';\nimport { EMULATOR_REGION } from './emulator';\nimport type { ContainerCredentials } from './localCredentials';\nimport {\n\tHOST_GATEWAY,\n\tminioWebhookEnv,\n\ttype ObjectWebhook,\n} from './objectEvents';\nimport type { Plan } from './plan';\nimport type { PortAssignments } from './ports';\n\n/** A compose service definition — as much of the schema as is emitted here. */\nexport interface ComposeService {\n\timage: string;\n\t/** An app is built from its generated Dockerfile; a container is pulled. */\n\tbuild?: {\n\t\tcontext: string;\n\t\tdockerfile: string;\n\t\t/** A site's public URLs, which its bundler inlines at build time. */\n\t\targs?: Record<string, string>;\n\t};\n\t/** Behind a profile, so starting the containers does not start the apps. */\n\tprofiles?: string[];\n\trestart?: string;\n\tentrypoint?: string;\n\tcommand?: string;\n\tports?: string[];\n\tenvironment?: Record<string, string>;\n\tvolumes?: string[];\n\tdepends_on?: string[];\n\thealthcheck?: {\n\t\ttest: string[];\n\t\tinterval: string;\n\t\ttimeout: string;\n\t\tretries: number;\n\t\tstart_period?: string;\n\t};\n\textra_hosts?: string[];\n}\n\nexport interface ComposeFile {\n\tname: string;\n\tservices: Record<string, ComposeService>;\n\tvolumes?: Record<string, Record<string, never>>;\n}\n\n/** The database every connection opens first: every cluster has it. */\nexport const CLUSTER_DATABASE = 'postgres';\n\nexport interface ComposeOptions {\n\t/** Names the compose project, which is what isolates it from other stacks. */\n\tproject: string;\n\t/** Ports assigned by `allocate`, keyed by port key — see `portKeys`. */\n\tports: PortAssignments;\n\t/** App services to write beside the containers — see `reconcile/apps.ts`. */\n\tapps?: Readonly<Record<string, ComposeService>>;\n\t/**\n\t * What each container is brought up with: the workspace's generated local\n\t * logins — see `localCredentials.ts` — or a stack's derived ones.\n\t */\n\tcredentials: ContainerCredentials;\n\t/**\n\t * Where MinIO posts each watched bucket's events — see `objectEvents.ts`.\n\t * Declared as MinIO's environment, so a change recreates the container.\n\t */\n\tobjectWebhooks?: readonly ObjectWebhook[];\n\t/**\n\t * Where Mailpit posts each message it receives, when an inbox is declared:\n\t * `gkm dev`'s relay, on the host. Mailpit's environment, so a change\n\t * recreates the container.\n\t */\n\tinboxRelay?: string;\n}\n\n/**\n * Build the compose document for a plan.\n *\n * Every container is published on its assigned port, never on the image's\n * default: the point of allocation is that two projects can run at once, and\n * one container publishing 5432 puts that back.\n */\nexport function composeFor(plan: Plan, options: ComposeOptions): ComposeFile {\n\tconst services: Record<string, ComposeService> = {};\n\tconst volumes: Record<string, Record<string, never>> = {};\n\n\tfor (const container of [...plan.containers].sort()) {\n\t\t// A declared version beats the default image, so the container a\n\t\t// developer runs is the major the declaration names — and the same one a\n\t\t// deploy provisions. An image pin is the project's own\n\t\t// `docker-compose.yml`, merged over this file, and wins over both.\n\t\t//\n\t\t// A database can name its own image (PostGIS, pgvector). The local\n\t\t// cluster is shared, so that image runs every database in it — and two\n\t\t// databases naming different ones cannot both have theirs.\n\t\tconst declared =\n\t\t\tcontainer === 'postgres'\n\t\t\t\t? plan.resources.find((r) => r.version)?.version\n\t\t\t\t: undefined;\n\t\tconst named =\n\t\t\tcontainer === 'postgres' ? declaredPostgresImage(plan) : undefined;\n\n\t\tconst fake = plan.fakes?.[container];\n\t\tconst image =\n\t\t\tnamed ??\n\t\t\t(declared\n\t\t\t\t? postgresImage(declared)\n\t\t\t\t: (fake?.image ?? DEFAULT_IMAGES[container]));\n\t\tif (!image) throw new UnknownContainer(container);\n\n\t\tconst published = publish(container, options.ports, plan.fakes);\n\t\tservices[container] = fake\n\t\t\t? // An external API's fake: the provider's image, as it ships. It has\n\t\t\t\t// no volume — a fake keeps nothing worth keeping — and no\n\t\t\t\t// healthcheck, so running is what ready means.\n\t\t\t\t{ image, restart: 'unless-stopped', ports: published }\n\t\t\t: define(container, image, published, options.credentials);\n\n\t\tconst volume = volumeOf(container);\n\t\tif (volume) volumes[volume] = {};\n\t}\n\n\tconst minio = services.minio;\n\tif (minio && options.objectWebhooks?.length) {\n\t\tminio.environment = {\n\t\t\t...minio.environment,\n\t\t\t...minioWebhookEnv(options.objectWebhooks),\n\t\t};\n\t\t// Locally it posts to a process on the host, which Docker Desktop\n\t\t// resolves on its own and Linux needs mapped.\n\t\tif (\n\t\t\toptions.objectWebhooks.some((hook) =>\n\t\t\t\thook.endpoint.includes(`//${HOST_GATEWAY}:`),\n\t\t\t)\n\t\t) {\n\t\t\tminio.extra_hosts = [`${HOST_GATEWAY}:host-gateway`];\n\t\t}\n\t}\n\n\tconst mailpit = services.mailpit;\n\tif (mailpit && options.inboxRelay) {\n\t\tmailpit.environment = {\n\t\t\t...mailpit.environment,\n\t\t\tMP_WEBHOOK_URL: options.inboxRelay,\n\t\t};\n\t\tif (options.inboxRelay.includes(`//${HOST_GATEWAY}:`)) {\n\t\t\tmailpit.extra_hosts = [`${HOST_GATEWAY}:host-gateway`];\n\t\t}\n\t}\n\n\treturn {\n\t\t// Compose derives a project name from the directory otherwise, so two\n\t\t// checkouts of the same repo would fight over one set of containers.\n\t\tname: options.project,\n\t\tservices: { ...services, ...options.apps },\n\t\t...(Object.keys(volumes).length ? { volumes } : {}),\n\t};\n}\n\n/** Render a compose document as the file it becomes. */\nexport function toYaml(file: ComposeFile): string {\n\treturn `# Generated by gkm from the construct manifest — do not edit.\n# Containers are derived from what the app declares. Image pins and anything\n# no construct implies go in your own docker-compose.yml, which is merged over\n# this file and wins:\n#\n# docker compose -f docker-compose.constructs.yml -f docker-compose.yml …\n#\n# \"gkm dev\" and \"gkm test\" start the containers. The apps sit behind the\n# \"apps\" profile: run \"gkm setup\", then\n# docker compose -f docker-compose.constructs.yml --profile apps up --build\n${stringify(file, { lineWidth: 0 })}`;\n}\n\n/** A container with no image, from config or from the defaults. */\n/**\n * The image the databases in the plan named for the shared local cluster, if\n * any did.\n */\nfunction declaredPostgresImage(plan: Plan): string | undefined {\n\tconst named = plan.resources.filter(\n\t\t(r): r is typeof r & { image: string } =>\n\t\t\tr.kind === 'database' && Boolean(r.image),\n\t);\n\tconst images = [...new Set(named.map((r) => r.image))];\n\n\tif (images.length > 1) {\n\t\tthrow new ConflictingPostgresImages(\n\t\t\tnamed.map((r) => ({ id: r.id, image: r.image })),\n\t\t);\n\t}\n\n\treturn images[0];\n}\n\n/** Two databases on the one local cluster named different images for it. */\nexport class ConflictingPostgresImages extends Error {\n\tconstructor(readonly databases: readonly { id: string; image: string }[]) {\n\t\tsuper(\n\t\t\t`Locally every database runs in one Postgres container, and these ` +\n\t\t\t\t`name different images for it: ` +\n\t\t\t\t`${databases.map((d) => `${d.id} (${d.image})`).join(', ')}. ` +\n\t\t\t\t`Give them the same image — one that ships every extension they ` +\n\t\t\t\t`declare.`,\n\t\t);\n\t\tthis.name = 'ConflictingPostgresImages';\n\t}\n}\n\nexport class UnknownContainer extends Error {\n\t/** The container that could not be resolved. */\n\treadonly container: string;\n\t/** The containers that have a default, so the caller can see the set. */\n\treadonly known: readonly string[] = Object.keys(DEFAULT_IMAGES).sort();\n\n\tconstructor(container: string) {\n\t\tsuper('No image is known for this container; pin one in config');\n\t\tthis.name = 'UnknownContainer';\n\t\tthis.container = container;\n\t}\n}\n\n/** One container's definition, published on the port it was assigned. */\nfunction define(\n\tcontainer: string,\n\timage: string,\n\tpublished: string[],\n\tcredentials: ContainerCredentials,\n): ComposeService {\n\tswitch (container) {\n\t\tcase 'postgres':\n\t\t\treturn {\n\t\t\t\timage,\n\t\t\t\trestart: 'unless-stopped',\n\t\t\t\tports: published,\n\t\t\t\tenvironment: {\n\t\t\t\t\t// Read only when the volume is first initialised. A volume made\n\t\t\t\t\t// with another login is rotated to this one by reconcile — see\n\t\t\t\t\t// `logins.ts` — rather than being trusted to follow.\n\t\t\t\t\tPOSTGRES_USER: credentials.postgres.user,\n\t\t\t\t\tPOSTGRES_PASSWORD: credentials.postgres.password,\n\t\t\t\t\t// Every declared database is created inside this cluster by the\n\t\t\t\t\t// applier, not by the image; connections open `postgres` first.\n\t\t\t\t\tPOSTGRES_DB: CLUSTER_DATABASE,\n\t\t\t\t},\n\t\t\t\t// One mount at the parent, not at `data`: the 18 image keeps its\n\t\t\t\t// cluster in a version-named subdirectory and refuses to start when\n\t\t\t\t// something is mounted over the legacy path. Mounting the parent is\n\t\t\t\t// also what makes the next major bump a `pg_upgrade --link` rather\n\t\t\t\t// than a new volume.\n\t\t\t\tvolumes: ['postgres-data:/var/lib/postgresql'],\n\t\t\t\thealthcheck: {\n\t\t\t\t\ttest: [\n\t\t\t\t\t\t'CMD-SHELL',\n\t\t\t\t\t\t`pg_isready -U ${credentials.postgres.user} -d ${CLUSTER_DATABASE}`,\n\t\t\t\t\t],\n\t\t\t\t\tinterval: '5s',\n\t\t\t\t\ttimeout: '3s',\n\t\t\t\t\tretries: 10,\n\t\t\t\t\tstart_period: '10s',\n\t\t\t\t},\n\t\t\t};\n\n\t\tcase 'minio':\n\t\t\treturn {\n\t\t\t\timage,\n\t\t\t\trestart: 'unless-stopped',\n\t\t\t\tports: published,\n\t\t\t\tenvironment: {\n\t\t\t\t\t// Read on every start, so a changed login takes effect when the\n\t\t\t\t\t// container is recreated with it; the buckets stay.\n\t\t\t\t\tMINIO_ROOT_USER: credentials.minio.user,\n\t\t\t\t\tMINIO_ROOT_PASSWORD: credentials.minio.password,\n\t\t\t\t},\n\t\t\t\t// No bucket is created here: buckets are planned resources, and\n\t\t\t\t// creating them in the entrypoint would put their names back in the\n\t\t\t\t// compose file — the declaration this change removes.\n\t\t\t\tcommand: 'server --console-address \":9001\" /data',\n\t\t\t\tvolumes: ['minio-data:/data'],\n\t\t\t\thealthcheck: {\n\t\t\t\t\ttest: ['CMD', 'mc', 'ready', 'local'],\n\t\t\t\t\tinterval: '10s',\n\t\t\t\t\ttimeout: '5s',\n\t\t\t\t\tretries: 5,\n\t\t\t\t\tstart_period: '10s',\n\t\t\t\t},\n\t\t\t};\n\n\t\tcase 'caddy':\n\t\t\treturn {\n\t\t\t\timage,\n\t\t\t\trestart: 'unless-stopped',\n\t\t\t\tports: published,\n\t\t\t\t// Relative to this file, which is at the project root, so the\n\t\t\t\t// mount resolves into `.gkm/` wherever the project lives.\n\t\t\t\tvolumes: [\n\t\t\t\t\t'./.gkm/Caddyfile:/etc/caddy/Caddyfile:ro',\n\t\t\t\t\t// A directory, not a file: every stage writes its own routes into\n\t\t\t\t\t// it, so `gkm test` cannot delete what `gkm dev` is serving.\n\t\t\t\t\t'./.gkm/caddy-sites:/etc/caddy/sites:ro',\n\t\t\t\t\t'caddy-data:/data',\n\t\t\t\t],\n\t\t\t\t// A surface and a site are processes on the *host*, not containers,\n\t\t\t\t// so the edge has to leave Docker's network to reach them. Docker\n\t\t\t\t// Desktop resolves this name already; on Linux it needs saying.\n\t\t\t\textra_hosts: ['host.docker.internal:host-gateway'],\n\t\t\t\thealthcheck: {\n\t\t\t\t\ttest: ['CMD', 'caddy', 'version'],\n\t\t\t\t\tinterval: '10s',\n\t\t\t\t\ttimeout: '5s',\n\t\t\t\t\tretries: 5,\n\t\t\t\t},\n\t\t\t};\n\n\t\tcase 'mailpit':\n\t\t\treturn {\n\t\t\t\timage,\n\t\t\t\trestart: 'unless-stopped',\n\t\t\t\tports: published,\n\t\t\t\tenvironment: {\n\t\t\t\t\t// Accept mail from anything on this network. The URL carries no\n\t\t\t\t\t// credentials locally, which is what the parser's optional `auth`\n\t\t\t\t\t// exists for.\n\t\t\t\t\tMP_SMTP_AUTH_ACCEPT_ANY: '1',\n\t\t\t\t\tMP_SMTP_AUTH_ALLOW_INSECURE: '1',\n\t\t\t\t},\n\t\t\t\thealthcheck: {\n\t\t\t\t\ttest: ['CMD', 'wget', '-q', '--spider', 'http://localhost:8025'],\n\t\t\t\t\tinterval: '10s',\n\t\t\t\t\ttimeout: '5s',\n\t\t\t\t\tretries: 5,\n\t\t\t\t},\n\t\t\t};\n\n\t\tcase 'redis':\n\t\t\treturn {\n\t\t\t\timage,\n\t\t\t\trestart: 'unless-stopped',\n\t\t\t\tports: published,\n\t\t\t\t// The password from the environment, by name, so it is not in the\n\t\t\t\t// container's arguments; `$$` is compose's escape for `$`.\n\t\t\t\t// Through the image's own entrypoint, so it still drops to `redis`.\n\t\t\t\tcommand:\n\t\t\t\t\t'sh -c \\'exec docker-entrypoint.sh redis-server --requirepass \"$$REDIS_PASSWORD\"\\'',\n\t\t\t\tenvironment: {\n\t\t\t\t\tREDIS_PASSWORD: credentials.redis.password,\n\t\t\t\t\t// What `redis-cli` signs in with — the health check's.\n\t\t\t\t\tREDISCLI_AUTH: credentials.redis.password,\n\t\t\t\t},\n\t\t\t\tvolumes: ['redis-data:/data'],\n\t\t\t\thealthcheck: {\n\t\t\t\t\t// Unauthenticated, a ping answers NOAUTH, which is not PONG.\n\t\t\t\t\ttest: ['CMD-SHELL', 'redis-cli ping | grep -q PONG'],\n\t\t\t\t\tinterval: '5s',\n\t\t\t\t\ttimeout: '3s',\n\t\t\t\t\tretries: 5,\n\t\t\t\t},\n\t\t\t};\n\n\t\tcase 'redis-http':\n\t\t\treturn {\n\t\t\t\timage,\n\t\t\t\trestart: 'unless-stopped',\n\t\t\t\tports: published,\n\t\t\t\tenvironment: {\n\t\t\t\t\tSRH_MODE: 'env',\n\t\t\t\t\tSRH_TOKEN: credentials.cacheToken,\n\t\t\t\t\t// The Redis beside it, by compose service name — the one address\n\t\t\t\t\t// in this file that is not published, because nothing outside the\n\t\t\t\t\t// network speaks to it.\n\t\t\t\t\tSRH_CONNECTION_STRING: `redis://:${encodeURIComponent(credentials.redis.password)}@redis:6379`,\n\t\t\t\t},\n\t\t\t\tdepends_on: ['redis'],\n\t\t\t\thealthcheck: {\n\t\t\t\t\t// 127.0.0.1, not localhost: the proxy binds IPv4 only, and\n\t\t\t\t\t// `localhost` resolves to ::1 first inside the container — which\n\t\t\t\t\t// is a health check that never passes and a container that never\n\t\t\t\t\t// comes up.\n\t\t\t\t\ttest: [\n\t\t\t\t\t\t'CMD',\n\t\t\t\t\t\t'wget',\n\t\t\t\t\t\t'-q',\n\t\t\t\t\t\t'-O',\n\t\t\t\t\t\t'/dev/null',\n\t\t\t\t\t\t'http://127.0.0.1:80/',\n\t\t\t\t\t],\n\t\t\t\t\tinterval: '5s',\n\t\t\t\t\ttimeout: '3s',\n\t\t\t\t\tretries: 10,\n\t\t\t\t},\n\t\t\t};\n\n\t\tcase 'rabbitmq':\n\t\t\treturn {\n\t\t\t\timage,\n\t\t\t\trestart: 'unless-stopped',\n\t\t\t\tports: published,\n\t\t\t\tenvironment: {\n\t\t\t\t\t// Read only when the volume is first initialised; reconcile\n\t\t\t\t\t// brings an older volume's users in line — see `logins.ts`.\n\t\t\t\t\tRABBITMQ_DEFAULT_USER: credentials.rabbitmq.user,\n\t\t\t\t\tRABBITMQ_DEFAULT_PASS: credentials.rabbitmq.password,\n\t\t\t\t},\n\t\t\t\tvolumes: ['rabbitmq-data:/var/lib/rabbitmq'],\n\t\t\t\thealthcheck: {\n\t\t\t\t\ttest: ['CMD', 'rabbitmq-diagnostics', '-q', 'ping'],\n\t\t\t\t\tinterval: '10s',\n\t\t\t\t\ttimeout: '5s',\n\t\t\t\t\tretries: 5,\n\t\t\t\t},\n\t\t\t};\n\n\t\tcase 'localstack':\n\t\t\treturn {\n\t\t\t\timage,\n\t\t\t\trestart: 'unless-stopped',\n\t\t\t\tports: published,\n\t\t\t\t// SNS pushes to subscribers on the host — the dev server — and only\n\t\t\t\t// Docker Desktop resolves host.docker.internal on its own. On Linux\n\t\t\t\t// the name has to be mapped, or every push is refused.\n\t\t\t\textra_hosts: ['host.docker.internal:host-gateway'],\n\t\t\t\tenvironment: {\n\t\t\t\t\tAWS_DEFAULT_REGION: EMULATOR_REGION,\n\t\t\t\t\tAWS_ACCESS_KEY_ID: credentials.emulator.accessKeyId,\n\t\t\t\t\tAWS_SECRET_ACCESS_KEY: credentials.emulator.secretAccessKey,\n\t\t\t\t},\n\t\t\t\tvolumes: ['localstack-data:/var/lib/localstack'],\n\t\t\t\thealthcheck: {\n\t\t\t\t\t// Bash, not curl: the floci image ships no curl, so a curl check\n\t\t\t\t\t// never passes and `--wait` fails every start. A TCP connect is\n\t\t\t\t\t// the fact a waiter needs — the gateway binds the port once its\n\t\t\t\t\t// HTTP server is up — and the repo's own compose file does the\n\t\t\t\t\t// same.\n\t\t\t\t\ttest: ['CMD', 'bash', '-c', 'exec 3<>/dev/tcp/localhost/4566'],\n\t\t\t\t\tinterval: '10s',\n\t\t\t\t\ttimeout: '5s',\n\t\t\t\t\tretries: 5,\n\t\t\t\t\tstart_period: '10s',\n\t\t\t\t},\n\t\t\t};\n\n\t\tcase 'openobserve': {\n\t\t\t// The compose stack's own service, with the local stage's login and\n\t\t\t// the default retention — what `gkm compose` on the local stage runs.\n\t\t\tconst login = credentials.logs;\n\t\t\treturn {\n\t\t\t\timage,\n\t\t\t\trestart: 'unless-stopped',\n\t\t\t\tports: published,\n\t\t\t\tenvironment: {\n\t\t\t\t\t[LOGS_EMAIL_KEY]: login.email,\n\t\t\t\t\t[LOGS_PASSWORD_KEY]: login.password,\n\t\t\t\t\tZO_DATA_DIR: '/data',\n\t\t\t\t\tZO_COMPACT_DATA_RETENTION_DAYS: String(LOGS_RETENTION_DAYS),\n\t\t\t\t\t// A local log store does not report home.\n\t\t\t\t\tZO_TELEMETRY: 'false',\n\t\t\t\t},\n\t\t\t\tvolumes: ['openobserve-data:/data'],\n\t\t\t\t// The image has no shell, `wget` or `curl`: its own binary asks the\n\t\t\t\t// running server for its status.\n\t\t\t\thealthcheck: {\n\t\t\t\t\ttest: ['CMD', '/openobserve', 'node', 'status'],\n\t\t\t\t\tinterval: '10s',\n\t\t\t\t\ttimeout: '5s',\n\t\t\t\t\tretries: 12,\n\t\t\t\t\tstart_period: '20s',\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\tdefault:\n\t\t\tthrow new UnknownContainer(container);\n\t}\n}\n\n/**\n * The published port mappings for a container.\n *\n * Every port is looked up by its own key rather than being derived as an offset\n * from the container's first, so MinIO's console cannot land on whatever was\n * allocated to the next container.\n */\nfunction publish(\n\tcontainer: string,\n\tports: PortAssignments,\n\tfakes?: Plan['fakes'],\n): string[] {\n\treturn portsOf(container, fakes).map((port) => {\n\t\tconst assigned = ports[port.key];\n\t\tif (assigned === undefined) throw new UnassignedPort(port.key);\n\n\t\treturn `${assigned}:${port.inside}`;\n\t});\n}\n\n/** A planned port that allocation never assigned. */\nexport class UnassignedPort extends Error {\n\t/** The port key that went unassigned, e.g. `minio-console`. */\n\treadonly key: string;\n\n\tconstructor(key: string) {\n\t\tsuper('No port was assigned for this container port');\n\t\tthis.name = 'UnassignedPort';\n\t\tthis.key = key;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,SAAgB,SACf,OACqB;CACrB,IAAI,MAAM,WAAW,GAAG,OAAO,KAAA;CAG/B,IAAI,MAAM,WAAW,GAAG,OAAO,MAAM,EAAE,CAAE;CAGzC,IAAI,MAAM,MAAM,EAAE,WAAW,SAAS,KAAK,GAAG,OAAO;CAGrD,MAAM,WAAW,MAAM,QAAQ,EAAE,WAAW,SAAS,IAAI;CACzD,IAAI,SAAS,WAAW,GAAG,OAAO,SAAS,EAAE,CAAE;CAE/C,MAAM,IAAI,kBACT,MAAM,KAAK,EAAE,WAAW,IAAI,GAC5B,SAAS,SAAS,CACnB;AACD;;AAGA,IAAa,oBAAb,cAAuC,SAAS;CAErC;CACA;CAFV,YACC,OACA,UAAmB,OAClB;EACD,MACC,UACG,gDAAgD,MAAM,KAAK,IAAI,EAAE,4CAEjE,GAAG,MAAM,OAAO,uDACL,MAAM,KAAK,IAAI,EAAE,uLAIhC;EAZS,KAAA,QAAA;EACA,KAAA,UAAA;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