@oyolincc/create 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +29 -13
- package/templates/hono-fullstack/.agents/skills/ask-matt/PHASE-BOUNDARIES.md +55 -0
- package/templates/hono-fullstack/.agents/skills/ask-matt/SKILL.md +90 -0
- package/templates/hono-fullstack/.agents/skills/ask-matt/agents/openai.yaml +5 -0
- package/templates/hono-fullstack/.agents/skills/code-review/SKILL.md +87 -0
- package/templates/hono-fullstack/.agents/skills/code-review/agents/openai.yaml +3 -0
- package/templates/hono-fullstack/.agents/skills/codebase-design/DEEPENING.md +37 -0
- package/templates/hono-fullstack/.agents/skills/codebase-design/DESIGN-IT-TWICE.md +44 -0
- package/templates/hono-fullstack/.agents/skills/codebase-design/SKILL.md +114 -0
- package/templates/hono-fullstack/.agents/skills/codebase-design/agents/openai.yaml +3 -0
- package/templates/hono-fullstack/.agents/skills/confirm-requirements/SKILL.md +25 -0
- package/templates/hono-fullstack/.agents/skills/diagnosing-bugs/SKILL.md +140 -0
- package/templates/hono-fullstack/.agents/skills/diagnosing-bugs/agents/openai.yaml +3 -0
- package/templates/hono-fullstack/.agents/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +44 -0
- package/templates/hono-fullstack/.agents/skills/domain-modeling/ADR-FORMAT.md +47 -0
- package/templates/hono-fullstack/.agents/skills/domain-modeling/CONTEXT-FORMAT.md +60 -0
- package/templates/hono-fullstack/.agents/skills/domain-modeling/SKILL.md +74 -0
- package/templates/hono-fullstack/.agents/skills/domain-modeling/agents/openai.yaml +3 -0
- package/templates/hono-fullstack/.agents/skills/grill-me/SKILL.md +7 -0
- package/templates/hono-fullstack/.agents/skills/grill-me/agents/openai.yaml +5 -0
- package/templates/hono-fullstack/.agents/skills/grilling/SKILL.md +22 -0
- package/templates/hono-fullstack/.agents/skills/grilling/agents/openai.yaml +3 -0
- package/templates/hono-fullstack/.agents/skills/implement/SKILL.md +15 -0
- package/templates/hono-fullstack/.agents/skills/implement/agents/openai.yaml +5 -0
- package/templates/hono-fullstack/.agents/skills/improve-codebase-architecture/HTML-REPORT.md +123 -0
- package/templates/hono-fullstack/.agents/skills/improve-codebase-architecture/SKILL.md +71 -0
- package/templates/hono-fullstack/.agents/skills/improve-codebase-architecture/agents/openai.yaml +5 -0
- package/templates/hono-fullstack/.agents/skills/prototype/LOGIC.md +67 -0
- package/templates/hono-fullstack/.agents/skills/prototype/SKILL.md +26 -0
- package/templates/hono-fullstack/.agents/skills/prototype/UI.md +112 -0
- package/templates/hono-fullstack/.agents/skills/prototype/agents/openai.yaml +3 -0
- package/templates/hono-fullstack/.agents/skills/research/SKILL.md +12 -0
- package/templates/hono-fullstack/.agents/skills/research/agents/openai.yaml +3 -0
- package/templates/hono-fullstack/.agents/skills/resolving-merge-conflicts/SKILL.md +14 -0
- package/templates/hono-fullstack/.agents/skills/resolving-merge-conflicts/agents/openai.yaml +3 -0
- package/templates/hono-fullstack/.agents/skills/scoped-code-review/SKILL.md +113 -0
- package/templates/hono-fullstack/.agents/skills/setup-matt-pocock-skills/SKILL.md +116 -0
- package/templates/hono-fullstack/.agents/skills/setup-matt-pocock-skills/agents/openai.yaml +5 -0
- package/templates/hono-fullstack/.agents/skills/setup-matt-pocock-skills/domain.md +51 -0
- package/templates/hono-fullstack/.agents/skills/setup-matt-pocock-skills/issue-tracker-github.md +45 -0
- package/templates/hono-fullstack/.agents/skills/setup-matt-pocock-skills/issue-tracker-gitlab.md +46 -0
- package/templates/hono-fullstack/.agents/skills/setup-matt-pocock-skills/issue-tracker-local.md +30 -0
- package/templates/hono-fullstack/.agents/skills/setup-matt-pocock-skills/triage-labels.md +15 -0
- package/templates/hono-fullstack/.agents/skills/tdd/SKILL.md +38 -0
- package/templates/hono-fullstack/.agents/skills/tdd/agents/openai.yaml +3 -0
- package/templates/hono-fullstack/.agents/skills/tdd/mocking.md +59 -0
- package/templates/hono-fullstack/.agents/skills/tdd/tests.md +77 -0
- package/templates/hono-fullstack/.agents/skills/teach/GLOSSARY-FORMAT.md +35 -0
- package/templates/hono-fullstack/.agents/skills/teach/LEARNING-RECORD-FORMAT.md +46 -0
- package/templates/hono-fullstack/.agents/skills/teach/MISSION-FORMAT.md +31 -0
- package/templates/hono-fullstack/.agents/skills/teach/RESOURCES-FORMAT.md +32 -0
- package/templates/hono-fullstack/.agents/skills/teach/SKILL.md +140 -0
- package/templates/hono-fullstack/.agents/skills/teach/agents/openai.yaml +5 -0
- package/templates/hono-fullstack/.agents/skills/to-questionnaire/SKILL.md +53 -0
- package/templates/hono-fullstack/.agents/skills/to-questionnaire/agents/openai.yaml +5 -0
- package/templates/hono-fullstack/.agents/skills/triage/AGENT-BRIEF.md +207 -0
- package/templates/hono-fullstack/.agents/skills/triage/OUT-OF-SCOPE.md +105 -0
- package/templates/hono-fullstack/.agents/skills/triage/SKILL.md +112 -0
- package/templates/hono-fullstack/.agents/skills/triage/agents/openai.yaml +5 -0
- package/templates/hono-fullstack/.agents/skills/wait-what/SKILL.md +7 -0
- package/templates/hono-fullstack/.agents/skills/wait-what/agents/openai.yaml +5 -0
- package/templates/hono-fullstack/.agents/skills/wayfinder/SKILL.md +128 -0
- package/templates/hono-fullstack/.agents/skills/wayfinder/agents/openai.yaml +5 -0
- package/templates/hono-fullstack/.agents/skills/wizard/SKILL.md +44 -0
- package/templates/hono-fullstack/.agents/skills/wizard/agents/openai.yaml +3 -0
- package/templates/hono-fullstack/.agents/skills/wizard/template.sh +204 -0
- package/templates/hono-fullstack/.agents/skills/writing-for-agents/SKILL-MECHANICS.md +22 -0
- package/templates/hono-fullstack/.agents/skills/writing-for-agents/SKILL.md +81 -0
- package/templates/hono-fullstack/.agents/skills/writing-for-agents/agents/openai.yaml +3 -0
- package/templates/hono-fullstack/.changeset/README.md +8 -0
- package/templates/hono-fullstack/.changeset/config.json +11 -0
- package/templates/hono-fullstack/.editorconfig +31 -0
- package/templates/hono-fullstack/.gitattributes +39 -0
- package/templates/hono-fullstack/.vscode/extensions.json +5 -0
- package/templates/hono-fullstack/.vscode/launch.json +36 -0
- package/templates/hono-fullstack/.vscode/settings.json +26 -0
- package/templates/hono-fullstack/AGENTS.md +50 -0
- package/templates/hono-fullstack/README.md +51 -0
- package/templates/hono-fullstack/_gitignore +35 -0
- package/templates/hono-fullstack/apps/server/.dev.vars.example +9 -0
- package/templates/hono-fullstack/apps/server/package.json +63 -0
- package/templates/hono-fullstack/apps/server/src/adapters/cloudflare/entry.ts +36 -0
- package/templates/hono-fullstack/apps/server/src/adapters/nodejs/bootstrap.ts +61 -0
- package/templates/hono-fullstack/apps/server/src/adapters/nodejs/entry.ts +62 -0
- package/templates/hono-fullstack/apps/server/src/app.ts +43 -0
- package/templates/hono-fullstack/apps/server/src/config.ts +47 -0
- package/templates/hono-fullstack/apps/server/src/infra/logger/getter.ts +74 -0
- package/templates/hono-fullstack/apps/server/src/infra/logger/pino.ts +126 -0
- package/templates/hono-fullstack/apps/server/src/infra/work-runner/constants.ts +23 -0
- package/templates/hono-fullstack/apps/server/src/infra/work-runner/errors.ts +40 -0
- package/templates/hono-fullstack/apps/server/src/infra/work-runner/example/worker-entry.ts +13 -0
- package/templates/hono-fullstack/apps/server/src/infra/work-runner/pass-through/runner.ts +42 -0
- package/templates/hono-fullstack/apps/server/src/infra/work-runner/piscina/runner.ts +185 -0
- package/templates/hono-fullstack/apps/server/src/infra/work-runner/types.ts +118 -0
- package/templates/hono-fullstack/apps/server/src/infra/work-runner/utils/business-error.ts +19 -0
- package/templates/hono-fullstack/apps/server/src/infra/work-runner/utils/message.ts +49 -0
- package/templates/hono-fullstack/apps/server/src/infra/work-runner/utils/transfer.ts +144 -0
- package/templates/hono-fullstack/apps/server/src/middlewares/cors.ts +26 -0
- package/templates/hono-fullstack/apps/server/src/modules/example/contracts.ts +9 -0
- package/templates/hono-fullstack/apps/server/src/modules/example/routes.ts +73 -0
- package/templates/hono-fullstack/apps/server/src/modules/example/work-task/tasks.test.ts +49 -0
- package/templates/hono-fullstack/apps/server/src/modules/example/work-task/tasks.ts +58 -0
- package/templates/hono-fullstack/apps/server/src/shared/app/types.ts +44 -0
- package/templates/hono-fullstack/apps/server/src/shared/errors/constants.ts +152 -0
- package/templates/hono-fullstack/apps/server/src/shared/errors/defs/index.ts +15 -0
- package/templates/hono-fullstack/apps/server/src/shared/errors/handler.ts +16 -0
- package/templates/hono-fullstack/apps/server/src/shared/errors/log.ts +67 -0
- package/templates/hono-fullstack/apps/server/src/shared/errors/proto.ts +42 -0
- package/templates/hono-fullstack/apps/server/src/shared/errors/types.ts +29 -0
- package/templates/hono-fullstack/apps/server/src/shared/network/fetcher.ts +35 -0
- package/templates/hono-fullstack/apps/server/src/shared/network/openapi/index.ts +50 -0
- package/templates/hono-fullstack/apps/server/src/shared/network/openapi/res-defs.ts +39 -0
- package/templates/hono-fullstack/apps/server/src/shared/network/types.ts +3 -0
- package/templates/hono-fullstack/apps/server/src/shared/network/utils.ts +36 -0
- package/templates/hono-fullstack/apps/server/src/shared/network/validator.ts +28 -0
- package/templates/hono-fullstack/apps/server/src/shared/utils/index.ts +30 -0
- package/templates/hono-fullstack/apps/server/src/virtual-modules.d.ts +5 -0
- package/templates/hono-fullstack/apps/server/tsconfig.json +17 -0
- package/templates/hono-fullstack/apps/server/vite.config.ts +87 -0
- package/templates/hono-fullstack/apps/server/wrangler.jsonc +29 -0
- package/templates/hono-fullstack/apps/stack/backend/cloudflare.ts +5 -0
- package/templates/hono-fullstack/apps/stack/backend/node.ts +3 -0
- package/templates/hono-fullstack/apps/stack/frontend/components/general/ErrorMessage.tsx +4 -0
- package/templates/hono-fullstack/apps/stack/frontend/components/layouts/AppLayout.tsx +11 -0
- package/templates/hono-fullstack/apps/stack/frontend/components/layouts/Header.tsx +7 -0
- package/templates/hono-fullstack/apps/stack/frontend/components/layouts/Page.tsx +5 -0
- package/templates/hono-fullstack/apps/stack/frontend/components/layouts/PageContainer.tsx +5 -0
- package/templates/hono-fullstack/apps/stack/frontend/modules/example/api.ts +13 -0
- package/templates/hono-fullstack/apps/stack/frontend/modules/example/components/ExampleForm.tsx +45 -0
- package/templates/hono-fullstack/apps/stack/frontend/modules/example/components/ExampleList.tsx +13 -0
- package/templates/hono-fullstack/apps/stack/frontend/modules/example/hooks/api-hooks.ts +14 -0
- package/templates/hono-fullstack/apps/stack/frontend/modules/example/stores/index.ts +3 -0
- package/templates/hono-fullstack/apps/stack/frontend/routeTree.gen.ts +73 -0
- package/templates/hono-fullstack/apps/stack/frontend/router.tsx +22 -0
- package/templates/hono-fullstack/apps/stack/frontend/routes/__root.tsx +61 -0
- package/templates/hono-fullstack/apps/stack/frontend/routes/api/$.ts +18 -0
- package/templates/hono-fullstack/apps/stack/frontend/routes/index.tsx +50 -0
- package/templates/hono-fullstack/apps/stack/frontend/shared/network/client.ts +19 -0
- package/templates/hono-fullstack/apps/stack/frontend/shared/network/constants.ts +1 -0
- package/templates/hono-fullstack/apps/stack/frontend/shared/network/errors.ts +33 -0
- package/templates/hono-fullstack/apps/stack/frontend/styles.css +23 -0
- package/templates/hono-fullstack/apps/stack/frontend/vite-env.d.ts +6 -0
- package/templates/hono-fullstack/apps/stack/package.json +59 -0
- package/templates/hono-fullstack/apps/stack/tsconfig.json +13 -0
- package/templates/hono-fullstack/apps/stack/tsr.config.json +5 -0
- package/templates/hono-fullstack/apps/stack/vite.config.ts +82 -0
- package/templates/hono-fullstack/apps/stack/wrangler.jsonc +20 -0
- package/templates/hono-fullstack/docs/agents/domain.md +41 -0
- package/templates/hono-fullstack/docs/agents/issue-tracker.md +30 -0
- package/templates/hono-fullstack/docs/agents/triage-labels.md +15 -0
- package/templates/hono-fullstack/envs/.env.example.server +12 -0
- package/templates/hono-fullstack/envs/.env.example.sqlite +1 -0
- package/templates/hono-fullstack/envs/.env.example.sqlite-d1 +3 -0
- package/templates/hono-fullstack/libs/db/drizzle-kit/sqlite-d1.config.ts +22 -0
- package/templates/hono-fullstack/libs/db/drizzle-kit/sqlite.config.ts +22 -0
- package/templates/hono-fullstack/libs/db/package.json +42 -0
- package/templates/hono-fullstack/libs/db/src/dialects/sqlite/client.ts +35 -0
- package/templates/hono-fullstack/libs/db/src/dialects/sqlite/d1-client.ts +12 -0
- package/templates/hono-fullstack/libs/db/src/dialects/sqlite/schema/columns.ts +37 -0
- package/templates/hono-fullstack/libs/db/src/dialects/sqlite/schema/index.ts +7 -0
- package/templates/hono-fullstack/libs/db/src/dialects/sqlite/schema/modules/examples/examples.ts +22 -0
- package/templates/hono-fullstack/libs/db/src/dialects/sqlite/schema/relations.ts +5 -0
- package/templates/hono-fullstack/libs/db/src/dialects/sqlite/schema/tables.ts +5 -0
- package/templates/hono-fullstack/libs/db/src/dialects/sqlite/schema/types.ts +7 -0
- package/templates/hono-fullstack/libs/db/src/dialects/sqlite/schema/vo.ts +1 -0
- package/templates/hono-fullstack/libs/db/src/dialects/sqlite/utils.ts +8 -0
- package/templates/hono-fullstack/libs/db/src/shared/types.ts +26 -0
- package/templates/hono-fullstack/libs/db/tsconfig.json +10 -0
- package/templates/hono-fullstack/libs/db/vite.config.ts +25 -0
- package/templates/hono-fullstack/libs/definition/package.json +30 -0
- package/templates/hono-fullstack/libs/definition/src/backend.ts +2 -0
- package/templates/hono-fullstack/libs/definition/src/configs/defs/log.ts +53 -0
- package/templates/hono-fullstack/libs/definition/src/configs/defs/middleware.ts +16 -0
- package/templates/hono-fullstack/libs/definition/src/configs/defs/runtime.ts +12 -0
- package/templates/hono-fullstack/libs/definition/src/configs/defs/sqlite.ts +26 -0
- package/templates/hono-fullstack/libs/definition/src/configs/defs/worker.ts +29 -0
- package/templates/hono-fullstack/libs/definition/src/configs/index.ts +5 -0
- package/templates/hono-fullstack/libs/definition/src/configs/proto.ts +81 -0
- package/templates/hono-fullstack/libs/definition/src/configs/schema.ts +23 -0
- package/templates/hono-fullstack/libs/definition/src/frontend.ts +1 -0
- package/templates/hono-fullstack/libs/definition/src/modules/example/index.ts +16 -0
- package/templates/hono-fullstack/libs/definition/src/modules/index.ts +1 -0
- package/templates/hono-fullstack/libs/definition/tsconfig.json +5 -0
- package/templates/hono-fullstack/libs/definition/vite.config.ts +16 -0
- package/templates/hono-fullstack/oyo.config.json +13 -0
- package/templates/hono-fullstack/package.json +25 -0
- package/templates/hono-fullstack/pnpm-workspace.yaml +84 -0
- package/templates/hono-fullstack/tsconfig.json +4 -0
- package/templates/hono-fullstack/turbo.json +36 -0
- package/templates/hono-fullstack/vite.config.ts +14 -0
- package/templates/hono-server/.agents/skills/ask-matt/PHASE-BOUNDARIES.md +55 -0
- package/templates/hono-server/.agents/skills/ask-matt/SKILL.md +90 -0
- package/templates/hono-server/.agents/skills/ask-matt/agents/openai.yaml +5 -0
- package/templates/hono-server/.agents/skills/code-review/SKILL.md +87 -0
- package/templates/hono-server/.agents/skills/code-review/agents/openai.yaml +3 -0
- package/templates/hono-server/.agents/skills/codebase-design/DEEPENING.md +37 -0
- package/templates/hono-server/.agents/skills/codebase-design/DESIGN-IT-TWICE.md +44 -0
- package/templates/hono-server/.agents/skills/codebase-design/SKILL.md +114 -0
- package/templates/hono-server/.agents/skills/codebase-design/agents/openai.yaml +3 -0
- package/templates/hono-server/.agents/skills/confirm-requirements/SKILL.md +25 -0
- package/templates/hono-server/.agents/skills/diagnosing-bugs/SKILL.md +140 -0
- package/templates/hono-server/.agents/skills/diagnosing-bugs/agents/openai.yaml +3 -0
- package/templates/hono-server/.agents/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +44 -0
- package/templates/hono-server/.agents/skills/domain-modeling/ADR-FORMAT.md +47 -0
- package/templates/hono-server/.agents/skills/domain-modeling/CONTEXT-FORMAT.md +60 -0
- package/templates/hono-server/.agents/skills/domain-modeling/SKILL.md +74 -0
- package/templates/hono-server/.agents/skills/domain-modeling/agents/openai.yaml +3 -0
- package/templates/hono-server/.agents/skills/grill-me/SKILL.md +7 -0
- package/templates/hono-server/.agents/skills/grill-me/agents/openai.yaml +5 -0
- package/templates/hono-server/.agents/skills/grilling/SKILL.md +22 -0
- package/templates/hono-server/.agents/skills/grilling/agents/openai.yaml +3 -0
- package/templates/hono-server/.agents/skills/implement/SKILL.md +15 -0
- package/templates/hono-server/.agents/skills/implement/agents/openai.yaml +5 -0
- package/templates/hono-server/.agents/skills/improve-codebase-architecture/HTML-REPORT.md +123 -0
- package/templates/hono-server/.agents/skills/improve-codebase-architecture/SKILL.md +71 -0
- package/templates/hono-server/.agents/skills/improve-codebase-architecture/agents/openai.yaml +5 -0
- package/templates/hono-server/.agents/skills/prototype/LOGIC.md +67 -0
- package/templates/hono-server/.agents/skills/prototype/SKILL.md +26 -0
- package/templates/hono-server/.agents/skills/prototype/UI.md +112 -0
- package/templates/hono-server/.agents/skills/prototype/agents/openai.yaml +3 -0
- package/templates/hono-server/.agents/skills/research/SKILL.md +12 -0
- package/templates/hono-server/.agents/skills/research/agents/openai.yaml +3 -0
- package/templates/hono-server/.agents/skills/resolving-merge-conflicts/SKILL.md +14 -0
- package/templates/hono-server/.agents/skills/resolving-merge-conflicts/agents/openai.yaml +3 -0
- package/templates/hono-server/.agents/skills/scoped-code-review/SKILL.md +113 -0
- package/templates/hono-server/.agents/skills/setup-matt-pocock-skills/SKILL.md +116 -0
- package/templates/hono-server/.agents/skills/setup-matt-pocock-skills/agents/openai.yaml +5 -0
- package/templates/hono-server/.agents/skills/setup-matt-pocock-skills/domain.md +51 -0
- package/templates/hono-server/.agents/skills/setup-matt-pocock-skills/issue-tracker-github.md +45 -0
- package/templates/hono-server/.agents/skills/setup-matt-pocock-skills/issue-tracker-gitlab.md +46 -0
- package/templates/hono-server/.agents/skills/setup-matt-pocock-skills/issue-tracker-local.md +30 -0
- package/templates/hono-server/.agents/skills/setup-matt-pocock-skills/triage-labels.md +15 -0
- package/templates/hono-server/.agents/skills/tdd/SKILL.md +38 -0
- package/templates/hono-server/.agents/skills/tdd/agents/openai.yaml +3 -0
- package/templates/hono-server/.agents/skills/tdd/mocking.md +59 -0
- package/templates/hono-server/.agents/skills/tdd/tests.md +77 -0
- package/templates/hono-server/.agents/skills/teach/GLOSSARY-FORMAT.md +35 -0
- package/templates/hono-server/.agents/skills/teach/LEARNING-RECORD-FORMAT.md +46 -0
- package/templates/hono-server/.agents/skills/teach/MISSION-FORMAT.md +31 -0
- package/templates/hono-server/.agents/skills/teach/RESOURCES-FORMAT.md +32 -0
- package/templates/hono-server/.agents/skills/teach/SKILL.md +140 -0
- package/templates/hono-server/.agents/skills/teach/agents/openai.yaml +5 -0
- package/templates/hono-server/.agents/skills/to-questionnaire/SKILL.md +53 -0
- package/templates/hono-server/.agents/skills/to-questionnaire/agents/openai.yaml +5 -0
- package/templates/hono-server/.agents/skills/triage/AGENT-BRIEF.md +207 -0
- package/templates/hono-server/.agents/skills/triage/OUT-OF-SCOPE.md +105 -0
- package/templates/hono-server/.agents/skills/triage/SKILL.md +112 -0
- package/templates/hono-server/.agents/skills/triage/agents/openai.yaml +5 -0
- package/templates/hono-server/.agents/skills/wait-what/SKILL.md +7 -0
- package/templates/hono-server/.agents/skills/wait-what/agents/openai.yaml +5 -0
- package/templates/hono-server/.agents/skills/wayfinder/SKILL.md +128 -0
- package/templates/hono-server/.agents/skills/wayfinder/agents/openai.yaml +5 -0
- package/templates/hono-server/.agents/skills/wizard/SKILL.md +44 -0
- package/templates/hono-server/.agents/skills/wizard/agents/openai.yaml +3 -0
- package/templates/hono-server/.agents/skills/wizard/template.sh +204 -0
- package/templates/hono-server/.agents/skills/writing-for-agents/SKILL-MECHANICS.md +22 -0
- package/templates/hono-server/.agents/skills/writing-for-agents/SKILL.md +81 -0
- package/templates/hono-server/.agents/skills/writing-for-agents/agents/openai.yaml +3 -0
- package/templates/hono-server/.changeset/README.md +8 -0
- package/templates/hono-server/.changeset/config.json +11 -0
- package/templates/hono-server/.editorconfig +31 -0
- package/templates/hono-server/.gitattributes +39 -0
- package/templates/hono-server/.vscode/extensions.json +5 -0
- package/templates/hono-server/.vscode/launch.json +29 -0
- package/templates/hono-server/.vscode/settings.json +26 -0
- package/templates/hono-server/AGENTS.md +50 -0
- package/templates/hono-server/README.md +44 -0
- package/templates/hono-server/_gitignore +35 -0
- package/templates/hono-server/apps/server/.dev.vars.example +9 -0
- package/templates/hono-server/apps/server/package.json +64 -0
- package/templates/hono-server/apps/server/src/adapters/cloudflare/entry.ts +36 -0
- package/templates/hono-server/apps/server/src/adapters/nodejs/bootstrap.ts +61 -0
- package/templates/hono-server/apps/server/src/adapters/nodejs/entry.ts +62 -0
- package/templates/hono-server/apps/server/src/app.ts +43 -0
- package/templates/hono-server/apps/server/src/config.ts +47 -0
- package/templates/hono-server/apps/server/src/infra/logger/getter.ts +74 -0
- package/templates/hono-server/apps/server/src/infra/logger/pino.ts +126 -0
- package/templates/hono-server/apps/server/src/infra/work-runner/constants.ts +23 -0
- package/templates/hono-server/apps/server/src/infra/work-runner/errors.ts +40 -0
- package/templates/hono-server/apps/server/src/infra/work-runner/example/worker-entry.ts +13 -0
- package/templates/hono-server/apps/server/src/infra/work-runner/pass-through/runner.ts +42 -0
- package/templates/hono-server/apps/server/src/infra/work-runner/piscina/runner.ts +185 -0
- package/templates/hono-server/apps/server/src/infra/work-runner/types.ts +118 -0
- package/templates/hono-server/apps/server/src/infra/work-runner/utils/business-error.ts +19 -0
- package/templates/hono-server/apps/server/src/infra/work-runner/utils/message.ts +49 -0
- package/templates/hono-server/apps/server/src/infra/work-runner/utils/transfer.ts +144 -0
- package/templates/hono-server/apps/server/src/middlewares/cors.ts +26 -0
- package/templates/hono-server/apps/server/src/modules/example/contracts.ts +9 -0
- package/templates/hono-server/apps/server/src/modules/example/routes.ts +73 -0
- package/templates/hono-server/apps/server/src/modules/example/work-task/tasks.test.ts +49 -0
- package/templates/hono-server/apps/server/src/modules/example/work-task/tasks.ts +58 -0
- package/templates/hono-server/apps/server/src/shared/app/types.ts +44 -0
- package/templates/hono-server/apps/server/src/shared/errors/constants.ts +152 -0
- package/templates/hono-server/apps/server/src/shared/errors/defs/index.ts +15 -0
- package/templates/hono-server/apps/server/src/shared/errors/handler.ts +16 -0
- package/templates/hono-server/apps/server/src/shared/errors/log.ts +67 -0
- package/templates/hono-server/apps/server/src/shared/errors/proto.ts +42 -0
- package/templates/hono-server/apps/server/src/shared/errors/types.ts +29 -0
- package/templates/hono-server/apps/server/src/shared/network/fetcher.ts +35 -0
- package/templates/hono-server/apps/server/src/shared/network/openapi/index.ts +50 -0
- package/templates/hono-server/apps/server/src/shared/network/openapi/res-defs.ts +39 -0
- package/templates/hono-server/apps/server/src/shared/network/types.ts +3 -0
- package/templates/hono-server/apps/server/src/shared/network/utils.ts +36 -0
- package/templates/hono-server/apps/server/src/shared/network/validator.ts +28 -0
- package/templates/hono-server/apps/server/src/shared/utils/index.ts +30 -0
- package/templates/hono-server/apps/server/src/virtual-modules.d.ts +5 -0
- package/templates/hono-server/apps/server/tsconfig.json +17 -0
- package/templates/hono-server/apps/server/vite.config.ts +87 -0
- package/templates/hono-server/apps/server/wrangler.jsonc +29 -0
- package/templates/hono-server/docker/.env.example +4 -0
- package/templates/hono-server/docker/README.md +5 -0
- package/templates/hono-server/docker/local/compose.local.app.yml +21 -0
- package/templates/hono-server/docker/local/local-app-deploy.sh +8 -0
- package/templates/hono-server/docker/local/local-app-down.sh +8 -0
- package/templates/hono-server/docker/prod/.env.example.server +11 -0
- package/templates/hono-server/docker/prod/compose.prod.stack.yml +21 -0
- package/templates/hono-server/docker/prod/update.sh +7 -0
- package/templates/hono-server/docker/server.Dockerfile +38 -0
- package/templates/hono-server/docker/server.Dockerfile.dockerignore +23 -0
- package/templates/hono-server/docs/agents/domain.md +41 -0
- package/templates/hono-server/docs/agents/issue-tracker.md +30 -0
- package/templates/hono-server/docs/agents/triage-labels.md +15 -0
- package/templates/hono-server/envs/.env.example.server +12 -0
- package/templates/hono-server/envs/.env.example.sqlite +1 -0
- package/templates/hono-server/envs/.env.example.sqlite-d1 +3 -0
- package/templates/hono-server/libs/db/drizzle-kit/sqlite-d1.config.ts +22 -0
- package/templates/hono-server/libs/db/drizzle-kit/sqlite.config.ts +22 -0
- package/templates/hono-server/libs/db/package.json +42 -0
- package/templates/hono-server/libs/db/src/dialects/sqlite/client.ts +35 -0
- package/templates/hono-server/libs/db/src/dialects/sqlite/d1-client.ts +12 -0
- package/templates/hono-server/libs/db/src/dialects/sqlite/schema/columns.ts +37 -0
- package/templates/hono-server/libs/db/src/dialects/sqlite/schema/index.ts +7 -0
- package/templates/hono-server/libs/db/src/dialects/sqlite/schema/modules/examples/examples.ts +22 -0
- package/templates/hono-server/libs/db/src/dialects/sqlite/schema/relations.ts +5 -0
- package/templates/hono-server/libs/db/src/dialects/sqlite/schema/tables.ts +5 -0
- package/templates/hono-server/libs/db/src/dialects/sqlite/schema/types.ts +7 -0
- package/templates/hono-server/libs/db/src/dialects/sqlite/schema/vo.ts +1 -0
- package/templates/hono-server/libs/db/src/dialects/sqlite/utils.ts +8 -0
- package/templates/hono-server/libs/db/src/shared/types.ts +26 -0
- package/templates/hono-server/libs/db/tsconfig.json +10 -0
- package/templates/hono-server/libs/db/vite.config.ts +25 -0
- package/templates/hono-server/libs/definition/package.json +29 -0
- package/templates/hono-server/libs/definition/src/backend.ts +2 -0
- package/templates/hono-server/libs/definition/src/configs/defs/log.ts +53 -0
- package/templates/hono-server/libs/definition/src/configs/defs/middleware.ts +16 -0
- package/templates/hono-server/libs/definition/src/configs/defs/runtime.ts +12 -0
- package/templates/hono-server/libs/definition/src/configs/defs/sqlite.ts +26 -0
- package/templates/hono-server/libs/definition/src/configs/defs/worker.ts +29 -0
- package/templates/hono-server/libs/definition/src/configs/index.ts +5 -0
- package/templates/hono-server/libs/definition/src/configs/proto.ts +81 -0
- package/templates/hono-server/libs/definition/src/configs/schema.ts +23 -0
- package/templates/hono-server/libs/definition/src/modules/example/index.ts +16 -0
- package/templates/hono-server/libs/definition/src/modules/index.ts +1 -0
- package/templates/hono-server/libs/definition/tsconfig.json +5 -0
- package/templates/hono-server/libs/definition/vite.config.ts +15 -0
- package/templates/hono-server/oyo.config.json +13 -0
- package/templates/hono-server/package.json +25 -0
- package/templates/hono-server/pnpm-workspace.yaml +66 -0
- package/templates/hono-server/scripts/.env.example.docker +4 -0
- package/templates/hono-server/scripts/build-docker-server.sh +13 -0
- package/templates/hono-server/scripts/common.sh +20 -0
- package/templates/hono-server/tsconfig.json +4 -0
- package/templates/hono-server/turbo.json +36 -0
- package/templates/hono-server/vite.config.ts +14 -0
- package/templates/monorepo/.agents/skills/ask-matt/PHASE-BOUNDARIES.md +55 -0
- package/templates/monorepo/.agents/skills/ask-matt/SKILL.md +90 -0
- package/templates/monorepo/.agents/skills/ask-matt/agents/openai.yaml +5 -0
- package/templates/monorepo/.agents/skills/code-review/SKILL.md +87 -0
- package/templates/monorepo/.agents/skills/code-review/agents/openai.yaml +3 -0
- package/templates/monorepo/.agents/skills/codebase-design/DEEPENING.md +37 -0
- package/templates/monorepo/.agents/skills/codebase-design/DESIGN-IT-TWICE.md +44 -0
- package/templates/monorepo/.agents/skills/codebase-design/SKILL.md +114 -0
- package/templates/monorepo/.agents/skills/codebase-design/agents/openai.yaml +3 -0
- package/templates/monorepo/.agents/skills/confirm-requirements/SKILL.md +25 -0
- package/templates/monorepo/.agents/skills/diagnosing-bugs/SKILL.md +140 -0
- package/templates/monorepo/.agents/skills/diagnosing-bugs/agents/openai.yaml +3 -0
- package/templates/monorepo/.agents/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +44 -0
- package/templates/monorepo/.agents/skills/domain-modeling/ADR-FORMAT.md +47 -0
- package/templates/monorepo/.agents/skills/domain-modeling/CONTEXT-FORMAT.md +60 -0
- package/templates/monorepo/.agents/skills/domain-modeling/SKILL.md +74 -0
- package/templates/monorepo/.agents/skills/domain-modeling/agents/openai.yaml +3 -0
- package/templates/monorepo/.agents/skills/grill-me/SKILL.md +7 -0
- package/templates/monorepo/.agents/skills/grill-me/agents/openai.yaml +5 -0
- package/templates/monorepo/.agents/skills/grilling/SKILL.md +22 -0
- package/templates/monorepo/.agents/skills/grilling/agents/openai.yaml +3 -0
- package/templates/monorepo/.agents/skills/implement/SKILL.md +15 -0
- package/templates/monorepo/.agents/skills/implement/agents/openai.yaml +5 -0
- package/templates/monorepo/.agents/skills/improve-codebase-architecture/HTML-REPORT.md +123 -0
- package/templates/monorepo/.agents/skills/improve-codebase-architecture/SKILL.md +71 -0
- package/templates/monorepo/.agents/skills/improve-codebase-architecture/agents/openai.yaml +5 -0
- package/templates/monorepo/.agents/skills/prototype/LOGIC.md +67 -0
- package/templates/monorepo/.agents/skills/prototype/SKILL.md +26 -0
- package/templates/monorepo/.agents/skills/prototype/UI.md +112 -0
- package/templates/monorepo/.agents/skills/prototype/agents/openai.yaml +3 -0
- package/templates/monorepo/.agents/skills/research/SKILL.md +12 -0
- package/templates/monorepo/.agents/skills/research/agents/openai.yaml +3 -0
- package/templates/monorepo/.agents/skills/resolving-merge-conflicts/SKILL.md +14 -0
- package/templates/monorepo/.agents/skills/resolving-merge-conflicts/agents/openai.yaml +3 -0
- package/templates/monorepo/.agents/skills/scoped-code-review/SKILL.md +113 -0
- package/templates/monorepo/.agents/skills/setup-matt-pocock-skills/SKILL.md +116 -0
- package/templates/monorepo/.agents/skills/setup-matt-pocock-skills/agents/openai.yaml +5 -0
- package/templates/monorepo/.agents/skills/setup-matt-pocock-skills/domain.md +51 -0
- package/templates/monorepo/.agents/skills/setup-matt-pocock-skills/issue-tracker-github.md +45 -0
- package/templates/monorepo/.agents/skills/setup-matt-pocock-skills/issue-tracker-gitlab.md +46 -0
- package/templates/monorepo/.agents/skills/setup-matt-pocock-skills/issue-tracker-local.md +30 -0
- package/templates/monorepo/.agents/skills/setup-matt-pocock-skills/triage-labels.md +15 -0
- package/templates/monorepo/.agents/skills/tdd/SKILL.md +38 -0
- package/templates/monorepo/.agents/skills/tdd/agents/openai.yaml +3 -0
- package/templates/monorepo/.agents/skills/tdd/mocking.md +59 -0
- package/templates/monorepo/.agents/skills/tdd/tests.md +77 -0
- package/templates/monorepo/.agents/skills/teach/GLOSSARY-FORMAT.md +35 -0
- package/templates/monorepo/.agents/skills/teach/LEARNING-RECORD-FORMAT.md +46 -0
- package/templates/monorepo/.agents/skills/teach/MISSION-FORMAT.md +31 -0
- package/templates/monorepo/.agents/skills/teach/RESOURCES-FORMAT.md +32 -0
- package/templates/monorepo/.agents/skills/teach/SKILL.md +140 -0
- package/templates/monorepo/.agents/skills/teach/agents/openai.yaml +5 -0
- package/templates/monorepo/.agents/skills/to-questionnaire/SKILL.md +53 -0
- package/templates/monorepo/.agents/skills/to-questionnaire/agents/openai.yaml +5 -0
- package/templates/monorepo/.agents/skills/triage/AGENT-BRIEF.md +207 -0
- package/templates/monorepo/.agents/skills/triage/OUT-OF-SCOPE.md +105 -0
- package/templates/monorepo/.agents/skills/triage/SKILL.md +112 -0
- package/templates/monorepo/.agents/skills/triage/agents/openai.yaml +5 -0
- package/templates/monorepo/.agents/skills/wait-what/SKILL.md +7 -0
- package/templates/monorepo/.agents/skills/wait-what/agents/openai.yaml +5 -0
- package/templates/monorepo/.agents/skills/wayfinder/SKILL.md +128 -0
- package/templates/monorepo/.agents/skills/wayfinder/agents/openai.yaml +5 -0
- package/templates/monorepo/.agents/skills/wizard/SKILL.md +44 -0
- package/templates/monorepo/.agents/skills/wizard/agents/openai.yaml +3 -0
- package/templates/monorepo/.agents/skills/wizard/template.sh +204 -0
- package/templates/monorepo/.agents/skills/writing-for-agents/SKILL-MECHANICS.md +22 -0
- package/templates/monorepo/.agents/skills/writing-for-agents/SKILL.md +81 -0
- package/templates/monorepo/.agents/skills/writing-for-agents/agents/openai.yaml +3 -0
- package/templates/monorepo/.vscode/extensions.json +5 -0
- package/templates/monorepo/.vscode/launch.json +0 -3
- package/templates/monorepo/.vscode/settings.json +3 -1
- package/templates/monorepo/AGENTS.md +50 -0
- package/templates/monorepo/README.md +27 -0
- package/templates/monorepo/_gitignore +5 -0
- package/templates/monorepo/docs/agents/domain.md +41 -0
- package/templates/monorepo/docs/agents/issue-tracker.md +30 -0
- package/templates/monorepo/docs/agents/triage-labels.md +15 -0
- package/templates/monorepo/package.json +4 -3
- package/templates/monorepo/pnpm-workspace.yaml +23 -26
- package/templates/monorepo/turbo.json +27 -3
- package/templates/monorepo/vite.config.ts +1 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { 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 { CreateAppOptions, 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 = ({ serverBasePath, makeDependencies }: CreateAppOptions): Hono<AppEnv> => {
|
|
15
|
+
const app = new Hono<AppEnv>().basePath(serverBasePath)
|
|
16
|
+
|
|
17
|
+
app.use('*', async (c, next) => {
|
|
18
|
+
const deps = await makeDependencies(c)
|
|
19
|
+
objectEntries(deps).forEach(([key, value]) => c.set(key, value))
|
|
20
|
+
await next()
|
|
21
|
+
})
|
|
22
|
+
app.use(contextStorage())
|
|
23
|
+
app.use('*', requestId())
|
|
24
|
+
app.use('*', async (c, next) => {
|
|
25
|
+
const loggerHandler = c.get('loggerHandler')
|
|
26
|
+
await loggerHandler(c as never, async () => {
|
|
27
|
+
c.get('logger')?.assign({ reqId: c.get('requestId') })
|
|
28
|
+
await next()
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
app.use('*', secureHeaders())
|
|
32
|
+
app.use('*', corsMiddleware())
|
|
33
|
+
app.use('*', csrf())
|
|
34
|
+
|
|
35
|
+
app.route('/', exampleRoutes)
|
|
36
|
+
configureOpenAPI(app)
|
|
37
|
+
|
|
38
|
+
app.notFound(() => {
|
|
39
|
+
throw E.NORMAL.NOT_FOUND.create()
|
|
40
|
+
})
|
|
41
|
+
app.onError(globalErrorHandler)
|
|
42
|
+
return app
|
|
43
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {
|
|
2
|
+
corsConfig,
|
|
3
|
+
logBaseConfig,
|
|
4
|
+
logPrettyRawConfig,
|
|
5
|
+
logRollRawConfig,
|
|
6
|
+
logRollSchemaConfig,
|
|
7
|
+
runtimeConfig,
|
|
8
|
+
workerConfig,
|
|
9
|
+
} from '@repo/definition/backend'
|
|
10
|
+
import { getRuntimeKey } from 'hono/adapter'
|
|
11
|
+
import { flatten as flattenValiIssues, isValiError } from 'valibot'
|
|
12
|
+
import type { AppConfig } from '@/shared/app/types'
|
|
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 runtimeKey = getRuntimeKey()
|
|
19
|
+
const isNodejsLike = runtimeKey === 'node' || runtimeKey === 'bun'
|
|
20
|
+
const log: AppConfig['log'] = { base: logBaseConfig.resolve(fromEnv) }
|
|
21
|
+
|
|
22
|
+
if (isNodejsLike) {
|
|
23
|
+
log.roll = {
|
|
24
|
+
...logRollSchemaConfig.resolve(fromEnv),
|
|
25
|
+
...logRollRawConfig.resolve(),
|
|
26
|
+
}
|
|
27
|
+
log.pretty = logPrettyRawConfig.resolve()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
runtime: { ...runtime, isLocal: runtime.serverEnv === 'local' },
|
|
32
|
+
log,
|
|
33
|
+
worker: workerConfig.resolve(fromEnv),
|
|
34
|
+
middleware: {
|
|
35
|
+
cors: corsConfig.resolve({
|
|
36
|
+
context: { domains: context.CORS_DOMAINS },
|
|
37
|
+
matchContextKey: 'camel',
|
|
38
|
+
}),
|
|
39
|
+
},
|
|
40
|
+
}
|
|
41
|
+
} catch (error) {
|
|
42
|
+
if (isValiError(error)) {
|
|
43
|
+
throw new Error(`[resolveConfig] ${JSON.stringify(flattenValiIssues(error.issues))}`)
|
|
44
|
+
}
|
|
45
|
+
throw error
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -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,126 @@
|
|
|
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
|
+
browser: {
|
|
41
|
+
asObject: true,
|
|
42
|
+
serialize: ['!stdSerializers.err', 'req', 'res', 'err'],
|
|
43
|
+
},
|
|
44
|
+
serializers: {
|
|
45
|
+
req: (req) => {
|
|
46
|
+
return {
|
|
47
|
+
method: req.method,
|
|
48
|
+
url: req.url,
|
|
49
|
+
headers: {
|
|
50
|
+
'content-type': req.headers?.['content-type'],
|
|
51
|
+
'user-agent': req.headers?.['user-agent'],
|
|
52
|
+
referer: req.headers?.['referer'],
|
|
53
|
+
},
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
res: (res) => {
|
|
57
|
+
return {
|
|
58
|
+
status: res.status,
|
|
59
|
+
headers: {
|
|
60
|
+
'content-type': res.headers?.['content-type'],
|
|
61
|
+
'content-length': res.headers?.['content-length'],
|
|
62
|
+
},
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
err: serializeErr,
|
|
66
|
+
},
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return pinoOptions
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export const createPinoLogger = ({
|
|
73
|
+
isLocal,
|
|
74
|
+
logBase,
|
|
75
|
+
runtime,
|
|
76
|
+
logRoll,
|
|
77
|
+
logPretty,
|
|
78
|
+
}: {
|
|
79
|
+
isLocal: boolean
|
|
80
|
+
logBase: AppConfig['log']['base']
|
|
81
|
+
runtime: Runtime
|
|
82
|
+
logRoll?: AppConfig['log']['roll']
|
|
83
|
+
logPretty?: AppConfig['log']['pretty']
|
|
84
|
+
}) => {
|
|
85
|
+
const pinoOptions = createPinoOptions({ isLocal, baseConfig: logBase })
|
|
86
|
+
const level = pinoOptions.level
|
|
87
|
+
if (runtime === 'node' || runtime === 'bun') {
|
|
88
|
+
if (isLocal && logPretty) {
|
|
89
|
+
try {
|
|
90
|
+
createRequire(import.meta.url).resolve('pino-pretty')
|
|
91
|
+
pinoOptions.transport = { target: 'pino-pretty', level, options: logPretty }
|
|
92
|
+
} catch {
|
|
93
|
+
console.warn('[logger] pino-pretty is not installed; falling back to JSON stdout')
|
|
94
|
+
}
|
|
95
|
+
} else if (logRoll) {
|
|
96
|
+
const { loggerDir, loggerFileBase } = logRoll
|
|
97
|
+
pinoOptions.transport = {
|
|
98
|
+
targets: [
|
|
99
|
+
{
|
|
100
|
+
target: 'pino-roll',
|
|
101
|
+
level,
|
|
102
|
+
options: {
|
|
103
|
+
...logRoll,
|
|
104
|
+
file: join(
|
|
105
|
+
isAbsolute(loggerDir) ? loggerDir : resolve(process.cwd(), loggerDir),
|
|
106
|
+
loggerFileBase,
|
|
107
|
+
),
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
{ target: 'pino/file', level, options: { destination: 1 } },
|
|
111
|
+
],
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const rootLogger = pino(pinoOptions)
|
|
116
|
+
const loggerHandler = pinoLogger({
|
|
117
|
+
pino: rootLogger,
|
|
118
|
+
// access log 只记请求完成;错误细节由 onError 走 serializers.err。
|
|
119
|
+
// 默认在 c.error 时升 error 且 msg=error.message,会打出一条无结构的重复 error。
|
|
120
|
+
http: {
|
|
121
|
+
onResLevel: () => 'info',
|
|
122
|
+
onResMessage: () => 'Request completed',
|
|
123
|
+
},
|
|
124
|
+
})
|
|
125
|
+
return { rootLogger, loggerHandler }
|
|
126
|
+
}
|
|
@@ -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,13 @@
|
|
|
1
|
+
/** WORKER 打包入口 */
|
|
2
|
+
import type { RunnerTaskInvocation } from '../types'
|
|
3
|
+
import {
|
|
4
|
+
executeExampleTask as runExampleTask,
|
|
5
|
+
type ExampleRunnerTaskModel,
|
|
6
|
+
} from '@/modules/example/work-task/tasks'
|
|
7
|
+
|
|
8
|
+
export function executeExampleTask({
|
|
9
|
+
input,
|
|
10
|
+
messagePort,
|
|
11
|
+
}: RunnerTaskInvocation<ExampleRunnerTaskModel['input']>): ReturnType<typeof runExampleTask> {
|
|
12
|
+
return runExampleTask(input, messagePort).finally(() => messagePort.close())
|
|
13
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { executeExampleTask } from '../example/worker-entry'
|
|
2
|
+
import { getLogger } from '@/infra/logger/getter'
|
|
3
|
+
import { WorkSubject } from '../constants'
|
|
4
|
+
import type {
|
|
5
|
+
AppWorkRunner,
|
|
6
|
+
RunnerTaskParams,
|
|
7
|
+
RunnerTaskRunOptions,
|
|
8
|
+
RunnerTaskRunResult,
|
|
9
|
+
WorkerMessage,
|
|
10
|
+
WorkerMessagePort,
|
|
11
|
+
} from '../types'
|
|
12
|
+
import { handleWorkerMessage } from '../utils/message'
|
|
13
|
+
|
|
14
|
+
function createMessagePort(subject: WorkSubject): WorkerMessagePort {
|
|
15
|
+
const logger = getLogger()
|
|
16
|
+
return {
|
|
17
|
+
postMessage(message: WorkerMessage) {
|
|
18
|
+
handleWorkerMessage(message, logger, { subject })
|
|
19
|
+
},
|
|
20
|
+
close() {},
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class PassThroughWorkRunner implements AppWorkRunner {
|
|
25
|
+
async run<TSubject extends WorkSubject>(
|
|
26
|
+
taskParams: RunnerTaskParams<TSubject>,
|
|
27
|
+
options?: RunnerTaskRunOptions,
|
|
28
|
+
): Promise<RunnerTaskRunResult<TSubject>> {
|
|
29
|
+
if (taskParams.subject !== WorkSubject.PROCESS_EXAMPLE) {
|
|
30
|
+
throw new Error(`[PassThroughWorkRunner] task name not found: ${String(taskParams.subject)}`)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
options?.signal?.throwIfAborted()
|
|
34
|
+
|
|
35
|
+
return executeExampleTask({
|
|
36
|
+
input: taskParams.input,
|
|
37
|
+
messagePort: createMessagePort(taskParams.subject),
|
|
38
|
+
}) as Promise<RunnerTaskRunResult<TSubject>>
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async shutdown(): Promise<void> {}
|
|
42
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { type WorkerConfig } from '@repo/definition/backend'
|
|
2
|
+
import type {
|
|
3
|
+
AppWorkRunner,
|
|
4
|
+
RunnerTaskInvocation,
|
|
5
|
+
RunnerTaskParams,
|
|
6
|
+
RunnerTaskRunOptions,
|
|
7
|
+
RunnerTaskRunResult,
|
|
8
|
+
WorkerMessage,
|
|
9
|
+
} from '../types'
|
|
10
|
+
import { WorkerErrorCode, WorkSubject } from '../constants'
|
|
11
|
+
import { isWorkerTaskError, WorkerTaskError } from '../errors'
|
|
12
|
+
import Piscina from 'piscina'
|
|
13
|
+
import path from 'node:path'
|
|
14
|
+
import { MessageChannel, type MessagePort } from 'node:worker_threads'
|
|
15
|
+
import workersDir from 'virtual:workers'
|
|
16
|
+
import { getLogger } from '@/infra/logger/getter'
|
|
17
|
+
import type * as ExampleWorker from '../example/worker-entry'
|
|
18
|
+
import { handleWorkerMessage } from '../utils/message'
|
|
19
|
+
|
|
20
|
+
const taskNameMap = {
|
|
21
|
+
[WorkSubject.PROCESS_EXAMPLE]: 'executeExampleTask',
|
|
22
|
+
} satisfies Partial<Record<WorkSubject, keyof typeof ExampleWorker>>
|
|
23
|
+
|
|
24
|
+
export class PiscinaWorkRunner implements AppWorkRunner {
|
|
25
|
+
static #instance: PiscinaWorkRunner | null = null
|
|
26
|
+
readonly #pool: Piscina
|
|
27
|
+
readonly #config: WorkerConfig
|
|
28
|
+
|
|
29
|
+
private constructor(config: WorkerConfig) {
|
|
30
|
+
if (!config) {
|
|
31
|
+
throw new Error('[PiscinaWorkRunner] config is required')
|
|
32
|
+
}
|
|
33
|
+
this.#pool = new Piscina({
|
|
34
|
+
filename: path.join(workersDir, 'example-worker.mjs'),
|
|
35
|
+
minThreads: config.minThreads,
|
|
36
|
+
maxThreads: config.maxThreads,
|
|
37
|
+
concurrentTasksPerWorker: config.concurrentTasksPerWorker,
|
|
38
|
+
maxQueue: config.maxQueue,
|
|
39
|
+
})
|
|
40
|
+
this.#config = config
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public static getInstance(config: WorkerConfig): PiscinaWorkRunner {
|
|
44
|
+
if (!this.#instance) {
|
|
45
|
+
getLogger().info({ worker: config }, 'PiscinaWorkRunner initialized')
|
|
46
|
+
this.#instance = new PiscinaWorkRunner(config)
|
|
47
|
+
}
|
|
48
|
+
return this.#instance
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async run<TSubject extends WorkSubject>(
|
|
52
|
+
taskParams: RunnerTaskParams<TSubject>,
|
|
53
|
+
options?: RunnerTaskRunOptions,
|
|
54
|
+
): Promise<RunnerTaskRunResult<TSubject>> {
|
|
55
|
+
const targetName = taskNameMap[taskParams.subject]
|
|
56
|
+
if (!targetName) {
|
|
57
|
+
throw new Error(`[PiscinaWorkRunner] task name not found: ${taskParams.subject}`)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let timeoutTimer: ReturnType<typeof setTimeout> | undefined
|
|
61
|
+
let result: RunnerTaskRunResult<TSubject>
|
|
62
|
+
let workerMessagePort: MessagePort | undefined
|
|
63
|
+
|
|
64
|
+
const { signal: optSignal, transferList } = options || {}
|
|
65
|
+
const logger = getLogger()
|
|
66
|
+
// pool当前状态
|
|
67
|
+
const poolStats = {
|
|
68
|
+
idleThreads: this.#pool.idleThreads,
|
|
69
|
+
threads: this.#pool.threads.length,
|
|
70
|
+
queueSize: this.#pool.queueSize,
|
|
71
|
+
}
|
|
72
|
+
logger.assign({
|
|
73
|
+
pool: poolStats,
|
|
74
|
+
subject: taskParams.subject,
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
optSignal?.throwIfAborted()
|
|
79
|
+
|
|
80
|
+
// 判断队列已满
|
|
81
|
+
const enableQueue = this.#pool.options.maxQueue > 0
|
|
82
|
+
if (
|
|
83
|
+
(enableQueue && poolStats.queueSize >= this.#pool.options.maxQueue) ||
|
|
84
|
+
(!enableQueue && poolStats.idleThreads <= 0)
|
|
85
|
+
) {
|
|
86
|
+
throw new WorkerTaskError(WorkerErrorCode.QUEUE_FULL, 'Worker queue is full', {
|
|
87
|
+
enableQueue,
|
|
88
|
+
queueSize: poolStats.queueSize,
|
|
89
|
+
maxQueue: this.#config.maxQueue,
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
logger.debug('Worker task dispatching')
|
|
94
|
+
|
|
95
|
+
// 建立收发端
|
|
96
|
+
const { port1: messagePort, port2 } = new MessageChannel()
|
|
97
|
+
workerMessagePort = port2
|
|
98
|
+
messagePort.on('message', (message: WorkerMessage) =>
|
|
99
|
+
handleWorkerMessage(message, logger, { subject: taskParams.subject }),
|
|
100
|
+
)
|
|
101
|
+
messagePort.unref()
|
|
102
|
+
|
|
103
|
+
// 设置任务信号和超时
|
|
104
|
+
let taskSignal = optSignal
|
|
105
|
+
let timeoutPromise: Promise<never> | undefined
|
|
106
|
+
if (this.#config.workerTaskTimeoutMs > 0) {
|
|
107
|
+
const timeoutController = new AbortController()
|
|
108
|
+
taskSignal = optSignal
|
|
109
|
+
? AbortSignal.any([optSignal, timeoutController.signal])
|
|
110
|
+
: timeoutController.signal
|
|
111
|
+
timeoutPromise = new Promise<never>((_, reject) => {
|
|
112
|
+
timeoutTimer = setTimeout(() => {
|
|
113
|
+
const error = new WorkerTaskError(
|
|
114
|
+
WorkerErrorCode.TASK_TIMEOUT,
|
|
115
|
+
`Worker task timed out after ${this.#config.workerTaskTimeoutMs}ms`,
|
|
116
|
+
{ timeoutMs: this.#config.workerTaskTimeoutMs },
|
|
117
|
+
)
|
|
118
|
+
reject(error)
|
|
119
|
+
timeoutController.abort(error)
|
|
120
|
+
}, this.#config.workerTaskTimeoutMs)
|
|
121
|
+
timeoutTimer.unref()
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// 开始调用
|
|
126
|
+
const invocation: RunnerTaskInvocation<(typeof taskParams)['input']> = {
|
|
127
|
+
input: taskParams.input,
|
|
128
|
+
messagePort: workerMessagePort,
|
|
129
|
+
}
|
|
130
|
+
const taskPromise = this.#pool.run(invocation, {
|
|
131
|
+
name: targetName,
|
|
132
|
+
signal: taskSignal,
|
|
133
|
+
transferList: [...(transferList || []), workerMessagePort],
|
|
134
|
+
}) as Promise<RunnerTaskRunResult<TSubject>>
|
|
135
|
+
|
|
136
|
+
result = timeoutPromise
|
|
137
|
+
? await Promise.race([taskPromise, timeoutPromise])
|
|
138
|
+
: await taskPromise
|
|
139
|
+
} catch (error) {
|
|
140
|
+
if (isWorkerTaskError(error)) {
|
|
141
|
+
result = {
|
|
142
|
+
ok: false,
|
|
143
|
+
error: error.serialize(),
|
|
144
|
+
}
|
|
145
|
+
} else if (error instanceof Error && error.name === 'AbortError') {
|
|
146
|
+
result = {
|
|
147
|
+
ok: false,
|
|
148
|
+
error: new WorkerTaskError(
|
|
149
|
+
WorkerErrorCode.TASK_ABORTED,
|
|
150
|
+
error.message,
|
|
151
|
+
undefined,
|
|
152
|
+
).serialize(),
|
|
153
|
+
}
|
|
154
|
+
} else {
|
|
155
|
+
result = {
|
|
156
|
+
ok: false,
|
|
157
|
+
error: new WorkerTaskError(
|
|
158
|
+
WorkerErrorCode.UNKNOWN,
|
|
159
|
+
'Worker task failed unexpectedly',
|
|
160
|
+
undefined,
|
|
161
|
+
error,
|
|
162
|
+
).serialize(),
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
} finally {
|
|
166
|
+
if (timeoutTimer) clearTimeout(timeoutTimer)
|
|
167
|
+
try {
|
|
168
|
+
workerMessagePort?.close()
|
|
169
|
+
} catch {
|
|
170
|
+
// 忽略已 transfer/detached 端口的 close 异常
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
logger[result.ok ? 'info' : 'error'](
|
|
175
|
+
{ subject: taskParams.subject, ok: result.ok },
|
|
176
|
+
`Worker task ${result.ok ? 'completed' : 'failed'}`,
|
|
177
|
+
)
|
|
178
|
+
return result
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
async shutdown(): Promise<void> {
|
|
182
|
+
await this.#pool.close()
|
|
183
|
+
if (PiscinaWorkRunner.#instance === this) PiscinaWorkRunner.#instance = null
|
|
184
|
+
}
|
|
185
|
+
}
|