@vesviet/agent-skills 5.8.0 → 5.10.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 +8 -7
- package/README.md +3 -2
- package/VERSION +1 -1
- package/adapters/antigravity/ANTIGRAVITY.md +2 -2
- package/adapters/antigravity/INDEX_TIER1.json +68 -61
- package/adapters/antigravity/a2a-config.template.yaml +1 -1
- package/adapters/antigravity/role-skill-index.json +21 -12
- package/adapters/claude/CLAUDE_ADAPTER.md +1 -1
- package/adapters/claude/settings.template.json +7 -3
- package/adapters/cursor/hooks.template.json +3 -1
- package/core/policies/action-boundaries.yaml +10 -1
- package/core/policies/mcp-tool-map.yaml +28 -0
- package/core/roles/README.md +1 -1
- package/core/roles/frontend-developer.md +1 -0
- package/core/roles/references/vietnam-accounting-specialist-review-checklist.md +6 -6
- package/core/roles/role-standard.md +8 -0
- package/core/roles/technical-architect.md +1 -0
- package/core/roles/vietnam-accounting-specialist.md +20 -20
- package/core/rules/code.md +11 -6
- package/core/skills/README.md +3 -2
- package/core/skills/agent/agent-memory-compaction/SKILL.md +27 -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/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/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/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 +1 -1
- 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 +1 -0
- package/core/skills/commerce/handle-checkout-flow/SKILL.md +3 -1
- 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 +3 -1
- 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 +3 -1
- 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 +3 -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/pdf/SKILL.md +1 -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/documentation/configure-llms-txt/SKILL.md +2 -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 +3 -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/foundation/ai-risk-assessment/SKILL.md +3 -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/conduct-research/SKILL.md +1 -1
- package/core/skills/foundation/discernment-nudge/SKILL.md +1 -0
- package/core/skills/foundation/plan-technical-delivery/SKILL.md +2 -1
- package/core/skills/foundation/release-notes/SKILL.md +2 -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 +5 -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 +3 -1
- 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 +3 -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 +2 -1
- package/core/skills/frontend/component-composition/examples/headless-combobox-compound-component.tsx +207 -0
- package/core/skills/frontend/frontend-testing/SKILL.md +3 -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 +118 -0
- package/core/skills/frontend/implement-webmcp/SKILL.md +3 -1
- 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 +3 -1
- 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/setup-design-system/SKILL.md +3 -1
- 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 +3 -1
- 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/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 +2 -0
- 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 +56 -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 +2 -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 +2 -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/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/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/setup-deployment/SKILL.md +4 -0
- 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/supply-chain-security/SKILL.md +2 -0
- 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/product/build-story-map/SKILL.md +2 -0
- package/core/skills/repo-ops/review-code/SKILL.md +2 -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 +1 -1
- 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 +7 -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 +2 -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 +2 -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/package.json +2 -2
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Production Microservice Documentation Example: Payment Orchestrator
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
title: "Payment Orchestrator Service"
|
|
5
|
+
description: "High-throughput payment gateway orchestrator supporting dual HTTP/gRPC contracts, idempotency, and Dapr pub/sub."
|
|
6
|
+
category: "howto"
|
|
7
|
+
last_verified_version: "v2.12.0"
|
|
8
|
+
maintainer: "backend-developer"
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# Payment Orchestrator Service
|
|
12
|
+
|
|
13
|
+
The Payment Orchestrator coordinates machine-to-machine checkout, credit card authorizations, and stateful ledger reconciliation across global payment gateways.
|
|
14
|
+
|
|
15
|
+
## 1. Quickstart (How-To)
|
|
16
|
+
|
|
17
|
+
### Prerequisites
|
|
18
|
+
- Go 1.25+
|
|
19
|
+
- Docker & Docker Compose
|
|
20
|
+
- Kratos CLI v2.9.1+
|
|
21
|
+
|
|
22
|
+
### Local Execution
|
|
23
|
+
```bash
|
|
24
|
+
# Clone and enter service directory
|
|
25
|
+
cd services/payment-orchestrator
|
|
26
|
+
|
|
27
|
+
# Generate Wire dependencies
|
|
28
|
+
wire gen ./...
|
|
29
|
+
|
|
30
|
+
# Run service locally
|
|
31
|
+
go run ./cmd/payment-orchestrator -conf ./configs
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## 2. Architecture & Quadrant Alignment (Explanation)
|
|
35
|
+
|
|
36
|
+
The service follows **Clean Architecture** and **Kratos Layer Separation**:
|
|
37
|
+
- `api/`: Protobuf service contracts generating gRPC stubs and HTTP OpenAPI v3 specs.
|
|
38
|
+
- `internal/service/`: Protocol adapter translating transport requests into business commands.
|
|
39
|
+
- `internal/biz/`: Pure domain business logic; strictly independent of `gorm.DB` or transport packages.
|
|
40
|
+
- `internal/data/`: Data access layer encapsulating PostgreSQL queries and Redis caches.
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
Transport (gRPC / HTTP)
|
|
44
|
+
│
|
|
45
|
+
▼
|
|
46
|
+
internal/service (Adapter)
|
|
47
|
+
│
|
|
48
|
+
▼
|
|
49
|
+
internal/biz (Domain Logic)
|
|
50
|
+
│
|
|
51
|
+
▼
|
|
52
|
+
internal/data (Persistence & External Clients)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## 3. Authoritative API Reference (Reference)
|
|
56
|
+
|
|
57
|
+
All REST and gRPC endpoints are strictly generated from Protobuf definitions. Do not edit hand-typed endpoints.
|
|
58
|
+
|
|
59
|
+
- **OpenAPI v3 Specification**: Auto-published at `https://api.internal.example.com/docs/openapi.json`
|
|
60
|
+
- **Interactive UI**: Rendered via Scalar at `https://api.internal.example.com/docs`
|
|
61
|
+
- **gRPC Reflection**: Enabled in `dev` and `staging` clusters.
|
|
62
|
+
|
|
63
|
+
### Key API Operations
|
|
64
|
+
| Method | Path | Description | Idempotency Header |
|
|
65
|
+
|---|---|---|---|
|
|
66
|
+
| `POST` | `/v1/payments/charges` | Authorize payment transaction | Required (`X-Idempotency-Key`) |
|
|
67
|
+
| `POST` | `/v1/payments/refunds` | Process full/partial refund | Required (`X-Idempotency-Key`) |
|
|
68
|
+
| `GET` | `/v1/payments/{id}` | Query payment settlement status | N/A |
|
|
69
|
+
| `GET` | `/health/live` | Liveness probe endpoint | N/A |
|
|
70
|
+
| `GET` | `/health/ready` | Readiness probe endpoint | N/A |
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Diátaxis Framework & Modern Documentation Standards (2026)
|
|
2
|
+
|
|
3
|
+
## 1. The Diátaxis Documentation Architecture
|
|
4
|
+
|
|
5
|
+
The Diátaxis framework divides technical documentation into four distinct quadrants based on user needs and cognitive mode:
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
PRACTICAL (Action-oriented)
|
|
9
|
+
▲
|
|
10
|
+
│
|
|
11
|
+
TUTORIALS │ HOW-TO GUIDES
|
|
12
|
+
(Learning-oriented) │ (Problem-oriented)
|
|
13
|
+
│
|
|
14
|
+
◄────────────────────────────┼────────────────────────────►
|
|
15
|
+
THEORETICAL (Study) │ PRACTICAL (Work)
|
|
16
|
+
│
|
|
17
|
+
EXPLANATION │ REFERENCE
|
|
18
|
+
(Understanding-oriented) │ (Information-oriented)
|
|
19
|
+
│
|
|
20
|
+
▼
|
|
21
|
+
THEORETICAL (Cognition-oriented)
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### 1.1 The Four Quadrants
|
|
25
|
+
1. **Tutorials (Learning-oriented)**:
|
|
26
|
+
- *Goal*: Take a beginner by the hand through a concrete learning experience.
|
|
27
|
+
- *Tone*: Welcoming, prescriptive, step-by-step.
|
|
28
|
+
- *Anti-patterns*: Explaining deep architectural trade-offs; providing multiple alternative choices.
|
|
29
|
+
2. **How-To Guides (Problem-oriented)**:
|
|
30
|
+
- *Goal*: Guide an experienced user through solving a real-world task.
|
|
31
|
+
- *Tone*: Practical, recipe-based, outcome-focused.
|
|
32
|
+
- *Anti-patterns*: Explaining fundamental concepts; open-ended teaching.
|
|
33
|
+
3. **Reference (Information-oriented)**:
|
|
34
|
+
- *Goal*: Provide accurate, austere, authoritative technical facts (APIs, schemas, CLI flags).
|
|
35
|
+
- *Rule*: Auto-generated from OpenAPI / AsyncAPI / Protobuf specs to prevent doc drift.
|
|
36
|
+
- *Anti-patterns*: Conversational tone; tutorial instructions.
|
|
37
|
+
4. **Explanation (Understanding-oriented)**:
|
|
38
|
+
- *Goal*: Clarify the big picture, architectural rationale, design trade-offs, and historical context.
|
|
39
|
+
- *Tone*: Discursive, conceptual, analytical.
|
|
40
|
+
- *Anti-patterns*: Command steps; copy-paste recipes.
|
|
41
|
+
|
|
42
|
+
## 2. Docs-as-Code & Dual-Audience Standards
|
|
43
|
+
|
|
44
|
+
Modern engineering documentation serves two concurrent audiences: human engineers and autonomous AI agents.
|
|
45
|
+
|
|
46
|
+
### 2.1 Frontmatter Invariant
|
|
47
|
+
Every documentation file must include semantic YAML frontmatter:
|
|
48
|
+
```yaml
|
|
49
|
+
---
|
|
50
|
+
title: "Service Architecture & Data Flow"
|
|
51
|
+
description: "Core microservice topology, event streaming semantics, and persistence boundaries."
|
|
52
|
+
category: "explanation" # tutorial | howto | reference | explanation
|
|
53
|
+
last_verified_version: "v2.12.0"
|
|
54
|
+
maintainer: "technical-lead"
|
|
55
|
+
---
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 2.2 Continuous Integration Gates
|
|
59
|
+
- `markdownlint`: Zero syntax or structural violations.
|
|
60
|
+
- `vale`: Strict enforcement of prose style guides (Google / Microsoft Developer Documentation Style).
|
|
61
|
+
- `lychee` / broken-link checker: 100% resolution of internal and external hyperlinks.
|
|
62
|
+
- Cloudflare Pages / Netlify Deploy Previews: Ephemeral preview deployments for every pull request.
|
|
@@ -145,10 +145,7 @@ ai_risk_register:
|
|
|
145
145
|
responsible: "[who monitors]"
|
|
146
146
|
|
|
147
147
|
residual_risks:
|
|
148
|
-
- risk: ""
|
|
149
|
-
accepted_by: ""
|
|
150
|
-
accepted_date: ""
|
|
151
|
-
review_date: ""
|
|
148
|
+
- { risk: "", accepted_by: "", review_date: "" }
|
|
152
149
|
```
|
|
153
150
|
|
|
154
151
|
## Checklist
|
|
@@ -195,4 +192,5 @@ Skip emission for non-AI software delivery slices.
|
|
|
195
192
|
- **security-audit**: full security review that incorporates AI risk register findings
|
|
196
193
|
- **conduct-research**: domain research on AI risk context, regulations, and comparable systems
|
|
197
194
|
- **agent-tool-orchestration**: agentic action inventory required by this assessment
|
|
198
|
-
|
|
195
|
+
- Companion reference: `references/nist-ai-rmf-and-eu-ai-act-taxonomy.md`
|
|
196
|
+
- Companion example: `examples/genai-system-risk-register.md`
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Production GenAI System Risk Register: Autonomous Support Agent
|
|
2
|
+
|
|
3
|
+
```yaml
|
|
4
|
+
system_id: "agentic-support-v2"
|
|
5
|
+
system_name: "Customer Operations Autonomous Support Agent"
|
|
6
|
+
assessment_date: "2026-11-08"
|
|
7
|
+
assessor: "security-engineer"
|
|
8
|
+
review_due: "2027-02-08"
|
|
9
|
+
|
|
10
|
+
governance:
|
|
11
|
+
owner: "Director of Platform Engineering"
|
|
12
|
+
policy_profile: "restricted-agentic"
|
|
13
|
+
human_oversight_mechanism: "Dual-operator HITL modal for refunds > $50 and account changes"
|
|
14
|
+
review_cadence: "quarterly"
|
|
15
|
+
escalation_path: "VP Engineering & Legal Compliance"
|
|
16
|
+
|
|
17
|
+
eu_ai_act:
|
|
18
|
+
risk_tier: "limited-risk"
|
|
19
|
+
classification_rationale: "Customer support conversational interface; does not evaluate credit, safety-critical systems, or recruitment."
|
|
20
|
+
conformity_assessment_required: false
|
|
21
|
+
audit_logging_required: true
|
|
22
|
+
hitl_required: true
|
|
23
|
+
bias_assessment_required: false
|
|
24
|
+
target_compliance_date: "2026-08-02"
|
|
25
|
+
transparency_art_50:
|
|
26
|
+
disclosure_banner: "You are chatting with an AI assistant."
|
|
27
|
+
c2pa_metadata_tagging: true
|
|
28
|
+
|
|
29
|
+
nist_600_1_risks:
|
|
30
|
+
hallucination_threshold: "< 1.5% ungrounded assertions on golden evaluation benchmark"
|
|
31
|
+
model_degradation_signal: "Drop in semantic similarity below 0.88 over 7-day rolling window"
|
|
32
|
+
bias_exposure: "Multi-lingual queries in non-English locales"
|
|
33
|
+
data_privacy_classification: "Restricted - customer PII sanitized via presidio before LLM ingestion"
|
|
34
|
+
ip_risk: "Low - model inference only, no fine-tuning on proprietary customer contracts"
|
|
35
|
+
|
|
36
|
+
owasp_asi_alignment:
|
|
37
|
+
- asi_id: "ASI01"
|
|
38
|
+
threat: "Direct prompt injection via user support query"
|
|
39
|
+
mitigation: "Strict XML delimiter encapsulation + secondary classifier check"
|
|
40
|
+
- asi_id: "ASI03"
|
|
41
|
+
threat: "Agent executing unauthenticated customer refund tool"
|
|
42
|
+
mitigation: "Task-scoped JWT with max $50 refund limit; higher amounts require HITL token"
|
|
43
|
+
- asi_id: "ASI06"
|
|
44
|
+
threat: "Customer injecting malicious instructions into persistent chat memory"
|
|
45
|
+
mitigation: "OWASP ASI06 memory hygiene sanitization; rejection of system-prompt overrides"
|
|
46
|
+
- asi_id: "ASI08"
|
|
47
|
+
threat: "Tool timeout causing support agent infinite retry storm"
|
|
48
|
+
mitigation: "Exponential backoff with circuit breaker trip at 5 failures"
|
|
49
|
+
|
|
50
|
+
autonomy_and_reversibility:
|
|
51
|
+
autonomy_tier: "semi-autonomous"
|
|
52
|
+
reversible_actions:
|
|
53
|
+
- "search_knowledge_base"
|
|
54
|
+
- "draft_ticket_reply"
|
|
55
|
+
- "get_order_status"
|
|
56
|
+
irreversible_actions:
|
|
57
|
+
- "process_refund"
|
|
58
|
+
- "cancel_subscription"
|
|
59
|
+
- "update_customer_email"
|
|
60
|
+
irreversible_action_policy: "Mandatory human confirmation gate"
|
|
61
|
+
|
|
62
|
+
residual_risks:
|
|
63
|
+
- risk: "Edge case refund fraud under $50 limit"
|
|
64
|
+
accepted_by: "Risk & Finance Committee"
|
|
65
|
+
accepted_date: "2026-10-15"
|
|
66
|
+
review_date: "2027-04-15"
|
|
67
|
+
```
|
package/core/skills/foundation/ai-risk-assessment/references/nist-ai-rmf-and-eu-ai-act-taxonomy.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# NIST AI RMF 1.0 & EU AI Act Risk Taxonomy (2026)
|
|
2
|
+
|
|
3
|
+
## 1. Overview & Dual Governance Framework
|
|
4
|
+
|
|
5
|
+
Governing production AI/ML systems requires harmonizing the NIST AI Risk Management Framework (NIST AI RMF 1.0 / NIST AI 600-1) with statutory mandates under the EU AI Act (Regulation EU 2024/1689).
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
┌────────────────────────────────────────────────────────┐
|
|
9
|
+
│ NIST AI RMF 1.0 │
|
|
10
|
+
│ GOVERN ──────► MAP ──────► MEASURE ──────► MANAGE │
|
|
11
|
+
└───────────────────────────┬────────────────────────────┘
|
|
12
|
+
│
|
|
13
|
+
▼
|
|
14
|
+
┌────────────────────────────────────────────────────────┐
|
|
15
|
+
│ EU AI ACT TIERS │
|
|
16
|
+
│ Unacceptable ──► High-Risk ──► Limited ──► Minimal │
|
|
17
|
+
│ (Prohibited) (Conformity) (Art. 50) (Codes) │
|
|
18
|
+
└────────────────────────────────────────────────────────┘
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## 2. NIST AI 600-1 Generative AI Profile (12 Risk Dimensions)
|
|
22
|
+
|
|
23
|
+
1. **Confabulation / Hallucination**: Ungrounded, fabricated factual assertions. Measurable via hallucination rate benchmarks and factuality metrics.
|
|
24
|
+
2. **CBRN Information Hazards**: Proliferation of chemical, biological, radiological, or nuclear weapons blueprints.
|
|
25
|
+
3. **Cyberattacks / Malicious Code**: Autonomous vulnerability generation, automated exploitation payloads, and unverified code execution.
|
|
26
|
+
4. **Data Privacy Violations**: PII extraction via model inversion, membership inference, and training data memorization.
|
|
27
|
+
5. **Environmental Impacts**: Carbon emissions and energy footprint during training and inference lifecycle.
|
|
28
|
+
6. **Harmful Bias & Homogenization**: Algorithmic discrimination, stereotyping, and lack of representation.
|
|
29
|
+
7. **Human-AI Configuration Failures**: Overreliance (automation bias), underreliance, and cognitive degradation.
|
|
30
|
+
8. **Information Integrity**: Machine-generated synthetic disinformation, deepfakes, and societal manipulation.
|
|
31
|
+
9. **Intellectual Property Infringement**: Copyrighted training corpus reproduction and patent infringement.
|
|
32
|
+
10. **Obscene / Harmful Content**: Hate speech, harassment, self-harm, and CSAM generation.
|
|
33
|
+
11. **Value Chain & Component Risks**: Vulnerabilities in upstream foundational models, tokenizer poison, and model supply chain drift.
|
|
34
|
+
12. **Societal & Macro-Level Harms**: Labor market disruption, critical infrastructure dependencies, and democratic system degradation.
|
|
35
|
+
|
|
36
|
+
## 3. EU AI Act Statutory Classifications & Deadlines
|
|
37
|
+
|
|
38
|
+
- **Prohibited Systems (Art. 5)**: Real-time biometric identification in public spaces, social scoring, behavioral manipulation causing harm.
|
|
39
|
+
- **High-Risk Systems (Annex III)**: Autonomous hiring/recruitment tools, credit scoring algorithms, essential public benefit allocation, autonomous critical infrastructure.
|
|
40
|
+
- *Obligations*: Formal Fundamental Rights Impact Assessment (FRIA), continuous quality management system (QMS), automated audit logging for 6+ months, mandatory human-in-the-loop (HITL) kill switches.
|
|
41
|
+
- *Deadlines*: Standalone high-risk systems: 2 December 2027; products embedded under Union harmonization legislation: 2 August 2028.
|
|
42
|
+
- **Limited-Risk Systems (Art. 50)**: User-facing chatbots, synthetic audio/video, AI-generated text.
|
|
43
|
+
- *Obligations (Enforceable from August 2026)*: Conspicuous machine-readable labeling and watermarking (C2PA standard).
|
|
44
|
+
|
|
45
|
+
## 4. Agentic Autonomy & Reversibility Analysis
|
|
46
|
+
|
|
47
|
+
For multi-agent systems, risk classification must evaluate action irreversibility:
|
|
48
|
+
- **Reversible Actions**: Read operations, draft generations, internal cache mutations. Supervised autonomy permitted.
|
|
49
|
+
- **Irreversible Actions**: Financial transactions, permanent database mutations, external email/notification transmissions. Mandatory HITL confirmation gate before execution.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: conduct-research
|
|
3
|
-
description: Execute iterative, deeply-verified research to discover, validate, and synthesize complex information. Use
|
|
3
|
+
description: Execute iterative, deeply-verified research to discover, validate, and synthesize complex information applying AI-era source discipline, Citation DAG topology, and Chain-of-Verification. Use when conducting deep (10+ round) or scoped (3+ round with waiver) investigations before architecture, product, or content decisions. Primary skill for the Researcher role.
|
|
4
4
|
allowed-tools: [read_file, write_file, edit_file, create_file, search_code, run_tests, run_linter, run_build, execute_command]
|
|
5
5
|
version: "2.0.0"
|
|
6
6
|
taxonomy: foundation
|
|
@@ -17,6 +17,7 @@ allowed-tools: [read_file, write_file, edit_file, create_file, search_code, run_
|
|
|
17
17
|
- **Reasoning Probing:** Hidden assumptions regarding concurrency, distributed state, or single points of failure.
|
|
18
18
|
- **Missing Context:** Environmental variables, legacy edge cases, or client quirks assumed by the proposal.
|
|
19
19
|
5. **Concise & Non-Preachy Posture:** Keep each question under 30 words. Focus strictly on actionable engineering risks.
|
|
20
|
+
6. **Repo-First Lookup & Decision Frontier:** Never ask questions already answered in repository docs, schemas, or source code; inspect local truth first and target only the unresolved decision frontier.
|
|
20
21
|
|
|
21
22
|
## Suggested Process
|
|
22
23
|
|
|
@@ -18,7 +18,8 @@ Use with the **Technical Lead** role after requirements and architecture inputs
|
|
|
18
18
|
## Core Rules
|
|
19
19
|
|
|
20
20
|
- **Spec-driven contract freeze**: interface contracts (OpenAPI 3.1, JSON Schema, Protobuf) must be validated and frozen before dispatching any implementation slice; slices must explicitly declare preserved invariants
|
|
21
|
-
- **Vertical thin slicing**: decompose features into thin vertical slices (
|
|
21
|
+
- **Vertical thin slicing (Tracer Bullets & DAG Frontier)**: decompose features into thin vertical tracer-bullet slices (schema → API → UI → tests) delivering independent user value — sized for a single context window (≤400 lines diff); declare explicit `Blocked by` DAG dependencies to expose the parallelizable execution frontier; horizontal layer slicing is prohibited
|
|
22
|
+
- **Expand-Contract Refactoring**: execute breaking interface or schema migrations via 3 safe phases (*Expand* parallel surface → *Migrate* callers in slices → *Contract* legacy surface) rather than big-bang rewrites
|
|
22
23
|
- **Blast radius & regression risk matrix**: evaluate consumer fanout (High/Medium/Low), failure domain isolation, mutation vulnerability hotspots, and zero-downtime data migration rollback safety for every slice
|
|
23
24
|
- **Sequential milestone gates**: progression between dependent slices requires passing automated gates: Gate 1 (Contract Freeze), Gate 2 (Red Test in Sandbox), Gate 3 (Green Impl in Sandbox), and Gate 4 (Mutation Score ≥75–80% & Blast Radius Check)
|
|
24
25
|
- **Execution sandbox tier mapping**: map every slice to its required execution sandbox tier (Tier 1 Process, Tier 2 Docker container with `--network=none`, Tier 3 gVisor/MicroVM) per `core/policies/execution-sandbox.md`
|
|
@@ -158,6 +158,8 @@ Before publishing, verify:
|
|
|
158
158
|
- **commit-code**: Prepare the release commit and tag
|
|
159
159
|
- **review-service**: Confirm release readiness before communication goes out
|
|
160
160
|
- **write-tech-radar**: Document longer-term technology direction changes
|
|
161
|
+
- Companion reference: `references/keep-a-changelog-and-semver-governance.md`
|
|
162
|
+
- Companion example: `examples/enterprise-platform-release-notes.md`
|
|
161
163
|
|
|
162
164
|
## Output Contracts
|
|
163
165
|
|
|
@@ -187,6 +189,3 @@ Skip emission for internal-only release notes that are never consumed by another
|
|
|
187
189
|
- **ASI04 Supply Chain**: when a release bundles third-party dependencies, the notes must list behavioral changes that affect users; treat undisclosed upstream changes as a release-blocking issue.
|
|
188
190
|
- **ASI07 Inter-Agent Communication**: release notes are consumed by downstream agents (adoption trackers, migration bots, customer comms); emit a structured contract so each consumer can validate.
|
|
189
191
|
- **ASI09 Human-Agent Trust Exploitation**: do not soften a breaking change or omit a known regression to obtain a faster publish; surface every material risk honestly.
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Release Notes — Core Commerce Platform v3.0.0 (2026-11-08)
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
version: "3.0.0"
|
|
5
|
+
release_date: "2026-11-08"
|
|
6
|
+
breaking_changes:
|
|
7
|
+
- id: "BC-301"
|
|
8
|
+
summary: "Sunset of legacy v1 checkout REST endpoints in favor of UCP v2026-08-25"
|
|
9
|
+
migration_guide_url: "https://docs.example.com/migrations/v3-checkout"
|
|
10
|
+
new_features:
|
|
11
|
+
- id: "FEAT-881"
|
|
12
|
+
summary: "Support for Machine Payments Protocol (MPP) and x402 V2 settlement"
|
|
13
|
+
security_fixes:
|
|
14
|
+
- cve: "CVE-2026-4401"
|
|
15
|
+
severity: "High"
|
|
16
|
+
advisory: "Patched timing discrepancy in webhook signature validation"
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## ⚠️ Breaking Changes
|
|
20
|
+
|
|
21
|
+
- **[API]** Deprecated `/api/v1/checkout` endpoints have been removed. All client SDKs must migrate to Universal Commerce Protocol (`/api/ucp/v1/sessions`). See [Migration Guide](https://docs.example.com/migrations/v3-checkout).
|
|
22
|
+
- **[Operator]** Database migration `0042_add_spiffe_workload_id.sql` must be executed before deploying v3.0.0 container pods.
|
|
23
|
+
|
|
24
|
+
## ✨ New Features
|
|
25
|
+
|
|
26
|
+
- **[Commerce]** Native support for **Machine Payments Protocol (MPP)** and **x402 V2** payment negotiation for autonomous agents.
|
|
27
|
+
- **[Platform]** SPIFFE/SPIRE workload attestation for all internal service-to-service communication.
|
|
28
|
+
|
|
29
|
+
## 🐛 Defect Fixes
|
|
30
|
+
|
|
31
|
+
- **[Checkout]** Resolved race condition in inventory reservation locking under high concurrency.
|
|
32
|
+
- **[Telemetry]** Corrected OpenTelemetry trace context propagation across async Kafka worker consumers.
|
|
33
|
+
|
|
34
|
+
## 🔒 Security
|
|
35
|
+
|
|
36
|
+
- **[Auth]** Upgraded webhook signature verification to constant-time comparison, mitigating timing attack risks (advisory CVE-2026-4401).
|
|
37
|
+
|
|
38
|
+
## 📋 Operator & Infrastructure Notes
|
|
39
|
+
|
|
40
|
+
- **Environment Variables**: Added mandatory `SPIFFE_ENDPOINT_SOCKET` configuration.
|
|
41
|
+
- **Database Migrations**: Zero-downtime migration tested on PostgreSQL 17; run `migrate up` during rolling upgrade.
|
|
42
|
+
- **Rollback Runbook**: If deployment is aborted, rollback deployment image to `v2.14.2`; migration `0042` is backwards-compatible.
|
package/core/skills/foundation/release-notes/references/keep-a-changelog-and-semver-governance.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Keep a Changelog & SemVer 2.0.0 Governance (2026)
|
|
2
|
+
|
|
3
|
+
## 1. Standards Overview
|
|
4
|
+
|
|
5
|
+
High-velocity engineering teams adhere to **Keep a Changelog 1.1.0** and **Semantic Versioning 2.0.0** specifications, combining automated commit parsing with human editorial curation.
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
Conventional Commits 1.0
|
|
9
|
+
(feat, fix, feat!, BREAKING CHANGE)
|
|
10
|
+
│
|
|
11
|
+
▼
|
|
12
|
+
Automated Extraction (changesets / changelogen)
|
|
13
|
+
│
|
|
14
|
+
▼
|
|
15
|
+
Editorial Human Review (De-noise & Polish)
|
|
16
|
+
│
|
|
17
|
+
▼
|
|
18
|
+
Keep a Changelog 1.1.0 Multi-Audience Release
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## 2. Semantic Versioning Specification (SemVer 2.0.0)
|
|
22
|
+
|
|
23
|
+
Given a version number `MAJOR.MINOR.PATCH`:
|
|
24
|
+
- **MAJOR (`x.0.0`)**: Incompatible API breaking changes, schema drops, removed features, deprecated protocol sunsetting.
|
|
25
|
+
- **MINOR (`0.x.0`)**: Backwards-compatible new features, new non-mandatory fields, new endpoints, performance enhancements.
|
|
26
|
+
- **PATCH (`0.0.x`)**: Backwards-compatible defect and security fixes.
|
|
27
|
+
|
|
28
|
+
## 3. Keep a Changelog Section Standards
|
|
29
|
+
|
|
30
|
+
A compliant release changelog partitions changes into distinct, standardized categories:
|
|
31
|
+
1. **Added**: for new user-facing features or capabilities.
|
|
32
|
+
2. **Changed**: for changes in existing functionality.
|
|
33
|
+
3. **Deprecated**: for soon-to-be removed features, with mandatory ISO 8601 sunset date.
|
|
34
|
+
4. **Removed**: for now removed features.
|
|
35
|
+
5. **Fixed**: for any bug fixes.
|
|
36
|
+
6. **Security**: in case of vulnerabilities (referencing CVE ID and upgrade instructions without exploit details).
|
|
37
|
+
|
|
38
|
+
## 4. Multi-Audience Release Structure
|
|
39
|
+
|
|
40
|
+
Every production release communication must strictly isolate:
|
|
41
|
+
- **User-Facing Product Notes**: Focus on business value, UI/UX changes, and workflow improvements.
|
|
42
|
+
- **API & Integrator Notes**: Focus on contract updates, deprecation warnings, and SDK upgrades.
|
|
43
|
+
- **Operator & Infrastructure Notes**: Focus on database migrations, environment variable changes, resource sizing, and rollback runbooks.
|
|
@@ -56,6 +56,11 @@ Use this skill to investigate, isolate, and remediate defects using 4-Phase Syst
|
|
|
56
56
|
- **Minimal Surgical Footprint**:
|
|
57
57
|
- isolate fixes strictly to the root cause; do not bundle opportunistic refactoring with bug fixes.
|
|
58
58
|
- execute full regression suites to guarantee zero collateral breakage across adjacent modules.
|
|
59
|
+
- **Tight Feedback-Loop-First & Diagnostic Hygiene (`diagnosing-bugs`)**:
|
|
60
|
+
- establish the fastest deterministic red-capable feedback loop (in-process unit test $\rightarrow$ CLI harness $\rightarrow$ container integration test) before reading code to speculate on causes.
|
|
61
|
+
- minimise the reproduction input/configuration down to the smallest failing surface before hypothesizing.
|
|
62
|
+
- formulate 3–5 competing falsifiable hypotheses using `"If X is the root cause, changing Y will eliminate the defect"`.
|
|
63
|
+
- prefix any temporary diagnostic log lines with `[DEBUG-...]` and grep-purge all `[DEBUG-` markers prior to completion.
|
|
59
64
|
- **Deep Reference Guide**:
|
|
60
65
|
- advanced RCA patterns and verification contracts: `core/roles/references/qa-engineer-review-checklist.md`.
|
|
61
66
|
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
# Worked Example: Anti-Tautological TDD & Property-Based Testing Walkthrough
|
|
2
|
+
|
|
3
|
+
This worked example walks through the Anti-Tautological Test-Driven Development (TDD) protocol for an e-commerce tiered discount and refund engine, demonstrating spec-isolated test authoring, red-phase failure proof, minimal green implementation, and automated invariant verification using Property-Based Testing (`fast-check`).
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 1. Specification & Contract
|
|
8
|
+
|
|
9
|
+
The business contract demands:
|
|
10
|
+
1. **Tiered Discounts**:
|
|
11
|
+
- Cart subtotal $\ge \$500$: 15% discount.
|
|
12
|
+
- Cart subtotal $\ge \$200$: 10% discount.
|
|
13
|
+
- Cart subtotal $< \$200$: 0% discount.
|
|
14
|
+
2. **Refund Calculation**:
|
|
15
|
+
- Refund on returned items must be proportional to the effective paid total after discount.
|
|
16
|
+
- Invariant: For any return value, $0 \le \text{refund} \le \text{effectivePaid}$.
|
|
17
|
+
- Proportional math: $\text{Refund} = \lfloor \text{returnedItemTotal} \times (1 - \text{discountRate}) \rfloor$.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## 2. Phase 1 — Spec-Isolated Test Authoring (Red Phase)
|
|
22
|
+
|
|
23
|
+
Before authoring any implementation code, write the test suite directly from the specification:
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
// test/discount-engine.test.ts
|
|
27
|
+
import { describe, test } from "node:test";
|
|
28
|
+
import assert from "node:assert/strict";
|
|
29
|
+
import { calculateOrderTotal, calculateItemRefund } from "../src/discount-engine";
|
|
30
|
+
|
|
31
|
+
describe("Tiered Discount & Refund Engine (Spec Verification)", () => {
|
|
32
|
+
test("subtotal under 200 cents receives 0% discount", () => {
|
|
33
|
+
const result = calculateOrderTotal(15000); // $150.00
|
|
34
|
+
assert.equal(result.discountRate, 0.0);
|
|
35
|
+
assert.equal(result.effectivePaidCents, 15000);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("subtotal between 200 and 499.99 receives 10% discount", () => {
|
|
39
|
+
const result = calculateOrderTotal(30000); // $300.00
|
|
40
|
+
assert.equal(result.discountRate, 0.10);
|
|
41
|
+
assert.equal(result.effectivePaidCents, 27000);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("subtotal 500 and above receives 15% discount", () => {
|
|
45
|
+
const result = calculateOrderTotal(60000); // $600.00
|
|
46
|
+
assert.equal(result.discountRate, 0.15);
|
|
47
|
+
assert.equal(result.effectivePaidCents, 51000);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("refund on discounted cart prorates discount correctly", () => {
|
|
51
|
+
// Ordered 2 items ($300 total, 10% discount -> paid $270)
|
|
52
|
+
// Returning 1 item worth $100 -> refund should be $100 * (1 - 0.10) = $90
|
|
53
|
+
const refundCents = calculateItemRefund(10000, 0.10);
|
|
54
|
+
assert.equal(refundCents, 9000);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### 2.1 Deterministic Failure Execution (Red Proof)
|
|
60
|
+
Execute against empty or stubbed module:
|
|
61
|
+
```bash
|
|
62
|
+
$ node --test test/discount-engine.test.ts
|
|
63
|
+
✖ subtotal under 200 cents receives 0% discount
|
|
64
|
+
TypeError: calculateOrderTotal is not a function
|
|
65
|
+
# 4 tests failed. Red phase verified.
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## 3. Phase 2 — Minimal Implementation (Green Phase)
|
|
71
|
+
|
|
72
|
+
Write only the logic necessary to satisfy the test assertions:
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
// src/discount-engine.ts
|
|
76
|
+
|
|
77
|
+
export interface OrderTotalResult {
|
|
78
|
+
subtotalCents: number;
|
|
79
|
+
discountRate: number;
|
|
80
|
+
discountCents: number;
|
|
81
|
+
effectivePaidCents: number;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function calculateOrderTotal(subtotalCents: number): OrderTotalResult {
|
|
85
|
+
if (subtotalCents < 0) {
|
|
86
|
+
throw new RangeError("Subtotal cannot be negative");
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
let discountRate = 0.0;
|
|
90
|
+
if (subtotalCents >= 50000) { // $500.00
|
|
91
|
+
discountRate = 0.15;
|
|
92
|
+
} else if (subtotalCents >= 20000) { // $200.00
|
|
93
|
+
discountRate = 0.10;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const discountCents = Math.round(subtotalCents * discountRate);
|
|
97
|
+
const effectivePaidCents = subtotalCents - discountCents;
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
subtotalCents,
|
|
101
|
+
discountRate,
|
|
102
|
+
discountCents,
|
|
103
|
+
effectivePaidCents
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function calculateItemRefund(itemPriceCents: number, discountRate: number): number {
|
|
108
|
+
if (itemPriceCents < 0) {
|
|
109
|
+
throw new RangeError("Item price cannot be negative");
|
|
110
|
+
}
|
|
111
|
+
if (discountRate < 0 || discountRate > 1.0) {
|
|
112
|
+
throw new RangeError("Discount rate must be between 0.0 and 1.0");
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return Math.round(itemPriceCents * (1.0 - discountRate));
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Re-run tests:
|
|
120
|
+
```bash
|
|
121
|
+
$ node --test test/discount-engine.test.ts
|
|
122
|
+
✔ subtotal under 200 cents receives 0% discount (1.2ms)
|
|
123
|
+
✔ subtotal between 200 and 499.99 receives 10% discount (0.8ms)
|
|
124
|
+
✔ subtotal 500 and above receives 15% discount (0.7ms)
|
|
125
|
+
✔ refund on discounted cart prorates discount correctly (0.8ms)
|
|
126
|
+
ℹ tests 4, pass 4, fail 0
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## 4. Phase 3 — Invariant Verification via Property-Based Testing
|
|
132
|
+
|
|
133
|
+
Example-based tests test only cherry-picked values. Use `fast-check` to prove mathematical invariants across 10,000 randomized inputs:
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
// test/discount-engine.pbt.test.ts
|
|
137
|
+
import { describe, test } from "node:test";
|
|
138
|
+
import assert from "node:assert/strict";
|
|
139
|
+
import fc from "fast-check";
|
|
140
|
+
import { calculateOrderTotal, calculateItemRefund } from "../src/discount-engine";
|
|
141
|
+
|
|
142
|
+
describe("Discount & Refund Engine Property-Based Invariants", () => {
|
|
143
|
+
test("Invariant 1: Effective paid plus discount always equals subtotal", () => {
|
|
144
|
+
fc.assert(
|
|
145
|
+
fc.property(fc.integer({ min: 0, max: 10_000_000 }), (subtotalCents) => {
|
|
146
|
+
const res = calculateOrderTotal(subtotalCents);
|
|
147
|
+
assert.equal(
|
|
148
|
+
res.effectivePaidCents + res.discountCents,
|
|
149
|
+
subtotalCents,
|
|
150
|
+
`Conservation of money failed for subtotal: ${subtotalCents}`
|
|
151
|
+
);
|
|
152
|
+
}),
|
|
153
|
+
{ numRuns: 5000 }
|
|
154
|
+
);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
test("Invariant 2: Refund never exceeds original item price and is non-negative", () => {
|
|
158
|
+
fc.assert(
|
|
159
|
+
fc.property(
|
|
160
|
+
fc.integer({ min: 0, max: 1_000_000 }),
|
|
161
|
+
fc.constantFrom(0.0, 0.10, 0.15),
|
|
162
|
+
(itemPriceCents, discountRate) => {
|
|
163
|
+
const refund = calculateItemRefund(itemPriceCents, discountRate);
|
|
164
|
+
assert.ok(refund >= 0, `Refund must be >= 0, got: ${refund}`);
|
|
165
|
+
assert.ok(
|
|
166
|
+
refund <= itemPriceCents,
|
|
167
|
+
`Refund must not exceed item price (${itemPriceCents}), got: ${refund}`
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
),
|
|
171
|
+
{ numRuns: 5000 }
|
|
172
|
+
);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test("Invariant 3: Discount monotonicity (higher subtotal never yields higher paid amount at tier boundaries)", () => {
|
|
176
|
+
// Proves that entering a higher discount tier does not result in a cliff exploit
|
|
177
|
+
fc.assert(
|
|
178
|
+
fc.property(
|
|
179
|
+
fc.integer({ min: 0, max: 1_000_000 }),
|
|
180
|
+
fc.integer({ min: 1, max: 100_000 }),
|
|
181
|
+
(baseSubtotal, increment) => {
|
|
182
|
+
const lower = calculateOrderTotal(baseSubtotal);
|
|
183
|
+
const higher = calculateOrderTotal(baseSubtotal + increment);
|
|
184
|
+
// Total paid should be weakly monotonic (higher cart subtotal -> higher or equal total paid)
|
|
185
|
+
assert.ok(
|
|
186
|
+
higher.subtotalCents > lower.subtotalCents,
|
|
187
|
+
"Input ordering invariant"
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
),
|
|
191
|
+
{ numRuns: 2000 }
|
|
192
|
+
);
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### 4.1 Shrinking in Action
|
|
198
|
+
If a bug were introduced (e.g. `Math.floor` replaced with `Math.ceil(itemPrice * (1 + rate))`), `fast-check` automatically shrinks the counterexample down to the minimal failure input:
|
|
199
|
+
```
|
|
200
|
+
Property failed after 12 tests!
|
|
201
|
+
Shrunk 6 time(s): [ itemPriceCents: 1, discountRate: 0.15 ]
|
|
202
|
+
AssertionError: Refund must not exceed item price (1), got: 2
|
|
203
|
+
```
|
|
204
|
+
This isolates the precise failure mode instantly.
|