@vesviet/agent-skills 5.8.0 → 5.11.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/INDEX.md +35 -22
- package/README.md +7 -18
- package/VERSION +1 -1
- package/adapters/antigravity/ANTIGRAVITY.md +40 -142
- package/adapters/antigravity/INDEX_TIER1.json +174 -146
- package/adapters/antigravity/a2a-config.template.yaml +1 -1
- package/adapters/antigravity/antigravity-tools.md +25 -0
- package/adapters/antigravity/role-skill-index.json +175 -58
- package/adapters/claude/CLAUDE_ADAPTER.md +3 -7
- package/adapters/claude/settings.template.json +18 -3
- package/adapters/cursor/README.md +1 -5
- package/adapters/cursor/hooks.template.json +4 -2
- package/core/contracts/README.md +0 -20
- package/core/contracts/schemas/compact-working-state.json +42 -1
- package/core/contracts/schemas/ui-component-spec.json +28 -2
- package/core/policies/README.md +0 -20
- package/core/policies/action-boundaries.yaml +10 -1
- package/core/policies/execution-sandbox.md +0 -12
- package/core/policies/mcp-tool-map.yaml +28 -0
- package/core/roles/3d-graphics-engineer.md +144 -208
- package/core/roles/README.md +1 -23
- package/core/roles/agent-coordinator.md +28 -147
- package/core/roles/agent-discovery-engineer.md +46 -39
- package/core/roles/ai-systems-engineer.md +2 -0
- package/core/roles/backend-developer.md +22 -117
- package/core/roles/cloudflare-engineer.md +1 -1
- package/core/roles/data-engineer.md +3 -1
- package/core/roles/devops-engineer.md +4 -3
- package/core/roles/ecommerce-engineer.md +18 -6
- package/core/roles/frontend-developer.md +146 -317
- package/core/roles/game-developer.md +2 -1
- package/core/roles/mobile-engineer.md +18 -204
- package/core/roles/product-manager.md +3 -3
- package/core/roles/project-manager.md +5 -5
- package/core/roles/references/3d-graphics-engineer-review-checklist.md +109 -109
- package/core/roles/references/agent-coordinator-responsibilities.md +120 -0
- package/core/roles/references/agent-coordinator-review-checklist.md +22 -4
- package/core/roles/references/agent-discovery-engineer-review-checklist.md +29 -20
- package/core/roles/references/backend-developer-responsibilities.md +47 -0
- package/core/roles/references/backend-developer-review-checklist.md +15 -0
- package/core/roles/references/business-analyst-responsibilities.md +2 -2
- package/core/roles/references/frontend-developer-responsibilities.md +14 -6
- package/core/roles/references/frontend-developer-review-checklist.md +13 -6
- package/core/roles/references/mobile-engineer-responsibilities.md +137 -0
- package/core/roles/references/mobile-engineer-review-checklist.md +63 -0
- package/core/roles/references/reviewer-review-checklist.md +54 -0
- package/core/roles/references/sdet-review-checklist.md +53 -0
- package/core/roles/references/solution-architect-responsibilities.md +134 -0
- package/core/roles/references/sre-review-checklist.md +81 -0
- package/core/roles/references/system-engineer-responsibilities.md +124 -0
- package/core/roles/references/technical-architect-responsibilities.md +192 -0
- package/core/roles/references/technical-architect-review-checklist.md +58 -0
- package/core/roles/references/technical-lead-review-checklist.md +65 -0
- package/core/roles/references/ui-ux-designer-anti-slop-standards.md +61 -35
- package/core/roles/references/ui-ux-designer-responsibilities.md +79 -226
- package/core/roles/references/ui-ux-designer-review-checklist.md +102 -116
- package/core/roles/references/vietnam-accounting-specialist-review-checklist.md +6 -6
- package/core/roles/researcher.md +3 -3
- package/core/roles/reviewer.md +2 -2
- package/core/roles/role-standard.md +79 -205
- package/core/roles/sdet.md +5 -6
- package/core/roles/security-engineer.md +4 -3
- package/core/roles/solution-architect.md +9 -130
- package/core/roles/sre.md +1 -0
- package/core/roles/system-engineer.md +15 -155
- package/core/roles/task-planner.md +1 -1
- package/core/roles/technical-architect.md +15 -244
- package/core/roles/technical-lead.md +1 -0
- package/core/roles/technical-writer.md +3 -3
- package/core/roles/ui-ux-designer.md +158 -303
- package/core/roles/vietnam-accounting-specialist.md +20 -20
- package/core/rules/README.md +0 -22
- package/core/rules/code.md +11 -6
- package/core/skills/README.md +12 -25
- package/core/skills/agent/agent-delegation/SKILL.md +11 -0
- package/core/skills/agent/agent-graph-orchestration/SKILL.md +5 -0
- package/core/skills/agent/agent-memory-compaction/SKILL.md +79 -82
- package/core/skills/agent/agent-memory-compaction/references/anchored-schema-and-compaction-algorithms.md +74 -115
- package/core/skills/agent/agent-model-routing/SKILL.md +2 -0
- package/core/skills/agent/agent-observability/SKILL.md +12 -6
- package/core/skills/agent/agent-observability/references/session-forensics-7-dimensions.md +41 -0
- package/core/skills/agent/agent-panel-meeting/SKILL.md +3 -3
- package/core/skills/agent/agent-quality-gate/SKILL.md +9 -0
- package/core/skills/agent/configure-agent-commerce/SKILL.md +2 -0
- package/core/skills/agent/configure-agent-commerce/examples/ucp-commerce-manifest-and-endpoints.json +55 -0
- package/core/skills/agent/configure-agent-commerce/references/acp-ucp-agent-commerce-manifest-specs.md +66 -0
- package/core/skills/agent/configure-agent-headers/SKILL.md +3 -0
- package/core/skills/agent/configure-agent-skills/SKILL.md +4 -4
- package/core/skills/agent/configure-oauth-metadata/SKILL.md +10 -7
- package/core/skills/agent/manage-agent-identity/SKILL.md +2 -0
- package/core/skills/agent/manage-agent-identity/examples/agent-identity-spire-workload.yaml +72 -0
- package/core/skills/agent/manage-agent-identity/references/nhi-lifecycle-and-token-rotation.md +45 -0
- package/core/skills/ai/deploy-vllm-inference/SKILL.md +2 -0
- package/core/skills/ai/deploy-vllm-inference/examples/vllm-production-serve-config.yaml +22 -0
- package/core/skills/ai/deploy-vllm-inference/references/vllm-v1-paged-attention-and-kv-tiering.md +20 -0
- package/core/skills/ai/openrouter-task/SKILL.md +5 -5
- package/core/skills/ai-agent/context-optimization/SKILL.md +2 -0
- package/core/skills/ai-agent/context-optimization/examples/context-pruner-and-reorderer.py +85 -0
- package/core/skills/ai-agent/context-optimization/references/token-budgeting-and-attention-allocation.md +47 -0
- package/core/skills/ai-agent/memory-hygiene/SKILL.md +13 -0
- package/core/skills/ai-agent/memory-hygiene/examples/memory-audit-and-compaction-routine.py +90 -0
- package/core/skills/ai-agent/memory-hygiene/references/agent-memory-vault-spec.md +137 -0
- package/core/skills/ai-agent/memory-hygiene/references/owasp-asi06-and-memory-poisoning-defense.md +38 -0
- package/core/skills/backend/add-api-endpoint/SKILL.md +9 -0
- package/core/skills/backend/add-api-endpoint/examples/express-zod-rfc9457-endpoint.md +329 -0
- package/core/skills/backend/add-api-endpoint/examples/kratos-go-clean-architecture-endpoint.md +405 -0
- package/core/skills/backend/add-api-endpoint/references/idempotency-and-rate-limiting.md +116 -0
- package/core/skills/backend/add-event-handler/SKILL.md +12 -1
- package/core/skills/backend/add-event-handler/examples/go-outbox-skip-locked-relay.go +97 -0
- package/core/skills/backend/add-event-handler/references/transactional-outbox-and-cloudevents.md +42 -0
- package/core/skills/backend/add-service-client/SKILL.md +2 -0
- package/core/skills/backend/add-service-client/examples/ts-circuit-breaker-full-jitter-client.ts +71 -0
- package/core/skills/backend/add-service-client/references/resilient-client-circuit-breaker-specs.md +25 -0
- package/core/skills/backend/build-mcp-server/SKILL.md +2 -0
- package/core/skills/backend/build-mcp-server/examples/ts-stateless-mcp-server-zod.ts +52 -0
- package/core/skills/backend/build-mcp-server/references/mcp-2026-stateless-contract-specs.md +21 -0
- package/core/skills/backend/design-caching-and-locking/SKILL.md +83 -0
- package/core/skills/backend/design-caching-and-locking/examples/redis-lua-atomic-reservation-fencing.lua +30 -0
- package/core/skills/backend/design-caching-and-locking/references/redis-lua-fencing-and-stampede-specs.md +25 -0
- package/core/skills/backend/design-caching-and-locking/scripts/verify_lua_atomicity.py +68 -0
- package/core/skills/backend/implement-auth/SKILL.md +9 -0
- package/core/skills/backend/implement-structured-outputs/SKILL.md +2 -0
- package/core/skills/backend/implement-structured-outputs/examples/python-pydantic-structured-output.py +65 -0
- package/core/skills/backend/implement-structured-outputs/references/constrained-decoding-and-double-validation.md +18 -0
- package/core/skills/backend/optimize-postgres/SKILL.md +9 -0
- package/core/skills/backend/scaffold-new-service/SKILL.md +2 -1
- package/core/skills/backend/scaffold-new-service/references/deep-modules-and-seams.md +43 -0
- package/core/skills/business/elicit-requirements/SKILL.md +2 -0
- package/core/skills/business/trace-requirements-impact/SKILL.md +1 -0
- package/core/skills/business/write-use-cases/SKILL.md +1 -0
- package/core/skills/commerce/handle-checkout-flow/SKILL.md +18 -66
- package/core/skills/commerce/handle-checkout-flow/examples/production-checkout-orchestrator.ts +185 -0
- package/core/skills/commerce/handle-checkout-flow/references/pci-dss-v4-and-agentic-checkout-specs.md +72 -0
- package/core/skills/commerce/integrate-payment-gateway/SKILL.md +22 -58
- package/core/skills/commerce/integrate-payment-gateway/examples/resilient-webhook-and-mpp-handler.ts +164 -0
- package/core/skills/commerce/integrate-payment-gateway/references/mpp-x402-and-webhook-security-specs.md +47 -0
- package/core/skills/commerce/manage-order-fulfillment/SKILL.md +17 -50
- package/core/skills/commerce/manage-order-fulfillment/examples/temporal-fulfillment-saga.ts +104 -0
- package/core/skills/commerce/manage-order-fulfillment/references/event-sourced-fulfillment-and-carrier-webhooks.md +58 -0
- package/core/skills/commerce/manage-product-catalog/SKILL.md +5 -1
- package/core/skills/commerce/manage-product-catalog/examples/hybrid-search-and-governance-pipeline.ts +120 -0
- package/core/skills/commerce/manage-product-catalog/references/semantic-vector-catalog-and-graphrag.md +54 -0
- package/core/skills/content/write-article/SKILL.md +1 -1
- package/core/skills/document/docx/SKILL.md +1 -0
- package/core/skills/document/pdf/SKILL.md +2 -0
- package/core/skills/document/pdf/references/pdf-acroforms-and-pdfplumber-specs.md +54 -0
- package/core/skills/document/pdf/scripts/check_fillable_fields.py +144 -0
- package/core/skills/document/pdf/scripts/fill_fillable_fields.py +145 -0
- package/core/skills/document/xlsx/SKILL.md +1 -0
- package/core/skills/documentation/configure-llms-txt/SKILL.md +3 -0
- package/core/skills/documentation/configure-llms-txt/examples/canonical-llms-txt-and-full-txt.md +45 -0
- package/core/skills/documentation/configure-llms-txt/references/llms-txt-and-llms-full-txt-standard.md +37 -0
- package/core/skills/documentation/write-documentation/SKILL.md +4 -1
- package/core/skills/documentation/write-documentation/examples/microservice-production-readme-and-api-docs.md +70 -0
- package/core/skills/documentation/write-documentation/references/diataxis-framework-and-doc-standards.md +62 -0
- package/core/skills/documentation/write-tech-radar/SKILL.md +1 -0
- package/core/skills/education/create-exercises/SKILL.md +1 -0
- package/core/skills/education/design-learning-plan/SKILL.md +1 -0
- package/core/skills/education/grade-and-review/SKILL.md +1 -0
- package/core/skills/foundation/accessibility-review/SKILL.md +1 -0
- package/core/skills/foundation/ai-risk-assessment/SKILL.md +4 -5
- package/core/skills/foundation/ai-risk-assessment/examples/genai-system-risk-register.md +67 -0
- package/core/skills/foundation/ai-risk-assessment/references/nist-ai-rmf-and-eu-ai-act-taxonomy.md +49 -0
- package/core/skills/foundation/combinatorial-testing/SKILL.md +1 -0
- package/core/skills/foundation/conduct-research/SKILL.md +2 -2
- package/core/skills/foundation/conduct-research/references/ai-era-source-discipline.md +1 -1
- package/core/skills/foundation/create-migration/SKILL.md +10 -0
- package/core/skills/foundation/design-review/SKILL.md +9 -10
- package/core/skills/foundation/design-ux-flow/SKILL.md +9 -7
- package/core/skills/foundation/discernment-nudge/SKILL.md +2 -0
- package/core/skills/foundation/hostile-component-stress-testing/SKILL.md +1 -0
- package/core/skills/foundation/incident-report/SKILL.md +1 -0
- package/core/skills/foundation/plan-technical-delivery/SKILL.md +3 -1
- package/core/skills/foundation/playwright-evidence-qa/SKILL.md +1 -0
- package/core/skills/foundation/refactor-legacy-code/SKILL.md +84 -0
- package/core/skills/foundation/refactor-legacy-code/examples/characterization-test-seam-extraction.py +34 -0
- package/core/skills/foundation/refactor-legacy-code/references/strangler-fig-seams-and-characterization-tests.md +17 -0
- package/core/skills/foundation/refactor-legacy-code/scripts/check_refactor_blast_radius.py +63 -0
- package/core/skills/foundation/release-notes/SKILL.md +3 -3
- package/core/skills/foundation/release-notes/examples/enterprise-platform-release-notes.md +42 -0
- package/core/skills/foundation/release-notes/references/keep-a-changelog-and-semver-governance.md +43 -0
- package/core/skills/foundation/systematic-debugging/SKILL.md +15 -0
- package/core/skills/foundation/webapp-server-runner/SKILL.md +1 -0
- package/core/skills/foundation/write-product-brief/SKILL.md +1 -0
- package/core/skills/foundation/write-tests/SKILL.md +9 -0
- package/core/skills/foundation/write-tests/examples/anti-tautological-tdd-walkthrough.md +204 -0
- package/core/skills/foundation/write-tests/examples/testcontainers-kratos-integration-test.md +186 -0
- package/core/skills/foundation/write-tests/references/contract-and-chaos-testing.md +187 -0
- package/core/skills/frontend/INDEX.json +16 -0
- package/core/skills/frontend/add-page-route/SKILL.md +10 -8
- package/core/skills/frontend/add-page-route/examples/streaming-rsc-page-with-view-transition.tsx +133 -0
- package/core/skills/frontend/add-page-route/references/rsc-routing-and-view-transitions.md +72 -0
- package/core/skills/frontend/add-ui-component/SKILL.md +4 -1
- package/core/skills/frontend/add-ui-component/examples/compound-dialog-and-form-actions.tsx +193 -0
- package/core/skills/frontend/add-ui-component/references/react19-component-standards-and-anti-slop.md +55 -0
- package/core/skills/frontend/component-composition/SKILL.md +12 -1
- package/core/skills/frontend/component-composition/examples/headless-combobox-compound-component.tsx +207 -0
- package/core/skills/frontend/design-md-specification/SKILL.md +5 -0
- package/core/skills/frontend/design-system-engineering/SKILL.md +4 -2
- package/core/skills/frontend/frontend-micro-polish/SKILL.md +1 -0
- package/core/skills/frontend/frontend-testing/SKILL.md +4 -1
- package/core/skills/frontend/frontend-testing/examples/playwright-e2e-with-msw-and-axe.spec.ts +87 -0
- package/core/skills/frontend/frontend-testing/references/playwright-msw-and-a11y-testing-standards.md +78 -0
- package/core/skills/frontend/implement-ai-disclosure/SKILL.md +119 -0
- package/core/skills/frontend/implement-view-transitions/SKILL.md +1 -0
- package/core/skills/frontend/implement-webmcp/SKILL.md +7 -4
- package/core/skills/frontend/implement-webmcp/examples/webmcp-provider-and-hitl-modal.tsx +163 -0
- package/core/skills/frontend/implement-webmcp/references/webmcp-architecture-and-hitl-security.md +48 -0
- package/core/skills/frontend/integrate-api-client/SKILL.md +12 -12
- package/core/skills/frontend/integrate-api-client/examples/orval-query-and-streaming-mutation.ts +102 -0
- package/core/skills/frontend/integrate-api-client/references/orval-tanstack-query-and-streaming-specs.md +57 -0
- package/core/skills/frontend/interactive-component-workbench/SKILL.md +1 -0
- package/core/skills/frontend/motion-performance-engineering/SKILL.md +1 -0
- package/core/skills/frontend/setup-design-system/SKILL.md +6 -3
- package/core/skills/frontend/setup-design-system/examples/tailwind-v4-theme-and-dtcg-tokens.css +87 -0
- package/core/skills/frontend/setup-design-system/references/tailwind-v4-oklch-and-dtcg-tokens.md +61 -0
- package/core/skills/frontend/setup-visual-regression/SKILL.md +8 -5
- package/core/skills/frontend/setup-visual-regression/examples/visual-regression-playwright.config.ts +83 -0
- package/core/skills/frontend/setup-visual-regression/references/visual-regression-docker-and-masking-specs.md +46 -0
- package/core/skills/frontend/ui-ux-designer-anti-slop-standards.md +64 -42
- package/core/skills/frontend/web-quality-audit/SKILL.md +1 -0
- package/core/skills/gamedev/abstract-input-actions/SKILL.md +2 -0
- package/core/skills/gamedev/abstract-input-actions/examples/input-action-manager.ts +85 -0
- package/core/skills/gamedev/abstract-input-actions/references/action-mapping-and-analog-deadzones.md +54 -0
- package/core/skills/gamedev/architect-ecs-systems/SKILL.md +2 -0
- package/core/skills/gamedev/architect-ecs-systems/examples/bevy-flecs-combat-system.rs +73 -0
- package/core/skills/gamedev/architect-ecs-systems/references/data-oriented-design-and-archetype-ecs.md +39 -0
- package/core/skills/gamedev/author-game-ai/SKILL.md +2 -0
- package/core/skills/gamedev/author-game-ai/examples/modular-behavior-tree-ai.ts +98 -0
- package/core/skills/gamedev/author-game-ai/references/behavior-trees-and-utility-ai-curves.md +47 -0
- package/core/skills/gamedev/configure-physics-collision/SKILL.md +2 -0
- package/core/skills/gamedev/configure-physics-collision/examples/kinematic-physics-substepping.cpp +100 -0
- package/core/skills/gamedev/configure-physics-collision/references/continuous-collision-detection-and-substepping.md +50 -0
- package/core/skills/gamedev/develop-gameplay-systems/SKILL.md +2 -0
- package/core/skills/gamedev/develop-gameplay-systems/examples/kinematic-character-controller.gd +86 -0
- package/core/skills/gamedev/develop-gameplay-systems/references/deterministic-gameplay-state-machines.md +42 -0
- package/core/skills/gamedev/implement-save-persistence/SKILL.md +2 -0
- package/core/skills/gamedev/implement-save-persistence/examples/versioned-save-manager.ts +127 -0
- package/core/skills/gamedev/implement-save-persistence/references/versioned-save-schemas-and-checksums.md +44 -0
- package/core/skills/gamedev/render-webgl-threejs/SKILL.md +14 -10
- package/core/skills/gamedev/render-webgl-threejs/examples/production-threejs-webgpu-scene.ts +116 -0
- package/core/skills/gamedev/render-webgl-threejs/references/webgpu-threejs-pbr-pipeline.md +72 -0
- package/core/skills/legal-compliance/audit-ai-compliance/SKILL.md +1 -0
- package/core/skills/legal-compliance/draft-legal-opinion/SKILL.md +1 -0
- package/core/skills/legal-compliance/manage-vietnam-legal/SKILL.md +1 -0
- package/core/skills/meetings-analysis/analyze-business-requirements/SKILL.md +1 -0
- package/core/skills/meetings-analysis/analyze-data/SKILL.md +1 -0
- package/core/skills/meetings-analysis/meeting-review/SKILL.md +1 -0
- package/core/skills/mmo/analyze-campaign-roi/SKILL.md +2 -0
- package/core/skills/mmo/analyze-campaign-roi/examples/campaign-roi-and-roas-dashboard.py +80 -0
- package/core/skills/mmo/analyze-campaign-roi/references/multi-touch-attribution-and-cpa-analytics.md +33 -0
- package/core/skills/mmo/create-automation-script/SKILL.md +2 -0
- package/core/skills/mmo/create-automation-script/examples/stealth-browser-automation-flow.ts +65 -0
- package/core/skills/mmo/create-automation-script/references/stealth-cdp-and-behavioral-mimicry.md +37 -0
- package/core/skills/mmo/deploy-mmo-infrastructure/SKILL.md +3 -0
- package/core/skills/mmo/deploy-mmo-infrastructure/examples/proxy-health-probe-and-rotation-daemon.py +75 -0
- package/core/skills/mmo/deploy-mmo-infrastructure/references/proxy-pool-rotation-and-anti-detect-specs.md +45 -0
- package/core/skills/mmo/deploy-proxyware-fleet/SKILL.md +3 -0
- package/core/skills/mmo/deploy-proxyware-fleet/examples/docker-compose-depin-light-node-fleet.yaml +52 -0
- package/core/skills/mmo/deploy-proxyware-fleet/references/depin-bandwidth-monetization-node-specs.md +43 -0
- package/core/skills/mmo/generate-mmo-content/SKILL.md +2 -0
- package/core/skills/mmo/generate-mmo-content/examples/pseo-programmatic-page-generator.ts +76 -0
- package/core/skills/mmo/generate-mmo-content/references/pseo-landing-pages-and-social-video-hooks.md +39 -0
- package/core/skills/mmo/manage-mmo-assets/SKILL.md +2 -0
- package/core/skills/mmo/manage-mmo-assets/examples/mmo-asset-vault-manager.py +63 -0
- package/core/skills/mmo/manage-mmo-assets/references/mmo-asset-rbac-and-vault-isolation.md +38 -0
- package/core/skills/mmo/setup-tracking-system/SKILL.md +2 -0
- package/core/skills/mmo/setup-tracking-system/examples/meta-capi-s2s-event-dispatcher.ts +79 -0
- package/core/skills/mmo/setup-tracking-system/references/server-to-server-postback-and-capi-specs.md +45 -0
- package/core/skills/mobile/deploy-mobile-app/SKILL.md +1 -0
- package/core/skills/mobile/develop-mobile-app/SKILL.md +1 -0
- package/core/skills/platform/add-telemetry-instrumentation/SKILL.md +2 -0
- package/core/skills/platform/add-telemetry-instrumentation/examples/kratos-otel-middleware-instrumentation.go +87 -0
- package/core/skills/platform/add-telemetry-instrumentation/references/opentelemetry-semantic-conventions-2026.md +37 -0
- package/core/skills/platform/agents-sdk/SKILL.md +1 -0
- package/core/skills/platform/aws-infrastructure/SKILL.md +2 -0
- package/core/skills/platform/aws-infrastructure/examples/opentofu-eks-pod-identity-vpc.tf +101 -0
- package/core/skills/platform/aws-infrastructure/references/opentofu-aws-zero-trust-and-irsa.md +40 -0
- package/core/skills/platform/cloudflare-email-service/SKILL.md +2 -2
- package/core/skills/platform/configure-ci-cd-pipeline/SKILL.md +83 -0
- package/core/skills/platform/configure-ci-cd-pipeline/examples/hardened-ci-matrix-workflow.yml +33 -0
- package/core/skills/platform/configure-ci-cd-pipeline/references/github-actions-sha-pinning-and-slsa-specs.md +22 -0
- package/core/skills/platform/configure-ci-cd-pipeline/scripts/audit_workflow_pinning.py +74 -0
- package/core/skills/platform/debug-runtime-platform/SKILL.md +1 -2
- package/core/skills/platform/debug-workers-edge/SKILL.md +2 -2
- package/core/skills/platform/durable-objects/SKILL.md +1 -0
- package/core/skills/platform/orchestrate-chaos-experiment/SKILL.md +1 -0
- package/core/skills/platform/sandbox-sdk/SKILL.md +1 -0
- package/core/skills/platform/setup-deployment/SKILL.md +6 -2
- package/core/skills/platform/setup-deployment/examples/kustomize-production-service-manifests.yaml +123 -0
- package/core/skills/platform/setup-deployment/references/interactive-hitl-wizard.md +55 -0
- package/core/skills/platform/setup-deployment/references/k8s-gitops-and-kustomize-invariants.md +40 -0
- package/core/skills/platform/setup-gpu-finops/SKILL.md +2 -0
- package/core/skills/platform/setup-gpu-finops/examples/gpu-finops-prometheus-rules.yaml +23 -0
- package/core/skills/platform/setup-gpu-finops/references/dcgm-kubecost-gpu-attribution-specs.md +16 -0
- package/core/skills/platform/setup-llm-gateway/SKILL.md +2 -0
- package/core/skills/platform/setup-llm-gateway/examples/litellm-gateway-config.yaml +28 -0
- package/core/skills/platform/setup-llm-gateway/references/litellm-routing-budget-failover-specs.md +16 -0
- package/core/skills/platform/supply-chain-security/SKILL.md +3 -2
- package/core/skills/platform/supply-chain-security/examples/github-actions-sbom-cosign.yaml +57 -0
- package/core/skills/platform/supply-chain-security/references/slsa-provenance-and-sbom-sigstore.md +60 -0
- package/core/skills/platform/turnstile-spin/SKILL.md +2 -2
- package/core/skills/platform/web-perf/SKILL.md +2 -2
- package/core/skills/platform/workers-best-practices/SKILL.md +1 -0
- package/core/skills/platform/wrangler/SKILL.md +1 -0
- package/core/skills/product/build-story-map/SKILL.md +3 -0
- package/core/skills/product/define-product-strategy/SKILL.md +1 -0
- package/core/skills/product/model-saas-metrics/SKILL.md +1 -0
- package/core/skills/product/prioritize-roadmap/SKILL.md +1 -0
- package/core/skills/repo-ops/commit-code/SKILL.md +1 -0
- package/core/skills/repo-ops/navigate-service/SKILL.md +28 -132
- package/core/skills/repo-ops/navigate-service/examples/service-boundary-map-example.md +14 -0
- package/core/skills/repo-ops/navigate-service/references/service-topology-mapping-guide.md +18 -0
- package/core/skills/repo-ops/review-code/SKILL.md +12 -2
- package/core/skills/repo-ops/review-code/examples/adversarial-two-axis-pr-review.md +167 -0
- package/core/skills/repo-ops/review-code/examples/ai-vibe-slop-remediation.md +220 -0
- package/core/skills/repo-ops/review-code/references/supply-chain-and-migration-safety.md +103 -0
- package/core/skills/repo-ops/review-service/SKILL.md +4 -1
- package/core/skills/repo-ops/review-service/examples/service-release-audit-report.md +21 -0
- package/core/skills/repo-ops/review-service/references/release-readiness-audit-rubric.md +21 -0
- package/core/skills/repo-ops/troubleshoot-service/SKILL.md +1 -0
- package/core/skills/security-data/database-maintenance/SKILL.md +1 -1
- package/core/skills/security-data/manage-secrets/SKILL.md +2 -0
- package/core/skills/security-data/manage-secrets/examples/external-secrets-vault-crds.yaml +53 -0
- package/core/skills/security-data/manage-secrets/references/zero-trust-secret-rotation-and-eso.md +30 -0
- package/core/skills/security-data/manage-vietnam-accounting/SKILL.md +8 -7
- package/core/skills/security-data/prompt-injection-defense/SKILL.md +2 -0
- package/core/skills/security-data/prompt-injection-defense/examples/bounded-tool-execution-wrapper.py +78 -0
- package/core/skills/security-data/prompt-injection-defense/references/prompt-injection-taxonomy-and-delimiters.md +37 -0
- package/core/skills/security-data/reverse-engineer-binary/SKILL.md +3 -0
- package/core/skills/security-data/reverse-engineer-binary/examples/binary-triage-and-vulnerability-dossier.md +58 -0
- package/core/skills/security-data/reverse-engineer-binary/references/ghidra-radare2-and-rea-evidence-ledgers.md +43 -0
- package/core/skills/security-data/security-audit/SKILL.md +3 -1
- package/core/skills/security-data/security-audit/examples/enterprise-service-security-audit-report.md +54 -0
- package/core/skills/security-data/security-audit/references/owasp-asi-and-cvss4-threat-modeling.md +39 -0
- package/core/skills/security-data/skill-preflight-ast-check/SKILL.md +3 -0
- package/core/skills/security-data/skill-preflight-ast-check/references/ast-lethal-trifecta-and-static-vetting.md +38 -0
- package/core/skills/security-data/skill-preflight-ast-check/scripts/scan-skill-ast.py +127 -0
- package/core/skills/seo/audit-technical-seo/SKILL.md +1 -0
- package/core/skills/seo/implement-schema-markup/SKILL.md +1 -0
- package/core/workflows/README.md +0 -20
- package/overlays/README.md +2 -22
- package/overlays/astro-cloudflare/README.md +0 -20
- package/overlays/astro-cloudflare/rules/astro-cloudflare-conventions.md +0 -31
- package/overlays/b2b-catalog-golf/README.md +0 -20
- package/overlays/b2b-catalog-golf/rules/golf-project-rules.md +0 -31
- package/overlays/b2b-catalog-golf/skills/develop-b2b-golf-feature/SKILL.md +1 -0
- package/overlays/b2b-factory-catalog/README.md +0 -20
- package/overlays/b2b-factory-catalog/rules/icm-project-rules.md +0 -31
- package/overlays/b2b-factory-catalog/skills/develop-b2b-catalog-feature/SKILL.md +1 -0
- package/overlays/b2b-sport-catalog/README.md +0 -20
- package/overlays/b2b-sport-catalog/rules/sport-project-rules.md +0 -31
- package/overlays/cad-projection/README.md +0 -20
- package/overlays/cad-projection/rules/cad-conventions.md +0 -20
- package/overlays/cad-projection/skills/isometric-svg-projection/SKILL.md +1 -0
- package/overlays/data-analyst-stack/README.md +0 -20
- package/overlays/data-analyst-stack/rules/metric-dashboard-templates.md +0 -31
- package/overlays/data-analyst-stack/rules/stack-conventions.md +0 -31
- package/overlays/data-warehouse/README.md +0 -22
- package/overlays/data-warehouse/learning/learning-conventions.md +0 -31
- package/overlays/data-warehouse/learning/phase-roadmap.md +0 -31
- package/overlays/data-warehouse/rules/amis-accounting-standards.md +0 -33
- package/overlays/data-warehouse/rules/duckdb-concurrency.md +0 -37
- package/overlays/data-warehouse/rules/pii-scrubbing.md +0 -37
- package/overlays/data-warehouse/rules/stocktake-tolerance.md +0 -33
- package/overlays/ecommerce-microservices/README.md +22 -35
- package/overlays/ecommerce-microservices/config/README.md +3 -1
- package/overlays/ecommerce-microservices/rules/README.md +2 -1
- package/overlays/ecommerce-microservices/rules/microservices-conventions.md +30 -0
- package/overlays/ecommerce-microservices/skills/README.md +1 -1
- package/overlays/ecommerce-microservices/workflows/README.md +3 -1
- package/overlays/fintech-compliance/README.md +0 -20
- package/overlays/fintech-compliance/rules/credit-scorecard-rules.md +0 -20
- package/overlays/fintech-compliance/skills/build-credit-scorecard/SKILL.md +1 -0
- package/overlays/go-microservices/README.md +1 -21
- package/overlays/go-microservices/rules/go-conventions.md +0 -31
- package/overlays/hugo-authority-content/README.md +0 -20
- package/overlays/hugo-authority-content/roles/README.md +0 -20
- package/overlays/hugo-authority-content/rules/content-brand.md +0 -30
- package/overlays/hugo-authority-content/rules/link-topology.md +0 -30
- package/overlays/hugo-authority-content/rules/seo-authority.md +0 -30
- package/overlays/hugo-authority-content/rules/technical-article-2027.md +0 -30
- package/overlays/hugo-authority-content/skills/audit-technical-article/SKILL.md +1 -0
- package/overlays/hugo-authority-content/skills/write-hugo-twin-content/SKILL.md +1 -0
- package/overlays/hugo-authority-content/workflows/README.md +0 -20
- package/overlays/hvac-authority-content/README.md +0 -20
- package/overlays/hvac-authority-content/config/collections.md +0 -22
- package/overlays/hvac-authority-content/rules/content-schema.md +0 -30
- package/overlays/hvac-authority-content/rules/hvac-engineering-standards.md +0 -30
- package/overlays/hvac-authority-content/rules/silo-linking.md +0 -30
- package/overlays/hvac-authority-content/skills/write-hvac-authority-content/SKILL.md +1 -0
- package/overlays/hvac-authority-content/workflows/publish-hvac-content.md +0 -22
- package/overlays/laravel-ecommerce/README.md +0 -20
- package/overlays/laravel-ecommerce/rules/elomus-design-system.md +0 -31
- package/overlays/laravel-ecommerce/rules/laravel-ecommerce-rules.md +0 -31
- package/overlays/laravel-ecommerce/skills/develop-laravel-ecommerce-feature/SKILL.md +1 -0
- package/overlays/laravel-filament/README.md +0 -20
- package/overlays/laravel-filament/rules/laravel-conventions.md +0 -31
- package/overlays/laravel-filament/skills/develop-laravel-feature/SKILL.md +1 -0
- package/overlays/livestream-web/README.md +0 -20
- package/overlays/livestream-web/rules/livestream-web-ux-conventions.md +0 -31
- package/overlays/obj-configurator/README.md +0 -20
- package/overlays/obj-configurator/rules/obj-project-rules.md +0 -31
- package/overlays/obj-configurator/skills/develop-obj-feature/SKILL.md +1 -0
- package/overlays/r3f-stack/README.md +0 -20
- package/overlays/r3f-stack/rules/stub.md +0 -31
- package/overlays/r3f-stack/skills/debug-3d-scene/SKILL.md +4 -2
- package/overlays/r3f-stack/skills/integrate-r3f-three-legacy/SKILL.md +6 -5
- package/overlays/r3f-stack/skills/optimize-3d-assets/SKILL.md +4 -3
- package/overlays/real-estate-content/README.md +0 -20
- package/overlays/real-estate-content/roles/README.md +0 -20
- package/overlays/real-estate-content/rules/affiliate-links.md +0 -31
- package/overlays/real-estate-content/rules/content-schema.md +0 -31
- package/overlays/real-estate-content/rules/seo-baseline.md +0 -31
- package/overlays/real-estate-content/skills/write-real-estate-astro-data/SKILL.md +1 -0
- package/overlays/real-estate-content/workflows/README.md +0 -20
- package/overlays/security-research/README.md +0 -20
- package/overlays/security-research/rules/reverse-engineering-rules.md +0 -20
- package/overlays/seo-publishing/README.md +1 -21
- package/overlays/seo-publishing/rules/publish-log-conventions.md +0 -31
- package/overlays/seo-publishing/rules/publishing-cadence.md +0 -31
- package/overlays/seo-publishing/rules/site-mix-and-cannibalization.md +0 -31
- package/overlays/seo-publishing/rules/topic-board-template.md +0 -31
- package/overlays/ui-design-system/README.md +0 -20
- package/overlays/ui-design-system/rules/handoff-conventions.md +0 -31
- package/package.json +2 -2
- package/packs/README.md +3 -9
- package/packs/ecommerce-team/manifest.yaml +1 -1
- package/core/skills/commerce/2026_STANDARDS_SUMMARY.md +0 -316
- package/core/skills/commerce/handle-checkout-flow/UPGRADE_PLAN_2026.md +0 -99
- package/core/skills/commerce/integrate-payment-gateway/UPGRADE_PLAN_2026.md +0 -128
- package/core/skills/commerce/manage-order-fulfillment/UPGRADE_PLAN_2026.md +0 -136
- package/core/skills/commerce/manage-product-catalog/UPGRADE_PLAN_2026.md +0 -130
- package/core/skills/education/2026_STANDARDS_SUMMARY.md +0 -290
- package/core/skills/education/create-exercises/UPGRADE_PLAN_2026.md +0 -115
- package/core/skills/education/design-learning-plan/UPGRADE_PLAN_2026.md +0 -140
- package/core/skills/education/grade-and-review/UPGRADE_PLAN_2026.md +0 -141
- package/core/skills/frontend/2026_STANDARDS_SUMMARY.md +0 -345
- package/core/skills/frontend/add-page-route/UPGRADE_PLAN_2026.md +0 -102
- package/core/skills/frontend/add-ui-component/UPGRADE_PLAN_2026.md +0 -114
- package/core/skills/frontend/component-composition/UPGRADE_PLAN_2026.md +0 -103
- package/core/skills/frontend/frontend-testing/UPGRADE_PLAN_2026.md +0 -137
- package/core/skills/frontend/implement-view-transitions/UPGRADE_PLAN_2026.md +0 -118
- package/core/skills/frontend/implement-webmcp/UPGRADE_PLAN_2026.md +0 -108
- package/core/skills/frontend/integrate-api-client/UPGRADE_PLAN_2026.md +0 -118
- package/core/skills/frontend/setup-design-system/UPGRADE_PLAN_2026.md +0 -123
- package/core/skills/frontend/setup-visual-regression/UPGRADE_PLAN_2026.md +0 -121
- package/core/skills/meetings-analysis/2026_STANDARDS_SUMMARY.md +0 -236
- package/core/skills/meetings-analysis/analyze-business-requirements/UPGRADE_PLAN_2026.md +0 -97
- package/core/skills/meetings-analysis/analyze-data/UPGRADE_PLAN_2026.md +0 -143
- package/core/skills/meetings-analysis/meeting-review/UPGRADE_PLAN_2026.md +0 -125
- package/core/skills/mobile/2026_STANDARDS_SUMMARY.md +0 -209
- package/core/skills/mobile/deploy-mobile-app/UPGRADE_PLAN_2026.md +0 -122
- package/core/skills/mobile/develop-mobile-app/UPGRADE_PLAN_2026.md +0 -141
package/core/skills/backend/add-service-client/examples/ts-circuit-breaker-full-jitter-client.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
const LedgerQuoteSchema = z.object({
|
|
5
|
+
quoteId: z.string().uuid(),
|
|
6
|
+
amountMinor: z.number().int().nonnegative(),
|
|
7
|
+
currency: z.string().length(3),
|
|
8
|
+
});
|
|
9
|
+
export type LedgerQuote = z.infer<typeof LedgerQuoteSchema>;
|
|
10
|
+
|
|
11
|
+
export class DownstreamUnavailableError extends Error {
|
|
12
|
+
constructor(public readonly service: string, cause?: unknown) {
|
|
13
|
+
super(`Downstream ${service} unavailable`, { cause });
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type CircuitState = 'CLOSED' | 'OPEN' | 'HALF_OPEN';
|
|
18
|
+
|
|
19
|
+
export class ResilientQuoteClient {
|
|
20
|
+
private state: CircuitState = 'CLOSED';
|
|
21
|
+
private openedAt = 0;
|
|
22
|
+
private halfOpenProbeInFlight = false;
|
|
23
|
+
private failures = 0;
|
|
24
|
+
|
|
25
|
+
constructor(private readonly baseUrl: string, private readonly timeoutMs = 2000) {}
|
|
26
|
+
|
|
27
|
+
async createQuote(orderId: string): Promise<LedgerQuote> {
|
|
28
|
+
if (this.state === 'OPEN') {
|
|
29
|
+
if (Date.now() - this.openedAt < 15_000) throw new DownstreamUnavailableError('ledger');
|
|
30
|
+
this.state = 'HALF_OPEN';
|
|
31
|
+
}
|
|
32
|
+
if (this.state === 'HALF_OPEN') {
|
|
33
|
+
if (this.halfOpenProbeInFlight) throw new DownstreamUnavailableError('ledger');
|
|
34
|
+
this.halfOpenProbeInFlight = true;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const idempotencyKey = randomUUID();
|
|
38
|
+
try {
|
|
39
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
40
|
+
try {
|
|
41
|
+
const res = await fetch(`${this.baseUrl}/v1/quotes`, {
|
|
42
|
+
method: 'POST',
|
|
43
|
+
signal: AbortSignal.timeout(this.timeoutMs),
|
|
44
|
+
headers: { 'content-type': 'application/json', 'idempotency-key': idempotencyKey },
|
|
45
|
+
body: JSON.stringify({ orderId }),
|
|
46
|
+
});
|
|
47
|
+
if (res.status >= 500 || res.status === 429) throw new Error(`transient ${res.status}`);
|
|
48
|
+
if (!res.ok) throw new DownstreamUnavailableError('ledger');
|
|
49
|
+
const parsed = LedgerQuoteSchema.parse(await res.json());
|
|
50
|
+
this.state = 'CLOSED';
|
|
51
|
+
this.failures = 0;
|
|
52
|
+
return parsed;
|
|
53
|
+
} catch (err) {
|
|
54
|
+
if (attempt === 2) throw err;
|
|
55
|
+
const cap = Math.min(2000, 100 * 2 ** attempt);
|
|
56
|
+
await new Promise((r) => setTimeout(r, Math.random() * cap));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
throw new DownstreamUnavailableError('ledger');
|
|
60
|
+
} catch (err) {
|
|
61
|
+
this.failures += 1;
|
|
62
|
+
if (this.failures >= 5 || this.state === 'HALF_OPEN') {
|
|
63
|
+
this.state = 'OPEN';
|
|
64
|
+
this.openedAt = Date.now();
|
|
65
|
+
}
|
|
66
|
+
throw err instanceof DownstreamUnavailableError ? err : new DownstreamUnavailableError('ledger', err);
|
|
67
|
+
} finally {
|
|
68
|
+
this.halfOpenProbeInFlight = false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
package/core/skills/backend/add-service-client/references/resilient-client-circuit-breaker-specs.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Resilient Service Client & Circuit Breaker Specifications
|
|
2
|
+
|
|
3
|
+
Normative reference for `add-service-client`: Connect/gRPC/HTTP narrow interfaces, AWS full-jitter exponential backoff, single-canary probe circuit breakers, and zero-trust workload identity.
|
|
4
|
+
|
|
5
|
+
## 1. Timeout & Resilience Equations
|
|
6
|
+
|
|
7
|
+
- **Connect Timeout**: $\le 2,000\text{ ms}$; **Request Timeout**: explicit per-RPC SLA (never library infinite defaults).
|
|
8
|
+
- **AWS Full Jitter Backoff**:
|
|
9
|
+
$$T_{\text{sleep}} = \text{random}\!\left(0, \min(T_{\max}, T_{\text{base}} \times 2^{\text{attempt}})\right)$$
|
|
10
|
+
- **Circuit Breaker FSM (`CLOSED` -> `OPEN` -> `HALF-OPEN`)**:
|
|
11
|
+
- Trip `CLOSED -> OPEN` when sliding window error ratio $\ge 50\%$ with $N_{\min} \ge 20$ samples.
|
|
12
|
+
- Cool down for $T_{\text{open}} \ge 15\text{s}$ before transitioning `OPEN -> HALF-OPEN`.
|
|
13
|
+
- **Single-Canary Probe Lock**: Hold an atomic CAS flag / Redis probe lock so strictly **1** request executes in `HALF-OPEN` while concurrent traffic fails fast until recovery confirms.
|
|
14
|
+
|
|
15
|
+
## 2. Error Normalization Boundary
|
|
16
|
+
|
|
17
|
+
Remote transport errors (`HTTP 4xx/5xx`, `gRPC codes.Unavailable`) MUST map into closed domain errors inside the adapter layer:
|
|
18
|
+
- `400/422` -> `DomainValidationError` (non-retryable)
|
|
19
|
+
- `401/403` -> `DownstreamAuthError` (non-retryable; trigger credential refresh check)
|
|
20
|
+
- `408/429/502/503/504` -> `TransientDependencyError` (retryable only with `Idempotency-Key` for writes)
|
|
21
|
+
|
|
22
|
+
## 3. Authentication & Zero-Trust Telemetry
|
|
23
|
+
|
|
24
|
+
- Internal service-to-service: **SPIFFE/SPIRE mTLS** (`SVID` auto-rotation); Cross-cloud: **OIDC Workload Identity**; User context: short-lived scoped **JWT**.
|
|
25
|
+
- Propagate W3C `traceparent`; emit OTel spans with `peer.service`, `rpc.method`, `http.response.status_code`; scrub PII and `Authorization` headers per `core/policies/data-classification.yaml`.
|
|
@@ -99,3 +99,5 @@ When this skill is invoked as part of a coordinated multi-role delivery, emit:
|
|
|
99
99
|
- **add-telemetry-instrumentation**: Wire OpenTelemetry spans and metrics for MCP tool executions
|
|
100
100
|
- **security-audit**: Review authentication, authorization boundaries, and input sanitization
|
|
101
101
|
- **write-tests**: Author automated test suites verifying MCP tool invocations and error scenarios
|
|
102
|
+
- Companion reference: [`references/mcp-2026-stateless-contract-specs.md`](references/mcp-2026-stateless-contract-specs.md)
|
|
103
|
+
- Companion example: [`examples/ts-stateless-mcp-server-zod.ts`](examples/ts-stateless-mcp-server-zod.ts)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
const InvoiceLookupInput = z.object({
|
|
5
|
+
invoiceId: z.string().regex(/^INV-[0-9]{6,12}$/),
|
|
6
|
+
tenantId: z.string().uuid(),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
const InvoiceLookupOutput = z.object({
|
|
10
|
+
invoiceId: z.string(),
|
|
11
|
+
status: z.enum(['draft', 'issued', 'paid', 'void']),
|
|
12
|
+
totalMinor: z.number().int().nonnegative(),
|
|
13
|
+
currency: z.string().length(3),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export function createStatelessMcpServer(verifyTenantAccess: (tenantId: string) => Promise<boolean>) {
|
|
17
|
+
const server = new McpServer({
|
|
18
|
+
name: 'billing-mcp-server',
|
|
19
|
+
version: '1.2.0',
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
server.registerTool(
|
|
23
|
+
'get_invoice_status_v1',
|
|
24
|
+
{
|
|
25
|
+
description: 'Read-only lookup of a tenant-scoped invoice status by immutable invoice identifier.',
|
|
26
|
+
inputSchema: InvoiceLookupInput,
|
|
27
|
+
outputSchema: InvoiceLookupOutput,
|
|
28
|
+
},
|
|
29
|
+
async (args) => {
|
|
30
|
+
const parsed = InvoiceLookupInput.parse(args);
|
|
31
|
+
const allowed = await verifyTenantAccess(parsed.tenantId);
|
|
32
|
+
if (!allowed) {
|
|
33
|
+
return {
|
|
34
|
+
isError: true,
|
|
35
|
+
content: [{ type: 'text', text: JSON.stringify({ error: 'FORBIDDEN_TENANT_SCOPE' }) }],
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const payload = InvoiceLookupOutput.parse({
|
|
39
|
+
invoiceId: parsed.invoiceId,
|
|
40
|
+
status: 'issued',
|
|
41
|
+
totalMinor: 125000,
|
|
42
|
+
currency: 'VND',
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
structuredContent: payload,
|
|
46
|
+
content: [{ type: 'text', text: JSON.stringify(payload) }],
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
return server;
|
|
52
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# MCP 2026-07-28 Stateless Contract & Transport Specifications
|
|
2
|
+
|
|
3
|
+
Normative reference for `build-mcp-server`: stateless Streamable HTTP, `stdio` isolation, OAuth 2.1 + RFC 8707 audience binding, and SemVer tool contract governance.
|
|
4
|
+
|
|
5
|
+
## 1. Stateless Streamable HTTP & Routing Headers
|
|
6
|
+
|
|
7
|
+
- **No Server-Memory Sessions**: Every HTTP invocation carries explicit bearer context (`Authorization: Bearer ...`) and externalizes state to Redis/Postgres/Durable Objects.
|
|
8
|
+
- **Gateway Inspection Headers**: Clients/proxies attach `Mcp-Method: tools/call` and `Mcp-Name: <tool_name>` so WAF and rate limiters inspect calls without JSON-RPC body buffering.
|
|
9
|
+
- **`stdio` Safety Rule**: In local CLI/IDE `stdio` transport, route 100% of diagnostic/OTel logs to `stderr`; never write non-JSON-RPC bytes to `stdout`.
|
|
10
|
+
|
|
11
|
+
## 2. Schema-First & SemVer Versioning
|
|
12
|
+
|
|
13
|
+
- Author canonical **Zod** / **Pydantic v2** schemas with explicit bounds (`additionalProperties: false` / `strict()`).
|
|
14
|
+
- Never mutate required fields in-place on an existing tool name:
|
|
15
|
+
- Additive optional fields -> increment server/tool **MINOR**.
|
|
16
|
+
- Breaking input/output contract changes -> publish `tool_v2` (**MAJOR**) and run dual-version coexistence with telemetry verification before sunset.
|
|
17
|
+
|
|
18
|
+
## 3. Authorization & Mutation Gating
|
|
19
|
+
|
|
20
|
+
- Validate OAuth 2.1 JWT signatures, issuer, `aud` (RFC 8707 Resource Indicator), and per-tool scopes (`read:*` vs `write:*`).
|
|
21
|
+
- Destructive tools (`delete_*`, `transfer_*`, `deploy_*`) MUST reject anonymous callers and require an explicit confirmation token or human-in-the-loop mandate.
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: design-caching-and-locking
|
|
3
|
+
description: Design distributed caching tiers, atomic Redis 7.4+ Lua fencing-token locks, cache-stampede protection (singleflight / XFetch), and hot-spot key mitigation without split-brain or race conditions. Use when building distributed locks, inventory reservations, rate limiters, session/JTI caches, or flash-sale hot-key pipelines.
|
|
4
|
+
version: "1.0.0"
|
|
5
|
+
allowed-tools: [read_file, write_file, edit_file, create_file, search_code, run_tests, run_linter, run_build, execute_command]
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Design Caching and Locking
|
|
9
|
+
|
|
10
|
+
Use this skill when implementing distributed locks, atomic Redis Lua state transitions, flash-sale hot-spot caching, or stampede-resistant cache invalidation.
|
|
11
|
+
|
|
12
|
+
## When to Use
|
|
13
|
+
|
|
14
|
+
- protecting inventory reservations, payment webhooks, or leader leases with Redis Lua fencing tokens
|
|
15
|
+
- eliminating thundering-herd cache stampedes via `singleflight` or probabilistic early expiration (XFetch)
|
|
16
|
+
- preventing Redis hot-key CPU saturation under flash-sale traffic (local L1 + sharded counters)
|
|
17
|
+
- storing security revocation state (JWT JTI denylists) with bounded TTLs and fail-closed policies
|
|
18
|
+
|
|
19
|
+
## Core Rules
|
|
20
|
+
|
|
21
|
+
- **Fencing Tokens Required on Distributed Locks**: Mutual-exclusion locks MUST issue a monotonically increasing fencing token (`INCR lock:fence:<resource>`) validated by downstream storage before committing writes — plain `SET NX PX` without storage fencing permits split-brain overwrites after GC/network pauses.
|
|
22
|
+
- **Lua Script Atomicity & Determinism**: Keep check-and-mutate operations inside one Redis Lua script (`EVALSHA`); avoid `TIME`, `RANDOMKEY`, `math.random`, and unbounded key scans (`KEYS *`).
|
|
23
|
+
- **Explicit TTL on Every Ephemeral Key**: Every lock, reservation, idempotency cache, and JTI denylist entry MUST specify an explicit finite TTL (`EX`/`PX`); never leave orphan locks without expiration.
|
|
24
|
+
- **Anti-Stampede Invalidation**: Guard cache-miss rebuilds with per-process `singleflight` coalescing + short jittered negative caching + early XFetch refresh before hard expiry.
|
|
25
|
+
- **Fail-Closed vs Fail-Open Separation**: Security revocation checks (`jti` denylist, rate limits on auth/payment) MUST fail closed if cache state is unreachable; read-through product caches may degrade cleanly to rate-limited DB replicas.
|
|
26
|
+
|
|
27
|
+
## Suggested Process
|
|
28
|
+
|
|
29
|
+
### 1. Classify Cache vs Lock Invariant
|
|
30
|
+
Determine consistency bar: eventual read cache (bounded staleness) vs linearizable state transition (fenced lock or atomic Lua reservation).
|
|
31
|
+
|
|
32
|
+
### 2. Design Keyspace, Shard Strategy & TTLs
|
|
33
|
+
Define deterministic key prefixes (`resv:{sku_id}`, `fence:{sku_id}`), compute memory budget ($N_{\text{keys}} \times (\text{key\_bytes} + \text{val\_bytes} + \text{overhead})$), and shard hot SKUs when single-shard ops exceed $50\text{k ops/s}$.
|
|
34
|
+
|
|
35
|
+
### 3. Implement Atomic Lua Transition & Storage Fencing
|
|
36
|
+
Write the Lua script in `examples/` or service repo, attach `EX`/`PEXPIRE` on every new key, return `[ok, fencing_token, remaining]`, and persist the `WHERE last_fence < $token` guard in SQL/storage. Run `verify_lua_atomicity.py` on Lua files before merging.
|
|
37
|
+
|
|
38
|
+
### 4. Verify Under Concurrency & Failover
|
|
39
|
+
Use skill: `write-tests`. Simulate parallel checkout bursts, expired lease takeover, and cache unavailability to verify zero oversell and fail-closed security behavior.
|
|
40
|
+
|
|
41
|
+
## Checklist
|
|
42
|
+
|
|
43
|
+
- [ ] distributed lock returns a monotonically increasing fencing token checked at downstream storage
|
|
44
|
+
- [ ] check-and-mutate executes inside one deterministic Redis Lua script (no `KEYS *`, `TIME`, or `math.random`)
|
|
45
|
+
- [ ] every lock, reservation, and denylist key enforces an explicit finite TTL (`EX` / `PX`)
|
|
46
|
+
- [ ] cache rebuild paths apply `singleflight` / XFetch stampede protection
|
|
47
|
+
- [ ] hot-spot traffic uses L1 LRU or sharded sub-keys with parity tests under concurrency
|
|
48
|
+
|
|
49
|
+
## Red Flags
|
|
50
|
+
|
|
51
|
+
| Rationalization Thought | Reality & Risk | Positive Corrective Action |
|
|
52
|
+
| :--- | :--- | :--- |
|
|
53
|
+
| "`GET` then `DECR` in app code is fast enough in Redis." | Concurrent requests interleave and oversell negative inventory under load. | Move check + decrement + TTL inside one atomic Lua script. |
|
|
54
|
+
| "`SET NX EX 30` is all we need for mutual exclusion." | Process pause > 30s lets stale holder overwrite newer lock holder's write. | Issue monotonic fencing token and enforce `fence >= current` in storage. |
|
|
55
|
+
| "Skip TTL on permanent deny keys or let eviction handle it." | Unbounded key growth exhausts Redis `maxmemory` and evicts active locks. | Set explicit TTL equal to token/reservation lifetime plus skew margin. |
|
|
56
|
+
| "Let all 5,000 misses query PostgreSQL directly when cache expires." | Stampede saturates DB connections and cascades into full outage. | Coalesce misses via `singleflight`, stagger TTL jitter, and pre-warm hot keys. |
|
|
57
|
+
|
|
58
|
+
## Output Contracts
|
|
59
|
+
|
|
60
|
+
When caching or locking alters cross-service contracts or rollout configuration, emit:
|
|
61
|
+
|
|
62
|
+
- **`contracts/schemas/implementation-result.json`** documenting Lua scripts, key prefixes, TTLs, and concurrency test results.
|
|
63
|
+
|
|
64
|
+
## Failure Modes
|
|
65
|
+
|
|
66
|
+
- **Split-brain stale writer**: lock expires during GC pause and stale worker writes anyway. Mitigation: validate monotonic fencing token inside DB conditional update.
|
|
67
|
+
- **Hot-key shard saturation**: single flash-sale SKU pins one Redis CPU core at 100%. Mitigation: L1 local micro-cache (50-200ms) + $K$-sharded counters.
|
|
68
|
+
- **Out-of-memory lock eviction**: cache bloat under `allkeys-lru` evicts active locks. Mitigation: separate Redis cluster/namespace (`noeviction`) for locks/idempotency vs `allkeys-lru` cache.
|
|
69
|
+
|
|
70
|
+
## Security Guardrails (OWASP ASI)
|
|
71
|
+
|
|
72
|
+
- **ASI02 Tool Misuse**: Lua scripts must never `cjson`/eval untrusted user strings into Redis commands.
|
|
73
|
+
- **ASI03 Identity & Privilege Abuse**: JTI denylists and session locks must fail closed when Redis is unreachable.
|
|
74
|
+
- **ASI05 RCE Guard**: validate numeric TTL/quantity arguments strictly as bounded integers before `EVALSHA`.
|
|
75
|
+
|
|
76
|
+
## Related Skills
|
|
77
|
+
|
|
78
|
+
- **add-api-endpoint**: Wire idempotency keys and rate limits at HTTP handlers
|
|
79
|
+
- **handle-checkout-flow**: Apply TTL reservations and ATP fencing during checkout
|
|
80
|
+
- **optimize-postgres**: Guard storage updates paired with distributed fencing tokens
|
|
81
|
+
- **write-tests**: Author concurrent race-condition verification suites
|
|
82
|
+
- Companion reference: [`references/redis-lua-fencing-and-stampede-specs.md`](references/redis-lua-fencing-and-stampede-specs.md)
|
|
83
|
+
- Companion example: [`examples/redis-lua-atomic-reservation-fencing.lua`](examples/redis-lua-atomic-reservation-fencing.lua)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
-- KEYS[1] = stock key (e.g., inv:stock:{sku_123})
|
|
2
|
+
-- KEYS[2] = reservation hash/key (e.g., inv:hold:{order_456})
|
|
3
|
+
-- KEYS[3] = monotonic fence sequence key (e.g., inv:fence:{sku_123})
|
|
4
|
+
-- ARGV[1] = requested quantity (> 0)
|
|
5
|
+
-- ARGV[2] = hold TTL seconds (> 0)
|
|
6
|
+
-- Returns: {status_code (1=OK, 0=INSUFFICIENT, -1=ALREADY_HELD), fence_token, remaining_stock}
|
|
7
|
+
|
|
8
|
+
local qty = tonumber(ARGV[1])
|
|
9
|
+
local ttl = tonumber(ARGV[2])
|
|
10
|
+
|
|
11
|
+
if not qty or qty <= 0 or not ttl or ttl <= 0 then
|
|
12
|
+
return redis.error_reply("INVALID_ARGS: qty and ttl must be positive integers")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
if redis.call("EXISTS", KEYS[2]) == 1 then
|
|
16
|
+
local existing_fence = tonumber(redis.call("GET", KEYS[2])) or 0
|
|
17
|
+
local rem = tonumber(redis.call("GET", KEYS[1])) or 0
|
|
18
|
+
return { -1, existing_fence, rem }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
local available = tonumber(redis.call("GET", KEYS[1])) or 0
|
|
22
|
+
if available < qty then
|
|
23
|
+
return { 0, 0, available }
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
local remaining = redis.call("DECRBY", KEYS[1], qty)
|
|
27
|
+
local fence_token = redis.call("INCR", KEYS[3])
|
|
28
|
+
redis.call("SET", KEYS[2], tostring(fence_token), "EX", ttl)
|
|
29
|
+
|
|
30
|
+
return { 1, fence_token, remaining }
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Redis 7.4+ Lua Fencing Tokens, Sharded Hot Keys & Stampede Protection
|
|
2
|
+
|
|
3
|
+
Normative reference for `design-caching-and-locking`.
|
|
4
|
+
|
|
5
|
+
## 1. Fencing Token State Model
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
Worker A acquires lock -> token = 41 -> pauses 35s (lease 30s expires)
|
|
9
|
+
Worker B acquires lock -> token = 42 -> DB UPDATE ... WHERE fence_token < 42 (SUCCEEDS, sets fence=42)
|
|
10
|
+
Worker A wakes up -> sends token=41 -> DB UPDATE ... WHERE fence_token < 41 (0 ROWS AFFECTED, REJECTED)
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
- Always separate **`noeviction`** Redis instance (locks, idempotency, JTI revocation) from **`allkeys-lfu`** Redis instance (read-through cache).
|
|
14
|
+
|
|
15
|
+
## 2. XFetch Probabilistic Early Expiration
|
|
16
|
+
|
|
17
|
+
Refresh cached values probabilistically before hard TTL $T_{\text{ttl}}$ ends:
|
|
18
|
+
|
|
19
|
+
$$t_{\text{now}} - \Delta \cdot \beta \cdot \ln(\text{rand}(0, 1]) \ge t_{\text{expiry}}$$
|
|
20
|
+
|
|
21
|
+
Where $\Delta$ is last recompute duration and $\beta \ge 1.0$ controls aggressiveness, preventing synchronized cache misses across replicas.
|
|
22
|
+
|
|
23
|
+
## 3. Hot-Key Sharding (Alipay 610k TPS Pattern)
|
|
24
|
+
|
|
25
|
+
Split single flash-sale SKU key `stock:{sku}` into $K$ shards (`stock:{sku}:0` .. `stock:{sku}:K-1`) hashed per request, backed by L1 in-memory read cache (50–250ms TTL) on storefront reads.
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Static verifier for Redis Lua atomicity, determinism, TTL discipline, and fencing tokens."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import argparse
|
|
7
|
+
import re
|
|
8
|
+
import sys
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
FORBIDDEN_COMMANDS = (
|
|
12
|
+
("KEYS", re.compile(r'redis\.call\(\s*["\']KEYS["\']', re.I)),
|
|
13
|
+
("TIME", re.compile(r'redis\.call\(\s*["\']TIME["\']', re.I)),
|
|
14
|
+
("RANDOMKEY", re.compile(r'redis\.call\(\s*["\']RANDOMKEY["\']', re.I)),
|
|
15
|
+
("math.random", re.compile(r'\bmath\.random\b')),
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
TTL_PATTERN = re.compile(r'(["\']EX["\']|["\']PX["\']|["\']EXPIRE["\']|["\']PEXPIRE["\']|SETEX)', re.I)
|
|
19
|
+
FENCE_PATTERN = re.compile(r'redis\.call\(\s*["\']INCR["\']', re.I)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def verify_lua_source(source: str, *, require_fence: bool = True) -> list[str]:
|
|
23
|
+
"""Return list of safety/atomicity violations for a Redis Lua script."""
|
|
24
|
+
errors: list[str] = []
|
|
25
|
+
for label, pat in FORBIDDEN_COMMANDS:
|
|
26
|
+
if pat.search(source):
|
|
27
|
+
errors.append(f"Non-deterministic or blocking Redis call forbidden in Lua: {label}")
|
|
28
|
+
if "SET" in source and not TTL_PATTERN.search(source):
|
|
29
|
+
errors.append("Lua script mutates keys via SET without explicit TTL (EX/PX/EXPIRE)")
|
|
30
|
+
if require_fence and not FENCE_PATTERN.search(source):
|
|
31
|
+
errors.append("Distributed reservation/lock Lua script must generate a monotonic INCR fencing token")
|
|
32
|
+
return errors
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def run_self_test() -> int:
|
|
36
|
+
example_path = Path(__file__).resolve().parent.parent / "examples" / "redis-lua-atomic-reservation-fencing.lua"
|
|
37
|
+
good = example_path.read_text(encoding="utf-8")
|
|
38
|
+
assert verify_lua_source(good) == [], f"Example Lua script failed: {verify_lua_source(good)}"
|
|
39
|
+
|
|
40
|
+
bad_time = 'redis.call("SET", KEYS[1], ARGV[1])\nredis.call("TIME")'
|
|
41
|
+
errs = verify_lua_source(bad_time)
|
|
42
|
+
assert len(errs) == 3, f"Expected 3 errors (TIME + missing TTL + missing INCR), got {errs}"
|
|
43
|
+
print("verify_lua_atomicity self-test PASSED")
|
|
44
|
+
return 0
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def main() -> int:
|
|
48
|
+
parser = argparse.ArgumentParser(description="Verify Redis Lua script atomicity & TTL invariants.")
|
|
49
|
+
parser.add_argument("path", nargs="?", help="Path to .lua script")
|
|
50
|
+
parser.add_argument("--self-test", action="store_true")
|
|
51
|
+
parser.add_argument("--no-fence", action="store_true")
|
|
52
|
+
args = parser.parse_args()
|
|
53
|
+
|
|
54
|
+
if args.self_test:
|
|
55
|
+
return run_self_test()
|
|
56
|
+
if not args.path:
|
|
57
|
+
parser.error("Provide a .lua path or --self-test")
|
|
58
|
+
errs = verify_lua_source(Path(args.path).read_text(encoding="utf-8"), require_fence=not args.no_fence)
|
|
59
|
+
if errs:
|
|
60
|
+
for e in errs:
|
|
61
|
+
print(f"ERROR: {e}", file=sys.stderr)
|
|
62
|
+
return 1
|
|
63
|
+
print(f"OK: {args.path}")
|
|
64
|
+
return 0
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
if __name__ == "__main__":
|
|
68
|
+
sys.exit(main())
|
|
@@ -82,6 +82,15 @@ When this skill is invoked as part of a coordinated multi-role delivery, emit:
|
|
|
82
82
|
- **ASI05 RCE Guard**: never interpolate user identifiers directly into raw SQL or session keys; use parameterized statements and validated types.
|
|
83
83
|
- **ASI07 Inter-Agent Communication**: emit structured `api-contract-spec.json` documenting authentication scopes and error behaviors.
|
|
84
84
|
|
|
85
|
+
## Red Flags
|
|
86
|
+
|
|
87
|
+
| Rationalization Thought | Reality & Risk | Positive Corrective Action |
|
|
88
|
+
| :--- | :--- | :--- |
|
|
89
|
+
| "`code_challenge_method=plain` or omitting PKCE simplifies client SDK setup." | Authorization code interception leaks session grants to malicious apps. | Enforce PKCE with `S256` and high-entropy `code_verifier` (`43–128` chars). |
|
|
90
|
+
| "Old refresh tokens just expire naturally — family revocation is overkill." | Stolen refresh token replay goes undetected alongside legitimate sessions. | Rotate single-use refresh tokens and revoke the entire family on reuse. |
|
|
91
|
+
| "Filtering `WHERE tenant_id = ?` in ORM code makes RLS unnecessary." | One missed raw query or job helper exposes cross-tenant production PII. | Enforce `FORCE ROW LEVEL SECURITY` with transactional `set_config(..., true)`. |
|
|
92
|
+
| "Storing auth user context on a container singleton is fast in FrankenPHP/ASGI." | Persistent worker runtimes bleed User A's session into User B's request. | Use `contextvars` / request-scoped containers flushed on request termination. |
|
|
93
|
+
|
|
85
94
|
## Related Skills
|
|
86
95
|
|
|
87
96
|
- **add-api-endpoint**: Wire authenticated handlers and boundary validators
|
|
@@ -93,3 +93,5 @@ When this skill is invoked as part of a coordinated multi-role delivery, emit:
|
|
|
93
93
|
- **add-api-endpoint**: Integrate validated LLM output payloads into service endpoints and domain flows
|
|
94
94
|
- **write-tests**: Create test suites covering schema validation, constraint failures, and retry logic
|
|
95
95
|
- **review-code**: Verify schema strictness, error boundaries, and absence of regex parsing
|
|
96
|
+
- Companion reference: [`references/constrained-decoding-and-double-validation.md`](references/constrained-decoding-and-double-validation.md)
|
|
97
|
+
- Companion example: [`examples/python-pydantic-structured-output.py`](examples/python-pydantic-structured-output.py)
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from typing import Callable, Literal
|
|
5
|
+
from pydantic import BaseModel, ConfigDict, Field, TypeAdapter, ValidationError
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class InvoiceExtraction(BaseModel):
|
|
9
|
+
model_config = ConfigDict(extra="forbid")
|
|
10
|
+
|
|
11
|
+
thought_process: str = Field(description="Scratchpad verification stripped before returning.")
|
|
12
|
+
invoice_number: str = Field(pattern=r"^INV-[0-9]{6,12}$")
|
|
13
|
+
currency: Literal["VND", "USD", "EUR"]
|
|
14
|
+
total_minor: int = Field(ge=0)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class PublicInvoiceResult(BaseModel):
|
|
18
|
+
model_config = ConfigDict(extra="forbid")
|
|
19
|
+
invoice_number: str
|
|
20
|
+
currency: Literal["VND", "USD", "EUR"]
|
|
21
|
+
total_minor: int
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class StructuredOutputError(RuntimeError):
|
|
25
|
+
"""Raised when bounded constrained-decoding + repair loop fails closed."""
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def extract_with_bounded_repair(
|
|
29
|
+
call_gateway: Callable[[str, dict], str],
|
|
30
|
+
document_text: str,
|
|
31
|
+
max_retries: int = 2,
|
|
32
|
+
) -> PublicInvoiceResult:
|
|
33
|
+
adapter = TypeAdapter(InvoiceExtraction)
|
|
34
|
+
schema = InvoiceExtraction.model_json_schema()
|
|
35
|
+
prompt = f"Extract invoice fields strictly as JSON from:\n{document_text}"
|
|
36
|
+
|
|
37
|
+
last_error = ""
|
|
38
|
+
for attempt in range(max_retries + 1):
|
|
39
|
+
raw_payload = call_gateway(prompt, schema)
|
|
40
|
+
try:
|
|
41
|
+
parsed = adapter.validate_json(raw_payload)
|
|
42
|
+
return PublicInvoiceResult(
|
|
43
|
+
invoice_number=parsed.invoice_number,
|
|
44
|
+
currency=parsed.currency,
|
|
45
|
+
total_minor=parsed.total_minor,
|
|
46
|
+
)
|
|
47
|
+
except ValidationError as exc:
|
|
48
|
+
last_error = exc.json()
|
|
49
|
+
if attempt >= max_retries:
|
|
50
|
+
break
|
|
51
|
+
prompt = (
|
|
52
|
+
f"Previous JSON failed validation:\n{last_error}\n"
|
|
53
|
+
f"Correct only invalid fields for source:\n{document_text}"
|
|
54
|
+
)
|
|
55
|
+
raise StructuredOutputError(f"Exceeded {max_retries} repair retries: {last_error}")
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
if __name__ == "__main__":
|
|
59
|
+
sample = json.dumps({
|
|
60
|
+
"thought_process": "Checked subtotal and ISO currency.",
|
|
61
|
+
"invoice_number": "INV-202601",
|
|
62
|
+
"currency": "VND",
|
|
63
|
+
"total_minor": 450000,
|
|
64
|
+
})
|
|
65
|
+
print(extract_with_bounded_repair(lambda _p, _s: sample, "Invoice INV-202601 450000 VND"))
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Constrained Decoding & Double-Validation Specifications
|
|
2
|
+
|
|
3
|
+
Normative reference for `implement-structured-outputs`: grammar/JSON-Schema token masking, dual-layer runtime validation, format-tax mitigation, and bounded repair loops.
|
|
4
|
+
|
|
5
|
+
## 1. Constrained Decoding Matrix
|
|
6
|
+
|
|
7
|
+
| Deployment Stack | Grammar / Schema Mechanism | Guarantee Scope |
|
|
8
|
+
| :--- | :--- | :--- |
|
|
9
|
+
| OpenAI / Gemini API | `response_format: { type: "json_schema", strict: true }` / `responseSchema` | Syntax + declared field types + closed `additionalProperties: false` |
|
|
10
|
+
| Self-Hosted vLLM / SGLang | `--guided-decoding-backend xgrammar` / `outlines` | Finite-state / pushdown CFG logit masking at decode step |
|
|
11
|
+
| Application Runtime | Pydantic v2 `TypeAdapter.validate_json()` / Zod `safeParse()` | Cross-field invariants, business ranges, regex/domain enums |
|
|
12
|
+
|
|
13
|
+
## 2. Double-Validation & Bounded Repair Protocol
|
|
14
|
+
|
|
15
|
+
1. Emit `thought_process` / `reasoning` field **first** in schema to neutralize reasoning-quality drop ("format tax"), then strip it before returning to callers.
|
|
16
|
+
2. Check provider safety/refusal fields **before** running JSON parsing.
|
|
17
|
+
3. Validate raw decoded JSON via Pydantic/Zod; on `ValidationError`, inject the exact validation error JSON into at most **2** repair attempts.
|
|
18
|
+
4. On retry exhaustion (`attempts > 2`), fail closed with a typed `StructuredOutputError` — NEVER fall back to regex or heuristic string slicing.
|
|
@@ -81,6 +81,15 @@ When this skill is invoked as part of a coordinated multi-role delivery, emit:
|
|
|
81
81
|
- **ASI05 RCE Guard**: never interpolate untrusted identifiers into DDL statements or query analyzer strings.
|
|
82
82
|
- **ASI07 Inter-Agent Communication**: emit structured `schema-migration.json` detailing locking behavior and rollout safety.
|
|
83
83
|
|
|
84
|
+
## Red Flags
|
|
85
|
+
|
|
86
|
+
| Rationalization Thought | Reality & Risk | Positive Corrective Action |
|
|
87
|
+
| :--- | :--- | :--- |
|
|
88
|
+
| "Query looks fast on 100 local dev rows, so `EXPLAIN (ANALYZE, BUFFERS)` isn't needed." | Production table sizes hit seq-scan cliffs and `external merge Disk` spills. | Capture buffer-verified `EXPLAIN (ANALYZE, BUFFERS)` plans before merging. |
|
|
89
|
+
| "Increase `max_connections` to 500 instead of tuning pool sizes." | Context-switching and memory exhaustion tank database throughput under load. | Use transaction-mode pooling (`6543`, `statement_cache_size=0`) bounded by cores. |
|
|
90
|
+
| "Skip `lock_timeout` so the migration finishes reliably." | Queued `ACCESS EXCLUSIVE` DDL blocks every subsequent read/write on the pool. | Prepend `SET lock_timeout = '2s';` and use two-phase `NOT VALID` constraints. |
|
|
91
|
+
| "Leave a failed `CREATE INDEX CONCURRENTLY` alone; we'll fix it next sprint." | `indisvalid=false` indexes consume disk and slow every `INSERT`/`UPDATE`. | Inspect `WHERE NOT indisvalid` and drop/rebuild failed indexes immediately. |
|
|
92
|
+
|
|
84
93
|
## Related Skills
|
|
85
94
|
|
|
86
95
|
- **create-migration**: Author additive schema migrations and rollback scripts
|
|
@@ -25,8 +25,9 @@ Use this skill to bootstrap new microservices, workers, or bounded components us
|
|
|
25
25
|
- **Sandbox readiness**: generate a multi-stage rootless `Dockerfile` (`USER nonroot`, read-only rootfs compatibility) and local test harness compatible with Level 0 air-gapped sandboxes (`--network=none`) per `core/policies/execution-sandbox.md`
|
|
26
26
|
- **Observability from commit 1**: implement `/health/live`, `/health/ready` probes and initialize OpenTelemetry tracer bootstrap with trace context propagation
|
|
27
27
|
- **Dependency injection**: use compile-time DI (Wire, Fx, or repo standard) for all constructor injection; no global state or `init()` singletons
|
|
28
|
+
- **Ousterhout Deep Modules & Seam Discipline**: design thin, stable public interfaces hiding deep implementations; apply *The Deletion Test*, *Design It Twice*, and the Two-Adapter rule (*1 adapter = hypothesis, 2+ adapters = proven seam*), keeping tests anchored to the public interface seam
|
|
28
29
|
- **Zero secrets in scaffold**: declare environment configurations and secret bindings via external secret stores; reject hardcoded credentials
|
|
29
|
-
- detailed directory layouts, Dockerfiles, and
|
|
30
|
+
- detailed directory layouts, Dockerfiles, and deep-module design guides: [`references/service-scaffolding-guide.md`](references/service-scaffolding-guide.md) and [`references/deep-modules-and-seams.md`](references/deep-modules-and-seams.md)
|
|
30
31
|
|
|
31
32
|
## Suggested Process
|
|
32
33
|
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Ousterhout Deep Modules, Seams & Interface-First Testing Reference
|
|
2
|
+
|
|
3
|
+
Use these structural design heuristics (synthesized from John Ousterhout's *A Philosophy of Software Design*, Michael Feathers' *Working Effectively with Legacy Code*, and `mattpocock/skills`) when architecting new services, boundaries, or TypeScript/backend modules.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 1. Core Design Vocabulary
|
|
8
|
+
|
|
9
|
+
- **Module:** Any cohesive unit with an exported interface and a hidden implementation (package, service, microservice client, domain class).
|
|
10
|
+
- **Deep Module vs Shallow Module:**
|
|
11
|
+
- **Deep Module:** Exposes a small, intuitive interface hiding substantial implementation complexity. Maximizes **Leverage** (callers learn very little to accomplish a lot) and **Locality** (behavior changes require editing one module, not ten).
|
|
12
|
+
- **Shallow Module (Reject):** Exposes a large or mirror-image interface whose body only forwards calls or adds boilerplate wrapper indirection, inflating context window overhead.
|
|
13
|
+
- **Seam:** A boundary point where system behavior can be altered or substituted without editing source code at the call site — the exact boundary where a module's public interface sits.
|
|
14
|
+
- **Adapter:** A concrete implementation satisfying the contract at a seam.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## 2. Architectural Guardrails
|
|
19
|
+
|
|
20
|
+
### 2.1 The Two-Adapter Rule ("Two Adapters Prove a Seam")
|
|
21
|
+
- Creating an abstract interface or repository wrapper around **one** concrete implementation proves only a *hypothetical seam* (speculative generality / Middle Man smell).
|
|
22
|
+
- Require **two or more concrete adapters** (e.g. primary database/provider plus fake/in-memory adapter or multiple carrier APIs) before introducing an abstraction seam.
|
|
23
|
+
|
|
24
|
+
### 2.2 The Deletion Test
|
|
25
|
+
Evaluate every intermediate wrapper, helper, or facade with a thought experiment:
|
|
26
|
+
- *If deleting the module causes complexity to simply disappear without touching callers* $\rightarrow$ it was a useless shallow pass-through wrapper; inline and delete it.
|
|
27
|
+
- *If deleting the module forces complex invariants and branching to fragment across $N$ call sites* $\rightarrow$ it is a justified Deep Module protecting callers.
|
|
28
|
+
|
|
29
|
+
### 2.3 Design It Twice
|
|
30
|
+
Before locking a new cross-module contract or service interface, sketch **two genuinely different structural designs** (not cosmetic renamings) and compare caller ergonomics, seam testability, and blast radius before picking the cleaner boundary.
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## 3. Interface Is The Test Surface (Seam-Based TDD)
|
|
35
|
+
- Both production callers and automated tests must traverse the **same public interface seam**.
|
|
36
|
+
- Prohibit unit tests that reach past the interface seam to assert private fields, internal helper invocation counts, or tautological mock behavior mirroring the implementation.
|
|
37
|
+
- Prefer real in-memory adapters or sandbox containers behind clean ports over deep mock trees.
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## 4. TypeScript Deep Module Conventions (Node / Astro / Next.js / Workers)
|
|
42
|
+
- **Root Entrypoint Enforcement (`dependency-cruiser`):** Configure architectural lint rules (`check:deps`) forbidding cross-module imports into internal subpaths (`src/modules/<mod>/internal/**`), allowing imports solely through each module's public root entrypoint while avoiding indiscriminate barrel re-export chains that trigger circular imports or bundle bloat.
|
|
43
|
+
- **Type-Safe Test Builders (`fromPartial()` over `as any`):** Replace unsafe `as any` or bare type assertions in test fixtures with strongly typed partial builders (e.g. `fromPartial(...)` via `@total-typescript/shoehorn` or strict helper factories) so interface evolutions surface compile-time breaks immediately.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: elicit-requirements
|
|
3
3
|
description: Elicit business requirements from stakeholders using Funnel Questioning (Open, Probing, Closed), the Colombo Method, and the 9 BABOK v3 requirement quality criteria. Use when scoping ambiguous business needs, conducting stakeholder interviews, uncovering tacit domain knowledge, or validating requirement quality before architecture handoff.
|
|
4
|
+
version: "1.0.0"
|
|
4
5
|
allowed-tools: [read_file, write_file, edit_file, create_file, search_code, run_tests, run_linter, run_build, execute_command]
|
|
5
6
|
---
|
|
6
7
|
|
|
@@ -24,6 +25,7 @@ Use this skill to extract, clarify, and validate business requirements from stak
|
|
|
24
25
|
2. *Probing phase*: drill down into edge cases, volumes, exceptions, and business rules ("What happens when an approval exceeds 48 hours?")
|
|
25
26
|
3. *Closed confirmation phase*: lock specific thresholds, states, and acceptance boundaries ("Is 50,000 USD the absolute hard ceiling for Level 2 approval?")
|
|
26
27
|
- **Apply the Colombo Method for Tacit Knowledge**: adopt a deliberate, structured curiosity posture to surface hidden assumptions; ask "naive" boundary questions that force stakeholders to articulate unwritten organizational habits and tribal knowledge
|
|
28
|
+
- **Socratic Decision-Tree Grilling & Repo-First Lookup**: model ambiguous scope as a design decision tree, resolve facts answerable from codebase/docs via search before asking stakeholders, compute the unresolved **Decision Frontier**, and present batched numbered questions with a clear `(Recommended)` default option
|
|
27
29
|
- **Mandate 9 BABOK v3 Requirement Quality Criteria**: every requirement item must pass the 9 characteristics:
|
|
28
30
|
- *Atomic*: captures a single requirement, never joined with compound "and/or" clauses
|
|
29
31
|
- *Complete*: includes context, preconditions, error states, and measurable outcomes
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: trace-requirements-impact
|
|
3
3
|
description: Build Requirements Traceability Matrices (RTM), run BFS change-request impact analysis across requirements to test cases, and prioritize backlogs using BABOK v3 models (MoSCoW, WSJF, Impact/Effort, Timeboxing). Use when assessing change requests, evaluating regression blast radiuses, prioritizing sprint scope, or maintaining end-to-end compliance audit trails.
|
|
4
|
+
version: "1.0.0"
|
|
4
5
|
allowed-tools: [read_file, write_file, edit_file, create_file, search_code, run_tests, run_linter, run_build, execute_command]
|
|
5
6
|
---
|
|
6
7
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: write-use-cases
|
|
3
3
|
description: Scope, structure, and document production-grade Use Cases using Karl Wiegers 13-field template, Alistair Cockburn goal levels and scoping tests, and 20-point quality validation. Use when detailing user interactions, specifying normal and alternative courses, defining system boundaries, or converting high-level business goals into engineering specifications.
|
|
4
|
+
version: "1.0.0"
|
|
4
5
|
allowed-tools: [read_file, write_file, edit_file, create_file, search_code, run_tests, run_linter, run_build, execute_command]
|
|
5
6
|
---
|
|
6
7
|
|