@h-ai/cli 0.1.0-alpha9 → 1.0.0-beta.2

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 (438) hide show
  1. package/README.en.md +229 -0
  2. package/README.ja.md +229 -0
  3. package/README.md +175 -113
  4. package/dist/chunk-AKV2CQZV.js +1497 -0
  5. package/dist/chunk-AKV2CQZV.js.map +1 -0
  6. package/dist/chunk-EF7WOFWZ.js +7557 -0
  7. package/dist/chunk-EF7WOFWZ.js.map +1 -0
  8. package/dist/chunk-MUHRBJSW.js +29272 -0
  9. package/dist/chunk-MUHRBJSW.js.map +1 -0
  10. package/dist/chunk-ZSDEVXZ7.js +38 -0
  11. package/dist/{chunk-2H7UOFLK.js.map → chunk-ZSDEVXZ7.js.map} +1 -1
  12. package/dist/cli-config-templates-HHFHNXBN.js +5 -0
  13. package/dist/cli-config-templates-HHFHNXBN.js.map +1 -0
  14. package/dist/cli-skill-templates-PN4FLGBC.js +5 -0
  15. package/dist/cli-skill-templates-PN4FLGBC.js.map +1 -0
  16. package/dist/index.js +4444 -554
  17. package/dist/index.js.map +1 -1
  18. package/dist/metafile-esm.json +1 -0
  19. package/dist/src-TEBHR5I5.js +5 -0
  20. package/dist/src-TEBHR5I5.js.map +1 -0
  21. package/package.json +35 -15
  22. package/templates/README.md +56 -114
  23. package/templates/apps/admin/messages/en-US.json +7 -0
  24. package/templates/apps/admin/messages/ja-JP.json +40 -0
  25. package/templates/apps/admin/messages/zh-CN.json +7 -0
  26. package/templates/apps/admin/src/routes/+layout.svelte.hbs +65 -8
  27. package/templates/apps/admin/src/routes/+page.svelte.hbs +35 -14
  28. package/templates/apps/admin/src/routes/admin/+layout.svelte.hbs +54 -22
  29. package/templates/apps/admin/src/routes/admin/+page.svelte.hbs +33 -24
  30. package/templates/apps/admin/src/routes/admin/settings/+page.svelte.hbs +16 -13
  31. package/templates/apps/api/.dockerignore.hbs +25 -0
  32. package/templates/apps/api/.gitignore.hbs +22 -0
  33. package/templates/apps/api/.npmrc.hbs +1 -0
  34. package/templates/apps/api/apps/{{projectName}}-contract/README.md.hbs +39 -0
  35. package/templates/apps/api/apps/{{projectName}}-contract/package.json.hbs +41 -0
  36. package/templates/apps/api/apps/{{projectName}}-contract/src/app-contract.ts.hbs +27 -0
  37. package/templates/apps/api/apps/{{projectName}}-contract/src/app-schemas.ts.hbs +28 -0
  38. package/templates/apps/api/apps/{{projectName}}-contract/src/index.ts.hbs +5 -0
  39. package/templates/apps/api/apps/{{projectName}}-contract/src/{{projectName}}-contract.ts.hbs +16 -0
  40. package/templates/apps/api/apps/{{projectName}}-contract/tests/contract.test.ts.hbs +18 -0
  41. package/templates/apps/api/apps/{{projectName}}-contract/tsconfig.json.hbs +12 -0
  42. package/templates/apps/api/apps/{{projectName}}-contract/tsup.config.ts.hbs +11 -0
  43. package/templates/apps/api/apps/{{projectName}}-contract/vitest.config.ts.hbs +9 -0
  44. package/templates/apps/api/apps/{{projectName}}-serv/README.md.hbs +60 -0
  45. package/templates/apps/api/apps/{{projectName}}-serv/config/_core.yml.hbs +17 -0
  46. package/templates/apps/api/apps/{{projectName}}-serv/config/_serv.yml.hbs +54 -0
  47. package/templates/apps/api/apps/{{projectName}}-serv/data/.gitkeep.hbs +1 -0
  48. package/templates/apps/api/apps/{{projectName}}-serv/package.json.hbs +66 -0
  49. package/templates/apps/api/apps/{{projectName}}-serv/src/app.ts.hbs +119 -0
  50. package/templates/apps/api/apps/{{projectName}}-serv/src/build-metadata.ts.hbs +7 -0
  51. package/templates/apps/api/apps/{{projectName}}-serv/src/index.ts.hbs +41 -0
  52. package/templates/apps/api/apps/{{projectName}}-serv/src/lib/server/init.ts.hbs +165 -0
  53. package/templates/apps/api/apps/{{projectName}}-serv/src/server/procedures/app-procedures.ts.hbs +57 -0
  54. package/templates/apps/api/apps/{{projectName}}-serv/src/server/procedures/index.ts.hbs +41 -0
  55. package/templates/apps/api/apps/{{projectName}}-serv/tests/service.test.ts.hbs +176 -0
  56. package/templates/apps/api/apps/{{projectName}}-serv/tsconfig.json.hbs +16 -0
  57. package/templates/apps/api/apps/{{projectName}}-serv/tsup.config.ts.hbs +20 -0
  58. package/templates/apps/api/apps/{{projectName}}-serv/vitest.config.ts.hbs +12 -0
  59. package/templates/apps/api/e2e/api-serv.spec.ts.hbs +113 -0
  60. package/templates/apps/api/e2e/capture-evidence.ts.hbs +23 -0
  61. package/templates/apps/api/eslint.config.js.hbs +30 -0
  62. package/templates/apps/api/hai.json.hbs +4 -0
  63. package/templates/apps/api/images/serv.Dockerfile.hbs +37 -0
  64. package/templates/apps/api/package.json.hbs +53 -0
  65. package/templates/apps/api/playwright.config.ts.hbs +67 -0
  66. package/templates/apps/api/pnpm-workspace.yaml.hbs +40 -0
  67. package/templates/apps/api/tsconfig.base.json +14 -0
  68. package/templates/apps/fullstack/.dockerignore.hbs +25 -0
  69. package/templates/apps/fullstack/.gitignore.hbs +38 -0
  70. package/templates/apps/fullstack/.npmrc.hbs +1 -0
  71. package/templates/apps/fullstack/apps/{{projectName}}-app/.env.example.hbs +10 -0
  72. package/templates/apps/fullstack/apps/{{projectName}}-app/README.md.hbs +67 -0
  73. package/templates/apps/fullstack/apps/{{projectName}}-app/capacitor.config.ts.hbs +20 -0
  74. package/templates/apps/fullstack/apps/{{projectName}}-app/eslint.config.js.hbs +20 -0
  75. package/templates/apps/fullstack/apps/{{projectName}}-app/index.html.hbs +22 -0
  76. package/templates/apps/fullstack/apps/{{projectName}}-app/messages/en-US.json.hbs +7 -0
  77. package/templates/apps/fullstack/apps/{{projectName}}-app/messages/ja-JP.json.hbs +7 -0
  78. package/templates/apps/fullstack/apps/{{projectName}}-app/messages/zh-CN.json.hbs +7 -0
  79. package/templates/apps/fullstack/apps/{{projectName}}-app/package.json.hbs +86 -0
  80. package/templates/apps/fullstack/apps/{{projectName}}-app/project.inlang/settings.json.hbs +17 -0
  81. package/templates/apps/fullstack/apps/{{projectName}}-app/public/runtime-config.js.hbs +4 -0
  82. package/templates/apps/fullstack/apps/{{projectName}}-app/src/App.svelte.hbs +59 -0
  83. package/templates/apps/fullstack/apps/{{projectName}}-app/src/app.css.hbs +20 -0
  84. package/templates/apps/fullstack/apps/{{projectName}}-app/src/app.d.ts.hbs +8 -0
  85. package/templates/apps/fullstack/apps/{{projectName}}-app/src/build-metadata.ts.hbs +9 -0
  86. package/templates/apps/fullstack/apps/{{projectName}}-app/src/lib/capacitor.ts.hbs +19 -0
  87. package/templates/apps/fullstack/apps/{{projectName}}-app/src/main.ts.hbs +21 -0
  88. package/templates/apps/fullstack/apps/{{projectName}}-app/svelte.config.js.hbs +16 -0
  89. package/templates/apps/fullstack/apps/{{projectName}}-app/tsconfig.json.hbs +23 -0
  90. package/templates/apps/fullstack/apps/{{projectName}}-app/vite.config.ts.hbs +74 -0
  91. package/templates/apps/fullstack/apps/{{projectName}}-desktop/.env.example.hbs +6 -0
  92. package/templates/apps/fullstack/apps/{{projectName}}-desktop/README.md.hbs +64 -0
  93. package/templates/apps/fullstack/apps/{{projectName}}-desktop/eslint.config.js.hbs +20 -0
  94. package/templates/apps/fullstack/apps/{{projectName}}-desktop/index.html.hbs +20 -0
  95. package/templates/apps/fullstack/apps/{{projectName}}-desktop/messages/en-US.json.hbs +7 -0
  96. package/templates/apps/fullstack/apps/{{projectName}}-desktop/messages/ja-JP.json.hbs +7 -0
  97. package/templates/apps/fullstack/apps/{{projectName}}-desktop/messages/zh-CN.json.hbs +7 -0
  98. package/templates/apps/fullstack/apps/{{projectName}}-desktop/package.json.hbs +66 -0
  99. package/templates/apps/fullstack/apps/{{projectName}}-desktop/project.inlang/settings.json.hbs +17 -0
  100. package/templates/apps/fullstack/apps/{{projectName}}-desktop/src/App.svelte.hbs +25 -0
  101. package/templates/apps/fullstack/apps/{{projectName}}-desktop/src/app.css.hbs +18 -0
  102. package/templates/apps/fullstack/apps/{{projectName}}-desktop/src/app.d.ts.hbs +8 -0
  103. package/templates/apps/fullstack/apps/{{projectName}}-desktop/src/build-metadata.ts.hbs +9 -0
  104. package/templates/apps/fullstack/apps/{{projectName}}-desktop/src/main.ts.hbs +20 -0
  105. package/templates/apps/fullstack/apps/{{projectName}}-desktop/src-tauri/Cargo.toml.hbs +33 -0
  106. package/templates/apps/fullstack/apps/{{projectName}}-desktop/src-tauri/build.rs.hbs +6 -0
  107. package/templates/apps/fullstack/apps/{{projectName}}-desktop/src-tauri/capabilities/default.json.hbs +16 -0
  108. package/templates/apps/fullstack/apps/{{projectName}}-desktop/src-tauri/icons/128x128.png +0 -0
  109. package/templates/apps/fullstack/apps/{{projectName}}-desktop/src-tauri/icons/128x128@2x.png +0 -0
  110. package/templates/apps/fullstack/apps/{{projectName}}-desktop/src-tauri/icons/32x32.png +0 -0
  111. package/templates/apps/fullstack/apps/{{projectName}}-desktop/src-tauri/icons/icon.icns +0 -0
  112. package/templates/apps/fullstack/apps/{{projectName}}-desktop/src-tauri/icons/icon.ico +0 -0
  113. package/templates/apps/fullstack/apps/{{projectName}}-desktop/src-tauri/src/lib.rs.hbs +91 -0
  114. package/templates/apps/fullstack/apps/{{projectName}}-desktop/src-tauri/src/main.rs.hbs +8 -0
  115. package/templates/apps/fullstack/apps/{{projectName}}-desktop/src-tauri/tauri.conf.json.hbs +46 -0
  116. package/templates/apps/fullstack/apps/{{projectName}}-desktop/svelte.config.js.hbs +14 -0
  117. package/templates/apps/fullstack/apps/{{projectName}}-desktop/tsconfig.json.hbs +22 -0
  118. package/templates/apps/fullstack/apps/{{projectName}}-desktop/vite.config.ts.hbs +89 -0
  119. package/templates/apps/fullstack/apps/{{projectName}}-miniapp/README.md.hbs +25 -0
  120. package/templates/apps/fullstack/apps/{{projectName}}-miniapp/messages/en-US.json.hbs +12 -0
  121. package/templates/apps/fullstack/apps/{{projectName}}-miniapp/messages/ja-JP.json.hbs +12 -0
  122. package/templates/apps/fullstack/apps/{{projectName}}-miniapp/messages/zh-CN.json.hbs +12 -0
  123. package/templates/apps/fullstack/apps/{{projectName}}-miniapp/project.inlang/settings.json.hbs +17 -0
  124. package/templates/apps/fullstack/apps/{{projectName}}-web/README.md.hbs +54 -0
  125. package/templates/apps/fullstack/apps/{{projectName}}-web/eslint.config.js.hbs +20 -0
  126. package/templates/apps/fullstack/apps/{{projectName}}-web/index.html.hbs +21 -0
  127. package/templates/apps/fullstack/apps/{{projectName}}-web/messages/en-US.json.hbs +7 -0
  128. package/templates/apps/fullstack/apps/{{projectName}}-web/messages/ja-JP.json.hbs +7 -0
  129. package/templates/apps/fullstack/apps/{{projectName}}-web/messages/zh-CN.json.hbs +7 -0
  130. package/templates/apps/fullstack/apps/{{projectName}}-web/package.json.hbs +53 -0
  131. package/templates/apps/fullstack/apps/{{projectName}}-web/project.inlang/settings.json.hbs +17 -0
  132. package/templates/apps/fullstack/apps/{{projectName}}-web/public/runtime-config.js.hbs +1 -0
  133. package/templates/apps/fullstack/apps/{{projectName}}-web/src/App.svelte.hbs +18 -0
  134. package/templates/apps/fullstack/apps/{{projectName}}-web/src/app.css.hbs +18 -0
  135. package/templates/apps/fullstack/apps/{{projectName}}-web/src/app.d.ts.hbs +8 -0
  136. package/templates/apps/fullstack/apps/{{projectName}}-web/src/build-metadata.ts.hbs +9 -0
  137. package/templates/apps/fullstack/apps/{{projectName}}-web/src/main.ts.hbs +14 -0
  138. package/templates/apps/fullstack/apps/{{projectName}}-web/svelte.config.js.hbs +16 -0
  139. package/templates/apps/fullstack/apps/{{projectName}}-web/tsconfig.json.hbs +23 -0
  140. package/templates/apps/fullstack/apps/{{projectName}}-web/vite.config.ts.hbs +76 -0
  141. package/templates/apps/fullstack/docs/security-configuration.md.hbs +349 -0
  142. package/templates/apps/fullstack/e2e/fullstack.spec.ts.hbs +988 -0
  143. package/templates/apps/fullstack/e2e/session-close.spec.ts.hbs +119 -0
  144. package/templates/apps/fullstack/eslint.config.js.hbs +41 -0
  145. package/templates/apps/fullstack/hai.json.hbs +11 -0
  146. package/templates/apps/fullstack/images/serv.Dockerfile.hbs +38 -0
  147. package/templates/apps/fullstack/images/web/19-runtime-config.envsh.hbs +5 -0
  148. package/templates/apps/fullstack/images/web/nginx.conf.hbs +24 -0
  149. package/templates/apps/fullstack/images/web/runtime-config.js.template.hbs +3 -0
  150. package/templates/apps/fullstack/images/web.Dockerfile.hbs +37 -0
  151. package/templates/apps/fullstack/package.json.hbs +61 -0
  152. package/templates/apps/fullstack/packages/{{projectName}}-contract/README.md.hbs +40 -0
  153. package/templates/apps/fullstack/packages/{{projectName}}-contract/package.json.hbs +30 -0
  154. package/templates/apps/fullstack/packages/{{projectName}}-contract/src/admin-contract.ts.hbs +78 -0
  155. package/templates/apps/fullstack/packages/{{projectName}}-contract/src/admin-schemas.ts.hbs +134 -0
  156. package/templates/apps/fullstack/packages/{{projectName}}-contract/src/app-contract.ts.hbs +20 -0
  157. package/templates/apps/fullstack/packages/{{projectName}}-contract/src/app-schemas.ts.hbs +35 -0
  158. package/templates/apps/fullstack/packages/{{projectName}}-contract/src/index.ts.hbs +7 -0
  159. package/templates/apps/fullstack/packages/{{projectName}}-contract/src/{{projectName}}-contract.ts.hbs +23 -0
  160. package/templates/apps/fullstack/packages/{{projectName}}-contract/tests/contract.test.ts.hbs +31 -0
  161. package/templates/apps/fullstack/packages/{{projectName}}-contract/tsconfig.json.hbs +9 -0
  162. package/templates/apps/fullstack/packages/{{projectName}}-contract/tsup.config.ts.hbs +9 -0
  163. package/templates/apps/fullstack/packages/{{projectName}}-serv/README.md.hbs +84 -0
  164. package/templates/apps/fullstack/packages/{{projectName}}-serv/config/_ai.yml.hbs +1 -0
  165. package/templates/apps/fullstack/packages/{{projectName}}-serv/config/_audit.yml.hbs +1 -0
  166. package/templates/apps/fullstack/packages/{{projectName}}-serv/config/_cache.yml.hbs +1 -0
  167. package/templates/apps/fullstack/packages/{{projectName}}-serv/config/_core.yml.hbs +22 -0
  168. package/templates/apps/fullstack/packages/{{projectName}}-serv/config/_db.yml.hbs +1 -0
  169. package/templates/apps/fullstack/packages/{{projectName}}-serv/config/_feedback.yml.hbs +1 -0
  170. package/templates/apps/fullstack/packages/{{projectName}}-serv/config/_iam.yml.hbs +1 -0
  171. package/templates/apps/fullstack/packages/{{projectName}}-serv/config/_payment.yml.hbs +1 -0
  172. package/templates/apps/fullstack/packages/{{projectName}}-serv/config/_reach.yml.hbs +60 -0
  173. package/templates/apps/fullstack/packages/{{projectName}}-serv/config/_scheduler.yml.hbs +1 -0
  174. package/templates/apps/fullstack/packages/{{projectName}}-serv/config/_serv.yml.hbs +64 -0
  175. package/templates/apps/fullstack/packages/{{projectName}}-serv/config/_storage.yml.hbs +1 -0
  176. package/templates/apps/fullstack/packages/{{projectName}}-serv/config/_vecdb.yml.hbs +1 -0
  177. package/templates/apps/fullstack/packages/{{projectName}}-serv/data/.gitkeep.hbs +1 -0
  178. package/templates/apps/fullstack/packages/{{projectName}}-serv/package.json.hbs +62 -0
  179. package/templates/apps/fullstack/packages/{{projectName}}-serv/src/app-server.ts.hbs +115 -0
  180. package/templates/apps/fullstack/packages/{{projectName}}-serv/src/build-metadata.ts.hbs +7 -0
  181. package/templates/apps/fullstack/packages/{{projectName}}-serv/src/index.ts.hbs +40 -0
  182. package/templates/apps/fullstack/packages/{{projectName}}-serv/src/server/admin-service.ts.hbs +294 -0
  183. package/templates/apps/fullstack/packages/{{projectName}}-serv/src/server/audit-jobs.ts.hbs +28 -0
  184. package/templates/apps/fullstack/packages/{{projectName}}-serv/src/server/business-settings.ts.hbs +50 -0
  185. package/templates/apps/fullstack/packages/{{projectName}}-serv/src/server/messages.ts.hbs +50 -0
  186. package/templates/apps/fullstack/packages/{{projectName}}-serv/src/server/procedures/admin-procedures.ts.hbs +106 -0
  187. package/templates/apps/fullstack/packages/{{projectName}}-serv/src/server/procedures/app-procedures.ts.hbs +49 -0
  188. package/templates/apps/fullstack/packages/{{projectName}}-serv/src/server/procedures/index.ts.hbs +34 -0
  189. package/templates/apps/fullstack/packages/{{projectName}}-serv/src/server/runtime.ts.hbs +159 -0
  190. package/templates/apps/fullstack/packages/{{projectName}}-serv/src/server/security-roles.ts.hbs +73 -0
  191. package/templates/apps/fullstack/packages/{{projectName}}-serv/tests/app-server.test.ts.hbs +505 -0
  192. package/templates/apps/fullstack/packages/{{projectName}}-serv/tests/runtime.test.ts.hbs +72 -0
  193. package/templates/apps/fullstack/packages/{{projectName}}-serv/tests/security.test.ts.hbs +183 -0
  194. package/templates/apps/fullstack/packages/{{projectName}}-serv/tsconfig.json.hbs +10 -0
  195. package/templates/apps/fullstack/packages/{{projectName}}-serv/tsup.config.ts.hbs +18 -0
  196. package/templates/apps/fullstack/packages/{{projectName}}-serv/vitest.config.ts.hbs +12 -0
  197. package/templates/apps/fullstack/packages/{{projectName}}-shared/.gitignore.hbs +10 -0
  198. package/templates/apps/fullstack/packages/{{projectName}}-shared/README.md.hbs +97 -0
  199. package/templates/apps/fullstack/packages/{{projectName}}-shared/messages/en-US.json.hbs +164 -0
  200. package/templates/apps/fullstack/packages/{{projectName}}-shared/messages/ja-JP.json.hbs +164 -0
  201. package/templates/apps/fullstack/packages/{{projectName}}-shared/messages/zh-CN.json.hbs +164 -0
  202. package/templates/apps/fullstack/packages/{{projectName}}-shared/package.json.hbs +55 -0
  203. package/templates/apps/fullstack/packages/{{projectName}}-shared/project.inlang/settings.json.hbs +11 -0
  204. package/templates/apps/fullstack/packages/{{projectName}}-shared/src/index.ts.hbs +7 -0
  205. package/templates/apps/fullstack/packages/{{projectName}}-shared/src/lib/api/api-client.ts.hbs +94 -0
  206. package/templates/apps/fullstack/packages/{{projectName}}-shared/src/lib/api/feedback-client.ts.hbs +36 -0
  207. package/templates/apps/fullstack/packages/{{projectName}}-shared/src/lib/api/sensitive-actions.svelte.ts.hbs +16 -0
  208. package/templates/apps/fullstack/packages/{{projectName}}-shared/src/lib/api/session-recovery.svelte.ts.hbs +4 -0
  209. package/templates/apps/fullstack/packages/{{projectName}}-shared/src/lib/components/AdminWorkspace.svelte.hbs +122 -0
  210. package/templates/apps/fullstack/packages/{{projectName}}-shared/src/lib/components/AppShell.svelte.hbs +90 -0
  211. package/templates/apps/fullstack/packages/{{projectName}}-shared/src/lib/components/FeedbackEntry.svelte.hbs +86 -0
  212. package/templates/apps/fullstack/packages/{{projectName}}-shared/src/lib/pages/audit.svelte.hbs +94 -0
  213. package/templates/apps/fullstack/packages/{{projectName}}-shared/src/lib/pages/configuration.svelte.hbs +25 -0
  214. package/templates/apps/fullstack/packages/{{projectName}}-shared/src/lib/pages/feedback.svelte.hbs +157 -0
  215. package/templates/apps/fullstack/packages/{{projectName}}-shared/src/lib/pages/roles.svelte.hbs +77 -0
  216. package/templates/apps/fullstack/packages/{{projectName}}-shared/src/lib/pages/settings.svelte.hbs +44 -0
  217. package/templates/apps/fullstack/packages/{{projectName}}-shared/src/lib/pages/users.svelte.hbs +216 -0
  218. package/templates/apps/fullstack/packages/{{projectName}}-shared/src/lib/security/role-label.ts.hbs +12 -0
  219. package/templates/apps/fullstack/packages/{{projectName}}-shared/src/lib/stores/guide-store.ts.hbs +55 -0
  220. package/templates/apps/fullstack/packages/{{projectName}}-shared/src/lib/stores/management-store.svelte.ts.hbs +614 -0
  221. package/templates/apps/fullstack/packages/{{projectName}}-shared/src/lib/stores/theme-store.svelte.ts.hbs +23 -0
  222. package/templates/apps/fullstack/packages/{{projectName}}-shared/svelte.config.js.hbs +1 -0
  223. package/templates/apps/fullstack/packages/{{projectName}}-shared/tests/api-client.test.ts.hbs +150 -0
  224. package/templates/apps/fullstack/packages/{{projectName}}-shared/tests/management-store.test.ts.hbs +253 -0
  225. package/templates/apps/fullstack/packages/{{projectName}}-shared/tsconfig.json.hbs +17 -0
  226. package/templates/apps/fullstack/packages/{{projectName}}-shared/vitest.config.ts.hbs +7 -0
  227. package/templates/apps/fullstack/playwright.config.ts.hbs +114 -0
  228. package/templates/apps/fullstack/playwright.session-close.config.ts.hbs +18 -0
  229. package/templates/apps/fullstack/pnpm-workspace.yaml.hbs +38 -0
  230. package/templates/apps/fullstack/tsconfig.base.json +14 -0
  231. package/templates/apps/h5/messages/en-US.json +3 -0
  232. package/templates/apps/h5/messages/ja-JP.json +40 -0
  233. package/templates/apps/h5/messages/zh-CN.json +3 -0
  234. package/templates/apps/h5/src/routes/+layout.svelte.hbs +85 -30
  235. package/templates/apps/h5/src/routes/+page.svelte.hbs +20 -8
  236. package/templates/apps/h5/src/routes/discover/+page.svelte.hbs +17 -6
  237. package/templates/apps/h5/src/routes/profile/+page.svelte.hbs +17 -6
  238. package/templates/apps/mobile-app/.env.hbs +3 -0
  239. package/templates/apps/{android-app → mobile-app}/capacitor.config.ts.hbs +2 -2
  240. package/templates/apps/mobile-app/index.html.hbs +14 -0
  241. package/templates/apps/mobile-app/messages/en-US.json +36 -0
  242. package/templates/apps/mobile-app/messages/ja-JP.json +36 -0
  243. package/templates/apps/mobile-app/messages/zh-CN.json +36 -0
  244. package/templates/apps/mobile-app/public/runtime-config.js +1 -0
  245. package/templates/apps/mobile-app/src/App.svelte.hbs +153 -0
  246. package/templates/apps/mobile-app/src/lib/api.ts.hbs +213 -0
  247. package/templates/apps/mobile-app/src/lib/app-config.ts.hbs +14 -0
  248. package/templates/apps/{android-app → mobile-app}/src/lib/capacitor.ts +6 -7
  249. package/templates/apps/mobile-app/src/lib/pages/home.svelte.hbs +58 -0
  250. package/templates/apps/mobile-app/src/lib/pages/profile.svelte.hbs +13 -0
  251. package/templates/apps/mobile-app/src/lib/pages/tasks.svelte.hbs +16 -0
  252. package/templates/apps/mobile-app/src/main.ts.hbs +11 -0
  253. package/templates/apps/website/messages/en-US.json +4 -2
  254. package/templates/apps/website/messages/ja-JP.json +34 -0
  255. package/templates/apps/website/messages/zh-CN.json +4 -2
  256. package/templates/apps/website/scripts/static-website.mjs.hbs +67 -0
  257. package/templates/apps/website/src/routes/+layout.svelte.hbs +77 -26
  258. package/templates/apps/website/src/routes/+layout.ts +3 -0
  259. package/templates/apps/website/src/routes/+page.svelte.hbs +31 -12
  260. package/templates/apps/website/src/routes/about/+page.svelte.hbs +11 -6
  261. package/templates/apps/website/src/routes/api/health/+server.ts +3 -0
  262. package/templates/apps/website/src/routes/contact/+page.svelte.hbs +44 -34
  263. package/templates/apps/website/src/routes/services/+page.svelte.hbs +27 -40
  264. package/templates/base/.dockerignore.hbs +27 -0
  265. package/templates/base/.gitignore.hbs +41 -0
  266. package/templates/base/.npmrc.hbs +1 -0
  267. package/templates/base/e2e/app.spec.ts.hbs +213 -0
  268. package/templates/base/e2e/helpers.ts +1 -1
  269. package/templates/base/eslint-rules.js +45 -0
  270. package/templates/base/eslint.config.js.hbs +34 -0
  271. package/templates/base/hai.json.hbs +4 -0
  272. package/templates/base/images/web/nginx.conf.hbs +24 -0
  273. package/templates/base/images/web.Dockerfile.hbs +72 -0
  274. package/templates/base/package.json.hbs +125 -49
  275. package/templates/base/playwright.config.ts +44 -6
  276. package/templates/base/pnpm-workspace.yaml.hbs +40 -0
  277. package/templates/base/src/app.css.hbs +40 -0
  278. package/templates/base/src/app.d.ts.hbs +14 -1
  279. package/templates/base/src/app.html.hbs +13 -0
  280. package/templates/base/src/hooks.server.ts.hbs +115 -43
  281. package/templates/base/src/lib/build-metadata.ts.hbs +7 -0
  282. package/templates/base/src/lib/server/init.ts.hbs +125 -152
  283. package/templates/base/src/lib/server/kit-config.ts.hbs +40 -0
  284. package/templates/base/src/routes/+layout.server.ts.hbs +35 -0
  285. package/templates/base/static/favicon.png +0 -0
  286. package/templates/base/svelte.config.js.hbs +84 -5
  287. package/templates/base/tests/scaffold.test.ts.hbs +102 -0
  288. package/templates/base/tsconfig.json.hbs +50 -0
  289. package/templates/base/vite.config.ts.hbs +117 -12
  290. package/templates/base/vitest.config.ts.hbs +19 -0
  291. package/templates/features/ai/routes/api/chat/+server.ts +6 -7
  292. package/templates/features/iam/routes-admin/(auth)/+layout.svelte.hbs +3 -17
  293. package/templates/features/iam/routes-admin/(auth)/auth/forgot-password/+page.svelte.hbs +10 -0
  294. package/templates/features/iam/routes-admin/(auth)/auth/login/+page.svelte.hbs +9 -96
  295. package/templates/features/iam/routes-admin/(auth)/auth/register/+page.svelte.hbs +9 -122
  296. package/templates/features/iam/routes-admin/(auth)/auth/reset-password/+page.svelte.hbs +10 -0
  297. package/templates/features/iam/routes-h5/auth/forgot-password/+page.svelte.hbs +10 -0
  298. package/templates/features/iam/routes-h5/auth/login/+page.svelte.hbs +9 -96
  299. package/templates/features/iam/routes-h5/auth/register/+page.svelte.hbs +9 -112
  300. package/templates/features/iam/routes-h5/auth/reset-password/+page.svelte.hbs +10 -0
  301. package/templates/features/iam/routes-shared/api/auth/captcha/+server.ts.hbs +4 -0
  302. package/templates/features/iam/routes-shared/api/auth/config/+server.ts +4 -0
  303. package/templates/features/iam/routes-shared/api/auth/login/+server.ts +1 -29
  304. package/templates/features/iam/routes-shared/api/auth/login/ldap/+server.ts +4 -0
  305. package/templates/features/iam/routes-shared/api/auth/login/otp/+server.ts +4 -0
  306. package/templates/features/iam/routes-shared/api/auth/logout/+server.ts +13 -6
  307. package/templates/features/iam/routes-shared/api/auth/otp/send/+server.ts +4 -0
  308. package/templates/features/iam/routes-shared/api/auth/password/renew/+server.ts +5 -0
  309. package/templates/features/iam/routes-shared/api/auth/password-reset/confirm/+server.ts +4 -0
  310. package/templates/features/iam/routes-shared/api/auth/password-reset/request/+server.ts +4 -0
  311. package/templates/features/iam/routes-shared/api/auth/reauthenticate/+server.ts +5 -0
  312. package/templates/features/iam/routes-shared/api/auth/register/+server.ts +1 -23
  313. package/templates/features/iam/routes-shared/api/auth/session/close/+server.ts.hbs +4 -0
  314. package/templates/features/iam/routes-website/auth/forgot-password/+page.svelte.hbs +10 -0
  315. package/templates/features/iam/routes-website/auth/login/+page.svelte.hbs +11 -0
  316. package/templates/features/iam/routes-website/auth/register/+page.svelte.hbs +11 -0
  317. package/templates/features/iam/routes-website/auth/reset-password/+page.svelte.hbs +10 -0
  318. package/templates/features/payment/routes/api/v1/payment/create/+server.ts +25 -23
  319. package/templates/features/payment/routes/api/v1/payment/notify/[provider]/+server.ts +5 -2
  320. package/templates/features/storage/routes/api/upload/+server.ts +10 -8
  321. package/templates/i18n/project.inlang/settings.json +2 -2
  322. package/templates/shared/.gitattributes +11 -0
  323. package/templates/shared/build-metadata.ts +42 -0
  324. package/templates/shared/container-runtime-config.sh +30 -0
  325. package/templates/shared/e2e-env.ts +98 -0
  326. package/templates/shared/hash-router.svelte.ts +83 -0
  327. package/templates/shared/public-base-path.mjs +19 -0
  328. package/templates/shared/run-e2e.mjs +104 -0
  329. package/templates/shared/vite-runtime-config.ts +56 -0
  330. package/templates/skills/AGENTS.md +75 -16
  331. package/templates/skills/CLAUDE.md +0 -11
  332. package/templates/skills/bridges/admin/AGENTS.md +89 -0
  333. package/templates/skills/bridges/api/AGENTS.md +83 -0
  334. package/templates/skills/bridges/fullstack/AGENTS.md.hbs +102 -0
  335. package/templates/skills/bridges/h5/AGENTS.md +88 -0
  336. package/templates/skills/bridges/mobile-app/AGENTS.md +100 -0
  337. package/templates/skills/bridges/website/AGENTS.md +88 -0
  338. package/templates/skills/copilot-instructions.md +3 -59
  339. package/templates/skills/hai-ai/SKILL.md +44 -715
  340. package/templates/skills/hai-ai/guide.md +457 -0
  341. package/templates/skills/hai-ai/reference.md +292 -0
  342. package/templates/skills/hai-api-client/SKILL.md +26 -339
  343. package/templates/skills/hai-api-client/reference.md +180 -0
  344. package/templates/skills/hai-api-contract/SKILL.md +36 -0
  345. package/templates/skills/hai-api-contract/reference.md +280 -0
  346. package/templates/skills/hai-app-create/SKILL.md +38 -351
  347. package/templates/skills/hai-app-create/collaboration.md +52 -0
  348. package/templates/skills/hai-app-create/development.md +243 -0
  349. package/templates/skills/hai-app-create/reference.md +376 -0
  350. package/templates/skills/hai-app-review/SKILL.md +57 -126
  351. package/templates/skills/hai-app-review/differential.md +34 -0
  352. package/templates/skills/hai-app-tests/SKILL.md +34 -454
  353. package/templates/skills/hai-app-tests/reference.md +462 -0
  354. package/templates/skills/hai-app-tests/validation.md +42 -0
  355. package/templates/skills/hai-audit/SKILL.md +37 -122
  356. package/templates/skills/hai-audit/reference.md +184 -0
  357. package/templates/skills/hai-build/SKILL.md +62 -315
  358. package/templates/skills/hai-build/paths.md +30 -0
  359. package/templates/skills/hai-build/reference.md +353 -0
  360. package/templates/skills/hai-cache/SKILL.md +26 -175
  361. package/templates/skills/hai-cache/reference.md +229 -0
  362. package/templates/skills/hai-capacitor/SKILL.md +24 -364
  363. package/templates/skills/hai-capacitor/reference.md +358 -0
  364. package/templates/skills/hai-change-plan/SKILL.md +46 -0
  365. package/templates/skills/hai-ci/SKILL.md +114 -0
  366. package/templates/skills/hai-core/SKILL.md +31 -469
  367. package/templates/skills/hai-core/reference.md +557 -0
  368. package/templates/skills/hai-core/request-access.md +65 -0
  369. package/templates/skills/hai-crypto/SKILL.md +29 -180
  370. package/templates/skills/hai-crypto/reference.md +317 -0
  371. package/templates/skills/hai-datapipe/SKILL.md +24 -207
  372. package/templates/skills/hai-datapipe/reference.md +204 -0
  373. package/templates/skills/hai-deploy/SKILL.md +53 -178
  374. package/templates/skills/hai-deploy/credentials.md +19 -0
  375. package/templates/skills/hai-deploy/middleware.md +129 -0
  376. package/templates/skills/hai-feedback/SKILL.md +85 -0
  377. package/templates/skills/hai-framework-sync/SKILL.md +105 -0
  378. package/templates/skills/hai-framework-sync/sync.md +49 -0
  379. package/templates/skills/hai-iam/SKILL.md +53 -325
  380. package/templates/skills/hai-iam/reference.md +535 -0
  381. package/templates/skills/hai-kit/SKILL.md +33 -329
  382. package/templates/skills/hai-kit/reference.md +202 -0
  383. package/templates/skills/hai-payment/SKILL.md +28 -262
  384. package/templates/skills/hai-payment/reference.md +295 -0
  385. package/templates/skills/hai-pr-review/SKILL.md +41 -0
  386. package/templates/skills/hai-reach/SKILL.md +28 -300
  387. package/templates/skills/hai-reach/reference.md +363 -0
  388. package/templates/skills/hai-reldb/SKILL.md +28 -449
  389. package/templates/skills/hai-reldb/reference.md +500 -0
  390. package/templates/skills/hai-scheduler/SKILL.md +26 -174
  391. package/templates/skills/hai-scheduler/reference.md +216 -0
  392. package/templates/skills/hai-serv/SKILL.md +60 -0
  393. package/templates/skills/hai-serv/reference.md +792 -0
  394. package/templates/skills/hai-spec-implement/SKILL.md +50 -0
  395. package/templates/skills/hai-spec-implement/changes.md +67 -0
  396. package/templates/skills/hai-spec-implement/evaluation.md +18 -0
  397. package/templates/skills/hai-spec-implement/handoff.md +47 -0
  398. package/templates/skills/hai-spec-implement/templates.md +117 -0
  399. package/templates/skills/hai-spec-implement/workflow.md +56 -0
  400. package/templates/skills/hai-spec-review/SKILL.md +57 -0
  401. package/templates/skills/hai-spec-review/checklist.md +71 -0
  402. package/templates/skills/hai-storage/SKILL.md +31 -262
  403. package/templates/skills/hai-storage/reference.md +284 -0
  404. package/templates/skills/hai-ui/SKILL.md +62 -238
  405. package/templates/skills/hai-ui/guide.md +81 -0
  406. package/templates/skills/hai-ui/reference.md +705 -0
  407. package/templates/skills/hai-ui-design/SKILL.md +31 -0
  408. package/templates/skills/hai-ui-design/patterns.md +31 -0
  409. package/templates/skills/hai-ui-review/SKILL.md +32 -0
  410. package/templates/skills/hai-ui-review/checklist.md +29 -0
  411. package/templates/skills/hai-vecdb/SKILL.md +25 -267
  412. package/templates/skills/hai-vecdb/reference.md +325 -0
  413. package/templates/skills/opencode.json +0 -5
  414. package/dist/chunk-2H7UOFLK.js +0 -10
  415. package/dist/chunk-LANIDJC7.js +0 -659
  416. package/dist/chunk-LANIDJC7.js.map +0 -1
  417. package/dist/chunk-YV7WPUI6.js +0 -206
  418. package/dist/chunk-YV7WPUI6.js.map +0 -1
  419. package/dist/config-templates-S5RI2MC6.js +0 -5
  420. package/dist/config-templates-S5RI2MC6.js.map +0 -1
  421. package/dist/skill-templates-N5DU5FNX.js +0 -5
  422. package/dist/skill-templates-N5DU5FNX.js.map +0 -1
  423. package/dist/src-XJ6YXNAF.js +0 -15030
  424. package/dist/src-XJ6YXNAF.js.map +0 -1
  425. package/templates/apps/android-app/.env.hbs +0 -3
  426. package/templates/apps/android-app/messages/en-US.json +0 -24
  427. package/templates/apps/android-app/messages/zh-CN.json +0 -24
  428. package/templates/apps/android-app/src/lib/api.ts.hbs +0 -30
  429. package/templates/apps/android-app/src/routes/+layout.svelte.hbs +0 -42
  430. package/templates/apps/android-app/src/routes/+layout.ts +0 -7
  431. package/templates/apps/android-app/src/routes/+page.svelte.hbs +0 -27
  432. package/templates/apps/api/src/routes/+layout.svelte +0 -14
  433. package/templates/apps/api/src/routes/+page.svelte +0 -11
  434. package/templates/apps/api/src/routes/api/v1/health/+server.ts +0 -14
  435. package/templates/apps/api/src/routes/api/v1/items/+server.ts +0 -37
  436. package/templates/apps/api/src/routes/api/v1/items/[id]/+server.ts +0 -30
  437. package/templates/base/src/app.css +0 -2
  438. package/templates/base/tsconfig.json +0 -8
@@ -4,25 +4,50 @@
4
4
  * =============================================================================
5
5
  */
6
6
 
7
+ {{#if features.crypto}}
8
+ import type { TransportEncryptionOptions } from '@h-ai/kit'
9
+ {{/if}}
7
10
  import type { Handle } from '@sveltejs/kit'
11
+ {{#if features.cache}}
12
+ import process from 'node:process'
13
+ {{else}}
14
+ {{#if features.crypto}}
15
+ import process from 'node:process'
16
+ {{/if}}
17
+ {{/if}}
18
+ {{#if hasI18n}}
19
+ import { base } from '$app/paths'
20
+ {{else}}
21
+ {{#if features.iam}}
22
+ import { base } from '$app/paths'
23
+ {{else}}
24
+ {{#if features.crypto}}
25
+ import { base } from '$app/paths'
26
+ {{/if}}
27
+ {{/if}}
28
+ {{/if}}
29
+ {{#if hasI18n}}
30
+ import { paraglideMiddleware } from '$lib/paraglide/server.js'
31
+ {{/if}}
8
32
  import { initApp } from '$lib/server/init.js'
33
+ import { getKitConfig } from '$lib/server/kit-config.js'
34
+ {{#if features.cache}}
35
+ import { cache } from '@h-ai/cache'
36
+ {{/if}}
9
37
  import { core } from '@h-ai/core'
10
- import { kit } from '@h-ai/kit'
38
+ {{#if features.crypto}}
39
+ import { {{#if features.db}}createReldbTransportKeyStore{{else}}createInMemoryKeyStore{{/if}}, crypto, parseTransportServerKeyRing } from '@h-ai/crypto'
40
+ {{/if}}
11
41
  {{#if features.iam}}
12
42
  import { iam } from '@h-ai/iam'
13
43
  {{/if}}
44
+ import { kit } from '@h-ai/kit'
14
45
  {{#if features.crypto}}
15
- import { crypto } from '@h-ai/crypto'
46
+ {{#if features.db}}
47
+ import { reldb } from '@h-ai/reldb'
16
48
  {{/if}}
17
- {{#if hasI18n}}
18
- import { paraglideMiddleware } from '$lib/paraglide/server.js'
19
49
  {{/if}}
20
50
 
21
- {{#if features.crypto}}
22
- // 初始化加密模块(同步)
23
- crypto.init()
24
-
25
- {{/if}}
26
51
  // =============================================================================
27
52
  // 应用初始化
28
53
  // =============================================================================
@@ -59,19 +84,17 @@ const initHandle: Handle = async ({ event, resolve }) => {
59
84
  * API 请求跳过 paraglideMiddleware(不需要页面级 locale + 避免消耗 body)
60
85
  */
61
86
  const i18nHandle: Handle = async ({ event, resolve }) => {
62
- if (event.url.pathname.startsWith('/api/')) {
87
+ if (event.url.pathname.startsWith(`${base}/api/`)) {
63
88
  const locale = event.cookies.get('PARAGLIDE_LOCALE') ?? '{{defaultLocale}}'
64
89
  event.locals.locale = locale
65
- kit.i18n.setLocale(locale)
66
- return resolve(event)
90
+ return kit.i18n.runWithLocale(locale, () => resolve(event))
67
91
  }
68
92
 
69
93
  return paraglideMiddleware(event.request, async ({ locale }) => {
70
94
  event.locals.locale = locale
71
- kit.i18n.setLocale(locale)
72
- return resolve(event, {
95
+ return kit.i18n.runWithLocale(locale, () => resolve(event, {
73
96
  transformPageChunk: ({ html }) => html.replace('%lang%', locale),
74
- })
97
+ }))
75
98
  })
76
99
  }
77
100
 
@@ -80,35 +103,84 @@ const i18nHandle: Handle = async ({ event, resolve }) => {
80
103
  // hai Handle(会话验证 + 限流 + 日志)
81
104
  // =============================================================================
82
105
 
83
- const haiHandle = kit.createHandle({
84
- {{#if features.iam}}
85
- auth: {
86
- verifyToken: async (token) => {
87
- const result = await iam.auth.verifyToken(token)
88
- return result.success ? result.data : null
89
- },
90
- operations: iam.auth,
91
- loginUrl: '/auth/login',
92
- protectedPaths: ['/admin/*', '/api/*'],
93
- publicPaths: ['/api/auth/*', '/api/public/*', '/api/health'],
94
- },
95
- {{/if}}
96
- rateLimit: { windowMs: 60000, maxRequests: 200 },
97
- logging: { logBody: false },
98
- onError: (error: unknown, _event) => {
99
- core.logger.error('Request error:', { error })
100
- return new Response(
101
- JSON.stringify({
102
- success: false,
103
- error: {
104
- code: 'INTERNAL_ERROR',
105
- message: error instanceof Error ? error.message : 'Unknown error',
106
+ let configuredHandle: Handle | undefined
107
+ const haiHandle: Handle = async (input) => {
108
+ if (!configuredHandle) {
109
+ const settings = getKitConfig()
110
+ {{#if features.crypto}}
111
+ let transport: TransportEncryptionOptions | undefined
112
+ if (settings.transport !== false) {
113
+ {{#unless features.db}}
114
+ if (core.module.requiresSharedState(process.env))
115
+ throw new Error('Production transport requires the db feature and a shared database registry')
116
+ {{/unless}}
117
+ const ring = parseTransportServerKeyRing(process.env.HAI_CRYPTO_TRANSPORT_SERVERKEYRING)
118
+ if (!ring.success)
119
+ throw new Error(`HAI_CRYPTO_TRANSPORT_SERVERKEYRING: ${ring.error.message} (${ring.error.code})`)
120
+ transport = {
121
+ ...settings.transport,
122
+ basePath: base,
123
+ serverKeyRing: ring.data,
124
+ {{#if features.db}}
125
+ keyStore: createReldbTransportKeyStore({ reldb, ttlSeconds: 3600 }),
126
+ {{else}}
127
+ keyStore: createInMemoryKeyStore(),
128
+ {{/if}}
129
+ }
130
+ }
131
+ {{else}}
132
+ if (settings.transport !== false)
133
+ throw new Error('Transport encryption requires the crypto feature; add it before enabling kit.transport')
134
+ {{/if}}
135
+ configuredHandle = kit.createHandle({
136
+ trustedProxies: settings.trustedProxies,
137
+ access: settings.access,
138
+ {{#if features.crypto}}
139
+ crypto: { crypto, transport },
140
+ {{/if}}
141
+ {{#if features.iam}}
142
+ auth: {
143
+ verifyToken: async (token) => {
144
+ const result = await iam.auth.verifyToken(token)
145
+ if (!result.success)
146
+ return null
147
+ const session = result.data
148
+ // 映射为 kit 的 SessionData 形态(携带守卫所需的核心字段)
149
+ return {
150
+ userId: session.userId,
151
+ username: session.username,
152
+ roles: session.roles,
153
+ permissions: session.permissions,
154
+ data: session.data,
155
+ }
106
156
  },
107
- }),
108
- { status: 500, headers: { 'Content-Type': 'application/json' } },
109
- )
110
- },
111
- })
157
+ loginUrl: `${base}/auth/login`,
158
+ protectedPaths: ['/admin/*', '/api/*'].map(path => `${base}${path}`),
159
+ publicPaths: [...kit.auth.publicPaths, '/api/auth/logout', '/api/public/*', '/api/health'].map(path => `${base}${path}`),
160
+ operations: () => iam.auth,
161
+ },
162
+ {{/if}}
163
+ {{#if features.cache}}
164
+ rateLimit: { windowMs: 60000, maxRequests: 200, store: kit.middleware.createCacheRateLimitStore(cache, { namespace: '{{projectName}}', allowMemory: process.env.NODE_ENV !== 'production' || process.env.HAI_E2E === '1' }) },
165
+ {{else}}
166
+ // 未选择cache能力时不启用限流;启用前须接入共享原子store。
167
+ rateLimit: false,
168
+ {{/if}}
169
+ logging: { logBody: false },
170
+ onError: (error: unknown, _event) => {
171
+ core.logger.error('Request error:', { error })
172
+ return new Response(
173
+ JSON.stringify({
174
+ success: false,
175
+ error: core.error.toPublic({ code: 'INTERNAL_ERROR', message: '', httpStatus: 500 }),
176
+ }),
177
+ { status: 500, headers: { 'Content-Type': 'application/json' } },
178
+ )
179
+ },
180
+ })
181
+ }
182
+ return configuredHandle(input)
183
+ }
112
184
 
113
185
  // =============================================================================
114
186
  // 组合 Handle
@@ -0,0 +1,7 @@
1
+ {{! @skipIfEmpty }}
2
+ {{#if features.feedback}}
3
+ /** 当前应用编译时烘焙的产物身份;运行时配置不能覆盖。 */
4
+ declare const __HAI_BUILD_METADATA__: { appVersion: string, buildId: string, commit: string }
5
+
6
+ export const buildMetadata = __HAI_BUILD_METADATA__
7
+ {{/if}}
@@ -1,190 +1,163 @@
1
- /**
2
- * =============================================================================
3
- * {{projectName}} - 应用初始化
4
- * =============================================================================
5
- *
6
- * 统一管理所有模块的初始化流程。
7
- *
8
- * 初始化顺序:
9
- * 1. core.init — 加载配置文件(约定优于配置)
10
- {{#if features.db}}
11
- * 2. reldb.init — 数据库连接
1
+ /** 应用声明真实模块顺序;并发、失败回滚与关闭重试由 core 处理。 */
2
+ {{#if features.ai}}
3
+ import { ai, AIConfigSchema } from '@h-ai/ai'
4
+ {{/if}}
5
+ {{#if features.audit}}
6
+ import { audit, AuditInitConfigSchema } from '@h-ai/audit'
12
7
  {{/if}}
13
8
  {{#if features.cache}}
14
- * 3. cache.init — 缓存
9
+ import { cache, CacheConfigSchema } from '@h-ai/cache'
15
10
  {{/if}}
16
- {{#if features.storage}}
17
- * 4. storage.init — 文件存储(可选)
11
+ import { core } from '@h-ai/core'
12
+ {{#if features.crypto}}
13
+ import { crypto } from '@h-ai/crypto'
18
14
  {{/if}}
19
- {{#if features.reach}}
20
- * 5. reach.init — 触达服务(可选)
15
+ {{#if features.feedback}}
16
+ import { feedback } from '@h-ai/feedback'
21
17
  {{/if}}
22
18
  {{#if features.iam}}
23
- * 6. iam.init — 身份认证
19
+ import { iam, IamConfigSchema } from '@h-ai/iam'
24
20
  {{/if}}
25
- {{#if features.ai}}
26
- * 7. ai.init — AI 集成(可选)
21
+ {{#if features.reach}}
22
+ import { reach, ReachConfigSchema } from '@h-ai/reach'
27
23
  {{/if}}
28
- */
29
-
30
- import { core } from '@h-ai/core'
31
24
  {{#if features.db}}
32
25
  import { reldb, ReldbConfigSchema } from '@h-ai/reldb'
33
26
  {{/if}}
34
- {{#if features.cache}}
35
- import { cache, CacheConfigSchema } from '@h-ai/cache'
27
+ {{#if features.audit}}
28
+ {{#if features.scheduler}}
29
+ import { scheduler, SchedulerConfigSchema } from '@h-ai/scheduler'
36
30
  {{/if}}
37
- {{#if features.iam}}
38
- import type { IamConfigSettingsInput } from '@h-ai/iam'
39
- import { iam } from '@h-ai/iam'
40
31
  {{/if}}
41
32
  {{#if features.storage}}
42
- import type { StorageConfigInput } from '@h-ai/storage'
43
33
  import { storage, StorageConfigSchema } from '@h-ai/storage'
44
34
  {{/if}}
45
- {{#if features.ai}}
46
- import type { AIConfigInput } from '@h-ai/ai'
47
- import { ai } from '@h-ai/ai'
48
- {{/if}}
49
- {{#if features.reach}}
50
- import type { ReachConfigInput } from '@h-ai/reach'
51
- import { reach } from '@h-ai/reach'
52
- {{/if}}
53
- {{#if features.audit}}
54
- import { audit } from '@h-ai/audit'
55
- {{/if}}
56
-
57
- {{#if features.db}}
58
- type DbConfigInput = Parameters<typeof reldb.init>[0]
59
- {{/if}}
60
- {{#if features.cache}}
61
- type CacheConfigInput = Parameters<typeof cache.init>[0]
62
- {{/if}}
63
-
64
- let initialized = false
65
-
66
- /**
67
- * 初始化应用
68
- */
69
- export async function initApp(): Promise<void> {
70
- if (initialized)
71
- return
35
+ {{#if features.vecdb}}
36
+ import { vecdb, VecdbConfigSchema } from '@h-ai/vecdb'
37
+ {{/if}}
38
+ {{#if features.feedback}}
39
+ import { buildMetadata } from '../build-metadata.js'
40
+ {{/if}}
41
+
42
+ {{#if features.feedback}}
43
+ let feedbackRetry: ReturnType<typeof setTimeout> | undefined
44
+ let feedbackStarting: Promise<void> | undefined
45
+ let feedbackClosing = false
46
+ let feedbackFailure: string | number | undefined
47
+
48
+ /** 可选辅助能力独立重试;不能回滚已经就绪的 IAM 与业务模块。 */
49
+ function startFeedback(): Promise<void> {
50
+ if (feedbackStarting)
51
+ return feedbackStarting
52
+ feedbackClosing = false
53
+ feedbackStarting = (async () => {
54
+ try {
55
+ const result = await feedback.init({ ...core.config.getOrThrow<import('@h-ai/feedback').FeedbackConfigInput>('feedback'), ...buildMetadata })
56
+ if (!result.success) {
57
+ if (feedbackFailure !== result.error.code)
58
+ core.logger.warn('Optional feedback unavailable; business runtime remains ready', { module: 'feedback', code: result.error.code })
59
+ feedbackFailure = result.error.code
60
+ }
61
+ else {
62
+ feedbackFailure = undefined
63
+ }
64
+ }
65
+ catch {
66
+ if (feedbackFailure !== 'configuration')
67
+ core.logger.warn('Optional feedback configuration unavailable; business runtime remains ready', { module: 'feedback' })
68
+ feedbackFailure = 'configuration'
69
+ }
70
+ if (feedbackFailure && !feedbackClosing) {
71
+ feedbackRetry = setTimeout(() => {
72
+ feedbackRetry = undefined
73
+ void startFeedback()
74
+ }, 30000)
75
+ feedbackRetry.unref()
76
+ }
77
+ })().finally(() => { feedbackStarting = undefined })
78
+ return feedbackStarting
79
+ }
72
80
 
73
- // 1. 加载配置
74
- core.init({
75
- configDir: './config',
76
- logging: { level: 'info' },
77
- })
81
+ async function closeFeedback() {
82
+ feedbackClosing = true
83
+ if (feedbackRetry)
84
+ clearTimeout(feedbackRetry)
85
+ feedbackRetry = undefined
86
+ await feedbackStarting
87
+ return feedback.close()
88
+ }
78
89
 
79
- {{#if features.db}}
80
- // ─── 配置校验 ───
81
- const dbValidation = core.config.validate('db', ReldbConfigSchema)
82
- if (!dbValidation.success) {
83
- throw new Error(`DB config invalid: ${dbValidation.error.message}`)
84
- }
85
- {{/if}}
86
- {{#if features.cache}}
87
- const cacheValidation = core.config.validate('cache', CacheConfigSchema)
88
- if (!cacheValidation.success) {
89
- throw new Error(`Cache config invalid: ${cacheValidation.error.message}`)
90
- }
91
90
  {{/if}}
92
91
 
92
+ const runtime = core.module.createRuntime([
93
+ { name: 'configuration', start: () => { core.init({ configDir: './config' }) }, close: () => {} },
93
94
  {{#if features.db}}
94
- // ─── 获取配置 ───
95
- const dbConfig = core.config.getOrThrow<DbConfigInput>('db')
95
+ { name: 'reldb', start: async () => {
96
+ const config = ReldbConfigSchema.parse(core.config.getOrThrow('db'))
97
+ if (config.type === 'sqlite' && config.database !== ':memory:') {
98
+ const { mkdir } = await import('node:fs/promises')
99
+ const { dirname } = await import('node:path')
100
+ await mkdir(dirname(config.database), { recursive: true })
101
+ }
102
+ return reldb.init(config)
103
+ }, close: () => reldb.close() },
96
104
  {{/if}}
97
105
  {{#if features.cache}}
98
- const cacheConfig = core.config.getOrThrow<CacheConfigInput>('cache')
99
- {{/if}}
100
- {{#if features.iam}}
101
- const iamConfig = core.config.getOrThrow<IamConfigSettingsInput>('iam')
106
+ { name: 'cache', start: () => cache.init(CacheConfigSchema.parse(core.config.getOrThrow('cache'))), close: () => cache.close() },
102
107
  {{/if}}
103
- {{#if features.storage}}
104
- const storageConfig = core.config.get<StorageConfigInput>('storage')
105
- {{/if}}
106
- {{#if features.ai}}
107
- const aiConfig = core.config.get<AIConfigInput>('ai')
108
- {{/if}}
109
- {{#if features.reach}}
110
- const reachConfig = core.config.get<ReachConfigInput>('reach')
111
- {{/if}}
112
-
113
- {{#if features.db}}
114
- // ─── 确保数据目录存在(SQLite) ───
115
- if (dbConfig.type === 'sqlite') {
116
- const path = await import('node:path')
117
- const fs = await import('node:fs')
118
- const dbDir = path.dirname(dbConfig.database)
119
- if (!fs.existsSync(dbDir)) {
120
- fs.mkdirSync(dbDir, { recursive: true })
121
- }
122
- }
123
-
124
- // ─── 初始化数据库 ───
125
- const dbResult = await reldb.init(dbConfig)
126
- if (!dbResult.success) {
127
- throw new Error(`Database initialization failed: ${dbResult.error.message}`)
128
- }
108
+ {{#if features.vecdb}}
109
+ { name: 'vecdb', start: () => vecdb.init(VecdbConfigSchema.parse(core.config.getOrThrow('vecdb'))), close: () => vecdb.close() },
129
110
  {{/if}}
130
-
131
- {{#if features.cache}}
132
- // ─── 初始化缓存 ───
133
- const cacheResult = await cache.init(cacheConfig)
134
- if (!cacheResult.success) {
135
- throw new Error(`Cache initialization failed: ${cacheResult.error.message}`)
136
- }
111
+ {{#if features.crypto}}
112
+ { name: 'crypto', start: () => crypto.init(), close: () => crypto.close() },
137
113
  {{/if}}
138
-
139
114
  {{#if features.storage}}
140
- // ─── 初始化存储(可选) ───
141
- if (storageConfig) {
142
- const storageValidation = core.config.validate('storage', StorageConfigSchema)
143
- if (storageValidation.success) {
144
- const storageResult = await storage.init(storageConfig)
145
- if (!storageResult.success) {
146
- core.logger.warn('Storage initialization failed', { error: storageResult.error.message })
147
- }
148
- }
149
- }
115
+ { name: 'storage', start: () => storage.init(StorageConfigSchema.parse(core.config.getOrThrow('storage'))), close: () => storage.close() },
150
116
  {{/if}}
151
-
152
117
  {{#if features.reach}}
153
- // ─── 初始化触达服务(可选) ───
154
- if (reachConfig) {
155
- const reachResult = await reach.init(reachConfig)
156
- if (!reachResult.success) {
157
- core.logger.warn('Reach initialization failed', { error: reachResult.error.message })
158
- }
159
- }
118
+ { name: 'reach', enabled: () => Boolean(core.config.get('reach')), start: () => reach.init(ReachConfigSchema.parse(core.config.getOrThrow('reach'))), close: () => reach.close() },
119
+ {{/if}}
120
+ {{#if features.audit}}
121
+ { name: 'audit', start: () => audit.init({ ...AuditInitConfigSchema.parse(core.config.get('audit') ?? {}){{#if features.storage}}, storage{{/if}}{{#if features.reach}}, reach{{/if}} }), close: () => audit.close() },
160
122
  {{/if}}
161
-
162
123
  {{#if features.iam}}
163
- // ─── 初始化 IAM ───
164
- const iamResult = await iam.init(iamConfig)
165
- if (!iamResult.success) {
166
- throw new Error(`IAM initialization failed: ${iamResult.error.message}`)
167
- }
124
+ { name: 'iam', start: () => iam.init({ ...IamConfigSchema.parse(core.config.getOrThrow('iam')){{#if features.reach}}, reach{{/if}} }), close: () => iam.close() },
168
125
  {{/if}}
169
-
170
126
  {{#if features.audit}}
171
- // ─── 初始化审计 ───
172
- const auditResult = await audit.init()
173
- if (!auditResult.success) {
174
- core.logger.warn('Audit initialization failed', { error: auditResult.error.message })
175
- }
127
+ {{#if features.scheduler}}
128
+ { name: 'audit-jobs', enabled: () => Boolean(audit.schedulerPlan), start: async () => {
129
+ const schedule = audit.schedulerPlan
130
+ if (!schedule)
131
+ return
132
+ const initialized = await scheduler.init({ ...SchedulerConfigSchema.parse(core.config.get('scheduler') ?? {}), ...schedule })
133
+ if (!initialized.success)
134
+ return initialized
135
+ const started = scheduler.start()
136
+ if (!started.success)
137
+ await scheduler.close()
138
+ return started
139
+ }, close: () => scheduler.close() },
140
+ {{/if}}
141
+ {{/if}}
142
+ {{#if features.feedback}}
143
+ { name: 'feedback', enabled: () => Boolean(core.config.get('feedback')), start: startFeedback, close: closeFeedback },
176
144
  {{/if}}
177
-
178
145
  {{#if features.ai}}
179
- // ─── 初始化 AI(可选) ───
180
- if (aiConfig?.llm?.apiKey) {
181
- const aiResult = await ai.init(aiConfig)
182
- if (!aiResult.success) {
183
- core.logger.warn('AI initialization failed', { error: aiResult.error.message })
184
- }
185
- }
146
+ { name: 'ai', start: () => ai.init(AIConfigSchema.parse(core.config.getOrThrow('ai'))), close: () => ai.close() },
186
147
  {{/if}}
148
+ { name: 'bootstrap', start: () => { core.logger.info('Application initialized') }, close: () => {} },
149
+ ])
150
+
151
+ /** 启动失败只报告模块、错误码和配置路径,私密值不进入错误上下文。 */
152
+ export async function initApp(): Promise<void> {
153
+ const result = await runtime.start()
154
+ if (!result.success)
155
+ throw new Error(result.error.message, { cause: result.error })
156
+ }
187
157
 
188
- initialized = true
189
- core.logger.info('{{projectName}} initialized.')
158
+ /** 清理失败时保留依赖和清理义务,可再次调用。 */
159
+ export async function closeApp(): Promise<void> {
160
+ const result = await runtime.close()
161
+ if (!result.success)
162
+ throw new Error(result.error.message, { cause: result.error })
190
163
  }
@@ -0,0 +1,40 @@
1
+ {{! @skipIfEmpty }}
2
+ {{#unless isSvelteOnlyApp}}
3
+ import type { KitConfig } from '@h-ai/kit'
4
+ import { base } from '$app/paths'
5
+ import { core } from '@h-ai/core'
6
+ import { KitConfigSchema } from '@h-ai/kit'
7
+
8
+ let configured: KitConfig | undefined
9
+
10
+ /** 输入已由 Schema 校验为绝对路径;宿主补构建目录并保留绝对路径类型。 */
11
+ function mounted(path: string): `/${string}` {
12
+ if (!base || path === base || path.startsWith(`${base}/`))
13
+ return `/${path.slice(1)}`
14
+ return `/${base.slice(1)}${path}`
15
+ }
16
+
17
+ /** 启动时固定服务端配置;浏览器只能接收根 load 明确投影的 transport。 */
18
+ export function getKitConfig(): KitConfig {
19
+ if (configured)
20
+ return configured
21
+ const loaded = core.config.load('kit', './config/_kit.yml', KitConfigSchema)
22
+ if (!loaded.success)
23
+ throw new Error(loaded.error.message)
24
+ const transport = loaded.data.transport
25
+ configured = {
26
+ ...loaded.data,
27
+ transport: transport === false
28
+ ? false
29
+ : {
30
+ ...transport,
31
+ keyExchangePath: mounted(transport.keyExchangePath),
32
+ excludePaths: transport.excludePaths.map(mounted),
33
+ routePlaintextBytes: transport.routePlaintextBytes
34
+ ? Object.fromEntries(Object.entries(transport.routePlaintextBytes).map(([path, bytes]) => [mounted(path), bytes]))
35
+ : undefined,
36
+ },
37
+ }
38
+ return configured
39
+ }
40
+ {{/unless}}
@@ -0,0 +1,35 @@
1
+ {{! @skipIfEmpty }}
2
+ {{#unless isSvelteOnlyApp}}
3
+ import type { CoreConfig } from '@h-ai/core'
4
+ import type { KitPublicConfig } from '@h-ai/kit'
5
+ import { getKitConfig } from '$lib/server/kit-config.js'
6
+ import { core } from '@h-ai/core'
7
+ {{#if features.iam}}
8
+ import { iam } from '@h-ai/iam'
9
+ import { error } from '@sveltejs/kit'
10
+ {{/if}}
11
+
12
+ /** 只向浏览器提供公开配置,避免暴露日志上下文、凭证或其它模块配置。 */
13
+ export async function load() {
14
+ const config = core.config.getOrThrow<CoreConfig>('core')
15
+ {{#if features.iam}}
16
+ const publicConfig = await iam.getPublicConfig()
17
+ if (!publicConfig.success) {
18
+ core.logger.error('Failed to load public authentication configuration', { error: publicConfig.error })
19
+ error(503, { message: core.error.toPublic(publicConfig.error).message })
20
+ }
21
+ {{/if}}
22
+ return {
23
+ kitConfig: { transport: getKitConfig().transport } satisfies KitPublicConfig,
24
+ {{#if features.iam}}
25
+ iamPublicConfig: publicConfig.data,
26
+ {{/if}}
27
+ appConfig: {
28
+ name: config.name,
29
+ version: config.version,
30
+ env: config.env,
31
+ defaultLocale: config.defaultLocale,
32
+ },
33
+ }
34
+ }
35
+ {{/unless}}