special-agents 0.1.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/README.md +69 -0
- package/content/agents/builder.yaml +25 -0
- package/content/agents/planner.yaml +13 -0
- package/content/agents/qa.yaml +16 -0
- package/content/agents/ticket-maker.yaml +11 -0
- package/content/defaults.yaml +13 -0
- package/content/docs/README.md +42 -0
- package/content/docs/admins.md +46 -0
- package/content/docs/ai-costs.md +38 -0
- package/content/docs/ai-evals.md +55 -0
- package/content/docs/ai.md +141 -0
- package/content/docs/api.md +51 -0
- package/content/docs/architecture.md +61 -0
- package/content/docs/business.md +49 -0
- package/content/docs/data-governance.md +67 -0
- package/content/docs/decisions/0000-template.md +29 -0
- package/content/docs/decisions/README.md +30 -0
- package/content/docs/docs.index.yaml +25 -0
- package/content/docs/features.md +41 -0
- package/content/docs/local-cloud.md +58 -0
- package/content/docs/operations.md +69 -0
- package/content/docs/release-checklist.md +56 -0
- package/content/docs/scalability.md +81 -0
- package/content/docs/security.md +82 -0
- package/content/docs/tickets.md +45 -0
- package/content/docs/users.md +43 -0
- package/content/preamble.md +13 -0
- package/content/rules/base/code-quality.md +20 -0
- package/content/rules/base/core.md +17 -0
- package/content/rules/base/definition-of-done.md +21 -0
- package/content/rules/base/git-safety.md +16 -0
- package/content/rules/base/response-expectations.md +18 -0
- package/content/rules/domain/accessibility.md +14 -0
- package/content/rules/domain/ai-cost.md +21 -0
- package/content/rules/domain/ai-evals.md +25 -0
- package/content/rules/domain/ai-governance.md +16 -0
- package/content/rules/domain/ai-reproducibility.md +19 -0
- package/content/rules/domain/ai-safety.md +19 -0
- package/content/rules/domain/data-governance.md +17 -0
- package/content/rules/domain/observability.md +18 -0
- package/content/rules/domain/robustness.md +21 -0
- package/content/rules/domain/scalability.md +18 -0
- package/content/rules/domain/security.md +28 -0
- package/content/rules/packs.index.yaml +177 -0
- package/content/rules/process/api-docs.md +16 -0
- package/content/rules/process/architecture.md +14 -0
- package/content/rules/process/business-docs.md +13 -0
- package/content/rules/process/ci.md +18 -0
- package/content/rules/process/dependencies.md +17 -0
- package/content/rules/process/project-docs.md +35 -0
- package/content/rules/process/release.md +16 -0
- package/content/rules/process/tdd.md +16 -0
- package/content/rules/process/testing.md +28 -0
- package/content/rules/process/tickets.md +17 -0
- package/content/rules/templated/database.md +16 -0
- package/content/rules/templated/infra.md +18 -0
- package/content/rules/templated/stack.md +19 -0
- package/content/skills/better-sqlite3-rebuild/SKILL.md +14 -0
- package/content/skills/grill-me/SKILL.md +10 -0
- package/content/skills/improve-codebase-architecture/REFERENCE.md +78 -0
- package/content/skills/improve-codebase-architecture/SKILL.md +76 -0
- package/content/skills/prd-to-issues/SKILL.md +92 -0
- package/content/skills/tdd/SKILL.md +107 -0
- package/content/skills/tdd/deep-modules.md +33 -0
- package/content/skills/tdd/interface-design.md +31 -0
- package/content/skills/tdd/mocking.md +59 -0
- package/content/skills/tdd/refactoring.md +10 -0
- package/content/skills/tdd/tests.md +61 -0
- package/content/skills/write-a-prd/SKILL.md +74 -0
- package/dist/agents.d.ts +11 -0
- package/dist/agents.js +31 -0
- package/dist/compile.d.ts +79 -0
- package/dist/compile.js +113 -0
- package/dist/content.d.ts +49 -0
- package/dist/content.js +73 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +12 -0
- package/dist/resolve.d.ts +46 -0
- package/dist/resolve.js +54 -0
- package/dist/skills.d.ts +11 -0
- package/dist/skills.js +45 -0
- package/dist/template.d.ts +22 -0
- package/dist/template.js +34 -0
- package/node_modules/rafi-spec/dist/index.d.ts +4 -0
- package/node_modules/rafi-spec/dist/index.js +4 -0
- package/node_modules/rafi-spec/dist/schemas.d.ts +185 -0
- package/node_modules/rafi-spec/dist/schemas.js +95 -0
- package/node_modules/rafi-spec/dist/types.d.ts +111 -0
- package/node_modules/rafi-spec/dist/types.js +6 -0
- package/node_modules/rafi-spec/dist/validate.d.ts +16 -0
- package/node_modules/rafi-spec/dist/validate.js +40 -0
- package/node_modules/rafi-spec/package.json +35 -0
- package/node_modules/rafi-spec/src/index.ts +19 -0
- package/node_modules/rafi-spec/src/schemas.ts +102 -0
- package/node_modules/rafi-spec/src/types.ts +134 -0
- package/node_modules/rafi-spec/src/validate.ts +60 -0
- package/package.json +39 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: tickets
|
|
3
|
+
category: process
|
|
4
|
+
description: "Ticket log expectations when no external tracker is configured."
|
|
5
|
+
condition: always
|
|
6
|
+
template: false
|
|
7
|
+
supersededByForeman: true
|
|
8
|
+
---
|
|
9
|
+
## Ticket Tracking
|
|
10
|
+
|
|
11
|
+
- Maintain `docs/tickets.md` as the source of truth if no external tracker is configured.
|
|
12
|
+
- Break work into epics, stories, and implementation tickets where useful.
|
|
13
|
+
- Every ticket should include: ID, title, status, priority, user/business value, acceptance criteria, implementation notes, test expectations, and links to related docs or code when available.
|
|
14
|
+
- Valid statuses: `Backlog`, `Ready`, `In Progress`, `Blocked`, `In Review`, `Done`, `Won't Do`.
|
|
15
|
+
- Add discovered follow-up work, deferred improvements, risks, and future ideas to the ticket log instead of leaving them only in chat.
|
|
16
|
+
- When completing a ticket, mark it `Done` and summarize what changed.
|
|
17
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: database
|
|
3
|
+
category: templated
|
|
4
|
+
description: "Database defaults, migrations, and boundary validation."
|
|
5
|
+
condition: always
|
|
6
|
+
template: true
|
|
7
|
+
---
|
|
8
|
+
## Data And Database Rules
|
|
9
|
+
|
|
10
|
+
- Use {{database}} by default.
|
|
11
|
+
- Use migrations for schema changes. Do not rely on manual database edits.
|
|
12
|
+
- Keep migrations reviewable and, where practical, reversible.
|
|
13
|
+
- Update seed data, fixtures, and `.env.example` when schema or setup requirements change.
|
|
14
|
+
- Validate data at system boundaries and before persistence.
|
|
15
|
+
- Document important entities and relationships in `docs/architecture.md`.
|
|
16
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: infra
|
|
3
|
+
category: templated
|
|
4
|
+
description: "Local/cloud runtime parity and infrastructure-as-code expectations."
|
|
5
|
+
condition: cloud
|
|
6
|
+
template: true
|
|
7
|
+
---
|
|
8
|
+
## Infrastructure And Local/Cloud Runtime
|
|
9
|
+
|
|
10
|
+
- Unless otherwise noted, build applications to run locally and in the cloud.
|
|
11
|
+
- Keep local and cloud environments as similar as practical while documenting intentional differences.
|
|
12
|
+
- Provide a local runtime path using Docker Compose, local services, scripts, or equivalent tooling when the app has service dependencies.
|
|
13
|
+
- Keep `.env.example`, setup docs, seed data, and local database instructions current.
|
|
14
|
+
- Define cloud infrastructure with Infrastructure as Code such as AWS CDK, Terraform, Pulumi, or CloudFormation unless there is a documented reason not to.
|
|
15
|
+
- Avoid manual cloud console changes for durable infrastructure. If manual changes are unavoidable, document them and add follow-up work to codify them.
|
|
16
|
+
- Document {{cloud}} account/region assumptions, IAM model, networking, secrets, storage, databases, queues, observability, and deployment flow in `docs/local-cloud.md`, `docs/architecture.md`, or `docs/operations.md`.
|
|
17
|
+
- Consult the user when local/cloud runtime expectations, hosting constraints, or infrastructure ownership are unclear.
|
|
18
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: stack
|
|
3
|
+
category: templated
|
|
4
|
+
description: "Default stack choices (package manager, frontend, backend, database, cloud)."
|
|
5
|
+
condition: always
|
|
6
|
+
template: true
|
|
7
|
+
---
|
|
8
|
+
## Default Stack
|
|
9
|
+
|
|
10
|
+
- Default package manager: `{{packageManager}}`.
|
|
11
|
+
- Default database: {{database}}.
|
|
12
|
+
- Default frontend: {{frontend}}.
|
|
13
|
+
- Unless the user explicitly says otherwise, plan to build a UI for the app. Do not assume an app is API-only, CLI-only, or backend-only.
|
|
14
|
+
- Default backend: {{backend}}.
|
|
15
|
+
- Default cloud infrastructure: {{cloud}}. Suggest another cloud provider when it is clearly more optimal for cost, product fit, compliance, operations, or team constraints.
|
|
16
|
+
- Unless otherwise noted, build applications so they can run both locally and in the cloud. Consult the user if local/cloud runtime expectations are unclear.
|
|
17
|
+
- If planning selects a different stack, update this rule file and the architecture docs to reflect that choice.
|
|
18
|
+
- Prefer TypeScript for JavaScript projects unless the project explicitly chooses otherwise.
|
|
19
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: better-sqlite3-rebuild
|
|
3
|
+
description: Use when seeing errors about better-sqlite3 native module, NODE_MODULE_VERSION mismatch, "was compiled against a different Node.js version", or similar native binding errors.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# better-sqlite3 Rebuild
|
|
7
|
+
|
|
8
|
+
When you encounter errors related to `better-sqlite3` and Node.js version mismatches (e.g. `NODE_MODULE_VERSION` mismatch, "was compiled against a different Node.js version", native module load failures), proactively fix by running:
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
npm rebuild
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Do this without asking the user first - just rebuild and retry.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: grill-me
|
|
3
|
+
description: Interview the user relentlessly about a plan or design until reaching shared understanding, resolving each branch of the decision tree. Use when user wants to stress-test a plan, get grilled on their design, or mentions "grill me".
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Interview me relentlessly about every aspect of this plan until we reach a shared understanding. Walk down each branch of the design tree, resolving dependencies between decisions one-by-one. For each question, provide your recommended answer.
|
|
7
|
+
|
|
8
|
+
Ask the questions one at a time.
|
|
9
|
+
|
|
10
|
+
If a question can be answered by exploring the codebase, explore the codebase instead.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# Reference
|
|
2
|
+
|
|
3
|
+
## Dependency Categories
|
|
4
|
+
|
|
5
|
+
When assessing a candidate for deepening, classify its dependencies:
|
|
6
|
+
|
|
7
|
+
### 1. In-process
|
|
8
|
+
|
|
9
|
+
Pure computation, in-memory state, no I/O. Always deepenable — just merge the modules and test directly.
|
|
10
|
+
|
|
11
|
+
### 2. Local-substitutable
|
|
12
|
+
|
|
13
|
+
Dependencies that have local test stand-ins (e.g., PGLite for Postgres, in-memory filesystem). Deepenable if the test substitute exists. The deepened module is tested with the local stand-in running in the test suite.
|
|
14
|
+
|
|
15
|
+
### 3. Remote but owned (Ports & Adapters)
|
|
16
|
+
|
|
17
|
+
Your own services across a network boundary (microservices, internal APIs). Define a port (interface) at the module boundary. The deep module owns the logic; the transport is injected. Tests use an in-memory adapter. Production uses the real HTTP/gRPC/queue adapter.
|
|
18
|
+
|
|
19
|
+
Recommendation shape: "Define a shared interface (port), implement an HTTP adapter for production and an in-memory adapter for testing, so the logic can be tested as one deep module even though it's deployed across a network boundary."
|
|
20
|
+
|
|
21
|
+
### 4. True external (Mock)
|
|
22
|
+
|
|
23
|
+
Third-party services (Stripe, Twilio, etc.) you don't control. Mock at the boundary. The deepened module takes the external dependency as an injected port, and tests provide a mock implementation.
|
|
24
|
+
|
|
25
|
+
## Testing Strategy
|
|
26
|
+
|
|
27
|
+
The core principle: **replace, don't layer.**
|
|
28
|
+
|
|
29
|
+
- Old unit tests on shallow modules are waste once boundary tests exist — delete them
|
|
30
|
+
- Write new tests at the deepened module's interface boundary
|
|
31
|
+
- Tests assert on observable outcomes through the public interface, not internal state
|
|
32
|
+
- Tests should survive internal refactors — they describe behavior, not implementation
|
|
33
|
+
|
|
34
|
+
## Issue Template
|
|
35
|
+
|
|
36
|
+
<issue-template>
|
|
37
|
+
|
|
38
|
+
## Problem
|
|
39
|
+
|
|
40
|
+
Describe the architectural friction:
|
|
41
|
+
|
|
42
|
+
- Which modules are shallow and tightly coupled
|
|
43
|
+
- What integration risk exists in the seams between them
|
|
44
|
+
- Why this makes the codebase harder to navigate and maintain
|
|
45
|
+
|
|
46
|
+
## Proposed Interface
|
|
47
|
+
|
|
48
|
+
The chosen interface design:
|
|
49
|
+
|
|
50
|
+
- Interface signature (types, methods, params)
|
|
51
|
+
- Usage example showing how callers use it
|
|
52
|
+
- What complexity it hides internally
|
|
53
|
+
|
|
54
|
+
## Dependency Strategy
|
|
55
|
+
|
|
56
|
+
Which category applies and how dependencies are handled:
|
|
57
|
+
|
|
58
|
+
- **In-process**: merged directly
|
|
59
|
+
- **Local-substitutable**: tested with [specific stand-in]
|
|
60
|
+
- **Ports & adapters**: port definition, production adapter, test adapter
|
|
61
|
+
- **Mock**: mock boundary for external services
|
|
62
|
+
|
|
63
|
+
## Testing Strategy
|
|
64
|
+
|
|
65
|
+
- **New boundary tests to write**: describe the behaviors to verify at the interface
|
|
66
|
+
- **Old tests to delete**: list the shallow module tests that become redundant
|
|
67
|
+
- **Test environment needs**: any local stand-ins or adapters required
|
|
68
|
+
|
|
69
|
+
## Implementation Recommendations
|
|
70
|
+
|
|
71
|
+
Durable architectural guidance that is NOT coupled to current file paths:
|
|
72
|
+
|
|
73
|
+
- What the module should own (responsibilities)
|
|
74
|
+
- What it should hide (implementation details)
|
|
75
|
+
- What it should expose (the interface contract)
|
|
76
|
+
- How callers should migrate to the new interface
|
|
77
|
+
|
|
78
|
+
</issue-template>
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: improve-codebase-architecture
|
|
3
|
+
description: Explore a codebase to find opportunities for architectural improvement, focusing on making the codebase more testable by deepening shallow modules. Use when user wants to improve architecture, find refactoring opportunities, consolidate tightly-coupled modules, or make a codebase more AI-navigable.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Improve Codebase Architecture
|
|
7
|
+
|
|
8
|
+
Explore a codebase like an AI would, surface architectural friction, discover opportunities for improving testability, and propose module-deepening refactors as GitHub issue RFCs.
|
|
9
|
+
|
|
10
|
+
A **deep module** (John Ousterhout, "A Philosophy of Software Design") has a small interface hiding a large implementation. Deep modules are more testable, more AI-navigable, and let you test at the boundary instead of inside.
|
|
11
|
+
|
|
12
|
+
## Process
|
|
13
|
+
|
|
14
|
+
### 1. Explore the codebase
|
|
15
|
+
|
|
16
|
+
Use the Agent tool with subagent_type=Explore to navigate the codebase naturally. Do NOT follow rigid heuristics — explore organically and note where you experience friction:
|
|
17
|
+
|
|
18
|
+
- Where does understanding one concept require bouncing between many small files?
|
|
19
|
+
- Where are modules so shallow that the interface is nearly as complex as the implementation?
|
|
20
|
+
- Where have pure functions been extracted just for testability, but the real bugs hide in how they're called?
|
|
21
|
+
- Where do tightly-coupled modules create integration risk in the seams between them?
|
|
22
|
+
- Which parts of the codebase are untested, or hard to test?
|
|
23
|
+
|
|
24
|
+
The friction you encounter IS the signal.
|
|
25
|
+
|
|
26
|
+
### 2. Present candidates
|
|
27
|
+
|
|
28
|
+
Present a numbered list of deepening opportunities. For each candidate, show:
|
|
29
|
+
|
|
30
|
+
- **Cluster**: Which modules/concepts are involved
|
|
31
|
+
- **Why they're coupled**: Shared types, call patterns, co-ownership of a concept
|
|
32
|
+
- **Dependency category**: See [REFERENCE.md](REFERENCE.md) for the four categories
|
|
33
|
+
- **Test impact**: What existing tests would be replaced by boundary tests
|
|
34
|
+
|
|
35
|
+
Do NOT propose interfaces yet. Ask the user: "Which of these would you like to explore?"
|
|
36
|
+
|
|
37
|
+
### 3. User picks a candidate
|
|
38
|
+
|
|
39
|
+
### 4. Frame the problem space
|
|
40
|
+
|
|
41
|
+
Before spawning sub-agents, write a user-facing explanation of the problem space for the chosen candidate:
|
|
42
|
+
|
|
43
|
+
- The constraints any new interface would need to satisfy
|
|
44
|
+
- The dependencies it would need to rely on
|
|
45
|
+
- A rough illustrative code sketch to make the constraints concrete — this is not a proposal, just a way to ground the constraints
|
|
46
|
+
|
|
47
|
+
Show this to the user, then immediately proceed to Step 5. The user reads and thinks about the problem while the sub-agents work in parallel.
|
|
48
|
+
|
|
49
|
+
### 5. Design multiple interfaces
|
|
50
|
+
|
|
51
|
+
Spawn 3+ sub-agents in parallel using the Agent tool. Each must produce a **radically different** interface for the deepened module.
|
|
52
|
+
|
|
53
|
+
Prompt each sub-agent with a separate technical brief (file paths, coupling details, dependency category, what's being hidden). This brief is independent of the user-facing explanation in Step 4. Give each agent a different design constraint:
|
|
54
|
+
|
|
55
|
+
- Agent 1: "Minimize the interface — aim for 1-3 entry points max"
|
|
56
|
+
- Agent 2: "Maximize flexibility — support many use cases and extension"
|
|
57
|
+
- Agent 3: "Optimize for the most common caller — make the default case trivial"
|
|
58
|
+
- Agent 4 (if applicable): "Design around the ports & adapters pattern for cross-boundary dependencies"
|
|
59
|
+
|
|
60
|
+
Each sub-agent outputs:
|
|
61
|
+
|
|
62
|
+
1. Interface signature (types, methods, params)
|
|
63
|
+
2. Usage example showing how callers use it
|
|
64
|
+
3. What complexity it hides internally
|
|
65
|
+
4. Dependency strategy (how deps are handled — see [REFERENCE.md](REFERENCE.md))
|
|
66
|
+
5. Trade-offs
|
|
67
|
+
|
|
68
|
+
Present designs sequentially, then compare them in prose.
|
|
69
|
+
|
|
70
|
+
After comparing, give your own recommendation: which design you think is strongest and why. If elements from different designs would combine well, propose a hybrid. Be opinionated — the user wants a strong read, not just a menu.
|
|
71
|
+
|
|
72
|
+
### 6. User picks an interface (or accepts recommendation)
|
|
73
|
+
|
|
74
|
+
### 7. Write issue file
|
|
75
|
+
|
|
76
|
+
Write the refactor RFC as a local markdown file in `issues/` using the template in [REFERENCE.md](REFERENCE.md). Do NOT ask the user to review before writing — just write it and share the path.
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: prd-to-issues
|
|
3
|
+
description: Break a PRD into independently-workable issues and write each as a local markdown file in issues/. Use when the user wants to turn a PRD into a list of concrete tasks.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# PRD to Issues
|
|
7
|
+
|
|
8
|
+
Break a PRD into independently-grabbable issues using vertical slices (tracer bullets), written as local markdown files.
|
|
9
|
+
|
|
10
|
+
## Process
|
|
11
|
+
|
|
12
|
+
### 1. Locate the PRD
|
|
13
|
+
|
|
14
|
+
Ask the user for the PRD file path (e.g. `issues/prd.md`).
|
|
15
|
+
|
|
16
|
+
If the PRD is not already in your context window, read it from the file.
|
|
17
|
+
|
|
18
|
+
### 2. Explore the codebase (optional)
|
|
19
|
+
|
|
20
|
+
If you have not already explored the codebase, do so to understand the current state of the code.
|
|
21
|
+
|
|
22
|
+
### 3. Draft vertical slices
|
|
23
|
+
|
|
24
|
+
Break the PRD into **tracer bullet** issues. Each issue is a thin vertical slice that cuts through ALL integration layers end-to-end, NOT a horizontal slice of one layer.
|
|
25
|
+
|
|
26
|
+
Slices may be 'HITL' or 'AFK'. HITL slices require human interaction, such as an architectural decision or a design review. AFK slices can be implemented and merged without human interaction. Prefer AFK over HITL where possible.
|
|
27
|
+
|
|
28
|
+
<vertical-slice-rules>
|
|
29
|
+
- Each slice delivers a narrow but COMPLETE path through every layer (schema, API, UI, tests)
|
|
30
|
+
- A completed slice is demoable or verifiable on its own
|
|
31
|
+
- Prefer many thin slices over few thick ones
|
|
32
|
+
</vertical-slice-rules>
|
|
33
|
+
|
|
34
|
+
### 4. Quiz the user
|
|
35
|
+
|
|
36
|
+
Present the proposed breakdown as a numbered list. For each slice, show:
|
|
37
|
+
|
|
38
|
+
- **Title**: short descriptive name
|
|
39
|
+
- **Type**: HITL / AFK
|
|
40
|
+
- **Blocked by**: which other slices (if any) must complete first
|
|
41
|
+
- **User stories covered**: which user stories from the PRD this addresses
|
|
42
|
+
|
|
43
|
+
Ask the user:
|
|
44
|
+
|
|
45
|
+
- Does the granularity feel right? (too coarse / too fine)
|
|
46
|
+
- Are the dependency relationships correct?
|
|
47
|
+
- Should any slices be merged or split further?
|
|
48
|
+
- Are the correct slices marked as HITL and AFK?
|
|
49
|
+
|
|
50
|
+
Iterate until the user approves the breakdown.
|
|
51
|
+
|
|
52
|
+
### 5. Create the issue files
|
|
53
|
+
|
|
54
|
+
For each approved slice, write a markdown file in `issues/` using the naming pattern `issues/NNN-short-title.md` (e.g. `issues/001-add-user-auth.md`).
|
|
55
|
+
|
|
56
|
+
Number issues starting from the next available number (check what files already exist in `issues/`).
|
|
57
|
+
|
|
58
|
+
Create files in dependency order (blockers first) so you can reference real filenames in the "Blocked by" field.
|
|
59
|
+
|
|
60
|
+
Do NOT use `gh issue create` or any GitHub CLI commands. Do NOT reference GitHub issue numbers. Use local filenames for all cross-references.
|
|
61
|
+
|
|
62
|
+
<issue-template>
|
|
63
|
+
## Parent PRD
|
|
64
|
+
|
|
65
|
+
`issues/prd.md` (or whichever PRD file was used)
|
|
66
|
+
|
|
67
|
+
## What to build
|
|
68
|
+
|
|
69
|
+
A concise description of this vertical slice. Describe the end-to-end behavior, not layer-by-layer implementation. Reference specific sections of the parent PRD rather than duplicating content.
|
|
70
|
+
|
|
71
|
+
## Acceptance criteria
|
|
72
|
+
|
|
73
|
+
- [ ] Criterion 1
|
|
74
|
+
- [ ] Criterion 2
|
|
75
|
+
- [ ] Criterion 3
|
|
76
|
+
|
|
77
|
+
## Blocked by
|
|
78
|
+
|
|
79
|
+
- Blocked by `issues/NNN-title.md` (if any)
|
|
80
|
+
|
|
81
|
+
Or "None - can start immediately" if no blockers.
|
|
82
|
+
|
|
83
|
+
## User stories addressed
|
|
84
|
+
|
|
85
|
+
Reference by number from the parent PRD:
|
|
86
|
+
|
|
87
|
+
- User story 3
|
|
88
|
+
- User story 7
|
|
89
|
+
|
|
90
|
+
</issue-template>
|
|
91
|
+
|
|
92
|
+
Do NOT close or modify the parent PRD file.
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: tdd
|
|
3
|
+
description: Test-driven development with red-green-refactor loop. Use when user wants to build features or fix bugs using TDD, mentions "red-green-refactor", wants integration tests, or asks for test-first development.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Test-Driven Development
|
|
7
|
+
|
|
8
|
+
## Philosophy
|
|
9
|
+
|
|
10
|
+
**Core principle**: Tests should verify behavior through public interfaces, not implementation details. Code can change entirely; tests shouldn't.
|
|
11
|
+
|
|
12
|
+
**Good tests** are integration-style: they exercise real code paths through public APIs. They describe _what_ the system does, not _how_ it does it. A good test reads like a specification - "user can checkout with valid cart" tells you exactly what capability exists. These tests survive refactors because they don't care about internal structure.
|
|
13
|
+
|
|
14
|
+
**Bad tests** are coupled to implementation. They mock internal collaborators, test private methods, or verify through external means (like querying a database directly instead of using the interface). The warning sign: your test breaks when you refactor, but behavior hasn't changed. If you rename an internal function and tests fail, those tests were testing implementation, not behavior.
|
|
15
|
+
|
|
16
|
+
See [tests.md](tests.md) for examples and [mocking.md](mocking.md) for mocking guidelines.
|
|
17
|
+
|
|
18
|
+
## Anti-Pattern: Horizontal Slices
|
|
19
|
+
|
|
20
|
+
**DO NOT write all tests first, then all implementation.** This is "horizontal slicing" - treating RED as "write all tests" and GREEN as "write all code."
|
|
21
|
+
|
|
22
|
+
This produces **crap tests**:
|
|
23
|
+
|
|
24
|
+
- Tests written in bulk test _imagined_ behavior, not _actual_ behavior
|
|
25
|
+
- You end up testing the _shape_ of things (data structures, function signatures) rather than user-facing behavior
|
|
26
|
+
- Tests become insensitive to real changes - they pass when behavior breaks, fail when behavior is fine
|
|
27
|
+
- You outrun your headlights, committing to test structure before understanding the implementation
|
|
28
|
+
|
|
29
|
+
**Correct approach**: Vertical slices via tracer bullets. One test → one implementation → repeat. Each test responds to what you learned from the previous cycle. Because you just wrote the code, you know exactly what behavior matters and how to verify it.
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
WRONG (horizontal):
|
|
33
|
+
RED: test1, test2, test3, test4, test5
|
|
34
|
+
GREEN: impl1, impl2, impl3, impl4, impl5
|
|
35
|
+
|
|
36
|
+
RIGHT (vertical):
|
|
37
|
+
RED→GREEN: test1→impl1
|
|
38
|
+
RED→GREEN: test2→impl2
|
|
39
|
+
RED→GREEN: test3→impl3
|
|
40
|
+
...
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Workflow
|
|
44
|
+
|
|
45
|
+
### 1. Planning
|
|
46
|
+
|
|
47
|
+
Before writing any code:
|
|
48
|
+
|
|
49
|
+
- [ ] Confirm with user what interface changes are needed
|
|
50
|
+
- [ ] Confirm with user which behaviors to test (prioritize)
|
|
51
|
+
- [ ] Identify opportunities for [deep modules](deep-modules.md) (small interface, deep implementation)
|
|
52
|
+
- [ ] Design interfaces for [testability](interface-design.md)
|
|
53
|
+
- [ ] List the behaviors to test (not implementation steps)
|
|
54
|
+
- [ ] Get user approval on the plan
|
|
55
|
+
|
|
56
|
+
Ask: "What should the public interface look like? Which behaviors are most important to test?"
|
|
57
|
+
|
|
58
|
+
**You can't test everything.** Confirm with the user exactly which behaviors matter most. Focus testing effort on critical paths and complex logic, not every possible edge case.
|
|
59
|
+
|
|
60
|
+
### 2. Tracer Bullet
|
|
61
|
+
|
|
62
|
+
Write ONE test that confirms ONE thing about the system:
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
RED: Write test for first behavior → test fails
|
|
66
|
+
GREEN: Write minimal code to pass → test passes
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
This is your tracer bullet - proves the path works end-to-end.
|
|
70
|
+
|
|
71
|
+
### 3. Incremental Loop
|
|
72
|
+
|
|
73
|
+
For each remaining behavior:
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
RED: Write next test → fails
|
|
77
|
+
GREEN: Minimal code to pass → passes
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Rules:
|
|
81
|
+
|
|
82
|
+
- One test at a time
|
|
83
|
+
- Only enough code to pass current test
|
|
84
|
+
- Don't anticipate future tests
|
|
85
|
+
- Keep tests focused on observable behavior
|
|
86
|
+
|
|
87
|
+
### 4. Refactor
|
|
88
|
+
|
|
89
|
+
After all tests pass, look for [refactor candidates](refactoring.md):
|
|
90
|
+
|
|
91
|
+
- [ ] Extract duplication
|
|
92
|
+
- [ ] Deepen modules (move complexity behind simple interfaces)
|
|
93
|
+
- [ ] Apply SOLID principles where natural
|
|
94
|
+
- [ ] Consider what new code reveals about existing code
|
|
95
|
+
- [ ] Run tests after each refactor step
|
|
96
|
+
|
|
97
|
+
**Never refactor while RED.** Get to GREEN first.
|
|
98
|
+
|
|
99
|
+
## Checklist Per Cycle
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
[ ] Test describes behavior, not implementation
|
|
103
|
+
[ ] Test uses public interface only
|
|
104
|
+
[ ] Test would survive internal refactor
|
|
105
|
+
[ ] Code is minimal for this test
|
|
106
|
+
[ ] No speculative features added
|
|
107
|
+
```
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Deep Modules
|
|
2
|
+
|
|
3
|
+
From "A Philosophy of Software Design":
|
|
4
|
+
|
|
5
|
+
**Deep module** = small interface + lots of implementation
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
┌─────────────────────┐
|
|
9
|
+
│ Small Interface │ ← Few methods, simple params
|
|
10
|
+
├─────────────────────┤
|
|
11
|
+
│ │
|
|
12
|
+
│ │
|
|
13
|
+
│ Deep Implementation│ ← Complex logic hidden
|
|
14
|
+
│ │
|
|
15
|
+
│ │
|
|
16
|
+
└─────────────────────┘
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
**Shallow module** = large interface + little implementation (avoid)
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
┌─────────────────────────────────┐
|
|
23
|
+
│ Large Interface │ ← Many methods, complex params
|
|
24
|
+
├─────────────────────────────────┤
|
|
25
|
+
│ Thin Implementation │ ← Just passes through
|
|
26
|
+
└─────────────────────────────────┘
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
When designing interfaces, ask:
|
|
30
|
+
|
|
31
|
+
- Can I reduce the number of methods?
|
|
32
|
+
- Can I simplify the parameters?
|
|
33
|
+
- Can I hide more complexity inside?
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Interface Design for Testability
|
|
2
|
+
|
|
3
|
+
Good interfaces make testing natural:
|
|
4
|
+
|
|
5
|
+
1. **Accept dependencies, don't create them**
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
// Testable
|
|
9
|
+
function processOrder(order, paymentGateway) {}
|
|
10
|
+
|
|
11
|
+
// Hard to test
|
|
12
|
+
function processOrder(order) {
|
|
13
|
+
const gateway = new StripeGateway();
|
|
14
|
+
}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
2. **Return results, don't produce side effects**
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
// Testable
|
|
21
|
+
function calculateDiscount(cart): Discount {}
|
|
22
|
+
|
|
23
|
+
// Hard to test
|
|
24
|
+
function applyDiscount(cart): void {
|
|
25
|
+
cart.total -= discount;
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
3. **Small surface area**
|
|
30
|
+
- Fewer methods = fewer tests needed
|
|
31
|
+
- Fewer params = simpler test setup
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# When to Mock
|
|
2
|
+
|
|
3
|
+
Mock at **system boundaries** only:
|
|
4
|
+
|
|
5
|
+
- External APIs (payment, email, etc.)
|
|
6
|
+
- Databases (sometimes - prefer test DB)
|
|
7
|
+
- Time/randomness
|
|
8
|
+
- File system (sometimes)
|
|
9
|
+
|
|
10
|
+
Don't mock:
|
|
11
|
+
|
|
12
|
+
- Your own classes/modules
|
|
13
|
+
- Internal collaborators
|
|
14
|
+
- Anything you control
|
|
15
|
+
|
|
16
|
+
## Designing for Mockability
|
|
17
|
+
|
|
18
|
+
At system boundaries, design interfaces that are easy to mock:
|
|
19
|
+
|
|
20
|
+
**1. Use dependency injection**
|
|
21
|
+
|
|
22
|
+
Pass external dependencies in rather than creating them internally:
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
// Easy to mock
|
|
26
|
+
function processPayment(order, paymentClient) {
|
|
27
|
+
return paymentClient.charge(order.total);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Hard to mock
|
|
31
|
+
function processPayment(order) {
|
|
32
|
+
const client = new StripeClient(process.env.STRIPE_KEY);
|
|
33
|
+
return client.charge(order.total);
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**2. Prefer SDK-style interfaces over generic fetchers**
|
|
38
|
+
|
|
39
|
+
Create specific functions for each external operation instead of one generic function with conditional logic:
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
// GOOD: Each function is independently mockable
|
|
43
|
+
const api = {
|
|
44
|
+
getUser: (id) => fetch(`/users/${id}`),
|
|
45
|
+
getOrders: (userId) => fetch(`/users/${userId}/orders`),
|
|
46
|
+
createOrder: (data) => fetch('/orders', { method: 'POST', body: data }),
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// BAD: Mocking requires conditional logic inside the mock
|
|
50
|
+
const api = {
|
|
51
|
+
fetch: (endpoint, options) => fetch(endpoint, options),
|
|
52
|
+
};
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
The SDK approach means:
|
|
56
|
+
- Each mock returns one specific shape
|
|
57
|
+
- No conditional logic in test setup
|
|
58
|
+
- Easier to see which endpoints a test exercises
|
|
59
|
+
- Type safety per endpoint
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Refactor Candidates
|
|
2
|
+
|
|
3
|
+
After TDD cycle, look for:
|
|
4
|
+
|
|
5
|
+
- **Duplication** → Extract function/class
|
|
6
|
+
- **Long methods** → Break into private helpers (keep tests on public interface)
|
|
7
|
+
- **Shallow modules** → Combine or deepen
|
|
8
|
+
- **Feature envy** → Move logic to where data lives
|
|
9
|
+
- **Primitive obsession** → Introduce value objects
|
|
10
|
+
- **Existing code** the new code reveals as problematic
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Good and Bad Tests
|
|
2
|
+
|
|
3
|
+
## Good Tests
|
|
4
|
+
|
|
5
|
+
**Integration-style**: Test through real interfaces, not mocks of internal parts.
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
// GOOD: Tests observable behavior
|
|
9
|
+
test("user can checkout with valid cart", async () => {
|
|
10
|
+
const cart = createCart();
|
|
11
|
+
cart.add(product);
|
|
12
|
+
const result = await checkout(cart, paymentMethod);
|
|
13
|
+
expect(result.status).toBe("confirmed");
|
|
14
|
+
});
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Characteristics:
|
|
18
|
+
|
|
19
|
+
- Tests behavior users/callers care about
|
|
20
|
+
- Uses public API only
|
|
21
|
+
- Survives internal refactors
|
|
22
|
+
- Describes WHAT, not HOW
|
|
23
|
+
- One logical assertion per test
|
|
24
|
+
|
|
25
|
+
## Bad Tests
|
|
26
|
+
|
|
27
|
+
**Implementation-detail tests**: Coupled to internal structure.
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
// BAD: Tests implementation details
|
|
31
|
+
test("checkout calls paymentService.process", async () => {
|
|
32
|
+
const mockPayment = jest.mock(paymentService);
|
|
33
|
+
await checkout(cart, payment);
|
|
34
|
+
expect(mockPayment.process).toHaveBeenCalledWith(cart.total);
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Red flags:
|
|
39
|
+
|
|
40
|
+
- Mocking internal collaborators
|
|
41
|
+
- Testing private methods
|
|
42
|
+
- Asserting on call counts/order
|
|
43
|
+
- Test breaks when refactoring without behavior change
|
|
44
|
+
- Test name describes HOW not WHAT
|
|
45
|
+
- Verifying through external means instead of interface
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
// BAD: Bypasses interface to verify
|
|
49
|
+
test("createUser saves to database", async () => {
|
|
50
|
+
await createUser({ name: "Alice" });
|
|
51
|
+
const row = await db.query("SELECT * FROM users WHERE name = ?", ["Alice"]);
|
|
52
|
+
expect(row).toBeDefined();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// GOOD: Verifies through interface
|
|
56
|
+
test("createUser makes user retrievable", async () => {
|
|
57
|
+
const user = await createUser({ name: "Alice" });
|
|
58
|
+
const retrieved = await getUser(user.id);
|
|
59
|
+
expect(retrieved.name).toBe("Alice");
|
|
60
|
+
});
|
|
61
|
+
```
|