create-ailk 0.37.1 → 0.39.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (318) hide show
  1. package/README.md +129 -0
  2. package/component-catalog.json +44 -6
  3. package/component-catalog.md +6 -5
  4. package/dist/add-module.js +16 -1
  5. package/dist/add-route.d.ts +2 -2
  6. package/dist/add-route.js +19 -12
  7. package/dist/cli.js +52 -0
  8. package/dist/declined-routes.d.ts +13 -0
  9. package/dist/declined-routes.js +74 -0
  10. package/dist/derive-architecture.d.ts +0 -6
  11. package/dist/derive-architecture.js +12 -16
  12. package/dist/index.d.ts +1 -0
  13. package/dist/index.js +3 -0
  14. package/dist/language-import.d.ts +93 -0
  15. package/dist/language-import.js +270 -43
  16. package/dist/lib/import-mdx.js +1 -1
  17. package/dist/lib/scaffold-render-sweep.d.ts +6 -3
  18. package/dist/lib/scaffold-render-sweep.js +8 -4
  19. package/dist/migrate-content.d.ts +6 -2
  20. package/dist/migrate-content.js +62 -5
  21. package/dist/module-architecture.js +139 -103
  22. package/dist/paid-sections.d.ts +13 -0
  23. package/dist/paid-sections.js +35 -5
  24. package/dist/programmatic.js +6 -16
  25. package/dist/remove-module.js +73 -2
  26. package/dist/routes.d.ts +130 -0
  27. package/dist/routes.js +954 -0
  28. package/dist/site-manifest.js +6 -4
  29. package/dist/site-roster.d.ts +11 -2
  30. package/dist/site-roster.js +63 -21
  31. package/dist/spoke-checkout.d.ts +28 -27
  32. package/dist/spoke-checkout.js +71 -102
  33. package/dist/surfaces.d.ts +26 -0
  34. package/dist/surfaces.js +105 -293
  35. package/dist/sync-routes.d.ts +14 -1
  36. package/dist/sync-routes.js +108 -10
  37. package/dist/template-record.js +3 -1
  38. package/dist/topology.d.ts +26 -1
  39. package/dist/topology.js +273 -7
  40. package/dist/update.d.ts +17 -2
  41. package/dist/update.js +480 -77
  42. package/package.json +3 -3
  43. package/templates/README.md +1 -1
  44. package/templates/apps/mcp/CLAUDE.md +5 -3
  45. package/templates/apps/web/CLAUDE.md +87 -23
  46. package/templates/apps/web/__tests__/__mocks__/next-intl-server.ts +5 -1
  47. package/templates/apps/web/__tests__/__mocks__/next-intl.ts +5 -1
  48. package/templates/apps/web/__tests__/auth/seam.test.ts +34 -0
  49. package/templates/apps/web/account.config.tsx +100 -0
  50. package/templates/apps/web/app/[locale]/(authed)/account/connect/__tests__/page.test.tsx +1 -1
  51. package/templates/apps/web/app/[locale]/(authed)/account/connect/page.tsx +2 -2
  52. package/templates/apps/web/app/[locale]/(authed)/signed-out-gate.generated.tsx +1 -1
  53. package/templates/apps/web/app/[locale]/layout.tsx +46 -29
  54. package/templates/apps/web/app/apple-icon.tsx +72 -0
  55. package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +22 -12
  56. package/templates/apps/web/app/og/__tests__/__snapshots__/card.test.tsx.snap +3 -0
  57. package/templates/apps/web/app/og/__tests__/card.test.tsx +129 -0
  58. package/templates/apps/web/app/og/__tests__/route.test.ts +3 -4
  59. package/templates/apps/web/app/og/route.tsx +155 -72
  60. package/templates/apps/web/app/sitemap.xml/__tests__/site-listing.test.ts +12 -0
  61. package/templates/apps/web/auth.config.tsx +107 -0
  62. package/templates/apps/web/auth.ts +2 -1
  63. package/templates/apps/web/i18n/request.ts +51 -1
  64. package/templates/apps/web/jest.config.cjs +17 -1
  65. package/templates/apps/web/lib/__tests__/auth-phone.test.ts +11 -0
  66. package/templates/apps/web/lib/__tests__/fixtures/site-topology.ts +73 -0
  67. package/templates/apps/web/lib/__tests__/nav-label-keys.test.ts +14 -0
  68. package/templates/apps/web/lib/__tests__/profile-back-link.test.ts +148 -61
  69. package/templates/apps/web/lib/__tests__/served-pages.test.ts +77 -0
  70. package/templates/apps/web/lib/__tests__/server-api.test.ts +37 -5
  71. package/templates/apps/web/lib/__tests__/structured-data.test.tsx +26 -13
  72. package/templates/apps/web/lib/listings.tsx +2 -2
  73. package/templates/apps/web/lib/nav-label-keys.ts +16 -2
  74. package/templates/apps/web/lib/paid-section-contracts.ts +35 -6
  75. package/templates/apps/web/lib/paid-sections.generated.ts +8 -0
  76. package/templates/apps/web/lib/profile-back-link.ts +105 -32
  77. package/templates/apps/web/lib/served-pages.ts +95 -0
  78. package/templates/apps/web/lib/server-api.ts +1 -1
  79. package/templates/apps/web/lib/site-brand.tsx +3 -5
  80. package/templates/apps/web/lib/topology.generated.ts +5 -0
  81. package/templates/apps/web/messages/en.json +8 -836
  82. package/templates/apps/web/middleware.ts +15 -26
  83. package/templates/apps/web/next.config.mjs +35 -0
  84. package/templates/apps/web/package.json +2 -0
  85. package/templates/apps/web/types/messages.d.ts +6 -1
  86. package/templates/customizations.yaml +9 -0
  87. package/templates/package.json +3 -1
  88. package/templates/tools/lint-architecture.ts +164 -11
  89. package/versions.json +49 -47
  90. package/templates/apps/web/app/[locale]/(auth)/__tests__/auth-pages.test.tsx +0 -322
  91. package/templates/apps/web/app/[locale]/(auth)/__tests__/password-reset.test.tsx +0 -554
  92. package/templates/apps/web/app/[locale]/(auth)/consent/__tests__/consent-actions.test.ts +0 -56
  93. package/templates/apps/web/app/[locale]/(auth)/consent/__tests__/page.test.tsx +0 -164
  94. package/templates/apps/web/app/[locale]/(auth)/consent/consent-form.tsx +0 -132
  95. package/templates/apps/web/app/[locale]/(auth)/consent/consent.actions.ts +0 -51
  96. package/templates/apps/web/app/[locale]/(auth)/consent/page.tsx +0 -144
  97. package/templates/apps/web/app/[locale]/(auth)/forgot-password/forgot-password-card.tsx +0 -101
  98. package/templates/apps/web/app/[locale]/(auth)/forgot-password/page.tsx +0 -111
  99. package/templates/apps/web/app/[locale]/(auth)/layout.tsx +0 -81
  100. package/templates/apps/web/app/[locale]/(auth)/legal-footnote.tsx +0 -35
  101. package/templates/apps/web/app/[locale]/(auth)/reset-password/__tests__/return.test.tsx +0 -179
  102. package/templates/apps/web/app/[locale]/(auth)/reset-password/page.tsx +0 -157
  103. package/templates/apps/web/app/[locale]/(auth)/reset-password/reset-password-card.tsx +0 -126
  104. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/next-path.test.ts +0 -54
  105. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/page.test.tsx +0 -628
  106. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/remembered-method.test.ts +0 -43
  107. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/sign-in-card.test.tsx +0 -266
  108. package/templates/apps/web/app/[locale]/(auth)/sign-in/next-path.ts +0 -20
  109. package/templates/apps/web/app/[locale]/(auth)/sign-in/page.tsx +0 -234
  110. package/templates/apps/web/app/[locale]/(auth)/sign-in/remembered-method.ts +0 -37
  111. package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-card.tsx +0 -323
  112. package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-text.ts +0 -93
  113. package/templates/apps/web/app/[locale]/(auth)/sign-up/__tests__/page.test.tsx +0 -301
  114. package/templates/apps/web/app/[locale]/(auth)/sign-up/__tests__/sign-up-card.test.tsx +0 -309
  115. package/templates/apps/web/app/[locale]/(auth)/sign-up/page.tsx +0 -201
  116. package/templates/apps/web/app/[locale]/(auth)/sign-up/sign-up-card.tsx +0 -366
  117. package/templates/apps/web/app/[locale]/(auth)/use-auth-card-flow.ts +0 -116
  118. package/templates/apps/web/app/[locale]/(auth)/verify-email/__tests__/actions.test.ts +0 -94
  119. package/templates/apps/web/app/[locale]/(auth)/verify-email/actions.ts +0 -77
  120. package/templates/apps/web/app/[locale]/(auth)/verify-email/page.tsx +0 -154
  121. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/account-frame-sign-out.test.tsx +0 -175
  122. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/agreements-prompt.test.tsx +0 -301
  123. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/billing.test.tsx +0 -515
  124. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/general.test.tsx +0 -883
  125. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +0 -758
  126. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/item.test.tsx +0 -264
  127. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout-sign-out.test.tsx +0 -167
  128. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout.test.tsx +0 -730
  129. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-menu.test.tsx +0 -355
  130. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-popups.test.tsx +0 -97
  131. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/notifications.test.tsx +0 -375
  132. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/onboarding.test.tsx +0 -323
  133. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +0 -1208
  134. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/popups.test.tsx +0 -418
  135. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/privacy.test.tsx +0 -462
  136. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/rich-translator.ts +0 -63
  137. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/security.test.tsx +0 -406
  138. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/settings.test.tsx +0 -93
  139. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/support.test.tsx +0 -208
  140. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/thread.test.tsx +0 -340
  141. package/templates/apps/web/app/[locale]/(authed)/account/account-data.ts +0 -182
  142. package/templates/apps/web/app/[locale]/(authed)/account/account-frame.tsx +0 -353
  143. package/templates/apps/web/app/[locale]/(authed)/account/actions.ts +0 -57
  144. package/templates/apps/web/app/[locale]/(authed)/account/agreements-actions.ts +0 -58
  145. package/templates/apps/web/app/[locale]/(authed)/account/agreements-gate.ts +0 -61
  146. package/templates/apps/web/app/[locale]/(authed)/account/agreements-prompt.tsx +0 -184
  147. package/templates/apps/web/app/[locale]/(authed)/account/appointments/[slug]/page.tsx +0 -161
  148. package/templates/apps/web/app/[locale]/(authed)/account/appointments/__tests__/page.test.tsx +0 -426
  149. package/templates/apps/web/app/[locale]/(authed)/account/appointments/appointments-data.ts +0 -76
  150. package/templates/apps/web/app/[locale]/(authed)/account/appointments/page.tsx +0 -139
  151. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/page.tsx +0 -406
  152. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/pay-form.tsx +0 -65
  153. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/review-form.tsx +0 -172
  154. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/versions/[version]/file/route.ts +0 -190
  155. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/file-route.test.ts +0 -333
  156. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/page.test.tsx +0 -936
  157. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/pay.test.tsx +0 -193
  158. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/review.test.tsx +0 -476
  159. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-actions.ts +0 -184
  160. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-data.ts +0 -197
  161. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/page.tsx +0 -182
  162. package/templates/apps/web/app/[locale]/(authed)/account/billing/__tests__/offerings.test.ts +0 -99
  163. package/templates/apps/web/app/[locale]/(authed)/account/billing/offerings.ts +0 -123
  164. package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +0 -424
  165. package/templates/apps/web/app/[locale]/(authed)/account/billing-source.ts +0 -303
  166. package/templates/apps/web/app/[locale]/(authed)/account/components/request-quote.tsx +0 -274
  167. package/templates/apps/web/app/[locale]/(authed)/account/error-row.tsx +0 -35
  168. package/templates/apps/web/app/[locale]/(authed)/account/for-you-labels.ts +0 -36
  169. package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/phone-verification.test.tsx +0 -215
  170. package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/seam-imports.test.ts +0 -65
  171. package/templates/apps/web/app/[locale]/(authed)/account/general/account-name.ts +0 -36
  172. package/templates/apps/web/app/[locale]/(authed)/account/general/billing-anchor.tsx +0 -27
  173. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-actions.ts +0 -149
  174. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-details.tsx +0 -42
  175. package/templates/apps/web/app/[locale]/(authed)/account/general/deletion-request.tsx +0 -132
  176. package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +0 -218
  177. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-actions.ts +0 -122
  178. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-verification.tsx +0 -215
  179. package/templates/apps/web/app/[locale]/(authed)/account/general/photo-actions.ts +0 -73
  180. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-form.tsx +0 -107
  181. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-source.ts +0 -87
  182. package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +0 -119
  183. package/templates/apps/web/app/[locale]/(authed)/account/inbox/message/[id]/file/__tests__/route.test.ts +0 -215
  184. package/templates/apps/web/app/[locale]/(authed)/account/inbox/message/[id]/file/route.ts +0 -80
  185. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/member-thread-composer.tsx +0 -43
  186. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/page.tsx +0 -125
  187. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-data.ts +0 -88
  188. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-write.ts +0 -31
  189. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/invitation-id.test.ts +0 -35
  190. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/page.test.tsx +0 -266
  191. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/actions.ts +0 -116
  192. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/invitation-id.ts +0 -12
  193. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/page.tsx +0 -154
  194. package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +0 -152
  195. package/templates/apps/web/app/[locale]/(authed)/account/new-actions.ts +0 -219
  196. package/templates/apps/web/app/[locale]/(authed)/account/new-menu.tsx +0 -365
  197. package/templates/apps/web/app/[locale]/(authed)/account/new-popups.tsx +0 -86
  198. package/templates/apps/web/app/[locale]/(authed)/account/notifications/page.tsx +0 -143
  199. package/templates/apps/web/app/[locale]/(authed)/account/onboarding/actions.ts +0 -120
  200. package/templates/apps/web/app/[locale]/(authed)/account/onboarding/onboarding-form.tsx +0 -322
  201. package/templates/apps/web/app/[locale]/(authed)/account/onboarding/page.tsx +0 -126
  202. package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +0 -306
  203. package/templates/apps/web/app/[locale]/(authed)/account/privacy/__tests__/export-route.test.ts +0 -173
  204. package/templates/apps/web/app/[locale]/(authed)/account/privacy/actions.ts +0 -103
  205. package/templates/apps/web/app/[locale]/(authed)/account/privacy/export/route.ts +0 -102
  206. package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +0 -240
  207. package/templates/apps/web/app/[locale]/(authed)/account/profile-actions.ts +0 -116
  208. package/templates/apps/web/app/[locale]/(authed)/account/retry-button.tsx +0 -27
  209. package/templates/apps/web/app/[locale]/(authed)/account/security/__tests__/hub-variant.test.tsx +0 -258
  210. package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +0 -131
  211. package/templates/apps/web/app/[locale]/(authed)/account/security/security-panel.tsx +0 -130
  212. package/templates/apps/web/app/[locale]/(authed)/account/security/security-source.ts +0 -92
  213. package/templates/apps/web/app/[locale]/(authed)/account/settings/page.tsx +0 -24
  214. package/templates/apps/web/app/[locale]/(authed)/account/settings-frame.tsx +0 -121
  215. package/templates/apps/web/app/[locale]/(authed)/account/sign-in-method.ts +0 -37
  216. package/templates/apps/web/app/[locale]/(authed)/account/support/page.tsx +0 -60
  217. package/templates/apps/web/app/[locale]/(authed)/account/support/support-form.tsx +0 -98
  218. package/templates/apps/web/app/[locale]/(authed)/account/support-actions.ts +0 -100
  219. package/templates/apps/web/app/[locale]/checkout/__tests__/pages.test.tsx +0 -139
  220. package/templates/apps/web/app/[locale]/checkout/__tests__/thank-you-account.test.tsx +0 -146
  221. package/templates/apps/web/app/[locale]/checkout/thank-you/page.tsx +0 -114
  222. package/templates/apps/web/app/[locale]/checkout/unavailable/page.tsx +0 -51
  223. package/templates/apps/web/app/[locale]/flows/[slug]/FlowStepperClient.tsx +0 -614
  224. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.count.test.tsx +0 -43
  225. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.deliverable.test.tsx +0 -214
  226. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.ending.test.tsx +0 -197
  227. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.invite.test.tsx +0 -286
  228. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.permalink.test.tsx +0 -520
  229. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.test.tsx +0 -376
  230. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.thanks-by-tier.test.tsx +0 -306
  231. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/account-invite.actions.test.ts +0 -69
  232. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/flow.actions.test.ts +0 -398
  233. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/magnet-page.test.tsx +0 -704
  234. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/save.actions.test.ts +0 -173
  235. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/two-route-tool.test.tsx +0 -141
  236. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/verify.test.tsx +0 -249
  237. package/templates/apps/web/app/[locale]/flows/[slug]/account-invite.actions.ts +0 -35
  238. package/templates/apps/web/app/[locale]/flows/[slug]/email-moment.ts +0 -92
  239. package/templates/apps/web/app/[locale]/flows/[slug]/flow.actions.ts +0 -177
  240. package/templates/apps/web/app/[locale]/flows/[slug]/magnet-page.tsx +0 -472
  241. package/templates/apps/web/app/[locale]/flows/[slug]/page.tsx +0 -48
  242. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/LevelChart.tsx +0 -100
  243. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsCard.tsx +0 -99
  244. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +0 -820
  245. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsEmailStep.tsx +0 -203
  246. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/ResultsClient.no-commerce.test.tsx +0 -194
  247. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/ResultsClient.report.test.tsx +0 -284
  248. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/by-result.test.tsx +0 -302
  249. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/cards.test.tsx +0 -402
  250. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/landing.test.tsx +0 -293
  251. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/page.test.tsx +0 -485
  252. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/score.test.tsx +0 -231
  253. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/checkout-seam.ts +0 -74
  254. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/meeting-seam.ts +0 -36
  255. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/page.tsx +0 -420
  256. package/templates/apps/web/app/[locale]/flows/[slug]/save.actions.ts +0 -85
  257. package/templates/apps/web/app/[locale]/flows/[slug]/served-flow.ts +0 -91
  258. package/templates/apps/web/app/[locale]/flows/[slug]/start/page.tsx +0 -32
  259. package/templates/apps/web/app/[locale]/flows/[slug]/verify/page.tsx +0 -153
  260. package/templates/apps/web/app/[locale]/flows/[slug]/verify.actions.ts +0 -151
  261. package/templates/apps/web/app/[locale]/meet/confirmed/BookingHandOff.tsx +0 -128
  262. package/templates/apps/web/app/[locale]/meet/confirmed/__tests__/BookingHandOff.test.tsx +0 -126
  263. package/templates/apps/web/app/[locale]/purchase/__tests__/cancel.test.tsx +0 -162
  264. package/templates/apps/web/app/[locale]/purchase/__tests__/module-scope.test.ts +0 -68
  265. package/templates/apps/web/app/[locale]/purchase/__tests__/success.test.tsx +0 -411
  266. package/templates/apps/web/app/[locale]/purchase/cancel/page.tsx +0 -115
  267. package/templates/apps/web/app/[locale]/purchase/success/page.tsx +0 -348
  268. package/templates/apps/web/app/api/auth/[...all]/route.ts +0 -16
  269. package/templates/apps/web/app/api/auth/hub/__tests__/continuation.test.ts +0 -143
  270. package/templates/apps/web/app/api/auth/hub/__tests__/entry-routes.test.ts +0 -749
  271. package/templates/apps/web/app/api/auth/hub/authorize/__tests__/route.test.ts +0 -964
  272. package/templates/apps/web/app/api/auth/hub/authorize/route.ts +0 -390
  273. package/templates/apps/web/app/api/auth/hub/continuation.ts +0 -127
  274. package/templates/apps/web/app/api/auth/hub/continue/[ref]/__tests__/route.test.ts +0 -188
  275. package/templates/apps/web/app/api/auth/hub/continue/[ref]/route.ts +0 -53
  276. package/templates/apps/web/app/api/auth/hub/email/route.ts +0 -111
  277. package/templates/apps/web/app/api/auth/hub/entry-shared.ts +0 -163
  278. package/templates/apps/web/app/api/auth/hub/password/__tests__/return.test.ts +0 -86
  279. package/templates/apps/web/app/api/auth/hub/password/__tests__/route.test.ts +0 -368
  280. package/templates/apps/web/app/api/auth/hub/password/return.ts +0 -86
  281. package/templates/apps/web/app/api/auth/hub/password/route.ts +0 -171
  282. package/templates/apps/web/app/api/auth/hub/purchase/route.ts +0 -230
  283. package/templates/apps/web/app/api/auth/hub/purchase-link/route.ts +0 -174
  284. package/templates/apps/web/app/api/auth/hub/sign-up/route.ts +0 -60
  285. package/templates/apps/web/app/api/auth/hub/sign-up-evidence.ts +0 -97
  286. package/templates/apps/web/app/api/auth/mcp/__tests__/continuation.test.ts +0 -92
  287. package/templates/apps/web/app/api/auth/mcp/continuation.ts +0 -89
  288. package/templates/apps/web/app/api/auth/mcp/continue/[ref]/__tests__/route.test.ts +0 -59
  289. package/templates/apps/web/app/api/auth/mcp/continue/[ref]/route.ts +0 -41
  290. package/templates/apps/web/app/api/hub-session/__tests__/routes.test.ts +0 -1166
  291. package/templates/apps/web/app/api/hub-session/callback/route.ts +0 -134
  292. package/templates/apps/web/app/api/hub-session/email/route.ts +0 -125
  293. package/templates/apps/web/app/api/hub-session/one-tap/nonce/route.ts +0 -49
  294. package/templates/apps/web/app/api/hub-session/one-tap/route.ts +0 -106
  295. package/templates/apps/web/app/api/hub-session/open/route.ts +0 -111
  296. package/templates/apps/web/app/api/hub-session/password/return/route.ts +0 -69
  297. package/templates/apps/web/app/api/hub-session/password/route.ts +0 -106
  298. package/templates/apps/web/app/api/hub-session/sign-in/route.ts +0 -91
  299. package/templates/apps/web/app/api/hub-session/sign-out/route.ts +0 -54
  300. package/templates/apps/web/components/sign-out-trigger.tsx +0 -62
  301. package/templates/apps/web/lib/__tests__/account-config.test.ts +0 -704
  302. package/templates/apps/web/lib/__tests__/auth-routes.test.ts +0 -140
  303. package/templates/apps/web/lib/account-config.ts +0 -678
  304. package/templates/apps/web/lib/auth-routes.ts +0 -125
  305. package/templates/apps/web/lib/checkout-config.ts +0 -16
  306. package/templates/apps/web/lib/hub-session/__tests__/hub-session.test.ts +0 -433
  307. package/templates/apps/web/lib/hub-session/__tests__/spoke-sign-in.test.tsx +0 -332
  308. package/templates/apps/web/lib/hub-session/config.ts +0 -110
  309. package/templates/apps/web/lib/hub-session/entry.ts +0 -238
  310. package/templates/apps/web/lib/hub-session/index.ts +0 -21
  311. package/templates/apps/web/lib/hub-session/one-tap.tsx +0 -148
  312. package/templates/apps/web/lib/hub-session/reseal.ts +0 -90
  313. package/templates/apps/web/lib/hub-session/seal.ts +0 -86
  314. package/templates/apps/web/lib/hub-session/session.ts +0 -298
  315. package/templates/apps/web/lib/hub-session/spoke-sign-in.tsx +0 -277
  316. package/templates/apps/web/lib/next-path.ts +0 -35
  317. package/templates/apps/web/src/lib/__tests__/commerce-sections.test.ts +0 -57
  318. package/templates/apps/web/src/lib/commerce-sections.ts +0 -55
package/dist/routes.js ADDED
@@ -0,0 +1,954 @@
1
+ /**
2
+ * `create-ailk routes --write | --check` — the one route-file generator
3
+ * (#11219; ADR 0040 rules 2, 3 and 4).
4
+ *
5
+ * A website page ships in a package. Next mounts a route tree only from the
6
+ * consuming app's `app/` directory, so a site's `apps/web/app/[locale]/`
7
+ * holds one GENERATED file per shipped route and nothing of the page's
8
+ * implementation — the Admin shell's shape
9
+ * (`packages-paid/admin/scripts/write-shell-routes.ts`), owned here once for
10
+ * every page package.
11
+ *
12
+ * Input: every installed `@working-theory/*` dependency of `apps/web` whose
13
+ * `package.json` declares `"ailk": { "routes": "<manifest path>" }`. The
14
+ * manifest (`RouteManifest`) names the package's route prefix under
15
+ * `app/[locale]` (or a list of them, #11252 — a package whose routes sit in
16
+ * more than one top-level directory), the site's config file, and one entry
17
+ * per routing file:
18
+ * its path, kind (`page` · `layout` · `route`), the exports to re-export,
19
+ * the segment-config lines to copy literally, and whether it takes the site
20
+ * config (and, with `metadataConfig` (#11253), whether its `generateMetadata`
21
+ * takes it too).
22
+ *
23
+ * Output: one file per entry — a header naming the package and version, one
24
+ * re-export per listed export, the segment-config lines, and, when the entry
25
+ * takes config, an import of the site's `<config>.tsx` passed to the page.
26
+ * Every statement names one specifier on one line, so the files are
27
+ * prettier-stable, and nothing else is written: a generated file is never
28
+ * hand-edited. A manifest that sets `"oss": false` (#11252) puts the
29
+ * `// oss: false` marker on each file's first line, before the header: a
30
+ * package outside the public tree (`packages-paid/`) generates files the
31
+ * public strip must drop with it (`scripts/check-oss-strip.sh`); in a
32
+ * scaffold the line is inert.
33
+ *
34
+ * Check mode exits 1 naming each file that is MISSING (an entry with no
35
+ * file), STALE (content differs from what would be generated — a version
36
+ * bump included, since the header names it) or STRAY (a routing file under
37
+ * the package's prefix that is neither generated nor recorded — the prefix
38
+ * is the subtree the package has taken over, and a manifest shipping no
39
+ * route owns nothing yet). A route the
40
+ * site has replaced or removed is recorded in `customizations.yaml` — an
41
+ * entry whose `paths` match the route file, in the manifest's own grammar
42
+ * (`build-in: site — …`) — and is REPORTED, never failed: a recorded route
43
+ * with a file is `replaced`, one without is `removed`, and `--write` never
44
+ * overwrites or re-creates either.
45
+ *
46
+ * A routing file the package names in its manifest's `siteOwned` list sits
47
+ * under its prefix but is the site's own page (one the package leaves to a
48
+ * later slice): it is REPORTED as kept by the site, never stray, and
49
+ * `--write` never touches it.
50
+ *
51
+ * A page package's strings ship in its own catalog (ADR 0040 rule 5), named
52
+ * by the manifest's `messages.catalog` (one `<locale>.json` per locale); a
53
+ * site's `messages/<locale>.json` holds overrides only. Check mode also
54
+ * lists each ORPHANED override — a site key under a namespace the package's
55
+ * catalog ships that the package no longer has (a site locale with no
56
+ * package catalog of its own is read against the package's `en`, as the
57
+ * site's request config falls back). Keys under the manifest's
58
+ * `messages.siteOwned` prefixes are the site's own strings, read by its own
59
+ * files, and are never overrides.
60
+ *
61
+ * A route the site's topology does not carry — a spoke without sign-in
62
+ * drops the whole `(authed)` group (`isSpokeExcluded`) — is not a route of
63
+ * that site: neither written, nor missing, nor stray; the check names it as
64
+ * not carried.
65
+ *
66
+ * The app mount (#11257 D10). A route handler a page package ships outside
67
+ * the locale segment — `/api/auth/**`, `/api/hub-session/**` — is an entry
68
+ * with `"mount": "app"`, its `path` relative to `apps/web/app/`, under one of
69
+ * the manifest's `appPrefixes`. The trust model is the same in both mounts: an
70
+ * installed `@working-theory/*` page package authors the routing files under
71
+ * the prefixes it declares, and nothing else. So an app prefix must start
72
+ * `api/`, may not be `api` itself or one of the site's own handler trees
73
+ * (`SITE_HANDLER_PREFIXES`), and may not equal, contain or sit under another
74
+ * installed manifest's; an app entry never takes the config (a route handler
75
+ * cannot). In both mounts `--write` never overwrites a routing file whose
76
+ * first line is not the generator header — a site's own handler, or a
77
+ * recorded replacement — it reports it as `kept`. An entry's `waiver` (one
78
+ * line — no newline or control character; non-ASCII text such as an em
79
+ * dash is allowed) is written as the ADR 0020 marker on the line
80
+ * after the header, and every `module` is held to a fixed character set, so
81
+ * no manifest text can inject source into a generated file.
82
+ *
83
+ * A manifest that sets `"siteSeam": true` names a package whose modules read
84
+ * the site through `<package>/site`, which the site aliases to its config
85
+ * file in `next.config.mjs` and `jest.config.cjs`; check mode names either
86
+ * file when its alias line is missing, so a build bound to the package's
87
+ * stub fails before any request (SEC-11257-1).
88
+ *
89
+ * The locale root (#11259 D5). A manifest that sets `"root": true` may list
90
+ * the entry `page.tsx` — the home page at `app/[locale]/page.tsx`; its stray
91
+ * scope there is that one file, never the tree beneath it. One installed
92
+ * manifest at most may claim the root, and no two may claim overlapping
93
+ * prefixes: each refusal names both packages.
94
+ *
95
+ * The site's surfaces (#11259 D5). A manifest that sets `"siteGated": true`
96
+ * ships routes a site carries only when it selected them. On a site whose
97
+ * `.ailk-site-manifest.json` lists no `marketing` module, an entry inside the
98
+ * public route tree (`isRemovedPublicRoutePath`) is not carried; and an entry
99
+ * whose top directory is a `GATEABLE_SURFACES` route of a surface the site's
100
+ * `architecture.yaml` `# Surfaces:` header does not list (aliases
101
+ * canonicalized) is not carried either. A site with no readable header
102
+ * carries every entry. A manifest without the flag is never gated.
103
+ *
104
+ * Pure module: no `import.meta.url`, so jest imports it directly.
105
+ */
106
+ import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
107
+ import { dirname, join, posix, relative, resolve, sep } from "node:path";
108
+ import { parseArgs } from "node:util";
109
+ import { AddModuleRefusedError, readArchitectureHeader } from "./add-module-core.js";
110
+ import { publicTreeRemoved } from "./lib/site-modules.js";
111
+ import { GATEABLE_SURFACES, ROUTE_ROOT, canonicalizeSurface, isRemovedPublicRoutePath } from "./surfaces.js";
112
+ import { isSpokeExcluded, readSpokeShape } from "./topology.js";
113
+ /** The app a page package's routes mount in, relative to the site root. */
114
+ export const ROUTES_APP_DIR = "apps/web";
115
+ /** The locale segment every shipped route sits under. */
116
+ const LOCALE_DIR = "app/[locale]";
117
+ /** The locale-root page, the one entry a `"root": true` manifest may list outside its prefixes (#11259 D5). */
118
+ const ROOT_PAGE = "page.tsx";
119
+ /** The app root an `app`-mounted entry's path is relative to (#11257 D10). */
120
+ const APP_DIR = "app";
121
+ /**
122
+ * The site's own handler trees under `app/api/`, which no page package may
123
+ * declare as an app prefix (#11257 D10, SEC-11257-3): the Offerings buy route,
124
+ * the revalidate hook, the webhook routes and the legacy checkout.
125
+ */
126
+ export const SITE_HANDLER_PREFIXES = ["api/offerings", "api/revalidate", "api/webhooks", "api/checkout"];
127
+ /** A `module` value: the characters both shipped manifests use, so no quote or backtick reaches generated source. */
128
+ const MODULE_RE = /^[A-Za-z0-9_\-./()[\]]+$/;
129
+ /**
130
+ * A `waiver`: one line of text — no control character (C0, DEL or C1) and no
131
+ * Unicode line or paragraph separator, so nothing can end the comment line it
132
+ * is written into. Not ASCII-only: the shipped waivers carry an em dash, the
133
+ * ADR 0020 marker's own form.
134
+ */
135
+ function isOneLineText(value) {
136
+ if (value === "")
137
+ return false;
138
+ for (const char of value) {
139
+ const code = char.codePointAt(0) ?? 0;
140
+ if (code < 0x20 || (code >= 0x7f && code <= 0x9f) || code === 0x2028 || code === 0x2029)
141
+ return false;
142
+ }
143
+ return true;
144
+ }
145
+ /** The `package.json` key a page package declares its manifest under. */
146
+ const MANIFEST_KEY = "ailk";
147
+ const PACKAGE_SCOPE = "@working-theory/";
148
+ const ROUTING_FILES = new Set(["page.tsx", "layout.tsx", "route.ts"]);
149
+ /** The routing file names the generator writes (`ROUTING_FILES`), for the snapshot build (#11259 D6). */
150
+ export const ROUTING_FILE_NAMES = ROUTING_FILES;
151
+ const SKIPPED_DIRS = new Set(["__tests__", "node_modules"]);
152
+ const HTTP_METHODS = new Set(["GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"]);
153
+ const KIND_OF_FILE = { "page.tsx": "page", "layout.tsx": "layout", "route.ts": "route" };
154
+ const SEGMENT_CONFIG_RE = /^export const (?:dynamic|revalidate|runtime|fetchCache|dynamicParams|preferredRegion|maxDuration) = .+;$/;
155
+ export class RoutesRefusedError extends Error {
156
+ exitCode = 2;
157
+ constructor(message) {
158
+ super(message);
159
+ this.name = "RoutesRefusedError";
160
+ }
161
+ }
162
+ function isRecord(value) {
163
+ return typeof value === "object" && value !== null && !Array.isArray(value);
164
+ }
165
+ /** A POSIX path with no `.`/`..` segment, no leading or trailing slash, as written: an installed package names no write target outside its prefix. */
166
+ function isPlainPath(value) {
167
+ return (typeof value === "string" &&
168
+ value !== "" &&
169
+ posix.normalize(value) === value &&
170
+ !value.startsWith("/") &&
171
+ !value.endsWith("/") &&
172
+ value.split("/").every((seg) => seg !== "." && seg !== ".."));
173
+ }
174
+ function stringList(value, where) {
175
+ if (value === undefined)
176
+ return [];
177
+ if (!Array.isArray(value) || !value.every((v) => typeof v === "string")) {
178
+ throw new RoutesRefusedError(`${where} must be a list of strings`);
179
+ }
180
+ return value;
181
+ }
182
+ /** Whether one of two plain paths equals the other or sits under it. */
183
+ function overlaps(a, b) {
184
+ return a === b || a.startsWith(`${b}/`) || b.startsWith(`${a}/`);
185
+ }
186
+ /** Parse and validate one manifest; every refusal names the package and the entry. */
187
+ export function parseRouteManifest(pkg, version, raw) {
188
+ const at = `${pkg}'s route manifest`;
189
+ if (!isRecord(raw))
190
+ throw new RoutesRefusedError(`${at} is not an object`);
191
+ if (raw.schema !== 1)
192
+ throw new RoutesRefusedError(`${at}: schema must be 1`);
193
+ const prefixes = Array.isArray(raw.prefix) ? raw.prefix : [raw.prefix];
194
+ if (prefixes.length === 0 ||
195
+ !prefixes.every(isPlainPath) ||
196
+ new Set(prefixes).size !== prefixes.length) {
197
+ throw new RoutesRefusedError(`${at}: prefix must be a plain path under app/[locale]/ (no leading or trailing slash, no . or .. segment), or a non-empty list of distinct ones`);
198
+ }
199
+ if (raw.oss !== undefined && raw.oss !== false) {
200
+ throw new RoutesRefusedError(`${at}: oss must be false when set (the generated files carry the oss: false marker)`);
201
+ }
202
+ if (raw.config !== undefined && (typeof raw.config !== "string" || raw.config.includes("/"))) {
203
+ throw new RoutesRefusedError(`${at}: config must be the site file's basename without extension`);
204
+ }
205
+ if (!Array.isArray(raw.routes))
206
+ throw new RoutesRefusedError(`${at}: routes must be a list`);
207
+ for (const key of ["siteSeam", "root", "siteGated"]) {
208
+ if (raw[key] !== undefined && typeof raw[key] !== "boolean") {
209
+ throw new RoutesRefusedError(`${at}: ${key} must be a boolean when set`);
210
+ }
211
+ }
212
+ const root = raw.root === true;
213
+ const appPrefixes = stringList(raw.appPrefixes, `${at}: appPrefixes`);
214
+ if (new Set(appPrefixes).size !== appPrefixes.length) {
215
+ throw new RoutesRefusedError(`${at}: appPrefixes must be distinct`);
216
+ }
217
+ for (const appPrefix of appPrefixes) {
218
+ if (!isPlainPath(appPrefix) || !appPrefix.startsWith("api/")) {
219
+ throw new RoutesRefusedError(`${at}: appPrefixes ${JSON.stringify(appPrefix)} must be a plain path under app/api/ (no leading or trailing slash, no . or .. segment)`);
220
+ }
221
+ const site = SITE_HANDLER_PREFIXES.find((own) => overlaps(own, appPrefix));
222
+ if (site !== undefined) {
223
+ throw new RoutesRefusedError(`${at}: appPrefixes ${JSON.stringify(appPrefix)} overlaps the site's own ${site}/ handlers`);
224
+ }
225
+ }
226
+ const prefix = prefixes;
227
+ const underPrefix = (path) => prefix.some((p) => path.startsWith(`${p}/`));
228
+ const prefixNamed = prefix.length === 1 ? `prefix ${prefix[0]}/` : `prefixes ${prefix.join(", ")}`;
229
+ const siteOwned = stringList(raw.siteOwned, `${at}: siteOwned`);
230
+ for (const path of siteOwned) {
231
+ if (!isPlainPath(path) || !ROUTING_FILES.has(posix.basename(path)) || !underPrefix(path)) {
232
+ throw new RoutesRefusedError(`${at}: siteOwned ${JSON.stringify(path)} must be a routing file under ${prefix.map((p) => `${p}/`).join(" or ")}`);
233
+ }
234
+ }
235
+ let messages;
236
+ if (raw.messages !== undefined) {
237
+ if (!isRecord(raw.messages) || !isPlainPath(raw.messages.catalog)) {
238
+ throw new RoutesRefusedError(`${at}: messages.catalog must be a plain path inside the package`);
239
+ }
240
+ const owned = stringList(raw.messages.siteOwned, `${at}: messages.siteOwned`);
241
+ for (const key of owned) {
242
+ if (!/^[A-Za-z0-9_-]+(\.[A-Za-z0-9_-]+)+$/.test(key)) {
243
+ throw new RoutesRefusedError(`${at}: messages.siteOwned ${JSON.stringify(key)} must be a dotted key under a namespace`);
244
+ }
245
+ }
246
+ messages = { catalog: raw.messages.catalog, siteOwned: owned };
247
+ }
248
+ const seen = new Set();
249
+ const routes = raw.routes.map((entry, i) => {
250
+ const where = `${at} routes[${i}]`;
251
+ if (!isRecord(entry))
252
+ throw new RoutesRefusedError(`${where} is not an object`);
253
+ const path = entry.path;
254
+ if (!isPlainPath(path) || !ROUTING_FILES.has(posix.basename(path))) {
255
+ throw new RoutesRefusedError(`${where}: path must be a plain path ending in page.tsx, layout.tsx or route.ts`);
256
+ }
257
+ if (entry.mount !== undefined && entry.mount !== "locale" && entry.mount !== "app") {
258
+ throw new RoutesRefusedError(`${where}: mount must be "locale" or "app"`);
259
+ }
260
+ const mount = entry.mount === "app" ? "app" : "locale";
261
+ if (mount === "app") {
262
+ if (appPrefixes.length === 0) {
263
+ throw new RoutesRefusedError(`${where}: ${path} is mounted under app/, but the manifest names no appPrefixes`);
264
+ }
265
+ if (!appPrefixes.some((p) => path.startsWith(`${p}/`))) {
266
+ throw new RoutesRefusedError(`${where}: ${path} is outside the manifest's appPrefixes ${appPrefixes.join(", ")}`);
267
+ }
268
+ if (entry.config === true) {
269
+ throw new RoutesRefusedError(`${where}: an app-mounted entry (${path}) cannot take the site config`);
270
+ }
271
+ }
272
+ else if (path === ROOT_PAGE) {
273
+ if (!root)
274
+ throw new RoutesRefusedError(`${where}: ${path} is the locale root, which only a manifest with "root": true ships`);
275
+ }
276
+ else if (!underPrefix(path)) {
277
+ throw new RoutesRefusedError(`${where}: ${path} is outside the manifest's ${prefixNamed}`);
278
+ }
279
+ if (seen.has(path) || siteOwned.includes(path)) {
280
+ throw new RoutesRefusedError(`${where}: ${path} is listed twice`);
281
+ }
282
+ seen.add(path);
283
+ const kind = KIND_OF_FILE[posix.basename(path)];
284
+ if (entry.kind !== kind)
285
+ throw new RoutesRefusedError(`${where}: kind must be ${JSON.stringify(kind)} for ${path}`);
286
+ if (!isPlainPath(entry.module) || !MODULE_RE.test(entry.module)) {
287
+ throw new RoutesRefusedError(`${where}: module must name the package subpath to re-export from, as a plain path of letters, digits and _ - . / ( ) [ ]`);
288
+ }
289
+ let waiver;
290
+ if (entry.waiver !== undefined) {
291
+ if (typeof entry.waiver !== "string" || !isOneLineText(entry.waiver)) {
292
+ throw new RoutesRefusedError(`${where}: waiver must be one line of text, with no control or line-separator character`);
293
+ }
294
+ if (kind !== "route")
295
+ throw new RoutesRefusedError(`${where}: only a route handler carries a waiver`);
296
+ waiver = entry.waiver;
297
+ }
298
+ const exports = stringList(entry.exports, `${where}: exports`);
299
+ if (exports.length === 0)
300
+ throw new RoutesRefusedError(`${where}: exports must list at least one export`);
301
+ const config = entry.config === true;
302
+ if (kind === "route") {
303
+ if (config)
304
+ throw new RoutesRefusedError(`${where}: a route handler (${path}) cannot take the site config`);
305
+ for (const name of exports) {
306
+ if (!HTTP_METHODS.has(name)) {
307
+ throw new RoutesRefusedError(`${where}: a route handler exports HTTP methods only, not ${JSON.stringify(name)}`);
308
+ }
309
+ }
310
+ }
311
+ else {
312
+ if (!exports.includes("default"))
313
+ throw new RoutesRefusedError(`${where}: a ${kind} must export default`);
314
+ for (const name of exports) {
315
+ if (!["default", "metadata", "generateMetadata"].includes(name)) {
316
+ throw new RoutesRefusedError(`${where}: a ${kind} may export default, metadata and generateMetadata only, not ${JSON.stringify(name)}`);
317
+ }
318
+ }
319
+ }
320
+ if (config && raw.config === undefined) {
321
+ throw new RoutesRefusedError(`${where}: takes config, but the manifest names no config file`);
322
+ }
323
+ const metadataConfig = entry.metadataConfig === true;
324
+ if (metadataConfig && !config)
325
+ throw new RoutesRefusedError(`${where}: metadataConfig needs config: true`);
326
+ if (metadataConfig && !exports.includes("generateMetadata")) {
327
+ throw new RoutesRefusedError(`${where}: metadataConfig needs generateMetadata in exports`);
328
+ }
329
+ const segmentConfig = stringList(entry.segmentConfig, `${where}: segmentConfig`);
330
+ for (const line of segmentConfig) {
331
+ if (!SEGMENT_CONFIG_RE.test(line)) {
332
+ throw new RoutesRefusedError(`${where}: ${JSON.stringify(line)} is not a route-segment-config line`);
333
+ }
334
+ }
335
+ return { path, kind, module: entry.module, exports, segmentConfig, config, metadataConfig, mount, waiver };
336
+ });
337
+ const oss = raw.oss === false ? false : undefined;
338
+ return {
339
+ package: pkg,
340
+ version,
341
+ prefix,
342
+ localeRoot: root,
343
+ siteGated: raw.siteGated === true,
344
+ appPrefixes,
345
+ siteSeam: raw.siteSeam === true,
346
+ config: raw.config,
347
+ siteOwned,
348
+ messages,
349
+ oss,
350
+ routes,
351
+ };
352
+ }
353
+ /**
354
+ * The route manifests of the installed page packages, in package-name
355
+ * order: every `@working-theory/*` dependency of `<site>/apps/web` whose
356
+ * installed `package.json` declares one. A dependency not installed yet
357
+ * (before `pnpm install`) declares nothing and is not an error.
358
+ */
359
+ export function readRouteManifests(siteDir) {
360
+ const web = join(resolve(siteDir), ROUTES_APP_DIR);
361
+ const pkgPath = join(web, "package.json");
362
+ if (!existsSync(pkgPath))
363
+ return [];
364
+ let pkg;
365
+ try {
366
+ pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
367
+ }
368
+ catch (err) {
369
+ throw new RoutesRefusedError(`${ROUTES_APP_DIR}/package.json does not parse: ${err.message}`);
370
+ }
371
+ if (!isRecord(pkg))
372
+ return [];
373
+ const names = new Set();
374
+ for (const key of ["dependencies", "devDependencies"]) {
375
+ const deps = pkg[key];
376
+ if (isRecord(deps))
377
+ for (const name of Object.keys(deps))
378
+ if (name.startsWith(PACKAGE_SCOPE))
379
+ names.add(name);
380
+ }
381
+ const manifests = [];
382
+ for (const name of [...names].sort()) {
383
+ const installed = join(web, "node_modules", name, "package.json");
384
+ if (!existsSync(installed))
385
+ continue;
386
+ let meta;
387
+ try {
388
+ meta = JSON.parse(readFileSync(installed, "utf8"));
389
+ }
390
+ catch {
391
+ continue;
392
+ }
393
+ if (!isRecord(meta))
394
+ continue;
395
+ const ailk = meta[MANIFEST_KEY];
396
+ if (!isRecord(ailk) || typeof ailk.routes !== "string")
397
+ continue;
398
+ const manifestPath = join(dirname(installed), ailk.routes);
399
+ if (!existsSync(manifestPath)) {
400
+ throw new RoutesRefusedError(`${name} declares a route manifest at ${ailk.routes}, which its install does not carry`);
401
+ }
402
+ let raw;
403
+ try {
404
+ raw = JSON.parse(readFileSync(manifestPath, "utf8"));
405
+ }
406
+ catch (err) {
407
+ throw new RoutesRefusedError(`${name}'s route manifest does not parse: ${err.message}`);
408
+ }
409
+ const manifest = parseRouteManifest(name, typeof meta.version === "string" ? meta.version : "0.0.0", raw);
410
+ for (const other of manifests) {
411
+ if (manifest.localeRoot && other.localeRoot) {
412
+ throw new RoutesRefusedError(`${name}'s route manifest claims the locale root, which ${other.package}'s already does`);
413
+ }
414
+ for (const mine of manifest.prefix) {
415
+ const clash = other.prefix.find((theirs) => overlaps(mine, theirs));
416
+ if (clash !== undefined) {
417
+ throw new RoutesRefusedError(`${name}'s route manifest: prefix ${JSON.stringify(mine)} overlaps ${other.package}'s ${JSON.stringify(clash)}`);
418
+ }
419
+ }
420
+ for (const mine of manifest.appPrefixes) {
421
+ const clash = other.appPrefixes.find((theirs) => overlaps(mine, theirs));
422
+ if (clash !== undefined) {
423
+ throw new RoutesRefusedError(`${name}'s route manifest: appPrefixes ${JSON.stringify(mine)} overlaps ${other.package}'s ${JSON.stringify(clash)}`);
424
+ }
425
+ }
426
+ }
427
+ manifests.push({ ...manifest, root: dirname(installed) });
428
+ }
429
+ return manifests;
430
+ }
431
+ /** The header line of every generated route file begins with this; `remove-module` reads it as module code. */
432
+ export const GENERATED_ROUTE_HEADER = "// Generated by create-ailk routes from ";
433
+ /** Line 1 of a generated file whose manifest sets `"oss": false` — the public strip's file marker. */
434
+ export const OSS_FALSE_MARKER = "// oss: false";
435
+ /** The generated file's text for one entry. Every statement is one line; the config wrapper is in prettier's shape. */
436
+ export function renderRouteFile(manifest, entry) {
437
+ const specifier = `${manifest.package}/${entry.module}`;
438
+ const lines = [`${GENERATED_ROUTE_HEADER}${manifest.package} ${manifest.version} — do not edit.`];
439
+ if (manifest.oss === false)
440
+ lines.unshift(OSS_FALSE_MARKER);
441
+ if (entry.waiver !== undefined)
442
+ lines.push(`// platform-decisions-waiver: ${entry.waiver}`);
443
+ if (entry.config) {
444
+ // The wrapper calls the page as the async function it is and returns its
445
+ // tree — no element boundary of its own — so the route module keeps the
446
+ // page's own contract (`(props) => Promise<ReactElement>`): what Next
447
+ // mounts, and what a test that renders `await Page(props)` renders.
448
+ // `app/[locale]/<path>` → the file's directory depth from the app root.
449
+ const depth = posix.dirname(posix.join(mountDir(entry.mount), entry.path)).split("/").length;
450
+ // #11253 — a `metadataConfig` entry's `generateMetadata` reads the config
451
+ // too (the checkout pages answer notFound() off a spoke before any
452
+ // translation), so it is imported beside `Page` and wrapped, never
453
+ // re-exported. Prettier keeps that import on one line only within 80
454
+ // columns, so a longer one is rendered in prettier's broken shape.
455
+ let pageImport = `import Page from "${specifier}";`;
456
+ if (entry.metadataConfig) {
457
+ pageImport = `import Page, { generateMetadata as pageMetadata } from "${specifier}";`;
458
+ if (pageImport.length > 80)
459
+ pageImport = `import Page, {\n generateMetadata as pageMetadata,\n} from "${specifier}";`;
460
+ }
461
+ lines.push(pageImport, "", `import config from "${"../".repeat(depth)}${manifest.config}";`);
462
+ const reexports = entry.exports
463
+ .filter((name) => name !== "default" && !(entry.metadataConfig && name === "generateMetadata"))
464
+ .map((name) => `export { ${name} } from "${specifier}";`);
465
+ if (reexports.length + entry.segmentConfig.length > 0)
466
+ lines.push("", ...reexports, ...entry.segmentConfig);
467
+ if (entry.metadataConfig) {
468
+ lines.push("", "export async function generateMetadata(", ' props: Omit<Parameters<typeof pageMetadata>[0], "config">,', ") {", " return pageMetadata({ ...props, config });", "}");
469
+ }
470
+ lines.push("", "export default async function Route(", ' props: Omit<Parameters<typeof Page>[0], "config">,', ") {", " return Page({ ...props, config });", "}");
471
+ }
472
+ else {
473
+ for (const name of entry.exports)
474
+ lines.push(`export { ${name} } from "${specifier}";`);
475
+ lines.push(...entry.segmentConfig);
476
+ }
477
+ return `${lines.join("\n")}\n`;
478
+ }
479
+ /** The directory under the app an entry's `path` is relative to. */
480
+ function mountDir(mount) {
481
+ return mount === "app" ? APP_DIR : LOCALE_DIR;
482
+ }
483
+ /** Whether `text` is a file this generator wrote: its first line (after an `oss: false` marker) is the header. */
484
+ export function isGenerated(text) {
485
+ const lines = text.split("\n", 2);
486
+ const first = lines[0] === OSS_FALSE_MARKER ? (lines[1] ?? "") : (lines[0] ?? "");
487
+ return first.startsWith(GENERATED_ROUTE_HEADER);
488
+ }
489
+ /** The scaffold lint's own glob (`template-overlay/tools/lint-architecture.ts`): `**` is zero or more whole segments, `*` stays inside one. */
490
+ function globToRegExp(glob) {
491
+ const segments = glob.split("/");
492
+ let re = "^";
493
+ segments.forEach((seg, i) => {
494
+ const last = i === segments.length - 1;
495
+ if (seg === "**") {
496
+ re += last ? ".*" : "(?:[^/]+/)*";
497
+ return;
498
+ }
499
+ re += seg.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, "[^/]*");
500
+ if (!last)
501
+ re += "/";
502
+ });
503
+ return new RegExp(`${re}$`);
504
+ }
505
+ /**
506
+ * The entries of `<site>/customizations.yaml`, when the site has one — read
507
+ * by line, in the shape the scaffold's own file documents (create-ailk
508
+ * carries no YAML parser): under `customizations:`, each `- id: <id>` entry's
509
+ * `paths:` list of quoted or bare globs, block or flow form. An entry with no id or no paths
510
+ * records nothing; the overlay lint owns the file's full validation.
511
+ */
512
+ function readRecorded(siteDir) {
513
+ const path = join(siteDir, "customizations.yaml");
514
+ if (!existsSync(path))
515
+ return [];
516
+ const out = [];
517
+ let inList = false;
518
+ let inPaths = false;
519
+ let current;
520
+ const unquote = (raw) => raw.trim().replace(/^["']|["']$/g, "");
521
+ const flush = () => {
522
+ if (current?.id !== undefined && current.paths.length > 0) {
523
+ out.push({ id: current.id, patterns: current.paths.map(globToRegExp) });
524
+ }
525
+ current = undefined;
526
+ };
527
+ for (const raw of readFileSync(path, "utf8").split(/\r?\n/)) {
528
+ const line = raw.replace(/\s+#.*$/, "");
529
+ if (line.trim() === "" || line.trimStart().startsWith("#"))
530
+ continue;
531
+ if (/^\S/.test(line)) {
532
+ flush();
533
+ inList = /^customizations:/.test(line);
534
+ inPaths = false;
535
+ continue;
536
+ }
537
+ if (!inList)
538
+ continue;
539
+ // `- <key>: …` opens an entry, whichever key comes first.
540
+ const entry = /^(\s*)-\s+(\w+):(.*)$/.exec(line);
541
+ const key = entry ? entry[2] : /^\s+(\w+):(.*)$/.exec(line)?.[1];
542
+ const rest = entry ? entry[3] : (/^\s+(\w+):(.*)$/.exec(line)?.[2] ?? "");
543
+ if (entry) {
544
+ flush();
545
+ current = { id: undefined, paths: [] };
546
+ }
547
+ if (current === undefined)
548
+ continue;
549
+ if (key === "id") {
550
+ current.id = unquote(rest);
551
+ inPaths = false;
552
+ }
553
+ else if (key === "paths") {
554
+ // The flow form, `paths: ["a/**", "b/**"]`, or the block form below it.
555
+ const flow = /^\s*\[(.*)\]\s*$/.exec(rest);
556
+ if (flow)
557
+ current.paths.push(...flow[1].split(",").map(unquote).filter((p) => p !== ""));
558
+ inPaths = !flow;
559
+ }
560
+ else if (key !== undefined) {
561
+ inPaths = false;
562
+ }
563
+ else {
564
+ const item = /^\s+-\s+(.+)$/.exec(line);
565
+ if (inPaths && item)
566
+ current.paths.push(unquote(item[1]));
567
+ }
568
+ }
569
+ flush();
570
+ return out;
571
+ }
572
+ function recordFor(recorded, sitePath) {
573
+ return recorded.find((entry) => entry.patterns.some((re) => re.test(sitePath)));
574
+ }
575
+ /** Whether `<siteDir>/customizations.yaml` records `sitePath` — any entry, any path form or glob (the generator's own reading). */
576
+ export function isRecordedRoute(siteDir, sitePath) {
577
+ return recordFor(readRecorded(resolve(siteDir)), sitePath) !== undefined;
578
+ }
579
+ /** Routing files under `<web>/<mount dir>/<prefix>`, as site-relative POSIX paths, sorted. */
580
+ function routingFilesUnder(web, siteDir, prefix, mount = "locale") {
581
+ const out = [];
582
+ const walk = (dir) => {
583
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
584
+ const path = join(dir, entry.name);
585
+ if (entry.isDirectory()) {
586
+ if (!SKIPPED_DIRS.has(entry.name))
587
+ walk(path);
588
+ }
589
+ else if (ROUTING_FILES.has(entry.name)) {
590
+ out.push(relative(siteDir, path).split(sep).join("/"));
591
+ }
592
+ }
593
+ };
594
+ const root = join(web, mountDir(mount), prefix);
595
+ if (existsSync(root))
596
+ walk(root);
597
+ return out.sort();
598
+ }
599
+ function plan(siteDir) {
600
+ const root = resolve(siteDir);
601
+ const web = join(root, ROUTES_APP_DIR);
602
+ const manifests = readRouteManifests(root);
603
+ const recorded = readRecorded(root);
604
+ // The site's topology (`.ailk-site-manifest.json`): on a spoke, the paths
605
+ // it does not carry are not its routes. A hub, or no manifest, carries all.
606
+ const spoke = readSpokeShape(root);
607
+ const gate = siteGate(root);
608
+ const carries = (manifest, sitePath) => (spoke === undefined || !isSpokeExcluded(sitePath, spoke)) && (!manifest.siteGated || gate(sitePath));
609
+ const planned = [];
610
+ const notCarried = [];
611
+ for (const manifest of manifests) {
612
+ const carried = manifest.routes.filter((entry) => carries(manifest, relative(root, join(web, mountDir(entry.mount), entry.path)).split(sep).join("/")));
613
+ if (manifest.config !== undefined && carried.some((entry) => entry.config)) {
614
+ const configPath = join(web, `${manifest.config}.tsx`);
615
+ if (!existsSync(configPath)) {
616
+ throw new RoutesRefusedError(`${manifest.package}'s routes take the site config, but ${ROUTES_APP_DIR}/${manifest.config}.tsx does not exist — create it, typed by the package`);
617
+ }
618
+ }
619
+ for (const entry of manifest.routes) {
620
+ const absPath = join(web, mountDir(entry.mount), entry.path);
621
+ const sitePath = relative(root, absPath).split(sep).join("/");
622
+ if (!carries(manifest, sitePath)) {
623
+ notCarried.push(sitePath);
624
+ continue;
625
+ }
626
+ planned.push({ sitePath, absPath, text: renderRouteFile(manifest, entry), record: recordFor(recorded, sitePath) });
627
+ }
628
+ }
629
+ return { root, web, manifests, planned, recorded, notCarried };
630
+ }
631
+ /**
632
+ * Whether a `siteGated` manifest's entry at `sitePath` is a route of the site
633
+ * (#11259 D5): not inside the public tree on a site without `marketing`, and
634
+ * not under a gateable surface the site's `# Surfaces:` header leaves out. A
635
+ * site with no readable header carries every surface.
636
+ */
637
+ function siteGate(siteDir) {
638
+ const noPublicTree = publicTreeRemoved(siteDir);
639
+ let surfaces;
640
+ const archPath = join(siteDir, "architecture.yaml");
641
+ if (existsSync(archPath)) {
642
+ const text = readFileSync(archPath, "utf8");
643
+ try {
644
+ surfaces = new Set(readArchitectureHeader(text).surfaces.map(canonicalizeSurface));
645
+ }
646
+ catch (err) {
647
+ // Only a missing or malformed header means "no header": a read error throws.
648
+ if (!(err instanceof AddModuleRefusedError))
649
+ throw err;
650
+ }
651
+ }
652
+ return (sitePath) => {
653
+ if (noPublicTree && isRemovedPublicRoutePath(sitePath))
654
+ return false;
655
+ if (surfaces === undefined || !sitePath.startsWith(`${ROUTE_ROOT}/`))
656
+ return true;
657
+ const top = `${ROUTE_ROOT}/${sitePath.slice(ROUTE_ROOT.length + 1).split("/")[0]}`;
658
+ const surface = GATEABLE_SURFACES.find((s) => s.routes.includes(top));
659
+ return surface === undefined || surfaces.has(surface.id);
660
+ };
661
+ }
662
+ /** The count check mode fails on: missing, stale and stray route files, orphaned overrides and missing seam aliases. */
663
+ export function routesFailing(drift) {
664
+ return (drift.missing.length +
665
+ drift.stale.length +
666
+ drift.stray.length +
667
+ drift.orphanedOverrides.length +
668
+ drift.seamAliasMissing.length);
669
+ }
670
+ /**
671
+ * The two site files that bind a `siteSeam` package's `<package>/site` to
672
+ * the site's config (#11257 D4, SEC-11257-1): `next.config.mjs`'s
673
+ * `resolve.alias` key and `jest.config.cjs`'s `moduleNameMapper` key, read as
674
+ * text. A missing line means a build or a suite would bind the package's
675
+ * stub, so check mode fails naming the file; a file the site does not have
676
+ * is named too.
677
+ */
678
+ function seamAliasMissing(web, siteDir, manifests) {
679
+ const out = [];
680
+ for (const manifest of manifests) {
681
+ if (!manifest.siteSeam || manifest.routes.length === 0)
682
+ continue;
683
+ const wants = [
684
+ ["next.config.mjs", `"${manifest.package}/site$"`],
685
+ ["jest.config.cjs", `"^${manifest.package}/site$"`],
686
+ ];
687
+ for (const [file, alias] of wants) {
688
+ const path = join(web, file);
689
+ const text = existsSync(path) ? readFileSync(path, "utf8") : "";
690
+ if (!text.includes(alias))
691
+ out.push(`${relative(siteDir, path).split(sep).join("/")}: ${alias}`);
692
+ }
693
+ }
694
+ return out;
695
+ }
696
+ /** How the site's route files and message overrides differ from the installed page packages. `routesFailing` zero means in sync. */
697
+ export function checkRoutes(siteDir) {
698
+ const { root, web, manifests, planned, recorded, notCarried } = plan(siteDir);
699
+ const drift = {
700
+ missing: [],
701
+ stale: [],
702
+ stray: [],
703
+ recorded: [],
704
+ notCarried,
705
+ siteKept: [],
706
+ orphanedOverrides: orphanedOverrides(web, root, manifests),
707
+ seamAliasMissing: seamAliasMissing(web, root, manifests),
708
+ generated: planned.length,
709
+ };
710
+ const known = new Set();
711
+ for (const p of planned) {
712
+ known.add(p.sitePath);
713
+ const exists = existsSync(p.absPath);
714
+ if (p.record) {
715
+ drift.recorded.push({ path: p.sitePath, state: exists ? "replaced" : "removed", id: p.record.id });
716
+ }
717
+ else if (!exists) {
718
+ drift.missing.push(p.sitePath);
719
+ }
720
+ else if (readFileSync(p.absPath, "utf8") !== p.text) {
721
+ drift.stale.push(p.sitePath);
722
+ }
723
+ }
724
+ for (const manifest of manifests) {
725
+ // A manifest that ships no route owns nothing yet (a package landing its
726
+ // contract ahead of its first page): nothing under its prefix is stray.
727
+ if (manifest.routes.length === 0)
728
+ continue;
729
+ const kept = new Set(manifest.siteOwned.map((path) => relative(root, join(web, LOCALE_DIR, path)).split(sep).join("/")));
730
+ const rootPage = join(web, LOCALE_DIR, ROOT_PAGE);
731
+ const underPrefixes = [
732
+ ...(manifest.localeRoot && existsSync(rootPage) ? [relative(root, rootPage).split(sep).join("/")] : []),
733
+ ...manifest.prefix.flatMap((prefix) => routingFilesUnder(web, root, prefix)),
734
+ ...manifest.appPrefixes.flatMap((prefix) => routingFilesUnder(web, root, prefix, "app")),
735
+ ];
736
+ for (const sitePath of underPrefixes) {
737
+ if (known.has(sitePath))
738
+ continue;
739
+ known.add(sitePath);
740
+ if (kept.has(sitePath)) {
741
+ drift.siteKept.push(sitePath);
742
+ continue;
743
+ }
744
+ const record = recordFor(recorded, sitePath);
745
+ if (record)
746
+ drift.recorded.push({ path: sitePath, state: "replaced", id: record.id });
747
+ else
748
+ drift.stray.push(sitePath);
749
+ }
750
+ }
751
+ return drift;
752
+ }
753
+ function readCatalog(path) {
754
+ if (!existsSync(path))
755
+ return undefined;
756
+ try {
757
+ const parsed = JSON.parse(readFileSync(path, "utf8"));
758
+ return isRecord(parsed) ? parsed : undefined;
759
+ }
760
+ catch {
761
+ return undefined;
762
+ }
763
+ }
764
+ /** Every string leaf of `catalog` under `prefix`, as dotted keys. */
765
+ function leafKeys(catalog, prefix) {
766
+ return Object.entries(catalog).flatMap(([key, value]) => isRecord(value) ? leafKeys(value, `${prefix}${key}.`) : typeof value === "string" ? [`${prefix}${key}`] : []);
767
+ }
768
+ function hasKey(catalog, dotted) {
769
+ let node = catalog;
770
+ for (const segment of dotted.split(".")) {
771
+ if (!isRecord(node) || !Object.prototype.hasOwnProperty.call(node, segment))
772
+ return false;
773
+ node = node[segment];
774
+ }
775
+ return typeof node === "string";
776
+ }
777
+ /**
778
+ * The site keys, across `<web>/messages/<locale>.json`, that sit under a
779
+ * namespace a page package's catalog ships yet name a key that catalog does
780
+ * not have — an override of a string the package no longer carries. A site
781
+ * locale with no package catalog is read against the package's `en`.
782
+ */
783
+ function orphanedOverrides(web, siteDir, manifests) {
784
+ const messagesDir = join(web, "messages");
785
+ if (!existsSync(messagesDir))
786
+ return [];
787
+ const locales = readdirSync(messagesDir)
788
+ .filter((name) => name.endsWith(".json"))
789
+ .map((name) => name.slice(0, -".json".length))
790
+ .sort();
791
+ const out = [];
792
+ for (const manifest of manifests) {
793
+ if (manifest.messages === undefined || manifest.root === undefined)
794
+ continue;
795
+ const catalogDir = join(manifest.root, manifest.messages.catalog);
796
+ const fallback = readCatalog(join(catalogDir, "en.json"));
797
+ // A declared catalog the install cannot answer for checks nothing: refuse,
798
+ // as an unreadable manifest is refused, rather than pass silently.
799
+ if (fallback === undefined) {
800
+ throw new RoutesRefusedError(`${manifest.package} declares its message catalog at ${manifest.messages.catalog}, but its install carries no readable ${manifest.messages.catalog}/en.json`);
801
+ }
802
+ const owned = manifest.messages.siteOwned;
803
+ for (const locale of locales) {
804
+ const sitePath = join(messagesDir, `${locale}.json`);
805
+ const siteCatalog = readCatalog(sitePath);
806
+ const packaged = readCatalog(join(catalogDir, `${locale}.json`)) ?? fallback;
807
+ if (siteCatalog === undefined || packaged === undefined)
808
+ continue;
809
+ const file = relative(siteDir, sitePath).split(sep).join("/");
810
+ for (const namespace of Object.keys(packaged)) {
811
+ const site = siteCatalog[namespace];
812
+ if (!isRecord(site))
813
+ continue;
814
+ for (const key of leafKeys(site, `${namespace}.`)) {
815
+ if (owned.some((prefix) => key === prefix || key.startsWith(`${prefix}.`)))
816
+ continue;
817
+ if (!hasKey(packaged, key))
818
+ out.push(`${file}: ${key} (${manifest.package})`);
819
+ }
820
+ }
821
+ }
822
+ }
823
+ return out;
824
+ }
825
+ /** Write every generated file that is missing or stale; a recorded route is left exactly as it is. */
826
+ export function writeRoutes(siteDir) {
827
+ const { planned } = plan(siteDir);
828
+ const result = { written: [], current: [], recorded: [], kept: [] };
829
+ for (const p of planned) {
830
+ const exists = existsSync(p.absPath);
831
+ if (p.record) {
832
+ result.recorded.push({ path: p.sitePath, state: exists ? "replaced" : "removed", id: p.record.id });
833
+ continue;
834
+ }
835
+ if (exists) {
836
+ const text = readFileSync(p.absPath, "utf8");
837
+ if (text === p.text) {
838
+ result.current.push(p.sitePath);
839
+ continue;
840
+ }
841
+ if (!isGenerated(text)) {
842
+ result.kept.push(p.sitePath);
843
+ continue;
844
+ }
845
+ }
846
+ mkdirSync(dirname(p.absPath), { recursive: true });
847
+ writeFileSync(p.absPath, p.text);
848
+ result.written.push(p.sitePath);
849
+ }
850
+ return result;
851
+ }
852
+ export const ROUTES_HELP = `create-ailk routes — generate the route files for the pages a site's packages ship.
853
+
854
+ Usage:
855
+ create-ailk routes --write [<target-dir>]
856
+ create-ailk routes --check [<target-dir>]
857
+
858
+ Arguments:
859
+ <target-dir> The site root (holds apps/web). Defaults to the
860
+ current dir.
861
+
862
+ Options:
863
+ --write Write one generated file per route the installed
864
+ page packages declare, under apps/web/app/[locale]/.
865
+ A file already current is left alone.
866
+ --check Write nothing; exit 1 naming each generated file
867
+ that is missing, stale (differs from what --write
868
+ would write) or stray (a page.tsx, layout.tsx or
869
+ route.ts under a package's route prefix that is
870
+ neither generated, recorded, nor one the package
871
+ leaves to the site). It also names each orphaned
872
+ override: a key in apps/web/messages/<locale>.json
873
+ under a namespace a package's catalog ships that
874
+ the catalog no longer has.
875
+ --help, -h Print this message.
876
+
877
+ A page package is an installed @working-theory/* dependency of apps/web whose
878
+ package.json declares "ailk": { "routes": "<manifest>" }. A generated file
879
+ re-exports the package's page and copies its route-segment config; when the
880
+ page takes the site's config it imports the manifest's config file from the
881
+ app root (apps/web/account.config.tsx, say) and passes it in. Replace or remove a shipped route by recording it in
882
+ customizations.yaml (an entry whose paths match the route file): a recorded
883
+ route is reported as replaced or removed, never failed, and --write never
884
+ touches it. A manifest may list several prefixes, and one manifest with
885
+ "root": true may ship the locale-root page.tsx. A manifest with
886
+ "siteGated": true ships only the routes the site selected: its public pages
887
+ are not carried when .ailk-site-manifest.json lists no marketing module, and
888
+ neither is any page under a surface the architecture.yaml "# Surfaces:" header
889
+ leaves out. Run --write after \`pnpm install\` (the manifests are read from the
890
+ installed packages); the scaffold's preflight runs --check as \`pnpm routes:check\`.
891
+ `;
892
+ /** Parse the argv AFTER the `routes` word. Strict `node:util` parseArgs, like `parseSyncRoutesArgs`. */
893
+ export function parseRoutesArgs(argv) {
894
+ const parsed = parseArgs({
895
+ args: argv,
896
+ strict: true,
897
+ allowPositionals: true,
898
+ options: {
899
+ write: { type: "boolean", default: false },
900
+ check: { type: "boolean", default: false },
901
+ help: { type: "boolean", default: false, short: "h" },
902
+ },
903
+ });
904
+ if (parsed.positionals.length > 1) {
905
+ throw new RoutesRefusedError(`routes takes one target directory, got ${parsed.positionals.length}`);
906
+ }
907
+ const args = {
908
+ target: parsed.positionals[0],
909
+ write: parsed.values.write,
910
+ check: parsed.values.check,
911
+ help: parsed.values.help,
912
+ };
913
+ if (!args.help && args.write === args.check) {
914
+ throw new RoutesRefusedError("routes needs exactly one of --write or --check");
915
+ }
916
+ return args;
917
+ }
918
+ /** The printed report: one line per file, grouped by state; the recorded routes last, under their decision. */
919
+ export function formatRoutesReport(result, mode) {
920
+ const lines = [];
921
+ if (mode === "check") {
922
+ const drift = result;
923
+ const failing = [
924
+ ...drift.missing.map((p) => ` missing: ${p}`),
925
+ ...drift.stale.map((p) => ` stale: ${p}`),
926
+ ...drift.stray.map((p) => ` stray: ${p}`),
927
+ ...drift.orphanedOverrides.map((p) => ` orphaned override: ${p}`),
928
+ ...drift.seamAliasMissing.map((p) => ` missing site seam alias: ${p}`),
929
+ ];
930
+ if (failing.length === 0) {
931
+ lines.push(`[create-ailk] routes: OK — ${drift.generated} generated route file(s) in sync`);
932
+ }
933
+ else {
934
+ lines.push(`[create-ailk] routes: ${failing.length} route file(s) or message override(s) differ from the installed page packages (run \`create-ailk routes --write\` to rewrite a route file; record a replaced or removed route in customizations.yaml; delete an orphaned override, whose key the package no longer has):`, ...failing);
935
+ }
936
+ }
937
+ else {
938
+ const write = result;
939
+ lines.push(`[create-ailk] routes: wrote ${write.written.length} route file(s), ${write.current.length} already current`);
940
+ for (const p of write.written)
941
+ lines.push(` wrote: ${p}`);
942
+ for (const p of write.kept)
943
+ lines.push(` kept (not a generated file, never overwritten): ${p}`);
944
+ }
945
+ for (const r of result.recorded)
946
+ lines.push(` ${r.state} (recorded): ${r.path} — customizations.yaml "${r.id}"`);
947
+ if ("notCarried" in result)
948
+ for (const p of result.notCarried)
949
+ lines.push(` not carried on this spoke: ${p}`);
950
+ if ("siteKept" in result)
951
+ for (const p of result.siteKept)
952
+ lines.push(` kept by the site (the package ships no page here): ${p}`);
953
+ return `${lines.join("\n")}\n`;
954
+ }