@oyolincc/create 0.0.0-dev-20260513110237 → 0.0.0-dev-20260918103756

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 (419) hide show
  1. package/dist/index.d.mts +2 -2
  2. package/dist/index.mjs +2 -2
  3. package/dist/index.mjs.map +1 -1
  4. package/package.json +35 -17
  5. package/templates/hono-fullstack/.agents/skills/ask-matt/PHASE-BOUNDARIES.md +55 -0
  6. package/templates/hono-fullstack/.agents/skills/ask-matt/SKILL.md +90 -0
  7. package/templates/hono-fullstack/.agents/skills/ask-matt/agents/openai.yaml +5 -0
  8. package/templates/hono-fullstack/.agents/skills/code-review/SKILL.md +87 -0
  9. package/templates/hono-fullstack/.agents/skills/code-review/agents/openai.yaml +3 -0
  10. package/templates/hono-fullstack/.agents/skills/codebase-design/DEEPENING.md +37 -0
  11. package/templates/hono-fullstack/.agents/skills/codebase-design/DESIGN-IT-TWICE.md +44 -0
  12. package/templates/hono-fullstack/.agents/skills/codebase-design/SKILL.md +114 -0
  13. package/templates/hono-fullstack/.agents/skills/codebase-design/agents/openai.yaml +3 -0
  14. package/templates/hono-fullstack/.agents/skills/confirm-requirements/SKILL.md +25 -0
  15. package/templates/hono-fullstack/.agents/skills/diagnosing-bugs/SKILL.md +140 -0
  16. package/templates/hono-fullstack/.agents/skills/diagnosing-bugs/agents/openai.yaml +3 -0
  17. package/templates/hono-fullstack/.agents/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +44 -0
  18. package/templates/hono-fullstack/.agents/skills/domain-modeling/ADR-FORMAT.md +47 -0
  19. package/templates/hono-fullstack/.agents/skills/domain-modeling/CONTEXT-FORMAT.md +60 -0
  20. package/templates/hono-fullstack/.agents/skills/domain-modeling/SKILL.md +74 -0
  21. package/templates/hono-fullstack/.agents/skills/domain-modeling/agents/openai.yaml +3 -0
  22. package/templates/hono-fullstack/.agents/skills/grill-me/SKILL.md +7 -0
  23. package/templates/hono-fullstack/.agents/skills/grill-me/agents/openai.yaml +5 -0
  24. package/templates/hono-fullstack/.agents/skills/grilling/SKILL.md +22 -0
  25. package/templates/hono-fullstack/.agents/skills/grilling/agents/openai.yaml +3 -0
  26. package/templates/hono-fullstack/.agents/skills/implement/SKILL.md +15 -0
  27. package/templates/hono-fullstack/.agents/skills/implement/agents/openai.yaml +5 -0
  28. package/templates/hono-fullstack/.agents/skills/improve-codebase-architecture/HTML-REPORT.md +123 -0
  29. package/templates/hono-fullstack/.agents/skills/improve-codebase-architecture/SKILL.md +71 -0
  30. package/templates/hono-fullstack/.agents/skills/improve-codebase-architecture/agents/openai.yaml +5 -0
  31. package/templates/hono-fullstack/.agents/skills/prototype/LOGIC.md +67 -0
  32. package/templates/hono-fullstack/.agents/skills/prototype/SKILL.md +26 -0
  33. package/templates/hono-fullstack/.agents/skills/prototype/UI.md +112 -0
  34. package/templates/hono-fullstack/.agents/skills/prototype/agents/openai.yaml +3 -0
  35. package/templates/hono-fullstack/.agents/skills/research/SKILL.md +12 -0
  36. package/templates/hono-fullstack/.agents/skills/research/agents/openai.yaml +3 -0
  37. package/templates/hono-fullstack/.agents/skills/resolving-merge-conflicts/SKILL.md +14 -0
  38. package/templates/hono-fullstack/.agents/skills/resolving-merge-conflicts/agents/openai.yaml +3 -0
  39. package/templates/hono-fullstack/.agents/skills/scoped-code-review/SKILL.md +113 -0
  40. package/templates/hono-fullstack/.agents/skills/setup-matt-pocock-skills/SKILL.md +116 -0
  41. package/templates/hono-fullstack/.agents/skills/setup-matt-pocock-skills/agents/openai.yaml +5 -0
  42. package/templates/hono-fullstack/.agents/skills/setup-matt-pocock-skills/domain.md +51 -0
  43. package/templates/hono-fullstack/.agents/skills/setup-matt-pocock-skills/issue-tracker-github.md +45 -0
  44. package/templates/hono-fullstack/.agents/skills/setup-matt-pocock-skills/issue-tracker-gitlab.md +46 -0
  45. package/templates/hono-fullstack/.agents/skills/setup-matt-pocock-skills/issue-tracker-local.md +30 -0
  46. package/templates/hono-fullstack/.agents/skills/setup-matt-pocock-skills/triage-labels.md +15 -0
  47. package/templates/hono-fullstack/.agents/skills/tdd/SKILL.md +38 -0
  48. package/templates/hono-fullstack/.agents/skills/tdd/agents/openai.yaml +3 -0
  49. package/templates/hono-fullstack/.agents/skills/tdd/mocking.md +59 -0
  50. package/templates/hono-fullstack/.agents/skills/tdd/tests.md +77 -0
  51. package/templates/hono-fullstack/.agents/skills/teach/GLOSSARY-FORMAT.md +35 -0
  52. package/templates/hono-fullstack/.agents/skills/teach/LEARNING-RECORD-FORMAT.md +46 -0
  53. package/templates/hono-fullstack/.agents/skills/teach/MISSION-FORMAT.md +31 -0
  54. package/templates/hono-fullstack/.agents/skills/teach/RESOURCES-FORMAT.md +32 -0
  55. package/templates/hono-fullstack/.agents/skills/teach/SKILL.md +140 -0
  56. package/templates/hono-fullstack/.agents/skills/teach/agents/openai.yaml +5 -0
  57. package/templates/hono-fullstack/.agents/skills/to-questionnaire/SKILL.md +53 -0
  58. package/templates/hono-fullstack/.agents/skills/to-questionnaire/agents/openai.yaml +5 -0
  59. package/templates/hono-fullstack/.agents/skills/triage/AGENT-BRIEF.md +207 -0
  60. package/templates/hono-fullstack/.agents/skills/triage/OUT-OF-SCOPE.md +105 -0
  61. package/templates/hono-fullstack/.agents/skills/triage/SKILL.md +112 -0
  62. package/templates/hono-fullstack/.agents/skills/triage/agents/openai.yaml +5 -0
  63. package/templates/hono-fullstack/.agents/skills/wait-what/SKILL.md +7 -0
  64. package/templates/hono-fullstack/.agents/skills/wait-what/agents/openai.yaml +5 -0
  65. package/templates/hono-fullstack/.agents/skills/wayfinder/SKILL.md +128 -0
  66. package/templates/hono-fullstack/.agents/skills/wayfinder/agents/openai.yaml +5 -0
  67. package/templates/hono-fullstack/.agents/skills/wizard/SKILL.md +44 -0
  68. package/templates/hono-fullstack/.agents/skills/wizard/agents/openai.yaml +3 -0
  69. package/templates/hono-fullstack/.agents/skills/wizard/template.sh +204 -0
  70. package/templates/hono-fullstack/.agents/skills/writing-for-agents/SKILL-MECHANICS.md +22 -0
  71. package/templates/hono-fullstack/.agents/skills/writing-for-agents/SKILL.md +81 -0
  72. package/templates/hono-fullstack/.agents/skills/writing-for-agents/agents/openai.yaml +3 -0
  73. package/templates/hono-fullstack/.changeset/README.md +8 -0
  74. package/templates/hono-fullstack/.changeset/config.json +11 -0
  75. package/templates/hono-fullstack/.vscode/extensions.json +5 -0
  76. package/templates/hono-fullstack/.vscode/launch.json +25 -0
  77. package/templates/hono-fullstack/.vscode/settings.json +24 -0
  78. package/templates/hono-fullstack/AGENTS.md +43 -0
  79. package/templates/hono-fullstack/README.md +37 -0
  80. package/templates/hono-fullstack/_gitignore +30 -0
  81. package/templates/hono-fullstack/apps/server/package.json +56 -0
  82. package/templates/hono-fullstack/apps/server/src/adapters/nodejs/bootstrap.ts +64 -0
  83. package/templates/hono-fullstack/apps/server/src/adapters/nodejs/config.ts +53 -0
  84. package/templates/hono-fullstack/apps/server/src/adapters/nodejs/entry.ts +47 -0
  85. package/templates/hono-fullstack/apps/server/src/app.test.ts +52 -0
  86. package/templates/hono-fullstack/apps/server/src/app.ts +45 -0
  87. package/templates/hono-fullstack/apps/server/src/infra/logger/getter.ts +74 -0
  88. package/templates/hono-fullstack/apps/server/src/infra/logger/pino.ts +122 -0
  89. package/templates/hono-fullstack/apps/server/src/infra/work-runner/constants.ts +23 -0
  90. package/templates/hono-fullstack/apps/server/src/infra/work-runner/errors.ts +40 -0
  91. package/templates/hono-fullstack/apps/server/src/infra/work-runner/example/runner.test.ts +56 -0
  92. package/templates/hono-fullstack/apps/server/src/infra/work-runner/example/runner.ts +185 -0
  93. package/templates/hono-fullstack/apps/server/src/infra/work-runner/example/worker-entry.ts +34 -0
  94. package/templates/hono-fullstack/apps/server/src/infra/work-runner/types.ts +113 -0
  95. package/templates/hono-fullstack/apps/server/src/infra/work-runner/utils/business-error.ts +19 -0
  96. package/templates/hono-fullstack/apps/server/src/infra/work-runner/utils/message.ts +46 -0
  97. package/templates/hono-fullstack/apps/server/src/infra/work-runner/utils/transfer.ts +144 -0
  98. package/templates/hono-fullstack/apps/server/src/middlewares/cors.ts +26 -0
  99. package/templates/hono-fullstack/apps/server/src/modules/example/contracts.ts +9 -0
  100. package/templates/hono-fullstack/apps/server/src/modules/example/routes.ts +75 -0
  101. package/templates/hono-fullstack/apps/server/src/modules/example/work-task/tasks.test.ts +37 -0
  102. package/templates/hono-fullstack/apps/server/src/modules/example/work-task/tasks.ts +35 -0
  103. package/templates/hono-fullstack/apps/server/src/shared/app/types.ts +40 -0
  104. package/templates/hono-fullstack/apps/server/src/shared/errors/constants.ts +152 -0
  105. package/templates/hono-fullstack/apps/server/src/shared/errors/defs/index.ts +15 -0
  106. package/templates/hono-fullstack/apps/server/src/shared/errors/handler.ts +16 -0
  107. package/templates/hono-fullstack/apps/server/src/shared/errors/log.ts +67 -0
  108. package/templates/hono-fullstack/apps/server/src/shared/errors/proto.ts +42 -0
  109. package/templates/hono-fullstack/apps/server/src/shared/errors/types.ts +29 -0
  110. package/templates/hono-fullstack/apps/server/src/shared/network/fetcher.ts +35 -0
  111. package/templates/hono-fullstack/apps/server/src/shared/network/openapi/index.ts +50 -0
  112. package/templates/hono-fullstack/apps/server/src/shared/network/openapi/res-defs.ts +39 -0
  113. package/templates/hono-fullstack/apps/server/src/shared/network/types.ts +3 -0
  114. package/templates/hono-fullstack/apps/server/src/shared/network/utils.ts +36 -0
  115. package/templates/hono-fullstack/apps/server/src/shared/network/validator.ts +21 -0
  116. package/templates/hono-fullstack/apps/server/src/shared/utils/index.ts +30 -0
  117. package/templates/hono-fullstack/apps/server/src/virtual-modules.d.ts +5 -0
  118. package/templates/hono-fullstack/apps/server/tsconfig.json +16 -0
  119. package/templates/hono-fullstack/apps/server/vite.config.ts +79 -0
  120. package/templates/hono-fullstack/apps/stack/frontend/modules/example/ExamplePage.tsx +57 -0
  121. package/templates/hono-fullstack/apps/stack/frontend/modules/example/api.ts +13 -0
  122. package/templates/hono-fullstack/apps/stack/frontend/modules/example/hooks.ts +13 -0
  123. package/templates/hono-fullstack/apps/stack/frontend/routeTree.gen.ts +56 -0
  124. package/templates/hono-fullstack/apps/stack/frontend/router.tsx +22 -0
  125. package/templates/hono-fullstack/apps/stack/frontend/routes/__root.tsx +61 -0
  126. package/templates/hono-fullstack/apps/stack/frontend/routes/index.tsx +4 -0
  127. package/templates/hono-fullstack/apps/stack/frontend/shared/network/client.ts +19 -0
  128. package/templates/hono-fullstack/apps/stack/frontend/shared/network/constants.ts +1 -0
  129. package/templates/hono-fullstack/apps/stack/frontend/shared/network/errors.ts +33 -0
  130. package/templates/hono-fullstack/apps/stack/frontend/styles.css +23 -0
  131. package/templates/hono-fullstack/apps/stack/frontend/vite-env.d.ts +1 -0
  132. package/templates/hono-fullstack/apps/stack/nitro/handlers/hono.ts +1 -0
  133. package/templates/hono-fullstack/apps/stack/nitro/plugins/hono.ts +9 -0
  134. package/templates/hono-fullstack/apps/stack/package.json +43 -0
  135. package/templates/hono-fullstack/apps/stack/tsconfig.json +10 -0
  136. package/templates/hono-fullstack/apps/stack/tsr.config.json +5 -0
  137. package/templates/hono-fullstack/apps/stack/vite.config.ts +33 -0
  138. package/templates/hono-fullstack/docs/agents/domain.md +41 -0
  139. package/templates/hono-fullstack/docs/agents/issue-tracker.md +30 -0
  140. package/templates/hono-fullstack/docs/agents/triage-labels.md +15 -0
  141. package/templates/hono-fullstack/envs/.env.example.server +12 -0
  142. package/templates/hono-fullstack/envs/.env.example.sqlite +2 -0
  143. package/templates/hono-fullstack/libs/db/drizzle-kit/sqlite.config.ts +22 -0
  144. package/templates/hono-fullstack/libs/db/package.json +39 -0
  145. package/templates/hono-fullstack/libs/db/src/dialects/sqlite/client.ts +35 -0
  146. package/templates/hono-fullstack/libs/db/src/dialects/sqlite/schema/columns.ts +32 -0
  147. package/templates/hono-fullstack/libs/db/src/dialects/sqlite/schema/index.ts +7 -0
  148. package/templates/hono-fullstack/libs/db/src/dialects/sqlite/schema/modules/examples/examples.ts +22 -0
  149. package/templates/hono-fullstack/libs/db/src/dialects/sqlite/schema/relations.ts +5 -0
  150. package/templates/hono-fullstack/libs/db/src/dialects/sqlite/schema/tables.ts +5 -0
  151. package/templates/hono-fullstack/libs/db/src/dialects/sqlite/schema/types.ts +7 -0
  152. package/templates/hono-fullstack/libs/db/src/dialects/sqlite/schema/vo.ts +1 -0
  153. package/templates/hono-fullstack/libs/db/src/dialects/sqlite/utils.ts +8 -0
  154. package/templates/hono-fullstack/libs/db/src/shared/types.ts +26 -0
  155. package/templates/hono-fullstack/libs/db/tsconfig.json +10 -0
  156. package/templates/hono-fullstack/libs/db/vite.config.ts +21 -0
  157. package/templates/hono-fullstack/libs/definition/package.json +30 -0
  158. package/templates/hono-fullstack/libs/definition/src/backend.ts +2 -0
  159. package/templates/hono-fullstack/libs/definition/src/configs/defs/log.ts +53 -0
  160. package/templates/hono-fullstack/libs/definition/src/configs/defs/middleware.ts +16 -0
  161. package/templates/hono-fullstack/libs/definition/src/configs/defs/runtime.ts +11 -0
  162. package/templates/hono-fullstack/libs/definition/src/configs/defs/sqlite.ts +13 -0
  163. package/templates/hono-fullstack/libs/definition/src/configs/defs/worker.ts +29 -0
  164. package/templates/hono-fullstack/libs/definition/src/configs/index.ts +5 -0
  165. package/templates/hono-fullstack/libs/definition/src/configs/proto.ts +81 -0
  166. package/templates/hono-fullstack/libs/definition/src/configs/schema.ts +23 -0
  167. package/templates/hono-fullstack/libs/definition/src/frontend.ts +1 -0
  168. package/templates/hono-fullstack/libs/definition/src/modules/example/index.ts +16 -0
  169. package/templates/hono-fullstack/libs/definition/src/modules/index.ts +1 -0
  170. package/templates/hono-fullstack/libs/definition/tsconfig.json +5 -0
  171. package/templates/hono-fullstack/libs/definition/vite.config.ts +13 -0
  172. package/templates/hono-fullstack/oyo.config.json +12 -0
  173. package/templates/hono-fullstack/package.json +29 -0
  174. package/templates/hono-fullstack/pnpm-workspace.yaml +82 -0
  175. package/templates/hono-fullstack/tsconfig.json +4 -0
  176. package/templates/hono-fullstack/turbo.json +13 -0
  177. package/templates/hono-fullstack/vite.config.ts +13 -0
  178. package/templates/hono-server/.agents/skills/ask-matt/PHASE-BOUNDARIES.md +55 -0
  179. package/templates/hono-server/.agents/skills/ask-matt/SKILL.md +90 -0
  180. package/templates/hono-server/.agents/skills/ask-matt/agents/openai.yaml +5 -0
  181. package/templates/hono-server/.agents/skills/code-review/SKILL.md +87 -0
  182. package/templates/hono-server/.agents/skills/code-review/agents/openai.yaml +3 -0
  183. package/templates/hono-server/.agents/skills/codebase-design/DEEPENING.md +37 -0
  184. package/templates/hono-server/.agents/skills/codebase-design/DESIGN-IT-TWICE.md +44 -0
  185. package/templates/hono-server/.agents/skills/codebase-design/SKILL.md +114 -0
  186. package/templates/hono-server/.agents/skills/codebase-design/agents/openai.yaml +3 -0
  187. package/templates/hono-server/.agents/skills/confirm-requirements/SKILL.md +25 -0
  188. package/templates/hono-server/.agents/skills/diagnosing-bugs/SKILL.md +140 -0
  189. package/templates/hono-server/.agents/skills/diagnosing-bugs/agents/openai.yaml +3 -0
  190. package/templates/hono-server/.agents/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +44 -0
  191. package/templates/hono-server/.agents/skills/domain-modeling/ADR-FORMAT.md +47 -0
  192. package/templates/hono-server/.agents/skills/domain-modeling/CONTEXT-FORMAT.md +60 -0
  193. package/templates/hono-server/.agents/skills/domain-modeling/SKILL.md +74 -0
  194. package/templates/hono-server/.agents/skills/domain-modeling/agents/openai.yaml +3 -0
  195. package/templates/hono-server/.agents/skills/grill-me/SKILL.md +7 -0
  196. package/templates/hono-server/.agents/skills/grill-me/agents/openai.yaml +5 -0
  197. package/templates/hono-server/.agents/skills/grilling/SKILL.md +22 -0
  198. package/templates/hono-server/.agents/skills/grilling/agents/openai.yaml +3 -0
  199. package/templates/hono-server/.agents/skills/implement/SKILL.md +15 -0
  200. package/templates/hono-server/.agents/skills/implement/agents/openai.yaml +5 -0
  201. package/templates/hono-server/.agents/skills/improve-codebase-architecture/HTML-REPORT.md +123 -0
  202. package/templates/hono-server/.agents/skills/improve-codebase-architecture/SKILL.md +71 -0
  203. package/templates/hono-server/.agents/skills/improve-codebase-architecture/agents/openai.yaml +5 -0
  204. package/templates/hono-server/.agents/skills/prototype/LOGIC.md +67 -0
  205. package/templates/hono-server/.agents/skills/prototype/SKILL.md +26 -0
  206. package/templates/hono-server/.agents/skills/prototype/UI.md +112 -0
  207. package/templates/hono-server/.agents/skills/prototype/agents/openai.yaml +3 -0
  208. package/templates/hono-server/.agents/skills/research/SKILL.md +12 -0
  209. package/templates/hono-server/.agents/skills/research/agents/openai.yaml +3 -0
  210. package/templates/hono-server/.agents/skills/resolving-merge-conflicts/SKILL.md +14 -0
  211. package/templates/hono-server/.agents/skills/resolving-merge-conflicts/agents/openai.yaml +3 -0
  212. package/templates/hono-server/.agents/skills/scoped-code-review/SKILL.md +113 -0
  213. package/templates/hono-server/.agents/skills/setup-matt-pocock-skills/SKILL.md +116 -0
  214. package/templates/hono-server/.agents/skills/setup-matt-pocock-skills/agents/openai.yaml +5 -0
  215. package/templates/hono-server/.agents/skills/setup-matt-pocock-skills/domain.md +51 -0
  216. package/templates/hono-server/.agents/skills/setup-matt-pocock-skills/issue-tracker-github.md +45 -0
  217. package/templates/hono-server/.agents/skills/setup-matt-pocock-skills/issue-tracker-gitlab.md +46 -0
  218. package/templates/hono-server/.agents/skills/setup-matt-pocock-skills/issue-tracker-local.md +30 -0
  219. package/templates/hono-server/.agents/skills/setup-matt-pocock-skills/triage-labels.md +15 -0
  220. package/templates/hono-server/.agents/skills/tdd/SKILL.md +38 -0
  221. package/templates/hono-server/.agents/skills/tdd/agents/openai.yaml +3 -0
  222. package/templates/hono-server/.agents/skills/tdd/mocking.md +59 -0
  223. package/templates/hono-server/.agents/skills/tdd/tests.md +77 -0
  224. package/templates/hono-server/.agents/skills/teach/GLOSSARY-FORMAT.md +35 -0
  225. package/templates/hono-server/.agents/skills/teach/LEARNING-RECORD-FORMAT.md +46 -0
  226. package/templates/hono-server/.agents/skills/teach/MISSION-FORMAT.md +31 -0
  227. package/templates/hono-server/.agents/skills/teach/RESOURCES-FORMAT.md +32 -0
  228. package/templates/hono-server/.agents/skills/teach/SKILL.md +140 -0
  229. package/templates/hono-server/.agents/skills/teach/agents/openai.yaml +5 -0
  230. package/templates/hono-server/.agents/skills/to-questionnaire/SKILL.md +53 -0
  231. package/templates/hono-server/.agents/skills/to-questionnaire/agents/openai.yaml +5 -0
  232. package/templates/hono-server/.agents/skills/triage/AGENT-BRIEF.md +207 -0
  233. package/templates/hono-server/.agents/skills/triage/OUT-OF-SCOPE.md +105 -0
  234. package/templates/hono-server/.agents/skills/triage/SKILL.md +112 -0
  235. package/templates/hono-server/.agents/skills/triage/agents/openai.yaml +5 -0
  236. package/templates/hono-server/.agents/skills/wait-what/SKILL.md +7 -0
  237. package/templates/hono-server/.agents/skills/wait-what/agents/openai.yaml +5 -0
  238. package/templates/hono-server/.agents/skills/wayfinder/SKILL.md +128 -0
  239. package/templates/hono-server/.agents/skills/wayfinder/agents/openai.yaml +5 -0
  240. package/templates/hono-server/.agents/skills/wizard/SKILL.md +44 -0
  241. package/templates/hono-server/.agents/skills/wizard/agents/openai.yaml +3 -0
  242. package/templates/hono-server/.agents/skills/wizard/template.sh +204 -0
  243. package/templates/hono-server/.agents/skills/writing-for-agents/SKILL-MECHANICS.md +22 -0
  244. package/templates/hono-server/.agents/skills/writing-for-agents/SKILL.md +81 -0
  245. package/templates/hono-server/.agents/skills/writing-for-agents/agents/openai.yaml +3 -0
  246. package/templates/hono-server/.changeset/README.md +8 -0
  247. package/templates/hono-server/.changeset/config.json +11 -0
  248. package/templates/hono-server/.editorconfig +31 -0
  249. package/templates/hono-server/.gitattributes +39 -0
  250. package/templates/hono-server/.vscode/extensions.json +5 -0
  251. package/templates/hono-server/.vscode/launch.json +25 -0
  252. package/templates/hono-server/.vscode/settings.json +24 -0
  253. package/templates/hono-server/AGENTS.md +43 -0
  254. package/templates/hono-server/README.md +31 -0
  255. package/templates/hono-server/_gitignore +30 -0
  256. package/templates/hono-server/apps/server/package.json +55 -0
  257. package/templates/hono-server/apps/server/src/adapters/nodejs/bootstrap.ts +61 -0
  258. package/templates/hono-server/apps/server/src/adapters/nodejs/config.ts +53 -0
  259. package/templates/hono-server/apps/server/src/adapters/nodejs/entry.ts +40 -0
  260. package/templates/hono-server/apps/server/src/app.test.ts +52 -0
  261. package/templates/hono-server/apps/server/src/app.ts +45 -0
  262. package/templates/hono-server/apps/server/src/infra/logger/getter.ts +74 -0
  263. package/templates/hono-server/apps/server/src/infra/logger/pino.ts +122 -0
  264. package/templates/hono-server/apps/server/src/infra/work-runner/constants.ts +23 -0
  265. package/templates/hono-server/apps/server/src/infra/work-runner/errors.ts +40 -0
  266. package/templates/hono-server/apps/server/src/infra/work-runner/example/runner.test.ts +56 -0
  267. package/templates/hono-server/apps/server/src/infra/work-runner/example/runner.ts +185 -0
  268. package/templates/hono-server/apps/server/src/infra/work-runner/example/worker-entry.ts +34 -0
  269. package/templates/hono-server/apps/server/src/infra/work-runner/types.ts +113 -0
  270. package/templates/hono-server/apps/server/src/infra/work-runner/utils/business-error.ts +19 -0
  271. package/templates/hono-server/apps/server/src/infra/work-runner/utils/message.ts +46 -0
  272. package/templates/hono-server/apps/server/src/infra/work-runner/utils/transfer.ts +144 -0
  273. package/templates/hono-server/apps/server/src/middlewares/cors.ts +26 -0
  274. package/templates/hono-server/apps/server/src/modules/example/contracts.ts +5 -0
  275. package/templates/hono-server/apps/server/src/modules/example/routes.ts +46 -0
  276. package/templates/hono-server/apps/server/src/modules/example/work-task/tasks.test.ts +37 -0
  277. package/templates/hono-server/apps/server/src/modules/example/work-task/tasks.ts +35 -0
  278. package/templates/hono-server/apps/server/src/shared/app/types.ts +40 -0
  279. package/templates/hono-server/apps/server/src/shared/errors/constants.ts +152 -0
  280. package/templates/hono-server/apps/server/src/shared/errors/defs/index.ts +15 -0
  281. package/templates/hono-server/apps/server/src/shared/errors/handler.ts +16 -0
  282. package/templates/hono-server/apps/server/src/shared/errors/log.ts +67 -0
  283. package/templates/hono-server/apps/server/src/shared/errors/proto.ts +42 -0
  284. package/templates/hono-server/apps/server/src/shared/errors/types.ts +29 -0
  285. package/templates/hono-server/apps/server/src/shared/network/fetcher.ts +35 -0
  286. package/templates/hono-server/apps/server/src/shared/network/openapi/index.ts +50 -0
  287. package/templates/hono-server/apps/server/src/shared/network/openapi/res-defs.ts +39 -0
  288. package/templates/hono-server/apps/server/src/shared/network/types.ts +3 -0
  289. package/templates/hono-server/apps/server/src/shared/network/utils.ts +36 -0
  290. package/templates/hono-server/apps/server/src/shared/network/validator.ts +21 -0
  291. package/templates/hono-server/apps/server/src/shared/utils/index.ts +30 -0
  292. package/templates/hono-server/apps/server/src/virtual-modules.d.ts +5 -0
  293. package/templates/hono-server/apps/server/tsconfig.json +16 -0
  294. package/templates/hono-server/apps/server/vite.config.ts +79 -0
  295. package/templates/hono-server/docker/.env.example +4 -0
  296. package/templates/hono-server/docker/README.md +5 -0
  297. package/templates/hono-server/docker/local/compose.local.app.yml +21 -0
  298. package/templates/hono-server/docker/local/local-app-deploy.sh +8 -0
  299. package/templates/hono-server/docker/local/local-app-down.sh +8 -0
  300. package/templates/hono-server/docker/prod/.env.example.server +11 -0
  301. package/templates/hono-server/docker/prod/compose.prod.stack.yml +21 -0
  302. package/templates/hono-server/docker/prod/update.sh +7 -0
  303. package/templates/hono-server/docker/server.Dockerfile +40 -0
  304. package/templates/hono-server/docker/server.Dockerfile.dockerignore +23 -0
  305. package/templates/hono-server/docs/agents/domain.md +41 -0
  306. package/templates/hono-server/docs/agents/issue-tracker.md +30 -0
  307. package/templates/hono-server/docs/agents/triage-labels.md +15 -0
  308. package/templates/hono-server/envs/.env.example.server +12 -0
  309. package/templates/hono-server/libs/definition/package.json +29 -0
  310. package/templates/hono-server/libs/definition/src/backend.ts +2 -0
  311. package/templates/hono-server/libs/definition/src/configs/defs/log.ts +53 -0
  312. package/templates/hono-server/libs/definition/src/configs/defs/middleware.ts +16 -0
  313. package/templates/hono-server/libs/definition/src/configs/defs/runtime.ts +11 -0
  314. package/templates/hono-server/libs/definition/src/configs/defs/worker.ts +29 -0
  315. package/templates/hono-server/libs/definition/src/configs/index.ts +4 -0
  316. package/templates/hono-server/libs/definition/src/configs/proto.ts +81 -0
  317. package/templates/hono-server/libs/definition/src/configs/schema.ts +23 -0
  318. package/templates/hono-server/libs/definition/src/modules/example/index.ts +16 -0
  319. package/templates/hono-server/libs/definition/src/modules/index.ts +1 -0
  320. package/templates/hono-server/libs/definition/tsconfig.json +5 -0
  321. package/templates/hono-server/libs/definition/vite.config.ts +12 -0
  322. package/templates/hono-server/oyo.config.json +11 -0
  323. package/templates/hono-server/package.json +26 -0
  324. package/templates/hono-server/pnpm-workspace.yaml +57 -0
  325. package/templates/hono-server/scripts/.env.example.docker +4 -0
  326. package/templates/hono-server/scripts/build-docker-server.sh +13 -0
  327. package/templates/hono-server/scripts/common.sh +20 -0
  328. package/templates/hono-server/tsconfig.json +4 -0
  329. package/templates/hono-server/turbo.json +13 -0
  330. package/templates/hono-server/vite.config.ts +13 -0
  331. package/templates/monorepo/.agents/skills/ask-matt/PHASE-BOUNDARIES.md +55 -0
  332. package/templates/monorepo/.agents/skills/ask-matt/SKILL.md +90 -0
  333. package/templates/monorepo/.agents/skills/ask-matt/agents/openai.yaml +5 -0
  334. package/templates/monorepo/.agents/skills/code-review/SKILL.md +87 -0
  335. package/templates/monorepo/.agents/skills/code-review/agents/openai.yaml +3 -0
  336. package/templates/monorepo/.agents/skills/codebase-design/DEEPENING.md +37 -0
  337. package/templates/monorepo/.agents/skills/codebase-design/DESIGN-IT-TWICE.md +44 -0
  338. package/templates/monorepo/.agents/skills/codebase-design/SKILL.md +114 -0
  339. package/templates/monorepo/.agents/skills/codebase-design/agents/openai.yaml +3 -0
  340. package/templates/monorepo/.agents/skills/confirm-requirements/SKILL.md +25 -0
  341. package/templates/monorepo/.agents/skills/diagnosing-bugs/SKILL.md +140 -0
  342. package/templates/monorepo/.agents/skills/diagnosing-bugs/agents/openai.yaml +3 -0
  343. package/templates/monorepo/.agents/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +44 -0
  344. package/templates/monorepo/.agents/skills/domain-modeling/ADR-FORMAT.md +47 -0
  345. package/templates/monorepo/.agents/skills/domain-modeling/CONTEXT-FORMAT.md +60 -0
  346. package/templates/monorepo/.agents/skills/domain-modeling/SKILL.md +74 -0
  347. package/templates/monorepo/.agents/skills/domain-modeling/agents/openai.yaml +3 -0
  348. package/templates/monorepo/.agents/skills/grill-me/SKILL.md +7 -0
  349. package/templates/monorepo/.agents/skills/grill-me/agents/openai.yaml +5 -0
  350. package/templates/monorepo/.agents/skills/grilling/SKILL.md +22 -0
  351. package/templates/monorepo/.agents/skills/grilling/agents/openai.yaml +3 -0
  352. package/templates/monorepo/.agents/skills/implement/SKILL.md +15 -0
  353. package/templates/monorepo/.agents/skills/implement/agents/openai.yaml +5 -0
  354. package/templates/monorepo/.agents/skills/improve-codebase-architecture/HTML-REPORT.md +123 -0
  355. package/templates/monorepo/.agents/skills/improve-codebase-architecture/SKILL.md +71 -0
  356. package/templates/monorepo/.agents/skills/improve-codebase-architecture/agents/openai.yaml +5 -0
  357. package/templates/monorepo/.agents/skills/prototype/LOGIC.md +67 -0
  358. package/templates/monorepo/.agents/skills/prototype/SKILL.md +26 -0
  359. package/templates/monorepo/.agents/skills/prototype/UI.md +112 -0
  360. package/templates/monorepo/.agents/skills/prototype/agents/openai.yaml +3 -0
  361. package/templates/monorepo/.agents/skills/research/SKILL.md +12 -0
  362. package/templates/monorepo/.agents/skills/research/agents/openai.yaml +3 -0
  363. package/templates/monorepo/.agents/skills/resolving-merge-conflicts/SKILL.md +14 -0
  364. package/templates/monorepo/.agents/skills/resolving-merge-conflicts/agents/openai.yaml +3 -0
  365. package/templates/monorepo/.agents/skills/scoped-code-review/SKILL.md +113 -0
  366. package/templates/monorepo/.agents/skills/setup-matt-pocock-skills/SKILL.md +116 -0
  367. package/templates/monorepo/.agents/skills/setup-matt-pocock-skills/agents/openai.yaml +5 -0
  368. package/templates/monorepo/.agents/skills/setup-matt-pocock-skills/domain.md +51 -0
  369. package/templates/monorepo/.agents/skills/setup-matt-pocock-skills/issue-tracker-github.md +45 -0
  370. package/templates/monorepo/.agents/skills/setup-matt-pocock-skills/issue-tracker-gitlab.md +46 -0
  371. package/templates/monorepo/.agents/skills/setup-matt-pocock-skills/issue-tracker-local.md +30 -0
  372. package/templates/monorepo/.agents/skills/setup-matt-pocock-skills/triage-labels.md +15 -0
  373. package/templates/monorepo/.agents/skills/tdd/SKILL.md +38 -0
  374. package/templates/monorepo/.agents/skills/tdd/agents/openai.yaml +3 -0
  375. package/templates/monorepo/.agents/skills/tdd/mocking.md +59 -0
  376. package/templates/monorepo/.agents/skills/tdd/tests.md +77 -0
  377. package/templates/monorepo/.agents/skills/teach/GLOSSARY-FORMAT.md +35 -0
  378. package/templates/monorepo/.agents/skills/teach/LEARNING-RECORD-FORMAT.md +46 -0
  379. package/templates/monorepo/.agents/skills/teach/MISSION-FORMAT.md +31 -0
  380. package/templates/monorepo/.agents/skills/teach/RESOURCES-FORMAT.md +32 -0
  381. package/templates/monorepo/.agents/skills/teach/SKILL.md +140 -0
  382. package/templates/monorepo/.agents/skills/teach/agents/openai.yaml +5 -0
  383. package/templates/monorepo/.agents/skills/to-questionnaire/SKILL.md +53 -0
  384. package/templates/monorepo/.agents/skills/to-questionnaire/agents/openai.yaml +5 -0
  385. package/templates/monorepo/.agents/skills/triage/AGENT-BRIEF.md +207 -0
  386. package/templates/monorepo/.agents/skills/triage/OUT-OF-SCOPE.md +105 -0
  387. package/templates/monorepo/.agents/skills/triage/SKILL.md +112 -0
  388. package/templates/monorepo/.agents/skills/triage/agents/openai.yaml +5 -0
  389. package/templates/monorepo/.agents/skills/wait-what/SKILL.md +7 -0
  390. package/templates/monorepo/.agents/skills/wait-what/agents/openai.yaml +5 -0
  391. package/templates/monorepo/.agents/skills/wayfinder/SKILL.md +128 -0
  392. package/templates/monorepo/.agents/skills/wayfinder/agents/openai.yaml +5 -0
  393. package/templates/monorepo/.agents/skills/wizard/SKILL.md +44 -0
  394. package/templates/monorepo/.agents/skills/wizard/agents/openai.yaml +3 -0
  395. package/templates/monorepo/.agents/skills/wizard/template.sh +204 -0
  396. package/templates/monorepo/.agents/skills/writing-for-agents/SKILL-MECHANICS.md +22 -0
  397. package/templates/monorepo/.agents/skills/writing-for-agents/SKILL.md +81 -0
  398. package/templates/monorepo/.agents/skills/writing-for-agents/agents/openai.yaml +3 -0
  399. package/templates/monorepo/.editorconfig +31 -0
  400. package/templates/monorepo/.gitattributes +39 -0
  401. package/templates/monorepo/.vscode/extensions.json +5 -0
  402. package/templates/monorepo/.vscode/launch.json +25 -0
  403. package/templates/monorepo/.vscode/settings.json +3 -1
  404. package/templates/monorepo/AGENTS.md +43 -0
  405. package/templates/monorepo/README.md +27 -0
  406. package/templates/monorepo/_gitignore +8 -0
  407. package/templates/monorepo/docs/agents/domain.md +41 -0
  408. package/templates/monorepo/docs/agents/issue-tracker.md +30 -0
  409. package/templates/monorepo/docs/agents/triage-labels.md +15 -0
  410. package/templates/monorepo/envs/.env.example +1 -0
  411. package/templates/monorepo/oyo.config.json +11 -0
  412. package/templates/monorepo/package.json +24 -0
  413. package/templates/monorepo/pnpm-workspace.yaml +32 -0
  414. package/templates/monorepo/tsconfig.json +4 -0
  415. package/templates/monorepo/turbo.json +13 -0
  416. package/templates/monorepo/vite.config.ts +13 -0
  417. package/templates/monorepo/.vite-hooks/pre-commit +0 -1
  418. /package/templates/{monorepo/_editorconfig → hono-fullstack/.editorconfig} +0 -0
  419. /package/templates/{monorepo/_gitattributes → hono-fullstack/.gitattributes} +0 -0
@@ -0,0 +1,61 @@
1
+ import { serve } from '@hono/node-server'
2
+ import app, { exampleWorkRunner } from './entry'
3
+
4
+ function main() {
5
+ const port = Number(process.env.NODE_PORT)
6
+ if (!port || Number.isNaN(port)) {
7
+ throw new Error(`Invalid port: ${process.env.NODE_PORT}`)
8
+ }
9
+
10
+ const server = serve(
11
+ {
12
+ fetch: app.fetch,
13
+ port,
14
+ },
15
+ (info) => {
16
+ console.log(`Server is running on http://localhost:${info.port}`)
17
+ },
18
+ )
19
+
20
+ let isShuttingDown = false
21
+
22
+ const gracefulShutdown = async (signal: string) => {
23
+ if (isShuttingDown) return
24
+ isShuttingDown = true
25
+
26
+ console.log(`Received ${signal}, shutting down...`)
27
+
28
+ // 设置保底超时:5 秒后强制退出,防止卡死
29
+ const forceExitTimeout = setTimeout(() => {
30
+ console.error('Forced exit: Shutdown timed out.')
31
+ process.exit(1)
32
+ }, 5000)
33
+ forceExitTimeout.unref()
34
+
35
+ try {
36
+ await new Promise<void>((resolve, reject) => {
37
+ server.close((err) => (err ? reject(err) : resolve()))
38
+ })
39
+ console.log('✔ HTTP server successfully closed.')
40
+
41
+ await exampleWorkRunner.shutdown()
42
+ console.log('✔ ExampleWorkRunner successfully shut down.')
43
+
44
+ console.log('Graceful shutdown completed.')
45
+ process.exit(0)
46
+ } catch (err) {
47
+ console.error('Error during shutdown:', err)
48
+ process.exit(1)
49
+ }
50
+ }
51
+
52
+ process.on('SIGTERM', () => gracefulShutdown('SIGTERM'))
53
+ process.on('SIGINT', () => gracefulShutdown('SIGINT'))
54
+ }
55
+
56
+ try {
57
+ main()
58
+ } catch (error) {
59
+ console.error('[server] failed to start', error)
60
+ process.exit(1)
61
+ }
@@ -0,0 +1,53 @@
1
+ import type { AppConfig } from '@/shared/app/types'
2
+ import {
3
+ corsConfig,
4
+ logBaseConfig,
5
+ logPrettyRawConfig,
6
+ logRollRawConfig,
7
+ logRollSchemaConfig,
8
+ runtimeConfig,
9
+ workerConfig,
10
+ type WorkerConfig,
11
+ } from '@repo/definition/backend'
12
+ import { flatten as flattenValiIssues, isValiError } from 'valibot'
13
+
14
+ export function resolveConfig(context: Record<string, unknown>): AppConfig {
15
+ try {
16
+ const fromEnv = { context, matchContextKey: 'constantCase' as const }
17
+ const runtime = runtimeConfig.resolve(fromEnv)
18
+ const logBaseParsed = logBaseConfig.resolve(fromEnv)
19
+ const logRollSchemaParsed = logRollSchemaConfig.resolve(fromEnv)
20
+ const worker = workerConfig.resolve(fromEnv)
21
+ const cors = corsConfig.resolve({
22
+ context: { domains: context.CORS_DOMAINS },
23
+ matchContextKey: 'camel',
24
+ })
25
+
26
+ return {
27
+ runtime: { ...runtime, isLocal: runtime.serverEnv === 'local' },
28
+ log: {
29
+ base: logBaseParsed,
30
+ roll: { ...logRollSchemaParsed, ...logRollRawConfig.resolve() },
31
+ pretty: logPrettyRawConfig.resolve(),
32
+ },
33
+ middleware: { cors },
34
+ worker,
35
+ }
36
+ } catch (error) {
37
+ if (isValiError(error)) {
38
+ throw new Error(`[resolveAppConfig] ${JSON.stringify(flattenValiIssues(error.issues))}`)
39
+ }
40
+ throw error
41
+ }
42
+ }
43
+
44
+ export function resolveWorkerConfig(context: Record<string, unknown>): WorkerConfig {
45
+ try {
46
+ return workerConfig.resolve({ context, matchContextKey: 'constantCase' })
47
+ } catch (error) {
48
+ if (isValiError(error)) {
49
+ throw new Error(`[resolveWorkerConfig] ${JSON.stringify(flattenValiIssues(error.issues))}`)
50
+ }
51
+ throw error
52
+ }
53
+ }
@@ -0,0 +1,40 @@
1
+ import { createApp } from '@/app'
2
+ import { resolveConfig } from './config'
3
+ import { createPinoLogger } from '@/infra/logger/pino'
4
+ import { getRuntimeKey } from 'hono/adapter'
5
+ import type { AppDependencies, AppLogger } from '@/shared/app/types'
6
+ import { ExampleWorkRunner } from '@/infra/work-runner/example/runner'
7
+ import { getLogger, setRootLogger } from '@/infra/logger/getter'
8
+
9
+ function installProcessErrorHandlers(isLocal: boolean) {
10
+ process.on('unhandledRejection', (reason) => {
11
+ getLogger().error({ err: reason }, 'unhandledRejection')
12
+ if (isLocal) process.exit(1)
13
+ })
14
+ process.on('uncaughtException', (error) => {
15
+ getLogger().fatal({ err: error }, 'uncaughtException')
16
+ process.exit(1)
17
+ })
18
+ }
19
+
20
+ const appConfig = resolveConfig(process.env)
21
+ const { runtime, log } = appConfig
22
+ const { rootLogger, loggerHandler } = createPinoLogger({
23
+ isLocal: runtime.isLocal,
24
+ logBase: log.base,
25
+ runtime: getRuntimeKey(),
26
+ logRoll: log.roll,
27
+ logPretty: log.pretty,
28
+ })
29
+ setRootLogger(rootLogger as unknown as AppLogger)
30
+ installProcessErrorHandlers(runtime.isLocal)
31
+
32
+ export const exampleWorkRunner = ExampleWorkRunner.getInstance(appConfig.worker)
33
+
34
+ let dependencies: AppDependencies | undefined
35
+ const app = createApp(() => {
36
+ dependencies ||= { appConfig, loggerHandler, exampleWorkRunner }
37
+ return dependencies
38
+ })
39
+
40
+ export default app
@@ -0,0 +1,52 @@
1
+ import { describe, expect, it } from 'vite-plus/test'
2
+ import { createApp } from './app'
3
+ import type { AppDependencies, AppLogger } from './shared/app/types'
4
+
5
+ const logger = new Proxy(
6
+ { assign() {} },
7
+ { get: (target, key) => Reflect.get(target, key) || (() => {}) },
8
+ ) as AppLogger
9
+ const dependencies = {
10
+ appConfig: { middleware: { cors: { domains: ['*'] } } },
11
+ loggerHandler: async (c: any, next: () => Promise<void>) => {
12
+ c.set('logger', logger)
13
+ await next()
14
+ },
15
+ exampleWorkRunner: {
16
+ async run(task: any) {
17
+ const original = task.input.message
18
+ const normalized = original.trim().replace(/\s+/g, ' ')
19
+ return { ok: true as const, data: { original, normalized, length: normalized.length } }
20
+ },
21
+ async shutdown() {},
22
+ },
23
+ } as unknown as AppDependencies
24
+
25
+ describe('HTTP contracts', () => {
26
+ const app = createApp(() => dependencies)
27
+
28
+ it('wraps successful responses in data', async () => {
29
+ const response = await app.request('/health')
30
+ expect(response.status).toBe(200)
31
+ await expect(response.json()).resolves.toEqual({ data: { status: 'ok' } })
32
+ })
33
+
34
+ it('returns Problem Details for missing routes', async () => {
35
+ const response = await app.request('/missing')
36
+ expect(response.status).toBe(404)
37
+ await expect(response.json()).resolves.toMatchObject({ status: 404, type: 'NORMAL.NOT_FOUND' })
38
+ })
39
+
40
+ it('returns validation Problem Details with status 422', async () => {
41
+ const response = await app.request('/examples/process', {
42
+ method: 'POST',
43
+ headers: { 'content-type': 'application/json' },
44
+ body: JSON.stringify({ message: '' }),
45
+ })
46
+ expect(response.status).toBe(422)
47
+ await expect(response.json()).resolves.toMatchObject({
48
+ status: 422,
49
+ type: 'NORMAL.VALIDATION',
50
+ })
51
+ })
52
+ })
@@ -0,0 +1,45 @@
1
+ import { type Context, Hono } from 'hono'
2
+ import { contextStorage } from 'hono/context-storage'
3
+ import { csrf } from 'hono/csrf'
4
+ import { secureHeaders } from 'hono/secure-headers'
5
+ import { requestId } from 'hono/request-id'
6
+ import { corsMiddleware } from './middlewares/cors'
7
+ import { exampleRoutes } from './modules/example/routes'
8
+ import type { AppDependencies, AppEnv } from './shared/app/types'
9
+ import { E } from './shared/errors/defs'
10
+ import { globalErrorHandler } from './shared/errors/handler'
11
+ import { configureOpenAPI } from './shared/network/openapi'
12
+ import { objectEntries } from './shared/utils'
13
+
14
+ export const createApp = (
15
+ makeDependencies: (c: Context<AppEnv>) => Promise<AppDependencies> | AppDependencies,
16
+ ): Hono<AppEnv> => {
17
+ const app = new Hono<AppEnv>()
18
+
19
+ app.use('*', async (c, next) => {
20
+ const deps = await makeDependencies(c)
21
+ objectEntries(deps).forEach(([key, value]) => c.set(key, value))
22
+ await next()
23
+ })
24
+ app.use(contextStorage())
25
+ app.use('*', requestId())
26
+ app.use('*', async (c, next) => {
27
+ const loggerHandler = c.get('loggerHandler')
28
+ await loggerHandler(c as never, async () => {
29
+ c.get('logger')?.assign({ reqId: c.get('requestId') })
30
+ await next()
31
+ })
32
+ })
33
+ app.use('*', secureHeaders())
34
+ app.use('*', corsMiddleware())
35
+ app.use('*', csrf())
36
+
37
+ app.route('/', exampleRoutes)
38
+ configureOpenAPI(app)
39
+
40
+ app.notFound(() => {
41
+ throw E.NORMAL.NOT_FOUND.create()
42
+ })
43
+ app.onError(globalErrorHandler)
44
+ return app
45
+ }
@@ -0,0 +1,74 @@
1
+ import type { AppEnv, AppLogger } from '@/shared/app/types'
2
+ import { hasProp } from '@/shared/utils'
3
+ import { getContext } from 'hono/context-storage'
4
+
5
+ // 1. 创建无限递归的空代理,用于抹平高级日志库独有的非核心属性/方法(如 logger.bindings(), logger.flush())
6
+ const dummyFn = () => noopProxy
7
+ const noopProxy: any = new Proxy(dummyFn, {
8
+ get: () => noopProxy,
9
+ apply: () => noopProxy,
10
+ })
11
+
12
+ // 2. 自定义日志级别到 Console 方法的映射
13
+ const mapToConsoleMethod: Record<string, string> = {
14
+ trace: 'trace',
15
+ debug: 'debug',
16
+ info: 'info',
17
+ warn: 'warn',
18
+ error: 'error',
19
+ fatal: 'error', // Console 没有 fatal,将其降级映射为 error
20
+ silent: 'debug', // 理论上不该输出,但做个兜底防崩溃
21
+ }
22
+
23
+ export const fallbackLogger = new Proxy(console, {
24
+ get(target, prop, receiver) {
25
+ if (prop === 'child') {
26
+ return () => fallbackLogger
27
+ }
28
+
29
+ if (typeof prop === 'string' && hasProp(mapToConsoleMethod, prop)) {
30
+ const consoleMethod = Reflect.get(target, mapToConsoleMethod[prop], receiver)
31
+ if (typeof consoleMethod === 'function') {
32
+ return consoleMethod.bind(target)
33
+ }
34
+ }
35
+
36
+ const value = Reflect.get(target, prop, receiver)
37
+ if (typeof value === 'function') {
38
+ return value.bind(target)
39
+ }
40
+
41
+ // 如果原生具有该属性(不为 undefined),则直接返回
42
+ if (value !== undefined) {
43
+ return value
44
+ }
45
+
46
+ // --- 核心改造点 D:未知的扩展属性/链式调用 ---
47
+ // 比如 logger.bindings().xxx(),返回无限安全代理,杜绝 Cannot read properties of xxx 报错
48
+ return noopProxy
49
+ },
50
+
51
+ // 拦截写入操作(如业务代码修改 logger.level = 'debug')
52
+ set(_target, _prop, _value) {
53
+ // 静默吞掉修改操作,防止污染原生的 console 对象
54
+ return true
55
+ },
56
+ }) as unknown as AppLogger
57
+
58
+ let rootLogger: AppLogger | undefined
59
+
60
+ export const setRootLogger = (logger: AppLogger) => {
61
+ rootLogger = logger
62
+ }
63
+
64
+ export const getLogger = (): AppLogger => {
65
+ try {
66
+ const contextLogger = getContext<AppEnv>().var.logger
67
+ if (contextLogger) {
68
+ return contextLogger
69
+ }
70
+ } catch {
71
+ // outside hono context-storage
72
+ }
73
+ return rootLogger || fallbackLogger
74
+ }
@@ -0,0 +1,122 @@
1
+ import { createRequire } from 'node:module'
2
+ import { isAbsolute, join, resolve } from 'node:path'
3
+ import { type Runtime } from 'hono/adapter'
4
+ import { pinoLogger } from 'hono-pino'
5
+ import pino, { type LoggerOptions } from 'pino'
6
+ import type { AppConfig } from '@/shared/app/types'
7
+ import { serializeErr } from '@/shared/errors/log'
8
+
9
+ // const pinoInstance = pino({
10
+ // hooks: {
11
+ // logMethod(args: any[], method) {
12
+ // if (
13
+ // args.length !== 2 ||
14
+ // args[0] instanceof Error ||
15
+ // typeof args[1] !== 'string'
16
+ // ) {
17
+ // return method.apply(this, args)
18
+ // }
19
+ // const firstArg = args[0]
20
+ // if (firstArg && typeof firstArg === 'object') {
21
+ // const { context, ...rest } = firstArg
22
+ // const arg1: any = { p: rest }
23
+ // if (context) arg1.context = context
24
+ // return method.apply(this, [{}, args[1]])
25
+ // }
26
+ // return method.apply(this, args)
27
+ // },
28
+ // },
29
+ // })
30
+
31
+ export const createPinoOptions = ({
32
+ isLocal,
33
+ baseConfig,
34
+ }: {
35
+ isLocal: boolean
36
+ baseConfig: AppConfig['log']['base']
37
+ }) => {
38
+ const pinoOptions: LoggerOptions = {
39
+ level: baseConfig.loggerLevel || (isLocal ? 'debug' : 'info'),
40
+ serializers: {
41
+ req: (req) => {
42
+ return {
43
+ method: req.method,
44
+ url: req.url,
45
+ headers: {
46
+ 'content-type': req.headers?.['content-type'],
47
+ 'user-agent': req.headers?.['user-agent'],
48
+ referer: req.headers?.['referer'],
49
+ },
50
+ }
51
+ },
52
+ res: (res) => {
53
+ return {
54
+ status: res.status,
55
+ headers: {
56
+ 'content-type': res.headers?.['content-type'],
57
+ 'content-length': res.headers?.['content-length'],
58
+ },
59
+ }
60
+ },
61
+ err: serializeErr,
62
+ },
63
+ }
64
+
65
+ return pinoOptions
66
+ }
67
+
68
+ export const createPinoLogger = ({
69
+ isLocal,
70
+ logBase,
71
+ runtime,
72
+ logRoll,
73
+ logPretty,
74
+ }: {
75
+ isLocal: boolean
76
+ logBase: AppConfig['log']['base']
77
+ runtime: Runtime
78
+ logRoll?: AppConfig['log']['roll']
79
+ logPretty?: AppConfig['log']['pretty']
80
+ }) => {
81
+ const pinoOptions = createPinoOptions({ isLocal, baseConfig: logBase })
82
+ const level = pinoOptions.level
83
+ if (runtime === 'node' || runtime === 'bun') {
84
+ if (isLocal && logPretty) {
85
+ try {
86
+ createRequire(import.meta.url).resolve('pino-pretty')
87
+ pinoOptions.transport = { target: 'pino-pretty', level, options: logPretty }
88
+ } catch {
89
+ console.warn('[logger] pino-pretty is not installed; falling back to JSON stdout')
90
+ }
91
+ } else if (logRoll) {
92
+ const { loggerDir, loggerFileBase } = logRoll
93
+ pinoOptions.transport = {
94
+ targets: [
95
+ {
96
+ target: 'pino-roll',
97
+ level,
98
+ options: {
99
+ ...logRoll,
100
+ file: join(
101
+ isAbsolute(loggerDir) ? loggerDir : resolve(process.cwd(), loggerDir),
102
+ loggerFileBase,
103
+ ),
104
+ },
105
+ },
106
+ { target: 'pino/file', level, options: { destination: 1 } },
107
+ ],
108
+ }
109
+ }
110
+ }
111
+ const rootLogger = pino(pinoOptions)
112
+ const loggerHandler = pinoLogger({
113
+ pino: rootLogger,
114
+ // access log 只记请求完成;错误细节由 onError 走 serializers.err。
115
+ // 默认在 c.error 时升 error 且 msg=error.message,会打出一条无结构的重复 error。
116
+ http: {
117
+ onResLevel: () => 'info',
118
+ onResMessage: () => 'Request completed',
119
+ },
120
+ })
121
+ return { rootLogger, loggerHandler }
122
+ }
@@ -0,0 +1,23 @@
1
+ // 所有工作任务标识
2
+ export const WorkSubject = Object.freeze({
3
+ PROCESS_EXAMPLE: 'PROCESS_EXAMPLE',
4
+ } as const)
5
+ export type WorkSubject = (typeof WorkSubject)[keyof typeof WorkSubject]
6
+
7
+ export const WorkerErrorCode = Object.freeze({
8
+ /** Worker 等待队列已满。 */
9
+ QUEUE_FULL: 'WORKER_QUEUE_FULL',
10
+ /** Worker 任务从提交到完成超过允许时限。 */
11
+ TASK_TIMEOUT: 'WORKER_TASK_TIMEOUT',
12
+ /** Worker 任务被取消。 */
13
+ TASK_ABORTED: 'WORKER_TASK_ABORTED',
14
+ /** Worker 任务内部错误。 */
15
+ TASK_INTERNAL: 'WORKER_TASK_INTERNAL',
16
+ /** Worker 未知错误。 */
17
+ UNKNOWN: 'UNKNOWN',
18
+ /** Worker 异常退出或 Pool 暂时没有可用 Worker。 */
19
+ WORKER_UNAVAILABLE: 'WORKER_UNAVAILABLE',
20
+ /** Worker Pool 已进入关闭流程,无法接受新任务。 */
21
+ WORKER_CLOSED: 'WORKER_CLOSED',
22
+ } as const)
23
+ export type WorkerErrorCode = (typeof WorkerErrorCode)[keyof typeof WorkerErrorCode]
@@ -0,0 +1,40 @@
1
+ import { hasProp } from '@/shared/utils'
2
+ import { WorkerErrorCode } from './constants'
3
+ import type { RunnerTaskError, RunnerTaskErrorDetails } from './types'
4
+
5
+ const workerErrorCodes = Object.values(WorkerErrorCode)
6
+
7
+ export class WorkerTaskError extends Error {
8
+ readonly code: WorkerErrorCode
9
+ readonly details?: RunnerTaskErrorDetails
10
+
11
+ constructor(
12
+ code: WorkerErrorCode,
13
+ message: string,
14
+ details?: RunnerTaskErrorDetails,
15
+ cause?: unknown,
16
+ ) {
17
+ super(message, { cause })
18
+ this.name = 'WorkerTaskError'
19
+ this.code = code
20
+ this.details = details
21
+ }
22
+
23
+ serialize(): RunnerTaskError<WorkerErrorCode> {
24
+ return {
25
+ code: this.code,
26
+ message: this.message,
27
+ ...(this.details ? { details: this.details } : {}),
28
+ ...(this.cause ? { cause: this.cause } : {}),
29
+ }
30
+ }
31
+ }
32
+
33
+ export function isWorkerTaskError(error: unknown): error is WorkerTaskError {
34
+ return (
35
+ error instanceof WorkerTaskError ||
36
+ (error instanceof Error &&
37
+ hasProp(error, 'code') &&
38
+ workerErrorCodes.includes(error.code as WorkerErrorCode))
39
+ )
40
+ }
@@ -0,0 +1,56 @@
1
+ import { afterEach, describe, expect, it, vi } from 'vite-plus/test'
2
+ import { WorkerErrorCode, WorkSubject } from '../constants'
3
+ import { ExampleWorkRunner } from './runner'
4
+
5
+ vi.mock('@/infra/logger/getter', () => ({
6
+ getLogger: () =>
7
+ new Proxy({ assign() {} }, { get: (target, key) => Reflect.get(target, key) || (() => {}) }),
8
+ }))
9
+ vi.mock('virtual:workers', () => ({ default: '/tmp' }))
10
+ vi.mock('piscina', () => ({
11
+ default: class PiscinaMock {
12
+ idleThreads = 1
13
+ threads: unknown[] = []
14
+ queueSize = 0
15
+ options = { maxQueue: 1 }
16
+
17
+ run() {
18
+ throw new Error('An aborted task must not reach the worker pool')
19
+ }
20
+
21
+ async close() {}
22
+ },
23
+ }))
24
+
25
+ const config = {
26
+ minThreads: 1,
27
+ maxThreads: 1,
28
+ concurrentTasksPerWorker: 1,
29
+ maxQueue: 1,
30
+ workerTaskTimeoutMs: 1_000,
31
+ }
32
+
33
+ describe('ExampleWorkRunner cancellation', () => {
34
+ let runner: ExampleWorkRunner | undefined
35
+
36
+ afterEach(async () => {
37
+ await runner?.shutdown()
38
+ runner = undefined
39
+ })
40
+
41
+ it('returns the task-aborted error model for an aborted signal', async () => {
42
+ runner = ExampleWorkRunner.getInstance(config)
43
+ const controller = new AbortController()
44
+ controller.abort()
45
+
46
+ await expect(
47
+ runner.run(
48
+ { subject: WorkSubject.PROCESS_EXAMPLE, input: { message: 'hello' } },
49
+ { signal: controller.signal },
50
+ ),
51
+ ).resolves.toMatchObject({
52
+ ok: false,
53
+ error: { code: WorkerErrorCode.TASK_ABORTED },
54
+ })
55
+ })
56
+ })