@invictus-group-ai/orchestra 0.5.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/LICENSE +21 -0
- package/LICENSING.md +49 -0
- package/README.md +507 -0
- package/assets/settings-template.json +99 -0
- package/bin/invi.js +6 -0
- package/content-dist/LICENSE +95 -0
- package/content-dist/PIPELINE.md +823 -0
- package/content-dist/README.md +128 -0
- package/content-dist/agents/README.md +135 -0
- package/content-dist/agents/mapping.json +476 -0
- package/content-dist/agents/stacks/backend-django.md +66 -0
- package/content-dist/agents/stacks/backend-dotnet.md +72 -0
- package/content-dist/agents/stacks/backend-fastapi.md +66 -0
- package/content-dist/agents/stacks/backend-laravel.md +66 -0
- package/content-dist/agents/stacks/backend-node.md +66 -0
- package/content-dist/agents/stacks/backend-spring.md +66 -0
- package/content-dist/agents/stacks/desktop-delphi.md +73 -0
- package/content-dist/agents/stacks/frontend-angular.md +65 -0
- package/content-dist/agents/stacks/frontend-react.md +67 -0
- package/content-dist/agents/stacks/frontend-svelte.md +67 -0
- package/content-dist/agents/stacks/frontend-vue.md +66 -0
- package/content-dist/agents/stacks/mobile-flutter.md +68 -0
- package/content-dist/agents/stacks/wordpress.md +66 -0
- package/content-dist/agents/universal/invi-qa.md +57 -0
- package/content-dist/agents/universal/invi-reviewer.md +61 -0
- package/content-dist/agents/universal/invi-security.md +55 -0
- package/content-dist/agents/universal/invi-tester.md +55 -0
- package/content-dist/agents/universal/invi-ui.md +85 -0
- package/content-dist/fragments/base.md +37 -0
- package/content-dist/fragments/domain/api-publica-rate-limiting.md +83 -0
- package/content-dist/fragments/domain/autenticacao-enterprise.md +86 -0
- package/content-dist/fragments/domain/busca-elasticsearch.md +86 -0
- package/content-dist/fragments/domain/dashboard-admin-rbac.md +80 -0
- package/content-dist/fragments/domain/design-system.md +71 -0
- package/content-dist/fragments/domain/ecommerce-completo.md +86 -0
- package/content-dist/fragments/domain/filas-jobs.md +80 -0
- package/content-dist/fragments/domain/integracao-crm-erp.md +82 -0
- package/content-dist/fragments/domain/lgpd.md +84 -0
- package/content-dist/fragments/domain/multi-tenancy.md +79 -0
- package/content-dist/fragments/domain/notificacoes-multicanal.md +81 -0
- package/content-dist/fragments/domain/pagamentos-brasil.md +85 -0
- package/content-dist/fragments/domain/plataforma-conteudo.md +77 -0
- package/content-dist/fragments/domain/realtime-websockets.md +92 -0
- package/content-dist/fragments/domain/relatorios-analytics.md +80 -0
- package/content-dist/fragments/domain/saas-stripe-billing.md +79 -0
- package/content-dist/fragments/domain/sistema-pagamentos.md +81 -0
- package/content-dist/fragments/domain/upload-midia.md +81 -0
- package/content-dist/fragments/domain/whatsapp-business.md +82 -0
- package/content-dist/fragments/index.json +1670 -0
- package/content-dist/fragments/references/angular-ngrx/app-config-and-testing.md +81 -0
- package/content-dist/fragments/references/angular-ngrx/store-pattern.md +155 -0
- package/content-dist/fragments/references/ansible-server-setup/layout-and-config.md +143 -0
- package/content-dist/fragments/references/ansible-server-setup/roles.md +238 -0
- package/content-dist/fragments/references/api-publica-rate-limiting/patterns.md +68 -0
- package/content-dist/fragments/references/astro-static/content-and-islands.md +117 -0
- package/content-dist/fragments/references/autenticacao-enterprise/pitfalls.md +70 -0
- package/content-dist/fragments/references/busca-elasticsearch/patterns.md +100 -0
- package/content-dist/fragments/references/chrome-extension-mv3/messaging-and-storage.md +109 -0
- package/content-dist/fragments/references/cli-typescript-commander/commands-and-config.md +136 -0
- package/content-dist/fragments/references/cloud-run-gcp/build-and-deploy.md +127 -0
- package/content-dist/fragments/references/cloud-run-gcp/iam-secrets-networking.md +65 -0
- package/content-dist/fragments/references/computer-vision-yolo/serving-and-export.md +182 -0
- package/content-dist/fragments/references/computer-vision-yolo/training-and-validation.md +131 -0
- package/content-dist/fragments/references/convex-react/functions.md +117 -0
- package/content-dist/fragments/references/convex-react/react-and-storage.md +109 -0
- package/content-dist/fragments/references/dashboard-admin-rbac/patterns.md +73 -0
- package/content-dist/fragments/references/data-pipeline-airflow/dag-patterns.md +149 -0
- package/content-dist/fragments/references/data-pipeline-airflow/operations.md +74 -0
- package/content-dist/fragments/references/delphi-object-pascal/legacy-extraction.md +175 -0
- package/content-dist/fragments/references/django-drf-celery/celery-tasks.md +47 -0
- package/content-dist/fragments/references/django-drf-celery/viewsets-and-serializers.md +92 -0
- package/content-dist/fragments/references/docker-compose-dev/compose-files.md +146 -0
- package/content-dist/fragments/references/docker-compose-dev/dockerfile-and-proxy.md +108 -0
- package/content-dist/fragments/references/dotnet-aspnet/data-and-di.md +90 -0
- package/content-dist/fragments/references/dotnet-aspnet/web-layer.md +88 -0
- package/content-dist/fragments/references/ecommerce-completo/patterns.md +76 -0
- package/content-dist/fragments/references/electron-app/ipc-bridge.md +123 -0
- package/content-dist/fragments/references/electron-app/security-and-packaging.md +134 -0
- package/content-dist/fragments/references/elixir-phoenix/context-and-web.md +112 -0
- package/content-dist/fragments/references/elixir-phoenix/processes.md +65 -0
- package/content-dist/fragments/references/filas-jobs/patterns.md +116 -0
- package/content-dist/fragments/references/fine-tuning-huggingface/data-and-export.md +114 -0
- package/content-dist/fragments/references/fine-tuning-huggingface/training-and-lora.md +123 -0
- package/content-dist/fragments/references/flutter/platform-channels-and-goldens.md +68 -0
- package/content-dist/fragments/references/flutter/state-and-widgets.md +95 -0
- package/content-dist/fragments/references/github-actions-cicd/workflows.md +235 -0
- package/content-dist/fragments/references/go-chi-gorm/http-layer.md +87 -0
- package/content-dist/fragments/references/go-chi-gorm/service-layer.md +58 -0
- package/content-dist/fragments/references/graphql-apollo/resolvers-and-loaders.md +128 -0
- package/content-dist/fragments/references/hono-bun/patterns.md +144 -0
- package/content-dist/fragments/references/integracao-crm-erp/patterns.md +100 -0
- package/content-dist/fragments/references/kubernetes-helm/chart-templates.md +162 -0
- package/content-dist/fragments/references/kubernetes-helm/secrets-storage-deploy.md +78 -0
- package/content-dist/fragments/references/langchain-python-agent/agent-and-cost.md +120 -0
- package/content-dist/fragments/references/langchain-python-agent/memory-and-resilience.md +76 -0
- package/content-dist/fragments/references/laravel/eloquent-and-queues.md +126 -0
- package/content-dist/fragments/references/laravel/http-layer.md +110 -0
- package/content-dist/fragments/references/lgpd/patterns.md +110 -0
- package/content-dist/fragments/references/llm-ops-production/routing-and-budget.md +118 -0
- package/content-dist/fragments/references/llm-ops-production/tracing-eval-ab.md +102 -0
- package/content-dist/fragments/references/microservices-docker/compose-and-gateway.md +93 -0
- package/content-dist/fragments/references/microservices-docker/events-and-correlation.md +88 -0
- package/content-dist/fragments/references/ml-fastapi-serving/metrics-drift-docker.md +97 -0
- package/content-dist/fragments/references/ml-fastapi-serving/serving-core.md +155 -0
- package/content-dist/fragments/references/ml-training-pipeline/dvc-pipeline.md +102 -0
- package/content-dist/fragments/references/ml-training-pipeline/mlflow-registry-ci.md +139 -0
- package/content-dist/fragments/references/monitoring-observability/alerts-and-config.md +169 -0
- package/content-dist/fragments/references/monitoring-observability/instrumentation-node.md +139 -0
- package/content-dist/fragments/references/multi-tenancy/patterns.md +85 -0
- package/content-dist/fragments/references/nestjs-typescript/guards-and-decorators.md +103 -0
- package/content-dist/fragments/references/nestjs-typescript/modules-dtos-setup.md +106 -0
- package/content-dist/fragments/references/nextjs-app-router/patterns.md +177 -0
- package/content-dist/fragments/references/nextjs-prisma-postgres/billing.md +167 -0
- package/content-dist/fragments/references/nextjs-trpc-drizzle/data-and-auth.md +121 -0
- package/content-dist/fragments/references/nextjs-trpc-drizzle/trpc-setup.md +62 -0
- package/content-dist/fragments/references/nodejs-express-typescript/config-and-tokens.md +48 -0
- package/content-dist/fragments/references/nodejs-express-typescript/middleware.md +108 -0
- package/content-dist/fragments/references/notificacoes-multicanal/patterns.md +78 -0
- package/content-dist/fragments/references/nuxt3-tailwind/server-routes.md +79 -0
- package/content-dist/fragments/references/nuxt3-tailwind/state-and-fetching.md +129 -0
- package/content-dist/fragments/references/openai-api-integration/calls.md +210 -0
- package/content-dist/fragments/references/openai-api-integration/client-and-cost.md +71 -0
- package/content-dist/fragments/references/pagamentos-brasil/gateways-reconciliation.md +92 -0
- package/content-dist/fragments/references/pagamentos-brasil/pix-boleto.md +115 -0
- package/content-dist/fragments/references/plataforma-conteudo/patterns.md +74 -0
- package/content-dist/fragments/references/python-fastapi/dependency-injection.md +99 -0
- package/content-dist/fragments/references/python-fastapi/settings-and-tasks.md +47 -0
- package/content-dist/fragments/references/rag-pipeline/ingestion.md +92 -0
- package/content-dist/fragments/references/rag-pipeline/retrieval-and-eval.md +148 -0
- package/content-dist/fragments/references/react-express-monolith/auth-and-client.md +110 -0
- package/content-dist/fragments/references/react-express-monolith/monorepo.md +71 -0
- package/content-dist/fragments/references/react-native-expo/native-patterns.md +103 -0
- package/content-dist/fragments/references/react-native-expo/navigation-and-auth.md +55 -0
- package/content-dist/fragments/references/react-ts-zustand-query/store-and-query.md +152 -0
- package/content-dist/fragments/references/react-typescript/feature-module.md +64 -0
- package/content-dist/fragments/references/react-typescript/forms-and-state.md +69 -0
- package/content-dist/fragments/references/react-typescript/recipes.md +37 -0
- package/content-dist/fragments/references/react-typescript/testing.md +40 -0
- package/content-dist/fragments/references/realtime-websockets/patterns.md +92 -0
- package/content-dist/fragments/references/relatorios-analytics/patterns.md +81 -0
- package/content-dist/fragments/references/remix-express-full/auth-and-uploads.md +88 -0
- package/content-dist/fragments/references/remix-express-full/express-server.md +54 -0
- package/content-dist/fragments/references/remix-typescript/auth-and-db.md +68 -0
- package/content-dist/fragments/references/remix-typescript/loaders-and-actions.md +98 -0
- package/content-dist/fragments/references/rust-axum/error-and-state.md +99 -0
- package/content-dist/fragments/references/rust-axum/handlers.md +87 -0
- package/content-dist/fragments/references/saas-stripe-billing/patterns.md +86 -0
- package/content-dist/fragments/references/serverless-lambda/handler-patterns.md +107 -0
- package/content-dist/fragments/references/sistema-pagamentos/pitfalls.md +54 -0
- package/content-dist/fragments/references/spring-boot/service-and-data.md +96 -0
- package/content-dist/fragments/references/spring-boot/web-layer.md +100 -0
- package/content-dist/fragments/references/supabase-nextjs/clients-and-middleware.md +102 -0
- package/content-dist/fragments/references/supabase-nextjs/rls-and-storage.md +86 -0
- package/content-dist/fragments/references/svelte-sveltekit/hooks-and-state.md +67 -0
- package/content-dist/fragments/references/svelte-sveltekit/load-and-actions.md +80 -0
- package/content-dist/fragments/references/t3-stack/routers-and-callers.md +75 -0
- package/content-dist/fragments/references/t3-stack/trpc-setup.md +60 -0
- package/content-dist/fragments/references/terraform-aws/modules-and-ci.md +114 -0
- package/content-dist/fragments/references/terraform-aws/state-and-workspaces.md +66 -0
- package/content-dist/fragments/references/turborepo-monorepo/pipeline-and-packages.md +84 -0
- package/content-dist/fragments/references/upload-midia/patterns.md +80 -0
- package/content-dist/fragments/references/vector-search-pinecone/client-and-upsert.md +98 -0
- package/content-dist/fragments/references/vector-search-pinecone/query-and-hybrid.md +81 -0
- package/content-dist/fragments/references/vps-deploy-producao/compose-prod.md +97 -0
- package/content-dist/fragments/references/vps-deploy-producao/proxy-and-operations.md +118 -0
- package/content-dist/fragments/references/vscode-extension/activation-and-tree.md +98 -0
- package/content-dist/fragments/references/vscode-extension/webview-csp.md +57 -0
- package/content-dist/fragments/references/vue3-pinia-vite/components-and-stores.md +73 -0
- package/content-dist/fragments/references/vue3-pinia-vite/queries-forms-testing.md +100 -0
- package/content-dist/fragments/references/whatsapp-business/patterns.md +107 -0
- package/content-dist/fragments/references/wordpress/hooks-and-security.md +92 -0
- package/content-dist/fragments/references/wordpress/wp-cli-gates.md +64 -0
- package/content-dist/fragments/stack/angular-ngrx.md +75 -0
- package/content-dist/fragments/stack/ansible-server-setup.md +69 -0
- package/content-dist/fragments/stack/astro-static.md +72 -0
- package/content-dist/fragments/stack/chrome-extension-mv3.md +66 -0
- package/content-dist/fragments/stack/cli-typescript-commander.md +66 -0
- package/content-dist/fragments/stack/cloud-run-gcp.md +63 -0
- package/content-dist/fragments/stack/computer-vision-yolo.md +62 -0
- package/content-dist/fragments/stack/convex-react.md +65 -0
- package/content-dist/fragments/stack/data-pipeline-airflow.md +64 -0
- package/content-dist/fragments/stack/delphi-object-pascal.md +63 -0
- package/content-dist/fragments/stack/django-drf-celery.md +63 -0
- package/content-dist/fragments/stack/docker-compose-dev.md +69 -0
- package/content-dist/fragments/stack/dotnet-aspnet.md +62 -0
- package/content-dist/fragments/stack/electron-app.md +70 -0
- package/content-dist/fragments/stack/elixir-phoenix.md +65 -0
- package/content-dist/fragments/stack/fine-tuning-huggingface.md +69 -0
- package/content-dist/fragments/stack/flutter.md +61 -0
- package/content-dist/fragments/stack/github-actions-cicd.md +73 -0
- package/content-dist/fragments/stack/go-chi-gorm.md +73 -0
- package/content-dist/fragments/stack/graphql-apollo.md +70 -0
- package/content-dist/fragments/stack/hono-bun.md +62 -0
- package/content-dist/fragments/stack/kubernetes-helm.md +67 -0
- package/content-dist/fragments/stack/langchain-python-agent.md +64 -0
- package/content-dist/fragments/stack/laravel.md +64 -0
- package/content-dist/fragments/stack/llm-ops-production.md +63 -0
- package/content-dist/fragments/stack/microservices-docker.md +70 -0
- package/content-dist/fragments/stack/ml-fastapi-serving.md +64 -0
- package/content-dist/fragments/stack/ml-training-pipeline.md +67 -0
- package/content-dist/fragments/stack/monitoring-observability.md +68 -0
- package/content-dist/fragments/stack/nestjs-typescript.md +68 -0
- package/content-dist/fragments/stack/nextjs-app-router.md +65 -0
- package/content-dist/fragments/stack/nextjs-prisma-postgres.md +61 -0
- package/content-dist/fragments/stack/nextjs-trpc-drizzle.md +63 -0
- package/content-dist/fragments/stack/nodejs-express-typescript.md +60 -0
- package/content-dist/fragments/stack/nuxt3-tailwind.md +62 -0
- package/content-dist/fragments/stack/openai-api-integration.md +58 -0
- package/content-dist/fragments/stack/python-fastapi.md +64 -0
- package/content-dist/fragments/stack/rag-pipeline.md +62 -0
- package/content-dist/fragments/stack/react-express-monolith.md +61 -0
- package/content-dist/fragments/stack/react-native-expo.md +68 -0
- package/content-dist/fragments/stack/react-ts-zustand-query.md +64 -0
- package/content-dist/fragments/stack/react-typescript.md +73 -0
- package/content-dist/fragments/stack/remix-express-full.md +63 -0
- package/content-dist/fragments/stack/remix-typescript.md +66 -0
- package/content-dist/fragments/stack/rust-axum.md +63 -0
- package/content-dist/fragments/stack/serverless-lambda.md +65 -0
- package/content-dist/fragments/stack/spring-boot.md +63 -0
- package/content-dist/fragments/stack/supabase-nextjs.md +64 -0
- package/content-dist/fragments/stack/svelte-sveltekit.md +67 -0
- package/content-dist/fragments/stack/t3-stack.md +63 -0
- package/content-dist/fragments/stack/terraform-aws.md +65 -0
- package/content-dist/fragments/stack/turborepo-monorepo.md +61 -0
- package/content-dist/fragments/stack/vector-search-pinecone.md +63 -0
- package/content-dist/fragments/stack/vps-deploy-producao.md +64 -0
- package/content-dist/fragments/stack/vscode-extension.md +64 -0
- package/content-dist/fragments/stack/vue3-pinia-vite.md +65 -0
- package/content-dist/fragments/stack/wordpress.md +63 -0
- package/content-dist/skills/invi-commit/SKILL.md +85 -0
- package/content-dist/skills/invi-journal/SKILL.md +67 -0
- package/content-dist/skills/invi-map/SKILL.md +118 -0
- package/content-dist/skills/invi-mode/SKILL.md +176 -0
- package/content-dist/skills/invi-pr/SKILL.md +142 -0
- package/content-dist/skills/invi-qa/SKILL.md +75 -0
- package/content-dist/skills/invi-refactor-legacy/SKILL.md +90 -0
- package/content-dist/skills/invi-review/SKILL.md +83 -0
- package/content-dist/skills/invi-security/SKILL.md +89 -0
- package/content-dist/skills/invi-status/SKILL.md +72 -0
- package/content-dist/skills/invi-task/SKILL.md +143 -0
- package/content-dist/skills/invi-test/SKILL.md +97 -0
- package/content-dist/skills/po-handoff/SKILL.md +130 -0
- package/content-dist/skills/po-intake/SKILL.md +115 -0
- package/content-dist/skills/po-lint/SKILL.md +82 -0
- package/content-dist/skills/po-spec/SKILL.md +138 -0
- package/content-dist/skills/po-status/SKILL.md +130 -0
- package/content-dist/skills/po-verify/SKILL.md +124 -0
- package/content-dist/templates/requirements/REQ-TEMPLATE.md +110 -0
- package/content-dist/templates/requirements/constitution-TEMPLATE.md +77 -0
- package/dist/baseline.d.ts +21 -0
- package/dist/baseline.d.ts.map +1 -0
- package/dist/baseline.js +43 -0
- package/dist/baseline.js.map +1 -0
- package/dist/cli.d.ts +15 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +345 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/doctor.d.ts +31 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +173 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/export.d.ts +49 -0
- package/dist/commands/export.d.ts.map +1 -0
- package/dist/commands/export.js +95 -0
- package/dist/commands/export.js.map +1 -0
- package/dist/commands/gate.d.ts +42 -0
- package/dist/commands/gate.d.ts.map +1 -0
- package/dist/commands/gate.js +97 -0
- package/dist/commands/gate.js.map +1 -0
- package/dist/commands/init.d.ts +88 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +540 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/journalCmd.d.ts +47 -0
- package/dist/commands/journalCmd.d.ts.map +1 -0
- package/dist/commands/journalCmd.js +89 -0
- package/dist/commands/journalCmd.js.map +1 -0
- package/dist/commands/keys.d.ts +68 -0
- package/dist/commands/keys.d.ts.map +1 -0
- package/dist/commands/keys.js +240 -0
- package/dist/commands/keys.js.map +1 -0
- package/dist/commands/map.d.ts +123 -0
- package/dist/commands/map.d.ts.map +1 -0
- package/dist/commands/map.js +383 -0
- package/dist/commands/map.js.map +1 -0
- package/dist/commands/plan.d.ts +28 -0
- package/dist/commands/plan.d.ts.map +1 -0
- package/dist/commands/plan.js +64 -0
- package/dist/commands/plan.js.map +1 -0
- package/dist/commands/req.d.ts +92 -0
- package/dist/commands/req.d.ts.map +1 -0
- package/dist/commands/req.js +270 -0
- package/dist/commands/req.js.map +1 -0
- package/dist/commands/review.d.ts +40 -0
- package/dist/commands/review.d.ts.map +1 -0
- package/dist/commands/review.js +101 -0
- package/dist/commands/review.js.map +1 -0
- package/dist/commands/run.d.ts +33 -0
- package/dist/commands/run.d.ts.map +1 -0
- package/dist/commands/run.js +151 -0
- package/dist/commands/run.js.map +1 -0
- package/dist/commands/ship.d.ts +45 -0
- package/dist/commands/ship.d.ts.map +1 -0
- package/dist/commands/ship.js +252 -0
- package/dist/commands/ship.js.map +1 -0
- package/dist/commands/status.d.ts +36 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +152 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/commands/sync.d.ts +91 -0
- package/dist/commands/sync.d.ts.map +1 -0
- package/dist/commands/sync.js +331 -0
- package/dist/commands/sync.js.map +1 -0
- package/dist/commands/syncCommits.d.ts +56 -0
- package/dist/commands/syncCommits.d.ts.map +1 -0
- package/dist/commands/syncCommits.js +97 -0
- package/dist/commands/syncCommits.js.map +1 -0
- package/dist/commands/task.d.ts +108 -0
- package/dist/commands/task.d.ts.map +1 -0
- package/dist/commands/task.js +217 -0
- package/dist/commands/task.js.map +1 -0
- package/dist/commands/update.d.ts +92 -0
- package/dist/commands/update.d.ts.map +1 -0
- package/dist/commands/update.js +541 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/commands/verifyTask.d.ts +50 -0
- package/dist/commands/verifyTask.d.ts.map +1 -0
- package/dist/commands/verifyTask.js +172 -0
- package/dist/commands/verifyTask.js.map +1 -0
- package/dist/content.d.ts +128 -0
- package/dist/content.d.ts.map +1 -0
- package/dist/content.js +177 -0
- package/dist/content.js.map +1 -0
- package/dist/detect.d.ts +122 -0
- package/dist/detect.d.ts.map +1 -0
- package/dist/detect.js +594 -0
- package/dist/detect.js.map +1 -0
- package/dist/events.d.ts +36 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +76 -0
- package/dist/events.js.map +1 -0
- package/dist/frontmatter.d.ts +15 -0
- package/dist/frontmatter.d.ts.map +1 -0
- package/dist/frontmatter.js +74 -0
- package/dist/frontmatter.js.map +1 -0
- package/dist/i18n/en.d.ts +421 -0
- package/dist/i18n/en.d.ts.map +1 -0
- package/dist/i18n/en.js +443 -0
- package/dist/i18n/en.js.map +1 -0
- package/dist/i18n/index.d.ts +40 -0
- package/dist/i18n/index.d.ts.map +1 -0
- package/dist/i18n/index.js +66 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/i18n/pt-BR.d.ts +11 -0
- package/dist/i18n/pt-BR.d.ts.map +1 -0
- package/dist/i18n/pt-BR.js +435 -0
- package/dist/i18n/pt-BR.js.map +1 -0
- package/dist/identity.d.ts +78 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +152 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +79 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +48 -0
- package/dist/index.js.map +1 -0
- package/dist/insights.d.ts +86 -0
- package/dist/insights.d.ts.map +1 -0
- package/dist/insights.js +199 -0
- package/dist/insights.js.map +1 -0
- package/dist/interview.d.ts +81 -0
- package/dist/interview.d.ts.map +1 -0
- package/dist/interview.js +283 -0
- package/dist/interview.js.map +1 -0
- package/dist/inventory.d.ts +79 -0
- package/dist/inventory.d.ts.map +1 -0
- package/dist/inventory.js +86 -0
- package/dist/inventory.js.map +1 -0
- package/dist/journal.d.ts +22 -0
- package/dist/journal.d.ts.map +1 -0
- package/dist/journal.js +88 -0
- package/dist/journal.js.map +1 -0
- package/dist/migrations/legacyNames.d.ts +45 -0
- package/dist/migrations/legacyNames.d.ts.map +1 -0
- package/dist/migrations/legacyNames.js +118 -0
- package/dist/migrations/legacyNames.js.map +1 -0
- package/dist/plan.d.ts +42 -0
- package/dist/plan.d.ts.map +1 -0
- package/dist/plan.js +126 -0
- package/dist/plan.js.map +1 -0
- package/dist/render/agents.d.ts +327 -0
- package/dist/render/agents.d.ts.map +1 -0
- package/dist/render/agents.js +356 -0
- package/dist/render/agents.js.map +1 -0
- package/dist/render/claudeMd.d.ts +29 -0
- package/dist/render/claudeMd.d.ts.map +1 -0
- package/dist/render/claudeMd.js +110 -0
- package/dist/render/claudeMd.js.map +1 -0
- package/dist/render/githooks.d.ts +41 -0
- package/dist/render/githooks.d.ts.map +1 -0
- package/dist/render/githooks.js +168 -0
- package/dist/render/githooks.js.map +1 -0
- package/dist/render/markers.d.ts +13 -0
- package/dist/render/markers.d.ts.map +1 -0
- package/dist/render/markers.js +35 -0
- package/dist/render/markers.js.map +1 -0
- package/dist/render/requirements.d.ts +56 -0
- package/dist/render/requirements.d.ts.map +1 -0
- package/dist/render/requirements.js +86 -0
- package/dist/render/requirements.js.map +1 -0
- package/dist/render/settings.d.ts +43 -0
- package/dist/render/settings.d.ts.map +1 -0
- package/dist/render/settings.js +94 -0
- package/dist/render/settings.js.map +1 -0
- package/dist/render/transparency.d.ts +7 -0
- package/dist/render/transparency.d.ts.map +1 -0
- package/dist/render/transparency.js +164 -0
- package/dist/render/transparency.js.map +1 -0
- package/dist/requirements.d.ts +84 -0
- package/dist/requirements.d.ts.map +1 -0
- package/dist/requirements.js +229 -0
- package/dist/requirements.js.map +1 -0
- package/dist/sizing.d.ts +63 -0
- package/dist/sizing.d.ts.map +1 -0
- package/dist/sizing.js +104 -0
- package/dist/sizing.js.map +1 -0
- package/dist/tasks.d.ts +199 -0
- package/dist/tasks.d.ts.map +1 -0
- package/dist/tasks.js +320 -0
- package/dist/tasks.js.map +1 -0
- package/dist/util/diff3.d.ts +26 -0
- package/dist/util/diff3.d.ts.map +1 -0
- package/dist/util/diff3.js +112 -0
- package/dist/util/diff3.js.map +1 -0
- package/dist/util/fsx.d.ts +33 -0
- package/dist/util/fsx.d.ts.map +1 -0
- package/dist/util/fsx.js +153 -0
- package/dist/util/fsx.js.map +1 -0
- package/dist/util/git.d.ts +58 -0
- package/dist/util/git.d.ts.map +1 -0
- package/dist/util/git.js +171 -0
- package/dist/util/git.js.map +1 -0
- package/dist/util/merge.d.ts +27 -0
- package/dist/util/merge.d.ts.map +1 -0
- package/dist/util/merge.js +78 -0
- package/dist/util/merge.js.map +1 -0
- package/dist/util/out.d.ts +18 -0
- package/dist/util/out.d.ts.map +1 -0
- package/dist/util/out.js +23 -0
- package/dist/util/out.js.map +1 -0
- package/dist/util/proc.d.ts +12 -0
- package/dist/util/proc.d.ts.map +1 -0
- package/dist/util/proc.js +45 -0
- package/dist/util/proc.js.map +1 -0
- package/dist/util/registry.d.ts +58 -0
- package/dist/util/registry.d.ts.map +1 -0
- package/dist/util/registry.js +240 -0
- package/dist/util/registry.js.map +1 -0
- package/dist/verify.d.ts +52 -0
- package/dist/verify.d.ts.map +1 -0
- package/dist/verify.js +205 -0
- package/dist/verify.js.map +1 -0
- package/dist/version.d.ts +5 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +18 -0
- package/dist/version.js.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# Reference: Nuxt state, composables and fetching (read on demand)
|
|
2
|
+
|
|
3
|
+
Exemplar for `stack/nuxt3-tailwind` — setup-store Pinia, composable vs util, fetch patterns, route middleware, tests.
|
|
4
|
+
|
|
5
|
+
## Composable vs util
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
// utils/formatDate.ts — pure, no reactivity, auto-imported
|
|
9
|
+
export function formatDate(date: Date, locale = 'pt-BR'): string {
|
|
10
|
+
return new Intl.DateTimeFormat(locale, { dateStyle: 'medium' }).format(date);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// composables/usePagination.ts — reactive, auto-imported
|
|
14
|
+
export function usePagination(totalItems: Ref<number>, perPage = 10) {
|
|
15
|
+
const currentPage = ref(1);
|
|
16
|
+
const totalPages = computed(() => Math.ceil(totalItems.value / perPage));
|
|
17
|
+
const offset = computed(() => (currentPage.value - 1) * perPage);
|
|
18
|
+
|
|
19
|
+
function goTo(page: number) {
|
|
20
|
+
currentPage.value = Math.max(1, Math.min(page, totalPages.value));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return { currentPage, totalPages, offset, goTo };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// composables/useProjects.ts — SSR-aware fetching wrapper
|
|
27
|
+
export function useProjects() {
|
|
28
|
+
const { data, pending, error, refresh } = useFetch('/api/projects');
|
|
29
|
+
return { projects: data, loading: pending, error, refresh };
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Pinia setup store
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
// stores/auth.store.ts — explicit import at use sites (stores are NOT auto-imported)
|
|
37
|
+
import { defineStore } from 'pinia';
|
|
38
|
+
import type { User } from '~/types';
|
|
39
|
+
|
|
40
|
+
export const useAuthStore = defineStore('auth', () => {
|
|
41
|
+
const user = ref<User | null>(null);
|
|
42
|
+
const loading = ref(false);
|
|
43
|
+
|
|
44
|
+
const isAuthenticated = computed(() => user.value !== null);
|
|
45
|
+
const isAdmin = computed(() => user.value?.role === 'admin');
|
|
46
|
+
|
|
47
|
+
async function login(email: string, password: string) {
|
|
48
|
+
loading.value = true;
|
|
49
|
+
try {
|
|
50
|
+
const { token, user: loggedUser } = await $fetch('/api/auth/login', {
|
|
51
|
+
method: 'POST',
|
|
52
|
+
body: { email, password },
|
|
53
|
+
});
|
|
54
|
+
user.value = loggedUser;
|
|
55
|
+
useCookie('auth_token').value = token;
|
|
56
|
+
await navigateTo('/dashboard');
|
|
57
|
+
} finally {
|
|
58
|
+
loading.value = false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async function logout() {
|
|
63
|
+
await $fetch('/api/auth/logout', { method: 'POST' });
|
|
64
|
+
user.value = null;
|
|
65
|
+
useCookie('auth_token').value = null;
|
|
66
|
+
await navigateTo('/login');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return { user, loading, isAuthenticated, isAdmin, login, logout };
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Fetch decision in practice
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
// Page — SSR aware, deduped, reactive to currentPage
|
|
77
|
+
const { data: projects, pending, refresh } = await useFetch('/api/projects', {
|
|
78
|
+
query: { page: currentPage },
|
|
79
|
+
watch: [currentPage],
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// Event-driven mutation — one-shot, not SSR
|
|
83
|
+
async function deleteProject(id: string) {
|
|
84
|
+
await $fetch(`/api/projects/${id}`, { method: 'DELETE' });
|
|
85
|
+
refresh();
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Global route middleware
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
// middleware/auth.global.ts — runs on EVERY route
|
|
93
|
+
export default defineNuxtRouteMiddleware((to) => {
|
|
94
|
+
const authStore = useAuthStore();
|
|
95
|
+
const publicRoutes = ['/', '/login', '/register'];
|
|
96
|
+
|
|
97
|
+
if (!authStore.isAuthenticated && !publicRoutes.includes(to.path)) {
|
|
98
|
+
return navigateTo('/login');
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Tests
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
// tests/unit/composables/usePagination.test.ts
|
|
107
|
+
import { describe, it, expect } from 'vitest';
|
|
108
|
+
import { ref } from 'vue';
|
|
109
|
+
import { usePagination } from '~/composables/usePagination';
|
|
110
|
+
|
|
111
|
+
describe('usePagination', () => {
|
|
112
|
+
it('computes totalPages correctly', () => {
|
|
113
|
+
const total = ref(100);
|
|
114
|
+
const { totalPages } = usePagination(total, 10);
|
|
115
|
+
expect(totalPages.value).toBe(10);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
// tests/e2e/login.spec.ts
|
|
120
|
+
import { test, expect } from '@playwright/test';
|
|
121
|
+
|
|
122
|
+
test('login with valid credentials', async ({ page }) => {
|
|
123
|
+
await page.goto('/login');
|
|
124
|
+
await page.fill('[name=email]', 'user@test.com');
|
|
125
|
+
await page.fill('[name=password]', 'password123');
|
|
126
|
+
await page.click('[type=submit]');
|
|
127
|
+
await expect(page).toHaveURL('/dashboard');
|
|
128
|
+
});
|
|
129
|
+
```
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
# Reference: LLM call patterns (read on demand)
|
|
2
|
+
|
|
3
|
+
Exemplar for `stack/openai-api-integration` — moderation gate, structured outputs, caching, streaming, tool calling, error handling. `env.EXTRACTION_MODEL` / `env.CHAT_MODEL` resolve to ids from `models.json`.
|
|
4
|
+
|
|
5
|
+
## Moderation gate (before every user-input call)
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
// src/lib/moderation.ts
|
|
9
|
+
import { openai } from './openai'
|
|
10
|
+
|
|
11
|
+
export class ContentPolicyError extends Error {
|
|
12
|
+
constructor(public categories: Record<string, boolean>) {
|
|
13
|
+
super('Content violates usage policy')
|
|
14
|
+
this.name = 'ContentPolicyError'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function moderateInput(text: string): Promise<void> {
|
|
19
|
+
const response = await openai.moderations.create({ input: text })
|
|
20
|
+
const result = response.results[0]
|
|
21
|
+
|
|
22
|
+
if (result.flagged) {
|
|
23
|
+
const flagged = Object.fromEntries(
|
|
24
|
+
Object.entries(result.categories).filter(([, v]) => v),
|
|
25
|
+
)
|
|
26
|
+
throw new ContentPolicyError(flagged)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Structured outputs with Zod (SDK parse helper, no regex)
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
// src/schemas/outputs.ts
|
|
35
|
+
import { z } from 'zod'
|
|
36
|
+
|
|
37
|
+
export const ProductExtractionSchema = z.object({
|
|
38
|
+
name: z.string().describe('Product name as stated in the text'),
|
|
39
|
+
price: z.number().nullable().describe('Price in USD, null if not mentioned'),
|
|
40
|
+
features: z.array(z.string()).describe('List of product features'),
|
|
41
|
+
sentiment: z.enum(['positive', 'neutral', 'negative']).describe('Overall product sentiment'),
|
|
42
|
+
})
|
|
43
|
+
export type ProductExtraction = z.infer<typeof ProductExtractionSchema>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
// src/services/extraction.ts
|
|
48
|
+
import { openai } from '../lib/openai'
|
|
49
|
+
import { zodResponseFormat } from 'openai/helpers/zod'
|
|
50
|
+
import { ProductExtractionSchema, type ProductExtraction } from '../schemas/outputs'
|
|
51
|
+
import { moderateInput } from '../lib/moderation'
|
|
52
|
+
import { assertWithinBudget, estimateInputTokens } from '../utils/tokenCount'
|
|
53
|
+
import { env } from '../config/env'
|
|
54
|
+
|
|
55
|
+
export async function extractProductInfo(text: string): Promise<ProductExtraction> {
|
|
56
|
+
await moderateInput(text) // 1. moderate first
|
|
57
|
+
const inputTokens = estimateInputTokens(text, env.EXTRACTION_MODEL)
|
|
58
|
+
assertWithinBudget(env.EXTRACTION_MODEL, inputTokens, 500) // 2. budget check
|
|
59
|
+
|
|
60
|
+
const completion = await openai.chat.completions.parse({ // 3. native parse helper
|
|
61
|
+
model: env.EXTRACTION_MODEL,
|
|
62
|
+
temperature: 0,
|
|
63
|
+
messages: [
|
|
64
|
+
{ role: 'system', content: 'Extract product information from the provided text. Return null for missing fields.' },
|
|
65
|
+
{ role: 'user', content: text },
|
|
66
|
+
],
|
|
67
|
+
response_format: zodResponseFormat(ProductExtractionSchema, 'product_extraction'),
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
const parsed = completion.choices[0].message.parsed
|
|
71
|
+
if (!parsed) throw new Error('Failed to parse structured output')
|
|
72
|
+
return parsed
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Redis caching (deterministic calls only)
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
// src/lib/cache.ts
|
|
80
|
+
import { Redis } from 'ioredis'
|
|
81
|
+
import { createHash } from 'crypto'
|
|
82
|
+
|
|
83
|
+
const redis = new Redis(process.env.REDIS_URL || 'redis://localhost:6379')
|
|
84
|
+
const CACHE_TTL = 3600 // 1 hour minimum
|
|
85
|
+
|
|
86
|
+
export function buildCacheKey(model: string, messages: object, temperature: number): string {
|
|
87
|
+
if (temperature !== 0) return '' // only deterministic calls are cacheable
|
|
88
|
+
const hash = createHash('sha256').update(JSON.stringify({ model, messages })).digest('hex')
|
|
89
|
+
return `llm:cache:${hash}`
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export async function getCached<T>(key: string): Promise<T | null> {
|
|
93
|
+
if (!key) return null
|
|
94
|
+
const cached = await redis.get(key)
|
|
95
|
+
return cached ? (JSON.parse(cached) as T) : null
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export async function setCached<T>(key: string, value: T): Promise<void> {
|
|
99
|
+
if (!key) return
|
|
100
|
+
await redis.setex(key, CACHE_TTL, JSON.stringify(value))
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Streaming to the client (SSE) with usage logging
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
// src/services/streaming.ts
|
|
108
|
+
import { openai } from '../lib/openai'
|
|
109
|
+
import { logger } from '../lib/logger'
|
|
110
|
+
import { env } from '../config/env'
|
|
111
|
+
import type { Response } from 'express'
|
|
112
|
+
|
|
113
|
+
export async function streamChatResponse(userMessage: string, res: Response): Promise<void> {
|
|
114
|
+
res.setHeader('Content-Type', 'text/event-stream')
|
|
115
|
+
res.setHeader('Cache-Control', 'no-cache')
|
|
116
|
+
res.setHeader('Connection', 'keep-alive')
|
|
117
|
+
|
|
118
|
+
const stream = openai.chat.completions.stream({
|
|
119
|
+
model: env.CHAT_MODEL,
|
|
120
|
+
messages: [{ role: 'user', content: userMessage }],
|
|
121
|
+
max_tokens: 1024,
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
for await (const chunk of stream) {
|
|
125
|
+
const delta = chunk.choices[0]?.delta?.content
|
|
126
|
+
if (delta) res.write(`data: ${JSON.stringify({ text: delta })}\n\n`)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const finalCompletion = await stream.finalChatCompletion()
|
|
130
|
+
logger.info({
|
|
131
|
+
event: 'stream_complete',
|
|
132
|
+
input_tokens: finalCompletion.usage?.prompt_tokens,
|
|
133
|
+
output_tokens: finalCompletion.usage?.completion_tokens,
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
res.write('data: [DONE]\n\n')
|
|
137
|
+
res.end()
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Tool-calling loop (strict schemas)
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
// src/services/chat.ts
|
|
145
|
+
const tools: OpenAI.Chat.ChatCompletionTool[] = [
|
|
146
|
+
{
|
|
147
|
+
type: 'function',
|
|
148
|
+
function: {
|
|
149
|
+
name: 'get_weather',
|
|
150
|
+
description: 'Get current weather for a city',
|
|
151
|
+
parameters: {
|
|
152
|
+
type: 'object',
|
|
153
|
+
properties: {
|
|
154
|
+
city: { type: 'string', description: 'City name' },
|
|
155
|
+
unit: { type: 'string', enum: ['celsius', 'fahrenheit'] },
|
|
156
|
+
},
|
|
157
|
+
required: ['city'],
|
|
158
|
+
additionalProperties: false,
|
|
159
|
+
},
|
|
160
|
+
strict: true, // guaranteed schema adherence
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
]
|
|
164
|
+
|
|
165
|
+
async function chatWithTools(userMessage: string): Promise<string> {
|
|
166
|
+
const messages: OpenAI.Chat.ChatCompletionMessageParam[] = [
|
|
167
|
+
{ role: 'user', content: userMessage },
|
|
168
|
+
]
|
|
169
|
+
|
|
170
|
+
const response = await openai.chat.completions.create({
|
|
171
|
+
model: env.CHAT_MODEL, messages, tools, tool_choice: 'auto',
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
const toolCalls = response.choices[0].message.tool_calls
|
|
175
|
+
if (!toolCalls?.length) return response.choices[0].message.content ?? ''
|
|
176
|
+
|
|
177
|
+
messages.push(response.choices[0].message) // append assistant message first
|
|
178
|
+
|
|
179
|
+
for (const toolCall of toolCalls) {
|
|
180
|
+
const args = JSON.parse(toolCall.function.arguments)
|
|
181
|
+
const result = await executeToolCall(toolCall.function.name, args)
|
|
182
|
+
messages.push({ role: 'tool', tool_call_id: toolCall.id, content: JSON.stringify(result) })
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const finalResponse = await openai.chat.completions.create({ model: env.CHAT_MODEL, messages })
|
|
186
|
+
return finalResponse.choices[0].message.content ?? ''
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Typed error handling
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
import OpenAI from 'openai'
|
|
194
|
+
|
|
195
|
+
export function handleOpenAIError(error: unknown): never {
|
|
196
|
+
if (error instanceof OpenAI.RateLimitError) {
|
|
197
|
+
throw new Error(`Rate limit exceeded. Retry after: ${error.headers?.['retry-after']}s`)
|
|
198
|
+
}
|
|
199
|
+
if (error instanceof OpenAI.AuthenticationError) {
|
|
200
|
+
throw new Error('Invalid API key. Check OPENAI_API_KEY env var.')
|
|
201
|
+
}
|
|
202
|
+
if (error instanceof OpenAI.BadRequestError) {
|
|
203
|
+
throw new Error(`Bad request: ${error.message}`)
|
|
204
|
+
}
|
|
205
|
+
if (error instanceof OpenAI.APIConnectionError) {
|
|
206
|
+
throw new Error('Network error connecting to the API. Check connectivity.')
|
|
207
|
+
}
|
|
208
|
+
throw error // re-throw unknown errors
|
|
209
|
+
}
|
|
210
|
+
```
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Reference: LLM client singleton and cost control (read on demand)
|
|
2
|
+
|
|
3
|
+
Exemplar for `stack/openai-api-integration` — one client instance, config-driven pricing, pre-call budget assertion. Model ids and prices load from versioned config (`models.json`), never literals.
|
|
4
|
+
|
|
5
|
+
## Client singleton
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
// src/lib/openai.ts
|
|
9
|
+
import OpenAI from 'openai'
|
|
10
|
+
|
|
11
|
+
if (!process.env.OPENAI_API_KEY) {
|
|
12
|
+
throw new Error('OPENAI_API_KEY environment variable is required')
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const openai = new OpenAI({
|
|
16
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
17
|
+
maxRetries: 3, // built-in retry for rate-limit and server errors
|
|
18
|
+
timeout: 30_000, // per-request timeout
|
|
19
|
+
})
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Config-driven pricing and cost estimation
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
// src/lib/cost.ts
|
|
26
|
+
import modelsConfig from '../../config/models.json'
|
|
27
|
+
// models.json shape: { "<model-id>": { "inputPer1K": number, "outputPer1K": number, "budgetPerCall": number } }
|
|
28
|
+
|
|
29
|
+
type ModelPricing = { inputPer1K: number; outputPer1K: number; budgetPerCall: number }
|
|
30
|
+
|
|
31
|
+
export function pricingFor(model: string): ModelPricing {
|
|
32
|
+
const pricing = (modelsConfig as Record<string, ModelPricing>)[model]
|
|
33
|
+
if (!pricing) throw new Error(`No pricing configured for model "${model}" — update models.json`)
|
|
34
|
+
return pricing
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function estimateCost(model: string, inputTokens: number, outputTokens: number): number {
|
|
38
|
+
const p = pricingFor(model)
|
|
39
|
+
return (inputTokens / 1000) * p.inputPer1K + (outputTokens / 1000) * p.outputPer1K
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Pre-call token estimation and budget assertion
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
// src/utils/tokenCount.ts
|
|
47
|
+
import { encoding_for_model, TiktokenModel } from 'tiktoken'
|
|
48
|
+
import { pricingFor, estimateCost } from '../lib/cost'
|
|
49
|
+
|
|
50
|
+
export function estimateInputTokens(text: string, model: string): number {
|
|
51
|
+
const enc = encoding_for_model(model as TiktokenModel)
|
|
52
|
+
const tokens = enc.encode(text).length
|
|
53
|
+
enc.free()
|
|
54
|
+
return tokens
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function assertWithinBudget(
|
|
58
|
+
model: string,
|
|
59
|
+
inputTokens: number,
|
|
60
|
+
expectedMaxOutputTokens: number,
|
|
61
|
+
): void {
|
|
62
|
+
const estimated = estimateCost(model, inputTokens, expectedMaxOutputTokens)
|
|
63
|
+
const limit = pricingFor(model).budgetPerCall
|
|
64
|
+
|
|
65
|
+
if (estimated > limit) {
|
|
66
|
+
throw new Error(
|
|
67
|
+
`Estimated cost $${estimated.toFixed(4)} exceeds per-call budget $${limit} for model ${model}`,
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
```
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# Reference: gateway adapters and reconciliation (read on demand)
|
|
2
|
+
|
|
3
|
+
Exemplar for `domain/pagamentos-brasil` — the adapter port, gateway family differences, the reconciliation job, and the charge state machine. Evicted from the standing fragment; read when integrating a gateway or building reconciliation.
|
|
4
|
+
|
|
5
|
+
## One port, one adapter per gateway
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
// The port is the ONLY payments surface the application sees.
|
|
9
|
+
interface PaymentGateway {
|
|
10
|
+
createDynamicQr(input: { txid: string; amountCents: number; ttlSeconds: number }): Promise<QrCode>;
|
|
11
|
+
createBoleto(input: { chargeId: string; amountCents: number; dueDate: string }): Promise<Boleto>;
|
|
12
|
+
getCharge(txid: string): Promise<ChargeStatus>; // the polling/reconciliation seam
|
|
13
|
+
requestDevolucao(input: { endToEndId: string; refundId: string; amountCents: number }): Promise<void>;
|
|
14
|
+
verifyWebhook(rawBody: Buffer, headers: Headers): boolean; // provider-specific HMAC/mTLS
|
|
15
|
+
parseWebhook(rawBody: Buffer): NormalizedEvent; // provider shape → internal event
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Provider families (Mercado Pago, Pagar.me, Asaas, Efí) differ in webhook payload shape, signature scheme, retry policy, and sandbox fidelity. Those differences live inside the adapter — `NormalizedEvent` is the only shape that crosses the port. If a provider type or field name appears outside the adapter, the port has leaked.
|
|
20
|
+
|
|
21
|
+
## Contract tests with recorded webhooks
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
// Record real sandbox webhook deliveries once; replay them against every
|
|
25
|
+
// adapter forever. New gateway = new adapter + the same contract suite.
|
|
26
|
+
describe.each(adapters)('PaymentGateway contract: %s', (adapter) => {
|
|
27
|
+
it('verifies a genuine signature and rejects a tampered body', () => {
|
|
28
|
+
const { rawBody, headers } = fixtures[adapter.name].paidEvent;
|
|
29
|
+
expect(adapter.verifyWebhook(rawBody, headers)).toBe(true);
|
|
30
|
+
expect(adapter.verifyWebhook(tamper(rawBody), headers)).toBe(false);
|
|
31
|
+
});
|
|
32
|
+
it('normalizes the paid event to the internal shape', () => {
|
|
33
|
+
const event = adapter.parseWebhook(fixtures[adapter.name].paidEvent.rawBody);
|
|
34
|
+
expect(event).toMatchObject({ kind: 'paid', txid: expect.any(String), amountCents: expect.any(Number) });
|
|
35
|
+
});
|
|
36
|
+
it('credits exactly once when the same event is delivered twice', async () => {
|
|
37
|
+
await deliver(adapter, fixtures[adapter.name].paidEvent);
|
|
38
|
+
await deliver(adapter, fixtures[adapter.name].paidEvent); // retry storm
|
|
39
|
+
expect(await ledger.creditsFor(event.txid)).toHaveLength(1);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Charge state machine
|
|
45
|
+
|
|
46
|
+
```javascript
|
|
47
|
+
// Transitions are data; anything not listed is illegal — rejected and logged,
|
|
48
|
+
// never silently applied. Out-of-order webhooks hit this wall, not the ledger.
|
|
49
|
+
const TRANSITIONS = {
|
|
50
|
+
created: ['waiting', 'failed'],
|
|
51
|
+
waiting: ['confirmed', 'expired', 'failed'],
|
|
52
|
+
confirmed: ['settled', 'refunded'], // boleto float lives between these
|
|
53
|
+
settled: ['refunded'],
|
|
54
|
+
refunded: [], expired: [], failed: [],
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
async function applyTransition(trx, txid, next) {
|
|
58
|
+
const charge = await trx.charges.forUpdate(txid); // row lock: serialize races
|
|
59
|
+
if (!TRANSITIONS[charge.status]?.includes(next)) {
|
|
60
|
+
log.warn('charge.illegal_transition', { txid, from: charge.status, to: next });
|
|
61
|
+
throw new IllegalTransition(charge.status, next);
|
|
62
|
+
}
|
|
63
|
+
await trx.charges.update(txid, { status: next, [`${next}_at`]: now() });
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Reconciliation job
|
|
68
|
+
|
|
69
|
+
```javascript
|
|
70
|
+
// Scheduled (e.g. daily): diff the provider's statement against the local
|
|
71
|
+
// ledger BOTH ways. Divergence alerts a human — the job never auto-corrects.
|
|
72
|
+
async function reconcile(day) {
|
|
73
|
+
const provider = await gateway.listTransactions(day); // statement/API
|
|
74
|
+
const local = await db.ledger.entriesFor(day);
|
|
75
|
+
|
|
76
|
+
const missingLocally = provider.filter((p) => !local.some((l) => l.txid === p.txid));
|
|
77
|
+
const missingAtProvider = local.filter((l) => !provider.some((p) => p.txid === l.txid));
|
|
78
|
+
const amountMismatch = provider.filter((p) => {
|
|
79
|
+
const l = local.find((x) => x.txid === p.txid);
|
|
80
|
+
return l && l.amount_cents !== p.amount_cents;
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
for (const diff of [...missingLocally, ...missingAtProvider, ...amountMismatch]) {
|
|
84
|
+
await db.reconciliationIssues.insert({ day, txid: diff.txid, kind: diff.kind });
|
|
85
|
+
}
|
|
86
|
+
if (missingLocally.length + missingAtProvider.length + amountMismatch.length > 0) {
|
|
87
|
+
alertHuman('reconciliation.divergence', { day });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
`missingLocally` usually means a lost webhook (poll and repair through the state machine); `missingAtProvider` means local state the provider never saw — a serious bug, always investigated by a person.
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# Reference: Pix and boleto flows (read on demand)
|
|
2
|
+
|
|
3
|
+
Exemplar for `domain/pagamentos-brasil` — dynamic QR lifecycle, the double-credit-proof webhook handler, devolução, and boleto settlement accounting. Evicted from the standing fragment; read when implementing charge creation, webhook processing, refunds, or boleto accounting.
|
|
4
|
+
|
|
5
|
+
## Dynamic QR lifecycle
|
|
6
|
+
|
|
7
|
+
```javascript
|
|
8
|
+
// Persist the charge BEFORE showing the QR — a QR the user can pay
|
|
9
|
+
// against a txid you never recorded is unreconcilable money.
|
|
10
|
+
async function createPixCharge({ orderId, amountCents, ttlSeconds }) {
|
|
11
|
+
const txid = generateTxid(); // provider-conformant, unique per charge
|
|
12
|
+
await db.charges.insert({
|
|
13
|
+
txid,
|
|
14
|
+
order_id: orderId,
|
|
15
|
+
amount_cents: amountCents, // integer centavos, never floats
|
|
16
|
+
status: 'created',
|
|
17
|
+
expires_at: addSeconds(now(), ttlSeconds), // explicit expiry, always
|
|
18
|
+
});
|
|
19
|
+
const qr = await gateway.createDynamicQr({ txid, amountCents, ttlSeconds });
|
|
20
|
+
await db.charges.update(txid, { status: 'waiting' });
|
|
21
|
+
return qr; // only now does the user see it
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Expiry: an expired QR is dead. Regenerate with a NEW txid — never reuse.
|
|
25
|
+
async function onExpiry(txid) {
|
|
26
|
+
const status = await gateway.getCharge(txid); // poll: the webhook may have been lost
|
|
27
|
+
if (status.paid) return applyPaidTransition(txid, status);
|
|
28
|
+
await db.charges.update(txid, { status: 'expired' });
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Idempotent webhook handler (wrong vs right)
|
|
33
|
+
|
|
34
|
+
```javascript
|
|
35
|
+
// ❌ WRONG: credits on receipt — the provider's retry storm double-credits
|
|
36
|
+
app.post('/webhooks/pix', async (req, res) => {
|
|
37
|
+
const event = req.body;
|
|
38
|
+
await ledger.credit(event.txid, event.amountCents); // DANGER
|
|
39
|
+
res.sendStatus(200);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// ✅ RIGHT: raw-body signature check, then unique event id + ledger credit
|
|
43
|
+
// in the SAME transaction — the duplicate insert aborts the credit.
|
|
44
|
+
app.post('/webhooks/pix', rawBodyParser, async (req, res) => {
|
|
45
|
+
if (!verifyProviderSignature(req.rawBody, req.headers)) {
|
|
46
|
+
alert('pix.webhook.bad_signature');
|
|
47
|
+
return res.sendStatus(401); // reject unsigned/invalid BEFORE parsing
|
|
48
|
+
}
|
|
49
|
+
const event = JSON.parse(req.rawBody);
|
|
50
|
+
res.sendStatus(200); // ack fast; heavy work is async
|
|
51
|
+
await queue.enqueue('pix-event', event);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
async function processPixEvent(event) {
|
|
55
|
+
await db.transaction(async (trx) => {
|
|
56
|
+
// UNIQUE(provider, event_id) — second delivery throws, credit never runs
|
|
57
|
+
await trx.webhookEvents.insert({
|
|
58
|
+
provider: 'pix',
|
|
59
|
+
event_id: event.id,
|
|
60
|
+
end_to_end_id: event.endToEndId,
|
|
61
|
+
txid: event.txid,
|
|
62
|
+
});
|
|
63
|
+
await applyTransition(trx, event.txid, 'confirmed'); // state machine, not a bare update
|
|
64
|
+
await trx.ledger.credit(event.txid, event.amountCents);
|
|
65
|
+
}).catch((e) => {
|
|
66
|
+
if (isUniqueViolation(e)) return; // duplicate delivery: already processed
|
|
67
|
+
throw e;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Devolução (Pix refund)
|
|
73
|
+
|
|
74
|
+
```javascript
|
|
75
|
+
// Devolução references the ORIGINAL endToEndId and is itself asynchronous:
|
|
76
|
+
// requesting it is not completing it — completion arrives by webhook,
|
|
77
|
+
// under the same unique-event idempotency rules as payment.
|
|
78
|
+
async function requestDevolucao({ endToEndId, amountCents }) {
|
|
79
|
+
const refundId = generateRefundId();
|
|
80
|
+
await db.refunds.insert({
|
|
81
|
+
refund_id: refundId,
|
|
82
|
+
end_to_end_id: endToEndId,
|
|
83
|
+
amount_cents: amountCents, // partial or full; validate ceiling first
|
|
84
|
+
status: 'requested',
|
|
85
|
+
});
|
|
86
|
+
await gateway.requestDevolucao({ endToEndId, refundId, amountCents });
|
|
87
|
+
// status becomes 'completed' only when the devolução webhook confirms
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Boleto settlement accounting
|
|
92
|
+
|
|
93
|
+
```javascript
|
|
94
|
+
// ❌ WRONG: treating the "paid" event as money in the account
|
|
95
|
+
if (event.type === 'boleto.paid') await releaseGoods(event.chargeId);
|
|
96
|
+
|
|
97
|
+
// ✅ RIGHT: "paid" and "settled" are different states, days apart (D+1..D+3).
|
|
98
|
+
// Model the float explicitly; release goods on settlement.
|
|
99
|
+
switch (event.type) {
|
|
100
|
+
case 'boleto.registered': // a boleto exists only after bank registration
|
|
101
|
+
await applyTransition(db, event.chargeId, 'waiting');
|
|
102
|
+
break;
|
|
103
|
+
case 'boleto.paid': // bank confirmed payment — money not yet available
|
|
104
|
+
await applyTransition(db, event.chargeId, 'confirmed');
|
|
105
|
+
await accounting.recordReceivable(event.chargeId, event.amountCents);
|
|
106
|
+
break;
|
|
107
|
+
case 'boleto.settled': // funds available — NOW fulfill
|
|
108
|
+
await applyTransition(db, event.chargeId, 'settled');
|
|
109
|
+
await accounting.settleReceivable(event.chargeId);
|
|
110
|
+
await releaseGoods(event.chargeId);
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Boleto has no native refund rail: refunds are manual transfers, each with an audit-trail record linking operator, charge, amount, and destination account.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Reference: content-platform patterns (read on demand)
|
|
2
|
+
|
|
3
|
+
Exemplar for `domain/plataforma-conteudo` — versioned content model, slug-redirect flow, editor-JSON storage, and queued CDN invalidation. Evicted from the standing fragment; read when implementing one of these mechanisms.
|
|
4
|
+
|
|
5
|
+
## Versioned content model
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
Post
|
|
9
|
+
├── id (uuid)
|
|
10
|
+
├── slug (unique, indexed)
|
|
11
|
+
├── status (draft | review | scheduled | published | archived)
|
|
12
|
+
├── published_at (nullable)
|
|
13
|
+
├── scheduled_at (nullable)
|
|
14
|
+
├── current_version_id (fk → PostVersion)
|
|
15
|
+
└── PostVersions (immutable history)
|
|
16
|
+
├── title, excerpt, content_json, meta_title, meta_description, canonical_url
|
|
17
|
+
├── featured_image_id (asset reference, not URL)
|
|
18
|
+
└── created_at, created_by
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
- Publish: create a `PostVersion` snapshot → update `current_version_id` → queue CDN invalidation → reindex search.
|
|
22
|
+
- Rollback: repoint `current_version_id` to an earlier version → queue CDN invalidation. Never edit a published version.
|
|
23
|
+
- Scheduled: a queued job fires at `scheduled_at`, re-checks the post is still `scheduled` (it may have been cancelled), then runs the same publish flow.
|
|
24
|
+
|
|
25
|
+
## Slug change on a published post (wrong vs right)
|
|
26
|
+
|
|
27
|
+
```javascript
|
|
28
|
+
// ❌ WRONG: every indexed/externally linked URL now 404s
|
|
29
|
+
await post.update({ slug: newSlug });
|
|
30
|
+
|
|
31
|
+
// ✅ RIGHT: create the 301 redirect first, then invalidate BOTH urls
|
|
32
|
+
await SlugRedirect.create({ from: post.slug, to: newSlug, postId: post.id });
|
|
33
|
+
await post.update({ slug: newSlug });
|
|
34
|
+
await queue.add('cdn-invalidate', { paths: [`/${oldSlug}`, `/${newSlug}`] });
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Slug generation on create: lowercase, strip special characters, hyphenate, then check for collisions before saving. Slugs are freely editable only before first publication.
|
|
38
|
+
|
|
39
|
+
## Rich-text storage (wrong vs right)
|
|
40
|
+
|
|
41
|
+
```sql
|
|
42
|
+
-- ❌ WRONG: raw HTML blocks future editor migration and is an XSS bomb
|
|
43
|
+
UPDATE posts SET content = '<h1>Title</h1><p>Body with <script>evil()</script></p>';
|
|
44
|
+
|
|
45
|
+
-- ✅ RIGHT: the editor's native JSON document
|
|
46
|
+
UPDATE posts SET content_json = '{"type":"doc","content":[{"type":"heading","content":[...]}]}';
|
|
47
|
+
-- HTML is generated server-side at render time, with sanitization —
|
|
48
|
+
-- editor JSON can still carry malicious links/attributes.
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Assets embedded in content are referenced by asset ID and resolved at render time — never by direct URL, so storage moves and CDN changes don't rewrite content.
|
|
52
|
+
|
|
53
|
+
## CDN invalidation (wrong vs right)
|
|
54
|
+
|
|
55
|
+
```javascript
|
|
56
|
+
// ❌ WRONG: the publish request hangs on the CDN provider
|
|
57
|
+
await post.publish();
|
|
58
|
+
await cdn.createInvalidation({ paths: ['/*'] }); // blocks the response; '/*' also nukes the whole cache
|
|
59
|
+
|
|
60
|
+
// ✅ RIGHT: queue targeted paths, respond immediately
|
|
61
|
+
await post.publish();
|
|
62
|
+
await queue.add('cdn-invalidate', {
|
|
63
|
+
paths: [`/${post.slug}`, '/', '/sitemap.xml', '/feed.xml'],
|
|
64
|
+
});
|
|
65
|
+
res.json({ ok: true });
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Unpublish invalidates the same paths. Use wildcards only as a deliberate last resort — a full-cache invalidation is slow and expensive.
|
|
69
|
+
|
|
70
|
+
## SEO checklist per published post
|
|
71
|
+
|
|
72
|
+
- `meta_title` (~60 chars max), `meta_description` (~160 chars max), `canonical_url` (defaults to the post's own canonical URL — never blank).
|
|
73
|
+
- Open Graph fields (`og:title`, `og:description`, `og:image`) are separate from the SEO meta tags.
|
|
74
|
+
- Sitemap: only published posts with `noindex: false`, `lastmod` = `published_at`; serve generated-on-demand or cached with a short TTL.
|